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);
36 tlv_len = NLA_ALIGN(tlv_len + be16_to_cpu(multi->total_len));
39 next = (void *) tlv + tlv_len;
40 return mlxfw_mfa2_tlv_get(mfa2_file, next);
43 const struct mlxfw_mfa2_tlv *
44 mlxfw_mfa2_tlv_advance(const struct mlxfw_mfa2_file *mfa2_file,
45 const struct mlxfw_mfa2_tlv *from_tlv, u16 count)
47 const struct mlxfw_mfa2_tlv *tlv;
50 mlxfw_mfa2_tlv_foreach(mfa2_file, tlv, idx, from_tlv, count)
56 const struct mlxfw_mfa2_tlv *
57 mlxfw_mfa2_tlv_multi_child_find(const struct mlxfw_mfa2_file *mfa2_file,
58 const struct mlxfw_mfa2_tlv_multi *multi,
59 enum mlxfw_mfa2_tlv_type type, u16 index)
61 const struct mlxfw_mfa2_tlv *tlv;
65 mlxfw_mfa2_tlv_multi_foreach(mfa2_file, tlv, idx, multi) {
67 pr_err("TLV parsing error\n");
70 if (tlv->type == type)
77 int mlxfw_mfa2_tlv_multi_child_count(const struct mlxfw_mfa2_file *mfa2_file,
78 const struct mlxfw_mfa2_tlv_multi *multi,
79 enum mlxfw_mfa2_tlv_type type,
82 const struct mlxfw_mfa2_tlv *tlv;
86 mlxfw_mfa2_tlv_multi_foreach(mfa2_file, tlv, idx, multi) {
88 pr_err("TLV parsing error\n");
92 if (tlv->type == type)