ipoib_main.c 32 KB

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