Skip to content

Commit c643ff0

Browse files
Murali Karicheridavem330
authored andcommitted
net: prp: add supervision frame generation utility function
Add support for generation of PRP supervision frames. For PRP, supervision frame format is similar to HSR version 0, but have a PRP Redundancy Control Trailer (RCT) added and uses a different message type, PRP_TLV_LIFE_CHECK_DD. Also update is_supervision_frame() to include the new message type used for PRP supervision frame. Signed-off-by: Murali Karicheri <m-karicheri2@ti.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 28e458e commit c643ff0

3 files changed

Lines changed: 88 additions & 2 deletions

File tree

‎net/hsr/hsr_device.c‎

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ static struct sk_buff *hsr_init_skb(struct hsr_port *master, u16 proto)
238238

239239
hlen = LL_RESERVED_SPACE(master->dev);
240240
tlen = master->dev->needed_tailroom;
241+
/* skb size is same for PRP/HSR frames, only difference
242+
* being, for PRP it is a trailer and for HSR it is a
243+
* header
244+
*/
241245
skb = dev_alloc_skb(sizeof(struct hsr_tag) +
242246
sizeof(struct hsr_sup_tag) +
243247
sizeof(struct hsr_sup_payload) + hlen + tlen);
@@ -336,6 +340,55 @@ static void send_hsr_supervision_frame(struct hsr_port *master,
336340
return;
337341
}
338342

343+
static void send_prp_supervision_frame(struct hsr_port *master,
344+
unsigned long *interval)
345+
{
346+
struct hsr_priv *hsr = master->hsr;
347+
struct hsr_sup_payload *hsr_sp;
348+
struct hsr_sup_tag *hsr_stag;
349+
unsigned long irqflags;
350+
struct sk_buff *skb;
351+
struct prp_rct *rct;
352+
u8 *tail;
353+
354+
skb = hsr_init_skb(master, ETH_P_PRP);
355+
if (!skb) {
356+
WARN_ONCE(1, "PRP: Could not send supervision frame\n");
357+
return;
358+
}
359+
360+
*interval = msecs_to_jiffies(HSR_LIFE_CHECK_INTERVAL);
361+
hsr_stag = skb_put(skb, sizeof(struct hsr_sup_tag));
362+
set_hsr_stag_path(hsr_stag, (hsr->prot_version ? 0x0 : 0xf));
363+
set_hsr_stag_HSR_ver(hsr_stag, (hsr->prot_version ? 1 : 0));
364+
365+
/* From HSRv1 on we have separate supervision sequence numbers. */
366+
spin_lock_irqsave(&master->hsr->seqnr_lock, irqflags);
367+
hsr_stag->sequence_nr = htons(hsr->sup_sequence_nr);
368+
hsr->sup_sequence_nr++;
369+
hsr_stag->HSR_TLV_type = PRP_TLV_LIFE_CHECK_DD;
370+
hsr_stag->HSR_TLV_length = sizeof(struct hsr_sup_payload);
371+
372+
/* Payload: MacAddressA */
373+
hsr_sp = skb_put(skb, sizeof(struct hsr_sup_payload));
374+
ether_addr_copy(hsr_sp->macaddress_A, master->dev->dev_addr);
375+
376+
if (skb_put_padto(skb, ETH_ZLEN + HSR_HLEN)) {
377+
spin_unlock_irqrestore(&master->hsr->seqnr_lock, irqflags);
378+
return;
379+
}
380+
381+
tail = skb_tail_pointer(skb) - HSR_HLEN;
382+
rct = (struct prp_rct *)tail;
383+
rct->PRP_suffix = htons(ETH_P_PRP);
384+
set_prp_LSDU_size(rct, HSR_V1_SUP_LSDUSIZE);
385+
rct->sequence_nr = htons(hsr->sequence_nr);
386+
hsr->sequence_nr++;
387+
spin_unlock_irqrestore(&master->hsr->seqnr_lock, irqflags);
388+
389+
hsr_forward_skb(skb, master);
390+
}
391+
339392
/* Announce (supervision frame) timer function
340393
*/
341394
static void hsr_announce(struct timer_list *t)
@@ -389,6 +442,10 @@ static struct hsr_proto_ops hsr_ops = {
389442
.send_sv_frame = send_hsr_supervision_frame,
390443
};
391444

