• Home
  • Raw
  • Download

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
24 /* seq_nr_after(a, b) - return true if a is after (higher in sequence than) b,
32 if ((int)b - a == 32768) in seq_nr_after()
35 return (((s16)(b - a)) < 0); in seq_nr_after()
45 node = list_first_or_null_rcu(&hsr->self_node_db, struct hsr_node, in hsr_addr_is_self()
52 if (ether_addr_equal(addr, node->macaddress_A)) in hsr_addr_is_self()
54 if (ether_addr_equal(addr, node->macaddress_B)) in hsr_addr_is_self()
68 if (ether_addr_equal(node->macaddress_A, addr)) in find_node_by_addr_A()
82 struct list_head *self_node_db = &hsr->self_node_db; in hsr_create_self_node()
87 return -ENOMEM; in hsr_create_self_node()
89 ether_addr_copy(node->macaddress_A, addr_a); in hsr_create_self_node()
90 ether_addr_copy(node->macaddress_B, addr_b); in hsr_create_self_node()
92 spin_lock_bh(&hsr->list_lock); in hsr_create_self_node()
96 list_replace_rcu(&oldnode->mac_list, &node->mac_list); in hsr_create_self_node()
97 spin_unlock_bh(&hsr->list_lock); in hsr_create_self_node()
100 list_add_tail_rcu(&node->mac_list, self_node_db); in hsr_create_self_node()
101 spin_unlock_bh(&hsr->list_lock); in hsr_create_self_node()
109 struct list_head *self_node_db = &hsr->self_node_db; in hsr_del_self_node()
112 spin_lock_bh(&hsr->list_lock); in hsr_del_self_node()
115 list_del_rcu(&node->mac_list); in hsr_del_self_node()
118 spin_unlock_bh(&hsr->list_lock); in hsr_del_self_node()
135 node->san_a = true; in prp_handle_san_frame()
140 node->san_b = true; in prp_handle_san_frame()
161 ether_addr_copy(new_node->macaddress_A, addr); in hsr_add_node()
162 spin_lock_init(&new_node->seq_out_lock); in hsr_add_node()
169 new_node->time_in[i] = now; in hsr_add_node()
170 new_node->time_out[i] = now; in hsr_add_node()
173 new_node->seq_out[i] = seq_out; in hsr_add_node()
175 if (san && hsr->proto_ops->handle_san_frame) in hsr_add_node()
176 hsr->proto_ops->handle_san_frame(san, rx_port, new_node); in hsr_add_node()
178 spin_lock_bh(&hsr->list_lock); in hsr_add_node()
180 lockdep_is_held(&hsr->list_lock)) { in hsr_add_node()
181 if (ether_addr_equal(node->macaddress_A, addr)) in hsr_add_node()
183 if (ether_addr_equal(node->macaddress_B, addr)) in hsr_add_node()
186 list_add_tail_rcu(&new_node->mac_list, node_db); in hsr_add_node()
187 spin_unlock_bh(&hsr->list_lock); in hsr_add_node()
190 spin_unlock_bh(&hsr->list_lock); in hsr_add_node()
200 node->san_a = false; in prp_update_san_info()
201 node->san_b = false; in prp_update_san_info()
210 struct hsr_priv *hsr = port->hsr; in hsr_get_node()
223 if (ether_addr_equal(node->macaddress_A, ethhdr->h_source)) { in hsr_get_node()
224 if (hsr->proto_ops->update_san_info) in hsr_get_node()
225 hsr->proto_ops->update_san_info(node, is_sup); in hsr_get_node()
228 if (ether_addr_equal(node->macaddress_B, ethhdr->h_source)) { in hsr_get_node()
229 if (hsr->proto_ops->update_san_info) in hsr_get_node()
230 hsr->proto_ops->update_san_info(node, is_sup); in hsr_get_node()
238 if (ethhdr->h_proto == htons(ETH_P_PRP) || in hsr_get_node()
239 ethhdr->h_proto == htons(ETH_P_HSR)) { in hsr_get_node()
243 seq_out = hsr_get_skb_sequence_nr(skb) - 1; in hsr_get_node()
255 return hsr_add_node(hsr, node_db, ethhdr->h_source, seq_out, in hsr_get_node()
265 struct hsr_node *node_curr = frame->node_src; in hsr_handle_sup_frame()
266 struct hsr_port *port_rcv = frame->port_rcv; in hsr_handle_sup_frame()
267 struct hsr_priv *hsr = port_rcv->hsr; in hsr_handle_sup_frame()
275 /* Here either frame->skb_hsr or frame->skb_prp should be in hsr_handle_sup_frame()
279 if (frame->skb_hsr) in hsr_handle_sup_frame()
280 skb = frame->skb_hsr; in hsr_handle_sup_frame()
281 else if (frame->skb_prp) in hsr_handle_sup_frame()
282 skb = frame->skb_prp; in hsr_handle_sup_frame()
292 if (ethhdr->h_proto == htons(ETH_P_HSR)) in hsr_handle_sup_frame()
298 hsr_sp = (struct hsr_sup_payload *)skb->data; in hsr_handle_sup_frame()
301 node_db = &port_rcv->hsr->node_db; in hsr_handle_sup_frame()
302 node_real = find_node_by_addr_A(node_db, hsr_sp->macaddress_A); in hsr_handle_sup_frame()
305 node_real = hsr_add_node(hsr, node_db, hsr_sp->macaddress_A, in hsr_handle_sup_frame()
306 HSR_SEQNR_START - 1, true, in hsr_handle_sup_frame()
307 port_rcv->type); in hsr_handle_sup_frame()
314 ether_addr_copy(node_real->macaddress_B, ethhdr->h_source); in hsr_handle_sup_frame()
315 spin_lock_bh(&node_real->seq_out_lock); in hsr_handle_sup_frame()
317 if (!node_curr->time_in_stale[i] && in hsr_handle_sup_frame()
318 time_after(node_curr->time_in[i], node_real->time_in[i])) { in hsr_handle_sup_frame()
319 node_real->time_in[i] = node_curr->time_in[i]; in hsr_handle_sup_frame()
320 node_real->time_in_stale[i] = in hsr_handle_sup_frame()
321 node_curr->time_in_stale[i]; in hsr_handle_sup_frame()
323 if (seq_nr_after(node_curr->seq_out[i], node_real->seq_out[i])) in hsr_handle_sup_frame()
324 node_real->seq_out[i] = node_curr->seq_out[i]; in hsr_handle_sup_frame()
326 spin_unlock_bh(&node_real->seq_out_lock); in hsr_handle_sup_frame()
327 node_real->addr_B_port = port_rcv->type; in hsr_handle_sup_frame()
329 spin_lock_bh(&hsr->list_lock); in hsr_handle_sup_frame()
330 list_del_rcu(&node_curr->mac_list); in hsr_handle_sup_frame()
331 spin_unlock_bh(&hsr->list_lock); in hsr_handle_sup_frame()
336 if (ethhdr->h_proto == htons(ETH_P_HSR)) in hsr_handle_sup_frame()
355 memcpy(&eth_hdr(skb)->h_source, node->macaddress_A, ETH_ALEN); in hsr_addr_subst_source()
364 * This is needed to keep the packets flowing through switches that learn on
377 if (!is_unicast_ether_addr(eth_hdr(skb)->h_dest)) in hsr_addr_subst_dest()
380 node_dst = find_node_by_addr_A(&port->hsr->node_db, in hsr_addr_subst_dest()
381 eth_hdr(skb)->h_dest); in hsr_addr_subst_dest()
383 if (port->hsr->prot_version != PRP_V1 && net_ratelimit()) in hsr_addr_subst_dest()
384 netdev_err(skb->dev, "%s: Unknown node\n", __func__); in hsr_addr_subst_dest()
387 if (port->type != node_dst->addr_B_port) in hsr_addr_subst_dest()
390 if (is_valid_ether_addr(node_dst->macaddress_B)) in hsr_addr_subst_dest()
391 ether_addr_copy(eth_hdr(skb)->h_dest, node_dst->macaddress_B); in hsr_addr_subst_dest()
399 * re-register and resume communications. in hsr_register_frame_in()
401 if (seq_nr_before(sequence_nr, node->seq_out[port->type])) in hsr_register_frame_in()
404 node->time_in[port->type] = jiffies; in hsr_register_frame_in()
405 node->time_in_stale[port->type] = false; in hsr_register_frame_in()
409 * ethhdr->h_source address and skb->mac_header set.
419 spin_lock_bh(&node->seq_out_lock); in hsr_register_frame_out()
420 if (seq_nr_before_or_eq(sequence_nr, node->seq_out[port->type]) && in hsr_register_frame_out()
421 time_is_after_jiffies(node->time_out[port->type] + in hsr_register_frame_out()
423 spin_unlock_bh(&node->seq_out_lock); in hsr_register_frame_out()
427 node->time_out[port->type] = jiffies; in hsr_register_frame_out()
428 node->seq_out[port->type] = sequence_nr; in hsr_register_frame_out()
429 spin_unlock_bh(&node->seq_out_lock); in hsr_register_frame_out()
436 if (node->time_in_stale[HSR_PT_SLAVE_A]) in get_late_port()
438 if (node->time_in_stale[HSR_PT_SLAVE_B]) in get_late_port()
441 if (time_after(node->time_in[HSR_PT_SLAVE_B], in get_late_port()
442 node->time_in[HSR_PT_SLAVE_A] + in get_late_port()
445 if (time_after(node->time_in[HSR_PT_SLAVE_A], in get_late_port()
446 node->time_in[HSR_PT_SLAVE_B] + in get_late_port()
465 spin_lock_bh(&hsr->list_lock); in hsr_prune_nodes()
466 list_for_each_entry_safe(node, tmp, &hsr->node_db, mac_list) { in hsr_prune_nodes()
472 if (hsr_addr_is_self(hsr, node->macaddress_A)) in hsr_prune_nodes()
476 time_a = node->time_in[HSR_PT_SLAVE_A]; in hsr_prune_nodes()
477 time_b = node->time_in[HSR_PT_SLAVE_B]; in hsr_prune_nodes()
479 /* Check for timestamps old enough to risk wrap-around */ in hsr_prune_nodes()
481 node->time_in_stale[HSR_PT_SLAVE_A] = true; in hsr_prune_nodes()
483 node->time_in_stale[HSR_PT_SLAVE_B] = true; in hsr_prune_nodes()
490 if (node->time_in_stale[HSR_PT_SLAVE_A] || in hsr_prune_nodes()
491 (!node->time_in_stale[HSR_PT_SLAVE_B] && in hsr_prune_nodes()
501 hsr_nl_ringerror(hsr, node->macaddress_A, port); in hsr_prune_nodes()
508 hsr_nl_nodedown(hsr, node->macaddress_A); in hsr_prune_nodes()
509 list_del_rcu(&node->mac_list); in hsr_prune_nodes()
510 /* Note that we need to free this entry later: */ in hsr_prune_nodes()
514 spin_unlock_bh(&hsr->list_lock); in hsr_prune_nodes()
517 mod_timer(&hsr->prune_timer, in hsr_prune_nodes()
527 node = list_first_or_null_rcu(&hsr->node_db, in hsr_get_next_node()
530 ether_addr_copy(addr, node->macaddress_A); in hsr_get_next_node()
535 list_for_each_entry_continue_rcu(node, &hsr->node_db, mac_list) { in hsr_get_next_node()
536 ether_addr_copy(addr, node->macaddress_A); in hsr_get_next_node()
556 node = find_node_by_addr_A(&hsr->node_db, addr); in hsr_get_node_data()
558 return -ENOENT; in hsr_get_node_data()
560 ether_addr_copy(addr_b, node->macaddress_B); in hsr_get_node_data()
562 tdiff = jiffies - node->time_in[HSR_PT_SLAVE_A]; in hsr_get_node_data()
563 if (node->time_in_stale[HSR_PT_SLAVE_A]) in hsr_get_node_data()
572 tdiff = jiffies - node->time_in[HSR_PT_SLAVE_B]; in hsr_get_node_data()
573 if (node->time_in_stale[HSR_PT_SLAVE_B]) in hsr_get_node_data()
583 *if1_seq = node->seq_out[HSR_PT_SLAVE_B]; in hsr_get_node_data()
584 *if2_seq = node->seq_out[HSR_PT_SLAVE_A]; in hsr_get_node_data()
586 if (node->addr_B_port != HSR_PT_NONE) { in hsr_get_node_data()
587 port = hsr_port_get_hsr(hsr, node->addr_B_port); in hsr_get_node_data()
588 *addr_b_ifindex = port->dev->ifindex; in hsr_get_node_data()
590 *addr_b_ifindex = -1; in hsr_get_node_data()