ipoib.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  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. #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/kref.h>
  41. #include <linux/if_infiniband.h>
  42. #include <linux/mutex.h>
  43. #include <net/neighbour.h>
  44. #include <net/sch_generic.h>
  45. #include <linux/atomic.h>
  46. #include <rdma/ib_verbs.h>
  47. #include <rdma/ib_pack.h>
  48. #include <rdma/ib_sa.h>
  49. #include <linux/sched.h>
  50. /* constants */
  51. enum ipoib_flush_level {
  52. IPOIB_FLUSH_LIGHT,
  53. IPOIB_FLUSH_NORMAL,
  54. IPOIB_FLUSH_HEAVY
  55. };
  56. enum {
  57. IPOIB_ENCAP_LEN = 4,
  58. IPOIB_UD_HEAD_SIZE = IB_GRH_BYTES + IPOIB_ENCAP_LEN,
  59. IPOIB_UD_RX_SG = 2, /* max buffer needed for 4K mtu */
  60. IPOIB_CM_MTU = 0x10000 - 0x10, /* padding to align header to 16 */
  61. IPOIB_CM_BUF_SIZE = IPOIB_CM_MTU + IPOIB_ENCAP_LEN,
  62. IPOIB_CM_HEAD_SIZE = IPOIB_CM_BUF_SIZE % PAGE_SIZE,
  63. IPOIB_CM_RX_SG = ALIGN(IPOIB_CM_BUF_SIZE, PAGE_SIZE) / PAGE_SIZE,
  64. IPOIB_RX_RING_SIZE = 256,
  65. IPOIB_TX_RING_SIZE = 128,
  66. IPOIB_MAX_QUEUE_SIZE = 8192,
  67. IPOIB_MIN_QUEUE_SIZE = 2,
  68. IPOIB_CM_MAX_CONN_QP = 4096,
  69. IPOIB_NUM_WC = 4,
  70. IPOIB_MAX_PATH_REC_QUEUE = 3,
  71. IPOIB_MAX_MCAST_QUEUE = 3,
  72. IPOIB_FLAG_OPER_UP = 0,
  73. IPOIB_FLAG_INITIALIZED = 1,
  74. IPOIB_FLAG_ADMIN_UP = 2,
  75. IPOIB_PKEY_ASSIGNED = 3,
  76. IPOIB_PKEY_STOP = 4,
  77. IPOIB_FLAG_SUBINTERFACE = 5,
  78. IPOIB_MCAST_RUN = 6,
  79. IPOIB_STOP_REAPER = 7,
  80. IPOIB_FLAG_ADMIN_CM = 9,
  81. IPOIB_FLAG_UMCAST = 10,
  82. IPOIB_STOP_NEIGH_GC = 11,
  83. IPOIB_NEIGH_TBL_FLUSH = 12,
  84. IPOIB_MAX_BACKOFF_SECONDS = 16,
  85. IPOIB_MCAST_FLAG_FOUND = 0, /* used in set_multicast_list */
  86. IPOIB_MCAST_FLAG_SENDONLY = 1,
  87. IPOIB_MCAST_FLAG_BUSY = 2, /* joining or already joined */
  88. IPOIB_MCAST_FLAG_ATTACHED = 3,
  89. MAX_SEND_CQE = 16,
  90. IPOIB_CM_COPYBREAK = 256,
  91. };
  92. #define IPOIB_OP_RECV (1ul << 31)
  93. #ifdef CONFIG_INFINIBAND_IPOIB_CM
  94. #define IPOIB_OP_CM (1ul << 30)
  95. #else
  96. #define IPOIB_OP_CM (0)
  97. #endif
  98. /* structs */
  99. struct ipoib_header {
  100. __be16 proto;
  101. u16 reserved;
  102. };
  103. struct ipoib_cb {
  104. struct qdisc_skb_cb qdisc_cb;
  105. u8 hwaddr[INFINIBAND_ALEN];
  106. };
  107. /* Used for all multicast joins (broadcast, IPv4 mcast and IPv6 mcast) */
  108. struct ipoib_mcast {
  109. struct ib_sa_mcmember_rec mcmember;
  110. struct ib_sa_multicast *mc;
  111. struct ipoib_ah *ah;
  112. struct rb_node rb_node;
  113. struct list_head list;
  114. unsigned long created;
  115. unsigned long backoff;
  116. unsigned long flags;
  117. unsigned char logcount;
  118. struct list_head neigh_list;
  119. struct sk_buff_head pkt_queue;
  120. struct net_device *dev;
  121. };
  122. struct ipoib_rx_buf {
  123. struct sk_buff *skb;
  124. u64 mapping[IPOIB_UD_RX_SG];
  125. };
  126. struct ipoib_tx_buf {
  127. struct sk_buff *skb;
  128. u64 mapping[MAX_SKB_FRAGS + 1];
  129. };
  130. struct ipoib_cm_tx_buf {
  131. struct sk_buff *skb;
  132. u64 mapping;
  133. };
  134. struct ib_cm_id;
  135. struct ipoib_cm_data {
  136. __be32 qpn; /* High byte MUST be ignored on receive */
  137. __be32 mtu;
  138. };
  139. /*
  140. * Quoting 10.3.1 Queue Pair and EE Context States:
  141. *
  142. * Note, for QPs that are associated with an SRQ, the Consumer should take the
  143. * QP through the Error State before invoking a Destroy QP or a Modify QP to the
  144. * Reset State. The Consumer may invoke the Destroy QP without first performing
  145. * a Modify QP to the Error State and waiting for the Affiliated Asynchronous
  146. * Last WQE Reached Event. However, if the Consumer does not wait for the
  147. * Affiliated Asynchronous Last WQE Reached Event, then WQE and Data Segment
  148. * leakage may occur. Therefore, it is good programming practice to tear down a
  149. * QP that is associated with an SRQ by using the following process:
  150. *
  151. * - Put the QP in the Error State
  152. * - Wait for the Affiliated Asynchronous Last WQE Reached Event;
  153. * - either:
  154. * drain the CQ by invoking the Poll CQ verb and either wait for CQ
  155. * to be empty or the number of Poll CQ operations has exceeded
  156. * CQ capacity size;
  157. * - or
  158. * post another WR that completes on the same CQ and wait for this
  159. * WR to return as a WC;
  160. * - and then invoke a Destroy QP or Reset QP.
  161. *
  162. * We use the second option and wait for a completion on the
  163. * same CQ before destroying QPs attached to our SRQ.
  164. */
  165. enum ipoib_cm_state {
  166. IPOIB_CM_RX_LIVE,
  167. IPOIB_CM_RX_ERROR, /* Ignored by stale task */
  168. IPOIB_CM_RX_FLUSH /* Last WQE Reached event observed */
  169. };
  170. struct ipoib_cm_rx {
  171. struct ib_cm_id *id;
  172. struct ib_qp *qp;
  173. struct ipoib_cm_rx_buf *rx_ring;
  174. struct list_head list;
  175. struct net_device *dev;
  176. unsigned long jiffies;
  177. enum ipoib_cm_state state;
  178. int recv_count;
  179. };
  180. struct ipoib_cm_tx {
  181. struct ib_cm_id *id;
  182. struct ib_qp *qp;
  183. struct list_head list;
  184. struct net_device *dev;
  185. struct ipoib_neigh *neigh;
  186. struct ipoib_path *path;
  187. struct ipoib_cm_tx_buf *tx_ring;
  188. unsigned tx_head;
  189. unsigned tx_tail;
  190. unsigned long flags;
  191. u32 mtu;
  192. };
  193. struct ipoib_cm_rx_buf {
  194. struct sk_buff *skb;
  195. u64 mapping[IPOIB_CM_RX_SG];
  196. };
  197. struct ipoib_cm_dev_priv {
  198. struct ib_srq *srq;
  199. struct ipoib_cm_rx_buf *srq_ring;
  200. struct ib_cm_id *id;
  201. struct list_head passive_ids; /* state: LIVE */
  202. struct list_head rx_error_list; /* state: ERROR */
  203. struct list_head rx_flush_list; /* state: FLUSH, drain not started */
  204. struct list_head rx_drain_list; /* state: FLUSH, drain started */
  205. struct list_head rx_reap_list; /* state: FLUSH, drain done */
  206. struct work_struct start_task;
  207. struct work_struct reap_task;
  208. struct work_struct skb_task;
  209. struct work_struct rx_reap_task;
  210. struct delayed_work stale_task;
  211. struct sk_buff_head skb_queue;
  212. struct list_head start_list;
  213. struct list_head reap_list;
  214. struct ib_wc ibwc[IPOIB_NUM_WC];
  215. struct ib_sge rx_sge[IPOIB_CM_RX_SG];
  216. struct ib_recv_wr rx_wr;
  217. int nonsrq_conn_qp;
  218. int max_cm_mtu;
  219. int num_frags;
  220. };
  221. struct ipoib_ethtool_st {
  222. u16 coalesce_usecs;
  223. u16 max_coalesced_frames;
  224. };
  225. struct ipoib_neigh_table;
  226. struct ipoib_neigh_hash {
  227. struct ipoib_neigh_table *ntbl;
  228. struct ipoib_neigh __rcu **buckets;
  229. struct rcu_head rcu;
  230. u32 mask;
  231. u32 size;
  232. };
  233. struct ipoib_neigh_table {
  234. struct ipoib_neigh_hash __rcu *htbl;
  235. rwlock_t rwlock;
  236. atomic_t entries;
  237. struct completion flushed;
  238. struct completion deleted;
  239. };
  240. /*
  241. * Device private locking: network stack tx_lock protects members used
  242. * in TX fast path, lock protects everything else. lock nests inside
  243. * of tx_lock (ie tx_lock must be acquired first if needed).
  244. */
  245. struct ipoib_dev_priv {
  246. spinlock_t lock;
  247. struct net_device *dev;
  248. struct napi_struct napi;
  249. unsigned long flags;
  250. struct mutex vlan_mutex;
  251. struct rb_root path_tree;
  252. struct list_head path_list;
  253. struct ipoib_neigh_table ntbl;
  254. struct ipoib_mcast *broadcast;
  255. struct list_head multicast_list;
  256. struct rb_root multicast_tree;
  257. struct delayed_work pkey_poll_task;
  258. struct delayed_work mcast_task;
  259. struct work_struct carrier_on_task;
  260. struct work_struct flush_light;
  261. struct work_struct flush_normal;
  262. struct work_struct flush_heavy;
  263. struct work_struct restart_task;
  264. struct delayed_work ah_reap_task;
  265. struct delayed_work neigh_reap_task;
  266. struct ib_device *ca;
  267. u8 port;
  268. u16 pkey;
  269. u16 pkey_index;
  270. struct ib_pd *pd;
  271. struct ib_mr *mr;
  272. struct ib_cq *recv_cq;
  273. struct ib_cq *send_cq;
  274. struct ib_qp *qp;
  275. u32 qkey;
  276. union ib_gid local_gid;
  277. u16 local_lid;
  278. unsigned int admin_mtu;
  279. unsigned int mcast_mtu;
  280. unsigned int max_ib_mtu;
  281. struct ipoib_rx_buf *rx_ring;
  282. struct ipoib_tx_buf *tx_ring;
  283. unsigned tx_head;
  284. unsigned tx_tail;
  285. struct ib_sge tx_sge[MAX_SKB_FRAGS + 1];
  286. struct ib_send_wr tx_wr;
  287. unsigned tx_outstanding;
  288. struct ib_wc send_wc[MAX_SEND_CQE];
  289. struct ib_recv_wr rx_wr;
  290. struct ib_sge rx_sge[IPOIB_UD_RX_SG];
  291. struct ib_wc ibwc[IPOIB_NUM_WC];
  292. struct list_head dead_ahs;
  293. struct ib_event_handler event_handler;
  294. struct net_device *parent;
  295. struct list_head child_intfs;
  296. struct list_head list;
  297. #ifdef CONFIG_INFINIBAND_IPOIB_CM
  298. struct ipoib_cm_dev_priv cm;
  299. #endif
  300. #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
  301. struct list_head fs_list;
  302. struct dentry *mcg_dentry;
  303. struct dentry *path_dentry;
  304. #endif
  305. int hca_caps;
  306. struct ipoib_ethtool_st ethtool;
  307. struct timer_list poll_timer;
  308. };
  309. struct ipoib_ah {
  310. struct net_device *dev;
  311. struct ib_ah *ah;
  312. struct list_head list;
  313. struct kref ref;
  314. unsigned last_send;
  315. };
  316. struct ipoib_path {
  317. struct net_device *dev;
  318. struct ib_sa_path_rec pathrec;
  319. struct ipoib_ah *ah;
  320. struct sk_buff_head queue;
  321. struct list_head neigh_list;
  322. int query_id;
  323. struct ib_sa_query *query;
  324. struct completion done;
  325. struct rb_node rb_node;
  326. struct list_head list;
  327. int valid;
  328. };
  329. struct ipoib_neigh {
  330. struct ipoib_ah *ah;
  331. #ifdef CONFIG_INFINIBAND_IPOIB_CM
  332. struct ipoib_cm_tx *cm;
  333. #endif
  334. u8 daddr[INFINIBAND_ALEN];
  335. struct sk_buff_head queue;
  336. struct net_device *dev;
  337. struct list_head list;
  338. struct ipoib_neigh __rcu *hnext;
  339. struct rcu_head rcu;
  340. atomic_t refcnt;
  341. unsigned long alive;
  342. };
  343. #define IPOIB_UD_MTU(ib_mtu) (ib_mtu - IPOIB_ENCAP_LEN)
  344. #define IPOIB_UD_BUF_SIZE(ib_mtu) (ib_mtu + IB_GRH_BYTES)
  345. static inline int ipoib_ud_need_sg(unsigned int ib_mtu)
  346. {
  347. return IPOIB_UD_BUF_SIZE(ib_mtu) > PAGE_SIZE;
  348. }
  349. void ipoib_neigh_dtor(struct ipoib_neigh *neigh);
  350. static inline void ipoib_neigh_put(struct ipoib_neigh *neigh)
  351. {
  352. if (atomic_dec_and_test(&neigh->refcnt))
  353. ipoib_neigh_dtor(neigh);
  354. }
  355. struct ipoib_neigh *ipoib_neigh_get(struct net_device *dev, u8 *daddr);
  356. struct ipoib_neigh *ipoib_neigh_alloc(u8 *daddr,
  357. struct net_device *dev);
  358. void ipoib_neigh_free(struct ipoib_neigh *neigh);
  359. void ipoib_del_neighs_by_gid(struct net_device *dev, u8 *gid);
  360. extern struct workqueue_struct *ipoib_workqueue;
  361. /* functions */
  362. int ipoib_poll(struct napi_struct *napi, int budget);
  363. void ipoib_ib_completion(struct ib_cq *cq, void *dev_ptr);
  364. void ipoib_send_comp_handler(struct ib_cq *cq, void *dev_ptr);
  365. struct ipoib_ah *ipoib_create_ah(struct net_device *dev,
  366. struct ib_pd *pd, struct ib_ah_attr *attr);
  367. void ipoib_free_ah(struct kref *kref);
  368. static inline void ipoib_put_ah(struct ipoib_ah *ah)
  369. {
  370. kref_put(&ah->ref, ipoib_free_ah);
  371. }
  372. int ipoib_open(struct net_device *dev);
  373. int ipoib_add_pkey_attr(struct net_device *dev);
  374. int ipoib_add_umcast_attr(struct net_device *dev);
  375. void ipoib_send(struct net_device *dev, struct sk_buff *skb,
  376. struct ipoib_ah *address, u32 qpn);
  377. void ipoib_reap_ah(struct work_struct *work);
  378. void ipoib_mark_paths_invalid(struct net_device *dev);
  379. void ipoib_flush_paths(struct net_device *dev);
  380. struct ipoib_dev_priv *ipoib_intf_alloc(const char *format);
  381. int ipoib_ib_dev_init(struct net_device *dev, struct ib_device *ca, int port);
  382. void ipoib_ib_dev_flush_light(struct work_struct *work);
  383. void ipoib_ib_dev_flush_normal(struct work_struct *work);
  384. void ipoib_ib_dev_flush_heavy(struct work_struct *work);
  385. void ipoib_pkey_event(struct work_struct *work);
  386. void ipoib_ib_dev_cleanup(struct net_device *dev);
  387. int ipoib_ib_dev_open(struct net_device *dev);
  388. int ipoib_ib_dev_up(struct net_device *dev);
  389. int ipoib_ib_dev_down(struct net_device *dev, int flush);
  390. int ipoib_ib_dev_stop(struct net_device *dev, int flush);
  391. int ipoib_dev_init(struct net_device *dev, struct ib_device *ca, int port);
  392. void ipoib_dev_cleanup(struct net_device *dev);
  393. void ipoib_mcast_join_task(struct work_struct *work);
  394. void ipoib_mcast_carrier_on_task(struct work_struct *work);
  395. void ipoib_mcast_send(struct net_device *dev, u8 *daddr, struct sk_buff *skb);
  396. void ipoib_mcast_restart_task(struct work_struct *work);
  397. int ipoib_mcast_start_thread(struct net_device *dev);
  398. int ipoib_mcast_stop_thread(struct net_device *dev, int flush);
  399. void ipoib_mcast_dev_down(struct net_device *dev);
  400. void ipoib_mcast_dev_flush(struct net_device *dev);
  401. #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
  402. struct ipoib_mcast_iter *ipoib_mcast_iter_init(struct net_device *dev);
  403. int ipoib_mcast_iter_next(struct ipoib_mcast_iter *iter);
  404. void ipoib_mcast_iter_read(struct ipoib_mcast_iter *iter,
  405. union ib_gid *gid,
  406. unsigned long *created,
  407. unsigned int *queuelen,
  408. unsigned int *complete,
  409. unsigned int *send_only);
  410. struct ipoib_path_iter *ipoib_path_iter_init(struct net_device *dev);
  411. int ipoib_path_iter_next(struct ipoib_path_iter *iter);
  412. void ipoib_path_iter_read(struct ipoib_path_iter *iter,
  413. struct ipoib_path *path);
  414. #endif
  415. int ipoib_mcast_attach(struct net_device *dev, u16 mlid,
  416. union ib_gid *mgid, int set_qkey);
  417. int ipoib_init_qp(struct net_device *dev);
  418. int ipoib_transport_dev_init(struct net_device *dev, struct ib_device *ca);
  419. void ipoib_transport_dev_cleanup(struct net_device *dev);
  420. void ipoib_event(struct ib_event_handler *handler,
  421. struct ib_event *record);
  422. int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey);
  423. int ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey);
  424. void ipoib_pkey_poll(struct work_struct *work);
  425. int ipoib_pkey_dev_delay_open(struct net_device *dev);
  426. void ipoib_drain_cq(struct net_device *dev);
  427. void ipoib_set_ethtool_ops(struct net_device *dev);
  428. int ipoib_set_dev_features(struct ipoib_dev_priv *priv, struct ib_device *hca);
  429. #ifdef CONFIG_INFINIBAND_IPOIB_CM
  430. #define IPOIB_FLAGS_RC 0x80
  431. #define IPOIB_FLAGS_UC 0x40
  432. /* We don't support UC connections at the moment */
  433. #define IPOIB_CM_SUPPORTED(ha) (ha[0] & (IPOIB_FLAGS_RC))
  434. extern int ipoib_max_conn_qp;
  435. static inline int ipoib_cm_admin_enabled(struct net_device *dev)
  436. {
  437. struct ipoib_dev_priv *priv = netdev_priv(dev);
  438. return IPOIB_CM_SUPPORTED(dev->dev_addr) &&
  439. test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags);
  440. }
  441. static inline int ipoib_cm_enabled(struct net_device *dev, u8 *hwaddr)
  442. {
  443. struct ipoib_dev_priv *priv = netdev_priv(dev);
  444. return IPOIB_CM_SUPPORTED(hwaddr) &&
  445. test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags);
  446. }
  447. static inline int ipoib_cm_up(struct ipoib_neigh *neigh)
  448. {
  449. return test_bit(IPOIB_FLAG_OPER_UP, &neigh->cm->flags);
  450. }
  451. static inline struct ipoib_cm_tx *ipoib_cm_get(struct ipoib_neigh *neigh)
  452. {
  453. return neigh->cm;
  454. }
  455. static inline void ipoib_cm_set(struct ipoib_neigh *neigh, struct ipoib_cm_tx *tx)
  456. {
  457. neigh->cm = tx;
  458. }
  459. static inline int ipoib_cm_has_srq(struct net_device *dev)
  460. {
  461. struct ipoib_dev_priv *priv = netdev_priv(dev);
  462. return !!priv->cm.srq;
  463. }
  464. static inline unsigned int ipoib_cm_max_mtu(struct net_device *dev)
  465. {
  466. struct ipoib_dev_priv *priv = netdev_priv(dev);
  467. return priv->cm.max_cm_mtu;
  468. }
  469. void ipoib_cm_send(struct net_device *dev, struct sk_buff *skb, struct ipoib_cm_tx *tx);
  470. int ipoib_cm_dev_open(struct net_device *dev);
  471. void ipoib_cm_dev_stop(struct net_device *dev);
  472. int ipoib_cm_dev_init(struct net_device *dev);
  473. int ipoib_cm_add_mode_attr(struct net_device *dev);
  474. void ipoib_cm_dev_cleanup(struct net_device *dev);
  475. struct ipoib_cm_tx *ipoib_cm_create_tx(struct net_device *dev, struct ipoib_path *path,
  476. struct ipoib_neigh *neigh);
  477. void ipoib_cm_destroy_tx(struct ipoib_cm_tx *tx);
  478. void ipoib_cm_skb_too_long(struct net_device *dev, struct sk_buff *skb,
  479. unsigned int mtu);
  480. void ipoib_cm_handle_rx_wc(struct net_device *dev, struct ib_wc *wc);
  481. void ipoib_cm_handle_tx_wc(struct net_device *dev, struct ib_wc *wc);
  482. #else
  483. struct ipoib_cm_tx;
  484. #define ipoib_max_conn_qp 0
  485. static inline int ipoib_cm_admin_enabled(struct net_device *dev)
  486. {
  487. return 0;
  488. }
  489. static inline int ipoib_cm_enabled(struct net_device *dev, u8 *hwaddr)
  490. {
  491. return 0;
  492. }
  493. static inline int ipoib_cm_up(struct ipoib_neigh *neigh)
  494. {
  495. return 0;
  496. }
  497. static inline struct ipoib_cm_tx *ipoib_cm_get(struct ipoib_neigh *neigh)
  498. {
  499. return NULL;
  500. }
  501. static inline void ipoib_cm_set(struct ipoib_neigh *neigh, struct ipoib_cm_tx *tx)
  502. {
  503. }
  504. static inline int ipoib_cm_has_srq(struct net_device *dev)
  505. {
  506. return 0;
  507. }
  508. static inline unsigned int ipoib_cm_max_mtu(struct net_device *dev)
  509. {
  510. return 0;
  511. }
  512. static inline
  513. void ipoib_cm_send(struct net_device *dev, struct sk_buff *skb, struct ipoib_cm_tx *tx)
  514. {
  515. return;
  516. }
  517. static inline
  518. int ipoib_cm_dev_open(struct net_device *dev)
  519. {
  520. return 0;
  521. }
  522. static inline
  523. void ipoib_cm_dev_stop(struct net_device *dev)
  524. {
  525. return;
  526. }
  527. static inline
  528. int ipoib_cm_dev_init(struct net_device *dev)
  529. {
  530. return -ENOSYS;
  531. }
  532. static inline
  533. void ipoib_cm_dev_cleanup(struct net_device *dev)
  534. {
  535. return;
  536. }
  537. static inline
  538. struct ipoib_cm_tx *ipoib_cm_create_tx(struct net_device *dev, struct ipoib_path *path,
  539. struct ipoib_neigh *neigh)
  540. {
  541. return NULL;
  542. }
  543. static inline
  544. void ipoib_cm_destroy_tx(struct ipoib_cm_tx *tx)
  545. {
  546. return;
  547. }
  548. static inline
  549. int ipoib_cm_add_mode_attr(struct net_device *dev)
  550. {
  551. return 0;
  552. }
  553. static inline void ipoib_cm_skb_too_long(struct net_device *dev, struct sk_buff *skb,
  554. unsigned int mtu)
  555. {
  556. dev_kfree_skb_any(skb);
  557. }
  558. static inline void ipoib_cm_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
  559. {
  560. }
  561. static inline void ipoib_cm_handle_tx_wc(struct net_device *dev, struct ib_wc *wc)
  562. {
  563. }
  564. #endif
  565. #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
  566. void ipoib_create_debug_files(struct net_device *dev);
  567. void ipoib_delete_debug_files(struct net_device *dev);
  568. int ipoib_register_debugfs(void);
  569. void ipoib_unregister_debugfs(void);
  570. #else
  571. static inline void ipoib_create_debug_files(struct net_device *dev) { }
  572. static inline void ipoib_delete_debug_files(struct net_device *dev) { }
  573. static inline int ipoib_register_debugfs(void) { return 0; }
  574. static inline void ipoib_unregister_debugfs(void) { }
  575. #endif
  576. #define ipoib_printk(level, priv, format, arg...) \
  577. printk(level "%s: " format, ((struct ipoib_dev_priv *) priv)->dev->name , ## arg)
  578. #define ipoib_warn(priv, format, arg...) \
  579. ipoib_printk(KERN_WARNING, priv, format , ## arg)
  580. extern int ipoib_sendq_size;
  581. extern int ipoib_recvq_size;
  582. extern struct ib_sa_client ipoib_sa_client;
  583. #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
  584. extern int ipoib_debug_level;
  585. #define ipoib_dbg(priv, format, arg...) \
  586. do { \
  587. if (ipoib_debug_level > 0) \
  588. ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
  589. } while (0)
  590. #define ipoib_dbg_mcast(priv, format, arg...) \
  591. do { \
  592. if (mcast_debug_level > 0) \
  593. ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
  594. } while (0)
  595. #else /* CONFIG_INFINIBAND_IPOIB_DEBUG */
  596. #define ipoib_dbg(priv, format, arg...) \
  597. do { (void) (priv); } while (0)
  598. #define ipoib_dbg_mcast(priv, format, arg...) \
  599. do { (void) (priv); } while (0)
  600. #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG */
  601. #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA
  602. #define ipoib_dbg_data(priv, format, arg...) \
  603. do { \
  604. if (data_debug_level > 0) \
  605. ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
  606. } while (0)
  607. #else /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */
  608. #define ipoib_dbg_data(priv, format, arg...) \
  609. do { (void) (priv); } while (0)
  610. #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */
  611. #define IPOIB_QPN(ha) (be32_to_cpup((__be32 *) ha) & 0xffffff)
  612. #endif /* _IPOIB_H */