Skip to contentSkip to conversation

cxgb4: add ethtool self_test support

PATCH Superseded Vishal Kulkarni 4 participants 13 messages Jul 17, 2020 – Jul 21, 2020

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover cxgb4: add ethtool self_test support

This series of patches add support for below tests.
1. Adapter status test
2. Link test
3. Link speed test
4. Loopback test

Vishal Kulkarni (4):
cxgb4: Add ethtool self-test support
cxgb4: Add link test to ethtool self test.
cxgb4: Add adapter status check to ethtool
cxgb4: Add speed link test to ethtool self_test

 drivers/net/ethernet/chelsio/cxgb4/cxgb4.h    |  10 ++
 .../ethernet/chelsio/cxgb4/cxgb4_ethtool.c    | 137 ++++++++++++++++++
 drivers/net/ethernet/chelsio/cxgb4/sge.c      | 117 ++++++++++++++-
 3 files changed, 261 insertions(+), 3 deletions(-)
Signature · 1 line
2.18.2
#1 lore raw

PATCH 1/4 cxgb4: Add ethtool self-test support

This test checks whether adapter has crashed or not

---
 .../ethernet/chelsio/cxgb4/cxgb4_ethtool.c    | 40 +++++++++++++++++++
 1 file changed, 40 insertions(+)
drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c +40 -0
index b66a2e6cbbeb..1ec6157f8ba7 100644
@@ -25,6 +25,15 @@ static void set_msglevel(struct net_device *dev, u32 val)
 	netdev2adap(dev)->msg_enable = val;
 }
 
+enum cxgb4_ethtool_tests {
+	CXGB4_ETHTOOL_ADAPTER_TEST,
+	CXGB4_ETHTOOL_MAX_TEST,
+};
+
+static const char cxgb4_selftest_strings[CXGB4_ETHTOOL_MAX_TEST][ETH_GSTRING_LEN] = {
+	"Adapter health status",
+};
+
 static const char * const flash_region_strings[] = {
 	"All",
 	"Firmware",
@@ -166,6 +175,8 @@ static int get_sset_count(struct net_device *dev, int sset)
 		       ARRAY_SIZE(loopback_stats_strings);
 	case ETH_SS_PRIV_FLAGS:
 		return ARRAY_SIZE(cxgb4_priv_flags_strings);
+	case ETH_SS_TEST:
+		return ARRAY_SIZE(cxgb4_selftest_strings);
 	default:
 		return -EOPNOTSUPP;
 	}
@@ -228,6 +239,9 @@ static void get_strings(struct net_device *dev, u32 stringset, u8 *data)
 	} else if (stringset == ETH_SS_PRIV_FLAGS) {
 		memcpy(data, cxgb4_priv_flags_strings,
 		       sizeof(cxgb4_priv_flags_strings));
+	} else if (stringset == ETH_SS_TEST) {
+		memcpy(data, cxgb4_selftest_strings,
+		       sizeof(cxgb4_selftest_strings));
 	}
 }
 
@@ -2056,6 +2070,31 @@ static int cxgb4_set_priv_flags(struct net_device *netdev, u32 flags)
 	return 0;
 }
 
