Skip to content

Commit 9c10dd8

Browse files
danish-tiPaolo Abeni
authored andcommitted
net: hsr: Create and export hsr_get_port_ndev()
Create an API to get the net_device to the slave port of HSR device. The API will take hsr net_device and enum hsr_port_type for which we want the net_device as arguments. This API can be used by client drivers who support HSR and want to get the net_devcie of slave ports from the hsr device. Export this API for the same. This API needs the enum hsr_port_type to be accessible by the drivers using hsr. Move the enum hsr_port_type from net/hsr/hsr_main.h to include/linux/if_hsr.h for the same. Signed-off-by: MD Danish Anwar <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 04508d2 commit 9c10dd8

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

include/linux/if_hsr.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ enum hsr_version {
1313
PRP_V1,
1414
};
1515

16+
enum hsr_port_type {
17+
HSR_PT_NONE = 0, /* Must be 0, used by framereg */
18+
HSR_PT_SLAVE_A,
19+
HSR_PT_SLAVE_B,
20+
HSR_PT_INTERLINK,
21+
HSR_PT_MASTER,
22+
HSR_PT_PORTS, /* This must be the last item in the enum */
23+
};
24+
1625
/* HSR Tag.
1726
* As defined in IEC-62439-3:2010, the HSR tag is really { ethertype = 0x88FB,
1827
* path, LSDU_size, sequence Nr }. But we let eth_header() create { h_dest,
@@ -32,6 +41,8 @@ struct hsr_tag {
3241
#if IS_ENABLED(CONFIG_HSR)
3342
extern bool is_hsr_master(struct net_device *dev);
3443
extern int hsr_get_version(struct net_device *dev, enum hsr_version *ver);
44+
struct net_device *hsr_get_port_ndev(struct net_device *ndev,
45+
enum hsr_port_type pt);
3546
#else
3647
static inline bool is_hsr_master(struct net_device *dev)
3748
{
@@ -42,6 +53,12 @@ static inline int hsr_get_version(struct net_device *dev,
4253
{
4354
return -EINVAL;
4455
}
56+
57+
static inline struct net_device *hsr_get_port_ndev(struct net_device *ndev,
58+
enum hsr_port_type pt)
59+
{
60+
return ERR_PTR(-EINVAL);
61+
}
4562
#endif /* CONFIG_HSR */
4663

4764
#endif /*_LINUX_IF_HSR_H_*/

net/hsr/hsr_device.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,19 @@ bool is_hsr_master(struct net_device *dev)
663663
}
664664
EXPORT_SYMBOL(is_hsr_master);
665665

666+
struct net_device *hsr_get_port_ndev(struct net_device *ndev,
667+
enum hsr_port_type pt)
668+
{
669+
struct hsr_priv *hsr = netdev_priv(ndev);
670+
struct hsr_port *port;
671+
672+
hsr_for_each_port(hsr, port)
673+
if (port->type == pt)
674+
return port->dev;
675+
return NULL;
676+
}
677+
EXPORT_SYMBOL(hsr_get_port_ndev);
678+
666679
/* Default multicast address for HSR Supervision frames */
667680
static const unsigned char def_multicast_addr[ETH_ALEN] __aligned(2) = {
668681
0x01, 0x15, 0x4e, 0x00, 0x01, 0x00

net/hsr/hsr_main.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,6 @@ struct hsrv1_ethhdr_sp {
121121
struct hsr_sup_tag hsr_sup;
122122
} __packed;
123123

124-
enum hsr_port_type {
125-
HSR_PT_NONE = 0, /* Must be 0, used by framereg */
126-
HSR_PT_SLAVE_A,
127-
HSR_PT_SLAVE_B,
128-
HSR_PT_INTERLINK,
129-
HSR_PT_MASTER,
130-
HSR_PT_PORTS, /* This must be the last item in the enum */
131-
};
132-
133124
/* PRP Redunancy Control Trailor (RCT).
134125
* As defined in IEC-62439-4:2012, the PRP RCT is really { sequence Nr,
135126
* Lan indentifier (LanId), LSDU_size and PRP_suffix = 0x88FB }.

0 commit comments

Comments
 (0)