linux_dsm_epyc7002/drivers/net/ethernet/rocker/rocker_tlv.c
Thomas Gleixner 2874c5fd28 treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152
Based on 1 normalized pattern(s):

  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

extracted by the scancode license scanner the SPDX license identifier

  GPL-2.0-or-later

has been chosen to replace the boilerplate/reference in 3029 file(s).

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Allison Randal <allison@lohutok.net>
Cc: linux-spdx@vger.kernel.org
Link: https://lkml.kernel.org/r/20190527070032.746973796@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-05-30 11:26:32 -07:00

50 lines
1.3 KiB
C

// SPDX-License-Identifier: GPL-2.0-or-later
/*
* 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>
*/
#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;
}