Lines Matching +full:free +full:- +full:flowing
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
22 /* seq_nr_after(a, b) - return true if a is after (higher in sequence than) b,
30 if ((int)b - a == 32768) in seq_nr_after()
33 return (((s16)(b - a)) < 0); in seq_nr_after()
45 sn = rcu_dereference(hsr->self_node); in hsr_addr_is_self()
51 if (ether_addr_equal(addr, sn->macaddress_A) || in hsr_addr_is_self()
52 ether_addr_equal(addr, sn->macaddress_B)) in hsr_addr_is_self()
67 if (ether_addr_equal(node->macaddress_A, addr)) in find_node_by_addr_A()
85 return -ENOMEM; in hsr_create_self_node()
87 ether_addr_copy(sn->macaddress_A, addr_a); in hsr_create_self_node()
88 ether_addr_copy(sn->macaddress_B, addr_b); in hsr_create_self_node()
90 spin_lock_bh(&hsr->list_lock); in hsr_create_self_node()
91 old = rcu_replace_pointer(hsr->self_node, sn, in hsr_create_self_node()
92 lockdep_is_held(&hsr->list_lock)); in hsr_create_self_node()
93 spin_unlock_bh(&hsr->list_lock); in hsr_create_self_node()
104 spin_lock_bh(&hsr->list_lock); in hsr_del_self_node()
105 old = rcu_replace_pointer(hsr->self_node, NULL, in hsr_del_self_node()
106 lockdep_is_held(&hsr->list_lock)); in hsr_del_self_node()
107 spin_unlock_bh(&hsr->list_lock); in hsr_del_self_node()
126 node->san_a = true; in prp_handle_san_frame()
131 node->san_b = true; in prp_handle_san_frame()
152 ether_addr_copy(new_node->macaddress_A, addr); in hsr_add_node()
153 spin_lock_init(&new_node->seq_out_lock); in hsr_add_node()
160 new_node->time_in[i] = now; in hsr_add_node()
161 new_node->time_out[i] = now; in hsr_add_node()
164 new_node->seq_out[i] = seq_out; in hsr_add_node()
166 if (san && hsr->proto_ops->handle_san_frame) in hsr_add_node()
167 hsr->proto_ops->handle_san_frame(san, rx_port, new_node); in hsr_add_node()
169 spin_lock_bh(&hsr->list_lock); in hsr_add_node()
171 lockdep_is_held(&hsr->list_lock)) { in hsr_add_node()
172 if (ether_addr_equal(node->macaddress_A, addr)) in hsr_add_node()
174 if (ether_addr_equal(node->macaddress_B, addr)) in hsr_add_node()
177 list_add_tail_rcu(&new_node->mac_list, node_db); in hsr_add_node()
178 spin_unlock_bh(&hsr->list_lock); in hsr_add_node()
181 spin_unlock_bh(&hsr->list_lock); in hsr_add_node()
191 node->san_a = false; in prp_update_san_info()
192 node->san_b = false; in prp_update_san_info()
201 struct hsr_priv *hsr = port->hsr; in hsr_get_node()
214 if (ether_addr_equal(node->macaddress_A, ethhdr->h_source)) { in hsr_get_node()
215 if (hsr->proto_ops->update_san_info) in hsr_get_node()
216 hsr->proto_ops->update_san_info(node, is_sup); in hsr_get_node()
219 if (ether_addr_equal(node->macaddress_B, ethhdr->h_source)) { in hsr_get_node()
220 if (hsr->proto_ops->update_san_info) in hsr_get_node()
221 hsr->proto_ops->update_san_info(node, is_sup); in hsr_get_node()
229 if (ethhdr->h_proto == htons(ETH_P_PRP) || in hsr_get_node()
230 ethhdr->h_proto == htons(ETH_P_HSR)) { in hsr_get_node()
234 seq_out = hsr_get_skb_sequence_nr(skb) - 1; in hsr_get_node()
246 return hsr_add_node(hsr, node_db, ethhdr->h_source, seq_out, in hsr_get_node()
256 struct hsr_node *node_curr = frame->node_src; in hsr_handle_sup_frame()
257 struct hsr_port *port_rcv = frame->port_rcv; in hsr_handle_sup_frame()
258 struct hsr_priv *hsr = port_rcv->hsr; in hsr_handle_sup_frame()
269 /* Here either frame->skb_hsr or frame->skb_prp should be in hsr_handle_sup_frame()
273 if (frame->skb_hsr) in hsr_handle_sup_frame()
274 skb = frame->skb_hsr; in hsr_handle_sup_frame()
275 else if (frame->skb_prp) in hsr_handle_sup_frame()
276 skb = frame->skb_prp; in hsr_handle_sup_frame()
277 else if (frame->skb_std) in hsr_handle_sup_frame()
278 skb = frame->skb_std; in hsr_handle_sup_frame()
290 if (ethhdr->h_proto == htons(ETH_P_HSR)) { in hsr_handle_sup_frame()
302 hsr_sp = (struct hsr_sup_payload *)skb->data; in hsr_handle_sup_frame()
305 node_db = &port_rcv->hsr->node_db; in hsr_handle_sup_frame()
306 node_real = find_node_by_addr_A(node_db, hsr_sp->macaddress_A); in hsr_handle_sup_frame()
309 node_real = hsr_add_node(hsr, node_db, hsr_sp->macaddress_A, in hsr_handle_sup_frame()
310 HSR_SEQNR_START - 1, true, in hsr_handle_sup_frame()
311 port_rcv->type); in hsr_handle_sup_frame()
324 hsr_sup_tlv = (struct hsr_sup_tlv *)skb->data; in hsr_handle_sup_frame()
326 if (hsr_sup_tlv->HSR_TLV_type == PRP_TLV_REDBOX_MAC) { in hsr_handle_sup_frame()
331 if (hsr_sup_tlv->HSR_TLV_length != 6) in hsr_handle_sup_frame()
340 hsr_sp = (struct hsr_sup_payload *)skb->data; in hsr_handle_sup_frame()
343 if (!ether_addr_equal(node_real->macaddress_A, hsr_sp->macaddress_A)) { in hsr_handle_sup_frame()
349 ether_addr_copy(node_real->macaddress_B, ethhdr->h_source); in hsr_handle_sup_frame()
350 spin_lock_bh(&node_real->seq_out_lock); in hsr_handle_sup_frame()
352 if (!node_curr->time_in_stale[i] && in hsr_handle_sup_frame()
353 time_after(node_curr->time_in[i], node_real->time_in[i])) { in hsr_handle_sup_frame()
354 node_real->time_in[i] = node_curr->time_in[i]; in hsr_handle_sup_frame()
355 node_real->time_in_stale[i] = in hsr_handle_sup_frame()
356 node_curr->time_in_stale[i]; in hsr_handle_sup_frame()
358 if (seq_nr_after(node_curr->seq_out[i], node_real->seq_out[i])) in hsr_handle_sup_frame()
359 node_real->seq_out[i] = node_curr->seq_out[i]; in hsr_handle_sup_frame()
361 spin_unlock_bh(&node_real->seq_out_lock); in hsr_handle_sup_frame()
362 node_real->addr_B_port = port_rcv->type; in hsr_handle_sup_frame()
364 spin_lock_bh(&hsr->list_lock); in hsr_handle_sup_frame()
365 if (!node_curr->removed) { in hsr_handle_sup_frame()
366 list_del_rcu(&node_curr->mac_list); in hsr_handle_sup_frame()
367 node_curr->removed = true; in hsr_handle_sup_frame()
370 spin_unlock_bh(&hsr->list_lock); in hsr_handle_sup_frame()
390 memcpy(ð_hdr(skb)->h_source, node->macaddress_A, ETH_ALEN); in hsr_addr_subst_source()
399 * This is needed to keep the packets flowing through switches that learn on
412 if (!is_unicast_ether_addr(eth_hdr(skb)->h_dest)) in hsr_addr_subst_dest()
415 node_dst = find_node_by_addr_A(&port->hsr->node_db, in hsr_addr_subst_dest()
416 eth_hdr(skb)->h_dest); in hsr_addr_subst_dest()
418 if (port->hsr->prot_version != PRP_V1 && net_ratelimit()) in hsr_addr_subst_dest()
419 netdev_err(skb->dev, "%s: Unknown node\n", __func__); in hsr_addr_subst_dest()
422 if (port->type != node_dst->addr_B_port) in hsr_addr_subst_dest()
425 if (is_valid_ether_addr(node_dst->macaddress_B)) in hsr_addr_subst_dest()
426 ether_addr_copy(eth_hdr(skb)->h_dest, node_dst->macaddress_B); in hsr_addr_subst_dest()
434 * re-register and resume communications. in hsr_register_frame_in()
436 if (!(port->dev->features & NETIF_F_HW_HSR_TAG_RM) && in hsr_register_frame_in()
437 seq_nr_before(sequence_nr, node->seq_out[port->type])) in hsr_register_frame_in()
440 node->time_in[port->type] = jiffies; in hsr_register_frame_in()
441 node->time_in_stale[port->type] = false; in hsr_register_frame_in()
445 * ethhdr->h_source address and skb->mac_header set.
455 spin_lock_bh(&node->seq_out_lock); in hsr_register_frame_out()
456 if (seq_nr_before_or_eq(sequence_nr, node->seq_out[port->type]) && in hsr_register_frame_out()
457 time_is_after_jiffies(node->time_out[port->type] + in hsr_register_frame_out()
459 spin_unlock_bh(&node->seq_out_lock); in hsr_register_frame_out()
463 node->time_out[port->type] = jiffies; in hsr_register_frame_out()
464 node->seq_out[port->type] = sequence_nr; in hsr_register_frame_out()
465 spin_unlock_bh(&node->seq_out_lock); in hsr_register_frame_out()
472 if (node->time_in_stale[HSR_PT_SLAVE_A]) in get_late_port()
474 if (node->time_in_stale[HSR_PT_SLAVE_B]) in get_late_port()
477 if (time_after(node->time_in[HSR_PT_SLAVE_B], in get_late_port()
478 node->time_in[HSR_PT_SLAVE_A] + in get_late_port()
481 if (time_after(node->time_in[HSR_PT_SLAVE_A], in get_late_port()
482 node->time_in[HSR_PT_SLAVE_B] + in get_late_port()
501 spin_lock_bh(&hsr->list_lock); in hsr_prune_nodes()
502 list_for_each_entry_safe(node, tmp, &hsr->node_db, mac_list) { in hsr_prune_nodes()
508 if (hsr_addr_is_self(hsr, node->macaddress_A)) in hsr_prune_nodes()
512 time_a = node->time_in[HSR_PT_SLAVE_A]; in hsr_prune_nodes()
513 time_b = node->time_in[HSR_PT_SLAVE_B]; in hsr_prune_nodes()
515 /* Check for timestamps old enough to risk wrap-around */ in hsr_prune_nodes()
517 node->time_in_stale[HSR_PT_SLAVE_A] = true; in hsr_prune_nodes()
519 node->time_in_stale[HSR_PT_SLAVE_B] = true; in hsr_prune_nodes()
526 if (node->time_in_stale[HSR_PT_SLAVE_A] || in hsr_prune_nodes()
527 (!node->time_in_stale[HSR_PT_SLAVE_B] && in hsr_prune_nodes()
537 hsr_nl_ringerror(hsr, node->macaddress_A, port); in hsr_prune_nodes()
544 hsr_nl_nodedown(hsr, node->macaddress_A); in hsr_prune_nodes()
545 if (!node->removed) { in hsr_prune_nodes()
546 list_del_rcu(&node->mac_list); in hsr_prune_nodes()
547 node->removed = true; in hsr_prune_nodes()
548 /* Note that we need to free this entry later: */ in hsr_prune_nodes()
553 spin_unlock_bh(&hsr->list_lock); in hsr_prune_nodes()
556 mod_timer(&hsr->prune_timer, in hsr_prune_nodes()
566 node = list_first_or_null_rcu(&hsr->node_db, in hsr_get_next_node()
569 ether_addr_copy(addr, node->macaddress_A); in hsr_get_next_node()
574 list_for_each_entry_continue_rcu(node, &hsr->node_db, mac_list) { in hsr_get_next_node()
575 ether_addr_copy(addr, node->macaddress_A); in hsr_get_next_node()
595 node = find_node_by_addr_A(&hsr->node_db, addr); in hsr_get_node_data()
597 return -ENOENT; in hsr_get_node_data()
599 ether_addr_copy(addr_b, node->macaddress_B); in hsr_get_node_data()
601 tdiff = jiffies - node->time_in[HSR_PT_SLAVE_A]; in hsr_get_node_data()
602 if (node->time_in_stale[HSR_PT_SLAVE_A]) in hsr_get_node_data()
611 tdiff = jiffies - node->time_in[HSR_PT_SLAVE_B]; in hsr_get_node_data()
612 if (node->time_in_stale[HSR_PT_SLAVE_B]) in hsr_get_node_data()
622 *if1_seq = node->seq_out[HSR_PT_SLAVE_B]; in hsr_get_node_data()
623 *if2_seq = node->seq_out[HSR_PT_SLAVE_A]; in hsr_get_node_data()
625 if (node->addr_B_port != HSR_PT_NONE) { in hsr_get_node_data()
626 port = hsr_port_get_hsr(hsr, node->addr_B_port); in hsr_get_node_data()
627 *addr_b_ifindex = port->dev->ifindex; in hsr_get_node_data()
629 *addr_b_ifindex = -1; in hsr_get_node_data()