Skip to content

Commit 360da60

Browse files
selvintxavierjgunthorpe
authored andcommitted
RDMA/bnxt_re: Enable low latency push
Introduce driver specific uapi functionalites. Added a alloc_page functionality for user library to allocate specific pages. Currently added support for allocating write combine pages for push functinality. This interface shall be extended for other page allocations. Allocate a WC page using the uapi hook for enabling the low latency push in Gen P5 adapters for small packets. This is supported only for the user space QPs. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Selvin Xavier <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 0ac20fa commit 360da60

File tree

7 files changed

+204
-4
lines changed

7 files changed

+204
-4
lines changed

drivers/infiniband/hw/bnxt_re/bnxt_re.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
#ifndef __BNXT_RE_H__
4141
#define __BNXT_RE_H__
42+
#include <rdma/uverbs_ioctl.h>
4243
#include "hw_counters.h"
4344
#define ROCE_DRV_MODULE_NAME "bnxt_re"
4445

@@ -189,4 +190,6 @@ static inline struct device *rdev_to_dev(struct bnxt_re_dev *rdev)
189190
return &rdev->ibdev.dev;
190191
return NULL;
191192
}
193+
194+
extern const struct uapi_definition bnxt_re_uapi_defs[];
192195
#endif

drivers/infiniband/hw/bnxt_re/ib_verbs.c

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@
6161

6262
#include "bnxt_re.h"
6363
#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+
6473
#include <rdma/bnxt_re-abi.h>
6574

6675
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,
546555

547556
entry->mem_offset = mem_offset;
548557
entry->mmap_flag = mmap_flag;
558+
entry->uctx = uctx;
549559

550560
switch (mmap_flag) {
551561
case BNXT_RE_MMAP_SH_PAGE:
552562
ret = rdma_user_mmap_entry_insert_exact(&uctx->ib_uctx,
553563
&entry->rdma_entry, PAGE_SIZE, 0);
554564
break;
555565
case BNXT_RE_MMAP_UC_DB:
566+
case BNXT_RE_MMAP_WC_DB:
556567
ret = rdma_user_mmap_entry_insert(&uctx->ib_uctx,
557568
&entry->rdma_entry, PAGE_SIZE);
558569
break;
@@ -4056,6 +4067,9 @@ int bnxt_re_alloc_ucontext(struct ib_ucontext *ctx, struct ib_udata *udata)
40564067
resp.comp_mask |= BNXT_RE_UCNTX_CMASK_HAVE_MODE;
40574068
resp.mode = rdev->chip_ctx->modes.wqe_mode;
40584069

4070+
if (rdev->chip_ctx->modes.db_push)
4071+
resp.comp_mask |= BNXT_RE_UCNTX_CMASK_WC_DPI_ENABLED;
4072+
40594073
entry = bnxt_re_mmap_entry_insert(uctx, 0, BNXT_RE_MMAP_SH_PAGE, NULL);
40604074
if (!entry) {
40614075
rc = -ENOMEM;
@@ -4119,6 +4133,12 @@ int bnxt_re_mmap(struct ib_ucontext *ib_uctx, struct vm_area_struct *vma)
41194133
rdma_entry);
41204134

41214135
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;
41224142
case BNXT_RE_MMAP_UC_DB:
41234143
pfn = bnxt_entry->mem_offset >> PAGE_SHIFT;
41244144
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)
41464166

41474167
kfree(bnxt_entry);
41484168
}
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+
};

drivers/infiniband/hw/bnxt_re/ib_verbs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct bnxt_re_pd {
6161
struct bnxt_qplib_pd qplib_pd;
6262
struct bnxt_re_fence_data fence;
6363
struct rdma_user_mmap_entry *pd_db_mmap;
64+
struct rdma_user_mmap_entry *pd_wcdb_mmap;
6465
};
6566

