bonding.h 6.9 KB

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