Skip to contentSkip to conversation

net: dsa: microchip: use phylink_mac_ops for ksz driver

PATCH Applied Russell King (Oracle) 4 participants 8 messages Apr 26, 2024 – Apr 30, 2024

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

cover net: dsa: microchip: use phylink_mac_ops for ksz driver

Hi,

This four patch series switches the Microchip KSZ DSA driver to use phylink_mac_ops support, and for this one we go a little further beyond a simple conversion. This driver has four distinct cases:

lan937x
ksz9477
ksz8
ksz8830

Three of these cases are handled by shimming the existing DSA calls through ksz_dev_ops, and the final case is handled through a conditional in ksz_phylink_mac_config(). These can all be handled with separate phylink_mac_ops.

To get there, we do a progressive conversion.

Patch 1 removes ksz_dev_ops' phylink_mac_config() method which is not populated in any of the arrays - and is thus redundant.

Patch 2 switches the driver to use a common set of phylink_mac_ops for all cases, doing the simple conversion to avoid the DSA shim.

Patch 3 pushes the phylink_mac_ops down to the first three classes (lan937x, ksz9477, ksz8) adding an appropriate pointer to the phylink_mac_ops to struct ksz_chip_data, and using that to populate DSA's ds->phylink_mac_ops pointer. The difference between each of these are the mac_link_up() method. mac_config() and mac_link_down() remain common between each at this stage.

Patch 4 splits out ksz8830, which needs different mac_config() handling, and thus means we have a difference in mac_config() methods between the now four phylink_mac_ops structures.

Build tested only, with additional -Wunused-const-variable flag.

 drivers/net/dsa/microchip/ksz8.h       |   6 +-
 drivers/net/dsa/microchip/ksz8795.c    |  10 ++-
 drivers/net/dsa/microchip/ksz_common.c | 121 ++++++++++++++++++++++-----------
 drivers/net/dsa/microchip/ksz_common.h |   5 +-
 4 files changed, 94 insertions(+), 48 deletions(-)
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
#1 lore raw

PATCH 1/4 net: dsa: ksz_common: remove phylink_mac_config from ksz_dev_ops

The phylink_mac_config function pointer member of struct ksz_dev_ops is never initialised, so let's remove it to simplify the code.

---
 drivers/net/dsa/microchip/ksz_common.c | 3 ---
 drivers/net/dsa/microchip/ksz_common.h | 3 ---
 2 files changed, 6 deletions(-)
drivers/net/dsa/microchip/ksz_common.c +0 -3
index 2b510f150dd8..f4469ee24239 100644
@@ -3087,9 +3087,6 @@ static void ksz_phylink_mac_config(struct dsa_switch *ds, int port,
 
 	ksz_set_xmii(dev, port, state->interface);
 
-	if (dev->dev_ops->phylink_mac_config)
-		dev->dev_ops->phylink_mac_config(dev, port, mode, state);
-
 	if (dev->dev_ops->setup_rgmii_delay)
 		dev->dev_ops->setup_rgmii_delay(dev, port);
 }
drivers/net/dsa/microchip/ksz_common.h +0 -3
index 40c11b0d6b62..c88ab5e89ecc 100644
@@ -349,9 +349,6 @@ struct ksz_dev_ops {
 	int (*change_mtu)(struct ksz_device *dev, int port, int mtu);
 	void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze);
 	void (*port_init_cnt)(struct ksz_device *dev, int port);
-	void (*phylink_mac_config)(struct ksz_device *dev, int port,
-				   unsigned int mode,
-				   const struct phylink_link_state *state);
 	void (*phylink_mac_link_up)(struct ksz_device *dev, int port,
 				    unsigned int mode,
 				    phy_interface_t interface,
Signature · 1 line
2.30.2
#3 lore raw

PATCH 2/4 net: dsa: ksz_common: provide own phylink MAC operations

In reply to Russell King (Oracle)

Convert ksz_common to provide its own phylink MAC operations, thus avoiding the shim layer in DSA's port.c

---
 drivers/net/dsa/microchip/ksz_common.c | 42 ++++++++++++++++----------
 1 file changed, 26 insertions(+), 16 deletions(-)
drivers/net/dsa/microchip/ksz_common.c +26 -16
index f4469ee24239..4a754801bca4 100644
@@ -2523,14 +2523,15 @@ static u32 ksz_get_phy_flags(struct dsa_switch *ds, int port)
 	return 0;
 }
 
