Skip to contentSkip to conversation

net: phy: Add config option to specify external switch port to be used if switch is used as PHY

PATCH In review Lambrecht Jürgen 3 participants 6 messages Sep 8, 2011

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

PATCH 1/1 net: phy: Add config option to specify external switch port to be used if switch is used as PHY

Hello,

In our embedded designs, this is a useful patch. Maybe it can be useful for somebody else too.
Or maybe there are already better solutions?
I know I could also write a driver for our switch, but that is too much effort just to select the active port.

Kind regards,
Jürgen

In embedded design, instead of a PHY, sometimes a switch is used that
behaves as a PHY through its MII port. For example to use a daisy chain network configuration instead of an expensive star config. In that case, many phy ports are available, but only 1 should
be used
to check link status, and not the first one available as is
the case
without this configuration (that is, set to its default value 0). So this options specifies the switch port number to be used
to check
link status, because if the link is down, no data is sent by the TCP/IP stack.

---
  drivers/net/phy/Kconfig    |   14 ++++++++++++++
  drivers/net/phy/mdio_bus.c |    9 +++++++++
  2 files changed, 23 insertions(+), 0 deletions(-)
drivers/net/phy/Kconfig +5 -0
index a702443..554561f 100644
@@ -13,6 +13,20 @@ menuconfig PHYLIB
 
  if PHYLIB
 
+config SWITCH_PHY
+       int "External switch port to be used if switch is used as PHY"
+       default "0"
+       help
+         In embedded design, instead of a PHY, sometimes a switch is 

used that

+         behaves as a PHY through its MII port. For example to use a daisy
+         chain network configuration instead of an expensive star config.
+         In that case, many phy ports are available, but only 1 should 

be used
+ to check link status, and not the first one available as is
the case
+ without this configuration (that is, set to its default value 0).
+ So this options specifies the switch port number to be used to
check
+ link status, because if the link is down, no data is sent by the
+ TCP/IP stack.
+
comment "MII PHY device drivers"

config MARVELL_PHY

drivers/net/phy/mdio_bus.c +9 -0
index 6c58da2..016437a 100644
@@ -112,7 +112,14 @@ int mdiobus_register(struct mii_bus *bus)
         if (bus->reset)
                 bus->reset(bus);
 
+       /* The config below is always availble with CONFIG_PHYLIB. If 0, the
+          behavior is as before without this patch (or P0 of the switch is
+          taken because it is the first one found). */
+#if CONFIG_SWITCH_PHY
+       i = CONFIG_SWITCH_PHY;
+#else
         for (i = 0; i < PHY_MAX_ADDR; i++) {
+#endif
                 if ((bus->phy_mask & (1 << i)) == 0) {
                         struct phy_device *phydev;
 
@@ -122,7 +129,9 @@ int mdiobus_register(struct mii_bus *bus)
                                 goto error;
                         }
                 }
+#if !CONFIG_SWITCH_PHY
         }
+#endif
 
         bus->state = MDIOBUS_REGISTERED;
         pr_info("%s: probed\n", bus->name);

--
1.7.1

#1 lore raw

Hello Jurgen,

Quoted 7 lines · On Thursday 08 September 2011 08:54:07 Lambrecht Jürgen wrote:

Hello,

In our embedded designs, this is a useful patch. Maybe it can be useful for somebody else too.
Or maybe there are already better solutions?
I know I could also write a driver for our switch, but that is too much effort just to select the active port.

This is not going to work well with all switches out there. You could use the fixed-PHY driver to make your ethernet driver see the link as always up between the MAC and switch CPU port.

A better solution would be to have proper switch drivers and user-space, which reminds me that we (OpenWrt) should at some point propose our switch drivers
[1] for review.

[1]:
https://dev.openwrt.org/browser/trunk/target/linux/generic/files/drivers/net/phy/

Quoted 83 lines

Kind regards,
Jürgen

In embedded design, instead of a PHY, sometimes a switch is used that
behaves as a PHY through its MII port. For example to use a
daisy chain network configuration instead of an expensive star config. In that case, many phy ports are available, but only 1 should be used
to check link status, and not the first one available as is
the case
without this configuration (that is, set to its default value
0). So this options specifies the switch port number to be used to check
link status, because if the link is down, no data is sent by the TCP/IP stack.

---
  drivers/net/phy/Kconfig    |   14 ++++++++++++++
  drivers/net/phy/mdio_bus.c |    9 +++++++++
  2 files changed, 23 insertions(+), 0 deletions(-)
drivers/net/phy/Kconfig +5 -0
index a702443..554561f 100644
@@ -13,6 +13,20 @@ menuconfig PHYLIB
 
  if PHYLIB
 
