Skip to content

Commit

Permalink
IB/core: Pass hardware specific data in query_device
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Matan Barak authored and Doug Ledford committed Jun 12, 2015
1 parent 24306dc commit 2528e33
Show file tree
Hide file tree
Showing 18 changed files with 75 additions and 25 deletions.
4 changes: 3 additions & 1 deletion drivers/infiniband/core/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion drivers/infiniband/core/uverbs_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 5 additions & 2 deletions drivers/infiniband/hw/amso1100/c2_provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,16 @@
#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;
}
Expand Down
8 changes: 6 additions & 2 deletions drivers/infiniband/hw/cxgb3/iwch_provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions drivers/infiniband/hw/cxgb4/provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion drivers/infiniband/hw/ehca/ehca_hca.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.");
Expand Down
3 changes: 2 additions & 1 deletion drivers/infiniband/hw/ehca/ehca_iverbs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions drivers/infiniband/hw/ipath/ipath_verbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1495,11 +1495,14 @@ int ipath_ib_piobufavail(struct ipath_ibdev *dev)
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 |
Expand Down
6 changes: 5 additions & 1 deletion drivers/infiniband/hw/mlx4/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,18 @@ 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;
struct ib_smp *out_mad = NULL;
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)
Expand Down
9 changes: 7 additions & 2 deletions drivers/infiniband/hw/mlx5/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions drivers/infiniband/hw/mthca/mthca_provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion drivers/infiniband/hw/nes/nes_verbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 5 additions & 1 deletion drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
3 changes: 2 additions & 1 deletion drivers/infiniband/hw/ocrdma/ocrdma_verbs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions drivers/infiniband/hw/qib/qib_verbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1550,12 +1550,14 @@ void qib_ib_piobufavail(struct qib_devdata *dd)
}
}

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 |
Expand Down
6 changes: 5 additions & 1 deletion drivers/infiniband/hw/usnic/usnic_ib_verbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion drivers/infiniband/hw/usnic/usnic_ib_verbs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion include/rdma/ib_verbs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2528e33

Please sign in to comment.