.. | .. |
---|
67 | 67 | #include "hw_counters.h" |
---|
68 | 68 | |
---|
69 | 69 | static char version[] = |
---|
70 | | - BNXT_RE_DESC " v" ROCE_DRV_MODULE_VERSION "\n"; |
---|
| 70 | + BNXT_RE_DESC "\n"; |
---|
71 | 71 | |
---|
72 | 72 | MODULE_AUTHOR("Eddie Wai <eddie.wai@broadcom.com>"); |
---|
73 | 73 | MODULE_DESCRIPTION(BNXT_RE_DESC " Driver"); |
---|
.. | .. |
---|
78 | 78 | /* Mutex to protect the list of bnxt_re devices added */ |
---|
79 | 79 | static DEFINE_MUTEX(bnxt_re_dev_lock); |
---|
80 | 80 | 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 | +} |
---|
82 | 133 | |
---|
83 | 134 | /* SR-IOV helper functions */ |
---|
84 | 135 | |
---|
.. | .. |
---|
96 | 147 | * reserved for the function. The driver may choose to allocate fewer |
---|
97 | 148 | * resources than the firmware maximum. |
---|
98 | 149 | */ |
---|
| 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 | + |
---|
99 | 209 | static void bnxt_re_set_resource_limits(struct bnxt_re_dev *rdev) |
---|
100 | 210 | { |
---|
101 | | - u32 vf_qps = 0, vf_srqs = 0, vf_cqs = 0, vf_mrws = 0, vf_gids = 0; |
---|
102 | | - u32 i; |
---|
103 | | - u32 vf_pct; |
---|
104 | 211 | u32 num_vfs; |
---|
105 | | - struct bnxt_qplib_dev_attr *dev_attr = &rdev->dev_attr; |
---|
106 | 212 | |
---|
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); |
---|
109 | 215 | |
---|
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); |
---|
154 | 220 | } |
---|
155 | 221 | |
---|
156 | 222 | /* for handling bnxt_en callbacks later */ |
---|
.. | .. |
---|
170 | 236 | return; |
---|
171 | 237 | |
---|
172 | 238 | 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 | + } |
---|
176 | 244 | } |
---|
177 | 245 | |
---|
178 | 246 | static void bnxt_re_shutdown(void *p) |
---|
.. | .. |
---|
181 | 249 | |
---|
182 | 250 | if (!rdev) |
---|
183 | 251 | 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); |
---|
186 | 256 | } |
---|
187 | 257 | |
---|
188 | 258 | static void bnxt_re_stop_irq(void *handle) |
---|
.. | .. |
---|
214 | 284 | * to f/w will timeout and that will set the |
---|
215 | 285 | * timeout bit. |
---|
216 | 286 | */ |
---|
217 | | - dev_err(rdev_to_dev(rdev), "Failed to re-start IRQs\n"); |
---|
| 287 | + ibdev_err(&rdev->ibdev, "Failed to re-start IRQs\n"); |
---|
218 | 288 | return; |
---|
219 | 289 | } |
---|
220 | 290 | |
---|
.. | .. |
---|
224 | 294 | for (indx = 0; indx < rdev->num_msix; indx++) |
---|
225 | 295 | rdev->msix_entries[indx].vector = ent[indx].vector; |
---|
226 | 296 | |
---|
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 | + } |
---|
229 | 303 | for (indx = BNXT_RE_NQ_IDX ; indx < rdev->num_msix; indx++) { |
---|
230 | 304 | nq = &rdev->nq[indx - 1]; |
---|
231 | 305 | rc = bnxt_qplib_nq_start_irq(nq, indx - 1, |
---|
232 | 306 | 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 | + } |
---|
236 | 312 | } |
---|
237 | 313 | } |
---|
238 | 314 | |
---|
.. | .. |
---|
278 | 354 | |
---|
279 | 355 | rc = en_dev->en_ops->bnxt_register_device(en_dev, BNXT_ROCE_ULP, |
---|
280 | 356 | &bnxt_re_ulp_ops, rdev); |
---|
| 357 | + rdev->qplib_res.pdev = rdev->en_dev->pdev; |
---|
281 | 358 | return rc; |
---|
282 | 359 | } |
---|
283 | 360 | |
---|
.. | .. |
---|
317 | 394 | goto done; |
---|
318 | 395 | } |
---|
319 | 396 | 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); |
---|
323 | 400 | } |
---|
324 | 401 | rdev->num_msix = num_msix_got; |
---|
325 | 402 | done: |
---|
.. | .. |
---|
345 | 422 | fw_msg->timeout = timeout; |
---|
346 | 423 | } |
---|
347 | 424 | |
---|
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) |
---|
349 | 427 | { |
---|
350 | 428 | struct bnxt_en_dev *en_dev = rdev->en_dev; |
---|
351 | 429 | struct hwrm_ring_free_input req = {0}; |
---|
.. | .. |
---|
359 | 437 | memset(&fw_msg, 0, sizeof(fw_msg)); |
---|
360 | 438 | |
---|
361 | 439 | 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; |
---|
363 | 441 | req.ring_id = cpu_to_le16(fw_ring_id); |
---|
364 | 442 | bnxt_re_fill_fw_msg(&fw_msg, (void *)&req, sizeof(req), (void *)&resp, |
---|
365 | 443 | sizeof(resp), DFLT_HWRM_CMD_TIMEOUT); |
---|
366 | 444 | rc = en_dev->en_ops->bnxt_send_fw_msg(en_dev, BNXT_ROCE_ULP, &fw_msg); |
---|
367 | 445 | 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); |
---|
370 | 448 | return rc; |
---|
371 | 449 | } |
---|
372 | 450 | |
---|
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) |
---|
376 | 454 | { |
---|
377 | 455 | struct bnxt_en_dev *en_dev = rdev->en_dev; |
---|
378 | 456 | struct hwrm_ring_alloc_input req = {0}; |
---|
.. | .. |
---|
386 | 464 | memset(&fw_msg, 0, sizeof(fw_msg)); |
---|
387 | 465 | bnxt_re_init_hwrm_hdr(rdev, (void *)&req, HWRM_RING_ALLOC, -1, -1); |
---|
388 | 466 | 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) { |
---|
391 | 469 | /* Page size is in log2 units */ |
---|
392 | 470 | req.page_size = BNXT_PAGE_SHIFT; |
---|
393 | 471 | req.page_tbl_depth = 1; |
---|
394 | 472 | } |
---|
395 | 473 | req.fbo = 0; |
---|
396 | 474 | /* 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; |
---|
401 | 479 | bnxt_re_fill_fw_msg(&fw_msg, (void *)&req, sizeof(req), (void *)&resp, |
---|
402 | 480 | sizeof(resp), DFLT_HWRM_CMD_TIMEOUT); |
---|
403 | 481 | rc = en_dev->en_ops->bnxt_send_fw_msg(en_dev, BNXT_ROCE_ULP, &fw_msg); |
---|
.. | .. |
---|
426 | 504 | sizeof(req), DFLT_HWRM_CMD_TIMEOUT); |
---|
427 | 505 | rc = en_dev->en_ops->bnxt_send_fw_msg(en_dev, BNXT_ROCE_ULP, &fw_msg); |
---|
428 | 506 | 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); |
---|
431 | 509 | |
---|
432 | 510 | return rc; |
---|
433 | 511 | } |
---|
.. | .. |
---|
436 | 514 | dma_addr_t dma_map, |
---|
437 | 515 | u32 *fw_stats_ctx_id) |
---|
438 | 516 | { |
---|
| 517 | + struct bnxt_qplib_chip_ctx *chip_ctx = rdev->chip_ctx; |
---|
439 | 518 | struct hwrm_stat_ctx_alloc_output resp = {0}; |
---|
440 | 519 | struct hwrm_stat_ctx_alloc_input req = {0}; |
---|
441 | 520 | struct bnxt_en_dev *en_dev = rdev->en_dev; |
---|
.. | .. |
---|
452 | 531 | bnxt_re_init_hwrm_hdr(rdev, (void *)&req, HWRM_STAT_CTX_ALLOC, -1, -1); |
---|
453 | 532 | req.update_period_ms = cpu_to_le32(1000); |
---|
454 | 533 | req.stats_dma_addr = cpu_to_le64(dma_map); |
---|
| 534 | + req.stats_dma_length = cpu_to_le16(chip_ctx->hw_stats_size); |
---|
455 | 535 | req.stat_ctx_flags = STAT_CTX_ALLOC_REQ_STAT_CTX_FLAGS_ROCE; |
---|
456 | 536 | bnxt_re_fill_fw_msg(&fw_msg, (void *)&req, sizeof(req), (void *)&resp, |
---|
457 | 537 | sizeof(resp), DFLT_HWRM_CMD_TIMEOUT); |
---|
.. | .. |
---|
481 | 561 | |
---|
482 | 562 | static struct bnxt_re_dev *bnxt_re_from_netdev(struct net_device *netdev) |
---|
483 | 563 | { |
---|
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; |
---|
485 | 568 | |
---|
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); |
---|
495 | 570 | } |
---|
496 | 571 | |
---|
497 | 572 | static void bnxt_re_dev_unprobe(struct net_device *netdev, |
---|
.. | .. |
---|
535 | 610 | return en_dev; |
---|
536 | 611 | } |
---|
537 | 612 | |
---|
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) |
---|
539 | 615 | { |
---|
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); |
---|
541 | 620 | } |
---|
| 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 | +}; |
---|
542 | 694 | |
---|
543 | 695 | static int bnxt_re_register_ib(struct bnxt_re_dev *rdev) |
---|
544 | 696 | { |
---|
545 | 697 | struct ib_device *ibdev = &rdev->ibdev; |
---|
| 698 | + int ret; |
---|
546 | 699 | |
---|
547 | 700 | /* ib device init */ |
---|
548 | | - ibdev->owner = THIS_MODULE; |
---|
549 | 701 | ibdev->node_type = RDMA_NODE_IB_CA; |
---|
550 | | - strlcpy(ibdev->name, "bnxt_re%d", IB_DEVICE_NAME_MAX); |
---|
551 | 702 | strlcpy(ibdev->node_desc, BNXT_RE_DESC " HCA", |
---|
552 | 703 | strlen(BNXT_RE_DESC) + 5); |
---|
553 | 704 | ibdev->phys_port_cnt = 1; |
---|
554 | 705 | |
---|
555 | 706 | bnxt_qplib_get_guid(rdev->netdev->dev_addr, (u8 *)&ibdev->node_guid); |
---|
556 | 707 | |
---|
557 | | - ibdev->num_comp_vectors = 1; |
---|
| 708 | + ibdev->num_comp_vectors = rdev->num_msix - 1; |
---|
558 | 709 | ibdev->dev.parent = &rdev->en_dev->pdev->dev; |
---|
559 | 710 | ibdev->local_dma_lkey = BNXT_QPLIB_RSVD_LKEY; |
---|
560 | 711 | |
---|
561 | 712 | /* User space */ |
---|
562 | | - ibdev->uverbs_abi_ver = BNXT_RE_ABI_VERSION; |
---|
563 | 713 | ibdev->uverbs_cmd_mask = |
---|
564 | 714 | (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) | |
---|
565 | 715 | (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) | |
---|
.. | .. |
---|
587 | 737 | (1ull << IB_USER_VERBS_CMD_DESTROY_AH); |
---|
588 | 738 | /* POLL_CQ and REQ_NOTIFY_CQ is directly handled in libbnxt_re */ |
---|
589 | 739 | |
---|
590 | | - /* Kernel verbs */ |
---|
591 | | - ibdev->query_device = bnxt_re_query_device; |
---|
592 | | - ibdev->modify_device = bnxt_re_modify_device; |
---|
593 | 740 | |
---|
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; |
---|
602 | 746 | |
---|
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); |
---|
644 | 749 | } |
---|
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 | | -}; |
---|
669 | 750 | |
---|
670 | 751 | static void bnxt_re_dev_remove(struct bnxt_re_dev *rdev) |
---|
671 | 752 | { |
---|
672 | 753 | dev_put(rdev->netdev); |
---|
673 | 754 | rdev->netdev = NULL; |
---|
674 | | - |
---|
675 | 755 | mutex_lock(&bnxt_re_dev_lock); |
---|
676 | 756 | list_del_rcu(&rdev->list); |
---|
677 | 757 | mutex_unlock(&bnxt_re_dev_lock); |
---|
678 | 758 | |
---|
679 | 759 | synchronize_rcu(); |
---|
680 | | - |
---|
681 | | - ib_dealloc_device(&rdev->ibdev); |
---|
682 | | - /* rdev is gone */ |
---|
683 | 760 | } |
---|
684 | 761 | |
---|
685 | 762 | static struct bnxt_re_dev *bnxt_re_dev_add(struct net_device *netdev, |
---|
.. | .. |
---|
688 | 765 | struct bnxt_re_dev *rdev; |
---|
689 | 766 | |
---|
690 | 767 | /* 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); |
---|
692 | 769 | 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); |
---|
695 | 772 | return NULL; |
---|
696 | 773 | } |
---|
697 | 774 | /* Default values */ |
---|
.. | .. |
---|
821 | 898 | int rc = 0; |
---|
822 | 899 | |
---|
823 | 900 | 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); |
---|
826 | 903 | rc = -EINVAL; |
---|
827 | 904 | goto done; |
---|
828 | 905 | } |
---|
.. | .. |
---|
849 | 926 | qplib_cq); |
---|
850 | 927 | |
---|
851 | 928 | 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); |
---|
854 | 931 | return -EINVAL; |
---|
855 | 932 | } |
---|
856 | 933 | if (cq->ib_cq.comp_handler) { |
---|
.. | .. |
---|
859 | 936 | } |
---|
860 | 937 | |
---|
861 | 938 | 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; |
---|
862 | 949 | } |
---|
863 | 950 | |
---|
864 | 951 | static void bnxt_re_cleanup_res(struct bnxt_re_dev *rdev) |
---|
.. | .. |
---|
874 | 961 | |
---|
875 | 962 | static int bnxt_re_init_res(struct bnxt_re_dev *rdev) |
---|
876 | 963 | { |
---|
877 | | - int rc = 0, i; |
---|
878 | 964 | int num_vec_enabled = 0; |
---|
| 965 | + int rc = 0, i; |
---|
| 966 | + u32 db_offt; |
---|
879 | 967 | |
---|
880 | 968 | bnxt_qplib_init_res(&rdev->qplib_res); |
---|
881 | 969 | |
---|
882 | 970 | for (i = 1; i < rdev->num_msix ; i++) { |
---|
| 971 | + db_offt = bnxt_re_get_nqdb_offset(rdev, i); |
---|
883 | 972 | rc = bnxt_qplib_enable_nq(rdev->en_dev->pdev, &rdev->nq[i - 1], |
---|
884 | 973 | 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, |
---|
887 | 975 | &bnxt_re_srqn_handler); |
---|
888 | | - |
---|
889 | 976 | 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); |
---|
892 | 979 | goto fail; |
---|
893 | 980 | } |
---|
894 | 981 | num_vec_enabled++; |
---|
.. | .. |
---|
897 | 984 | fail: |
---|
898 | 985 | for (i = num_vec_enabled; i >= 0; i--) |
---|
899 | 986 | bnxt_qplib_disable_nq(&rdev->nq[i]); |
---|
900 | | - |
---|
901 | 987 | return rc; |
---|
902 | 988 | } |
---|
903 | 989 | |
---|
904 | 990 | static void bnxt_re_free_nq_res(struct bnxt_re_dev *rdev) |
---|
905 | 991 | { |
---|
| 992 | + u8 type; |
---|
906 | 993 | int i; |
---|
907 | 994 | |
---|
908 | 995 | 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); |
---|
910 | 998 | bnxt_qplib_free_nq(&rdev->nq[i]); |
---|
| 999 | + rdev->nq[i].res = NULL; |
---|
911 | 1000 | } |
---|
912 | 1001 | } |
---|
913 | 1002 | |
---|
.. | .. |
---|
928 | 1017 | |
---|
929 | 1018 | static int bnxt_re_alloc_res(struct bnxt_re_dev *rdev) |
---|
930 | 1019 | { |
---|
931 | | - int rc = 0, i; |
---|
| 1020 | + struct bnxt_re_ring_attr rattr = {}; |
---|
932 | 1021 | int num_vec_created = 0; |
---|
| 1022 | + int rc = 0, i; |
---|
| 1023 | + u8 type; |
---|
933 | 1024 | |
---|
934 | 1025 | /* Configure and allocate resources for qplib */ |
---|
935 | 1026 | rdev->qplib_res.rcfw = &rdev->rcfw; |
---|
.. | .. |
---|
950 | 1041 | goto dealloc_res; |
---|
951 | 1042 | |
---|
952 | 1043 | 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]); |
---|
956 | 1049 | 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); |
---|
959 | 1052 | goto free_nq; |
---|
960 | 1053 | } |
---|
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); |
---|
968 | 1062 | 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); |
---|
972 | 1066 | bnxt_qplib_free_nq(&rdev->nq[i]); |
---|
973 | 1067 | goto free_nq; |
---|
974 | 1068 | } |
---|
.. | .. |
---|
976 | 1070 | } |
---|
977 | 1071 | return 0; |
---|
978 | 1072 | 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); |
---|
981 | 1076 | bnxt_qplib_free_nq(&rdev->nq[i]); |
---|
982 | 1077 | } |
---|
983 | 1078 | bnxt_qplib_dealloc_dpi(&rdev->qplib_res, |
---|
.. | .. |
---|
1041 | 1136 | return rc; |
---|
1042 | 1137 | |
---|
1043 | 1138 | 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"); |
---|
1048 | 1143 | } |
---|
1049 | 1144 | qcfgmap = &resp.pri0_cos_queue_id; |
---|
1050 | 1145 | tmp_map = (u8 *)cid_map; |
---|
.. | .. |
---|
1057 | 1152 | static bool bnxt_re_is_qp1_or_shadow_qp(struct bnxt_re_dev *rdev, |
---|
1058 | 1153 | struct bnxt_re_qp *qp) |
---|
1059 | 1154 | { |
---|
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); |
---|
1061 | 1157 | } |
---|
1062 | 1158 | |
---|
1063 | 1159 | static void bnxt_re_dev_stop(struct bnxt_re_dev *rdev) |
---|
.. | .. |
---|
1092 | 1188 | u16 gid_idx, index; |
---|
1093 | 1189 | int rc = 0; |
---|
1094 | 1190 | |
---|
1095 | | - if (!test_bit(BNXT_RE_FLAG_IBDEV_REGISTERED, &rdev->flags)) |
---|
| 1191 | + if (!ib_device_try_get(&rdev->ibdev)) |
---|
1096 | 1192 | return 0; |
---|
1097 | | - |
---|
1098 | | - if (!sgid_tbl) { |
---|
1099 | | - dev_err(rdev_to_dev(rdev), "QPLIB: SGID table not allocated"); |
---|
1100 | | - return -EINVAL; |
---|
1101 | | - } |
---|
1102 | 1193 | |
---|
1103 | 1194 | for (index = 0; index < sgid_tbl->active; index++) { |
---|
1104 | 1195 | gid_idx = sgid_tbl->hw_id[index]; |
---|
.. | .. |
---|
1118 | 1209 | rdev->qplib_res.netdev->dev_addr); |
---|
1119 | 1210 | } |
---|
1120 | 1211 | |
---|
| 1212 | + ib_device_put(&rdev->ibdev); |
---|
1121 | 1213 | return rc; |
---|
1122 | 1214 | } |
---|
1123 | 1215 | |
---|
.. | .. |
---|
1173 | 1265 | /* Get cosq id for this priority */ |
---|
1174 | 1266 | rc = bnxt_re_query_hwrm_pri2cos(rdev, 0, &cid_map); |
---|
1175 | 1267 | 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); |
---|
1177 | 1269 | return rc; |
---|
1178 | 1270 | } |
---|
1179 | 1271 | /* Parse CoS IDs for app priority */ |
---|
.. | .. |
---|
1182 | 1274 | /* Config BONO. */ |
---|
1183 | 1275 | rc = bnxt_qplib_map_tc2cos(&rdev->qplib_res, rdev->cosq); |
---|
1184 | 1276 | 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]); |
---|
1187 | 1279 | return rc; |
---|
1188 | 1280 | } |
---|
1189 | 1281 | |
---|
.. | .. |
---|
1200 | 1292 | return 0; |
---|
1201 | 1293 | } |
---|
1202 | 1294 | |
---|
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) |
---|
1204 | 1296 | { |
---|
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; |
---|
1206 | 1302 | |
---|
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; |
---|
1213 | 1316 | } |
---|
| 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 | + |
---|
1214 | 1353 | 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); |
---|
1216 | 1355 | |
---|
1217 | 1356 | if (test_and_clear_bit(BNXT_RE_FLAG_RESOURCES_INITIALIZED, |
---|
1218 | 1357 | &rdev->flags)) |
---|
.. | .. |
---|
1223 | 1362 | if (test_and_clear_bit(BNXT_RE_FLAG_RCFW_CHANNEL_EN, &rdev->flags)) { |
---|
1224 | 1363 | rc = bnxt_qplib_deinit_rcfw(&rdev->rcfw); |
---|
1225 | 1364 | 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); |
---|
1228 | 1367 | 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); |
---|
1230 | 1369 | 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); |
---|
1232 | 1372 | bnxt_qplib_free_rcfw_channel(&rdev->rcfw); |
---|
1233 | 1373 | } |
---|
1234 | 1374 | if (test_and_clear_bit(BNXT_RE_FLAG_GOT_MSIX, &rdev->flags)) { |
---|
1235 | 1375 | rc = bnxt_re_free_msix(rdev); |
---|
1236 | 1376 | 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); |
---|
1239 | 1379 | } |
---|
| 1380 | + |
---|
| 1381 | + bnxt_re_destroy_chip_ctx(rdev); |
---|
1240 | 1382 | if (test_and_clear_bit(BNXT_RE_FLAG_NETDEV_REGISTERED, &rdev->flags)) { |
---|
1241 | 1383 | rc = bnxt_re_unregister_netdev(rdev); |
---|
1242 | 1384 | 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); |
---|
1245 | 1387 | } |
---|
1246 | 1388 | } |
---|
1247 | 1389 | |
---|
.. | .. |
---|
1255 | 1397 | schedule_delayed_work(&rdev->worker, msecs_to_jiffies(30000)); |
---|
1256 | 1398 | } |
---|
1257 | 1399 | |
---|
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) |
---|
1259 | 1401 | { |
---|
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; |
---|
1267 | 1408 | |
---|
1268 | 1409 | /* Registered a new RoCE device instance to netdev */ |
---|
| 1410 | + memset(&rattr, 0, sizeof(rattr)); |
---|
1269 | 1411 | rc = bnxt_re_register_netdev(rdev); |
---|
1270 | 1412 | 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); |
---|
1273 | 1415 | return -EINVAL; |
---|
1274 | 1416 | } |
---|
1275 | 1417 | 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 | + } |
---|
1276 | 1424 | |
---|
1277 | 1425 | /* Check whether VF or PF */ |
---|
1278 | 1426 | bnxt_re_get_sriov_func_type(rdev); |
---|
1279 | 1427 | |
---|
1280 | 1428 | rc = bnxt_re_request_msix(rdev); |
---|
1281 | 1429 | 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); |
---|
1283 | 1432 | rc = -EINVAL; |
---|
1284 | 1433 | goto fail; |
---|
1285 | 1434 | } |
---|
1286 | 1435 | set_bit(BNXT_RE_FLAG_GOT_MSIX, &rdev->flags); |
---|
1287 | 1436 | |
---|
| 1437 | + bnxt_re_query_hwrm_intf_version(rdev); |
---|
| 1438 | + |
---|
1288 | 1439 | /* Establish RCFW Communication Channel to initialize the context |
---|
1289 | 1440 | * memory for the function and all child VFs |
---|
1290 | 1441 | */ |
---|
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, |
---|
1292 | 1444 | BNXT_RE_MAX_QPC_COUNT); |
---|
1293 | 1445 | 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); |
---|
1295 | 1448 | goto fail; |
---|
1296 | 1449 | } |
---|
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); |
---|
1303 | 1460 | if (rc) { |
---|
1304 | | - pr_err("Failed to allocate CREQ: %#x\n", rc); |
---|
| 1461 | + ibdev_err(&rdev->ibdev, "Failed to allocate CREQ: %#x\n", rc); |
---|
1305 | 1462 | goto free_rcfw; |
---|
1306 | 1463 | } |
---|
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); |
---|
1312 | 1469 | 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); |
---|
1314 | 1472 | goto free_ring; |
---|
1315 | 1473 | } |
---|
1316 | 1474 | |
---|
.. | .. |
---|
1318 | 1476 | rdev->is_virtfn); |
---|
1319 | 1477 | if (rc) |
---|
1320 | 1478 | goto disable_rcfw; |
---|
1321 | | - if (!rdev->is_virtfn) |
---|
1322 | | - bnxt_re_set_resource_limits(rdev); |
---|
1323 | 1479 | |
---|
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)); |
---|
1325 | 1484 | 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); |
---|
1327 | 1487 | goto disable_rcfw; |
---|
1328 | 1488 | } |
---|
1329 | 1489 | rc = bnxt_re_net_stats_ctx_alloc(rdev, |
---|
1330 | 1490 | rdev->qplib_ctx.stats.dma_map, |
---|
1331 | 1491 | &rdev->qplib_ctx.stats.fw_id); |
---|
1332 | 1492 | 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); |
---|
1334 | 1495 | goto free_ctx; |
---|
1335 | 1496 | } |
---|
1336 | 1497 | |
---|
1337 | 1498 | rc = bnxt_qplib_init_rcfw(&rdev->rcfw, &rdev->qplib_ctx, |
---|
1338 | 1499 | rdev->is_virtfn); |
---|
1339 | 1500 | 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); |
---|
1341 | 1503 | goto free_sctx; |
---|
1342 | 1504 | } |
---|
1343 | 1505 | set_bit(BNXT_RE_FLAG_RCFW_CHANNEL_EN, &rdev->flags); |
---|
.. | .. |
---|
1345 | 1507 | /* Resources based on the 'new' device caps */ |
---|
1346 | 1508 | rc = bnxt_re_alloc_res(rdev); |
---|
1347 | 1509 | 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); |
---|
1349 | 1512 | goto fail; |
---|
1350 | 1513 | } |
---|
1351 | 1514 | set_bit(BNXT_RE_FLAG_RESOURCES_ALLOCATED, &rdev->flags); |
---|
1352 | 1515 | rc = bnxt_re_init_res(rdev); |
---|
1353 | 1516 | 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); |
---|
1355 | 1519 | goto fail; |
---|
1356 | 1520 | } |
---|
1357 | 1521 | |
---|
.. | .. |
---|
1360 | 1524 | if (!rdev->is_virtfn) { |
---|
1361 | 1525 | rc = bnxt_re_setup_qos(rdev); |
---|
1362 | 1526 | if (rc) |
---|
1363 | | - pr_info("RoCE priority not yet configured\n"); |
---|
| 1527 | + ibdev_info(&rdev->ibdev, |
---|
| 1528 | + "RoCE priority not yet configured\n"); |
---|
1364 | 1529 | |
---|
1365 | 1530 | INIT_DELAYED_WORK(&rdev->worker, bnxt_re_worker); |
---|
1366 | 1531 | set_bit(BNXT_RE_FLAG_QOS_WORK_REG, &rdev->flags); |
---|
1367 | 1532 | schedule_delayed_work(&rdev->worker, msecs_to_jiffies(30000)); |
---|
1368 | 1533 | } |
---|
1369 | 1534 | |
---|
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 | | - |
---|
1401 | 1535 | return 0; |
---|
1402 | 1536 | free_sctx: |
---|
1403 | 1537 | bnxt_re_net_stats_ctx_free(rdev, rdev->qplib_ctx.stats.fw_id); |
---|
1404 | 1538 | 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); |
---|
1406 | 1540 | disable_rcfw: |
---|
1407 | 1541 | bnxt_qplib_disable_rcfw_channel(&rdev->rcfw); |
---|
1408 | 1542 | 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); |
---|
1410 | 1545 | free_rcfw: |
---|
1411 | 1546 | bnxt_qplib_free_rcfw_channel(&rdev->rcfw); |
---|
1412 | 1547 | fail: |
---|
1413 | | - if (!locked) |
---|
1414 | | - rtnl_lock(); |
---|
1415 | | - bnxt_re_ib_unreg(rdev); |
---|
1416 | | - rtnl_unlock(); |
---|
| 1548 | + bnxt_re_dev_uninit(rdev); |
---|
1417 | 1549 | |
---|
1418 | 1550 | return rc; |
---|
1419 | 1551 | } |
---|
.. | .. |
---|
1440 | 1572 | en_dev = bnxt_re_dev_probe(netdev); |
---|
1441 | 1573 | if (IS_ERR(en_dev)) { |
---|
1442 | 1574 | 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); |
---|
1444 | 1577 | rc = PTR_ERR(en_dev); |
---|
1445 | 1578 | goto exit; |
---|
1446 | 1579 | } |
---|
.. | .. |
---|
1454 | 1587 | return rc; |
---|
1455 | 1588 | } |
---|
1456 | 1589 | |
---|
1457 | | -static void bnxt_re_remove_one(struct bnxt_re_dev *rdev) |
---|
| 1590 | +static void bnxt_re_remove_device(struct bnxt_re_dev *rdev) |
---|
1458 | 1591 | { |
---|
| 1592 | + bnxt_re_dev_uninit(rdev); |
---|
1459 | 1593 | 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(); |
---|
1460 | 1631 | } |
---|
1461 | 1632 | |
---|
1462 | 1633 | /* Handle all deferred netevents tasks */ |
---|
.. | .. |
---|
1469 | 1640 | re_work = container_of(work, struct bnxt_re_work, work); |
---|
1470 | 1641 | rdev = re_work->rdev; |
---|
1471 | 1642 | |
---|
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); |
---|
1479 | 1645 | 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(); |
---|
1484 | 1651 | goto exit; |
---|
1485 | 1652 | } |
---|
1486 | | - break; |
---|
| 1653 | + goto exit; |
---|
| 1654 | + } |
---|
| 1655 | + |
---|
| 1656 | + if (!ib_device_try_get(&rdev->ibdev)) |
---|
| 1657 | + goto exit; |
---|
| 1658 | + |
---|
| 1659 | + switch (re_work->event) { |
---|
1487 | 1660 | case NETDEV_UP: |
---|
1488 | 1661 | bnxt_re_dispatch_event(&rdev->ibdev, NULL, 1, |
---|
1489 | 1662 | IB_EVENT_PORT_ACTIVE); |
---|
.. | .. |
---|
1503 | 1676 | default: |
---|
1504 | 1677 | break; |
---|
1505 | 1678 | } |
---|
1506 | | - smp_mb__before_atomic(); |
---|
1507 | | - atomic_dec(&rdev->sched_count); |
---|
| 1679 | + ib_device_put(&rdev->ibdev); |
---|
1508 | 1680 | exit: |
---|
| 1681 | + put_device(&rdev->ibdev.dev); |
---|
1509 | 1682 | 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); |
---|
1515 | 1683 | } |
---|
1516 | 1684 | |
---|
1517 | 1685 | /* |
---|
.. | .. |
---|
1536 | 1704 | struct bnxt_re_dev *rdev; |
---|
1537 | 1705 | int rc = 0; |
---|
1538 | 1706 | bool sch_work = false; |
---|
| 1707 | + bool release = true; |
---|
1539 | 1708 | |
---|
1540 | 1709 | real_dev = rdma_vlan_dev_real_dev(netdev); |
---|
1541 | 1710 | if (!real_dev) |
---|
.. | .. |
---|
1543 | 1712 | |
---|
1544 | 1713 | rdev = bnxt_re_from_netdev(real_dev); |
---|
1545 | 1714 | if (!rdev && event != NETDEV_REGISTER) |
---|
1546 | | - goto exit; |
---|
| 1715 | + return NOTIFY_OK; |
---|
| 1716 | + |
---|
1547 | 1717 | if (real_dev != netdev) |
---|
1548 | 1718 | goto exit; |
---|
1549 | 1719 | |
---|
.. | .. |
---|
1551 | 1721 | case NETDEV_REGISTER: |
---|
1552 | 1722 | if (rdev) |
---|
1553 | 1723 | 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; |
---|
1564 | 1729 | break; |
---|
1565 | 1730 | |
---|
1566 | 1731 | 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); |
---|
1575 | 1733 | break; |
---|
1576 | 1734 | |
---|
1577 | 1735 | default: |
---|
.. | .. |
---|
1582 | 1740 | /* Allocate for the deferred task */ |
---|
1583 | 1741 | re_work = kzalloc(sizeof(*re_work), GFP_ATOMIC); |
---|
1584 | 1742 | if (re_work) { |
---|
| 1743 | + get_device(&rdev->ibdev.dev); |
---|
1585 | 1744 | re_work->rdev = rdev; |
---|
1586 | 1745 | re_work->event = event; |
---|
1587 | 1746 | re_work->vlan_dev = (real_dev == netdev ? |
---|
1588 | 1747 | NULL : netdev); |
---|
1589 | 1748 | INIT_WORK(&re_work->work, bnxt_re_task); |
---|
1590 | | - atomic_inc(&rdev->sched_count); |
---|
1591 | 1749 | queue_work(bnxt_re_wq, &re_work->work); |
---|
1592 | 1750 | } |
---|
1593 | 1751 | } |
---|
1594 | 1752 | |
---|
1595 | 1753 | exit: |
---|
| 1754 | + if (rdev && release) |
---|
| 1755 | + ib_device_put(&rdev->ibdev); |
---|
1596 | 1756 | return NOTIFY_DONE; |
---|
1597 | 1757 | } |
---|
1598 | 1758 | |
---|
.. | .. |
---|
1628 | 1788 | |
---|
1629 | 1789 | static void __exit bnxt_re_mod_exit(void) |
---|
1630 | 1790 | { |
---|
1631 | | - struct bnxt_re_dev *rdev, *next; |
---|
1632 | | - LIST_HEAD(to_be_deleted); |
---|
| 1791 | + struct bnxt_re_dev *rdev; |
---|
1633 | 1792 | |
---|
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 | | - } |
---|
1658 | 1793 | unregister_netdevice_notifier(&bnxt_re_netdev_notifier); |
---|
1659 | 1794 | if (bnxt_re_wq) |
---|
1660 | 1795 | 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); |
---|
1661 | 1806 | } |
---|
1662 | 1807 | |
---|
1663 | 1808 | module_init(bnxt_re_mod_init); |
---|