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>
51 #include <net/addrconf.h>
52 #include <linux/inetdevice.h>
53 #include <rdma/ib_cache.h>
54 #include <linux/pci.h>
56 #define DRV_VERSION "1.0.0"
58 const char ipoib_driver_version[] = DRV_VERSION;
60 MODULE_AUTHOR("Roland Dreier");
61 MODULE_DESCRIPTION("IP-over-InfiniBand net driver");
62 MODULE_LICENSE("Dual BSD/GPL");
64 int ipoib_sendq_size __read_mostly = IPOIB_TX_RING_SIZE;
65 int ipoib_recvq_size __read_mostly = IPOIB_RX_RING_SIZE;
67 module_param_named(send_queue_size, ipoib_sendq_size, int, 0444);
68 MODULE_PARM_DESC(send_queue_size, "Number of descriptors in send queue");
69 module_param_named(recv_queue_size, ipoib_recvq_size, int, 0444);
70 MODULE_PARM_DESC(recv_queue_size, "Number of descriptors in receive queue");
72 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
73 int ipoib_debug_level;
75 module_param_named(debug_level, ipoib_debug_level, int, 0644);
76 MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0");
79 struct ipoib_path_iter {
80 struct net_device *dev;
81 struct ipoib_path path;
84 static const u8 ipv4_bcast_addr[] = {
85 0x00, 0xff, 0xff, 0xff,
86 0xff, 0x12, 0x40, 0x1b, 0x00, 0x00, 0x00, 0x00,
87 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff
90 struct workqueue_struct *ipoib_workqueue;
92 struct ib_sa_client ipoib_sa_client;
94 static void ipoib_add_one(struct ib_device *device);
95 static void ipoib_remove_one(struct ib_device *device, void *client_data);
96 static void ipoib_neigh_reclaim(struct rcu_head *rp);
97 static struct net_device *ipoib_get_net_dev_by_params(
98 struct ib_device *dev, u8 port, u16 pkey,
99 const union ib_gid *gid, const struct sockaddr *addr,
101 static int ipoib_set_mac(struct net_device *dev, void *addr);
102 static int ipoib_ioctl(struct net_device *dev, struct ifreq *ifr,
105 static struct ib_client ipoib_client = {
107 .add = ipoib_add_one,
108 .remove = ipoib_remove_one,
109 .get_net_dev_by_params = ipoib_get_net_dev_by_params,
112 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
113 static int ipoib_netdev_event(struct notifier_block *this,
114 unsigned long event, void *ptr)
116 struct netdev_notifier_info *ni = ptr;
117 struct net_device *dev = ni->dev;
119 if (dev->netdev_ops->ndo_open != ipoib_open)
123 case NETDEV_REGISTER:
124 ipoib_create_debug_files(dev);
126 case NETDEV_CHANGENAME:
127 ipoib_delete_debug_files(dev);
128 ipoib_create_debug_files(dev);
130 case NETDEV_UNREGISTER:
131 ipoib_delete_debug_files(dev);
139 int ipoib_open(struct net_device *dev)
141 struct ipoib_dev_priv *priv = ipoib_priv(dev);
143 ipoib_dbg(priv, "bringing up interface\n");
145 netif_carrier_off(dev);
147 set_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags);
149 priv->sm_fullmember_sendonly_support = false;
151 if (ipoib_ib_dev_open(dev)) {
152 if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags))
157 ipoib_ib_dev_up(dev);
159 if (!test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags)) {
160 struct ipoib_dev_priv *cpriv;
162 /* Bring up any child interfaces too */
163 down_read(&priv->vlan_rwsem);
164 list_for_each_entry(cpriv, &priv->child_intfs, list) {
167 flags = cpriv->dev->flags;
171 dev_change_flags(cpriv->dev, flags | IFF_UP);
173 up_read(&priv->vlan_rwsem);
176 netif_start_queue(dev);
181 clear_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags);
186 static int ipoib_stop(struct net_device *dev)
188 struct ipoib_dev_priv *priv = ipoib_priv(dev);
190 ipoib_dbg(priv, "stopping interface\n");
192 clear_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags);
194 netif_stop_queue(dev);
196 ipoib_ib_dev_down(dev);
197 ipoib_ib_dev_stop(dev);
199 if (!test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags)) {
200 struct ipoib_dev_priv *cpriv;
202 /* Bring down any child interfaces too */
203 down_read(&priv->vlan_rwsem);
204 list_for_each_entry(cpriv, &priv->child_intfs, list) {
207 flags = cpriv->dev->flags;
208 if (!(flags & IFF_UP))
211 dev_change_flags(cpriv->dev, flags & ~IFF_UP);
213 up_read(&priv->vlan_rwsem);
219 static void ipoib_uninit(struct net_device *dev)
221 ipoib_dev_cleanup(dev);
224 static netdev_features_t ipoib_fix_features(struct net_device *dev, netdev_features_t features)
226 struct ipoib_dev_priv *priv = ipoib_priv(dev);
228 if (test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags))
229 features &= ~(NETIF_F_IP_CSUM | NETIF_F_TSO);
234 static int ipoib_change_mtu(struct net_device *dev, int new_mtu)
236 struct ipoib_dev_priv *priv = ipoib_priv(dev);
239 /* dev->mtu > 2K ==> connected mode */
240 if (ipoib_cm_admin_enabled(dev)) {
241 if (new_mtu > ipoib_cm_max_mtu(dev))
244 if (new_mtu > priv->mcast_mtu)
245 ipoib_warn(priv, "mtu > %d will cause multicast packet drops.\n",
252 if (new_mtu < (ETH_MIN_MTU + IPOIB_ENCAP_LEN) ||
253 new_mtu > IPOIB_UD_MTU(priv->max_ib_mtu))
256 priv->admin_mtu = new_mtu;
258 if (priv->mcast_mtu < priv->admin_mtu)
259 ipoib_dbg(priv, "MTU must be smaller than the underlying "
260 "link layer MTU - 4 (%u)\n", priv->mcast_mtu);
262 new_mtu = min(priv->mcast_mtu, priv->admin_mtu);
264 if (priv->rn_ops->ndo_change_mtu) {
265 bool carrier_status = netif_carrier_ok(dev);
267 netif_carrier_off(dev);
269 /* notify lower level on the real mtu */
270 ret = priv->rn_ops->ndo_change_mtu(dev, new_mtu);
273 netif_carrier_on(dev);
281 static void ipoib_get_stats(struct net_device *dev,
282 struct rtnl_link_stats64 *stats)
284 struct ipoib_dev_priv *priv = ipoib_priv(dev);
286 if (priv->rn_ops->ndo_get_stats64)
287 priv->rn_ops->ndo_get_stats64(dev, stats);
289 netdev_stats_to_stats64(stats, &dev->stats);
292 /* Called with an RCU read lock taken */
293 static bool ipoib_is_dev_match_addr_rcu(const struct sockaddr *addr,
294 struct net_device *dev)
296 struct net *net = dev_net(dev);
297 struct in_device *in_dev;
298 struct sockaddr_in *addr_in = (struct sockaddr_in *)addr;
299 struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6 *)addr;
302 switch (addr->sa_family) {
304 in_dev = in_dev_get(dev);
308 ret_addr = inet_confirm_addr(net, in_dev, 0,
309 addr_in->sin_addr.s_addr,
317 if (IS_ENABLED(CONFIG_IPV6) &&
318 ipv6_chk_addr(net, &addr_in6->sin6_addr, dev, 1))
327 * Find the master net_device on top of the given net_device.
328 * @dev: base IPoIB net_device
330 * Returns the master net_device with a reference held, or the same net_device
331 * if no master exists.
333 static struct net_device *ipoib_get_master_net_dev(struct net_device *dev)
335 struct net_device *master;
338 master = netdev_master_upper_dev_get_rcu(dev);
350 struct ipoib_walk_data {
351 const struct sockaddr *addr;
352 struct net_device *result;
355 static int ipoib_upper_walk(struct net_device *upper, void *_data)
357 struct ipoib_walk_data *data = _data;
360 if (ipoib_is_dev_match_addr_rcu(data->addr, upper)) {
362 data->result = upper;
370 * Find a net_device matching the given address, which is an upper device of
371 * the given net_device.
372 * @addr: IP address to look for.
373 * @dev: base IPoIB net_device
375 * If found, returns the net_device with a reference held. Otherwise return
378 static struct net_device *ipoib_get_net_dev_match_addr(
379 const struct sockaddr *addr, struct net_device *dev)
381 struct ipoib_walk_data data = {
386 if (ipoib_is_dev_match_addr_rcu(addr, dev)) {
392 netdev_walk_all_upper_dev_rcu(dev, ipoib_upper_walk, &data);
398 /* returns the number of IPoIB netdevs on top a given ipoib device matching a
399 * pkey_index and address, if one exists.
401 * @found_net_dev: contains a matching net_device if the return value >= 1,
402 * with a reference held. */
403 static int ipoib_match_gid_pkey_addr(struct ipoib_dev_priv *priv,
404 const union ib_gid *gid,
406 const struct sockaddr *addr,
408 struct net_device **found_net_dev)
410 struct ipoib_dev_priv *child_priv;
411 struct net_device *net_dev = NULL;
414 if (priv->pkey_index == pkey_index &&
415 (!gid || !memcmp(gid, &priv->local_gid, sizeof(*gid)))) {
417 net_dev = ipoib_get_master_net_dev(priv->dev);
419 /* Verify the net_device matches the IP address, as
420 * IPoIB child devices currently share a GID. */
421 net_dev = ipoib_get_net_dev_match_addr(addr, priv->dev);
425 *found_net_dev = net_dev;
432 /* Check child interfaces */
433 down_read_nested(&priv->vlan_rwsem, nesting);
434 list_for_each_entry(child_priv, &priv->child_intfs, list) {
435 matches += ipoib_match_gid_pkey_addr(child_priv, gid,
442 up_read(&priv->vlan_rwsem);
447 /* Returns the number of matching net_devs found (between 0 and 2). Also
448 * return the matching net_device in the @net_dev parameter, holding a
449 * reference to the net_device, if the number of matches >= 1 */
450 static int __ipoib_get_net_dev_by_params(struct list_head *dev_list, u8 port,
452 const union ib_gid *gid,
453 const struct sockaddr *addr,
454 struct net_device **net_dev)
456 struct ipoib_dev_priv *priv;
461 list_for_each_entry(priv, dev_list, list) {
462 if (priv->port != port)
465 matches += ipoib_match_gid_pkey_addr(priv, gid, pkey_index,
474 static struct net_device *ipoib_get_net_dev_by_params(
475 struct ib_device *dev, u8 port, u16 pkey,
476 const union ib_gid *gid, const struct sockaddr *addr,
479 struct net_device *net_dev;
480 struct list_head *dev_list = client_data;
485 if (!rdma_protocol_ib(dev, port))
488 ret = ib_find_cached_pkey(dev, port, pkey, &pkey_index);
495 /* See if we can find a unique device matching the L2 parameters */
496 matches = __ipoib_get_net_dev_by_params(dev_list, port, pkey_index,
497 gid, NULL, &net_dev);
508 /* Couldn't find a unique device with L2 parameters only. Use L3
509 * address to uniquely match the net device */
510 matches = __ipoib_get_net_dev_by_params(dev_list, port, pkey_index,
511 gid, addr, &net_dev);
516 dev_warn_ratelimited(&dev->dev,
517 "duplicate IP address detected\n");
524 int ipoib_set_mode(struct net_device *dev, const char *buf)
526 struct ipoib_dev_priv *priv = ipoib_priv(dev);
528 if ((test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags) &&
529 !strcmp(buf, "connected\n")) ||
530 (!test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags) &&
531 !strcmp(buf, "datagram\n"))) {
535 /* flush paths if we switch modes so that connections are restarted */
536 if (IPOIB_CM_SUPPORTED(dev->dev_addr) && !strcmp(buf, "connected\n")) {
537 set_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags);
538 ipoib_warn(priv, "enabling connected mode "
539 "will cause multicast packet drops\n");
540 netdev_update_features(dev);
541 dev_set_mtu(dev, ipoib_cm_max_mtu(dev));
543 priv->tx_wr.wr.send_flags &= ~IB_SEND_IP_CSUM;
545 ipoib_flush_paths(dev);
546 return (!rtnl_trylock()) ? -EBUSY : 0;
549 if (!strcmp(buf, "datagram\n")) {
550 clear_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags);
551 netdev_update_features(dev);
552 dev_set_mtu(dev, min(priv->mcast_mtu, dev->mtu));
554 ipoib_flush_paths(dev);
555 return (!rtnl_trylock()) ? -EBUSY : 0;
561 struct ipoib_path *__path_find(struct net_device *dev, void *gid)
563 struct ipoib_dev_priv *priv = ipoib_priv(dev);
564 struct rb_node *n = priv->path_tree.rb_node;
565 struct ipoib_path *path;
569 path = rb_entry(n, struct ipoib_path, rb_node);
571 ret = memcmp(gid, path->pathrec.dgid.raw,
572 sizeof (union ib_gid));
585 static int __path_add(struct net_device *dev, struct ipoib_path *path)
587 struct ipoib_dev_priv *priv = ipoib_priv(dev);
588 struct rb_node **n = &priv->path_tree.rb_node;
589 struct rb_node *pn = NULL;
590 struct ipoib_path *tpath;
595 tpath = rb_entry(pn, struct ipoib_path, rb_node);
597 ret = memcmp(path->pathrec.dgid.raw, tpath->pathrec.dgid.raw,
598 sizeof (union ib_gid));
607 rb_link_node(&path->rb_node, pn, n);
608 rb_insert_color(&path->rb_node, &priv->path_tree);
610 list_add_tail(&path->list, &priv->path_list);
615 static void path_free(struct net_device *dev, struct ipoib_path *path)
619 while ((skb = __skb_dequeue(&path->queue)))
620 dev_kfree_skb_irq(skb);
622 ipoib_dbg(ipoib_priv(dev), "path_free\n");
624 /* remove all neigh connected to this path */
625 ipoib_del_neighs_by_gid(dev, path->pathrec.dgid.raw);
628 ipoib_put_ah(path->ah);
633 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
635 struct ipoib_path_iter *ipoib_path_iter_init(struct net_device *dev)
637 struct ipoib_path_iter *iter;
639 iter = kmalloc(sizeof *iter, GFP_KERNEL);
644 memset(iter->path.pathrec.dgid.raw, 0, 16);
646 if (ipoib_path_iter_next(iter)) {
654 int ipoib_path_iter_next(struct ipoib_path_iter *iter)
656 struct ipoib_dev_priv *priv = ipoib_priv(iter->dev);
658 struct ipoib_path *path;
661 spin_lock_irq(&priv->lock);
663 n = rb_first(&priv->path_tree);
666 path = rb_entry(n, struct ipoib_path, rb_node);
668 if (memcmp(iter->path.pathrec.dgid.raw, path->pathrec.dgid.raw,
669 sizeof (union ib_gid)) < 0) {
678 spin_unlock_irq(&priv->lock);
683 void ipoib_path_iter_read(struct ipoib_path_iter *iter,
684 struct ipoib_path *path)
689 #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG */
691 void ipoib_mark_paths_invalid(struct net_device *dev)
693 struct ipoib_dev_priv *priv = ipoib_priv(dev);
694 struct ipoib_path *path, *tp;
696 spin_lock_irq(&priv->lock);
698 list_for_each_entry_safe(path, tp, &priv->path_list, list) {
699 ipoib_dbg(priv, "mark path LID 0x%08x GID %pI6 invalid\n",
700 be32_to_cpu(sa_path_get_dlid(&path->pathrec)),
701 path->pathrec.dgid.raw);
705 spin_unlock_irq(&priv->lock);
708 static void push_pseudo_header(struct sk_buff *skb, const char *daddr)
710 struct ipoib_pseudo_header *phdr;
712 phdr = skb_push(skb, sizeof(*phdr));
713 memcpy(phdr->hwaddr, daddr, INFINIBAND_ALEN);
716 void ipoib_flush_paths(struct net_device *dev)
718 struct ipoib_dev_priv *priv = ipoib_priv(dev);
719 struct ipoib_path *path, *tp;
720 LIST_HEAD(remove_list);
723 netif_tx_lock_bh(dev);
724 spin_lock_irqsave(&priv->lock, flags);
726 list_splice_init(&priv->path_list, &remove_list);
728 list_for_each_entry(path, &remove_list, list)
729 rb_erase(&path->rb_node, &priv->path_tree);
731 list_for_each_entry_safe(path, tp, &remove_list, list) {
733 ib_sa_cancel_query(path->query_id, path->query);
734 spin_unlock_irqrestore(&priv->lock, flags);
735 netif_tx_unlock_bh(dev);
736 wait_for_completion(&path->done);
737 path_free(dev, path);
738 netif_tx_lock_bh(dev);
739 spin_lock_irqsave(&priv->lock, flags);
742 spin_unlock_irqrestore(&priv->lock, flags);
743 netif_tx_unlock_bh(dev);
746 static void path_rec_completion(int status,
747 struct sa_path_rec *pathrec,
750 struct ipoib_path *path = path_ptr;
751 struct net_device *dev = path->dev;
752 struct ipoib_dev_priv *priv = ipoib_priv(dev);
753 struct ipoib_ah *ah = NULL;
754 struct ipoib_ah *old_ah = NULL;
755 struct ipoib_neigh *neigh, *tn;
756 struct sk_buff_head skqueue;
761 ipoib_dbg(priv, "PathRec LID 0x%04x for GID %pI6\n",
762 be32_to_cpu(sa_path_get_dlid(pathrec)),
765 ipoib_dbg(priv, "PathRec status %d for GID %pI6\n",
766 status, path->pathrec.dgid.raw);
768 skb_queue_head_init(&skqueue);
771 struct rdma_ah_attr av;
773 if (!ib_init_ah_from_path(priv->ca, priv->port, pathrec, &av))
774 ah = ipoib_create_ah(dev, priv->pd, &av);
777 spin_lock_irqsave(&priv->lock, flags);
779 if (!IS_ERR_OR_NULL(ah)) {
781 * pathrec.dgid is used as the database key from the LLADDR,
782 * it must remain unchanged even if the SA returns a different
783 * GID to use in the AH.
785 if (memcmp(pathrec->dgid.raw, path->pathrec.dgid.raw,
786 sizeof(union ib_gid))) {
789 "%s got PathRec for gid %pI6 while asked for %pI6\n",
790 dev->name, pathrec->dgid.raw,
791 path->pathrec.dgid.raw);
792 memcpy(pathrec->dgid.raw, path->pathrec.dgid.raw,
793 sizeof(union ib_gid));
796 path->pathrec = *pathrec;
801 ipoib_dbg(priv, "created address handle %p for LID 0x%04x, SL %d\n",
802 ah, be32_to_cpu(sa_path_get_dlid(pathrec)),
805 while ((skb = __skb_dequeue(&path->queue)))
806 __skb_queue_tail(&skqueue, skb);
808 list_for_each_entry_safe(neigh, tn, &path->neigh_list, list) {
810 WARN_ON(neigh->ah != old_ah);
812 * Dropping the ah reference inside
813 * priv->lock is safe here, because we
814 * will hold one more reference from
815 * the original value of path->ah (ie
818 ipoib_put_ah(neigh->ah);
820 kref_get(&path->ah->ref);
821 neigh->ah = path->ah;
823 if (ipoib_cm_enabled(dev, neigh->daddr)) {
824 if (!ipoib_cm_get(neigh))
825 ipoib_cm_set(neigh, ipoib_cm_create_tx(dev,
828 if (!ipoib_cm_get(neigh)) {
829 ipoib_neigh_free(neigh);
834 while ((skb = __skb_dequeue(&neigh->queue)))
835 __skb_queue_tail(&skqueue, skb);
841 complete(&path->done);
843 spin_unlock_irqrestore(&priv->lock, flags);
845 if (IS_ERR_OR_NULL(ah))
846 ipoib_del_neighs_by_gid(dev, path->pathrec.dgid.raw);
849 ipoib_put_ah(old_ah);
851 while ((skb = __skb_dequeue(&skqueue))) {
854 ret = dev_queue_xmit(skb);
856 ipoib_warn(priv, "%s: dev_queue_xmit failed to re-queue packet, ret:%d\n",
861 static struct ipoib_path *path_rec_create(struct net_device *dev, void *gid)
863 struct ipoib_dev_priv *priv = ipoib_priv(dev);
864 struct ipoib_path *path;
866 if (!priv->broadcast)
869 path = kzalloc(sizeof *path, GFP_ATOMIC);
875 skb_queue_head_init(&path->queue);
877 INIT_LIST_HEAD(&path->neigh_list);
879 if (rdma_cap_opa_ah(priv->ca, priv->port))
880 path->pathrec.rec_type = SA_PATH_REC_TYPE_OPA;
882 path->pathrec.rec_type = SA_PATH_REC_TYPE_IB;
883 memcpy(path->pathrec.dgid.raw, gid, sizeof (union ib_gid));
884 path->pathrec.sgid = priv->local_gid;
885 path->pathrec.pkey = cpu_to_be16(priv->pkey);
886 path->pathrec.numb_path = 1;
887 path->pathrec.traffic_class = priv->broadcast->mcmember.traffic_class;
892 static int path_rec_start(struct net_device *dev,
893 struct ipoib_path *path)
895 struct ipoib_dev_priv *priv = ipoib_priv(dev);
897 ipoib_dbg(priv, "Start path record lookup for %pI6\n",
898 path->pathrec.dgid.raw);
900 init_completion(&path->done);
903 ib_sa_path_rec_get(&ipoib_sa_client, priv->ca, priv->port,
905 IB_SA_PATH_REC_DGID |
906 IB_SA_PATH_REC_SGID |
907 IB_SA_PATH_REC_NUMB_PATH |
908 IB_SA_PATH_REC_TRAFFIC_CLASS |
913 if (path->query_id < 0) {
914 ipoib_warn(priv, "ib_sa_path_rec_get failed: %d\n", path->query_id);
916 complete(&path->done);
917 return path->query_id;
923 static struct ipoib_neigh *neigh_add_path(struct sk_buff *skb, u8 *daddr,
924 struct net_device *dev)
926 struct ipoib_dev_priv *priv = ipoib_priv(dev);
927 struct rdma_netdev *rn = netdev_priv(dev);
928 struct ipoib_path *path;
929 struct ipoib_neigh *neigh;
932 spin_lock_irqsave(&priv->lock, flags);
933 neigh = ipoib_neigh_alloc(daddr, dev);
935 spin_unlock_irqrestore(&priv->lock, flags);
936 ++dev->stats.tx_dropped;
937 dev_kfree_skb_any(skb);
941 /* To avoid race condition, make sure that the
942 * neigh will be added only once.
944 if (unlikely(!list_empty(&neigh->list))) {
945 spin_unlock_irqrestore(&priv->lock, flags);
949 path = __path_find(dev, daddr + 4);
951 path = path_rec_create(dev, daddr + 4);
955 __path_add(dev, path);
958 list_add_tail(&neigh->list, &path->neigh_list);
961 kref_get(&path->ah->ref);
962 neigh->ah = path->ah;
964 if (ipoib_cm_enabled(dev, neigh->daddr)) {
965 if (!ipoib_cm_get(neigh))
966 ipoib_cm_set(neigh, ipoib_cm_create_tx(dev, path, neigh));
967 if (!ipoib_cm_get(neigh)) {
968 ipoib_neigh_free(neigh);
971 if (skb_queue_len(&neigh->queue) <
972 IPOIB_MAX_PATH_REC_QUEUE) {
973 push_pseudo_header(skb, neigh->daddr);
974 __skb_queue_tail(&neigh->queue, skb);
976 ipoib_warn(priv, "queue length limit %d. Packet drop.\n",
977 skb_queue_len(&neigh->queue));
981 spin_unlock_irqrestore(&priv->lock, flags);
982 path->ah->last_send = rn->send(dev, skb, path->ah->ah,
984 ipoib_neigh_put(neigh);
990 if (!path->query && path_rec_start(dev, path))
992 if (skb_queue_len(&neigh->queue) < IPOIB_MAX_PATH_REC_QUEUE) {
993 push_pseudo_header(skb, neigh->daddr);
994 __skb_queue_tail(&neigh->queue, skb);
1000 spin_unlock_irqrestore(&priv->lock, flags);
1001 ipoib_neigh_put(neigh);
1005 ipoib_neigh_free(neigh);
1007 ++dev->stats.tx_dropped;
1008 dev_kfree_skb_any(skb);
1010 spin_unlock_irqrestore(&priv->lock, flags);
1011 ipoib_neigh_put(neigh);
1016 static void unicast_arp_send(struct sk_buff *skb, struct net_device *dev,
1017 struct ipoib_pseudo_header *phdr)
1019 struct ipoib_dev_priv *priv = ipoib_priv(dev);
1020 struct rdma_netdev *rn = netdev_priv(dev);
1021 struct ipoib_path *path;
1022 unsigned long flags;
1024 spin_lock_irqsave(&priv->lock, flags);
1026 path = __path_find(dev, phdr->hwaddr + 4);
1027 if (!path || !path->valid) {
1031 path = path_rec_create(dev, phdr->hwaddr + 4);
1035 if (skb_queue_len(&path->queue) < IPOIB_MAX_PATH_REC_QUEUE) {
1036 push_pseudo_header(skb, phdr->hwaddr);
1037 __skb_queue_tail(&path->queue, skb);
1039 ++dev->stats.tx_dropped;
1040 dev_kfree_skb_any(skb);
1043 if (!path->query && path_rec_start(dev, path)) {
1044 spin_unlock_irqrestore(&priv->lock, flags);
1046 path_free(dev, path);
1049 __path_add(dev, path);
1051 ++dev->stats.tx_dropped;
1052 dev_kfree_skb_any(skb);
1055 spin_unlock_irqrestore(&priv->lock, flags);
1060 ipoib_dbg(priv, "Send unicast ARP to %08x\n",
1061 be32_to_cpu(sa_path_get_dlid(&path->pathrec)));
1063 spin_unlock_irqrestore(&priv->lock, flags);
1064 path->ah->last_send = rn->send(dev, skb, path->ah->ah,
1065 IPOIB_QPN(phdr->hwaddr));
1067 } else if ((path->query || !path_rec_start(dev, path)) &&
1068 skb_queue_len(&path->queue) < IPOIB_MAX_PATH_REC_QUEUE) {
1069 push_pseudo_header(skb, phdr->hwaddr);
1070 __skb_queue_tail(&path->queue, skb);
1072 ++dev->stats.tx_dropped;
1073 dev_kfree_skb_any(skb);
1076 spin_unlock_irqrestore(&priv->lock, flags);
1079 static int ipoib_start_xmit(struct sk_buff *skb, struct net_device *dev)
1081 struct ipoib_dev_priv *priv = ipoib_priv(dev);
1082 struct rdma_netdev *rn = netdev_priv(dev);
1083 struct ipoib_neigh *neigh;
1084 struct ipoib_pseudo_header *phdr;
1085 struct ipoib_header *header;
1086 unsigned long flags;
1088 phdr = (struct ipoib_pseudo_header *) skb->data;
1089 skb_pull(skb, sizeof(*phdr));
1090 header = (struct ipoib_header *) skb->data;
1092 if (unlikely(phdr->hwaddr[4] == 0xff)) {
1093 /* multicast, arrange "if" according to probability */
1094 if ((header->proto != htons(ETH_P_IP)) &&
1095 (header->proto != htons(ETH_P_IPV6)) &&
1096 (header->proto != htons(ETH_P_ARP)) &&
1097 (header->proto != htons(ETH_P_RARP)) &&
1098 (header->proto != htons(ETH_P_TIPC))) {
1099 /* ethertype not supported by IPoIB */
1100 ++dev->stats.tx_dropped;
1101 dev_kfree_skb_any(skb);
1102 return NETDEV_TX_OK;
1104 /* Add in the P_Key for multicast*/
1105 phdr->hwaddr[8] = (priv->pkey >> 8) & 0xff;
1106 phdr->hwaddr[9] = priv->pkey & 0xff;
1108 neigh = ipoib_neigh_get(dev, phdr->hwaddr);
1110 goto send_using_neigh;
1111 ipoib_mcast_send(dev, phdr->hwaddr, skb);
1112 return NETDEV_TX_OK;
1115 /* unicast, arrange "switch" according to probability */
1116 switch (header->proto) {
1117 case htons(ETH_P_IP):
1118 case htons(ETH_P_IPV6):
1119 case htons(ETH_P_TIPC):
1120 neigh = ipoib_neigh_get(dev, phdr->hwaddr);
1121 if (unlikely(!neigh)) {
1122 neigh = neigh_add_path(skb, phdr->hwaddr, dev);
1124 return NETDEV_TX_OK;
1127 case htons(ETH_P_ARP):
1128 case htons(ETH_P_RARP):
1129 /* for unicast ARP and RARP should always perform path find */
1130 unicast_arp_send(skb, dev, phdr);
1131 return NETDEV_TX_OK;
1133 /* ethertype not supported by IPoIB */
1134 ++dev->stats.tx_dropped;
1135 dev_kfree_skb_any(skb);
1136 return NETDEV_TX_OK;
1140 /* note we now hold a ref to neigh */
1141 if (ipoib_cm_get(neigh)) {
1142 if (ipoib_cm_up(neigh)) {
1143 ipoib_cm_send(dev, skb, ipoib_cm_get(neigh));
1146 } else if (neigh->ah) {
1147 neigh->ah->last_send = rn->send(dev, skb, neigh->ah->ah,
1148 IPOIB_QPN(phdr->hwaddr));
1152 if (skb_queue_len(&neigh->queue) < IPOIB_MAX_PATH_REC_QUEUE) {
1153 push_pseudo_header(skb, phdr->hwaddr);
1154 spin_lock_irqsave(&priv->lock, flags);
1155 __skb_queue_tail(&neigh->queue, skb);
1156 spin_unlock_irqrestore(&priv->lock, flags);
1158 ++dev->stats.tx_dropped;
1159 dev_kfree_skb_any(skb);
1163 ipoib_neigh_put(neigh);
1165 return NETDEV_TX_OK;
1168 static void ipoib_timeout(struct net_device *dev)
1170 struct ipoib_dev_priv *priv = ipoib_priv(dev);
1172 ipoib_warn(priv, "transmit timeout: latency %d msecs\n",
1173 jiffies_to_msecs(jiffies - dev_trans_start(dev)));
1174 ipoib_warn(priv, "queue stopped %d, tx_head %u, tx_tail %u\n",
1175 netif_queue_stopped(dev),
1176 priv->tx_head, priv->tx_tail);
1177 /* XXX reset QP, etc. */
1180 static int ipoib_hard_header(struct sk_buff *skb,
1181 struct net_device *dev,
1182 unsigned short type,
1183 const void *daddr, const void *saddr, unsigned len)
1185 struct ipoib_header *header;
1187 header = skb_push(skb, sizeof *header);
1189 header->proto = htons(type);
1190 header->reserved = 0;
1193 * we don't rely on dst_entry structure, always stuff the
1194 * destination address into skb hard header so we can figure out where
1195 * to send the packet later.
1197 push_pseudo_header(skb, daddr);
1199 return IPOIB_HARD_LEN;
1202 static void ipoib_set_mcast_list(struct net_device *dev)
1204 struct ipoib_dev_priv *priv = ipoib_priv(dev);
1206 if (!test_bit(IPOIB_FLAG_OPER_UP, &priv->flags)) {
1207 ipoib_dbg(priv, "IPOIB_FLAG_OPER_UP not set");
1211 queue_work(priv->wq, &priv->restart_task);
1214 static int ipoib_get_iflink(const struct net_device *dev)
1216 struct ipoib_dev_priv *priv = ipoib_priv(dev);
1218 /* parent interface */
1219 if (!test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags))
1220 return dev->ifindex;
1222 /* child/vlan interface */
1223 return priv->parent->ifindex;
1226 static u32 ipoib_addr_hash(struct ipoib_neigh_hash *htbl, u8 *daddr)
1229 * Use only the address parts that contributes to spreading
1230 * The subnet prefix is not used as one can not connect to
1231 * same remote port (GUID) using the same remote QPN via two
1232 * different subnets.
1234 /* qpn octets[1:4) & port GUID octets[12:20) */
1235 u32 *d32 = (u32 *) daddr;
1238 hv = jhash_3words(d32[3], d32[4], IPOIB_QPN_MASK & d32[0], 0);
1239 return hv & htbl->mask;
1242 struct ipoib_neigh *ipoib_neigh_get(struct net_device *dev, u8 *daddr)
1244 struct ipoib_dev_priv *priv = ipoib_priv(dev);
1245 struct ipoib_neigh_table *ntbl = &priv->ntbl;
1246 struct ipoib_neigh_hash *htbl;
1247 struct ipoib_neigh *neigh = NULL;
1252 htbl = rcu_dereference_bh(ntbl->htbl);
1257 hash_val = ipoib_addr_hash(htbl, daddr);
1258 for (neigh = rcu_dereference_bh(htbl->buckets[hash_val]);
1260 neigh = rcu_dereference_bh(neigh->hnext)) {
1261 if (memcmp(daddr, neigh->daddr, INFINIBAND_ALEN) == 0) {
1262 /* found, take one ref on behalf of the caller */
1263 if (!atomic_inc_not_zero(&neigh->refcnt)) {
1269 if (likely(skb_queue_len(&neigh->queue) < IPOIB_MAX_PATH_REC_QUEUE))
1270 neigh->alive = jiffies;
1276 rcu_read_unlock_bh();
1280 static void __ipoib_reap_neigh(struct ipoib_dev_priv *priv)
1282 struct ipoib_neigh_table *ntbl = &priv->ntbl;
1283 struct ipoib_neigh_hash *htbl;
1284 unsigned long neigh_obsolete;
1286 unsigned long flags;
1288 LIST_HEAD(remove_list);
1290 if (test_bit(IPOIB_STOP_NEIGH_GC, &priv->flags))
1293 spin_lock_irqsave(&priv->lock, flags);
1295 htbl = rcu_dereference_protected(ntbl->htbl,
1296 lockdep_is_held(&priv->lock));
1301 /* neigh is obsolete if it was idle for two GC periods */
1302 dt = 2 * arp_tbl.gc_interval;
1303 neigh_obsolete = jiffies - dt;
1304 /* handle possible race condition */
1305 if (test_bit(IPOIB_STOP_NEIGH_GC, &priv->flags))
1308 for (i = 0; i < htbl->size; i++) {
1309 struct ipoib_neigh *neigh;
1310 struct ipoib_neigh __rcu **np = &htbl->buckets[i];
1312 while ((neigh = rcu_dereference_protected(*np,
1313 lockdep_is_held(&priv->lock))) != NULL) {
1314 /* was the neigh idle for two GC periods */
1315 if (time_after(neigh_obsolete, neigh->alive)) {
1317 ipoib_check_and_add_mcast_sendonly(priv, neigh->daddr + 4, &remove_list);
1319 rcu_assign_pointer(*np,
1320 rcu_dereference_protected(neigh->hnext,
1321 lockdep_is_held(&priv->lock)));
1322 /* remove from path/mc list */
1323 list_del_init(&neigh->list);
1324 call_rcu(&neigh->rcu, ipoib_neigh_reclaim);
1333 spin_unlock_irqrestore(&priv->lock, flags);
1334 ipoib_mcast_remove_list(&remove_list);
1337 static void ipoib_reap_neigh(struct work_struct *work)
1339 struct ipoib_dev_priv *priv =
1340 container_of(work, struct ipoib_dev_priv, neigh_reap_task.work);
1342 __ipoib_reap_neigh(priv);
1344 if (!test_bit(IPOIB_STOP_NEIGH_GC, &priv->flags))
1345 queue_delayed_work(priv->wq, &priv->neigh_reap_task,
1346 arp_tbl.gc_interval);
1350 static struct ipoib_neigh *ipoib_neigh_ctor(u8 *daddr,
1351 struct net_device *dev)
1353 struct ipoib_neigh *neigh;
1355 neigh = kzalloc(sizeof *neigh, GFP_ATOMIC);
1360 memcpy(&neigh->daddr, daddr, sizeof(neigh->daddr));
1361 skb_queue_head_init(&neigh->queue);
1362 INIT_LIST_HEAD(&neigh->list);
1363 ipoib_cm_set(neigh, NULL);
1364 /* one ref on behalf of the caller */
1365 atomic_set(&neigh->refcnt, 1);
1370 struct ipoib_neigh *ipoib_neigh_alloc(u8 *daddr,
1371 struct net_device *dev)
1373 struct ipoib_dev_priv *priv = ipoib_priv(dev);
1374 struct ipoib_neigh_table *ntbl = &priv->ntbl;
1375 struct ipoib_neigh_hash *htbl;
1376 struct ipoib_neigh *neigh;
1379 htbl = rcu_dereference_protected(ntbl->htbl,
1380 lockdep_is_held(&priv->lock));
1386 /* need to add a new neigh, but maybe some other thread succeeded?
1387 * recalc hash, maybe hash resize took place so we do a search
1389 hash_val = ipoib_addr_hash(htbl, daddr);
1390 for (neigh = rcu_dereference_protected(htbl->buckets[hash_val],
1391 lockdep_is_held(&priv->lock));
1393 neigh = rcu_dereference_protected(neigh->hnext,
1394 lockdep_is_held(&priv->lock))) {
1395 if (memcmp(daddr, neigh->daddr, INFINIBAND_ALEN) == 0) {
1396 /* found, take one ref on behalf of the caller */
1397 if (!atomic_inc_not_zero(&neigh->refcnt)) {
1402 neigh->alive = jiffies;
1407 neigh = ipoib_neigh_ctor(daddr, dev);
1411 /* one ref on behalf of the hash table */
1412 atomic_inc(&neigh->refcnt);
1413 neigh->alive = jiffies;
1415 rcu_assign_pointer(neigh->hnext,
1416 rcu_dereference_protected(htbl->buckets[hash_val],
1417 lockdep_is_held(&priv->lock)));
1418 rcu_assign_pointer(htbl->buckets[hash_val], neigh);
1419 atomic_inc(&ntbl->entries);
1426 void ipoib_neigh_dtor(struct ipoib_neigh *neigh)
1428 /* neigh reference count was dropprd to zero */
1429 struct net_device *dev = neigh->dev;
1430 struct ipoib_dev_priv *priv = ipoib_priv(dev);
1431 struct sk_buff *skb;
1433 ipoib_put_ah(neigh->ah);
1434 while ((skb = __skb_dequeue(&neigh->queue))) {
1435 ++dev->stats.tx_dropped;
1436 dev_kfree_skb_any(skb);
1438 if (ipoib_cm_get(neigh))
1439 ipoib_cm_destroy_tx(ipoib_cm_get(neigh));
1440 ipoib_dbg(ipoib_priv(dev),
1441 "neigh free for %06x %pI6\n",
1442 IPOIB_QPN(neigh->daddr),
1445 if (atomic_dec_and_test(&priv->ntbl.entries)) {
1446 if (test_bit(IPOIB_NEIGH_TBL_FLUSH, &priv->flags))
1447 complete(&priv->ntbl.flushed);
1451 static void ipoib_neigh_reclaim(struct rcu_head *rp)
1453 /* Called as a result of removal from hash table */
1454 struct ipoib_neigh *neigh = container_of(rp, struct ipoib_neigh, rcu);
1455 /* note TX context may hold another ref */
1456 ipoib_neigh_put(neigh);
1459 void ipoib_neigh_free(struct ipoib_neigh *neigh)
1461 struct net_device *dev = neigh->dev;
1462 struct ipoib_dev_priv *priv = ipoib_priv(dev);
1463 struct ipoib_neigh_table *ntbl = &priv->ntbl;
1464 struct ipoib_neigh_hash *htbl;
1465 struct ipoib_neigh __rcu **np;
1466 struct ipoib_neigh *n;
1469 htbl = rcu_dereference_protected(ntbl->htbl,
1470 lockdep_is_held(&priv->lock));
1474 hash_val = ipoib_addr_hash(htbl, neigh->daddr);
1475 np = &htbl->buckets[hash_val];
1476 for (n = rcu_dereference_protected(*np,
1477 lockdep_is_held(&priv->lock));
1479 n = rcu_dereference_protected(*np,
1480 lockdep_is_held(&priv->lock))) {
1483 rcu_assign_pointer(*np,
1484 rcu_dereference_protected(neigh->hnext,
1485 lockdep_is_held(&priv->lock)));
1486 /* remove from parent list */
1487 list_del_init(&neigh->list);
1488 call_rcu(&neigh->rcu, ipoib_neigh_reclaim);
1496 static int ipoib_neigh_hash_init(struct ipoib_dev_priv *priv)
1498 struct ipoib_neigh_table *ntbl = &priv->ntbl;
1499 struct ipoib_neigh_hash *htbl;
1500 struct ipoib_neigh __rcu **buckets;
1503 clear_bit(IPOIB_NEIGH_TBL_FLUSH, &priv->flags);
1505 htbl = kzalloc(sizeof(*htbl), GFP_KERNEL);
1508 set_bit(IPOIB_STOP_NEIGH_GC, &priv->flags);
1509 size = roundup_pow_of_two(arp_tbl.gc_thresh3);
1510 buckets = kzalloc(size * sizeof(*buckets), GFP_KERNEL);
1516 htbl->mask = (size - 1);
1517 htbl->buckets = buckets;
1518 RCU_INIT_POINTER(ntbl->htbl, htbl);
1520 atomic_set(&ntbl->entries, 0);
1522 /* start garbage collection */
1523 clear_bit(IPOIB_STOP_NEIGH_GC, &priv->flags);
1524 queue_delayed_work(priv->wq, &priv->neigh_reap_task,
1525 arp_tbl.gc_interval);
1530 static void neigh_hash_free_rcu(struct rcu_head *head)
1532 struct ipoib_neigh_hash *htbl = container_of(head,
1533 struct ipoib_neigh_hash,
1535 struct ipoib_neigh __rcu **buckets = htbl->buckets;
1536 struct ipoib_neigh_table *ntbl = htbl->ntbl;
1540 complete(&ntbl->deleted);
1543 void ipoib_del_neighs_by_gid(struct net_device *dev, u8 *gid)
1545 struct ipoib_dev_priv *priv = ipoib_priv(dev);
1546 struct ipoib_neigh_table *ntbl = &priv->ntbl;
1547 struct ipoib_neigh_hash *htbl;
1548 unsigned long flags;
1551 /* remove all neigh connected to a given path or mcast */
1552 spin_lock_irqsave(&priv->lock, flags);
1554 htbl = rcu_dereference_protected(ntbl->htbl,
1555 lockdep_is_held(&priv->lock));
1560 for (i = 0; i < htbl->size; i++) {
1561 struct ipoib_neigh *neigh;
1562 struct ipoib_neigh __rcu **np = &htbl->buckets[i];
1564 while ((neigh = rcu_dereference_protected(*np,
1565 lockdep_is_held(&priv->lock))) != NULL) {
1566 /* delete neighs belong to this parent */
1567 if (!memcmp(gid, neigh->daddr + 4, sizeof (union ib_gid))) {
1568 rcu_assign_pointer(*np,
1569 rcu_dereference_protected(neigh->hnext,
1570 lockdep_is_held(&priv->lock)));
1571 /* remove from parent list */
1572 list_del_init(&neigh->list);
1573 call_rcu(&neigh->rcu, ipoib_neigh_reclaim);
1581 spin_unlock_irqrestore(&priv->lock, flags);
1584 static void ipoib_flush_neighs(struct ipoib_dev_priv *priv)
1586 struct ipoib_neigh_table *ntbl = &priv->ntbl;
1587 struct ipoib_neigh_hash *htbl;
1588 unsigned long flags;
1589 int i, wait_flushed = 0;
1591 init_completion(&priv->ntbl.flushed);
1592 set_bit(IPOIB_NEIGH_TBL_FLUSH, &priv->flags);
1594 spin_lock_irqsave(&priv->lock, flags);
1596 htbl = rcu_dereference_protected(ntbl->htbl,
1597 lockdep_is_held(&priv->lock));
1601 wait_flushed = atomic_read(&priv->ntbl.entries);
1605 for (i = 0; i < htbl->size; i++) {
1606 struct ipoib_neigh *neigh;
1607 struct ipoib_neigh __rcu **np = &htbl->buckets[i];
1609 while ((neigh = rcu_dereference_protected(*np,
1610 lockdep_is_held(&priv->lock))) != NULL) {
1611 rcu_assign_pointer(*np,
1612 rcu_dereference_protected(neigh->hnext,
1613 lockdep_is_held(&priv->lock)));
1614 /* remove from path/mc list */
1615 list_del_init(&neigh->list);
1616 call_rcu(&neigh->rcu, ipoib_neigh_reclaim);
1621 rcu_assign_pointer(ntbl->htbl, NULL);
1622 call_rcu(&htbl->rcu, neigh_hash_free_rcu);
1625 spin_unlock_irqrestore(&priv->lock, flags);
1627 wait_for_completion(&priv->ntbl.flushed);
1630 static void ipoib_neigh_hash_uninit(struct net_device *dev)
1632 struct ipoib_dev_priv *priv = ipoib_priv(dev);
1635 ipoib_dbg(priv, "ipoib_neigh_hash_uninit\n");
1636 init_completion(&priv->ntbl.deleted);
1638 /* Stop GC if called at init fail need to cancel work */
1639 stopped = test_and_set_bit(IPOIB_STOP_NEIGH_GC, &priv->flags);
1641 cancel_delayed_work(&priv->neigh_reap_task);
1643 ipoib_flush_neighs(priv);
1645 wait_for_completion(&priv->ntbl.deleted);
1648 static void ipoib_dev_uninit_default(struct net_device *dev)
1650 struct ipoib_dev_priv *priv = ipoib_priv(dev);
1652 ipoib_transport_dev_cleanup(dev);
1654 netif_napi_del(&priv->napi);
1656 ipoib_cm_dev_cleanup(dev);
1658 kfree(priv->rx_ring);
1659 vfree(priv->tx_ring);
1661 priv->rx_ring = NULL;
1662 priv->tx_ring = NULL;
1665 static int ipoib_dev_init_default(struct net_device *dev)
1667 struct ipoib_dev_priv *priv = ipoib_priv(dev);
1669 netif_napi_add(dev, &priv->napi, ipoib_poll, NAPI_POLL_WEIGHT);
1671 /* Allocate RX/TX "rings" to hold queued skbs */
1672 priv->rx_ring = kzalloc(ipoib_recvq_size * sizeof *priv->rx_ring,
1677 priv->tx_ring = vzalloc(ipoib_sendq_size * sizeof *priv->tx_ring);
1678 if (!priv->tx_ring) {
1679 printk(KERN_WARNING "%s: failed to allocate TX ring (%d entries)\n",
1680 priv->ca->name, ipoib_sendq_size);
1681 goto out_rx_ring_cleanup;
1684 /* priv->tx_head, tx_tail & tx_outstanding are already 0 */
1686 if (ipoib_transport_dev_init(dev, priv->ca)) {
1687 pr_warn("%s: ipoib_transport_dev_init failed\n",
1689 goto out_tx_ring_cleanup;
1692 /* after qp created set dev address */
1693 priv->dev->dev_addr[1] = (priv->qp->qp_num >> 16) & 0xff;
1694 priv->dev->dev_addr[2] = (priv->qp->qp_num >> 8) & 0xff;
1695 priv->dev->dev_addr[3] = (priv->qp->qp_num) & 0xff;
1697 setup_timer(&priv->poll_timer, ipoib_ib_tx_timer_func,
1698 (unsigned long)dev);
1702 out_tx_ring_cleanup:
1703 vfree(priv->tx_ring);
1705 out_rx_ring_cleanup:
1706 kfree(priv->rx_ring);
1709 netif_napi_del(&priv->napi);
1713 static int ipoib_ioctl(struct net_device *dev, struct ifreq *ifr,
1716 struct ipoib_dev_priv *priv = ipoib_priv(dev);
1718 if (!priv->rn_ops->ndo_do_ioctl)
1721 return priv->rn_ops->ndo_do_ioctl(dev, ifr, cmd);
1724 int ipoib_dev_init(struct net_device *dev, struct ib_device *ca, int port)
1726 struct ipoib_dev_priv *priv = ipoib_priv(dev);
1734 * the various IPoIB tasks assume they will never race against
1735 * themselves, so always use a single thread workqueue
1737 priv->wq = alloc_ordered_workqueue("ipoib_wq", WQ_MEM_RECLAIM);
1739 pr_warn("%s: failed to allocate device WQ\n", dev->name);
1743 /* create pd, which used both for control and datapath*/
1744 priv->pd = ib_alloc_pd(priv->ca, 0);
1745 if (IS_ERR(priv->pd)) {
1746 pr_warn("%s: failed to allocate PD\n", ca->name);
1750 ret = priv->rn_ops->ndo_init(dev);
1752 pr_warn("%s failed to init HW resource\n", dev->name);
1756 ret = ipoib_neigh_hash_init(priv);
1758 pr_warn("%s failed to init neigh hash\n", dev->name);
1759 goto out_dev_uninit;
1762 if (dev->flags & IFF_UP) {
1763 if (ipoib_ib_dev_open(dev)) {
1764 pr_warn("%s failed to open device\n", dev->name);
1766 goto out_dev_uninit;
1773 ipoib_ib_dev_cleanup(dev);
1777 ib_dealloc_pd(priv->pd);
1783 destroy_workqueue(priv->wq);
1791 void ipoib_dev_cleanup(struct net_device *dev)
1793 struct ipoib_dev_priv *priv = ipoib_priv(dev), *cpriv, *tcpriv;
1798 /* Delete any child interfaces first */
1799 list_for_each_entry_safe(cpriv, tcpriv, &priv->child_intfs, list) {
1800 /* Stop GC on child */
1801 set_bit(IPOIB_STOP_NEIGH_GC, &cpriv->flags);
1802 cancel_delayed_work(&cpriv->neigh_reap_task);
1803 unregister_netdevice_queue(cpriv->dev, &head);
1805 unregister_netdevice_many(&head);
1807 ipoib_neigh_hash_uninit(dev);
1809 ipoib_ib_dev_cleanup(dev);
1811 /* no more works over the priv->wq */
1813 flush_workqueue(priv->wq);
1814 destroy_workqueue(priv->wq);
1819 static int ipoib_set_vf_link_state(struct net_device *dev, int vf, int link_state)
1821 struct ipoib_dev_priv *priv = ipoib_priv(dev);
1823 return ib_set_vf_link_state(priv->ca, vf, priv->port, link_state);
1826 static int ipoib_get_vf_config(struct net_device *dev, int vf,
1827 struct ifla_vf_info *ivf)
1829 struct ipoib_dev_priv *priv = ipoib_priv(dev);
1832 err = ib_get_vf_config(priv->ca, vf, priv->port, ivf);
1837 memcpy(ivf->mac, dev->dev_addr, dev->addr_len);
1842 static int ipoib_set_vf_guid(struct net_device *dev, int vf, u64 guid, int type)
1844 struct ipoib_dev_priv *priv = ipoib_priv(dev);
1846 if (type != IFLA_VF_IB_NODE_GUID && type != IFLA_VF_IB_PORT_GUID)
1849 return ib_set_vf_guid(priv->ca, vf, priv->port, guid, type);
1852 static int ipoib_get_vf_stats(struct net_device *dev, int vf,
1853 struct ifla_vf_stats *vf_stats)
1855 struct ipoib_dev_priv *priv = ipoib_priv(dev);
1857 return ib_get_vf_stats(priv->ca, vf, priv->port, vf_stats);
1860 static const struct header_ops ipoib_header_ops = {
1861 .create = ipoib_hard_header,
1864 static const struct net_device_ops ipoib_netdev_ops_pf = {
1865 .ndo_uninit = ipoib_uninit,
1866 .ndo_open = ipoib_open,
1867 .ndo_stop = ipoib_stop,
1868 .ndo_change_mtu = ipoib_change_mtu,
1869 .ndo_fix_features = ipoib_fix_features,
1870 .ndo_start_xmit = ipoib_start_xmit,
1871 .ndo_tx_timeout = ipoib_timeout,
1872 .ndo_set_rx_mode = ipoib_set_mcast_list,
1873 .ndo_get_iflink = ipoib_get_iflink,
1874 .ndo_set_vf_link_state = ipoib_set_vf_link_state,
1875 .ndo_get_vf_config = ipoib_get_vf_config,
1876 .ndo_get_vf_stats = ipoib_get_vf_stats,
1877 .ndo_set_vf_guid = ipoib_set_vf_guid,
1878 .ndo_set_mac_address = ipoib_set_mac,
1879 .ndo_get_stats64 = ipoib_get_stats,
1880 .ndo_do_ioctl = ipoib_ioctl,
1883 static const struct net_device_ops ipoib_netdev_ops_vf = {
1884 .ndo_uninit = ipoib_uninit,
1885 .ndo_open = ipoib_open,
1886 .ndo_stop = ipoib_stop,
1887 .ndo_change_mtu = ipoib_change_mtu,
1888 .ndo_fix_features = ipoib_fix_features,
1889 .ndo_start_xmit = ipoib_start_xmit,
1890 .ndo_tx_timeout = ipoib_timeout,
1891 .ndo_set_rx_mode = ipoib_set_mcast_list,
1892 .ndo_get_iflink = ipoib_get_iflink,
1893 .ndo_get_stats64 = ipoib_get_stats,
1894 .ndo_do_ioctl = ipoib_ioctl,
1897 void ipoib_setup_common(struct net_device *dev)
1899 dev->header_ops = &ipoib_header_ops;
1901 ipoib_set_ethtool_ops(dev);
1903 dev->watchdog_timeo = HZ;
1905 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
1907 dev->hard_header_len = IPOIB_HARD_LEN;
1908 dev->addr_len = INFINIBAND_ALEN;
1909 dev->type = ARPHRD_INFINIBAND;
1910 dev->tx_queue_len = ipoib_sendq_size * 2;
1911 dev->features = (NETIF_F_VLAN_CHALLENGED |
1913 netif_keep_dst(dev);
1915 memcpy(dev->broadcast, ipv4_bcast_addr, INFINIBAND_ALEN);
1918 static void ipoib_build_priv(struct net_device *dev)
1920 struct ipoib_dev_priv *priv = ipoib_priv(dev);
1923 spin_lock_init(&priv->lock);
1924 init_rwsem(&priv->vlan_rwsem);
1925 mutex_init(&priv->mcast_mutex);
1926 mutex_init(&priv->sysfs_mutex);
1928 INIT_LIST_HEAD(&priv->path_list);
1929 INIT_LIST_HEAD(&priv->child_intfs);
1930 INIT_LIST_HEAD(&priv->dead_ahs);
1931 INIT_LIST_HEAD(&priv->multicast_list);
1933 INIT_DELAYED_WORK(&priv->mcast_task, ipoib_mcast_join_task);
1934 INIT_WORK(&priv->carrier_on_task, ipoib_mcast_carrier_on_task);
1935 INIT_WORK(&priv->flush_light, ipoib_ib_dev_flush_light);
1936 INIT_WORK(&priv->flush_normal, ipoib_ib_dev_flush_normal);
1937 INIT_WORK(&priv->flush_heavy, ipoib_ib_dev_flush_heavy);
1938 INIT_WORK(&priv->restart_task, ipoib_mcast_restart_task);
1939 INIT_DELAYED_WORK(&priv->ah_reap_task, ipoib_reap_ah);
1940 INIT_DELAYED_WORK(&priv->neigh_reap_task, ipoib_reap_neigh);
1943 static const struct net_device_ops ipoib_netdev_default_pf = {
1944 .ndo_init = ipoib_dev_init_default,
1945 .ndo_uninit = ipoib_dev_uninit_default,
1946 .ndo_open = ipoib_ib_dev_open_default,
1947 .ndo_stop = ipoib_ib_dev_stop_default,
1950 static struct net_device
1951 *ipoib_create_netdev_default(struct ib_device *hca,
1953 unsigned char name_assign_type,
1954 void (*setup)(struct net_device *))
1956 struct net_device *dev;
1957 struct rdma_netdev *rn;
1959 dev = alloc_netdev((int)sizeof(struct rdma_netdev),
1961 name_assign_type, setup);
1965 rn = netdev_priv(dev);
1967 rn->send = ipoib_send;
1968 rn->attach_mcast = ipoib_mcast_attach;
1969 rn->detach_mcast = ipoib_mcast_detach;
1970 rn->free_rdma_netdev = free_netdev;
1973 dev->netdev_ops = &ipoib_netdev_default_pf;
1978 static struct net_device *ipoib_get_netdev(struct ib_device *hca, u8 port,
1981 struct net_device *dev;
1983 if (hca->alloc_rdma_netdev) {
1984 dev = hca->alloc_rdma_netdev(hca, port,
1985 RDMA_NETDEV_IPOIB, name,
1987 ipoib_setup_common);
1988 if (IS_ERR_OR_NULL(dev) && PTR_ERR(dev) != -EOPNOTSUPP)
1992 if (!hca->alloc_rdma_netdev || PTR_ERR(dev) == -EOPNOTSUPP)
1993 dev = ipoib_create_netdev_default(hca, name, NET_NAME_UNKNOWN,
1994 ipoib_setup_common);
1999 struct ipoib_dev_priv *ipoib_intf_alloc(struct ib_device *hca, u8 port,
2002 struct net_device *dev;
2003 struct ipoib_dev_priv *priv;
2004 struct rdma_netdev *rn;
2006 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
2010 dev = ipoib_get_netdev(hca, port, name);
2014 priv->rn_ops = dev->netdev_ops;
2016 /* fixme : should be after the query_cap */
2017 if (priv->hca_caps & IB_DEVICE_VIRTUAL_FUNCTION)
2018 dev->netdev_ops = &ipoib_netdev_ops_vf;
2020 dev->netdev_ops = &ipoib_netdev_ops_pf;
2022 rn = netdev_priv(dev);
2023 rn->clnt_priv = priv;
2024 ipoib_build_priv(dev);
2032 static ssize_t show_pkey(struct device *dev,
2033 struct device_attribute *attr, char *buf)
2035 struct net_device *ndev = to_net_dev(dev);
2036 struct ipoib_dev_priv *priv = ipoib_priv(ndev);
2038 return sprintf(buf, "0x%04x\n", priv->pkey);
2040 static DEVICE_ATTR(pkey, S_IRUGO, show_pkey, NULL);
2042 static ssize_t show_umcast(struct device *dev,
2043 struct device_attribute *attr, char *buf)
2045 struct net_device *ndev = to_net_dev(dev);
2046 struct ipoib_dev_priv *priv = ipoib_priv(ndev);
2048 return sprintf(buf, "%d\n", test_bit(IPOIB_FLAG_UMCAST, &priv->flags));
2051 void ipoib_set_umcast(struct net_device *ndev, int umcast_val)
2053 struct ipoib_dev_priv *priv = ipoib_priv(ndev);
2055 if (umcast_val > 0) {
2056 set_bit(IPOIB_FLAG_UMCAST, &priv->flags);
2057 ipoib_warn(priv, "ignoring multicast groups joined directly "
2060 clear_bit(IPOIB_FLAG_UMCAST, &priv->flags);
2063 static ssize_t set_umcast(struct device *dev,
2064 struct device_attribute *attr,
2065 const char *buf, size_t count)
2067 unsigned long umcast_val = simple_strtoul(buf, NULL, 0);
2069 ipoib_set_umcast(to_net_dev(dev), umcast_val);
2073 static DEVICE_ATTR(umcast, S_IWUSR | S_IRUGO, show_umcast, set_umcast);
2075 int ipoib_add_umcast_attr(struct net_device *dev)
2077 return device_create_file(&dev->dev, &dev_attr_umcast);
2080 static void set_base_guid(struct ipoib_dev_priv *priv, union ib_gid *gid)
2082 struct ipoib_dev_priv *child_priv;
2083 struct net_device *netdev = priv->dev;
2085 netif_addr_lock_bh(netdev);
2087 memcpy(&priv->local_gid.global.interface_id,
2088 &gid->global.interface_id,
2089 sizeof(gid->global.interface_id));
2090 memcpy(netdev->dev_addr + 4, &priv->local_gid, sizeof(priv->local_gid));
2091 clear_bit(IPOIB_FLAG_DEV_ADDR_SET, &priv->flags);
2093 netif_addr_unlock_bh(netdev);
2095 if (!test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags)) {
2096 down_read(&priv->vlan_rwsem);
2097 list_for_each_entry(child_priv, &priv->child_intfs, list)
2098 set_base_guid(child_priv, gid);
2099 up_read(&priv->vlan_rwsem);
2103 static int ipoib_check_lladdr(struct net_device *dev,
2104 struct sockaddr_storage *ss)
2106 union ib_gid *gid = (union ib_gid *)(ss->__data + 4);
2109 netif_addr_lock_bh(dev);
2111 /* Make sure the QPN, reserved and subnet prefix match the current
2112 * lladdr, it also makes sure the lladdr is unicast.
2114 if (memcmp(dev->dev_addr, ss->__data,
2115 4 + sizeof(gid->global.subnet_prefix)) ||
2116 gid->global.interface_id == 0)
2119 netif_addr_unlock_bh(dev);
2124 static int ipoib_set_mac(struct net_device *dev, void *addr)
2126 struct ipoib_dev_priv *priv = ipoib_priv(dev);
2127 struct sockaddr_storage *ss = addr;
2130 if (!(dev->priv_flags & IFF_LIVE_ADDR_CHANGE) && netif_running(dev))
2133 ret = ipoib_check_lladdr(dev, ss);
2137 set_base_guid(priv, (union ib_gid *)(ss->__data + 4));
2139 queue_work(ipoib_workqueue, &priv->flush_light);
2144 static ssize_t create_child(struct device *dev,
2145 struct device_attribute *attr,
2146 const char *buf, size_t count)
2151 if (sscanf(buf, "%i", &pkey) != 1)
2154 if (pkey <= 0 || pkey > 0xffff || pkey == 0x8000)
2158 * Set the full membership bit, so that we join the right
2159 * broadcast group, etc.
2163 ret = ipoib_vlan_add(to_net_dev(dev), pkey);
2165 return ret ? ret : count;
2167 static DEVICE_ATTR(create_child, S_IWUSR, NULL, create_child);
2169 static ssize_t delete_child(struct device *dev,
2170 struct device_attribute *attr,
2171 const char *buf, size_t count)
2176 if (sscanf(buf, "%i", &pkey) != 1)
2179 if (pkey < 0 || pkey > 0xffff)
2182 ret = ipoib_vlan_delete(to_net_dev(dev), pkey);
2184 return ret ? ret : count;
2187 static DEVICE_ATTR(delete_child, S_IWUSR, NULL, delete_child);
2189 int ipoib_add_pkey_attr(struct net_device *dev)
2191 return device_create_file(&dev->dev, &dev_attr_pkey);
2194 void ipoib_set_dev_features(struct ipoib_dev_priv *priv, struct ib_device *hca)
2196 priv->hca_caps = hca->attrs.device_cap_flags;
2198 if (priv->hca_caps & IB_DEVICE_UD_IP_CSUM) {
2199 priv->dev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_RXCSUM;
2201 if (priv->hca_caps & IB_DEVICE_UD_TSO)
2202 priv->dev->hw_features |= NETIF_F_TSO;
2204 priv->dev->features |= priv->dev->hw_features;
2208 static struct net_device *ipoib_add_port(const char *format,
2209 struct ib_device *hca, u8 port)
2211 struct ipoib_dev_priv *priv;
2212 struct ib_port_attr attr;
2213 struct rdma_netdev *rn;
2214 int result = -ENOMEM;
2216 priv = ipoib_intf_alloc(hca, port, format);
2218 goto alloc_mem_failed;
2220 SET_NETDEV_DEV(priv->dev, hca->dev.parent);
2221 priv->dev->dev_id = port - 1;
2223 result = ib_query_port(hca, port, &attr);
2225 printk(KERN_WARNING "%s: ib_query_port %d failed\n",
2227 goto device_init_failed;
2230 priv->max_ib_mtu = ib_mtu_enum_to_int(attr.max_mtu);
2232 /* MTU will be reset when mcast join happens */
2233 priv->dev->mtu = IPOIB_UD_MTU(priv->max_ib_mtu);
2234 priv->mcast_mtu = priv->admin_mtu = priv->dev->mtu;
2235 priv->dev->max_mtu = IPOIB_CM_MTU;
2237 priv->dev->neigh_priv_len = sizeof(struct ipoib_neigh);
2239 result = ib_query_pkey(hca, port, 0, &priv->pkey);
2241 printk(KERN_WARNING "%s: ib_query_pkey port %d failed (ret = %d)\n",
2242 hca->name, port, result);
2243 goto device_init_failed;
2246 ipoib_set_dev_features(priv, hca);
2249 * Set the full membership bit, so that we join the right
2250 * broadcast group, etc.
2252 priv->pkey |= 0x8000;
2254 priv->dev->broadcast[8] = priv->pkey >> 8;
2255 priv->dev->broadcast[9] = priv->pkey & 0xff;
2257 result = ib_query_gid(hca, port, 0, &priv->local_gid, NULL);
2259 printk(KERN_WARNING "%s: ib_query_gid port %d failed (ret = %d)\n",
2260 hca->name, port, result);
2261 goto device_init_failed;
2264 memcpy(priv->dev->dev_addr + 4, priv->local_gid.raw,
2265 sizeof(union ib_gid));
2266 set_bit(IPOIB_FLAG_DEV_ADDR_SET, &priv->flags);
2268 result = ipoib_dev_init(priv->dev, hca, port);
2270 printk(KERN_WARNING "%s: failed to initialize port %d (ret = %d)\n",
2271 hca->name, port, result);
2272 goto device_init_failed;
2275 INIT_IB_EVENT_HANDLER(&priv->event_handler,
2276 priv->ca, ipoib_event);
2277 ib_register_event_handler(&priv->event_handler);
2279 /* call event handler to ensure pkey in sync */
2280 queue_work(ipoib_workqueue, &priv->flush_heavy);
2282 result = register_netdev(priv->dev);
2284 printk(KERN_WARNING "%s: couldn't register ipoib port %d; error %d\n",
2285 hca->name, port, result);
2286 goto register_failed;
2290 if (ipoib_cm_add_mode_attr(priv->dev))
2292 if (ipoib_add_pkey_attr(priv->dev))
2294 if (ipoib_add_umcast_attr(priv->dev))
2296 if (device_create_file(&priv->dev->dev, &dev_attr_create_child))
2298 if (device_create_file(&priv->dev->dev, &dev_attr_delete_child))
2304 unregister_netdev(priv->dev);
2307 ib_unregister_event_handler(&priv->event_handler);
2308 flush_workqueue(ipoib_workqueue);
2309 /* Stop GC if started before flush */
2310 set_bit(IPOIB_STOP_NEIGH_GC, &priv->flags);
2311 cancel_delayed_work(&priv->neigh_reap_task);
2312 flush_workqueue(priv->wq);
2313 ipoib_dev_cleanup(priv->dev);
2316 rn = netdev_priv(priv->dev);
2317 rn->free_rdma_netdev(priv->dev);
2321 return ERR_PTR(result);
2324 static void ipoib_add_one(struct ib_device *device)
2326 struct list_head *dev_list;
2327 struct net_device *dev;
2328 struct ipoib_dev_priv *priv;
2332 dev_list = kmalloc(sizeof *dev_list, GFP_KERNEL);
2336 INIT_LIST_HEAD(dev_list);
2338 for (p = rdma_start_port(device); p <= rdma_end_port(device); ++p) {
2339 if (!rdma_protocol_ib(device, p))
2341 dev = ipoib_add_port("ib%d", device, p);
2343 priv = ipoib_priv(dev);
2344 list_add_tail(&priv->list, dev_list);
2354 ib_set_client_data(device, &ipoib_client, dev_list);
2357 static void ipoib_remove_one(struct ib_device *device, void *client_data)
2359 struct ipoib_dev_priv *priv, *tmp, *cpriv, *tcpriv;
2360 struct list_head *dev_list = client_data;
2365 list_for_each_entry_safe(priv, tmp, dev_list, list) {
2366 struct rdma_netdev *parent_rn = netdev_priv(priv->dev);
2368 ib_unregister_event_handler(&priv->event_handler);
2369 flush_workqueue(ipoib_workqueue);
2371 /* mark interface in the middle of destruction */
2372 set_bit(IPOIB_FLAG_GOING_DOWN, &priv->flags);
2375 dev_change_flags(priv->dev, priv->dev->flags & ~IFF_UP);
2379 set_bit(IPOIB_STOP_NEIGH_GC, &priv->flags);
2380 cancel_delayed_work(&priv->neigh_reap_task);
2381 flush_workqueue(priv->wq);
2383 /* Wrap rtnl_lock/unlock with mutex to protect sysfs calls */
2384 mutex_lock(&priv->sysfs_mutex);
2385 unregister_netdev(priv->dev);
2386 mutex_unlock(&priv->sysfs_mutex);
2388 parent_rn->free_rdma_netdev(priv->dev);
2390 list_for_each_entry_safe(cpriv, tcpriv, &priv->child_intfs, list) {
2391 struct rdma_netdev *child_rn;
2393 child_rn = netdev_priv(cpriv->dev);
2394 child_rn->free_rdma_netdev(cpriv->dev);
2404 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
2405 static struct notifier_block ipoib_netdev_notifier = {
2406 .notifier_call = ipoib_netdev_event,
2410 static int __init ipoib_init_module(void)
2414 ipoib_recvq_size = roundup_pow_of_two(ipoib_recvq_size);
2415 ipoib_recvq_size = min(ipoib_recvq_size, IPOIB_MAX_QUEUE_SIZE);
2416 ipoib_recvq_size = max(ipoib_recvq_size, IPOIB_MIN_QUEUE_SIZE);
2418 ipoib_sendq_size = roundup_pow_of_two(ipoib_sendq_size);
2419 ipoib_sendq_size = min(ipoib_sendq_size, IPOIB_MAX_QUEUE_SIZE);
2420 ipoib_sendq_size = max3(ipoib_sendq_size, 2 * MAX_SEND_CQE, IPOIB_MIN_QUEUE_SIZE);
2421 #ifdef CONFIG_INFINIBAND_IPOIB_CM
2422 ipoib_max_conn_qp = min(ipoib_max_conn_qp, IPOIB_CM_MAX_CONN_QP);
2423 ipoib_max_conn_qp = max(ipoib_max_conn_qp, 0);
2427 * When copying small received packets, we only copy from the
2428 * linear data part of the SKB, so we rely on this condition.
2430 BUILD_BUG_ON(IPOIB_CM_COPYBREAK > IPOIB_CM_HEAD_SIZE);
2432 ret = ipoib_register_debugfs();
2437 * We create a global workqueue here that is used for all flush
2438 * operations. However, if you attempt to flush a workqueue
2439 * from a task on that same workqueue, it deadlocks the system.
2440 * We want to be able to flush the tasks associated with a
2441 * specific net device, so we also create a workqueue for each
2442 * netdevice. We queue up the tasks for that device only on
2443 * its private workqueue, and we only queue up flush events
2444 * on our global flush workqueue. This avoids the deadlocks.
2446 ipoib_workqueue = alloc_ordered_workqueue("ipoib_flush",
2448 if (!ipoib_workqueue) {
2453 ib_sa_register_client(&ipoib_sa_client);
2455 ret = ib_register_client(&ipoib_client);
2459 ret = ipoib_netlink_init();
2463 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
2464 register_netdevice_notifier(&ipoib_netdev_notifier);
2469 ib_unregister_client(&ipoib_client);
2472 ib_sa_unregister_client(&ipoib_sa_client);
2473 destroy_workqueue(ipoib_workqueue);
2476 ipoib_unregister_debugfs();
2481 static void __exit ipoib_cleanup_module(void)
2483 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
2484 unregister_netdevice_notifier(&ipoib_netdev_notifier);
2486 ipoib_netlink_fini();
2487 ib_unregister_client(&ipoib_client);
2488 ib_sa_unregister_client(&ipoib_sa_client);
2489 ipoib_unregister_debugfs();
2490 destroy_workqueue(ipoib_workqueue);
2493 module_init(ipoib_init_module);
2494 module_exit(ipoib_cleanup_module);