Skip to content

Commit fa4dc89

Browse files
Murali Karicheridavem330
authored andcommitted
net: hsr: define and use proto_ops ptrs to handle hsr specific frames
As a preparatory patch to introduce PRP, refactor the code specific to handling HSR frames into separate functions and call them through proto_ops function pointers. Signed-off-by: Murali Karicheri <m-karicheri2@ti.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c643ff0 commit fa4dc89

4 files changed

Lines changed: 55 additions & 28 deletions

File tree

‎net/hsr/hsr_device.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,12 @@ static struct device_type hsr_type = {
440440

441441
static struct hsr_proto_ops hsr_ops = {
442442
.send_sv_frame = send_hsr_supervision_frame,
443+
.create_tagged_frame = hsr_create_tagged_frame,
444+
.get_untagged_frame = hsr_get_untagged_frame,
445+
.fill_frame_info = hsr_fill_frame_info,
443446
};
444447

445-
struct hsr_proto_ops prp_ops = {
448+
static struct hsr_proto_ops prp_ops = {
446449
.send_sv_frame = send_prp_supervision_frame,
447450
};
448451

‎net/hsr/hsr_forward.c‎

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ static struct sk_buff *create_stripped_skb(struct sk_buff *skb_in,
116116
return skb;
117117
}
118118

119-
static struct sk_buff *frame_get_stripped_skb(struct hsr_frame_info *frame,
120-
struct hsr_port *port)
119+
struct sk_buff *hsr_get_untagged_frame(struct hsr_frame_info *frame,
120+
struct hsr_port *port)
121121
{
122122
if (!frame->skb_std)
123123
frame->skb_std = create_stripped_skb(frame->skb_hsr, frame);
@@ -192,8 +192,8 @@ static struct sk_buff *create_tagged_skb(struct sk_buff *skb_o,
192192
/* If the original frame was an HSR tagged frame, just clone it to be sent
193193
* unchanged. Otherwise, create a private frame especially tagged for 'port'.
194194
*/
195-
static struct sk_buff *frame_get_tagged_skb(struct hsr_frame_info *frame,
196-
struct hsr_port *port)
195+
struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,
196+
struct hsr_port *port)
197197
{
198198
if (frame->skb_hsr)
199199
return skb_clone(frame->skb_hsr, GFP_ATOMIC);
@@ -257,6 +257,7 @@ static void hsr_forward_do(struct hsr_frame_info *frame)
257257
struct sk_buff *skb;
258258

259259
hsr_for_each_port(frame->port_rcv->hsr, port) {
260+
struct hsr_priv *hsr = port->hsr;
260261
/* Don't send frame back the way it came */
261262
if (port == frame->port_rcv)
262263
continue;
@@ -282,9 +283,10 @@ static void hsr_forward_do(struct hsr_frame_info *frame)
282283
}
283284

284285
if (port->type != HSR_PT_MASTER)
285-
skb = frame_get_tagged_skb(frame, port);
286+
skb = hsr->proto_ops->create_tagged_frame(frame, port);
286287
else
287-
skb = frame_get_stripped_skb(frame, port);
288+
skb = hsr->proto_ops->get_untagged_frame(frame, port);
289+
288290
if (!skb) {
289291
/* FIXME: Record the dropped frame? */
290292
continue;
@@ -317,12 +319,34 @@ static void check_local_dest(struct hsr_priv *hsr, struct sk_buff *skb,
317319
}
318320
}
319321

320-
static int hsr_fill_frame_info(struct hsr_frame_info *frame,
321-
struct sk_buff *skb, struct hsr_port *port)
322+
void hsr_fill_frame_info(__be16 proto, struct sk_buff *skb,
323+
struct hsr_frame_info *frame)
322324
{
323-
struct ethhdr *ethhdr;
325+
struct hsr_priv *hsr = frame->port_rcv->hsr;
324326
unsigned long irqflags;
325327

328+
if (proto == htons(ETH_P_PRP) || proto == htons(ETH_P_HSR)) {
329+
frame->skb_std = NULL;
330+
frame->skb_hsr = skb;
331+
frame->sequence_nr = hsr_get_skb_sequence_nr(skb);
332+
} else {
333+
frame->skb_std = skb;
334+
frame->skb_hsr = NULL;
335+
/* Sequence nr for the master node */
336+
spin_lock_irqsave(&hsr->seqnr_lock, irqflags);
337+
frame->sequence_nr = hsr->sequence_nr;
338+
hsr->sequence_nr++;
339+
spin_unlock_irqrestore(&hsr->seqnr_lock, irqflags);
340+
}
341+
}
342+
343+
static int fill_frame_info(struct hsr_frame_info *frame,
344+
struct sk_buff *skb, struct hsr_port *port)
345+
{
346+
struct hsr_priv *hsr = port->hsr;
347+
struct ethhdr *ethhdr;
348+
__be16 proto;
349+
326350
frame->is_supervision = is_supervision_frame(port->hsr, skb);
327351
frame->node_src = hsr_get_node(port, skb, frame->is_supervision);
328352
if (!frame->node_src)
@@ -335,23 +359,10 @@ static int hsr_fill_frame_info(struct hsr_frame_info *frame,
335359
/* FIXME: */
336360
netdev_warn_once(skb->dev, "VLAN not yet supported");
337361
}
338-
if (ethhdr->h_proto == htons(ETH_P_PRP) ||
339-
ethhdr->h_proto == htons(ETH_P_HSR)) {
340-
frame->skb_std = NULL;
341-
frame->skb_hsr = skb;
342-
frame->sequence_nr = hsr_get_skb_sequence_nr(skb);
343-
} else {
344-
frame->skb_std = skb;
345-
frame->skb_hsr = NULL;
346-
/* Sequence nr for the master node */
347-
spin_lock_irqsave(&port->hsr->seqnr_lock, irqflags);
348-
frame->sequence_nr = port->hsr->sequence_nr;
349-
port->hsr->sequence_nr++;
350-
spin_unlock_irqrestore(&port->hsr->seqnr_lock, irqflags);
351-
}
352-
362+
proto = ethhdr->h_proto;
353363
frame->port_rcv = port;
354-
check_local_dest(port->hsr, skb, frame);
364+
hsr->proto_ops->fill_frame_info(proto, skb, frame);
365+
check_local_dest(hsr, skb, frame);
355366

356367
return 0;
357368
}
@@ -367,7 +378,7 @@ void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port)
367378
goto out_drop;
368379
}
369380

370-
if (hsr_fill_frame_info(&frame, skb, port) < 0)
381+
if (fill_frame_info(&frame, skb, port) < 0)
371382
goto out_drop;
372383
hsr_register_frame_in(frame.node_src, port, frame.sequence_nr);
373384
hsr_forward_do(&frame);

‎net/hsr/hsr_forward.h‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,10 @@
1414
#include "hsr_main.h"
1515

1616
void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port);
17-
17+
struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,
18+
struct hsr_port *port);
19+
struct sk_buff *hsr_get_untagged_frame(struct hsr_frame_info *frame,
20+
struct hsr_port *port);
21+
void hsr_fill_frame_info(__be16 proto, struct sk_buff *skb,
22+
struct hsr_frame_info *frame);
1823
#endif /* __HSR_FORWARD_H */

‎net/hsr/hsr_main.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,17 @@ enum hsr_version {
162162
PRP_V1,
163163
};
164164

165+
struct hsr_frame_info;
166+
165167
struct hsr_proto_ops {
166168
/* format and send supervision frame */
167169
void (*send_sv_frame)(struct hsr_port *port, unsigned long *interval);
170+
struct sk_buff * (*get_untagged_frame)(struct hsr_frame_info *frame,
171+
struct hsr_port *port);
172+
struct sk_buff * (*create_tagged_frame)(struct hsr_frame_info *frame,
173+
struct hsr_port *port);
174+
void (*fill_frame_info)(__be16 proto, struct sk_buff *skb,
175+
struct hsr_frame_info *frame);
168176
};
169177

170178
struct hsr_priv {

0 commit comments

Comments
 (0)