4 * Copyright(c) Broadcom Limited.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Broadcom Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include <rte_byteorder.h>
37 #include <rte_common.h>
38 #include <rte_cycles.h>
39 #include <rte_malloc.h>
40 #include <rte_memzone.h>
41 #include <rte_version.h>
45 #include "bnxt_filter.h"
46 #include "bnxt_hwrm.h"
49 #include "bnxt_ring.h"
52 #include "bnxt_vnic.h"
53 #include "hsi_struct_def_dpdk.h"
57 #define HWRM_CMD_TIMEOUT 2000
59 struct bnxt_plcmodes_cfg {
61 uint16_t jumbo_thresh;
63 uint16_t hds_threshold;
66 static int page_getenum(size_t size)
82 RTE_LOG(ERR, PMD, "Page size %zu out of range\n", size);
83 return sizeof(void *) * 8 - 1;
86 static int page_roundup(size_t size)
88 return 1 << page_getenum(size);
92 * HWRM Functions (sent to HWRM)
93 * These are named bnxt_hwrm_*() and return -1 if bnxt_hwrm_send_message()
94 * fails (ie: a timeout), and a positive non-zero HWRM error code if the HWRM
95 * command was failed by the ChiMP.
98 static int bnxt_hwrm_send_message_locked(struct bnxt *bp, void *msg,
102 struct input *req = msg;
103 struct output *resp = bp->hwrm_cmd_resp_addr;
104 uint32_t *data = msg;
108 /* Write request msg to hwrm channel */
109 for (i = 0; i < msg_len; i += 4) {
110 bar = (uint8_t *)bp->bar0 + i;
111 rte_write32(*data, bar);
115 /* Zero the rest of the request space */
116 for (; i < bp->max_req_len; i += 4) {
117 bar = (uint8_t *)bp->bar0 + i;
121 /* Ring channel doorbell */
122 bar = (uint8_t *)bp->bar0 + 0x100;
125 /* Poll for the valid bit */
126 for (i = 0; i < HWRM_CMD_TIMEOUT; i++) {
127 /* Sanity check on the resp->resp_len */
129 if (resp->resp_len && resp->resp_len <=
131 /* Last byte of resp contains the valid key */
132 valid = (uint8_t *)resp + resp->resp_len - 1;
133 if (*valid == HWRM_RESP_VALID_KEY)
139 if (i >= HWRM_CMD_TIMEOUT) {
140 RTE_LOG(ERR, PMD, "Error sending msg %x\n",
150 static int bnxt_hwrm_send_message(struct bnxt *bp, void *msg, uint32_t msg_len)
154 rte_spinlock_lock(&bp->hwrm_lock);
155 rc = bnxt_hwrm_send_message_locked(bp, msg, msg_len);
156 rte_spinlock_unlock(&bp->hwrm_lock);
160 #define HWRM_PREP(req, type, cr, resp) \
161 memset(bp->hwrm_cmd_resp_addr, 0, bp->max_resp_len); \
162 req.req_type = rte_cpu_to_le_16(HWRM_##type); \
163 req.cmpl_ring = rte_cpu_to_le_16(cr); \
164 req.seq_id = rte_cpu_to_le_16(bp->hwrm_cmd_seq++); \
165 req.target_id = rte_cpu_to_le_16(0xffff); \
166 req.resp_addr = rte_cpu_to_le_64(bp->hwrm_cmd_resp_dma_addr)
168 #define HWRM_CHECK_RESULT \
171 RTE_LOG(ERR, PMD, "%s failed rc:%d\n", \
175 if (resp->error_code) { \
176 rc = rte_le_to_cpu_16(resp->error_code); \
177 RTE_LOG(ERR, PMD, "%s error %d\n", __func__, rc); \
182 int bnxt_hwrm_cfa_l2_clear_rx_mask(struct bnxt *bp, struct bnxt_vnic_info *vnic)
185 struct hwrm_cfa_l2_set_rx_mask_input req = {.req_type = 0 };
186 struct hwrm_cfa_l2_set_rx_mask_output *resp = bp->hwrm_cmd_resp_addr;
188 HWRM_PREP(req, CFA_L2_SET_RX_MASK, -1, resp);
189 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
192 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
199 int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp, struct bnxt_vnic_info *vnic)
202 struct hwrm_cfa_l2_set_rx_mask_input req = {.req_type = 0 };
203 struct hwrm_cfa_l2_set_rx_mask_output *resp = bp->hwrm_cmd_resp_addr;
206 HWRM_PREP(req, CFA_L2_SET_RX_MASK, -1, resp);
207 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
209 /* FIXME add multicast flag, when multicast adding options is supported
212 if (vnic->flags & BNXT_VNIC_INFO_PROMISC)
213 mask = HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_PROMISCUOUS;
214 if (vnic->flags & BNXT_VNIC_INFO_ALLMULTI)
215 mask = HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
216 req.mask = rte_cpu_to_le_32(HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_BCAST |
219 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
226 int bnxt_hwrm_clear_filter(struct bnxt *bp,
227 struct bnxt_filter_info *filter)
230 struct hwrm_cfa_l2_filter_free_input req = {.req_type = 0 };
231 struct hwrm_cfa_l2_filter_free_output *resp = bp->hwrm_cmd_resp_addr;
233 HWRM_PREP(req, CFA_L2_FILTER_FREE, -1, resp);
235 req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
237 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
241 filter->fw_l2_filter_id = -1;
246 int bnxt_hwrm_set_filter(struct bnxt *bp,
247 struct bnxt_vnic_info *vnic,
248 struct bnxt_filter_info *filter)
251 struct hwrm_cfa_l2_filter_alloc_input req = {.req_type = 0 };
252 struct hwrm_cfa_l2_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr;
253 uint32_t enables = 0;
255 HWRM_PREP(req, CFA_L2_FILTER_ALLOC, -1, resp);
257 req.flags = rte_cpu_to_le_32(filter->flags);
259 enables = filter->enables |
260 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_DST_ID;
261 req.dst_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
264 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR)
265 memcpy(req.l2_addr, filter->l2_addr,
268 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR_MASK)
269 memcpy(req.l2_addr_mask, filter->l2_addr_mask,
272 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN)
273 req.l2_ovlan = filter->l2_ovlan;
275 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN_MASK)
276 req.l2_ovlan_mask = filter->l2_ovlan_mask;
278 req.enables = rte_cpu_to_le_32(enables);
280 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
284 filter->fw_l2_filter_id = rte_le_to_cpu_64(resp->l2_filter_id);
289 int bnxt_hwrm_exec_fwd_resp(struct bnxt *bp, void *fwd_cmd)
292 struct hwrm_exec_fwd_resp_input req = {.req_type = 0 };
293 struct hwrm_exec_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr;
295 HWRM_PREP(req, EXEC_FWD_RESP, -1, resp);
297 memcpy(req.encap_request, fwd_cmd,
298 sizeof(req.encap_request));
300 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
307 int bnxt_hwrm_func_qcaps(struct bnxt *bp)
310 struct hwrm_func_qcaps_input req = {.req_type = 0 };
311 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
312 uint16_t new_max_vfs;
315 HWRM_PREP(req, FUNC_QCAPS, -1, resp);
317 req.fid = rte_cpu_to_le_16(0xffff);
319 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
323 bp->max_ring_grps = rte_le_to_cpu_32(resp->max_hw_ring_grps);
325 bp->pf.port_id = resp->port_id;
326 bp->pf.first_vf_id = rte_le_to_cpu_16(resp->first_vf_id);
327 new_max_vfs = bp->pdev->max_vfs;
328 if (new_max_vfs != bp->pf.max_vfs) {
330 rte_free(bp->pf.vf_info);
331 bp->pf.vf_info = rte_malloc("bnxt_vf_info",
332 sizeof(bp->pf.vf_info[0]) * new_max_vfs, 0);
333 bp->pf.max_vfs = new_max_vfs;
334 for (i = 0; i < new_max_vfs; i++) {
335 bp->pf.vf_info[i].fid = bp->pf.first_vf_id + i;
336 bp->pf.vf_info[i].vlan_table =
337 rte_zmalloc("VF VLAN table",
340 if (bp->pf.vf_info[i].vlan_table == NULL)
342 "Fail to alloc VLAN table for VF %d\n",
346 bp->pf.vf_info[i].vlan_table);
347 STAILQ_INIT(&bp->pf.vf_info[i].filter);
352 bp->fw_fid = rte_le_to_cpu_32(resp->fid);
353 memcpy(bp->dflt_mac_addr, &resp->mac_address, ETHER_ADDR_LEN);
354 bp->max_rsscos_ctx = rte_le_to_cpu_16(resp->max_rsscos_ctx);
355 bp->max_cp_rings = rte_le_to_cpu_16(resp->max_cmpl_rings);
356 bp->max_tx_rings = rte_le_to_cpu_16(resp->max_tx_rings);
357 bp->max_rx_rings = rte_le_to_cpu_16(resp->max_rx_rings);
358 bp->max_l2_ctx = rte_le_to_cpu_16(resp->max_l2_ctxs);
359 /* TODO: For now, do not support VMDq/RFS on VFs. */
364 bp->max_vnics = rte_le_to_cpu_16(resp->max_vnics);
368 bp->max_stat_ctx = rte_le_to_cpu_16(resp->max_stat_ctx);
370 bp->pf.total_vnics = rte_le_to_cpu_16(resp->max_vnics);
375 int bnxt_hwrm_func_reset(struct bnxt *bp)
378 struct hwrm_func_reset_input req = {.req_type = 0 };
379 struct hwrm_func_reset_output *resp = bp->hwrm_cmd_resp_addr;
381 HWRM_PREP(req, FUNC_RESET, -1, resp);
383 req.enables = rte_cpu_to_le_32(0);
385 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
392 int bnxt_hwrm_func_driver_register(struct bnxt *bp)
395 struct hwrm_func_drv_rgtr_input req = {.req_type = 0 };
396 struct hwrm_func_drv_rgtr_output *resp = bp->hwrm_cmd_resp_addr;
398 if (bp->flags & BNXT_FLAG_REGISTERED)
401 HWRM_PREP(req, FUNC_DRV_RGTR, -1, resp);
402 req.enables = rte_cpu_to_le_32(HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_VER |
403 HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_ASYNC_EVENT_FWD);
404 req.ver_maj = RTE_VER_YEAR;
405 req.ver_min = RTE_VER_MONTH;
406 req.ver_upd = RTE_VER_MINOR;
409 req.enables |= rte_cpu_to_le_32(
410 HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_VF_INPUT_FWD);
411 memcpy(req.vf_req_fwd, bp->pf.vf_req_fwd,
412 RTE_MIN(sizeof(req.vf_req_fwd),
413 sizeof(bp->pf.vf_req_fwd)));
416 req.async_event_fwd[0] |= rte_cpu_to_le_32(0x1); /* TODO: Use MACRO */
417 memset(req.async_event_fwd, 0xff, sizeof(req.async_event_fwd));
419 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
423 bp->flags |= BNXT_FLAG_REGISTERED;
428 int bnxt_hwrm_ver_get(struct bnxt *bp)
431 struct hwrm_ver_get_input req = {.req_type = 0 };
432 struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr;
435 uint16_t max_resp_len;
436 char type[RTE_MEMZONE_NAMESIZE];
438 HWRM_PREP(req, VER_GET, -1, resp);
440 req.hwrm_intf_maj = HWRM_VERSION_MAJOR;
441 req.hwrm_intf_min = HWRM_VERSION_MINOR;
442 req.hwrm_intf_upd = HWRM_VERSION_UPDATE;
445 * Hold the lock since we may be adjusting the response pointers.
447 rte_spinlock_lock(&bp->hwrm_lock);
448 rc = bnxt_hwrm_send_message_locked(bp, &req, sizeof(req));
452 RTE_LOG(INFO, PMD, "%d.%d.%d:%d.%d.%d\n",
453 resp->hwrm_intf_maj, resp->hwrm_intf_min,
455 resp->hwrm_fw_maj, resp->hwrm_fw_min, resp->hwrm_fw_bld);
456 bp->fw_ver = (resp->hwrm_fw_maj << 24) | (resp->hwrm_fw_min << 16) |
457 (resp->hwrm_fw_bld << 8) | resp->hwrm_fw_rsvd;
458 RTE_LOG(INFO, PMD, "Driver HWRM version: %d.%d.%d\n",
459 HWRM_VERSION_MAJOR, HWRM_VERSION_MINOR, HWRM_VERSION_UPDATE);
461 my_version = HWRM_VERSION_MAJOR << 16;
462 my_version |= HWRM_VERSION_MINOR << 8;
463 my_version |= HWRM_VERSION_UPDATE;
465 fw_version = resp->hwrm_intf_maj << 16;
466 fw_version |= resp->hwrm_intf_min << 8;
467 fw_version |= resp->hwrm_intf_upd;
469 if (resp->hwrm_intf_maj != HWRM_VERSION_MAJOR) {
470 RTE_LOG(ERR, PMD, "Unsupported firmware API version\n");
475 if (my_version != fw_version) {
476 RTE_LOG(INFO, PMD, "BNXT Driver/HWRM API mismatch.\n");
477 if (my_version < fw_version) {
479 "Firmware API version is newer than driver.\n");
481 "The driver may be missing features.\n");
484 "Firmware API version is older than driver.\n");
486 "Not all driver features may be functional.\n");
490 if (bp->max_req_len > resp->max_req_win_len) {
491 RTE_LOG(ERR, PMD, "Unsupported request length\n");
494 bp->max_req_len = resp->max_req_win_len;
495 max_resp_len = resp->max_resp_len;
496 if (bp->max_resp_len != max_resp_len) {
497 sprintf(type, "bnxt_hwrm_%04x:%02x:%02x:%02x",
498 bp->pdev->addr.domain, bp->pdev->addr.bus,
499 bp->pdev->addr.devid, bp->pdev->addr.function);
501 rte_free(bp->hwrm_cmd_resp_addr);
503 bp->hwrm_cmd_resp_addr = rte_malloc(type, max_resp_len, 0);
504 if (bp->hwrm_cmd_resp_addr == NULL) {
508 bp->hwrm_cmd_resp_dma_addr =
509 rte_malloc_virt2phy(bp->hwrm_cmd_resp_addr);
510 bp->max_resp_len = max_resp_len;
514 rte_spinlock_unlock(&bp->hwrm_lock);
518 int bnxt_hwrm_func_driver_unregister(struct bnxt *bp, uint32_t flags)
521 struct hwrm_func_drv_unrgtr_input req = {.req_type = 0 };
522 struct hwrm_func_drv_unrgtr_output *resp = bp->hwrm_cmd_resp_addr;
524 if (!(bp->flags & BNXT_FLAG_REGISTERED))
527 HWRM_PREP(req, FUNC_DRV_UNRGTR, -1, resp);
530 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
534 bp->flags &= ~BNXT_FLAG_REGISTERED;
539 static int bnxt_hwrm_port_phy_cfg(struct bnxt *bp, struct bnxt_link_info *conf)
542 struct hwrm_port_phy_cfg_input req = {0};
543 struct hwrm_port_phy_cfg_output *resp = bp->hwrm_cmd_resp_addr;
544 uint32_t enables = 0;
546 HWRM_PREP(req, PORT_PHY_CFG, -1, resp);
549 req.flags = rte_cpu_to_le_32(conf->phy_flags);
550 req.force_link_speed = rte_cpu_to_le_16(conf->link_speed);
552 * Note, ChiMP FW 20.2.1 and 20.2.2 return an error when we set
553 * any auto mode, even "none".
555 if (!conf->link_speed) {
556 req.auto_mode |= conf->auto_mode;
557 enables = HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_MODE;
558 req.auto_link_speed_mask = conf->auto_link_speed_mask;
560 HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_LINK_SPEED_MASK;
561 req.auto_link_speed = bp->link_info.auto_link_speed;
563 HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_LINK_SPEED;
565 req.auto_duplex = conf->duplex;
566 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_DUPLEX;
567 req.auto_pause = conf->auto_pause;
568 req.force_pause = conf->force_pause;
569 /* Set force_pause if there is no auto or if there is a force */
570 if (req.auto_pause && !req.force_pause)
571 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_PAUSE;
573 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_FORCE_PAUSE;
575 req.enables = rte_cpu_to_le_32(enables);
578 rte_cpu_to_le_32(HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE_LINK_DWN);
579 RTE_LOG(INFO, PMD, "Force Link Down\n");
582 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
589 static int bnxt_hwrm_port_phy_qcfg(struct bnxt *bp,
590 struct bnxt_link_info *link_info)
593 struct hwrm_port_phy_qcfg_input req = {0};
594 struct hwrm_port_phy_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
596 HWRM_PREP(req, PORT_PHY_QCFG, -1, resp);
598 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
602 link_info->phy_link_status = resp->link;
603 if (link_info->phy_link_status != HWRM_PORT_PHY_QCFG_OUTPUT_LINK_NO_LINK) {
604 link_info->link_up = 1;
605 link_info->link_speed = rte_le_to_cpu_16(resp->link_speed);
607 link_info->link_up = 0;
608 link_info->link_speed = 0;
610 link_info->duplex = resp->duplex;
611 link_info->pause = resp->pause;
612 link_info->auto_pause = resp->auto_pause;
613 link_info->force_pause = resp->force_pause;
614 link_info->auto_mode = resp->auto_mode;
616 link_info->support_speeds = rte_le_to_cpu_16(resp->support_speeds);
617 link_info->auto_link_speed = rte_le_to_cpu_16(resp->auto_link_speed);
618 link_info->preemphasis = rte_le_to_cpu_32(resp->preemphasis);
619 link_info->phy_ver[0] = resp->phy_maj;
620 link_info->phy_ver[1] = resp->phy_min;
621 link_info->phy_ver[2] = resp->phy_bld;
626 int bnxt_hwrm_queue_qportcfg(struct bnxt *bp)
629 struct hwrm_queue_qportcfg_input req = {.req_type = 0 };
630 struct hwrm_queue_qportcfg_output *resp = bp->hwrm_cmd_resp_addr;
632 HWRM_PREP(req, QUEUE_QPORTCFG, -1, resp);
634 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
638 #define GET_QUEUE_INFO(x) \
639 bp->cos_queue[x].id = resp->queue_id##x; \
640 bp->cos_queue[x].profile = resp->queue_id##x##_service_profile
654 int bnxt_hwrm_ring_alloc(struct bnxt *bp,
655 struct bnxt_ring *ring,
656 uint32_t ring_type, uint32_t map_index,
657 uint32_t stats_ctx_id)
660 struct hwrm_ring_alloc_input req = {.req_type = 0 };
661 struct hwrm_ring_alloc_output *resp = bp->hwrm_cmd_resp_addr;
663 HWRM_PREP(req, RING_ALLOC, -1, resp);
665 req.enables = rte_cpu_to_le_32(0);
667 req.page_tbl_addr = rte_cpu_to_le_64(ring->bd_dma);
668 req.fbo = rte_cpu_to_le_32(0);
669 /* Association of ring index with doorbell index */
670 req.logical_id = rte_cpu_to_le_16(map_index);
673 case HWRM_RING_ALLOC_INPUT_RING_TYPE_TX:
674 req.queue_id = bp->cos_queue[0].id;
676 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX:
677 req.ring_type = ring_type;
679 rte_cpu_to_le_16(bp->grp_info[map_index].cp_fw_ring_id);
680 req.length = rte_cpu_to_le_32(ring->ring_size);
681 req.stat_ctx_id = rte_cpu_to_le_16(stats_ctx_id);
682 req.enables = rte_cpu_to_le_32(rte_le_to_cpu_32(req.enables) |
683 HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID);
685 case HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL:
686 req.ring_type = ring_type;
688 * TODO: Some HWRM versions crash with
689 * HWRM_RING_ALLOC_INPUT_INT_MODE_POLL
691 req.int_mode = HWRM_RING_ALLOC_INPUT_INT_MODE_MSIX;
692 req.length = rte_cpu_to_le_32(ring->ring_size);
695 RTE_LOG(ERR, PMD, "hwrm alloc invalid ring type %d\n",
700 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
702 if (rc || resp->error_code) {
703 if (rc == 0 && resp->error_code)
704 rc = rte_le_to_cpu_16(resp->error_code);
706 case HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL:
708 "hwrm_ring_alloc cp failed. rc:%d\n", rc);
710 case HWRM_RING_FREE_INPUT_RING_TYPE_RX:
712 "hwrm_ring_alloc rx failed. rc:%d\n", rc);
714 case HWRM_RING_FREE_INPUT_RING_TYPE_TX:
716 "hwrm_ring_alloc tx failed. rc:%d\n", rc);
719 RTE_LOG(ERR, PMD, "Invalid ring. rc:%d\n", rc);
724 ring->fw_ring_id = rte_le_to_cpu_16(resp->ring_id);
728 int bnxt_hwrm_ring_free(struct bnxt *bp,
729 struct bnxt_ring *ring, uint32_t ring_type)
732 struct hwrm_ring_free_input req = {.req_type = 0 };
733 struct hwrm_ring_free_output *resp = bp->hwrm_cmd_resp_addr;
735 HWRM_PREP(req, RING_FREE, -1, resp);
737 req.ring_type = ring_type;
738 req.ring_id = rte_cpu_to_le_16(ring->fw_ring_id);
740 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
742 if (rc || resp->error_code) {
743 if (rc == 0 && resp->error_code)
744 rc = rte_le_to_cpu_16(resp->error_code);
747 case HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL:
748 RTE_LOG(ERR, PMD, "hwrm_ring_free cp failed. rc:%d\n",
751 case HWRM_RING_FREE_INPUT_RING_TYPE_RX:
752 RTE_LOG(ERR, PMD, "hwrm_ring_free rx failed. rc:%d\n",
755 case HWRM_RING_FREE_INPUT_RING_TYPE_TX:
756 RTE_LOG(ERR, PMD, "hwrm_ring_free tx failed. rc:%d\n",
760 RTE_LOG(ERR, PMD, "Invalid ring, rc:%d\n", rc);
767 int bnxt_hwrm_ring_grp_alloc(struct bnxt *bp, unsigned int idx)
770 struct hwrm_ring_grp_alloc_input req = {.req_type = 0 };
771 struct hwrm_ring_grp_alloc_output *resp = bp->hwrm_cmd_resp_addr;
773 HWRM_PREP(req, RING_GRP_ALLOC, -1, resp);
775 req.cr = rte_cpu_to_le_16(bp->grp_info[idx].cp_fw_ring_id);
776 req.rr = rte_cpu_to_le_16(bp->grp_info[idx].rx_fw_ring_id);
777 req.ar = rte_cpu_to_le_16(bp->grp_info[idx].ag_fw_ring_id);
778 req.sc = rte_cpu_to_le_16(bp->grp_info[idx].fw_stats_ctx);
780 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
784 bp->grp_info[idx].fw_grp_id =
785 rte_le_to_cpu_16(resp->ring_group_id);
790 int bnxt_hwrm_ring_grp_free(struct bnxt *bp, unsigned int idx)
793 struct hwrm_ring_grp_free_input req = {.req_type = 0 };
794 struct hwrm_ring_grp_free_output *resp = bp->hwrm_cmd_resp_addr;
796 HWRM_PREP(req, RING_GRP_FREE, -1, resp);
798 req.ring_group_id = rte_cpu_to_le_16(bp->grp_info[idx].fw_grp_id);
800 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
804 bp->grp_info[idx].fw_grp_id = INVALID_HW_RING_ID;
808 int bnxt_hwrm_stat_clear(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
811 struct hwrm_stat_ctx_clr_stats_input req = {.req_type = 0 };
812 struct hwrm_stat_ctx_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
814 HWRM_PREP(req, STAT_CTX_CLR_STATS, -1, resp);
816 if (cpr->hw_stats_ctx_id == (uint32_t)HWRM_NA_SIGNATURE)
819 req.stat_ctx_id = rte_cpu_to_le_16(cpr->hw_stats_ctx_id);
820 req.seq_id = rte_cpu_to_le_16(bp->hwrm_cmd_seq++);
822 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
829 int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp,
830 struct bnxt_cp_ring_info *cpr, unsigned int idx)
833 struct hwrm_stat_ctx_alloc_input req = {.req_type = 0 };
834 struct hwrm_stat_ctx_alloc_output *resp = bp->hwrm_cmd_resp_addr;
836 HWRM_PREP(req, STAT_CTX_ALLOC, -1, resp);
838 req.update_period_ms = rte_cpu_to_le_32(1000);
840 req.seq_id = rte_cpu_to_le_16(bp->hwrm_cmd_seq++);
842 rte_cpu_to_le_64(cpr->hw_stats_map);
844 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
848 cpr->hw_stats_ctx_id = rte_le_to_cpu_16(resp->stat_ctx_id);
849 bp->grp_info[idx].fw_stats_ctx = cpr->hw_stats_ctx_id;
854 int bnxt_hwrm_stat_ctx_free(struct bnxt *bp,
855 struct bnxt_cp_ring_info *cpr, unsigned int idx)
858 struct hwrm_stat_ctx_free_input req = {.req_type = 0 };
859 struct hwrm_stat_ctx_free_output *resp = bp->hwrm_cmd_resp_addr;
861 HWRM_PREP(req, STAT_CTX_FREE, -1, resp);
863 req.stat_ctx_id = rte_cpu_to_le_16(cpr->hw_stats_ctx_id);
864 req.seq_id = rte_cpu_to_le_16(bp->hwrm_cmd_seq++);
866 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
870 cpr->hw_stats_ctx_id = HWRM_NA_SIGNATURE;
871 bp->grp_info[idx].fw_stats_ctx = cpr->hw_stats_ctx_id;
876 int bnxt_hwrm_vnic_alloc(struct bnxt *bp, struct bnxt_vnic_info *vnic)
879 struct hwrm_vnic_alloc_input req = { 0 };
880 struct hwrm_vnic_alloc_output *resp = bp->hwrm_cmd_resp_addr;
882 /* map ring groups to this vnic */
883 for (i = vnic->start_grp_id, j = 0; i <= vnic->end_grp_id; i++, j++) {
884 if (bp->grp_info[i].fw_grp_id == (uint16_t)HWRM_NA_SIGNATURE) {
886 "Not enough ring groups avail:%x req:%x\n", j,
887 (vnic->end_grp_id - vnic->start_grp_id) + 1);
890 vnic->fw_grp_ids[j] = bp->grp_info[i].fw_grp_id;
892 vnic->dflt_ring_grp = bp->grp_info[vnic->start_grp_id].fw_grp_id;
893 vnic->rss_rule = (uint16_t)HWRM_NA_SIGNATURE;
894 vnic->cos_rule = (uint16_t)HWRM_NA_SIGNATURE;
895 vnic->lb_rule = (uint16_t)HWRM_NA_SIGNATURE;
896 vnic->mru = bp->eth_dev->data->mtu + ETHER_HDR_LEN +
897 ETHER_CRC_LEN + VLAN_TAG_SIZE;
898 HWRM_PREP(req, VNIC_ALLOC, -1, resp);
900 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
904 vnic->fw_vnic_id = rte_le_to_cpu_16(resp->vnic_id);
908 int bnxt_hwrm_vnic_cfg(struct bnxt *bp, struct bnxt_vnic_info *vnic)
911 struct hwrm_vnic_cfg_input req = {.req_type = 0 };
912 struct hwrm_vnic_cfg_output *resp = bp->hwrm_cmd_resp_addr;
913 uint32_t ctx_enable_flag = HWRM_VNIC_CFG_INPUT_ENABLES_RSS_RULE;
915 HWRM_PREP(req, VNIC_CFG, -1, resp);
917 /* Only RSS support for now TBD: COS & LB */
919 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_ENABLES_DFLT_RING_GRP |
920 HWRM_VNIC_CFG_INPUT_ENABLES_MRU);
921 if (vnic->lb_rule != 0xffff)
922 ctx_enable_flag = HWRM_VNIC_CFG_INPUT_ENABLES_LB_RULE;
923 if (vnic->cos_rule != 0xffff)
924 ctx_enable_flag = HWRM_VNIC_CFG_INPUT_ENABLES_COS_RULE;
925 if (vnic->rss_rule != 0xffff)
926 ctx_enable_flag = HWRM_VNIC_CFG_INPUT_ENABLES_RSS_RULE;
927 req.enables |= rte_cpu_to_le_32(ctx_enable_flag);
928 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
929 req.dflt_ring_grp = rte_cpu_to_le_16(vnic->dflt_ring_grp);
930 req.rss_rule = rte_cpu_to_le_16(vnic->rss_rule);
931 req.cos_rule = rte_cpu_to_le_16(vnic->cos_rule);
932 req.lb_rule = rte_cpu_to_le_16(vnic->lb_rule);
933 req.mru = rte_cpu_to_le_16(vnic->mru);
934 if (vnic->func_default)
936 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_DEFAULT);
937 if (vnic->vlan_strip)
939 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_VLAN_STRIP_MODE);
942 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_BD_STALL_MODE);
944 req.flags |= rte_cpu_to_le_32(
945 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_DUAL_VNIC_MODE);
947 req.flags |= rte_cpu_to_le_32(
948 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_ONLY_VNIC_MODE);
949 if (vnic->rss_dflt_cr)
950 req.flags |= rte_cpu_to_le_32(
951 HWRM_VNIC_QCFG_OUTPUT_FLAGS_RSS_DFLT_CR_MODE);
953 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
960 int bnxt_hwrm_vnic_qcfg(struct bnxt *bp, struct bnxt_vnic_info *vnic,
964 struct hwrm_vnic_qcfg_input req = {.req_type = 0 };
965 struct hwrm_vnic_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
967 HWRM_PREP(req, VNIC_QCFG, -1, resp);
970 rte_cpu_to_le_32(HWRM_VNIC_QCFG_INPUT_ENABLES_VF_ID_VALID);
971 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
972 req.vf_id = rte_cpu_to_le_16(fw_vf_id);
974 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
978 vnic->dflt_ring_grp = rte_le_to_cpu_16(resp->dflt_ring_grp);
979 vnic->rss_rule = rte_le_to_cpu_16(resp->rss_rule);
980 vnic->cos_rule = rte_le_to_cpu_16(resp->cos_rule);
981 vnic->lb_rule = rte_le_to_cpu_16(resp->lb_rule);
982 vnic->mru = rte_le_to_cpu_16(resp->mru);
983 vnic->func_default = rte_le_to_cpu_32(
984 resp->flags) & HWRM_VNIC_QCFG_OUTPUT_FLAGS_DEFAULT;
985 vnic->vlan_strip = rte_le_to_cpu_32(resp->flags) &
986 HWRM_VNIC_QCFG_OUTPUT_FLAGS_VLAN_STRIP_MODE;
987 vnic->bd_stall = rte_le_to_cpu_32(resp->flags) &
988 HWRM_VNIC_QCFG_OUTPUT_FLAGS_BD_STALL_MODE;
989 vnic->roce_dual = rte_le_to_cpu_32(resp->flags) &
990 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_DUAL_VNIC_MODE;
991 vnic->roce_only = rte_le_to_cpu_32(resp->flags) &
992 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_ONLY_VNIC_MODE;
993 vnic->rss_dflt_cr = rte_le_to_cpu_32(resp->flags) &
994 HWRM_VNIC_QCFG_OUTPUT_FLAGS_RSS_DFLT_CR_MODE;
999 int bnxt_hwrm_vnic_ctx_alloc(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1002 struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req = {.req_type = 0 };
1003 struct hwrm_vnic_rss_cos_lb_ctx_alloc_output *resp =
1004 bp->hwrm_cmd_resp_addr;
1006 HWRM_PREP(req, VNIC_RSS_COS_LB_CTX_ALLOC, -1, resp);
1008 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1012 vnic->rss_rule = rte_le_to_cpu_16(resp->rss_cos_lb_ctx_id);
1017 int bnxt_hwrm_vnic_ctx_free(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1020 struct hwrm_vnic_rss_cos_lb_ctx_free_input req = {.req_type = 0 };
1021 struct hwrm_vnic_rss_cos_lb_ctx_free_output *resp =
1022 bp->hwrm_cmd_resp_addr;
1024 HWRM_PREP(req, VNIC_RSS_COS_LB_CTX_FREE, -1, resp);
1026 req.rss_cos_lb_ctx_id = rte_cpu_to_le_16(vnic->rss_rule);
1028 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1032 vnic->rss_rule = INVALID_HW_RING_ID;
1037 int bnxt_hwrm_vnic_free(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1040 struct hwrm_vnic_free_input req = {.req_type = 0 };
1041 struct hwrm_vnic_free_output *resp = bp->hwrm_cmd_resp_addr;
1043 if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
1046 HWRM_PREP(req, VNIC_FREE, -1, resp);
1048 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1050 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1054 vnic->fw_vnic_id = INVALID_HW_RING_ID;
1058 int bnxt_hwrm_vnic_rss_cfg(struct bnxt *bp,
1059 struct bnxt_vnic_info *vnic)
1062 struct hwrm_vnic_rss_cfg_input req = {.req_type = 0 };
1063 struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1065 HWRM_PREP(req, VNIC_RSS_CFG, -1, resp);
1067 req.hash_type = rte_cpu_to_le_32(vnic->hash_type);
1069 req.ring_grp_tbl_addr =
1070 rte_cpu_to_le_64(vnic->rss_table_dma_addr);
1071 req.hash_key_tbl_addr =
1072 rte_cpu_to_le_64(vnic->rss_hash_key_dma_addr);
1073 req.rss_ctx_idx = rte_cpu_to_le_16(vnic->rss_rule);
1075 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1082 int bnxt_hwrm_func_vf_mac(struct bnxt *bp, uint16_t vf, const uint8_t *mac_addr)
1084 struct hwrm_func_cfg_input req = {0};
1085 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1088 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[vf].func_cfg_flags);
1089 req.enables = rte_cpu_to_le_32(
1090 HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
1091 memcpy(req.dflt_mac_addr, mac_addr, sizeof(req.dflt_mac_addr));
1092 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
1094 HWRM_PREP(req, FUNC_CFG, -1, resp);
1096 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1099 bp->pf.vf_info[vf].random_mac = false;
1105 * HWRM utility functions
1108 int bnxt_clear_all_hwrm_stat_ctxs(struct bnxt *bp)
1113 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
1114 struct bnxt_tx_queue *txq;
1115 struct bnxt_rx_queue *rxq;
1116 struct bnxt_cp_ring_info *cpr;
1118 if (i >= bp->rx_cp_nr_rings) {
1119 txq = bp->tx_queues[i - bp->rx_cp_nr_rings];
1122 rxq = bp->rx_queues[i];
1126 rc = bnxt_hwrm_stat_clear(bp, cpr);
1133 int bnxt_free_all_hwrm_stat_ctxs(struct bnxt *bp)
1137 struct bnxt_cp_ring_info *cpr;
1139 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
1140 unsigned int idx = i + 1;
1142 if (i >= bp->rx_cp_nr_rings)
1143 cpr = bp->tx_queues[i - bp->rx_cp_nr_rings]->cp_ring;
1145 cpr = bp->rx_queues[i]->cp_ring;
1146 if (cpr->hw_stats_ctx_id != HWRM_NA_SIGNATURE) {
1147 rc = bnxt_hwrm_stat_ctx_free(bp, cpr, idx);
1155 int bnxt_alloc_all_hwrm_stat_ctxs(struct bnxt *bp)
1160 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
1161 struct bnxt_tx_queue *txq;
1162 struct bnxt_rx_queue *rxq;
1163 struct bnxt_cp_ring_info *cpr;
1164 unsigned int idx = i + 1;
1166 if (i >= bp->rx_cp_nr_rings) {
1167 txq = bp->tx_queues[i - bp->rx_cp_nr_rings];
1170 rxq = bp->rx_queues[i];
1174 rc = bnxt_hwrm_stat_ctx_alloc(bp, cpr, idx);
1182 int bnxt_free_all_hwrm_ring_grps(struct bnxt *bp)
1187 for (i = 0; i < bp->rx_cp_nr_rings; i++) {
1188 unsigned int idx = i + 1;
1190 if (bp->grp_info[idx].fw_grp_id == INVALID_HW_RING_ID) {
1192 "Attempt to free invalid ring group %d\n",
1197 rc = bnxt_hwrm_ring_grp_free(bp, idx);
1205 static void bnxt_free_cp_ring(struct bnxt *bp,
1206 struct bnxt_cp_ring_info *cpr, unsigned int idx)
1208 struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
1210 bnxt_hwrm_ring_free(bp, cp_ring,
1211 HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL);
1212 cp_ring->fw_ring_id = INVALID_HW_RING_ID;
1213 bp->grp_info[idx].cp_fw_ring_id = INVALID_HW_RING_ID;
1214 memset(cpr->cp_desc_ring, 0, cpr->cp_ring_struct->ring_size *
1215 sizeof(*cpr->cp_desc_ring));
1216 cpr->cp_raw_cons = 0;
1219 int bnxt_free_all_hwrm_rings(struct bnxt *bp)
1224 for (i = 0; i < bp->tx_cp_nr_rings; i++) {
1225 struct bnxt_tx_queue *txq = bp->tx_queues[i];
1226 struct bnxt_tx_ring_info *txr = txq->tx_ring;
1227 struct bnxt_ring *ring = txr->tx_ring_struct;
1228 struct bnxt_cp_ring_info *cpr = txq->cp_ring;
1229 unsigned int idx = bp->rx_cp_nr_rings + i + 1;
1231 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
1232 bnxt_hwrm_ring_free(bp, ring,
1233 HWRM_RING_FREE_INPUT_RING_TYPE_TX);
1234 ring->fw_ring_id = INVALID_HW_RING_ID;
1235 memset(txr->tx_desc_ring, 0,
1236 txr->tx_ring_struct->ring_size *
1237 sizeof(*txr->tx_desc_ring));
1238 memset(txr->tx_buf_ring, 0,
1239 txr->tx_ring_struct->ring_size *
1240 sizeof(*txr->tx_buf_ring));
1244 if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID)
1245 bnxt_free_cp_ring(bp, cpr, idx);
1248 for (i = 0; i < bp->rx_cp_nr_rings; i++) {
1249 struct bnxt_rx_queue *rxq = bp->rx_queues[i];
1250 struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
1251 struct bnxt_ring *ring = rxr->rx_ring_struct;
1252 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
1253 unsigned int idx = i + 1;
1255 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
1256 bnxt_hwrm_ring_free(bp, ring,
1257 HWRM_RING_FREE_INPUT_RING_TYPE_RX);
1258 ring->fw_ring_id = INVALID_HW_RING_ID;
1259 bp->grp_info[idx].rx_fw_ring_id = INVALID_HW_RING_ID;
1260 memset(rxr->rx_desc_ring, 0,
1261 rxr->rx_ring_struct->ring_size *
1262 sizeof(*rxr->rx_desc_ring));
1263 memset(rxr->rx_buf_ring, 0,
1264 rxr->rx_ring_struct->ring_size *
1265 sizeof(*rxr->rx_buf_ring));
1268 if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID)
1269 bnxt_free_cp_ring(bp, cpr, idx);
1272 /* Default completion ring */
1274 struct bnxt_cp_ring_info *cpr = bp->def_cp_ring;
1276 if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID)
1277 bnxt_free_cp_ring(bp, cpr, 0);
1283 int bnxt_alloc_all_hwrm_ring_grps(struct bnxt *bp)
1288 for (i = 0; i < bp->rx_cp_nr_rings; i++) {
1289 unsigned int idx = i + 1;
1291 if (bp->grp_info[idx].cp_fw_ring_id == INVALID_HW_RING_ID ||
1292 bp->grp_info[idx].rx_fw_ring_id == INVALID_HW_RING_ID)
1295 rc = bnxt_hwrm_ring_grp_alloc(bp, idx);
1303 void bnxt_free_hwrm_resources(struct bnxt *bp)
1305 /* Release memzone */
1306 rte_free(bp->hwrm_cmd_resp_addr);
1307 bp->hwrm_cmd_resp_addr = NULL;
1308 bp->hwrm_cmd_resp_dma_addr = 0;
1311 int bnxt_alloc_hwrm_resources(struct bnxt *bp)
1313 struct rte_pci_device *pdev = bp->pdev;
1314 char type[RTE_MEMZONE_NAMESIZE];
1316 sprintf(type, "bnxt_hwrm_%04x:%02x:%02x:%02x", pdev->addr.domain,
1317 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
1318 bp->max_req_len = HWRM_MAX_REQ_LEN;
1319 bp->max_resp_len = HWRM_MAX_RESP_LEN;
1320 bp->hwrm_cmd_resp_addr = rte_malloc(type, bp->max_resp_len, 0);
1321 if (bp->hwrm_cmd_resp_addr == NULL)
1323 bp->hwrm_cmd_resp_dma_addr =
1324 rte_malloc_virt2phy(bp->hwrm_cmd_resp_addr);
1325 rte_spinlock_init(&bp->hwrm_lock);
1330 int bnxt_clear_hwrm_vnic_filters(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1332 struct bnxt_filter_info *filter;
1335 STAILQ_FOREACH(filter, &vnic->filter, next) {
1336 rc = bnxt_hwrm_clear_filter(bp, filter);
1343 int bnxt_set_hwrm_vnic_filters(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1345 struct bnxt_filter_info *filter;
1348 STAILQ_FOREACH(filter, &vnic->filter, next) {
1349 rc = bnxt_hwrm_set_filter(bp, vnic, filter);
1356 void bnxt_free_all_hwrm_resources(struct bnxt *bp)
1358 struct bnxt_vnic_info *vnic;
1361 if (bp->vnic_info == NULL)
1364 vnic = &bp->vnic_info[0];
1366 bnxt_hwrm_cfa_l2_clear_rx_mask(bp, vnic);
1368 /* VNIC resources */
1369 for (i = 0; i < bp->nr_vnics; i++) {
1370 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
1372 bnxt_clear_hwrm_vnic_filters(bp, vnic);
1374 bnxt_hwrm_vnic_ctx_free(bp, vnic);
1375 bnxt_hwrm_vnic_free(bp, vnic);
1377 /* Ring resources */
1378 bnxt_free_all_hwrm_rings(bp);
1379 bnxt_free_all_hwrm_ring_grps(bp);
1380 bnxt_free_all_hwrm_stat_ctxs(bp);
1383 static uint16_t bnxt_parse_eth_link_duplex(uint32_t conf_link_speed)
1385 uint8_t hw_link_duplex = HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH;
1387 if ((conf_link_speed & ETH_LINK_SPEED_FIXED) == ETH_LINK_SPEED_AUTONEG)
1388 return HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH;
1390 switch (conf_link_speed) {
1391 case ETH_LINK_SPEED_10M_HD:
1392 case ETH_LINK_SPEED_100M_HD:
1393 return HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_HALF;
1395 return hw_link_duplex;
1398 static uint16_t bnxt_parse_eth_link_speed(uint32_t conf_link_speed)
1400 uint16_t eth_link_speed = 0;
1402 if (conf_link_speed == ETH_LINK_SPEED_AUTONEG)
1403 return ETH_LINK_SPEED_AUTONEG;
1405 switch (conf_link_speed & ~ETH_LINK_SPEED_FIXED) {
1406 case ETH_LINK_SPEED_100M:
1407 case ETH_LINK_SPEED_100M_HD:
1409 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_100MB;
1411 case ETH_LINK_SPEED_1G:
1413 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_1GB;
1415 case ETH_LINK_SPEED_2_5G:
1417 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_2_5GB;
1419 case ETH_LINK_SPEED_10G:
1421 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_10GB;
1423 case ETH_LINK_SPEED_20G:
1425 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_20GB;
1427 case ETH_LINK_SPEED_25G:
1429 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_25GB;
1431 case ETH_LINK_SPEED_40G:
1433 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_40GB;
1435 case ETH_LINK_SPEED_50G:
1437 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_50GB;
1441 "Unsupported link speed %d; default to AUTO\n",
1445 return eth_link_speed;
1448 #define BNXT_SUPPORTED_SPEEDS (ETH_LINK_SPEED_100M | ETH_LINK_SPEED_100M_HD | \
1449 ETH_LINK_SPEED_1G | ETH_LINK_SPEED_2_5G | \
1450 ETH_LINK_SPEED_10G | ETH_LINK_SPEED_20G | ETH_LINK_SPEED_25G | \
1451 ETH_LINK_SPEED_40G | ETH_LINK_SPEED_50G)
1453 static int bnxt_valid_link_speed(uint32_t link_speed, uint8_t port_id)
1457 if (link_speed == ETH_LINK_SPEED_AUTONEG)
1460 if (link_speed & ETH_LINK_SPEED_FIXED) {
1461 one_speed = link_speed & ~ETH_LINK_SPEED_FIXED;
1463 if (one_speed & (one_speed - 1)) {
1465 "Invalid advertised speeds (%u) for port %u\n",
1466 link_speed, port_id);
1469 if ((one_speed & BNXT_SUPPORTED_SPEEDS) != one_speed) {
1471 "Unsupported advertised speed (%u) for port %u\n",
1472 link_speed, port_id);
1476 if (!(link_speed & BNXT_SUPPORTED_SPEEDS)) {
1478 "Unsupported advertised speeds (%u) for port %u\n",
1479 link_speed, port_id);
1486 static uint16_t bnxt_parse_eth_link_speed_mask(uint32_t link_speed)
1490 if (link_speed == ETH_LINK_SPEED_AUTONEG)
1491 link_speed = BNXT_SUPPORTED_SPEEDS;
1493 if (link_speed & ETH_LINK_SPEED_100M)
1494 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100MB;
1495 if (link_speed & ETH_LINK_SPEED_100M_HD)
1496 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100MB;
1497 if (link_speed & ETH_LINK_SPEED_1G)
1498 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_1GB;
1499 if (link_speed & ETH_LINK_SPEED_2_5G)
1500 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_2_5GB;
1501 if (link_speed & ETH_LINK_SPEED_10G)
1502 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_10GB;
1503 if (link_speed & ETH_LINK_SPEED_20G)
1504 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_20GB;
1505 if (link_speed & ETH_LINK_SPEED_25G)
1506 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_25GB;
1507 if (link_speed & ETH_LINK_SPEED_40G)
1508 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_40GB;
1509 if (link_speed & ETH_LINK_SPEED_50G)
1510 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_50GB;
1514 static uint32_t bnxt_parse_hw_link_speed(uint16_t hw_link_speed)
1516 uint32_t eth_link_speed = ETH_SPEED_NUM_NONE;
1518 switch (hw_link_speed) {
1519 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100MB:
1520 eth_link_speed = ETH_SPEED_NUM_100M;
1522 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_1GB:
1523 eth_link_speed = ETH_SPEED_NUM_1G;
1525 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2_5GB:
1526 eth_link_speed = ETH_SPEED_NUM_2_5G;
1528 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_10GB:
1529 eth_link_speed = ETH_SPEED_NUM_10G;
1531 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_20GB:
1532 eth_link_speed = ETH_SPEED_NUM_20G;
1534 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_25GB:
1535 eth_link_speed = ETH_SPEED_NUM_25G;
1537 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_40GB:
1538 eth_link_speed = ETH_SPEED_NUM_40G;
1540 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_50GB:
1541 eth_link_speed = ETH_SPEED_NUM_50G;
1543 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2GB:
1545 RTE_LOG(ERR, PMD, "HWRM link speed %d not defined\n",
1549 return eth_link_speed;
1552 static uint16_t bnxt_parse_hw_link_duplex(uint16_t hw_link_duplex)
1554 uint16_t eth_link_duplex = ETH_LINK_FULL_DUPLEX;
1556 switch (hw_link_duplex) {
1557 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH:
1558 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_FULL:
1559 eth_link_duplex = ETH_LINK_FULL_DUPLEX;
1561 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_HALF:
1562 eth_link_duplex = ETH_LINK_HALF_DUPLEX;
1565 RTE_LOG(ERR, PMD, "HWRM link duplex %d not defined\n",
1569 return eth_link_duplex;
1572 int bnxt_get_hwrm_link_config(struct bnxt *bp, struct rte_eth_link *link)
1575 struct bnxt_link_info *link_info = &bp->link_info;
1577 rc = bnxt_hwrm_port_phy_qcfg(bp, link_info);
1580 "Get link config failed with rc %d\n", rc);
1583 if (link_info->link_up)
1585 bnxt_parse_hw_link_speed(link_info->link_speed);
1587 link->link_speed = ETH_LINK_SPEED_10M;
1588 link->link_duplex = bnxt_parse_hw_link_duplex(link_info->duplex);
1589 link->link_status = link_info->link_up;
1590 link->link_autoneg = link_info->auto_mode ==
1591 HWRM_PORT_PHY_QCFG_OUTPUT_AUTO_MODE_NONE ?
1592 ETH_LINK_SPEED_FIXED : ETH_LINK_SPEED_AUTONEG;
1597 int bnxt_set_hwrm_link_config(struct bnxt *bp, bool link_up)
1600 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
1601 struct bnxt_link_info link_req;
1604 if (BNXT_NPAR_PF(bp) || BNXT_VF(bp))
1607 rc = bnxt_valid_link_speed(dev_conf->link_speeds,
1608 bp->eth_dev->data->port_id);
1612 memset(&link_req, 0, sizeof(link_req));
1613 link_req.link_up = link_up;
1617 speed = bnxt_parse_eth_link_speed(dev_conf->link_speeds);
1618 link_req.phy_flags = HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESET_PHY;
1620 link_req.phy_flags |=
1621 HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESTART_AUTONEG;
1622 link_req.auto_mode =
1623 HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_SPEED_MASK;
1624 link_req.auto_link_speed_mask =
1625 bnxt_parse_eth_link_speed_mask(dev_conf->link_speeds);
1627 link_req.phy_flags |= HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE;
1628 link_req.link_speed = speed;
1629 RTE_LOG(INFO, PMD, "Set Link Speed %x\n", speed);
1631 link_req.duplex = bnxt_parse_eth_link_duplex(dev_conf->link_speeds);
1632 link_req.auto_pause = bp->link_info.auto_pause;
1633 link_req.force_pause = bp->link_info.force_pause;
1636 rc = bnxt_hwrm_port_phy_cfg(bp, &link_req);
1639 "Set link config failed with rc %d\n", rc);
1642 rte_delay_ms(BNXT_LINK_WAIT_INTERVAL);
1648 int bnxt_hwrm_func_qcfg(struct bnxt *bp)
1650 struct hwrm_func_qcfg_input req = {0};
1651 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
1654 HWRM_PREP(req, FUNC_QCFG, -1, resp);
1655 req.fid = rte_cpu_to_le_16(0xffff);
1657 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1661 /* Hard Coded.. 0xfff VLAN ID mask */
1662 bp->vlan = rte_le_to_cpu_16(resp->vlan) & 0xfff;
1664 switch (resp->port_partition_type) {
1665 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR1_0:
1666 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR1_5:
1667 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR2_0:
1668 bp->port_partition_type = resp->port_partition_type;
1671 bp->port_partition_type = 0;
1678 static void copy_func_cfg_to_qcaps(struct hwrm_func_cfg_input *fcfg,
1679 struct hwrm_func_qcaps_output *qcaps)
1681 qcaps->max_rsscos_ctx = fcfg->num_rsscos_ctxs;
1682 memcpy(qcaps->mac_address, fcfg->dflt_mac_addr,
1683 sizeof(qcaps->mac_address));
1684 qcaps->max_l2_ctxs = fcfg->num_l2_ctxs;
1685 qcaps->max_rx_rings = fcfg->num_rx_rings;
1686 qcaps->max_tx_rings = fcfg->num_tx_rings;
1687 qcaps->max_cmpl_rings = fcfg->num_cmpl_rings;
1688 qcaps->max_stat_ctx = fcfg->num_stat_ctxs;
1690 qcaps->first_vf_id = 0;
1691 qcaps->max_vnics = fcfg->num_vnics;
1692 qcaps->max_decap_records = 0;
1693 qcaps->max_encap_records = 0;
1694 qcaps->max_tx_wm_flows = 0;
1695 qcaps->max_tx_em_flows = 0;
1696 qcaps->max_rx_wm_flows = 0;
1697 qcaps->max_rx_em_flows = 0;
1698 qcaps->max_flow_id = 0;
1699 qcaps->max_mcast_filters = fcfg->num_mcast_filters;
1700 qcaps->max_sp_tx_rings = 0;
1701 qcaps->max_hw_ring_grps = fcfg->num_hw_ring_grps;
1704 static int bnxt_hwrm_pf_func_cfg(struct bnxt *bp, int tx_rings)
1706 struct hwrm_func_cfg_input req = {0};
1707 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1710 req.enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_MTU |
1711 HWRM_FUNC_CFG_INPUT_ENABLES_MRU |
1712 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS |
1713 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
1714 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
1715 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_TX_RINGS |
1716 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RX_RINGS |
1717 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_L2_CTXS |
1718 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_VNICS |
1719 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS);
1720 req.flags = rte_cpu_to_le_32(bp->pf.func_cfg_flags);
1721 req.mtu = rte_cpu_to_le_16(bp->eth_dev->data->mtu + ETHER_HDR_LEN +
1722 ETHER_CRC_LEN + VLAN_TAG_SIZE);
1723 req.mru = rte_cpu_to_le_16(bp->eth_dev->data->mtu + ETHER_HDR_LEN +
1724 ETHER_CRC_LEN + VLAN_TAG_SIZE);
1725 req.num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx);
1726 req.num_stat_ctxs = rte_cpu_to_le_16(bp->max_stat_ctx);
1727 req.num_cmpl_rings = rte_cpu_to_le_16(bp->max_cp_rings);
1728 req.num_tx_rings = rte_cpu_to_le_16(tx_rings);
1729 req.num_rx_rings = rte_cpu_to_le_16(bp->max_rx_rings);
1730 req.num_l2_ctxs = rte_cpu_to_le_16(bp->max_l2_ctx);
1731 req.num_vnics = rte_cpu_to_le_16(bp->max_vnics);
1732 req.num_hw_ring_grps = rte_cpu_to_le_16(bp->max_ring_grps);
1733 req.fid = rte_cpu_to_le_16(0xffff);
1735 HWRM_PREP(req, FUNC_CFG, -1, resp);
1737 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1743 static void populate_vf_func_cfg_req(struct bnxt *bp,
1744 struct hwrm_func_cfg_input *req,
1747 req->enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_MTU |
1748 HWRM_FUNC_CFG_INPUT_ENABLES_MRU |
1749 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS |
1750 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
1751 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
1752 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_TX_RINGS |
1753 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RX_RINGS |
1754 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_L2_CTXS |
1755 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_VNICS |
1756 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS);
1758 req->mtu = rte_cpu_to_le_16(bp->eth_dev->data->mtu + ETHER_HDR_LEN +
1759 ETHER_CRC_LEN + VLAN_TAG_SIZE);
1760 req->mru = rte_cpu_to_le_16(bp->eth_dev->data->mtu + ETHER_HDR_LEN +
1761 ETHER_CRC_LEN + VLAN_TAG_SIZE);
1762 req->num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx /
1764 req->num_stat_ctxs = rte_cpu_to_le_16(bp->max_stat_ctx / (num_vfs + 1));
1765 req->num_cmpl_rings = rte_cpu_to_le_16(bp->max_cp_rings /
1767 req->num_tx_rings = rte_cpu_to_le_16(bp->max_tx_rings / (num_vfs + 1));
1768 req->num_rx_rings = rte_cpu_to_le_16(bp->max_rx_rings / (num_vfs + 1));
1769 req->num_l2_ctxs = rte_cpu_to_le_16(bp->max_l2_ctx / (num_vfs + 1));
1770 /* TODO: For now, do not support VMDq/RFS on VFs. */
1771 req->num_vnics = rte_cpu_to_le_16(1);
1772 req->num_hw_ring_grps = rte_cpu_to_le_16(bp->max_ring_grps /
1776 static void reserve_resources_from_vf(struct bnxt *bp,
1777 struct hwrm_func_cfg_input *cfg_req,
1780 struct hwrm_func_qcaps_input req = {0};
1781 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
1784 /* Get the actual allocated values now */
1785 HWRM_PREP(req, FUNC_QCAPS, -1, resp);
1786 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
1787 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1790 RTE_LOG(ERR, PMD, "hwrm_func_qcaps failed rc:%d\n", rc);
1791 copy_func_cfg_to_qcaps(cfg_req, resp);
1792 } else if (resp->error_code) {
1793 rc = rte_le_to_cpu_16(resp->error_code);
1794 RTE_LOG(ERR, PMD, "hwrm_func_qcaps error %d\n", rc);
1795 copy_func_cfg_to_qcaps(cfg_req, resp);
1798 bp->max_rsscos_ctx -= rte_le_to_cpu_16(resp->max_rsscos_ctx);
1799 bp->max_stat_ctx -= rte_le_to_cpu_16(resp->max_stat_ctx);
1800 bp->max_cp_rings -= rte_le_to_cpu_16(resp->max_cmpl_rings);
1801 bp->max_tx_rings -= rte_le_to_cpu_16(resp->max_tx_rings);
1802 bp->max_rx_rings -= rte_le_to_cpu_16(resp->max_rx_rings);
1803 bp->max_l2_ctx -= rte_le_to_cpu_16(resp->max_l2_ctxs);
1805 * TODO: While not supporting VMDq with VFs, max_vnics is always
1806 * forced to 1 in this case
1808 //bp->max_vnics -= rte_le_to_cpu_16(esp->max_vnics);
1809 bp->max_ring_grps -= rte_le_to_cpu_16(resp->max_hw_ring_grps);
1812 static int update_pf_resource_max(struct bnxt *bp)
1814 struct hwrm_func_qcfg_input req = {0};
1815 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
1818 /* And copy the allocated numbers into the pf struct */
1819 HWRM_PREP(req, FUNC_QCFG, -1, resp);
1820 req.fid = rte_cpu_to_le_16(0xffff);
1821 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1824 /* Only TX ring value reflects actual allocation? TODO */
1825 bp->max_tx_rings = rte_le_to_cpu_16(resp->alloc_tx_rings);
1826 bp->pf.evb_mode = resp->evb_mode;
1831 int bnxt_hwrm_allocate_pf_only(struct bnxt *bp)
1836 RTE_LOG(ERR, PMD, "Attempt to allcoate VFs on a VF!\n");
1840 rc = bnxt_hwrm_func_qcaps(bp);
1844 bp->pf.func_cfg_flags &=
1845 ~(HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE |
1846 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE);
1847 bp->pf.func_cfg_flags |=
1848 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE;
1849 rc = bnxt_hwrm_pf_func_cfg(bp, bp->max_tx_rings);
1853 int bnxt_hwrm_allocate_vfs(struct bnxt *bp, int num_vfs)
1855 struct hwrm_func_cfg_input req = {0};
1856 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1863 RTE_LOG(ERR, PMD, "Attempt to allcoate VFs on a VF!\n");
1867 rc = bnxt_hwrm_func_qcaps(bp);
1872 bp->pf.active_vfs = num_vfs;
1875 * First, configure the PF to only use one TX ring. This ensures that
1876 * there are enough rings for all VFs.
1878 * If we don't do this, when we call func_alloc() later, we will lock
1879 * extra rings to the PF that won't be available during func_cfg() of
1882 * This has been fixed with firmware versions above 20.6.54
1884 bp->pf.func_cfg_flags &=
1885 ~(HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE |
1886 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE);
1887 bp->pf.func_cfg_flags |=
1888 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE;
1889 rc = bnxt_hwrm_pf_func_cfg(bp, 1);
1894 * Now, create and register a buffer to hold forwarded VF requests
1896 req_buf_sz = num_vfs * HWRM_MAX_REQ_LEN;
1897 bp->pf.vf_req_buf = rte_malloc("bnxt_vf_fwd", req_buf_sz,
1898 page_roundup(num_vfs * HWRM_MAX_REQ_LEN));
1899 if (bp->pf.vf_req_buf == NULL) {
1903 for (sz = 0; sz < req_buf_sz; sz += getpagesize())
1904 rte_mem_lock_page(((char *)bp->pf.vf_req_buf) + sz);
1905 for (i = 0; i < num_vfs; i++)
1906 bp->pf.vf_info[i].req_buf = ((char *)bp->pf.vf_req_buf) +
1907 (i * HWRM_MAX_REQ_LEN);
1909 rc = bnxt_hwrm_func_buf_rgtr(bp);
1913 populate_vf_func_cfg_req(bp, &req, num_vfs);
1915 bp->pf.active_vfs = 0;
1916 for (i = 0; i < num_vfs; i++) {
1917 HWRM_PREP(req, FUNC_CFG, -1, resp);
1918 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[i].func_cfg_flags);
1919 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[i].fid);
1920 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1922 /* Clear enable flag for next pass */
1923 req.enables &= ~rte_cpu_to_le_32(
1924 HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
1926 if (rc || resp->error_code) {
1928 "Failed to initizlie VF %d\n", i);
1930 "Not all VFs available. (%d, %d)\n",
1931 rc, resp->error_code);
1935 reserve_resources_from_vf(bp, &req, i);
1936 bp->pf.active_vfs++;
1940 * Now configure the PF to use "the rest" of the resources
1941 * We're using STD_TX_RING_MODE here though which will limit the TX
1942 * rings. This will allow QoS to function properly. Not setting this
1943 * will cause PF rings to break bandwidth settings.
1945 rc = bnxt_hwrm_pf_func_cfg(bp, bp->max_tx_rings);
1949 rc = update_pf_resource_max(bp);
1956 bnxt_hwrm_func_buf_unrgtr(bp);
1961 int bnxt_hwrm_func_buf_rgtr(struct bnxt *bp)
1964 struct hwrm_func_buf_rgtr_input req = {.req_type = 0 };
1965 struct hwrm_func_buf_rgtr_output *resp = bp->hwrm_cmd_resp_addr;
1967 HWRM_PREP(req, FUNC_BUF_RGTR, -1, resp);
1969 req.req_buf_num_pages = rte_cpu_to_le_16(1);
1970 req.req_buf_page_size = rte_cpu_to_le_16(
1971 page_getenum(bp->pf.active_vfs * HWRM_MAX_REQ_LEN));
1972 req.req_buf_len = rte_cpu_to_le_16(HWRM_MAX_REQ_LEN);
1973 req.req_buf_page_addr[0] =
1974 rte_cpu_to_le_64(rte_mem_virt2phy(bp->pf.vf_req_buf));
1975 if (req.req_buf_page_addr[0] == 0) {
1977 "unable to map buffer address to physical memory\n");
1981 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1988 int bnxt_hwrm_func_buf_unrgtr(struct bnxt *bp)
1991 struct hwrm_func_buf_unrgtr_input req = {.req_type = 0 };
1992 struct hwrm_func_buf_unrgtr_output *resp = bp->hwrm_cmd_resp_addr;
1994 HWRM_PREP(req, FUNC_BUF_UNRGTR, -1, resp);
1996 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2003 int bnxt_hwrm_func_cfg_def_cp(struct bnxt *bp)
2005 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2006 struct hwrm_func_cfg_input req = {0};
2009 HWRM_PREP(req, FUNC_CFG, -1, resp);
2010 req.fid = rte_cpu_to_le_16(0xffff);
2011 req.flags = rte_cpu_to_le_32(bp->pf.func_cfg_flags);
2012 req.enables = rte_cpu_to_le_32(
2013 HWRM_FUNC_CFG_INPUT_ENABLES_ASYNC_EVENT_CR);
2014 req.async_event_cr = rte_cpu_to_le_16(
2015 bp->def_cp_ring->cp_ring_struct->fw_ring_id);
2016 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2022 int bnxt_hwrm_reject_fwd_resp(struct bnxt *bp, uint16_t target_id,
2023 void *encaped, size_t ec_size)
2026 struct hwrm_reject_fwd_resp_input req = {.req_type = 0};
2027 struct hwrm_reject_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr;
2029 if (ec_size > sizeof(req.encap_request))
2032 HWRM_PREP(req, REJECT_FWD_RESP, -1, resp);
2034 req.encap_resp_target_id = rte_cpu_to_le_16(target_id);
2035 memcpy(req.encap_request, encaped, ec_size);
2037 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));