ip: introduce ip_is_fragment helper inline function
[linux-2.6-block.git] / drivers / net / bonding / bonding.h
CommitLineData
1da177e4
LT
1/*
2 * Bond several ethernet interfaces into a Cisco, running 'Etherchannel'.
3 *
4 * Portions are (c) Copyright 1995 Simon "Guru Aleph-Null" Janes
5 * NCM: Network and Communications Management, Inc.
6 *
7 * BUT, I'm the one who modified it for ethernet, so:
8 * (c) Copyright 1999, Thomas Davis, tadavis@lbl.gov
9 *
10 * This software may be used and distributed according to the terms
11 * of the GNU Public License, incorporated herein by reference.
12 *
1da177e4
LT
13 */
14
15#ifndef _LINUX_BONDING_H
16#define _LINUX_BONDING_H
17
18#include <linux/timer.h>
19#include <linux/proc_fs.h>
20#include <linux/if_bonding.h>
e843fa50 21#include <linux/cpumask.h>
305d552a 22#include <linux/in6.h>
8a8efa22 23#include <linux/netpoll.h>
1da177e4
LT
24#include "bond_3ad.h"
25#include "bond_alb.h"
26
ad246c99
BH
27#define DRV_VERSION "3.7.1"
28#define DRV_RELDATE "April 27, 2011"
1da177e4
LT
29#define DRV_NAME "bonding"
30#define DRV_DESCRIPTION "Ethernet Channel Bonding Driver"
31
bd33acc3
AW
32#define bond_version DRV_DESCRIPTION ": v" DRV_VERSION " (" DRV_RELDATE ")\n"
33
1da177e4
LT
34#define BOND_MAX_ARP_TARGETS 16
35
1da177e4
LT
36#define IS_UP(dev) \
37 ((((dev)->flags & IFF_UP) == IFF_UP) && \
38 netif_running(dev) && \
39 netif_carrier_ok(dev))
40
1da177e4
LT
41/*
42 * Checks whether slave is ready for transmit.
43 */
44#define SLAVE_IS_OK(slave) \
45 (((slave)->dev->flags & IFF_UP) && \
46 netif_running((slave)->dev) && \
47 ((slave)->link == BOND_LINK_UP) && \
e30bc066 48 bond_is_active_slave(slave))
1da177e4
LT
49
50
51#define USES_PRIMARY(mode) \
52 (((mode) == BOND_MODE_ACTIVEBACKUP) || \
53 ((mode) == BOND_MODE_TLB) || \
54 ((mode) == BOND_MODE_ALB))
55
bb1d9123
AG
56#define TX_QUEUE_OVERRIDE(mode) \
57 (((mode) == BOND_MODE_ACTIVEBACKUP) || \
58 ((mode) == BOND_MODE_ROUNDROBIN))
1da177e4
LT
59/*
60 * Less bad way to call ioctl from within the kernel; this needs to be
61 * done some other way to get the call out of interrupt context.
62 * Needs "ioctl" variable to be supplied by calling context.
63 */
64#define IOCTL(dev, arg, cmd) ({ \
65 int res = 0; \
66 mm_segment_t fs = get_fs(); \
67 set_fs(get_ds()); \
68 res = ioctl(dev, arg, cmd); \
69 set_fs(fs); \
70 res; })
71
72/**
73 * bond_for_each_slave_from - iterate the slaves list from a starting point
74 * @bond: the bond holding this list.
75 * @pos: current slave.
76 * @cnt: counter for max number of moves
77 * @start: starting point.
78 *
79 * Caller must hold bond->lock
80 */
81#define bond_for_each_slave_from(bond, pos, cnt, start) \
82 for (cnt = 0, pos = start; \
83 cnt < (bond)->slave_cnt; \
84 cnt++, pos = (pos)->next)
85
86/**
87 * bond_for_each_slave_from_to - iterate the slaves list from start point to stop point
88 * @bond: the bond holding this list.
89 * @pos: current slave.
90 * @cnt: counter for number max of moves
91 * @start: start point.
92 * @stop: stop point.
93 *
94 * Caller must hold bond->lock
95 */
96#define bond_for_each_slave_from_to(bond, pos, cnt, start, stop) \
97 for (cnt = 0, pos = start; \
98 ((cnt < (bond)->slave_cnt) && (pos != (stop)->next)); \
99 cnt++, pos = (pos)->next)
100
101/**
102 * bond_for_each_slave - iterate the slaves list from head
103 * @bond: the bond holding this list.
104 * @pos: current slave.
105 * @cnt: counter for max number of moves
106 *
107 * Caller must hold bond->lock
108 */
109#define bond_for_each_slave(bond, pos, cnt) \
110 bond_for_each_slave_from(bond, pos, cnt, (bond)->first_slave)
111
112
e843fa50 113#ifdef CONFIG_NET_POLL_CONTROLLER
fb4fa76a 114extern atomic_t netpoll_block_tx;
e843fa50
NH
115
116static inline void block_netpoll_tx(void)
117{
fb4fa76a 118 atomic_inc(&netpoll_block_tx);
e843fa50
NH
119}
120
121static inline void unblock_netpoll_tx(void)
122{
fb4fa76a 123 atomic_dec(&netpoll_block_tx);
e843fa50
NH
124}
125
126static inline int is_netpoll_tx_blocked(struct net_device *dev)
127{
080e4130 128 if (unlikely(netpoll_tx_running(dev)))
fb4fa76a 129 return atomic_read(&netpoll_block_tx);
e843fa50
NH
130 return 0;
131}
132#else
133#define block_netpoll_tx()
134#define unblock_netpoll_tx()
135#define is_netpoll_tx_blocked(dev) (0)
136#endif
137
1da177e4
LT
138struct bond_params {
139 int mode;
169a3e66 140 int xmit_policy;
1da177e4 141 int miimon;
ad246c99 142 u8 num_peer_notif;
1da177e4 143 int arp_interval;
f5b2b966 144 int arp_validate;
1da177e4 145 int use_carrier;
dd957c57 146 int fail_over_mac;
1da177e4
LT
147 int updelay;
148 int downdelay;
149 int lacp_fast;
fd989c83 150 int ad_select;
1da177e4 151 char primary[IFNAMSIZ];
a549952a 152 int primary_reselect;
d3bb52b0 153 __be32 arp_targets[BOND_MAX_ARP_TARGETS];
bb1d9123 154 int tx_queues;
ebd8e497 155 int all_slaves_active;
c2952c31 156 int resend_igmp;
1da177e4
LT
157};
158
12479f9a
MW
159struct bond_parm_tbl {
160 char *modename;
161 int mode;
162};
163
ece95f7f
JV
164#define BOND_MAX_MODENAME_LEN 20
165
1da177e4
LT
166struct vlan_entry {
167 struct list_head vlan_list;
d3bb52b0 168 __be32 vlan_ip;
1da177e4
LT
169 unsigned short vlan_id;
170};
171
172struct slave {
e944ef79 173 struct net_device *dev; /* first - useful for panic debug */
1da177e4
LT
174 struct slave *next;
175 struct slave *prev;
35d48903 176 struct bonding *bond; /* our master */
8bb5f96b 177 int delay;
f8a8ccd5
AG
178 unsigned long jiffies;
179 unsigned long last_arp_rx;
1da177e4 180 s8 link; /* one of BOND_LINK_XXXX */
b2220cad 181 s8 new_link;
2d7011ca
JP
182 u8 backup:1, /* indicates backup slave. Value corresponds with
183 BOND_STATE_ACTIVE and BOND_STATE_BACKUP */
184 inactive:1; /* indicates inactive slave */
5d30530e 185 u8 duplex;
3158bf7d 186 u32 original_mtu;
1da177e4 187 u32 link_failure_count;
5d30530e 188 u32 speed;
bb1d9123 189 u16 queue_id;
5d30530e 190 u8 perm_hwaddr[ETH_ALEN];
1da177e4
LT
191 struct ad_slave_info ad_info; /* HUGE - better to dynamically alloc */
192 struct tlb_slave_info tlb_info;
8a8efa22
AW
193#ifdef CONFIG_NET_POLL_CONTROLLER
194 struct netpoll *np;
195#endif
1da177e4
LT
196};
197
b2220cad
JV
198/*
199 * Link pseudo-state only used internally by monitors
200 */
201#define BOND_LINK_NOCHANGE -1
202
1da177e4
LT
203/*
204 * Here are the locking policies for the two bonding locks:
205 *
206 * 1) Get bond->lock when reading/writing slave list.
207 * 2) Get bond->curr_slave_lock when reading/writing bond->curr_active_slave.
208 * (It is unnecessary when the write-lock is put with bond->lock.)
209 * 3) When we lock with bond->curr_slave_lock, we must lock with bond->lock
210 * beforehand.
211 */
212struct bonding {
e944ef79 213 struct net_device *dev; /* first - useful for panic debug */
1da177e4
LT
214 struct slave *first_slave;
215 struct slave *curr_active_slave;
216 struct slave *current_arp_slave;
217 struct slave *primary_slave;
a549952a 218 bool force_primary;
1da177e4 219 s32 slave_cnt; /* never change this value outside the attach/detach wrappers */
3aba891d
JP
220 void (*recv_probe)(struct sk_buff *, struct bonding *,
221 struct slave *);
1da177e4
LT
222 rwlock_t lock;
223 rwlock_t curr_slave_lock;
1da177e4 224 s8 kill_timers;
ad246c99 225 u8 send_peer_notif;
d90a162a 226 s8 setup_by_slave;
c2952c31 227 s8 igmp_retrans;
1da177e4
LT
228#ifdef CONFIG_PROC_FS
229 struct proc_dir_entry *proc_entry;
230 char proc_file_name[IFNAMSIZ];
231#endif /* CONFIG_PROC_FS */
232 struct list_head bond_list;
22bedad3 233 struct netdev_hw_addr_list mc_list;
a361c83c 234 int (*xmit_hash_policy)(struct sk_buff *, int);
d3bb52b0 235 __be32 master_ip;
1da177e4 236 u16 flags;
cf5f9044 237 u16 rr_tx_counter;
1da177e4
LT
238 struct ad_bond_info ad_info;
239 struct alb_bond_info alb_info;
240 struct bond_params params;
241 struct list_head vlan_list;
242 struct vlan_group *vlgrp;
1b76b316
JV
243 struct workqueue_struct *wq;
244 struct delayed_work mii_work;
245 struct delayed_work arp_work;
246 struct delayed_work alb_work;
247 struct delayed_work ad_work;
5a37e8ca 248 struct delayed_work mcast_work;
f073c7ca
TI
249#ifdef CONFIG_DEBUG_FS
250 /* debugging suport via debugfs */
251 struct dentry *debug_dir;
252#endif /* CONFIG_DEBUG_FS */
1da177e4
LT
253};
254
f1c1775a
JP
255#define bond_slave_get_rcu(dev) \
256 ((struct slave *) rcu_dereference(dev->rx_handler_data))
257
1da177e4
LT
258/**
259 * Returns NULL if the net_device does not belong to any of the bond's slaves
260 *
261 * Caller must hold bond lock for read
262 */
4ec952b8 263static inline struct slave *bond_get_slave_by_dev(struct bonding *bond,
264 struct net_device *slave_dev)
1da177e4
LT
265{
266 struct slave *slave = NULL;
267 int i;
268
269 bond_for_each_slave(bond, slave, i) {
270 if (slave->dev == slave_dev) {
af3e5bd5 271 return slave;
1da177e4
LT
272 }
273 }
274
4ec952b8 275 return NULL;
1da177e4
LT
276}
277
cceb904f 278static inline struct bonding *bond_get_bond_by_slave(struct slave *slave)
1da177e4
LT
279{
280 if (!slave || !slave->dev->master) {
281 return NULL;
282 }
283
c04914af 284 return netdev_priv(slave->dev->master);
1da177e4
LT
285}
286
58402054
HE
287static inline bool bond_is_lb(const struct bonding *bond)
288{
8e95a202
JP
289 return (bond->params.mode == BOND_MODE_TLB ||
290 bond->params.mode == BOND_MODE_ALB);
58402054
HE
291}
292
e30bc066
JP
293static inline void bond_set_active_slave(struct slave *slave)
294{
295 slave->backup = 0;
296}
297
298static inline void bond_set_backup_slave(struct slave *slave)
299{
300 slave->backup = 1;
301}
302
303static inline int bond_slave_state(struct slave *slave)
304{
305 return slave->backup;
306}
307
308static inline bool bond_is_active_slave(struct slave *slave)
309{
310 return !bond_slave_state(slave);
311}
312
a549952a
JP
313#define BOND_PRI_RESELECT_ALWAYS 0
314#define BOND_PRI_RESELECT_BETTER 1
315#define BOND_PRI_RESELECT_FAILURE 2
316
3915c1e8
JV
317#define BOND_FOM_NONE 0
318#define BOND_FOM_ACTIVE 1
319#define BOND_FOM_FOLLOW 2
320
f5b2b966
JV
321#define BOND_ARP_VALIDATE_NONE 0
322#define BOND_ARP_VALIDATE_ACTIVE (1 << BOND_STATE_ACTIVE)
323#define BOND_ARP_VALIDATE_BACKUP (1 << BOND_STATE_BACKUP)
324#define BOND_ARP_VALIDATE_ALL (BOND_ARP_VALIDATE_ACTIVE | \
325 BOND_ARP_VALIDATE_BACKUP)
326
079ca7da
AB
327static inline int slave_do_arp_validate(struct bonding *bond,
328 struct slave *slave)
f5b2b966 329{
e30bc066 330 return bond->params.arp_validate & (1 << bond_slave_state(slave));
f5b2b966
JV
331}
332
079ca7da 333static inline unsigned long slave_last_rx(struct bonding *bond,
f8a8ccd5 334 struct slave *slave)
f5b2b966
JV
335{
336 if (slave_do_arp_validate(bond, slave))
337 return slave->last_arp_rx;
338
339 return slave->dev->last_rx;
340}
341
8a8efa22
AW
342#ifdef CONFIG_NET_POLL_CONTROLLER
343static inline void bond_netpoll_send_skb(const struct slave *slave,
344 struct sk_buff *skb)
345{
346 struct netpoll *np = slave->np;
347
348 if (np)
349 netpoll_send_skb(np, skb);
350}
351#else
352static inline void bond_netpoll_send_skb(const struct slave *slave,
353 struct sk_buff *skb)
354{
355}
356#endif
357
cceb904f 358static inline void bond_set_slave_inactive_flags(struct slave *slave)
1da177e4 359{
454d7c9b 360 struct bonding *bond = netdev_priv(slave->dev->master);
ae63e808 361 if (!bond_is_lb(bond))
e30bc066 362 bond_set_backup_slave(slave);
ebd8e497 363 if (!bond->params.all_slaves_active)
2d7011ca 364 slave->inactive = 1;
1da177e4
LT
365}
366
cceb904f 367static inline void bond_set_slave_active_flags(struct slave *slave)
1da177e4 368{
e30bc066 369 bond_set_active_slave(slave);
2d7011ca
JP
370 slave->inactive = 0;
371}
372
373static inline bool bond_is_slave_inactive(struct slave *slave)
374{
375 return slave->inactive;
1da177e4
LT
376}
377
378struct vlan_entry *bond_next_vlan(struct bonding *bond, struct vlan_entry *curr);
379int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, struct net_device *slave_dev);
ec87fd3b 380int bond_create(struct net *net, const char *name);
b76cdba9
MW
381int bond_create_sysfs(void);
382void bond_destroy_sysfs(void);
6151b3d4 383void bond_prepare_sysfs_group(struct bonding *bond);
b76cdba9
MW
384int bond_create_slave_symlinks(struct net_device *master, struct net_device *slave);
385void bond_destroy_slave_symlinks(struct net_device *master, struct net_device *slave);
a77b5325
MW
386int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev);
387int bond_release(struct net_device *bond_dev, struct net_device *slave_dev);
1b76b316
JV
388void bond_mii_monitor(struct work_struct *);
389void bond_loadbalance_arp_mon(struct work_struct *);
390void bond_activebackup_arp_mon(struct work_struct *);
a77b5325 391void bond_set_mode_ops(struct bonding *bond, int mode);
325dcf7a 392int bond_parse_parm(const char *mode_arg, const struct bond_parm_tbl *tbl);
a77b5325
MW
393void bond_select_active_slave(struct bonding *bond);
394void bond_change_active_slave(struct bonding *bond, struct slave *new_active);
f073c7ca
TI
395void bond_create_debugfs(void);
396void bond_destroy_debugfs(void);
397void bond_debug_register(struct bonding *bond);
398void bond_debug_unregister(struct bonding *bond);
399void bond_debug_reregister(struct bonding *bond);
d30ee670 400const char *bond_mode_name(int mode);
1da177e4 401
ec87fd3b
EB
402struct bond_net {
403 struct net * net; /* Associated network namespace */
404 struct list_head dev_list;
405#ifdef CONFIG_PROC_FS
406 struct proc_dir_entry * proc_dir;
407#endif
408};
409
bd33acc3
AW
410#ifdef CONFIG_PROC_FS
411void bond_create_proc_entry(struct bonding *bond);
412void bond_remove_proc_entry(struct bonding *bond);
413void bond_create_proc_dir(struct bond_net *bn);
414void bond_destroy_proc_dir(struct bond_net *bn);
415#else
416static inline void bond_create_proc_entry(struct bonding *bond)
417{
418}
419
420static inline void bond_remove_proc_entry(struct bonding *bond)
421{
422}
423
424static inline void bond_create_proc_dir(struct bond_net *bn)
425{
426}
427
428static inline void bond_destroy_proc_dir(struct bond_net *bn)
429{
430}
431#endif
432
433
b2259672 434/* exported from bond_main.c */
ec87fd3b 435extern int bond_net_id;
e97fd7c6
HE
436extern const struct bond_parm_tbl bond_lacp_tbl[];
437extern const struct bond_parm_tbl bond_mode_tbl[];
438extern const struct bond_parm_tbl xmit_hashtype_tbl[];
439extern const struct bond_parm_tbl arp_validate_tbl[];
440extern const struct bond_parm_tbl fail_over_mac_tbl[];
a549952a 441extern const struct bond_parm_tbl pri_reselect_tbl[];
b06715b7
HE
442extern struct bond_parm_tbl ad_select_tbl[];
443
1da177e4 444#endif /* _LINUX_BONDING_H */