1 /*******************************************************************************
3 Copyright (c) 2013 - 2015, Intel Corporation
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 3. Neither the name of the Intel Corporation nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
32 ***************************************************************************/
37 /* forward declaration */
38 struct fm10k_msg_data;
40 #include "fm10k_type.h"
42 /* Message / Argument header format
44 * 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
45 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 * | Length | Flags | Type / ID |
47 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49 * The message header format described here is used for messages that are
50 * passed between the PF and the VF. To allow for messages larger then
51 * mailbox size we will provide a message with the above header and it
52 * will be segmented and transported to the mailbox to the other side where
53 * it is reassembled. It contains the following fields:
54 * Length: Length of the message in bytes excluding the message header
56 * Type/ID: These will be the message/argument types we pass
58 /* message data header */
59 #define FM10K_TLV_ID_SHIFT 0
60 #define FM10K_TLV_ID_SIZE 16
61 #define FM10K_TLV_ID_MASK ((1u << FM10K_TLV_ID_SIZE) - 1)
62 #define FM10K_TLV_FLAGS_SHIFT 16
63 #define FM10K_TLV_FLAGS_MSG 0x1
64 #define FM10K_TLV_FLAGS_SIZE 4
65 #define FM10K_TLV_LEN_SHIFT 20
66 #define FM10K_TLV_LEN_SIZE 12
68 #define FM10K_TLV_HDR_LEN 4ul
69 #define FM10K_TLV_LEN_ALIGN_MASK \
70 ((FM10K_TLV_HDR_LEN - 1) << FM10K_TLV_LEN_SHIFT)
71 #define FM10K_TLV_LEN_ALIGN(tlv) \
72 (((tlv) + FM10K_TLV_LEN_ALIGN_MASK) & ~FM10K_TLV_LEN_ALIGN_MASK)
73 #define FM10K_TLV_DWORD_LEN(tlv) \
74 ((u16)((FM10K_TLV_LEN_ALIGN(tlv)) >> (FM10K_TLV_LEN_SHIFT + 2)) + 1)
76 #define FM10K_TLV_RESULTS_MAX 32
79 FM10K_TLV_NULL_STRING,
89 #define FM10K_TLV_ERROR (~0u)
91 struct fm10k_tlv_attr {
93 enum fm10k_tlv_type type;
97 #define FM10K_TLV_ATTR_NULL_STRING(id, len) { id, FM10K_TLV_NULL_STRING, len }
98 #define FM10K_TLV_ATTR_MAC_ADDR(id) { id, FM10K_TLV_MAC_ADDR, 6 }
99 #define FM10K_TLV_ATTR_BOOL(id) { id, FM10K_TLV_BOOL, 0 }
100 #define FM10K_TLV_ATTR_U8(id) { id, FM10K_TLV_UNSIGNED, 1 }
101 #define FM10K_TLV_ATTR_U16(id) { id, FM10K_TLV_UNSIGNED, 2 }
102 #define FM10K_TLV_ATTR_U32(id) { id, FM10K_TLV_UNSIGNED, 4 }
103 #define FM10K_TLV_ATTR_U64(id) { id, FM10K_TLV_UNSIGNED, 8 }
104 #define FM10K_TLV_ATTR_S8(id) { id, FM10K_TLV_SIGNED, 1 }
105 #define FM10K_TLV_ATTR_S16(id) { id, FM10K_TLV_SIGNED, 2 }
106 #define FM10K_TLV_ATTR_S32(id) { id, FM10K_TLV_SIGNED, 4 }
107 #define FM10K_TLV_ATTR_S64(id) { id, FM10K_TLV_SIGNED, 8 }
108 #define FM10K_TLV_ATTR_LE_STRUCT(id, len) { id, FM10K_TLV_LE_STRUCT, len }
109 #define FM10K_TLV_ATTR_NESTED(id) { id, FM10K_TLV_NESTED }
110 #define FM10K_TLV_ATTR_LAST { FM10K_TLV_ERROR }
112 struct fm10k_msg_data {
114 const struct fm10k_tlv_attr *attr;
115 s32 (*func)(struct fm10k_hw *, u32 **,
116 struct fm10k_mbx_info *);
119 #define FM10K_MSG_HANDLER(id, attr, func) { id, attr, func }
121 s32 fm10k_tlv_msg_init(u32 *, u16);
122 s32 fm10k_tlv_attr_put_mac_vlan(u32 *, u16, const u8 *, u16);
123 s32 fm10k_tlv_attr_get_mac_vlan(u32 *, u8 *, u16 *);
124 s32 fm10k_tlv_attr_put_bool(u32 *, u16);
125 s32 fm10k_tlv_attr_put_value(u32 *, u16, s64, u32);
126 #define fm10k_tlv_attr_put_u8(msg, attr_id, val) \
127 fm10k_tlv_attr_put_value(msg, attr_id, val, 1)
128 #define fm10k_tlv_attr_put_u16(msg, attr_id, val) \
129 fm10k_tlv_attr_put_value(msg, attr_id, val, 2)
130 #define fm10k_tlv_attr_put_u32(msg, attr_id, val) \
131 fm10k_tlv_attr_put_value(msg, attr_id, val, 4)
132 #define fm10k_tlv_attr_put_u64(msg, attr_id, val) \
133 fm10k_tlv_attr_put_value(msg, attr_id, val, 8)
134 #define fm10k_tlv_attr_put_s8(msg, attr_id, val) \
135 fm10k_tlv_attr_put_value(msg, attr_id, val, 1)
136 #define fm10k_tlv_attr_put_s16(msg, attr_id, val) \
137 fm10k_tlv_attr_put_value(msg, attr_id, val, 2)
138 #define fm10k_tlv_attr_put_s32(msg, attr_id, val) \
139 fm10k_tlv_attr_put_value(msg, attr_id, val, 4)
140 #define fm10k_tlv_attr_put_s64(msg, attr_id, val) \
141 fm10k_tlv_attr_put_value(msg, attr_id, val, 8)
142 s32 fm10k_tlv_attr_get_value(u32 *, void *, u32);
143 #define fm10k_tlv_attr_get_u8(attr, ptr) \
144 fm10k_tlv_attr_get_value(attr, ptr, sizeof(u8))
145 #define fm10k_tlv_attr_get_u16(attr, ptr) \
146 fm10k_tlv_attr_get_value(attr, ptr, sizeof(u16))
147 #define fm10k_tlv_attr_get_u32(attr, ptr) \
148 fm10k_tlv_attr_get_value(attr, ptr, sizeof(u32))
149 #define fm10k_tlv_attr_get_u64(attr, ptr) \
150 fm10k_tlv_attr_get_value(attr, ptr, sizeof(u64))
151 #define fm10k_tlv_attr_get_s8(attr, ptr) \
152 fm10k_tlv_attr_get_value(attr, ptr, sizeof(s8))
153 #define fm10k_tlv_attr_get_s16(attr, ptr) \
154 fm10k_tlv_attr_get_value(attr, ptr, sizeof(s16))
155 #define fm10k_tlv_attr_get_s32(attr, ptr) \
156 fm10k_tlv_attr_get_value(attr, ptr, sizeof(s32))
157 #define fm10k_tlv_attr_get_s64(attr, ptr) \
158 fm10k_tlv_attr_get_value(attr, ptr, sizeof(s64))
159 s32 fm10k_tlv_attr_put_le_struct(u32 *, u16, const void *, u32);
160 s32 fm10k_tlv_attr_get_le_struct(u32 *, void *, u32);
161 s32 fm10k_tlv_msg_parse(struct fm10k_hw *, u32 *, struct fm10k_mbx_info *,
162 const struct fm10k_msg_data *);
163 s32 fm10k_tlv_msg_error(struct fm10k_hw *hw, u32 **results,
164 struct fm10k_mbx_info *);
166 #define FM10K_TLV_MSG_ID_TEST 0
168 enum fm10k_tlv_test_attr_id {
169 FM10K_TEST_MSG_UNSET,
170 FM10K_TEST_MSG_STRING,
171 FM10K_TEST_MSG_MAC_ADDR,
180 FM10K_TEST_MSG_LE_STRUCT,
181 FM10K_TEST_MSG_NESTED,
182 FM10K_TEST_MSG_RESULT,
186 extern const struct fm10k_tlv_attr fm10k_tlv_msg_test_attr[];
187 void fm10k_tlv_msg_test_create(u32 *, u32);
188 s32 fm10k_tlv_msg_test(struct fm10k_hw *, u32 **, struct fm10k_mbx_info *);
190 #define FM10K_TLV_MSG_TEST_HANDLER(func) \
191 FM10K_MSG_HANDLER(FM10K_TLV_MSG_ID_TEST, fm10k_tlv_msg_test_attr, func)
192 #define FM10K_TLV_MSG_ERROR_HANDLER(func) \
193 FM10K_MSG_HANDLER(FM10K_TLV_ERROR, NULL, func)
194 #endif /* _FM10K_MSG_H_ */