IB/core: Pass hardware specific data in query_device
authorMatan Barak <matanb@mellanox.com>
Thu, 11 Jun 2015 13:35:25 +0000 (16:35 +0300)
committerDoug Ledford <dledford@redhat.com>
Fri, 12 Jun 2015 18:49:10 +0000 (14:49 -0400)
Vendors should be able to pass vendor specific data to/from
user-space via query_device uverb. In order to do this,
we need to pass the vendors' specific udata.

Signed-off-by: Matan Barak <matanb@mellanox.com>
Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
18 files changed:
drivers/infiniband/core/device.c
drivers/infiniband/core/uverbs_cmd.c
drivers/infiniband/hw/amso1100/c2_provider.c
drivers/infiniband/hw/cxgb3/iwch_provider.c
drivers/infiniband/hw/cxgb4/provider.c
drivers/infiniband/hw/ehca/ehca_hca.c
drivers/infiniband/hw/ehca/ehca_iverbs.h
drivers/infiniband/hw/ipath/ipath_verbs.c
drivers/infiniband/hw/mlx4/main.c
drivers/infiniband/hw/mlx5/main.c
drivers/infiniband/hw/mthca/mthca_provider.c
drivers/infiniband/hw/nes/nes_verbs.c
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
drivers/infiniband/hw/ocrdma/ocrdma_verbs.h
drivers/infiniband/hw/qib/qib_verbs.c
drivers/infiniband/hw/usnic/usnic_ib_verbs.c
drivers/infiniband/hw/usnic/usnic_ib_verbs.h
include/rdma/ib_verbs.h

index 568cb41be904e88bb74efd6b70a3798e9a1e9f66..694bd669b2d8b8c5ca7a553b7e3f4b5734560a51 100644 (file)
@@ -539,9 +539,11 @@ EXPORT_SYMBOL(ib_dispatch_event);
 int ib_query_device(struct ib_device *device,
                    struct ib_device_attr *device_attr)
 {
+       struct ib_udata uhw = {.outlen = 0, .inlen = 0};
+
        memset(device_attr, 0, sizeof(*device_attr));
 
-       return device->query_device(device, device_attr);
+       return device->query_device(device, device_attr, &uhw);
 }
 EXPORT_SYMBOL(ib_query_device);
 
index 11ee298bb26b00540df1a1c1d0ed772ca04299c3..bbb02ffe87df97ea2696e97e4baf9ae1718d0355 100644 (file)
@@ -3428,7 +3428,7 @@ int ib_uverbs_ex_query_device(struct ib_uverbs_file *file,
 
        memset(&attr, 0, sizeof(attr));
 
-       err = device->query_device(device, &attr);
+       err = device->query_device(device, &attr, uhw);
        if (err)
                return err;
 
index 8ea569f2cfa687dc56b4172015ca23e23db8a069..adfcef0946f73fed3180eb42a056c8a11db2f689 100644 (file)
 #include "c2_provider.h"
 #include "c2_user.h"
 
-static int c2_query_device(struct ib_device *ibdev,
-                          struct ib_device_attr *props)
+static int c2_query_device(struct ib_device *ibdev, struct ib_device_attr *props,
+                          struct ib_udata *uhw)
 {
        struct c2_dev *c2dev = to_c2dev(ibdev);
 
        pr_debug("%s:%u\n", __func__, __LINE__);
 
+       if (uhw->inlen || uhw->outlen)
+               return -EINVAL;
+
        *props = c2dev->props;
        return 0;
 }
index b3b847c3d24b67988706b527665b546278e247e0..208b68b9bba1af4fe2777b3c13acad802771f933 100644 (file)
@@ -1150,13 +1150,17 @@ static u64 fw_vers_string_to_u64(struct iwch_dev *iwch_dev)
               (fw_mic & 0xffff);
 }
 
