mbox series

[net-next,v3,0/7] net: dsa: microchip: provide Wake on LAN support

Message ID 20231013122405.3745475-1-o.rempel@pengutronix.de
Headers show
Series net: dsa: microchip: provide Wake on LAN support | expand

Message

Oleksij Rempel Oct. 13, 2023, 12:23 p.m. UTC
changes v3:
- use ethernet address of DSA master instead from devicetree
- use dev_ops->wol* instead of list of supported switch
- don't shotdown the switch if WoL is enabled
- rework on top of latest HSR changes

changes v2:
- rebase against latest next

This series of patches provides Wake on LAN support for the KSZ9477
family of switches. It was tested on KSZ8565 Switch with PME pin
attached to an external PMIC.

The patch making WoL configuration persist on system shutdown will be
send separately, since it will potentially need more discussion.

Oleksij Rempel (7):
  net: dsa: microchip: Add missing MAC address register offset for
    ksz8863
  net: dsa: microchip: Set unique MAC at startup for WoL support
  net: dsa: microchip: ksz9477: add Wake on LAN support
  net: dsa: microchip: ksz9477: add Wake on PHY event support
  dt-bindings: net: dsa: microchip: add wakeup-source property
  net: dsa: microchip: use wakeup-source DT property to enable PME
    output
  net: dsa: microchip: do not shut down the switch if WoL is active

 .../bindings/net/dsa/microchip,ksz.yaml       |   2 +
 drivers/net/dsa/microchip/ksz9477.c           | 116 +++++++++++++++++
 drivers/net/dsa/microchip/ksz9477.h           |   4 +
 drivers/net/dsa/microchip/ksz9477_i2c.c       |   3 +
 drivers/net/dsa/microchip/ksz_common.c        | 117 ++++++++++++++++--
 drivers/net/dsa/microchip/ksz_common.h        |   7 ++
 drivers/net/dsa/microchip/ksz_spi.c           |   3 +
 7 files changed, 245 insertions(+), 7 deletions(-)

Comments

Andrew Lunn Oct. 14, 2023, 4:55 p.m. UTC | #1
On Fri, Oct 13, 2023 at 02:23:59PM +0200, Oleksij Rempel wrote:
> Add the missing offset for the global MAC address register
> (REG_SW_MAC_ADDR) for the ksz8863 family of switches.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew
Andrew Lunn Oct. 14, 2023, 5:01 p.m. UTC | #2
On Fri, Oct 13, 2023 at 02:24:00PM +0200, Oleksij Rempel wrote:
> Set a unique global MAC address for each switch on the network at system
> startup by syncing the switch's global MAC address with the Ethernet
> address of the DSA master interface. This is crucial for supporting
> Wake-on-LAN (WoL) functionality, as it requires a unique address for
> each switch.
> 
> Although the operation is performed only at system start and won't sync
> if the master Ethernet address changes dynamically, it lays the
> groundwork for WoL support by ensuring a unique MAC address for each
> switch.

I've not been following this patchset, so sorry if i make points
others have asked on earlier versions.

Maybe it would be good to add that the hardware only supports one MAC
address for all ports for WoL, and its this address. At least that is
my assumption.

> + * ksz_cmn_set_default_switch_mac_addr - Set the switch's global MAC address
> + *                                       from master port.

Florian is doing a search replace to make use of the word `conduit`. 


> @@ -3572,8 +3633,6 @@ static int ksz_switch_macaddr_get(struct dsa_switch *ds, int port,
>  	const unsigned char *addr = slave->dev_addr;

and this might need to change to user?
Andrew Lunn Oct. 14, 2023, 5:20 p.m. UTC | #3
On Fri, Oct 13, 2023 at 02:24:02PM +0200, Oleksij Rempel wrote:
> KSZ9477 family of switches supports multiple PHY events:
> - wake on Link Up
> - wake on Energy Detect.
> Since current UAPI can't differentiate between this PHY events, map all of them
> to WAKE_PHY.

I assume link up and energy detect work without doing a MAC address
comparison? So maybe these should be added first, and then handle
WAKE_MAGIC and setting the global MAC address, and verifying it
matches the user interface MAC address?

     Andrew
Florian Fainelli Oct. 15, 2023, 9:14 p.m. UTC | #4
On 10/13/2023 5:23 AM, Oleksij Rempel wrote:
> Add the missing offset for the global MAC address register
> (REG_SW_MAC_ADDR) for the ksz8863 family of switches.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>

Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Florian Fainelli Oct. 15, 2023, 9:18 p.m. UTC | #5
On 10/13/2023 5:32 AM, Vladimir Oltean wrote:
> On Fri, Oct 13, 2023 at 02:24:00PM +0200, Oleksij Rempel wrote:
>> Set a unique global MAC address for each switch on the network at system
>> startup by syncing the switch's global MAC address with the Ethernet
>> address of the DSA master interface. This is crucial for supporting
>> Wake-on-LAN (WoL) functionality, as it requires a unique address for
>> each switch.
>>
>> Although the operation is performed only at system start and won't sync
>> if the master Ethernet address changes dynamically, it lays the
>> groundwork for WoL support by ensuring a unique MAC address for each
>> switch.
>>
>> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
>> ---
> 
> Why not take the MAC address of the user port at ksz9477_set_wol() time,
> and use the existing ksz_switch_macaddr_get() API that was just added so
> that this use case could work?

Agreed we do that in a number of Ethernet MAC and PHY drivers FWIW 
(net_device::dev_addr).
Vladimir Oltean Oct. 16, 2023, 10:15 a.m. UTC | #6
On Sun, Oct 15, 2023 at 02:18:43PM -0700, Florian Fainelli wrote:
> 
> 
> On 10/13/2023 5:32 AM, Vladimir Oltean wrote:
> > On Fri, Oct 13, 2023 at 02:24:00PM +0200, Oleksij Rempel wrote:
> > > Set a unique global MAC address for each switch on the network at system
> > > startup by syncing the switch's global MAC address with the Ethernet
> > > address of the DSA master interface. This is crucial for supporting
> > > Wake-on-LAN (WoL) functionality, as it requires a unique address for
> > > each switch.
> > > 
> > > Although the operation is performed only at system start and won't sync
> > > if the master Ethernet address changes dynamically, it lays the
> > > groundwork for WoL support by ensuring a unique MAC address for each
> > > switch.
> > > 
> > > Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> > > ---
> > 
> > Why not take the MAC address of the user port at ksz9477_set_wol() time,
> > and use the existing ksz_switch_macaddr_get() API that was just added so
> > that this use case could work?
> 
> Agreed we do that in a number of Ethernet MAC and PHY drivers FWIW
> (net_device::dev_addr).
> -- 
> Florian

To be clear (to Oleksij), the request is for WoL to use the same runtime
management of the global MAC address (ksz_switch_macaddr_get) as HSR,
and also extend ksz_port_set_mac_address() to deny address changes to a
port with WoL active. Thus, multiple user ports could have WoL enabled
as long as they share the same MAC address. MAC address changes are also
possible while WoL is not enabled. I guess wol->supported should only
get set on those user ports which have the same MAC address as the
global MAC address (if a global MAC address is configured), or on all
user ports (if there is none).