bonding.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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.3"
  41. #define DRV_RELDATE "June 8, 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 vlan_entry {
  139. struct list_head vlan_list;
  140. u32 vlan_ip;
  141. unsigned short vlan_id;
  142. };
  143. struct slave {
  144. struct net_device *dev; /* first - usefull for panic debug */
  145. struct slave *next;
  146. struct slave *prev;
  147. s16 delay;
  148. u32 jiffies;
  149. s8 link; /* one of BOND_LINK_XXXX */
  150. s8 state; /* one of BOND_STATE_XXXX */
  151. u32 original_flags;
  152. u32 link_failure_count;
  153. u16 speed;
  154. u8 duplex;
  155. u8 perm_hwaddr[ETH_ALEN];
  156. struct ad_slave_info ad_info; /* HUGE - better to dynamically alloc */
  157. struct tlb_slave_info tlb_info;
  158. };
  159. /*
  160. * Here are the locking policies for the two bonding locks:
  161. *
  162. * 1) Get bond->lock when reading/writing slave list.
  163. * 2) Get bond->curr_slave_lock when reading/writing bond->curr_active_slave.
  164. * (It is unnecessary when the write-lock is put with bond->lock.)
  165. * 3) When we lock with bond->curr_slave_lock, we must lock with bond->lock
  166. * beforehand.
  167. */
  168. struct bonding {
  169. struct net_device *dev; /* first - usefull for panic debug */
  170. struct slave *first_slave;
  171. struct slave *curr_active_slave;
  172. struct slave *current_arp_slave;
  173. struct slave *primary_slave;
  174. s32 slave_cnt; /* never change this value outside the attach/detach wrappers */
  175. rwlock_t lock;
  176. rwlock_t curr_slave_lock;
  177. struct timer_list mii_timer;
  178. struct timer_list arp_timer;
  179. s8 kill_timers;
  180. struct net_device_stats stats;
  181. #ifdef CONFIG_PROC_FS
  182. struct proc_dir_entry *proc_entry;
  183. char proc_file_name[IFNAMSIZ];
  184. #endif /* CONFIG_PROC_FS */
  185. struct list_head bond_list;
  186. struct dev_mc_list *mc_list;
  187. int (*xmit_hash_policy)(struct sk_buff *, struct net_device *, int);
  188. u32 master_ip;
  189. u16 flags;
  190. struct ad_bond_info ad_info;
  191. struct alb_bond_info alb_info;
  192. struct bond_params params;
  193. struct list_head vlan_list;
  194. struct vlan_group *vlgrp;
  195. /* the features the bonding device supports, independently
  196. * of any slaves */
  197. int bond_features;
  198. };
  199. /**
  200. * Returns NULL if the net_device does not belong to any of the bond's slaves
  201. *
  202. * Caller must hold bond lock for read
  203. */
  204. extern inline struct slave *bond_get_slave_by_dev(struct bonding *bond, struct net_device *slave_dev)
  205. {
  206. struct slave *slave = NULL;
  207. int i;
  208. bond_for_each_slave(bond, slave, i) {
  209. if (slave->dev == slave_dev) {
  210. break;
  211. }
  212. }
  213. return slave;
  214. }
  215. extern inline struct bonding *bond_get_bond_by_slave(struct slave *slave)
  216. {
  217. if (!slave || !slave->dev->master) {
  218. return NULL;
  219. }
  220. return (struct bonding *)slave->dev->master->priv;
  221. }
  222. extern inline void bond_set_slave_inactive_flags(struct slave *slave)
  223. {
  224. slave->state = BOND_STATE_BACKUP;
  225. slave->dev->flags |= IFF_NOARP;
  226. }
  227. extern inline void bond_set_slave_active_flags(struct slave *slave)
  228. {
  229. slave->state = BOND_STATE_ACTIVE;
  230. slave->dev->flags &= ~IFF_NOARP;
  231. }
  232. struct vlan_entry *bond_next_vlan(struct bonding *bond, struct vlan_entry *curr);
  233. int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, struct net_device *slave_dev);
  234. #endif /* _LINUX_BONDING_H */