-static void ksz_mac_link_down(struct dsa_switch *ds, int port,
-			      unsigned int mode, phy_interface_t interface)
+static void ksz_phylink_mac_link_down(struct phylink_config *config,
+				      unsigned int mode,
+				      phy_interface_t interface)
 {
-	struct ksz_device *dev = ds->priv;
-	struct ksz_port *p = &dev->ports[port];
+	struct dsa_port *dp = dsa_phylink_to_port(config);
+	struct ksz_device *dev = dp->ds->priv;
 
 	/* Read all MIB counters when the link is going down. */
-	p->read = true;
+	dev->ports[dp->index].read = true;
 	/* timer started */
 	if (dev->mib_read_interval)
 		schedule_delayed_work(&dev->mib_read, 0);
@@ -3065,11 +3066,13 @@ phy_interface_t ksz_get_xmii(struct ksz_device *dev, int port, bool gbit)
 	return interface;
 }
 
-static void ksz_phylink_mac_config(struct dsa_switch *ds, int port,
+static void ksz_phylink_mac_config(struct phylink_config *config,
 				   unsigned int mode,
 				   const struct phylink_link_state *state)
 {
-	struct ksz_device *dev = ds->priv;
+	struct dsa_port *dp = dsa_phylink_to_port(config);
+	struct ksz_device *dev = dp->ds->priv;
+	int port = dp->index;
 
 	if (ksz_is_ksz88x3(dev)) {
 		dev->ports[port].manual_flow = !(state->pause & MLO_PAUSE_AN);
@@ -3206,16 +3209,19 @@ static void ksz9477_phylink_mac_link_up(struct ksz_device *dev, int port,
 	ksz_duplex_flowctrl(dev, port, duplex, tx_pause, rx_pause);
 }
 
-static void ksz_phylink_mac_link_up(struct dsa_switch *ds, int port,
+static void ksz_phylink_mac_link_up(struct phylink_config *config,
+				    struct phy_device *phydev,
 				    unsigned int mode,
 				    phy_interface_t interface,
-				    struct phy_device *phydev, int speed,
-				    int duplex, bool tx_pause, bool rx_pause)
+				    int speed, int duplex, bool tx_pause,
+				    bool rx_pause)
 {
-	struct ksz_device *dev = ds->priv;
+	struct dsa_port *dp = dsa_phylink_to_port(config);
+	struct ksz_device *dev = dp->ds->priv;
 
-	dev->dev_ops->phylink_mac_link_up(dev, port, mode, interface, phydev,
-					  speed, duplex, tx_pause, rx_pause);
+	dev->dev_ops->phylink_mac_link_up(dev, dp->index, mode, interface,
+					  phydev, speed, duplex, tx_pause,
+					  rx_pause);
 }
 
 static int ksz_switch_detect(struct ksz_device *dev)
@@ -3869,6 +3875,12 @@ static int ksz_hsr_leave(struct dsa_switch *ds, int port,
 	return 0;
 }
 
+static const struct phylink_mac_ops ksz_phylink_mac_ops = {
+	.mac_config	= ksz_phylink_mac_config,
+	.mac_link_down	= ksz_phylink_mac_link_down,
+	.mac_link_up	= ksz_phylink_mac_link_up,
+};
+
 static const struct dsa_switch_ops ksz_switch_ops = {
 	.get_tag_protocol	= ksz_get_tag_protocol,
 	.connect_tag_protocol   = ksz_connect_tag_protocol,
@@ -3878,9 +3890,6 @@ static const struct dsa_switch_ops ksz_switch_ops = {
 	.phy_read		= ksz_phy_read16,
 	.phy_write		= ksz_phy_write16,
 	.phylink_get_caps	= ksz_phylink_get_caps,
-	.phylink_mac_config	= ksz_phylink_mac_config,
-	.phylink_mac_link_up	= ksz_phylink_mac_link_up,
-	.phylink_mac_link_down	= ksz_mac_link_down,
 	.port_setup		= ksz_port_setup,
 	.set_ageing_time	= ksz_set_ageing_time,
 	.get_strings		= ksz_get_strings,
@@ -3936,6 +3945,7 @@ struct ksz_device *ksz_switch_alloc(struct device *base, void *priv)
 	ds->dev = base;
 	ds->num_ports = DSA_MAX_PORTS;
 	ds->ops = &ksz_switch_ops;
+	ds->phylink_mac_ops = &ksz_phylink_mac_ops;
 
 	swdev = devm_kzalloc(base, sizeof(*swdev), GFP_KERNEL);
 	if (!swdev)
Signature · 1 line
2.30.2
#5 lore raw

PATCH 3/4 net: dsa: ksz_common: sub-driver phylink ops

In reply to Russell King (Oracle)
---
 drivers/net/dsa/microchip/ksz8.h       |  6 +-
 drivers/net/dsa/microchip/ksz8795.c    | 10 ++-
 drivers/net/dsa/microchip/ksz_common.c | 84 ++++++++++++++++----------
 drivers/net/dsa/microchip/ksz_common.h |  2 +
 4 files changed, 65 insertions(+), 37 deletions(-)
drivers/net/dsa/microchip/ksz8.h +3 -3
index 571c26ce71e4..9a286d73e9cf 100644
@@ -54,9 +54,9 @@ int ksz8_reset_switch(struct ksz_device *dev);
 int ksz8_switch_init(struct ksz_device *dev);
 void ksz8_switch_exit(struct ksz_device *dev);
 int ksz8_change_mtu(struct ksz_device *dev, int port, int mtu);
-void ksz8_phylink_mac_link_up(struct ksz_device *dev, int port,
-			      unsigned int mode, phy_interface_t interface,
-			      struct phy_device *phydev, int speed, int duplex,
+void ksz8_phylink_mac_link_up(struct phylink_config *config,
+			      struct phy_device *phydev, unsigned int mode,
+			      phy_interface_t interface, int speed, int duplex,
 			      bool tx_pause, bool rx_pause);
 
 #endif
drivers/net/dsa/microchip/ksz8795.c +7 -3
index ecef6f6f830b..b2f66cc75208 100644
@@ -1702,11 +1702,15 @@ static void ksz8_cpu_port_link_up(struct ksz_device *dev, int speed, int duplex,
 		 SW_10_MBIT, ctrl);
 }
 
-void ksz8_phylink_mac_link_up(struct ksz_device *dev, int port,
-			      unsigned int mode, phy_interface_t interface,
-			      struct phy_device *phydev, int speed, int duplex,
+void ksz8_phylink_mac_link_up(struct phylink_config *config,
+			      struct phy_device *phydev, unsigned int mode,
+			      phy_interface_t interface, int speed, int duplex,
 			      bool tx_pause, bool rx_pause)
 {
+	struct dsa_port *dp = dsa_phylink_to_port(config);
+	struct ksz_device *dev = dp->ds->priv;
+	int port = dp->index;
+
 	/* If the port is the CPU port, apply special handling. Only the CPU
 	 * port is configured via global registers.
 	 */
drivers/net/dsa/microchip/ksz_common.c +53 -31

254 lines not on this page · raw message

drivers/net/dsa/microchip/ksz_common.h +2 -0
index c88ab5e89ecc..9409b844af63 100644
@@ -22,6 +22,7 @@
 
 struct ksz_device;
 struct ksz_port;
+struct phylink_mac_ops;
 
 enum ksz_regmap_width {
 	KSZ_REGMAP_8,
@@ -61,6 +62,7 @@ struct ksz_chip_data {
 	bool tc_cbs_supported;
 	bool tc_ets_supported;
 	const struct ksz_dev_ops *ops;
+	const struct phylink_mac_ops *phylink_mac_ops;
 	bool ksz87xx_eee_link_erratum;
 	const struct ksz_mib_names *mib_names;
 	int mib_cnt;
Signature · 1 line
2.30.2
#6 lore raw

PATCH 4/4 net: dsa: ksz_common: use separate phylink_mac_ops for ksz8830

In reply to Russell King (Oracle)

Use a separate phylink_mac_ops for the KSZ8830 chip-id.

---
 drivers/net/dsa/microchip/ksz_common.c | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)
drivers/net/dsa/microchip/ksz_common.c +20 -6
index 2ff0cb175daf..2bb8e8f9e49f 100644
@@ -253,6 +253,9 @@ static const struct ksz_drive_strength ksz8830_drive_strengths[] = {
 	{ KSZ8873_DRIVE_STRENGTH_16MA, 16000 },
 };
 
+static void ksz8830_phylink_mac_config(struct phylink_config *config,
+				       unsigned int mode,
+				       const struct phylink_link_state *state);
 static void ksz_phylink_mac_config(struct phylink_config *config,
 				   unsigned int mode,
 				   const struct phylink_link_state *state);
@@ -260,6 +263,12 @@ static void ksz_phylink_mac_link_down(struct phylink_config *config,
 				      unsigned int mode,
 				      phy_interface_t interface);
 
+static const struct phylink_mac_ops ksz8830_phylink_mac_ops = {
+	.mac_config	= ksz8830_phylink_mac_config,
+	.mac_link_down	= ksz_phylink_mac_link_down,
+	.mac_link_up	= ksz8_phylink_mac_link_up,
+};
+
 static const struct phylink_mac_ops ksz8_phylink_mac_ops = {
 	.mac_config	= ksz_phylink_mac_config,
 	.mac_link_down	= ksz_phylink_mac_link_down,
@@ -1339,7 +1348,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.port_cnt = 3,
 		.num_tx_queues = 4,
 		.ops = &ksz8_dev_ops,
-		.phylink_mac_ops = &ksz8_phylink_mac_ops,
+		.phylink_mac_ops = &ksz8830_phylink_mac_ops,
 		.mib_names = ksz88xx_mib_names,
 		.mib_cnt = ARRAY_SIZE(ksz88xx_mib_names),
 		.reg_mib_cnt = MIB_COUNTER_NUM,
@@ -3104,6 +3113,16 @@ phy_interface_t ksz_get_xmii(struct ksz_device *dev, int port, bool gbit)
 	return interface;
 }
 
+static void ksz8830_phylink_mac_config(struct phylink_config *config,
+				       unsigned int mode,
+				       const struct phylink_link_state *state)
+{
+	struct dsa_port *dp = dsa_phylink_to_port(config);
+	struct ksz_device *dev = dp->ds->priv;
+
+	dev->ports[dp->index].manual_flow = !(state->pause & MLO_PAUSE_AN);
+}
+
 static void ksz_phylink_mac_config(struct phylink_config *config,
 				   unsigned int mode,
 				   const struct phylink_link_state *state)
@@ -3112,11 +3131,6 @@ static void ksz_phylink_mac_config(struct phylink_config *config,
 	struct ksz_device *dev = dp->ds->priv;
 	int port = dp->index;
 
-	if (ksz_is_ksz88x3(dev)) {
-		dev->ports[port].manual_flow = !(state->pause & MLO_PAUSE_AN);
-		return;
-	}
-
 	/* Internal PHYs */
 	if (dev->info->internal_phy[port])
 		return;
Signature · 1 line
2.30.2
#7 lore raw
In reply to Russell King (Oracle)
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 6 lines · On Fri, 26 Apr 2024 17:02:05 +0100 you wrote:

Hi,

This four patch series switches the Microchip KSZ DSA driver to use phylink_mac_ops support, and for this one we go a little further beyond a simple conversion. This driver has four distinct cases:

Quoted 6 lines

lan937x
ksz9477
ksz8
ksz8830

[...]

Here is the summary with links:
- [net-next,1/4] net: dsa: ksz_common: remove phylink_mac_config from ksz_dev_ops

    https://git.kernel.org/netdev/net-next/c/8433c5833ed9
  - [net-next,2/4] net: dsa: ksz_common: provide own phylink MAC operations
    https://git.kernel.org/netdev/net-next/c/95fe2662c56f
  - [net-next,3/4] net: dsa: ksz_common: sub-driver phylink ops
    https://git.kernel.org/netdev/net-next/c/9424c0731355
  - [net-next,4/4] net: dsa: ksz_common: use separate phylink_mac_ops for ksz8830
    https://git.kernel.org/netdev/net-next/c/968d068e5476

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html