blob: 6558af22eda48734a6a8329cb0c83685eaa25838 [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
28 */
29
30#ifndef _LINUX_BONDING_H
31#define _LINUX_BONDING_H
32
33#include <linux/timer.h>
34#include <linux/proc_fs.h>
35#include <linux/if_bonding.h>
36#include "bond_3ad.h"
37#include "bond_alb.h"
38
Jay Vosburghc3ade5c2005-06-26 17:52:20 -040039#define DRV_VERSION "2.6.2"
40#define DRV_RELDATE "June 5, 2005"
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#define DRV_NAME "bonding"
42#define DRV_DESCRIPTION "Ethernet Channel Bonding Driver"
43
44#define BOND_MAX_ARP_TARGETS 16
45
46#ifdef BONDING_DEBUG
47#define dprintk(fmt, args...) \
48 printk(KERN_DEBUG \
49 DRV_NAME ": %s() %d: " fmt, __FUNCTION__, __LINE__ , ## args )
50#else
51#define dprintk(fmt, args...)
52#endif /* BONDING_DEBUG */
53
54#define IS_UP(dev) \
55 ((((dev)->flags & IFF_UP) == IFF_UP) && \
56 netif_running(dev) && \
57 netif_carrier_ok(dev))
58
59/*
60 * Checks whether bond is ready for transmit.
61 *
62 * Caller must hold bond->lock
63 */
64#define BOND_IS_OK(bond) \
65 (((bond)->dev->flags & IFF_UP) && \
66 netif_running((bond)->dev) && \
67 ((bond)->slave_cnt > 0))
68
69/*
70 * Checks whether slave is ready for transmit.
71 */
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))
77
78
79#define USES_PRIMARY(mode) \
80 (((mode) == BOND_MODE_ACTIVEBACKUP) || \
81 ((mode) == BOND_MODE_TLB) || \
82 ((mode) == BOND_MODE_ALB))
83
84/*
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.
88 */
89#define IOCTL(dev, arg, cmd) ({ \
90 int res = 0; \
91 mm_segment_t fs = get_fs(); \
92 set_fs(get_ds()); \
93 res = ioctl(dev, arg, cmd); \
94 set_fs(fs); \
95 res; })
96
97/**
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.
103 *
104 * Caller must hold bond->lock
105 */
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)
110
111/**
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.
117 * @stop: stop point.
118 *
119 * Caller must hold bond->lock
120 */
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)
125
126/**
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
131 *
132 * Caller must hold bond->lock
133 */
134#define bond_for_each_slave(bond, pos, cnt) \
135 bond_for_each_slave_from(bond, pos, cnt, (bond)->first_slave)
136
137
138struct bond_params {
139 int mode;
140 int miimon;
141 int arp_interval;
142 int use_carrier;
143 int updelay;
144 int downdelay;
145 int lacp_fast;
146 char primary[IFNAMSIZ];
147 u32 arp_targets[BOND_MAX_ARP_TARGETS];
148};
149
150struct vlan_entry {
151 struct list_head vlan_list;
Jay Vosburghc3ade5c2005-06-26 17:52:20 -0400152 u32 vlan_ip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 unsigned short vlan_id;
154};
155
156struct slave {
157 struct net_device *dev; /* first - usefull for panic debug */
158 struct slave *next;
159 struct slave *prev;
160 s16 delay;
161 u32 jiffies;
162 s8 link; /* one of BOND_LINK_XXXX */
163 s8 state; /* one of BOND_STATE_XXXX */
164 u32 original_flags;
165 u32 link_failure_count;
166 u16 speed;
167 u8 duplex;
168 u8 perm_hwaddr[ETH_ALEN];
169 struct ad_slave_info ad_info; /* HUGE - better to dynamically alloc */
170 struct tlb_slave_info tlb_info;
171};
172
173/*
174 * Here are the locking policies for the two bonding locks:
175 *
176 * 1) Get bond->lock when reading/writing slave list.
177 * 2) Get bond->curr_slave_lock when reading/writing bond->curr_active_slave.
178 * (It is unnecessary when the write-lock is put with bond->lock.)
179 * 3) When we lock with bond->curr_slave_lock, we must lock with bond->lock
180 * beforehand.
181 */
182struct bonding {
183 struct net_device *dev; /* first - usefull for panic debug */
184 struct slave *first_slave;
185 struct slave *curr_active_slave;
186 struct slave *current_arp_slave;
187 struct slave *primary_slave;
188 s32 slave_cnt; /* never change this value outside the attach/detach wrappers */
189 rwlock_t lock;
190 rwlock_t curr_slave_lock;
191 struct timer_list mii_timer;
192 struct timer_list arp_timer;
193 s8 kill_timers;
194 struct net_device_stats stats;
195#ifdef CONFIG_PROC_FS
196 struct proc_dir_entry *proc_entry;
197 char proc_file_name[IFNAMSIZ];
198#endif /* CONFIG_PROC_FS */
199 struct list_head bond_list;
200 struct dev_mc_list *mc_list;
Jay Vosburghc3ade5c2005-06-26 17:52:20 -0400201 u32 master_ip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 u16 flags;
203 struct ad_bond_info ad_info;
204 struct alb_bond_info alb_info;
205 struct bond_params params;
206 struct list_head vlan_list;
207 struct vlan_group *vlgrp;
208};
209
210/**
211 * Returns NULL if the net_device does not belong to any of the bond's slaves
212 *
213 * Caller must hold bond lock for read
214 */
215extern inline struct slave *bond_get_slave_by_dev(struct bonding *bond, struct net_device *slave_dev)
216{
217 struct slave *slave = NULL;
218 int i;
219
220 bond_for_each_slave(bond, slave, i) {
221 if (slave->dev == slave_dev) {
222 break;
223 }
224 }
225
226 return slave;
227}
228
229extern inline struct bonding *bond_get_bond_by_slave(struct slave *slave)
230{
231 if (!slave || !slave->dev->master) {
232 return NULL;
233 }
234
235 return (struct bonding *)slave->dev->master->priv;
236}
237
238extern inline void bond_set_slave_inactive_flags(struct slave *slave)
239{
240 slave->state = BOND_STATE_BACKUP;
241 slave->dev->flags |= IFF_NOARP;
242}
243
244extern inline void bond_set_slave_active_flags(struct slave *slave)
245{
246 slave->state = BOND_STATE_ACTIVE;
247 slave->dev->flags &= ~IFF_NOARP;
248}
249
250struct vlan_entry *bond_next_vlan(struct bonding *bond, struct vlan_entry *curr);
251int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, struct net_device *slave_dev);
252
253#endif /* _LINUX_BONDING_H */
254