Skip to content

Commit 5a77abf

Browse files
Eli Cohenrolandd
authored andcommitted
IB/core: Add support for extended query device caps
Add extensible query device capabilities verb to allow adding new features. ib_uverbs_ex_query_device is added and copy_query_dev_fields is used to copy capability fields to be used by both ib_uverbs_query_device and ib_uverbs_ex_query_device. Signed-off-by: Eli Cohen <[email protected]> Signed-off-by: Haggai Eran <[email protected]> Signed-off-by: Roland Dreier <[email protected]>
1 parent c1395a2 commit 5a77abf

File tree

5 files changed

+103
-44
lines changed

5 files changed

+103
-44
lines changed

drivers/infiniband/core/uverbs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,5 +258,6 @@ IB_UVERBS_DECLARE_CMD(close_xrcd);
258258

259259
IB_UVERBS_DECLARE_EX_CMD(create_flow);
260260
IB_UVERBS_DECLARE_EX_CMD(destroy_flow);
261+
IB_UVERBS_DECLARE_EX_CMD(query_device);
261262

262263
#endif /* UVERBS_H */

drivers/infiniband/core/uverbs_cmd.c

Lines changed: 83 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,52 @@ ssize_t ib_uverbs_get_context(struct ib_uverbs_file *file,
378378
return ret;
379379
}
380380

