IB/rxe: Use rdma GID API
authorParav Pandit <parav@mellanox.com>
Tue, 5 Jun 2018 05:40:23 +0000 (08:40 +0300)
committerJason Gunthorpe <jgg@mellanox.com>
Mon, 18 Jun 2018 17:09:05 +0000 (11:09 -0600)
rxe_netdev_from_av can now be done by the core code directly from the
gid_attrs, no need for a helper in the driver.

ib_find_cached_gid_by_port can be switched to use the rdma version here as
well.

Signed-off-by: Parav Pandit <parav@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
drivers/infiniband/sw/rxe/rxe_net.c
drivers/infiniband/sw/rxe/rxe_recv.c

index 59ec6d918ed4782c78370bdafcef06eee48d848b..79b69943a8afaf04063b9f61fc8ddb0dc1eda6a1 100644 (file)
@@ -182,39 +182,19 @@ static struct dst_entry *rxe_find_route6(struct net_device *ndev,
 
 #endif
 
-/*
- * Derive the net_device from the av.
- * For physical devices, this will just return rxe->ndev.
- * But for VLAN devices, it will return the vlan dev.
- * Caller should dev_put() the returned net_device.
- */
-static struct net_device *rxe_netdev_from_av(struct rxe_dev *rxe,
-                                            int port_num,
-                                            struct rxe_av *av)
-{
-       union ib_gid gid;
-       struct ib_gid_attr attr;
-       struct net_device *ndev = rxe->ndev;
-
-       if (ib_get_cached_gid(&rxe->ib_dev, port_num, av->grh.sgid_index,
-                             &gid, &attr) == 0 &&
-           attr.ndev && attr.ndev != ndev)
-               ndev = attr.ndev;
-       else
-               /* Only to ensure that caller may call dev_put() */
-               dev_hold(ndev);
-
-       return ndev;
-}
-
 static struct dst_entry *rxe_find_route(struct rxe_dev *rxe,
                                        struct rxe_qp *qp,
                                        struct rxe_av *av)
 {
+       const struct ib_gid_attr *attr;
        struct dst_entry *dst = NULL;
        struct net_device *ndev;
 
-       ndev = rxe_netdev_from_av(rxe, qp->attr.port_num, av);
+       attr = rdma_get_gid_attr(&rxe->ib_dev, qp->attr.port_num,
+                                av->grh.sgid_index);
+       if (IS_ERR(attr))
+               return NULL;
+       ndev = attr->ndev;
 
        if (qp_type(qp) == IB_QPT_RC)
                dst = sk_dst_get(qp->sk->sk);
@@ -244,8 +224,7 @@ static struct dst_entry *rxe_find_route(struct rxe_dev *rxe,
 #endif
                }
        }
-
-       dev_put(ndev);
+       rdma_put_gid_attr(attr);
        return dst;
 }
 
@@ -536,9 +515,13 @@ struct sk_buff *rxe_init_packet(struct rxe_dev *rxe, struct rxe_av *av,
        unsigned int hdr_len;
        struct sk_buff *skb;
        struct net_device *ndev;
+       const struct ib_gid_attr *attr;
        const int port_num = 1;
 
-       ndev = rxe_netdev_from_av(rxe, port_num, av);
+       attr = rdma_get_gid_attr(&rxe->ib_dev, port_num, av->grh.sgid_index);
+       if (IS_ERR(attr))
+               return NULL;
+       ndev = attr->ndev;
 
        if (av->network_type == RDMA_NETWORK_IPV4)
                hdr_len = ETH_HLEN + sizeof(struct udphdr) +
@@ -550,10 +533,8 @@ struct sk_buff *rxe_init_packet(struct rxe_dev *rxe, struct rxe_av *av,
        skb = alloc_skb(paylen + hdr_len + LL_RESERVED_SPACE(ndev),
                        GFP_ATOMIC);
 
-       if (unlikely(!skb)) {
-               dev_put(ndev);
-               return NULL;
-       }
+       if (unlikely(!skb))
+               goto out;
 
        skb_reserve(skb, hdr_len + LL_RESERVED_SPACE(rxe->ndev));
 
@@ -568,7 +549,8 @@ struct sk_buff *rxe_init_packet(struct rxe_dev *rxe, struct rxe_av *av,
        pkt->hdr        = skb_put_zero(skb, paylen);
        pkt->mask       |= RXE_GRH_MASK;
 
-       dev_put(ndev);
+out:
+       rdma_put_gid_attr(attr);
        return skb;
 }
 
index dfba44a40f0b4a92ae0102e634e693ff81a5a642..42797ac6f7b161d6eed3293861b5a5d65350a002 100644 (file)
@@ -328,6 +328,7 @@ err1:
 
 static int rxe_match_dgid(struct rxe_dev *rxe, struct sk_buff *skb)
 {
+       const struct ib_gid_attr *gid_attr;
        union ib_gid dgid;
        union ib_gid *pdgid;
 
@@ -339,9 +340,14 @@ static int rxe_match_dgid(struct rxe_dev *rxe, struct sk_buff *skb)
                pdgid = (union ib_gid *)&ipv6_hdr(skb)->daddr;
        }
 
-       return ib_find_cached_gid_by_port(&rxe->ib_dev, pdgid,
-                                         IB_GID_TYPE_ROCE_UDP_ENCAP,
-                                         1, skb->dev, NULL);
+       gid_attr = rdma_find_gid_by_port(&rxe->ib_dev, pdgid,
+                                        IB_GID_TYPE_ROCE_UDP_ENCAP,
+                                        1, skb->dev);
+       if (IS_ERR(gid_attr))
+               return PTR_ERR(gid_attr);
+
+       rdma_put_gid_attr(gid_attr);
+       return 0;
 }
 
 /* rxe_rcv is called from the interface driver */