eth fbnic: Add fbnic self tests
Subsystems (3)
v4 cover eth fbnic: Add fbnic self tests
From: "Mike Marciniszyn (Meta)" <[email protected]>
This series adds self tests to test the registers, the msix interrupts, the tlv, and the firmware mailbox.
This series assumes that the
[PATCH net-next 0/2] Add debugfs hooks [1]
is present.
When the self tests are run the with ethtool -t:
ethtool -t eth0
The test result is PASS
The test extra info:
Register test (offline) 0
MSI-X Interrupt test (offline) 0
FW mailbox test (on/offline) 0
Mike Marciniszyn (Meta) (5):
net: export netif_open for self_test usage
eth fbnic: Add register self test
eth fbnic: Add msix self test
eth fbnic: TLV support for use by MBX self test
eth fbnic: Add mailbox self test
v2 - add enums for test return codes 2/5, 3/5, snf 5/5
- correct placement of fbnic_nic forward in 2/5, 4/5
v3 - add missing enum in 3/5
v4 - use kzalloc_obj() vs. kzalloc with sizeof in 3/5
drivers/net/ethernet/meta/fbnic/fbnic.h | 1 + drivers/net/ethernet/meta/fbnic/fbnic_csr.c | 128 ++++++++ drivers/net/ethernet/meta/fbnic/fbnic_csr.h | 19 ++ .../net/ethernet/meta/fbnic/fbnic_ethtool.c | 93 ++++++ drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 100 +++++++ drivers/net/ethernet/meta/fbnic/fbnic_fw.h | 27 ++ drivers/net/ethernet/meta/fbnic/fbnic_irq.c | 154 ++++++++++ drivers/net/ethernet/meta/fbnic/fbnic_tlv.c | 276 ++++++++++++++++++ drivers/net/ethernet/meta/fbnic/fbnic_tlv.h | 27 ++ net/core/dev.c | 1 + 10 files changed, 857 insertions(+)
Signature · 1 line
2.43.0
PATCH v4 1/5 net: export netif_open for self_test usage
From: "Mike Marciniszyn (Meta)" <[email protected]>
dev_open() already is exported, but drivers which use the netdev instance lock need to use netif_open() instead. netif_close() is also already exported [1] so this completes the pairing.
This export is required for the following fbnic self tests to avoid calling ndo_stop() and ndo_open() in favor of the more appropriate netif_open() and netif_close() that notifies any listeners that the interface went down to test and is now coming back up.
--- net/core/dev.c | 1 + 1 file changed, 1 insertion(+)
net/core/dev.c +1 -0
@@ -1731,6 +1731,7 @@ int netif_open(struct net_device *dev, struct netlink_ext_ack *extack)return ret; } +EXPORT_SYMBOL (netif_open);static void __dev_close_many (struct list_head *head) {
Signature · 1 line
2.43.0
PATCH v4 2/5 eth fbnic: Add register self test
In reply to [email protected]From: "Mike Marciniszyn (Meta)" <[email protected]>
The register test will be used to verify hardware is behaving as expected.
The test itself will have us writing to registers that should have no side effects due to us resetting after the test has been completed.
While the test is being run the interface should be offline.
This patch counts on the first patch of this series to export netif_open() and also ensures that the half close calls netif_close() to avoid deadlock.
---
v2 - add enum for test return codes
- place forward of struct fbnic_dev after include with a blank line
v3 - no changes
v4 - no changes
drivers/net/ethernet/meta/fbnic/fbnic.h | 18 +++ drivers/net/ethernet/meta/fbnic/fbnic_csr.c | 128 ++++++++++++++++++ drivers/net/ethernet/meta/fbnic/fbnic_csr.h | 19 +++ .../net/ethernet/meta/fbnic/fbnic_ethtool.c | 50 +++++++ 3 files changed, 197 insertions(+)
drivers/net/ethernet/meta/fbnic/fbnic_csr.c +128 -0
@@ -147,3 +147,131 @@ int fbnic_csr_regs_len(struct fbnic_dev *fbd)return len; } + +/* CSR register test data +* +* The register test will be used to verify hardware is behaving as expected. +* +* The test itself will have us writing to registers that should have no +* side effects due to us resetting after the test has been completed. +* While the test is being run the interface should be offline. +*/ +struct fbnic_csr_reg_test_data { +int reg; +u16 reg_offset; +u8 array_len; +u32 read; +u32 write; +}; + +#define FBNIC_QUEUE_REG_TEST (_name, _read, _write) { \ + .reg = FBNIC_QUEUE(0) + FBNIC_QUEUE_##_name, \ + .reg_offset = FBNIC_QUEUE_STRIDE, \ + .array_len = 64, \ + .read = _read, \ + .write = _write \ +} + +static const struct fbnic_csr_reg_test_data pattern_test[] = { +FBNIC_QUEUE_REG_TEST (TWQ0_CTL ,FBNIC_QUEUE_TWQ_CTL_RESET , +FBNIC_QUEUE_TWQ_CTL_RESET ), +FBNIC_QUEUE_REG_TEST (TWQ0_PTRS ,0 , ~0 ), +FBNIC_QUEUE_REG_TEST (TWQ0_SIZE ,FBNIC_QUEUE_TWQ_SIZE_MASK , ~0 ), +FBNIC_QUEUE_REG_TEST (TWQ0_BAL ,FBNIC_QUEUE_BAL_MASK , ~0 ), +FBNIC_QUEUE_REG_TEST (TWQ0_BAH , ~0 , ~0 ), +FBNIC_QUEUE_REG_TEST (TWQ1_CTL ,FBNIC_QUEUE_TWQ_CTL_RESET , +FBNIC_QUEUE_TWQ_CTL_RESET ), +FBNIC_QUEUE_REG_TEST (TWQ1_PTRS ,0 , ~0 ), +FBNIC_QUEUE_REG_TEST (TWQ1_SIZE ,FBNIC_QUEUE_TWQ_SIZE_MASK , ~0 ), +FBNIC_QUEUE_REG_TEST (TWQ1_BAL ,FBNIC_QUEUE_BAL_MASK , ~0 ), +FBNIC_QUEUE_REG_TEST (TWQ1_BAH , ~0 , ~0 ), +FBNIC_QUEUE_REG_TEST (TCQ_CTL ,FBNIC_QUEUE_TCQ_CTL_RESET , +FBNIC_QUEUE_TCQ_CTL_RESET ), +FBNIC_QUEUE_REG_TEST (TCQ_PTRS ,0 , ~0 ), +FBNIC_QUEUE_REG_TEST (TCQ_SIZE ,FBNIC_QUEUE_TCQ_SIZE_MASK , ~0 ), +FBNIC_QUEUE_REG_TEST (TCQ_BAL ,FBNIC_QUEUE_BAL_MASK , ~0 ), +FBNIC_QUEUE_REG_TEST (TCQ_BAH , ~0 , ~0 ), +FBNIC_QUEUE_REG_TEST (RCQ_CTL ,FBNIC_QUEUE_RCQ_CTL_RESET , +FBNIC_QUEUE_RCQ_CTL_RESET ), +FBNIC_QUEUE_REG_TEST (RCQ_PTRS ,0 , ~0 ), +FBNIC_QUEUE_REG_TEST (RCQ_SIZE ,FBNIC_QUEUE_RCQ_SIZE_MASK , ~0 ), +FBNIC_QUEUE_REG_TEST (RCQ_BAL ,FBNIC_QUEUE_BAL_MASK , ~0 ), +FBNIC_QUEUE_REG_TEST (RCQ_BAH , ~0 , ~0 ), +FBNIC_QUEUE_REG_TEST (BDQ_CTL ,FBNIC_QUEUE_BDQ_CTL_RESET , +FBNIC_QUEUE_BDQ_CTL_RESET ), +FBNIC_QUEUE_REG_TEST (BDQ_HPQ_PTRS ,0 , ~0 ), +FBNIC_QUEUE_REG_TEST (BDQ_HPQ_SIZE ,FBNIC_QUEUE_BDQ_SIZE_MASK , ~0 ), +FBNIC_QUEUE_REG_TEST (BDQ_HPQ_BAL ,FBNIC_QUEUE_BAL_MASK , ~0 ), +FBNIC_QUEUE_REG_TEST (BDQ_HPQ_BAH , ~0 , ~0 ), +FBNIC_QUEUE_REG_TEST (BDQ_PPQ_PTRS ,0 , ~0 ), +FBNIC_QUEUE_REG_TEST (BDQ_PPQ_SIZE ,FBNIC_QUEUE_BDQ_SIZE_MASK , ~0 ), +FBNIC_QUEUE_REG_TEST (BDQ_PPQ_BAL ,FBNIC_QUEUE_BAL_MASK , ~0 ), +FBNIC_QUEUE_REG_TEST (BDQ_PPQ_BAH , ~0 , ~0 ), +}; + +static enum fbnic_reg_self_test_codes +fbnic_csr_reg_pattern_test (struct fbnic_dev *fbd,int index, +const struct fbnic_csr_reg_test_data *test_data) +{ +static const u32 pattern[] = { ~0 ,0x5A5A5A5A ,0xA5A5A5A5 ,0 }; +enum fbnic_reg_self_test_codes reg; +int i; + + reg = test_data->reg + test_data->reg_offset * index; +for (i =0 ; i <ARRAY_SIZE (pattern); i++) { +u32 val = pattern[i] & test_data->write; +u32 result; + +wr32 (fbd, reg, val); + result =rd32 (fbd, reg); + val &= test_data->read; + +if (result == val) +continue ; + +dev_err (fbd->dev, +"%s: reg 0x%06X failed, expected 0x%08X received 0x%08X\n" , + __func__, reg, val, result); + +/* Note that FBNIC_INTR_STATUS(0) could be tested and fail +* and the result would not be reported since the register +* offset is 0. However as that register isn't included in +* the register test that isn't an issue. +*/ +return reg; + } + +return FBNIC_REG_TEST_SUCCESS ; +} + +/** +* fbnic_csr_regs_test() - Verify behavior of NIC registers +* @fbd: device to test +* +* This function is meant to test the bit values of various registers in +* the NIC device. Specifically this test will verify which bits are +* writable and which ones are not. It will write varying patterns of bits +* to the registers testing for sticky bits, or bits that are writable but +* should not be. +* +* Return: FBNIC_REG_TEST_SUCCESS on success, register number on failure +**/ +enum fbnic_reg_self_test_codes fbnic_csr_regs_test (struct fbnic_dev *fbd) +{ +const struct fbnic_csr_reg_test_data *test_data; + +for (test_data = pattern_test; + test_data < pattern_test +ARRAY_SIZE (pattern_test); test_data++) { +u32 i; + +for (i =0 ; i < test_data->array_len; i++) { +enum fbnic_reg_self_test_codes reg = +fbnic_csr_reg_pattern_test (fbd, i, test_data); + +if (reg) +return reg; + } + } + +return FBNIC_REG_TEST_SUCCESS ; +}
drivers/net/ethernet/meta/fbnic/fbnic_csr.h +19 -0
@@ -6,6 +6,8 @@#include <linux/bitops.h> +struct fbnic_dev ; +#define CSR_BIT (nr) (1u << (nr))#define CSR_GENMASK (h, l) GENMASK(h, l)
@@ -1221,4 +1223,21 @@ enum{ FBNIC_CSR_VERSION_V1_0_ASIC = 1, }; +/** +* enum fbnic_reg_self_test_codes - return codes from self test routines +* +* This is the code that is returned from the register self test +* routines. +* +* The test either returns success or the register number +* that failed during the test. +* +* @FBNIC_REG_TEST_SUCCESS: no errors +*/ +enum fbnic_reg_self_test_codes { +FBNIC_REG_TEST_SUCCESS =0 , +}; + +enum fbnic_reg_self_test_codes fbnic_csr_regs_test (struct fbnic_dev *fbd); +#endif /* _FBNIC_CSR_H_ */
drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +50 -0
80 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v4 3/5 eth fbnic: Add msix self test
In reply to [email protected]From: "Mike Marciniszyn (Meta)" <[email protected]>
This function is meant to test the global interrupt registers and the PCIe IP MSI-X functionality. It essentially goes through and tests various combinations of the set, clear, and mask bits in order to verify the behavior is as we expect it to be from the driver.
---
v2 - add enum for test return codes
v3 - add missing enum
v4 - use kzalloc_obj() vs. kzalloc with sizeof
drivers/net/ethernet/meta/fbnic/fbnic.h | 18 ++ .../net/ethernet/meta/fbnic/fbnic_ethtool.c | 28 ++++ drivers/net/ethernet/meta/fbnic/fbnic_irq.c | 154 ++++++++++++++++++ 3 files changed, 214 insertions(+)
drivers/net/ethernet/meta/fbnic/fbnic.h +32 -0
@@ -197,6 +197,38 @@ void fbnic_synchronize_irq(struct fbnic_dev *fbd, int nr);int fbnic_request_irq (struct fbnic_dev *dev,int nr,irq_handler_t handler,unsigned long flags,const char *name,void *data);void fbnic_free_irq (struct fbnic_dev *dev,int nr,void *data); + +/** +* enum fbnic_msix_self_test_codes - return codes from self test routines +* +* These are the codes returned from the self test routines and +* stored in the test result array indexed by the specific +* test name. +* +* @FBNIC_TEST_MSIX_SUCCESS: no errors +* @FBNIC_TEST_MSIX_NOMEM: allocation failure +* @FBNIC_TEST_MSIX_IRQ_REQ_FAIL: IRQ request failure +* @FBNIC_TEST_MSIX_MASK: masking failed to prevent IRQ +* @FBNIC_TEST_MSIX_UNMASK: unmasking failure w/ sw status set +* @FBNIC_TEST_MSIX_IRQ_CLEAR: interrupt when clearing mask +* @FBNIC_TEST_MSIX_NO_INTERRUPT: no interrupt when not masked +* @FBNIC_TEST_MSIX_NO_CLEAR_OR_MASK: status not cleared, or mask not set +* @FBNIC_TEST_MSIX_BITS_SET_AFTER_TEST: Bits are set after test +*/ +enum fbnic_msix_self_test_codes { +FBNIC_TEST_MSIX_SUCCESS =0 , +FBNIC_TEST_MSIX_NOMEM =5 , +FBNIC_TEST_MSIX_IRQ_REQ_FAIL =10 , +FBNIC_TEST_MSIX_MASK =20 , +FBNIC_TEST_MSIX_UNMASK =30 , +FBNIC_TEST_MSIX_IRQ_CLEAR =40 , +FBNIC_TEST_MSIX_NO_INTERRUPT =50 , +FBNIC_TEST_MSIX_NO_CLEAR_OR_MASK =60 , +FBNIC_TEST_MSIX_BITS_SET_AFTER_TEST =70 , +}; + +enum fbnic_msix_self_test_codes fbnic_msix_test (struct fbnic_dev *fbd); +void fbnic_free_irqs (struct fbnic_dev *fbd);int fbnic_alloc_irqs (struct fbnic_dev *fbd);
drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +28 -0
@@ -128,10 +128,12 @@ static const struct fbnic_stat fbnic_gstrings_xdp_stats[] = {enum fbnic_self_test_results {TEST_REG =0 , +TEST_MSIX , };static const char fbnic_gstrings_self_test[][ETH_GSTRING_LEN ] = { [TEST_REG ] ="Register test (offline)" , + [TEST_MSIX ] ="MSI-X Interrupt test (offline)" , };#define FBNIC_TEST_LEN ARRAY_SIZE(fbnic_gstrings_self_test)
@@ -1504,6 +1506,28 @@ static int fbnic_ethtool_regs_test(struct net_device *netdev, u64 *data)return !!*data; } +/** +* fbnic_ethtool_msix_test - Verify behavior of NIC interrupts +* @netdev: netdev device to test +* @data: Pointer to results storage +* +* This function is meant to test the global interrupt registers and the +* PCIe IP MSI-X functionality. It essentially goes through and tests +* test various combinations of the set, clear, and mask bits in order to +* verify the behavior is as we expect it to be from the driver. +* +* Return: non-zero on failure. +**/ +static int fbnic_ethtool_msix_test (struct net_device *netdev,u64 *data) +{ +struct fbnic_net *fbn =netdev_priv (netdev); +struct fbnic_dev *fbd = fbn->fbd; + + *data =fbnic_msix_test (fbd); + +return !!*data; +} +static void fbnic_self_test (struct net_device *netdev,struct ethtool_test *eth_test,u64 *data) {
@@ -1511,6 +1535,7 @@ static void fbnic_self_test(struct net_device *netdev,if (!(eth_test->flags Ð_TEST_FL_OFFLINE )) { data[TEST_REG ] =0 ; + data[TEST_MSIX ] =0 ;return ; }
@@ -1520,6 +1545,9 @@ static void fbnic_self_test(struct net_device *netdev,if (fbnic_ethtool_regs_test (netdev, &data[TEST_REG ])) eth_test->flags |=ETH_TEST_FL_FAILED ; +if (fbnic_ethtool_msix_test (netdev, &data[TEST_MSIX ])) + eth_test->flags |=ETH_TEST_FL_FAILED ; +if (if_running &&netif_open (netdev,NULL )) {netdev_err (netdev,"Failed to re-initialize hardware following test\n" );
drivers/net/ethernet/meta/fbnic/fbnic_irq.c +154 -0
160 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v4 4/5 eth fbnic: TLV support for use by MBX self test
In reply to [email protected]From: "Mike Marciniszyn (Meta)" <[email protected]>
The TLV (Type-Value-Length) self uses a known set of data to create a TLV message. These routines support the MBX self test by creating the test messages and parsing the response message coming back from the firmware.
---
v2 - place forward of struct fbnic_dev after include with a blank line v3 - no changes
v4 - no changes
drivers/net/ethernet/meta/fbnic/fbnic_tlv.c | 276 ++++++++++++++++++++ drivers/net/ethernet/meta/fbnic/fbnic_tlv.h | 27 ++ 2 files changed, 303 insertions(+)
drivers/net/ethernet/meta/fbnic/fbnic_tlv.c +276 -0
@@ -551,6 +551,172 @@ int fbnic_tlv_parser_error(void *opaque, struct fbnic_tlv_msg **results)return -EBADMSG ; } +#define FBNIC_TLV_TEST_STRING_LEN 32 + +struct fbnic_tlv_test { +u64 test_u64; +s64 test_s64; +u32 test_u32; +s32 test_s32; +u16 test_u16; +s16 test_s16; +u8 test_mac[ETH_ALEN ]; +u8 test_mac_array[4 ][ETH_ALEN ]; +u8 test_true; +u8 test_false; +char test_string[FBNIC_TLV_TEST_STRING_LEN ]; +}; + +static struct fbnic_tlv_test test_struct; + +const struct fbnic_tlv_index fbnic_tlv_test_index[] = { +FBNIC_TLV_ATTR_U64 (FBNIC_TLV_TEST_MSG_U64 ), +FBNIC_TLV_ATTR_S64 (FBNIC_TLV_TEST_MSG_S64 ), +FBNIC_TLV_ATTR_U32 (FBNIC_TLV_TEST_MSG_U32 ), +FBNIC_TLV_ATTR_S32 (FBNIC_TLV_TEST_MSG_S32 ), +FBNIC_TLV_ATTR_U32 (FBNIC_TLV_TEST_MSG_U16 ), +FBNIC_TLV_ATTR_S32 (FBNIC_TLV_TEST_MSG_S16 ), +FBNIC_TLV_ATTR_MAC_ADDR (FBNIC_TLV_TEST_MSG_MAC_ADDR ), +FBNIC_TLV_ATTR_FLAG (FBNIC_TLV_TEST_MSG_FLAG_TRUE ), +FBNIC_TLV_ATTR_FLAG (FBNIC_TLV_TEST_MSG_FLAG_FALSE ), +FBNIC_TLV_ATTR_STRING (FBNIC_TLV_TEST_MSG_STRING , +FBNIC_TLV_TEST_STRING_LEN ), +FBNIC_TLV_ATTR_ARRAY (FBNIC_TLV_TEST_MSG_ARRAY ), +FBNIC_TLV_ATTR_NESTED (FBNIC_TLV_TEST_MSG_NESTED ), +FBNIC_TLV_ATTR_LAST +}; + +static void fbnic_tlv_test_struct_init (void ) +{ +int i =FBNIC_TLV_TEST_STRING_LEN -1 ; + +/* Populate the struct with random data */ +get_random_once (&test_struct, + offsetof(struct fbnic_tlv_test , test_string) + i); + +/* Force true/false to their expected values */ + test_struct.test_false = false; + test_struct.test_true = true; + +/* Convert test_string to a true ASCII string */ + test_struct.test_string[i] ='\0' ; +while (i--) { +/* Force characters into displayable range */ +if (test_struct.test_string[i] <64 || + test_struct.test_string[i] >=96 ) { + test_struct.test_string[i] %=32 ; + test_struct.test_string[i] +=64 ; + } + } +} + +static int fbnic_tlv_test_attr_data (struct fbnic_tlv_msg *msg) +{ +struct fbnic_tlv_msg *array; +int err, i; + + err =fbnic_tlv_attr_put_int (msg,FBNIC_TLV_TEST_MSG_U64 , + test_struct.test_u64); +if (err) +return err; + + err =fbnic_tlv_attr_put_int (msg,FBNIC_TLV_TEST_MSG_S64 , + test_struct.test_s64); +if (err) +return err; + + err =fbnic_tlv_attr_put_int (msg,FBNIC_TLV_TEST_MSG_U32 , + test_struct.test_u32); +if (err) +return err; + + err =fbnic_tlv_attr_put_int (msg,FBNIC_TLV_TEST_MSG_S32 , + test_struct.test_s32); +if (err) +return err; + + err =fbnic_tlv_attr_put_int (msg,FBNIC_TLV_TEST_MSG_U16 , + test_struct.test_u16); +if (err) +return err; + + err =fbnic_tlv_attr_put_int (msg,FBNIC_TLV_TEST_MSG_S16 , + test_struct.test_s16); +if (err) +return err; + + err =fbnic_tlv_attr_put_value (msg,FBNIC_TLV_TEST_MSG_MAC_ADDR , + test_struct.test_mac,ETH_ALEN ); +if (err) +return err; + +/* Start MAC address array */ + array =fbnic_tlv_attr_nest_start (msg,FBNIC_TLV_TEST_MSG_ARRAY ); +if (!array) +return -ENOSPC ; + +for (i =0 ; i <4 ; i++) { + err =fbnic_tlv_attr_put_value (array, +FBNIC_TLV_TEST_MSG_MAC_ADDR , + test_struct.test_mac_array[i], +ETH_ALEN ); +if (err) +return err; + } + +/* Close array */ +fbnic_tlv_attr_nest_stop (msg); + + err =fbnic_tlv_attr_put_flag (msg,FBNIC_TLV_TEST_MSG_FLAG_TRUE ); +if (err) +return err; + +return fbnic_tlv_attr_put_string (msg,FBNIC_TLV_TEST_MSG_STRING , + test_struct.test_string); +} + +/** +* fbnic_tlv_test_create - Allocate a test message and fill it w/ data +* @fbd: FBNIC device structure +* +* Return: NULL on failure to allocate or pointer to new TLV test message. +**/ +struct fbnic_tlv_msg *fbnic_tlv_test_create (struct fbnic_dev *fbd) +{ +struct fbnic_tlv_msg *msg, *nest; +int err; + + msg =fbnic_tlv_msg_alloc (FBNIC_TLV_MSG_ID_TEST ); +if (!msg) +return NULL ; + +/* Randomize struct data */ +fbnic_tlv_test_struct_init (); + +/* Add first level of data to message */ + err =fbnic_tlv_test_attr_data (msg); +if (err) + goto free_message; + +/* Start second level nested */ + nest =fbnic_tlv_attr_nest_start (msg,FBNIC_TLV_TEST_MSG_NESTED ); +if (!nest) + goto free_message; + +/* Add nested data */ + err =fbnic_tlv_test_attr_data (nest); +if (err) + goto free_message; + +/* Close nest and report full message */ +fbnic_tlv_attr_nest_stop (msg); + +return msg; +free_message: +free_page ((unsigned long )msg); +return NULL ; +} +void fbnic_tlv_attr_addr_copy (u8 *dest,struct fbnic_tlv_msg *src) {u8 *mac_addr;
@@ -558,3 +724,113 @@ void fbnic_tlv_attr_addr_copy(u8 *dest, struct fbnic_tlv_msg *src) mac_addr =fbnic_tlv_attr_get_value_ptr (src);memcpy (dest, mac_addr,ETH_ALEN ); } + +/** +* fbnic_tlv_parser_test_attr - Function loading test attributes into structure +* @str: Test structure to load +* @results: Pointer to results array +* +* Copies attributes into structure. Any attribute that doesn't exist in the +* results array is not populated. +**/ +static void fbnic_tlv_parser_test_attr (struct fbnic_tlv_test *str, +struct fbnic_tlv_msg **results) +{ +struct fbnic_tlv_msg *array_results[4 ]; +struct fbnic_tlv_msg *attr; +char *string =NULL ; +int i, err; + + str->test_u64 =fta_get_uint (results,FBNIC_TLV_TEST_MSG_U64 ); + str->test_u32 =fta_get_uint (results,FBNIC_TLV_TEST_MSG_U32 ); + str->test_u16 =fta_get_uint (results,FBNIC_TLV_TEST_MSG_U16 ); + + str->test_s64 =fta_get_sint (results,FBNIC_TLV_TEST_MSG_S64 ); + str->test_s32 =fta_get_sint (results,FBNIC_TLV_TEST_MSG_S32 ); + str->test_s16 =fta_get_sint (results,FBNIC_TLV_TEST_MSG_S16 ); + + attr = results[FBNIC_TLV_TEST_MSG_MAC_ADDR ]; +if (attr) +fbnic_tlv_attr_addr_copy (str->test_mac, attr); + + attr = results[FBNIC_TLV_TEST_MSG_ARRAY ]; +if (attr) { +int len =le16_to_cpu (attr->hdr.len) /sizeof (u32) -1 ; + + err =fbnic_tlv_attr_parse_array (&attr[1 ], len, + array_results, + fbnic_tlv_test_index, +FBNIC_TLV_TEST_MSG_MAC_ADDR , +4 ); +if (!err) { +for (i =0 ; i <4 && array_results[i]; i++) +fbnic_tlv_attr_addr_copy (str->test_mac_array[i], + array_results[i]); + } + } + + str->test_true = !!results[FBNIC_TLV_TEST_MSG_FLAG_TRUE ]; + str->test_false = !!results[FBNIC_TLV_TEST_MSG_FLAG_FALSE ]; + + attr = results[FBNIC_TLV_TEST_MSG_STRING ]; +if (attr) { + string =fbnic_tlv_attr_get_value_ptr (attr); +strscpy (str->test_string, string,FBNIC_TLV_TEST_STRING_LEN ); + } +} + +static void fbnic_tlv_test_dump (struct fbnic_tlv_test *value,char *prefix) +{ +print_hex_dump (KERN_INFO , prefix,DUMP_PREFIX_OFFSET ,16 ,1 , + value,sizeof (*value), true); +} + +/** +* fbnic_tlv_parser_test - Function for parsing and testing test message +* @opaque: Unused value +* @results: Results of parser output +* +* Return: negative value on error, or 0 on success. +* +* Parses attributes to structures and compares the structure to the +* expected test value that should have been used to populate the message. +* +* Used to verify message generation and parser are working correctly. +**/ +int fbnic_tlv_parser_test (void *opaque,struct fbnic_tlv_msg **results) +{ +struct fbnic_tlv_msg *nest_results[FBNIC_TLV_RESULTS_MAX ] = {0 }; +struct fbnic_tlv_test result_struct; +struct fbnic_tlv_msg *attr; +int err; + +memset (&result_struct,0 ,sizeof (result_struct)); +fbnic_tlv_parser_test_attr (&result_struct, results); + +if (memcmp (&test_struct, &result_struct,sizeof (test_struct))) { +fbnic_tlv_test_dump (&result_struct,"fbnic: found - " ); +fbnic_tlv_test_dump (&test_struct,"fbnic: expected - " ); +return -EINVAL ; + } + + attr = results[FBNIC_TLV_TEST_MSG_NESTED ]; +if (!attr) +return -EINVAL ; + + err =fbnic_tlv_attr_parse (&attr[1 ], +le16_to_cpu (attr->hdr.len) /sizeof (u32) -1 , + nest_results, fbnic_tlv_test_index); +if (err) +return err; + +memset (&result_struct,0 ,sizeof (result_struct)); +fbnic_tlv_parser_test_attr (&result_struct, nest_results); + +if (memcmp (&test_struct, &result_struct,sizeof (test_struct))) { +fbnic_tlv_test_dump (&result_struct,"fbnic: found - " ); +fbnic_tlv_test_dump (&test_struct,"fbnic: expected - " ); +return -EINVAL ; + } + +return 0 ; +}
drivers/net/ethernet/meta/fbnic/fbnic_tlv.h +27 -0
@@ -9,6 +9,8 @@#include <linux/const.h> #include <linux/types.h> +struct fbnic_dev ; +#define FBNIC_TLV_MSG_ALIGN (len) ALIGN(len, sizeof(u32))#define FBNIC_TLV_MSG_SIZE (len) \ (FBNIC_TLV_MSG_ALIGN(len) / sizeof(u32))
@@ -153,6 +155,31 @@ int fbnic_tlv_parser_error(void *opaque, struct fbnic_tlv_msg **results);#define fta_get_str (_results, _id, _dst, _dstsize) \ fbnic_tlv_attr_get_string(_results[_id], _dst, _dstsize) +#define FBNIC_TLV_MSG_ID_TEST 0 + +enum fbnic_tlv_test_attr_id { +FBNIC_TLV_TEST_MSG_U64 , +FBNIC_TLV_TEST_MSG_S64 , +FBNIC_TLV_TEST_MSG_U32 , +FBNIC_TLV_TEST_MSG_S32 , +FBNIC_TLV_TEST_MSG_U16 , +FBNIC_TLV_TEST_MSG_S16 , +FBNIC_TLV_TEST_MSG_MAC_ADDR , +FBNIC_TLV_TEST_MSG_FLAG_TRUE , +FBNIC_TLV_TEST_MSG_FLAG_FALSE , +FBNIC_TLV_TEST_MSG_STRING , +FBNIC_TLV_TEST_MSG_NESTED , +FBNIC_TLV_TEST_MSG_ARRAY , +FBNIC_TLV_TEST_MSG_MAX +}; + +extern const struct fbnic_tlv_index fbnic_tlv_test_index[]; +struct fbnic_tlv_msg *fbnic_tlv_test_create (struct fbnic_dev *fbd); +int fbnic_tlv_parser_test (void *opaque,struct fbnic_tlv_msg **results); + +#define FBNIC_TLV_MSG_TEST \ + FBNIC_TLV_PARSER(TEST, fbnic_tlv_test_index, \ + fbnic_tlv_parser_test)#define FBNIC_TLV_MSG_ERROR \ FBNIC_TLV_PARSER(UNKNOWN, NULL, fbnic_tlv_parser_error)#endif /* _FBNIC_TLV_H_ */
Signature · 1 line
2.43.0
PATCH v4 5/5 eth fbnic: Add mailbox self test
In reply to [email protected]From: "Mike Marciniszyn (Meta)" <[email protected]>
The mailbox self test ensures the interface to and from the firmware is healthy by sending a test message and fielding the response from the firmware.
This patch uses the new completion API [1][2] that allocates a completion structure, binds the completion to the TEST message, and uses a new FW parsing routine that wraps the completion processing around the TLV parser.
---
v2 - add enum for test return codes
v3 - no changes
v4 - no changes
drivers/net/ethernet/meta/fbnic/fbnic.h | 14 ++- .../net/ethernet/meta/fbnic/fbnic_ethtool.c | 15 +++ drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 100 ++++++++++++++++++ drivers/net/ethernet/meta/fbnic/fbnic_fw.h | 27 +++++ 3 files changed, 142 insertions(+)
drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +15 -0
@@ -129,11 +129,13 @@ static const struct fbnic_stat fbnic_gstrings_xdp_stats[] = {enum fbnic_self_test_results {TEST_REG =0 ,TEST_MSIX , +TEST_MBX , };static const char fbnic_gstrings_self_test[][ETH_GSTRING_LEN ] = { [TEST_REG ] ="Register test (offline)" , [TEST_MSIX ] ="MSI-X Interrupt test (offline)" , + [TEST_MBX ] ="FW mailbox test (on/offline)" , };#define FBNIC_TEST_LEN ARRAY_SIZE(fbnic_gstrings_self_test)
@@ -1528,11 +1530,24 @@ static int fbnic_ethtool_msix_test(struct net_device *netdev, u64 *data)return !!*data; } +static int fbnic_ethtool_mbx_self_test (struct net_device *netdev,u64 *data) +{ +struct fbnic_net *fbn =netdev_priv (netdev); +struct fbnic_dev *fbd = fbn->fbd; + + *data =fbnic_fw_mbx_self_test (fbd); + +return !!*data; +} +static void fbnic_self_test (struct net_device *netdev,struct ethtool_test *eth_test,u64 *data) {bool if_running =netif_running (netdev); +if (fbnic_ethtool_mbx_self_test (netdev, &data[TEST_MBX ])) + eth_test->flags |=ETH_TEST_FL_FAILED ; +if (!(eth_test->flags Ð_TEST_FL_OFFLINE )) { data[TEST_REG ] =0 ; data[TEST_MSIX ] =0 ;
drivers/net/ethernet/meta/fbnic/fbnic_fw.c +100 -0
119 lines not on this page · raw message
drivers/net/ethernet/meta/fbnic/fbnic_fw.h +27 -0
@@ -104,6 +104,33 @@ void fbnic_mbx_clear_cmpl(struct fbnic_dev *fbd,void fbnic_mbx_poll (struct fbnic_dev *fbd);int fbnic_mbx_poll_tx_ready (struct fbnic_dev *fbd);void fbnic_mbx_flush_tx (struct fbnic_dev *fbd); + +/** +* enum fbnic_fw_self_test_codes - return codes from self test routines +* +* These are the codes returned from the self test routines and +* stored in the test result array indexed by the specific +* test name. +* +* @FBNIC_TEST_FW_SUCCESS: test success +* @FBNIC_TEST_FW_NO_FIRMWARE: FW interface not present +* @FBNIC_TEST_FW_NO_CMPL: No completion available +* @FBNIC_TEST_FW_NO_XMIT: Could not xmit message +* @FBNIC_TEST_FW_NO_MSG: no message returned +* @FBNIC_TEST_FW_PARSE: returned message had parsing error +*/ +enum fbnic_fw_self_test_codes { +FBNIC_TEST_FW_SUCCESS =0 , +FBNIC_TEST_FW_NO_FIRMWARE =10 , +FBNIC_TEST_FW_NO_CMPL =20 , +FBNIC_TEST_FW_NO_XMIT =30 , +FBNIC_TEST_FW_NO_MSG =40 , +FBNIC_TEST_FW_PARSE =50 , +}; + +enum fbnic_fw_self_test_codes fbnic_fw_mbx_self_test (struct fbnic_dev *fbd); +int fbnic_fw_xmit_test_msg (struct fbnic_dev *fbd, +struct fbnic_fw_completion *c);int fbnic_fw_xmit_ownership_msg (struct fbnic_dev *fbd,bool take_ownership);int fbnic_fw_init_heartbeat (struct fbnic_dev *fbd,bool poll);void fbnic_fw_check_heartbeat (struct fbnic_dev *fbd);
Signature · 1 line
2.43.0
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 10 lines · On Sat, 7 Mar 2026 05:58:42 -0500 you wrote:
From: "Mike Marciniszyn (Meta)" <[email protected]>
This series adds self tests to test the registers, the msix interrupts, the tlv, and the firmware mailbox.
This series assumes that the
[PATCH net-next 0/2] Add debugfs hooks [1]
is present.[...]
Here is the summary with links:
- [net-next,v4,1/5] net: export netif_open for self_test usage
https://git.kernel.org/netdev/net-next/c/3fdd33697c2b - [net-next,v4,2/5] eth fbnic: Add register self test https://git.kernel.org/netdev/net-next/c/b43498b7e9be - [net-next,v4,3/5] eth fbnic: Add msix self test https://git.kernel.org/netdev/net-next/c/99fc8d3d00c9 - [net-next,v4,4/5] eth fbnic: TLV support for use by MBX self test https://git.kernel.org/netdev/net-next/c/d522b1b00480 - [net-next,v4,5/5] eth fbnic: Add mailbox self test https://git.kernel.org/netdev/net-next/c/8e5218199da4
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html