Skip to content

Commit bcfee4c

Browse files
kadesai16rleon
authored andcommitted
RDMA/bnxt_re: remove redundant cmdq_bitmap
cmdq_bitmap is used to derive the next available index in the CMDQ. This is not required as the we can get the next index using the existing bnxt_qplib_crsqe array. Driver will use bnxt_qplib_crsqe array and flag is_in_used to derive valid entries. is_in_used is replacement of cmdq_bitmap. There is no change in the existing mechanism of the circular buffer used to get index. Added opcode field in bnxt_qplib_crsqe array so that it is easy to map opcode associated with pending rcfw command. Signed-off-by: Kashyap Desai <[email protected]> Signed-off-by: Selvin Xavier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Leon Romanovsky <[email protected]>
1 parent f0c875f commit bcfee4c

File tree

2 files changed

+34
-48
lines changed

2 files changed

+34
-48
lines changed

drivers/infiniband/hw/bnxt_re/qplib_rcfw.c

Lines changed: 32 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ static int bnxt_qplib_map_rc(u8 opcode)
9595
* @cookie - cookie to track the command
9696
* @opcode - rcfw submitted for given opcode
9797
* @cbit - bitmap entry of cookie
98+
* @in_used - command is in used or freed
9899
*
99100
* If firmware has not responded any rcfw command within
100101
* rcfw->max_timeout, consider firmware as stalled.
@@ -104,7 +105,7 @@ static int bnxt_qplib_map_rc(u8 opcode)
104105
* -ENODEV if firmware is not responding
105106
*/
106107
static int bnxt_re_is_fw_stalled(struct bnxt_qplib_rcfw *rcfw,
107-
u16 cookie, u8 opcode, u16 cbit)
108+
u16 cookie, u8 opcode, bool in_used)
108109
{
109110
struct bnxt_qplib_cmdq_ctx *cmdq;
110111

@@ -117,7 +118,7 @@ static int bnxt_re_is_fw_stalled(struct bnxt_qplib_rcfw *rcfw,
117118
__func__, cookie, opcode,
118119
jiffies_to_msecs(jiffies - cmdq->last_seen),
119120
rcfw->max_timeout * 1000,
120-
test_bit(cbit, cmdq->cmdq_bitmap));
121+
in_used);
121122
return -ENODEV;
122123
}
123124

