1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /* Copyright (c) 2017-2019 Mellanox Technologies. All rights reserved */
4 #define pr_fmt(fmt) "MFA2: " fmt
6 #include "mlxfw_mfa2_tlv_multi.h"
7 #include <uapi/linux/netlink.h>
9 #define MLXFW_MFA2_TLV_TOTAL_SIZE(tlv) \
10 NLA_ALIGN(sizeof(*(tlv)) + be16_to_cpu((tlv)->len))
12 const struct mlxfw_mfa2_tlv *
13 mlxfw_mfa2_tlv_multi_child(const struct mlxfw_mfa2_file *mfa2_file,
14 const struct mlxfw_mfa2_tlv_multi *multi)
18 multi_len = NLA_ALIGN(sizeof(struct mlxfw_mfa2_tlv_multi));
19 return mlxfw_mfa2_tlv_get(mfa2_file, (void *) multi + multi_len);
22 const struct mlxfw_mfa2_tlv *
23 mlxfw_mfa2_tlv_next(const struct mlxfw_mfa2_file *mfa2_file,
24 const struct mlxfw_mfa2_tlv *tlv)
26 const struct mlxfw_mfa2_tlv_multi *multi;
30 tlv_len = MLXFW_MFA2_TLV_TOTAL_SIZE(tlv);
32 if (tlv->type == MLXFW_MFA2_TLV_MULTI_PART) {
33 multi = mlxfw_mfa2_tlv_multi_get(mfa2_file, tlv);
34 tlv_len = NLA_ALIGN(tlv_len + be16_to_cpu(multi->total_len));
37 next = (void *) tlv + tlv_len;
38 return mlxfw_mfa2_tlv_get(mfa2_file, next);
41 const struct mlxfw_mfa2_tlv *
42 mlxfw_mfa2_tlv_advance(const struct mlxfw_mfa2_file *mfa2_file,
43 const struct mlxfw_mfa2_tlv *from_tlv, u16 count)
45 const struct mlxfw_mfa2_tlv *tlv;
48 mlxfw_mfa2_tlv_foreach(mfa2_file, tlv, idx, from_tlv, count)
54 const struct mlxfw_mfa2_tlv *
55 mlxfw_mfa2_tlv_multi_child_find(const struct mlxfw_mfa2_file *mfa2_file,
56 const struct mlxfw_mfa2_tlv_multi *multi,
57 enum mlxfw_mfa2_tlv_type type, u16 index)
59 const struct mlxfw_mfa2_tlv *tlv;
63 mlxfw_mfa2_tlv_multi_foreach(mfa2_file, tlv, idx, multi) {
65 pr_err("TLV parsing error\n");
68 if (tlv->type == type)
75 int mlxfw_mfa2_tlv_multi_child_count(const struct mlxfw_mfa2_file *mfa2_file,
76 const struct mlxfw_mfa2_tlv_multi *multi,
77 enum mlxfw_mfa2_tlv_type type,
80 const struct mlxfw_mfa2_tlv *tlv;
84 mlxfw_mfa2_tlv_multi_foreach(mfa2_file, tlv, idx, multi) {
86 pr_err("TLV parsing error\n");
90 if (tlv->type == type)