bonding.h 8.0 KB

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