Skip to contentSkip to conversation

net: dsa: microchip: delete dead code

RFC PATCH Superseded Helmut Grohne 3 participants 13 messages Jul 21, 2020 – Aug 18, 2020

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

RFC PATCH 1/1 net: dsa: microchip: delete dead code

None of the removed assignments is ever read back and never influences logic.

---
 drivers/net/dsa/microchip/ksz8795.c    | 26 ++--------------------
 drivers/net/dsa/microchip/ksz9477.c    | 30 +-------------------------
 drivers/net/dsa/microchip/ksz_common.c | 23 --------------------
 drivers/net/dsa/microchip/ksz_common.h | 11 ----------
 4 files changed, 3 insertions(+), 87 deletions(-)

While working on the driver (e.g.
https://lore.kernel.org/netdev/[email protected]/), it became clear that we don't have a good understanding of what all that code does. It turns out that part of the code simply does nothing useful and this patch attempts to figure out whether it can be simply removed.

drivers/net/dsa/microchip/ksz8795.c +2 -24
index 7c17b0f705ec..545cb7871712 100644
@@ -731,14 +731,6 @@ static void ksz8795_port_stp_state_set(struct dsa_switch *ds, int port,
 
 	ksz_pwrite8(dev, port, P_STP_CTRL, data);
 	p->stp_state = state;
-	if (data & PORT_RX_ENABLE)
-		dev->rx_ports |= BIT(port);
-	else
-		dev->rx_ports &= ~BIT(port);
-	if (data & PORT_TX_ENABLE)
-		dev->tx_ports |= BIT(port);
-	else
-		dev->tx_ports &= ~BIT(port);
 
 	/* Port membership may share register with STP state. */
 	if (member >= 0 && member != p->member)
@@ -976,15 +968,8 @@ static void ksz8795_port_setup(struct ksz_device *dev, int port, bool cpu_port)
 		p->phydev.duplex = 1;
 
 		member = dev->port_mask;
-		dev->on_ports = dev->host_mask;
-		dev->live_ports = dev->host_mask;
 	} else {
 		member = dev->host_mask | p->vid_member;
-		dev->on_ports |= BIT(port);
-
-		/* Link was detected before port is enabled. */
-		if (p->phydev.link)
-			dev->live_ports |= BIT(port);
 	}
 	ksz8795_cfg_port_member(dev, port, member);
 }
@@ -1023,7 +1008,6 @@ static void ksz8795_config_cpu_port(struct dsa_switch *ds)
 		if (i == dev->port_cnt)
 			break;
 		p->on = 1;
-		p->phy = 1;
 	}
 	for (i = 0; i < dev->phy_port_cnt; i++) {
 		p = &dev->ports[i];
@@ -1032,12 +1016,8 @@ static void ksz8795_config_cpu_port(struct dsa_switch *ds)
 		ksz_pread8(dev, i, P_REMOTE_STATUS, &remote);
 		if (remote & PORT_FIBER_MODE)
 			p->fiber = 1;
-		if (p->fiber)
-			ksz_port_cfg(dev, i, P_STP_CTRL, PORT_FORCE_FLOW_CTRL,
-				     true);
-		else
-			ksz_port_cfg(dev, i, P_STP_CTRL, PORT_FORCE_FLOW_CTRL,
-				     false);
+		ksz_port_cfg(dev, i, P_STP_CTRL, PORT_FORCE_FLOW_CTRL,
+			     !!p->fiber);
 	}
 }
 
@@ -1113,7 +1093,6 @@ static const struct dsa_switch_ops ksz8795_switch_ops = {
 	.phy_write		= ksz_phy_write16,
 	.adjust_link		= ksz_adjust_link,
 	.port_enable		= ksz_enable_port,
-	.port_disable		= ksz_disable_port,
 	.get_strings		= ksz8795_get_strings,
 	.get_ethtool_stats	= ksz_get_ethtool_stats,
 	.get_sset_count		= ksz_sset_count,
@@ -1168,7 +1147,6 @@ static int ksz8795_switch_detect(struct ksz_device *dev)
 			id2 = 0x65;
 	} else if (id2 == CHIP_ID_94) {
 		dev->port_cnt--;
-		dev->last_port = dev->port_cnt;
 		id2 = 0x94;
 	}
 	id16 &= ~0xff;
