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 6000000
30 #define HWRM_SHORT_CMD_TIMEOUT 50000
31 #define HWRM_SPEC_CODE_1_8_3 0x10803
32 #define HWRM_VERSION_1_9_1 0x10901
33 #define HWRM_VERSION_1_9_2 0x10903
35 struct bnxt_plcmodes_cfg {
37 uint16_t jumbo_thresh;
39 uint16_t hds_threshold;
42 static int page_getenum(size_t size)
58 PMD_DRV_LOG(ERR, "Page size %zu out of range\n", size);
59 return sizeof(void *) * 8 - 1;
62 static int page_roundup(size_t size)
64 return 1 << page_getenum(size);
67 static void bnxt_hwrm_set_pg_attr(struct bnxt_ring_mem_info *rmem,
71 if (rmem->nr_pages > 1) {
73 *pg_dir = rte_cpu_to_le_64(rmem->pg_tbl_map);
75 *pg_dir = rte_cpu_to_le_64(rmem->dma_arr[0]);
80 * HWRM Functions (sent to HWRM)
81 * These are named bnxt_hwrm_*() and return -1 if bnxt_hwrm_send_message()
82 * fails (ie: a timeout), and a positive non-zero HWRM error code if the HWRM
83 * command was failed by the ChiMP.
86 static int bnxt_hwrm_send_message(struct bnxt *bp, void *msg,
87 uint32_t msg_len, bool use_kong_mb)
90 struct input *req = msg;
91 struct output *resp = bp->hwrm_cmd_resp_addr;
95 uint16_t max_req_len = bp->max_req_len;
96 struct hwrm_short_input short_input = { 0 };
97 uint16_t bar_offset = use_kong_mb ?
98 GRCPF_REG_KONG_CHANNEL_OFFSET : GRCPF_REG_CHIMP_CHANNEL_OFFSET;
99 uint16_t mb_trigger_offset = use_kong_mb ?
100 GRCPF_REG_KONG_COMM_TRIGGER : GRCPF_REG_CHIMP_COMM_TRIGGER;
103 /* Do not send HWRM commands to firmware in error state */
104 if (bp->flags & BNXT_FLAG_FATAL_ERROR)
107 /* For VER_GET command, set timeout as 50ms */
108 if (rte_cpu_to_le_16(req->req_type) == HWRM_VER_GET)
109 timeout = HWRM_SHORT_CMD_TIMEOUT;
111 timeout = HWRM_CMD_TIMEOUT;
113 if (bp->flags & BNXT_FLAG_SHORT_CMD ||
114 msg_len > bp->max_req_len) {
115 void *short_cmd_req = bp->hwrm_short_cmd_req_addr;
117 memset(short_cmd_req, 0, bp->hwrm_max_ext_req_len);
118 memcpy(short_cmd_req, req, msg_len);
120 short_input.req_type = rte_cpu_to_le_16(req->req_type);
121 short_input.signature = rte_cpu_to_le_16(
122 HWRM_SHORT_INPUT_SIGNATURE_SHORT_CMD);
123 short_input.size = rte_cpu_to_le_16(msg_len);
124 short_input.req_addr =
125 rte_cpu_to_le_64(bp->hwrm_short_cmd_req_dma_addr);
127 data = (uint32_t *)&short_input;
128 msg_len = sizeof(short_input);
130 max_req_len = BNXT_HWRM_SHORT_REQ_LEN;
133 /* Write request msg to hwrm channel */
134 for (i = 0; i < msg_len; i += 4) {
135 bar = (uint8_t *)bp->bar0 + bar_offset + i;
136 rte_write32(*data, bar);
140 /* Zero the rest of the request space */
141 for (; i < max_req_len; i += 4) {
142 bar = (uint8_t *)bp->bar0 + bar_offset + i;
146 /* Ring channel doorbell */
147 bar = (uint8_t *)bp->bar0 + mb_trigger_offset;
150 * Make sure the channel doorbell ring command complete before
151 * reading the response to avoid getting stale or invalid
156 /* Poll for the valid bit */
157 for (i = 0; i < timeout; i++) {
158 /* Sanity check on the resp->resp_len */
160 if (resp->resp_len && resp->resp_len <= bp->max_resp_len) {
161 /* Last byte of resp contains the valid key */
162 valid = (uint8_t *)resp + resp->resp_len - 1;
163 if (*valid == HWRM_RESP_VALID_KEY)
170 /* Suppress VER_GET timeout messages during reset recovery */
171 if (bp->flags & BNXT_FLAG_FW_RESET &&
172 rte_cpu_to_le_16(req->req_type) == HWRM_VER_GET)
175 PMD_DRV_LOG(ERR, "Error(timeout) sending msg 0x%04x\n",
183 * HWRM_PREP() should be used to prepare *ALL* HWRM commands. It grabs the
184 * spinlock, and does initial processing.
186 * HWRM_CHECK_RESULT() returns errors on failure and may not be used. It
187 * releases the spinlock only if it returns. If the regular int return codes
188 * are not used by the function, HWRM_CHECK_RESULT() should not be used
189 * directly, rather it should be copied and modified to suit the function.
191 * HWRM_UNLOCK() must be called after all response processing is completed.
193 #define HWRM_PREP(req, type, kong) do { \
194 rte_spinlock_lock(&bp->hwrm_lock); \
195 memset(bp->hwrm_cmd_resp_addr, 0, bp->max_resp_len); \
196 req.req_type = rte_cpu_to_le_16(HWRM_##type); \
197 req.cmpl_ring = rte_cpu_to_le_16(-1); \
198 req.seq_id = kong ? rte_cpu_to_le_16(bp->kong_cmd_seq++) :\
199 rte_cpu_to_le_16(bp->hwrm_cmd_seq++); \
200 req.target_id = rte_cpu_to_le_16(0xffff); \
201 req.resp_addr = rte_cpu_to_le_64(bp->hwrm_cmd_resp_dma_addr); \
204 #define HWRM_CHECK_RESULT_SILENT() do {\
206 rte_spinlock_unlock(&bp->hwrm_lock); \
209 if (resp->error_code) { \
210 rc = rte_le_to_cpu_16(resp->error_code); \
211 rte_spinlock_unlock(&bp->hwrm_lock); \
216 #define HWRM_CHECK_RESULT() do {\
218 PMD_DRV_LOG(ERR, "failed rc:%d\n", rc); \
219 rte_spinlock_unlock(&bp->hwrm_lock); \
220 if (rc == HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED) \
226 if (resp->error_code) { \
227 rc = rte_le_to_cpu_16(resp->error_code); \
228 if (resp->resp_len >= 16) { \
229 struct hwrm_err_output *tmp_hwrm_err_op = \
232 "error %d:%d:%08x:%04x\n", \
233 rc, tmp_hwrm_err_op->cmd_err, \
235 tmp_hwrm_err_op->opaque_0), \
237 tmp_hwrm_err_op->opaque_1)); \
239 PMD_DRV_LOG(ERR, "error %d\n", rc); \
241 rte_spinlock_unlock(&bp->hwrm_lock); \
242 if (rc == HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED) \
250 #define HWRM_UNLOCK() rte_spinlock_unlock(&bp->hwrm_lock)
252 int bnxt_hwrm_cfa_l2_clear_rx_mask(struct bnxt *bp, struct bnxt_vnic_info *vnic)
255 struct hwrm_cfa_l2_set_rx_mask_input req = {.req_type = 0 };
256 struct hwrm_cfa_l2_set_rx_mask_output *resp = bp->hwrm_cmd_resp_addr;
258 HWRM_PREP(req, CFA_L2_SET_RX_MASK, BNXT_USE_CHIMP_MB);
259 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
262 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
270 int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp,
271 struct bnxt_vnic_info *vnic,
273 struct bnxt_vlan_table_entry *vlan_table)
276 struct hwrm_cfa_l2_set_rx_mask_input req = {.req_type = 0 };
277 struct hwrm_cfa_l2_set_rx_mask_output *resp = bp->hwrm_cmd_resp_addr;
280 if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
283 HWRM_PREP(req, CFA_L2_SET_RX_MASK, BNXT_USE_CHIMP_MB);
284 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
286 /* FIXME add multicast flag, when multicast adding options is supported
289 if (vnic->flags & BNXT_VNIC_INFO_BCAST)
290 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_BCAST;
291 if (vnic->flags & BNXT_VNIC_INFO_UNTAGGED)
292 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLAN_NONVLAN;
293 if (vnic->flags & BNXT_VNIC_INFO_PROMISC)
294 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_PROMISCUOUS;
295 if (vnic->flags & BNXT_VNIC_INFO_ALLMULTI)
296 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
297 if (vnic->flags & BNXT_VNIC_INFO_MCAST)
298 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_MCAST;
299 if (vnic->mc_addr_cnt) {
300 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_MCAST;
301 req.num_mc_entries = rte_cpu_to_le_32(vnic->mc_addr_cnt);
302 req.mc_tbl_addr = rte_cpu_to_le_64(vnic->mc_list_dma_addr);
305 if (!(mask & HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLAN_NONVLAN))
306 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLANONLY;
307 req.vlan_tag_tbl_addr = rte_cpu_to_le_64(
308 rte_mem_virt2iova(vlan_table));
309 req.num_vlan_tags = rte_cpu_to_le_32((uint32_t)vlan_count);
311 req.mask = rte_cpu_to_le_32(mask);
313 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
321 int bnxt_hwrm_cfa_vlan_antispoof_cfg(struct bnxt *bp, uint16_t fid,
323 struct bnxt_vlan_antispoof_table_entry *vlan_table)
326 struct hwrm_cfa_vlan_antispoof_cfg_input req = {.req_type = 0 };
327 struct hwrm_cfa_vlan_antispoof_cfg_output *resp =
328 bp->hwrm_cmd_resp_addr;
331 * Older HWRM versions did not support this command, and the set_rx_mask
332 * list was used for anti-spoof. In 1.8.0, the TX path configuration was
333 * removed from set_rx_mask call, and this command was added.
335 * This command is also present from 1.7.8.11 and higher,
338 if (bp->fw_ver < ((1 << 24) | (8 << 16))) {
339 if (bp->fw_ver != ((1 << 24) | (7 << 16) | (8 << 8))) {
340 if (bp->fw_ver < ((1 << 24) | (7 << 16) | (8 << 8) |
345 HWRM_PREP(req, CFA_VLAN_ANTISPOOF_CFG, BNXT_USE_CHIMP_MB);
346 req.fid = rte_cpu_to_le_16(fid);
348 req.vlan_tag_mask_tbl_addr =
349 rte_cpu_to_le_64(rte_mem_virt2iova(vlan_table));
350 req.num_vlan_entries = rte_cpu_to_le_32((uint32_t)vlan_count);
352 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
360 int bnxt_hwrm_clear_l2_filter(struct bnxt *bp,
361 struct bnxt_filter_info *filter)
364 struct hwrm_cfa_l2_filter_free_input req = {.req_type = 0 };
365 struct hwrm_cfa_l2_filter_free_output *resp = bp->hwrm_cmd_resp_addr;
367 if (filter->fw_l2_filter_id == UINT64_MAX)
370 HWRM_PREP(req, CFA_L2_FILTER_FREE, BNXT_USE_CHIMP_MB);
372 req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
374 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
379 filter->fw_l2_filter_id = UINT64_MAX;
384 int bnxt_hwrm_set_l2_filter(struct bnxt *bp,
386 struct bnxt_filter_info *filter)
389 struct hwrm_cfa_l2_filter_alloc_input req = {.req_type = 0 };
390 struct hwrm_cfa_l2_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr;
391 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
392 const struct rte_eth_vmdq_rx_conf *conf =
393 &dev_conf->rx_adv_conf.vmdq_rx_conf;
394 uint32_t enables = 0;
395 uint16_t j = dst_id - 1;
397 //TODO: Is there a better way to add VLANs to each VNIC in case of VMDQ
398 if ((dev_conf->rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG) &&
399 conf->pool_map[j].pools & (1UL << j)) {
401 "Add vlan %u to vmdq pool %u\n",
402 conf->pool_map[j].vlan_id, j);
404 filter->l2_ivlan = conf->pool_map[j].vlan_id;
406 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN |
407 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN_MASK;
410 if (filter->fw_l2_filter_id != UINT64_MAX)
411 bnxt_hwrm_clear_l2_filter(bp, filter);
413 HWRM_PREP(req, CFA_L2_FILTER_ALLOC, BNXT_USE_CHIMP_MB);
415 req.flags = rte_cpu_to_le_32(filter->flags);
417 rte_cpu_to_le_32(HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_OUTERMOST);
419 enables = filter->enables |
420 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_DST_ID;
421 req.dst_id = rte_cpu_to_le_16(dst_id);
424 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR)
425 memcpy(req.l2_addr, filter->l2_addr,
428 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR_MASK)
429 memcpy(req.l2_addr_mask, filter->l2_addr_mask,
432 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN)
433 req.l2_ovlan = filter->l2_ovlan;
435 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN)
436 req.l2_ivlan = filter->l2_ivlan;
438 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN_MASK)
439 req.l2_ovlan_mask = filter->l2_ovlan_mask;
441 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN_MASK)
442 req.l2_ivlan_mask = filter->l2_ivlan_mask;
443 if (enables & HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_SRC_ID)
444 req.src_id = rte_cpu_to_le_32(filter->src_id);
445 if (enables & HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_SRC_TYPE)
446 req.src_type = filter->src_type;
448 req.enables = rte_cpu_to_le_32(enables);
450 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
454 filter->fw_l2_filter_id = rte_le_to_cpu_64(resp->l2_filter_id);
460 int bnxt_hwrm_ptp_cfg(struct bnxt *bp)
462 struct hwrm_port_mac_cfg_input req = {.req_type = 0};
463 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
470 HWRM_PREP(req, PORT_MAC_CFG, BNXT_USE_CHIMP_MB);
473 flags |= HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_RX_TS_CAPTURE_ENABLE;
476 HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_RX_TS_CAPTURE_DISABLE;
477 if (ptp->tx_tstamp_en)
478 flags |= HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_TX_TS_CAPTURE_ENABLE;
481 HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_TX_TS_CAPTURE_DISABLE;
482 req.flags = rte_cpu_to_le_32(flags);
483 req.enables = rte_cpu_to_le_32
484 (HWRM_PORT_MAC_CFG_INPUT_ENABLES_RX_TS_CAPTURE_PTP_MSG_TYPE);
485 req.rx_ts_capture_ptp_msg_type = rte_cpu_to_le_16(ptp->rxctl);
487 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
493 static int bnxt_hwrm_ptp_qcfg(struct bnxt *bp)
496 struct hwrm_port_mac_ptp_qcfg_input req = {.req_type = 0};
497 struct hwrm_port_mac_ptp_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
498 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
500 /* if (bp->hwrm_spec_code < 0x10801 || ptp) TBD */
504 HWRM_PREP(req, PORT_MAC_PTP_QCFG, BNXT_USE_CHIMP_MB);
506 req.port_id = rte_cpu_to_le_16(bp->pf.port_id);
508 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
512 if (!BNXT_CHIP_THOR(bp) &&
513 !(resp->flags & HWRM_PORT_MAC_PTP_QCFG_OUTPUT_FLAGS_DIRECT_ACCESS))
516 if (resp->flags & HWRM_PORT_MAC_PTP_QCFG_OUTPUT_FLAGS_ONE_STEP_TX_TS)
517 bp->flags |= BNXT_FLAG_FW_CAP_ONE_STEP_TX_TS;
519 ptp = rte_zmalloc("ptp_cfg", sizeof(*ptp), 0);
523 if (!BNXT_CHIP_THOR(bp)) {
524 ptp->rx_regs[BNXT_PTP_RX_TS_L] =
525 rte_le_to_cpu_32(resp->rx_ts_reg_off_lower);
526 ptp->rx_regs[BNXT_PTP_RX_TS_H] =
527 rte_le_to_cpu_32(resp->rx_ts_reg_off_upper);
528 ptp->rx_regs[BNXT_PTP_RX_SEQ] =
529 rte_le_to_cpu_32(resp->rx_ts_reg_off_seq_id);
530 ptp->rx_regs[BNXT_PTP_RX_FIFO] =
531 rte_le_to_cpu_32(resp->rx_ts_reg_off_fifo);
532 ptp->rx_regs[BNXT_PTP_RX_FIFO_ADV] =
533 rte_le_to_cpu_32(resp->rx_ts_reg_off_fifo_adv);
534 ptp->tx_regs[BNXT_PTP_TX_TS_L] =
535 rte_le_to_cpu_32(resp->tx_ts_reg_off_lower);
536 ptp->tx_regs[BNXT_PTP_TX_TS_H] =
537 rte_le_to_cpu_32(resp->tx_ts_reg_off_upper);
538 ptp->tx_regs[BNXT_PTP_TX_SEQ] =
539 rte_le_to_cpu_32(resp->tx_ts_reg_off_seq_id);
540 ptp->tx_regs[BNXT_PTP_TX_FIFO] =
541 rte_le_to_cpu_32(resp->tx_ts_reg_off_fifo);
550 static int __bnxt_hwrm_func_qcaps(struct bnxt *bp)
553 struct hwrm_func_qcaps_input req = {.req_type = 0 };
554 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
555 uint16_t new_max_vfs;
559 HWRM_PREP(req, FUNC_QCAPS, BNXT_USE_CHIMP_MB);
561 req.fid = rte_cpu_to_le_16(0xffff);
563 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
567 bp->max_ring_grps = rte_le_to_cpu_32(resp->max_hw_ring_grps);
568 flags = rte_le_to_cpu_32(resp->flags);
570 bp->pf.port_id = resp->port_id;
571 bp->pf.first_vf_id = rte_le_to_cpu_16(resp->first_vf_id);
572 bp->pf.total_vfs = rte_le_to_cpu_16(resp->max_vfs);
573 new_max_vfs = bp->pdev->max_vfs;
574 if (new_max_vfs != bp->pf.max_vfs) {
576 rte_free(bp->pf.vf_info);
577 bp->pf.vf_info = rte_malloc("bnxt_vf_info",
578 sizeof(bp->pf.vf_info[0]) * new_max_vfs, 0);
579 bp->pf.max_vfs = new_max_vfs;
580 for (i = 0; i < new_max_vfs; i++) {
581 bp->pf.vf_info[i].fid = bp->pf.first_vf_id + i;
582 bp->pf.vf_info[i].vlan_table =
583 rte_zmalloc("VF VLAN table",
586 if (bp->pf.vf_info[i].vlan_table == NULL)
588 "Fail to alloc VLAN table for VF %d\n",
592 bp->pf.vf_info[i].vlan_table);
593 bp->pf.vf_info[i].vlan_as_table =
594 rte_zmalloc("VF VLAN AS table",
597 if (bp->pf.vf_info[i].vlan_as_table == NULL)
599 "Alloc VLAN AS table for VF %d fail\n",
603 bp->pf.vf_info[i].vlan_as_table);
604 STAILQ_INIT(&bp->pf.vf_info[i].filter);
609 bp->fw_fid = rte_le_to_cpu_32(resp->fid);
610 memcpy(bp->dflt_mac_addr, &resp->mac_address, RTE_ETHER_ADDR_LEN);
611 bp->max_rsscos_ctx = rte_le_to_cpu_16(resp->max_rsscos_ctx);
612 bp->max_cp_rings = rte_le_to_cpu_16(resp->max_cmpl_rings);
613 bp->max_tx_rings = rte_le_to_cpu_16(resp->max_tx_rings);
614 bp->max_rx_rings = rte_le_to_cpu_16(resp->max_rx_rings);
615 bp->first_vf_id = rte_le_to_cpu_16(resp->first_vf_id);
616 bp->max_rx_em_flows = rte_le_to_cpu_16(resp->max_rx_em_flows);
617 bp->max_l2_ctx = rte_le_to_cpu_16(resp->max_l2_ctxs);
618 if (!BNXT_CHIP_THOR(bp))
619 bp->max_l2_ctx += bp->max_rx_em_flows;
620 /* TODO: For now, do not support VMDq/RFS on VFs. */
625 bp->max_vnics = rte_le_to_cpu_16(resp->max_vnics);
629 bp->max_stat_ctx = rte_le_to_cpu_16(resp->max_stat_ctx);
631 bp->pf.total_vnics = rte_le_to_cpu_16(resp->max_vnics);
632 if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_PTP_SUPPORTED) {
633 bp->flags |= BNXT_FLAG_PTP_SUPPORTED;
634 PMD_DRV_LOG(DEBUG, "PTP SUPPORTED\n");
636 bnxt_hwrm_ptp_qcfg(bp);
640 if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_EXT_STATS_SUPPORTED)
641 bp->flags |= BNXT_FLAG_EXT_STATS_SUPPORTED;
643 if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_ERROR_RECOVERY_CAPABLE) {
644 bp->flags |= BNXT_FLAG_FW_CAP_ERROR_RECOVERY;
645 PMD_DRV_LOG(DEBUG, "Adapter Error recovery SUPPORTED\n");
647 bp->flags &= ~BNXT_FLAG_FW_CAP_ERROR_RECOVERY;
650 if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_ERR_RECOVER_RELOAD)
651 bp->flags |= BNXT_FLAG_FW_CAP_ERR_RECOVER_RELOAD;
653 bp->flags &= ~BNXT_FLAG_FW_CAP_ERR_RECOVER_RELOAD;
660 int bnxt_hwrm_func_qcaps(struct bnxt *bp)
664 rc = __bnxt_hwrm_func_qcaps(bp);
665 if (!rc && bp->hwrm_spec_code >= HWRM_SPEC_CODE_1_8_3) {
666 rc = bnxt_alloc_ctx_mem(bp);
670 rc = bnxt_hwrm_func_resc_qcaps(bp);
672 bp->flags |= BNXT_FLAG_NEW_RM;
678 int bnxt_hwrm_func_reset(struct bnxt *bp)
681 struct hwrm_func_reset_input req = {.req_type = 0 };
682 struct hwrm_func_reset_output *resp = bp->hwrm_cmd_resp_addr;
684 HWRM_PREP(req, FUNC_RESET, BNXT_USE_CHIMP_MB);
686 req.enables = rte_cpu_to_le_32(0);
688 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
696 int bnxt_hwrm_func_driver_register(struct bnxt *bp)
700 struct hwrm_func_drv_rgtr_input req = {.req_type = 0 };
701 struct hwrm_func_drv_rgtr_output *resp = bp->hwrm_cmd_resp_addr;
703 if (bp->flags & BNXT_FLAG_REGISTERED)
706 flags = HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_HOT_RESET_SUPPORT;
707 if (bp->flags & BNXT_FLAG_FW_CAP_ERROR_RECOVERY)
708 flags |= HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_ERROR_RECOVERY_SUPPORT;
710 /* PFs and trusted VFs should indicate the support of the
711 * Master capability on non Stingray platform
713 if ((BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp)) && !BNXT_STINGRAY(bp))
714 flags |= HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_MASTER_SUPPORT;
716 HWRM_PREP(req, FUNC_DRV_RGTR, BNXT_USE_CHIMP_MB);
717 req.enables = rte_cpu_to_le_32(HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_VER |
718 HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_ASYNC_EVENT_FWD);
719 req.ver_maj = RTE_VER_YEAR;
720 req.ver_min = RTE_VER_MONTH;
721 req.ver_upd = RTE_VER_MINOR;
724 req.enables |= rte_cpu_to_le_32(
725 HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_VF_REQ_FWD);
726 memcpy(req.vf_req_fwd, bp->pf.vf_req_fwd,
727 RTE_MIN(sizeof(req.vf_req_fwd),
728 sizeof(bp->pf.vf_req_fwd)));
731 * PF can sniff HWRM API issued by VF. This can be set up by
732 * linux driver and inherited by the DPDK PF driver. Clear
733 * this HWRM sniffer list in FW because DPDK PF driver does
736 flags |= HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_FWD_NONE_MODE;
739 req.flags = rte_cpu_to_le_32(flags);
741 req.async_event_fwd[0] |=
742 rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_LINK_STATUS_CHANGE |
743 ASYNC_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED |
744 ASYNC_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE |
745 ASYNC_CMPL_EVENT_ID_LINK_SPEED_CHANGE |
746 ASYNC_CMPL_EVENT_ID_RESET_NOTIFY);
747 if (bp->flags & BNXT_FLAG_FW_CAP_ERROR_RECOVERY)
748 req.async_event_fwd[0] |=
749 rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_ERROR_RECOVERY);
750 req.async_event_fwd[1] |=
751 rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_PF_DRVR_UNLOAD |
752 ASYNC_CMPL_EVENT_ID_VF_CFG_CHANGE);
754 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
758 flags = rte_le_to_cpu_32(resp->flags);
759 if (flags & HWRM_FUNC_DRV_RGTR_OUTPUT_FLAGS_IF_CHANGE_SUPPORTED)
760 bp->flags |= BNXT_FLAG_FW_CAP_IF_CHANGE;
764 bp->flags |= BNXT_FLAG_REGISTERED;
769 int bnxt_hwrm_check_vf_rings(struct bnxt *bp)
771 if (!(BNXT_VF(bp) && (bp->flags & BNXT_FLAG_NEW_RM)))
774 return bnxt_hwrm_func_reserve_vf_resc(bp, true);
777 int bnxt_hwrm_func_reserve_vf_resc(struct bnxt *bp, bool test)
782 struct hwrm_func_vf_cfg_output *resp = bp->hwrm_cmd_resp_addr;
783 struct hwrm_func_vf_cfg_input req = {0};
785 HWRM_PREP(req, FUNC_VF_CFG, BNXT_USE_CHIMP_MB);
787 enables = HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_RX_RINGS |
788 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_TX_RINGS |
789 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
790 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
791 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_VNICS;
793 if (BNXT_HAS_RING_GRPS(bp)) {
794 enables |= HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS;
795 req.num_hw_ring_grps = rte_cpu_to_le_16(bp->rx_nr_rings);
798 req.num_tx_rings = rte_cpu_to_le_16(bp->tx_nr_rings);
799 req.num_rx_rings = rte_cpu_to_le_16(bp->rx_nr_rings *
800 AGG_RING_MULTIPLIER);
801 req.num_stat_ctxs = rte_cpu_to_le_16(bp->rx_nr_rings +
803 BNXT_NUM_ASYNC_CPR(bp));
804 req.num_cmpl_rings = rte_cpu_to_le_16(bp->rx_nr_rings +
806 BNXT_NUM_ASYNC_CPR(bp));
807 req.num_vnics = rte_cpu_to_le_16(bp->rx_nr_rings);
808 if (bp->vf_resv_strategy ==
809 HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESV_STRATEGY_MINIMAL_STATIC) {
810 enables |= HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_VNICS |
811 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_L2_CTXS |
812 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS;
813 req.num_rsscos_ctxs = rte_cpu_to_le_16(BNXT_VF_RSV_NUM_RSS_CTX);
814 req.num_l2_ctxs = rte_cpu_to_le_16(BNXT_VF_RSV_NUM_L2_CTX);
815 req.num_vnics = rte_cpu_to_le_16(BNXT_VF_RSV_NUM_VNIC);
819 flags = HWRM_FUNC_VF_CFG_INPUT_FLAGS_TX_ASSETS_TEST |
820 HWRM_FUNC_VF_CFG_INPUT_FLAGS_RX_ASSETS_TEST |
821 HWRM_FUNC_VF_CFG_INPUT_FLAGS_CMPL_ASSETS_TEST |
822 HWRM_FUNC_VF_CFG_INPUT_FLAGS_RING_GRP_ASSETS_TEST |
823 HWRM_FUNC_VF_CFG_INPUT_FLAGS_STAT_CTX_ASSETS_TEST |
824 HWRM_FUNC_VF_CFG_INPUT_FLAGS_VNIC_ASSETS_TEST;
826 if (test && BNXT_HAS_RING_GRPS(bp))
827 flags |= HWRM_FUNC_VF_CFG_INPUT_FLAGS_RING_GRP_ASSETS_TEST;
829 req.flags = rte_cpu_to_le_32(flags);
830 req.enables |= rte_cpu_to_le_32(enables);
832 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
835 HWRM_CHECK_RESULT_SILENT();
843 int bnxt_hwrm_func_resc_qcaps(struct bnxt *bp)
846 struct hwrm_func_resource_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
847 struct hwrm_func_resource_qcaps_input req = {0};
849 HWRM_PREP(req, FUNC_RESOURCE_QCAPS, BNXT_USE_CHIMP_MB);
850 req.fid = rte_cpu_to_le_16(0xffff);
852 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
857 bp->max_rsscos_ctx = rte_le_to_cpu_16(resp->max_rsscos_ctx);
858 bp->max_cp_rings = rte_le_to_cpu_16(resp->max_cmpl_rings);
859 bp->max_tx_rings = rte_le_to_cpu_16(resp->max_tx_rings);
860 bp->max_rx_rings = rte_le_to_cpu_16(resp->max_rx_rings);
861 bp->max_ring_grps = rte_le_to_cpu_32(resp->max_hw_ring_grps);
862 /* func_resource_qcaps does not return max_rx_em_flows.
863 * So use the value provided by func_qcaps.
865 bp->max_l2_ctx = rte_le_to_cpu_16(resp->max_l2_ctxs);
866 if (!BNXT_CHIP_THOR(bp))
867 bp->max_l2_ctx += bp->max_rx_em_flows;
868 bp->max_vnics = rte_le_to_cpu_16(resp->max_vnics);
869 bp->max_stat_ctx = rte_le_to_cpu_16(resp->max_stat_ctx);
871 bp->max_nq_rings = rte_le_to_cpu_16(resp->max_msix);
872 bp->vf_resv_strategy = rte_le_to_cpu_16(resp->vf_reservation_strategy);
873 if (bp->vf_resv_strategy >
874 HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESV_STRATEGY_MINIMAL_STATIC)
875 bp->vf_resv_strategy =
876 HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESERVATION_STRATEGY_MAXIMAL;
882 int bnxt_hwrm_ver_get(struct bnxt *bp)
885 struct hwrm_ver_get_input req = {.req_type = 0 };
886 struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr;
888 uint16_t max_resp_len;
889 char type[RTE_MEMZONE_NAMESIZE];
890 uint32_t dev_caps_cfg;
892 bp->max_req_len = HWRM_MAX_REQ_LEN;
893 HWRM_PREP(req, VER_GET, BNXT_USE_CHIMP_MB);
895 req.hwrm_intf_maj = HWRM_VERSION_MAJOR;
896 req.hwrm_intf_min = HWRM_VERSION_MINOR;
897 req.hwrm_intf_upd = HWRM_VERSION_UPDATE;
899 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
901 if (bp->flags & BNXT_FLAG_FW_RESET)
902 HWRM_CHECK_RESULT_SILENT();
906 PMD_DRV_LOG(INFO, "%d.%d.%d:%d.%d.%d\n",
907 resp->hwrm_intf_maj_8b, resp->hwrm_intf_min_8b,
908 resp->hwrm_intf_upd_8b, resp->hwrm_fw_maj_8b,
909 resp->hwrm_fw_min_8b, resp->hwrm_fw_bld_8b);
910 bp->fw_ver = (resp->hwrm_fw_maj_8b << 24) |
911 (resp->hwrm_fw_min_8b << 16) |
912 (resp->hwrm_fw_bld_8b << 8) |
913 resp->hwrm_fw_rsvd_8b;
914 PMD_DRV_LOG(INFO, "Driver HWRM version: %d.%d.%d\n",
915 HWRM_VERSION_MAJOR, HWRM_VERSION_MINOR, HWRM_VERSION_UPDATE);
917 fw_version = resp->hwrm_intf_maj_8b << 16;
918 fw_version |= resp->hwrm_intf_min_8b << 8;
919 fw_version |= resp->hwrm_intf_upd_8b;
920 bp->hwrm_spec_code = fw_version;
922 if (resp->hwrm_intf_maj_8b != HWRM_VERSION_MAJOR) {
923 PMD_DRV_LOG(ERR, "Unsupported firmware API version\n");
928 if (bp->max_req_len > resp->max_req_win_len) {
929 PMD_DRV_LOG(ERR, "Unsupported request length\n");
932 bp->max_req_len = rte_le_to_cpu_16(resp->max_req_win_len);
933 bp->hwrm_max_ext_req_len = rte_le_to_cpu_16(resp->max_ext_req_len);
934 if (bp->hwrm_max_ext_req_len < HWRM_MAX_REQ_LEN)
935 bp->hwrm_max_ext_req_len = HWRM_MAX_REQ_LEN;
937 max_resp_len = rte_le_to_cpu_16(resp->max_resp_len);
938 dev_caps_cfg = rte_le_to_cpu_32(resp->dev_caps_cfg);
940 if (bp->max_resp_len != max_resp_len) {
941 sprintf(type, "bnxt_hwrm_%04x:%02x:%02x:%02x",
942 bp->pdev->addr.domain, bp->pdev->addr.bus,
943 bp->pdev->addr.devid, bp->pdev->addr.function);
945 rte_free(bp->hwrm_cmd_resp_addr);
947 bp->hwrm_cmd_resp_addr = rte_malloc(type, max_resp_len, 0);
948 if (bp->hwrm_cmd_resp_addr == NULL) {
952 rte_mem_lock_page(bp->hwrm_cmd_resp_addr);
953 bp->hwrm_cmd_resp_dma_addr =
954 rte_mem_virt2iova(bp->hwrm_cmd_resp_addr);
955 if (bp->hwrm_cmd_resp_dma_addr == RTE_BAD_IOVA) {
957 "Unable to map response buffer to physical memory.\n");
961 bp->max_resp_len = max_resp_len;
965 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
967 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_REQUIRED)) {
968 PMD_DRV_LOG(DEBUG, "Short command supported\n");
969 bp->flags |= BNXT_FLAG_SHORT_CMD;
973 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
975 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_REQUIRED)) ||
976 bp->hwrm_max_ext_req_len > HWRM_MAX_REQ_LEN) {
977 sprintf(type, "bnxt_hwrm_short_%04x:%02x:%02x:%02x",
978 bp->pdev->addr.domain, bp->pdev->addr.bus,
979 bp->pdev->addr.devid, bp->pdev->addr.function);
981 rte_free(bp->hwrm_short_cmd_req_addr);
983 bp->hwrm_short_cmd_req_addr =
984 rte_malloc(type, bp->hwrm_max_ext_req_len, 0);
985 if (bp->hwrm_short_cmd_req_addr == NULL) {
989 rte_mem_lock_page(bp->hwrm_short_cmd_req_addr);
990 bp->hwrm_short_cmd_req_dma_addr =
991 rte_mem_virt2iova(bp->hwrm_short_cmd_req_addr);
992 if (bp->hwrm_short_cmd_req_dma_addr == RTE_BAD_IOVA) {
993 rte_free(bp->hwrm_short_cmd_req_addr);
995 "Unable to map buffer to physical memory.\n");
1001 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_KONG_MB_CHNL_SUPPORTED) {
1002 bp->flags |= BNXT_FLAG_KONG_MB_EN;
1003 PMD_DRV_LOG(DEBUG, "Kong mailbox channel enabled\n");
1006 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_TRUSTED_VF_SUPPORTED)
1007 PMD_DRV_LOG(DEBUG, "FW supports Trusted VFs\n");
1014 int bnxt_hwrm_func_driver_unregister(struct bnxt *bp, uint32_t flags)
1017 struct hwrm_func_drv_unrgtr_input req = {.req_type = 0 };
1018 struct hwrm_func_drv_unrgtr_output *resp = bp->hwrm_cmd_resp_addr;
1020 if (!(bp->flags & BNXT_FLAG_REGISTERED))
1023 HWRM_PREP(req, FUNC_DRV_UNRGTR, BNXT_USE_CHIMP_MB);
1026 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1028 HWRM_CHECK_RESULT();
1034 static int bnxt_hwrm_port_phy_cfg(struct bnxt *bp, struct bnxt_link_info *conf)
1037 struct hwrm_port_phy_cfg_input req = {0};
1038 struct hwrm_port_phy_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1039 uint32_t enables = 0;
1041 HWRM_PREP(req, PORT_PHY_CFG, BNXT_USE_CHIMP_MB);
1043 if (conf->link_up) {
1044 /* Setting Fixed Speed. But AutoNeg is ON, So disable it */
1045 if (bp->link_info.auto_mode && conf->link_speed) {
1046 req.auto_mode = HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_NONE;
1047 PMD_DRV_LOG(DEBUG, "Disabling AutoNeg\n");
1050 req.flags = rte_cpu_to_le_32(conf->phy_flags);
1051 req.force_link_speed = rte_cpu_to_le_16(conf->link_speed);
1052 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_MODE;
1054 * Note, ChiMP FW 20.2.1 and 20.2.2 return an error when we set
1055 * any auto mode, even "none".
1057 if (!conf->link_speed) {
1058 /* No speeds specified. Enable AutoNeg - all speeds */
1060 HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_ALL_SPEEDS;
1062 /* AutoNeg - Advertise speeds specified. */
1063 if (conf->auto_link_speed_mask &&
1064 !(conf->phy_flags & HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE)) {
1066 HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_SPEED_MASK;
1067 req.auto_link_speed_mask =
1068 conf->auto_link_speed_mask;
1070 HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_LINK_SPEED_MASK;
1073 req.auto_duplex = conf->duplex;
1074 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_DUPLEX;
1075 req.auto_pause = conf->auto_pause;
1076 req.force_pause = conf->force_pause;
1077 /* Set force_pause if there is no auto or if there is a force */
1078 if (req.auto_pause && !req.force_pause)
1079 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_PAUSE;
1081 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_FORCE_PAUSE;
1083 req.enables = rte_cpu_to_le_32(enables);
1086 rte_cpu_to_le_32(HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE_LINK_DWN);
1087 PMD_DRV_LOG(INFO, "Force Link Down\n");
1090 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1092 HWRM_CHECK_RESULT();
1098 static int bnxt_hwrm_port_phy_qcfg(struct bnxt *bp,
1099 struct bnxt_link_info *link_info)
1102 struct hwrm_port_phy_qcfg_input req = {0};
1103 struct hwrm_port_phy_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
1105 HWRM_PREP(req, PORT_PHY_QCFG, BNXT_USE_CHIMP_MB);
1107 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1109 HWRM_CHECK_RESULT();
1111 link_info->phy_link_status = resp->link;
1112 link_info->link_up =
1113 (link_info->phy_link_status ==
1114 HWRM_PORT_PHY_QCFG_OUTPUT_LINK_LINK) ? 1 : 0;
1115 link_info->link_speed = rte_le_to_cpu_16(resp->link_speed);
1116 link_info->duplex = resp->duplex_cfg;
1117 link_info->pause = resp->pause;
1118 link_info->auto_pause = resp->auto_pause;
1119 link_info->force_pause = resp->force_pause;
1120 link_info->auto_mode = resp->auto_mode;
1121 link_info->phy_type = resp->phy_type;
1122 link_info->media_type = resp->media_type;
1124 link_info->support_speeds = rte_le_to_cpu_16(resp->support_speeds);
1125 link_info->auto_link_speed = rte_le_to_cpu_16(resp->auto_link_speed);
1126 link_info->preemphasis = rte_le_to_cpu_32(resp->preemphasis);
1127 link_info->force_link_speed = rte_le_to_cpu_16(resp->force_link_speed);
1128 link_info->phy_ver[0] = resp->phy_maj;
1129 link_info->phy_ver[1] = resp->phy_min;
1130 link_info->phy_ver[2] = resp->phy_bld;
1134 PMD_DRV_LOG(DEBUG, "Link Speed %d\n", link_info->link_speed);
1135 PMD_DRV_LOG(DEBUG, "Auto Mode %d\n", link_info->auto_mode);
1136 PMD_DRV_LOG(DEBUG, "Support Speeds %x\n", link_info->support_speeds);
1137 PMD_DRV_LOG(DEBUG, "Auto Link Speed %x\n", link_info->auto_link_speed);
1138 PMD_DRV_LOG(DEBUG, "Auto Link Speed Mask %x\n",
1139 link_info->auto_link_speed_mask);
1140 PMD_DRV_LOG(DEBUG, "Forced Link Speed %x\n",
1141 link_info->force_link_speed);
1146 int bnxt_hwrm_queue_qportcfg(struct bnxt *bp)
1149 struct hwrm_queue_qportcfg_input req = {.req_type = 0 };
1150 struct hwrm_queue_qportcfg_output *resp = bp->hwrm_cmd_resp_addr;
1153 HWRM_PREP(req, QUEUE_QPORTCFG, BNXT_USE_CHIMP_MB);
1155 req.flags = HWRM_QUEUE_QPORTCFG_INPUT_FLAGS_PATH_TX;
1156 /* HWRM Version >= 1.9.1 */
1157 if (bp->hwrm_spec_code >= HWRM_VERSION_1_9_1)
1159 HWRM_QUEUE_QPORTCFG_INPUT_DRV_QMAP_CAP_ENABLED;
1160 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1162 HWRM_CHECK_RESULT();
1164 #define GET_QUEUE_INFO(x) \
1165 bp->cos_queue[x].id = resp->queue_id##x; \
1166 bp->cos_queue[x].profile = resp->queue_id##x##_service_profile
1179 if (bp->hwrm_spec_code < HWRM_VERSION_1_9_1) {
1180 bp->tx_cosq_id = bp->cos_queue[0].id;
1182 /* iterate and find the COSq profile to use for Tx */
1183 for (i = 0; i < BNXT_COS_QUEUE_COUNT; i++) {
1184 if (bp->cos_queue[i].profile ==
1185 HWRM_QUEUE_SERVICE_PROFILE_LOSSY) {
1186 bp->tx_cosq_id = bp->cos_queue[i].id;
1192 bp->max_tc = resp->max_configurable_queues;
1193 bp->max_lltc = resp->max_configurable_lossless_queues;
1194 if (bp->max_tc > BNXT_MAX_QUEUE)
1195 bp->max_tc = BNXT_MAX_QUEUE;
1196 bp->max_q = bp->max_tc;
1198 PMD_DRV_LOG(DEBUG, "Tx Cos Queue to use: %d\n", bp->tx_cosq_id);
1203 int bnxt_hwrm_ring_alloc(struct bnxt *bp,
1204 struct bnxt_ring *ring,
1205 uint32_t ring_type, uint32_t map_index,
1206 uint32_t stats_ctx_id, uint32_t cmpl_ring_id)
1209 uint32_t enables = 0;
1210 struct hwrm_ring_alloc_input req = {.req_type = 0 };
1211 struct hwrm_ring_alloc_output *resp = bp->hwrm_cmd_resp_addr;
1212 struct rte_mempool *mb_pool;
1213 uint16_t rx_buf_size;
1215 HWRM_PREP(req, RING_ALLOC, BNXT_USE_CHIMP_MB);
1217 req.page_tbl_addr = rte_cpu_to_le_64(ring->bd_dma);
1218 req.fbo = rte_cpu_to_le_32(0);
1219 /* Association of ring index with doorbell index */
1220 req.logical_id = rte_cpu_to_le_16(map_index);
1221 req.length = rte_cpu_to_le_32(ring->ring_size);
1223 switch (ring_type) {
1224 case HWRM_RING_ALLOC_INPUT_RING_TYPE_TX:
1225 req.ring_type = ring_type;
1226 req.cmpl_ring_id = rte_cpu_to_le_16(cmpl_ring_id);
1227 req.stat_ctx_id = rte_cpu_to_le_32(stats_ctx_id);
1228 req.queue_id = rte_cpu_to_le_16(bp->tx_cosq_id);
1229 if (stats_ctx_id != INVALID_STATS_CTX_ID)
1231 HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID;
1233 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX:
1234 req.ring_type = ring_type;
1235 req.cmpl_ring_id = rte_cpu_to_le_16(cmpl_ring_id);
1236 req.stat_ctx_id = rte_cpu_to_le_32(stats_ctx_id);
1237 if (BNXT_CHIP_THOR(bp)) {
1238 mb_pool = bp->rx_queues[0]->mb_pool;
1239 rx_buf_size = rte_pktmbuf_data_room_size(mb_pool) -
1240 RTE_PKTMBUF_HEADROOM;
1241 rx_buf_size = RTE_MIN(BNXT_MAX_PKT_LEN, rx_buf_size);
1242 req.rx_buf_size = rte_cpu_to_le_16(rx_buf_size);
1244 HWRM_RING_ALLOC_INPUT_ENABLES_RX_BUF_SIZE_VALID;
1246 if (stats_ctx_id != INVALID_STATS_CTX_ID)
1248 HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID;
1250 case HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL:
1251 req.ring_type = ring_type;
1252 if (BNXT_HAS_NQ(bp)) {
1253 /* Association of cp ring with nq */
1254 req.nq_ring_id = rte_cpu_to_le_16(cmpl_ring_id);
1256 HWRM_RING_ALLOC_INPUT_ENABLES_NQ_RING_ID_VALID;
1258 req.int_mode = HWRM_RING_ALLOC_INPUT_INT_MODE_MSIX;
1260 case HWRM_RING_ALLOC_INPUT_RING_TYPE_NQ:
1261 req.ring_type = ring_type;
1262 req.page_size = BNXT_PAGE_SHFT;
1263 req.int_mode = HWRM_RING_ALLOC_INPUT_INT_MODE_MSIX;
1265 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX_AGG:
1266 req.ring_type = ring_type;
1267 req.rx_ring_id = rte_cpu_to_le_16(ring->fw_rx_ring_id);
1269 mb_pool = bp->rx_queues[0]->mb_pool;
1270 rx_buf_size = rte_pktmbuf_data_room_size(mb_pool) -
1271 RTE_PKTMBUF_HEADROOM;
1272 rx_buf_size = RTE_MIN(BNXT_MAX_PKT_LEN, rx_buf_size);
1273 req.rx_buf_size = rte_cpu_to_le_16(rx_buf_size);
1275 req.stat_ctx_id = rte_cpu_to_le_32(stats_ctx_id);
1276 enables |= HWRM_RING_ALLOC_INPUT_ENABLES_RX_RING_ID_VALID |
1277 HWRM_RING_ALLOC_INPUT_ENABLES_RX_BUF_SIZE_VALID |
1278 HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID;
1281 PMD_DRV_LOG(ERR, "hwrm alloc invalid ring type %d\n",
1286 req.enables = rte_cpu_to_le_32(enables);
1288 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1290 if (rc || resp->error_code) {
1291 if (rc == 0 && resp->error_code)
1292 rc = rte_le_to_cpu_16(resp->error_code);
1293 switch (ring_type) {
1294 case HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL:
1296 "hwrm_ring_alloc cp failed. rc:%d\n", rc);
1299 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX:
1301 "hwrm_ring_alloc rx failed. rc:%d\n", rc);
1304 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX_AGG:
1306 "hwrm_ring_alloc rx agg failed. rc:%d\n",
1310 case HWRM_RING_ALLOC_INPUT_RING_TYPE_TX:
1312 "hwrm_ring_alloc tx failed. rc:%d\n", rc);
1315 case HWRM_RING_ALLOC_INPUT_RING_TYPE_NQ:
1317 "hwrm_ring_alloc nq failed. rc:%d\n", rc);
1321 PMD_DRV_LOG(ERR, "Invalid ring. rc:%d\n", rc);
1327 ring->fw_ring_id = rte_le_to_cpu_16(resp->ring_id);
1332 int bnxt_hwrm_ring_free(struct bnxt *bp,
1333 struct bnxt_ring *ring, uint32_t ring_type)
1336 struct hwrm_ring_free_input req = {.req_type = 0 };
1337 struct hwrm_ring_free_output *resp = bp->hwrm_cmd_resp_addr;
1339 HWRM_PREP(req, RING_FREE, BNXT_USE_CHIMP_MB);
1341 req.ring_type = ring_type;
1342 req.ring_id = rte_cpu_to_le_16(ring->fw_ring_id);
1344 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1346 if (rc || resp->error_code) {
1347 if (rc == 0 && resp->error_code)
1348 rc = rte_le_to_cpu_16(resp->error_code);
1351 switch (ring_type) {
1352 case HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL:
1353 PMD_DRV_LOG(ERR, "hwrm_ring_free cp failed. rc:%d\n",
1356 case HWRM_RING_FREE_INPUT_RING_TYPE_RX:
1357 PMD_DRV_LOG(ERR, "hwrm_ring_free rx failed. rc:%d\n",
1360 case HWRM_RING_FREE_INPUT_RING_TYPE_TX:
1361 PMD_DRV_LOG(ERR, "hwrm_ring_free tx failed. rc:%d\n",
1364 case HWRM_RING_FREE_INPUT_RING_TYPE_NQ:
1366 "hwrm_ring_free nq failed. rc:%d\n", rc);
1368 case HWRM_RING_FREE_INPUT_RING_TYPE_RX_AGG:
1370 "hwrm_ring_free agg failed. rc:%d\n", rc);
1373 PMD_DRV_LOG(ERR, "Invalid ring, rc:%d\n", rc);
1381 int bnxt_hwrm_ring_grp_alloc(struct bnxt *bp, unsigned int idx)
1384 struct hwrm_ring_grp_alloc_input req = {.req_type = 0 };
1385 struct hwrm_ring_grp_alloc_output *resp = bp->hwrm_cmd_resp_addr;
1387 HWRM_PREP(req, RING_GRP_ALLOC, BNXT_USE_CHIMP_MB);
1389 req.cr = rte_cpu_to_le_16(bp->grp_info[idx].cp_fw_ring_id);
1390 req.rr = rte_cpu_to_le_16(bp->grp_info[idx].rx_fw_ring_id);
1391 req.ar = rte_cpu_to_le_16(bp->grp_info[idx].ag_fw_ring_id);
1392 req.sc = rte_cpu_to_le_16(bp->grp_info[idx].fw_stats_ctx);
1394 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1396 HWRM_CHECK_RESULT();
1398 bp->grp_info[idx].fw_grp_id =
1399 rte_le_to_cpu_16(resp->ring_group_id);
1406 int bnxt_hwrm_ring_grp_free(struct bnxt *bp, unsigned int idx)
1409 struct hwrm_ring_grp_free_input req = {.req_type = 0 };
1410 struct hwrm_ring_grp_free_output *resp = bp->hwrm_cmd_resp_addr;
1412 HWRM_PREP(req, RING_GRP_FREE, BNXT_USE_CHIMP_MB);
1414 req.ring_group_id = rte_cpu_to_le_16(bp->grp_info[idx].fw_grp_id);
1416 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1418 HWRM_CHECK_RESULT();
1421 bp->grp_info[idx].fw_grp_id = INVALID_HW_RING_ID;
1425 int bnxt_hwrm_stat_clear(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
1428 struct hwrm_stat_ctx_clr_stats_input req = {.req_type = 0 };
1429 struct hwrm_stat_ctx_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
1431 if (cpr->hw_stats_ctx_id == (uint32_t)HWRM_NA_SIGNATURE)
1434 HWRM_PREP(req, STAT_CTX_CLR_STATS, BNXT_USE_CHIMP_MB);
1436 req.stat_ctx_id = rte_cpu_to_le_32(cpr->hw_stats_ctx_id);
1438 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1440 HWRM_CHECK_RESULT();
1446 int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
1447 unsigned int idx __rte_unused)
1450 struct hwrm_stat_ctx_alloc_input req = {.req_type = 0 };
1451 struct hwrm_stat_ctx_alloc_output *resp = bp->hwrm_cmd_resp_addr;
1453 HWRM_PREP(req, STAT_CTX_ALLOC, BNXT_USE_CHIMP_MB);
1455 req.update_period_ms = rte_cpu_to_le_32(0);
1457 req.stats_dma_addr =
1458 rte_cpu_to_le_64(cpr->hw_stats_map);
1460 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1462 HWRM_CHECK_RESULT();
1464 cpr->hw_stats_ctx_id = rte_le_to_cpu_32(resp->stat_ctx_id);
1471 int bnxt_hwrm_stat_ctx_free(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
1472 unsigned int idx __rte_unused)
1475 struct hwrm_stat_ctx_free_input req = {.req_type = 0 };
1476 struct hwrm_stat_ctx_free_output *resp = bp->hwrm_cmd_resp_addr;
1478 HWRM_PREP(req, STAT_CTX_FREE, BNXT_USE_CHIMP_MB);
1480 req.stat_ctx_id = rte_cpu_to_le_32(cpr->hw_stats_ctx_id);
1482 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1484 HWRM_CHECK_RESULT();
1490 int bnxt_hwrm_vnic_alloc(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1493 struct hwrm_vnic_alloc_input req = { 0 };
1494 struct hwrm_vnic_alloc_output *resp = bp->hwrm_cmd_resp_addr;
1496 if (!BNXT_HAS_RING_GRPS(bp))
1497 goto skip_ring_grps;
1499 /* map ring groups to this vnic */
1500 PMD_DRV_LOG(DEBUG, "Alloc VNIC. Start %x, End %x\n",
1501 vnic->start_grp_id, vnic->end_grp_id);
1502 for (i = vnic->start_grp_id, j = 0; i < vnic->end_grp_id; i++, j++)
1503 vnic->fw_grp_ids[j] = bp->grp_info[i].fw_grp_id;
1505 vnic->dflt_ring_grp = bp->grp_info[vnic->start_grp_id].fw_grp_id;
1506 vnic->rss_rule = (uint16_t)HWRM_NA_SIGNATURE;
1507 vnic->cos_rule = (uint16_t)HWRM_NA_SIGNATURE;
1508 vnic->lb_rule = (uint16_t)HWRM_NA_SIGNATURE;
1511 vnic->mru = bp->eth_dev->data->mtu + RTE_ETHER_HDR_LEN +
1512 RTE_ETHER_CRC_LEN + VLAN_TAG_SIZE;
1513 HWRM_PREP(req, VNIC_ALLOC, BNXT_USE_CHIMP_MB);
1515 if (vnic->func_default)
1517 rte_cpu_to_le_32(HWRM_VNIC_ALLOC_INPUT_FLAGS_DEFAULT);
1518 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1520 HWRM_CHECK_RESULT();
1522 vnic->fw_vnic_id = rte_le_to_cpu_16(resp->vnic_id);
1524 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
1528 static int bnxt_hwrm_vnic_plcmodes_qcfg(struct bnxt *bp,
1529 struct bnxt_vnic_info *vnic,
1530 struct bnxt_plcmodes_cfg *pmode)
1533 struct hwrm_vnic_plcmodes_qcfg_input req = {.req_type = 0 };
1534 struct hwrm_vnic_plcmodes_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
1536 HWRM_PREP(req, VNIC_PLCMODES_QCFG, BNXT_USE_CHIMP_MB);
1538 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1540 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1542 HWRM_CHECK_RESULT();
1544 pmode->flags = rte_le_to_cpu_32(resp->flags);
1545 /* dflt_vnic bit doesn't exist in the _cfg command */
1546 pmode->flags &= ~(HWRM_VNIC_PLCMODES_QCFG_OUTPUT_FLAGS_DFLT_VNIC);
1547 pmode->jumbo_thresh = rte_le_to_cpu_16(resp->jumbo_thresh);
1548 pmode->hds_offset = rte_le_to_cpu_16(resp->hds_offset);
1549 pmode->hds_threshold = rte_le_to_cpu_16(resp->hds_threshold);
1556 static int bnxt_hwrm_vnic_plcmodes_cfg(struct bnxt *bp,
1557 struct bnxt_vnic_info *vnic,
1558 struct bnxt_plcmodes_cfg *pmode)
1561 struct hwrm_vnic_plcmodes_cfg_input req = {.req_type = 0 };
1562 struct hwrm_vnic_plcmodes_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1564 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1565 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
1569 HWRM_PREP(req, VNIC_PLCMODES_CFG, BNXT_USE_CHIMP_MB);
1571 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1572 req.flags = rte_cpu_to_le_32(pmode->flags);
1573 req.jumbo_thresh = rte_cpu_to_le_16(pmode->jumbo_thresh);
1574 req.hds_offset = rte_cpu_to_le_16(pmode->hds_offset);
1575 req.hds_threshold = rte_cpu_to_le_16(pmode->hds_threshold);
1576 req.enables = rte_cpu_to_le_32(
1577 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_HDS_THRESHOLD_VALID |
1578 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_HDS_OFFSET_VALID |
1579 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_JUMBO_THRESH_VALID
1582 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1584 HWRM_CHECK_RESULT();
1590 int bnxt_hwrm_vnic_cfg(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1593 struct hwrm_vnic_cfg_input req = {.req_type = 0 };
1594 struct hwrm_vnic_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1595 struct bnxt_plcmodes_cfg pmodes = { 0 };
1596 uint32_t ctx_enable_flag = 0;
1597 uint32_t enables = 0;
1599 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1600 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
1604 rc = bnxt_hwrm_vnic_plcmodes_qcfg(bp, vnic, &pmodes);
1608 HWRM_PREP(req, VNIC_CFG, BNXT_USE_CHIMP_MB);
1610 if (BNXT_CHIP_THOR(bp)) {
1611 struct bnxt_rx_queue *rxq = bp->eth_dev->data->rx_queues[0];
1612 struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
1613 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
1615 req.default_rx_ring_id =
1616 rte_cpu_to_le_16(rxr->rx_ring_struct->fw_ring_id);
1617 req.default_cmpl_ring_id =
1618 rte_cpu_to_le_16(cpr->cp_ring_struct->fw_ring_id);
1619 enables = HWRM_VNIC_CFG_INPUT_ENABLES_DEFAULT_RX_RING_ID |
1620 HWRM_VNIC_CFG_INPUT_ENABLES_DEFAULT_CMPL_RING_ID;
1624 /* Only RSS support for now TBD: COS & LB */
1625 enables = HWRM_VNIC_CFG_INPUT_ENABLES_DFLT_RING_GRP;
1626 if (vnic->lb_rule != 0xffff)
1627 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_LB_RULE;
1628 if (vnic->cos_rule != 0xffff)
1629 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_COS_RULE;
1630 if (vnic->rss_rule != (uint16_t)HWRM_NA_SIGNATURE) {
1631 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_MRU;
1632 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_RSS_RULE;
1634 enables |= ctx_enable_flag;
1635 req.dflt_ring_grp = rte_cpu_to_le_16(vnic->dflt_ring_grp);
1636 req.rss_rule = rte_cpu_to_le_16(vnic->rss_rule);
1637 req.cos_rule = rte_cpu_to_le_16(vnic->cos_rule);
1638 req.lb_rule = rte_cpu_to_le_16(vnic->lb_rule);
1641 req.enables = rte_cpu_to_le_32(enables);
1642 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1643 req.mru = rte_cpu_to_le_16(vnic->mru);
1644 /* Configure default VNIC only once. */
1645 if (vnic->func_default && !(bp->flags & BNXT_FLAG_DFLT_VNIC_SET)) {
1647 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_DEFAULT);
1648 bp->flags |= BNXT_FLAG_DFLT_VNIC_SET;
1650 if (vnic->vlan_strip)
1652 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_VLAN_STRIP_MODE);
1655 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_BD_STALL_MODE);
1656 if (vnic->roce_dual)
1657 req.flags |= rte_cpu_to_le_32(
1658 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_DUAL_VNIC_MODE);
1659 if (vnic->roce_only)
1660 req.flags |= rte_cpu_to_le_32(
1661 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_ONLY_VNIC_MODE);
1662 if (vnic->rss_dflt_cr)
1663 req.flags |= rte_cpu_to_le_32(
1664 HWRM_VNIC_QCFG_OUTPUT_FLAGS_RSS_DFLT_CR_MODE);
1666 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1668 HWRM_CHECK_RESULT();
1671 rc = bnxt_hwrm_vnic_plcmodes_cfg(bp, vnic, &pmodes);
1676 int bnxt_hwrm_vnic_qcfg(struct bnxt *bp, struct bnxt_vnic_info *vnic,
1680 struct hwrm_vnic_qcfg_input req = {.req_type = 0 };
1681 struct hwrm_vnic_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
1683 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1684 PMD_DRV_LOG(DEBUG, "VNIC QCFG ID %d\n", vnic->fw_vnic_id);
1687 HWRM_PREP(req, VNIC_QCFG, BNXT_USE_CHIMP_MB);
1690 rte_cpu_to_le_32(HWRM_VNIC_QCFG_INPUT_ENABLES_VF_ID_VALID);
1691 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1692 req.vf_id = rte_cpu_to_le_16(fw_vf_id);
1694 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1696 HWRM_CHECK_RESULT();
1698 vnic->dflt_ring_grp = rte_le_to_cpu_16(resp->dflt_ring_grp);
1699 vnic->rss_rule = rte_le_to_cpu_16(resp->rss_rule);
1700 vnic->cos_rule = rte_le_to_cpu_16(resp->cos_rule);
1701 vnic->lb_rule = rte_le_to_cpu_16(resp->lb_rule);
1702 vnic->mru = rte_le_to_cpu_16(resp->mru);
1703 vnic->func_default = rte_le_to_cpu_32(
1704 resp->flags) & HWRM_VNIC_QCFG_OUTPUT_FLAGS_DEFAULT;
1705 vnic->vlan_strip = rte_le_to_cpu_32(resp->flags) &
1706 HWRM_VNIC_QCFG_OUTPUT_FLAGS_VLAN_STRIP_MODE;
1707 vnic->bd_stall = rte_le_to_cpu_32(resp->flags) &
1708 HWRM_VNIC_QCFG_OUTPUT_FLAGS_BD_STALL_MODE;
1709 vnic->roce_dual = rte_le_to_cpu_32(resp->flags) &
1710 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_DUAL_VNIC_MODE;
1711 vnic->roce_only = rte_le_to_cpu_32(resp->flags) &
1712 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_ONLY_VNIC_MODE;
1713 vnic->rss_dflt_cr = rte_le_to_cpu_32(resp->flags) &
1714 HWRM_VNIC_QCFG_OUTPUT_FLAGS_RSS_DFLT_CR_MODE;
1721 int bnxt_hwrm_vnic_ctx_alloc(struct bnxt *bp,
1722 struct bnxt_vnic_info *vnic, uint16_t ctx_idx)
1726 struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req = {.req_type = 0 };
1727 struct hwrm_vnic_rss_cos_lb_ctx_alloc_output *resp =
1728 bp->hwrm_cmd_resp_addr;
1730 HWRM_PREP(req, VNIC_RSS_COS_LB_CTX_ALLOC, BNXT_USE_CHIMP_MB);
1732 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1733 HWRM_CHECK_RESULT();
1735 ctx_id = rte_le_to_cpu_16(resp->rss_cos_lb_ctx_id);
1736 if (!BNXT_HAS_RING_GRPS(bp))
1737 vnic->fw_grp_ids[ctx_idx] = ctx_id;
1738 else if (ctx_idx == 0)
1739 vnic->rss_rule = ctx_id;
1746 int bnxt_hwrm_vnic_ctx_free(struct bnxt *bp,
1747 struct bnxt_vnic_info *vnic, uint16_t ctx_idx)
1750 struct hwrm_vnic_rss_cos_lb_ctx_free_input req = {.req_type = 0 };
1751 struct hwrm_vnic_rss_cos_lb_ctx_free_output *resp =
1752 bp->hwrm_cmd_resp_addr;
1754 if (ctx_idx == (uint16_t)HWRM_NA_SIGNATURE) {
1755 PMD_DRV_LOG(DEBUG, "VNIC RSS Rule %x\n", vnic->rss_rule);
1758 HWRM_PREP(req, VNIC_RSS_COS_LB_CTX_FREE, BNXT_USE_CHIMP_MB);
1760 req.rss_cos_lb_ctx_id = rte_cpu_to_le_16(ctx_idx);
1762 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1764 HWRM_CHECK_RESULT();
1770 int bnxt_hwrm_vnic_free(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1773 struct hwrm_vnic_free_input req = {.req_type = 0 };
1774 struct hwrm_vnic_free_output *resp = bp->hwrm_cmd_resp_addr;
1776 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1777 PMD_DRV_LOG(DEBUG, "VNIC FREE ID %x\n", vnic->fw_vnic_id);
1781 HWRM_PREP(req, VNIC_FREE, BNXT_USE_CHIMP_MB);
1783 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1785 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1787 HWRM_CHECK_RESULT();
1790 vnic->fw_vnic_id = INVALID_HW_RING_ID;
1791 /* Configure default VNIC again if necessary. */
1792 if (vnic->func_default && (bp->flags & BNXT_FLAG_DFLT_VNIC_SET))
1793 bp->flags &= ~BNXT_FLAG_DFLT_VNIC_SET;
1799 bnxt_hwrm_vnic_rss_cfg_thor(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1803 int nr_ctxs = vnic->num_lb_ctxts;
1804 struct hwrm_vnic_rss_cfg_input req = {.req_type = 0 };
1805 struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1807 for (i = 0; i < nr_ctxs; i++) {
1808 HWRM_PREP(req, VNIC_RSS_CFG, BNXT_USE_CHIMP_MB);
1810 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1811 req.hash_type = rte_cpu_to_le_32(vnic->hash_type);
1812 req.hash_mode_flags = vnic->hash_mode;
1814 req.hash_key_tbl_addr =
1815 rte_cpu_to_le_64(vnic->rss_hash_key_dma_addr);
1817 req.ring_grp_tbl_addr =
1818 rte_cpu_to_le_64(vnic->rss_table_dma_addr +
1819 i * HW_HASH_INDEX_SIZE);
1820 req.ring_table_pair_index = i;
1821 req.rss_ctx_idx = rte_cpu_to_le_16(vnic->fw_grp_ids[i]);
1823 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req),
1826 HWRM_CHECK_RESULT();
1833 int bnxt_hwrm_vnic_rss_cfg(struct bnxt *bp,
1834 struct bnxt_vnic_info *vnic)
1837 struct hwrm_vnic_rss_cfg_input req = {.req_type = 0 };
1838 struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1840 if (!vnic->rss_table)
1843 if (BNXT_CHIP_THOR(bp))
1844 return bnxt_hwrm_vnic_rss_cfg_thor(bp, vnic);
1846 HWRM_PREP(req, VNIC_RSS_CFG, BNXT_USE_CHIMP_MB);
1848 req.hash_type = rte_cpu_to_le_32(vnic->hash_type);
1849 req.hash_mode_flags = vnic->hash_mode;
1851 req.ring_grp_tbl_addr =
1852 rte_cpu_to_le_64(vnic->rss_table_dma_addr);
1853 req.hash_key_tbl_addr =
1854 rte_cpu_to_le_64(vnic->rss_hash_key_dma_addr);
1855 req.rss_ctx_idx = rte_cpu_to_le_16(vnic->rss_rule);
1856 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1858 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1860 HWRM_CHECK_RESULT();
1866 int bnxt_hwrm_vnic_plcmode_cfg(struct bnxt *bp,
1867 struct bnxt_vnic_info *vnic)
1870 struct hwrm_vnic_plcmodes_cfg_input req = {.req_type = 0 };
1871 struct hwrm_vnic_plcmodes_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1874 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1875 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
1879 HWRM_PREP(req, VNIC_PLCMODES_CFG, BNXT_USE_CHIMP_MB);
1881 req.flags = rte_cpu_to_le_32(
1882 HWRM_VNIC_PLCMODES_CFG_INPUT_FLAGS_JUMBO_PLACEMENT);
1884 req.enables = rte_cpu_to_le_32(
1885 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_JUMBO_THRESH_VALID);
1887 size = rte_pktmbuf_data_room_size(bp->rx_queues[0]->mb_pool);
1888 size -= RTE_PKTMBUF_HEADROOM;
1889 size = RTE_MIN(BNXT_MAX_PKT_LEN, size);
1891 req.jumbo_thresh = rte_cpu_to_le_16(size);
1892 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1894 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1896 HWRM_CHECK_RESULT();
1902 int bnxt_hwrm_vnic_tpa_cfg(struct bnxt *bp,
1903 struct bnxt_vnic_info *vnic, bool enable)
1906 struct hwrm_vnic_tpa_cfg_input req = {.req_type = 0 };
1907 struct hwrm_vnic_tpa_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1909 if (BNXT_CHIP_THOR(bp))
1912 HWRM_PREP(req, VNIC_TPA_CFG, BNXT_USE_CHIMP_MB);
1915 req.enables = rte_cpu_to_le_32(
1916 HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MAX_AGG_SEGS |
1917 HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MAX_AGGS |
1918 HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MIN_AGG_LEN);
1919 req.flags = rte_cpu_to_le_32(
1920 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_TPA |
1921 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_ENCAP_TPA |
1922 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_RSC_WND_UPDATE |
1923 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_GRO |
1924 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_AGG_WITH_ECN |
1925 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_AGG_WITH_SAME_GRE_SEQ);
1926 req.max_agg_segs = rte_cpu_to_le_16(5);
1928 rte_cpu_to_le_16(HWRM_VNIC_TPA_CFG_INPUT_MAX_AGGS_MAX);
1929 req.min_agg_len = rte_cpu_to_le_32(512);
1931 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1933 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1935 HWRM_CHECK_RESULT();
1941 int bnxt_hwrm_func_vf_mac(struct bnxt *bp, uint16_t vf, const uint8_t *mac_addr)
1943 struct hwrm_func_cfg_input req = {0};
1944 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1947 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[vf].func_cfg_flags);
1948 req.enables = rte_cpu_to_le_32(
1949 HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
1950 memcpy(req.dflt_mac_addr, mac_addr, sizeof(req.dflt_mac_addr));
1951 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
1953 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
1955 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1956 HWRM_CHECK_RESULT();
1959 bp->pf.vf_info[vf].random_mac = false;
1964 int bnxt_hwrm_func_qstats_tx_drop(struct bnxt *bp, uint16_t fid,
1968 struct hwrm_func_qstats_input req = {.req_type = 0};
1969 struct hwrm_func_qstats_output *resp = bp->hwrm_cmd_resp_addr;
1971 HWRM_PREP(req, FUNC_QSTATS, BNXT_USE_CHIMP_MB);
1973 req.fid = rte_cpu_to_le_16(fid);
1975 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1977 HWRM_CHECK_RESULT();
1980 *dropped = rte_le_to_cpu_64(resp->tx_drop_pkts);
1987 int bnxt_hwrm_func_qstats(struct bnxt *bp, uint16_t fid,
1988 struct rte_eth_stats *stats)
1991 struct hwrm_func_qstats_input req = {.req_type = 0};
1992 struct hwrm_func_qstats_output *resp = bp->hwrm_cmd_resp_addr;
1994 HWRM_PREP(req, FUNC_QSTATS, BNXT_USE_CHIMP_MB);
1996 req.fid = rte_cpu_to_le_16(fid);
1998 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2000 HWRM_CHECK_RESULT();
2002 stats->ipackets = rte_le_to_cpu_64(resp->rx_ucast_pkts);
2003 stats->ipackets += rte_le_to_cpu_64(resp->rx_mcast_pkts);
2004 stats->ipackets += rte_le_to_cpu_64(resp->rx_bcast_pkts);
2005 stats->ibytes = rte_le_to_cpu_64(resp->rx_ucast_bytes);
2006 stats->ibytes += rte_le_to_cpu_64(resp->rx_mcast_bytes);
2007 stats->ibytes += rte_le_to_cpu_64(resp->rx_bcast_bytes);
2009 stats->opackets = rte_le_to_cpu_64(resp->tx_ucast_pkts);
2010 stats->opackets += rte_le_to_cpu_64(resp->tx_mcast_pkts);
2011 stats->opackets += rte_le_to_cpu_64(resp->tx_bcast_pkts);
2012 stats->obytes = rte_le_to_cpu_64(resp->tx_ucast_bytes);
2013 stats->obytes += rte_le_to_cpu_64(resp->tx_mcast_bytes);
2014 stats->obytes += rte_le_to_cpu_64(resp->tx_bcast_bytes);
2016 stats->imissed = rte_le_to_cpu_64(resp->rx_discard_pkts);
2017 stats->ierrors = rte_le_to_cpu_64(resp->rx_drop_pkts);
2018 stats->oerrors = rte_le_to_cpu_64(resp->tx_discard_pkts);
2025 int bnxt_hwrm_func_clr_stats(struct bnxt *bp, uint16_t fid)
2028 struct hwrm_func_clr_stats_input req = {.req_type = 0};
2029 struct hwrm_func_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
2031 HWRM_PREP(req, FUNC_CLR_STATS, BNXT_USE_CHIMP_MB);
2033 req.fid = rte_cpu_to_le_16(fid);
2035 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2037 HWRM_CHECK_RESULT();
2044 * HWRM utility functions
2047 int bnxt_clear_all_hwrm_stat_ctxs(struct bnxt *bp)
2052 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
2053 struct bnxt_tx_queue *txq;
2054 struct bnxt_rx_queue *rxq;
2055 struct bnxt_cp_ring_info *cpr;
2057 if (i >= bp->rx_cp_nr_rings) {
2058 txq = bp->tx_queues[i - bp->rx_cp_nr_rings];
2061 rxq = bp->rx_queues[i];
2065 rc = bnxt_hwrm_stat_clear(bp, cpr);
2072 int bnxt_free_all_hwrm_stat_ctxs(struct bnxt *bp)
2076 struct bnxt_cp_ring_info *cpr;
2078 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
2080 if (i >= bp->rx_cp_nr_rings) {
2081 cpr = bp->tx_queues[i - bp->rx_cp_nr_rings]->cp_ring;
2083 cpr = bp->rx_queues[i]->cp_ring;
2084 if (BNXT_HAS_RING_GRPS(bp))
2085 bp->grp_info[i].fw_stats_ctx = -1;
2087 if (cpr->hw_stats_ctx_id != HWRM_NA_SIGNATURE) {
2088 rc = bnxt_hwrm_stat_ctx_free(bp, cpr, i);
2089 cpr->hw_stats_ctx_id = HWRM_NA_SIGNATURE;
2097 int bnxt_alloc_all_hwrm_stat_ctxs(struct bnxt *bp)
2102 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
2103 struct bnxt_tx_queue *txq;
2104 struct bnxt_rx_queue *rxq;
2105 struct bnxt_cp_ring_info *cpr;
2107 if (i >= bp->rx_cp_nr_rings) {
2108 txq = bp->tx_queues[i - bp->rx_cp_nr_rings];
2111 rxq = bp->rx_queues[i];
2115 rc = bnxt_hwrm_stat_ctx_alloc(bp, cpr, i);
2123 int bnxt_free_all_hwrm_ring_grps(struct bnxt *bp)
2128 if (!BNXT_HAS_RING_GRPS(bp))
2131 for (idx = 0; idx < bp->rx_cp_nr_rings; idx++) {
2133 if (bp->grp_info[idx].fw_grp_id == INVALID_HW_RING_ID)
2136 rc = bnxt_hwrm_ring_grp_free(bp, idx);
2144 void bnxt_free_nq_ring(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
2146 struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
2148 bnxt_hwrm_ring_free(bp, cp_ring,
2149 HWRM_RING_FREE_INPUT_RING_TYPE_NQ);
2150 cp_ring->fw_ring_id = INVALID_HW_RING_ID;
2151 memset(cpr->cp_desc_ring, 0, cpr->cp_ring_struct->ring_size *
2152 sizeof(*cpr->cp_desc_ring));
2153 cpr->cp_raw_cons = 0;
2157 void bnxt_free_cp_ring(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
2159 struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
2161 bnxt_hwrm_ring_free(bp, cp_ring,
2162 HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL);
2163 cp_ring->fw_ring_id = INVALID_HW_RING_ID;
2164 memset(cpr->cp_desc_ring, 0, cpr->cp_ring_struct->ring_size *
2165 sizeof(*cpr->cp_desc_ring));
2166 cpr->cp_raw_cons = 0;
2170 void bnxt_free_hwrm_rx_ring(struct bnxt *bp, int queue_index)
2172 struct bnxt_rx_queue *rxq = bp->rx_queues[queue_index];
2173 struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
2174 struct bnxt_ring *ring = rxr->rx_ring_struct;
2175 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
2177 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
2178 bnxt_hwrm_ring_free(bp, ring,
2179 HWRM_RING_FREE_INPUT_RING_TYPE_RX);
2180 ring->fw_ring_id = INVALID_HW_RING_ID;
2181 if (BNXT_HAS_RING_GRPS(bp))
2182 bp->grp_info[queue_index].rx_fw_ring_id =
2184 memset(rxr->rx_desc_ring, 0,
2185 rxr->rx_ring_struct->ring_size *
2186 sizeof(*rxr->rx_desc_ring));
2187 memset(rxr->rx_buf_ring, 0,
2188 rxr->rx_ring_struct->ring_size *
2189 sizeof(*rxr->rx_buf_ring));
2192 ring = rxr->ag_ring_struct;
2193 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
2194 bnxt_hwrm_ring_free(bp, ring,
2195 BNXT_CHIP_THOR(bp) ?
2196 HWRM_RING_FREE_INPUT_RING_TYPE_RX_AGG :
2197 HWRM_RING_FREE_INPUT_RING_TYPE_RX);
2198 ring->fw_ring_id = INVALID_HW_RING_ID;
2199 memset(rxr->ag_buf_ring, 0,
2200 rxr->ag_ring_struct->ring_size *
2201 sizeof(*rxr->ag_buf_ring));
2203 if (BNXT_HAS_RING_GRPS(bp))
2204 bp->grp_info[queue_index].ag_fw_ring_id =
2207 if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID) {
2208 bnxt_free_cp_ring(bp, cpr);
2210 bnxt_free_nq_ring(bp, rxq->nq_ring);
2213 if (BNXT_HAS_RING_GRPS(bp))
2214 bp->grp_info[queue_index].cp_fw_ring_id = INVALID_HW_RING_ID;
2217 int bnxt_free_all_hwrm_rings(struct bnxt *bp)
2221 for (i = 0; i < bp->tx_cp_nr_rings; i++) {
2222 struct bnxt_tx_queue *txq = bp->tx_queues[i];
2223 struct bnxt_tx_ring_info *txr = txq->tx_ring;
2224 struct bnxt_ring *ring = txr->tx_ring_struct;
2225 struct bnxt_cp_ring_info *cpr = txq->cp_ring;
2227 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
2228 bnxt_hwrm_ring_free(bp, ring,
2229 HWRM_RING_FREE_INPUT_RING_TYPE_TX);
2230 ring->fw_ring_id = INVALID_HW_RING_ID;
2231 memset(txr->tx_desc_ring, 0,
2232 txr->tx_ring_struct->ring_size *
2233 sizeof(*txr->tx_desc_ring));
2234 memset(txr->tx_buf_ring, 0,
2235 txr->tx_ring_struct->ring_size *
2236 sizeof(*txr->tx_buf_ring));
2240 if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID) {
2241 bnxt_free_cp_ring(bp, cpr);
2242 cpr->cp_ring_struct->fw_ring_id = INVALID_HW_RING_ID;
2244 bnxt_free_nq_ring(bp, txq->nq_ring);
2248 for (i = 0; i < bp->rx_cp_nr_rings; i++)
2249 bnxt_free_hwrm_rx_ring(bp, i);
2254 int bnxt_alloc_all_hwrm_ring_grps(struct bnxt *bp)
2259 if (!BNXT_HAS_RING_GRPS(bp))
2262 for (i = 0; i < bp->rx_cp_nr_rings; i++) {
2263 rc = bnxt_hwrm_ring_grp_alloc(bp, i);
2270 void bnxt_free_hwrm_resources(struct bnxt *bp)
2272 /* Release memzone */
2273 rte_free(bp->hwrm_cmd_resp_addr);
2274 rte_free(bp->hwrm_short_cmd_req_addr);
2275 bp->hwrm_cmd_resp_addr = NULL;
2276 bp->hwrm_short_cmd_req_addr = NULL;
2277 bp->hwrm_cmd_resp_dma_addr = 0;
2278 bp->hwrm_short_cmd_req_dma_addr = 0;
2281 int bnxt_alloc_hwrm_resources(struct bnxt *bp)
2283 struct rte_pci_device *pdev = bp->pdev;
2284 char type[RTE_MEMZONE_NAMESIZE];
2286 sprintf(type, "bnxt_hwrm_%04x:%02x:%02x:%02x", pdev->addr.domain,
2287 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
2288 bp->max_resp_len = HWRM_MAX_RESP_LEN;
2289 bp->hwrm_cmd_resp_addr = rte_malloc(type, bp->max_resp_len, 0);
2290 rte_mem_lock_page(bp->hwrm_cmd_resp_addr);
2291 if (bp->hwrm_cmd_resp_addr == NULL)
2293 bp->hwrm_cmd_resp_dma_addr =
2294 rte_mem_virt2iova(bp->hwrm_cmd_resp_addr);
2295 if (bp->hwrm_cmd_resp_dma_addr == RTE_BAD_IOVA) {
2297 "unable to map response address to physical memory\n");
2300 rte_spinlock_init(&bp->hwrm_lock);
2305 int bnxt_clear_hwrm_vnic_filters(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2307 struct bnxt_filter_info *filter;
2310 STAILQ_FOREACH(filter, &vnic->filter, next) {
2311 if (filter->filter_type == HWRM_CFA_EM_FILTER)
2312 rc = bnxt_hwrm_clear_em_filter(bp, filter);
2313 else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
2314 rc = bnxt_hwrm_clear_ntuple_filter(bp, filter);
2316 rc = bnxt_hwrm_clear_l2_filter(bp, filter);
2317 STAILQ_REMOVE(&vnic->filter, filter, bnxt_filter_info, next);
2325 bnxt_clear_hwrm_vnic_flows(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2327 struct bnxt_filter_info *filter;
2328 struct rte_flow *flow;
2331 STAILQ_FOREACH(flow, &vnic->flow_list, next) {
2332 filter = flow->filter;
2333 PMD_DRV_LOG(DEBUG, "filter type %d\n", filter->filter_type);
2334 if (filter->filter_type == HWRM_CFA_EM_FILTER)
2335 rc = bnxt_hwrm_clear_em_filter(bp, filter);
2336 else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
2337 rc = bnxt_hwrm_clear_ntuple_filter(bp, filter);
2339 rc = bnxt_hwrm_clear_l2_filter(bp, filter);
2341 STAILQ_REMOVE(&vnic->flow_list, flow, rte_flow, next);
2349 int bnxt_set_hwrm_vnic_filters(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2351 struct bnxt_filter_info *filter;
2354 STAILQ_FOREACH(filter, &vnic->filter, next) {
2355 if (filter->filter_type == HWRM_CFA_EM_FILTER)
2356 rc = bnxt_hwrm_set_em_filter(bp, filter->dst_id,
2358 else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
2359 rc = bnxt_hwrm_set_ntuple_filter(bp, filter->dst_id,
2362 rc = bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id,
2370 void bnxt_free_tunnel_ports(struct bnxt *bp)
2372 if (bp->vxlan_port_cnt)
2373 bnxt_hwrm_tunnel_dst_port_free(bp, bp->vxlan_fw_dst_port_id,
2374 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_VXLAN);
2376 if (bp->geneve_port_cnt)
2377 bnxt_hwrm_tunnel_dst_port_free(bp, bp->geneve_fw_dst_port_id,
2378 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_GENEVE);
2379 bp->geneve_port = 0;
2382 void bnxt_free_all_hwrm_resources(struct bnxt *bp)
2386 if (bp->vnic_info == NULL)
2390 * Cleanup VNICs in reverse order, to make sure the L2 filter
2391 * from vnic0 is last to be cleaned up.
2393 for (i = bp->nr_vnics - 1; i >= 0; i--) {
2394 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
2396 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
2397 PMD_DRV_LOG(DEBUG, "Invalid vNIC ID\n");
2401 bnxt_clear_hwrm_vnic_flows(bp, vnic);
2403 bnxt_clear_hwrm_vnic_filters(bp, vnic);
2405 if (BNXT_CHIP_THOR(bp)) {
2406 for (j = 0; j < vnic->num_lb_ctxts; j++) {
2407 bnxt_hwrm_vnic_ctx_free(bp, vnic,
2408 vnic->fw_grp_ids[j]);
2409 vnic->fw_grp_ids[j] = INVALID_HW_RING_ID;
2411 vnic->num_lb_ctxts = 0;
2413 bnxt_hwrm_vnic_ctx_free(bp, vnic, vnic->rss_rule);
2414 vnic->rss_rule = INVALID_HW_RING_ID;
2417 bnxt_hwrm_vnic_tpa_cfg(bp, vnic, false);
2419 bnxt_hwrm_vnic_free(bp, vnic);
2421 rte_free(vnic->fw_grp_ids);
2423 /* Ring resources */
2424 bnxt_free_all_hwrm_rings(bp);
2425 bnxt_free_all_hwrm_ring_grps(bp);
2426 bnxt_free_all_hwrm_stat_ctxs(bp);
2427 bnxt_free_tunnel_ports(bp);
2430 static uint16_t bnxt_parse_eth_link_duplex(uint32_t conf_link_speed)
2432 uint8_t hw_link_duplex = HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH;
2434 if ((conf_link_speed & ETH_LINK_SPEED_FIXED) == ETH_LINK_SPEED_AUTONEG)
2435 return HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH;
2437 switch (conf_link_speed) {
2438 case ETH_LINK_SPEED_10M_HD:
2439 case ETH_LINK_SPEED_100M_HD:
2441 return HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_HALF;
2443 return hw_link_duplex;
2446 static uint16_t bnxt_check_eth_link_autoneg(uint32_t conf_link)
2448 return (conf_link & ETH_LINK_SPEED_FIXED) ? 0 : 1;
2451 static uint16_t bnxt_parse_eth_link_speed(uint32_t conf_link_speed)
2453 uint16_t eth_link_speed = 0;
2455 if (conf_link_speed == ETH_LINK_SPEED_AUTONEG)
2456 return ETH_LINK_SPEED_AUTONEG;
2458 switch (conf_link_speed & ~ETH_LINK_SPEED_FIXED) {
2459 case ETH_LINK_SPEED_100M:
2460 case ETH_LINK_SPEED_100M_HD:
2463 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_100MB;
2465 case ETH_LINK_SPEED_1G:
2467 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_1GB;
2469 case ETH_LINK_SPEED_2_5G:
2471 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_2_5GB;
2473 case ETH_LINK_SPEED_10G:
2475 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_10GB;
2477 case ETH_LINK_SPEED_20G:
2479 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_20GB;
2481 case ETH_LINK_SPEED_25G:
2483 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_25GB;
2485 case ETH_LINK_SPEED_40G:
2487 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_40GB;
2489 case ETH_LINK_SPEED_50G:
2491 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_50GB;
2493 case ETH_LINK_SPEED_100G:
2495 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_100GB;
2499 "Unsupported link speed %d; default to AUTO\n",
2503 return eth_link_speed;
2506 #define BNXT_SUPPORTED_SPEEDS (ETH_LINK_SPEED_100M | ETH_LINK_SPEED_100M_HD | \
2507 ETH_LINK_SPEED_1G | ETH_LINK_SPEED_2_5G | \
2508 ETH_LINK_SPEED_10G | ETH_LINK_SPEED_20G | ETH_LINK_SPEED_25G | \
2509 ETH_LINK_SPEED_40G | ETH_LINK_SPEED_50G | ETH_LINK_SPEED_100G)
2511 static int bnxt_valid_link_speed(uint32_t link_speed, uint16_t port_id)
2515 if (link_speed == ETH_LINK_SPEED_AUTONEG)
2518 if (link_speed & ETH_LINK_SPEED_FIXED) {
2519 one_speed = link_speed & ~ETH_LINK_SPEED_FIXED;
2521 if (one_speed & (one_speed - 1)) {
2523 "Invalid advertised speeds (%u) for port %u\n",
2524 link_speed, port_id);
2527 if ((one_speed & BNXT_SUPPORTED_SPEEDS) != one_speed) {
2529 "Unsupported advertised speed (%u) for port %u\n",
2530 link_speed, port_id);
2534 if (!(link_speed & BNXT_SUPPORTED_SPEEDS)) {
2536 "Unsupported advertised speeds (%u) for port %u\n",
2537 link_speed, port_id);
2545 bnxt_parse_eth_link_speed_mask(struct bnxt *bp, uint32_t link_speed)
2549 if (link_speed == ETH_LINK_SPEED_AUTONEG) {
2550 if (bp->link_info.support_speeds)
2551 return bp->link_info.support_speeds;
2552 link_speed = BNXT_SUPPORTED_SPEEDS;
2555 if (link_speed & ETH_LINK_SPEED_100M)
2556 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100MB;
2557 if (link_speed & ETH_LINK_SPEED_100M_HD)
2558 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100MB;
2559 if (link_speed & ETH_LINK_SPEED_1G)
2560 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_1GB;
2561 if (link_speed & ETH_LINK_SPEED_2_5G)
2562 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_2_5GB;
2563 if (link_speed & ETH_LINK_SPEED_10G)
2564 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_10GB;
2565 if (link_speed & ETH_LINK_SPEED_20G)
2566 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_20GB;
2567 if (link_speed & ETH_LINK_SPEED_25G)
2568 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_25GB;
2569 if (link_speed & ETH_LINK_SPEED_40G)
2570 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_40GB;
2571 if (link_speed & ETH_LINK_SPEED_50G)
2572 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_50GB;
2573 if (link_speed & ETH_LINK_SPEED_100G)
2574 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100GB;
2578 static uint32_t bnxt_parse_hw_link_speed(uint16_t hw_link_speed)
2580 uint32_t eth_link_speed = ETH_SPEED_NUM_NONE;
2582 switch (hw_link_speed) {
2583 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100MB:
2584 eth_link_speed = ETH_SPEED_NUM_100M;
2586 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_1GB:
2587 eth_link_speed = ETH_SPEED_NUM_1G;
2589 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2_5GB:
2590 eth_link_speed = ETH_SPEED_NUM_2_5G;
2592 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_10GB:
2593 eth_link_speed = ETH_SPEED_NUM_10G;
2595 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_20GB:
2596 eth_link_speed = ETH_SPEED_NUM_20G;
2598 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_25GB:
2599 eth_link_speed = ETH_SPEED_NUM_25G;
2601 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_40GB:
2602 eth_link_speed = ETH_SPEED_NUM_40G;
2604 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_50GB:
2605 eth_link_speed = ETH_SPEED_NUM_50G;
2607 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100GB:
2608 eth_link_speed = ETH_SPEED_NUM_100G;
2610 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2GB:
2612 PMD_DRV_LOG(ERR, "HWRM link speed %d not defined\n",
2616 return eth_link_speed;
2619 static uint16_t bnxt_parse_hw_link_duplex(uint16_t hw_link_duplex)
2621 uint16_t eth_link_duplex = ETH_LINK_FULL_DUPLEX;
2623 switch (hw_link_duplex) {
2624 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH:
2625 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_FULL:
2627 eth_link_duplex = ETH_LINK_FULL_DUPLEX;
2629 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_HALF:
2630 eth_link_duplex = ETH_LINK_HALF_DUPLEX;
2633 PMD_DRV_LOG(ERR, "HWRM link duplex %d not defined\n",
2637 return eth_link_duplex;
2640 int bnxt_get_hwrm_link_config(struct bnxt *bp, struct rte_eth_link *link)
2643 struct bnxt_link_info *link_info = &bp->link_info;
2645 rc = bnxt_hwrm_port_phy_qcfg(bp, link_info);
2648 "Get link config failed with rc %d\n", rc);
2651 if (link_info->link_speed)
2653 bnxt_parse_hw_link_speed(link_info->link_speed);
2655 link->link_speed = ETH_SPEED_NUM_NONE;
2656 link->link_duplex = bnxt_parse_hw_link_duplex(link_info->duplex);
2657 link->link_status = link_info->link_up;
2658 link->link_autoneg = link_info->auto_mode ==
2659 HWRM_PORT_PHY_QCFG_OUTPUT_AUTO_MODE_NONE ?
2660 ETH_LINK_FIXED : ETH_LINK_AUTONEG;
2665 int bnxt_set_hwrm_link_config(struct bnxt *bp, bool link_up)
2668 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
2669 struct bnxt_link_info link_req;
2670 uint16_t speed, autoneg;
2672 if (!BNXT_SINGLE_PF(bp) || BNXT_VF(bp))
2675 rc = bnxt_valid_link_speed(dev_conf->link_speeds,
2676 bp->eth_dev->data->port_id);
2680 memset(&link_req, 0, sizeof(link_req));
2681 link_req.link_up = link_up;
2685 autoneg = bnxt_check_eth_link_autoneg(dev_conf->link_speeds);
2686 if (BNXT_CHIP_THOR(bp) &&
2687 dev_conf->link_speeds == ETH_LINK_SPEED_40G) {
2688 /* 40G is not supported as part of media auto detect.
2689 * The speed should be forced and autoneg disabled
2690 * to configure 40G speed.
2692 PMD_DRV_LOG(INFO, "Disabling autoneg for 40G\n");
2696 speed = bnxt_parse_eth_link_speed(dev_conf->link_speeds);
2697 link_req.phy_flags = HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESET_PHY;
2698 /* Autoneg can be done only when the FW allows.
2699 * When user configures fixed speed of 40G and later changes to
2700 * any other speed, auto_link_speed/force_link_speed is still set
2701 * to 40G until link comes up at new speed.
2704 !(!BNXT_CHIP_THOR(bp) &&
2705 (bp->link_info.auto_link_speed ||
2706 bp->link_info.force_link_speed))) {
2707 link_req.phy_flags |=
2708 HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESTART_AUTONEG;
2709 link_req.auto_link_speed_mask =
2710 bnxt_parse_eth_link_speed_mask(bp,
2711 dev_conf->link_speeds);
2713 if (bp->link_info.phy_type ==
2714 HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET ||
2715 bp->link_info.phy_type ==
2716 HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASETE ||
2717 bp->link_info.media_type ==
2718 HWRM_PORT_PHY_QCFG_OUTPUT_MEDIA_TYPE_TP) {
2719 PMD_DRV_LOG(ERR, "10GBase-T devices must autoneg\n");
2723 link_req.phy_flags |= HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE;
2724 /* If user wants a particular speed try that first. */
2726 link_req.link_speed = speed;
2727 else if (bp->link_info.force_link_speed)
2728 link_req.link_speed = bp->link_info.force_link_speed;
2730 link_req.link_speed = bp->link_info.auto_link_speed;
2732 link_req.duplex = bnxt_parse_eth_link_duplex(dev_conf->link_speeds);
2733 link_req.auto_pause = bp->link_info.auto_pause;
2734 link_req.force_pause = bp->link_info.force_pause;
2737 rc = bnxt_hwrm_port_phy_cfg(bp, &link_req);
2740 "Set link config failed with rc %d\n", rc);
2748 int bnxt_hwrm_func_qcfg(struct bnxt *bp, uint16_t *mtu)
2750 struct hwrm_func_qcfg_input req = {0};
2751 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
2755 HWRM_PREP(req, FUNC_QCFG, BNXT_USE_CHIMP_MB);
2756 req.fid = rte_cpu_to_le_16(0xffff);
2758 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2760 HWRM_CHECK_RESULT();
2762 /* Hard Coded.. 0xfff VLAN ID mask */
2763 bp->vlan = rte_le_to_cpu_16(resp->vlan) & 0xfff;
2764 flags = rte_le_to_cpu_16(resp->flags);
2765 if (BNXT_PF(bp) && (flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_MULTI_HOST))
2766 bp->flags |= BNXT_FLAG_MULTI_HOST;
2768 if (BNXT_VF(bp) && (flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_TRUSTED_VF)) {
2769 bp->flags |= BNXT_FLAG_TRUSTED_VF_EN;
2770 PMD_DRV_LOG(INFO, "Trusted VF cap enabled\n");
2771 } else if (BNXT_VF(bp) &&
2772 !(flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_TRUSTED_VF)) {
2773 bp->flags &= ~BNXT_FLAG_TRUSTED_VF_EN;
2774 PMD_DRV_LOG(INFO, "Trusted VF cap disabled\n");
2780 switch (resp->port_partition_type) {
2781 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR1_0:
2782 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR1_5:
2783 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR2_0:
2785 bp->port_partition_type = resp->port_partition_type;
2788 bp->port_partition_type = 0;
2797 static void copy_func_cfg_to_qcaps(struct hwrm_func_cfg_input *fcfg,
2798 struct hwrm_func_qcaps_output *qcaps)
2800 qcaps->max_rsscos_ctx = fcfg->num_rsscos_ctxs;
2801 memcpy(qcaps->mac_address, fcfg->dflt_mac_addr,
2802 sizeof(qcaps->mac_address));
2803 qcaps->max_l2_ctxs = fcfg->num_l2_ctxs;
2804 qcaps->max_rx_rings = fcfg->num_rx_rings;
2805 qcaps->max_tx_rings = fcfg->num_tx_rings;
2806 qcaps->max_cmpl_rings = fcfg->num_cmpl_rings;
2807 qcaps->max_stat_ctx = fcfg->num_stat_ctxs;
2809 qcaps->first_vf_id = 0;
2810 qcaps->max_vnics = fcfg->num_vnics;
2811 qcaps->max_decap_records = 0;
2812 qcaps->max_encap_records = 0;
2813 qcaps->max_tx_wm_flows = 0;
2814 qcaps->max_tx_em_flows = 0;
2815 qcaps->max_rx_wm_flows = 0;
2816 qcaps->max_rx_em_flows = 0;
2817 qcaps->max_flow_id = 0;
2818 qcaps->max_mcast_filters = fcfg->num_mcast_filters;
2819 qcaps->max_sp_tx_rings = 0;
2820 qcaps->max_hw_ring_grps = fcfg->num_hw_ring_grps;
2823 static int bnxt_hwrm_pf_func_cfg(struct bnxt *bp, int tx_rings)
2825 struct hwrm_func_cfg_input req = {0};
2826 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2830 enables = HWRM_FUNC_CFG_INPUT_ENABLES_MTU |
2831 HWRM_FUNC_CFG_INPUT_ENABLES_MRU |
2832 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS |
2833 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
2834 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
2835 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_TX_RINGS |
2836 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RX_RINGS |
2837 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_L2_CTXS |
2838 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_VNICS;
2840 if (BNXT_HAS_RING_GRPS(bp)) {
2841 enables |= HWRM_FUNC_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS;
2842 req.num_hw_ring_grps = rte_cpu_to_le_16(bp->max_ring_grps);
2843 } else if (BNXT_HAS_NQ(bp)) {
2844 enables |= HWRM_FUNC_CFG_INPUT_ENABLES_NUM_MSIX;
2845 req.num_msix = rte_cpu_to_le_16(bp->max_nq_rings);
2848 req.flags = rte_cpu_to_le_32(bp->pf.func_cfg_flags);
2849 req.mtu = rte_cpu_to_le_16(BNXT_MAX_MTU);
2850 req.mru = rte_cpu_to_le_16(bp->eth_dev->data->mtu + RTE_ETHER_HDR_LEN +
2851 RTE_ETHER_CRC_LEN + VLAN_TAG_SIZE *
2853 req.num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx);
2854 req.num_stat_ctxs = rte_cpu_to_le_16(bp->max_stat_ctx);
2855 req.num_cmpl_rings = rte_cpu_to_le_16(bp->max_cp_rings);
2856 req.num_tx_rings = rte_cpu_to_le_16(tx_rings);
2857 req.num_rx_rings = rte_cpu_to_le_16(bp->max_rx_rings);
2858 req.num_l2_ctxs = rte_cpu_to_le_16(bp->max_l2_ctx);
2859 req.num_vnics = rte_cpu_to_le_16(bp->max_vnics);
2860 req.fid = rte_cpu_to_le_16(0xffff);
2861 req.enables = rte_cpu_to_le_32(enables);
2863 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
2865 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2867 HWRM_CHECK_RESULT();
2873 static void populate_vf_func_cfg_req(struct bnxt *bp,
2874 struct hwrm_func_cfg_input *req,
2877 req->enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_MTU |
2878 HWRM_FUNC_CFG_INPUT_ENABLES_MRU |
2879 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS |
2880 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
2881 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
2882 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_TX_RINGS |
2883 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RX_RINGS |
2884 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_L2_CTXS |
2885 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_VNICS |
2886 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS);
2888 req->mtu = rte_cpu_to_le_16(bp->eth_dev->data->mtu + RTE_ETHER_HDR_LEN +
2889 RTE_ETHER_CRC_LEN + VLAN_TAG_SIZE *
2891 req->mru = rte_cpu_to_le_16(bp->eth_dev->data->mtu + RTE_ETHER_HDR_LEN +
2892 RTE_ETHER_CRC_LEN + VLAN_TAG_SIZE *
2894 req->num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx /
2896 req->num_stat_ctxs = rte_cpu_to_le_16(bp->max_stat_ctx / (num_vfs + 1));
2897 req->num_cmpl_rings = rte_cpu_to_le_16(bp->max_cp_rings /
2899 req->num_tx_rings = rte_cpu_to_le_16(bp->max_tx_rings / (num_vfs + 1));
2900 req->num_rx_rings = rte_cpu_to_le_16(bp->max_rx_rings / (num_vfs + 1));
2901 req->num_l2_ctxs = rte_cpu_to_le_16(bp->max_l2_ctx / (num_vfs + 1));
2902 /* TODO: For now, do not support VMDq/RFS on VFs. */
2903 req->num_vnics = rte_cpu_to_le_16(1);
2904 req->num_hw_ring_grps = rte_cpu_to_le_16(bp->max_ring_grps /
2908 static void add_random_mac_if_needed(struct bnxt *bp,
2909 struct hwrm_func_cfg_input *cfg_req,
2912 struct rte_ether_addr mac;
2914 if (bnxt_hwrm_func_qcfg_vf_default_mac(bp, vf, &mac))
2917 if (memcmp(mac.addr_bytes, "\x00\x00\x00\x00\x00", 6) == 0) {
2919 rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
2920 rte_eth_random_addr(cfg_req->dflt_mac_addr);
2921 bp->pf.vf_info[vf].random_mac = true;
2923 memcpy(cfg_req->dflt_mac_addr, mac.addr_bytes,
2924 RTE_ETHER_ADDR_LEN);
2928 static void reserve_resources_from_vf(struct bnxt *bp,
2929 struct hwrm_func_cfg_input *cfg_req,
2932 struct hwrm_func_qcaps_input req = {0};
2933 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
2936 /* Get the actual allocated values now */
2937 HWRM_PREP(req, FUNC_QCAPS, BNXT_USE_CHIMP_MB);
2938 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
2939 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2942 PMD_DRV_LOG(ERR, "hwrm_func_qcaps failed rc:%d\n", rc);
2943 copy_func_cfg_to_qcaps(cfg_req, resp);
2944 } else if (resp->error_code) {
2945 rc = rte_le_to_cpu_16(resp->error_code);
2946 PMD_DRV_LOG(ERR, "hwrm_func_qcaps error %d\n", rc);
2947 copy_func_cfg_to_qcaps(cfg_req, resp);
2950 bp->max_rsscos_ctx -= rte_le_to_cpu_16(resp->max_rsscos_ctx);
2951 bp->max_stat_ctx -= rte_le_to_cpu_16(resp->max_stat_ctx);
2952 bp->max_cp_rings -= rte_le_to_cpu_16(resp->max_cmpl_rings);
2953 bp->max_tx_rings -= rte_le_to_cpu_16(resp->max_tx_rings);
2954 bp->max_rx_rings -= rte_le_to_cpu_16(resp->max_rx_rings);
2955 bp->max_l2_ctx -= rte_le_to_cpu_16(resp->max_l2_ctxs);
2957 * TODO: While not supporting VMDq with VFs, max_vnics is always
2958 * forced to 1 in this case
2960 //bp->max_vnics -= rte_le_to_cpu_16(esp->max_vnics);
2961 bp->max_ring_grps -= rte_le_to_cpu_16(resp->max_hw_ring_grps);
2966 int bnxt_hwrm_func_qcfg_current_vf_vlan(struct bnxt *bp, int vf)
2968 struct hwrm_func_qcfg_input req = {0};
2969 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
2972 /* Check for zero MAC address */
2973 HWRM_PREP(req, FUNC_QCFG, BNXT_USE_CHIMP_MB);
2974 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
2975 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2976 HWRM_CHECK_RESULT();
2977 rc = rte_le_to_cpu_16(resp->vlan);
2984 static int update_pf_resource_max(struct bnxt *bp)
2986 struct hwrm_func_qcfg_input req = {0};
2987 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
2990 /* And copy the allocated numbers into the pf struct */
2991 HWRM_PREP(req, FUNC_QCFG, BNXT_USE_CHIMP_MB);
2992 req.fid = rte_cpu_to_le_16(0xffff);
2993 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2994 HWRM_CHECK_RESULT();
2996 /* Only TX ring value reflects actual allocation? TODO */
2997 bp->max_tx_rings = rte_le_to_cpu_16(resp->alloc_tx_rings);
2998 bp->pf.evb_mode = resp->evb_mode;
3005 int bnxt_hwrm_allocate_pf_only(struct bnxt *bp)
3010 PMD_DRV_LOG(ERR, "Attempt to allcoate VFs on a VF!\n");
3014 rc = bnxt_hwrm_func_qcaps(bp);
3018 bp->pf.func_cfg_flags &=
3019 ~(HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE |
3020 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE);
3021 bp->pf.func_cfg_flags |=
3022 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE;
3023 rc = bnxt_hwrm_pf_func_cfg(bp, bp->max_tx_rings);
3024 rc = __bnxt_hwrm_func_qcaps(bp);
3028 int bnxt_hwrm_allocate_vfs(struct bnxt *bp, int num_vfs)
3030 struct hwrm_func_cfg_input req = {0};
3031 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3038 PMD_DRV_LOG(ERR, "Attempt to allcoate VFs on a VF!\n");
3042 rc = bnxt_hwrm_func_qcaps(bp);
3047 bp->pf.active_vfs = num_vfs;
3050 * First, configure the PF to only use one TX ring. This ensures that
3051 * there are enough rings for all VFs.
3053 * If we don't do this, when we call func_alloc() later, we will lock
3054 * extra rings to the PF that won't be available during func_cfg() of
3057 * This has been fixed with firmware versions above 20.6.54
3059 bp->pf.func_cfg_flags &=
3060 ~(HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE |
3061 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE);
3062 bp->pf.func_cfg_flags |=
3063 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE;
3064 rc = bnxt_hwrm_pf_func_cfg(bp, 1);
3069 * Now, create and register a buffer to hold forwarded VF requests
3071 req_buf_sz = num_vfs * HWRM_MAX_REQ_LEN;
3072 bp->pf.vf_req_buf = rte_malloc("bnxt_vf_fwd", req_buf_sz,
3073 page_roundup(num_vfs * HWRM_MAX_REQ_LEN));
3074 if (bp->pf.vf_req_buf == NULL) {
3078 for (sz = 0; sz < req_buf_sz; sz += getpagesize())
3079 rte_mem_lock_page(((char *)bp->pf.vf_req_buf) + sz);
3080 for (i = 0; i < num_vfs; i++)
3081 bp->pf.vf_info[i].req_buf = ((char *)bp->pf.vf_req_buf) +
3082 (i * HWRM_MAX_REQ_LEN);
3084 rc = bnxt_hwrm_func_buf_rgtr(bp);
3088 populate_vf_func_cfg_req(bp, &req, num_vfs);
3090 bp->pf.active_vfs = 0;
3091 for (i = 0; i < num_vfs; i++) {
3092 add_random_mac_if_needed(bp, &req, i);
3094 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
3095 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[i].func_cfg_flags);
3096 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[i].fid);
3097 rc = bnxt_hwrm_send_message(bp,
3102 /* Clear enable flag for next pass */
3103 req.enables &= ~rte_cpu_to_le_32(
3104 HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
3106 if (rc || resp->error_code) {
3108 "Failed to initizlie VF %d\n", i);
3110 "Not all VFs available. (%d, %d)\n",
3111 rc, resp->error_code);
3118 reserve_resources_from_vf(bp, &req, i);
3119 bp->pf.active_vfs++;
3120 bnxt_hwrm_func_clr_stats(bp, bp->pf.vf_info[i].fid);
3124 * Now configure the PF to use "the rest" of the resources
3125 * We're using STD_TX_RING_MODE here though which will limit the TX
3126 * rings. This will allow QoS to function properly. Not setting this
3127 * will cause PF rings to break bandwidth settings.
3129 rc = bnxt_hwrm_pf_func_cfg(bp, bp->max_tx_rings);
3133 rc = update_pf_resource_max(bp);
3140 bnxt_hwrm_func_buf_unrgtr(bp);
3144 int bnxt_hwrm_pf_evb_mode(struct bnxt *bp)
3146 struct hwrm_func_cfg_input req = {0};
3147 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3150 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
3152 req.fid = rte_cpu_to_le_16(0xffff);
3153 req.enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_EVB_MODE);
3154 req.evb_mode = bp->pf.evb_mode;
3156 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3157 HWRM_CHECK_RESULT();
3163 int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt *bp, uint16_t port,
3164 uint8_t tunnel_type)
3166 struct hwrm_tunnel_dst_port_alloc_input req = {0};
3167 struct hwrm_tunnel_dst_port_alloc_output *resp = bp->hwrm_cmd_resp_addr;
3170 HWRM_PREP(req, TUNNEL_DST_PORT_ALLOC, BNXT_USE_CHIMP_MB);
3171 req.tunnel_type = tunnel_type;
3172 req.tunnel_dst_port_val = port;
3173 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3174 HWRM_CHECK_RESULT();
3176 switch (tunnel_type) {
3177 case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_VXLAN:
3178 bp->vxlan_fw_dst_port_id = resp->tunnel_dst_port_id;
3179 bp->vxlan_port = port;
3181 case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_GENEVE:
3182 bp->geneve_fw_dst_port_id = resp->tunnel_dst_port_id;
3183 bp->geneve_port = port;
3194 int bnxt_hwrm_tunnel_dst_port_free(struct bnxt *bp, uint16_t port,
3195 uint8_t tunnel_type)
3197 struct hwrm_tunnel_dst_port_free_input req = {0};
3198 struct hwrm_tunnel_dst_port_free_output *resp = bp->hwrm_cmd_resp_addr;
3201 HWRM_PREP(req, TUNNEL_DST_PORT_FREE, BNXT_USE_CHIMP_MB);
3203 req.tunnel_type = tunnel_type;
3204 req.tunnel_dst_port_id = rte_cpu_to_be_16(port);
3205 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3207 HWRM_CHECK_RESULT();
3213 int bnxt_hwrm_func_cfg_vf_set_flags(struct bnxt *bp, uint16_t vf,
3216 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3217 struct hwrm_func_cfg_input req = {0};
3220 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
3222 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3223 req.flags = rte_cpu_to_le_32(flags);
3224 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3226 HWRM_CHECK_RESULT();
3232 void vf_vnic_set_rxmask_cb(struct bnxt_vnic_info *vnic, void *flagp)
3234 uint32_t *flag = flagp;
3236 vnic->flags = *flag;
3239 int bnxt_set_rx_mask_no_vlan(struct bnxt *bp, struct bnxt_vnic_info *vnic)
3241 return bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
3244 int bnxt_hwrm_func_buf_rgtr(struct bnxt *bp)
3247 struct hwrm_func_buf_rgtr_input req = {.req_type = 0 };
3248 struct hwrm_func_buf_rgtr_output *resp = bp->hwrm_cmd_resp_addr;
3250 HWRM_PREP(req, FUNC_BUF_RGTR, BNXT_USE_CHIMP_MB);
3252 req.req_buf_num_pages = rte_cpu_to_le_16(1);
3253 req.req_buf_page_size = rte_cpu_to_le_16(
3254 page_getenum(bp->pf.active_vfs * HWRM_MAX_REQ_LEN));
3255 req.req_buf_len = rte_cpu_to_le_16(HWRM_MAX_REQ_LEN);
3256 req.req_buf_page_addr0 =
3257 rte_cpu_to_le_64(rte_mem_virt2iova(bp->pf.vf_req_buf));
3258 if (req.req_buf_page_addr0 == RTE_BAD_IOVA) {
3260 "unable to map buffer address to physical memory\n");
3264 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3266 HWRM_CHECK_RESULT();
3272 int bnxt_hwrm_func_buf_unrgtr(struct bnxt *bp)
3275 struct hwrm_func_buf_unrgtr_input req = {.req_type = 0 };
3276 struct hwrm_func_buf_unrgtr_output *resp = bp->hwrm_cmd_resp_addr;
3278 if (!(BNXT_PF(bp) && bp->pdev->max_vfs))
3281 HWRM_PREP(req, FUNC_BUF_UNRGTR, BNXT_USE_CHIMP_MB);
3283 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3285 HWRM_CHECK_RESULT();
3291 int bnxt_hwrm_func_cfg_def_cp(struct bnxt *bp)
3293 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3294 struct hwrm_func_cfg_input req = {0};
3297 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
3299 req.fid = rte_cpu_to_le_16(0xffff);
3300 req.flags = rte_cpu_to_le_32(bp->pf.func_cfg_flags);
3301 req.enables = rte_cpu_to_le_32(
3302 HWRM_FUNC_CFG_INPUT_ENABLES_ASYNC_EVENT_CR);
3303 req.async_event_cr = rte_cpu_to_le_16(
3304 bp->async_cp_ring->cp_ring_struct->fw_ring_id);
3305 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3307 HWRM_CHECK_RESULT();
3313 int bnxt_hwrm_vf_func_cfg_def_cp(struct bnxt *bp)
3315 struct hwrm_func_vf_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3316 struct hwrm_func_vf_cfg_input req = {0};
3319 HWRM_PREP(req, FUNC_VF_CFG, BNXT_USE_CHIMP_MB);
3321 req.enables = rte_cpu_to_le_32(
3322 HWRM_FUNC_VF_CFG_INPUT_ENABLES_ASYNC_EVENT_CR);
3323 req.async_event_cr = rte_cpu_to_le_16(
3324 bp->async_cp_ring->cp_ring_struct->fw_ring_id);
3325 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3327 HWRM_CHECK_RESULT();
3333 int bnxt_hwrm_set_default_vlan(struct bnxt *bp, int vf, uint8_t is_vf)
3335 struct hwrm_func_cfg_input req = {0};
3336 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3337 uint16_t dflt_vlan, fid;
3338 uint32_t func_cfg_flags;
3341 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
3344 dflt_vlan = bp->pf.vf_info[vf].dflt_vlan;
3345 fid = bp->pf.vf_info[vf].fid;
3346 func_cfg_flags = bp->pf.vf_info[vf].func_cfg_flags;
3348 fid = rte_cpu_to_le_16(0xffff);
3349 func_cfg_flags = bp->pf.func_cfg_flags;
3350 dflt_vlan = bp->vlan;
3353 req.flags = rte_cpu_to_le_32(func_cfg_flags);
3354 req.fid = rte_cpu_to_le_16(fid);
3355 req.enables |= rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_VLAN);
3356 req.dflt_vlan = rte_cpu_to_le_16(dflt_vlan);
3358 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3360 HWRM_CHECK_RESULT();
3366 int bnxt_hwrm_func_bw_cfg(struct bnxt *bp, uint16_t vf,
3367 uint16_t max_bw, uint16_t enables)
3369 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3370 struct hwrm_func_cfg_input req = {0};
3373 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
3375 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3376 req.enables |= rte_cpu_to_le_32(enables);
3377 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[vf].func_cfg_flags);
3378 req.max_bw = rte_cpu_to_le_32(max_bw);
3379 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3381 HWRM_CHECK_RESULT();
3387 int bnxt_hwrm_set_vf_vlan(struct bnxt *bp, int vf)
3389 struct hwrm_func_cfg_input req = {0};
3390 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3393 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
3395 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[vf].func_cfg_flags);
3396 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3397 req.enables |= rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_VLAN);
3398 req.dflt_vlan = rte_cpu_to_le_16(bp->pf.vf_info[vf].dflt_vlan);
3400 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3402 HWRM_CHECK_RESULT();
3408 int bnxt_hwrm_set_async_event_cr(struct bnxt *bp)
3413 rc = bnxt_hwrm_func_cfg_def_cp(bp);
3415 rc = bnxt_hwrm_vf_func_cfg_def_cp(bp);
3420 int bnxt_hwrm_reject_fwd_resp(struct bnxt *bp, uint16_t target_id,
3421 void *encaped, size_t ec_size)
3424 struct hwrm_reject_fwd_resp_input req = {.req_type = 0};
3425 struct hwrm_reject_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr;
3427 if (ec_size > sizeof(req.encap_request))
3430 HWRM_PREP(req, REJECT_FWD_RESP, BNXT_USE_CHIMP_MB);
3432 req.encap_resp_target_id = rte_cpu_to_le_16(target_id);
3433 memcpy(req.encap_request, encaped, ec_size);
3435 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3437 HWRM_CHECK_RESULT();
3443 int bnxt_hwrm_func_qcfg_vf_default_mac(struct bnxt *bp, uint16_t vf,
3444 struct rte_ether_addr *mac)
3446 struct hwrm_func_qcfg_input req = {0};
3447 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
3450 HWRM_PREP(req, FUNC_QCFG, BNXT_USE_CHIMP_MB);
3452 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3453 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3455 HWRM_CHECK_RESULT();
3457 memcpy(mac->addr_bytes, resp->mac_address, RTE_ETHER_ADDR_LEN);
3464 int bnxt_hwrm_exec_fwd_resp(struct bnxt *bp, uint16_t target_id,
3465 void *encaped, size_t ec_size)
3468 struct hwrm_exec_fwd_resp_input req = {.req_type = 0};
3469 struct hwrm_exec_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr;
3471 if (ec_size > sizeof(req.encap_request))
3474 HWRM_PREP(req, EXEC_FWD_RESP, BNXT_USE_CHIMP_MB);
3476 req.encap_resp_target_id = rte_cpu_to_le_16(target_id);
3477 memcpy(req.encap_request, encaped, ec_size);
3479 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3481 HWRM_CHECK_RESULT();
3487 int bnxt_hwrm_ctx_qstats(struct bnxt *bp, uint32_t cid, int idx,
3488 struct rte_eth_stats *stats, uint8_t rx)
3491 struct hwrm_stat_ctx_query_input req = {.req_type = 0};
3492 struct hwrm_stat_ctx_query_output *resp = bp->hwrm_cmd_resp_addr;
3494 HWRM_PREP(req, STAT_CTX_QUERY, BNXT_USE_CHIMP_MB);
3496 req.stat_ctx_id = rte_cpu_to_le_32(cid);
3498 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3500 HWRM_CHECK_RESULT();
3503 stats->q_ipackets[idx] = rte_le_to_cpu_64(resp->rx_ucast_pkts);
3504 stats->q_ipackets[idx] += rte_le_to_cpu_64(resp->rx_mcast_pkts);
3505 stats->q_ipackets[idx] += rte_le_to_cpu_64(resp->rx_bcast_pkts);
3506 stats->q_ibytes[idx] = rte_le_to_cpu_64(resp->rx_ucast_bytes);
3507 stats->q_ibytes[idx] += rte_le_to_cpu_64(resp->rx_mcast_bytes);
3508 stats->q_ibytes[idx] += rte_le_to_cpu_64(resp->rx_bcast_bytes);
3509 stats->q_errors[idx] = rte_le_to_cpu_64(resp->rx_err_pkts);
3510 stats->q_errors[idx] += rte_le_to_cpu_64(resp->rx_drop_pkts);
3512 stats->q_opackets[idx] = rte_le_to_cpu_64(resp->tx_ucast_pkts);
3513 stats->q_opackets[idx] += rte_le_to_cpu_64(resp->tx_mcast_pkts);
3514 stats->q_opackets[idx] += rte_le_to_cpu_64(resp->tx_bcast_pkts);
3515 stats->q_obytes[idx] = rte_le_to_cpu_64(resp->tx_ucast_bytes);
3516 stats->q_obytes[idx] += rte_le_to_cpu_64(resp->tx_mcast_bytes);
3517 stats->q_obytes[idx] += rte_le_to_cpu_64(resp->tx_bcast_bytes);
3526 int bnxt_hwrm_port_qstats(struct bnxt *bp)
3528 struct hwrm_port_qstats_input req = {0};
3529 struct hwrm_port_qstats_output *resp = bp->hwrm_cmd_resp_addr;
3530 struct bnxt_pf_info *pf = &bp->pf;
3533 HWRM_PREP(req, PORT_QSTATS, BNXT_USE_CHIMP_MB);
3535 req.port_id = rte_cpu_to_le_16(pf->port_id);
3536 req.tx_stat_host_addr = rte_cpu_to_le_64(bp->hw_tx_port_stats_map);
3537 req.rx_stat_host_addr = rte_cpu_to_le_64(bp->hw_rx_port_stats_map);
3538 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3540 HWRM_CHECK_RESULT();
3546 int bnxt_hwrm_port_clr_stats(struct bnxt *bp)
3548 struct hwrm_port_clr_stats_input req = {0};
3549 struct hwrm_port_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
3550 struct bnxt_pf_info *pf = &bp->pf;
3553 /* Not allowed on NS2 device, NPAR, MultiHost, VF */
3554 if (!(bp->flags & BNXT_FLAG_PORT_STATS) || BNXT_VF(bp) ||
3555 BNXT_NPAR(bp) || BNXT_MH(bp) || BNXT_TOTAL_VFS(bp))
3558 HWRM_PREP(req, PORT_CLR_STATS, BNXT_USE_CHIMP_MB);
3560 req.port_id = rte_cpu_to_le_16(pf->port_id);
3561 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3563 HWRM_CHECK_RESULT();
3569 int bnxt_hwrm_port_led_qcaps(struct bnxt *bp)
3571 struct hwrm_port_led_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
3572 struct hwrm_port_led_qcaps_input req = {0};
3578 HWRM_PREP(req, PORT_LED_QCAPS, BNXT_USE_CHIMP_MB);
3579 req.port_id = bp->pf.port_id;
3580 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3582 HWRM_CHECK_RESULT();
3584 if (resp->num_leds > 0 && resp->num_leds < BNXT_MAX_LED) {
3587 bp->num_leds = resp->num_leds;
3588 memcpy(bp->leds, &resp->led0_id,
3589 sizeof(bp->leds[0]) * bp->num_leds);
3590 for (i = 0; i < bp->num_leds; i++) {
3591 struct bnxt_led_info *led = &bp->leds[i];
3593 uint16_t caps = led->led_state_caps;
3595 if (!led->led_group_id ||
3596 !BNXT_LED_ALT_BLINK_CAP(caps)) {
3608 int bnxt_hwrm_port_led_cfg(struct bnxt *bp, bool led_on)
3610 struct hwrm_port_led_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3611 struct hwrm_port_led_cfg_input req = {0};
3612 struct bnxt_led_cfg *led_cfg;
3613 uint8_t led_state = HWRM_PORT_LED_QCFG_OUTPUT_LED0_STATE_DEFAULT;
3614 uint16_t duration = 0;
3617 if (!bp->num_leds || BNXT_VF(bp))
3620 HWRM_PREP(req, PORT_LED_CFG, BNXT_USE_CHIMP_MB);
3623 led_state = HWRM_PORT_LED_CFG_INPUT_LED0_STATE_BLINKALT;
3624 duration = rte_cpu_to_le_16(500);
3626 req.port_id = bp->pf.port_id;
3627 req.num_leds = bp->num_leds;
3628 led_cfg = (struct bnxt_led_cfg *)&req.led0_id;
3629 for (i = 0; i < bp->num_leds; i++, led_cfg++) {
3630 req.enables |= BNXT_LED_DFLT_ENABLES(i);
3631 led_cfg->led_id = bp->leds[i].led_id;
3632 led_cfg->led_state = led_state;
3633 led_cfg->led_blink_on = duration;
3634 led_cfg->led_blink_off = duration;
3635 led_cfg->led_group_id = bp->leds[i].led_group_id;
3638 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3640 HWRM_CHECK_RESULT();
3646 int bnxt_hwrm_nvm_get_dir_info(struct bnxt *bp, uint32_t *entries,
3650 struct hwrm_nvm_get_dir_info_input req = {0};
3651 struct hwrm_nvm_get_dir_info_output *resp = bp->hwrm_cmd_resp_addr;
3653 HWRM_PREP(req, NVM_GET_DIR_INFO, BNXT_USE_CHIMP_MB);
3655 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3657 HWRM_CHECK_RESULT();
3659 *entries = rte_le_to_cpu_32(resp->entries);
3660 *length = rte_le_to_cpu_32(resp->entry_length);
3666 int bnxt_get_nvram_directory(struct bnxt *bp, uint32_t len, uint8_t *data)
3669 uint32_t dir_entries;
3670 uint32_t entry_length;
3673 rte_iova_t dma_handle;
3674 struct hwrm_nvm_get_dir_entries_input req = {0};
3675 struct hwrm_nvm_get_dir_entries_output *resp = bp->hwrm_cmd_resp_addr;
3677 rc = bnxt_hwrm_nvm_get_dir_info(bp, &dir_entries, &entry_length);
3681 *data++ = dir_entries;
3682 *data++ = entry_length;
3684 memset(data, 0xff, len);
3686 buflen = dir_entries * entry_length;
3687 buf = rte_malloc("nvm_dir", buflen, 0);
3688 rte_mem_lock_page(buf);
3691 dma_handle = rte_mem_virt2iova(buf);
3692 if (dma_handle == RTE_BAD_IOVA) {
3694 "unable to map response address to physical memory\n");
3697 HWRM_PREP(req, NVM_GET_DIR_ENTRIES, BNXT_USE_CHIMP_MB);
3698 req.host_dest_addr = rte_cpu_to_le_64(dma_handle);
3699 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3702 memcpy(data, buf, len > buflen ? buflen : len);
3705 HWRM_CHECK_RESULT();
3711 int bnxt_hwrm_get_nvram_item(struct bnxt *bp, uint32_t index,
3712 uint32_t offset, uint32_t length,
3717 rte_iova_t dma_handle;
3718 struct hwrm_nvm_read_input req = {0};
3719 struct hwrm_nvm_read_output *resp = bp->hwrm_cmd_resp_addr;
3721 buf = rte_malloc("nvm_item", length, 0);
3722 rte_mem_lock_page(buf);
3726 dma_handle = rte_mem_virt2iova(buf);
3727 if (dma_handle == RTE_BAD_IOVA) {
3729 "unable to map response address to physical memory\n");
3732 HWRM_PREP(req, NVM_READ, BNXT_USE_CHIMP_MB);
3733 req.host_dest_addr = rte_cpu_to_le_64(dma_handle);
3734 req.dir_idx = rte_cpu_to_le_16(index);
3735 req.offset = rte_cpu_to_le_32(offset);
3736 req.len = rte_cpu_to_le_32(length);
3737 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3739 memcpy(data, buf, length);
3742 HWRM_CHECK_RESULT();
3748 int bnxt_hwrm_erase_nvram_directory(struct bnxt *bp, uint8_t index)
3751 struct hwrm_nvm_erase_dir_entry_input req = {0};
3752 struct hwrm_nvm_erase_dir_entry_output *resp = bp->hwrm_cmd_resp_addr;
3754 HWRM_PREP(req, NVM_ERASE_DIR_ENTRY, BNXT_USE_CHIMP_MB);
3755 req.dir_idx = rte_cpu_to_le_16(index);
3756 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3757 HWRM_CHECK_RESULT();
3764 int bnxt_hwrm_flash_nvram(struct bnxt *bp, uint16_t dir_type,
3765 uint16_t dir_ordinal, uint16_t dir_ext,
3766 uint16_t dir_attr, const uint8_t *data,
3770 struct hwrm_nvm_write_input req = {0};
3771 struct hwrm_nvm_write_output *resp = bp->hwrm_cmd_resp_addr;
3772 rte_iova_t dma_handle;
3775 buf = rte_malloc("nvm_write", data_len, 0);
3776 rte_mem_lock_page(buf);
3780 dma_handle = rte_mem_virt2iova(buf);
3781 if (dma_handle == RTE_BAD_IOVA) {
3783 "unable to map response address to physical memory\n");
3786 memcpy(buf, data, data_len);
3788 HWRM_PREP(req, NVM_WRITE, BNXT_USE_CHIMP_MB);
3790 req.dir_type = rte_cpu_to_le_16(dir_type);
3791 req.dir_ordinal = rte_cpu_to_le_16(dir_ordinal);
3792 req.dir_ext = rte_cpu_to_le_16(dir_ext);
3793 req.dir_attr = rte_cpu_to_le_16(dir_attr);
3794 req.dir_data_length = rte_cpu_to_le_32(data_len);
3795 req.host_src_addr = rte_cpu_to_le_64(dma_handle);
3797 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3800 HWRM_CHECK_RESULT();
3807 bnxt_vnic_count(struct bnxt_vnic_info *vnic __rte_unused, void *cbdata)
3809 uint32_t *count = cbdata;
3811 *count = *count + 1;
3814 static int bnxt_vnic_count_hwrm_stub(struct bnxt *bp __rte_unused,
3815 struct bnxt_vnic_info *vnic __rte_unused)
3820 int bnxt_vf_vnic_count(struct bnxt *bp, uint16_t vf)
3824 bnxt_hwrm_func_vf_vnic_query_and_config(bp, vf, bnxt_vnic_count,
3825 &count, bnxt_vnic_count_hwrm_stub);
3830 static int bnxt_hwrm_func_vf_vnic_query(struct bnxt *bp, uint16_t vf,
3833 struct hwrm_func_vf_vnic_ids_query_input req = {0};
3834 struct hwrm_func_vf_vnic_ids_query_output *resp =
3835 bp->hwrm_cmd_resp_addr;
3838 /* First query all VNIC ids */
3839 HWRM_PREP(req, FUNC_VF_VNIC_IDS_QUERY, BNXT_USE_CHIMP_MB);
3841 req.vf_id = rte_cpu_to_le_16(bp->pf.first_vf_id + vf);
3842 req.max_vnic_id_cnt = rte_cpu_to_le_32(bp->pf.total_vnics);
3843 req.vnic_id_tbl_addr = rte_cpu_to_le_64(rte_mem_virt2iova(vnic_ids));
3845 if (req.vnic_id_tbl_addr == RTE_BAD_IOVA) {
3848 "unable to map VNIC ID table address to physical memory\n");
3851 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3852 HWRM_CHECK_RESULT();
3853 rc = rte_le_to_cpu_32(resp->vnic_id_cnt);
3861 * This function queries the VNIC IDs for a specified VF. It then calls
3862 * the vnic_cb to update the necessary field in vnic_info with cbdata.
3863 * Then it calls the hwrm_cb function to program this new vnic configuration.
3865 int bnxt_hwrm_func_vf_vnic_query_and_config(struct bnxt *bp, uint16_t vf,
3866 void (*vnic_cb)(struct bnxt_vnic_info *, void *), void *cbdata,
3867 int (*hwrm_cb)(struct bnxt *bp, struct bnxt_vnic_info *vnic))
3869 struct bnxt_vnic_info vnic;
3871 int i, num_vnic_ids;
3876 /* First query all VNIC ids */
3877 vnic_id_sz = bp->pf.total_vnics * sizeof(*vnic_ids);
3878 vnic_ids = rte_malloc("bnxt_hwrm_vf_vnic_ids_query", vnic_id_sz,
3879 RTE_CACHE_LINE_SIZE);
3880 if (vnic_ids == NULL)
3883 for (sz = 0; sz < vnic_id_sz; sz += getpagesize())
3884 rte_mem_lock_page(((char *)vnic_ids) + sz);
3886 num_vnic_ids = bnxt_hwrm_func_vf_vnic_query(bp, vf, vnic_ids);
3888 if (num_vnic_ids < 0)
3889 return num_vnic_ids;
3891 /* Retrieve VNIC, update bd_stall then update */
3893 for (i = 0; i < num_vnic_ids; i++) {
3894 memset(&vnic, 0, sizeof(struct bnxt_vnic_info));
3895 vnic.fw_vnic_id = rte_le_to_cpu_16(vnic_ids[i]);
3896 rc = bnxt_hwrm_vnic_qcfg(bp, &vnic, bp->pf.first_vf_id + vf);
3899 if (vnic.mru <= 4) /* Indicates unallocated */
3902 vnic_cb(&vnic, cbdata);
3904 rc = hwrm_cb(bp, &vnic);
3914 int bnxt_hwrm_func_cfg_vf_set_vlan_anti_spoof(struct bnxt *bp, uint16_t vf,
3917 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3918 struct hwrm_func_cfg_input req = {0};
3921 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
3923 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3924 req.enables |= rte_cpu_to_le_32(
3925 HWRM_FUNC_CFG_INPUT_ENABLES_VLAN_ANTISPOOF_MODE);
3926 req.vlan_antispoof_mode = on ?
3927 HWRM_FUNC_CFG_INPUT_VLAN_ANTISPOOF_MODE_VALIDATE_VLAN :
3928 HWRM_FUNC_CFG_INPUT_VLAN_ANTISPOOF_MODE_NOCHECK;
3929 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3931 HWRM_CHECK_RESULT();
3937 int bnxt_hwrm_func_qcfg_vf_dflt_vnic_id(struct bnxt *bp, int vf)
3939 struct bnxt_vnic_info vnic;
3942 int num_vnic_ids, i;
3946 vnic_id_sz = bp->pf.total_vnics * sizeof(*vnic_ids);
3947 vnic_ids = rte_malloc("bnxt_hwrm_vf_vnic_ids_query", vnic_id_sz,
3948 RTE_CACHE_LINE_SIZE);
3949 if (vnic_ids == NULL)
3952 for (sz = 0; sz < vnic_id_sz; sz += getpagesize())
3953 rte_mem_lock_page(((char *)vnic_ids) + sz);
3955 rc = bnxt_hwrm_func_vf_vnic_query(bp, vf, vnic_ids);
3961 * Loop through to find the default VNIC ID.
3962 * TODO: The easier way would be to obtain the resp->dflt_vnic_id
3963 * by sending the hwrm_func_qcfg command to the firmware.
3965 for (i = 0; i < num_vnic_ids; i++) {
3966 memset(&vnic, 0, sizeof(struct bnxt_vnic_info));
3967 vnic.fw_vnic_id = rte_le_to_cpu_16(vnic_ids[i]);
3968 rc = bnxt_hwrm_vnic_qcfg(bp, &vnic,
3969 bp->pf.first_vf_id + vf);
3972 if (vnic.func_default) {
3974 return vnic.fw_vnic_id;
3977 /* Could not find a default VNIC. */
3978 PMD_DRV_LOG(ERR, "No default VNIC\n");
3984 int bnxt_hwrm_set_em_filter(struct bnxt *bp,
3986 struct bnxt_filter_info *filter)
3989 struct hwrm_cfa_em_flow_alloc_input req = {.req_type = 0 };
3990 struct hwrm_cfa_em_flow_alloc_output *resp = bp->hwrm_cmd_resp_addr;
3991 uint32_t enables = 0;
3993 if (filter->fw_em_filter_id != UINT64_MAX)
3994 bnxt_hwrm_clear_em_filter(bp, filter);
3996 HWRM_PREP(req, CFA_EM_FLOW_ALLOC, BNXT_USE_KONG(bp));
3998 req.flags = rte_cpu_to_le_32(filter->flags);
4000 enables = filter->enables |
4001 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_ID;
4002 req.dst_id = rte_cpu_to_le_16(dst_id);
4004 if (filter->ip_addr_type) {
4005 req.ip_addr_type = filter->ip_addr_type;
4006 enables |= HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IPADDR_TYPE;
4009 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_L2_FILTER_ID)
4010 req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
4012 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_MACADDR)
4013 memcpy(req.src_macaddr, filter->src_macaddr,
4014 RTE_ETHER_ADDR_LEN);
4016 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_MACADDR)
4017 memcpy(req.dst_macaddr, filter->dst_macaddr,
4018 RTE_ETHER_ADDR_LEN);
4020 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_OVLAN_VID)
4021 req.ovlan_vid = filter->l2_ovlan;
4023 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IVLAN_VID)
4024 req.ivlan_vid = filter->l2_ivlan;
4026 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_ETHERTYPE)
4027 req.ethertype = rte_cpu_to_be_16(filter->ethertype);
4029 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IP_PROTOCOL)
4030 req.ip_protocol = filter->ip_protocol;
4032 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_IPADDR)
4033 req.src_ipaddr[0] = rte_cpu_to_be_32(filter->src_ipaddr[0]);
4035 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_IPADDR)
4036 req.dst_ipaddr[0] = rte_cpu_to_be_32(filter->dst_ipaddr[0]);
4038 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_PORT)
4039 req.src_port = rte_cpu_to_be_16(filter->src_port);
4041 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_PORT)
4042 req.dst_port = rte_cpu_to_be_16(filter->dst_port);
4044 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_MIRROR_VNIC_ID)
4045 req.mirror_vnic_id = filter->mirror_vnic_id;
4047 req.enables = rte_cpu_to_le_32(enables);
4049 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
4051 HWRM_CHECK_RESULT();
4053 filter->fw_em_filter_id = rte_le_to_cpu_64(resp->em_filter_id);
4059 int bnxt_hwrm_clear_em_filter(struct bnxt *bp, struct bnxt_filter_info *filter)
4062 struct hwrm_cfa_em_flow_free_input req = {.req_type = 0 };
4063 struct hwrm_cfa_em_flow_free_output *resp = bp->hwrm_cmd_resp_addr;
4065 if (filter->fw_em_filter_id == UINT64_MAX)
4068 PMD_DRV_LOG(ERR, "Clear EM filter\n");
4069 HWRM_PREP(req, CFA_EM_FLOW_FREE, BNXT_USE_KONG(bp));
4071 req.em_filter_id = rte_cpu_to_le_64(filter->fw_em_filter_id);
4073 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
4075 HWRM_CHECK_RESULT();
4078 filter->fw_em_filter_id = UINT64_MAX;
4079 filter->fw_l2_filter_id = UINT64_MAX;
4084 int bnxt_hwrm_set_ntuple_filter(struct bnxt *bp,
4086 struct bnxt_filter_info *filter)
4089 struct hwrm_cfa_ntuple_filter_alloc_input req = {.req_type = 0 };
4090 struct hwrm_cfa_ntuple_filter_alloc_output *resp =
4091 bp->hwrm_cmd_resp_addr;
4092 uint32_t enables = 0;
4094 if (filter->fw_ntuple_filter_id != UINT64_MAX)
4095 bnxt_hwrm_clear_ntuple_filter(bp, filter);
4097 HWRM_PREP(req, CFA_NTUPLE_FILTER_ALLOC, BNXT_USE_CHIMP_MB);
4099 req.flags = rte_cpu_to_le_32(filter->flags);
4101 enables = filter->enables |
4102 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_ID;
4103 req.dst_id = rte_cpu_to_le_16(dst_id);
4106 if (filter->ip_addr_type) {
4107 req.ip_addr_type = filter->ip_addr_type;
4109 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_IPADDR_TYPE;
4112 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_L2_FILTER_ID)
4113 req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
4115 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_MACADDR)
4116 memcpy(req.src_macaddr, filter->src_macaddr,
4117 RTE_ETHER_ADDR_LEN);
4119 //HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_MACADDR)
4120 //memcpy(req.dst_macaddr, filter->dst_macaddr,
4121 //RTE_ETHER_ADDR_LEN);
4123 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_ETHERTYPE)
4124 req.ethertype = rte_cpu_to_be_16(filter->ethertype);
4126 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_IP_PROTOCOL)
4127 req.ip_protocol = filter->ip_protocol;
4129 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_IPADDR)
4130 req.src_ipaddr[0] = rte_cpu_to_le_32(filter->src_ipaddr[0]);
4132 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_IPADDR_MASK)
4133 req.src_ipaddr_mask[0] =
4134 rte_cpu_to_le_32(filter->src_ipaddr_mask[0]);
4136 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_IPADDR)
4137 req.dst_ipaddr[0] = rte_cpu_to_le_32(filter->dst_ipaddr[0]);
4139 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_IPADDR_MASK)
4140 req.dst_ipaddr_mask[0] =
4141 rte_cpu_to_be_32(filter->dst_ipaddr_mask[0]);
4143 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_PORT)
4144 req.src_port = rte_cpu_to_le_16(filter->src_port);
4146 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_PORT_MASK)
4147 req.src_port_mask = rte_cpu_to_le_16(filter->src_port_mask);
4149 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_PORT)
4150 req.dst_port = rte_cpu_to_le_16(filter->dst_port);
4152 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_PORT_MASK)
4153 req.dst_port_mask = rte_cpu_to_le_16(filter->dst_port_mask);
4155 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_MIRROR_VNIC_ID)
4156 req.mirror_vnic_id = filter->mirror_vnic_id;
4158 req.enables = rte_cpu_to_le_32(enables);
4160 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4162 HWRM_CHECK_RESULT();
4164 filter->fw_ntuple_filter_id = rte_le_to_cpu_64(resp->ntuple_filter_id);
4170 int bnxt_hwrm_clear_ntuple_filter(struct bnxt *bp,
4171 struct bnxt_filter_info *filter)
4174 struct hwrm_cfa_ntuple_filter_free_input req = {.req_type = 0 };
4175 struct hwrm_cfa_ntuple_filter_free_output *resp =
4176 bp->hwrm_cmd_resp_addr;
4178 if (filter->fw_ntuple_filter_id == UINT64_MAX)
4181 HWRM_PREP(req, CFA_NTUPLE_FILTER_FREE, BNXT_USE_CHIMP_MB);
4183 req.ntuple_filter_id = rte_cpu_to_le_64(filter->fw_ntuple_filter_id);
4185 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4187 HWRM_CHECK_RESULT();
4190 filter->fw_ntuple_filter_id = UINT64_MAX;
4196 bnxt_vnic_rss_configure_thor(struct bnxt *bp, struct bnxt_vnic_info *vnic)
4198 struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
4199 uint8_t *rx_queue_state = bp->eth_dev->data->rx_queue_state;
4200 struct hwrm_vnic_rss_cfg_input req = {.req_type = 0 };
4201 struct bnxt_rx_queue **rxqs = bp->rx_queues;
4202 uint16_t *ring_tbl = vnic->rss_table;
4203 int nr_ctxs = vnic->num_lb_ctxts;
4204 int max_rings = bp->rx_nr_rings;
4208 for (i = 0, k = 0; i < nr_ctxs; i++) {
4209 struct bnxt_rx_ring_info *rxr;
4210 struct bnxt_cp_ring_info *cpr;
4212 HWRM_PREP(req, VNIC_RSS_CFG, BNXT_USE_CHIMP_MB);
4214 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
4215 req.hash_type = rte_cpu_to_le_32(vnic->hash_type);
4216 req.hash_mode_flags = vnic->hash_mode;
4218 req.ring_grp_tbl_addr =
4219 rte_cpu_to_le_64(vnic->rss_table_dma_addr +
4220 i * BNXT_RSS_ENTRIES_PER_CTX_THOR *
4221 2 * sizeof(*ring_tbl));
4222 req.hash_key_tbl_addr =
4223 rte_cpu_to_le_64(vnic->rss_hash_key_dma_addr);
4225 req.ring_table_pair_index = i;
4226 req.rss_ctx_idx = rte_cpu_to_le_16(vnic->fw_grp_ids[i]);
4228 for (j = 0; j < 64; j++) {
4231 /* Find next active ring. */
4232 for (cnt = 0; cnt < max_rings; cnt++) {
4233 if (rx_queue_state[k] !=
4234 RTE_ETH_QUEUE_STATE_STOPPED)
4236 if (++k == max_rings)
4240 /* Return if no rings are active. */
4241 if (cnt == max_rings)
4244 /* Add rx/cp ring pair to RSS table. */
4245 rxr = rxqs[k]->rx_ring;
4246 cpr = rxqs[k]->cp_ring;
4248 ring_id = rxr->rx_ring_struct->fw_ring_id;
4249 *ring_tbl++ = rte_cpu_to_le_16(ring_id);
4250 ring_id = cpr->cp_ring_struct->fw_ring_id;
4251 *ring_tbl++ = rte_cpu_to_le_16(ring_id);
4253 if (++k == max_rings)
4256 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req),
4259 HWRM_CHECK_RESULT();
4266 int bnxt_vnic_rss_configure(struct bnxt *bp, struct bnxt_vnic_info *vnic)
4268 unsigned int rss_idx, fw_idx, i;
4270 if (!(vnic->rss_table && vnic->hash_type))
4273 if (BNXT_CHIP_THOR(bp))
4274 return bnxt_vnic_rss_configure_thor(bp, vnic);
4277 * Fill the RSS hash & redirection table with
4278 * ring group ids for all VNICs
4280 for (rss_idx = 0, fw_idx = 0; rss_idx < HW_HASH_INDEX_SIZE;
4281 rss_idx++, fw_idx++) {
4282 for (i = 0; i < bp->rx_cp_nr_rings; i++) {
4283 fw_idx %= bp->rx_cp_nr_rings;
4284 if (vnic->fw_grp_ids[fw_idx] != INVALID_HW_RING_ID)
4288 if (i == bp->rx_cp_nr_rings)
4290 vnic->rss_table[rss_idx] = vnic->fw_grp_ids[fw_idx];
4292 return bnxt_hwrm_vnic_rss_cfg(bp, vnic);
4295 static void bnxt_hwrm_set_coal_params(struct bnxt_coal *hw_coal,
4296 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *req)
4300 req->num_cmpl_aggr_int = rte_cpu_to_le_16(hw_coal->num_cmpl_aggr_int);
4302 /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
4303 req->num_cmpl_dma_aggr = rte_cpu_to_le_16(hw_coal->num_cmpl_dma_aggr);
4305 /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
4306 req->num_cmpl_dma_aggr_during_int =
4307 rte_cpu_to_le_16(hw_coal->num_cmpl_dma_aggr_during_int);
4309 req->int_lat_tmr_max = rte_cpu_to_le_16(hw_coal->int_lat_tmr_max);
4311 /* min timer set to 1/2 of interrupt timer */
4312 req->int_lat_tmr_min = rte_cpu_to_le_16(hw_coal->int_lat_tmr_min);
4314 /* buf timer set to 1/4 of interrupt timer */
4315 req->cmpl_aggr_dma_tmr = rte_cpu_to_le_16(hw_coal->cmpl_aggr_dma_tmr);
4317 req->cmpl_aggr_dma_tmr_during_int =
4318 rte_cpu_to_le_16(hw_coal->cmpl_aggr_dma_tmr_during_int);
4320 flags = HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_TIMER_RESET |
4321 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_RING_IDLE;
4322 req->flags = rte_cpu_to_le_16(flags);
4325 static int bnxt_hwrm_set_coal_params_thor(struct bnxt *bp,
4326 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *agg_req)
4328 struct hwrm_ring_aggint_qcaps_input req = {0};
4329 struct hwrm_ring_aggint_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
4334 HWRM_PREP(req, RING_AGGINT_QCAPS, BNXT_USE_CHIMP_MB);
4335 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4336 HWRM_CHECK_RESULT();
4338 agg_req->num_cmpl_dma_aggr = resp->num_cmpl_dma_aggr_max;
4339 agg_req->cmpl_aggr_dma_tmr = resp->cmpl_aggr_dma_tmr_min;
4341 flags = HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_TIMER_RESET |
4342 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_RING_IDLE;
4343 agg_req->flags = rte_cpu_to_le_16(flags);
4345 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_ENABLES_CMPL_AGGR_DMA_TMR |
4346 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_ENABLES_NUM_CMPL_DMA_AGGR;
4347 agg_req->enables = rte_cpu_to_le_32(enables);
4353 int bnxt_hwrm_set_ring_coal(struct bnxt *bp,
4354 struct bnxt_coal *coal, uint16_t ring_id)
4356 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req = {0};
4357 struct hwrm_ring_cmpl_ring_cfg_aggint_params_output *resp =
4358 bp->hwrm_cmd_resp_addr;
4361 /* Set ring coalesce parameters only for 100G NICs */
4362 if (BNXT_CHIP_THOR(bp)) {
4363 if (bnxt_hwrm_set_coal_params_thor(bp, &req))
4365 } else if (bnxt_stratus_device(bp)) {
4366 bnxt_hwrm_set_coal_params(coal, &req);
4371 HWRM_PREP(req, RING_CMPL_RING_CFG_AGGINT_PARAMS, BNXT_USE_CHIMP_MB);
4372 req.ring_id = rte_cpu_to_le_16(ring_id);
4373 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4374 HWRM_CHECK_RESULT();
4379 #define BNXT_RTE_MEMZONE_FLAG (RTE_MEMZONE_1GB | RTE_MEMZONE_IOVA_CONTIG)
4380 int bnxt_hwrm_func_backing_store_qcaps(struct bnxt *bp)
4382 struct hwrm_func_backing_store_qcaps_input req = {0};
4383 struct hwrm_func_backing_store_qcaps_output *resp =
4384 bp->hwrm_cmd_resp_addr;
4387 if (!BNXT_CHIP_THOR(bp) ||
4388 bp->hwrm_spec_code < HWRM_VERSION_1_9_2 ||
4393 HWRM_PREP(req, FUNC_BACKING_STORE_QCAPS, BNXT_USE_CHIMP_MB);
4394 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4395 HWRM_CHECK_RESULT_SILENT();
4398 struct bnxt_ctx_pg_info *ctx_pg;
4399 struct bnxt_ctx_mem_info *ctx;
4400 int total_alloc_len;
4403 total_alloc_len = sizeof(*ctx);
4404 ctx = rte_malloc("bnxt_ctx_mem", total_alloc_len,
4405 RTE_CACHE_LINE_SIZE);
4410 memset(ctx, 0, total_alloc_len);
4412 ctx_pg = rte_malloc("bnxt_ctx_pg_mem",
4413 sizeof(*ctx_pg) * BNXT_MAX_Q,
4414 RTE_CACHE_LINE_SIZE);
4419 for (i = 0; i < BNXT_MAX_Q; i++, ctx_pg++)
4420 ctx->tqm_mem[i] = ctx_pg;
4423 ctx->qp_max_entries = rte_le_to_cpu_32(resp->qp_max_entries);
4424 ctx->qp_min_qp1_entries =
4425 rte_le_to_cpu_16(resp->qp_min_qp1_entries);
4426 ctx->qp_max_l2_entries =
4427 rte_le_to_cpu_16(resp->qp_max_l2_entries);
4428 ctx->qp_entry_size = rte_le_to_cpu_16(resp->qp_entry_size);
4429 ctx->srq_max_l2_entries =
4430 rte_le_to_cpu_16(resp->srq_max_l2_entries);
4431 ctx->srq_max_entries = rte_le_to_cpu_32(resp->srq_max_entries);
4432 ctx->srq_entry_size = rte_le_to_cpu_16(resp->srq_entry_size);
4433 ctx->cq_max_l2_entries =
4434 rte_le_to_cpu_16(resp->cq_max_l2_entries);
4435 ctx->cq_max_entries = rte_le_to_cpu_32(resp->cq_max_entries);
4436 ctx->cq_entry_size = rte_le_to_cpu_16(resp->cq_entry_size);
4437 ctx->vnic_max_vnic_entries =
4438 rte_le_to_cpu_16(resp->vnic_max_vnic_entries);
4439 ctx->vnic_max_ring_table_entries =
4440 rte_le_to_cpu_16(resp->vnic_max_ring_table_entries);
4441 ctx->vnic_entry_size = rte_le_to_cpu_16(resp->vnic_entry_size);
4442 ctx->stat_max_entries =
4443 rte_le_to_cpu_32(resp->stat_max_entries);
4444 ctx->stat_entry_size = rte_le_to_cpu_16(resp->stat_entry_size);
4445 ctx->tqm_entry_size = rte_le_to_cpu_16(resp->tqm_entry_size);
4446 ctx->tqm_min_entries_per_ring =
4447 rte_le_to_cpu_32(resp->tqm_min_entries_per_ring);
4448 ctx->tqm_max_entries_per_ring =
4449 rte_le_to_cpu_32(resp->tqm_max_entries_per_ring);
4450 ctx->tqm_entries_multiple = resp->tqm_entries_multiple;
4451 if (!ctx->tqm_entries_multiple)
4452 ctx->tqm_entries_multiple = 1;
4453 ctx->mrav_max_entries =
4454 rte_le_to_cpu_32(resp->mrav_max_entries);
4455 ctx->mrav_entry_size = rte_le_to_cpu_16(resp->mrav_entry_size);
4456 ctx->tim_entry_size = rte_le_to_cpu_16(resp->tim_entry_size);
4457 ctx->tim_max_entries = rte_le_to_cpu_32(resp->tim_max_entries);
4466 int bnxt_hwrm_func_backing_store_cfg(struct bnxt *bp, uint32_t enables)
4468 struct hwrm_func_backing_store_cfg_input req = {0};
4469 struct hwrm_func_backing_store_cfg_output *resp =
4470 bp->hwrm_cmd_resp_addr;
4471 struct bnxt_ctx_mem_info *ctx = bp->ctx;
4472 struct bnxt_ctx_pg_info *ctx_pg;
4473 uint32_t *num_entries;
4482 HWRM_PREP(req, FUNC_BACKING_STORE_CFG, BNXT_USE_CHIMP_MB);
4483 req.enables = rte_cpu_to_le_32(enables);
4485 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_QP) {
4486 ctx_pg = &ctx->qp_mem;
4487 req.qp_num_entries = rte_cpu_to_le_32(ctx_pg->entries);
4488 req.qp_num_qp1_entries =
4489 rte_cpu_to_le_16(ctx->qp_min_qp1_entries);
4490 req.qp_num_l2_entries =
4491 rte_cpu_to_le_16(ctx->qp_max_l2_entries);
4492 req.qp_entry_size = rte_cpu_to_le_16(ctx->qp_entry_size);
4493 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4494 &req.qpc_pg_size_qpc_lvl,
4498 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_SRQ) {
4499 ctx_pg = &ctx->srq_mem;
4500 req.srq_num_entries = rte_cpu_to_le_32(ctx_pg->entries);
4501 req.srq_num_l2_entries =
4502 rte_cpu_to_le_16(ctx->srq_max_l2_entries);
4503 req.srq_entry_size = rte_cpu_to_le_16(ctx->srq_entry_size);
4504 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4505 &req.srq_pg_size_srq_lvl,
4509 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_CQ) {
4510 ctx_pg = &ctx->cq_mem;
4511 req.cq_num_entries = rte_cpu_to_le_32(ctx_pg->entries);
4512 req.cq_num_l2_entries =
4513 rte_cpu_to_le_16(ctx->cq_max_l2_entries);
4514 req.cq_entry_size = rte_cpu_to_le_16(ctx->cq_entry_size);
4515 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4516 &req.cq_pg_size_cq_lvl,
4520 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_VNIC) {
4521 ctx_pg = &ctx->vnic_mem;
4522 req.vnic_num_vnic_entries =
4523 rte_cpu_to_le_16(ctx->vnic_max_vnic_entries);
4524 req.vnic_num_ring_table_entries =
4525 rte_cpu_to_le_16(ctx->vnic_max_ring_table_entries);
4526 req.vnic_entry_size = rte_cpu_to_le_16(ctx->vnic_entry_size);
4527 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4528 &req.vnic_pg_size_vnic_lvl,
4529 &req.vnic_page_dir);
4532 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_STAT) {
4533 ctx_pg = &ctx->stat_mem;
4534 req.stat_num_entries = rte_cpu_to_le_16(ctx->stat_max_entries);
4535 req.stat_entry_size = rte_cpu_to_le_16(ctx->stat_entry_size);
4536 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4537 &req.stat_pg_size_stat_lvl,
4538 &req.stat_page_dir);
4541 req.tqm_entry_size = rte_cpu_to_le_16(ctx->tqm_entry_size);
4542 num_entries = &req.tqm_sp_num_entries;
4543 pg_attr = &req.tqm_sp_pg_size_tqm_sp_lvl;
4544 pg_dir = &req.tqm_sp_page_dir;
4545 ena = HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_TQM_SP;
4546 for (i = 0; i < 9; i++, num_entries++, pg_attr++, pg_dir++, ena <<= 1) {
4547 if (!(enables & ena))
4550 req.tqm_entry_size = rte_cpu_to_le_16(ctx->tqm_entry_size);
4552 ctx_pg = ctx->tqm_mem[i];
4553 *num_entries = rte_cpu_to_le_16(ctx_pg->entries);
4554 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem, pg_attr, pg_dir);
4557 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4558 HWRM_CHECK_RESULT();
4564 int bnxt_hwrm_ext_port_qstats(struct bnxt *bp)
4566 struct hwrm_port_qstats_ext_input req = {0};
4567 struct hwrm_port_qstats_ext_output *resp = bp->hwrm_cmd_resp_addr;
4568 struct bnxt_pf_info *pf = &bp->pf;
4571 if (!(bp->flags & BNXT_FLAG_EXT_RX_PORT_STATS ||
4572 bp->flags & BNXT_FLAG_EXT_TX_PORT_STATS))
4575 HWRM_PREP(req, PORT_QSTATS_EXT, BNXT_USE_CHIMP_MB);
4577 req.port_id = rte_cpu_to_le_16(pf->port_id);
4578 if (bp->flags & BNXT_FLAG_EXT_TX_PORT_STATS) {
4579 req.tx_stat_host_addr =
4580 rte_cpu_to_le_64(bp->hw_tx_port_stats_ext_map);
4582 rte_cpu_to_le_16(sizeof(struct tx_port_stats_ext));
4584 if (bp->flags & BNXT_FLAG_EXT_RX_PORT_STATS) {
4585 req.rx_stat_host_addr =
4586 rte_cpu_to_le_64(bp->hw_rx_port_stats_ext_map);
4588 rte_cpu_to_le_16(sizeof(struct rx_port_stats_ext));
4590 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4593 bp->fw_rx_port_stats_ext_size = 0;
4594 bp->fw_tx_port_stats_ext_size = 0;
4596 bp->fw_rx_port_stats_ext_size =
4597 rte_le_to_cpu_16(resp->rx_stat_size);
4598 bp->fw_tx_port_stats_ext_size =
4599 rte_le_to_cpu_16(resp->tx_stat_size);
4602 HWRM_CHECK_RESULT();
4609 bnxt_hwrm_tunnel_redirect(struct bnxt *bp, uint8_t type)
4611 struct hwrm_cfa_redirect_tunnel_type_alloc_input req = {0};
4612 struct hwrm_cfa_redirect_tunnel_type_alloc_output *resp =
4613 bp->hwrm_cmd_resp_addr;
4616 HWRM_PREP(req, CFA_REDIRECT_TUNNEL_TYPE_ALLOC, BNXT_USE_CHIMP_MB);
4617 req.tunnel_type = type;
4618 req.dest_fid = bp->fw_fid;
4619 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4620 HWRM_CHECK_RESULT();
4628 bnxt_hwrm_tunnel_redirect_free(struct bnxt *bp, uint8_t type)
4630 struct hwrm_cfa_redirect_tunnel_type_free_input req = {0};
4631 struct hwrm_cfa_redirect_tunnel_type_free_output *resp =
4632 bp->hwrm_cmd_resp_addr;
4635 HWRM_PREP(req, CFA_REDIRECT_TUNNEL_TYPE_FREE, BNXT_USE_CHIMP_MB);
4636 req.tunnel_type = type;
4637 req.dest_fid = bp->fw_fid;
4638 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4639 HWRM_CHECK_RESULT();
4646 int bnxt_hwrm_tunnel_redirect_query(struct bnxt *bp, uint32_t *type)
4648 struct hwrm_cfa_redirect_query_tunnel_type_input req = {0};
4649 struct hwrm_cfa_redirect_query_tunnel_type_output *resp =
4650 bp->hwrm_cmd_resp_addr;
4653 HWRM_PREP(req, CFA_REDIRECT_QUERY_TUNNEL_TYPE, BNXT_USE_CHIMP_MB);
4654 req.src_fid = bp->fw_fid;
4655 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4656 HWRM_CHECK_RESULT();
4659 *type = rte_le_to_cpu_32(resp->tunnel_mask);
4666 int bnxt_hwrm_tunnel_redirect_info(struct bnxt *bp, uint8_t tun_type,
4669 struct hwrm_cfa_redirect_tunnel_type_info_input req = {0};
4670 struct hwrm_cfa_redirect_tunnel_type_info_output *resp =
4671 bp->hwrm_cmd_resp_addr;
4674 HWRM_PREP(req, CFA_REDIRECT_TUNNEL_TYPE_INFO, BNXT_USE_CHIMP_MB);
4675 req.src_fid = bp->fw_fid;
4676 req.tunnel_type = tun_type;
4677 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4678 HWRM_CHECK_RESULT();
4681 *dst_fid = rte_le_to_cpu_16(resp->dest_fid);
4683 PMD_DRV_LOG(DEBUG, "dst_fid: %x\n", resp->dest_fid);
4690 int bnxt_hwrm_set_mac(struct bnxt *bp)
4692 struct hwrm_func_vf_cfg_output *resp = bp->hwrm_cmd_resp_addr;
4693 struct hwrm_func_vf_cfg_input req = {0};
4699 HWRM_PREP(req, FUNC_VF_CFG, BNXT_USE_CHIMP_MB);
4702 rte_cpu_to_le_32(HWRM_FUNC_VF_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
4703 memcpy(req.dflt_mac_addr, bp->mac_addr, RTE_ETHER_ADDR_LEN);
4705 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4707 HWRM_CHECK_RESULT();
4709 memcpy(bp->dflt_mac_addr, bp->mac_addr, RTE_ETHER_ADDR_LEN);
4715 int bnxt_hwrm_if_change(struct bnxt *bp, bool up)
4717 struct hwrm_func_drv_if_change_output *resp = bp->hwrm_cmd_resp_addr;
4718 struct hwrm_func_drv_if_change_input req = {0};
4722 if (!(bp->flags & BNXT_FLAG_FW_CAP_IF_CHANGE))
4725 /* Do not issue FUNC_DRV_IF_CHANGE during reset recovery.
4726 * If we issue FUNC_DRV_IF_CHANGE with flags down before
4727 * FUNC_DRV_UNRGTR, FW resets before FUNC_DRV_UNRGTR
4729 if (!up && (bp->flags & BNXT_FLAG_FW_RESET))
4732 HWRM_PREP(req, FUNC_DRV_IF_CHANGE, BNXT_USE_CHIMP_MB);
4736 rte_cpu_to_le_32(HWRM_FUNC_DRV_IF_CHANGE_INPUT_FLAGS_UP);
4738 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4740 HWRM_CHECK_RESULT();
4741 flags = rte_le_to_cpu_32(resp->flags);
4744 if (flags & HWRM_FUNC_DRV_IF_CHANGE_OUTPUT_FLAGS_HOT_FW_RESET_DONE) {
4745 PMD_DRV_LOG(INFO, "FW reset happened while port was down\n");
4746 bp->flags |= BNXT_FLAG_IF_CHANGE_HOT_FW_RESET_DONE;
4752 int bnxt_hwrm_error_recovery_qcfg(struct bnxt *bp)
4754 struct hwrm_error_recovery_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
4755 struct bnxt_error_recovery_info *info = bp->recovery_info;
4756 struct hwrm_error_recovery_qcfg_input req = {0};
4761 /* Older FW does not have error recovery support */
4762 if (!(bp->flags & BNXT_FLAG_FW_CAP_ERROR_RECOVERY))
4766 info = rte_zmalloc("bnxt_hwrm_error_recovery_qcfg",
4768 bp->recovery_info = info;
4772 memset(info, 0, sizeof(*info));
4775 HWRM_PREP(req, ERROR_RECOVERY_QCFG, BNXT_USE_CHIMP_MB);
4777 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4779 HWRM_CHECK_RESULT();
4781 flags = rte_le_to_cpu_32(resp->flags);
4782 if (flags & HWRM_ERROR_RECOVERY_QCFG_OUTPUT_FLAGS_HOST)
4783 info->flags |= BNXT_FLAG_ERROR_RECOVERY_HOST;
4784 else if (flags & HWRM_ERROR_RECOVERY_QCFG_OUTPUT_FLAGS_CO_CPU)
4785 info->flags |= BNXT_FLAG_ERROR_RECOVERY_CO_CPU;
4787 if ((info->flags & BNXT_FLAG_ERROR_RECOVERY_CO_CPU) &&
4788 !(bp->flags & BNXT_FLAG_KONG_MB_EN)) {
4793 /* FW returned values are in units of 100msec */
4794 info->driver_polling_freq =
4795 rte_le_to_cpu_32(resp->driver_polling_freq) * 100;
4796 info->master_func_wait_period =
4797 rte_le_to_cpu_32(resp->master_func_wait_period) * 100;
4798 info->normal_func_wait_period =
4799 rte_le_to_cpu_32(resp->normal_func_wait_period) * 100;
4800 info->master_func_wait_period_after_reset =
4801 rte_le_to_cpu_32(resp->master_func_wait_period_after_reset) * 100;
4802 info->max_bailout_time_after_reset =
4803 rte_le_to_cpu_32(resp->max_bailout_time_after_reset) * 100;
4804 info->status_regs[BNXT_FW_STATUS_REG] =
4805 rte_le_to_cpu_32(resp->fw_health_status_reg);
4806 info->status_regs[BNXT_FW_HEARTBEAT_CNT_REG] =
4807 rte_le_to_cpu_32(resp->fw_heartbeat_reg);
4808 info->status_regs[BNXT_FW_RECOVERY_CNT_REG] =
4809 rte_le_to_cpu_32(resp->fw_reset_cnt_reg);
4810 info->status_regs[BNXT_FW_RESET_INPROG_REG] =
4811 rte_le_to_cpu_32(resp->reset_inprogress_reg);
4812 info->reg_array_cnt =
4813 rte_le_to_cpu_32(resp->reg_array_cnt);
4815 if (info->reg_array_cnt >= BNXT_NUM_RESET_REG) {
4820 for (i = 0; i < info->reg_array_cnt; i++) {
4821 info->reset_reg[i] =
4822 rte_le_to_cpu_32(resp->reset_reg[i]);
4823 info->reset_reg_val[i] =
4824 rte_le_to_cpu_32(resp->reset_reg_val[i]);
4825 info->delay_after_reset[i] =
4826 resp->delay_after_reset[i];
4831 /* Map the FW status registers */
4833 rc = bnxt_map_fw_health_status_regs(bp);
4836 rte_free(bp->recovery_info);
4837 bp->recovery_info = NULL;
4842 int bnxt_hwrm_fw_reset(struct bnxt *bp)
4844 struct hwrm_fw_reset_output *resp = bp->hwrm_cmd_resp_addr;
4845 struct hwrm_fw_reset_input req = {0};
4851 HWRM_PREP(req, FW_RESET, BNXT_USE_KONG(bp));
4853 req.embedded_proc_type =
4854 HWRM_FW_RESET_INPUT_EMBEDDED_PROC_TYPE_CHIP;
4855 req.selfrst_status =
4856 HWRM_FW_RESET_INPUT_SELFRST_STATUS_SELFRSTASAP;
4857 req.flags = HWRM_FW_RESET_INPUT_FLAGS_RESET_GRACEFUL;
4859 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req),
4862 HWRM_CHECK_RESULT();
4868 int bnxt_hwrm_port_ts_query(struct bnxt *bp, uint8_t path, uint64_t *timestamp)
4870 struct hwrm_port_ts_query_output *resp = bp->hwrm_cmd_resp_addr;
4871 struct hwrm_port_ts_query_input req = {0};
4872 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
4879 HWRM_PREP(req, PORT_TS_QUERY, BNXT_USE_CHIMP_MB);
4882 case BNXT_PTP_FLAGS_PATH_TX:
4883 flags |= HWRM_PORT_TS_QUERY_INPUT_FLAGS_PATH_TX;
4885 case BNXT_PTP_FLAGS_PATH_RX:
4886 flags |= HWRM_PORT_TS_QUERY_INPUT_FLAGS_PATH_RX;
4888 case BNXT_PTP_FLAGS_CURRENT_TIME:
4889 flags |= HWRM_PORT_TS_QUERY_INPUT_FLAGS_CURRENT_TIME;
4893 req.flags = rte_cpu_to_le_32(flags);
4894 req.port_id = rte_cpu_to_le_16(bp->pf.port_id);
4896 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4898 HWRM_CHECK_RESULT();
4901 *timestamp = rte_le_to_cpu_32(resp->ptp_msg_ts[0]);
4903 (uint64_t)(rte_le_to_cpu_32(resp->ptp_msg_ts[1])) << 32;