ipoib_ib.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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 DECLARE_MUTEX(pkey_sem);
  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. if ((int) priv->tx_tail - (int) ah->last_send >= 0) {
  73. ipoib_dbg(priv, "Freeing ah %p\n", ah->ah);
  74. ib_destroy_ah(ah->ah);
  75. kfree(ah);
  76. } else {
  77. spin_lock_irqsave(&priv->lock, flags);
  78. list_add_tail(&ah->list, &priv->dead_ahs);
  79. spin_unlock_irqrestore(&priv->lock, flags);
  80. }
  81. }
  82. static inline int ipoib_ib_receive(struct ipoib_dev_priv *priv,
  83. unsigned int wr_id,
  84. dma_addr_t addr)
  85. {
  86. struct ib_sge list = {
  87. .addr = addr,
  88. .length = IPOIB_BUF_SIZE,
  89. .lkey = priv->mr->lkey,
  90. };
  91. struct ib_recv_wr param = {
  92. .wr_id = wr_id | IPOIB_OP_RECV,
  93. .sg_list = &list,
  94. .num_sge = 1,
  95. };
  96. struct ib_recv_wr *bad_wr;
  97. return ib_post_recv(priv->qp, &param, &bad_wr);
  98. }
  99. static int ipoib_ib_post_receive(struct net_device *dev, int id)
  100. {
  101. struct ipoib_dev_priv *priv = netdev_priv(dev);
  102. struct sk_buff *skb;
  103. dma_addr_t addr;
  104. int ret;
  105. skb = dev_alloc_skb(IPOIB_BUF_SIZE + 4);
  106. if (!skb) {
  107. ipoib_warn(priv, "failed to allocate receive buffer\n");
  108. priv->rx_ring[id].skb = NULL;
  109. return -ENOMEM;
  110. }
  111. skb_reserve(skb, 4); /* 16 byte align IP header */
  112. priv->rx_ring[id].skb = skb;
  113. addr = dma_map_single(priv->ca->dma_device,
  114. skb->data, IPOIB_BUF_SIZE,
  115. DMA_FROM_DEVICE);
  116. pci_unmap_addr_set(&priv->rx_ring[id], mapping, addr);
  117. ret = ipoib_ib_receive(priv, id, addr);
  118. if (ret) {
  119. ipoib_warn(priv, "ipoib_ib_receive failed for buf %d (%d)\n",
  120. id, ret);
  121. dma_unmap_single(priv->ca->dma_device, addr,
  122. IPOIB_BUF_SIZE, DMA_FROM_DEVICE);
  123. dev_kfree_skb_any(skb);
  124. priv->rx_ring[id].skb = NULL;
  125. }
  126. return ret;
  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_RX_RING_SIZE; ++i) {
  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_wc(struct net_device *dev,
  141. struct ib_wc *wc)
  142. {
  143. struct ipoib_dev_priv *priv = netdev_priv(dev);
  144. unsigned int wr_id = wc->wr_id;
  145. ipoib_dbg_data(priv, "called: id %d, op %d, status: %d\n",
  146. wr_id, wc->opcode, wc->status);
  147. if (wr_id & IPOIB_OP_RECV) {
  148. wr_id &= ~IPOIB_OP_RECV;
  149. if (wr_id < IPOIB_RX_RING_SIZE) {
  150. struct sk_buff *skb = priv->rx_ring[wr_id].skb;
  151. priv->rx_ring[wr_id].skb = NULL;
  152. dma_unmap_single(priv->ca->dma_device,
  153. pci_unmap_addr(&priv->rx_ring[wr_id],
  154. mapping),
  155. IPOIB_BUF_SIZE,
  156. DMA_FROM_DEVICE);
  157. if (wc->status != IB_WC_SUCCESS) {
  158. if (wc->status != IB_WC_WR_FLUSH_ERR)
  159. ipoib_warn(priv, "failed recv event "
  160. "(status=%d, wrid=%d vend_err %x)\n",
  161. wc->status, wr_id, wc->vendor_err);
  162. dev_kfree_skb_any(skb);
  163. return;
  164. }
  165. ipoib_dbg_data(priv, "received %d bytes, SLID 0x%04x\n",
  166. wc->byte_len, wc->slid);
  167. skb_put(skb, wc->byte_len);
  168. skb_pull(skb, IB_GRH_BYTES);
  169. if (wc->slid != priv->local_lid ||
  170. wc->src_qp != priv->qp->qp_num) {
  171. skb->protocol = ((struct ipoib_header *) skb->data)->proto;
  172. skb->mac.raw = skb->data;
  173. skb_pull(skb, IPOIB_ENCAP_LEN);
  174. dev->last_rx = jiffies;
  175. ++priv->stats.rx_packets;
  176. priv->stats.rx_bytes += skb->len;
  177. skb->dev = dev;
  178. /* XXX get correct PACKET_ type here */
  179. skb->pkt_type = PACKET_HOST;
  180. netif_rx_ni(skb);
  181. } else {
  182. ipoib_dbg_data(priv, "dropping loopback packet\n");
  183. dev_kfree_skb_any(skb);
  184. }
  185. /* repost receive */
  186. if (ipoib_ib_post_receive(dev, wr_id))
  187. ipoib_warn(priv, "ipoib_ib_post_receive failed "
  188. "for buf %d\n", wr_id);
  189. } else
  190. ipoib_warn(priv, "completion event with wrid %d\n",
  191. wr_id);
  192. } else {
  193. struct ipoib_buf *tx_req;
  194. unsigned long flags;
  195. if (wr_id >= IPOIB_TX_RING_SIZE) {
  196. ipoib_warn(priv, "completion event with wrid %d (> %d)\n",
  197. wr_id, IPOIB_TX_RING_SIZE);
  198. return;
  199. }
  200. ipoib_dbg_data(priv, "send complete, wrid %d\n", wr_id);
  201. tx_req = &priv->tx_ring[wr_id];
  202. dma_unmap_single(priv->ca->dma_device,
  203. pci_unmap_addr(tx_req, mapping),
  204. tx_req->skb->len,
  205. DMA_TO_DEVICE);
  206. ++priv->stats.tx_packets;
  207. priv->stats.tx_bytes += tx_req->skb->len;
  208. dev_kfree_skb_any(tx_req->skb);
  209. spin_lock_irqsave(&priv->tx_lock, flags);
  210. ++priv->tx_tail;
  211. if (netif_queue_stopped(dev) &&
  212. priv->tx_head - priv->tx_tail <= IPOIB_TX_RING_SIZE / 2)
  213. netif_wake_queue(dev);
  214. spin_unlock_irqrestore(&priv->tx_lock, flags);
  215. if (wc->status != IB_WC_SUCCESS &&
  216. wc->status != IB_WC_WR_FLUSH_ERR)
  217. ipoib_warn(priv, "failed send event "
  218. "(status=%d, wrid=%d vend_err %x)\n",
  219. wc->status, wr_id, wc->vendor_err);
  220. }
  221. }
  222. void ipoib_ib_completion(struct ib_cq *cq, void *dev_ptr)
  223. {
  224. struct net_device *dev = (struct net_device *) dev_ptr;
  225. struct ipoib_dev_priv *priv = netdev_priv(dev);
  226. int n, i;
  227. ib_req_notify_cq(cq, IB_CQ_NEXT_COMP);
  228. do {
  229. n = ib_poll_cq(cq, IPOIB_NUM_WC, priv->ibwc);
  230. for (i = 0; i < n; ++i)
  231. ipoib_ib_handle_wc(dev, priv->ibwc + i);
  232. } while (n == IPOIB_NUM_WC);
  233. }
  234. static inline int post_send(struct ipoib_dev_priv *priv,
  235. unsigned int wr_id,
  236. struct ib_ah *address, u32 qpn,
  237. dma_addr_t addr, int len)
  238. {
  239. struct ib_send_wr *bad_wr;
  240. priv->tx_sge.addr = addr;
  241. priv->tx_sge.length = len;
  242. priv->tx_wr.wr_id = wr_id;
  243. priv->tx_wr.wr.ud.remote_qpn = qpn;
  244. priv->tx_wr.wr.ud.ah = address;
  245. return ib_post_send(priv->qp, &priv->tx_wr, &bad_wr);
  246. }
  247. void ipoib_send(struct net_device *dev, struct sk_buff *skb,
  248. struct ipoib_ah *address, u32 qpn)
  249. {
  250. struct ipoib_dev_priv *priv = netdev_priv(dev);
  251. struct ipoib_buf *tx_req;
  252. dma_addr_t addr;
  253. if (skb->len > dev->mtu + INFINIBAND_ALEN) {
  254. ipoib_warn(priv, "packet len %d (> %d) too long to send, dropping\n",
  255. skb->len, dev->mtu + INFINIBAND_ALEN);
  256. ++priv->stats.tx_dropped;
  257. ++priv->stats.tx_errors;
  258. dev_kfree_skb_any(skb);
  259. return;
  260. }
  261. ipoib_dbg_data(priv, "sending packet, length=%d address=%p qpn=0x%06x\n",
  262. skb->len, address, qpn);
  263. /*
  264. * We put the skb into the tx_ring _before_ we call post_send()
  265. * because it's entirely possible that the completion handler will
  266. * run before we execute anything after the post_send(). That
  267. * means we have to make sure everything is properly recorded and
  268. * our state is consistent before we call post_send().
  269. */
  270. tx_req = &priv->tx_ring[priv->tx_head & (IPOIB_TX_RING_SIZE - 1)];
  271. tx_req->skb = skb;
  272. addr = dma_map_single(priv->ca->dma_device, skb->data, skb->len,
  273. DMA_TO_DEVICE);
  274. pci_unmap_addr_set(tx_req, mapping, addr);
  275. if (unlikely(post_send(priv, priv->tx_head & (IPOIB_TX_RING_SIZE - 1),
  276. address->ah, qpn, addr, skb->len))) {
  277. ipoib_warn(priv, "post_send failed\n");
  278. ++priv->stats.tx_errors;
  279. dma_unmap_single(priv->ca->dma_device, addr, skb->len,
  280. DMA_TO_DEVICE);
  281. dev_kfree_skb_any(skb);
  282. } else {
  283. dev->trans_start = jiffies;
  284. address->last_send = priv->tx_head;
  285. ++priv->tx_head;
  286. if (priv->tx_head - priv->tx_tail == IPOIB_TX_RING_SIZE) {
  287. ipoib_dbg(priv, "TX ring full, stopping kernel net queue\n");
  288. netif_stop_queue(dev);
  289. }
  290. }
  291. }
  292. static void __ipoib_reap_ah(struct net_device *dev)
  293. {
  294. struct ipoib_dev_priv *priv = netdev_priv(dev);
  295. struct ipoib_ah *ah, *tah;
  296. LIST_HEAD(remove_list);
  297. spin_lock_irq(&priv->lock);
  298. list_for_each_entry_safe(ah, tah, &priv->dead_ahs, list)
  299. if ((int) priv->tx_tail - (int) ah->last_send >= 0) {
  300. list_del(&ah->list);
  301. list_add_tail(&ah->list, &remove_list);
  302. }
  303. spin_unlock_irq(&priv->lock);
  304. list_for_each_entry_safe(ah, tah, &remove_list, list) {
  305. ipoib_dbg(priv, "Reaping ah %p\n", ah->ah);
  306. ib_destroy_ah(ah->ah);
  307. kfree(ah);
  308. }
  309. }
  310. void ipoib_reap_ah(void *dev_ptr)
  311. {
  312. struct net_device *dev = dev_ptr;
  313. struct ipoib_dev_priv *priv = netdev_priv(dev);
  314. __ipoib_reap_ah(dev);
  315. if (!test_bit(IPOIB_STOP_REAPER, &priv->flags))
  316. queue_delayed_work(ipoib_workqueue, &priv->ah_reap_task, HZ);
  317. }
  318. int ipoib_ib_dev_open(struct net_device *dev)
  319. {
  320. struct ipoib_dev_priv *priv = netdev_priv(dev);
  321. int ret;
  322. ret = ipoib_qp_create(dev);
  323. if (ret) {
  324. ipoib_warn(priv, "ipoib_qp_create returned %d\n", ret);
  325. return -1;
  326. }
  327. ret = ipoib_ib_post_receives(dev);
  328. if (ret) {
  329. ipoib_warn(priv, "ipoib_ib_post_receives returned %d\n", ret);
  330. return -1;
  331. }
  332. clear_bit(IPOIB_STOP_REAPER, &priv->flags);
  333. queue_delayed_work(ipoib_workqueue, &priv->ah_reap_task, HZ);
  334. return 0;
  335. }
  336. int ipoib_ib_dev_up(struct net_device *dev)
  337. {
  338. struct ipoib_dev_priv *priv = netdev_priv(dev);
  339. set_bit(IPOIB_FLAG_OPER_UP, &priv->flags);
  340. return ipoib_mcast_start_thread(dev);
  341. }
  342. int ipoib_ib_dev_down(struct net_device *dev)
  343. {
  344. struct ipoib_dev_priv *priv = netdev_priv(dev);
  345. ipoib_dbg(priv, "downing ib_dev\n");
  346. clear_bit(IPOIB_FLAG_OPER_UP, &priv->flags);
  347. netif_carrier_off(dev);
  348. /* Shutdown the P_Key thread if still active */
  349. if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) {
  350. down(&pkey_sem);
  351. set_bit(IPOIB_PKEY_STOP, &priv->flags);
  352. cancel_delayed_work(&priv->pkey_task);
  353. up(&pkey_sem);
  354. flush_workqueue(ipoib_workqueue);
  355. }
  356. ipoib_mcast_stop_thread(dev);
  357. /*
  358. * Flush the multicast groups first so we stop any multicast joins. The
  359. * completion thread may have already died and we may deadlock waiting
  360. * for the completion thread to finish some multicast joins.
  361. */
  362. ipoib_mcast_dev_flush(dev);
  363. /* Delete broadcast and local addresses since they will be recreated */
  364. ipoib_mcast_dev_down(dev);
  365. ipoib_flush_paths(dev);
  366. return 0;
  367. }
  368. static int recvs_pending(struct net_device *dev)
  369. {
  370. struct ipoib_dev_priv *priv = netdev_priv(dev);
  371. int pending = 0;
  372. int i;
  373. for (i = 0; i < IPOIB_RX_RING_SIZE; ++i)
  374. if (priv->rx_ring[i].skb)
  375. ++pending;
  376. return pending;
  377. }
  378. int ipoib_ib_dev_stop(struct net_device *dev)
  379. {
  380. struct ipoib_dev_priv *priv = netdev_priv(dev);
  381. struct ib_qp_attr qp_attr;
  382. int attr_mask;
  383. unsigned long begin;
  384. struct ipoib_buf *tx_req;
  385. int i;
  386. /* Kill the existing QP and allocate a new one */
  387. qp_attr.qp_state = IB_QPS_ERR;
  388. attr_mask = IB_QP_STATE;
  389. if (ib_modify_qp(priv->qp, &qp_attr, attr_mask))
  390. ipoib_warn(priv, "Failed to modify QP to ERROR state\n");
  391. /* Wait for all sends and receives to complete */
  392. begin = jiffies;
  393. while (priv->tx_head != priv->tx_tail || recvs_pending(dev)) {
  394. if (time_after(jiffies, begin + 5 * HZ)) {
  395. ipoib_warn(priv, "timing out; %d sends %d receives not completed\n",
  396. priv->tx_head - priv->tx_tail, recvs_pending(dev));
  397. /*
  398. * assume the HW is wedged and just free up
  399. * all our pending work requests.
  400. */
  401. while ((int) priv->tx_tail - (int) priv->tx_head < 0) {
  402. tx_req = &priv->tx_ring[priv->tx_tail &
  403. (IPOIB_TX_RING_SIZE - 1)];
  404. dma_unmap_single(priv->ca->dma_device,
  405. pci_unmap_addr(tx_req, mapping),
  406. tx_req->skb->len,
  407. DMA_TO_DEVICE);
  408. dev_kfree_skb_any(tx_req->skb);
  409. ++priv->tx_tail;
  410. }
  411. for (i = 0; i < IPOIB_RX_RING_SIZE; ++i)
  412. if (priv->rx_ring[i].skb) {
  413. dma_unmap_single(priv->ca->dma_device,
  414. pci_unmap_addr(&priv->rx_ring[i],
  415. mapping),
  416. IPOIB_BUF_SIZE,
  417. DMA_FROM_DEVICE);
  418. dev_kfree_skb_any(priv->rx_ring[i].skb);
  419. priv->rx_ring[i].skb = NULL;
  420. }
  421. goto timeout;
  422. }
  423. msleep(1);
  424. }
  425. ipoib_dbg(priv, "All sends and receives done.\n");
  426. timeout:
  427. qp_attr.qp_state = IB_QPS_RESET;
  428. attr_mask = IB_QP_STATE;
  429. if (ib_modify_qp(priv->qp, &qp_attr, attr_mask))
  430. ipoib_warn(priv, "Failed to modify QP to RESET state\n");
  431. /* Wait for all AHs to be reaped */
  432. set_bit(IPOIB_STOP_REAPER, &priv->flags);
  433. cancel_delayed_work(&priv->ah_reap_task);
  434. flush_workqueue(ipoib_workqueue);
  435. begin = jiffies;
  436. while (!list_empty(&priv->dead_ahs)) {
  437. __ipoib_reap_ah(dev);
  438. if (time_after(jiffies, begin + HZ)) {
  439. ipoib_warn(priv, "timing out; will leak address handles\n");
  440. break;
  441. }
  442. msleep(1);
  443. }
  444. return 0;
  445. }
  446. int ipoib_ib_dev_init(struct net_device *dev, struct ib_device *ca, int port)
  447. {
  448. struct ipoib_dev_priv *priv = netdev_priv(dev);
  449. priv->ca = ca;
  450. priv->port = port;
  451. priv->qp = NULL;
  452. if (ipoib_transport_dev_init(dev, ca)) {
  453. printk(KERN_WARNING "%s: ipoib_transport_dev_init failed\n", ca->name);
  454. return -ENODEV;
  455. }
  456. if (dev->flags & IFF_UP) {
  457. if (ipoib_ib_dev_open(dev)) {
  458. ipoib_transport_dev_cleanup(dev);
  459. return -ENODEV;
  460. }
  461. }
  462. return 0;
  463. }
  464. void ipoib_ib_dev_flush(void *_dev)
  465. {
  466. struct net_device *dev = (struct net_device *)_dev;
  467. struct ipoib_dev_priv *priv = netdev_priv(dev), *cpriv;
  468. if (!test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags))
  469. return;
  470. ipoib_dbg(priv, "flushing\n");
  471. ipoib_ib_dev_down(dev);
  472. /*
  473. * The device could have been brought down between the start and when
  474. * we get here, don't bring it back up if it's not configured up
  475. */
  476. if (test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags))
  477. ipoib_ib_dev_up(dev);
  478. /* Flush any child interfaces too */
  479. list_for_each_entry(cpriv, &priv->child_intfs, list)
  480. ipoib_ib_dev_flush(&cpriv->dev);
  481. }
  482. void ipoib_ib_dev_cleanup(struct net_device *dev)
  483. {
  484. struct ipoib_dev_priv *priv = netdev_priv(dev);
  485. ipoib_dbg(priv, "cleaning up ib_dev\n");
  486. ipoib_mcast_stop_thread(dev);
  487. /* Delete the broadcast address and the local address */
  488. ipoib_mcast_dev_down(dev);
  489. ipoib_transport_dev_cleanup(dev);
  490. }
  491. /*
  492. * Delayed P_Key Assigment Interim Support
  493. *
  494. * The following is initial implementation of delayed P_Key assigment
  495. * mechanism. It is using the same approach implemented for the multicast
  496. * group join. The single goal of this implementation is to quickly address
  497. * Bug #2507. This implementation will probably be removed when the P_Key
  498. * change async notification is available.
  499. */
  500. int ipoib_open(struct net_device *dev);
  501. static void ipoib_pkey_dev_check_presence(struct net_device *dev)
  502. {
  503. struct ipoib_dev_priv *priv = netdev_priv(dev);
  504. u16 pkey_index = 0;
  505. if (ib_find_cached_pkey(priv->ca, priv->port, priv->pkey, &pkey_index))
  506. clear_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
  507. else
  508. set_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
  509. }
  510. void ipoib_pkey_poll(void *dev_ptr)
  511. {
  512. struct net_device *dev = dev_ptr;
  513. struct ipoib_dev_priv *priv = netdev_priv(dev);
  514. ipoib_pkey_dev_check_presence(dev);
  515. if (test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags))
  516. ipoib_open(dev);
  517. else {
  518. down(&pkey_sem);
  519. if (!test_bit(IPOIB_PKEY_STOP, &priv->flags))
  520. queue_delayed_work(ipoib_workqueue,
  521. &priv->pkey_task,
  522. HZ);
  523. up(&pkey_sem);
  524. }
  525. }
  526. int ipoib_pkey_dev_delay_open(struct net_device *dev)
  527. {
  528. struct ipoib_dev_priv *priv = netdev_priv(dev);
  529. /* Look for the interface pkey value in the IB Port P_Key table and */
  530. /* set the interface pkey assigment flag */
  531. ipoib_pkey_dev_check_presence(dev);
  532. /* P_Key value not assigned yet - start polling */
  533. if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) {
  534. down(&pkey_sem);
  535. clear_bit(IPOIB_PKEY_STOP, &priv->flags);
  536. queue_delayed_work(ipoib_workqueue,
  537. &priv->pkey_task,
  538. HZ);
  539. up(&pkey_sem);
  540. return 1;
  541. }
  542. return 0;
  543. }