drivers/net/dsa/microchip/ksz9477.c +1 -29
index 8d15c3016024..db2e8f95fa65 100644
@@ -452,14 +452,6 @@ static void ksz9477_port_stp_state_set(struct dsa_switch *ds, int port,
 	ksz_pwrite8(dev, port, P_STP_CTRL, data);
 	p->stp_state = state;
 	mutex_lock(&dev->dev_mutex);
-	if (data & PORT_RX_ENABLE)
-		dev->rx_ports |= (1 << port);
-	else
-		dev->rx_ports &= ~(1 << port);
-	if (data & PORT_TX_ENABLE)
-		dev->tx_ports |= (1 << port);
-	else
-		dev->tx_ports &= ~(1 << port);
 
 	/* Port membership may share register with STP state. */
 	if (member >= 0 && member != p->member)
@@ -1268,18 +1260,7 @@ static void ksz9477_port_setup(struct ksz_device *dev, int port, bool cpu_port)
 		p->phydev.duplex = 1;
 	}
 	mutex_lock(&dev->dev_mutex);
-	if (cpu_port) {
-		member = dev->port_mask;
-		dev->on_ports = dev->host_mask;
-		dev->live_ports = dev->host_mask;
-	} else {
-		member = dev->host_mask | p->vid_member;
-		dev->on_ports |= (1 << port);
-
-		/* Link was detected before port is enabled. */
-		if (p->phydev.link)
-			dev->live_ports |= (1 << port);
-	}
+	member = cpu_port ? dev->port_mask : (dev->host_mask | p->vid_member);
 	mutex_unlock(&dev->dev_mutex);
 	ksz9477_cfg_port_member(dev, port, member);
 
@@ -1339,14 +1320,6 @@ static void ksz9477_config_cpu_port(struct dsa_switch *ds)
 		p->member = dev->port_mask;
 		ksz9477_port_stp_state_set(ds, i, BR_STATE_DISABLED);
 		p->on = 1;
-		if (i < dev->phy_port_cnt)
-			p->phy = 1;
-		if (dev->chip_id == 0x00947700 && i == 6) {
-			p->sgmii = 1;
-
-			/* SGMII PHY detection code is not implemented yet. */
-			p->phy = 0;
-		}
 	}
 }
 
@@ -1401,7 +1374,6 @@ static const struct dsa_switch_ops ksz9477_switch_ops = {
 	.phy_write		= ksz9477_phy_write16,
 	.adjust_link		= ksz_adjust_link,
 	.port_enable		= ksz_enable_port,
-	.port_disable		= ksz_disable_port,
 	.get_strings		= ksz9477_get_strings,
 	.get_ethtool_stats	= ksz_get_ethtool_stats,
 	.get_sset_count		= ksz_sset_count,
drivers/net/dsa/microchip/ksz_common.c +0 -23
index fd1d6676ae4f..d39644bec85e 100644
@@ -146,13 +146,6 @@ void ksz_adjust_link(struct dsa_switch *ds, int port,
 		p->read = true;
 		schedule_delayed_work(&dev->mib_read, 0);
 	}
-	mutex_lock(&dev->dev_mutex);
-	if (!phydev->link)
-		dev->live_ports &= ~(1 << port);
-	else
-		/* Remember which port is connected and active. */
-		dev->live_ports |= (1 << port) & dev->on_ports;
-	mutex_unlock(&dev->dev_mutex);
 }
 EXPORT_SYMBOL_GPL(ksz_adjust_link);
 
