Lines Matching +full:master +full:- +full:stats
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright 2011-2014 Autronica Fire and Security AS
5 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
24 * --
25 * Or not - resetting the counter and bridging the frame would create a
47 if (!ether_addr_equal(eth_hdr->h_dest, in is_supervision_frame()
48 hsr->sup_multicast_addr)) in is_supervision_frame()
52 if (!(eth_hdr->h_proto == htons(ETH_P_PRP) || in is_supervision_frame()
53 eth_hdr->h_proto == htons(ETH_P_HSR))) in is_supervision_frame()
57 if (eth_hdr->h_proto == htons(ETH_P_HSR)) { /* Okay HSRv1. */ in is_supervision_frame()
63 if (hsr_V1_hdr->hsr.encap_proto != htons(ETH_P_PRP)) in is_supervision_frame()
66 hsr_sup_tag = &hsr_V1_hdr->hsr_sup; in is_supervision_frame()
73 &((struct hsrv0_ethhdr_sp *)skb_mac_header(skb))->hsr_sup; in is_supervision_frame()
76 if (hsr_sup_tag->tlv.HSR_TLV_type != HSR_TLV_ANNOUNCE && in is_supervision_frame()
77 hsr_sup_tag->tlv.HSR_TLV_type != HSR_TLV_LIFE_CHECK && in is_supervision_frame()
78 hsr_sup_tag->tlv.HSR_TLV_type != PRP_TLV_LIFE_CHECK_DD && in is_supervision_frame()
79 hsr_sup_tag->tlv.HSR_TLV_type != PRP_TLV_LIFE_CHECK_DA) in is_supervision_frame()
81 if (hsr_sup_tag->tlv.HSR_TLV_length != 12 && in is_supervision_frame()
82 hsr_sup_tag->tlv.HSR_TLV_length != sizeof(struct hsr_sup_payload)) in is_supervision_frame()
86 total_length += hsr_sup_tag->tlv.HSR_TLV_length; in is_supervision_frame()
90 hsr_sup_tlv = (struct hsr_sup_tlv *)skb->data; in is_supervision_frame()
96 if (hsr_sup_tlv->HSR_TLV_type == PRP_TLV_REDBOX_MAC) { in is_supervision_frame()
98 if (hsr_sup_tlv->HSR_TLV_length != sizeof(struct hsr_sup_payload)) in is_supervision_frame()
102 total_length += sizeof(struct hsr_sup_tlv) + hsr_sup_tlv->HSR_TLV_length; in is_supervision_frame()
108 hsr_sup_tlv = (struct hsr_sup_tlv *)skb->data; in is_supervision_frame()
113 if (hsr_sup_tlv->HSR_TLV_type == HSR_TLV_EOT && in is_supervision_frame()
114 hsr_sup_tlv->HSR_TLV_length != 0) in is_supervision_frame()
130 if (eth_hdr->h_proto == htons(ETH_P_HSR)) in is_proxy_supervision_frame()
139 payload = (struct hsr_sup_payload *)skb->data; in is_proxy_supervision_frame()
142 /* For RedBox (HSR-SAN) check if we have received the supervision in is_proxy_supervision_frame()
145 return hsr_is_node_in_db(&hsr->proxy_node_db, in is_proxy_supervision_frame()
146 payload->macaddress_A); in is_proxy_supervision_frame()
157 skb = __pskb_copy(skb_in, skb_headroom(skb_in) - HSR_HLEN, GFP_ATOMIC); in create_stripped_skb_hsr()
164 if (skb->ip_summed == CHECKSUM_PARTIAL) in create_stripped_skb_hsr()
165 skb->csum_start -= HSR_HLEN; in create_stripped_skb_hsr()
168 if (frame->is_vlan) in create_stripped_skb_hsr()
174 skb->protocol = eth_hdr(skb)->h_proto; in create_stripped_skb_hsr()
181 if (!frame->skb_std) { in hsr_get_untagged_frame()
182 if (frame->skb_hsr) in hsr_get_untagged_frame()
183 frame->skb_std = in hsr_get_untagged_frame()
184 create_stripped_skb_hsr(frame->skb_hsr, frame); in hsr_get_untagged_frame()
186 netdev_warn_once(port->dev, in hsr_get_untagged_frame()
189 if (!frame->skb_std) in hsr_get_untagged_frame()
193 return skb_clone(frame->skb_std, GFP_ATOMIC); in hsr_get_untagged_frame()
199 if (!frame->skb_std) { in prp_get_untagged_frame()
200 if (frame->skb_prp) { in prp_get_untagged_frame()
201 /* trim the skb by len - HSR_HLEN to exclude RCT */ in prp_get_untagged_frame()
202 skb_trim(frame->skb_prp, in prp_get_untagged_frame()
203 frame->skb_prp->len - HSR_HLEN); in prp_get_untagged_frame()
204 frame->skb_std = in prp_get_untagged_frame()
205 __pskb_copy(frame->skb_prp, in prp_get_untagged_frame()
206 skb_headroom(frame->skb_prp), in prp_get_untagged_frame()
211 __FILE__, __LINE__, port->dev->name); in prp_get_untagged_frame()
216 return skb_clone(frame->skb_std, GFP_ATOMIC); in prp_get_untagged_frame()
224 if (port->type == HSR_PT_SLAVE_A) in prp_set_lan_id()
230 lane_id |= port->hsr->net_id; in prp_set_lan_id()
246 if (frame->is_vlan) in prp_fill_rct()
253 lsdu_size = skb->len - 14; in prp_fill_rct()
254 if (frame->is_vlan) in prp_fill_rct()
255 lsdu_size -= 4; in prp_fill_rct()
258 trailer->sequence_nr = htons(frame->sequence_nr); in prp_fill_rct()
259 trailer->PRP_suffix = htons(ETH_P_PRP); in prp_fill_rct()
260 skb->protocol = eth_hdr(skb)->h_proto; in prp_fill_rct()
270 if (port->type == HSR_PT_SLAVE_A) in hsr_set_path_id()
275 set_hsr_tag_path(&hsr_ethhdr->hsr_tag, path_id); in hsr_set_path_id()
289 lsdu_size = skb->len - 14; in hsr_fill_tag()
290 if (frame->is_vlan) in hsr_fill_tag()
291 lsdu_size -= 4; in hsr_fill_tag()
296 set_hsr_tag_LSDU_size(&hsr_ethhdr->hsr_tag, lsdu_size); in hsr_fill_tag()
297 hsr_ethhdr->hsr_tag.sequence_nr = htons(frame->sequence_nr); in hsr_fill_tag()
298 hsr_ethhdr->hsr_tag.encap_proto = hsr_ethhdr->ethhdr.h_proto; in hsr_fill_tag()
299 hsr_ethhdr->ethhdr.h_proto = htons(proto_version ? in hsr_fill_tag()
301 skb->protocol = hsr_ethhdr->ethhdr.h_proto; in hsr_fill_tag()
316 if (frame->skb_hsr) { in hsr_create_tagged_frame()
318 (struct hsr_ethhdr *)skb_mac_header(frame->skb_hsr); in hsr_create_tagged_frame()
322 return skb_clone(frame->skb_hsr, GFP_ATOMIC); in hsr_create_tagged_frame()
323 } else if (port->dev->features & NETIF_F_HW_HSR_TAG_INS) { in hsr_create_tagged_frame()
324 return skb_clone(frame->skb_std, GFP_ATOMIC); in hsr_create_tagged_frame()
328 skb = __pskb_copy(frame->skb_std, in hsr_create_tagged_frame()
329 skb_headroom(frame->skb_std) + HSR_HLEN, GFP_ATOMIC); in hsr_create_tagged_frame()
334 if (skb->ip_summed == CHECKSUM_PARTIAL) in hsr_create_tagged_frame()
335 skb->csum_start += HSR_HLEN; in hsr_create_tagged_frame()
338 if (frame->is_vlan) in hsr_create_tagged_frame()
349 return hsr_fill_tag(skb, frame, port, port->hsr->prot_version); in hsr_create_tagged_frame()
357 if (frame->skb_prp) { in prp_create_tagged_frame()
358 struct prp_rct *trailer = skb_get_PRP_rct(frame->skb_prp); in prp_create_tagged_frame()
366 return skb_clone(frame->skb_prp, GFP_ATOMIC); in prp_create_tagged_frame()
367 } else if (port->dev->features & NETIF_F_HW_HSR_TAG_INS) { in prp_create_tagged_frame()
368 return skb_clone(frame->skb_std, GFP_ATOMIC); in prp_create_tagged_frame()
371 skb = skb_copy_expand(frame->skb_std, 0, in prp_create_tagged_frame()
372 skb_tailroom(frame->skb_std) + HSR_HLEN, in prp_create_tagged_frame()
383 was_multicast_frame = (skb->pkt_type == PACKET_MULTICAST); in hsr_deliver_master()
386 recv_len = skb->len; in hsr_deliver_master()
389 dev->stats.rx_dropped++; in hsr_deliver_master()
391 dev->stats.rx_packets++; in hsr_deliver_master()
392 dev->stats.rx_bytes += recv_len; in hsr_deliver_master()
394 dev->stats.multicast++; in hsr_deliver_master()
401 if (frame->port_rcv->type == HSR_PT_MASTER) { in hsr_xmit()
402 hsr_addr_subst_dest(frame->node_src, skb, port); in hsr_xmit()
404 /* Address substitution (IEC62439-3 pp 26, 50): replace mac in hsr_xmit()
407 ether_addr_copy(eth_hdr(skb)->h_source, port->dev->dev_addr); in hsr_xmit()
410 /* When HSR node is used as RedBox - the frame received from HSR ring in hsr_xmit()
414 if (port->type == HSR_PT_INTERLINK) in hsr_xmit()
415 ether_addr_copy(eth_hdr(skb)->h_source, in hsr_xmit()
416 port->hsr->macaddress_redbox); in hsr_xmit()
423 return ((frame->port_rcv->type == HSR_PT_SLAVE_A && in prp_drop_frame()
424 port->type == HSR_PT_SLAVE_B) || in prp_drop_frame()
425 (frame->port_rcv->type == HSR_PT_SLAVE_B && in prp_drop_frame()
426 port->type == HSR_PT_SLAVE_A)); in prp_drop_frame()
433 if (port->dev->features & NETIF_F_HW_HSR_FWD) in hsr_drop_frame()
440 if (frame->is_supervision && port->type == HSR_PT_INTERLINK) in hsr_drop_frame()
446 skb = frame->skb_hsr; in hsr_drop_frame()
448 is_unicast_ether_addr(eth_hdr(skb)->h_dest) && in hsr_drop_frame()
449 hsr_is_node_in_db(&port->hsr->proxy_node_db, in hsr_drop_frame()
450 eth_hdr(skb)->h_dest)) { in hsr_drop_frame()
457 if ((frame->port_rcv->type == HSR_PT_SLAVE_A || in hsr_drop_frame()
458 frame->port_rcv->type == HSR_PT_SLAVE_B) && in hsr_drop_frame()
459 port->type == HSR_PT_INTERLINK) { in hsr_drop_frame()
460 skb = frame->skb_hsr; in hsr_drop_frame()
461 if (skb && is_unicast_ether_addr(eth_hdr(skb)->h_dest) && in hsr_drop_frame()
462 hsr_is_node_in_db(&port->hsr->node_db, in hsr_drop_frame()
463 eth_hdr(skb)->h_dest)) { in hsr_drop_frame()
472 if ((port->type == HSR_PT_SLAVE_A || port->type == HSR_PT_SLAVE_B) && in hsr_drop_frame()
473 frame->port_rcv->type == HSR_PT_INTERLINK) { in hsr_drop_frame()
474 skb = frame->skb_std; in hsr_drop_frame()
475 if (skb && is_unicast_ether_addr(eth_hdr(skb)->h_dest) && in hsr_drop_frame()
476 hsr_is_node_in_db(&port->hsr->proxy_node_db, in hsr_drop_frame()
477 eth_hdr(skb)->h_dest)) { in hsr_drop_frame()
486 * - Back through the receiving device
487 * - If it's a HSR frame: through a device where it has passed before
488 * - if it's a PRP frame: through another PRP slave device (no bridge)
489 * - To the local HSR master only if the frame is directly addressed to it, or
490 * a non-supervision multicast or broadcast frame.
494 * tags if they're of the non-HSR type (but only after duplicate discard). The
495 * master device always strips HSR tags.
503 hsr_for_each_port(frame->port_rcv->hsr, port) { in hsr_forward_do()
504 struct hsr_priv *hsr = port->hsr; in hsr_forward_do()
506 if (port == frame->port_rcv) in hsr_forward_do()
510 if (port->type == HSR_PT_MASTER && !frame->is_local_dest) in hsr_forward_do()
513 /* Deliver frames directly addressed to us to master only */ in hsr_forward_do()
514 if (port->type != HSR_PT_MASTER && frame->is_local_exclusive) in hsr_forward_do()
520 if ((port->dev->features & NETIF_F_HW_HSR_DUP) && sent) in hsr_forward_do()
526 if (!frame->is_from_san && in hsr_forward_do()
527 hsr_register_frame_out(port, frame->node_src, in hsr_forward_do()
528 frame->sequence_nr)) in hsr_forward_do()
531 if (frame->is_supervision && port->type == HSR_PT_MASTER && in hsr_forward_do()
532 !frame->is_proxy_supervision) { in hsr_forward_do()
540 if (hsr->proto_ops->drop_frame && in hsr_forward_do()
541 hsr->proto_ops->drop_frame(frame, port)) in hsr_forward_do()
544 if (port->type == HSR_PT_SLAVE_A || in hsr_forward_do()
545 port->type == HSR_PT_SLAVE_B) in hsr_forward_do()
546 skb = hsr->proto_ops->create_tagged_frame(frame, port); in hsr_forward_do()
548 skb = hsr->proto_ops->get_untagged_frame(frame, port); in hsr_forward_do()
551 frame->port_rcv->dev->stats.rx_dropped++; in hsr_forward_do()
555 skb->dev = port->dev; in hsr_forward_do()
556 if (port->type == HSR_PT_MASTER) { in hsr_forward_do()
557 hsr_deliver_master(skb, port->dev, frame->node_src); in hsr_forward_do()
560 if (port->type == HSR_PT_SLAVE_A || in hsr_forward_do()
561 port->type == HSR_PT_SLAVE_B) in hsr_forward_do()
570 if (hsr_addr_is_self(hsr, eth_hdr(skb)->h_dest)) { in check_local_dest()
571 frame->is_local_exclusive = true; in check_local_dest()
572 skb->pkt_type = PACKET_HOST; in check_local_dest()
574 frame->is_local_exclusive = false; in check_local_dest()
577 if (skb->pkt_type == PACKET_HOST || in check_local_dest()
578 skb->pkt_type == PACKET_MULTICAST || in check_local_dest()
579 skb->pkt_type == PACKET_BROADCAST) { in check_local_dest()
580 frame->is_local_dest = true; in check_local_dest()
582 frame->is_local_dest = false; in check_local_dest()
589 struct hsr_port *port = frame->port_rcv; in handle_std_frame()
590 struct hsr_priv *hsr = port->hsr; in handle_std_frame()
592 frame->skb_hsr = NULL; in handle_std_frame()
593 frame->skb_prp = NULL; in handle_std_frame()
594 frame->skb_std = skb; in handle_std_frame()
596 if (port->type != HSR_PT_MASTER) in handle_std_frame()
597 frame->is_from_san = true; in handle_std_frame()
599 if (port->type == HSR_PT_MASTER || in handle_std_frame()
600 port->type == HSR_PT_INTERLINK) { in handle_std_frame()
601 /* Sequence nr for the master/interlink node */ in handle_std_frame()
602 lockdep_assert_held(&hsr->seqnr_lock); in handle_std_frame()
603 frame->sequence_nr = hsr->sequence_nr; in handle_std_frame()
604 hsr->sequence_nr++; in handle_std_frame()
611 struct hsr_port *port = frame->port_rcv; in hsr_fill_frame_info()
612 struct hsr_priv *hsr = port->hsr; in hsr_fill_frame_info()
615 if ((!hsr->prot_version && proto == htons(ETH_P_PRP)) || in hsr_fill_frame_info()
618 if (skb->mac_len < sizeof(struct hsr_ethhdr)) in hsr_fill_frame_info()
619 return -EINVAL; in hsr_fill_frame_info()
621 /* HSR tagged frame :- Data or Supervision */ in hsr_fill_frame_info()
622 frame->skb_std = NULL; in hsr_fill_frame_info()
623 frame->skb_prp = NULL; in hsr_fill_frame_info()
624 frame->skb_hsr = skb; in hsr_fill_frame_info()
625 frame->sequence_nr = hsr_get_skb_sequence_nr(skb); in hsr_fill_frame_info()
629 /* Standard frame or PRP from master port */ in hsr_fill_frame_info()
642 prp_check_lsdu_size(skb, rct, frame->is_supervision)) { in prp_fill_frame_info()
643 frame->skb_hsr = NULL; in prp_fill_frame_info()
644 frame->skb_std = NULL; in prp_fill_frame_info()
645 frame->skb_prp = skb; in prp_fill_frame_info()
646 frame->sequence_nr = prp_get_skb_sequence_nr(rct); in prp_fill_frame_info()
657 struct hsr_priv *hsr = port->hsr; in fill_frame_info()
665 if (skb->mac_len < sizeof(struct ethhdr)) in fill_frame_info()
666 return -EINVAL; in fill_frame_info()
669 frame->is_supervision = is_supervision_frame(port->hsr, skb); in fill_frame_info()
670 if (frame->is_supervision && hsr->redbox) in fill_frame_info()
671 frame->is_proxy_supervision = in fill_frame_info()
672 is_proxy_supervision_frame(port->hsr, skb); in fill_frame_info()
674 n_db = &hsr->node_db; in fill_frame_info()
675 if (port->type == HSR_PT_INTERLINK) in fill_frame_info()
676 n_db = &hsr->proxy_node_db; in fill_frame_info()
678 frame->node_src = hsr_get_node(port, n_db, skb, in fill_frame_info()
679 frame->is_supervision, port->type); in fill_frame_info()
680 if (!frame->node_src) in fill_frame_info()
681 return -1; /* Unknown node and !is_supervision, or no mem */ in fill_frame_info()
684 frame->is_vlan = false; in fill_frame_info()
685 proto = ethhdr->h_proto; in fill_frame_info()
688 frame->is_vlan = true; in fill_frame_info()
690 if (frame->is_vlan) { in fill_frame_info()
692 proto = vlan_hdr->vlanhdr.h_vlan_encapsulated_proto; in fill_frame_info()
694 netdev_warn_once(skb->dev, "VLAN not yet supported"); in fill_frame_info()
695 return -EINVAL; in fill_frame_info()
698 frame->is_from_san = false; in fill_frame_info()
699 frame->port_rcv = port; in fill_frame_info()
700 ret = hsr->proto_ops->fill_frame_info(proto, skb, frame); in fill_frame_info()
704 check_local_dest(port->hsr, skb, frame); in fill_frame_info()
721 /* Gets called for ingress frames as well as egress from master port. in hsr_forward_skb()
722 * So check and increment stats for master port only here. in hsr_forward_skb()
724 if (port->type == HSR_PT_MASTER || port->type == HSR_PT_INTERLINK) { in hsr_forward_skb()
725 port->dev->stats.tx_packets++; in hsr_forward_skb()
726 port->dev->stats.tx_bytes += skb->len; in hsr_forward_skb()
736 port->dev->stats.tx_dropped++; in hsr_forward_skb()