bonding:update speed/duplex for NETDEV_CHANGE
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / net / bonding / bond_procfs.c
blobd2ff52e63cbb614ea01c817a1342a6195a4de91d
1 #include <linux/proc_fs.h>
2 #include <net/net_namespace.h>
3 #include <net/netns/generic.h>
4 #include "bonding.h"
7 static void *bond_info_seq_start(struct seq_file *seq, loff_t *pos)
8 __acquires(RCU)
9 __acquires(&bond->lock)
11 struct bonding *bond = seq->private;
12 loff_t off = 0;
13 struct slave *slave;
14 int i;
16 /* make sure the bond won't be taken away */
17 rcu_read_lock();
18 read_lock(&bond->lock);
20 if (*pos == 0)
21 return SEQ_START_TOKEN;
23 bond_for_each_slave(bond, slave, i) {
24 if (++off == *pos)
25 return slave;
28 return NULL;
31 static void *bond_info_seq_next(struct seq_file *seq, void *v, loff_t *pos)
33 struct bonding *bond = seq->private;
34 struct slave *slave = v;
36 ++*pos;
37 if (v == SEQ_START_TOKEN)
38 return bond->first_slave;
40 slave = slave->next;
42 return (slave == bond->first_slave) ? NULL : slave;
45 static void bond_info_seq_stop(struct seq_file *seq, void *v)
46 __releases(&bond->lock)
47 __releases(RCU)
49 struct bonding *bond = seq->private;
51 read_unlock(&bond->lock);
52 rcu_read_unlock();
55 static void bond_info_show_master(struct seq_file *seq)
57 struct bonding *bond = seq->private;
58 struct slave *curr;
59 int i;
61 read_lock(&bond->curr_slave_lock);
62 curr = bond->curr_active_slave;
63 read_unlock(&bond->curr_slave_lock);
65 seq_printf(seq, "Bonding Mode: %s",
66 bond_mode_name(bond->params.mode));
68 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP &&
69 bond->params.fail_over_mac)
70 seq_printf(seq, " (fail_over_mac %s)",
71 fail_over_mac_tbl[bond->params.fail_over_mac].modename);
73 seq_printf(seq, "\n");
75 if (bond->params.mode == BOND_MODE_XOR ||
76 bond->params.mode == BOND_MODE_8023AD) {
77 seq_printf(seq, "Transmit Hash Policy: %s (%d)\n",
78 xmit_hashtype_tbl[bond->params.xmit_policy].modename,
79 bond->params.xmit_policy);
82 if (USES_PRIMARY(bond->params.mode)) {
83 seq_printf(seq, "Primary Slave: %s",
84 (bond->primary_slave) ?
85 bond->primary_slave->dev->name : "None");
86 if (bond->primary_slave)
87 seq_printf(seq, " (primary_reselect %s)",
88 pri_reselect_tbl[bond->params.primary_reselect].modename);
90 seq_printf(seq, "\nCurrently Active Slave: %s\n",
91 (curr) ? curr->dev->name : "None");
94 seq_printf(seq, "MII Status: %s\n", netif_carrier_ok(bond->dev) ?
95 "up" : "down");
96 seq_printf(seq, "MII Polling Interval (ms): %d\n", bond->params.miimon);
97 seq_printf(seq, "Up Delay (ms): %d\n",
98 bond->params.updelay * bond->params.miimon);
99 seq_printf(seq, "Down Delay (ms): %d\n",
100 bond->params.downdelay * bond->params.miimon);
103 /* ARP information */
104 if (bond->params.arp_interval > 0) {
105 int printed = 0;
106 seq_printf(seq, "ARP Polling Interval (ms): %d\n",
107 bond->params.arp_interval);
109 seq_printf(seq, "ARP IP target/s (n.n.n.n form):");
111 for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) {
112 if (!bond->params.arp_targets[i])
113 break;
114 if (printed)
115 seq_printf(seq, ",");
116 seq_printf(seq, " %pI4", &bond->params.arp_targets[i]);
117 printed = 1;
119 seq_printf(seq, "\n");
122 if (bond->params.mode == BOND_MODE_8023AD) {
123 struct ad_info ad_info;
125 seq_puts(seq, "\n802.3ad info\n");
126 seq_printf(seq, "LACP rate: %s\n",
127 (bond->params.lacp_fast) ? "fast" : "slow");
128 seq_printf(seq, "Min links: %d\n", bond->params.min_links);
129 seq_printf(seq, "Aggregator selection policy (ad_select): %s\n",
130 ad_select_tbl[bond->params.ad_select].modename);
132 if (bond_3ad_get_active_agg_info(bond, &ad_info)) {
133 seq_printf(seq, "bond %s has no active aggregator\n",
134 bond->dev->name);
135 } else {
136 seq_printf(seq, "Active Aggregator Info:\n");
138 seq_printf(seq, "\tAggregator ID: %d\n",
139 ad_info.aggregator_id);
140 seq_printf(seq, "\tNumber of ports: %d\n",
141 ad_info.ports);
142 seq_printf(seq, "\tActor Key: %d\n",
143 ad_info.actor_key);
144 seq_printf(seq, "\tPartner Key: %d\n",
145 ad_info.partner_key);
146 seq_printf(seq, "\tPartner Mac Address: %pM\n",
147 ad_info.partner_system);
152 static void bond_info_show_slave(struct seq_file *seq,
153 const struct slave *slave)
155 struct bonding *bond = seq->private;
157 seq_printf(seq, "\nSlave Interface: %s\n", slave->dev->name);
158 seq_printf(seq, "MII Status: %s\n",
159 (slave->link == BOND_LINK_UP) ? "up" : "down");
160 if (slave->speed == -1)
161 seq_printf(seq, "Speed: %s\n", "Unknown");
162 else
163 seq_printf(seq, "Speed: %d Mbps\n", slave->speed);
165 if (slave->duplex == -1)
166 seq_printf(seq, "Duplex: %s\n", "Unknown");
167 else
168 seq_printf(seq, "Duplex: %s\n", slave->duplex ? "full" : "half");
170 seq_printf(seq, "Link Failure Count: %u\n",
171 slave->link_failure_count);
173 seq_printf(seq, "Permanent HW addr: %pM\n", slave->perm_hwaddr);
175 if (bond->params.mode == BOND_MODE_8023AD) {
176 const struct aggregator *agg
177 = SLAVE_AD_INFO(slave).port.aggregator;
179 if (agg)
180 seq_printf(seq, "Aggregator ID: %d\n",
181 agg->aggregator_identifier);
182 else
183 seq_puts(seq, "Aggregator ID: N/A\n");
185 seq_printf(seq, "Slave queue ID: %d\n", slave->queue_id);
188 static int bond_info_seq_show(struct seq_file *seq, void *v)
190 if (v == SEQ_START_TOKEN) {
191 seq_printf(seq, "%s\n", bond_version);
192 bond_info_show_master(seq);
193 } else
194 bond_info_show_slave(seq, v);
196 return 0;
199 static const struct seq_operations bond_info_seq_ops = {
200 .start = bond_info_seq_start,
201 .next = bond_info_seq_next,
202 .stop = bond_info_seq_stop,
203 .show = bond_info_seq_show,
206 static int bond_info_open(struct inode *inode, struct file *file)
208 struct seq_file *seq;
209 struct proc_dir_entry *proc;
210 int res;
212 res = seq_open(file, &bond_info_seq_ops);
213 if (!res) {
214 /* recover the pointer buried in proc_dir_entry data */
215 seq = file->private_data;
216 proc = PDE(inode);
217 seq->private = proc->data;
220 return res;
223 static const struct file_operations bond_info_fops = {
224 .owner = THIS_MODULE,
225 .open = bond_info_open,
226 .read = seq_read,
227 .llseek = seq_lseek,
228 .release = seq_release,
231 void bond_create_proc_entry(struct bonding *bond)
233 struct net_device *bond_dev = bond->dev;
234 struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id);
236 if (bn->proc_dir) {
237 bond->proc_entry = proc_create_data(bond_dev->name,
238 S_IRUGO, bn->proc_dir,
239 &bond_info_fops, bond);
240 if (bond->proc_entry == NULL)
241 pr_warning("Warning: Cannot create /proc/net/%s/%s\n",
242 DRV_NAME, bond_dev->name);
243 else
244 memcpy(bond->proc_file_name, bond_dev->name, IFNAMSIZ);
248 void bond_remove_proc_entry(struct bonding *bond)
250 struct net_device *bond_dev = bond->dev;
251 struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id);
253 if (bn->proc_dir && bond->proc_entry) {
254 remove_proc_entry(bond->proc_file_name, bn->proc_dir);
255 memset(bond->proc_file_name, 0, IFNAMSIZ);
256 bond->proc_entry = NULL;
260 /* Create the bonding directory under /proc/net, if doesn't exist yet.
261 * Caller must hold rtnl_lock.
263 void __net_init bond_create_proc_dir(struct bond_net *bn)
265 if (!bn->proc_dir) {
266 bn->proc_dir = proc_mkdir(DRV_NAME, bn->net->proc_net);
267 if (!bn->proc_dir)
268 pr_warning("Warning: cannot create /proc/net/%s\n",
269 DRV_NAME);
273 /* Destroy the bonding directory under /proc/net, if empty.
274 * Caller must hold rtnl_lock.
276 void __net_exit bond_destroy_proc_dir(struct bond_net *bn)
278 if (bn->proc_dir) {
279 remove_proc_entry(DRV_NAME, bn->net->proc_net);
280 bn->proc_dir = NULL;