-static int iwch_query_device(struct ib_device *ibdev,
-                            struct ib_device_attr *props)
+static int iwch_query_device(struct ib_device *ibdev, struct ib_device_attr *props,
+                            struct ib_udata *uhw)
 {
 
        struct iwch_dev *dev;
+
        PDBG("%s ibdev %p\n", __func__, ibdev);
 
+       if (uhw->inlen || uhw->outlen)
+               return -EINVAL;
+
        dev = to_iwch_dev(ibdev);
        memset(props, 0, sizeof *props);
        memcpy(&props->sys_image_guid, dev->rdev.t3cdev_p->lldev->dev_addr, 6);
index 75ea26a32076997a273d2fc9aadbe693cdeffe9b..2e909ddd065fb67a71ef174bf48ed7af5a611de2 100644 (file)
@@ -302,13 +302,17 @@ static int c4iw_query_gid(struct ib_device *ibdev, u8 port, int index,
        return 0;
 }
 
-static int c4iw_query_device(struct ib_device *ibdev,
-                            struct ib_device_attr *props)
+static int c4iw_query_device(struct ib_device *ibdev, struct ib_device_attr *props,
+                            struct ib_udata *uhw)
 {
 
        struct c4iw_dev *dev;
+
        PDBG("%s ibdev %p\n", __func__, ibdev);
 
+       if (uhw->inlen || uhw->outlen)
+               return -EINVAL;
+
        dev = to_c4iw_dev(ibdev);
        memset(props, 0, sizeof *props);
        memcpy(&props->sys_image_guid, dev->rdev.lldi.ports[0]->dev_addr, 6);
index 9ed4d2588304a2029e4d401aaee28e8cddd3403e..e8b1bb65797a97c19180a477a7bb62471f25dbf5 100644 (file)
@@ -50,7 +50,8 @@ static unsigned int limit_uint(unsigned int value)
        return min_t(unsigned int, value, INT_MAX);
 }
 
-int ehca_query_device(struct ib_device *ibdev, struct ib_device_attr *props)
+int ehca_query_device(struct ib_device *ibdev, struct ib_device_attr *props,
+                     struct ib_udata *uhw)
 {
        int i, ret = 0;
        struct ehca_shca *shca = container_of(ibdev, struct ehca_shca,
@@ -71,6 +72,9 @@ int ehca_query_device(struct ib_device *ibdev, struct ib_device_attr *props)
                IB_DEVICE_PORT_ACTIVE_EVENT,  HCA_CAP_PORT_ACTIVE_EVENT,
        };
 
+       if (uhw->inlen || uhw->outlen)
+               return -EINVAL;
+
        rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
        if (!rblock) {
                ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
index 62caf2ee020913bba03d6145662c9bb7c8d56fc8..568e52bcfb605fbc6a1b51c9a988e87f8e344bbc 100644 (file)
@@ -44,7 +44,8 @@
 
 #include "ehca_classes.h"
 
-int ehca_query_device(struct ib_device *ibdev, struct ib_device_attr *props);
+int ehca_query_device(struct ib_device *ibdev, struct ib_device_attr *props,
+                     struct ib_udata *uhw);
 
 int ehca_query_port(struct ib_device *ibdev, u8 port,
                    struct ib_port_attr *props);
index 764081d305b62e0a10378148ed428afb358d6490..78af73c62916d8ad875a01558187efb5e34eb61c 100644 (file)
@@ -1495,11 +1495,14 @@ bail:
        return 0;
 }
 
-static int ipath_query_device(struct ib_device *ibdev,
-                             struct ib_device_attr *props)
+static int ipath_query_device(struct ib_device *ibdev, struct ib_device_attr *props,
+                             struct ib_udata *uhw)
 {
        struct ipath_ibdev *dev = to_idev(ibdev);
 
+       if (uhw->inlen || uhw->outlen)
+               return -EINVAL;
+
        memset(props, 0, sizeof(*props));
 
        props->device_cap_flags = IB_DEVICE_BAD_PKEY_CNTR |
index af2071ed143711a2320a83b43be4eb99898c93b6..6cd8cd5bf1c5b92a67c2785455b866014a753bed 100644 (file)
@@ -132,7 +132,8 @@ static int num_ib_ports(struct mlx4_dev *dev)
 }
 
 static int mlx4_ib_query_device(struct ib_device *ibdev,
-                               struct ib_device_attr *props)
+                               struct ib_device_attr *props,
+                               struct ib_udata *uhw)
 {
        struct mlx4_ib_dev *dev = to_mdev(ibdev);
        struct ib_smp *in_mad  = NULL;
@@ -140,6 +141,9 @@ static int mlx4_ib_query_device(struct ib_device *ibdev,
        int err = -ENOMEM;
        int have_ib_ports;
 
+       if (uhw->inlen || uhw->outlen)
+               return -EINVAL;
+
        in_mad  = kzalloc(sizeof *in_mad, GFP_KERNEL);
        out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
        if (!in_mad || !out_mad)
index 06b023855a335154306d6c1a90ebfe51ca0d567a..5803859d3f7666c70a552765bca304c2256a6991 100644 (file)
@@ -63,7 +63,8 @@ static char mlx5_version[] =
        DRIVER_VERSION " (" DRIVER_RELDATE ")\n";
 
 static int mlx5_ib_query_device(struct ib_device *ibdev,
-                               struct ib_device_attr *props)
+                               struct ib_device_attr *props,
+                               struct ib_udata *uhw)
 {
        struct mlx5_ib_dev *dev = to_mdev(ibdev);
        struct ib_smp *in_mad  = NULL;
@@ -74,6 +75,9 @@ static int mlx5_ib_query_device(struct ib_device *ibdev,
        int max_sq_sg;
        u64 flags;
 
+       if (uhw->inlen || uhw->outlen)
+               return -EINVAL;
+
        gen = &dev->mdev->caps.gen;
        in_mad  = kzalloc(sizeof(*in_mad), GFP_KERNEL);
        out_mad = kmalloc(sizeof(*out_mad), GFP_KERNEL);
@@ -910,6 +914,7 @@ static int get_port_caps(struct mlx5_ib_dev *dev)
        struct mlx5_general_caps *gen;
        int err = -ENOMEM;
        int port;
+       struct ib_udata uhw = {.inlen = 0, .outlen = 0};
 
        gen = &dev->mdev->caps.gen;
        pprops = kmalloc(sizeof(*pprops), GFP_KERNEL);
@@ -920,7 +925,7 @@ static int get_port_caps(struct mlx5_ib_dev *dev)
        if (!dprops)
                goto out;
 
-       err = mlx5_ib_query_device(&dev->ib_dev, dprops);
+       err = mlx5_ib_query_device(&dev->ib_dev, dprops, &uhw);
        if (err) {
                mlx5_ib_warn(dev, "query_device failed %d\n", err);
                goto out;
index f1b04bd102d107181a8f5ad407b257a9ef6a8a44..d6d7c164cc2d2890786db74982f1a599a5094e5b 100644 (file)
@@ -57,14 +57,17 @@ static void init_query_mad(struct ib_smp *mad)
        mad->method        = IB_MGMT_METHOD_GET;
 }
 
-static int mthca_query_device(struct ib_device *ibdev,
-                             struct ib_device_attr *props)
+static int mthca_query_device(struct ib_device *ibdev, struct ib_device_attr *props,
+                             struct ib_udata *uhw)
 {
        struct ib_smp *in_mad  = NULL;
        struct ib_smp *out_mad = NULL;
        int err = -ENOMEM;
        struct mthca_dev *mdev = to_mdev(ibdev);
 
+       if (uhw->inlen || uhw->outlen)
+               return -EINVAL;
+
        in_mad  = kzalloc(sizeof *in_mad, GFP_KERNEL);
        out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
        if (!in_mad || !out_mad)
index a3d3d8172f9aef4ab286a2db0f7c8a1cf9e8f46c..c94390b57de1a937f521a33209659f5ac55eb4b7 100644 (file)
@@ -512,12 +512,16 @@ static void nes_free_fast_reg_page_list(struct ib_fast_reg_page_list *pifrpl)
 /**
  * nes_query_device
  */
-static int nes_query_device(struct ib_device *ibdev, struct ib_device_attr *props)
+static int nes_query_device(struct ib_device *ibdev, struct ib_device_attr *props,
+                           struct ib_udata *uhw)
 {
        struct nes_vnic *nesvnic = to_nesvnic(ibdev);
        struct nes_device *nesdev = nesvnic->nesdev;
        struct nes_ib_device *nesibdev = nesvnic->nesibdev;
 
+       if (uhw->inlen || uhw->outlen)
+               return -EINVAL;
+
        memset(props, 0, sizeof(*props));
        memcpy(&props->sys_image_guid, nesvnic->netdev->dev_addr, 6);
 
index 787058dc8d1818fbfb05cbfd52d3c6ca0bc4b6fb..aab120280907964dd1c26c51d5d116a9e503e616 100644 (file)
@@ -61,10 +61,14 @@ int ocrdma_query_gid(struct ib_device *ibdev, u8 port,
        return 0;
 }
 
-int ocrdma_query_device(struct ib_device *ibdev, struct ib_device_attr *attr)
+int ocrdma_query_device(struct ib_device *ibdev, struct ib_device_attr *attr,
+                       struct ib_udata *uhw)
 {
        struct ocrdma_dev *dev = get_ocrdma_dev(ibdev);
 
+       if (uhw->inlen || uhw->outlen)
+               return -EINVAL;
+
        memset(attr, 0, sizeof *attr);
        memcpy(&attr->fw_ver, &dev->attr.fw_ver[0],
               min(sizeof(dev->attr.fw_ver), sizeof(attr->fw_ver)));
index e853195e005bfa280d820c95d725e8f1dc14121c..b15c608efa7b03c72a2eb44e1f7b8af919db13b0 100644 (file)
@@ -36,7 +36,8 @@ int ocrdma_post_recv(struct ib_qp *, struct ib_recv_wr *,
 int ocrdma_poll_cq(struct ib_cq *, int num_entries, struct ib_wc *wc);
 int ocrdma_arm_cq(struct ib_cq *, enum ib_cq_notify_flags flags);
 
-int ocrdma_query_device(struct ib_device *, struct ib_device_attr *props);
+int ocrdma_query_device(struct ib_device *, struct ib_device_attr *props,
+                       struct ib_udata *uhw);
 int ocrdma_query_port(struct ib_device *, u8 port, struct ib_port_attr *props);
 int ocrdma_modify_port(struct ib_device *, u8 port, int mask,
                       struct ib_port_modify *props);
index dba1c92f1a544710cdc70d7f6dc331cee87a337a..e1dad4558ed13cbf206c7a8452a91ac2c70d5b77 100644 (file)
@@ -1550,12 +1550,14 @@ full:
        }
 }
 
-static int qib_query_device(struct ib_device *ibdev,
-                           struct ib_device_attr *props)
+static int qib_query_device(struct ib_device *ibdev, struct ib_device_attr *props,
+                           struct ib_udata *uhw)
 {
        struct qib_devdata *dd = dd_from_ibdev(ibdev);
        struct qib_ibdev *dev = to_idev(ibdev);
 
+       if (uhw->inlen || uhw->outlen)
+               return -EINVAL;
        memset(props, 0, sizeof(*props));
 
        props->device_cap_flags = IB_DEVICE_BAD_PKEY_CNTR |
index 2b3f7e3fe1aab658da2c092bae7d103e883586ab..7df43827cb29661a039d1794d24a20e6cbf1b094 100644 (file)
@@ -248,7 +248,8 @@ enum rdma_link_layer usnic_ib_port_link_layer(struct ib_device *device,
 }
 
 int usnic_ib_query_device(struct ib_device *ibdev,
-                               struct ib_device_attr *props)
+                         struct ib_device_attr *props,
+                         struct ib_udata *uhw)
 {
        struct usnic_ib_dev *us_ibdev = to_usdev(ibdev);
        union ib_gid gid;
@@ -257,6 +258,9 @@ int usnic_ib_query_device(struct ib_device *ibdev,
        int qp_per_vf;
 
        usnic_dbg("\n");
+       if (uhw->inlen || uhw->outlen)
+               return -EINVAL;
+
        mutex_lock(&us_ibdev->usdev_lock);
        us_ibdev->netdev->ethtool_ops->get_drvinfo(us_ibdev->netdev, &info);
        us_ibdev->netdev->ethtool_ops->get_settings(us_ibdev->netdev, &cmd);
index 2ab84270b83da6346c23b2e6e6d73f208539b7ca..0bd04efa16f33f514c30b3b5c32cf62f8488c271 100644 (file)
@@ -24,7 +24,8 @@
 enum rdma_link_layer usnic_ib_port_link_layer(struct ib_device *device,
                                                u8 port_num);
 int usnic_ib_query_device(struct ib_device *ibdev,
-                               struct ib_device_attr *props);
+                               struct ib_device_attr *props,
+                         struct ib_udata *uhw);
 int usnic_ib_query_port(struct ib_device *ibdev, u8 port,
                                struct ib_port_attr *props);
 enum rdma_protocol_type
index c0929245ddeedda3b395baa42420a1c6a524bce4..b02778812729e8a920aa0fb084241060f67944ad 100644 (file)
@@ -1561,7 +1561,8 @@ struct ib_device {
        int                        (*get_protocol_stats)(struct ib_device *device,
                                                         union rdma_protocol_stats *stats);
        int                        (*query_device)(struct ib_device *device,
-                                                  struct ib_device_attr *device_attr);
+                                                  struct ib_device_attr *device_attr,
+                                                  struct ib_udata *udata);
        int                        (*query_port)(struct ib_device *device,
                                                 u8 port_num,
                                                 struct ib_port_attr *port_attr);