ARM: use ARM_DMA_ZONE_SIZE to adjust the zone sizes
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / bridge / br_stp_timer.c
blob3e965140051e79ad146cc41bd0da78f93d26d476
1 /*
2 * Spanning tree protocol; timer-related code
3 * Linux ethernet bridge
5 * Authors:
6 * Lennert Buytenhek <buytenh@gnu.org>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
14 #include <linux/kernel.h>
15 #include <linux/times.h>
17 #include "br_private.h"
18 #include "br_private_stp.h"
20 /* called under bridge lock */
21 static int br_is_designated_for_some_port(const struct net_bridge *br)
23 struct net_bridge_port *p;
25 list_for_each_entry(p, &br->port_list, list) {
26 if (p->state != BR_STATE_DISABLED &&
27 !memcmp(&p->designated_bridge, &br->bridge_id, 8))
28 return 1;
31 return 0;
34 static void br_hello_timer_expired(unsigned long arg)
36 struct net_bridge *br = (struct net_bridge *)arg;
38 br_debug(br, "hello timer expired\n");
39 spin_lock(&br->lock);
40 if (br->dev->flags & IFF_UP) {
41 br_config_bpdu_generation(br);
43 mod_timer(&br->hello_timer, round_jiffies(jiffies + br->hello_time));
45 spin_unlock(&br->lock);
48 static void br_message_age_timer_expired(unsigned long arg)
50 struct net_bridge_port *p = (struct net_bridge_port *) arg;
51 struct net_bridge *br = p->br;
52 const bridge_id *id = &p->designated_bridge;
53 int was_root;
55 if (p->state == BR_STATE_DISABLED)
56 return;
58 br_info(br, "port %u(%s) neighbor %.2x%.2x.%pM lost\n",
59 (unsigned) p->port_no, p->dev->name,
60 id->prio[0], id->prio[1], &id->addr);
63 * According to the spec, the message age timer cannot be
64 * running when we are the root bridge. So.. this was_root
65 * check is redundant. I'm leaving it in for now, though.
67 spin_lock(&br->lock);
68 if (p->state == BR_STATE_DISABLED)
69 goto unlock;
70 was_root = br_is_root_bridge(br);
72 br_become_designated_port(p);
73 br_configuration_update(br);
74 br_port_state_selection(br);
75 if (br_is_root_bridge(br) && !was_root)
76 br_become_root_bridge(br);
77 unlock:
78 spin_unlock(&br->lock);
81 static void br_forward_delay_timer_expired(unsigned long arg)
83 struct net_bridge_port *p = (struct net_bridge_port *) arg;
84 struct net_bridge *br = p->br;
86 br_debug(br, "port %u(%s) forward delay timer\n",
87 (unsigned) p->port_no, p->dev->name);
88 spin_lock(&br->lock);
89 if (p->state == BR_STATE_LISTENING) {
90 p->state = BR_STATE_LEARNING;
91 mod_timer(&p->forward_delay_timer,
92 jiffies + br->forward_delay);
93 } else if (p->state == BR_STATE_LEARNING) {
94 p->state = BR_STATE_FORWARDING;
95 if (br_is_designated_for_some_port(br))
96 br_topology_change_detection(br);
97 netif_carrier_on(br->dev);
99 br_log_state(p);
100 spin_unlock(&br->lock);
103 static void br_tcn_timer_expired(unsigned long arg)
105 struct net_bridge *br = (struct net_bridge *) arg;
107 br_debug(br, "tcn timer expired\n");
108 spin_lock(&br->lock);
109 if (br->dev->flags & IFF_UP) {
110 br_transmit_tcn(br);
112 mod_timer(&br->tcn_timer,jiffies + br->bridge_hello_time);
114 spin_unlock(&br->lock);
117 static void br_topology_change_timer_expired(unsigned long arg)
119 struct net_bridge *br = (struct net_bridge *) arg;
121 br_debug(br, "topo change timer expired\n");
122 spin_lock(&br->lock);
123 br->topology_change_detected = 0;
124 br->topology_change = 0;
125 spin_unlock(&br->lock);
128 static void br_hold_timer_expired(unsigned long arg)
130 struct net_bridge_port *p = (struct net_bridge_port *) arg;
132 br_debug(p->br, "port %u(%s) hold timer expired\n",
133 (unsigned) p->port_no, p->dev->name);
135 spin_lock(&p->br->lock);
136 if (p->config_pending)
137 br_transmit_config(p);
138 spin_unlock(&p->br->lock);
141 void br_stp_timer_init(struct net_bridge *br)
143 setup_timer(&br->hello_timer, br_hello_timer_expired,
144 (unsigned long) br);
146 setup_timer(&br->tcn_timer, br_tcn_timer_expired,
147 (unsigned long) br);
149 setup_timer(&br->topology_change_timer,
150 br_topology_change_timer_expired,
151 (unsigned long) br);
153 setup_timer(&br->gc_timer, br_fdb_cleanup, (unsigned long) br);
156 void br_stp_port_timer_init(struct net_bridge_port *p)
158 setup_timer(&p->message_age_timer, br_message_age_timer_expired,
159 (unsigned long) p);
161 setup_timer(&p->forward_delay_timer, br_forward_delay_timer_expired,
162 (unsigned long) p);
164 setup_timer(&p->hold_timer, br_hold_timer_expired,
165 (unsigned long) p);
168 /* Report ticks left (in USER_HZ) used for API */
169 unsigned long br_timer_value(const struct timer_list *timer)
171 return timer_pending(timer)
172 ? jiffies_to_clock_t(timer->expires - jiffies) : 0;