All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Łukasz Majewski" <lukma@nabladev.com>
To: Vladimir Oltean <vladimir.oltean@nxp.com>
Cc: netdev@vger.kernel.org, Andrew Lunn <andrew+netdev@lunn.ch>,
	Xiaoliang Yang <xiaoliang.yang_1@nxp.com>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Subject: Re: [PATCH net-next 02/15] net: hsr: create an API to get hsr port type
Date: Mon, 1 Dec 2025 09:32:49 +0100	[thread overview]
Message-ID: <20251201093249.6e451e07@wsk> (raw)
In-Reply-To: <20251130131657.65080-3-vladimir.oltean@nxp.com>

Hi Vladimir,

> From: Xiaoliang Yang <xiaoliang.yang_1@nxp.com>
> 
> Since the introduction of HSR_PT_INTERLINK in commit 5055cccfc2d1
> ("net: hsr: Provide RedBox support (HSR-SAN)"), we see that different
> port types require different settings for hardware offload, which was
> not the case before when we only had HSR_PT_SLAVE_A and
> HSR_PT_SLAVE_B. But there is currently no way to know which port is
> which type, so create the hsr_get_port_type() API function and export
> it.
> 
> When hsr_get_port_type() is called from the device driver, the port
> can must be found in the HSR port list. An important use case is for
^^^^^^^^^^ - I think that can is redundant here.

