ksz9477 dsa switch driver improvements
v3 cover ksz9477 dsa switch driver improvements
These changes were made while debugging the ksz9477 driver for use on a custom board which uses the ksz9893 switch supported by this driver. The patches have been runtime tested on top of Linux 5.8.4, I couldn't runtime test them on top of 5.9-rc3 due to unrelated issues. They have been build tested on top of net-next.
These changes can also be pulled from:
https://gitlab.com/pbarker.dev/staging/linux.git
tag: for-net-next/ksz-v3_2020-09-09
Changes from v2:
* Fixed incorrect type in assignment error.
Changes from v1:
* Rebased onto net-next.
* Dropped unnecessary #include <linux/printk.h>.
* Instead of printing the phy mode in ksz9477_port_setup(), modify the existing print in ksz9477_config_cpu_port() to always produce output and to be more clear.
Paul Barker (4):
net: dsa: microchip: Make switch detection more informative
net: dsa: microchip: Improve phy mode message
net: dsa: microchip: Disable RGMII in-band status on KSZ9893
net: dsa: microchip: Implement recommended reset timing
drivers/net/dsa/microchip/ksz9477.c | 25 ++++++++++++++++++++----- drivers/net/dsa/microchip/ksz_common.c | 3 ++- 2 files changed, 22 insertions(+), 6 deletions(-)
Signature · 17 lines
2.28.0 Paul Barker (4): net: dsa: microchip: Make switch detection more informative net: dsa: microchip: Improve phy mode message net: dsa: microchip: Disable RGMII in-band status on KSZ9893 net: dsa: microchip: Implement recommended reset timing drivers/net/dsa/microchip/ksz9477.c | 26 +++++++++++++++++++++----- drivers/net/dsa/microchip/ksz_common.c | 3 ++- 2 files changed, 23 insertions(+), 6 deletions(-) base-commit: f5499c67477eb640e794428da0502c5e4c723119 -- 2.28.0
PATCH v3 1/4 net: dsa: microchip: Make switch detection more informative
To make switch detection more informative print the result of the ksz9477/ksz9893 compatibility check. With debug output enabled also print the contents of the Chip ID registers as a 40-bit hex string.
As this detection is the first communication with the switch performed by the driver, making it easy to see any errors here will help identify issues with SPI data corruption or reset sequencing.
--- drivers/net/dsa/microchip/ksz9477.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/dsa/microchip/ksz9477.c +3 -0
@@ -1426,10 +1426,12 @@ static int ksz9477_switch_detect(struct ksz_device *dev)/* Default capability is gigabit capable. */ dev->features =GBIT_SUPPORT ; +dev_dbg (dev->dev,"Switch detect: ID=%08x%02x\n" , id32, data8); id_hi = (u8)(id32 >>16 ); id_lo = (u8)(id32 >>8 );if ((id_lo &0xf ) ==3 ) {/* Chip is from KSZ9893 design. */ +dev_info (dev->dev,"Found KSZ9893\n" ); dev->features |=IS_9893 ;/* Chip does not support gigabit. */
@@ -1438,6 +1440,7 @@ static int ksz9477_switch_detect(struct ksz_device *dev) dev->mib_port_cnt =3 ; dev->phy_port_cnt =2 ; }else { +dev_info (dev->dev,"Found KSZ9477 or compatible\n" );/* Chip uses new XMII register definitions. */ dev->features |=NEW_XMII ;
Signature · 1 line
2.28.0
PATCH v3 2/4 net: dsa: microchip: Improve phy mode message
In reply to Paul BarkerAlways print the selected phy mode for the CPU port when using the ksz9477 driver. If the phy mode was changed, also print the previous mode to aid in debugging.
To make the message more clear, prefix it with the port number which it applies to and improve the language a little.
--- drivers/net/dsa/microchip/ksz9477.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
drivers/net/dsa/microchip/ksz9477.c +15 -5
@@ -1265,6 +1265,8 @@ static void ksz9477_config_cpu_port(struct dsa_switch *ds)for (i =0 ; i < dev->port_cnt; i++) {if (dsa_is_cpu_port (ds, i) && (dev->cpu_ports & (1 << i))) {phy_interface_t interface; +const char *prev_msg; +const char *prev_mode; dev->cpu_port = i; dev->host_mask = (1 << dev->cpu_port);
@@ -1277,11 +1279,19 @@ static void ksz9477_config_cpu_port(struct dsa_switch *ds) interface =ksz9477_get_interface (dev, i);if (!dev->interface) dev->interface = interface; -if (interface && interface != dev->interface) -dev_info (dev->dev, -"use %s instead of %s\n" , -phy_modes (dev->interface), -phy_modes (interface)); +if (interface && interface != dev->interface) { + prev_msg =" instead of " ; + prev_mode =phy_modes (interface); + }else { + prev_msg ="" ; + prev_mode ="" ; + } +dev_info (dev->dev, +"Port%d: using phy mode %s%s%s\n" , + i, +phy_modes (dev->interface), + prev_msg, + prev_mode);/* enable cpu port */ ksz9477_port_setup (dev, i, true);
Signature · 1 line
2.28.0
PATCH v3 3/4 net: dsa: microchip: Disable RGMII in-band status on KSZ9893
In reply to Paul BarkerWe can't assume that the link partner supports the in-band status reporting which is enabled by default on the KSZ9893 when using RGMII for the upstream port.
--- drivers/net/dsa/microchip/ksz9477.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/dsa/microchip/ksz9477.c +3 -0
@@ -1235,6 +1235,9 @@ static void ksz9477_port_setup(struct ksz_device *dev, int port, bool cpu_port)if (dev->interface ==PHY_INTERFACE_MODE_RGMII_ID || dev->interface ==PHY_INTERFACE_MODE_RGMII_TXID ) data8 |=PORT_RGMII_ID_EG_ENABLE ; +/* On KSZ9893, disable RGMII in-band status support */ +if (dev->features &IS_9893 ) + data8 &= ~PORT_MII_MAC_MODE ; p->phydev.speed =SPEED_1000 ;break ; }
Signature · 1 line
2.28.0
PATCH v3 4/4 net: dsa: microchip: Implement recommended reset timing
In reply to Paul BarkerThe datasheet for the ksz9893 and ksz9477 switches recommend waiting at least 100us after the de-assertion of reset before trying to program the device through any interface.
Also switch the existing msleep() call to usleep_range() as recommended in Documentation/timers/timers-howto.rst. The 2ms range used here is somewhat arbitrary, as long as the reset is asserted for at least 10ms we should be ok.
--- drivers/net/dsa/microchip/ksz_common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/dsa/microchip/ksz_common.c +2 -1
@@ -400,8 +400,9 @@ int ksz_switch_register(struct ksz_device *dev,if (dev->reset_gpio) {gpiod_set_value_cansleep (dev->reset_gpio,1 ); -mdelay (10 ); +usleep_range (10000 ,12000 );gpiod_set_value_cansleep (dev->reset_gpio,0 ); +usleep_range (100 ,1000 ); }mutex_init (&dev->dev_mutex);
Signature · 1 line
2.28.0
David Miller
maintainerFrom: Paul Barker <[email protected]>
Date: Wed, 9 Sep 2020 11:04:13 +0100
Quoted 5 lines
These changes were made while debugging the ksz9477 driver for use on a custom board which uses the ksz9893 switch supported by this driver. The patches have been runtime tested on top of Linux 5.8.4, I couldn't runtime test them on top of 5.9-rc3 due to unrelated issues. They have been build tested on top of net-next.
...
Series applied to net-next, thank you.
Quoted 4 lines · David Miller
From: Paul Barker <[email protected]>
Date: Wed, 9 Sep 2020 11:04:13 +0100
Quoted 9 lines
Quoted 5 lines
These changes were made while debugging the ksz9477 driver for use on a custom board which uses the ksz9893 switch supported by this driver. The patches have been runtime tested on top of Linux 5.8.4, I couldn't runtime test them on top of 5.9-rc3 due to unrelated issues. They have been build tested on top of net-next.
...
Series applied to net-next, thank you.
Thanks David, and thanks Andrew and Florian for the reviews.
Signature · 2 lines
Paul Barker Konsulko Group