Skip to content

Commit 77c6e27

Browse files
Amit Cohenkuba-moo
Amit Cohen
authored andcommitted
mlxsw: pci: Store DQ pointer as part of CQ structure
Currently, for each completion, we check the number of descriptor queue and take it via mlxsw_pci_{sdq,rdq}_get(). This is inefficient, the DQ should be the same for all the completions in CQ, as each CQ handles only one DQ - SDQ or RDQ. This mapping is handled as part of DQ initialization via mlxsw_cmd_mbox_sw2hw_dq_cq_set(). Instead, as part of DQ initialization, set DQ pointer in the appropriate CQ structure. When we handle completions, warn in case that the DQ number that we expect is different from the number we get in the CQE. Call WARN_ON_ONCE() only after checking the value, to avoid calling this method for each completion. Signed-off-by: Amit Cohen <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Signed-off-by: Petr Machata <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://lore.kernel.org/r/a5b2559cd6d532c120f3194f89a1e257110318f1.1712062203.git.petrm@nvidia.com Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 82238f0 commit 77c6e27

File tree

1 file changed

+28
-13
lines changed
  • drivers/net/ethernet/mellanox/mlxsw

1 file changed

+28
-13
lines changed

drivers/net/ethernet/mellanox/mlxsw/pci.c

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ struct mlxsw_pci_queue {
8686
struct mlxsw_pci *pci;
8787
struct {
8888
enum mlxsw_pci_cqe_v v;
89+
struct mlxsw_pci_queue *dq;
8990
} cq;
9091
};
9192

@@ -194,13 +195,6 @@ static struct mlxsw_pci_queue *mlxsw_pci_sdq_get(struct mlxsw_pci *mlxsw_pci,
194195
MLXSW_PCI_QUEUE_TYPE_SDQ, q_num);
195196
}
196197

