mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frieder Schrempf <frieder.schrempf@kontron.de>
To: Tristram.Ha@microchip.com, frieder@fris.de
Cc: netdev@vger.kernel.org, davem@davemloft.net, edumazet@google.com,
	kuba@kernel.org, linux-kernel@vger.kernel.org, lukma@denx.de,
	pabeni@redhat.com, UNGLinuxDriver@microchip.com,
	olteanv@gmail.com, Woojung.Huh@microchip.com, andrew@lunn.ch,
	florian.fainelli@broadcom.com, jesseevg@gmail.com,
	o.rempel@pengutronix.de, pieter.van.trappen@cern.ch,
	rmk+kernel@armlinux.org.uk, horms@kernel.org,
	vadim.fedorenko@linux.dev
Subject: Re: [RFC PATCH] net: dsa: microchip: Prevent overriding of HSR port forwarding
Date: Mon, 18 Aug 2025 13:00:59 +0200	[thread overview]
Message-ID: <a45178cf-304d-4fab-bb10-7621296661fe@kontron.de> (raw)
In-Reply-To: <DM3PR11MB8736A15C582626DE95429F6EEC37A@DM3PR11MB8736.namprd11.prod.outlook.com>

Hi Tristram,

Am 16.08.25 um 02:53 schrieb Tristram.Ha@microchip.com:
>> Am 15.08.25 um 00:59 schrieb Andrew Lunn:
>>> On Wed, Aug 13, 2025 at 05:26:12PM +0200, Frieder Schrempf wrote:
>>>> From: Frieder Schrempf <frieder.schrempf@kontron.de>
>>>>
>>>> The KSZ9477 supports NETIF_F_HW_HSR_FWD to forward packets between
>>>> HSR ports. This is set up when creating the HSR interface via
>>>> ksz9477_hsr_join() and ksz9477_cfg_port_member().
>>>>
>>>> At the same time ksz_update_port_member() is called on every
>>>> state change of a port and reconfiguring the forwarding to the
>>>> default state which means packets get only forwarded to the CPU
>>>> port.
>>>>
>>>> If the ports are brought up before setting up the HSR interface
>>>> and then the port state is not changed afterwards, everything works
>>>> as intended:
>>>>
>>>>    ip link set lan1 up
>>>>    ip link set lan2 up
>>>>    ip link add name hsr type hsr slave1 lan1 slave2 lan2 supervision 45 version 1
>>>>    ip addr add dev hsr 10.0.0.10/24
>>>>    ip link set hsr up
>>>>
>>>> If the port state is changed after creating the HSR interface, this results
>>>> in a non-working HSR setup:
>>>>
>>>>    ip link add name hsr type hsr slave1 lan1 slave2 lan2 supervision 45 version 1
>>>>    ip addr add dev hsr 10.0.0.10/24
>>>>    ip link set lan1 up
>>>>    ip link set lan2 up
>>>>    ip link set hsr up
>>>
>>> So, restating what i said in a different thread, what happens if only
>>> software was used? No hardware offload.
>>
>> Sorry, I don't understand what you are aiming at.
>>
>> Yes, this issue is related to hardware offloading. As far as I know
>> there is no option (for the user) to force HSR into SW-only mode. The
>> KSZ9477 driver uses hardware offloading up to the capabilities of the HW
>> by default.
>>
>> Yes, if I disable the offloading by modifying the driver code as already
>> described in the other thread, the issue can be fixed at the cost of
>> loosing the HW acceleration. In this case the driver consistently
>> configures the HSR ports to forward any packets to the CPU which then
>> forwards them as needed.
>>
>> With the driver code as-is, there are two conflicting values used for
>> the register that configures the forwarding. One is set during the HSR
>> setup and makes sure that HSR ports forward packets among each other
>> (and not only to the CPU), the other is set while changing the link
>> state of the HSR ports and causes the forwarding to only happen between
>> each port and the CPU, therefore effectively disabling the HW offloading
>> while the driver still assumes it is enabled.
>>
>> This is obviously a problem that should be fixed in the driver as
>> changing the link state of the ports *after* setup of the HSR is a
>> completely valid operation that shouldn't break things like it currently
>> does.
> 
> Here is a simpler fix for this problem.  If that works for you I can
> submit the fix.
> 
> net: dsa: microchip: Fix HSR port setup issue
> 
> ksz9477_hsr_join() is called once to setup the HSR port membership, but
> the port can be enabled later, or disabled and enabled back and the port
> membership is not set correctly inside ksz_update_port_member().  The
> added code always use the correct HSR port membership for HSR port that
> is enabled.
> 
> Fixes: 2d61298fdd7b ("net: dsa: microchip: Enable HSR offloading for KSZ9477")
> Signed-off-by: Tristram Ha <tristram.ha@microchip.com>
> ---
>  drivers/net/dsa/microchip/ksz_common.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
> index 4cb14288ff0f..c04d4c895025 100644
> --- a/drivers/net/dsa/microchip/ksz_common.c
> +++ b/drivers/net/dsa/microchip/ksz_common.c
> @@ -2457,6 +2457,9 @@ static void ksz_update_port_member(struct ksz_device *dev, int port)
>  		dev->dev_ops->cfg_port_member(dev, i, val | cpu_port);
>  	}
>  
> +	if (!port_member && p->stp_state == BR_STATE_FORWARDING &&
> +	    (dev->hsr_ports & BIT(port)))
> +		port_member = dev->hsr_ports;
>  	dev->dev_ops->cfg_port_member(dev, port, port_member | cpu_port);
>  }
> 

This looks fantastic! Way better than my approach!

I just tested it and it seems to fix the issue for me. Please send this
as formal patch and put me in Reported-by.

You might also want to add a comment in the code that gives a short
explanation for this.

Thanks
Frieder

      reply	other threads:[~2025-08-18 11:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-13 15:26 Frieder Schrempf
2025-08-13 15:45 ` Łukasz Majewski
2025-08-13 15:57   ` Frieder Schrempf
2025-08-14  7:23     ` Łukasz Majewski
2025-08-14 22:59 ` Andrew Lunn
2025-08-15 18:30   ` Frieder Schrempf
2025-08-16  0:53     ` Tristram.Ha
2025-08-18 11:00       ` Frieder Schrempf [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a45178cf-304d-4fab-bb10-7621296661fe@kontron.de \
    --to=frieder.schrempf@kontron.de \
    --cc=Tristram.Ha@microchip.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=Woojung.Huh@microchip.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=florian.fainelli@broadcom.com \
    --cc=frieder@fris.de \
    --cc=horms@kernel.org \
    --cc=jesseevg@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukma@denx.de \
    --cc=netdev@vger.kernel.org \
    --cc=o.rempel@pengutronix.de \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=pieter.van.trappen@cern.ch \
    --cc=rmk+kernel@armlinux.org.uk \
    --cc=vadim.fedorenko@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®