ipoib.h 23 KB

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