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"
27 #define HWRM_SPEC_CODE_1_8_3 0x10803
28 #define HWRM_VERSION_1_9_1 0x10901
29 #define HWRM_VERSION_1_9_2 0x10903
31 struct bnxt_plcmodes_cfg {
33 uint16_t jumbo_thresh;
35 uint16_t hds_threshold;
38 static int page_getenum(size_t size)
54 PMD_DRV_LOG(ERR, "Page size %zu out of range\n", size);
55 return sizeof(void *) * 8 - 1;
58 static int page_roundup(size_t size)
60 return 1 << page_getenum(size);
63 static void bnxt_hwrm_set_pg_attr(struct bnxt_ring_mem_info *rmem,
67 if (rmem->nr_pages > 1) {
69 *pg_dir = rte_cpu_to_le_64(rmem->pg_tbl_map);
71 *pg_dir = rte_cpu_to_le_64(rmem->dma_arr[0]);
76 * HWRM Functions (sent to HWRM)
77 * These are named bnxt_hwrm_*() and return 0 on success or -110 if the
78 * HWRM command times out, or a negative error code if the HWRM
79 * command was failed by the FW.
82 static int bnxt_hwrm_send_message(struct bnxt *bp, void *msg,
83 uint32_t msg_len, bool use_kong_mb)
86 struct input *req = msg;
87 struct output *resp = bp->hwrm_cmd_resp_addr;
91 uint16_t max_req_len = bp->max_req_len;
92 struct hwrm_short_input short_input = { 0 };
93 uint16_t bar_offset = use_kong_mb ?
94 GRCPF_REG_KONG_CHANNEL_OFFSET : GRCPF_REG_CHIMP_CHANNEL_OFFSET;
95 uint16_t mb_trigger_offset = use_kong_mb ?
96 GRCPF_REG_KONG_COMM_TRIGGER : GRCPF_REG_CHIMP_COMM_TRIGGER;
99 /* Do not send HWRM commands to firmware in error state */
100 if (bp->flags & BNXT_FLAG_FATAL_ERROR)
103 timeout = bp->hwrm_cmd_timeout;
105 if (bp->flags & BNXT_FLAG_SHORT_CMD ||
106 msg_len > bp->max_req_len) {
107 void *short_cmd_req = bp->hwrm_short_cmd_req_addr;
109 memset(short_cmd_req, 0, bp->hwrm_max_ext_req_len);
110 memcpy(short_cmd_req, req, msg_len);
112 short_input.req_type = rte_cpu_to_le_16(req->req_type);
113 short_input.signature = rte_cpu_to_le_16(
114 HWRM_SHORT_INPUT_SIGNATURE_SHORT_CMD);
115 short_input.size = rte_cpu_to_le_16(msg_len);
116 short_input.req_addr =
117 rte_cpu_to_le_64(bp->hwrm_short_cmd_req_dma_addr);
119 data = (uint32_t *)&short_input;
120 msg_len = sizeof(short_input);
122 max_req_len = BNXT_HWRM_SHORT_REQ_LEN;
125 /* Write request msg to hwrm channel */
126 for (i = 0; i < msg_len; i += 4) {
127 bar = (uint8_t *)bp->bar0 + bar_offset + i;
128 rte_write32(*data, bar);
132 /* Zero the rest of the request space */
133 for (; i < max_req_len; i += 4) {
134 bar = (uint8_t *)bp->bar0 + bar_offset + i;
138 /* Ring channel doorbell */
139 bar = (uint8_t *)bp->bar0 + mb_trigger_offset;
142 * Make sure the channel doorbell ring command complete before
143 * reading the response to avoid getting stale or invalid
148 /* Poll for the valid bit */
149 for (i = 0; i < timeout; i++) {
150 /* Sanity check on the resp->resp_len */
152 if (resp->resp_len && resp->resp_len <= bp->max_resp_len) {
153 /* Last byte of resp contains the valid key */
154 valid = (uint8_t *)resp + resp->resp_len - 1;
155 if (*valid == HWRM_RESP_VALID_KEY)
162 /* Suppress VER_GET timeout messages during reset recovery */
163 if (bp->flags & BNXT_FLAG_FW_RESET &&
164 rte_cpu_to_le_16(req->req_type) == HWRM_VER_GET)
167 PMD_DRV_LOG(ERR, "Error(timeout) sending msg 0x%04x\n",
175 * HWRM_PREP() should be used to prepare *ALL* HWRM commands. It grabs the
176 * spinlock, and does initial processing.
178 * HWRM_CHECK_RESULT() returns errors on failure and may not be used. It
179 * releases the spinlock only if it returns. If the regular int return codes
180 * are not used by the function, HWRM_CHECK_RESULT() should not be used
181 * directly, rather it should be copied and modified to suit the function.
183 * HWRM_UNLOCK() must be called after all response processing is completed.
185 #define HWRM_PREP(req, type, kong) do { \
186 rte_spinlock_lock(&bp->hwrm_lock); \
187 if (bp->hwrm_cmd_resp_addr == NULL) { \
188 rte_spinlock_unlock(&bp->hwrm_lock); \
191 memset(bp->hwrm_cmd_resp_addr, 0, bp->max_resp_len); \
192 (req)->req_type = rte_cpu_to_le_16(type); \
193 (req)->cmpl_ring = rte_cpu_to_le_16(-1); \
194 (req)->seq_id = kong ? rte_cpu_to_le_16(bp->kong_cmd_seq++) :\
195 rte_cpu_to_le_16(bp->chimp_cmd_seq++); \
196 (req)->target_id = rte_cpu_to_le_16(0xffff); \
197 (req)->resp_addr = rte_cpu_to_le_64(bp->hwrm_cmd_resp_dma_addr); \
200 #define HWRM_CHECK_RESULT_SILENT() do {\
202 rte_spinlock_unlock(&bp->hwrm_lock); \
205 if (resp->error_code) { \
206 rc = rte_le_to_cpu_16(resp->error_code); \
207 rte_spinlock_unlock(&bp->hwrm_lock); \
212 #define HWRM_CHECK_RESULT() do {\
214 PMD_DRV_LOG(ERR, "failed rc:%d\n", rc); \
215 rte_spinlock_unlock(&bp->hwrm_lock); \
216 if (rc == HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED) \
218 else if (rc == HWRM_ERR_CODE_RESOURCE_ALLOC_ERROR) \
220 else if (rc == HWRM_ERR_CODE_INVALID_PARAMS) \
222 else if (rc == HWRM_ERR_CODE_CMD_NOT_SUPPORTED) \
228 if (resp->error_code) { \
229 rc = rte_le_to_cpu_16(resp->error_code); \
230 if (resp->resp_len >= 16) { \
231 struct hwrm_err_output *tmp_hwrm_err_op = \
234 "error %d:%d:%08x:%04x\n", \
235 rc, tmp_hwrm_err_op->cmd_err, \
237 tmp_hwrm_err_op->opaque_0), \
239 tmp_hwrm_err_op->opaque_1)); \
241 PMD_DRV_LOG(ERR, "error %d\n", rc); \
243 rte_spinlock_unlock(&bp->hwrm_lock); \
244 if (rc == HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED) \
246 else if (rc == HWRM_ERR_CODE_RESOURCE_ALLOC_ERROR) \
248 else if (rc == HWRM_ERR_CODE_INVALID_PARAMS) \
250 else if (rc == HWRM_ERR_CODE_CMD_NOT_SUPPORTED) \
258 #define HWRM_UNLOCK() rte_spinlock_unlock(&bp->hwrm_lock)
260 int bnxt_hwrm_tf_message_direct(struct bnxt *bp,
269 bool mailbox = BNXT_USE_CHIMP_MB;
270 struct input *req = msg;
271 struct output *resp = bp->hwrm_cmd_resp_addr;
274 mailbox = BNXT_USE_KONG(bp);
276 HWRM_PREP(req, msg_type, mailbox);
278 rc = bnxt_hwrm_send_message(bp, req, msg_len, mailbox);
283 memcpy(resp_msg, resp, resp_len);
290 int bnxt_hwrm_tf_message_tunneled(struct bnxt *bp,
294 uint32_t *tf_response_code,
298 uint32_t response_len)
301 struct hwrm_cfa_tflib_input req = { .req_type = 0 };
302 struct hwrm_cfa_tflib_output *resp = bp->hwrm_cmd_resp_addr;
303 bool mailbox = BNXT_USE_CHIMP_MB;
305 if (msg_len > sizeof(req.tf_req))
309 mailbox = BNXT_USE_KONG(bp);
311 HWRM_PREP(&req, HWRM_TF, mailbox);
312 /* Build request using the user supplied request payload.
313 * TLV request size is checked at build time against HWRM
314 * request max size, thus no checking required.
316 req.tf_type = tf_type;
317 req.tf_subtype = tf_subtype;
318 memcpy(req.tf_req, msg, msg_len);
320 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), mailbox);
323 /* Copy the resp to user provided response buffer */
324 if (response != NULL)
325 /* Post process response data. We need to copy only
326 * the 'payload' as the HWRM data structure really is
327 * HWRM header + msg header + payload and the TFLIB
328 * only provided a payload place holder.
330 if (response_len != 0) {
336 /* Extract the internal tflib response code */
337 *tf_response_code = resp->tf_resp_code;
343 int bnxt_hwrm_cfa_l2_clear_rx_mask(struct bnxt *bp, struct bnxt_vnic_info *vnic)
346 struct hwrm_cfa_l2_set_rx_mask_input req = {.req_type = 0 };
347 struct hwrm_cfa_l2_set_rx_mask_output *resp = bp->hwrm_cmd_resp_addr;
349 HWRM_PREP(&req, HWRM_CFA_L2_SET_RX_MASK, BNXT_USE_CHIMP_MB);
350 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
353 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
361 int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp,
362 struct bnxt_vnic_info *vnic,
364 struct bnxt_vlan_table_entry *vlan_table)
367 struct hwrm_cfa_l2_set_rx_mask_input req = {.req_type = 0 };
368 struct hwrm_cfa_l2_set_rx_mask_output *resp = bp->hwrm_cmd_resp_addr;
371 if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
374 HWRM_PREP(&req, HWRM_CFA_L2_SET_RX_MASK, BNXT_USE_CHIMP_MB);
375 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
377 if (vnic->flags & BNXT_VNIC_INFO_BCAST)
378 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_BCAST;
379 if (vnic->flags & BNXT_VNIC_INFO_UNTAGGED)
380 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLAN_NONVLAN;
382 if (vnic->flags & BNXT_VNIC_INFO_PROMISC)
383 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_PROMISCUOUS;
385 if (vnic->flags & BNXT_VNIC_INFO_ALLMULTI) {
386 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
387 } else if (vnic->flags & BNXT_VNIC_INFO_MCAST) {
388 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_MCAST;
389 req.num_mc_entries = rte_cpu_to_le_32(vnic->mc_addr_cnt);
390 req.mc_tbl_addr = rte_cpu_to_le_64(vnic->mc_list_dma_addr);
393 if (!(mask & HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLAN_NONVLAN))
394 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLANONLY;
395 req.vlan_tag_tbl_addr =
396 rte_cpu_to_le_64(rte_malloc_virt2iova(vlan_table));
397 req.num_vlan_tags = rte_cpu_to_le_32((uint32_t)vlan_count);
399 req.mask = rte_cpu_to_le_32(mask);
401 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
409 int bnxt_hwrm_cfa_vlan_antispoof_cfg(struct bnxt *bp, uint16_t fid,
411 struct bnxt_vlan_antispoof_table_entry *vlan_table)
414 struct hwrm_cfa_vlan_antispoof_cfg_input req = {.req_type = 0 };
415 struct hwrm_cfa_vlan_antispoof_cfg_output *resp =
416 bp->hwrm_cmd_resp_addr;
419 * Older HWRM versions did not support this command, and the set_rx_mask
420 * list was used for anti-spoof. In 1.8.0, the TX path configuration was
421 * removed from set_rx_mask call, and this command was added.
423 * This command is also present from 1.7.8.11 and higher,
426 if (bp->fw_ver < ((1 << 24) | (8 << 16))) {
427 if (bp->fw_ver != ((1 << 24) | (7 << 16) | (8 << 8))) {
428 if (bp->fw_ver < ((1 << 24) | (7 << 16) | (8 << 8) |
433 HWRM_PREP(&req, HWRM_CFA_VLAN_ANTISPOOF_CFG, BNXT_USE_CHIMP_MB);
434 req.fid = rte_cpu_to_le_16(fid);
436 req.vlan_tag_mask_tbl_addr =
437 rte_cpu_to_le_64(rte_malloc_virt2iova(vlan_table));
438 req.num_vlan_entries = rte_cpu_to_le_32((uint32_t)vlan_count);
440 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
448 int bnxt_hwrm_clear_l2_filter(struct bnxt *bp,
449 struct bnxt_filter_info *filter)
452 struct bnxt_filter_info *l2_filter = filter;
453 struct bnxt_vnic_info *vnic = NULL;
454 struct hwrm_cfa_l2_filter_free_input req = {.req_type = 0 };
455 struct hwrm_cfa_l2_filter_free_output *resp = bp->hwrm_cmd_resp_addr;
457 if (filter->fw_l2_filter_id == UINT64_MAX)
460 if (filter->matching_l2_fltr_ptr)
461 l2_filter = filter->matching_l2_fltr_ptr;
463 PMD_DRV_LOG(DEBUG, "filter: %p l2_filter: %p ref_cnt: %d\n",
464 filter, l2_filter, l2_filter->l2_ref_cnt);
466 if (l2_filter->l2_ref_cnt == 0)
469 if (l2_filter->l2_ref_cnt > 0)
470 l2_filter->l2_ref_cnt--;
472 if (l2_filter->l2_ref_cnt > 0)
475 HWRM_PREP(&req, HWRM_CFA_L2_FILTER_FREE, BNXT_USE_CHIMP_MB);
477 req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
479 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
484 filter->fw_l2_filter_id = UINT64_MAX;
485 if (l2_filter->l2_ref_cnt == 0) {
486 vnic = l2_filter->vnic;
488 STAILQ_REMOVE(&vnic->filter, l2_filter,
489 bnxt_filter_info, next);
490 bnxt_free_filter(bp, l2_filter);
497 int bnxt_hwrm_set_l2_filter(struct bnxt *bp,
499 struct bnxt_filter_info *filter)
502 struct hwrm_cfa_l2_filter_alloc_input req = {.req_type = 0 };
503 struct hwrm_cfa_l2_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr;
504 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
505 const struct rte_eth_vmdq_rx_conf *conf =
506 &dev_conf->rx_adv_conf.vmdq_rx_conf;
507 uint32_t enables = 0;
508 uint16_t j = dst_id - 1;
510 //TODO: Is there a better way to add VLANs to each VNIC in case of VMDQ
511 if ((dev_conf->rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG) &&
512 conf->pool_map[j].pools & (1UL << j)) {
514 "Add vlan %u to vmdq pool %u\n",
515 conf->pool_map[j].vlan_id, j);
517 filter->l2_ivlan = conf->pool_map[j].vlan_id;
519 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN |
520 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN_MASK;
523 if (filter->fw_l2_filter_id != UINT64_MAX)
524 bnxt_hwrm_clear_l2_filter(bp, filter);
526 HWRM_PREP(&req, HWRM_CFA_L2_FILTER_ALLOC, BNXT_USE_CHIMP_MB);
528 req.flags = rte_cpu_to_le_32(filter->flags);
530 enables = filter->enables |
531 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_DST_ID;
532 req.dst_id = rte_cpu_to_le_16(dst_id);
535 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR)
536 memcpy(req.l2_addr, filter->l2_addr,
539 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR_MASK)
540 memcpy(req.l2_addr_mask, filter->l2_addr_mask,
543 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN)
544 req.l2_ovlan = filter->l2_ovlan;
546 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN)
547 req.l2_ivlan = filter->l2_ivlan;
549 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN_MASK)
550 req.l2_ovlan_mask = filter->l2_ovlan_mask;
552 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN_MASK)
553 req.l2_ivlan_mask = filter->l2_ivlan_mask;
554 if (enables & HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_SRC_ID)
555 req.src_id = rte_cpu_to_le_32(filter->src_id);
556 if (enables & HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_SRC_TYPE)
557 req.src_type = filter->src_type;
558 if (filter->pri_hint) {
559 req.pri_hint = filter->pri_hint;
560 req.l2_filter_id_hint =
561 rte_cpu_to_le_64(filter->l2_filter_id_hint);
564 req.enables = rte_cpu_to_le_32(enables);
566 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
570 filter->fw_l2_filter_id = rte_le_to_cpu_64(resp->l2_filter_id);
571 filter->flow_id = rte_le_to_cpu_32(resp->flow_id);
574 filter->l2_ref_cnt++;
579 int bnxt_hwrm_ptp_cfg(struct bnxt *bp)
581 struct hwrm_port_mac_cfg_input req = {.req_type = 0};
582 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
589 HWRM_PREP(&req, HWRM_PORT_MAC_CFG, BNXT_USE_CHIMP_MB);
592 flags |= HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_RX_TS_CAPTURE_ENABLE;
595 HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_RX_TS_CAPTURE_DISABLE;
596 if (ptp->tx_tstamp_en)
597 flags |= HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_TX_TS_CAPTURE_ENABLE;
600 HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_TX_TS_CAPTURE_DISABLE;
601 req.flags = rte_cpu_to_le_32(flags);
602 req.enables = rte_cpu_to_le_32
603 (HWRM_PORT_MAC_CFG_INPUT_ENABLES_RX_TS_CAPTURE_PTP_MSG_TYPE);
604 req.rx_ts_capture_ptp_msg_type = rte_cpu_to_le_16(ptp->rxctl);
606 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
612 static int bnxt_hwrm_ptp_qcfg(struct bnxt *bp)
615 struct hwrm_port_mac_ptp_qcfg_input req = {.req_type = 0};
616 struct hwrm_port_mac_ptp_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
617 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
622 HWRM_PREP(&req, HWRM_PORT_MAC_PTP_QCFG, BNXT_USE_CHIMP_MB);
624 req.port_id = rte_cpu_to_le_16(bp->pf.port_id);
626 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
630 if (!BNXT_CHIP_THOR(bp) &&
631 !(resp->flags & HWRM_PORT_MAC_PTP_QCFG_OUTPUT_FLAGS_DIRECT_ACCESS))
634 if (resp->flags & HWRM_PORT_MAC_PTP_QCFG_OUTPUT_FLAGS_ONE_STEP_TX_TS)
635 bp->flags |= BNXT_FLAG_FW_CAP_ONE_STEP_TX_TS;
637 ptp = rte_zmalloc("ptp_cfg", sizeof(*ptp), 0);
641 if (!BNXT_CHIP_THOR(bp)) {
642 ptp->rx_regs[BNXT_PTP_RX_TS_L] =
643 rte_le_to_cpu_32(resp->rx_ts_reg_off_lower);
644 ptp->rx_regs[BNXT_PTP_RX_TS_H] =
645 rte_le_to_cpu_32(resp->rx_ts_reg_off_upper);
646 ptp->rx_regs[BNXT_PTP_RX_SEQ] =
647 rte_le_to_cpu_32(resp->rx_ts_reg_off_seq_id);
648 ptp->rx_regs[BNXT_PTP_RX_FIFO] =
649 rte_le_to_cpu_32(resp->rx_ts_reg_off_fifo);
650 ptp->rx_regs[BNXT_PTP_RX_FIFO_ADV] =
651 rte_le_to_cpu_32(resp->rx_ts_reg_off_fifo_adv);
652 ptp->tx_regs[BNXT_PTP_TX_TS_L] =
653 rte_le_to_cpu_32(resp->tx_ts_reg_off_lower);
654 ptp->tx_regs[BNXT_PTP_TX_TS_H] =
655 rte_le_to_cpu_32(resp->tx_ts_reg_off_upper);
656 ptp->tx_regs[BNXT_PTP_TX_SEQ] =
657 rte_le_to_cpu_32(resp->tx_ts_reg_off_seq_id);
658 ptp->tx_regs[BNXT_PTP_TX_FIFO] =
659 rte_le_to_cpu_32(resp->tx_ts_reg_off_fifo);
668 static int __bnxt_hwrm_func_qcaps(struct bnxt *bp)
671 struct hwrm_func_qcaps_input req = {.req_type = 0 };
672 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
673 uint16_t new_max_vfs;
677 HWRM_PREP(&req, HWRM_FUNC_QCAPS, BNXT_USE_CHIMP_MB);
679 req.fid = rte_cpu_to_le_16(0xffff);
681 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
685 bp->max_ring_grps = rte_le_to_cpu_32(resp->max_hw_ring_grps);
686 flags = rte_le_to_cpu_32(resp->flags);
688 bp->pf.port_id = resp->port_id;
689 bp->pf.first_vf_id = rte_le_to_cpu_16(resp->first_vf_id);
690 bp->pf.total_vfs = rte_le_to_cpu_16(resp->max_vfs);
691 new_max_vfs = bp->pdev->max_vfs;
692 if (new_max_vfs != bp->pf.max_vfs) {
694 rte_free(bp->pf.vf_info);
695 bp->pf.vf_info = rte_malloc("bnxt_vf_info",
696 sizeof(bp->pf.vf_info[0]) * new_max_vfs, 0);
697 bp->pf.max_vfs = new_max_vfs;
698 for (i = 0; i < new_max_vfs; i++) {
699 bp->pf.vf_info[i].fid = bp->pf.first_vf_id + i;
700 bp->pf.vf_info[i].vlan_table =
701 rte_zmalloc("VF VLAN table",
704 if (bp->pf.vf_info[i].vlan_table == NULL)
706 "Fail to alloc VLAN table for VF %d\n",
710 bp->pf.vf_info[i].vlan_table);
711 bp->pf.vf_info[i].vlan_as_table =
712 rte_zmalloc("VF VLAN AS table",
715 if (bp->pf.vf_info[i].vlan_as_table == NULL)
717 "Alloc VLAN AS table for VF %d fail\n",
721 bp->pf.vf_info[i].vlan_as_table);
722 STAILQ_INIT(&bp->pf.vf_info[i].filter);
727 bp->fw_fid = rte_le_to_cpu_32(resp->fid);
728 memcpy(bp->dflt_mac_addr, &resp->mac_address, RTE_ETHER_ADDR_LEN);
729 bp->max_rsscos_ctx = rte_le_to_cpu_16(resp->max_rsscos_ctx);
730 bp->max_cp_rings = rte_le_to_cpu_16(resp->max_cmpl_rings);
731 bp->max_tx_rings = rte_le_to_cpu_16(resp->max_tx_rings);
732 bp->max_rx_rings = rte_le_to_cpu_16(resp->max_rx_rings);
733 bp->first_vf_id = rte_le_to_cpu_16(resp->first_vf_id);
734 bp->max_rx_em_flows = rte_le_to_cpu_16(resp->max_rx_em_flows);
735 bp->max_l2_ctx = rte_le_to_cpu_16(resp->max_l2_ctxs);
736 if (!BNXT_CHIP_THOR(bp))
737 bp->max_l2_ctx += bp->max_rx_em_flows;
738 /* TODO: For now, do not support VMDq/RFS on VFs. */
743 bp->max_vnics = rte_le_to_cpu_16(resp->max_vnics);
747 bp->max_stat_ctx = rte_le_to_cpu_16(resp->max_stat_ctx);
749 bp->pf.total_vnics = rte_le_to_cpu_16(resp->max_vnics);
750 if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_PTP_SUPPORTED) {
751 bp->flags |= BNXT_FLAG_PTP_SUPPORTED;
752 PMD_DRV_LOG(DEBUG, "PTP SUPPORTED\n");
754 bnxt_hwrm_ptp_qcfg(bp);
758 if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_EXT_STATS_SUPPORTED)
759 bp->flags |= BNXT_FLAG_EXT_STATS_SUPPORTED;
761 if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_ERROR_RECOVERY_CAPABLE) {
762 bp->fw_cap |= BNXT_FW_CAP_ERROR_RECOVERY;
763 PMD_DRV_LOG(DEBUG, "Adapter Error recovery SUPPORTED\n");
766 if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_ERR_RECOVER_RELOAD)
767 bp->fw_cap |= BNXT_FW_CAP_ERR_RECOVER_RELOAD;
769 if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_HOT_RESET_CAPABLE)
770 bp->fw_cap |= BNXT_FW_CAP_HOT_RESET;
777 int bnxt_hwrm_func_qcaps(struct bnxt *bp)
781 rc = __bnxt_hwrm_func_qcaps(bp);
782 if (!rc && bp->hwrm_spec_code >= HWRM_SPEC_CODE_1_8_3) {
783 rc = bnxt_alloc_ctx_mem(bp);
787 rc = bnxt_hwrm_func_resc_qcaps(bp);
789 bp->flags |= BNXT_FLAG_NEW_RM;
793 * bnxt_hwrm_func_resc_qcaps can fail and cause init failure.
794 * But the error can be ignored. Return success.
800 /* VNIC cap covers capability of all VNICs. So no need to pass vnic_id */
801 int bnxt_hwrm_vnic_qcaps(struct bnxt *bp)
804 struct hwrm_vnic_qcaps_input req = {.req_type = 0 };
805 struct hwrm_vnic_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
807 HWRM_PREP(&req, HWRM_VNIC_QCAPS, BNXT_USE_CHIMP_MB);
809 req.target_id = rte_cpu_to_le_16(0xffff);
811 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
815 if (rte_le_to_cpu_32(resp->flags) &
816 HWRM_VNIC_QCAPS_OUTPUT_FLAGS_COS_ASSIGNMENT_CAP) {
817 bp->vnic_cap_flags |= BNXT_VNIC_CAP_COS_CLASSIFY;
818 PMD_DRV_LOG(INFO, "CoS assignment capability enabled\n");
821 bp->max_tpa_v2 = rte_le_to_cpu_16(resp->max_aggs_supported);
828 int bnxt_hwrm_func_reset(struct bnxt *bp)
831 struct hwrm_func_reset_input req = {.req_type = 0 };
832 struct hwrm_func_reset_output *resp = bp->hwrm_cmd_resp_addr;
834 HWRM_PREP(&req, HWRM_FUNC_RESET, BNXT_USE_CHIMP_MB);
836 req.enables = rte_cpu_to_le_32(0);
838 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
846 int bnxt_hwrm_func_driver_register(struct bnxt *bp)
850 struct hwrm_func_drv_rgtr_input req = {.req_type = 0 };
851 struct hwrm_func_drv_rgtr_output *resp = bp->hwrm_cmd_resp_addr;
853 if (bp->flags & BNXT_FLAG_REGISTERED)
856 if (bp->fw_cap & BNXT_FW_CAP_HOT_RESET)
857 flags = HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_HOT_RESET_SUPPORT;
858 if (bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY)
859 flags |= HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_ERROR_RECOVERY_SUPPORT;
861 /* PFs and trusted VFs should indicate the support of the
862 * Master capability on non Stingray platform
864 if ((BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp)) && !BNXT_STINGRAY(bp))
865 flags |= HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_MASTER_SUPPORT;
867 HWRM_PREP(&req, HWRM_FUNC_DRV_RGTR, BNXT_USE_CHIMP_MB);
868 req.enables = rte_cpu_to_le_32(HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_VER |
869 HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_ASYNC_EVENT_FWD);
870 req.ver_maj = RTE_VER_YEAR;
871 req.ver_min = RTE_VER_MONTH;
872 req.ver_upd = RTE_VER_MINOR;
875 req.enables |= rte_cpu_to_le_32(
876 HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_VF_REQ_FWD);
877 memcpy(req.vf_req_fwd, bp->pf.vf_req_fwd,
878 RTE_MIN(sizeof(req.vf_req_fwd),
879 sizeof(bp->pf.vf_req_fwd)));
882 * PF can sniff HWRM API issued by VF. This can be set up by
883 * linux driver and inherited by the DPDK PF driver. Clear
884 * this HWRM sniffer list in FW because DPDK PF driver does
887 flags |= HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_FWD_NONE_MODE;
890 req.flags = rte_cpu_to_le_32(flags);
892 req.async_event_fwd[0] |=
893 rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_LINK_STATUS_CHANGE |
894 ASYNC_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED |
895 ASYNC_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE |
896 ASYNC_CMPL_EVENT_ID_LINK_SPEED_CHANGE |
897 ASYNC_CMPL_EVENT_ID_RESET_NOTIFY);
898 if (bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY)
899 req.async_event_fwd[0] |=
900 rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_ERROR_RECOVERY);
901 req.async_event_fwd[1] |=
902 rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_PF_DRVR_UNLOAD |
903 ASYNC_CMPL_EVENT_ID_VF_CFG_CHANGE);
905 req.async_event_fwd[1] |=
906 rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_DBG_NOTIFICATION);
908 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
912 flags = rte_le_to_cpu_32(resp->flags);
913 if (flags & HWRM_FUNC_DRV_RGTR_OUTPUT_FLAGS_IF_CHANGE_SUPPORTED)
914 bp->fw_cap |= BNXT_FW_CAP_IF_CHANGE;
918 bp->flags |= BNXT_FLAG_REGISTERED;
923 int bnxt_hwrm_check_vf_rings(struct bnxt *bp)
925 if (!(BNXT_VF(bp) && (bp->flags & BNXT_FLAG_NEW_RM)))
928 return bnxt_hwrm_func_reserve_vf_resc(bp, true);
931 int bnxt_hwrm_func_reserve_vf_resc(struct bnxt *bp, bool test)
936 struct hwrm_func_vf_cfg_output *resp = bp->hwrm_cmd_resp_addr;
937 struct hwrm_func_vf_cfg_input req = {0};
939 HWRM_PREP(&req, HWRM_FUNC_VF_CFG, BNXT_USE_CHIMP_MB);
941 enables = HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_RX_RINGS |
942 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_TX_RINGS |
943 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
944 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
945 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_VNICS;
947 if (BNXT_HAS_RING_GRPS(bp)) {
948 enables |= HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS;
949 req.num_hw_ring_grps = rte_cpu_to_le_16(bp->rx_nr_rings);
952 req.num_tx_rings = rte_cpu_to_le_16(bp->tx_nr_rings);
953 req.num_rx_rings = rte_cpu_to_le_16(bp->rx_nr_rings *
954 AGG_RING_MULTIPLIER);
955 req.num_stat_ctxs = rte_cpu_to_le_16(bp->rx_nr_rings + bp->tx_nr_rings);
956 req.num_cmpl_rings = rte_cpu_to_le_16(bp->rx_nr_rings +
958 BNXT_NUM_ASYNC_CPR(bp));
959 req.num_vnics = rte_cpu_to_le_16(bp->rx_nr_rings);
960 if (bp->vf_resv_strategy ==
961 HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESV_STRATEGY_MINIMAL_STATIC) {
962 enables |= HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_VNICS |
963 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_L2_CTXS |
964 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS;
965 req.num_rsscos_ctxs = rte_cpu_to_le_16(BNXT_VF_RSV_NUM_RSS_CTX);
966 req.num_l2_ctxs = rte_cpu_to_le_16(BNXT_VF_RSV_NUM_L2_CTX);
967 req.num_vnics = rte_cpu_to_le_16(BNXT_VF_RSV_NUM_VNIC);
968 } else if (bp->vf_resv_strategy ==
969 HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESV_STRATEGY_MAXIMAL) {
970 enables |= HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS;
971 req.num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx);
975 flags = HWRM_FUNC_VF_CFG_INPUT_FLAGS_TX_ASSETS_TEST |
976 HWRM_FUNC_VF_CFG_INPUT_FLAGS_RX_ASSETS_TEST |
977 HWRM_FUNC_VF_CFG_INPUT_FLAGS_CMPL_ASSETS_TEST |
978 HWRM_FUNC_VF_CFG_INPUT_FLAGS_RING_GRP_ASSETS_TEST |
979 HWRM_FUNC_VF_CFG_INPUT_FLAGS_STAT_CTX_ASSETS_TEST |
980 HWRM_FUNC_VF_CFG_INPUT_FLAGS_VNIC_ASSETS_TEST;
982 if (test && BNXT_HAS_RING_GRPS(bp))
983 flags |= HWRM_FUNC_VF_CFG_INPUT_FLAGS_RING_GRP_ASSETS_TEST;
985 req.flags = rte_cpu_to_le_32(flags);
986 req.enables |= rte_cpu_to_le_32(enables);
988 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
991 HWRM_CHECK_RESULT_SILENT();
999 int bnxt_hwrm_func_resc_qcaps(struct bnxt *bp)
1002 struct hwrm_func_resource_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
1003 struct hwrm_func_resource_qcaps_input req = {0};
1005 HWRM_PREP(&req, HWRM_FUNC_RESOURCE_QCAPS, BNXT_USE_CHIMP_MB);
1006 req.fid = rte_cpu_to_le_16(0xffff);
1008 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1010 HWRM_CHECK_RESULT_SILENT();
1013 bp->max_rsscos_ctx = rte_le_to_cpu_16(resp->max_rsscos_ctx);
1014 bp->max_cp_rings = rte_le_to_cpu_16(resp->max_cmpl_rings);
1015 bp->max_tx_rings = rte_le_to_cpu_16(resp->max_tx_rings);
1016 bp->max_rx_rings = rte_le_to_cpu_16(resp->max_rx_rings);
1017 bp->max_ring_grps = rte_le_to_cpu_32(resp->max_hw_ring_grps);
1018 /* func_resource_qcaps does not return max_rx_em_flows.
1019 * So use the value provided by func_qcaps.
1021 bp->max_l2_ctx = rte_le_to_cpu_16(resp->max_l2_ctxs);
1022 if (!BNXT_CHIP_THOR(bp))
1023 bp->max_l2_ctx += bp->max_rx_em_flows;
1024 bp->max_vnics = rte_le_to_cpu_16(resp->max_vnics);
1025 bp->max_stat_ctx = rte_le_to_cpu_16(resp->max_stat_ctx);
1027 bp->max_nq_rings = rte_le_to_cpu_16(resp->max_msix);
1028 bp->vf_resv_strategy = rte_le_to_cpu_16(resp->vf_reservation_strategy);
1029 if (bp->vf_resv_strategy >
1030 HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESV_STRATEGY_MINIMAL_STATIC)
1031 bp->vf_resv_strategy =
1032 HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESERVATION_STRATEGY_MAXIMAL;
1038 int bnxt_hwrm_ver_get(struct bnxt *bp, uint32_t timeout)
1041 struct hwrm_ver_get_input req = {.req_type = 0 };
1042 struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr;
1043 uint32_t fw_version;
1044 uint16_t max_resp_len;
1045 char type[RTE_MEMZONE_NAMESIZE];
1046 uint32_t dev_caps_cfg;
1048 bp->max_req_len = HWRM_MAX_REQ_LEN;
1049 bp->hwrm_cmd_timeout = timeout;
1050 HWRM_PREP(&req, HWRM_VER_GET, BNXT_USE_CHIMP_MB);
1052 req.hwrm_intf_maj = HWRM_VERSION_MAJOR;
1053 req.hwrm_intf_min = HWRM_VERSION_MINOR;
1054 req.hwrm_intf_upd = HWRM_VERSION_UPDATE;
1056 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1058 if (bp->flags & BNXT_FLAG_FW_RESET)
1059 HWRM_CHECK_RESULT_SILENT();
1061 HWRM_CHECK_RESULT();
1063 PMD_DRV_LOG(INFO, "%d.%d.%d:%d.%d.%d\n",
1064 resp->hwrm_intf_maj_8b, resp->hwrm_intf_min_8b,
1065 resp->hwrm_intf_upd_8b, resp->hwrm_fw_maj_8b,
1066 resp->hwrm_fw_min_8b, resp->hwrm_fw_bld_8b);
1067 bp->fw_ver = (resp->hwrm_fw_maj_8b << 24) |
1068 (resp->hwrm_fw_min_8b << 16) |
1069 (resp->hwrm_fw_bld_8b << 8) |
1070 resp->hwrm_fw_rsvd_8b;
1071 PMD_DRV_LOG(INFO, "Driver HWRM version: %d.%d.%d\n",
1072 HWRM_VERSION_MAJOR, HWRM_VERSION_MINOR, HWRM_VERSION_UPDATE);
1074 fw_version = resp->hwrm_intf_maj_8b << 16;
1075 fw_version |= resp->hwrm_intf_min_8b << 8;
1076 fw_version |= resp->hwrm_intf_upd_8b;
1077 bp->hwrm_spec_code = fw_version;
1079 /* def_req_timeout value is in milliseconds */
1080 bp->hwrm_cmd_timeout = rte_le_to_cpu_16(resp->def_req_timeout);
1081 /* convert timeout to usec */
1082 bp->hwrm_cmd_timeout *= 1000;
1083 if (!bp->hwrm_cmd_timeout)
1084 bp->hwrm_cmd_timeout = DFLT_HWRM_CMD_TIMEOUT;
1086 if (resp->hwrm_intf_maj_8b != HWRM_VERSION_MAJOR) {
1087 PMD_DRV_LOG(ERR, "Unsupported firmware API version\n");
1092 if (bp->max_req_len > resp->max_req_win_len) {
1093 PMD_DRV_LOG(ERR, "Unsupported request length\n");
1096 bp->max_req_len = rte_le_to_cpu_16(resp->max_req_win_len);
1097 bp->hwrm_max_ext_req_len = rte_le_to_cpu_16(resp->max_ext_req_len);
1098 if (bp->hwrm_max_ext_req_len < HWRM_MAX_REQ_LEN)
1099 bp->hwrm_max_ext_req_len = HWRM_MAX_REQ_LEN;
1101 max_resp_len = rte_le_to_cpu_16(resp->max_resp_len);
1102 dev_caps_cfg = rte_le_to_cpu_32(resp->dev_caps_cfg);
1104 if (bp->max_resp_len != max_resp_len) {
1105 sprintf(type, "bnxt_hwrm_%04x:%02x:%02x:%02x",
1106 bp->pdev->addr.domain, bp->pdev->addr.bus,
1107 bp->pdev->addr.devid, bp->pdev->addr.function);
1109 rte_free(bp->hwrm_cmd_resp_addr);
1111 bp->hwrm_cmd_resp_addr = rte_malloc(type, max_resp_len, 0);
1112 if (bp->hwrm_cmd_resp_addr == NULL) {
1116 bp->hwrm_cmd_resp_dma_addr =
1117 rte_malloc_virt2iova(bp->hwrm_cmd_resp_addr);
1118 if (bp->hwrm_cmd_resp_dma_addr == RTE_BAD_IOVA) {
1120 "Unable to map response buffer to physical memory.\n");
1124 bp->max_resp_len = max_resp_len;
1128 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
1130 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_REQUIRED)) {
1131 PMD_DRV_LOG(DEBUG, "Short command supported\n");
1132 bp->flags |= BNXT_FLAG_SHORT_CMD;
1135 if (((dev_caps_cfg &
1136 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
1138 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_REQUIRED)) ||
1139 bp->hwrm_max_ext_req_len > HWRM_MAX_REQ_LEN) {
1140 sprintf(type, "bnxt_hwrm_short_%04x:%02x:%02x:%02x",
1141 bp->pdev->addr.domain, bp->pdev->addr.bus,
1142 bp->pdev->addr.devid, bp->pdev->addr.function);
1144 rte_free(bp->hwrm_short_cmd_req_addr);
1146 bp->hwrm_short_cmd_req_addr =
1147 rte_malloc(type, bp->hwrm_max_ext_req_len, 0);
1148 if (bp->hwrm_short_cmd_req_addr == NULL) {
1152 bp->hwrm_short_cmd_req_dma_addr =
1153 rte_malloc_virt2iova(bp->hwrm_short_cmd_req_addr);
1154 if (bp->hwrm_short_cmd_req_dma_addr == RTE_BAD_IOVA) {
1155 rte_free(bp->hwrm_short_cmd_req_addr);
1157 "Unable to map buffer to physical memory.\n");
1163 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_KONG_MB_CHNL_SUPPORTED) {
1164 bp->flags |= BNXT_FLAG_KONG_MB_EN;
1165 PMD_DRV_LOG(DEBUG, "Kong mailbox channel enabled\n");
1168 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_TRUSTED_VF_SUPPORTED)
1169 PMD_DRV_LOG(DEBUG, "FW supports Trusted VFs\n");
1171 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_CFA_ADV_FLOW_MGNT_SUPPORTED) {
1172 bp->flags |= BNXT_FLAG_ADV_FLOW_MGMT;
1173 PMD_DRV_LOG(DEBUG, "FW supports advanced flow management\n");
1181 int bnxt_hwrm_func_driver_unregister(struct bnxt *bp, uint32_t flags)
1184 struct hwrm_func_drv_unrgtr_input req = {.req_type = 0 };
1185 struct hwrm_func_drv_unrgtr_output *resp = bp->hwrm_cmd_resp_addr;
1187 if (!(bp->flags & BNXT_FLAG_REGISTERED))
1190 HWRM_PREP(&req, HWRM_FUNC_DRV_UNRGTR, BNXT_USE_CHIMP_MB);
1193 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1195 HWRM_CHECK_RESULT();
1201 static int bnxt_hwrm_port_phy_cfg(struct bnxt *bp, struct bnxt_link_info *conf)
1204 struct hwrm_port_phy_cfg_input req = {0};
1205 struct hwrm_port_phy_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1206 uint32_t enables = 0;
1208 HWRM_PREP(&req, HWRM_PORT_PHY_CFG, BNXT_USE_CHIMP_MB);
1210 if (conf->link_up) {
1211 /* Setting Fixed Speed. But AutoNeg is ON, So disable it */
1212 if (bp->link_info.auto_mode && conf->link_speed) {
1213 req.auto_mode = HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_NONE;
1214 PMD_DRV_LOG(DEBUG, "Disabling AutoNeg\n");
1217 req.flags = rte_cpu_to_le_32(conf->phy_flags);
1218 req.force_link_speed = rte_cpu_to_le_16(conf->link_speed);
1219 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_MODE;
1221 * Note, ChiMP FW 20.2.1 and 20.2.2 return an error when we set
1222 * any auto mode, even "none".
1224 if (!conf->link_speed) {
1225 /* No speeds specified. Enable AutoNeg - all speeds */
1227 HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_ALL_SPEEDS;
1229 /* AutoNeg - Advertise speeds specified. */
1230 if (conf->auto_link_speed_mask &&
1231 !(conf->phy_flags & HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE)) {
1233 HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_SPEED_MASK;
1234 req.auto_link_speed_mask =
1235 conf->auto_link_speed_mask;
1237 HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_LINK_SPEED_MASK;
1240 req.auto_duplex = conf->duplex;
1241 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_DUPLEX;
1242 req.auto_pause = conf->auto_pause;
1243 req.force_pause = conf->force_pause;
1244 /* Set force_pause if there is no auto or if there is a force */
1245 if (req.auto_pause && !req.force_pause)
1246 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_PAUSE;
1248 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_FORCE_PAUSE;
1250 req.enables = rte_cpu_to_le_32(enables);
1253 rte_cpu_to_le_32(HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE_LINK_DWN);
1254 PMD_DRV_LOG(INFO, "Force Link Down\n");
1257 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1259 HWRM_CHECK_RESULT();
1265 static int bnxt_hwrm_port_phy_qcfg(struct bnxt *bp,
1266 struct bnxt_link_info *link_info)
1269 struct hwrm_port_phy_qcfg_input req = {0};
1270 struct hwrm_port_phy_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
1272 HWRM_PREP(&req, HWRM_PORT_PHY_QCFG, BNXT_USE_CHIMP_MB);
1274 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1276 HWRM_CHECK_RESULT();
1278 link_info->phy_link_status = resp->link;
1279 link_info->link_up =
1280 (link_info->phy_link_status ==
1281 HWRM_PORT_PHY_QCFG_OUTPUT_LINK_LINK) ? 1 : 0;
1282 link_info->link_speed = rte_le_to_cpu_16(resp->link_speed);
1283 link_info->duplex = resp->duplex_cfg;
1284 link_info->pause = resp->pause;
1285 link_info->auto_pause = resp->auto_pause;
1286 link_info->force_pause = resp->force_pause;
1287 link_info->auto_mode = resp->auto_mode;
1288 link_info->phy_type = resp->phy_type;
1289 link_info->media_type = resp->media_type;
1291 link_info->support_speeds = rte_le_to_cpu_16(resp->support_speeds);
1292 link_info->auto_link_speed = rte_le_to_cpu_16(resp->auto_link_speed);
1293 link_info->preemphasis = rte_le_to_cpu_32(resp->preemphasis);
1294 link_info->force_link_speed = rte_le_to_cpu_16(resp->force_link_speed);
1295 link_info->phy_ver[0] = resp->phy_maj;
1296 link_info->phy_ver[1] = resp->phy_min;
1297 link_info->phy_ver[2] = resp->phy_bld;
1301 PMD_DRV_LOG(DEBUG, "Link Speed %d\n", link_info->link_speed);
1302 PMD_DRV_LOG(DEBUG, "Auto Mode %d\n", link_info->auto_mode);
1303 PMD_DRV_LOG(DEBUG, "Support Speeds %x\n", link_info->support_speeds);
1304 PMD_DRV_LOG(DEBUG, "Auto Link Speed %x\n", link_info->auto_link_speed);
1305 PMD_DRV_LOG(DEBUG, "Auto Link Speed Mask %x\n",
1306 link_info->auto_link_speed_mask);
1307 PMD_DRV_LOG(DEBUG, "Forced Link Speed %x\n",
1308 link_info->force_link_speed);
1313 static bool bnxt_find_lossy_profile(struct bnxt *bp)
1317 for (i = BNXT_COS_QUEUE_COUNT - 1; i >= 0; i--) {
1318 if (bp->tx_cos_queue[i].profile ==
1319 HWRM_QUEUE_SERVICE_PROFILE_LOSSY) {
1320 bp->tx_cosq_id[0] = bp->tx_cos_queue[i].id;
1327 static void bnxt_find_first_valid_profile(struct bnxt *bp)
1331 for (i = BNXT_COS_QUEUE_COUNT - 1; i >= 0; i--) {
1332 if (bp->tx_cos_queue[i].profile !=
1333 HWRM_QUEUE_SERVICE_PROFILE_UNKNOWN &&
1334 bp->tx_cos_queue[i].id !=
1335 HWRM_QUEUE_SERVICE_PROFILE_UNKNOWN) {
1336 bp->tx_cosq_id[0] = bp->tx_cos_queue[i].id;
1342 int bnxt_hwrm_queue_qportcfg(struct bnxt *bp)
1345 struct hwrm_queue_qportcfg_input req = {.req_type = 0 };
1346 struct hwrm_queue_qportcfg_output *resp = bp->hwrm_cmd_resp_addr;
1347 uint32_t dir = HWRM_QUEUE_QPORTCFG_INPUT_FLAGS_PATH_TX;
1351 HWRM_PREP(&req, HWRM_QUEUE_QPORTCFG, BNXT_USE_CHIMP_MB);
1353 req.flags = rte_cpu_to_le_32(dir);
1354 /* HWRM Version >= 1.9.1 only if COS Classification is not required. */
1355 if (bp->hwrm_spec_code >= HWRM_VERSION_1_9_1 &&
1356 !(bp->vnic_cap_flags & BNXT_VNIC_CAP_COS_CLASSIFY))
1358 HWRM_QUEUE_QPORTCFG_INPUT_DRV_QMAP_CAP_ENABLED;
1359 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1361 HWRM_CHECK_RESULT();
1363 if (dir == HWRM_QUEUE_QPORTCFG_INPUT_FLAGS_PATH_TX) {
1364 GET_TX_QUEUE_INFO(0);
1365 GET_TX_QUEUE_INFO(1);
1366 GET_TX_QUEUE_INFO(2);
1367 GET_TX_QUEUE_INFO(3);
1368 GET_TX_QUEUE_INFO(4);
1369 GET_TX_QUEUE_INFO(5);
1370 GET_TX_QUEUE_INFO(6);
1371 GET_TX_QUEUE_INFO(7);
1373 GET_RX_QUEUE_INFO(0);
1374 GET_RX_QUEUE_INFO(1);
1375 GET_RX_QUEUE_INFO(2);
1376 GET_RX_QUEUE_INFO(3);
1377 GET_RX_QUEUE_INFO(4);
1378 GET_RX_QUEUE_INFO(5);
1379 GET_RX_QUEUE_INFO(6);
1380 GET_RX_QUEUE_INFO(7);
1385 if (dir == HWRM_QUEUE_QPORTCFG_INPUT_FLAGS_PATH_RX)
1388 if (bp->hwrm_spec_code < HWRM_VERSION_1_9_1) {
1389 bp->tx_cosq_id[0] = bp->tx_cos_queue[0].id;
1393 /* iterate and find the COSq profile to use for Tx */
1394 if (bp->vnic_cap_flags & BNXT_VNIC_CAP_COS_CLASSIFY) {
1395 for (j = 0, i = 0; i < BNXT_COS_QUEUE_COUNT; i++) {
1396 if (bp->tx_cos_queue[i].id != 0xff)
1397 bp->tx_cosq_id[j++] =
1398 bp->tx_cos_queue[i].id;
1401 /* When CoS classification is disabled, for normal NIC
1402 * operations, ideally we should look to use LOSSY.
1403 * If not found, fallback to the first valid profile
1405 if (!bnxt_find_lossy_profile(bp))
1406 bnxt_find_first_valid_profile(bp);
1411 bp->max_tc = resp->max_configurable_queues;
1412 bp->max_lltc = resp->max_configurable_lossless_queues;
1413 if (bp->max_tc > BNXT_MAX_QUEUE)
1414 bp->max_tc = BNXT_MAX_QUEUE;
1415 bp->max_q = bp->max_tc;
1417 if (dir == HWRM_QUEUE_QPORTCFG_INPUT_FLAGS_PATH_TX) {
1418 dir = HWRM_QUEUE_QPORTCFG_INPUT_FLAGS_PATH_RX;
1426 int bnxt_hwrm_ring_alloc(struct bnxt *bp,
1427 struct bnxt_ring *ring,
1428 uint32_t ring_type, uint32_t map_index,
1429 uint32_t stats_ctx_id, uint32_t cmpl_ring_id,
1430 uint16_t tx_cosq_id)
1433 uint32_t enables = 0;
1434 struct hwrm_ring_alloc_input req = {.req_type = 0 };
1435 struct hwrm_ring_alloc_output *resp = bp->hwrm_cmd_resp_addr;
1436 struct rte_mempool *mb_pool;
1437 uint16_t rx_buf_size;
1439 HWRM_PREP(&req, HWRM_RING_ALLOC, BNXT_USE_CHIMP_MB);
1441 req.page_tbl_addr = rte_cpu_to_le_64(ring->bd_dma);
1442 req.fbo = rte_cpu_to_le_32(0);
1443 /* Association of ring index with doorbell index */
1444 req.logical_id = rte_cpu_to_le_16(map_index);
1445 req.length = rte_cpu_to_le_32(ring->ring_size);
1447 switch (ring_type) {
1448 case HWRM_RING_ALLOC_INPUT_RING_TYPE_TX:
1449 req.ring_type = ring_type;
1450 req.cmpl_ring_id = rte_cpu_to_le_16(cmpl_ring_id);
1451 req.stat_ctx_id = rte_cpu_to_le_32(stats_ctx_id);
1452 req.queue_id = rte_cpu_to_le_16(tx_cosq_id);
1453 if (stats_ctx_id != INVALID_STATS_CTX_ID)
1455 HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID;
1457 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX:
1458 req.ring_type = ring_type;
1459 req.cmpl_ring_id = rte_cpu_to_le_16(cmpl_ring_id);
1460 req.stat_ctx_id = rte_cpu_to_le_32(stats_ctx_id);
1461 if (BNXT_CHIP_THOR(bp)) {
1462 mb_pool = bp->rx_queues[0]->mb_pool;
1463 rx_buf_size = rte_pktmbuf_data_room_size(mb_pool) -
1464 RTE_PKTMBUF_HEADROOM;
1465 rx_buf_size = RTE_MIN(BNXT_MAX_PKT_LEN, rx_buf_size);
1466 req.rx_buf_size = rte_cpu_to_le_16(rx_buf_size);
1468 HWRM_RING_ALLOC_INPUT_ENABLES_RX_BUF_SIZE_VALID;
1470 if (stats_ctx_id != INVALID_STATS_CTX_ID)
1472 HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID;
1474 case HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL:
1475 req.ring_type = ring_type;
1476 if (BNXT_HAS_NQ(bp)) {
1477 /* Association of cp ring with nq */
1478 req.nq_ring_id = rte_cpu_to_le_16(cmpl_ring_id);
1480 HWRM_RING_ALLOC_INPUT_ENABLES_NQ_RING_ID_VALID;
1482 req.int_mode = HWRM_RING_ALLOC_INPUT_INT_MODE_MSIX;
1484 case HWRM_RING_ALLOC_INPUT_RING_TYPE_NQ:
1485 req.ring_type = ring_type;
1486 req.page_size = BNXT_PAGE_SHFT;
1487 req.int_mode = HWRM_RING_ALLOC_INPUT_INT_MODE_MSIX;
1489 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX_AGG:
1490 req.ring_type = ring_type;
1491 req.rx_ring_id = rte_cpu_to_le_16(ring->fw_rx_ring_id);
1493 mb_pool = bp->rx_queues[0]->mb_pool;
1494 rx_buf_size = rte_pktmbuf_data_room_size(mb_pool) -
1495 RTE_PKTMBUF_HEADROOM;
1496 rx_buf_size = RTE_MIN(BNXT_MAX_PKT_LEN, rx_buf_size);
1497 req.rx_buf_size = rte_cpu_to_le_16(rx_buf_size);
1499 req.stat_ctx_id = rte_cpu_to_le_32(stats_ctx_id);
1500 enables |= HWRM_RING_ALLOC_INPUT_ENABLES_RX_RING_ID_VALID |
1501 HWRM_RING_ALLOC_INPUT_ENABLES_RX_BUF_SIZE_VALID |
1502 HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID;
1505 PMD_DRV_LOG(ERR, "hwrm alloc invalid ring type %d\n",
1510 req.enables = rte_cpu_to_le_32(enables);
1512 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1514 if (rc || resp->error_code) {
1515 if (rc == 0 && resp->error_code)
1516 rc = rte_le_to_cpu_16(resp->error_code);
1517 switch (ring_type) {
1518 case HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL:
1520 "hwrm_ring_alloc cp failed. rc:%d\n", rc);
1523 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX:
1525 "hwrm_ring_alloc rx failed. rc:%d\n", rc);
1528 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX_AGG:
1530 "hwrm_ring_alloc rx agg failed. rc:%d\n",
1534 case HWRM_RING_ALLOC_INPUT_RING_TYPE_TX:
1536 "hwrm_ring_alloc tx failed. rc:%d\n", rc);
1539 case HWRM_RING_ALLOC_INPUT_RING_TYPE_NQ:
1541 "hwrm_ring_alloc nq failed. rc:%d\n", rc);
1545 PMD_DRV_LOG(ERR, "Invalid ring. rc:%d\n", rc);
1551 ring->fw_ring_id = rte_le_to_cpu_16(resp->ring_id);
1556 int bnxt_hwrm_ring_free(struct bnxt *bp,
1557 struct bnxt_ring *ring, uint32_t ring_type)
1560 struct hwrm_ring_free_input req = {.req_type = 0 };
1561 struct hwrm_ring_free_output *resp = bp->hwrm_cmd_resp_addr;
1563 HWRM_PREP(&req, HWRM_RING_FREE, BNXT_USE_CHIMP_MB);
1565 req.ring_type = ring_type;
1566 req.ring_id = rte_cpu_to_le_16(ring->fw_ring_id);
1568 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1570 if (rc || resp->error_code) {
1571 if (rc == 0 && resp->error_code)
1572 rc = rte_le_to_cpu_16(resp->error_code);
1575 switch (ring_type) {
1576 case HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL:
1577 PMD_DRV_LOG(ERR, "hwrm_ring_free cp failed. rc:%d\n",
1580 case HWRM_RING_FREE_INPUT_RING_TYPE_RX:
1581 PMD_DRV_LOG(ERR, "hwrm_ring_free rx failed. rc:%d\n",
1584 case HWRM_RING_FREE_INPUT_RING_TYPE_TX:
1585 PMD_DRV_LOG(ERR, "hwrm_ring_free tx failed. rc:%d\n",
1588 case HWRM_RING_FREE_INPUT_RING_TYPE_NQ:
1590 "hwrm_ring_free nq failed. rc:%d\n", rc);
1592 case HWRM_RING_FREE_INPUT_RING_TYPE_RX_AGG:
1594 "hwrm_ring_free agg failed. rc:%d\n", rc);
1597 PMD_DRV_LOG(ERR, "Invalid ring, rc:%d\n", rc);
1605 int bnxt_hwrm_ring_grp_alloc(struct bnxt *bp, unsigned int idx)
1608 struct hwrm_ring_grp_alloc_input req = {.req_type = 0 };
1609 struct hwrm_ring_grp_alloc_output *resp = bp->hwrm_cmd_resp_addr;
1611 HWRM_PREP(&req, HWRM_RING_GRP_ALLOC, BNXT_USE_CHIMP_MB);
1613 req.cr = rte_cpu_to_le_16(bp->grp_info[idx].cp_fw_ring_id);
1614 req.rr = rte_cpu_to_le_16(bp->grp_info[idx].rx_fw_ring_id);
1615 req.ar = rte_cpu_to_le_16(bp->grp_info[idx].ag_fw_ring_id);
1616 req.sc = rte_cpu_to_le_16(bp->grp_info[idx].fw_stats_ctx);
1618 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1620 HWRM_CHECK_RESULT();
1622 bp->grp_info[idx].fw_grp_id = rte_le_to_cpu_16(resp->ring_group_id);
1629 int bnxt_hwrm_ring_grp_free(struct bnxt *bp, unsigned int idx)
1632 struct hwrm_ring_grp_free_input req = {.req_type = 0 };
1633 struct hwrm_ring_grp_free_output *resp = bp->hwrm_cmd_resp_addr;
1635 HWRM_PREP(&req, HWRM_RING_GRP_FREE, BNXT_USE_CHIMP_MB);
1637 req.ring_group_id = rte_cpu_to_le_16(bp->grp_info[idx].fw_grp_id);
1639 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1641 HWRM_CHECK_RESULT();
1644 bp->grp_info[idx].fw_grp_id = INVALID_HW_RING_ID;
1648 int bnxt_hwrm_stat_clear(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
1651 struct hwrm_stat_ctx_clr_stats_input req = {.req_type = 0 };
1652 struct hwrm_stat_ctx_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
1654 if (cpr->hw_stats_ctx_id == (uint32_t)HWRM_NA_SIGNATURE)
1657 HWRM_PREP(&req, HWRM_STAT_CTX_CLR_STATS, BNXT_USE_CHIMP_MB);
1659 req.stat_ctx_id = rte_cpu_to_le_32(cpr->hw_stats_ctx_id);
1661 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1663 HWRM_CHECK_RESULT();
1669 int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
1670 unsigned int idx __rte_unused)
1673 struct hwrm_stat_ctx_alloc_input req = {.req_type = 0 };
1674 struct hwrm_stat_ctx_alloc_output *resp = bp->hwrm_cmd_resp_addr;
1676 HWRM_PREP(&req, HWRM_STAT_CTX_ALLOC, BNXT_USE_CHIMP_MB);
1678 req.update_period_ms = rte_cpu_to_le_32(0);
1680 req.stats_dma_addr = rte_cpu_to_le_64(cpr->hw_stats_map);
1682 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1684 HWRM_CHECK_RESULT();
1686 cpr->hw_stats_ctx_id = rte_le_to_cpu_32(resp->stat_ctx_id);
1693 int bnxt_hwrm_stat_ctx_free(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
1694 unsigned int idx __rte_unused)
1697 struct hwrm_stat_ctx_free_input req = {.req_type = 0 };
1698 struct hwrm_stat_ctx_free_output *resp = bp->hwrm_cmd_resp_addr;
1700 HWRM_PREP(&req, HWRM_STAT_CTX_FREE, BNXT_USE_CHIMP_MB);
1702 req.stat_ctx_id = rte_cpu_to_le_32(cpr->hw_stats_ctx_id);
1704 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1706 HWRM_CHECK_RESULT();
1712 int bnxt_hwrm_vnic_alloc(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1715 struct hwrm_vnic_alloc_input req = { 0 };
1716 struct hwrm_vnic_alloc_output *resp = bp->hwrm_cmd_resp_addr;
1718 if (!BNXT_HAS_RING_GRPS(bp))
1719 goto skip_ring_grps;
1721 /* map ring groups to this vnic */
1722 PMD_DRV_LOG(DEBUG, "Alloc VNIC. Start %x, End %x\n",
1723 vnic->start_grp_id, vnic->end_grp_id);
1724 for (i = vnic->start_grp_id, j = 0; i < vnic->end_grp_id; i++, j++)
1725 vnic->fw_grp_ids[j] = bp->grp_info[i].fw_grp_id;
1727 vnic->dflt_ring_grp = bp->grp_info[vnic->start_grp_id].fw_grp_id;
1728 vnic->rss_rule = (uint16_t)HWRM_NA_SIGNATURE;
1729 vnic->cos_rule = (uint16_t)HWRM_NA_SIGNATURE;
1730 vnic->lb_rule = (uint16_t)HWRM_NA_SIGNATURE;
1733 vnic->mru = BNXT_VNIC_MRU(bp->eth_dev->data->mtu);
1734 HWRM_PREP(&req, HWRM_VNIC_ALLOC, BNXT_USE_CHIMP_MB);
1736 if (vnic->func_default)
1738 rte_cpu_to_le_32(HWRM_VNIC_ALLOC_INPUT_FLAGS_DEFAULT);
1739 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1741 HWRM_CHECK_RESULT();
1743 vnic->fw_vnic_id = rte_le_to_cpu_16(resp->vnic_id);
1745 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
1749 static int bnxt_hwrm_vnic_plcmodes_qcfg(struct bnxt *bp,
1750 struct bnxt_vnic_info *vnic,
1751 struct bnxt_plcmodes_cfg *pmode)
1754 struct hwrm_vnic_plcmodes_qcfg_input req = {.req_type = 0 };
1755 struct hwrm_vnic_plcmodes_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
1757 HWRM_PREP(&req, HWRM_VNIC_PLCMODES_QCFG, BNXT_USE_CHIMP_MB);
1759 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1761 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1763 HWRM_CHECK_RESULT();
1765 pmode->flags = rte_le_to_cpu_32(resp->flags);
1766 /* dflt_vnic bit doesn't exist in the _cfg command */
1767 pmode->flags &= ~(HWRM_VNIC_PLCMODES_QCFG_OUTPUT_FLAGS_DFLT_VNIC);
1768 pmode->jumbo_thresh = rte_le_to_cpu_16(resp->jumbo_thresh);
1769 pmode->hds_offset = rte_le_to_cpu_16(resp->hds_offset);
1770 pmode->hds_threshold = rte_le_to_cpu_16(resp->hds_threshold);
1777 static int bnxt_hwrm_vnic_plcmodes_cfg(struct bnxt *bp,
1778 struct bnxt_vnic_info *vnic,
1779 struct bnxt_plcmodes_cfg *pmode)
1782 struct hwrm_vnic_plcmodes_cfg_input req = {.req_type = 0 };
1783 struct hwrm_vnic_plcmodes_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1785 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1786 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
1790 HWRM_PREP(&req, HWRM_VNIC_PLCMODES_CFG, BNXT_USE_CHIMP_MB);
1792 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1793 req.flags = rte_cpu_to_le_32(pmode->flags);
1794 req.jumbo_thresh = rte_cpu_to_le_16(pmode->jumbo_thresh);
1795 req.hds_offset = rte_cpu_to_le_16(pmode->hds_offset);
1796 req.hds_threshold = rte_cpu_to_le_16(pmode->hds_threshold);
1797 req.enables = rte_cpu_to_le_32(
1798 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_HDS_THRESHOLD_VALID |
1799 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_HDS_OFFSET_VALID |
1800 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_JUMBO_THRESH_VALID
1803 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1805 HWRM_CHECK_RESULT();
1811 int bnxt_hwrm_vnic_cfg(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1814 struct hwrm_vnic_cfg_input req = {.req_type = 0 };
1815 struct hwrm_vnic_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1816 struct bnxt_plcmodes_cfg pmodes = { 0 };
1817 uint32_t ctx_enable_flag = 0;
1818 uint32_t enables = 0;
1820 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1821 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
1825 rc = bnxt_hwrm_vnic_plcmodes_qcfg(bp, vnic, &pmodes);
1829 HWRM_PREP(&req, HWRM_VNIC_CFG, BNXT_USE_CHIMP_MB);
1831 if (BNXT_CHIP_THOR(bp)) {
1832 int dflt_rxq = vnic->start_grp_id;
1833 struct bnxt_rx_ring_info *rxr;
1834 struct bnxt_cp_ring_info *cpr;
1835 struct bnxt_rx_queue *rxq;
1839 * The first active receive ring is used as the VNIC
1840 * default receive ring. If there are no active receive
1841 * rings (all corresponding receive queues are stopped),
1842 * the first receive ring is used.
1844 for (i = vnic->start_grp_id; i < vnic->end_grp_id; i++) {
1845 rxq = bp->eth_dev->data->rx_queues[i];
1846 if (rxq->rx_started) {
1852 rxq = bp->eth_dev->data->rx_queues[dflt_rxq];
1856 req.default_rx_ring_id =
1857 rte_cpu_to_le_16(rxr->rx_ring_struct->fw_ring_id);
1858 req.default_cmpl_ring_id =
1859 rte_cpu_to_le_16(cpr->cp_ring_struct->fw_ring_id);
1860 enables = HWRM_VNIC_CFG_INPUT_ENABLES_DEFAULT_RX_RING_ID |
1861 HWRM_VNIC_CFG_INPUT_ENABLES_DEFAULT_CMPL_RING_ID;
1865 /* Only RSS support for now TBD: COS & LB */
1866 enables = HWRM_VNIC_CFG_INPUT_ENABLES_DFLT_RING_GRP;
1867 if (vnic->lb_rule != 0xffff)
1868 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_LB_RULE;
1869 if (vnic->cos_rule != 0xffff)
1870 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_COS_RULE;
1871 if (vnic->rss_rule != (uint16_t)HWRM_NA_SIGNATURE) {
1872 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_MRU;
1873 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_RSS_RULE;
1875 if (bp->vnic_cap_flags & BNXT_VNIC_CAP_COS_CLASSIFY) {
1876 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_QUEUE_ID;
1877 req.queue_id = rte_cpu_to_le_16(vnic->cos_queue_id);
1880 enables |= ctx_enable_flag;
1881 req.dflt_ring_grp = rte_cpu_to_le_16(vnic->dflt_ring_grp);
1882 req.rss_rule = rte_cpu_to_le_16(vnic->rss_rule);
1883 req.cos_rule = rte_cpu_to_le_16(vnic->cos_rule);
1884 req.lb_rule = rte_cpu_to_le_16(vnic->lb_rule);
1887 req.enables = rte_cpu_to_le_32(enables);
1888 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1889 req.mru = rte_cpu_to_le_16(vnic->mru);
1890 /* Configure default VNIC only once. */
1891 if (vnic->func_default && !(bp->flags & BNXT_FLAG_DFLT_VNIC_SET)) {
1893 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_DEFAULT);
1894 bp->flags |= BNXT_FLAG_DFLT_VNIC_SET;
1896 if (vnic->vlan_strip)
1898 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_VLAN_STRIP_MODE);
1901 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_BD_STALL_MODE);
1902 if (vnic->roce_dual)
1903 req.flags |= rte_cpu_to_le_32(
1904 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_DUAL_VNIC_MODE);
1905 if (vnic->roce_only)
1906 req.flags |= rte_cpu_to_le_32(
1907 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_ONLY_VNIC_MODE);
1908 if (vnic->rss_dflt_cr)
1909 req.flags |= rte_cpu_to_le_32(
1910 HWRM_VNIC_QCFG_OUTPUT_FLAGS_RSS_DFLT_CR_MODE);
1912 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1914 HWRM_CHECK_RESULT();
1917 rc = bnxt_hwrm_vnic_plcmodes_cfg(bp, vnic, &pmodes);
1922 int bnxt_hwrm_vnic_qcfg(struct bnxt *bp, struct bnxt_vnic_info *vnic,
1926 struct hwrm_vnic_qcfg_input req = {.req_type = 0 };
1927 struct hwrm_vnic_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
1929 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1930 PMD_DRV_LOG(DEBUG, "VNIC QCFG ID %d\n", vnic->fw_vnic_id);
1933 HWRM_PREP(&req, HWRM_VNIC_QCFG, BNXT_USE_CHIMP_MB);
1936 rte_cpu_to_le_32(HWRM_VNIC_QCFG_INPUT_ENABLES_VF_ID_VALID);
1937 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1938 req.vf_id = rte_cpu_to_le_16(fw_vf_id);
1940 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1942 HWRM_CHECK_RESULT();
1944 vnic->dflt_ring_grp = rte_le_to_cpu_16(resp->dflt_ring_grp);
1945 vnic->rss_rule = rte_le_to_cpu_16(resp->rss_rule);
1946 vnic->cos_rule = rte_le_to_cpu_16(resp->cos_rule);
1947 vnic->lb_rule = rte_le_to_cpu_16(resp->lb_rule);
1948 vnic->mru = rte_le_to_cpu_16(resp->mru);
1949 vnic->func_default = rte_le_to_cpu_32(
1950 resp->flags) & HWRM_VNIC_QCFG_OUTPUT_FLAGS_DEFAULT;
1951 vnic->vlan_strip = rte_le_to_cpu_32(resp->flags) &
1952 HWRM_VNIC_QCFG_OUTPUT_FLAGS_VLAN_STRIP_MODE;
1953 vnic->bd_stall = rte_le_to_cpu_32(resp->flags) &
1954 HWRM_VNIC_QCFG_OUTPUT_FLAGS_BD_STALL_MODE;
1955 vnic->roce_dual = rte_le_to_cpu_32(resp->flags) &
1956 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_DUAL_VNIC_MODE;
1957 vnic->roce_only = rte_le_to_cpu_32(resp->flags) &
1958 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_ONLY_VNIC_MODE;
1959 vnic->rss_dflt_cr = rte_le_to_cpu_32(resp->flags) &
1960 HWRM_VNIC_QCFG_OUTPUT_FLAGS_RSS_DFLT_CR_MODE;
1967 int bnxt_hwrm_vnic_ctx_alloc(struct bnxt *bp,
1968 struct bnxt_vnic_info *vnic, uint16_t ctx_idx)
1972 struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req = {.req_type = 0 };
1973 struct hwrm_vnic_rss_cos_lb_ctx_alloc_output *resp =
1974 bp->hwrm_cmd_resp_addr;
1976 HWRM_PREP(&req, HWRM_VNIC_RSS_COS_LB_CTX_ALLOC, BNXT_USE_CHIMP_MB);
1978 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1979 HWRM_CHECK_RESULT();
1981 ctx_id = rte_le_to_cpu_16(resp->rss_cos_lb_ctx_id);
1982 if (!BNXT_HAS_RING_GRPS(bp))
1983 vnic->fw_grp_ids[ctx_idx] = ctx_id;
1984 else if (ctx_idx == 0)
1985 vnic->rss_rule = ctx_id;
1993 int _bnxt_hwrm_vnic_ctx_free(struct bnxt *bp,
1994 struct bnxt_vnic_info *vnic, uint16_t ctx_idx)
1997 struct hwrm_vnic_rss_cos_lb_ctx_free_input req = {.req_type = 0 };
1998 struct hwrm_vnic_rss_cos_lb_ctx_free_output *resp =
1999 bp->hwrm_cmd_resp_addr;
2001 if (ctx_idx == (uint16_t)HWRM_NA_SIGNATURE) {
2002 PMD_DRV_LOG(DEBUG, "VNIC RSS Rule %x\n", vnic->rss_rule);
2005 HWRM_PREP(&req, HWRM_VNIC_RSS_COS_LB_CTX_FREE, BNXT_USE_CHIMP_MB);
2007 req.rss_cos_lb_ctx_id = rte_cpu_to_le_16(ctx_idx);
2009 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2011 HWRM_CHECK_RESULT();
2017 int bnxt_hwrm_vnic_ctx_free(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2021 if (BNXT_CHIP_THOR(bp)) {
2024 for (j = 0; j < vnic->num_lb_ctxts; j++) {
2025 rc = _bnxt_hwrm_vnic_ctx_free(bp,
2027 vnic->fw_grp_ids[j]);
2028 vnic->fw_grp_ids[j] = INVALID_HW_RING_ID;
2030 vnic->num_lb_ctxts = 0;
2032 rc = _bnxt_hwrm_vnic_ctx_free(bp, vnic, vnic->rss_rule);
2033 vnic->rss_rule = INVALID_HW_RING_ID;
2039 int bnxt_hwrm_vnic_free(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2042 struct hwrm_vnic_free_input req = {.req_type = 0 };
2043 struct hwrm_vnic_free_output *resp = bp->hwrm_cmd_resp_addr;
2045 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
2046 PMD_DRV_LOG(DEBUG, "VNIC FREE ID %x\n", vnic->fw_vnic_id);
2050 HWRM_PREP(&req, HWRM_VNIC_FREE, BNXT_USE_CHIMP_MB);
2052 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
2054 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2056 HWRM_CHECK_RESULT();
2059 vnic->fw_vnic_id = INVALID_HW_RING_ID;
2060 /* Configure default VNIC again if necessary. */
2061 if (vnic->func_default && (bp->flags & BNXT_FLAG_DFLT_VNIC_SET))
2062 bp->flags &= ~BNXT_FLAG_DFLT_VNIC_SET;
2068 bnxt_hwrm_vnic_rss_cfg_thor(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2072 int nr_ctxs = vnic->num_lb_ctxts;
2073 struct hwrm_vnic_rss_cfg_input req = {.req_type = 0 };
2074 struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2076 for (i = 0; i < nr_ctxs; i++) {
2077 HWRM_PREP(&req, HWRM_VNIC_RSS_CFG, BNXT_USE_CHIMP_MB);
2079 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
2080 req.hash_type = rte_cpu_to_le_32(vnic->hash_type);
2081 req.hash_mode_flags = vnic->hash_mode;
2083 req.hash_key_tbl_addr =
2084 rte_cpu_to_le_64(vnic->rss_hash_key_dma_addr);
2086 req.ring_grp_tbl_addr =
2087 rte_cpu_to_le_64(vnic->rss_table_dma_addr +
2088 i * HW_HASH_INDEX_SIZE);
2089 req.ring_table_pair_index = i;
2090 req.rss_ctx_idx = rte_cpu_to_le_16(vnic->fw_grp_ids[i]);
2092 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req),
2095 HWRM_CHECK_RESULT();
2102 int bnxt_hwrm_vnic_rss_cfg(struct bnxt *bp,
2103 struct bnxt_vnic_info *vnic)
2106 struct hwrm_vnic_rss_cfg_input req = {.req_type = 0 };
2107 struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2109 if (!vnic->rss_table)
2112 if (BNXT_CHIP_THOR(bp))
2113 return bnxt_hwrm_vnic_rss_cfg_thor(bp, vnic);
2115 HWRM_PREP(&req, HWRM_VNIC_RSS_CFG, BNXT_USE_CHIMP_MB);
2117 req.hash_type = rte_cpu_to_le_32(vnic->hash_type);
2118 req.hash_mode_flags = vnic->hash_mode;
2120 req.ring_grp_tbl_addr =
2121 rte_cpu_to_le_64(vnic->rss_table_dma_addr);
2122 req.hash_key_tbl_addr =
2123 rte_cpu_to_le_64(vnic->rss_hash_key_dma_addr);
2124 req.rss_ctx_idx = rte_cpu_to_le_16(vnic->rss_rule);
2125 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
2127 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2129 HWRM_CHECK_RESULT();
2135 int bnxt_hwrm_vnic_plcmode_cfg(struct bnxt *bp,
2136 struct bnxt_vnic_info *vnic)
2139 struct hwrm_vnic_plcmodes_cfg_input req = {.req_type = 0 };
2140 struct hwrm_vnic_plcmodes_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2143 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
2144 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
2148 HWRM_PREP(&req, HWRM_VNIC_PLCMODES_CFG, BNXT_USE_CHIMP_MB);
2150 req.flags = rte_cpu_to_le_32(
2151 HWRM_VNIC_PLCMODES_CFG_INPUT_FLAGS_JUMBO_PLACEMENT);
2153 req.enables = rte_cpu_to_le_32(
2154 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_JUMBO_THRESH_VALID);
2156 size = rte_pktmbuf_data_room_size(bp->rx_queues[0]->mb_pool);
2157 size -= RTE_PKTMBUF_HEADROOM;
2158 size = RTE_MIN(BNXT_MAX_PKT_LEN, size);
2160 req.jumbo_thresh = rte_cpu_to_le_16(size);
2161 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
2163 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2165 HWRM_CHECK_RESULT();
2171 int bnxt_hwrm_vnic_tpa_cfg(struct bnxt *bp,
2172 struct bnxt_vnic_info *vnic, bool enable)
2175 struct hwrm_vnic_tpa_cfg_input req = {.req_type = 0 };
2176 struct hwrm_vnic_tpa_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2178 if (BNXT_CHIP_THOR(bp) && !bp->max_tpa_v2) {
2180 PMD_DRV_LOG(ERR, "No HW support for LRO\n");
2184 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
2185 PMD_DRV_LOG(DEBUG, "Invalid vNIC ID\n");
2189 HWRM_PREP(&req, HWRM_VNIC_TPA_CFG, BNXT_USE_CHIMP_MB);
2192 req.enables = rte_cpu_to_le_32(
2193 HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MAX_AGG_SEGS |
2194 HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MAX_AGGS |
2195 HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MIN_AGG_LEN);
2196 req.flags = rte_cpu_to_le_32(
2197 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_TPA |
2198 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_ENCAP_TPA |
2199 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_RSC_WND_UPDATE |
2200 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_GRO |
2201 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_AGG_WITH_ECN |
2202 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_AGG_WITH_SAME_GRE_SEQ);
2203 req.max_agg_segs = rte_cpu_to_le_16(BNXT_TPA_MAX_AGGS(bp));
2204 req.max_aggs = rte_cpu_to_le_16(BNXT_TPA_MAX_SEGS(bp));
2205 req.min_agg_len = rte_cpu_to_le_32(512);
2207 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
2209 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2211 HWRM_CHECK_RESULT();
2217 int bnxt_hwrm_func_vf_mac(struct bnxt *bp, uint16_t vf, const uint8_t *mac_addr)
2219 struct hwrm_func_cfg_input req = {0};
2220 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2223 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[vf].func_cfg_flags);
2224 req.enables = rte_cpu_to_le_32(
2225 HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
2226 memcpy(req.dflt_mac_addr, mac_addr, sizeof(req.dflt_mac_addr));
2227 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
2229 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
2231 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2232 HWRM_CHECK_RESULT();
2235 bp->pf.vf_info[vf].random_mac = false;
2240 int bnxt_hwrm_func_qstats_tx_drop(struct bnxt *bp, uint16_t fid,
2244 struct hwrm_func_qstats_input req = {.req_type = 0};
2245 struct hwrm_func_qstats_output *resp = bp->hwrm_cmd_resp_addr;
2247 HWRM_PREP(&req, HWRM_FUNC_QSTATS, BNXT_USE_CHIMP_MB);
2249 req.fid = rte_cpu_to_le_16(fid);
2251 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2253 HWRM_CHECK_RESULT();
2256 *dropped = rte_le_to_cpu_64(resp->tx_drop_pkts);
2263 int bnxt_hwrm_func_qstats(struct bnxt *bp, uint16_t fid,
2264 struct rte_eth_stats *stats,
2265 struct hwrm_func_qstats_output *func_qstats)
2268 struct hwrm_func_qstats_input req = {.req_type = 0};
2269 struct hwrm_func_qstats_output *resp = bp->hwrm_cmd_resp_addr;
2271 HWRM_PREP(&req, HWRM_FUNC_QSTATS, BNXT_USE_CHIMP_MB);
2273 req.fid = rte_cpu_to_le_16(fid);
2275 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2277 HWRM_CHECK_RESULT();
2279 memcpy(func_qstats, resp,
2280 sizeof(struct hwrm_func_qstats_output));
2285 stats->ipackets = rte_le_to_cpu_64(resp->rx_ucast_pkts);
2286 stats->ipackets += rte_le_to_cpu_64(resp->rx_mcast_pkts);
2287 stats->ipackets += rte_le_to_cpu_64(resp->rx_bcast_pkts);
2288 stats->ibytes = rte_le_to_cpu_64(resp->rx_ucast_bytes);
2289 stats->ibytes += rte_le_to_cpu_64(resp->rx_mcast_bytes);
2290 stats->ibytes += rte_le_to_cpu_64(resp->rx_bcast_bytes);
2292 stats->opackets = rte_le_to_cpu_64(resp->tx_ucast_pkts);
2293 stats->opackets += rte_le_to_cpu_64(resp->tx_mcast_pkts);
2294 stats->opackets += rte_le_to_cpu_64(resp->tx_bcast_pkts);
2295 stats->obytes = rte_le_to_cpu_64(resp->tx_ucast_bytes);
2296 stats->obytes += rte_le_to_cpu_64(resp->tx_mcast_bytes);
2297 stats->obytes += rte_le_to_cpu_64(resp->tx_bcast_bytes);
2299 stats->imissed = rte_le_to_cpu_64(resp->rx_discard_pkts);
2300 stats->ierrors = rte_le_to_cpu_64(resp->rx_drop_pkts);
2301 stats->oerrors = rte_le_to_cpu_64(resp->tx_discard_pkts);
2309 int bnxt_hwrm_func_clr_stats(struct bnxt *bp, uint16_t fid)
2312 struct hwrm_func_clr_stats_input req = {.req_type = 0};
2313 struct hwrm_func_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
2315 HWRM_PREP(&req, HWRM_FUNC_CLR_STATS, BNXT_USE_CHIMP_MB);
2317 req.fid = rte_cpu_to_le_16(fid);
2319 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2321 HWRM_CHECK_RESULT();
2327 int bnxt_clear_all_hwrm_stat_ctxs(struct bnxt *bp)
2332 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
2333 struct bnxt_tx_queue *txq;
2334 struct bnxt_rx_queue *rxq;
2335 struct bnxt_cp_ring_info *cpr;
2337 if (i >= bp->rx_cp_nr_rings) {
2338 txq = bp->tx_queues[i - bp->rx_cp_nr_rings];
2341 rxq = bp->rx_queues[i];
2345 rc = bnxt_hwrm_stat_clear(bp, cpr);
2353 bnxt_free_all_hwrm_stat_ctxs(struct bnxt *bp)
2357 struct bnxt_cp_ring_info *cpr;
2359 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
2361 if (i >= bp->rx_cp_nr_rings) {
2362 cpr = bp->tx_queues[i - bp->rx_cp_nr_rings]->cp_ring;
2364 cpr = bp->rx_queues[i]->cp_ring;
2365 if (BNXT_HAS_RING_GRPS(bp))
2366 bp->grp_info[i].fw_stats_ctx = -1;
2368 if (cpr->hw_stats_ctx_id != HWRM_NA_SIGNATURE) {
2369 rc = bnxt_hwrm_stat_ctx_free(bp, cpr, i);
2370 cpr->hw_stats_ctx_id = HWRM_NA_SIGNATURE;
2378 int bnxt_alloc_all_hwrm_stat_ctxs(struct bnxt *bp)
2383 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
2384 struct bnxt_tx_queue *txq;
2385 struct bnxt_rx_queue *rxq;
2386 struct bnxt_cp_ring_info *cpr;
2388 if (i >= bp->rx_cp_nr_rings) {
2389 txq = bp->tx_queues[i - bp->rx_cp_nr_rings];
2392 rxq = bp->rx_queues[i];
2396 rc = bnxt_hwrm_stat_ctx_alloc(bp, cpr, i);
2405 bnxt_free_all_hwrm_ring_grps(struct bnxt *bp)
2410 if (!BNXT_HAS_RING_GRPS(bp))
2413 for (idx = 0; idx < bp->rx_cp_nr_rings; idx++) {
2415 if (bp->grp_info[idx].fw_grp_id == INVALID_HW_RING_ID)
2418 rc = bnxt_hwrm_ring_grp_free(bp, idx);
2426 void bnxt_free_nq_ring(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
2428 struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
2430 bnxt_hwrm_ring_free(bp, cp_ring,
2431 HWRM_RING_FREE_INPUT_RING_TYPE_NQ);
2432 cp_ring->fw_ring_id = INVALID_HW_RING_ID;
2433 memset(cpr->cp_desc_ring, 0, cpr->cp_ring_struct->ring_size *
2434 sizeof(*cpr->cp_desc_ring));
2435 cpr->cp_raw_cons = 0;
2439 void bnxt_free_cp_ring(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
2441 struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
2443 bnxt_hwrm_ring_free(bp, cp_ring,
2444 HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL);
2445 cp_ring->fw_ring_id = INVALID_HW_RING_ID;
2446 memset(cpr->cp_desc_ring, 0, cpr->cp_ring_struct->ring_size *
2447 sizeof(*cpr->cp_desc_ring));
2448 cpr->cp_raw_cons = 0;
2452 void bnxt_free_hwrm_rx_ring(struct bnxt *bp, int queue_index)
2454 struct bnxt_rx_queue *rxq = bp->rx_queues[queue_index];
2455 struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
2456 struct bnxt_ring *ring = rxr->rx_ring_struct;
2457 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
2459 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
2460 bnxt_hwrm_ring_free(bp, ring,
2461 HWRM_RING_FREE_INPUT_RING_TYPE_RX);
2462 ring->fw_ring_id = INVALID_HW_RING_ID;
2463 if (BNXT_HAS_RING_GRPS(bp))
2464 bp->grp_info[queue_index].rx_fw_ring_id =
2466 memset(rxr->rx_desc_ring, 0,
2467 rxr->rx_ring_struct->ring_size *
2468 sizeof(*rxr->rx_desc_ring));
2469 memset(rxr->rx_buf_ring, 0,
2470 rxr->rx_ring_struct->ring_size *
2471 sizeof(*rxr->rx_buf_ring));
2474 ring = rxr->ag_ring_struct;
2475 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
2476 bnxt_hwrm_ring_free(bp, ring,
2477 BNXT_CHIP_THOR(bp) ?
2478 HWRM_RING_FREE_INPUT_RING_TYPE_RX_AGG :
2479 HWRM_RING_FREE_INPUT_RING_TYPE_RX);
2480 ring->fw_ring_id = INVALID_HW_RING_ID;
2481 memset(rxr->ag_buf_ring, 0,
2482 rxr->ag_ring_struct->ring_size *
2483 sizeof(*rxr->ag_buf_ring));
2485 if (BNXT_HAS_RING_GRPS(bp))
2486 bp->grp_info[queue_index].ag_fw_ring_id =
2489 if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID)
2490 bnxt_free_cp_ring(bp, cpr);
2492 if (BNXT_HAS_RING_GRPS(bp))
2493 bp->grp_info[queue_index].cp_fw_ring_id = INVALID_HW_RING_ID;
2497 bnxt_free_all_hwrm_rings(struct bnxt *bp)
2501 for (i = 0; i < bp->tx_cp_nr_rings; i++) {
2502 struct bnxt_tx_queue *txq = bp->tx_queues[i];
2503 struct bnxt_tx_ring_info *txr = txq->tx_ring;
2504 struct bnxt_ring *ring = txr->tx_ring_struct;
2505 struct bnxt_cp_ring_info *cpr = txq->cp_ring;
2507 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
2508 bnxt_hwrm_ring_free(bp, ring,
2509 HWRM_RING_FREE_INPUT_RING_TYPE_TX);
2510 ring->fw_ring_id = INVALID_HW_RING_ID;
2511 memset(txr->tx_desc_ring, 0,
2512 txr->tx_ring_struct->ring_size *
2513 sizeof(*txr->tx_desc_ring));
2514 memset(txr->tx_buf_ring, 0,
2515 txr->tx_ring_struct->ring_size *
2516 sizeof(*txr->tx_buf_ring));
2520 if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID) {
2521 bnxt_free_cp_ring(bp, cpr);
2522 cpr->cp_ring_struct->fw_ring_id = INVALID_HW_RING_ID;
2526 for (i = 0; i < bp->rx_cp_nr_rings; i++)
2527 bnxt_free_hwrm_rx_ring(bp, i);
2532 int bnxt_alloc_all_hwrm_ring_grps(struct bnxt *bp)
2537 if (!BNXT_HAS_RING_GRPS(bp))
2540 for (i = 0; i < bp->rx_cp_nr_rings; i++) {
2541 rc = bnxt_hwrm_ring_grp_alloc(bp, i);
2549 * HWRM utility functions
2552 void bnxt_free_hwrm_resources(struct bnxt *bp)
2554 /* Release memzone */
2555 rte_free(bp->hwrm_cmd_resp_addr);
2556 rte_free(bp->hwrm_short_cmd_req_addr);
2557 bp->hwrm_cmd_resp_addr = NULL;
2558 bp->hwrm_short_cmd_req_addr = NULL;
2559 bp->hwrm_cmd_resp_dma_addr = 0;
2560 bp->hwrm_short_cmd_req_dma_addr = 0;
2563 int bnxt_alloc_hwrm_resources(struct bnxt *bp)
2565 struct rte_pci_device *pdev = bp->pdev;
2566 char type[RTE_MEMZONE_NAMESIZE];
2568 sprintf(type, "bnxt_hwrm_%04x:%02x:%02x:%02x", pdev->addr.domain,
2569 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
2570 bp->max_resp_len = HWRM_MAX_RESP_LEN;
2571 bp->hwrm_cmd_resp_addr = rte_malloc(type, bp->max_resp_len, 0);
2572 if (bp->hwrm_cmd_resp_addr == NULL)
2574 bp->hwrm_cmd_resp_dma_addr =
2575 rte_malloc_virt2iova(bp->hwrm_cmd_resp_addr);
2576 if (bp->hwrm_cmd_resp_dma_addr == RTE_BAD_IOVA) {
2578 "unable to map response address to physical memory\n");
2581 rte_spinlock_init(&bp->hwrm_lock);
2587 bnxt_clear_hwrm_vnic_filters(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2589 struct bnxt_filter_info *filter;
2592 STAILQ_FOREACH(filter, &vnic->filter, next) {
2593 if (filter->filter_type == HWRM_CFA_EM_FILTER)
2594 rc = bnxt_hwrm_clear_em_filter(bp, filter);
2595 else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
2596 rc = bnxt_hwrm_clear_ntuple_filter(bp, filter);
2597 rc = bnxt_hwrm_clear_l2_filter(bp, filter);
2598 STAILQ_REMOVE(&vnic->filter, filter, bnxt_filter_info, next);
2599 bnxt_free_filter(bp, filter);
2605 bnxt_clear_hwrm_vnic_flows(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2607 struct bnxt_filter_info *filter;
2608 struct rte_flow *flow;
2611 while (!STAILQ_EMPTY(&vnic->flow_list)) {
2612 flow = STAILQ_FIRST(&vnic->flow_list);
2613 filter = flow->filter;
2614 PMD_DRV_LOG(DEBUG, "filter type %d\n", filter->filter_type);
2615 if (filter->filter_type == HWRM_CFA_EM_FILTER)
2616 rc = bnxt_hwrm_clear_em_filter(bp, filter);
2617 else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
2618 rc = bnxt_hwrm_clear_ntuple_filter(bp, filter);
2619 rc = bnxt_hwrm_clear_l2_filter(bp, filter);
2621 STAILQ_REMOVE(&vnic->flow_list, flow, rte_flow, next);
2627 int bnxt_set_hwrm_vnic_filters(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2629 struct bnxt_filter_info *filter;
2632 STAILQ_FOREACH(filter, &vnic->filter, next) {
2633 if (filter->filter_type == HWRM_CFA_EM_FILTER)
2634 rc = bnxt_hwrm_set_em_filter(bp, filter->dst_id,
2636 else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
2637 rc = bnxt_hwrm_set_ntuple_filter(bp, filter->dst_id,
2640 rc = bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id,
2649 bnxt_free_tunnel_ports(struct bnxt *bp)
2651 if (bp->vxlan_port_cnt)
2652 bnxt_hwrm_tunnel_dst_port_free(bp, bp->vxlan_fw_dst_port_id,
2653 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_VXLAN);
2655 if (bp->geneve_port_cnt)
2656 bnxt_hwrm_tunnel_dst_port_free(bp, bp->geneve_fw_dst_port_id,
2657 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_GENEVE);
2658 bp->geneve_port = 0;
2661 void bnxt_free_all_hwrm_resources(struct bnxt *bp)
2665 if (bp->vnic_info == NULL)
2669 * Cleanup VNICs in reverse order, to make sure the L2 filter
2670 * from vnic0 is last to be cleaned up.
2672 for (i = bp->max_vnics - 1; i >= 0; i--) {
2673 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
2675 if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
2678 bnxt_clear_hwrm_vnic_flows(bp, vnic);
2680 bnxt_clear_hwrm_vnic_filters(bp, vnic);
2682 bnxt_hwrm_vnic_ctx_free(bp, vnic);
2684 bnxt_hwrm_vnic_tpa_cfg(bp, vnic, false);
2686 bnxt_hwrm_vnic_free(bp, vnic);
2688 rte_free(vnic->fw_grp_ids);
2690 /* Ring resources */
2691 bnxt_free_all_hwrm_rings(bp);
2692 bnxt_free_all_hwrm_ring_grps(bp);
2693 bnxt_free_all_hwrm_stat_ctxs(bp);
2694 bnxt_free_tunnel_ports(bp);
2697 static uint16_t bnxt_parse_eth_link_duplex(uint32_t conf_link_speed)
2699 uint8_t hw_link_duplex = HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH;
2701 if ((conf_link_speed & ETH_LINK_SPEED_FIXED) == ETH_LINK_SPEED_AUTONEG)
2702 return HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH;
2704 switch (conf_link_speed) {
2705 case ETH_LINK_SPEED_10M_HD:
2706 case ETH_LINK_SPEED_100M_HD:
2708 return HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_HALF;
2710 return hw_link_duplex;
2713 static uint16_t bnxt_check_eth_link_autoneg(uint32_t conf_link)
2715 return (conf_link & ETH_LINK_SPEED_FIXED) ? 0 : 1;
2718 static uint16_t bnxt_parse_eth_link_speed(uint32_t conf_link_speed)
2720 uint16_t eth_link_speed = 0;
2722 if (conf_link_speed == ETH_LINK_SPEED_AUTONEG)
2723 return ETH_LINK_SPEED_AUTONEG;
2725 switch (conf_link_speed & ~ETH_LINK_SPEED_FIXED) {
2726 case ETH_LINK_SPEED_100M:
2727 case ETH_LINK_SPEED_100M_HD:
2730 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_100MB;
2732 case ETH_LINK_SPEED_1G:
2734 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_1GB;
2736 case ETH_LINK_SPEED_2_5G:
2738 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_2_5GB;
2740 case ETH_LINK_SPEED_10G:
2742 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_10GB;
2744 case ETH_LINK_SPEED_20G:
2746 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_20GB;
2748 case ETH_LINK_SPEED_25G:
2750 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_25GB;
2752 case ETH_LINK_SPEED_40G:
2754 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_40GB;
2756 case ETH_LINK_SPEED_50G:
2758 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_50GB;
2760 case ETH_LINK_SPEED_100G:
2762 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_100GB;
2766 "Unsupported link speed %d; default to AUTO\n",
2770 return eth_link_speed;
2773 #define BNXT_SUPPORTED_SPEEDS (ETH_LINK_SPEED_100M | ETH_LINK_SPEED_100M_HD | \
2774 ETH_LINK_SPEED_1G | ETH_LINK_SPEED_2_5G | \
2775 ETH_LINK_SPEED_10G | ETH_LINK_SPEED_20G | ETH_LINK_SPEED_25G | \
2776 ETH_LINK_SPEED_40G | ETH_LINK_SPEED_50G | ETH_LINK_SPEED_100G)
2778 static int bnxt_valid_link_speed(uint32_t link_speed, uint16_t port_id)
2782 if (link_speed == ETH_LINK_SPEED_AUTONEG)
2785 if (link_speed & ETH_LINK_SPEED_FIXED) {
2786 one_speed = link_speed & ~ETH_LINK_SPEED_FIXED;
2788 if (one_speed & (one_speed - 1)) {
2790 "Invalid advertised speeds (%u) for port %u\n",
2791 link_speed, port_id);
2794 if ((one_speed & BNXT_SUPPORTED_SPEEDS) != one_speed) {
2796 "Unsupported advertised speed (%u) for port %u\n",
2797 link_speed, port_id);
2801 if (!(link_speed & BNXT_SUPPORTED_SPEEDS)) {
2803 "Unsupported advertised speeds (%u) for port %u\n",
2804 link_speed, port_id);
2812 bnxt_parse_eth_link_speed_mask(struct bnxt *bp, uint32_t link_speed)
2816 if (link_speed == ETH_LINK_SPEED_AUTONEG) {
2817 if (bp->link_info.support_speeds)
2818 return bp->link_info.support_speeds;
2819 link_speed = BNXT_SUPPORTED_SPEEDS;
2822 if (link_speed & ETH_LINK_SPEED_100M)
2823 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100MB;
2824 if (link_speed & ETH_LINK_SPEED_100M_HD)
2825 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100MB;
2826 if (link_speed & ETH_LINK_SPEED_1G)
2827 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_1GB;
2828 if (link_speed & ETH_LINK_SPEED_2_5G)
2829 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_2_5GB;
2830 if (link_speed & ETH_LINK_SPEED_10G)
2831 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_10GB;
2832 if (link_speed & ETH_LINK_SPEED_20G)
2833 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_20GB;
2834 if (link_speed & ETH_LINK_SPEED_25G)
2835 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_25GB;
2836 if (link_speed & ETH_LINK_SPEED_40G)
2837 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_40GB;
2838 if (link_speed & ETH_LINK_SPEED_50G)
2839 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_50GB;
2840 if (link_speed & ETH_LINK_SPEED_100G)
2841 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100GB;
2845 static uint32_t bnxt_parse_hw_link_speed(uint16_t hw_link_speed)
2847 uint32_t eth_link_speed = ETH_SPEED_NUM_NONE;
2849 switch (hw_link_speed) {
2850 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100MB:
2851 eth_link_speed = ETH_SPEED_NUM_100M;
2853 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_1GB:
2854 eth_link_speed = ETH_SPEED_NUM_1G;
2856 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2_5GB:
2857 eth_link_speed = ETH_SPEED_NUM_2_5G;
2859 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_10GB:
2860 eth_link_speed = ETH_SPEED_NUM_10G;
2862 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_20GB:
2863 eth_link_speed = ETH_SPEED_NUM_20G;
2865 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_25GB:
2866 eth_link_speed = ETH_SPEED_NUM_25G;
2868 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_40GB:
2869 eth_link_speed = ETH_SPEED_NUM_40G;
2871 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_50GB:
2872 eth_link_speed = ETH_SPEED_NUM_50G;
2874 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100GB:
2875 eth_link_speed = ETH_SPEED_NUM_100G;
2877 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2GB:
2879 PMD_DRV_LOG(ERR, "HWRM link speed %d not defined\n",
2883 return eth_link_speed;
2886 static uint16_t bnxt_parse_hw_link_duplex(uint16_t hw_link_duplex)
2888 uint16_t eth_link_duplex = ETH_LINK_FULL_DUPLEX;
2890 switch (hw_link_duplex) {
2891 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH:
2892 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_FULL:
2894 eth_link_duplex = ETH_LINK_FULL_DUPLEX;
2896 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_HALF:
2897 eth_link_duplex = ETH_LINK_HALF_DUPLEX;
2900 PMD_DRV_LOG(ERR, "HWRM link duplex %d not defined\n",
2904 return eth_link_duplex;
2907 int bnxt_get_hwrm_link_config(struct bnxt *bp, struct rte_eth_link *link)
2910 struct bnxt_link_info *link_info = &bp->link_info;
2912 rc = bnxt_hwrm_port_phy_qcfg(bp, link_info);
2915 "Get link config failed with rc %d\n", rc);
2918 if (link_info->link_speed)
2920 bnxt_parse_hw_link_speed(link_info->link_speed);
2922 link->link_speed = ETH_SPEED_NUM_NONE;
2923 link->link_duplex = bnxt_parse_hw_link_duplex(link_info->duplex);
2924 link->link_status = link_info->link_up;
2925 link->link_autoneg = link_info->auto_mode ==
2926 HWRM_PORT_PHY_QCFG_OUTPUT_AUTO_MODE_NONE ?
2927 ETH_LINK_FIXED : ETH_LINK_AUTONEG;
2932 int bnxt_set_hwrm_link_config(struct bnxt *bp, bool link_up)
2935 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
2936 struct bnxt_link_info link_req;
2937 uint16_t speed, autoneg;
2939 if (!BNXT_SINGLE_PF(bp) || BNXT_VF(bp))
2942 rc = bnxt_valid_link_speed(dev_conf->link_speeds,
2943 bp->eth_dev->data->port_id);
2947 memset(&link_req, 0, sizeof(link_req));
2948 link_req.link_up = link_up;
2952 autoneg = bnxt_check_eth_link_autoneg(dev_conf->link_speeds);
2953 if (BNXT_CHIP_THOR(bp) &&
2954 dev_conf->link_speeds == ETH_LINK_SPEED_40G) {
2955 /* 40G is not supported as part of media auto detect.
2956 * The speed should be forced and autoneg disabled
2957 * to configure 40G speed.
2959 PMD_DRV_LOG(INFO, "Disabling autoneg for 40G\n");
2963 speed = bnxt_parse_eth_link_speed(dev_conf->link_speeds);
2964 link_req.phy_flags = HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESET_PHY;
2965 /* Autoneg can be done only when the FW allows.
2966 * When user configures fixed speed of 40G and later changes to
2967 * any other speed, auto_link_speed/force_link_speed is still set
2968 * to 40G until link comes up at new speed.
2971 !(!BNXT_CHIP_THOR(bp) &&
2972 (bp->link_info.auto_link_speed ||
2973 bp->link_info.force_link_speed))) {
2974 link_req.phy_flags |=
2975 HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESTART_AUTONEG;
2976 link_req.auto_link_speed_mask =
2977 bnxt_parse_eth_link_speed_mask(bp,
2978 dev_conf->link_speeds);
2980 if (bp->link_info.phy_type ==
2981 HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET ||
2982 bp->link_info.phy_type ==
2983 HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASETE ||
2984 bp->link_info.media_type ==
2985 HWRM_PORT_PHY_QCFG_OUTPUT_MEDIA_TYPE_TP) {
2986 PMD_DRV_LOG(ERR, "10GBase-T devices must autoneg\n");
2990 link_req.phy_flags |= HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE;
2991 /* If user wants a particular speed try that first. */
2993 link_req.link_speed = speed;
2994 else if (bp->link_info.force_link_speed)
2995 link_req.link_speed = bp->link_info.force_link_speed;
2997 link_req.link_speed = bp->link_info.auto_link_speed;
2999 link_req.duplex = bnxt_parse_eth_link_duplex(dev_conf->link_speeds);
3000 link_req.auto_pause = bp->link_info.auto_pause;
3001 link_req.force_pause = bp->link_info.force_pause;
3004 rc = bnxt_hwrm_port_phy_cfg(bp, &link_req);
3007 "Set link config failed with rc %d\n", rc);
3015 int bnxt_hwrm_func_qcfg(struct bnxt *bp, uint16_t *mtu)
3017 struct hwrm_func_qcfg_input req = {0};
3018 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
3021 bp->func_svif = BNXT_SVIF_INVALID;
3024 HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
3025 req.fid = rte_cpu_to_le_16(0xffff);
3027 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3029 HWRM_CHECK_RESULT();
3031 /* Hard Coded.. 0xfff VLAN ID mask */
3032 bp->vlan = rte_le_to_cpu_16(resp->vlan) & 0xfff;
3034 svif_info = rte_le_to_cpu_16(resp->svif_info);
3035 if (svif_info & HWRM_FUNC_QCFG_OUTPUT_SVIF_INFO_SVIF_VALID)
3036 bp->func_svif = svif_info &
3037 HWRM_FUNC_QCFG_OUTPUT_SVIF_INFO_SVIF_MASK;
3039 flags = rte_le_to_cpu_16(resp->flags);
3040 if (BNXT_PF(bp) && (flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_MULTI_HOST))
3041 bp->flags |= BNXT_FLAG_MULTI_HOST;
3044 !BNXT_VF_IS_TRUSTED(bp) &&
3045 (flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_TRUSTED_VF)) {
3046 bp->flags |= BNXT_FLAG_TRUSTED_VF_EN;
3047 PMD_DRV_LOG(INFO, "Trusted VF cap enabled\n");
3048 } else if (BNXT_VF(bp) &&
3049 BNXT_VF_IS_TRUSTED(bp) &&
3050 !(flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_TRUSTED_VF)) {
3051 bp->flags &= ~BNXT_FLAG_TRUSTED_VF_EN;
3052 PMD_DRV_LOG(INFO, "Trusted VF cap disabled\n");
3056 *mtu = rte_le_to_cpu_16(resp->mtu);
3058 switch (resp->port_partition_type) {
3059 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR1_0:
3060 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR1_5:
3061 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR2_0:
3063 bp->flags |= BNXT_FLAG_NPAR_PF;
3066 bp->flags &= ~BNXT_FLAG_NPAR_PF;
3075 int bnxt_hwrm_port_mac_qcfg(struct bnxt *bp)
3077 struct hwrm_port_mac_qcfg_input req = {0};
3078 struct hwrm_port_mac_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
3079 uint16_t port_svif_info;
3082 bp->port_svif = BNXT_SVIF_INVALID;
3084 HWRM_PREP(&req, HWRM_PORT_MAC_QCFG, BNXT_USE_CHIMP_MB);
3086 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3088 HWRM_CHECK_RESULT();
3090 port_svif_info = rte_le_to_cpu_16(resp->port_svif_info);
3091 if (port_svif_info &
3092 HWRM_PORT_MAC_QCFG_OUTPUT_PORT_SVIF_INFO_PORT_SVIF_VALID)
3093 bp->port_svif = port_svif_info &
3094 HWRM_PORT_MAC_QCFG_OUTPUT_PORT_SVIF_INFO_PORT_SVIF_MASK;
3101 static void copy_func_cfg_to_qcaps(struct hwrm_func_cfg_input *fcfg,
3102 struct hwrm_func_qcaps_output *qcaps)
3104 qcaps->max_rsscos_ctx = fcfg->num_rsscos_ctxs;
3105 memcpy(qcaps->mac_address, fcfg->dflt_mac_addr,
3106 sizeof(qcaps->mac_address));
3107 qcaps->max_l2_ctxs = fcfg->num_l2_ctxs;
3108 qcaps->max_rx_rings = fcfg->num_rx_rings;
3109 qcaps->max_tx_rings = fcfg->num_tx_rings;
3110 qcaps->max_cmpl_rings = fcfg->num_cmpl_rings;
3111 qcaps->max_stat_ctx = fcfg->num_stat_ctxs;
3113 qcaps->first_vf_id = 0;
3114 qcaps->max_vnics = fcfg->num_vnics;
3115 qcaps->max_decap_records = 0;
3116 qcaps->max_encap_records = 0;
3117 qcaps->max_tx_wm_flows = 0;
3118 qcaps->max_tx_em_flows = 0;
3119 qcaps->max_rx_wm_flows = 0;
3120 qcaps->max_rx_em_flows = 0;
3121 qcaps->max_flow_id = 0;
3122 qcaps->max_mcast_filters = fcfg->num_mcast_filters;
3123 qcaps->max_sp_tx_rings = 0;
3124 qcaps->max_hw_ring_grps = fcfg->num_hw_ring_grps;
3127 static int bnxt_hwrm_pf_func_cfg(struct bnxt *bp, int tx_rings)
3129 struct hwrm_func_cfg_input req = {0};
3130 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3134 enables = HWRM_FUNC_CFG_INPUT_ENABLES_MTU |
3135 HWRM_FUNC_CFG_INPUT_ENABLES_MRU |
3136 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS |
3137 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
3138 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
3139 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_TX_RINGS |
3140 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RX_RINGS |
3141 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_L2_CTXS |
3142 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_VNICS;
3144 if (BNXT_HAS_RING_GRPS(bp)) {
3145 enables |= HWRM_FUNC_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS;
3146 req.num_hw_ring_grps = rte_cpu_to_le_16(bp->max_ring_grps);
3147 } else if (BNXT_HAS_NQ(bp)) {
3148 enables |= HWRM_FUNC_CFG_INPUT_ENABLES_NUM_MSIX;
3149 req.num_msix = rte_cpu_to_le_16(bp->max_nq_rings);
3152 req.flags = rte_cpu_to_le_32(bp->pf.func_cfg_flags);
3153 req.mtu = rte_cpu_to_le_16(BNXT_MAX_MTU);
3154 req.mru = rte_cpu_to_le_16(BNXT_VNIC_MRU(bp->eth_dev->data->mtu));
3155 req.num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx);
3156 req.num_stat_ctxs = rte_cpu_to_le_16(bp->max_stat_ctx);
3157 req.num_cmpl_rings = rte_cpu_to_le_16(bp->max_cp_rings);
3158 req.num_tx_rings = rte_cpu_to_le_16(tx_rings);
3159 req.num_rx_rings = rte_cpu_to_le_16(bp->max_rx_rings);
3160 req.num_l2_ctxs = rte_cpu_to_le_16(bp->max_l2_ctx);
3161 req.num_vnics = rte_cpu_to_le_16(bp->max_vnics);
3162 req.fid = rte_cpu_to_le_16(0xffff);
3163 req.enables = rte_cpu_to_le_32(enables);
3165 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
3167 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3169 HWRM_CHECK_RESULT();
3175 static void populate_vf_func_cfg_req(struct bnxt *bp,
3176 struct hwrm_func_cfg_input *req,
3179 req->enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_MTU |
3180 HWRM_FUNC_CFG_INPUT_ENABLES_MRU |
3181 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS |
3182 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
3183 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
3184 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_TX_RINGS |
3185 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RX_RINGS |
3186 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_L2_CTXS |
3187 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_VNICS |
3188 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS);
3190 req->mtu = rte_cpu_to_le_16(bp->eth_dev->data->mtu + RTE_ETHER_HDR_LEN +
3191 RTE_ETHER_CRC_LEN + VLAN_TAG_SIZE *
3193 req->mru = rte_cpu_to_le_16(BNXT_VNIC_MRU(bp->eth_dev->data->mtu));
3194 req->num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx /
3196 req->num_stat_ctxs = rte_cpu_to_le_16(bp->max_stat_ctx / (num_vfs + 1));
3197 req->num_cmpl_rings = rte_cpu_to_le_16(bp->max_cp_rings /
3199 req->num_tx_rings = rte_cpu_to_le_16(bp->max_tx_rings / (num_vfs + 1));
3200 req->num_rx_rings = rte_cpu_to_le_16(bp->max_rx_rings / (num_vfs + 1));
3201 req->num_l2_ctxs = rte_cpu_to_le_16(bp->max_l2_ctx / (num_vfs + 1));
3202 /* TODO: For now, do not support VMDq/RFS on VFs. */
3203 req->num_vnics = rte_cpu_to_le_16(1);
3204 req->num_hw_ring_grps = rte_cpu_to_le_16(bp->max_ring_grps /
3208 static void add_random_mac_if_needed(struct bnxt *bp,
3209 struct hwrm_func_cfg_input *cfg_req,
3212 struct rte_ether_addr mac;
3214 if (bnxt_hwrm_func_qcfg_vf_default_mac(bp, vf, &mac))
3217 if (memcmp(mac.addr_bytes, "\x00\x00\x00\x00\x00", 6) == 0) {
3219 rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
3220 rte_eth_random_addr(cfg_req->dflt_mac_addr);
3221 bp->pf.vf_info[vf].random_mac = true;
3223 memcpy(cfg_req->dflt_mac_addr, mac.addr_bytes,
3224 RTE_ETHER_ADDR_LEN);
3228 static int reserve_resources_from_vf(struct bnxt *bp,
3229 struct hwrm_func_cfg_input *cfg_req,
3232 struct hwrm_func_qcaps_input req = {0};
3233 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
3236 /* Get the actual allocated values now */
3237 HWRM_PREP(&req, HWRM_FUNC_QCAPS, BNXT_USE_CHIMP_MB);
3238 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3239 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3242 PMD_DRV_LOG(ERR, "hwrm_func_qcaps failed rc:%d\n", rc);
3243 copy_func_cfg_to_qcaps(cfg_req, resp);
3244 } else if (resp->error_code) {
3245 rc = rte_le_to_cpu_16(resp->error_code);
3246 PMD_DRV_LOG(ERR, "hwrm_func_qcaps error %d\n", rc);
3247 copy_func_cfg_to_qcaps(cfg_req, resp);
3250 bp->max_rsscos_ctx -= rte_le_to_cpu_16(resp->max_rsscos_ctx);
3251 bp->max_stat_ctx -= rte_le_to_cpu_16(resp->max_stat_ctx);
3252 bp->max_cp_rings -= rte_le_to_cpu_16(resp->max_cmpl_rings);
3253 bp->max_tx_rings -= rte_le_to_cpu_16(resp->max_tx_rings);
3254 bp->max_rx_rings -= rte_le_to_cpu_16(resp->max_rx_rings);
3255 bp->max_l2_ctx -= rte_le_to_cpu_16(resp->max_l2_ctxs);
3257 * TODO: While not supporting VMDq with VFs, max_vnics is always
3258 * forced to 1 in this case
3260 //bp->max_vnics -= rte_le_to_cpu_16(esp->max_vnics);
3261 bp->max_ring_grps -= rte_le_to_cpu_16(resp->max_hw_ring_grps);
3268 int bnxt_hwrm_func_qcfg_current_vf_vlan(struct bnxt *bp, int vf)
3270 struct hwrm_func_qcfg_input req = {0};
3271 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
3274 /* Check for zero MAC address */
3275 HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
3276 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3277 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3278 HWRM_CHECK_RESULT();
3279 rc = rte_le_to_cpu_16(resp->vlan);
3286 static int update_pf_resource_max(struct bnxt *bp)
3288 struct hwrm_func_qcfg_input req = {0};
3289 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
3292 /* And copy the allocated numbers into the pf struct */
3293 HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
3294 req.fid = rte_cpu_to_le_16(0xffff);
3295 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3296 HWRM_CHECK_RESULT();
3298 /* Only TX ring value reflects actual allocation? TODO */
3299 bp->max_tx_rings = rte_le_to_cpu_16(resp->alloc_tx_rings);
3300 bp->pf.evb_mode = resp->evb_mode;
3307 int bnxt_hwrm_allocate_pf_only(struct bnxt *bp)
3312 PMD_DRV_LOG(ERR, "Attempt to allcoate VFs on a VF!\n");
3316 rc = bnxt_hwrm_func_qcaps(bp);
3320 bp->pf.func_cfg_flags &=
3321 ~(HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE |
3322 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE);
3323 bp->pf.func_cfg_flags |=
3324 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE;
3325 rc = bnxt_hwrm_pf_func_cfg(bp, bp->max_tx_rings);
3326 rc = __bnxt_hwrm_func_qcaps(bp);
3330 int bnxt_hwrm_allocate_vfs(struct bnxt *bp, int num_vfs)
3332 struct hwrm_func_cfg_input req = {0};
3333 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3340 PMD_DRV_LOG(ERR, "Attempt to allcoate VFs on a VF!\n");
3344 rc = bnxt_hwrm_func_qcaps(bp);
3349 bp->pf.active_vfs = num_vfs;
3352 * First, configure the PF to only use one TX ring. This ensures that
3353 * there are enough rings for all VFs.
3355 * If we don't do this, when we call func_alloc() later, we will lock
3356 * extra rings to the PF that won't be available during func_cfg() of
3359 * This has been fixed with firmware versions above 20.6.54
3361 bp->pf.func_cfg_flags &=
3362 ~(HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE |
3363 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE);
3364 bp->pf.func_cfg_flags |=
3365 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE;
3366 rc = bnxt_hwrm_pf_func_cfg(bp, 1);
3371 * Now, create and register a buffer to hold forwarded VF requests
3373 req_buf_sz = num_vfs * HWRM_MAX_REQ_LEN;
3374 bp->pf.vf_req_buf = rte_malloc("bnxt_vf_fwd", req_buf_sz,
3375 page_roundup(num_vfs * HWRM_MAX_REQ_LEN));
3376 if (bp->pf.vf_req_buf == NULL) {
3380 for (sz = 0; sz < req_buf_sz; sz += getpagesize())
3381 rte_mem_lock_page(((char *)bp->pf.vf_req_buf) + sz);
3382 for (i = 0; i < num_vfs; i++)
3383 bp->pf.vf_info[i].req_buf = ((char *)bp->pf.vf_req_buf) +
3384 (i * HWRM_MAX_REQ_LEN);
3386 rc = bnxt_hwrm_func_buf_rgtr(bp);
3390 populate_vf_func_cfg_req(bp, &req, num_vfs);
3392 bp->pf.active_vfs = 0;
3393 for (i = 0; i < num_vfs; i++) {
3394 add_random_mac_if_needed(bp, &req, i);
3396 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
3397 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[i].func_cfg_flags);
3398 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[i].fid);
3399 rc = bnxt_hwrm_send_message(bp,
3404 /* Clear enable flag for next pass */
3405 req.enables &= ~rte_cpu_to_le_32(
3406 HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
3408 if (rc || resp->error_code) {
3410 "Failed to initizlie VF %d\n", i);
3412 "Not all VFs available. (%d, %d)\n",
3413 rc, resp->error_code);
3420 reserve_resources_from_vf(bp, &req, i);
3421 bp->pf.active_vfs++;
3422 bnxt_hwrm_func_clr_stats(bp, bp->pf.vf_info[i].fid);
3426 * Now configure the PF to use "the rest" of the resources
3427 * We're using STD_TX_RING_MODE here though which will limit the TX
3428 * rings. This will allow QoS to function properly. Not setting this
3429 * will cause PF rings to break bandwidth settings.
3431 rc = bnxt_hwrm_pf_func_cfg(bp, bp->max_tx_rings);
3435 rc = update_pf_resource_max(bp);
3442 bnxt_hwrm_func_buf_unrgtr(bp);
3446 int bnxt_hwrm_pf_evb_mode(struct bnxt *bp)
3448 struct hwrm_func_cfg_input req = {0};
3449 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3452 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
3454 req.fid = rte_cpu_to_le_16(0xffff);
3455 req.enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_EVB_MODE);
3456 req.evb_mode = bp->pf.evb_mode;
3458 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3459 HWRM_CHECK_RESULT();
3465 int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt *bp, uint16_t port,
3466 uint8_t tunnel_type)
3468 struct hwrm_tunnel_dst_port_alloc_input req = {0};
3469 struct hwrm_tunnel_dst_port_alloc_output *resp = bp->hwrm_cmd_resp_addr;
3472 HWRM_PREP(&req, HWRM_TUNNEL_DST_PORT_ALLOC, BNXT_USE_CHIMP_MB);
3473 req.tunnel_type = tunnel_type;
3474 req.tunnel_dst_port_val = port;
3475 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3476 HWRM_CHECK_RESULT();
3478 switch (tunnel_type) {
3479 case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_VXLAN:
3480 bp->vxlan_fw_dst_port_id = resp->tunnel_dst_port_id;
3481 bp->vxlan_port = port;
3483 case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_GENEVE:
3484 bp->geneve_fw_dst_port_id = resp->tunnel_dst_port_id;
3485 bp->geneve_port = port;
3496 int bnxt_hwrm_tunnel_dst_port_free(struct bnxt *bp, uint16_t port,
3497 uint8_t tunnel_type)
3499 struct hwrm_tunnel_dst_port_free_input req = {0};
3500 struct hwrm_tunnel_dst_port_free_output *resp = bp->hwrm_cmd_resp_addr;
3503 HWRM_PREP(&req, HWRM_TUNNEL_DST_PORT_FREE, BNXT_USE_CHIMP_MB);
3505 req.tunnel_type = tunnel_type;
3506 req.tunnel_dst_port_id = rte_cpu_to_be_16(port);
3507 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3509 HWRM_CHECK_RESULT();
3515 int bnxt_hwrm_func_cfg_vf_set_flags(struct bnxt *bp, uint16_t vf,
3518 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3519 struct hwrm_func_cfg_input req = {0};
3522 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
3524 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3525 req.flags = rte_cpu_to_le_32(flags);
3526 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3528 HWRM_CHECK_RESULT();
3534 void vf_vnic_set_rxmask_cb(struct bnxt_vnic_info *vnic, void *flagp)
3536 uint32_t *flag = flagp;
3538 vnic->flags = *flag;
3541 int bnxt_set_rx_mask_no_vlan(struct bnxt *bp, struct bnxt_vnic_info *vnic)
3543 return bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
3546 int bnxt_hwrm_func_buf_rgtr(struct bnxt *bp)
3549 struct hwrm_func_buf_rgtr_input req = {.req_type = 0 };
3550 struct hwrm_func_buf_rgtr_output *resp = bp->hwrm_cmd_resp_addr;
3552 HWRM_PREP(&req, HWRM_FUNC_BUF_RGTR, BNXT_USE_CHIMP_MB);
3554 req.req_buf_num_pages = rte_cpu_to_le_16(1);
3555 req.req_buf_page_size = rte_cpu_to_le_16(
3556 page_getenum(bp->pf.active_vfs * HWRM_MAX_REQ_LEN));
3557 req.req_buf_len = rte_cpu_to_le_16(HWRM_MAX_REQ_LEN);
3558 req.req_buf_page_addr0 =
3559 rte_cpu_to_le_64(rte_malloc_virt2iova(bp->pf.vf_req_buf));
3560 if (req.req_buf_page_addr0 == RTE_BAD_IOVA) {
3562 "unable to map buffer address to physical memory\n");
3566 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3568 HWRM_CHECK_RESULT();
3574 int bnxt_hwrm_func_buf_unrgtr(struct bnxt *bp)
3577 struct hwrm_func_buf_unrgtr_input req = {.req_type = 0 };
3578 struct hwrm_func_buf_unrgtr_output *resp = bp->hwrm_cmd_resp_addr;
3580 if (!(BNXT_PF(bp) && bp->pdev->max_vfs))
3583 HWRM_PREP(&req, HWRM_FUNC_BUF_UNRGTR, BNXT_USE_CHIMP_MB);
3585 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3587 HWRM_CHECK_RESULT();
3593 int bnxt_hwrm_func_cfg_def_cp(struct bnxt *bp)
3595 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3596 struct hwrm_func_cfg_input req = {0};
3599 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
3601 req.fid = rte_cpu_to_le_16(0xffff);
3602 req.flags = rte_cpu_to_le_32(bp->pf.func_cfg_flags);
3603 req.enables = rte_cpu_to_le_32(
3604 HWRM_FUNC_CFG_INPUT_ENABLES_ASYNC_EVENT_CR);
3605 req.async_event_cr = rte_cpu_to_le_16(
3606 bp->async_cp_ring->cp_ring_struct->fw_ring_id);
3607 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3609 HWRM_CHECK_RESULT();
3615 int bnxt_hwrm_vf_func_cfg_def_cp(struct bnxt *bp)
3617 struct hwrm_func_vf_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3618 struct hwrm_func_vf_cfg_input req = {0};
3621 HWRM_PREP(&req, HWRM_FUNC_VF_CFG, BNXT_USE_CHIMP_MB);
3623 req.enables = rte_cpu_to_le_32(
3624 HWRM_FUNC_VF_CFG_INPUT_ENABLES_ASYNC_EVENT_CR);
3625 req.async_event_cr = rte_cpu_to_le_16(
3626 bp->async_cp_ring->cp_ring_struct->fw_ring_id);
3627 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3629 HWRM_CHECK_RESULT();
3635 int bnxt_hwrm_set_default_vlan(struct bnxt *bp, int vf, uint8_t is_vf)
3637 struct hwrm_func_cfg_input req = {0};
3638 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3639 uint16_t dflt_vlan, fid;
3640 uint32_t func_cfg_flags;
3643 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
3646 dflt_vlan = bp->pf.vf_info[vf].dflt_vlan;
3647 fid = bp->pf.vf_info[vf].fid;
3648 func_cfg_flags = bp->pf.vf_info[vf].func_cfg_flags;
3650 fid = rte_cpu_to_le_16(0xffff);
3651 func_cfg_flags = bp->pf.func_cfg_flags;
3652 dflt_vlan = bp->vlan;
3655 req.flags = rte_cpu_to_le_32(func_cfg_flags);
3656 req.fid = rte_cpu_to_le_16(fid);
3657 req.enables |= rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_VLAN);
3658 req.dflt_vlan = rte_cpu_to_le_16(dflt_vlan);
3660 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3662 HWRM_CHECK_RESULT();
3668 int bnxt_hwrm_func_bw_cfg(struct bnxt *bp, uint16_t vf,
3669 uint16_t max_bw, uint16_t enables)
3671 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3672 struct hwrm_func_cfg_input req = {0};
3675 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
3677 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3678 req.enables |= rte_cpu_to_le_32(enables);
3679 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[vf].func_cfg_flags);
3680 req.max_bw = rte_cpu_to_le_32(max_bw);
3681 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3683 HWRM_CHECK_RESULT();
3689 int bnxt_hwrm_set_vf_vlan(struct bnxt *bp, int vf)
3691 struct hwrm_func_cfg_input req = {0};
3692 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3695 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
3697 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[vf].func_cfg_flags);
3698 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3699 req.enables |= rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_VLAN);
3700 req.dflt_vlan = rte_cpu_to_le_16(bp->pf.vf_info[vf].dflt_vlan);
3702 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3704 HWRM_CHECK_RESULT();
3710 int bnxt_hwrm_set_async_event_cr(struct bnxt *bp)
3715 rc = bnxt_hwrm_func_cfg_def_cp(bp);
3717 rc = bnxt_hwrm_vf_func_cfg_def_cp(bp);
3722 int bnxt_hwrm_reject_fwd_resp(struct bnxt *bp, uint16_t target_id,
3723 void *encaped, size_t ec_size)
3726 struct hwrm_reject_fwd_resp_input req = {.req_type = 0};
3727 struct hwrm_reject_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr;
3729 if (ec_size > sizeof(req.encap_request))
3732 HWRM_PREP(&req, HWRM_REJECT_FWD_RESP, BNXT_USE_CHIMP_MB);
3734 req.encap_resp_target_id = rte_cpu_to_le_16(target_id);
3735 memcpy(req.encap_request, encaped, ec_size);
3737 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3739 HWRM_CHECK_RESULT();
3745 int bnxt_hwrm_func_qcfg_vf_default_mac(struct bnxt *bp, uint16_t vf,
3746 struct rte_ether_addr *mac)
3748 struct hwrm_func_qcfg_input req = {0};
3749 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
3752 HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
3754 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3755 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3757 HWRM_CHECK_RESULT();
3759 memcpy(mac->addr_bytes, resp->mac_address, RTE_ETHER_ADDR_LEN);
3766 int bnxt_hwrm_exec_fwd_resp(struct bnxt *bp, uint16_t target_id,
3767 void *encaped, size_t ec_size)
3770 struct hwrm_exec_fwd_resp_input req = {.req_type = 0};
3771 struct hwrm_exec_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr;
3773 if (ec_size > sizeof(req.encap_request))
3776 HWRM_PREP(&req, HWRM_EXEC_FWD_RESP, BNXT_USE_CHIMP_MB);
3778 req.encap_resp_target_id = rte_cpu_to_le_16(target_id);
3779 memcpy(req.encap_request, encaped, ec_size);
3781 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3783 HWRM_CHECK_RESULT();
3789 int bnxt_hwrm_ctx_qstats(struct bnxt *bp, uint32_t cid, int idx,
3790 struct rte_eth_stats *stats, uint8_t rx)
3793 struct hwrm_stat_ctx_query_input req = {.req_type = 0};
3794 struct hwrm_stat_ctx_query_output *resp = bp->hwrm_cmd_resp_addr;
3796 HWRM_PREP(&req, HWRM_STAT_CTX_QUERY, BNXT_USE_CHIMP_MB);
3798 req.stat_ctx_id = rte_cpu_to_le_32(cid);
3800 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3802 HWRM_CHECK_RESULT();
3805 stats->q_ipackets[idx] = rte_le_to_cpu_64(resp->rx_ucast_pkts);
3806 stats->q_ipackets[idx] += rte_le_to_cpu_64(resp->rx_mcast_pkts);
3807 stats->q_ipackets[idx] += rte_le_to_cpu_64(resp->rx_bcast_pkts);
3808 stats->q_ibytes[idx] = rte_le_to_cpu_64(resp->rx_ucast_bytes);
3809 stats->q_ibytes[idx] += rte_le_to_cpu_64(resp->rx_mcast_bytes);
3810 stats->q_ibytes[idx] += rte_le_to_cpu_64(resp->rx_bcast_bytes);
3811 stats->q_errors[idx] = rte_le_to_cpu_64(resp->rx_err_pkts);
3812 stats->q_errors[idx] += rte_le_to_cpu_64(resp->rx_drop_pkts);
3814 stats->q_opackets[idx] = rte_le_to_cpu_64(resp->tx_ucast_pkts);
3815 stats->q_opackets[idx] += rte_le_to_cpu_64(resp->tx_mcast_pkts);
3816 stats->q_opackets[idx] += rte_le_to_cpu_64(resp->tx_bcast_pkts);
3817 stats->q_obytes[idx] = rte_le_to_cpu_64(resp->tx_ucast_bytes);
3818 stats->q_obytes[idx] += rte_le_to_cpu_64(resp->tx_mcast_bytes);
3819 stats->q_obytes[idx] += rte_le_to_cpu_64(resp->tx_bcast_bytes);
3827 int bnxt_hwrm_port_qstats(struct bnxt *bp)
3829 struct hwrm_port_qstats_input req = {0};
3830 struct hwrm_port_qstats_output *resp = bp->hwrm_cmd_resp_addr;
3831 struct bnxt_pf_info *pf = &bp->pf;
3834 HWRM_PREP(&req, HWRM_PORT_QSTATS, BNXT_USE_CHIMP_MB);
3836 req.port_id = rte_cpu_to_le_16(pf->port_id);
3837 req.tx_stat_host_addr = rte_cpu_to_le_64(bp->hw_tx_port_stats_map);
3838 req.rx_stat_host_addr = rte_cpu_to_le_64(bp->hw_rx_port_stats_map);
3839 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3841 HWRM_CHECK_RESULT();
3847 int bnxt_hwrm_port_clr_stats(struct bnxt *bp)
3849 struct hwrm_port_clr_stats_input req = {0};
3850 struct hwrm_port_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
3851 struct bnxt_pf_info *pf = &bp->pf;
3854 /* Not allowed on NS2 device, NPAR, MultiHost, VF */
3855 if (!(bp->flags & BNXT_FLAG_PORT_STATS) || BNXT_VF(bp) ||
3856 BNXT_NPAR(bp) || BNXT_MH(bp) || BNXT_TOTAL_VFS(bp))
3859 HWRM_PREP(&req, HWRM_PORT_CLR_STATS, BNXT_USE_CHIMP_MB);
3861 req.port_id = rte_cpu_to_le_16(pf->port_id);
3862 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3864 HWRM_CHECK_RESULT();
3870 int bnxt_hwrm_port_led_qcaps(struct bnxt *bp)
3872 struct hwrm_port_led_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
3873 struct hwrm_port_led_qcaps_input req = {0};
3879 HWRM_PREP(&req, HWRM_PORT_LED_QCAPS, BNXT_USE_CHIMP_MB);
3880 req.port_id = bp->pf.port_id;
3881 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3883 HWRM_CHECK_RESULT();
3885 if (resp->num_leds > 0 && resp->num_leds < BNXT_MAX_LED) {
3888 bp->num_leds = resp->num_leds;
3889 memcpy(bp->leds, &resp->led0_id,
3890 sizeof(bp->leds[0]) * bp->num_leds);
3891 for (i = 0; i < bp->num_leds; i++) {
3892 struct bnxt_led_info *led = &bp->leds[i];
3894 uint16_t caps = led->led_state_caps;
3896 if (!led->led_group_id ||
3897 !BNXT_LED_ALT_BLINK_CAP(caps)) {
3909 int bnxt_hwrm_port_led_cfg(struct bnxt *bp, bool led_on)
3911 struct hwrm_port_led_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3912 struct hwrm_port_led_cfg_input req = {0};
3913 struct bnxt_led_cfg *led_cfg;
3914 uint8_t led_state = HWRM_PORT_LED_QCFG_OUTPUT_LED0_STATE_DEFAULT;
3915 uint16_t duration = 0;
3918 if (!bp->num_leds || BNXT_VF(bp))
3921 HWRM_PREP(&req, HWRM_PORT_LED_CFG, BNXT_USE_CHIMP_MB);
3924 led_state = HWRM_PORT_LED_CFG_INPUT_LED0_STATE_BLINKALT;
3925 duration = rte_cpu_to_le_16(500);
3927 req.port_id = bp->pf.port_id;
3928 req.num_leds = bp->num_leds;
3929 led_cfg = (struct bnxt_led_cfg *)&req.led0_id;
3930 for (i = 0; i < bp->num_leds; i++, led_cfg++) {
3931 req.enables |= BNXT_LED_DFLT_ENABLES(i);
3932 led_cfg->led_id = bp->leds[i].led_id;
3933 led_cfg->led_state = led_state;
3934 led_cfg->led_blink_on = duration;
3935 led_cfg->led_blink_off = duration;
3936 led_cfg->led_group_id = bp->leds[i].led_group_id;
3939 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3941 HWRM_CHECK_RESULT();
3947 int bnxt_hwrm_nvm_get_dir_info(struct bnxt *bp, uint32_t *entries,
3951 struct hwrm_nvm_get_dir_info_input req = {0};
3952 struct hwrm_nvm_get_dir_info_output *resp = bp->hwrm_cmd_resp_addr;
3954 HWRM_PREP(&req, HWRM_NVM_GET_DIR_INFO, BNXT_USE_CHIMP_MB);
3956 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3958 HWRM_CHECK_RESULT();
3960 *entries = rte_le_to_cpu_32(resp->entries);
3961 *length = rte_le_to_cpu_32(resp->entry_length);
3967 int bnxt_get_nvram_directory(struct bnxt *bp, uint32_t len, uint8_t *data)
3970 uint32_t dir_entries;
3971 uint32_t entry_length;
3974 rte_iova_t dma_handle;
3975 struct hwrm_nvm_get_dir_entries_input req = {0};
3976 struct hwrm_nvm_get_dir_entries_output *resp = bp->hwrm_cmd_resp_addr;
3978 rc = bnxt_hwrm_nvm_get_dir_info(bp, &dir_entries, &entry_length);
3982 *data++ = dir_entries;
3983 *data++ = entry_length;
3985 memset(data, 0xff, len);
3987 buflen = dir_entries * entry_length;
3988 buf = rte_malloc("nvm_dir", buflen, 0);
3991 dma_handle = rte_malloc_virt2iova(buf);
3992 if (dma_handle == RTE_BAD_IOVA) {
3994 "unable to map response address to physical memory\n");
3997 HWRM_PREP(&req, HWRM_NVM_GET_DIR_ENTRIES, BNXT_USE_CHIMP_MB);
3998 req.host_dest_addr = rte_cpu_to_le_64(dma_handle);
3999 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4002 memcpy(data, buf, len > buflen ? buflen : len);
4005 HWRM_CHECK_RESULT();
4011 int bnxt_hwrm_get_nvram_item(struct bnxt *bp, uint32_t index,
4012 uint32_t offset, uint32_t length,
4017 rte_iova_t dma_handle;
4018 struct hwrm_nvm_read_input req = {0};
4019 struct hwrm_nvm_read_output *resp = bp->hwrm_cmd_resp_addr;
4021 buf = rte_malloc("nvm_item", length, 0);
4025 dma_handle = rte_malloc_virt2iova(buf);
4026 if (dma_handle == RTE_BAD_IOVA) {
4028 "unable to map response address to physical memory\n");
4031 HWRM_PREP(&req, HWRM_NVM_READ, BNXT_USE_CHIMP_MB);
4032 req.host_dest_addr = rte_cpu_to_le_64(dma_handle);
4033 req.dir_idx = rte_cpu_to_le_16(index);
4034 req.offset = rte_cpu_to_le_32(offset);
4035 req.len = rte_cpu_to_le_32(length);
4036 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4038 memcpy(data, buf, length);
4041 HWRM_CHECK_RESULT();
4047 int bnxt_hwrm_erase_nvram_directory(struct bnxt *bp, uint8_t index)
4050 struct hwrm_nvm_erase_dir_entry_input req = {0};
4051 struct hwrm_nvm_erase_dir_entry_output *resp = bp->hwrm_cmd_resp_addr;
4053 HWRM_PREP(&req, HWRM_NVM_ERASE_DIR_ENTRY, BNXT_USE_CHIMP_MB);
4054 req.dir_idx = rte_cpu_to_le_16(index);
4055 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4056 HWRM_CHECK_RESULT();
4063 int bnxt_hwrm_flash_nvram(struct bnxt *bp, uint16_t dir_type,
4064 uint16_t dir_ordinal, uint16_t dir_ext,
4065 uint16_t dir_attr, const uint8_t *data,
4069 struct hwrm_nvm_write_input req = {0};
4070 struct hwrm_nvm_write_output *resp = bp->hwrm_cmd_resp_addr;
4071 rte_iova_t dma_handle;
4074 buf = rte_malloc("nvm_write", data_len, 0);
4078 dma_handle = rte_malloc_virt2iova(buf);
4079 if (dma_handle == RTE_BAD_IOVA) {
4081 "unable to map response address to physical memory\n");
4084 memcpy(buf, data, data_len);
4086 HWRM_PREP(&req, HWRM_NVM_WRITE, BNXT_USE_CHIMP_MB);
4088 req.dir_type = rte_cpu_to_le_16(dir_type);
4089 req.dir_ordinal = rte_cpu_to_le_16(dir_ordinal);
4090 req.dir_ext = rte_cpu_to_le_16(dir_ext);
4091 req.dir_attr = rte_cpu_to_le_16(dir_attr);
4092 req.dir_data_length = rte_cpu_to_le_32(data_len);
4093 req.host_src_addr = rte_cpu_to_le_64(dma_handle);
4095 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4098 HWRM_CHECK_RESULT();
4105 bnxt_vnic_count(struct bnxt_vnic_info *vnic __rte_unused, void *cbdata)
4107 uint32_t *count = cbdata;
4109 *count = *count + 1;
4112 static int bnxt_vnic_count_hwrm_stub(struct bnxt *bp __rte_unused,
4113 struct bnxt_vnic_info *vnic __rte_unused)
4118 int bnxt_vf_vnic_count(struct bnxt *bp, uint16_t vf)
4122 bnxt_hwrm_func_vf_vnic_query_and_config(bp, vf, bnxt_vnic_count,
4123 &count, bnxt_vnic_count_hwrm_stub);
4128 static int bnxt_hwrm_func_vf_vnic_query(struct bnxt *bp, uint16_t vf,
4131 struct hwrm_func_vf_vnic_ids_query_input req = {0};
4132 struct hwrm_func_vf_vnic_ids_query_output *resp =
4133 bp->hwrm_cmd_resp_addr;
4136 /* First query all VNIC ids */
4137 HWRM_PREP(&req, HWRM_FUNC_VF_VNIC_IDS_QUERY, BNXT_USE_CHIMP_MB);
4139 req.vf_id = rte_cpu_to_le_16(bp->pf.first_vf_id + vf);
4140 req.max_vnic_id_cnt = rte_cpu_to_le_32(bp->pf.total_vnics);
4141 req.vnic_id_tbl_addr = rte_cpu_to_le_64(rte_malloc_virt2iova(vnic_ids));
4143 if (req.vnic_id_tbl_addr == RTE_BAD_IOVA) {
4146 "unable to map VNIC ID table address to physical memory\n");
4149 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4150 HWRM_CHECK_RESULT();
4151 rc = rte_le_to_cpu_32(resp->vnic_id_cnt);
4159 * This function queries the VNIC IDs for a specified VF. It then calls
4160 * the vnic_cb to update the necessary field in vnic_info with cbdata.
4161 * Then it calls the hwrm_cb function to program this new vnic configuration.
4163 int bnxt_hwrm_func_vf_vnic_query_and_config(struct bnxt *bp, uint16_t vf,
4164 void (*vnic_cb)(struct bnxt_vnic_info *, void *), void *cbdata,
4165 int (*hwrm_cb)(struct bnxt *bp, struct bnxt_vnic_info *vnic))
4167 struct bnxt_vnic_info vnic;
4169 int i, num_vnic_ids;
4174 /* First query all VNIC ids */
4175 vnic_id_sz = bp->pf.total_vnics * sizeof(*vnic_ids);
4176 vnic_ids = rte_malloc("bnxt_hwrm_vf_vnic_ids_query", vnic_id_sz,
4177 RTE_CACHE_LINE_SIZE);
4178 if (vnic_ids == NULL)
4181 for (sz = 0; sz < vnic_id_sz; sz += getpagesize())
4182 rte_mem_lock_page(((char *)vnic_ids) + sz);
4184 num_vnic_ids = bnxt_hwrm_func_vf_vnic_query(bp, vf, vnic_ids);
4186 if (num_vnic_ids < 0)
4187 return num_vnic_ids;
4189 /* Retrieve VNIC, update bd_stall then update */
4191 for (i = 0; i < num_vnic_ids; i++) {
4192 memset(&vnic, 0, sizeof(struct bnxt_vnic_info));
4193 vnic.fw_vnic_id = rte_le_to_cpu_16(vnic_ids[i]);
4194 rc = bnxt_hwrm_vnic_qcfg(bp, &vnic, bp->pf.first_vf_id + vf);
4197 if (vnic.mru <= 4) /* Indicates unallocated */
4200 vnic_cb(&vnic, cbdata);
4202 rc = hwrm_cb(bp, &vnic);
4212 int bnxt_hwrm_func_cfg_vf_set_vlan_anti_spoof(struct bnxt *bp, uint16_t vf,
4215 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
4216 struct hwrm_func_cfg_input req = {0};
4219 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
4221 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
4222 req.enables |= rte_cpu_to_le_32(
4223 HWRM_FUNC_CFG_INPUT_ENABLES_VLAN_ANTISPOOF_MODE);
4224 req.vlan_antispoof_mode = on ?
4225 HWRM_FUNC_CFG_INPUT_VLAN_ANTISPOOF_MODE_VALIDATE_VLAN :
4226 HWRM_FUNC_CFG_INPUT_VLAN_ANTISPOOF_MODE_NOCHECK;
4227 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4229 HWRM_CHECK_RESULT();
4235 int bnxt_hwrm_func_qcfg_vf_dflt_vnic_id(struct bnxt *bp, int vf)
4237 struct bnxt_vnic_info vnic;
4240 int num_vnic_ids, i;
4244 vnic_id_sz = bp->pf.total_vnics * sizeof(*vnic_ids);
4245 vnic_ids = rte_malloc("bnxt_hwrm_vf_vnic_ids_query", vnic_id_sz,
4246 RTE_CACHE_LINE_SIZE);
4247 if (vnic_ids == NULL)
4250 for (sz = 0; sz < vnic_id_sz; sz += getpagesize())
4251 rte_mem_lock_page(((char *)vnic_ids) + sz);
4253 rc = bnxt_hwrm_func_vf_vnic_query(bp, vf, vnic_ids);
4259 * Loop through to find the default VNIC ID.
4260 * TODO: The easier way would be to obtain the resp->dflt_vnic_id
4261 * by sending the hwrm_func_qcfg command to the firmware.
4263 for (i = 0; i < num_vnic_ids; i++) {
4264 memset(&vnic, 0, sizeof(struct bnxt_vnic_info));
4265 vnic.fw_vnic_id = rte_le_to_cpu_16(vnic_ids[i]);
4266 rc = bnxt_hwrm_vnic_qcfg(bp, &vnic,
4267 bp->pf.first_vf_id + vf);
4270 if (vnic.func_default) {
4272 return vnic.fw_vnic_id;
4275 /* Could not find a default VNIC. */
4276 PMD_DRV_LOG(ERR, "No default VNIC\n");
4282 int bnxt_hwrm_set_em_filter(struct bnxt *bp,
4284 struct bnxt_filter_info *filter)
4287 struct hwrm_cfa_em_flow_alloc_input req = {.req_type = 0 };
4288 struct hwrm_cfa_em_flow_alloc_output *resp = bp->hwrm_cmd_resp_addr;
4289 uint32_t enables = 0;
4291 if (filter->fw_em_filter_id != UINT64_MAX)
4292 bnxt_hwrm_clear_em_filter(bp, filter);
4294 HWRM_PREP(&req, HWRM_CFA_EM_FLOW_ALLOC, BNXT_USE_KONG(bp));
4296 req.flags = rte_cpu_to_le_32(filter->flags);
4298 enables = filter->enables |
4299 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_ID;
4300 req.dst_id = rte_cpu_to_le_16(dst_id);
4302 if (filter->ip_addr_type) {
4303 req.ip_addr_type = filter->ip_addr_type;
4304 enables |= HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IPADDR_TYPE;
4307 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_L2_FILTER_ID)
4308 req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
4310 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_MACADDR)
4311 memcpy(req.src_macaddr, filter->src_macaddr,
4312 RTE_ETHER_ADDR_LEN);
4314 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_MACADDR)
4315 memcpy(req.dst_macaddr, filter->dst_macaddr,
4316 RTE_ETHER_ADDR_LEN);
4318 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_OVLAN_VID)
4319 req.ovlan_vid = filter->l2_ovlan;
4321 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IVLAN_VID)
4322 req.ivlan_vid = filter->l2_ivlan;
4324 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_ETHERTYPE)
4325 req.ethertype = rte_cpu_to_be_16(filter->ethertype);
4327 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IP_PROTOCOL)
4328 req.ip_protocol = filter->ip_protocol;
4330 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_IPADDR)
4331 req.src_ipaddr[0] = rte_cpu_to_be_32(filter->src_ipaddr[0]);
4333 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_IPADDR)
4334 req.dst_ipaddr[0] = rte_cpu_to_be_32(filter->dst_ipaddr[0]);
4336 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_PORT)
4337 req.src_port = rte_cpu_to_be_16(filter->src_port);
4339 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_PORT)
4340 req.dst_port = rte_cpu_to_be_16(filter->dst_port);
4342 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_MIRROR_VNIC_ID)
4343 req.mirror_vnic_id = filter->mirror_vnic_id;
4345 req.enables = rte_cpu_to_le_32(enables);
4347 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
4349 HWRM_CHECK_RESULT();
4351 filter->fw_em_filter_id = rte_le_to_cpu_64(resp->em_filter_id);
4357 int bnxt_hwrm_clear_em_filter(struct bnxt *bp, struct bnxt_filter_info *filter)
4360 struct hwrm_cfa_em_flow_free_input req = {.req_type = 0 };
4361 struct hwrm_cfa_em_flow_free_output *resp = bp->hwrm_cmd_resp_addr;
4363 if (filter->fw_em_filter_id == UINT64_MAX)
4366 HWRM_PREP(&req, HWRM_CFA_EM_FLOW_FREE, BNXT_USE_KONG(bp));
4368 req.em_filter_id = rte_cpu_to_le_64(filter->fw_em_filter_id);
4370 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
4372 HWRM_CHECK_RESULT();
4375 filter->fw_em_filter_id = UINT64_MAX;
4376 filter->fw_l2_filter_id = UINT64_MAX;
4381 int bnxt_hwrm_set_ntuple_filter(struct bnxt *bp,
4383 struct bnxt_filter_info *filter)
4386 struct hwrm_cfa_ntuple_filter_alloc_input req = {.req_type = 0 };
4387 struct hwrm_cfa_ntuple_filter_alloc_output *resp =
4388 bp->hwrm_cmd_resp_addr;
4389 uint32_t enables = 0;
4391 if (filter->fw_ntuple_filter_id != UINT64_MAX)
4392 bnxt_hwrm_clear_ntuple_filter(bp, filter);
4394 HWRM_PREP(&req, HWRM_CFA_NTUPLE_FILTER_ALLOC, BNXT_USE_CHIMP_MB);
4396 req.flags = rte_cpu_to_le_32(filter->flags);
4398 enables = filter->enables |
4399 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_ID;
4400 req.dst_id = rte_cpu_to_le_16(dst_id);
4402 if (filter->ip_addr_type) {
4403 req.ip_addr_type = filter->ip_addr_type;
4405 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_IPADDR_TYPE;
4408 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_L2_FILTER_ID)
4409 req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
4411 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_MACADDR)
4412 memcpy(req.src_macaddr, filter->src_macaddr,
4413 RTE_ETHER_ADDR_LEN);
4415 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_ETHERTYPE)
4416 req.ethertype = rte_cpu_to_be_16(filter->ethertype);
4418 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_IP_PROTOCOL)
4419 req.ip_protocol = filter->ip_protocol;
4421 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_IPADDR)
4422 req.src_ipaddr[0] = rte_cpu_to_le_32(filter->src_ipaddr[0]);
4424 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_IPADDR_MASK)
4425 req.src_ipaddr_mask[0] =
4426 rte_cpu_to_le_32(filter->src_ipaddr_mask[0]);
4428 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_IPADDR)
4429 req.dst_ipaddr[0] = rte_cpu_to_le_32(filter->dst_ipaddr[0]);
4431 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_IPADDR_MASK)
4432 req.dst_ipaddr_mask[0] =
4433 rte_cpu_to_be_32(filter->dst_ipaddr_mask[0]);
4435 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_PORT)
4436 req.src_port = rte_cpu_to_le_16(filter->src_port);
4438 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_PORT_MASK)
4439 req.src_port_mask = rte_cpu_to_le_16(filter->src_port_mask);
4441 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_PORT)
4442 req.dst_port = rte_cpu_to_le_16(filter->dst_port);
4444 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_PORT_MASK)
4445 req.dst_port_mask = rte_cpu_to_le_16(filter->dst_port_mask);
4447 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_MIRROR_VNIC_ID)
4448 req.mirror_vnic_id = filter->mirror_vnic_id;
4450 req.enables = rte_cpu_to_le_32(enables);
4452 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4454 HWRM_CHECK_RESULT();
4456 filter->fw_ntuple_filter_id = rte_le_to_cpu_64(resp->ntuple_filter_id);
4457 filter->flow_id = rte_le_to_cpu_32(resp->flow_id);
4463 int bnxt_hwrm_clear_ntuple_filter(struct bnxt *bp,
4464 struct bnxt_filter_info *filter)
4467 struct hwrm_cfa_ntuple_filter_free_input req = {.req_type = 0 };
4468 struct hwrm_cfa_ntuple_filter_free_output *resp =
4469 bp->hwrm_cmd_resp_addr;
4471 if (filter->fw_ntuple_filter_id == UINT64_MAX)
4474 HWRM_PREP(&req, HWRM_CFA_NTUPLE_FILTER_FREE, BNXT_USE_CHIMP_MB);
4476 req.ntuple_filter_id = rte_cpu_to_le_64(filter->fw_ntuple_filter_id);
4478 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4480 HWRM_CHECK_RESULT();
4483 filter->fw_ntuple_filter_id = UINT64_MAX;
4489 bnxt_vnic_rss_configure_thor(struct bnxt *bp, struct bnxt_vnic_info *vnic)
4491 struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
4492 uint8_t *rx_queue_state = bp->eth_dev->data->rx_queue_state;
4493 struct hwrm_vnic_rss_cfg_input req = {.req_type = 0 };
4494 struct bnxt_rx_queue **rxqs = bp->rx_queues;
4495 uint16_t *ring_tbl = vnic->rss_table;
4496 int nr_ctxs = vnic->num_lb_ctxts;
4497 int max_rings = bp->rx_nr_rings;
4501 for (i = 0, k = 0; i < nr_ctxs; i++) {
4502 struct bnxt_rx_ring_info *rxr;
4503 struct bnxt_cp_ring_info *cpr;
4505 HWRM_PREP(&req, HWRM_VNIC_RSS_CFG, BNXT_USE_CHIMP_MB);
4507 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
4508 req.hash_type = rte_cpu_to_le_32(vnic->hash_type);
4509 req.hash_mode_flags = vnic->hash_mode;
4511 req.ring_grp_tbl_addr =
4512 rte_cpu_to_le_64(vnic->rss_table_dma_addr +
4513 i * BNXT_RSS_ENTRIES_PER_CTX_THOR *
4514 2 * sizeof(*ring_tbl));
4515 req.hash_key_tbl_addr =
4516 rte_cpu_to_le_64(vnic->rss_hash_key_dma_addr);
4518 req.ring_table_pair_index = i;
4519 req.rss_ctx_idx = rte_cpu_to_le_16(vnic->fw_grp_ids[i]);
4521 for (j = 0; j < 64; j++) {
4524 /* Find next active ring. */
4525 for (cnt = 0; cnt < max_rings; cnt++) {
4526 if (rx_queue_state[k] !=
4527 RTE_ETH_QUEUE_STATE_STOPPED)
4529 if (++k == max_rings)
4533 /* Return if no rings are active. */
4534 if (cnt == max_rings) {
4539 /* Add rx/cp ring pair to RSS table. */
4540 rxr = rxqs[k]->rx_ring;
4541 cpr = rxqs[k]->cp_ring;
4543 ring_id = rxr->rx_ring_struct->fw_ring_id;
4544 *ring_tbl++ = rte_cpu_to_le_16(ring_id);
4545 ring_id = cpr->cp_ring_struct->fw_ring_id;
4546 *ring_tbl++ = rte_cpu_to_le_16(ring_id);
4548 if (++k == max_rings)
4551 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req),
4554 HWRM_CHECK_RESULT();
4561 int bnxt_vnic_rss_configure(struct bnxt *bp, struct bnxt_vnic_info *vnic)
4563 unsigned int rss_idx, fw_idx, i;
4565 if (!(vnic->rss_table && vnic->hash_type))
4568 if (BNXT_CHIP_THOR(bp))
4569 return bnxt_vnic_rss_configure_thor(bp, vnic);
4571 if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
4574 if (vnic->rss_table && vnic->hash_type) {
4576 * Fill the RSS hash & redirection table with
4577 * ring group ids for all VNICs
4579 for (rss_idx = 0, fw_idx = 0; rss_idx < HW_HASH_INDEX_SIZE;
4580 rss_idx++, fw_idx++) {
4581 for (i = 0; i < bp->rx_cp_nr_rings; i++) {
4582 fw_idx %= bp->rx_cp_nr_rings;
4583 if (vnic->fw_grp_ids[fw_idx] !=
4588 if (i == bp->rx_cp_nr_rings)
4590 vnic->rss_table[rss_idx] = vnic->fw_grp_ids[fw_idx];
4592 return bnxt_hwrm_vnic_rss_cfg(bp, vnic);
4598 static void bnxt_hwrm_set_coal_params(struct bnxt_coal *hw_coal,
4599 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *req)
4603 req->num_cmpl_aggr_int = rte_cpu_to_le_16(hw_coal->num_cmpl_aggr_int);
4605 /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
4606 req->num_cmpl_dma_aggr = rte_cpu_to_le_16(hw_coal->num_cmpl_dma_aggr);
4608 /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
4609 req->num_cmpl_dma_aggr_during_int =
4610 rte_cpu_to_le_16(hw_coal->num_cmpl_dma_aggr_during_int);
4612 req->int_lat_tmr_max = rte_cpu_to_le_16(hw_coal->int_lat_tmr_max);
4614 /* min timer set to 1/2 of interrupt timer */
4615 req->int_lat_tmr_min = rte_cpu_to_le_16(hw_coal->int_lat_tmr_min);
4617 /* buf timer set to 1/4 of interrupt timer */
4618 req->cmpl_aggr_dma_tmr = rte_cpu_to_le_16(hw_coal->cmpl_aggr_dma_tmr);
4620 req->cmpl_aggr_dma_tmr_during_int =
4621 rte_cpu_to_le_16(hw_coal->cmpl_aggr_dma_tmr_during_int);
4623 flags = HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_TIMER_RESET |
4624 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_RING_IDLE;
4625 req->flags = rte_cpu_to_le_16(flags);
4628 static int bnxt_hwrm_set_coal_params_thor(struct bnxt *bp,
4629 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *agg_req)
4631 struct hwrm_ring_aggint_qcaps_input req = {0};
4632 struct hwrm_ring_aggint_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
4637 HWRM_PREP(&req, HWRM_RING_AGGINT_QCAPS, BNXT_USE_CHIMP_MB);
4638 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4639 HWRM_CHECK_RESULT();
4641 agg_req->num_cmpl_dma_aggr = resp->num_cmpl_dma_aggr_max;
4642 agg_req->cmpl_aggr_dma_tmr = resp->cmpl_aggr_dma_tmr_min;
4644 flags = HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_TIMER_RESET |
4645 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_RING_IDLE;
4646 agg_req->flags = rte_cpu_to_le_16(flags);
4648 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_ENABLES_CMPL_AGGR_DMA_TMR |
4649 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_ENABLES_NUM_CMPL_DMA_AGGR;
4650 agg_req->enables = rte_cpu_to_le_32(enables);
4656 int bnxt_hwrm_set_ring_coal(struct bnxt *bp,
4657 struct bnxt_coal *coal, uint16_t ring_id)
4659 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req = {0};
4660 struct hwrm_ring_cmpl_ring_cfg_aggint_params_output *resp =
4661 bp->hwrm_cmd_resp_addr;
4664 /* Set ring coalesce parameters only for 100G NICs */
4665 if (BNXT_CHIP_THOR(bp)) {
4666 if (bnxt_hwrm_set_coal_params_thor(bp, &req))
4668 } else if (bnxt_stratus_device(bp)) {
4669 bnxt_hwrm_set_coal_params(coal, &req);
4675 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS,
4677 req.ring_id = rte_cpu_to_le_16(ring_id);
4678 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4679 HWRM_CHECK_RESULT();
4684 #define BNXT_RTE_MEMZONE_FLAG (RTE_MEMZONE_1GB | RTE_MEMZONE_IOVA_CONTIG)
4685 int bnxt_hwrm_func_backing_store_qcaps(struct bnxt *bp)
4687 struct hwrm_func_backing_store_qcaps_input req = {0};
4688 struct hwrm_func_backing_store_qcaps_output *resp =
4689 bp->hwrm_cmd_resp_addr;
4690 struct bnxt_ctx_pg_info *ctx_pg;
4691 struct bnxt_ctx_mem_info *ctx;
4692 int total_alloc_len;
4695 if (!BNXT_CHIP_THOR(bp) ||
4696 bp->hwrm_spec_code < HWRM_VERSION_1_9_2 ||
4701 HWRM_PREP(&req, HWRM_FUNC_BACKING_STORE_QCAPS, BNXT_USE_CHIMP_MB);
4702 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4703 HWRM_CHECK_RESULT_SILENT();
4705 total_alloc_len = sizeof(*ctx);
4706 ctx = rte_zmalloc("bnxt_ctx_mem", total_alloc_len,
4707 RTE_CACHE_LINE_SIZE);
4713 ctx_pg = rte_malloc("bnxt_ctx_pg_mem",
4714 sizeof(*ctx_pg) * BNXT_MAX_Q,
4715 RTE_CACHE_LINE_SIZE);
4720 for (i = 0; i < BNXT_MAX_Q; i++, ctx_pg++)
4721 ctx->tqm_mem[i] = ctx_pg;
4724 ctx->qp_max_entries = rte_le_to_cpu_32(resp->qp_max_entries);
4725 ctx->qp_min_qp1_entries =
4726 rte_le_to_cpu_16(resp->qp_min_qp1_entries);
4727 ctx->qp_max_l2_entries =
4728 rte_le_to_cpu_16(resp->qp_max_l2_entries);
4729 ctx->qp_entry_size = rte_le_to_cpu_16(resp->qp_entry_size);
4730 ctx->srq_max_l2_entries =
4731 rte_le_to_cpu_16(resp->srq_max_l2_entries);
4732 ctx->srq_max_entries = rte_le_to_cpu_32(resp->srq_max_entries);
4733 ctx->srq_entry_size = rte_le_to_cpu_16(resp->srq_entry_size);
4734 ctx->cq_max_l2_entries =
4735 rte_le_to_cpu_16(resp->cq_max_l2_entries);
4736 ctx->cq_max_entries = rte_le_to_cpu_32(resp->cq_max_entries);
4737 ctx->cq_entry_size = rte_le_to_cpu_16(resp->cq_entry_size);
4738 ctx->vnic_max_vnic_entries =
4739 rte_le_to_cpu_16(resp->vnic_max_vnic_entries);
4740 ctx->vnic_max_ring_table_entries =
4741 rte_le_to_cpu_16(resp->vnic_max_ring_table_entries);
4742 ctx->vnic_entry_size = rte_le_to_cpu_16(resp->vnic_entry_size);
4743 ctx->stat_max_entries =
4744 rte_le_to_cpu_32(resp->stat_max_entries);
4745 ctx->stat_entry_size = rte_le_to_cpu_16(resp->stat_entry_size);
4746 ctx->tqm_entry_size = rte_le_to_cpu_16(resp->tqm_entry_size);
4747 ctx->tqm_min_entries_per_ring =
4748 rte_le_to_cpu_32(resp->tqm_min_entries_per_ring);
4749 ctx->tqm_max_entries_per_ring =
4750 rte_le_to_cpu_32(resp->tqm_max_entries_per_ring);
4751 ctx->tqm_entries_multiple = resp->tqm_entries_multiple;
4752 if (!ctx->tqm_entries_multiple)
4753 ctx->tqm_entries_multiple = 1;
4754 ctx->mrav_max_entries =
4755 rte_le_to_cpu_32(resp->mrav_max_entries);
4756 ctx->mrav_entry_size = rte_le_to_cpu_16(resp->mrav_entry_size);
4757 ctx->tim_entry_size = rte_le_to_cpu_16(resp->tim_entry_size);
4758 ctx->tim_max_entries = rte_le_to_cpu_32(resp->tim_max_entries);
4764 int bnxt_hwrm_func_backing_store_cfg(struct bnxt *bp, uint32_t enables)
4766 struct hwrm_func_backing_store_cfg_input req = {0};
4767 struct hwrm_func_backing_store_cfg_output *resp =
4768 bp->hwrm_cmd_resp_addr;
4769 struct bnxt_ctx_mem_info *ctx = bp->ctx;
4770 struct bnxt_ctx_pg_info *ctx_pg;
4771 uint32_t *num_entries;
4780 HWRM_PREP(&req, HWRM_FUNC_BACKING_STORE_CFG, BNXT_USE_CHIMP_MB);
4781 req.enables = rte_cpu_to_le_32(enables);
4783 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_QP) {
4784 ctx_pg = &ctx->qp_mem;
4785 req.qp_num_entries = rte_cpu_to_le_32(ctx_pg->entries);
4786 req.qp_num_qp1_entries =
4787 rte_cpu_to_le_16(ctx->qp_min_qp1_entries);
4788 req.qp_num_l2_entries =
4789 rte_cpu_to_le_16(ctx->qp_max_l2_entries);
4790 req.qp_entry_size = rte_cpu_to_le_16(ctx->qp_entry_size);
4791 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4792 &req.qpc_pg_size_qpc_lvl,
4796 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_SRQ) {
4797 ctx_pg = &ctx->srq_mem;
4798 req.srq_num_entries = rte_cpu_to_le_32(ctx_pg->entries);
4799 req.srq_num_l2_entries =
4800 rte_cpu_to_le_16(ctx->srq_max_l2_entries);
4801 req.srq_entry_size = rte_cpu_to_le_16(ctx->srq_entry_size);
4802 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4803 &req.srq_pg_size_srq_lvl,
4807 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_CQ) {
4808 ctx_pg = &ctx->cq_mem;
4809 req.cq_num_entries = rte_cpu_to_le_32(ctx_pg->entries);
4810 req.cq_num_l2_entries =
4811 rte_cpu_to_le_16(ctx->cq_max_l2_entries);
4812 req.cq_entry_size = rte_cpu_to_le_16(ctx->cq_entry_size);
4813 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4814 &req.cq_pg_size_cq_lvl,
4818 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_VNIC) {
4819 ctx_pg = &ctx->vnic_mem;
4820 req.vnic_num_vnic_entries =
4821 rte_cpu_to_le_16(ctx->vnic_max_vnic_entries);
4822 req.vnic_num_ring_table_entries =
4823 rte_cpu_to_le_16(ctx->vnic_max_ring_table_entries);
4824 req.vnic_entry_size = rte_cpu_to_le_16(ctx->vnic_entry_size);
4825 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4826 &req.vnic_pg_size_vnic_lvl,
4827 &req.vnic_page_dir);
4830 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_STAT) {
4831 ctx_pg = &ctx->stat_mem;
4832 req.stat_num_entries = rte_cpu_to_le_16(ctx->stat_max_entries);
4833 req.stat_entry_size = rte_cpu_to_le_16(ctx->stat_entry_size);
4834 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4835 &req.stat_pg_size_stat_lvl,
4836 &req.stat_page_dir);
4839 req.tqm_entry_size = rte_cpu_to_le_16(ctx->tqm_entry_size);
4840 num_entries = &req.tqm_sp_num_entries;
4841 pg_attr = &req.tqm_sp_pg_size_tqm_sp_lvl;
4842 pg_dir = &req.tqm_sp_page_dir;
4843 ena = HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_TQM_SP;
4844 for (i = 0; i < 9; i++, num_entries++, pg_attr++, pg_dir++, ena <<= 1) {
4845 if (!(enables & ena))
4848 req.tqm_entry_size = rte_cpu_to_le_16(ctx->tqm_entry_size);
4850 ctx_pg = ctx->tqm_mem[i];
4851 *num_entries = rte_cpu_to_le_16(ctx_pg->entries);
4852 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem, pg_attr, pg_dir);
4855 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4856 HWRM_CHECK_RESULT();
4862 int bnxt_hwrm_ext_port_qstats(struct bnxt *bp)
4864 struct hwrm_port_qstats_ext_input req = {0};
4865 struct hwrm_port_qstats_ext_output *resp = bp->hwrm_cmd_resp_addr;
4866 struct bnxt_pf_info *pf = &bp->pf;
4869 if (!(bp->flags & BNXT_FLAG_EXT_RX_PORT_STATS ||
4870 bp->flags & BNXT_FLAG_EXT_TX_PORT_STATS))
4873 HWRM_PREP(&req, HWRM_PORT_QSTATS_EXT, BNXT_USE_CHIMP_MB);
4875 req.port_id = rte_cpu_to_le_16(pf->port_id);
4876 if (bp->flags & BNXT_FLAG_EXT_TX_PORT_STATS) {
4877 req.tx_stat_host_addr =
4878 rte_cpu_to_le_64(bp->hw_tx_port_stats_ext_map);
4880 rte_cpu_to_le_16(sizeof(struct tx_port_stats_ext));
4882 if (bp->flags & BNXT_FLAG_EXT_RX_PORT_STATS) {
4883 req.rx_stat_host_addr =
4884 rte_cpu_to_le_64(bp->hw_rx_port_stats_ext_map);
4886 rte_cpu_to_le_16(sizeof(struct rx_port_stats_ext));
4888 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4891 bp->fw_rx_port_stats_ext_size = 0;
4892 bp->fw_tx_port_stats_ext_size = 0;
4894 bp->fw_rx_port_stats_ext_size =
4895 rte_le_to_cpu_16(resp->rx_stat_size);
4896 bp->fw_tx_port_stats_ext_size =
4897 rte_le_to_cpu_16(resp->tx_stat_size);
4900 HWRM_CHECK_RESULT();
4907 bnxt_hwrm_tunnel_redirect(struct bnxt *bp, uint8_t type)
4909 struct hwrm_cfa_redirect_tunnel_type_alloc_input req = {0};
4910 struct hwrm_cfa_redirect_tunnel_type_alloc_output *resp =
4911 bp->hwrm_cmd_resp_addr;
4914 HWRM_PREP(&req, HWRM_CFA_REDIRECT_TUNNEL_TYPE_ALLOC, BNXT_USE_CHIMP_MB);
4915 req.tunnel_type = type;
4916 req.dest_fid = bp->fw_fid;
4917 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4918 HWRM_CHECK_RESULT();
4926 bnxt_hwrm_tunnel_redirect_free(struct bnxt *bp, uint8_t type)
4928 struct hwrm_cfa_redirect_tunnel_type_free_input req = {0};
4929 struct hwrm_cfa_redirect_tunnel_type_free_output *resp =
4930 bp->hwrm_cmd_resp_addr;
4933 HWRM_PREP(&req, HWRM_CFA_REDIRECT_TUNNEL_TYPE_FREE, BNXT_USE_CHIMP_MB);
4934 req.tunnel_type = type;
4935 req.dest_fid = bp->fw_fid;
4936 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4937 HWRM_CHECK_RESULT();
4944 int bnxt_hwrm_tunnel_redirect_query(struct bnxt *bp, uint32_t *type)
4946 struct hwrm_cfa_redirect_query_tunnel_type_input req = {0};
4947 struct hwrm_cfa_redirect_query_tunnel_type_output *resp =
4948 bp->hwrm_cmd_resp_addr;
4951 HWRM_PREP(&req, HWRM_CFA_REDIRECT_QUERY_TUNNEL_TYPE, BNXT_USE_CHIMP_MB);
4952 req.src_fid = bp->fw_fid;
4953 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4954 HWRM_CHECK_RESULT();
4957 *type = rte_le_to_cpu_32(resp->tunnel_mask);
4964 int bnxt_hwrm_tunnel_redirect_info(struct bnxt *bp, uint8_t tun_type,
4967 struct hwrm_cfa_redirect_tunnel_type_info_input req = {0};
4968 struct hwrm_cfa_redirect_tunnel_type_info_output *resp =
4969 bp->hwrm_cmd_resp_addr;
4972 HWRM_PREP(&req, HWRM_CFA_REDIRECT_TUNNEL_TYPE_INFO, BNXT_USE_CHIMP_MB);
4973 req.src_fid = bp->fw_fid;
4974 req.tunnel_type = tun_type;
4975 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4976 HWRM_CHECK_RESULT();
4979 *dst_fid = rte_le_to_cpu_16(resp->dest_fid);
4981 PMD_DRV_LOG(DEBUG, "dst_fid: %x\n", resp->dest_fid);
4988 int bnxt_hwrm_set_mac(struct bnxt *bp)
4990 struct hwrm_func_vf_cfg_output *resp = bp->hwrm_cmd_resp_addr;
4991 struct hwrm_func_vf_cfg_input req = {0};
4997 HWRM_PREP(&req, HWRM_FUNC_VF_CFG, BNXT_USE_CHIMP_MB);
5000 rte_cpu_to_le_32(HWRM_FUNC_VF_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
5001 memcpy(req.dflt_mac_addr, bp->mac_addr, RTE_ETHER_ADDR_LEN);
5003 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5005 HWRM_CHECK_RESULT();
5007 memcpy(bp->dflt_mac_addr, bp->mac_addr, RTE_ETHER_ADDR_LEN);
5013 int bnxt_hwrm_if_change(struct bnxt *bp, bool up)
5015 struct hwrm_func_drv_if_change_output *resp = bp->hwrm_cmd_resp_addr;
5016 struct hwrm_func_drv_if_change_input req = {0};
5020 if (!(bp->fw_cap & BNXT_FW_CAP_IF_CHANGE))
5023 /* Do not issue FUNC_DRV_IF_CHANGE during reset recovery.
5024 * If we issue FUNC_DRV_IF_CHANGE with flags down before
5025 * FUNC_DRV_UNRGTR, FW resets before FUNC_DRV_UNRGTR
5027 if (!up && (bp->flags & BNXT_FLAG_FW_RESET))
5030 HWRM_PREP(&req, HWRM_FUNC_DRV_IF_CHANGE, BNXT_USE_CHIMP_MB);
5034 rte_cpu_to_le_32(HWRM_FUNC_DRV_IF_CHANGE_INPUT_FLAGS_UP);
5036 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5038 HWRM_CHECK_RESULT();
5039 flags = rte_le_to_cpu_32(resp->flags);
5045 if (flags & HWRM_FUNC_DRV_IF_CHANGE_OUTPUT_FLAGS_HOT_FW_RESET_DONE) {
5046 PMD_DRV_LOG(INFO, "FW reset happened while port was down\n");
5047 bp->flags |= BNXT_FLAG_IF_CHANGE_HOT_FW_RESET_DONE;
5053 int bnxt_hwrm_error_recovery_qcfg(struct bnxt *bp)
5055 struct hwrm_error_recovery_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
5056 struct bnxt_error_recovery_info *info = bp->recovery_info;
5057 struct hwrm_error_recovery_qcfg_input req = {0};
5062 /* Older FW does not have error recovery support */
5063 if (!(bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY))
5067 info = rte_zmalloc("bnxt_hwrm_error_recovery_qcfg",
5069 bp->recovery_info = info;
5073 memset(info, 0, sizeof(*info));
5076 HWRM_PREP(&req, HWRM_ERROR_RECOVERY_QCFG, BNXT_USE_CHIMP_MB);
5078 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5080 HWRM_CHECK_RESULT();
5082 flags = rte_le_to_cpu_32(resp->flags);
5083 if (flags & HWRM_ERROR_RECOVERY_QCFG_OUTPUT_FLAGS_HOST)
5084 info->flags |= BNXT_FLAG_ERROR_RECOVERY_HOST;
5085 else if (flags & HWRM_ERROR_RECOVERY_QCFG_OUTPUT_FLAGS_CO_CPU)
5086 info->flags |= BNXT_FLAG_ERROR_RECOVERY_CO_CPU;
5088 if ((info->flags & BNXT_FLAG_ERROR_RECOVERY_CO_CPU) &&
5089 !(bp->flags & BNXT_FLAG_KONG_MB_EN)) {
5094 /* FW returned values are in units of 100msec */
5095 info->driver_polling_freq =
5096 rte_le_to_cpu_32(resp->driver_polling_freq) * 100;
5097 info->master_func_wait_period =
5098 rte_le_to_cpu_32(resp->master_func_wait_period) * 100;
5099 info->normal_func_wait_period =
5100 rte_le_to_cpu_32(resp->normal_func_wait_period) * 100;
5101 info->master_func_wait_period_after_reset =
5102 rte_le_to_cpu_32(resp->master_func_wait_period_after_reset) * 100;
5103 info->max_bailout_time_after_reset =
5104 rte_le_to_cpu_32(resp->max_bailout_time_after_reset) * 100;
5105 info->status_regs[BNXT_FW_STATUS_REG] =
5106 rte_le_to_cpu_32(resp->fw_health_status_reg);
5107 info->status_regs[BNXT_FW_HEARTBEAT_CNT_REG] =
5108 rte_le_to_cpu_32(resp->fw_heartbeat_reg);
5109 info->status_regs[BNXT_FW_RECOVERY_CNT_REG] =
5110 rte_le_to_cpu_32(resp->fw_reset_cnt_reg);
5111 info->status_regs[BNXT_FW_RESET_INPROG_REG] =
5112 rte_le_to_cpu_32(resp->reset_inprogress_reg);
5113 info->reg_array_cnt =
5114 rte_le_to_cpu_32(resp->reg_array_cnt);
5116 if (info->reg_array_cnt >= BNXT_NUM_RESET_REG) {
5121 for (i = 0; i < info->reg_array_cnt; i++) {
5122 info->reset_reg[i] =
5123 rte_le_to_cpu_32(resp->reset_reg[i]);
5124 info->reset_reg_val[i] =
5125 rte_le_to_cpu_32(resp->reset_reg_val[i]);
5126 info->delay_after_reset[i] =
5127 resp->delay_after_reset[i];
5132 /* Map the FW status registers */
5134 rc = bnxt_map_fw_health_status_regs(bp);
5137 rte_free(bp->recovery_info);
5138 bp->recovery_info = NULL;
5143 int bnxt_hwrm_fw_reset(struct bnxt *bp)
5145 struct hwrm_fw_reset_output *resp = bp->hwrm_cmd_resp_addr;
5146 struct hwrm_fw_reset_input req = {0};
5152 HWRM_PREP(&req, HWRM_FW_RESET, BNXT_USE_KONG(bp));
5154 req.embedded_proc_type =
5155 HWRM_FW_RESET_INPUT_EMBEDDED_PROC_TYPE_CHIP;
5156 req.selfrst_status =
5157 HWRM_FW_RESET_INPUT_SELFRST_STATUS_SELFRSTASAP;
5158 req.flags = HWRM_FW_RESET_INPUT_FLAGS_RESET_GRACEFUL;
5160 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req),
5163 HWRM_CHECK_RESULT();
5169 int bnxt_hwrm_port_ts_query(struct bnxt *bp, uint8_t path, uint64_t *timestamp)
5171 struct hwrm_port_ts_query_output *resp = bp->hwrm_cmd_resp_addr;
5172 struct hwrm_port_ts_query_input req = {0};
5173 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
5180 HWRM_PREP(&req, HWRM_PORT_TS_QUERY, BNXT_USE_CHIMP_MB);
5183 case BNXT_PTP_FLAGS_PATH_TX:
5184 flags |= HWRM_PORT_TS_QUERY_INPUT_FLAGS_PATH_TX;
5186 case BNXT_PTP_FLAGS_PATH_RX:
5187 flags |= HWRM_PORT_TS_QUERY_INPUT_FLAGS_PATH_RX;
5189 case BNXT_PTP_FLAGS_CURRENT_TIME:
5190 flags |= HWRM_PORT_TS_QUERY_INPUT_FLAGS_CURRENT_TIME;
5194 req.flags = rte_cpu_to_le_32(flags);
5195 req.port_id = rte_cpu_to_le_16(bp->pf.port_id);
5197 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5199 HWRM_CHECK_RESULT();
5202 *timestamp = rte_le_to_cpu_32(resp->ptp_msg_ts[0]);
5204 (uint64_t)(rte_le_to_cpu_32(resp->ptp_msg_ts[1])) << 32;
5211 int bnxt_hwrm_cfa_adv_flow_mgmt_qcaps(struct bnxt *bp)
5213 struct hwrm_cfa_adv_flow_mgnt_qcaps_output *resp =
5214 bp->hwrm_cmd_resp_addr;
5215 struct hwrm_cfa_adv_flow_mgnt_qcaps_input req = {0};
5219 if (!(bp->flags & BNXT_FLAG_ADV_FLOW_MGMT))
5222 if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp))) {
5224 "Not a PF or trusted VF. Command not supported\n");
5228 HWRM_PREP(&req, HWRM_CFA_ADV_FLOW_MGNT_QCAPS, BNXT_USE_KONG(bp));
5229 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
5231 HWRM_CHECK_RESULT();
5232 flags = rte_le_to_cpu_32(resp->flags);
5235 if (flags & HWRM_CFA_ADV_FLOW_MGNT_QCAPS_L2_HDR_SRC_FILTER_EN) {
5236 bp->flow_flags |= BNXT_FLOW_FLAG_L2_HDR_SRC_FILTER_EN;
5237 PMD_DRV_LOG(INFO, "Source L2 header filtering enabled\n");