+config SWITCH_PHY
+       int "External switch port to be used if switch is used as PHY"
+       default "0"
+       help
+         In embedded design, instead of a PHY, sometimes a switch is

used that

drivers/net/phy/Kconfig +3 -0
+         behaves as a PHY through its MII port. For example to use a daisy
+         chain network configuration instead of an expensive star config.
+         In that case, many phy ports are available, but only 1 should

be used
+ to check link status, and not the first one available as is
the case

drivers/net/phy/Kconfig +2 -0
+         without this configuration (that is, set to its default value 0).
+         So this options specifies the switch port number to be used to

check

drivers/net/phy/Kconfig +3 -0
+         link status, because if the link is down, no data is sent by the
+         TCP/IP stack.
+
  comment "MII PHY device drivers"
 
  config MARVELL_PHY
drivers/net/phy/mdio_bus.c +1 -0
index 6c58da2..016437a 100644
@@ -112,7 +112,14 @@ int mdiobus_register(struct mii_bus *bus)
         if (bus->reset)
                 bus->reset(bus);
 
+       /* The config below is always availble with CONFIG_PHYLIB. If 0,

the + behavior is as before without this patch (or P0 of the
switch is + taken because it is the first one found). */

drivers/net/phy/mdio_bus.c +6 -1
+#if CONFIG_SWITCH_PHY
+       i = CONFIG_SWITCH_PHY;
+#else
         for (i = 0; i < PHY_MAX_ADDR; i++) {
+#endif
                 if ((bus->phy_mask & (1 << i)) == 0) {
                         struct phy_device *phydev;
@@ -122,7 +129,9 @@ int mdiobus_register(struct mii_bus *bus)
                                 goto error;
                         }
                 }
+#if !CONFIG_SWITCH_PHY
         }
+#endif
 
         bus->state = MDIOBUS_REGISTERED;
         pr_info("%s: probed\n", bus->name);
--

1.7.1 N�����r��y����b�X��ǧv�^�)޺{.n�+���z�^�)����w*jg��������ݢj/���z�ޖ��2�ޙ���� &�)ߡ�a�����G���h��j:+v���w��٥

Signature · 1 line
Florian
#2 lore raw
Quoted 6 lines · Florian Fainelli

Hello Jurgen,

Quoted 2 lines · On Thursday 08 September 2011 08:54:07 Lambrecht J��rgen wrote:

Hello,

Quoted 9 lines
Quoted 5 lines

In our embedded designs, this is a useful patch. Maybe it can be useful for somebody else too.
Or maybe there are already better solutions?
I know I could also write a driver for our switch, but that is too much effort just to select the active port.

This is not going to work well with all switches out there. You could use the

Do not all switches follow the basic MII register map with room for 31 phy's?

Quoted 5 lines

fixed-PHY driver to make your ethernet driver see the link as always up between
the MAC and switch CPU port.

Indeed, I tried to, but it didn't work. (would be my preferred solution) I juist enabled FIXED_PHY in menuconfig (and kept MII, NET_ETHERNET and FEC (for my iMX cpu); also PHYLIB is on that makes mdio_bus.c compile). I checked the architecture file for mpc866ads and didn't find any init for it, but maybe I need to initialize fixed-PHY somewhere?

However, it could be interesting sometimes from application side to know if the real external link is up, then fixed-PHY is not ok.

Quoted 11 lines

A better solution would be to have proper switch drivers and user-space, which
reminds me that we (OpenWrt) should at some point propose our switch drivers
[1] for review.

[1]:
https://dev.openwrt.org/browser/trunk/target/linux/generic/files/drivers/net/phy/

Just had a fast look to the Marvell switch driver. Nice to know it is there.

Quoted 22 lines
Quoted 9 lines

Kind regards,
J��rgen

In embedded design, instead of a PHY, sometimes a switch is used that
behaves as a PHY through its MII port. For example to use a
daisy chain network configuration instead of an expensive star

config. In

Quoted 6 lines

that case, many phy ports are available, but only 1 should be used
to check link status, and not the first one available as is
the case
without this configuration (that is, set to its default value
0). So this options specifies the switch port number to be used to check
link status, because if the link is down, no data is sent

by the

Quoted 4 lines

TCP/IP stack.

---

[snip]

Quoted 4 lines

--
Florian

Signature · 6 lines
J��rgen Lambrecht
R&D Associate
Tel: +32 (0)51 303045    Fax: +32 (0)51 310670
http://www.televic-rail.com
Televic Rail NV - Leo Bekaertlaan 1 - 8870 Izegem - Belgium
Company number 0825.539.581 - RPR Kortrijk
#3 lore raw
In reply to Lambrecht Jürgen

