-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rocker: push tlv processing into separate files
Carve out TLV processing helpers into separate files. Signed-off-by: Jiri Pirko <jiri@mellanox.com> Acked-by: Scott Feldman <sfeldma@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
- Loading branch information
Jiri Pirko
authored and
David S. Miller
committed
Feb 18, 2016
1 parent
11ce2ba
commit de15219
Showing
5 changed files
with
284 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ | |
# | ||
|
||
obj-$(CONFIG_ROCKER) += rocker.o | ||
rocker-y := rocker_main.o | ||
rocker-y := rocker_main.o rocker_tlv.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* drivers/net/ethernet/rocker/rocker.h - Rocker switch device driver | ||
* Copyright (c) 2014-2016 Jiri Pirko <jiri@mellanox.com> | ||
* Copyright (c) 2014 Scott Feldman <sfeldma@gmail.com> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
*/ | ||
|
||
#ifndef _ROCKER_H | ||
#define _ROCKER_H | ||
|
||
#include <linux/types.h> | ||
|
||
#include "rocker_hw.h" | ||
|
||
struct rocker_desc_info { | ||
char *data; /* mapped */ | ||
size_t data_size; | ||
size_t tlv_size; | ||
struct rocker_desc *desc; | ||
dma_addr_t mapaddr; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* drivers/net/ethernet/rocker/rocker_tlv.c - Rocker switch device driver | ||
* Copyright (c) 2014-2016 Jiri Pirko <jiri@mellanox.com> | ||
* Copyright (c) 2014 Scott Feldman <sfeldma@gmail.com> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
*/ | ||
|
||
#include <linux/types.h> | ||
#include <linux/string.h> | ||
#include <linux/errno.h> | ||
|
||
#include "rocker_hw.h" | ||
#include "rocker_tlv.h" | ||
|
||
void rocker_tlv_parse(const struct rocker_tlv **tb, int maxtype, | ||
const char *buf, int buf_len) | ||
{ | ||
const struct rocker_tlv *tlv; | ||
const struct rocker_tlv *head = (const struct rocker_tlv *) buf; | ||
int rem; | ||
|
||
memset(tb, 0, sizeof(struct rocker_tlv *) * (maxtype + 1)); | ||
|
||
rocker_tlv_for_each(tlv, head, buf_len, rem) { | ||
u32 type = rocker_tlv_type(tlv); | ||
|
||
if (type > 0 && type <= maxtype) | ||
tb[type] = tlv; | ||
} | ||
} | ||
|
||
int rocker_tlv_put(struct rocker_desc_info *desc_info, | ||
int attrtype, int attrlen, const void *data) | ||
{ | ||
int tail_room = desc_info->data_size - desc_info->tlv_size; | ||
int total_size = rocker_tlv_total_size(attrlen); | ||
struct rocker_tlv *tlv; | ||
|
||
if (unlikely(tail_room < total_size)) | ||
return -EMSGSIZE; | ||
|
||
tlv = rocker_tlv_start(desc_info); | ||
desc_info->tlv_size += total_size; | ||
tlv->type = attrtype; | ||
tlv->len = rocker_tlv_attr_size(attrlen); | ||
memcpy(rocker_tlv_data(tlv), data, attrlen); | ||
memset((char *) tlv + tlv->len, 0, rocker_tlv_padlen(attrlen)); | ||
return 0; | ||
} |
Oops, something went wrong.