6667
struct bnxt_re_ah {
@@ -135,6 +136,7 @@ struct bnxt_re_ucontext {
135136
struct ib_ucontext ib_uctx;
136137
struct bnxt_re_dev *rdev;
137138
struct bnxt_qplib_dpi dpi;
139+
struct bnxt_qplib_dpi wcdpi;
138140
void *shpg;
139141
spinlock_t sh_lock; /* protect shpg */
140142
struct rdma_user_mmap_entry *shpage_mmap;
@@ -143,10 +145,12 @@ struct bnxt_re_ucontext {
143145
enum bnxt_re_mmap_flag {
144146
BNXT_RE_MMAP_SH_PAGE,
145147
BNXT_RE_MMAP_UC_DB,
148+
BNXT_RE_MMAP_WC_DB,
146149
};
147150

148151
struct bnxt_re_user_mmap_entry {
149152
struct rdma_user_mmap_entry rdma_entry;
153+
struct bnxt_re_ucontext *uctx;
150154
u64 mem_offset;
151155
u8 mmap_flag;
152156
};

drivers/infiniband/hw/bnxt_re/main.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
#include <rdma/bnxt_re-abi.h>
6767
#include "bnxt.h"
6868
#include "hw_counters.h"
69+
#include "ib_verbs.h"
6970

7071
static char version[] =
7172
BNXT_RE_DESC "\n";
@@ -117,6 +118,10 @@ static void bnxt_re_set_db_offset(struct bnxt_re_dev *rdev)
117118
* in such cases and DB-push will be disabled.
118119
*/
119120
barlen = pci_resource_len(res->pdev, RCFW_DBR_PCI_BAR_REGION);
121+
if (cctx->modes.db_push && l2db_len && en_dev->l2_db_size != barlen) {
122+
res->dpi_tbl.wcreg.offset = en_dev->l2_db_size;
123+
dev_info(rdev_to_dev(rdev), "Low latency framework is enabled\n");
124+
}
120125
}
121126

122127
static void bnxt_re_set_drv_mode(struct bnxt_re_dev *rdev, u8 mode)
@@ -395,8 +400,7 @@ static int bnxt_re_hwrm_qcfg(struct bnxt_re_dev *rdev, u32 *db_len,
395400
int rc;
396401

397402
memset(&fw_msg, 0, sizeof(fw_msg));
398-
bnxt_re_init_hwrm_hdr(rdev, (void *)&req,
399-
HWRM_FUNC_QCFG, -1, -1);
403+
bnxt_re_init_hwrm_hdr((void *)&req, HWRM_FUNC_QCFG);
400404
req.fid = cpu_to_le16(0xffff);
401405
bnxt_re_fill_fw_msg(&fw_msg, (void *)&req, sizeof(req), (void *)&resp,
402406
sizeof(resp), DFLT_HWRM_CMD_TIMEOUT);
@@ -416,13 +420,20 @@ int bnxt_re_hwrm_qcaps(struct bnxt_re_dev *rdev)
416420
struct hwrm_func_qcaps_input req = {};
417421
struct bnxt_qplib_chip_ctx *cctx;
418422
struct bnxt_fw_msg fw_msg = {};
423+
int rc;
419424

420425
cctx = rdev->chip_ctx;
421426
bnxt_re_init_hwrm_hdr((void *)&req, HWRM_FUNC_QCAPS);
422427
req.fid = cpu_to_le16(0xffff);
423428
bnxt_re_fill_fw_msg(&fw_msg, (void *)&req, sizeof(req), (void *)&resp,
424429
sizeof(resp), DFLT_HWRM_CMD_TIMEOUT);
425-
return bnxt_send_msg(en_dev, &fw_msg);
430+
431+
rc = bnxt_send_msg(en_dev, &fw_msg);
432+
if (rc)
433+
return rc;
434+
cctx->modes.db_push = le32_to_cpu(resp.flags) & FUNC_QCAPS_RESP_FLAGS_WCB_PUSH_MODE;
435+
436+
return 0;
426437
}
427438

428439
static int bnxt_re_net_ring_free(struct bnxt_re_dev *rdev,
@@ -669,6 +680,9 @@ static int bnxt_re_register_ib(struct bnxt_re_dev *rdev)
669680
ibdev->dev.parent = &rdev->en_dev->pdev->dev;
670681
ibdev->local_dma_lkey = BNXT_QPLIB_RSVD_LKEY;
671682

683+
if (IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS))
684+
ibdev->driver_def = bnxt_re_uapi_defs;
685+
672686
ib_set_device_ops(ibdev, &bnxt_re_dev_ops);
673687
ret = ib_device_set_netdev(&rdev->ibdev, rdev->netdev, 1);
674688
if (ret)

drivers/infiniband/hw/bnxt_re/qplib_res.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,9 @@ int bnxt_qplib_alloc_dpi(struct bnxt_qplib_res *res,
740740
dpi->dbr = dpit->priv_db;
741741
dpi->dpi = dpi->bit;
742742
break;
743+
case BNXT_QPLIB_DPI_TYPE_WC:
744+
dpi->dbr = ioremap_wc(umaddr, PAGE_SIZE);
745+
break;
743746
default:
744747
dpi->dbr = ioremap(umaddr, PAGE_SIZE);
745748
break;

drivers/infiniband/hw/bnxt_re/qplib_res.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extern const struct bnxt_qplib_gid bnxt_qplib_gid_zero;
4747

4848
struct bnxt_qplib_drv_modes {
4949
u8 wqe_mode;
50-
/* Other modes to follow here */
50+
bool db_push;
5151
};
5252

5353
struct bnxt_qplib_chip_ctx {
@@ -194,6 +194,7 @@ struct bnxt_qplib_sgid_tbl {
194194
enum {
195195
BNXT_QPLIB_DPI_TYPE_KERNEL = 0,
196196
BNXT_QPLIB_DPI_TYPE_UC = 1,
197+
BNXT_QPLIB_DPI_TYPE_WC = 2
197198
};
198199

199200
struct bnxt_qplib_dpi {

include/uapi/rdma/bnxt_re-abi.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#define __BNXT_RE_UVERBS_ABI_H__
4242

4343
#include <linux/types.h>
44+
#include <rdma/ib_user_ioctl_cmds.h>
4445

4546
#define BNXT_RE_ABI_VERSION 1
4647

@@ -51,6 +52,7 @@
5152
enum {
5253
BNXT_RE_UCNTX_CMASK_HAVE_CCTX = 0x1ULL,
5354
BNXT_RE_UCNTX_CMASK_HAVE_MODE = 0x02ULL,
55+
BNXT_RE_UCNTX_CMASK_WC_DPI_ENABLED = 0x04ULL,
5456
};
5557

5658
enum bnxt_re_wqe_mode {
@@ -127,4 +129,29 @@ enum bnxt_re_shpg_offt {
127129
BNXT_RE_END_RESV_OFFT = 0xFF0
128130
};
129131

132+
enum bnxt_re_objects {
133+
BNXT_RE_OBJECT_ALLOC_PAGE = (1U << UVERBS_ID_NS_SHIFT),
134+
};
135+
136+
enum bnxt_re_alloc_page_type {
137+
BNXT_RE_ALLOC_WC_PAGE = 0,
138+
};
139+
140+
enum bnxt_re_var_alloc_page_attrs {
141+
BNXT_RE_ALLOC_PAGE_HANDLE = (1U << UVERBS_ID_NS_SHIFT),
142+
BNXT_RE_ALLOC_PAGE_TYPE,
143+
BNXT_RE_ALLOC_PAGE_DPI,
144+
BNXT_RE_ALLOC_PAGE_MMAP_OFFSET,
145+
BNXT_RE_ALLOC_PAGE_MMAP_LENGTH,
146+
};
147+
148+
enum bnxt_re_alloc_page_attrs {
149+
BNXT_RE_DESTROY_PAGE_HANDLE = (1U << UVERBS_ID_NS_SHIFT),
150+
};
151+
152+
enum bnxt_re_alloc_page_methods {
153+
BNXT_RE_METHOD_ALLOC_PAGE = (1U << UVERBS_ID_NS_SHIFT),
154+
BNXT_RE_METHOD_DESTROY_PAGE,
155+
};
156+
130157
#endif /* __BNXT_RE_UVERBS_ABI_H__*/

0 commit comments

Comments
 (0)