|
61 | 61 |
|
62 | 62 | #include "bnxt_re.h" |
63 | 63 | #include "ib_verbs.h" |
| 64 | + |
| 65 | +#include <rdma/uverbs_types.h> |
| 66 | +#include <rdma/uverbs_std_types.h> |
| 67 | + |
| 68 | +#include <rdma/ib_user_ioctl_cmds.h> |
| 69 | + |
| 70 | +#define UVERBS_MODULE_NAME bnxt_re |
| 71 | +#include <rdma/uverbs_named_ioctl.h> |
| 72 | + |
64 | 73 | #include <rdma/bnxt_re-abi.h> |
65 | 74 |
|
66 | 75 | static int __from_ib_access_flags(int iflags) |
@@ -546,13 +555,15 @@ bnxt_re_mmap_entry_insert(struct bnxt_re_ucontext *uctx, u64 mem_offset, |
546 | 555 |
|
547 | 556 | entry->mem_offset = mem_offset; |
548 | 557 | entry->mmap_flag = mmap_flag; |
| 558 | + entry->uctx = uctx; |
549 | 559 |
|
550 | 560 | switch (mmap_flag) { |
551 | 561 | case BNXT_RE_MMAP_SH_PAGE: |
552 | 562 | ret = rdma_user_mmap_entry_insert_exact(&uctx->ib_uctx, |
553 | 563 | &entry->rdma_entry, PAGE_SIZE, 0); |
554 | 564 | break; |
555 | 565 | case BNXT_RE_MMAP_UC_DB: |
| 566 | + case BNXT_RE_MMAP_WC_DB: |
556 | 567 | ret = rdma_user_mmap_entry_insert(&uctx->ib_uctx, |
557 | 568 | &entry->rdma_entry, PAGE_SIZE); |
558 | 569 | break; |
@@ -4056,6 +4067,9 @@ int bnxt_re_alloc_ucontext(struct ib_ucontext *ctx, struct ib_udata *udata) |
4056 | 4067 | resp.comp_mask |= BNXT_RE_UCNTX_CMASK_HAVE_MODE; |
4057 | 4068 | resp.mode = rdev->chip_ctx->modes.wqe_mode; |
4058 | 4069 |
|
| 4070 | + if (rdev->chip_ctx->modes.db_push) |
| 4071 | + resp.comp_mask |= BNXT_RE_UCNTX_CMASK_WC_DPI_ENABLED; |
| 4072 | + |
4059 | 4073 | entry = bnxt_re_mmap_entry_insert(uctx, 0, BNXT_RE_MMAP_SH_PAGE, NULL); |
4060 | 4074 | if (!entry) { |
4061 | 4075 | rc = -ENOMEM; |
@@ -4119,6 +4133,12 @@ int bnxt_re_mmap(struct ib_ucontext *ib_uctx, struct vm_area_struct *vma) |
4119 | 4133 | rdma_entry); |
4120 | 4134 |
|
4121 | 4135 | switch (bnxt_entry->mmap_flag) { |
| 4136 | + case BNXT_RE_MMAP_WC_DB: |
| 4137 | + pfn = bnxt_entry->mem_offset >> PAGE_SHIFT; |
| 4138 | + ret = rdma_user_mmap_io(ib_uctx, vma, pfn, PAGE_SIZE, |
| 4139 | + pgprot_writecombine(vma->vm_page_prot), |
| 4140 | + rdma_entry); |
| 4141 | + break; |
4122 | 4142 | case BNXT_RE_MMAP_UC_DB: |
4123 | 4143 | pfn = bnxt_entry->mem_offset >> PAGE_SHIFT; |
4124 | 4144 | ret = rdma_user_mmap_io(ib_uctx, vma, pfn, PAGE_SIZE, |
@@ -4146,3 +4166,131 @@ void bnxt_re_mmap_free(struct rdma_user_mmap_entry *rdma_entry) |
4146 | 4166 |
|
4147 | 4167 | kfree(bnxt_entry); |
4148 | 4168 | } |
| 4169 | + |
| 4170 | +static int UVERBS_HANDLER(BNXT_RE_METHOD_ALLOC_PAGE)(struct uverbs_attr_bundle *attrs) |
| 4171 | +{ |
| 4172 | + struct ib_uobject *uobj = uverbs_attr_get_uobject(attrs, BNXT_RE_ALLOC_PAGE_HANDLE); |
| 4173 | + enum bnxt_re_alloc_page_type alloc_type; |
| 4174 | + struct bnxt_re_user_mmap_entry *entry; |
| 4175 | + enum bnxt_re_mmap_flag mmap_flag; |
| 4176 | + struct bnxt_qplib_chip_ctx *cctx; |
| 4177 | + struct bnxt_re_ucontext *uctx; |
| 4178 | + struct bnxt_re_dev *rdev; |
| 4179 | + u64 mmap_offset; |
| 4180 | + u32 length; |
| 4181 | + u32 dpi; |
| 4182 | + u64 dbr; |
| 4183 | + int err; |
| 4184 | + |
| 4185 | + uctx = container_of(ib_uverbs_get_ucontext(attrs), struct bnxt_re_ucontext, ib_uctx); |
| 4186 | + if (IS_ERR(uctx)) |
| 4187 | + return PTR_ERR(uctx); |
| 4188 | + |
| 4189 | + err = uverbs_get_const(&alloc_type, attrs, BNXT_RE_ALLOC_PAGE_TYPE); |
| 4190 | + if (err) |
| 4191 | + return err; |
| 4192 | + |
| 4193 | + rdev = uctx->rdev; |
| 4194 | + cctx = rdev->chip_ctx; |
| 4195 | + |
| 4196 | + switch (alloc_type) { |
| 4197 | + case BNXT_RE_ALLOC_WC_PAGE: |
| 4198 | + if (cctx->modes.db_push) { |
| 4199 | + if (bnxt_qplib_alloc_dpi(&rdev->qplib_res, &uctx->wcdpi, |
| 4200 | + uctx, BNXT_QPLIB_DPI_TYPE_WC)) |
| 4201 | + return -ENOMEM; |
| 4202 | + length = PAGE_SIZE; |
| 4203 | + dpi = uctx->wcdpi.dpi; |
| 4204 | + dbr = (u64)uctx->wcdpi.umdbr; |
| 4205 | + mmap_flag = BNXT_RE_MMAP_WC_DB; |
| 4206 | + } else { |
| 4207 | + return -EINVAL; |
| 4208 | + } |
| 4209 | + |
| 4210 | + break; |
| 4211 | + |
| 4212 | + default: |
| 4213 | + return -EOPNOTSUPP; |
| 4214 | + } |
| 4215 | + |
| 4216 | + entry = bnxt_re_mmap_entry_insert(uctx, dbr, mmap_flag, &mmap_offset); |
| 4217 | + if (IS_ERR(entry)) |
| 4218 | + return PTR_ERR(entry); |
| 4219 | + |
| 4220 | + uobj->object = entry; |
| 4221 | + uverbs_finalize_uobj_create(attrs, BNXT_RE_ALLOC_PAGE_HANDLE); |
| 4222 | + err = uverbs_copy_to(attrs, BNXT_RE_ALLOC_PAGE_MMAP_OFFSET, |
| 4223 | + &mmap_offset, sizeof(mmap_offset)); |
| 4224 | + if (err) |
| 4225 | + return err; |
| 4226 | + |
| 4227 | + err = uverbs_copy_to(attrs, BNXT_RE_ALLOC_PAGE_MMAP_LENGTH, |
| 4228 | + &length, sizeof(length)); |
| 4229 | + if (err) |
| 4230 | + return err; |
| 4231 | + |
| 4232 | + err = uverbs_copy_to(attrs, BNXT_RE_ALLOC_PAGE_DPI, |
| 4233 | + &dpi, sizeof(length)); |
| 4234 | + if (err) |
| 4235 | + return err; |
| 4236 | + |
| 4237 | + return 0; |
| 4238 | +} |
| 4239 | + |
| 4240 | +static int alloc_page_obj_cleanup(struct ib_uobject *uobject, |
| 4241 | + enum rdma_remove_reason why, |
| 4242 | + struct uverbs_attr_bundle *attrs) |
| 4243 | +{ |
| 4244 | + struct bnxt_re_user_mmap_entry *entry = uobject->object; |
| 4245 | + struct bnxt_re_ucontext *uctx = entry->uctx; |
| 4246 | + |
| 4247 | + switch (entry->mmap_flag) { |
| 4248 | + case BNXT_RE_MMAP_WC_DB: |
| 4249 | + if (uctx && uctx->wcdpi.dbr) { |
| 4250 | + struct bnxt_re_dev *rdev = uctx->rdev; |
| 4251 | + |
| 4252 | + bnxt_qplib_dealloc_dpi(&rdev->qplib_res, &uctx->wcdpi); |
| 4253 | + uctx->wcdpi.dbr = NULL; |
| 4254 | + } |
| 4255 | + break; |
| 4256 | + default: |
| 4257 | + goto exit; |
| 4258 | + } |
| 4259 | + rdma_user_mmap_entry_remove(&entry->rdma_entry); |
| 4260 | +exit: |
| 4261 | + return 0; |
| 4262 | +} |
| 4263 | + |
| 4264 | +DECLARE_UVERBS_NAMED_METHOD(BNXT_RE_METHOD_ALLOC_PAGE, |
| 4265 | + UVERBS_ATTR_IDR(BNXT_RE_ALLOC_PAGE_HANDLE, |
| 4266 | + BNXT_RE_OBJECT_ALLOC_PAGE, |
| 4267 | + UVERBS_ACCESS_NEW, |
| 4268 | + UA_MANDATORY), |
| 4269 | + UVERBS_ATTR_CONST_IN(BNXT_RE_ALLOC_PAGE_TYPE, |
| 4270 | + enum bnxt_re_alloc_page_type, |
| 4271 | + UA_MANDATORY), |
| 4272 | + UVERBS_ATTR_PTR_OUT(BNXT_RE_ALLOC_PAGE_MMAP_OFFSET, |
| 4273 | + UVERBS_ATTR_TYPE(u64), |
| 4274 | + UA_MANDATORY), |
| 4275 | + UVERBS_ATTR_PTR_OUT(BNXT_RE_ALLOC_PAGE_MMAP_LENGTH, |
| 4276 | + UVERBS_ATTR_TYPE(u32), |
| 4277 | + UA_MANDATORY), |
| 4278 | + UVERBS_ATTR_PTR_OUT(BNXT_RE_ALLOC_PAGE_DPI, |
| 4279 | + UVERBS_ATTR_TYPE(u32), |
| 4280 | + UA_MANDATORY)); |
| 4281 | + |
| 4282 | +DECLARE_UVERBS_NAMED_METHOD_DESTROY(BNXT_RE_METHOD_DESTROY_PAGE, |
| 4283 | + UVERBS_ATTR_IDR(BNXT_RE_DESTROY_PAGE_HANDLE, |
| 4284 | + BNXT_RE_OBJECT_ALLOC_PAGE, |
| 4285 | + UVERBS_ACCESS_DESTROY, |
| 4286 | + UA_MANDATORY)); |
| 4287 | + |
| 4288 | +DECLARE_UVERBS_NAMED_OBJECT(BNXT_RE_OBJECT_ALLOC_PAGE, |
| 4289 | + UVERBS_TYPE_ALLOC_IDR(alloc_page_obj_cleanup), |
| 4290 | + &UVERBS_METHOD(BNXT_RE_METHOD_ALLOC_PAGE), |
| 4291 | + &UVERBS_METHOD(BNXT_RE_METHOD_DESTROY_PAGE)); |
| 4292 | + |
| 4293 | +const struct uapi_definition bnxt_re_uapi_defs[] = { |
| 4294 | + UAPI_DEF_CHAIN_OBJ_TREE_NAMED(BNXT_RE_OBJECT_ALLOC_PAGE), |
| 4295 | + {} |
| 4296 | +}; |
0 commit comments