1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2018 Broadcom
8 #include <rte_byteorder.h>
9 #include <rte_common.h>
10 #include <rte_cycles.h>
11 #include <rte_malloc.h>
12 #include <rte_memzone.h>
13 #include <rte_version.h>
17 #include "bnxt_filter.h"
18 #include "bnxt_hwrm.h"
21 #include "bnxt_ring.h"
24 #include "bnxt_vnic.h"
25 #include "hsi_struct_def_dpdk.h"
29 #define HWRM_CMD_TIMEOUT 10000
30 #define HWRM_VERSION_1_9_1 0x10901
32 struct bnxt_plcmodes_cfg {
34 uint16_t jumbo_thresh;
36 uint16_t hds_threshold;
39 static int page_getenum(size_t size)
55 PMD_DRV_LOG(ERR, "Page size %zu out of range\n", size);
56 return sizeof(void *) * 8 - 1;
59 static int page_roundup(size_t size)
61 return 1 << page_getenum(size);
65 * HWRM Functions (sent to HWRM)
66 * These are named bnxt_hwrm_*() and return -1 if bnxt_hwrm_send_message()
67 * fails (ie: a timeout), and a positive non-zero HWRM error code if the HWRM
68 * command was failed by the ChiMP.
71 static int bnxt_hwrm_send_message(struct bnxt *bp, void *msg,
75 struct input *req = msg;
76 struct output *resp = bp->hwrm_cmd_resp_addr;
80 uint16_t max_req_len = bp->max_req_len;
81 struct hwrm_short_input short_input = { 0 };
83 if (bp->flags & BNXT_FLAG_SHORT_CMD) {
84 void *short_cmd_req = bp->hwrm_short_cmd_req_addr;
86 memset(short_cmd_req, 0, bp->max_req_len);
87 memcpy(short_cmd_req, req, msg_len);
89 short_input.req_type = rte_cpu_to_le_16(req->req_type);
90 short_input.signature = rte_cpu_to_le_16(
91 HWRM_SHORT_REQ_SIGNATURE_SHORT_CMD);
92 short_input.size = rte_cpu_to_le_16(msg_len);
93 short_input.req_addr =
94 rte_cpu_to_le_64(bp->hwrm_short_cmd_req_dma_addr);
96 data = (uint32_t *)&short_input;
97 msg_len = sizeof(short_input);
99 /* Sync memory write before updating doorbell */
102 max_req_len = BNXT_HWRM_SHORT_REQ_LEN;
105 /* Write request msg to hwrm channel */
106 for (i = 0; i < msg_len; i += 4) {
107 bar = (uint8_t *)bp->bar0 + i;
108 rte_write32(*data, bar);
112 /* Zero the rest of the request space */
113 for (; i < max_req_len; i += 4) {
114 bar = (uint8_t *)bp->bar0 + i;
118 /* Ring channel doorbell */
119 bar = (uint8_t *)bp->bar0 + 0x100;
122 /* Poll for the valid bit */
123 for (i = 0; i < HWRM_CMD_TIMEOUT; i++) {
124 /* Sanity check on the resp->resp_len */
126 if (resp->resp_len && resp->resp_len <=
128 /* Last byte of resp contains the valid key */
129 valid = (uint8_t *)resp + resp->resp_len - 1;
130 if (*valid == HWRM_RESP_VALID_KEY)
136 if (i >= HWRM_CMD_TIMEOUT) {
137 PMD_DRV_LOG(ERR, "Error sending msg 0x%04x\n",
148 * HWRM_PREP() should be used to prepare *ALL* HWRM commands. It grabs the
149 * spinlock, and does initial processing.
151 * HWRM_CHECK_RESULT() returns errors on failure and may not be used. It
152 * releases the spinlock only if it returns. If the regular int return codes
153 * are not used by the function, HWRM_CHECK_RESULT() should not be used
154 * directly, rather it should be copied and modified to suit the function.
156 * HWRM_UNLOCK() must be called after all response processing is completed.
158 #define HWRM_PREP(req, type) do { \
159 rte_spinlock_lock(&bp->hwrm_lock); \
160 memset(bp->hwrm_cmd_resp_addr, 0, bp->max_resp_len); \
161 req.req_type = rte_cpu_to_le_16(HWRM_##type); \
162 req.cmpl_ring = rte_cpu_to_le_16(-1); \
163 req.seq_id = rte_cpu_to_le_16(bp->hwrm_cmd_seq++); \
164 req.target_id = rte_cpu_to_le_16(0xffff); \
165 req.resp_addr = rte_cpu_to_le_64(bp->hwrm_cmd_resp_dma_addr); \
168 #define HWRM_CHECK_RESULT() do {\
170 PMD_DRV_LOG(ERR, "failed rc:%d\n", rc); \
171 rte_spinlock_unlock(&bp->hwrm_lock); \
174 if (resp->error_code) { \
175 rc = rte_le_to_cpu_16(resp->error_code); \
176 if (resp->resp_len >= 16) { \
177 struct hwrm_err_output *tmp_hwrm_err_op = \
180 "error %d:%d:%08x:%04x\n", \
181 rc, tmp_hwrm_err_op->cmd_err, \
183 tmp_hwrm_err_op->opaque_0), \
185 tmp_hwrm_err_op->opaque_1)); \
187 PMD_DRV_LOG(ERR, "error %d\n", rc); \
189 rte_spinlock_unlock(&bp->hwrm_lock); \
194 #define HWRM_UNLOCK() rte_spinlock_unlock(&bp->hwrm_lock)
196 int bnxt_hwrm_cfa_l2_clear_rx_mask(struct bnxt *bp, struct bnxt_vnic_info *vnic)
199 struct hwrm_cfa_l2_set_rx_mask_input req = {.req_type = 0 };
200 struct hwrm_cfa_l2_set_rx_mask_output *resp = bp->hwrm_cmd_resp_addr;
202 HWRM_PREP(req, CFA_L2_SET_RX_MASK);
203 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
206 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
214 int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp,
215 struct bnxt_vnic_info *vnic,
217 struct bnxt_vlan_table_entry *vlan_table)
220 struct hwrm_cfa_l2_set_rx_mask_input req = {.req_type = 0 };
221 struct hwrm_cfa_l2_set_rx_mask_output *resp = bp->hwrm_cmd_resp_addr;
224 if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
227 HWRM_PREP(req, CFA_L2_SET_RX_MASK);
228 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
230 /* FIXME add multicast flag, when multicast adding options is supported
233 if (vnic->flags & BNXT_VNIC_INFO_BCAST)
234 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_BCAST;
235 if (vnic->flags & BNXT_VNIC_INFO_UNTAGGED)
236 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLAN_NONVLAN;
237 if (vnic->flags & BNXT_VNIC_INFO_PROMISC)
238 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_PROMISCUOUS;
239 if (vnic->flags & BNXT_VNIC_INFO_ALLMULTI)
240 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
241 if (vnic->flags & BNXT_VNIC_INFO_MCAST)
242 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_MCAST;
243 if (vnic->mc_addr_cnt) {
244 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_MCAST;
245 req.num_mc_entries = rte_cpu_to_le_32(vnic->mc_addr_cnt);
246 req.mc_tbl_addr = rte_cpu_to_le_64(vnic->mc_list_dma_addr);
249 if (!(mask & HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLAN_NONVLAN))
250 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLANONLY;
251 req.vlan_tag_tbl_addr = rte_cpu_to_le_64(
252 rte_mem_virt2iova(vlan_table));
253 req.num_vlan_tags = rte_cpu_to_le_32((uint32_t)vlan_count);
255 req.mask = rte_cpu_to_le_32(mask);
257 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
265 int bnxt_hwrm_cfa_vlan_antispoof_cfg(struct bnxt *bp, uint16_t fid,
267 struct bnxt_vlan_antispoof_table_entry *vlan_table)
270 struct hwrm_cfa_vlan_antispoof_cfg_input req = {.req_type = 0 };
271 struct hwrm_cfa_vlan_antispoof_cfg_output *resp =
272 bp->hwrm_cmd_resp_addr;
275 * Older HWRM versions did not support this command, and the set_rx_mask
276 * list was used for anti-spoof. In 1.8.0, the TX path configuration was
277 * removed from set_rx_mask call, and this command was added.
279 * This command is also present from 1.7.8.11 and higher,
282 if (bp->fw_ver < ((1 << 24) | (8 << 16))) {
283 if (bp->fw_ver != ((1 << 24) | (7 << 16) | (8 << 8))) {
284 if (bp->fw_ver < ((1 << 24) | (7 << 16) | (8 << 8) |
289 HWRM_PREP(req, CFA_VLAN_ANTISPOOF_CFG);
290 req.fid = rte_cpu_to_le_16(fid);
292 req.vlan_tag_mask_tbl_addr =
293 rte_cpu_to_le_64(rte_mem_virt2iova(vlan_table));
294 req.num_vlan_entries = rte_cpu_to_le_32((uint32_t)vlan_count);
296 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
304 int bnxt_hwrm_clear_l2_filter(struct bnxt *bp,
305 struct bnxt_filter_info *filter)
308 struct hwrm_cfa_l2_filter_free_input req = {.req_type = 0 };
309 struct hwrm_cfa_l2_filter_free_output *resp = bp->hwrm_cmd_resp_addr;
311 if (filter->fw_l2_filter_id == UINT64_MAX)
314 HWRM_PREP(req, CFA_L2_FILTER_FREE);
316 req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
318 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
323 filter->fw_l2_filter_id = UINT64_MAX;
328 int bnxt_hwrm_set_l2_filter(struct bnxt *bp,
330 struct bnxt_filter_info *filter)
333 struct hwrm_cfa_l2_filter_alloc_input req = {.req_type = 0 };
334 struct hwrm_cfa_l2_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr;
335 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
336 const struct rte_eth_vmdq_rx_conf *conf =
337 &dev_conf->rx_adv_conf.vmdq_rx_conf;
338 uint32_t enables = 0;
339 uint16_t j = dst_id - 1;
341 //TODO: Is there a better way to add VLANs to each VNIC in case of VMDQ
342 if ((dev_conf->rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG) &&
343 conf->pool_map[j].pools & (1UL << j)) {
345 "Add vlan %u to vmdq pool %u\n",
346 conf->pool_map[j].vlan_id, j);
348 filter->l2_ivlan = conf->pool_map[j].vlan_id;
350 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN |
351 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN_MASK;
354 if (filter->fw_l2_filter_id != UINT64_MAX)
355 bnxt_hwrm_clear_l2_filter(bp, filter);
357 HWRM_PREP(req, CFA_L2_FILTER_ALLOC);
359 req.flags = rte_cpu_to_le_32(filter->flags);
361 enables = filter->enables |
362 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_DST_ID;
363 req.dst_id = rte_cpu_to_le_16(dst_id);
366 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR)
367 memcpy(req.l2_addr, filter->l2_addr,
370 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR_MASK)
371 memcpy(req.l2_addr_mask, filter->l2_addr_mask,
374 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN)
375 req.l2_ovlan = filter->l2_ovlan;
377 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN)
378 req.l2_ovlan = filter->l2_ivlan;
380 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN_MASK)
381 req.l2_ovlan_mask = filter->l2_ovlan_mask;
383 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN_MASK)
384 req.l2_ovlan_mask = filter->l2_ivlan_mask;
385 if (enables & HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_SRC_ID)
386 req.src_id = rte_cpu_to_le_32(filter->src_id);
387 if (enables & HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_SRC_TYPE)
388 req.src_type = filter->src_type;
390 req.enables = rte_cpu_to_le_32(enables);
392 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
396 filter->fw_l2_filter_id = rte_le_to_cpu_64(resp->l2_filter_id);
402 int bnxt_hwrm_ptp_cfg(struct bnxt *bp)
404 struct hwrm_port_mac_cfg_input req = {.req_type = 0};
405 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
412 HWRM_PREP(req, PORT_MAC_CFG);
415 flags |= PORT_MAC_CFG_REQ_FLAGS_PTP_RX_TS_CAPTURE_ENABLE;
417 flags |= PORT_MAC_CFG_REQ_FLAGS_PTP_RX_TS_CAPTURE_DISABLE;
418 if (ptp->tx_tstamp_en)
419 flags |= PORT_MAC_CFG_REQ_FLAGS_PTP_TX_TS_CAPTURE_ENABLE;
421 flags |= PORT_MAC_CFG_REQ_FLAGS_PTP_TX_TS_CAPTURE_DISABLE;
422 req.flags = rte_cpu_to_le_32(flags);
424 rte_cpu_to_le_32(PORT_MAC_CFG_REQ_ENABLES_RX_TS_CAPTURE_PTP_MSG_TYPE);
425 req.rx_ts_capture_ptp_msg_type = rte_cpu_to_le_16(ptp->rxctl);
427 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
433 static int bnxt_hwrm_ptp_qcfg(struct bnxt *bp)
436 struct hwrm_port_mac_ptp_qcfg_input req = {.req_type = 0};
437 struct hwrm_port_mac_ptp_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
438 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
440 /* if (bp->hwrm_spec_code < 0x10801 || ptp) TBD */
444 HWRM_PREP(req, PORT_MAC_PTP_QCFG);
446 req.port_id = rte_cpu_to_le_16(bp->pf.port_id);
448 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
452 if (!(resp->flags & PORT_MAC_PTP_QCFG_RESP_FLAGS_DIRECT_ACCESS))
455 ptp = rte_zmalloc("ptp_cfg", sizeof(*ptp), 0);
459 ptp->rx_regs[BNXT_PTP_RX_TS_L] =
460 rte_le_to_cpu_32(resp->rx_ts_reg_off_lower);
461 ptp->rx_regs[BNXT_PTP_RX_TS_H] =
462 rte_le_to_cpu_32(resp->rx_ts_reg_off_upper);
463 ptp->rx_regs[BNXT_PTP_RX_SEQ] =
464 rte_le_to_cpu_32(resp->rx_ts_reg_off_seq_id);
465 ptp->rx_regs[BNXT_PTP_RX_FIFO] =
466 rte_le_to_cpu_32(resp->rx_ts_reg_off_fifo);
467 ptp->rx_regs[BNXT_PTP_RX_FIFO_ADV] =
468 rte_le_to_cpu_32(resp->rx_ts_reg_off_fifo_adv);
469 ptp->tx_regs[BNXT_PTP_TX_TS_L] =
470 rte_le_to_cpu_32(resp->tx_ts_reg_off_lower);
471 ptp->tx_regs[BNXT_PTP_TX_TS_H] =
472 rte_le_to_cpu_32(resp->tx_ts_reg_off_upper);
473 ptp->tx_regs[BNXT_PTP_TX_SEQ] =
474 rte_le_to_cpu_32(resp->tx_ts_reg_off_seq_id);
475 ptp->tx_regs[BNXT_PTP_TX_FIFO] =
476 rte_le_to_cpu_32(resp->tx_ts_reg_off_fifo);
484 int bnxt_hwrm_func_qcaps(struct bnxt *bp)
487 struct hwrm_func_qcaps_input req = {.req_type = 0 };
488 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
489 uint16_t new_max_vfs;
493 HWRM_PREP(req, FUNC_QCAPS);
495 req.fid = rte_cpu_to_le_16(0xffff);
497 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
501 bp->max_ring_grps = rte_le_to_cpu_32(resp->max_hw_ring_grps);
502 flags = rte_le_to_cpu_32(resp->flags);
504 bp->pf.port_id = resp->port_id;
505 bp->pf.first_vf_id = rte_le_to_cpu_16(resp->first_vf_id);
506 new_max_vfs = bp->pdev->max_vfs;
507 if (new_max_vfs != bp->pf.max_vfs) {
509 rte_free(bp->pf.vf_info);
510 bp->pf.vf_info = rte_malloc("bnxt_vf_info",
511 sizeof(bp->pf.vf_info[0]) * new_max_vfs, 0);
512 bp->pf.max_vfs = new_max_vfs;
513 for (i = 0; i < new_max_vfs; i++) {
514 bp->pf.vf_info[i].fid = bp->pf.first_vf_id + i;
515 bp->pf.vf_info[i].vlan_table =
516 rte_zmalloc("VF VLAN table",
519 if (bp->pf.vf_info[i].vlan_table == NULL)
521 "Fail to alloc VLAN table for VF %d\n",
525 bp->pf.vf_info[i].vlan_table);
526 bp->pf.vf_info[i].vlan_as_table =
527 rte_zmalloc("VF VLAN AS table",
530 if (bp->pf.vf_info[i].vlan_as_table == NULL)
532 "Alloc VLAN AS table for VF %d fail\n",
536 bp->pf.vf_info[i].vlan_as_table);
537 STAILQ_INIT(&bp->pf.vf_info[i].filter);
542 bp->fw_fid = rte_le_to_cpu_32(resp->fid);
543 memcpy(bp->dflt_mac_addr, &resp->mac_address, ETHER_ADDR_LEN);
544 bp->max_rsscos_ctx = rte_le_to_cpu_16(resp->max_rsscos_ctx);
545 bp->max_cp_rings = rte_le_to_cpu_16(resp->max_cmpl_rings);
546 bp->max_tx_rings = rte_le_to_cpu_16(resp->max_tx_rings);
547 bp->max_rx_rings = rte_le_to_cpu_16(resp->max_rx_rings);
548 bp->max_l2_ctx = rte_le_to_cpu_16(resp->max_l2_ctxs);
549 /* TODO: For now, do not support VMDq/RFS on VFs. */
554 bp->max_vnics = rte_le_to_cpu_16(resp->max_vnics);
558 bp->max_stat_ctx = rte_le_to_cpu_16(resp->max_stat_ctx);
560 bp->pf.total_vnics = rte_le_to_cpu_16(resp->max_vnics);
561 if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_PTP_SUPPORTED) {
562 bp->flags |= BNXT_FLAG_PTP_SUPPORTED;
563 PMD_DRV_LOG(INFO, "PTP SUPPORTED\n");
565 bnxt_hwrm_ptp_qcfg(bp);
574 int bnxt_hwrm_func_reset(struct bnxt *bp)
577 struct hwrm_func_reset_input req = {.req_type = 0 };
578 struct hwrm_func_reset_output *resp = bp->hwrm_cmd_resp_addr;
580 HWRM_PREP(req, FUNC_RESET);
582 req.enables = rte_cpu_to_le_32(0);
584 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
592 int bnxt_hwrm_func_driver_register(struct bnxt *bp)
595 struct hwrm_func_drv_rgtr_input req = {.req_type = 0 };
596 struct hwrm_func_drv_rgtr_output *resp = bp->hwrm_cmd_resp_addr;
598 if (bp->flags & BNXT_FLAG_REGISTERED)
601 HWRM_PREP(req, FUNC_DRV_RGTR);
602 req.enables = rte_cpu_to_le_32(HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_VER |
603 HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_ASYNC_EVENT_FWD);
604 req.ver_maj = RTE_VER_YEAR;
605 req.ver_min = RTE_VER_MONTH;
606 req.ver_upd = RTE_VER_MINOR;
609 req.enables |= rte_cpu_to_le_32(
610 HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_VF_INPUT_FWD);
611 memcpy(req.vf_req_fwd, bp->pf.vf_req_fwd,
612 RTE_MIN(sizeof(req.vf_req_fwd),
613 sizeof(bp->pf.vf_req_fwd)));
616 * PF can sniff HWRM API issued by VF. This can be set up by
617 * linux driver and inherited by the DPDK PF driver. Clear
618 * this HWRM sniffer list in FW because DPDK PF driver does
622 rte_cpu_to_le_32(HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_FWD_NONE_MODE);
625 req.async_event_fwd[0] |=
626 rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_LINK_STATUS_CHANGE |
627 ASYNC_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED |
628 ASYNC_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE);
629 req.async_event_fwd[1] |=
630 rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_PF_DRVR_UNLOAD |
631 ASYNC_CMPL_EVENT_ID_VF_CFG_CHANGE);
633 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
638 bp->flags |= BNXT_FLAG_REGISTERED;
643 int bnxt_hwrm_ver_get(struct bnxt *bp)
646 struct hwrm_ver_get_input req = {.req_type = 0 };
647 struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr;
650 uint16_t max_resp_len;
651 char type[RTE_MEMZONE_NAMESIZE];
652 uint32_t dev_caps_cfg;
654 bp->max_req_len = HWRM_MAX_REQ_LEN;
655 HWRM_PREP(req, VER_GET);
657 req.hwrm_intf_maj = HWRM_VERSION_MAJOR;
658 req.hwrm_intf_min = HWRM_VERSION_MINOR;
659 req.hwrm_intf_upd = HWRM_VERSION_UPDATE;
661 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
665 PMD_DRV_LOG(INFO, "%d.%d.%d:%d.%d.%d\n",
666 resp->hwrm_intf_maj, resp->hwrm_intf_min,
668 resp->hwrm_fw_maj, resp->hwrm_fw_min, resp->hwrm_fw_bld);
669 bp->fw_ver = (resp->hwrm_fw_maj << 24) | (resp->hwrm_fw_min << 16) |
670 (resp->hwrm_fw_bld << 8) | resp->hwrm_fw_rsvd;
671 PMD_DRV_LOG(INFO, "Driver HWRM version: %d.%d.%d\n",
672 HWRM_VERSION_MAJOR, HWRM_VERSION_MINOR, HWRM_VERSION_UPDATE);
674 my_version = HWRM_VERSION_MAJOR << 16;
675 my_version |= HWRM_VERSION_MINOR << 8;
676 my_version |= HWRM_VERSION_UPDATE;
678 fw_version = resp->hwrm_intf_maj << 16;
679 fw_version |= resp->hwrm_intf_min << 8;
680 fw_version |= resp->hwrm_intf_upd;
681 bp->hwrm_spec_code = fw_version;
683 if (resp->hwrm_intf_maj != HWRM_VERSION_MAJOR) {
684 PMD_DRV_LOG(ERR, "Unsupported firmware API version\n");
689 if (my_version != fw_version) {
690 PMD_DRV_LOG(INFO, "BNXT Driver/HWRM API mismatch.\n");
691 if (my_version < fw_version) {
693 "Firmware API version is newer than driver.\n");
695 "The driver may be missing features.\n");
698 "Firmware API version is older than driver.\n");
700 "Not all driver features may be functional.\n");
704 if (bp->max_req_len > resp->max_req_win_len) {
705 PMD_DRV_LOG(ERR, "Unsupported request length\n");
708 bp->max_req_len = rte_le_to_cpu_16(resp->max_req_win_len);
709 max_resp_len = resp->max_resp_len;
710 dev_caps_cfg = rte_le_to_cpu_32(resp->dev_caps_cfg);
712 if (bp->max_resp_len != max_resp_len) {
713 sprintf(type, "bnxt_hwrm_%04x:%02x:%02x:%02x",
714 bp->pdev->addr.domain, bp->pdev->addr.bus,
715 bp->pdev->addr.devid, bp->pdev->addr.function);
717 rte_free(bp->hwrm_cmd_resp_addr);
719 bp->hwrm_cmd_resp_addr = rte_malloc(type, max_resp_len, 0);
720 if (bp->hwrm_cmd_resp_addr == NULL) {
724 rte_mem_lock_page(bp->hwrm_cmd_resp_addr);
725 bp->hwrm_cmd_resp_dma_addr =
726 rte_mem_virt2iova(bp->hwrm_cmd_resp_addr);
727 if (bp->hwrm_cmd_resp_dma_addr == 0) {
729 "Unable to map response buffer to physical memory.\n");
733 bp->max_resp_len = max_resp_len;
737 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
739 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_INPUTUIRED)) {
740 PMD_DRV_LOG(DEBUG, "Short command supported\n");
742 rte_free(bp->hwrm_short_cmd_req_addr);
744 bp->hwrm_short_cmd_req_addr = rte_malloc(type,
746 if (bp->hwrm_short_cmd_req_addr == NULL) {
750 rte_mem_lock_page(bp->hwrm_short_cmd_req_addr);
751 bp->hwrm_short_cmd_req_dma_addr =
752 rte_mem_virt2iova(bp->hwrm_short_cmd_req_addr);
753 if (bp->hwrm_short_cmd_req_dma_addr == 0) {
754 rte_free(bp->hwrm_short_cmd_req_addr);
756 "Unable to map buffer to physical memory.\n");
761 bp->flags |= BNXT_FLAG_SHORT_CMD;
769 int bnxt_hwrm_func_driver_unregister(struct bnxt *bp, uint32_t flags)
772 struct hwrm_func_drv_unrgtr_input req = {.req_type = 0 };
773 struct hwrm_func_drv_unrgtr_output *resp = bp->hwrm_cmd_resp_addr;
775 if (!(bp->flags & BNXT_FLAG_REGISTERED))
778 HWRM_PREP(req, FUNC_DRV_UNRGTR);
781 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
786 bp->flags &= ~BNXT_FLAG_REGISTERED;
791 static int bnxt_hwrm_port_phy_cfg(struct bnxt *bp, struct bnxt_link_info *conf)
794 struct hwrm_port_phy_cfg_input req = {0};
795 struct hwrm_port_phy_cfg_output *resp = bp->hwrm_cmd_resp_addr;
796 uint32_t enables = 0;
798 HWRM_PREP(req, PORT_PHY_CFG);
801 /* Setting Fixed Speed. But AutoNeg is ON, So disable it */
802 if (bp->link_info.auto_mode && conf->link_speed) {
803 req.auto_mode = HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_NONE;
804 PMD_DRV_LOG(DEBUG, "Disabling AutoNeg\n");
807 req.flags = rte_cpu_to_le_32(conf->phy_flags);
808 req.force_link_speed = rte_cpu_to_le_16(conf->link_speed);
809 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_MODE;
811 * Note, ChiMP FW 20.2.1 and 20.2.2 return an error when we set
812 * any auto mode, even "none".
814 if (!conf->link_speed) {
815 /* No speeds specified. Enable AutoNeg - all speeds */
817 HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_ALL_SPEEDS;
819 /* AutoNeg - Advertise speeds specified. */
820 if (conf->auto_link_speed_mask &&
821 !(conf->phy_flags & HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE)) {
823 HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_SPEED_MASK;
824 req.auto_link_speed_mask =
825 conf->auto_link_speed_mask;
827 HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_LINK_SPEED_MASK;
830 req.auto_duplex = conf->duplex;
831 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_DUPLEX;
832 req.auto_pause = conf->auto_pause;
833 req.force_pause = conf->force_pause;
834 /* Set force_pause if there is no auto or if there is a force */
835 if (req.auto_pause && !req.force_pause)
836 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_PAUSE;
838 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_FORCE_PAUSE;
840 req.enables = rte_cpu_to_le_32(enables);
843 rte_cpu_to_le_32(HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE_LINK_DWN);
844 PMD_DRV_LOG(INFO, "Force Link Down\n");
847 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
855 static int bnxt_hwrm_port_phy_qcfg(struct bnxt *bp,
856 struct bnxt_link_info *link_info)
859 struct hwrm_port_phy_qcfg_input req = {0};
860 struct hwrm_port_phy_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
862 HWRM_PREP(req, PORT_PHY_QCFG);
864 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
868 link_info->phy_link_status = resp->link;
870 (link_info->phy_link_status ==
871 HWRM_PORT_PHY_QCFG_OUTPUT_LINK_LINK) ? 1 : 0;
872 link_info->link_speed = rte_le_to_cpu_16(resp->link_speed);
873 link_info->duplex = resp->duplex_cfg;
874 link_info->pause = resp->pause;
875 link_info->auto_pause = resp->auto_pause;
876 link_info->force_pause = resp->force_pause;
877 link_info->auto_mode = resp->auto_mode;
878 link_info->phy_type = resp->phy_type;
879 link_info->media_type = resp->media_type;
881 link_info->support_speeds = rte_le_to_cpu_16(resp->support_speeds);
882 link_info->auto_link_speed = rte_le_to_cpu_16(resp->auto_link_speed);
883 link_info->preemphasis = rte_le_to_cpu_32(resp->preemphasis);
884 link_info->force_link_speed = rte_le_to_cpu_16(resp->force_link_speed);
885 link_info->phy_ver[0] = resp->phy_maj;
886 link_info->phy_ver[1] = resp->phy_min;
887 link_info->phy_ver[2] = resp->phy_bld;
891 PMD_DRV_LOG(DEBUG, "Link Speed %d\n", link_info->link_speed);
892 PMD_DRV_LOG(DEBUG, "Auto Mode %d\n", link_info->auto_mode);
893 PMD_DRV_LOG(DEBUG, "Support Speeds %x\n", link_info->support_speeds);
894 PMD_DRV_LOG(DEBUG, "Auto Link Speed %x\n", link_info->auto_link_speed);
895 PMD_DRV_LOG(DEBUG, "Auto Link Speed Mask %x\n",
896 link_info->auto_link_speed_mask);
897 PMD_DRV_LOG(DEBUG, "Forced Link Speed %x\n",
898 link_info->force_link_speed);
903 int bnxt_hwrm_queue_qportcfg(struct bnxt *bp)
906 struct hwrm_queue_qportcfg_input req = {.req_type = 0 };
907 struct hwrm_queue_qportcfg_output *resp = bp->hwrm_cmd_resp_addr;
910 HWRM_PREP(req, QUEUE_QPORTCFG);
912 req.flags = HWRM_QUEUE_QPORTCFG_INPUT_FLAGS_PATH_TX;
913 /* HWRM Version >= 1.9.1 */
914 if (bp->hwrm_spec_code >= HWRM_VERSION_1_9_1)
916 HWRM_QUEUE_QPORTCFG_INPUT_DRV_QMAP_CAP_ENABLED;
917 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
921 #define GET_QUEUE_INFO(x) \
922 bp->cos_queue[x].id = resp->queue_id##x; \
923 bp->cos_queue[x].profile = resp->queue_id##x##_service_profile
936 if (bp->hwrm_spec_code < HWRM_VERSION_1_9_1) {
937 bp->tx_cosq_id = bp->cos_queue[0].id;
939 /* iterate and find the COSq profile to use for Tx */
940 for (i = 0; i < BNXT_COS_QUEUE_COUNT; i++) {
941 if (bp->cos_queue[i].profile ==
942 HWRM_QUEUE_SERVICE_PROFILE_LOSSY) {
943 bp->tx_cosq_id = bp->cos_queue[i].id;
948 PMD_DRV_LOG(DEBUG, "Tx Cos Queue to use: %d\n", bp->tx_cosq_id);
953 int bnxt_hwrm_ring_alloc(struct bnxt *bp,
954 struct bnxt_ring *ring,
955 uint32_t ring_type, uint32_t map_index,
956 uint32_t stats_ctx_id, uint32_t cmpl_ring_id)
959 uint32_t enables = 0;
960 struct hwrm_ring_alloc_input req = {.req_type = 0 };
961 struct hwrm_ring_alloc_output *resp = bp->hwrm_cmd_resp_addr;
963 HWRM_PREP(req, RING_ALLOC);
965 req.page_tbl_addr = rte_cpu_to_le_64(ring->bd_dma);
966 req.fbo = rte_cpu_to_le_32(0);
967 /* Association of ring index with doorbell index */
968 req.logical_id = rte_cpu_to_le_16(map_index);
969 req.length = rte_cpu_to_le_32(ring->ring_size);
972 case HWRM_RING_ALLOC_INPUT_RING_TYPE_TX:
973 req.queue_id = rte_cpu_to_le_16(bp->tx_cosq_id);
975 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX:
976 req.ring_type = ring_type;
977 req.cmpl_ring_id = rte_cpu_to_le_16(cmpl_ring_id);
978 req.stat_ctx_id = rte_cpu_to_le_16(stats_ctx_id);
979 if (stats_ctx_id != INVALID_STATS_CTX_ID)
981 HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID;
983 case HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL:
984 req.ring_type = ring_type;
986 * TODO: Some HWRM versions crash with
987 * HWRM_RING_ALLOC_INPUT_INT_MODE_POLL
989 req.int_mode = HWRM_RING_ALLOC_INPUT_INT_MODE_MSIX;
992 PMD_DRV_LOG(ERR, "hwrm alloc invalid ring type %d\n",
997 req.enables = rte_cpu_to_le_32(enables);
999 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1001 if (rc || resp->error_code) {
1002 if (rc == 0 && resp->error_code)
1003 rc = rte_le_to_cpu_16(resp->error_code);
1004 switch (ring_type) {
1005 case HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL:
1007 "hwrm_ring_alloc cp failed. rc:%d\n", rc);
1010 case HWRM_RING_FREE_INPUT_RING_TYPE_RX:
1012 "hwrm_ring_alloc rx failed. rc:%d\n", rc);
1015 case HWRM_RING_FREE_INPUT_RING_TYPE_TX:
1017 "hwrm_ring_alloc tx failed. rc:%d\n", rc);
1021 PMD_DRV_LOG(ERR, "Invalid ring. rc:%d\n", rc);
1027 ring->fw_ring_id = rte_le_to_cpu_16(resp->ring_id);
1032 int bnxt_hwrm_ring_free(struct bnxt *bp,
1033 struct bnxt_ring *ring, uint32_t ring_type)
1036 struct hwrm_ring_free_input req = {.req_type = 0 };
1037 struct hwrm_ring_free_output *resp = bp->hwrm_cmd_resp_addr;
1039 HWRM_PREP(req, RING_FREE);
1041 req.ring_type = ring_type;
1042 req.ring_id = rte_cpu_to_le_16(ring->fw_ring_id);
1044 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1046 if (rc || resp->error_code) {
1047 if (rc == 0 && resp->error_code)
1048 rc = rte_le_to_cpu_16(resp->error_code);
1051 switch (ring_type) {
1052 case HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL:
1053 PMD_DRV_LOG(ERR, "hwrm_ring_free cp failed. rc:%d\n",
1056 case HWRM_RING_FREE_INPUT_RING_TYPE_RX:
1057 PMD_DRV_LOG(ERR, "hwrm_ring_free rx failed. rc:%d\n",
1060 case HWRM_RING_FREE_INPUT_RING_TYPE_TX:
1061 PMD_DRV_LOG(ERR, "hwrm_ring_free tx failed. rc:%d\n",
1065 PMD_DRV_LOG(ERR, "Invalid ring, rc:%d\n", rc);
1073 int bnxt_hwrm_ring_grp_alloc(struct bnxt *bp, unsigned int idx)
1076 struct hwrm_ring_grp_alloc_input req = {.req_type = 0 };
1077 struct hwrm_ring_grp_alloc_output *resp = bp->hwrm_cmd_resp_addr;
1079 HWRM_PREP(req, RING_GRP_ALLOC);
1081 req.cr = rte_cpu_to_le_16(bp->grp_info[idx].cp_fw_ring_id);
1082 req.rr = rte_cpu_to_le_16(bp->grp_info[idx].rx_fw_ring_id);
1083 req.ar = rte_cpu_to_le_16(bp->grp_info[idx].ag_fw_ring_id);
1084 req.sc = rte_cpu_to_le_16(bp->grp_info[idx].fw_stats_ctx);
1086 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1088 HWRM_CHECK_RESULT();
1090 bp->grp_info[idx].fw_grp_id =
1091 rte_le_to_cpu_16(resp->ring_group_id);
1098 int bnxt_hwrm_ring_grp_free(struct bnxt *bp, unsigned int idx)
1101 struct hwrm_ring_grp_free_input req = {.req_type = 0 };
1102 struct hwrm_ring_grp_free_output *resp = bp->hwrm_cmd_resp_addr;
1104 HWRM_PREP(req, RING_GRP_FREE);
1106 req.ring_group_id = rte_cpu_to_le_16(bp->grp_info[idx].fw_grp_id);
1108 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1110 HWRM_CHECK_RESULT();
1113 bp->grp_info[idx].fw_grp_id = INVALID_HW_RING_ID;
1117 int bnxt_hwrm_stat_clear(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
1120 struct hwrm_stat_ctx_clr_stats_input req = {.req_type = 0 };
1121 struct hwrm_stat_ctx_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
1123 if (cpr->hw_stats_ctx_id == (uint32_t)HWRM_NA_SIGNATURE)
1126 HWRM_PREP(req, STAT_CTX_CLR_STATS);
1128 req.stat_ctx_id = rte_cpu_to_le_16(cpr->hw_stats_ctx_id);
1130 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1132 HWRM_CHECK_RESULT();
1138 int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
1139 unsigned int idx __rte_unused)
1142 struct hwrm_stat_ctx_alloc_input req = {.req_type = 0 };
1143 struct hwrm_stat_ctx_alloc_output *resp = bp->hwrm_cmd_resp_addr;
1145 HWRM_PREP(req, STAT_CTX_ALLOC);
1147 req.update_period_ms = rte_cpu_to_le_32(0);
1149 req.stats_dma_addr =
1150 rte_cpu_to_le_64(cpr->hw_stats_map);
1152 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1154 HWRM_CHECK_RESULT();
1156 cpr->hw_stats_ctx_id = rte_le_to_cpu_16(resp->stat_ctx_id);
1163 int bnxt_hwrm_stat_ctx_free(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
1164 unsigned int idx __rte_unused)
1167 struct hwrm_stat_ctx_free_input req = {.req_type = 0 };
1168 struct hwrm_stat_ctx_free_output *resp = bp->hwrm_cmd_resp_addr;
1170 HWRM_PREP(req, STAT_CTX_FREE);
1172 req.stat_ctx_id = rte_cpu_to_le_16(cpr->hw_stats_ctx_id);
1174 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1176 HWRM_CHECK_RESULT();
1182 int bnxt_hwrm_vnic_alloc(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1185 struct hwrm_vnic_alloc_input req = { 0 };
1186 struct hwrm_vnic_alloc_output *resp = bp->hwrm_cmd_resp_addr;
1188 /* map ring groups to this vnic */
1189 PMD_DRV_LOG(DEBUG, "Alloc VNIC. Start %x, End %x\n",
1190 vnic->start_grp_id, vnic->end_grp_id);
1191 for (i = vnic->start_grp_id, j = 0; i <= vnic->end_grp_id; i++, j++)
1192 vnic->fw_grp_ids[j] = bp->grp_info[i].fw_grp_id;
1193 vnic->dflt_ring_grp = bp->grp_info[vnic->start_grp_id].fw_grp_id;
1194 vnic->rss_rule = (uint16_t)HWRM_NA_SIGNATURE;
1195 vnic->cos_rule = (uint16_t)HWRM_NA_SIGNATURE;
1196 vnic->lb_rule = (uint16_t)HWRM_NA_SIGNATURE;
1197 vnic->mru = bp->eth_dev->data->mtu + ETHER_HDR_LEN +
1198 ETHER_CRC_LEN + VLAN_TAG_SIZE;
1199 HWRM_PREP(req, VNIC_ALLOC);
1201 if (vnic->func_default)
1203 rte_cpu_to_le_32(HWRM_VNIC_ALLOC_INPUT_FLAGS_DEFAULT);
1204 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1206 HWRM_CHECK_RESULT();
1208 vnic->fw_vnic_id = rte_le_to_cpu_16(resp->vnic_id);
1210 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
1214 static int bnxt_hwrm_vnic_plcmodes_qcfg(struct bnxt *bp,
1215 struct bnxt_vnic_info *vnic,
1216 struct bnxt_plcmodes_cfg *pmode)
1219 struct hwrm_vnic_plcmodes_qcfg_input req = {.req_type = 0 };
1220 struct hwrm_vnic_plcmodes_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
1222 HWRM_PREP(req, VNIC_PLCMODES_QCFG);
1224 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1226 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1228 HWRM_CHECK_RESULT();
1230 pmode->flags = rte_le_to_cpu_32(resp->flags);
1231 /* dflt_vnic bit doesn't exist in the _cfg command */
1232 pmode->flags &= ~(HWRM_VNIC_PLCMODES_QCFG_OUTPUT_FLAGS_DFLT_VNIC);
1233 pmode->jumbo_thresh = rte_le_to_cpu_16(resp->jumbo_thresh);
1234 pmode->hds_offset = rte_le_to_cpu_16(resp->hds_offset);
1235 pmode->hds_threshold = rte_le_to_cpu_16(resp->hds_threshold);
1242 static int bnxt_hwrm_vnic_plcmodes_cfg(struct bnxt *bp,
1243 struct bnxt_vnic_info *vnic,
1244 struct bnxt_plcmodes_cfg *pmode)
1247 struct hwrm_vnic_plcmodes_cfg_input req = {.req_type = 0 };
1248 struct hwrm_vnic_plcmodes_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1250 HWRM_PREP(req, VNIC_PLCMODES_CFG);
1252 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1253 req.flags = rte_cpu_to_le_32(pmode->flags);
1254 req.jumbo_thresh = rte_cpu_to_le_16(pmode->jumbo_thresh);
1255 req.hds_offset = rte_cpu_to_le_16(pmode->hds_offset);
1256 req.hds_threshold = rte_cpu_to_le_16(pmode->hds_threshold);
1257 req.enables = rte_cpu_to_le_32(
1258 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_HDS_THRESHOLD_VALID |
1259 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_HDS_OFFSET_VALID |
1260 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_JUMBO_THRESH_VALID
1263 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1265 HWRM_CHECK_RESULT();
1271 int bnxt_hwrm_vnic_cfg(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1274 struct hwrm_vnic_cfg_input req = {.req_type = 0 };
1275 struct hwrm_vnic_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1276 uint32_t ctx_enable_flag = 0;
1277 struct bnxt_plcmodes_cfg pmodes;
1279 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1280 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
1284 rc = bnxt_hwrm_vnic_plcmodes_qcfg(bp, vnic, &pmodes);
1288 HWRM_PREP(req, VNIC_CFG);
1290 /* Only RSS support for now TBD: COS & LB */
1292 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_ENABLES_DFLT_RING_GRP);
1293 if (vnic->lb_rule != 0xffff)
1294 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_LB_RULE;
1295 if (vnic->cos_rule != 0xffff)
1296 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_COS_RULE;
1297 if (vnic->rss_rule != 0xffff) {
1298 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_MRU;
1299 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_RSS_RULE;
1301 req.enables |= rte_cpu_to_le_32(ctx_enable_flag);
1302 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1303 req.dflt_ring_grp = rte_cpu_to_le_16(vnic->dflt_ring_grp);
1304 req.rss_rule = rte_cpu_to_le_16(vnic->rss_rule);
1305 req.cos_rule = rte_cpu_to_le_16(vnic->cos_rule);
1306 req.lb_rule = rte_cpu_to_le_16(vnic->lb_rule);
1307 req.mru = rte_cpu_to_le_16(vnic->mru);
1308 if (vnic->func_default)
1310 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_DEFAULT);
1311 if (vnic->vlan_strip)
1313 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_VLAN_STRIP_MODE);
1316 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_BD_STALL_MODE);
1317 if (vnic->roce_dual)
1318 req.flags |= rte_cpu_to_le_32(
1319 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_DUAL_VNIC_MODE);
1320 if (vnic->roce_only)
1321 req.flags |= rte_cpu_to_le_32(
1322 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_ONLY_VNIC_MODE);
1323 if (vnic->rss_dflt_cr)
1324 req.flags |= rte_cpu_to_le_32(
1325 HWRM_VNIC_QCFG_OUTPUT_FLAGS_RSS_DFLT_CR_MODE);
1327 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1329 HWRM_CHECK_RESULT();
1332 rc = bnxt_hwrm_vnic_plcmodes_cfg(bp, vnic, &pmodes);
1337 int bnxt_hwrm_vnic_qcfg(struct bnxt *bp, struct bnxt_vnic_info *vnic,
1341 struct hwrm_vnic_qcfg_input req = {.req_type = 0 };
1342 struct hwrm_vnic_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
1344 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1345 PMD_DRV_LOG(DEBUG, "VNIC QCFG ID %d\n", vnic->fw_vnic_id);
1348 HWRM_PREP(req, VNIC_QCFG);
1351 rte_cpu_to_le_32(HWRM_VNIC_QCFG_INPUT_ENABLES_VF_ID_VALID);
1352 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1353 req.vf_id = rte_cpu_to_le_16(fw_vf_id);
1355 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1357 HWRM_CHECK_RESULT();
1359 vnic->dflt_ring_grp = rte_le_to_cpu_16(resp->dflt_ring_grp);
1360 vnic->rss_rule = rte_le_to_cpu_16(resp->rss_rule);
1361 vnic->cos_rule = rte_le_to_cpu_16(resp->cos_rule);
1362 vnic->lb_rule = rte_le_to_cpu_16(resp->lb_rule);
1363 vnic->mru = rte_le_to_cpu_16(resp->mru);
1364 vnic->func_default = rte_le_to_cpu_32(
1365 resp->flags) & HWRM_VNIC_QCFG_OUTPUT_FLAGS_DEFAULT;
1366 vnic->vlan_strip = rte_le_to_cpu_32(resp->flags) &
1367 HWRM_VNIC_QCFG_OUTPUT_FLAGS_VLAN_STRIP_MODE;
1368 vnic->bd_stall = rte_le_to_cpu_32(resp->flags) &
1369 HWRM_VNIC_QCFG_OUTPUT_FLAGS_BD_STALL_MODE;
1370 vnic->roce_dual = rte_le_to_cpu_32(resp->flags) &
1371 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_DUAL_VNIC_MODE;
1372 vnic->roce_only = rte_le_to_cpu_32(resp->flags) &
1373 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_ONLY_VNIC_MODE;
1374 vnic->rss_dflt_cr = rte_le_to_cpu_32(resp->flags) &
1375 HWRM_VNIC_QCFG_OUTPUT_FLAGS_RSS_DFLT_CR_MODE;
1382 int bnxt_hwrm_vnic_ctx_alloc(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1385 struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req = {.req_type = 0 };
1386 struct hwrm_vnic_rss_cos_lb_ctx_alloc_output *resp =
1387 bp->hwrm_cmd_resp_addr;
1389 HWRM_PREP(req, VNIC_RSS_COS_LB_CTX_ALLOC);
1391 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1393 HWRM_CHECK_RESULT();
1395 vnic->rss_rule = rte_le_to_cpu_16(resp->rss_cos_lb_ctx_id);
1397 PMD_DRV_LOG(DEBUG, "VNIC RSS Rule %x\n", vnic->rss_rule);
1402 int bnxt_hwrm_vnic_ctx_free(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1405 struct hwrm_vnic_rss_cos_lb_ctx_free_input req = {.req_type = 0 };
1406 struct hwrm_vnic_rss_cos_lb_ctx_free_output *resp =
1407 bp->hwrm_cmd_resp_addr;
1409 if (vnic->rss_rule == 0xffff) {
1410 PMD_DRV_LOG(DEBUG, "VNIC RSS Rule %x\n", vnic->rss_rule);
1413 HWRM_PREP(req, VNIC_RSS_COS_LB_CTX_FREE);
1415 req.rss_cos_lb_ctx_id = rte_cpu_to_le_16(vnic->rss_rule);
1417 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1419 HWRM_CHECK_RESULT();
1422 vnic->rss_rule = INVALID_HW_RING_ID;
1427 int bnxt_hwrm_vnic_free(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1430 struct hwrm_vnic_free_input req = {.req_type = 0 };
1431 struct hwrm_vnic_free_output *resp = bp->hwrm_cmd_resp_addr;
1433 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1434 PMD_DRV_LOG(DEBUG, "VNIC FREE ID %x\n", vnic->fw_vnic_id);
1438 HWRM_PREP(req, VNIC_FREE);
1440 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1442 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1444 HWRM_CHECK_RESULT();
1447 vnic->fw_vnic_id = INVALID_HW_RING_ID;
1451 int bnxt_hwrm_vnic_rss_cfg(struct bnxt *bp,
1452 struct bnxt_vnic_info *vnic)
1455 struct hwrm_vnic_rss_cfg_input req = {.req_type = 0 };
1456 struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1458 HWRM_PREP(req, VNIC_RSS_CFG);
1460 req.hash_type = rte_cpu_to_le_32(vnic->hash_type);
1462 req.ring_grp_tbl_addr =
1463 rte_cpu_to_le_64(vnic->rss_table_dma_addr);
1464 req.hash_key_tbl_addr =
1465 rte_cpu_to_le_64(vnic->rss_hash_key_dma_addr);
1466 req.rss_ctx_idx = rte_cpu_to_le_16(vnic->rss_rule);
1468 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1470 HWRM_CHECK_RESULT();
1476 int bnxt_hwrm_vnic_plcmode_cfg(struct bnxt *bp,
1477 struct bnxt_vnic_info *vnic)
1480 struct hwrm_vnic_plcmodes_cfg_input req = {.req_type = 0 };
1481 struct hwrm_vnic_plcmodes_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1484 HWRM_PREP(req, VNIC_PLCMODES_CFG);
1486 req.flags = rte_cpu_to_le_32(
1487 HWRM_VNIC_PLCMODES_CFG_INPUT_FLAGS_JUMBO_PLACEMENT);
1489 req.enables = rte_cpu_to_le_32(
1490 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_JUMBO_THRESH_VALID);
1492 size = rte_pktmbuf_data_room_size(bp->rx_queues[0]->mb_pool);
1493 size -= RTE_PKTMBUF_HEADROOM;
1495 req.jumbo_thresh = rte_cpu_to_le_16(size);
1496 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1498 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1500 HWRM_CHECK_RESULT();
1506 int bnxt_hwrm_vnic_tpa_cfg(struct bnxt *bp,
1507 struct bnxt_vnic_info *vnic, bool enable)
1510 struct hwrm_vnic_tpa_cfg_input req = {.req_type = 0 };
1511 struct hwrm_vnic_tpa_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1513 HWRM_PREP(req, VNIC_TPA_CFG);
1516 req.enables = rte_cpu_to_le_32(
1517 HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MAX_AGG_SEGS |
1518 HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MAX_AGGS |
1519 HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MIN_AGG_LEN);
1520 req.flags = rte_cpu_to_le_32(
1521 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_TPA |
1522 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_ENCAP_TPA |
1523 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_RSC_WND_UPDATE |
1524 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_GRO |
1525 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_AGG_WITH_ECN |
1526 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_AGG_WITH_SAME_GRE_SEQ);
1527 req.max_agg_segs = rte_cpu_to_le_16(5);
1529 rte_cpu_to_le_16(HWRM_VNIC_TPA_CFG_INPUT_MAX_AGGS_MAX);
1530 req.min_agg_len = rte_cpu_to_le_32(512);
1532 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1534 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1536 HWRM_CHECK_RESULT();
1542 int bnxt_hwrm_func_vf_mac(struct bnxt *bp, uint16_t vf, const uint8_t *mac_addr)
1544 struct hwrm_func_cfg_input req = {0};
1545 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1548 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[vf].func_cfg_flags);
1549 req.enables = rte_cpu_to_le_32(
1550 HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
1551 memcpy(req.dflt_mac_addr, mac_addr, sizeof(req.dflt_mac_addr));
1552 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
1554 HWRM_PREP(req, FUNC_CFG);
1556 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1557 HWRM_CHECK_RESULT();
1560 bp->pf.vf_info[vf].random_mac = false;
1565 int bnxt_hwrm_func_qstats_tx_drop(struct bnxt *bp, uint16_t fid,
1569 struct hwrm_func_qstats_input req = {.req_type = 0};
1570 struct hwrm_func_qstats_output *resp = bp->hwrm_cmd_resp_addr;
1572 HWRM_PREP(req, FUNC_QSTATS);
1574 req.fid = rte_cpu_to_le_16(fid);
1576 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1578 HWRM_CHECK_RESULT();
1581 *dropped = rte_le_to_cpu_64(resp->tx_drop_pkts);
1588 int bnxt_hwrm_func_qstats(struct bnxt *bp, uint16_t fid,
1589 struct rte_eth_stats *stats)
1592 struct hwrm_func_qstats_input req = {.req_type = 0};
1593 struct hwrm_func_qstats_output *resp = bp->hwrm_cmd_resp_addr;
1595 HWRM_PREP(req, FUNC_QSTATS);
1597 req.fid = rte_cpu_to_le_16(fid);
1599 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1601 HWRM_CHECK_RESULT();
1603 stats->ipackets = rte_le_to_cpu_64(resp->rx_ucast_pkts);
1604 stats->ipackets += rte_le_to_cpu_64(resp->rx_mcast_pkts);
1605 stats->ipackets += rte_le_to_cpu_64(resp->rx_bcast_pkts);
1606 stats->ibytes = rte_le_to_cpu_64(resp->rx_ucast_bytes);
1607 stats->ibytes += rte_le_to_cpu_64(resp->rx_mcast_bytes);
1608 stats->ibytes += rte_le_to_cpu_64(resp->rx_bcast_bytes);
1610 stats->opackets = rte_le_to_cpu_64(resp->tx_ucast_pkts);
1611 stats->opackets += rte_le_to_cpu_64(resp->tx_mcast_pkts);
1612 stats->opackets += rte_le_to_cpu_64(resp->tx_bcast_pkts);
1613 stats->obytes = rte_le_to_cpu_64(resp->tx_ucast_bytes);
1614 stats->obytes += rte_le_to_cpu_64(resp->tx_mcast_bytes);
1615 stats->obytes += rte_le_to_cpu_64(resp->tx_bcast_bytes);
1617 stats->ierrors = rte_le_to_cpu_64(resp->rx_err_pkts);
1618 stats->oerrors = rte_le_to_cpu_64(resp->tx_err_pkts);
1620 stats->imissed = rte_le_to_cpu_64(resp->rx_drop_pkts);
1627 int bnxt_hwrm_func_clr_stats(struct bnxt *bp, uint16_t fid)
1630 struct hwrm_func_clr_stats_input req = {.req_type = 0};
1631 struct hwrm_func_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
1633 HWRM_PREP(req, FUNC_CLR_STATS);
1635 req.fid = rte_cpu_to_le_16(fid);
1637 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1639 HWRM_CHECK_RESULT();
1646 * HWRM utility functions
1649 int bnxt_clear_all_hwrm_stat_ctxs(struct bnxt *bp)
1654 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
1655 struct bnxt_tx_queue *txq;
1656 struct bnxt_rx_queue *rxq;
1657 struct bnxt_cp_ring_info *cpr;
1659 if (i >= bp->rx_cp_nr_rings) {
1660 txq = bp->tx_queues[i - bp->rx_cp_nr_rings];
1663 rxq = bp->rx_queues[i];
1667 rc = bnxt_hwrm_stat_clear(bp, cpr);
1674 int bnxt_free_all_hwrm_stat_ctxs(struct bnxt *bp)
1678 struct bnxt_cp_ring_info *cpr;
1680 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
1682 if (i >= bp->rx_cp_nr_rings) {
1683 cpr = bp->tx_queues[i - bp->rx_cp_nr_rings]->cp_ring;
1685 cpr = bp->rx_queues[i]->cp_ring;
1686 bp->grp_info[i].fw_stats_ctx = -1;
1688 if (cpr->hw_stats_ctx_id != HWRM_NA_SIGNATURE) {
1689 rc = bnxt_hwrm_stat_ctx_free(bp, cpr, i);
1690 cpr->hw_stats_ctx_id = HWRM_NA_SIGNATURE;
1698 int bnxt_alloc_all_hwrm_stat_ctxs(struct bnxt *bp)
1703 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
1704 struct bnxt_tx_queue *txq;
1705 struct bnxt_rx_queue *rxq;
1706 struct bnxt_cp_ring_info *cpr;
1708 if (i >= bp->rx_cp_nr_rings) {
1709 txq = bp->tx_queues[i - bp->rx_cp_nr_rings];
1712 rxq = bp->rx_queues[i];
1716 rc = bnxt_hwrm_stat_ctx_alloc(bp, cpr, i);
1724 int bnxt_free_all_hwrm_ring_grps(struct bnxt *bp)
1729 for (idx = 0; idx < bp->rx_cp_nr_rings; idx++) {
1731 if (bp->grp_info[idx].fw_grp_id == INVALID_HW_RING_ID)
1734 rc = bnxt_hwrm_ring_grp_free(bp, idx);
1742 static void bnxt_free_cp_ring(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
1743 unsigned int idx __rte_unused)
1745 struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
1747 bnxt_hwrm_ring_free(bp, cp_ring,
1748 HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL);
1749 cp_ring->fw_ring_id = INVALID_HW_RING_ID;
1750 memset(cpr->cp_desc_ring, 0, cpr->cp_ring_struct->ring_size *
1751 sizeof(*cpr->cp_desc_ring));
1752 cpr->cp_raw_cons = 0;
1755 int bnxt_free_all_hwrm_rings(struct bnxt *bp)
1760 for (i = 0; i < bp->tx_cp_nr_rings; i++) {
1761 struct bnxt_tx_queue *txq = bp->tx_queues[i];
1762 struct bnxt_tx_ring_info *txr = txq->tx_ring;
1763 struct bnxt_ring *ring = txr->tx_ring_struct;
1764 struct bnxt_cp_ring_info *cpr = txq->cp_ring;
1765 unsigned int idx = bp->rx_cp_nr_rings + i + 1;
1767 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
1768 bnxt_hwrm_ring_free(bp, ring,
1769 HWRM_RING_FREE_INPUT_RING_TYPE_TX);
1770 ring->fw_ring_id = INVALID_HW_RING_ID;
1771 memset(txr->tx_desc_ring, 0,
1772 txr->tx_ring_struct->ring_size *
1773 sizeof(*txr->tx_desc_ring));
1774 memset(txr->tx_buf_ring, 0,
1775 txr->tx_ring_struct->ring_size *
1776 sizeof(*txr->tx_buf_ring));
1780 if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID) {
1781 bnxt_free_cp_ring(bp, cpr, idx);
1782 cpr->cp_ring_struct->fw_ring_id = INVALID_HW_RING_ID;
1786 for (i = 0; i < bp->rx_cp_nr_rings; i++) {
1787 struct bnxt_rx_queue *rxq = bp->rx_queues[i];
1788 struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
1789 struct bnxt_ring *ring = rxr->rx_ring_struct;
1790 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
1791 unsigned int idx = i + 1;
1793 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
1794 bnxt_hwrm_ring_free(bp, ring,
1795 HWRM_RING_FREE_INPUT_RING_TYPE_RX);
1796 ring->fw_ring_id = INVALID_HW_RING_ID;
1797 bp->grp_info[idx].rx_fw_ring_id = INVALID_HW_RING_ID;
1798 memset(rxr->rx_desc_ring, 0,
1799 rxr->rx_ring_struct->ring_size *
1800 sizeof(*rxr->rx_desc_ring));
1801 memset(rxr->rx_buf_ring, 0,
1802 rxr->rx_ring_struct->ring_size *
1803 sizeof(*rxr->rx_buf_ring));
1806 ring = rxr->ag_ring_struct;
1807 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
1808 bnxt_hwrm_ring_free(bp, ring,
1809 HWRM_RING_FREE_INPUT_RING_TYPE_RX);
1810 ring->fw_ring_id = INVALID_HW_RING_ID;
1811 memset(rxr->ag_buf_ring, 0,
1812 rxr->ag_ring_struct->ring_size *
1813 sizeof(*rxr->ag_buf_ring));
1815 bp->grp_info[i].ag_fw_ring_id = INVALID_HW_RING_ID;
1817 if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID) {
1818 bnxt_free_cp_ring(bp, cpr, idx);
1819 bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID;
1820 cpr->cp_ring_struct->fw_ring_id = INVALID_HW_RING_ID;
1824 /* Default completion ring */
1826 struct bnxt_cp_ring_info *cpr = bp->def_cp_ring;
1828 if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID) {
1829 bnxt_free_cp_ring(bp, cpr, 0);
1830 cpr->cp_ring_struct->fw_ring_id = INVALID_HW_RING_ID;
1837 int bnxt_alloc_all_hwrm_ring_grps(struct bnxt *bp)
1842 for (i = 0; i < bp->rx_cp_nr_rings; i++) {
1843 rc = bnxt_hwrm_ring_grp_alloc(bp, i);
1850 void bnxt_free_hwrm_resources(struct bnxt *bp)
1852 /* Release memzone */
1853 rte_free(bp->hwrm_cmd_resp_addr);
1854 rte_free(bp->hwrm_short_cmd_req_addr);
1855 bp->hwrm_cmd_resp_addr = NULL;
1856 bp->hwrm_short_cmd_req_addr = NULL;
1857 bp->hwrm_cmd_resp_dma_addr = 0;
1858 bp->hwrm_short_cmd_req_dma_addr = 0;
1861 int bnxt_alloc_hwrm_resources(struct bnxt *bp)
1863 struct rte_pci_device *pdev = bp->pdev;
1864 char type[RTE_MEMZONE_NAMESIZE];
1866 sprintf(type, "bnxt_hwrm_%04x:%02x:%02x:%02x", pdev->addr.domain,
1867 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
1868 bp->max_resp_len = HWRM_MAX_RESP_LEN;
1869 bp->hwrm_cmd_resp_addr = rte_malloc(type, bp->max_resp_len, 0);
1870 rte_mem_lock_page(bp->hwrm_cmd_resp_addr);
1871 if (bp->hwrm_cmd_resp_addr == NULL)
1873 bp->hwrm_cmd_resp_dma_addr =
1874 rte_mem_virt2iova(bp->hwrm_cmd_resp_addr);
1875 if (bp->hwrm_cmd_resp_dma_addr == 0) {
1877 "unable to map response address to physical memory\n");
1880 rte_spinlock_init(&bp->hwrm_lock);
1885 int bnxt_clear_hwrm_vnic_filters(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1887 struct bnxt_filter_info *filter;
1890 STAILQ_FOREACH(filter, &vnic->filter, next) {
1891 if (filter->filter_type == HWRM_CFA_EM_FILTER)
1892 rc = bnxt_hwrm_clear_em_filter(bp, filter);
1893 else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
1894 rc = bnxt_hwrm_clear_ntuple_filter(bp, filter);
1896 rc = bnxt_hwrm_clear_l2_filter(bp, filter);
1904 bnxt_clear_hwrm_vnic_flows(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1906 struct bnxt_filter_info *filter;
1907 struct rte_flow *flow;
1910 STAILQ_FOREACH(flow, &vnic->flow_list, next) {
1911 filter = flow->filter;
1912 PMD_DRV_LOG(ERR, "filter type %d\n", filter->filter_type);
1913 if (filter->filter_type == HWRM_CFA_EM_FILTER)
1914 rc = bnxt_hwrm_clear_em_filter(bp, filter);
1915 else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
1916 rc = bnxt_hwrm_clear_ntuple_filter(bp, filter);
1918 rc = bnxt_hwrm_clear_l2_filter(bp, filter);
1920 STAILQ_REMOVE(&vnic->flow_list, flow, rte_flow, next);
1928 int bnxt_set_hwrm_vnic_filters(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1930 struct bnxt_filter_info *filter;
1933 STAILQ_FOREACH(filter, &vnic->filter, next) {
1934 if (filter->filter_type == HWRM_CFA_EM_FILTER)
1935 rc = bnxt_hwrm_set_em_filter(bp, filter->dst_id,
1937 else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
1938 rc = bnxt_hwrm_set_ntuple_filter(bp, filter->dst_id,
1941 rc = bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id,
1949 void bnxt_free_tunnel_ports(struct bnxt *bp)
1951 if (bp->vxlan_port_cnt)
1952 bnxt_hwrm_tunnel_dst_port_free(bp, bp->vxlan_fw_dst_port_id,
1953 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_VXLAN);
1955 if (bp->geneve_port_cnt)
1956 bnxt_hwrm_tunnel_dst_port_free(bp, bp->geneve_fw_dst_port_id,
1957 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_GENEVE);
1958 bp->geneve_port = 0;
1961 void bnxt_free_all_hwrm_resources(struct bnxt *bp)
1965 if (bp->vnic_info == NULL)
1969 * Cleanup VNICs in reverse order, to make sure the L2 filter
1970 * from vnic0 is last to be cleaned up.
1972 for (i = bp->nr_vnics - 1; i >= 0; i--) {
1973 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
1975 bnxt_clear_hwrm_vnic_flows(bp, vnic);
1977 bnxt_clear_hwrm_vnic_filters(bp, vnic);
1979 bnxt_hwrm_vnic_ctx_free(bp, vnic);
1981 bnxt_hwrm_vnic_tpa_cfg(bp, vnic, false);
1983 bnxt_hwrm_vnic_free(bp, vnic);
1985 /* Ring resources */
1986 bnxt_free_all_hwrm_rings(bp);
1987 bnxt_free_all_hwrm_ring_grps(bp);
1988 bnxt_free_all_hwrm_stat_ctxs(bp);
1989 bnxt_free_tunnel_ports(bp);
1992 static uint16_t bnxt_parse_eth_link_duplex(uint32_t conf_link_speed)
1994 uint8_t hw_link_duplex = HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH;
1996 if ((conf_link_speed & ETH_LINK_SPEED_FIXED) == ETH_LINK_SPEED_AUTONEG)
1997 return HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH;
1999 switch (conf_link_speed) {
2000 case ETH_LINK_SPEED_10M_HD:
2001 case ETH_LINK_SPEED_100M_HD:
2002 return HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_HALF;
2004 return hw_link_duplex;
2007 static uint16_t bnxt_check_eth_link_autoneg(uint32_t conf_link)
2009 return (conf_link & ETH_LINK_SPEED_FIXED) ? 0 : 1;
2012 static uint16_t bnxt_parse_eth_link_speed(uint32_t conf_link_speed)
2014 uint16_t eth_link_speed = 0;
2016 if (conf_link_speed == ETH_LINK_SPEED_AUTONEG)
2017 return ETH_LINK_SPEED_AUTONEG;
2019 switch (conf_link_speed & ~ETH_LINK_SPEED_FIXED) {
2020 case ETH_LINK_SPEED_100M:
2021 case ETH_LINK_SPEED_100M_HD:
2023 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_100MB;
2025 case ETH_LINK_SPEED_1G:
2027 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_1GB;
2029 case ETH_LINK_SPEED_2_5G:
2031 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_2_5GB;
2033 case ETH_LINK_SPEED_10G:
2035 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_10GB;
2037 case ETH_LINK_SPEED_20G:
2039 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_20GB;
2041 case ETH_LINK_SPEED_25G:
2043 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_25GB;
2045 case ETH_LINK_SPEED_40G:
2047 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_40GB;
2049 case ETH_LINK_SPEED_50G:
2051 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_50GB;
2053 case ETH_LINK_SPEED_100G:
2055 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_100GB;
2059 "Unsupported link speed %d; default to AUTO\n",
2063 return eth_link_speed;
2066 #define BNXT_SUPPORTED_SPEEDS (ETH_LINK_SPEED_100M | ETH_LINK_SPEED_100M_HD | \
2067 ETH_LINK_SPEED_1G | ETH_LINK_SPEED_2_5G | \
2068 ETH_LINK_SPEED_10G | ETH_LINK_SPEED_20G | ETH_LINK_SPEED_25G | \
2069 ETH_LINK_SPEED_40G | ETH_LINK_SPEED_50G | ETH_LINK_SPEED_100G)
2071 static int bnxt_valid_link_speed(uint32_t link_speed, uint16_t port_id)
2075 if (link_speed == ETH_LINK_SPEED_AUTONEG)
2078 if (link_speed & ETH_LINK_SPEED_FIXED) {
2079 one_speed = link_speed & ~ETH_LINK_SPEED_FIXED;
2081 if (one_speed & (one_speed - 1)) {
2083 "Invalid advertised speeds (%u) for port %u\n",
2084 link_speed, port_id);
2087 if ((one_speed & BNXT_SUPPORTED_SPEEDS) != one_speed) {
2089 "Unsupported advertised speed (%u) for port %u\n",
2090 link_speed, port_id);
2094 if (!(link_speed & BNXT_SUPPORTED_SPEEDS)) {
2096 "Unsupported advertised speeds (%u) for port %u\n",
2097 link_speed, port_id);
2105 bnxt_parse_eth_link_speed_mask(struct bnxt *bp, uint32_t link_speed)
2109 if (link_speed == ETH_LINK_SPEED_AUTONEG) {
2110 if (bp->link_info.support_speeds)
2111 return bp->link_info.support_speeds;
2112 link_speed = BNXT_SUPPORTED_SPEEDS;
2115 if (link_speed & ETH_LINK_SPEED_100M)
2116 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100MB;
2117 if (link_speed & ETH_LINK_SPEED_100M_HD)
2118 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100MB;
2119 if (link_speed & ETH_LINK_SPEED_1G)
2120 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_1GB;
2121 if (link_speed & ETH_LINK_SPEED_2_5G)
2122 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_2_5GB;
2123 if (link_speed & ETH_LINK_SPEED_10G)
2124 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_10GB;
2125 if (link_speed & ETH_LINK_SPEED_20G)
2126 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_20GB;
2127 if (link_speed & ETH_LINK_SPEED_25G)
2128 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_25GB;
2129 if (link_speed & ETH_LINK_SPEED_40G)
2130 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_40GB;
2131 if (link_speed & ETH_LINK_SPEED_50G)
2132 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_50GB;
2133 if (link_speed & ETH_LINK_SPEED_100G)
2134 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100GB;
2138 static uint32_t bnxt_parse_hw_link_speed(uint16_t hw_link_speed)
2140 uint32_t eth_link_speed = ETH_SPEED_NUM_NONE;
2142 switch (hw_link_speed) {
2143 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100MB:
2144 eth_link_speed = ETH_SPEED_NUM_100M;
2146 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_1GB:
2147 eth_link_speed = ETH_SPEED_NUM_1G;
2149 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2_5GB:
2150 eth_link_speed = ETH_SPEED_NUM_2_5G;
2152 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_10GB:
2153 eth_link_speed = ETH_SPEED_NUM_10G;
2155 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_20GB:
2156 eth_link_speed = ETH_SPEED_NUM_20G;
2158 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_25GB:
2159 eth_link_speed = ETH_SPEED_NUM_25G;
2161 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_40GB:
2162 eth_link_speed = ETH_SPEED_NUM_40G;
2164 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_50GB:
2165 eth_link_speed = ETH_SPEED_NUM_50G;
2167 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100GB:
2168 eth_link_speed = ETH_SPEED_NUM_100G;
2170 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2GB:
2172 PMD_DRV_LOG(ERR, "HWRM link speed %d not defined\n",
2176 return eth_link_speed;
2179 static uint16_t bnxt_parse_hw_link_duplex(uint16_t hw_link_duplex)
2181 uint16_t eth_link_duplex = ETH_LINK_FULL_DUPLEX;
2183 switch (hw_link_duplex) {
2184 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH:
2185 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_FULL:
2186 eth_link_duplex = ETH_LINK_FULL_DUPLEX;
2188 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_HALF:
2189 eth_link_duplex = ETH_LINK_HALF_DUPLEX;
2192 PMD_DRV_LOG(ERR, "HWRM link duplex %d not defined\n",
2196 return eth_link_duplex;
2199 int bnxt_get_hwrm_link_config(struct bnxt *bp, struct rte_eth_link *link)
2202 struct bnxt_link_info *link_info = &bp->link_info;
2204 rc = bnxt_hwrm_port_phy_qcfg(bp, link_info);
2207 "Get link config failed with rc %d\n", rc);
2210 if (link_info->link_speed)
2212 bnxt_parse_hw_link_speed(link_info->link_speed);
2214 link->link_speed = ETH_SPEED_NUM_NONE;
2215 link->link_duplex = bnxt_parse_hw_link_duplex(link_info->duplex);
2216 link->link_status = link_info->link_up;
2217 link->link_autoneg = link_info->auto_mode ==
2218 HWRM_PORT_PHY_QCFG_OUTPUT_AUTO_MODE_NONE ?
2219 ETH_LINK_FIXED : ETH_LINK_AUTONEG;
2224 int bnxt_set_hwrm_link_config(struct bnxt *bp, bool link_up)
2227 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
2228 struct bnxt_link_info link_req;
2229 uint16_t speed, autoneg;
2231 if (!BNXT_SINGLE_PF(bp) || BNXT_VF(bp))
2234 rc = bnxt_valid_link_speed(dev_conf->link_speeds,
2235 bp->eth_dev->data->port_id);
2239 memset(&link_req, 0, sizeof(link_req));
2240 link_req.link_up = link_up;
2244 autoneg = bnxt_check_eth_link_autoneg(dev_conf->link_speeds);
2245 speed = bnxt_parse_eth_link_speed(dev_conf->link_speeds);
2246 link_req.phy_flags = HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESET_PHY;
2247 /* Autoneg can be done only when the FW allows */
2248 if (autoneg == 1 && !(bp->link_info.auto_link_speed ||
2249 bp->link_info.force_link_speed)) {
2250 link_req.phy_flags |=
2251 HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESTART_AUTONEG;
2252 link_req.auto_link_speed_mask =
2253 bnxt_parse_eth_link_speed_mask(bp,
2254 dev_conf->link_speeds);
2256 if (bp->link_info.phy_type ==
2257 HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET ||
2258 bp->link_info.phy_type ==
2259 HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASETE ||
2260 bp->link_info.media_type ==
2261 HWRM_PORT_PHY_QCFG_OUTPUT_MEDIA_TYPE_TP) {
2262 PMD_DRV_LOG(ERR, "10GBase-T devices must autoneg\n");
2266 link_req.phy_flags |= HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE;
2267 /* If user wants a particular speed try that first. */
2269 link_req.link_speed = speed;
2270 else if (bp->link_info.force_link_speed)
2271 link_req.link_speed = bp->link_info.force_link_speed;
2273 link_req.link_speed = bp->link_info.auto_link_speed;
2275 link_req.duplex = bnxt_parse_eth_link_duplex(dev_conf->link_speeds);
2276 link_req.auto_pause = bp->link_info.auto_pause;
2277 link_req.force_pause = bp->link_info.force_pause;
2280 rc = bnxt_hwrm_port_phy_cfg(bp, &link_req);
2283 "Set link config failed with rc %d\n", rc);
2291 int bnxt_hwrm_func_qcfg(struct bnxt *bp)
2293 struct hwrm_func_qcfg_input req = {0};
2294 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
2298 HWRM_PREP(req, FUNC_QCFG);
2299 req.fid = rte_cpu_to_le_16(0xffff);
2301 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2303 HWRM_CHECK_RESULT();
2305 /* Hard Coded.. 0xfff VLAN ID mask */
2306 bp->vlan = rte_le_to_cpu_16(resp->vlan) & 0xfff;
2307 flags = rte_le_to_cpu_16(resp->flags);
2308 if (BNXT_PF(bp) && (flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_MULTI_HOST))
2309 bp->flags |= BNXT_FLAG_MULTI_HOST;
2311 switch (resp->port_partition_type) {
2312 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR1_0:
2313 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR1_5:
2314 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR2_0:
2315 bp->port_partition_type = resp->port_partition_type;
2318 bp->port_partition_type = 0;
2327 static void copy_func_cfg_to_qcaps(struct hwrm_func_cfg_input *fcfg,
2328 struct hwrm_func_qcaps_output *qcaps)
2330 qcaps->max_rsscos_ctx = fcfg->num_rsscos_ctxs;
2331 memcpy(qcaps->mac_address, fcfg->dflt_mac_addr,
2332 sizeof(qcaps->mac_address));
2333 qcaps->max_l2_ctxs = fcfg->num_l2_ctxs;
2334 qcaps->max_rx_rings = fcfg->num_rx_rings;
2335 qcaps->max_tx_rings = fcfg->num_tx_rings;
2336 qcaps->max_cmpl_rings = fcfg->num_cmpl_rings;
2337 qcaps->max_stat_ctx = fcfg->num_stat_ctxs;
2339 qcaps->first_vf_id = 0;
2340 qcaps->max_vnics = fcfg->num_vnics;
2341 qcaps->max_decap_records = 0;
2342 qcaps->max_encap_records = 0;
2343 qcaps->max_tx_wm_flows = 0;
2344 qcaps->max_tx_em_flows = 0;
2345 qcaps->max_rx_wm_flows = 0;
2346 qcaps->max_rx_em_flows = 0;
2347 qcaps->max_flow_id = 0;
2348 qcaps->max_mcast_filters = fcfg->num_mcast_filters;
2349 qcaps->max_sp_tx_rings = 0;
2350 qcaps->max_hw_ring_grps = fcfg->num_hw_ring_grps;
2353 static int bnxt_hwrm_pf_func_cfg(struct bnxt *bp, int tx_rings)
2355 struct hwrm_func_cfg_input req = {0};
2356 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2359 req.enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_MTU |
2360 HWRM_FUNC_CFG_INPUT_ENABLES_MRU |
2361 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS |
2362 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
2363 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
2364 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_TX_RINGS |
2365 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RX_RINGS |
2366 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_L2_CTXS |
2367 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_VNICS |
2368 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS);
2369 req.flags = rte_cpu_to_le_32(bp->pf.func_cfg_flags);
2370 req.mtu = rte_cpu_to_le_16(BNXT_MAX_MTU);
2371 req.mru = rte_cpu_to_le_16(bp->eth_dev->data->mtu + ETHER_HDR_LEN +
2372 ETHER_CRC_LEN + VLAN_TAG_SIZE *
2374 req.num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx);
2375 req.num_stat_ctxs = rte_cpu_to_le_16(bp->max_stat_ctx);
2376 req.num_cmpl_rings = rte_cpu_to_le_16(bp->max_cp_rings);
2377 req.num_tx_rings = rte_cpu_to_le_16(tx_rings);
2378 req.num_rx_rings = rte_cpu_to_le_16(bp->max_rx_rings);
2379 req.num_l2_ctxs = rte_cpu_to_le_16(bp->max_l2_ctx);
2380 req.num_vnics = rte_cpu_to_le_16(bp->max_vnics);
2381 req.num_hw_ring_grps = rte_cpu_to_le_16(bp->max_ring_grps);
2382 req.fid = rte_cpu_to_le_16(0xffff);
2384 HWRM_PREP(req, FUNC_CFG);
2386 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2388 HWRM_CHECK_RESULT();
2394 static void populate_vf_func_cfg_req(struct bnxt *bp,
2395 struct hwrm_func_cfg_input *req,
2398 req->enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_MTU |
2399 HWRM_FUNC_CFG_INPUT_ENABLES_MRU |
2400 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS |
2401 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
2402 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
2403 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_TX_RINGS |
2404 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RX_RINGS |
2405 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_L2_CTXS |
2406 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_VNICS |
2407 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS);
2409 req->mtu = rte_cpu_to_le_16(bp->eth_dev->data->mtu + ETHER_HDR_LEN +
2410 ETHER_CRC_LEN + VLAN_TAG_SIZE *
2412 req->mru = rte_cpu_to_le_16(bp->eth_dev->data->mtu + ETHER_HDR_LEN +
2413 ETHER_CRC_LEN + VLAN_TAG_SIZE *
2415 req->num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx /
2417 req->num_stat_ctxs = rte_cpu_to_le_16(bp->max_stat_ctx / (num_vfs + 1));
2418 req->num_cmpl_rings = rte_cpu_to_le_16(bp->max_cp_rings /
2420 req->num_tx_rings = rte_cpu_to_le_16(bp->max_tx_rings / (num_vfs + 1));
2421 req->num_rx_rings = rte_cpu_to_le_16(bp->max_rx_rings / (num_vfs + 1));
2422 req->num_l2_ctxs = rte_cpu_to_le_16(bp->max_l2_ctx / (num_vfs + 1));
2423 /* TODO: For now, do not support VMDq/RFS on VFs. */
2424 req->num_vnics = rte_cpu_to_le_16(1);
2425 req->num_hw_ring_grps = rte_cpu_to_le_16(bp->max_ring_grps /
2429 static void add_random_mac_if_needed(struct bnxt *bp,
2430 struct hwrm_func_cfg_input *cfg_req,
2433 struct ether_addr mac;
2435 if (bnxt_hwrm_func_qcfg_vf_default_mac(bp, vf, &mac))
2438 if (memcmp(mac.addr_bytes, "\x00\x00\x00\x00\x00", 6) == 0) {
2440 rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
2441 eth_random_addr(cfg_req->dflt_mac_addr);
2442 bp->pf.vf_info[vf].random_mac = true;
2444 memcpy(cfg_req->dflt_mac_addr, mac.addr_bytes, ETHER_ADDR_LEN);
2448 static void reserve_resources_from_vf(struct bnxt *bp,
2449 struct hwrm_func_cfg_input *cfg_req,
2452 struct hwrm_func_qcaps_input req = {0};
2453 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
2456 /* Get the actual allocated values now */
2457 HWRM_PREP(req, FUNC_QCAPS);
2458 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
2459 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2462 PMD_DRV_LOG(ERR, "hwrm_func_qcaps failed rc:%d\n", rc);
2463 copy_func_cfg_to_qcaps(cfg_req, resp);
2464 } else if (resp->error_code) {
2465 rc = rte_le_to_cpu_16(resp->error_code);
2466 PMD_DRV_LOG(ERR, "hwrm_func_qcaps error %d\n", rc);
2467 copy_func_cfg_to_qcaps(cfg_req, resp);
2470 bp->max_rsscos_ctx -= rte_le_to_cpu_16(resp->max_rsscos_ctx);
2471 bp->max_stat_ctx -= rte_le_to_cpu_16(resp->max_stat_ctx);
2472 bp->max_cp_rings -= rte_le_to_cpu_16(resp->max_cmpl_rings);
2473 bp->max_tx_rings -= rte_le_to_cpu_16(resp->max_tx_rings);
2474 bp->max_rx_rings -= rte_le_to_cpu_16(resp->max_rx_rings);
2475 bp->max_l2_ctx -= rte_le_to_cpu_16(resp->max_l2_ctxs);
2477 * TODO: While not supporting VMDq with VFs, max_vnics is always
2478 * forced to 1 in this case
2480 //bp->max_vnics -= rte_le_to_cpu_16(esp->max_vnics);
2481 bp->max_ring_grps -= rte_le_to_cpu_16(resp->max_hw_ring_grps);
2486 int bnxt_hwrm_func_qcfg_current_vf_vlan(struct bnxt *bp, int vf)
2488 struct hwrm_func_qcfg_input req = {0};
2489 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
2492 /* Check for zero MAC address */
2493 HWRM_PREP(req, FUNC_QCFG);
2494 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
2495 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2497 PMD_DRV_LOG(ERR, "hwrm_func_qcfg failed rc:%d\n", rc);
2499 } else if (resp->error_code) {
2500 rc = rte_le_to_cpu_16(resp->error_code);
2501 PMD_DRV_LOG(ERR, "hwrm_func_qcfg error %d\n", rc);
2504 rc = rte_le_to_cpu_16(resp->vlan);
2511 static int update_pf_resource_max(struct bnxt *bp)
2513 struct hwrm_func_qcfg_input req = {0};
2514 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
2517 /* And copy the allocated numbers into the pf struct */
2518 HWRM_PREP(req, FUNC_QCFG);
2519 req.fid = rte_cpu_to_le_16(0xffff);
2520 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2521 HWRM_CHECK_RESULT();
2523 /* Only TX ring value reflects actual allocation? TODO */
2524 bp->max_tx_rings = rte_le_to_cpu_16(resp->alloc_tx_rings);
2525 bp->pf.evb_mode = resp->evb_mode;
2532 int bnxt_hwrm_allocate_pf_only(struct bnxt *bp)
2537 PMD_DRV_LOG(ERR, "Attempt to allcoate VFs on a VF!\n");
2541 rc = bnxt_hwrm_func_qcaps(bp);
2545 bp->pf.func_cfg_flags &=
2546 ~(HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE |
2547 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE);
2548 bp->pf.func_cfg_flags |=
2549 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE;
2550 rc = bnxt_hwrm_pf_func_cfg(bp, bp->max_tx_rings);
2554 int bnxt_hwrm_allocate_vfs(struct bnxt *bp, int num_vfs)
2556 struct hwrm_func_cfg_input req = {0};
2557 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2564 PMD_DRV_LOG(ERR, "Attempt to allcoate VFs on a VF!\n");
2568 rc = bnxt_hwrm_func_qcaps(bp);
2573 bp->pf.active_vfs = num_vfs;
2576 * First, configure the PF to only use one TX ring. This ensures that
2577 * there are enough rings for all VFs.
2579 * If we don't do this, when we call func_alloc() later, we will lock
2580 * extra rings to the PF that won't be available during func_cfg() of
2583 * This has been fixed with firmware versions above 20.6.54
2585 bp->pf.func_cfg_flags &=
2586 ~(HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE |
2587 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE);
2588 bp->pf.func_cfg_flags |=
2589 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE;
2590 rc = bnxt_hwrm_pf_func_cfg(bp, 1);
2595 * Now, create and register a buffer to hold forwarded VF requests
2597 req_buf_sz = num_vfs * HWRM_MAX_REQ_LEN;
2598 bp->pf.vf_req_buf = rte_malloc("bnxt_vf_fwd", req_buf_sz,
2599 page_roundup(num_vfs * HWRM_MAX_REQ_LEN));
2600 if (bp->pf.vf_req_buf == NULL) {
2604 for (sz = 0; sz < req_buf_sz; sz += getpagesize())
2605 rte_mem_lock_page(((char *)bp->pf.vf_req_buf) + sz);
2606 for (i = 0; i < num_vfs; i++)
2607 bp->pf.vf_info[i].req_buf = ((char *)bp->pf.vf_req_buf) +
2608 (i * HWRM_MAX_REQ_LEN);
2610 rc = bnxt_hwrm_func_buf_rgtr(bp);
2614 populate_vf_func_cfg_req(bp, &req, num_vfs);
2616 bp->pf.active_vfs = 0;
2617 for (i = 0; i < num_vfs; i++) {
2618 add_random_mac_if_needed(bp, &req, i);
2620 HWRM_PREP(req, FUNC_CFG);
2621 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[i].func_cfg_flags);
2622 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[i].fid);
2623 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2625 /* Clear enable flag for next pass */
2626 req.enables &= ~rte_cpu_to_le_32(
2627 HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
2629 if (rc || resp->error_code) {
2631 "Failed to initizlie VF %d\n", i);
2633 "Not all VFs available. (%d, %d)\n",
2634 rc, resp->error_code);
2641 reserve_resources_from_vf(bp, &req, i);
2642 bp->pf.active_vfs++;
2643 bnxt_hwrm_func_clr_stats(bp, bp->pf.vf_info[i].fid);
2647 * Now configure the PF to use "the rest" of the resources
2648 * We're using STD_TX_RING_MODE here though which will limit the TX
2649 * rings. This will allow QoS to function properly. Not setting this
2650 * will cause PF rings to break bandwidth settings.
2652 rc = bnxt_hwrm_pf_func_cfg(bp, bp->max_tx_rings);
2656 rc = update_pf_resource_max(bp);
2663 bnxt_hwrm_func_buf_unrgtr(bp);
2667 int bnxt_hwrm_pf_evb_mode(struct bnxt *bp)
2669 struct hwrm_func_cfg_input req = {0};
2670 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2673 HWRM_PREP(req, FUNC_CFG);
2675 req.fid = rte_cpu_to_le_16(0xffff);
2676 req.enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_EVB_MODE);
2677 req.evb_mode = bp->pf.evb_mode;
2679 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2680 HWRM_CHECK_RESULT();
2686 int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt *bp, uint16_t port,
2687 uint8_t tunnel_type)
2689 struct hwrm_tunnel_dst_port_alloc_input req = {0};
2690 struct hwrm_tunnel_dst_port_alloc_output *resp = bp->hwrm_cmd_resp_addr;
2693 HWRM_PREP(req, TUNNEL_DST_PORT_ALLOC);
2694 req.tunnel_type = tunnel_type;
2695 req.tunnel_dst_port_val = port;
2696 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2697 HWRM_CHECK_RESULT();
2699 switch (tunnel_type) {
2700 case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_VXLAN:
2701 bp->vxlan_fw_dst_port_id = resp->tunnel_dst_port_id;
2702 bp->vxlan_port = port;
2704 case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_GENEVE:
2705 bp->geneve_fw_dst_port_id = resp->tunnel_dst_port_id;
2706 bp->geneve_port = port;
2717 int bnxt_hwrm_tunnel_dst_port_free(struct bnxt *bp, uint16_t port,
2718 uint8_t tunnel_type)
2720 struct hwrm_tunnel_dst_port_free_input req = {0};
2721 struct hwrm_tunnel_dst_port_free_output *resp = bp->hwrm_cmd_resp_addr;
2724 HWRM_PREP(req, TUNNEL_DST_PORT_FREE);
2726 req.tunnel_type = tunnel_type;
2727 req.tunnel_dst_port_id = rte_cpu_to_be_16(port);
2728 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2730 HWRM_CHECK_RESULT();
2736 int bnxt_hwrm_func_cfg_vf_set_flags(struct bnxt *bp, uint16_t vf,
2739 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2740 struct hwrm_func_cfg_input req = {0};
2743 HWRM_PREP(req, FUNC_CFG);
2745 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
2746 req.flags = rte_cpu_to_le_32(flags);
2747 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2749 HWRM_CHECK_RESULT();
2755 void vf_vnic_set_rxmask_cb(struct bnxt_vnic_info *vnic, void *flagp)
2757 uint32_t *flag = flagp;
2759 vnic->flags = *flag;
2762 int bnxt_set_rx_mask_no_vlan(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2764 return bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
2767 int bnxt_hwrm_func_buf_rgtr(struct bnxt *bp)
2770 struct hwrm_func_buf_rgtr_input req = {.req_type = 0 };
2771 struct hwrm_func_buf_rgtr_output *resp = bp->hwrm_cmd_resp_addr;
2773 HWRM_PREP(req, FUNC_BUF_RGTR);
2775 req.req_buf_num_pages = rte_cpu_to_le_16(1);
2776 req.req_buf_page_size = rte_cpu_to_le_16(
2777 page_getenum(bp->pf.active_vfs * HWRM_MAX_REQ_LEN));
2778 req.req_buf_len = rte_cpu_to_le_16(HWRM_MAX_REQ_LEN);
2779 req.req_buf_page_addr[0] =
2780 rte_cpu_to_le_64(rte_mem_virt2iova(bp->pf.vf_req_buf));
2781 if (req.req_buf_page_addr[0] == 0) {
2783 "unable to map buffer address to physical memory\n");
2787 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2789 HWRM_CHECK_RESULT();
2795 int bnxt_hwrm_func_buf_unrgtr(struct bnxt *bp)
2798 struct hwrm_func_buf_unrgtr_input req = {.req_type = 0 };
2799 struct hwrm_func_buf_unrgtr_output *resp = bp->hwrm_cmd_resp_addr;
2801 HWRM_PREP(req, FUNC_BUF_UNRGTR);
2803 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2805 HWRM_CHECK_RESULT();
2811 int bnxt_hwrm_func_cfg_def_cp(struct bnxt *bp)
2813 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2814 struct hwrm_func_cfg_input req = {0};
2817 HWRM_PREP(req, FUNC_CFG);
2819 req.fid = rte_cpu_to_le_16(0xffff);
2820 req.flags = rte_cpu_to_le_32(bp->pf.func_cfg_flags);
2821 req.enables = rte_cpu_to_le_32(
2822 HWRM_FUNC_CFG_INPUT_ENABLES_ASYNC_EVENT_CR);
2823 req.async_event_cr = rte_cpu_to_le_16(
2824 bp->def_cp_ring->cp_ring_struct->fw_ring_id);
2825 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2827 HWRM_CHECK_RESULT();
2833 int bnxt_hwrm_vf_func_cfg_def_cp(struct bnxt *bp)
2835 struct hwrm_func_vf_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2836 struct hwrm_func_vf_cfg_input req = {0};
2839 HWRM_PREP(req, FUNC_VF_CFG);
2841 req.enables = rte_cpu_to_le_32(
2842 HWRM_FUNC_CFG_INPUT_ENABLES_ASYNC_EVENT_CR);
2843 req.async_event_cr = rte_cpu_to_le_16(
2844 bp->def_cp_ring->cp_ring_struct->fw_ring_id);
2845 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2847 HWRM_CHECK_RESULT();
2853 int bnxt_hwrm_set_default_vlan(struct bnxt *bp, int vf, uint8_t is_vf)
2855 struct hwrm_func_cfg_input req = {0};
2856 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2857 uint16_t dflt_vlan, fid;
2858 uint32_t func_cfg_flags;
2861 HWRM_PREP(req, FUNC_CFG);
2864 dflt_vlan = bp->pf.vf_info[vf].dflt_vlan;
2865 fid = bp->pf.vf_info[vf].fid;
2866 func_cfg_flags = bp->pf.vf_info[vf].func_cfg_flags;
2868 fid = rte_cpu_to_le_16(0xffff);
2869 func_cfg_flags = bp->pf.func_cfg_flags;
2870 dflt_vlan = bp->vlan;
2873 req.flags = rte_cpu_to_le_32(func_cfg_flags);
2874 req.fid = rte_cpu_to_le_16(fid);
2875 req.enables |= rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_VLAN);
2876 req.dflt_vlan = rte_cpu_to_le_16(dflt_vlan);
2878 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2880 HWRM_CHECK_RESULT();
2886 int bnxt_hwrm_func_bw_cfg(struct bnxt *bp, uint16_t vf,
2887 uint16_t max_bw, uint16_t enables)
2889 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2890 struct hwrm_func_cfg_input req = {0};
2893 HWRM_PREP(req, FUNC_CFG);
2895 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
2896 req.enables |= rte_cpu_to_le_32(enables);
2897 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[vf].func_cfg_flags);
2898 req.max_bw = rte_cpu_to_le_32(max_bw);
2899 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2901 HWRM_CHECK_RESULT();
2907 int bnxt_hwrm_set_vf_vlan(struct bnxt *bp, int vf)
2909 struct hwrm_func_cfg_input req = {0};
2910 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2913 HWRM_PREP(req, FUNC_CFG);
2915 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[vf].func_cfg_flags);
2916 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
2917 req.enables |= rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_VLAN);
2918 req.dflt_vlan = rte_cpu_to_le_16(bp->pf.vf_info[vf].dflt_vlan);
2920 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2922 HWRM_CHECK_RESULT();
2928 int bnxt_hwrm_reject_fwd_resp(struct bnxt *bp, uint16_t target_id,
2929 void *encaped, size_t ec_size)
2932 struct hwrm_reject_fwd_resp_input req = {.req_type = 0};
2933 struct hwrm_reject_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr;
2935 if (ec_size > sizeof(req.encap_request))
2938 HWRM_PREP(req, REJECT_FWD_RESP);
2940 req.encap_resp_target_id = rte_cpu_to_le_16(target_id);
2941 memcpy(req.encap_request, encaped, ec_size);
2943 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2945 HWRM_CHECK_RESULT();
2951 int bnxt_hwrm_func_qcfg_vf_default_mac(struct bnxt *bp, uint16_t vf,
2952 struct ether_addr *mac)
2954 struct hwrm_func_qcfg_input req = {0};
2955 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
2958 HWRM_PREP(req, FUNC_QCFG);
2960 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
2961 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2963 HWRM_CHECK_RESULT();
2965 memcpy(mac->addr_bytes, resp->mac_address, ETHER_ADDR_LEN);
2972 int bnxt_hwrm_exec_fwd_resp(struct bnxt *bp, uint16_t target_id,
2973 void *encaped, size_t ec_size)
2976 struct hwrm_exec_fwd_resp_input req = {.req_type = 0};
2977 struct hwrm_exec_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr;
2979 if (ec_size > sizeof(req.encap_request))
2982 HWRM_PREP(req, EXEC_FWD_RESP);
2984 req.encap_resp_target_id = rte_cpu_to_le_16(target_id);
2985 memcpy(req.encap_request, encaped, ec_size);
2987 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2989 HWRM_CHECK_RESULT();
2995 int bnxt_hwrm_ctx_qstats(struct bnxt *bp, uint32_t cid, int idx,
2996 struct rte_eth_stats *stats, uint8_t rx)
2999 struct hwrm_stat_ctx_query_input req = {.req_type = 0};
3000 struct hwrm_stat_ctx_query_output *resp = bp->hwrm_cmd_resp_addr;
3002 HWRM_PREP(req, STAT_CTX_QUERY);
3004 req.stat_ctx_id = rte_cpu_to_le_32(cid);
3006 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3008 HWRM_CHECK_RESULT();
3011 stats->q_ipackets[idx] = rte_le_to_cpu_64(resp->rx_ucast_pkts);
3012 stats->q_ipackets[idx] += rte_le_to_cpu_64(resp->rx_mcast_pkts);
3013 stats->q_ipackets[idx] += rte_le_to_cpu_64(resp->rx_bcast_pkts);
3014 stats->q_ibytes[idx] = rte_le_to_cpu_64(resp->rx_ucast_bytes);
3015 stats->q_ibytes[idx] += rte_le_to_cpu_64(resp->rx_mcast_bytes);
3016 stats->q_ibytes[idx] += rte_le_to_cpu_64(resp->rx_bcast_bytes);
3017 stats->q_errors[idx] = rte_le_to_cpu_64(resp->rx_err_pkts);
3018 stats->q_errors[idx] += rte_le_to_cpu_64(resp->rx_drop_pkts);
3020 stats->q_opackets[idx] = rte_le_to_cpu_64(resp->tx_ucast_pkts);
3021 stats->q_opackets[idx] += rte_le_to_cpu_64(resp->tx_mcast_pkts);
3022 stats->q_opackets[idx] += rte_le_to_cpu_64(resp->tx_bcast_pkts);
3023 stats->q_obytes[idx] = rte_le_to_cpu_64(resp->tx_ucast_bytes);
3024 stats->q_obytes[idx] += rte_le_to_cpu_64(resp->tx_mcast_bytes);
3025 stats->q_obytes[idx] += rte_le_to_cpu_64(resp->tx_bcast_bytes);
3026 stats->q_errors[idx] += rte_le_to_cpu_64(resp->tx_err_pkts);
3035 int bnxt_hwrm_port_qstats(struct bnxt *bp)
3037 struct hwrm_port_qstats_input req = {0};
3038 struct hwrm_port_qstats_output *resp = bp->hwrm_cmd_resp_addr;
3039 struct bnxt_pf_info *pf = &bp->pf;
3042 if (!(bp->flags & BNXT_FLAG_PORT_STATS))
3045 HWRM_PREP(req, PORT_QSTATS);
3047 req.port_id = rte_cpu_to_le_16(pf->port_id);
3048 req.tx_stat_host_addr = rte_cpu_to_le_64(bp->hw_tx_port_stats_map);
3049 req.rx_stat_host_addr = rte_cpu_to_le_64(bp->hw_rx_port_stats_map);
3050 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3052 HWRM_CHECK_RESULT();
3058 int bnxt_hwrm_port_clr_stats(struct bnxt *bp)
3060 struct hwrm_port_clr_stats_input req = {0};
3061 struct hwrm_port_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
3062 struct bnxt_pf_info *pf = &bp->pf;
3065 if (!(bp->flags & BNXT_FLAG_PORT_STATS))
3068 HWRM_PREP(req, PORT_CLR_STATS);
3070 req.port_id = rte_cpu_to_le_16(pf->port_id);
3071 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3073 HWRM_CHECK_RESULT();
3079 int bnxt_hwrm_port_led_qcaps(struct bnxt *bp)
3081 struct hwrm_port_led_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
3082 struct hwrm_port_led_qcaps_input req = {0};
3088 HWRM_PREP(req, PORT_LED_QCAPS);
3089 req.port_id = bp->pf.port_id;
3090 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3092 HWRM_CHECK_RESULT();
3094 if (resp->num_leds > 0 && resp->num_leds < BNXT_MAX_LED) {
3097 bp->num_leds = resp->num_leds;
3098 memcpy(bp->leds, &resp->led0_id,
3099 sizeof(bp->leds[0]) * bp->num_leds);
3100 for (i = 0; i < bp->num_leds; i++) {
3101 struct bnxt_led_info *led = &bp->leds[i];
3103 uint16_t caps = led->led_state_caps;
3105 if (!led->led_group_id ||
3106 !BNXT_LED_ALT_BLINK_CAP(caps)) {
3118 int bnxt_hwrm_port_led_cfg(struct bnxt *bp, bool led_on)
3120 struct hwrm_port_led_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3121 struct hwrm_port_led_cfg_input req = {0};
3122 struct bnxt_led_cfg *led_cfg;
3123 uint8_t led_state = HWRM_PORT_LED_QCFG_OUTPUT_LED0_STATE_DEFAULT;
3124 uint16_t duration = 0;
3127 if (!bp->num_leds || BNXT_VF(bp))
3130 HWRM_PREP(req, PORT_LED_CFG);
3133 led_state = HWRM_PORT_LED_CFG_INPUT_LED0_STATE_BLINKALT;
3134 duration = rte_cpu_to_le_16(500);
3136 req.port_id = bp->pf.port_id;
3137 req.num_leds = bp->num_leds;
3138 led_cfg = (struct bnxt_led_cfg *)&req.led0_id;
3139 for (i = 0; i < bp->num_leds; i++, led_cfg++) {
3140 req.enables |= BNXT_LED_DFLT_ENABLES(i);
3141 led_cfg->led_id = bp->leds[i].led_id;
3142 led_cfg->led_state = led_state;
3143 led_cfg->led_blink_on = duration;
3144 led_cfg->led_blink_off = duration;
3145 led_cfg->led_group_id = bp->leds[i].led_group_id;
3148 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3150 HWRM_CHECK_RESULT();
3156 int bnxt_hwrm_nvm_get_dir_info(struct bnxt *bp, uint32_t *entries,
3160 struct hwrm_nvm_get_dir_info_input req = {0};
3161 struct hwrm_nvm_get_dir_info_output *resp = bp->hwrm_cmd_resp_addr;
3163 HWRM_PREP(req, NVM_GET_DIR_INFO);
3165 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3167 HWRM_CHECK_RESULT();
3171 *entries = rte_le_to_cpu_32(resp->entries);
3172 *length = rte_le_to_cpu_32(resp->entry_length);
3177 int bnxt_get_nvram_directory(struct bnxt *bp, uint32_t len, uint8_t *data)
3180 uint32_t dir_entries;
3181 uint32_t entry_length;
3184 rte_iova_t dma_handle;
3185 struct hwrm_nvm_get_dir_entries_input req = {0};
3186 struct hwrm_nvm_get_dir_entries_output *resp = bp->hwrm_cmd_resp_addr;
3188 rc = bnxt_hwrm_nvm_get_dir_info(bp, &dir_entries, &entry_length);
3192 *data++ = dir_entries;
3193 *data++ = entry_length;
3195 memset(data, 0xff, len);
3197 buflen = dir_entries * entry_length;
3198 buf = rte_malloc("nvm_dir", buflen, 0);
3199 rte_mem_lock_page(buf);
3202 dma_handle = rte_mem_virt2iova(buf);
3203 if (dma_handle == 0) {
3205 "unable to map response address to physical memory\n");
3208 HWRM_PREP(req, NVM_GET_DIR_ENTRIES);
3209 req.host_dest_addr = rte_cpu_to_le_64(dma_handle);
3210 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3212 HWRM_CHECK_RESULT();
3216 memcpy(data, buf, len > buflen ? buflen : len);
3223 int bnxt_hwrm_get_nvram_item(struct bnxt *bp, uint32_t index,
3224 uint32_t offset, uint32_t length,
3229 rte_iova_t dma_handle;
3230 struct hwrm_nvm_read_input req = {0};
3231 struct hwrm_nvm_read_output *resp = bp->hwrm_cmd_resp_addr;
3233 buf = rte_malloc("nvm_item", length, 0);
3234 rte_mem_lock_page(buf);
3238 dma_handle = rte_mem_virt2iova(buf);
3239 if (dma_handle == 0) {
3241 "unable to map response address to physical memory\n");
3244 HWRM_PREP(req, NVM_READ);
3245 req.host_dest_addr = rte_cpu_to_le_64(dma_handle);
3246 req.dir_idx = rte_cpu_to_le_16(index);
3247 req.offset = rte_cpu_to_le_32(offset);
3248 req.len = rte_cpu_to_le_32(length);
3249 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3250 HWRM_CHECK_RESULT();
3253 memcpy(data, buf, length);
3259 int bnxt_hwrm_erase_nvram_directory(struct bnxt *bp, uint8_t index)
3262 struct hwrm_nvm_erase_dir_entry_input req = {0};
3263 struct hwrm_nvm_erase_dir_entry_output *resp = bp->hwrm_cmd_resp_addr;
3265 HWRM_PREP(req, NVM_ERASE_DIR_ENTRY);
3266 req.dir_idx = rte_cpu_to_le_16(index);
3267 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3268 HWRM_CHECK_RESULT();
3275 int bnxt_hwrm_flash_nvram(struct bnxt *bp, uint16_t dir_type,
3276 uint16_t dir_ordinal, uint16_t dir_ext,
3277 uint16_t dir_attr, const uint8_t *data,
3281 struct hwrm_nvm_write_input req = {0};
3282 struct hwrm_nvm_write_output *resp = bp->hwrm_cmd_resp_addr;
3283 rte_iova_t dma_handle;
3286 HWRM_PREP(req, NVM_WRITE);
3288 req.dir_type = rte_cpu_to_le_16(dir_type);
3289 req.dir_ordinal = rte_cpu_to_le_16(dir_ordinal);
3290 req.dir_ext = rte_cpu_to_le_16(dir_ext);
3291 req.dir_attr = rte_cpu_to_le_16(dir_attr);
3292 req.dir_data_length = rte_cpu_to_le_32(data_len);
3294 buf = rte_malloc("nvm_write", data_len, 0);
3295 rte_mem_lock_page(buf);
3299 dma_handle = rte_mem_virt2iova(buf);
3300 if (dma_handle == 0) {
3302 "unable to map response address to physical memory\n");
3305 memcpy(buf, data, data_len);
3306 req.host_src_addr = rte_cpu_to_le_64(dma_handle);
3308 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3310 HWRM_CHECK_RESULT();
3318 bnxt_vnic_count(struct bnxt_vnic_info *vnic __rte_unused, void *cbdata)
3320 uint32_t *count = cbdata;
3322 *count = *count + 1;
3325 static int bnxt_vnic_count_hwrm_stub(struct bnxt *bp __rte_unused,
3326 struct bnxt_vnic_info *vnic __rte_unused)
3331 int bnxt_vf_vnic_count(struct bnxt *bp, uint16_t vf)
3335 bnxt_hwrm_func_vf_vnic_query_and_config(bp, vf, bnxt_vnic_count,
3336 &count, bnxt_vnic_count_hwrm_stub);
3341 static int bnxt_hwrm_func_vf_vnic_query(struct bnxt *bp, uint16_t vf,
3344 struct hwrm_func_vf_vnic_ids_query_input req = {0};
3345 struct hwrm_func_vf_vnic_ids_query_output *resp =
3346 bp->hwrm_cmd_resp_addr;
3349 /* First query all VNIC ids */
3350 HWRM_PREP(req, FUNC_VF_VNIC_IDS_QUERY);
3352 req.vf_id = rte_cpu_to_le_16(bp->pf.first_vf_id + vf);
3353 req.max_vnic_id_cnt = rte_cpu_to_le_32(bp->pf.total_vnics);
3354 req.vnic_id_tbl_addr = rte_cpu_to_le_64(rte_mem_virt2iova(vnic_ids));
3356 if (req.vnic_id_tbl_addr == 0) {
3359 "unable to map VNIC ID table address to physical memory\n");
3362 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3365 PMD_DRV_LOG(ERR, "hwrm_func_vf_vnic_query failed rc:%d\n", rc);
3367 } else if (resp->error_code) {
3368 rc = rte_le_to_cpu_16(resp->error_code);
3370 PMD_DRV_LOG(ERR, "hwrm_func_vf_vnic_query error %d\n", rc);
3373 rc = rte_le_to_cpu_32(resp->vnic_id_cnt);
3381 * This function queries the VNIC IDs for a specified VF. It then calls
3382 * the vnic_cb to update the necessary field in vnic_info with cbdata.
3383 * Then it calls the hwrm_cb function to program this new vnic configuration.
3385 int bnxt_hwrm_func_vf_vnic_query_and_config(struct bnxt *bp, uint16_t vf,
3386 void (*vnic_cb)(struct bnxt_vnic_info *, void *), void *cbdata,
3387 int (*hwrm_cb)(struct bnxt *bp, struct bnxt_vnic_info *vnic))
3389 struct bnxt_vnic_info vnic;
3391 int i, num_vnic_ids;
3396 /* First query all VNIC ids */
3397 vnic_id_sz = bp->pf.total_vnics * sizeof(*vnic_ids);
3398 vnic_ids = rte_malloc("bnxt_hwrm_vf_vnic_ids_query", vnic_id_sz,
3399 RTE_CACHE_LINE_SIZE);
3400 if (vnic_ids == NULL) {
3404 for (sz = 0; sz < vnic_id_sz; sz += getpagesize())
3405 rte_mem_lock_page(((char *)vnic_ids) + sz);
3407 num_vnic_ids = bnxt_hwrm_func_vf_vnic_query(bp, vf, vnic_ids);
3409 if (num_vnic_ids < 0)
3410 return num_vnic_ids;
3412 /* Retrieve VNIC, update bd_stall then update */
3414 for (i = 0; i < num_vnic_ids; i++) {
3415 memset(&vnic, 0, sizeof(struct bnxt_vnic_info));
3416 vnic.fw_vnic_id = rte_le_to_cpu_16(vnic_ids[i]);
3417 rc = bnxt_hwrm_vnic_qcfg(bp, &vnic, bp->pf.first_vf_id + vf);
3420 if (vnic.mru <= 4) /* Indicates unallocated */
3423 vnic_cb(&vnic, cbdata);
3425 rc = hwrm_cb(bp, &vnic);
3435 int bnxt_hwrm_func_cfg_vf_set_vlan_anti_spoof(struct bnxt *bp, uint16_t vf,
3438 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3439 struct hwrm_func_cfg_input req = {0};
3442 HWRM_PREP(req, FUNC_CFG);
3444 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3445 req.enables |= rte_cpu_to_le_32(
3446 HWRM_FUNC_CFG_INPUT_ENABLES_VLAN_ANTISPOOF_MODE);
3447 req.vlan_antispoof_mode = on ?
3448 HWRM_FUNC_CFG_INPUT_VLAN_ANTISPOOF_MODE_VALIDATE_VLAN :
3449 HWRM_FUNC_CFG_INPUT_VLAN_ANTISPOOF_MODE_NOCHECK;
3450 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3452 HWRM_CHECK_RESULT();
3458 int bnxt_hwrm_func_qcfg_vf_dflt_vnic_id(struct bnxt *bp, int vf)
3460 struct bnxt_vnic_info vnic;
3463 int num_vnic_ids, i;
3467 vnic_id_sz = bp->pf.total_vnics * sizeof(*vnic_ids);
3468 vnic_ids = rte_malloc("bnxt_hwrm_vf_vnic_ids_query", vnic_id_sz,
3469 RTE_CACHE_LINE_SIZE);
3470 if (vnic_ids == NULL) {
3475 for (sz = 0; sz < vnic_id_sz; sz += getpagesize())
3476 rte_mem_lock_page(((char *)vnic_ids) + sz);
3478 rc = bnxt_hwrm_func_vf_vnic_query(bp, vf, vnic_ids);
3484 * Loop through to find the default VNIC ID.
3485 * TODO: The easier way would be to obtain the resp->dflt_vnic_id
3486 * by sending the hwrm_func_qcfg command to the firmware.
3488 for (i = 0; i < num_vnic_ids; i++) {
3489 memset(&vnic, 0, sizeof(struct bnxt_vnic_info));
3490 vnic.fw_vnic_id = rte_le_to_cpu_16(vnic_ids[i]);
3491 rc = bnxt_hwrm_vnic_qcfg(bp, &vnic,
3492 bp->pf.first_vf_id + vf);
3495 if (vnic.func_default) {
3497 return vnic.fw_vnic_id;
3500 /* Could not find a default VNIC. */
3501 PMD_DRV_LOG(ERR, "No default VNIC\n");
3507 int bnxt_hwrm_set_em_filter(struct bnxt *bp,
3509 struct bnxt_filter_info *filter)
3512 struct hwrm_cfa_em_flow_alloc_input req = {.req_type = 0 };
3513 struct hwrm_cfa_em_flow_alloc_output *resp = bp->hwrm_cmd_resp_addr;
3514 uint32_t enables = 0;
3516 if (filter->fw_em_filter_id != UINT64_MAX)
3517 bnxt_hwrm_clear_em_filter(bp, filter);
3519 HWRM_PREP(req, CFA_EM_FLOW_ALLOC);
3521 req.flags = rte_cpu_to_le_32(filter->flags);
3523 enables = filter->enables |
3524 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_ID;
3525 req.dst_id = rte_cpu_to_le_16(dst_id);
3527 if (filter->ip_addr_type) {
3528 req.ip_addr_type = filter->ip_addr_type;
3529 enables |= HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IPADDR_TYPE;
3532 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_L2_FILTER_ID)
3533 req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
3535 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_MACADDR)
3536 memcpy(req.src_macaddr, filter->src_macaddr,
3539 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_MACADDR)
3540 memcpy(req.dst_macaddr, filter->dst_macaddr,
3543 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_OVLAN_VID)
3544 req.ovlan_vid = filter->l2_ovlan;
3546 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IVLAN_VID)
3547 req.ivlan_vid = filter->l2_ivlan;
3549 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_ETHERTYPE)
3550 req.ethertype = rte_cpu_to_be_16(filter->ethertype);
3552 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IP_PROTOCOL)
3553 req.ip_protocol = filter->ip_protocol;
3555 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_IPADDR)
3556 req.src_ipaddr[0] = rte_cpu_to_be_32(filter->src_ipaddr[0]);
3558 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_IPADDR)
3559 req.dst_ipaddr[0] = rte_cpu_to_be_32(filter->dst_ipaddr[0]);
3561 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_PORT)
3562 req.src_port = rte_cpu_to_be_16(filter->src_port);
3564 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_PORT)
3565 req.dst_port = rte_cpu_to_be_16(filter->dst_port);
3567 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_MIRROR_VNIC_ID)
3568 req.mirror_vnic_id = filter->mirror_vnic_id;
3570 req.enables = rte_cpu_to_le_32(enables);
3572 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3574 HWRM_CHECK_RESULT();
3576 filter->fw_em_filter_id = rte_le_to_cpu_64(resp->em_filter_id);
3582 int bnxt_hwrm_clear_em_filter(struct bnxt *bp, struct bnxt_filter_info *filter)
3585 struct hwrm_cfa_em_flow_free_input req = {.req_type = 0 };
3586 struct hwrm_cfa_em_flow_free_output *resp = bp->hwrm_cmd_resp_addr;
3588 if (filter->fw_em_filter_id == UINT64_MAX)
3591 PMD_DRV_LOG(ERR, "Clear EM filter\n");
3592 HWRM_PREP(req, CFA_EM_FLOW_FREE);
3594 req.em_filter_id = rte_cpu_to_le_64(filter->fw_em_filter_id);
3596 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3598 HWRM_CHECK_RESULT();
3601 filter->fw_em_filter_id = UINT64_MAX;
3602 filter->fw_l2_filter_id = UINT64_MAX;
3607 int bnxt_hwrm_set_ntuple_filter(struct bnxt *bp,
3609 struct bnxt_filter_info *filter)
3612 struct hwrm_cfa_ntuple_filter_alloc_input req = {.req_type = 0 };
3613 struct hwrm_cfa_ntuple_filter_alloc_output *resp =
3614 bp->hwrm_cmd_resp_addr;
3615 uint32_t enables = 0;
3617 if (filter->fw_ntuple_filter_id != UINT64_MAX)
3618 bnxt_hwrm_clear_ntuple_filter(bp, filter);
3620 HWRM_PREP(req, CFA_NTUPLE_FILTER_ALLOC);
3622 req.flags = rte_cpu_to_le_32(filter->flags);
3624 enables = filter->enables |
3625 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_ID;
3626 req.dst_id = rte_cpu_to_le_16(dst_id);
3629 if (filter->ip_addr_type) {
3630 req.ip_addr_type = filter->ip_addr_type;
3632 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_IPADDR_TYPE;
3635 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_L2_FILTER_ID)
3636 req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
3638 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_MACADDR)
3639 memcpy(req.src_macaddr, filter->src_macaddr,
3642 //HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_MACADDR)
3643 //memcpy(req.dst_macaddr, filter->dst_macaddr,
3646 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_ETHERTYPE)
3647 req.ethertype = rte_cpu_to_be_16(filter->ethertype);
3649 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_IP_PROTOCOL)
3650 req.ip_protocol = filter->ip_protocol;
3652 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_IPADDR)
3653 req.src_ipaddr[0] = rte_cpu_to_le_32(filter->src_ipaddr[0]);
3655 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_IPADDR_MASK)
3656 req.src_ipaddr_mask[0] =
3657 rte_cpu_to_le_32(filter->src_ipaddr_mask[0]);
3659 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_IPADDR)
3660 req.dst_ipaddr[0] = rte_cpu_to_le_32(filter->dst_ipaddr[0]);
3662 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_IPADDR_MASK)
3663 req.dst_ipaddr_mask[0] =
3664 rte_cpu_to_be_32(filter->dst_ipaddr_mask[0]);
3666 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_PORT)
3667 req.src_port = rte_cpu_to_le_16(filter->src_port);
3669 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_PORT_MASK)
3670 req.src_port_mask = rte_cpu_to_le_16(filter->src_port_mask);
3672 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_PORT)
3673 req.dst_port = rte_cpu_to_le_16(filter->dst_port);
3675 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_PORT_MASK)
3676 req.dst_port_mask = rte_cpu_to_le_16(filter->dst_port_mask);
3678 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_MIRROR_VNIC_ID)
3679 req.mirror_vnic_id = filter->mirror_vnic_id;
3681 req.enables = rte_cpu_to_le_32(enables);
3683 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3685 HWRM_CHECK_RESULT();
3687 filter->fw_ntuple_filter_id = rte_le_to_cpu_64(resp->ntuple_filter_id);
3693 int bnxt_hwrm_clear_ntuple_filter(struct bnxt *bp,
3694 struct bnxt_filter_info *filter)
3697 struct hwrm_cfa_ntuple_filter_free_input req = {.req_type = 0 };
3698 struct hwrm_cfa_ntuple_filter_free_output *resp =
3699 bp->hwrm_cmd_resp_addr;
3701 if (filter->fw_ntuple_filter_id == UINT64_MAX)
3704 HWRM_PREP(req, CFA_NTUPLE_FILTER_FREE);
3706 req.ntuple_filter_id = rte_cpu_to_le_64(filter->fw_ntuple_filter_id);
3708 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3710 HWRM_CHECK_RESULT();
3713 filter->fw_ntuple_filter_id = UINT64_MAX;
3714 filter->fw_l2_filter_id = UINT64_MAX;
3719 int bnxt_vnic_rss_configure(struct bnxt *bp, struct bnxt_vnic_info *vnic)
3721 unsigned int rss_idx, fw_idx, i;
3723 if (vnic->rss_table && vnic->hash_type) {
3725 * Fill the RSS hash & redirection table with
3726 * ring group ids for all VNICs
3728 for (rss_idx = 0, fw_idx = 0; rss_idx < HW_HASH_INDEX_SIZE;
3729 rss_idx++, fw_idx++) {
3730 for (i = 0; i < bp->rx_cp_nr_rings; i++) {
3731 fw_idx %= bp->rx_cp_nr_rings;
3732 if (vnic->fw_grp_ids[fw_idx] !=
3737 if (i == bp->rx_cp_nr_rings)
3739 vnic->rss_table[rss_idx] =
3740 vnic->fw_grp_ids[fw_idx];
3742 return bnxt_hwrm_vnic_rss_cfg(bp, vnic);