ipoib_main.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315
  1. /*
  2. * Copyright (c) 2004 Topspin Communications. All rights reserved.
  3. * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
  4. * Copyright (c) 2004 Voltaire, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. *
  34. * $Id: ipoib_main.c 1377 2004-12-23 19:57:12Z roland $
  35. */
  36. #include "ipoib.h"
  37. #include <linux/module.h>
  38. #include <linux/init.h>
  39. #include <linux/slab.h>
  40. #include <linux/kernel.h>
  41. #include <linux/vmalloc.h>
  42. #include <linux/if_arp.h> /* For ARPHRD_xxx */
  43. #include <linux/ip.h>
  44. #include <linux/in.h>
  45. #include <net/dst.h>
  46. MODULE_AUTHOR("Roland Dreier");
  47. MODULE_DESCRIPTION("IP-over-InfiniBand net driver");
  48. MODULE_LICENSE("Dual BSD/GPL");
  49. int ipoib_sendq_size __read_mostly = IPOIB_TX_RING_SIZE;
  50. int ipoib_recvq_size __read_mostly = IPOIB_RX_RING_SIZE;
  51. module_param_named(send_queue_size, ipoib_sendq_size, int, 0444);
  52. MODULE_PARM_DESC(send_queue_size, "Number of descriptors in send queue");
  53. module_param_named(recv_queue_size, ipoib_recvq_size, int, 0444);
  54. MODULE_PARM_DESC(recv_queue_size, "Number of descriptors in receive queue");
  55. #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
  56. int ipoib_debug_level;
  57. module_param_named(debug_level, ipoib_debug_level, int, 0644);
  58. MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0");
  59. #endif
  60. struct ipoib_path_iter {
  61. struct net_device *dev;
  62. struct ipoib_path path;
  63. };
  64. static const u8 ipv4_bcast_addr[] = {
  65. 0x00, 0xff, 0xff, 0xff,
  66. 0xff, 0x12, 0x40, 0x1b, 0x00, 0x00, 0x00, 0x00,
  67. 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff
  68. };
  69. struct workqueue_struct *ipoib_workqueue;
  70. struct ib_sa_client ipoib_sa_client;
  71. static void ipoib_add_one(struct ib_device *device);
  72. static void ipoib_remove_one(struct ib_device *device);
  73. static struct ib_client ipoib_client = {
  74. .name = "ipoib",
  75. .add = ipoib_add_one,
  76. .remove = ipoib_remove_one
  77. };
  78. int ipoib_open(struct net_device *dev)
  79. {
  80. struct ipoib_dev_priv *priv = netdev_priv(dev);
  81. ipoib_dbg(priv, "bringing up interface\n");
  82. napi_enable(&priv->napi);
  83. set_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags);
  84. if (ipoib_pkey_dev_delay_open(dev))
  85. return 0;
  86. if (ipoib_ib_dev_open(dev)) {
  87. napi_disable(&priv->napi);
  88. return -EINVAL;
  89. }
  90. if (ipoib_ib_dev_up(dev)) {
  91. ipoib_ib_dev_stop(dev, 1);
  92. napi_disable(&priv->napi);
  93. return -EINVAL;
  94. }
  95. if (!test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags)) {
  96. struct ipoib_dev_priv *cpriv;
  97. /* Bring up any child interfaces too */
  98. mutex_lock(&priv->vlan_mutex);
  99. list_for_each_entry(cpriv, &priv->child_intfs, list) {
  100. int flags;
  101. flags = cpriv->dev->flags;
  102. if (flags & IFF_UP)
  103. continue;
  104. dev_change_flags(cpriv->dev, flags | IFF_UP);
  105. }
  106. mutex_unlock(&priv->vlan_mutex);
  107. }
  108. netif_start_queue(dev);
  109. return 0;
  110. }
  111. static int ipoib_stop(struct net_device *dev)
  112. {
  113. struct ipoib_dev_priv *priv = netdev_priv(dev);
  114. ipoib_dbg(priv, "stopping interface\n");
  115. clear_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags);
  116. napi_disable(&priv->napi);
  117. netif_stop_queue(dev);
  118. /*
  119. * Now flush workqueue to make sure a scheduled task doesn't
  120. * bring our internal state back up.
  121. */
  122. flush_workqueue(ipoib_workqueue);
  123. ipoib_ib_dev_down(dev, 1);
  124. ipoib_ib_dev_stop(dev, 1);
  125. if (!test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags)) {
  126. struct ipoib_dev_priv *cpriv;
  127. /* Bring down any child interfaces too */
  128. mutex_lock(&priv->vlan_mutex);
  129. list_for_each_entry(cpriv, &priv->child_intfs, list) {
  130. int flags;
  131. flags = cpriv->dev->flags;
  132. if (!(flags & IFF_UP))
  133. continue;
  134. dev_change_flags(cpriv->dev, flags & ~IFF_UP);
  135. }
  136. mutex_unlock(&priv->vlan_mutex);
  137. }
  138. return 0;
  139. }
  140. static int ipoib_change_mtu(struct net_device *dev, int new_mtu)
  141. {
  142. struct ipoib_dev_priv *priv = netdev_priv(dev);
  143. /* dev->mtu > 2K ==> connected mode */
  144. if (ipoib_cm_admin_enabled(dev)) {
  145. if (new_mtu > ipoib_cm_max_mtu(dev))
  146. return -EINVAL;
  147. if (new_mtu > priv->mcast_mtu)
  148. ipoib_warn(priv, "mtu > %d will cause multicast packet drops.\n",
  149. priv->mcast_mtu);
  150. dev->mtu = new_mtu;
  151. return 0;
  152. }
  153. if (new_mtu > IPOIB_PACKET_SIZE - IPOIB_ENCAP_LEN)
  154. return -EINVAL;
  155. priv->admin_mtu = new_mtu;
  156. dev->mtu = min(priv->mcast_mtu, priv->admin_mtu);
  157. return 0;
  158. }
  159. static struct ipoib_path *__path_find(struct net_device *dev, void *gid)
  160. {
  161. struct ipoib_dev_priv *priv = netdev_priv(dev);
  162. struct rb_node *n = priv->path_tree.rb_node;
  163. struct ipoib_path *path;
  164. int ret;
  165. while (n) {
  166. path = rb_entry(n, struct ipoib_path, rb_node);
  167. ret = memcmp(gid, path->pathrec.dgid.raw,
  168. sizeof (union ib_gid));
  169. if (ret < 0)
  170. n = n->rb_left;
  171. else if (ret > 0)
  172. n = n->rb_right;
  173. else
  174. return path;
  175. }
  176. return NULL;
  177. }
  178. static int __path_add(struct net_device *dev, struct ipoib_path *path)
  179. {
  180. struct ipoib_dev_priv *priv = netdev_priv(dev);
  181. struct rb_node **n = &priv->path_tree.rb_node;
  182. struct rb_node *pn = NULL;
  183. struct ipoib_path *tpath;
  184. int ret;
  185. while (*n) {
  186. pn = *n;
  187. tpath = rb_entry(pn, struct ipoib_path, rb_node);
  188. ret = memcmp(path->pathrec.dgid.raw, tpath->pathrec.dgid.raw,
  189. sizeof (union ib_gid));
  190. if (ret < 0)
  191. n = &pn->rb_left;
  192. else if (ret > 0)
  193. n = &pn->rb_right;
  194. else
  195. return -EEXIST;
  196. }
  197. rb_link_node(&path->rb_node, pn, n);
  198. rb_insert_color(&path->rb_node, &priv->path_tree);
  199. list_add_tail(&path->list, &priv->path_list);
  200. return 0;
  201. }
  202. static void path_free(struct net_device *dev, struct ipoib_path *path)
  203. {
  204. struct ipoib_dev_priv *priv = netdev_priv(dev);
  205. struct ipoib_neigh *neigh, *tn;
  206. struct sk_buff *skb;
  207. unsigned long flags;
  208. while ((skb = __skb_dequeue(&path->queue)))
  209. dev_kfree_skb_irq(skb);
  210. spin_lock_irqsave(&priv->lock, flags);
  211. list_for_each_entry_safe(neigh, tn, &path->neigh_list, list) {
  212. /*
  213. * It's safe to call ipoib_put_ah() inside priv->lock
  214. * here, because we know that path->ah will always
  215. * hold one more reference, so ipoib_put_ah() will
  216. * never do more than decrement the ref count.
  217. */
  218. if (neigh->ah)
  219. ipoib_put_ah(neigh->ah);
  220. ipoib_neigh_free(dev, neigh);
  221. }
  222. spin_unlock_irqrestore(&priv->lock, flags);
  223. if (path->ah)
  224. ipoib_put_ah(path->ah);
  225. kfree(path);
  226. }
  227. #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
  228. struct ipoib_path_iter *ipoib_path_iter_init(struct net_device *dev)
  229. {
  230. struct ipoib_path_iter *iter;
  231. iter = kmalloc(sizeof *iter, GFP_KERNEL);
  232. if (!iter)
  233. return NULL;
  234. iter->dev = dev;
  235. memset(iter->path.pathrec.dgid.raw, 0, 16);
  236. if (ipoib_path_iter_next(iter)) {
  237. kfree(iter);
  238. return NULL;
  239. }
  240. return iter;
  241. }
  242. int ipoib_path_iter_next(struct ipoib_path_iter *iter)
  243. {
  244. struct ipoib_dev_priv *priv = netdev_priv(iter->dev);
  245. struct rb_node *n;
  246. struct ipoib_path *path;
  247. int ret = 1;
  248. spin_lock_irq(&priv->lock);
  249. n = rb_first(&priv->path_tree);
  250. while (n) {
  251. path = rb_entry(n, struct ipoib_path, rb_node);
  252. if (memcmp(iter->path.pathrec.dgid.raw, path->pathrec.dgid.raw,
  253. sizeof (union ib_gid)) < 0) {
  254. iter->path = *path;
  255. ret = 0;
  256. break;
  257. }
  258. n = rb_next(n);
  259. }
  260. spin_unlock_irq(&priv->lock);
  261. return ret;
  262. }
  263. void ipoib_path_iter_read(struct ipoib_path_iter *iter,
  264. struct ipoib_path *path)
  265. {
  266. *path = iter->path;
  267. }
  268. #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG */
  269. void ipoib_flush_paths(struct net_device *dev)
  270. {
  271. struct ipoib_dev_priv *priv = netdev_priv(dev);
  272. struct ipoib_path *path, *tp;
  273. LIST_HEAD(remove_list);
  274. spin_lock_irq(&priv->tx_lock);
  275. spin_lock(&priv->lock);
  276. list_splice(&priv->path_list, &remove_list);
  277. INIT_LIST_HEAD(&priv->path_list);
  278. list_for_each_entry(path, &remove_list, list)
  279. rb_erase(&path->rb_node, &priv->path_tree);
  280. list_for_each_entry_safe(path, tp, &remove_list, list) {
  281. if (path->query)
  282. ib_sa_cancel_query(path->query_id, path->query);
  283. spin_unlock(&priv->lock);
  284. spin_unlock_irq(&priv->tx_lock);
  285. wait_for_completion(&path->done);
  286. path_free(dev, path);
  287. spin_lock_irq(&priv->tx_lock);
  288. spin_lock(&priv->lock);
  289. }
  290. spin_unlock(&priv->lock);
  291. spin_unlock_irq(&priv->tx_lock);
  292. }
  293. static void path_rec_completion(int status,
  294. struct ib_sa_path_rec *pathrec,
  295. void *path_ptr)
  296. {
  297. struct ipoib_path *path = path_ptr;
  298. struct net_device *dev = path->dev;
  299. struct ipoib_dev_priv *priv = netdev_priv(dev);
  300. struct ipoib_ah *ah = NULL;
  301. struct ipoib_neigh *neigh, *tn;
  302. struct sk_buff_head skqueue;
  303. struct sk_buff *skb;
  304. unsigned long flags;
  305. if (!status)
  306. ipoib_dbg(priv, "PathRec LID 0x%04x for GID " IPOIB_GID_FMT "\n",
  307. be16_to_cpu(pathrec->dlid), IPOIB_GID_ARG(pathrec->dgid));
  308. else
  309. ipoib_dbg(priv, "PathRec status %d for GID " IPOIB_GID_FMT "\n",
  310. status, IPOIB_GID_ARG(path->pathrec.dgid));
  311. skb_queue_head_init(&skqueue);
  312. if (!status) {
  313. struct ib_ah_attr av;
  314. if (!ib_init_ah_from_path(priv->ca, priv->port, pathrec, &av))
  315. ah = ipoib_create_ah(dev, priv->pd, &av);
  316. }
  317. spin_lock_irqsave(&priv->lock, flags);
  318. path->ah = ah;
  319. if (ah) {
  320. path->pathrec = *pathrec;
  321. ipoib_dbg(priv, "created address handle %p for LID 0x%04x, SL %d\n",
  322. ah, be16_to_cpu(pathrec->dlid), pathrec->sl);
  323. while ((skb = __skb_dequeue(&path->queue)))
  324. __skb_queue_tail(&skqueue, skb);
  325. list_for_each_entry_safe(neigh, tn, &path->neigh_list, list) {
  326. kref_get(&path->ah->ref);
  327. neigh->ah = path->ah;
  328. memcpy(&neigh->dgid.raw, &path->pathrec.dgid.raw,
  329. sizeof(union ib_gid));
  330. if (ipoib_cm_enabled(dev, neigh->neighbour)) {
  331. if (!ipoib_cm_get(neigh))
  332. ipoib_cm_set(neigh, ipoib_cm_create_tx(dev,
  333. path,
  334. neigh));
  335. if (!ipoib_cm_get(neigh)) {
  336. list_del(&neigh->list);
  337. if (neigh->ah)
  338. ipoib_put_ah(neigh->ah);
  339. ipoib_neigh_free(dev, neigh);
  340. continue;
  341. }
  342. }
  343. while ((skb = __skb_dequeue(&neigh->queue)))
  344. __skb_queue_tail(&skqueue, skb);
  345. }
  346. }
  347. path->query = NULL;
  348. complete(&path->done);
  349. spin_unlock_irqrestore(&priv->lock, flags);
  350. while ((skb = __skb_dequeue(&skqueue))) {
  351. skb->dev = dev;
  352. if (dev_queue_xmit(skb))
  353. ipoib_warn(priv, "dev_queue_xmit failed "
  354. "to requeue packet\n");
  355. }
  356. }
  357. static struct ipoib_path *path_rec_create(struct net_device *dev, void *gid)
  358. {
  359. struct ipoib_dev_priv *priv = netdev_priv(dev);
  360. struct ipoib_path *path;
  361. if (!priv->broadcast)
  362. return NULL;
  363. path = kzalloc(sizeof *path, GFP_ATOMIC);
  364. if (!path)
  365. return NULL;
  366. path->dev = dev;
  367. skb_queue_head_init(&path->queue);
  368. INIT_LIST_HEAD(&path->neigh_list);
  369. memcpy(path->pathrec.dgid.raw, gid, sizeof (union ib_gid));
  370. path->pathrec.sgid = priv->local_gid;
  371. path->pathrec.pkey = cpu_to_be16(priv->pkey);
  372. path->pathrec.numb_path = 1;
  373. path->pathrec.traffic_class = priv->broadcast->mcmember.traffic_class;
  374. return path;
  375. }
  376. static int path_rec_start(struct net_device *dev,
  377. struct ipoib_path *path)
  378. {
  379. struct ipoib_dev_priv *priv = netdev_priv(dev);
  380. ipoib_dbg(priv, "Start path record lookup for " IPOIB_GID_FMT "\n",
  381. IPOIB_GID_ARG(path->pathrec.dgid));
  382. init_completion(&path->done);
  383. path->query_id =
  384. ib_sa_path_rec_get(&ipoib_sa_client, priv->ca, priv->port,
  385. &path->pathrec,
  386. IB_SA_PATH_REC_DGID |
  387. IB_SA_PATH_REC_SGID |
  388. IB_SA_PATH_REC_NUMB_PATH |
  389. IB_SA_PATH_REC_TRAFFIC_CLASS |
  390. IB_SA_PATH_REC_PKEY,
  391. 1000, GFP_ATOMIC,
  392. path_rec_completion,
  393. path, &path->query);
  394. if (path->query_id < 0) {
  395. ipoib_warn(priv, "ib_sa_path_rec_get failed\n");
  396. path->query = NULL;
  397. return path->query_id;
  398. }
  399. return 0;
  400. }
  401. static void neigh_add_path(struct sk_buff *skb, struct net_device *dev)
  402. {
  403. struct ipoib_dev_priv *priv = netdev_priv(dev);
  404. struct ipoib_path *path;
  405. struct ipoib_neigh *neigh;
  406. neigh = ipoib_neigh_alloc(skb->dst->neighbour, skb->dev);
  407. if (!neigh) {
  408. ++dev->stats.tx_dropped;
  409. dev_kfree_skb_any(skb);
  410. return;
  411. }
  412. /*
  413. * We can only be called from ipoib_start_xmit, so we're
  414. * inside tx_lock -- no need to save/restore flags.
  415. */
  416. spin_lock(&priv->lock);
  417. path = __path_find(dev, skb->dst->neighbour->ha + 4);
  418. if (!path) {
  419. path = path_rec_create(dev, skb->dst->neighbour->ha + 4);
  420. if (!path)
  421. goto err_path;
  422. __path_add(dev, path);
  423. }
  424. list_add_tail(&neigh->list, &path->neigh_list);
  425. if (path->ah) {
  426. kref_get(&path->ah->ref);
  427. neigh->ah = path->ah;
  428. memcpy(&neigh->dgid.raw, &path->pathrec.dgid.raw,
  429. sizeof(union ib_gid));
  430. if (ipoib_cm_enabled(dev, neigh->neighbour)) {
  431. if (!ipoib_cm_get(neigh))
  432. ipoib_cm_set(neigh, ipoib_cm_create_tx(dev, path, neigh));
  433. if (!ipoib_cm_get(neigh)) {
  434. list_del(&neigh->list);
  435. if (neigh->ah)
  436. ipoib_put_ah(neigh->ah);
  437. ipoib_neigh_free(dev, neigh);
  438. goto err_drop;
  439. }
  440. if (skb_queue_len(&neigh->queue) < IPOIB_MAX_PATH_REC_QUEUE)
  441. __skb_queue_tail(&neigh->queue, skb);
  442. else {
  443. ipoib_warn(priv, "queue length limit %d. Packet drop.\n",
  444. skb_queue_len(&neigh->queue));
  445. goto err_drop;
  446. }
  447. } else
  448. ipoib_send(dev, skb, path->ah, IPOIB_QPN(skb->dst->neighbour->ha));
  449. } else {
  450. neigh->ah = NULL;
  451. if (!path->query && path_rec_start(dev, path))
  452. goto err_list;
  453. __skb_queue_tail(&neigh->queue, skb);
  454. }
  455. spin_unlock(&priv->lock);
  456. return;
  457. err_list:
  458. list_del(&neigh->list);
  459. err_path:
  460. ipoib_neigh_free(dev, neigh);
  461. err_drop:
  462. ++dev->stats.tx_dropped;
  463. dev_kfree_skb_any(skb);
  464. spin_unlock(&priv->lock);
  465. }
  466. static void ipoib_path_lookup(struct sk_buff *skb, struct net_device *dev)
  467. {
  468. struct ipoib_dev_priv *priv = netdev_priv(skb->dev);
  469. /* Look up path record for unicasts */
  470. if (skb->dst->neighbour->ha[4] != 0xff) {
  471. neigh_add_path(skb, dev);
  472. return;
  473. }
  474. /* Add in the P_Key for multicasts */
  475. skb->dst->neighbour->ha[8] = (priv->pkey >> 8) & 0xff;
  476. skb->dst->neighbour->ha[9] = priv->pkey & 0xff;
  477. ipoib_mcast_send(dev, skb->dst->neighbour->ha + 4, skb);
  478. }
  479. static void unicast_arp_send(struct sk_buff *skb, struct net_device *dev,
  480. struct ipoib_pseudoheader *phdr)
  481. {
  482. struct ipoib_dev_priv *priv = netdev_priv(dev);
  483. struct ipoib_path *path;
  484. /*
  485. * We can only be called from ipoib_start_xmit, so we're
  486. * inside tx_lock -- no need to save/restore flags.
  487. */
  488. spin_lock(&priv->lock);
  489. path = __path_find(dev, phdr->hwaddr + 4);
  490. if (!path) {
  491. path = path_rec_create(dev, phdr->hwaddr + 4);
  492. if (path) {
  493. /* put pseudoheader back on for next time */
  494. skb_push(skb, sizeof *phdr);
  495. __skb_queue_tail(&path->queue, skb);
  496. if (path_rec_start(dev, path)) {
  497. spin_unlock(&priv->lock);
  498. path_free(dev, path);
  499. return;
  500. } else
  501. __path_add(dev, path);
  502. } else {
  503. ++dev->stats.tx_dropped;
  504. dev_kfree_skb_any(skb);
  505. }
  506. spin_unlock(&priv->lock);
  507. return;
  508. }
  509. if (path->ah) {
  510. ipoib_dbg(priv, "Send unicast ARP to %04x\n",
  511. be16_to_cpu(path->pathrec.dlid));
  512. ipoib_send(dev, skb, path->ah, IPOIB_QPN(phdr->hwaddr));
  513. } else if ((path->query || !path_rec_start(dev, path)) &&
  514. skb_queue_len(&path->queue) < IPOIB_MAX_PATH_REC_QUEUE) {
  515. /* put pseudoheader back on for next time */
  516. skb_push(skb, sizeof *phdr);
  517. __skb_queue_tail(&path->queue, skb);
  518. } else {
  519. ++dev->stats.tx_dropped;
  520. dev_kfree_skb_any(skb);
  521. }
  522. spin_unlock(&priv->lock);
  523. }
  524. static int ipoib_start_xmit(struct sk_buff *skb, struct net_device *dev)
  525. {
  526. struct ipoib_dev_priv *priv = netdev_priv(dev);
  527. struct ipoib_neigh *neigh;
  528. unsigned long flags;
  529. if (unlikely(!spin_trylock_irqsave(&priv->tx_lock, flags)))
  530. return NETDEV_TX_LOCKED;
  531. if (likely(skb->dst && skb->dst->neighbour)) {
  532. if (unlikely(!*to_ipoib_neigh(skb->dst->neighbour))) {
  533. ipoib_path_lookup(skb, dev);
  534. goto out;
  535. }
  536. neigh = *to_ipoib_neigh(skb->dst->neighbour);
  537. if (neigh->ah)
  538. if (unlikely((memcmp(&neigh->dgid.raw,
  539. skb->dst->neighbour->ha + 4,
  540. sizeof(union ib_gid))) ||
  541. (neigh->dev != dev))) {
  542. spin_lock(&priv->lock);
  543. /*
  544. * It's safe to call ipoib_put_ah() inside
  545. * priv->lock here, because we know that
  546. * path->ah will always hold one more reference,
  547. * so ipoib_put_ah() will never do more than
  548. * decrement the ref count.
  549. */
  550. ipoib_put_ah(neigh->ah);
  551. list_del(&neigh->list);
  552. ipoib_neigh_free(dev, neigh);
  553. spin_unlock(&priv->lock);
  554. ipoib_path_lookup(skb, dev);
  555. goto out;
  556. }
  557. if (ipoib_cm_get(neigh)) {
  558. if (ipoib_cm_up(neigh)) {
  559. ipoib_cm_send(dev, skb, ipoib_cm_get(neigh));
  560. goto out;
  561. }
  562. } else if (neigh->ah) {
  563. ipoib_send(dev, skb, neigh->ah, IPOIB_QPN(skb->dst->neighbour->ha));
  564. goto out;
  565. }
  566. if (skb_queue_len(&neigh->queue) < IPOIB_MAX_PATH_REC_QUEUE) {
  567. spin_lock(&priv->lock);
  568. __skb_queue_tail(&neigh->queue, skb);
  569. spin_unlock(&priv->lock);
  570. } else {
  571. ++dev->stats.tx_dropped;
  572. dev_kfree_skb_any(skb);
  573. }
  574. } else {
  575. struct ipoib_pseudoheader *phdr =
  576. (struct ipoib_pseudoheader *) skb->data;
  577. skb_pull(skb, sizeof *phdr);
  578. if (phdr->hwaddr[4] == 0xff) {
  579. /* Add in the P_Key for multicast*/
  580. phdr->hwaddr[8] = (priv->pkey >> 8) & 0xff;
  581. phdr->hwaddr[9] = priv->pkey & 0xff;
  582. ipoib_mcast_send(dev, phdr->hwaddr + 4, skb);
  583. } else {
  584. /* unicast GID -- should be ARP or RARP reply */
  585. if ((be16_to_cpup((__be16 *) skb->data) != ETH_P_ARP) &&
  586. (be16_to_cpup((__be16 *) skb->data) != ETH_P_RARP)) {
  587. ipoib_warn(priv, "Unicast, no %s: type %04x, QPN %06x "
  588. IPOIB_GID_FMT "\n",
  589. skb->dst ? "neigh" : "dst",
  590. be16_to_cpup((__be16 *) skb->data),
  591. IPOIB_QPN(phdr->hwaddr),
  592. IPOIB_GID_RAW_ARG(phdr->hwaddr + 4));
  593. dev_kfree_skb_any(skb);
  594. ++dev->stats.tx_dropped;
  595. goto out;
  596. }
  597. unicast_arp_send(skb, dev, phdr);
  598. }
  599. }
  600. out:
  601. spin_unlock_irqrestore(&priv->tx_lock, flags);
  602. return NETDEV_TX_OK;
  603. }
  604. static void ipoib_timeout(struct net_device *dev)
  605. {
  606. struct ipoib_dev_priv *priv = netdev_priv(dev);
  607. ipoib_warn(priv, "transmit timeout: latency %d msecs\n",
  608. jiffies_to_msecs(jiffies - dev->trans_start));
  609. ipoib_warn(priv, "queue stopped %d, tx_head %u, tx_tail %u\n",
  610. netif_queue_stopped(dev),
  611. priv->tx_head, priv->tx_tail);
  612. /* XXX reset QP, etc. */
  613. }
  614. static int ipoib_hard_header(struct sk_buff *skb,
  615. struct net_device *dev,
  616. unsigned short type,
  617. const void *daddr, const void *saddr, unsigned len)
  618. {
  619. struct ipoib_header *header;
  620. header = (struct ipoib_header *) skb_push(skb, sizeof *header);
  621. header->proto = htons(type);
  622. header->reserved = 0;
  623. /*
  624. * If we don't have a neighbour structure, stuff the
  625. * destination address onto the front of the skb so we can
  626. * figure out where to send the packet later.
  627. */
  628. if ((!skb->dst || !skb->dst->neighbour) && daddr) {
  629. struct ipoib_pseudoheader *phdr =
  630. (struct ipoib_pseudoheader *) skb_push(skb, sizeof *phdr);
  631. memcpy(phdr->hwaddr, daddr, INFINIBAND_ALEN);
  632. }
  633. return 0;
  634. }
  635. static void ipoib_set_mcast_list(struct net_device *dev)
  636. {
  637. struct ipoib_dev_priv *priv = netdev_priv(dev);
  638. if (!test_bit(IPOIB_FLAG_OPER_UP, &priv->flags)) {
  639. ipoib_dbg(priv, "IPOIB_FLAG_OPER_UP not set");
  640. return;
  641. }
  642. queue_work(ipoib_workqueue, &priv->restart_task);
  643. }
  644. static void ipoib_neigh_cleanup(struct neighbour *n)
  645. {
  646. struct ipoib_neigh *neigh;
  647. struct ipoib_dev_priv *priv = netdev_priv(n->dev);
  648. unsigned long flags;
  649. struct ipoib_ah *ah = NULL;
  650. neigh = *to_ipoib_neigh(n);
  651. if (neigh)
  652. priv = netdev_priv(neigh->dev);
  653. else
  654. return;
  655. ipoib_dbg(priv,
  656. "neigh_cleanup for %06x " IPOIB_GID_FMT "\n",
  657. IPOIB_QPN(n->ha),
  658. IPOIB_GID_RAW_ARG(n->ha + 4));
  659. spin_lock_irqsave(&priv->lock, flags);
  660. if (neigh->ah)
  661. ah = neigh->ah;
  662. list_del(&neigh->list);
  663. ipoib_neigh_free(n->dev, neigh);
  664. spin_unlock_irqrestore(&priv->lock, flags);
  665. if (ah)
  666. ipoib_put_ah(ah);
  667. }
  668. struct ipoib_neigh *ipoib_neigh_alloc(struct neighbour *neighbour,
  669. struct net_device *dev)
  670. {
  671. struct ipoib_neigh *neigh;
  672. neigh = kmalloc(sizeof *neigh, GFP_ATOMIC);
  673. if (!neigh)
  674. return NULL;
  675. neigh->neighbour = neighbour;
  676. neigh->dev = dev;
  677. *to_ipoib_neigh(neighbour) = neigh;
  678. skb_queue_head_init(&neigh->queue);
  679. ipoib_cm_set(neigh, NULL);
  680. return neigh;
  681. }
  682. void ipoib_neigh_free(struct net_device *dev, struct ipoib_neigh *neigh)
  683. {
  684. struct sk_buff *skb;
  685. *to_ipoib_neigh(neigh->neighbour) = NULL;
  686. while ((skb = __skb_dequeue(&neigh->queue))) {
  687. ++dev->stats.tx_dropped;
  688. dev_kfree_skb_any(skb);
  689. }
  690. if (ipoib_cm_get(neigh))
  691. ipoib_cm_destroy_tx(ipoib_cm_get(neigh));
  692. kfree(neigh);
  693. }
  694. static int ipoib_neigh_setup_dev(struct net_device *dev, struct neigh_parms *parms)
  695. {
  696. parms->neigh_cleanup = ipoib_neigh_cleanup;
  697. return 0;
  698. }
  699. int ipoib_dev_init(struct net_device *dev, struct ib_device *ca, int port)
  700. {
  701. struct ipoib_dev_priv *priv = netdev_priv(dev);
  702. /* Allocate RX/TX "rings" to hold queued skbs */
  703. priv->rx_ring = kzalloc(ipoib_recvq_size * sizeof *priv->rx_ring,
  704. GFP_KERNEL);
  705. if (!priv->rx_ring) {
  706. printk(KERN_WARNING "%s: failed to allocate RX ring (%d entries)\n",
  707. ca->name, ipoib_recvq_size);
  708. goto out;
  709. }
  710. priv->tx_ring = vmalloc(ipoib_sendq_size * sizeof *priv->tx_ring);
  711. if (!priv->tx_ring) {
  712. printk(KERN_WARNING "%s: failed to allocate TX ring (%d entries)\n",
  713. ca->name, ipoib_sendq_size);
  714. goto out_rx_ring_cleanup;
  715. }
  716. memset(priv->tx_ring, 0, ipoib_sendq_size * sizeof *priv->tx_ring);
  717. /* priv->tx_head, tx_tail & tx_outstanding are already 0 */
  718. if (ipoib_ib_dev_init(dev, ca, port))
  719. goto out_tx_ring_cleanup;
  720. return 0;
  721. out_tx_ring_cleanup:
  722. vfree(priv->tx_ring);
  723. out_rx_ring_cleanup:
  724. kfree(priv->rx_ring);
  725. out:
  726. return -ENOMEM;
  727. }
  728. void ipoib_dev_cleanup(struct net_device *dev)
  729. {
  730. struct ipoib_dev_priv *priv = netdev_priv(dev), *cpriv, *tcpriv;
  731. ipoib_delete_debug_files(dev);
  732. /* Delete any child interfaces first */
  733. list_for_each_entry_safe(cpriv, tcpriv, &priv->child_intfs, list) {
  734. unregister_netdev(cpriv->dev);
  735. ipoib_dev_cleanup(cpriv->dev);
  736. free_netdev(cpriv->dev);
  737. }
  738. ipoib_ib_dev_cleanup(dev);
  739. kfree(priv->rx_ring);
  740. vfree(priv->tx_ring);
  741. priv->rx_ring = NULL;
  742. priv->tx_ring = NULL;
  743. }
  744. static const struct header_ops ipoib_header_ops = {
  745. .create = ipoib_hard_header,
  746. };
  747. static void ipoib_setup(struct net_device *dev)
  748. {
  749. struct ipoib_dev_priv *priv = netdev_priv(dev);
  750. dev->open = ipoib_open;
  751. dev->stop = ipoib_stop;
  752. dev->change_mtu = ipoib_change_mtu;
  753. dev->hard_start_xmit = ipoib_start_xmit;
  754. dev->tx_timeout = ipoib_timeout;
  755. dev->header_ops = &ipoib_header_ops;
  756. dev->set_multicast_list = ipoib_set_mcast_list;
  757. dev->neigh_setup = ipoib_neigh_setup_dev;
  758. netif_napi_add(dev, &priv->napi, ipoib_poll, 100);
  759. dev->watchdog_timeo = HZ;
  760. dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
  761. /*
  762. * We add in INFINIBAND_ALEN to allow for the destination
  763. * address "pseudoheader" for skbs without neighbour struct.
  764. */
  765. dev->hard_header_len = IPOIB_ENCAP_LEN + INFINIBAND_ALEN;
  766. dev->addr_len = INFINIBAND_ALEN;
  767. dev->type = ARPHRD_INFINIBAND;
  768. dev->tx_queue_len = ipoib_sendq_size * 2;
  769. dev->features = (NETIF_F_VLAN_CHALLENGED |
  770. NETIF_F_LLTX |
  771. NETIF_F_HIGHDMA);
  772. /* MTU will be reset when mcast join happens */
  773. dev->mtu = IPOIB_PACKET_SIZE - IPOIB_ENCAP_LEN;
  774. priv->mcast_mtu = priv->admin_mtu = dev->mtu;
  775. memcpy(dev->broadcast, ipv4_bcast_addr, INFINIBAND_ALEN);
  776. netif_carrier_off(dev);
  777. priv->dev = dev;
  778. spin_lock_init(&priv->lock);
  779. spin_lock_init(&priv->tx_lock);
  780. mutex_init(&priv->mcast_mutex);
  781. mutex_init(&priv->vlan_mutex);
  782. INIT_LIST_HEAD(&priv->path_list);
  783. INIT_LIST_HEAD(&priv->child_intfs);
  784. INIT_LIST_HEAD(&priv->dead_ahs);
  785. INIT_LIST_HEAD(&priv->multicast_list);
  786. INIT_DELAYED_WORK(&priv->pkey_poll_task, ipoib_pkey_poll);
  787. INIT_WORK(&priv->pkey_event_task, ipoib_pkey_event);
  788. INIT_DELAYED_WORK(&priv->mcast_task, ipoib_mcast_join_task);
  789. INIT_WORK(&priv->flush_task, ipoib_ib_dev_flush);
  790. INIT_WORK(&priv->restart_task, ipoib_mcast_restart_task);
  791. INIT_DELAYED_WORK(&priv->ah_reap_task, ipoib_reap_ah);
  792. }
  793. struct ipoib_dev_priv *ipoib_intf_alloc(const char *name)
  794. {
  795. struct net_device *dev;
  796. dev = alloc_netdev((int) sizeof (struct ipoib_dev_priv), name,
  797. ipoib_setup);
  798. if (!dev)
  799. return NULL;
  800. return netdev_priv(dev);
  801. }
  802. static ssize_t show_pkey(struct device *dev,
  803. struct device_attribute *attr, char *buf)
  804. {
  805. struct ipoib_dev_priv *priv = netdev_priv(to_net_dev(dev));
  806. return sprintf(buf, "0x%04x\n", priv->pkey);
  807. }
  808. static DEVICE_ATTR(pkey, S_IRUGO, show_pkey, NULL);
  809. static ssize_t show_umcast(struct device *dev,
  810. struct device_attribute *attr, char *buf)
  811. {
  812. struct ipoib_dev_priv *priv = netdev_priv(to_net_dev(dev));
  813. return sprintf(buf, "%d\n", test_bit(IPOIB_FLAG_UMCAST, &priv->flags));
  814. }
  815. static ssize_t set_umcast(struct device *dev,
  816. struct device_attribute *attr,
  817. const char *buf, size_t count)
  818. {
  819. struct ipoib_dev_priv *priv = netdev_priv(to_net_dev(dev));
  820. unsigned long umcast_val = simple_strtoul(buf, NULL, 0);
  821. if (umcast_val > 0) {
  822. set_bit(IPOIB_FLAG_UMCAST, &priv->flags);
  823. ipoib_warn(priv, "ignoring multicast groups joined directly "
  824. "by userspace\n");
  825. } else
  826. clear_bit(IPOIB_FLAG_UMCAST, &priv->flags);
  827. return count;
  828. }
  829. static DEVICE_ATTR(umcast, S_IWUSR | S_IRUGO, show_umcast, set_umcast);
  830. int ipoib_add_umcast_attr(struct net_device *dev)
  831. {
  832. return device_create_file(&dev->dev, &dev_attr_umcast);
  833. }
  834. static ssize_t create_child(struct device *dev,
  835. struct device_attribute *attr,
  836. const char *buf, size_t count)
  837. {
  838. int pkey;
  839. int ret;
  840. if (sscanf(buf, "%i", &pkey) != 1)
  841. return -EINVAL;
  842. if (pkey < 0 || pkey > 0xffff)
  843. return -EINVAL;
  844. /*
  845. * Set the full membership bit, so that we join the right
  846. * broadcast group, etc.
  847. */
  848. pkey |= 0x8000;
  849. ret = ipoib_vlan_add(to_net_dev(dev), pkey);
  850. return ret ? ret : count;
  851. }
  852. static DEVICE_ATTR(create_child, S_IWUGO, NULL, create_child);
  853. static ssize_t delete_child(struct device *dev,
  854. struct device_attribute *attr,
  855. const char *buf, size_t count)
  856. {
  857. int pkey;
  858. int ret;
  859. if (sscanf(buf, "%i", &pkey) != 1)
  860. return -EINVAL;
  861. if (pkey < 0 || pkey > 0xffff)
  862. return -EINVAL;
  863. ret = ipoib_vlan_delete(to_net_dev(dev), pkey);
  864. return ret ? ret : count;
  865. }
  866. static DEVICE_ATTR(delete_child, S_IWUGO, NULL, delete_child);
  867. int ipoib_add_pkey_attr(struct net_device *dev)
  868. {
  869. return device_create_file(&dev->dev, &dev_attr_pkey);
  870. }
  871. static struct net_device *ipoib_add_port(const char *format,
  872. struct ib_device *hca, u8 port)
  873. {
  874. struct ipoib_dev_priv *priv;
  875. int result = -ENOMEM;
  876. priv = ipoib_intf_alloc(format);
  877. if (!priv)
  878. goto alloc_mem_failed;
  879. SET_NETDEV_DEV(priv->dev, hca->dma_device);
  880. result = ib_query_pkey(hca, port, 0, &priv->pkey);
  881. if (result) {
  882. printk(KERN_WARNING "%s: ib_query_pkey port %d failed (ret = %d)\n",
  883. hca->name, port, result);
  884. goto device_init_failed;
  885. }
  886. /*
  887. * Set the full membership bit, so that we join the right
  888. * broadcast group, etc.
  889. */
  890. priv->pkey |= 0x8000;
  891. priv->dev->broadcast[8] = priv->pkey >> 8;
  892. priv->dev->broadcast[9] = priv->pkey & 0xff;
  893. result = ib_query_gid(hca, port, 0, &priv->local_gid);
  894. if (result) {
  895. printk(KERN_WARNING "%s: ib_query_gid port %d failed (ret = %d)\n",
  896. hca->name, port, result);
  897. goto device_init_failed;
  898. } else
  899. memcpy(priv->dev->dev_addr + 4, priv->local_gid.raw, sizeof (union ib_gid));
  900. result = ipoib_dev_init(priv->dev, hca, port);
  901. if (result < 0) {
  902. printk(KERN_WARNING "%s: failed to initialize port %d (ret = %d)\n",
  903. hca->name, port, result);
  904. goto device_init_failed;
  905. }
  906. INIT_IB_EVENT_HANDLER(&priv->event_handler,
  907. priv->ca, ipoib_event);
  908. result = ib_register_event_handler(&priv->event_handler);
  909. if (result < 0) {
  910. printk(KERN_WARNING "%s: ib_register_event_handler failed for "
  911. "port %d (ret = %d)\n",
  912. hca->name, port, result);
  913. goto event_failed;
  914. }
  915. result = register_netdev(priv->dev);
  916. if (result) {
  917. printk(KERN_WARNING "%s: couldn't register ipoib port %d; error %d\n",
  918. hca->name, port, result);
  919. goto register_failed;
  920. }
  921. ipoib_create_debug_files(priv->dev);
  922. if (ipoib_cm_add_mode_attr(priv->dev))
  923. goto sysfs_failed;
  924. if (ipoib_add_pkey_attr(priv->dev))
  925. goto sysfs_failed;
  926. if (ipoib_add_umcast_attr(priv->dev))
  927. goto sysfs_failed;
  928. if (device_create_file(&priv->dev->dev, &dev_attr_create_child))
  929. goto sysfs_failed;
  930. if (device_create_file(&priv->dev->dev, &dev_attr_delete_child))
  931. goto sysfs_failed;
  932. return priv->dev;
  933. sysfs_failed:
  934. ipoib_delete_debug_files(priv->dev);
  935. unregister_netdev(priv->dev);
  936. register_failed:
  937. ib_unregister_event_handler(&priv->event_handler);
  938. flush_scheduled_work();
  939. event_failed:
  940. ipoib_dev_cleanup(priv->dev);
  941. device_init_failed:
  942. free_netdev(priv->dev);
  943. alloc_mem_failed:
  944. return ERR_PTR(result);
  945. }
  946. static void ipoib_add_one(struct ib_device *device)
  947. {
  948. struct list_head *dev_list;
  949. struct net_device *dev;
  950. struct ipoib_dev_priv *priv;
  951. int s, e, p;
  952. if (rdma_node_get_transport(device->node_type) != RDMA_TRANSPORT_IB)
  953. return;
  954. dev_list = kmalloc(sizeof *dev_list, GFP_KERNEL);
  955. if (!dev_list)
  956. return;
  957. INIT_LIST_HEAD(dev_list);
  958. if (device->node_type == RDMA_NODE_IB_SWITCH) {
  959. s = 0;
  960. e = 0;
  961. } else {
  962. s = 1;
  963. e = device->phys_port_cnt;
  964. }
  965. for (p = s; p <= e; ++p) {
  966. dev = ipoib_add_port("ib%d", device, p);
  967. if (!IS_ERR(dev)) {
  968. priv = netdev_priv(dev);
  969. list_add_tail(&priv->list, dev_list);
  970. }
  971. }
  972. ib_set_client_data(device, &ipoib_client, dev_list);
  973. }
  974. static void ipoib_remove_one(struct ib_device *device)
  975. {
  976. struct ipoib_dev_priv *priv, *tmp;
  977. struct list_head *dev_list;
  978. if (rdma_node_get_transport(device->node_type) != RDMA_TRANSPORT_IB)
  979. return;
  980. dev_list = ib_get_client_data(device, &ipoib_client);
  981. list_for_each_entry_safe(priv, tmp, dev_list, list) {
  982. ib_unregister_event_handler(&priv->event_handler);
  983. flush_scheduled_work();
  984. unregister_netdev(priv->dev);
  985. ipoib_dev_cleanup(priv->dev);
  986. free_netdev(priv->dev);
  987. }
  988. kfree(dev_list);
  989. }
  990. static int __init ipoib_init_module(void)
  991. {
  992. int ret;
  993. ipoib_recvq_size = roundup_pow_of_two(ipoib_recvq_size);
  994. ipoib_recvq_size = min(ipoib_recvq_size, IPOIB_MAX_QUEUE_SIZE);
  995. ipoib_recvq_size = max(ipoib_recvq_size, IPOIB_MIN_QUEUE_SIZE);
  996. ipoib_sendq_size = roundup_pow_of_two(ipoib_sendq_size);
  997. ipoib_sendq_size = min(ipoib_sendq_size, IPOIB_MAX_QUEUE_SIZE);
  998. ipoib_sendq_size = max(ipoib_sendq_size, IPOIB_MIN_QUEUE_SIZE);
  999. #ifdef CONFIG_INFINIBAND_IPOIB_CM
  1000. ipoib_max_conn_qp = min(ipoib_max_conn_qp, IPOIB_CM_MAX_CONN_QP);
  1001. #endif
  1002. ret = ipoib_register_debugfs();
  1003. if (ret)
  1004. return ret;
  1005. /*
  1006. * We create our own workqueue mainly because we want to be
  1007. * able to flush it when devices are being removed. We can't
  1008. * use schedule_work()/flush_scheduled_work() because both
  1009. * unregister_netdev() and linkwatch_event take the rtnl lock,
  1010. * so flush_scheduled_work() can deadlock during device
  1011. * removal.
  1012. */
  1013. ipoib_workqueue = create_singlethread_workqueue("ipoib");
  1014. if (!ipoib_workqueue) {
  1015. ret = -ENOMEM;
  1016. goto err_fs;
  1017. }
  1018. ib_sa_register_client(&ipoib_sa_client);
  1019. ret = ib_register_client(&ipoib_client);
  1020. if (ret)
  1021. goto err_sa;
  1022. return 0;
  1023. err_sa:
  1024. ib_sa_unregister_client(&ipoib_sa_client);
  1025. destroy_workqueue(ipoib_workqueue);
  1026. err_fs:
  1027. ipoib_unregister_debugfs();
  1028. return ret;
  1029. }
  1030. static void __exit ipoib_cleanup_module(void)
  1031. {
  1032. ib_unregister_client(&ipoib_client);
  1033. ib_sa_unregister_client(&ipoib_sa_client);
  1034. ipoib_unregister_debugfs();
  1035. destroy_workqueue(ipoib_workqueue);
  1036. }
  1037. module_init(ipoib_init_module);
  1038. module_exit(ipoib_cleanup_module);