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.
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:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
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.
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
37 #include <linux/module.h>
39 #include <linux/init.h>
40 #include <linux/slab.h>
41 #include <linux/kernel.h>
42 #include <linux/vmalloc.h>
44 #include <linux/if_arp.h> /* For ARPHRD_xxx */
49 #include <linux/jhash.h>
52 MODULE_AUTHOR("Roland Dreier");
53 MODULE_DESCRIPTION("IP-over-InfiniBand net driver");
54 MODULE_LICENSE("Dual BSD/GPL");
56 int ipoib_sendq_size __read_mostly = IPOIB_TX_RING_SIZE;
57 int ipoib_recvq_size __read_mostly = IPOIB_RX_RING_SIZE;
59 module_param_named(send_queue_size, ipoib_sendq_size, int, 0444);
60 MODULE_PARM_DESC(send_queue_size, "Number of descriptors in send queue");
61 module_param_named(recv_queue_size, ipoib_recvq_size, int, 0444);
62 MODULE_PARM_DESC(recv_queue_size, "Number of descriptors in receive queue");
64 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
65 int ipoib_debug_level;
67 module_param_named(debug_level, ipoib_debug_level, int, 0644);
68 MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0");
71 struct ipoib_path_iter {
72 struct net_device *dev;
73 struct ipoib_path path;
76 static 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
82 struct workqueue_struct *ipoib_workqueue;
84 struct ib_sa_client ipoib_sa_client;
86 static void ipoib_add_one(struct ib_device *device);
87 static void ipoib_remove_one(struct ib_device *device);
88 static void ipoib_neigh_reclaim(struct rcu_head *rp);
90 static struct ib_client ipoib_client = {
93 .remove = ipoib_remove_one
96 int ipoib_open(struct net_device *dev)
98 struct ipoib_dev_priv *priv = netdev_priv(dev);
100 ipoib_dbg(priv, "bringing up interface\n");
102 set_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags);
104 if (ipoib_pkey_dev_delay_open(dev))
107 if (ipoib_ib_dev_open(dev))
110 if (ipoib_ib_dev_up(dev))
113 if (!test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags)) {
114 struct ipoib_dev_priv *cpriv;
116 /* Bring up any child interfaces too */
117 mutex_lock(&priv->vlan_mutex);
118 list_for_each_entry(cpriv, &priv->child_intfs, list) {
121 flags = cpriv->dev->flags;
125 dev_change_flags(cpriv->dev, flags | IFF_UP);
127 mutex_unlock(&priv->vlan_mutex);
130 netif_start_queue(dev);
135 ipoib_ib_dev_stop(dev, 1);
138 clear_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags);
143 static int ipoib_stop(struct net_device *dev)
145 struct ipoib_dev_priv *priv = netdev_priv(dev);
147 ipoib_dbg(priv, "stopping interface\n");
149 clear_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags);
151 netif_stop_queue(dev);
153 ipoib_ib_dev_down(dev, 1);
154 ipoib_ib_dev_stop(dev, 0);
156 if (!test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags)) {
157 struct ipoib_dev_priv *cpriv;
159 /* Bring down any child interfaces too */
160 mutex_lock(&priv->vlan_mutex);
161 list_for_each_entry(cpriv, &priv->child_intfs, list) {
164 flags = cpriv->dev->flags;
165 if (!(flags & IFF_UP))
168 dev_change_flags(cpriv->dev, flags & ~IFF_UP);
170 mutex_unlock(&priv->vlan_mutex);
176 static void ipoib_uninit(struct net_device *dev)
178 ipoib_dev_cleanup(dev);
181 static netdev_features_t ipoib_fix_features(struct net_device *dev, netdev_features_t features)
183 struct ipoib_dev_priv *priv = netdev_priv(dev);
185 if (test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags))
186 features &= ~(NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
191 static int ipoib_change_mtu(struct net_device *dev, int new_mtu)
193 struct ipoib_dev_priv *priv = netdev_priv(dev);
195 /* dev->mtu > 2K ==> connected mode */
196 if (ipoib_cm_admin_enabled(dev)) {
197 if (new_mtu > ipoib_cm_max_mtu(dev))
200 if (new_mtu > priv->mcast_mtu)
201 ipoib_warn(priv, "mtu > %d will cause multicast packet drops.\n",
208 if (new_mtu > IPOIB_UD_MTU(priv->max_ib_mtu))
211 priv->admin_mtu = new_mtu;
213 dev->mtu = min(priv->mcast_mtu, priv->admin_mtu);
218 static struct ipoib_path *__path_find(struct net_device *dev, void *gid)
220 struct ipoib_dev_priv *priv = netdev_priv(dev);
221 struct rb_node *n = priv->path_tree.rb_node;
222 struct ipoib_path *path;
226 path = rb_entry(n, struct ipoib_path, rb_node);
228 ret = memcmp(gid, path->pathrec.dgid.raw,
229 sizeof (union ib_gid));
242 static int __path_add(struct net_device *dev, struct ipoib_path *path)
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;
252 tpath = rb_entry(pn, struct ipoib_path, rb_node);
254 ret = memcmp(path->pathrec.dgid.raw, tpath->pathrec.dgid.raw,
255 sizeof (union ib_gid));
264 rb_link_node(&path->rb_node, pn, n);
265 rb_insert_color(&path->rb_node, &priv->path_tree);
267 list_add_tail(&path->list, &priv->path_list);
272 static void path_free(struct net_device *dev, struct ipoib_path *path)
276 while ((skb = __skb_dequeue(&path->queue)))
277 dev_kfree_skb_irq(skb);
279 ipoib_dbg(netdev_priv(dev), "path_free\n");
281 /* remove all neigh connected to this path */
282 ipoib_del_neighs_by_gid(dev, path->pathrec.dgid.raw);
285 ipoib_put_ah(path->ah);
290 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
292 struct ipoib_path_iter *ipoib_path_iter_init(struct net_device *dev)
294 struct ipoib_path_iter *iter;
296 iter = kmalloc(sizeof *iter, GFP_KERNEL);
301 memset(iter->path.pathrec.dgid.raw, 0, 16);
303 if (ipoib_path_iter_next(iter)) {
311 int ipoib_path_iter_next(struct ipoib_path_iter *iter)
313 struct ipoib_dev_priv *priv = netdev_priv(iter->dev);
315 struct ipoib_path *path;
318 spin_lock_irq(&priv->lock);
320 n = rb_first(&priv->path_tree);
323 path = rb_entry(n, struct ipoib_path, rb_node);
325 if (memcmp(iter->path.pathrec.dgid.raw, path->pathrec.dgid.raw,
326 sizeof (union ib_gid)) < 0) {
335 spin_unlock_irq(&priv->lock);
340 void ipoib_path_iter_read(struct ipoib_path_iter *iter,
341 struct ipoib_path *path)
346 #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG */
348 void ipoib_mark_paths_invalid(struct net_device *dev)
350 struct ipoib_dev_priv *priv = netdev_priv(dev);
351 struct ipoib_path *path, *tp;
353 spin_lock_irq(&priv->lock);
355 list_for_each_entry_safe(path, tp, &priv->path_list, list) {
356 ipoib_dbg(priv, "mark path LID 0x%04x GID %pI6 invalid\n",
357 be16_to_cpu(path->pathrec.dlid),
358 path->pathrec.dgid.raw);
362 spin_unlock_irq(&priv->lock);
365 void ipoib_flush_paths(struct net_device *dev)
367 struct ipoib_dev_priv *priv = netdev_priv(dev);
368 struct ipoib_path *path, *tp;
369 LIST_HEAD(remove_list);
372 netif_tx_lock_bh(dev);
373 spin_lock_irqsave(&priv->lock, flags);
375 list_splice_init(&priv->path_list, &remove_list);
377 list_for_each_entry(path, &remove_list, list)
378 rb_erase(&path->rb_node, &priv->path_tree);
380 list_for_each_entry_safe(path, tp, &remove_list, list) {
382 ib_sa_cancel_query(path->query_id, path->query);
383 spin_unlock_irqrestore(&priv->lock, flags);
384 netif_tx_unlock_bh(dev);
385 wait_for_completion(&path->done);
386 path_free(dev, path);
387 netif_tx_lock_bh(dev);
388 spin_lock_irqsave(&priv->lock, flags);
391 spin_unlock_irqrestore(&priv->lock, flags);
392 netif_tx_unlock_bh(dev);
395 static void path_rec_completion(int status,
396 struct ib_sa_path_rec *pathrec,
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;
403 struct ipoib_ah *old_ah = NULL;
404 struct ipoib_neigh *neigh, *tn;
405 struct sk_buff_head skqueue;
410 ipoib_dbg(priv, "PathRec LID 0x%04x for GID %pI6\n",
411 be16_to_cpu(pathrec->dlid), pathrec->dgid.raw);
413 ipoib_dbg(priv, "PathRec status %d for GID %pI6\n",
414 status, path->pathrec.dgid.raw);
416 skb_queue_head_init(&skqueue);
419 struct ib_ah_attr av;
421 if (!ib_init_ah_from_path(priv->ca, priv->port, pathrec, &av))
422 ah = ipoib_create_ah(dev, priv->pd, &av);
425 spin_lock_irqsave(&priv->lock, flags);
427 if (!IS_ERR_OR_NULL(ah)) {
428 path->pathrec = *pathrec;
433 ipoib_dbg(priv, "created address handle %p for LID 0x%04x, SL %d\n",
434 ah, be16_to_cpu(pathrec->dlid), pathrec->sl);
436 while ((skb = __skb_dequeue(&path->queue)))
437 __skb_queue_tail(&skqueue, skb);
439 list_for_each_entry_safe(neigh, tn, &path->neigh_list, list) {
441 WARN_ON(neigh->ah != old_ah);
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
449 ipoib_put_ah(neigh->ah);
451 kref_get(&path->ah->ref);
452 neigh->ah = path->ah;
454 if (ipoib_cm_enabled(dev, neigh->daddr)) {
455 if (!ipoib_cm_get(neigh))
456 ipoib_cm_set(neigh, ipoib_cm_create_tx(dev,
459 if (!ipoib_cm_get(neigh)) {
460 list_del(&neigh->list);
461 ipoib_neigh_free(neigh);
466 while ((skb = __skb_dequeue(&neigh->queue)))
467 __skb_queue_tail(&skqueue, skb);
473 complete(&path->done);
475 spin_unlock_irqrestore(&priv->lock, flags);
478 ipoib_put_ah(old_ah);
480 while ((skb = __skb_dequeue(&skqueue))) {
482 if (dev_queue_xmit(skb))
483 ipoib_warn(priv, "dev_queue_xmit failed "
484 "to requeue packet\n");
488 static struct ipoib_path *path_rec_create(struct net_device *dev, void *gid)
490 struct ipoib_dev_priv *priv = netdev_priv(dev);
491 struct ipoib_path *path;
493 if (!priv->broadcast)
496 path = kzalloc(sizeof *path, GFP_ATOMIC);
502 skb_queue_head_init(&path->queue);
504 INIT_LIST_HEAD(&path->neigh_list);
506 memcpy(path->pathrec.dgid.raw, gid, sizeof (union ib_gid));
507 path->pathrec.sgid = priv->local_gid;
508 path->pathrec.pkey = cpu_to_be16(priv->pkey);
509 path->pathrec.numb_path = 1;
510 path->pathrec.traffic_class = priv->broadcast->mcmember.traffic_class;
515 static int path_rec_start(struct net_device *dev,
516 struct ipoib_path *path)
518 struct ipoib_dev_priv *priv = netdev_priv(dev);
520 ipoib_dbg(priv, "Start path record lookup for %pI6\n",
521 path->pathrec.dgid.raw);
523 init_completion(&path->done);
526 ib_sa_path_rec_get(&ipoib_sa_client, priv->ca, priv->port,
528 IB_SA_PATH_REC_DGID |
529 IB_SA_PATH_REC_SGID |
530 IB_SA_PATH_REC_NUMB_PATH |
531 IB_SA_PATH_REC_TRAFFIC_CLASS |
536 if (path->query_id < 0) {
537 ipoib_warn(priv, "ib_sa_path_rec_get failed: %d\n", path->query_id);
539 complete(&path->done);
540 return path->query_id;
546 static void neigh_add_path(struct sk_buff *skb, u8 *daddr,
547 struct net_device *dev)
549 struct ipoib_dev_priv *priv = netdev_priv(dev);
550 struct ipoib_path *path;
551 struct ipoib_neigh *neigh;
554 spin_lock_irqsave(&priv->lock, flags);
555 neigh = ipoib_neigh_alloc(daddr, dev);
557 spin_unlock_irqrestore(&priv->lock, flags);
558 ++dev->stats.tx_dropped;
559 dev_kfree_skb_any(skb);
563 path = __path_find(dev, daddr + 4);
565 path = path_rec_create(dev, daddr + 4);
569 __path_add(dev, path);
572 list_add_tail(&neigh->list, &path->neigh_list);
575 kref_get(&path->ah->ref);
576 neigh->ah = path->ah;
578 if (ipoib_cm_enabled(dev, neigh->daddr)) {
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);
583 ipoib_neigh_free(neigh);
586 if (skb_queue_len(&neigh->queue) < IPOIB_MAX_PATH_REC_QUEUE)
587 __skb_queue_tail(&neigh->queue, skb);
589 ipoib_warn(priv, "queue length limit %d. Packet drop.\n",
590 skb_queue_len(&neigh->queue));
594 spin_unlock_irqrestore(&priv->lock, flags);
595 ipoib_send(dev, skb, path->ah, IPOIB_QPN(daddr));
596 ipoib_neigh_put(neigh);
602 if (!path->query && path_rec_start(dev, path))
605 __skb_queue_tail(&neigh->queue, skb);
608 spin_unlock_irqrestore(&priv->lock, flags);
609 ipoib_neigh_put(neigh);
613 list_del(&neigh->list);
616 ipoib_neigh_free(neigh);
618 ++dev->stats.tx_dropped;
619 dev_kfree_skb_any(skb);
621 spin_unlock_irqrestore(&priv->lock, flags);
622 ipoib_neigh_put(neigh);
625 static void unicast_arp_send(struct sk_buff *skb, struct net_device *dev,
628 struct ipoib_dev_priv *priv = netdev_priv(dev);
629 struct ipoib_path *path;
632 spin_lock_irqsave(&priv->lock, flags);
634 path = __path_find(dev, cb->hwaddr + 4);
635 if (!path || !path->valid) {
639 path = path_rec_create(dev, cb->hwaddr + 4);
643 __skb_queue_tail(&path->queue, skb);
645 if (!path->query && path_rec_start(dev, path)) {
646 spin_unlock_irqrestore(&priv->lock, flags);
648 path_free(dev, path);
651 __path_add(dev, path);
653 ++dev->stats.tx_dropped;
654 dev_kfree_skb_any(skb);
657 spin_unlock_irqrestore(&priv->lock, flags);
662 ipoib_dbg(priv, "Send unicast ARP to %04x\n",
663 be16_to_cpu(path->pathrec.dlid));
665 spin_unlock_irqrestore(&priv->lock, flags);
666 ipoib_send(dev, skb, path->ah, IPOIB_QPN(cb->hwaddr));
668 } else if ((path->query || !path_rec_start(dev, path)) &&
669 skb_queue_len(&path->queue) < IPOIB_MAX_PATH_REC_QUEUE) {
670 __skb_queue_tail(&path->queue, skb);
672 ++dev->stats.tx_dropped;
673 dev_kfree_skb_any(skb);
676 spin_unlock_irqrestore(&priv->lock, flags);
679 static int ipoib_start_xmit(struct sk_buff *skb, struct net_device *dev)
681 struct ipoib_dev_priv *priv = netdev_priv(dev);
682 struct ipoib_neigh *neigh;
683 struct ipoib_cb *cb = (struct ipoib_cb *) skb->cb;
684 struct ipoib_header *header;
687 header = (struct ipoib_header *) skb->data;
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 */
696 ++dev->stats.tx_dropped;
697 dev_kfree_skb_any(skb);
700 /* Add in the P_Key for multicast*/
701 cb->hwaddr[8] = (priv->pkey >> 8) & 0xff;
702 cb->hwaddr[9] = priv->pkey & 0xff;
704 neigh = ipoib_neigh_get(dev, cb->hwaddr);
706 goto send_using_neigh;
707 ipoib_mcast_send(dev, cb->hwaddr, skb);
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);
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);
727 /* ethertype not supported by IPoIB */
728 ++dev->stats.tx_dropped;
729 dev_kfree_skb_any(skb);
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));
740 } else if (neigh->ah) {
741 ipoib_send(dev, skb, neigh->ah, IPOIB_QPN(cb->hwaddr));
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);
750 ++dev->stats.tx_dropped;
751 dev_kfree_skb_any(skb);
755 ipoib_neigh_put(neigh);
760 static void ipoib_timeout(struct net_device *dev)
762 struct ipoib_dev_priv *priv = netdev_priv(dev);
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);
769 /* XXX reset QP, etc. */
772 static int ipoib_hard_header(struct sk_buff *skb,
773 struct net_device *dev,
775 const void *daddr, const void *saddr, unsigned len)
777 struct ipoib_header *header;
778 struct ipoib_cb *cb = (struct ipoib_cb *) skb->cb;
780 header = (struct ipoib_header *) skb_push(skb, sizeof *header);
782 header->proto = htons(type);
783 header->reserved = 0;
786 * we don't rely on dst_entry structure, always stuff the
787 * destination address into skb->cb so we can figure out where
788 * to send the packet later.
790 memcpy(cb->hwaddr, daddr, INFINIBAND_ALEN);
795 static void ipoib_set_mcast_list(struct net_device *dev)
797 struct ipoib_dev_priv *priv = netdev_priv(dev);
799 if (!test_bit(IPOIB_FLAG_OPER_UP, &priv->flags)) {
800 ipoib_dbg(priv, "IPOIB_FLAG_OPER_UP not set");
804 queue_work(ipoib_workqueue, &priv->restart_task);
807 static u32 ipoib_addr_hash(struct ipoib_neigh_hash *htbl, u8 *daddr)
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
815 /* qpn octets[1:4) & port GUID octets[12:20) */
816 u32 *daddr_32 = (u32 *) daddr;
819 hv = jhash_3words(daddr_32[3], daddr_32[4], 0xFFFFFF & daddr_32[0], 0);
820 return hv & htbl->mask;
823 struct ipoib_neigh *ipoib_neigh_get(struct net_device *dev, u8 *daddr)
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;
833 htbl = rcu_dereference_bh(ntbl->htbl);
838 hash_val = ipoib_addr_hash(htbl, daddr);
839 for (neigh = rcu_dereference_bh(htbl->buckets[hash_val]);
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)) {
849 neigh->alive = jiffies;
855 rcu_read_unlock_bh();
859 static void __ipoib_reap_neigh(struct ipoib_dev_priv *priv)
861 struct ipoib_neigh_table *ntbl = &priv->ntbl;
862 struct ipoib_neigh_hash *htbl;
863 unsigned long neigh_obsolete;
868 if (test_bit(IPOIB_STOP_NEIGH_GC, &priv->flags))
871 spin_lock_irqsave(&priv->lock, flags);
873 htbl = rcu_dereference_protected(ntbl->htbl,
874 lockdep_is_held(&priv->lock));
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))
886 for (i = 0; i < htbl->size; i++) {
887 struct ipoib_neigh *neigh;
888 struct ipoib_neigh __rcu **np = &htbl->buckets[i];
890 while ((neigh = rcu_dereference_protected(*np,
891 lockdep_is_held(&priv->lock))) != NULL) {
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,
896 lockdep_is_held(&priv->lock)));
897 /* remove from path/mc list */
898 list_del(&neigh->list);
899 call_rcu(&neigh->rcu, ipoib_neigh_reclaim);
908 spin_unlock_irqrestore(&priv->lock, flags);
911 static void ipoib_reap_neigh(struct work_struct *work)
913 struct ipoib_dev_priv *priv =
914 container_of(work, struct ipoib_dev_priv, neigh_reap_task.work);
916 __ipoib_reap_neigh(priv);
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);
924 static struct ipoib_neigh *ipoib_neigh_ctor(u8 *daddr,
925 struct net_device *dev)
927 struct ipoib_neigh *neigh;
929 neigh = kzalloc(sizeof *neigh, GFP_ATOMIC);
934 memcpy(&neigh->daddr, daddr, sizeof(neigh->daddr));
935 skb_queue_head_init(&neigh->queue);
936 INIT_LIST_HEAD(&neigh->list);
937 ipoib_cm_set(neigh, NULL);
938 /* one ref on behalf of the caller */
939 atomic_set(&neigh->refcnt, 1);
944 struct ipoib_neigh *ipoib_neigh_alloc(u8 *daddr,
945 struct net_device *dev)
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;
953 htbl = rcu_dereference_protected(ntbl->htbl,
954 lockdep_is_held(&priv->lock));
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
963 hash_val = ipoib_addr_hash(htbl, daddr);
964 for (neigh = rcu_dereference_protected(htbl->buckets[hash_val],
965 lockdep_is_held(&priv->lock));
967 neigh = rcu_dereference_protected(neigh->hnext,
968 lockdep_is_held(&priv->lock))) {
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)) {
976 neigh->alive = jiffies;
981 neigh = ipoib_neigh_ctor(daddr, dev);
985 /* one ref on behalf of the hash table */
986 atomic_inc(&neigh->refcnt);
987 neigh->alive = jiffies;
989 rcu_assign_pointer(neigh->hnext,
990 rcu_dereference_protected(htbl->buckets[hash_val],
991 lockdep_is_held(&priv->lock)));
992 rcu_assign_pointer(htbl->buckets[hash_val], neigh);
993 atomic_inc(&ntbl->entries);
1000 void ipoib_neigh_dtor(struct ipoib_neigh *neigh)
1002 /* neigh reference count was dropprd to zero */
1003 struct net_device *dev = neigh->dev;
1004 struct ipoib_dev_priv *priv = netdev_priv(dev);
1005 struct sk_buff *skb;
1007 ipoib_put_ah(neigh->ah);
1008 while ((skb = __skb_dequeue(&neigh->queue))) {
1009 ++dev->stats.tx_dropped;
1010 dev_kfree_skb_any(skb);
1012 if (ipoib_cm_get(neigh))
1013 ipoib_cm_destroy_tx(ipoib_cm_get(neigh));
1014 ipoib_dbg(netdev_priv(dev),
1015 "neigh free for %06x %pI6\n",
1016 IPOIB_QPN(neigh->daddr),
1019 if (atomic_dec_and_test(&priv->ntbl.entries)) {
1020 if (test_bit(IPOIB_NEIGH_TBL_FLUSH, &priv->flags))
1021 complete(&priv->ntbl.flushed);
1025 static void ipoib_neigh_reclaim(struct rcu_head *rp)
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);
1033 void ipoib_neigh_free(struct ipoib_neigh *neigh)
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;
1043 htbl = rcu_dereference_protected(ntbl->htbl,
1044 lockdep_is_held(&priv->lock));
1048 hash_val = ipoib_addr_hash(htbl, neigh->daddr);
1049 np = &htbl->buckets[hash_val];
1050 for (n = rcu_dereference_protected(*np,
1051 lockdep_is_held(&priv->lock));
1053 n = rcu_dereference_protected(*np,
1054 lockdep_is_held(&priv->lock))) {
1057 rcu_assign_pointer(*np,
1058 rcu_dereference_protected(neigh->hnext,
1059 lockdep_is_held(&priv->lock)));
1060 call_rcu(&neigh->rcu, ipoib_neigh_reclaim);
1068 static int ipoib_neigh_hash_init(struct ipoib_dev_priv *priv)
1070 struct ipoib_neigh_table *ntbl = &priv->ntbl;
1071 struct ipoib_neigh_hash *htbl;
1072 struct ipoib_neigh **buckets;
1075 clear_bit(IPOIB_NEIGH_TBL_FLUSH, &priv->flags);
1077 htbl = kzalloc(sizeof(*htbl), GFP_KERNEL);
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);
1088 htbl->mask = (size - 1);
1089 htbl->buckets = buckets;
1092 atomic_set(&ntbl->entries, 0);
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);
1102 static void neigh_hash_free_rcu(struct rcu_head *head)
1104 struct ipoib_neigh_hash *htbl = container_of(head,
1105 struct ipoib_neigh_hash,
1107 struct ipoib_neigh __rcu **buckets = htbl->buckets;
1108 struct ipoib_neigh_table *ntbl = htbl->ntbl;
1112 complete(&ntbl->deleted);
1115 void ipoib_del_neighs_by_gid(struct net_device *dev, u8 *gid)
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;
1123 /* remove all neigh connected to a given path or mcast */
1124 spin_lock_irqsave(&priv->lock, flags);
1126 htbl = rcu_dereference_protected(ntbl->htbl,
1127 lockdep_is_held(&priv->lock));
1132 for (i = 0; i < htbl->size; i++) {
1133 struct ipoib_neigh *neigh;
1134 struct ipoib_neigh __rcu **np = &htbl->buckets[i];
1136 while ((neigh = rcu_dereference_protected(*np,
1137 lockdep_is_held(&priv->lock))) != NULL) {
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,
1142 lockdep_is_held(&priv->lock)));
1143 /* remove from parent list */
1144 list_del(&neigh->list);
1145 call_rcu(&neigh->rcu, ipoib_neigh_reclaim);
1153 spin_unlock_irqrestore(&priv->lock, flags);
1156 static void ipoib_flush_neighs(struct ipoib_dev_priv *priv)
1158 struct ipoib_neigh_table *ntbl = &priv->ntbl;
1159 struct ipoib_neigh_hash *htbl;
1160 unsigned long flags;
1161 int i, wait_flushed = 0;
1163 init_completion(&priv->ntbl.flushed);
1165 spin_lock_irqsave(&priv->lock, flags);
1167 htbl = rcu_dereference_protected(ntbl->htbl,
1168 lockdep_is_held(&priv->lock));
1172 wait_flushed = atomic_read(&priv->ntbl.entries);
1176 for (i = 0; i < htbl->size; i++) {
1177 struct ipoib_neigh *neigh;
1178 struct ipoib_neigh __rcu **np = &htbl->buckets[i];
1180 while ((neigh = rcu_dereference_protected(*np,
1181 lockdep_is_held(&priv->lock))) != NULL) {
1182 rcu_assign_pointer(*np,
1183 rcu_dereference_protected(neigh->hnext,
1184 lockdep_is_held(&priv->lock)));
1185 /* remove from path/mc list */
1186 list_del(&neigh->list);
1187 call_rcu(&neigh->rcu, ipoib_neigh_reclaim);
1192 rcu_assign_pointer(ntbl->htbl, NULL);
1193 call_rcu(&htbl->rcu, neigh_hash_free_rcu);
1196 spin_unlock_irqrestore(&priv->lock, flags);
1198 wait_for_completion(&priv->ntbl.flushed);
1201 static void ipoib_neigh_hash_uninit(struct net_device *dev)
1203 struct ipoib_dev_priv *priv = netdev_priv(dev);
1206 ipoib_dbg(priv, "ipoib_neigh_hash_uninit\n");
1207 init_completion(&priv->ntbl.deleted);
1208 set_bit(IPOIB_NEIGH_TBL_FLUSH, &priv->flags);
1210 /* Stop GC if called at init fail need to cancel work */
1211 stopped = test_and_set_bit(IPOIB_STOP_NEIGH_GC, &priv->flags);
1213 cancel_delayed_work(&priv->neigh_reap_task);
1215 ipoib_flush_neighs(priv);
1217 wait_for_completion(&priv->ntbl.deleted);
1221 int ipoib_dev_init(struct net_device *dev, struct ib_device *ca, int port)
1223 struct ipoib_dev_priv *priv = netdev_priv(dev);
1225 if (ipoib_neigh_hash_init(priv) < 0)
1227 /* Allocate RX/TX "rings" to hold queued skbs */
1228 priv->rx_ring = kzalloc(ipoib_recvq_size * sizeof *priv->rx_ring,
1230 if (!priv->rx_ring) {
1231 printk(KERN_WARNING "%s: failed to allocate RX ring (%d entries)\n",
1232 ca->name, ipoib_recvq_size);
1233 goto out_neigh_hash_cleanup;
1236 priv->tx_ring = vzalloc(ipoib_sendq_size * sizeof *priv->tx_ring);
1237 if (!priv->tx_ring) {
1238 printk(KERN_WARNING "%s: failed to allocate TX ring (%d entries)\n",
1239 ca->name, ipoib_sendq_size);
1240 goto out_rx_ring_cleanup;
1243 /* priv->tx_head, tx_tail & tx_outstanding are already 0 */
1245 if (ipoib_ib_dev_init(dev, ca, port))
1246 goto out_tx_ring_cleanup;
1250 out_tx_ring_cleanup:
1251 vfree(priv->tx_ring);
1253 out_rx_ring_cleanup:
1254 kfree(priv->rx_ring);
1256 out_neigh_hash_cleanup:
1257 ipoib_neigh_hash_uninit(dev);
1262 void ipoib_dev_cleanup(struct net_device *dev)
1264 struct ipoib_dev_priv *priv = netdev_priv(dev), *cpriv, *tcpriv;
1269 ipoib_delete_debug_files(dev);
1271 /* Delete any child interfaces first */
1272 list_for_each_entry_safe(cpriv, tcpriv, &priv->child_intfs, list) {
1273 /* Stop GC on child */
1274 set_bit(IPOIB_STOP_NEIGH_GC, &cpriv->flags);
1275 cancel_delayed_work(&cpriv->neigh_reap_task);
1276 unregister_netdevice_queue(cpriv->dev, &head);
1278 unregister_netdevice_many(&head);
1280 ipoib_ib_dev_cleanup(dev);
1282 kfree(priv->rx_ring);
1283 vfree(priv->tx_ring);
1285 priv->rx_ring = NULL;
1286 priv->tx_ring = NULL;
1288 ipoib_neigh_hash_uninit(dev);
1291 static const struct header_ops ipoib_header_ops = {
1292 .create = ipoib_hard_header,
1295 static const struct net_device_ops ipoib_netdev_ops = {
1296 .ndo_uninit = ipoib_uninit,
1297 .ndo_open = ipoib_open,
1298 .ndo_stop = ipoib_stop,
1299 .ndo_change_mtu = ipoib_change_mtu,
1300 .ndo_fix_features = ipoib_fix_features,
1301 .ndo_start_xmit = ipoib_start_xmit,
1302 .ndo_tx_timeout = ipoib_timeout,
1303 .ndo_set_rx_mode = ipoib_set_mcast_list,
1306 void ipoib_setup(struct net_device *dev)
1308 struct ipoib_dev_priv *priv = netdev_priv(dev);
1310 dev->netdev_ops = &ipoib_netdev_ops;
1311 dev->header_ops = &ipoib_header_ops;
1313 ipoib_set_ethtool_ops(dev);
1315 netif_napi_add(dev, &priv->napi, ipoib_poll, 100);
1317 dev->watchdog_timeo = HZ;
1319 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
1321 dev->hard_header_len = IPOIB_ENCAP_LEN;
1322 dev->addr_len = INFINIBAND_ALEN;
1323 dev->type = ARPHRD_INFINIBAND;
1324 dev->tx_queue_len = ipoib_sendq_size * 2;
1325 dev->features = (NETIF_F_VLAN_CHALLENGED |
1327 dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
1329 memcpy(dev->broadcast, ipv4_bcast_addr, INFINIBAND_ALEN);
1331 netif_carrier_off(dev);
1335 spin_lock_init(&priv->lock);
1337 mutex_init(&priv->vlan_mutex);
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);
1344 INIT_DELAYED_WORK(&priv->pkey_poll_task, ipoib_pkey_poll);
1345 INIT_DELAYED_WORK(&priv->mcast_task, ipoib_mcast_join_task);
1346 INIT_WORK(&priv->carrier_on_task, ipoib_mcast_carrier_on_task);
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);
1350 INIT_WORK(&priv->restart_task, ipoib_mcast_restart_task);
1351 INIT_DELAYED_WORK(&priv->ah_reap_task, ipoib_reap_ah);
1352 INIT_DELAYED_WORK(&priv->neigh_reap_task, ipoib_reap_neigh);
1355 struct ipoib_dev_priv *ipoib_intf_alloc(const char *name)
1357 struct net_device *dev;
1359 dev = alloc_netdev((int) sizeof (struct ipoib_dev_priv), name,
1364 return netdev_priv(dev);
1367 static ssize_t show_pkey(struct device *dev,
1368 struct device_attribute *attr, char *buf)
1370 struct ipoib_dev_priv *priv = netdev_priv(to_net_dev(dev));
1372 return sprintf(buf, "0x%04x\n", priv->pkey);
1374 static DEVICE_ATTR(pkey, S_IRUGO, show_pkey, NULL);
1376 static ssize_t show_umcast(struct device *dev,
1377 struct device_attribute *attr, char *buf)
1379 struct ipoib_dev_priv *priv = netdev_priv(to_net_dev(dev));
1381 return sprintf(buf, "%d\n", test_bit(IPOIB_FLAG_UMCAST, &priv->flags));
1384 void ipoib_set_umcast(struct net_device *ndev, int umcast_val)
1386 struct ipoib_dev_priv *priv = netdev_priv(ndev);
1388 if (umcast_val > 0) {
1389 set_bit(IPOIB_FLAG_UMCAST, &priv->flags);
1390 ipoib_warn(priv, "ignoring multicast groups joined directly "
1393 clear_bit(IPOIB_FLAG_UMCAST, &priv->flags);
1396 static ssize_t set_umcast(struct device *dev,
1397 struct device_attribute *attr,
1398 const char *buf, size_t count)
1400 unsigned long umcast_val = simple_strtoul(buf, NULL, 0);
1402 ipoib_set_umcast(to_net_dev(dev), umcast_val);
1406 static DEVICE_ATTR(umcast, S_IWUSR | S_IRUGO, show_umcast, set_umcast);
1408 int ipoib_add_umcast_attr(struct net_device *dev)
1410 return device_create_file(&dev->dev, &dev_attr_umcast);
1413 static ssize_t create_child(struct device *dev,
1414 struct device_attribute *attr,
1415 const char *buf, size_t count)
1420 if (sscanf(buf, "%i", &pkey) != 1)
1423 if (pkey < 0 || pkey > 0xffff)
1427 * Set the full membership bit, so that we join the right
1428 * broadcast group, etc.
1432 ret = ipoib_vlan_add(to_net_dev(dev), pkey);
1434 return ret ? ret : count;
1436 static DEVICE_ATTR(create_child, S_IWUSR, NULL, create_child);
1438 static ssize_t delete_child(struct device *dev,
1439 struct device_attribute *attr,
1440 const char *buf, size_t count)
1445 if (sscanf(buf, "%i", &pkey) != 1)
1448 if (pkey < 0 || pkey > 0xffff)
1451 ret = ipoib_vlan_delete(to_net_dev(dev), pkey);
1453 return ret ? ret : count;
1456 static DEVICE_ATTR(delete_child, S_IWUSR, NULL, delete_child);
1458 int ipoib_add_pkey_attr(struct net_device *dev)
1460 return device_create_file(&dev->dev, &dev_attr_pkey);
1463 int ipoib_set_dev_features(struct ipoib_dev_priv *priv, struct ib_device *hca)
1465 struct ib_device_attr *device_attr;
1466 int result = -ENOMEM;
1468 device_attr = kmalloc(sizeof *device_attr, GFP_KERNEL);
1470 printk(KERN_WARNING "%s: allocation of %zu bytes failed\n",
1471 hca->name, sizeof *device_attr);
1475 result = ib_query_device(hca, device_attr);
1477 printk(KERN_WARNING "%s: ib_query_device failed (ret = %d)\n",
1482 priv->hca_caps = device_attr->device_cap_flags;
1486 if (priv->hca_caps & IB_DEVICE_UD_IP_CSUM) {
1487 priv->dev->hw_features = NETIF_F_SG |
1488 NETIF_F_IP_CSUM | NETIF_F_RXCSUM;
1490 if (priv->hca_caps & IB_DEVICE_UD_TSO)
1491 priv->dev->hw_features |= NETIF_F_TSO;
1493 priv->dev->features |= priv->dev->hw_features;
1499 static struct net_device *ipoib_add_port(const char *format,
1500 struct ib_device *hca, u8 port)
1502 struct ipoib_dev_priv *priv;
1503 struct ib_port_attr attr;
1504 int result = -ENOMEM;
1506 priv = ipoib_intf_alloc(format);
1508 goto alloc_mem_failed;
1510 SET_NETDEV_DEV(priv->dev, hca->dma_device);
1511 priv->dev->dev_id = port - 1;
1513 if (!ib_query_port(hca, port, &attr))
1514 priv->max_ib_mtu = ib_mtu_enum_to_int(attr.max_mtu);
1516 printk(KERN_WARNING "%s: ib_query_port %d failed\n",
1518 goto device_init_failed;
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;
1525 priv->dev->neigh_priv_len = sizeof(struct ipoib_neigh);
1527 result = ib_query_pkey(hca, port, 0, &priv->pkey);
1529 printk(KERN_WARNING "%s: ib_query_pkey port %d failed (ret = %d)\n",
1530 hca->name, port, result);
1531 goto device_init_failed;
1534 if (ipoib_set_dev_features(priv, hca))
1535 goto device_init_failed;
1538 * Set the full membership bit, so that we join the right
1539 * broadcast group, etc.
1541 priv->pkey |= 0x8000;
1543 priv->dev->broadcast[8] = priv->pkey >> 8;
1544 priv->dev->broadcast[9] = priv->pkey & 0xff;
1546 result = ib_query_gid(hca, port, 0, &priv->local_gid);
1548 printk(KERN_WARNING "%s: ib_query_gid port %d failed (ret = %d)\n",
1549 hca->name, port, result);
1550 goto device_init_failed;
1552 memcpy(priv->dev->dev_addr + 4, priv->local_gid.raw, sizeof (union ib_gid));
1554 result = ipoib_dev_init(priv->dev, hca, port);
1556 printk(KERN_WARNING "%s: failed to initialize port %d (ret = %d)\n",
1557 hca->name, port, result);
1558 goto device_init_failed;
1561 INIT_IB_EVENT_HANDLER(&priv->event_handler,
1562 priv->ca, ipoib_event);
1563 result = ib_register_event_handler(&priv->event_handler);
1565 printk(KERN_WARNING "%s: ib_register_event_handler failed for "
1566 "port %d (ret = %d)\n",
1567 hca->name, port, result);
1571 result = register_netdev(priv->dev);
1573 printk(KERN_WARNING "%s: couldn't register ipoib port %d; error %d\n",
1574 hca->name, port, result);
1575 goto register_failed;
1578 ipoib_create_debug_files(priv->dev);
1580 if (ipoib_cm_add_mode_attr(priv->dev))
1582 if (ipoib_add_pkey_attr(priv->dev))
1584 if (ipoib_add_umcast_attr(priv->dev))
1586 if (device_create_file(&priv->dev->dev, &dev_attr_create_child))
1588 if (device_create_file(&priv->dev->dev, &dev_attr_delete_child))
1594 ipoib_delete_debug_files(priv->dev);
1595 unregister_netdev(priv->dev);
1598 ib_unregister_event_handler(&priv->event_handler);
1599 /* Stop GC if started before flush */
1600 set_bit(IPOIB_STOP_NEIGH_GC, &priv->flags);
1601 cancel_delayed_work(&priv->neigh_reap_task);
1602 flush_workqueue(ipoib_workqueue);
1605 ipoib_dev_cleanup(priv->dev);
1608 free_netdev(priv->dev);
1611 return ERR_PTR(result);
1614 static void ipoib_add_one(struct ib_device *device)
1616 struct list_head *dev_list;
1617 struct net_device *dev;
1618 struct ipoib_dev_priv *priv;
1621 if (rdma_node_get_transport(device->node_type) != RDMA_TRANSPORT_IB)
1624 dev_list = kmalloc(sizeof *dev_list, GFP_KERNEL);
1628 INIT_LIST_HEAD(dev_list);
1630 if (device->node_type == RDMA_NODE_IB_SWITCH) {
1635 e = device->phys_port_cnt;
1638 for (p = s; p <= e; ++p) {
1639 if (rdma_port_get_link_layer(device, p) != IB_LINK_LAYER_INFINIBAND)
1641 dev = ipoib_add_port("ib%d", device, p);
1643 priv = netdev_priv(dev);
1644 list_add_tail(&priv->list, dev_list);
1648 ib_set_client_data(device, &ipoib_client, dev_list);
1651 static void ipoib_remove_one(struct ib_device *device)
1653 struct ipoib_dev_priv *priv, *tmp;
1654 struct list_head *dev_list;
1656 if (rdma_node_get_transport(device->node_type) != RDMA_TRANSPORT_IB)
1659 dev_list = ib_get_client_data(device, &ipoib_client);
1661 list_for_each_entry_safe(priv, tmp, dev_list, list) {
1662 ib_unregister_event_handler(&priv->event_handler);
1665 dev_change_flags(priv->dev, priv->dev->flags & ~IFF_UP);
1669 set_bit(IPOIB_STOP_NEIGH_GC, &priv->flags);
1670 cancel_delayed_work(&priv->neigh_reap_task);
1671 flush_workqueue(ipoib_workqueue);
1673 unregister_netdev(priv->dev);
1674 free_netdev(priv->dev);
1680 static int __init ipoib_init_module(void)
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);
1688 ipoib_sendq_size = roundup_pow_of_two(ipoib_sendq_size);
1689 ipoib_sendq_size = min(ipoib_sendq_size, IPOIB_MAX_QUEUE_SIZE);
1690 ipoib_sendq_size = max3(ipoib_sendq_size, 2 * MAX_SEND_CQE, IPOIB_MIN_QUEUE_SIZE);
1691 #ifdef CONFIG_INFINIBAND_IPOIB_CM
1692 ipoib_max_conn_qp = min(ipoib_max_conn_qp, IPOIB_CM_MAX_CONN_QP);
1696 * When copying small received packets, we only copy from the
1697 * linear data part of the SKB, so we rely on this condition.
1699 BUILD_BUG_ON(IPOIB_CM_COPYBREAK > IPOIB_CM_HEAD_SIZE);
1701 ret = ipoib_register_debugfs();
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
1713 ipoib_workqueue = create_singlethread_workqueue("ipoib");
1714 if (!ipoib_workqueue) {
1719 ib_sa_register_client(&ipoib_sa_client);
1721 ret = ib_register_client(&ipoib_client);
1725 ret = ipoib_netlink_init();
1732 ib_unregister_client(&ipoib_client);
1735 ib_sa_unregister_client(&ipoib_sa_client);
1736 destroy_workqueue(ipoib_workqueue);
1739 ipoib_unregister_debugfs();
1744 static void __exit ipoib_cleanup_module(void)
1746 ipoib_netlink_fini();
1747 ib_unregister_client(&ipoib_client);
1748 ib_sa_unregister_client(&ipoib_sa_client);
1749 ipoib_unregister_debugfs();
1750 destroy_workqueue(ipoib_workqueue);
1753 module_init(ipoib_init_module);
1754 module_exit(ipoib_cleanup_module);