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_MAX_SIZE 256 26 27 struct fbnic_fw_ver { 28 u32 version; 29 char commit[FBNIC_FW_CAP_RESP_COMMIT_MAX_SIZE]; 30 }; 31 32 struct fbnic_fw_cap { 33 struct { 34 struct fbnic_fw_ver mgmt, bootloader; 35 } running; 36 struct { 37 struct fbnic_fw_ver mgmt, bootloader, undi; 38 } stored; 39 u8 active_slot; 40 u8 bmc_mac_addr[4][ETH_ALEN]; 41 u8 bmc_present : 1; 42 u8 all_multi : 1; 43 u8 link_speed; 44 u8 link_fec; 45 }; 46 47 void fbnic_mbx_init(struct fbnic_dev *fbd); 48 void fbnic_mbx_clean(struct fbnic_dev *fbd); 49 void fbnic_mbx_poll(struct fbnic_dev *fbd); 50 int fbnic_mbx_poll_tx_ready(struct fbnic_dev *fbd); 51 void fbnic_mbx_flush_tx(struct fbnic_dev *fbd); 52 int fbnic_fw_xmit_ownership_msg(struct fbnic_dev *fbd, bool take_ownership); 53 int fbnic_fw_init_heartbeat(struct fbnic_dev *fbd, bool poll); 54 void fbnic_fw_check_heartbeat(struct fbnic_dev *fbd); 55 56 #define fbnic_mk_full_fw_ver_str(_rev_id, _delim, _commit, _str, _str_sz) \ 57 do { \ 58 const u32 __rev_id = _rev_id; \ 59 snprintf(_str, _str_sz, "%02lu.%02lu.%02lu-%03lu%s%s", \ 60 FIELD_GET(FBNIC_FW_CAP_RESP_VERSION_MAJOR, __rev_id), \ 61 FIELD_GET(FBNIC_FW_CAP_RESP_VERSION_MINOR, __rev_id), \ 62 FIELD_GET(FBNIC_FW_CAP_RESP_VERSION_PATCH, __rev_id), \ 63 FIELD_GET(FBNIC_FW_CAP_RESP_VERSION_BUILD, __rev_id), \ 64 _delim, _commit); \ 65 } while (0) 66 67 #define fbnic_mk_fw_ver_str(_rev_id, _str) \ 68 fbnic_mk_full_fw_ver_str(_rev_id, "", "", _str, sizeof(_str)) 69 70 #define FW_HEARTBEAT_PERIOD (10 * HZ) 71 72 enum { 73 FBNIC_TLV_MSG_ID_HOST_CAP_REQ = 0x10, 74 FBNIC_TLV_MSG_ID_FW_CAP_RESP = 0x11, 75 FBNIC_TLV_MSG_ID_OWNERSHIP_REQ = 0x12, 76 FBNIC_TLV_MSG_ID_OWNERSHIP_RESP = 0x13, 77 FBNIC_TLV_MSG_ID_HEARTBEAT_REQ = 0x14, 78 FBNIC_TLV_MSG_ID_HEARTBEAT_RESP = 0x15, 79 }; 80 81 #define FBNIC_FW_CAP_RESP_VERSION_MAJOR CSR_GENMASK(31, 24) 82 #define FBNIC_FW_CAP_RESP_VERSION_MINOR CSR_GENMASK(23, 16) 83 #define FBNIC_FW_CAP_RESP_VERSION_PATCH CSR_GENMASK(15, 8) 84 #define FBNIC_FW_CAP_RESP_VERSION_BUILD CSR_GENMASK(7, 0) 85 enum { 86 FBNIC_FW_CAP_RESP_VERSION = 0x0, 87 FBNIC_FW_CAP_RESP_BMC_PRESENT = 0x1, 88 FBNIC_FW_CAP_RESP_BMC_MAC_ADDR = 0x2, 89 FBNIC_FW_CAP_RESP_BMC_MAC_ARRAY = 0x3, 90 FBNIC_FW_CAP_RESP_STORED_VERSION = 0x4, 91 FBNIC_FW_CAP_RESP_ACTIVE_FW_SLOT = 0x5, 92 FBNIC_FW_CAP_RESP_VERSION_COMMIT_STR = 0x6, 93 FBNIC_FW_CAP_RESP_BMC_ALL_MULTI = 0x8, 94 FBNIC_FW_CAP_RESP_FW_STATE = 0x9, 95 FBNIC_FW_CAP_RESP_FW_LINK_SPEED = 0xa, 96 FBNIC_FW_CAP_RESP_FW_LINK_FEC = 0xb, 97 FBNIC_FW_CAP_RESP_STORED_COMMIT_STR = 0xc, 98 FBNIC_FW_CAP_RESP_CMRT_VERSION = 0xd, 99 FBNIC_FW_CAP_RESP_STORED_CMRT_VERSION = 0xe, 100 FBNIC_FW_CAP_RESP_CMRT_COMMIT_STR = 0xf, 101 FBNIC_FW_CAP_RESP_STORED_CMRT_COMMIT_STR = 0x10, 102 FBNIC_FW_CAP_RESP_UEFI_VERSION = 0x11, 103 FBNIC_FW_CAP_RESP_UEFI_COMMIT_STR = 0x12, 104 FBNIC_FW_CAP_RESP_MSG_MAX 105 }; 106 107 enum { 108 FBNIC_FW_LINK_SPEED_25R1 = 1, 109 FBNIC_FW_LINK_SPEED_50R2 = 2, 110 FBNIC_FW_LINK_SPEED_50R1 = 3, 111 FBNIC_FW_LINK_SPEED_100R2 = 4, 112 }; 113 114 enum { 115 FBNIC_FW_LINK_FEC_NONE = 1, 116 FBNIC_FW_LINK_FEC_RS = 2, 117 FBNIC_FW_LINK_FEC_BASER = 3, 118 }; 119 120 enum { 121 FBNIC_FW_OWNERSHIP_FLAG = 0x0, 122 FBNIC_FW_OWNERSHIP_MSG_MAX 123 }; 124 #endif /* _FBNIC_FW_H_ */ 125