ipoib.h 11 KB

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