Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Murali Karicheri and committed by
David S. Miller
fa4dc895 c643ff03

+55 -28
+4 -1
net/hsr/hsr_device.c
··· 440 440 441 441 static struct hsr_proto_ops hsr_ops = { 442 442 .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, 443 446 }; 444 447 445 - struct hsr_proto_ops prp_ops = { 448 + static struct hsr_proto_ops prp_ops = { 446 449 .send_sv_frame = send_prp_supervision_frame, 447 450 }; 448 451
+37 -26
net/hsr/hsr_forward.c
··· 116 116 return skb; 117 117 } 118 118 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) 121 121 { 122 122 if (!frame->skb_std) 123 123 frame->skb_std = create_stripped_skb(frame->skb_hsr, frame); ··· 192 192 /* If the original frame was an HSR tagged frame, just clone it to be sent 193 193 * unchanged. Otherwise, create a private frame especially tagged for 'port'. 194 194 */ 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) 197 197 { 198 198 if (frame->skb_hsr) 199 199 return skb_clone(frame->skb_hsr, GFP_ATOMIC); ··· 257 257 struct sk_buff *skb; 258 258 259 259 hsr_for_each_port(frame->port_rcv->hsr, port) { 260 + struct hsr_priv *hsr = port->hsr; 260 261 /* Don't send frame back the way it came */ 261 262 if (port == frame->port_rcv) 262 263 continue; ··· 283 282 } 284 283 285 284 if (port->type != HSR_PT_MASTER) 286 - skb = frame_get_tagged_skb(frame, port); 285 + skb = hsr->proto_ops->create_tagged_frame(frame, port); 287 286 else 288 - skb = frame_get_stripped_skb(frame, port); 287 + skb = hsr->proto_ops->get_untagged_frame(frame, port); 288 + 289 289 if (!skb) { 290 290 /* FIXME: Record the dropped frame? */ 291 291 continue; ··· 319 317 } 320 318 } 321 319 322 - static int hsr_fill_frame_info(struct hsr_frame_info *frame, 323 - struct sk_buff *skb, struct hsr_port *port) 320 + void hsr_fill_frame_info(__be16 proto, struct sk_buff *skb, 321 + struct hsr_frame_info *frame) 324 322 { 325 - struct ethhdr *ethhdr; 323 + struct hsr_priv *hsr = frame->port_rcv->hsr; 326 324 unsigned long irqflags; 325 + 326 + if (proto == htons(ETH_P_PRP) || proto == htons(ETH_P_HSR)) { 327 + frame->skb_std = NULL; 328 + frame->skb_hsr = skb; 329 + frame->sequence_nr = hsr_get_skb_sequence_nr(skb); 330 + } else { 331 + frame->skb_std = skb; 332 + frame->skb_hsr = NULL; 333 + /* Sequence nr for the master node */ 334 + spin_lock_irqsave(&hsr->seqnr_lock, irqflags); 335 + frame->sequence_nr = hsr->sequence_nr; 336 + hsr->sequence_nr++; 337 + spin_unlock_irqrestore(&hsr->seqnr_lock, irqflags); 338 + } 339 + } 340 + 341 + static int fill_frame_info(struct hsr_frame_info *frame, 342 + struct sk_buff *skb, struct hsr_port *port) 343 + { 344 + struct hsr_priv *hsr = port->hsr; 345 + struct ethhdr *ethhdr; 346 + __be16 proto; 327 347 328 348 frame->is_supervision = is_supervision_frame(port->hsr, skb); 329 349 frame->node_src = hsr_get_node(port, skb, frame->is_supervision); ··· 359 335 /* FIXME: */ 360 336 netdev_warn_once(skb->dev, "VLAN not yet supported"); 361 337 } 362 - if (ethhdr->h_proto == htons(ETH_P_PRP) || 363 - ethhdr->h_proto == htons(ETH_P_HSR)) { 364 - frame->skb_std = NULL; 365 - frame->skb_hsr = skb; 366 - frame->sequence_nr = hsr_get_skb_sequence_nr(skb); 367 - } else { 368 - frame->skb_std = skb; 369 - frame->skb_hsr = NULL; 370 - /* Sequence nr for the master node */ 371 - spin_lock_irqsave(&port->hsr->seqnr_lock, irqflags); 372 - frame->sequence_nr = port->hsr->sequence_nr; 373 - port->hsr->sequence_nr++; 374 - spin_unlock_irqrestore(&port->hsr->seqnr_lock, irqflags); 375 - } 376 - 338 + proto = ethhdr->h_proto; 377 339 frame->port_rcv = port; 378 - check_local_dest(port->hsr, skb, frame); 340 + hsr->proto_ops->fill_frame_info(proto, skb, frame); 341 + check_local_dest(hsr, skb, frame); 379 342 380 343 return 0; 381 344 } ··· 378 367 goto out_drop; 379 368 } 380 369 381 - if (hsr_fill_frame_info(&frame, skb, port) < 0) 370 + if (fill_frame_info(&frame, skb, port) < 0) 382 371 goto out_drop; 383 372 hsr_register_frame_in(frame.node_src, port, frame.sequence_nr); 384 373 hsr_forward_do(&frame);
+6 -1
net/hsr/hsr_forward.h
··· 14 14 #include "hsr_main.h" 15 15 16 16 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); 18 23 #endif /* __HSR_FORWARD_H */
+8
net/hsr/hsr_main.h
··· 162 162 PRP_V1, 163 163 }; 164 164 165 + struct hsr_frame_info; 166 + 165 167 struct hsr_proto_ops { 166 168 /* format and send supervision frame */ 167 169 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); 168 176 }; 169 177 170 178 struct hsr_priv {