ipoib_ib.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. /*
  2. * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. *
  32. * $Id: ipoib_ib.c 1386 2004-12-27 16:23:17Z roland $
  33. */
  34. #include <linux/delay.h>
  35. #include <linux/dma-mapping.h>
  36. #include <ib_cache.h>
  37. #include "ipoib.h"
  38. #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA
  39. static int data_debug_level;
  40. module_param(data_debug_level, int, 0644);
  41. MODULE_PARM_DESC(data_debug_level,
  42. "Enable data path debug tracing if > 0");
  43. #endif
  44. #define IPOIB_OP_RECV (1ul << 31)
  45. static DECLARE_MUTEX(pkey_sem);
  46. struct ipoib_ah *ipoib_create_ah(struct net_device *dev,
  47. struct ib_pd *pd, struct ib_ah_attr *attr)
  48. {
  49. struct ipoib_ah *ah;
  50. ah = kmalloc(sizeof *ah, GFP_KERNEL);
  51. if (!ah)
  52. return NULL;
  53. ah->dev = dev;
  54. ah->last_send = 0;
  55. kref_init(&ah->ref);
  56. ah->ah = ib_create_ah(pd, attr);
  57. if (IS_ERR(ah->ah)) {
  58. kfree(ah);
  59. ah = NULL;
  60. } else
  61. ipoib_dbg(netdev_priv(dev), "Created ah %p\n", ah->ah);
  62. return ah;
  63. }
  64. void ipoib_free_ah(struct kref *kref)
  65. {
  66. struct ipoib_ah *ah = container_of(kref, struct ipoib_ah, ref);
  67. struct ipoib_dev_priv *priv = netdev_priv(ah->dev);
  68. unsigned long flags;
  69. if (ah->last_send <= priv->tx_tail) {
  70. ipoib_dbg(priv, "Freeing ah %p\n", ah->ah);
  71. ib_destroy_ah(ah->ah);
  72. kfree(ah);
  73. } else {
  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. }
  79. static inline int ipoib_ib_receive(struct ipoib_dev_priv *priv,
  80. unsigned int wr_id,
  81. dma_addr_t addr)
  82. {
  83. struct ib_sge list = {
  84. .addr = addr,
  85. .length = IPOIB_BUF_SIZE,
  86. .lkey = priv->mr->lkey,
  87. };
  88. struct ib_recv_wr param = {
  89. .wr_id = wr_id | IPOIB_OP_RECV,
  90. .sg_list = &list,
  91. .num_sge = 1,
  92. };
  93. struct ib_recv_wr *bad_wr;
  94. return ib_post_recv(priv->qp, &param, &bad_wr);
  95. }
  96. static int ipoib_ib_post_receive(struct net_device *dev, int id)
  97. {
  98. struct ipoib_dev_priv *priv = netdev_priv(dev);
  99. struct sk_buff *skb;
  100. dma_addr_t addr;
  101. int ret;
  102. skb = dev_alloc_skb(IPOIB_BUF_SIZE + 4);
  103. if (!skb) {
  104. ipoib_warn(priv, "failed to allocate receive buffer\n");
  105. priv->rx_ring[id].skb = NULL;
  106. return -ENOMEM;
  107. }
  108. skb_reserve(skb, 4); /* 16 byte align IP header */
  109. priv->rx_ring[id].skb = skb;
  110. addr = dma_map_single(priv->ca->dma_device,
  111. skb->data, IPOIB_BUF_SIZE,
  112. DMA_FROM_DEVICE);
  113. pci_unmap_addr_set(&priv->rx_ring[id], mapping, addr);
  114. ret = ipoib_ib_receive(priv, id, addr);
  115. if (ret) {
  116. ipoib_warn(priv, "ipoib_ib_receive failed for buf %d (%d)\n",
  117. id, ret);
  118. dma_unmap_single(priv->ca->dma_device, addr,
  119. IPOIB_BUF_SIZE, DMA_FROM_DEVICE);
  120. dev_kfree_skb_any(skb);
  121. priv->rx_ring[id].skb = NULL;
  122. }
  123. return ret;
  124. }
  125. static int ipoib_ib_post_receives(struct net_device *dev)
  126. {
  127. struct ipoib_dev_priv *priv = netdev_priv(dev);
  128. int i;
  129. for (i = 0; i < IPOIB_RX_RING_SIZE; ++i) {
  130. if (ipoib_ib_post_receive(dev, i)) {
  131. ipoib_warn(priv, "ipoib_ib_post_receive failed for buf %d\n", i);
  132. return -EIO;
  133. }
  134. }
  135. return 0;
  136. }
  137. static void ipoib_ib_handle_wc(struct net_device *dev,
  138. struct ib_wc *wc)
  139. {
  140. struct ipoib_dev_priv *priv = netdev_priv(dev);
  141. unsigned int wr_id = wc->wr_id;
  142. ipoib_dbg_data(priv, "called: id %d, op %d, status: %d\n",
  143. wr_id, wc->opcode, wc->status);
  144. if (wr_id & IPOIB_OP_RECV) {
  145. wr_id &= ~IPOIB_OP_RECV;
  146. if (wr_id < IPOIB_RX_RING_SIZE) {
  147. struct sk_buff *skb = priv->rx_ring[wr_id].skb;
  148. priv->rx_ring[wr_id].skb = NULL;
  149. dma_unmap_single(priv->ca->dma_device,
  150. pci_unmap_addr(&priv->rx_ring[wr_id],
  151. mapping),
  152. IPOIB_BUF_SIZE,
  153. DMA_FROM_DEVICE);
  154. if (wc->status != IB_WC_SUCCESS) {
  155. if (wc->status != IB_WC_WR_FLUSH_ERR)
  156. ipoib_warn(priv, "failed recv event "
  157. "(status=%d, wrid=%d vend_err %x)\n",
  158. wc->status, wr_id, wc->vendor_err);
  159. dev_kfree_skb_any(skb);
  160. return;
  161. }
  162. ipoib_dbg_data(priv, "received %d bytes, SLID 0x%04x\n",
  163. wc->byte_len, wc->slid);
  164. skb_put(skb, wc->byte_len);
  165. skb_pull(skb, IB_GRH_BYTES);
  166. if (wc->slid != priv->local_lid ||
  167. wc->src_qp != priv->qp->qp_num) {
  168. skb->protocol = ((struct ipoib_header *) skb->data)->proto;
  169. skb->mac.raw = skb->data;
  170. skb_pull(skb, IPOIB_ENCAP_LEN);
  171. dev->last_rx = jiffies;
  172. ++priv->stats.rx_packets;
  173. priv->stats.rx_bytes += skb->len;
  174. skb->dev = dev;
  175. /* XXX get correct PACKET_ type here */
  176. skb->pkt_type = PACKET_HOST;
  177. netif_rx_ni(skb);
  178. } else {
  179. ipoib_dbg_data(priv, "dropping loopback packet\n");
  180. dev_kfree_skb_any(skb);
  181. }
  182. /* repost receive */
  183. if (ipoib_ib_post_receive(dev, wr_id))
  184. ipoib_warn(priv, "ipoib_ib_post_receive failed "
  185. "for buf %d\n", wr_id);
  186. } else
  187. ipoib_warn(priv, "completion event with wrid %d\n",
  188. wr_id);
  189. } else {
  190. struct ipoib_buf *tx_req;
  191. unsigned long flags;
  192. if (wr_id >= IPOIB_TX_RING_SIZE) {
  193. ipoib_warn(priv, "completion event with wrid %d (> %d)\n",
  194. wr_id, IPOIB_TX_RING_SIZE);
  195. return;
  196. }
  197. ipoib_dbg_data(priv, "send complete, wrid %d\n", wr_id);
  198. tx_req = &priv->tx_ring[wr_id];
  199. dma_unmap_single(priv->ca->dma_device,
  200. pci_unmap_addr(tx_req, mapping),
  201. tx_req->skb->len,
  202. DMA_TO_DEVICE);
  203. ++priv->stats.tx_packets;
  204. priv->stats.tx_bytes += tx_req->skb->len;
  205. dev_kfree_skb_any(tx_req->skb);
  206. spin_lock_irqsave(&priv->tx_lock, flags);
  207. ++priv->tx_tail;
  208. if (netif_queue_stopped(dev) &&
  209. priv->tx_head - priv->tx_tail <= IPOIB_TX_RING_SIZE / 2)
  210. netif_wake_queue(dev);
  211. spin_unlock_irqrestore(&priv->tx_lock, flags);
  212. if (wc->status != IB_WC_SUCCESS &&
  213. wc->status != IB_WC_WR_FLUSH_ERR)
  214. ipoib_warn(priv, "failed send event "
  215. "(status=%d, wrid=%d vend_err %x)\n",
  216. wc->status, wr_id, wc->vendor_err);
  217. }
  218. }
  219. void ipoib_ib_completion(struct ib_cq *cq, void *dev_ptr)
  220. {
  221. struct net_device *dev = (struct net_device *) dev_ptr;
  222. struct ipoib_dev_priv *priv = netdev_priv(dev);
  223. int n, i;
  224. ib_req_notify_cq(cq, IB_CQ_NEXT_COMP);
  225. do {
  226. n = ib_poll_cq(cq, IPOIB_NUM_WC, priv->ibwc);
  227. for (i = 0; i < n; ++i)
  228. ipoib_ib_handle_wc(dev, priv->ibwc + i);
  229. } while (n == IPOIB_NUM_WC);
  230. }
  231. static inline int post_send(struct ipoib_dev_priv *priv,
  232. unsigned int wr_id,
  233. struct ib_ah *address, u32 qpn,
  234. dma_addr_t addr, int len)
  235. {
  236. struct ib_send_wr *bad_wr;
  237. priv->tx_sge.addr = addr;
  238. priv->tx_sge.length = len;
  239. priv->tx_wr.wr_id = wr_id;
  240. priv->tx_wr.wr.ud.remote_qpn = qpn;
  241. priv->tx_wr.wr.ud.ah = address;
  242. return ib_post_send(priv->qp, &priv->tx_wr, &bad_wr);
  243. }
  244. void ipoib_send(struct net_device *dev, struct sk_buff *skb,
  245. struct ipoib_ah *address, u32 qpn)
  246. {
  247. struct ipoib_dev_priv *priv = netdev_priv(dev);
  248. struct ipoib_buf *tx_req;
  249. dma_addr_t addr;
  250. if (skb->len > dev->mtu + INFINIBAND_ALEN) {
  251. ipoib_warn(priv, "packet len %d (> %d) too long to send, dropping\n",
  252. skb->len, dev->mtu + INFINIBAND_ALEN);
  253. ++priv->stats.tx_dropped;
  254. ++priv->stats.tx_errors;
  255. dev_kfree_skb_any(skb);
  256. return;
  257. }
  258. ipoib_dbg_data(priv, "sending packet, length=%d address=%p qpn=0x%06x\n",
  259. skb->len, address, qpn);
  260. /*
  261. * We put the skb into the tx_ring _before_ we call post_send()
  262. * because it's entirely possible that the completion handler will
  263. * run before we execute anything after the post_send(). That
  264. * means we have to make sure everything is properly recorded and
  265. * our state is consistent before we call post_send().
  266. */
  267. tx_req = &priv->tx_ring[priv->tx_head & (IPOIB_TX_RING_SIZE - 1)];
  268. tx_req->skb = skb;
  269. addr = dma_map_single(priv->ca->dma_device, skb->data, skb->len,
  270. DMA_TO_DEVICE);
  271. pci_unmap_addr_set(tx_req, mapping, addr);
  272. if (unlikely(post_send(priv, priv->tx_head & (IPOIB_TX_RING_SIZE - 1),
  273. address->ah, qpn, addr, skb->len))) {
  274. ipoib_warn(priv, "post_send failed\n");
  275. ++priv->stats.tx_errors;
  276. dma_unmap_single(priv->ca->dma_device, addr, skb->len,
  277. DMA_TO_DEVICE);
  278. dev_kfree_skb_any(skb);
  279. } else {
  280. dev->trans_start = jiffies;
  281. address->last_send = priv->tx_head;
  282. ++priv->tx_head;
  283. if (priv->tx_head - priv->tx_tail == IPOIB_TX_RING_SIZE) {
  284. ipoib_dbg(priv, "TX ring full, stopping kernel net queue\n");
  285. netif_stop_queue(dev);
  286. }
  287. }
  288. }
  289. static void __ipoib_reap_ah(struct net_device *dev)
  290. {
  291. struct ipoib_dev_priv *priv = netdev_priv(dev);
  292. struct ipoib_ah *ah, *tah;
  293. LIST_HEAD(remove_list);
  294. spin_lock_irq(&priv->lock);
  295. list_for_each_entry_safe(ah, tah, &priv->dead_ahs, list)
  296. if (ah->last_send <= priv->tx_tail) {
  297. list_del(&ah->list);
  298. list_add_tail(&ah->list, &remove_list);
  299. }
  300. spin_unlock_irq(&priv->lock);
  301. list_for_each_entry_safe(ah, tah, &remove_list, list) {
  302. ipoib_dbg(priv, "Reaping ah %p\n", ah->ah);
  303. ib_destroy_ah(ah->ah);
  304. kfree(ah);
  305. }
  306. }
  307. void ipoib_reap_ah(void *dev_ptr)
  308. {
  309. struct net_device *dev = dev_ptr;
  310. struct ipoib_dev_priv *priv = netdev_priv(dev);
  311. __ipoib_reap_ah(dev);
  312. if (!test_bit(IPOIB_STOP_REAPER, &priv->flags))
  313. queue_delayed_work(ipoib_workqueue, &priv->ah_reap_task, HZ);
  314. }
  315. int ipoib_ib_dev_open(struct net_device *dev)
  316. {
  317. struct ipoib_dev_priv *priv = netdev_priv(dev);
  318. int ret;
  319. ret = ipoib_qp_create(dev);
  320. if (ret) {
  321. ipoib_warn(priv, "ipoib_qp_create returned %d\n", ret);
  322. return -1;
  323. }
  324. ret = ipoib_ib_post_receives(dev);
  325. if (ret) {
  326. ipoib_warn(priv, "ipoib_ib_post_receives returned %d\n", ret);
  327. return -1;
  328. }
  329. clear_bit(IPOIB_STOP_REAPER, &priv->flags);
  330. queue_delayed_work(ipoib_workqueue, &priv->ah_reap_task, HZ);
  331. return 0;
  332. }
  333. int ipoib_ib_dev_up(struct net_device *dev)
  334. {
  335. struct ipoib_dev_priv *priv = netdev_priv(dev);
  336. set_bit(IPOIB_FLAG_OPER_UP, &priv->flags);
  337. return ipoib_mcast_start_thread(dev);
  338. }
  339. int ipoib_ib_dev_down(struct net_device *dev)
  340. {
  341. struct ipoib_dev_priv *priv = netdev_priv(dev);
  342. ipoib_dbg(priv, "downing ib_dev\n");
  343. clear_bit(IPOIB_FLAG_OPER_UP, &priv->flags);
  344. netif_carrier_off(dev);
  345. /* Shutdown the P_Key thread if still active */
  346. if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) {
  347. down(&pkey_sem);
  348. set_bit(IPOIB_PKEY_STOP, &priv->flags);
  349. cancel_delayed_work(&priv->pkey_task);
  350. up(&pkey_sem);
  351. flush_workqueue(ipoib_workqueue);
  352. }
  353. ipoib_mcast_stop_thread(dev);
  354. /*
  355. * Flush the multicast groups first so we stop any multicast joins. The
  356. * completion thread may have already died and we may deadlock waiting
  357. * for the completion thread to finish some multicast joins.
  358. */
  359. ipoib_mcast_dev_flush(dev);
  360. /* Delete broadcast and local addresses since they will be recreated */
  361. ipoib_mcast_dev_down(dev);
  362. ipoib_flush_paths(dev);
  363. return 0;
  364. }
  365. static int recvs_pending(struct net_device *dev)
  366. {
  367. struct ipoib_dev_priv *priv = netdev_priv(dev);
  368. int pending = 0;
  369. int i;
  370. for (i = 0; i < IPOIB_RX_RING_SIZE; ++i)
  371. if (priv->rx_ring[i].skb)
  372. ++pending;
  373. return pending;
  374. }
  375. int ipoib_ib_dev_stop(struct net_device *dev)
  376. {
  377. struct ipoib_dev_priv *priv = netdev_priv(dev);
  378. struct ib_qp_attr qp_attr;
  379. int attr_mask;
  380. unsigned long begin;
  381. struct ipoib_buf *tx_req;
  382. int i;
  383. /* Kill the existing QP and allocate a new one */
  384. qp_attr.qp_state = IB_QPS_ERR;
  385. attr_mask = IB_QP_STATE;
  386. if (ib_modify_qp(priv->qp, &qp_attr, attr_mask))
  387. ipoib_warn(priv, "Failed to modify QP to ERROR state\n");
  388. /* Wait for all sends and receives to complete */
  389. begin = jiffies;
  390. while (priv->tx_head != priv->tx_tail || recvs_pending(dev)) {
  391. if (time_after(jiffies, begin + 5 * HZ)) {
  392. ipoib_warn(priv, "timing out; %d sends %d receives not completed\n",
  393. priv->tx_head - priv->tx_tail, recvs_pending(dev));
  394. /*
  395. * assume the HW is wedged and just free up
  396. * all our pending work requests.
  397. */
  398. while (priv->tx_tail < priv->tx_head) {
  399. tx_req = &priv->tx_ring[priv->tx_tail &
  400. (IPOIB_TX_RING_SIZE - 1)];
  401. dma_unmap_single(priv->ca->dma_device,
  402. pci_unmap_addr(tx_req, mapping),
  403. tx_req->skb->len,
  404. DMA_TO_DEVICE);
  405. dev_kfree_skb_any(tx_req->skb);
  406. ++priv->tx_tail;
  407. }
  408. for (i = 0; i < IPOIB_RX_RING_SIZE; ++i)
  409. if (priv->rx_ring[i].skb) {
  410. dma_unmap_single(priv->ca->dma_device,
  411. pci_unmap_addr(&priv->rx_ring[i],
  412. mapping),
  413. IPOIB_BUF_SIZE,
  414. DMA_FROM_DEVICE);
  415. dev_kfree_skb_any(priv->rx_ring[i].skb);
  416. priv->rx_ring[i].skb = NULL;
  417. }
  418. goto timeout;
  419. }
  420. msleep(1);
  421. }
  422. ipoib_dbg(priv, "All sends and receives done.\n");
  423. timeout:
  424. qp_attr.qp_state = IB_QPS_RESET;
  425. attr_mask = IB_QP_STATE;
  426. if (ib_modify_qp(priv->qp, &qp_attr, attr_mask))
  427. ipoib_warn(priv, "Failed to modify QP to RESET state\n");
  428. /* Wait for all AHs to be reaped */
  429. set_bit(IPOIB_STOP_REAPER, &priv->flags);
  430. cancel_delayed_work(&priv->ah_reap_task);
  431. flush_workqueue(ipoib_workqueue);
  432. begin = jiffies;
  433. while (!list_empty(&priv->dead_ahs)) {
  434. __ipoib_reap_ah(dev);
  435. if (time_after(jiffies, begin + HZ)) {
  436. ipoib_warn(priv, "timing out; will leak address handles\n");
  437. break;
  438. }
  439. msleep(1);
  440. }
  441. return 0;
  442. }
  443. int ipoib_ib_dev_init(struct net_device *dev, struct ib_device *ca, int port)
  444. {
  445. struct ipoib_dev_priv *priv = netdev_priv(dev);
  446. priv->ca = ca;
  447. priv->port = port;
  448. priv->qp = NULL;
  449. if (ipoib_transport_dev_init(dev, ca)) {
  450. printk(KERN_WARNING "%s: ipoib_transport_dev_init failed\n", ca->name);
  451. return -ENODEV;
  452. }
  453. if (dev->flags & IFF_UP) {
  454. if (ipoib_ib_dev_open(dev)) {
  455. ipoib_transport_dev_cleanup(dev);
  456. return -ENODEV;
  457. }
  458. }
  459. return 0;
  460. }
  461. void ipoib_ib_dev_flush(void *_dev)
  462. {
  463. struct net_device *dev = (struct net_device *)_dev;
  464. struct ipoib_dev_priv *priv = netdev_priv(dev), *cpriv;
  465. if (!test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags))
  466. return;
  467. ipoib_dbg(priv, "flushing\n");
  468. ipoib_ib_dev_down(dev);
  469. /*
  470. * The device could have been brought down between the start and when
  471. * we get here, don't bring it back up if it's not configured up
  472. */
  473. if (test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags))
  474. ipoib_ib_dev_up(dev);
  475. /* Flush any child interfaces too */
  476. list_for_each_entry(cpriv, &priv->child_intfs, list)
  477. ipoib_ib_dev_flush(&cpriv->dev);
  478. }
  479. void ipoib_ib_dev_cleanup(struct net_device *dev)
  480. {
  481. struct ipoib_dev_priv *priv = netdev_priv(dev);
  482. ipoib_dbg(priv, "cleaning up ib_dev\n");
  483. ipoib_mcast_stop_thread(dev);
  484. /* Delete the broadcast address and the local address */
  485. ipoib_mcast_dev_down(dev);
  486. ipoib_transport_dev_cleanup(dev);
  487. }
  488. /*
  489. * Delayed P_Key Assigment Interim Support
  490. *
  491. * The following is initial implementation of delayed P_Key assigment
  492. * mechanism. It is using the same approach implemented for the multicast
  493. * group join. The single goal of this implementation is to quickly address
  494. * Bug #2507. This implementation will probably be removed when the P_Key
  495. * change async notification is available.
  496. */
  497. int ipoib_open(struct net_device *dev);
  498. static void ipoib_pkey_dev_check_presence(struct net_device *dev)
  499. {
  500. struct ipoib_dev_priv *priv = netdev_priv(dev);
  501. u16 pkey_index = 0;
  502. if (ib_find_cached_pkey(priv->ca, priv->port, priv->pkey, &pkey_index))
  503. clear_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
  504. else
  505. set_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
  506. }
  507. void ipoib_pkey_poll(void *dev_ptr)
  508. {
  509. struct net_device *dev = dev_ptr;
  510. struct ipoib_dev_priv *priv = netdev_priv(dev);
  511. ipoib_pkey_dev_check_presence(dev);
  512. if (test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags))
  513. ipoib_open(dev);
  514. else {
  515. down(&pkey_sem);
  516. if (!test_bit(IPOIB_PKEY_STOP, &priv->flags))
  517. queue_delayed_work(ipoib_workqueue,
  518. &priv->pkey_task,
  519. HZ);
  520. up(&pkey_sem);
  521. }
  522. }
  523. int ipoib_pkey_dev_delay_open(struct net_device *dev)
  524. {
  525. struct ipoib_dev_priv *priv = netdev_priv(dev);
  526. /* Look for the interface pkey value in the IB Port P_Key table and */
  527. /* set the interface pkey assigment flag */
  528. ipoib_pkey_dev_check_presence(dev);
  529. /* P_Key value not assigned yet - start polling */
  530. if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) {
  531. down(&pkey_sem);
  532. clear_bit(IPOIB_PKEY_STOP, &priv->flags);
  533. queue_delayed_work(ipoib_workqueue,
  534. &priv->pkey_task,
  535. HZ);
  536. up(&pkey_sem);
  537. return 1;
  538. }
  539. return 0;
  540. }