Staging: hv: mousevsc: Cleanup and properly implement reportdesc_callback()
[zen-stable.git] / drivers / net / bonding / bond_procfs.c
blob95de93b9038675994e66622eff5423ae082583c0
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 seq_printf(seq, "Speed: %d Mbps\n", slave->speed);
161 seq_printf(seq, "Duplex: %s\n", slave->duplex ? "full" : "half");
162 seq_printf(seq, "Link Failure Count: %u\n",
163 slave->link_failure_count);
165 seq_printf(seq, "Permanent HW addr: %pM\n", slave->perm_hwaddr);
167 if (bond->params.mode == BOND_MODE_8023AD) {
168 const struct aggregator *agg
169 = SLAVE_AD_INFO(slave).port.aggregator;
171 if (agg)
172 seq_printf(seq, "Aggregator ID: %d\n",
173 agg->aggregator_identifier);
174 else
175 seq_puts(seq, "Aggregator ID: N/A\n");
177 seq_printf(seq, "Slave queue ID: %d\n", slave->queue_id);
180 static int bond_info_seq_show(struct seq_file *seq, void *v)
182 if (v == SEQ_START_TOKEN) {
183 seq_printf(seq, "%s\n", bond_version);
184 bond_info_show_master(seq);
185 } else
186 bond_info_show_slave(seq, v);
188 return 0;
191 static const struct seq_operations bond_info_seq_ops = {
192 .start = bond_info_seq_start,
193 .next = bond_info_seq_next,
194 .stop = bond_info_seq_stop,
195 .show = bond_info_seq_show,
198 static int bond_info_open(struct inode *inode, struct file *file)
200 struct seq_file *seq;
201 struct proc_dir_entry *proc;
202 int res;
204 res = seq_open(file, &bond_info_seq_ops);
205 if (!res) {
206 /* recover the pointer buried in proc_dir_entry data */
207 seq = file->private_data;
208 proc = PDE(inode);
209 seq->private = proc->data;
212 return res;
215 static const struct file_operations bond_info_fops = {
216 .owner = THIS_MODULE,
217 .open = bond_info_open,
218 .read = seq_read,
219 .llseek = seq_lseek,
220 .release = seq_release,
223 void bond_create_proc_entry(struct bonding *bond)
225 struct net_device *bond_dev = bond->dev;
226 struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id);
228 if (bn->proc_dir) {
229 bond->proc_entry = proc_create_data(bond_dev->name,
230 S_IRUGO, bn->proc_dir,
231 &bond_info_fops, bond);
232 if (bond->proc_entry == NULL)
233 pr_warning("Warning: Cannot create /proc/net/%s/%s\n",
234 DRV_NAME, bond_dev->name);
235 else
236 memcpy(bond->proc_file_name, bond_dev->name, IFNAMSIZ);
240 void bond_remove_proc_entry(struct bonding *bond)
242 struct net_device *bond_dev = bond->dev;
243 struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id);
245 if (bn->proc_dir && bond->proc_entry) {
246 remove_proc_entry(bond->proc_file_name, bn->proc_dir);
247 memset(bond->proc_file_name, 0, IFNAMSIZ);
248 bond->proc_entry = NULL;
252 /* Create the bonding directory under /proc/net, if doesn't exist yet.
253 * Caller must hold rtnl_lock.
255 void __net_init bond_create_proc_dir(struct bond_net *bn)
257 if (!bn->proc_dir) {
258 bn->proc_dir = proc_mkdir(DRV_NAME, bn->net->proc_net);
259 if (!bn->proc_dir)
260 pr_warning("Warning: cannot create /proc/net/%s\n",
261 DRV_NAME);
265 /* Destroy the bonding directory under /proc/net, if empty.
266 * Caller must hold rtnl_lock.
268 void __net_exit bond_destroy_proc_dir(struct bond_net *bn)
270 if (bn->proc_dir) {
271 remove_proc_entry(DRV_NAME, bn->net->proc_net);
272 bn->proc_dir = NULL;