]>
git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blob - drivers/net/ethernet/rocker/rocker_tlv.c
2 * drivers/net/ethernet/rocker/rocker_tlv.c - Rocker switch device driver
3 * Copyright (c) 2014-2016 Jiri Pirko <jiri@mellanox.com>
4 * Copyright (c) 2014 Scott Feldman <sfeldma@gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
12 #include <linux/types.h>
13 #include <linux/string.h>
14 #include <linux/errno.h>
16 #include "rocker_hw.h"
17 #include "rocker_tlv.h"
19 void rocker_tlv_parse(const struct rocker_tlv
**tb
, int maxtype
,
20 const char *buf
, int buf_len
)
22 const struct rocker_tlv
*tlv
;
23 const struct rocker_tlv
*head
= (const struct rocker_tlv
*) buf
;
26 memset(tb
, 0, sizeof(struct rocker_tlv
*) * (maxtype
+ 1));
28 rocker_tlv_for_each(tlv
, head
, buf_len
, rem
) {
29 u32 type
= rocker_tlv_type(tlv
);
31 if (type
> 0 && type
<= maxtype
)
36 int rocker_tlv_put(struct rocker_desc_info
*desc_info
,
37 int attrtype
, int attrlen
, const void *data
)
39 int tail_room
= desc_info
->data_size
- desc_info
->tlv_size
;
40 int total_size
= rocker_tlv_total_size(attrlen
);
41 struct rocker_tlv
*tlv
;
43 if (unlikely(tail_room
< total_size
))
46 tlv
= rocker_tlv_start(desc_info
);
47 desc_info
->tlv_size
+= total_size
;
49 tlv
->len
= rocker_tlv_attr_size(attrlen
);
50 memcpy(rocker_tlv_data(tlv
), data
, attrlen
);
51 memset((char *) tlv
+ tlv
->len
, 0, rocker_tlv_padlen(attrlen
));