> this function to work from offloading drivers' NETDEV_CHANGEUPPER
> handler, which is triggered by hsr_portdev_setup() ->
> netdev_master_upper_dev_link(). Therefore, we need to move the
> addition of the hsr_port to the HSR port list prior to calling
> hsr_portdev_setup(). This makes the error restoration path also more
> similar to hsr_del_port(), where kfree_rcu(port) is already used.
> 
> Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> Cc: Lukasz Majewski <lukma@denx.de>
> Signed-off-by: Xiaoliang Yang <xiaoliang.yang_1@nxp.com>
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
> ---
>  include/linux/if_hsr.h |  9 +++++++++
>  net/hsr/hsr_device.c   | 20 ++++++++++++++++++++
>  net/hsr/hsr_slave.c    |  7 ++++---
>  3 files changed, 33 insertions(+), 3 deletions(-)
> 
> diff --git a/include/linux/if_hsr.h b/include/linux/if_hsr.h
> index d7941fd88032..f4cf2dd36d19 100644
> --- a/include/linux/if_hsr.h
> +++ b/include/linux/if_hsr.h
> @@ -43,6 +43,8 @@ extern bool is_hsr_master(struct net_device *dev);
>  extern int hsr_get_version(struct net_device *dev, enum hsr_version
> *ver); struct net_device *hsr_get_port_ndev(struct net_device *ndev,
>  				     enum hsr_port_type pt);
> +int hsr_get_port_type(struct net_device *hsr_dev, struct net_device
> *dev,
> +		      enum hsr_port_type *type);
>  #else
>  static inline bool is_hsr_master(struct net_device *dev)
>  {
> @@ -59,6 +61,13 @@ static inline struct net_device
> *hsr_get_port_ndev(struct net_device *ndev, {
>  	return ERR_PTR(-EINVAL);
>  }
> +
> +static inline int hsr_get_port_type(struct net_device *hsr_dev,
> +				    struct net_device *dev,
> +				    enum hsr_port_type *type)
> +{
> +	return -EINVAL;
> +}
>  #endif /* CONFIG_HSR */
>  
>  #endif /*_LINUX_IF_HSR_H_*/
> diff --git a/net/hsr/hsr_device.c b/net/hsr/hsr_device.c
> index 492cbc78ab75..d1bfc49b5f01 100644
> --- a/net/hsr/hsr_device.c
> +++ b/net/hsr/hsr_device.c
> @@ -690,6 +690,26 @@ struct net_device *hsr_get_port_ndev(struct
> net_device *ndev, }
>  EXPORT_SYMBOL(hsr_get_port_ndev);
>  
> +int hsr_get_port_type(struct net_device *hsr_dev, struct net_device
> *dev,
> +		      enum hsr_port_type *type)
> +{
> +	struct hsr_priv *hsr = netdev_priv(hsr_dev);
> +	struct hsr_port *port;
> +
> +	rcu_read_lock();
> +	hsr_for_each_port(hsr, port) {
> +		if (port->dev == dev) {
> +			*type = port->type;
> +			rcu_read_unlock();
> +			return 0;
> +		}
> +	}
> +	rcu_read_unlock();
> +
> +	return -EINVAL;
> +}
> +EXPORT_SYMBOL(hsr_get_port_type);
> +
>  /* Default multicast address for HSR Supervision frames */
>  static const unsigned char def_multicast_addr[ETH_ALEN] __aligned(2)
> = { 0x01, 0x15, 0x4e, 0x00, 0x01, 0x00
> diff --git a/net/hsr/hsr_slave.c b/net/hsr/hsr_slave.c
> index 8177ac6c2d26..afe06ba00ea4 100644
> --- a/net/hsr/hsr_slave.c
> +++ b/net/hsr/hsr_slave.c
> @@ -207,14 +207,14 @@ int hsr_add_port(struct hsr_priv *hsr, struct
> net_device *dev, port->type = type;
>  	ether_addr_copy(port->original_macaddress, dev->dev_addr);
>  
> +	list_add_tail_rcu(&port->port_list, &hsr->ports);
> +
>  	if (type != HSR_PT_MASTER) {
>  		res = hsr_portdev_setup(hsr, dev, port, extack);
>  		if (res)
>  			goto fail_dev_setup;
>  	}
>  
> -	list_add_tail_rcu(&port->port_list, &hsr->ports);
> -
>  	master = hsr_port_get_hsr(hsr, HSR_PT_MASTER);
>  	netdev_update_features(master->dev);
>  	dev_set_mtu(master->dev, hsr_get_max_mtu(hsr));
> @@ -222,7 +222,8 @@ int hsr_add_port(struct hsr_priv *hsr, struct
> net_device *dev, return 0;
>  
>  fail_dev_setup:
> -	kfree(port);
> +	list_del_rcu(&port->port_list);
> +	kfree_rcu(port, rcu);
>  	return res;
>  }
>  

Reviewed-by: Łukasz Majewski <lukma@nabladev.com>

-- 
Best regards,

Lukasz Majewski

--
Nabla Software Engineering GmbH
HRB 40522 Augsburg
Phone: +49 821 45592596
E-Mail: office@nabladev.com
Managing Director : Stefano Babic

  reply	other threads:[~2025-12-01  8:38 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-30 13:16 [PATCH net-next 00/15] DSA simple HSR offload Vladimir Oltean
2025-11-30 13:16 ` [PATCH net-next 01/15] net: dsa: mt7530: unexport mt7530_switch_ops Vladimir Oltean
2025-11-30 20:30   ` Daniel Golle
2025-12-01  5:43   ` Chester A. Unal
2025-11-30 13:16 ` [PATCH net-next 02/15] net: hsr: create an API to get hsr port type Vladimir Oltean
2025-12-01  8:32   ` Łukasz Majewski [this message]
2025-11-30 13:16 ` [PATCH net-next 03/15] net: dsa: avoid calling ds->ops->port_hsr_leave() when unoffloaded Vladimir Oltean
2025-11-30 13:16 ` [PATCH net-next 04/15] net: dsa: xrs700x: reject unsupported HSR configurations Vladimir Oltean
2025-12-01 16:20   ` George McCollister
2025-11-30 13:16 ` [PATCH net-next 05/15] net: dsa: add simple HSR offload helpers Vladimir Oltean
2025-11-30 13:16 ` [PATCH net-next 06/15] net: dsa: yt921x: use simple HSR offloading helpers Vladimir Oltean
2025-11-30 13:16 ` [PATCH net-next 07/15] net: dsa: ocelot: use simple HSR offload helpers Vladimir Oltean
2025-11-30 13:16 ` [PATCH net-next 08/15] net: dsa: realtek: " Vladimir Oltean
2025-11-30 16:03   ` Linus Walleij
2025-11-30 13:16 ` [PATCH net-next 09/15] net: dsa: lantiq_gswip: " Vladimir Oltean
2025-11-30 13:16 ` [PATCH net-next 10/15] net: dsa: mv88e6060: " Vladimir Oltean
2025-11-30 13:16 ` [PATCH net-next 11/15] net: dsa: hellcreek: " Vladimir Oltean
2025-11-30 13:16 ` [PATCH net-next 12/15] net: dsa: mt7530: " Vladimir Oltean
2025-12-01  5:43   ` Chester A. Unal
2025-11-30 13:16 ` [PATCH net-next 13/15] net: dsa: a5psw: " Vladimir Oltean
2025-11-30 13:16 ` [PATCH net-next 14/15] Documentation: net: dsa: mention availability of RedBox Vladimir Oltean
2025-12-02  0:53   ` Jakub Kicinski
2025-11-30 13:16 ` [PATCH net-next 15/15] Documentation: net: dsa: mention simple HSR offload helpers Vladimir Oltean
2025-12-01  8:46 ` [PATCH net-next 00/15] DSA simple HSR offload Łukasz Majewski
2025-12-02  1:00 ` patchwork-bot+netdevbpf

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=20251201093249.6e451e07@wsk \
    --to=lukma@nabladev.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=bigeasy@linutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=vladimir.oltean@nxp.com \
    --cc=xiaoliang.yang_1@nxp.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.