Lines Matching +full:lock +full:- +full:state
1 // SPDX-License-Identifier: GPL-2.0-or-later
29 void br_set_state(struct net_bridge_port *p, unsigned int state) in br_set_state() argument
32 .orig_dev = p->dev, in br_set_state()
35 .u.stp_state = state, in br_set_state()
39 /* Don't change the state of the ports if they are driven by a different in br_set_state()
42 if (p->flags & BR_MRP_AWARE) in br_set_state()
45 p->state = state; in br_set_state()
46 if (br_opt_get(p->br, BROPT_MST_ENABLED)) { in br_set_state()
47 err = br_mst_set_state(p, 0, state, NULL); in br_set_state()
49 br_warn(p->br, "error setting MST state on port %u(%s)\n", in br_set_state()
50 p->port_no, netdev_name(p->dev)); in br_set_state()
52 err = switchdev_port_attr_set(p->dev, &attr, NULL); in br_set_state()
53 if (err && err != -EOPNOTSUPP) in br_set_state()
54 br_warn(p->br, "error setting offload STP state on port %u(%s)\n", in br_set_state()
55 (unsigned int) p->port_no, p->dev->name); in br_set_state()
57 br_info(p->br, "port %u(%s) entered %s state\n", in br_set_state()
58 (unsigned int) p->port_no, p->dev->name, in br_set_state()
59 br_port_state_names[p->state]); in br_set_state()
61 if (p->br->stp_enabled == BR_KERNEL_STP) { in br_set_state()
62 switch (p->state) { in br_set_state()
64 p->stp_xstats.transition_blk++; in br_set_state()
67 p->stp_xstats.transition_fwd++; in br_set_state()
83 return p->state; in br_port_get_stp_state()
87 /* called under bridge lock */
92 list_for_each_entry_rcu(p, &br->port_list, list, in br_get_port()
93 lockdep_is_held(&br->lock)) { in br_get_port()
94 if (p->port_no == port_no) in br_get_port()
101 /* called under bridge lock */
109 br = p->br; in br_should_become_root_port()
110 if (p->state == BR_STATE_DISABLED || in br_should_become_root_port()
114 if (memcmp(&br->bridge_id, &p->designated_root, 8) <= 0) in br_should_become_root_port()
122 t = memcmp(&p->designated_root, &rp->designated_root, 8); in br_should_become_root_port()
128 if (p->designated_cost + p->path_cost < in br_should_become_root_port()
129 rp->designated_cost + rp->path_cost) in br_should_become_root_port()
131 else if (p->designated_cost + p->path_cost > in br_should_become_root_port()
132 rp->designated_cost + rp->path_cost) in br_should_become_root_port()
135 t = memcmp(&p->designated_bridge, &rp->designated_bridge, 8); in br_should_become_root_port()
141 if (p->designated_port < rp->designated_port) in br_should_become_root_port()
143 else if (p->designated_port > rp->designated_port) in br_should_become_root_port()
146 if (p->port_id < rp->port_id) in br_should_become_root_port()
157 (unsigned int) p->port_no, p->dev->name); in br_root_port_block()
162 if (br->forward_delay > 0) in br_root_port_block()
163 mod_timer(&p->forward_delay_timer, jiffies + br->forward_delay); in br_root_port_block()
166 /* called under bridge lock */
172 list_for_each_entry(p, &br->port_list, list) { in br_root_selection()
176 if (p->flags & BR_ROOT_BLOCK) in br_root_selection()
179 root_port = p->port_no; in br_root_selection()
182 br->root_port = root_port; in br_root_selection()
185 br->designated_root = br->bridge_id; in br_root_selection()
186 br->root_path_cost = 0; in br_root_selection()
189 br->designated_root = p->designated_root; in br_root_selection()
190 br->root_path_cost = p->designated_cost + p->path_cost; in br_root_selection()
194 /* called under bridge lock */
197 br->max_age = br->bridge_max_age; in br_become_root_bridge()
198 br->hello_time = br->bridge_hello_time; in br_become_root_bridge()
199 br->forward_delay = br->bridge_forward_delay; in br_become_root_bridge()
201 del_timer(&br->tcn_timer); in br_become_root_bridge()
203 if (br->dev->flags & IFF_UP) { in br_become_root_bridge()
205 mod_timer(&br->hello_timer, jiffies + br->hello_time); in br_become_root_bridge()
209 /* called under bridge lock */
215 if (timer_pending(&p->hold_timer)) { in br_transmit_config()
216 p->config_pending = 1; in br_transmit_config()
220 br = p->br; in br_transmit_config()
222 bpdu.topology_change = br->topology_change; in br_transmit_config()
223 bpdu.topology_change_ack = p->topology_change_ack; in br_transmit_config()
224 bpdu.root = br->designated_root; in br_transmit_config()
225 bpdu.root_path_cost = br->root_path_cost; in br_transmit_config()
226 bpdu.bridge_id = br->bridge_id; in br_transmit_config()
227 bpdu.port_id = p->port_id; in br_transmit_config()
232 = br_get_port(br, br->root_port); in br_transmit_config()
233 bpdu.message_age = (jiffies - root->designated_age) in br_transmit_config()
236 bpdu.max_age = br->max_age; in br_transmit_config()
237 bpdu.hello_time = br->hello_time; in br_transmit_config()
238 bpdu.forward_delay = br->forward_delay; in br_transmit_config()
240 if (bpdu.message_age < br->max_age) { in br_transmit_config()
242 p->topology_change_ack = 0; in br_transmit_config()
243 p->config_pending = 0; in br_transmit_config()
244 if (p->br->stp_enabled == BR_KERNEL_STP) in br_transmit_config()
245 mod_timer(&p->hold_timer, in br_transmit_config()
250 /* called under bridge lock */
254 p->designated_root = bpdu->root; in br_record_config_information()
255 p->designated_cost = bpdu->root_path_cost; in br_record_config_information()
256 p->designated_bridge = bpdu->bridge_id; in br_record_config_information()
257 p->designated_port = bpdu->port_id; in br_record_config_information()
258 p->designated_age = jiffies - bpdu->message_age; in br_record_config_information()
260 mod_timer(&p->message_age_timer, jiffies in br_record_config_information()
261 + (bpdu->max_age - bpdu->message_age)); in br_record_config_information()
264 /* called under bridge lock */
268 br->max_age = bpdu->max_age; in br_record_config_timeout_values()
269 br->hello_time = bpdu->hello_time; in br_record_config_timeout_values()
270 br->forward_delay = bpdu->forward_delay; in br_record_config_timeout_values()
271 __br_set_topology_change(br, bpdu->topology_change); in br_record_config_timeout_values()
274 /* called under bridge lock */
279 p = br_get_port(br, br->root_port); in br_transmit_tcn()
284 br->root_port); in br_transmit_tcn()
287 /* called under bridge lock */
293 br = p->br; in br_should_become_designated_port()
297 if (memcmp(&p->designated_root, &br->designated_root, 8)) in br_should_become_designated_port()
300 if (br->root_path_cost < p->designated_cost) in br_should_become_designated_port()
302 else if (br->root_path_cost > p->designated_cost) in br_should_become_designated_port()
305 t = memcmp(&br->bridge_id, &p->designated_bridge, 8); in br_should_become_designated_port()
311 if (p->port_id < p->designated_port) in br_should_become_designated_port()
317 /* called under bridge lock */
322 list_for_each_entry(p, &br->port_list, list) { in br_designated_port_selection()
323 if (p->state != BR_STATE_DISABLED && in br_designated_port_selection()
330 /* called under bridge lock */
336 t = memcmp(&bpdu->root, &p->designated_root, 8); in br_supersedes_port_info()
342 if (bpdu->root_path_cost < p->designated_cost) in br_supersedes_port_info()
344 else if (bpdu->root_path_cost > p->designated_cost) in br_supersedes_port_info()
347 t = memcmp(&bpdu->bridge_id, &p->designated_bridge, 8); in br_supersedes_port_info()
353 if (memcmp(&bpdu->bridge_id, &p->br->bridge_id, 8)) in br_supersedes_port_info()
356 if (bpdu->port_id <= p->designated_port) in br_supersedes_port_info()
362 /* called under bridge lock */
365 br->topology_change_detected = 0; in br_topology_change_acknowledged()
366 del_timer(&br->tcn_timer); in br_topology_change_acknowledged()
369 /* called under bridge lock */
374 if (br->stp_enabled != BR_KERNEL_STP) in br_topology_change_detection()
382 mod_timer(&br->topology_change_timer, jiffies in br_topology_change_detection()
383 + br->bridge_forward_delay + br->bridge_max_age); in br_topology_change_detection()
384 } else if (!br->topology_change_detected) { in br_topology_change_detection()
386 mod_timer(&br->tcn_timer, jiffies + br->bridge_hello_time); in br_topology_change_detection()
389 br->topology_change_detected = 1; in br_topology_change_detection()
392 /* called under bridge lock */
397 list_for_each_entry(p, &br->port_list, list) { in br_config_bpdu_generation()
398 if (p->state != BR_STATE_DISABLED && in br_config_bpdu_generation()
404 /* called under bridge lock */
410 /* called under bridge lock */
417 /* called under bridge lock */
422 br = p->br; in br_become_designated_port()
423 p->designated_root = br->designated_root; in br_become_designated_port()
424 p->designated_cost = br->root_path_cost; in br_become_designated_port()
425 p->designated_bridge = br->bridge_id; in br_become_designated_port()
426 p->designated_port = p->port_id; in br_become_designated_port()
430 /* called under bridge lock */
433 if (p->state != BR_STATE_DISABLED && in br_make_blocking()
434 p->state != BR_STATE_BLOCKING) { in br_make_blocking()
435 if (p->state == BR_STATE_FORWARDING || in br_make_blocking()
436 p->state == BR_STATE_LEARNING) in br_make_blocking()
437 br_topology_change_detection(p->br); in br_make_blocking()
442 del_timer(&p->forward_delay_timer); in br_make_blocking()
446 /* called under bridge lock */
449 struct net_bridge *br = p->br; in br_make_forwarding()
451 if (p->state != BR_STATE_BLOCKING) in br_make_forwarding()
454 if (br->stp_enabled == BR_NO_STP || br->forward_delay == 0) { in br_make_forwarding()
457 del_timer(&p->forward_delay_timer); in br_make_forwarding()
458 } else if (br->stp_enabled == BR_KERNEL_STP) in br_make_forwarding()
465 if (br->forward_delay != 0) in br_make_forwarding()
466 mod_timer(&p->forward_delay_timer, jiffies + br->forward_delay); in br_make_forwarding()
469 /* called under bridge lock */
475 list_for_each_entry(p, &br->port_list, list) { in br_port_state_selection()
476 if (p->state == BR_STATE_DISABLED) in br_port_state_selection()
480 if (br->stp_enabled != BR_USER_STP) { in br_port_state_selection()
481 if (p->port_no == br->root_port) { in br_port_state_selection()
482 p->config_pending = 0; in br_port_state_selection()
483 p->topology_change_ack = 0; in br_port_state_selection()
486 del_timer(&p->message_age_timer); in br_port_state_selection()
489 p->config_pending = 0; in br_port_state_selection()
490 p->topology_change_ack = 0; in br_port_state_selection()
495 if (p->state != BR_STATE_BLOCKING) in br_port_state_selection()
498 * blocking state because the timers will expire and stop by in br_port_state_selection()
501 if (p->state == BR_STATE_FORWARDING) in br_port_state_selection()
506 netif_carrier_off(br->dev); in br_port_state_selection()
508 netif_carrier_on(br->dev); in br_port_state_selection()
511 /* called under bridge lock */
514 p->topology_change_ack = 1; in br_topology_change_acknowledge()
518 /* called under bridge lock */
525 p->stp_xstats.rx_bpdu++; in br_received_config_bpdu()
527 br = p->br; in br_received_config_bpdu()
536 del_timer(&br->hello_timer); in br_received_config_bpdu()
537 if (br->topology_change_detected) { in br_received_config_bpdu()
538 del_timer(&br->topology_change_timer); in br_received_config_bpdu()
541 mod_timer(&br->tcn_timer, in br_received_config_bpdu()
542 jiffies + br->bridge_hello_time); in br_received_config_bpdu()
546 if (p->port_no == br->root_port) { in br_received_config_bpdu()
549 if (bpdu->topology_change_ack) in br_received_config_bpdu()
557 /* called under bridge lock */
560 p->stp_xstats.rx_tcn++; in br_received_tcn_bpdu()
563 br_info(p->br, "port %u(%s) received tcn bpdu\n", in br_received_tcn_bpdu()
564 (unsigned int) p->port_no, p->dev->name); in br_received_tcn_bpdu()
566 br_topology_change_detection(p->br); in br_received_tcn_bpdu()
577 return -ERANGE; in br_set_hello_time()
579 spin_lock_bh(&br->lock); in br_set_hello_time()
580 br->bridge_hello_time = t; in br_set_hello_time()
582 br->hello_time = br->bridge_hello_time; in br_set_hello_time()
583 spin_unlock_bh(&br->lock); in br_set_hello_time()
592 return -ERANGE; in br_set_max_age()
594 spin_lock_bh(&br->lock); in br_set_max_age()
595 br->bridge_max_age = t; in br_set_max_age()
597 br->max_age = br->bridge_max_age; in br_set_max_age()
598 spin_unlock_bh(&br->lock); in br_set_max_age()
603 /* called under bridge lock */
615 if (err && err != -EOPNOTSUPP) in __set_ageing_time()
624 * 0 - entry never ages (all permanent)
625 * 1 - entry disappears (no persistence)
634 err = __set_ageing_time(br->dev, t); in br_set_ageing_time()
638 spin_lock_bh(&br->lock); in br_set_ageing_time()
639 br->bridge_ageing_time = t; in br_set_ageing_time()
640 br->ageing_time = t; in br_set_ageing_time()
641 spin_unlock_bh(&br->lock); in br_set_ageing_time()
643 mod_delayed_work(system_long_wq, &br->gc_work, 0); in br_set_ageing_time()
657 return jiffies_to_clock_t(br->ageing_time); in br_get_ageing_time()
661 /* called under bridge lock */
667 if (br->stp_enabled == BR_KERNEL_STP && br->topology_change != val) { in __br_set_topology_change()
673 t = 2 * br->forward_delay; in __br_set_topology_change()
676 t = br->bridge_ageing_time; in __br_set_topology_change()
680 err = __set_ageing_time(br->dev, t); in __br_set_topology_change()
684 br->ageing_time = t; in __br_set_topology_change()
687 br->topology_change = val; in __br_set_topology_change()
692 br->bridge_forward_delay = t; in __br_set_forward_delay()
694 br->forward_delay = br->bridge_forward_delay; in __br_set_forward_delay()
700 int err = -ERANGE; in br_set_forward_delay()
702 spin_lock_bh(&br->lock); in br_set_forward_delay()
703 if (br->stp_enabled != BR_NO_STP && in br_set_forward_delay()
711 spin_unlock_bh(&br->lock); in br_set_forward_delay()