Skip to contentSkip to conversation

sfc: ethtool for EF100 and related improvements

PATCH In review Edward Cree 3 participants 11 messages Sep 7, 2020 – Sep 8, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover sfc: ethtool for EF100 and related improvements

This series adds the ethtool support to the EF100 driver that was held
back from the original submission as the lack of phy_ops caused issues.
Patch #2, removing the phy_op indirection, deals with this. There are a
lot of checkpatch warnings / xmastree violations but they're all in pure code movement so I've left the code as it is.
While patch #1 is technically a fix and possibly could go to 'net', I've
put it in this series since it only becomes triggerable with the added 'ethtool --reset' support.

Edward Cree (6):
sfc: don't double-down() filters in ef100_reset()
sfc: remove phy_op indirection
sfc: add ethtool ops and miscellaneous ndos to EF100
sfc: handle limited FEC support
sfc: remove EFX_DRIVER_VERSION
sfc: simplify DMA mask setting

 drivers/net/ethernet/sfc/ef100_ethtool.c    |  41 ++
 drivers/net/ethernet/sfc/ef100_netdev.c     |   4 +
 drivers/net/ethernet/sfc/ef100_nic.c        |  19 +-
 drivers/net/ethernet/sfc/efx.c              |  20 +-
 drivers/net/ethernet/sfc/efx_common.c       |  38 +-
 drivers/net/ethernet/sfc/ethtool_common.c   |  45 +-
 drivers/net/ethernet/sfc/mcdi.h             |   1 -
 drivers/net/ethernet/sfc/mcdi_port.c        | 593 +------------------
 drivers/net/ethernet/sfc/mcdi_port_common.c | 604 +++++++++++++++++++-
 drivers/net/ethernet/sfc/mcdi_port_common.h |  15 +-
 drivers/net/ethernet/sfc/net_driver.h       |  49 --
 drivers/net/ethernet/sfc/selftest.c         |  12 +-
 12 files changed, 688 insertions(+), 753 deletions(-)
#1 lore raw

PATCH 1/6 sfc: don't double-down() filters in ef100_reset()

dev_close(), by way of ef100_net_stop(), already brings down the filter
table, so there's no need to do it again (which just causes lots of WARN_ONs).
Similarly, don't bring it up ourselves, as dev_open() -> ef100_net_open()
will do it, and will fail if it's already been brought up.

Fixes a9dc3d5612ce ("sfc_ef100: RX filter table management and related gubbins")
---
 drivers/net/ethernet/sfc/ef100_nic.c | 12 ------------
 1 file changed, 12 deletions(-)
drivers/net/ethernet/sfc/ef100_nic.c +0 -12
index 19fe86b3b316..9cf5b8f8fab9 100644
@@ -428,24 +428,12 @@ static int ef100_reset(struct efx_nic *efx, enum reset_type reset_type)
 		__clear_bit(reset_type, &efx->reset_pending);
 		rc = dev_open(efx->net_dev, NULL);
 	} else if (reset_type == RESET_TYPE_ALL) {
-		/* A RESET_TYPE_ALL will cause filters to be removed, so we remove filters
-		 * and reprobe after reset to avoid removing filters twice
-		 */
-		down_write(&efx->filter_sem);
-		ef100_filter_table_down(efx);
-		up_write(&efx->filter_sem);
 		rc = efx_mcdi_reset(efx, reset_type);
 		if (rc)
 			return rc;
 
 		netif_device_attach(efx->net_dev);
 
-		down_write(&efx->filter_sem);
-		rc = ef100_filter_table_up(efx);
-		up_write(&efx->filter_sem);
-		if (rc)
-			return rc;
-
 		rc = dev_open(efx->net_dev, NULL);
 	} else {
 		rc = 1;	/* Leave the device closed */
#2 lore raw

PATCH 2/6 sfc: remove phy_op indirection

In reply to Edward Cree

Originally there were several implementations of PHY operations for the
several different PHYs used on Falcon boards. But Falcon is now in a separate driver, and all sfc NICs since then have had MCDI-managed PHYs.
Thus, there is no need to indirect through function pointers in
efx->phy_op; we can simply call the efx_mcdi_phy_* functions directly.

This also hooks up these functions for EF100, which was previously using
the dummy_phy_ops.

---
 drivers/net/ethernet/sfc/efx.c              |  17 +-
 drivers/net/ethernet/sfc/efx_common.c       |  26 +-
 drivers/net/ethernet/sfc/ethtool_common.c   |  44 +-
 drivers/net/ethernet/sfc/mcdi.h             |   1 -
 drivers/net/ethernet/sfc/mcdi_port.c        | 593 +-------------------
 drivers/net/ethernet/sfc/mcdi_port_common.c | 560 ++++++++++++++++++
 drivers/net/ethernet/sfc/mcdi_port_common.h |  13 +-
 drivers/net/ethernet/sfc/net_driver.h       |  47 --
 drivers/net/ethernet/sfc/selftest.c         |  12 +-
 9 files changed, 601 insertions(+), 712 deletions(-)
drivers/net/ethernet/sfc/efx.c +5 -12
index e06fa89f2d72..aad6710c0afb 100644
@@ -33,7 +33,7 @@
 #include "selftest.h"
 #include "sriov.h"
 
-#include "mcdi.h"
+#include "mcdi_port_common.h"
 #include "mcdi_pcol.h"
 #include "workarounds.h"
 
@@ -149,23 +149,17 @@ static int efx_init_port(struct efx_nic *efx)
 
 	mutex_lock(&efx->mac_lock);
 
-	rc = efx->phy_op->init(efx);
-	if (rc)
-		goto fail1;
-
 	efx->port_initialized = true;
 
 	/* Ensure the PHY advertises the correct flow control settings */
-	rc = efx->phy_op->reconfigure(efx);
+	rc = efx_mcdi_port_reconfigure(efx);
 	if (rc && rc != -EPERM)
-		goto fail2;
+		goto fail;
 
 	mutex_unlock(&efx->mac_lock);
 	return 0;
 
-fail2:
-	efx->phy_op->fini(efx);
-fail1:
+fail:
 	mutex_unlock(&efx->mac_lock);
 	return rc;
 }
