ipoib_ib.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242
  1. /*
  2. * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
  3. * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
  4. * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
  5. * Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved.
  6. *
  7. * This software is available to you under a choice of one of two
  8. * licenses. You may choose to be licensed under the terms of the GNU
  9. * General Public License (GPL) Version 2, available from the file
  10. * COPYING in the main directory of this source tree, or the
  11. * OpenIB.org BSD license below:
  12. *
  13. * Redistribution and use in source and binary forms, with or
  14. * without modification, are permitted provided that the following
  15. * conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above
  18. * copyright notice, this list of conditions and the following
  19. * disclaimer.
  20. *
  21. * - Redistributions in binary form must reproduce the above
  22. * copyright notice, this list of conditions and the following
  23. * disclaimer in the documentation and/or other materials
  24. * provided with the distribution.
  25. *
  26. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  27. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  28. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  29. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  30. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  31. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  32. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  33. * SOFTWARE.
  34. */
  35. #include <linux/delay.h>
  36. #include <linux/moduleparam.h>
  37. #include <linux/dma-mapping.h>
  38. #include <linux/slab.h>
  39. #include <linux/ip.h>
  40. #include <linux/tcp.h>
  41. #include "ipoib.h"
  42. #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA
  43. static int data_debug_level;
  44. module_param(data_debug_level, int, 0644);
  45. MODULE_PARM_DESC(data_debug_level,
  46. "Enable data path debug tracing if > 0");
  47. #endif
  48. struct ipoib_ah *ipoib_create_ah(struct net_device *dev,
  49. struct ib_pd *pd, struct ib_ah_attr *attr)
  50. {
  51. struct ipoib_ah *ah;
  52. struct ib_ah *vah;
  53. ah = kmalloc(sizeof *ah, GFP_KERNEL);
  54. if (!ah)
  55. return ERR_PTR(-ENOMEM);
  56. ah->dev = dev;
  57. ah->last_send = 0;
  58. kref_init(&ah->ref);
  59. vah = ib_create_ah(pd, attr);
  60. if (IS_ERR(vah)) {
  61. kfree(ah);
  62. ah = (struct ipoib_ah *)vah;
  63. } else {
  64. ah->ah = vah;
  65. ipoib_dbg(netdev_priv(dev), "Created ah %p\n", ah->ah);
  66. }
  67. return ah;
  68. }
  69. void ipoib_free_ah(struct kref *kref)
  70. {
  71. struct ipoib_ah *ah = container_of(kref, struct ipoib_ah, ref);
  72. struct ipoib_dev_priv *priv = netdev_priv(ah->dev);
  73. unsigned long flags;
  74. spin_lock_irqsave(&priv->lock, flags);
  75. list_add_tail(&ah->list, &priv->dead_ahs);
  76. spin_unlock_irqrestore(&priv->lock, flags);
  77. }
  78. static void ipoib_ud_dma_unmap_rx(struct ipoib_dev_priv *priv,
  79. u64 mapping[IPOIB_UD_RX_SG])
  80. {
  81. ib_dma_unmap_single(priv->ca, mapping[0],
  82. IPOIB_UD_BUF_SIZE(priv->max_ib_mtu),
  83. DMA_FROM_DEVICE);
  84. }
  85. static int ipoib_ib_post_receive(struct net_device *dev, int id)
  86. {
  87. struct ipoib_dev_priv *priv = netdev_priv(dev);
  88. struct ib_recv_wr *bad_wr;
  89. int ret;
  90. priv->rx_wr.wr_id = id | IPOIB_OP_RECV;
  91. priv->rx_sge[0].addr = priv->rx_ring[id].mapping[0];
  92. priv->rx_sge[1].addr = priv->rx_ring[id].mapping[1];
  93. ret = ib_post_recv(priv->qp, &priv->rx_wr, &bad_wr);
  94. if (unlikely(ret)) {
  95. ipoib_warn(priv, "receive failed for buf %d (%d)\n", id, ret);
  96. ipoib_ud_dma_unmap_rx(priv, priv->rx_ring[id].mapping);
  97. dev_kfree_skb_any(priv->rx_ring[id].skb);
  98. priv->rx_ring[id].skb = NULL;
  99. }
  100. return ret;
  101. }
  102. static struct sk_buff *ipoib_alloc_rx_skb(struct net_device *dev, int id)
  103. {
  104. struct ipoib_dev_priv *priv = netdev_priv(dev);
  105. struct sk_buff *skb;
  106. int buf_size;
  107. u64 *mapping;
  108. buf_size = IPOIB_UD_BUF_SIZE(priv->max_ib_mtu);
  109. skb = dev_alloc_skb(buf_size + IPOIB_HARD_LEN);
  110. if (unlikely(!skb))
  111. return NULL;
  112. /*
  113. * the IP header will be at IPOIP_HARD_LEN + IB_GRH_BYTES, that is
  114. * 64 bytes aligned
  115. */
  116. skb_reserve(skb, sizeof(struct ipoib_pseudo_header));
  117. mapping = priv->rx_ring[id].mapping;
  118. mapping[0] = ib_dma_map_single(priv->ca, skb->data, buf_size,
  119. DMA_FROM_DEVICE);
  120. if (unlikely(ib_dma_mapping_error(priv->ca, mapping[0])))
  121. goto error;
  122. priv->rx_ring[id].skb = skb;
  123. return skb;
  124. error:
  125. dev_kfree_skb_any(skb);
  126. return NULL;
  127. }
  128. static int ipoib_ib_post_receives(struct net_device *dev)
  129. {
  130. struct ipoib_dev_priv *priv = netdev_priv(dev);
  131. int i;
  132. for (i = 0; i < ipoib_recvq_size; ++i) {
  133. if (!ipoib_alloc_rx_skb(dev, i)) {
  134. ipoib_warn(priv, "failed to allocate receive buffer %d\n", i);
  135. return -ENOMEM;
  136. }
  137. if (ipoib_ib_post_receive(dev, i)) {
  138. ipoib_warn(priv, "ipoib_ib_post_receive failed for buf %d\n", i);
  139. return -EIO;
  140. }
  141. }
  142. return 0;
  143. }
  144. static void ipoib_ib_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
  145. {
  146. struct ipoib_dev_priv *priv = netdev_priv(dev);
  147. unsigned int wr_id = wc->wr_id & ~IPOIB_OP_RECV;
  148. struct sk_buff *skb;
  149. u64 mapping[IPOIB_UD_RX_SG];
  150. union ib_gid *dgid;
  151. union ib_gid *sgid;
  152. ipoib_dbg_data(priv, "recv completion: id %d, status: %d\n",
  153. wr_id, wc->status);
  154. if (unlikely(wr_id >= ipoib_recvq_size)) {
  155. ipoib_warn(priv, "recv completion event with wrid %d (> %d)\n",
  156. wr_id, ipoib_recvq_size);
  157. return;
  158. }
  159. skb = priv->rx_ring[wr_id].skb;
  160. if (unlikely(wc->status != IB_WC_SUCCESS)) {
  161. if (wc->status != IB_WC_WR_FLUSH_ERR)
  162. ipoib_warn(priv, "failed recv event "
  163. "(status=%d, wrid=%d vend_err %x)\n",
  164. wc->status, wr_id, wc->vendor_err);
  165. ipoib_ud_dma_unmap_rx(priv, priv->rx_ring[wr_id].mapping);
  166. dev_kfree_skb_any(skb);
  167. priv->rx_ring[wr_id].skb = NULL;
  168. return;
  169. }
  170. memcpy(mapping, priv->rx_ring[wr_id].mapping,
  171. IPOIB_UD_RX_SG * sizeof *mapping);
  172. /*
  173. * If we can't allocate a new RX buffer, dump
  174. * this packet and reuse the old buffer.
  175. */
  176. if (unlikely(!ipoib_alloc_rx_skb(dev, wr_id))) {
  177. ++dev->stats.rx_dropped;
  178. goto repost;
  179. }
  180. ipoib_dbg_data(priv, "received %d bytes, SLID 0x%04x\n",
  181. wc->byte_len, wc->slid);
  182. ipoib_ud_dma_unmap_rx(priv, mapping);
  183. skb_put(skb, wc->byte_len);
  184. /* First byte of dgid signals multicast when 0xff */
  185. dgid = &((struct ib_grh *)skb->data)->dgid;
  186. if (!(wc->wc_flags & IB_WC_GRH) || dgid->raw[0] != 0xff)
  187. skb->pkt_type = PACKET_HOST;
  188. else if (memcmp(dgid, dev->broadcast + 4, sizeof(union ib_gid)) == 0)
  189. skb->pkt_type = PACKET_BROADCAST;
  190. else
  191. skb->pkt_type = PACKET_MULTICAST;
  192. sgid = &((struct ib_grh *)skb->data)->sgid;
  193. /*
  194. * Drop packets that this interface sent, ie multicast packets
  195. * that the HCA has replicated.
  196. */
  197. if (wc->slid == priv->local_lid && wc->src_qp == priv->qp->qp_num) {
  198. int need_repost = 1;
  199. if ((wc->wc_flags & IB_WC_GRH) &&
  200. sgid->global.interface_id != priv->local_gid.global.interface_id)
  201. need_repost = 0;
  202. if (need_repost) {
  203. dev_kfree_skb_any(skb);
  204. goto repost;
  205. }
  206. }
  207. skb_pull(skb, IB_GRH_BYTES);
  208. skb->protocol = ((struct ipoib_header *) skb->data)->proto;
  209. skb_add_pseudo_hdr(skb);
  210. ++dev->stats.rx_packets;
  211. dev->stats.rx_bytes += skb->len;
  212. skb->dev = dev;
  213. if ((dev->features & NETIF_F_RXCSUM) &&
  214. likely(wc->wc_flags & IB_WC_IP_CSUM_OK))
  215. skb->ip_summed = CHECKSUM_UNNECESSARY;
  216. napi_gro_receive(&priv->napi, skb);
  217. repost:
  218. if (unlikely(ipoib_ib_post_receive(dev, wr_id)))
  219. ipoib_warn(priv, "ipoib_ib_post_receive failed "
  220. "for buf %d\n", wr_id);
  221. }
  222. int ipoib_dma_map_tx(struct ib_device *ca, struct ipoib_tx_buf *tx_req)
  223. {
  224. struct sk_buff *skb = tx_req->skb;
  225. u64 *mapping = tx_req->mapping;
  226. int i;
  227. int off;
  228. if (skb_headlen(skb)) {
  229. mapping[0] = ib_dma_map_single(ca, skb->data, skb_headlen(skb),
  230. DMA_TO_DEVICE);
  231. if (unlikely(ib_dma_mapping_error(ca, mapping[0])))
  232. return -EIO;
  233. off = 1;
  234. } else
  235. off = 0;
  236. for (i = 0; i < skb_shinfo(skb)->nr_frags; ++i) {
  237. const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  238. mapping[i + off] = ib_dma_map_page(ca,
  239. skb_frag_page(frag),
  240. frag->page_offset, skb_frag_size(frag),
  241. DMA_TO_DEVICE);
  242. if (unlikely(ib_dma_mapping_error(ca, mapping[i + off])))
  243. goto partial_error;
  244. }
  245. return 0;
  246. partial_error:
  247. for (; i > 0; --i) {
  248. const skb_frag_t *frag = &skb_shinfo(skb)->frags[i - 1];
  249. ib_dma_unmap_page(ca, mapping[i - !off], skb_frag_size(frag), DMA_TO_DEVICE);
  250. }
  251. if (off)
  252. ib_dma_unmap_single(ca, mapping[0], skb_headlen(skb), DMA_TO_DEVICE);
  253. return -EIO;
  254. }
  255. void ipoib_dma_unmap_tx(struct ipoib_dev_priv *priv,
  256. struct ipoib_tx_buf *tx_req)
  257. {
  258. struct sk_buff *skb = tx_req->skb;
  259. u64 *mapping = tx_req->mapping;
  260. int i;
  261. int off;
  262. if (skb_headlen(skb)) {
  263. ib_dma_unmap_single(priv->ca, mapping[0], skb_headlen(skb),
  264. DMA_TO_DEVICE);
  265. off = 1;
  266. } else
  267. off = 0;
  268. for (i = 0; i < skb_shinfo(skb)->nr_frags; ++i) {
  269. const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  270. ib_dma_unmap_page(priv->ca, mapping[i + off],
  271. skb_frag_size(frag), DMA_TO_DEVICE);
  272. }
  273. }
  274. /*
  275. * As the result of a completion error the QP Can be transferred to SQE states.
  276. * The function checks if the (send)QP is in SQE state and
  277. * moves it back to RTS state, that in order to have it functional again.
  278. */
  279. static void ipoib_qp_state_validate_work(struct work_struct *work)
  280. {
  281. struct ipoib_qp_state_validate *qp_work =
  282. container_of(work, struct ipoib_qp_state_validate, work);
  283. struct ipoib_dev_priv *priv = qp_work->priv;
  284. struct ib_qp_attr qp_attr;
  285. struct ib_qp_init_attr query_init_attr;
  286. int ret;
  287. ret = ib_query_qp(priv->qp, &qp_attr, IB_QP_STATE, &query_init_attr);
  288. if (ret) {
  289. ipoib_warn(priv, "%s: Failed to query QP ret: %d\n",
  290. __func__, ret);
  291. goto free_res;
  292. }
  293. pr_info("%s: QP: 0x%x is in state: %d\n",
  294. __func__, priv->qp->qp_num, qp_attr.qp_state);
  295. /* currently support only in SQE->RTS transition*/
  296. if (qp_attr.qp_state == IB_QPS_SQE) {
  297. qp_attr.qp_state = IB_QPS_RTS;
  298. ret = ib_modify_qp(priv->qp, &qp_attr, IB_QP_STATE);
  299. if (ret) {
  300. pr_warn("failed(%d) modify QP:0x%x SQE->RTS\n",
  301. ret, priv->qp->qp_num);
  302. goto free_res;
  303. }
  304. pr_info("%s: QP: 0x%x moved from IB_QPS_SQE to IB_QPS_RTS\n",
  305. __func__, priv->qp->qp_num);
  306. } else {
  307. pr_warn("QP (%d) will stay in state: %d\n",
  308. priv->qp->qp_num, qp_attr.qp_state);
  309. }
  310. free_res:
  311. kfree(qp_work);
  312. }
  313. static void ipoib_ib_handle_tx_wc(struct net_device *dev, struct ib_wc *wc)
  314. {
  315. struct ipoib_dev_priv *priv = netdev_priv(dev);
  316. unsigned int wr_id = wc->wr_id;
  317. struct ipoib_tx_buf *tx_req;
  318. ipoib_dbg_data(priv, "send completion: id %d, status: %d\n",
  319. wr_id, wc->status);
  320. if (unlikely(wr_id >= ipoib_sendq_size)) {
  321. ipoib_warn(priv, "send completion event with wrid %d (> %d)\n",
  322. wr_id, ipoib_sendq_size);
  323. return;
  324. }
  325. tx_req = &priv->tx_ring[wr_id];
  326. ipoib_dma_unmap_tx(priv, tx_req);
  327. ++dev->stats.tx_packets;
  328. dev->stats.tx_bytes += tx_req->skb->len;
  329. dev_kfree_skb_any(tx_req->skb);
  330. ++priv->tx_tail;
  331. if (unlikely(--priv->tx_outstanding == ipoib_sendq_size >> 1) &&
  332. netif_queue_stopped(dev) &&
  333. test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags))
  334. netif_wake_queue(dev);
  335. if (wc->status != IB_WC_SUCCESS &&
  336. wc->status != IB_WC_WR_FLUSH_ERR) {
  337. struct ipoib_qp_state_validate *qp_work;
  338. ipoib_warn(priv, "failed send event "
  339. "(status=%d, wrid=%d vend_err %x)\n",
  340. wc->status, wr_id, wc->vendor_err);
  341. qp_work = kzalloc(sizeof(*qp_work), GFP_ATOMIC);
  342. if (!qp_work)
  343. return;
  344. INIT_WORK(&qp_work->work, ipoib_qp_state_validate_work);
  345. qp_work->priv = priv;
  346. queue_work(priv->wq, &qp_work->work);
  347. }
  348. }
  349. static int poll_tx(struct ipoib_dev_priv *priv)
  350. {
  351. int n, i;
  352. n = ib_poll_cq(priv->send_cq, MAX_SEND_CQE, priv->send_wc);
  353. for (i = 0; i < n; ++i)
  354. ipoib_ib_handle_tx_wc(priv->dev, priv->send_wc + i);
  355. return n == MAX_SEND_CQE;
  356. }
  357. int ipoib_poll(struct napi_struct *napi, int budget)
  358. {
  359. struct ipoib_dev_priv *priv = container_of(napi, struct ipoib_dev_priv, napi);
  360. struct net_device *dev = priv->dev;
  361. int done;
  362. int t;
  363. int n, i;
  364. done = 0;
  365. poll_more:
  366. while (done < budget) {
  367. int max = (budget - done);
  368. t = min(IPOIB_NUM_WC, max);
  369. n = ib_poll_cq(priv->recv_cq, t, priv->ibwc);
  370. for (i = 0; i < n; i++) {
  371. struct ib_wc *wc = priv->ibwc + i;
  372. if (wc->wr_id & IPOIB_OP_RECV) {
  373. ++done;
  374. if (wc->wr_id & IPOIB_OP_CM)
  375. ipoib_cm_handle_rx_wc(dev, wc);
  376. else
  377. ipoib_ib_handle_rx_wc(dev, wc);
  378. } else
  379. ipoib_cm_handle_tx_wc(priv->dev, wc);
  380. }
  381. if (n != t)
  382. break;
  383. }
  384. if (done < budget) {
  385. napi_complete(napi);
  386. if (unlikely(ib_req_notify_cq(priv->recv_cq,
  387. IB_CQ_NEXT_COMP |
  388. IB_CQ_REPORT_MISSED_EVENTS)) &&
  389. napi_reschedule(napi))
  390. goto poll_more;
  391. }
  392. return done;
  393. }
  394. void ipoib_ib_completion(struct ib_cq *cq, void *dev_ptr)
  395. {
  396. struct net_device *dev = dev_ptr;
  397. struct ipoib_dev_priv *priv = netdev_priv(dev);
  398. napi_schedule(&priv->napi);
  399. }
  400. static void drain_tx_cq(struct net_device *dev)
  401. {
  402. struct ipoib_dev_priv *priv = netdev_priv(dev);
  403. netif_tx_lock(dev);
  404. while (poll_tx(priv))
  405. ; /* nothing */
  406. if (netif_queue_stopped(dev))
  407. mod_timer(&priv->poll_timer, jiffies + 1);
  408. netif_tx_unlock(dev);
  409. }
  410. void ipoib_send_comp_handler(struct ib_cq *cq, void *dev_ptr)
  411. {
  412. struct ipoib_dev_priv *priv = netdev_priv(dev_ptr);
  413. mod_timer(&priv->poll_timer, jiffies);
  414. }
  415. static inline int post_send(struct ipoib_dev_priv *priv,
  416. unsigned int wr_id,
  417. struct ib_ah *address, u32 qpn,
  418. struct ipoib_tx_buf *tx_req,
  419. void *head, int hlen)
  420. {
  421. struct ib_send_wr *bad_wr;
  422. struct sk_buff *skb = tx_req->skb;
  423. ipoib_build_sge(priv, tx_req);
  424. priv->tx_wr.wr.wr_id = wr_id;
  425. priv->tx_wr.remote_qpn = qpn;
  426. priv->tx_wr.ah = address;
  427. if (head) {
  428. priv->tx_wr.mss = skb_shinfo(skb)->gso_size;
  429. priv->tx_wr.header = head;
  430. priv->tx_wr.hlen = hlen;
  431. priv->tx_wr.wr.opcode = IB_WR_LSO;
  432. } else
  433. priv->tx_wr.wr.opcode = IB_WR_SEND;
  434. return ib_post_send(priv->qp, &priv->tx_wr.wr, &bad_wr);
  435. }
  436. void ipoib_send(struct net_device *dev, struct sk_buff *skb,
  437. struct ipoib_ah *address, u32 qpn)
  438. {
  439. struct ipoib_dev_priv *priv = netdev_priv(dev);
  440. struct ipoib_tx_buf *tx_req;
  441. int hlen, rc;
  442. void *phead;
  443. unsigned usable_sge = priv->max_send_sge - !!skb_headlen(skb);
  444. if (skb_is_gso(skb)) {
  445. hlen = skb_transport_offset(skb) + tcp_hdrlen(skb);
  446. phead = skb->data;
  447. if (unlikely(!skb_pull(skb, hlen))) {
  448. ipoib_warn(priv, "linear data too small\n");
  449. ++dev->stats.tx_dropped;
  450. ++dev->stats.tx_errors;
  451. dev_kfree_skb_any(skb);
  452. return;
  453. }
  454. } else {
  455. if (unlikely(skb->len > priv->mcast_mtu + IPOIB_ENCAP_LEN)) {
  456. ipoib_warn(priv, "packet len %d (> %d) too long to send, dropping\n",
  457. skb->len, priv->mcast_mtu + IPOIB_ENCAP_LEN);
  458. ++dev->stats.tx_dropped;
  459. ++dev->stats.tx_errors;
  460. ipoib_cm_skb_too_long(dev, skb, priv->mcast_mtu);
  461. return;
  462. }
  463. phead = NULL;
  464. hlen = 0;
  465. }
  466. if (skb_shinfo(skb)->nr_frags > usable_sge) {
  467. if (skb_linearize(skb) < 0) {
  468. ipoib_warn(priv, "skb could not be linearized\n");
  469. ++dev->stats.tx_dropped;
  470. ++dev->stats.tx_errors;
  471. dev_kfree_skb_any(skb);
  472. return;
  473. }
  474. /* Does skb_linearize return ok without reducing nr_frags? */
  475. if (skb_shinfo(skb)->nr_frags > usable_sge) {
  476. ipoib_warn(priv, "too many frags after skb linearize\n");
  477. ++dev->stats.tx_dropped;
  478. ++dev->stats.tx_errors;
  479. dev_kfree_skb_any(skb);
  480. return;
  481. }
  482. }
  483. ipoib_dbg_data(priv, "sending packet, length=%d address=%p qpn=0x%06x\n",
  484. skb->len, address, qpn);
  485. /*
  486. * We put the skb into the tx_ring _before_ we call post_send()
  487. * because it's entirely possible that the completion handler will
  488. * run before we execute anything after the post_send(). That
  489. * means we have to make sure everything is properly recorded and
  490. * our state is consistent before we call post_send().
  491. */
  492. tx_req = &priv->tx_ring[priv->tx_head & (ipoib_sendq_size - 1)];
  493. tx_req->skb = skb;
  494. if (unlikely(ipoib_dma_map_tx(priv->ca, tx_req))) {
  495. ++dev->stats.tx_errors;
  496. dev_kfree_skb_any(skb);
  497. return;
  498. }
  499. if (skb->ip_summed == CHECKSUM_PARTIAL)
  500. priv->tx_wr.wr.send_flags |= IB_SEND_IP_CSUM;
  501. else
  502. priv->tx_wr.wr.send_flags &= ~IB_SEND_IP_CSUM;
  503. if (++priv->tx_outstanding == ipoib_sendq_size) {
  504. ipoib_dbg(priv, "TX ring full, stopping kernel net queue\n");
  505. if (ib_req_notify_cq(priv->send_cq, IB_CQ_NEXT_COMP))
  506. ipoib_warn(priv, "request notify on send CQ failed\n");
  507. netif_stop_queue(dev);
  508. }
  509. skb_orphan(skb);
  510. skb_dst_drop(skb);
  511. rc = post_send(priv, priv->tx_head & (ipoib_sendq_size - 1),
  512. address->ah, qpn, tx_req, phead, hlen);
  513. if (unlikely(rc)) {
  514. ipoib_warn(priv, "post_send failed, error %d\n", rc);
  515. ++dev->stats.tx_errors;
  516. --priv->tx_outstanding;
  517. ipoib_dma_unmap_tx(priv, tx_req);
  518. dev_kfree_skb_any(skb);
  519. if (netif_queue_stopped(dev))
  520. netif_wake_queue(dev);
  521. } else {
  522. netif_trans_update(dev);
  523. address->last_send = priv->tx_head;
  524. ++priv->tx_head;
  525. }
  526. if (unlikely(priv->tx_outstanding > MAX_SEND_CQE))
  527. while (poll_tx(priv))
  528. ; /* nothing */
  529. }
  530. static void __ipoib_reap_ah(struct net_device *dev)
  531. {
  532. struct ipoib_dev_priv *priv = netdev_priv(dev);
  533. struct ipoib_ah *ah, *tah;
  534. LIST_HEAD(remove_list);
  535. unsigned long flags;
  536. netif_tx_lock_bh(dev);
  537. spin_lock_irqsave(&priv->lock, flags);
  538. list_for_each_entry_safe(ah, tah, &priv->dead_ahs, list)
  539. if ((int) priv->tx_tail - (int) ah->last_send >= 0) {
  540. list_del(&ah->list);
  541. ib_destroy_ah(ah->ah);
  542. kfree(ah);
  543. }
  544. spin_unlock_irqrestore(&priv->lock, flags);
  545. netif_tx_unlock_bh(dev);
  546. }
  547. void ipoib_reap_ah(struct work_struct *work)
  548. {
  549. struct ipoib_dev_priv *priv =
  550. container_of(work, struct ipoib_dev_priv, ah_reap_task.work);
  551. struct net_device *dev = priv->dev;
  552. __ipoib_reap_ah(dev);
  553. if (!test_bit(IPOIB_STOP_REAPER, &priv->flags))
  554. queue_delayed_work(priv->wq, &priv->ah_reap_task,
  555. round_jiffies_relative(HZ));
  556. }
  557. static void ipoib_flush_ah(struct net_device *dev)
  558. {
  559. struct ipoib_dev_priv *priv = netdev_priv(dev);
  560. cancel_delayed_work(&priv->ah_reap_task);
  561. flush_workqueue(priv->wq);
  562. ipoib_reap_ah(&priv->ah_reap_task.work);
  563. }
  564. static void ipoib_stop_ah(struct net_device *dev)
  565. {
  566. struct ipoib_dev_priv *priv = netdev_priv(dev);
  567. set_bit(IPOIB_STOP_REAPER, &priv->flags);
  568. ipoib_flush_ah(dev);
  569. }
  570. static void ipoib_ib_tx_timer_func(unsigned long ctx)
  571. {
  572. drain_tx_cq((struct net_device *)ctx);
  573. }
  574. int ipoib_ib_dev_open(struct net_device *dev)
  575. {
  576. struct ipoib_dev_priv *priv = netdev_priv(dev);
  577. int ret;
  578. ipoib_pkey_dev_check_presence(dev);
  579. if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) {
  580. ipoib_warn(priv, "P_Key 0x%04x is %s\n", priv->pkey,
  581. (!(priv->pkey & 0x7fff) ? "Invalid" : "not found"));
  582. return -1;
  583. }
  584. ret = ipoib_init_qp(dev);
  585. if (ret) {
  586. ipoib_warn(priv, "ipoib_init_qp returned %d\n", ret);
  587. return -1;
  588. }
  589. ret = ipoib_ib_post_receives(dev);
  590. if (ret) {
  591. ipoib_warn(priv, "ipoib_ib_post_receives returned %d\n", ret);
  592. goto dev_stop;
  593. }
  594. ret = ipoib_cm_dev_open(dev);
  595. if (ret) {
  596. ipoib_warn(priv, "ipoib_cm_dev_open returned %d\n", ret);
  597. goto dev_stop;
  598. }
  599. clear_bit(IPOIB_STOP_REAPER, &priv->flags);
  600. queue_delayed_work(priv->wq, &priv->ah_reap_task,
  601. round_jiffies_relative(HZ));
  602. if (!test_and_set_bit(IPOIB_FLAG_INITIALIZED, &priv->flags))
  603. napi_enable(&priv->napi);
  604. return 0;
  605. dev_stop:
  606. if (!test_and_set_bit(IPOIB_FLAG_INITIALIZED, &priv->flags))
  607. napi_enable(&priv->napi);
  608. ipoib_ib_dev_stop(dev);
  609. return -1;
  610. }
  611. void ipoib_pkey_dev_check_presence(struct net_device *dev)
  612. {
  613. struct ipoib_dev_priv *priv = netdev_priv(dev);
  614. if (!(priv->pkey & 0x7fff) ||
  615. ib_find_pkey(priv->ca, priv->port, priv->pkey,
  616. &priv->pkey_index))
  617. clear_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
  618. else
  619. set_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
  620. }
  621. void ipoib_ib_dev_up(struct net_device *dev)
  622. {
  623. struct ipoib_dev_priv *priv = netdev_priv(dev);
  624. ipoib_pkey_dev_check_presence(dev);
  625. if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) {
  626. ipoib_dbg(priv, "PKEY is not assigned.\n");
  627. return;
  628. }
  629. set_bit(IPOIB_FLAG_OPER_UP, &priv->flags);
  630. ipoib_mcast_start_thread(dev);
  631. }
  632. void ipoib_ib_dev_down(struct net_device *dev)
  633. {
  634. struct ipoib_dev_priv *priv = netdev_priv(dev);
  635. ipoib_dbg(priv, "downing ib_dev\n");
  636. clear_bit(IPOIB_FLAG_OPER_UP, &priv->flags);
  637. netif_carrier_off(dev);
  638. ipoib_mcast_stop_thread(dev);
  639. ipoib_mcast_dev_flush(dev);
  640. ipoib_flush_paths(dev);
  641. }
  642. static int recvs_pending(struct net_device *dev)
  643. {
  644. struct ipoib_dev_priv *priv = netdev_priv(dev);
  645. int pending = 0;
  646. int i;
  647. for (i = 0; i < ipoib_recvq_size; ++i)
  648. if (priv->rx_ring[i].skb)
  649. ++pending;
  650. return pending;
  651. }
  652. void ipoib_drain_cq(struct net_device *dev)
  653. {
  654. struct ipoib_dev_priv *priv = netdev_priv(dev);
  655. int i, n;
  656. /*
  657. * We call completion handling routines that expect to be
  658. * called from the BH-disabled NAPI poll context, so disable
  659. * BHs here too.
  660. */
  661. local_bh_disable();
  662. do {
  663. n = ib_poll_cq(priv->recv_cq, IPOIB_NUM_WC, priv->ibwc);
  664. for (i = 0; i < n; ++i) {
  665. /*
  666. * Convert any successful completions to flush
  667. * errors to avoid passing packets up the
  668. * stack after bringing the device down.
  669. */
  670. if (priv->ibwc[i].status == IB_WC_SUCCESS)
  671. priv->ibwc[i].status = IB_WC_WR_FLUSH_ERR;
  672. if (priv->ibwc[i].wr_id & IPOIB_OP_RECV) {
  673. if (priv->ibwc[i].wr_id & IPOIB_OP_CM)
  674. ipoib_cm_handle_rx_wc(dev, priv->ibwc + i);
  675. else
  676. ipoib_ib_handle_rx_wc(dev, priv->ibwc + i);
  677. } else
  678. ipoib_cm_handle_tx_wc(dev, priv->ibwc + i);
  679. }
  680. } while (n == IPOIB_NUM_WC);
  681. while (poll_tx(priv))
  682. ; /* nothing */
  683. local_bh_enable();
  684. }
  685. void ipoib_ib_dev_stop(struct net_device *dev)
  686. {
  687. struct ipoib_dev_priv *priv = netdev_priv(dev);
  688. struct ib_qp_attr qp_attr;
  689. unsigned long begin;
  690. struct ipoib_tx_buf *tx_req;
  691. int i;
  692. if (test_and_clear_bit(IPOIB_FLAG_INITIALIZED, &priv->flags))
  693. napi_disable(&priv->napi);
  694. ipoib_cm_dev_stop(dev);
  695. /*
  696. * Move our QP to the error state and then reinitialize in
  697. * when all work requests have completed or have been flushed.
  698. */
  699. qp_attr.qp_state = IB_QPS_ERR;
  700. if (ib_modify_qp(priv->qp, &qp_attr, IB_QP_STATE))
  701. ipoib_warn(priv, "Failed to modify QP to ERROR state\n");
  702. /* Wait for all sends and receives to complete */
  703. begin = jiffies;
  704. while (priv->tx_head != priv->tx_tail || recvs_pending(dev)) {
  705. if (time_after(jiffies, begin + 5 * HZ)) {
  706. ipoib_warn(priv, "timing out; %d sends %d receives not completed\n",
  707. priv->tx_head - priv->tx_tail, recvs_pending(dev));
  708. /*
  709. * assume the HW is wedged and just free up
  710. * all our pending work requests.
  711. */
  712. while ((int) priv->tx_tail - (int) priv->tx_head < 0) {
  713. tx_req = &priv->tx_ring[priv->tx_tail &
  714. (ipoib_sendq_size - 1)];
  715. ipoib_dma_unmap_tx(priv, tx_req);
  716. dev_kfree_skb_any(tx_req->skb);
  717. ++priv->tx_tail;
  718. --priv->tx_outstanding;
  719. }
  720. for (i = 0; i < ipoib_recvq_size; ++i) {
  721. struct ipoib_rx_buf *rx_req;
  722. rx_req = &priv->rx_ring[i];
  723. if (!rx_req->skb)
  724. continue;
  725. ipoib_ud_dma_unmap_rx(priv,
  726. priv->rx_ring[i].mapping);
  727. dev_kfree_skb_any(rx_req->skb);
  728. rx_req->skb = NULL;
  729. }
  730. goto timeout;
  731. }
  732. ipoib_drain_cq(dev);
  733. msleep(1);
  734. }
  735. ipoib_dbg(priv, "All sends and receives done.\n");
  736. timeout:
  737. del_timer_sync(&priv->poll_timer);
  738. qp_attr.qp_state = IB_QPS_RESET;
  739. if (ib_modify_qp(priv->qp, &qp_attr, IB_QP_STATE))
  740. ipoib_warn(priv, "Failed to modify QP to RESET state\n");
  741. ipoib_flush_ah(dev);
  742. ib_req_notify_cq(priv->recv_cq, IB_CQ_NEXT_COMP);
  743. }
  744. int ipoib_ib_dev_init(struct net_device *dev, struct ib_device *ca, int port)
  745. {
  746. struct ipoib_dev_priv *priv = netdev_priv(dev);
  747. priv->ca = ca;
  748. priv->port = port;
  749. priv->qp = NULL;
  750. if (ipoib_transport_dev_init(dev, ca)) {
  751. printk(KERN_WARNING "%s: ipoib_transport_dev_init failed\n", ca->name);
  752. return -ENODEV;
  753. }
  754. setup_timer(&priv->poll_timer, ipoib_ib_tx_timer_func,
  755. (unsigned long) dev);
  756. if (dev->flags & IFF_UP) {
  757. if (ipoib_ib_dev_open(dev)) {
  758. ipoib_transport_dev_cleanup(dev);
  759. return -ENODEV;
  760. }
  761. }
  762. return 0;
  763. }
  764. /*
  765. * Takes whatever value which is in pkey index 0 and updates priv->pkey
  766. * returns 0 if the pkey value was changed.
  767. */
  768. static inline int update_parent_pkey(struct ipoib_dev_priv *priv)
  769. {
  770. int result;
  771. u16 prev_pkey;
  772. prev_pkey = priv->pkey;
  773. result = ib_query_pkey(priv->ca, priv->port, 0, &priv->pkey);
  774. if (result) {
  775. ipoib_warn(priv, "ib_query_pkey port %d failed (ret = %d)\n",
  776. priv->port, result);
  777. return result;
  778. }
  779. priv->pkey |= 0x8000;
  780. if (prev_pkey != priv->pkey) {
  781. ipoib_dbg(priv, "pkey changed from 0x%x to 0x%x\n",
  782. prev_pkey, priv->pkey);
  783. /*
  784. * Update the pkey in the broadcast address, while making sure to set
  785. * the full membership bit, so that we join the right broadcast group.
  786. */
  787. priv->dev->broadcast[8] = priv->pkey >> 8;
  788. priv->dev->broadcast[9] = priv->pkey & 0xff;
  789. return 0;
  790. }
  791. return 1;
  792. }
  793. /*
  794. * returns 0 if pkey value was found in a different slot.
  795. */
  796. static inline int update_child_pkey(struct ipoib_dev_priv *priv)
  797. {
  798. u16 old_index = priv->pkey_index;
  799. priv->pkey_index = 0;
  800. ipoib_pkey_dev_check_presence(priv->dev);
  801. if (test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags) &&
  802. (old_index == priv->pkey_index))
  803. return 1;
  804. return 0;
  805. }
  806. /*
  807. * returns true if the device address of the ipoib interface has changed and the
  808. * new address is a valid one (i.e in the gid table), return false otherwise.
  809. */
  810. static bool ipoib_dev_addr_changed_valid(struct ipoib_dev_priv *priv)
  811. {
  812. union ib_gid search_gid;
  813. union ib_gid gid0;
  814. union ib_gid *netdev_gid;
  815. int err;
  816. u16 index;
  817. u8 port;
  818. bool ret = false;
  819. netdev_gid = (union ib_gid *)(priv->dev->dev_addr + 4);
  820. if (ib_query_gid(priv->ca, priv->port, 0, &gid0, NULL))
  821. return false;
  822. netif_addr_lock_bh(priv->dev);
  823. /* The subnet prefix may have changed, update it now so we won't have
  824. * to do it later
  825. */
  826. priv->local_gid.global.subnet_prefix = gid0.global.subnet_prefix;
  827. netdev_gid->global.subnet_prefix = gid0.global.subnet_prefix;
  828. search_gid.global.subnet_prefix = gid0.global.subnet_prefix;
  829. search_gid.global.interface_id = priv->local_gid.global.interface_id;
  830. netif_addr_unlock_bh(priv->dev);
  831. err = ib_find_gid(priv->ca, &search_gid, IB_GID_TYPE_IB,
  832. priv->dev, &port, &index);
  833. netif_addr_lock_bh(priv->dev);
  834. if (search_gid.global.interface_id !=
  835. priv->local_gid.global.interface_id)
  836. /* There was a change while we were looking up the gid, bail
  837. * here and let the next work sort this out
  838. */
  839. goto out;
  840. /* The next section of code needs some background:
  841. * Per IB spec the port GUID can't change if the HCA is powered on.
  842. * port GUID is the basis for GID at index 0 which is the basis for
  843. * the default device address of a ipoib interface.
  844. *
  845. * so it seems the flow should be:
  846. * if user_changed_dev_addr && gid in gid tbl
  847. * set bit dev_addr_set
  848. * return true
  849. * else
  850. * return false
  851. *
  852. * The issue is that there are devices that don't follow the spec,
  853. * they change the port GUID when the HCA is powered, so in order
  854. * not to break userspace applications, We need to check if the
  855. * user wanted to control the device address and we assume that
  856. * if he sets the device address back to be based on GID index 0,
  857. * he no longer wishs to control it.
  858. *
  859. * If the user doesn't control the the device address,
  860. * IPOIB_FLAG_DEV_ADDR_SET is set and ib_find_gid failed it means
  861. * the port GUID has changed and GID at index 0 has changed
  862. * so we need to change priv->local_gid and priv->dev->dev_addr
  863. * to reflect the new GID.
  864. */
  865. if (!test_bit(IPOIB_FLAG_DEV_ADDR_SET, &priv->flags)) {
  866. if (!err && port == priv->port) {
  867. set_bit(IPOIB_FLAG_DEV_ADDR_SET, &priv->flags);
  868. if (index == 0)
  869. clear_bit(IPOIB_FLAG_DEV_ADDR_CTRL,
  870. &priv->flags);
  871. else
  872. set_bit(IPOIB_FLAG_DEV_ADDR_CTRL, &priv->flags);
  873. ret = true;
  874. } else {
  875. ret = false;
  876. }
  877. } else {
  878. if (!err && port == priv->port) {
  879. ret = true;
  880. } else {
  881. if (!test_bit(IPOIB_FLAG_DEV_ADDR_CTRL, &priv->flags)) {
  882. memcpy(&priv->local_gid, &gid0,
  883. sizeof(priv->local_gid));
  884. memcpy(priv->dev->dev_addr + 4, &gid0,
  885. sizeof(priv->local_gid));
  886. ret = true;
  887. }
  888. }
  889. }
  890. out:
  891. netif_addr_unlock_bh(priv->dev);
  892. return ret;
  893. }
  894. static void __ipoib_ib_dev_flush(struct ipoib_dev_priv *priv,
  895. enum ipoib_flush_level level,
  896. int nesting)
  897. {
  898. struct ipoib_dev_priv *cpriv;
  899. struct net_device *dev = priv->dev;
  900. int result;
  901. down_read_nested(&priv->vlan_rwsem, nesting);
  902. /*
  903. * Flush any child interfaces too -- they might be up even if
  904. * the parent is down.
  905. */
  906. list_for_each_entry(cpriv, &priv->child_intfs, list)
  907. __ipoib_ib_dev_flush(cpriv, level, nesting + 1);
  908. up_read(&priv->vlan_rwsem);
  909. if (!test_bit(IPOIB_FLAG_INITIALIZED, &priv->flags) &&
  910. level != IPOIB_FLUSH_HEAVY) {
  911. /* Make sure the dev_addr is set even if not flushing */
  912. if (level == IPOIB_FLUSH_LIGHT)
  913. ipoib_dev_addr_changed_valid(priv);
  914. ipoib_dbg(priv, "Not flushing - IPOIB_FLAG_INITIALIZED not set.\n");
  915. return;
  916. }
  917. if (!test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags)) {
  918. /* interface is down. update pkey and leave. */
  919. if (level == IPOIB_FLUSH_HEAVY) {
  920. if (!test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags))
  921. update_parent_pkey(priv);
  922. else
  923. update_child_pkey(priv);
  924. } else if (level == IPOIB_FLUSH_LIGHT)
  925. ipoib_dev_addr_changed_valid(priv);
  926. ipoib_dbg(priv, "Not flushing - IPOIB_FLAG_ADMIN_UP not set.\n");
  927. return;
  928. }
  929. if (level == IPOIB_FLUSH_HEAVY) {
  930. /* child devices chase their origin pkey value, while non-child
  931. * (parent) devices should always takes what present in pkey index 0
  932. */
  933. if (test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags)) {
  934. result = update_child_pkey(priv);
  935. if (result) {
  936. /* restart QP only if P_Key index is changed */
  937. ipoib_dbg(priv, "Not flushing - P_Key index not changed.\n");
  938. return;
  939. }
  940. } else {
  941. result = update_parent_pkey(priv);
  942. /* restart QP only if P_Key value changed */
  943. if (result) {
  944. ipoib_dbg(priv, "Not flushing - P_Key value not changed.\n");
  945. return;
  946. }
  947. }
  948. }
  949. if (level == IPOIB_FLUSH_LIGHT) {
  950. int oper_up;
  951. ipoib_mark_paths_invalid(dev);
  952. /* Set IPoIB operation as down to prevent races between:
  953. * the flush flow which leaves MCG and on the fly joins
  954. * which can happen during that time. mcast restart task
  955. * should deal with join requests we missed.
  956. */
  957. oper_up = test_and_clear_bit(IPOIB_FLAG_OPER_UP, &priv->flags);
  958. ipoib_mcast_dev_flush(dev);
  959. if (oper_up)
  960. set_bit(IPOIB_FLAG_OPER_UP, &priv->flags);
  961. ipoib_flush_ah(dev);
  962. }
  963. if (level >= IPOIB_FLUSH_NORMAL)
  964. ipoib_ib_dev_down(dev);
  965. if (level == IPOIB_FLUSH_HEAVY) {
  966. if (test_bit(IPOIB_FLAG_INITIALIZED, &priv->flags))
  967. ipoib_ib_dev_stop(dev);
  968. if (ipoib_ib_dev_open(dev) != 0)
  969. return;
  970. if (netif_queue_stopped(dev))
  971. netif_start_queue(dev);
  972. }
  973. /*
  974. * The device could have been brought down between the start and when
  975. * we get here, don't bring it back up if it's not configured up
  976. */
  977. if (test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags)) {
  978. if (level >= IPOIB_FLUSH_NORMAL)
  979. ipoib_ib_dev_up(dev);
  980. if (ipoib_dev_addr_changed_valid(priv))
  981. ipoib_mcast_restart_task(&priv->restart_task);
  982. }
  983. }
  984. void ipoib_ib_dev_flush_light(struct work_struct *work)
  985. {
  986. struct ipoib_dev_priv *priv =
  987. container_of(work, struct ipoib_dev_priv, flush_light);
  988. __ipoib_ib_dev_flush(priv, IPOIB_FLUSH_LIGHT, 0);
  989. }
  990. void ipoib_ib_dev_flush_normal(struct work_struct *work)
  991. {
  992. struct ipoib_dev_priv *priv =
  993. container_of(work, struct ipoib_dev_priv, flush_normal);
  994. __ipoib_ib_dev_flush(priv, IPOIB_FLUSH_NORMAL, 0);
  995. }
  996. void ipoib_ib_dev_flush_heavy(struct work_struct *work)
  997. {
  998. struct ipoib_dev_priv *priv =
  999. container_of(work, struct ipoib_dev_priv, flush_heavy);
  1000. __ipoib_ib_dev_flush(priv, IPOIB_FLUSH_HEAVY, 0);
  1001. }
  1002. void ipoib_ib_dev_cleanup(struct net_device *dev)
  1003. {
  1004. struct ipoib_dev_priv *priv = netdev_priv(dev);
  1005. ipoib_dbg(priv, "cleaning up ib_dev\n");
  1006. /*
  1007. * We must make sure there are no more (path) completions
  1008. * that may wish to touch priv fields that are no longer valid
  1009. */
  1010. ipoib_flush_paths(dev);
  1011. ipoib_mcast_stop_thread(dev);
  1012. ipoib_mcast_dev_flush(dev);
  1013. /*
  1014. * All of our ah references aren't free until after
  1015. * ipoib_mcast_dev_flush(), ipoib_flush_paths, and
  1016. * the neighbor garbage collection is stopped and reaped.
  1017. * That should all be done now, so make a final ah flush.
  1018. */
  1019. ipoib_stop_ah(dev);
  1020. ipoib_transport_dev_cleanup(dev);
  1021. }