xref: /linux/drivers/net/ethernet/meta/fbnic/fbnic_fw.h (revision 9410645520e9b820069761f3450ef6661418e279)
1da3cde08SAlexander Duyck /* SPDX-License-Identifier: GPL-2.0 */
2da3cde08SAlexander Duyck /* Copyright (c) Meta Platforms, Inc. and affiliates. */
3da3cde08SAlexander Duyck 
4da3cde08SAlexander Duyck #ifndef _FBNIC_FW_H_
5da3cde08SAlexander Duyck #define _FBNIC_FW_H_
6da3cde08SAlexander Duyck 
720d2e88cSAlexander Duyck #include <linux/if_ether.h>
8da3cde08SAlexander Duyck #include <linux/types.h>
9da3cde08SAlexander Duyck 
10da3cde08SAlexander Duyck struct fbnic_dev;
11da3cde08SAlexander Duyck struct fbnic_tlv_msg;
12da3cde08SAlexander Duyck 
13da3cde08SAlexander Duyck struct fbnic_fw_mbx {
14da3cde08SAlexander Duyck 	u8 ready, head, tail;
15da3cde08SAlexander Duyck 	struct {
16da3cde08SAlexander Duyck 		struct fbnic_tlv_msg	*msg;
17da3cde08SAlexander Duyck 		dma_addr_t		addr;
18da3cde08SAlexander Duyck 	} buf_info[FBNIC_IPC_MBX_DESC_LEN];
19da3cde08SAlexander Duyck };
20da3cde08SAlexander Duyck 
2120d2e88cSAlexander Duyck // FW_VER_MAX_SIZE must match ETHTOOL_FWVERS_LEN
2220d2e88cSAlexander Duyck #define FBNIC_FW_VER_MAX_SIZE	                32
2320d2e88cSAlexander Duyck // Formatted version is in the format XX.YY.ZZ_RRR_COMMIT
2420d2e88cSAlexander Duyck #define FBNIC_FW_CAP_RESP_COMMIT_MAX_SIZE	(FBNIC_FW_VER_MAX_SIZE - 13)
2520d2e88cSAlexander Duyck #define FBNIC_FW_LOG_MAX_SIZE	                256
2620d2e88cSAlexander Duyck 
2720d2e88cSAlexander Duyck struct fbnic_fw_ver {
2820d2e88cSAlexander Duyck 	u32 version;
2920d2e88cSAlexander Duyck 	char commit[FBNIC_FW_CAP_RESP_COMMIT_MAX_SIZE];
3020d2e88cSAlexander Duyck };
3120d2e88cSAlexander Duyck 
3220d2e88cSAlexander Duyck struct fbnic_fw_cap {
3320d2e88cSAlexander Duyck 	struct {
3420d2e88cSAlexander Duyck 		struct fbnic_fw_ver mgmt, bootloader;
3520d2e88cSAlexander Duyck 	} running;
3620d2e88cSAlexander Duyck 	struct {
3720d2e88cSAlexander Duyck 		struct fbnic_fw_ver mgmt, bootloader, undi;
3820d2e88cSAlexander Duyck 	} stored;
3920d2e88cSAlexander Duyck 	u8	active_slot;
4020d2e88cSAlexander Duyck 	u8	bmc_mac_addr[4][ETH_ALEN];
4120d2e88cSAlexander Duyck 	u8	bmc_present	: 1;
4220d2e88cSAlexander Duyck 	u8	all_multi	: 1;
4320d2e88cSAlexander Duyck 	u8	link_speed;
4420d2e88cSAlexander Duyck 	u8	link_fec;
4520d2e88cSAlexander Duyck };
4620d2e88cSAlexander Duyck 
47da3cde08SAlexander Duyck void fbnic_mbx_init(struct fbnic_dev *fbd);
48da3cde08SAlexander Duyck void fbnic_mbx_clean(struct fbnic_dev *fbd);
49da3cde08SAlexander Duyck void fbnic_mbx_poll(struct fbnic_dev *fbd);
50da3cde08SAlexander Duyck int fbnic_mbx_poll_tx_ready(struct fbnic_dev *fbd);
51da3cde08SAlexander Duyck void fbnic_mbx_flush_tx(struct fbnic_dev *fbd);
5220d2e88cSAlexander Duyck int fbnic_fw_xmit_ownership_msg(struct fbnic_dev *fbd, bool take_ownership);
5320d2e88cSAlexander Duyck int fbnic_fw_init_heartbeat(struct fbnic_dev *fbd, bool poll);
5420d2e88cSAlexander Duyck void fbnic_fw_check_heartbeat(struct fbnic_dev *fbd);
55da3cde08SAlexander Duyck 
56*bd2557a5SMohsin Bashir #define fbnic_mk_full_fw_ver_str(_rev_id, _delim, _commit, _str, _str_sz) \
5720d2e88cSAlexander Duyck do {									\
5820d2e88cSAlexander Duyck 	const u32 __rev_id = _rev_id;					\
59*bd2557a5SMohsin Bashir 	snprintf(_str, _str_sz, "%02lu.%02lu.%02lu-%03lu%s%s",	\
6020d2e88cSAlexander Duyck 		 FIELD_GET(FBNIC_FW_CAP_RESP_VERSION_MAJOR, __rev_id),	\
6120d2e88cSAlexander Duyck 		 FIELD_GET(FBNIC_FW_CAP_RESP_VERSION_MINOR, __rev_id),	\
6220d2e88cSAlexander Duyck 		 FIELD_GET(FBNIC_FW_CAP_RESP_VERSION_PATCH, __rev_id),	\
6320d2e88cSAlexander Duyck 		 FIELD_GET(FBNIC_FW_CAP_RESP_VERSION_BUILD, __rev_id),	\
6420d2e88cSAlexander Duyck 		 _delim, _commit);					\
6520d2e88cSAlexander Duyck } while (0)
6620d2e88cSAlexander Duyck 
6720d2e88cSAlexander Duyck #define fbnic_mk_fw_ver_str(_rev_id, _str) \
68*bd2557a5SMohsin Bashir 	fbnic_mk_full_fw_ver_str(_rev_id, "", "", _str, sizeof(_str))
6920d2e88cSAlexander Duyck 
7020d2e88cSAlexander Duyck #define FW_HEARTBEAT_PERIOD		(10 * HZ)
7120d2e88cSAlexander Duyck 
7220d2e88cSAlexander Duyck enum {
7320d2e88cSAlexander Duyck 	FBNIC_TLV_MSG_ID_HOST_CAP_REQ			= 0x10,
7420d2e88cSAlexander Duyck 	FBNIC_TLV_MSG_ID_FW_CAP_RESP			= 0x11,
7520d2e88cSAlexander Duyck 	FBNIC_TLV_MSG_ID_OWNERSHIP_REQ			= 0x12,
7620d2e88cSAlexander Duyck 	FBNIC_TLV_MSG_ID_OWNERSHIP_RESP			= 0x13,
7720d2e88cSAlexander Duyck 	FBNIC_TLV_MSG_ID_HEARTBEAT_REQ			= 0x14,
7820d2e88cSAlexander Duyck 	FBNIC_TLV_MSG_ID_HEARTBEAT_RESP			= 0x15,
7920d2e88cSAlexander Duyck };
8020d2e88cSAlexander Duyck 
8120d2e88cSAlexander Duyck #define FBNIC_FW_CAP_RESP_VERSION_MAJOR		CSR_GENMASK(31, 24)
8220d2e88cSAlexander Duyck #define FBNIC_FW_CAP_RESP_VERSION_MINOR		CSR_GENMASK(23, 16)
8320d2e88cSAlexander Duyck #define FBNIC_FW_CAP_RESP_VERSION_PATCH		CSR_GENMASK(15, 8)
8420d2e88cSAlexander Duyck #define FBNIC_FW_CAP_RESP_VERSION_BUILD		CSR_GENMASK(7, 0)
8520d2e88cSAlexander Duyck enum {
8620d2e88cSAlexander Duyck 	FBNIC_FW_CAP_RESP_VERSION			= 0x0,
8720d2e88cSAlexander Duyck 	FBNIC_FW_CAP_RESP_BMC_PRESENT			= 0x1,
8820d2e88cSAlexander Duyck 	FBNIC_FW_CAP_RESP_BMC_MAC_ADDR			= 0x2,
8920d2e88cSAlexander Duyck 	FBNIC_FW_CAP_RESP_BMC_MAC_ARRAY			= 0x3,
9020d2e88cSAlexander Duyck 	FBNIC_FW_CAP_RESP_STORED_VERSION		= 0x4,
9120d2e88cSAlexander Duyck 	FBNIC_FW_CAP_RESP_ACTIVE_FW_SLOT		= 0x5,
9220d2e88cSAlexander Duyck 	FBNIC_FW_CAP_RESP_VERSION_COMMIT_STR		= 0x6,
9320d2e88cSAlexander Duyck 	FBNIC_FW_CAP_RESP_BMC_ALL_MULTI			= 0x8,
9420d2e88cSAlexander Duyck 	FBNIC_FW_CAP_RESP_FW_STATE			= 0x9,
9520d2e88cSAlexander Duyck 	FBNIC_FW_CAP_RESP_FW_LINK_SPEED			= 0xa,
9620d2e88cSAlexander Duyck 	FBNIC_FW_CAP_RESP_FW_LINK_FEC			= 0xb,
9720d2e88cSAlexander Duyck 	FBNIC_FW_CAP_RESP_STORED_COMMIT_STR		= 0xc,
9820d2e88cSAlexander Duyck 	FBNIC_FW_CAP_RESP_CMRT_VERSION			= 0xd,
9920d2e88cSAlexander Duyck 	FBNIC_FW_CAP_RESP_STORED_CMRT_VERSION		= 0xe,
10020d2e88cSAlexander Duyck 	FBNIC_FW_CAP_RESP_CMRT_COMMIT_STR		= 0xf,
10120d2e88cSAlexander Duyck 	FBNIC_FW_CAP_RESP_STORED_CMRT_COMMIT_STR	= 0x10,
10220d2e88cSAlexander Duyck 	FBNIC_FW_CAP_RESP_UEFI_VERSION			= 0x11,
10320d2e88cSAlexander Duyck 	FBNIC_FW_CAP_RESP_UEFI_COMMIT_STR		= 0x12,
10420d2e88cSAlexander Duyck 	FBNIC_FW_CAP_RESP_MSG_MAX
10520d2e88cSAlexander Duyck };
10620d2e88cSAlexander Duyck 
10720d2e88cSAlexander Duyck enum {
10869684376SAlexander Duyck 	FBNIC_FW_LINK_SPEED_25R1		= 1,
10969684376SAlexander Duyck 	FBNIC_FW_LINK_SPEED_50R2		= 2,
11069684376SAlexander Duyck 	FBNIC_FW_LINK_SPEED_50R1		= 3,
11169684376SAlexander Duyck 	FBNIC_FW_LINK_SPEED_100R2		= 4,
11269684376SAlexander Duyck };
11369684376SAlexander Duyck 
11469684376SAlexander Duyck enum {
11569684376SAlexander Duyck 	FBNIC_FW_LINK_FEC_NONE			= 1,
11669684376SAlexander Duyck 	FBNIC_FW_LINK_FEC_RS			= 2,
11769684376SAlexander Duyck 	FBNIC_FW_LINK_FEC_BASER			= 3,
11869684376SAlexander Duyck };
11969684376SAlexander Duyck 
12069684376SAlexander Duyck enum {
12120d2e88cSAlexander Duyck 	FBNIC_FW_OWNERSHIP_FLAG			= 0x0,
12220d2e88cSAlexander Duyck 	FBNIC_FW_OWNERSHIP_MSG_MAX
12320d2e88cSAlexander Duyck };
124da3cde08SAlexander Duyck #endif /* _FBNIC_FW_H_ */
125