ipoib_ib.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  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. * $Id: ipoib_ib.c 1386 2004-12-27 16:23:17Z roland $
  36. */
  37. #include <linux/delay.h>
  38. #include <linux/dma-mapping.h>
  39. #include <rdma/ib_cache.h>
  40. #include "ipoib.h"
  41. #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA
  42. static int data_debug_level;
  43. module_param(data_debug_level, int, 0644);
  44. MODULE_PARM_DESC(data_debug_level,
  45. "Enable data path debug tracing if > 0");
  46. #endif
  47. #define IPOIB_OP_RECV (1ul << 31)
  48. static DEFINE_MUTEX(pkey_mutex);
  49. struct ipoib_ah *ipoib_create_ah(struct net_device *dev,
  50. struct ib_pd *pd, struct ib_ah_attr *attr)
  51. {
  52. struct ipoib_ah *ah;
  53. ah = kmalloc(sizeof *ah, GFP_KERNEL);
  54. if (!ah)
  55. return NULL;
  56. ah->dev = dev;
  57. ah->last_send = 0;
  58. kref_init(&ah->ref);
  59. ah->ah = ib_create_ah(pd, attr);
  60. if (IS_ERR(ah->ah)) {
  61. kfree(ah);
  62. ah = NULL;
  63. } else
  64. ipoib_dbg(netdev_priv(dev), "Created ah %p\n", ah->ah);
  65. return ah;
  66. }
  67. void ipoib_free_ah(struct kref *kref)
  68. {
  69. struct ipoib_ah *ah = container_of(kref, struct ipoib_ah, ref);
  70. struct ipoib_dev_priv *priv = netdev_priv(ah->dev);
  71. unsigned long flags;
  72. spin_lock_irqsave(&priv->lock, flags);
  73. list_add_tail(&ah->list, &priv->dead_ahs);
  74. spin_unlock_irqrestore(&priv->lock, flags);
  75. }
  76. static int ipoib_ib_post_receive(struct net_device *dev, int id)
  77. {
  78. struct ipoib_dev_priv *priv = netdev_priv(dev);
  79. struct ib_sge list;
  80. struct ib_recv_wr param;
  81. struct ib_recv_wr *bad_wr;
  82. int ret;
  83. list.addr = priv->rx_ring[id].mapping;
  84. list.length = IPOIB_BUF_SIZE;
  85. list.lkey = priv->mr->lkey;
  86. param.next = NULL;
  87. param.wr_id = id | IPOIB_OP_RECV;
  88. param.sg_list = &list;
  89. param.num_sge = 1;
  90. ret = ib_post_recv(priv->qp, &param, &bad_wr);
  91. if (unlikely(ret)) {
  92. ipoib_warn(priv, "receive failed for buf %d (%d)\n", id, ret);
  93. ib_dma_unmap_single(priv->ca, priv->rx_ring[id].mapping,
  94. IPOIB_BUF_SIZE, DMA_FROM_DEVICE);
  95. dev_kfree_skb_any(priv->rx_ring[id].skb);
  96. priv->rx_ring[id].skb = NULL;
  97. }
  98. return ret;
  99. }
  100. static int ipoib_alloc_rx_skb(struct net_device *dev, int id)
  101. {
  102. struct ipoib_dev_priv *priv = netdev_priv(dev);
  103. struct sk_buff *skb;
  104. u64 addr;
  105. skb = dev_alloc_skb(IPOIB_BUF_SIZE + 4);
  106. if (!skb)
  107. return -ENOMEM;
  108. /*
  109. * IB will leave a 40 byte gap for a GRH and IPoIB adds a 4 byte
  110. * header. So we need 4 more bytes to get to 48 and align the
  111. * IP header to a multiple of 16.
  112. */
  113. skb_reserve(skb, 4);
  114. addr = ib_dma_map_single(priv->ca, skb->data, IPOIB_BUF_SIZE,
  115. DMA_FROM_DEVICE);
  116. if (unlikely(ib_dma_mapping_error(priv->ca, addr))) {
  117. dev_kfree_skb_any(skb);
  118. return -EIO;
  119. }
  120. priv->rx_ring[id].skb = skb;
  121. priv->rx_ring[id].mapping = addr;
  122. return 0;
  123. }
  124. static int ipoib_ib_post_receives(struct net_device *dev)
  125. {
  126. struct ipoib_dev_priv *priv = netdev_priv(dev);
  127. int i;
  128. for (i = 0; i < ipoib_recvq_size; ++i) {
  129. if (ipoib_alloc_rx_skb(dev, i)) {
  130. ipoib_warn(priv, "failed to allocate receive buffer %d\n", i);
  131. return -ENOMEM;
  132. }
  133. if (ipoib_ib_post_receive(dev, i)) {
  134. ipoib_warn(priv, "ipoib_ib_post_receive failed for buf %d\n", i);
  135. return -EIO;
  136. }
  137. }
  138. return 0;
  139. }
  140. static void ipoib_ib_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
  141. {
  142. struct ipoib_dev_priv *priv = netdev_priv(dev);
  143. unsigned int wr_id = wc->wr_id & ~IPOIB_OP_RECV;
  144. struct sk_buff *skb;
  145. u64 addr;
  146. ipoib_dbg_data(priv, "recv completion: id %d, op %d, status: %d\n",
  147. wr_id, wc->opcode, wc->status);
  148. if (unlikely(wr_id >= ipoib_recvq_size)) {
  149. ipoib_warn(priv, "recv completion event with wrid %d (> %d)\n",
  150. wr_id, ipoib_recvq_size);
  151. return;
  152. }
  153. skb = priv->rx_ring[wr_id].skb;
  154. addr = priv->rx_ring[wr_id].mapping;
  155. if (unlikely(wc->status != IB_WC_SUCCESS)) {
  156. if (wc->status != IB_WC_WR_FLUSH_ERR)
  157. ipoib_warn(priv, "failed recv event "
  158. "(status=%d, wrid=%d vend_err %x)\n",
  159. wc->status, wr_id, wc->vendor_err);
  160. ib_dma_unmap_single(priv->ca, addr,
  161. IPOIB_BUF_SIZE, DMA_FROM_DEVICE);
  162. dev_kfree_skb_any(skb);
  163. priv->rx_ring[wr_id].skb = NULL;
  164. return;
  165. }
  166. /*
  167. * If we can't allocate a new RX buffer, dump
  168. * this packet and reuse the old buffer.
  169. */
  170. if (unlikely(ipoib_alloc_rx_skb(dev, wr_id))) {
  171. ++priv->stats.rx_dropped;
  172. goto repost;
  173. }
  174. ipoib_dbg_data(priv, "received %d bytes, SLID 0x%04x\n",
  175. wc->byte_len, wc->slid);
  176. ib_dma_unmap_single(priv->ca, addr, IPOIB_BUF_SIZE, DMA_FROM_DEVICE);
  177. skb_put(skb, wc->byte_len);
  178. skb_pull(skb, IB_GRH_BYTES);
  179. if (wc->slid != priv->local_lid ||
  180. wc->src_qp != priv->qp->qp_num) {
  181. skb->protocol = ((struct ipoib_header *) skb->data)->proto;
  182. skb->mac.raw = skb->data;
  183. skb_pull(skb, IPOIB_ENCAP_LEN);
  184. dev->last_rx = jiffies;
  185. ++priv->stats.rx_packets;
  186. priv->stats.rx_bytes += skb->len;
  187. skb->dev = dev;
  188. /* XXX get correct PACKET_ type here */
  189. skb->pkt_type = PACKET_HOST;
  190. netif_rx_ni(skb);
  191. } else {
  192. ipoib_dbg_data(priv, "dropping loopback packet\n");
  193. dev_kfree_skb_any(skb);
  194. }
  195. repost:
  196. if (unlikely(ipoib_ib_post_receive(dev, wr_id)))
  197. ipoib_warn(priv, "ipoib_ib_post_receive failed "
  198. "for buf %d\n", wr_id);
  199. }
  200. static void ipoib_ib_handle_tx_wc(struct net_device *dev, struct ib_wc *wc)
  201. {
  202. struct ipoib_dev_priv *priv = netdev_priv(dev);
  203. unsigned int wr_id = wc->wr_id;
  204. struct ipoib_tx_buf *tx_req;
  205. unsigned long flags;
  206. ipoib_dbg_data(priv, "send completion: id %d, op %d, status: %d\n",
  207. wr_id, wc->opcode, wc->status);
  208. if (unlikely(wr_id >= ipoib_sendq_size)) {
  209. ipoib_warn(priv, "send completion event with wrid %d (> %d)\n",
  210. wr_id, ipoib_sendq_size);
  211. return;
  212. }
  213. tx_req = &priv->tx_ring[wr_id];
  214. ib_dma_unmap_single(priv->ca, tx_req->mapping,
  215. tx_req->skb->len, DMA_TO_DEVICE);
  216. ++priv->stats.tx_packets;
  217. priv->stats.tx_bytes += tx_req->skb->len;
  218. dev_kfree_skb_any(tx_req->skb);
  219. spin_lock_irqsave(&priv->tx_lock, flags);
  220. ++priv->tx_tail;
  221. if (netif_queue_stopped(dev) &&
  222. test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags) &&
  223. priv->tx_head - priv->tx_tail <= ipoib_sendq_size >> 1)
  224. netif_wake_queue(dev);
  225. spin_unlock_irqrestore(&priv->tx_lock, flags);
  226. if (wc->status != IB_WC_SUCCESS &&
  227. wc->status != IB_WC_WR_FLUSH_ERR)
  228. ipoib_warn(priv, "failed send event "
  229. "(status=%d, wrid=%d vend_err %x)\n",
  230. wc->status, wr_id, wc->vendor_err);
  231. }
  232. static void ipoib_ib_handle_wc(struct net_device *dev, struct ib_wc *wc)
  233. {
  234. if (wc->wr_id & IPOIB_OP_RECV)
  235. ipoib_ib_handle_rx_wc(dev, wc);
  236. else
  237. ipoib_ib_handle_tx_wc(dev, wc);
  238. }
  239. void ipoib_ib_completion(struct ib_cq *cq, void *dev_ptr)
  240. {
  241. struct net_device *dev = (struct net_device *) dev_ptr;
  242. struct ipoib_dev_priv *priv = netdev_priv(dev);
  243. int n, i;
  244. ib_req_notify_cq(cq, IB_CQ_NEXT_COMP);
  245. do {
  246. n = ib_poll_cq(cq, IPOIB_NUM_WC, priv->ibwc);
  247. for (i = 0; i < n; ++i)
  248. ipoib_ib_handle_wc(dev, priv->ibwc + i);
  249. } while (n == IPOIB_NUM_WC);
  250. }
  251. static inline int post_send(struct ipoib_dev_priv *priv,
  252. unsigned int wr_id,
  253. struct ib_ah *address, u32 qpn,
  254. u64 addr, int len)
  255. {
  256. struct ib_send_wr *bad_wr;
  257. priv->tx_sge.addr = addr;
  258. priv->tx_sge.length = len;
  259. priv->tx_wr.wr_id = wr_id;
  260. priv->tx_wr.wr.ud.remote_qpn = qpn;
  261. priv->tx_wr.wr.ud.ah = address;
  262. return ib_post_send(priv->qp, &priv->tx_wr, &bad_wr);
  263. }
  264. void ipoib_send(struct net_device *dev, struct sk_buff *skb,
  265. struct ipoib_ah *address, u32 qpn)
  266. {
  267. struct ipoib_dev_priv *priv = netdev_priv(dev);
  268. struct ipoib_tx_buf *tx_req;
  269. u64 addr;
  270. if (unlikely(skb->len > dev->mtu + INFINIBAND_ALEN)) {
  271. ipoib_warn(priv, "packet len %d (> %d) too long to send, dropping\n",
  272. skb->len, dev->mtu + INFINIBAND_ALEN);
  273. ++priv->stats.tx_dropped;
  274. ++priv->stats.tx_errors;
  275. dev_kfree_skb_any(skb);
  276. return;
  277. }
  278. ipoib_dbg_data(priv, "sending packet, length=%d address=%p qpn=0x%06x\n",
  279. skb->len, address, qpn);
  280. /*
  281. * We put the skb into the tx_ring _before_ we call post_send()
  282. * because it's entirely possible that the completion handler will
  283. * run before we execute anything after the post_send(). That
  284. * means we have to make sure everything is properly recorded and
  285. * our state is consistent before we call post_send().
  286. */
  287. tx_req = &priv->tx_ring[priv->tx_head & (ipoib_sendq_size - 1)];
  288. tx_req->skb = skb;
  289. addr = ib_dma_map_single(priv->ca, skb->data, skb->len,
  290. DMA_TO_DEVICE);
  291. if (unlikely(ib_dma_mapping_error(priv->ca, addr))) {
  292. ++priv->stats.tx_errors;
  293. dev_kfree_skb_any(skb);
  294. return;
  295. }
  296. tx_req->mapping = addr;
  297. if (unlikely(post_send(priv, priv->tx_head & (ipoib_sendq_size - 1),
  298. address->ah, qpn, addr, skb->len))) {
  299. ipoib_warn(priv, "post_send failed\n");
  300. ++priv->stats.tx_errors;
  301. ib_dma_unmap_single(priv->ca, addr, skb->len, DMA_TO_DEVICE);
  302. dev_kfree_skb_any(skb);
  303. } else {
  304. dev->trans_start = jiffies;
  305. address->last_send = priv->tx_head;
  306. ++priv->tx_head;
  307. if (priv->tx_head - priv->tx_tail == ipoib_sendq_size) {
  308. ipoib_dbg(priv, "TX ring full, stopping kernel net queue\n");
  309. netif_stop_queue(dev);
  310. }
  311. }
  312. }
  313. static void __ipoib_reap_ah(struct net_device *dev)
  314. {
  315. struct ipoib_dev_priv *priv = netdev_priv(dev);
  316. struct ipoib_ah *ah, *tah;
  317. LIST_HEAD(remove_list);
  318. spin_lock_irq(&priv->tx_lock);
  319. spin_lock(&priv->lock);
  320. list_for_each_entry_safe(ah, tah, &priv->dead_ahs, list)
  321. if ((int) priv->tx_tail - (int) ah->last_send >= 0) {
  322. list_del(&ah->list);
  323. ib_destroy_ah(ah->ah);
  324. kfree(ah);
  325. }
  326. spin_unlock(&priv->lock);
  327. spin_unlock_irq(&priv->tx_lock);
  328. }
  329. void ipoib_reap_ah(struct work_struct *work)
  330. {
  331. struct ipoib_dev_priv *priv =
  332. container_of(work, struct ipoib_dev_priv, ah_reap_task.work);
  333. struct net_device *dev = priv->dev;
  334. __ipoib_reap_ah(dev);
  335. if (!test_bit(IPOIB_STOP_REAPER, &priv->flags))
  336. queue_delayed_work(ipoib_workqueue, &priv->ah_reap_task, HZ);
  337. }
  338. int ipoib_ib_dev_open(struct net_device *dev)
  339. {
  340. struct ipoib_dev_priv *priv = netdev_priv(dev);
  341. int ret;
  342. ret = ipoib_init_qp(dev);
  343. if (ret) {
  344. ipoib_warn(priv, "ipoib_init_qp returned %d\n", ret);
  345. return -1;
  346. }
  347. ret = ipoib_ib_post_receives(dev);
  348. if (ret) {
  349. ipoib_warn(priv, "ipoib_ib_post_receives returned %d\n", ret);
  350. ipoib_ib_dev_stop(dev);
  351. return -1;
  352. }
  353. clear_bit(IPOIB_STOP_REAPER, &priv->flags);
  354. queue_delayed_work(ipoib_workqueue, &priv->ah_reap_task, HZ);
  355. set_bit(IPOIB_FLAG_INITIALIZED, &priv->flags);
  356. return 0;
  357. }
  358. static void ipoib_pkey_dev_check_presence(struct net_device *dev)
  359. {
  360. struct ipoib_dev_priv *priv = netdev_priv(dev);
  361. u16 pkey_index = 0;
  362. if (ib_find_cached_pkey(priv->ca, priv->port, priv->pkey, &pkey_index))
  363. clear_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
  364. else
  365. set_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
  366. }
  367. int ipoib_ib_dev_up(struct net_device *dev)
  368. {
  369. struct ipoib_dev_priv *priv = netdev_priv(dev);
  370. ipoib_pkey_dev_check_presence(dev);
  371. if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) {
  372. ipoib_dbg(priv, "PKEY is not assigned.\n");
  373. return 0;
  374. }
  375. set_bit(IPOIB_FLAG_OPER_UP, &priv->flags);
  376. return ipoib_mcast_start_thread(dev);
  377. }
  378. int ipoib_ib_dev_down(struct net_device *dev, int flush)
  379. {
  380. struct ipoib_dev_priv *priv = netdev_priv(dev);
  381. ipoib_dbg(priv, "downing ib_dev\n");
  382. clear_bit(IPOIB_FLAG_OPER_UP, &priv->flags);
  383. netif_carrier_off(dev);
  384. /* Shutdown the P_Key thread if still active */
  385. if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) {
  386. mutex_lock(&pkey_mutex);
  387. set_bit(IPOIB_PKEY_STOP, &priv->flags);
  388. cancel_delayed_work(&priv->pkey_task);
  389. mutex_unlock(&pkey_mutex);
  390. if (flush)
  391. flush_workqueue(ipoib_workqueue);
  392. }
  393. ipoib_mcast_stop_thread(dev, flush);
  394. ipoib_mcast_dev_flush(dev);
  395. ipoib_flush_paths(dev);
  396. return 0;
  397. }
  398. static int recvs_pending(struct net_device *dev)
  399. {
  400. struct ipoib_dev_priv *priv = netdev_priv(dev);
  401. int pending = 0;
  402. int i;
  403. for (i = 0; i < ipoib_recvq_size; ++i)
  404. if (priv->rx_ring[i].skb)
  405. ++pending;
  406. return pending;
  407. }
  408. int ipoib_ib_dev_stop(struct net_device *dev)
  409. {
  410. struct ipoib_dev_priv *priv = netdev_priv(dev);
  411. struct ib_qp_attr qp_attr;
  412. unsigned long begin;
  413. struct ipoib_tx_buf *tx_req;
  414. int i;
  415. clear_bit(IPOIB_FLAG_INITIALIZED, &priv->flags);
  416. /*
  417. * Move our QP to the error state and then reinitialize in
  418. * when all work requests have completed or have been flushed.
  419. */
  420. qp_attr.qp_state = IB_QPS_ERR;
  421. if (ib_modify_qp(priv->qp, &qp_attr, IB_QP_STATE))
  422. ipoib_warn(priv, "Failed to modify QP to ERROR state\n");
  423. /* Wait for all sends and receives to complete */
  424. begin = jiffies;
  425. while (priv->tx_head != priv->tx_tail || recvs_pending(dev)) {
  426. if (time_after(jiffies, begin + 5 * HZ)) {
  427. ipoib_warn(priv, "timing out; %d sends %d receives not completed\n",
  428. priv->tx_head - priv->tx_tail, recvs_pending(dev));
  429. /*
  430. * assume the HW is wedged and just free up
  431. * all our pending work requests.
  432. */
  433. while ((int) priv->tx_tail - (int) priv->tx_head < 0) {
  434. tx_req = &priv->tx_ring[priv->tx_tail &
  435. (ipoib_sendq_size - 1)];
  436. ib_dma_unmap_single(priv->ca,
  437. tx_req->mapping,
  438. tx_req->skb->len,
  439. DMA_TO_DEVICE);
  440. dev_kfree_skb_any(tx_req->skb);
  441. ++priv->tx_tail;
  442. }
  443. for (i = 0; i < ipoib_recvq_size; ++i) {
  444. struct ipoib_rx_buf *rx_req;
  445. rx_req = &priv->rx_ring[i];
  446. if (!rx_req->skb)
  447. continue;
  448. ib_dma_unmap_single(priv->ca,
  449. rx_req->mapping,
  450. IPOIB_BUF_SIZE,
  451. DMA_FROM_DEVICE);
  452. dev_kfree_skb_any(rx_req->skb);
  453. rx_req->skb = NULL;
  454. }
  455. goto timeout;
  456. }
  457. msleep(1);
  458. }
  459. ipoib_dbg(priv, "All sends and receives done.\n");
  460. timeout:
  461. qp_attr.qp_state = IB_QPS_RESET;
  462. if (ib_modify_qp(priv->qp, &qp_attr, IB_QP_STATE))
  463. ipoib_warn(priv, "Failed to modify QP to RESET state\n");
  464. /* Wait for all AHs to be reaped */
  465. set_bit(IPOIB_STOP_REAPER, &priv->flags);
  466. cancel_delayed_work(&priv->ah_reap_task);
  467. flush_workqueue(ipoib_workqueue);
  468. begin = jiffies;
  469. while (!list_empty(&priv->dead_ahs)) {
  470. __ipoib_reap_ah(dev);
  471. if (time_after(jiffies, begin + HZ)) {
  472. ipoib_warn(priv, "timing out; will leak address handles\n");
  473. break;
  474. }
  475. msleep(1);
  476. }
  477. return 0;
  478. }
  479. int ipoib_ib_dev_init(struct net_device *dev, struct ib_device *ca, int port)
  480. {
  481. struct ipoib_dev_priv *priv = netdev_priv(dev);
  482. priv->ca = ca;
  483. priv->port = port;
  484. priv->qp = NULL;
  485. if (ipoib_transport_dev_init(dev, ca)) {
  486. printk(KERN_WARNING "%s: ipoib_transport_dev_init failed\n", ca->name);
  487. return -ENODEV;
  488. }
  489. if (dev->flags & IFF_UP) {
  490. if (ipoib_ib_dev_open(dev)) {
  491. ipoib_transport_dev_cleanup(dev);
  492. return -ENODEV;
  493. }
  494. }
  495. return 0;
  496. }
  497. void ipoib_ib_dev_flush(struct work_struct *work)
  498. {
  499. struct ipoib_dev_priv *cpriv, *priv =
  500. container_of(work, struct ipoib_dev_priv, flush_task);
  501. struct net_device *dev = priv->dev;
  502. if (!test_bit(IPOIB_FLAG_INITIALIZED, &priv->flags) ) {
  503. ipoib_dbg(priv, "Not flushing - IPOIB_FLAG_INITIALIZED not set.\n");
  504. return;
  505. }
  506. if (!test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags)) {
  507. ipoib_dbg(priv, "Not flushing - IPOIB_FLAG_ADMIN_UP not set.\n");
  508. return;
  509. }
  510. ipoib_dbg(priv, "flushing\n");
  511. ipoib_ib_dev_down(dev, 0);
  512. /*
  513. * The device could have been brought down between the start and when
  514. * we get here, don't bring it back up if it's not configured up
  515. */
  516. if (test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags)) {
  517. ipoib_ib_dev_up(dev);
  518. ipoib_mcast_restart_task(&priv->restart_task);
  519. }
  520. mutex_lock(&priv->vlan_mutex);
  521. /* Flush any child interfaces too */
  522. list_for_each_entry(cpriv, &priv->child_intfs, list)
  523. ipoib_ib_dev_flush(&cpriv->flush_task);
  524. mutex_unlock(&priv->vlan_mutex);
  525. }
  526. void ipoib_ib_dev_cleanup(struct net_device *dev)
  527. {
  528. struct ipoib_dev_priv *priv = netdev_priv(dev);
  529. ipoib_dbg(priv, "cleaning up ib_dev\n");
  530. ipoib_mcast_stop_thread(dev, 1);
  531. ipoib_mcast_dev_flush(dev);
  532. ipoib_transport_dev_cleanup(dev);
  533. }
  534. /*
  535. * Delayed P_Key Assigment Interim Support
  536. *
  537. * The following is initial implementation of delayed P_Key assigment
  538. * mechanism. It is using the same approach implemented for the multicast
  539. * group join. The single goal of this implementation is to quickly address
  540. * Bug #2507. This implementation will probably be removed when the P_Key
  541. * change async notification is available.
  542. */
  543. void ipoib_pkey_poll(struct work_struct *work)
  544. {
  545. struct ipoib_dev_priv *priv =
  546. container_of(work, struct ipoib_dev_priv, pkey_task.work);
  547. struct net_device *dev = priv->dev;
  548. ipoib_pkey_dev_check_presence(dev);
  549. if (test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags))
  550. ipoib_open(dev);
  551. else {
  552. mutex_lock(&pkey_mutex);
  553. if (!test_bit(IPOIB_PKEY_STOP, &priv->flags))
  554. queue_delayed_work(ipoib_workqueue,
  555. &priv->pkey_task,
  556. HZ);
  557. mutex_unlock(&pkey_mutex);
  558. }
  559. }
  560. int ipoib_pkey_dev_delay_open(struct net_device *dev)
  561. {
  562. struct ipoib_dev_priv *priv = netdev_priv(dev);
  563. /* Look for the interface pkey value in the IB Port P_Key table and */
  564. /* set the interface pkey assigment flag */
  565. ipoib_pkey_dev_check_presence(dev);
  566. /* P_Key value not assigned yet - start polling */
  567. if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) {
  568. mutex_lock(&pkey_mutex);
  569. clear_bit(IPOIB_PKEY_STOP, &priv->flags);
  570. queue_delayed_work(ipoib_workqueue,
  571. &priv->pkey_task,
  572. HZ);
  573. mutex_unlock(&pkey_mutex);
  574. return 1;
  575. }
  576. return 0;
  577. }