@@ -369,22 +362,6 @@ int ksz_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy)
 }
 EXPORT_SYMBOL_GPL(ksz_enable_port);
 
-void ksz_disable_port(struct dsa_switch *ds, int port)
-{
-	struct ksz_device *dev = ds->priv;
-
-	if (!dsa_is_user_port(ds, port))
-		return;
-
-	dev->on_ports &= ~(1 << port);
-	dev->live_ports &= ~(1 << port);
-
-	/* port_stp_state_set() will be called after to disable the port so
-	 * there is no need to do anything.
-	 */
-}
-EXPORT_SYMBOL_GPL(ksz_disable_port);
-
 struct ksz_device *ksz_switch_alloc(struct device *base, void *priv)
 {
 	struct dsa_switch *ds;
drivers/net/dsa/microchip/ksz_common.h +0 -11
index f2c9bb68fd33..80b56448d7d9 100644
@@ -31,10 +31,7 @@ struct ksz_port {
 	struct phy_device phydev;
 
 	u32 on:1;			/* port is not disabled by hardware */
-	u32 phy:1;			/* port has a PHY */
 	u32 fiber:1;			/* port is fiber */
-	u32 sgmii:1;			/* port is SGMII */
-	u32 force:1;
 	u32 read:1;			/* read MIB counters in background */
 	u32 freeze:1;			/* MIB counter freeze is enabled */
 
@@ -71,9 +68,7 @@ struct ksz_device {
 	int reg_mib_cnt;
 	int mib_cnt;
 	int mib_port_cnt;
-	int last_port;			/* ports after that not used */
 	phy_interface_t interface;
-	u32 regs_size;
 	bool phy_errata_9477;
 	bool synclko_125;
 
@@ -84,14 +79,9 @@ struct ksz_device {
 	unsigned long mib_read_interval;
 	u16 br_member;
 	u16 member;
-	u16 live_ports;
-	u16 on_ports;			/* ports enabled by DSA */
-	u16 rx_ports;
-	u16 tx_ports;
 	u16 mirror_rx;
 	u16 mirror_tx;
 	u32 features;			/* chip specific features */
-	u32 overrides;			/* chip functions set by user */
 	u16 host_mask;
 	u16 port_mask;
 };
@@ -179,7 +169,6 @@ void ksz_port_mdb_add(struct dsa_switch *ds, int port,
 int ksz_port_mdb_del(struct dsa_switch *ds, int port,
 		     const struct switchdev_obj_port_mdb *mdb);
 int ksz_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy);
-void ksz_disable_port(struct dsa_switch *ds, int port);
 
 /* Common register access functions */
 
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 4 lines · Helmut Grohne

None of the removed assignments is ever read back and never influences logic.

Hi Helmut

This patch probably is correct. But it is not obviously correct, because there are so many changes at once. Please could you break it up.

Quoted 25 lines
drivers/net/dsa/microchip/ksz_common.h +0 -5
@@ -31,10 +31,7 @@ struct ksz_port {
 	struct phy_device phydev;
 
 	u32 on:1;			/* port is not disabled by hardware */
-	u32 phy:1;			/* port has a PHY */
 	u32 fiber:1;			/* port is fiber */
-	u32 sgmii:1;			/* port is SGMII */
-	u32 force:1;
 	u32 read:1;			/* read MIB counters in background */
 	u32 freeze:1;			/* MIB counter freeze is enabled */
 
@@ -71,9 +68,7 @@ struct ksz_device {
 	int reg_mib_cnt;
 	int mib_cnt;
 	int mib_port_cnt;
-	int last_port;			/* ports after that not used */
 	phy_interface_t interface;
-	u32 regs_size;
 	bool phy_errata_9477;
 	bool synclko_125;
 
@@ -84,14 +79,9 @@ struct ksz_device {
 	unsigned long mib_read_interval;
 	u16 br_member;
 	u16 member;

drivers/net/dsa/microchip/ksz_common.h struct ksz_device { · line 86

Quoted 10 lines
drivers/net/dsa/microchip/ksz_common.h +0 -5
-	u16 live_ports;
-	u16 on_ports;			/* ports enabled by DSA */
-	u16 rx_ports;
-	u16 tx_ports;
 	u16 mirror_rx;
 	u16 mirror_tx;
 	u32 features;			/* chip specific features */
-	u32 overrides;			/* chip functions set by user */
 	u16 host_mask;
 	u16 port_mask;

So at minimum, break it up into 3 patches, one per structure. I would even go further.

Small patches are easier to review. And if something does break, a git bisect gives you more information about what change broke it.

Thanks
Andrew

#2 lore raw

Hi Andrew,

Quoted 3 lines · Andrew Lunn

This patch probably is correct. But it is not obviously correct, because there are so many changes at once. Please could you break it up.

From my pov, it is less a question of whether it is correct, but whether it goes into the desired direction. There are a few comments in the driver that point to pending work. It might as well be that I'm removing the infrastructure that other patches are meant to build upon.

I guess only the microchip people can answer this and in the event of silence, the best course of action likely is to proceed. Maybe give it some time? It's summer holdiday time in northern hemisphere.

Quoted 5 lines

So at minimum, break it up into 3 patches, one per structure. I would even go further.

Small patches are easier to review. And if something does break, a git bisect gives you more information about what change broke it.

Yes, sure. But this was deliberately RFC and I deliberately merged all the removals to give you a quick idea of the dead code size. I didn't expect this to be applied as is but rather generate a reply regarding the purpose of the code that I propose to remove (in smaller steps).

Helmut

maintainer
#3 lore raw
Quoted 11 lines · Helmut Grohne

Hi Andrew,

Quoted 5 lines · Andrew Lunn

This patch probably is correct. But it is not obviously correct, because there are so many changes at once. Please could you break it up.

From my pov, it is less a question of whether it is correct, but whether

it goes into the desired direction. There are a few comments in the driver that point to pending work. It might as well be that I'm removing the infrastructure that other patches are meant to build upon.

Hi Helmut

There was a small burst of patches from Microchip in this month. But apart from that, you need to go a long way back.

I say clean it up now. The code is in the git history, so it is easy to get back if needed.

Andrew

#6 lore raw

PATCH v2 2/6 net: dsa: microchip: delete unused member ksz_port.sgmii

In reply to Helmut Grohne
---
 drivers/net/dsa/microchip/ksz9477.c    | 2 --
 drivers/net/dsa/microchip/ksz_common.h | 1 -
 2 files changed, 3 deletions(-)
drivers/net/dsa/microchip/ksz9477.c +0 -2
index c548894553bc..0ff54ee4f963 100644
@@ -1305,8 +1305,6 @@ static void ksz9477_config_cpu_port(struct dsa_switch *ds)
 		p->member = dev->port_mask;
 		ksz9477_port_stp_state_set(ds, i, BR_STATE_DISABLED);
 		p->on = 1;
-		if (dev->chip_id == 0x00947700 && i == 6)
-			p->sgmii = 1;
 	}
 }
 
drivers/net/dsa/microchip/ksz_common.h +0 -1
index 0432cd38bf0b..83247140b784 100644
@@ -32,7 +32,6 @@ struct ksz_port {
 
 	u32 on:1;			/* port is not disabled by hardware */
 	u32 fiber:1;			/* port is fiber */
-	u32 sgmii:1;			/* port is SGMII */
 	u32 force:1;
 	u32 read:1;			/* read MIB counters in background */
 	u32 freeze:1;			/* MIB counter freeze is enabled */
Signature · 1 line
2.20.1
#7 lore raw

PATCH v2 3/6 net: dsa: microchip: delete unused member ksz_port.force

In reply to Helmut Grohne
---
 drivers/net/dsa/microchip/ksz_common.h | 1 -
 1 file changed, 1 deletion(-)
drivers/net/dsa/microchip/ksz_common.h +0 -1
index 83247140b784..8e277033bff7 100644
@@ -32,7 +32,6 @@ struct ksz_port {
 
 	u32 on:1;			/* port is not disabled by hardware */
 	u32 fiber:1;			/* port is fiber */
-	u32 force:1;
 	u32 read:1;			/* read MIB counters in background */
 	u32 freeze:1;			/* MIB counter freeze is enabled */
 
Signature · 1 line
2.20.1
#8 lore raw

PATCH v2 4/6 net: dsa: microchip: delete unused member ksz_device.last_port

In reply to Helmut Grohne
---
 drivers/net/dsa/microchip/ksz8795.c    | 1 -
 drivers/net/dsa/microchip/ksz_common.h | 1 -
 2 files changed, 2 deletions(-)
drivers/net/dsa/microchip/ksz8795.c +0 -1
index e62d54306765..3bdfe1f4d0f5 100644
@@ -1150,7 +1150,6 @@ static int ksz8795_switch_detect(struct ksz_device *dev)
 			id2 = 0x65;
 	} else if (id2 == CHIP_ID_94) {
 		dev->port_cnt--;
-		dev->last_port = dev->port_cnt;
 		id2 = 0x94;
 	}
 	id16 &= ~0xff;
drivers/net/dsa/microchip/ksz_common.h +0 -1
index 8e277033bff7..1791442f04ee 100644
@@ -68,7 +68,6 @@ struct ksz_device {
 	int reg_mib_cnt;
 	int mib_cnt;
 	int mib_port_cnt;
-	int last_port;			/* ports after that not used */
 	phy_interface_t interface;
 	u32 regs_size;
 	bool phy_errata_9477;
Signature · 1 line
2.20.1
#5 lore raw

PATCH v2 1/6 net: dsa: microchip: delete unused member ksz_port.phy

In reply to Helmut Grohne
---
 drivers/net/dsa/microchip/ksz8795.c    | 1 -
 drivers/net/dsa/microchip/ksz9477.c    | 8 +-------
 drivers/net/dsa/microchip/ksz_common.h | 1 -
 3 files changed, 1 insertion(+), 9 deletions(-)
drivers/net/dsa/microchip/ksz8795.c +0 -1
index 8f1d15ea15d9..e62d54306765 100644
@@ -1007,7 +1007,6 @@ static void ksz8795_config_cpu_port(struct dsa_switch *ds)
 		if (i == dev->port_cnt)
 			break;
 		p->on = 1;
-		p->phy = 1;
 	}
 	for (i = 0; i < dev->phy_port_cnt; i++) {
 		p = &dev->ports[i];
drivers/net/dsa/microchip/ksz9477.c +1 -7
index dc999406ce86..c548894553bc 100644
@@ -1305,14 +1305,8 @@ static void ksz9477_config_cpu_port(struct dsa_switch *ds)
 		p->member = dev->port_mask;
 		ksz9477_port_stp_state_set(ds, i, BR_STATE_DISABLED);
 		p->on = 1;
-		if (i < dev->phy_port_cnt)
-			p->phy = 1;
-		if (dev->chip_id == 0x00947700 && i == 6) {
+		if (dev->chip_id == 0x00947700 && i == 6)
 			p->sgmii = 1;
-
-			/* SGMII PHY detection code is not implemented yet. */
-			p->phy = 0;
-		}
 	}
 }
 
drivers/net/dsa/microchip/ksz_common.h +0 -1
index 206838160f49..0432cd38bf0b 100644
@@ -31,7 +31,6 @@ struct ksz_port {
 	struct phy_device phydev;
 
 	u32 on:1;			/* port is not disabled by hardware */
-	u32 phy:1;			/* port has a PHY */
 	u32 fiber:1;			/* port is fiber */
 	u32 sgmii:1;			/* port is SGMII */
 	u32 force:1;
Signature · 1 line
2.20.1
#4 lore raw

v2 cover net: dsa: microchip: delete dead code

In reply to Andrew Lunn

Andrew Lunn asked me to turn my dead code removal RFC patch into a real one splitting it per member. This is what this v2 series does. Some parts of the RFC patch are already applied via:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=b20a6b29a811bee0e44b64958d415eb50436154c

All other structure members are read at least once.

Helmut

Helmut Grohne (6):
net: dsa: microchip: delete unused member ksz_port.phy
net: dsa: microchip: delete unused member ksz_port.sgmii
net: dsa: microchip: delete unused member ksz_port.force
net: dsa: microchip: delete unused member ksz_device.last_port
net: dsa: microchip: delete unused member ksz_device.regs_size
net: dsa: microchip: delete unused member ksz_device.overrides

 drivers/net/dsa/microchip/ksz8795.c    | 2 --
 drivers/net/dsa/microchip/ksz9477.c    | 8 --------
 drivers/net/dsa/microchip/ksz_common.h | 6 ------
 3 files changed, 16 deletions(-)
Signature · 1 line
2.20.1
#9 lore raw

PATCH v2 5/6 net: dsa: microchip: delete unused member ksz_device.regs_size

---
 drivers/net/dsa/microchip/ksz_common.h | 1 -
 1 file changed, 1 deletion(-)
drivers/net/dsa/microchip/ksz_common.h +0 -1
index 1791442f04ee..0120f2b72091 100644
@@ -69,7 +69,6 @@ struct ksz_device {
 	int mib_cnt;
 	int mib_port_cnt;
 	phy_interface_t interface;
-	u32 regs_size;
 	bool phy_errata_9477;
 	bool synclko_125;
 
Signature · 1 line
2.20.1
#10 lore raw

PATCH v2 6/6 net: dsa: microchip: delete unused member ksz_device.overrides

In reply to Helmut Grohne
---
 drivers/net/dsa/microchip/ksz_common.h | 1 -
 1 file changed, 1 deletion(-)
drivers/net/dsa/microchip/ksz_common.h +0 -1
index 0120f2b72091..10ff7774a867 100644
@@ -82,7 +82,6 @@ struct ksz_device {
 	u16 mirror_rx;
 	u16 mirror_tx;
 	u32 features;			/* chip specific features */
-	u32 overrides;			/* chip functions set by user */
 	u16 host_mask;
 	u16 port_mask;
 };
Signature · 1 line
2.20.1
#11 lore raw
In reply to Helmut Grohne
Quoted 6 lines · Helmut Grohne

Andrew Lunn asked me to turn my dead code removal RFC patch into a real one splitting it per member. This is what this v2 series does. Some parts of the RFC patch are already applied via:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=b20a6b29a811bee0e44b64958d415eb50436154c

All other structure members are read at least once.

net-next is currently closed at the moment, and these patches are clearly targeted at that tree:

http://vger.kernel.org/~davem/net-next.html

Also, please provide a commit message, even if it is only paraphrasing what the subject does. The changes do look good, so once you fix that, we should be good.

Thank you

Signature · 1 line
Florian
#12 lore raw

Hi Florian,

Quoted 2 lines · Florian Fainelli

net-next is currently closed at the moment, and these patches are clearly targeted at that tree:

I agree that these are clearly net-next material.

Quoted 1 line

http://vger.kernel.org/~davem/net-next.html

It says "Come in we're open" for me. Maybe that changed over night and I was just a day early? I'll check this for future submissions.

Quoted 3 lines

Also, please provide a commit message, even if it is only paraphrasing what the subject does. The changes do look good, so once you fix that, we should be good.

I'm all for writing good commit messages and if you look into the few commits I've authored thus far, you see that I usually do explain them in detail. In these cases however, I'm left wondering what value any further explanation would add. Repeating the subject does not make sense to me.

I feel that we're overdoing it here and that there are more important aspects to be improved about the driver. I'll be focusing on those.

Helmut