ipoib.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. /*
  2. * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. *
  32. * $Id: ipoib.h 1358 2004-12-17 22:00:11Z roland $
  33. */
  34. #ifndef _IPOIB_H
  35. #define _IPOIB_H
  36. #include <linux/list.h>
  37. #include <linux/skbuff.h>
  38. #include <linux/netdevice.h>
  39. #include <linux/workqueue.h>
  40. #include <linux/pci.h>
  41. #include <linux/config.h>
  42. #include <linux/kref.h>
  43. #include <linux/if_infiniband.h>
  44. #include <net/neighbour.h>
  45. #include <asm/atomic.h>
  46. #include <asm/semaphore.h>
  47. #include <ib_verbs.h>
  48. #include <ib_pack.h>
  49. #include <ib_sa.h>
  50. /* constants */
  51. enum {
  52. IPOIB_PACKET_SIZE = 2048,
  53. IPOIB_BUF_SIZE = IPOIB_PACKET_SIZE + IB_GRH_BYTES,
  54. IPOIB_ENCAP_LEN = 4,
  55. IPOIB_RX_RING_SIZE = 128,
  56. IPOIB_TX_RING_SIZE = 64,
  57. IPOIB_NUM_WC = 4,
  58. IPOIB_MAX_PATH_REC_QUEUE = 3,
  59. IPOIB_MAX_MCAST_QUEUE = 3,
  60. IPOIB_FLAG_OPER_UP = 0,
  61. IPOIB_FLAG_ADMIN_UP = 1,
  62. IPOIB_PKEY_ASSIGNED = 2,
  63. IPOIB_PKEY_STOP = 3,
  64. IPOIB_FLAG_SUBINTERFACE = 4,
  65. IPOIB_MCAST_RUN = 5,
  66. IPOIB_STOP_REAPER = 6,
  67. IPOIB_MAX_BACKOFF_SECONDS = 16,
  68. IPOIB_MCAST_FLAG_FOUND = 0, /* used in set_multicast_list */
  69. IPOIB_MCAST_FLAG_SENDONLY = 1,
  70. IPOIB_MCAST_FLAG_BUSY = 2, /* joining or already joined */
  71. IPOIB_MCAST_FLAG_ATTACHED = 3,
  72. };
  73. /* structs */
  74. struct ipoib_header {
  75. u16 proto;
  76. u16 reserved;
  77. };
  78. struct ipoib_pseudoheader {
  79. u8 hwaddr[INFINIBAND_ALEN];
  80. };
  81. struct ipoib_mcast;
  82. struct ipoib_buf {
  83. struct sk_buff *skb;
  84. DECLARE_PCI_UNMAP_ADDR(mapping)
  85. };
  86. /*
  87. * Device private locking: tx_lock protects members used in TX fast
  88. * path (and we use LLTX so upper layers don't do extra locking).
  89. * lock protects everything else. lock nests inside of tx_lock (ie
  90. * tx_lock must be acquired first if needed).
  91. */
  92. struct ipoib_dev_priv {
  93. spinlock_t lock;
  94. struct net_device *dev;
  95. unsigned long flags;
  96. struct semaphore mcast_mutex;
  97. struct semaphore vlan_mutex;
  98. struct rb_root path_tree;
  99. struct list_head path_list;
  100. struct ipoib_mcast *broadcast;
  101. struct list_head multicast_list;
  102. struct rb_root multicast_tree;
  103. struct work_struct pkey_task;
  104. struct work_struct mcast_task;
  105. struct work_struct flush_task;
  106. struct work_struct restart_task;
  107. struct work_struct ah_reap_task;
  108. struct ib_device *ca;
  109. u8 port;
  110. u16 pkey;
  111. struct ib_pd *pd;
  112. struct ib_mr *mr;
  113. struct ib_cq *cq;
  114. struct ib_qp *qp;
  115. u32 qkey;
  116. union ib_gid local_gid;
  117. u16 local_lid;
  118. u8 local_rate;
  119. unsigned int admin_mtu;
  120. unsigned int mcast_mtu;
  121. struct ipoib_buf *rx_ring;
  122. spinlock_t tx_lock;
  123. struct ipoib_buf *tx_ring;
  124. unsigned tx_head;
  125. unsigned tx_tail;
  126. struct ib_sge tx_sge;
  127. struct ib_send_wr tx_wr;
  128. struct ib_wc ibwc[IPOIB_NUM_WC];
  129. struct list_head dead_ahs;
  130. struct ib_event_handler event_handler;
  131. struct net_device_stats stats;
  132. struct net_device *parent;
  133. struct list_head child_intfs;
  134. struct list_head list;
  135. #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
  136. struct list_head fs_list;
  137. struct dentry *mcg_dentry;
  138. #endif
  139. };
  140. struct ipoib_ah {
  141. struct net_device *dev;
  142. struct ib_ah *ah;
  143. struct list_head list;
  144. struct kref ref;
  145. unsigned last_send;
  146. };
  147. struct ipoib_path {
  148. struct net_device *dev;
  149. struct ib_sa_path_rec pathrec;
  150. struct ipoib_ah *ah;
  151. struct sk_buff_head queue;
  152. struct list_head neigh_list;
  153. int query_id;
  154. struct ib_sa_query *query;
  155. struct completion done;
  156. struct rb_node rb_node;
  157. struct list_head list;
  158. };
  159. struct ipoib_neigh {
  160. struct ipoib_ah *ah;
  161. struct sk_buff_head queue;
  162. struct neighbour *neighbour;
  163. struct list_head list;
  164. };
  165. static inline struct ipoib_neigh **to_ipoib_neigh(struct neighbour *neigh)
  166. {
  167. return (struct ipoib_neigh **) (neigh->ha + 24 -
  168. (offsetof(struct neighbour, ha) & 4));
  169. }
  170. extern struct workqueue_struct *ipoib_workqueue;
  171. /* functions */
  172. void ipoib_ib_completion(struct ib_cq *cq, void *dev_ptr);
  173. struct ipoib_ah *ipoib_create_ah(struct net_device *dev,
  174. struct ib_pd *pd, struct ib_ah_attr *attr);
  175. void ipoib_free_ah(struct kref *kref);
  176. static inline void ipoib_put_ah(struct ipoib_ah *ah)
  177. {
  178. kref_put(&ah->ref, ipoib_free_ah);
  179. }
  180. int ipoib_add_pkey_attr(struct net_device *dev);
  181. void ipoib_send(struct net_device *dev, struct sk_buff *skb,
  182. struct ipoib_ah *address, u32 qpn);
  183. void ipoib_reap_ah(void *dev_ptr);
  184. void ipoib_flush_paths(struct net_device *dev);
  185. struct ipoib_dev_priv *ipoib_intf_alloc(const char *format);
  186. int ipoib_ib_dev_init(struct net_device *dev, struct ib_device *ca, int port);
  187. void ipoib_ib_dev_flush(void *dev);
  188. void ipoib_ib_dev_cleanup(struct net_device *dev);
  189. int ipoib_ib_dev_open(struct net_device *dev);
  190. int ipoib_ib_dev_up(struct net_device *dev);
  191. int ipoib_ib_dev_down(struct net_device *dev);
  192. int ipoib_ib_dev_stop(struct net_device *dev);
  193. int ipoib_dev_init(struct net_device *dev, struct ib_device *ca, int port);
  194. void ipoib_dev_cleanup(struct net_device *dev);
  195. void ipoib_mcast_join_task(void *dev_ptr);
  196. void ipoib_mcast_send(struct net_device *dev, union ib_gid *mgid,
  197. struct sk_buff *skb);
  198. void ipoib_mcast_restart_task(void *dev_ptr);
  199. int ipoib_mcast_start_thread(struct net_device *dev);
  200. int ipoib_mcast_stop_thread(struct net_device *dev);
  201. void ipoib_mcast_dev_down(struct net_device *dev);
  202. void ipoib_mcast_dev_flush(struct net_device *dev);
  203. struct ipoib_mcast_iter *ipoib_mcast_iter_init(struct net_device *dev);
  204. void ipoib_mcast_iter_free(struct ipoib_mcast_iter *iter);
  205. int ipoib_mcast_iter_next(struct ipoib_mcast_iter *iter);
  206. void ipoib_mcast_iter_read(struct ipoib_mcast_iter *iter,
  207. union ib_gid *gid,
  208. unsigned long *created,
  209. unsigned int *queuelen,
  210. unsigned int *complete,
  211. unsigned int *send_only);
  212. int ipoib_mcast_attach(struct net_device *dev, u16 mlid,
  213. union ib_gid *mgid);
  214. int ipoib_mcast_detach(struct net_device *dev, u16 mlid,
  215. union ib_gid *mgid);
  216. int ipoib_qp_create(struct net_device *dev);
  217. int ipoib_transport_dev_init(struct net_device *dev, struct ib_device *ca);
  218. void ipoib_transport_dev_cleanup(struct net_device *dev);
  219. void ipoib_event(struct ib_event_handler *handler,
  220. struct ib_event *record);
  221. int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey);
  222. int ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey);
  223. void ipoib_pkey_poll(void *dev);
  224. int ipoib_pkey_dev_delay_open(struct net_device *dev);
  225. #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
  226. int ipoib_create_debug_file(struct net_device *dev);
  227. void ipoib_delete_debug_file(struct net_device *dev);
  228. int ipoib_register_debugfs(void);
  229. void ipoib_unregister_debugfs(void);
  230. #else
  231. static inline int ipoib_create_debug_file(struct net_device *dev) { return 0; }
  232. static inline void ipoib_delete_debug_file(struct net_device *dev) { }
  233. static inline int ipoib_register_debugfs(void) { return 0; }
  234. static inline void ipoib_unregister_debugfs(void) { }
  235. #endif
  236. #define ipoib_printk(level, priv, format, arg...) \
  237. printk(level "%s: " format, ((struct ipoib_dev_priv *) priv)->dev->name , ## arg)
  238. #define ipoib_warn(priv, format, arg...) \
  239. ipoib_printk(KERN_WARNING, priv, format , ## arg)
  240. #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
  241. extern int ipoib_debug_level;
  242. #define ipoib_dbg(priv, format, arg...) \
  243. do { \
  244. if (ipoib_debug_level > 0) \
  245. ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
  246. } while (0)
  247. #define ipoib_dbg_mcast(priv, format, arg...) \
  248. do { \
  249. if (mcast_debug_level > 0) \
  250. ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
  251. } while (0)
  252. #else /* CONFIG_INFINIBAND_IPOIB_DEBUG */
  253. #define ipoib_dbg(priv, format, arg...) \
  254. do { (void) (priv); } while (0)
  255. #define ipoib_dbg_mcast(priv, format, arg...) \
  256. do { (void) (priv); } while (0)
  257. #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG */
  258. #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA
  259. #define ipoib_dbg_data(priv, format, arg...) \
  260. do { \
  261. if (data_debug_level > 0) \
  262. ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
  263. } while (0)
  264. #else /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */
  265. #define ipoib_dbg_data(priv, format, arg...) \
  266. do { (void) (priv); } while (0)
  267. #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */
  268. #define IPOIB_GID_FMT "%x:%x:%x:%x:%x:%x:%x:%x"
  269. #define IPOIB_GID_ARG(gid) be16_to_cpup((__be16 *) ((gid).raw + 0)), \
  270. be16_to_cpup((__be16 *) ((gid).raw + 2)), \
  271. be16_to_cpup((__be16 *) ((gid).raw + 4)), \
  272. be16_to_cpup((__be16 *) ((gid).raw + 6)), \
  273. be16_to_cpup((__be16 *) ((gid).raw + 8)), \
  274. be16_to_cpup((__be16 *) ((gid).raw + 10)), \
  275. be16_to_cpup((__be16 *) ((gid).raw + 12)), \
  276. be16_to_cpup((__be16 *) ((gid).raw + 14))
  277. #endif /* _IPOIB_H */