From nobody Mon Oct 6 08:30:17 2025 Received: from inva020.nxp.com (inva020.nxp.com [92.121.34.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA69A281351; Wed, 23 Jul 2025 09:55:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=92.121.34.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753264531; cv=none; b=KuNjCrx4AlB4IbyvwnCLwEd709mVPcnPRqREwnClHIzsKrpkg9VNjKTfOWb+Wzb7XsdZtdE1rGw4IpEi3HIThrZdNJdW9Kf4P4X3WWTjDvo5nTWtm1baAhJm88iwJPNKmdit7k0OYumrwKmEuVj8L94Qj9kTPVJ4FoVoOSQL+Dw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753264531; c=relaxed/simple; bh=uMba/ezhAC8r5pyu8vjGDcLH/UWyJZSzahC5FZcfZPY=; h=From:To:Cc:Subject:Date:Message-Id; b=inEgSNQYBUWXnLfOnEVi6EPIqnBpWV2gm+iLcG+xlDJUwHKZO1VS7TkM9Js2PrvMwW3Aq0bO7rTdr055c/jbX1KD+IQVSdMUHVFigy9PFdFgi/Q+Kc6Y1dVXQbeKWiRBA8ElN74rkgYzfHjWTmyBAmSO27dz2U9CrJYFezKSzjU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; arc=none smtp.client-ip=92.121.34.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 749D91A1640; Wed, 23 Jul 2025 11:55:22 +0200 (CEST) Received: from aprdc01srsp001v.ap-rdc01.nxp.com (aprdc01srsp001v.ap-rdc01.nxp.com [165.114.16.16]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 37DB61A05FA; Wed, 23 Jul 2025 11:55:22 +0200 (CEST) Received: from mega.am.freescale.net (mega.ap.freescale.net [10.192.208.232]) by aprdc01srsp001v.ap-rdc01.nxp.com (Postfix) with ESMTP id 1B9AD1800079; Wed, 23 Jul 2025 17:55:20 +0800 (+08) From: Xiaoliang Yang To: davem@davemloft.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: kuba@kernel.org, n.zhandarovich@fintech.ru, edumazet@google.com, pabeni@redhat.com, wojciech.drewek@intel.com, Arvid.Brodin@xdin.com, horms@kernel.org, lukma@denx.de, m-karicheri2@ti.com, xiaoliang.yang_1@nxp.com, vladimir.oltean@nxp.com Subject: [PATCH net-next] net: hsr: create an API to get hsr port type Date: Wed, 23 Jul 2025 18:06:05 +0800 Message-Id: <20250723100605.23860-1-xiaoliang.yang_1@nxp.com> X-Mailer: git-send-email 2.17.1 X-Virus-Scanned: ClamAV using ClamSMTP Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" If a switch device has HSR hardware ability and HSR configuration offload to hardware. The device driver needs to get the HSR port type when joining the port to HSR. Different port types require different settings for the hardware, like HSR_PT_SLAVE_A, HSR_PT_SLAVE_B, and HSR_PT_INTERLINK. Create the API hsr_get_port_type() and export it. When the hsr_get_port_type() is called in the device driver, if the port can be found in the HSR port list, the HSR port type can be obtained. Therefore, before calling the device driver, we need to first add the hsr_port to the HSR port list. Signed-off-by: Xiaoliang Yang --- include/linux/if_hsr.h | 8 ++++++++ net/hsr/hsr_device.c | 20 ++++++++++++++++++++ net/hsr/hsr_slave.c | 7 ++++--- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/include/linux/if_hsr.h b/include/linux/if_hsr.h index d7941fd88032..4d6452ca2ac8 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); +extern 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,12 @@ static inline struct net_device *hsr_get_port_ndev(struc= t 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 */ =20 #endif /*_LINUX_IF_HSR_H_*/ diff --git a/net/hsr/hsr_device.c b/net/hsr/hsr_device.c index 88657255fec1..d4bea847527c 100644 --- a/net/hsr/hsr_device.c +++ b/net/hsr/hsr_device.c @@ -679,6 +679,26 @@ struct net_device *hsr_get_port_ndev(struct net_device= *ndev, } EXPORT_SYMBOL(hsr_get_port_ndev); =20 +/* Get hsr port type, return -EINVAL if not get. + */ +int hsr_get_port_type(struct net_device *hsr_dev, struct net_device *dev, = enum hsr_port_type *type) +{ + struct hsr_priv *hsr; + struct hsr_port *port; + + hsr =3D netdev_priv(hsr_dev); + + hsr_for_each_port(hsr, port) { + if (port->dev =3D=3D dev) { + *type =3D port->type; + return 0; + } + } + + 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) =3D { 0x01, 0x15, 0x4e, 0x00, 0x01, 0x00 diff --git a/net/hsr/hsr_slave.c b/net/hsr/hsr_slave.c index b87b6a6fe070..e11ab1ed3320 100644 --- a/net/hsr/hsr_slave.c +++ b/net/hsr/hsr_slave.c @@ -198,14 +198,14 @@ int hsr_add_port(struct hsr_priv *hsr, struct net_dev= ice *dev, port->type =3D type; ether_addr_copy(port->original_macaddress, dev->dev_addr); =20 + list_add_tail_rcu(&port->port_list, &hsr->ports); + if (type !=3D HSR_PT_MASTER) { res =3D hsr_portdev_setup(hsr, dev, port, extack); if (res) goto fail_dev_setup; } =20 - list_add_tail_rcu(&port->port_list, &hsr->ports); - master =3D hsr_port_get_hsr(hsr, HSR_PT_MASTER); netdev_update_features(master->dev); dev_set_mtu(master->dev, hsr_get_max_mtu(hsr)); @@ -213,7 +213,8 @@ int hsr_add_port(struct hsr_priv *hsr, struct net_devic= e *dev, return 0; =20 fail_dev_setup: - kfree(port); + list_del_rcu(&port->port_list); + kfree_rcu(port, rcu); return res; } =20 --=20 2.17.1