381+
static void copy_query_dev_fields(struct ib_uverbs_file *file,
382+
struct ib_uverbs_query_device_resp *resp,
383+
struct ib_device_attr *attr)
384+
{
385+
resp->fw_ver = attr->fw_ver;
386+
resp->node_guid = file->device->ib_dev->node_guid;
387+
resp->sys_image_guid = attr->sys_image_guid;
388+
resp->max_mr_size = attr->max_mr_size;
389+
resp->page_size_cap = attr->page_size_cap;
390+
resp->vendor_id = attr->vendor_id;
391+
resp->vendor_part_id = attr->vendor_part_id;
392+
resp->hw_ver = attr->hw_ver;
393+
resp->max_qp = attr->max_qp;
394+
resp->max_qp_wr = attr->max_qp_wr;
395+
resp->device_cap_flags = attr->device_cap_flags;
396+
resp->max_sge = attr->max_sge;
397+
resp->max_sge_rd = attr->max_sge_rd;
398+
resp->max_cq = attr->max_cq;
399+
resp->max_cqe = attr->max_cqe;
400+
resp->max_mr = attr->max_mr;
401+
resp->max_pd = attr->max_pd;
402+
resp->max_qp_rd_atom = attr->max_qp_rd_atom;
403+
resp->max_ee_rd_atom = attr->max_ee_rd_atom;
404+
resp->max_res_rd_atom = attr->max_res_rd_atom;
405+
resp->max_qp_init_rd_atom = attr->max_qp_init_rd_atom;
406+
resp->max_ee_init_rd_atom = attr->max_ee_init_rd_atom;
407+
resp->atomic_cap = attr->atomic_cap;
408+
resp->max_ee = attr->max_ee;
409+
resp->max_rdd = attr->max_rdd;
410+
resp->max_mw = attr->max_mw;
411+
resp->max_raw_ipv6_qp = attr->max_raw_ipv6_qp;
412+
resp->max_raw_ethy_qp = attr->max_raw_ethy_qp;
413+
resp->max_mcast_grp = attr->max_mcast_grp;
414+
resp->max_mcast_qp_attach = attr->max_mcast_qp_attach;
415+
resp->max_total_mcast_qp_attach = attr->max_total_mcast_qp_attach;
416+
resp->max_ah = attr->max_ah;
417+
resp->max_fmr = attr->max_fmr;
418+
resp->max_map_per_fmr = attr->max_map_per_fmr;
419+
resp->max_srq = attr->max_srq;
420+
resp->max_srq_wr = attr->max_srq_wr;
421+
resp->max_srq_sge = attr->max_srq_sge;
422+
resp->max_pkeys = attr->max_pkeys;
423+
resp->local_ca_ack_delay = attr->local_ca_ack_delay;
424+
resp->phys_port_cnt = file->device->ib_dev->phys_port_cnt;
425+
}
426+
381427
ssize_t ib_uverbs_query_device(struct ib_uverbs_file *file,
382428
const char __user *buf,
383429
int in_len, int out_len)
@@ -398,47 +444,7 @@ ssize_t ib_uverbs_query_device(struct ib_uverbs_file *file,
398444
return ret;
399445

400446
memset(&resp, 0, sizeof resp);
401-
402-
resp.fw_ver = attr.fw_ver;
403-
resp.node_guid = file->device->ib_dev->node_guid;
404-
resp.sys_image_guid = attr.sys_image_guid;
405-
resp.max_mr_size = attr.max_mr_size;
406-
resp.page_size_cap = attr.page_size_cap;
407-
resp.vendor_id = attr.vendor_id;
408-
resp.vendor_part_id = attr.vendor_part_id;
409-
resp.hw_ver = attr.hw_ver;
410-
resp.max_qp = attr.max_qp;
411-
resp.max_qp_wr = attr.max_qp_wr;
412-
resp.device_cap_flags = attr.device_cap_flags;
413-
resp.max_sge = attr.max_sge;
414-
resp.max_sge_rd = attr.max_sge_rd;
415-
resp.max_cq = attr.max_cq;
416-
resp.max_cqe = attr.max_cqe;
417-
resp.max_mr = attr.max_mr;
418-
resp.max_pd = attr.max_pd;
419-
resp.max_qp_rd_atom = attr.max_qp_rd_atom;
420-
resp.max_ee_rd_atom = attr.max_ee_rd_atom;
421-
resp.max_res_rd_atom = attr.max_res_rd_atom;
422-
resp.max_qp_init_rd_atom = attr.max_qp_init_rd_atom;
423-
resp.max_ee_init_rd_atom = attr.max_ee_init_rd_atom;
424-
resp.atomic_cap = attr.atomic_cap;
425-
resp.max_ee = attr.max_ee;
426-
resp.max_rdd = attr.max_rdd;
427-
resp.max_mw = attr.max_mw;
428-
resp.max_raw_ipv6_qp = attr.max_raw_ipv6_qp;
429-
resp.max_raw_ethy_qp = attr.max_raw_ethy_qp;
430-
resp.max_mcast_grp = attr.max_mcast_grp;
431-
resp.max_mcast_qp_attach = attr.max_mcast_qp_attach;
432-
resp.max_total_mcast_qp_attach = attr.max_total_mcast_qp_attach;
433-
resp.max_ah = attr.max_ah;
434-
resp.max_fmr = attr.max_fmr;
435-
resp.max_map_per_fmr = attr.max_map_per_fmr;
436-
resp.max_srq = attr.max_srq;
437-
resp.max_srq_wr = attr.max_srq_wr;
438-
resp.max_srq_sge = attr.max_srq_sge;
439-
resp.max_pkeys = attr.max_pkeys;
440-
resp.local_ca_ack_delay = attr.local_ca_ack_delay;
441-
resp.phys_port_cnt = file->device->ib_dev->phys_port_cnt;
447+
copy_query_dev_fields(file, &resp, &attr);
442448

443449
if (copy_to_user((void __user *) (unsigned long) cmd.response,
444450
&resp, sizeof resp))
@@ -3253,3 +3259,39 @@ ssize_t ib_uverbs_destroy_srq(struct ib_uverbs_file *file,
32533259

32543260
return ret ? ret : in_len;
32553261
}
3262+
3263+
int ib_uverbs_ex_query_device(struct ib_uverbs_file *file,
3264+
struct ib_udata *ucore,
3265+
struct ib_udata *uhw)
3266+
{
3267+
struct ib_uverbs_ex_query_device_resp resp;
3268+
struct ib_uverbs_ex_query_device cmd;
3269+
struct ib_device_attr attr;
3270+
struct ib_device *device;
3271+
int err;
3272+
3273+
device = file->device->ib_dev;
3274+
if (ucore->inlen < sizeof(cmd))
3275+
return -EINVAL;
3276+
3277+
err = ib_copy_from_udata(&cmd, ucore, sizeof(cmd));
3278+
if (err)
3279+
return err;
3280+
3281+
if (cmd.reserved)
3282+
return -EINVAL;
3283+
3284+
err = device->query_device(device, &attr);
3285+
if (err)
3286+
return err;
3287+
3288+
memset(&resp, 0, sizeof(resp));
3289+
copy_query_dev_fields(file, &resp.base, &attr);
3290+
resp.comp_mask = 0;
3291+
3292+
err = ib_copy_to_udata(ucore, &resp, sizeof(resp));
3293+
if (err)
3294+
return err;
3295+
3296+
return 0;
3297+
}

drivers/infiniband/core/uverbs_main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ static int (*uverbs_ex_cmd_table[])(struct ib_uverbs_file *file,
122122
struct ib_udata *ucore,
123123
struct ib_udata *uhw) = {
124124
[IB_USER_VERBS_EX_CMD_CREATE_FLOW] = ib_uverbs_ex_create_flow,
125-
[IB_USER_VERBS_EX_CMD_DESTROY_FLOW] = ib_uverbs_ex_destroy_flow
125+
[IB_USER_VERBS_EX_CMD_DESTROY_FLOW] = ib_uverbs_ex_destroy_flow,
126+
[IB_USER_VERBS_EX_CMD_QUERY_DEVICE] = ib_uverbs_ex_query_device
126127
};
127128

128129
static void ib_uverbs_add_one(struct ib_device *device);

include/rdma/ib_verbs.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1662,7 +1662,10 @@ static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t
16621662

16631663
static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
16641664
{
1665-
return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
1665+
size_t copy_sz;
1666+
1667+
copy_sz = min_t(size_t, len, udata->outlen);
1668+
return copy_to_user(udata->outbuf, src, copy_sz) ? -EFAULT : 0;
16661669
}
16671670

16681671
/**

include/uapi/rdma/ib_user_verbs.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ enum {
9090
};
9191

9292
enum {
93+
IB_USER_VERBS_EX_CMD_QUERY_DEVICE = IB_USER_VERBS_CMD_QUERY_DEVICE,
9394
IB_USER_VERBS_EX_CMD_CREATE_FLOW = IB_USER_VERBS_CMD_THRESHOLD,
94-
IB_USER_VERBS_EX_CMD_DESTROY_FLOW
95+
IB_USER_VERBS_EX_CMD_DESTROY_FLOW,
9596
};
9697

9798
/*
@@ -201,6 +202,17 @@ struct ib_uverbs_query_device_resp {
201202
__u8 reserved[4];
202203
};
203204

205+
struct ib_uverbs_ex_query_device {
206+
__u32 comp_mask;
207+
__u32 reserved;
208+
};
209+
210+
struct ib_uverbs_ex_query_device_resp {
211+
struct ib_uverbs_query_device_resp base;
212+
__u32 comp_mask;
213+
__u32 reserved;
214+
};
215+
204216
struct ib_uverbs_query_port {
205217
__u64 response;
206218
__u8 port_num;

0 commit comments

Comments
 (0)