* [PATCH net-next] net: hsr: create an API to get hsr port type
@ 2025-07-23 10:06 Xiaoliang Yang
2025-07-23 10:06 ` Vladimir Oltean
0 siblings, 1 reply; 4+ messages in thread
From: Xiaoliang Yang @ 2025-07-23 10:06 UTC (permalink / raw)
To: davem, netdev, linux-kernel
Cc: kuba, n.zhandarovich, edumazet, pabeni, wojciech.drewek,
Arvid.Brodin, horms, lukma, m-karicheri2, xiaoliang.yang_1,
vladimir.oltean
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 <xiaoliang.yang_1@nxp.com>
---
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(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 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);
+/* 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 = netdev_priv(hsr_dev);
+
+ hsr_for_each_port(hsr, port) {
+ if (port->dev == dev) {
+ *type = 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) = {
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_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));
@@ -213,7 +213,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;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH net-next] net: hsr: create an API to get hsr port type
2025-07-23 10:06 [PATCH net-next] net: hsr: create an API to get hsr port type Xiaoliang Yang
@ 2025-07-23 10:06 ` Vladimir Oltean
2025-07-23 10:29 ` Xiaoliang Yang
0 siblings, 1 reply; 4+ messages in thread
From: Vladimir Oltean @ 2025-07-23 10:06 UTC (permalink / raw)
To: Xiaoliang Yang
Cc: davem, netdev, linux-kernel, kuba, n.zhandarovich, edumazet,
pabeni, wojciech.drewek, Arvid.Brodin, horms, lukma, m-karicheri2
Hi Xiaoliang,
On Wed, Jul 23, 2025 at 06:06:05PM +0800, Xiaoliang Yang wrote:
> 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 <xiaoliang.yang_1@nxp.com>
> ---
An API with no callers will never be accepted. You need to post the user
together with this change, for the maintainers to have the full picture
and see whether it is the best way to solve the problem.
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH net-next] net: hsr: create an API to get hsr port type
2025-07-23 10:06 ` Vladimir Oltean
@ 2025-07-23 10:29 ` Xiaoliang Yang
2025-07-23 10:37 ` Vladimir Oltean
0 siblings, 1 reply; 4+ messages in thread
From: Xiaoliang Yang @ 2025-07-23 10:29 UTC (permalink / raw)
To: Vladimir Oltean
Cc: davem@davemloft.net, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, 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
> -----Original Message-----
> From: Vladimir Oltean <vladimir.oltean@nxp.com>
> Sent: Wednesday, July 23, 2025 6:06 PM
> To: Xiaoliang Yang <xiaoliang.yang_1@nxp.com>
> Cc: davem@davemloft.net; netdev@vger.kernel.org; linux-
> kernel@vger.kernel.org; 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
> Subject: Re: [PATCH net-next] net: hsr: create an API to get hsr port type
>
> Hi Xiaoliang,
>
> On Wed, Jul 23, 2025 at 06:06:05PM +0800, Xiaoliang Yang wrote:
> > 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 <xiaoliang.yang_1@nxp.com>
> > ---
>
> An API with no callers will never be accepted. You need to post the user together
> with this change, for the maintainers to have the full picture and see whether it is
> the best way to solve the problem.
Thanks Vladimir, I want to use the API in dsa netc driver. The driver has not been upstream now. I see the HSR implemented on some devices only act as DANH. If the device act as RedBox, we don't know which port is interlink, which is slave_A or slave_B. I will re-send it as RFC patch, anyone can discuss how to handle this issue.
Regards,
Xiaoliang
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] net: hsr: create an API to get hsr port type
2025-07-23 10:29 ` Xiaoliang Yang
@ 2025-07-23 10:37 ` Vladimir Oltean
0 siblings, 0 replies; 4+ messages in thread
From: Vladimir Oltean @ 2025-07-23 10:37 UTC (permalink / raw)
To: Xiaoliang Yang
Cc: davem@davemloft.net, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, 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
On Wed, Jul 23, 2025 at 01:29:09PM +0300, Xiaoliang Yang wrote:
>
>
> > -----Original Message-----
> > From: Vladimir Oltean <vladimir.oltean@nxp.com>
> > Sent: Wednesday, July 23, 2025 6:06 PM
> > To: Xiaoliang Yang <xiaoliang.yang_1@nxp.com>
> > Cc: davem@davemloft.net; netdev@vger.kernel.org; linux-
> > kernel@vger.kernel.org; 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
> > Subject: Re: [PATCH net-next] net: hsr: create an API to get hsr port type
> >
> > Hi Xiaoliang,
> >
> > On Wed, Jul 23, 2025 at 06:06:05PM +0800, Xiaoliang Yang wrote:
> > > 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 <xiaoliang.yang_1@nxp.com>
> > > ---
> >
> > An API with no callers will never be accepted. You need to post the user together
> > with this change, for the maintainers to have the full picture and see whether it is
> > the best way to solve the problem.
>
> Thanks Vladimir, I want to use the API in dsa netc driver. The driver
> has not been upstream now. I see the HSR implemented on some devices
> only act as DANH. If the device act as RedBox, we don't know which
> port is interlink, which is slave_A or slave_B. I will re-send it as
> RFC patch, anyone can discuss how to handle this issue.
>
> Regards,
> Xiaoliang
It's not of much use if you still repost an API with no users with an
RFC tag.
I could equally propose populating struct netdev_notifier_changeupper_info :: upper_info
with the information you need (port type). Currently HSR calls netdev_upper_dev_link(),
which sets this argument to NULL.
But without seeing actual code which makes use of this, it is impossible
to know which one is preferable. So please don't send an empty RFC.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-07-23 10:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-23 10:06 [PATCH net-next] net: hsr: create an API to get hsr port type Xiaoliang Yang
2025-07-23 10:06 ` Vladimir Oltean
2025-07-23 10:29 ` Xiaoliang Yang
2025-07-23 10:37 ` Vladimir Oltean
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox