bonding.h 8.5 KB

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