Skip to content

Commit 9264cd6

Browse files
Kalesh APrleon
authored andcommitted
RDMA/bnxt_re: Allocate dev_attr information dynamically
In order to optimize the size of driver private structure, the memory for dev_attr is allocated dynamically during the chip context initialization. In order to make certain runtime decisions, store dev_attr in the qplib_res structure. Signed-off-by: Kalesh AP <[email protected]> Signed-off-by: Selvin Xavier <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Leon Romanovsky <[email protected]>
1 parent 57e6464 commit 9264cd6

File tree

8 files changed

+51
-45
lines changed

8 files changed

+51
-45
lines changed

drivers/infiniband/hw/bnxt_re/bnxt_re.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ struct bnxt_re_dev {
204204
struct bnxt_re_nq_record *nqr;
205205

206206
/* Device Resources */
207-
struct bnxt_qplib_dev_attr dev_attr;
207+
struct bnxt_qplib_dev_attr *dev_attr;
208208
struct bnxt_qplib_ctx qplib_ctx;
209209
struct bnxt_qplib_res qplib_res;
210210
struct bnxt_qplib_dpi dpi_privileged;

drivers/infiniband/hw/bnxt_re/hw_counters.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ int bnxt_re_ib_get_hw_stats(struct ib_device *ibdev,
348348
goto done;
349349
}
350350
bnxt_re_copy_err_stats(rdev, stats, err_s);
351-
if (_is_ext_stats_supported(rdev->dev_attr.dev_cap_flags) &&
351+
if (_is_ext_stats_supported(rdev->dev_attr->dev_cap_flags) &&
352352
!rdev->is_virtfn) {
353353
rc = bnxt_re_get_ext_stat(rdev, stats);
354354
if (rc) {

drivers/infiniband/hw/bnxt_re/ib_verbs.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static int __qp_access_flags_to_ib(struct bnxt_qplib_chip_ctx *cctx, u8 qflags)
159159
static void bnxt_re_check_and_set_relaxed_ordering(struct bnxt_re_dev *rdev,
160160
struct bnxt_qplib_mrw *qplib_mr)
161161
{
162-
if (_is_relaxed_ordering_supported(rdev->dev_attr.dev_cap_flags2) &&
162+
if (_is_relaxed_ordering_supported(rdev->dev_attr->dev_cap_flags2) &&
163163
pcie_relaxed_ordering_enabled(rdev->en_dev->pdev))
164164
qplib_mr->flags |= CMDQ_REGISTER_MR_FLAGS_ENABLE_RO;
165165
}
@@ -184,7 +184,7 @@ int bnxt_re_query_device(struct ib_device *ibdev,
184184
struct ib_udata *udata)
185185
{
186186
struct bnxt_re_dev *rdev = to_bnxt_re_dev(ibdev, ibdev);
187-
struct bnxt_qplib_dev_attr *dev_attr = &rdev->dev_attr;
187+
struct bnxt_qplib_dev_attr *dev_attr = rdev->dev_attr;
188188

189189
memset(ib_attr, 0, sizeof(*ib_attr));
190190
memcpy(&ib_attr->fw_ver, dev_attr->fw_ver,
@@ -273,7 +273,7 @@ int bnxt_re_query_port(struct ib_device *ibdev, u32 port_num,
273273
struct ib_port_attr *port_attr)
274274
{
275275
struct bnxt_re_dev *rdev = to_bnxt_re_dev(ibdev, ibdev);
276-
struct bnxt_qplib_dev_attr *dev_attr = &rdev->dev_attr;
276+
struct bnxt_qplib_dev_attr *dev_attr = rdev->dev_attr;
277277
int rc;
278278

279279
memset(port_attr, 0, sizeof(*port_attr));
@@ -331,8 +331,8 @@ void bnxt_re_query_fw_str(struct ib_device *ibdev, char *str)
331331
struct bnxt_re_dev *rdev = to_bnxt_re_dev(ibdev, ibdev);
332332

333333
snprintf(str, IB_FW_VERSION_NAME_MAX, "%d.%d.%d.%d",
334-
rdev->dev_attr.fw_ver[0], rdev->dev_attr.fw_ver[1],
335-
rdev->dev_attr.fw_ver[2], rdev->dev_attr.fw_ver[3]);
334+
rdev->dev_attr->fw_ver[0], rdev->dev_attr->fw_ver[1],
335+
rdev->dev_attr->fw_ver[2], rdev->dev_attr->fw_ver[3]);
336336
}
337337

338338
int bnxt_re_query_pkey(struct ib_device *ibdev, u32 port_num,
@@ -583,7 +583,7 @@ static int bnxt_re_create_fence_mr(struct bnxt_re_pd *pd)
583583
mr->qplib_mr.pd = &pd->qplib_pd;
584584
mr->qplib_mr.type = CMDQ_ALLOCATE_MRW_MRW_FLAGS_PMR;
585585
mr->qplib_mr.access_flags = __from_ib_access_flags(mr_access_flags);
586-
if (!_is_alloc_mr_unified(rdev->dev_attr.dev_cap_flags)) {
586+
if (!_is_alloc_mr_unified(rdev->dev_attr->dev_cap_flags)) {
587587
rc = bnxt_qplib_alloc_mrw(&rdev->qplib_res, &mr->qplib_mr);
588588
if (rc) {
589589
ibdev_err(&rdev->ibdev, "Failed to alloc fence-HW-MR\n");
@@ -1060,7 +1060,7 @@ static int bnxt_re_setup_swqe_size(struct bnxt_re_qp *qp,
10601060
rdev = qp->rdev;
10611061
qplqp = &qp->qplib_qp;
10621062
sq = &qplqp->sq;
1063-
dev_attr = &rdev->dev_attr;
1063+
dev_attr = rdev->dev_attr;
10641064

10651065
align = sizeof(struct sq_send_hdr);
10661066
ilsize = ALIGN(init_attr->cap.max_inline_data, align);
@@ -1280,7 +1280,7 @@ static int bnxt_re_init_rq_attr(struct bnxt_re_qp *qp,
12801280
rdev = qp->rdev;
12811281
qplqp = &qp->qplib_qp;
12821282
rq = &qplqp->rq;
1283-
dev_attr = &rdev->dev_attr;
1283+
dev_attr = rdev->dev_attr;
12841284

12851285
if (init_attr->srq) {
12861286
struct bnxt_re_srq *srq;
@@ -1317,7 +1317,7 @@ static void bnxt_re_adjust_gsi_rq_attr(struct bnxt_re_qp *qp)
13171317

13181318
rdev = qp->rdev;
13191319
qplqp = &qp->qplib_qp;
1320-
dev_attr = &rdev->dev_attr;
1320+
dev_attr = rdev->dev_attr;
13211321

13221322
if (!bnxt_qplib_is_chip_gen_p5_p7(rdev->chip_ctx)) {
13231323
qplqp->rq.max_sge = dev_attr->max_qp_sges;
@@ -1343,7 +1343,7 @@ static int bnxt_re_init_sq_attr(struct bnxt_re_qp *qp,
13431343
rdev = qp->rdev;
13441344
qplqp = &qp->qplib_qp;
13451345
sq = &qplqp->sq;
1346-
dev_attr = &rdev->dev_attr;
1346+
dev_attr = rdev->dev_attr;
13471347

13481348
sq->max_sge = init_attr->cap.max_send_sge;
13491349
entries = init_attr->cap.max_send_wr;
@@ -1396,7 +1396,7 @@ static void bnxt_re_adjust_gsi_sq_attr(struct bnxt_re_qp *qp,
13961396

13971397
rdev = qp->rdev;
13981398
qplqp = &qp->qplib_qp;
1399-
dev_attr = &rdev->dev_attr;
1399+
dev_attr = rdev->dev_attr;
14001400

14011401
if (!bnxt_qplib_is_chip_gen_p5_p7(rdev->chip_ctx)) {
14021402
entries = bnxt_re_init_depth(init_attr->cap.max_send_wr + 1, uctx);
@@ -1445,7 +1445,7 @@ static int bnxt_re_init_qp_attr(struct bnxt_re_qp *qp, struct bnxt_re_pd *pd,
14451445

14461446
rdev = qp->rdev;
14471447
qplqp = &qp->qplib_qp;
1448-
dev_attr = &rdev->dev_attr;
1448+
dev_attr = rdev->dev_attr;
14491449

14501450
/* Setup misc params */
14511451
ether_addr_copy(qplqp->smac, rdev->netdev->dev_addr);
@@ -1615,7 +1615,7 @@ int bnxt_re_create_qp(struct ib_qp *ib_qp, struct ib_qp_init_attr *qp_init_attr,
16151615
ib_pd = ib_qp->pd;
16161616
pd = container_of(ib_pd, struct bnxt_re_pd, ib_pd);
16171617
rdev = pd->rdev;
1618-
dev_attr = &rdev->dev_attr;
1618+
dev_attr = rdev->dev_attr;
16191619
qp = container_of(ib_qp, struct bnxt_re_qp, ib_qp);
16201620

16211621
uctx = rdma_udata_to_drv_context(udata, struct bnxt_re_ucontext, ib_uctx);
@@ -1843,7 +1843,7 @@ int bnxt_re_create_srq(struct ib_srq *ib_srq,
18431843
ib_pd = ib_srq->pd;
18441844
pd = container_of(ib_pd, struct bnxt_re_pd, ib_pd);
18451845
rdev = pd->rdev;
1846-
dev_attr = &rdev->dev_attr;
1846+
dev_attr = rdev->dev_attr;
18471847
srq = container_of(ib_srq, struct bnxt_re_srq, ib_srq);
18481848

18491849
if (srq_init_attr->attr.max_wr >= dev_attr->max_srq_wqes) {
@@ -2047,7 +2047,7 @@ int bnxt_re_modify_qp(struct ib_qp *ib_qp, struct ib_qp_attr *qp_attr,
20472047
{
20482048
struct bnxt_re_qp *qp = container_of(ib_qp, struct bnxt_re_qp, ib_qp);
20492049
struct bnxt_re_dev *rdev = qp->rdev;
2050-
struct bnxt_qplib_dev_attr *dev_attr = &rdev->dev_attr;
2050+
struct bnxt_qplib_dev_attr *dev_attr = rdev->dev_attr;
20512051
enum ib_qp_state curr_qp_state, new_qp_state;
20522052
int rc, entries;
20532053
unsigned int flags;
@@ -3089,7 +3089,7 @@ int bnxt_re_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
30893089
struct ib_udata *udata = &attrs->driver_udata;
30903090
struct bnxt_re_ucontext *uctx =
30913091
rdma_udata_to_drv_context(udata, struct bnxt_re_ucontext, ib_uctx);
3092-
struct bnxt_qplib_dev_attr *dev_attr = &rdev->dev_attr;
3092+
struct bnxt_qplib_dev_attr *dev_attr = rdev->dev_attr;
30933093
struct bnxt_qplib_chip_ctx *cctx;
30943094
int cqe = attr->cqe;
30953095
int rc, entries;
@@ -3224,7 +3224,7 @@ int bnxt_re_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata)
32243224

32253225
cq = container_of(ibcq, struct bnxt_re_cq, ib_cq);
32263226
rdev = cq->rdev;
3227-
dev_attr = &rdev->dev_attr;
3227+
dev_attr = rdev->dev_attr;
32283228
if (!ibcq->uobject) {
32293229
ibdev_err(&rdev->ibdev, "Kernel CQ Resize not supported");
32303230
return -EOPNOTSUPP;
@@ -4197,7 +4197,7 @@ static struct ib_mr *__bnxt_re_user_reg_mr(struct ib_pd *ib_pd, u64 length, u64
41974197
mr->qplib_mr.access_flags = __from_ib_access_flags(mr_access_flags);
41984198
mr->qplib_mr.type = CMDQ_ALLOCATE_MRW_MRW_FLAGS_MR;
41994199

4200-
if (!_is_alloc_mr_unified(rdev->dev_attr.dev_cap_flags)) {
4200+
if (!_is_alloc_mr_unified(rdev->dev_attr->dev_cap_flags)) {
42014201
rc = bnxt_qplib_alloc_mrw(&rdev->qplib_res, &mr->qplib_mr);
42024202
if (rc) {
42034203
ibdev_err(&rdev->ibdev, "Failed to allocate MR rc = %d", rc);
@@ -4289,7 +4289,7 @@ int bnxt_re_alloc_ucontext(struct ib_ucontext *ctx, struct ib_udata *udata)
42894289
struct bnxt_re_ucontext *uctx =
42904290
container_of(ctx, struct bnxt_re_ucontext, ib_uctx);
42914291
struct bnxt_re_dev *rdev = to_bnxt_re_dev(ibdev, ibdev);
4292-
struct bnxt_qplib_dev_attr *dev_attr = &rdev->dev_attr;
4292+
struct bnxt_qplib_dev_attr *dev_attr = rdev->dev_attr;
42934293
struct bnxt_re_user_mmap_entry *entry;
42944294
struct bnxt_re_uctx_resp resp = {};
42954295
struct bnxt_re_uctx_req ureq = {};

drivers/infiniband/hw/bnxt_re/main.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ static void bnxt_re_destroy_chip_ctx(struct bnxt_re_dev *rdev)
148148

149149
if (!rdev->chip_ctx)
150150
return;
151+
152+
kfree(rdev->dev_attr);
153+
rdev->dev_attr = NULL;
154+
151155
chip_ctx = rdev->chip_ctx;
152156
rdev->chip_ctx = NULL;
153157
rdev->rcfw.res = NULL;
@@ -161,7 +165,7 @@ static int bnxt_re_setup_chip_ctx(struct bnxt_re_dev *rdev)
161165
{
162166
struct bnxt_qplib_chip_ctx *chip_ctx;
163167
struct bnxt_en_dev *en_dev;
164-
int rc;
168+
int rc = -ENOMEM;
165169

166170
en_dev = rdev->en_dev;
167171

@@ -177,24 +181,31 @@ static int bnxt_re_setup_chip_ctx(struct bnxt_re_dev *rdev)
177181

178182
rdev->qplib_res.cctx = rdev->chip_ctx;
179183
rdev->rcfw.res = &rdev->qplib_res;
180-
rdev->qplib_res.dattr = &rdev->dev_attr;
184+
rdev->dev_attr = kzalloc(sizeof(*rdev->dev_attr), GFP_KERNEL);
185+
if (!rdev->dev_attr)
186+
goto free_chip_ctx;
187+
rdev->qplib_res.dattr = rdev->dev_attr;
181188
rdev->qplib_res.is_vf = BNXT_EN_VF(en_dev);
182189
rdev->qplib_res.en_dev = en_dev;
183190

184191
bnxt_re_set_drv_mode(rdev);
185192

186193
bnxt_re_set_db_offset(rdev);
187194
rc = bnxt_qplib_map_db_bar(&rdev->qplib_res);
188-
if (rc) {
189-
kfree(rdev->chip_ctx);
190-
rdev->chip_ctx = NULL;
191-
return rc;
192-
}
195+
if (rc)
196+
goto free_dev_attr;
193197

194198
if (bnxt_qplib_determine_atomics(en_dev->pdev))
195199
ibdev_info(&rdev->ibdev,
196200
"platform doesn't support global atomics.");
197201
return 0;
202+
free_dev_attr:
203+
kfree(rdev->dev_attr);
204+
rdev->dev_attr = NULL;
205+
free_chip_ctx:
206+
kfree(rdev->chip_ctx);
207+
rdev->chip_ctx = NULL;
208+
return rc;
198209
}
199210

200211
/* SR-IOV helper functions */
@@ -216,7 +227,7 @@ static void bnxt_re_limit_pf_res(struct bnxt_re_dev *rdev)
216227
struct bnxt_qplib_ctx *ctx;
217228
int i;
218229

219-
attr = &rdev->dev_attr;
230+
attr = rdev->dev_attr;
220231
ctx = &rdev->qplib_ctx;
221232

222233
ctx->qpc_count = min_t(u32, BNXT_RE_MAX_QPC_COUNT,
@@ -230,7 +241,7 @@ static void bnxt_re_limit_pf_res(struct bnxt_re_dev *rdev)
230241
if (!bnxt_qplib_is_chip_gen_p5_p7(rdev->chip_ctx))
231242
for (i = 0; i < MAX_TQM_ALLOC_REQ; i++)
232243
rdev->qplib_ctx.tqm_ctx.qcount[i] =
233-
rdev->dev_attr.tqm_alloc_reqs[i];
244+
rdev->dev_attr->tqm_alloc_reqs[i];
234245
}
235246

236247
static void bnxt_re_limit_vf_res(struct bnxt_qplib_ctx *qplib_ctx, u32 num_vf)
@@ -1726,12 +1737,11 @@ static int bnxt_re_alloc_res(struct bnxt_re_dev *rdev)
17261737

17271738
/* Configure and allocate resources for qplib */
17281739
rdev->qplib_res.rcfw = &rdev->rcfw;
1729-
rc = bnxt_qplib_get_dev_attr(&rdev->rcfw, &rdev->dev_attr);
1740+
rc = bnxt_qplib_get_dev_attr(&rdev->rcfw);
17301741
if (rc)
17311742
goto fail;
17321743

1733-
rc = bnxt_qplib_alloc_res(&rdev->qplib_res, rdev->en_dev->pdev,
1734-
rdev->netdev, &rdev->dev_attr);
1744+
rc = bnxt_qplib_alloc_res(&rdev->qplib_res, rdev->netdev);
17351745
if (rc)
17361746
goto fail;
17371747

@@ -2160,7 +2170,7 @@ static int bnxt_re_dev_init(struct bnxt_re_dev *rdev, u8 op_type)
21602170
rdev->pacing.dbr_pacing = false;
21612171
}
21622172
}
2163-
rc = bnxt_qplib_get_dev_attr(&rdev->rcfw, &rdev->dev_attr);
2173+
rc = bnxt_qplib_get_dev_attr(&rdev->rcfw);
21642174
if (rc)
21652175
goto disable_rcfw;
21662176

drivers/infiniband/hw/bnxt_re/qplib_res.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -876,14 +876,13 @@ void bnxt_qplib_free_res(struct bnxt_qplib_res *res)
876876
bnxt_qplib_free_dpi_tbl(res, &res->dpi_tbl);
877877
}
878878

879-
int bnxt_qplib_alloc_res(struct bnxt_qplib_res *res, struct pci_dev *pdev,
880-
struct net_device *netdev,
881-
struct bnxt_qplib_dev_attr *dev_attr)
879+
int bnxt_qplib_alloc_res(struct bnxt_qplib_res *res, struct net_device *netdev)
882880
{
881+
struct bnxt_qplib_dev_attr *dev_attr;
883882
int rc;
884883

885-
res->pdev = pdev;
886884
res->netdev = netdev;
885+
dev_attr = res->dattr;
887886

888887
rc = bnxt_qplib_alloc_sgid_tbl(res, &res->sgid_tbl, dev_attr->max_sgid);
889888
if (rc)

drivers/infiniband/hw/bnxt_re/qplib_res.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,7 @@ int bnxt_qplib_dealloc_dpi(struct bnxt_qplib_res *res,
424424
void bnxt_qplib_cleanup_res(struct bnxt_qplib_res *res);
425425
int bnxt_qplib_init_res(struct bnxt_qplib_res *res);
426426
void bnxt_qplib_free_res(struct bnxt_qplib_res *res);
427-
int bnxt_qplib_alloc_res(struct bnxt_qplib_res *res, struct pci_dev *pdev,
428-
struct net_device *netdev,
429-
struct bnxt_qplib_dev_attr *dev_attr);
427+
int bnxt_qplib_alloc_res(struct bnxt_qplib_res *res, struct net_device *netdev);
430428
void bnxt_qplib_free_ctx(struct bnxt_qplib_res *res,
431429
struct bnxt_qplib_ctx *ctx);
432430
int bnxt_qplib_alloc_ctx(struct bnxt_qplib_res *res,

drivers/infiniband/hw/bnxt_re/qplib_sp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ static void bnxt_qplib_query_version(struct bnxt_qplib_rcfw *rcfw,
8888
fw_ver[3] = resp.fw_rsvd;
8989
}
9090

91-
int bnxt_qplib_get_dev_attr(struct bnxt_qplib_rcfw *rcfw,
92-
struct bnxt_qplib_dev_attr *attr)
91+
int bnxt_qplib_get_dev_attr(struct bnxt_qplib_rcfw *rcfw)
9392
{
93+
struct bnxt_qplib_dev_attr *attr = rcfw->res->dattr;
9494
struct creq_query_func_resp resp = {};
9595
struct bnxt_qplib_cmdqmsg msg = {};
9696
struct creq_query_func_resp_sb *sb;

drivers/infiniband/hw/bnxt_re/qplib_sp.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,7 @@ int bnxt_qplib_add_sgid(struct bnxt_qplib_sgid_tbl *sgid_tbl,
326326
int bnxt_qplib_update_sgid(struct bnxt_qplib_sgid_tbl *sgid_tbl,
327327
struct bnxt_qplib_gid *gid, u16 gid_idx,
328328
const u8 *smac);
329-
int bnxt_qplib_get_dev_attr(struct bnxt_qplib_rcfw *rcfw,
330-
struct bnxt_qplib_dev_attr *attr);
329+
int bnxt_qplib_get_dev_attr(struct bnxt_qplib_rcfw *rcfw);
331330
int bnxt_qplib_set_func_resources(struct bnxt_qplib_res *res,
332331
struct bnxt_qplib_rcfw *rcfw,
333332
struct bnxt_qplib_ctx *ctx);

0 commit comments

Comments
 (0)