37 #include <linux/module.h>
40 #include <linux/slab.h>
41 #include <linux/kernel.h>
44 #include <linux/if_arp.h>
64 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
65 int ipoib_debug_level;
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
88 static void ipoib_neigh_reclaim(
struct rcu_head *
rp);
93 .remove = ipoib_remove_one
100 ipoib_dbg(priv,
"bringing up interface\n");
121 flags = cpriv->
dev->flags;
130 netif_start_queue(dev);
151 netif_stop_queue(dev);
164 flags = cpriv->
dev->flags;
176 static void ipoib_uninit(
struct net_device *dev)
191 static int ipoib_change_mtu(
struct net_device *dev,
int new_mtu)
196 if (ipoib_cm_admin_enabled(dev)) {
197 if (new_mtu > ipoib_cm_max_mtu(dev))
201 ipoib_warn(priv,
"mtu > %d will cause multicast packet drops.\n",
226 "will cause multicast packet drops\n");
236 if (!
strcmp(buf,
"datagram\n")) {
295 rb_link_node(&path->
rb_node, pn, n);
307 while ((skb = __skb_dequeue(&path->
queue)))
310 ipoib_dbg(netdev_priv(dev),
"path_free\n");
316 ipoib_put_ah(path->
ah);
321 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
334 if (ipoib_path_iter_next(iter)) {
349 spin_lock_irq(&priv->
lock);
366 spin_unlock_irq(&priv->
lock);
384 spin_lock_irq(&priv->
lock);
387 ipoib_dbg(priv,
"mark path LID 0x%04x GID %pI6 invalid\n",
393 spin_unlock_irq(&priv->
lock);
403 netif_tx_lock_bh(dev);
406 list_splice_init(&priv->
path_list, &remove_list);
414 spin_unlock_irqrestore(&priv->
lock, flags);
415 netif_tx_unlock_bh(dev);
417 path_free(dev, path);
418 netif_tx_lock_bh(dev);
422 spin_unlock_irqrestore(&priv->
lock, flags);
423 netif_tx_unlock_bh(dev);
426 static void path_rec_completion(
int status,
441 ipoib_dbg(priv,
"PathRec LID 0x%04x for GID %pI6\n",
444 ipoib_dbg(priv,
"PathRec status %d for GID %pI6\n",
445 status, path->
pathrec.dgid.raw);
447 skb_queue_head_init(&skqueue);
458 if (!IS_ERR_OR_NULL(ah)) {
464 ipoib_dbg(priv,
"created address handle %p for LID 0x%04x, SL %d\n",
467 while ((skb = __skb_dequeue(&path->
queue)))
468 __skb_queue_tail(&skqueue, skb);
480 ipoib_put_ah(neigh->
ah);
482 kref_get(&path->
ah->ref);
483 neigh->
ah = path->
ah;
485 if (ipoib_cm_enabled(dev, neigh->
daddr)) {
486 if (!ipoib_cm_get(neigh))
490 if (!ipoib_cm_get(neigh)) {
497 while ((skb = __skb_dequeue(&neigh->
queue)))
498 __skb_queue_tail(&skqueue, skb);
506 spin_unlock_irqrestore(&priv->
lock, flags);
509 ipoib_put_ah(old_ah);
511 while ((skb = __skb_dequeue(&skqueue))) {
515 "to requeue packet\n");
533 skb_queue_head_init(&path->
queue);
546 static int path_rec_start(
struct net_device *dev,
551 ipoib_dbg(priv,
"Start path record lookup for %pI6\n",
554 init_completion(&path->
done);
588 spin_unlock_irqrestore(&priv->
lock, flags);
589 ++dev->
stats.tx_dropped;
594 path = __path_find(dev, daddr + 4);
596 path = path_rec_create(dev, daddr + 4);
600 __path_add(dev, path);
606 kref_get(&path->
ah->ref);
607 neigh->
ah = path->
ah;
609 if (ipoib_cm_enabled(dev, neigh->
daddr)) {
610 if (!ipoib_cm_get(neigh))
612 if (!ipoib_cm_get(neigh)) {
618 __skb_queue_tail(&neigh->
queue, skb);
620 ipoib_warn(priv,
"queue length limit %d. Packet drop.\n",
621 skb_queue_len(&neigh->
queue));
625 spin_unlock_irqrestore(&priv->
lock, flags);
627 ipoib_neigh_put(neigh);
633 if (!path->
query && path_rec_start(dev, path))
636 __skb_queue_tail(&neigh->
queue, skb);
639 spin_unlock_irqrestore(&priv->
lock, flags);
640 ipoib_neigh_put(neigh);
649 ++dev->
stats.tx_dropped;
652 spin_unlock_irqrestore(&priv->
lock, flags);
653 ipoib_neigh_put(neigh);
665 path = __path_find(dev, cb->
hwaddr + 4);
666 if (!path || !path->
valid) {
670 path = path_rec_create(dev, cb->
hwaddr + 4);
674 __skb_queue_tail(&path->
queue, skb);
676 if (!path->
query && path_rec_start(dev, path)) {
677 spin_unlock_irqrestore(&priv->
lock, flags);
679 path_free(dev, path);
682 __path_add(dev, path);
684 ++dev->
stats.tx_dropped;
688 spin_unlock_irqrestore(&priv->
lock, flags);
693 ipoib_dbg(priv,
"Send unicast ARP to %04x\n",
696 spin_unlock_irqrestore(&priv->
lock, flags);
699 }
else if ((path->
query || !path_rec_start(dev, path)) &&
701 __skb_queue_tail(&path->
queue, skb);
703 ++dev->
stats.tx_dropped;
707 spin_unlock_irqrestore(&priv->
lock, flags);
727 ++dev->
stats.tx_dropped;
737 goto send_using_neigh;
748 neigh_add_path(skb, cb->
hwaddr, dev);
755 unicast_arp_send(skb, dev, cb);
759 ++dev->
stats.tx_dropped;
766 if (ipoib_cm_get(neigh)) {
767 if (ipoib_cm_up(neigh)) {
771 }
else if (neigh->
ah) {
778 __skb_queue_tail(&neigh->
queue, skb);
779 spin_unlock_irqrestore(&priv->
lock, flags);
781 ++dev->
stats.tx_dropped;
786 ipoib_neigh_put(neigh);
791 static void ipoib_timeout(
struct net_device *dev)
795 ipoib_warn(priv,
"transmit timeout: latency %d msecs\n",
797 ipoib_warn(priv,
"queue stopped %d, tx_head %u, tx_tail %u\n",
798 netif_queue_stopped(dev),
803 static int ipoib_hard_header(
struct sk_buff *skb,
806 const void *daddr,
const void *
saddr,
unsigned len)
826 static void ipoib_set_mcast_list(
struct net_device *dev)
831 ipoib_dbg(priv,
"IPOIB_FLAG_OPER_UP not set");
847 u32 *daddr_32 = (
u32 *) daddr;
850 hv = jhash_3words(daddr_32[3], daddr_32[4], 0xFFFFFF & daddr_32[0], 0);
851 return hv & htbl->
mask;
869 hash_val = ipoib_addr_hash(htbl, daddr);
886 rcu_read_unlock_bh();
894 unsigned long neigh_obsolete;
905 lockdep_is_held(&priv->
lock));
917 for (i = 0; i < htbl->
size; i++) {
922 lockdep_is_held(&priv->
lock))) !=
NULL) {
927 lockdep_is_held(&priv->
lock)));
939 spin_unlock_irqrestore(&priv->
lock, flags);
947 __ipoib_reap_neigh(priv);
966 skb_queue_head_init(&neigh->
queue);
967 INIT_LIST_HEAD(&neigh->
list);
968 ipoib_cm_set(neigh,
NULL);
985 lockdep_is_held(&priv->
lock));
994 hash_val = ipoib_addr_hash(htbl, daddr);
996 lockdep_is_held(&priv->
lock));
999 lockdep_is_held(&priv->
lock))) {
1012 neigh = ipoib_neigh_ctor(daddr, dev);
1022 lockdep_is_held(&priv->
lock)));
1038 ipoib_put_ah(neigh->
ah);
1039 while ((skb = __skb_dequeue(&neigh->
queue))) {
1040 ++dev->
stats.tx_dropped;
1043 if (ipoib_cm_get(neigh))
1046 "neigh free for %06x %pI6\n",
1056 static void ipoib_neigh_reclaim(
struct rcu_head *
rp)
1061 ipoib_neigh_put(neigh);
1075 lockdep_is_held(&priv->
lock));
1079 hash_val = ipoib_addr_hash(htbl, neigh->
daddr);
1080 np = &htbl->
buckets[hash_val];
1082 lockdep_is_held(&priv->
lock));
1085 lockdep_is_held(&priv->
lock))) {
1090 lockdep_is_held(&priv->
lock)));
1113 buckets = kzalloc(size *
sizeof(*buckets),
GFP_KERNEL);
1119 htbl->
mask = (size - 1);
1151 unsigned long flags;
1158 lockdep_is_held(&priv->
lock));
1163 for (i = 0; i < htbl->
size; i++) {
1168 lockdep_is_held(&priv->
lock))) !=
NULL) {
1173 lockdep_is_held(&priv->
lock)));
1184 spin_unlock_irqrestore(&priv->
lock, flags);
1191 unsigned long flags;
1192 int i, wait_flushed = 0;
1194 init_completion(&priv->
ntbl.flushed);
1199 lockdep_is_held(&priv->
lock));
1207 for (i = 0; i < htbl->
size; i++) {
1212 lockdep_is_held(&priv->
lock))) !=
NULL) {
1215 lockdep_is_held(&priv->
lock)));
1227 spin_unlock_irqrestore(&priv->
lock, flags);
1232 static void ipoib_neigh_hash_uninit(
struct net_device *dev)
1237 ipoib_dbg(priv,
"ipoib_neigh_hash_uninit\n");
1238 init_completion(&priv->
ntbl.deleted);
1246 ipoib_flush_neighs(priv);
1256 if (ipoib_neigh_hash_init(priv) < 0)
1264 goto out_neigh_hash_cleanup;
1271 goto out_rx_ring_cleanup;
1277 goto out_tx_ring_cleanup;
1281 out_tx_ring_cleanup:
1284 out_rx_ring_cleanup:
1287 out_neigh_hash_cleanup:
1288 ipoib_neigh_hash_uninit(dev);
1319 ipoib_neigh_hash_uninit(dev);
1322 static const struct header_ops ipoib_header_ops = {
1323 .create = ipoib_hard_header,
1327 .ndo_uninit = ipoib_uninit,
1329 .ndo_stop = ipoib_stop,
1330 .ndo_change_mtu = ipoib_change_mtu,
1331 .ndo_fix_features = ipoib_fix_features,
1332 .ndo_start_xmit = ipoib_start_xmit,
1333 .ndo_tx_timeout = ipoib_timeout,
1334 .ndo_set_rx_mode = ipoib_set_mcast_list,
1395 return netdev_priv(dev);
1419 if (umcast_val > 0) {
1421 ipoib_warn(priv,
"ignoring multicast groups joined directly "
1429 const char *buf,
size_t count)
1446 const char *buf,
size_t count)
1451 if (
sscanf(buf,
"%i", &pkey) != 1)
1454 if (pkey < 0 || pkey > 0xffff)
1465 return ret ? ret :
count;
1471 const char *buf,
size_t count)
1476 if (
sscanf(buf,
"%i", &pkey) != 1)
1479 if (pkey < 0 || pkey > 0xffff)
1484 return ret ? ret :
count;
1502 hca->
name,
sizeof *device_attr);
1524 priv->
dev->features |= priv->
dev->hw_features;
1539 goto alloc_mem_failed;
1542 priv->
dev->dev_id = port - 1;
1545 priv->
max_ib_mtu = ib_mtu_enum_to_int(attr.max_mtu);
1549 goto device_init_failed;
1561 hca->
name, port, result);
1562 goto device_init_failed;
1566 goto device_init_failed;
1572 priv->
pkey |= 0x8000;
1574 priv->
dev->broadcast[8] = priv->
pkey >> 8;
1575 priv->
dev->broadcast[9] = priv->
pkey & 0xff;
1580 hca->
name, port, result);
1581 goto device_init_failed;
1588 hca->
name, port, result);
1589 goto device_init_failed;
1597 "port %d (ret = %d)\n",
1598 hca->
name, port, result);
1605 hca->
name, port, result);
1606 goto register_failed;
1642 return ERR_PTR(result);
1659 INIT_LIST_HEAD(dev_list);
1669 for (p = s; p <=
e; ++
p) {
1672 dev = ipoib_add_port(
"ib%d", device, p);
1674 priv = netdev_priv(dev);
1682 static void ipoib_remove_one(
struct ib_device *device)
1711 static int __init ipoib_init_module(
void)
1722 #ifdef CONFIG_INFINIBAND_IPOIB_CM
1745 if (!ipoib_workqueue) {
1775 static void __exit ipoib_cleanup_module(
void)