forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/infiniband/hw/bnxt_re/qplib_sp.c
....@@ -36,6 +36,8 @@
3636 * Description: Slow Path Operators
3737 */
3838
39
+#define dev_fmt(fmt) "QPLIB: " fmt
40
+
3941 #include <linux/interrupt.h>
4042 #include <linux/spinlock.h>
4143 #include <linux/sched.h>
....@@ -89,7 +91,7 @@
8991 sbuf = bnxt_qplib_rcfw_alloc_sbuf(rcfw, sizeof(*sb));
9092 if (!sbuf) {
9193 dev_err(&rcfw->pdev->dev,
92
- "QPLIB: SP: QUERY_FUNC alloc side buffer failed");
94
+ "SP: QUERY_FUNC alloc side buffer failed\n");
9395 return -ENOMEM;
9496 }
9597
....@@ -117,7 +119,8 @@
117119 * reporting the max number
118120 */
119121 attr->max_qp_wqes -= BNXT_QPLIB_RESERVED_QP_WRS;
120
- attr->max_qp_sges = sb->max_sge;
122
+ attr->max_qp_sges = bnxt_qplib_is_chip_gen_p5(rcfw->res->cctx) ?
123
+ 6 : sb->max_sge;
121124 attr->max_cq = le32_to_cpu(sb->max_cq);
122125 attr->max_cq_wqes = le32_to_cpu(sb->max_cqe);
123126 attr->max_cq_sges = attr->max_qp_sges;
....@@ -129,14 +132,19 @@
129132 attr->max_raw_ethy_qp = le32_to_cpu(sb->max_raw_eth_qp);
130133 attr->max_ah = le32_to_cpu(sb->max_ah);
131134
132
- attr->max_fmr = le32_to_cpu(sb->max_fmr);
133
- attr->max_map_per_fmr = sb->max_map_per_fmr;
134
-
135135 attr->max_srq = le16_to_cpu(sb->max_srq);
136136 attr->max_srq_wqes = le32_to_cpu(sb->max_srq_wr) - 1;
137137 attr->max_srq_sges = sb->max_srq_sge;
138
- /* Bono only reports 1 PKEY for now, but it can support > 1 */
139138 attr->max_pkey = le32_to_cpu(sb->max_pkeys);
139
+ /*
140
+ * Some versions of FW reports more than 0xFFFF.
141
+ * Restrict it for now to 0xFFFF to avoid
142
+ * reporting trucated value
143
+ */
144
+ if (attr->max_pkey > 0xFFFF) {
145
+ /* ib_port_attr::pkey_tbl_len is u16 */
146
+ attr->max_pkey = 0xFFFF;
147
+ }
140148
141149 attr->max_inline_data = le32_to_cpu(sb->max_inline_data);
142150 attr->l2_db_size = (sb->l2_db_space_size + 1) *
....@@ -186,8 +194,7 @@
186194 (void *)&resp,
187195 NULL, 0);
188196 if (rc) {
189
- dev_err(&res->pdev->dev,
190
- "QPLIB: Failed to set function resources");
197
+ dev_err(&res->pdev->dev, "Failed to set function resources\n");
191198 }
192199 return rc;
193200 }
....@@ -199,16 +206,16 @@
199206 {
200207 if (index >= sgid_tbl->max) {
201208 dev_err(&res->pdev->dev,
202
- "QPLIB: Index %d exceeded SGID table max (%d)",
209
+ "Index %d exceeded SGID table max (%d)\n",
203210 index, sgid_tbl->max);
204211 return -EINVAL;
205212 }
206
- memcpy(gid, &sgid_tbl->tbl[index], sizeof(*gid));
213
+ memcpy(gid, &sgid_tbl->tbl[index].gid, sizeof(*gid));
207214 return 0;
208215 }
209216
210217 int bnxt_qplib_del_sgid(struct bnxt_qplib_sgid_tbl *sgid_tbl,
211
- struct bnxt_qplib_gid *gid, bool update)
218
+ struct bnxt_qplib_gid *gid, u16 vlan_id, bool update)
212219 {
213220 struct bnxt_qplib_res *res = to_bnxt_qplib(sgid_tbl,
214221 struct bnxt_qplib_res,
....@@ -217,21 +224,21 @@
217224 int index;
218225
219226 if (!sgid_tbl) {
220
- dev_err(&res->pdev->dev, "QPLIB: SGID table not allocated");
227
+ dev_err(&res->pdev->dev, "SGID table not allocated\n");
221228 return -EINVAL;
222229 }
223230 /* Do we need a sgid_lock here? */
224231 if (!sgid_tbl->active) {
225
- dev_err(&res->pdev->dev,
226
- "QPLIB: SGID table has no active entries");
232
+ dev_err(&res->pdev->dev, "SGID table has no active entries\n");
227233 return -ENOMEM;
228234 }
229235 for (index = 0; index < sgid_tbl->max; index++) {
230
- if (!memcmp(&sgid_tbl->tbl[index], gid, sizeof(*gid)))
236
+ if (!memcmp(&sgid_tbl->tbl[index].gid, gid, sizeof(*gid)) &&
237
+ vlan_id == sgid_tbl->tbl[index].vlan_id)
231238 break;
232239 }
233240 if (index == sgid_tbl->max) {
234
- dev_warn(&res->pdev->dev, "GID not found in the SGID table");
241
+ dev_warn(&res->pdev->dev, "GID not found in the SGID table\n");
235242 return 0;
236243 }
237244 /* Remove GID from the SGID table */
....@@ -244,7 +251,7 @@
244251 RCFW_CMD_PREP(req, DELETE_GID, cmd_flags);
245252 if (sgid_tbl->hw_id[index] == 0xFFFF) {
246253 dev_err(&res->pdev->dev,
247
- "QPLIB: GID entry contains an invalid HW id");
254
+ "GID entry contains an invalid HW id\n");
248255 return -EINVAL;
249256 }
250257 req.gid_index = cpu_to_le16(sgid_tbl->hw_id[index]);
....@@ -253,12 +260,13 @@
253260 if (rc)
254261 return rc;
255262 }
256
- memcpy(&sgid_tbl->tbl[index], &bnxt_qplib_gid_zero,
263
+ memcpy(&sgid_tbl->tbl[index].gid, &bnxt_qplib_gid_zero,
257264 sizeof(bnxt_qplib_gid_zero));
265
+ sgid_tbl->tbl[index].vlan_id = 0xFFFF;
258266 sgid_tbl->vlan[index] = 0;
259267 sgid_tbl->active--;
260268 dev_dbg(&res->pdev->dev,
261
- "QPLIB: SGID deleted hw_id[0x%x] = 0x%x active = 0x%x",
269
+ "SGID deleted hw_id[0x%x] = 0x%x active = 0x%x\n",
262270 index, sgid_tbl->hw_id[index], sgid_tbl->active);
263271 sgid_tbl->hw_id[index] = (u16)-1;
264272
....@@ -277,20 +285,20 @@
277285 int i, free_idx;
278286
279287 if (!sgid_tbl) {
280
- dev_err(&res->pdev->dev, "QPLIB: SGID table not allocated");
288
+ dev_err(&res->pdev->dev, "SGID table not allocated\n");
281289 return -EINVAL;
282290 }
283291 /* Do we need a sgid_lock here? */
284292 if (sgid_tbl->active == sgid_tbl->max) {
285
- dev_err(&res->pdev->dev, "QPLIB: SGID table is full");
293
+ dev_err(&res->pdev->dev, "SGID table is full\n");
286294 return -ENOMEM;
287295 }
288296 free_idx = sgid_tbl->max;
289297 for (i = 0; i < sgid_tbl->max; i++) {
290
- if (!memcmp(&sgid_tbl->tbl[i], gid, sizeof(*gid))) {
298
+ if (!memcmp(&sgid_tbl->tbl[i], gid, sizeof(*gid)) &&
299
+ sgid_tbl->tbl[i].vlan_id == vlan_id) {
291300 dev_dbg(&res->pdev->dev,
292
- "QPLIB: SGID entry already exist in entry %d!",
293
- i);
301
+ "SGID entry already exist in entry %d!\n", i);
294302 *index = i;
295303 return -EALREADY;
296304 } else if (!memcmp(&sgid_tbl->tbl[i], &bnxt_qplib_gid_zero,
....@@ -301,7 +309,7 @@
301309 }
302310 if (free_idx == sgid_tbl->max) {
303311 dev_err(&res->pdev->dev,
304
- "QPLIB: SGID table is FULL but count is not MAX??");
312
+ "SGID table is FULL but count is not MAX??\n");
305313 return -ENOMEM;
306314 }
307315 if (update) {
....@@ -343,12 +351,13 @@
343351 }
344352 /* Add GID to the sgid_tbl */
345353 memcpy(&sgid_tbl->tbl[free_idx], gid, sizeof(*gid));
354
+ sgid_tbl->tbl[free_idx].vlan_id = vlan_id;
346355 sgid_tbl->active++;
347356 if (vlan_id != 0xFFFF)
348357 sgid_tbl->vlan[free_idx] = 1;
349358
350359 dev_dbg(&res->pdev->dev,
351
- "QPLIB: SGID added hw_id[0x%x] = 0x%x active = 0x%x",
360
+ "SGID added hw_id[0x%x] = 0x%x active = 0x%x\n",
352361 free_idx, sgid_tbl->hw_id[free_idx], sgid_tbl->active);
353362
354363 *index = free_idx;
....@@ -404,7 +413,7 @@
404413 }
405414 if (index >= pkey_tbl->max) {
406415 dev_err(&res->pdev->dev,
407
- "QPLIB: Index %d exceeded PKEY table max (%d)",
416
+ "Index %d exceeded PKEY table max (%d)\n",
408417 index, pkey_tbl->max);
409418 return -EINVAL;
410419 }
....@@ -419,14 +428,13 @@
419428 int i, rc = 0;
420429
421430 if (!pkey_tbl) {
422
- dev_err(&res->pdev->dev, "QPLIB: PKEY table not allocated");
431
+ dev_err(&res->pdev->dev, "PKEY table not allocated\n");
423432 return -EINVAL;
424433 }
425434
426435 /* Do we need a pkey_lock here? */
427436 if (!pkey_tbl->active) {
428
- dev_err(&res->pdev->dev,
429
- "QPLIB: PKEY table has no active entries");
437
+ dev_err(&res->pdev->dev, "PKEY table has no active entries\n");
430438 return -ENOMEM;
431439 }
432440 for (i = 0; i < pkey_tbl->max; i++) {
....@@ -435,8 +443,7 @@
435443 }
436444 if (i == pkey_tbl->max) {
437445 dev_err(&res->pdev->dev,
438
- "QPLIB: PKEY 0x%04x not found in the pkey table",
439
- *pkey);
446
+ "PKEY 0x%04x not found in the pkey table\n", *pkey);
440447 return -ENOMEM;
441448 }
442449 memset(&pkey_tbl->tbl[i], 0, sizeof(*pkey));
....@@ -453,13 +460,13 @@
453460 int i, free_idx, rc = 0;
454461
455462 if (!pkey_tbl) {
456
- dev_err(&res->pdev->dev, "QPLIB: PKEY table not allocated");
463
+ dev_err(&res->pdev->dev, "PKEY table not allocated\n");
457464 return -EINVAL;
458465 }
459466
460467 /* Do we need a pkey_lock here? */
461468 if (pkey_tbl->active == pkey_tbl->max) {
462
- dev_err(&res->pdev->dev, "QPLIB: PKEY table is full");
469
+ dev_err(&res->pdev->dev, "PKEY table is full\n");
463470 return -ENOMEM;
464471 }
465472 free_idx = pkey_tbl->max;
....@@ -471,7 +478,7 @@
471478 }
472479 if (free_idx == pkey_tbl->max) {
473480 dev_err(&res->pdev->dev,
474
- "QPLIB: PKEY table is FULL but count is not MAX??");
481
+ "PKEY table is FULL but count is not MAX??\n");
475482 return -ENOMEM;
476483 }
477484 /* Add PKEY to the pkey_tbl */
....@@ -483,7 +490,8 @@
483490 }
484491
485492 /* AH */
486
-int bnxt_qplib_create_ah(struct bnxt_qplib_res *res, struct bnxt_qplib_ah *ah)
493
+int bnxt_qplib_create_ah(struct bnxt_qplib_res *res, struct bnxt_qplib_ah *ah,
494
+ bool block)
487495 {
488496 struct bnxt_qplib_rcfw *rcfw = res->rcfw;
489497 struct cmdq_create_ah req;
....@@ -517,7 +525,7 @@
517525 req.dest_mac[2] = cpu_to_le16(temp16[2]);
518526
519527 rc = bnxt_qplib_rcfw_send_message(rcfw, (void *)&req, (void *)&resp,
520
- NULL, 1);
528
+ NULL, block);
521529 if (rc)
522530 return rc;
523531
....@@ -525,24 +533,21 @@
525533 return 0;
526534 }
527535
528
-int bnxt_qplib_destroy_ah(struct bnxt_qplib_res *res, struct bnxt_qplib_ah *ah)
536
+void bnxt_qplib_destroy_ah(struct bnxt_qplib_res *res, struct bnxt_qplib_ah *ah,
537
+ bool block)
529538 {
530539 struct bnxt_qplib_rcfw *rcfw = res->rcfw;
531540 struct cmdq_destroy_ah req;
532541 struct creq_destroy_ah_resp resp;
533542 u16 cmd_flags = 0;
534
- int rc;
535543
536544 /* Clean up the AH table in the device */
537545 RCFW_CMD_PREP(req, DESTROY_AH, cmd_flags);
538546
539547 req.ah_cid = cpu_to_le32(ah->id);
540548
541
- rc = bnxt_qplib_rcfw_send_message(rcfw, (void *)&req, (void *)&resp,
542
- NULL, 1);
543
- if (rc)
544
- return rc;
545
- return 0;
549
+ bnxt_qplib_rcfw_send_message(rcfw, (void *)&req, (void *)&resp, NULL,
550
+ block);
546551 }
547552
548553 /* MRW */
....@@ -555,8 +560,7 @@
555560 int rc;
556561
557562 if (mrw->lkey == 0xFFFFFFFF) {
558
- dev_info(&res->pdev->dev,
559
- "QPLIB: SP: Free a reserved lkey MRW");
563
+ dev_info(&res->pdev->dev, "SP: Free a reserved lkey MRW\n");
560564 return 0;
561565 }
562566
....@@ -578,7 +582,7 @@
578582
579583 /* Free the qplib's MRW memory */
580584 if (mrw->hwq.max_elements)
581
- bnxt_qplib_free_hwq(res->pdev, &mrw->hwq);
585
+ bnxt_qplib_free_hwq(res, &mrw->hwq);
582586
583587 return 0;
584588 }
....@@ -639,21 +643,22 @@
639643 if (mrw->hwq.max_elements) {
640644 mrw->va = 0;
641645 mrw->total_size = 0;
642
- bnxt_qplib_free_hwq(res->pdev, &mrw->hwq);
646
+ bnxt_qplib_free_hwq(res, &mrw->hwq);
643647 }
644648
645649 return 0;
646650 }
647651
648652 int bnxt_qplib_reg_mr(struct bnxt_qplib_res *res, struct bnxt_qplib_mrw *mr,
649
- u64 *pbl_tbl, int num_pbls, bool block, u32 buf_pg_size)
653
+ struct ib_umem *umem, int num_pbls, u32 buf_pg_size)
650654 {
651655 struct bnxt_qplib_rcfw *rcfw = res->rcfw;
652
- struct cmdq_register_mr req;
656
+ struct bnxt_qplib_hwq_attr hwq_attr = {};
657
+ struct bnxt_qplib_sg_info sginfo = {};
653658 struct creq_register_mr_resp resp;
659
+ struct cmdq_register_mr req;
654660 u16 cmd_flags = 0, level;
655
- int pg_ptrs, pages, i, rc;
656
- dma_addr_t **pbl_ptr;
661
+ int pages, rc, pg_ptrs;
657662 u32 pg_size;
658663
659664 if (num_pbls) {
....@@ -666,32 +671,29 @@
666671 pages++;
667672
668673 if (pages > MAX_PBL_LVL_1_PGS) {
669
- dev_err(&res->pdev->dev, "QPLIB: SP: Reg MR pages ");
670674 dev_err(&res->pdev->dev,
671
- "requested (0x%x) exceeded max (0x%x)",
675
+ "SP: Reg MR: pages requested (0x%x) exceeded max (0x%x)\n",
672676 pages, MAX_PBL_LVL_1_PGS);
673677 return -ENOMEM;
674678 }
675679 /* Free the hwq if it already exist, must be a rereg */
676680 if (mr->hwq.max_elements)
677
- bnxt_qplib_free_hwq(res->pdev, &mr->hwq);
678
-
679
- mr->hwq.max_elements = pages;
680
- /* Use system PAGE_SIZE */
681
- rc = bnxt_qplib_alloc_init_hwq(res->pdev, &mr->hwq, NULL, 0,
682
- &mr->hwq.max_elements,
683
- PAGE_SIZE, 0, PAGE_SIZE,
684
- HWQ_TYPE_CTX);
681
+ bnxt_qplib_free_hwq(res, &mr->hwq);
682
+ hwq_attr.res = res;
683
+ hwq_attr.depth = pages;
684
+ hwq_attr.stride = sizeof(dma_addr_t);
685
+ hwq_attr.type = HWQ_TYPE_MR;
686
+ hwq_attr.sginfo = &sginfo;
687
+ hwq_attr.sginfo->umem = umem;
688
+ hwq_attr.sginfo->npages = pages;
689
+ hwq_attr.sginfo->pgsize = buf_pg_size;
690
+ hwq_attr.sginfo->pgshft = ilog2(buf_pg_size);
691
+ rc = bnxt_qplib_alloc_init_hwq(&mr->hwq, &hwq_attr);
685692 if (rc) {
686693 dev_err(&res->pdev->dev,
687
- "SP: Reg MR memory allocation failed");
694
+ "SP: Reg MR memory allocation failed\n");
688695 return -ENOMEM;
689696 }
690
- /* Write to the hwq */
691
- pbl_ptr = (dma_addr_t **)mr->hwq.pbl_ptr;
692
- for (i = 0; i < num_pbls; i++)
693
- pbl_ptr[PTR_PG(i)][PTR_IDX(i)] =
694
- (pbl_tbl[i] & PAGE_MASK) | PTU_PTE_VALID;
695697 }
696698
697699 RCFW_CMD_PREP(req, REGISTER_MR, cmd_flags);
....@@ -703,7 +705,7 @@
703705 req.pbl = 0;
704706 pg_size = PAGE_SIZE;
705707 } else {
706
- level = mr->hwq.level + 1;
708
+ level = mr->hwq.level;
707709 req.pbl = cpu_to_le64(mr->hwq.pbl[PBL_LVL_0].pg_map_arr[0]);
708710 }
709711 pg_size = buf_pg_size ? buf_pg_size : PAGE_SIZE;
....@@ -720,7 +722,7 @@
720722 req.mr_size = cpu_to_le64(mr->total_size);
721723
722724 rc = bnxt_qplib_rcfw_send_message(rcfw, (void *)&req,
723
- (void *)&resp, NULL, block);
725
+ (void *)&resp, NULL, false);
724726 if (rc)
725727 goto fail;
726728
....@@ -728,7 +730,7 @@
728730
729731 fail:
730732 if (mr->hwq.max_elements)
731
- bnxt_qplib_free_hwq(res->pdev, &mr->hwq);
733
+ bnxt_qplib_free_hwq(res, &mr->hwq);
732734 return rc;
733735 }
734736
....@@ -736,6 +738,8 @@
736738 struct bnxt_qplib_frpl *frpl,
737739 int max_pg_ptrs)
738740 {
741
+ struct bnxt_qplib_hwq_attr hwq_attr = {};
742
+ struct bnxt_qplib_sg_info sginfo = {};
739743 int pg_ptrs, pages, rc;
740744
741745 /* Re-calculate the max to fit the HWQ allocation model */
....@@ -747,10 +751,15 @@
747751 if (pages > MAX_PBL_LVL_1_PGS)
748752 return -ENOMEM;
749753
750
- frpl->hwq.max_elements = pages;
751
- rc = bnxt_qplib_alloc_init_hwq(res->pdev, &frpl->hwq, NULL, 0,
752
- &frpl->hwq.max_elements, PAGE_SIZE, 0,
753
- PAGE_SIZE, HWQ_TYPE_CTX);
754
+ sginfo.pgsize = PAGE_SIZE;
755
+ sginfo.nopte = true;
756
+
757
+ hwq_attr.res = res;
758
+ hwq_attr.depth = pg_ptrs;
759
+ hwq_attr.stride = PAGE_SIZE;
760
+ hwq_attr.sginfo = &sginfo;
761
+ hwq_attr.type = HWQ_TYPE_CTX;
762
+ rc = bnxt_qplib_alloc_init_hwq(&frpl->hwq, &hwq_attr);
754763 if (!rc)
755764 frpl->max_pg_ptrs = pg_ptrs;
756765
....@@ -760,7 +769,7 @@
760769 int bnxt_qplib_free_fast_reg_page_list(struct bnxt_qplib_res *res,
761770 struct bnxt_qplib_frpl *frpl)
762771 {
763
- bnxt_qplib_free_hwq(res->pdev, &frpl->hwq);
772
+ bnxt_qplib_free_hwq(res, &frpl->hwq);
764773 return 0;
765774 }
766775
....@@ -794,7 +803,7 @@
794803 sbuf = bnxt_qplib_rcfw_alloc_sbuf(rcfw, sizeof(*sb));
795804 if (!sbuf) {
796805 dev_err(&rcfw->pdev->dev,
797
- "QPLIB: SP: QUERY_ROCE_STATS alloc side buffer failed");
806
+ "SP: QUERY_ROCE_STATS alloc side buffer failed\n");
798807 return -ENOMEM;
799808 }
800809
....@@ -844,6 +853,16 @@
844853 stats->res_srq_load_err = le64_to_cpu(sb->res_srq_load_err);
845854 stats->res_tx_pci_err = le64_to_cpu(sb->res_tx_pci_err);
846855 stats->res_rx_pci_err = le64_to_cpu(sb->res_rx_pci_err);
856
+ if (!rcfw->init_oos_stats) {
857
+ rcfw->oos_prev = le64_to_cpu(sb->res_oos_drop_count);
858
+ rcfw->init_oos_stats = 1;
859
+ } else {
860
+ stats->res_oos_drop_count +=
861
+ (le64_to_cpu(sb->res_oos_drop_count) -
862
+ rcfw->oos_prev) & BNXT_QPLIB_OOS_COUNT_MASK;
863
+ rcfw->oos_prev = le64_to_cpu(sb->res_oos_drop_count);
864
+ }
865
+
847866 bail:
848867 bnxt_qplib_rcfw_free_sbuf(rcfw, sbuf);
849868 return rc;