IB/core: Add netdev and gid attributes paramteres to cache
authorMatan Barak <matanb@mellanox.com>
Thu, 15 Oct 2015 15:38:45 +0000 (18:38 +0300)
committerDoug Ledford <dledford@redhat.com>
Thu, 22 Oct 2015 03:48:17 +0000 (23:48 -0400)
Adding an ability to query the IB cache by a netdev and get the
attributes of a GID. These parameters are necessary in order to
successfully resolve the required GID (when the netdevice is known)
and get the Ethernet L2 attributes from a GID.

Signed-off-by: Matan Barak <matanb@mellanox.com>
Reviewed-By: Devesh Sharma <devesh.sharma@avagotech.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
19 files changed:
drivers/infiniband/core/cache.c
drivers/infiniband/core/cm.c
drivers/infiniband/core/cma.c
drivers/infiniband/core/device.c
drivers/infiniband/core/mad.c
drivers/infiniband/core/multicast.c
drivers/infiniband/core/sa_query.c
drivers/infiniband/core/sysfs.c
drivers/infiniband/core/verbs.c
drivers/infiniband/hw/mlx4/main.c
drivers/infiniband/hw/mlx4/qp.c
drivers/infiniband/hw/mthca/mthca_av.c
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
drivers/infiniband/ulp/ipoib/ipoib_main.c
drivers/infiniband/ulp/ipoib/ipoib_multicast.c
drivers/infiniband/ulp/srp/ib_srp.c
drivers/infiniband/ulp/srpt/ib_srpt.c
include/rdma/ib_cache.h
include/rdma/ib_verbs.h

index 87471ef371986c11f59e6761e7566ebec78cc1cd..5c054072ef2008d2222665538d95745c82d91bb9 100644 (file)
@@ -649,21 +649,23 @@ static int gid_table_setup_one(struct ib_device *ib_dev)
 int ib_get_cached_gid(struct ib_device *device,
                      u8                port_num,
                      int               index,
-                     union ib_gid     *gid)
+                     union ib_gid     *gid,
+                     struct ib_gid_attr *gid_attr)
 {
        if (port_num < rdma_start_port(device) || port_num > rdma_end_port(device))
                return -EINVAL;
 
-       return __ib_cache_gid_get(device, port_num, index, gid, NULL);
+       return __ib_cache_gid_get(device, port_num, index, gid, gid_attr);
 }
 EXPORT_SYMBOL(ib_get_cached_gid);
 
 int ib_find_cached_gid(struct ib_device *device,
                       const union ib_gid *gid,
+                      struct net_device *ndev,
                       u8               *port_num,
                       u16              *index)
 {
-       return ib_cache_gid_find(device, gid, NULL, port_num, index);
+       return ib_cache_gid_find(device, gid, ndev, port_num, index);
 }
 EXPORT_SYMBOL(ib_find_cached_gid);
 