@@ -139,11 +140,11 @@ static int bnxt_re_is_fw_stalled(struct bnxt_qplib_rcfw *rcfw,
139140
static int __wait_for_resp(struct bnxt_qplib_rcfw *rcfw, u16 cookie, u8 opcode)
140141
{
141142
struct bnxt_qplib_cmdq_ctx *cmdq;
142-
u16 cbit;
143+
struct bnxt_qplib_crsqe *crsqe;
143144
int ret;
144145

145146
cmdq = &rcfw->cmdq;
146-
cbit = cookie % rcfw->cmdq_depth;
147+
crsqe = &rcfw->crsqe_tbl[cookie];
147148

148149
do {
149150
if (test_bit(ERR_DEVICE_DETACHED, &cmdq->flags))
@@ -152,19 +153,19 @@ static int __wait_for_resp(struct bnxt_qplib_rcfw *rcfw, u16 cookie, u8 opcode)
152153
return -ETIMEDOUT;
153154

154155
wait_event_timeout(cmdq->waitq,
155-
!test_bit(cbit, cmdq->cmdq_bitmap) ||
156+
!crsqe->is_in_used ||
156157
test_bit(ERR_DEVICE_DETACHED, &cmdq->flags),
157158
msecs_to_jiffies(rcfw->max_timeout * 1000));
158159

159-
if (!test_bit(cbit, cmdq->cmdq_bitmap))
160+
if (!crsqe->is_in_used)
160161
return 0;
161162

162163
bnxt_qplib_service_creq(&rcfw->creq.creq_tasklet);
163164

164-
if (!test_bit(cbit, cmdq->cmdq_bitmap))
165+
if (!crsqe->is_in_used)
165166
return 0;
166167

167-
ret = bnxt_re_is_fw_stalled(rcfw, cookie, opcode, cbit);
168+
ret = bnxt_re_is_fw_stalled(rcfw, cookie, opcode, crsqe->is_in_used);
168169
if (ret)
169170
return ret;
170171

@@ -187,11 +188,11 @@ static int __wait_for_resp(struct bnxt_qplib_rcfw *rcfw, u16 cookie, u8 opcode)
187188
static int __block_for_resp(struct bnxt_qplib_rcfw *rcfw, u16 cookie, u8 opcode)
188189
{
189190
struct bnxt_qplib_cmdq_ctx *cmdq = &rcfw->cmdq;
191+
struct bnxt_qplib_crsqe *crsqe;
190192
unsigned long issue_time = 0;
191-
u16 cbit;
192193

193-
cbit = cookie % rcfw->cmdq_depth;
194194
issue_time = jiffies;
195+
crsqe = &rcfw->crsqe_tbl[cookie];
195196

196197
do {
197198
if (test_bit(ERR_DEVICE_DETACHED, &cmdq->flags))
@@ -202,7 +203,7 @@ static int __block_for_resp(struct bnxt_qplib_rcfw *rcfw, u16 cookie, u8 opcode)
202203
udelay(1);
203204

204205
bnxt_qplib_service_creq(&rcfw->creq.creq_tasklet);
205-
if (!test_bit(cbit, cmdq->cmdq_bitmap))
206+
if (!crsqe->is_in_used)
206207
return 0;
207208

208209
} while (time_before(jiffies, issue_time + (8 * HZ)));
@@ -235,16 +236,13 @@ static void __send_message_no_waiter(struct bnxt_qplib_rcfw *rcfw,
235236
struct bnxt_qplib_crsqe *crsqe;
236237
struct bnxt_qplib_cmdqe *cmdqe;
237238
u32 sw_prod, cmdq_prod;
238-
u16 cookie, cbit;
239+
u16 cookie;
239240
u32 bsize;
240241
u8 *preq;
241242

242243
cookie = cmdq->seq_num & RCFW_MAX_COOKIE_VALUE;
243-
cbit = cookie % rcfw->cmdq_depth;
244-
245-
set_bit(cbit, cmdq->cmdq_bitmap);
246244
__set_cmdq_base_cookie(msg->req, msg->req_sz, cpu_to_le16(cookie));
247-
crsqe = &rcfw->crsqe_tbl[cbit];
245+
crsqe = &rcfw->crsqe_tbl[cookie];
248246

249247
/* Set cmd_size in terms of 16B slots in req. */
250248
bsize = bnxt_qplib_set_cmd_slots(msg->req);
@@ -253,6 +251,7 @@ static void __send_message_no_waiter(struct bnxt_qplib_rcfw *rcfw,
253251
*/
254252
crsqe->is_internal_cmd = true;
255253
crsqe->is_waiter_alive = false;
254+
crsqe->is_in_used = true;
256255
crsqe->req_size = __get_cmdq_base_cmd_size(msg->req, msg->req_sz);
257256

258257
preq = (u8 *)msg->req;
@@ -288,7 +287,8 @@ static int __send_message(struct bnxt_qplib_rcfw *rcfw,
288287
u32 sw_prod, cmdq_prod;
289288
struct pci_dev *pdev;
290289
unsigned long flags;
291-
u16 cookie, cbit;
290+
u16 cookie;
291+
u8 opcode;
292292
u8 *preq;
293293

294294
cmdq = &rcfw->cmdq;
@@ -302,10 +302,9 @@ static int __send_message(struct bnxt_qplib_rcfw *rcfw,
302302
required_slots = bnxt_qplib_get_cmd_slots(msg->req);
303303
free_slots = HWQ_FREE_SLOTS(hwq);
304304
cookie = cmdq->seq_num & RCFW_MAX_COOKIE_VALUE;
305-
cbit = cookie % rcfw->cmdq_depth;
305+
crsqe = &rcfw->crsqe_tbl[cookie];
306306

307-
if (required_slots >= free_slots ||
308-
test_bit(cbit, cmdq->cmdq_bitmap)) {
307+
if (required_slots >= free_slots) {
309308
dev_info_ratelimited(&pdev->dev,
310309
"CMDQ is full req/free %d/%d!",
311310
required_slots, free_slots);
@@ -314,15 +313,17 @@ static int __send_message(struct bnxt_qplib_rcfw *rcfw,
314313
}
315314
if (msg->block)
316315
cookie |= RCFW_CMD_IS_BLOCKING;
317-
set_bit(cbit, cmdq->cmdq_bitmap);
318316
__set_cmdq_base_cookie(msg->req, msg->req_sz, cpu_to_le16(cookie));
319-
crsqe = &rcfw->crsqe_tbl[cbit];
317+
320318
bsize = bnxt_qplib_set_cmd_slots(msg->req);
321319
crsqe->free_slots = free_slots;
322320
crsqe->resp = (struct creq_qp_event *)msg->resp;
323321
crsqe->resp->cookie = cpu_to_le16(cookie);
324322
crsqe->is_internal_cmd = false;
325323
crsqe->is_waiter_alive = true;
324+
crsqe->is_in_used = true;
325+
crsqe->opcode = opcode;
326+
326327
crsqe->req_size = __get_cmdq_base_cmd_size(msg->req, msg->req_sz);
327328
if (__get_cmdq_base_resp_size(msg->req, msg->req_sz) && msg->sb) {
328329
struct bnxt_qplib_rcfw_sbuf *sbuf = msg->sb;
@@ -385,12 +386,12 @@ static int __poll_for_resp(struct bnxt_qplib_rcfw *rcfw, u16 cookie,
385386
u8 opcode)
386387
{
387388
struct bnxt_qplib_cmdq_ctx *cmdq = &rcfw->cmdq;
389+
struct bnxt_qplib_crsqe *crsqe;
388390
unsigned long issue_time;
389-
u16 cbit;
390391
int ret;
391392

392-
cbit = cookie % rcfw->cmdq_depth;
393393
issue_time = jiffies;
394+
crsqe = &rcfw->crsqe_tbl[cookie];
394395

395396
do {
396397
if (test_bit(ERR_DEVICE_DETACHED, &cmdq->flags))
@@ -401,11 +402,11 @@ static int __poll_for_resp(struct bnxt_qplib_rcfw *rcfw, u16 cookie,
401402
usleep_range(1000, 1001);
402403

403404
bnxt_qplib_service_creq(&rcfw->creq.creq_tasklet);
404-
if (!test_bit(cbit, cmdq->cmdq_bitmap))
405+
if (!crsqe->is_in_used)
405406
return 0;
406407
if (jiffies_to_msecs(jiffies - issue_time) >
407408
(rcfw->max_timeout * 1000)) {
408-
ret = bnxt_re_is_fw_stalled(rcfw, cookie, opcode, cbit);
409+
ret = bnxt_re_is_fw_stalled(rcfw, cookie, opcode, crsqe->is_in_used);
409410
if (ret)
410411
return ret;
411412
}
@@ -485,7 +486,7 @@ static int __bnxt_qplib_rcfw_send_message(struct bnxt_qplib_rcfw *rcfw,
485486
struct creq_qp_event *evnt = (struct creq_qp_event *)msg->resp;
486487
struct bnxt_qplib_crsqe *crsqe;
487488
unsigned long flags;
488-
u16 cookie, cbit;
489+
u16 cookie;
489490
int rc = 0;
490491
u8 opcode;
491492

@@ -501,7 +502,6 @@ static int __bnxt_qplib_rcfw_send_message(struct bnxt_qplib_rcfw *rcfw,
501502

502503
cookie = le16_to_cpu(__get_cmdq_base_cookie(msg->req, msg->req_sz))
503504
& RCFW_MAX_COOKIE_VALUE;
504-
cbit = cookie % rcfw->cmdq_depth;
505505

506506
if (msg->block)
507507
rc = __block_for_resp(rcfw, cookie, opcode);
@@ -518,7 +518,7 @@ static int __bnxt_qplib_rcfw_send_message(struct bnxt_qplib_rcfw *rcfw,
518518

519519
if (rc) {
520520
spin_lock_irqsave(&rcfw->cmdq.hwq.lock, flags);
521-
crsqe = &rcfw->crsqe_tbl[cbit];
521+
crsqe = &rcfw->crsqe_tbl[cookie];
522522
crsqe->is_waiter_alive = false;
523523
if (rc == -ENODEV)
524524
set_bit(FIRMWARE_STALL_DETECTED, &rcfw->cmdq.flags);
@@ -630,12 +630,11 @@ static int bnxt_qplib_process_qp_event(struct bnxt_qplib_rcfw *rcfw,
630630
struct bnxt_qplib_crsqe *crsqe;
631631
u32 qp_id, tbl_indx, req_size;
632632
struct bnxt_qplib_qp *qp;
633-
u16 cbit, blocked = 0;
633+
u16 cookie, blocked = 0;
634634
bool is_waiter_alive;
635635
struct pci_dev *pdev;
636636
unsigned long flags;
637637
u32 wait_cmds = 0;
638-
u16 cookie;
639638
int rc = 0;
640639

641640
pdev = rcfw->pdev;
@@ -670,8 +669,8 @@ static int bnxt_qplib_process_qp_event(struct bnxt_qplib_rcfw *rcfw,
670669
cookie = le16_to_cpu(qp_event->cookie);
671670
blocked = cookie & RCFW_CMD_IS_BLOCKING;
672671
cookie &= RCFW_MAX_COOKIE_VALUE;
673-
cbit = cookie % rcfw->cmdq_depth;
674-
crsqe = &rcfw->crsqe_tbl[cbit];
672+
crsqe = &rcfw->crsqe_tbl[cookie];
673+
crsqe->is_in_used = false;
675674

676675
if (WARN_ONCE(test_bit(FIRMWARE_STALL_DETECTED,
677676
&rcfw->cmdq.flags),
@@ -683,9 +682,6 @@ static int bnxt_qplib_process_qp_event(struct bnxt_qplib_rcfw *rcfw,
683682
return rc;
684683
}
685684

686-
if (!test_and_clear_bit(cbit, rcfw->cmdq.cmdq_bitmap))
687-
dev_warn(&pdev->dev,
688-
"CMD bit %d was not requested\n", cbit);
689685
if (crsqe->is_internal_cmd && !qp_event->status)
690686
atomic_dec(&rcfw->timeout_send);
691687

@@ -920,7 +916,6 @@ int bnxt_qplib_init_rcfw(struct bnxt_qplib_rcfw *rcfw,
920916

921917
void bnxt_qplib_free_rcfw_channel(struct bnxt_qplib_rcfw *rcfw)
922918
{
923-
bitmap_free(rcfw->cmdq.cmdq_bitmap);
924919
kfree(rcfw->qp_tbl);
925920
kfree(rcfw->crsqe_tbl);
926921
bnxt_qplib_free_hwq(rcfw->res, &rcfw->cmdq.hwq);
@@ -975,10 +970,6 @@ int bnxt_qplib_alloc_rcfw_channel(struct bnxt_qplib_res *res,
975970
if (!rcfw->crsqe_tbl)
976971
goto fail;
977972

978-
cmdq->cmdq_bitmap = bitmap_zalloc(rcfw->cmdq_depth, GFP_KERNEL);
979-
if (!cmdq->cmdq_bitmap)
980-
goto fail;
981-
982973
/* Allocate one extra to hold the QP1 entries */
983974
rcfw->qp_tbl_size = qp_tbl_sz + 1;
984975
rcfw->qp_tbl = kcalloc(rcfw->qp_tbl_size, sizeof(struct bnxt_qplib_qp_node),
@@ -1023,7 +1014,6 @@ void bnxt_qplib_disable_rcfw_channel(struct bnxt_qplib_rcfw *rcfw)
10231014
{
10241015
struct bnxt_qplib_creq_ctx *creq;
10251016
struct bnxt_qplib_cmdq_ctx *cmdq;
1026-
unsigned long indx;
10271017

10281018
creq = &rcfw->creq;
10291019
cmdq = &rcfw->cmdq;
@@ -1033,11 +1023,6 @@ void bnxt_qplib_disable_rcfw_channel(struct bnxt_qplib_rcfw *rcfw)
10331023
iounmap(cmdq->cmdq_mbox.reg.bar_reg);
10341024
iounmap(creq->creq_db.reg.bar_reg);
10351025

1036-
indx = find_first_bit(cmdq->cmdq_bitmap, rcfw->cmdq_depth);
1037-
if (indx != rcfw->cmdq_depth)
1038-
dev_err(&rcfw->pdev->dev,
1039-
"disabling RCFW with pending cmd-bit %lx\n", indx);
1040-
10411026
cmdq->cmdq_mbox.reg.bar_reg = NULL;
10421027
creq->creq_db.reg.bar_reg = NULL;
10431028
creq->aeq_handler = NULL;

drivers/infiniband/hw/bnxt_re/qplib_rcfw.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,10 @@ struct bnxt_qplib_crsqe {
152152
u32 req_size;
153153
/* Free slots at the time of submission */
154154
u32 free_slots;
155+
u8 opcode;
155156
bool is_waiter_alive;
156157
bool is_internal_cmd;
158+
bool is_in_used;
157159
};
158160

159161
struct bnxt_qplib_rcfw_sbuf {
@@ -185,7 +187,6 @@ struct bnxt_qplib_cmdq_ctx {
185187
struct bnxt_qplib_cmdq_mbox cmdq_mbox;
186188
wait_queue_head_t waitq;
187189
unsigned long flags;
188-
unsigned long *cmdq_bitmap;
189190
unsigned long last_seen;
190191
u32 seq_num;
191192
};

0 commit comments

Comments
 (0)