aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/bonding/bonding.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/net/bonding/bonding.h
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/net/bonding/bonding.h')
-rw-r--r--drivers/net/bonding/bonding.h252
1 files changed, 252 insertions, 0 deletions
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
new file mode 100644
index 000000000000..8c325308489d
--- /dev/null
+++ b/drivers/net/bonding/bonding.h
@@ -0,0 +1,252 @@
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
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
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"
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;
152 unsigned short vlan_id;
153};
154
155struct slave {
156 struct net_device *dev; /* first - usefull for panic debug */
157 struct slave *next;
158 struct slave *prev;
159 s16 delay;
160 u32 jiffies;
161 s8 link; /* one of BOND_LINK_XXXX */
162 s8 state; /* one of BOND_STATE_XXXX */
163 u32 original_flags;
164 u32 link_failure_count;
165 u16 speed;
166 u8 duplex;
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;
170};
171
172/*
173 * Here are the locking policies for the two bonding locks:
174 *
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
179 * beforehand.
180 */
181struct bonding {
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 */
188 rwlock_t lock;
189 rwlock_t curr_slave_lock;
190 struct timer_list mii_timer;
191 struct timer_list arp_timer;
192 s8 kill_timers;
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;
200 u16 flags;
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;
206};
207
208/**
209 * Returns NULL if the net_device does not belong to any of the bond's slaves
210 *
211 * Caller must hold bond lock for read
212 */
213extern inline struct slave *bond_get_slave_by_dev(struct bonding *bond, struct net_device *slave_dev)
214{
215 struct slave *slave = NULL;
216 int i;
217
218 bond_for_each_slave(bond, slave, i) {
219 if (slave->dev == slave_dev) {
220 break;
221 }
222 }
223
224 return slave;
225}
226
227extern inline struct bonding *bond_get_bond_by_slave(struct slave *slave)
228{
229 if (!slave || !slave->dev->master) {
230 return NULL;
231 }
232
233 return (struct bonding *)slave->dev->master->priv;
234}
235
236extern inline void bond_set_slave_inactive_flags(struct slave *slave)
237{
238 slave->state = BOND_STATE_BACKUP;
239 slave->dev->flags |= IFF_NOARP;
240}
241
242extern inline void bond_set_slave_active_flags(struct slave *slave)
243{
244 slave->state = BOND_STATE_ACTIVE;
245 slave->dev->flags &= ~IFF_NOARP;
246}
247
248struct vlan_entry *bond_next_vlan(struct bonding *bond, struct vlan_entry *curr);
249int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, struct net_device *slave_dev);
250
251#endif /* _LINUX_BONDING_H */
252