@@ -845,7 +847,7 @@ static void ib_cache_update(struct ib_device *device,
        if (!use_roce_gid_table) {
                for (i = 0;  i < gid_cache->table_len; ++i) {
                        ret = ib_query_gid(device, port, i,
-                                          gid_cache->table + i);
+                                          gid_cache->table + i, NULL);
                        if (ret) {
                                printk(KERN_WARNING "ib_query_gid failed (%d) for %s (index %d)\n",
                                       ret, device->name, i);
index 4f918b929eca955532cd5dc0541bc842272a0a3b..2d8a0e4c42d6567cbc925ce46a1d51e770ff5a89 100644 (file)
@@ -365,7 +365,7 @@ static int cm_init_av_by_path(struct ib_sa_path_rec *path, struct cm_av *av)
        read_lock_irqsave(&cm.device_lock, flags);
        list_for_each_entry(cm_dev, &cm.device_list, list) {
                if (!ib_find_cached_gid(cm_dev->ib_device, &path->sgid,
-                                       &p, NULL)) {
+                                       NULL, &p, NULL)) {
                        port = cm_dev->port[p-1];
                        break;
                }
@@ -1643,7 +1643,8 @@ static int cm_req_handler(struct cm_work *work)
        ret = cm_init_av_by_path(&work->path[0], &cm_id_priv->av);
        if (ret) {
                ib_get_cached_gid(work->port->cm_dev->ib_device,
-                                 work->port->port_num, 0, &work->path[0].sgid);
+                                 work->port->port_num, 0, &work->path[0].sgid,
+                                 NULL);
                ib_send_cm_rej(cm_id, IB_CM_REJ_INVALID_GID,
                               &work->path[0].sgid, sizeof work->path[0].sgid,
                               NULL, 0);
index 36b12d560e17e5a862a2e37d1f56875b46425f4b..e4d9d75ffc083f5ee7036a12db496d4582ef6dc7 100644 (file)
@@ -438,7 +438,7 @@ static inline int cma_validate_port(struct ib_device *device, u8 port,
        if ((dev_type != ARPHRD_INFINIBAND) && rdma_protocol_ib(device, port))
                return ret;
 
-       ret = ib_find_cached_gid(device, gid, &found_port, NULL);
+       ret = ib_find_cached_gid(device, gid, NULL, &found_port, NULL);
        if (port != found_port)
                return -ENODEV;
 
@@ -531,7 +531,9 @@ static int cma_resolve_ib_dev(struct rdma_id_private *id_priv)
                        if (ib_find_cached_pkey(cur_dev->device, p, pkey, &index))
                                continue;
 
-                       for (i = 0; !ib_get_cached_gid(cur_dev->device, p, i, &gid); i++) {
+                       for (i = 0; !ib_get_cached_gid(cur_dev->device, p, i,
+                                                      &gid, NULL);
+                            i++) {
                                if (!memcmp(&gid, dgid, sizeof(gid))) {
                                        cma_dev = cur_dev;
                                        sgid = gid;
@@ -718,7 +720,7 @@ static int cma_modify_qp_rtr(struct rdma_id_private *id_priv,
                goto out;
 
        ret = ib_query_gid(id_priv->id.device, id_priv->id.port_num,
-                          qp_attr.ah_attr.grh.sgid_index, &sgid);
+                          qp_attr.ah_attr.grh.sgid_index, &sgid, NULL);
        if (ret)
                goto out;
 
@@ -2426,7 +2428,7 @@ static int cma_bind_loopback(struct rdma_id_private *id_priv)
        p = 1;
 
 port_found:
-       ret = ib_get_cached_gid(cma_dev->device, p, 0, &gid);
+       ret = ib_get_cached_gid(cma_dev->device, p, 0, &gid, NULL);
        if (ret)
                goto out;
 
index 17639117afc6ab8637c7e73a3e2a13e6101a9702..f22ce487fd3a8be6ead305eee8e1b6e30cc1b7de 100644 (file)
@@ -672,14 +672,20 @@ EXPORT_SYMBOL(ib_query_port);
  * @port_num:Port number to query
  * @index:GID table index to query
  * @gid:Returned GID
+ * @attr: Returned GID attributes related to this GID index (only in RoCE).
+ *   NULL means ignore.
  *
  * ib_query_gid() fetches the specified GID table entry.
  */
 int ib_query_gid(struct ib_device *device,
-                u8 port_num, int index, union ib_gid *gid)
+                u8 port_num, int index, union ib_gid *gid,
+                struct ib_gid_attr *attr)
 {
        if (rdma_cap_roce_gid_table(device, port_num))
-               return ib_get_cached_gid(device, port_num, index, gid);
+               return ib_get_cached_gid(device, port_num, index, gid, attr);
+
+       if (attr)
+               return -EINVAL;
 
        return device->query_gid(device, port_num, index, gid);
 }
@@ -819,12 +825,13 @@ EXPORT_SYMBOL(ib_modify_port);
  *   a specified GID value occurs.
  * @device: The device to query.
  * @gid: The GID value to search for.
+ * @ndev: The ndev related to the GID to search for.
  * @port_num: The port number of the device where the GID value was found.
  * @index: The index into the GID table where the GID was found.  This
  *   parameter may be NULL.
  */
 int ib_find_gid(struct ib_device *device, union ib_gid *gid,
-               u8 *port_num, u16 *index)
+               struct net_device *ndev, u8 *port_num, u16 *index)
 {
        union ib_gid tmp_gid;
        int ret, port, i;
@@ -832,14 +839,14 @@ int ib_find_gid(struct ib_device *device, union ib_gid *gid,
        for (port = rdma_start_port(device); port <= rdma_end_port(device); ++port) {
                if (rdma_cap_roce_gid_table(device, port)) {
                        if (!ib_cache_gid_find_by_port(device, gid, port,
-                                                      NULL, index)) {
+                                                      ndev, index)) {
                                *port_num = port;
                                return 0;
                        }
                }
 
                for (i = 0; i < device->port_immutable[port].gid_tbl_len; ++i) {
-                       ret = ib_query_gid(device, port, i, &tmp_gid);
+                       ret = ib_query_gid(device, port, i, &tmp_gid, NULL);
                        if (ret)
                                return ret;
                        if (!memcmp(&tmp_gid, gid, sizeof *gid)) {
index 4b5c72311debbe59ae0975ec6d0fa722db13234e..fa63b89e15aac7ece9de389dca05ee2316fa7ec9 100644 (file)
@@ -1877,7 +1877,7 @@ static inline int rcv_has_same_gid(const struct ib_mad_agent_private *mad_agent_
                                          ((1 << lmc) - 1)));
                } else {
                        if (ib_get_cached_gid(device, port_num,
-                                             attr.grh.sgid_index, &sgid))
+                                             attr.grh.sgid_index, &sgid, NULL))
                                return 0;
                        return !memcmp(sgid.raw, rwc->recv_buf.grh->dgid.raw,
                                       16);
index d38d8b2b2979ddc2bebb243b98b79a04644fc929..bb6685fb08c61483546505f99037b88af6202ad0 100644 (file)
@@ -729,7 +729,8 @@ int ib_init_ah_from_mcmember(struct ib_device *device, u8 port_num,
        u16 gid_index;
        u8 p;
 
-       ret = ib_find_cached_gid(device, &rec->port_gid, &p, &gid_index);
+       ret = ib_find_cached_gid(device, &rec->port_gid,
+                                NULL, &p, &gid_index);
        if (ret)
                return ret;
 
index 8c014b33d8e0a5bc97e6e2408b3ded37ddfd06c2..9a4e7891ada20ad7b72bc20fcb31defa5f6808ad 100644 (file)
@@ -1010,7 +1010,7 @@ int ib_init_ah_from_path(struct ib_device *device, u8 port_num,
                ah_attr->ah_flags = IB_AH_GRH;
                ah_attr->grh.dgid = rec->dgid;
 
-               ret = ib_find_cached_gid(device, &rec->sgid, &port_num,
+               ret = ib_find_cached_gid(device, &rec->sgid, NULL, &port_num,
                                         &gid_index);
                if (ret)
                        return ret;
index 34cdd74b0a17ed06228bf78f134c2001c976125a..b1f37d4095fa1e15f7402c35a367b00e1f24b6b5 100644 (file)
@@ -289,7 +289,7 @@ static ssize_t show_port_gid(struct ib_port *p, struct port_attribute *attr,
        union ib_gid gid;
        ssize_t ret;
 
-       ret = ib_query_gid(p->ibdev, p->port_num, tab_attr->index, &gid);
+       ret = ib_query_gid(p->ibdev, p->port_num, tab_attr->index, &gid, NULL);
        if (ret)
                return ret;
 
index e1f2c9887f3f48ebc20c0931304ae75c5f65c03f..6012f5e5b97c030fa5fad519cbaeb5207d725d92 100644 (file)
@@ -344,8 +344,8 @@ int ib_init_ah_from_wc(struct ib_device *device, u8 port_num,
                ah_attr->ah_flags = IB_AH_GRH;
                ah_attr->grh.dgid = grh->sgid;
 
-               ret = ib_find_cached_gid(device, &grh->dgid, &port_num,
-                                        &gid_index);
+               ret = ib_find_cached_gid(device, &grh->dgid,
+                                        NULL, &port_num, &gid_index);
                if (ret)
                        return ret;
 
@@ -988,7 +988,8 @@ int ib_resolve_eth_l2_attrs(struct ib_qp *qp,
        if ((*qp_attr_mask & IB_QP_AV)  &&
            (rdma_cap_eth_ah(qp->device, qp_attr->ah_attr.port_num))) {
                ret = ib_query_gid(qp->device, qp_attr->ah_attr.port_num,
-                                  qp_attr->ah_attr.grh.sgid_index, &sgid);
+                                  qp_attr->ah_attr.grh.sgid_index, &sgid,
+                                  NULL);
                if (ret)
                        goto out;
                if (rdma_link_local_addr((struct in6_addr *)qp_attr->ah_attr.grh.dgid.raw)) {
index 8779d26d1e61f13a44f403c02bb7aab350388199..f63d5427bfc0c55153738061ebb9b1c607f7b4fd 100644 (file)
@@ -335,7 +335,7 @@ int mlx4_ib_gid_index_to_real_index(struct mlx4_ib_dev *ibdev,
        if (!rdma_cap_roce_gid_table(&ibdev->ib_dev, port_num))
                return index;
 
-       ret = ib_get_cached_gid(&ibdev->ib_dev, port_num, index, &gid);
+       ret = ib_get_cached_gid(&ibdev->ib_dev, port_num, index, &gid, NULL);
        if (ret)
                return ret;
 
@@ -756,7 +756,7 @@ static int mlx4_ib_query_gid(struct ib_device *ibdev, u8 port, int index,
        if (!rdma_cap_roce_gid_table(ibdev, port))
                return -ENODEV;
 
-       ret = ib_get_cached_gid(ibdev, port, index, gid);
+       ret = ib_get_cached_gid(ibdev, port, index, gid, NULL);
        if (ret == -EAGAIN) {
                memcpy(gid, &zgid, sizeof(*gid));
                return 0;
index ba25a1bfa52f67f2b0d4da54a9e67a5db3f83890..b52c9e1cdf1aef280be4da84705acb2e0504b062 100644 (file)
@@ -2269,7 +2269,8 @@ static int build_mlx_header(struct mlx4_ib_sqp *sqp, struct ib_send_wr *wr,
                } else  {
                        err = ib_get_cached_gid(ib_dev,
                                                be32_to_cpu(ah->av.ib.port_pd) >> 24,
-                                               ah->av.ib.gid_index, &sgid);
+                                               ah->av.ib.gid_index, &sgid,
+                                               NULL);
                        if (err)
                                return err;
                }
@@ -2311,7 +2312,7 @@ static int build_mlx_header(struct mlx4_ib_sqp *sqp, struct ib_send_wr *wr,
                        ib_get_cached_gid(ib_dev,
                                          be32_to_cpu(ah->av.ib.port_pd) >> 24,
                                          ah->av.ib.gid_index,
-                                         &sqp->ud_header.grh.source_gid);
+                                         &sqp->ud_header.grh.source_gid, NULL);
                }
                memcpy(sqp->ud_header.grh.destination_gid.raw,
                       ah->av.ib.dgid, 16);
index 32f6c63154541dec229ec8904d1438fddb88d14d..bcac294042f5e315e6324cbb0478f56d0524049c 100644 (file)
@@ -281,7 +281,7 @@ int mthca_read_ah(struct mthca_dev *dev, struct mthca_ah *ah,
                ib_get_cached_gid(&dev->ib_dev,
                                  be32_to_cpu(ah->av->port_pd) >> 24,
                                  ah->av->gid_index % dev->limits.gid_table_len,
-                                 &header->grh.source_gid);
+                                 &header->grh.source_gid, NULL);
                memcpy(header->grh.destination_gid.raw,
                       ah->av->dgid, 16);
        }
index 1c4e83d5d153a4f7b02b5a252ba562f0a867ea1a..9bb710a402cdeda9c991477a6ef732c0e4544c48 100644 (file)
@@ -73,7 +73,7 @@ int ocrdma_query_gid(struct ib_device *ibdev, u8 port,
        if (index >= OCRDMA_MAX_SGID)
                return -EINVAL;
 
-       ret = ib_get_cached_gid(ibdev, port, index, sgid);
+       ret = ib_get_cached_gid(ibdev, port, index, sgid, NULL);
        if (ret == -EAGAIN) {
                memcpy(sgid, &zgid, sizeof(*sgid));
                return 0;
index babba05d7a0eb707f472d7de3cb06843a0844eff..cbb6721d0a6526252a29494798f66f8b361c7fbe 100644 (file)
@@ -1860,7 +1860,7 @@ static struct net_device *ipoib_add_port(const char *format,
        priv->dev->broadcast[8] = priv->pkey >> 8;
        priv->dev->broadcast[9] = priv->pkey & 0xff;
 
-       result = ib_query_gid(hca, port, 0, &priv->local_gid);
+       result = ib_query_gid(hca, port, 0, &priv->local_gid, NULL);
        if (result) {
                printk(KERN_WARNING "%s: ib_query_gid port %d failed (ret = %d)\n",
                       hca->name, port, result);
index d750a86042f3d8da0736c23a52f41737b329c37d..d4b97614196c1ba1f6252af2967f735ce7a1a42c 100644 (file)
@@ -561,7 +561,7 @@ void ipoib_mcast_join_task(struct work_struct *work)
        }
        priv->local_lid = port_attr.lid;
 
-       if (ib_query_gid(priv->ca, priv->port, 0, &priv->local_gid))
+       if (ib_query_gid(priv->ca, priv->port, 0, &priv->local_gid, NULL))
                ipoib_warn(priv, "ib_query_gid() failed\n");
        else
                memcpy(priv->dev->dev_addr + 4, priv->local_gid.raw, sizeof (union ib_gid));
index b481490ad25756f6de36cd718c0983be751c8e5c..8ba887824d055f9823914a2bbee30501cf998508 100644 (file)
@@ -3213,7 +3213,7 @@ static ssize_t srp_create_target(struct device *dev,
        INIT_WORK(&target->tl_err_work, srp_tl_err_work);
        INIT_WORK(&target->remove_work, srp_remove_work);
        spin_lock_init(&target->lock);
-       ret = ib_query_gid(ibdev, host->port, 0, &target->sgid);
+       ret = ib_query_gid(ibdev, host->port, 0, &target->sgid, NULL);
        if (ret)
                goto out;
 
index f6fe0414139beeafa3ddfba0ed33bf1ebc6a7489..a7ac77a02593af24cd4cea86e63e5997dbb55b3e 100644 (file)
@@ -546,7 +546,8 @@ static int srpt_refresh_port(struct srpt_port *sport)
        sport->sm_lid = port_attr.sm_lid;
        sport->lid = port_attr.lid;
 
-       ret = ib_query_gid(sport->sdev->device, sport->port, 0, &sport->gid);
+       ret = ib_query_gid(sport->sdev->device, sport->port, 0, &sport->gid,
+                          NULL);
        if (ret)
                goto err_query_port;
 
index bd92130f4ac5803a60e0c058bc19d26faca9f948..dcc9bed9b69aa800897fa2b6ce742c69f24ccc66 100644 (file)
@@ -43,6 +43,8 @@
  * @port_num: The port number of the device to query.
  * @index: The index into the cached GID table to query.
  * @gid: The GID value found at the specified index.
+ * @attr: The GID attribute found at the specified index (only in RoCE).
+ *   NULL means ignore (output parameter).
  *
  * ib_get_cached_gid() fetches the specified GID table entry stored in
  * the local software cache.
 int ib_get_cached_gid(struct ib_device    *device,
                      u8                   port_num,
                      int                  index,
-                     union ib_gid        *gid);
+                     union ib_gid        *gid,
+                     struct ib_gid_attr  *attr);
 
 /**
  * ib_find_cached_gid - Returns the port number and GID table index where
  *   a specified GID value occurs.
  * @device: The device to query.
  * @gid: The GID value to search for.
+ * @ndev: In RoCE, the net device of the device. NULL means ignore.
  * @port_num: The port number of the device where the GID value was found.
  * @index: The index into the cached GID table where the GID was found.  This
  *   parameter may be NULL.
@@ -64,10 +68,11 @@ int ib_get_cached_gid(struct ib_device    *device,
  * ib_find_cached_gid() searches for the specified GID value in
  * the local software cache.
  */
-int ib_find_cached_gid(struct ib_device   *device,
+int ib_find_cached_gid(struct ib_device *device,
                       const union ib_gid *gid,
-                      u8                 *port_num,
-                      u16                *index);
+                      struct net_device *ndev,
+                      u8               *port_num,
+                      u16              *index);
 
 /**
  * ib_get_cached_pkey - Returns a cached PKey table entry
index e1f65e204d37d01abb8709c4a8ebc9fce98c1b39..98ded0b749cd76bd4dd20146894e6f03c8f826c2 100644 (file)
@@ -2177,7 +2177,8 @@ static inline bool rdma_cap_roce_gid_table(const struct ib_device *device,
 }
 
 int ib_query_gid(struct ib_device *device,
-                u8 port_num, int index, union ib_gid *gid);
+                u8 port_num, int index, union ib_gid *gid,
+                struct ib_gid_attr *attr);
 
 int ib_query_pkey(struct ib_device *device,
                  u8 port_num, u16 index, u16 *pkey);
@@ -2191,7 +2192,7 @@ int ib_modify_port(struct ib_device *device,
                   struct ib_port_modify *port_modify);
 
 int ib_find_gid(struct ib_device *device, union ib_gid *gid,
-               u8 *port_num, u16 *index);
+               struct net_device *ndev, u8 *port_num, u16 *index);
 
 int ib_find_pkey(struct ib_device *device,
                 u8 port_num, u16 pkey, u16 *index);