eth fbnic: Add fbnic self tests
Subsystems (3)
v12 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
drivers/net/ethernet/meta/fbnic/fbnic.h | 1 + drivers/net/ethernet/meta/fbnic/fbnic_csr.c | 126 ++++++++ drivers/net/ethernet/meta/fbnic/fbnic_csr.h | 4 + .../net/ethernet/meta/fbnic/fbnic_ethtool.c | 93 ++++++ drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 92 ++++++ drivers/net/ethernet/meta/fbnic/fbnic_fw.h | 3 + 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 | 26 ++ net/core/dev.c | 1 + 10 files changed, 776 insertions(+)
--
2.43.0
PATCH v12 1/5 net: export netif_open for self_test usage
From: "Mike Marciniszyn (Meta)" <[email protected]>
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.
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.
--- net/core/dev.c | 1 + 1 file changed, 1 insertion(+)
net/core/dev.c +1 -0
@@ -1724,6 +1724,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) {
--
2.43.0
PATCH v12 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.
--- drivers/net/ethernet/meta/fbnic/fbnic_csr.c | 126 ++++++++++++++++++ drivers/net/ethernet/meta/fbnic/fbnic_csr.h | 4 + .../net/ethernet/meta/fbnic/fbnic_ethtool.c | 50 +++++++ 3 files changed, 180 insertions(+)
drivers/net/ethernet/meta/fbnic/fbnic_csr.c +126 -0
@@ -147,3 +147,129 @@ 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 int +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 }; +u32 reg = test_data->reg + test_data->reg_offset * index; +int i; + +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 0 ; +} + +/** +* 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: non-zero on failure. +**/ +int 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++) { +int reg =fbnic_csr_reg_pattern_test (fbd, i, test_data); + +if (reg) +return reg; + } + } + +return 0 ; +}
drivers/net/ethernet/meta/fbnic/fbnic_csr.h +4 -0
@@ -1210,4 +1210,8 @@ enum{ FBNIC_CSR_VERSION_V1_0_ASIC = 1, }; +struct fbnic_dev ; + +int 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
--
2.43.0
PATCH v12 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 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.
---drivers/net/ethernet/meta/fbnic/fbnic.h | 1 +
.../net/ethernet/meta/fbnic/fbnic_ethtool.c | 27 +++ drivers/net/ethernet/meta/fbnic/fbnic_irq.c | 154 ++++++++++++++++++ 3 files changed, 183 insertions(+)
drivers/net/ethernet/meta/fbnic/fbnic.h +1 -0
@@ -194,6 +194,7 @@ 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); +int 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)
@@ -1501,6 +1503,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) {
@@ -1508,6 +1532,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 ; }
@@ -1517,6 +1542,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
--
2.43.0
Paolo Abeni
maintainerRe: [PATCH net-next v12 3/5] eth fbnic: Add msix self test
Quoted 15 lines · On 2/6/26 4:42 PM, [email protected] wrote:
drivers/net/ethernet/meta/fbnic/fbnic_irq.c +15
-0+/** +* fbnic_msix_test - Verify behavior of NIC interrupts +* @fbd: device to test +* +* 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. +**/ +int fbnic_msix_test (struct fbnic_dev *fbd) +{ +struct pci_dev *pdev =to_pci_dev (fbd->dev); +struct fbnic_msix_test_data *test_data;
drivers/net/ethernet/meta/fbnic/fbnic_irq.c void fbnic_free_irq(struct fbnic_dev *fbd, int nr, void *data) · line 287
Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_irq.c +10
-0+int result =0 ; +u32 mask =0 ; +int i; + +/* Allocate bitmap and IRQ vector table */ + test_data =kzalloc (sizeof (*test_data),GFP_KERNEL ); + +/* Result = 5 for memory allocation failure */ +if (!test_data) +return 5 ;
Instead of magic numbers you could define some macros, or simply return a boolean success/failures value (as the caller ignores the error code).
/P
Re: [PATCH net-next v12 3/5] eth fbnic: Add msix self test
Quoted 30 lines · Paolo Abeni
Quoted 15 lines · On 2/6/26 4:42 PM, [email protected] wrote:
drivers/net/ethernet/meta/fbnic/fbnic_irq.c +15
-0+/** +* fbnic_msix_test - Verify behavior of NIC interrupts +* @fbd: device to test +* +* 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. +**/ +int fbnic_msix_test (struct fbnic_dev *fbd) +{ +struct pci_dev *pdev =to_pci_dev (fbd->dev); +struct fbnic_msix_test_data *test_data;drivers/net/ethernet/meta/fbnic/fbnic_irq.c void fbnic_free_irq(struct fbnic_dev *fbd, int nr, void *data) · line 287
Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_irq.c +10
-0+int result =0 ; +u32 mask =0 ; +int i; + +/* Allocate bitmap and IRQ vector table */ + test_data =kzalloc (sizeof (*test_data),GFP_KERNEL ); + +/* Result = 5 for memory allocation failure */ +if (!test_data) +return 5 ;Instead of magic numbers you could define some macros, or simply return a boolean success/failures value (as the caller ignores the error code).
Quoted 2 lines
/P
It is not ignored.
The returned u64 value for all the tests is assigned into a per test array:
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); <--- stored here
return !!*data;
}The rval could be a set of test specific define, but regardless, it is meant to refer to a failure point in the test.
Mike
RE: [PATCH net-next v12 3/5] eth fbnic: Add msix self test
In reply to Paolo AbeniQuoted 50 lines
-----Original Message-----
From: Paolo Abeni <[email protected]>
Sent: Tuesday, February 10, 2026 7:06 AM
To: [email protected]; Alexander Duyck <[email protected]>; Jakub Kicinski <[email protected]>; kernel- [email protected]; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Simon Horman <[email protected]>; Russell King <[email protected]>; Keller, Jacob E <[email protected]>; Mohsin Bashir <[email protected]>; Lee Trager <[email protected]>; Dan Carpenter <[email protected]>; Pei Xiao <[email protected]>; Stanislav Fomichev <[email protected]>; Kuniyuki Iwashima <[email protected]>; Samiullah Khawaja <[email protected]>; Ahmed Zaki <[email protected]>; Lobakin, Aleksander <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [PATCH net-next v12 3/5] eth fbnic: Add msix self testQuoted 15 lines · On 2/6/26 4:42 PM, [email protected] wrote:
drivers/net/ethernet/meta/fbnic/fbnic_irq.c +15
-0+/** +* fbnic_msix_test - Verify behavior of NIC interrupts +* @fbd: device to test +* +* 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. +**/ +int fbnic_msix_test (struct fbnic_dev *fbd) +{ +struct pci_dev *pdev =to_pci_dev (fbd->dev); +struct fbnic_msix_test_data *test_data;drivers/net/ethernet/meta/fbnic/fbnic_irq.c void fbnic_free_irq(struct fbnic_dev *fbd, int nr, void *data) · line 287
Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_irq.c +10
-0+int result =0 ; +u32 mask =0 ; +int i; + +/* Allocate bitmap and IRQ vector table */ + test_data =kzalloc (sizeof (*test_data),GFP_KERNEL ); + +/* Result = 5 for memory allocation failure */ +if (!test_data) +return 5 ;Instead of magic numbers you could define some macros, or simply return a boolean success/failures value (as the caller ignores the error code).
Quoted 1 line
/P
At least use -ENOMEM or something....
PATCH v12 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.
---
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 +26 -0
@@ -8,6 +8,7 @@#include <linux/bits.h> #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) \
@@ -153,6 +154,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_ */
--
2.43.0
PATCH v12 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.
--- .../net/ethernet/meta/fbnic/fbnic_ethtool.c | 15 +++ drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 92 +++++++++++++++++++ drivers/net/ethernet/meta/fbnic/fbnic_fw.h | 3 + 3 files changed, 110 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)
@@ -1525,11 +1527,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 +92 -0
111 lines not on this page · raw message
drivers/net/ethernet/meta/fbnic/fbnic_fw.h +3 -0
@@ -104,6 +104,9 @@ 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); +int 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);
--
2.43.0
Quoted 39 lines · On Fri, Feb 06, 2026 at 10:42:40AM -0500, [email protected] 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.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) 0Mike Marciniszyn (Meta) (5):
net: exportnetif_openforself_testusage
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 testdrivers/net/ethernet/meta/fbnic/fbnic.h | 1 + drivers/net/ethernet/meta/fbnic/fbnic_csr.c | 126 ++++++++ drivers/net/ethernet/meta/fbnic/fbnic_csr.h | 4 + .../net/ethernet/meta/fbnic/fbnic_ethtool.c | 93 ++++++ drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 92 ++++++ drivers/net/ethernet/meta/fbnic/fbnic_fw.h | 3 + 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 | 26 ++ net/core/dev.c | 1 + 10 files changed, 776 insertions(+)
Quoted 3 lines
--
2.43.0
Ignore the v12. This is v1.
Mike