2 * Bond several ethernet interfaces into a Cisco, running 'Etherchannel'.
4 * Portions are (c) Copyright 1995 Simon "Guru Aleph-Null" Janes
5 * NCM: Network and Communications Management, Inc.
7 * BUT, I'm the one who modified it for ethernet, so:
8 * (c) Copyright 1999, Thomas Davis, tadavis@lbl.gov
10 * This software may be used and distributed according to the terms
11 * of the GNU Public License, incorporated herein by reference.
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.
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).
23 * 2003/05/01 - Shmulik Hen <shmulik.hen at intel dot com>
24 * - Added support for Transmit load balancing mode.
26 * 2003/12/01 - Shmulik Hen <shmulik.hen at intel dot com>
27 * - Code cleanup and style changes
29 * 2005/05/05 - Jason Gabler <jygabler at lbl dot gov>
30 * - added "xmit_policy" kernel parameter for alternate hashing policy
34 #ifndef _LINUX_BONDING_H
35 #define _LINUX_BONDING_H
37 #include <linux/timer.h>
38 #include <linux/proc_fs.h>
39 #include <linux/if_bonding.h>
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"
48 #define BOND_MAX_ARP_TARGETS 16
51 #define dprintk(fmt, args...) \
53 DRV_NAME ": %s() %d: " fmt, __FUNCTION__, __LINE__ , ## args )
55 #define dprintk(fmt, args...)
56 #endif /* BONDING_DEBUG */
59 ((((dev)->flags & IFF_UP) == IFF_UP) && \
60 netif_running(dev) && \
61 netif_carrier_ok(dev))
64 * Checks whether bond is ready for transmit.
66 * Caller must hold bond->lock
68 #define BOND_IS_OK(bond) \
69 (((bond)->dev->flags & IFF_UP) && \
70 netif_running((bond)->dev) && \
71 ((bond)->slave_cnt > 0))
74 * Checks whether slave is ready for transmit.
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))
83 #define USES_PRIMARY(mode) \
84 (((mode) == BOND_MODE_ACTIVEBACKUP) || \
85 ((mode) == BOND_MODE_TLB) || \
86 ((mode) == BOND_MODE_ALB))
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.
93 #define IOCTL(dev, arg, cmd) ({ \
95 mm_segment_t fs = get_fs(); \
97 res = ioctl(dev, arg, cmd); \
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.
108 * Caller must hold bond->lock
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)
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.
123 * Caller must hold bond->lock
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)
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
136 * Caller must hold bond->lock
138 #define bond_for_each_slave(bond, pos, cnt) \
139 bond_for_each_slave_from(bond, pos, cnt, (bond)->first_slave)
151 char primary
[IFNAMSIZ
];
152 u32 arp_targets
[BOND_MAX_ARP_TARGETS
];
156 struct list_head vlan_list
;
158 unsigned short vlan_id
;
162 struct net_device
*dev
; /* first - usefull for panic debug */
167 s8 link
; /* one of BOND_LINK_XXXX */
168 s8 state
; /* one of BOND_STATE_XXXX */
170 u32 link_failure_count
;
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
;
179 * Here are the locking policies for the two bonding locks:
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
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 */
195 rwlock_t curr_slave_lock
;
196 struct timer_list mii_timer
;
197 struct timer_list arp_timer
;
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);
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
220 * Returns NULL if the net_device does not belong to any of the bond's slaves
222 * Caller must hold bond lock for read
224 extern inline struct slave
*bond_get_slave_by_dev(struct bonding
*bond
, struct net_device
*slave_dev
)
226 struct slave
*slave
= NULL
;
229 bond_for_each_slave(bond
, slave
, i
) {
230 if (slave
->dev
== slave_dev
) {
238 extern inline struct bonding
*bond_get_bond_by_slave(struct slave
*slave
)
240 if (!slave
|| !slave
->dev
->master
) {
244 return (struct bonding
*)slave
->dev
->master
->priv
;
247 extern inline void bond_set_slave_inactive_flags(struct slave
*slave
)
249 slave
->state
= BOND_STATE_BACKUP
;
250 slave
->dev
->flags
|= IFF_NOARP
;
253 extern inline void bond_set_slave_active_flags(struct slave
*slave
)
255 slave
->state
= BOND_STATE_ACTIVE
;
256 slave
->dev
->flags
&= ~IFF_NOARP
;
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
);
262 #endif /* _LINUX_BONDING_H */