@@ -177,7 +171,6 @@ static void efx_fini_port(struct efx_nic *efx)
 	if (!efx->port_initialized)
 		return;
 
-	efx->phy_op->fini(efx);
 	efx->port_initialized = false;
 
 	efx->link_state.up = false;
@@ -1229,7 +1222,7 @@ static int efx_pm_thaw(struct device *dev)
 			goto fail;
 
 		mutex_lock(&efx->mac_lock);
-		efx->phy_op->reconfigure(efx);
+		efx_mcdi_port_reconfigure(efx);
 		mutex_unlock(&efx->mac_lock);
 
 		efx_start_all(efx);
drivers/net/ethernet/sfc/efx_common.c +4 -22
index dfc6032e75f4..9eda54e27cd4 100644
@@ -19,6 +19,7 @@
 #include "rx_common.h"
 #include "tx_common.h"
 #include "nic.h"
+#include "mcdi_port_common.h"
 #include "io.h"
 #include "mcdi_pcol.h"
 
@@ -544,7 +545,7 @@ void efx_start_all(struct efx_nic *efx)
 	 * to poll now because we could have missed a change
 	 */
 	mutex_lock(&efx->mac_lock);
-	if (efx->phy_op->poll(efx))
+	if (efx_mcdi_phy_poll(efx))
 		efx_link_status_changed(efx);
 	mutex_unlock(&efx->mac_lock);
 
@@ -714,9 +715,6 @@ void efx_reset_down(struct efx_nic *efx, enum reset_type method)
 	mutex_lock(&efx->mac_lock);
 	down_write(&efx->filter_sem);
 	mutex_lock(&efx->rss_lock);
-	if (efx->port_initialized && method != RESET_TYPE_INVISIBLE &&
-	    method != RESET_TYPE_DATAPATH)
-		efx->phy_op->fini(efx);
 	efx->type->fini(efx);
 }
 