197-
static struct mlxsw_pci_queue *mlxsw_pci_rdq_get(struct mlxsw_pci *mlxsw_pci,
198-
u8 q_num)
199-
{
200-
return __mlxsw_pci_queue_get(mlxsw_pci,
201-
MLXSW_PCI_QUEUE_TYPE_RDQ, q_num);
202-
}
203-
204198
static struct mlxsw_pci_queue *mlxsw_pci_cq_get(struct mlxsw_pci *mlxsw_pci,
205199
u8 q_num)
206200
{
@@ -265,7 +259,9 @@ static dma_addr_t __mlxsw_pci_queue_page_get(struct mlxsw_pci_queue *q,
265259
static int mlxsw_pci_sdq_init(struct mlxsw_pci *mlxsw_pci, char *mbox,
266260
struct mlxsw_pci_queue *q)
267261
{
262+
struct mlxsw_pci_queue *cq;
268263
int tclass;
264+
u8 cq_num;
269265
int lp;
270266
int i;
271267
int err;
@@ -278,7 +274,8 @@ static int mlxsw_pci_sdq_init(struct mlxsw_pci *mlxsw_pci, char *mbox,
278274
MLXSW_CMD_MBOX_SW2HW_DQ_SDQ_LP_WQE;
279275

280276
/* Set CQ of same number of this SDQ. */
281-
mlxsw_cmd_mbox_sw2hw_dq_cq_set(mbox, q->num);
277+
cq_num = q->num;
278+
mlxsw_cmd_mbox_sw2hw_dq_cq_set(mbox, cq_num);
282279
mlxsw_cmd_mbox_sw2hw_dq_sdq_lp_set(mbox, lp);
283280
mlxsw_cmd_mbox_sw2hw_dq_sdq_tclass_set(mbox, tclass);
284281
mlxsw_cmd_mbox_sw2hw_dq_log2_dq_sz_set(mbox, 3); /* 8 pages */
@@ -291,6 +288,9 @@ static int mlxsw_pci_sdq_init(struct mlxsw_pci *mlxsw_pci, char *mbox,
291288
err = mlxsw_cmd_sw2hw_sdq(mlxsw_pci->core, mbox, q->num);
292289
if (err)
293290
return err;
291+
292+
cq = mlxsw_pci_cq_get(mlxsw_pci, cq_num);
293+
cq->cq.dq = q;
294294
mlxsw_pci_queue_doorbell_producer_ring(mlxsw_pci, q);
295295
return 0;
296296
}
@@ -374,6 +374,8 @@ static int mlxsw_pci_rdq_init(struct mlxsw_pci *mlxsw_pci, char *mbox,
374374
{
375375
struct mlxsw_pci_queue_elem_info *elem_info;
376376
u8 sdq_count = mlxsw_pci->num_sdqs;
377+
struct mlxsw_pci_queue *cq;
378+
u8 cq_num;
377379
int i;
378380
int err;
379381

@@ -383,7 +385,8 @@ static int mlxsw_pci_rdq_init(struct mlxsw_pci *mlxsw_pci, char *mbox,
383385
/* Set CQ of same number of this RDQ with base
384386
* above SDQ count as the lower ones are assigned to SDQs.
385387
*/
386-
mlxsw_cmd_mbox_sw2hw_dq_cq_set(mbox, sdq_count + q->num);
388+
cq_num = sdq_count + q->num;
389+
mlxsw_cmd_mbox_sw2hw_dq_cq_set(mbox, cq_num);
387390
mlxsw_cmd_mbox_sw2hw_dq_log2_dq_sz_set(mbox, 3); /* 8 pages */
388391
for (i = 0; i < MLXSW_PCI_AQ_PAGES; i++) {
389392
dma_addr_t mapaddr = __mlxsw_pci_queue_page_get(q, i);
@@ -395,6 +398,9 @@ static int mlxsw_pci_rdq_init(struct mlxsw_pci *mlxsw_pci, char *mbox,
395398
if (err)
396399
return err;
397400

401+
cq = mlxsw_pci_cq_get(mlxsw_pci, cq_num);
402+
cq->cq.dq = q;
403+
398404
mlxsw_pci_queue_doorbell_producer_ring(mlxsw_pci, q);
399405

400406
for (i = 0; i < q->count; i++) {
@@ -415,6 +421,7 @@ static int mlxsw_pci_rdq_init(struct mlxsw_pci *mlxsw_pci, char *mbox,
415421
elem_info = mlxsw_pci_queue_elem_info_get(q, i);
416422
mlxsw_pci_rdq_skb_free(mlxsw_pci, elem_info);
417423
}
424+
cq->cq.dq = NULL;
418425
mlxsw_cmd_hw2sw_rdq(mlxsw_pci->core, q->num);
419426

420427
return err;
@@ -648,6 +655,7 @@ static char *mlxsw_pci_cq_sw_cqe_get(struct mlxsw_pci_queue *q)
648655
static void mlxsw_pci_cq_rx_tasklet(struct tasklet_struct *t)
649656
{
650657
struct mlxsw_pci_queue *q = from_tasklet(q, t, tasklet);
658+
struct mlxsw_pci_queue *rdq = q->cq.dq;
651659
struct mlxsw_pci *mlxsw_pci = q->pci;
652660
int credits = q->count >> 1;
653661
int items = 0;
@@ -658,17 +666,20 @@ static void mlxsw_pci_cq_rx_tasklet(struct tasklet_struct *t)
658666
u8 sendq = mlxsw_pci_cqe_sr_get(q->cq.v, cqe);
659667
u8 dqn = mlxsw_pci_cqe_dqn_get(q->cq.v, cqe);
660668
char ncqe[MLXSW_PCI_CQE_SIZE_MAX];
661-
struct mlxsw_pci_queue *rdq;
662669

663670
if (unlikely(sendq)) {
664671
WARN_ON_ONCE(1);
665672
continue;
666673
}
667674

675+
if (unlikely(dqn != rdq->num)) {
676+
WARN_ON_ONCE(1);
677+
continue;
678+
}
679+
668680
memcpy(ncqe, cqe, q->elem_size);
669681
mlxsw_pci_queue_doorbell_consumer_ring(mlxsw_pci, q);
670682

671-
rdq = mlxsw_pci_rdq_get(mlxsw_pci, dqn);
672683
mlxsw_pci_cqe_rdq_handle(mlxsw_pci, rdq,
673684
wqe_counter, q->cq.v, ncqe);
674685

@@ -682,6 +693,7 @@ static void mlxsw_pci_cq_rx_tasklet(struct tasklet_struct *t)
682693
static void mlxsw_pci_cq_tx_tasklet(struct tasklet_struct *t)
683694
{
684695
struct mlxsw_pci_queue *q = from_tasklet(q, t, tasklet);
696+
struct mlxsw_pci_queue *sdq = q->cq.dq;
685697
struct mlxsw_pci *mlxsw_pci = q->pci;
686698
int credits = q->count >> 1;
687699
int items = 0;
@@ -692,17 +704,20 @@ static void mlxsw_pci_cq_tx_tasklet(struct tasklet_struct *t)
692704
u8 sendq = mlxsw_pci_cqe_sr_get(q->cq.v, cqe);
693705
u8 dqn = mlxsw_pci_cqe_dqn_get(q->cq.v, cqe);
694706
char ncqe[MLXSW_PCI_CQE_SIZE_MAX];
695-
struct mlxsw_pci_queue *sdq;
696707

697708
if (unlikely(!sendq)) {
698709
WARN_ON_ONCE(1);
699710
continue;
700711
}
701712

713+
if (unlikely(dqn != sdq->num)) {
714+
WARN_ON_ONCE(1);
715+
continue;
716+
}
717+
702718
memcpy(ncqe, cqe, q->elem_size);
703719
mlxsw_pci_queue_doorbell_consumer_ring(mlxsw_pci, q);
704720

705-
sdq = mlxsw_pci_sdq_get(mlxsw_pci, dqn);
706721
mlxsw_pci_cqe_sdq_handle(mlxsw_pci, sdq,
707722
wqe_counter, q->cq.v, ncqe);
708723

0 commit comments

Comments
 (0)