Skip to content

Commit a0244e7

Browse files
Xiaoliang Yangkuba-moo
authored andcommitted
net: hsr: create an API to get hsr port type
Since the introduction of HSR_PT_INTERLINK in commit 5055ccc ("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 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> Reviewed-by: Łukasz Majewski <lukma@nabladev.com> Link: https://patch.msgid.link/20251130131657.65080-3-vladimir.oltean@nxp.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 3b87e60 commit a0244e7

3 files changed

Lines changed: 33 additions & 3 deletions

File tree

include/linux/if_hsr.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ extern bool is_hsr_master(struct net_device *dev);
4343
extern int hsr_get_version(struct net_device *dev, enum hsr_version *ver);
4444
struct net_device *hsr_get_port_ndev(struct net_device *ndev,
4545
enum hsr_port_type pt);
46+
int hsr_get_port_type(struct net_device *hsr_dev, struct net_device *dev,
47+
enum hsr_port_type *type);
4648
#else
4749
static inline bool is_hsr_master(struct net_device *dev)
4850
{
@@ -59,6 +61,13 @@ static inline struct net_device *hsr_get_port_ndev(struct net_device *ndev,
5961
{
6062
return ERR_PTR(-EINVAL);
6163
}
64+
65+
static inline int hsr_get_port_type(struct net_device *hsr_dev,
66+
struct net_device *dev,
67+
enum hsr_port_type *type)
68+
{
69+
return -EINVAL;
70+
}
6271
#endif /* CONFIG_HSR */
6372

6473
#endif /*_LINUX_IF_HSR_H_*/

net/hsr/hsr_device.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,26 @@ struct net_device *hsr_get_port_ndev(struct net_device *ndev,
690690
}
691691
EXPORT_SYMBOL(hsr_get_port_ndev);
692692

693+
int hsr_get_port_type(struct net_device *hsr_dev, struct net_device *dev,
694+
enum hsr_port_type *type)
695+
{
696+
struct hsr_priv *hsr = netdev_priv(hsr_dev);
697+
struct hsr_port *port;
698+
699+
rcu_read_lock();
700+
hsr_for_each_port(hsr, port) {
701+
if (port->dev == dev) {
702+
*type = port->type;
703+
rcu_read_unlock();
704+
return 0;
705+
}
706+
}
707+
rcu_read_unlock();
708+
709+
return -EINVAL;
710+
}
711+
EXPORT_SYMBOL(hsr_get_port_type);
712+
693713
/* Default multicast address for HSR Supervision frames */
694714
static const unsigned char def_multicast_addr[ETH_ALEN] __aligned(2) = {
695715
0x01, 0x15, 0x4e, 0x00, 0x01, 0x00

net/hsr/hsr_slave.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,22 +207,23 @@ int hsr_add_port(struct hsr_priv *hsr, struct net_device *dev,
207207
port->type = type;
208208
ether_addr_copy(port->original_macaddress, dev->dev_addr);
209209

210+
list_add_tail_rcu(&port->port_list, &hsr->ports);
211+
210212
if (type != HSR_PT_MASTER) {
211213
res = hsr_portdev_setup(hsr, dev, port, extack);
212214
if (res)
213215
goto fail_dev_setup;
214216
}
215217

216-
list_add_tail_rcu(&port->port_list, &hsr->ports);
217-
218218
master = hsr_port_get_hsr(hsr, HSR_PT_MASTER);
219219
netdev_update_features(master->dev);
220220
dev_set_mtu(master->dev, hsr_get_max_mtu(hsr));
221221

222222
return 0;
223223

224224
fail_dev_setup:
225-
kfree(port);
225+
list_del_rcu(&port->port_list);
226+
kfree_rcu(port, rcu);
226227
return res;
227228
}
228229

0 commit comments

Comments
 (0)