Skip to contentSkip to conversation

ibm: emac: more cleanups

PATCH Superseded Rosen Penev 3 participants 16 messages Oct 15, 2024 – Oct 19, 2024

Subsystems (10)

v7 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v7 cover ibm: emac: more cleanups

Tested on Cisco MX60W.

v2: fixed build errors. Also added extra commits to clean the driver up further.
v3: Added tested message. Removed bad alloc_netdev_dummy commit.
v4: removed modules changes from patchset. Added fix for if MAC not found.
v5: added of_find_matching_node commit.
v6: resend after net-next merge.
v7: removed of_find_matching_node commit. Adjusted mutex_init patch.

Rosen Penev (6):
net: ibm: emac: use netif_receive_skb_list
net: ibm: emac: remove custom init/exit functions
net: ibm: emac: use devm_platform_ioremap_resource
net: ibm: emac: use platform_get_irq
net: ibm: emac: use devm for mutex_init
net: ibm: emac: generate random MAC if not found

 drivers/net/ethernet/ibm/emac/core.c  | 81 ++++++++-------------------
 drivers/net/ethernet/ibm/emac/mal.c   | 10 +---
 drivers/net/ethernet/ibm/emac/mal.h   |  4 --
 drivers/net/ethernet/ibm/emac/rgmii.c | 10 +---
 drivers/net/ethernet/ibm/emac/rgmii.h |  4 --
 drivers/net/ethernet/ibm/emac/tah.c   | 10 +---
 drivers/net/ethernet/ibm/emac/tah.h   |  4 --
 drivers/net/ethernet/ibm/emac/zmii.c  | 10 +---
 drivers/net/ethernet/ibm/emac/zmii.h  |  4 --
 9 files changed, 27 insertions(+), 110 deletions(-)
Signature · 1 line
2.47.0
#1 lore raw

PATCH v7 1/6 net: ibm: emac: use netif_receive_skb_list

Small rx improvement. Would use napi_gro_receive instead but that's a lot more involved than netif_receive_skb_list because of how the function is implemented.

Before:

Quoted 1 line

iperf -c 192.168.1.1

------------------------------------------------------------
Client connecting to 192.168.1.1, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[ 1] local 192.168.1.101 port 51556 connected with 192.168.1.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 1] 0.00-10.04 sec 559 MBytes 467 Mbits/sec

Quoted 1 line

iperf -c 192.168.1.1

------------------------------------------------------------
Client connecting to 192.168.1.1, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[ 1] local 192.168.1.101 port 48228 connected with 192.168.1.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 1] 0.00-10.03 sec 558 MBytes 467 Mbits/sec

Quoted 1 line

iperf -c 192.168.1.1

------------------------------------------------------------
Client connecting to 192.168.1.1, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[ 1] local 192.168.1.101 port 47600 connected with 192.168.1.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 1] 0.00-10.04 sec 557 MBytes 466 Mbits/sec

Quoted 1 line

iperf -c 192.168.1.1

------------------------------------------------------------
Client connecting to 192.168.1.1, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[ 1] local 192.168.1.101 port 37252 connected with 192.168.1.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 1] 0.00-10.05 sec 559 MBytes 467 Mbits/sec

After:

Quoted 1 line

iperf -c 192.168.1.1

------------------------------------------------------------
Client connecting to 192.168.1.1, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[ 1] local 192.168.1.101 port 40786 connected with 192.168.1.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 1] 0.00-10.05 sec 572 MBytes 478 Mbits/sec

Quoted 1 line

iperf -c 192.168.1.1

------------------------------------------------------------
Client connecting to 192.168.1.1, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[ 1] local 192.168.1.101 port 52482 connected with 192.168.1.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 1] 0.00-10.04 sec 571 MBytes 477 Mbits/sec

Quoted 1 line

iperf -c 192.168.1.1

------------------------------------------------------------
Client connecting to 192.168.1.1, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[ 1] local 192.168.1.101 port 48370 connected with 192.168.1.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 1] 0.00-10.04 sec 572 MBytes 478 Mbits/sec

Quoted 1 line

iperf -c 192.168.1.1

------------------------------------------------------------
Client connecting to 192.168.1.1, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[ 1] local 192.168.1.101 port 46086 connected with 192.168.1.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 1] 0.00-10.05 sec 571 MBytes 476 Mbits/sec

Quoted 1 line

iperf -c 192.168.1.1

------------------------------------------------------------
Client connecting to 192.168.1.1, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[ 1] local 192.168.1.101 port 46062 connected with 192.168.1.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 1] 0.00-10.04 sec 572 MBytes 478 Mbits/sec

---
 drivers/net/ethernet/ibm/emac/core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/ibm/emac/core.c +4 -2
index dadd987efb6b..0edcb435e62f 100644
@@ -1727,6 +1727,7 @@ static inline int emac_rx_sg_append(struct emac_instance *dev, int slot)
 /* NAPI poll context */
 static int emac_poll_rx(void *param, int budget)
 {
+	LIST_HEAD(rx_list);
 	struct emac_instance *dev = param;
 	int slot = dev->rx_slot, received = 0;
 
@@ -1783,8 +1784,7 @@ static int emac_poll_rx(void *param, int budget)
 		skb->protocol = eth_type_trans(skb, dev->ndev);
 		emac_rx_csum(dev, skb, ctrl);
 
-		if (unlikely(netif_receive_skb(skb) == NET_RX_DROP))
-			++dev->estats.rx_dropped_stack;
+		list_add_tail(&skb->list, &rx_list);
 	next:
 		++dev->stats.rx_packets;
 	skip:
@@ -1828,6 +1828,8 @@ static int emac_poll_rx(void *param, int budget)
 		goto next;
 	}
 
+	netif_receive_skb_list(&rx_list);
+
 	if (received) {
 		DBG2(dev, "rx %d BDs" NL, received);
 		dev->rx_slot = slot;
Signature · 1 line
2.47.0
#2 lore raw

PATCH 1/1 net: memcpy to ethtool_puts

In reply to Rosen Penev

The latter is the prefered way to copy ethtool strings.

Transformed with the following coccinelle script:

virtual org
virtual report
virtual context
virtual patch

@depends on patch@
expression E1, E2;
identifier I;
position p;
@@

- memcpy@p(E1 + I * ETH_GSTRING_LEN, E2, ETH_GSTRING_LEN);
+ ethtool_puts(&E1, E2);

---
 drivers/net/dsa/b53/b53_common.c              |  3 +-
 drivers/net/dsa/bcm_sf2.c                     |  5 +-
 drivers/net/dsa/bcm_sf2_cfp.c                 | 17 ++--
 drivers/net/dsa/hirschmann/hellcreek.c        |  8 +-
 drivers/net/dsa/microchip/ksz_common.c        |  3 +-
 drivers/net/dsa/mv88e6xxx/chip.c              |  5 +-
 drivers/net/dsa/rzn1_a5psw.c                  |  3 +-
 drivers/net/dsa/sja1105/sja1105_ethtool.c     |  7 +-
 drivers/net/dsa/xrs700x/xrs700x.c             |  6 +-
 drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c  | 22 +++---
 drivers/net/ethernet/apm/xgene-v2/ethtool.c   | 13 +---
 .../ethernet/apm/xgene/xgene_enet_ethtool.c   | 13 +---
 drivers/net/ethernet/atheros/atlx/atl1.c      |  8 +-
 .../ethernet/broadcom/asp2/bcmasp_ethtool.c   |  5 +-
 drivers/net/ethernet/broadcom/bcm63xx_enet.c  | 10 +--
 drivers/net/ethernet/broadcom/bcmsysport.c    | 16 ++--
 drivers/net/ethernet/broadcom/bgmac.c         |  3 +-
 .../net/ethernet/broadcom/genet/bcmgenet.c    |  5 +-
 drivers/net/ethernet/cadence/macb_main.c      | 19 ++---
 drivers/net/ethernet/calxeda/xgmac.c          |  9 +--
 .../ethernet/cavium/liquidio/lio_ethtool.c    | 50 +++++-------
 .../ethernet/cavium/thunder/nicvf_ethtool.c   | 48 ++++--------
 .../net/ethernet/cisco/enic/enic_ethtool.c    | 40 ++++------
 .../net/ethernet/emulex/benet/be_ethtool.c    | 39 ++++------
 drivers/net/ethernet/engleder/tsnep_ethtool.c | 32 ++++----
 .../ethernet/freescale/dpaa/dpaa_ethtool.c    | 38 +++------
 .../ethernet/freescale/dpaa2/dpaa2-ethtool.c  | 15 ++--
 .../net/ethernet/freescale/dpaa2/dpaa2-mac.c  |  7 +-
 .../freescale/dpaa2/dpaa2-switch-ethtool.c    | 12 ++-
 .../ethernet/freescale/enetc/enetc_ethtool.c  | 33 +++-----
 .../net/ethernet/freescale/gianfar_ethtool.c  |  8 +-
 .../net/ethernet/freescale/ucc_geth_ethtool.c | 23 +++---
 .../ethernet/hisilicon/hns/hns_dsaf_main.c    | 66 ++++++----------
 .../hns3/hns3_common/hclge_comm_tqp_stats.c   |  6 +-
 .../ethernet/hisilicon/hns3/hns3_ethtool.c    |  9 +--
 .../hisilicon/hns3/hns3pf/hclge_main.c        | 49 +++++-------
 drivers/net/ethernet/ibm/ibmveth.c            |  4 +-
 drivers/net/ethernet/ibm/ibmvnic.c            | 30 +++----
 .../net/ethernet/intel/e1000/e1000_ethtool.c  | 13 ++--
 drivers/net/ethernet/intel/e1000e/ethtool.c   | 13 ++--
 drivers/net/ethernet/intel/igbvf/ethtool.c    |  9 +--
 drivers/net/ethernet/intel/ixgbevf/ethtool.c  | 35 ++++-----
 .../net/ethernet/marvell/mvpp2/mvpp2_main.c   | 38 +++------
 .../marvell/octeon_ep/octep_ethtool.c         | 34 +++-----
 .../marvell/octeon_ep_vf/octep_vf_ethtool.c   | 37 ++++-----
 .../marvell/octeontx2/nic/otx2_ethtool.c      | 78 +++++++------------
 drivers/net/ethernet/marvell/skge.c           |  3 +-
 drivers/net/ethernet/marvell/sky2.c           |  3 +-
 .../mellanox/mlxsw/spectrum_ethtool.c         | 77 +++++++-----------
 .../ethernet/mellanox/mlxsw/spectrum_ptp.c    |  7 +-
 drivers/net/ethernet/micrel/ksz884x.c         |  5 +-
 .../microchip/lan966x/lan966x_ethtool.c       |  3 +-
 .../ethernet/microsoft/mana/mana_ethtool.c    | 55 +++++--------
 drivers/net/ethernet/mscc/ocelot_stats.c      |  3 +-
 .../ethernet/netronome/nfp/nfp_net_ethtool.c  |  3 +-
 .../oki-semi/pch_gbe/pch_gbe_ethtool.c        |  8 +-
 .../qlogic/netxen/netxen_nic_ethtool.c        | 10 +--
 .../net/ethernet/qlogic/qede/qede_ethtool.c   | 34 ++++----
 .../ethernet/qlogic/qlcnic/qlcnic_ethtool.c   | 49 +++++-------
 .../net/ethernet/qualcomm/emac/emac-ethtool.c |  7 +-
 drivers/net/ethernet/rocker/rocker_main.c     |  7 +-
 .../ethernet/samsung/sxgbe/sxgbe_ethtool.c    |  9 +--
 drivers/net/ethernet/sfc/ethtool_common.c     | 21 +++--
 drivers/net/ethernet/sfc/falcon/ethtool.c     | 14 ++--
 drivers/net/ethernet/sfc/falcon/nic.c         |  7 +-
 drivers/net/ethernet/sfc/nic.c                |  7 +-
 .../net/ethernet/sfc/siena/ethtool_common.c   | 25 +++---
 drivers/net/ethernet/sfc/siena/nic.c          |  7 +-
 .../ethernet/stmicro/stmmac/stmmac_ethtool.c  | 60 ++++++--------
 .../stmicro/stmmac/stmmac_selftests.c         |  7 +-
 drivers/net/ethernet/sun/cassini.c            |  6 +-
 .../ethernet/synopsys/dwc-xlgmac-ethtool.c    |  8 +-
 drivers/net/ethernet/ti/am65-cpsw-ethtool.c   | 20 ++---
 drivers/net/ethernet/ti/cpsw_ethtool.c        | 15 ++--
 drivers/net/ethernet/ti/netcp_ethss.c         |  7 +-
 drivers/net/fjes/fjes_ethtool.c               | 52 +++++--------
 drivers/net/phy/aquantia/aquantia_main.c      |  3 +-
 drivers/net/phy/bcm-phy-lib.c                 |  3 +-
 drivers/net/usb/cdc_ncm.c                     |  8 +-
 drivers/net/xen-netback/interface.c           |  3 +-
 drivers/net/xen-netfront.c                    |  3 +-
 net/dsa/user.c                                | 11 ++-
 82 files changed, 550 insertions(+), 966 deletions(-)
drivers/net/dsa/b53/b53_common.c +1 -2
index c39cb119e760..285785c942b0 100644
@@ -989,8 +989,7 @@ void b53_get_strings(struct dsa_switch *ds, int port, u32 stringset,
 
 	if (stringset == ETH_SS_STATS) {
 		for (i = 0; i < mib_size; i++)
-			strscpy(data + i * ETH_GSTRING_LEN,
-				mibs[i].name, ETH_GSTRING_LEN);
+			ethtool_puts(&data, mibs[i].name);
 	} else if (stringset == ETH_SS_PHY_STATS) {
 		phydev = b53_get_phy_device(ds, port);
 		if (!phydev)
drivers/net/dsa/bcm_sf2.c +1 -4
index 9201f07839ad..2bb1832d21bc 100644
@@ -1180,11 +1180,8 @@ static const struct b53_io_ops bcm_sf2_io_ops = {
 static void bcm_sf2_sw_get_strings(struct dsa_switch *ds, int port,
 				   u32 stringset, uint8_t *data)
 {
-	int cnt = b53_get_sset_count(ds, port, stringset);
-
 	b53_get_strings(ds, port, stringset, data);
-	bcm_sf2_cfp_get_strings(ds, port, stringset,
-				data + cnt * ETH_GSTRING_LEN);
+	bcm_sf2_cfp_get_strings(ds, port, stringset, data);
 }
 
 static void bcm_sf2_sw_get_ethtool_stats(struct dsa_switch *ds, int port,
drivers/net/dsa/bcm_sf2_cfp.c +5 -12
index c88ee3dd4299..8ba23e643a42 100644
@@ -1284,22 +1284,15 @@ void bcm_sf2_cfp_get_strings(struct dsa_switch *ds, int port,
 {
 	struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
 	unsigned int s = ARRAY_SIZE(bcm_sf2_cfp_stats);
-	char buf[ETH_GSTRING_LEN];
-	unsigned int i, j, iter;
+	unsigned int i, j;
 
 	if (stringset != ETH_SS_STATS)
 		return;
 
-	for (i = 1; i < priv->num_cfp_rules; i++) {
-		for (j = 0; j < s; j++) {
-			snprintf(buf, sizeof(buf),
-				 "CFP%03d_%sCntr",
-				 i, bcm_sf2_cfp_stats[j].name);
-			iter = (i - 1) * s + j;
-			strscpy(data + iter * ETH_GSTRING_LEN,
-				buf, ETH_GSTRING_LEN);
-		}
-	}
+	for (i = 1; i < priv->num_cfp_rules; i++)
+		for (j = 0; j < s; j++)
+			ethtool_sprintf(&data, "CFP%03d_%sCntr", i,
+					bcm_sf2_cfp_stats[j].name);
 }
 
 void bcm_sf2_cfp_get_ethtool_stats(struct dsa_switch *ds, int port,
drivers/net/dsa/hirschmann/hellcreek.c +2 -6
index d798f17cf7ea..283ec5a6e23c 100644
@@ -294,12 +294,8 @@ static void hellcreek_get_strings(struct dsa_switch *ds, int port,
 {
 	int i;
 
-	for (i = 0; i < ARRAY_SIZE(hellcreek_counter); ++i) {
-		const struct hellcreek_counter *counter = &hellcreek_counter[i];
-
-		strscpy(data + i * ETH_GSTRING_LEN,
-			counter->name, ETH_GSTRING_LEN);
-	}
+	for (i = 0; i < ARRAY_SIZE(hellcreek_counter); ++i)
+		ethtool_puts(&data, hellcreek_counter[i].name);
 }
 
 static int hellcreek_get_sset_count(struct dsa_switch *ds, int port, int sset)
drivers/net/dsa/microchip/ksz_common.c +1 -2
index 4e8710c7cb7b..408ccb1f012e 100644
@@ -2113,8 +2113,7 @@ static void ksz_get_strings(struct dsa_switch *ds, int port,
 		return;
 
 	for (i = 0; i < dev->info->mib_cnt; i++) {
-		memcpy(buf + i * ETH_GSTRING_LEN,
-		       dev->info->mib_names[i].string, ETH_GSTRING_LEN);
+		ethtool_puts(&buf, dev->info->mib_names[i].string);
 	}
 }
 
drivers/net/dsa/mv88e6xxx/chip.c +1 -4
index 69cf19d3dd5e..bc813d97afa7 100644
@@ -1220,12 +1220,9 @@ static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
 	if (chip->info->ops->stats_get_strings)
 		count = chip->info->ops->stats_get_strings(chip, data);
 
-	if (chip->info->ops->serdes_get_strings) {
-		data += count * ETH_GSTRING_LEN;
+	if (chip->info->ops->serdes_get_strings)
 		count = chip->info->ops->serdes_get_strings(chip, port, data);
-	}
 
-	data += count * ETH_GSTRING_LEN;
 	mv88e6xxx_atu_vtu_get_strings(data);
 
 	mv88e6xxx_reg_unlock(chip);
drivers/net/dsa/rzn1_a5psw.c +1 -2
index 1135a32e4b7e..b3e127f64b08 100644
@@ -803,8 +803,7 @@ static void a5psw_get_strings(struct dsa_switch *ds, int port, u32 stringset,
 		return;
 
 	for (u = 0; u < ARRAY_SIZE(a5psw_stats); u++) {
-		memcpy(data + u * ETH_GSTRING_LEN, a5psw_stats[u].name,
-		       ETH_GSTRING_LEN);
+		ethtool_puts(&data, a5psw_stats[u].name);
 	}
 }
 
drivers/net/dsa/sja1105/sja1105_ethtool.c +2 -5
index decc6c931dc1..2ea64b1d026d 100644
@@ -586,7 +586,6 @@ void sja1105_get_strings(struct dsa_switch *ds, int port,
 {
 	struct sja1105_private *priv = ds->priv;
 	enum sja1105_counter_index max_ctr, i;
-	char *p = data;
 
 	if (stringset != ETH_SS_STATS)
 		return;
@@ -597,10 +596,8 @@ void sja1105_get_strings(struct dsa_switch *ds, int port,
 	else
 		max_ctr = __MAX_SJA1105PQRS_PORT_COUNTER;
 
-	for (i = 0; i < max_ctr; i++) {
-		strscpy(p, sja1105_port_counters[i].name, ETH_GSTRING_LEN);
-		p += ETH_GSTRING_LEN;
-	}
+	for (i = 0; i < max_ctr; i++)
+		ethtool_puts(&data, sja1105_port_counters[i].name);
 }
 
 int sja1105_get_sset_count(struct dsa_switch *ds, int port, int sset)
drivers/net/dsa/xrs700x/xrs700x.c +2 -4
index de3b768f2ff9..4dbcc49a9e52 100644
@@ -91,10 +91,8 @@ static void xrs700x_get_strings(struct dsa_switch *ds, int port,
 	if (stringset != ETH_SS_STATS)
 		return;
 
-	for (i = 0; i < ARRAY_SIZE(xrs700x_mibs); i++) {
-		strscpy(data, xrs700x_mibs[i].name, ETH_GSTRING_LEN);
-		data += ETH_GSTRING_LEN;
-	}
+	for (i = 0; i < ARRAY_SIZE(xrs700x_mibs); i++)
+		ethtool_puts(&data, xrs700x_mibs[i].name);
 }
 
 static int xrs700x_get_sset_count(struct dsa_switch *ds, int port, int sset)
#3 lore raw

Re: [PATCH] net: memcpy to ethtool_puts

Quoted 16 lines · Rosen Penev

The latter is the prefered way to copy ethtool strings.

Transformed with the following coccinelle script:

virtual org
virtual report
virtual context
virtual patch

@depends on patch@
expression E1, E2;
identifier I;
position p;
@@

Quoted 4 lines

- memcpy@p(E1 + I * ETH_GSTRING_LEN, E2, ETH_GSTRING_LEN);
+ ethtool_puts(&E1, E2);

ugh accidentally sent this. It needs more work.

Quoted 255 lines
---
 drivers/net/dsa/b53/b53_common.c              |  3 +-
 drivers/net/dsa/bcm_sf2.c                     |  5 +-
 drivers/net/dsa/bcm_sf2_cfp.c                 | 17 ++--
 drivers/net/dsa/hirschmann/hellcreek.c        |  8 +-
 drivers/net/dsa/microchip/ksz_common.c        |  3 +-
 drivers/net/dsa/mv88e6xxx/chip.c              |  5 +-
 drivers/net/dsa/rzn1_a5psw.c                  |  3 +-
 drivers/net/dsa/sja1105/sja1105_ethtool.c     |  7 +-
 drivers/net/dsa/xrs700x/xrs700x.c             |  6 +-
 drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c  | 22 +++---
 drivers/net/ethernet/apm/xgene-v2/ethtool.c   | 13 +---
 .../ethernet/apm/xgene/xgene_enet_ethtool.c   | 13 +---
 drivers/net/ethernet/atheros/atlx/atl1.c      |  8 +-
 .../ethernet/broadcom/asp2/bcmasp_ethtool.c   |  5 +-
 drivers/net/ethernet/broadcom/bcm63xx_enet.c  | 10 +--
 drivers/net/ethernet/broadcom/bcmsysport.c    | 16 ++--
 drivers/net/ethernet/broadcom/bgmac.c         |  3 +-
 .../net/ethernet/broadcom/genet/bcmgenet.c    |  5 +-
 drivers/net/ethernet/cadence/macb_main.c      | 19 ++---
 drivers/net/ethernet/calxeda/xgmac.c          |  9 +--
 .../ethernet/cavium/liquidio/lio_ethtool.c    | 50 +++++-------
 .../ethernet/cavium/thunder/nicvf_ethtool.c   | 48 ++++--------
 .../net/ethernet/cisco/enic/enic_ethtool.c    | 40 ++++------
 .../net/ethernet/emulex/benet/be_ethtool.c    | 39 ++++------
 drivers/net/ethernet/engleder/tsnep_ethtool.c | 32 ++++----
 .../ethernet/freescale/dpaa/dpaa_ethtool.c    | 38 +++------
 .../ethernet/freescale/dpaa2/dpaa2-ethtool.c  | 15 ++--
 .../net/ethernet/freescale/dpaa2/dpaa2-mac.c  |  7 +-
 .../freescale/dpaa2/dpaa2-switch-ethtool.c    | 12 ++-
 .../ethernet/freescale/enetc/enetc_ethtool.c  | 33 +++-----
 .../net/ethernet/freescale/gianfar_ethtool.c  |  8 +-
 .../net/ethernet/freescale/ucc_geth_ethtool.c | 23 +++---
 .../ethernet/hisilicon/hns/hns_dsaf_main.c    | 66 ++++++----------
 .../hns3/hns3_common/hclge_comm_tqp_stats.c   |  6 +-
 .../ethernet/hisilicon/hns3/hns3_ethtool.c    |  9 +--
 .../hisilicon/hns3/hns3pf/hclge_main.c        | 49 +++++-------
 drivers/net/ethernet/ibm/ibmveth.c            |  4 +-
 drivers/net/ethernet/ibm/ibmvnic.c            | 30 +++----
 .../net/ethernet/intel/e1000/e1000_ethtool.c  | 13 ++--
 drivers/net/ethernet/intel/e1000e/ethtool.c   | 13 ++--
 drivers/net/ethernet/intel/igbvf/ethtool.c    |  9 +--
 drivers/net/ethernet/intel/ixgbevf/ethtool.c  | 35 ++++-----
 .../net/ethernet/marvell/mvpp2/mvpp2_main.c   | 38 +++------
 .../marvell/octeon_ep/octep_ethtool.c         | 34 +++-----
 .../marvell/octeon_ep_vf/octep_vf_ethtool.c   | 37 ++++-----
 .../marvell/octeontx2/nic/otx2_ethtool.c      | 78 +++++++------------
 drivers/net/ethernet/marvell/skge.c           |  3 +-
 drivers/net/ethernet/marvell/sky2.c           |  3 +-
 .../mellanox/mlxsw/spectrum_ethtool.c         | 77 +++++++-----------
 .../ethernet/mellanox/mlxsw/spectrum_ptp.c    |  7 +-
 drivers/net/ethernet/micrel/ksz884x.c         |  5 +-
 .../microchip/lan966x/lan966x_ethtool.c       |  3 +-
 .../ethernet/microsoft/mana/mana_ethtool.c    | 55 +++++--------
 drivers/net/ethernet/mscc/ocelot_stats.c      |  3 +-
 .../ethernet/netronome/nfp/nfp_net_ethtool.c  |  3 +-
 .../oki-semi/pch_gbe/pch_gbe_ethtool.c        |  8 +-
 .../qlogic/netxen/netxen_nic_ethtool.c        | 10 +--
 .../net/ethernet/qlogic/qede/qede_ethtool.c   | 34 ++++----
 .../ethernet/qlogic/qlcnic/qlcnic_ethtool.c   | 49 +++++-------
 .../net/ethernet/qualcomm/emac/emac-ethtool.c |  7 +-
 drivers/net/ethernet/rocker/rocker_main.c     |  7 +-
 .../ethernet/samsung/sxgbe/sxgbe_ethtool.c    |  9 +--
 drivers/net/ethernet/sfc/ethtool_common.c     | 21 +++--
 drivers/net/ethernet/sfc/falcon/ethtool.c     | 14 ++--
 drivers/net/ethernet/sfc/falcon/nic.c         |  7 +-
 drivers/net/ethernet/sfc/nic.c                |  7 +-
 .../net/ethernet/sfc/siena/ethtool_common.c   | 25 +++---
 drivers/net/ethernet/sfc/siena/nic.c          |  7 +-
 .../ethernet/stmicro/stmmac/stmmac_ethtool.c  | 60 ++++++--------
 .../stmicro/stmmac/stmmac_selftests.c         |  7 +-
 drivers/net/ethernet/sun/cassini.c            |  6 +-
 .../ethernet/synopsys/dwc-xlgmac-ethtool.c    |  8 +-
 drivers/net/ethernet/ti/am65-cpsw-ethtool.c   | 20 ++---
 drivers/net/ethernet/ti/cpsw_ethtool.c        | 15 ++--
 drivers/net/ethernet/ti/netcp_ethss.c         |  7 +-
 drivers/net/fjes/fjes_ethtool.c               | 52 +++++--------
 drivers/net/phy/aquantia/aquantia_main.c      |  3 +-
 drivers/net/phy/bcm-phy-lib.c                 |  3 +-
 drivers/net/usb/cdc_ncm.c                     |  8 +-
 drivers/net/xen-netback/interface.c           |  3 +-
 drivers/net/xen-netfront.c                    |  3 +-
 net/dsa/user.c                                | 11 ++-
 82 files changed, 550 insertions(+), 966 deletions(-)
drivers/net/dsa/b53/b53_common.c +1 -2
index c39cb119e760..285785c942b0 100644
@@ -989,8 +989,7 @@ void b53_get_strings(struct dsa_switch *ds, int port, u32 stringset,
 
        if (stringset == ETH_SS_STATS) {
                for (i = 0; i < mib_size; i++)
-                       strscpy(data + i * ETH_GSTRING_LEN,
-                               mibs[i].name, ETH_GSTRING_LEN);
+                       ethtool_puts(&data, mibs[i].name);
        } else if (stringset == ETH_SS_PHY_STATS) {
                phydev = b53_get_phy_device(ds, port);
                if (!phydev)
drivers/net/dsa/bcm_sf2.c +1 -4
index 9201f07839ad..2bb1832d21bc 100644
@@ -1180,11 +1180,8 @@ static const struct b53_io_ops bcm_sf2_io_ops = {
 static void bcm_sf2_sw_get_strings(struct dsa_switch *ds, int port,
                                   u32 stringset, uint8_t *data)
 {
-       int cnt = b53_get_sset_count(ds, port, stringset);
-
        b53_get_strings(ds, port, stringset, data);
-       bcm_sf2_cfp_get_strings(ds, port, stringset,
-                               data + cnt * ETH_GSTRING_LEN);
+       bcm_sf2_cfp_get_strings(ds, port, stringset, data);
 }
 
 static void bcm_sf2_sw_get_ethtool_stats(struct dsa_switch *ds, int port,
drivers/net/dsa/bcm_sf2_cfp.c +5 -12
index c88ee3dd4299..8ba23e643a42 100644
@@ -1284,22 +1284,15 @@ void bcm_sf2_cfp_get_strings(struct dsa_switch *ds, int port,
 {
        struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
        unsigned int s = ARRAY_SIZE(bcm_sf2_cfp_stats);
-       char buf[ETH_GSTRING_LEN];
-       unsigned int i, j, iter;
+       unsigned int i, j;
 
        if (stringset != ETH_SS_STATS)
                return;
 
-       for (i = 1; i < priv->num_cfp_rules; i++) {
-               for (j = 0; j < s; j++) {
-                       snprintf(buf, sizeof(buf),
-                                "CFP%03d_%sCntr",
-                                i, bcm_sf2_cfp_stats[j].name);
-                       iter = (i - 1) * s + j;
-                       strscpy(data + iter * ETH_GSTRING_LEN,
-                               buf, ETH_GSTRING_LEN);
-               }
-       }
+       for (i = 1; i < priv->num_cfp_rules; i++)
+               for (j = 0; j < s; j++)
+                       ethtool_sprintf(&data, "CFP%03d_%sCntr", i,
+                                       bcm_sf2_cfp_stats[j].name);
 }
 
 void bcm_sf2_cfp_get_ethtool_stats(struct dsa_switch *ds, int port,
drivers/net/dsa/hirschmann/hellcreek.c +2 -6
index d798f17cf7ea..283ec5a6e23c 100644
@@ -294,12 +294,8 @@ static void hellcreek_get_strings(struct dsa_switch *ds, int port,
 {
        int i;
 
-       for (i = 0; i < ARRAY_SIZE(hellcreek_counter); ++i) {
-               const struct hellcreek_counter *counter = &hellcreek_counter[i];
-
-               strscpy(data + i * ETH_GSTRING_LEN,
-                       counter->name, ETH_GSTRING_LEN);
-       }
+       for (i = 0; i < ARRAY_SIZE(hellcreek_counter); ++i)
+               ethtool_puts(&data, hellcreek_counter[i].name);
 }
 
 static int hellcreek_get_sset_count(struct dsa_switch *ds, int port, int sset)
drivers/net/dsa/microchip/ksz_common.c +1 -2
index 4e8710c7cb7b..408ccb1f012e 100644
@@ -2113,8 +2113,7 @@ static void ksz_get_strings(struct dsa_switch *ds, int port,
                return;
 
        for (i = 0; i < dev->info->mib_cnt; i++) {
-               memcpy(buf + i * ETH_GSTRING_LEN,
-                      dev->info->mib_names[i].string, ETH_GSTRING_LEN);
+               ethtool_puts(&buf, dev->info->mib_names[i].string);
        }
 }
 
drivers/net/dsa/mv88e6xxx/chip.c +1 -4
index 69cf19d3dd5e..bc813d97afa7 100644
@@ -1220,12 +1220,9 @@ static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
        if (chip->info->ops->stats_get_strings)
                count = chip->info->ops->stats_get_strings(chip, data);
 
-       if (chip->info->ops->serdes_get_strings) {
-               data += count * ETH_GSTRING_LEN;
+       if (chip->info->ops->serdes_get_strings)
                count = chip->info->ops->serdes_get_strings(chip, port, data);
-       }
 
-       data += count * ETH_GSTRING_LEN;
        mv88e6xxx_atu_vtu_get_strings(data);
 
        mv88e6xxx_reg_unlock(chip);
drivers/net/dsa/rzn1_a5psw.c +1 -2
index 1135a32e4b7e..b3e127f64b08 100644
@@ -803,8 +803,7 @@ static void a5psw_get_strings(struct dsa_switch *ds, int port, u32 stringset,
                return;
 
        for (u = 0; u < ARRAY_SIZE(a5psw_stats); u++) {
-               memcpy(data + u * ETH_GSTRING_LEN, a5psw_stats[u].name,
-                      ETH_GSTRING_LEN);
+               ethtool_puts(&data, a5psw_stats[u].name);
        }
 }
 
drivers/net/dsa/sja1105/sja1105_ethtool.c +2 -5
index decc6c931dc1..2ea64b1d026d 100644
@@ -586,7 +586,6 @@ void sja1105_get_strings(struct dsa_switch *ds, int port,
 {
        struct sja1105_private *priv = ds->priv;
        enum sja1105_counter_index max_ctr, i;
-       char *p = data;
 
        if (stringset != ETH_SS_STATS)
                return;
@@ -597,10 +596,8 @@ void sja1105_get_strings(struct dsa_switch *ds, int port,
        else
                max_ctr = __MAX_SJA1105PQRS_PORT_COUNTER;
 
-       for (i = 0; i < max_ctr; i++) {
-               strscpy(p, sja1105_port_counters[i].name, ETH_GSTRING_LEN);
-               p += ETH_GSTRING_LEN;
-       }
+       for (i = 0; i < max_ctr; i++)
+               ethtool_puts(&data, sja1105_port_counters[i].name);
 }
 
 int sja1105_get_sset_count(struct dsa_switch *ds, int port, int sset)
drivers/net/dsa/xrs700x/xrs700x.c +2 -4
index de3b768f2ff9..4dbcc49a9e52 100644
@@ -91,10 +91,8 @@ static void xrs700x_get_strings(struct dsa_switch *ds, int port,
        if (stringset != ETH_SS_STATS)
                return;
 
-       for (i = 0; i < ARRAY_SIZE(xrs700x_mibs); i++) {
-               strscpy(data, xrs700x_mibs[i].name, ETH_GSTRING_LEN);
-               data += ETH_GSTRING_LEN;
-       }
+       for (i = 0; i < ARRAY_SIZE(xrs700x_mibs); i++)
+               ethtool_puts(&data, xrs700x_mibs[i].name);
 }
 
 static int xrs700x_get_sset_count(struct dsa_switch *ds, int port, int sset)
#4 lore raw

Re: [PATCH] net: memcpy to ethtool_puts

In reply to Rosen Penev
kernel test robot noticed the following build warnings:

Hi Rosen,

kernel test robot noticed the following build warnings:

[auto build test WARNING on net/main]
[also build test WARNING on net-next/main linus/master horms-ipvs/master v6.12-rc3 next-20241016] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Rosen-Penev/net-memcpy-to-ethtool_puts/20241016-040502
base:   net/main
patch link:    https://lore.kernel.org/r/20241015200222.12452-3-rosenp%40gmail.com
patch subject: [PATCH] net: memcpy to ethtool_puts
config: arc-allyesconfig (https://download.01.org/0day-ci/archive/20241016/[email protected]/config)
compiler: arceb-elf-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241016/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

drivers/net/dsa/mv88e6xxx/chip.c: In function 'mv88e6xxx_get_strings':

>> drivers/net/dsa/mv88e6xxx/chip.c:1215:13: warning: variable 'count' set but not used [-Wunused-but-set-variable]
    1215 |         int count = 0;
         |             ^~~~~
   during RTL pass: mach
   drivers/net/dsa/mv88e6xxx/chip.c: In function 'mv88e6xxx_read':
   drivers/net/dsa/mv88e6xxx/chip.c:68:1: internal compiler error: in arc_ifcvt, at config/arc/arc.cc:9703
      68 | }
         | ^

0x5b78c1 arc_ifcvt
/tmp/build-crosstools-gcc-13.2.0-binutils-2.41/gcc/gcc-13.2.0/gcc/config/arc/arc.cc:9703
0xe431b4 arc_reorg
/tmp/build-crosstools-gcc-13.2.0-binutils-2.41/gcc/gcc-13.2.0/gcc/config/arc/arc.cc:8552
0xaed299 execute
/tmp/build-crosstools-gcc-13.2.0-binutils-2.41/gcc/gcc-13.2.0/gcc/reorg.cc:3927
Please submit a full bug report, with preprocessed source (by using -freport-bug). Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for GET_FREE_REGION Depends on [n]: SPARSEMEM [=n]
Selected by [y]:
- RESOURCE_KUNIT_TEST [=y] && RUNTIME_TESTING_MENU [=y] && KUNIT [=y]

vim +/count +1215 drivers/net/dsa/mv88e6xxx/chip.c

65f60e4582bd32 drivers/net/dsa/mv88e6xxx/chip.c Andrew Lunn      2018-03-28  1210  
dfafe449bbc91d drivers/net/dsa/mv88e6xxx/chip.c Andrew Lunn      2016-11-21  1211  static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
89f09048348936 drivers/net/dsa/mv88e6xxx/chip.c Florian Fainelli 2018-04-25  1212  				  u32 stringset, uint8_t *data)
f5e2ed022dff60 drivers/net/dsa/mv88e6xxx.c      Andrew Lunn      2015-12-23  1213  {
04bed1434df256 drivers/net/dsa/mv88e6xxx/chip.c Vivien Didelot   2016-08-31  1214  	struct mv88e6xxx_chip *chip = ds->priv;
436fe17d273bed drivers/net/dsa/mv88e6xxx/chip.c Andrew Lunn      2018-03-01 @1215  	int count = 0;
dfafe449bbc91d drivers/net/dsa/mv88e6xxx/chip.c Andrew Lunn      2016-11-21  1216  
89f09048348936 drivers/net/dsa/mv88e6xxx/chip.c Florian Fainelli 2018-04-25  1217  	if (stringset != ETH_SS_STATS)
89f09048348936 drivers/net/dsa/mv88e6xxx/chip.c Florian Fainelli 2018-04-25  1218  		return;
89f09048348936 drivers/net/dsa/mv88e6xxx/chip.c Florian Fainelli 2018-04-25  1219  
c9acece064e3f0 drivers/net/dsa/mv88e6xxx/chip.c Rasmus Villemoes 2019-06-20  1220  	mv88e6xxx_reg_lock(chip);
c6c8cd5e3ce494 drivers/net/dsa/mv88e6xxx/chip.c Andrew Lunn      2018-03-01  1221  
dfafe449bbc91d drivers/net/dsa/mv88e6xxx/chip.c Andrew Lunn      2016-11-21  1222  	if (chip->info->ops->stats_get_strings)
436fe17d273bed drivers/net/dsa/mv88e6xxx/chip.c Andrew Lunn      2018-03-01  1223  		count = chip->info->ops->stats_get_strings(chip, data);
436fe17d273bed drivers/net/dsa/mv88e6xxx/chip.c Andrew Lunn      2018-03-01  1224  
577149384b2aab drivers/net/dsa/mv88e6xxx/chip.c Rosen Penev      2024-10-15  1225  	if (chip->info->ops->serdes_get_strings)
65f60e4582bd32 drivers/net/dsa/mv88e6xxx/chip.c Andrew Lunn      2018-03-28  1226  		count = chip->info->ops->serdes_get_strings(chip, port, data);
c6c8cd5e3ce494 drivers/net/dsa/mv88e6xxx/chip.c Andrew Lunn      2018-03-01  1227  
65f60e4582bd32 drivers/net/dsa/mv88e6xxx/chip.c Andrew Lunn      2018-03-28  1228  	mv88e6xxx_atu_vtu_get_strings(data);
65f60e4582bd32 drivers/net/dsa/mv88e6xxx/chip.c Andrew Lunn      2018-03-28  1229  
c9acece064e3f0 drivers/net/dsa/mv88e6xxx/chip.c Rasmus Villemoes 2019-06-20  1230  	mv88e6xxx_reg_unlock(chip);
dfafe449bbc91d drivers/net/dsa/mv88e6xxx/chip.c Andrew Lunn      2016-11-21  1231  }
dfafe449bbc91d drivers/net/dsa/mv88e6xxx/chip.c Andrew Lunn      2016-11-21  1232  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#5 lore raw

PATCH v7 2/6 net: ibm: emac: remove custom init/exit functions

In reply to Rosen Penev

commit c092d0be38f4 ("net: ibm: emac: remove all waiting code") introduced EPROBE_DEFER support. Because of that, we can defer initialization until all modules are ready instead of handling it explicitly with custom init/exit functions.

As a consequence of removing explicit module initialization and deferring probe until everything is ready, there's no need for custom init and exit functions.

There are now module_init and module_exit calls but no real change in functionality as these init and exit functions are no longer directly called by core.

---
 drivers/net/ethernet/ibm/emac/core.c  | 39 +--------------------------
 drivers/net/ethernet/ibm/emac/mal.c   | 10 +------
 drivers/net/ethernet/ibm/emac/mal.h   |  4 ---
 drivers/net/ethernet/ibm/emac/rgmii.c | 10 +------
 drivers/net/ethernet/ibm/emac/rgmii.h |  4 ---
 drivers/net/ethernet/ibm/emac/tah.c   | 10 +------
 drivers/net/ethernet/ibm/emac/tah.h   |  4 ---
 drivers/net/ethernet/ibm/emac/zmii.c  | 10 +------
 drivers/net/ethernet/ibm/emac/zmii.h  |  4 ---
 9 files changed, 5 insertions(+), 90 deletions(-)
drivers/net/ethernet/ibm/emac/core.c +1 -38
index 0edcb435e62f..644abd37cfb4 100644
@@ -3283,42 +3283,10 @@ static void __init emac_make_bootlist(void)
 
 static int __init emac_init(void)
 {
-	int rc;
-
-	printk(KERN_INFO DRV_DESC ", version " DRV_VERSION "\n");
-
 	/* Build EMAC boot list */
 	emac_make_bootlist();
 
-	/* Init submodules */
-	rc = mal_init();
-	if (rc)
-		goto err;
-	rc = zmii_init();
-	if (rc)
-		goto err_mal;
-	rc = rgmii_init();
-	if (rc)
-		goto err_zmii;
-	rc = tah_init();
-	if (rc)
-		goto err_rgmii;
-	rc = platform_driver_register(&emac_driver);
-	if (rc)
-		goto err_tah;
-
-	return 0;
-
- err_tah:
-	tah_exit();
- err_rgmii:
-	rgmii_exit();
- err_zmii:
-	zmii_exit();
- err_mal:
-	mal_exit();
- err:
-	return rc;
+	return platform_driver_register(&emac_driver);
 }
 
 static void __exit emac_exit(void)
@@ -3327,11 +3295,6 @@ static void __exit emac_exit(void)
 
 	platform_driver_unregister(&emac_driver);
 
-	tah_exit();
-	rgmii_exit();
-	zmii_exit();
-	mal_exit();
-
 	/* Destroy EMAC boot list */
 	for (i = 0; i < EMAC_BOOT_LIST_SIZE; i++)
 		of_node_put(emac_boot_list[i]);
drivers/net/ethernet/ibm/emac/mal.c +1 -9
index c634534710d9..c66adb7f4e7a 100644
@@ -781,12 +781,4 @@ static struct platform_driver mal_of_driver = {
 	.remove = mal_remove,
 };
 
-int __init mal_init(void)
-{
-	return platform_driver_register(&mal_of_driver);
-}
-
-void mal_exit(void)
-{
-	platform_driver_unregister(&mal_of_driver);
-}
+module_platform_driver(mal_of_driver);
drivers/net/ethernet/ibm/emac/mal.h +0 -4
index e0ddc41186a2..2963b36be6f5 100644
@@ -252,10 +252,6 @@ static inline int mal_has_feature(struct mal_instance *dev,
 		(MAL_FTRS_POSSIBLE & dev->features & feature);
 }
 
-/* Register MAL devices */
-int mal_init(void);
-void mal_exit(void);
-
 int mal_register_commac(struct mal_instance *mal,
 			struct mal_commac *commac);
 void mal_unregister_commac(struct mal_instance *mal,
drivers/net/ethernet/ibm/emac/rgmii.c +1 -9
index 317c22d09172..f275ebeb7158 100644
@@ -303,12 +303,4 @@ static struct platform_driver rgmii_driver = {
 	.remove = rgmii_remove,
 };
 
-int __init rgmii_init(void)
-{
-	return platform_driver_register(&rgmii_driver);
-}
-
-void rgmii_exit(void)
-{
-	platform_driver_unregister(&rgmii_driver);
-}
+module_platform_driver(rgmii_driver);
drivers/net/ethernet/ibm/emac/rgmii.h +0 -4
index 8e4e36eed172..170bcd35039b 100644
@@ -52,8 +52,6 @@ struct rgmii_instance {
 
 #ifdef CONFIG_IBM_EMAC_RGMII
 
-int rgmii_init(void);
-void rgmii_exit(void);
 int rgmii_attach(struct platform_device *ofdev, int input, int mode);
 void rgmii_detach(struct platform_device *ofdev, int input);
 void rgmii_get_mdio(struct platform_device *ofdev, int input);
@@ -64,8 +62,6 @@ void *rgmii_dump_regs(struct platform_device *ofdev, void *buf);
 
 #else
 
-# define rgmii_init()		0
-# define rgmii_exit()		do { } while(0)
 # define rgmii_attach(x,y,z)	(-ENXIO)
 # define rgmii_detach(x,y)	do { } while(0)
 # define rgmii_get_mdio(o,i)	do { } while (0)
drivers/net/ethernet/ibm/emac/tah.c +1 -9
index c605c8ff933e..77e881efa598 100644
@@ -161,12 +161,4 @@ static struct platform_driver tah_driver = {
 	.remove = tah_remove,
 };
 
-int __init tah_init(void)
-{
-	return platform_driver_register(&tah_driver);
-}
-
-void tah_exit(void)
-{
-	platform_driver_unregister(&tah_driver);
-}
+module_platform_driver(tah_driver);
drivers/net/ethernet/ibm/emac/tah.h +0 -4
index 86c2b6b9d460..60c16cf7a41a 100644
@@ -68,8 +68,6 @@ struct tah_instance {
 
 #ifdef CONFIG_IBM_EMAC_TAH
 
-int tah_init(void);
-void tah_exit(void);
 int tah_attach(struct platform_device *ofdev, int channel);
 void tah_detach(struct platform_device *ofdev, int channel);
 void tah_reset(struct platform_device *ofdev);
@@ -78,8 +76,6 @@ void *tah_dump_regs(struct platform_device *ofdev, void *buf);
 
 #else
 
-# define tah_init()		0
-# define tah_exit()		do { } while(0)
 # define tah_attach(x,y)	(-ENXIO)
 # define tah_detach(x,y)	do { } while(0)
 # define tah_reset(x)		do { } while(0)
drivers/net/ethernet/ibm/emac/zmii.c +1 -9
index 03bab3f95fe4..211e843fdc7e 100644
@@ -309,12 +309,4 @@ static struct platform_driver zmii_driver = {
 	.remove = zmii_remove,
 };
 
-int __init zmii_init(void)
-{
-	return platform_driver_register(&zmii_driver);
-}
-
-void zmii_exit(void)
-{
-	platform_driver_unregister(&zmii_driver);
-}
+module_platform_driver(zmii_driver);
drivers/net/ethernet/ibm/emac/zmii.h +0 -4
index 65daedc78594..213de06d8ea2 100644
@@ -48,8 +48,6 @@ struct zmii_instance {
 
 #ifdef CONFIG_IBM_EMAC_ZMII
 
-int zmii_init(void);
-void zmii_exit(void);
 int zmii_attach(struct platform_device *ofdev, int input,
 		phy_interface_t *mode);
 void zmii_detach(struct platform_device *ofdev, int input);
@@ -60,8 +58,6 @@ int zmii_get_regs_len(struct platform_device *ocpdev);
 void *zmii_dump_regs(struct platform_device *ofdev, void *buf);
 
 #else
-# define zmii_init()		0
-# define zmii_exit()		do { } while(0)
 # define zmii_attach(x,y,z)	(-ENXIO)
 # define zmii_detach(x,y)	do { } while(0)
 # define zmii_get_mdio(x,y)	do { } while(0)
Signature · 1 line
2.47.0
reviewer Reviewed-by on v7 2/6
#6 lore raw

Re: [PATCHv7 net-next 2/6] net: ibm: emac: remove custom init/exit functions

Quoted 9 lines · Rosen Penev

commit c092d0be38f4 ("net: ibm: emac: remove all waiting code") introduced EPROBE_DEFER support. Because of that, we can defer initialization until all modules are ready instead of handling it explicitly with custom init/exit functions.

As a consequence of removing explicit module initialization and deferring probe until everything is ready, there's no need for custom init and exit functions.

Quoted 5 lines

There are now module_init and module_exit calls but no real change in functionality as these init and exit functions are no longer directly called by core.

#7 lore raw

Re: [PATCHv7 net-next 2/6] net: ibm: emac: remove custom init/exit functions

In reply to Rosen Penev
kernel test robot noticed the following build errors:

Hi Rosen,

kernel test robot noticed the following build errors:

[auto build test ERROR on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Rosen-Penev/net-ibm-emac-use-netif_receive_skb_list/20241016-040516
base:   net-next/main
patch link:    https://lore.kernel.org/r/20241015200222.12452-4-rosenp%40gmail.com
patch subject: [PATCHv7 net-next 2/6] net: ibm: emac: remove custom init/exit functions
config: powerpc-allmodconfig (https://download.01.org/0day-ci/archive/20241019/[email protected]/config)
compiler: powerpc64-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241019/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

powerpc64-linux-ld: drivers/net/ethernet/ibm/emac/core.o: in function `emac_init':

>> core.c:(.init.text+0x8): multiple definition of `init_module'; drivers/net/ethernet/ibm/emac/mal.o:mal.c:(.init.text+0x8): first defined here

powerpc64-linux-ld: drivers/net/ethernet/ibm/emac/core.o: in function `emac_exit':
core.c:(.exit.text+0x8): multiple definition of `cleanup_module'; drivers/net/ethernet/ibm/emac/mal.o:mal.c:(.exit.text+0x8): first defined here
powerpc64-linux-ld: drivers/net/ethernet/ibm/emac/zmii.o: in function `zmii_driver_init':
zmii.c:(.init.text+0x8): multiple definition of `init_module'; drivers/net/ethernet/ibm/emac/mal.o:mal.c:(.init.text+0x8): first defined here
powerpc64-linux-ld: drivers/net/ethernet/ibm/emac/zmii.o: in function `zmii_driver_exit':
zmii.c:(.exit.text+0x8): multiple definition of `cleanup_module'; drivers/net/ethernet/ibm/emac/mal.o:mal.c:(.exit.text+0x8): first defined here
powerpc64-linux-ld: drivers/net/ethernet/ibm/emac/rgmii.o: in function `rgmii_driver_init':
rgmii.c:(.init.text+0x8): multiple definition of `init_module'; drivers/net/ethernet/ibm/emac/mal.o:mal.c:(.init.text+0x8): first defined here
powerpc64-linux-ld: drivers/net/ethernet/ibm/emac/rgmii.o: in function `rgmii_driver_exit':
rgmii.c:(.exit.text+0x8): multiple definition of `cleanup_module'; drivers/net/ethernet/ibm/emac/mal.o:mal.c:(.exit.text+0x8): first defined here
powerpc64-linux-ld: drivers/net/ethernet/ibm/emac/tah.o: in function `tah_driver_init':
tah.c:(.init.text+0x8): multiple definition of `init_module'; drivers/net/ethernet/ibm/emac/mal.o:mal.c:(.init.text+0x8): first defined here
powerpc64-linux-ld: drivers/net/ethernet/ibm/emac/tah.o: in function `tah_driver_exit':
tah.c:(.exit.text+0x8): multiple definition of `cleanup_module'; drivers/net/ethernet/ibm/emac/mal.o:mal.c:(.exit.text+0x8): first defined here

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#8 lore raw

PATCH v7 3/6 net: ibm: emac: use devm_platform_ioremap_resource

In reply to Rosen Penev

No need to have a struct resource. Gets rid of the TODO.

---
 drivers/net/ethernet/ibm/emac/core.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/net/ethernet/ibm/emac/core.c +3 -5
index 644abd37cfb4..438b08e8e956 100644
@@ -3050,12 +3050,10 @@ static int emac_probe(struct platform_device *ofdev)
 
 	ndev->irq = dev->emac_irq;
 
-	/* Map EMAC regs */
-	// TODO : platform_get_resource() and devm_ioremap_resource()
-	dev->emacp = devm_of_iomap(&ofdev->dev, np, 0, NULL);
-	if (!dev->emacp) {
+	dev->emacp = devm_platform_ioremap_resource(ofdev, 0);
+	if (IS_ERR(dev->emacp)) {
 		dev_err(&ofdev->dev, "can't map device registers");
-		err = -ENOMEM;
+		err = PTR_ERR(dev->emacp);
 		goto err_gone;
 	}
 
Signature · 1 line
2.47.0
#9 lore raw

PATCH v7 4/6 net: ibm: emac: use platform_get_irq

In reply to Rosen Penev

No need for irq_of_parse_and_map since we have platform_device.

---
 drivers/net/ethernet/ibm/emac/core.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/net/ethernet/ibm/emac/core.c +1 -8
index 438b08e8e956..f8478f0026af 100644
@@ -3031,15 +3031,8 @@ static int emac_probe(struct platform_device *ofdev)
 	if (err)
 		goto err_gone;
 
-	/* Get interrupts. EMAC irq is mandatory */
-	dev->emac_irq = irq_of_parse_and_map(np, 0);
-	if (!dev->emac_irq) {
-		printk(KERN_ERR "%pOF: Can't map main interrupt\n", np);
-		err = -ENODEV;
-		goto err_gone;
-	}
-
 	/* Setup error IRQ handler */
+	dev->emac_irq = platform_get_irq(ofdev, 0);
 	err = devm_request_irq(&ofdev->dev, dev->emac_irq, emac_irq, 0, "EMAC",
 			       dev);
 	if (err) {
Signature · 1 line
2.47.0
#10 lore raw

PATCH v7 5/6 net: ibm: emac: use devm for mutex_init

In reply to Rosen Penev

It seems since inception that mutex_destroy was never called for these in _remove. Instead of handling this manually, just use devm for simplicity.

---
 drivers/net/ethernet/ibm/emac/core.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/ethernet/ibm/emac/core.c +8 -2
index f8478f0026af..3bea10624291 100644
@@ -3021,8 +3021,14 @@ static int emac_probe(struct platform_device *ofdev)
 	SET_NETDEV_DEV(ndev, &ofdev->dev);
 
 	/* Initialize some embedded data structures */
-	mutex_init(&dev->mdio_lock);
-	mutex_init(&dev->link_lock);
+	err = devm_mutex_init(&ofdev->dev, &dev->mdio_lock);
+	if (err)
+		goto err_gone;
+
+	err = devm_mutex_init(&ofdev->dev, &dev->link_lock);
+	if (err)
+		goto err_gone;
+
 	spin_lock_init(&dev->lock);
 	INIT_WORK(&dev->reset_work, emac_reset_work);
 
Signature · 1 line
2.47.0
#12 lore raw

PATCH v7 6/6 net: ibm: emac: generate random MAC if not found

In reply to Rosen Penev

On this Cisco MX60W, u-boot sets the local-mac-address property. Unfortunately by default, the MAC is wrong and is actually located on a UBI partition. Which means nvmem needs to be used to grab it.

In the case where that fails, EMAC fails to initialize instead of generating a random MAC as many other drivers do.

Match behavior with other drivers to have a working ethernet interface.

---
 drivers/net/ethernet/ibm/emac/core.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/ethernet/ibm/emac/core.c +6 -3
index 3bea10624291..fb9adcc3a16d 100644
@@ -2937,9 +2937,12 @@ static int emac_init_config(struct emac_instance *dev)
 
 	/* Read MAC-address */
 	err = of_get_ethdev_address(np, dev->ndev);
-	if (err)
-		return dev_err_probe(&dev->ofdev->dev, err,
-				     "Can't get valid [local-]mac-address from OF !\n");
+	if (err == -EPROBE_DEFER)
+		return err;
+	if (err) {
+		dev_warn(&dev->ofdev->dev, "Can't get valid mac-address. Generating random.");
+		eth_hw_addr_random(dev->ndev);
+	}
 
 	/* IAHT and GAHT filter parameterization */
 	if (emac_has_feature(dev, EMAC_FTR_EMAC4SYNC)) {
Signature · 1 line
2.47.0
reviewer Reviewed-by on v7 6/6
#13 lore raw

Re: [PATCHv7 net-next 6/6] net: ibm: emac: generate random MAC if not found

Quoted 10 lines · Rosen Penev

On this Cisco MX60W, u-boot sets the local-mac-address property. Unfortunately by default, the MAC is wrong and is actually located on a UBI partition. Which means nvmem needs to be used to grab it.

In the case where that fails, EMAC fails to initialize instead of generating a random MAC as many other drivers do.

Match behavior with other drivers to have a working ethernet interface.

#14 lore raw
In reply to Rosen Penev
Quoted 12 lines · Rosen Penev

Tested on Cisco MX60W.

v2: fixed build errors. Also added extra commits to clean the driver up further.
v3: Added tested message. Removed bad alloc_netdev_dummy commit.
v4: removed modules changes from patchset. Added fix for if MAC not found.
v5: added of_find_matching_node commit.
v6: resend after net-next merge.
v7: removed of_find_matching_node commit. Adjusted mutex_init patch.

Quoted 7 lines

Rosen Penev (6):
net: ibm: emac: use netif_receive_skb_list
net: ibm: emac: remove custom init/exit functions
net: ibm: emac: use devm_platform_ioremap_resource
net: ibm: emac: use platform_get_irq
net: ibm: emac: use devm for mutex_init
net: ibm: emac: generate random MAC if not found

why is this set to changes requested?

Quoted 15 lines
 drivers/net/ethernet/ibm/emac/core.c  | 81 ++++++++-------------------
 drivers/net/ethernet/ibm/emac/mal.c   | 10 +---
 drivers/net/ethernet/ibm/emac/mal.h   |  4 --
 drivers/net/ethernet/ibm/emac/rgmii.c | 10 +---
 drivers/net/ethernet/ibm/emac/rgmii.h |  4 --
 drivers/net/ethernet/ibm/emac/tah.c   | 10 +---
 drivers/net/ethernet/ibm/emac/tah.h   |  4 --
 drivers/net/ethernet/ibm/emac/zmii.c  | 10 +---
 drivers/net/ethernet/ibm/emac/zmii.h  |  4 --
 9 files changed, 27 insertions(+), 110 deletions(-)

--
2.47.0

reviewer
#15 lore raw
Quoted 13 lines · Rosen Penev
Quoted 12 lines · Rosen Penev

Tested on Cisco MX60W.

v2: fixed build errors. Also added extra commits to clean the driver up further.
v3: Added tested message. Removed bad alloc_netdev_dummy commit.
v4: removed modules changes from patchset. Added fix for if MAC not found.
v5: added of_find_matching_node commit.
v6: resend after net-next merge.
v7: removed of_find_matching_node commit. Adjusted mutex_init patch.

Quoted 8 lines
Quoted 7 lines

Rosen Penev (6):
net: ibm: emac: use netif_receive_skb_list
net: ibm: emac: remove custom init/exit functions
net: ibm: emac: use devm_platform_ioremap_resource
net: ibm: emac: use platform_get_irq
net: ibm: emac: use devm for mutex_init
net: ibm: emac: generate random MAC if not found

why is this set to changes requested?

That isn't clear to me either.
Let's try this:

pw-bot: under-review