Skip to content

Commit

Permalink
verbs: Add new create_cq command that supports driver attribute over …
Browse files Browse the repository at this point in the history
…ioctl

Adds ibv_cmd_create_cq_ex2. The new command includes a uverbs attr
bundle as a parameter so drivers can send driver-specific attrs to
kernel using ioctl. Additionally, it contains a new macro which
incorporates a pre-existing uverbs attr bundle from the caller into the
final buffer and sets up the fallback flow in case the ioctl flow is not
supported.

Signed-off-by: Akiva Goldberger <agoldberger@nvidia.com>
Reviewed-by: Patrisious Haddad <phaddad@nvidia.com>
Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
  • Loading branch information
Akiva Goldberger authored and Yishai Hadas committed Jun 30, 2024
1 parent ca6211a commit c5cded7
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 15 deletions.
57 changes: 42 additions & 15 deletions libibverbs/cmd_cq.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,32 @@ static int ibv_icmd_create_cq(struct ibv_context *context, int cqe,
return 0;
}

static int ibv_icmd_create_cq_ex(struct ibv_context *context,
const struct ibv_cq_init_attr_ex *cq_attr,
struct verbs_cq *cq,
struct ibv_command_buffer *cmdb,
uint32_t cmd_flags)
{
uint32_t flags = 0;

if (!check_comp_mask(cq_attr->comp_mask,
IBV_CQ_INIT_ATTR_MASK_FLAGS |
IBV_CQ_INIT_ATTR_MASK_PD))
return EOPNOTSUPP;

if (cq_attr->wc_flags & IBV_WC_EX_WITH_COMPLETION_TIMESTAMP ||
cq_attr->wc_flags & IBV_WC_EX_WITH_COMPLETION_TIMESTAMP_WALLCLOCK)
flags |= IB_UVERBS_CQ_FLAGS_TIMESTAMP_COMPLETION;

if ((cq_attr->comp_mask & IBV_CQ_INIT_ATTR_MASK_FLAGS) &&
cq_attr->flags & IBV_CREATE_CQ_ATTR_IGNORE_OVERRUN)
flags |= IB_UVERBS_CQ_FLAGS_IGNORE_OVERRUN;

return ibv_icmd_create_cq(context, cq_attr->cqe, cq_attr->channel,
cq_attr->comp_vector, flags,
&cq->cq, cmdb, cmd_flags);
}

int ibv_cmd_create_cq(struct ibv_context *context, int cqe,
struct ibv_comp_channel *channel, int comp_vector,
struct ibv_cq *cq, struct ibv_create_cq *cmd,
Expand All @@ -153,24 +179,25 @@ int ibv_cmd_create_cq_ex(struct ibv_context *context,
DECLARE_CMD_BUFFER_COMPAT(cmdb, UVERBS_OBJECT_CQ,
UVERBS_METHOD_CQ_CREATE, cmd, cmd_size, resp,
resp_size);
uint32_t flags = 0;

if (!check_comp_mask(cq_attr->comp_mask,
IBV_CQ_INIT_ATTR_MASK_FLAGS |
IBV_CQ_INIT_ATTR_MASK_PD))
return EOPNOTSUPP;

if (cq_attr->wc_flags & IBV_WC_EX_WITH_COMPLETION_TIMESTAMP ||
cq_attr->wc_flags & IBV_WC_EX_WITH_COMPLETION_TIMESTAMP_WALLCLOCK)
flags |= IB_UVERBS_CQ_FLAGS_TIMESTAMP_COMPLETION;
return ibv_icmd_create_cq_ex(context, cq_attr, cq, cmdb, cmd_flags);
}

if ((cq_attr->comp_mask & IBV_CQ_INIT_ATTR_MASK_FLAGS) &&
cq_attr->flags & IBV_CREATE_CQ_ATTR_IGNORE_OVERRUN)
flags |= IB_UVERBS_CQ_FLAGS_IGNORE_OVERRUN;
int ibv_cmd_create_cq_ex2(struct ibv_context *context,
const struct ibv_cq_init_attr_ex *cq_attr,
struct verbs_cq *cq,
struct ibv_create_cq_ex *cmd,
size_t cmd_size,
struct ib_uverbs_ex_create_cq_resp *resp,
size_t resp_size,
uint32_t cmd_flags,
struct ibv_command_buffer *driver)
{
DECLARE_CMD_BUFFER_LINK_COMPAT(cmdb, UVERBS_OBJECT_CQ,
UVERBS_METHOD_CQ_CREATE,
driver, cmd, cmd_size, resp, resp_size);

return ibv_icmd_create_cq(context, cq_attr->cqe, cq_attr->channel,
cq_attr->comp_vector, flags,
&cq->cq, cmdb, cmd_flags);
return ibv_icmd_create_cq_ex(context, cq_attr, cq, cmdb, cmd_flags);
}

int ibv_cmd_destroy_cq(struct ibv_cq *cq)
Expand Down
7 changes: 7 additions & 0 deletions libibverbs/cmd_write.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ void _write_set_uhw(struct ibv_command_buffer *cmdb, const void *req,
_write_set_uhw(_name, cmd, sizeof(*cmd), cmd_size, resp, \
sizeof(*resp), resp_size)

#define DECLARE_CMD_BUFFER_LINK_COMPAT(_name, _object_id, _method_id, \
_link, cmd, cmd_size, \
resp, resp_size) \
DECLARE_COMMAND_BUFFER_LINK(_name, _object_id, _method_id, 2, _link); \
_write_set_uhw(_name, cmd, sizeof(*cmd), cmd_size, resp, \
sizeof(*resp), resp_size)

/*
* The fallback scheme keeps track of which ioctls succeed in a per-context
* bitmap. If ENOTTY or EPROTONOSUPPORT is seen then the ioctl is never
Expand Down
9 changes: 9 additions & 0 deletions libibverbs/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,15 @@ int ibv_cmd_create_cq_ex(struct ibv_context *context,
struct ib_uverbs_ex_create_cq_resp *resp,
size_t resp_size,
uint32_t cmd_flags);
int ibv_cmd_create_cq_ex2(struct ibv_context *context,
const struct ibv_cq_init_attr_ex *cq_attr,
struct verbs_cq *cq,
struct ibv_create_cq_ex *cmd,
size_t cmd_size,
struct ib_uverbs_ex_create_cq_resp *resp,
size_t resp_size,
uint32_t cmd_flags,
struct ibv_command_buffer *driver);
int ibv_cmd_poll_cq(struct ibv_cq *cq, int ne, struct ibv_wc *wc);
int ibv_cmd_req_notify_cq(struct ibv_cq *cq, int solicited_only);
int ibv_cmd_resize_cq(struct ibv_cq *cq, int cqe,
Expand Down
1 change: 1 addition & 0 deletions libibverbs/libibverbs.map.in
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ IBVERBS_PRIVATE_@IBVERBS_PABI_VERSION@ {
ibv_cmd_create_counters;
ibv_cmd_create_cq;
ibv_cmd_create_cq_ex;
ibv_cmd_create_cq_ex2;
ibv_cmd_create_flow;
ibv_cmd_create_flow_action_esp;
ibv_cmd_create_qp;
Expand Down

0 comments on commit c5cded7

Please sign in to comment.