1112098Ssam/*-
2112098Ssam * SPDX-License-Identifier: BSD-3-Clause
3112098Ssam *
4112098Ssam * Copyright (c) 2017-2019 Mellanox Technologies.
5112098Ssam * All rights reserved.
6112098Ssam *
7112098Ssam * Redistribution and use in source and binary forms, with or without
8112098Ssam * modification, are permitted provided that the following conditions
9112098Ssam * are met:
10112098Ssam * 1. Redistributions of source code must retain the above copyright
11112098Ssam *    notice, this list of conditions and the following disclaimer.
12112098Ssam * 2. Redistributions in binary form must reproduce the above copyright
13112098Ssam *    notice, this list of conditions and the following disclaimer in the
14112098Ssam *    documentation and/or other materials provided with the distribution.
15112098Ssam * 3. Neither the name of Mellanox nor the names of contributors
16112098Ssam *    may be used to endorse or promote products derived from this software
17112098Ssam *    without specific prior written permission.
18112098Ssam *
19112098Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20112098Ssam * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21112098Ssam * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22112098Ssam * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23112098Ssam * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24112098Ssam * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25112098Ssam * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26112098Ssam * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27112098Ssam * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28112098Ssam * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29112098Ssam * SUCH DAMAGE.
30112100Ssam *
31112098Ssam * $FreeBSD: stable/11/sys/dev/mlxfw/mlxfw_mfa2_tlv_multi.h 347285 2019-05-08 10:49:05Z hselasky $
32112098Ssam */
33112098Ssam
34112098Ssam#ifndef _MLXFW_MFA2_TLV_MULTI_H
35112098Ssam#define _MLXFW_MFA2_TLV_MULTI_H
36112098Ssam
37112098Ssam#include "mlxfw_mfa2_tlv.h"
38112098Ssam#include "mlxfw_mfa2_format.h"
39112098Ssam#include "mlxfw_mfa2_file.h"
40112098Ssam
41112098Ssamconst struct mlxfw_mfa2_tlv *
42112098Ssammlxfw_mfa2_tlv_multi_child(const struct mlxfw_mfa2_file *mfa2_file,
43112098Ssam			   const struct mlxfw_mfa2_tlv_multi *multi);
44112098Ssam
45112098Ssamconst struct mlxfw_mfa2_tlv *
46112098Ssammlxfw_mfa2_tlv_next(const struct mlxfw_mfa2_file *mfa2_file,
47112098Ssam		    const struct mlxfw_mfa2_tlv *tlv);
48112098Ssam
49112098Ssamconst struct mlxfw_mfa2_tlv *
50112098Ssammlxfw_mfa2_tlv_advance(const struct mlxfw_mfa2_file *mfa2_file,
51112098Ssam		       const struct mlxfw_mfa2_tlv *from_tlv, u16 count);
52158719Spjd
53158719Spjdconst struct mlxfw_mfa2_tlv *
54112098Ssammlxfw_mfa2_tlv_multi_child_find(const struct mlxfw_mfa2_file *mfa2_file,
55112098Ssam				const struct mlxfw_mfa2_tlv_multi *multi,
56112098Ssam				enum mlxfw_mfa2_tlv_type type, u16 index);
57158719Spjd
58158719Spjdint mlxfw_mfa2_tlv_multi_child_count(const struct mlxfw_mfa2_file *mfa2_file,
59112098Ssam				     const struct mlxfw_mfa2_tlv_multi *multi,
60112098Ssam				     enum mlxfw_mfa2_tlv_type type,
61112098Ssam				     u16 *p_count);
62112098Ssam
63112098Ssam#define mlxfw_mfa2_tlv_foreach(mfa2_file, tlv, idx, from_tlv, count) \
64112545Ssam	for (idx = 0, tlv = from_tlv; idx < (count); \
65112098Ssam	     idx++, tlv = mlxfw_mfa2_tlv_next(mfa2_file, tlv))
66112098Ssam
67112098Ssam#define mlxfw_mfa2_tlv_multi_foreach(mfa2_file, tlv, idx, multi) \
68112098Ssam	mlxfw_mfa2_tlv_foreach(mfa2_file, tlv, idx, \
69112098Ssam			       mlxfw_mfa2_tlv_multi_child(mfa2_file, multi), \
70			       be16_to_cpu(multi->num_extensions) + 1)
71#endif
72