forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 958e46acc8e900e8569dd467c1af9b8d2d019394
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,7 +643,7 @@
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;
....@@ -649,10 +653,12 @@
649653 u64 *pbl_tbl, int num_pbls, bool block, 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;
654
- u16 cmd_flags = 0, level;
659
+ struct cmdq_register_mr req;
655660 int pg_ptrs, pages, i, rc;
661
+ u16 cmd_flags = 0, level;
656662 dma_addr_t **pbl_ptr;
657663 u32 pg_size;
658664
....@@ -666,25 +672,27 @@
666672 pages++;
667673
668674 if (pages > MAX_PBL_LVL_1_PGS) {
669
- dev_err(&res->pdev->dev, "QPLIB: SP: Reg MR pages ");
670675 dev_err(&res->pdev->dev,
671
- "requested (0x%x) exceeded max (0x%x)",
676
+ "SP: Reg MR: pages requested (0x%x) exceeded max (0x%x)\n",
672677 pages, MAX_PBL_LVL_1_PGS);
673678 return -ENOMEM;
674679 }
675680 /* Free the hwq if it already exist, must be a rereg */
676681 if (mr->hwq.max_elements)
677
- bnxt_qplib_free_hwq(res->pdev, &mr->hwq);
678
-
679
- mr->hwq.max_elements = pages;
682
+ bnxt_qplib_free_hwq(res, &mr->hwq);
680683 /* 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);
684
+ hwq_attr.res = res;
685
+ hwq_attr.depth = pages;
686
+ hwq_attr.stride = PAGE_SIZE;
687
+ hwq_attr.type = HWQ_TYPE_MR;
688
+ hwq_attr.sginfo = &sginfo;
689
+ hwq_attr.sginfo->npages = pages;
690
+ hwq_attr.sginfo->pgsize = PAGE_SIZE;
691
+ hwq_attr.sginfo->pgshft = PAGE_SHIFT;
692
+ rc = bnxt_qplib_alloc_init_hwq(&mr->hwq, &hwq_attr);
685693 if (rc) {
686694 dev_err(&res->pdev->dev,
687
- "SP: Reg MR memory allocation failed");
695
+ "SP: Reg MR memory allocation failed\n");
688696 return -ENOMEM;
689697 }
690698 /* Write to the hwq */
....@@ -728,7 +736,7 @@
728736
729737 fail:
730738 if (mr->hwq.max_elements)
731
- bnxt_qplib_free_hwq(res->pdev, &mr->hwq);
739
+ bnxt_qplib_free_hwq(res, &mr->hwq);
732740 return rc;
733741 }
734742
....@@ -736,6 +744,8 @@
736744 struct bnxt_qplib_frpl *frpl,
737745 int max_pg_ptrs)
738746 {
747
+ struct bnxt_qplib_hwq_attr hwq_attr = {};
748
+ struct bnxt_qplib_sg_info sginfo = {};
739749 int pg_ptrs, pages, rc;
740750
741751 /* Re-calculate the max to fit the HWQ allocation model */
....@@ -747,10 +757,15 @@
747757 if (pages > MAX_PBL_LVL_1_PGS)
748758 return -ENOMEM;
749759
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);
760
+ sginfo.pgsize = PAGE_SIZE;
761
+ sginfo.nopte = true;
762
+
763
+ hwq_attr.res = res;
764
+ hwq_attr.depth = pg_ptrs;
765
+ hwq_attr.stride = PAGE_SIZE;
766
+ hwq_attr.sginfo = &sginfo;
767
+ hwq_attr.type = HWQ_TYPE_CTX;
768
+ rc = bnxt_qplib_alloc_init_hwq(&frpl->hwq, &hwq_attr);
754769 if (!rc)
755770 frpl->max_pg_ptrs = pg_ptrs;
756771
....@@ -760,7 +775,7 @@
760775 int bnxt_qplib_free_fast_reg_page_list(struct bnxt_qplib_res *res,
761776 struct bnxt_qplib_frpl *frpl)
762777 {
763
- bnxt_qplib_free_hwq(res->pdev, &frpl->hwq);
778
+ bnxt_qplib_free_hwq(res, &frpl->hwq);
764779 return 0;
765780 }
766781
....@@ -794,7 +809,7 @@
794809 sbuf = bnxt_qplib_rcfw_alloc_sbuf(rcfw, sizeof(*sb));
795810 if (!sbuf) {
796811 dev_err(&rcfw->pdev->dev,
797
- "QPLIB: SP: QUERY_ROCE_STATS alloc side buffer failed");
812
+ "SP: QUERY_ROCE_STATS alloc side buffer failed\n");
798813 return -ENOMEM;
799814 }
800815
....@@ -844,6 +859,16 @@
844859 stats->res_srq_load_err = le64_to_cpu(sb->res_srq_load_err);
845860 stats->res_tx_pci_err = le64_to_cpu(sb->res_tx_pci_err);
846861 stats->res_rx_pci_err = le64_to_cpu(sb->res_rx_pci_err);
862
+ if (!rcfw->init_oos_stats) {
863
+ rcfw->oos_prev = le64_to_cpu(sb->res_oos_drop_count);
864
+ rcfw->init_oos_stats = 1;
865
+ } else {
866
+ stats->res_oos_drop_count +=
867
+ (le64_to_cpu(sb->res_oos_drop_count) -
868
+ rcfw->oos_prev) & BNXT_QPLIB_OOS_COUNT_MASK;
869
+ rcfw->oos_prev = le64_to_cpu(sb->res_oos_drop_count);
870
+ }
871
+
847872 bail:
848873 bnxt_qplib_rcfw_free_sbuf(rcfw, sbuf);
849874 return rc;