@@ -129,10 +129,11 @@ static struct verbs_context *bnxt_re_alloc_context(struct ibv_device *vdev,
int cmd_fd,
void *private_data)
{
- struct ibv_get_context cmd;
+ struct bnxt_re_dev *rdev = to_bnxt_re_dev(vdev);
struct ubnxt_re_cntx_resp resp;
- struct bnxt_re_dev *dev = to_bnxt_re_dev(vdev);
struct bnxt_re_context *cntx;
+ struct ibv_get_context cmd;
+ int ret;
cntx = verbs_init_and_alloc_context(vdev, cmd_fd, cntx, ibvctx,
RDMA_DRIVER_BNXT_RE);
@@ -146,9 +147,9 @@ static struct verbs_context *bnxt_re_alloc_context(struct ibv_device *vdev,
cntx->dev_id = resp.dev_id;
cntx->max_qp = resp.max_qp;
- dev->pg_size = resp.pg_size;
- dev->cqe_size = resp.cqe_sz;
- dev->max_cq_depth = resp.max_cqd;
+ rdev->pg_size = resp.pg_size;
+ rdev->cqe_size = resp.cqe_sz;
+ rdev->max_cq_depth = resp.max_cqd;
if (resp.comp_mask & BNXT_RE_UCNTX_CMASK_HAVE_CCTX) {
cntx->cctx.chip_num = resp.chip_id0 & 0xFFFF;
cntx->cctx.chip_rev = (resp.chip_id0 >>
@@ -159,7 +160,7 @@ static struct verbs_context *bnxt_re_alloc_context(struct ibv_device *vdev,
}
pthread_spin_init(&cntx->fqlock, PTHREAD_PROCESS_PRIVATE);
/* mmap shared page. */
- cntx->shpg = mmap(NULL, dev->pg_size, PROT_READ | PROT_WRITE,
+ cntx->shpg = mmap(NULL, rdev->pg_size, PROT_READ | PROT_WRITE,
MAP_SHARED, cmd_fd, 0);
if (cntx->shpg == MAP_FAILED) {
cntx->shpg = NULL;
@@ -168,6 +169,10 @@ static struct verbs_context *bnxt_re_alloc_context(struct ibv_device *vdev,
pthread_mutex_init(&cntx->shlock, NULL);
verbs_set_ops(&cntx->ibvctx, &bnxt_re_cntx_ops);
+ cntx->rdev = rdev;
+ ret = ibv_query_device(&cntx->ibvctx.context, &rdev->devattr);
+ if (ret)
+ goto failed;
return &cntx->ibvctx;
@@ -180,19 +185,19 @@ failed:
static void bnxt_re_free_context(struct ibv_context *ibvctx)
{
struct bnxt_re_context *cntx = to_bnxt_re_context(ibvctx);
- struct bnxt_re_dev *dev = to_bnxt_re_dev(ibvctx->device);
+ struct bnxt_re_dev *rdev = to_bnxt_re_dev(ibvctx->device);
/* Unmap if anything device specific was mapped in init_context. */
pthread_mutex_destroy(&cntx->shlock);
if (cntx->shpg)
- munmap(cntx->shpg, dev->pg_size);
+ munmap(cntx->shpg, rdev->pg_size);
pthread_spin_destroy(&cntx->fqlock);
/* Un-map DPI only for the first PD that was
* allocated in this context.
*/
if (cntx->udpi.dbpage && cntx->udpi.dbpage != MAP_FAILED) {
- munmap(cntx->udpi.dbpage, dev->pg_size);
+ munmap(cntx->udpi.dbpage, rdev->pg_size);
cntx->udpi.dbpage = NULL;
}
@@ -203,13 +208,13 @@ static void bnxt_re_free_context(struct ibv_context *ibvctx)
static struct verbs_device *
bnxt_re_device_alloc(struct verbs_sysfs_dev *sysfs_dev)
{
- struct bnxt_re_dev *dev;
+ struct bnxt_re_dev *rdev;
- dev = calloc(1, sizeof(*dev));
- if (!dev)
+ rdev = calloc(1, sizeof(*rdev));
+ if (!rdev)
return NULL;
- return &dev->vdev;
+ return &rdev->vdev;
}
static const struct verbs_device_ops bnxt_re_dev_ops = {
@@ -166,10 +166,12 @@ struct bnxt_re_dev {
uint32_t cqe_size;
uint32_t max_cq_depth;
+ struct ibv_device_attr devattr;
};
struct bnxt_re_context {
struct verbs_context ibvctx;
+ struct bnxt_re_dev *rdev;
uint32_t dev_id;
uint32_t max_qp;
struct bnxt_re_chip_ctx cctx;
@@ -777,25 +777,22 @@ int bnxt_re_arm_cq(struct ibv_cq *ibvcq, int flags)
static int bnxt_re_check_qp_limits(struct bnxt_re_context *cntx,
struct ibv_qp_init_attr *attr)
{
- struct ibv_device_attr devattr;
- int ret;
+ struct ibv_device_attr *devattr;
+ struct bnxt_re_dev *rdev;
- ret = bnxt_re_query_device(
- &cntx->ibvctx.context, NULL,
- container_of(&devattr, struct ibv_device_attr_ex, orig_attr),
- sizeof(devattr));
- if (ret)
- return ret;
- if (attr->cap.max_send_sge > devattr.max_sge)
+ rdev = cntx->rdev;
+ devattr = &rdev->devattr;
+
+ if (attr->cap.max_send_sge > devattr->max_sge)
return EINVAL;
- if (attr->cap.max_recv_sge > devattr.max_sge)
+ if (attr->cap.max_recv_sge > devattr->max_sge)
return EINVAL;
if (attr->cap.max_inline_data > BNXT_RE_MAX_INLINE_SIZE)
return EINVAL;
- if (attr->cap.max_send_wr > devattr.max_qp_wr)
- attr->cap.max_send_wr = devattr.max_qp_wr;
- if (attr->cap.max_recv_wr > devattr.max_qp_wr)
- attr->cap.max_recv_wr = devattr.max_qp_wr;
+ if (attr->cap.max_send_wr > devattr->max_qp_wr)
+ attr->cap.max_send_wr = devattr->max_qp_wr;
+ if (attr->cap.max_recv_wr > devattr->max_qp_wr)
+ attr->cap.max_recv_wr = devattr->max_qp_wr;
return 0;
}
Making a change to let bnxt_re_dev strucutre store the device attributes once for entire life of device context. This change saves a firmware call per QP creation and speed it up. Signed-off-by: Devesh Sharma <devesh.sharma@broadcom.com> --- providers/bnxt_re/main.c | 31 ++++++++++++++++++------------- providers/bnxt_re/main.h | 2 ++ providers/bnxt_re/verbs.c | 25 +++++++++++-------------- 3 files changed, 31 insertions(+), 27 deletions(-)