[PATCH] fix bonding crash, remove old ABI support
[safe/jmp/linux-2.6] / drivers / net / bonding / bonding.h
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  *
13  *
14  * 2003/03/18 - Amir Noam <amir.noam at intel dot com>,
15  *              Tsippy Mendelson <tsippy.mendelson at intel dot com> and
16  *              Shmulik Hen <shmulik.hen at intel dot com>
17  *      - Added support for IEEE 802.3ad Dynamic link aggregation mode.
18  *
19  * 2003/05/01 - Tsippy Mendelson <tsippy.mendelson at intel dot com> and
20  *              Amir Noam <amir.noam at intel dot com>
21  *      - Code beautification and style changes (mainly in comments).
22  *
23  * 2003/05/01 - Shmulik Hen <shmulik.hen at intel dot com>
24  *      - Added support for Transmit load balancing mode.
25  *
26  * 2003/12/01 - Shmulik Hen <shmulik.hen at intel dot com>
27  *      - Code cleanup and style changes
28  *
29  * 2005/05/05 - Jason Gabler <jygabler at lbl dot gov>
30  *      - added "xmit_policy" kernel parameter for alternate hashing policy
31  *        support for mode 2
32  */
33
34 #ifndef _LINUX_BONDING_H
35 #define _LINUX_BONDING_H
36
37 #include <linux/timer.h>
38 #include <linux/proc_fs.h>
39 #include <linux/if_bonding.h>
40 #include "bond_3ad.h"
41 #include "bond_alb.h"
42
43 #define DRV_VERSION     "2.6.4"
44 #define DRV_RELDATE     "September 26, 2005"
45 #define DRV_NAME        "bonding"
46 #define DRV_DESCRIPTION "Ethernet Channel Bonding Driver"
47
48 #define BOND_MAX_ARP_TARGETS    16
49
50 #ifdef BONDING_DEBUG
51 #define dprintk(fmt, args...) \
52         printk(KERN_DEBUG     \
53                DRV_NAME ": %s() %d: " fmt, __FUNCTION__, __LINE__ , ## args )
54 #else
55 #define dprintk(fmt, args...)
56 #endif /* BONDING_DEBUG */
57
58 #define IS_UP(dev)                                         \
59               ((((dev)->flags & IFF_UP) == IFF_UP)      && \
60                netif_running(dev)                       && \
61                netif_carrier_ok(dev))
62
63 /*
64  * Checks whether bond is ready for transmit.
65  *
66  * Caller must hold bond->lock
67  */
68 #define BOND_IS_OK(bond)                             \
69                    (((bond)->dev->flags & IFF_UP) && \
70                     netif_running((bond)->dev)    && \
71                     ((bond)->slave_cnt > 0))
72
73 /*
74  * Checks whether slave is ready for transmit.
75  */
76 #define SLAVE_IS_OK(slave)                              \
77                     (((slave)->dev->flags & IFF_UP)  && \
78                      netif_running((slave)->dev)     && \
79                      ((slave)->link == BOND_LINK_UP) && \
80                      ((slave)->state == BOND_STATE_ACTIVE))
81
82
83 #define USES_PRIMARY(mode)                              \
84                 (((mode) == BOND_MODE_ACTIVEBACKUP) ||  \
85                  ((mode) == BOND_MODE_TLB)          ||  \
86                  ((mode) == BOND_MODE_ALB))
87
88 /*
89  * Less bad way to call ioctl from within the kernel; this needs to be
90  * done some other way to get the call out of interrupt context.
91  * Needs "ioctl" variable to be supplied by calling context.
92  */
93 #define IOCTL(dev, arg, cmd) ({         \
94         int res = 0;                    \
95         mm_segment_t fs = get_fs();     \
96         set_fs(get_ds());               \
97         res = ioctl(dev, arg, cmd);     \
98         set_fs(fs);                     \
99         res; })
100
101 /**
102  * bond_for_each_slave_from - iterate the slaves list from a starting point
103  * @bond:       the bond holding this list.
104  * @pos:        current slave.
105  * @cnt:        counter for max number of moves
106  * @start:      starting point.
107  *
108  * Caller must hold bond->lock
109  */
110 #define bond_for_each_slave_from(bond, pos, cnt, start) \
111         for (cnt = 0, pos = start;                              \
112              cnt < (bond)->slave_cnt;                           \
113              cnt++, pos = (pos)->next)
114
115 /**
116  * bond_for_each_slave_from_to - iterate the slaves list from start point to stop point
117  * @bond:       the bond holding this list.
118  * @pos:        current slave.
119  * @cnt:        counter for number max of moves
120  * @start:      start point.
121  * @stop:       stop point.
122  *
123  * Caller must hold bond->lock
124  */
125 #define bond_for_each_slave_from_to(bond, pos, cnt, start, stop)        \
126         for (cnt = 0, pos = start;                                      \
127              ((cnt < (bond)->slave_cnt) && (pos != (stop)->next));      \
128              cnt++, pos = (pos)->next)
129
130 /**
131  * bond_for_each_slave - iterate the slaves list from head
132  * @bond:       the bond holding this list.
133  * @pos:        current slave.
134  * @cnt:        counter for max number of moves
135  *
136  * Caller must hold bond->lock
137  */
138 #define bond_for_each_slave(bond, pos, cnt)     \
139                 bond_for_each_slave_from(bond, pos, cnt, (bond)->first_slave)
140
141
142 struct bond_params {
143         int mode;
144         int xmit_policy;
145         int miimon;
146         int arp_interval;
147         int use_carrier;
148         int updelay;
149         int downdelay;
150         int lacp_fast;
151         char primary[IFNAMSIZ];
152         u32 arp_targets[BOND_MAX_ARP_TARGETS];
153 };
154
155 struct vlan_entry {
156         struct list_head vlan_list;
157         u32 vlan_ip;
158         unsigned short vlan_id;
159 };
160
161 struct slave {
162         struct net_device *dev; /* first - usefull for panic debug */
163         struct slave *next;
164         struct slave *prev;
165         s16    delay;
166         u32    jiffies;
167         s8     link;    /* one of BOND_LINK_XXXX */
168         s8     state;   /* one of BOND_STATE_XXXX */
169         u32    original_flags;
170         u32    link_failure_count;
171         u16    speed;
172         u8     duplex;
173         u8     perm_hwaddr[ETH_ALEN];
174         struct ad_slave_info ad_info; /* HUGE - better to dynamically alloc */
175         struct tlb_slave_info tlb_info;
176 };
177
178 /*
179  * Here are the locking policies for the two bonding locks:
180  *
181  * 1) Get bond->lock when reading/writing slave list.
182  * 2) Get bond->curr_slave_lock when reading/writing bond->curr_active_slave.
183  *    (It is unnecessary when the write-lock is put with bond->lock.)
184  * 3) When we lock with bond->curr_slave_lock, we must lock with bond->lock
185  *    beforehand.
186  */
187 struct bonding {
188         struct   net_device *dev; /* first - usefull for panic debug */
189         struct   slave *first_slave;
190         struct   slave *curr_active_slave;
191         struct   slave *current_arp_slave;
192         struct   slave *primary_slave;
193         s32      slave_cnt; /* never change this value outside the attach/detach wrappers */
194         rwlock_t lock;
195         rwlock_t curr_slave_lock;
196         struct   timer_list mii_timer;
197         struct   timer_list arp_timer;
198         s8       kill_timers;
199         struct   net_device_stats stats;
200 #ifdef CONFIG_PROC_FS
201         struct   proc_dir_entry *proc_entry;
202         char     proc_file_name[IFNAMSIZ];
203 #endif /* CONFIG_PROC_FS */
204         struct   list_head bond_list;
205         struct   dev_mc_list *mc_list;
206         int      (*xmit_hash_policy)(struct sk_buff *, struct net_device *, int);
207         u32      master_ip;
208         u16      flags;
209         struct   ad_bond_info ad_info;
210         struct   alb_bond_info alb_info;
211         struct   bond_params params;
212         struct   list_head vlan_list;
213         struct   vlan_group *vlgrp;
214         /* the features the bonding device supports, independently 
215          * of any slaves */
216         int      bond_features; 
217 };
218
219 /**
220  * Returns NULL if the net_device does not belong to any of the bond's slaves
221  *
222  * Caller must hold bond lock for read
223  */
224 extern inline struct slave *bond_get_slave_by_dev(struct bonding *bond, struct net_device *slave_dev)
225 {
226         struct slave *slave = NULL;
227         int i;
228
229         bond_for_each_slave(bond, slave, i) {
230                 if (slave->dev == slave_dev) {
231                         break;
232                 }
233         }
234
235         return slave;
236 }
237
238 extern inline struct bonding *bond_get_bond_by_slave(struct slave *slave)
239 {
240         if (!slave || !slave->dev->master) {
241                 return NULL;
242         }
243
244         return (struct bonding *)slave->dev->master->priv;
245 }
246
247 extern inline void bond_set_slave_inactive_flags(struct slave *slave)
248 {
249         slave->state = BOND_STATE_BACKUP;
250         slave->dev->flags |= IFF_NOARP;
251 }
252
253 extern inline void bond_set_slave_active_flags(struct slave *slave)
254 {
255         slave->state = BOND_STATE_ACTIVE;
256         slave->dev->flags &= ~IFF_NOARP;
257 }
258
259 struct vlan_entry *bond_next_vlan(struct bonding *bond, struct vlan_entry *curr);
260 int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, struct net_device *slave_dev);
261
262 #endif /* _LINUX_BONDING_H */
263