445+
struct hsr_proto_ops prp_ops = {
446+
.send_sv_frame = send_prp_supervision_frame,
447+
};
448+
392449
void hsr_dev_setup(struct net_device *dev)
393450
{
394451
eth_hw_addr_random(dev);
@@ -452,7 +509,12 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],
452509
if (protocol_version == PRP_V1)
453510
return -EPROTONOSUPPORT;
454511

455-
hsr->proto_ops = &hsr_ops;
512+
/* initialize protocol specific functions */
513+
if (protocol_version == PRP_V1)
514+
hsr->proto_ops = &prp_ops;
515+
else
516+
hsr->proto_ops = &hsr_ops;
517+
456518
/* Make sure we recognize frames from ourselves in hsr_rcv() */
457519
res = hsr_create_self_node(hsr, hsr_dev->dev_addr,
458520
slave[1]->dev_addr);

‎net/hsr/hsr_forward.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ static bool is_supervision_frame(struct hsr_priv *hsr, struct sk_buff *skb)
7676
}
7777

7878
if (hsr_sup_tag->HSR_TLV_type != HSR_TLV_ANNOUNCE &&
79-
hsr_sup_tag->HSR_TLV_type != HSR_TLV_LIFE_CHECK)
79+
hsr_sup_tag->HSR_TLV_type != HSR_TLV_LIFE_CHECK &&
80+
hsr_sup_tag->HSR_TLV_type != PRP_TLV_LIFE_CHECK_DD &&
81+
hsr_sup_tag->HSR_TLV_type != PRP_TLV_LIFE_CHECK_DA)
8082
return false;
8183
if (hsr_sup_tag->HSR_TLV_length != 12 &&
8284
hsr_sup_tag->HSR_TLV_length != sizeof(struct hsr_sup_payload))

‎net/hsr/hsr_main.h‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535

3636
#define HSR_TLV_ANNOUNCE 22
3737
#define HSR_TLV_LIFE_CHECK 23
38+
/* PRP V1 life check for Duplicate discard */
39+
#define PRP_TLV_LIFE_CHECK_DD 20
40+
/* PRP V1 life check for Duplicate Accept */
41+
#define PRP_TLV_LIFE_CHECK_DA 21
3842

3943
/* HSR Tag.
4044
* As defined in IEC-62439-3:2010, the HSR tag is really { ethertype = 0x88FB,
@@ -126,6 +130,24 @@ enum hsr_port_type {
126130
HSR_PT_PORTS, /* This must be the last item in the enum */
127131
};
128132

133+
/* PRP Redunancy Control Trailor (RCT).
134+
* As defined in IEC-62439-4:2012, the PRP RCT is really { sequence Nr,
135+
* Lan indentifier (LanId), LSDU_size and PRP_suffix = 0x88FB }.
136+
*
137+
* Field names as defined in the IEC:2012 standard for PRP.
138+
*/
139+
struct prp_rct {
140+
__be16 sequence_nr;
141+
__be16 lan_id_and_LSDU_size;
142+
__be16 PRP_suffix;
143+
} __packed;
144+
145+
static inline void set_prp_LSDU_size(struct prp_rct *rct, u16 LSDU_size)
146+
{
147+
rct->lan_id_and_LSDU_size = htons((ntohs(rct->lan_id_and_LSDU_size) &
148+
0xF000) | (LSDU_size & 0x0FFF));
149+
}
150+
129151
struct hsr_port {
130152
struct list_head port_list;
131153
struct net_device *dev;

0 commit comments

Comments
 (0)