blob: 903e60aa611ef266f38bd86330c0c690ad5ba3a9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Jay Vosburgh169a3e62005-06-26 17:54:11 -040028 *
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 */
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>
Mitch Williamsb76cdba2005-11-09 10:36:41 -080040#include <linux/kobject.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include "bond_3ad.h"
42#include "bond_alb.h"
43
Jay Vosburgh8e3babc2005-11-04 18:45:45 -080044#define DRV_VERSION "2.6.5"
45#define DRV_RELDATE "November 4, 2005"
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#define DRV_NAME "bonding"
47#define DRV_DESCRIPTION "Ethernet Channel Bonding Driver"
48
49#define BOND_MAX_ARP_TARGETS 16
50
51#ifdef BONDING_DEBUG
52#define dprintk(fmt, args...) \
53 printk(KERN_DEBUG \
54 DRV_NAME ": %s() %d: " fmt, __FUNCTION__, __LINE__ , ## args )
55#else
56#define dprintk(fmt, args...)
57#endif /* BONDING_DEBUG */
58
59#define IS_UP(dev) \
60 ((((dev)->flags & IFF_UP) == IFF_UP) && \
61 netif_running(dev) && \
62 netif_carrier_ok(dev))
63
64/*
65 * Checks whether bond is ready for transmit.
66 *
67 * Caller must hold bond->lock
68 */
69#define BOND_IS_OK(bond) \
70 (((bond)->dev->flags & IFF_UP) && \
71 netif_running((bond)->dev) && \
72 ((bond)->slave_cnt > 0))
73
74/*
75 * Checks whether slave is ready for transmit.
76 */
77#define SLAVE_IS_OK(slave) \
78 (((slave)->dev->flags & IFF_UP) && \
79 netif_running((slave)->dev) && \
80 ((slave)->link == BOND_LINK_UP) && \
81 ((slave)->state == BOND_STATE_ACTIVE))
82
83
84#define USES_PRIMARY(mode) \
85 (((mode) == BOND_MODE_ACTIVEBACKUP) || \
86 ((mode) == BOND_MODE_TLB) || \
87 ((mode) == BOND_MODE_ALB))
88
89/*
90 * Less bad way to call ioctl from within the kernel; this needs to be
91 * done some other way to get the call out of interrupt context.
92 * Needs "ioctl" variable to be supplied by calling context.
93 */
94#define IOCTL(dev, arg, cmd) ({ \
95 int res = 0; \
96 mm_segment_t fs = get_fs(); \
97 set_fs(get_ds()); \
98 res = ioctl(dev, arg, cmd); \
99 set_fs(fs); \
100 res; })
101
102/**
103 * bond_for_each_slave_from - iterate the slaves list from a starting point
104 * @bond: the bond holding this list.
105 * @pos: current slave.
106 * @cnt: counter for max number of moves
107 * @start: starting point.
108 *
109 * Caller must hold bond->lock
110 */
111#define bond_for_each_slave_from(bond, pos, cnt, start) \
112 for (cnt = 0, pos = start; \
113 cnt < (bond)->slave_cnt; \
114 cnt++, pos = (pos)->next)
115
116/**
117 * bond_for_each_slave_from_to - iterate the slaves list from start point to stop point
118 * @bond: the bond holding this list.
119 * @pos: current slave.
120 * @cnt: counter for number max of moves
121 * @start: start point.
122 * @stop: stop point.
123 *
124 * Caller must hold bond->lock
125 */
126#define bond_for_each_slave_from_to(bond, pos, cnt, start, stop) \
127 for (cnt = 0, pos = start; \
128 ((cnt < (bond)->slave_cnt) && (pos != (stop)->next)); \
129 cnt++, pos = (pos)->next)
130
131/**
132 * bond_for_each_slave - iterate the slaves list from head
133 * @bond: the bond holding this list.
134 * @pos: current slave.
135 * @cnt: counter for max number of moves
136 *
137 * Caller must hold bond->lock
138 */
139#define bond_for_each_slave(bond, pos, cnt) \
140 bond_for_each_slave_from(bond, pos, cnt, (bond)->first_slave)
141
142
143struct bond_params {
144 int mode;
Jay Vosburgh169a3e62005-06-26 17:54:11 -0400145 int xmit_policy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 int miimon;
147 int arp_interval;
148 int use_carrier;
149 int updelay;
150 int downdelay;
151 int lacp_fast;
152 char primary[IFNAMSIZ];
153 u32 arp_targets[BOND_MAX_ARP_TARGETS];
154};
155
Mitch Williams12479f92005-11-09 10:35:44 -0800156struct bond_parm_tbl {
157 char *modename;
158 int mode;
159};
160
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161struct vlan_entry {
162 struct list_head vlan_list;
Jay Vosburghc3ade5c2005-06-26 17:52:20 -0400163 u32 vlan_ip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 unsigned short vlan_id;
165};
166
167struct slave {
168 struct net_device *dev; /* first - usefull for panic debug */
169 struct slave *next;
170 struct slave *prev;
171 s16 delay;
172 u32 jiffies;
173 s8 link; /* one of BOND_LINK_XXXX */
174 s8 state; /* one of BOND_STATE_XXXX */
175 u32 original_flags;
176 u32 link_failure_count;
177 u16 speed;
178 u8 duplex;
179 u8 perm_hwaddr[ETH_ALEN];
180 struct ad_slave_info ad_info; /* HUGE - better to dynamically alloc */
181 struct tlb_slave_info tlb_info;
182};
183
184/*
185 * Here are the locking policies for the two bonding locks:
186 *
187 * 1) Get bond->lock when reading/writing slave list.
188 * 2) Get bond->curr_slave_lock when reading/writing bond->curr_active_slave.
189 * (It is unnecessary when the write-lock is put with bond->lock.)
190 * 3) When we lock with bond->curr_slave_lock, we must lock with bond->lock
191 * beforehand.
192 */
193struct bonding {
194 struct net_device *dev; /* first - usefull for panic debug */
195 struct slave *first_slave;
196 struct slave *curr_active_slave;
197 struct slave *current_arp_slave;
198 struct slave *primary_slave;
199 s32 slave_cnt; /* never change this value outside the attach/detach wrappers */
200 rwlock_t lock;
201 rwlock_t curr_slave_lock;
202 struct timer_list mii_timer;
203 struct timer_list arp_timer;
204 s8 kill_timers;
205 struct net_device_stats stats;
206#ifdef CONFIG_PROC_FS
207 struct proc_dir_entry *proc_entry;
208 char proc_file_name[IFNAMSIZ];
209#endif /* CONFIG_PROC_FS */
210 struct list_head bond_list;
211 struct dev_mc_list *mc_list;
Jay Vosburgh169a3e62005-06-26 17:54:11 -0400212 int (*xmit_hash_policy)(struct sk_buff *, struct net_device *, int);
Jay Vosburghc3ade5c2005-06-26 17:52:20 -0400213 u32 master_ip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 u16 flags;
215 struct ad_bond_info ad_info;
216 struct alb_bond_info alb_info;
217 struct bond_params params;
218 struct list_head vlan_list;
219 struct vlan_group *vlgrp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220};
221
222/**
223 * Returns NULL if the net_device does not belong to any of the bond's slaves
224 *
225 * Caller must hold bond lock for read
226 */
227extern inline struct slave *bond_get_slave_by_dev(struct bonding *bond, struct net_device *slave_dev)
228{
229 struct slave *slave = NULL;
230 int i;
231
232 bond_for_each_slave(bond, slave, i) {
233 if (slave->dev == slave_dev) {
234 break;
235 }
236 }
237
238 return slave;
239}
240
241extern inline struct bonding *bond_get_bond_by_slave(struct slave *slave)
242{
243 if (!slave || !slave->dev->master) {
244 return NULL;
245 }
246
247 return (struct bonding *)slave->dev->master->priv;
248}
249
250extern inline void bond_set_slave_inactive_flags(struct slave *slave)
251{
252 slave->state = BOND_STATE_BACKUP;
253 slave->dev->flags |= IFF_NOARP;
254}
255
256extern inline void bond_set_slave_active_flags(struct slave *slave)
257{
258 slave->state = BOND_STATE_ACTIVE;
259 slave->dev->flags &= ~IFF_NOARP;
260}
261
262struct vlan_entry *bond_next_vlan(struct bonding *bond, struct vlan_entry *curr);
263int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, struct net_device *slave_dev);
Mitch Williamsdfe60392005-11-09 10:36:04 -0800264int bond_create(char *name, struct bond_params *params, struct bonding **newbond);
Mitch Williamsa77b5322005-11-09 10:35:51 -0800265void bond_deinit(struct net_device *bond_dev);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800266int bond_create_sysfs(void);
267void bond_destroy_sysfs(void);
268void bond_destroy_sysfs_entry(struct bonding *bond);
269int bond_create_sysfs_entry(struct bonding *bond);
270int bond_create_slave_symlinks(struct net_device *master, struct net_device *slave);
271void bond_destroy_slave_symlinks(struct net_device *master, struct net_device *slave);
Mitch Williamsa77b5322005-11-09 10:35:51 -0800272int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev);
273int bond_release(struct net_device *bond_dev, struct net_device *slave_dev);
274int bond_sethwaddr(struct net_device *bond_dev, struct net_device *slave_dev);
275void bond_mii_monitor(struct net_device *bond_dev);
276void bond_loadbalance_arp_mon(struct net_device *bond_dev);
277void bond_activebackup_arp_mon(struct net_device *bond_dev);
278void bond_set_mode_ops(struct bonding *bond, int mode);
279int bond_parse_parm(char *mode_arg, struct bond_parm_tbl *tbl);
280const char *bond_mode_name(int mode);
281void bond_select_active_slave(struct bonding *bond);
282void bond_change_active_slave(struct bonding *bond, struct slave *new_active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284#endif /* _LINUX_BONDING_H */
285