+static void cxgb4_adapter_status_test(struct net_device *netdev, u64 *data)
+{
+	struct port_info *pi = netdev_priv(netdev);
+	struct adapter *adap = pi->adapter;
+	u32 pcie_fw;
+
+	pcie_fw = t4_read_reg(adap, PCIE_FW_A);
+	if (pcie_fw & PCIE_FW_ERR_F) {
+		*data = 1;
+		return;
+	}
+
+	*data = 0;
+}
+
+static void cxgb4_self_test(struct net_device *netdev,
+			    struct ethtool_test *eth_test, u64 *data)
+{
+	memset(data, 0, sizeof(u64) * CXGB4_ETHTOOL_MAX_TEST);
+
+	cxgb4_adapter_status_test(netdev, &data[CXGB4_ETHTOOL_ADAPTER_TEST]);
+	if (data[CXGB4_ETHTOOL_ADAPTER_TEST])
+		eth_test->flags |= ETH_TEST_FL_FAILED;
+}
+
 static const struct ethtool_ops cxgb_ethtool_ops = {
 	.supported_coalesce_params = ETHTOOL_COALESCE_USECS |
 				     ETHTOOL_COALESCE_RX_MAX_FRAMES |
@@ -2090,6 +2129,7 @@ static const struct ethtool_ops cxgb_ethtool_ops = {
 	.get_rxfh_indir_size = get_rss_table_size,
 	.get_rxfh	   = get_rss_table,
 	.set_rxfh	   = set_rss_table,
+	.self_test	   = cxgb4_self_test,
 	.flash_device      = set_flash,
 	.get_ts_info       = get_ts_info,
 	.set_dump          = set_dump,
Signature · 1 line
2.21.1
#2 lore raw

PATCH 2/4 cxgb4: Add link test to ethtool self test

In reply to Vishal Kulkarni

This test checks whether link is up or not

---
 .../ethernet/chelsio/cxgb4/cxgb4_ethtool.c    | 35 ++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c +34 -1
index 1ec6157f8ba7..f374757e15c8 100644
@@ -27,11 +27,13 @@ static void set_msglevel(struct net_device *dev, u32 val)
 
 enum cxgb4_ethtool_tests {
 	CXGB4_ETHTOOL_ADAPTER_TEST,
+	CXGB4_ETHTOOL_LINK_TEST,
 	CXGB4_ETHTOOL_MAX_TEST,
 };
 
 static const char cxgb4_selftest_strings[CXGB4_ETHTOOL_MAX_TEST][ETH_GSTRING_LEN] = {
 	"Adapter health status",
+	"Link test",
 };
 
 static const char * const flash_region_strings[] = {
@@ -2085,14 +2087,45 @@ static void cxgb4_adapter_status_test(struct net_device *netdev, u64 *data)
 	*data = 0;
 }
 
+static void cxgb4_link_test(struct net_device *netdev, u64 *data)
+{
+	struct port_info *pi = netdev_priv(netdev);
+	unsigned int link = 0;
+	int ret;
+
+	ret = t4_get_link_params(pi, &link, NULL, NULL);
+	if (ret) {
+		*data = ret;
+		return;
+	}
+
+	*data = !link;
+}
+
 static void cxgb4_self_test(struct net_device *netdev,
 			    struct ethtool_test *eth_test, u64 *data)
 {
+	int i;
+
 	memset(data, 0, sizeof(u64) * CXGB4_ETHTOOL_MAX_TEST);
 
 	cxgb4_adapter_status_test(netdev, &data[CXGB4_ETHTOOL_ADAPTER_TEST]);
-	if (data[CXGB4_ETHTOOL_ADAPTER_TEST])
+	if (data[CXGB4_ETHTOOL_ADAPTER_TEST]) {
+		for (i = CXGB4_ETHTOOL_ADAPTER_TEST + 1;
+		       i < CXGB4_ETHTOOL_MAX_TEST; i++)
+			data[i] = 1;
+
 		eth_test->flags |= ETH_TEST_FL_FAILED;
+		return;
+	}
+
+	cxgb4_link_test(netdev, &data[CXGB4_ETHTOOL_LINK_TEST]);
+	for (i = CXGB4_ETHTOOL_ADAPTER_TEST; i < CXGB4_ETHTOOL_MAX_TEST; i++) {
+		if (data[i]) {
+			eth_test->flags |= ETH_TEST_FL_FAILED;
+			break;
+		}
+	}
 }
 
 static const struct ethtool_ops cxgb_ethtool_ops = {
Signature · 1 line
2.21.1
#3 lore raw

PATCH 3/4 cxgb4: Add speed link test to ethtool

In reply to Vishal Kulkarni

This test checks whether the current speed is supported or not

---
 .../ethernet/chelsio/cxgb4/cxgb4_ethtool.c    | 24 +++++++++++++++++++
 1 file changed, 24 insertions(+)
drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c +24 -0
index f374757e15c8..5d3eb44dee46 100644
@@ -28,12 +28,14 @@ static void set_msglevel(struct net_device *dev, u32 val)
 enum cxgb4_ethtool_tests {
 	CXGB4_ETHTOOL_ADAPTER_TEST,
 	CXGB4_ETHTOOL_LINK_TEST,
+	CXGB4_ETHTOOL_LINK_SPEED_TEST,
 	CXGB4_ETHTOOL_MAX_TEST,
 };
 
 static const char cxgb4_selftest_strings[CXGB4_ETHTOOL_MAX_TEST][ETH_GSTRING_LEN] = {
 	"Adapter health status",
 	"Link test",
+	"Link speed test",
 };
 
 static const char * const flash_region_strings[] = {
@@ -2102,6 +2104,26 @@ static void cxgb4_link_test(struct net_device *netdev, u64 *data)
 	*data = !link;
 }
 
+static void cxgb4_link_speed_test(struct net_device *netdev, u64 *data)
+{
+	struct port_info *pi = netdev_priv(netdev);
+	unsigned int speed;
+	int ret;
+
+	ret = t4_get_link_params(pi, NULL, &speed, NULL);
+	if (ret) {
+		*data = ret;
+		return;
+	}
+
+	if (!speed_to_fw_caps(speed)) {
+		*data = 1;
+		return;
+	}
+
+	*data = 0;
+}
+
 static void cxgb4_self_test(struct net_device *netdev,
 			    struct ethtool_test *eth_test, u64 *data)
 {
@@ -2120,6 +2142,8 @@ static void cxgb4_self_test(struct net_device *netdev,
 	}
 
 	cxgb4_link_test(netdev, &data[CXGB4_ETHTOOL_LINK_TEST]);
+	cxgb4_link_speed_test(netdev, &data[CXGB4_ETHTOOL_LINK_SPEED_TEST]);
+
 	for (i = CXGB4_ETHTOOL_ADAPTER_TEST; i < CXGB4_ETHTOOL_MAX_TEST; i++) {
 		if (data[i]) {
 			eth_test->flags |= ETH_TEST_FL_FAILED;
Signature · 1 line
2.21.1
#4 lore raw

PATCH 4/4 cxgb4: add loop back test to ethtool

In reply to Vishal Kulkarni

In this test, loopback pkt is created and sent on default queue.

---
 drivers/net/ethernet/chelsio/cxgb4/cxgb4.h    |   8 ++
 .../ethernet/chelsio/cxgb4/cxgb4_ethtool.c    |  22 ++++
 drivers/net/ethernet/chelsio/cxgb4/sge.c      | 107 +++++++++++++++++-
 3 files changed, 136 insertions(+), 1 deletion(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h +8 -0
index c59e9ccc2f18..adbc0d088070 100644
@@ -532,6 +532,12 @@ static inline struct mbox_cmd *mbox_cmd_log_entry(struct mbox_cmd_log *log,
 		FW_HDR_FW_VER_BUILD_G(chip##FW_VERSION_BUILD))
 #define FW_INTFVER(chip, intf) (FW_HDR_INTFVER_##intf)
 
+struct cxgb4_ethtool_lb_test {
+	struct completion completion;
+	int result;
+	int loopback;
+};
+
 struct fw_info {
 	u8 chip;
 	char *fs_name;
@@ -685,6 +691,7 @@ struct port_info {
 	u16 nmirrorqsets;
 	u32 vi_mirror_count;
 	struct mutex vi_mirror_mutex; /* Sync access to Mirror VI info */
+	struct cxgb4_ethtool_lb_test ethtool_lb;
 };
 
 struct dentry;
@@ -1595,6 +1602,7 @@ void t4_free_sge_resources(struct adapter *adap);
 void t4_free_ofld_rxqs(struct adapter *adap, int n, struct sge_ofld_rxq *q);
 irq_handler_t t4_intr_handler(struct adapter *adap);
 netdev_tx_t t4_start_xmit(struct sk_buff *skb, struct net_device *dev);
+int cxgb4_selftest_lb_pkt(struct net_device *netdev);
 int t4_ethrx_handler(struct sge_rspq *q, const __be64 *rsp,
 		     const struct pkt_gl *gl);
 int t4_mgmt_tx(struct adapter *adap, struct sk_buff *skb);
drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c +22 -0
index 5d3eb44dee46..9773a4ab435b 100644
@@ -29,6 +29,7 @@ enum cxgb4_ethtool_tests {
 	CXGB4_ETHTOOL_ADAPTER_TEST,
 	CXGB4_ETHTOOL_LINK_TEST,
 	CXGB4_ETHTOOL_LINK_SPEED_TEST,
+	CXGB4_ETHTOOL_LB_TEST,
 	CXGB4_ETHTOOL_MAX_TEST,
 };
 
@@ -36,6 +37,7 @@ static const char cxgb4_selftest_strings[CXGB4_ETHTOOL_MAX_TEST][ETH_GSTRING_LEN
 	"Adapter health status",
 	"Link test",
 	"Link speed test",
+	"Loop back test",
 };
 
 static const char * const flash_region_strings[] = {
@@ -2124,6 +2126,23 @@ static void cxgb4_link_speed_test(struct net_device *netdev, u64 *data)
 	*data = 0;
 }
 
+static void cxgb4_lb_test(struct net_device *netdev, u64 *lb_status)
+{
+	int dev_state = netif_running(netdev);
+
+	if (dev_state) {
+		netif_tx_stop_all_queues(netdev);
+		netif_carrier_off(netdev);
+	}
+
+	*lb_status = cxgb4_selftest_lb_pkt(netdev);
+
+	if (dev_state) {
+		netif_tx_start_all_queues(netdev);
+		netif_carrier_on(netdev);
+	}
+}
+
 static void cxgb4_self_test(struct net_device *netdev,
 			    struct ethtool_test *eth_test, u64 *data)
 {
@@ -2144,6 +2163,9 @@ static void cxgb4_self_test(struct net_device *netdev,
 	cxgb4_link_test(netdev, &data[CXGB4_ETHTOOL_LINK_TEST]);
 	cxgb4_link_speed_test(netdev, &data[CXGB4_ETHTOOL_LINK_SPEED_TEST]);
 
+	if (eth_test->flags == ETH_TEST_FL_OFFLINE)
+		cxgb4_lb_test(netdev, &data[CXGB4_ETHTOOL_LB_TEST]);
+
 	for (i = CXGB4_ETHTOOL_ADAPTER_TEST; i < CXGB4_ETHTOOL_MAX_TEST; i++) {
 		if (data[i]) {
 			eth_test->flags |= ETH_TEST_FL_FAILED;
drivers/net/ethernet/chelsio/cxgb4/sge.c +106 -1

137 lines not on this page · raw message

Signature · 1 line
2.21.1
#5 lore raw
In reply to Vishal Kulkarni
Quoted 5 lines · Vishal Kulkarni

This series of patches add support for below tests.
1. Adapter status test
2. Link test
3. Link speed test
4. Loopback test

Hi Vishal

The loopback test is pretty usual for an ethtool self test. But the first 3 are rather odd. They don't really seem to be self tests. What reason do you have for adding these? Are you trying to debug a specific problem?

Andrew

#6 lore raw
Quoted 7 lines · Andrew Lunn
Quoted 5 lines · Vishal Kulkarni

This series of patches add support for below tests.
1. Adapter status test
2. Link test
3. Link speed test
4. Loopback test

Quoted 8 lines

Hi Vishal

The loopback test is pretty usual for an ethtool self test. But the first 3 are rather odd. They don't really seem to be self tests. What reason do you have for adding these? Are you trying to debug a specific problem?

Andrew

Hi Andrew,

Our requirement is to add a list of self tests that can summarize if the adapter is functioning properly in a single command during system init. The above tests are the most common ones run by our on-field diagnostics team. Besides, these tests seem to be the most common among other drivers as well.

Hence we have added
1. Adapter status test: Tests whether the adapter is alive or crashed
2. Link test: Adapter PHY is up or not.
3. Link speed test: Adapter has negotiated link speed correctly or not.

-Vishal

#7 lore raw
Quoted 18 lines · Vishal Kulkarni
Quoted 7 lines · Andrew Lunn
Quoted 5 lines · Vishal Kulkarni

This series of patches add support for below tests.
1. Adapter status test
2. Link test
3. Link speed test
4. Loopback test

Quoted 8 lines

Hi Vishal

The loopback test is pretty usual for an ethtool self test. But the first 3 are rather odd. They don't really seem to be self tests. What reason do you have for adding these? Are you trying to debug a specific problem?

Andrew

Hi Andrew,

Quoted 8 lines

Our requirement is to add a list of self tests that can summarize if the adapter is functioning properly in a single command during system init. The above tests are the most common ones run by our on-field diagnostics team. Besides, these tests seem to be the most common among other drivers as well.

Hence we have added
1. Adapter status test: Tests whether the adapter is alive or crashed
2. Link test: Adapter PHY is up or not.
3. Link speed test: Adapter has negotiated link speed correctly or not.

Hi Vishal

Knowing that the field team does this is useful. But i still don't see these as self tests.

From the man page:

-t --test
Executes adapter selftest on the specified network device. Possible test modes are:

offline
Perform full set of tests, possibly interrupting normal operation during the tests,

online Perform limited set of tests, not interrupting normal operation,

external_lb
Perform full set of tests, as for offline, and additionally an external-loopback test.

Maybe a crashed adaptor could be considered a self test, but

1) I expect nearly everything else is failing so it is pretty obvious
2) devlink health seems like a better API

The PHY is up or not is only partially to do with self. It has a lot to do with the link partner and the cable. Plus ip link show will tell you this.

3) This actually sounds like a bug. Why would it of negotiated a link speed it cannot support? If you have non-overlapping sets of advertised link modes, i.e. there is no common mode to select, the link should remain down, but this is not an error. You can use ethtool to list both the local and peer advertised modes. You could also report this via the new link state properties Mellanox just added.

Andrew

#8 lore raw
Quoted 60 lines · Andrew Lunn
Quoted 18 lines · Vishal Kulkarni
Quoted 7 lines · Andrew Lunn
Quoted 5 lines · Vishal Kulkarni

This series of patches add support for below tests.
1. Adapter status test
2. Link test
3. Link speed test
4. Loopback test

Quoted 8 lines

Hi Vishal

The loopback test is pretty usual for an ethtool self test. But the first 3 are rather odd. They don't really seem to be self tests. What reason do you have for adding these? Are you trying to debug a specific problem?

Andrew

Hi Andrew,

Quoted 8 lines

Our requirement is to add a list of self tests that can summarize if the adapter is functioning properly in a single command during system init. The above tests are the most common ones run by our on-field diagnostics team. Besides, these tests seem to be the most common among other drivers as well.

Hence we have added
1. Adapter status test: Tests whether the adapter is alive or crashed
2. Link test: Adapter PHY is up or not.
3. Link speed test: Adapter has negotiated link speed correctly or not.

Hi Vishal

Knowing that the field team does this is useful. But i still don't see these as self tests.

From the man page:

-t --test
Executes adapter selftest on the specified network device. Possible test modes are:

offline
Perform full set of tests, possibly interrupting normal operation during the tests,

online Perform limited set of tests, not interrupting normal operation,

external_lb
Perform full set of tests, as for offline, and additionally an external-loopback test.

Maybe a crashed adaptor could be considered a self test, but

1) I expect nearly everything else is failing so it is pretty obvious
2) devlink health seems like a better API

The PHY is up or not is only partially to do with self. It has a lot to do with the link partner and the cable. Plus ip link show will tell you this.

Quoted 8 lines

3) This actually sounds like a bug. Why would it of negotiated a link speed it cannot support? If you have non-overlapping sets of advertised link modes, i.e. there is no common mode to select, the link should remain down, but this is not an error. You can use ethtool to list both the local and peer advertised modes. You could also report this via the new link state properties Mellanox just added.

Andrew

Hi Andrew,

Our requirement is to get overall adapter health from single tool and command. Using devlink and ip will require multiple tools and commands.

-Vishal

#9 lore raw
Quoted 4 lines

Hi Andrew,

Our requirement is to get overall adapter health from single tool and command. Using devlink and ip will require multiple tools and commands.

That is not a good reason to abuse the Kernel norms and do odd things.

Andrew

maintainer
#10 lore raw
Quoted 6 lines · On Tue, 21 Jul 2020 15:41:45 +0200 Andrew Lunn wrote:
Quoted 4 lines

Hi Andrew,

Our requirement is to get overall adapter health from single tool and command. Using devlink and ip will require multiple tools and commands.

That is not a good reason to abuse the Kernel norms and do odd things.

+1

You should probably build your own tool if you have this single tool requirement. This single tool fallacy leads to very bad outcomes, like people trying to report system state in device dumps, 'cause they want system state in their customer bug reports :/

maintainer
#11 lore raw
In reply to Andrew Lunn

From: Andrew Lunn <[email protected]>
Date: Tue, 21 Jul 2020 15:41:45 +0200

Quoted 6 lines
Quoted 4 lines

Hi Andrew,

Our requirement is to get overall adapter health from single tool and command. Using devlink and ip will require multiple tools and commands.

That is not a good reason to abuse the Kernel norms and do odd things.

+1

maintainer
#12 lore raw
In reply to Vishal Kulkarni

From: Vishal Kulkarni <[email protected]>
Date: Tue, 21 Jul 2020 19:08:35 +0530

Quoted 2 lines

Our requirement is to get overall adapter health from single tool and command. Using devlink and ip will require multiple tools and commands.

This is an invalid argument.

We have multiple facilities, each of which handles a specific task that it was designed for. You shall use such facilities, as appropriate, to fulfill your needs.