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.
38 #include <rte_byteorder.h>
39 #include <rte_common.h>
40 #include <rte_cycles.h>
41 #include <rte_malloc.h>
42 #include <rte_memzone.h>
43 #include <rte_version.h>
47 #include "bnxt_filter.h"
48 #include "bnxt_hwrm.h"
51 #include "bnxt_ring.h"
54 #include "bnxt_vnic.h"
55 #include "hsi_struct_def_dpdk.h"
59 #define HWRM_CMD_TIMEOUT 2000
61 struct bnxt_plcmodes_cfg {
63 uint16_t jumbo_thresh;
65 uint16_t hds_threshold;
68 static int page_getenum(size_t size)
84 RTE_LOG(ERR, PMD, "Page size %zu out of range\n", size);
85 return sizeof(void *) * 8 - 1;
88 static int page_roundup(size_t size)
90 return 1 << page_getenum(size);
94 * HWRM Functions (sent to HWRM)
95 * These are named bnxt_hwrm_*() and return -1 if bnxt_hwrm_send_message()
96 * fails (ie: a timeout), and a positive non-zero HWRM error code if the HWRM
97 * command was failed by the ChiMP.
100 static int bnxt_hwrm_send_message_locked(struct bnxt *bp, void *msg,
104 struct input *req = msg;
105 struct output *resp = bp->hwrm_cmd_resp_addr;
106 uint32_t *data = msg;
110 /* Write request msg to hwrm channel */
111 for (i = 0; i < msg_len; i += 4) {
112 bar = (uint8_t *)bp->bar0 + i;
113 rte_write32(*data, bar);
117 /* Zero the rest of the request space */
118 for (; i < bp->max_req_len; i += 4) {
119 bar = (uint8_t *)bp->bar0 + i;
123 /* Ring channel doorbell */
124 bar = (uint8_t *)bp->bar0 + 0x100;
127 /* Poll for the valid bit */
128 for (i = 0; i < HWRM_CMD_TIMEOUT; i++) {
129 /* Sanity check on the resp->resp_len */
131 if (resp->resp_len && resp->resp_len <=
133 /* Last byte of resp contains the valid key */
134 valid = (uint8_t *)resp + resp->resp_len - 1;
135 if (*valid == HWRM_RESP_VALID_KEY)
141 if (i >= HWRM_CMD_TIMEOUT) {
142 RTE_LOG(ERR, PMD, "Error sending msg 0x%04x\n",
152 static int bnxt_hwrm_send_message(struct bnxt *bp, void *msg, uint32_t msg_len)
156 rte_spinlock_lock(&bp->hwrm_lock);
157 rc = bnxt_hwrm_send_message_locked(bp, msg, msg_len);
158 rte_spinlock_unlock(&bp->hwrm_lock);
162 #define HWRM_PREP(req, type, cr, resp) \
163 memset(bp->hwrm_cmd_resp_addr, 0, bp->max_resp_len); \
164 req.req_type = rte_cpu_to_le_16(HWRM_##type); \
165 req.cmpl_ring = rte_cpu_to_le_16(cr); \
166 req.seq_id = rte_cpu_to_le_16(bp->hwrm_cmd_seq++); \
167 req.target_id = rte_cpu_to_le_16(0xffff); \
168 req.resp_addr = rte_cpu_to_le_64(bp->hwrm_cmd_resp_dma_addr)
170 #define HWRM_CHECK_RESULT \
173 RTE_LOG(ERR, PMD, "%s failed rc:%d\n", \
177 if (resp->error_code) { \
178 rc = rte_le_to_cpu_16(resp->error_code); \
179 if (resp->resp_len >= 16) { \
180 struct hwrm_err_output *tmp_hwrm_err_op = \
183 "%s error %d:%d:%08x:%04x\n", \
185 rc, tmp_hwrm_err_op->cmd_err, \
187 tmp_hwrm_err_op->opaque_0), \
189 tmp_hwrm_err_op->opaque_1)); \
193 "%s error %d\n", __func__, rc); \
199 int bnxt_hwrm_cfa_l2_clear_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;
205 HWRM_PREP(req, CFA_L2_SET_RX_MASK, -1, resp);
206 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
209 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
216 int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp,
217 struct bnxt_vnic_info *vnic,
219 struct bnxt_vlan_table_entry *vlan_table)
222 struct hwrm_cfa_l2_set_rx_mask_input req = {.req_type = 0 };
223 struct hwrm_cfa_l2_set_rx_mask_output *resp = bp->hwrm_cmd_resp_addr;
226 HWRM_PREP(req, CFA_L2_SET_RX_MASK, -1, resp);
227 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
229 /* FIXME add multicast flag, when multicast adding options is supported
232 if (vnic->flags & BNXT_VNIC_INFO_PROMISC)
233 mask = HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_PROMISCUOUS;
234 if (vnic->flags & BNXT_VNIC_INFO_ALLMULTI)
235 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
236 if (vnic->mc_addr_cnt) {
237 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_MCAST;
238 req.num_mc_entries = rte_cpu_to_le_32(vnic->mc_addr_cnt);
239 req.mc_tbl_addr = rte_cpu_to_le_64(vnic->mc_list_dma_addr);
241 req.mask = rte_cpu_to_le_32(HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_BCAST |
243 if (vlan_count && vlan_table) {
244 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLANONLY;
245 req.vlan_tag_tbl_addr = rte_cpu_to_le_16(
246 rte_mem_virt2phy(vlan_table));
247 req.num_vlan_tags = rte_cpu_to_le_32((uint32_t)vlan_count);
250 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
257 int bnxt_hwrm_clear_filter(struct bnxt *bp,
258 struct bnxt_filter_info *filter)
261 struct hwrm_cfa_l2_filter_free_input req = {.req_type = 0 };
262 struct hwrm_cfa_l2_filter_free_output *resp = bp->hwrm_cmd_resp_addr;
264 HWRM_PREP(req, CFA_L2_FILTER_FREE, -1, resp);
266 req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
268 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
272 filter->fw_l2_filter_id = -1;
277 int bnxt_hwrm_set_filter(struct bnxt *bp,
279 struct bnxt_filter_info *filter)
282 struct hwrm_cfa_l2_filter_alloc_input req = {.req_type = 0 };
283 struct hwrm_cfa_l2_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr;
284 uint32_t enables = 0;
286 HWRM_PREP(req, CFA_L2_FILTER_ALLOC, -1, resp);
288 req.flags = rte_cpu_to_le_32(filter->flags);
290 enables = filter->enables |
291 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_DST_ID;
292 req.dst_id = rte_cpu_to_le_16(dst_id);
295 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR)
296 memcpy(req.l2_addr, filter->l2_addr,
299 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR_MASK)
300 memcpy(req.l2_addr_mask, filter->l2_addr_mask,
303 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN)
304 req.l2_ovlan = filter->l2_ovlan;
306 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN_MASK)
307 req.l2_ovlan_mask = filter->l2_ovlan_mask;
308 if (enables & HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_SRC_ID)
309 req.src_id = rte_cpu_to_le_32(filter->src_id);
310 if (enables & HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_SRC_TYPE)
311 req.src_type = filter->src_type;
313 req.enables = rte_cpu_to_le_32(enables);
315 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
319 filter->fw_l2_filter_id = rte_le_to_cpu_64(resp->l2_filter_id);
324 int bnxt_hwrm_func_qcaps(struct bnxt *bp)
327 struct hwrm_func_qcaps_input req = {.req_type = 0 };
328 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
329 uint16_t new_max_vfs;
332 HWRM_PREP(req, FUNC_QCAPS, -1, resp);
334 req.fid = rte_cpu_to_le_16(0xffff);
336 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
340 bp->max_ring_grps = rte_le_to_cpu_32(resp->max_hw_ring_grps);
342 bp->pf.port_id = resp->port_id;
343 bp->pf.first_vf_id = rte_le_to_cpu_16(resp->first_vf_id);
344 new_max_vfs = bp->pdev->max_vfs;
345 if (new_max_vfs != bp->pf.max_vfs) {
347 rte_free(bp->pf.vf_info);
348 bp->pf.vf_info = rte_malloc("bnxt_vf_info",
349 sizeof(bp->pf.vf_info[0]) * new_max_vfs, 0);
350 bp->pf.max_vfs = new_max_vfs;
351 for (i = 0; i < new_max_vfs; i++) {
352 bp->pf.vf_info[i].fid = bp->pf.first_vf_id + i;
353 bp->pf.vf_info[i].vlan_table =
354 rte_zmalloc("VF VLAN table",
357 if (bp->pf.vf_info[i].vlan_table == NULL)
359 "Fail to alloc VLAN table for VF %d\n",
363 bp->pf.vf_info[i].vlan_table);
364 STAILQ_INIT(&bp->pf.vf_info[i].filter);
369 bp->fw_fid = rte_le_to_cpu_32(resp->fid);
370 memcpy(bp->dflt_mac_addr, &resp->mac_address, ETHER_ADDR_LEN);
371 bp->max_rsscos_ctx = rte_le_to_cpu_16(resp->max_rsscos_ctx);
372 bp->max_cp_rings = rte_le_to_cpu_16(resp->max_cmpl_rings);
373 bp->max_tx_rings = rte_le_to_cpu_16(resp->max_tx_rings);
374 bp->max_rx_rings = rte_le_to_cpu_16(resp->max_rx_rings);
375 bp->max_l2_ctx = rte_le_to_cpu_16(resp->max_l2_ctxs);
376 /* TODO: For now, do not support VMDq/RFS on VFs. */
381 bp->max_vnics = rte_le_to_cpu_16(resp->max_vnics);
385 bp->max_stat_ctx = rte_le_to_cpu_16(resp->max_stat_ctx);
387 bp->pf.total_vnics = rte_le_to_cpu_16(resp->max_vnics);
392 int bnxt_hwrm_func_reset(struct bnxt *bp)
395 struct hwrm_func_reset_input req = {.req_type = 0 };
396 struct hwrm_func_reset_output *resp = bp->hwrm_cmd_resp_addr;
398 HWRM_PREP(req, FUNC_RESET, -1, resp);
400 req.enables = rte_cpu_to_le_32(0);
402 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
409 int bnxt_hwrm_func_driver_register(struct bnxt *bp)
412 struct hwrm_func_drv_rgtr_input req = {.req_type = 0 };
413 struct hwrm_func_drv_rgtr_output *resp = bp->hwrm_cmd_resp_addr;
415 if (bp->flags & BNXT_FLAG_REGISTERED)
418 HWRM_PREP(req, FUNC_DRV_RGTR, -1, resp);
419 req.enables = rte_cpu_to_le_32(HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_VER |
420 HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_ASYNC_EVENT_FWD);
421 req.ver_maj = RTE_VER_YEAR;
422 req.ver_min = RTE_VER_MONTH;
423 req.ver_upd = RTE_VER_MINOR;
426 req.enables |= rte_cpu_to_le_32(
427 HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_VF_INPUT_FWD);
428 memcpy(req.vf_req_fwd, bp->pf.vf_req_fwd,
429 RTE_MIN(sizeof(req.vf_req_fwd),
430 sizeof(bp->pf.vf_req_fwd)));
433 req.async_event_fwd[0] |= rte_cpu_to_le_32(0x1); /* TODO: Use MACRO */
434 memset(req.async_event_fwd, 0xff, sizeof(req.async_event_fwd));
436 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
440 bp->flags |= BNXT_FLAG_REGISTERED;
445 int bnxt_hwrm_ver_get(struct bnxt *bp)
448 struct hwrm_ver_get_input req = {.req_type = 0 };
449 struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr;
452 uint16_t max_resp_len;
453 char type[RTE_MEMZONE_NAMESIZE];
455 HWRM_PREP(req, VER_GET, -1, resp);
457 req.hwrm_intf_maj = HWRM_VERSION_MAJOR;
458 req.hwrm_intf_min = HWRM_VERSION_MINOR;
459 req.hwrm_intf_upd = HWRM_VERSION_UPDATE;
462 * Hold the lock since we may be adjusting the response pointers.
464 rte_spinlock_lock(&bp->hwrm_lock);
465 rc = bnxt_hwrm_send_message_locked(bp, &req, sizeof(req));
469 RTE_LOG(INFO, PMD, "%d.%d.%d:%d.%d.%d\n",
470 resp->hwrm_intf_maj, resp->hwrm_intf_min,
472 resp->hwrm_fw_maj, resp->hwrm_fw_min, resp->hwrm_fw_bld);
473 bp->fw_ver = (resp->hwrm_fw_maj << 24) | (resp->hwrm_fw_min << 16) |
474 (resp->hwrm_fw_bld << 8) | resp->hwrm_fw_rsvd;
475 RTE_LOG(INFO, PMD, "Driver HWRM version: %d.%d.%d\n",
476 HWRM_VERSION_MAJOR, HWRM_VERSION_MINOR, HWRM_VERSION_UPDATE);
478 my_version = HWRM_VERSION_MAJOR << 16;
479 my_version |= HWRM_VERSION_MINOR << 8;
480 my_version |= HWRM_VERSION_UPDATE;
482 fw_version = resp->hwrm_intf_maj << 16;
483 fw_version |= resp->hwrm_intf_min << 8;
484 fw_version |= resp->hwrm_intf_upd;
486 if (resp->hwrm_intf_maj != HWRM_VERSION_MAJOR) {
487 RTE_LOG(ERR, PMD, "Unsupported firmware API version\n");
492 if (my_version != fw_version) {
493 RTE_LOG(INFO, PMD, "BNXT Driver/HWRM API mismatch.\n");
494 if (my_version < fw_version) {
496 "Firmware API version is newer than driver.\n");
498 "The driver may be missing features.\n");
501 "Firmware API version is older than driver.\n");
503 "Not all driver features may be functional.\n");
507 if (bp->max_req_len > resp->max_req_win_len) {
508 RTE_LOG(ERR, PMD, "Unsupported request length\n");
511 bp->max_req_len = resp->max_req_win_len;
512 max_resp_len = resp->max_resp_len;
513 if (bp->max_resp_len != max_resp_len) {
514 sprintf(type, "bnxt_hwrm_%04x:%02x:%02x:%02x",
515 bp->pdev->addr.domain, bp->pdev->addr.bus,
516 bp->pdev->addr.devid, bp->pdev->addr.function);
518 rte_free(bp->hwrm_cmd_resp_addr);
520 bp->hwrm_cmd_resp_addr = rte_malloc(type, max_resp_len, 0);
521 if (bp->hwrm_cmd_resp_addr == NULL) {
525 rte_mem_lock_page(bp->hwrm_cmd_resp_addr);
526 bp->hwrm_cmd_resp_dma_addr =
527 rte_mem_virt2phy(bp->hwrm_cmd_resp_addr);
528 if (bp->hwrm_cmd_resp_dma_addr == 0) {
530 "Unable to map response buffer to physical memory.\n");
534 bp->max_resp_len = max_resp_len;
538 rte_spinlock_unlock(&bp->hwrm_lock);
542 int bnxt_hwrm_func_driver_unregister(struct bnxt *bp, uint32_t flags)
545 struct hwrm_func_drv_unrgtr_input req = {.req_type = 0 };
546 struct hwrm_func_drv_unrgtr_output *resp = bp->hwrm_cmd_resp_addr;
548 if (!(bp->flags & BNXT_FLAG_REGISTERED))
551 HWRM_PREP(req, FUNC_DRV_UNRGTR, -1, resp);
554 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
558 bp->flags &= ~BNXT_FLAG_REGISTERED;
563 static int bnxt_hwrm_port_phy_cfg(struct bnxt *bp, struct bnxt_link_info *conf)
566 struct hwrm_port_phy_cfg_input req = {0};
567 struct hwrm_port_phy_cfg_output *resp = bp->hwrm_cmd_resp_addr;
568 uint32_t enables = 0;
570 HWRM_PREP(req, PORT_PHY_CFG, -1, resp);
573 req.flags = rte_cpu_to_le_32(conf->phy_flags);
574 req.force_link_speed = rte_cpu_to_le_16(conf->link_speed);
576 * Note, ChiMP FW 20.2.1 and 20.2.2 return an error when we set
577 * any auto mode, even "none".
579 if (!conf->link_speed) {
580 req.auto_mode |= conf->auto_mode;
581 enables = HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_MODE;
582 req.auto_link_speed_mask = conf->auto_link_speed_mask;
584 HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_LINK_SPEED_MASK;
585 req.auto_link_speed = bp->link_info.auto_link_speed;
587 HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_LINK_SPEED;
589 req.auto_duplex = conf->duplex;
590 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_DUPLEX;
591 req.auto_pause = conf->auto_pause;
592 req.force_pause = conf->force_pause;
593 /* Set force_pause if there is no auto or if there is a force */
594 if (req.auto_pause && !req.force_pause)
595 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_PAUSE;
597 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_FORCE_PAUSE;
599 req.enables = rte_cpu_to_le_32(enables);
602 rte_cpu_to_le_32(HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE_LINK_DWN);
603 RTE_LOG(INFO, PMD, "Force Link Down\n");
606 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
613 static int bnxt_hwrm_port_phy_qcfg(struct bnxt *bp,
614 struct bnxt_link_info *link_info)
617 struct hwrm_port_phy_qcfg_input req = {0};
618 struct hwrm_port_phy_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
620 HWRM_PREP(req, PORT_PHY_QCFG, -1, resp);
622 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
626 link_info->phy_link_status = resp->link;
627 if (link_info->phy_link_status != HWRM_PORT_PHY_QCFG_OUTPUT_LINK_NO_LINK) {
628 link_info->link_up = 1;
629 link_info->link_speed = rte_le_to_cpu_16(resp->link_speed);
631 link_info->link_up = 0;
632 link_info->link_speed = 0;
634 link_info->duplex = resp->duplex;
635 link_info->pause = resp->pause;
636 link_info->auto_pause = resp->auto_pause;
637 link_info->force_pause = resp->force_pause;
638 link_info->auto_mode = resp->auto_mode;
640 link_info->support_speeds = rte_le_to_cpu_16(resp->support_speeds);
641 link_info->auto_link_speed = rte_le_to_cpu_16(resp->auto_link_speed);
642 link_info->preemphasis = rte_le_to_cpu_32(resp->preemphasis);
643 link_info->phy_ver[0] = resp->phy_maj;
644 link_info->phy_ver[1] = resp->phy_min;
645 link_info->phy_ver[2] = resp->phy_bld;
650 int bnxt_hwrm_queue_qportcfg(struct bnxt *bp)
653 struct hwrm_queue_qportcfg_input req = {.req_type = 0 };
654 struct hwrm_queue_qportcfg_output *resp = bp->hwrm_cmd_resp_addr;
656 HWRM_PREP(req, QUEUE_QPORTCFG, -1, resp);
658 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
662 #define GET_QUEUE_INFO(x) \
663 bp->cos_queue[x].id = resp->queue_id##x; \
664 bp->cos_queue[x].profile = resp->queue_id##x##_service_profile
678 int bnxt_hwrm_ring_alloc(struct bnxt *bp,
679 struct bnxt_ring *ring,
680 uint32_t ring_type, uint32_t map_index,
681 uint32_t stats_ctx_id, uint32_t cmpl_ring_id)
684 uint32_t enables = 0;
685 struct hwrm_ring_alloc_input req = {.req_type = 0 };
686 struct hwrm_ring_alloc_output *resp = bp->hwrm_cmd_resp_addr;
688 HWRM_PREP(req, RING_ALLOC, -1, resp);
690 req.page_tbl_addr = rte_cpu_to_le_64(ring->bd_dma);
691 req.fbo = rte_cpu_to_le_32(0);
692 /* Association of ring index with doorbell index */
693 req.logical_id = rte_cpu_to_le_16(map_index);
694 req.length = rte_cpu_to_le_32(ring->ring_size);
697 case HWRM_RING_ALLOC_INPUT_RING_TYPE_TX:
698 req.queue_id = bp->cos_queue[0].id;
700 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX:
701 req.ring_type = ring_type;
702 req.cmpl_ring_id = rte_cpu_to_le_16(cmpl_ring_id);
703 req.stat_ctx_id = rte_cpu_to_le_16(stats_ctx_id);
704 if (stats_ctx_id != INVALID_STATS_CTX_ID)
706 HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID;
708 case HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL:
709 req.ring_type = ring_type;
711 * TODO: Some HWRM versions crash with
712 * HWRM_RING_ALLOC_INPUT_INT_MODE_POLL
714 req.int_mode = HWRM_RING_ALLOC_INPUT_INT_MODE_MSIX;
717 RTE_LOG(ERR, PMD, "hwrm alloc invalid ring type %d\n",
721 req.enables = rte_cpu_to_le_32(enables);
723 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
725 if (rc || resp->error_code) {
726 if (rc == 0 && resp->error_code)
727 rc = rte_le_to_cpu_16(resp->error_code);
729 case HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL:
731 "hwrm_ring_alloc cp failed. rc:%d\n", rc);
733 case HWRM_RING_FREE_INPUT_RING_TYPE_RX:
735 "hwrm_ring_alloc rx failed. rc:%d\n", rc);
737 case HWRM_RING_FREE_INPUT_RING_TYPE_TX:
739 "hwrm_ring_alloc tx failed. rc:%d\n", rc);
742 RTE_LOG(ERR, PMD, "Invalid ring. rc:%d\n", rc);
747 ring->fw_ring_id = rte_le_to_cpu_16(resp->ring_id);
751 int bnxt_hwrm_ring_free(struct bnxt *bp,
752 struct bnxt_ring *ring, uint32_t ring_type)
755 struct hwrm_ring_free_input req = {.req_type = 0 };
756 struct hwrm_ring_free_output *resp = bp->hwrm_cmd_resp_addr;
758 HWRM_PREP(req, RING_FREE, -1, resp);
760 req.ring_type = ring_type;
761 req.ring_id = rte_cpu_to_le_16(ring->fw_ring_id);
763 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
765 if (rc || resp->error_code) {
766 if (rc == 0 && resp->error_code)
767 rc = rte_le_to_cpu_16(resp->error_code);
770 case HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL:
771 RTE_LOG(ERR, PMD, "hwrm_ring_free cp failed. rc:%d\n",
774 case HWRM_RING_FREE_INPUT_RING_TYPE_RX:
775 RTE_LOG(ERR, PMD, "hwrm_ring_free rx failed. rc:%d\n",
778 case HWRM_RING_FREE_INPUT_RING_TYPE_TX:
779 RTE_LOG(ERR, PMD, "hwrm_ring_free tx failed. rc:%d\n",
783 RTE_LOG(ERR, PMD, "Invalid ring, rc:%d\n", rc);
790 int bnxt_hwrm_ring_grp_alloc(struct bnxt *bp, unsigned int idx)
793 struct hwrm_ring_grp_alloc_input req = {.req_type = 0 };
794 struct hwrm_ring_grp_alloc_output *resp = bp->hwrm_cmd_resp_addr;
796 HWRM_PREP(req, RING_GRP_ALLOC, -1, resp);
798 req.cr = rte_cpu_to_le_16(bp->grp_info[idx].cp_fw_ring_id);
799 req.rr = rte_cpu_to_le_16(bp->grp_info[idx].rx_fw_ring_id);
800 req.ar = rte_cpu_to_le_16(bp->grp_info[idx].ag_fw_ring_id);
801 req.sc = rte_cpu_to_le_16(bp->grp_info[idx].fw_stats_ctx);
803 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
807 bp->grp_info[idx].fw_grp_id =
808 rte_le_to_cpu_16(resp->ring_group_id);
813 int bnxt_hwrm_ring_grp_free(struct bnxt *bp, unsigned int idx)
816 struct hwrm_ring_grp_free_input req = {.req_type = 0 };
817 struct hwrm_ring_grp_free_output *resp = bp->hwrm_cmd_resp_addr;
819 HWRM_PREP(req, RING_GRP_FREE, -1, resp);
821 req.ring_group_id = rte_cpu_to_le_16(bp->grp_info[idx].fw_grp_id);
823 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
827 bp->grp_info[idx].fw_grp_id = INVALID_HW_RING_ID;
831 int bnxt_hwrm_stat_clear(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
834 struct hwrm_stat_ctx_clr_stats_input req = {.req_type = 0 };
835 struct hwrm_stat_ctx_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
837 if (cpr->hw_stats_ctx_id == (uint32_t)HWRM_NA_SIGNATURE)
840 HWRM_PREP(req, STAT_CTX_CLR_STATS, -1, resp);
842 req.stat_ctx_id = rte_cpu_to_le_16(cpr->hw_stats_ctx_id);
844 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
851 int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
852 unsigned int idx __rte_unused)
855 struct hwrm_stat_ctx_alloc_input req = {.req_type = 0 };
856 struct hwrm_stat_ctx_alloc_output *resp = bp->hwrm_cmd_resp_addr;
858 HWRM_PREP(req, STAT_CTX_ALLOC, -1, resp);
860 req.update_period_ms = rte_cpu_to_le_32(0);
863 rte_cpu_to_le_64(cpr->hw_stats_map);
865 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
869 cpr->hw_stats_ctx_id = rte_le_to_cpu_16(resp->stat_ctx_id);
874 int bnxt_hwrm_stat_ctx_free(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
875 unsigned int idx __rte_unused)
878 struct hwrm_stat_ctx_free_input req = {.req_type = 0 };
879 struct hwrm_stat_ctx_free_output *resp = bp->hwrm_cmd_resp_addr;
881 HWRM_PREP(req, STAT_CTX_FREE, -1, resp);
883 req.stat_ctx_id = rte_cpu_to_le_16(cpr->hw_stats_ctx_id);
885 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
892 int bnxt_hwrm_vnic_alloc(struct bnxt *bp, struct bnxt_vnic_info *vnic)
895 struct hwrm_vnic_alloc_input req = { 0 };
896 struct hwrm_vnic_alloc_output *resp = bp->hwrm_cmd_resp_addr;
898 /* map ring groups to this vnic */
899 RTE_LOG(DEBUG, PMD, "Alloc VNIC. Start %x, End %x\n",
900 vnic->start_grp_id, vnic->end_grp_id);
901 for (i = vnic->start_grp_id, j = 0; i <= vnic->end_grp_id; i++, j++)
902 vnic->fw_grp_ids[j] = bp->grp_info[i].fw_grp_id;
903 vnic->dflt_ring_grp = bp->grp_info[vnic->start_grp_id].fw_grp_id;
904 vnic->rss_rule = (uint16_t)HWRM_NA_SIGNATURE;
905 vnic->cos_rule = (uint16_t)HWRM_NA_SIGNATURE;
906 vnic->lb_rule = (uint16_t)HWRM_NA_SIGNATURE;
907 vnic->mru = bp->eth_dev->data->mtu + ETHER_HDR_LEN +
908 ETHER_CRC_LEN + VLAN_TAG_SIZE;
909 HWRM_PREP(req, VNIC_ALLOC, -1, resp);
911 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
915 vnic->fw_vnic_id = rte_le_to_cpu_16(resp->vnic_id);
919 static int bnxt_hwrm_vnic_plcmodes_qcfg(struct bnxt *bp,
920 struct bnxt_vnic_info *vnic,
921 struct bnxt_plcmodes_cfg *pmode)
924 struct hwrm_vnic_plcmodes_qcfg_input req = {.req_type = 0 };
925 struct hwrm_vnic_plcmodes_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
927 HWRM_PREP(req, VNIC_PLCMODES_QCFG, -1, resp);
929 req.vnic_id = rte_cpu_to_le_32(vnic->fw_vnic_id);
931 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
935 pmode->flags = rte_le_to_cpu_32(resp->flags);
936 /* dflt_vnic bit doesn't exist in the _cfg command */
937 pmode->flags &= ~(HWRM_VNIC_PLCMODES_QCFG_OUTPUT_FLAGS_DFLT_VNIC);
938 pmode->jumbo_thresh = rte_le_to_cpu_16(resp->jumbo_thresh);
939 pmode->hds_offset = rte_le_to_cpu_16(resp->hds_offset);
940 pmode->hds_threshold = rte_le_to_cpu_16(resp->hds_threshold);
945 static int bnxt_hwrm_vnic_plcmodes_cfg(struct bnxt *bp,
946 struct bnxt_vnic_info *vnic,
947 struct bnxt_plcmodes_cfg *pmode)
950 struct hwrm_vnic_plcmodes_cfg_input req = {.req_type = 0 };
951 struct hwrm_vnic_plcmodes_cfg_output *resp = bp->hwrm_cmd_resp_addr;
953 HWRM_PREP(req, VNIC_PLCMODES_CFG, -1, resp);
955 req.vnic_id = rte_cpu_to_le_32(vnic->fw_vnic_id);
956 req.flags = rte_cpu_to_le_32(pmode->flags);
957 req.jumbo_thresh = rte_cpu_to_le_16(pmode->jumbo_thresh);
958 req.hds_offset = rte_cpu_to_le_16(pmode->hds_offset);
959 req.hds_threshold = rte_cpu_to_le_16(pmode->hds_threshold);
960 req.enables = rte_cpu_to_le_32(
961 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_HDS_THRESHOLD_VALID |
962 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_HDS_OFFSET_VALID |
963 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_JUMBO_THRESH_VALID
966 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
973 int bnxt_hwrm_vnic_cfg(struct bnxt *bp, struct bnxt_vnic_info *vnic)
976 struct hwrm_vnic_cfg_input req = {.req_type = 0 };
977 struct hwrm_vnic_cfg_output *resp = bp->hwrm_cmd_resp_addr;
978 uint32_t ctx_enable_flag = HWRM_VNIC_CFG_INPUT_ENABLES_RSS_RULE;
979 struct bnxt_plcmodes_cfg pmodes;
981 rc = bnxt_hwrm_vnic_plcmodes_qcfg(bp, vnic, &pmodes);
985 HWRM_PREP(req, VNIC_CFG, -1, resp);
987 /* Only RSS support for now TBD: COS & LB */
989 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_ENABLES_DFLT_RING_GRP |
990 HWRM_VNIC_CFG_INPUT_ENABLES_MRU);
991 if (vnic->lb_rule != 0xffff)
992 ctx_enable_flag = HWRM_VNIC_CFG_INPUT_ENABLES_LB_RULE;
993 if (vnic->cos_rule != 0xffff)
994 ctx_enable_flag = HWRM_VNIC_CFG_INPUT_ENABLES_COS_RULE;
995 if (vnic->rss_rule != 0xffff)
996 ctx_enable_flag = HWRM_VNIC_CFG_INPUT_ENABLES_RSS_RULE;
997 req.enables |= rte_cpu_to_le_32(ctx_enable_flag);
998 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
999 req.dflt_ring_grp = rte_cpu_to_le_16(vnic->dflt_ring_grp);
1000 req.rss_rule = rte_cpu_to_le_16(vnic->rss_rule);
1001 req.cos_rule = rte_cpu_to_le_16(vnic->cos_rule);
1002 req.lb_rule = rte_cpu_to_le_16(vnic->lb_rule);
1003 req.mru = rte_cpu_to_le_16(vnic->mru);
1004 if (vnic->func_default)
1006 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_DEFAULT);
1007 if (vnic->vlan_strip)
1009 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_VLAN_STRIP_MODE);
1012 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_BD_STALL_MODE);
1013 if (vnic->roce_dual)
1014 req.flags |= rte_cpu_to_le_32(
1015 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_DUAL_VNIC_MODE);
1016 if (vnic->roce_only)
1017 req.flags |= rte_cpu_to_le_32(
1018 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_ONLY_VNIC_MODE);
1019 if (vnic->rss_dflt_cr)
1020 req.flags |= rte_cpu_to_le_32(
1021 HWRM_VNIC_QCFG_OUTPUT_FLAGS_RSS_DFLT_CR_MODE);
1023 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1027 rc = bnxt_hwrm_vnic_plcmodes_cfg(bp, vnic, &pmodes);
1032 int bnxt_hwrm_vnic_qcfg(struct bnxt *bp, struct bnxt_vnic_info *vnic,
1036 struct hwrm_vnic_qcfg_input req = {.req_type = 0 };
1037 struct hwrm_vnic_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
1039 HWRM_PREP(req, VNIC_QCFG, -1, resp);
1042 rte_cpu_to_le_32(HWRM_VNIC_QCFG_INPUT_ENABLES_VF_ID_VALID);
1043 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1044 req.vf_id = rte_cpu_to_le_16(fw_vf_id);
1046 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1050 vnic->dflt_ring_grp = rte_le_to_cpu_16(resp->dflt_ring_grp);
1051 vnic->rss_rule = rte_le_to_cpu_16(resp->rss_rule);
1052 vnic->cos_rule = rte_le_to_cpu_16(resp->cos_rule);
1053 vnic->lb_rule = rte_le_to_cpu_16(resp->lb_rule);
1054 vnic->mru = rte_le_to_cpu_16(resp->mru);
1055 vnic->func_default = rte_le_to_cpu_32(
1056 resp->flags) & HWRM_VNIC_QCFG_OUTPUT_FLAGS_DEFAULT;
1057 vnic->vlan_strip = rte_le_to_cpu_32(resp->flags) &
1058 HWRM_VNIC_QCFG_OUTPUT_FLAGS_VLAN_STRIP_MODE;
1059 vnic->bd_stall = rte_le_to_cpu_32(resp->flags) &
1060 HWRM_VNIC_QCFG_OUTPUT_FLAGS_BD_STALL_MODE;
1061 vnic->roce_dual = rte_le_to_cpu_32(resp->flags) &
1062 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_DUAL_VNIC_MODE;
1063 vnic->roce_only = rte_le_to_cpu_32(resp->flags) &
1064 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_ONLY_VNIC_MODE;
1065 vnic->rss_dflt_cr = rte_le_to_cpu_32(resp->flags) &
1066 HWRM_VNIC_QCFG_OUTPUT_FLAGS_RSS_DFLT_CR_MODE;
1071 int bnxt_hwrm_vnic_ctx_alloc(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1074 struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req = {.req_type = 0 };
1075 struct hwrm_vnic_rss_cos_lb_ctx_alloc_output *resp =
1076 bp->hwrm_cmd_resp_addr;
1078 HWRM_PREP(req, VNIC_RSS_COS_LB_CTX_ALLOC, -1, resp);
1080 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1084 vnic->rss_rule = rte_le_to_cpu_16(resp->rss_cos_lb_ctx_id);
1089 int bnxt_hwrm_vnic_ctx_free(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1092 struct hwrm_vnic_rss_cos_lb_ctx_free_input req = {.req_type = 0 };
1093 struct hwrm_vnic_rss_cos_lb_ctx_free_output *resp =
1094 bp->hwrm_cmd_resp_addr;
1096 HWRM_PREP(req, VNIC_RSS_COS_LB_CTX_FREE, -1, resp);
1098 req.rss_cos_lb_ctx_id = rte_cpu_to_le_16(vnic->rss_rule);
1100 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1104 vnic->rss_rule = INVALID_HW_RING_ID;
1109 int bnxt_hwrm_vnic_free(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1112 struct hwrm_vnic_free_input req = {.req_type = 0 };
1113 struct hwrm_vnic_free_output *resp = bp->hwrm_cmd_resp_addr;
1115 if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
1118 HWRM_PREP(req, VNIC_FREE, -1, resp);
1120 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1122 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1126 vnic->fw_vnic_id = INVALID_HW_RING_ID;
1130 int bnxt_hwrm_vnic_rss_cfg(struct bnxt *bp,
1131 struct bnxt_vnic_info *vnic)
1134 struct hwrm_vnic_rss_cfg_input req = {.req_type = 0 };
1135 struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1137 HWRM_PREP(req, VNIC_RSS_CFG, -1, resp);
1139 req.hash_type = rte_cpu_to_le_32(vnic->hash_type);
1141 req.ring_grp_tbl_addr =
1142 rte_cpu_to_le_64(vnic->rss_table_dma_addr);
1143 req.hash_key_tbl_addr =
1144 rte_cpu_to_le_64(vnic->rss_hash_key_dma_addr);
1145 req.rss_ctx_idx = rte_cpu_to_le_16(vnic->rss_rule);
1147 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1154 int bnxt_hwrm_vnic_plcmode_cfg(struct bnxt *bp,
1155 struct bnxt_vnic_info *vnic)
1158 struct hwrm_vnic_plcmodes_cfg_input req = {.req_type = 0 };
1159 struct hwrm_vnic_plcmodes_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1162 HWRM_PREP(req, VNIC_PLCMODES_CFG, -1, resp);
1164 req.flags = rte_cpu_to_le_32(
1165 HWRM_VNIC_PLCMODES_CFG_INPUT_FLAGS_JUMBO_PLACEMENT);
1167 req.enables = rte_cpu_to_le_32(
1168 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_JUMBO_THRESH_VALID);
1170 size = rte_pktmbuf_data_room_size(bp->rx_queues[0]->mb_pool);
1171 size -= RTE_PKTMBUF_HEADROOM;
1173 req.jumbo_thresh = rte_cpu_to_le_16(size);
1174 req.vnic_id = rte_cpu_to_le_32(vnic->fw_vnic_id);
1176 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1183 int bnxt_hwrm_vnic_tpa_cfg(struct bnxt *bp,
1184 struct bnxt_vnic_info *vnic, bool enable)
1187 struct hwrm_vnic_tpa_cfg_input req = {.req_type = 0 };
1188 struct hwrm_vnic_tpa_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1190 HWRM_PREP(req, VNIC_TPA_CFG, -1, resp);
1193 req.enables = rte_cpu_to_le_32(
1194 HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MAX_AGG_SEGS |
1195 HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MAX_AGGS |
1196 HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MIN_AGG_LEN);
1197 req.flags = rte_cpu_to_le_32(
1198 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_TPA |
1199 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_ENCAP_TPA |
1200 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_RSC_WND_UPDATE |
1201 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_GRO |
1202 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_AGG_WITH_ECN |
1203 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_AGG_WITH_SAME_GRE_SEQ);
1204 req.vnic_id = rte_cpu_to_le_32(vnic->fw_vnic_id);
1205 req.max_agg_segs = rte_cpu_to_le_16(5);
1207 rte_cpu_to_le_16(HWRM_VNIC_TPA_CFG_INPUT_MAX_AGGS_MAX);
1208 req.min_agg_len = rte_cpu_to_le_32(512);
1211 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1218 int bnxt_hwrm_func_vf_mac(struct bnxt *bp, uint16_t vf, const uint8_t *mac_addr)
1220 struct hwrm_func_cfg_input req = {0};
1221 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1224 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[vf].func_cfg_flags);
1225 req.enables = rte_cpu_to_le_32(
1226 HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
1227 memcpy(req.dflt_mac_addr, mac_addr, sizeof(req.dflt_mac_addr));
1228 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
1230 HWRM_PREP(req, FUNC_CFG, -1, resp);
1232 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1235 bp->pf.vf_info[vf].random_mac = false;
1240 int bnxt_hwrm_func_qstats(struct bnxt *bp, uint16_t fid,
1241 struct rte_eth_stats *stats)
1244 struct hwrm_func_qstats_input req = {.req_type = 0};
1245 struct hwrm_func_qstats_output *resp = bp->hwrm_cmd_resp_addr;
1247 HWRM_PREP(req, FUNC_QSTATS, -1, resp);
1249 req.fid = rte_cpu_to_le_16(fid);
1251 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1255 stats->ipackets = rte_le_to_cpu_64(resp->rx_ucast_pkts);
1256 stats->ipackets += rte_le_to_cpu_64(resp->rx_mcast_pkts);
1257 stats->ipackets += rte_le_to_cpu_64(resp->rx_bcast_pkts);
1258 stats->ibytes = rte_le_to_cpu_64(resp->rx_ucast_bytes);
1259 stats->ibytes += rte_le_to_cpu_64(resp->rx_mcast_bytes);
1260 stats->ibytes += rte_le_to_cpu_64(resp->rx_bcast_bytes);
1262 stats->opackets = rte_le_to_cpu_64(resp->tx_ucast_pkts);
1263 stats->opackets += rte_le_to_cpu_64(resp->tx_mcast_pkts);
1264 stats->opackets += rte_le_to_cpu_64(resp->tx_bcast_pkts);
1265 stats->obytes = rte_le_to_cpu_64(resp->tx_ucast_bytes);
1266 stats->obytes += rte_le_to_cpu_64(resp->tx_mcast_bytes);
1267 stats->obytes += rte_le_to_cpu_64(resp->tx_bcast_bytes);
1269 stats->ierrors = rte_le_to_cpu_64(resp->rx_err_pkts);
1270 stats->oerrors = rte_le_to_cpu_64(resp->tx_err_pkts);
1272 stats->imissed = rte_le_to_cpu_64(resp->rx_drop_pkts);
1278 * HWRM utility functions
1281 int bnxt_clear_all_hwrm_stat_ctxs(struct bnxt *bp)
1286 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
1287 struct bnxt_tx_queue *txq;
1288 struct bnxt_rx_queue *rxq;
1289 struct bnxt_cp_ring_info *cpr;
1291 if (i >= bp->rx_cp_nr_rings) {
1292 txq = bp->tx_queues[i - bp->rx_cp_nr_rings];
1295 rxq = bp->rx_queues[i];
1299 rc = bnxt_hwrm_stat_clear(bp, cpr);
1306 int bnxt_free_all_hwrm_stat_ctxs(struct bnxt *bp)
1310 struct bnxt_cp_ring_info *cpr;
1312 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
1314 if (i >= bp->rx_cp_nr_rings)
1315 cpr = bp->tx_queues[i - bp->rx_cp_nr_rings]->cp_ring;
1317 cpr = bp->rx_queues[i]->cp_ring;
1318 if (cpr->hw_stats_ctx_id != HWRM_NA_SIGNATURE) {
1319 rc = bnxt_hwrm_stat_ctx_free(bp, cpr, i);
1320 cpr->hw_stats_ctx_id = HWRM_NA_SIGNATURE;
1322 * TODO. Need a better way to reset grp_info.stats_ctx
1323 * for Rx rings only. stats_ctx is not saved for Tx
1326 bp->grp_info[i].fw_stats_ctx = cpr->hw_stats_ctx_id;
1334 int bnxt_alloc_all_hwrm_stat_ctxs(struct bnxt *bp)
1339 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
1340 struct bnxt_tx_queue *txq;
1341 struct bnxt_rx_queue *rxq;
1342 struct bnxt_cp_ring_info *cpr;
1344 if (i >= bp->rx_cp_nr_rings) {
1345 txq = bp->tx_queues[i - bp->rx_cp_nr_rings];
1348 rxq = bp->rx_queues[i];
1352 rc = bnxt_hwrm_stat_ctx_alloc(bp, cpr, i);
1360 int bnxt_free_all_hwrm_ring_grps(struct bnxt *bp)
1365 for (idx = 0; idx < bp->rx_cp_nr_rings; idx++) {
1367 if (bp->grp_info[idx].fw_grp_id == INVALID_HW_RING_ID) {
1369 "Attempt to free invalid ring group %d\n",
1374 rc = bnxt_hwrm_ring_grp_free(bp, idx);
1382 static void bnxt_free_cp_ring(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
1383 unsigned int idx __rte_unused)
1385 struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
1387 bnxt_hwrm_ring_free(bp, cp_ring,
1388 HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL);
1389 cp_ring->fw_ring_id = INVALID_HW_RING_ID;
1390 bp->grp_info[idx].cp_fw_ring_id = INVALID_HW_RING_ID;
1391 memset(cpr->cp_desc_ring, 0, cpr->cp_ring_struct->ring_size *
1392 sizeof(*cpr->cp_desc_ring));
1393 cpr->cp_raw_cons = 0;
1396 int bnxt_free_all_hwrm_rings(struct bnxt *bp)
1401 for (i = 0; i < bp->tx_cp_nr_rings; i++) {
1402 struct bnxt_tx_queue *txq = bp->tx_queues[i];
1403 struct bnxt_tx_ring_info *txr = txq->tx_ring;
1404 struct bnxt_ring *ring = txr->tx_ring_struct;
1405 struct bnxt_cp_ring_info *cpr = txq->cp_ring;
1406 unsigned int idx = bp->rx_cp_nr_rings + i + 1;
1408 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
1409 bnxt_hwrm_ring_free(bp, ring,
1410 HWRM_RING_FREE_INPUT_RING_TYPE_TX);
1411 ring->fw_ring_id = INVALID_HW_RING_ID;
1412 memset(txr->tx_desc_ring, 0,
1413 txr->tx_ring_struct->ring_size *
1414 sizeof(*txr->tx_desc_ring));
1415 memset(txr->tx_buf_ring, 0,
1416 txr->tx_ring_struct->ring_size *
1417 sizeof(*txr->tx_buf_ring));
1421 if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID) {
1422 bnxt_free_cp_ring(bp, cpr, idx);
1423 cpr->cp_ring_struct->fw_ring_id = INVALID_HW_RING_ID;
1427 for (i = 0; i < bp->rx_cp_nr_rings; i++) {
1428 struct bnxt_rx_queue *rxq = bp->rx_queues[i];
1429 struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
1430 struct bnxt_ring *ring = rxr->rx_ring_struct;
1431 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
1432 unsigned int idx = i + 1;
1434 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
1435 bnxt_hwrm_ring_free(bp, ring,
1436 HWRM_RING_FREE_INPUT_RING_TYPE_RX);
1437 ring->fw_ring_id = INVALID_HW_RING_ID;
1438 bp->grp_info[idx].rx_fw_ring_id = INVALID_HW_RING_ID;
1439 memset(rxr->rx_desc_ring, 0,
1440 rxr->rx_ring_struct->ring_size *
1441 sizeof(*rxr->rx_desc_ring));
1442 memset(rxr->rx_buf_ring, 0,
1443 rxr->rx_ring_struct->ring_size *
1444 sizeof(*rxr->rx_buf_ring));
1446 memset(rxr->ag_buf_ring, 0,
1447 rxr->ag_ring_struct->ring_size *
1448 sizeof(*rxr->ag_buf_ring));
1451 if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID) {
1452 bnxt_free_cp_ring(bp, cpr, idx);
1453 bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID;
1454 cpr->cp_ring_struct->fw_ring_id = INVALID_HW_RING_ID;
1458 /* Default completion ring */
1460 struct bnxt_cp_ring_info *cpr = bp->def_cp_ring;
1462 if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID) {
1463 bnxt_free_cp_ring(bp, cpr, 0);
1464 cpr->cp_ring_struct->fw_ring_id = INVALID_HW_RING_ID;
1471 int bnxt_alloc_all_hwrm_ring_grps(struct bnxt *bp)
1476 for (i = 0; i < bp->rx_cp_nr_rings; i++) {
1477 rc = bnxt_hwrm_ring_grp_alloc(bp, i);
1484 void bnxt_free_hwrm_resources(struct bnxt *bp)
1486 /* Release memzone */
1487 rte_free(bp->hwrm_cmd_resp_addr);
1488 bp->hwrm_cmd_resp_addr = NULL;
1489 bp->hwrm_cmd_resp_dma_addr = 0;
1492 int bnxt_alloc_hwrm_resources(struct bnxt *bp)
1494 struct rte_pci_device *pdev = bp->pdev;
1495 char type[RTE_MEMZONE_NAMESIZE];
1497 sprintf(type, "bnxt_hwrm_%04x:%02x:%02x:%02x", pdev->addr.domain,
1498 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
1499 bp->max_req_len = HWRM_MAX_REQ_LEN;
1500 bp->max_resp_len = HWRM_MAX_RESP_LEN;
1501 bp->hwrm_cmd_resp_addr = rte_malloc(type, bp->max_resp_len, 0);
1502 rte_mem_lock_page(bp->hwrm_cmd_resp_addr);
1503 if (bp->hwrm_cmd_resp_addr == NULL)
1505 bp->hwrm_cmd_resp_dma_addr =
1506 rte_mem_virt2phy(bp->hwrm_cmd_resp_addr);
1507 if (bp->hwrm_cmd_resp_dma_addr == 0) {
1509 "unable to map response address to physical memory\n");
1512 rte_spinlock_init(&bp->hwrm_lock);
1517 int bnxt_clear_hwrm_vnic_filters(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1519 struct bnxt_filter_info *filter;
1522 STAILQ_FOREACH(filter, &vnic->filter, next) {
1523 rc = bnxt_hwrm_clear_filter(bp, filter);
1530 int bnxt_set_hwrm_vnic_filters(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1532 struct bnxt_filter_info *filter;
1535 STAILQ_FOREACH(filter, &vnic->filter, next) {
1536 rc = bnxt_hwrm_set_filter(bp, vnic->fw_vnic_id, filter);
1543 void bnxt_free_tunnel_ports(struct bnxt *bp)
1545 if (bp->vxlan_port_cnt)
1546 bnxt_hwrm_tunnel_dst_port_free(bp, bp->vxlan_fw_dst_port_id,
1547 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_VXLAN);
1549 if (bp->geneve_port_cnt)
1550 bnxt_hwrm_tunnel_dst_port_free(bp, bp->geneve_fw_dst_port_id,
1551 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_GENEVE);
1552 bp->geneve_port = 0;
1555 void bnxt_free_all_hwrm_resources(struct bnxt *bp)
1557 struct bnxt_vnic_info *vnic;
1560 if (bp->vnic_info == NULL)
1563 vnic = &bp->vnic_info[0];
1565 bnxt_hwrm_cfa_l2_clear_rx_mask(bp, vnic);
1567 /* VNIC resources */
1568 for (i = 0; i < bp->nr_vnics; i++) {
1569 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
1571 bnxt_clear_hwrm_vnic_filters(bp, vnic);
1573 bnxt_hwrm_vnic_ctx_free(bp, vnic);
1575 bnxt_hwrm_vnic_tpa_cfg(bp, vnic, false);
1577 bnxt_hwrm_vnic_free(bp, vnic);
1579 /* Ring resources */
1580 bnxt_free_all_hwrm_rings(bp);
1581 bnxt_free_all_hwrm_ring_grps(bp);
1582 bnxt_free_all_hwrm_stat_ctxs(bp);
1583 bnxt_free_tunnel_ports(bp);
1586 static uint16_t bnxt_parse_eth_link_duplex(uint32_t conf_link_speed)
1588 uint8_t hw_link_duplex = HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH;
1590 if ((conf_link_speed & ETH_LINK_SPEED_FIXED) == ETH_LINK_SPEED_AUTONEG)
1591 return HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH;
1593 switch (conf_link_speed) {
1594 case ETH_LINK_SPEED_10M_HD:
1595 case ETH_LINK_SPEED_100M_HD:
1596 return HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_HALF;
1598 return hw_link_duplex;
1601 static uint16_t bnxt_parse_eth_link_speed(uint32_t conf_link_speed)
1603 uint16_t eth_link_speed = 0;
1605 if (conf_link_speed == ETH_LINK_SPEED_AUTONEG)
1606 return ETH_LINK_SPEED_AUTONEG;
1608 switch (conf_link_speed & ~ETH_LINK_SPEED_FIXED) {
1609 case ETH_LINK_SPEED_100M:
1610 case ETH_LINK_SPEED_100M_HD:
1612 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_100MB;
1614 case ETH_LINK_SPEED_1G:
1616 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_1GB;
1618 case ETH_LINK_SPEED_2_5G:
1620 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_2_5GB;
1622 case ETH_LINK_SPEED_10G:
1624 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_10GB;
1626 case ETH_LINK_SPEED_20G:
1628 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_20GB;
1630 case ETH_LINK_SPEED_25G:
1632 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_25GB;
1634 case ETH_LINK_SPEED_40G:
1636 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_40GB;
1638 case ETH_LINK_SPEED_50G:
1640 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_50GB;
1644 "Unsupported link speed %d; default to AUTO\n",
1648 return eth_link_speed;
1651 #define BNXT_SUPPORTED_SPEEDS (ETH_LINK_SPEED_100M | ETH_LINK_SPEED_100M_HD | \
1652 ETH_LINK_SPEED_1G | ETH_LINK_SPEED_2_5G | \
1653 ETH_LINK_SPEED_10G | ETH_LINK_SPEED_20G | ETH_LINK_SPEED_25G | \
1654 ETH_LINK_SPEED_40G | ETH_LINK_SPEED_50G)
1656 static int bnxt_valid_link_speed(uint32_t link_speed, uint8_t port_id)
1660 if (link_speed == ETH_LINK_SPEED_AUTONEG)
1663 if (link_speed & ETH_LINK_SPEED_FIXED) {
1664 one_speed = link_speed & ~ETH_LINK_SPEED_FIXED;
1666 if (one_speed & (one_speed - 1)) {
1668 "Invalid advertised speeds (%u) for port %u\n",
1669 link_speed, port_id);
1672 if ((one_speed & BNXT_SUPPORTED_SPEEDS) != one_speed) {
1674 "Unsupported advertised speed (%u) for port %u\n",
1675 link_speed, port_id);
1679 if (!(link_speed & BNXT_SUPPORTED_SPEEDS)) {
1681 "Unsupported advertised speeds (%u) for port %u\n",
1682 link_speed, port_id);
1689 static uint16_t bnxt_parse_eth_link_speed_mask(uint32_t link_speed)
1693 if (link_speed == ETH_LINK_SPEED_AUTONEG)
1694 link_speed = BNXT_SUPPORTED_SPEEDS;
1696 if (link_speed & ETH_LINK_SPEED_100M)
1697 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100MB;
1698 if (link_speed & ETH_LINK_SPEED_100M_HD)
1699 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100MB;
1700 if (link_speed & ETH_LINK_SPEED_1G)
1701 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_1GB;
1702 if (link_speed & ETH_LINK_SPEED_2_5G)
1703 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_2_5GB;
1704 if (link_speed & ETH_LINK_SPEED_10G)
1705 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_10GB;
1706 if (link_speed & ETH_LINK_SPEED_20G)
1707 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_20GB;
1708 if (link_speed & ETH_LINK_SPEED_25G)
1709 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_25GB;
1710 if (link_speed & ETH_LINK_SPEED_40G)
1711 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_40GB;
1712 if (link_speed & ETH_LINK_SPEED_50G)
1713 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_50GB;
1717 static uint32_t bnxt_parse_hw_link_speed(uint16_t hw_link_speed)
1719 uint32_t eth_link_speed = ETH_SPEED_NUM_NONE;
1721 switch (hw_link_speed) {
1722 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100MB:
1723 eth_link_speed = ETH_SPEED_NUM_100M;
1725 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_1GB:
1726 eth_link_speed = ETH_SPEED_NUM_1G;
1728 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2_5GB:
1729 eth_link_speed = ETH_SPEED_NUM_2_5G;
1731 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_10GB:
1732 eth_link_speed = ETH_SPEED_NUM_10G;
1734 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_20GB:
1735 eth_link_speed = ETH_SPEED_NUM_20G;
1737 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_25GB:
1738 eth_link_speed = ETH_SPEED_NUM_25G;
1740 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_40GB:
1741 eth_link_speed = ETH_SPEED_NUM_40G;
1743 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_50GB:
1744 eth_link_speed = ETH_SPEED_NUM_50G;
1746 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2GB:
1748 RTE_LOG(ERR, PMD, "HWRM link speed %d not defined\n",
1752 return eth_link_speed;
1755 static uint16_t bnxt_parse_hw_link_duplex(uint16_t hw_link_duplex)
1757 uint16_t eth_link_duplex = ETH_LINK_FULL_DUPLEX;
1759 switch (hw_link_duplex) {
1760 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH:
1761 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_FULL:
1762 eth_link_duplex = ETH_LINK_FULL_DUPLEX;
1764 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_HALF:
1765 eth_link_duplex = ETH_LINK_HALF_DUPLEX;
1768 RTE_LOG(ERR, PMD, "HWRM link duplex %d not defined\n",
1772 return eth_link_duplex;
1775 int bnxt_get_hwrm_link_config(struct bnxt *bp, struct rte_eth_link *link)
1778 struct bnxt_link_info *link_info = &bp->link_info;
1780 rc = bnxt_hwrm_port_phy_qcfg(bp, link_info);
1783 "Get link config failed with rc %d\n", rc);
1786 if (link_info->link_up)
1788 bnxt_parse_hw_link_speed(link_info->link_speed);
1790 link->link_speed = ETH_LINK_SPEED_10M;
1791 link->link_duplex = bnxt_parse_hw_link_duplex(link_info->duplex);
1792 link->link_status = link_info->link_up;
1793 link->link_autoneg = link_info->auto_mode ==
1794 HWRM_PORT_PHY_QCFG_OUTPUT_AUTO_MODE_NONE ?
1795 ETH_LINK_SPEED_FIXED : ETH_LINK_SPEED_AUTONEG;
1800 int bnxt_set_hwrm_link_config(struct bnxt *bp, bool link_up)
1803 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
1804 struct bnxt_link_info link_req;
1807 if (BNXT_NPAR_PF(bp) || BNXT_VF(bp))
1810 rc = bnxt_valid_link_speed(dev_conf->link_speeds,
1811 bp->eth_dev->data->port_id);
1815 memset(&link_req, 0, sizeof(link_req));
1816 link_req.link_up = link_up;
1820 speed = bnxt_parse_eth_link_speed(dev_conf->link_speeds);
1821 link_req.phy_flags = HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESET_PHY;
1823 link_req.phy_flags |=
1824 HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESTART_AUTONEG;
1825 link_req.auto_mode =
1826 HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_SPEED_MASK;
1827 link_req.auto_link_speed_mask =
1828 bnxt_parse_eth_link_speed_mask(dev_conf->link_speeds);
1830 link_req.phy_flags |= HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE;
1831 link_req.link_speed = speed;
1832 RTE_LOG(INFO, PMD, "Set Link Speed %x\n", speed);
1834 link_req.duplex = bnxt_parse_eth_link_duplex(dev_conf->link_speeds);
1835 link_req.auto_pause = bp->link_info.auto_pause;
1836 link_req.force_pause = bp->link_info.force_pause;
1839 rc = bnxt_hwrm_port_phy_cfg(bp, &link_req);
1842 "Set link config failed with rc %d\n", rc);
1845 rte_delay_ms(BNXT_LINK_WAIT_INTERVAL);
1851 int bnxt_hwrm_func_qcfg(struct bnxt *bp)
1853 struct hwrm_func_qcfg_input req = {0};
1854 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
1857 HWRM_PREP(req, FUNC_QCFG, -1, resp);
1858 req.fid = rte_cpu_to_le_16(0xffff);
1860 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1864 /* Hard Coded.. 0xfff VLAN ID mask */
1865 bp->vlan = rte_le_to_cpu_16(resp->vlan) & 0xfff;
1867 switch (resp->port_partition_type) {
1868 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR1_0:
1869 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR1_5:
1870 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR2_0:
1871 bp->port_partition_type = resp->port_partition_type;
1874 bp->port_partition_type = 0;
1881 static void copy_func_cfg_to_qcaps(struct hwrm_func_cfg_input *fcfg,
1882 struct hwrm_func_qcaps_output *qcaps)
1884 qcaps->max_rsscos_ctx = fcfg->num_rsscos_ctxs;
1885 memcpy(qcaps->mac_address, fcfg->dflt_mac_addr,
1886 sizeof(qcaps->mac_address));
1887 qcaps->max_l2_ctxs = fcfg->num_l2_ctxs;
1888 qcaps->max_rx_rings = fcfg->num_rx_rings;
1889 qcaps->max_tx_rings = fcfg->num_tx_rings;
1890 qcaps->max_cmpl_rings = fcfg->num_cmpl_rings;
1891 qcaps->max_stat_ctx = fcfg->num_stat_ctxs;
1893 qcaps->first_vf_id = 0;
1894 qcaps->max_vnics = fcfg->num_vnics;
1895 qcaps->max_decap_records = 0;
1896 qcaps->max_encap_records = 0;
1897 qcaps->max_tx_wm_flows = 0;
1898 qcaps->max_tx_em_flows = 0;
1899 qcaps->max_rx_wm_flows = 0;
1900 qcaps->max_rx_em_flows = 0;
1901 qcaps->max_flow_id = 0;
1902 qcaps->max_mcast_filters = fcfg->num_mcast_filters;
1903 qcaps->max_sp_tx_rings = 0;
1904 qcaps->max_hw_ring_grps = fcfg->num_hw_ring_grps;
1907 static int bnxt_hwrm_pf_func_cfg(struct bnxt *bp, int tx_rings)
1909 struct hwrm_func_cfg_input req = {0};
1910 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1913 req.enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_MTU |
1914 HWRM_FUNC_CFG_INPUT_ENABLES_MRU |
1915 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS |
1916 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
1917 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
1918 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_TX_RINGS |
1919 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RX_RINGS |
1920 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_L2_CTXS |
1921 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_VNICS |
1922 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS);
1923 req.flags = rte_cpu_to_le_32(bp->pf.func_cfg_flags);
1924 req.mtu = rte_cpu_to_le_16(bp->eth_dev->data->mtu + ETHER_HDR_LEN +
1925 ETHER_CRC_LEN + VLAN_TAG_SIZE);
1926 req.mru = rte_cpu_to_le_16(bp->eth_dev->data->mtu + ETHER_HDR_LEN +
1927 ETHER_CRC_LEN + VLAN_TAG_SIZE);
1928 req.num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx);
1929 req.num_stat_ctxs = rte_cpu_to_le_16(bp->max_stat_ctx);
1930 req.num_cmpl_rings = rte_cpu_to_le_16(bp->max_cp_rings);
1931 req.num_tx_rings = rte_cpu_to_le_16(tx_rings);
1932 req.num_rx_rings = rte_cpu_to_le_16(bp->max_rx_rings);
1933 req.num_l2_ctxs = rte_cpu_to_le_16(bp->max_l2_ctx);
1934 req.num_vnics = rte_cpu_to_le_16(bp->max_vnics);
1935 req.num_hw_ring_grps = rte_cpu_to_le_16(bp->max_ring_grps);
1936 req.fid = rte_cpu_to_le_16(0xffff);
1938 HWRM_PREP(req, FUNC_CFG, -1, resp);
1940 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1946 static void populate_vf_func_cfg_req(struct bnxt *bp,
1947 struct hwrm_func_cfg_input *req,
1950 req->enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_MTU |
1951 HWRM_FUNC_CFG_INPUT_ENABLES_MRU |
1952 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS |
1953 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
1954 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
1955 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_TX_RINGS |
1956 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RX_RINGS |
1957 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_L2_CTXS |
1958 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_VNICS |
1959 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS);
1961 req->mtu = rte_cpu_to_le_16(bp->eth_dev->data->mtu + ETHER_HDR_LEN +
1962 ETHER_CRC_LEN + VLAN_TAG_SIZE);
1963 req->mru = rte_cpu_to_le_16(bp->eth_dev->data->mtu + ETHER_HDR_LEN +
1964 ETHER_CRC_LEN + VLAN_TAG_SIZE);
1965 req->num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx /
1967 req->num_stat_ctxs = rte_cpu_to_le_16(bp->max_stat_ctx / (num_vfs + 1));
1968 req->num_cmpl_rings = rte_cpu_to_le_16(bp->max_cp_rings /
1970 req->num_tx_rings = rte_cpu_to_le_16(bp->max_tx_rings / (num_vfs + 1));
1971 req->num_rx_rings = rte_cpu_to_le_16(bp->max_rx_rings / (num_vfs + 1));
1972 req->num_l2_ctxs = rte_cpu_to_le_16(bp->max_l2_ctx / (num_vfs + 1));
1973 /* TODO: For now, do not support VMDq/RFS on VFs. */
1974 req->num_vnics = rte_cpu_to_le_16(1);
1975 req->num_hw_ring_grps = rte_cpu_to_le_16(bp->max_ring_grps /
1979 static void add_random_mac_if_needed(struct bnxt *bp,
1980 struct hwrm_func_cfg_input *cfg_req,
1983 struct ether_addr mac;
1985 if (bnxt_hwrm_func_qcfg_vf_default_mac(bp, vf, &mac))
1988 if (memcmp(mac.addr_bytes, "\x00\x00\x00\x00\x00", 6) == 0) {
1990 rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
1991 eth_random_addr(cfg_req->dflt_mac_addr);
1992 bp->pf.vf_info[vf].random_mac = true;
1994 memcpy(cfg_req->dflt_mac_addr, mac.addr_bytes, ETHER_ADDR_LEN);
1998 static void reserve_resources_from_vf(struct bnxt *bp,
1999 struct hwrm_func_cfg_input *cfg_req,
2002 struct hwrm_func_qcaps_input req = {0};
2003 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
2006 /* Get the actual allocated values now */
2007 HWRM_PREP(req, FUNC_QCAPS, -1, resp);
2008 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
2009 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2012 RTE_LOG(ERR, PMD, "hwrm_func_qcaps failed rc:%d\n", rc);
2013 copy_func_cfg_to_qcaps(cfg_req, resp);
2014 } else if (resp->error_code) {
2015 rc = rte_le_to_cpu_16(resp->error_code);
2016 RTE_LOG(ERR, PMD, "hwrm_func_qcaps error %d\n", rc);
2017 copy_func_cfg_to_qcaps(cfg_req, resp);
2020 bp->max_rsscos_ctx -= rte_le_to_cpu_16(resp->max_rsscos_ctx);
2021 bp->max_stat_ctx -= rte_le_to_cpu_16(resp->max_stat_ctx);
2022 bp->max_cp_rings -= rte_le_to_cpu_16(resp->max_cmpl_rings);
2023 bp->max_tx_rings -= rte_le_to_cpu_16(resp->max_tx_rings);
2024 bp->max_rx_rings -= rte_le_to_cpu_16(resp->max_rx_rings);
2025 bp->max_l2_ctx -= rte_le_to_cpu_16(resp->max_l2_ctxs);
2027 * TODO: While not supporting VMDq with VFs, max_vnics is always
2028 * forced to 1 in this case
2030 //bp->max_vnics -= rte_le_to_cpu_16(esp->max_vnics);
2031 bp->max_ring_grps -= rte_le_to_cpu_16(resp->max_hw_ring_grps);
2034 static int update_pf_resource_max(struct bnxt *bp)
2036 struct hwrm_func_qcfg_input req = {0};
2037 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
2040 /* And copy the allocated numbers into the pf struct */
2041 HWRM_PREP(req, FUNC_QCFG, -1, resp);
2042 req.fid = rte_cpu_to_le_16(0xffff);
2043 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2046 /* Only TX ring value reflects actual allocation? TODO */
2047 bp->max_tx_rings = rte_le_to_cpu_16(resp->alloc_tx_rings);
2048 bp->pf.evb_mode = resp->evb_mode;
2053 int bnxt_hwrm_allocate_pf_only(struct bnxt *bp)
2058 RTE_LOG(ERR, PMD, "Attempt to allcoate VFs on a VF!\n");
2062 rc = bnxt_hwrm_func_qcaps(bp);
2066 bp->pf.func_cfg_flags &=
2067 ~(HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE |
2068 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE);
2069 bp->pf.func_cfg_flags |=
2070 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE;
2071 rc = bnxt_hwrm_pf_func_cfg(bp, bp->max_tx_rings);
2075 int bnxt_hwrm_allocate_vfs(struct bnxt *bp, int num_vfs)
2077 struct hwrm_func_cfg_input req = {0};
2078 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2085 RTE_LOG(ERR, PMD, "Attempt to allcoate VFs on a VF!\n");
2089 rc = bnxt_hwrm_func_qcaps(bp);
2094 bp->pf.active_vfs = num_vfs;
2097 * First, configure the PF to only use one TX ring. This ensures that
2098 * there are enough rings for all VFs.
2100 * If we don't do this, when we call func_alloc() later, we will lock
2101 * extra rings to the PF that won't be available during func_cfg() of
2104 * This has been fixed with firmware versions above 20.6.54
2106 bp->pf.func_cfg_flags &=
2107 ~(HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE |
2108 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE);
2109 bp->pf.func_cfg_flags |=
2110 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE;
2111 rc = bnxt_hwrm_pf_func_cfg(bp, 1);
2116 * Now, create and register a buffer to hold forwarded VF requests
2118 req_buf_sz = num_vfs * HWRM_MAX_REQ_LEN;
2119 bp->pf.vf_req_buf = rte_malloc("bnxt_vf_fwd", req_buf_sz,
2120 page_roundup(num_vfs * HWRM_MAX_REQ_LEN));
2121 if (bp->pf.vf_req_buf == NULL) {
2125 for (sz = 0; sz < req_buf_sz; sz += getpagesize())
2126 rte_mem_lock_page(((char *)bp->pf.vf_req_buf) + sz);
2127 for (i = 0; i < num_vfs; i++)
2128 bp->pf.vf_info[i].req_buf = ((char *)bp->pf.vf_req_buf) +
2129 (i * HWRM_MAX_REQ_LEN);
2131 rc = bnxt_hwrm_func_buf_rgtr(bp);
2135 populate_vf_func_cfg_req(bp, &req, num_vfs);
2137 bp->pf.active_vfs = 0;
2138 for (i = 0; i < num_vfs; i++) {
2139 add_random_mac_if_needed(bp, &req, i);
2141 HWRM_PREP(req, FUNC_CFG, -1, resp);
2142 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[i].func_cfg_flags);
2143 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[i].fid);
2144 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2146 /* Clear enable flag for next pass */
2147 req.enables &= ~rte_cpu_to_le_32(
2148 HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
2150 if (rc || resp->error_code) {
2152 "Failed to initizlie VF %d\n", i);
2154 "Not all VFs available. (%d, %d)\n",
2155 rc, resp->error_code);
2159 reserve_resources_from_vf(bp, &req, i);
2160 bp->pf.active_vfs++;
2164 * Now configure the PF to use "the rest" of the resources
2165 * We're using STD_TX_RING_MODE here though which will limit the TX
2166 * rings. This will allow QoS to function properly. Not setting this
2167 * will cause PF rings to break bandwidth settings.
2169 rc = bnxt_hwrm_pf_func_cfg(bp, bp->max_tx_rings);
2173 rc = update_pf_resource_max(bp);
2180 bnxt_hwrm_func_buf_unrgtr(bp);
2184 int bnxt_hwrm_pf_evb_mode(struct bnxt *bp)
2186 struct hwrm_func_cfg_input req = {0};
2187 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2190 HWRM_PREP(req, FUNC_CFG, -1, resp);
2192 req.fid = rte_cpu_to_le_16(0xffff);
2193 req.enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_EVB_MODE);
2194 req.evb_mode = bp->pf.evb_mode;
2196 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2202 int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt *bp, uint16_t port,
2203 uint8_t tunnel_type)
2205 struct hwrm_tunnel_dst_port_alloc_input req = {0};
2206 struct hwrm_tunnel_dst_port_alloc_output *resp = bp->hwrm_cmd_resp_addr;
2209 HWRM_PREP(req, TUNNEL_DST_PORT_ALLOC, -1, resp);
2210 req.tunnel_type = tunnel_type;
2211 req.tunnel_dst_port_val = port;
2212 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2215 switch (tunnel_type) {
2216 case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_VXLAN:
2217 bp->vxlan_fw_dst_port_id = resp->tunnel_dst_port_id;
2218 bp->vxlan_port = port;
2220 case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_GENEVE:
2221 bp->geneve_fw_dst_port_id = resp->tunnel_dst_port_id;
2222 bp->geneve_port = port;
2230 int bnxt_hwrm_tunnel_dst_port_free(struct bnxt *bp, uint16_t port,
2231 uint8_t tunnel_type)
2233 struct hwrm_tunnel_dst_port_free_input req = {0};
2234 struct hwrm_tunnel_dst_port_free_output *resp = bp->hwrm_cmd_resp_addr;
2237 HWRM_PREP(req, TUNNEL_DST_PORT_FREE, -1, resp);
2238 req.tunnel_type = tunnel_type;
2239 req.tunnel_dst_port_id = rte_cpu_to_be_16(port);
2240 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2246 int bnxt_hwrm_func_cfg_vf_set_flags(struct bnxt *bp, uint16_t vf)
2248 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2249 struct hwrm_func_cfg_input req = {0};
2252 HWRM_PREP(req, FUNC_CFG, -1, resp);
2253 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
2254 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[vf].func_cfg_flags);
2255 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2261 int bnxt_hwrm_func_buf_rgtr(struct bnxt *bp)
2264 struct hwrm_func_buf_rgtr_input req = {.req_type = 0 };
2265 struct hwrm_func_buf_rgtr_output *resp = bp->hwrm_cmd_resp_addr;
2267 HWRM_PREP(req, FUNC_BUF_RGTR, -1, resp);
2269 req.req_buf_num_pages = rte_cpu_to_le_16(1);
2270 req.req_buf_page_size = rte_cpu_to_le_16(
2271 page_getenum(bp->pf.active_vfs * HWRM_MAX_REQ_LEN));
2272 req.req_buf_len = rte_cpu_to_le_16(HWRM_MAX_REQ_LEN);
2273 req.req_buf_page_addr[0] =
2274 rte_cpu_to_le_64(rte_mem_virt2phy(bp->pf.vf_req_buf));
2275 if (req.req_buf_page_addr[0] == 0) {
2277 "unable to map buffer address to physical memory\n");
2281 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2288 int bnxt_hwrm_func_buf_unrgtr(struct bnxt *bp)
2291 struct hwrm_func_buf_unrgtr_input req = {.req_type = 0 };
2292 struct hwrm_func_buf_unrgtr_output *resp = bp->hwrm_cmd_resp_addr;
2294 HWRM_PREP(req, FUNC_BUF_UNRGTR, -1, resp);
2296 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2303 int bnxt_hwrm_func_cfg_def_cp(struct bnxt *bp)
2305 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2306 struct hwrm_func_cfg_input req = {0};
2309 HWRM_PREP(req, FUNC_CFG, -1, resp);
2310 req.fid = rte_cpu_to_le_16(0xffff);
2311 req.flags = rte_cpu_to_le_32(bp->pf.func_cfg_flags);
2312 req.enables = rte_cpu_to_le_32(
2313 HWRM_FUNC_CFG_INPUT_ENABLES_ASYNC_EVENT_CR);
2314 req.async_event_cr = rte_cpu_to_le_16(
2315 bp->def_cp_ring->cp_ring_struct->fw_ring_id);
2316 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2322 int bnxt_hwrm_vf_func_cfg_def_cp(struct bnxt *bp)
2324 struct hwrm_func_vf_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2325 struct hwrm_func_vf_cfg_input req = {0};
2328 HWRM_PREP(req, FUNC_VF_CFG, -1, resp);
2329 req.enables = rte_cpu_to_le_32(
2330 HWRM_FUNC_CFG_INPUT_ENABLES_ASYNC_EVENT_CR);
2331 req.async_event_cr = rte_cpu_to_le_16(
2332 bp->def_cp_ring->cp_ring_struct->fw_ring_id);
2333 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2339 int bnxt_hwrm_set_default_vlan(struct bnxt *bp, int vf, uint8_t is_vf)
2341 struct hwrm_func_cfg_input req = {0};
2342 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2343 uint16_t dflt_vlan, fid;
2344 uint32_t func_cfg_flags;
2347 HWRM_PREP(req, FUNC_CFG, -1, resp);
2350 dflt_vlan = bp->pf.vf_info[vf].dflt_vlan;
2351 fid = bp->pf.vf_info[vf].fid;
2352 func_cfg_flags = bp->pf.vf_info[vf].func_cfg_flags;
2354 fid = rte_cpu_to_le_16(0xffff);
2355 func_cfg_flags = bp->pf.func_cfg_flags;
2356 dflt_vlan = bp->vlan;
2359 req.flags = rte_cpu_to_le_32(func_cfg_flags);
2360 req.fid = rte_cpu_to_le_16(fid);
2361 req.enables |= rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_VLAN);
2362 req.dflt_vlan = rte_cpu_to_le_16(dflt_vlan);
2364 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2370 int bnxt_hwrm_func_bw_cfg(struct bnxt *bp, uint16_t vf,
2371 uint16_t max_bw, uint16_t enables)
2373 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2374 struct hwrm_func_cfg_input req = {0};
2377 HWRM_PREP(req, FUNC_CFG, -1, resp);
2378 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
2379 req.enables |= rte_cpu_to_le_32(enables);
2380 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[vf].func_cfg_flags);
2381 req.max_bw = rte_cpu_to_le_32(max_bw);
2382 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2388 int bnxt_hwrm_reject_fwd_resp(struct bnxt *bp, uint16_t target_id,
2389 void *encaped, size_t ec_size)
2392 struct hwrm_reject_fwd_resp_input req = {.req_type = 0};
2393 struct hwrm_reject_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr;
2395 if (ec_size > sizeof(req.encap_request))
2398 HWRM_PREP(req, REJECT_FWD_RESP, -1, resp);
2400 req.encap_resp_target_id = rte_cpu_to_le_16(target_id);
2401 memcpy(req.encap_request, encaped, ec_size);
2403 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2410 int bnxt_hwrm_func_qcfg_vf_default_mac(struct bnxt *bp, uint16_t vf,
2411 struct ether_addr *mac)
2413 struct hwrm_func_qcfg_input req = {0};
2414 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
2417 HWRM_PREP(req, FUNC_QCFG, -1, resp);
2418 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
2419 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2423 memcpy(mac->addr_bytes, resp->mac_address, ETHER_ADDR_LEN);
2427 int bnxt_hwrm_exec_fwd_resp(struct bnxt *bp, uint16_t target_id,
2428 void *encaped, size_t ec_size)
2431 struct hwrm_exec_fwd_resp_input req = {.req_type = 0};
2432 struct hwrm_exec_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr;
2434 if (ec_size > sizeof(req.encap_request))
2437 HWRM_PREP(req, EXEC_FWD_RESP, -1, resp);
2439 req.encap_resp_target_id = rte_cpu_to_le_16(target_id);
2440 memcpy(req.encap_request, encaped, ec_size);
2442 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2449 int bnxt_hwrm_ctx_qstats(struct bnxt *bp, uint32_t cid, int idx,
2450 struct rte_eth_stats *stats)
2453 struct hwrm_stat_ctx_query_input req = {.req_type = 0};
2454 struct hwrm_stat_ctx_query_output *resp = bp->hwrm_cmd_resp_addr;
2456 HWRM_PREP(req, STAT_CTX_QUERY, -1, resp);
2458 req.stat_ctx_id = rte_cpu_to_le_32(cid);
2460 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2464 stats->q_ipackets[idx] = rte_le_to_cpu_64(resp->rx_ucast_pkts);
2465 stats->q_ipackets[idx] += rte_le_to_cpu_64(resp->rx_mcast_pkts);
2466 stats->q_ipackets[idx] += rte_le_to_cpu_64(resp->rx_bcast_pkts);
2467 stats->q_ibytes[idx] = rte_le_to_cpu_64(resp->rx_ucast_bytes);
2468 stats->q_ibytes[idx] += rte_le_to_cpu_64(resp->rx_mcast_bytes);
2469 stats->q_ibytes[idx] += rte_le_to_cpu_64(resp->rx_bcast_bytes);
2471 stats->q_opackets[idx] = rte_le_to_cpu_64(resp->tx_ucast_pkts);
2472 stats->q_opackets[idx] += rte_le_to_cpu_64(resp->tx_mcast_pkts);
2473 stats->q_opackets[idx] += rte_le_to_cpu_64(resp->tx_bcast_pkts);
2474 stats->q_obytes[idx] = rte_le_to_cpu_64(resp->tx_ucast_bytes);
2475 stats->q_obytes[idx] += rte_le_to_cpu_64(resp->tx_mcast_bytes);
2476 stats->q_obytes[idx] += rte_le_to_cpu_64(resp->tx_bcast_bytes);
2478 stats->q_errors[idx] = rte_le_to_cpu_64(resp->rx_err_pkts);
2479 stats->q_errors[idx] += rte_le_to_cpu_64(resp->tx_err_pkts);
2480 stats->q_errors[idx] += rte_le_to_cpu_64(resp->rx_drop_pkts);
2485 int bnxt_hwrm_port_qstats(struct bnxt *bp)
2487 struct hwrm_port_qstats_input req = {0};
2488 struct hwrm_port_qstats_output *resp = bp->hwrm_cmd_resp_addr;
2489 struct bnxt_pf_info *pf = &bp->pf;
2492 if (!(bp->flags & BNXT_FLAG_PORT_STATS))
2495 HWRM_PREP(req, PORT_QSTATS, -1, resp);
2496 req.port_id = rte_cpu_to_le_16(pf->port_id);
2497 req.tx_stat_host_addr = rte_cpu_to_le_64(bp->hw_tx_port_stats_map);
2498 req.rx_stat_host_addr = rte_cpu_to_le_64(bp->hw_rx_port_stats_map);
2499 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2504 int bnxt_hwrm_port_clr_stats(struct bnxt *bp)
2506 struct hwrm_port_clr_stats_input req = {0};
2507 struct hwrm_port_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
2508 struct bnxt_pf_info *pf = &bp->pf;
2511 if (!(bp->flags & BNXT_FLAG_PORT_STATS))
2514 HWRM_PREP(req, PORT_CLR_STATS, -1, resp);
2515 req.port_id = rte_cpu_to_le_16(pf->port_id);
2516 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2521 int bnxt_hwrm_port_led_qcaps(struct bnxt *bp)
2523 struct hwrm_port_led_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
2524 struct hwrm_port_led_qcaps_input req = {0};
2530 HWRM_PREP(req, PORT_LED_QCAPS, -1, resp);
2531 req.port_id = bp->pf.port_id;
2532 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2535 if (resp->num_leds > 0 && resp->num_leds < BNXT_MAX_LED) {
2538 bp->num_leds = resp->num_leds;
2539 memcpy(bp->leds, &resp->led0_id,
2540 sizeof(bp->leds[0]) * bp->num_leds);
2541 for (i = 0; i < bp->num_leds; i++) {
2542 struct bnxt_led_info *led = &bp->leds[i];
2544 uint16_t caps = led->led_state_caps;
2546 if (!led->led_group_id ||
2547 !BNXT_LED_ALT_BLINK_CAP(caps)) {
2556 int bnxt_hwrm_port_led_cfg(struct bnxt *bp, bool led_on)
2558 struct hwrm_port_led_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2559 struct hwrm_port_led_cfg_input req = {0};
2560 struct bnxt_led_cfg *led_cfg;
2561 uint8_t led_state = HWRM_PORT_LED_QCFG_OUTPUT_LED0_STATE_DEFAULT;
2562 uint16_t duration = 0;
2565 if (!bp->num_leds || BNXT_VF(bp))
2568 HWRM_PREP(req, PORT_LED_CFG, -1, resp);
2570 led_state = HWRM_PORT_LED_CFG_INPUT_LED0_STATE_BLINKALT;
2571 duration = rte_cpu_to_le_16(500);
2573 req.port_id = bp->pf.port_id;
2574 req.num_leds = bp->num_leds;
2575 led_cfg = (struct bnxt_led_cfg *)&req.led0_id;
2576 for (i = 0; i < bp->num_leds; i++, led_cfg++) {
2577 req.enables |= BNXT_LED_DFLT_ENABLES(i);
2578 led_cfg->led_id = bp->leds[i].led_id;
2579 led_cfg->led_state = led_state;
2580 led_cfg->led_blink_on = duration;
2581 led_cfg->led_blink_off = duration;
2582 led_cfg->led_group_id = bp->leds[i].led_group_id;
2585 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2591 static int bnxt_hwrm_func_vf_vnic_query(struct bnxt *bp, uint16_t vf,
2594 struct hwrm_func_vf_vnic_ids_query_input req = {0};
2595 struct hwrm_func_vf_vnic_ids_query_output *resp =
2596 bp->hwrm_cmd_resp_addr;
2599 /* First query all VNIC ids */
2600 HWRM_PREP(req, FUNC_VF_VNIC_IDS_QUERY, -1, resp_vf_vnic_ids);
2602 req.vf_id = rte_cpu_to_le_16(bp->pf.first_vf_id + vf);
2603 req.max_vnic_id_cnt = rte_cpu_to_le_32(bp->pf.total_vnics);
2604 req.vnic_id_tbl_addr = rte_cpu_to_le_64(rte_mem_virt2phy(vnic_ids));
2606 if (req.vnic_id_tbl_addr == 0) {
2608 "unable to map VNIC ID table address to physical memory\n");
2611 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2613 RTE_LOG(ERR, PMD, "hwrm_func_vf_vnic_query failed rc:%d\n", rc);
2615 } else if (resp->error_code) {
2616 rc = rte_le_to_cpu_16(resp->error_code);
2617 RTE_LOG(ERR, PMD, "hwrm_func_vf_vnic_query error %d\n", rc);
2621 return rte_le_to_cpu_32(resp->vnic_id_cnt);
2625 * This function queries the VNIC IDs for a specified VF. It then calls
2626 * the vnic_cb to update the necessary field in vnic_info with cbdata.
2627 * Then it calls the hwrm_cb function to program this new vnic configuration.
2629 int bnxt_hwrm_func_vf_vnic_query_and_config(struct bnxt *bp, uint16_t vf,
2630 void (*vnic_cb)(struct bnxt_vnic_info *, void *), void *cbdata,
2631 int (*hwrm_cb)(struct bnxt *bp, struct bnxt_vnic_info *vnic))
2633 struct bnxt_vnic_info vnic;
2635 int i, num_vnic_ids;
2640 /* First query all VNIC ids */
2641 vnic_id_sz = bp->pf.total_vnics * sizeof(*vnic_ids);
2642 vnic_ids = rte_malloc("bnxt_hwrm_vf_vnic_ids_query", vnic_id_sz,
2643 RTE_CACHE_LINE_SIZE);
2644 if (vnic_ids == NULL) {
2648 for (sz = 0; sz < vnic_id_sz; sz += getpagesize())
2649 rte_mem_lock_page(((char *)vnic_ids) + sz);
2651 num_vnic_ids = bnxt_hwrm_func_vf_vnic_query(bp, vf, vnic_ids);
2653 if (num_vnic_ids < 0)
2654 return num_vnic_ids;
2656 /* Retrieve VNIC, update bd_stall then update */
2658 for (i = 0; i < num_vnic_ids; i++) {
2659 memset(&vnic, 0, sizeof(struct bnxt_vnic_info));
2660 vnic.fw_vnic_id = rte_le_to_cpu_16(vnic_ids[i]);
2661 rc = bnxt_hwrm_vnic_qcfg(bp, &vnic, bp->pf.first_vf_id + vf);
2664 if (vnic.mru == 4) /* Indicates unallocated */
2667 vnic_cb(&vnic, cbdata);
2669 rc = hwrm_cb(bp, &vnic);
2679 int bnxt_hwrm_func_cfg_vf_set_vlan_anti_spoof(struct bnxt *bp, uint16_t vf,
2682 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2683 struct hwrm_func_cfg_input req = {0};
2686 HWRM_PREP(req, FUNC_CFG, -1, resp);
2687 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
2688 req.enables |= rte_cpu_to_le_32(
2689 HWRM_FUNC_CFG_INPUT_ENABLES_VLAN_ANTISPOOF_MODE);
2690 req.vlan_antispoof_mode = on ?
2691 HWRM_FUNC_CFG_INPUT_VLAN_ANTISPOOF_MODE_VALIDATE_VLAN :
2692 HWRM_FUNC_CFG_INPUT_VLAN_ANTISPOOF_MODE_NOCHECK;
2693 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2699 int bnxt_hwrm_func_qcfg_vf_dflt_vnic_id(struct bnxt *bp, int vf)
2701 struct bnxt_vnic_info vnic;
2704 int num_vnic_ids, i;
2708 vnic_id_sz = bp->pf.total_vnics * sizeof(*vnic_ids);
2709 vnic_ids = rte_malloc("bnxt_hwrm_vf_vnic_ids_query", vnic_id_sz,
2710 RTE_CACHE_LINE_SIZE);
2711 if (vnic_ids == NULL) {
2716 for (sz = 0; sz < vnic_id_sz; sz += getpagesize())
2717 rte_mem_lock_page(((char *)vnic_ids) + sz);
2719 rc = bnxt_hwrm_func_vf_vnic_query(bp, vf, vnic_ids);
2725 * Loop through to find the default VNIC ID.
2726 * TODO: The easier way would be to obtain the resp->dflt_vnic_id
2727 * by sending the hwrm_func_qcfg command to the firmware.
2729 for (i = 0; i < num_vnic_ids; i++) {
2730 memset(&vnic, 0, sizeof(struct bnxt_vnic_info));
2731 vnic.fw_vnic_id = rte_le_to_cpu_16(vnic_ids[i]);
2732 rc = bnxt_hwrm_vnic_qcfg(bp, &vnic,
2733 bp->pf.first_vf_id + vf);
2736 if (vnic.func_default) {
2738 return vnic.fw_vnic_id;
2741 /* Could not find a default VNIC. */
2742 RTE_LOG(ERR, PMD, "No default VNIC\n");