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
> IPOIB_UD_MTU(priv
->max_ib_mtu
))
255 priv
->admin_mtu
= new_mtu
;
257 if (priv
->mcast_mtu
< priv
->admin_mtu
)
258 ipoib_dbg(priv
, "MTU must be smaller than the underlying "
259 "link layer MTU - 4 (%u)\n", priv
->mcast_mtu
);
261 new_mtu
= min(priv
->mcast_mtu
, priv
->admin_mtu
);
263 if (priv
->rn_ops
->ndo_change_mtu
) {
264 bool carrier_status
= netif_carrier_ok(dev
);
266 netif_carrier_off(dev
);
268 /* notify lower level on the real mtu */
269 ret
= priv
->rn_ops
->ndo_change_mtu(dev
, new_mtu
);
272 netif_carrier_on(dev
);
280 static void ipoib_get_stats(struct net_device
*dev
,
281 struct rtnl_link_stats64
*stats
)
283 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
285 if (priv
->rn_ops
->ndo_get_stats64
)
286 priv
->rn_ops
->ndo_get_stats64(dev
, stats
);
288 netdev_stats_to_stats64(stats
, &dev
->stats
);
291 /* Called with an RCU read lock taken */
292 static bool ipoib_is_dev_match_addr_rcu(const struct sockaddr
*addr
,
293 struct net_device
*dev
)
295 struct net
*net
= dev_net(dev
);
296 struct in_device
*in_dev
;
297 struct sockaddr_in
*addr_in
= (struct sockaddr_in
*)addr
;
298 struct sockaddr_in6
*addr_in6
= (struct sockaddr_in6
*)addr
;
301 switch (addr
->sa_family
) {
303 in_dev
= in_dev_get(dev
);
307 ret_addr
= inet_confirm_addr(net
, in_dev
, 0,
308 addr_in
->sin_addr
.s_addr
,
316 if (IS_ENABLED(CONFIG_IPV6
) &&
317 ipv6_chk_addr(net
, &addr_in6
->sin6_addr
, dev
, 1))
326 * Find the master net_device on top of the given net_device.
327 * @dev: base IPoIB net_device
329 * Returns the master net_device with a reference held, or the same net_device
330 * if no master exists.
332 static struct net_device
*ipoib_get_master_net_dev(struct net_device
*dev
)
334 struct net_device
*master
;
337 master
= netdev_master_upper_dev_get_rcu(dev
);
349 struct ipoib_walk_data
{
350 const struct sockaddr
*addr
;
351 struct net_device
*result
;
354 static int ipoib_upper_walk(struct net_device
*upper
, void *_data
)
356 struct ipoib_walk_data
*data
= _data
;
359 if (ipoib_is_dev_match_addr_rcu(data
->addr
, upper
)) {
361 data
->result
= upper
;
369 * Find a net_device matching the given address, which is an upper device of
370 * the given net_device.
371 * @addr: IP address to look for.
372 * @dev: base IPoIB net_device
374 * If found, returns the net_device with a reference held. Otherwise return
377 static struct net_device
*ipoib_get_net_dev_match_addr(
378 const struct sockaddr
*addr
, struct net_device
*dev
)
380 struct ipoib_walk_data data
= {
385 if (ipoib_is_dev_match_addr_rcu(addr
, dev
)) {
391 netdev_walk_all_upper_dev_rcu(dev
, ipoib_upper_walk
, &data
);
397 /* returns the number of IPoIB netdevs on top a given ipoib device matching a
398 * pkey_index and address, if one exists.
400 * @found_net_dev: contains a matching net_device if the return value >= 1,
401 * with a reference held. */
402 static int ipoib_match_gid_pkey_addr(struct ipoib_dev_priv
*priv
,
403 const union ib_gid
*gid
,
405 const struct sockaddr
*addr
,
407 struct net_device
**found_net_dev
)
409 struct ipoib_dev_priv
*child_priv
;
410 struct net_device
*net_dev
= NULL
;
413 if (priv
->pkey_index
== pkey_index
&&
414 (!gid
|| !memcmp(gid
, &priv
->local_gid
, sizeof(*gid
)))) {
416 net_dev
= ipoib_get_master_net_dev(priv
->dev
);
418 /* Verify the net_device matches the IP address, as
419 * IPoIB child devices currently share a GID. */
420 net_dev
= ipoib_get_net_dev_match_addr(addr
, priv
->dev
);
424 *found_net_dev
= net_dev
;
431 /* Check child interfaces */
432 down_read_nested(&priv
->vlan_rwsem
, nesting
);
433 list_for_each_entry(child_priv
, &priv
->child_intfs
, list
) {
434 matches
+= ipoib_match_gid_pkey_addr(child_priv
, gid
,
441 up_read(&priv
->vlan_rwsem
);
446 /* Returns the number of matching net_devs found (between 0 and 2). Also
447 * return the matching net_device in the @net_dev parameter, holding a
448 * reference to the net_device, if the number of matches >= 1 */
449 static int __ipoib_get_net_dev_by_params(struct list_head
*dev_list
, u8 port
,
451 const union ib_gid
*gid
,
452 const struct sockaddr
*addr
,
453 struct net_device
**net_dev
)
455 struct ipoib_dev_priv
*priv
;
460 list_for_each_entry(priv
, dev_list
, list
) {
461 if (priv
->port
!= port
)
464 matches
+= ipoib_match_gid_pkey_addr(priv
, gid
, pkey_index
,
473 static struct net_device
*ipoib_get_net_dev_by_params(
474 struct ib_device
*dev
, u8 port
, u16 pkey
,
475 const union ib_gid
*gid
, const struct sockaddr
*addr
,
478 struct net_device
*net_dev
;
479 struct list_head
*dev_list
= client_data
;
484 if (!rdma_protocol_ib(dev
, port
))
487 ret
= ib_find_cached_pkey(dev
, port
, pkey
, &pkey_index
);
494 /* See if we can find a unique device matching the L2 parameters */
495 matches
= __ipoib_get_net_dev_by_params(dev_list
, port
, pkey_index
,
496 gid
, NULL
, &net_dev
);
507 /* Couldn't find a unique device with L2 parameters only. Use L3
508 * address to uniquely match the net device */
509 matches
= __ipoib_get_net_dev_by_params(dev_list
, port
, pkey_index
,
510 gid
, addr
, &net_dev
);
515 dev_warn_ratelimited(&dev
->dev
,
516 "duplicate IP address detected\n");
523 int ipoib_set_mode(struct net_device
*dev
, const char *buf
)
525 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
527 if ((test_bit(IPOIB_FLAG_ADMIN_CM
, &priv
->flags
) &&
528 !strcmp(buf
, "connected\n")) ||
529 (!test_bit(IPOIB_FLAG_ADMIN_CM
, &priv
->flags
) &&
530 !strcmp(buf
, "datagram\n"))) {
534 /* flush paths if we switch modes so that connections are restarted */
535 if (IPOIB_CM_SUPPORTED(dev
->dev_addr
) && !strcmp(buf
, "connected\n")) {
536 set_bit(IPOIB_FLAG_ADMIN_CM
, &priv
->flags
);
537 ipoib_warn(priv
, "enabling connected mode "
538 "will cause multicast packet drops\n");
539 netdev_update_features(dev
);
540 dev_set_mtu(dev
, ipoib_cm_max_mtu(dev
));
542 priv
->tx_wr
.wr
.send_flags
&= ~IB_SEND_IP_CSUM
;
544 ipoib_flush_paths(dev
);
545 return (!rtnl_trylock()) ? -EBUSY
: 0;
548 if (!strcmp(buf
, "datagram\n")) {
549 clear_bit(IPOIB_FLAG_ADMIN_CM
, &priv
->flags
);
550 netdev_update_features(dev
);
551 dev_set_mtu(dev
, min(priv
->mcast_mtu
, dev
->mtu
));
553 ipoib_flush_paths(dev
);
554 return (!rtnl_trylock()) ? -EBUSY
: 0;
560 struct ipoib_path
*__path_find(struct net_device
*dev
, void *gid
)
562 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
563 struct rb_node
*n
= priv
->path_tree
.rb_node
;
564 struct ipoib_path
*path
;
568 path
= rb_entry(n
, struct ipoib_path
, rb_node
);
570 ret
= memcmp(gid
, path
->pathrec
.dgid
.raw
,
571 sizeof (union ib_gid
));
584 static int __path_add(struct net_device
*dev
, struct ipoib_path
*path
)
586 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
587 struct rb_node
**n
= &priv
->path_tree
.rb_node
;
588 struct rb_node
*pn
= NULL
;
589 struct ipoib_path
*tpath
;
594 tpath
= rb_entry(pn
, struct ipoib_path
, rb_node
);
596 ret
= memcmp(path
->pathrec
.dgid
.raw
, tpath
->pathrec
.dgid
.raw
,
597 sizeof (union ib_gid
));
606 rb_link_node(&path
->rb_node
, pn
, n
);
607 rb_insert_color(&path
->rb_node
, &priv
->path_tree
);
609 list_add_tail(&path
->list
, &priv
->path_list
);
614 static void path_free(struct net_device
*dev
, struct ipoib_path
*path
)
618 while ((skb
= __skb_dequeue(&path
->queue
)))
619 dev_kfree_skb_irq(skb
);
621 ipoib_dbg(ipoib_priv(dev
), "path_free\n");
623 /* remove all neigh connected to this path */
624 ipoib_del_neighs_by_gid(dev
, path
->pathrec
.dgid
.raw
);
627 ipoib_put_ah(path
->ah
);
632 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
634 struct ipoib_path_iter
*ipoib_path_iter_init(struct net_device
*dev
)
636 struct ipoib_path_iter
*iter
;
638 iter
= kmalloc(sizeof *iter
, GFP_KERNEL
);
643 memset(iter
->path
.pathrec
.dgid
.raw
, 0, 16);
645 if (ipoib_path_iter_next(iter
)) {
653 int ipoib_path_iter_next(struct ipoib_path_iter
*iter
)
655 struct ipoib_dev_priv
*priv
= ipoib_priv(iter
->dev
);
657 struct ipoib_path
*path
;
660 spin_lock_irq(&priv
->lock
);
662 n
= rb_first(&priv
->path_tree
);
665 path
= rb_entry(n
, struct ipoib_path
, rb_node
);
667 if (memcmp(iter
->path
.pathrec
.dgid
.raw
, path
->pathrec
.dgid
.raw
,
668 sizeof (union ib_gid
)) < 0) {
677 spin_unlock_irq(&priv
->lock
);
682 void ipoib_path_iter_read(struct ipoib_path_iter
*iter
,
683 struct ipoib_path
*path
)
688 #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG */
690 void ipoib_mark_paths_invalid(struct net_device
*dev
)
692 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
693 struct ipoib_path
*path
, *tp
;
695 spin_lock_irq(&priv
->lock
);
697 list_for_each_entry_safe(path
, tp
, &priv
->path_list
, list
) {
698 ipoib_dbg(priv
, "mark path LID 0x%08x GID %pI6 invalid\n",
699 be32_to_cpu(sa_path_get_dlid(&path
->pathrec
)),
700 path
->pathrec
.dgid
.raw
);
704 spin_unlock_irq(&priv
->lock
);
707 static void push_pseudo_header(struct sk_buff
*skb
, const char *daddr
)
709 struct ipoib_pseudo_header
*phdr
;
711 phdr
= skb_push(skb
, sizeof(*phdr
));
712 memcpy(phdr
->hwaddr
, daddr
, INFINIBAND_ALEN
);
715 void ipoib_flush_paths(struct net_device
*dev
)
717 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
718 struct ipoib_path
*path
, *tp
;
719 LIST_HEAD(remove_list
);
722 netif_tx_lock_bh(dev
);
723 spin_lock_irqsave(&priv
->lock
, flags
);
725 list_splice_init(&priv
->path_list
, &remove_list
);
727 list_for_each_entry(path
, &remove_list
, list
)
728 rb_erase(&path
->rb_node
, &priv
->path_tree
);
730 list_for_each_entry_safe(path
, tp
, &remove_list
, list
) {
732 ib_sa_cancel_query(path
->query_id
, path
->query
);
733 spin_unlock_irqrestore(&priv
->lock
, flags
);
734 netif_tx_unlock_bh(dev
);
735 wait_for_completion(&path
->done
);
736 path_free(dev
, path
);
737 netif_tx_lock_bh(dev
);
738 spin_lock_irqsave(&priv
->lock
, flags
);
741 spin_unlock_irqrestore(&priv
->lock
, flags
);
742 netif_tx_unlock_bh(dev
);
745 static void path_rec_completion(int status
,
746 struct sa_path_rec
*pathrec
,
749 struct ipoib_path
*path
= path_ptr
;
750 struct net_device
*dev
= path
->dev
;
751 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
752 struct ipoib_ah
*ah
= NULL
;
753 struct ipoib_ah
*old_ah
= NULL
;
754 struct ipoib_neigh
*neigh
, *tn
;
755 struct sk_buff_head skqueue
;
760 ipoib_dbg(priv
, "PathRec LID 0x%04x for GID %pI6\n",
761 be32_to_cpu(sa_path_get_dlid(pathrec
)),
764 ipoib_dbg(priv
, "PathRec status %d for GID %pI6\n",
765 status
, path
->pathrec
.dgid
.raw
);
767 skb_queue_head_init(&skqueue
);
770 struct rdma_ah_attr av
;
772 if (!ib_init_ah_from_path(priv
->ca
, priv
->port
, pathrec
, &av
))
773 ah
= ipoib_create_ah(dev
, priv
->pd
, &av
);
776 spin_lock_irqsave(&priv
->lock
, flags
);
778 if (!IS_ERR_OR_NULL(ah
)) {
779 path
->pathrec
= *pathrec
;
784 ipoib_dbg(priv
, "created address handle %p for LID 0x%04x, SL %d\n",
785 ah
, be32_to_cpu(sa_path_get_dlid(pathrec
)),
788 while ((skb
= __skb_dequeue(&path
->queue
)))
789 __skb_queue_tail(&skqueue
, skb
);
791 list_for_each_entry_safe(neigh
, tn
, &path
->neigh_list
, list
) {
793 WARN_ON(neigh
->ah
!= old_ah
);
795 * Dropping the ah reference inside
796 * priv->lock is safe here, because we
797 * will hold one more reference from
798 * the original value of path->ah (ie
801 ipoib_put_ah(neigh
->ah
);
803 kref_get(&path
->ah
->ref
);
804 neigh
->ah
= path
->ah
;
806 if (ipoib_cm_enabled(dev
, neigh
->daddr
)) {
807 if (!ipoib_cm_get(neigh
))
808 ipoib_cm_set(neigh
, ipoib_cm_create_tx(dev
,
811 if (!ipoib_cm_get(neigh
)) {
812 ipoib_neigh_free(neigh
);
817 while ((skb
= __skb_dequeue(&neigh
->queue
)))
818 __skb_queue_tail(&skqueue
, skb
);
824 complete(&path
->done
);
826 spin_unlock_irqrestore(&priv
->lock
, flags
);
828 if (IS_ERR_OR_NULL(ah
))
829 ipoib_del_neighs_by_gid(dev
, path
->pathrec
.dgid
.raw
);
832 ipoib_put_ah(old_ah
);
834 while ((skb
= __skb_dequeue(&skqueue
))) {
837 ret
= dev_queue_xmit(skb
);
839 ipoib_warn(priv
, "%s: dev_queue_xmit failed to re-queue packet, ret:%d\n",
844 static struct ipoib_path
*path_rec_create(struct net_device
*dev
, void *gid
)
846 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
847 struct ipoib_path
*path
;
849 if (!priv
->broadcast
)
852 path
= kzalloc(sizeof *path
, GFP_ATOMIC
);
858 skb_queue_head_init(&path
->queue
);
860 INIT_LIST_HEAD(&path
->neigh_list
);
862 if (rdma_cap_opa_ah(priv
->ca
, priv
->port
))
863 path
->pathrec
.rec_type
= SA_PATH_REC_TYPE_OPA
;
865 path
->pathrec
.rec_type
= SA_PATH_REC_TYPE_IB
;
866 memcpy(path
->pathrec
.dgid
.raw
, gid
, sizeof (union ib_gid
));
867 path
->pathrec
.sgid
= priv
->local_gid
;
868 path
->pathrec
.pkey
= cpu_to_be16(priv
->pkey
);
869 path
->pathrec
.numb_path
= 1;
870 path
->pathrec
.traffic_class
= priv
->broadcast
->mcmember
.traffic_class
;
875 static int path_rec_start(struct net_device
*dev
,
876 struct ipoib_path
*path
)
878 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
880 ipoib_dbg(priv
, "Start path record lookup for %pI6\n",
881 path
->pathrec
.dgid
.raw
);
883 init_completion(&path
->done
);
886 ib_sa_path_rec_get(&ipoib_sa_client
, priv
->ca
, priv
->port
,
888 IB_SA_PATH_REC_DGID
|
889 IB_SA_PATH_REC_SGID
|
890 IB_SA_PATH_REC_NUMB_PATH
|
891 IB_SA_PATH_REC_TRAFFIC_CLASS
|
896 if (path
->query_id
< 0) {
897 ipoib_warn(priv
, "ib_sa_path_rec_get failed: %d\n", path
->query_id
);
899 complete(&path
->done
);
900 return path
->query_id
;
906 static void neigh_add_path(struct sk_buff
*skb
, u8
*daddr
,
907 struct net_device
*dev
)
909 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
910 struct rdma_netdev
*rn
= netdev_priv(dev
);
911 struct ipoib_path
*path
;
912 struct ipoib_neigh
*neigh
;
915 spin_lock_irqsave(&priv
->lock
, flags
);
916 neigh
= ipoib_neigh_alloc(daddr
, dev
);
918 spin_unlock_irqrestore(&priv
->lock
, flags
);
919 ++dev
->stats
.tx_dropped
;
920 dev_kfree_skb_any(skb
);
924 path
= __path_find(dev
, daddr
+ 4);
926 path
= path_rec_create(dev
, daddr
+ 4);
930 __path_add(dev
, path
);
933 list_add_tail(&neigh
->list
, &path
->neigh_list
);
936 kref_get(&path
->ah
->ref
);
937 neigh
->ah
= path
->ah
;
939 if (ipoib_cm_enabled(dev
, neigh
->daddr
)) {
940 if (!ipoib_cm_get(neigh
))
941 ipoib_cm_set(neigh
, ipoib_cm_create_tx(dev
, path
, neigh
));
942 if (!ipoib_cm_get(neigh
)) {
943 ipoib_neigh_free(neigh
);
946 if (skb_queue_len(&neigh
->queue
) <
947 IPOIB_MAX_PATH_REC_QUEUE
) {
948 push_pseudo_header(skb
, neigh
->daddr
);
949 __skb_queue_tail(&neigh
->queue
, skb
);
951 ipoib_warn(priv
, "queue length limit %d. Packet drop.\n",
952 skb_queue_len(&neigh
->queue
));
956 spin_unlock_irqrestore(&priv
->lock
, flags
);
957 path
->ah
->last_send
= rn
->send(dev
, skb
, path
->ah
->ah
,
959 ipoib_neigh_put(neigh
);
965 if (!path
->query
&& path_rec_start(dev
, path
))
967 if (skb_queue_len(&neigh
->queue
) < IPOIB_MAX_PATH_REC_QUEUE
) {
968 push_pseudo_header(skb
, neigh
->daddr
);
969 __skb_queue_tail(&neigh
->queue
, skb
);
975 spin_unlock_irqrestore(&priv
->lock
, flags
);
976 ipoib_neigh_put(neigh
);
980 ipoib_neigh_free(neigh
);
982 ++dev
->stats
.tx_dropped
;
983 dev_kfree_skb_any(skb
);
985 spin_unlock_irqrestore(&priv
->lock
, flags
);
986 ipoib_neigh_put(neigh
);
989 static void unicast_arp_send(struct sk_buff
*skb
, struct net_device
*dev
,
990 struct ipoib_pseudo_header
*phdr
)
992 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
993 struct rdma_netdev
*rn
= netdev_priv(dev
);
994 struct ipoib_path
*path
;
997 spin_lock_irqsave(&priv
->lock
, flags
);
999 path
= __path_find(dev
, phdr
->hwaddr
+ 4);
1000 if (!path
|| !path
->valid
) {
1004 path
= path_rec_create(dev
, phdr
->hwaddr
+ 4);
1008 if (skb_queue_len(&path
->queue
) < IPOIB_MAX_PATH_REC_QUEUE
) {
1009 push_pseudo_header(skb
, phdr
->hwaddr
);
1010 __skb_queue_tail(&path
->queue
, skb
);
1012 ++dev
->stats
.tx_dropped
;
1013 dev_kfree_skb_any(skb
);
1016 if (!path
->query
&& path_rec_start(dev
, path
)) {
1017 spin_unlock_irqrestore(&priv
->lock
, flags
);
1019 path_free(dev
, path
);
1022 __path_add(dev
, path
);
1024 ++dev
->stats
.tx_dropped
;
1025 dev_kfree_skb_any(skb
);
1028 spin_unlock_irqrestore(&priv
->lock
, flags
);
1033 ipoib_dbg(priv
, "Send unicast ARP to %08x\n",
1034 be32_to_cpu(sa_path_get_dlid(&path
->pathrec
)));
1036 spin_unlock_irqrestore(&priv
->lock
, flags
);
1037 path
->ah
->last_send
= rn
->send(dev
, skb
, path
->ah
->ah
,
1038 IPOIB_QPN(phdr
->hwaddr
));
1040 } else if ((path
->query
|| !path_rec_start(dev
, path
)) &&
1041 skb_queue_len(&path
->queue
) < IPOIB_MAX_PATH_REC_QUEUE
) {
1042 push_pseudo_header(skb
, phdr
->hwaddr
);
1043 __skb_queue_tail(&path
->queue
, skb
);
1045 ++dev
->stats
.tx_dropped
;
1046 dev_kfree_skb_any(skb
);
1049 spin_unlock_irqrestore(&priv
->lock
, flags
);
1052 static int ipoib_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1054 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
1055 struct rdma_netdev
*rn
= netdev_priv(dev
);
1056 struct ipoib_neigh
*neigh
;
1057 struct ipoib_pseudo_header
*phdr
;
1058 struct ipoib_header
*header
;
1059 unsigned long flags
;
1061 phdr
= (struct ipoib_pseudo_header
*) skb
->data
;
1062 skb_pull(skb
, sizeof(*phdr
));
1063 header
= (struct ipoib_header
*) skb
->data
;
1065 if (unlikely(phdr
->hwaddr
[4] == 0xff)) {
1066 /* multicast, arrange "if" according to probability */
1067 if ((header
->proto
!= htons(ETH_P_IP
)) &&
1068 (header
->proto
!= htons(ETH_P_IPV6
)) &&
1069 (header
->proto
!= htons(ETH_P_ARP
)) &&
1070 (header
->proto
!= htons(ETH_P_RARP
)) &&
1071 (header
->proto
!= htons(ETH_P_TIPC
))) {
1072 /* ethertype not supported by IPoIB */
1073 ++dev
->stats
.tx_dropped
;
1074 dev_kfree_skb_any(skb
);
1075 return NETDEV_TX_OK
;
1077 /* Add in the P_Key for multicast*/
1078 phdr
->hwaddr
[8] = (priv
->pkey
>> 8) & 0xff;
1079 phdr
->hwaddr
[9] = priv
->pkey
& 0xff;
1081 neigh
= ipoib_neigh_get(dev
, phdr
->hwaddr
);
1083 goto send_using_neigh
;
1084 ipoib_mcast_send(dev
, phdr
->hwaddr
, skb
);
1085 return NETDEV_TX_OK
;
1088 /* unicast, arrange "switch" according to probability */
1089 switch (header
->proto
) {
1090 case htons(ETH_P_IP
):
1091 case htons(ETH_P_IPV6
):
1092 case htons(ETH_P_TIPC
):
1093 neigh
= ipoib_neigh_get(dev
, phdr
->hwaddr
);
1094 if (unlikely(!neigh
)) {
1095 neigh_add_path(skb
, phdr
->hwaddr
, dev
);
1096 return NETDEV_TX_OK
;
1099 case htons(ETH_P_ARP
):
1100 case htons(ETH_P_RARP
):
1101 /* for unicast ARP and RARP should always perform path find */
1102 unicast_arp_send(skb
, dev
, phdr
);
1103 return NETDEV_TX_OK
;
1105 /* ethertype not supported by IPoIB */
1106 ++dev
->stats
.tx_dropped
;
1107 dev_kfree_skb_any(skb
);
1108 return NETDEV_TX_OK
;
1112 /* note we now hold a ref to neigh */
1113 if (ipoib_cm_get(neigh
)) {
1114 if (ipoib_cm_up(neigh
)) {
1115 ipoib_cm_send(dev
, skb
, ipoib_cm_get(neigh
));
1118 } else if (neigh
->ah
) {
1119 neigh
->ah
->last_send
= rn
->send(dev
, skb
, neigh
->ah
->ah
,
1120 IPOIB_QPN(phdr
->hwaddr
));
1124 if (skb_queue_len(&neigh
->queue
) < IPOIB_MAX_PATH_REC_QUEUE
) {
1125 push_pseudo_header(skb
, phdr
->hwaddr
);
1126 spin_lock_irqsave(&priv
->lock
, flags
);
1127 __skb_queue_tail(&neigh
->queue
, skb
);
1128 spin_unlock_irqrestore(&priv
->lock
, flags
);
1130 ++dev
->stats
.tx_dropped
;
1131 dev_kfree_skb_any(skb
);
1135 ipoib_neigh_put(neigh
);
1137 return NETDEV_TX_OK
;
1140 static void ipoib_timeout(struct net_device
*dev
)
1142 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
1144 ipoib_warn(priv
, "transmit timeout: latency %d msecs\n",
1145 jiffies_to_msecs(jiffies
- dev_trans_start(dev
)));
1146 ipoib_warn(priv
, "queue stopped %d, tx_head %u, tx_tail %u\n",
1147 netif_queue_stopped(dev
),
1148 priv
->tx_head
, priv
->tx_tail
);
1149 /* XXX reset QP, etc. */
1152 static int ipoib_hard_header(struct sk_buff
*skb
,
1153 struct net_device
*dev
,
1154 unsigned short type
,
1155 const void *daddr
, const void *saddr
, unsigned len
)
1157 struct ipoib_header
*header
;
1159 header
= skb_push(skb
, sizeof *header
);
1161 header
->proto
= htons(type
);
1162 header
->reserved
= 0;
1165 * we don't rely on dst_entry structure, always stuff the
1166 * destination address into skb hard header so we can figure out where
1167 * to send the packet later.
1169 push_pseudo_header(skb
, daddr
);
1171 return IPOIB_HARD_LEN
;
1174 static void ipoib_set_mcast_list(struct net_device
*dev
)
1176 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
1178 if (!test_bit(IPOIB_FLAG_OPER_UP
, &priv
->flags
)) {
1179 ipoib_dbg(priv
, "IPOIB_FLAG_OPER_UP not set");
1183 queue_work(priv
->wq
, &priv
->restart_task
);
1186 static int ipoib_get_iflink(const struct net_device
*dev
)
1188 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
1190 /* parent interface */
1191 if (!test_bit(IPOIB_FLAG_SUBINTERFACE
, &priv
->flags
))
1192 return dev
->ifindex
;
1194 /* child/vlan interface */
1195 return priv
->parent
->ifindex
;
1198 static u32
ipoib_addr_hash(struct ipoib_neigh_hash
*htbl
, u8
*daddr
)
1201 * Use only the address parts that contributes to spreading
1202 * The subnet prefix is not used as one can not connect to
1203 * same remote port (GUID) using the same remote QPN via two
1204 * different subnets.
1206 /* qpn octets[1:4) & port GUID octets[12:20) */
1207 u32
*d32
= (u32
*) daddr
;
1210 hv
= jhash_3words(d32
[3], d32
[4], IPOIB_QPN_MASK
& d32
[0], 0);
1211 return hv
& htbl
->mask
;
1214 struct ipoib_neigh
*ipoib_neigh_get(struct net_device
*dev
, u8
*daddr
)
1216 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
1217 struct ipoib_neigh_table
*ntbl
= &priv
->ntbl
;
1218 struct ipoib_neigh_hash
*htbl
;
1219 struct ipoib_neigh
*neigh
= NULL
;
1224 htbl
= rcu_dereference_bh(ntbl
->htbl
);
1229 hash_val
= ipoib_addr_hash(htbl
, daddr
);
1230 for (neigh
= rcu_dereference_bh(htbl
->buckets
[hash_val
]);
1232 neigh
= rcu_dereference_bh(neigh
->hnext
)) {
1233 if (memcmp(daddr
, neigh
->daddr
, INFINIBAND_ALEN
) == 0) {
1234 /* found, take one ref on behalf of the caller */
1235 if (!atomic_inc_not_zero(&neigh
->refcnt
)) {
1241 if (likely(skb_queue_len(&neigh
->queue
) < IPOIB_MAX_PATH_REC_QUEUE
))
1242 neigh
->alive
= jiffies
;
1248 rcu_read_unlock_bh();
1252 static void __ipoib_reap_neigh(struct ipoib_dev_priv
*priv
)
1254 struct ipoib_neigh_table
*ntbl
= &priv
->ntbl
;
1255 struct ipoib_neigh_hash
*htbl
;
1256 unsigned long neigh_obsolete
;
1258 unsigned long flags
;
1260 LIST_HEAD(remove_list
);
1262 if (test_bit(IPOIB_STOP_NEIGH_GC
, &priv
->flags
))
1265 spin_lock_irqsave(&priv
->lock
, flags
);
1267 htbl
= rcu_dereference_protected(ntbl
->htbl
,
1268 lockdep_is_held(&priv
->lock
));
1273 /* neigh is obsolete if it was idle for two GC periods */
1274 dt
= 2 * arp_tbl
.gc_interval
;
1275 neigh_obsolete
= jiffies
- dt
;
1276 /* handle possible race condition */
1277 if (test_bit(IPOIB_STOP_NEIGH_GC
, &priv
->flags
))
1280 for (i
= 0; i
< htbl
->size
; i
++) {
1281 struct ipoib_neigh
*neigh
;
1282 struct ipoib_neigh __rcu
**np
= &htbl
->buckets
[i
];
1284 while ((neigh
= rcu_dereference_protected(*np
,
1285 lockdep_is_held(&priv
->lock
))) != NULL
) {
1286 /* was the neigh idle for two GC periods */
1287 if (time_after(neigh_obsolete
, neigh
->alive
)) {
1289 ipoib_check_and_add_mcast_sendonly(priv
, neigh
->daddr
+ 4, &remove_list
);
1291 rcu_assign_pointer(*np
,
1292 rcu_dereference_protected(neigh
->hnext
,
1293 lockdep_is_held(&priv
->lock
)));
1294 /* remove from path/mc list */
1295 list_del_init(&neigh
->list
);
1296 call_rcu(&neigh
->rcu
, ipoib_neigh_reclaim
);
1305 spin_unlock_irqrestore(&priv
->lock
, flags
);
1306 ipoib_mcast_remove_list(&remove_list
);
1309 static void ipoib_reap_neigh(struct work_struct
*work
)
1311 struct ipoib_dev_priv
*priv
=
1312 container_of(work
, struct ipoib_dev_priv
, neigh_reap_task
.work
);
1314 __ipoib_reap_neigh(priv
);
1316 if (!test_bit(IPOIB_STOP_NEIGH_GC
, &priv
->flags
))
1317 queue_delayed_work(priv
->wq
, &priv
->neigh_reap_task
,
1318 arp_tbl
.gc_interval
);
1322 static struct ipoib_neigh
*ipoib_neigh_ctor(u8
*daddr
,
1323 struct net_device
*dev
)
1325 struct ipoib_neigh
*neigh
;
1327 neigh
= kzalloc(sizeof *neigh
, GFP_ATOMIC
);
1332 memcpy(&neigh
->daddr
, daddr
, sizeof(neigh
->daddr
));
1333 skb_queue_head_init(&neigh
->queue
);
1334 INIT_LIST_HEAD(&neigh
->list
);
1335 ipoib_cm_set(neigh
, NULL
);
1336 /* one ref on behalf of the caller */
1337 atomic_set(&neigh
->refcnt
, 1);
1342 struct ipoib_neigh
*ipoib_neigh_alloc(u8
*daddr
,
1343 struct net_device
*dev
)
1345 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
1346 struct ipoib_neigh_table
*ntbl
= &priv
->ntbl
;
1347 struct ipoib_neigh_hash
*htbl
;
1348 struct ipoib_neigh
*neigh
;
1351 htbl
= rcu_dereference_protected(ntbl
->htbl
,
1352 lockdep_is_held(&priv
->lock
));
1358 /* need to add a new neigh, but maybe some other thread succeeded?
1359 * recalc hash, maybe hash resize took place so we do a search
1361 hash_val
= ipoib_addr_hash(htbl
, daddr
);
1362 for (neigh
= rcu_dereference_protected(htbl
->buckets
[hash_val
],
1363 lockdep_is_held(&priv
->lock
));
1365 neigh
= rcu_dereference_protected(neigh
->hnext
,
1366 lockdep_is_held(&priv
->lock
))) {
1367 if (memcmp(daddr
, neigh
->daddr
, INFINIBAND_ALEN
) == 0) {
1368 /* found, take one ref on behalf of the caller */
1369 if (!atomic_inc_not_zero(&neigh
->refcnt
)) {
1374 neigh
->alive
= jiffies
;
1379 neigh
= ipoib_neigh_ctor(daddr
, dev
);
1383 /* one ref on behalf of the hash table */
1384 atomic_inc(&neigh
->refcnt
);
1385 neigh
->alive
= jiffies
;
1387 rcu_assign_pointer(neigh
->hnext
,
1388 rcu_dereference_protected(htbl
->buckets
[hash_val
],
1389 lockdep_is_held(&priv
->lock
)));
1390 rcu_assign_pointer(htbl
->buckets
[hash_val
], neigh
);
1391 atomic_inc(&ntbl
->entries
);
1398 void ipoib_neigh_dtor(struct ipoib_neigh
*neigh
)
1400 /* neigh reference count was dropprd to zero */
1401 struct net_device
*dev
= neigh
->dev
;
1402 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
1403 struct sk_buff
*skb
;
1405 ipoib_put_ah(neigh
->ah
);
1406 while ((skb
= __skb_dequeue(&neigh
->queue
))) {
1407 ++dev
->stats
.tx_dropped
;
1408 dev_kfree_skb_any(skb
);
1410 if (ipoib_cm_get(neigh
))
1411 ipoib_cm_destroy_tx(ipoib_cm_get(neigh
));
1412 ipoib_dbg(ipoib_priv(dev
),
1413 "neigh free for %06x %pI6\n",
1414 IPOIB_QPN(neigh
->daddr
),
1417 if (atomic_dec_and_test(&priv
->ntbl
.entries
)) {
1418 if (test_bit(IPOIB_NEIGH_TBL_FLUSH
, &priv
->flags
))
1419 complete(&priv
->ntbl
.flushed
);
1423 static void ipoib_neigh_reclaim(struct rcu_head
*rp
)
1425 /* Called as a result of removal from hash table */
1426 struct ipoib_neigh
*neigh
= container_of(rp
, struct ipoib_neigh
, rcu
);
1427 /* note TX context may hold another ref */
1428 ipoib_neigh_put(neigh
);
1431 void ipoib_neigh_free(struct ipoib_neigh
*neigh
)
1433 struct net_device
*dev
= neigh
->dev
;
1434 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
1435 struct ipoib_neigh_table
*ntbl
= &priv
->ntbl
;
1436 struct ipoib_neigh_hash
*htbl
;
1437 struct ipoib_neigh __rcu
**np
;
1438 struct ipoib_neigh
*n
;
1441 htbl
= rcu_dereference_protected(ntbl
->htbl
,
1442 lockdep_is_held(&priv
->lock
));
1446 hash_val
= ipoib_addr_hash(htbl
, neigh
->daddr
);
1447 np
= &htbl
->buckets
[hash_val
];
1448 for (n
= rcu_dereference_protected(*np
,
1449 lockdep_is_held(&priv
->lock
));
1451 n
= rcu_dereference_protected(*np
,
1452 lockdep_is_held(&priv
->lock
))) {
1455 rcu_assign_pointer(*np
,
1456 rcu_dereference_protected(neigh
->hnext
,
1457 lockdep_is_held(&priv
->lock
)));
1458 /* remove from parent list */
1459 list_del_init(&neigh
->list
);
1460 call_rcu(&neigh
->rcu
, ipoib_neigh_reclaim
);
1468 static int ipoib_neigh_hash_init(struct ipoib_dev_priv
*priv
)
1470 struct ipoib_neigh_table
*ntbl
= &priv
->ntbl
;
1471 struct ipoib_neigh_hash
*htbl
;
1472 struct ipoib_neigh __rcu
**buckets
;
1475 clear_bit(IPOIB_NEIGH_TBL_FLUSH
, &priv
->flags
);
1477 htbl
= kzalloc(sizeof(*htbl
), GFP_KERNEL
);
1480 set_bit(IPOIB_STOP_NEIGH_GC
, &priv
->flags
);
1481 size
= roundup_pow_of_two(arp_tbl
.gc_thresh3
);
1482 buckets
= kzalloc(size
* sizeof(*buckets
), GFP_KERNEL
);
1488 htbl
->mask
= (size
- 1);
1489 htbl
->buckets
= buckets
;
1490 RCU_INIT_POINTER(ntbl
->htbl
, htbl
);
1492 atomic_set(&ntbl
->entries
, 0);
1494 /* start garbage collection */
1495 clear_bit(IPOIB_STOP_NEIGH_GC
, &priv
->flags
);
1496 queue_delayed_work(priv
->wq
, &priv
->neigh_reap_task
,
1497 arp_tbl
.gc_interval
);
1502 static void neigh_hash_free_rcu(struct rcu_head
*head
)
1504 struct ipoib_neigh_hash
*htbl
= container_of(head
,
1505 struct ipoib_neigh_hash
,
1507 struct ipoib_neigh __rcu
**buckets
= htbl
->buckets
;
1508 struct ipoib_neigh_table
*ntbl
= htbl
->ntbl
;
1512 complete(&ntbl
->deleted
);
1515 void ipoib_del_neighs_by_gid(struct net_device
*dev
, u8
*gid
)
1517 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
1518 struct ipoib_neigh_table
*ntbl
= &priv
->ntbl
;
1519 struct ipoib_neigh_hash
*htbl
;
1520 unsigned long flags
;
1523 /* remove all neigh connected to a given path or mcast */
1524 spin_lock_irqsave(&priv
->lock
, flags
);
1526 htbl
= rcu_dereference_protected(ntbl
->htbl
,
1527 lockdep_is_held(&priv
->lock
));
1532 for (i
= 0; i
< htbl
->size
; i
++) {
1533 struct ipoib_neigh
*neigh
;
1534 struct ipoib_neigh __rcu
**np
= &htbl
->buckets
[i
];
1536 while ((neigh
= rcu_dereference_protected(*np
,
1537 lockdep_is_held(&priv
->lock
))) != NULL
) {
1538 /* delete neighs belong to this parent */
1539 if (!memcmp(gid
, neigh
->daddr
+ 4, sizeof (union ib_gid
))) {
1540 rcu_assign_pointer(*np
,
1541 rcu_dereference_protected(neigh
->hnext
,
1542 lockdep_is_held(&priv
->lock
)));
1543 /* remove from parent list */
1544 list_del_init(&neigh
->list
);
1545 call_rcu(&neigh
->rcu
, ipoib_neigh_reclaim
);
1553 spin_unlock_irqrestore(&priv
->lock
, flags
);
1556 static void ipoib_flush_neighs(struct ipoib_dev_priv
*priv
)
1558 struct ipoib_neigh_table
*ntbl
= &priv
->ntbl
;
1559 struct ipoib_neigh_hash
*htbl
;
1560 unsigned long flags
;
1561 int i
, wait_flushed
= 0;
1563 init_completion(&priv
->ntbl
.flushed
);
1564 set_bit(IPOIB_NEIGH_TBL_FLUSH
, &priv
->flags
);
1566 spin_lock_irqsave(&priv
->lock
, flags
);
1568 htbl
= rcu_dereference_protected(ntbl
->htbl
,
1569 lockdep_is_held(&priv
->lock
));
1573 wait_flushed
= atomic_read(&priv
->ntbl
.entries
);
1577 for (i
= 0; i
< htbl
->size
; i
++) {
1578 struct ipoib_neigh
*neigh
;
1579 struct ipoib_neigh __rcu
**np
= &htbl
->buckets
[i
];
1581 while ((neigh
= rcu_dereference_protected(*np
,
1582 lockdep_is_held(&priv
->lock
))) != NULL
) {
1583 rcu_assign_pointer(*np
,
1584 rcu_dereference_protected(neigh
->hnext
,
1585 lockdep_is_held(&priv
->lock
)));
1586 /* remove from path/mc list */
1587 list_del_init(&neigh
->list
);
1588 call_rcu(&neigh
->rcu
, ipoib_neigh_reclaim
);
1593 rcu_assign_pointer(ntbl
->htbl
, NULL
);
1594 call_rcu(&htbl
->rcu
, neigh_hash_free_rcu
);
1597 spin_unlock_irqrestore(&priv
->lock
, flags
);
1599 wait_for_completion(&priv
->ntbl
.flushed
);
1602 static void ipoib_neigh_hash_uninit(struct net_device
*dev
)
1604 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
1607 ipoib_dbg(priv
, "ipoib_neigh_hash_uninit\n");
1608 init_completion(&priv
->ntbl
.deleted
);
1610 /* Stop GC if called at init fail need to cancel work */
1611 stopped
= test_and_set_bit(IPOIB_STOP_NEIGH_GC
, &priv
->flags
);
1613 cancel_delayed_work(&priv
->neigh_reap_task
);
1615 ipoib_flush_neighs(priv
);
1617 wait_for_completion(&priv
->ntbl
.deleted
);
1620 static void ipoib_dev_uninit_default(struct net_device
*dev
)
1622 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
1624 ipoib_transport_dev_cleanup(dev
);
1626 netif_napi_del(&priv
->napi
);
1628 ipoib_cm_dev_cleanup(dev
);
1630 kfree(priv
->rx_ring
);
1631 vfree(priv
->tx_ring
);
1633 priv
->rx_ring
= NULL
;
1634 priv
->tx_ring
= NULL
;
1637 static int ipoib_dev_init_default(struct net_device
*dev
)
1639 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
1641 netif_napi_add(dev
, &priv
->napi
, ipoib_poll
, NAPI_POLL_WEIGHT
);
1643 /* Allocate RX/TX "rings" to hold queued skbs */
1644 priv
->rx_ring
= kzalloc(ipoib_recvq_size
* sizeof *priv
->rx_ring
,
1649 priv
->tx_ring
= vzalloc(ipoib_sendq_size
* sizeof *priv
->tx_ring
);
1650 if (!priv
->tx_ring
) {
1651 printk(KERN_WARNING
"%s: failed to allocate TX ring (%d entries)\n",
1652 priv
->ca
->name
, ipoib_sendq_size
);
1653 goto out_rx_ring_cleanup
;
1656 /* priv->tx_head, tx_tail & tx_outstanding are already 0 */
1658 if (ipoib_transport_dev_init(dev
, priv
->ca
)) {
1659 pr_warn("%s: ipoib_transport_dev_init failed\n",
1661 goto out_tx_ring_cleanup
;
1664 /* after qp created set dev address */
1665 priv
->dev
->dev_addr
[1] = (priv
->qp
->qp_num
>> 16) & 0xff;
1666 priv
->dev
->dev_addr
[2] = (priv
->qp
->qp_num
>> 8) & 0xff;
1667 priv
->dev
->dev_addr
[3] = (priv
->qp
->qp_num
) & 0xff;
1669 setup_timer(&priv
->poll_timer
, ipoib_ib_tx_timer_func
,
1670 (unsigned long)dev
);
1674 out_tx_ring_cleanup
:
1675 vfree(priv
->tx_ring
);
1677 out_rx_ring_cleanup
:
1678 kfree(priv
->rx_ring
);
1681 netif_napi_del(&priv
->napi
);
1685 static int ipoib_ioctl(struct net_device
*dev
, struct ifreq
*ifr
,
1688 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
1690 if (!priv
->rn_ops
->ndo_do_ioctl
)
1693 return priv
->rn_ops
->ndo_do_ioctl(dev
, ifr
, cmd
);
1696 int ipoib_dev_init(struct net_device
*dev
, struct ib_device
*ca
, int port
)
1698 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
1706 * the various IPoIB tasks assume they will never race against
1707 * themselves, so always use a single thread workqueue
1709 priv
->wq
= alloc_ordered_workqueue("ipoib_wq", WQ_MEM_RECLAIM
);
1711 pr_warn("%s: failed to allocate device WQ\n", dev
->name
);
1715 /* create pd, which used both for control and datapath*/
1716 priv
->pd
= ib_alloc_pd(priv
->ca
, 0);
1717 if (IS_ERR(priv
->pd
)) {
1718 pr_warn("%s: failed to allocate PD\n", ca
->name
);
1722 ret
= priv
->rn_ops
->ndo_init(dev
);
1724 pr_warn("%s failed to init HW resource\n", dev
->name
);
1728 if (ipoib_neigh_hash_init(priv
) < 0) {
1729 pr_warn("%s failed to init neigh hash\n", dev
->name
);
1730 goto out_dev_uninit
;
1733 if (dev
->flags
& IFF_UP
) {
1734 if (ipoib_ib_dev_open(dev
)) {
1735 pr_warn("%s failed to open device\n", dev
->name
);
1737 goto out_dev_uninit
;
1744 ipoib_ib_dev_cleanup(dev
);
1748 ib_dealloc_pd(priv
->pd
);
1754 destroy_workqueue(priv
->wq
);
1762 void ipoib_dev_cleanup(struct net_device
*dev
)
1764 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
), *cpriv
, *tcpriv
;
1769 /* Delete any child interfaces first */
1770 list_for_each_entry_safe(cpriv
, tcpriv
, &priv
->child_intfs
, list
) {
1771 /* Stop GC on child */
1772 set_bit(IPOIB_STOP_NEIGH_GC
, &cpriv
->flags
);
1773 cancel_delayed_work(&cpriv
->neigh_reap_task
);
1774 unregister_netdevice_queue(cpriv
->dev
, &head
);
1776 unregister_netdevice_many(&head
);
1778 ipoib_neigh_hash_uninit(dev
);
1780 ipoib_ib_dev_cleanup(dev
);
1782 /* no more works over the priv->wq */
1784 flush_workqueue(priv
->wq
);
1785 destroy_workqueue(priv
->wq
);
1790 static int ipoib_set_vf_link_state(struct net_device
*dev
, int vf
, int link_state
)
1792 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
1794 return ib_set_vf_link_state(priv
->ca
, vf
, priv
->port
, link_state
);
1797 static int ipoib_get_vf_config(struct net_device
*dev
, int vf
,
1798 struct ifla_vf_info
*ivf
)
1800 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
1803 err
= ib_get_vf_config(priv
->ca
, vf
, priv
->port
, ivf
);
1812 static int ipoib_set_vf_guid(struct net_device
*dev
, int vf
, u64 guid
, int type
)
1814 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
1816 if (type
!= IFLA_VF_IB_NODE_GUID
&& type
!= IFLA_VF_IB_PORT_GUID
)
1819 return ib_set_vf_guid(priv
->ca
, vf
, priv
->port
, guid
, type
);
1822 static int ipoib_get_vf_stats(struct net_device
*dev
, int vf
,
1823 struct ifla_vf_stats
*vf_stats
)
1825 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
1827 return ib_get_vf_stats(priv
->ca
, vf
, priv
->port
, vf_stats
);
1830 static const struct header_ops ipoib_header_ops
= {
1831 .create
= ipoib_hard_header
,
1834 static const struct net_device_ops ipoib_netdev_ops_pf
= {
1835 .ndo_uninit
= ipoib_uninit
,
1836 .ndo_open
= ipoib_open
,
1837 .ndo_stop
= ipoib_stop
,
1838 .ndo_change_mtu
= ipoib_change_mtu
,
1839 .ndo_fix_features
= ipoib_fix_features
,
1840 .ndo_start_xmit
= ipoib_start_xmit
,
1841 .ndo_tx_timeout
= ipoib_timeout
,
1842 .ndo_set_rx_mode
= ipoib_set_mcast_list
,
1843 .ndo_get_iflink
= ipoib_get_iflink
,
1844 .ndo_set_vf_link_state
= ipoib_set_vf_link_state
,
1845 .ndo_get_vf_config
= ipoib_get_vf_config
,
1846 .ndo_get_vf_stats
= ipoib_get_vf_stats
,
1847 .ndo_set_vf_guid
= ipoib_set_vf_guid
,
1848 .ndo_set_mac_address
= ipoib_set_mac
,
1849 .ndo_get_stats64
= ipoib_get_stats
,
1850 .ndo_do_ioctl
= ipoib_ioctl
,
1853 static const struct net_device_ops ipoib_netdev_ops_vf
= {
1854 .ndo_uninit
= ipoib_uninit
,
1855 .ndo_open
= ipoib_open
,
1856 .ndo_stop
= ipoib_stop
,
1857 .ndo_change_mtu
= ipoib_change_mtu
,
1858 .ndo_fix_features
= ipoib_fix_features
,
1859 .ndo_start_xmit
= ipoib_start_xmit
,
1860 .ndo_tx_timeout
= ipoib_timeout
,
1861 .ndo_set_rx_mode
= ipoib_set_mcast_list
,
1862 .ndo_get_iflink
= ipoib_get_iflink
,
1863 .ndo_get_stats64
= ipoib_get_stats
,
1864 .ndo_do_ioctl
= ipoib_ioctl
,
1867 void ipoib_setup_common(struct net_device
*dev
)
1869 dev
->header_ops
= &ipoib_header_ops
;
1871 ipoib_set_ethtool_ops(dev
);
1873 dev
->watchdog_timeo
= HZ
;
1875 dev
->flags
|= IFF_BROADCAST
| IFF_MULTICAST
;
1877 dev
->hard_header_len
= IPOIB_HARD_LEN
;
1878 dev
->addr_len
= INFINIBAND_ALEN
;
1879 dev
->type
= ARPHRD_INFINIBAND
;
1880 dev
->tx_queue_len
= ipoib_sendq_size
* 2;
1881 dev
->features
= (NETIF_F_VLAN_CHALLENGED
|
1883 netif_keep_dst(dev
);
1885 memcpy(dev
->broadcast
, ipv4_bcast_addr
, INFINIBAND_ALEN
);
1888 static void ipoib_build_priv(struct net_device
*dev
)
1890 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
1893 spin_lock_init(&priv
->lock
);
1894 init_rwsem(&priv
->vlan_rwsem
);
1895 mutex_init(&priv
->mcast_mutex
);
1896 mutex_init(&priv
->sysfs_mutex
);
1898 INIT_LIST_HEAD(&priv
->path_list
);
1899 INIT_LIST_HEAD(&priv
->child_intfs
);
1900 INIT_LIST_HEAD(&priv
->dead_ahs
);
1901 INIT_LIST_HEAD(&priv
->multicast_list
);
1903 INIT_DELAYED_WORK(&priv
->mcast_task
, ipoib_mcast_join_task
);
1904 INIT_WORK(&priv
->carrier_on_task
, ipoib_mcast_carrier_on_task
);
1905 INIT_WORK(&priv
->flush_light
, ipoib_ib_dev_flush_light
);
1906 INIT_WORK(&priv
->flush_normal
, ipoib_ib_dev_flush_normal
);
1907 INIT_WORK(&priv
->flush_heavy
, ipoib_ib_dev_flush_heavy
);
1908 INIT_WORK(&priv
->restart_task
, ipoib_mcast_restart_task
);
1909 INIT_DELAYED_WORK(&priv
->ah_reap_task
, ipoib_reap_ah
);
1910 INIT_DELAYED_WORK(&priv
->neigh_reap_task
, ipoib_reap_neigh
);
1913 static const struct net_device_ops ipoib_netdev_default_pf
= {
1914 .ndo_init
= ipoib_dev_init_default
,
1915 .ndo_uninit
= ipoib_dev_uninit_default
,
1916 .ndo_open
= ipoib_ib_dev_open_default
,
1917 .ndo_stop
= ipoib_ib_dev_stop_default
,
1920 static struct net_device
1921 *ipoib_create_netdev_default(struct ib_device
*hca
,
1923 unsigned char name_assign_type
,
1924 void (*setup
)(struct net_device
*))
1926 struct net_device
*dev
;
1927 struct rdma_netdev
*rn
;
1929 dev
= alloc_netdev((int)sizeof(struct rdma_netdev
),
1931 name_assign_type
, setup
);
1935 rn
= netdev_priv(dev
);
1937 rn
->send
= ipoib_send
;
1938 rn
->attach_mcast
= ipoib_mcast_attach
;
1939 rn
->detach_mcast
= ipoib_mcast_detach
;
1940 rn
->free_rdma_netdev
= free_netdev
;
1943 dev
->netdev_ops
= &ipoib_netdev_default_pf
;
1948 static struct net_device
*ipoib_get_netdev(struct ib_device
*hca
, u8 port
,
1951 struct net_device
*dev
;
1953 if (hca
->alloc_rdma_netdev
) {
1954 dev
= hca
->alloc_rdma_netdev(hca
, port
,
1955 RDMA_NETDEV_IPOIB
, name
,
1957 ipoib_setup_common
);
1958 if (IS_ERR_OR_NULL(dev
) && PTR_ERR(dev
) != -EOPNOTSUPP
)
1962 if (!hca
->alloc_rdma_netdev
|| PTR_ERR(dev
) == -EOPNOTSUPP
)
1963 dev
= ipoib_create_netdev_default(hca
, name
, NET_NAME_UNKNOWN
,
1964 ipoib_setup_common
);
1969 struct ipoib_dev_priv
*ipoib_intf_alloc(struct ib_device
*hca
, u8 port
,
1972 struct net_device
*dev
;
1973 struct ipoib_dev_priv
*priv
;
1974 struct rdma_netdev
*rn
;
1976 priv
= kzalloc(sizeof(*priv
), GFP_KERNEL
);
1980 dev
= ipoib_get_netdev(hca
, port
, name
);
1984 priv
->rn_ops
= dev
->netdev_ops
;
1986 /* fixme : should be after the query_cap */
1987 if (priv
->hca_caps
& IB_DEVICE_VIRTUAL_FUNCTION
)
1988 dev
->netdev_ops
= &ipoib_netdev_ops_vf
;
1990 dev
->netdev_ops
= &ipoib_netdev_ops_pf
;
1992 rn
= netdev_priv(dev
);
1993 rn
->clnt_priv
= priv
;
1994 ipoib_build_priv(dev
);
2002 static ssize_t
show_pkey(struct device
*dev
,
2003 struct device_attribute
*attr
, char *buf
)
2005 struct net_device
*ndev
= to_net_dev(dev
);
2006 struct ipoib_dev_priv
*priv
= ipoib_priv(ndev
);
2008 return sprintf(buf
, "0x%04x\n", priv
->pkey
);
2010 static DEVICE_ATTR(pkey
, S_IRUGO
, show_pkey
, NULL
);
2012 static ssize_t
show_umcast(struct device
*dev
,
2013 struct device_attribute
*attr
, char *buf
)
2015 struct net_device
*ndev
= to_net_dev(dev
);
2016 struct ipoib_dev_priv
*priv
= ipoib_priv(ndev
);
2018 return sprintf(buf
, "%d\n", test_bit(IPOIB_FLAG_UMCAST
, &priv
->flags
));
2021 void ipoib_set_umcast(struct net_device
*ndev
, int umcast_val
)
2023 struct ipoib_dev_priv
*priv
= ipoib_priv(ndev
);
2025 if (umcast_val
> 0) {
2026 set_bit(IPOIB_FLAG_UMCAST
, &priv
->flags
);
2027 ipoib_warn(priv
, "ignoring multicast groups joined directly "
2030 clear_bit(IPOIB_FLAG_UMCAST
, &priv
->flags
);
2033 static ssize_t
set_umcast(struct device
*dev
,
2034 struct device_attribute
*attr
,
2035 const char *buf
, size_t count
)
2037 unsigned long umcast_val
= simple_strtoul(buf
, NULL
, 0);
2039 ipoib_set_umcast(to_net_dev(dev
), umcast_val
);
2043 static DEVICE_ATTR(umcast
, S_IWUSR
| S_IRUGO
, show_umcast
, set_umcast
);
2045 int ipoib_add_umcast_attr(struct net_device
*dev
)
2047 return device_create_file(&dev
->dev
, &dev_attr_umcast
);
2050 static void set_base_guid(struct ipoib_dev_priv
*priv
, union ib_gid
*gid
)
2052 struct ipoib_dev_priv
*child_priv
;
2053 struct net_device
*netdev
= priv
->dev
;
2055 netif_addr_lock_bh(netdev
);
2057 memcpy(&priv
->local_gid
.global
.interface_id
,
2058 &gid
->global
.interface_id
,
2059 sizeof(gid
->global
.interface_id
));
2060 memcpy(netdev
->dev_addr
+ 4, &priv
->local_gid
, sizeof(priv
->local_gid
));
2061 clear_bit(IPOIB_FLAG_DEV_ADDR_SET
, &priv
->flags
);
2063 netif_addr_unlock_bh(netdev
);
2065 if (!test_bit(IPOIB_FLAG_SUBINTERFACE
, &priv
->flags
)) {
2066 down_read(&priv
->vlan_rwsem
);
2067 list_for_each_entry(child_priv
, &priv
->child_intfs
, list
)
2068 set_base_guid(child_priv
, gid
);
2069 up_read(&priv
->vlan_rwsem
);
2073 static int ipoib_check_lladdr(struct net_device
*dev
,
2074 struct sockaddr_storage
*ss
)
2076 union ib_gid
*gid
= (union ib_gid
*)(ss
->__data
+ 4);
2079 netif_addr_lock_bh(dev
);
2081 /* Make sure the QPN, reserved and subnet prefix match the current
2082 * lladdr, it also makes sure the lladdr is unicast.
2084 if (memcmp(dev
->dev_addr
, ss
->__data
,
2085 4 + sizeof(gid
->global
.subnet_prefix
)) ||
2086 gid
->global
.interface_id
== 0)
2089 netif_addr_unlock_bh(dev
);
2094 static int ipoib_set_mac(struct net_device
*dev
, void *addr
)
2096 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
2097 struct sockaddr_storage
*ss
= addr
;
2100 if (!(dev
->priv_flags
& IFF_LIVE_ADDR_CHANGE
) && netif_running(dev
))
2103 ret
= ipoib_check_lladdr(dev
, ss
);
2107 set_base_guid(priv
, (union ib_gid
*)(ss
->__data
+ 4));
2109 queue_work(ipoib_workqueue
, &priv
->flush_light
);
2114 static ssize_t
create_child(struct device
*dev
,
2115 struct device_attribute
*attr
,
2116 const char *buf
, size_t count
)
2121 if (sscanf(buf
, "%i", &pkey
) != 1)
2124 if (pkey
<= 0 || pkey
> 0xffff || pkey
== 0x8000)
2128 * Set the full membership bit, so that we join the right
2129 * broadcast group, etc.
2133 ret
= ipoib_vlan_add(to_net_dev(dev
), pkey
);
2135 return ret
? ret
: count
;
2137 static DEVICE_ATTR(create_child
, S_IWUSR
, NULL
, create_child
);
2139 static ssize_t
delete_child(struct device
*dev
,
2140 struct device_attribute
*attr
,
2141 const char *buf
, size_t count
)
2146 if (sscanf(buf
, "%i", &pkey
) != 1)
2149 if (pkey
< 0 || pkey
> 0xffff)
2152 ret
= ipoib_vlan_delete(to_net_dev(dev
), pkey
);
2154 return ret
? ret
: count
;
2157 static DEVICE_ATTR(delete_child
, S_IWUSR
, NULL
, delete_child
);
2159 int ipoib_add_pkey_attr(struct net_device
*dev
)
2161 return device_create_file(&dev
->dev
, &dev_attr_pkey
);
2164 void ipoib_set_dev_features(struct ipoib_dev_priv
*priv
, struct ib_device
*hca
)
2166 priv
->hca_caps
= hca
->attrs
.device_cap_flags
;
2168 if (priv
->hca_caps
& IB_DEVICE_UD_IP_CSUM
) {
2169 priv
->dev
->hw_features
|= NETIF_F_IP_CSUM
| NETIF_F_RXCSUM
;
2171 if (priv
->hca_caps
& IB_DEVICE_UD_TSO
)
2172 priv
->dev
->hw_features
|= NETIF_F_TSO
;
2174 priv
->dev
->features
|= priv
->dev
->hw_features
;
2178 static struct net_device
*ipoib_add_port(const char *format
,
2179 struct ib_device
*hca
, u8 port
)
2181 struct ipoib_dev_priv
*priv
;
2182 struct ib_port_attr attr
;
2183 struct rdma_netdev
*rn
;
2184 int result
= -ENOMEM
;
2186 priv
= ipoib_intf_alloc(hca
, port
, format
);
2188 goto alloc_mem_failed
;
2190 SET_NETDEV_DEV(priv
->dev
, hca
->dev
.parent
);
2191 priv
->dev
->dev_id
= port
- 1;
2193 result
= ib_query_port(hca
, port
, &attr
);
2195 printk(KERN_WARNING
"%s: ib_query_port %d failed\n",
2197 goto device_init_failed
;
2200 priv
->max_ib_mtu
= ib_mtu_enum_to_int(attr
.max_mtu
);
2202 /* MTU will be reset when mcast join happens */
2203 priv
->dev
->mtu
= IPOIB_UD_MTU(priv
->max_ib_mtu
);
2204 priv
->mcast_mtu
= priv
->admin_mtu
= priv
->dev
->mtu
;
2205 priv
->dev
->max_mtu
= IPOIB_CM_MTU
;
2207 priv
->dev
->neigh_priv_len
= sizeof(struct ipoib_neigh
);
2209 result
= ib_query_pkey(hca
, port
, 0, &priv
->pkey
);
2211 printk(KERN_WARNING
"%s: ib_query_pkey port %d failed (ret = %d)\n",
2212 hca
->name
, port
, result
);
2213 goto device_init_failed
;
2216 ipoib_set_dev_features(priv
, hca
);
2219 * Set the full membership bit, so that we join the right
2220 * broadcast group, etc.
2222 priv
->pkey
|= 0x8000;
2224 priv
->dev
->broadcast
[8] = priv
->pkey
>> 8;
2225 priv
->dev
->broadcast
[9] = priv
->pkey
& 0xff;
2227 result
= ib_query_gid(hca
, port
, 0, &priv
->local_gid
, NULL
);
2229 printk(KERN_WARNING
"%s: ib_query_gid port %d failed (ret = %d)\n",
2230 hca
->name
, port
, result
);
2231 goto device_init_failed
;
2234 memcpy(priv
->dev
->dev_addr
+ 4, priv
->local_gid
.raw
,
2235 sizeof(union ib_gid
));
2236 set_bit(IPOIB_FLAG_DEV_ADDR_SET
, &priv
->flags
);
2238 result
= ipoib_dev_init(priv
->dev
, hca
, port
);
2240 printk(KERN_WARNING
"%s: failed to initialize port %d (ret = %d)\n",
2241 hca
->name
, port
, result
);
2242 goto device_init_failed
;
2245 INIT_IB_EVENT_HANDLER(&priv
->event_handler
,
2246 priv
->ca
, ipoib_event
);
2247 ib_register_event_handler(&priv
->event_handler
);
2249 result
= register_netdev(priv
->dev
);
2251 printk(KERN_WARNING
"%s: couldn't register ipoib port %d; error %d\n",
2252 hca
->name
, port
, result
);
2253 goto register_failed
;
2257 if (ipoib_cm_add_mode_attr(priv
->dev
))
2259 if (ipoib_add_pkey_attr(priv
->dev
))
2261 if (ipoib_add_umcast_attr(priv
->dev
))
2263 if (device_create_file(&priv
->dev
->dev
, &dev_attr_create_child
))
2265 if (device_create_file(&priv
->dev
->dev
, &dev_attr_delete_child
))
2271 unregister_netdev(priv
->dev
);
2274 ib_unregister_event_handler(&priv
->event_handler
);
2275 flush_workqueue(ipoib_workqueue
);
2276 /* Stop GC if started before flush */
2277 set_bit(IPOIB_STOP_NEIGH_GC
, &priv
->flags
);
2278 cancel_delayed_work(&priv
->neigh_reap_task
);
2279 flush_workqueue(priv
->wq
);
2280 ipoib_dev_cleanup(priv
->dev
);
2283 rn
= netdev_priv(priv
->dev
);
2284 rn
->free_rdma_netdev(priv
->dev
);
2288 return ERR_PTR(result
);
2291 static void ipoib_add_one(struct ib_device
*device
)
2293 struct list_head
*dev_list
;
2294 struct net_device
*dev
;
2295 struct ipoib_dev_priv
*priv
;
2299 dev_list
= kmalloc(sizeof *dev_list
, GFP_KERNEL
);
2303 INIT_LIST_HEAD(dev_list
);
2305 for (p
= rdma_start_port(device
); p
<= rdma_end_port(device
); ++p
) {
2306 if (!rdma_protocol_ib(device
, p
))
2308 dev
= ipoib_add_port("ib%d", device
, p
);
2310 priv
= ipoib_priv(dev
);
2311 list_add_tail(&priv
->list
, dev_list
);
2321 ib_set_client_data(device
, &ipoib_client
, dev_list
);
2324 static void ipoib_remove_one(struct ib_device
*device
, void *client_data
)
2326 struct ipoib_dev_priv
*priv
, *tmp
, *cpriv
, *tcpriv
;
2327 struct list_head
*dev_list
= client_data
;
2332 list_for_each_entry_safe(priv
, tmp
, dev_list
, list
) {
2333 struct rdma_netdev
*parent_rn
= netdev_priv(priv
->dev
);
2335 ib_unregister_event_handler(&priv
->event_handler
);
2336 flush_workqueue(ipoib_workqueue
);
2338 /* mark interface in the middle of destruction */
2339 set_bit(IPOIB_FLAG_GOING_DOWN
, &priv
->flags
);
2342 dev_change_flags(priv
->dev
, priv
->dev
->flags
& ~IFF_UP
);
2346 set_bit(IPOIB_STOP_NEIGH_GC
, &priv
->flags
);
2347 cancel_delayed_work(&priv
->neigh_reap_task
);
2348 flush_workqueue(priv
->wq
);
2350 /* Wrap rtnl_lock/unlock with mutex to protect sysfs calls */
2351 mutex_lock(&priv
->sysfs_mutex
);
2352 unregister_netdev(priv
->dev
);
2353 mutex_unlock(&priv
->sysfs_mutex
);
2355 parent_rn
->free_rdma_netdev(priv
->dev
);
2357 list_for_each_entry_safe(cpriv
, tcpriv
, &priv
->child_intfs
, list
) {
2358 struct rdma_netdev
*child_rn
;
2360 child_rn
= netdev_priv(cpriv
->dev
);
2361 child_rn
->free_rdma_netdev(cpriv
->dev
);
2371 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
2372 static struct notifier_block ipoib_netdev_notifier
= {
2373 .notifier_call
= ipoib_netdev_event
,
2377 static int __init
ipoib_init_module(void)
2381 ipoib_recvq_size
= roundup_pow_of_two(ipoib_recvq_size
);
2382 ipoib_recvq_size
= min(ipoib_recvq_size
, IPOIB_MAX_QUEUE_SIZE
);
2383 ipoib_recvq_size
= max(ipoib_recvq_size
, IPOIB_MIN_QUEUE_SIZE
);
2385 ipoib_sendq_size
= roundup_pow_of_two(ipoib_sendq_size
);
2386 ipoib_sendq_size
= min(ipoib_sendq_size
, IPOIB_MAX_QUEUE_SIZE
);
2387 ipoib_sendq_size
= max3(ipoib_sendq_size
, 2 * MAX_SEND_CQE
, IPOIB_MIN_QUEUE_SIZE
);
2388 #ifdef CONFIG_INFINIBAND_IPOIB_CM
2389 ipoib_max_conn_qp
= min(ipoib_max_conn_qp
, IPOIB_CM_MAX_CONN_QP
);
2390 ipoib_max_conn_qp
= max(ipoib_max_conn_qp
, 0);
2394 * When copying small received packets, we only copy from the
2395 * linear data part of the SKB, so we rely on this condition.
2397 BUILD_BUG_ON(IPOIB_CM_COPYBREAK
> IPOIB_CM_HEAD_SIZE
);
2399 ret
= ipoib_register_debugfs();
2404 * We create a global workqueue here that is used for all flush
2405 * operations. However, if you attempt to flush a workqueue
2406 * from a task on that same workqueue, it deadlocks the system.
2407 * We want to be able to flush the tasks associated with a
2408 * specific net device, so we also create a workqueue for each
2409 * netdevice. We queue up the tasks for that device only on
2410 * its private workqueue, and we only queue up flush events
2411 * on our global flush workqueue. This avoids the deadlocks.
2413 ipoib_workqueue
= alloc_ordered_workqueue("ipoib_flush",
2415 if (!ipoib_workqueue
) {
2420 ib_sa_register_client(&ipoib_sa_client
);
2422 ret
= ib_register_client(&ipoib_client
);
2426 ret
= ipoib_netlink_init();
2430 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
2431 register_netdevice_notifier(&ipoib_netdev_notifier
);
2436 ib_unregister_client(&ipoib_client
);
2439 ib_sa_unregister_client(&ipoib_sa_client
);
2440 destroy_workqueue(ipoib_workqueue
);
2443 ipoib_unregister_debugfs();
2448 static void __exit
ipoib_cleanup_module(void)
2450 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
2451 unregister_netdevice_notifier(&ipoib_netdev_notifier
);
2453 ipoib_netlink_fini();
2454 ib_unregister_client(&ipoib_client
);
2455 ib_sa_unregister_client(&ipoib_sa_client
);
2456 ipoib_unregister_debugfs();
2457 destroy_workqueue(ipoib_workqueue
);
2460 module_init(ipoib_init_module
);
2461 module_exit(ipoib_cleanup_module
);