ipoib_ib.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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. 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 int ipoib_ib_post_receive(struct net_device *dev, int id)
  83. {
  84. struct ipoib_dev_priv *priv = netdev_priv(dev);
  85. struct ib_sge list;
  86. struct ib_recv_wr param;
  87. struct ib_recv_wr *bad_wr;
  88. int ret;
  89. list.addr = priv->rx_ring[id].mapping;
  90. list.length = IPOIB_BUF_SIZE;
  91. list.lkey = priv->mr->lkey;
  92. param.next = NULL;
  93. param.wr_id = id | IPOIB_OP_RECV;
  94. param.sg_list = &list;
  95. param.num_sge = 1;
  96. ret = ib_post_recv(priv->qp, &param, &bad_wr);
  97. if (unlikely(ret)) {
  98. ipoib_warn(priv, "receive failed for buf %d (%d)\n", id, ret);
  99. dma_unmap_single(priv->ca->dma_device,
  100. priv->rx_ring[id].mapping,
  101. IPOIB_BUF_SIZE, DMA_FROM_DEVICE);
  102. dev_kfree_skb_any(priv->rx_ring[id].skb);
  103. priv->rx_ring[id].skb = NULL;
  104. }
  105. return ret;
  106. }
  107. static int ipoib_alloc_rx_skb(struct net_device *dev, int id)
  108. {
  109. struct ipoib_dev_priv *priv = netdev_priv(dev);
  110. struct sk_buff *skb;
  111. dma_addr_t addr;
  112. skb = dev_alloc_skb(IPOIB_BUF_SIZE + 4);
  113. if (!skb)
  114. return -ENOMEM;
  115. /*
  116. * IB will leave a 40 byte gap for a GRH and IPoIB adds a 4 byte
  117. * header. So we need 4 more bytes to get to 48 and align the
  118. * IP header to a multiple of 16.
  119. */
  120. skb_reserve(skb, 4);
  121. addr = dma_map_single(priv->ca->dma_device,
  122. skb->data, IPOIB_BUF_SIZE,
  123. DMA_FROM_DEVICE);
  124. if (unlikely(dma_mapping_error(addr))) {
  125. dev_kfree_skb_any(skb);
  126. return -EIO;
  127. }
  128. priv->rx_ring[id].skb = skb;
  129. priv->rx_ring[id].mapping = addr;
  130. return 0;
  131. }
  132. static int ipoib_ib_post_receives(struct net_device *dev)
  133. {
  134. struct ipoib_dev_priv *priv = netdev_priv(dev);
  135. int i;
  136. for (i = 0; i < ipoib_recvq_size; ++i) {
  137. if (ipoib_alloc_rx_skb(dev, i)) {
  138. ipoib_warn(priv, "failed to allocate receive buffer %d\n", i);
  139. return -ENOMEM;
  140. }
  141. if (ipoib_ib_post_receive(dev, i)) {
  142. ipoib_warn(priv, "ipoib_ib_post_receive failed for buf %d\n", i);
  143. return -EIO;
  144. }
  145. }
  146. return 0;
  147. }
  148. static void ipoib_ib_handle_wc(struct net_device *dev,
  149. struct ib_wc *wc)
  150. {
  151. struct ipoib_dev_priv *priv = netdev_priv(dev);
  152. unsigned int wr_id = wc->wr_id;
  153. ipoib_dbg_data(priv, "called: id %d, op %d, status: %d\n",
  154. wr_id, wc->opcode, wc->status);
  155. if (wr_id & IPOIB_OP_RECV) {
  156. wr_id &= ~IPOIB_OP_RECV;
  157. if (wr_id < ipoib_recvq_size) {
  158. struct sk_buff *skb = priv->rx_ring[wr_id].skb;
  159. dma_addr_t addr = priv->rx_ring[wr_id].mapping;
  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. dma_unmap_single(priv->ca->dma_device, addr,
  166. IPOIB_BUF_SIZE, DMA_FROM_DEVICE);
  167. dev_kfree_skb_any(skb);
  168. priv->rx_ring[wr_id].skb = NULL;
  169. return;
  170. }
  171. /*
  172. * If we can't allocate a new RX buffer, dump
  173. * this packet and reuse the old buffer.
  174. */
  175. if (unlikely(ipoib_alloc_rx_skb(dev, wr_id))) {
  176. ++priv->stats.rx_dropped;
  177. goto repost;
  178. }
  179. ipoib_dbg_data(priv, "received %d bytes, SLID 0x%04x\n",
  180. wc->byte_len, wc->slid);
  181. dma_unmap_single(priv->ca->dma_device, addr,
  182. IPOIB_BUF_SIZE, DMA_FROM_DEVICE);
  183. skb_put(skb, wc->byte_len);
  184. skb_pull(skb, IB_GRH_BYTES);
  185. if (wc->slid != priv->local_lid ||
  186. wc->src_qp != priv->qp->qp_num) {
  187. skb->protocol = ((struct ipoib_header *) skb->data)->proto;
  188. skb->mac.raw = skb->data;
  189. skb_pull(skb, IPOIB_ENCAP_LEN);
  190. dev->last_rx = jiffies;
  191. ++priv->stats.rx_packets;
  192. priv->stats.rx_bytes += skb->len;
  193. skb->dev = dev;
  194. /* XXX get correct PACKET_ type here */
  195. skb->pkt_type = PACKET_HOST;
  196. netif_rx_ni(skb);
  197. } else {
  198. ipoib_dbg_data(priv, "dropping loopback packet\n");
  199. dev_kfree_skb_any(skb);
  200. }
  201. repost:
  202. if (unlikely(ipoib_ib_post_receive(dev, wr_id)))
  203. ipoib_warn(priv, "ipoib_ib_post_receive failed "
  204. "for buf %d\n", wr_id);
  205. } else
  206. ipoib_warn(priv, "completion event with wrid %d\n",
  207. wr_id);
  208. } else {
  209. struct ipoib_tx_buf *tx_req;
  210. unsigned long flags;
  211. if (wr_id >= ipoib_sendq_size) {
  212. ipoib_warn(priv, "completion event with wrid %d (> %d)\n",
  213. wr_id, ipoib_sendq_size);
  214. return;
  215. }
  216. ipoib_dbg_data(priv, "send complete, wrid %d\n", wr_id);
  217. tx_req = &priv->tx_ring[wr_id];
  218. dma_unmap_single(priv->ca->dma_device,
  219. pci_unmap_addr(tx_req, mapping),
  220. tx_req->skb->len,
  221. DMA_TO_DEVICE);
  222. ++priv->stats.tx_packets;
  223. priv->stats.tx_bytes += tx_req->skb->len;
  224. dev_kfree_skb_any(tx_req->skb);
  225. spin_lock_irqsave(&priv->tx_lock, flags);
  226. ++priv->tx_tail;
  227. if (netif_queue_stopped(dev) &&
  228. test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags) &&
  229. priv->tx_head - priv->tx_tail <= ipoib_sendq_size >> 1)
  230. netif_wake_queue(dev);
  231. spin_unlock_irqrestore(&priv->tx_lock, flags);
  232. if (wc->status != IB_WC_SUCCESS &&
  233. wc->status != IB_WC_WR_FLUSH_ERR)
  234. ipoib_warn(priv, "failed send event "
  235. "(status=%d, wrid=%d vend_err %x)\n",
  236. wc->status, wr_id, wc->vendor_err);
  237. }
  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. dma_addr_t 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. dma_addr_t addr;
  270. if (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 = dma_map_single(priv->ca->dma_device, skb->data, skb->len,
  290. DMA_TO_DEVICE);
  291. pci_unmap_addr_set(tx_req, mapping, addr);
  292. if (unlikely(post_send(priv, priv->tx_head & (ipoib_sendq_size - 1),
  293. address->ah, qpn, addr, skb->len))) {
  294. ipoib_warn(priv, "post_send failed\n");
  295. ++priv->stats.tx_errors;
  296. dma_unmap_single(priv->ca->dma_device, addr, skb->len,
  297. DMA_TO_DEVICE);
  298. dev_kfree_skb_any(skb);
  299. } else {
  300. dev->trans_start = jiffies;
  301. address->last_send = priv->tx_head;
  302. ++priv->tx_head;
  303. if (priv->tx_head - priv->tx_tail == ipoib_sendq_size) {
  304. ipoib_dbg(priv, "TX ring full, stopping kernel net queue\n");
  305. netif_stop_queue(dev);
  306. }
  307. }
  308. }
  309. static void __ipoib_reap_ah(struct net_device *dev)
  310. {
  311. struct ipoib_dev_priv *priv = netdev_priv(dev);
  312. struct ipoib_ah *ah, *tah;
  313. LIST_HEAD(remove_list);
  314. spin_lock_irq(&priv->lock);
  315. list_for_each_entry_safe(ah, tah, &priv->dead_ahs, list)
  316. if ((int) priv->tx_tail - (int) ah->last_send >= 0) {
  317. list_del(&ah->list);
  318. list_add_tail(&ah->list, &remove_list);
  319. }
  320. spin_unlock_irq(&priv->lock);
  321. list_for_each_entry_safe(ah, tah, &remove_list, list) {
  322. ipoib_dbg(priv, "Reaping ah %p\n", ah->ah);
  323. ib_destroy_ah(ah->ah);
  324. kfree(ah);
  325. }
  326. }
  327. void ipoib_reap_ah(void *dev_ptr)
  328. {
  329. struct net_device *dev = dev_ptr;
  330. struct ipoib_dev_priv *priv = netdev_priv(dev);
  331. __ipoib_reap_ah(dev);
  332. if (!test_bit(IPOIB_STOP_REAPER, &priv->flags))
  333. queue_delayed_work(ipoib_workqueue, &priv->ah_reap_task, HZ);
  334. }
  335. int ipoib_ib_dev_open(struct net_device *dev)
  336. {
  337. struct ipoib_dev_priv *priv = netdev_priv(dev);
  338. int ret;
  339. ret = ipoib_init_qp(dev);
  340. if (ret) {
  341. ipoib_warn(priv, "ipoib_init_qp returned %d\n", ret);
  342. return -1;
  343. }
  344. ret = ipoib_ib_post_receives(dev);
  345. if (ret) {
  346. ipoib_warn(priv, "ipoib_ib_post_receives returned %d\n", ret);
  347. ipoib_ib_dev_stop(dev);
  348. return -1;
  349. }
  350. clear_bit(IPOIB_STOP_REAPER, &priv->flags);
  351. queue_delayed_work(ipoib_workqueue, &priv->ah_reap_task, HZ);
  352. set_bit(IPOIB_FLAG_INITIALIZED, &priv->flags);
  353. return 0;
  354. }
  355. static void ipoib_pkey_dev_check_presence(struct net_device *dev)
  356. {
  357. struct ipoib_dev_priv *priv = netdev_priv(dev);
  358. u16 pkey_index = 0;
  359. if (ib_find_cached_pkey(priv->ca, priv->port, priv->pkey, &pkey_index))
  360. clear_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
  361. else
  362. set_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
  363. }
  364. int ipoib_ib_dev_up(struct net_device *dev)
  365. {
  366. struct ipoib_dev_priv *priv = netdev_priv(dev);
  367. ipoib_pkey_dev_check_presence(dev);
  368. if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) {
  369. ipoib_dbg(priv, "PKEY is not assigned.\n");
  370. return 0;
  371. }
  372. set_bit(IPOIB_FLAG_OPER_UP, &priv->flags);
  373. return ipoib_mcast_start_thread(dev);
  374. }
  375. int ipoib_ib_dev_down(struct net_device *dev, int flush)
  376. {
  377. struct ipoib_dev_priv *priv = netdev_priv(dev);
  378. ipoib_dbg(priv, "downing ib_dev\n");
  379. clear_bit(IPOIB_FLAG_OPER_UP, &priv->flags);
  380. netif_carrier_off(dev);
  381. /* Shutdown the P_Key thread if still active */
  382. if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) {
  383. mutex_lock(&pkey_mutex);
  384. set_bit(IPOIB_PKEY_STOP, &priv->flags);
  385. cancel_delayed_work(&priv->pkey_task);
  386. mutex_unlock(&pkey_mutex);
  387. if (flush)
  388. flush_workqueue(ipoib_workqueue);
  389. }
  390. ipoib_mcast_stop_thread(dev, flush);
  391. ipoib_mcast_dev_flush(dev);
  392. ipoib_flush_paths(dev);
  393. return 0;
  394. }
  395. static int recvs_pending(struct net_device *dev)
  396. {
  397. struct ipoib_dev_priv *priv = netdev_priv(dev);
  398. int pending = 0;
  399. int i;
  400. for (i = 0; i < ipoib_recvq_size; ++i)
  401. if (priv->rx_ring[i].skb)
  402. ++pending;
  403. return pending;
  404. }
  405. int ipoib_ib_dev_stop(struct net_device *dev)
  406. {
  407. struct ipoib_dev_priv *priv = netdev_priv(dev);
  408. struct ib_qp_attr qp_attr;
  409. unsigned long begin;
  410. struct ipoib_tx_buf *tx_req;
  411. int i;
  412. clear_bit(IPOIB_FLAG_INITIALIZED, &priv->flags);
  413. /*
  414. * Move our QP to the error state and then reinitialize in
  415. * when all work requests have completed or have been flushed.
  416. */
  417. qp_attr.qp_state = IB_QPS_ERR;
  418. if (ib_modify_qp(priv->qp, &qp_attr, IB_QP_STATE))
  419. ipoib_warn(priv, "Failed to modify QP to ERROR state\n");
  420. /* Wait for all sends and receives to complete */
  421. begin = jiffies;
  422. while (priv->tx_head != priv->tx_tail || recvs_pending(dev)) {
  423. if (time_after(jiffies, begin + 5 * HZ)) {
  424. ipoib_warn(priv, "timing out; %d sends %d receives not completed\n",
  425. priv->tx_head - priv->tx_tail, recvs_pending(dev));
  426. /*
  427. * assume the HW is wedged and just free up
  428. * all our pending work requests.
  429. */
  430. while ((int) priv->tx_tail - (int) priv->tx_head < 0) {
  431. tx_req = &priv->tx_ring[priv->tx_tail &
  432. (ipoib_sendq_size - 1)];
  433. dma_unmap_single(priv->ca->dma_device,
  434. pci_unmap_addr(tx_req, mapping),
  435. tx_req->skb->len,
  436. DMA_TO_DEVICE);
  437. dev_kfree_skb_any(tx_req->skb);
  438. ++priv->tx_tail;
  439. }
  440. for (i = 0; i < ipoib_recvq_size; ++i)
  441. if (priv->rx_ring[i].skb) {
  442. dma_unmap_single(priv->ca->dma_device,
  443. pci_unmap_addr(&priv->rx_ring[i],
  444. mapping),
  445. IPOIB_BUF_SIZE,
  446. DMA_FROM_DEVICE);
  447. dev_kfree_skb_any(priv->rx_ring[i].skb);
  448. priv->rx_ring[i].skb = NULL;
  449. }
  450. goto timeout;
  451. }
  452. msleep(1);
  453. }
  454. ipoib_dbg(priv, "All sends and receives done.\n");
  455. timeout:
  456. qp_attr.qp_state = IB_QPS_RESET;
  457. if (ib_modify_qp(priv->qp, &qp_attr, IB_QP_STATE))
  458. ipoib_warn(priv, "Failed to modify QP to RESET state\n");
  459. /* Wait for all AHs to be reaped */
  460. set_bit(IPOIB_STOP_REAPER, &priv->flags);
  461. cancel_delayed_work(&priv->ah_reap_task);
  462. flush_workqueue(ipoib_workqueue);
  463. begin = jiffies;
  464. while (!list_empty(&priv->dead_ahs)) {
  465. __ipoib_reap_ah(dev);
  466. if (time_after(jiffies, begin + HZ)) {
  467. ipoib_warn(priv, "timing out; will leak address handles\n");
  468. break;
  469. }
  470. msleep(1);
  471. }
  472. return 0;
  473. }
  474. int ipoib_ib_dev_init(struct net_device *dev, struct ib_device *ca, int port)
  475. {
  476. struct ipoib_dev_priv *priv = netdev_priv(dev);
  477. priv->ca = ca;
  478. priv->port = port;
  479. priv->qp = NULL;
  480. if (ipoib_transport_dev_init(dev, ca)) {
  481. printk(KERN_WARNING "%s: ipoib_transport_dev_init failed\n", ca->name);
  482. return -ENODEV;
  483. }
  484. if (dev->flags & IFF_UP) {
  485. if (ipoib_ib_dev_open(dev)) {
  486. ipoib_transport_dev_cleanup(dev);
  487. return -ENODEV;
  488. }
  489. }
  490. return 0;
  491. }
  492. void ipoib_ib_dev_flush(void *_dev)
  493. {
  494. struct net_device *dev = (struct net_device *)_dev;
  495. struct ipoib_dev_priv *priv = netdev_priv(dev), *cpriv;
  496. if (!test_bit(IPOIB_FLAG_INITIALIZED, &priv->flags) ) {
  497. ipoib_dbg(priv, "Not flushing - IPOIB_FLAG_INITIALIZED not set.\n");
  498. return;
  499. }
  500. if (!test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags)) {
  501. ipoib_dbg(priv, "Not flushing - IPOIB_FLAG_ADMIN_UP not set.\n");
  502. return;
  503. }
  504. ipoib_dbg(priv, "flushing\n");
  505. ipoib_ib_dev_down(dev, 0);
  506. /*
  507. * The device could have been brought down between the start and when
  508. * we get here, don't bring it back up if it's not configured up
  509. */
  510. if (test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags))
  511. ipoib_ib_dev_up(dev);
  512. mutex_lock(&priv->vlan_mutex);
  513. /* Flush any child interfaces too */
  514. list_for_each_entry(cpriv, &priv->child_intfs, list)
  515. ipoib_ib_dev_flush(cpriv->dev);
  516. mutex_unlock(&priv->vlan_mutex);
  517. }
  518. void ipoib_ib_dev_cleanup(struct net_device *dev)
  519. {
  520. struct ipoib_dev_priv *priv = netdev_priv(dev);
  521. ipoib_dbg(priv, "cleaning up ib_dev\n");
  522. ipoib_mcast_stop_thread(dev, 1);
  523. ipoib_mcast_dev_flush(dev);
  524. ipoib_transport_dev_cleanup(dev);
  525. }
  526. /*
  527. * Delayed P_Key Assigment Interim Support
  528. *
  529. * The following is initial implementation of delayed P_Key assigment
  530. * mechanism. It is using the same approach implemented for the multicast
  531. * group join. The single goal of this implementation is to quickly address
  532. * Bug #2507. This implementation will probably be removed when the P_Key
  533. * change async notification is available.
  534. */
  535. void ipoib_pkey_poll(void *dev_ptr)
  536. {
  537. struct net_device *dev = dev_ptr;
  538. struct ipoib_dev_priv *priv = netdev_priv(dev);
  539. ipoib_pkey_dev_check_presence(dev);
  540. if (test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags))
  541. ipoib_open(dev);
  542. else {
  543. mutex_lock(&pkey_mutex);
  544. if (!test_bit(IPOIB_PKEY_STOP, &priv->flags))
  545. queue_delayed_work(ipoib_workqueue,
  546. &priv->pkey_task,
  547. HZ);
  548. mutex_unlock(&pkey_mutex);
  549. }
  550. }
  551. int ipoib_pkey_dev_delay_open(struct net_device *dev)
  552. {
  553. struct ipoib_dev_priv *priv = netdev_priv(dev);
  554. /* Look for the interface pkey value in the IB Port P_Key table and */
  555. /* set the interface pkey assigment flag */
  556. ipoib_pkey_dev_check_presence(dev);
  557. /* P_Key value not assigned yet - start polling */
  558. if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) {
  559. mutex_lock(&pkey_mutex);
  560. clear_bit(IPOIB_PKEY_STOP, &priv->flags);
  561. queue_delayed_work(ipoib_workqueue,
  562. &priv->pkey_task,
  563. HZ);
  564. mutex_unlock(&pkey_mutex);
  565. return 1;
  566. }
  567. return 0;
  568. }