Lambrecht Jürgen <[email protected]> :
[...]

Quoted 8 lines
drivers/net/phy/mdio_bus.c +0 -0
index 6c58da2..016437a 100644
@@ -112,7 +112,14 @@ int mdiobus_register(struct mii_bus *bus)
         if (bus->reset)
                 bus->reset(bus);
 

drivers/net/phy/mdio_bus.c int mdiobus_register(struct mii_bus *bus) · line 124

Quoted 10 lines
drivers/net/phy/mdio_bus.c +7 -0
+       /* The config below is always availble with CONFIG_PHYLIB. If 0, the
+          behavior is as before without this patch (or P0 of the switch is
+          taken because it is the first one found). */
+#if CONFIG_SWITCH_PHY
+       i = CONFIG_SWITCH_PHY;
+#else
         for (i = 0; i < PHY_MAX_ADDR; i++) {
+#endif
                 if ((bus->phy_mask & (1 << i)) == 0) {
                         struct phy_device *phydev;

This config option may help your platform but it is nowhere reusable on a slightly different one (each mii_bus behavior is changed).

Which driver(s) do you use that you can not set phy_mask directly ?

Signature · 1 line
Ueimor
#4 lore raw
Quoted 27 lines · Francois Romieu

Lambrecht Jürgen <[email protected]> :
[...]

drivers/net/phy/mdio_bus.c int mdiobus_register(struct mii_bus *bus) · line 115

Quoted 9 lines
drivers/net/phy/mdio_bus.c +1 -0
index 6c58da2..016437a 100644
@@ -112,7 +112,14 @@ int mdiobus_register(struct mii_bus *bus)
         if (bus->reset)
                 bus->reset(bus);
 
+       /* The config below is always availble with CONFIG_PHYLIB. 

If 0, the

drivers/net/phy/mdio_bus.c int mdiobus_register(struct mii_bus *bus) · line 116

Quoted 1 line
drivers/net/phy/mdio_bus.c +1 -0
+          behavior is as before without this patch (or P0 of the 

switch is

drivers/net/phy/mdio_bus.c int mdiobus_register(struct mii_bus *bus) · line 124

Quoted 8 lines
drivers/net/phy/mdio_bus.c +5 -0
+          taken because it is the first one found). */
+#if CONFIG_SWITCH_PHY
+       i = CONFIG_SWITCH_PHY;
+#else
         for (i = 0; i < PHY_MAX_ADDR; i++) {
+#endif
                 if ((bus->phy_mask & (1 << i)) == 0) {
                         struct phy_device *phydev;

This config option may help your platform but it is nowhere reusable on a slightly different one (each mii_bus behavior is changed).

Quoted 2 lines

Which driver(s) do you use that you can not set phy_mask directly ?

The HW driver is 'FEC' for iMX Ethernet. For the PHY, just MII and PHYLIB. I am rather new to linux, didn't knew phy_mask. Checked it now, and is not set in fec.c.
You mean then to patch drivers/net/fec.c in the same way (as my current patch) to set the phy_mask instead (via menuconfig, or in the platform init)?

Thanks for your reply,
Jürgen

Quoted 5 lines

--
Ueimor

Signature · 6 lines
Jürgen Lambrecht
R&D Associate
Tel: +32 (0)51 303045    Fax: +32 (0)51 310670
http://www.televic-rail.com
Televic Rail NV - Leo Bekaertlaan 1 - 8870 Izegem - Belgium
Company number 0825.539.581 - RPR Kortrijk
#5 lore raw

Lambrecht Jürgen <[email protected]> :

Quoted 1 line · Francois Romieu

[...]

Quoted 8 lines
Quoted 2 lines

Which driver(s) do you use that you can not set phy_mask directly ?

The HW driver is 'FEC' for iMX Ethernet. For the PHY, just MII and PHYLIB. I am rather new to linux, didn't knew phy_mask. Checked it now, and is not set in fec.c.
You mean then to patch drivers/net/fec.c in the same way (as my current patch) to set the phy_mask instead (via menuconfig, or in the platform init)?

It is not my area but I would have drivers/net/fec.c::fec_devtype.driver_data point to a real struct where the relevant phy_mask and the current quirks are stored, then add a new entry in fec_devtype and a reference to it (Kconfig + platform init) somewhere below arch/arm/plat-mxc.

Freescale's application note suggests that the MX25 fec allows some freedom for the implementation of the media interface. So it may not be overkill.

Signature · 1 line
Ueimor