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 if (vnic->flags & BNXT_VNIC_INFO_BCAST)
299 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_BCAST;
300 if (vnic->flags & BNXT_VNIC_INFO_UNTAGGED)
301 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLAN_NONVLAN;
303 if (vnic->flags & BNXT_VNIC_INFO_PROMISC)
304 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_PROMISCUOUS;
306 if (vnic->flags & BNXT_VNIC_INFO_ALLMULTI) {
307 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
308 } else if (vnic->flags & BNXT_VNIC_INFO_MCAST) {
309 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_MCAST;
310 req.num_mc_entries = rte_cpu_to_le_32(vnic->mc_addr_cnt);
311 req.mc_tbl_addr = rte_cpu_to_le_64(vnic->mc_list_dma_addr);
314 if (!(mask & HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLAN_NONVLAN))
315 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLANONLY;
316 req.vlan_tag_tbl_addr = rte_cpu_to_le_64(
317 rte_mem_virt2iova(vlan_table));
318 req.num_vlan_tags = rte_cpu_to_le_32((uint32_t)vlan_count);
320 req.mask = rte_cpu_to_le_32(mask);
322 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
330 int bnxt_hwrm_cfa_vlan_antispoof_cfg(struct bnxt *bp, uint16_t fid,
332 struct bnxt_vlan_antispoof_table_entry *vlan_table)
335 struct hwrm_cfa_vlan_antispoof_cfg_input req = {.req_type = 0 };
336 struct hwrm_cfa_vlan_antispoof_cfg_output *resp =
337 bp->hwrm_cmd_resp_addr;
340 * Older HWRM versions did not support this command, and the set_rx_mask
341 * list was used for anti-spoof. In 1.8.0, the TX path configuration was
342 * removed from set_rx_mask call, and this command was added.
344 * This command is also present from 1.7.8.11 and higher,
347 if (bp->fw_ver < ((1 << 24) | (8 << 16))) {
348 if (bp->fw_ver != ((1 << 24) | (7 << 16) | (8 << 8))) {
349 if (bp->fw_ver < ((1 << 24) | (7 << 16) | (8 << 8) |
354 HWRM_PREP(req, CFA_VLAN_ANTISPOOF_CFG, BNXT_USE_CHIMP_MB);
355 req.fid = rte_cpu_to_le_16(fid);
357 req.vlan_tag_mask_tbl_addr =
358 rte_cpu_to_le_64(rte_mem_virt2iova(vlan_table));
359 req.num_vlan_entries = rte_cpu_to_le_32((uint32_t)vlan_count);
361 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
369 int bnxt_hwrm_clear_l2_filter(struct bnxt *bp,
370 struct bnxt_filter_info *filter)
373 struct bnxt_filter_info *l2_filter = filter;
374 struct hwrm_cfa_l2_filter_free_input req = {.req_type = 0 };
375 struct hwrm_cfa_l2_filter_free_output *resp = bp->hwrm_cmd_resp_addr;
377 if (filter->fw_l2_filter_id == UINT64_MAX)
380 if (filter->matching_l2_fltr_ptr)
381 l2_filter = filter->matching_l2_fltr_ptr;
383 PMD_DRV_LOG(DEBUG, "filter: %p l2_filter: %p ref_cnt: %d\n",
384 filter, l2_filter, l2_filter->l2_ref_cnt);
386 if (l2_filter->l2_ref_cnt > 0)
387 l2_filter->l2_ref_cnt--;
389 if (l2_filter->l2_ref_cnt > 0)
392 HWRM_PREP(req, CFA_L2_FILTER_FREE, BNXT_USE_CHIMP_MB);
394 req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
396 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
401 filter->fw_l2_filter_id = UINT64_MAX;
406 int bnxt_hwrm_set_l2_filter(struct bnxt *bp,
408 struct bnxt_filter_info *filter)
411 struct hwrm_cfa_l2_filter_alloc_input req = {.req_type = 0 };
412 struct hwrm_cfa_l2_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr;
413 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
414 const struct rte_eth_vmdq_rx_conf *conf =
415 &dev_conf->rx_adv_conf.vmdq_rx_conf;
416 uint32_t enables = 0;
417 uint16_t j = dst_id - 1;
419 //TODO: Is there a better way to add VLANs to each VNIC in case of VMDQ
420 if ((dev_conf->rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG) &&
421 conf->pool_map[j].pools & (1UL << j)) {
423 "Add vlan %u to vmdq pool %u\n",
424 conf->pool_map[j].vlan_id, j);
426 filter->l2_ivlan = conf->pool_map[j].vlan_id;
428 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN |
429 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN_MASK;
432 if (filter->fw_l2_filter_id != UINT64_MAX)
433 bnxt_hwrm_clear_l2_filter(bp, filter);
435 HWRM_PREP(req, CFA_L2_FILTER_ALLOC, BNXT_USE_CHIMP_MB);
437 req.flags = rte_cpu_to_le_32(filter->flags);
439 enables = filter->enables |
440 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_DST_ID;
441 req.dst_id = rte_cpu_to_le_16(dst_id);
444 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR)
445 memcpy(req.l2_addr, filter->l2_addr,
448 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR_MASK)
449 memcpy(req.l2_addr_mask, filter->l2_addr_mask,
452 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN)
453 req.l2_ovlan = filter->l2_ovlan;
455 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN)
456 req.l2_ivlan = filter->l2_ivlan;
458 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN_MASK)
459 req.l2_ovlan_mask = filter->l2_ovlan_mask;
461 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN_MASK)
462 req.l2_ivlan_mask = filter->l2_ivlan_mask;
463 if (enables & HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_SRC_ID)
464 req.src_id = rte_cpu_to_le_32(filter->src_id);
465 if (enables & HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_SRC_TYPE)
466 req.src_type = filter->src_type;
467 if (filter->pri_hint) {
468 req.pri_hint = filter->pri_hint;
469 req.l2_filter_id_hint =
470 rte_cpu_to_le_64(filter->l2_filter_id_hint);
473 req.enables = rte_cpu_to_le_32(enables);
475 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
479 filter->fw_l2_filter_id = rte_le_to_cpu_64(resp->l2_filter_id);
485 int bnxt_hwrm_ptp_cfg(struct bnxt *bp)
487 struct hwrm_port_mac_cfg_input req = {.req_type = 0};
488 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
495 HWRM_PREP(req, PORT_MAC_CFG, BNXT_USE_CHIMP_MB);
498 flags |= HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_RX_TS_CAPTURE_ENABLE;
501 HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_RX_TS_CAPTURE_DISABLE;
502 if (ptp->tx_tstamp_en)
503 flags |= HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_TX_TS_CAPTURE_ENABLE;
506 HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_TX_TS_CAPTURE_DISABLE;
507 req.flags = rte_cpu_to_le_32(flags);
508 req.enables = rte_cpu_to_le_32
509 (HWRM_PORT_MAC_CFG_INPUT_ENABLES_RX_TS_CAPTURE_PTP_MSG_TYPE);
510 req.rx_ts_capture_ptp_msg_type = rte_cpu_to_le_16(ptp->rxctl);
512 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
518 static int bnxt_hwrm_ptp_qcfg(struct bnxt *bp)
521 struct hwrm_port_mac_ptp_qcfg_input req = {.req_type = 0};
522 struct hwrm_port_mac_ptp_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
523 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
525 /* if (bp->hwrm_spec_code < 0x10801 || ptp) TBD */
529 HWRM_PREP(req, PORT_MAC_PTP_QCFG, BNXT_USE_CHIMP_MB);
531 req.port_id = rte_cpu_to_le_16(bp->pf.port_id);
533 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
537 if (!BNXT_CHIP_THOR(bp) &&
538 !(resp->flags & HWRM_PORT_MAC_PTP_QCFG_OUTPUT_FLAGS_DIRECT_ACCESS))
541 if (resp->flags & HWRM_PORT_MAC_PTP_QCFG_OUTPUT_FLAGS_ONE_STEP_TX_TS)
542 bp->flags |= BNXT_FLAG_FW_CAP_ONE_STEP_TX_TS;
544 ptp = rte_zmalloc("ptp_cfg", sizeof(*ptp), 0);
548 if (!BNXT_CHIP_THOR(bp)) {
549 ptp->rx_regs[BNXT_PTP_RX_TS_L] =
550 rte_le_to_cpu_32(resp->rx_ts_reg_off_lower);
551 ptp->rx_regs[BNXT_PTP_RX_TS_H] =
552 rte_le_to_cpu_32(resp->rx_ts_reg_off_upper);
553 ptp->rx_regs[BNXT_PTP_RX_SEQ] =
554 rte_le_to_cpu_32(resp->rx_ts_reg_off_seq_id);
555 ptp->rx_regs[BNXT_PTP_RX_FIFO] =
556 rte_le_to_cpu_32(resp->rx_ts_reg_off_fifo);
557 ptp->rx_regs[BNXT_PTP_RX_FIFO_ADV] =
558 rte_le_to_cpu_32(resp->rx_ts_reg_off_fifo_adv);
559 ptp->tx_regs[BNXT_PTP_TX_TS_L] =
560 rte_le_to_cpu_32(resp->tx_ts_reg_off_lower);
561 ptp->tx_regs[BNXT_PTP_TX_TS_H] =
562 rte_le_to_cpu_32(resp->tx_ts_reg_off_upper);
563 ptp->tx_regs[BNXT_PTP_TX_SEQ] =
564 rte_le_to_cpu_32(resp->tx_ts_reg_off_seq_id);
565 ptp->tx_regs[BNXT_PTP_TX_FIFO] =
566 rte_le_to_cpu_32(resp->tx_ts_reg_off_fifo);
575 static int __bnxt_hwrm_func_qcaps(struct bnxt *bp)
578 struct hwrm_func_qcaps_input req = {.req_type = 0 };
579 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
580 uint16_t new_max_vfs;
584 HWRM_PREP(req, FUNC_QCAPS, BNXT_USE_CHIMP_MB);
586 req.fid = rte_cpu_to_le_16(0xffff);
588 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
592 bp->max_ring_grps = rte_le_to_cpu_32(resp->max_hw_ring_grps);
593 flags = rte_le_to_cpu_32(resp->flags);
595 bp->pf.port_id = resp->port_id;
596 bp->pf.first_vf_id = rte_le_to_cpu_16(resp->first_vf_id);
597 bp->pf.total_vfs = rte_le_to_cpu_16(resp->max_vfs);
598 new_max_vfs = bp->pdev->max_vfs;
599 if (new_max_vfs != bp->pf.max_vfs) {
601 rte_free(bp->pf.vf_info);
602 bp->pf.vf_info = rte_malloc("bnxt_vf_info",
603 sizeof(bp->pf.vf_info[0]) * new_max_vfs, 0);
604 bp->pf.max_vfs = new_max_vfs;
605 for (i = 0; i < new_max_vfs; i++) {
606 bp->pf.vf_info[i].fid = bp->pf.first_vf_id + i;
607 bp->pf.vf_info[i].vlan_table =
608 rte_zmalloc("VF VLAN table",
611 if (bp->pf.vf_info[i].vlan_table == NULL)
613 "Fail to alloc VLAN table for VF %d\n",
617 bp->pf.vf_info[i].vlan_table);
618 bp->pf.vf_info[i].vlan_as_table =
619 rte_zmalloc("VF VLAN AS table",
622 if (bp->pf.vf_info[i].vlan_as_table == NULL)
624 "Alloc VLAN AS table for VF %d fail\n",
628 bp->pf.vf_info[i].vlan_as_table);
629 STAILQ_INIT(&bp->pf.vf_info[i].filter);
634 bp->fw_fid = rte_le_to_cpu_32(resp->fid);
635 memcpy(bp->dflt_mac_addr, &resp->mac_address, RTE_ETHER_ADDR_LEN);
636 bp->max_rsscos_ctx = rte_le_to_cpu_16(resp->max_rsscos_ctx);
637 bp->max_cp_rings = rte_le_to_cpu_16(resp->max_cmpl_rings);
638 bp->max_tx_rings = rte_le_to_cpu_16(resp->max_tx_rings);
639 bp->max_rx_rings = rte_le_to_cpu_16(resp->max_rx_rings);
640 bp->first_vf_id = rte_le_to_cpu_16(resp->first_vf_id);
641 bp->max_rx_em_flows = rte_le_to_cpu_16(resp->max_rx_em_flows);
642 bp->max_l2_ctx = rte_le_to_cpu_16(resp->max_l2_ctxs);
643 if (!BNXT_CHIP_THOR(bp))
644 bp->max_l2_ctx += bp->max_rx_em_flows;
645 /* TODO: For now, do not support VMDq/RFS on VFs. */
650 bp->max_vnics = rte_le_to_cpu_16(resp->max_vnics);
654 bp->max_stat_ctx = rte_le_to_cpu_16(resp->max_stat_ctx);
656 bp->pf.total_vnics = rte_le_to_cpu_16(resp->max_vnics);
657 if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_PTP_SUPPORTED) {
658 bp->flags |= BNXT_FLAG_PTP_SUPPORTED;
659 PMD_DRV_LOG(DEBUG, "PTP SUPPORTED\n");
661 bnxt_hwrm_ptp_qcfg(bp);
665 if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_EXT_STATS_SUPPORTED)
666 bp->flags |= BNXT_FLAG_EXT_STATS_SUPPORTED;
668 if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_ERROR_RECOVERY_CAPABLE) {
669 bp->flags |= BNXT_FLAG_FW_CAP_ERROR_RECOVERY;
670 PMD_DRV_LOG(DEBUG, "Adapter Error recovery SUPPORTED\n");
672 bp->flags &= ~BNXT_FLAG_FW_CAP_ERROR_RECOVERY;
675 if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_ERR_RECOVER_RELOAD)
676 bp->flags |= BNXT_FLAG_FW_CAP_ERR_RECOVER_RELOAD;
678 bp->flags &= ~BNXT_FLAG_FW_CAP_ERR_RECOVER_RELOAD;
685 int bnxt_hwrm_func_qcaps(struct bnxt *bp)
689 rc = __bnxt_hwrm_func_qcaps(bp);
690 if (!rc && bp->hwrm_spec_code >= HWRM_SPEC_CODE_1_8_3) {
691 rc = bnxt_alloc_ctx_mem(bp);
695 rc = bnxt_hwrm_func_resc_qcaps(bp);
697 bp->flags |= BNXT_FLAG_NEW_RM;
703 int bnxt_hwrm_vnic_qcaps(struct bnxt *bp)
706 struct hwrm_vnic_qcaps_input req = {.req_type = 0 };
707 struct hwrm_vnic_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
709 HWRM_PREP(req, VNIC_QCAPS, BNXT_USE_CHIMP_MB);
711 req.target_id = rte_cpu_to_le_16(0xffff);
713 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
717 bp->max_tpa_v2 = rte_le_to_cpu_16(resp->max_aggs_supported);
724 int bnxt_hwrm_func_reset(struct bnxt *bp)
727 struct hwrm_func_reset_input req = {.req_type = 0 };
728 struct hwrm_func_reset_output *resp = bp->hwrm_cmd_resp_addr;
730 HWRM_PREP(req, FUNC_RESET, BNXT_USE_CHIMP_MB);
732 req.enables = rte_cpu_to_le_32(0);
734 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
742 int bnxt_hwrm_func_driver_register(struct bnxt *bp)
746 struct hwrm_func_drv_rgtr_input req = {.req_type = 0 };
747 struct hwrm_func_drv_rgtr_output *resp = bp->hwrm_cmd_resp_addr;
749 if (bp->flags & BNXT_FLAG_REGISTERED)
752 flags = HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_HOT_RESET_SUPPORT;
753 if (bp->flags & BNXT_FLAG_FW_CAP_ERROR_RECOVERY)
754 flags |= HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_ERROR_RECOVERY_SUPPORT;
756 /* PFs and trusted VFs should indicate the support of the
757 * Master capability on non Stingray platform
759 if ((BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp)) && !BNXT_STINGRAY(bp))
760 flags |= HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_MASTER_SUPPORT;
762 HWRM_PREP(req, FUNC_DRV_RGTR, BNXT_USE_CHIMP_MB);
763 req.enables = rte_cpu_to_le_32(HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_VER |
764 HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_ASYNC_EVENT_FWD);
765 req.ver_maj = RTE_VER_YEAR;
766 req.ver_min = RTE_VER_MONTH;
767 req.ver_upd = RTE_VER_MINOR;
770 req.enables |= rte_cpu_to_le_32(
771 HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_VF_REQ_FWD);
772 memcpy(req.vf_req_fwd, bp->pf.vf_req_fwd,
773 RTE_MIN(sizeof(req.vf_req_fwd),
774 sizeof(bp->pf.vf_req_fwd)));
777 * PF can sniff HWRM API issued by VF. This can be set up by
778 * linux driver and inherited by the DPDK PF driver. Clear
779 * this HWRM sniffer list in FW because DPDK PF driver does
782 flags |= HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_FWD_NONE_MODE;
785 req.flags = rte_cpu_to_le_32(flags);
787 req.async_event_fwd[0] |=
788 rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_LINK_STATUS_CHANGE |
789 ASYNC_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED |
790 ASYNC_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE |
791 ASYNC_CMPL_EVENT_ID_LINK_SPEED_CHANGE |
792 ASYNC_CMPL_EVENT_ID_RESET_NOTIFY);
793 if (bp->flags & BNXT_FLAG_FW_CAP_ERROR_RECOVERY)
794 req.async_event_fwd[0] |=
795 rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_ERROR_RECOVERY);
796 req.async_event_fwd[1] |=
797 rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_PF_DRVR_UNLOAD |
798 ASYNC_CMPL_EVENT_ID_VF_CFG_CHANGE);
800 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
804 flags = rte_le_to_cpu_32(resp->flags);
805 if (flags & HWRM_FUNC_DRV_RGTR_OUTPUT_FLAGS_IF_CHANGE_SUPPORTED)
806 bp->flags |= BNXT_FLAG_FW_CAP_IF_CHANGE;
810 bp->flags |= BNXT_FLAG_REGISTERED;
815 int bnxt_hwrm_check_vf_rings(struct bnxt *bp)
817 if (!(BNXT_VF(bp) && (bp->flags & BNXT_FLAG_NEW_RM)))
820 return bnxt_hwrm_func_reserve_vf_resc(bp, true);
823 int bnxt_hwrm_func_reserve_vf_resc(struct bnxt *bp, bool test)
828 struct hwrm_func_vf_cfg_output *resp = bp->hwrm_cmd_resp_addr;
829 struct hwrm_func_vf_cfg_input req = {0};
831 HWRM_PREP(req, FUNC_VF_CFG, BNXT_USE_CHIMP_MB);
833 enables = HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_RX_RINGS |
834 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_TX_RINGS |
835 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
836 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
837 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_VNICS;
839 if (BNXT_HAS_RING_GRPS(bp)) {
840 enables |= HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS;
841 req.num_hw_ring_grps = rte_cpu_to_le_16(bp->rx_nr_rings);
844 req.num_tx_rings = rte_cpu_to_le_16(bp->tx_nr_rings);
845 req.num_rx_rings = rte_cpu_to_le_16(bp->rx_nr_rings *
846 AGG_RING_MULTIPLIER);
847 req.num_stat_ctxs = rte_cpu_to_le_16(bp->rx_nr_rings +
849 BNXT_NUM_ASYNC_CPR(bp));
850 req.num_cmpl_rings = rte_cpu_to_le_16(bp->rx_nr_rings +
852 BNXT_NUM_ASYNC_CPR(bp));
853 req.num_vnics = rte_cpu_to_le_16(bp->rx_nr_rings);
854 if (bp->vf_resv_strategy ==
855 HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESV_STRATEGY_MINIMAL_STATIC) {
856 enables |= HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_VNICS |
857 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_L2_CTXS |
858 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS;
859 req.num_rsscos_ctxs = rte_cpu_to_le_16(BNXT_VF_RSV_NUM_RSS_CTX);
860 req.num_l2_ctxs = rte_cpu_to_le_16(BNXT_VF_RSV_NUM_L2_CTX);
861 req.num_vnics = rte_cpu_to_le_16(BNXT_VF_RSV_NUM_VNIC);
865 flags = HWRM_FUNC_VF_CFG_INPUT_FLAGS_TX_ASSETS_TEST |
866 HWRM_FUNC_VF_CFG_INPUT_FLAGS_RX_ASSETS_TEST |
867 HWRM_FUNC_VF_CFG_INPUT_FLAGS_CMPL_ASSETS_TEST |
868 HWRM_FUNC_VF_CFG_INPUT_FLAGS_RING_GRP_ASSETS_TEST |
869 HWRM_FUNC_VF_CFG_INPUT_FLAGS_STAT_CTX_ASSETS_TEST |
870 HWRM_FUNC_VF_CFG_INPUT_FLAGS_VNIC_ASSETS_TEST;
872 if (test && BNXT_HAS_RING_GRPS(bp))
873 flags |= HWRM_FUNC_VF_CFG_INPUT_FLAGS_RING_GRP_ASSETS_TEST;
875 req.flags = rte_cpu_to_le_32(flags);
876 req.enables |= rte_cpu_to_le_32(enables);
878 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
881 HWRM_CHECK_RESULT_SILENT();
889 int bnxt_hwrm_func_resc_qcaps(struct bnxt *bp)
892 struct hwrm_func_resource_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
893 struct hwrm_func_resource_qcaps_input req = {0};
895 HWRM_PREP(req, FUNC_RESOURCE_QCAPS, BNXT_USE_CHIMP_MB);
896 req.fid = rte_cpu_to_le_16(0xffff);
898 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
903 bp->max_rsscos_ctx = rte_le_to_cpu_16(resp->max_rsscos_ctx);
904 bp->max_cp_rings = rte_le_to_cpu_16(resp->max_cmpl_rings);
905 bp->max_tx_rings = rte_le_to_cpu_16(resp->max_tx_rings);
906 bp->max_rx_rings = rte_le_to_cpu_16(resp->max_rx_rings);
907 bp->max_ring_grps = rte_le_to_cpu_32(resp->max_hw_ring_grps);
908 /* func_resource_qcaps does not return max_rx_em_flows.
909 * So use the value provided by func_qcaps.
911 bp->max_l2_ctx = rte_le_to_cpu_16(resp->max_l2_ctxs);
912 if (!BNXT_CHIP_THOR(bp))
913 bp->max_l2_ctx += bp->max_rx_em_flows;
914 bp->max_vnics = rte_le_to_cpu_16(resp->max_vnics);
915 bp->max_stat_ctx = rte_le_to_cpu_16(resp->max_stat_ctx);
917 bp->max_nq_rings = rte_le_to_cpu_16(resp->max_msix);
918 bp->vf_resv_strategy = rte_le_to_cpu_16(resp->vf_reservation_strategy);
919 if (bp->vf_resv_strategy >
920 HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESV_STRATEGY_MINIMAL_STATIC)
921 bp->vf_resv_strategy =
922 HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESERVATION_STRATEGY_MAXIMAL;
928 int bnxt_hwrm_ver_get(struct bnxt *bp)
931 struct hwrm_ver_get_input req = {.req_type = 0 };
932 struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr;
934 uint16_t max_resp_len;
935 char type[RTE_MEMZONE_NAMESIZE];
936 uint32_t dev_caps_cfg;
938 bp->max_req_len = HWRM_MAX_REQ_LEN;
939 HWRM_PREP(req, VER_GET, BNXT_USE_CHIMP_MB);
941 req.hwrm_intf_maj = HWRM_VERSION_MAJOR;
942 req.hwrm_intf_min = HWRM_VERSION_MINOR;
943 req.hwrm_intf_upd = HWRM_VERSION_UPDATE;
945 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
947 if (bp->flags & BNXT_FLAG_FW_RESET)
948 HWRM_CHECK_RESULT_SILENT();
952 PMD_DRV_LOG(INFO, "%d.%d.%d:%d.%d.%d\n",
953 resp->hwrm_intf_maj_8b, resp->hwrm_intf_min_8b,
954 resp->hwrm_intf_upd_8b, resp->hwrm_fw_maj_8b,
955 resp->hwrm_fw_min_8b, resp->hwrm_fw_bld_8b);
956 bp->fw_ver = (resp->hwrm_fw_maj_8b << 24) |
957 (resp->hwrm_fw_min_8b << 16) |
958 (resp->hwrm_fw_bld_8b << 8) |
959 resp->hwrm_fw_rsvd_8b;
960 PMD_DRV_LOG(INFO, "Driver HWRM version: %d.%d.%d\n",
961 HWRM_VERSION_MAJOR, HWRM_VERSION_MINOR, HWRM_VERSION_UPDATE);
963 fw_version = resp->hwrm_intf_maj_8b << 16;
964 fw_version |= resp->hwrm_intf_min_8b << 8;
965 fw_version |= resp->hwrm_intf_upd_8b;
966 bp->hwrm_spec_code = fw_version;
968 if (resp->hwrm_intf_maj_8b != HWRM_VERSION_MAJOR) {
969 PMD_DRV_LOG(ERR, "Unsupported firmware API version\n");
974 if (bp->max_req_len > resp->max_req_win_len) {
975 PMD_DRV_LOG(ERR, "Unsupported request length\n");
978 bp->max_req_len = rte_le_to_cpu_16(resp->max_req_win_len);
979 bp->hwrm_max_ext_req_len = rte_le_to_cpu_16(resp->max_ext_req_len);
980 if (bp->hwrm_max_ext_req_len < HWRM_MAX_REQ_LEN)
981 bp->hwrm_max_ext_req_len = HWRM_MAX_REQ_LEN;
983 max_resp_len = rte_le_to_cpu_16(resp->max_resp_len);
984 dev_caps_cfg = rte_le_to_cpu_32(resp->dev_caps_cfg);
986 if (bp->max_resp_len != max_resp_len) {
987 sprintf(type, "bnxt_hwrm_%04x:%02x:%02x:%02x",
988 bp->pdev->addr.domain, bp->pdev->addr.bus,
989 bp->pdev->addr.devid, bp->pdev->addr.function);
991 rte_free(bp->hwrm_cmd_resp_addr);
993 bp->hwrm_cmd_resp_addr = rte_malloc(type, max_resp_len, 0);
994 if (bp->hwrm_cmd_resp_addr == NULL) {
998 rte_mem_lock_page(bp->hwrm_cmd_resp_addr);
999 bp->hwrm_cmd_resp_dma_addr =
1000 rte_mem_virt2iova(bp->hwrm_cmd_resp_addr);
1001 if (bp->hwrm_cmd_resp_dma_addr == RTE_BAD_IOVA) {
1003 "Unable to map response buffer to physical memory.\n");
1007 bp->max_resp_len = max_resp_len;
1011 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
1013 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_REQUIRED)) {
1014 PMD_DRV_LOG(DEBUG, "Short command supported\n");
1015 bp->flags |= BNXT_FLAG_SHORT_CMD;
1018 if (((dev_caps_cfg &
1019 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
1021 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_REQUIRED)) ||
1022 bp->hwrm_max_ext_req_len > HWRM_MAX_REQ_LEN) {
1023 sprintf(type, "bnxt_hwrm_short_%04x:%02x:%02x:%02x",
1024 bp->pdev->addr.domain, bp->pdev->addr.bus,
1025 bp->pdev->addr.devid, bp->pdev->addr.function);
1027 rte_free(bp->hwrm_short_cmd_req_addr);
1029 bp->hwrm_short_cmd_req_addr =
1030 rte_malloc(type, bp->hwrm_max_ext_req_len, 0);
1031 if (bp->hwrm_short_cmd_req_addr == NULL) {
1035 rte_mem_lock_page(bp->hwrm_short_cmd_req_addr);
1036 bp->hwrm_short_cmd_req_dma_addr =
1037 rte_mem_virt2iova(bp->hwrm_short_cmd_req_addr);
1038 if (bp->hwrm_short_cmd_req_dma_addr == RTE_BAD_IOVA) {
1039 rte_free(bp->hwrm_short_cmd_req_addr);
1041 "Unable to map buffer to physical memory.\n");
1047 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_KONG_MB_CHNL_SUPPORTED) {
1048 bp->flags |= BNXT_FLAG_KONG_MB_EN;
1049 PMD_DRV_LOG(DEBUG, "Kong mailbox channel enabled\n");
1052 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_TRUSTED_VF_SUPPORTED)
1053 PMD_DRV_LOG(DEBUG, "FW supports Trusted VFs\n");
1055 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_CFA_ADV_FLOW_MGNT_SUPPORTED) {
1056 bp->flags |= BNXT_FLAG_ADV_FLOW_MGMT;
1057 PMD_DRV_LOG(DEBUG, "FW supports advanced flow management\n");
1065 int bnxt_hwrm_func_driver_unregister(struct bnxt *bp, uint32_t flags)
1068 struct hwrm_func_drv_unrgtr_input req = {.req_type = 0 };
1069 struct hwrm_func_drv_unrgtr_output *resp = bp->hwrm_cmd_resp_addr;
1071 if (!(bp->flags & BNXT_FLAG_REGISTERED))
1074 HWRM_PREP(req, FUNC_DRV_UNRGTR, BNXT_USE_CHIMP_MB);
1077 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1079 HWRM_CHECK_RESULT();
1085 static int bnxt_hwrm_port_phy_cfg(struct bnxt *bp, struct bnxt_link_info *conf)
1088 struct hwrm_port_phy_cfg_input req = {0};
1089 struct hwrm_port_phy_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1090 uint32_t enables = 0;
1092 HWRM_PREP(req, PORT_PHY_CFG, BNXT_USE_CHIMP_MB);
1094 if (conf->link_up) {
1095 /* Setting Fixed Speed. But AutoNeg is ON, So disable it */
1096 if (bp->link_info.auto_mode && conf->link_speed) {
1097 req.auto_mode = HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_NONE;
1098 PMD_DRV_LOG(DEBUG, "Disabling AutoNeg\n");
1101 req.flags = rte_cpu_to_le_32(conf->phy_flags);
1102 req.force_link_speed = rte_cpu_to_le_16(conf->link_speed);
1103 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_MODE;
1105 * Note, ChiMP FW 20.2.1 and 20.2.2 return an error when we set
1106 * any auto mode, even "none".
1108 if (!conf->link_speed) {
1109 /* No speeds specified. Enable AutoNeg - all speeds */
1111 HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_ALL_SPEEDS;
1113 /* AutoNeg - Advertise speeds specified. */
1114 if (conf->auto_link_speed_mask &&
1115 !(conf->phy_flags & HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE)) {
1117 HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_SPEED_MASK;
1118 req.auto_link_speed_mask =
1119 conf->auto_link_speed_mask;
1121 HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_LINK_SPEED_MASK;
1124 req.auto_duplex = conf->duplex;
1125 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_DUPLEX;
1126 req.auto_pause = conf->auto_pause;
1127 req.force_pause = conf->force_pause;
1128 /* Set force_pause if there is no auto or if there is a force */
1129 if (req.auto_pause && !req.force_pause)
1130 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_PAUSE;
1132 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_FORCE_PAUSE;
1134 req.enables = rte_cpu_to_le_32(enables);
1137 rte_cpu_to_le_32(HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE_LINK_DWN);
1138 PMD_DRV_LOG(INFO, "Force Link Down\n");
1141 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1143 HWRM_CHECK_RESULT();
1149 static int bnxt_hwrm_port_phy_qcfg(struct bnxt *bp,
1150 struct bnxt_link_info *link_info)
1153 struct hwrm_port_phy_qcfg_input req = {0};
1154 struct hwrm_port_phy_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
1156 HWRM_PREP(req, PORT_PHY_QCFG, BNXT_USE_CHIMP_MB);
1158 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1160 HWRM_CHECK_RESULT();
1162 link_info->phy_link_status = resp->link;
1163 link_info->link_up =
1164 (link_info->phy_link_status ==
1165 HWRM_PORT_PHY_QCFG_OUTPUT_LINK_LINK) ? 1 : 0;
1166 link_info->link_speed = rte_le_to_cpu_16(resp->link_speed);
1167 link_info->duplex = resp->duplex_cfg;
1168 link_info->pause = resp->pause;
1169 link_info->auto_pause = resp->auto_pause;
1170 link_info->force_pause = resp->force_pause;
1171 link_info->auto_mode = resp->auto_mode;
1172 link_info->phy_type = resp->phy_type;
1173 link_info->media_type = resp->media_type;
1175 link_info->support_speeds = rte_le_to_cpu_16(resp->support_speeds);
1176 link_info->auto_link_speed = rte_le_to_cpu_16(resp->auto_link_speed);
1177 link_info->preemphasis = rte_le_to_cpu_32(resp->preemphasis);
1178 link_info->force_link_speed = rte_le_to_cpu_16(resp->force_link_speed);
1179 link_info->phy_ver[0] = resp->phy_maj;
1180 link_info->phy_ver[1] = resp->phy_min;
1181 link_info->phy_ver[2] = resp->phy_bld;
1185 PMD_DRV_LOG(DEBUG, "Link Speed %d\n", link_info->link_speed);
1186 PMD_DRV_LOG(DEBUG, "Auto Mode %d\n", link_info->auto_mode);
1187 PMD_DRV_LOG(DEBUG, "Support Speeds %x\n", link_info->support_speeds);
1188 PMD_DRV_LOG(DEBUG, "Auto Link Speed %x\n", link_info->auto_link_speed);
1189 PMD_DRV_LOG(DEBUG, "Auto Link Speed Mask %x\n",
1190 link_info->auto_link_speed_mask);
1191 PMD_DRV_LOG(DEBUG, "Forced Link Speed %x\n",
1192 link_info->force_link_speed);
1197 int bnxt_hwrm_queue_qportcfg(struct bnxt *bp)
1200 struct hwrm_queue_qportcfg_input req = {.req_type = 0 };
1201 struct hwrm_queue_qportcfg_output *resp = bp->hwrm_cmd_resp_addr;
1204 HWRM_PREP(req, QUEUE_QPORTCFG, BNXT_USE_CHIMP_MB);
1206 req.flags = HWRM_QUEUE_QPORTCFG_INPUT_FLAGS_PATH_TX;
1207 /* HWRM Version >= 1.9.1 */
1208 if (bp->hwrm_spec_code >= HWRM_VERSION_1_9_1)
1210 HWRM_QUEUE_QPORTCFG_INPUT_DRV_QMAP_CAP_ENABLED;
1211 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1213 HWRM_CHECK_RESULT();
1215 #define GET_QUEUE_INFO(x) \
1216 bp->cos_queue[x].id = resp->queue_id##x; \
1217 bp->cos_queue[x].profile = resp->queue_id##x##_service_profile
1230 if (bp->hwrm_spec_code < HWRM_VERSION_1_9_1) {
1231 bp->tx_cosq_id = bp->cos_queue[0].id;
1233 /* iterate and find the COSq profile to use for Tx */
1234 for (i = 0; i < BNXT_COS_QUEUE_COUNT; i++) {
1235 if (bp->cos_queue[i].profile ==
1236 HWRM_QUEUE_SERVICE_PROFILE_LOSSY) {
1237 bp->tx_cosq_id = bp->cos_queue[i].id;
1243 bp->max_tc = resp->max_configurable_queues;
1244 bp->max_lltc = resp->max_configurable_lossless_queues;
1245 if (bp->max_tc > BNXT_MAX_QUEUE)
1246 bp->max_tc = BNXT_MAX_QUEUE;
1247 bp->max_q = bp->max_tc;
1249 PMD_DRV_LOG(DEBUG, "Tx Cos Queue to use: %d\n", bp->tx_cosq_id);
1254 int bnxt_hwrm_ring_alloc(struct bnxt *bp,
1255 struct bnxt_ring *ring,
1256 uint32_t ring_type, uint32_t map_index,
1257 uint32_t stats_ctx_id, uint32_t cmpl_ring_id)
1260 uint32_t enables = 0;
1261 struct hwrm_ring_alloc_input req = {.req_type = 0 };
1262 struct hwrm_ring_alloc_output *resp = bp->hwrm_cmd_resp_addr;
1263 struct rte_mempool *mb_pool;
1264 uint16_t rx_buf_size;
1266 HWRM_PREP(req, RING_ALLOC, BNXT_USE_CHIMP_MB);
1268 req.page_tbl_addr = rte_cpu_to_le_64(ring->bd_dma);
1269 req.fbo = rte_cpu_to_le_32(0);
1270 /* Association of ring index with doorbell index */
1271 req.logical_id = rte_cpu_to_le_16(map_index);
1272 req.length = rte_cpu_to_le_32(ring->ring_size);
1274 switch (ring_type) {
1275 case HWRM_RING_ALLOC_INPUT_RING_TYPE_TX:
1276 req.ring_type = ring_type;
1277 req.cmpl_ring_id = rte_cpu_to_le_16(cmpl_ring_id);
1278 req.stat_ctx_id = rte_cpu_to_le_32(stats_ctx_id);
1279 req.queue_id = rte_cpu_to_le_16(bp->tx_cosq_id);
1280 if (stats_ctx_id != INVALID_STATS_CTX_ID)
1282 HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID;
1284 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX:
1285 req.ring_type = ring_type;
1286 req.cmpl_ring_id = rte_cpu_to_le_16(cmpl_ring_id);
1287 req.stat_ctx_id = rte_cpu_to_le_32(stats_ctx_id);
1288 if (BNXT_CHIP_THOR(bp)) {
1289 mb_pool = bp->rx_queues[0]->mb_pool;
1290 rx_buf_size = rte_pktmbuf_data_room_size(mb_pool) -
1291 RTE_PKTMBUF_HEADROOM;
1292 rx_buf_size = RTE_MIN(BNXT_MAX_PKT_LEN, rx_buf_size);
1293 req.rx_buf_size = rte_cpu_to_le_16(rx_buf_size);
1295 HWRM_RING_ALLOC_INPUT_ENABLES_RX_BUF_SIZE_VALID;
1297 if (stats_ctx_id != INVALID_STATS_CTX_ID)
1299 HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID;
1301 case HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL:
1302 req.ring_type = ring_type;
1303 if (BNXT_HAS_NQ(bp)) {
1304 /* Association of cp ring with nq */
1305 req.nq_ring_id = rte_cpu_to_le_16(cmpl_ring_id);
1307 HWRM_RING_ALLOC_INPUT_ENABLES_NQ_RING_ID_VALID;
1309 req.int_mode = HWRM_RING_ALLOC_INPUT_INT_MODE_MSIX;
1311 case HWRM_RING_ALLOC_INPUT_RING_TYPE_NQ:
1312 req.ring_type = ring_type;
1313 req.page_size = BNXT_PAGE_SHFT;
1314 req.int_mode = HWRM_RING_ALLOC_INPUT_INT_MODE_MSIX;
1316 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX_AGG:
1317 req.ring_type = ring_type;
1318 req.rx_ring_id = rte_cpu_to_le_16(ring->fw_rx_ring_id);
1320 mb_pool = bp->rx_queues[0]->mb_pool;
1321 rx_buf_size = rte_pktmbuf_data_room_size(mb_pool) -
1322 RTE_PKTMBUF_HEADROOM;
1323 rx_buf_size = RTE_MIN(BNXT_MAX_PKT_LEN, rx_buf_size);
1324 req.rx_buf_size = rte_cpu_to_le_16(rx_buf_size);
1326 req.stat_ctx_id = rte_cpu_to_le_32(stats_ctx_id);
1327 enables |= HWRM_RING_ALLOC_INPUT_ENABLES_RX_RING_ID_VALID |
1328 HWRM_RING_ALLOC_INPUT_ENABLES_RX_BUF_SIZE_VALID |
1329 HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID;
1332 PMD_DRV_LOG(ERR, "hwrm alloc invalid ring type %d\n",
1337 req.enables = rte_cpu_to_le_32(enables);
1339 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1341 if (rc || resp->error_code) {
1342 if (rc == 0 && resp->error_code)
1343 rc = rte_le_to_cpu_16(resp->error_code);
1344 switch (ring_type) {
1345 case HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL:
1347 "hwrm_ring_alloc cp failed. rc:%d\n", rc);
1350 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX:
1352 "hwrm_ring_alloc rx failed. rc:%d\n", rc);
1355 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX_AGG:
1357 "hwrm_ring_alloc rx agg failed. rc:%d\n",
1361 case HWRM_RING_ALLOC_INPUT_RING_TYPE_TX:
1363 "hwrm_ring_alloc tx failed. rc:%d\n", rc);
1366 case HWRM_RING_ALLOC_INPUT_RING_TYPE_NQ:
1368 "hwrm_ring_alloc nq failed. rc:%d\n", rc);
1372 PMD_DRV_LOG(ERR, "Invalid ring. rc:%d\n", rc);
1378 ring->fw_ring_id = rte_le_to_cpu_16(resp->ring_id);
1383 int bnxt_hwrm_ring_free(struct bnxt *bp,
1384 struct bnxt_ring *ring, uint32_t ring_type)
1387 struct hwrm_ring_free_input req = {.req_type = 0 };
1388 struct hwrm_ring_free_output *resp = bp->hwrm_cmd_resp_addr;
1390 HWRM_PREP(req, RING_FREE, BNXT_USE_CHIMP_MB);
1392 req.ring_type = ring_type;
1393 req.ring_id = rte_cpu_to_le_16(ring->fw_ring_id);
1395 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1397 if (rc || resp->error_code) {
1398 if (rc == 0 && resp->error_code)
1399 rc = rte_le_to_cpu_16(resp->error_code);
1402 switch (ring_type) {
1403 case HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL:
1404 PMD_DRV_LOG(ERR, "hwrm_ring_free cp failed. rc:%d\n",
1407 case HWRM_RING_FREE_INPUT_RING_TYPE_RX:
1408 PMD_DRV_LOG(ERR, "hwrm_ring_free rx failed. rc:%d\n",
1411 case HWRM_RING_FREE_INPUT_RING_TYPE_TX:
1412 PMD_DRV_LOG(ERR, "hwrm_ring_free tx failed. rc:%d\n",
1415 case HWRM_RING_FREE_INPUT_RING_TYPE_NQ:
1417 "hwrm_ring_free nq failed. rc:%d\n", rc);
1419 case HWRM_RING_FREE_INPUT_RING_TYPE_RX_AGG:
1421 "hwrm_ring_free agg failed. rc:%d\n", rc);
1424 PMD_DRV_LOG(ERR, "Invalid ring, rc:%d\n", rc);
1432 int bnxt_hwrm_ring_grp_alloc(struct bnxt *bp, unsigned int idx)
1435 struct hwrm_ring_grp_alloc_input req = {.req_type = 0 };
1436 struct hwrm_ring_grp_alloc_output *resp = bp->hwrm_cmd_resp_addr;
1438 HWRM_PREP(req, RING_GRP_ALLOC, BNXT_USE_CHIMP_MB);
1440 req.cr = rte_cpu_to_le_16(bp->grp_info[idx].cp_fw_ring_id);
1441 req.rr = rte_cpu_to_le_16(bp->grp_info[idx].rx_fw_ring_id);
1442 req.ar = rte_cpu_to_le_16(bp->grp_info[idx].ag_fw_ring_id);
1443 req.sc = rte_cpu_to_le_16(bp->grp_info[idx].fw_stats_ctx);
1445 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1447 HWRM_CHECK_RESULT();
1449 bp->grp_info[idx].fw_grp_id =
1450 rte_le_to_cpu_16(resp->ring_group_id);
1457 int bnxt_hwrm_ring_grp_free(struct bnxt *bp, unsigned int idx)
1460 struct hwrm_ring_grp_free_input req = {.req_type = 0 };
1461 struct hwrm_ring_grp_free_output *resp = bp->hwrm_cmd_resp_addr;
1463 HWRM_PREP(req, RING_GRP_FREE, BNXT_USE_CHIMP_MB);
1465 req.ring_group_id = rte_cpu_to_le_16(bp->grp_info[idx].fw_grp_id);
1467 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1469 HWRM_CHECK_RESULT();
1472 bp->grp_info[idx].fw_grp_id = INVALID_HW_RING_ID;
1476 int bnxt_hwrm_stat_clear(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
1479 struct hwrm_stat_ctx_clr_stats_input req = {.req_type = 0 };
1480 struct hwrm_stat_ctx_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
1482 if (cpr->hw_stats_ctx_id == (uint32_t)HWRM_NA_SIGNATURE)
1485 HWRM_PREP(req, STAT_CTX_CLR_STATS, BNXT_USE_CHIMP_MB);
1487 req.stat_ctx_id = rte_cpu_to_le_32(cpr->hw_stats_ctx_id);
1489 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1491 HWRM_CHECK_RESULT();
1497 int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
1498 unsigned int idx __rte_unused)
1501 struct hwrm_stat_ctx_alloc_input req = {.req_type = 0 };
1502 struct hwrm_stat_ctx_alloc_output *resp = bp->hwrm_cmd_resp_addr;
1504 HWRM_PREP(req, STAT_CTX_ALLOC, BNXT_USE_CHIMP_MB);
1506 req.update_period_ms = rte_cpu_to_le_32(0);
1508 req.stats_dma_addr =
1509 rte_cpu_to_le_64(cpr->hw_stats_map);
1511 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1513 HWRM_CHECK_RESULT();
1515 cpr->hw_stats_ctx_id = rte_le_to_cpu_32(resp->stat_ctx_id);
1522 int bnxt_hwrm_stat_ctx_free(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
1523 unsigned int idx __rte_unused)
1526 struct hwrm_stat_ctx_free_input req = {.req_type = 0 };
1527 struct hwrm_stat_ctx_free_output *resp = bp->hwrm_cmd_resp_addr;
1529 HWRM_PREP(req, STAT_CTX_FREE, BNXT_USE_CHIMP_MB);
1531 req.stat_ctx_id = rte_cpu_to_le_32(cpr->hw_stats_ctx_id);
1533 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1535 HWRM_CHECK_RESULT();
1541 int bnxt_hwrm_vnic_alloc(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1544 struct hwrm_vnic_alloc_input req = { 0 };
1545 struct hwrm_vnic_alloc_output *resp = bp->hwrm_cmd_resp_addr;
1547 if (!BNXT_HAS_RING_GRPS(bp))
1548 goto skip_ring_grps;
1550 /* map ring groups to this vnic */
1551 PMD_DRV_LOG(DEBUG, "Alloc VNIC. Start %x, End %x\n",
1552 vnic->start_grp_id, vnic->end_grp_id);
1553 for (i = vnic->start_grp_id, j = 0; i < vnic->end_grp_id; i++, j++)
1554 vnic->fw_grp_ids[j] = bp->grp_info[i].fw_grp_id;
1556 vnic->dflt_ring_grp = bp->grp_info[vnic->start_grp_id].fw_grp_id;
1557 vnic->rss_rule = (uint16_t)HWRM_NA_SIGNATURE;
1558 vnic->cos_rule = (uint16_t)HWRM_NA_SIGNATURE;
1559 vnic->lb_rule = (uint16_t)HWRM_NA_SIGNATURE;
1562 vnic->mru = bp->eth_dev->data->mtu + RTE_ETHER_HDR_LEN +
1563 RTE_ETHER_CRC_LEN + VLAN_TAG_SIZE;
1564 HWRM_PREP(req, VNIC_ALLOC, BNXT_USE_CHIMP_MB);
1566 if (vnic->func_default)
1568 rte_cpu_to_le_32(HWRM_VNIC_ALLOC_INPUT_FLAGS_DEFAULT);
1569 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1571 HWRM_CHECK_RESULT();
1573 vnic->fw_vnic_id = rte_le_to_cpu_16(resp->vnic_id);
1575 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
1579 static int bnxt_hwrm_vnic_plcmodes_qcfg(struct bnxt *bp,
1580 struct bnxt_vnic_info *vnic,
1581 struct bnxt_plcmodes_cfg *pmode)
1584 struct hwrm_vnic_plcmodes_qcfg_input req = {.req_type = 0 };
1585 struct hwrm_vnic_plcmodes_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
1587 HWRM_PREP(req, VNIC_PLCMODES_QCFG, BNXT_USE_CHIMP_MB);
1589 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1591 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1593 HWRM_CHECK_RESULT();
1595 pmode->flags = rte_le_to_cpu_32(resp->flags);
1596 /* dflt_vnic bit doesn't exist in the _cfg command */
1597 pmode->flags &= ~(HWRM_VNIC_PLCMODES_QCFG_OUTPUT_FLAGS_DFLT_VNIC);
1598 pmode->jumbo_thresh = rte_le_to_cpu_16(resp->jumbo_thresh);
1599 pmode->hds_offset = rte_le_to_cpu_16(resp->hds_offset);
1600 pmode->hds_threshold = rte_le_to_cpu_16(resp->hds_threshold);
1607 static int bnxt_hwrm_vnic_plcmodes_cfg(struct bnxt *bp,
1608 struct bnxt_vnic_info *vnic,
1609 struct bnxt_plcmodes_cfg *pmode)
1612 struct hwrm_vnic_plcmodes_cfg_input req = {.req_type = 0 };
1613 struct hwrm_vnic_plcmodes_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1615 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1616 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
1620 HWRM_PREP(req, VNIC_PLCMODES_CFG, BNXT_USE_CHIMP_MB);
1622 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1623 req.flags = rte_cpu_to_le_32(pmode->flags);
1624 req.jumbo_thresh = rte_cpu_to_le_16(pmode->jumbo_thresh);
1625 req.hds_offset = rte_cpu_to_le_16(pmode->hds_offset);
1626 req.hds_threshold = rte_cpu_to_le_16(pmode->hds_threshold);
1627 req.enables = rte_cpu_to_le_32(
1628 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_HDS_THRESHOLD_VALID |
1629 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_HDS_OFFSET_VALID |
1630 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_JUMBO_THRESH_VALID
1633 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1635 HWRM_CHECK_RESULT();
1641 int bnxt_hwrm_vnic_cfg(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1644 struct hwrm_vnic_cfg_input req = {.req_type = 0 };
1645 struct hwrm_vnic_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1646 struct bnxt_plcmodes_cfg pmodes = { 0 };
1647 uint32_t ctx_enable_flag = 0;
1648 uint32_t enables = 0;
1650 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1651 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
1655 rc = bnxt_hwrm_vnic_plcmodes_qcfg(bp, vnic, &pmodes);
1659 HWRM_PREP(req, VNIC_CFG, BNXT_USE_CHIMP_MB);
1661 if (BNXT_CHIP_THOR(bp)) {
1662 struct bnxt_rx_queue *rxq = bp->eth_dev->data->rx_queues[0];
1663 struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
1664 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
1666 req.default_rx_ring_id =
1667 rte_cpu_to_le_16(rxr->rx_ring_struct->fw_ring_id);
1668 req.default_cmpl_ring_id =
1669 rte_cpu_to_le_16(cpr->cp_ring_struct->fw_ring_id);
1670 enables = HWRM_VNIC_CFG_INPUT_ENABLES_DEFAULT_RX_RING_ID |
1671 HWRM_VNIC_CFG_INPUT_ENABLES_DEFAULT_CMPL_RING_ID;
1675 /* Only RSS support for now TBD: COS & LB */
1676 enables = HWRM_VNIC_CFG_INPUT_ENABLES_DFLT_RING_GRP;
1677 if (vnic->lb_rule != 0xffff)
1678 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_LB_RULE;
1679 if (vnic->cos_rule != 0xffff)
1680 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_COS_RULE;
1681 if (vnic->rss_rule != (uint16_t)HWRM_NA_SIGNATURE) {
1682 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_MRU;
1683 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_RSS_RULE;
1685 enables |= ctx_enable_flag;
1686 req.dflt_ring_grp = rte_cpu_to_le_16(vnic->dflt_ring_grp);
1687 req.rss_rule = rte_cpu_to_le_16(vnic->rss_rule);
1688 req.cos_rule = rte_cpu_to_le_16(vnic->cos_rule);
1689 req.lb_rule = rte_cpu_to_le_16(vnic->lb_rule);
1692 req.enables = rte_cpu_to_le_32(enables);
1693 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1694 req.mru = rte_cpu_to_le_16(vnic->mru);
1695 /* Configure default VNIC only once. */
1696 if (vnic->func_default && !(bp->flags & BNXT_FLAG_DFLT_VNIC_SET)) {
1698 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_DEFAULT);
1699 bp->flags |= BNXT_FLAG_DFLT_VNIC_SET;
1701 if (vnic->vlan_strip)
1703 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_VLAN_STRIP_MODE);
1706 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_BD_STALL_MODE);
1707 if (vnic->roce_dual)
1708 req.flags |= rte_cpu_to_le_32(
1709 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_DUAL_VNIC_MODE);
1710 if (vnic->roce_only)
1711 req.flags |= rte_cpu_to_le_32(
1712 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_ONLY_VNIC_MODE);
1713 if (vnic->rss_dflt_cr)
1714 req.flags |= rte_cpu_to_le_32(
1715 HWRM_VNIC_QCFG_OUTPUT_FLAGS_RSS_DFLT_CR_MODE);
1717 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1719 HWRM_CHECK_RESULT();
1722 rc = bnxt_hwrm_vnic_plcmodes_cfg(bp, vnic, &pmodes);
1727 int bnxt_hwrm_vnic_qcfg(struct bnxt *bp, struct bnxt_vnic_info *vnic,
1731 struct hwrm_vnic_qcfg_input req = {.req_type = 0 };
1732 struct hwrm_vnic_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
1734 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1735 PMD_DRV_LOG(DEBUG, "VNIC QCFG ID %d\n", vnic->fw_vnic_id);
1738 HWRM_PREP(req, VNIC_QCFG, BNXT_USE_CHIMP_MB);
1741 rte_cpu_to_le_32(HWRM_VNIC_QCFG_INPUT_ENABLES_VF_ID_VALID);
1742 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1743 req.vf_id = rte_cpu_to_le_16(fw_vf_id);
1745 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1747 HWRM_CHECK_RESULT();
1749 vnic->dflt_ring_grp = rte_le_to_cpu_16(resp->dflt_ring_grp);
1750 vnic->rss_rule = rte_le_to_cpu_16(resp->rss_rule);
1751 vnic->cos_rule = rte_le_to_cpu_16(resp->cos_rule);
1752 vnic->lb_rule = rte_le_to_cpu_16(resp->lb_rule);
1753 vnic->mru = rte_le_to_cpu_16(resp->mru);
1754 vnic->func_default = rte_le_to_cpu_32(
1755 resp->flags) & HWRM_VNIC_QCFG_OUTPUT_FLAGS_DEFAULT;
1756 vnic->vlan_strip = rte_le_to_cpu_32(resp->flags) &
1757 HWRM_VNIC_QCFG_OUTPUT_FLAGS_VLAN_STRIP_MODE;
1758 vnic->bd_stall = rte_le_to_cpu_32(resp->flags) &
1759 HWRM_VNIC_QCFG_OUTPUT_FLAGS_BD_STALL_MODE;
1760 vnic->roce_dual = rte_le_to_cpu_32(resp->flags) &
1761 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_DUAL_VNIC_MODE;
1762 vnic->roce_only = rte_le_to_cpu_32(resp->flags) &
1763 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_ONLY_VNIC_MODE;
1764 vnic->rss_dflt_cr = rte_le_to_cpu_32(resp->flags) &
1765 HWRM_VNIC_QCFG_OUTPUT_FLAGS_RSS_DFLT_CR_MODE;
1772 int bnxt_hwrm_vnic_ctx_alloc(struct bnxt *bp,
1773 struct bnxt_vnic_info *vnic, uint16_t ctx_idx)
1777 struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req = {.req_type = 0 };
1778 struct hwrm_vnic_rss_cos_lb_ctx_alloc_output *resp =
1779 bp->hwrm_cmd_resp_addr;
1781 HWRM_PREP(req, VNIC_RSS_COS_LB_CTX_ALLOC, BNXT_USE_CHIMP_MB);
1783 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1784 HWRM_CHECK_RESULT();
1786 ctx_id = rte_le_to_cpu_16(resp->rss_cos_lb_ctx_id);
1787 if (!BNXT_HAS_RING_GRPS(bp))
1788 vnic->fw_grp_ids[ctx_idx] = ctx_id;
1789 else if (ctx_idx == 0)
1790 vnic->rss_rule = ctx_id;
1798 int _bnxt_hwrm_vnic_ctx_free(struct bnxt *bp,
1799 struct bnxt_vnic_info *vnic, uint16_t ctx_idx)
1802 struct hwrm_vnic_rss_cos_lb_ctx_free_input req = {.req_type = 0 };
1803 struct hwrm_vnic_rss_cos_lb_ctx_free_output *resp =
1804 bp->hwrm_cmd_resp_addr;
1806 if (ctx_idx == (uint16_t)HWRM_NA_SIGNATURE) {
1807 PMD_DRV_LOG(DEBUG, "VNIC RSS Rule %x\n", vnic->rss_rule);
1810 HWRM_PREP(req, VNIC_RSS_COS_LB_CTX_FREE, BNXT_USE_CHIMP_MB);
1812 req.rss_cos_lb_ctx_id = rte_cpu_to_le_16(ctx_idx);
1814 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1816 HWRM_CHECK_RESULT();
1822 int bnxt_hwrm_vnic_ctx_free(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1826 if (BNXT_CHIP_THOR(bp)) {
1829 for (j = 0; j < vnic->num_lb_ctxts; j++) {
1830 rc = _bnxt_hwrm_vnic_ctx_free(bp,
1832 vnic->fw_grp_ids[j]);
1833 vnic->fw_grp_ids[j] = INVALID_HW_RING_ID;
1835 vnic->num_lb_ctxts = 0;
1837 rc = _bnxt_hwrm_vnic_ctx_free(bp, vnic, vnic->rss_rule);
1838 vnic->rss_rule = INVALID_HW_RING_ID;
1844 int bnxt_hwrm_vnic_free(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1847 struct hwrm_vnic_free_input req = {.req_type = 0 };
1848 struct hwrm_vnic_free_output *resp = bp->hwrm_cmd_resp_addr;
1850 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1851 PMD_DRV_LOG(DEBUG, "VNIC FREE ID %x\n", vnic->fw_vnic_id);
1855 HWRM_PREP(req, VNIC_FREE, BNXT_USE_CHIMP_MB);
1857 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1859 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1861 HWRM_CHECK_RESULT();
1864 vnic->fw_vnic_id = INVALID_HW_RING_ID;
1865 /* Configure default VNIC again if necessary. */
1866 if (vnic->func_default && (bp->flags & BNXT_FLAG_DFLT_VNIC_SET))
1867 bp->flags &= ~BNXT_FLAG_DFLT_VNIC_SET;
1873 bnxt_hwrm_vnic_rss_cfg_thor(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1877 int nr_ctxs = vnic->num_lb_ctxts;
1878 struct hwrm_vnic_rss_cfg_input req = {.req_type = 0 };
1879 struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1881 for (i = 0; i < nr_ctxs; i++) {
1882 HWRM_PREP(req, VNIC_RSS_CFG, BNXT_USE_CHIMP_MB);
1884 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1885 req.hash_type = rte_cpu_to_le_32(vnic->hash_type);
1886 req.hash_mode_flags = vnic->hash_mode;
1888 req.hash_key_tbl_addr =
1889 rte_cpu_to_le_64(vnic->rss_hash_key_dma_addr);
1891 req.ring_grp_tbl_addr =
1892 rte_cpu_to_le_64(vnic->rss_table_dma_addr +
1893 i * HW_HASH_INDEX_SIZE);
1894 req.ring_table_pair_index = i;
1895 req.rss_ctx_idx = rte_cpu_to_le_16(vnic->fw_grp_ids[i]);
1897 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req),
1900 HWRM_CHECK_RESULT();
1907 int bnxt_hwrm_vnic_rss_cfg(struct bnxt *bp,
1908 struct bnxt_vnic_info *vnic)
1911 struct hwrm_vnic_rss_cfg_input req = {.req_type = 0 };
1912 struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1914 if (!vnic->rss_table)
1917 if (BNXT_CHIP_THOR(bp))
1918 return bnxt_hwrm_vnic_rss_cfg_thor(bp, vnic);
1920 HWRM_PREP(req, VNIC_RSS_CFG, BNXT_USE_CHIMP_MB);
1922 req.hash_type = rte_cpu_to_le_32(vnic->hash_type);
1923 req.hash_mode_flags = vnic->hash_mode;
1925 req.ring_grp_tbl_addr =
1926 rte_cpu_to_le_64(vnic->rss_table_dma_addr);
1927 req.hash_key_tbl_addr =
1928 rte_cpu_to_le_64(vnic->rss_hash_key_dma_addr);
1929 req.rss_ctx_idx = rte_cpu_to_le_16(vnic->rss_rule);
1930 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1932 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1934 HWRM_CHECK_RESULT();
1940 int bnxt_hwrm_vnic_plcmode_cfg(struct bnxt *bp,
1941 struct bnxt_vnic_info *vnic)
1944 struct hwrm_vnic_plcmodes_cfg_input req = {.req_type = 0 };
1945 struct hwrm_vnic_plcmodes_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1948 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1949 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
1953 HWRM_PREP(req, VNIC_PLCMODES_CFG, BNXT_USE_CHIMP_MB);
1955 req.flags = rte_cpu_to_le_32(
1956 HWRM_VNIC_PLCMODES_CFG_INPUT_FLAGS_JUMBO_PLACEMENT);
1958 req.enables = rte_cpu_to_le_32(
1959 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_JUMBO_THRESH_VALID);
1961 size = rte_pktmbuf_data_room_size(bp->rx_queues[0]->mb_pool);
1962 size -= RTE_PKTMBUF_HEADROOM;
1963 size = RTE_MIN(BNXT_MAX_PKT_LEN, size);
1965 req.jumbo_thresh = rte_cpu_to_le_16(size);
1966 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1968 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1970 HWRM_CHECK_RESULT();
1976 int bnxt_hwrm_vnic_tpa_cfg(struct bnxt *bp,
1977 struct bnxt_vnic_info *vnic, bool enable)
1980 struct hwrm_vnic_tpa_cfg_input req = {.req_type = 0 };
1981 struct hwrm_vnic_tpa_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1983 if (BNXT_CHIP_THOR(bp) && !bp->max_tpa_v2) {
1985 PMD_DRV_LOG(ERR, "No HW support for LRO\n");
1989 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1990 PMD_DRV_LOG(DEBUG, "Invalid vNIC ID\n");
1994 HWRM_PREP(req, VNIC_TPA_CFG, BNXT_USE_CHIMP_MB);
1997 req.enables = rte_cpu_to_le_32(
1998 HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MAX_AGG_SEGS |
1999 HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MAX_AGGS |
2000 HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MIN_AGG_LEN);
2001 req.flags = rte_cpu_to_le_32(
2002 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_TPA |
2003 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_ENCAP_TPA |
2004 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_RSC_WND_UPDATE |
2005 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_GRO |
2006 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_AGG_WITH_ECN |
2007 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_AGG_WITH_SAME_GRE_SEQ);
2008 req.max_agg_segs = rte_cpu_to_le_16(BNXT_TPA_MAX_AGGS(bp));
2009 req.max_aggs = rte_cpu_to_le_16(BNXT_TPA_MAX_SEGS(bp));
2010 req.min_agg_len = rte_cpu_to_le_32(512);
2012 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
2014 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2016 HWRM_CHECK_RESULT();
2022 int bnxt_hwrm_func_vf_mac(struct bnxt *bp, uint16_t vf, const uint8_t *mac_addr)
2024 struct hwrm_func_cfg_input req = {0};
2025 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2028 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[vf].func_cfg_flags);
2029 req.enables = rte_cpu_to_le_32(
2030 HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
2031 memcpy(req.dflt_mac_addr, mac_addr, sizeof(req.dflt_mac_addr));
2032 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
2034 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
2036 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2037 HWRM_CHECK_RESULT();
2040 bp->pf.vf_info[vf].random_mac = false;
2045 int bnxt_hwrm_func_qstats_tx_drop(struct bnxt *bp, uint16_t fid,
2049 struct hwrm_func_qstats_input req = {.req_type = 0};
2050 struct hwrm_func_qstats_output *resp = bp->hwrm_cmd_resp_addr;
2052 HWRM_PREP(req, FUNC_QSTATS, BNXT_USE_CHIMP_MB);
2054 req.fid = rte_cpu_to_le_16(fid);
2056 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2058 HWRM_CHECK_RESULT();
2061 *dropped = rte_le_to_cpu_64(resp->tx_drop_pkts);
2068 int bnxt_hwrm_func_qstats(struct bnxt *bp, uint16_t fid,
2069 struct rte_eth_stats *stats)
2072 struct hwrm_func_qstats_input req = {.req_type = 0};
2073 struct hwrm_func_qstats_output *resp = bp->hwrm_cmd_resp_addr;
2075 HWRM_PREP(req, FUNC_QSTATS, BNXT_USE_CHIMP_MB);
2077 req.fid = rte_cpu_to_le_16(fid);
2079 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2081 HWRM_CHECK_RESULT();
2083 stats->ipackets = rte_le_to_cpu_64(resp->rx_ucast_pkts);
2084 stats->ipackets += rte_le_to_cpu_64(resp->rx_mcast_pkts);
2085 stats->ipackets += rte_le_to_cpu_64(resp->rx_bcast_pkts);
2086 stats->ibytes = rte_le_to_cpu_64(resp->rx_ucast_bytes);
2087 stats->ibytes += rte_le_to_cpu_64(resp->rx_mcast_bytes);
2088 stats->ibytes += rte_le_to_cpu_64(resp->rx_bcast_bytes);
2090 stats->opackets = rte_le_to_cpu_64(resp->tx_ucast_pkts);
2091 stats->opackets += rte_le_to_cpu_64(resp->tx_mcast_pkts);
2092 stats->opackets += rte_le_to_cpu_64(resp->tx_bcast_pkts);
2093 stats->obytes = rte_le_to_cpu_64(resp->tx_ucast_bytes);
2094 stats->obytes += rte_le_to_cpu_64(resp->tx_mcast_bytes);
2095 stats->obytes += rte_le_to_cpu_64(resp->tx_bcast_bytes);
2097 stats->imissed = rte_le_to_cpu_64(resp->rx_discard_pkts);
2098 stats->ierrors = rte_le_to_cpu_64(resp->rx_drop_pkts);
2099 stats->oerrors = rte_le_to_cpu_64(resp->tx_discard_pkts);
2106 int bnxt_hwrm_func_clr_stats(struct bnxt *bp, uint16_t fid)
2109 struct hwrm_func_clr_stats_input req = {.req_type = 0};
2110 struct hwrm_func_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
2112 HWRM_PREP(req, FUNC_CLR_STATS, BNXT_USE_CHIMP_MB);
2114 req.fid = rte_cpu_to_le_16(fid);
2116 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2118 HWRM_CHECK_RESULT();
2125 * HWRM utility functions
2128 int bnxt_clear_all_hwrm_stat_ctxs(struct bnxt *bp)
2133 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
2134 struct bnxt_tx_queue *txq;
2135 struct bnxt_rx_queue *rxq;
2136 struct bnxt_cp_ring_info *cpr;
2138 if (i >= bp->rx_cp_nr_rings) {
2139 txq = bp->tx_queues[i - bp->rx_cp_nr_rings];
2142 rxq = bp->rx_queues[i];
2146 rc = bnxt_hwrm_stat_clear(bp, cpr);
2153 int bnxt_free_all_hwrm_stat_ctxs(struct bnxt *bp)
2157 struct bnxt_cp_ring_info *cpr;
2159 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
2161 if (i >= bp->rx_cp_nr_rings) {
2162 cpr = bp->tx_queues[i - bp->rx_cp_nr_rings]->cp_ring;
2164 cpr = bp->rx_queues[i]->cp_ring;
2165 if (BNXT_HAS_RING_GRPS(bp))
2166 bp->grp_info[i].fw_stats_ctx = -1;
2168 if (cpr->hw_stats_ctx_id != HWRM_NA_SIGNATURE) {
2169 rc = bnxt_hwrm_stat_ctx_free(bp, cpr, i);
2170 cpr->hw_stats_ctx_id = HWRM_NA_SIGNATURE;
2178 int bnxt_alloc_all_hwrm_stat_ctxs(struct bnxt *bp)
2183 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
2184 struct bnxt_tx_queue *txq;
2185 struct bnxt_rx_queue *rxq;
2186 struct bnxt_cp_ring_info *cpr;
2188 if (i >= bp->rx_cp_nr_rings) {
2189 txq = bp->tx_queues[i - bp->rx_cp_nr_rings];
2192 rxq = bp->rx_queues[i];
2196 rc = bnxt_hwrm_stat_ctx_alloc(bp, cpr, i);
2204 int bnxt_free_all_hwrm_ring_grps(struct bnxt *bp)
2209 if (!BNXT_HAS_RING_GRPS(bp))
2212 for (idx = 0; idx < bp->rx_cp_nr_rings; idx++) {
2214 if (bp->grp_info[idx].fw_grp_id == INVALID_HW_RING_ID)
2217 rc = bnxt_hwrm_ring_grp_free(bp, idx);
2225 void bnxt_free_nq_ring(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
2227 struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
2229 bnxt_hwrm_ring_free(bp, cp_ring,
2230 HWRM_RING_FREE_INPUT_RING_TYPE_NQ);
2231 cp_ring->fw_ring_id = INVALID_HW_RING_ID;
2232 memset(cpr->cp_desc_ring, 0, cpr->cp_ring_struct->ring_size *
2233 sizeof(*cpr->cp_desc_ring));
2234 cpr->cp_raw_cons = 0;
2238 void bnxt_free_cp_ring(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
2240 struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
2242 bnxt_hwrm_ring_free(bp, cp_ring,
2243 HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL);
2244 cp_ring->fw_ring_id = INVALID_HW_RING_ID;
2245 memset(cpr->cp_desc_ring, 0, cpr->cp_ring_struct->ring_size *
2246 sizeof(*cpr->cp_desc_ring));
2247 cpr->cp_raw_cons = 0;
2251 void bnxt_free_hwrm_rx_ring(struct bnxt *bp, int queue_index)
2253 struct bnxt_rx_queue *rxq = bp->rx_queues[queue_index];
2254 struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
2255 struct bnxt_ring *ring = rxr->rx_ring_struct;
2256 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
2258 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
2259 bnxt_hwrm_ring_free(bp, ring,
2260 HWRM_RING_FREE_INPUT_RING_TYPE_RX);
2261 ring->fw_ring_id = INVALID_HW_RING_ID;
2262 if (BNXT_HAS_RING_GRPS(bp))
2263 bp->grp_info[queue_index].rx_fw_ring_id =
2265 memset(rxr->rx_desc_ring, 0,
2266 rxr->rx_ring_struct->ring_size *
2267 sizeof(*rxr->rx_desc_ring));
2268 memset(rxr->rx_buf_ring, 0,
2269 rxr->rx_ring_struct->ring_size *
2270 sizeof(*rxr->rx_buf_ring));
2273 ring = rxr->ag_ring_struct;
2274 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
2275 bnxt_hwrm_ring_free(bp, ring,
2276 BNXT_CHIP_THOR(bp) ?
2277 HWRM_RING_FREE_INPUT_RING_TYPE_RX_AGG :
2278 HWRM_RING_FREE_INPUT_RING_TYPE_RX);
2279 ring->fw_ring_id = INVALID_HW_RING_ID;
2280 memset(rxr->ag_buf_ring, 0,
2281 rxr->ag_ring_struct->ring_size *
2282 sizeof(*rxr->ag_buf_ring));
2284 if (BNXT_HAS_RING_GRPS(bp))
2285 bp->grp_info[queue_index].ag_fw_ring_id =
2288 if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID) {
2289 bnxt_free_cp_ring(bp, cpr);
2291 bnxt_free_nq_ring(bp, rxq->nq_ring);
2294 if (BNXT_HAS_RING_GRPS(bp))
2295 bp->grp_info[queue_index].cp_fw_ring_id = INVALID_HW_RING_ID;
2298 int bnxt_free_all_hwrm_rings(struct bnxt *bp)
2302 for (i = 0; i < bp->tx_cp_nr_rings; i++) {
2303 struct bnxt_tx_queue *txq = bp->tx_queues[i];
2304 struct bnxt_tx_ring_info *txr = txq->tx_ring;
2305 struct bnxt_ring *ring = txr->tx_ring_struct;
2306 struct bnxt_cp_ring_info *cpr = txq->cp_ring;
2308 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
2309 bnxt_hwrm_ring_free(bp, ring,
2310 HWRM_RING_FREE_INPUT_RING_TYPE_TX);
2311 ring->fw_ring_id = INVALID_HW_RING_ID;
2312 memset(txr->tx_desc_ring, 0,
2313 txr->tx_ring_struct->ring_size *
2314 sizeof(*txr->tx_desc_ring));
2315 memset(txr->tx_buf_ring, 0,
2316 txr->tx_ring_struct->ring_size *
2317 sizeof(*txr->tx_buf_ring));
2321 if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID) {
2322 bnxt_free_cp_ring(bp, cpr);
2323 cpr->cp_ring_struct->fw_ring_id = INVALID_HW_RING_ID;
2325 bnxt_free_nq_ring(bp, txq->nq_ring);
2329 for (i = 0; i < bp->rx_cp_nr_rings; i++)
2330 bnxt_free_hwrm_rx_ring(bp, i);
2335 int bnxt_alloc_all_hwrm_ring_grps(struct bnxt *bp)
2340 if (!BNXT_HAS_RING_GRPS(bp))
2343 for (i = 0; i < bp->rx_cp_nr_rings; i++) {
2344 rc = bnxt_hwrm_ring_grp_alloc(bp, i);
2351 void bnxt_free_hwrm_resources(struct bnxt *bp)
2353 /* Release memzone */
2354 rte_free(bp->hwrm_cmd_resp_addr);
2355 rte_free(bp->hwrm_short_cmd_req_addr);
2356 bp->hwrm_cmd_resp_addr = NULL;
2357 bp->hwrm_short_cmd_req_addr = NULL;
2358 bp->hwrm_cmd_resp_dma_addr = 0;
2359 bp->hwrm_short_cmd_req_dma_addr = 0;
2362 int bnxt_alloc_hwrm_resources(struct bnxt *bp)
2364 struct rte_pci_device *pdev = bp->pdev;
2365 char type[RTE_MEMZONE_NAMESIZE];
2367 sprintf(type, "bnxt_hwrm_%04x:%02x:%02x:%02x", pdev->addr.domain,
2368 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
2369 bp->max_resp_len = HWRM_MAX_RESP_LEN;
2370 bp->hwrm_cmd_resp_addr = rte_malloc(type, bp->max_resp_len, 0);
2371 rte_mem_lock_page(bp->hwrm_cmd_resp_addr);
2372 if (bp->hwrm_cmd_resp_addr == NULL)
2374 bp->hwrm_cmd_resp_dma_addr =
2375 rte_mem_virt2iova(bp->hwrm_cmd_resp_addr);
2376 if (bp->hwrm_cmd_resp_dma_addr == RTE_BAD_IOVA) {
2378 "unable to map response address to physical memory\n");
2381 rte_spinlock_init(&bp->hwrm_lock);
2386 int bnxt_clear_hwrm_vnic_filters(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2388 struct bnxt_filter_info *filter;
2391 STAILQ_FOREACH(filter, &vnic->filter, next) {
2392 if (filter->filter_type == HWRM_CFA_EM_FILTER)
2393 rc = bnxt_hwrm_clear_em_filter(bp, filter);
2394 else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
2395 rc = bnxt_hwrm_clear_ntuple_filter(bp, filter);
2397 rc = bnxt_hwrm_clear_l2_filter(bp, filter);
2398 STAILQ_REMOVE(&vnic->filter, filter, bnxt_filter_info, next);
2399 bnxt_free_filter(bp, filter);
2407 bnxt_clear_hwrm_vnic_flows(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2409 struct bnxt_filter_info *filter;
2410 struct rte_flow *flow;
2413 while (!STAILQ_EMPTY(&vnic->flow_list)) {
2414 flow = STAILQ_FIRST(&vnic->flow_list);
2415 filter = flow->filter;
2416 PMD_DRV_LOG(DEBUG, "filter type %d\n", filter->filter_type);
2417 if (filter->filter_type == HWRM_CFA_EM_FILTER)
2418 rc = bnxt_hwrm_clear_em_filter(bp, filter);
2419 else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
2420 rc = bnxt_hwrm_clear_ntuple_filter(bp, filter);
2422 rc = bnxt_hwrm_clear_l2_filter(bp, filter);
2424 STAILQ_REMOVE(&vnic->flow_list, flow, rte_flow, next);
2432 int bnxt_set_hwrm_vnic_filters(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2434 struct bnxt_filter_info *filter;
2437 STAILQ_FOREACH(filter, &vnic->filter, next) {
2438 if (filter->filter_type == HWRM_CFA_EM_FILTER) {
2439 rc = bnxt_hwrm_set_em_filter(bp, filter->dst_id,
2441 } else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER) {
2442 rc = bnxt_hwrm_set_ntuple_filter(bp, filter->dst_id,
2445 rc = bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id,
2456 void bnxt_free_tunnel_ports(struct bnxt *bp)
2458 if (bp->vxlan_port_cnt)
2459 bnxt_hwrm_tunnel_dst_port_free(bp, bp->vxlan_fw_dst_port_id,
2460 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_VXLAN);
2462 if (bp->geneve_port_cnt)
2463 bnxt_hwrm_tunnel_dst_port_free(bp, bp->geneve_fw_dst_port_id,
2464 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_GENEVE);
2465 bp->geneve_port = 0;
2468 void bnxt_free_all_hwrm_resources(struct bnxt *bp)
2472 if (bp->vnic_info == NULL)
2476 * Cleanup VNICs in reverse order, to make sure the L2 filter
2477 * from vnic0 is last to be cleaned up.
2479 for (i = bp->max_vnics - 1; i >= 0; i--) {
2480 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
2482 // If the VNIC ID is invalid we are not currently using the VNIC
2483 if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
2486 bnxt_clear_hwrm_vnic_flows(bp, vnic);
2488 bnxt_clear_hwrm_vnic_filters(bp, vnic);
2490 bnxt_hwrm_vnic_ctx_free(bp, vnic);
2492 bnxt_hwrm_vnic_tpa_cfg(bp, vnic, false);
2494 bnxt_hwrm_vnic_free(bp, vnic);
2496 rte_free(vnic->fw_grp_ids);
2498 /* Ring resources */
2499 bnxt_free_all_hwrm_rings(bp);
2500 bnxt_free_all_hwrm_ring_grps(bp);
2501 bnxt_free_all_hwrm_stat_ctxs(bp);
2502 bnxt_free_tunnel_ports(bp);
2505 static uint16_t bnxt_parse_eth_link_duplex(uint32_t conf_link_speed)
2507 uint8_t hw_link_duplex = HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH;
2509 if ((conf_link_speed & ETH_LINK_SPEED_FIXED) == ETH_LINK_SPEED_AUTONEG)
2510 return HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH;
2512 switch (conf_link_speed) {
2513 case ETH_LINK_SPEED_10M_HD:
2514 case ETH_LINK_SPEED_100M_HD:
2516 return HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_HALF;
2518 return hw_link_duplex;
2521 static uint16_t bnxt_check_eth_link_autoneg(uint32_t conf_link)
2523 return (conf_link & ETH_LINK_SPEED_FIXED) ? 0 : 1;
2526 static uint16_t bnxt_parse_eth_link_speed(uint32_t conf_link_speed)
2528 uint16_t eth_link_speed = 0;
2530 if (conf_link_speed == ETH_LINK_SPEED_AUTONEG)
2531 return ETH_LINK_SPEED_AUTONEG;
2533 switch (conf_link_speed & ~ETH_LINK_SPEED_FIXED) {
2534 case ETH_LINK_SPEED_100M:
2535 case ETH_LINK_SPEED_100M_HD:
2538 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_100MB;
2540 case ETH_LINK_SPEED_1G:
2542 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_1GB;
2544 case ETH_LINK_SPEED_2_5G:
2546 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_2_5GB;
2548 case ETH_LINK_SPEED_10G:
2550 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_10GB;
2552 case ETH_LINK_SPEED_20G:
2554 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_20GB;
2556 case ETH_LINK_SPEED_25G:
2558 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_25GB;
2560 case ETH_LINK_SPEED_40G:
2562 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_40GB;
2564 case ETH_LINK_SPEED_50G:
2566 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_50GB;
2568 case ETH_LINK_SPEED_100G:
2570 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_100GB;
2574 "Unsupported link speed %d; default to AUTO\n",
2578 return eth_link_speed;
2581 #define BNXT_SUPPORTED_SPEEDS (ETH_LINK_SPEED_100M | ETH_LINK_SPEED_100M_HD | \
2582 ETH_LINK_SPEED_1G | ETH_LINK_SPEED_2_5G | \
2583 ETH_LINK_SPEED_10G | ETH_LINK_SPEED_20G | ETH_LINK_SPEED_25G | \
2584 ETH_LINK_SPEED_40G | ETH_LINK_SPEED_50G | ETH_LINK_SPEED_100G)
2586 static int bnxt_valid_link_speed(uint32_t link_speed, uint16_t port_id)
2590 if (link_speed == ETH_LINK_SPEED_AUTONEG)
2593 if (link_speed & ETH_LINK_SPEED_FIXED) {
2594 one_speed = link_speed & ~ETH_LINK_SPEED_FIXED;
2596 if (one_speed & (one_speed - 1)) {
2598 "Invalid advertised speeds (%u) for port %u\n",
2599 link_speed, port_id);
2602 if ((one_speed & BNXT_SUPPORTED_SPEEDS) != one_speed) {
2604 "Unsupported advertised speed (%u) for port %u\n",
2605 link_speed, port_id);
2609 if (!(link_speed & BNXT_SUPPORTED_SPEEDS)) {
2611 "Unsupported advertised speeds (%u) for port %u\n",
2612 link_speed, port_id);
2620 bnxt_parse_eth_link_speed_mask(struct bnxt *bp, uint32_t link_speed)
2624 if (link_speed == ETH_LINK_SPEED_AUTONEG) {
2625 if (bp->link_info.support_speeds)
2626 return bp->link_info.support_speeds;
2627 link_speed = BNXT_SUPPORTED_SPEEDS;
2630 if (link_speed & ETH_LINK_SPEED_100M)
2631 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100MB;
2632 if (link_speed & ETH_LINK_SPEED_100M_HD)
2633 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100MB;
2634 if (link_speed & ETH_LINK_SPEED_1G)
2635 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_1GB;
2636 if (link_speed & ETH_LINK_SPEED_2_5G)
2637 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_2_5GB;
2638 if (link_speed & ETH_LINK_SPEED_10G)
2639 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_10GB;
2640 if (link_speed & ETH_LINK_SPEED_20G)
2641 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_20GB;
2642 if (link_speed & ETH_LINK_SPEED_25G)
2643 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_25GB;
2644 if (link_speed & ETH_LINK_SPEED_40G)
2645 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_40GB;
2646 if (link_speed & ETH_LINK_SPEED_50G)
2647 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_50GB;
2648 if (link_speed & ETH_LINK_SPEED_100G)
2649 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100GB;
2653 static uint32_t bnxt_parse_hw_link_speed(uint16_t hw_link_speed)
2655 uint32_t eth_link_speed = ETH_SPEED_NUM_NONE;
2657 switch (hw_link_speed) {
2658 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100MB:
2659 eth_link_speed = ETH_SPEED_NUM_100M;
2661 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_1GB:
2662 eth_link_speed = ETH_SPEED_NUM_1G;
2664 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2_5GB:
2665 eth_link_speed = ETH_SPEED_NUM_2_5G;
2667 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_10GB:
2668 eth_link_speed = ETH_SPEED_NUM_10G;
2670 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_20GB:
2671 eth_link_speed = ETH_SPEED_NUM_20G;
2673 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_25GB:
2674 eth_link_speed = ETH_SPEED_NUM_25G;
2676 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_40GB:
2677 eth_link_speed = ETH_SPEED_NUM_40G;
2679 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_50GB:
2680 eth_link_speed = ETH_SPEED_NUM_50G;
2682 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100GB:
2683 eth_link_speed = ETH_SPEED_NUM_100G;
2685 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2GB:
2687 PMD_DRV_LOG(ERR, "HWRM link speed %d not defined\n",
2691 return eth_link_speed;
2694 static uint16_t bnxt_parse_hw_link_duplex(uint16_t hw_link_duplex)
2696 uint16_t eth_link_duplex = ETH_LINK_FULL_DUPLEX;
2698 switch (hw_link_duplex) {
2699 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH:
2700 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_FULL:
2702 eth_link_duplex = ETH_LINK_FULL_DUPLEX;
2704 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_HALF:
2705 eth_link_duplex = ETH_LINK_HALF_DUPLEX;
2708 PMD_DRV_LOG(ERR, "HWRM link duplex %d not defined\n",
2712 return eth_link_duplex;
2715 int bnxt_get_hwrm_link_config(struct bnxt *bp, struct rte_eth_link *link)
2718 struct bnxt_link_info *link_info = &bp->link_info;
2720 rc = bnxt_hwrm_port_phy_qcfg(bp, link_info);
2723 "Get link config failed with rc %d\n", rc);
2726 if (link_info->link_speed)
2728 bnxt_parse_hw_link_speed(link_info->link_speed);
2730 link->link_speed = ETH_SPEED_NUM_NONE;
2731 link->link_duplex = bnxt_parse_hw_link_duplex(link_info->duplex);
2732 link->link_status = link_info->link_up;
2733 link->link_autoneg = link_info->auto_mode ==
2734 HWRM_PORT_PHY_QCFG_OUTPUT_AUTO_MODE_NONE ?
2735 ETH_LINK_FIXED : ETH_LINK_AUTONEG;
2740 int bnxt_set_hwrm_link_config(struct bnxt *bp, bool link_up)
2743 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
2744 struct bnxt_link_info link_req;
2745 uint16_t speed, autoneg;
2747 if (!BNXT_SINGLE_PF(bp) || BNXT_VF(bp))
2750 rc = bnxt_valid_link_speed(dev_conf->link_speeds,
2751 bp->eth_dev->data->port_id);
2755 memset(&link_req, 0, sizeof(link_req));
2756 link_req.link_up = link_up;
2760 autoneg = bnxt_check_eth_link_autoneg(dev_conf->link_speeds);
2761 if (BNXT_CHIP_THOR(bp) &&
2762 dev_conf->link_speeds == ETH_LINK_SPEED_40G) {
2763 /* 40G is not supported as part of media auto detect.
2764 * The speed should be forced and autoneg disabled
2765 * to configure 40G speed.
2767 PMD_DRV_LOG(INFO, "Disabling autoneg for 40G\n");
2771 speed = bnxt_parse_eth_link_speed(dev_conf->link_speeds);
2772 link_req.phy_flags = HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESET_PHY;
2773 /* Autoneg can be done only when the FW allows.
2774 * When user configures fixed speed of 40G and later changes to
2775 * any other speed, auto_link_speed/force_link_speed is still set
2776 * to 40G until link comes up at new speed.
2779 !(!BNXT_CHIP_THOR(bp) &&
2780 (bp->link_info.auto_link_speed ||
2781 bp->link_info.force_link_speed))) {
2782 link_req.phy_flags |=
2783 HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESTART_AUTONEG;
2784 link_req.auto_link_speed_mask =
2785 bnxt_parse_eth_link_speed_mask(bp,
2786 dev_conf->link_speeds);
2788 if (bp->link_info.phy_type ==
2789 HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET ||
2790 bp->link_info.phy_type ==
2791 HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASETE ||
2792 bp->link_info.media_type ==
2793 HWRM_PORT_PHY_QCFG_OUTPUT_MEDIA_TYPE_TP) {
2794 PMD_DRV_LOG(ERR, "10GBase-T devices must autoneg\n");
2798 link_req.phy_flags |= HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE;
2799 /* If user wants a particular speed try that first. */
2801 link_req.link_speed = speed;
2802 else if (bp->link_info.force_link_speed)
2803 link_req.link_speed = bp->link_info.force_link_speed;
2805 link_req.link_speed = bp->link_info.auto_link_speed;
2807 link_req.duplex = bnxt_parse_eth_link_duplex(dev_conf->link_speeds);
2808 link_req.auto_pause = bp->link_info.auto_pause;
2809 link_req.force_pause = bp->link_info.force_pause;
2812 rc = bnxt_hwrm_port_phy_cfg(bp, &link_req);
2815 "Set link config failed with rc %d\n", rc);
2823 int bnxt_hwrm_func_qcfg(struct bnxt *bp, uint16_t *mtu)
2825 struct hwrm_func_qcfg_input req = {0};
2826 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
2830 HWRM_PREP(req, FUNC_QCFG, BNXT_USE_CHIMP_MB);
2831 req.fid = rte_cpu_to_le_16(0xffff);
2833 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2835 HWRM_CHECK_RESULT();
2837 /* Hard Coded.. 0xfff VLAN ID mask */
2838 bp->vlan = rte_le_to_cpu_16(resp->vlan) & 0xfff;
2839 flags = rte_le_to_cpu_16(resp->flags);
2840 if (BNXT_PF(bp) && (flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_MULTI_HOST))
2841 bp->flags |= BNXT_FLAG_MULTI_HOST;
2843 if (BNXT_VF(bp) && (flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_TRUSTED_VF)) {
2844 bp->flags |= BNXT_FLAG_TRUSTED_VF_EN;
2845 PMD_DRV_LOG(INFO, "Trusted VF cap enabled\n");
2846 } else if (BNXT_VF(bp) &&
2847 !(flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_TRUSTED_VF)) {
2848 bp->flags &= ~BNXT_FLAG_TRUSTED_VF_EN;
2849 PMD_DRV_LOG(INFO, "Trusted VF cap disabled\n");
2855 switch (resp->port_partition_type) {
2856 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR1_0:
2857 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR1_5:
2858 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR2_0:
2860 bp->port_partition_type = resp->port_partition_type;
2863 bp->port_partition_type = 0;
2872 static void copy_func_cfg_to_qcaps(struct hwrm_func_cfg_input *fcfg,
2873 struct hwrm_func_qcaps_output *qcaps)
2875 qcaps->max_rsscos_ctx = fcfg->num_rsscos_ctxs;
2876 memcpy(qcaps->mac_address, fcfg->dflt_mac_addr,
2877 sizeof(qcaps->mac_address));
2878 qcaps->max_l2_ctxs = fcfg->num_l2_ctxs;
2879 qcaps->max_rx_rings = fcfg->num_rx_rings;
2880 qcaps->max_tx_rings = fcfg->num_tx_rings;
2881 qcaps->max_cmpl_rings = fcfg->num_cmpl_rings;
2882 qcaps->max_stat_ctx = fcfg->num_stat_ctxs;
2884 qcaps->first_vf_id = 0;
2885 qcaps->max_vnics = fcfg->num_vnics;
2886 qcaps->max_decap_records = 0;
2887 qcaps->max_encap_records = 0;
2888 qcaps->max_tx_wm_flows = 0;
2889 qcaps->max_tx_em_flows = 0;
2890 qcaps->max_rx_wm_flows = 0;
2891 qcaps->max_rx_em_flows = 0;
2892 qcaps->max_flow_id = 0;
2893 qcaps->max_mcast_filters = fcfg->num_mcast_filters;
2894 qcaps->max_sp_tx_rings = 0;
2895 qcaps->max_hw_ring_grps = fcfg->num_hw_ring_grps;
2898 static int bnxt_hwrm_pf_func_cfg(struct bnxt *bp, int tx_rings)
2900 struct hwrm_func_cfg_input req = {0};
2901 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2905 enables = HWRM_FUNC_CFG_INPUT_ENABLES_MTU |
2906 HWRM_FUNC_CFG_INPUT_ENABLES_MRU |
2907 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS |
2908 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
2909 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
2910 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_TX_RINGS |
2911 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RX_RINGS |
2912 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_L2_CTXS |
2913 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_VNICS;
2915 if (BNXT_HAS_RING_GRPS(bp)) {
2916 enables |= HWRM_FUNC_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS;
2917 req.num_hw_ring_grps = rte_cpu_to_le_16(bp->max_ring_grps);
2918 } else if (BNXT_HAS_NQ(bp)) {
2919 enables |= HWRM_FUNC_CFG_INPUT_ENABLES_NUM_MSIX;
2920 req.num_msix = rte_cpu_to_le_16(bp->max_nq_rings);
2923 req.flags = rte_cpu_to_le_32(bp->pf.func_cfg_flags);
2924 req.mtu = rte_cpu_to_le_16(BNXT_MAX_MTU);
2925 req.mru = rte_cpu_to_le_16(bp->eth_dev->data->mtu + RTE_ETHER_HDR_LEN +
2926 RTE_ETHER_CRC_LEN + VLAN_TAG_SIZE *
2928 req.num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx);
2929 req.num_stat_ctxs = rte_cpu_to_le_16(bp->max_stat_ctx);
2930 req.num_cmpl_rings = rte_cpu_to_le_16(bp->max_cp_rings);
2931 req.num_tx_rings = rte_cpu_to_le_16(tx_rings);
2932 req.num_rx_rings = rte_cpu_to_le_16(bp->max_rx_rings);
2933 req.num_l2_ctxs = rte_cpu_to_le_16(bp->max_l2_ctx);
2934 req.num_vnics = rte_cpu_to_le_16(bp->max_vnics);
2935 req.fid = rte_cpu_to_le_16(0xffff);
2936 req.enables = rte_cpu_to_le_32(enables);
2938 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
2940 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2942 HWRM_CHECK_RESULT();
2948 static void populate_vf_func_cfg_req(struct bnxt *bp,
2949 struct hwrm_func_cfg_input *req,
2952 req->enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_MTU |
2953 HWRM_FUNC_CFG_INPUT_ENABLES_MRU |
2954 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS |
2955 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
2956 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
2957 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_TX_RINGS |
2958 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RX_RINGS |
2959 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_L2_CTXS |
2960 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_VNICS |
2961 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS);
2963 req->mtu = rte_cpu_to_le_16(bp->eth_dev->data->mtu + RTE_ETHER_HDR_LEN +
2964 RTE_ETHER_CRC_LEN + VLAN_TAG_SIZE *
2966 req->mru = rte_cpu_to_le_16(bp->eth_dev->data->mtu + RTE_ETHER_HDR_LEN +
2967 RTE_ETHER_CRC_LEN + VLAN_TAG_SIZE *
2969 req->num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx /
2971 req->num_stat_ctxs = rte_cpu_to_le_16(bp->max_stat_ctx / (num_vfs + 1));
2972 req->num_cmpl_rings = rte_cpu_to_le_16(bp->max_cp_rings /
2974 req->num_tx_rings = rte_cpu_to_le_16(bp->max_tx_rings / (num_vfs + 1));
2975 req->num_rx_rings = rte_cpu_to_le_16(bp->max_rx_rings / (num_vfs + 1));
2976 req->num_l2_ctxs = rte_cpu_to_le_16(bp->max_l2_ctx / (num_vfs + 1));
2977 /* TODO: For now, do not support VMDq/RFS on VFs. */
2978 req->num_vnics = rte_cpu_to_le_16(1);
2979 req->num_hw_ring_grps = rte_cpu_to_le_16(bp->max_ring_grps /
2983 static void add_random_mac_if_needed(struct bnxt *bp,
2984 struct hwrm_func_cfg_input *cfg_req,
2987 struct rte_ether_addr mac;
2989 if (bnxt_hwrm_func_qcfg_vf_default_mac(bp, vf, &mac))
2992 if (memcmp(mac.addr_bytes, "\x00\x00\x00\x00\x00", 6) == 0) {
2994 rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
2995 rte_eth_random_addr(cfg_req->dflt_mac_addr);
2996 bp->pf.vf_info[vf].random_mac = true;
2998 memcpy(cfg_req->dflt_mac_addr, mac.addr_bytes,
2999 RTE_ETHER_ADDR_LEN);
3003 static void reserve_resources_from_vf(struct bnxt *bp,
3004 struct hwrm_func_cfg_input *cfg_req,
3007 struct hwrm_func_qcaps_input req = {0};
3008 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
3011 /* Get the actual allocated values now */
3012 HWRM_PREP(req, FUNC_QCAPS, BNXT_USE_CHIMP_MB);
3013 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3014 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3017 PMD_DRV_LOG(ERR, "hwrm_func_qcaps failed rc:%d\n", rc);
3018 copy_func_cfg_to_qcaps(cfg_req, resp);
3019 } else if (resp->error_code) {
3020 rc = rte_le_to_cpu_16(resp->error_code);
3021 PMD_DRV_LOG(ERR, "hwrm_func_qcaps error %d\n", rc);
3022 copy_func_cfg_to_qcaps(cfg_req, resp);
3025 bp->max_rsscos_ctx -= rte_le_to_cpu_16(resp->max_rsscos_ctx);
3026 bp->max_stat_ctx -= rte_le_to_cpu_16(resp->max_stat_ctx);
3027 bp->max_cp_rings -= rte_le_to_cpu_16(resp->max_cmpl_rings);
3028 bp->max_tx_rings -= rte_le_to_cpu_16(resp->max_tx_rings);
3029 bp->max_rx_rings -= rte_le_to_cpu_16(resp->max_rx_rings);
3030 bp->max_l2_ctx -= rte_le_to_cpu_16(resp->max_l2_ctxs);
3032 * TODO: While not supporting VMDq with VFs, max_vnics is always
3033 * forced to 1 in this case
3035 //bp->max_vnics -= rte_le_to_cpu_16(esp->max_vnics);
3036 bp->max_ring_grps -= rte_le_to_cpu_16(resp->max_hw_ring_grps);
3041 int bnxt_hwrm_func_qcfg_current_vf_vlan(struct bnxt *bp, int vf)
3043 struct hwrm_func_qcfg_input req = {0};
3044 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
3047 /* Check for zero MAC address */
3048 HWRM_PREP(req, FUNC_QCFG, BNXT_USE_CHIMP_MB);
3049 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3050 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3051 HWRM_CHECK_RESULT();
3052 rc = rte_le_to_cpu_16(resp->vlan);
3059 static int update_pf_resource_max(struct bnxt *bp)
3061 struct hwrm_func_qcfg_input req = {0};
3062 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
3065 /* And copy the allocated numbers into the pf struct */
3066 HWRM_PREP(req, FUNC_QCFG, BNXT_USE_CHIMP_MB);
3067 req.fid = rte_cpu_to_le_16(0xffff);
3068 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3069 HWRM_CHECK_RESULT();
3071 /* Only TX ring value reflects actual allocation? TODO */
3072 bp->max_tx_rings = rte_le_to_cpu_16(resp->alloc_tx_rings);
3073 bp->pf.evb_mode = resp->evb_mode;
3080 int bnxt_hwrm_allocate_pf_only(struct bnxt *bp)
3085 PMD_DRV_LOG(ERR, "Attempt to allcoate VFs on a VF!\n");
3089 rc = bnxt_hwrm_func_qcaps(bp);
3093 bp->pf.func_cfg_flags &=
3094 ~(HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE |
3095 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE);
3096 bp->pf.func_cfg_flags |=
3097 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE;
3098 rc = bnxt_hwrm_pf_func_cfg(bp, bp->max_tx_rings);
3099 rc = __bnxt_hwrm_func_qcaps(bp);
3103 int bnxt_hwrm_allocate_vfs(struct bnxt *bp, int num_vfs)
3105 struct hwrm_func_cfg_input req = {0};
3106 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3113 PMD_DRV_LOG(ERR, "Attempt to allcoate VFs on a VF!\n");
3117 rc = bnxt_hwrm_func_qcaps(bp);
3122 bp->pf.active_vfs = num_vfs;
3125 * First, configure the PF to only use one TX ring. This ensures that
3126 * there are enough rings for all VFs.
3128 * If we don't do this, when we call func_alloc() later, we will lock
3129 * extra rings to the PF that won't be available during func_cfg() of
3132 * This has been fixed with firmware versions above 20.6.54
3134 bp->pf.func_cfg_flags &=
3135 ~(HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE |
3136 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE);
3137 bp->pf.func_cfg_flags |=
3138 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE;
3139 rc = bnxt_hwrm_pf_func_cfg(bp, 1);
3144 * Now, create and register a buffer to hold forwarded VF requests
3146 req_buf_sz = num_vfs * HWRM_MAX_REQ_LEN;
3147 bp->pf.vf_req_buf = rte_malloc("bnxt_vf_fwd", req_buf_sz,
3148 page_roundup(num_vfs * HWRM_MAX_REQ_LEN));
3149 if (bp->pf.vf_req_buf == NULL) {
3153 for (sz = 0; sz < req_buf_sz; sz += getpagesize())
3154 rte_mem_lock_page(((char *)bp->pf.vf_req_buf) + sz);
3155 for (i = 0; i < num_vfs; i++)
3156 bp->pf.vf_info[i].req_buf = ((char *)bp->pf.vf_req_buf) +
3157 (i * HWRM_MAX_REQ_LEN);
3159 rc = bnxt_hwrm_func_buf_rgtr(bp);
3163 populate_vf_func_cfg_req(bp, &req, num_vfs);
3165 bp->pf.active_vfs = 0;
3166 for (i = 0; i < num_vfs; i++) {
3167 add_random_mac_if_needed(bp, &req, i);
3169 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
3170 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[i].func_cfg_flags);
3171 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[i].fid);
3172 rc = bnxt_hwrm_send_message(bp,
3177 /* Clear enable flag for next pass */
3178 req.enables &= ~rte_cpu_to_le_32(
3179 HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
3181 if (rc || resp->error_code) {
3183 "Failed to initizlie VF %d\n", i);
3185 "Not all VFs available. (%d, %d)\n",
3186 rc, resp->error_code);
3193 reserve_resources_from_vf(bp, &req, i);
3194 bp->pf.active_vfs++;
3195 bnxt_hwrm_func_clr_stats(bp, bp->pf.vf_info[i].fid);
3199 * Now configure the PF to use "the rest" of the resources
3200 * We're using STD_TX_RING_MODE here though which will limit the TX
3201 * rings. This will allow QoS to function properly. Not setting this
3202 * will cause PF rings to break bandwidth settings.
3204 rc = bnxt_hwrm_pf_func_cfg(bp, bp->max_tx_rings);
3208 rc = update_pf_resource_max(bp);
3215 bnxt_hwrm_func_buf_unrgtr(bp);
3219 int bnxt_hwrm_pf_evb_mode(struct bnxt *bp)
3221 struct hwrm_func_cfg_input req = {0};
3222 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3225 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
3227 req.fid = rte_cpu_to_le_16(0xffff);
3228 req.enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_EVB_MODE);
3229 req.evb_mode = bp->pf.evb_mode;
3231 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3232 HWRM_CHECK_RESULT();
3238 int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt *bp, uint16_t port,
3239 uint8_t tunnel_type)
3241 struct hwrm_tunnel_dst_port_alloc_input req = {0};
3242 struct hwrm_tunnel_dst_port_alloc_output *resp = bp->hwrm_cmd_resp_addr;
3245 HWRM_PREP(req, TUNNEL_DST_PORT_ALLOC, BNXT_USE_CHIMP_MB);
3246 req.tunnel_type = tunnel_type;
3247 req.tunnel_dst_port_val = port;
3248 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3249 HWRM_CHECK_RESULT();
3251 switch (tunnel_type) {
3252 case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_VXLAN:
3253 bp->vxlan_fw_dst_port_id = resp->tunnel_dst_port_id;
3254 bp->vxlan_port = port;
3256 case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_GENEVE:
3257 bp->geneve_fw_dst_port_id = resp->tunnel_dst_port_id;
3258 bp->geneve_port = port;
3269 int bnxt_hwrm_tunnel_dst_port_free(struct bnxt *bp, uint16_t port,
3270 uint8_t tunnel_type)
3272 struct hwrm_tunnel_dst_port_free_input req = {0};
3273 struct hwrm_tunnel_dst_port_free_output *resp = bp->hwrm_cmd_resp_addr;
3276 HWRM_PREP(req, TUNNEL_DST_PORT_FREE, BNXT_USE_CHIMP_MB);
3278 req.tunnel_type = tunnel_type;
3279 req.tunnel_dst_port_id = rte_cpu_to_be_16(port);
3280 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3282 HWRM_CHECK_RESULT();
3288 int bnxt_hwrm_func_cfg_vf_set_flags(struct bnxt *bp, uint16_t vf,
3291 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3292 struct hwrm_func_cfg_input req = {0};
3295 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
3297 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3298 req.flags = rte_cpu_to_le_32(flags);
3299 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3301 HWRM_CHECK_RESULT();
3307 void vf_vnic_set_rxmask_cb(struct bnxt_vnic_info *vnic, void *flagp)
3309 uint32_t *flag = flagp;
3311 vnic->flags = *flag;
3314 int bnxt_set_rx_mask_no_vlan(struct bnxt *bp, struct bnxt_vnic_info *vnic)
3316 return bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
3319 int bnxt_hwrm_func_buf_rgtr(struct bnxt *bp)
3322 struct hwrm_func_buf_rgtr_input req = {.req_type = 0 };
3323 struct hwrm_func_buf_rgtr_output *resp = bp->hwrm_cmd_resp_addr;
3325 HWRM_PREP(req, FUNC_BUF_RGTR, BNXT_USE_CHIMP_MB);
3327 req.req_buf_num_pages = rte_cpu_to_le_16(1);
3328 req.req_buf_page_size = rte_cpu_to_le_16(
3329 page_getenum(bp->pf.active_vfs * HWRM_MAX_REQ_LEN));
3330 req.req_buf_len = rte_cpu_to_le_16(HWRM_MAX_REQ_LEN);
3331 req.req_buf_page_addr0 =
3332 rte_cpu_to_le_64(rte_mem_virt2iova(bp->pf.vf_req_buf));
3333 if (req.req_buf_page_addr0 == RTE_BAD_IOVA) {
3335 "unable to map buffer address to physical memory\n");
3339 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3341 HWRM_CHECK_RESULT();
3347 int bnxt_hwrm_func_buf_unrgtr(struct bnxt *bp)
3350 struct hwrm_func_buf_unrgtr_input req = {.req_type = 0 };
3351 struct hwrm_func_buf_unrgtr_output *resp = bp->hwrm_cmd_resp_addr;
3353 if (!(BNXT_PF(bp) && bp->pdev->max_vfs))
3356 HWRM_PREP(req, FUNC_BUF_UNRGTR, BNXT_USE_CHIMP_MB);
3358 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3360 HWRM_CHECK_RESULT();
3366 int bnxt_hwrm_func_cfg_def_cp(struct bnxt *bp)
3368 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3369 struct hwrm_func_cfg_input req = {0};
3372 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
3374 req.fid = rte_cpu_to_le_16(0xffff);
3375 req.flags = rte_cpu_to_le_32(bp->pf.func_cfg_flags);
3376 req.enables = rte_cpu_to_le_32(
3377 HWRM_FUNC_CFG_INPUT_ENABLES_ASYNC_EVENT_CR);
3378 req.async_event_cr = rte_cpu_to_le_16(
3379 bp->async_cp_ring->cp_ring_struct->fw_ring_id);
3380 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3382 HWRM_CHECK_RESULT();
3388 int bnxt_hwrm_vf_func_cfg_def_cp(struct bnxt *bp)
3390 struct hwrm_func_vf_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3391 struct hwrm_func_vf_cfg_input req = {0};
3394 HWRM_PREP(req, FUNC_VF_CFG, BNXT_USE_CHIMP_MB);
3396 req.enables = rte_cpu_to_le_32(
3397 HWRM_FUNC_VF_CFG_INPUT_ENABLES_ASYNC_EVENT_CR);
3398 req.async_event_cr = rte_cpu_to_le_16(
3399 bp->async_cp_ring->cp_ring_struct->fw_ring_id);
3400 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3402 HWRM_CHECK_RESULT();
3408 int bnxt_hwrm_set_default_vlan(struct bnxt *bp, int vf, uint8_t is_vf)
3410 struct hwrm_func_cfg_input req = {0};
3411 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3412 uint16_t dflt_vlan, fid;
3413 uint32_t func_cfg_flags;
3416 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
3419 dflt_vlan = bp->pf.vf_info[vf].dflt_vlan;
3420 fid = bp->pf.vf_info[vf].fid;
3421 func_cfg_flags = bp->pf.vf_info[vf].func_cfg_flags;
3423 fid = rte_cpu_to_le_16(0xffff);
3424 func_cfg_flags = bp->pf.func_cfg_flags;
3425 dflt_vlan = bp->vlan;
3428 req.flags = rte_cpu_to_le_32(func_cfg_flags);
3429 req.fid = rte_cpu_to_le_16(fid);
3430 req.enables |= rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_VLAN);
3431 req.dflt_vlan = rte_cpu_to_le_16(dflt_vlan);
3433 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3435 HWRM_CHECK_RESULT();
3441 int bnxt_hwrm_func_bw_cfg(struct bnxt *bp, uint16_t vf,
3442 uint16_t max_bw, uint16_t enables)
3444 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3445 struct hwrm_func_cfg_input req = {0};
3448 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
3450 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3451 req.enables |= rte_cpu_to_le_32(enables);
3452 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[vf].func_cfg_flags);
3453 req.max_bw = rte_cpu_to_le_32(max_bw);
3454 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3456 HWRM_CHECK_RESULT();
3462 int bnxt_hwrm_set_vf_vlan(struct bnxt *bp, int vf)
3464 struct hwrm_func_cfg_input req = {0};
3465 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3468 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
3470 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[vf].func_cfg_flags);
3471 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3472 req.enables |= rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_VLAN);
3473 req.dflt_vlan = rte_cpu_to_le_16(bp->pf.vf_info[vf].dflt_vlan);
3475 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3477 HWRM_CHECK_RESULT();
3483 int bnxt_hwrm_set_async_event_cr(struct bnxt *bp)
3488 rc = bnxt_hwrm_func_cfg_def_cp(bp);
3490 rc = bnxt_hwrm_vf_func_cfg_def_cp(bp);
3495 int bnxt_hwrm_reject_fwd_resp(struct bnxt *bp, uint16_t target_id,
3496 void *encaped, size_t ec_size)
3499 struct hwrm_reject_fwd_resp_input req = {.req_type = 0};
3500 struct hwrm_reject_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr;
3502 if (ec_size > sizeof(req.encap_request))
3505 HWRM_PREP(req, REJECT_FWD_RESP, BNXT_USE_CHIMP_MB);
3507 req.encap_resp_target_id = rte_cpu_to_le_16(target_id);
3508 memcpy(req.encap_request, encaped, ec_size);
3510 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3512 HWRM_CHECK_RESULT();
3518 int bnxt_hwrm_func_qcfg_vf_default_mac(struct bnxt *bp, uint16_t vf,
3519 struct rte_ether_addr *mac)
3521 struct hwrm_func_qcfg_input req = {0};
3522 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
3525 HWRM_PREP(req, FUNC_QCFG, BNXT_USE_CHIMP_MB);
3527 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3528 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3530 HWRM_CHECK_RESULT();
3532 memcpy(mac->addr_bytes, resp->mac_address, RTE_ETHER_ADDR_LEN);
3539 int bnxt_hwrm_exec_fwd_resp(struct bnxt *bp, uint16_t target_id,
3540 void *encaped, size_t ec_size)
3543 struct hwrm_exec_fwd_resp_input req = {.req_type = 0};
3544 struct hwrm_exec_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr;
3546 if (ec_size > sizeof(req.encap_request))
3549 HWRM_PREP(req, EXEC_FWD_RESP, BNXT_USE_CHIMP_MB);
3551 req.encap_resp_target_id = rte_cpu_to_le_16(target_id);
3552 memcpy(req.encap_request, encaped, ec_size);
3554 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3556 HWRM_CHECK_RESULT();
3562 int bnxt_hwrm_ctx_qstats(struct bnxt *bp, uint32_t cid, int idx,
3563 struct rte_eth_stats *stats, uint8_t rx)
3566 struct hwrm_stat_ctx_query_input req = {.req_type = 0};
3567 struct hwrm_stat_ctx_query_output *resp = bp->hwrm_cmd_resp_addr;
3569 HWRM_PREP(req, STAT_CTX_QUERY, BNXT_USE_CHIMP_MB);
3571 req.stat_ctx_id = rte_cpu_to_le_32(cid);
3573 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3575 HWRM_CHECK_RESULT();
3578 stats->q_ipackets[idx] = rte_le_to_cpu_64(resp->rx_ucast_pkts);
3579 stats->q_ipackets[idx] += rte_le_to_cpu_64(resp->rx_mcast_pkts);
3580 stats->q_ipackets[idx] += rte_le_to_cpu_64(resp->rx_bcast_pkts);
3581 stats->q_ibytes[idx] = rte_le_to_cpu_64(resp->rx_ucast_bytes);
3582 stats->q_ibytes[idx] += rte_le_to_cpu_64(resp->rx_mcast_bytes);
3583 stats->q_ibytes[idx] += rte_le_to_cpu_64(resp->rx_bcast_bytes);
3584 stats->q_errors[idx] = rte_le_to_cpu_64(resp->rx_err_pkts);
3585 stats->q_errors[idx] += rte_le_to_cpu_64(resp->rx_drop_pkts);
3587 stats->q_opackets[idx] = rte_le_to_cpu_64(resp->tx_ucast_pkts);
3588 stats->q_opackets[idx] += rte_le_to_cpu_64(resp->tx_mcast_pkts);
3589 stats->q_opackets[idx] += rte_le_to_cpu_64(resp->tx_bcast_pkts);
3590 stats->q_obytes[idx] = rte_le_to_cpu_64(resp->tx_ucast_bytes);
3591 stats->q_obytes[idx] += rte_le_to_cpu_64(resp->tx_mcast_bytes);
3592 stats->q_obytes[idx] += rte_le_to_cpu_64(resp->tx_bcast_bytes);
3601 int bnxt_hwrm_port_qstats(struct bnxt *bp)
3603 struct hwrm_port_qstats_input req = {0};
3604 struct hwrm_port_qstats_output *resp = bp->hwrm_cmd_resp_addr;
3605 struct bnxt_pf_info *pf = &bp->pf;
3608 HWRM_PREP(req, PORT_QSTATS, BNXT_USE_CHIMP_MB);
3610 req.port_id = rte_cpu_to_le_16(pf->port_id);
3611 req.tx_stat_host_addr = rte_cpu_to_le_64(bp->hw_tx_port_stats_map);
3612 req.rx_stat_host_addr = rte_cpu_to_le_64(bp->hw_rx_port_stats_map);
3613 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3615 HWRM_CHECK_RESULT();
3621 int bnxt_hwrm_port_clr_stats(struct bnxt *bp)
3623 struct hwrm_port_clr_stats_input req = {0};
3624 struct hwrm_port_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
3625 struct bnxt_pf_info *pf = &bp->pf;
3628 /* Not allowed on NS2 device, NPAR, MultiHost, VF */
3629 if (!(bp->flags & BNXT_FLAG_PORT_STATS) || BNXT_VF(bp) ||
3630 BNXT_NPAR(bp) || BNXT_MH(bp) || BNXT_TOTAL_VFS(bp))
3633 HWRM_PREP(req, PORT_CLR_STATS, BNXT_USE_CHIMP_MB);
3635 req.port_id = rte_cpu_to_le_16(pf->port_id);
3636 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3638 HWRM_CHECK_RESULT();
3644 int bnxt_hwrm_port_led_qcaps(struct bnxt *bp)
3646 struct hwrm_port_led_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
3647 struct hwrm_port_led_qcaps_input req = {0};
3653 HWRM_PREP(req, PORT_LED_QCAPS, BNXT_USE_CHIMP_MB);
3654 req.port_id = bp->pf.port_id;
3655 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3657 HWRM_CHECK_RESULT();
3659 if (resp->num_leds > 0 && resp->num_leds < BNXT_MAX_LED) {
3662 bp->num_leds = resp->num_leds;
3663 memcpy(bp->leds, &resp->led0_id,
3664 sizeof(bp->leds[0]) * bp->num_leds);
3665 for (i = 0; i < bp->num_leds; i++) {
3666 struct bnxt_led_info *led = &bp->leds[i];
3668 uint16_t caps = led->led_state_caps;
3670 if (!led->led_group_id ||
3671 !BNXT_LED_ALT_BLINK_CAP(caps)) {
3683 int bnxt_hwrm_port_led_cfg(struct bnxt *bp, bool led_on)
3685 struct hwrm_port_led_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3686 struct hwrm_port_led_cfg_input req = {0};
3687 struct bnxt_led_cfg *led_cfg;
3688 uint8_t led_state = HWRM_PORT_LED_QCFG_OUTPUT_LED0_STATE_DEFAULT;
3689 uint16_t duration = 0;
3692 if (!bp->num_leds || BNXT_VF(bp))
3695 HWRM_PREP(req, PORT_LED_CFG, BNXT_USE_CHIMP_MB);
3698 led_state = HWRM_PORT_LED_CFG_INPUT_LED0_STATE_BLINKALT;
3699 duration = rte_cpu_to_le_16(500);
3701 req.port_id = bp->pf.port_id;
3702 req.num_leds = bp->num_leds;
3703 led_cfg = (struct bnxt_led_cfg *)&req.led0_id;
3704 for (i = 0; i < bp->num_leds; i++, led_cfg++) {
3705 req.enables |= BNXT_LED_DFLT_ENABLES(i);
3706 led_cfg->led_id = bp->leds[i].led_id;
3707 led_cfg->led_state = led_state;
3708 led_cfg->led_blink_on = duration;
3709 led_cfg->led_blink_off = duration;
3710 led_cfg->led_group_id = bp->leds[i].led_group_id;
3713 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3715 HWRM_CHECK_RESULT();
3721 int bnxt_hwrm_nvm_get_dir_info(struct bnxt *bp, uint32_t *entries,
3725 struct hwrm_nvm_get_dir_info_input req = {0};
3726 struct hwrm_nvm_get_dir_info_output *resp = bp->hwrm_cmd_resp_addr;
3728 HWRM_PREP(req, NVM_GET_DIR_INFO, BNXT_USE_CHIMP_MB);
3730 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3732 HWRM_CHECK_RESULT();
3734 *entries = rte_le_to_cpu_32(resp->entries);
3735 *length = rte_le_to_cpu_32(resp->entry_length);
3741 int bnxt_get_nvram_directory(struct bnxt *bp, uint32_t len, uint8_t *data)
3744 uint32_t dir_entries;
3745 uint32_t entry_length;
3748 rte_iova_t dma_handle;
3749 struct hwrm_nvm_get_dir_entries_input req = {0};
3750 struct hwrm_nvm_get_dir_entries_output *resp = bp->hwrm_cmd_resp_addr;
3752 rc = bnxt_hwrm_nvm_get_dir_info(bp, &dir_entries, &entry_length);
3756 *data++ = dir_entries;
3757 *data++ = entry_length;
3759 memset(data, 0xff, len);
3761 buflen = dir_entries * entry_length;
3762 buf = rte_malloc("nvm_dir", buflen, 0);
3763 rte_mem_lock_page(buf);
3766 dma_handle = rte_mem_virt2iova(buf);
3767 if (dma_handle == RTE_BAD_IOVA) {
3769 "unable to map response address to physical memory\n");
3772 HWRM_PREP(req, NVM_GET_DIR_ENTRIES, BNXT_USE_CHIMP_MB);
3773 req.host_dest_addr = rte_cpu_to_le_64(dma_handle);
3774 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3777 memcpy(data, buf, len > buflen ? buflen : len);
3780 HWRM_CHECK_RESULT();
3786 int bnxt_hwrm_get_nvram_item(struct bnxt *bp, uint32_t index,
3787 uint32_t offset, uint32_t length,
3792 rte_iova_t dma_handle;
3793 struct hwrm_nvm_read_input req = {0};
3794 struct hwrm_nvm_read_output *resp = bp->hwrm_cmd_resp_addr;
3796 buf = rte_malloc("nvm_item", length, 0);
3797 rte_mem_lock_page(buf);
3801 dma_handle = rte_mem_virt2iova(buf);
3802 if (dma_handle == RTE_BAD_IOVA) {
3804 "unable to map response address to physical memory\n");
3807 HWRM_PREP(req, NVM_READ, BNXT_USE_CHIMP_MB);
3808 req.host_dest_addr = rte_cpu_to_le_64(dma_handle);
3809 req.dir_idx = rte_cpu_to_le_16(index);
3810 req.offset = rte_cpu_to_le_32(offset);
3811 req.len = rte_cpu_to_le_32(length);
3812 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3814 memcpy(data, buf, length);
3817 HWRM_CHECK_RESULT();
3823 int bnxt_hwrm_erase_nvram_directory(struct bnxt *bp, uint8_t index)
3826 struct hwrm_nvm_erase_dir_entry_input req = {0};
3827 struct hwrm_nvm_erase_dir_entry_output *resp = bp->hwrm_cmd_resp_addr;
3829 HWRM_PREP(req, NVM_ERASE_DIR_ENTRY, BNXT_USE_CHIMP_MB);
3830 req.dir_idx = rte_cpu_to_le_16(index);
3831 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3832 HWRM_CHECK_RESULT();
3839 int bnxt_hwrm_flash_nvram(struct bnxt *bp, uint16_t dir_type,
3840 uint16_t dir_ordinal, uint16_t dir_ext,
3841 uint16_t dir_attr, const uint8_t *data,
3845 struct hwrm_nvm_write_input req = {0};
3846 struct hwrm_nvm_write_output *resp = bp->hwrm_cmd_resp_addr;
3847 rte_iova_t dma_handle;
3850 buf = rte_malloc("nvm_write", data_len, 0);
3851 rte_mem_lock_page(buf);
3855 dma_handle = rte_mem_virt2iova(buf);
3856 if (dma_handle == RTE_BAD_IOVA) {
3858 "unable to map response address to physical memory\n");
3861 memcpy(buf, data, data_len);
3863 HWRM_PREP(req, NVM_WRITE, BNXT_USE_CHIMP_MB);
3865 req.dir_type = rte_cpu_to_le_16(dir_type);
3866 req.dir_ordinal = rte_cpu_to_le_16(dir_ordinal);
3867 req.dir_ext = rte_cpu_to_le_16(dir_ext);
3868 req.dir_attr = rte_cpu_to_le_16(dir_attr);
3869 req.dir_data_length = rte_cpu_to_le_32(data_len);
3870 req.host_src_addr = rte_cpu_to_le_64(dma_handle);
3872 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3875 HWRM_CHECK_RESULT();
3882 bnxt_vnic_count(struct bnxt_vnic_info *vnic __rte_unused, void *cbdata)
3884 uint32_t *count = cbdata;
3886 *count = *count + 1;
3889 static int bnxt_vnic_count_hwrm_stub(struct bnxt *bp __rte_unused,
3890 struct bnxt_vnic_info *vnic __rte_unused)
3895 int bnxt_vf_vnic_count(struct bnxt *bp, uint16_t vf)
3899 bnxt_hwrm_func_vf_vnic_query_and_config(bp, vf, bnxt_vnic_count,
3900 &count, bnxt_vnic_count_hwrm_stub);
3905 static int bnxt_hwrm_func_vf_vnic_query(struct bnxt *bp, uint16_t vf,
3908 struct hwrm_func_vf_vnic_ids_query_input req = {0};
3909 struct hwrm_func_vf_vnic_ids_query_output *resp =
3910 bp->hwrm_cmd_resp_addr;
3913 /* First query all VNIC ids */
3914 HWRM_PREP(req, FUNC_VF_VNIC_IDS_QUERY, BNXT_USE_CHIMP_MB);
3916 req.vf_id = rte_cpu_to_le_16(bp->pf.first_vf_id + vf);
3917 req.max_vnic_id_cnt = rte_cpu_to_le_32(bp->pf.total_vnics);
3918 req.vnic_id_tbl_addr = rte_cpu_to_le_64(rte_mem_virt2iova(vnic_ids));
3920 if (req.vnic_id_tbl_addr == RTE_BAD_IOVA) {
3923 "unable to map VNIC ID table address to physical memory\n");
3926 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3927 HWRM_CHECK_RESULT();
3928 rc = rte_le_to_cpu_32(resp->vnic_id_cnt);
3936 * This function queries the VNIC IDs for a specified VF. It then calls
3937 * the vnic_cb to update the necessary field in vnic_info with cbdata.
3938 * Then it calls the hwrm_cb function to program this new vnic configuration.
3940 int bnxt_hwrm_func_vf_vnic_query_and_config(struct bnxt *bp, uint16_t vf,
3941 void (*vnic_cb)(struct bnxt_vnic_info *, void *), void *cbdata,
3942 int (*hwrm_cb)(struct bnxt *bp, struct bnxt_vnic_info *vnic))
3944 struct bnxt_vnic_info vnic;
3946 int i, num_vnic_ids;
3951 /* First query all VNIC ids */
3952 vnic_id_sz = bp->pf.total_vnics * sizeof(*vnic_ids);
3953 vnic_ids = rte_malloc("bnxt_hwrm_vf_vnic_ids_query", vnic_id_sz,
3954 RTE_CACHE_LINE_SIZE);
3955 if (vnic_ids == NULL)
3958 for (sz = 0; sz < vnic_id_sz; sz += getpagesize())
3959 rte_mem_lock_page(((char *)vnic_ids) + sz);
3961 num_vnic_ids = bnxt_hwrm_func_vf_vnic_query(bp, vf, vnic_ids);
3963 if (num_vnic_ids < 0)
3964 return num_vnic_ids;
3966 /* Retrieve VNIC, update bd_stall then update */
3968 for (i = 0; i < num_vnic_ids; i++) {
3969 memset(&vnic, 0, sizeof(struct bnxt_vnic_info));
3970 vnic.fw_vnic_id = rte_le_to_cpu_16(vnic_ids[i]);
3971 rc = bnxt_hwrm_vnic_qcfg(bp, &vnic, bp->pf.first_vf_id + vf);
3974 if (vnic.mru <= 4) /* Indicates unallocated */
3977 vnic_cb(&vnic, cbdata);
3979 rc = hwrm_cb(bp, &vnic);
3989 int bnxt_hwrm_func_cfg_vf_set_vlan_anti_spoof(struct bnxt *bp, uint16_t vf,
3992 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3993 struct hwrm_func_cfg_input req = {0};
3996 HWRM_PREP(req, FUNC_CFG, BNXT_USE_CHIMP_MB);
3998 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3999 req.enables |= rte_cpu_to_le_32(
4000 HWRM_FUNC_CFG_INPUT_ENABLES_VLAN_ANTISPOOF_MODE);
4001 req.vlan_antispoof_mode = on ?
4002 HWRM_FUNC_CFG_INPUT_VLAN_ANTISPOOF_MODE_VALIDATE_VLAN :
4003 HWRM_FUNC_CFG_INPUT_VLAN_ANTISPOOF_MODE_NOCHECK;
4004 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4006 HWRM_CHECK_RESULT();
4012 int bnxt_hwrm_func_qcfg_vf_dflt_vnic_id(struct bnxt *bp, int vf)
4014 struct bnxt_vnic_info vnic;
4017 int num_vnic_ids, i;
4021 vnic_id_sz = bp->pf.total_vnics * sizeof(*vnic_ids);
4022 vnic_ids = rte_malloc("bnxt_hwrm_vf_vnic_ids_query", vnic_id_sz,
4023 RTE_CACHE_LINE_SIZE);
4024 if (vnic_ids == NULL)
4027 for (sz = 0; sz < vnic_id_sz; sz += getpagesize())
4028 rte_mem_lock_page(((char *)vnic_ids) + sz);
4030 rc = bnxt_hwrm_func_vf_vnic_query(bp, vf, vnic_ids);
4036 * Loop through to find the default VNIC ID.
4037 * TODO: The easier way would be to obtain the resp->dflt_vnic_id
4038 * by sending the hwrm_func_qcfg command to the firmware.
4040 for (i = 0; i < num_vnic_ids; i++) {
4041 memset(&vnic, 0, sizeof(struct bnxt_vnic_info));
4042 vnic.fw_vnic_id = rte_le_to_cpu_16(vnic_ids[i]);
4043 rc = bnxt_hwrm_vnic_qcfg(bp, &vnic,
4044 bp->pf.first_vf_id + vf);
4047 if (vnic.func_default) {
4049 return vnic.fw_vnic_id;
4052 /* Could not find a default VNIC. */
4053 PMD_DRV_LOG(ERR, "No default VNIC\n");
4059 int bnxt_hwrm_set_em_filter(struct bnxt *bp,
4061 struct bnxt_filter_info *filter)
4064 struct hwrm_cfa_em_flow_alloc_input req = {.req_type = 0 };
4065 struct hwrm_cfa_em_flow_alloc_output *resp = bp->hwrm_cmd_resp_addr;
4066 uint32_t enables = 0;
4068 if (filter->fw_em_filter_id != UINT64_MAX)
4069 bnxt_hwrm_clear_em_filter(bp, filter);
4071 HWRM_PREP(req, CFA_EM_FLOW_ALLOC, BNXT_USE_KONG(bp));
4073 req.flags = rte_cpu_to_le_32(filter->flags);
4075 enables = filter->enables |
4076 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_ID;
4077 req.dst_id = rte_cpu_to_le_16(dst_id);
4079 if (filter->ip_addr_type) {
4080 req.ip_addr_type = filter->ip_addr_type;
4081 enables |= HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IPADDR_TYPE;
4084 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_L2_FILTER_ID)
4085 req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
4087 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_MACADDR)
4088 memcpy(req.src_macaddr, filter->src_macaddr,
4089 RTE_ETHER_ADDR_LEN);
4091 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_MACADDR)
4092 memcpy(req.dst_macaddr, filter->dst_macaddr,
4093 RTE_ETHER_ADDR_LEN);
4095 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_OVLAN_VID)
4096 req.ovlan_vid = filter->l2_ovlan;
4098 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IVLAN_VID)
4099 req.ivlan_vid = filter->l2_ivlan;
4101 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_ETHERTYPE)
4102 req.ethertype = rte_cpu_to_be_16(filter->ethertype);
4104 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IP_PROTOCOL)
4105 req.ip_protocol = filter->ip_protocol;
4107 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_IPADDR)
4108 req.src_ipaddr[0] = rte_cpu_to_be_32(filter->src_ipaddr[0]);
4110 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_IPADDR)
4111 req.dst_ipaddr[0] = rte_cpu_to_be_32(filter->dst_ipaddr[0]);
4113 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_PORT)
4114 req.src_port = rte_cpu_to_be_16(filter->src_port);
4116 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_PORT)
4117 req.dst_port = rte_cpu_to_be_16(filter->dst_port);
4119 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_MIRROR_VNIC_ID)
4120 req.mirror_vnic_id = filter->mirror_vnic_id;
4122 req.enables = rte_cpu_to_le_32(enables);
4124 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
4126 HWRM_CHECK_RESULT();
4128 filter->fw_em_filter_id = rte_le_to_cpu_64(resp->em_filter_id);
4134 int bnxt_hwrm_clear_em_filter(struct bnxt *bp, struct bnxt_filter_info *filter)
4137 struct hwrm_cfa_em_flow_free_input req = {.req_type = 0 };
4138 struct hwrm_cfa_em_flow_free_output *resp = bp->hwrm_cmd_resp_addr;
4140 if (filter->fw_em_filter_id == UINT64_MAX)
4143 PMD_DRV_LOG(ERR, "Clear EM filter\n");
4144 HWRM_PREP(req, CFA_EM_FLOW_FREE, BNXT_USE_KONG(bp));
4146 req.em_filter_id = rte_cpu_to_le_64(filter->fw_em_filter_id);
4148 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
4150 HWRM_CHECK_RESULT();
4153 filter->fw_em_filter_id = UINT64_MAX;
4154 filter->fw_l2_filter_id = UINT64_MAX;
4159 int bnxt_hwrm_set_ntuple_filter(struct bnxt *bp,
4161 struct bnxt_filter_info *filter)
4164 struct hwrm_cfa_ntuple_filter_alloc_input req = {.req_type = 0 };
4165 struct hwrm_cfa_ntuple_filter_alloc_output *resp =
4166 bp->hwrm_cmd_resp_addr;
4167 uint32_t enables = 0;
4169 if (filter->fw_ntuple_filter_id != UINT64_MAX)
4170 bnxt_hwrm_clear_ntuple_filter(bp, filter);
4172 HWRM_PREP(req, CFA_NTUPLE_FILTER_ALLOC, BNXT_USE_CHIMP_MB);
4174 req.flags = rte_cpu_to_le_32(filter->flags);
4176 enables = filter->enables |
4177 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_ID;
4178 req.dst_id = rte_cpu_to_le_16(dst_id);
4181 if (filter->ip_addr_type) {
4182 req.ip_addr_type = filter->ip_addr_type;
4184 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_IPADDR_TYPE;
4187 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_L2_FILTER_ID)
4188 req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
4190 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_MACADDR)
4191 memcpy(req.src_macaddr, filter->src_macaddr,
4192 RTE_ETHER_ADDR_LEN);
4194 //HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_MACADDR)
4195 //memcpy(req.dst_macaddr, filter->dst_macaddr,
4196 //RTE_ETHER_ADDR_LEN);
4198 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_ETHERTYPE)
4199 req.ethertype = rte_cpu_to_be_16(filter->ethertype);
4201 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_IP_PROTOCOL)
4202 req.ip_protocol = filter->ip_protocol;
4204 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_IPADDR)
4205 req.src_ipaddr[0] = rte_cpu_to_le_32(filter->src_ipaddr[0]);
4207 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_IPADDR_MASK)
4208 req.src_ipaddr_mask[0] =
4209 rte_cpu_to_le_32(filter->src_ipaddr_mask[0]);
4211 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_IPADDR)
4212 req.dst_ipaddr[0] = rte_cpu_to_le_32(filter->dst_ipaddr[0]);
4214 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_IPADDR_MASK)
4215 req.dst_ipaddr_mask[0] =
4216 rte_cpu_to_be_32(filter->dst_ipaddr_mask[0]);
4218 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_PORT)
4219 req.src_port = rte_cpu_to_le_16(filter->src_port);
4221 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_PORT_MASK)
4222 req.src_port_mask = rte_cpu_to_le_16(filter->src_port_mask);
4224 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_PORT)
4225 req.dst_port = rte_cpu_to_le_16(filter->dst_port);
4227 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_PORT_MASK)
4228 req.dst_port_mask = rte_cpu_to_le_16(filter->dst_port_mask);
4230 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_MIRROR_VNIC_ID)
4231 req.mirror_vnic_id = filter->mirror_vnic_id;
4233 req.enables = rte_cpu_to_le_32(enables);
4235 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4237 HWRM_CHECK_RESULT();
4239 filter->fw_ntuple_filter_id = rte_le_to_cpu_64(resp->ntuple_filter_id);
4245 int bnxt_hwrm_clear_ntuple_filter(struct bnxt *bp,
4246 struct bnxt_filter_info *filter)
4249 struct hwrm_cfa_ntuple_filter_free_input req = {.req_type = 0 };
4250 struct hwrm_cfa_ntuple_filter_free_output *resp =
4251 bp->hwrm_cmd_resp_addr;
4253 if (filter->fw_ntuple_filter_id == UINT64_MAX)
4256 HWRM_PREP(req, CFA_NTUPLE_FILTER_FREE, BNXT_USE_CHIMP_MB);
4258 req.ntuple_filter_id = rte_cpu_to_le_64(filter->fw_ntuple_filter_id);
4260 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4262 HWRM_CHECK_RESULT();
4265 filter->fw_ntuple_filter_id = UINT64_MAX;
4271 bnxt_vnic_rss_configure_thor(struct bnxt *bp, struct bnxt_vnic_info *vnic)
4273 struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
4274 uint8_t *rx_queue_state = bp->eth_dev->data->rx_queue_state;
4275 struct hwrm_vnic_rss_cfg_input req = {.req_type = 0 };
4276 struct bnxt_rx_queue **rxqs = bp->rx_queues;
4277 uint16_t *ring_tbl = vnic->rss_table;
4278 int nr_ctxs = vnic->num_lb_ctxts;
4279 int max_rings = bp->rx_nr_rings;
4283 for (i = 0, k = 0; i < nr_ctxs; i++) {
4284 struct bnxt_rx_ring_info *rxr;
4285 struct bnxt_cp_ring_info *cpr;
4287 HWRM_PREP(req, VNIC_RSS_CFG, BNXT_USE_CHIMP_MB);
4289 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
4290 req.hash_type = rte_cpu_to_le_32(vnic->hash_type);
4291 req.hash_mode_flags = vnic->hash_mode;
4293 req.ring_grp_tbl_addr =
4294 rte_cpu_to_le_64(vnic->rss_table_dma_addr +
4295 i * BNXT_RSS_ENTRIES_PER_CTX_THOR *
4296 2 * sizeof(*ring_tbl));
4297 req.hash_key_tbl_addr =
4298 rte_cpu_to_le_64(vnic->rss_hash_key_dma_addr);
4300 req.ring_table_pair_index = i;
4301 req.rss_ctx_idx = rte_cpu_to_le_16(vnic->fw_grp_ids[i]);
4303 for (j = 0; j < 64; j++) {
4306 /* Find next active ring. */
4307 for (cnt = 0; cnt < max_rings; cnt++) {
4308 if (rx_queue_state[k] !=
4309 RTE_ETH_QUEUE_STATE_STOPPED)
4311 if (++k == max_rings)
4315 /* Return if no rings are active. */
4316 if (cnt == max_rings)
4319 /* Add rx/cp ring pair to RSS table. */
4320 rxr = rxqs[k]->rx_ring;
4321 cpr = rxqs[k]->cp_ring;
4323 ring_id = rxr->rx_ring_struct->fw_ring_id;
4324 *ring_tbl++ = rte_cpu_to_le_16(ring_id);
4325 ring_id = cpr->cp_ring_struct->fw_ring_id;
4326 *ring_tbl++ = rte_cpu_to_le_16(ring_id);
4328 if (++k == max_rings)
4331 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req),
4334 HWRM_CHECK_RESULT();
4341 int bnxt_vnic_rss_configure(struct bnxt *bp, struct bnxt_vnic_info *vnic)
4343 unsigned int rss_idx, fw_idx, i;
4345 if (!(vnic->rss_table && vnic->hash_type))
4348 if (BNXT_CHIP_THOR(bp))
4349 return bnxt_vnic_rss_configure_thor(bp, vnic);
4351 if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
4354 if (vnic->rss_table && vnic->hash_type) {
4356 * Fill the RSS hash & redirection table with
4357 * ring group ids for all VNICs
4359 for (rss_idx = 0, fw_idx = 0; rss_idx < HW_HASH_INDEX_SIZE;
4360 rss_idx++, fw_idx++) {
4361 for (i = 0; i < bp->rx_cp_nr_rings; i++) {
4362 fw_idx %= bp->rx_cp_nr_rings;
4363 if (vnic->fw_grp_ids[fw_idx] !=
4368 if (i == bp->rx_cp_nr_rings)
4370 vnic->rss_table[rss_idx] = vnic->fw_grp_ids[fw_idx];
4372 return bnxt_hwrm_vnic_rss_cfg(bp, vnic);
4378 static void bnxt_hwrm_set_coal_params(struct bnxt_coal *hw_coal,
4379 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *req)
4383 req->num_cmpl_aggr_int = rte_cpu_to_le_16(hw_coal->num_cmpl_aggr_int);
4385 /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
4386 req->num_cmpl_dma_aggr = rte_cpu_to_le_16(hw_coal->num_cmpl_dma_aggr);
4388 /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
4389 req->num_cmpl_dma_aggr_during_int =
4390 rte_cpu_to_le_16(hw_coal->num_cmpl_dma_aggr_during_int);
4392 req->int_lat_tmr_max = rte_cpu_to_le_16(hw_coal->int_lat_tmr_max);
4394 /* min timer set to 1/2 of interrupt timer */
4395 req->int_lat_tmr_min = rte_cpu_to_le_16(hw_coal->int_lat_tmr_min);
4397 /* buf timer set to 1/4 of interrupt timer */
4398 req->cmpl_aggr_dma_tmr = rte_cpu_to_le_16(hw_coal->cmpl_aggr_dma_tmr);
4400 req->cmpl_aggr_dma_tmr_during_int =
4401 rte_cpu_to_le_16(hw_coal->cmpl_aggr_dma_tmr_during_int);
4403 flags = HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_TIMER_RESET |
4404 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_RING_IDLE;
4405 req->flags = rte_cpu_to_le_16(flags);
4408 static int bnxt_hwrm_set_coal_params_thor(struct bnxt *bp,
4409 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *agg_req)
4411 struct hwrm_ring_aggint_qcaps_input req = {0};
4412 struct hwrm_ring_aggint_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
4417 HWRM_PREP(req, RING_AGGINT_QCAPS, BNXT_USE_CHIMP_MB);
4418 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4419 HWRM_CHECK_RESULT();
4421 agg_req->num_cmpl_dma_aggr = resp->num_cmpl_dma_aggr_max;
4422 agg_req->cmpl_aggr_dma_tmr = resp->cmpl_aggr_dma_tmr_min;
4424 flags = HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_TIMER_RESET |
4425 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_RING_IDLE;
4426 agg_req->flags = rte_cpu_to_le_16(flags);
4428 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_ENABLES_CMPL_AGGR_DMA_TMR |
4429 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_ENABLES_NUM_CMPL_DMA_AGGR;
4430 agg_req->enables = rte_cpu_to_le_32(enables);
4436 int bnxt_hwrm_set_ring_coal(struct bnxt *bp,
4437 struct bnxt_coal *coal, uint16_t ring_id)
4439 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req = {0};
4440 struct hwrm_ring_cmpl_ring_cfg_aggint_params_output *resp =
4441 bp->hwrm_cmd_resp_addr;
4444 /* Set ring coalesce parameters only for 100G NICs */
4445 if (BNXT_CHIP_THOR(bp)) {
4446 if (bnxt_hwrm_set_coal_params_thor(bp, &req))
4448 } else if (bnxt_stratus_device(bp)) {
4449 bnxt_hwrm_set_coal_params(coal, &req);
4454 HWRM_PREP(req, RING_CMPL_RING_CFG_AGGINT_PARAMS, BNXT_USE_CHIMP_MB);
4455 req.ring_id = rte_cpu_to_le_16(ring_id);
4456 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4457 HWRM_CHECK_RESULT();
4462 #define BNXT_RTE_MEMZONE_FLAG (RTE_MEMZONE_1GB | RTE_MEMZONE_IOVA_CONTIG)
4463 int bnxt_hwrm_func_backing_store_qcaps(struct bnxt *bp)
4465 struct hwrm_func_backing_store_qcaps_input req = {0};
4466 struct hwrm_func_backing_store_qcaps_output *resp =
4467 bp->hwrm_cmd_resp_addr;
4468 struct bnxt_ctx_pg_info *ctx_pg;
4469 struct bnxt_ctx_mem_info *ctx;
4470 int total_alloc_len;
4473 if (!BNXT_CHIP_THOR(bp) ||
4474 bp->hwrm_spec_code < HWRM_VERSION_1_9_2 ||
4479 HWRM_PREP(req, FUNC_BACKING_STORE_QCAPS, BNXT_USE_CHIMP_MB);
4480 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4481 HWRM_CHECK_RESULT_SILENT();
4483 total_alloc_len = sizeof(*ctx);
4484 ctx = rte_zmalloc("bnxt_ctx_mem", total_alloc_len,
4485 RTE_CACHE_LINE_SIZE);
4491 ctx_pg = rte_malloc("bnxt_ctx_pg_mem",
4492 sizeof(*ctx_pg) * BNXT_MAX_Q,
4493 RTE_CACHE_LINE_SIZE);
4498 for (i = 0; i < BNXT_MAX_Q; i++, ctx_pg++)
4499 ctx->tqm_mem[i] = ctx_pg;
4502 ctx->qp_max_entries = rte_le_to_cpu_32(resp->qp_max_entries);
4503 ctx->qp_min_qp1_entries =
4504 rte_le_to_cpu_16(resp->qp_min_qp1_entries);
4505 ctx->qp_max_l2_entries =
4506 rte_le_to_cpu_16(resp->qp_max_l2_entries);
4507 ctx->qp_entry_size = rte_le_to_cpu_16(resp->qp_entry_size);
4508 ctx->srq_max_l2_entries =
4509 rte_le_to_cpu_16(resp->srq_max_l2_entries);
4510 ctx->srq_max_entries = rte_le_to_cpu_32(resp->srq_max_entries);
4511 ctx->srq_entry_size = rte_le_to_cpu_16(resp->srq_entry_size);
4512 ctx->cq_max_l2_entries =
4513 rte_le_to_cpu_16(resp->cq_max_l2_entries);
4514 ctx->cq_max_entries = rte_le_to_cpu_32(resp->cq_max_entries);
4515 ctx->cq_entry_size = rte_le_to_cpu_16(resp->cq_entry_size);
4516 ctx->vnic_max_vnic_entries =
4517 rte_le_to_cpu_16(resp->vnic_max_vnic_entries);
4518 ctx->vnic_max_ring_table_entries =
4519 rte_le_to_cpu_16(resp->vnic_max_ring_table_entries);
4520 ctx->vnic_entry_size = rte_le_to_cpu_16(resp->vnic_entry_size);
4521 ctx->stat_max_entries =
4522 rte_le_to_cpu_32(resp->stat_max_entries);
4523 ctx->stat_entry_size = rte_le_to_cpu_16(resp->stat_entry_size);
4524 ctx->tqm_entry_size = rte_le_to_cpu_16(resp->tqm_entry_size);
4525 ctx->tqm_min_entries_per_ring =
4526 rte_le_to_cpu_32(resp->tqm_min_entries_per_ring);
4527 ctx->tqm_max_entries_per_ring =
4528 rte_le_to_cpu_32(resp->tqm_max_entries_per_ring);
4529 ctx->tqm_entries_multiple = resp->tqm_entries_multiple;
4530 if (!ctx->tqm_entries_multiple)
4531 ctx->tqm_entries_multiple = 1;
4532 ctx->mrav_max_entries =
4533 rte_le_to_cpu_32(resp->mrav_max_entries);
4534 ctx->mrav_entry_size = rte_le_to_cpu_16(resp->mrav_entry_size);
4535 ctx->tim_entry_size = rte_le_to_cpu_16(resp->tim_entry_size);
4536 ctx->tim_max_entries = rte_le_to_cpu_32(resp->tim_max_entries);
4542 int bnxt_hwrm_func_backing_store_cfg(struct bnxt *bp, uint32_t enables)
4544 struct hwrm_func_backing_store_cfg_input req = {0};
4545 struct hwrm_func_backing_store_cfg_output *resp =
4546 bp->hwrm_cmd_resp_addr;
4547 struct bnxt_ctx_mem_info *ctx = bp->ctx;
4548 struct bnxt_ctx_pg_info *ctx_pg;
4549 uint32_t *num_entries;
4558 HWRM_PREP(req, FUNC_BACKING_STORE_CFG, BNXT_USE_CHIMP_MB);
4559 req.enables = rte_cpu_to_le_32(enables);
4561 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_QP) {
4562 ctx_pg = &ctx->qp_mem;
4563 req.qp_num_entries = rte_cpu_to_le_32(ctx_pg->entries);
4564 req.qp_num_qp1_entries =
4565 rte_cpu_to_le_16(ctx->qp_min_qp1_entries);
4566 req.qp_num_l2_entries =
4567 rte_cpu_to_le_16(ctx->qp_max_l2_entries);
4568 req.qp_entry_size = rte_cpu_to_le_16(ctx->qp_entry_size);
4569 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4570 &req.qpc_pg_size_qpc_lvl,
4574 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_SRQ) {
4575 ctx_pg = &ctx->srq_mem;
4576 req.srq_num_entries = rte_cpu_to_le_32(ctx_pg->entries);
4577 req.srq_num_l2_entries =
4578 rte_cpu_to_le_16(ctx->srq_max_l2_entries);
4579 req.srq_entry_size = rte_cpu_to_le_16(ctx->srq_entry_size);
4580 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4581 &req.srq_pg_size_srq_lvl,
4585 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_CQ) {
4586 ctx_pg = &ctx->cq_mem;
4587 req.cq_num_entries = rte_cpu_to_le_32(ctx_pg->entries);
4588 req.cq_num_l2_entries =
4589 rte_cpu_to_le_16(ctx->cq_max_l2_entries);
4590 req.cq_entry_size = rte_cpu_to_le_16(ctx->cq_entry_size);
4591 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4592 &req.cq_pg_size_cq_lvl,
4596 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_VNIC) {
4597 ctx_pg = &ctx->vnic_mem;
4598 req.vnic_num_vnic_entries =
4599 rte_cpu_to_le_16(ctx->vnic_max_vnic_entries);
4600 req.vnic_num_ring_table_entries =
4601 rte_cpu_to_le_16(ctx->vnic_max_ring_table_entries);
4602 req.vnic_entry_size = rte_cpu_to_le_16(ctx->vnic_entry_size);
4603 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4604 &req.vnic_pg_size_vnic_lvl,
4605 &req.vnic_page_dir);
4608 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_STAT) {
4609 ctx_pg = &ctx->stat_mem;
4610 req.stat_num_entries = rte_cpu_to_le_16(ctx->stat_max_entries);
4611 req.stat_entry_size = rte_cpu_to_le_16(ctx->stat_entry_size);
4612 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4613 &req.stat_pg_size_stat_lvl,
4614 &req.stat_page_dir);
4617 req.tqm_entry_size = rte_cpu_to_le_16(ctx->tqm_entry_size);
4618 num_entries = &req.tqm_sp_num_entries;
4619 pg_attr = &req.tqm_sp_pg_size_tqm_sp_lvl;
4620 pg_dir = &req.tqm_sp_page_dir;
4621 ena = HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_TQM_SP;
4622 for (i = 0; i < 9; i++, num_entries++, pg_attr++, pg_dir++, ena <<= 1) {
4623 if (!(enables & ena))
4626 req.tqm_entry_size = rte_cpu_to_le_16(ctx->tqm_entry_size);
4628 ctx_pg = ctx->tqm_mem[i];
4629 *num_entries = rte_cpu_to_le_16(ctx_pg->entries);
4630 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem, pg_attr, pg_dir);
4633 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4634 HWRM_CHECK_RESULT();
4640 int bnxt_hwrm_ext_port_qstats(struct bnxt *bp)
4642 struct hwrm_port_qstats_ext_input req = {0};
4643 struct hwrm_port_qstats_ext_output *resp = bp->hwrm_cmd_resp_addr;
4644 struct bnxt_pf_info *pf = &bp->pf;
4647 if (!(bp->flags & BNXT_FLAG_EXT_RX_PORT_STATS ||
4648 bp->flags & BNXT_FLAG_EXT_TX_PORT_STATS))
4651 HWRM_PREP(req, PORT_QSTATS_EXT, BNXT_USE_CHIMP_MB);
4653 req.port_id = rte_cpu_to_le_16(pf->port_id);
4654 if (bp->flags & BNXT_FLAG_EXT_TX_PORT_STATS) {
4655 req.tx_stat_host_addr =
4656 rte_cpu_to_le_64(bp->hw_tx_port_stats_ext_map);
4658 rte_cpu_to_le_16(sizeof(struct tx_port_stats_ext));
4660 if (bp->flags & BNXT_FLAG_EXT_RX_PORT_STATS) {
4661 req.rx_stat_host_addr =
4662 rte_cpu_to_le_64(bp->hw_rx_port_stats_ext_map);
4664 rte_cpu_to_le_16(sizeof(struct rx_port_stats_ext));
4666 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4669 bp->fw_rx_port_stats_ext_size = 0;
4670 bp->fw_tx_port_stats_ext_size = 0;
4672 bp->fw_rx_port_stats_ext_size =
4673 rte_le_to_cpu_16(resp->rx_stat_size);
4674 bp->fw_tx_port_stats_ext_size =
4675 rte_le_to_cpu_16(resp->tx_stat_size);
4678 HWRM_CHECK_RESULT();
4685 bnxt_hwrm_tunnel_redirect(struct bnxt *bp, uint8_t type)
4687 struct hwrm_cfa_redirect_tunnel_type_alloc_input req = {0};
4688 struct hwrm_cfa_redirect_tunnel_type_alloc_output *resp =
4689 bp->hwrm_cmd_resp_addr;
4692 HWRM_PREP(req, CFA_REDIRECT_TUNNEL_TYPE_ALLOC, BNXT_USE_CHIMP_MB);
4693 req.tunnel_type = type;
4694 req.dest_fid = bp->fw_fid;
4695 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4696 HWRM_CHECK_RESULT();
4704 bnxt_hwrm_tunnel_redirect_free(struct bnxt *bp, uint8_t type)
4706 struct hwrm_cfa_redirect_tunnel_type_free_input req = {0};
4707 struct hwrm_cfa_redirect_tunnel_type_free_output *resp =
4708 bp->hwrm_cmd_resp_addr;
4711 HWRM_PREP(req, CFA_REDIRECT_TUNNEL_TYPE_FREE, BNXT_USE_CHIMP_MB);
4712 req.tunnel_type = type;
4713 req.dest_fid = bp->fw_fid;
4714 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4715 HWRM_CHECK_RESULT();
4722 int bnxt_hwrm_tunnel_redirect_query(struct bnxt *bp, uint32_t *type)
4724 struct hwrm_cfa_redirect_query_tunnel_type_input req = {0};
4725 struct hwrm_cfa_redirect_query_tunnel_type_output *resp =
4726 bp->hwrm_cmd_resp_addr;
4729 HWRM_PREP(req, CFA_REDIRECT_QUERY_TUNNEL_TYPE, BNXT_USE_CHIMP_MB);
4730 req.src_fid = bp->fw_fid;
4731 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4732 HWRM_CHECK_RESULT();
4735 *type = rte_le_to_cpu_32(resp->tunnel_mask);
4742 int bnxt_hwrm_tunnel_redirect_info(struct bnxt *bp, uint8_t tun_type,
4745 struct hwrm_cfa_redirect_tunnel_type_info_input req = {0};
4746 struct hwrm_cfa_redirect_tunnel_type_info_output *resp =
4747 bp->hwrm_cmd_resp_addr;
4750 HWRM_PREP(req, CFA_REDIRECT_TUNNEL_TYPE_INFO, BNXT_USE_CHIMP_MB);
4751 req.src_fid = bp->fw_fid;
4752 req.tunnel_type = tun_type;
4753 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4754 HWRM_CHECK_RESULT();
4757 *dst_fid = rte_le_to_cpu_16(resp->dest_fid);
4759 PMD_DRV_LOG(DEBUG, "dst_fid: %x\n", resp->dest_fid);
4766 int bnxt_hwrm_set_mac(struct bnxt *bp)
4768 struct hwrm_func_vf_cfg_output *resp = bp->hwrm_cmd_resp_addr;
4769 struct hwrm_func_vf_cfg_input req = {0};
4775 HWRM_PREP(req, FUNC_VF_CFG, BNXT_USE_CHIMP_MB);
4778 rte_cpu_to_le_32(HWRM_FUNC_VF_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
4779 memcpy(req.dflt_mac_addr, bp->mac_addr, RTE_ETHER_ADDR_LEN);
4781 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4783 HWRM_CHECK_RESULT();
4785 memcpy(bp->dflt_mac_addr, bp->mac_addr, RTE_ETHER_ADDR_LEN);
4791 int bnxt_hwrm_if_change(struct bnxt *bp, bool up)
4793 struct hwrm_func_drv_if_change_output *resp = bp->hwrm_cmd_resp_addr;
4794 struct hwrm_func_drv_if_change_input req = {0};
4798 if (!(bp->flags & BNXT_FLAG_FW_CAP_IF_CHANGE))
4801 /* Do not issue FUNC_DRV_IF_CHANGE during reset recovery.
4802 * If we issue FUNC_DRV_IF_CHANGE with flags down before
4803 * FUNC_DRV_UNRGTR, FW resets before FUNC_DRV_UNRGTR
4805 if (!up && (bp->flags & BNXT_FLAG_FW_RESET))
4808 HWRM_PREP(req, FUNC_DRV_IF_CHANGE, BNXT_USE_CHIMP_MB);
4812 rte_cpu_to_le_32(HWRM_FUNC_DRV_IF_CHANGE_INPUT_FLAGS_UP);
4814 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4816 HWRM_CHECK_RESULT();
4817 flags = rte_le_to_cpu_32(resp->flags);
4820 if (flags & HWRM_FUNC_DRV_IF_CHANGE_OUTPUT_FLAGS_HOT_FW_RESET_DONE) {
4821 PMD_DRV_LOG(INFO, "FW reset happened while port was down\n");
4822 bp->flags |= BNXT_FLAG_IF_CHANGE_HOT_FW_RESET_DONE;
4828 int bnxt_hwrm_error_recovery_qcfg(struct bnxt *bp)
4830 struct hwrm_error_recovery_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
4831 struct bnxt_error_recovery_info *info = bp->recovery_info;
4832 struct hwrm_error_recovery_qcfg_input req = {0};
4837 /* Older FW does not have error recovery support */
4838 if (!(bp->flags & BNXT_FLAG_FW_CAP_ERROR_RECOVERY))
4842 info = rte_zmalloc("bnxt_hwrm_error_recovery_qcfg",
4844 bp->recovery_info = info;
4848 memset(info, 0, sizeof(*info));
4851 HWRM_PREP(req, ERROR_RECOVERY_QCFG, BNXT_USE_CHIMP_MB);
4853 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4855 HWRM_CHECK_RESULT();
4857 flags = rte_le_to_cpu_32(resp->flags);
4858 if (flags & HWRM_ERROR_RECOVERY_QCFG_OUTPUT_FLAGS_HOST)
4859 info->flags |= BNXT_FLAG_ERROR_RECOVERY_HOST;
4860 else if (flags & HWRM_ERROR_RECOVERY_QCFG_OUTPUT_FLAGS_CO_CPU)
4861 info->flags |= BNXT_FLAG_ERROR_RECOVERY_CO_CPU;
4863 if ((info->flags & BNXT_FLAG_ERROR_RECOVERY_CO_CPU) &&
4864 !(bp->flags & BNXT_FLAG_KONG_MB_EN)) {
4869 /* FW returned values are in units of 100msec */
4870 info->driver_polling_freq =
4871 rte_le_to_cpu_32(resp->driver_polling_freq) * 100;
4872 info->master_func_wait_period =
4873 rte_le_to_cpu_32(resp->master_func_wait_period) * 100;
4874 info->normal_func_wait_period =
4875 rte_le_to_cpu_32(resp->normal_func_wait_period) * 100;
4876 info->master_func_wait_period_after_reset =
4877 rte_le_to_cpu_32(resp->master_func_wait_period_after_reset) * 100;
4878 info->max_bailout_time_after_reset =
4879 rte_le_to_cpu_32(resp->max_bailout_time_after_reset) * 100;
4880 info->status_regs[BNXT_FW_STATUS_REG] =
4881 rte_le_to_cpu_32(resp->fw_health_status_reg);
4882 info->status_regs[BNXT_FW_HEARTBEAT_CNT_REG] =
4883 rte_le_to_cpu_32(resp->fw_heartbeat_reg);
4884 info->status_regs[BNXT_FW_RECOVERY_CNT_REG] =
4885 rte_le_to_cpu_32(resp->fw_reset_cnt_reg);
4886 info->status_regs[BNXT_FW_RESET_INPROG_REG] =
4887 rte_le_to_cpu_32(resp->reset_inprogress_reg);
4888 info->reg_array_cnt =
4889 rte_le_to_cpu_32(resp->reg_array_cnt);
4891 if (info->reg_array_cnt >= BNXT_NUM_RESET_REG) {
4896 for (i = 0; i < info->reg_array_cnt; i++) {
4897 info->reset_reg[i] =
4898 rte_le_to_cpu_32(resp->reset_reg[i]);
4899 info->reset_reg_val[i] =
4900 rte_le_to_cpu_32(resp->reset_reg_val[i]);
4901 info->delay_after_reset[i] =
4902 resp->delay_after_reset[i];
4907 /* Map the FW status registers */
4909 rc = bnxt_map_fw_health_status_regs(bp);
4912 rte_free(bp->recovery_info);
4913 bp->recovery_info = NULL;
4918 int bnxt_hwrm_fw_reset(struct bnxt *bp)
4920 struct hwrm_fw_reset_output *resp = bp->hwrm_cmd_resp_addr;
4921 struct hwrm_fw_reset_input req = {0};
4927 HWRM_PREP(req, FW_RESET, BNXT_USE_KONG(bp));
4929 req.embedded_proc_type =
4930 HWRM_FW_RESET_INPUT_EMBEDDED_PROC_TYPE_CHIP;
4931 req.selfrst_status =
4932 HWRM_FW_RESET_INPUT_SELFRST_STATUS_SELFRSTASAP;
4933 req.flags = HWRM_FW_RESET_INPUT_FLAGS_RESET_GRACEFUL;
4935 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req),
4938 HWRM_CHECK_RESULT();
4944 int bnxt_hwrm_port_ts_query(struct bnxt *bp, uint8_t path, uint64_t *timestamp)
4946 struct hwrm_port_ts_query_output *resp = bp->hwrm_cmd_resp_addr;
4947 struct hwrm_port_ts_query_input req = {0};
4948 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
4955 HWRM_PREP(req, PORT_TS_QUERY, BNXT_USE_CHIMP_MB);
4958 case BNXT_PTP_FLAGS_PATH_TX:
4959 flags |= HWRM_PORT_TS_QUERY_INPUT_FLAGS_PATH_TX;
4961 case BNXT_PTP_FLAGS_PATH_RX:
4962 flags |= HWRM_PORT_TS_QUERY_INPUT_FLAGS_PATH_RX;
4964 case BNXT_PTP_FLAGS_CURRENT_TIME:
4965 flags |= HWRM_PORT_TS_QUERY_INPUT_FLAGS_CURRENT_TIME;
4969 req.flags = rte_cpu_to_le_32(flags);
4970 req.port_id = rte_cpu_to_le_16(bp->pf.port_id);
4972 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4974 HWRM_CHECK_RESULT();
4977 *timestamp = rte_le_to_cpu_32(resp->ptp_msg_ts[0]);
4979 (uint64_t)(rte_le_to_cpu_32(resp->ptp_msg_ts[1])) << 32;
4986 int bnxt_hwrm_cfa_adv_flow_mgmt_qcaps(struct bnxt *bp)
4988 struct hwrm_cfa_adv_flow_mgnt_qcaps_output *resp =
4989 bp->hwrm_cmd_resp_addr;
4990 struct hwrm_cfa_adv_flow_mgnt_qcaps_input req = {0};
4994 if (!(bp->flags & BNXT_FLAG_ADV_FLOW_MGMT))
4997 if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp))) {
4999 "Not a PF or trusted VF. Command not supported\n");
5003 HWRM_PREP(req, CFA_ADV_FLOW_MGNT_QCAPS, BNXT_USE_KONG(bp));
5004 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
5006 HWRM_CHECK_RESULT();
5007 flags = rte_le_to_cpu_32(resp->flags);
5010 if (flags & HWRM_CFA_ADV_FLOW_MGNT_QCAPS_L2_HDR_SRC_FILTER_EN) {
5011 bp->flow_flags |= BNXT_FLOW_FLAG_L2_HDR_SRC_FILTER_EN;
5012 PMD_DRV_LOG(INFO, "Source L2 header filtering enabled\n");