1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2013 - 2015 Intel Corporation
8 /* forward declaration */
11 #include "fm10k_type.h"
13 /* Message / Argument header format
15 * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
16 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
17 * | Length | Flags | Type / ID |
18 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
20 * The message header format described here is used for messages that are
21 * passed between the PF and the VF. To allow for messages larger then
22 * mailbox size we will provide a message with the above header and it
23 * will be segmented and transported to the mailbox to the other side where
24 * it is reassembled. It contains the following fields:
25 * Length: Length of the message in bytes excluding the message header
27 * Type/ID: These will be the message/argument types we pass
29 /* message data header */
30 #define FM10K_TLV_ID_SHIFT 0
31 #define FM10K_TLV_ID_SIZE 16
32 #define FM10K_TLV_ID_MASK ((1u << FM10K_TLV_ID_SIZE) - 1)
33 #define FM10K_TLV_FLAGS_SHIFT 16
34 #define FM10K_TLV_FLAGS_MSG 0x1
35 #define FM10K_TLV_FLAGS_SIZE 4
36 #define FM10K_TLV_LEN_SHIFT 20
37 #define FM10K_TLV_LEN_SIZE 12
39 #define FM10K_TLV_HDR_LEN 4ul
40 #define FM10K_TLV_LEN_ALIGN_MASK \
41 ((FM10K_TLV_HDR_LEN - 1) << FM10K_TLV_LEN_SHIFT)
42 #define FM10K_TLV_LEN_ALIGN(tlv) \
43 (((tlv) + FM10K_TLV_LEN_ALIGN_MASK) & ~FM10K_TLV_LEN_ALIGN_MASK)
44 #define FM10K_TLV_DWORD_LEN(tlv) \
45 ((u16)((FM10K_TLV_LEN_ALIGN(tlv)) >> (FM10K_TLV_LEN_SHIFT + 2)) + 1)
47 #define FM10K_TLV_RESULTS_MAX 32
50 FM10K_TLV_NULL_STRING,
60 #define FM10K_TLV_ERROR (~0u)
62 struct fm10k_tlv_attr {
64 enum fm10k_tlv_type type;
68 #define FM10K_TLV_ATTR_NULL_STRING(id, len) { id, FM10K_TLV_NULL_STRING, len }
69 #define FM10K_TLV_ATTR_MAC_ADDR(id) { id, FM10K_TLV_MAC_ADDR, 6 }
70 #define FM10K_TLV_ATTR_BOOL(id) { id, FM10K_TLV_BOOL, 0 }
71 #define FM10K_TLV_ATTR_U8(id) { id, FM10K_TLV_UNSIGNED, 1 }
72 #define FM10K_TLV_ATTR_U16(id) { id, FM10K_TLV_UNSIGNED, 2 }
73 #define FM10K_TLV_ATTR_U32(id) { id, FM10K_TLV_UNSIGNED, 4 }
74 #define FM10K_TLV_ATTR_U64(id) { id, FM10K_TLV_UNSIGNED, 8 }
75 #define FM10K_TLV_ATTR_S8(id) { id, FM10K_TLV_SIGNED, 1 }
76 #define FM10K_TLV_ATTR_S16(id) { id, FM10K_TLV_SIGNED, 2 }
77 #define FM10K_TLV_ATTR_S32(id) { id, FM10K_TLV_SIGNED, 4 }
78 #define FM10K_TLV_ATTR_S64(id) { id, FM10K_TLV_SIGNED, 8 }
79 #define FM10K_TLV_ATTR_LE_STRUCT(id, len) { id, FM10K_TLV_LE_STRUCT, len }
80 #define FM10K_TLV_ATTR_NESTED(id) { id, FM10K_TLV_NESTED }
81 #define FM10K_TLV_ATTR_LAST { FM10K_TLV_ERROR }
83 struct fm10k_msg_data {
85 const struct fm10k_tlv_attr *attr;
86 s32 (*func)(struct fm10k_hw *, u32 **,
87 struct fm10k_mbx_info *);
90 #define FM10K_MSG_HANDLER(id, attr, func) { id, attr, func }
92 s32 fm10k_tlv_msg_init(u32 *, u16);
93 s32 fm10k_tlv_attr_put_mac_vlan(u32 *, u16, const u8 *, u16);
94 s32 fm10k_tlv_attr_get_mac_vlan(u32 *, u8 *, u16 *);
95 s32 fm10k_tlv_attr_put_bool(u32 *, u16);
96 s32 fm10k_tlv_attr_put_value(u32 *, u16, s64, u32);
97 #define fm10k_tlv_attr_put_u8(msg, attr_id, val) \
98 fm10k_tlv_attr_put_value(msg, attr_id, val, 1)
99 #define fm10k_tlv_attr_put_u16(msg, attr_id, val) \
100 fm10k_tlv_attr_put_value(msg, attr_id, val, 2)
101 #define fm10k_tlv_attr_put_u32(msg, attr_id, val) \
102 fm10k_tlv_attr_put_value(msg, attr_id, val, 4)
103 #define fm10k_tlv_attr_put_u64(msg, attr_id, val) \
104 fm10k_tlv_attr_put_value(msg, attr_id, val, 8)
105 #define fm10k_tlv_attr_put_s8(msg, attr_id, val) \
106 fm10k_tlv_attr_put_value(msg, attr_id, val, 1)
107 #define fm10k_tlv_attr_put_s16(msg, attr_id, val) \
108 fm10k_tlv_attr_put_value(msg, attr_id, val, 2)
109 #define fm10k_tlv_attr_put_s32(msg, attr_id, val) \
110 fm10k_tlv_attr_put_value(msg, attr_id, val, 4)
111 #define fm10k_tlv_attr_put_s64(msg, attr_id, val) \
112 fm10k_tlv_attr_put_value(msg, attr_id, val, 8)
113 s32 fm10k_tlv_attr_get_value(u32 *, void *, u32);
114 #define fm10k_tlv_attr_get_u8(attr, ptr) \
115 fm10k_tlv_attr_get_value(attr, ptr, sizeof(u8))
116 #define fm10k_tlv_attr_get_u16(attr, ptr) \
117 fm10k_tlv_attr_get_value(attr, ptr, sizeof(u16))
118 #define fm10k_tlv_attr_get_u32(attr, ptr) \
119 fm10k_tlv_attr_get_value(attr, ptr, sizeof(u32))
120 #define fm10k_tlv_attr_get_u64(attr, ptr) \
121 fm10k_tlv_attr_get_value(attr, ptr, sizeof(u64))
122 #define fm10k_tlv_attr_get_s8(attr, ptr) \
123 fm10k_tlv_attr_get_value(attr, ptr, sizeof(s8))
124 #define fm10k_tlv_attr_get_s16(attr, ptr) \
125 fm10k_tlv_attr_get_value(attr, ptr, sizeof(s16))
126 #define fm10k_tlv_attr_get_s32(attr, ptr) \
127 fm10k_tlv_attr_get_value(attr, ptr, sizeof(s32))
128 #define fm10k_tlv_attr_get_s64(attr, ptr) \
129 fm10k_tlv_attr_get_value(attr, ptr, sizeof(s64))
130 s32 fm10k_tlv_attr_put_le_struct(u32 *, u16, const void *, u32);
131 s32 fm10k_tlv_attr_get_le_struct(u32 *, void *, u32);
132 s32 fm10k_tlv_msg_parse(struct fm10k_hw *, u32 *, struct fm10k_mbx_info *,
133 const struct fm10k_msg_data *);
134 s32 fm10k_tlv_msg_error(struct fm10k_hw *hw, u32 **results,
135 struct fm10k_mbx_info *);
137 #define FM10K_TLV_MSG_ID_TEST 0
139 enum fm10k_tlv_test_attr_id {
140 FM10K_TEST_MSG_UNSET,
141 FM10K_TEST_MSG_STRING,
142 FM10K_TEST_MSG_MAC_ADDR,
151 FM10K_TEST_MSG_LE_STRUCT,
152 FM10K_TEST_MSG_NESTED,
153 FM10K_TEST_MSG_RESULT,
157 extern const struct fm10k_tlv_attr fm10k_tlv_msg_test_attr[];
158 void fm10k_tlv_msg_test_create(u32 *, u32);
159 s32 fm10k_tlv_msg_test(struct fm10k_hw *, u32 **, struct fm10k_mbx_info *);
161 #define FM10K_TLV_MSG_TEST_HANDLER(func) \
162 FM10K_MSG_HANDLER(FM10K_TLV_MSG_ID_TEST, fm10k_tlv_msg_test_attr, func)
163 #define FM10K_TLV_MSG_ERROR_HANDLER(func) \
164 FM10K_MSG_HANDLER(FM10K_TLV_ERROR, NULL, func)
165 #endif /* _FM10K_MSG_H_ */