xref: /linux/drivers/net/ethernet/meta/fbnic/fbnic_fw.h (revision 8be4d31cb8aaeea27bde4b7ddb26e28a89062ebf)
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/if_ether.h>
8 #include <linux/types.h>
9 
10 struct fbnic_dev;
11 struct fbnic_tlv_msg;
12 
13 struct fbnic_fw_mbx {
14 	u8 ready, head, tail;
15 	struct {
16 		struct fbnic_tlv_msg	*msg;
17 		dma_addr_t		addr;
18 	} buf_info[FBNIC_IPC_MBX_DESC_LEN];
19 };
20 
21 // FW_VER_MAX_SIZE must match ETHTOOL_FWVERS_LEN
22 #define FBNIC_FW_VER_MAX_SIZE			32
23 // Formatted version is in the format XX.YY.ZZ_RRR_COMMIT
24 #define FBNIC_FW_CAP_RESP_COMMIT_MAX_SIZE	(FBNIC_FW_VER_MAX_SIZE - 13)
25 #define FBNIC_FW_LOG_VERSION			1
26 #define FBNIC_FW_LOG_MAX_SIZE			256
27 /*
28  * The max amount of logs which can fit in a single mailbox message. Firmware
29  * assumes each mailbox message is 4096B. The amount of messages supported is
30  * calculated as 4096 minus headers for message, arrays, and length minus the
31  * size of length divided by headers for each array plus the maximum LOG size,
32  * and the size of MSEC and INDEX. Put another way:
33  *
34  * MAX_LOG_HISTORY = ((4096 - TLV_HDR_SZ * 5 - LENGTH_SZ)
35  *                    / (FBNIC_FW_LOG_MAX_SIZE + TLV_HDR_SZ * 3 + MSEC_SZ
36  *                       + INDEX_SZ))
37  */
38 #define FBNIC_FW_MAX_LOG_HISTORY		14
39 
40 struct fbnic_fw_ver {
41 	u32 version;
42 	char commit[FBNIC_FW_CAP_RESP_COMMIT_MAX_SIZE];
43 };
44 
45 struct fbnic_fw_cap {
46 	struct {
47 		struct fbnic_fw_ver mgmt, bootloader;
48 	} running;
49 	struct {
50 		struct fbnic_fw_ver mgmt, bootloader, undi;
51 	} stored;
52 	u8	active_slot;
53 	u8	bmc_mac_addr[4][ETH_ALEN];
54 	u8	bmc_present	: 1;
55 	u8	all_multi	: 1;
56 	u8	link_speed;
57 	u8	link_fec;
58 	u32	anti_rollback_version;
59 };
60 
61 struct fbnic_fw_completion {
62 	u32 msg_type;
63 	struct completion done;
64 	struct kref ref_count;
65 	int result;
66 	union {
67 		struct {
68 			u32 offset;
69 			u32 length;
70 		} fw_update;
71 		struct {
72 			s32 millivolts;
73 			s32 millidegrees;
74 		} tsene;
75 	} u;
76 };
77 
78 void fbnic_mbx_init(struct fbnic_dev *fbd);
79 void fbnic_mbx_clean(struct fbnic_dev *fbd);
80 int fbnic_mbx_set_cmpl(struct fbnic_dev *fbd,
81 		       struct fbnic_fw_completion *cmpl_data);
82 void fbnic_mbx_clear_cmpl(struct fbnic_dev *fbd,
83 			  struct fbnic_fw_completion *cmpl_data);
84 void fbnic_mbx_poll(struct fbnic_dev *fbd);
85 int fbnic_mbx_poll_tx_ready(struct fbnic_dev *fbd);
86 void fbnic_mbx_flush_tx(struct fbnic_dev *fbd);
87 int fbnic_fw_xmit_ownership_msg(struct fbnic_dev *fbd, bool take_ownership);
88 int fbnic_fw_init_heartbeat(struct fbnic_dev *fbd, bool poll);
89 void fbnic_fw_check_heartbeat(struct fbnic_dev *fbd);
90 int fbnic_fw_xmit_fw_start_upgrade(struct fbnic_dev *fbd,
91 				   struct fbnic_fw_completion *cmpl_data,
92 				   unsigned int id, unsigned int len);
93 int fbnic_fw_xmit_fw_write_chunk(struct fbnic_dev *fbd,
94 				 const u8 *data, u32 offset, u16 length,
95 				 int cancel_error);
96 int fbnic_fw_xmit_tsene_read_msg(struct fbnic_dev *fbd,
97 				 struct fbnic_fw_completion *cmpl_data);
98 int fbnic_fw_xmit_send_logs(struct fbnic_dev *fbd, bool enable,
99 			    bool send_log_history);
100 struct fbnic_fw_completion *fbnic_fw_alloc_cmpl(u32 msg_type);
101 void fbnic_fw_put_cmpl(struct fbnic_fw_completion *cmpl_data);
102 
103 #define fbnic_mk_full_fw_ver_str(_rev_id, _delim, _commit, _str, _str_sz) \
104 do {									\
105 	const u32 __rev_id = _rev_id;					\
106 	snprintf(_str, _str_sz, "%02lu.%02lu.%02lu-%03lu%s%s",	\
107 		 FIELD_GET(FBNIC_FW_CAP_RESP_VERSION_MAJOR, __rev_id),	\
108 		 FIELD_GET(FBNIC_FW_CAP_RESP_VERSION_MINOR, __rev_id),	\
109 		 FIELD_GET(FBNIC_FW_CAP_RESP_VERSION_PATCH, __rev_id),	\
110 		 FIELD_GET(FBNIC_FW_CAP_RESP_VERSION_BUILD, __rev_id),	\
111 		 _delim, _commit);					\
112 } while (0)
113 
114 #define fbnic_mk_fw_ver_str(_rev_id, _str) \
115 	fbnic_mk_full_fw_ver_str(_rev_id, "", "", _str, sizeof(_str))
116 
117 enum {
118 	QSPI_SECTION_CMRT			= 0,
119 	QSPI_SECTION_CONTROL_FW			= 1,
120 	QSPI_SECTION_UCODE			= 2,
121 	QSPI_SECTION_OPTION_ROM			= 3,
122 	QSPI_SECTION_USER			= 4,
123 	QSPI_SECTION_INVALID,
124 };
125 
126 #define FW_HEARTBEAT_PERIOD		(10 * HZ)
127 
128 enum {
129 	FBNIC_TLV_MSG_ID_HOST_CAP_REQ			= 0x10,
130 	FBNIC_TLV_MSG_ID_FW_CAP_RESP			= 0x11,
131 	FBNIC_TLV_MSG_ID_OWNERSHIP_REQ			= 0x12,
132 	FBNIC_TLV_MSG_ID_OWNERSHIP_RESP			= 0x13,
133 	FBNIC_TLV_MSG_ID_HEARTBEAT_REQ			= 0x14,
134 	FBNIC_TLV_MSG_ID_HEARTBEAT_RESP			= 0x15,
135 	FBNIC_TLV_MSG_ID_FW_START_UPGRADE_REQ		= 0x22,
136 	FBNIC_TLV_MSG_ID_FW_START_UPGRADE_RESP		= 0x23,
137 	FBNIC_TLV_MSG_ID_FW_WRITE_CHUNK_REQ		= 0x24,
138 	FBNIC_TLV_MSG_ID_FW_WRITE_CHUNK_RESP		= 0x25,
139 	FBNIC_TLV_MSG_ID_FW_FINISH_UPGRADE_REQ		= 0x28,
140 	FBNIC_TLV_MSG_ID_FW_FINISH_UPGRADE_RESP		= 0x29,
141 	FBNIC_TLV_MSG_ID_TSENE_READ_REQ			= 0x3C,
142 	FBNIC_TLV_MSG_ID_TSENE_READ_RESP		= 0x3D,
143 	FBNIC_TLV_MSG_ID_LOG_SEND_LOGS_REQ		= 0x43,
144 	FBNIC_TLV_MSG_ID_LOG_MSG_REQ			= 0x44,
145 	FBNIC_TLV_MSG_ID_LOG_MSG_RESP			= 0x45,
146 };
147 
148 #define FBNIC_FW_CAP_RESP_VERSION_MAJOR		CSR_GENMASK(31, 24)
149 #define FBNIC_FW_CAP_RESP_VERSION_MINOR		CSR_GENMASK(23, 16)
150 #define FBNIC_FW_CAP_RESP_VERSION_PATCH		CSR_GENMASK(15, 8)
151 #define FBNIC_FW_CAP_RESP_VERSION_BUILD		CSR_GENMASK(7, 0)
152 enum {
153 	FBNIC_FW_CAP_RESP_VERSION			= 0x0,
154 	FBNIC_FW_CAP_RESP_BMC_PRESENT			= 0x1,
155 	FBNIC_FW_CAP_RESP_BMC_MAC_ADDR			= 0x2,
156 	FBNIC_FW_CAP_RESP_BMC_MAC_ARRAY			= 0x3,
157 	FBNIC_FW_CAP_RESP_STORED_VERSION		= 0x4,
158 	FBNIC_FW_CAP_RESP_ACTIVE_FW_SLOT		= 0x5,
159 	FBNIC_FW_CAP_RESP_VERSION_COMMIT_STR		= 0x6,
160 	FBNIC_FW_CAP_RESP_BMC_ALL_MULTI			= 0x8,
161 	FBNIC_FW_CAP_RESP_FW_STATE			= 0x9,
162 	FBNIC_FW_CAP_RESP_FW_LINK_SPEED			= 0xa,
163 	FBNIC_FW_CAP_RESP_FW_LINK_FEC			= 0xb,
164 	FBNIC_FW_CAP_RESP_STORED_COMMIT_STR		= 0xc,
165 	FBNIC_FW_CAP_RESP_CMRT_VERSION			= 0xd,
166 	FBNIC_FW_CAP_RESP_STORED_CMRT_VERSION		= 0xe,
167 	FBNIC_FW_CAP_RESP_CMRT_COMMIT_STR		= 0xf,
168 	FBNIC_FW_CAP_RESP_STORED_CMRT_COMMIT_STR	= 0x10,
169 	FBNIC_FW_CAP_RESP_UEFI_VERSION			= 0x11,
170 	FBNIC_FW_CAP_RESP_UEFI_COMMIT_STR		= 0x12,
171 	FBNIC_FW_CAP_RESP_ANTI_ROLLBACK_VERSION		= 0x15,
172 	FBNIC_FW_CAP_RESP_MSG_MAX
173 };
174 
175 enum {
176 	FBNIC_FW_LINK_MODE_25CR			= 1,
177 	FBNIC_FW_LINK_MODE_50CR2		= 2,
178 	FBNIC_FW_LINK_MODE_50CR			= 3,
179 	FBNIC_FW_LINK_MODE_100CR2		= 4,
180 };
181 
182 enum {
183 	FBNIC_FW_LINK_FEC_NONE			= 1,
184 	FBNIC_FW_LINK_FEC_RS			= 2,
185 	FBNIC_FW_LINK_FEC_BASER			= 3,
186 };
187 
188 enum {
189 	FBNIC_FW_TSENE_THERM			= 0x0,
190 	FBNIC_FW_TSENE_VOLT			= 0x1,
191 	FBNIC_FW_TSENE_ERROR			= 0x2,
192 	FBNIC_FW_TSENE_MSG_MAX
193 };
194 
195 enum {
196 	FBNIC_FW_OWNERSHIP_FLAG			= 0x0,
197 	FBNIC_FW_OWNERSHIP_MSG_MAX
198 };
199 
200 enum {
201 	FBNIC_FW_START_UPGRADE_ERROR		= 0x0,
202 	FBNIC_FW_START_UPGRADE_SECTION		= 0x1,
203 	FBNIC_FW_START_UPGRADE_IMAGE_LENGTH	= 0x2,
204 	FBNIC_FW_START_UPGRADE_MSG_MAX
205 };
206 
207 enum {
208 	FBNIC_FW_WRITE_CHUNK_OFFSET		= 0x0,
209 	FBNIC_FW_WRITE_CHUNK_LENGTH		= 0x1,
210 	FBNIC_FW_WRITE_CHUNK_DATA		= 0x2,
211 	FBNIC_FW_WRITE_CHUNK_ERROR		= 0x3,
212 	FBNIC_FW_WRITE_CHUNK_MSG_MAX
213 };
214 
215 enum {
216 	FBNIC_FW_FINISH_UPGRADE_ERROR		= 0x0,
217 	FBNIC_FW_FINISH_UPGRADE_MSG_MAX
218 };
219 
220 enum {
221 	FBNIC_SEND_LOGS				= 0x0,
222 	FBNIC_SEND_LOGS_VERSION			= 0x1,
223 	FBNIC_SEND_LOGS_HISTORY			= 0x2,
224 	FBNIC_SEND_LOGS_MSG_MAX
225 };
226 
227 enum {
228 	FBNIC_FW_LOG_MSEC			= 0x0,
229 	FBNIC_FW_LOG_INDEX			= 0x1,
230 	FBNIC_FW_LOG_MSG			= 0x2,
231 	FBNIC_FW_LOG_LENGTH			= 0x3,
232 	FBNIC_FW_LOG_MSEC_ARRAY			= 0x4,
233 	FBNIC_FW_LOG_INDEX_ARRAY		= 0x5,
234 	FBNIC_FW_LOG_MSG_ARRAY			= 0x6,
235 	FBNIC_FW_LOG_MSG_MAX
236 };
237 
238 #endif /* _FBNIC_FW_H_ */
239