Merge tag 'rdma-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/roland...
[deliverable/linux.git] / drivers / infiniband / ulp / ipoib / ipoib_main.c
CommitLineData
1da177e4
LT
1/*
2 * Copyright (c) 2004 Topspin Communications. All rights reserved.
2a1d9b7f
RD
3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
4 * Copyright (c) 2004 Voltaire, Inc. All rights reserved.
1da177e4
LT
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.
1da177e4
LT
33 */
34
35#include "ipoib.h"
36
1da177e4
LT
37#include <linux/module.h>
38
39#include <linux/init.h>
40#include <linux/slab.h>
0f485251 41#include <linux/kernel.h>
10313cbb 42#include <linux/vmalloc.h>
1da177e4
LT
43
44#include <linux/if_arp.h> /* For ARPHRD_xxx */
45
46#include <linux/ip.h>
47#include <linux/in.h>
48
b63b70d8
SP
49#include <linux/jhash.h>
50#include <net/arp.h>
14c85021 51
1da177e4
LT
52MODULE_AUTHOR("Roland Dreier");
53MODULE_DESCRIPTION("IP-over-InfiniBand net driver");
54MODULE_LICENSE("Dual BSD/GPL");
55
0f485251
SM
56int ipoib_sendq_size __read_mostly = IPOIB_TX_RING_SIZE;
57int ipoib_recvq_size __read_mostly = IPOIB_RX_RING_SIZE;
58
59module_param_named(send_queue_size, ipoib_sendq_size, int, 0444);
60MODULE_PARM_DESC(send_queue_size, "Number of descriptors in send queue");
61module_param_named(recv_queue_size, ipoib_recvq_size, int, 0444);
62MODULE_PARM_DESC(recv_queue_size, "Number of descriptors in receive queue");
63
1da177e4
LT
64#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
65int ipoib_debug_level;
66
67module_param_named(debug_level, ipoib_debug_level, int, 0644);
68MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0");
69#endif
70
1732b0ef
RD
71struct ipoib_path_iter {
72 struct net_device *dev;
73 struct ipoib_path path;
74};
75
1da177e4
LT
76static const u8 ipv4_bcast_addr[] = {
77 0x00, 0xff, 0xff, 0xff,
78 0xff, 0x12, 0x40, 0x1b, 0x00, 0x00, 0x00, 0x00,
79 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff
80};
81
82struct workqueue_struct *ipoib_workqueue;
83
c1a0b23b
MT
84struct ib_sa_client ipoib_sa_client;
85
1da177e4
LT
86static void ipoib_add_one(struct ib_device *device);
87static void ipoib_remove_one(struct ib_device *device);
b63b70d8 88static void ipoib_neigh_reclaim(struct rcu_head *rp);
1da177e4
LT
89
90static struct ib_client ipoib_client = {
91 .name = "ipoib",
92 .add = ipoib_add_one,
93 .remove = ipoib_remove_one
94};
95
96int ipoib_open(struct net_device *dev)
97{
98 struct ipoib_dev_priv *priv = netdev_priv(dev);
99
100 ipoib_dbg(priv, "bringing up interface\n");
101
e028cc55 102 set_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags);
1da177e4
LT
103
104 if (ipoib_pkey_dev_delay_open(dev))
105 return 0;
106
b8a1b1ce
RD
107 if (ipoib_ib_dev_open(dev))
108 goto err_disable;
fe25c561 109
b8a1b1ce
RD
110 if (ipoib_ib_dev_up(dev))
111 goto err_stop;
1da177e4
LT
112
113 if (!test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags)) {
114 struct ipoib_dev_priv *cpriv;
115
116 /* Bring up any child interfaces too */
95ed644f 117 mutex_lock(&priv->vlan_mutex);
1da177e4
LT
118 list_for_each_entry(cpriv, &priv->child_intfs, list) {
119 int flags;
120
121 flags = cpriv->dev->flags;
122 if (flags & IFF_UP)
123 continue;
124
125 dev_change_flags(cpriv->dev, flags | IFF_UP);
126 }
95ed644f 127 mutex_unlock(&priv->vlan_mutex);
1da177e4
LT
128 }
129
130 netif_start_queue(dev);
131
132 return 0;
b8a1b1ce
RD
133
134err_stop:
135 ipoib_ib_dev_stop(dev, 1);
136
137err_disable:
b8a1b1ce
RD
138 clear_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags);
139
140 return -EINVAL;
1da177e4
LT
141}
142
143static int ipoib_stop(struct net_device *dev)
144{
145 struct ipoib_dev_priv *priv = netdev_priv(dev);
146
147 ipoib_dbg(priv, "stopping interface\n");
148
149 clear_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags);
150
151 netif_stop_queue(dev);
152
bea1e22d 153 ipoib_ib_dev_down(dev, 1);
a77a57a1 154 ipoib_ib_dev_stop(dev, 0);
1da177e4
LT
155
156 if (!test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags)) {
157 struct ipoib_dev_priv *cpriv;
158
159 /* Bring down any child interfaces too */
95ed644f 160 mutex_lock(&priv->vlan_mutex);
1da177e4
LT
161 list_for_each_entry(cpriv, &priv->child_intfs, list) {
162 int flags;
163
164 flags = cpriv->dev->flags;
165 if (!(flags & IFF_UP))
166 continue;
167
168 dev_change_flags(cpriv->dev, flags & ~IFF_UP);
169 }
95ed644f 170 mutex_unlock(&priv->vlan_mutex);
1da177e4
LT
171 }
172
173 return 0;
174}
175
9baa0b03
OG
176static void ipoib_uninit(struct net_device *dev)
177{
178 ipoib_dev_cleanup(dev);
179}
180
9ca36f7d 181static netdev_features_t ipoib_fix_features(struct net_device *dev, netdev_features_t features)
3d96c74d
MM
182{
183 struct ipoib_dev_priv *priv = netdev_priv(dev);
184
185 if (test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags))
186 features &= ~(NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
187
188 return features;
189}
190
1da177e4
LT
191static int ipoib_change_mtu(struct net_device *dev, int new_mtu)
192{
193 struct ipoib_dev_priv *priv = netdev_priv(dev);
194
839fcaba 195 /* dev->mtu > 2K ==> connected mode */
586a6934
PS
196 if (ipoib_cm_admin_enabled(dev)) {
197 if (new_mtu > ipoib_cm_max_mtu(dev))
198 return -EINVAL;
199
839fcaba
MT
200 if (new_mtu > priv->mcast_mtu)
201 ipoib_warn(priv, "mtu > %d will cause multicast packet drops.\n",
202 priv->mcast_mtu);
586a6934 203
839fcaba
MT
204 dev->mtu = new_mtu;
205 return 0;
206 }
207
bc7b3a36 208 if (new_mtu > IPOIB_UD_MTU(priv->max_ib_mtu))
1da177e4
LT
209 return -EINVAL;
210
211 priv->admin_mtu = new_mtu;
212
213 dev->mtu = min(priv->mcast_mtu, priv->admin_mtu);
214
215 return 0;
216}
217
37c22a77 218static struct ipoib_path *__path_find(struct net_device *dev, void *gid)
1da177e4
LT
219{
220 struct ipoib_dev_priv *priv = netdev_priv(dev);
221 struct rb_node *n = priv->path_tree.rb_node;
222 struct ipoib_path *path;
223 int ret;
224
225 while (n) {
226 path = rb_entry(n, struct ipoib_path, rb_node);
227
37c22a77 228 ret = memcmp(gid, path->pathrec.dgid.raw,
1da177e4
LT
229 sizeof (union ib_gid));
230
231 if (ret < 0)
232 n = n->rb_left;
233 else if (ret > 0)
234 n = n->rb_right;
235 else
236 return path;
237 }
238
239 return NULL;
240}
241
242static int __path_add(struct net_device *dev, struct ipoib_path *path)
243{
244 struct ipoib_dev_priv *priv = netdev_priv(dev);
245 struct rb_node **n = &priv->path_tree.rb_node;
246 struct rb_node *pn = NULL;
247 struct ipoib_path *tpath;
248 int ret;
249
250 while (*n) {
251 pn = *n;
252 tpath = rb_entry(pn, struct ipoib_path, rb_node);
253
254 ret = memcmp(path->pathrec.dgid.raw, tpath->pathrec.dgid.raw,
255 sizeof (union ib_gid));
256 if (ret < 0)
257 n = &pn->rb_left;
258 else if (ret > 0)
259 n = &pn->rb_right;
260 else
261 return -EEXIST;
262 }
263
264 rb_link_node(&path->rb_node, pn, n);
265 rb_insert_color(&path->rb_node, &priv->path_tree);
266
267 list_add_tail(&path->list, &priv->path_list);
268
269 return 0;
270}
271
272static void path_free(struct net_device *dev, struct ipoib_path *path)
273{
1da177e4 274 struct sk_buff *skb;
1da177e4
LT
275
276 while ((skb = __skb_dequeue(&path->queue)))
277 dev_kfree_skb_irq(skb);
278
b63b70d8 279 ipoib_dbg(netdev_priv(dev), "path_free\n");
1da177e4 280
b63b70d8
SP
281 /* remove all neigh connected to this path */
282 ipoib_del_neighs_by_gid(dev, path->pathrec.dgid.raw);
1da177e4
LT
283
284 if (path->ah)
285 ipoib_put_ah(path->ah);
286
287 kfree(path);
288}
289
1732b0ef
RD
290#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
291
292struct ipoib_path_iter *ipoib_path_iter_init(struct net_device *dev)
293{
294 struct ipoib_path_iter *iter;
295
296 iter = kmalloc(sizeof *iter, GFP_KERNEL);
297 if (!iter)
298 return NULL;
299
300 iter->dev = dev;
301 memset(iter->path.pathrec.dgid.raw, 0, 16);
302
303 if (ipoib_path_iter_next(iter)) {
304 kfree(iter);
305 return NULL;
306 }
307
308 return iter;
309}
310
311int ipoib_path_iter_next(struct ipoib_path_iter *iter)
312{
313 struct ipoib_dev_priv *priv = netdev_priv(iter->dev);
314 struct rb_node *n;
315 struct ipoib_path *path;
316 int ret = 1;
317
318 spin_lock_irq(&priv->lock);
319
320 n = rb_first(&priv->path_tree);
321
322 while (n) {
323 path = rb_entry(n, struct ipoib_path, rb_node);
324
325 if (memcmp(iter->path.pathrec.dgid.raw, path->pathrec.dgid.raw,
326 sizeof (union ib_gid)) < 0) {
327 iter->path = *path;
328 ret = 0;
329 break;
330 }
331
332 n = rb_next(n);
333 }
334
335 spin_unlock_irq(&priv->lock);
336
337 return ret;
338}
339
340void ipoib_path_iter_read(struct ipoib_path_iter *iter,
341 struct ipoib_path *path)
342{
343 *path = iter->path;
344}
345
346#endif /* CONFIG_INFINIBAND_IPOIB_DEBUG */
347
ee1e2c82
MS
348void ipoib_mark_paths_invalid(struct net_device *dev)
349{
350 struct ipoib_dev_priv *priv = netdev_priv(dev);
351 struct ipoib_path *path, *tp;
352
353 spin_lock_irq(&priv->lock);
354
355 list_for_each_entry_safe(path, tp, &priv->path_list, list) {
5b095d98 356 ipoib_dbg(priv, "mark path LID 0x%04x GID %pI6 invalid\n",
ee1e2c82 357 be16_to_cpu(path->pathrec.dlid),
fcace2fe 358 path->pathrec.dgid.raw);
ee1e2c82
MS
359 path->valid = 0;
360 }
361
362 spin_unlock_irq(&priv->lock);
363}
364
1da177e4
LT
365void ipoib_flush_paths(struct net_device *dev)
366{
367 struct ipoib_dev_priv *priv = netdev_priv(dev);
368 struct ipoib_path *path, *tp;
369 LIST_HEAD(remove_list);
943c246e 370 unsigned long flags;
1da177e4 371
943c246e
RD
372 netif_tx_lock_bh(dev);
373 spin_lock_irqsave(&priv->lock, flags);
1da177e4 374
157de229 375 list_splice_init(&priv->path_list, &remove_list);
1da177e4
LT
376
377 list_for_each_entry(path, &remove_list, list)
378 rb_erase(&path->rb_node, &priv->path_tree);
379
1da177e4
LT
380 list_for_each_entry_safe(path, tp, &remove_list, list) {
381 if (path->query)
382 ib_sa_cancel_query(path->query_id, path->query);
943c246e
RD
383 spin_unlock_irqrestore(&priv->lock, flags);
384 netif_tx_unlock_bh(dev);
1da177e4
LT
385 wait_for_completion(&path->done);
386 path_free(dev, path);
943c246e
RD
387 netif_tx_lock_bh(dev);
388 spin_lock_irqsave(&priv->lock, flags);
1da177e4 389 }
943c246e
RD
390
391 spin_unlock_irqrestore(&priv->lock, flags);
392 netif_tx_unlock_bh(dev);
1da177e4
LT
393}
394
395static void path_rec_completion(int status,
396 struct ib_sa_path_rec *pathrec,
397 void *path_ptr)
398{
399 struct ipoib_path *path = path_ptr;
400 struct net_device *dev = path->dev;
401 struct ipoib_dev_priv *priv = netdev_priv(dev);
402 struct ipoib_ah *ah = NULL;
c9da4bad 403 struct ipoib_ah *old_ah = NULL;
d04d01b1 404 struct ipoib_neigh *neigh, *tn;
1da177e4
LT
405 struct sk_buff_head skqueue;
406 struct sk_buff *skb;
407 unsigned long flags;
408
843613b0 409 if (!status)
5b095d98 410 ipoib_dbg(priv, "PathRec LID 0x%04x for GID %pI6\n",
fcace2fe 411 be16_to_cpu(pathrec->dlid), pathrec->dgid.raw);
1da177e4 412 else
5b095d98 413 ipoib_dbg(priv, "PathRec status %d for GID %pI6\n",
fcace2fe 414 status, path->pathrec.dgid.raw);
1da177e4
LT
415
416 skb_queue_head_init(&skqueue);
417
418 if (!status) {
46f1b3d7
SH
419 struct ib_ah_attr av;
420
421 if (!ib_init_ah_from_path(priv->ca, priv->port, pathrec, &av))
422 ah = ipoib_create_ah(dev, priv->pd, &av);
1da177e4
LT
423 }
424
425 spin_lock_irqsave(&priv->lock, flags);
426
3874397c 427 if (!IS_ERR_OR_NULL(ah)) {
1da177e4
LT
428 path->pathrec = *pathrec;
429
c9da4bad
RD
430 old_ah = path->ah;
431 path->ah = ah;
432
1da177e4
LT
433 ipoib_dbg(priv, "created address handle %p for LID 0x%04x, SL %d\n",
434 ah, be16_to_cpu(pathrec->dlid), pathrec->sl);
435
436 while ((skb = __skb_dequeue(&path->queue)))
437 __skb_queue_tail(&skqueue, skb);
438
d04d01b1 439 list_for_each_entry_safe(neigh, tn, &path->neigh_list, list) {
ee1e2c82
MS
440 if (neigh->ah) {
441 WARN_ON(neigh->ah != old_ah);
442 /*
443 * Dropping the ah reference inside
444 * priv->lock is safe here, because we
445 * will hold one more reference from
446 * the original value of path->ah (ie
447 * old_ah).
448 */
449 ipoib_put_ah(neigh->ah);
450 }
1da177e4
LT
451 kref_get(&path->ah->ref);
452 neigh->ah = path->ah;
453
b63b70d8 454 if (ipoib_cm_enabled(dev, neigh->daddr)) {
839fcaba
MT
455 if (!ipoib_cm_get(neigh))
456 ipoib_cm_set(neigh, ipoib_cm_create_tx(dev,
457 path,
458 neigh));
459 if (!ipoib_cm_get(neigh)) {
460 list_del(&neigh->list);
b63b70d8 461 ipoib_neigh_free(neigh);
839fcaba
MT
462 continue;
463 }
464 }
465
1da177e4
LT
466 while ((skb = __skb_dequeue(&neigh->queue)))
467 __skb_queue_tail(&skqueue, skb);
468 }
ee1e2c82 469 path->valid = 1;
5872a9fc 470 }
1da177e4 471
5872a9fc 472 path->query = NULL;
1da177e4
LT
473 complete(&path->done);
474
475 spin_unlock_irqrestore(&priv->lock, flags);
476
ee1e2c82
MS
477 if (old_ah)
478 ipoib_put_ah(old_ah);
479
1da177e4
LT
480 while ((skb = __skb_dequeue(&skqueue))) {
481 skb->dev = dev;
482 if (dev_queue_xmit(skb))
483 ipoib_warn(priv, "dev_queue_xmit failed "
484 "to requeue packet\n");
485 }
486}
487
37c22a77 488static struct ipoib_path *path_rec_create(struct net_device *dev, void *gid)
1da177e4
LT
489{
490 struct ipoib_dev_priv *priv = netdev_priv(dev);
491 struct ipoib_path *path;
492
1401b53a
JM
493 if (!priv->broadcast)
494 return NULL;
495
21a38489 496 path = kzalloc(sizeof *path, GFP_ATOMIC);
1da177e4
LT
497 if (!path)
498 return NULL;
499
21a38489 500 path->dev = dev;
1da177e4
LT
501
502 skb_queue_head_init(&path->queue);
503
504 INIT_LIST_HEAD(&path->neigh_list);
1da177e4 505
37c22a77 506 memcpy(path->pathrec.dgid.raw, gid, sizeof (union ib_gid));
2337f809
RD
507 path->pathrec.sgid = priv->local_gid;
508 path->pathrec.pkey = cpu_to_be16(priv->pkey);
81668838
SH
509 path->pathrec.numb_path = 1;
510 path->pathrec.traffic_class = priv->broadcast->mcmember.traffic_class;
1da177e4
LT
511
512 return path;
513}
514
515static int path_rec_start(struct net_device *dev,
516 struct ipoib_path *path)
517{
518 struct ipoib_dev_priv *priv = netdev_priv(dev);
519
5b095d98 520 ipoib_dbg(priv, "Start path record lookup for %pI6\n",
fcace2fe 521 path->pathrec.dgid.raw);
1da177e4 522
65c7edda
RD
523 init_completion(&path->done);
524
1da177e4 525 path->query_id =
c1a0b23b 526 ib_sa_path_rec_get(&ipoib_sa_client, priv->ca, priv->port,
1da177e4
LT
527 &path->pathrec,
528 IB_SA_PATH_REC_DGID |
529 IB_SA_PATH_REC_SGID |
530 IB_SA_PATH_REC_NUMB_PATH |
81668838 531 IB_SA_PATH_REC_TRAFFIC_CLASS |
1da177e4
LT
532 IB_SA_PATH_REC_PKEY,
533 1000, GFP_ATOMIC,
534 path_rec_completion,
535 path, &path->query);
536 if (path->query_id < 0) {
01b3fc8b 537 ipoib_warn(priv, "ib_sa_path_rec_get failed: %d\n", path->query_id);
1da177e4 538 path->query = NULL;
93a3ab93 539 complete(&path->done);
1da177e4
LT
540 return path->query_id;
541 }
542
543 return 0;
544}
545
b63b70d8
SP
546static void neigh_add_path(struct sk_buff *skb, u8 *daddr,
547 struct net_device *dev)
1da177e4
LT
548{
549 struct ipoib_dev_priv *priv = netdev_priv(dev);
550 struct ipoib_path *path;
551 struct ipoib_neigh *neigh;
943c246e 552 unsigned long flags;
1da177e4 553
b5120a6e 554 spin_lock_irqsave(&priv->lock, flags);
b63b70d8 555 neigh = ipoib_neigh_alloc(daddr, dev);
1da177e4 556 if (!neigh) {
b5120a6e 557 spin_unlock_irqrestore(&priv->lock, flags);
de903512 558 ++dev->stats.tx_dropped;
1da177e4
LT
559 dev_kfree_skb_any(skb);
560 return;
561 }
562
b63b70d8 563 path = __path_find(dev, daddr + 4);
1da177e4 564 if (!path) {
b63b70d8 565 path = path_rec_create(dev, daddr + 4);
1da177e4 566 if (!path)
d2e0655e 567 goto err_path;
1da177e4
LT
568
569 __path_add(dev, path);
570 }
571
572 list_add_tail(&neigh->list, &path->neigh_list);
573
47f7a071 574 if (path->ah) {
1da177e4
LT
575 kref_get(&path->ah->ref);
576 neigh->ah = path->ah;
577
b63b70d8 578 if (ipoib_cm_enabled(dev, neigh->daddr)) {
839fcaba
MT
579 if (!ipoib_cm_get(neigh))
580 ipoib_cm_set(neigh, ipoib_cm_create_tx(dev, path, neigh));
581 if (!ipoib_cm_get(neigh)) {
582 list_del(&neigh->list);
b63b70d8 583 ipoib_neigh_free(neigh);
839fcaba
MT
584 goto err_drop;
585 }
586 if (skb_queue_len(&neigh->queue) < IPOIB_MAX_PATH_REC_QUEUE)
587 __skb_queue_tail(&neigh->queue, skb);
588 else {
589 ipoib_warn(priv, "queue length limit %d. Packet drop.\n",
590 skb_queue_len(&neigh->queue));
591 goto err_drop;
592 }
721d67cd
RD
593 } else {
594 spin_unlock_irqrestore(&priv->lock, flags);
b63b70d8
SP
595 ipoib_send(dev, skb, path->ah, IPOIB_QPN(daddr));
596 ipoib_neigh_put(neigh);
721d67cd
RD
597 return;
598 }
1da177e4
LT
599 } else {
600 neigh->ah = NULL;
1da177e4
LT
601
602 if (!path->query && path_rec_start(dev, path))
d2e0655e 603 goto err_list;
2745b5b7
MT
604
605 __skb_queue_tail(&neigh->queue, skb);
1da177e4
LT
606 }
607
943c246e 608 spin_unlock_irqrestore(&priv->lock, flags);
b63b70d8 609 ipoib_neigh_put(neigh);
1da177e4
LT
610 return;
611
d2e0655e 612err_list:
1da177e4 613 list_del(&neigh->list);
1da177e4 614
d2e0655e 615err_path:
b63b70d8 616 ipoib_neigh_free(neigh);
839fcaba 617err_drop:
de903512 618 ++dev->stats.tx_dropped;
1da177e4
LT
619 dev_kfree_skb_any(skb);
620
943c246e 621 spin_unlock_irqrestore(&priv->lock, flags);
b63b70d8 622 ipoib_neigh_put(neigh);
1da177e4
LT
623}
624
625static void unicast_arp_send(struct sk_buff *skb, struct net_device *dev,
936d7de3 626 struct ipoib_cb *cb)
1da177e4
LT
627{
628 struct ipoib_dev_priv *priv = netdev_priv(dev);
629 struct ipoib_path *path;
943c246e 630 unsigned long flags;
1da177e4 631
943c246e 632 spin_lock_irqsave(&priv->lock, flags);
1da177e4 633
936d7de3 634 path = __path_find(dev, cb->hwaddr + 4);
ee1e2c82 635 if (!path || !path->valid) {
71d98b46
JM
636 int new_path = 0;
637
638 if (!path) {
936d7de3 639 path = path_rec_create(dev, cb->hwaddr + 4);
71d98b46
JM
640 new_path = 1;
641 }
1da177e4 642 if (path) {
1da177e4
LT
643 __skb_queue_tail(&path->queue, skb);
644
ff79ae80 645 if (!path->query && path_rec_start(dev, path)) {
943c246e 646 spin_unlock_irqrestore(&priv->lock, flags);
71d98b46
JM
647 if (new_path)
648 path_free(dev, path);
1da177e4
LT
649 return;
650 } else
651 __path_add(dev, path);
652 } else {
de903512 653 ++dev->stats.tx_dropped;
1da177e4
LT
654 dev_kfree_skb_any(skb);
655 }
656
943c246e 657 spin_unlock_irqrestore(&priv->lock, flags);
1da177e4
LT
658 return;
659 }
660
47f7a071 661 if (path->ah) {
1da177e4
LT
662 ipoib_dbg(priv, "Send unicast ARP to %04x\n",
663 be16_to_cpu(path->pathrec.dlid));
664
721d67cd 665 spin_unlock_irqrestore(&priv->lock, flags);
936d7de3 666 ipoib_send(dev, skb, path->ah, IPOIB_QPN(cb->hwaddr));
721d67cd 667 return;
1da177e4
LT
668 } else if ((path->query || !path_rec_start(dev, path)) &&
669 skb_queue_len(&path->queue) < IPOIB_MAX_PATH_REC_QUEUE) {
1da177e4
LT
670 __skb_queue_tail(&path->queue, skb);
671 } else {
de903512 672 ++dev->stats.tx_dropped;
1da177e4
LT
673 dev_kfree_skb_any(skb);
674 }
675
943c246e 676 spin_unlock_irqrestore(&priv->lock, flags);
1da177e4
LT
677}
678
679static int ipoib_start_xmit(struct sk_buff *skb, struct net_device *dev)
680{
681 struct ipoib_dev_priv *priv = netdev_priv(dev);
682 struct ipoib_neigh *neigh;
b63b70d8
SP
683 struct ipoib_cb *cb = (struct ipoib_cb *) skb->cb;
684 struct ipoib_header *header;
1da177e4
LT
685 unsigned long flags;
686
b63b70d8
SP
687 header = (struct ipoib_header *) skb->data;
688
689 if (unlikely(cb->hwaddr[4] == 0xff)) {
690 /* multicast, arrange "if" according to probability */
691 if ((header->proto != htons(ETH_P_IP)) &&
692 (header->proto != htons(ETH_P_IPV6)) &&
693 (header->proto != htons(ETH_P_ARP)) &&
694 (header->proto != htons(ETH_P_RARP))) {
695 /* ethertype not supported by IPoIB */
17e6abee
DM
696 ++dev->stats.tx_dropped;
697 dev_kfree_skb_any(skb);
b63b70d8 698 return NETDEV_TX_OK;
17e6abee 699 }
b63b70d8
SP
700 /* Add in the P_Key for multicast*/
701 cb->hwaddr[8] = (priv->pkey >> 8) & 0xff;
702 cb->hwaddr[9] = priv->pkey & 0xff;
703
704 neigh = ipoib_neigh_get(dev, cb->hwaddr);
705 if (likely(neigh))
706 goto send_using_neigh;
707 ipoib_mcast_send(dev, cb->hwaddr, skb);
708 return NETDEV_TX_OK;
17e6abee 709 }
1da177e4 710
b63b70d8
SP
711 /* unicast, arrange "switch" according to probability */
712 switch (header->proto) {
713 case htons(ETH_P_IP):
714 case htons(ETH_P_IPV6):
715 neigh = ipoib_neigh_get(dev, cb->hwaddr);
716 if (unlikely(!neigh)) {
717 neigh_add_path(skb, cb->hwaddr, dev);
718 return NETDEV_TX_OK;
a50df398 719 }
b63b70d8
SP
720 break;
721 case htons(ETH_P_ARP):
722 case htons(ETH_P_RARP):
723 /* for unicast ARP and RARP should always perform path find */
724 unicast_arp_send(skb, dev, cb);
725 return NETDEV_TX_OK;
726 default:
727 /* ethertype not supported by IPoIB */
728 ++dev->stats.tx_dropped;
729 dev_kfree_skb_any(skb);
730 return NETDEV_TX_OK;
731 }
8a7f7521 732
b63b70d8
SP
733send_using_neigh:
734 /* note we now hold a ref to neigh */
735 if (ipoib_cm_get(neigh)) {
736 if (ipoib_cm_up(neigh)) {
737 ipoib_cm_send(dev, skb, ipoib_cm_get(neigh));
738 goto unref;
1da177e4 739 }
b63b70d8
SP
740 } else if (neigh->ah) {
741 ipoib_send(dev, skb, neigh->ah, IPOIB_QPN(cb->hwaddr));
742 goto unref;
743 }
1da177e4 744
b63b70d8
SP
745 if (skb_queue_len(&neigh->queue) < IPOIB_MAX_PATH_REC_QUEUE) {
746 spin_lock_irqsave(&priv->lock, flags);
747 __skb_queue_tail(&neigh->queue, skb);
748 spin_unlock_irqrestore(&priv->lock, flags);
1da177e4 749 } else {
b63b70d8
SP
750 ++dev->stats.tx_dropped;
751 dev_kfree_skb_any(skb);
752 }
1da177e4 753
b63b70d8
SP
754unref:
755 ipoib_neigh_put(neigh);
1da177e4 756
1da177e4
LT
757 return NETDEV_TX_OK;
758}
759
1da177e4
LT
760static void ipoib_timeout(struct net_device *dev)
761{
762 struct ipoib_dev_priv *priv = netdev_priv(dev);
763
4b2d319b
RD
764 ipoib_warn(priv, "transmit timeout: latency %d msecs\n",
765 jiffies_to_msecs(jiffies - dev->trans_start));
766 ipoib_warn(priv, "queue stopped %d, tx_head %u, tx_tail %u\n",
767 netif_queue_stopped(dev),
768 priv->tx_head, priv->tx_tail);
1da177e4
LT
769 /* XXX reset QP, etc. */
770}
771
772static int ipoib_hard_header(struct sk_buff *skb,
773 struct net_device *dev,
774 unsigned short type,
3b04ddde 775 const void *daddr, const void *saddr, unsigned len)
1da177e4
LT
776{
777 struct ipoib_header *header;
b63b70d8 778 struct ipoib_cb *cb = (struct ipoib_cb *) skb->cb;
1da177e4
LT
779
780 header = (struct ipoib_header *) skb_push(skb, sizeof *header);
781
782 header->proto = htons(type);
783 header->reserved = 0;
784
785 /*
b63b70d8 786 * we don't rely on dst_entry structure, always stuff the
936d7de3
RD
787 * destination address into skb->cb so we can figure out where
788 * to send the packet later.
1da177e4 789 */
b63b70d8 790 memcpy(cb->hwaddr, daddr, INFINIBAND_ALEN);
1da177e4
LT
791
792 return 0;
793}
794
795static void ipoib_set_mcast_list(struct net_device *dev)
796{
797 struct ipoib_dev_priv *priv = netdev_priv(dev);
798
7a343d4c
LA
799 if (!test_bit(IPOIB_FLAG_OPER_UP, &priv->flags)) {
800 ipoib_dbg(priv, "IPOIB_FLAG_OPER_UP not set");
801 return;
802 }
803
1ad62a19 804 queue_work(ipoib_workqueue, &priv->restart_task);
1da177e4
LT
805}
806
b63b70d8 807static u32 ipoib_addr_hash(struct ipoib_neigh_hash *htbl, u8 *daddr)
1da177e4 808{
b63b70d8
SP
809 /*
810 * Use only the address parts that contributes to spreading
811 * The subnet prefix is not used as one can not connect to
812 * same remote port (GUID) using the same remote QPN via two
813 * different subnets.
814 */
815 /* qpn octets[1:4) & port GUID octets[12:20) */
816 u32 *daddr_32 = (u32 *) daddr;
817 u32 hv;
818
819 hv = jhash_3words(daddr_32[3], daddr_32[4], 0xFFFFFF & daddr_32[0], 0);
820 return hv & htbl->mask;
821}
822
823struct ipoib_neigh *ipoib_neigh_get(struct net_device *dev, u8 *daddr)
824{
825 struct ipoib_dev_priv *priv = netdev_priv(dev);
826 struct ipoib_neigh_table *ntbl = &priv->ntbl;
827 struct ipoib_neigh_hash *htbl;
828 struct ipoib_neigh *neigh = NULL;
829 u32 hash_val;
830
831 rcu_read_lock_bh();
832
833 htbl = rcu_dereference_bh(ntbl->htbl);
834
835 if (!htbl)
836 goto out_unlock;
837
838 hash_val = ipoib_addr_hash(htbl, daddr);
839 for (neigh = rcu_dereference_bh(htbl->buckets[hash_val]);
840 neigh != NULL;
841 neigh = rcu_dereference_bh(neigh->hnext)) {
842 if (memcmp(daddr, neigh->daddr, INFINIBAND_ALEN) == 0) {
843 /* found, take one ref on behalf of the caller */
844 if (!atomic_inc_not_zero(&neigh->refcnt)) {
845 /* deleted */
846 neigh = NULL;
847 goto out_unlock;
848 }
849 neigh->alive = jiffies;
850 goto out_unlock;
851 }
852 }
853
854out_unlock:
855 rcu_read_unlock_bh();
856 return neigh;
857}
858
859static void __ipoib_reap_neigh(struct ipoib_dev_priv *priv)
860{
861 struct ipoib_neigh_table *ntbl = &priv->ntbl;
862 struct ipoib_neigh_hash *htbl;
863 unsigned long neigh_obsolete;
864 unsigned long dt;
1da177e4 865 unsigned long flags;
b63b70d8 866 int i;
1da177e4 867
b63b70d8 868 if (test_bit(IPOIB_STOP_NEIGH_GC, &priv->flags))
732a2170 869 return;
1da177e4 870
b5120a6e 871 spin_lock_irqsave(&priv->lock, flags);
b63b70d8
SP
872
873 htbl = rcu_dereference_protected(ntbl->htbl,
b5120a6e 874 lockdep_is_held(&priv->lock));
b63b70d8
SP
875
876 if (!htbl)
877 goto out_unlock;
878
879 /* neigh is obsolete if it was idle for two GC periods */
880 dt = 2 * arp_tbl.gc_interval;
881 neigh_obsolete = jiffies - dt;
882 /* handle possible race condition */
883 if (test_bit(IPOIB_STOP_NEIGH_GC, &priv->flags))
884 goto out_unlock;
885
886 for (i = 0; i < htbl->size; i++) {
887 struct ipoib_neigh *neigh;
888 struct ipoib_neigh __rcu **np = &htbl->buckets[i];
889
890 while ((neigh = rcu_dereference_protected(*np,
b5120a6e 891 lockdep_is_held(&priv->lock))) != NULL) {
b63b70d8
SP
892 /* was the neigh idle for two GC periods */
893 if (time_after(neigh_obsolete, neigh->alive)) {
894 rcu_assign_pointer(*np,
895 rcu_dereference_protected(neigh->hnext,
b5120a6e 896 lockdep_is_held(&priv->lock)));
b63b70d8 897 /* remove from path/mc list */
b63b70d8 898 list_del(&neigh->list);
b63b70d8
SP
899 call_rcu(&neigh->rcu, ipoib_neigh_reclaim);
900 } else {
901 np = &neigh->hnext;
902 }
1da177e4 903
b63b70d8
SP
904 }
905 }
1da177e4 906
b63b70d8 907out_unlock:
b5120a6e 908 spin_unlock_irqrestore(&priv->lock, flags);
b63b70d8 909}
1da177e4 910
b63b70d8
SP
911static void ipoib_reap_neigh(struct work_struct *work)
912{
913 struct ipoib_dev_priv *priv =
914 container_of(work, struct ipoib_dev_priv, neigh_reap_task.work);
915
916 __ipoib_reap_neigh(priv);
917
918 if (!test_bit(IPOIB_STOP_NEIGH_GC, &priv->flags))
919 queue_delayed_work(ipoib_workqueue, &priv->neigh_reap_task,
920 arp_tbl.gc_interval);
1da177e4
LT
921}
922
b63b70d8
SP
923
924static struct ipoib_neigh *ipoib_neigh_ctor(u8 *daddr,
732a2170 925 struct net_device *dev)
d2e0655e
MT
926{
927 struct ipoib_neigh *neigh;
928
b63b70d8 929 neigh = kzalloc(sizeof *neigh, GFP_ATOMIC);
d2e0655e
MT
930 if (!neigh)
931 return NULL;
932
732a2170 933 neigh->dev = dev;
b63b70d8 934 memcpy(&neigh->daddr, daddr, sizeof(neigh->daddr));
82b39913 935 skb_queue_head_init(&neigh->queue);
b63b70d8 936 INIT_LIST_HEAD(&neigh->list);
839fcaba 937 ipoib_cm_set(neigh, NULL);
b63b70d8
SP
938 /* one ref on behalf of the caller */
939 atomic_set(&neigh->refcnt, 1);
940
941 return neigh;
942}
943
944struct ipoib_neigh *ipoib_neigh_alloc(u8 *daddr,
945 struct net_device *dev)
946{
947 struct ipoib_dev_priv *priv = netdev_priv(dev);
948 struct ipoib_neigh_table *ntbl = &priv->ntbl;
949 struct ipoib_neigh_hash *htbl;
950 struct ipoib_neigh *neigh;
951 u32 hash_val;
952
b63b70d8 953 htbl = rcu_dereference_protected(ntbl->htbl,
b5120a6e 954 lockdep_is_held(&priv->lock));
b63b70d8
SP
955 if (!htbl) {
956 neigh = NULL;
957 goto out_unlock;
958 }
959
960 /* need to add a new neigh, but maybe some other thread succeeded?
961 * recalc hash, maybe hash resize took place so we do a search
962 */
963 hash_val = ipoib_addr_hash(htbl, daddr);
964 for (neigh = rcu_dereference_protected(htbl->buckets[hash_val],
b5120a6e 965 lockdep_is_held(&priv->lock));
b63b70d8
SP
966 neigh != NULL;
967 neigh = rcu_dereference_protected(neigh->hnext,
b5120a6e 968 lockdep_is_held(&priv->lock))) {
b63b70d8
SP
969 if (memcmp(daddr, neigh->daddr, INFINIBAND_ALEN) == 0) {
970 /* found, take one ref on behalf of the caller */
971 if (!atomic_inc_not_zero(&neigh->refcnt)) {
972 /* deleted */
973 neigh = NULL;
974 break;
975 }
976 neigh->alive = jiffies;
977 goto out_unlock;
978 }
979 }
980
981 neigh = ipoib_neigh_ctor(daddr, dev);
982 if (!neigh)
983 goto out_unlock;
984
985 /* one ref on behalf of the hash table */
986 atomic_inc(&neigh->refcnt);
987 neigh->alive = jiffies;
988 /* put in hash */
989 rcu_assign_pointer(neigh->hnext,
990 rcu_dereference_protected(htbl->buckets[hash_val],
b5120a6e 991 lockdep_is_held(&priv->lock)));
b63b70d8
SP
992 rcu_assign_pointer(htbl->buckets[hash_val], neigh);
993 atomic_inc(&ntbl->entries);
994
995out_unlock:
d2e0655e
MT
996
997 return neigh;
998}
999
b63b70d8 1000void ipoib_neigh_dtor(struct ipoib_neigh *neigh)
d2e0655e 1001{
b63b70d8
SP
1002 /* neigh reference count was dropprd to zero */
1003 struct net_device *dev = neigh->dev;
1004 struct ipoib_dev_priv *priv = netdev_priv(dev);
2745b5b7 1005 struct sk_buff *skb;
b63b70d8
SP
1006 if (neigh->ah)
1007 ipoib_put_ah(neigh->ah);
2745b5b7 1008 while ((skb = __skb_dequeue(&neigh->queue))) {
de903512 1009 ++dev->stats.tx_dropped;
2745b5b7
MT
1010 dev_kfree_skb_any(skb);
1011 }
839fcaba
MT
1012 if (ipoib_cm_get(neigh))
1013 ipoib_cm_destroy_tx(ipoib_cm_get(neigh));
b63b70d8
SP
1014 ipoib_dbg(netdev_priv(dev),
1015 "neigh free for %06x %pI6\n",
1016 IPOIB_QPN(neigh->daddr),
1017 neigh->daddr + 4);
d2e0655e 1018 kfree(neigh);
b63b70d8
SP
1019 if (atomic_dec_and_test(&priv->ntbl.entries)) {
1020 if (test_bit(IPOIB_NEIGH_TBL_FLUSH, &priv->flags))
1021 complete(&priv->ntbl.flushed);
1022 }
1023}
1024
1025static void ipoib_neigh_reclaim(struct rcu_head *rp)
1026{
1027 /* Called as a result of removal from hash table */
1028 struct ipoib_neigh *neigh = container_of(rp, struct ipoib_neigh, rcu);
1029 /* note TX context may hold another ref */
1030 ipoib_neigh_put(neigh);
d2e0655e
MT
1031}
1032
b63b70d8 1033void ipoib_neigh_free(struct ipoib_neigh *neigh)
1da177e4 1034{
b63b70d8
SP
1035 struct net_device *dev = neigh->dev;
1036 struct ipoib_dev_priv *priv = netdev_priv(dev);
1037 struct ipoib_neigh_table *ntbl = &priv->ntbl;
1038 struct ipoib_neigh_hash *htbl;
1039 struct ipoib_neigh __rcu **np;
1040 struct ipoib_neigh *n;
1041 u32 hash_val;
1042
b63b70d8 1043 htbl = rcu_dereference_protected(ntbl->htbl,
b5120a6e 1044 lockdep_is_held(&priv->lock));
b63b70d8 1045 if (!htbl)
b5120a6e 1046 return;
b63b70d8
SP
1047
1048 hash_val = ipoib_addr_hash(htbl, neigh->daddr);
1049 np = &htbl->buckets[hash_val];
1050 for (n = rcu_dereference_protected(*np,
b5120a6e 1051 lockdep_is_held(&priv->lock));
b63b70d8 1052 n != NULL;
6c723a68 1053 n = rcu_dereference_protected(*np,
b5120a6e 1054 lockdep_is_held(&priv->lock))) {
b63b70d8
SP
1055 if (n == neigh) {
1056 /* found */
1057 rcu_assign_pointer(*np,
1058 rcu_dereference_protected(neigh->hnext,
b5120a6e 1059 lockdep_is_held(&priv->lock)));
b63b70d8 1060 call_rcu(&neigh->rcu, ipoib_neigh_reclaim);
b5120a6e 1061 return;
b63b70d8
SP
1062 } else {
1063 np = &n->hnext;
1064 }
1065 }
b63b70d8
SP
1066}
1067
1068static int ipoib_neigh_hash_init(struct ipoib_dev_priv *priv)
1069{
1070 struct ipoib_neigh_table *ntbl = &priv->ntbl;
1071 struct ipoib_neigh_hash *htbl;
1072 struct ipoib_neigh **buckets;
1073 u32 size;
1074
1075 clear_bit(IPOIB_NEIGH_TBL_FLUSH, &priv->flags);
1076 ntbl->htbl = NULL;
b63b70d8
SP
1077 htbl = kzalloc(sizeof(*htbl), GFP_KERNEL);
1078 if (!htbl)
1079 return -ENOMEM;
1080 set_bit(IPOIB_STOP_NEIGH_GC, &priv->flags);
1081 size = roundup_pow_of_two(arp_tbl.gc_thresh3);
1082 buckets = kzalloc(size * sizeof(*buckets), GFP_KERNEL);
1083 if (!buckets) {
1084 kfree(htbl);
1085 return -ENOMEM;
1086 }
1087 htbl->size = size;
1088 htbl->mask = (size - 1);
1089 htbl->buckets = buckets;
1090 ntbl->htbl = htbl;
66172c09 1091 htbl->ntbl = ntbl;
b63b70d8
SP
1092 atomic_set(&ntbl->entries, 0);
1093
1094 /* start garbage collection */
1095 clear_bit(IPOIB_STOP_NEIGH_GC, &priv->flags);
1096 queue_delayed_work(ipoib_workqueue, &priv->neigh_reap_task,
1097 arp_tbl.gc_interval);
1da177e4
LT
1098
1099 return 0;
1100}
1101
b63b70d8
SP
1102static void neigh_hash_free_rcu(struct rcu_head *head)
1103{
1104 struct ipoib_neigh_hash *htbl = container_of(head,
1105 struct ipoib_neigh_hash,
1106 rcu);
1107 struct ipoib_neigh __rcu **buckets = htbl->buckets;
66172c09 1108 struct ipoib_neigh_table *ntbl = htbl->ntbl;
b63b70d8
SP
1109
1110 kfree(buckets);
1111 kfree(htbl);
66172c09 1112 complete(&ntbl->deleted);
b63b70d8
SP
1113}
1114
1115void ipoib_del_neighs_by_gid(struct net_device *dev, u8 *gid)
1116{
1117 struct ipoib_dev_priv *priv = netdev_priv(dev);
1118 struct ipoib_neigh_table *ntbl = &priv->ntbl;
1119 struct ipoib_neigh_hash *htbl;
1120 unsigned long flags;
1121 int i;
1122
1123 /* remove all neigh connected to a given path or mcast */
b5120a6e 1124 spin_lock_irqsave(&priv->lock, flags);
b63b70d8
SP
1125
1126 htbl = rcu_dereference_protected(ntbl->htbl,
b5120a6e 1127 lockdep_is_held(&priv->lock));
b63b70d8
SP
1128
1129 if (!htbl)
1130 goto out_unlock;
1131
1132 for (i = 0; i < htbl->size; i++) {
1133 struct ipoib_neigh *neigh;
1134 struct ipoib_neigh __rcu **np = &htbl->buckets[i];
1135
1136 while ((neigh = rcu_dereference_protected(*np,
b5120a6e 1137 lockdep_is_held(&priv->lock))) != NULL) {
b63b70d8
SP
1138 /* delete neighs belong to this parent */
1139 if (!memcmp(gid, neigh->daddr + 4, sizeof (union ib_gid))) {
1140 rcu_assign_pointer(*np,
1141 rcu_dereference_protected(neigh->hnext,
b5120a6e 1142 lockdep_is_held(&priv->lock)));
b63b70d8 1143 /* remove from parent list */
b63b70d8 1144 list_del(&neigh->list);
b63b70d8
SP
1145 call_rcu(&neigh->rcu, ipoib_neigh_reclaim);
1146 } else {
1147 np = &neigh->hnext;
1148 }
1149
1150 }
1151 }
1152out_unlock:
b5120a6e 1153 spin_unlock_irqrestore(&priv->lock, flags);
b63b70d8
SP
1154}
1155
1156static void ipoib_flush_neighs(struct ipoib_dev_priv *priv)
1157{
1158 struct ipoib_neigh_table *ntbl = &priv->ntbl;
1159 struct ipoib_neigh_hash *htbl;
1160 unsigned long flags;
66172c09 1161 int i, wait_flushed = 0;
b63b70d8 1162
66172c09 1163 init_completion(&priv->ntbl.flushed);
b63b70d8 1164
b5120a6e 1165 spin_lock_irqsave(&priv->lock, flags);
b63b70d8
SP
1166
1167 htbl = rcu_dereference_protected(ntbl->htbl,
b5120a6e 1168 lockdep_is_held(&priv->lock));
b63b70d8
SP
1169 if (!htbl)
1170 goto out_unlock;
1171
66172c09
SP
1172 wait_flushed = atomic_read(&priv->ntbl.entries);
1173 if (!wait_flushed)
1174 goto free_htbl;
1175
b63b70d8
SP
1176 for (i = 0; i < htbl->size; i++) {
1177 struct ipoib_neigh *neigh;
1178 struct ipoib_neigh __rcu **np = &htbl->buckets[i];
1179
1180 while ((neigh = rcu_dereference_protected(*np,
b5120a6e 1181 lockdep_is_held(&priv->lock))) != NULL) {
b63b70d8
SP
1182 rcu_assign_pointer(*np,
1183 rcu_dereference_protected(neigh->hnext,
b5120a6e 1184 lockdep_is_held(&priv->lock)));
b63b70d8 1185 /* remove from path/mc list */
b63b70d8 1186 list_del(&neigh->list);
b63b70d8
SP
1187 call_rcu(&neigh->rcu, ipoib_neigh_reclaim);
1188 }
1189 }
1190
66172c09 1191free_htbl:
b63b70d8
SP
1192 rcu_assign_pointer(ntbl->htbl, NULL);
1193 call_rcu(&htbl->rcu, neigh_hash_free_rcu);
1194
1195out_unlock:
b5120a6e 1196 spin_unlock_irqrestore(&priv->lock, flags);
66172c09
SP
1197 if (wait_flushed)
1198 wait_for_completion(&priv->ntbl.flushed);
b63b70d8
SP
1199}
1200
1201static void ipoib_neigh_hash_uninit(struct net_device *dev)
1202{
1203 struct ipoib_dev_priv *priv = netdev_priv(dev);
1204 int stopped;
1205
1206 ipoib_dbg(priv, "ipoib_neigh_hash_uninit\n");
66172c09 1207 init_completion(&priv->ntbl.deleted);
b63b70d8
SP
1208 set_bit(IPOIB_NEIGH_TBL_FLUSH, &priv->flags);
1209
1210 /* Stop GC if called at init fail need to cancel work */
1211 stopped = test_and_set_bit(IPOIB_STOP_NEIGH_GC, &priv->flags);
1212 if (!stopped)
1213 cancel_delayed_work(&priv->neigh_reap_task);
1214
66172c09
SP
1215 ipoib_flush_neighs(priv);
1216
1217 wait_for_completion(&priv->ntbl.deleted);
b63b70d8
SP
1218}
1219
1220
1da177e4
LT
1221int ipoib_dev_init(struct net_device *dev, struct ib_device *ca, int port)
1222{
1223 struct ipoib_dev_priv *priv = netdev_priv(dev);
1224
b63b70d8
SP
1225 if (ipoib_neigh_hash_init(priv) < 0)
1226 goto out;
1da177e4 1227 /* Allocate RX/TX "rings" to hold queued skbs */
0f485251 1228 priv->rx_ring = kzalloc(ipoib_recvq_size * sizeof *priv->rx_ring,
1da177e4
LT
1229 GFP_KERNEL);
1230 if (!priv->rx_ring) {
1231 printk(KERN_WARNING "%s: failed to allocate RX ring (%d entries)\n",
0f485251 1232 ca->name, ipoib_recvq_size);
b63b70d8 1233 goto out_neigh_hash_cleanup;
1da177e4 1234 }
1da177e4 1235
948579cd 1236 priv->tx_ring = vzalloc(ipoib_sendq_size * sizeof *priv->tx_ring);
1da177e4
LT
1237 if (!priv->tx_ring) {
1238 printk(KERN_WARNING "%s: failed to allocate TX ring (%d entries)\n",
0f485251 1239 ca->name, ipoib_sendq_size);
1da177e4
LT
1240 goto out_rx_ring_cleanup;
1241 }
1da177e4 1242
1b524963 1243 /* priv->tx_head, tx_tail & tx_outstanding are already 0 */
1da177e4
LT
1244
1245 if (ipoib_ib_dev_init(dev, ca, port))
1246 goto out_tx_ring_cleanup;
1247
1248 return 0;
1249
1250out_tx_ring_cleanup:
10313cbb 1251 vfree(priv->tx_ring);
1da177e4
LT
1252
1253out_rx_ring_cleanup:
1254 kfree(priv->rx_ring);
1255
b63b70d8
SP
1256out_neigh_hash_cleanup:
1257 ipoib_neigh_hash_uninit(dev);
1da177e4
LT
1258out:
1259 return -ENOMEM;
1260}
1261
1262void ipoib_dev_cleanup(struct net_device *dev)
1263{
1264 struct ipoib_dev_priv *priv = netdev_priv(dev), *cpriv, *tcpriv;
9baa0b03
OG
1265 LIST_HEAD(head);
1266
1267 ASSERT_RTNL();
1da177e4 1268
1732b0ef 1269 ipoib_delete_debug_files(dev);
1da177e4
LT
1270
1271 /* Delete any child interfaces first */
1272 list_for_each_entry_safe(cpriv, tcpriv, &priv->child_intfs, list) {
b63b70d8
SP
1273 /* Stop GC on child */
1274 set_bit(IPOIB_STOP_NEIGH_GC, &cpriv->flags);
1275 cancel_delayed_work(&cpriv->neigh_reap_task);
9baa0b03 1276 unregister_netdevice_queue(cpriv->dev, &head);
1da177e4 1277 }
9baa0b03 1278 unregister_netdevice_many(&head);
1da177e4
LT
1279
1280 ipoib_ib_dev_cleanup(dev);
1281
92a6b34b 1282 kfree(priv->rx_ring);
10313cbb 1283 vfree(priv->tx_ring);
1da177e4 1284
92a6b34b
HR
1285 priv->rx_ring = NULL;
1286 priv->tx_ring = NULL;
b63b70d8
SP
1287
1288 ipoib_neigh_hash_uninit(dev);
1da177e4
LT
1289}
1290
3b04ddde
SH
1291static const struct header_ops ipoib_header_ops = {
1292 .create = ipoib_hard_header,
1293};
1294
fe8114e8 1295static const struct net_device_ops ipoib_netdev_ops = {
9baa0b03 1296 .ndo_uninit = ipoib_uninit,
fe8114e8
SH
1297 .ndo_open = ipoib_open,
1298 .ndo_stop = ipoib_stop,
1299 .ndo_change_mtu = ipoib_change_mtu,
3d96c74d 1300 .ndo_fix_features = ipoib_fix_features,
fe8114e8
SH
1301 .ndo_start_xmit = ipoib_start_xmit,
1302 .ndo_tx_timeout = ipoib_timeout,
afc4b13d 1303 .ndo_set_rx_mode = ipoib_set_mcast_list,
fe8114e8
SH
1304};
1305
9baa0b03 1306void ipoib_setup(struct net_device *dev)
1da177e4
LT
1307{
1308 struct ipoib_dev_priv *priv = netdev_priv(dev);
1309
fe8114e8 1310 dev->netdev_ops = &ipoib_netdev_ops;
2337f809 1311 dev->header_ops = &ipoib_header_ops;
bea3348e 1312
82c24c18
EC
1313 ipoib_set_ethtool_ops(dev);
1314
bea3348e 1315 netif_napi_add(dev, &priv->napi, ipoib_poll, 100);
1da177e4 1316
2337f809 1317 dev->watchdog_timeo = HZ;
1da177e4 1318
2337f809 1319 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
1da177e4 1320
936d7de3 1321 dev->hard_header_len = IPOIB_ENCAP_LEN;
2337f809
RD
1322 dev->addr_len = INFINIBAND_ALEN;
1323 dev->type = ARPHRD_INFINIBAND;
1324 dev->tx_queue_len = ipoib_sendq_size * 2;
eb14032f 1325 dev->features = (NETIF_F_VLAN_CHALLENGED |
eb14032f 1326 NETIF_F_HIGHDMA);
86d15cd8 1327 dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
1da177e4 1328
1da177e4
LT
1329 memcpy(dev->broadcast, ipv4_bcast_addr, INFINIBAND_ALEN);
1330
1331 netif_carrier_off(dev);
1332
1da177e4
LT
1333 priv->dev = dev;
1334
1335 spin_lock_init(&priv->lock);
1da177e4 1336
95ed644f 1337 mutex_init(&priv->vlan_mutex);
1da177e4
LT
1338
1339 INIT_LIST_HEAD(&priv->path_list);
1340 INIT_LIST_HEAD(&priv->child_intfs);
1341 INIT_LIST_HEAD(&priv->dead_ahs);
1342 INIT_LIST_HEAD(&priv->multicast_list);
1343
26bbf13c 1344 INIT_DELAYED_WORK(&priv->pkey_poll_task, ipoib_pkey_poll);
c4028958 1345 INIT_DELAYED_WORK(&priv->mcast_task, ipoib_mcast_join_task);
e8224e4b 1346 INIT_WORK(&priv->carrier_on_task, ipoib_mcast_carrier_on_task);
ee1e2c82
MS
1347 INIT_WORK(&priv->flush_light, ipoib_ib_dev_flush_light);
1348 INIT_WORK(&priv->flush_normal, ipoib_ib_dev_flush_normal);
1349 INIT_WORK(&priv->flush_heavy, ipoib_ib_dev_flush_heavy);
c4028958
DH
1350 INIT_WORK(&priv->restart_task, ipoib_mcast_restart_task);
1351 INIT_DELAYED_WORK(&priv->ah_reap_task, ipoib_reap_ah);
b63b70d8 1352 INIT_DELAYED_WORK(&priv->neigh_reap_task, ipoib_reap_neigh);
1da177e4
LT
1353}
1354
1355struct ipoib_dev_priv *ipoib_intf_alloc(const char *name)
1356{
1357 struct net_device *dev;
1358
1359 dev = alloc_netdev((int) sizeof (struct ipoib_dev_priv), name,
1360 ipoib_setup);
1361 if (!dev)
1362 return NULL;
1363
1364 return netdev_priv(dev);
1365}
1366
43cb76d9
GKH
1367static ssize_t show_pkey(struct device *dev,
1368 struct device_attribute *attr, char *buf)
1da177e4 1369{
43cb76d9 1370 struct ipoib_dev_priv *priv = netdev_priv(to_net_dev(dev));
1da177e4
LT
1371
1372 return sprintf(buf, "0x%04x\n", priv->pkey);
1373}
43cb76d9 1374static DEVICE_ATTR(pkey, S_IRUGO, show_pkey, NULL);
1da177e4 1375
335a64a5
OG
1376static ssize_t show_umcast(struct device *dev,
1377 struct device_attribute *attr, char *buf)
1378{
1379 struct ipoib_dev_priv *priv = netdev_priv(to_net_dev(dev));
1380
1381 return sprintf(buf, "%d\n", test_bit(IPOIB_FLAG_UMCAST, &priv->flags));
1382}
1383
862096a8 1384void ipoib_set_umcast(struct net_device *ndev, int umcast_val)
335a64a5 1385{
862096a8 1386 struct ipoib_dev_priv *priv = netdev_priv(ndev);
335a64a5
OG
1387
1388 if (umcast_val > 0) {
1389 set_bit(IPOIB_FLAG_UMCAST, &priv->flags);
1390 ipoib_warn(priv, "ignoring multicast groups joined directly "
1391 "by userspace\n");
1392 } else
1393 clear_bit(IPOIB_FLAG_UMCAST, &priv->flags);
862096a8
OG
1394}
1395
1396static ssize_t set_umcast(struct device *dev,
1397 struct device_attribute *attr,
1398 const char *buf, size_t count)
1399{
1400 unsigned long umcast_val = simple_strtoul(buf, NULL, 0);
1401
1402 ipoib_set_umcast(to_net_dev(dev), umcast_val);
335a64a5
OG
1403
1404 return count;
1405}
1406static DEVICE_ATTR(umcast, S_IWUSR | S_IRUGO, show_umcast, set_umcast);
1407
1408int ipoib_add_umcast_attr(struct net_device *dev)
1409{
1410 return device_create_file(&dev->dev, &dev_attr_umcast);
1411}
1412
43cb76d9
GKH
1413static ssize_t create_child(struct device *dev,
1414 struct device_attribute *attr,
1da177e4
LT
1415 const char *buf, size_t count)
1416{
1417 int pkey;
1418 int ret;
1419
1420 if (sscanf(buf, "%i", &pkey) != 1)
1421 return -EINVAL;
1422
1423 if (pkey < 0 || pkey > 0xffff)
1424 return -EINVAL;
1425
4ce05937
RD
1426 /*
1427 * Set the full membership bit, so that we join the right
1428 * broadcast group, etc.
1429 */
1430 pkey |= 0x8000;
1431
43cb76d9 1432 ret = ipoib_vlan_add(to_net_dev(dev), pkey);
1da177e4
LT
1433
1434 return ret ? ret : count;
1435}
7a52b34b 1436static DEVICE_ATTR(create_child, S_IWUSR, NULL, create_child);
1da177e4 1437
43cb76d9
GKH
1438static ssize_t delete_child(struct device *dev,
1439 struct device_attribute *attr,
1da177e4
LT
1440 const char *buf, size_t count)
1441{
1442 int pkey;
1443 int ret;
1444
1445 if (sscanf(buf, "%i", &pkey) != 1)
1446 return -EINVAL;
1447
1448 if (pkey < 0 || pkey > 0xffff)
1449 return -EINVAL;
1450
43cb76d9 1451 ret = ipoib_vlan_delete(to_net_dev(dev), pkey);
1da177e4
LT
1452
1453 return ret ? ret : count;
1454
1455}
7a52b34b 1456static DEVICE_ATTR(delete_child, S_IWUSR, NULL, delete_child);
1da177e4
LT
1457
1458int ipoib_add_pkey_attr(struct net_device *dev)
1459{
43cb76d9 1460 return device_create_file(&dev->dev, &dev_attr_pkey);
1da177e4
LT
1461}
1462
83bb63f6
OG
1463int ipoib_set_dev_features(struct ipoib_dev_priv *priv, struct ib_device *hca)
1464{
1465 struct ib_device_attr *device_attr;
1466 int result = -ENOMEM;
1467
1468 device_attr = kmalloc(sizeof *device_attr, GFP_KERNEL);
1469 if (!device_attr) {
1470 printk(KERN_WARNING "%s: allocation of %zu bytes failed\n",
1471 hca->name, sizeof *device_attr);
1472 return result;
1473 }
1474
1475 result = ib_query_device(hca, device_attr);
1476 if (result) {
1477 printk(KERN_WARNING "%s: ib_query_device failed (ret = %d)\n",
1478 hca->name, result);
1479 kfree(device_attr);
1480 return result;
1481 }
1482 priv->hca_caps = device_attr->device_cap_flags;
1483
1484 kfree(device_attr);
1485
1486 if (priv->hca_caps & IB_DEVICE_UD_IP_CSUM) {
3d96c74d
MM
1487 priv->dev->hw_features = NETIF_F_SG |
1488 NETIF_F_IP_CSUM | NETIF_F_RXCSUM;
83bb63f6 1489
3d96c74d
MM
1490 if (priv->hca_caps & IB_DEVICE_UD_TSO)
1491 priv->dev->hw_features |= NETIF_F_TSO;
8ae31e5b 1492
3d96c74d
MM
1493 priv->dev->features |= priv->dev->hw_features;
1494 }
83bb63f6
OG
1495
1496 return 0;
1497}
1498
1da177e4
LT
1499static struct net_device *ipoib_add_port(const char *format,
1500 struct ib_device *hca, u8 port)
1501{
1502 struct ipoib_dev_priv *priv;
bc7b3a36 1503 struct ib_port_attr attr;
1da177e4
LT
1504 int result = -ENOMEM;
1505
1506 priv = ipoib_intf_alloc(format);
1507 if (!priv)
1508 goto alloc_mem_failed;
1509
1510 SET_NETDEV_DEV(priv->dev, hca->dma_device);
c3aa9b18 1511 priv->dev->dev_id = port - 1;
1da177e4 1512
bc7b3a36
SM
1513 if (!ib_query_port(hca, port, &attr))
1514 priv->max_ib_mtu = ib_mtu_enum_to_int(attr.max_mtu);
1515 else {
1516 printk(KERN_WARNING "%s: ib_query_port %d failed\n",
1517 hca->name, port);
1518 goto device_init_failed;
1519 }
1520
1521 /* MTU will be reset when mcast join happens */
1522 priv->dev->mtu = IPOIB_UD_MTU(priv->max_ib_mtu);
1523 priv->mcast_mtu = priv->admin_mtu = priv->dev->mtu;
1524
596b9b68
DM
1525 priv->dev->neigh_priv_len = sizeof(struct ipoib_neigh);
1526
1da177e4
LT
1527 result = ib_query_pkey(hca, port, 0, &priv->pkey);
1528 if (result) {
1529 printk(KERN_WARNING "%s: ib_query_pkey port %d failed (ret = %d)\n",
1530 hca->name, port, result);
ca6de177 1531 goto device_init_failed;
1da177e4
LT
1532 }
1533
83bb63f6 1534 if (ipoib_set_dev_features(priv, hca))
6046136c 1535 goto device_init_failed;
af40da89 1536
4ce05937
RD
1537 /*
1538 * Set the full membership bit, so that we join the right
1539 * broadcast group, etc.
1540 */
1541 priv->pkey |= 0x8000;
1542
1da177e4
LT
1543 priv->dev->broadcast[8] = priv->pkey >> 8;
1544 priv->dev->broadcast[9] = priv->pkey & 0xff;
1545
1546 result = ib_query_gid(hca, port, 0, &priv->local_gid);
1547 if (result) {
1548 printk(KERN_WARNING "%s: ib_query_gid port %d failed (ret = %d)\n",
1549 hca->name, port, result);
ca6de177 1550 goto device_init_failed;
1da177e4
LT
1551 } else
1552 memcpy(priv->dev->dev_addr + 4, priv->local_gid.raw, sizeof (union ib_gid));
1553
1da177e4
LT
1554 result = ipoib_dev_init(priv->dev, hca, port);
1555 if (result < 0) {
1556 printk(KERN_WARNING "%s: failed to initialize port %d (ret = %d)\n",
1557 hca->name, port, result);
1558 goto device_init_failed;
1559 }
1560
1561 INIT_IB_EVENT_HANDLER(&priv->event_handler,
1562 priv->ca, ipoib_event);
1563 result = ib_register_event_handler(&priv->event_handler);
1564 if (result < 0) {
1565 printk(KERN_WARNING "%s: ib_register_event_handler failed for "
1566 "port %d (ret = %d)\n",
1567 hca->name, port, result);
1568 goto event_failed;
1569 }
1570
1571 result = register_netdev(priv->dev);
1572 if (result) {
1573 printk(KERN_WARNING "%s: couldn't register ipoib port %d; error %d\n",
1574 hca->name, port, result);
1575 goto register_failed;
1576 }
1577
1732b0ef 1578 ipoib_create_debug_files(priv->dev);
1da177e4 1579
839fcaba
MT
1580 if (ipoib_cm_add_mode_attr(priv->dev))
1581 goto sysfs_failed;
1da177e4
LT
1582 if (ipoib_add_pkey_attr(priv->dev))
1583 goto sysfs_failed;
335a64a5
OG
1584 if (ipoib_add_umcast_attr(priv->dev))
1585 goto sysfs_failed;
43cb76d9 1586 if (device_create_file(&priv->dev->dev, &dev_attr_create_child))
1da177e4 1587 goto sysfs_failed;
43cb76d9 1588 if (device_create_file(&priv->dev->dev, &dev_attr_delete_child))
1da177e4
LT
1589 goto sysfs_failed;
1590
1591 return priv->dev;
1592
1593sysfs_failed:
1732b0ef 1594 ipoib_delete_debug_files(priv->dev);
1da177e4
LT
1595 unregister_netdev(priv->dev);
1596
1597register_failed:
1598 ib_unregister_event_handler(&priv->event_handler);
b63b70d8
SP
1599 /* Stop GC if started before flush */
1600 set_bit(IPOIB_STOP_NEIGH_GC, &priv->flags);
1601 cancel_delayed_work(&priv->neigh_reap_task);
a77a57a1 1602 flush_workqueue(ipoib_workqueue);
1da177e4
LT
1603
1604event_failed:
1605 ipoib_dev_cleanup(priv->dev);
1606
1607device_init_failed:
1608 free_netdev(priv->dev);
1609
1610alloc_mem_failed:
1611 return ERR_PTR(result);
1612}
1613
1614static void ipoib_add_one(struct ib_device *device)
1615{
1616 struct list_head *dev_list;
1617 struct net_device *dev;
1618 struct ipoib_dev_priv *priv;
1619 int s, e, p;
1620
07ebafba
TT
1621 if (rdma_node_get_transport(device->node_type) != RDMA_TRANSPORT_IB)
1622 return;
1623
1da177e4
LT
1624 dev_list = kmalloc(sizeof *dev_list, GFP_KERNEL);
1625 if (!dev_list)
1626 return;
1627
1628 INIT_LIST_HEAD(dev_list);
1629
07ebafba 1630 if (device->node_type == RDMA_NODE_IB_SWITCH) {
1da177e4
LT
1631 s = 0;
1632 e = 0;
1633 } else {
1634 s = 1;
1635 e = device->phys_port_cnt;
1636 }
1637
1638 for (p = s; p <= e; ++p) {
7b4c8769
EC
1639 if (rdma_port_get_link_layer(device, p) != IB_LINK_LAYER_INFINIBAND)
1640 continue;
1da177e4
LT
1641 dev = ipoib_add_port("ib%d", device, p);
1642 if (!IS_ERR(dev)) {
1643 priv = netdev_priv(dev);
1644 list_add_tail(&priv->list, dev_list);
1645 }
1646 }
1647
1648 ib_set_client_data(device, &ipoib_client, dev_list);
1649}
1650
1651static void ipoib_remove_one(struct ib_device *device)
1652{
1653 struct ipoib_dev_priv *priv, *tmp;
1654 struct list_head *dev_list;
1655
07ebafba
TT
1656 if (rdma_node_get_transport(device->node_type) != RDMA_TRANSPORT_IB)
1657 return;
1658
1da177e4
LT
1659 dev_list = ib_get_client_data(device, &ipoib_client);
1660
1661 list_for_each_entry_safe(priv, tmp, dev_list, list) {
1662 ib_unregister_event_handler(&priv->event_handler);
a77a57a1
RD
1663
1664 rtnl_lock();
1665 dev_change_flags(priv->dev, priv->dev->flags & ~IFF_UP);
1666 rtnl_unlock();
1667
b63b70d8
SP
1668 /* Stop GC */
1669 set_bit(IPOIB_STOP_NEIGH_GC, &priv->flags);
1670 cancel_delayed_work(&priv->neigh_reap_task);
a77a57a1 1671 flush_workqueue(ipoib_workqueue);
1da177e4
LT
1672
1673 unregister_netdev(priv->dev);
1da177e4
LT
1674 free_netdev(priv->dev);
1675 }
06c56e44
MT
1676
1677 kfree(dev_list);
1da177e4
LT
1678}
1679
1680static int __init ipoib_init_module(void)
1681{
1682 int ret;
1683
0f485251
SM
1684 ipoib_recvq_size = roundup_pow_of_two(ipoib_recvq_size);
1685 ipoib_recvq_size = min(ipoib_recvq_size, IPOIB_MAX_QUEUE_SIZE);
1686 ipoib_recvq_size = max(ipoib_recvq_size, IPOIB_MIN_QUEUE_SIZE);
1687
1688 ipoib_sendq_size = roundup_pow_of_two(ipoib_sendq_size);
1689 ipoib_sendq_size = min(ipoib_sendq_size, IPOIB_MAX_QUEUE_SIZE);
732eacc0 1690 ipoib_sendq_size = max3(ipoib_sendq_size, 2 * MAX_SEND_CQE, IPOIB_MIN_QUEUE_SIZE);
68e995a2
PS
1691#ifdef CONFIG_INFINIBAND_IPOIB_CM
1692 ipoib_max_conn_qp = min(ipoib_max_conn_qp, IPOIB_CM_MAX_CONN_QP);
1693#endif
0f485251 1694
f89271da
EC
1695 /*
1696 * When copying small received packets, we only copy from the
1697 * linear data part of the SKB, so we rely on this condition.
1698 */
1699 BUILD_BUG_ON(IPOIB_CM_COPYBREAK > IPOIB_CM_HEAD_SIZE);
1700
1da177e4
LT
1701 ret = ipoib_register_debugfs();
1702 if (ret)
1703 return ret;
1704
1705 /*
1706 * We create our own workqueue mainly because we want to be
1707 * able to flush it when devices are being removed. We can't
1708 * use schedule_work()/flush_scheduled_work() because both
1709 * unregister_netdev() and linkwatch_event take the rtnl lock,
1710 * so flush_scheduled_work() can deadlock during device
1711 * removal.
1712 */
1713 ipoib_workqueue = create_singlethread_workqueue("ipoib");
1714 if (!ipoib_workqueue) {
1715 ret = -ENOMEM;
1716 goto err_fs;
1717 }
1718
c1a0b23b
MT
1719 ib_sa_register_client(&ipoib_sa_client);
1720
1da177e4
LT
1721 ret = ib_register_client(&ipoib_client);
1722 if (ret)
c1a0b23b 1723 goto err_sa;
1da177e4 1724
9baa0b03
OG
1725 ret = ipoib_netlink_init();
1726 if (ret)
1727 goto err_client;
1728
1da177e4
LT
1729 return 0;
1730
9baa0b03
OG
1731err_client:
1732 ib_unregister_client(&ipoib_client);
1733
c1a0b23b
MT
1734err_sa:
1735 ib_sa_unregister_client(&ipoib_sa_client);
1da177e4
LT
1736 destroy_workqueue(ipoib_workqueue);
1737
9adec1a8
RD
1738err_fs:
1739 ipoib_unregister_debugfs();
1740
1da177e4
LT
1741 return ret;
1742}
1743
1744static void __exit ipoib_cleanup_module(void)
1745{
9baa0b03 1746 ipoib_netlink_fini();
1da177e4 1747 ib_unregister_client(&ipoib_client);
c1a0b23b 1748 ib_sa_unregister_client(&ipoib_sa_client);
9adec1a8 1749 ipoib_unregister_debugfs();
1da177e4
LT
1750 destroy_workqueue(ipoib_workqueue);
1751}
1752
1753module_init(ipoib_init_module);
1754module_exit(ipoib_cleanup_module);
This page took 1.380188 seconds and 5 git commands to generate.