[go: nahoru, domu]

bonding.h revision 12479f9a823dc7d791f198af2d3e4efae418a65e
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.5"
44#define DRV_RELDATE	"November 4, 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
142struct 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
155struct bond_parm_tbl {
156	char *modename;
157	int mode;
158};
159
160struct vlan_entry {
161	struct list_head vlan_list;
162	u32 vlan_ip;
163	unsigned short vlan_id;
164};
165
166struct slave {
167	struct net_device *dev; /* first - usefull for panic debug */
168	struct slave *next;
169	struct slave *prev;
170	s16    delay;
171	u32    jiffies;
172	s8     link;    /* one of BOND_LINK_XXXX */
173	s8     state;   /* one of BOND_STATE_XXXX */
174	u32    original_flags;
175	u32    link_failure_count;
176	u16    speed;
177	u8     duplex;
178	u8     perm_hwaddr[ETH_ALEN];
179	struct ad_slave_info ad_info; /* HUGE - better to dynamically alloc */
180	struct tlb_slave_info tlb_info;
181};
182
183/*
184 * Here are the locking policies for the two bonding locks:
185 *
186 * 1) Get bond->lock when reading/writing slave list.
187 * 2) Get bond->curr_slave_lock when reading/writing bond->curr_active_slave.
188 *    (It is unnecessary when the write-lock is put with bond->lock.)
189 * 3) When we lock with bond->curr_slave_lock, we must lock with bond->lock
190 *    beforehand.
191 */
192struct bonding {
193	struct   net_device *dev; /* first - usefull for panic debug */
194	struct   slave *first_slave;
195	struct   slave *curr_active_slave;
196	struct   slave *current_arp_slave;
197	struct   slave *primary_slave;
198	s32      slave_cnt; /* never change this value outside the attach/detach wrappers */
199	rwlock_t lock;
200	rwlock_t curr_slave_lock;
201	struct   timer_list mii_timer;
202	struct   timer_list arp_timer;
203	s8       kill_timers;
204	struct   net_device_stats stats;
205#ifdef CONFIG_PROC_FS
206	struct   proc_dir_entry *proc_entry;
207	char     proc_file_name[IFNAMSIZ];
208#endif /* CONFIG_PROC_FS */
209	struct   list_head bond_list;
210	struct   dev_mc_list *mc_list;
211	int      (*xmit_hash_policy)(struct sk_buff *, struct net_device *, int);
212	u32      master_ip;
213	u16      flags;
214	struct   ad_bond_info ad_info;
215	struct   alb_bond_info alb_info;
216	struct   bond_params params;
217	struct   list_head vlan_list;
218	struct   vlan_group *vlgrp;
219};
220
221/**
222 * Returns NULL if the net_device does not belong to any of the bond's slaves
223 *
224 * Caller must hold bond lock for read
225 */
226extern inline struct slave *bond_get_slave_by_dev(struct bonding *bond, struct net_device *slave_dev)
227{
228	struct slave *slave = NULL;
229	int i;
230
231	bond_for_each_slave(bond, slave, i) {
232		if (slave->dev == slave_dev) {
233			break;
234		}
235	}
236
237	return slave;
238}
239
240extern inline struct bonding *bond_get_bond_by_slave(struct slave *slave)
241{
242	if (!slave || !slave->dev->master) {
243		return NULL;
244	}
245
246	return (struct bonding *)slave->dev->master->priv;
247}
248
249extern inline void bond_set_slave_inactive_flags(struct slave *slave)
250{
251	slave->state = BOND_STATE_BACKUP;
252	slave->dev->flags |= IFF_NOARP;
253}
254
255extern inline void bond_set_slave_active_flags(struct slave *slave)
256{
257	slave->state = BOND_STATE_ACTIVE;
258	slave->dev->flags &= ~IFF_NOARP;
259}
260
261struct vlan_entry *bond_next_vlan(struct bonding *bond, struct vlan_entry *curr);
262int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, struct net_device *slave_dev);
263
264#endif /* _LINUX_BONDING_H */
265
266