@@ -759,10 +757,7 @@ int efx_reset_up(struct efx_nic *efx, enum reset_type method, bool ok)
 
 	if (efx->port_initialized && method != RESET_TYPE_INVISIBLE &&
 	    method != RESET_TYPE_DATAPATH) {
-		rc = efx->phy_op->init(efx);
-		if (rc)
-			goto fail;
-		rc = efx->phy_op->reconfigure(efx);
+		rc = efx_mcdi_port_reconfigure(efx);
 		if (rc && rc != -EPERM)
 			netif_err(efx, drv, efx->net_dev,
 				  "could not restore PHY settings\n");
@@ -959,7 +954,7 @@ void efx_schedule_reset(struct efx_nic *efx, enum reset_type type)
 
 /**************************************************************************
  *
- * Dummy PHY/MAC operations
+ * Dummy NIC operations
  *
  * Can be used for some unimplemented operations
  * Needed so all function pointers are valid and do not have to be tested
@@ -972,18 +967,6 @@ int efx_port_dummy_op_int(struct efx_nic *efx)
 }
 void efx_port_dummy_op_void(struct efx_nic *efx) {}
 
-static bool efx_port_dummy_op_poll(struct efx_nic *efx)
-{
-	return false;
-}
-
-static const struct efx_phy_operations efx_dummy_phy_operations = {
-	.init		 = efx_port_dummy_op_int,
-	.reconfigure	 = efx_port_dummy_op_int,
-	.poll		 = efx_port_dummy_op_poll,
-	.fini		 = efx_port_dummy_op_void,
-};
-
 /**************************************************************************
  *
  * Data housekeeping
@@ -1037,7 +1020,6 @@ int efx_init_struct(struct efx_nic *efx,
 	efx->rps_hash_table = kcalloc(EFX_ARFS_HASH_TABLE_SIZE,
 				      sizeof(*efx->rps_hash_table), GFP_KERNEL);
 #endif
-	efx->phy_op = &efx_dummy_phy_operations;
 	efx->mdio.dev = net_dev;
 	INIT_WORK(&efx->mac_work, efx_mac_work);
 	init_waitqueue_head(&efx->flush_wq);
drivers/net/ethernet/sfc/ethtool_common.c +15 -29

104 lines not on this page · raw message

drivers/net/ethernet/sfc/mcdi.h +0 -1
index 8aed65018964..ef6d21e4bd0b 100644
@@ -355,7 +355,6 @@ int efx_mcdi_wol_filter_get_magic(struct efx_nic *efx, int *id_out);
 int efx_mcdi_wol_filter_remove(struct efx_nic *efx, int id);
 int efx_mcdi_wol_filter_reset(struct efx_nic *efx);
 int efx_mcdi_flush_rxqs(struct efx_nic *efx);
-int efx_mcdi_port_reconfigure(struct efx_nic *efx);
 void efx_mcdi_process_link_change(struct efx_nic *efx, efx_qword_t *ev);
 void efx_mcdi_mac_start_stats(struct efx_nic *efx);
 void efx_mcdi_mac_stop_stats(struct efx_nic *efx);
drivers/net/ethernet/sfc/mcdi_port.c +2 -591

616 lines not on this page · raw message

drivers/net/ethernet/sfc/mcdi_port_common.c +560 -0

578 lines not on this page · raw message

drivers/net/ethernet/sfc/mcdi_port_common.h +11 -2
index 9dbeee83266f..9d214079f699 100644
@@ -45,9 +45,18 @@ u32 ethtool_fec_caps_to_mcdi(u32 ethtool_cap);
 u32 mcdi_fec_caps_to_ethtool(u32 caps, bool is_25g);
 void efx_mcdi_phy_check_fcntl(struct efx_nic *efx, u32 lpa);
 bool efx_mcdi_phy_poll(struct efx_nic *efx);
-int efx_mcdi_phy_get_fecparam(struct efx_nic *efx,
-			      struct ethtool_fecparam *fec);
+int efx_mcdi_phy_probe(struct efx_nic *efx);
+void efx_mcdi_phy_remove(struct efx_nic *efx);
+void efx_mcdi_phy_get_link_ksettings(struct efx_nic *efx, struct ethtool_link_ksettings *cmd);
+int efx_mcdi_phy_set_link_ksettings(struct efx_nic *efx, const struct ethtool_link_ksettings *cmd);
+int efx_mcdi_phy_get_fecparam(struct efx_nic *efx, struct ethtool_fecparam *fec);
+int efx_mcdi_phy_set_fecparam(struct efx_nic *efx, const struct ethtool_fecparam *fec);
 int efx_mcdi_phy_test_alive(struct efx_nic *efx);
+int efx_mcdi_port_reconfigure(struct efx_nic *efx);
+int efx_mcdi_phy_run_tests(struct efx_nic *efx, int *results, unsigned flags);
+const char *efx_mcdi_phy_test_name(struct efx_nic *efx, unsigned int index);
+int efx_mcdi_phy_get_module_eeprom(struct efx_nic *efx, struct ethtool_eeprom *ee, u8 *data);
+int efx_mcdi_phy_get_module_info(struct efx_nic *efx, struct ethtool_modinfo *modinfo);
 int efx_mcdi_set_mac(struct efx_nic *efx);
 int efx_mcdi_set_mtu(struct efx_nic *efx);
 int efx_mcdi_mac_init_stats(struct efx_nic *efx);
drivers/net/ethernet/sfc/net_driver.h +0 -47

65 lines not on this page · raw message

drivers/net/ethernet/sfc/selftest.c +4 -8
index 34b9c7d50c4e..574856a8a83c 100644
@@ -21,6 +21,7 @@
 #include "efx_common.h"
 #include "efx_channels.h"
 #include "nic.h"
+#include "mcdi_port_common.h"
 #include "selftest.h"
 #include "workarounds.h"
 
@@ -99,10 +100,8 @@ static int efx_test_phy_alive(struct efx_nic *efx, struct efx_self_tests *tests)
 {
 	int rc = 0;
 
-	if (efx->phy_op->test_alive) {
-		rc = efx->phy_op->test_alive(efx);
-		tests->phy_alive = rc ? -1 : 1;
-	}
+	rc = efx_mcdi_phy_test_alive(efx);
+	tests->phy_alive = rc ? -1 : 1;
 
 	return rc;
 }
@@ -257,11 +256,8 @@ static int efx_test_phy(struct efx_nic *efx, struct efx_self_tests *tests,
 {
 	int rc;
 
-	if (!efx->phy_op->run_tests)
-		return 0;
-
 	mutex_lock(&efx->mac_lock);
-	rc = efx->phy_op->run_tests(efx, tests->phy_ext, flags);
+	rc = efx_mcdi_phy_run_tests(efx, tests->phy_ext, flags);
 	mutex_unlock(&efx->mac_lock);
 	if (rc == -EPERM)
 		rc = 0;
maintainer
#3 lore raw

Re: [PATCH net-next 2/6] sfc: remove phy_op indirection

Quoted 2 lines · On Mon, 7 Sep 2020 17:14:34 +0100 Edward Cree wrote:
 drivers/net/ethernet/sfc/mcdi_port.c        | 593 +-------------------
 drivers/net/ethernet/sfc/mcdi_port_common.c | 560 ++++++++++++++++++

Would you mind improving variable ordering and addressing checkpatch complaints while moving this code? The camel case and breaking up case statements warning can definitely be ignored, but there are others.

#4 lore raw

Re: [PATCH net-next 2/6] sfc: remove phy_op indirection

Quoted 6 lines · Jakub Kicinski
Quoted 2 lines · On Mon, 7 Sep 2020 17:14:34 +0100 Edward Cree wrote:
 drivers/net/ethernet/sfc/mcdi_port.c        | 593 +-------------------
 drivers/net/ethernet/sfc/mcdi_port_common.c | 560 ++++++++++++++++++

Would you mind improving variable ordering and addressing checkpatch complaints while moving this code? The camel case and breaking up case statements warning can definitely be ignored, but there are others.

I'd prefer to do it as a separate follow-up patch, so that git tools can more reliably trace the history across the movement, per [1]. If the series needs respinning then I'll add it in v2, otherwise I'll post it standalone after this goes in.

-ed

[1]: https://yarchive.net/comp/linux/coding_style.html#16

maintainer
#5 lore raw

Re: [PATCH net-next 2/6] sfc: remove phy_op indirection

Quoted 11 lines · On Mon, 7 Sep 2020 20:31:03 +0100 Edward Cree wrote:
Quoted 6 lines · Jakub Kicinski
Quoted 2 lines · On Mon, 7 Sep 2020 17:14:34 +0100 Edward Cree wrote:
 drivers/net/ethernet/sfc/mcdi_port.c        | 593 +-------------------
 drivers/net/ethernet/sfc/mcdi_port_common.c | 560 ++++++++++++++++++  

Would you mind improving variable ordering and addressing checkpatch complaints while moving this code? The camel case and breaking up case statements warning can definitely be ignored, but there are others.

I'd prefer to do it as a separate follow-up patch, so that git tools can more reliably trace the history across the movement, per [1]. If the series needs respinning then I'll add it in v2, otherwise I'll post it standalone after this goes in.

Okay, applied, thanks!

#6 lore raw

PATCH 3/6 sfc: add ethtool ops and miscellaneous ndos to EF100

In reply to Edward Cree

Mostly just calls to existing common functions.

---
 drivers/net/ethernet/sfc/ef100_ethtool.c | 41 ++++++++++++++++++++++++
 drivers/net/ethernet/sfc/ef100_netdev.c  |  4 +++
 drivers/net/ethernet/sfc/ef100_nic.c     |  7 +++-
 3 files changed, 51 insertions(+), 1 deletion(-)
drivers/net/ethernet/sfc/ef100_ethtool.c +41 -0
index 729c425d0f78..835c838b7dfa 100644
@@ -17,8 +17,49 @@
 #include "ef100_ethtool.h"
 #include "mcdi_functions.h"
 
+/* This is the maximum number of descriptor rings supported by the QDMA */
+#define EFX_EF100_MAX_DMAQ_SIZE 16384UL
+
+static void ef100_ethtool_get_ringparam(struct net_device *net_dev,
+					struct ethtool_ringparam *ring)
+{
+	struct efx_nic *efx = netdev_priv(net_dev);
+
+	ring->rx_max_pending = EFX_EF100_MAX_DMAQ_SIZE;
+	ring->tx_max_pending = EFX_EF100_MAX_DMAQ_SIZE;
+	ring->rx_pending = efx->rxq_entries;
+	ring->tx_pending = efx->txq_entries;
+}
+
 /*	Ethtool options available
  */
 const struct ethtool_ops ef100_ethtool_ops = {
 	.get_drvinfo		= efx_ethtool_get_drvinfo,
+	.get_msglevel		= efx_ethtool_get_msglevel,
+	.set_msglevel		= efx_ethtool_set_msglevel,
+	.get_pauseparam         = efx_ethtool_get_pauseparam,
+	.set_pauseparam         = efx_ethtool_set_pauseparam,
+	.get_sset_count		= efx_ethtool_get_sset_count,
+	.self_test		= efx_ethtool_self_test,
+	.get_strings		= efx_ethtool_get_strings,
+	.get_link_ksettings	= efx_ethtool_get_link_ksettings,
+	.set_link_ksettings	= efx_ethtool_set_link_ksettings,
+	.get_link		= ethtool_op_get_link,
+	.get_ringparam		= ef100_ethtool_get_ringparam,
+	.get_fecparam		= efx_ethtool_get_fecparam,
+	.set_fecparam		= efx_ethtool_set_fecparam,
+	.get_ethtool_stats	= efx_ethtool_get_stats,
+	.get_rxnfc              = efx_ethtool_get_rxnfc,
+	.set_rxnfc              = efx_ethtool_set_rxnfc,
+	.reset                  = efx_ethtool_reset,
+
+	.get_rxfh_indir_size	= efx_ethtool_get_rxfh_indir_size,
+	.get_rxfh_key_size	= efx_ethtool_get_rxfh_key_size,
+	.get_rxfh		= efx_ethtool_get_rxfh,
+	.set_rxfh		= efx_ethtool_set_rxfh,
+	.get_rxfh_context	= efx_ethtool_get_rxfh_context,
+	.set_rxfh_context	= efx_ethtool_set_rxfh_context,
+
+	.get_module_info	= efx_ethtool_get_module_info,
+	.get_module_eeprom	= efx_ethtool_get_module_eeprom,
 };
drivers/net/ethernet/sfc/ef100_netdev.c +4 -0
index 63c311ba28b9..67fe44db6b61 100644
@@ -217,9 +217,13 @@ static const struct net_device_ops ef100_netdev_ops = {
 	.ndo_open               = ef100_net_open,
 	.ndo_stop               = ef100_net_stop,
 	.ndo_start_xmit         = ef100_hard_start_xmit,
+	.ndo_tx_timeout         = efx_watchdog,
 	.ndo_get_stats64        = efx_net_stats,
+	.ndo_change_mtu         = efx_change_mtu,
 	.ndo_validate_addr      = eth_validate_addr,
+	.ndo_set_mac_address    = efx_set_mac_address,
 	.ndo_set_rx_mode        = efx_set_rx_mode, /* Lookout */
+	.ndo_set_features       = efx_set_features,
 	.ndo_get_phys_port_id   = efx_get_phys_port_id,
 	.ndo_get_phys_port_name = efx_get_phys_port_name,
 #ifdef CONFIG_RFS_ACCEL
drivers/net/ethernet/sfc/ef100_nic.c +6 -1
index 9cf5b8f8fab9..fb7752d62ce0 100644
@@ -684,7 +684,7 @@ static unsigned int ef100_check_caps(const struct efx_nic *efx,
 /*	NIC level access functions
  */
 #define EF100_OFFLOAD_FEATURES	(NETIF_F_HW_CSUM | NETIF_F_RXCSUM |	\
-	NETIF_F_HIGHDMA | NETIF_F_SG | NETIF_F_FRAGLIST |		\
+	NETIF_F_HIGHDMA | NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_NTUPLE | \
 	NETIF_F_RXHASH | NETIF_F_RXFCS | NETIF_F_TSO_ECN | NETIF_F_RXALL | \
 	NETIF_F_TSO_MANGLEID | NETIF_F_HW_VLAN_CTAG_TX)
 
@@ -757,6 +757,7 @@ const struct efx_nic_type ef100_pf_nic_type = {
 	.rx_restore_rss_contexts = efx_mcdi_rx_restore_rss_contexts,
 
 	.reconfigure_mac = ef100_reconfigure_mac,
+	.reconfigure_port = efx_mcdi_port_reconfigure,
 	.test_nvram = efx_new_mcdi_nvram_test_all,
 	.describe_stats = ef100_describe_stats,
 	.start_stats = efx_mcdi_mac_start_stats,
@@ -1158,6 +1159,10 @@ static int ef100_probe_main(struct efx_nic *efx)
 		goto fail;
 	/* Reset (most) configuration for this function */
 	rc = efx_mcdi_reset(efx, RESET_TYPE_ALL);
+	if (rc)
+		goto fail;
+	/* Enable event logging */
+	rc = efx_mcdi_log_ctrl(efx, true, false, 0);
 	if (rc)
 		goto fail;
 
#7 lore raw

PATCH 4/6 sfc: handle limited FEC support

In reply to Edward Cree

If the reported PHY capabilities do not include a given FEC mode, don't
attempt to select that FEC mode anyway. If the user tries to set a mode through ethtool that is not supported, return an error.
The _REQUESTED bits don't appear in the supported caps, but are implied
by the corresponding FEC bits.

---
 drivers/net/ethernet/sfc/mcdi_port_common.c | 48 +++++++++++++++------
 drivers/net/ethernet/sfc/mcdi_port_common.h |  2 +-
 2 files changed, 36 insertions(+), 14 deletions(-)
drivers/net/ethernet/sfc/mcdi_port_common.c +35 -13
index 71c76a6a6b0e..c0e1c88a652c 100644
@@ -308,7 +308,7 @@ void efx_mcdi_phy_decode_link(struct efx_nic *efx,
  * Both RS and BASER (whether AUTO or not) means use FEC if cable and link
  * partner support it, preferring RS to BASER.
  */
-u32 ethtool_fec_caps_to_mcdi(u32 ethtool_cap)
+u32 ethtool_fec_caps_to_mcdi(u32 supported_cap, u32 ethtool_cap)
 {
 	u32 ret = 0;
 
@@ -316,17 +316,21 @@ u32 ethtool_fec_caps_to_mcdi(u32 ethtool_cap)
 		return 0;
 
 	if (ethtool_cap & ETHTOOL_FEC_AUTO)
-		ret |= (1 << MC_CMD_PHY_CAP_BASER_FEC_LBN) |
-		       (1 << MC_CMD_PHY_CAP_25G_BASER_FEC_LBN) |
-		       (1 << MC_CMD_PHY_CAP_RS_FEC_LBN);
-	if (ethtool_cap & ETHTOOL_FEC_RS)
+		ret |= ((1 << MC_CMD_PHY_CAP_BASER_FEC_LBN) |
+			(1 << MC_CMD_PHY_CAP_25G_BASER_FEC_LBN) |
+			(1 << MC_CMD_PHY_CAP_RS_FEC_LBN)) & supported_cap;
+	if (ethtool_cap & ETHTOOL_FEC_RS &&
+	    supported_cap & (1 << MC_CMD_PHY_CAP_RS_FEC_LBN))
 		ret |= (1 << MC_CMD_PHY_CAP_RS_FEC_LBN) |
 		       (1 << MC_CMD_PHY_CAP_RS_FEC_REQUESTED_LBN);
-	if (ethtool_cap & ETHTOOL_FEC_BASER)
-		ret |= (1 << MC_CMD_PHY_CAP_BASER_FEC_LBN) |
-		       (1 << MC_CMD_PHY_CAP_25G_BASER_FEC_LBN) |
-		       (1 << MC_CMD_PHY_CAP_BASER_FEC_REQUESTED_LBN) |
-		       (1 << MC_CMD_PHY_CAP_25G_BASER_FEC_REQUESTED_LBN);
+	if (ethtool_cap & ETHTOOL_FEC_BASER) {
+		if (supported_cap & (1 << MC_CMD_PHY_CAP_BASER_FEC_LBN))
+			ret |= (1 << MC_CMD_PHY_CAP_BASER_FEC_LBN) |
+			       (1 << MC_CMD_PHY_CAP_BASER_FEC_REQUESTED_LBN);
+		if (supported_cap & (1 << MC_CMD_PHY_CAP_25G_BASER_FEC_LBN))
+			ret |= (1 << MC_CMD_PHY_CAP_25G_BASER_FEC_LBN) |
+			       (1 << MC_CMD_PHY_CAP_25G_BASER_FEC_REQUESTED_LBN);
+	}
 	return ret;
 }
 
@@ -577,7 +581,7 @@ int efx_mcdi_phy_set_link_ksettings(struct efx_nic *efx, const struct ethtool_li
 		}
 	}
 
-	caps |= ethtool_fec_caps_to_mcdi(efx->fec_config);
+	caps |= ethtool_fec_caps_to_mcdi(phy_cfg->supported_cap, efx->fec_config);
 
 	rc = efx_mcdi_set_link(efx, caps, efx_get_mcdi_phy_flags(efx),
 			       efx->loopback_mode, 0);
@@ -645,12 +649,30 @@ int efx_mcdi_phy_get_fecparam(struct efx_nic *efx, struct ethtool_fecparam *fec)
 	return 0;
 }
 
+/* Basic validation to ensure that the caps we are going to attempt to set are
+ * in fact supported by the adapter.  Note that 'no FEC' is always supported.
+ */
+static int ethtool_fec_supported(u32 supported_cap, u32 ethtool_cap)
+{
+	if (ethtool_cap & ETHTOOL_FEC_OFF)
+		return 0;
+
+	if (ethtool_cap &&
+	    !ethtool_fec_caps_to_mcdi(supported_cap, ethtool_cap))
+		return -EINVAL;
+	return 0;
+}
+
 int efx_mcdi_phy_set_fecparam(struct efx_nic *efx, const struct ethtool_fecparam *fec)
 {
 	struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
 	u32 caps;
 	int rc;
 
+	rc = ethtool_fec_supported(phy_cfg->supported_cap, fec->fec);
+	if (rc)
+		return rc;
+
 	/* Work out what efx_mcdi_phy_set_link_ksettings() would produce from
 	 * saved advertising bits
 	 */
@@ -660,7 +682,7 @@ int efx_mcdi_phy_set_fecparam(struct efx_nic *efx, const struct ethtool_fecparam
 	else
 		caps = phy_cfg->forced_cap;
 
-	caps |= ethtool_fec_caps_to_mcdi(fec->fec);
+	caps |= ethtool_fec_caps_to_mcdi(phy_cfg->supported_cap, fec->fec);
 	rc = efx_mcdi_set_link(efx, caps, efx_get_mcdi_phy_flags(efx),
 			       efx->loopback_mode, 0);
 	if (rc)
@@ -699,7 +721,7 @@ int efx_mcdi_port_reconfigure(struct efx_nic *efx)
 		    ethtool_linkset_to_mcdi_cap(efx->link_advertising) :
 		    phy_cfg->forced_cap);
 
-	caps |= ethtool_fec_caps_to_mcdi(efx->fec_config);
+	caps |= ethtool_fec_caps_to_mcdi(phy_cfg->supported_cap, efx->fec_config);
 
 	return efx_mcdi_set_link(efx, caps, efx_get_mcdi_phy_flags(efx),
 				 efx->loopback_mode, 0);
drivers/net/ethernet/sfc/mcdi_port_common.h +1 -1
index 9d214079f699..f37e18adbc37 100644
@@ -41,7 +41,7 @@ u8 mcdi_to_ethtool_media(u32 media);
 void efx_mcdi_phy_decode_link(struct efx_nic *efx,
 			      struct efx_link_state *link_state,
 			      u32 speed, u32 flags, u32 fcntl);
-u32 ethtool_fec_caps_to_mcdi(u32 ethtool_cap);
+u32 ethtool_fec_caps_to_mcdi(u32 supported_cap, u32 ethtool_cap);
 u32 mcdi_fec_caps_to_ethtool(u32 caps, bool is_25g);
 void efx_mcdi_phy_check_fcntl(struct efx_nic *efx, u32 lpa);
 bool efx_mcdi_phy_poll(struct efx_nic *efx);
#8 lore raw

PATCH 5/6 sfc: remove EFX_DRIVER_VERSION

In reply to Edward Cree

Per-module versions for in-tree drivers are deprecated.

---
 drivers/net/ethernet/sfc/efx.c            | 3 +--
 drivers/net/ethernet/sfc/ethtool_common.c | 1 -
 drivers/net/ethernet/sfc/net_driver.h     | 2 --
 3 files changed, 1 insertion(+), 5 deletions(-)
drivers/net/ethernet/sfc/efx.c +1 -2
index aad6710c0afb..58b043f946b4 100644
@@ -1329,7 +1329,7 @@ static int __init efx_init_module(void)
 {
 	int rc;
 
-	printk(KERN_INFO "Solarflare NET driver v" EFX_DRIVER_VERSION "\n");
+	printk(KERN_INFO "Solarflare NET driver\n");
 
 	rc = register_netdevice_notifier(&efx_netdev_notifier);
 	if (rc)
@@ -1391,4 +1391,3 @@ MODULE_AUTHOR("Solarflare Communications and "
 MODULE_DESCRIPTION("Solarflare network driver");
 MODULE_LICENSE("GPL");
 MODULE_DEVICE_TABLE(pci, efx_pci_table);
-MODULE_VERSION(EFX_DRIVER_VERSION);
drivers/net/ethernet/sfc/ethtool_common.c +0 -1
index 622a72eb153a..b18a4bcfccdf 100644
@@ -106,7 +106,6 @@ void efx_ethtool_get_drvinfo(struct net_device *net_dev,
 	struct efx_nic *efx = netdev_priv(net_dev);
 
 	strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
-	strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version));
 	efx_mcdi_print_fwver(efx, info->fw_version,
 			     sizeof(info->fw_version));
 	strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
drivers/net/ethernet/sfc/net_driver.h +0 -2
index c3015f258ba0..3fd0b59107d1 100644
@@ -38,8 +38,6 @@
  *
  **************************************************************************/
 
-#define EFX_DRIVER_VERSION	"4.1"
-
 #ifdef DEBUG
 #define EFX_WARN_ON_ONCE_PARANOID(x) WARN_ON_ONCE(x)
 #define EFX_WARN_ON_PARANOID(x) WARN_ON(x)
#9 lore raw

PATCH 6/6 sfc: simplify DMA mask setting

In reply to Edward Cree

Christoph says[1] that dma_set_mask_and_coherent() is smart enough to
truncate the mask itself if it's too long. So we can get rid of our "lop off one bit and retry" loop in efx_init_io().

[1]: https://www.spinics.net/lists/netdev/msg677266.html

---
 drivers/net/ethernet/sfc/efx_common.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
drivers/net/ethernet/sfc/efx_common.c +1 -11
index 9eda54e27cd4..80a23def96ad 100644
@@ -1086,17 +1086,7 @@ int efx_init_io(struct efx_nic *efx, int bar, dma_addr_t dma_mask,
 
 	pci_set_master(pci_dev);
 
-	/* Set the PCI DMA mask.  Try all possibilities from our
-	 * genuine mask down to 32 bits, because some architectures
-	 * (e.g. x86_64 with iommu_sac_force set) will allow 40 bit
-	 * masks event though they reject 46 bit masks.
-	 */
-	while (dma_mask > 0x7fffffffUL) {
-		rc = dma_set_mask_and_coherent(&pci_dev->dev, dma_mask);
-		if (rc == 0)
-			break;
-		dma_mask >>= 1;
-	}
+	rc = dma_set_mask_and_coherent(&pci_dev->dev, dma_mask);
 	if (rc) {
 		netif_err(efx, probe, efx->net_dev,
 			  "could not find a suitable DMA mask\n");
Reviewed-by on v1 6/6
#10 lore raw

Re: [PATCH net-next 6/6] sfc: simplify DMA mask setting

Quoted 7 lines · Edward Cree

Christoph says[1] that dma_set_mask_and_coherent() is smart enough to
truncate the mask itself if it's too long. So we can get rid of our "lop off one bit and retry" loop in efx_init_io().

[1]: https://www.spinics.net/lists/netdev/msg677266.html

Looks good: