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
30 #ifndef _LINUX_BONDING_H
31 #define _LINUX_BONDING_H
33 #include <linux/timer.h>
34 #include <linux/proc_fs.h>
35 #include <linux/if_bonding.h>
39 #define DRV_VERSION "2.6.1"
40 #define DRV_RELDATE "October 29, 2004"
41 #define DRV_NAME "bonding"
42 #define DRV_DESCRIPTION "Ethernet Channel Bonding Driver"
44 #define BOND_MAX_ARP_TARGETS 16
47 #define dprintk(fmt, args...) \
49 DRV_NAME ": %s() %d: " fmt, __FUNCTION__, __LINE__ , ## args )
51 #define dprintk(fmt, args...)
52 #endif /* BONDING_DEBUG */
55 ((((dev)->flags & IFF_UP) == IFF_UP) && \
56 netif_running(dev) && \
57 netif_carrier_ok(dev))
60 * Checks whether bond is ready for transmit.
62 * Caller must hold bond->lock
64 #define BOND_IS_OK(bond) \
65 (((bond)->dev->flags & IFF_UP) && \
66 netif_running((bond)->dev) && \
67 ((bond)->slave_cnt > 0))
70 * Checks whether slave is ready for transmit.
72 #define SLAVE_IS_OK(slave) \
73 (((slave)->dev->flags & IFF_UP) && \
74 netif_running((slave)->dev) && \
75 ((slave)->link == BOND_LINK_UP) && \
76 ((slave)->state == BOND_STATE_ACTIVE))
79 #define USES_PRIMARY(mode) \
80 (((mode) == BOND_MODE_ACTIVEBACKUP) || \
81 ((mode) == BOND_MODE_TLB) || \
82 ((mode) == BOND_MODE_ALB))
85 * Less bad way to call ioctl from within the kernel; this needs to be
86 * done some other way to get the call out of interrupt context.
87 * Needs "ioctl" variable to be supplied by calling context.
89 #define IOCTL(dev, arg, cmd) ({ \
91 mm_segment_t fs = get_fs(); \
93 res = ioctl(dev, arg, cmd); \
98 * bond_for_each_slave_from - iterate the slaves list from a starting point
99 * @bond: the bond holding this list.
100 * @pos: current slave.
101 * @cnt: counter for max number of moves
102 * @start: starting point.
104 * Caller must hold bond->lock
106 #define bond_for_each_slave_from(bond, pos, cnt, start) \
107 for (cnt = 0, pos = start; \
108 cnt < (bond)->slave_cnt; \
109 cnt++, pos = (pos)->next)
112 * bond_for_each_slave_from_to - iterate the slaves list from start point to stop point
113 * @bond: the bond holding this list.
114 * @pos: current slave.
115 * @cnt: counter for number max of moves
116 * @start: start point.
119 * Caller must hold bond->lock
121 #define bond_for_each_slave_from_to(bond, pos, cnt, start, stop) \
122 for (cnt = 0, pos = start; \
123 ((cnt < (bond)->slave_cnt) && (pos != (stop)->next)); \
124 cnt++, pos = (pos)->next)
127 * bond_for_each_slave - iterate the slaves list from head
128 * @bond: the bond holding this list.
129 * @pos: current slave.
130 * @cnt: counter for max number of moves
132 * Caller must hold bond->lock
134 #define bond_for_each_slave(bond, pos, cnt) \
135 bond_for_each_slave_from(bond, pos, cnt, (bond)->first_slave)
146 char primary
[IFNAMSIZ
];
147 u32 arp_targets
[BOND_MAX_ARP_TARGETS
];
151 struct list_head vlan_list
;
152 unsigned short vlan_id
;
156 struct net_device
*dev
; /* first - usefull for panic debug */
161 s8 link
; /* one of BOND_LINK_XXXX */
162 s8 state
; /* one of BOND_STATE_XXXX */
164 u32 link_failure_count
;
167 u8 perm_hwaddr
[ETH_ALEN
];
168 struct ad_slave_info ad_info
; /* HUGE - better to dynamically alloc */
169 struct tlb_slave_info tlb_info
;
173 * Here are the locking policies for the two bonding locks:
175 * 1) Get bond->lock when reading/writing slave list.
176 * 2) Get bond->curr_slave_lock when reading/writing bond->curr_active_slave.
177 * (It is unnecessary when the write-lock is put with bond->lock.)
178 * 3) When we lock with bond->curr_slave_lock, we must lock with bond->lock
182 struct net_device
*dev
; /* first - usefull for panic debug */
183 struct slave
*first_slave
;
184 struct slave
*curr_active_slave
;
185 struct slave
*current_arp_slave
;
186 struct slave
*primary_slave
;
187 s32 slave_cnt
; /* never change this value outside the attach/detach wrappers */
189 rwlock_t curr_slave_lock
;
190 struct timer_list mii_timer
;
191 struct timer_list arp_timer
;
193 struct net_device_stats stats
;
194 #ifdef CONFIG_PROC_FS
195 struct proc_dir_entry
*proc_entry
;
196 char proc_file_name
[IFNAMSIZ
];
197 #endif /* CONFIG_PROC_FS */
198 struct list_head bond_list
;
199 struct dev_mc_list
*mc_list
;
201 struct ad_bond_info ad_info
;
202 struct alb_bond_info alb_info
;
203 struct bond_params params
;
204 struct list_head vlan_list
;
205 struct vlan_group
*vlgrp
;
209 * Returns NULL if the net_device does not belong to any of the bond's slaves
211 * Caller must hold bond lock for read
213 extern inline struct slave
*bond_get_slave_by_dev(struct bonding
*bond
, struct net_device
*slave_dev
)
215 struct slave
*slave
= NULL
;
218 bond_for_each_slave(bond
, slave
, i
) {
219 if (slave
->dev
== slave_dev
) {
227 extern inline struct bonding
*bond_get_bond_by_slave(struct slave
*slave
)
229 if (!slave
|| !slave
->dev
->master
) {
233 return (struct bonding
*)slave
->dev
->master
->priv
;
236 extern inline void bond_set_slave_inactive_flags(struct slave
*slave
)
238 slave
->state
= BOND_STATE_BACKUP
;
239 slave
->dev
->flags
|= IFF_NOARP
;
242 extern inline void bond_set_slave_active_flags(struct slave
*slave
)
244 slave
->state
= BOND_STATE_ACTIVE
;
245 slave
->dev
->flags
&= ~IFF_NOARP
;
248 struct vlan_entry
*bond_next_vlan(struct bonding
*bond
, struct vlan_entry
*curr
);
249 int bond_dev_queue_xmit(struct bonding
*bond
, struct sk_buff
*skb
, struct net_device
*slave_dev
);
251 #endif /* _LINUX_BONDING_H */