Skip to content

Commit 28e458e

Browse files
Murali Karicheridavem330
authored andcommitted
net: hsr: introduce protocol specific function pointers
As a preparatory patch to introduce support for PRP protocol, add a protocol ops ptr in the private hsr structure to hold function pointers as some of the functions at protocol level packet handling is different for HSR vs PRP. It is expected that PRP will add its of set of functions for protocol handling. Modify existing hsr_announce() function to call proto_ops->send_sv_frame() to send supervision frame for HSR. This is expected to be different for PRP. So introduce a ops function ptr, send_sv_frame() for the same and initialize it to send_hsr_supervsion_frame(). Modify hsr_announce() to call proto_ops->send_sv_frame(). Signed-off-by: Murali Karicheri <m-karicheri2@ti.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 121c33b commit 28e458e

2 files changed

Lines changed: 45 additions & 31 deletions

File tree

‎net/hsr/hsr_device.c‎

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static const struct header_ops hsr_header_ops = {
230230
.parse = eth_header_parse,
231231
};
232232

233-
static struct sk_buff *hsr_init_skb(struct hsr_port *master, u8 hsr_ver)
233+
static struct sk_buff *hsr_init_skb(struct hsr_port *master, u16 proto)
234234
{
235235
struct hsr_priv *hsr = master->hsr;
236236
struct sk_buff *skb;
@@ -247,10 +247,10 @@ static struct sk_buff *hsr_init_skb(struct hsr_port *master, u8 hsr_ver)
247247

248248
skb_reserve(skb, hlen);
249249
skb->dev = master->dev;
250-
skb->protocol = htons(hsr_ver ? ETH_P_HSR : ETH_P_PRP);
250+
skb->protocol = htons(proto);
251251
skb->priority = TC_PRIO_CONTROL;
252252

253-
if (dev_hard_header(skb, skb->dev, (hsr_ver ? ETH_P_HSR : ETH_P_PRP),
253+
if (dev_hard_header(skb, skb->dev, proto,
254254
hsr->sup_multicast_addr,
255255
skb->dev->dev_addr, skb->len) <= 0)
256256
goto out;
@@ -267,47 +267,62 @@ static struct sk_buff *hsr_init_skb(struct hsr_port *master, u8 hsr_ver)
267267
}
268268

269269
static void send_hsr_supervision_frame(struct hsr_port *master,
270-
u8 type, u8 hsr_ver)
270+
unsigned long *interval)
271271
{
272+
struct hsr_priv *hsr = master->hsr;
273+
__u8 type = HSR_TLV_LIFE_CHECK;
274+
struct hsr_tag *hsr_tag = NULL;
272275
struct hsr_sup_payload *hsr_sp;
273276
struct hsr_sup_tag *hsr_stag;
274-
struct hsr_tag *hsr_tag;
275277
unsigned long irqflags;
276278
struct sk_buff *skb;
279+
u16 proto;
280+
281+
*interval = msecs_to_jiffies(HSR_LIFE_CHECK_INTERVAL);
282+
if (hsr->announce_count < 3 && hsr->prot_version == 0) {
283+
type = HSR_TLV_ANNOUNCE;
284+
*interval = msecs_to_jiffies(HSR_ANNOUNCE_INTERVAL);
285+
hsr->announce_count++;
286+
}
287+
288+
if (!hsr->prot_version)
289+
proto = ETH_P_PRP;
290+
else
291+
proto = ETH_P_HSR;
277292

278-
skb = hsr_init_skb(master, hsr_ver);
293+
skb = hsr_init_skb(master, proto);
279294
if (!skb) {
280295
WARN_ONCE(1, "HSR: Could not send supervision frame\n");
281296
return;
282297
}
283298

284-
if (hsr_ver > 0) {
299+
if (hsr->prot_version > 0) {
285300
hsr_tag = skb_put(skb, sizeof(struct hsr_tag));
286301
hsr_tag->encap_proto = htons(ETH_P_PRP);
287302
set_hsr_tag_LSDU_size(hsr_tag, HSR_V1_SUP_LSDUSIZE);
288303
}
289304

290305
hsr_stag = skb_put(skb, sizeof(struct hsr_sup_tag));
291-
set_hsr_stag_path(hsr_stag, (hsr_ver ? 0x0 : 0xf));
292-
set_hsr_stag_HSR_ver(hsr_stag, hsr_ver);
306+
set_hsr_stag_path(hsr_stag, (hsr->prot_version ? 0x0 : 0xf));
307+
set_hsr_stag_HSR_ver(hsr_stag, hsr->prot_version);
293308

294309
/* From HSRv1 on we have separate supervision sequence numbers. */
295310
spin_lock_irqsave(&master->hsr->seqnr_lock, irqflags);
296-
if (hsr_ver > 0) {
297-
hsr_stag->sequence_nr = htons(master->hsr->sup_sequence_nr);
298-
hsr_tag->sequence_nr = htons(master->hsr->sequence_nr);
299-
master->hsr->sup_sequence_nr++;
300-
master->hsr->sequence_nr++;
311+
if (hsr->prot_version > 0) {
312+
hsr_stag->sequence_nr = htons(hsr->sup_sequence_nr);
313+
hsr->sup_sequence_nr++;
314+
hsr_tag->sequence_nr = htons(hsr->sequence_nr);
315+
hsr->sequence_nr++;
301316
} else {
302-
hsr_stag->sequence_nr = htons(master->hsr->sequence_nr);
303-
master->hsr->sequence_nr++;
317+
hsr_stag->sequence_nr = htons(hsr->sequence_nr);
318+
hsr->sequence_nr++;
304319
}
305320
spin_unlock_irqrestore(&master->hsr->seqnr_lock, irqflags);
306321

307322
hsr_stag->HSR_TLV_type = type;
308323
/* TODO: Why 12 in HSRv0? */
309-
hsr_stag->HSR_TLV_length =
310-
hsr_ver ? sizeof(struct hsr_sup_payload) : 12;
324+
hsr_stag->HSR_TLV_length = hsr->prot_version ?
325+
sizeof(struct hsr_sup_payload) : 12;
311326

312327
/* Payload: MacAddressA */
313328
hsr_sp = skb_put(skb, sizeof(struct hsr_sup_payload));
@@ -333,19 +348,7 @@ static void hsr_announce(struct timer_list *t)
333348

334349
rcu_read_lock();
335350
master = hsr_port_get_hsr(hsr, HSR_PT_MASTER);
336-
337-
if (hsr->announce_count < 3 && hsr->prot_version == 0) {
338-
send_hsr_supervision_frame(master, HSR_TLV_ANNOUNCE,
339-
hsr->prot_version);
340-
hsr->announce_count++;
341-
342-
interval = msecs_to_jiffies(HSR_ANNOUNCE_INTERVAL);
343-
} else {
344-
send_hsr_supervision_frame(master, HSR_TLV_LIFE_CHECK,
345-
hsr->prot_version);
346-
347-
interval = msecs_to_jiffies(HSR_LIFE_CHECK_INTERVAL);
348-
}
351+
hsr->proto_ops->send_sv_frame(master, &interval);
349352

350353
if (is_admin_up(master->dev))
351354
mod_timer(&hsr->announce_timer, jiffies + interval);
@@ -382,6 +385,10 @@ static struct device_type hsr_type = {
382385
.name = "hsr",
383386
};
384387

388+
static struct hsr_proto_ops hsr_ops = {
389+
.send_sv_frame = send_hsr_supervision_frame,
390+
};
391+
385392
void hsr_dev_setup(struct net_device *dev)
386393
{
387394
eth_hw_addr_random(dev);
@@ -445,6 +452,7 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],
445452
if (protocol_version == PRP_V1)
446453
return -EPROTONOSUPPORT;
447454

455+
hsr->proto_ops = &hsr_ops;
448456
/* Make sure we recognize frames from ourselves in hsr_rcv() */
449457
res = hsr_create_self_node(hsr, hsr_dev->dev_addr,
450458
slave[1]->dev_addr);

‎net/hsr/hsr_main.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ enum hsr_version {
140140
PRP_V1,
141141
};
142142

143+
struct hsr_proto_ops {
144+
/* format and send supervision frame */
145+
void (*send_sv_frame)(struct hsr_port *port, unsigned long *interval);
146+
};
147+
143148
struct hsr_priv {
144149
struct rcu_head rcu_head;
145150
struct list_head ports;
@@ -153,6 +158,7 @@ struct hsr_priv {
153158
enum hsr_version prot_version; /* Indicate if HSRv0, HSRv1 or PRPv1 */
154159
spinlock_t seqnr_lock; /* locking for sequence_nr */
155160
spinlock_t list_lock; /* locking for node list */
161+
struct hsr_proto_ops *proto_ops;
156162
unsigned char sup_multicast_addr[ETH_ALEN];
157163
#ifdef CONFIG_DEBUG_FS
158164
struct dentry *node_tbl_root;

0 commit comments

Comments
 (0)