hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/infiniband/hw/bnxt_re/main.c
....@@ -67,7 +67,7 @@
6767 #include "hw_counters.h"
6868
6969 static char version[] =
70
- BNXT_RE_DESC " v" ROCE_DRV_MODULE_VERSION "\n";
70
+ BNXT_RE_DESC "\n";
7171
7272 MODULE_AUTHOR("Eddie Wai <eddie.wai@broadcom.com>");
7373 MODULE_DESCRIPTION(BNXT_RE_DESC " Driver");
....@@ -78,7 +78,58 @@
7878 /* Mutex to protect the list of bnxt_re devices added */
7979 static DEFINE_MUTEX(bnxt_re_dev_lock);
8080 static struct workqueue_struct *bnxt_re_wq;
81
-static void bnxt_re_ib_unreg(struct bnxt_re_dev *rdev);
81
+static void bnxt_re_remove_device(struct bnxt_re_dev *rdev);
82
+static void bnxt_re_dealloc_driver(struct ib_device *ib_dev);
83
+static void bnxt_re_stop_irq(void *handle);
84
+
85
+static void bnxt_re_set_drv_mode(struct bnxt_re_dev *rdev, u8 mode)
86
+{
87
+ struct bnxt_qplib_chip_ctx *cctx;
88
+
89
+ cctx = rdev->chip_ctx;
90
+ cctx->modes.wqe_mode = bnxt_qplib_is_chip_gen_p5(rdev->chip_ctx) ?
91
+ mode : BNXT_QPLIB_WQE_MODE_STATIC;
92
+}
93
+
94
+static void bnxt_re_destroy_chip_ctx(struct bnxt_re_dev *rdev)
95
+{
96
+ struct bnxt_qplib_chip_ctx *chip_ctx;
97
+
98
+ if (!rdev->chip_ctx)
99
+ return;
100
+ chip_ctx = rdev->chip_ctx;
101
+ rdev->chip_ctx = NULL;
102
+ rdev->rcfw.res = NULL;
103
+ rdev->qplib_res.cctx = NULL;
104
+ rdev->qplib_res.pdev = NULL;
105
+ rdev->qplib_res.netdev = NULL;
106
+ kfree(chip_ctx);
107
+}
108
+
109
+static int bnxt_re_setup_chip_ctx(struct bnxt_re_dev *rdev, u8 wqe_mode)
110
+{
111
+ struct bnxt_qplib_chip_ctx *chip_ctx;
112
+ struct bnxt_en_dev *en_dev;
113
+ struct bnxt *bp;
114
+
115
+ en_dev = rdev->en_dev;
116
+ bp = netdev_priv(en_dev->net);
117
+
118
+ chip_ctx = kzalloc(sizeof(*chip_ctx), GFP_KERNEL);
119
+ if (!chip_ctx)
120
+ return -ENOMEM;
121
+ chip_ctx->chip_num = bp->chip_num;
122
+ chip_ctx->hw_stats_size = bp->hw_ring_stats_size;
123
+
124
+ rdev->chip_ctx = chip_ctx;
125
+ /* rest members to follow eventually */
126
+
127
+ rdev->qplib_res.cctx = rdev->chip_ctx;
128
+ rdev->rcfw.res = &rdev->qplib_res;
129
+
130
+ bnxt_re_set_drv_mode(rdev, wqe_mode);
131
+ return 0;
132
+}
82133
83134 /* SR-IOV helper functions */
84135
....@@ -96,61 +147,76 @@
96147 * reserved for the function. The driver may choose to allocate fewer
97148 * resources than the firmware maximum.
98149 */
150
+static void bnxt_re_limit_pf_res(struct bnxt_re_dev *rdev)
151
+{
152
+ struct bnxt_qplib_dev_attr *attr;
153
+ struct bnxt_qplib_ctx *ctx;
154
+ int i;
155
+
156
+ attr = &rdev->dev_attr;
157
+ ctx = &rdev->qplib_ctx;
158
+
159
+ ctx->qpc_count = min_t(u32, BNXT_RE_MAX_QPC_COUNT,
160
+ attr->max_qp);
161
+ ctx->mrw_count = BNXT_RE_MAX_MRW_COUNT_256K;
162
+ /* Use max_mr from fw since max_mrw does not get set */
163
+ ctx->mrw_count = min_t(u32, ctx->mrw_count, attr->max_mr);
164
+ ctx->srqc_count = min_t(u32, BNXT_RE_MAX_SRQC_COUNT,
165
+ attr->max_srq);
166
+ ctx->cq_count = min_t(u32, BNXT_RE_MAX_CQ_COUNT, attr->max_cq);
167
+ if (!bnxt_qplib_is_chip_gen_p5(rdev->chip_ctx))
168
+ for (i = 0; i < MAX_TQM_ALLOC_REQ; i++)
169
+ rdev->qplib_ctx.tqm_ctx.qcount[i] =
170
+ rdev->dev_attr.tqm_alloc_reqs[i];
171
+}
172
+
173
+static void bnxt_re_limit_vf_res(struct bnxt_qplib_ctx *qplib_ctx, u32 num_vf)
174
+{
175
+ struct bnxt_qplib_vf_res *vf_res;
176
+ u32 mrws = 0;
177
+ u32 vf_pct;
178
+ u32 nvfs;
179
+
180
+ vf_res = &qplib_ctx->vf_res;
181
+ /*
182
+ * Reserve a set of resources for the PF. Divide the remaining
183
+ * resources among the VFs
184
+ */
185
+ vf_pct = 100 - BNXT_RE_PCT_RSVD_FOR_PF;
186
+ nvfs = num_vf;
187
+ num_vf = 100 * num_vf;
188
+ vf_res->max_qp_per_vf = (qplib_ctx->qpc_count * vf_pct) / num_vf;
189
+ vf_res->max_srq_per_vf = (qplib_ctx->srqc_count * vf_pct) / num_vf;
190
+ vf_res->max_cq_per_vf = (qplib_ctx->cq_count * vf_pct) / num_vf;
191
+ /*
192
+ * The driver allows many more MRs than other resources. If the
193
+ * firmware does also, then reserve a fixed amount for the PF and
194
+ * divide the rest among VFs. VFs may use many MRs for NFS
195
+ * mounts, ISER, NVME applications, etc. If the firmware severely
196
+ * restricts the number of MRs, then let PF have half and divide
197
+ * the rest among VFs, as for the other resource types.
198
+ */
199
+ if (qplib_ctx->mrw_count < BNXT_RE_MAX_MRW_COUNT_64K) {
200
+ mrws = qplib_ctx->mrw_count * vf_pct;
201
+ nvfs = num_vf;
202
+ } else {
203
+ mrws = qplib_ctx->mrw_count - BNXT_RE_RESVD_MR_FOR_PF;
204
+ }
205
+ vf_res->max_mrw_per_vf = (mrws / nvfs);
206
+ vf_res->max_gid_per_vf = BNXT_RE_MAX_GID_PER_VF;
207
+}
208
+
99209 static void bnxt_re_set_resource_limits(struct bnxt_re_dev *rdev)
100210 {
101
- u32 vf_qps = 0, vf_srqs = 0, vf_cqs = 0, vf_mrws = 0, vf_gids = 0;
102
- u32 i;
103
- u32 vf_pct;
104211 u32 num_vfs;
105
- struct bnxt_qplib_dev_attr *dev_attr = &rdev->dev_attr;
106212
107
- rdev->qplib_ctx.qpc_count = min_t(u32, BNXT_RE_MAX_QPC_COUNT,
108
- dev_attr->max_qp);
213
+ memset(&rdev->qplib_ctx.vf_res, 0, sizeof(struct bnxt_qplib_vf_res));
214
+ bnxt_re_limit_pf_res(rdev);
109215
110
- rdev->qplib_ctx.mrw_count = BNXT_RE_MAX_MRW_COUNT_256K;
111
- /* Use max_mr from fw since max_mrw does not get set */
112
- rdev->qplib_ctx.mrw_count = min_t(u32, rdev->qplib_ctx.mrw_count,
113
- dev_attr->max_mr);
114
- rdev->qplib_ctx.srqc_count = min_t(u32, BNXT_RE_MAX_SRQC_COUNT,
115
- dev_attr->max_srq);
116
- rdev->qplib_ctx.cq_count = min_t(u32, BNXT_RE_MAX_CQ_COUNT,
117
- dev_attr->max_cq);
118
-
119
- for (i = 0; i < MAX_TQM_ALLOC_REQ; i++)
120
- rdev->qplib_ctx.tqm_count[i] =
121
- rdev->dev_attr.tqm_alloc_reqs[i];
122
-
123
- if (rdev->num_vfs) {
124
- /*
125
- * Reserve a set of resources for the PF. Divide the remaining
126
- * resources among the VFs
127
- */
128
- vf_pct = 100 - BNXT_RE_PCT_RSVD_FOR_PF;
129
- num_vfs = 100 * rdev->num_vfs;
130
- vf_qps = (rdev->qplib_ctx.qpc_count * vf_pct) / num_vfs;
131
- vf_srqs = (rdev->qplib_ctx.srqc_count * vf_pct) / num_vfs;
132
- vf_cqs = (rdev->qplib_ctx.cq_count * vf_pct) / num_vfs;
133
- /*
134
- * The driver allows many more MRs than other resources. If the
135
- * firmware does also, then reserve a fixed amount for the PF
136
- * and divide the rest among VFs. VFs may use many MRs for NFS
137
- * mounts, ISER, NVME applications, etc. If the firmware
138
- * severely restricts the number of MRs, then let PF have
139
- * half and divide the rest among VFs, as for the other
140
- * resource types.
141
- */
142
- if (rdev->qplib_ctx.mrw_count < BNXT_RE_MAX_MRW_COUNT_64K)
143
- vf_mrws = rdev->qplib_ctx.mrw_count * vf_pct / num_vfs;
144
- else
145
- vf_mrws = (rdev->qplib_ctx.mrw_count -
146
- BNXT_RE_RESVD_MR_FOR_PF) / rdev->num_vfs;
147
- vf_gids = BNXT_RE_MAX_GID_PER_VF;
148
- }
149
- rdev->qplib_ctx.vf_res.max_mrw_per_vf = vf_mrws;
150
- rdev->qplib_ctx.vf_res.max_gid_per_vf = vf_gids;
151
- rdev->qplib_ctx.vf_res.max_qp_per_vf = vf_qps;
152
- rdev->qplib_ctx.vf_res.max_srq_per_vf = vf_srqs;
153
- rdev->qplib_ctx.vf_res.max_cq_per_vf = vf_cqs;
216
+ num_vfs = bnxt_qplib_is_chip_gen_p5(rdev->chip_ctx) ?
217
+ BNXT_RE_GEN_P5_MAX_VF : rdev->num_vfs;
218
+ if (num_vfs)
219
+ bnxt_re_limit_vf_res(&rdev->qplib_ctx, num_vfs);
154220 }
155221
156222 /* for handling bnxt_en callbacks later */
....@@ -170,9 +236,11 @@
170236 return;
171237
172238 rdev->num_vfs = num_vfs;
173
- bnxt_re_set_resource_limits(rdev);
174
- bnxt_qplib_set_func_resources(&rdev->qplib_res, &rdev->rcfw,
175
- &rdev->qplib_ctx);
239
+ if (!bnxt_qplib_is_chip_gen_p5(rdev->chip_ctx)) {
240
+ bnxt_re_set_resource_limits(rdev);
241
+ bnxt_qplib_set_func_resources(&rdev->qplib_res, &rdev->rcfw,
242
+ &rdev->qplib_ctx);
243
+ }
176244 }
177245
178246 static void bnxt_re_shutdown(void *p)
....@@ -181,8 +249,10 @@
181249
182250 if (!rdev)
183251 return;
184
-
185
- bnxt_re_ib_unreg(rdev);
252
+ ASSERT_RTNL();
253
+ /* Release the MSIx vectors before queuing unregister */
254
+ bnxt_re_stop_irq(rdev);
255
+ ib_unregister_device_queued(&rdev->ibdev);
186256 }
187257
188258 static void bnxt_re_stop_irq(void *handle)
....@@ -214,7 +284,7 @@
214284 * to f/w will timeout and that will set the
215285 * timeout bit.
216286 */
217
- dev_err(rdev_to_dev(rdev), "Failed to re-start IRQs\n");
287
+ ibdev_err(&rdev->ibdev, "Failed to re-start IRQs\n");
218288 return;
219289 }
220290
....@@ -224,15 +294,21 @@
224294 for (indx = 0; indx < rdev->num_msix; indx++)
225295 rdev->msix_entries[indx].vector = ent[indx].vector;
226296
227
- bnxt_qplib_rcfw_start_irq(rcfw, msix_ent[BNXT_RE_AEQ_IDX].vector,
228
- false);
297
+ rc = bnxt_qplib_rcfw_start_irq(rcfw, msix_ent[BNXT_RE_AEQ_IDX].vector,
298
+ false);
299
+ if (rc) {
300
+ ibdev_warn(&rdev->ibdev, "Failed to reinit CREQ\n");
301
+ return;
302
+ }
229303 for (indx = BNXT_RE_NQ_IDX ; indx < rdev->num_msix; indx++) {
230304 nq = &rdev->nq[indx - 1];
231305 rc = bnxt_qplib_nq_start_irq(nq, indx - 1,
232306 msix_ent[indx].vector, false);
233
- if (rc)
234
- dev_warn(rdev_to_dev(rdev),
235
- "Failed to reinit NQ index %d\n", indx - 1);
307
+ if (rc) {
308
+ ibdev_warn(&rdev->ibdev, "Failed to reinit NQ index %d\n",
309
+ indx - 1);
310
+ return;
311
+ }
236312 }
237313 }
238314
....@@ -278,6 +354,7 @@
278354
279355 rc = en_dev->en_ops->bnxt_register_device(en_dev, BNXT_ROCE_ULP,
280356 &bnxt_re_ulp_ops, rdev);
357
+ rdev->qplib_res.pdev = rdev->en_dev->pdev;
281358 return rc;
282359 }
283360
....@@ -317,9 +394,9 @@
317394 goto done;
318395 }
319396 if (num_msix_got != num_msix_want) {
320
- dev_warn(rdev_to_dev(rdev),
321
- "Requested %d MSI-X vectors, got %d\n",
322
- num_msix_want, num_msix_got);
397
+ ibdev_warn(&rdev->ibdev,
398
+ "Requested %d MSI-X vectors, got %d\n",
399
+ num_msix_want, num_msix_got);
323400 }
324401 rdev->num_msix = num_msix_got;
325402 done:
....@@ -345,7 +422,8 @@
345422 fw_msg->timeout = timeout;
346423 }
347424
348
-static int bnxt_re_net_ring_free(struct bnxt_re_dev *rdev, u16 fw_ring_id)
425
+static int bnxt_re_net_ring_free(struct bnxt_re_dev *rdev,
426
+ u16 fw_ring_id, int type)
349427 {
350428 struct bnxt_en_dev *en_dev = rdev->en_dev;
351429 struct hwrm_ring_free_input req = {0};
....@@ -359,20 +437,20 @@
359437 memset(&fw_msg, 0, sizeof(fw_msg));
360438
361439 bnxt_re_init_hwrm_hdr(rdev, (void *)&req, HWRM_RING_FREE, -1, -1);
362
- req.ring_type = RING_ALLOC_REQ_RING_TYPE_L2_CMPL;
440
+ req.ring_type = type;
363441 req.ring_id = cpu_to_le16(fw_ring_id);
364442 bnxt_re_fill_fw_msg(&fw_msg, (void *)&req, sizeof(req), (void *)&resp,
365443 sizeof(resp), DFLT_HWRM_CMD_TIMEOUT);
366444 rc = en_dev->en_ops->bnxt_send_fw_msg(en_dev, BNXT_ROCE_ULP, &fw_msg);
367445 if (rc)
368
- dev_err(rdev_to_dev(rdev),
369
- "Failed to free HW ring:%d :%#x", req.ring_id, rc);
446
+ ibdev_err(&rdev->ibdev, "Failed to free HW ring:%d :%#x",
447
+ req.ring_id, rc);
370448 return rc;
371449 }
372450
373
-static int bnxt_re_net_ring_alloc(struct bnxt_re_dev *rdev, dma_addr_t *dma_arr,
374
- int pages, int type, u32 ring_mask,
375
- u32 map_index, u16 *fw_ring_id)
451
+static int bnxt_re_net_ring_alloc(struct bnxt_re_dev *rdev,
452
+ struct bnxt_re_ring_attr *ring_attr,
453
+ u16 *fw_ring_id)
376454 {
377455 struct bnxt_en_dev *en_dev = rdev->en_dev;
378456 struct hwrm_ring_alloc_input req = {0};
....@@ -386,18 +464,18 @@
386464 memset(&fw_msg, 0, sizeof(fw_msg));
387465 bnxt_re_init_hwrm_hdr(rdev, (void *)&req, HWRM_RING_ALLOC, -1, -1);
388466 req.enables = 0;
389
- req.page_tbl_addr = cpu_to_le64(dma_arr[0]);
390
- if (pages > 1) {
467
+ req.page_tbl_addr = cpu_to_le64(ring_attr->dma_arr[0]);
468
+ if (ring_attr->pages > 1) {
391469 /* Page size is in log2 units */
392470 req.page_size = BNXT_PAGE_SHIFT;
393471 req.page_tbl_depth = 1;
394472 }
395473 req.fbo = 0;
396474 /* Association of ring index with doorbell index and MSIX number */
397
- req.logical_id = cpu_to_le16(map_index);
398
- req.length = cpu_to_le32(ring_mask + 1);
399
- req.ring_type = RING_ALLOC_REQ_RING_TYPE_L2_CMPL;
400
- req.int_mode = RING_ALLOC_REQ_INT_MODE_MSIX;
475
+ req.logical_id = cpu_to_le16(ring_attr->lrid);
476
+ req.length = cpu_to_le32(ring_attr->depth + 1);
477
+ req.ring_type = ring_attr->type;
478
+ req.int_mode = ring_attr->mode;
401479 bnxt_re_fill_fw_msg(&fw_msg, (void *)&req, sizeof(req), (void *)&resp,
402480 sizeof(resp), DFLT_HWRM_CMD_TIMEOUT);
403481 rc = en_dev->en_ops->bnxt_send_fw_msg(en_dev, BNXT_ROCE_ULP, &fw_msg);
....@@ -426,8 +504,8 @@
426504 sizeof(req), DFLT_HWRM_CMD_TIMEOUT);
427505 rc = en_dev->en_ops->bnxt_send_fw_msg(en_dev, BNXT_ROCE_ULP, &fw_msg);
428506 if (rc)
429
- dev_err(rdev_to_dev(rdev),
430
- "Failed to free HW stats context %#x", rc);
507
+ ibdev_err(&rdev->ibdev, "Failed to free HW stats context %#x",
508
+ rc);
431509
432510 return rc;
433511 }
....@@ -436,6 +514,7 @@
436514 dma_addr_t dma_map,
437515 u32 *fw_stats_ctx_id)
438516 {
517
+ struct bnxt_qplib_chip_ctx *chip_ctx = rdev->chip_ctx;
439518 struct hwrm_stat_ctx_alloc_output resp = {0};
440519 struct hwrm_stat_ctx_alloc_input req = {0};
441520 struct bnxt_en_dev *en_dev = rdev->en_dev;
....@@ -452,6 +531,7 @@
452531 bnxt_re_init_hwrm_hdr(rdev, (void *)&req, HWRM_STAT_CTX_ALLOC, -1, -1);
453532 req.update_period_ms = cpu_to_le32(1000);
454533 req.stats_dma_addr = cpu_to_le64(dma_map);
534
+ req.stats_dma_length = cpu_to_le16(chip_ctx->hw_stats_size);
455535 req.stat_ctx_flags = STAT_CTX_ALLOC_REQ_STAT_CTX_FLAGS_ROCE;
456536 bnxt_re_fill_fw_msg(&fw_msg, (void *)&req, sizeof(req), (void *)&resp,
457537 sizeof(resp), DFLT_HWRM_CMD_TIMEOUT);
....@@ -481,17 +561,12 @@
481561
482562 static struct bnxt_re_dev *bnxt_re_from_netdev(struct net_device *netdev)
483563 {
484
- struct bnxt_re_dev *rdev;
564
+ struct ib_device *ibdev =
565
+ ib_device_get_by_netdev(netdev, RDMA_DRIVER_BNXT_RE);
566
+ if (!ibdev)
567
+ return NULL;
485568
486
- rcu_read_lock();
487
- list_for_each_entry_rcu(rdev, &bnxt_re_dev_list, list) {
488
- if (rdev->netdev == netdev) {
489
- rcu_read_unlock();
490
- return rdev;
491
- }
492
- }
493
- rcu_read_unlock();
494
- return NULL;
569
+ return container_of(ibdev, struct bnxt_re_dev, ibdev);
495570 }
496571
497572 static void bnxt_re_dev_unprobe(struct net_device *netdev,
....@@ -535,31 +610,106 @@
535610 return en_dev;
536611 }
537612
538
-static void bnxt_re_unregister_ib(struct bnxt_re_dev *rdev)
613
+static ssize_t hw_rev_show(struct device *device, struct device_attribute *attr,
614
+ char *buf)
539615 {
540
- ib_unregister_device(&rdev->ibdev);
616
+ struct bnxt_re_dev *rdev =
617
+ rdma_device_to_drv_device(device, struct bnxt_re_dev, ibdev);
618
+
619
+ return scnprintf(buf, PAGE_SIZE, "0x%x\n", rdev->en_dev->pdev->vendor);
541620 }
621
+static DEVICE_ATTR_RO(hw_rev);
622
+
623
+static ssize_t hca_type_show(struct device *device,
624
+ struct device_attribute *attr, char *buf)
625
+{
626
+ struct bnxt_re_dev *rdev =
627
+ rdma_device_to_drv_device(device, struct bnxt_re_dev, ibdev);
628
+
629
+ return scnprintf(buf, PAGE_SIZE, "%s\n", rdev->ibdev.node_desc);
630
+}
631
+static DEVICE_ATTR_RO(hca_type);
632
+
633
+static struct attribute *bnxt_re_attributes[] = {
634
+ &dev_attr_hw_rev.attr,
635
+ &dev_attr_hca_type.attr,
636
+ NULL
637
+};
638
+
639
+static const struct attribute_group bnxt_re_dev_attr_group = {
640
+ .attrs = bnxt_re_attributes,
641
+};
642
+
643
+static const struct ib_device_ops bnxt_re_dev_ops = {
644
+ .owner = THIS_MODULE,
645
+ .driver_id = RDMA_DRIVER_BNXT_RE,
646
+ .uverbs_abi_ver = BNXT_RE_ABI_VERSION,
647
+
648
+ .add_gid = bnxt_re_add_gid,
649
+ .alloc_hw_stats = bnxt_re_ib_alloc_hw_stats,
650
+ .alloc_mr = bnxt_re_alloc_mr,
651
+ .alloc_pd = bnxt_re_alloc_pd,
652
+ .alloc_ucontext = bnxt_re_alloc_ucontext,
653
+ .create_ah = bnxt_re_create_ah,
654
+ .create_cq = bnxt_re_create_cq,
655
+ .create_qp = bnxt_re_create_qp,
656
+ .create_srq = bnxt_re_create_srq,
657
+ .dealloc_driver = bnxt_re_dealloc_driver,
658
+ .dealloc_pd = bnxt_re_dealloc_pd,
659
+ .dealloc_ucontext = bnxt_re_dealloc_ucontext,
660
+ .del_gid = bnxt_re_del_gid,
661
+ .dereg_mr = bnxt_re_dereg_mr,
662
+ .destroy_ah = bnxt_re_destroy_ah,
663
+ .destroy_cq = bnxt_re_destroy_cq,
664
+ .destroy_qp = bnxt_re_destroy_qp,
665
+ .destroy_srq = bnxt_re_destroy_srq,
666
+ .get_dev_fw_str = bnxt_re_query_fw_str,
667
+ .get_dma_mr = bnxt_re_get_dma_mr,
668
+ .get_hw_stats = bnxt_re_ib_get_hw_stats,
669
+ .get_link_layer = bnxt_re_get_link_layer,
670
+ .get_port_immutable = bnxt_re_get_port_immutable,
671
+ .map_mr_sg = bnxt_re_map_mr_sg,
672
+ .mmap = bnxt_re_mmap,
673
+ .modify_ah = bnxt_re_modify_ah,
674
+ .modify_qp = bnxt_re_modify_qp,
675
+ .modify_srq = bnxt_re_modify_srq,
676
+ .poll_cq = bnxt_re_poll_cq,
677
+ .post_recv = bnxt_re_post_recv,
678
+ .post_send = bnxt_re_post_send,
679
+ .post_srq_recv = bnxt_re_post_srq_recv,
680
+ .query_ah = bnxt_re_query_ah,
681
+ .query_device = bnxt_re_query_device,
682
+ .query_pkey = bnxt_re_query_pkey,
683
+ .query_port = bnxt_re_query_port,
684
+ .query_qp = bnxt_re_query_qp,
685
+ .query_srq = bnxt_re_query_srq,
686
+ .reg_user_mr = bnxt_re_reg_user_mr,
687
+ .req_notify_cq = bnxt_re_req_notify_cq,
688
+ INIT_RDMA_OBJ_SIZE(ib_ah, bnxt_re_ah, ib_ah),
689
+ INIT_RDMA_OBJ_SIZE(ib_cq, bnxt_re_cq, ib_cq),
690
+ INIT_RDMA_OBJ_SIZE(ib_pd, bnxt_re_pd, ib_pd),
691
+ INIT_RDMA_OBJ_SIZE(ib_srq, bnxt_re_srq, ib_srq),
692
+ INIT_RDMA_OBJ_SIZE(ib_ucontext, bnxt_re_ucontext, ib_uctx),
693
+};
542694
543695 static int bnxt_re_register_ib(struct bnxt_re_dev *rdev)
544696 {
545697 struct ib_device *ibdev = &rdev->ibdev;
698
+ int ret;
546699
547700 /* ib device init */
548
- ibdev->owner = THIS_MODULE;
549701 ibdev->node_type = RDMA_NODE_IB_CA;
550
- strlcpy(ibdev->name, "bnxt_re%d", IB_DEVICE_NAME_MAX);
551702 strlcpy(ibdev->node_desc, BNXT_RE_DESC " HCA",
552703 strlen(BNXT_RE_DESC) + 5);
553704 ibdev->phys_port_cnt = 1;
554705
555706 bnxt_qplib_get_guid(rdev->netdev->dev_addr, (u8 *)&ibdev->node_guid);
556707
557
- ibdev->num_comp_vectors = 1;
708
+ ibdev->num_comp_vectors = rdev->num_msix - 1;
558709 ibdev->dev.parent = &rdev->en_dev->pdev->dev;
559710 ibdev->local_dma_lkey = BNXT_QPLIB_RSVD_LKEY;
560711
561712 /* User space */
562
- ibdev->uverbs_abi_ver = BNXT_RE_ABI_VERSION;
563713 ibdev->uverbs_cmd_mask =
564714 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
565715 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
....@@ -587,99 +737,26 @@
587737 (1ull << IB_USER_VERBS_CMD_DESTROY_AH);
588738 /* POLL_CQ and REQ_NOTIFY_CQ is directly handled in libbnxt_re */
589739
590
- /* Kernel verbs */
591
- ibdev->query_device = bnxt_re_query_device;
592
- ibdev->modify_device = bnxt_re_modify_device;
593740
594
- ibdev->query_port = bnxt_re_query_port;
595
- ibdev->get_port_immutable = bnxt_re_get_port_immutable;
596
- ibdev->get_dev_fw_str = bnxt_re_query_fw_str;
597
- ibdev->query_pkey = bnxt_re_query_pkey;
598
- ibdev->get_netdev = bnxt_re_get_netdev;
599
- ibdev->add_gid = bnxt_re_add_gid;
600
- ibdev->del_gid = bnxt_re_del_gid;
601
- ibdev->get_link_layer = bnxt_re_get_link_layer;
741
+ rdma_set_device_sysfs_group(ibdev, &bnxt_re_dev_attr_group);
742
+ ib_set_device_ops(ibdev, &bnxt_re_dev_ops);
743
+ ret = ib_device_set_netdev(&rdev->ibdev, rdev->netdev, 1);
744
+ if (ret)
745
+ return ret;
602746
603
- ibdev->alloc_pd = bnxt_re_alloc_pd;
604
- ibdev->dealloc_pd = bnxt_re_dealloc_pd;
605
-
606
- ibdev->create_ah = bnxt_re_create_ah;
607
- ibdev->modify_ah = bnxt_re_modify_ah;
608
- ibdev->query_ah = bnxt_re_query_ah;
609
- ibdev->destroy_ah = bnxt_re_destroy_ah;
610
-
611
- ibdev->create_srq = bnxt_re_create_srq;
612
- ibdev->modify_srq = bnxt_re_modify_srq;
613
- ibdev->query_srq = bnxt_re_query_srq;
614
- ibdev->destroy_srq = bnxt_re_destroy_srq;
615
- ibdev->post_srq_recv = bnxt_re_post_srq_recv;
616
-
617
- ibdev->create_qp = bnxt_re_create_qp;
618
- ibdev->modify_qp = bnxt_re_modify_qp;
619
- ibdev->query_qp = bnxt_re_query_qp;
620
- ibdev->destroy_qp = bnxt_re_destroy_qp;
621
-
622
- ibdev->post_send = bnxt_re_post_send;
623
- ibdev->post_recv = bnxt_re_post_recv;
624
-
625
- ibdev->create_cq = bnxt_re_create_cq;
626
- ibdev->destroy_cq = bnxt_re_destroy_cq;
627
- ibdev->poll_cq = bnxt_re_poll_cq;
628
- ibdev->req_notify_cq = bnxt_re_req_notify_cq;
629
-
630
- ibdev->get_dma_mr = bnxt_re_get_dma_mr;
631
- ibdev->dereg_mr = bnxt_re_dereg_mr;
632
- ibdev->alloc_mr = bnxt_re_alloc_mr;
633
- ibdev->map_mr_sg = bnxt_re_map_mr_sg;
634
-
635
- ibdev->reg_user_mr = bnxt_re_reg_user_mr;
636
- ibdev->alloc_ucontext = bnxt_re_alloc_ucontext;
637
- ibdev->dealloc_ucontext = bnxt_re_dealloc_ucontext;
638
- ibdev->mmap = bnxt_re_mmap;
639
- ibdev->get_hw_stats = bnxt_re_ib_get_hw_stats;
640
- ibdev->alloc_hw_stats = bnxt_re_ib_alloc_hw_stats;
641
-
642
- ibdev->driver_id = RDMA_DRIVER_BNXT_RE;
643
- return ib_register_device(ibdev, NULL);
747
+ dma_set_max_seg_size(&rdev->en_dev->pdev->dev, UINT_MAX);
748
+ return ib_register_device(ibdev, "bnxt_re%d", &rdev->en_dev->pdev->dev);
644749 }
645
-
646
-static ssize_t show_rev(struct device *device, struct device_attribute *attr,
647
- char *buf)
648
-{
649
- struct bnxt_re_dev *rdev = to_bnxt_re_dev(device, ibdev.dev);
650
-
651
- return scnprintf(buf, PAGE_SIZE, "0x%x\n", rdev->en_dev->pdev->vendor);
652
-}
653
-
654
-static ssize_t show_hca(struct device *device, struct device_attribute *attr,
655
- char *buf)
656
-{
657
- struct bnxt_re_dev *rdev = to_bnxt_re_dev(device, ibdev.dev);
658
-
659
- return scnprintf(buf, PAGE_SIZE, "%s\n", rdev->ibdev.node_desc);
660
-}
661
-
662
-static DEVICE_ATTR(hw_rev, 0444, show_rev, NULL);
663
-static DEVICE_ATTR(hca_type, 0444, show_hca, NULL);
664
-
665
-static struct device_attribute *bnxt_re_attributes[] = {
666
- &dev_attr_hw_rev,
667
- &dev_attr_hca_type
668
-};
669750
670751 static void bnxt_re_dev_remove(struct bnxt_re_dev *rdev)
671752 {
672753 dev_put(rdev->netdev);
673754 rdev->netdev = NULL;
674
-
675755 mutex_lock(&bnxt_re_dev_lock);
676756 list_del_rcu(&rdev->list);
677757 mutex_unlock(&bnxt_re_dev_lock);
678758
679759 synchronize_rcu();
680
-
681
- ib_dealloc_device(&rdev->ibdev);
682
- /* rdev is gone */
683760 }
684761
685762 static struct bnxt_re_dev *bnxt_re_dev_add(struct net_device *netdev,
....@@ -688,10 +765,10 @@
688765 struct bnxt_re_dev *rdev;
689766
690767 /* Allocate bnxt_re_dev instance here */
691
- rdev = (struct bnxt_re_dev *)ib_alloc_device(sizeof(*rdev));
768
+ rdev = ib_alloc_device(bnxt_re_dev, ibdev);
692769 if (!rdev) {
693
- dev_err(NULL, "%s: bnxt_re_dev allocation failure!",
694
- ROCE_DRV_MODULE_NAME);
770
+ ibdev_err(NULL, "%s: bnxt_re_dev allocation failure!",
771
+ ROCE_DRV_MODULE_NAME);
695772 return NULL;
696773 }
697774 /* Default values */
....@@ -821,8 +898,8 @@
821898 int rc = 0;
822899
823900 if (!srq) {
824
- dev_err(NULL, "%s: SRQ is NULL, SRQN not handled",
825
- ROCE_DRV_MODULE_NAME);
901
+ ibdev_err(NULL, "%s: SRQ is NULL, SRQN not handled",
902
+ ROCE_DRV_MODULE_NAME);
826903 rc = -EINVAL;
827904 goto done;
828905 }
....@@ -849,8 +926,8 @@
849926 qplib_cq);
850927
851928 if (!cq) {
852
- dev_err(NULL, "%s: CQ is NULL, CQN not handled",
853
- ROCE_DRV_MODULE_NAME);
929
+ ibdev_err(NULL, "%s: CQ is NULL, CQN not handled",
930
+ ROCE_DRV_MODULE_NAME);
854931 return -EINVAL;
855932 }
856933 if (cq->ib_cq.comp_handler) {
....@@ -859,6 +936,16 @@
859936 }
860937
861938 return 0;
939
+}
940
+
941
+#define BNXT_RE_GEN_P5_PF_NQ_DB 0x10000
942
+#define BNXT_RE_GEN_P5_VF_NQ_DB 0x4000
943
+static u32 bnxt_re_get_nqdb_offset(struct bnxt_re_dev *rdev, u16 indx)
944
+{
945
+ return bnxt_qplib_is_chip_gen_p5(rdev->chip_ctx) ?
946
+ (rdev->is_virtfn ? BNXT_RE_GEN_P5_VF_NQ_DB :
947
+ BNXT_RE_GEN_P5_PF_NQ_DB) :
948
+ rdev->msix_entries[indx].db_offset;
862949 }
863950
864951 static void bnxt_re_cleanup_res(struct bnxt_re_dev *rdev)
....@@ -874,21 +961,21 @@
874961
875962 static int bnxt_re_init_res(struct bnxt_re_dev *rdev)
876963 {
877
- int rc = 0, i;
878964 int num_vec_enabled = 0;
965
+ int rc = 0, i;
966
+ u32 db_offt;
879967
880968 bnxt_qplib_init_res(&rdev->qplib_res);
881969
882970 for (i = 1; i < rdev->num_msix ; i++) {
971
+ db_offt = bnxt_re_get_nqdb_offset(rdev, i);
883972 rc = bnxt_qplib_enable_nq(rdev->en_dev->pdev, &rdev->nq[i - 1],
884973 i - 1, rdev->msix_entries[i].vector,
885
- rdev->msix_entries[i].db_offset,
886
- &bnxt_re_cqn_handler,
974
+ db_offt, &bnxt_re_cqn_handler,
887975 &bnxt_re_srqn_handler);
888
-
889976 if (rc) {
890
- dev_err(rdev_to_dev(rdev),
891
- "Failed to enable NQ with rc = 0x%x", rc);
977
+ ibdev_err(&rdev->ibdev,
978
+ "Failed to enable NQ with rc = 0x%x", rc);
892979 goto fail;
893980 }
894981 num_vec_enabled++;
....@@ -897,17 +984,19 @@
897984 fail:
898985 for (i = num_vec_enabled; i >= 0; i--)
899986 bnxt_qplib_disable_nq(&rdev->nq[i]);
900
-
901987 return rc;
902988 }
903989
904990 static void bnxt_re_free_nq_res(struct bnxt_re_dev *rdev)
905991 {
992
+ u8 type;
906993 int i;
907994
908995 for (i = 0; i < rdev->num_msix - 1; i++) {
909
- bnxt_re_net_ring_free(rdev, rdev->nq[i].ring_id);
996
+ type = bnxt_qplib_get_ring_type(rdev->chip_ctx);
997
+ bnxt_re_net_ring_free(rdev, rdev->nq[i].ring_id, type);
910998 bnxt_qplib_free_nq(&rdev->nq[i]);
999
+ rdev->nq[i].res = NULL;
9111000 }
9121001 }
9131002
....@@ -928,8 +1017,10 @@
9281017
9291018 static int bnxt_re_alloc_res(struct bnxt_re_dev *rdev)
9301019 {
931
- int rc = 0, i;
1020
+ struct bnxt_re_ring_attr rattr = {};
9321021 int num_vec_created = 0;
1022
+ int rc = 0, i;
1023
+ u8 type;
9331024
9341025 /* Configure and allocate resources for qplib */
9351026 rdev->qplib_res.rcfw = &rdev->rcfw;
....@@ -950,25 +1041,28 @@
9501041 goto dealloc_res;
9511042
9521043 for (i = 0; i < rdev->num_msix - 1; i++) {
953
- rdev->nq[i].hwq.max_elements = BNXT_RE_MAX_CQ_COUNT +
954
- BNXT_RE_MAX_SRQC_COUNT + 2;
955
- rc = bnxt_qplib_alloc_nq(rdev->en_dev->pdev, &rdev->nq[i]);
1044
+ struct bnxt_qplib_nq *nq;
1045
+
1046
+ nq = &rdev->nq[i];
1047
+ nq->hwq.max_elements = BNXT_QPLIB_NQE_MAX_CNT;
1048
+ rc = bnxt_qplib_alloc_nq(&rdev->qplib_res, &rdev->nq[i]);
9561049 if (rc) {
957
- dev_err(rdev_to_dev(rdev), "Alloc Failed NQ%d rc:%#x",
958
- i, rc);
1050
+ ibdev_err(&rdev->ibdev, "Alloc Failed NQ%d rc:%#x",
1051
+ i, rc);
9591052 goto free_nq;
9601053 }
961
- rc = bnxt_re_net_ring_alloc
962
- (rdev, rdev->nq[i].hwq.pbl[PBL_LVL_0].pg_map_arr,
963
- rdev->nq[i].hwq.pbl[rdev->nq[i].hwq.level].pg_count,
964
- HWRM_RING_ALLOC_CMPL,
965
- BNXT_QPLIB_NQE_MAX_CNT - 1,
966
- rdev->msix_entries[i + 1].ring_idx,
967
- &rdev->nq[i].ring_id);
1054
+ type = bnxt_qplib_get_ring_type(rdev->chip_ctx);
1055
+ rattr.dma_arr = nq->hwq.pbl[PBL_LVL_0].pg_map_arr;
1056
+ rattr.pages = nq->hwq.pbl[rdev->nq[i].hwq.level].pg_count;
1057
+ rattr.type = type;
1058
+ rattr.mode = RING_ALLOC_REQ_INT_MODE_MSIX;
1059
+ rattr.depth = BNXT_QPLIB_NQE_MAX_CNT - 1;
1060
+ rattr.lrid = rdev->msix_entries[i + 1].ring_idx;
1061
+ rc = bnxt_re_net_ring_alloc(rdev, &rattr, &nq->ring_id);
9681062 if (rc) {
969
- dev_err(rdev_to_dev(rdev),
970
- "Failed to allocate NQ fw id with rc = 0x%x",
971
- rc);
1063
+ ibdev_err(&rdev->ibdev,
1064
+ "Failed to allocate NQ fw id with rc = 0x%x",
1065
+ rc);
9721066 bnxt_qplib_free_nq(&rdev->nq[i]);
9731067 goto free_nq;
9741068 }
....@@ -976,8 +1070,9 @@
9761070 }
9771071 return 0;
9781072 free_nq:
979
- for (i = num_vec_created; i >= 0; i--) {
980
- bnxt_re_net_ring_free(rdev, rdev->nq[i].ring_id);
1073
+ for (i = num_vec_created - 1; i >= 0; i--) {
1074
+ type = bnxt_qplib_get_ring_type(rdev->chip_ctx);
1075
+ bnxt_re_net_ring_free(rdev, rdev->nq[i].ring_id, type);
9811076 bnxt_qplib_free_nq(&rdev->nq[i]);
9821077 }
9831078 bnxt_qplib_dealloc_dpi(&rdev->qplib_res,
....@@ -1041,10 +1136,10 @@
10411136 return rc;
10421137
10431138 if (resp.queue_cfg_info) {
1044
- dev_warn(rdev_to_dev(rdev),
1045
- "Asymmetric cos queue configuration detected");
1046
- dev_warn(rdev_to_dev(rdev),
1047
- " on device, QoS may not be fully functional\n");
1139
+ ibdev_warn(&rdev->ibdev,
1140
+ "Asymmetric cos queue configuration detected");
1141
+ ibdev_warn(&rdev->ibdev,
1142
+ " on device, QoS may not be fully functional\n");
10481143 }
10491144 qcfgmap = &resp.pri0_cos_queue_id;
10501145 tmp_map = (u8 *)cid_map;
....@@ -1057,7 +1152,8 @@
10571152 static bool bnxt_re_is_qp1_or_shadow_qp(struct bnxt_re_dev *rdev,
10581153 struct bnxt_re_qp *qp)
10591154 {
1060
- return (qp->ib_qp.qp_type == IB_QPT_GSI) || (qp == rdev->qp1_sqp);
1155
+ return (qp->ib_qp.qp_type == IB_QPT_GSI) ||
1156
+ (qp == rdev->gsi_ctx.gsi_sqp);
10611157 }
10621158
10631159 static void bnxt_re_dev_stop(struct bnxt_re_dev *rdev)
....@@ -1092,13 +1188,8 @@
10921188 u16 gid_idx, index;
10931189 int rc = 0;
10941190
1095
- if (!test_bit(BNXT_RE_FLAG_IBDEV_REGISTERED, &rdev->flags))
1191
+ if (!ib_device_try_get(&rdev->ibdev))
10961192 return 0;
1097
-
1098
- if (!sgid_tbl) {
1099
- dev_err(rdev_to_dev(rdev), "QPLIB: SGID table not allocated");
1100
- return -EINVAL;
1101
- }
11021193
11031194 for (index = 0; index < sgid_tbl->active; index++) {
11041195 gid_idx = sgid_tbl->hw_id[index];
....@@ -1118,6 +1209,7 @@
11181209 rdev->qplib_res.netdev->dev_addr);
11191210 }
11201211
1212
+ ib_device_put(&rdev->ibdev);
11211213 return rc;
11221214 }
11231215
....@@ -1173,7 +1265,7 @@
11731265 /* Get cosq id for this priority */
11741266 rc = bnxt_re_query_hwrm_pri2cos(rdev, 0, &cid_map);
11751267 if (rc) {
1176
- dev_warn(rdev_to_dev(rdev), "no cos for p_mask %x\n", prio_map);
1268
+ ibdev_warn(&rdev->ibdev, "no cos for p_mask %x\n", prio_map);
11771269 return rc;
11781270 }
11791271 /* Parse CoS IDs for app priority */
....@@ -1182,8 +1274,8 @@
11821274 /* Config BONO. */
11831275 rc = bnxt_qplib_map_tc2cos(&rdev->qplib_res, rdev->cosq);
11841276 if (rc) {
1185
- dev_warn(rdev_to_dev(rdev), "no tc for cos{%x, %x}\n",
1186
- rdev->cosq[0], rdev->cosq[1]);
1277
+ ibdev_warn(&rdev->ibdev, "no tc for cos{%x, %x}\n",
1278
+ rdev->cosq[0], rdev->cosq[1]);
11871279 return rc;
11881280 }
11891281
....@@ -1200,19 +1292,66 @@
12001292 return 0;
12011293 }
12021294
1203
-static void bnxt_re_ib_unreg(struct bnxt_re_dev *rdev)
1295
+static void bnxt_re_query_hwrm_intf_version(struct bnxt_re_dev *rdev)
12041296 {
1205
- int i, rc;
1297
+ struct bnxt_en_dev *en_dev = rdev->en_dev;
1298
+ struct hwrm_ver_get_output resp = {0};
1299
+ struct hwrm_ver_get_input req = {0};
1300
+ struct bnxt_fw_msg fw_msg;
1301
+ int rc = 0;
12061302
1207
- if (test_and_clear_bit(BNXT_RE_FLAG_IBDEV_REGISTERED, &rdev->flags)) {
1208
- for (i = 0; i < ARRAY_SIZE(bnxt_re_attributes); i++)
1209
- device_remove_file(&rdev->ibdev.dev,
1210
- bnxt_re_attributes[i]);
1211
- /* Cleanup ib dev */
1212
- bnxt_re_unregister_ib(rdev);
1303
+ memset(&fw_msg, 0, sizeof(fw_msg));
1304
+ bnxt_re_init_hwrm_hdr(rdev, (void *)&req,
1305
+ HWRM_VER_GET, -1, -1);
1306
+ req.hwrm_intf_maj = HWRM_VERSION_MAJOR;
1307
+ req.hwrm_intf_min = HWRM_VERSION_MINOR;
1308
+ req.hwrm_intf_upd = HWRM_VERSION_UPDATE;
1309
+ bnxt_re_fill_fw_msg(&fw_msg, (void *)&req, sizeof(req), (void *)&resp,
1310
+ sizeof(resp), DFLT_HWRM_CMD_TIMEOUT);
1311
+ rc = en_dev->en_ops->bnxt_send_fw_msg(en_dev, BNXT_ROCE_ULP, &fw_msg);
1312
+ if (rc) {
1313
+ ibdev_err(&rdev->ibdev, "Failed to query HW version, rc = 0x%x",
1314
+ rc);
1315
+ return;
12131316 }
1317
+ rdev->qplib_ctx.hwrm_intf_ver =
1318
+ (u64)le16_to_cpu(resp.hwrm_intf_major) << 48 |
1319
+ (u64)le16_to_cpu(resp.hwrm_intf_minor) << 32 |
1320
+ (u64)le16_to_cpu(resp.hwrm_intf_build) << 16 |
1321
+ le16_to_cpu(resp.hwrm_intf_patch);
1322
+}
1323
+
1324
+static int bnxt_re_ib_init(struct bnxt_re_dev *rdev)
1325
+{
1326
+ int rc = 0;
1327
+ u32 event;
1328
+
1329
+ /* Register ib dev */
1330
+ rc = bnxt_re_register_ib(rdev);
1331
+ if (rc) {
1332
+ pr_err("Failed to register with IB: %#x\n", rc);
1333
+ return rc;
1334
+ }
1335
+ dev_info(rdev_to_dev(rdev), "Device registered successfully");
1336
+ ib_get_eth_speed(&rdev->ibdev, 1, &rdev->active_speed,
1337
+ &rdev->active_width);
1338
+ set_bit(BNXT_RE_FLAG_ISSUE_ROCE_STATS, &rdev->flags);
1339
+
1340
+ event = netif_running(rdev->netdev) && netif_carrier_ok(rdev->netdev) ?
1341
+ IB_EVENT_PORT_ACTIVE : IB_EVENT_PORT_ERR;
1342
+
1343
+ bnxt_re_dispatch_event(&rdev->ibdev, NULL, 1, event);
1344
+
1345
+ return rc;
1346
+}
1347
+
1348
+static void bnxt_re_dev_uninit(struct bnxt_re_dev *rdev)
1349
+{
1350
+ u8 type;
1351
+ int rc;
1352
+
12141353 if (test_and_clear_bit(BNXT_RE_FLAG_QOS_WORK_REG, &rdev->flags))
1215
- cancel_delayed_work(&rdev->worker);
1354
+ cancel_delayed_work_sync(&rdev->worker);
12161355
12171356 if (test_and_clear_bit(BNXT_RE_FLAG_RESOURCES_INITIALIZED,
12181357 &rdev->flags))
....@@ -1223,25 +1362,28 @@
12231362 if (test_and_clear_bit(BNXT_RE_FLAG_RCFW_CHANNEL_EN, &rdev->flags)) {
12241363 rc = bnxt_qplib_deinit_rcfw(&rdev->rcfw);
12251364 if (rc)
1226
- dev_warn(rdev_to_dev(rdev),
1227
- "Failed to deinitialize RCFW: %#x", rc);
1365
+ ibdev_warn(&rdev->ibdev,
1366
+ "Failed to deinitialize RCFW: %#x", rc);
12281367 bnxt_re_net_stats_ctx_free(rdev, rdev->qplib_ctx.stats.fw_id);
1229
- bnxt_qplib_free_ctx(rdev->en_dev->pdev, &rdev->qplib_ctx);
1368
+ bnxt_qplib_free_ctx(&rdev->qplib_res, &rdev->qplib_ctx);
12301369 bnxt_qplib_disable_rcfw_channel(&rdev->rcfw);
1231
- bnxt_re_net_ring_free(rdev, rdev->rcfw.creq_ring_id);
1370
+ type = bnxt_qplib_get_ring_type(rdev->chip_ctx);
1371
+ bnxt_re_net_ring_free(rdev, rdev->rcfw.creq.ring_id, type);
12321372 bnxt_qplib_free_rcfw_channel(&rdev->rcfw);
12331373 }
12341374 if (test_and_clear_bit(BNXT_RE_FLAG_GOT_MSIX, &rdev->flags)) {
12351375 rc = bnxt_re_free_msix(rdev);
12361376 if (rc)
1237
- dev_warn(rdev_to_dev(rdev),
1238
- "Failed to free MSI-X vectors: %#x", rc);
1377
+ ibdev_warn(&rdev->ibdev,
1378
+ "Failed to free MSI-X vectors: %#x", rc);
12391379 }
1380
+
1381
+ bnxt_re_destroy_chip_ctx(rdev);
12401382 if (test_and_clear_bit(BNXT_RE_FLAG_NETDEV_REGISTERED, &rdev->flags)) {
12411383 rc = bnxt_re_unregister_netdev(rdev);
12421384 if (rc)
1243
- dev_warn(rdev_to_dev(rdev),
1244
- "Failed to unregister with netdev: %#x", rc);
1385
+ ibdev_warn(&rdev->ibdev,
1386
+ "Failed to unregister with netdev: %#x", rc);
12451387 }
12461388 }
12471389
....@@ -1255,62 +1397,78 @@
12551397 schedule_delayed_work(&rdev->worker, msecs_to_jiffies(30000));
12561398 }
12571399
1258
-static int bnxt_re_ib_reg(struct bnxt_re_dev *rdev)
1400
+static int bnxt_re_dev_init(struct bnxt_re_dev *rdev, u8 wqe_mode)
12591401 {
1260
- int i, j, rc;
1261
-
1262
- bool locked;
1263
-
1264
- /* Acquire rtnl lock through out this function */
1265
- rtnl_lock();
1266
- locked = true;
1402
+ struct bnxt_qplib_creq_ctx *creq;
1403
+ struct bnxt_re_ring_attr rattr;
1404
+ u32 db_offt;
1405
+ int vid;
1406
+ u8 type;
1407
+ int rc;
12671408
12681409 /* Registered a new RoCE device instance to netdev */
1410
+ memset(&rattr, 0, sizeof(rattr));
12691411 rc = bnxt_re_register_netdev(rdev);
12701412 if (rc) {
1271
- rtnl_unlock();
1272
- pr_err("Failed to register with netedev: %#x\n", rc);
1413
+ ibdev_err(&rdev->ibdev,
1414
+ "Failed to register with netedev: %#x\n", rc);
12731415 return -EINVAL;
12741416 }
12751417 set_bit(BNXT_RE_FLAG_NETDEV_REGISTERED, &rdev->flags);
1418
+
1419
+ rc = bnxt_re_setup_chip_ctx(rdev, wqe_mode);
1420
+ if (rc) {
1421
+ ibdev_err(&rdev->ibdev, "Failed to get chip context\n");
1422
+ return -EINVAL;
1423
+ }
12761424
12771425 /* Check whether VF or PF */
12781426 bnxt_re_get_sriov_func_type(rdev);
12791427
12801428 rc = bnxt_re_request_msix(rdev);
12811429 if (rc) {
1282
- pr_err("Failed to get MSI-X vectors: %#x\n", rc);
1430
+ ibdev_err(&rdev->ibdev,
1431
+ "Failed to get MSI-X vectors: %#x\n", rc);
12831432 rc = -EINVAL;
12841433 goto fail;
12851434 }
12861435 set_bit(BNXT_RE_FLAG_GOT_MSIX, &rdev->flags);
12871436
1437
+ bnxt_re_query_hwrm_intf_version(rdev);
1438
+
12881439 /* Establish RCFW Communication Channel to initialize the context
12891440 * memory for the function and all child VFs
12901441 */
1291
- rc = bnxt_qplib_alloc_rcfw_channel(rdev->en_dev->pdev, &rdev->rcfw,
1442
+ rc = bnxt_qplib_alloc_rcfw_channel(&rdev->qplib_res, &rdev->rcfw,
1443
+ &rdev->qplib_ctx,
12921444 BNXT_RE_MAX_QPC_COUNT);
12931445 if (rc) {
1294
- pr_err("Failed to allocate RCFW Channel: %#x\n", rc);
1446
+ ibdev_err(&rdev->ibdev,
1447
+ "Failed to allocate RCFW Channel: %#x\n", rc);
12951448 goto fail;
12961449 }
1297
- rc = bnxt_re_net_ring_alloc
1298
- (rdev, rdev->rcfw.creq.pbl[PBL_LVL_0].pg_map_arr,
1299
- rdev->rcfw.creq.pbl[rdev->rcfw.creq.level].pg_count,
1300
- HWRM_RING_ALLOC_CMPL, BNXT_QPLIB_CREQE_MAX_CNT - 1,
1301
- rdev->msix_entries[BNXT_RE_AEQ_IDX].ring_idx,
1302
- &rdev->rcfw.creq_ring_id);
1450
+
1451
+ type = bnxt_qplib_get_ring_type(rdev->chip_ctx);
1452
+ creq = &rdev->rcfw.creq;
1453
+ rattr.dma_arr = creq->hwq.pbl[PBL_LVL_0].pg_map_arr;
1454
+ rattr.pages = creq->hwq.pbl[creq->hwq.level].pg_count;
1455
+ rattr.type = type;
1456
+ rattr.mode = RING_ALLOC_REQ_INT_MODE_MSIX;
1457
+ rattr.depth = BNXT_QPLIB_CREQE_MAX_CNT - 1;
1458
+ rattr.lrid = rdev->msix_entries[BNXT_RE_AEQ_IDX].ring_idx;
1459
+ rc = bnxt_re_net_ring_alloc(rdev, &rattr, &creq->ring_id);
13031460 if (rc) {
1304
- pr_err("Failed to allocate CREQ: %#x\n", rc);
1461
+ ibdev_err(&rdev->ibdev, "Failed to allocate CREQ: %#x\n", rc);
13051462 goto free_rcfw;
13061463 }
1307
- rc = bnxt_qplib_enable_rcfw_channel
1308
- (rdev->en_dev->pdev, &rdev->rcfw,
1309
- rdev->msix_entries[BNXT_RE_AEQ_IDX].vector,
1310
- rdev->msix_entries[BNXT_RE_AEQ_IDX].db_offset,
1311
- rdev->is_virtfn, &bnxt_re_aeq_handler);
1464
+ db_offt = bnxt_re_get_nqdb_offset(rdev, BNXT_RE_AEQ_IDX);
1465
+ vid = rdev->msix_entries[BNXT_RE_AEQ_IDX].vector;
1466
+ rc = bnxt_qplib_enable_rcfw_channel(&rdev->rcfw,
1467
+ vid, db_offt, rdev->is_virtfn,
1468
+ &bnxt_re_aeq_handler);
13121469 if (rc) {
1313
- pr_err("Failed to enable RCFW channel: %#x\n", rc);
1470
+ ibdev_err(&rdev->ibdev, "Failed to enable RCFW channel: %#x\n",
1471
+ rc);
13141472 goto free_ring;
13151473 }
13161474
....@@ -1318,26 +1476,30 @@
13181476 rdev->is_virtfn);
13191477 if (rc)
13201478 goto disable_rcfw;
1321
- if (!rdev->is_virtfn)
1322
- bnxt_re_set_resource_limits(rdev);
13231479
1324
- rc = bnxt_qplib_alloc_ctx(rdev->en_dev->pdev, &rdev->qplib_ctx, 0);
1480
+ bnxt_re_set_resource_limits(rdev);
1481
+
1482
+ rc = bnxt_qplib_alloc_ctx(&rdev->qplib_res, &rdev->qplib_ctx, 0,
1483
+ bnxt_qplib_is_chip_gen_p5(rdev->chip_ctx));
13251484 if (rc) {
1326
- pr_err("Failed to allocate QPLIB context: %#x\n", rc);
1485
+ ibdev_err(&rdev->ibdev,
1486
+ "Failed to allocate QPLIB context: %#x\n", rc);
13271487 goto disable_rcfw;
13281488 }
13291489 rc = bnxt_re_net_stats_ctx_alloc(rdev,
13301490 rdev->qplib_ctx.stats.dma_map,
13311491 &rdev->qplib_ctx.stats.fw_id);
13321492 if (rc) {
1333
- pr_err("Failed to allocate stats context: %#x\n", rc);
1493
+ ibdev_err(&rdev->ibdev,
1494
+ "Failed to allocate stats context: %#x\n", rc);
13341495 goto free_ctx;
13351496 }
13361497
13371498 rc = bnxt_qplib_init_rcfw(&rdev->rcfw, &rdev->qplib_ctx,
13381499 rdev->is_virtfn);
13391500 if (rc) {
1340
- pr_err("Failed to initialize RCFW: %#x\n", rc);
1501
+ ibdev_err(&rdev->ibdev,
1502
+ "Failed to initialize RCFW: %#x\n", rc);
13411503 goto free_sctx;
13421504 }
13431505 set_bit(BNXT_RE_FLAG_RCFW_CHANNEL_EN, &rdev->flags);
....@@ -1345,13 +1507,15 @@
13451507 /* Resources based on the 'new' device caps */
13461508 rc = bnxt_re_alloc_res(rdev);
13471509 if (rc) {
1348
- pr_err("Failed to allocate resources: %#x\n", rc);
1510
+ ibdev_err(&rdev->ibdev,
1511
+ "Failed to allocate resources: %#x\n", rc);
13491512 goto fail;
13501513 }
13511514 set_bit(BNXT_RE_FLAG_RESOURCES_ALLOCATED, &rdev->flags);
13521515 rc = bnxt_re_init_res(rdev);
13531516 if (rc) {
1354
- pr_err("Failed to initialize resources: %#x\n", rc);
1517
+ ibdev_err(&rdev->ibdev,
1518
+ "Failed to initialize resources: %#x\n", rc);
13551519 goto fail;
13561520 }
13571521
....@@ -1360,60 +1524,28 @@
13601524 if (!rdev->is_virtfn) {
13611525 rc = bnxt_re_setup_qos(rdev);
13621526 if (rc)
1363
- pr_info("RoCE priority not yet configured\n");
1527
+ ibdev_info(&rdev->ibdev,
1528
+ "RoCE priority not yet configured\n");
13641529
13651530 INIT_DELAYED_WORK(&rdev->worker, bnxt_re_worker);
13661531 set_bit(BNXT_RE_FLAG_QOS_WORK_REG, &rdev->flags);
13671532 schedule_delayed_work(&rdev->worker, msecs_to_jiffies(30000));
13681533 }
13691534
1370
- rtnl_unlock();
1371
- locked = false;
1372
-
1373
- /* Register ib dev */
1374
- rc = bnxt_re_register_ib(rdev);
1375
- if (rc) {
1376
- pr_err("Failed to register with IB: %#x\n", rc);
1377
- goto fail;
1378
- }
1379
- set_bit(BNXT_RE_FLAG_IBDEV_REGISTERED, &rdev->flags);
1380
- dev_info(rdev_to_dev(rdev), "Device registered successfully");
1381
- for (i = 0; i < ARRAY_SIZE(bnxt_re_attributes); i++) {
1382
- rc = device_create_file(&rdev->ibdev.dev,
1383
- bnxt_re_attributes[i]);
1384
- if (rc) {
1385
- dev_err(rdev_to_dev(rdev),
1386
- "Failed to create IB sysfs: %#x", rc);
1387
- /* Must clean up all created device files */
1388
- for (j = 0; j < i; j++)
1389
- device_remove_file(&rdev->ibdev.dev,
1390
- bnxt_re_attributes[j]);
1391
- bnxt_re_unregister_ib(rdev);
1392
- goto fail;
1393
- }
1394
- }
1395
- ib_get_eth_speed(&rdev->ibdev, 1, &rdev->active_speed,
1396
- &rdev->active_width);
1397
- set_bit(BNXT_RE_FLAG_ISSUE_ROCE_STATS, &rdev->flags);
1398
- bnxt_re_dispatch_event(&rdev->ibdev, NULL, 1, IB_EVENT_PORT_ACTIVE);
1399
- bnxt_re_dispatch_event(&rdev->ibdev, NULL, 1, IB_EVENT_GID_CHANGE);
1400
-
14011535 return 0;
14021536 free_sctx:
14031537 bnxt_re_net_stats_ctx_free(rdev, rdev->qplib_ctx.stats.fw_id);
14041538 free_ctx:
1405
- bnxt_qplib_free_ctx(rdev->en_dev->pdev, &rdev->qplib_ctx);
1539
+ bnxt_qplib_free_ctx(&rdev->qplib_res, &rdev->qplib_ctx);
14061540 disable_rcfw:
14071541 bnxt_qplib_disable_rcfw_channel(&rdev->rcfw);
14081542 free_ring:
1409
- bnxt_re_net_ring_free(rdev, rdev->rcfw.creq_ring_id);
1543
+ type = bnxt_qplib_get_ring_type(rdev->chip_ctx);
1544
+ bnxt_re_net_ring_free(rdev, rdev->rcfw.creq.ring_id, type);
14101545 free_rcfw:
14111546 bnxt_qplib_free_rcfw_channel(&rdev->rcfw);
14121547 fail:
1413
- if (!locked)
1414
- rtnl_lock();
1415
- bnxt_re_ib_unreg(rdev);
1416
- rtnl_unlock();
1548
+ bnxt_re_dev_uninit(rdev);
14171549
14181550 return rc;
14191551 }
....@@ -1440,7 +1572,8 @@
14401572 en_dev = bnxt_re_dev_probe(netdev);
14411573 if (IS_ERR(en_dev)) {
14421574 if (en_dev != ERR_PTR(-ENODEV))
1443
- pr_err("%s: Failed to probe\n", ROCE_DRV_MODULE_NAME);
1575
+ ibdev_err(&(*rdev)->ibdev, "%s: Failed to probe\n",
1576
+ ROCE_DRV_MODULE_NAME);
14441577 rc = PTR_ERR(en_dev);
14451578 goto exit;
14461579 }
....@@ -1454,9 +1587,47 @@
14541587 return rc;
14551588 }
14561589
1457
-static void bnxt_re_remove_one(struct bnxt_re_dev *rdev)
1590
+static void bnxt_re_remove_device(struct bnxt_re_dev *rdev)
14581591 {
1592
+ bnxt_re_dev_uninit(rdev);
14591593 pci_dev_put(rdev->en_dev->pdev);
1594
+ bnxt_re_dev_unreg(rdev);
1595
+}
1596
+
1597
+static int bnxt_re_add_device(struct bnxt_re_dev **rdev,
1598
+ struct net_device *netdev, u8 wqe_mode)
1599
+{
1600
+ int rc;
1601
+
1602
+ rc = bnxt_re_dev_reg(rdev, netdev);
1603
+ if (rc == -ENODEV)
1604
+ return rc;
1605
+ if (rc) {
1606
+ pr_err("Failed to register with the device %s: %#x\n",
1607
+ netdev->name, rc);
1608
+ return rc;
1609
+ }
1610
+
1611
+ pci_dev_get((*rdev)->en_dev->pdev);
1612
+ rc = bnxt_re_dev_init(*rdev, wqe_mode);
1613
+ if (rc) {
1614
+ pci_dev_put((*rdev)->en_dev->pdev);
1615
+ bnxt_re_dev_unreg(*rdev);
1616
+ }
1617
+
1618
+ return rc;
1619
+}
1620
+
1621
+static void bnxt_re_dealloc_driver(struct ib_device *ib_dev)
1622
+{
1623
+ struct bnxt_re_dev *rdev =
1624
+ container_of(ib_dev, struct bnxt_re_dev, ibdev);
1625
+
1626
+ dev_info(rdev_to_dev(rdev), "Unregistering Device");
1627
+
1628
+ rtnl_lock();
1629
+ bnxt_re_remove_device(rdev);
1630
+ rtnl_unlock();
14601631 }
14611632
14621633 /* Handle all deferred netevents tasks */
....@@ -1469,21 +1640,23 @@
14691640 re_work = container_of(work, struct bnxt_re_work, work);
14701641 rdev = re_work->rdev;
14711642
1472
- if (re_work->event != NETDEV_REGISTER &&
1473
- !test_bit(BNXT_RE_FLAG_IBDEV_REGISTERED, &rdev->flags))
1474
- return;
1475
-
1476
- switch (re_work->event) {
1477
- case NETDEV_REGISTER:
1478
- rc = bnxt_re_ib_reg(rdev);
1643
+ if (re_work->event == NETDEV_REGISTER) {
1644
+ rc = bnxt_re_ib_init(rdev);
14791645 if (rc) {
1480
- dev_err(rdev_to_dev(rdev),
1481
- "Failed to register with IB: %#x", rc);
1482
- bnxt_re_remove_one(rdev);
1483
- bnxt_re_dev_unreg(rdev);
1646
+ ibdev_err(&rdev->ibdev,
1647
+ "Failed to register with IB: %#x", rc);
1648
+ rtnl_lock();
1649
+ bnxt_re_remove_device(rdev);
1650
+ rtnl_unlock();
14841651 goto exit;
14851652 }
1486
- break;
1653
+ goto exit;
1654
+ }
1655
+
1656
+ if (!ib_device_try_get(&rdev->ibdev))
1657
+ goto exit;
1658
+
1659
+ switch (re_work->event) {
14871660 case NETDEV_UP:
14881661 bnxt_re_dispatch_event(&rdev->ibdev, NULL, 1,
14891662 IB_EVENT_PORT_ACTIVE);
....@@ -1503,15 +1676,10 @@
15031676 default:
15041677 break;
15051678 }
1506
- smp_mb__before_atomic();
1507
- atomic_dec(&rdev->sched_count);
1679
+ ib_device_put(&rdev->ibdev);
15081680 exit:
1681
+ put_device(&rdev->ibdev.dev);
15091682 kfree(re_work);
1510
-}
1511
-
1512
-static void bnxt_re_init_one(struct bnxt_re_dev *rdev)
1513
-{
1514
- pci_dev_get(rdev->en_dev->pdev);
15151683 }
15161684
15171685 /*
....@@ -1536,6 +1704,7 @@
15361704 struct bnxt_re_dev *rdev;
15371705 int rc = 0;
15381706 bool sch_work = false;
1707
+ bool release = true;
15391708
15401709 real_dev = rdma_vlan_dev_real_dev(netdev);
15411710 if (!real_dev)
....@@ -1543,7 +1712,8 @@
15431712
15441713 rdev = bnxt_re_from_netdev(real_dev);
15451714 if (!rdev && event != NETDEV_REGISTER)
1546
- goto exit;
1715
+ return NOTIFY_OK;
1716
+
15471717 if (real_dev != netdev)
15481718 goto exit;
15491719
....@@ -1551,27 +1721,15 @@
15511721 case NETDEV_REGISTER:
15521722 if (rdev)
15531723 break;
1554
- rc = bnxt_re_dev_reg(&rdev, real_dev);
1555
- if (rc == -ENODEV)
1556
- break;
1557
- if (rc) {
1558
- pr_err("Failed to register with the device %s: %#x\n",
1559
- real_dev->name, rc);
1560
- break;
1561
- }
1562
- bnxt_re_init_one(rdev);
1563
- sch_work = true;
1724
+ rc = bnxt_re_add_device(&rdev, real_dev,
1725
+ BNXT_QPLIB_WQE_MODE_STATIC);
1726
+ if (!rc)
1727
+ sch_work = true;
1728
+ release = false;
15641729 break;
15651730
15661731 case NETDEV_UNREGISTER:
1567
- /* netdev notifier will call NETDEV_UNREGISTER again later since
1568
- * we are still holding the reference to the netdev
1569
- */
1570
- if (atomic_read(&rdev->sched_count) > 0)
1571
- goto exit;
1572
- bnxt_re_ib_unreg(rdev);
1573
- bnxt_re_remove_one(rdev);
1574
- bnxt_re_dev_unreg(rdev);
1732
+ ib_unregister_device_queued(&rdev->ibdev);
15751733 break;
15761734
15771735 default:
....@@ -1582,17 +1740,19 @@
15821740 /* Allocate for the deferred task */
15831741 re_work = kzalloc(sizeof(*re_work), GFP_ATOMIC);
15841742 if (re_work) {
1743
+ get_device(&rdev->ibdev.dev);
15851744 re_work->rdev = rdev;
15861745 re_work->event = event;
15871746 re_work->vlan_dev = (real_dev == netdev ?
15881747 NULL : netdev);
15891748 INIT_WORK(&re_work->work, bnxt_re_task);
1590
- atomic_inc(&rdev->sched_count);
15911749 queue_work(bnxt_re_wq, &re_work->work);
15921750 }
15931751 }
15941752
15951753 exit:
1754
+ if (rdev && release)
1755
+ ib_device_put(&rdev->ibdev);
15961756 return NOTIFY_DONE;
15971757 }
15981758
....@@ -1628,36 +1788,21 @@
16281788
16291789 static void __exit bnxt_re_mod_exit(void)
16301790 {
1631
- struct bnxt_re_dev *rdev, *next;
1632
- LIST_HEAD(to_be_deleted);
1791
+ struct bnxt_re_dev *rdev;
16331792
1634
- mutex_lock(&bnxt_re_dev_lock);
1635
- /* Free all adapter allocated resources */
1636
- if (!list_empty(&bnxt_re_dev_list))
1637
- list_splice_init(&bnxt_re_dev_list, &to_be_deleted);
1638
- mutex_unlock(&bnxt_re_dev_lock);
1639
- /*
1640
- * Cleanup the devices in reverse order so that the VF device
1641
- * cleanup is done before PF cleanup
1642
- */
1643
- list_for_each_entry_safe_reverse(rdev, next, &to_be_deleted, list) {
1644
- dev_info(rdev_to_dev(rdev), "Unregistering Device");
1645
- /*
1646
- * Flush out any scheduled tasks before destroying the
1647
- * resources
1648
- */
1649
- flush_workqueue(bnxt_re_wq);
1650
- bnxt_re_dev_stop(rdev);
1651
- /* Acquire the rtnl_lock as the L2 resources are freed here */
1652
- rtnl_lock();
1653
- bnxt_re_ib_unreg(rdev);
1654
- rtnl_unlock();
1655
- bnxt_re_remove_one(rdev);
1656
- bnxt_re_dev_unreg(rdev);
1657
- }
16581793 unregister_netdevice_notifier(&bnxt_re_netdev_notifier);
16591794 if (bnxt_re_wq)
16601795 destroy_workqueue(bnxt_re_wq);
1796
+ list_for_each_entry(rdev, &bnxt_re_dev_list, list) {
1797
+ /* VF device removal should be called before the removal
1798
+ * of PF device. Queue VFs unregister first, so that VFs
1799
+ * shall be removed before the PF during the call of
1800
+ * ib_unregister_driver.
1801
+ */
1802
+ if (rdev->is_virtfn)
1803
+ ib_unregister_device(&rdev->ibdev);
1804
+ }
1805
+ ib_unregister_driver(RDMA_DRIVER_BNXT_RE);
16611806 }
16621807
16631808 module_init(bnxt_re_mod_init);