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) \
222 else if (rc == HWRM_ERR_CODE_RESOURCE_ALLOC_ERROR) \
224 else if (rc == HWRM_ERR_CODE_INVALID_PARAMS) \
226 else if (rc == HWRM_ERR_CODE_CMD_NOT_SUPPORTED) \
232 if (resp->error_code) { \
233 rc = rte_le_to_cpu_16(resp->error_code); \
234 if (resp->resp_len >= 16) { \
235 struct hwrm_err_output *tmp_hwrm_err_op = \
238 "error %d:%d:%08x:%04x\n", \
239 rc, tmp_hwrm_err_op->cmd_err, \
241 tmp_hwrm_err_op->opaque_0), \
243 tmp_hwrm_err_op->opaque_1)); \
245 PMD_DRV_LOG(ERR, "error %d\n", rc); \
247 rte_spinlock_unlock(&bp->hwrm_lock); \
248 if (rc == HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED) \
250 else if (rc == HWRM_ERR_CODE_RESOURCE_ALLOC_ERROR) \
252 else if (rc == HWRM_ERR_CODE_INVALID_PARAMS) \
254 else if (rc == HWRM_ERR_CODE_CMD_NOT_SUPPORTED) \
262 #define HWRM_UNLOCK() rte_spinlock_unlock(&bp->hwrm_lock)
264 int bnxt_hwrm_cfa_l2_clear_rx_mask(struct bnxt *bp, struct bnxt_vnic_info *vnic)
267 struct hwrm_cfa_l2_set_rx_mask_input req = {.req_type = 0 };
268 struct hwrm_cfa_l2_set_rx_mask_output *resp = bp->hwrm_cmd_resp_addr;
270 HWRM_PREP(req, CFA_L2_SET_RX_MASK, BNXT_USE_CHIMP_MB);
271 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
274 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
282 int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp,
283 struct bnxt_vnic_info *vnic,
285 struct bnxt_vlan_table_entry *vlan_table)
288 struct hwrm_cfa_l2_set_rx_mask_input req = {.req_type = 0 };
289 struct hwrm_cfa_l2_set_rx_mask_output *resp = bp->hwrm_cmd_resp_addr;
292 if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
295 HWRM_PREP(req, CFA_L2_SET_RX_MASK, BNXT_USE_CHIMP_MB);
296 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
298 /* FIXME add multicast flag, when multicast adding options is supported
301 if (vnic->flags & BNXT_VNIC_INFO_BCAST)
302 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_BCAST;
303 if (vnic->flags & BNXT_VNIC_INFO_UNTAGGED)
304 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLAN_NONVLAN;
305 if (vnic->flags & BNXT_VNIC_INFO_PROMISC)
306 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_PROMISCUOUS;
307 if (vnic->flags & BNXT_VNIC_INFO_ALLMULTI)
308 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
309 if (vnic->flags & BNXT_VNIC_INFO_MCAST)
310 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_MCAST;
311 if (vnic->mc_addr_cnt) {
312 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_MCAST;
313 req.num_mc_entries = rte_cpu_to_le_32(vnic->mc_addr_cnt);
314 req.mc_tbl_addr = rte_cpu_to_le_64(vnic->mc_list_dma_addr);
317 if (!(mask & HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLAN_NONVLAN))
318 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLANONLY;
319 req.vlan_tag_tbl_addr = rte_cpu_to_le_64(
320 rte_mem_virt2iova(vlan_table));
321 req.num_vlan_tags = rte_cpu_to_le_32((uint32_t)vlan_count);
323 req.mask = rte_cpu_to_le_32(mask);
325 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
333 int bnxt_hwrm_cfa_vlan_antispoof_cfg(struct bnxt *bp, uint16_t fid,
335 struct bnxt_vlan_antispoof_table_entry *vlan_table)
338 struct hwrm_cfa_vlan_antispoof_cfg_input req = {.req_type = 0 };
339 struct hwrm_cfa_vlan_antispoof_cfg_output *resp =
340 bp->hwrm_cmd_resp_addr;
343 * Older HWRM versions did not support this command, and the set_rx_mask
344 * list was used for anti-spoof. In 1.8.0, the TX path configuration was
345 * removed from set_rx_mask call, and this command was added.
347 * This command is also present from 1.7.8.11 and higher,
350 if (bp->fw_ver < ((1 << 24) | (8 << 16))) {
351 if (bp->fw_ver != ((1 << 24) | (7 << 16) | (8 << 8))) {
352 if (bp->fw_ver < ((1 << 24) | (7 << 16) | (8 << 8) |
357 HWRM_PREP(req, CFA_VLAN_ANTISPOOF_CFG, BNXT_USE_CHIMP_MB);
358 req.fid = rte_cpu_to_le_16(fid);
360 req.vlan_tag_mask_tbl_addr =
361 rte_cpu_to_le_64(rte_mem_virt2iova(vlan_table));
362 req.num_vlan_entries = rte_cpu_to_le_32((uint32_t)vlan_count);
364 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
372 int bnxt_hwrm_clear_l2_filter(struct bnxt *bp,
373 struct bnxt_filter_info *filter)
376 struct hwrm_cfa_l2_filter_free_input req = {.req_type = 0 };
377 struct hwrm_cfa_l2_filter_free_output *resp = bp->hwrm_cmd_resp_addr;
379 if (filter->fw_l2_filter_id == UINT64_MAX)
382 HWRM_PREP(req, CFA_L2_FILTER_FREE, BNXT_USE_CHIMP_MB);
384 req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
386 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
391 filter->fw_l2_filter_id = UINT64_MAX;
396 int bnxt_hwrm_set_l2_filter(struct bnxt *bp,
398 struct bnxt_filter_info *filter)
401 struct hwrm_cfa_l2_filter_alloc_input req = {.req_type = 0 };
402 struct hwrm_cfa_l2_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr;
403 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
404 const struct rte_eth_vmdq_rx_conf *conf =
405 &dev_conf->rx_adv_conf.vmdq_rx_conf;
406 uint32_t enables = 0;
407 uint16_t j = dst_id - 1;
409 //TODO: Is there a better way to add VLANs to each VNIC in case of VMDQ
410 if ((dev_conf->rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG) &&
411 conf->pool_map[j].pools & (1UL << j)) {
413 "Add vlan %u to vmdq pool %u\n",
414 conf->pool_map[j].vlan_id, j);
416 filter->l2_ivlan = conf->pool_map[j].vlan_id;
418 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN |
419 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN_MASK;
422 if (filter->fw_l2_filter_id != UINT64_MAX)
423 bnxt_hwrm_clear_l2_filter(bp, filter);
425 HWRM_PREP(req, CFA_L2_FILTER_ALLOC, BNXT_USE_CHIMP_MB);
427 req.flags = rte_cpu_to_le_32(filter->flags);
429 rte_cpu_to_le_32(HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_OUTERMOST);
431 enables = filter->enables |
432 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_DST_ID;
433 req.dst_id = rte_cpu_to_le_16(dst_id);
436 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR)
437 memcpy(req.l2_addr, filter->l2_addr,
440 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR_MASK)
441 memcpy(req.l2_addr_mask, filter->l2_addr_mask,
444 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN)
445 req.l2_ovlan = filter->l2_ovlan;
447 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN)
448 req.l2_ivlan = filter->l2_ivlan;
450 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN_MASK)
451 req.l2_ovlan_mask = filter->l2_ovlan_mask;
453 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN_MASK)
454 req.l2_ivlan_mask = filter->l2_ivlan_mask;
455 if (enables & HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_SRC_ID)
456 req.src_id = rte_cpu_to_le_32(filter->src_id);
457 if (enables & HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_SRC_TYPE)
458 req.src_type = filter->src_type;
460 req.enables = rte_cpu_to_le_32(enables);
462 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
466 filter->fw_l2_filter_id = rte_le_to_cpu_64(resp->l2_filter_id);
472 int bnxt_hwrm_ptp_cfg(struct bnxt *bp)
474 struct hwrm_port_mac_cfg_input req = {.req_type = 0};
475 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
482 HWRM_PREP(req, PORT_MAC_CFG, BNXT_USE_CHIMP_MB);
485 flags |= HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_RX_TS_CAPTURE_ENABLE;
488 HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_RX_TS_CAPTURE_DISABLE;
489 if (ptp->tx_tstamp_en)
490 flags |= HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_TX_TS_CAPTURE_ENABLE;
493 HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_TX_TS_CAPTURE_DISABLE;
494 req.flags = rte_cpu_to_le_32(flags);
495 req.enables = rte_cpu_to_le_32
496 (HWRM_PORT_MAC_CFG_INPUT_ENABLES_RX_TS_CAPTURE_PTP_MSG_TYPE);
497 req.rx_ts_capture_ptp_msg_type = rte_cpu_to_le_16(ptp->rxctl);
499 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
505 static int bnxt_hwrm_ptp_qcfg(struct bnxt *bp)
508 struct hwrm_port_mac_ptp_qcfg_input req = {.req_type = 0};
509 struct hwrm_port_mac_ptp_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
510 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
512 /* if (bp->hwrm_spec_code < 0x10801 || ptp) TBD */
516 HWRM_PREP(req, PORT_MAC_PTP_QCFG, BNXT_USE_CHIMP_MB);
518 req.port_id = rte_cpu_to_le_16(bp->pf.port_id);
520 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
524 if (!BNXT_CHIP_THOR(bp) &&
525 !(resp->flags & HWRM_PORT_MAC_PTP_QCFG_OUTPUT_FLAGS_DIRECT_ACCESS))
528 if (resp->flags & HWRM_PORT_MAC_PTP_QCFG_OUTPUT_FLAGS_ONE_STEP_TX_TS)
529 bp->flags |= BNXT_FLAG_FW_CAP_ONE_STEP_TX_TS;
531 ptp = rte_zmalloc("ptp_cfg", sizeof(*ptp), 0);
535 if (!BNXT_CHIP_THOR(bp)) {
536 ptp->rx_regs[BNXT_PTP_RX_TS_L] =
537 rte_le_to_cpu_32(resp->rx_ts_reg_off_lower);
538 ptp->rx_regs[BNXT_PTP_RX_TS_H] =
539 rte_le_to_cpu_32(resp->rx_ts_reg_off_upper);
540 ptp->rx_regs[BNXT_PTP_RX_SEQ] =
541 rte_le_to_cpu_32(resp->rx_ts_reg_off_seq_id);
542 ptp->rx_regs[BNXT_PTP_RX_FIFO] =
543 rte_le_to_cpu_32(resp->rx_ts_reg_off_fifo);
544 ptp->rx_regs[BNXT_PTP_RX_FIFO_ADV] =
545 rte_le_to_cpu_32(resp->rx_ts_reg_off_fifo_adv);
546 ptp->tx_regs[BNXT_PTP_TX_TS_L] =
547 rte_le_to_cpu_32(resp->tx_ts_reg_off_lower);
548 ptp->tx_regs[BNXT_PTP_TX_TS_H] =
549 rte_le_to_cpu_32(resp->tx_ts_reg_off_upper);
550 ptp->tx_regs[BNXT_PTP_TX_SEQ] =
551 rte_le_to_cpu_32(resp->tx_ts_reg_off_seq_id);
552 ptp->tx_regs[BNXT_PTP_TX_FIFO] =
553 rte_le_to_cpu_32(resp->tx_ts_reg_off_fifo);
562 static int __bnxt_hwrm_func_qcaps(struct bnxt *bp)
565 struct hwrm_func_qcaps_input req = {.req_type = 0 };
566 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
567 uint16_t new_max_vfs;
571 HWRM_PREP(req, FUNC_QCAPS, BNXT_USE_CHIMP_MB);
573 req.fid = rte_cpu_to_le_16(0xffff);
575 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
579 bp->max_ring_grps = rte_le_to_cpu_32(resp->max_hw_ring_grps);
580 flags = rte_le_to_cpu_32(resp->flags);
582 bp->pf.port_id = resp->port_id;
583 bp->pf.first_vf_id = rte_le_to_cpu_16(resp->first_vf_id);
584 bp->pf.total_vfs = rte_le_to_cpu_16(resp->max_vfs);
585 new_max_vfs = bp->pdev->max_vfs;
586 if (new_max_vfs != bp->pf.max_vfs) {
588 rte_free(bp->pf.vf_info);
589 bp->pf.vf_info = rte_malloc("bnxt_vf_info",
590 sizeof(bp->pf.vf_info[0]) * new_max_vfs, 0);
591 bp->pf.max_vfs = new_max_vfs;
592 for (i = 0; i < new_max_vfs; i++) {
593 bp->pf.vf_info[i].fid = bp->pf.first_vf_id + i;
594 bp->pf.vf_info[i].vlan_table =
595 rte_zmalloc("VF VLAN table",
598 if (bp->pf.vf_info[i].vlan_table == NULL)
600 "Fail to alloc VLAN table for VF %d\n",
604 bp->pf.vf_info[i].vlan_table);
605 bp->pf.vf_info[i].vlan_as_table =
606 rte_zmalloc("VF VLAN AS table",
609 if (bp->pf.vf_info[i].vlan_as_table == NULL)
611 "Alloc VLAN AS table for VF %d fail\n",
615 bp->pf.vf_info[i].vlan_as_table);
616 STAILQ_INIT(&bp->pf.vf_info[i].filter);
621 bp->fw_fid = rte_le_to_cpu_32(resp->fid);
622 memcpy(bp->dflt_mac_addr, &resp->mac_address, RTE_ETHER_ADDR_LEN);
623 bp->max_rsscos_ctx = rte_le_to_cpu_16(resp->max_rsscos_ctx);
624 bp->max_cp_rings = rte_le_to_cpu_16(resp->max_cmpl_rings);
625 bp->max_tx_rings = rte_le_to_cpu_16(resp->max_tx_rings);
626 bp->max_rx_rings = rte_le_to_cpu_16(resp->max_rx_rings);
627 bp->first_vf_id = rte_le_to_cpu_16(resp->first_vf_id);
628 bp->max_rx_em_flows = rte_le_to_cpu_16(resp->max_rx_em_flows);
629 bp->max_l2_ctx = rte_le_to_cpu_16(resp->max_l2_ctxs);
630 if (!BNXT_CHIP_THOR(bp))
631 bp->max_l2_ctx += bp->max_rx_em_flows;
632 /* TODO: For now, do not support VMDq/RFS on VFs. */
637 bp->max_vnics = rte_le_to_cpu_16(resp->max_vnics);
641 bp->max_stat_ctx = rte_le_to_cpu_16(resp->max_stat_ctx);
643 bp->pf.total_vnics = rte_le_to_cpu_16(resp->max_vnics);
644 if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_PTP_SUPPORTED) {
645 bp->flags |= BNXT_FLAG_PTP_SUPPORTED;
646 PMD_DRV_LOG(DEBUG, "PTP SUPPORTED\n");
648 bnxt_hwrm_ptp_qcfg(bp);
652 if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_EXT_STATS_SUPPORTED)
653 bp->flags |= BNXT_FLAG_EXT_STATS_SUPPORTED;
655 if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_ERROR_RECOVERY_CAPABLE) {
656 bp->flags |= BNXT_FLAG_FW_CAP_ERROR_RECOVERY;
657 PMD_DRV_LOG(DEBUG, "Adapter Error recovery SUPPORTED\n");
659 bp->flags &= ~BNXT_FLAG_FW_CAP_ERROR_RECOVERY;
662 if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_ERR_RECOVER_RELOAD)
663 bp->flags |= BNXT_FLAG_FW_CAP_ERR_RECOVER_RELOAD;
665 bp->flags &= ~BNXT_FLAG_FW_CAP_ERR_RECOVER_RELOAD;
672 int bnxt_hwrm_func_qcaps(struct bnxt *bp)
676 rc = __bnxt_hwrm_func_qcaps(bp);
677 if (!rc && bp->hwrm_spec_code >= HWRM_SPEC_CODE_1_8_3) {
678 rc = bnxt_alloc_ctx_mem(bp);
682 rc = bnxt_hwrm_func_resc_qcaps(bp);
684 bp->flags |= BNXT_FLAG_NEW_RM;
690 int bnxt_hwrm_func_reset(struct bnxt *bp)
693 struct hwrm_func_reset_input req = {.req_type = 0 };
694 struct hwrm_func_reset_output *resp = bp->hwrm_cmd_resp_addr;
696 HWRM_PREP(req, FUNC_RESET, BNXT_USE_CHIMP_MB);
698 req.enables = rte_cpu_to_le_32(0);
700 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
708 int bnxt_hwrm_func_driver_register(struct bnxt *bp)
712 struct hwrm_func_drv_rgtr_input req = {.req_type = 0 };
713 struct hwrm_func_drv_rgtr_output *resp = bp->hwrm_cmd_resp_addr;
715 if (bp->flags & BNXT_FLAG_REGISTERED)
718 flags = HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_HOT_RESET_SUPPORT;
719 if (bp->flags & BNXT_FLAG_FW_CAP_ERROR_RECOVERY)
720 flags |= HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_ERROR_RECOVERY_SUPPORT;
722 /* PFs and trusted VFs should indicate the support of the
723 * Master capability on non Stingray platform
725 if ((BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp)) && !BNXT_STINGRAY(bp))
726 flags |= HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_MASTER_SUPPORT;
728 HWRM_PREP(req, FUNC_DRV_RGTR, BNXT_USE_CHIMP_MB);
729 req.enables = rte_cpu_to_le_32(HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_VER |
730 HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_ASYNC_EVENT_FWD);
731 req.ver_maj = RTE_VER_YEAR;
732 req.ver_min = RTE_VER_MONTH;
733 req.ver_upd = RTE_VER_MINOR;
736 req.enables |= rte_cpu_to_le_32(
737 HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_VF_REQ_FWD);
738 memcpy(req.vf_req_fwd, bp->pf.vf_req_fwd,
739 RTE_MIN(sizeof(req.vf_req_fwd),
740 sizeof(bp->pf.vf_req_fwd)));
743 * PF can sniff HWRM API issued by VF. This can be set up by
744 * linux driver and inherited by the DPDK PF driver. Clear
745 * this HWRM sniffer list in FW because DPDK PF driver does
748 flags |= HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_FWD_NONE_MODE;
751 req.flags = rte_cpu_to_le_32(flags);
753 req.async_event_fwd[0] |=
754 rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_LINK_STATUS_CHANGE |
755 ASYNC_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED |
756 ASYNC_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE |
757 ASYNC_CMPL_EVENT_ID_LINK_SPEED_CHANGE |
758 ASYNC_CMPL_EVENT_ID_RESET_NOTIFY);
759 if (bp->flags & BNXT_FLAG_FW_CAP_ERROR_RECOVERY)
760 req.async_event_fwd[0] |=
761 rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_ERROR_RECOVERY);
762 req.async_event_fwd[1] |=
763 rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_PF_DRVR_UNLOAD |
764 ASYNC_CMPL_EVENT_ID_VF_CFG_CHANGE);
766 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
770 flags = rte_le_to_cpu_32(resp->flags);
771 if (flags & HWRM_FUNC_DRV_RGTR_OUTPUT_FLAGS_IF_CHANGE_SUPPORTED)
772 bp->flags |= BNXT_FLAG_FW_CAP_IF_CHANGE;
776 bp->flags |= BNXT_FLAG_REGISTERED;
781 int bnxt_hwrm_check_vf_rings(struct bnxt *bp)
783 if (!(BNXT_VF(bp) && (bp->flags & BNXT_FLAG_NEW_RM)))
786 return bnxt_hwrm_func_reserve_vf_resc(bp, true);
789 int bnxt_hwrm_func_reserve_vf_resc(struct bnxt *bp, bool test)
794 struct hwrm_func_vf_cfg_output *resp = bp->hwrm_cmd_resp_addr;
795 struct hwrm_func_vf_cfg_input req = {0};
797 HWRM_PREP(req, FUNC_VF_CFG, BNXT_USE_CHIMP_MB);
799 enables = HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_RX_RINGS |
800 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_TX_RINGS |
801 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
802 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
803 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_VNICS;
805 if (BNXT_HAS_RING_GRPS(bp)) {
806 enables |= HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS;
807 req.num_hw_ring_grps = rte_cpu_to_le_16(bp->rx_nr_rings);
810 req.num_tx_rings = rte_cpu_to_le_16(bp->tx_nr_rings);
811 req.num_rx_rings = rte_cpu_to_le_16(bp->rx_nr_rings *
812 AGG_RING_MULTIPLIER);
813 req.num_stat_ctxs = rte_cpu_to_le_16(bp->rx_nr_rings +
815 BNXT_NUM_ASYNC_CPR(bp));
816 req.num_cmpl_rings = rte_cpu_to_le_16(bp->rx_nr_rings +
818 BNXT_NUM_ASYNC_CPR(bp));
819 req.num_vnics = rte_cpu_to_le_16(bp->rx_nr_rings);
820 if (bp->vf_resv_strategy ==
821 HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESV_STRATEGY_MINIMAL_STATIC) {
822 enables |= HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_VNICS |
823 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_L2_CTXS |
824 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS;
825 req.num_rsscos_ctxs = rte_cpu_to_le_16(BNXT_VF_RSV_NUM_RSS_CTX);
826 req.num_l2_ctxs = rte_cpu_to_le_16(BNXT_VF_RSV_NUM_L2_CTX);
827 req.num_vnics = rte_cpu_to_le_16(BNXT_VF_RSV_NUM_VNIC);
831 flags = HWRM_FUNC_VF_CFG_INPUT_FLAGS_TX_ASSETS_TEST |
832 HWRM_FUNC_VF_CFG_INPUT_FLAGS_RX_ASSETS_TEST |
833 HWRM_FUNC_VF_CFG_INPUT_FLAGS_CMPL_ASSETS_TEST |
834 HWRM_FUNC_VF_CFG_INPUT_FLAGS_RING_GRP_ASSETS_TEST |
835 HWRM_FUNC_VF_CFG_INPUT_FLAGS_STAT_CTX_ASSETS_TEST |
836 HWRM_FUNC_VF_CFG_INPUT_FLAGS_VNIC_ASSETS_TEST;
838 if (test && BNXT_HAS_RING_GRPS(bp))
839 flags |= HWRM_FUNC_VF_CFG_INPUT_FLAGS_RING_GRP_ASSETS_TEST;
841 req.flags = rte_cpu_to_le_32(flags);
842 req.enables |= rte_cpu_to_le_32(enables);
844 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
847 HWRM_CHECK_RESULT_SILENT();
855 int bnxt_hwrm_func_resc_qcaps(struct bnxt *bp)
858 struct hwrm_func_resource_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
859 struct hwrm_func_resource_qcaps_input req = {0};
861 HWRM_PREP(req, FUNC_RESOURCE_QCAPS, BNXT_USE_CHIMP_MB);
862 req.fid = rte_cpu_to_le_16(0xffff);
864 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
869 bp->max_rsscos_ctx = rte_le_to_cpu_16(resp->max_rsscos_ctx);
870 bp->max_cp_rings = rte_le_to_cpu_16(resp->max_cmpl_rings);
871 bp->max_tx_rings = rte_le_to_cpu_16(resp->max_tx_rings);
872 bp->max_rx_rings = rte_le_to_cpu_16(resp->max_rx_rings);
873 bp->max_ring_grps = rte_le_to_cpu_32(resp->max_hw_ring_grps);
874 /* func_resource_qcaps does not return max_rx_em_flows.
875 * So use the value provided by func_qcaps.
877 bp->max_l2_ctx = rte_le_to_cpu_16(resp->max_l2_ctxs);
878 if (!BNXT_CHIP_THOR(bp))
879 bp->max_l2_ctx += bp->max_rx_em_flows;
880 bp->max_vnics = rte_le_to_cpu_16(resp->max_vnics);
881 bp->max_stat_ctx = rte_le_to_cpu_16(resp->max_stat_ctx);
883 bp->max_nq_rings = rte_le_to_cpu_16(resp->max_msix);
884 bp->vf_resv_strategy = rte_le_to_cpu_16(resp->vf_reservation_strategy);
885 if (bp->vf_resv_strategy >
886 HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESV_STRATEGY_MINIMAL_STATIC)
887 bp->vf_resv_strategy =
888 HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESERVATION_STRATEGY_MAXIMAL;
894 int bnxt_hwrm_ver_get(struct bnxt *bp)
897 struct hwrm_ver_get_input req = {.req_type = 0 };
898 struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr;
900 uint16_t max_resp_len;
901 char type[RTE_MEMZONE_NAMESIZE];
902 uint32_t dev_caps_cfg;
904 bp->max_req_len = HWRM_MAX_REQ_LEN;
905 HWRM_PREP(req, VER_GET, BNXT_USE_CHIMP_MB);
907 req.hwrm_intf_maj = HWRM_VERSION_MAJOR;
908 req.hwrm_intf_min = HWRM_VERSION_MINOR;
909 req.hwrm_intf_upd = HWRM_VERSION_UPDATE;
911 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
913 if (bp->flags & BNXT_FLAG_FW_RESET)
914 HWRM_CHECK_RESULT_SILENT();
918 PMD_DRV_LOG(INFO, "%d.%d.%d:%d.%d.%d\n",
919 resp->hwrm_intf_maj_8b, resp->hwrm_intf_min_8b,
920 resp->hwrm_intf_upd_8b, resp->hwrm_fw_maj_8b,
921 resp->hwrm_fw_min_8b, resp->hwrm_fw_bld_8b);
922 bp->fw_ver = (resp->hwrm_fw_maj_8b << 24) |
923 (resp->hwrm_fw_min_8b << 16) |
924 (resp->hwrm_fw_bld_8b << 8) |
925 resp->hwrm_fw_rsvd_8b;
926 PMD_DRV_LOG(INFO, "Driver HWRM version: %d.%d.%d\n",
927 HWRM_VERSION_MAJOR, HWRM_VERSION_MINOR, HWRM_VERSION_UPDATE);
929 fw_version = resp->hwrm_intf_maj_8b << 16;
930 fw_version |= resp->hwrm_intf_min_8b << 8;
931 fw_version |= resp->hwrm_intf_upd_8b;
932 bp->hwrm_spec_code = fw_version;
934 if (resp->hwrm_intf_maj_8b != HWRM_VERSION_MAJOR) {
935 PMD_DRV_LOG(ERR, "Unsupported firmware API version\n");
940 if (bp->max_req_len > resp->max_req_win_len) {
941 PMD_DRV_LOG(ERR, "Unsupported request length\n");
944 bp->max_req_len = rte_le_to_cpu_16(resp->max_req_win_len);
945 bp->hwrm_max_ext_req_len = rte_le_to_cpu_16(resp->max_ext_req_len);
946 if (bp->hwrm_max_ext_req_len < HWRM_MAX_REQ_LEN)
947 bp->hwrm_max_ext_req_len = HWRM_MAX_REQ_LEN;
949 max_resp_len = rte_le_to_cpu_16(resp->max_resp_len);
950 dev_caps_cfg = rte_le_to_cpu_32(resp->dev_caps_cfg);
952 if (bp->max_resp_len != max_resp_len) {
953 sprintf(type, "bnxt_hwrm_%04x:%02x:%02x:%02x",
954 bp->pdev->addr.domain, bp->pdev->addr.bus,
955 bp->pdev->addr.devid, bp->pdev->addr.function);
957 rte_free(bp->hwrm_cmd_resp_addr);
959 bp->hwrm_cmd_resp_addr = rte_malloc(type, max_resp_len, 0);
960 if (bp->hwrm_cmd_resp_addr == NULL) {
964 rte_mem_lock_page(bp->hwrm_cmd_resp_addr);
965 bp->hwrm_cmd_resp_dma_addr =
966 rte_mem_virt2iova(bp->hwrm_cmd_resp_addr);
967 if (bp->hwrm_cmd_resp_dma_addr == RTE_BAD_IOVA) {
969 "Unable to map response buffer to physical memory.\n");
973 bp->max_resp_len = max_resp_len;
977 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
979 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_REQUIRED)) {
980 PMD_DRV_LOG(DEBUG, "Short command supported\n");
981 bp->flags |= BNXT_FLAG_SHORT_CMD;
985 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
987 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_REQUIRED)) ||
988 bp->hwrm_max_ext_req_len > HWRM_MAX_REQ_LEN) {
989 sprintf(type, "bnxt_hwrm_short_%04x:%02x:%02x:%02x",
990 bp->pdev->addr.domain, bp->pdev->addr.bus,
991 bp->pdev->addr.devid, bp->pdev->addr.function);
993 rte_free(bp->hwrm_short_cmd_req_addr);
995 bp->hwrm_short_cmd_req_addr =
996 rte_malloc(type, bp->hwrm_max_ext_req_len, 0);
997 if (bp->hwrm_short_cmd_req_addr == NULL) {
1001 rte_mem_lock_page(bp->hwrm_short_cmd_req_addr);
1002 bp->hwrm_short_cmd_req_dma_addr =
1003 rte_mem_virt2iova(bp->hwrm_short_cmd_req_addr);
1004 if (bp->hwrm_short_cmd_req_dma_addr == RTE_BAD_IOVA) {
1005 rte_free(bp->hwrm_short_cmd_req_addr);
1007 "Unable to map buffer to physical memory.\n");
1013 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_KONG_MB_CHNL_SUPPORTED) {
1014 bp->flags |= BNXT_FLAG_KONG_MB_EN;
1015 PMD_DRV_LOG(DEBUG, "Kong mailbox channel enabled\n");
1018 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_TRUSTED_VF_SUPPORTED)
1019 PMD_DRV_LOG(DEBUG, "FW supports Trusted VFs\n");
1026 int bnxt_hwrm_func_driver_unregister(struct bnxt *bp, uint32_t flags)
1029 struct hwrm_func_drv_unrgtr_input req = {.req_type = 0 };
1030 struct hwrm_func_drv_unrgtr_output *resp = bp->hwrm_cmd_resp_addr;
1032 if (!(bp->flags & BNXT_FLAG_REGISTERED))
1035 HWRM_PREP(req, FUNC_DRV_UNRGTR, BNXT_USE_CHIMP_MB);
1038 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1040 HWRM_CHECK_RESULT();
1046 static int bnxt_hwrm_port_phy_cfg(struct bnxt *bp, struct bnxt_link_info *conf)
1049 struct hwrm_port_phy_cfg_input req = {0};
1050 struct hwrm_port_phy_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1051 uint32_t enables = 0;
1053 HWRM_PREP(req, PORT_PHY_CFG, BNXT_USE_CHIMP_MB);
1055 if (conf->link_up) {
1056 /* Setting Fixed Speed. But AutoNeg is ON, So disable it */
1057 if (bp->link_info.auto_mode && conf->link_speed) {
1058 req.auto_mode = HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_NONE;
1059 PMD_DRV_LOG(DEBUG, "Disabling AutoNeg\n");
1062 req.flags = rte_cpu_to_le_32(conf->phy_flags);
1063 req.force_link_speed = rte_cpu_to_le_16(conf->link_speed);
1064 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_MODE;
1066 * Note, ChiMP FW 20.2.1 and 20.2.2 return an error when we set
1067 * any auto mode, even "none".
1069 if (!conf->link_speed) {
1070 /* No speeds specified. Enable AutoNeg - all speeds */
1072 HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_ALL_SPEEDS;
1074 /* AutoNeg - Advertise speeds specified. */
1075 if (conf->auto_link_speed_mask &&
1076 !(conf->phy_flags & HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE)) {
1078 HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_SPEED_MASK;
1079 req.auto_link_speed_mask =
1080 conf->auto_link_speed_mask;
1082 HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_LINK_SPEED_MASK;
1085 req.auto_duplex = conf->duplex;
1086 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_DUPLEX;
1087 req.auto_pause = conf->auto_pause;
1088 req.force_pause = conf->force_pause;
1089 /* Set force_pause if there is no auto or if there is a force */
1090 if (req.auto_pause && !req.force_pause)
1091 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_PAUSE;
1093 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_FORCE_PAUSE;
1095 req.enables = rte_cpu_to_le_32(enables);
1098 rte_cpu_to_le_32(HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE_LINK_DWN);
1099 PMD_DRV_LOG(INFO, "Force Link Down\n");
1102 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1104 HWRM_CHECK_RESULT();
1110 static int bnxt_hwrm_port_phy_qcfg(struct bnxt *bp,
1111 struct bnxt_link_info *link_info)
1114 struct hwrm_port_phy_qcfg_input req = {0};
1115 struct hwrm_port_phy_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
1117 HWRM_PREP(req, PORT_PHY_QCFG, BNXT_USE_CHIMP_MB);
1119 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1121 HWRM_CHECK_RESULT();
1123 link_info->phy_link_status = resp->link;
1124 link_info->link_up =
1125 (link_info->phy_link_status ==
1126 HWRM_PORT_PHY_QCFG_OUTPUT_LINK_LINK) ? 1 : 0;
1127 link_info->link_speed = rte_le_to_cpu_16(resp->link_speed);
1128 link_info->duplex = resp->duplex_cfg;
1129 link_info->pause = resp->pause;
1130 link_info->auto_pause = resp->auto_pause;
1131 link_info->force_pause = resp->force_pause;
1132 link_info->auto_mode = resp->auto_mode;
1133 link_info->phy_type = resp->phy_type;
1134 link_info->media_type = resp->media_type;
1136 link_info->support_speeds = rte_le_to_cpu_16(resp->support_speeds);
1137 link_info->auto_link_speed = rte_le_to_cpu_16(resp->auto_link_speed);
1138 link_info->preemphasis = rte_le_to_cpu_32(resp->preemphasis);
1139 link_info->force_link_speed = rte_le_to_cpu_16(resp->force_link_speed);
1140 link_info->phy_ver[0] = resp->phy_maj;
1141 link_info->phy_ver[1] = resp->phy_min;
1142 link_info->phy_ver[2] = resp->phy_bld;
1146 PMD_DRV_LOG(DEBUG, "Link Speed %d\n", link_info->link_speed);
1147 PMD_DRV_LOG(DEBUG, "Auto Mode %d\n", link_info->auto_mode);
1148 PMD_DRV_LOG(DEBUG, "Support Speeds %x\n", link_info->support_speeds);
1149 PMD_DRV_LOG(DEBUG, "Auto Link Speed %x\n", link_info->auto_link_speed);
1150 PMD_DRV_LOG(DEBUG, "Auto Link Speed Mask %x\n",
1151 link_info->auto_link_speed_mask);
1152 PMD_DRV_LOG(DEBUG, "Forced Link Speed %x\n",
1153 link_info->force_link_speed);
1158 int bnxt_hwrm_queue_qportcfg(struct bnxt *bp)
1161 struct hwrm_queue_qportcfg_input req = {.req_type = 0 };
1162 struct hwrm_queue_qportcfg_output *resp = bp->hwrm_cmd_resp_addr;
1165 HWRM_PREP(req, QUEUE_QPORTCFG, BNXT_USE_CHIMP_MB);
1167 req.flags = HWRM_QUEUE_QPORTCFG_INPUT_FLAGS_PATH_TX;
1168 /* HWRM Version >= 1.9.1 */
1169 if (bp->hwrm_spec_code >= HWRM_VERSION_1_9_1)
1171 HWRM_QUEUE_QPORTCFG_INPUT_DRV_QMAP_CAP_ENABLED;
1172 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1174 HWRM_CHECK_RESULT();
1176 #define GET_QUEUE_INFO(x) \
1177 bp->cos_queue[x].id = resp->queue_id##x; \
1178 bp->cos_queue[x].profile = resp->queue_id##x##_service_profile
1191 if (bp->hwrm_spec_code < HWRM_VERSION_1_9_1) {
1192 bp->tx_cosq_id = bp->cos_queue[0].id;
1194 /* iterate and find the COSq profile to use for Tx */
1195 for (i = 0; i < BNXT_COS_QUEUE_COUNT; i++) {
1196 if (bp->cos_queue[i].profile ==
1197 HWRM_QUEUE_SERVICE_PROFILE_LOSSY) {
1198 bp->tx_cosq_id = bp->cos_queue[i].id;
1204 bp->max_tc = resp->max_configurable_queues;
1205 bp->max_lltc = resp->max_configurable_lossless_queues;
1206 if (bp->max_tc > BNXT_MAX_QUEUE)
1207 bp->max_tc = BNXT_MAX_QUEUE;
1208 bp->max_q = bp->max_tc;
1210 PMD_DRV_LOG(DEBUG, "Tx Cos Queue to use: %d\n", bp->tx_cosq_id);
1215 int bnxt_hwrm_ring_alloc(struct bnxt *bp,
1216 struct bnxt_ring *ring,
1217 uint32_t ring_type, uint32_t map_index,
1218 uint32_t stats_ctx_id, uint32_t cmpl_ring_id)
1221 uint32_t enables = 0;
1222 struct hwrm_ring_alloc_input req = {.req_type = 0 };
1223 struct hwrm_ring_alloc_output *resp = bp->hwrm_cmd_resp_addr;
1224 struct rte_mempool *mb_pool;
1225 uint16_t rx_buf_size;
1227 HWRM_PREP(req, RING_ALLOC, BNXT_USE_CHIMP_MB);
1229 req.page_tbl_addr = rte_cpu_to_le_64(ring->bd_dma);
1230 req.fbo = rte_cpu_to_le_32(0);
1231 /* Association of ring index with doorbell index */
1232 req.logical_id = rte_cpu_to_le_16(map_index);
1233 req.length = rte_cpu_to_le_32(ring->ring_size);
1235 switch (ring_type) {
1236 case HWRM_RING_ALLOC_INPUT_RING_TYPE_TX:
1237 req.ring_type = ring_type;
1238 req.cmpl_ring_id = rte_cpu_to_le_16(cmpl_ring_id);
1239 req.stat_ctx_id = rte_cpu_to_le_32(stats_ctx_id);
1240 req.queue_id = rte_cpu_to_le_16(bp->tx_cosq_id);
1241 if (stats_ctx_id != INVALID_STATS_CTX_ID)
1243 HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID;
1245 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX:
1246 req.ring_type = ring_type;
1247 req.cmpl_ring_id = rte_cpu_to_le_16(cmpl_ring_id);
1248 req.stat_ctx_id = rte_cpu_to_le_32(stats_ctx_id);
1249 if (BNXT_CHIP_THOR(bp)) {
1250 mb_pool = bp->rx_queues[0]->mb_pool;
1251 rx_buf_size = rte_pktmbuf_data_room_size(mb_pool) -
1252 RTE_PKTMBUF_HEADROOM;
1253 rx_buf_size = RTE_MIN(BNXT_MAX_PKT_LEN, rx_buf_size);
1254 req.rx_buf_size = rte_cpu_to_le_16(rx_buf_size);
1256 HWRM_RING_ALLOC_INPUT_ENABLES_RX_BUF_SIZE_VALID;
1258 if (stats_ctx_id != INVALID_STATS_CTX_ID)
1260 HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID;
1262 case HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL:
1263 req.ring_type = ring_type;
1264 if (BNXT_HAS_NQ(bp)) {
1265 /* Association of cp ring with nq */
1266 req.nq_ring_id = rte_cpu_to_le_16(cmpl_ring_id);
1268 HWRM_RING_ALLOC_INPUT_ENABLES_NQ_RING_ID_VALID;
1270 req.int_mode = HWRM_RING_ALLOC_INPUT_INT_MODE_MSIX;
1272 case HWRM_RING_ALLOC_INPUT_RING_TYPE_NQ:
1273 req.ring_type = ring_type;
1274 req.page_size = BNXT_PAGE_SHFT;
1275 req.int_mode = HWRM_RING_ALLOC_INPUT_INT_MODE_MSIX;
1277 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX_AGG:
1278 req.ring_type = ring_type;
1279 req.rx_ring_id = rte_cpu_to_le_16(ring->fw_rx_ring_id);
1281 mb_pool = bp->rx_queues[0]->mb_pool;
1282 rx_buf_size = rte_pktmbuf_data_room_size(mb_pool) -
1283 RTE_PKTMBUF_HEADROOM;
1284 rx_buf_size = RTE_MIN(BNXT_MAX_PKT_LEN, rx_buf_size);
1285 req.rx_buf_size = rte_cpu_to_le_16(rx_buf_size);
1287 req.stat_ctx_id = rte_cpu_to_le_32(stats_ctx_id);
1288 enables |= HWRM_RING_ALLOC_INPUT_ENABLES_RX_RING_ID_VALID |
1289 HWRM_RING_ALLOC_INPUT_ENABLES_RX_BUF_SIZE_VALID |
1290 HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID;
1293 PMD_DRV_LOG(ERR, "hwrm alloc invalid ring type %d\n",
1298 req.enables = rte_cpu_to_le_32(enables);
1300 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1302 if (rc || resp->error_code) {
1303 if (rc == 0 && resp->error_code)
1304 rc = rte_le_to_cpu_16(resp->error_code);
1305 switch (ring_type) {
1306 case HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL:
1308 "hwrm_ring_alloc cp failed. rc:%d\n", rc);
1311 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX:
1313 "hwrm_ring_alloc rx failed. rc:%d\n", rc);
1316 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX_AGG:
1318 "hwrm_ring_alloc rx agg failed. rc:%d\n",
1322 case HWRM_RING_ALLOC_INPUT_RING_TYPE_TX:
1324 "hwrm_ring_alloc tx failed. rc:%d\n", rc);
1327 case HWRM_RING_ALLOC_INPUT_RING_TYPE_NQ:
1329 "hwrm_ring_alloc nq failed. rc:%d\n", rc);
1333 PMD_DRV_LOG(ERR, "Invalid ring. rc:%d\n", rc);
1339 ring->fw_ring_id = rte_le_to_cpu_16(resp->ring_id);
1344 int bnxt_hwrm_ring_free(struct bnxt *bp,
1345 struct bnxt_ring *ring, uint32_t ring_type)
1348 struct hwrm_ring_free_input req = {.req_type = 0 };
1349 struct hwrm_ring_free_output *resp = bp->hwrm_cmd_resp_addr;
1351 HWRM_PREP(req, RING_FREE, BNXT_USE_CHIMP_MB);
1353 req.ring_type = ring_type;
1354 req.ring_id = rte_cpu_to_le_16(ring->fw_ring_id);
1356 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1358 if (rc || resp->error_code) {
1359 if (rc == 0 && resp->error_code)
1360 rc = rte_le_to_cpu_16(resp->error_code);
1363 switch (ring_type) {
1364 case HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL:
1365 PMD_DRV_LOG(ERR, "hwrm_ring_free cp failed. rc:%d\n",
1368 case HWRM_RING_FREE_INPUT_RING_TYPE_RX:
1369 PMD_DRV_LOG(ERR, "hwrm_ring_free rx failed. rc:%d\n",
1372 case HWRM_RING_FREE_INPUT_RING_TYPE_TX:
1373 PMD_DRV_LOG(ERR, "hwrm_ring_free tx failed. rc:%d\n",
1376 case HWRM_RING_FREE_INPUT_RING_TYPE_NQ:
1378 "hwrm_ring_free nq failed. rc:%d\n", rc);
1380 case HWRM_RING_FREE_INPUT_RING_TYPE_RX_AGG:
1382 "hwrm_ring_free agg failed. rc:%d\n", rc);
1385 PMD_DRV_LOG(ERR, "Invalid ring, rc:%d\n", rc);
1393 int bnxt_hwrm_ring_grp_alloc(struct bnxt *bp, unsigned int idx)
1396 struct hwrm_ring_grp_alloc_input req = {.req_type = 0 };
1397 struct hwrm_ring_grp_alloc_output *resp = bp->hwrm_cmd_resp_addr;
1399 HWRM_PREP(req, RING_GRP_ALLOC, BNXT_USE_CHIMP_MB);
1401 req.cr = rte_cpu_to_le_16(bp->grp_info[idx].cp_fw_ring_id);
1402 req.rr = rte_cpu_to_le_16(bp->grp_info[idx].rx_fw_ring_id);
1403 req.ar = rte_cpu_to_le_16(bp->grp_info[idx].ag_fw_ring_id);
1404 req.sc = rte_cpu_to_le_16(bp->grp_info[idx].fw_stats_ctx);
1406 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1408 HWRM_CHECK_RESULT();
1410 bp->grp_info[idx].fw_grp_id =
1411 rte_le_to_cpu_16(resp->ring_group_id);
1418 int bnxt_hwrm_ring_grp_free(struct bnxt *bp, unsigned int idx)
1421 struct hwrm_ring_grp_free_input req = {.req_type = 0 };
1422 struct hwrm_ring_grp_free_output *resp = bp->hwrm_cmd_resp_addr;
1424 HWRM_PREP(req, RING_GRP_FREE, BNXT_USE_CHIMP_MB);
1426 req.ring_group_id = rte_cpu_to_le_16(bp->grp_info[idx].fw_grp_id);
1428 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1430 HWRM_CHECK_RESULT();
1433 bp->grp_info[idx].fw_grp_id = INVALID_HW_RING_ID;
1437 int bnxt_hwrm_stat_clear(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
1440 struct hwrm_stat_ctx_clr_stats_input req = {.req_type = 0 };
1441 struct hwrm_stat_ctx_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
1443 if (cpr->hw_stats_ctx_id == (uint32_t)HWRM_NA_SIGNATURE)
1446 HWRM_PREP(req, STAT_CTX_CLR_STATS, BNXT_USE_CHIMP_MB);
1448 req.stat_ctx_id = rte_cpu_to_le_32(cpr->hw_stats_ctx_id);
1450 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1452 HWRM_CHECK_RESULT();
1458 int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
1459 unsigned int idx __rte_unused)
1462 struct hwrm_stat_ctx_alloc_input req = {.req_type = 0 };
1463 struct hwrm_stat_ctx_alloc_output *resp = bp->hwrm_cmd_resp_addr;
1465 HWRM_PREP(req, STAT_CTX_ALLOC, BNXT_USE_CHIMP_MB);
1467 req.update_period_ms = rte_cpu_to_le_32(0);
1469 req.stats_dma_addr =
1470 rte_cpu_to_le_64(cpr->hw_stats_map);
1472 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1474 HWRM_CHECK_RESULT();
1476 cpr->hw_stats_ctx_id = rte_le_to_cpu_32(resp->stat_ctx_id);
1483 int bnxt_hwrm_stat_ctx_free(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
1484 unsigned int idx __rte_unused)
1487 struct hwrm_stat_ctx_free_input req = {.req_type = 0 };
1488 struct hwrm_stat_ctx_free_output *resp = bp->hwrm_cmd_resp_addr;
1490 HWRM_PREP(req, STAT_CTX_FREE, BNXT_USE_CHIMP_MB);
1492 req.stat_ctx_id = rte_cpu_to_le_32(cpr->hw_stats_ctx_id);
1494 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1496 HWRM_CHECK_RESULT();
1502 int bnxt_hwrm_vnic_alloc(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1505 struct hwrm_vnic_alloc_input req = { 0 };
1506 struct hwrm_vnic_alloc_output *resp = bp->hwrm_cmd_resp_addr;
1508 if (!BNXT_HAS_RING_GRPS(bp))
1509 goto skip_ring_grps;
1511 /* map ring groups to this vnic */
1512 PMD_DRV_LOG(DEBUG, "Alloc VNIC. Start %x, End %x\n",
1513 vnic->start_grp_id, vnic->end_grp_id);
1514 for (i = vnic->start_grp_id, j = 0; i < vnic->end_grp_id; i++, j++)
1515 vnic->fw_grp_ids[j] = bp->grp_info[i].fw_grp_id;
1517 vnic->dflt_ring_grp = bp->grp_info[vnic->start_grp_id].fw_grp_id;
1518 vnic->rss_rule = (uint16_t)HWRM_NA_SIGNATURE;
1519 vnic->cos_rule = (uint16_t)HWRM_NA_SIGNATURE;
1520 vnic->lb_rule = (uint16_t)HWRM_NA_SIGNATURE;
1523 vnic->mru = bp->eth_dev->data->mtu + RTE_ETHER_HDR_LEN +
1524 RTE_ETHER_CRC_LEN + VLAN_TAG_SIZE;
1525 HWRM_PREP(req, VNIC_ALLOC, BNXT_USE_CHIMP_MB);
1527 if (vnic->func_default)
1529 rte_cpu_to_le_32(HWRM_VNIC_ALLOC_INPUT_FLAGS_DEFAULT);
1530 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1532 HWRM_CHECK_RESULT();
1534 vnic->fw_vnic_id = rte_le_to_cpu_16(resp->vnic_id);
1536 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
1540 static int bnxt_hwrm_vnic_plcmodes_qcfg(struct bnxt *bp,
1541 struct bnxt_vnic_info *vnic,
1542 struct bnxt_plcmodes_cfg *pmode)
1545 struct hwrm_vnic_plcmodes_qcfg_input req = {.req_type = 0 };
1546 struct hwrm_vnic_plcmodes_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
1548 HWRM_PREP(req, VNIC_PLCMODES_QCFG, BNXT_USE_CHIMP_MB);
1550 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1552 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1554 HWRM_CHECK_RESULT();
1556 pmode->flags = rte_le_to_cpu_32(resp->flags);
1557 /* dflt_vnic bit doesn't exist in the _cfg command */
1558 pmode->flags &= ~(HWRM_VNIC_PLCMODES_QCFG_OUTPUT_FLAGS_DFLT_VNIC);
1559 pmode->jumbo_thresh = rte_le_to_cpu_16(resp->jumbo_thresh);
1560 pmode->hds_offset = rte_le_to_cpu_16(resp->hds_offset);
1561 pmode->hds_threshold = rte_le_to_cpu_16(resp->hds_threshold);
1568 static int bnxt_hwrm_vnic_plcmodes_cfg(struct bnxt *bp,
1569 struct bnxt_vnic_info *vnic,
1570 struct bnxt_plcmodes_cfg *pmode)
1573 struct hwrm_vnic_plcmodes_cfg_input req = {.req_type = 0 };
1574 struct hwrm_vnic_plcmodes_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1576 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1577 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
1581 HWRM_PREP(req, VNIC_PLCMODES_CFG, BNXT_USE_CHIMP_MB);
1583 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1584 req.flags = rte_cpu_to_le_32(pmode->flags);
1585 req.jumbo_thresh = rte_cpu_to_le_16(pmode->jumbo_thresh);
1586 req.hds_offset = rte_cpu_to_le_16(pmode->hds_offset);
1587 req.hds_threshold = rte_cpu_to_le_16(pmode->hds_threshold);
1588 req.enables = rte_cpu_to_le_32(
1589 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_HDS_THRESHOLD_VALID |
1590 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_HDS_OFFSET_VALID |
1591 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_JUMBO_THRESH_VALID
1594 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1596 HWRM_CHECK_RESULT();
1602 int bnxt_hwrm_vnic_cfg(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1605 struct hwrm_vnic_cfg_input req = {.req_type = 0 };
1606 struct hwrm_vnic_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1607 struct bnxt_plcmodes_cfg pmodes = { 0 };
1608 uint32_t ctx_enable_flag = 0;
1609 uint32_t enables = 0;
1611 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1612 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
1616 rc = bnxt_hwrm_vnic_plcmodes_qcfg(bp, vnic, &pmodes);
1620 HWRM_PREP(req, VNIC_CFG, BNXT_USE_CHIMP_MB);
1622 if (BNXT_CHIP_THOR(bp)) {
1623 struct bnxt_rx_queue *rxq = bp->eth_dev->data->rx_queues[0];
1624 struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
1625 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
1627 req.default_rx_ring_id =
1628 rte_cpu_to_le_16(rxr->rx_ring_struct->fw_ring_id);
1629 req.default_cmpl_ring_id =
1630 rte_cpu_to_le_16(cpr->cp_ring_struct->fw_ring_id);
1631 enables = HWRM_VNIC_CFG_INPUT_ENABLES_DEFAULT_RX_RING_ID |
1632 HWRM_VNIC_CFG_INPUT_ENABLES_DEFAULT_CMPL_RING_ID;
1636 /* Only RSS support for now TBD: COS & LB */
1637 enables = HWRM_VNIC_CFG_INPUT_ENABLES_DFLT_RING_GRP;
1638 if (vnic->lb_rule != 0xffff)
1639 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_LB_RULE;
1640 if (vnic->cos_rule != 0xffff)
1641 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_COS_RULE;
1642 if (vnic->rss_rule != (uint16_t)HWRM_NA_SIGNATURE) {
1643 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_MRU;
1644 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_RSS_RULE;
1646 enables |= ctx_enable_flag;
1647 req.dflt_ring_grp = rte_cpu_to_le_16(vnic->dflt_ring_grp);
1648 req.rss_rule = rte_cpu_to_le_16(vnic->rss_rule);
1649 req.cos_rule = rte_cpu_to_le_16(vnic->cos_rule);
1650 req.lb_rule = rte_cpu_to_le_16(vnic->lb_rule);
1653 req.enables = rte_cpu_to_le_32(enables);
1654 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1655 req.mru = rte_cpu_to_le_16(vnic->mru);
1656 /* Configure default VNIC only once. */
1657 if (vnic->func_default && !(bp->flags & BNXT_FLAG_DFLT_VNIC_SET)) {
1659 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_DEFAULT);
1660 bp->flags |= BNXT_FLAG_DFLT_VNIC_SET;
1662 if (vnic->vlan_strip)
1664 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_VLAN_STRIP_MODE);
1667 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_BD_STALL_MODE);
1668 if (vnic->roce_dual)
1669 req.flags |= rte_cpu_to_le_32(
1670 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_DUAL_VNIC_MODE);
1671 if (vnic->roce_only)
1672 req.flags |= rte_cpu_to_le_32(
1673 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_ONLY_VNIC_MODE);
1674 if (vnic->rss_dflt_cr)
1675 req.flags |= rte_cpu_to_le_32(
1676 HWRM_VNIC_QCFG_OUTPUT_FLAGS_RSS_DFLT_CR_MODE);
1678 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1680 HWRM_CHECK_RESULT();
1683 rc = bnxt_hwrm_vnic_plcmodes_cfg(bp, vnic, &pmodes);
1688 int bnxt_hwrm_vnic_qcfg(struct bnxt *bp, struct bnxt_vnic_info *vnic,
1692 struct hwrm_vnic_qcfg_input req = {.req_type = 0 };
1693 struct hwrm_vnic_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
1695 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1696 PMD_DRV_LOG(DEBUG, "VNIC QCFG ID %d\n", vnic->fw_vnic_id);
1699 HWRM_PREP(req, VNIC_QCFG, BNXT_USE_CHIMP_MB);
1702 rte_cpu_to_le_32(HWRM_VNIC_QCFG_INPUT_ENABLES_VF_ID_VALID);
1703 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1704 req.vf_id = rte_cpu_to_le_16(fw_vf_id);
1706 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1708 HWRM_CHECK_RESULT();
1710 vnic->dflt_ring_grp = rte_le_to_cpu_16(resp->dflt_ring_grp);
1711 vnic->rss_rule = rte_le_to_cpu_16(resp->rss_rule);
1712 vnic->cos_rule = rte_le_to_cpu_16(resp->cos_rule);
1713 vnic->lb_rule = rte_le_to_cpu_16(resp->lb_rule);
1714 vnic->mru = rte_le_to_cpu_16(resp->mru);
1715 vnic->func_default = rte_le_to_cpu_32(
1716 resp->flags) & HWRM_VNIC_QCFG_OUTPUT_FLAGS_DEFAULT;
1717 vnic->vlan_strip = rte_le_to_cpu_32(resp->flags) &
1718 HWRM_VNIC_QCFG_OUTPUT_FLAGS_VLAN_STRIP_MODE;
1719 vnic->bd_stall = rte_le_to_cpu_32(resp->flags) &
1720 HWRM_VNIC_QCFG_OUTPUT_FLAGS_BD_STALL_MODE;
1721 vnic->roce_dual = rte_le_to_cpu_32(resp->flags) &
1722 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_DUAL_VNIC_MODE;
1723 vnic->roce_only = rte_le_to_cpu_32(resp->flags) &
1724 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_ONLY_VNIC_MODE;
1725 vnic->rss_dflt_cr = rte_le_to_cpu_32(resp->flags) &
1726 HWRM_VNIC_QCFG_OUTPUT_FLAGS_RSS_DFLT_CR_MODE;
1733 int bnxt_hwrm_vnic_ctx_alloc(struct bnxt *bp,
1734 struct bnxt_vnic_info *vnic, uint16_t ctx_idx)
1738 struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req = {.req_type = 0 };
1739 struct hwrm_vnic_rss_cos_lb_ctx_alloc_output *resp =
1740 bp->hwrm_cmd_resp_addr;
1742 HWRM_PREP(req, VNIC_RSS_COS_LB_CTX_ALLOC, BNXT_USE_CHIMP_MB);
1744 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1745 HWRM_CHECK_RESULT();
1747 ctx_id = rte_le_to_cpu_16(resp->rss_cos_lb_ctx_id);
1748 if (!BNXT_HAS_RING_GRPS(bp))
1749 vnic->fw_grp_ids[ctx_idx] = ctx_id;
1750 else if (ctx_idx == 0)
1751 vnic->rss_rule = ctx_id;
1758 int bnxt_hwrm_vnic_ctx_free(struct bnxt *bp,
1759 struct bnxt_vnic_info *vnic, uint16_t ctx_idx)
1762 struct hwrm_vnic_rss_cos_lb_ctx_free_input req = {.req_type = 0 };
1763 struct hwrm_vnic_rss_cos_lb_ctx_free_output *resp =
1764 bp->hwrm_cmd_resp_addr;
1766 if (ctx_idx == (uint16_t)HWRM_NA_SIGNATURE) {
1767 PMD_DRV_LOG(DEBUG, "VNIC RSS Rule %x\n", vnic->rss_rule);
1770 HWRM_PREP(req, VNIC_RSS_COS_LB_CTX_FREE, BNXT_USE_CHIMP_MB);
1772 req.rss_cos_lb_ctx_id = rte_cpu_to_le_16(ctx_idx);
1774 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1776 HWRM_CHECK_RESULT();
1782 int bnxt_hwrm_vnic_free(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1785 struct hwrm_vnic_free_input req = {.req_type = 0 };
1786 struct hwrm_vnic_free_output *resp = bp->hwrm_cmd_resp_addr;
1788 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1789 PMD_DRV_LOG(DEBUG, "VNIC FREE ID %x\n", vnic->fw_vnic_id);
1793 HWRM_PREP(req, VNIC_FREE, BNXT_USE_CHIMP_MB);
1795 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1797 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1799 HWRM_CHECK_RESULT();
1802 vnic->fw_vnic_id = INVALID_HW_RING_ID;
1803 /* Configure default VNIC again if necessary. */
1804 if (vnic->func_default && (bp->flags & BNXT_FLAG_DFLT_VNIC_SET))
1805 bp->flags &= ~BNXT_FLAG_DFLT_VNIC_SET;
1811 bnxt_hwrm_vnic_rss_cfg_thor(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1815 int nr_ctxs = vnic->num_lb_ctxts;
1816 struct hwrm_vnic_rss_cfg_input req = {.req_type = 0 };
1817 struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1819 for (i = 0; i < nr_ctxs; i++) {
1820 HWRM_PREP(req, VNIC_RSS_CFG, BNXT_USE_CHIMP_MB);
1822 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1823 req.hash_type = rte_cpu_to_le_32(vnic->hash_type);
1824 req.hash_mode_flags = vnic->hash_mode;
1826 req.hash_key_tbl_addr =
1827 rte_cpu_to_le_64(vnic->rss_hash_key_dma_addr);
1829 req.ring_grp_tbl_addr =
1830 rte_cpu_to_le_64(vnic->rss_table_dma_addr +
1831 i * HW_HASH_INDEX_SIZE);
1832 req.ring_table_pair_index = i;
1833 req.rss_ctx_idx = rte_cpu_to_le_16(vnic->fw_grp_ids[i]);
1835 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req),
1838 HWRM_CHECK_RESULT();
1845 int bnxt_hwrm_vnic_rss_cfg(struct bnxt *bp,
1846 struct bnxt_vnic_info *vnic)
1849 struct hwrm_vnic_rss_cfg_input req = {.req_type = 0 };
1850 struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1852 if (!vnic->rss_table)
1855 if (BNXT_CHIP_THOR(bp))
1856 return bnxt_hwrm_vnic_rss_cfg_thor(bp, vnic);
1858 HWRM_PREP(req, VNIC_RSS_CFG, BNXT_USE_CHIMP_MB);
1860 req.hash_type = rte_cpu_to_le_32(vnic->hash_type);
1861 req.hash_mode_flags = vnic->hash_mode;
1863 req.ring_grp_tbl_addr =
1864 rte_cpu_to_le_64(vnic->rss_table_dma_addr);
1865 req.hash_key_tbl_addr =
1866 rte_cpu_to_le_64(vnic->rss_hash_key_dma_addr);
1867 req.rss_ctx_idx = rte_cpu_to_le_16(vnic->rss_rule);
1868 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1870 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1872 HWRM_CHECK_RESULT();
1878 int bnxt_hwrm_vnic_plcmode_cfg(struct bnxt *bp,
1879 struct bnxt_vnic_info *vnic)
1882 struct hwrm_vnic_plcmodes_cfg_input req = {.req_type = 0 };
1883 struct hwrm_vnic_plcmodes_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1886 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1887 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
1891 HWRM_PREP(req, VNIC_PLCMODES_CFG, BNXT_USE_CHIMP_MB);
1893 req.flags = rte_cpu_to_le_32(
1894 HWRM_VNIC_PLCMODES_CFG_INPUT_FLAGS_JUMBO_PLACEMENT);
1896 req.enables = rte_cpu_to_le_32(
1897 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_JUMBO_THRESH_VALID);
1899 size = rte_pktmbuf_data_room_size(bp->rx_queues[0]->mb_pool);
1900 size -= RTE_PKTMBUF_HEADROOM;
1901 size = RTE_MIN(BNXT_MAX_PKT_LEN, size);
1903 req.jumbo_thresh = rte_cpu_to_le_16(size);
1904 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1906 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1908 HWRM_CHECK_RESULT();
1914 int bnxt_hwrm_vnic_tpa_cfg(struct bnxt *bp,
1915 struct bnxt_vnic_info *vnic, bool enable)
1918 struct hwrm_vnic_tpa_cfg_input req = {.req_type = 0 };
1919 struct hwrm_vnic_tpa_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1921 if (BNXT_CHIP_THOR(bp))
1924 HWRM_PREP(req, VNIC_TPA_CFG, BNXT_USE_CHIMP_MB);
1927 req.enables = rte_cpu_to_le_32(
1928 HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MAX_AGG_SEGS |
1929 HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MAX_AGGS |
1930 HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MIN_AGG_LEN);
1931 req.flags = rte_cpu_to_le_32(
1932 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_TPA |
1933 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_ENCAP_TPA |
1934 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_RSC_WND_UPDATE |
1935 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_GRO |
1936 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_AGG_WITH_ECN |
1937 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_AGG_WITH_SAME_GRE_SEQ);
1938 req.max_agg_segs = rte_cpu_to_le_16(5);
1940 rte_cpu_to_le_16(HWRM_VNIC_TPA_CFG_INPUT_MAX_AGGS_MAX);
1941 req.min_agg_len = rte_cpu_to_le_32(512);
1943 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1945 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1947 HWRM_CHECK_RESULT();
1953 int bnxt_hwrm_func_vf_mac(struct bnxt *bp, uint16_t vf, const uint8_t *mac_addr)
1955 struct hwrm_func_cfg_input req = {0};
1956 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1959 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[vf].func_cfg_flags);
1960 req.enables = rte_cpu_to_le_32(
1961 HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
1962 memcpy(req.dflt_mac_addr, mac_addr, sizeof(req.dflt_mac_addr));
1963 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
1965 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
1967 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1968 HWRM_CHECK_RESULT();
1971 bp->pf.vf_info[vf].random_mac = false;
1976 int bnxt_hwrm_func_qstats_tx_drop(struct bnxt *bp, uint16_t fid,
1980 struct hwrm_func_qstats_input req = {.req_type = 0};
1981 struct hwrm_func_qstats_output *resp = bp->hwrm_cmd_resp_addr;
1983 HWRM_PREP(req, FUNC_QSTATS, BNXT_USE_CHIMP_MB);
1985 req.fid = rte_cpu_to_le_16(fid);
1987 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1989 HWRM_CHECK_RESULT();
1992 *dropped = rte_le_to_cpu_64(resp->tx_drop_pkts);
1999 int bnxt_hwrm_func_qstats(struct bnxt *bp, uint16_t fid,
2000 struct rte_eth_stats *stats)
2003 struct hwrm_func_qstats_input req = {.req_type = 0};
2004 struct hwrm_func_qstats_output *resp = bp->hwrm_cmd_resp_addr;
2006 HWRM_PREP(req, FUNC_QSTATS, BNXT_USE_CHIMP_MB);
2008 req.fid = rte_cpu_to_le_16(fid);
2010 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2012 HWRM_CHECK_RESULT();
2014 stats->ipackets = rte_le_to_cpu_64(resp->rx_ucast_pkts);
2015 stats->ipackets += rte_le_to_cpu_64(resp->rx_mcast_pkts);
2016 stats->ipackets += rte_le_to_cpu_64(resp->rx_bcast_pkts);
2017 stats->ibytes = rte_le_to_cpu_64(resp->rx_ucast_bytes);
2018 stats->ibytes += rte_le_to_cpu_64(resp->rx_mcast_bytes);
2019 stats->ibytes += rte_le_to_cpu_64(resp->rx_bcast_bytes);
2021 stats->opackets = rte_le_to_cpu_64(resp->tx_ucast_pkts);
2022 stats->opackets += rte_le_to_cpu_64(resp->tx_mcast_pkts);
2023 stats->opackets += rte_le_to_cpu_64(resp->tx_bcast_pkts);
2024 stats->obytes = rte_le_to_cpu_64(resp->tx_ucast_bytes);
2025 stats->obytes += rte_le_to_cpu_64(resp->tx_mcast_bytes);
2026 stats->obytes += rte_le_to_cpu_64(resp->tx_bcast_bytes);
2028 stats->imissed = rte_le_to_cpu_64(resp->rx_discard_pkts);
2029 stats->ierrors = rte_le_to_cpu_64(resp->rx_drop_pkts);
2030 stats->oerrors = rte_le_to_cpu_64(resp->tx_discard_pkts);
2037 int bnxt_hwrm_func_clr_stats(struct bnxt *bp, uint16_t fid)
2040 struct hwrm_func_clr_stats_input req = {.req_type = 0};
2041 struct hwrm_func_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
2043 HWRM_PREP(req, FUNC_CLR_STATS, BNXT_USE_CHIMP_MB);
2045 req.fid = rte_cpu_to_le_16(fid);
2047 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2049 HWRM_CHECK_RESULT();
2056 * HWRM utility functions
2059 int bnxt_clear_all_hwrm_stat_ctxs(struct bnxt *bp)
2064 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
2065 struct bnxt_tx_queue *txq;
2066 struct bnxt_rx_queue *rxq;
2067 struct bnxt_cp_ring_info *cpr;
2069 if (i >= bp->rx_cp_nr_rings) {
2070 txq = bp->tx_queues[i - bp->rx_cp_nr_rings];
2073 rxq = bp->rx_queues[i];
2077 rc = bnxt_hwrm_stat_clear(bp, cpr);
2084 int bnxt_free_all_hwrm_stat_ctxs(struct bnxt *bp)
2088 struct bnxt_cp_ring_info *cpr;
2090 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
2092 if (i >= bp->rx_cp_nr_rings) {
2093 cpr = bp->tx_queues[i - bp->rx_cp_nr_rings]->cp_ring;
2095 cpr = bp->rx_queues[i]->cp_ring;
2096 if (BNXT_HAS_RING_GRPS(bp))
2097 bp->grp_info[i].fw_stats_ctx = -1;
2099 if (cpr->hw_stats_ctx_id != HWRM_NA_SIGNATURE) {
2100 rc = bnxt_hwrm_stat_ctx_free(bp, cpr, i);
2101 cpr->hw_stats_ctx_id = HWRM_NA_SIGNATURE;
2109 int bnxt_alloc_all_hwrm_stat_ctxs(struct bnxt *bp)
2114 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
2115 struct bnxt_tx_queue *txq;
2116 struct bnxt_rx_queue *rxq;
2117 struct bnxt_cp_ring_info *cpr;
2119 if (i >= bp->rx_cp_nr_rings) {
2120 txq = bp->tx_queues[i - bp->rx_cp_nr_rings];
2123 rxq = bp->rx_queues[i];
2127 rc = bnxt_hwrm_stat_ctx_alloc(bp, cpr, i);
2135 int bnxt_free_all_hwrm_ring_grps(struct bnxt *bp)
2140 if (!BNXT_HAS_RING_GRPS(bp))
2143 for (idx = 0; idx < bp->rx_cp_nr_rings; idx++) {
2145 if (bp->grp_info[idx].fw_grp_id == INVALID_HW_RING_ID)
2148 rc = bnxt_hwrm_ring_grp_free(bp, idx);
2156 void bnxt_free_nq_ring(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
2158 struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
2160 bnxt_hwrm_ring_free(bp, cp_ring,
2161 HWRM_RING_FREE_INPUT_RING_TYPE_NQ);
2162 cp_ring->fw_ring_id = INVALID_HW_RING_ID;
2163 memset(cpr->cp_desc_ring, 0, cpr->cp_ring_struct->ring_size *
2164 sizeof(*cpr->cp_desc_ring));
2165 cpr->cp_raw_cons = 0;
2169 void bnxt_free_cp_ring(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
2171 struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
2173 bnxt_hwrm_ring_free(bp, cp_ring,
2174 HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL);
2175 cp_ring->fw_ring_id = INVALID_HW_RING_ID;
2176 memset(cpr->cp_desc_ring, 0, cpr->cp_ring_struct->ring_size *
2177 sizeof(*cpr->cp_desc_ring));
2178 cpr->cp_raw_cons = 0;
2182 void bnxt_free_hwrm_rx_ring(struct bnxt *bp, int queue_index)
2184 struct bnxt_rx_queue *rxq = bp->rx_queues[queue_index];
2185 struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
2186 struct bnxt_ring *ring = rxr->rx_ring_struct;
2187 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
2189 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
2190 bnxt_hwrm_ring_free(bp, ring,
2191 HWRM_RING_FREE_INPUT_RING_TYPE_RX);
2192 ring->fw_ring_id = INVALID_HW_RING_ID;
2193 if (BNXT_HAS_RING_GRPS(bp))
2194 bp->grp_info[queue_index].rx_fw_ring_id =
2196 memset(rxr->rx_desc_ring, 0,
2197 rxr->rx_ring_struct->ring_size *
2198 sizeof(*rxr->rx_desc_ring));
2199 memset(rxr->rx_buf_ring, 0,
2200 rxr->rx_ring_struct->ring_size *
2201 sizeof(*rxr->rx_buf_ring));
2204 ring = rxr->ag_ring_struct;
2205 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
2206 bnxt_hwrm_ring_free(bp, ring,
2207 BNXT_CHIP_THOR(bp) ?
2208 HWRM_RING_FREE_INPUT_RING_TYPE_RX_AGG :
2209 HWRM_RING_FREE_INPUT_RING_TYPE_RX);
2210 ring->fw_ring_id = INVALID_HW_RING_ID;
2211 memset(rxr->ag_buf_ring, 0,
2212 rxr->ag_ring_struct->ring_size *
2213 sizeof(*rxr->ag_buf_ring));
2215 if (BNXT_HAS_RING_GRPS(bp))
2216 bp->grp_info[queue_index].ag_fw_ring_id =
2219 if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID) {
2220 bnxt_free_cp_ring(bp, cpr);
2222 bnxt_free_nq_ring(bp, rxq->nq_ring);
2225 if (BNXT_HAS_RING_GRPS(bp))
2226 bp->grp_info[queue_index].cp_fw_ring_id = INVALID_HW_RING_ID;
2229 int bnxt_free_all_hwrm_rings(struct bnxt *bp)
2233 for (i = 0; i < bp->tx_cp_nr_rings; i++) {
2234 struct bnxt_tx_queue *txq = bp->tx_queues[i];
2235 struct bnxt_tx_ring_info *txr = txq->tx_ring;
2236 struct bnxt_ring *ring = txr->tx_ring_struct;
2237 struct bnxt_cp_ring_info *cpr = txq->cp_ring;
2239 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
2240 bnxt_hwrm_ring_free(bp, ring,
2241 HWRM_RING_FREE_INPUT_RING_TYPE_TX);
2242 ring->fw_ring_id = INVALID_HW_RING_ID;
2243 memset(txr->tx_desc_ring, 0,
2244 txr->tx_ring_struct->ring_size *
2245 sizeof(*txr->tx_desc_ring));
2246 memset(txr->tx_buf_ring, 0,
2247 txr->tx_ring_struct->ring_size *
2248 sizeof(*txr->tx_buf_ring));
2252 if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID) {
2253 bnxt_free_cp_ring(bp, cpr);
2254 cpr->cp_ring_struct->fw_ring_id = INVALID_HW_RING_ID;
2256 bnxt_free_nq_ring(bp, txq->nq_ring);
2260 for (i = 0; i < bp->rx_cp_nr_rings; i++)
2261 bnxt_free_hwrm_rx_ring(bp, i);
2266 int bnxt_alloc_all_hwrm_ring_grps(struct bnxt *bp)
2271 if (!BNXT_HAS_RING_GRPS(bp))
2274 for (i = 0; i < bp->rx_cp_nr_rings; i++) {
2275 rc = bnxt_hwrm_ring_grp_alloc(bp, i);
2282 void bnxt_free_hwrm_resources(struct bnxt *bp)
2284 /* Release memzone */
2285 rte_free(bp->hwrm_cmd_resp_addr);
2286 rte_free(bp->hwrm_short_cmd_req_addr);
2287 bp->hwrm_cmd_resp_addr = NULL;
2288 bp->hwrm_short_cmd_req_addr = NULL;
2289 bp->hwrm_cmd_resp_dma_addr = 0;
2290 bp->hwrm_short_cmd_req_dma_addr = 0;
2293 int bnxt_alloc_hwrm_resources(struct bnxt *bp)
2295 struct rte_pci_device *pdev = bp->pdev;
2296 char type[RTE_MEMZONE_NAMESIZE];
2298 sprintf(type, "bnxt_hwrm_%04x:%02x:%02x:%02x", pdev->addr.domain,
2299 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
2300 bp->max_resp_len = HWRM_MAX_RESP_LEN;
2301 bp->hwrm_cmd_resp_addr = rte_malloc(type, bp->max_resp_len, 0);
2302 rte_mem_lock_page(bp->hwrm_cmd_resp_addr);
2303 if (bp->hwrm_cmd_resp_addr == NULL)
2305 bp->hwrm_cmd_resp_dma_addr =
2306 rte_mem_virt2iova(bp->hwrm_cmd_resp_addr);
2307 if (bp->hwrm_cmd_resp_dma_addr == RTE_BAD_IOVA) {
2309 "unable to map response address to physical memory\n");
2312 rte_spinlock_init(&bp->hwrm_lock);
2317 int bnxt_clear_hwrm_vnic_filters(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2319 struct bnxt_filter_info *filter;
2322 STAILQ_FOREACH(filter, &vnic->filter, next) {
2323 if (filter->filter_type == HWRM_CFA_EM_FILTER)
2324 rc = bnxt_hwrm_clear_em_filter(bp, filter);
2325 else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
2326 rc = bnxt_hwrm_clear_ntuple_filter(bp, filter);
2328 rc = bnxt_hwrm_clear_l2_filter(bp, filter);
2329 STAILQ_REMOVE(&vnic->filter, filter, bnxt_filter_info, next);
2330 bnxt_free_filter(bp, filter);
2338 bnxt_clear_hwrm_vnic_flows(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2340 struct bnxt_filter_info *filter;
2341 struct rte_flow *flow;
2344 STAILQ_FOREACH(flow, &vnic->flow_list, next) {
2345 filter = flow->filter;
2346 PMD_DRV_LOG(DEBUG, "filter type %d\n", filter->filter_type);
2347 if (filter->filter_type == HWRM_CFA_EM_FILTER)
2348 rc = bnxt_hwrm_clear_em_filter(bp, filter);
2349 else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
2350 rc = bnxt_hwrm_clear_ntuple_filter(bp, filter);
2352 rc = bnxt_hwrm_clear_l2_filter(bp, filter);
2354 STAILQ_REMOVE(&vnic->flow_list, flow, rte_flow, next);
2362 int bnxt_set_hwrm_vnic_filters(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2364 struct bnxt_filter_info *filter;
2367 STAILQ_FOREACH(filter, &vnic->filter, next) {
2368 if (filter->filter_type == HWRM_CFA_EM_FILTER)
2369 rc = bnxt_hwrm_set_em_filter(bp, filter->dst_id,
2371 else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
2372 rc = bnxt_hwrm_set_ntuple_filter(bp, filter->dst_id,
2375 rc = bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id,
2383 void bnxt_free_tunnel_ports(struct bnxt *bp)
2385 if (bp->vxlan_port_cnt)
2386 bnxt_hwrm_tunnel_dst_port_free(bp, bp->vxlan_fw_dst_port_id,
2387 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_VXLAN);
2389 if (bp->geneve_port_cnt)
2390 bnxt_hwrm_tunnel_dst_port_free(bp, bp->geneve_fw_dst_port_id,
2391 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_GENEVE);
2392 bp->geneve_port = 0;
2395 void bnxt_free_all_hwrm_resources(struct bnxt *bp)
2399 if (bp->vnic_info == NULL)
2403 * Cleanup VNICs in reverse order, to make sure the L2 filter
2404 * from vnic0 is last to be cleaned up.
2406 for (i = bp->nr_vnics - 1; i >= 0; i--) {
2407 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
2409 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
2410 PMD_DRV_LOG(DEBUG, "Invalid vNIC ID\n");
2414 bnxt_clear_hwrm_vnic_flows(bp, vnic);
2416 bnxt_clear_hwrm_vnic_filters(bp, vnic);
2418 if (BNXT_CHIP_THOR(bp)) {
2419 for (j = 0; j < vnic->num_lb_ctxts; j++) {
2420 bnxt_hwrm_vnic_ctx_free(bp, vnic,
2421 vnic->fw_grp_ids[j]);
2422 vnic->fw_grp_ids[j] = INVALID_HW_RING_ID;
2424 vnic->num_lb_ctxts = 0;
2426 bnxt_hwrm_vnic_ctx_free(bp, vnic, vnic->rss_rule);
2427 vnic->rss_rule = INVALID_HW_RING_ID;
2430 bnxt_hwrm_vnic_tpa_cfg(bp, vnic, false);
2432 bnxt_hwrm_vnic_free(bp, vnic);
2434 rte_free(vnic->fw_grp_ids);
2436 /* Ring resources */
2437 bnxt_free_all_hwrm_rings(bp);
2438 bnxt_free_all_hwrm_ring_grps(bp);
2439 bnxt_free_all_hwrm_stat_ctxs(bp);
2440 bnxt_free_tunnel_ports(bp);
2443 static uint16_t bnxt_parse_eth_link_duplex(uint32_t conf_link_speed)
2445 uint8_t hw_link_duplex = HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH;
2447 if ((conf_link_speed & ETH_LINK_SPEED_FIXED) == ETH_LINK_SPEED_AUTONEG)
2448 return HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH;
2450 switch (conf_link_speed) {
2451 case ETH_LINK_SPEED_10M_HD:
2452 case ETH_LINK_SPEED_100M_HD:
2454 return HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_HALF;
2456 return hw_link_duplex;
2459 static uint16_t bnxt_check_eth_link_autoneg(uint32_t conf_link)
2461 return (conf_link & ETH_LINK_SPEED_FIXED) ? 0 : 1;
2464 static uint16_t bnxt_parse_eth_link_speed(uint32_t conf_link_speed)
2466 uint16_t eth_link_speed = 0;
2468 if (conf_link_speed == ETH_LINK_SPEED_AUTONEG)
2469 return ETH_LINK_SPEED_AUTONEG;
2471 switch (conf_link_speed & ~ETH_LINK_SPEED_FIXED) {
2472 case ETH_LINK_SPEED_100M:
2473 case ETH_LINK_SPEED_100M_HD:
2476 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_100MB;
2478 case ETH_LINK_SPEED_1G:
2480 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_1GB;
2482 case ETH_LINK_SPEED_2_5G:
2484 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_2_5GB;
2486 case ETH_LINK_SPEED_10G:
2488 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_10GB;
2490 case ETH_LINK_SPEED_20G:
2492 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_20GB;
2494 case ETH_LINK_SPEED_25G:
2496 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_25GB;
2498 case ETH_LINK_SPEED_40G:
2500 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_40GB;
2502 case ETH_LINK_SPEED_50G:
2504 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_50GB;
2506 case ETH_LINK_SPEED_100G:
2508 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_100GB;
2512 "Unsupported link speed %d; default to AUTO\n",
2516 return eth_link_speed;
2519 #define BNXT_SUPPORTED_SPEEDS (ETH_LINK_SPEED_100M | ETH_LINK_SPEED_100M_HD | \
2520 ETH_LINK_SPEED_1G | ETH_LINK_SPEED_2_5G | \
2521 ETH_LINK_SPEED_10G | ETH_LINK_SPEED_20G | ETH_LINK_SPEED_25G | \
2522 ETH_LINK_SPEED_40G | ETH_LINK_SPEED_50G | ETH_LINK_SPEED_100G)
2524 static int bnxt_valid_link_speed(uint32_t link_speed, uint16_t port_id)
2528 if (link_speed == ETH_LINK_SPEED_AUTONEG)
2531 if (link_speed & ETH_LINK_SPEED_FIXED) {
2532 one_speed = link_speed & ~ETH_LINK_SPEED_FIXED;
2534 if (one_speed & (one_speed - 1)) {
2536 "Invalid advertised speeds (%u) for port %u\n",
2537 link_speed, port_id);
2540 if ((one_speed & BNXT_SUPPORTED_SPEEDS) != one_speed) {
2542 "Unsupported advertised speed (%u) for port %u\n",
2543 link_speed, port_id);
2547 if (!(link_speed & BNXT_SUPPORTED_SPEEDS)) {
2549 "Unsupported advertised speeds (%u) for port %u\n",
2550 link_speed, port_id);
2558 bnxt_parse_eth_link_speed_mask(struct bnxt *bp, uint32_t link_speed)
2562 if (link_speed == ETH_LINK_SPEED_AUTONEG) {
2563 if (bp->link_info.support_speeds)
2564 return bp->link_info.support_speeds;
2565 link_speed = BNXT_SUPPORTED_SPEEDS;
2568 if (link_speed & ETH_LINK_SPEED_100M)
2569 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100MB;
2570 if (link_speed & ETH_LINK_SPEED_100M_HD)
2571 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100MB;
2572 if (link_speed & ETH_LINK_SPEED_1G)
2573 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_1GB;
2574 if (link_speed & ETH_LINK_SPEED_2_5G)
2575 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_2_5GB;
2576 if (link_speed & ETH_LINK_SPEED_10G)
2577 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_10GB;
2578 if (link_speed & ETH_LINK_SPEED_20G)
2579 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_20GB;
2580 if (link_speed & ETH_LINK_SPEED_25G)
2581 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_25GB;
2582 if (link_speed & ETH_LINK_SPEED_40G)
2583 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_40GB;
2584 if (link_speed & ETH_LINK_SPEED_50G)
2585 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_50GB;
2586 if (link_speed & ETH_LINK_SPEED_100G)
2587 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100GB;
2591 static uint32_t bnxt_parse_hw_link_speed(uint16_t hw_link_speed)
2593 uint32_t eth_link_speed = ETH_SPEED_NUM_NONE;
2595 switch (hw_link_speed) {
2596 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100MB:
2597 eth_link_speed = ETH_SPEED_NUM_100M;
2599 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_1GB:
2600 eth_link_speed = ETH_SPEED_NUM_1G;
2602 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2_5GB:
2603 eth_link_speed = ETH_SPEED_NUM_2_5G;
2605 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_10GB:
2606 eth_link_speed = ETH_SPEED_NUM_10G;
2608 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_20GB:
2609 eth_link_speed = ETH_SPEED_NUM_20G;
2611 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_25GB:
2612 eth_link_speed = ETH_SPEED_NUM_25G;
2614 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_40GB:
2615 eth_link_speed = ETH_SPEED_NUM_40G;
2617 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_50GB:
2618 eth_link_speed = ETH_SPEED_NUM_50G;
2620 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100GB:
2621 eth_link_speed = ETH_SPEED_NUM_100G;
2623 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2GB:
2625 PMD_DRV_LOG(ERR, "HWRM link speed %d not defined\n",
2629 return eth_link_speed;
2632 static uint16_t bnxt_parse_hw_link_duplex(uint16_t hw_link_duplex)
2634 uint16_t eth_link_duplex = ETH_LINK_FULL_DUPLEX;
2636 switch (hw_link_duplex) {
2637 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH:
2638 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_FULL:
2640 eth_link_duplex = ETH_LINK_FULL_DUPLEX;
2642 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_HALF:
2643 eth_link_duplex = ETH_LINK_HALF_DUPLEX;
2646 PMD_DRV_LOG(ERR, "HWRM link duplex %d not defined\n",
2650 return eth_link_duplex;
2653 int bnxt_get_hwrm_link_config(struct bnxt *bp, struct rte_eth_link *link)
2656 struct bnxt_link_info *link_info = &bp->link_info;
2658 rc = bnxt_hwrm_port_phy_qcfg(bp, link_info);
2661 "Get link config failed with rc %d\n", rc);
2664 if (link_info->link_speed)
2666 bnxt_parse_hw_link_speed(link_info->link_speed);
2668 link->link_speed = ETH_SPEED_NUM_NONE;
2669 link->link_duplex = bnxt_parse_hw_link_duplex(link_info->duplex);
2670 link->link_status = link_info->link_up;
2671 link->link_autoneg = link_info->auto_mode ==
2672 HWRM_PORT_PHY_QCFG_OUTPUT_AUTO_MODE_NONE ?
2673 ETH_LINK_FIXED : ETH_LINK_AUTONEG;
2678 int bnxt_set_hwrm_link_config(struct bnxt *bp, bool link_up)
2681 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
2682 struct bnxt_link_info link_req;
2683 uint16_t speed, autoneg;
2685 if (!BNXT_SINGLE_PF(bp) || BNXT_VF(bp))
2688 rc = bnxt_valid_link_speed(dev_conf->link_speeds,
2689 bp->eth_dev->data->port_id);
2693 memset(&link_req, 0, sizeof(link_req));
2694 link_req.link_up = link_up;
2698 autoneg = bnxt_check_eth_link_autoneg(dev_conf->link_speeds);
2699 if (BNXT_CHIP_THOR(bp) &&
2700 dev_conf->link_speeds == ETH_LINK_SPEED_40G) {
2701 /* 40G is not supported as part of media auto detect.
2702 * The speed should be forced and autoneg disabled
2703 * to configure 40G speed.
2705 PMD_DRV_LOG(INFO, "Disabling autoneg for 40G\n");
2709 speed = bnxt_parse_eth_link_speed(dev_conf->link_speeds);
2710 link_req.phy_flags = HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESET_PHY;
2711 /* Autoneg can be done only when the FW allows.
2712 * When user configures fixed speed of 40G and later changes to
2713 * any other speed, auto_link_speed/force_link_speed is still set
2714 * to 40G until link comes up at new speed.
2717 !(!BNXT_CHIP_THOR(bp) &&
2718 (bp->link_info.auto_link_speed ||
2719 bp->link_info.force_link_speed))) {
2720 link_req.phy_flags |=
2721 HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESTART_AUTONEG;
2722 link_req.auto_link_speed_mask =
2723 bnxt_parse_eth_link_speed_mask(bp,
2724 dev_conf->link_speeds);
2726 if (bp->link_info.phy_type ==
2727 HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET ||
2728 bp->link_info.phy_type ==
2729 HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASETE ||
2730 bp->link_info.media_type ==
2731 HWRM_PORT_PHY_QCFG_OUTPUT_MEDIA_TYPE_TP) {
2732 PMD_DRV_LOG(ERR, "10GBase-T devices must autoneg\n");
2736 link_req.phy_flags |= HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE;
2737 /* If user wants a particular speed try that first. */
2739 link_req.link_speed = speed;
2740 else if (bp->link_info.force_link_speed)
2741 link_req.link_speed = bp->link_info.force_link_speed;
2743 link_req.link_speed = bp->link_info.auto_link_speed;
2745 link_req.duplex = bnxt_parse_eth_link_duplex(dev_conf->link_speeds);
2746 link_req.auto_pause = bp->link_info.auto_pause;
2747 link_req.force_pause = bp->link_info.force_pause;
2750 rc = bnxt_hwrm_port_phy_cfg(bp, &link_req);
2753 "Set link config failed with rc %d\n", rc);
2761 int bnxt_hwrm_func_qcfg(struct bnxt *bp, uint16_t *mtu)
2763 struct hwrm_func_qcfg_input req = {0};
2764 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
2768 HWRM_PREP(req, FUNC_QCFG, BNXT_USE_CHIMP_MB);
2769 req.fid = rte_cpu_to_le_16(0xffff);
2771 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2773 HWRM_CHECK_RESULT();
2775 /* Hard Coded.. 0xfff VLAN ID mask */
2776 bp->vlan = rte_le_to_cpu_16(resp->vlan) & 0xfff;
2777 flags = rte_le_to_cpu_16(resp->flags);
2778 if (BNXT_PF(bp) && (flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_MULTI_HOST))
2779 bp->flags |= BNXT_FLAG_MULTI_HOST;
2781 if (BNXT_VF(bp) && (flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_TRUSTED_VF)) {
2782 bp->flags |= BNXT_FLAG_TRUSTED_VF_EN;
2783 PMD_DRV_LOG(INFO, "Trusted VF cap enabled\n");
2784 } else if (BNXT_VF(bp) &&
2785 !(flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_TRUSTED_VF)) {
2786 bp->flags &= ~BNXT_FLAG_TRUSTED_VF_EN;
2787 PMD_DRV_LOG(INFO, "Trusted VF cap disabled\n");
2793 switch (resp->port_partition_type) {
2794 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR1_0:
2795 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR1_5:
2796 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR2_0:
2798 bp->port_partition_type = resp->port_partition_type;
2801 bp->port_partition_type = 0;
2810 static void copy_func_cfg_to_qcaps(struct hwrm_func_cfg_input *fcfg,
2811 struct hwrm_func_qcaps_output *qcaps)
2813 qcaps->max_rsscos_ctx = fcfg->num_rsscos_ctxs;
2814 memcpy(qcaps->mac_address, fcfg->dflt_mac_addr,
2815 sizeof(qcaps->mac_address));
2816 qcaps->max_l2_ctxs = fcfg->num_l2_ctxs;
2817 qcaps->max_rx_rings = fcfg->num_rx_rings;
2818 qcaps->max_tx_rings = fcfg->num_tx_rings;
2819 qcaps->max_cmpl_rings = fcfg->num_cmpl_rings;
2820 qcaps->max_stat_ctx = fcfg->num_stat_ctxs;
2822 qcaps->first_vf_id = 0;
2823 qcaps->max_vnics = fcfg->num_vnics;
2824 qcaps->max_decap_records = 0;
2825 qcaps->max_encap_records = 0;
2826 qcaps->max_tx_wm_flows = 0;
2827 qcaps->max_tx_em_flows = 0;
2828 qcaps->max_rx_wm_flows = 0;
2829 qcaps->max_rx_em_flows = 0;
2830 qcaps->max_flow_id = 0;
2831 qcaps->max_mcast_filters = fcfg->num_mcast_filters;
2832 qcaps->max_sp_tx_rings = 0;
2833 qcaps->max_hw_ring_grps = fcfg->num_hw_ring_grps;
2836 static int bnxt_hwrm_pf_func_cfg(struct bnxt *bp, int tx_rings)
2838 struct hwrm_func_cfg_input req = {0};
2839 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2843 enables = HWRM_FUNC_CFG_INPUT_ENABLES_MTU |
2844 HWRM_FUNC_CFG_INPUT_ENABLES_MRU |
2845 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS |
2846 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
2847 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
2848 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_TX_RINGS |
2849 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RX_RINGS |
2850 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_L2_CTXS |
2851 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_VNICS;
2853 if (BNXT_HAS_RING_GRPS(bp)) {
2854 enables |= HWRM_FUNC_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS;
2855 req.num_hw_ring_grps = rte_cpu_to_le_16(bp->max_ring_grps);
2856 } else if (BNXT_HAS_NQ(bp)) {
2857 enables |= HWRM_FUNC_CFG_INPUT_ENABLES_NUM_MSIX;
2858 req.num_msix = rte_cpu_to_le_16(bp->max_nq_rings);
2861 req.flags = rte_cpu_to_le_32(bp->pf.func_cfg_flags);
2862 req.mtu = rte_cpu_to_le_16(BNXT_MAX_MTU);
2863 req.mru = rte_cpu_to_le_16(bp->eth_dev->data->mtu + RTE_ETHER_HDR_LEN +
2864 RTE_ETHER_CRC_LEN + VLAN_TAG_SIZE *
2866 req.num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx);
2867 req.num_stat_ctxs = rte_cpu_to_le_16(bp->max_stat_ctx);
2868 req.num_cmpl_rings = rte_cpu_to_le_16(bp->max_cp_rings);
2869 req.num_tx_rings = rte_cpu_to_le_16(tx_rings);
2870 req.num_rx_rings = rte_cpu_to_le_16(bp->max_rx_rings);
2871 req.num_l2_ctxs = rte_cpu_to_le_16(bp->max_l2_ctx);
2872 req.num_vnics = rte_cpu_to_le_16(bp->max_vnics);
2873 req.fid = rte_cpu_to_le_16(0xffff);
2874 req.enables = rte_cpu_to_le_32(enables);
2876 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
2878 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2880 HWRM_CHECK_RESULT();
2886 static void populate_vf_func_cfg_req(struct bnxt *bp,
2887 struct hwrm_func_cfg_input *req,
2890 req->enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_MTU |
2891 HWRM_FUNC_CFG_INPUT_ENABLES_MRU |
2892 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS |
2893 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
2894 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
2895 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_TX_RINGS |
2896 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RX_RINGS |
2897 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_L2_CTXS |
2898 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_VNICS |
2899 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS);
2901 req->mtu = rte_cpu_to_le_16(bp->eth_dev->data->mtu + RTE_ETHER_HDR_LEN +
2902 RTE_ETHER_CRC_LEN + VLAN_TAG_SIZE *
2904 req->mru = rte_cpu_to_le_16(bp->eth_dev->data->mtu + RTE_ETHER_HDR_LEN +
2905 RTE_ETHER_CRC_LEN + VLAN_TAG_SIZE *
2907 req->num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx /
2909 req->num_stat_ctxs = rte_cpu_to_le_16(bp->max_stat_ctx / (num_vfs + 1));
2910 req->num_cmpl_rings = rte_cpu_to_le_16(bp->max_cp_rings /
2912 req->num_tx_rings = rte_cpu_to_le_16(bp->max_tx_rings / (num_vfs + 1));
2913 req->num_rx_rings = rte_cpu_to_le_16(bp->max_rx_rings / (num_vfs + 1));
2914 req->num_l2_ctxs = rte_cpu_to_le_16(bp->max_l2_ctx / (num_vfs + 1));
2915 /* TODO: For now, do not support VMDq/RFS on VFs. */
2916 req->num_vnics = rte_cpu_to_le_16(1);
2917 req->num_hw_ring_grps = rte_cpu_to_le_16(bp->max_ring_grps /
2921 static void add_random_mac_if_needed(struct bnxt *bp,
2922 struct hwrm_func_cfg_input *cfg_req,
2925 struct rte_ether_addr mac;
2927 if (bnxt_hwrm_func_qcfg_vf_default_mac(bp, vf, &mac))
2930 if (memcmp(mac.addr_bytes, "\x00\x00\x00\x00\x00", 6) == 0) {
2932 rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
2933 rte_eth_random_addr(cfg_req->dflt_mac_addr);
2934 bp->pf.vf_info[vf].random_mac = true;
2936 memcpy(cfg_req->dflt_mac_addr, mac.addr_bytes,
2937 RTE_ETHER_ADDR_LEN);
2941 static void reserve_resources_from_vf(struct bnxt *bp,
2942 struct hwrm_func_cfg_input *cfg_req,
2945 struct hwrm_func_qcaps_input req = {0};
2946 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
2949 /* Get the actual allocated values now */
2950 HWRM_PREP(req, FUNC_QCAPS, BNXT_USE_CHIMP_MB);
2951 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
2952 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2955 PMD_DRV_LOG(ERR, "hwrm_func_qcaps failed rc:%d\n", rc);
2956 copy_func_cfg_to_qcaps(cfg_req, resp);
2957 } else if (resp->error_code) {
2958 rc = rte_le_to_cpu_16(resp->error_code);
2959 PMD_DRV_LOG(ERR, "hwrm_func_qcaps error %d\n", rc);
2960 copy_func_cfg_to_qcaps(cfg_req, resp);
2963 bp->max_rsscos_ctx -= rte_le_to_cpu_16(resp->max_rsscos_ctx);
2964 bp->max_stat_ctx -= rte_le_to_cpu_16(resp->max_stat_ctx);
2965 bp->max_cp_rings -= rte_le_to_cpu_16(resp->max_cmpl_rings);
2966 bp->max_tx_rings -= rte_le_to_cpu_16(resp->max_tx_rings);
2967 bp->max_rx_rings -= rte_le_to_cpu_16(resp->max_rx_rings);
2968 bp->max_l2_ctx -= rte_le_to_cpu_16(resp->max_l2_ctxs);
2970 * TODO: While not supporting VMDq with VFs, max_vnics is always
2971 * forced to 1 in this case
2973 //bp->max_vnics -= rte_le_to_cpu_16(esp->max_vnics);
2974 bp->max_ring_grps -= rte_le_to_cpu_16(resp->max_hw_ring_grps);
2979 int bnxt_hwrm_func_qcfg_current_vf_vlan(struct bnxt *bp, int vf)
2981 struct hwrm_func_qcfg_input req = {0};
2982 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
2985 /* Check for zero MAC address */
2986 HWRM_PREP(req, FUNC_QCFG, BNXT_USE_CHIMP_MB);
2987 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
2988 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2989 HWRM_CHECK_RESULT();
2990 rc = rte_le_to_cpu_16(resp->vlan);
2997 static int update_pf_resource_max(struct bnxt *bp)
2999 struct hwrm_func_qcfg_input req = {0};
3000 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
3003 /* And copy the allocated numbers into the pf struct */
3004 HWRM_PREP(req, FUNC_QCFG, BNXT_USE_CHIMP_MB);
3005 req.fid = rte_cpu_to_le_16(0xffff);
3006 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3007 HWRM_CHECK_RESULT();
3009 /* Only TX ring value reflects actual allocation? TODO */
3010 bp->max_tx_rings = rte_le_to_cpu_16(resp->alloc_tx_rings);
3011 bp->pf.evb_mode = resp->evb_mode;
3018 int bnxt_hwrm_allocate_pf_only(struct bnxt *bp)
3023 PMD_DRV_LOG(ERR, "Attempt to allcoate VFs on a VF!\n");
3027 rc = bnxt_hwrm_func_qcaps(bp);
3031 bp->pf.func_cfg_flags &=
3032 ~(HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE |
3033 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE);
3034 bp->pf.func_cfg_flags |=
3035 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE;
3036 rc = bnxt_hwrm_pf_func_cfg(bp, bp->max_tx_rings);
3037 rc = __bnxt_hwrm_func_qcaps(bp);
3041 int bnxt_hwrm_allocate_vfs(struct bnxt *bp, int num_vfs)
3043 struct hwrm_func_cfg_input req = {0};
3044 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3051 PMD_DRV_LOG(ERR, "Attempt to allcoate VFs on a VF!\n");
3055 rc = bnxt_hwrm_func_qcaps(bp);
3060 bp->pf.active_vfs = num_vfs;
3063 * First, configure the PF to only use one TX ring. This ensures that
3064 * there are enough rings for all VFs.
3066 * If we don't do this, when we call func_alloc() later, we will lock
3067 * extra rings to the PF that won't be available during func_cfg() of
3070 * This has been fixed with firmware versions above 20.6.54
3072 bp->pf.func_cfg_flags &=
3073 ~(HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE |
3074 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE);
3075 bp->pf.func_cfg_flags |=
3076 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE;
3077 rc = bnxt_hwrm_pf_func_cfg(bp, 1);
3082 * Now, create and register a buffer to hold forwarded VF requests
3084 req_buf_sz = num_vfs * HWRM_MAX_REQ_LEN;
3085 bp->pf.vf_req_buf = rte_malloc("bnxt_vf_fwd", req_buf_sz,
3086 page_roundup(num_vfs * HWRM_MAX_REQ_LEN));
3087 if (bp->pf.vf_req_buf == NULL) {
3091 for (sz = 0; sz < req_buf_sz; sz += getpagesize())
3092 rte_mem_lock_page(((char *)bp->pf.vf_req_buf) + sz);
3093 for (i = 0; i < num_vfs; i++)
3094 bp->pf.vf_info[i].req_buf = ((char *)bp->pf.vf_req_buf) +
3095 (i * HWRM_MAX_REQ_LEN);
3097 rc = bnxt_hwrm_func_buf_rgtr(bp);
3101 populate_vf_func_cfg_req(bp, &req, num_vfs);
3103 bp->pf.active_vfs = 0;
3104 for (i = 0; i < num_vfs; i++) {
3105 add_random_mac_if_needed(bp, &req, i);
3107 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
3108 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[i].func_cfg_flags);
3109 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[i].fid);
3110 rc = bnxt_hwrm_send_message(bp,
3115 /* Clear enable flag for next pass */
3116 req.enables &= ~rte_cpu_to_le_32(
3117 HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
3119 if (rc || resp->error_code) {
3121 "Failed to initizlie VF %d\n", i);
3123 "Not all VFs available. (%d, %d)\n",
3124 rc, resp->error_code);
3131 reserve_resources_from_vf(bp, &req, i);
3132 bp->pf.active_vfs++;
3133 bnxt_hwrm_func_clr_stats(bp, bp->pf.vf_info[i].fid);
3137 * Now configure the PF to use "the rest" of the resources
3138 * We're using STD_TX_RING_MODE here though which will limit the TX
3139 * rings. This will allow QoS to function properly. Not setting this
3140 * will cause PF rings to break bandwidth settings.
3142 rc = bnxt_hwrm_pf_func_cfg(bp, bp->max_tx_rings);
3146 rc = update_pf_resource_max(bp);
3153 bnxt_hwrm_func_buf_unrgtr(bp);
3157 int bnxt_hwrm_pf_evb_mode(struct bnxt *bp)
3159 struct hwrm_func_cfg_input req = {0};
3160 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3163 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
3165 req.fid = rte_cpu_to_le_16(0xffff);
3166 req.enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_EVB_MODE);
3167 req.evb_mode = bp->pf.evb_mode;
3169 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3170 HWRM_CHECK_RESULT();
3176 int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt *bp, uint16_t port,
3177 uint8_t tunnel_type)
3179 struct hwrm_tunnel_dst_port_alloc_input req = {0};
3180 struct hwrm_tunnel_dst_port_alloc_output *resp = bp->hwrm_cmd_resp_addr;
3183 HWRM_PREP(req, TUNNEL_DST_PORT_ALLOC, BNXT_USE_CHIMP_MB);
3184 req.tunnel_type = tunnel_type;
3185 req.tunnel_dst_port_val = port;
3186 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3187 HWRM_CHECK_RESULT();
3189 switch (tunnel_type) {
3190 case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_VXLAN:
3191 bp->vxlan_fw_dst_port_id = resp->tunnel_dst_port_id;
3192 bp->vxlan_port = port;
3194 case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_GENEVE:
3195 bp->geneve_fw_dst_port_id = resp->tunnel_dst_port_id;
3196 bp->geneve_port = port;
3207 int bnxt_hwrm_tunnel_dst_port_free(struct bnxt *bp, uint16_t port,
3208 uint8_t tunnel_type)
3210 struct hwrm_tunnel_dst_port_free_input req = {0};
3211 struct hwrm_tunnel_dst_port_free_output *resp = bp->hwrm_cmd_resp_addr;
3214 HWRM_PREP(req, TUNNEL_DST_PORT_FREE, BNXT_USE_CHIMP_MB);
3216 req.tunnel_type = tunnel_type;
3217 req.tunnel_dst_port_id = rte_cpu_to_be_16(port);
3218 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3220 HWRM_CHECK_RESULT();
3226 int bnxt_hwrm_func_cfg_vf_set_flags(struct bnxt *bp, uint16_t vf,
3229 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3230 struct hwrm_func_cfg_input req = {0};
3233 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
3235 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3236 req.flags = rte_cpu_to_le_32(flags);
3237 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3239 HWRM_CHECK_RESULT();
3245 void vf_vnic_set_rxmask_cb(struct bnxt_vnic_info *vnic, void *flagp)
3247 uint32_t *flag = flagp;
3249 vnic->flags = *flag;
3252 int bnxt_set_rx_mask_no_vlan(struct bnxt *bp, struct bnxt_vnic_info *vnic)
3254 return bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
3257 int bnxt_hwrm_func_buf_rgtr(struct bnxt *bp)
3260 struct hwrm_func_buf_rgtr_input req = {.req_type = 0 };
3261 struct hwrm_func_buf_rgtr_output *resp = bp->hwrm_cmd_resp_addr;
3263 HWRM_PREP(req, FUNC_BUF_RGTR, BNXT_USE_CHIMP_MB);
3265 req.req_buf_num_pages = rte_cpu_to_le_16(1);
3266 req.req_buf_page_size = rte_cpu_to_le_16(
3267 page_getenum(bp->pf.active_vfs * HWRM_MAX_REQ_LEN));
3268 req.req_buf_len = rte_cpu_to_le_16(HWRM_MAX_REQ_LEN);
3269 req.req_buf_page_addr0 =
3270 rte_cpu_to_le_64(rte_mem_virt2iova(bp->pf.vf_req_buf));
3271 if (req.req_buf_page_addr0 == RTE_BAD_IOVA) {
3273 "unable to map buffer address to physical memory\n");
3277 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3279 HWRM_CHECK_RESULT();
3285 int bnxt_hwrm_func_buf_unrgtr(struct bnxt *bp)
3288 struct hwrm_func_buf_unrgtr_input req = {.req_type = 0 };
3289 struct hwrm_func_buf_unrgtr_output *resp = bp->hwrm_cmd_resp_addr;
3291 if (!(BNXT_PF(bp) && bp->pdev->max_vfs))
3294 HWRM_PREP(req, FUNC_BUF_UNRGTR, BNXT_USE_CHIMP_MB);
3296 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3298 HWRM_CHECK_RESULT();
3304 int bnxt_hwrm_func_cfg_def_cp(struct bnxt *bp)
3306 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3307 struct hwrm_func_cfg_input req = {0};
3310 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
3312 req.fid = rte_cpu_to_le_16(0xffff);
3313 req.flags = rte_cpu_to_le_32(bp->pf.func_cfg_flags);
3314 req.enables = rte_cpu_to_le_32(
3315 HWRM_FUNC_CFG_INPUT_ENABLES_ASYNC_EVENT_CR);
3316 req.async_event_cr = rte_cpu_to_le_16(
3317 bp->async_cp_ring->cp_ring_struct->fw_ring_id);
3318 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3320 HWRM_CHECK_RESULT();
3326 int bnxt_hwrm_vf_func_cfg_def_cp(struct bnxt *bp)
3328 struct hwrm_func_vf_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3329 struct hwrm_func_vf_cfg_input req = {0};
3332 HWRM_PREP(req, FUNC_VF_CFG, BNXT_USE_CHIMP_MB);
3334 req.enables = rte_cpu_to_le_32(
3335 HWRM_FUNC_VF_CFG_INPUT_ENABLES_ASYNC_EVENT_CR);
3336 req.async_event_cr = rte_cpu_to_le_16(
3337 bp->async_cp_ring->cp_ring_struct->fw_ring_id);
3338 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3340 HWRM_CHECK_RESULT();
3346 int bnxt_hwrm_set_default_vlan(struct bnxt *bp, int vf, uint8_t is_vf)
3348 struct hwrm_func_cfg_input req = {0};
3349 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3350 uint16_t dflt_vlan, fid;
3351 uint32_t func_cfg_flags;
3354 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
3357 dflt_vlan = bp->pf.vf_info[vf].dflt_vlan;
3358 fid = bp->pf.vf_info[vf].fid;
3359 func_cfg_flags = bp->pf.vf_info[vf].func_cfg_flags;
3361 fid = rte_cpu_to_le_16(0xffff);
3362 func_cfg_flags = bp->pf.func_cfg_flags;
3363 dflt_vlan = bp->vlan;
3366 req.flags = rte_cpu_to_le_32(func_cfg_flags);
3367 req.fid = rte_cpu_to_le_16(fid);
3368 req.enables |= rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_VLAN);
3369 req.dflt_vlan = rte_cpu_to_le_16(dflt_vlan);
3371 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3373 HWRM_CHECK_RESULT();
3379 int bnxt_hwrm_func_bw_cfg(struct bnxt *bp, uint16_t vf,
3380 uint16_t max_bw, uint16_t enables)
3382 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3383 struct hwrm_func_cfg_input req = {0};
3386 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
3388 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3389 req.enables |= rte_cpu_to_le_32(enables);
3390 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[vf].func_cfg_flags);
3391 req.max_bw = rte_cpu_to_le_32(max_bw);
3392 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3394 HWRM_CHECK_RESULT();
3400 int bnxt_hwrm_set_vf_vlan(struct bnxt *bp, int vf)
3402 struct hwrm_func_cfg_input req = {0};
3403 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3406 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
3408 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[vf].func_cfg_flags);
3409 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3410 req.enables |= rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_VLAN);
3411 req.dflt_vlan = rte_cpu_to_le_16(bp->pf.vf_info[vf].dflt_vlan);
3413 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3415 HWRM_CHECK_RESULT();
3421 int bnxt_hwrm_set_async_event_cr(struct bnxt *bp)
3426 rc = bnxt_hwrm_func_cfg_def_cp(bp);
3428 rc = bnxt_hwrm_vf_func_cfg_def_cp(bp);
3433 int bnxt_hwrm_reject_fwd_resp(struct bnxt *bp, uint16_t target_id,
3434 void *encaped, size_t ec_size)
3437 struct hwrm_reject_fwd_resp_input req = {.req_type = 0};
3438 struct hwrm_reject_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr;
3440 if (ec_size > sizeof(req.encap_request))
3443 HWRM_PREP(req, REJECT_FWD_RESP, BNXT_USE_CHIMP_MB);
3445 req.encap_resp_target_id = rte_cpu_to_le_16(target_id);
3446 memcpy(req.encap_request, encaped, ec_size);
3448 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3450 HWRM_CHECK_RESULT();
3456 int bnxt_hwrm_func_qcfg_vf_default_mac(struct bnxt *bp, uint16_t vf,
3457 struct rte_ether_addr *mac)
3459 struct hwrm_func_qcfg_input req = {0};
3460 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
3463 HWRM_PREP(req, FUNC_QCFG, BNXT_USE_CHIMP_MB);
3465 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3466 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3468 HWRM_CHECK_RESULT();
3470 memcpy(mac->addr_bytes, resp->mac_address, RTE_ETHER_ADDR_LEN);
3477 int bnxt_hwrm_exec_fwd_resp(struct bnxt *bp, uint16_t target_id,
3478 void *encaped, size_t ec_size)
3481 struct hwrm_exec_fwd_resp_input req = {.req_type = 0};
3482 struct hwrm_exec_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr;
3484 if (ec_size > sizeof(req.encap_request))
3487 HWRM_PREP(req, EXEC_FWD_RESP, BNXT_USE_CHIMP_MB);
3489 req.encap_resp_target_id = rte_cpu_to_le_16(target_id);
3490 memcpy(req.encap_request, encaped, ec_size);
3492 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3494 HWRM_CHECK_RESULT();
3500 int bnxt_hwrm_ctx_qstats(struct bnxt *bp, uint32_t cid, int idx,
3501 struct rte_eth_stats *stats, uint8_t rx)
3504 struct hwrm_stat_ctx_query_input req = {.req_type = 0};
3505 struct hwrm_stat_ctx_query_output *resp = bp->hwrm_cmd_resp_addr;
3507 HWRM_PREP(req, STAT_CTX_QUERY, BNXT_USE_CHIMP_MB);
3509 req.stat_ctx_id = rte_cpu_to_le_32(cid);
3511 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3513 HWRM_CHECK_RESULT();
3516 stats->q_ipackets[idx] = rte_le_to_cpu_64(resp->rx_ucast_pkts);
3517 stats->q_ipackets[idx] += rte_le_to_cpu_64(resp->rx_mcast_pkts);
3518 stats->q_ipackets[idx] += rte_le_to_cpu_64(resp->rx_bcast_pkts);
3519 stats->q_ibytes[idx] = rte_le_to_cpu_64(resp->rx_ucast_bytes);
3520 stats->q_ibytes[idx] += rte_le_to_cpu_64(resp->rx_mcast_bytes);
3521 stats->q_ibytes[idx] += rte_le_to_cpu_64(resp->rx_bcast_bytes);
3522 stats->q_errors[idx] = rte_le_to_cpu_64(resp->rx_err_pkts);
3523 stats->q_errors[idx] += rte_le_to_cpu_64(resp->rx_drop_pkts);
3525 stats->q_opackets[idx] = rte_le_to_cpu_64(resp->tx_ucast_pkts);
3526 stats->q_opackets[idx] += rte_le_to_cpu_64(resp->tx_mcast_pkts);
3527 stats->q_opackets[idx] += rte_le_to_cpu_64(resp->tx_bcast_pkts);
3528 stats->q_obytes[idx] = rte_le_to_cpu_64(resp->tx_ucast_bytes);
3529 stats->q_obytes[idx] += rte_le_to_cpu_64(resp->tx_mcast_bytes);
3530 stats->q_obytes[idx] += rte_le_to_cpu_64(resp->tx_bcast_bytes);
3539 int bnxt_hwrm_port_qstats(struct bnxt *bp)
3541 struct hwrm_port_qstats_input req = {0};
3542 struct hwrm_port_qstats_output *resp = bp->hwrm_cmd_resp_addr;
3543 struct bnxt_pf_info *pf = &bp->pf;
3546 HWRM_PREP(req, PORT_QSTATS, BNXT_USE_CHIMP_MB);
3548 req.port_id = rte_cpu_to_le_16(pf->port_id);
3549 req.tx_stat_host_addr = rte_cpu_to_le_64(bp->hw_tx_port_stats_map);
3550 req.rx_stat_host_addr = rte_cpu_to_le_64(bp->hw_rx_port_stats_map);
3551 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3553 HWRM_CHECK_RESULT();
3559 int bnxt_hwrm_port_clr_stats(struct bnxt *bp)
3561 struct hwrm_port_clr_stats_input req = {0};
3562 struct hwrm_port_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
3563 struct bnxt_pf_info *pf = &bp->pf;
3566 /* Not allowed on NS2 device, NPAR, MultiHost, VF */
3567 if (!(bp->flags & BNXT_FLAG_PORT_STATS) || BNXT_VF(bp) ||
3568 BNXT_NPAR(bp) || BNXT_MH(bp) || BNXT_TOTAL_VFS(bp))
3571 HWRM_PREP(req, PORT_CLR_STATS, BNXT_USE_CHIMP_MB);
3573 req.port_id = rte_cpu_to_le_16(pf->port_id);
3574 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3576 HWRM_CHECK_RESULT();
3582 int bnxt_hwrm_port_led_qcaps(struct bnxt *bp)
3584 struct hwrm_port_led_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
3585 struct hwrm_port_led_qcaps_input req = {0};
3591 HWRM_PREP(req, PORT_LED_QCAPS, BNXT_USE_CHIMP_MB);
3592 req.port_id = bp->pf.port_id;
3593 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3595 HWRM_CHECK_RESULT();
3597 if (resp->num_leds > 0 && resp->num_leds < BNXT_MAX_LED) {
3600 bp->num_leds = resp->num_leds;
3601 memcpy(bp->leds, &resp->led0_id,
3602 sizeof(bp->leds[0]) * bp->num_leds);
3603 for (i = 0; i < bp->num_leds; i++) {
3604 struct bnxt_led_info *led = &bp->leds[i];
3606 uint16_t caps = led->led_state_caps;
3608 if (!led->led_group_id ||
3609 !BNXT_LED_ALT_BLINK_CAP(caps)) {
3621 int bnxt_hwrm_port_led_cfg(struct bnxt *bp, bool led_on)
3623 struct hwrm_port_led_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3624 struct hwrm_port_led_cfg_input req = {0};
3625 struct bnxt_led_cfg *led_cfg;
3626 uint8_t led_state = HWRM_PORT_LED_QCFG_OUTPUT_LED0_STATE_DEFAULT;
3627 uint16_t duration = 0;
3630 if (!bp->num_leds || BNXT_VF(bp))
3633 HWRM_PREP(req, PORT_LED_CFG, BNXT_USE_CHIMP_MB);
3636 led_state = HWRM_PORT_LED_CFG_INPUT_LED0_STATE_BLINKALT;
3637 duration = rte_cpu_to_le_16(500);
3639 req.port_id = bp->pf.port_id;
3640 req.num_leds = bp->num_leds;
3641 led_cfg = (struct bnxt_led_cfg *)&req.led0_id;
3642 for (i = 0; i < bp->num_leds; i++, led_cfg++) {
3643 req.enables |= BNXT_LED_DFLT_ENABLES(i);
3644 led_cfg->led_id = bp->leds[i].led_id;
3645 led_cfg->led_state = led_state;
3646 led_cfg->led_blink_on = duration;
3647 led_cfg->led_blink_off = duration;
3648 led_cfg->led_group_id = bp->leds[i].led_group_id;
3651 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3653 HWRM_CHECK_RESULT();
3659 int bnxt_hwrm_nvm_get_dir_info(struct bnxt *bp, uint32_t *entries,
3663 struct hwrm_nvm_get_dir_info_input req = {0};
3664 struct hwrm_nvm_get_dir_info_output *resp = bp->hwrm_cmd_resp_addr;
3666 HWRM_PREP(req, NVM_GET_DIR_INFO, BNXT_USE_CHIMP_MB);
3668 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3670 HWRM_CHECK_RESULT();
3672 *entries = rte_le_to_cpu_32(resp->entries);
3673 *length = rte_le_to_cpu_32(resp->entry_length);
3679 int bnxt_get_nvram_directory(struct bnxt *bp, uint32_t len, uint8_t *data)
3682 uint32_t dir_entries;
3683 uint32_t entry_length;
3686 rte_iova_t dma_handle;
3687 struct hwrm_nvm_get_dir_entries_input req = {0};
3688 struct hwrm_nvm_get_dir_entries_output *resp = bp->hwrm_cmd_resp_addr;
3690 rc = bnxt_hwrm_nvm_get_dir_info(bp, &dir_entries, &entry_length);
3694 *data++ = dir_entries;
3695 *data++ = entry_length;
3697 memset(data, 0xff, len);
3699 buflen = dir_entries * entry_length;
3700 buf = rte_malloc("nvm_dir", buflen, 0);
3701 rte_mem_lock_page(buf);
3704 dma_handle = rte_mem_virt2iova(buf);
3705 if (dma_handle == RTE_BAD_IOVA) {
3707 "unable to map response address to physical memory\n");
3710 HWRM_PREP(req, NVM_GET_DIR_ENTRIES, BNXT_USE_CHIMP_MB);
3711 req.host_dest_addr = rte_cpu_to_le_64(dma_handle);
3712 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3715 memcpy(data, buf, len > buflen ? buflen : len);
3718 HWRM_CHECK_RESULT();
3724 int bnxt_hwrm_get_nvram_item(struct bnxt *bp, uint32_t index,
3725 uint32_t offset, uint32_t length,
3730 rte_iova_t dma_handle;
3731 struct hwrm_nvm_read_input req = {0};
3732 struct hwrm_nvm_read_output *resp = bp->hwrm_cmd_resp_addr;
3734 buf = rte_malloc("nvm_item", length, 0);
3735 rte_mem_lock_page(buf);
3739 dma_handle = rte_mem_virt2iova(buf);
3740 if (dma_handle == RTE_BAD_IOVA) {
3742 "unable to map response address to physical memory\n");
3745 HWRM_PREP(req, NVM_READ, BNXT_USE_CHIMP_MB);
3746 req.host_dest_addr = rte_cpu_to_le_64(dma_handle);
3747 req.dir_idx = rte_cpu_to_le_16(index);
3748 req.offset = rte_cpu_to_le_32(offset);
3749 req.len = rte_cpu_to_le_32(length);
3750 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3752 memcpy(data, buf, length);
3755 HWRM_CHECK_RESULT();
3761 int bnxt_hwrm_erase_nvram_directory(struct bnxt *bp, uint8_t index)
3764 struct hwrm_nvm_erase_dir_entry_input req = {0};
3765 struct hwrm_nvm_erase_dir_entry_output *resp = bp->hwrm_cmd_resp_addr;
3767 HWRM_PREP(req, NVM_ERASE_DIR_ENTRY, BNXT_USE_CHIMP_MB);
3768 req.dir_idx = rte_cpu_to_le_16(index);
3769 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3770 HWRM_CHECK_RESULT();
3777 int bnxt_hwrm_flash_nvram(struct bnxt *bp, uint16_t dir_type,
3778 uint16_t dir_ordinal, uint16_t dir_ext,
3779 uint16_t dir_attr, const uint8_t *data,
3783 struct hwrm_nvm_write_input req = {0};
3784 struct hwrm_nvm_write_output *resp = bp->hwrm_cmd_resp_addr;
3785 rte_iova_t dma_handle;
3788 buf = rte_malloc("nvm_write", data_len, 0);
3789 rte_mem_lock_page(buf);
3793 dma_handle = rte_mem_virt2iova(buf);
3794 if (dma_handle == RTE_BAD_IOVA) {
3796 "unable to map response address to physical memory\n");
3799 memcpy(buf, data, data_len);
3801 HWRM_PREP(req, NVM_WRITE, BNXT_USE_CHIMP_MB);
3803 req.dir_type = rte_cpu_to_le_16(dir_type);
3804 req.dir_ordinal = rte_cpu_to_le_16(dir_ordinal);
3805 req.dir_ext = rte_cpu_to_le_16(dir_ext);
3806 req.dir_attr = rte_cpu_to_le_16(dir_attr);
3807 req.dir_data_length = rte_cpu_to_le_32(data_len);
3808 req.host_src_addr = rte_cpu_to_le_64(dma_handle);
3810 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3813 HWRM_CHECK_RESULT();
3820 bnxt_vnic_count(struct bnxt_vnic_info *vnic __rte_unused, void *cbdata)
3822 uint32_t *count = cbdata;
3824 *count = *count + 1;
3827 static int bnxt_vnic_count_hwrm_stub(struct bnxt *bp __rte_unused,
3828 struct bnxt_vnic_info *vnic __rte_unused)
3833 int bnxt_vf_vnic_count(struct bnxt *bp, uint16_t vf)
3837 bnxt_hwrm_func_vf_vnic_query_and_config(bp, vf, bnxt_vnic_count,
3838 &count, bnxt_vnic_count_hwrm_stub);
3843 static int bnxt_hwrm_func_vf_vnic_query(struct bnxt *bp, uint16_t vf,
3846 struct hwrm_func_vf_vnic_ids_query_input req = {0};
3847 struct hwrm_func_vf_vnic_ids_query_output *resp =
3848 bp->hwrm_cmd_resp_addr;
3851 /* First query all VNIC ids */
3852 HWRM_PREP(req, FUNC_VF_VNIC_IDS_QUERY, BNXT_USE_CHIMP_MB);
3854 req.vf_id = rte_cpu_to_le_16(bp->pf.first_vf_id + vf);
3855 req.max_vnic_id_cnt = rte_cpu_to_le_32(bp->pf.total_vnics);
3856 req.vnic_id_tbl_addr = rte_cpu_to_le_64(rte_mem_virt2iova(vnic_ids));
3858 if (req.vnic_id_tbl_addr == RTE_BAD_IOVA) {
3861 "unable to map VNIC ID table address to physical memory\n");
3864 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3865 HWRM_CHECK_RESULT();
3866 rc = rte_le_to_cpu_32(resp->vnic_id_cnt);
3874 * This function queries the VNIC IDs for a specified VF. It then calls
3875 * the vnic_cb to update the necessary field in vnic_info with cbdata.
3876 * Then it calls the hwrm_cb function to program this new vnic configuration.
3878 int bnxt_hwrm_func_vf_vnic_query_and_config(struct bnxt *bp, uint16_t vf,
3879 void (*vnic_cb)(struct bnxt_vnic_info *, void *), void *cbdata,
3880 int (*hwrm_cb)(struct bnxt *bp, struct bnxt_vnic_info *vnic))
3882 struct bnxt_vnic_info vnic;
3884 int i, num_vnic_ids;
3889 /* First query all VNIC ids */
3890 vnic_id_sz = bp->pf.total_vnics * sizeof(*vnic_ids);
3891 vnic_ids = rte_malloc("bnxt_hwrm_vf_vnic_ids_query", vnic_id_sz,
3892 RTE_CACHE_LINE_SIZE);
3893 if (vnic_ids == NULL)
3896 for (sz = 0; sz < vnic_id_sz; sz += getpagesize())
3897 rte_mem_lock_page(((char *)vnic_ids) + sz);
3899 num_vnic_ids = bnxt_hwrm_func_vf_vnic_query(bp, vf, vnic_ids);
3901 if (num_vnic_ids < 0)
3902 return num_vnic_ids;
3904 /* Retrieve VNIC, update bd_stall then update */
3906 for (i = 0; i < num_vnic_ids; i++) {
3907 memset(&vnic, 0, sizeof(struct bnxt_vnic_info));
3908 vnic.fw_vnic_id = rte_le_to_cpu_16(vnic_ids[i]);
3909 rc = bnxt_hwrm_vnic_qcfg(bp, &vnic, bp->pf.first_vf_id + vf);
3912 if (vnic.mru <= 4) /* Indicates unallocated */
3915 vnic_cb(&vnic, cbdata);
3917 rc = hwrm_cb(bp, &vnic);
3927 int bnxt_hwrm_func_cfg_vf_set_vlan_anti_spoof(struct bnxt *bp, uint16_t vf,
3930 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3931 struct hwrm_func_cfg_input req = {0};
3934 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
3936 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3937 req.enables |= rte_cpu_to_le_32(
3938 HWRM_FUNC_CFG_INPUT_ENABLES_VLAN_ANTISPOOF_MODE);
3939 req.vlan_antispoof_mode = on ?
3940 HWRM_FUNC_CFG_INPUT_VLAN_ANTISPOOF_MODE_VALIDATE_VLAN :
3941 HWRM_FUNC_CFG_INPUT_VLAN_ANTISPOOF_MODE_NOCHECK;
3942 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3944 HWRM_CHECK_RESULT();
3950 int bnxt_hwrm_func_qcfg_vf_dflt_vnic_id(struct bnxt *bp, int vf)
3952 struct bnxt_vnic_info vnic;
3955 int num_vnic_ids, i;
3959 vnic_id_sz = bp->pf.total_vnics * sizeof(*vnic_ids);
3960 vnic_ids = rte_malloc("bnxt_hwrm_vf_vnic_ids_query", vnic_id_sz,
3961 RTE_CACHE_LINE_SIZE);
3962 if (vnic_ids == NULL)
3965 for (sz = 0; sz < vnic_id_sz; sz += getpagesize())
3966 rte_mem_lock_page(((char *)vnic_ids) + sz);
3968 rc = bnxt_hwrm_func_vf_vnic_query(bp, vf, vnic_ids);
3974 * Loop through to find the default VNIC ID.
3975 * TODO: The easier way would be to obtain the resp->dflt_vnic_id
3976 * by sending the hwrm_func_qcfg command to the firmware.
3978 for (i = 0; i < num_vnic_ids; i++) {
3979 memset(&vnic, 0, sizeof(struct bnxt_vnic_info));
3980 vnic.fw_vnic_id = rte_le_to_cpu_16(vnic_ids[i]);
3981 rc = bnxt_hwrm_vnic_qcfg(bp, &vnic,
3982 bp->pf.first_vf_id + vf);
3985 if (vnic.func_default) {
3987 return vnic.fw_vnic_id;
3990 /* Could not find a default VNIC. */
3991 PMD_DRV_LOG(ERR, "No default VNIC\n");
3997 int bnxt_hwrm_set_em_filter(struct bnxt *bp,
3999 struct bnxt_filter_info *filter)
4002 struct hwrm_cfa_em_flow_alloc_input req = {.req_type = 0 };
4003 struct hwrm_cfa_em_flow_alloc_output *resp = bp->hwrm_cmd_resp_addr;
4004 uint32_t enables = 0;
4006 if (filter->fw_em_filter_id != UINT64_MAX)
4007 bnxt_hwrm_clear_em_filter(bp, filter);
4009 HWRM_PREP(req, CFA_EM_FLOW_ALLOC, BNXT_USE_KONG(bp));
4011 req.flags = rte_cpu_to_le_32(filter->flags);
4013 enables = filter->enables |
4014 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_ID;
4015 req.dst_id = rte_cpu_to_le_16(dst_id);
4017 if (filter->ip_addr_type) {
4018 req.ip_addr_type = filter->ip_addr_type;
4019 enables |= HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IPADDR_TYPE;
4022 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_L2_FILTER_ID)
4023 req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
4025 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_MACADDR)
4026 memcpy(req.src_macaddr, filter->src_macaddr,
4027 RTE_ETHER_ADDR_LEN);
4029 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_MACADDR)
4030 memcpy(req.dst_macaddr, filter->dst_macaddr,
4031 RTE_ETHER_ADDR_LEN);
4033 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_OVLAN_VID)
4034 req.ovlan_vid = filter->l2_ovlan;
4036 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IVLAN_VID)
4037 req.ivlan_vid = filter->l2_ivlan;
4039 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_ETHERTYPE)
4040 req.ethertype = rte_cpu_to_be_16(filter->ethertype);
4042 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IP_PROTOCOL)
4043 req.ip_protocol = filter->ip_protocol;
4045 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_IPADDR)
4046 req.src_ipaddr[0] = rte_cpu_to_be_32(filter->src_ipaddr[0]);
4048 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_IPADDR)
4049 req.dst_ipaddr[0] = rte_cpu_to_be_32(filter->dst_ipaddr[0]);
4051 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_PORT)
4052 req.src_port = rte_cpu_to_be_16(filter->src_port);
4054 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_PORT)
4055 req.dst_port = rte_cpu_to_be_16(filter->dst_port);
4057 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_MIRROR_VNIC_ID)
4058 req.mirror_vnic_id = filter->mirror_vnic_id;
4060 req.enables = rte_cpu_to_le_32(enables);
4062 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
4064 HWRM_CHECK_RESULT();
4066 filter->fw_em_filter_id = rte_le_to_cpu_64(resp->em_filter_id);
4072 int bnxt_hwrm_clear_em_filter(struct bnxt *bp, struct bnxt_filter_info *filter)
4075 struct hwrm_cfa_em_flow_free_input req = {.req_type = 0 };
4076 struct hwrm_cfa_em_flow_free_output *resp = bp->hwrm_cmd_resp_addr;
4078 if (filter->fw_em_filter_id == UINT64_MAX)
4081 PMD_DRV_LOG(ERR, "Clear EM filter\n");
4082 HWRM_PREP(req, CFA_EM_FLOW_FREE, BNXT_USE_KONG(bp));
4084 req.em_filter_id = rte_cpu_to_le_64(filter->fw_em_filter_id);
4086 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
4088 HWRM_CHECK_RESULT();
4091 filter->fw_em_filter_id = UINT64_MAX;
4092 filter->fw_l2_filter_id = UINT64_MAX;
4097 int bnxt_hwrm_set_ntuple_filter(struct bnxt *bp,
4099 struct bnxt_filter_info *filter)
4102 struct hwrm_cfa_ntuple_filter_alloc_input req = {.req_type = 0 };
4103 struct hwrm_cfa_ntuple_filter_alloc_output *resp =
4104 bp->hwrm_cmd_resp_addr;
4105 uint32_t enables = 0;
4107 if (filter->fw_ntuple_filter_id != UINT64_MAX)
4108 bnxt_hwrm_clear_ntuple_filter(bp, filter);
4110 HWRM_PREP(req, CFA_NTUPLE_FILTER_ALLOC, BNXT_USE_CHIMP_MB);
4112 req.flags = rte_cpu_to_le_32(filter->flags);
4114 enables = filter->enables |
4115 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_ID;
4116 req.dst_id = rte_cpu_to_le_16(dst_id);
4119 if (filter->ip_addr_type) {
4120 req.ip_addr_type = filter->ip_addr_type;
4122 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_IPADDR_TYPE;
4125 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_L2_FILTER_ID)
4126 req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
4128 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_MACADDR)
4129 memcpy(req.src_macaddr, filter->src_macaddr,
4130 RTE_ETHER_ADDR_LEN);
4132 //HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_MACADDR)
4133 //memcpy(req.dst_macaddr, filter->dst_macaddr,
4134 //RTE_ETHER_ADDR_LEN);
4136 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_ETHERTYPE)
4137 req.ethertype = rte_cpu_to_be_16(filter->ethertype);
4139 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_IP_PROTOCOL)
4140 req.ip_protocol = filter->ip_protocol;
4142 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_IPADDR)
4143 req.src_ipaddr[0] = rte_cpu_to_le_32(filter->src_ipaddr[0]);
4145 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_IPADDR_MASK)
4146 req.src_ipaddr_mask[0] =
4147 rte_cpu_to_le_32(filter->src_ipaddr_mask[0]);
4149 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_IPADDR)
4150 req.dst_ipaddr[0] = rte_cpu_to_le_32(filter->dst_ipaddr[0]);
4152 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_IPADDR_MASK)
4153 req.dst_ipaddr_mask[0] =
4154 rte_cpu_to_be_32(filter->dst_ipaddr_mask[0]);
4156 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_PORT)
4157 req.src_port = rte_cpu_to_le_16(filter->src_port);
4159 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_PORT_MASK)
4160 req.src_port_mask = rte_cpu_to_le_16(filter->src_port_mask);
4162 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_PORT)
4163 req.dst_port = rte_cpu_to_le_16(filter->dst_port);
4165 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_PORT_MASK)
4166 req.dst_port_mask = rte_cpu_to_le_16(filter->dst_port_mask);
4168 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_MIRROR_VNIC_ID)
4169 req.mirror_vnic_id = filter->mirror_vnic_id;
4171 req.enables = rte_cpu_to_le_32(enables);
4173 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4175 HWRM_CHECK_RESULT();
4177 filter->fw_ntuple_filter_id = rte_le_to_cpu_64(resp->ntuple_filter_id);
4183 int bnxt_hwrm_clear_ntuple_filter(struct bnxt *bp,
4184 struct bnxt_filter_info *filter)
4187 struct hwrm_cfa_ntuple_filter_free_input req = {.req_type = 0 };
4188 struct hwrm_cfa_ntuple_filter_free_output *resp =
4189 bp->hwrm_cmd_resp_addr;
4191 if (filter->fw_ntuple_filter_id == UINT64_MAX)
4194 HWRM_PREP(req, CFA_NTUPLE_FILTER_FREE, BNXT_USE_CHIMP_MB);
4196 req.ntuple_filter_id = rte_cpu_to_le_64(filter->fw_ntuple_filter_id);
4198 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4200 HWRM_CHECK_RESULT();
4203 filter->fw_ntuple_filter_id = UINT64_MAX;
4209 bnxt_vnic_rss_configure_thor(struct bnxt *bp, struct bnxt_vnic_info *vnic)
4211 struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
4212 uint8_t *rx_queue_state = bp->eth_dev->data->rx_queue_state;
4213 struct hwrm_vnic_rss_cfg_input req = {.req_type = 0 };
4214 struct bnxt_rx_queue **rxqs = bp->rx_queues;
4215 uint16_t *ring_tbl = vnic->rss_table;
4216 int nr_ctxs = vnic->num_lb_ctxts;
4217 int max_rings = bp->rx_nr_rings;
4221 for (i = 0, k = 0; i < nr_ctxs; i++) {
4222 struct bnxt_rx_ring_info *rxr;
4223 struct bnxt_cp_ring_info *cpr;
4225 HWRM_PREP(req, VNIC_RSS_CFG, BNXT_USE_CHIMP_MB);
4227 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
4228 req.hash_type = rte_cpu_to_le_32(vnic->hash_type);
4229 req.hash_mode_flags = vnic->hash_mode;
4231 req.ring_grp_tbl_addr =
4232 rte_cpu_to_le_64(vnic->rss_table_dma_addr +
4233 i * BNXT_RSS_ENTRIES_PER_CTX_THOR *
4234 2 * sizeof(*ring_tbl));
4235 req.hash_key_tbl_addr =
4236 rte_cpu_to_le_64(vnic->rss_hash_key_dma_addr);
4238 req.ring_table_pair_index = i;
4239 req.rss_ctx_idx = rte_cpu_to_le_16(vnic->fw_grp_ids[i]);
4241 for (j = 0; j < 64; j++) {
4244 /* Find next active ring. */
4245 for (cnt = 0; cnt < max_rings; cnt++) {
4246 if (rx_queue_state[k] !=
4247 RTE_ETH_QUEUE_STATE_STOPPED)
4249 if (++k == max_rings)
4253 /* Return if no rings are active. */
4254 if (cnt == max_rings)
4257 /* Add rx/cp ring pair to RSS table. */
4258 rxr = rxqs[k]->rx_ring;
4259 cpr = rxqs[k]->cp_ring;
4261 ring_id = rxr->rx_ring_struct->fw_ring_id;
4262 *ring_tbl++ = rte_cpu_to_le_16(ring_id);
4263 ring_id = cpr->cp_ring_struct->fw_ring_id;
4264 *ring_tbl++ = rte_cpu_to_le_16(ring_id);
4266 if (++k == max_rings)
4269 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req),
4272 HWRM_CHECK_RESULT();
4279 int bnxt_vnic_rss_configure(struct bnxt *bp, struct bnxt_vnic_info *vnic)
4281 unsigned int rss_idx, fw_idx, i;
4283 if (!(vnic->rss_table && vnic->hash_type))
4286 if (BNXT_CHIP_THOR(bp))
4287 return bnxt_vnic_rss_configure_thor(bp, vnic);
4290 * Fill the RSS hash & redirection table with
4291 * ring group ids for all VNICs
4293 for (rss_idx = 0, fw_idx = 0; rss_idx < HW_HASH_INDEX_SIZE;
4294 rss_idx++, fw_idx++) {
4295 for (i = 0; i < bp->rx_cp_nr_rings; i++) {
4296 fw_idx %= bp->rx_cp_nr_rings;
4297 if (vnic->fw_grp_ids[fw_idx] != INVALID_HW_RING_ID)
4301 if (i == bp->rx_cp_nr_rings)
4303 vnic->rss_table[rss_idx] = vnic->fw_grp_ids[fw_idx];
4305 return bnxt_hwrm_vnic_rss_cfg(bp, vnic);
4308 static void bnxt_hwrm_set_coal_params(struct bnxt_coal *hw_coal,
4309 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *req)
4313 req->num_cmpl_aggr_int = rte_cpu_to_le_16(hw_coal->num_cmpl_aggr_int);
4315 /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
4316 req->num_cmpl_dma_aggr = rte_cpu_to_le_16(hw_coal->num_cmpl_dma_aggr);
4318 /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
4319 req->num_cmpl_dma_aggr_during_int =
4320 rte_cpu_to_le_16(hw_coal->num_cmpl_dma_aggr_during_int);
4322 req->int_lat_tmr_max = rte_cpu_to_le_16(hw_coal->int_lat_tmr_max);
4324 /* min timer set to 1/2 of interrupt timer */
4325 req->int_lat_tmr_min = rte_cpu_to_le_16(hw_coal->int_lat_tmr_min);
4327 /* buf timer set to 1/4 of interrupt timer */
4328 req->cmpl_aggr_dma_tmr = rte_cpu_to_le_16(hw_coal->cmpl_aggr_dma_tmr);
4330 req->cmpl_aggr_dma_tmr_during_int =
4331 rte_cpu_to_le_16(hw_coal->cmpl_aggr_dma_tmr_during_int);
4333 flags = HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_TIMER_RESET |
4334 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_RING_IDLE;
4335 req->flags = rte_cpu_to_le_16(flags);
4338 static int bnxt_hwrm_set_coal_params_thor(struct bnxt *bp,
4339 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *agg_req)
4341 struct hwrm_ring_aggint_qcaps_input req = {0};
4342 struct hwrm_ring_aggint_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
4347 HWRM_PREP(req, RING_AGGINT_QCAPS, BNXT_USE_CHIMP_MB);
4348 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4349 HWRM_CHECK_RESULT();
4351 agg_req->num_cmpl_dma_aggr = resp->num_cmpl_dma_aggr_max;
4352 agg_req->cmpl_aggr_dma_tmr = resp->cmpl_aggr_dma_tmr_min;
4354 flags = HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_TIMER_RESET |
4355 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_RING_IDLE;
4356 agg_req->flags = rte_cpu_to_le_16(flags);
4358 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_ENABLES_CMPL_AGGR_DMA_TMR |
4359 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_ENABLES_NUM_CMPL_DMA_AGGR;
4360 agg_req->enables = rte_cpu_to_le_32(enables);
4366 int bnxt_hwrm_set_ring_coal(struct bnxt *bp,
4367 struct bnxt_coal *coal, uint16_t ring_id)
4369 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req = {0};
4370 struct hwrm_ring_cmpl_ring_cfg_aggint_params_output *resp =
4371 bp->hwrm_cmd_resp_addr;
4374 /* Set ring coalesce parameters only for 100G NICs */
4375 if (BNXT_CHIP_THOR(bp)) {
4376 if (bnxt_hwrm_set_coal_params_thor(bp, &req))
4378 } else if (bnxt_stratus_device(bp)) {
4379 bnxt_hwrm_set_coal_params(coal, &req);
4384 HWRM_PREP(req, RING_CMPL_RING_CFG_AGGINT_PARAMS, BNXT_USE_CHIMP_MB);
4385 req.ring_id = rte_cpu_to_le_16(ring_id);
4386 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4387 HWRM_CHECK_RESULT();
4392 #define BNXT_RTE_MEMZONE_FLAG (RTE_MEMZONE_1GB | RTE_MEMZONE_IOVA_CONTIG)
4393 int bnxt_hwrm_func_backing_store_qcaps(struct bnxt *bp)
4395 struct hwrm_func_backing_store_qcaps_input req = {0};
4396 struct hwrm_func_backing_store_qcaps_output *resp =
4397 bp->hwrm_cmd_resp_addr;
4398 struct bnxt_ctx_pg_info *ctx_pg;
4399 struct bnxt_ctx_mem_info *ctx;
4400 int total_alloc_len;
4403 if (!BNXT_CHIP_THOR(bp) ||
4404 bp->hwrm_spec_code < HWRM_VERSION_1_9_2 ||
4409 HWRM_PREP(req, FUNC_BACKING_STORE_QCAPS, BNXT_USE_CHIMP_MB);
4410 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4411 HWRM_CHECK_RESULT_SILENT();
4413 total_alloc_len = sizeof(*ctx);
4414 ctx = rte_zmalloc("bnxt_ctx_mem", total_alloc_len,
4415 RTE_CACHE_LINE_SIZE);
4421 ctx_pg = rte_malloc("bnxt_ctx_pg_mem",
4422 sizeof(*ctx_pg) * BNXT_MAX_Q,
4423 RTE_CACHE_LINE_SIZE);
4428 for (i = 0; i < BNXT_MAX_Q; i++, ctx_pg++)
4429 ctx->tqm_mem[i] = ctx_pg;
4432 ctx->qp_max_entries = rte_le_to_cpu_32(resp->qp_max_entries);
4433 ctx->qp_min_qp1_entries =
4434 rte_le_to_cpu_16(resp->qp_min_qp1_entries);
4435 ctx->qp_max_l2_entries =
4436 rte_le_to_cpu_16(resp->qp_max_l2_entries);
4437 ctx->qp_entry_size = rte_le_to_cpu_16(resp->qp_entry_size);
4438 ctx->srq_max_l2_entries =
4439 rte_le_to_cpu_16(resp->srq_max_l2_entries);
4440 ctx->srq_max_entries = rte_le_to_cpu_32(resp->srq_max_entries);
4441 ctx->srq_entry_size = rte_le_to_cpu_16(resp->srq_entry_size);
4442 ctx->cq_max_l2_entries =
4443 rte_le_to_cpu_16(resp->cq_max_l2_entries);
4444 ctx->cq_max_entries = rte_le_to_cpu_32(resp->cq_max_entries);
4445 ctx->cq_entry_size = rte_le_to_cpu_16(resp->cq_entry_size);
4446 ctx->vnic_max_vnic_entries =
4447 rte_le_to_cpu_16(resp->vnic_max_vnic_entries);
4448 ctx->vnic_max_ring_table_entries =
4449 rte_le_to_cpu_16(resp->vnic_max_ring_table_entries);
4450 ctx->vnic_entry_size = rte_le_to_cpu_16(resp->vnic_entry_size);
4451 ctx->stat_max_entries =
4452 rte_le_to_cpu_32(resp->stat_max_entries);
4453 ctx->stat_entry_size = rte_le_to_cpu_16(resp->stat_entry_size);
4454 ctx->tqm_entry_size = rte_le_to_cpu_16(resp->tqm_entry_size);
4455 ctx->tqm_min_entries_per_ring =
4456 rte_le_to_cpu_32(resp->tqm_min_entries_per_ring);
4457 ctx->tqm_max_entries_per_ring =
4458 rte_le_to_cpu_32(resp->tqm_max_entries_per_ring);
4459 ctx->tqm_entries_multiple = resp->tqm_entries_multiple;
4460 if (!ctx->tqm_entries_multiple)
4461 ctx->tqm_entries_multiple = 1;
4462 ctx->mrav_max_entries =
4463 rte_le_to_cpu_32(resp->mrav_max_entries);
4464 ctx->mrav_entry_size = rte_le_to_cpu_16(resp->mrav_entry_size);
4465 ctx->tim_entry_size = rte_le_to_cpu_16(resp->tim_entry_size);
4466 ctx->tim_max_entries = rte_le_to_cpu_32(resp->tim_max_entries);
4472 int bnxt_hwrm_func_backing_store_cfg(struct bnxt *bp, uint32_t enables)
4474 struct hwrm_func_backing_store_cfg_input req = {0};
4475 struct hwrm_func_backing_store_cfg_output *resp =
4476 bp->hwrm_cmd_resp_addr;
4477 struct bnxt_ctx_mem_info *ctx = bp->ctx;
4478 struct bnxt_ctx_pg_info *ctx_pg;
4479 uint32_t *num_entries;
4488 HWRM_PREP(req, FUNC_BACKING_STORE_CFG, BNXT_USE_CHIMP_MB);
4489 req.enables = rte_cpu_to_le_32(enables);
4491 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_QP) {
4492 ctx_pg = &ctx->qp_mem;
4493 req.qp_num_entries = rte_cpu_to_le_32(ctx_pg->entries);
4494 req.qp_num_qp1_entries =
4495 rte_cpu_to_le_16(ctx->qp_min_qp1_entries);
4496 req.qp_num_l2_entries =
4497 rte_cpu_to_le_16(ctx->qp_max_l2_entries);
4498 req.qp_entry_size = rte_cpu_to_le_16(ctx->qp_entry_size);
4499 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4500 &req.qpc_pg_size_qpc_lvl,
4504 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_SRQ) {
4505 ctx_pg = &ctx->srq_mem;
4506 req.srq_num_entries = rte_cpu_to_le_32(ctx_pg->entries);
4507 req.srq_num_l2_entries =
4508 rte_cpu_to_le_16(ctx->srq_max_l2_entries);
4509 req.srq_entry_size = rte_cpu_to_le_16(ctx->srq_entry_size);
4510 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4511 &req.srq_pg_size_srq_lvl,
4515 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_CQ) {
4516 ctx_pg = &ctx->cq_mem;
4517 req.cq_num_entries = rte_cpu_to_le_32(ctx_pg->entries);
4518 req.cq_num_l2_entries =
4519 rte_cpu_to_le_16(ctx->cq_max_l2_entries);
4520 req.cq_entry_size = rte_cpu_to_le_16(ctx->cq_entry_size);
4521 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4522 &req.cq_pg_size_cq_lvl,
4526 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_VNIC) {
4527 ctx_pg = &ctx->vnic_mem;
4528 req.vnic_num_vnic_entries =
4529 rte_cpu_to_le_16(ctx->vnic_max_vnic_entries);
4530 req.vnic_num_ring_table_entries =
4531 rte_cpu_to_le_16(ctx->vnic_max_ring_table_entries);
4532 req.vnic_entry_size = rte_cpu_to_le_16(ctx->vnic_entry_size);
4533 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4534 &req.vnic_pg_size_vnic_lvl,
4535 &req.vnic_page_dir);
4538 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_STAT) {
4539 ctx_pg = &ctx->stat_mem;
4540 req.stat_num_entries = rte_cpu_to_le_16(ctx->stat_max_entries);
4541 req.stat_entry_size = rte_cpu_to_le_16(ctx->stat_entry_size);
4542 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4543 &req.stat_pg_size_stat_lvl,
4544 &req.stat_page_dir);
4547 req.tqm_entry_size = rte_cpu_to_le_16(ctx->tqm_entry_size);
4548 num_entries = &req.tqm_sp_num_entries;
4549 pg_attr = &req.tqm_sp_pg_size_tqm_sp_lvl;
4550 pg_dir = &req.tqm_sp_page_dir;
4551 ena = HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_TQM_SP;
4552 for (i = 0; i < 9; i++, num_entries++, pg_attr++, pg_dir++, ena <<= 1) {
4553 if (!(enables & ena))
4556 req.tqm_entry_size = rte_cpu_to_le_16(ctx->tqm_entry_size);
4558 ctx_pg = ctx->tqm_mem[i];
4559 *num_entries = rte_cpu_to_le_16(ctx_pg->entries);
4560 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem, pg_attr, pg_dir);
4563 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4564 HWRM_CHECK_RESULT();
4570 int bnxt_hwrm_ext_port_qstats(struct bnxt *bp)
4572 struct hwrm_port_qstats_ext_input req = {0};
4573 struct hwrm_port_qstats_ext_output *resp = bp->hwrm_cmd_resp_addr;
4574 struct bnxt_pf_info *pf = &bp->pf;
4577 if (!(bp->flags & BNXT_FLAG_EXT_RX_PORT_STATS ||
4578 bp->flags & BNXT_FLAG_EXT_TX_PORT_STATS))
4581 HWRM_PREP(req, PORT_QSTATS_EXT, BNXT_USE_CHIMP_MB);
4583 req.port_id = rte_cpu_to_le_16(pf->port_id);
4584 if (bp->flags & BNXT_FLAG_EXT_TX_PORT_STATS) {
4585 req.tx_stat_host_addr =
4586 rte_cpu_to_le_64(bp->hw_tx_port_stats_ext_map);
4588 rte_cpu_to_le_16(sizeof(struct tx_port_stats_ext));
4590 if (bp->flags & BNXT_FLAG_EXT_RX_PORT_STATS) {
4591 req.rx_stat_host_addr =
4592 rte_cpu_to_le_64(bp->hw_rx_port_stats_ext_map);
4594 rte_cpu_to_le_16(sizeof(struct rx_port_stats_ext));
4596 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4599 bp->fw_rx_port_stats_ext_size = 0;
4600 bp->fw_tx_port_stats_ext_size = 0;
4602 bp->fw_rx_port_stats_ext_size =
4603 rte_le_to_cpu_16(resp->rx_stat_size);
4604 bp->fw_tx_port_stats_ext_size =
4605 rte_le_to_cpu_16(resp->tx_stat_size);
4608 HWRM_CHECK_RESULT();
4615 bnxt_hwrm_tunnel_redirect(struct bnxt *bp, uint8_t type)
4617 struct hwrm_cfa_redirect_tunnel_type_alloc_input req = {0};
4618 struct hwrm_cfa_redirect_tunnel_type_alloc_output *resp =
4619 bp->hwrm_cmd_resp_addr;
4622 HWRM_PREP(req, CFA_REDIRECT_TUNNEL_TYPE_ALLOC, BNXT_USE_CHIMP_MB);
4623 req.tunnel_type = type;
4624 req.dest_fid = bp->fw_fid;
4625 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4626 HWRM_CHECK_RESULT();
4634 bnxt_hwrm_tunnel_redirect_free(struct bnxt *bp, uint8_t type)
4636 struct hwrm_cfa_redirect_tunnel_type_free_input req = {0};
4637 struct hwrm_cfa_redirect_tunnel_type_free_output *resp =
4638 bp->hwrm_cmd_resp_addr;
4641 HWRM_PREP(req, CFA_REDIRECT_TUNNEL_TYPE_FREE, BNXT_USE_CHIMP_MB);
4642 req.tunnel_type = type;
4643 req.dest_fid = bp->fw_fid;
4644 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4645 HWRM_CHECK_RESULT();
4652 int bnxt_hwrm_tunnel_redirect_query(struct bnxt *bp, uint32_t *type)
4654 struct hwrm_cfa_redirect_query_tunnel_type_input req = {0};
4655 struct hwrm_cfa_redirect_query_tunnel_type_output *resp =
4656 bp->hwrm_cmd_resp_addr;
4659 HWRM_PREP(req, CFA_REDIRECT_QUERY_TUNNEL_TYPE, BNXT_USE_CHIMP_MB);
4660 req.src_fid = bp->fw_fid;
4661 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4662 HWRM_CHECK_RESULT();
4665 *type = rte_le_to_cpu_32(resp->tunnel_mask);
4672 int bnxt_hwrm_tunnel_redirect_info(struct bnxt *bp, uint8_t tun_type,
4675 struct hwrm_cfa_redirect_tunnel_type_info_input req = {0};
4676 struct hwrm_cfa_redirect_tunnel_type_info_output *resp =
4677 bp->hwrm_cmd_resp_addr;
4680 HWRM_PREP(req, CFA_REDIRECT_TUNNEL_TYPE_INFO, BNXT_USE_CHIMP_MB);
4681 req.src_fid = bp->fw_fid;
4682 req.tunnel_type = tun_type;
4683 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4684 HWRM_CHECK_RESULT();
4687 *dst_fid = rte_le_to_cpu_16(resp->dest_fid);
4689 PMD_DRV_LOG(DEBUG, "dst_fid: %x\n", resp->dest_fid);
4696 int bnxt_hwrm_set_mac(struct bnxt *bp)
4698 struct hwrm_func_vf_cfg_output *resp = bp->hwrm_cmd_resp_addr;
4699 struct hwrm_func_vf_cfg_input req = {0};
4705 HWRM_PREP(req, FUNC_VF_CFG, BNXT_USE_CHIMP_MB);
4708 rte_cpu_to_le_32(HWRM_FUNC_VF_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
4709 memcpy(req.dflt_mac_addr, bp->mac_addr, RTE_ETHER_ADDR_LEN);
4711 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4713 HWRM_CHECK_RESULT();
4715 memcpy(bp->dflt_mac_addr, bp->mac_addr, RTE_ETHER_ADDR_LEN);
4721 int bnxt_hwrm_if_change(struct bnxt *bp, bool up)
4723 struct hwrm_func_drv_if_change_output *resp = bp->hwrm_cmd_resp_addr;
4724 struct hwrm_func_drv_if_change_input req = {0};
4728 if (!(bp->flags & BNXT_FLAG_FW_CAP_IF_CHANGE))
4731 /* Do not issue FUNC_DRV_IF_CHANGE during reset recovery.
4732 * If we issue FUNC_DRV_IF_CHANGE with flags down before
4733 * FUNC_DRV_UNRGTR, FW resets before FUNC_DRV_UNRGTR
4735 if (!up && (bp->flags & BNXT_FLAG_FW_RESET))
4738 HWRM_PREP(req, FUNC_DRV_IF_CHANGE, BNXT_USE_CHIMP_MB);
4742 rte_cpu_to_le_32(HWRM_FUNC_DRV_IF_CHANGE_INPUT_FLAGS_UP);
4744 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4746 HWRM_CHECK_RESULT();
4747 flags = rte_le_to_cpu_32(resp->flags);
4750 if (flags & HWRM_FUNC_DRV_IF_CHANGE_OUTPUT_FLAGS_HOT_FW_RESET_DONE) {
4751 PMD_DRV_LOG(INFO, "FW reset happened while port was down\n");
4752 bp->flags |= BNXT_FLAG_IF_CHANGE_HOT_FW_RESET_DONE;
4758 int bnxt_hwrm_error_recovery_qcfg(struct bnxt *bp)
4760 struct hwrm_error_recovery_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
4761 struct bnxt_error_recovery_info *info = bp->recovery_info;
4762 struct hwrm_error_recovery_qcfg_input req = {0};
4767 /* Older FW does not have error recovery support */
4768 if (!(bp->flags & BNXT_FLAG_FW_CAP_ERROR_RECOVERY))
4772 info = rte_zmalloc("bnxt_hwrm_error_recovery_qcfg",
4774 bp->recovery_info = info;
4778 memset(info, 0, sizeof(*info));
4781 HWRM_PREP(req, ERROR_RECOVERY_QCFG, BNXT_USE_CHIMP_MB);
4783 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4785 HWRM_CHECK_RESULT();
4787 flags = rte_le_to_cpu_32(resp->flags);
4788 if (flags & HWRM_ERROR_RECOVERY_QCFG_OUTPUT_FLAGS_HOST)
4789 info->flags |= BNXT_FLAG_ERROR_RECOVERY_HOST;
4790 else if (flags & HWRM_ERROR_RECOVERY_QCFG_OUTPUT_FLAGS_CO_CPU)
4791 info->flags |= BNXT_FLAG_ERROR_RECOVERY_CO_CPU;
4793 if ((info->flags & BNXT_FLAG_ERROR_RECOVERY_CO_CPU) &&
4794 !(bp->flags & BNXT_FLAG_KONG_MB_EN)) {
4799 /* FW returned values are in units of 100msec */
4800 info->driver_polling_freq =
4801 rte_le_to_cpu_32(resp->driver_polling_freq) * 100;
4802 info->master_func_wait_period =
4803 rte_le_to_cpu_32(resp->master_func_wait_period) * 100;
4804 info->normal_func_wait_period =
4805 rte_le_to_cpu_32(resp->normal_func_wait_period) * 100;
4806 info->master_func_wait_period_after_reset =
4807 rte_le_to_cpu_32(resp->master_func_wait_period_after_reset) * 100;
4808 info->max_bailout_time_after_reset =
4809 rte_le_to_cpu_32(resp->max_bailout_time_after_reset) * 100;
4810 info->status_regs[BNXT_FW_STATUS_REG] =
4811 rte_le_to_cpu_32(resp->fw_health_status_reg);
4812 info->status_regs[BNXT_FW_HEARTBEAT_CNT_REG] =
4813 rte_le_to_cpu_32(resp->fw_heartbeat_reg);
4814 info->status_regs[BNXT_FW_RECOVERY_CNT_REG] =
4815 rte_le_to_cpu_32(resp->fw_reset_cnt_reg);
4816 info->status_regs[BNXT_FW_RESET_INPROG_REG] =
4817 rte_le_to_cpu_32(resp->reset_inprogress_reg);
4818 info->reg_array_cnt =
4819 rte_le_to_cpu_32(resp->reg_array_cnt);
4821 if (info->reg_array_cnt >= BNXT_NUM_RESET_REG) {
4826 for (i = 0; i < info->reg_array_cnt; i++) {
4827 info->reset_reg[i] =
4828 rte_le_to_cpu_32(resp->reset_reg[i]);
4829 info->reset_reg_val[i] =
4830 rte_le_to_cpu_32(resp->reset_reg_val[i]);
4831 info->delay_after_reset[i] =
4832 resp->delay_after_reset[i];
4837 /* Map the FW status registers */
4839 rc = bnxt_map_fw_health_status_regs(bp);
4842 rte_free(bp->recovery_info);
4843 bp->recovery_info = NULL;
4848 int bnxt_hwrm_fw_reset(struct bnxt *bp)
4850 struct hwrm_fw_reset_output *resp = bp->hwrm_cmd_resp_addr;
4851 struct hwrm_fw_reset_input req = {0};
4857 HWRM_PREP(req, FW_RESET, BNXT_USE_KONG(bp));
4859 req.embedded_proc_type =
4860 HWRM_FW_RESET_INPUT_EMBEDDED_PROC_TYPE_CHIP;
4861 req.selfrst_status =
4862 HWRM_FW_RESET_INPUT_SELFRST_STATUS_SELFRSTASAP;
4863 req.flags = HWRM_FW_RESET_INPUT_FLAGS_RESET_GRACEFUL;
4865 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req),
4868 HWRM_CHECK_RESULT();
4874 int bnxt_hwrm_port_ts_query(struct bnxt *bp, uint8_t path, uint64_t *timestamp)
4876 struct hwrm_port_ts_query_output *resp = bp->hwrm_cmd_resp_addr;
4877 struct hwrm_port_ts_query_input req = {0};
4878 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
4885 HWRM_PREP(req, PORT_TS_QUERY, BNXT_USE_CHIMP_MB);
4888 case BNXT_PTP_FLAGS_PATH_TX:
4889 flags |= HWRM_PORT_TS_QUERY_INPUT_FLAGS_PATH_TX;
4891 case BNXT_PTP_FLAGS_PATH_RX:
4892 flags |= HWRM_PORT_TS_QUERY_INPUT_FLAGS_PATH_RX;
4894 case BNXT_PTP_FLAGS_CURRENT_TIME:
4895 flags |= HWRM_PORT_TS_QUERY_INPUT_FLAGS_CURRENT_TIME;
4899 req.flags = rte_cpu_to_le_32(flags);
4900 req.port_id = rte_cpu_to_le_16(bp->pf.port_id);
4902 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4904 HWRM_CHECK_RESULT();
4907 *timestamp = rte_le_to_cpu_32(resp->ptp_msg_ts[0]);
4909 (uint64_t)(rte_le_to_cpu_32(resp->ptp_msg_ts[1])) << 32;