xref: /linux/drivers/net/ethernet/meta/fbnic/fbnic_fw.h (revision f2c53ea949c5048f96b3dbb5a5ee7131ce4ff2de)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) Meta Platforms, Inc. and affiliates. */
3 
4 #ifndef _FBNIC_FW_H_
5 #define _FBNIC_FW_H_
6 
7 #include <linux/completion.h>
8 #include <linux/if_ether.h>
9 #include <linux/types.h>
10 
11 struct fbnic_dev;
12 struct fbnic_tlv_msg;
13 
14 struct fbnic_fw_mbx {
15 	u8 ready, head, tail;
16 	u64 resp_error;
17 	struct {
18 		struct fbnic_tlv_msg	*msg;
19 		dma_addr_t		addr;
20 	} buf_info[FBNIC_IPC_MBX_DESC_LEN];
21 };
22 
23 // FW_VER_MAX_SIZE must match ETHTOOL_FWVERS_LEN
24 #define FBNIC_FW_VER_MAX_SIZE			32
25 // Formatted version is in the format XX.YY.ZZ_RRR_COMMIT
26 #define FBNIC_FW_CAP_RESP_COMMIT_MAX_SIZE	(FBNIC_FW_VER_MAX_SIZE - 13)
27 #define FBNIC_FW_LOG_VERSION			1
28 #define FBNIC_FW_LOG_MAX_SIZE			256
29 /*
30  * The max amount of logs which can fit in a single mailbox message. Firmware
31  * assumes each mailbox message is 4096B. The amount of messages supported is
32  * calculated as 4096 minus headers for message, arrays, and length minus the
33  * size of length divided by headers for each array plus the maximum LOG size,
34  * and the size of MSEC and INDEX. Put another way:
35  *
36  * MAX_LOG_HISTORY = ((4096 - TLV_HDR_SZ * 5 - LENGTH_SZ)
37  *                    / (FBNIC_FW_LOG_MAX_SIZE + TLV_HDR_SZ * 3 + MSEC_SZ
38  *                       + INDEX_SZ))
39  */
40 #define FBNIC_FW_MAX_LOG_HISTORY		14
41 #define FBNIC_MBX_RX_TO_SEC			10
42 
43 struct fbnic_fw_ver {
44 	u32 version;
45 	char commit[FBNIC_FW_CAP_RESP_COMMIT_MAX_SIZE];
46 };
47 
48 struct fbnic_fw_cap {
49 	struct {
50 		struct fbnic_fw_ver mgmt, bootloader;
51 	} running;
52 	struct {
53 		struct fbnic_fw_ver mgmt, bootloader, undi;
54 	} stored;
55 	u8	active_slot;
56 	u8	bmc_mac_addr[4][ETH_ALEN];
57 	u8	bmc_present		: 1;
58 	u8	need_bmc_tcam_reinit	: 1;
59 	u8	need_bmc_macda_sync	: 1;
60 	u8	all_multi		: 1;
61 	u8	link_speed;
62 	u8	link_fec;
63 	u32	anti_rollback_version;
64 };
65 
66 struct fbnic_fw_completion {
67 	u32 msg_type;
68 	struct completion done;
69 	struct kref ref_count;
70 	int result;
71 	union {
72 		struct {
73 			u32 size;
74 		} coredump_info;
75 		struct {
76 			u32 size;
77 			u16 stride;
78 			u8 *data[];
79 		} coredump;
80 		struct {
81 			u32 offset;
82 			u32 length;
83 		} fw_update;
84 		struct {
85 			u16 length;
86 			u8 offset;
87 			u8 page;
88 			u8 bank;
89 			u8 data[] __aligned(sizeof(u32)) __counted_by(length);
90 		} qsfp;
91 		struct {
92 			s32 millivolts;
93 			s32 millidegrees;
94 		} tsene;
95 	} u;
96 };
97 
98 u64 __fbnic_mbx_rd_desc(struct fbnic_dev *fbd, int mbx_idx, int desc_idx);
99 void fbnic_mbx_init(struct fbnic_dev *fbd);
100 void fbnic_mbx_clean(struct fbnic_dev *fbd);
101 int fbnic_mbx_set_cmpl(struct fbnic_dev *fbd,
102 		       struct fbnic_fw_completion *cmpl_data);
103 void fbnic_mbx_clear_cmpl(struct fbnic_dev *fbd,
104 			  struct fbnic_fw_completion *cmpl_data);
105 void fbnic_mbx_poll(struct fbnic_dev *fbd);
106 int fbnic_mbx_poll_tx_ready(struct fbnic_dev *fbd);
107 void fbnic_mbx_flush_tx(struct fbnic_dev *fbd);
108 
109 /**
110  * enum fbnic_fw_self_test_codes - return codes from self test routines
111  *
112  * These are the codes returned from the self test routines and
113  * stored in the test result array indexed by the specific
114  * test name.
115  *
116  * @FBNIC_TEST_FW_SUCCESS: test success
117  * @FBNIC_TEST_FW_NO_FIRMWARE: FW interface not present
118  * @FBNIC_TEST_FW_NO_CMPL: No completion available
119  * @FBNIC_TEST_FW_NO_XMIT: Could not xmit message
120  * @FBNIC_TEST_FW_NO_MSG: no message returned
121  * @FBNIC_TEST_FW_PARSE: returned message had parsing error
122  */
123 enum fbnic_fw_self_test_codes {
124 	FBNIC_TEST_FW_SUCCESS = 0,
125 	FBNIC_TEST_FW_NO_FIRMWARE = 10,
126 	FBNIC_TEST_FW_NO_CMPL = 20,
127 	FBNIC_TEST_FW_NO_XMIT = 30,
128 	FBNIC_TEST_FW_NO_MSG = 40,
129 	FBNIC_TEST_FW_PARSE = 50,
130 };
131 
132 enum fbnic_fw_self_test_codes fbnic_fw_mbx_self_test(struct fbnic_dev *fbd);
133 int fbnic_fw_xmit_test_msg(struct fbnic_dev *fbd,
134 			   struct fbnic_fw_completion *c);
135 int fbnic_fw_xmit_ownership_msg(struct fbnic_dev *fbd, bool take_ownership);
136 int fbnic_fw_init_heartbeat(struct fbnic_dev *fbd, bool poll);
137 void fbnic_fw_check_heartbeat(struct fbnic_dev *fbd);
138 int fbnic_fw_xmit_coredump_info_msg(struct fbnic_dev *fbd,
139 				    struct fbnic_fw_completion *cmpl_data,
140 				    bool force);
141 int fbnic_fw_xmit_coredump_read_msg(struct fbnic_dev *fbd,
142 				    struct fbnic_fw_completion *cmpl_data,
143 				    u32 offset, u32 length);
144 int fbnic_fw_xmit_fw_start_upgrade(struct fbnic_dev *fbd,
145 				   struct fbnic_fw_completion *cmpl_data,
146 				   unsigned int id, unsigned int len);
147 int fbnic_fw_xmit_fw_write_chunk(struct fbnic_dev *fbd,
148 				 const u8 *data, u32 offset, u16 length,
149 				 int cancel_error);
150 int fbnic_fw_xmit_qsfp_read_msg(struct fbnic_dev *fbd,
151 				struct fbnic_fw_completion *cmpl_data,
152 				u32 page, u32 bank, u32 offset, u32 length);
153 int fbnic_fw_xmit_tsene_read_msg(struct fbnic_dev *fbd,
154 				 struct fbnic_fw_completion *cmpl_data);
155 int fbnic_fw_xmit_send_logs(struct fbnic_dev *fbd, bool enable,
156 			    bool send_log_history);
157 int fbnic_fw_xmit_rpc_macda_sync(struct fbnic_dev *fbd);
158 struct fbnic_fw_completion *__fbnic_fw_alloc_cmpl(u32 msg_type,
159 						  size_t priv_size);
160 struct fbnic_fw_completion *fbnic_fw_alloc_cmpl(u32 msg_type);
161 void fbnic_fw_put_cmpl(struct fbnic_fw_completion *cmpl_data);
162 
163 static inline unsigned long
fbnic_mbx_wait_for_cmpl(struct fbnic_fw_completion * cmpl)164 fbnic_mbx_wait_for_cmpl(struct fbnic_fw_completion *cmpl)
165 {
166 	return wait_for_completion_timeout(&cmpl->done,
167 					   FBNIC_MBX_RX_TO_SEC * HZ);
168 }
169 
170 #define fbnic_mk_full_fw_ver_str(_rev_id, _delim, _commit, _str, _str_sz) \
171 do {									\
172 	const u32 __rev_id = _rev_id;					\
173 	snprintf(_str, _str_sz, "%02lu.%02lu.%02lu-%03lu%s%s",	\
174 		 FIELD_GET(FBNIC_FW_CAP_RESP_VERSION_MAJOR, __rev_id),	\
175 		 FIELD_GET(FBNIC_FW_CAP_RESP_VERSION_MINOR, __rev_id),	\
176 		 FIELD_GET(FBNIC_FW_CAP_RESP_VERSION_PATCH, __rev_id),	\
177 		 FIELD_GET(FBNIC_FW_CAP_RESP_VERSION_BUILD, __rev_id),	\
178 		 _delim, _commit);					\
179 } while (0)
180 
181 #define fbnic_mk_fw_ver_str(_rev_id, _str) \
182 	fbnic_mk_full_fw_ver_str(_rev_id, "", "", _str, sizeof(_str))
183 
184 enum {
185 	QSPI_SECTION_CMRT			= 0,
186 	QSPI_SECTION_CONTROL_FW			= 1,
187 	QSPI_SECTION_UCODE			= 2,
188 	QSPI_SECTION_OPTION_ROM			= 3,
189 	QSPI_SECTION_USER			= 4,
190 	QSPI_SECTION_INVALID,
191 };
192 
193 #define FW_HEARTBEAT_PERIOD		(10 * HZ)
194 
195 enum {
196 	FBNIC_TLV_MSG_ID_HOST_CAP_REQ			= 0x10,
197 	FBNIC_TLV_MSG_ID_FW_CAP_RESP			= 0x11,
198 	FBNIC_TLV_MSG_ID_OWNERSHIP_REQ			= 0x12,
199 	FBNIC_TLV_MSG_ID_OWNERSHIP_RESP			= 0x13,
200 	FBNIC_TLV_MSG_ID_HEARTBEAT_REQ			= 0x14,
201 	FBNIC_TLV_MSG_ID_HEARTBEAT_RESP			= 0x15,
202 	FBNIC_TLV_MSG_ID_COREDUMP_GET_INFO_REQ		= 0x18,
203 	FBNIC_TLV_MSG_ID_COREDUMP_GET_INFO_RESP		= 0x19,
204 	FBNIC_TLV_MSG_ID_COREDUMP_READ_REQ		= 0x20,
205 	FBNIC_TLV_MSG_ID_COREDUMP_READ_RESP		= 0x21,
206 	FBNIC_TLV_MSG_ID_FW_START_UPGRADE_REQ		= 0x22,
207 	FBNIC_TLV_MSG_ID_FW_START_UPGRADE_RESP		= 0x23,
208 	FBNIC_TLV_MSG_ID_FW_WRITE_CHUNK_REQ		= 0x24,
209 	FBNIC_TLV_MSG_ID_FW_WRITE_CHUNK_RESP		= 0x25,
210 	FBNIC_TLV_MSG_ID_FW_FINISH_UPGRADE_REQ		= 0x28,
211 	FBNIC_TLV_MSG_ID_FW_FINISH_UPGRADE_RESP		= 0x29,
212 	FBNIC_TLV_MSG_ID_QSFP_READ_REQ			= 0x38,
213 	FBNIC_TLV_MSG_ID_QSFP_READ_RESP			= 0x39,
214 	FBNIC_TLV_MSG_ID_TSENE_READ_REQ			= 0x3C,
215 	FBNIC_TLV_MSG_ID_TSENE_READ_RESP		= 0x3D,
216 	FBNIC_TLV_MSG_ID_LOG_SEND_LOGS_REQ		= 0x43,
217 	FBNIC_TLV_MSG_ID_LOG_MSG_REQ			= 0x44,
218 	FBNIC_TLV_MSG_ID_LOG_MSG_RESP			= 0x45,
219 	FBNIC_TLV_MSG_ID_RPC_MAC_SYNC_REQ		= 0x46,
220 };
221 
222 #define FBNIC_FW_CAP_RESP_VERSION_MAJOR		CSR_GENMASK(31, 24)
223 #define FBNIC_FW_CAP_RESP_VERSION_MINOR		CSR_GENMASK(23, 16)
224 #define FBNIC_FW_CAP_RESP_VERSION_PATCH		CSR_GENMASK(15, 8)
225 #define FBNIC_FW_CAP_RESP_VERSION_BUILD		CSR_GENMASK(7, 0)
226 enum {
227 	FBNIC_FW_CAP_RESP_VERSION			= 0x0,
228 	FBNIC_FW_CAP_RESP_BMC_PRESENT			= 0x1,
229 	FBNIC_FW_CAP_RESP_BMC_MAC_ADDR			= 0x2,
230 	FBNIC_FW_CAP_RESP_BMC_MAC_ARRAY			= 0x3,
231 	FBNIC_FW_CAP_RESP_STORED_VERSION		= 0x4,
232 	FBNIC_FW_CAP_RESP_ACTIVE_FW_SLOT		= 0x5,
233 	FBNIC_FW_CAP_RESP_VERSION_COMMIT_STR		= 0x6,
234 	FBNIC_FW_CAP_RESP_BMC_ALL_MULTI			= 0x8,
235 	FBNIC_FW_CAP_RESP_FW_STATE			= 0x9,
236 	FBNIC_FW_CAP_RESP_FW_LINK_SPEED			= 0xa,
237 	FBNIC_FW_CAP_RESP_FW_LINK_FEC			= 0xb,
238 	FBNIC_FW_CAP_RESP_STORED_COMMIT_STR		= 0xc,
239 	FBNIC_FW_CAP_RESP_CMRT_VERSION			= 0xd,
240 	FBNIC_FW_CAP_RESP_STORED_CMRT_VERSION		= 0xe,
241 	FBNIC_FW_CAP_RESP_CMRT_COMMIT_STR		= 0xf,
242 	FBNIC_FW_CAP_RESP_STORED_CMRT_COMMIT_STR	= 0x10,
243 	FBNIC_FW_CAP_RESP_UEFI_VERSION			= 0x11,
244 	FBNIC_FW_CAP_RESP_UEFI_COMMIT_STR		= 0x12,
245 	FBNIC_FW_CAP_RESP_ANTI_ROLLBACK_VERSION		= 0x15,
246 	FBNIC_FW_CAP_RESP_MSG_MAX
247 };
248 
249 enum {
250 	FBNIC_FW_LINK_MODE_25CR			= 1,
251 	FBNIC_FW_LINK_MODE_50CR2		= 2,
252 	FBNIC_FW_LINK_MODE_50CR			= 3,
253 	FBNIC_FW_LINK_MODE_100CR2		= 4,
254 };
255 
256 enum {
257 	FBNIC_FW_LINK_FEC_NONE			= 1,
258 	FBNIC_FW_LINK_FEC_RS			= 2,
259 	FBNIC_FW_LINK_FEC_BASER			= 3,
260 };
261 
262 enum {
263 	FBNIC_FW_QSFP_BANK			= 0x0,
264 	FBNIC_FW_QSFP_PAGE			= 0x1,
265 	FBNIC_FW_QSFP_OFFSET			= 0x2,
266 	FBNIC_FW_QSFP_LENGTH			= 0x3,
267 	FBNIC_FW_QSFP_ERROR			= 0x4,
268 	FBNIC_FW_QSFP_DATA			= 0x5,
269 	FBNIC_FW_QSFP_MSG_MAX
270 };
271 
272 enum {
273 	FBNIC_FW_TSENE_THERM			= 0x0,
274 	FBNIC_FW_TSENE_VOLT			= 0x1,
275 	FBNIC_FW_TSENE_ERROR			= 0x2,
276 	FBNIC_FW_TSENE_MSG_MAX
277 };
278 
279 enum {
280 	FBNIC_FW_OWNERSHIP_FLAG			= 0x0,
281 	FBNIC_FW_OWNERSHIP_TIME			= 0x1,
282 	FBNIC_FW_OWNERSHIP_MSG_MAX
283 };
284 
285 enum {
286 	FBNIC_FW_HEARTBEAT_UPTIME               = 0x0,
287 	FBNIC_FW_HEARTBEAT_NUMBER_OF_MESSAGES   = 0x1,
288 	FBNIC_FW_HEARTBEAT_MSG_MAX
289 };
290 
291 enum {
292 	FBNIC_FW_COREDUMP_REQ_INFO_CREATE	= 0x0,
293 	FBNIC_FW_COREDUMP_REQ_INFO_MSG_MAX
294 };
295 
296 enum {
297 	FBNIC_FW_COREDUMP_INFO_AVAILABLE	= 0x0,
298 	FBNIC_FW_COREDUMP_INFO_SIZE		= 0x1,
299 	FBNIC_FW_COREDUMP_INFO_ERROR		= 0x2,
300 	FBNIC_FW_COREDUMP_INFO_MSG_MAX
301 };
302 
303 enum {
304 	FBNIC_FW_COREDUMP_READ_OFFSET		= 0x0,
305 	FBNIC_FW_COREDUMP_READ_LENGTH		= 0x1,
306 	FBNIC_FW_COREDUMP_READ_DATA		= 0x2,
307 	FBNIC_FW_COREDUMP_READ_ERROR		= 0x3,
308 	FBNIC_FW_COREDUMP_READ_MSG_MAX
309 };
310 
311 enum {
312 	FBNIC_FW_START_UPGRADE_ERROR		= 0x0,
313 	FBNIC_FW_START_UPGRADE_SECTION		= 0x1,
314 	FBNIC_FW_START_UPGRADE_IMAGE_LENGTH	= 0x2,
315 	FBNIC_FW_START_UPGRADE_MSG_MAX
316 };
317 
318 enum {
319 	FBNIC_FW_WRITE_CHUNK_OFFSET		= 0x0,
320 	FBNIC_FW_WRITE_CHUNK_LENGTH		= 0x1,
321 	FBNIC_FW_WRITE_CHUNK_DATA		= 0x2,
322 	FBNIC_FW_WRITE_CHUNK_ERROR		= 0x3,
323 	FBNIC_FW_WRITE_CHUNK_MSG_MAX
324 };
325 
326 enum {
327 	FBNIC_FW_FINISH_UPGRADE_ERROR		= 0x0,
328 	FBNIC_FW_FINISH_UPGRADE_MSG_MAX
329 };
330 
331 enum {
332 	FBNIC_SEND_LOGS				= 0x0,
333 	FBNIC_SEND_LOGS_VERSION			= 0x1,
334 	FBNIC_SEND_LOGS_HISTORY			= 0x2,
335 	FBNIC_SEND_LOGS_MSG_MAX
336 };
337 
338 enum {
339 	FBNIC_FW_LOG_MSEC			= 0x0,
340 	FBNIC_FW_LOG_INDEX			= 0x1,
341 	FBNIC_FW_LOG_MSG			= 0x2,
342 	FBNIC_FW_LOG_LENGTH			= 0x3,
343 	FBNIC_FW_LOG_MSEC_ARRAY			= 0x4,
344 	FBNIC_FW_LOG_INDEX_ARRAY		= 0x5,
345 	FBNIC_FW_LOG_MSG_ARRAY			= 0x6,
346 	FBNIC_FW_LOG_MSG_MAX
347 };
348 
349 enum {
350 	FBNIC_FW_RPC_MAC_SYNC_RX_FLAGS		= 0x0,
351 	FBNIC_FW_RPC_MAC_SYNC_UC_ARRAY		= 0x1,
352 	FBNIC_FW_RPC_MAC_SYNC_MC_ARRAY		= 0x2,
353 	FBNIC_FW_RPC_MAC_SYNC_MAC_ADDR		= 0x3,
354 	FBNIC_FW_RPC_MAC_SYNC_MSG_MAX
355 };
356 
357 #define FW_RPC_MAC_SYNC_RX_FLAGS_PROMISC	1
358 #define FW_RPC_MAC_SYNC_RX_FLAGS_ALLMULTI	2
359 #define FW_RPC_MAC_SYNC_RX_FLAGS_BROADCAST	4
360 
361 #define FW_RPC_MAC_SYNC_UC_ARRAY_SIZE		8
362 #define FW_RPC_MAC_SYNC_MC_ARRAY_SIZE		8
363 
364 #endif /* _FBNIC_FW_H_ */
365