ipoib.h 21 KB

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