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)
2267 struct hwrm_func_qstats_input req = {.req_type = 0};
2268 struct hwrm_func_qstats_output *resp = bp->hwrm_cmd_resp_addr;
2270 HWRM_PREP(&req, HWRM_FUNC_QSTATS, BNXT_USE_CHIMP_MB);
2272 req.fid = rte_cpu_to_le_16(fid);
2274 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2276 HWRM_CHECK_RESULT();
2278 stats->ipackets = rte_le_to_cpu_64(resp->rx_ucast_pkts);
2279 stats->ipackets += rte_le_to_cpu_64(resp->rx_mcast_pkts);
2280 stats->ipackets += rte_le_to_cpu_64(resp->rx_bcast_pkts);
2281 stats->ibytes = rte_le_to_cpu_64(resp->rx_ucast_bytes);
2282 stats->ibytes += rte_le_to_cpu_64(resp->rx_mcast_bytes);
2283 stats->ibytes += rte_le_to_cpu_64(resp->rx_bcast_bytes);
2285 stats->opackets = rte_le_to_cpu_64(resp->tx_ucast_pkts);
2286 stats->opackets += rte_le_to_cpu_64(resp->tx_mcast_pkts);
2287 stats->opackets += rte_le_to_cpu_64(resp->tx_bcast_pkts);
2288 stats->obytes = rte_le_to_cpu_64(resp->tx_ucast_bytes);
2289 stats->obytes += rte_le_to_cpu_64(resp->tx_mcast_bytes);
2290 stats->obytes += rte_le_to_cpu_64(resp->tx_bcast_bytes);
2292 stats->imissed = rte_le_to_cpu_64(resp->rx_discard_pkts);
2293 stats->ierrors = rte_le_to_cpu_64(resp->rx_drop_pkts);
2294 stats->oerrors = rte_le_to_cpu_64(resp->tx_discard_pkts);
2301 int bnxt_hwrm_func_clr_stats(struct bnxt *bp, uint16_t fid)
2304 struct hwrm_func_clr_stats_input req = {.req_type = 0};
2305 struct hwrm_func_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
2307 HWRM_PREP(&req, HWRM_FUNC_CLR_STATS, BNXT_USE_CHIMP_MB);
2309 req.fid = rte_cpu_to_le_16(fid);
2311 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2313 HWRM_CHECK_RESULT();
2319 int bnxt_clear_all_hwrm_stat_ctxs(struct bnxt *bp)
2324 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
2325 struct bnxt_tx_queue *txq;
2326 struct bnxt_rx_queue *rxq;
2327 struct bnxt_cp_ring_info *cpr;
2329 if (i >= bp->rx_cp_nr_rings) {
2330 txq = bp->tx_queues[i - bp->rx_cp_nr_rings];
2333 rxq = bp->rx_queues[i];
2337 rc = bnxt_hwrm_stat_clear(bp, cpr);
2345 bnxt_free_all_hwrm_stat_ctxs(struct bnxt *bp)
2349 struct bnxt_cp_ring_info *cpr;
2351 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
2353 if (i >= bp->rx_cp_nr_rings) {
2354 cpr = bp->tx_queues[i - bp->rx_cp_nr_rings]->cp_ring;
2356 cpr = bp->rx_queues[i]->cp_ring;
2357 if (BNXT_HAS_RING_GRPS(bp))
2358 bp->grp_info[i].fw_stats_ctx = -1;
2360 if (cpr->hw_stats_ctx_id != HWRM_NA_SIGNATURE) {
2361 rc = bnxt_hwrm_stat_ctx_free(bp, cpr, i);
2362 cpr->hw_stats_ctx_id = HWRM_NA_SIGNATURE;
2370 int bnxt_alloc_all_hwrm_stat_ctxs(struct bnxt *bp)
2375 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
2376 struct bnxt_tx_queue *txq;
2377 struct bnxt_rx_queue *rxq;
2378 struct bnxt_cp_ring_info *cpr;
2380 if (i >= bp->rx_cp_nr_rings) {
2381 txq = bp->tx_queues[i - bp->rx_cp_nr_rings];
2384 rxq = bp->rx_queues[i];
2388 rc = bnxt_hwrm_stat_ctx_alloc(bp, cpr, i);
2397 bnxt_free_all_hwrm_ring_grps(struct bnxt *bp)
2402 if (!BNXT_HAS_RING_GRPS(bp))
2405 for (idx = 0; idx < bp->rx_cp_nr_rings; idx++) {
2407 if (bp->grp_info[idx].fw_grp_id == INVALID_HW_RING_ID)
2410 rc = bnxt_hwrm_ring_grp_free(bp, idx);
2418 void bnxt_free_nq_ring(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
2420 struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
2422 bnxt_hwrm_ring_free(bp, cp_ring,
2423 HWRM_RING_FREE_INPUT_RING_TYPE_NQ);
2424 cp_ring->fw_ring_id = INVALID_HW_RING_ID;
2425 memset(cpr->cp_desc_ring, 0, cpr->cp_ring_struct->ring_size *
2426 sizeof(*cpr->cp_desc_ring));
2427 cpr->cp_raw_cons = 0;
2431 void bnxt_free_cp_ring(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
2433 struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
2435 bnxt_hwrm_ring_free(bp, cp_ring,
2436 HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL);
2437 cp_ring->fw_ring_id = INVALID_HW_RING_ID;
2438 memset(cpr->cp_desc_ring, 0, cpr->cp_ring_struct->ring_size *
2439 sizeof(*cpr->cp_desc_ring));
2440 cpr->cp_raw_cons = 0;
2444 void bnxt_free_hwrm_rx_ring(struct bnxt *bp, int queue_index)
2446 struct bnxt_rx_queue *rxq = bp->rx_queues[queue_index];
2447 struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
2448 struct bnxt_ring *ring = rxr->rx_ring_struct;
2449 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
2451 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
2452 bnxt_hwrm_ring_free(bp, ring,
2453 HWRM_RING_FREE_INPUT_RING_TYPE_RX);
2454 ring->fw_ring_id = INVALID_HW_RING_ID;
2455 if (BNXT_HAS_RING_GRPS(bp))
2456 bp->grp_info[queue_index].rx_fw_ring_id =
2458 memset(rxr->rx_desc_ring, 0,
2459 rxr->rx_ring_struct->ring_size *
2460 sizeof(*rxr->rx_desc_ring));
2461 memset(rxr->rx_buf_ring, 0,
2462 rxr->rx_ring_struct->ring_size *
2463 sizeof(*rxr->rx_buf_ring));
2466 ring = rxr->ag_ring_struct;
2467 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
2468 bnxt_hwrm_ring_free(bp, ring,
2469 BNXT_CHIP_THOR(bp) ?
2470 HWRM_RING_FREE_INPUT_RING_TYPE_RX_AGG :
2471 HWRM_RING_FREE_INPUT_RING_TYPE_RX);
2472 ring->fw_ring_id = INVALID_HW_RING_ID;
2473 memset(rxr->ag_buf_ring, 0,
2474 rxr->ag_ring_struct->ring_size *
2475 sizeof(*rxr->ag_buf_ring));
2477 if (BNXT_HAS_RING_GRPS(bp))
2478 bp->grp_info[queue_index].ag_fw_ring_id =
2481 if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID)
2482 bnxt_free_cp_ring(bp, cpr);
2484 if (BNXT_HAS_RING_GRPS(bp))
2485 bp->grp_info[queue_index].cp_fw_ring_id = INVALID_HW_RING_ID;
2489 bnxt_free_all_hwrm_rings(struct bnxt *bp)
2493 for (i = 0; i < bp->tx_cp_nr_rings; i++) {
2494 struct bnxt_tx_queue *txq = bp->tx_queues[i];
2495 struct bnxt_tx_ring_info *txr = txq->tx_ring;
2496 struct bnxt_ring *ring = txr->tx_ring_struct;
2497 struct bnxt_cp_ring_info *cpr = txq->cp_ring;
2499 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
2500 bnxt_hwrm_ring_free(bp, ring,
2501 HWRM_RING_FREE_INPUT_RING_TYPE_TX);
2502 ring->fw_ring_id = INVALID_HW_RING_ID;
2503 memset(txr->tx_desc_ring, 0,
2504 txr->tx_ring_struct->ring_size *
2505 sizeof(*txr->tx_desc_ring));
2506 memset(txr->tx_buf_ring, 0,
2507 txr->tx_ring_struct->ring_size *
2508 sizeof(*txr->tx_buf_ring));
2512 if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID) {
2513 bnxt_free_cp_ring(bp, cpr);
2514 cpr->cp_ring_struct->fw_ring_id = INVALID_HW_RING_ID;
2518 for (i = 0; i < bp->rx_cp_nr_rings; i++)
2519 bnxt_free_hwrm_rx_ring(bp, i);
2524 int bnxt_alloc_all_hwrm_ring_grps(struct bnxt *bp)
2529 if (!BNXT_HAS_RING_GRPS(bp))
2532 for (i = 0; i < bp->rx_cp_nr_rings; i++) {
2533 rc = bnxt_hwrm_ring_grp_alloc(bp, i);
2541 * HWRM utility functions
2544 void bnxt_free_hwrm_resources(struct bnxt *bp)
2546 /* Release memzone */
2547 rte_free(bp->hwrm_cmd_resp_addr);
2548 rte_free(bp->hwrm_short_cmd_req_addr);
2549 bp->hwrm_cmd_resp_addr = NULL;
2550 bp->hwrm_short_cmd_req_addr = NULL;
2551 bp->hwrm_cmd_resp_dma_addr = 0;
2552 bp->hwrm_short_cmd_req_dma_addr = 0;
2555 int bnxt_alloc_hwrm_resources(struct bnxt *bp)
2557 struct rte_pci_device *pdev = bp->pdev;
2558 char type[RTE_MEMZONE_NAMESIZE];
2560 sprintf(type, "bnxt_hwrm_%04x:%02x:%02x:%02x", pdev->addr.domain,
2561 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
2562 bp->max_resp_len = HWRM_MAX_RESP_LEN;
2563 bp->hwrm_cmd_resp_addr = rte_malloc(type, bp->max_resp_len, 0);
2564 if (bp->hwrm_cmd_resp_addr == NULL)
2566 bp->hwrm_cmd_resp_dma_addr =
2567 rte_malloc_virt2iova(bp->hwrm_cmd_resp_addr);
2568 if (bp->hwrm_cmd_resp_dma_addr == RTE_BAD_IOVA) {
2570 "unable to map response address to physical memory\n");
2573 rte_spinlock_init(&bp->hwrm_lock);
2579 bnxt_clear_hwrm_vnic_filters(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2581 struct bnxt_filter_info *filter;
2584 STAILQ_FOREACH(filter, &vnic->filter, next) {
2585 if (filter->filter_type == HWRM_CFA_EM_FILTER)
2586 rc = bnxt_hwrm_clear_em_filter(bp, filter);
2587 else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
2588 rc = bnxt_hwrm_clear_ntuple_filter(bp, filter);
2589 rc = bnxt_hwrm_clear_l2_filter(bp, filter);
2590 STAILQ_REMOVE(&vnic->filter, filter, bnxt_filter_info, next);
2591 bnxt_free_filter(bp, filter);
2597 bnxt_clear_hwrm_vnic_flows(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2599 struct bnxt_filter_info *filter;
2600 struct rte_flow *flow;
2603 while (!STAILQ_EMPTY(&vnic->flow_list)) {
2604 flow = STAILQ_FIRST(&vnic->flow_list);
2605 filter = flow->filter;
2606 PMD_DRV_LOG(DEBUG, "filter type %d\n", filter->filter_type);
2607 if (filter->filter_type == HWRM_CFA_EM_FILTER)
2608 rc = bnxt_hwrm_clear_em_filter(bp, filter);
2609 else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
2610 rc = bnxt_hwrm_clear_ntuple_filter(bp, filter);
2611 rc = bnxt_hwrm_clear_l2_filter(bp, filter);
2613 STAILQ_REMOVE(&vnic->flow_list, flow, rte_flow, next);
2619 int bnxt_set_hwrm_vnic_filters(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2621 struct bnxt_filter_info *filter;
2624 STAILQ_FOREACH(filter, &vnic->filter, next) {
2625 if (filter->filter_type == HWRM_CFA_EM_FILTER)
2626 rc = bnxt_hwrm_set_em_filter(bp, filter->dst_id,
2628 else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
2629 rc = bnxt_hwrm_set_ntuple_filter(bp, filter->dst_id,
2632 rc = bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id,
2641 bnxt_free_tunnel_ports(struct bnxt *bp)
2643 if (bp->vxlan_port_cnt)
2644 bnxt_hwrm_tunnel_dst_port_free(bp, bp->vxlan_fw_dst_port_id,
2645 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_VXLAN);
2647 if (bp->geneve_port_cnt)
2648 bnxt_hwrm_tunnel_dst_port_free(bp, bp->geneve_fw_dst_port_id,
2649 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_GENEVE);
2650 bp->geneve_port = 0;
2653 void bnxt_free_all_hwrm_resources(struct bnxt *bp)
2657 if (bp->vnic_info == NULL)
2661 * Cleanup VNICs in reverse order, to make sure the L2 filter
2662 * from vnic0 is last to be cleaned up.
2664 for (i = bp->max_vnics - 1; i >= 0; i--) {
2665 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
2667 if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
2670 bnxt_clear_hwrm_vnic_flows(bp, vnic);
2672 bnxt_clear_hwrm_vnic_filters(bp, vnic);
2674 bnxt_hwrm_vnic_ctx_free(bp, vnic);
2676 bnxt_hwrm_vnic_tpa_cfg(bp, vnic, false);
2678 bnxt_hwrm_vnic_free(bp, vnic);
2680 rte_free(vnic->fw_grp_ids);
2682 /* Ring resources */
2683 bnxt_free_all_hwrm_rings(bp);
2684 bnxt_free_all_hwrm_ring_grps(bp);
2685 bnxt_free_all_hwrm_stat_ctxs(bp);
2686 bnxt_free_tunnel_ports(bp);
2689 static uint16_t bnxt_parse_eth_link_duplex(uint32_t conf_link_speed)
2691 uint8_t hw_link_duplex = HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH;
2693 if ((conf_link_speed & ETH_LINK_SPEED_FIXED) == ETH_LINK_SPEED_AUTONEG)
2694 return HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH;
2696 switch (conf_link_speed) {
2697 case ETH_LINK_SPEED_10M_HD:
2698 case ETH_LINK_SPEED_100M_HD:
2700 return HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_HALF;
2702 return hw_link_duplex;
2705 static uint16_t bnxt_check_eth_link_autoneg(uint32_t conf_link)
2707 return (conf_link & ETH_LINK_SPEED_FIXED) ? 0 : 1;
2710 static uint16_t bnxt_parse_eth_link_speed(uint32_t conf_link_speed)
2712 uint16_t eth_link_speed = 0;
2714 if (conf_link_speed == ETH_LINK_SPEED_AUTONEG)
2715 return ETH_LINK_SPEED_AUTONEG;
2717 switch (conf_link_speed & ~ETH_LINK_SPEED_FIXED) {
2718 case ETH_LINK_SPEED_100M:
2719 case ETH_LINK_SPEED_100M_HD:
2722 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_100MB;
2724 case ETH_LINK_SPEED_1G:
2726 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_1GB;
2728 case ETH_LINK_SPEED_2_5G:
2730 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_2_5GB;
2732 case ETH_LINK_SPEED_10G:
2734 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_10GB;
2736 case ETH_LINK_SPEED_20G:
2738 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_20GB;
2740 case ETH_LINK_SPEED_25G:
2742 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_25GB;
2744 case ETH_LINK_SPEED_40G:
2746 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_40GB;
2748 case ETH_LINK_SPEED_50G:
2750 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_50GB;
2752 case ETH_LINK_SPEED_100G:
2754 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_100GB;
2758 "Unsupported link speed %d; default to AUTO\n",
2762 return eth_link_speed;
2765 #define BNXT_SUPPORTED_SPEEDS (ETH_LINK_SPEED_100M | ETH_LINK_SPEED_100M_HD | \
2766 ETH_LINK_SPEED_1G | ETH_LINK_SPEED_2_5G | \
2767 ETH_LINK_SPEED_10G | ETH_LINK_SPEED_20G | ETH_LINK_SPEED_25G | \
2768 ETH_LINK_SPEED_40G | ETH_LINK_SPEED_50G | ETH_LINK_SPEED_100G)
2770 static int bnxt_valid_link_speed(uint32_t link_speed, uint16_t port_id)
2774 if (link_speed == ETH_LINK_SPEED_AUTONEG)
2777 if (link_speed & ETH_LINK_SPEED_FIXED) {
2778 one_speed = link_speed & ~ETH_LINK_SPEED_FIXED;
2780 if (one_speed & (one_speed - 1)) {
2782 "Invalid advertised speeds (%u) for port %u\n",
2783 link_speed, port_id);
2786 if ((one_speed & BNXT_SUPPORTED_SPEEDS) != one_speed) {
2788 "Unsupported advertised speed (%u) for port %u\n",
2789 link_speed, port_id);
2793 if (!(link_speed & BNXT_SUPPORTED_SPEEDS)) {
2795 "Unsupported advertised speeds (%u) for port %u\n",
2796 link_speed, port_id);
2804 bnxt_parse_eth_link_speed_mask(struct bnxt *bp, uint32_t link_speed)
2808 if (link_speed == ETH_LINK_SPEED_AUTONEG) {
2809 if (bp->link_info.support_speeds)
2810 return bp->link_info.support_speeds;
2811 link_speed = BNXT_SUPPORTED_SPEEDS;
2814 if (link_speed & ETH_LINK_SPEED_100M)
2815 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100MB;
2816 if (link_speed & ETH_LINK_SPEED_100M_HD)
2817 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100MB;
2818 if (link_speed & ETH_LINK_SPEED_1G)
2819 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_1GB;
2820 if (link_speed & ETH_LINK_SPEED_2_5G)
2821 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_2_5GB;
2822 if (link_speed & ETH_LINK_SPEED_10G)
2823 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_10GB;
2824 if (link_speed & ETH_LINK_SPEED_20G)
2825 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_20GB;
2826 if (link_speed & ETH_LINK_SPEED_25G)
2827 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_25GB;
2828 if (link_speed & ETH_LINK_SPEED_40G)
2829 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_40GB;
2830 if (link_speed & ETH_LINK_SPEED_50G)
2831 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_50GB;
2832 if (link_speed & ETH_LINK_SPEED_100G)
2833 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100GB;
2837 static uint32_t bnxt_parse_hw_link_speed(uint16_t hw_link_speed)
2839 uint32_t eth_link_speed = ETH_SPEED_NUM_NONE;
2841 switch (hw_link_speed) {
2842 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100MB:
2843 eth_link_speed = ETH_SPEED_NUM_100M;
2845 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_1GB:
2846 eth_link_speed = ETH_SPEED_NUM_1G;
2848 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2_5GB:
2849 eth_link_speed = ETH_SPEED_NUM_2_5G;
2851 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_10GB:
2852 eth_link_speed = ETH_SPEED_NUM_10G;
2854 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_20GB:
2855 eth_link_speed = ETH_SPEED_NUM_20G;
2857 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_25GB:
2858 eth_link_speed = ETH_SPEED_NUM_25G;
2860 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_40GB:
2861 eth_link_speed = ETH_SPEED_NUM_40G;
2863 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_50GB:
2864 eth_link_speed = ETH_SPEED_NUM_50G;
2866 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100GB:
2867 eth_link_speed = ETH_SPEED_NUM_100G;
2869 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2GB:
2871 PMD_DRV_LOG(ERR, "HWRM link speed %d not defined\n",
2875 return eth_link_speed;
2878 static uint16_t bnxt_parse_hw_link_duplex(uint16_t hw_link_duplex)
2880 uint16_t eth_link_duplex = ETH_LINK_FULL_DUPLEX;
2882 switch (hw_link_duplex) {
2883 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH:
2884 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_FULL:
2886 eth_link_duplex = ETH_LINK_FULL_DUPLEX;
2888 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_HALF:
2889 eth_link_duplex = ETH_LINK_HALF_DUPLEX;
2892 PMD_DRV_LOG(ERR, "HWRM link duplex %d not defined\n",
2896 return eth_link_duplex;
2899 int bnxt_get_hwrm_link_config(struct bnxt *bp, struct rte_eth_link *link)
2902 struct bnxt_link_info *link_info = &bp->link_info;
2904 rc = bnxt_hwrm_port_phy_qcfg(bp, link_info);
2907 "Get link config failed with rc %d\n", rc);
2910 if (link_info->link_speed)
2912 bnxt_parse_hw_link_speed(link_info->link_speed);
2914 link->link_speed = ETH_SPEED_NUM_NONE;
2915 link->link_duplex = bnxt_parse_hw_link_duplex(link_info->duplex);
2916 link->link_status = link_info->link_up;
2917 link->link_autoneg = link_info->auto_mode ==
2918 HWRM_PORT_PHY_QCFG_OUTPUT_AUTO_MODE_NONE ?
2919 ETH_LINK_FIXED : ETH_LINK_AUTONEG;
2924 int bnxt_set_hwrm_link_config(struct bnxt *bp, bool link_up)
2927 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
2928 struct bnxt_link_info link_req;
2929 uint16_t speed, autoneg;
2931 if (!BNXT_SINGLE_PF(bp) || BNXT_VF(bp))
2934 rc = bnxt_valid_link_speed(dev_conf->link_speeds,
2935 bp->eth_dev->data->port_id);
2939 memset(&link_req, 0, sizeof(link_req));
2940 link_req.link_up = link_up;
2944 autoneg = bnxt_check_eth_link_autoneg(dev_conf->link_speeds);
2945 if (BNXT_CHIP_THOR(bp) &&
2946 dev_conf->link_speeds == ETH_LINK_SPEED_40G) {
2947 /* 40G is not supported as part of media auto detect.
2948 * The speed should be forced and autoneg disabled
2949 * to configure 40G speed.
2951 PMD_DRV_LOG(INFO, "Disabling autoneg for 40G\n");
2955 speed = bnxt_parse_eth_link_speed(dev_conf->link_speeds);
2956 link_req.phy_flags = HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESET_PHY;
2957 /* Autoneg can be done only when the FW allows.
2958 * When user configures fixed speed of 40G and later changes to
2959 * any other speed, auto_link_speed/force_link_speed is still set
2960 * to 40G until link comes up at new speed.
2963 !(!BNXT_CHIP_THOR(bp) &&
2964 (bp->link_info.auto_link_speed ||
2965 bp->link_info.force_link_speed))) {
2966 link_req.phy_flags |=
2967 HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESTART_AUTONEG;
2968 link_req.auto_link_speed_mask =
2969 bnxt_parse_eth_link_speed_mask(bp,
2970 dev_conf->link_speeds);
2972 if (bp->link_info.phy_type ==
2973 HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET ||
2974 bp->link_info.phy_type ==
2975 HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASETE ||
2976 bp->link_info.media_type ==
2977 HWRM_PORT_PHY_QCFG_OUTPUT_MEDIA_TYPE_TP) {
2978 PMD_DRV_LOG(ERR, "10GBase-T devices must autoneg\n");
2982 link_req.phy_flags |= HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE;
2983 /* If user wants a particular speed try that first. */
2985 link_req.link_speed = speed;
2986 else if (bp->link_info.force_link_speed)
2987 link_req.link_speed = bp->link_info.force_link_speed;
2989 link_req.link_speed = bp->link_info.auto_link_speed;
2991 link_req.duplex = bnxt_parse_eth_link_duplex(dev_conf->link_speeds);
2992 link_req.auto_pause = bp->link_info.auto_pause;
2993 link_req.force_pause = bp->link_info.force_pause;
2996 rc = bnxt_hwrm_port_phy_cfg(bp, &link_req);
2999 "Set link config failed with rc %d\n", rc);
3007 int bnxt_hwrm_func_qcfg(struct bnxt *bp, uint16_t *mtu)
3009 struct hwrm_func_qcfg_input req = {0};
3010 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
3013 bp->func_svif = BNXT_SVIF_INVALID;
3016 HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
3017 req.fid = rte_cpu_to_le_16(0xffff);
3019 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3021 HWRM_CHECK_RESULT();
3023 /* Hard Coded.. 0xfff VLAN ID mask */
3024 bp->vlan = rte_le_to_cpu_16(resp->vlan) & 0xfff;
3026 svif_info = rte_le_to_cpu_16(resp->svif_info);
3027 if (svif_info & HWRM_FUNC_QCFG_OUTPUT_SVIF_INFO_SVIF_VALID)
3028 bp->func_svif = svif_info &
3029 HWRM_FUNC_QCFG_OUTPUT_SVIF_INFO_SVIF_MASK;
3031 flags = rte_le_to_cpu_16(resp->flags);
3032 if (BNXT_PF(bp) && (flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_MULTI_HOST))
3033 bp->flags |= BNXT_FLAG_MULTI_HOST;
3036 !BNXT_VF_IS_TRUSTED(bp) &&
3037 (flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_TRUSTED_VF)) {
3038 bp->flags |= BNXT_FLAG_TRUSTED_VF_EN;
3039 PMD_DRV_LOG(INFO, "Trusted VF cap enabled\n");
3040 } else if (BNXT_VF(bp) &&
3041 BNXT_VF_IS_TRUSTED(bp) &&
3042 !(flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_TRUSTED_VF)) {
3043 bp->flags &= ~BNXT_FLAG_TRUSTED_VF_EN;
3044 PMD_DRV_LOG(INFO, "Trusted VF cap disabled\n");
3048 *mtu = rte_le_to_cpu_16(resp->mtu);
3050 switch (resp->port_partition_type) {
3051 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR1_0:
3052 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR1_5:
3053 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR2_0:
3055 bp->flags |= BNXT_FLAG_NPAR_PF;
3058 bp->flags &= ~BNXT_FLAG_NPAR_PF;
3067 int bnxt_hwrm_port_mac_qcfg(struct bnxt *bp)
3069 struct hwrm_port_mac_qcfg_input req = {0};
3070 struct hwrm_port_mac_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
3071 uint16_t port_svif_info;
3074 bp->port_svif = BNXT_SVIF_INVALID;
3076 HWRM_PREP(&req, HWRM_PORT_MAC_QCFG, BNXT_USE_CHIMP_MB);
3078 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3080 HWRM_CHECK_RESULT();
3082 port_svif_info = rte_le_to_cpu_16(resp->port_svif_info);
3083 if (port_svif_info &
3084 HWRM_PORT_MAC_QCFG_OUTPUT_PORT_SVIF_INFO_PORT_SVIF_VALID)
3085 bp->port_svif = port_svif_info &
3086 HWRM_PORT_MAC_QCFG_OUTPUT_PORT_SVIF_INFO_PORT_SVIF_MASK;
3093 static void copy_func_cfg_to_qcaps(struct hwrm_func_cfg_input *fcfg,
3094 struct hwrm_func_qcaps_output *qcaps)
3096 qcaps->max_rsscos_ctx = fcfg->num_rsscos_ctxs;
3097 memcpy(qcaps->mac_address, fcfg->dflt_mac_addr,
3098 sizeof(qcaps->mac_address));
3099 qcaps->max_l2_ctxs = fcfg->num_l2_ctxs;
3100 qcaps->max_rx_rings = fcfg->num_rx_rings;
3101 qcaps->max_tx_rings = fcfg->num_tx_rings;
3102 qcaps->max_cmpl_rings = fcfg->num_cmpl_rings;
3103 qcaps->max_stat_ctx = fcfg->num_stat_ctxs;
3105 qcaps->first_vf_id = 0;
3106 qcaps->max_vnics = fcfg->num_vnics;
3107 qcaps->max_decap_records = 0;
3108 qcaps->max_encap_records = 0;
3109 qcaps->max_tx_wm_flows = 0;
3110 qcaps->max_tx_em_flows = 0;
3111 qcaps->max_rx_wm_flows = 0;
3112 qcaps->max_rx_em_flows = 0;
3113 qcaps->max_flow_id = 0;
3114 qcaps->max_mcast_filters = fcfg->num_mcast_filters;
3115 qcaps->max_sp_tx_rings = 0;
3116 qcaps->max_hw_ring_grps = fcfg->num_hw_ring_grps;
3119 static int bnxt_hwrm_pf_func_cfg(struct bnxt *bp, int tx_rings)
3121 struct hwrm_func_cfg_input req = {0};
3122 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3126 enables = HWRM_FUNC_CFG_INPUT_ENABLES_MTU |
3127 HWRM_FUNC_CFG_INPUT_ENABLES_MRU |
3128 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS |
3129 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
3130 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
3131 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_TX_RINGS |
3132 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RX_RINGS |
3133 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_L2_CTXS |
3134 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_VNICS;
3136 if (BNXT_HAS_RING_GRPS(bp)) {
3137 enables |= HWRM_FUNC_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS;
3138 req.num_hw_ring_grps = rte_cpu_to_le_16(bp->max_ring_grps);
3139 } else if (BNXT_HAS_NQ(bp)) {
3140 enables |= HWRM_FUNC_CFG_INPUT_ENABLES_NUM_MSIX;
3141 req.num_msix = rte_cpu_to_le_16(bp->max_nq_rings);
3144 req.flags = rte_cpu_to_le_32(bp->pf.func_cfg_flags);
3145 req.mtu = rte_cpu_to_le_16(BNXT_MAX_MTU);
3146 req.mru = rte_cpu_to_le_16(BNXT_VNIC_MRU(bp->eth_dev->data->mtu));
3147 req.num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx);
3148 req.num_stat_ctxs = rte_cpu_to_le_16(bp->max_stat_ctx);
3149 req.num_cmpl_rings = rte_cpu_to_le_16(bp->max_cp_rings);
3150 req.num_tx_rings = rte_cpu_to_le_16(tx_rings);
3151 req.num_rx_rings = rte_cpu_to_le_16(bp->max_rx_rings);
3152 req.num_l2_ctxs = rte_cpu_to_le_16(bp->max_l2_ctx);
3153 req.num_vnics = rte_cpu_to_le_16(bp->max_vnics);
3154 req.fid = rte_cpu_to_le_16(0xffff);
3155 req.enables = rte_cpu_to_le_32(enables);
3157 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
3159 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3161 HWRM_CHECK_RESULT();
3167 static void populate_vf_func_cfg_req(struct bnxt *bp,
3168 struct hwrm_func_cfg_input *req,
3171 req->enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_MTU |
3172 HWRM_FUNC_CFG_INPUT_ENABLES_MRU |
3173 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS |
3174 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
3175 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
3176 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_TX_RINGS |
3177 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RX_RINGS |
3178 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_L2_CTXS |
3179 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_VNICS |
3180 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS);
3182 req->mtu = rte_cpu_to_le_16(bp->eth_dev->data->mtu + RTE_ETHER_HDR_LEN +
3183 RTE_ETHER_CRC_LEN + VLAN_TAG_SIZE *
3185 req->mru = rte_cpu_to_le_16(BNXT_VNIC_MRU(bp->eth_dev->data->mtu));
3186 req->num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx /
3188 req->num_stat_ctxs = rte_cpu_to_le_16(bp->max_stat_ctx / (num_vfs + 1));
3189 req->num_cmpl_rings = rte_cpu_to_le_16(bp->max_cp_rings /
3191 req->num_tx_rings = rte_cpu_to_le_16(bp->max_tx_rings / (num_vfs + 1));
3192 req->num_rx_rings = rte_cpu_to_le_16(bp->max_rx_rings / (num_vfs + 1));
3193 req->num_l2_ctxs = rte_cpu_to_le_16(bp->max_l2_ctx / (num_vfs + 1));
3194 /* TODO: For now, do not support VMDq/RFS on VFs. */
3195 req->num_vnics = rte_cpu_to_le_16(1);
3196 req->num_hw_ring_grps = rte_cpu_to_le_16(bp->max_ring_grps /
3200 static void add_random_mac_if_needed(struct bnxt *bp,
3201 struct hwrm_func_cfg_input *cfg_req,
3204 struct rte_ether_addr mac;
3206 if (bnxt_hwrm_func_qcfg_vf_default_mac(bp, vf, &mac))
3209 if (memcmp(mac.addr_bytes, "\x00\x00\x00\x00\x00", 6) == 0) {
3211 rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
3212 rte_eth_random_addr(cfg_req->dflt_mac_addr);
3213 bp->pf.vf_info[vf].random_mac = true;
3215 memcpy(cfg_req->dflt_mac_addr, mac.addr_bytes,
3216 RTE_ETHER_ADDR_LEN);
3220 static int reserve_resources_from_vf(struct bnxt *bp,
3221 struct hwrm_func_cfg_input *cfg_req,
3224 struct hwrm_func_qcaps_input req = {0};
3225 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
3228 /* Get the actual allocated values now */
3229 HWRM_PREP(&req, HWRM_FUNC_QCAPS, BNXT_USE_CHIMP_MB);
3230 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3231 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3234 PMD_DRV_LOG(ERR, "hwrm_func_qcaps failed rc:%d\n", rc);
3235 copy_func_cfg_to_qcaps(cfg_req, resp);
3236 } else if (resp->error_code) {
3237 rc = rte_le_to_cpu_16(resp->error_code);
3238 PMD_DRV_LOG(ERR, "hwrm_func_qcaps error %d\n", rc);
3239 copy_func_cfg_to_qcaps(cfg_req, resp);
3242 bp->max_rsscos_ctx -= rte_le_to_cpu_16(resp->max_rsscos_ctx);
3243 bp->max_stat_ctx -= rte_le_to_cpu_16(resp->max_stat_ctx);
3244 bp->max_cp_rings -= rte_le_to_cpu_16(resp->max_cmpl_rings);
3245 bp->max_tx_rings -= rte_le_to_cpu_16(resp->max_tx_rings);
3246 bp->max_rx_rings -= rte_le_to_cpu_16(resp->max_rx_rings);
3247 bp->max_l2_ctx -= rte_le_to_cpu_16(resp->max_l2_ctxs);
3249 * TODO: While not supporting VMDq with VFs, max_vnics is always
3250 * forced to 1 in this case
3252 //bp->max_vnics -= rte_le_to_cpu_16(esp->max_vnics);
3253 bp->max_ring_grps -= rte_le_to_cpu_16(resp->max_hw_ring_grps);
3260 int bnxt_hwrm_func_qcfg_current_vf_vlan(struct bnxt *bp, int vf)
3262 struct hwrm_func_qcfg_input req = {0};
3263 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
3266 /* Check for zero MAC address */
3267 HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
3268 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3269 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3270 HWRM_CHECK_RESULT();
3271 rc = rte_le_to_cpu_16(resp->vlan);
3278 static int update_pf_resource_max(struct bnxt *bp)
3280 struct hwrm_func_qcfg_input req = {0};
3281 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
3284 /* And copy the allocated numbers into the pf struct */
3285 HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
3286 req.fid = rte_cpu_to_le_16(0xffff);
3287 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3288 HWRM_CHECK_RESULT();
3290 /* Only TX ring value reflects actual allocation? TODO */
3291 bp->max_tx_rings = rte_le_to_cpu_16(resp->alloc_tx_rings);
3292 bp->pf.evb_mode = resp->evb_mode;
3299 int bnxt_hwrm_allocate_pf_only(struct bnxt *bp)
3304 PMD_DRV_LOG(ERR, "Attempt to allcoate VFs on a VF!\n");
3308 rc = bnxt_hwrm_func_qcaps(bp);
3312 bp->pf.func_cfg_flags &=
3313 ~(HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE |
3314 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE);
3315 bp->pf.func_cfg_flags |=
3316 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE;
3317 rc = bnxt_hwrm_pf_func_cfg(bp, bp->max_tx_rings);
3318 rc = __bnxt_hwrm_func_qcaps(bp);
3322 int bnxt_hwrm_allocate_vfs(struct bnxt *bp, int num_vfs)
3324 struct hwrm_func_cfg_input req = {0};
3325 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3332 PMD_DRV_LOG(ERR, "Attempt to allcoate VFs on a VF!\n");
3336 rc = bnxt_hwrm_func_qcaps(bp);
3341 bp->pf.active_vfs = num_vfs;
3344 * First, configure the PF to only use one TX ring. This ensures that
3345 * there are enough rings for all VFs.
3347 * If we don't do this, when we call func_alloc() later, we will lock
3348 * extra rings to the PF that won't be available during func_cfg() of
3351 * This has been fixed with firmware versions above 20.6.54
3353 bp->pf.func_cfg_flags &=
3354 ~(HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE |
3355 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE);
3356 bp->pf.func_cfg_flags |=
3357 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE;
3358 rc = bnxt_hwrm_pf_func_cfg(bp, 1);
3363 * Now, create and register a buffer to hold forwarded VF requests
3365 req_buf_sz = num_vfs * HWRM_MAX_REQ_LEN;
3366 bp->pf.vf_req_buf = rte_malloc("bnxt_vf_fwd", req_buf_sz,
3367 page_roundup(num_vfs * HWRM_MAX_REQ_LEN));
3368 if (bp->pf.vf_req_buf == NULL) {
3372 for (sz = 0; sz < req_buf_sz; sz += getpagesize())
3373 rte_mem_lock_page(((char *)bp->pf.vf_req_buf) + sz);
3374 for (i = 0; i < num_vfs; i++)
3375 bp->pf.vf_info[i].req_buf = ((char *)bp->pf.vf_req_buf) +
3376 (i * HWRM_MAX_REQ_LEN);
3378 rc = bnxt_hwrm_func_buf_rgtr(bp);
3382 populate_vf_func_cfg_req(bp, &req, num_vfs);
3384 bp->pf.active_vfs = 0;
3385 for (i = 0; i < num_vfs; i++) {
3386 add_random_mac_if_needed(bp, &req, i);
3388 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
3389 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[i].func_cfg_flags);
3390 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[i].fid);
3391 rc = bnxt_hwrm_send_message(bp,
3396 /* Clear enable flag for next pass */
3397 req.enables &= ~rte_cpu_to_le_32(
3398 HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
3400 if (rc || resp->error_code) {
3402 "Failed to initizlie VF %d\n", i);
3404 "Not all VFs available. (%d, %d)\n",
3405 rc, resp->error_code);
3412 reserve_resources_from_vf(bp, &req, i);
3413 bp->pf.active_vfs++;
3414 bnxt_hwrm_func_clr_stats(bp, bp->pf.vf_info[i].fid);
3418 * Now configure the PF to use "the rest" of the resources
3419 * We're using STD_TX_RING_MODE here though which will limit the TX
3420 * rings. This will allow QoS to function properly. Not setting this
3421 * will cause PF rings to break bandwidth settings.
3423 rc = bnxt_hwrm_pf_func_cfg(bp, bp->max_tx_rings);
3427 rc = update_pf_resource_max(bp);
3434 bnxt_hwrm_func_buf_unrgtr(bp);
3438 int bnxt_hwrm_pf_evb_mode(struct bnxt *bp)
3440 struct hwrm_func_cfg_input req = {0};
3441 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3444 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
3446 req.fid = rte_cpu_to_le_16(0xffff);
3447 req.enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_EVB_MODE);
3448 req.evb_mode = bp->pf.evb_mode;
3450 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3451 HWRM_CHECK_RESULT();
3457 int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt *bp, uint16_t port,
3458 uint8_t tunnel_type)
3460 struct hwrm_tunnel_dst_port_alloc_input req = {0};
3461 struct hwrm_tunnel_dst_port_alloc_output *resp = bp->hwrm_cmd_resp_addr;
3464 HWRM_PREP(&req, HWRM_TUNNEL_DST_PORT_ALLOC, BNXT_USE_CHIMP_MB);
3465 req.tunnel_type = tunnel_type;
3466 req.tunnel_dst_port_val = port;
3467 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3468 HWRM_CHECK_RESULT();
3470 switch (tunnel_type) {
3471 case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_VXLAN:
3472 bp->vxlan_fw_dst_port_id = resp->tunnel_dst_port_id;
3473 bp->vxlan_port = port;
3475 case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_GENEVE:
3476 bp->geneve_fw_dst_port_id = resp->tunnel_dst_port_id;
3477 bp->geneve_port = port;
3488 int bnxt_hwrm_tunnel_dst_port_free(struct bnxt *bp, uint16_t port,
3489 uint8_t tunnel_type)
3491 struct hwrm_tunnel_dst_port_free_input req = {0};
3492 struct hwrm_tunnel_dst_port_free_output *resp = bp->hwrm_cmd_resp_addr;
3495 HWRM_PREP(&req, HWRM_TUNNEL_DST_PORT_FREE, BNXT_USE_CHIMP_MB);
3497 req.tunnel_type = tunnel_type;
3498 req.tunnel_dst_port_id = rte_cpu_to_be_16(port);
3499 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3501 HWRM_CHECK_RESULT();
3507 int bnxt_hwrm_func_cfg_vf_set_flags(struct bnxt *bp, uint16_t vf,
3510 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3511 struct hwrm_func_cfg_input req = {0};
3514 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
3516 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3517 req.flags = rte_cpu_to_le_32(flags);
3518 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3520 HWRM_CHECK_RESULT();
3526 void vf_vnic_set_rxmask_cb(struct bnxt_vnic_info *vnic, void *flagp)
3528 uint32_t *flag = flagp;
3530 vnic->flags = *flag;
3533 int bnxt_set_rx_mask_no_vlan(struct bnxt *bp, struct bnxt_vnic_info *vnic)
3535 return bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
3538 int bnxt_hwrm_func_buf_rgtr(struct bnxt *bp)
3541 struct hwrm_func_buf_rgtr_input req = {.req_type = 0 };
3542 struct hwrm_func_buf_rgtr_output *resp = bp->hwrm_cmd_resp_addr;
3544 HWRM_PREP(&req, HWRM_FUNC_BUF_RGTR, BNXT_USE_CHIMP_MB);
3546 req.req_buf_num_pages = rte_cpu_to_le_16(1);
3547 req.req_buf_page_size = rte_cpu_to_le_16(
3548 page_getenum(bp->pf.active_vfs * HWRM_MAX_REQ_LEN));
3549 req.req_buf_len = rte_cpu_to_le_16(HWRM_MAX_REQ_LEN);
3550 req.req_buf_page_addr0 =
3551 rte_cpu_to_le_64(rte_malloc_virt2iova(bp->pf.vf_req_buf));
3552 if (req.req_buf_page_addr0 == RTE_BAD_IOVA) {
3554 "unable to map buffer address to physical memory\n");
3558 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3560 HWRM_CHECK_RESULT();
3566 int bnxt_hwrm_func_buf_unrgtr(struct bnxt *bp)
3569 struct hwrm_func_buf_unrgtr_input req = {.req_type = 0 };
3570 struct hwrm_func_buf_unrgtr_output *resp = bp->hwrm_cmd_resp_addr;
3572 if (!(BNXT_PF(bp) && bp->pdev->max_vfs))
3575 HWRM_PREP(&req, HWRM_FUNC_BUF_UNRGTR, BNXT_USE_CHIMP_MB);
3577 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3579 HWRM_CHECK_RESULT();
3585 int bnxt_hwrm_func_cfg_def_cp(struct bnxt *bp)
3587 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3588 struct hwrm_func_cfg_input req = {0};
3591 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
3593 req.fid = rte_cpu_to_le_16(0xffff);
3594 req.flags = rte_cpu_to_le_32(bp->pf.func_cfg_flags);
3595 req.enables = rte_cpu_to_le_32(
3596 HWRM_FUNC_CFG_INPUT_ENABLES_ASYNC_EVENT_CR);
3597 req.async_event_cr = rte_cpu_to_le_16(
3598 bp->async_cp_ring->cp_ring_struct->fw_ring_id);
3599 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3601 HWRM_CHECK_RESULT();
3607 int bnxt_hwrm_vf_func_cfg_def_cp(struct bnxt *bp)
3609 struct hwrm_func_vf_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3610 struct hwrm_func_vf_cfg_input req = {0};
3613 HWRM_PREP(&req, HWRM_FUNC_VF_CFG, BNXT_USE_CHIMP_MB);
3615 req.enables = rte_cpu_to_le_32(
3616 HWRM_FUNC_VF_CFG_INPUT_ENABLES_ASYNC_EVENT_CR);
3617 req.async_event_cr = rte_cpu_to_le_16(
3618 bp->async_cp_ring->cp_ring_struct->fw_ring_id);
3619 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3621 HWRM_CHECK_RESULT();
3627 int bnxt_hwrm_set_default_vlan(struct bnxt *bp, int vf, uint8_t is_vf)
3629 struct hwrm_func_cfg_input req = {0};
3630 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3631 uint16_t dflt_vlan, fid;
3632 uint32_t func_cfg_flags;
3635 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
3638 dflt_vlan = bp->pf.vf_info[vf].dflt_vlan;
3639 fid = bp->pf.vf_info[vf].fid;
3640 func_cfg_flags = bp->pf.vf_info[vf].func_cfg_flags;
3642 fid = rte_cpu_to_le_16(0xffff);
3643 func_cfg_flags = bp->pf.func_cfg_flags;
3644 dflt_vlan = bp->vlan;
3647 req.flags = rte_cpu_to_le_32(func_cfg_flags);
3648 req.fid = rte_cpu_to_le_16(fid);
3649 req.enables |= rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_VLAN);
3650 req.dflt_vlan = rte_cpu_to_le_16(dflt_vlan);
3652 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3654 HWRM_CHECK_RESULT();
3660 int bnxt_hwrm_func_bw_cfg(struct bnxt *bp, uint16_t vf,
3661 uint16_t max_bw, uint16_t enables)
3663 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3664 struct hwrm_func_cfg_input req = {0};
3667 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
3669 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3670 req.enables |= rte_cpu_to_le_32(enables);
3671 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[vf].func_cfg_flags);
3672 req.max_bw = rte_cpu_to_le_32(max_bw);
3673 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3675 HWRM_CHECK_RESULT();
3681 int bnxt_hwrm_set_vf_vlan(struct bnxt *bp, int vf)
3683 struct hwrm_func_cfg_input req = {0};
3684 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3687 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
3689 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[vf].func_cfg_flags);
3690 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3691 req.enables |= rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_VLAN);
3692 req.dflt_vlan = rte_cpu_to_le_16(bp->pf.vf_info[vf].dflt_vlan);
3694 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3696 HWRM_CHECK_RESULT();
3702 int bnxt_hwrm_set_async_event_cr(struct bnxt *bp)
3707 rc = bnxt_hwrm_func_cfg_def_cp(bp);
3709 rc = bnxt_hwrm_vf_func_cfg_def_cp(bp);
3714 int bnxt_hwrm_reject_fwd_resp(struct bnxt *bp, uint16_t target_id,
3715 void *encaped, size_t ec_size)
3718 struct hwrm_reject_fwd_resp_input req = {.req_type = 0};
3719 struct hwrm_reject_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr;
3721 if (ec_size > sizeof(req.encap_request))
3724 HWRM_PREP(&req, HWRM_REJECT_FWD_RESP, BNXT_USE_CHIMP_MB);
3726 req.encap_resp_target_id = rte_cpu_to_le_16(target_id);
3727 memcpy(req.encap_request, encaped, ec_size);
3729 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3731 HWRM_CHECK_RESULT();
3737 int bnxt_hwrm_func_qcfg_vf_default_mac(struct bnxt *bp, uint16_t vf,
3738 struct rte_ether_addr *mac)
3740 struct hwrm_func_qcfg_input req = {0};
3741 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
3744 HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
3746 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3747 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3749 HWRM_CHECK_RESULT();
3751 memcpy(mac->addr_bytes, resp->mac_address, RTE_ETHER_ADDR_LEN);
3758 int bnxt_hwrm_exec_fwd_resp(struct bnxt *bp, uint16_t target_id,
3759 void *encaped, size_t ec_size)
3762 struct hwrm_exec_fwd_resp_input req = {.req_type = 0};
3763 struct hwrm_exec_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr;
3765 if (ec_size > sizeof(req.encap_request))
3768 HWRM_PREP(&req, HWRM_EXEC_FWD_RESP, BNXT_USE_CHIMP_MB);
3770 req.encap_resp_target_id = rte_cpu_to_le_16(target_id);
3771 memcpy(req.encap_request, encaped, ec_size);
3773 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3775 HWRM_CHECK_RESULT();
3781 int bnxt_hwrm_ctx_qstats(struct bnxt *bp, uint32_t cid, int idx,
3782 struct rte_eth_stats *stats, uint8_t rx)
3785 struct hwrm_stat_ctx_query_input req = {.req_type = 0};
3786 struct hwrm_stat_ctx_query_output *resp = bp->hwrm_cmd_resp_addr;
3788 HWRM_PREP(&req, HWRM_STAT_CTX_QUERY, BNXT_USE_CHIMP_MB);
3790 req.stat_ctx_id = rte_cpu_to_le_32(cid);
3792 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3794 HWRM_CHECK_RESULT();
3797 stats->q_ipackets[idx] = rte_le_to_cpu_64(resp->rx_ucast_pkts);
3798 stats->q_ipackets[idx] += rte_le_to_cpu_64(resp->rx_mcast_pkts);
3799 stats->q_ipackets[idx] += rte_le_to_cpu_64(resp->rx_bcast_pkts);
3800 stats->q_ibytes[idx] = rte_le_to_cpu_64(resp->rx_ucast_bytes);
3801 stats->q_ibytes[idx] += rte_le_to_cpu_64(resp->rx_mcast_bytes);
3802 stats->q_ibytes[idx] += rte_le_to_cpu_64(resp->rx_bcast_bytes);
3803 stats->q_errors[idx] = rte_le_to_cpu_64(resp->rx_err_pkts);
3804 stats->q_errors[idx] += rte_le_to_cpu_64(resp->rx_drop_pkts);
3806 stats->q_opackets[idx] = rte_le_to_cpu_64(resp->tx_ucast_pkts);
3807 stats->q_opackets[idx] += rte_le_to_cpu_64(resp->tx_mcast_pkts);
3808 stats->q_opackets[idx] += rte_le_to_cpu_64(resp->tx_bcast_pkts);
3809 stats->q_obytes[idx] = rte_le_to_cpu_64(resp->tx_ucast_bytes);
3810 stats->q_obytes[idx] += rte_le_to_cpu_64(resp->tx_mcast_bytes);
3811 stats->q_obytes[idx] += rte_le_to_cpu_64(resp->tx_bcast_bytes);
3819 int bnxt_hwrm_port_qstats(struct bnxt *bp)
3821 struct hwrm_port_qstats_input req = {0};
3822 struct hwrm_port_qstats_output *resp = bp->hwrm_cmd_resp_addr;
3823 struct bnxt_pf_info *pf = &bp->pf;
3826 HWRM_PREP(&req, HWRM_PORT_QSTATS, BNXT_USE_CHIMP_MB);
3828 req.port_id = rte_cpu_to_le_16(pf->port_id);
3829 req.tx_stat_host_addr = rte_cpu_to_le_64(bp->hw_tx_port_stats_map);
3830 req.rx_stat_host_addr = rte_cpu_to_le_64(bp->hw_rx_port_stats_map);
3831 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3833 HWRM_CHECK_RESULT();
3839 int bnxt_hwrm_port_clr_stats(struct bnxt *bp)
3841 struct hwrm_port_clr_stats_input req = {0};
3842 struct hwrm_port_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
3843 struct bnxt_pf_info *pf = &bp->pf;
3846 /* Not allowed on NS2 device, NPAR, MultiHost, VF */
3847 if (!(bp->flags & BNXT_FLAG_PORT_STATS) || BNXT_VF(bp) ||
3848 BNXT_NPAR(bp) || BNXT_MH(bp) || BNXT_TOTAL_VFS(bp))
3851 HWRM_PREP(&req, HWRM_PORT_CLR_STATS, BNXT_USE_CHIMP_MB);
3853 req.port_id = rte_cpu_to_le_16(pf->port_id);
3854 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3856 HWRM_CHECK_RESULT();
3862 int bnxt_hwrm_port_led_qcaps(struct bnxt *bp)
3864 struct hwrm_port_led_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
3865 struct hwrm_port_led_qcaps_input req = {0};
3871 HWRM_PREP(&req, HWRM_PORT_LED_QCAPS, BNXT_USE_CHIMP_MB);
3872 req.port_id = bp->pf.port_id;
3873 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3875 HWRM_CHECK_RESULT();
3877 if (resp->num_leds > 0 && resp->num_leds < BNXT_MAX_LED) {
3880 bp->num_leds = resp->num_leds;
3881 memcpy(bp->leds, &resp->led0_id,
3882 sizeof(bp->leds[0]) * bp->num_leds);
3883 for (i = 0; i < bp->num_leds; i++) {
3884 struct bnxt_led_info *led = &bp->leds[i];
3886 uint16_t caps = led->led_state_caps;
3888 if (!led->led_group_id ||
3889 !BNXT_LED_ALT_BLINK_CAP(caps)) {
3901 int bnxt_hwrm_port_led_cfg(struct bnxt *bp, bool led_on)
3903 struct hwrm_port_led_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3904 struct hwrm_port_led_cfg_input req = {0};
3905 struct bnxt_led_cfg *led_cfg;
3906 uint8_t led_state = HWRM_PORT_LED_QCFG_OUTPUT_LED0_STATE_DEFAULT;
3907 uint16_t duration = 0;
3910 if (!bp->num_leds || BNXT_VF(bp))
3913 HWRM_PREP(&req, HWRM_PORT_LED_CFG, BNXT_USE_CHIMP_MB);
3916 led_state = HWRM_PORT_LED_CFG_INPUT_LED0_STATE_BLINKALT;
3917 duration = rte_cpu_to_le_16(500);
3919 req.port_id = bp->pf.port_id;
3920 req.num_leds = bp->num_leds;
3921 led_cfg = (struct bnxt_led_cfg *)&req.led0_id;
3922 for (i = 0; i < bp->num_leds; i++, led_cfg++) {
3923 req.enables |= BNXT_LED_DFLT_ENABLES(i);
3924 led_cfg->led_id = bp->leds[i].led_id;
3925 led_cfg->led_state = led_state;
3926 led_cfg->led_blink_on = duration;
3927 led_cfg->led_blink_off = duration;
3928 led_cfg->led_group_id = bp->leds[i].led_group_id;
3931 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3933 HWRM_CHECK_RESULT();
3939 int bnxt_hwrm_nvm_get_dir_info(struct bnxt *bp, uint32_t *entries,
3943 struct hwrm_nvm_get_dir_info_input req = {0};
3944 struct hwrm_nvm_get_dir_info_output *resp = bp->hwrm_cmd_resp_addr;
3946 HWRM_PREP(&req, HWRM_NVM_GET_DIR_INFO, BNXT_USE_CHIMP_MB);
3948 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3950 HWRM_CHECK_RESULT();
3952 *entries = rte_le_to_cpu_32(resp->entries);
3953 *length = rte_le_to_cpu_32(resp->entry_length);
3959 int bnxt_get_nvram_directory(struct bnxt *bp, uint32_t len, uint8_t *data)
3962 uint32_t dir_entries;
3963 uint32_t entry_length;
3966 rte_iova_t dma_handle;
3967 struct hwrm_nvm_get_dir_entries_input req = {0};
3968 struct hwrm_nvm_get_dir_entries_output *resp = bp->hwrm_cmd_resp_addr;
3970 rc = bnxt_hwrm_nvm_get_dir_info(bp, &dir_entries, &entry_length);
3974 *data++ = dir_entries;
3975 *data++ = entry_length;
3977 memset(data, 0xff, len);
3979 buflen = dir_entries * entry_length;
3980 buf = rte_malloc("nvm_dir", buflen, 0);
3983 dma_handle = rte_malloc_virt2iova(buf);
3984 if (dma_handle == RTE_BAD_IOVA) {
3986 "unable to map response address to physical memory\n");
3989 HWRM_PREP(&req, HWRM_NVM_GET_DIR_ENTRIES, BNXT_USE_CHIMP_MB);
3990 req.host_dest_addr = rte_cpu_to_le_64(dma_handle);
3991 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3994 memcpy(data, buf, len > buflen ? buflen : len);
3997 HWRM_CHECK_RESULT();
4003 int bnxt_hwrm_get_nvram_item(struct bnxt *bp, uint32_t index,
4004 uint32_t offset, uint32_t length,
4009 rte_iova_t dma_handle;
4010 struct hwrm_nvm_read_input req = {0};
4011 struct hwrm_nvm_read_output *resp = bp->hwrm_cmd_resp_addr;
4013 buf = rte_malloc("nvm_item", length, 0);
4017 dma_handle = rte_malloc_virt2iova(buf);
4018 if (dma_handle == RTE_BAD_IOVA) {
4020 "unable to map response address to physical memory\n");
4023 HWRM_PREP(&req, HWRM_NVM_READ, BNXT_USE_CHIMP_MB);
4024 req.host_dest_addr = rte_cpu_to_le_64(dma_handle);
4025 req.dir_idx = rte_cpu_to_le_16(index);
4026 req.offset = rte_cpu_to_le_32(offset);
4027 req.len = rte_cpu_to_le_32(length);
4028 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4030 memcpy(data, buf, length);
4033 HWRM_CHECK_RESULT();
4039 int bnxt_hwrm_erase_nvram_directory(struct bnxt *bp, uint8_t index)
4042 struct hwrm_nvm_erase_dir_entry_input req = {0};
4043 struct hwrm_nvm_erase_dir_entry_output *resp = bp->hwrm_cmd_resp_addr;
4045 HWRM_PREP(&req, HWRM_NVM_ERASE_DIR_ENTRY, BNXT_USE_CHIMP_MB);
4046 req.dir_idx = rte_cpu_to_le_16(index);
4047 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4048 HWRM_CHECK_RESULT();
4055 int bnxt_hwrm_flash_nvram(struct bnxt *bp, uint16_t dir_type,
4056 uint16_t dir_ordinal, uint16_t dir_ext,
4057 uint16_t dir_attr, const uint8_t *data,
4061 struct hwrm_nvm_write_input req = {0};
4062 struct hwrm_nvm_write_output *resp = bp->hwrm_cmd_resp_addr;
4063 rte_iova_t dma_handle;
4066 buf = rte_malloc("nvm_write", data_len, 0);
4070 dma_handle = rte_malloc_virt2iova(buf);
4071 if (dma_handle == RTE_BAD_IOVA) {
4073 "unable to map response address to physical memory\n");
4076 memcpy(buf, data, data_len);
4078 HWRM_PREP(&req, HWRM_NVM_WRITE, BNXT_USE_CHIMP_MB);
4080 req.dir_type = rte_cpu_to_le_16(dir_type);
4081 req.dir_ordinal = rte_cpu_to_le_16(dir_ordinal);
4082 req.dir_ext = rte_cpu_to_le_16(dir_ext);
4083 req.dir_attr = rte_cpu_to_le_16(dir_attr);
4084 req.dir_data_length = rte_cpu_to_le_32(data_len);
4085 req.host_src_addr = rte_cpu_to_le_64(dma_handle);
4087 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4090 HWRM_CHECK_RESULT();
4097 bnxt_vnic_count(struct bnxt_vnic_info *vnic __rte_unused, void *cbdata)
4099 uint32_t *count = cbdata;
4101 *count = *count + 1;
4104 static int bnxt_vnic_count_hwrm_stub(struct bnxt *bp __rte_unused,
4105 struct bnxt_vnic_info *vnic __rte_unused)
4110 int bnxt_vf_vnic_count(struct bnxt *bp, uint16_t vf)
4114 bnxt_hwrm_func_vf_vnic_query_and_config(bp, vf, bnxt_vnic_count,
4115 &count, bnxt_vnic_count_hwrm_stub);
4120 static int bnxt_hwrm_func_vf_vnic_query(struct bnxt *bp, uint16_t vf,
4123 struct hwrm_func_vf_vnic_ids_query_input req = {0};
4124 struct hwrm_func_vf_vnic_ids_query_output *resp =
4125 bp->hwrm_cmd_resp_addr;
4128 /* First query all VNIC ids */
4129 HWRM_PREP(&req, HWRM_FUNC_VF_VNIC_IDS_QUERY, BNXT_USE_CHIMP_MB);
4131 req.vf_id = rte_cpu_to_le_16(bp->pf.first_vf_id + vf);
4132 req.max_vnic_id_cnt = rte_cpu_to_le_32(bp->pf.total_vnics);
4133 req.vnic_id_tbl_addr = rte_cpu_to_le_64(rte_malloc_virt2iova(vnic_ids));
4135 if (req.vnic_id_tbl_addr == RTE_BAD_IOVA) {
4138 "unable to map VNIC ID table address to physical memory\n");
4141 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4142 HWRM_CHECK_RESULT();
4143 rc = rte_le_to_cpu_32(resp->vnic_id_cnt);
4151 * This function queries the VNIC IDs for a specified VF. It then calls
4152 * the vnic_cb to update the necessary field in vnic_info with cbdata.
4153 * Then it calls the hwrm_cb function to program this new vnic configuration.
4155 int bnxt_hwrm_func_vf_vnic_query_and_config(struct bnxt *bp, uint16_t vf,
4156 void (*vnic_cb)(struct bnxt_vnic_info *, void *), void *cbdata,
4157 int (*hwrm_cb)(struct bnxt *bp, struct bnxt_vnic_info *vnic))
4159 struct bnxt_vnic_info vnic;
4161 int i, num_vnic_ids;
4166 /* First query all VNIC ids */
4167 vnic_id_sz = bp->pf.total_vnics * sizeof(*vnic_ids);
4168 vnic_ids = rte_malloc("bnxt_hwrm_vf_vnic_ids_query", vnic_id_sz,
4169 RTE_CACHE_LINE_SIZE);
4170 if (vnic_ids == NULL)
4173 for (sz = 0; sz < vnic_id_sz; sz += getpagesize())
4174 rte_mem_lock_page(((char *)vnic_ids) + sz);
4176 num_vnic_ids = bnxt_hwrm_func_vf_vnic_query(bp, vf, vnic_ids);
4178 if (num_vnic_ids < 0)
4179 return num_vnic_ids;
4181 /* Retrieve VNIC, update bd_stall then update */
4183 for (i = 0; i < num_vnic_ids; i++) {
4184 memset(&vnic, 0, sizeof(struct bnxt_vnic_info));
4185 vnic.fw_vnic_id = rte_le_to_cpu_16(vnic_ids[i]);
4186 rc = bnxt_hwrm_vnic_qcfg(bp, &vnic, bp->pf.first_vf_id + vf);
4189 if (vnic.mru <= 4) /* Indicates unallocated */
4192 vnic_cb(&vnic, cbdata);
4194 rc = hwrm_cb(bp, &vnic);
4204 int bnxt_hwrm_func_cfg_vf_set_vlan_anti_spoof(struct bnxt *bp, uint16_t vf,
4207 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
4208 struct hwrm_func_cfg_input req = {0};
4211 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
4213 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
4214 req.enables |= rte_cpu_to_le_32(
4215 HWRM_FUNC_CFG_INPUT_ENABLES_VLAN_ANTISPOOF_MODE);
4216 req.vlan_antispoof_mode = on ?
4217 HWRM_FUNC_CFG_INPUT_VLAN_ANTISPOOF_MODE_VALIDATE_VLAN :
4218 HWRM_FUNC_CFG_INPUT_VLAN_ANTISPOOF_MODE_NOCHECK;
4219 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4221 HWRM_CHECK_RESULT();
4227 int bnxt_hwrm_func_qcfg_vf_dflt_vnic_id(struct bnxt *bp, int vf)
4229 struct bnxt_vnic_info vnic;
4232 int num_vnic_ids, i;
4236 vnic_id_sz = bp->pf.total_vnics * sizeof(*vnic_ids);
4237 vnic_ids = rte_malloc("bnxt_hwrm_vf_vnic_ids_query", vnic_id_sz,
4238 RTE_CACHE_LINE_SIZE);
4239 if (vnic_ids == NULL)
4242 for (sz = 0; sz < vnic_id_sz; sz += getpagesize())
4243 rte_mem_lock_page(((char *)vnic_ids) + sz);
4245 rc = bnxt_hwrm_func_vf_vnic_query(bp, vf, vnic_ids);
4251 * Loop through to find the default VNIC ID.
4252 * TODO: The easier way would be to obtain the resp->dflt_vnic_id
4253 * by sending the hwrm_func_qcfg command to the firmware.
4255 for (i = 0; i < num_vnic_ids; i++) {
4256 memset(&vnic, 0, sizeof(struct bnxt_vnic_info));
4257 vnic.fw_vnic_id = rte_le_to_cpu_16(vnic_ids[i]);
4258 rc = bnxt_hwrm_vnic_qcfg(bp, &vnic,
4259 bp->pf.first_vf_id + vf);
4262 if (vnic.func_default) {
4264 return vnic.fw_vnic_id;
4267 /* Could not find a default VNIC. */
4268 PMD_DRV_LOG(ERR, "No default VNIC\n");
4274 int bnxt_hwrm_set_em_filter(struct bnxt *bp,
4276 struct bnxt_filter_info *filter)
4279 struct hwrm_cfa_em_flow_alloc_input req = {.req_type = 0 };
4280 struct hwrm_cfa_em_flow_alloc_output *resp = bp->hwrm_cmd_resp_addr;
4281 uint32_t enables = 0;
4283 if (filter->fw_em_filter_id != UINT64_MAX)
4284 bnxt_hwrm_clear_em_filter(bp, filter);
4286 HWRM_PREP(&req, HWRM_CFA_EM_FLOW_ALLOC, BNXT_USE_KONG(bp));
4288 req.flags = rte_cpu_to_le_32(filter->flags);
4290 enables = filter->enables |
4291 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_ID;
4292 req.dst_id = rte_cpu_to_le_16(dst_id);
4294 if (filter->ip_addr_type) {
4295 req.ip_addr_type = filter->ip_addr_type;
4296 enables |= HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IPADDR_TYPE;
4299 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_L2_FILTER_ID)
4300 req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
4302 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_MACADDR)
4303 memcpy(req.src_macaddr, filter->src_macaddr,
4304 RTE_ETHER_ADDR_LEN);
4306 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_MACADDR)
4307 memcpy(req.dst_macaddr, filter->dst_macaddr,
4308 RTE_ETHER_ADDR_LEN);
4310 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_OVLAN_VID)
4311 req.ovlan_vid = filter->l2_ovlan;
4313 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IVLAN_VID)
4314 req.ivlan_vid = filter->l2_ivlan;
4316 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_ETHERTYPE)
4317 req.ethertype = rte_cpu_to_be_16(filter->ethertype);
4319 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IP_PROTOCOL)
4320 req.ip_protocol = filter->ip_protocol;
4322 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_IPADDR)
4323 req.src_ipaddr[0] = rte_cpu_to_be_32(filter->src_ipaddr[0]);
4325 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_IPADDR)
4326 req.dst_ipaddr[0] = rte_cpu_to_be_32(filter->dst_ipaddr[0]);
4328 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_PORT)
4329 req.src_port = rte_cpu_to_be_16(filter->src_port);
4331 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_PORT)
4332 req.dst_port = rte_cpu_to_be_16(filter->dst_port);
4334 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_MIRROR_VNIC_ID)
4335 req.mirror_vnic_id = filter->mirror_vnic_id;
4337 req.enables = rte_cpu_to_le_32(enables);
4339 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
4341 HWRM_CHECK_RESULT();
4343 filter->fw_em_filter_id = rte_le_to_cpu_64(resp->em_filter_id);
4349 int bnxt_hwrm_clear_em_filter(struct bnxt *bp, struct bnxt_filter_info *filter)
4352 struct hwrm_cfa_em_flow_free_input req = {.req_type = 0 };
4353 struct hwrm_cfa_em_flow_free_output *resp = bp->hwrm_cmd_resp_addr;
4355 if (filter->fw_em_filter_id == UINT64_MAX)
4358 HWRM_PREP(&req, HWRM_CFA_EM_FLOW_FREE, BNXT_USE_KONG(bp));
4360 req.em_filter_id = rte_cpu_to_le_64(filter->fw_em_filter_id);
4362 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
4364 HWRM_CHECK_RESULT();
4367 filter->fw_em_filter_id = UINT64_MAX;
4368 filter->fw_l2_filter_id = UINT64_MAX;
4373 int bnxt_hwrm_set_ntuple_filter(struct bnxt *bp,
4375 struct bnxt_filter_info *filter)
4378 struct hwrm_cfa_ntuple_filter_alloc_input req = {.req_type = 0 };
4379 struct hwrm_cfa_ntuple_filter_alloc_output *resp =
4380 bp->hwrm_cmd_resp_addr;
4381 uint32_t enables = 0;
4383 if (filter->fw_ntuple_filter_id != UINT64_MAX)
4384 bnxt_hwrm_clear_ntuple_filter(bp, filter);
4386 HWRM_PREP(&req, HWRM_CFA_NTUPLE_FILTER_ALLOC, BNXT_USE_CHIMP_MB);
4388 req.flags = rte_cpu_to_le_32(filter->flags);
4390 enables = filter->enables |
4391 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_ID;
4392 req.dst_id = rte_cpu_to_le_16(dst_id);
4394 if (filter->ip_addr_type) {
4395 req.ip_addr_type = filter->ip_addr_type;
4397 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_IPADDR_TYPE;
4400 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_L2_FILTER_ID)
4401 req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
4403 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_MACADDR)
4404 memcpy(req.src_macaddr, filter->src_macaddr,
4405 RTE_ETHER_ADDR_LEN);
4407 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_ETHERTYPE)
4408 req.ethertype = rte_cpu_to_be_16(filter->ethertype);
4410 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_IP_PROTOCOL)
4411 req.ip_protocol = filter->ip_protocol;
4413 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_IPADDR)
4414 req.src_ipaddr[0] = rte_cpu_to_le_32(filter->src_ipaddr[0]);
4416 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_IPADDR_MASK)
4417 req.src_ipaddr_mask[0] =
4418 rte_cpu_to_le_32(filter->src_ipaddr_mask[0]);
4420 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_IPADDR)
4421 req.dst_ipaddr[0] = rte_cpu_to_le_32(filter->dst_ipaddr[0]);
4423 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_IPADDR_MASK)
4424 req.dst_ipaddr_mask[0] =
4425 rte_cpu_to_be_32(filter->dst_ipaddr_mask[0]);
4427 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_PORT)
4428 req.src_port = rte_cpu_to_le_16(filter->src_port);
4430 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_PORT_MASK)
4431 req.src_port_mask = rte_cpu_to_le_16(filter->src_port_mask);
4433 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_PORT)
4434 req.dst_port = rte_cpu_to_le_16(filter->dst_port);
4436 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_PORT_MASK)
4437 req.dst_port_mask = rte_cpu_to_le_16(filter->dst_port_mask);
4439 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_MIRROR_VNIC_ID)
4440 req.mirror_vnic_id = filter->mirror_vnic_id;
4442 req.enables = rte_cpu_to_le_32(enables);
4444 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4446 HWRM_CHECK_RESULT();
4448 filter->fw_ntuple_filter_id = rte_le_to_cpu_64(resp->ntuple_filter_id);
4449 filter->flow_id = rte_le_to_cpu_32(resp->flow_id);
4455 int bnxt_hwrm_clear_ntuple_filter(struct bnxt *bp,
4456 struct bnxt_filter_info *filter)
4459 struct hwrm_cfa_ntuple_filter_free_input req = {.req_type = 0 };
4460 struct hwrm_cfa_ntuple_filter_free_output *resp =
4461 bp->hwrm_cmd_resp_addr;
4463 if (filter->fw_ntuple_filter_id == UINT64_MAX)
4466 HWRM_PREP(&req, HWRM_CFA_NTUPLE_FILTER_FREE, BNXT_USE_CHIMP_MB);
4468 req.ntuple_filter_id = rte_cpu_to_le_64(filter->fw_ntuple_filter_id);
4470 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4472 HWRM_CHECK_RESULT();
4475 filter->fw_ntuple_filter_id = UINT64_MAX;
4481 bnxt_vnic_rss_configure_thor(struct bnxt *bp, struct bnxt_vnic_info *vnic)
4483 struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
4484 uint8_t *rx_queue_state = bp->eth_dev->data->rx_queue_state;
4485 struct hwrm_vnic_rss_cfg_input req = {.req_type = 0 };
4486 struct bnxt_rx_queue **rxqs = bp->rx_queues;
4487 uint16_t *ring_tbl = vnic->rss_table;
4488 int nr_ctxs = vnic->num_lb_ctxts;
4489 int max_rings = bp->rx_nr_rings;
4493 for (i = 0, k = 0; i < nr_ctxs; i++) {
4494 struct bnxt_rx_ring_info *rxr;
4495 struct bnxt_cp_ring_info *cpr;
4497 HWRM_PREP(&req, HWRM_VNIC_RSS_CFG, BNXT_USE_CHIMP_MB);
4499 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
4500 req.hash_type = rte_cpu_to_le_32(vnic->hash_type);
4501 req.hash_mode_flags = vnic->hash_mode;
4503 req.ring_grp_tbl_addr =
4504 rte_cpu_to_le_64(vnic->rss_table_dma_addr +
4505 i * BNXT_RSS_ENTRIES_PER_CTX_THOR *
4506 2 * sizeof(*ring_tbl));
4507 req.hash_key_tbl_addr =
4508 rte_cpu_to_le_64(vnic->rss_hash_key_dma_addr);
4510 req.ring_table_pair_index = i;
4511 req.rss_ctx_idx = rte_cpu_to_le_16(vnic->fw_grp_ids[i]);
4513 for (j = 0; j < 64; j++) {
4516 /* Find next active ring. */
4517 for (cnt = 0; cnt < max_rings; cnt++) {
4518 if (rx_queue_state[k] !=
4519 RTE_ETH_QUEUE_STATE_STOPPED)
4521 if (++k == max_rings)
4525 /* Return if no rings are active. */
4526 if (cnt == max_rings) {
4531 /* Add rx/cp ring pair to RSS table. */
4532 rxr = rxqs[k]->rx_ring;
4533 cpr = rxqs[k]->cp_ring;
4535 ring_id = rxr->rx_ring_struct->fw_ring_id;
4536 *ring_tbl++ = rte_cpu_to_le_16(ring_id);
4537 ring_id = cpr->cp_ring_struct->fw_ring_id;
4538 *ring_tbl++ = rte_cpu_to_le_16(ring_id);
4540 if (++k == max_rings)
4543 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req),
4546 HWRM_CHECK_RESULT();
4553 int bnxt_vnic_rss_configure(struct bnxt *bp, struct bnxt_vnic_info *vnic)
4555 unsigned int rss_idx, fw_idx, i;
4557 if (!(vnic->rss_table && vnic->hash_type))
4560 if (BNXT_CHIP_THOR(bp))
4561 return bnxt_vnic_rss_configure_thor(bp, vnic);
4563 if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
4566 if (vnic->rss_table && vnic->hash_type) {
4568 * Fill the RSS hash & redirection table with
4569 * ring group ids for all VNICs
4571 for (rss_idx = 0, fw_idx = 0; rss_idx < HW_HASH_INDEX_SIZE;
4572 rss_idx++, fw_idx++) {
4573 for (i = 0; i < bp->rx_cp_nr_rings; i++) {
4574 fw_idx %= bp->rx_cp_nr_rings;
4575 if (vnic->fw_grp_ids[fw_idx] !=
4580 if (i == bp->rx_cp_nr_rings)
4582 vnic->rss_table[rss_idx] = vnic->fw_grp_ids[fw_idx];
4584 return bnxt_hwrm_vnic_rss_cfg(bp, vnic);
4590 static void bnxt_hwrm_set_coal_params(struct bnxt_coal *hw_coal,
4591 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *req)
4595 req->num_cmpl_aggr_int = rte_cpu_to_le_16(hw_coal->num_cmpl_aggr_int);
4597 /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
4598 req->num_cmpl_dma_aggr = rte_cpu_to_le_16(hw_coal->num_cmpl_dma_aggr);
4600 /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
4601 req->num_cmpl_dma_aggr_during_int =
4602 rte_cpu_to_le_16(hw_coal->num_cmpl_dma_aggr_during_int);
4604 req->int_lat_tmr_max = rte_cpu_to_le_16(hw_coal->int_lat_tmr_max);
4606 /* min timer set to 1/2 of interrupt timer */
4607 req->int_lat_tmr_min = rte_cpu_to_le_16(hw_coal->int_lat_tmr_min);
4609 /* buf timer set to 1/4 of interrupt timer */
4610 req->cmpl_aggr_dma_tmr = rte_cpu_to_le_16(hw_coal->cmpl_aggr_dma_tmr);
4612 req->cmpl_aggr_dma_tmr_during_int =
4613 rte_cpu_to_le_16(hw_coal->cmpl_aggr_dma_tmr_during_int);
4615 flags = HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_TIMER_RESET |
4616 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_RING_IDLE;
4617 req->flags = rte_cpu_to_le_16(flags);
4620 static int bnxt_hwrm_set_coal_params_thor(struct bnxt *bp,
4621 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *agg_req)
4623 struct hwrm_ring_aggint_qcaps_input req = {0};
4624 struct hwrm_ring_aggint_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
4629 HWRM_PREP(&req, HWRM_RING_AGGINT_QCAPS, BNXT_USE_CHIMP_MB);
4630 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4631 HWRM_CHECK_RESULT();
4633 agg_req->num_cmpl_dma_aggr = resp->num_cmpl_dma_aggr_max;
4634 agg_req->cmpl_aggr_dma_tmr = resp->cmpl_aggr_dma_tmr_min;
4636 flags = HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_TIMER_RESET |
4637 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_RING_IDLE;
4638 agg_req->flags = rte_cpu_to_le_16(flags);
4640 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_ENABLES_CMPL_AGGR_DMA_TMR |
4641 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_ENABLES_NUM_CMPL_DMA_AGGR;
4642 agg_req->enables = rte_cpu_to_le_32(enables);
4648 int bnxt_hwrm_set_ring_coal(struct bnxt *bp,
4649 struct bnxt_coal *coal, uint16_t ring_id)
4651 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req = {0};
4652 struct hwrm_ring_cmpl_ring_cfg_aggint_params_output *resp =
4653 bp->hwrm_cmd_resp_addr;
4656 /* Set ring coalesce parameters only for 100G NICs */
4657 if (BNXT_CHIP_THOR(bp)) {
4658 if (bnxt_hwrm_set_coal_params_thor(bp, &req))
4660 } else if (bnxt_stratus_device(bp)) {
4661 bnxt_hwrm_set_coal_params(coal, &req);
4667 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS,
4669 req.ring_id = rte_cpu_to_le_16(ring_id);
4670 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4671 HWRM_CHECK_RESULT();
4676 #define BNXT_RTE_MEMZONE_FLAG (RTE_MEMZONE_1GB | RTE_MEMZONE_IOVA_CONTIG)
4677 int bnxt_hwrm_func_backing_store_qcaps(struct bnxt *bp)
4679 struct hwrm_func_backing_store_qcaps_input req = {0};
4680 struct hwrm_func_backing_store_qcaps_output *resp =
4681 bp->hwrm_cmd_resp_addr;
4682 struct bnxt_ctx_pg_info *ctx_pg;
4683 struct bnxt_ctx_mem_info *ctx;
4684 int total_alloc_len;
4687 if (!BNXT_CHIP_THOR(bp) ||
4688 bp->hwrm_spec_code < HWRM_VERSION_1_9_2 ||
4693 HWRM_PREP(&req, HWRM_FUNC_BACKING_STORE_QCAPS, BNXT_USE_CHIMP_MB);
4694 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4695 HWRM_CHECK_RESULT_SILENT();
4697 total_alloc_len = sizeof(*ctx);
4698 ctx = rte_zmalloc("bnxt_ctx_mem", total_alloc_len,
4699 RTE_CACHE_LINE_SIZE);
4705 ctx_pg = rte_malloc("bnxt_ctx_pg_mem",
4706 sizeof(*ctx_pg) * BNXT_MAX_Q,
4707 RTE_CACHE_LINE_SIZE);
4712 for (i = 0; i < BNXT_MAX_Q; i++, ctx_pg++)
4713 ctx->tqm_mem[i] = ctx_pg;
4716 ctx->qp_max_entries = rte_le_to_cpu_32(resp->qp_max_entries);
4717 ctx->qp_min_qp1_entries =
4718 rte_le_to_cpu_16(resp->qp_min_qp1_entries);
4719 ctx->qp_max_l2_entries =
4720 rte_le_to_cpu_16(resp->qp_max_l2_entries);
4721 ctx->qp_entry_size = rte_le_to_cpu_16(resp->qp_entry_size);
4722 ctx->srq_max_l2_entries =
4723 rte_le_to_cpu_16(resp->srq_max_l2_entries);
4724 ctx->srq_max_entries = rte_le_to_cpu_32(resp->srq_max_entries);
4725 ctx->srq_entry_size = rte_le_to_cpu_16(resp->srq_entry_size);
4726 ctx->cq_max_l2_entries =
4727 rte_le_to_cpu_16(resp->cq_max_l2_entries);
4728 ctx->cq_max_entries = rte_le_to_cpu_32(resp->cq_max_entries);
4729 ctx->cq_entry_size = rte_le_to_cpu_16(resp->cq_entry_size);
4730 ctx->vnic_max_vnic_entries =
4731 rte_le_to_cpu_16(resp->vnic_max_vnic_entries);
4732 ctx->vnic_max_ring_table_entries =
4733 rte_le_to_cpu_16(resp->vnic_max_ring_table_entries);
4734 ctx->vnic_entry_size = rte_le_to_cpu_16(resp->vnic_entry_size);
4735 ctx->stat_max_entries =
4736 rte_le_to_cpu_32(resp->stat_max_entries);
4737 ctx->stat_entry_size = rte_le_to_cpu_16(resp->stat_entry_size);
4738 ctx->tqm_entry_size = rte_le_to_cpu_16(resp->tqm_entry_size);
4739 ctx->tqm_min_entries_per_ring =
4740 rte_le_to_cpu_32(resp->tqm_min_entries_per_ring);
4741 ctx->tqm_max_entries_per_ring =
4742 rte_le_to_cpu_32(resp->tqm_max_entries_per_ring);
4743 ctx->tqm_entries_multiple = resp->tqm_entries_multiple;
4744 if (!ctx->tqm_entries_multiple)
4745 ctx->tqm_entries_multiple = 1;
4746 ctx->mrav_max_entries =
4747 rte_le_to_cpu_32(resp->mrav_max_entries);
4748 ctx->mrav_entry_size = rte_le_to_cpu_16(resp->mrav_entry_size);
4749 ctx->tim_entry_size = rte_le_to_cpu_16(resp->tim_entry_size);
4750 ctx->tim_max_entries = rte_le_to_cpu_32(resp->tim_max_entries);
4756 int bnxt_hwrm_func_backing_store_cfg(struct bnxt *bp, uint32_t enables)
4758 struct hwrm_func_backing_store_cfg_input req = {0};
4759 struct hwrm_func_backing_store_cfg_output *resp =
4760 bp->hwrm_cmd_resp_addr;
4761 struct bnxt_ctx_mem_info *ctx = bp->ctx;
4762 struct bnxt_ctx_pg_info *ctx_pg;
4763 uint32_t *num_entries;
4772 HWRM_PREP(&req, HWRM_FUNC_BACKING_STORE_CFG, BNXT_USE_CHIMP_MB);
4773 req.enables = rte_cpu_to_le_32(enables);
4775 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_QP) {
4776 ctx_pg = &ctx->qp_mem;
4777 req.qp_num_entries = rte_cpu_to_le_32(ctx_pg->entries);
4778 req.qp_num_qp1_entries =
4779 rte_cpu_to_le_16(ctx->qp_min_qp1_entries);
4780 req.qp_num_l2_entries =
4781 rte_cpu_to_le_16(ctx->qp_max_l2_entries);
4782 req.qp_entry_size = rte_cpu_to_le_16(ctx->qp_entry_size);
4783 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4784 &req.qpc_pg_size_qpc_lvl,
4788 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_SRQ) {
4789 ctx_pg = &ctx->srq_mem;
4790 req.srq_num_entries = rte_cpu_to_le_32(ctx_pg->entries);
4791 req.srq_num_l2_entries =
4792 rte_cpu_to_le_16(ctx->srq_max_l2_entries);
4793 req.srq_entry_size = rte_cpu_to_le_16(ctx->srq_entry_size);
4794 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4795 &req.srq_pg_size_srq_lvl,
4799 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_CQ) {
4800 ctx_pg = &ctx->cq_mem;
4801 req.cq_num_entries = rte_cpu_to_le_32(ctx_pg->entries);
4802 req.cq_num_l2_entries =
4803 rte_cpu_to_le_16(ctx->cq_max_l2_entries);
4804 req.cq_entry_size = rte_cpu_to_le_16(ctx->cq_entry_size);
4805 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4806 &req.cq_pg_size_cq_lvl,
4810 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_VNIC) {
4811 ctx_pg = &ctx->vnic_mem;
4812 req.vnic_num_vnic_entries =
4813 rte_cpu_to_le_16(ctx->vnic_max_vnic_entries);
4814 req.vnic_num_ring_table_entries =
4815 rte_cpu_to_le_16(ctx->vnic_max_ring_table_entries);
4816 req.vnic_entry_size = rte_cpu_to_le_16(ctx->vnic_entry_size);
4817 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4818 &req.vnic_pg_size_vnic_lvl,
4819 &req.vnic_page_dir);
4822 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_STAT) {
4823 ctx_pg = &ctx->stat_mem;
4824 req.stat_num_entries = rte_cpu_to_le_16(ctx->stat_max_entries);
4825 req.stat_entry_size = rte_cpu_to_le_16(ctx->stat_entry_size);
4826 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4827 &req.stat_pg_size_stat_lvl,
4828 &req.stat_page_dir);
4831 req.tqm_entry_size = rte_cpu_to_le_16(ctx->tqm_entry_size);
4832 num_entries = &req.tqm_sp_num_entries;
4833 pg_attr = &req.tqm_sp_pg_size_tqm_sp_lvl;
4834 pg_dir = &req.tqm_sp_page_dir;
4835 ena = HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_TQM_SP;
4836 for (i = 0; i < 9; i++, num_entries++, pg_attr++, pg_dir++, ena <<= 1) {
4837 if (!(enables & ena))
4840 req.tqm_entry_size = rte_cpu_to_le_16(ctx->tqm_entry_size);
4842 ctx_pg = ctx->tqm_mem[i];
4843 *num_entries = rte_cpu_to_le_16(ctx_pg->entries);
4844 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem, pg_attr, pg_dir);
4847 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4848 HWRM_CHECK_RESULT();
4854 int bnxt_hwrm_ext_port_qstats(struct bnxt *bp)
4856 struct hwrm_port_qstats_ext_input req = {0};
4857 struct hwrm_port_qstats_ext_output *resp = bp->hwrm_cmd_resp_addr;
4858 struct bnxt_pf_info *pf = &bp->pf;
4861 if (!(bp->flags & BNXT_FLAG_EXT_RX_PORT_STATS ||
4862 bp->flags & BNXT_FLAG_EXT_TX_PORT_STATS))
4865 HWRM_PREP(&req, HWRM_PORT_QSTATS_EXT, BNXT_USE_CHIMP_MB);
4867 req.port_id = rte_cpu_to_le_16(pf->port_id);
4868 if (bp->flags & BNXT_FLAG_EXT_TX_PORT_STATS) {
4869 req.tx_stat_host_addr =
4870 rte_cpu_to_le_64(bp->hw_tx_port_stats_ext_map);
4872 rte_cpu_to_le_16(sizeof(struct tx_port_stats_ext));
4874 if (bp->flags & BNXT_FLAG_EXT_RX_PORT_STATS) {
4875 req.rx_stat_host_addr =
4876 rte_cpu_to_le_64(bp->hw_rx_port_stats_ext_map);
4878 rte_cpu_to_le_16(sizeof(struct rx_port_stats_ext));
4880 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4883 bp->fw_rx_port_stats_ext_size = 0;
4884 bp->fw_tx_port_stats_ext_size = 0;
4886 bp->fw_rx_port_stats_ext_size =
4887 rte_le_to_cpu_16(resp->rx_stat_size);
4888 bp->fw_tx_port_stats_ext_size =
4889 rte_le_to_cpu_16(resp->tx_stat_size);
4892 HWRM_CHECK_RESULT();
4899 bnxt_hwrm_tunnel_redirect(struct bnxt *bp, uint8_t type)
4901 struct hwrm_cfa_redirect_tunnel_type_alloc_input req = {0};
4902 struct hwrm_cfa_redirect_tunnel_type_alloc_output *resp =
4903 bp->hwrm_cmd_resp_addr;
4906 HWRM_PREP(&req, HWRM_CFA_REDIRECT_TUNNEL_TYPE_ALLOC, BNXT_USE_CHIMP_MB);
4907 req.tunnel_type = type;
4908 req.dest_fid = bp->fw_fid;
4909 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4910 HWRM_CHECK_RESULT();
4918 bnxt_hwrm_tunnel_redirect_free(struct bnxt *bp, uint8_t type)
4920 struct hwrm_cfa_redirect_tunnel_type_free_input req = {0};
4921 struct hwrm_cfa_redirect_tunnel_type_free_output *resp =
4922 bp->hwrm_cmd_resp_addr;
4925 HWRM_PREP(&req, HWRM_CFA_REDIRECT_TUNNEL_TYPE_FREE, BNXT_USE_CHIMP_MB);
4926 req.tunnel_type = type;
4927 req.dest_fid = bp->fw_fid;
4928 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4929 HWRM_CHECK_RESULT();
4936 int bnxt_hwrm_tunnel_redirect_query(struct bnxt *bp, uint32_t *type)
4938 struct hwrm_cfa_redirect_query_tunnel_type_input req = {0};
4939 struct hwrm_cfa_redirect_query_tunnel_type_output *resp =
4940 bp->hwrm_cmd_resp_addr;
4943 HWRM_PREP(&req, HWRM_CFA_REDIRECT_QUERY_TUNNEL_TYPE, BNXT_USE_CHIMP_MB);
4944 req.src_fid = bp->fw_fid;
4945 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4946 HWRM_CHECK_RESULT();
4949 *type = rte_le_to_cpu_32(resp->tunnel_mask);
4956 int bnxt_hwrm_tunnel_redirect_info(struct bnxt *bp, uint8_t tun_type,
4959 struct hwrm_cfa_redirect_tunnel_type_info_input req = {0};
4960 struct hwrm_cfa_redirect_tunnel_type_info_output *resp =
4961 bp->hwrm_cmd_resp_addr;
4964 HWRM_PREP(&req, HWRM_CFA_REDIRECT_TUNNEL_TYPE_INFO, BNXT_USE_CHIMP_MB);
4965 req.src_fid = bp->fw_fid;
4966 req.tunnel_type = tun_type;
4967 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4968 HWRM_CHECK_RESULT();
4971 *dst_fid = rte_le_to_cpu_16(resp->dest_fid);
4973 PMD_DRV_LOG(DEBUG, "dst_fid: %x\n", resp->dest_fid);
4980 int bnxt_hwrm_set_mac(struct bnxt *bp)
4982 struct hwrm_func_vf_cfg_output *resp = bp->hwrm_cmd_resp_addr;
4983 struct hwrm_func_vf_cfg_input req = {0};
4989 HWRM_PREP(&req, HWRM_FUNC_VF_CFG, BNXT_USE_CHIMP_MB);
4992 rte_cpu_to_le_32(HWRM_FUNC_VF_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
4993 memcpy(req.dflt_mac_addr, bp->mac_addr, RTE_ETHER_ADDR_LEN);
4995 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4997 HWRM_CHECK_RESULT();
4999 memcpy(bp->dflt_mac_addr, bp->mac_addr, RTE_ETHER_ADDR_LEN);
5005 int bnxt_hwrm_if_change(struct bnxt *bp, bool up)
5007 struct hwrm_func_drv_if_change_output *resp = bp->hwrm_cmd_resp_addr;
5008 struct hwrm_func_drv_if_change_input req = {0};
5012 if (!(bp->fw_cap & BNXT_FW_CAP_IF_CHANGE))
5015 /* Do not issue FUNC_DRV_IF_CHANGE during reset recovery.
5016 * If we issue FUNC_DRV_IF_CHANGE with flags down before
5017 * FUNC_DRV_UNRGTR, FW resets before FUNC_DRV_UNRGTR
5019 if (!up && (bp->flags & BNXT_FLAG_FW_RESET))
5022 HWRM_PREP(&req, HWRM_FUNC_DRV_IF_CHANGE, BNXT_USE_CHIMP_MB);
5026 rte_cpu_to_le_32(HWRM_FUNC_DRV_IF_CHANGE_INPUT_FLAGS_UP);
5028 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5030 HWRM_CHECK_RESULT();
5031 flags = rte_le_to_cpu_32(resp->flags);
5037 if (flags & HWRM_FUNC_DRV_IF_CHANGE_OUTPUT_FLAGS_HOT_FW_RESET_DONE) {
5038 PMD_DRV_LOG(INFO, "FW reset happened while port was down\n");
5039 bp->flags |= BNXT_FLAG_IF_CHANGE_HOT_FW_RESET_DONE;
5045 int bnxt_hwrm_error_recovery_qcfg(struct bnxt *bp)
5047 struct hwrm_error_recovery_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
5048 struct bnxt_error_recovery_info *info = bp->recovery_info;
5049 struct hwrm_error_recovery_qcfg_input req = {0};
5054 /* Older FW does not have error recovery support */
5055 if (!(bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY))
5059 info = rte_zmalloc("bnxt_hwrm_error_recovery_qcfg",
5061 bp->recovery_info = info;
5065 memset(info, 0, sizeof(*info));
5068 HWRM_PREP(&req, HWRM_ERROR_RECOVERY_QCFG, BNXT_USE_CHIMP_MB);
5070 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5072 HWRM_CHECK_RESULT();
5074 flags = rte_le_to_cpu_32(resp->flags);
5075 if (flags & HWRM_ERROR_RECOVERY_QCFG_OUTPUT_FLAGS_HOST)
5076 info->flags |= BNXT_FLAG_ERROR_RECOVERY_HOST;
5077 else if (flags & HWRM_ERROR_RECOVERY_QCFG_OUTPUT_FLAGS_CO_CPU)
5078 info->flags |= BNXT_FLAG_ERROR_RECOVERY_CO_CPU;
5080 if ((info->flags & BNXT_FLAG_ERROR_RECOVERY_CO_CPU) &&
5081 !(bp->flags & BNXT_FLAG_KONG_MB_EN)) {
5086 /* FW returned values are in units of 100msec */
5087 info->driver_polling_freq =
5088 rte_le_to_cpu_32(resp->driver_polling_freq) * 100;
5089 info->master_func_wait_period =
5090 rte_le_to_cpu_32(resp->master_func_wait_period) * 100;
5091 info->normal_func_wait_period =
5092 rte_le_to_cpu_32(resp->normal_func_wait_period) * 100;
5093 info->master_func_wait_period_after_reset =
5094 rte_le_to_cpu_32(resp->master_func_wait_period_after_reset) * 100;
5095 info->max_bailout_time_after_reset =
5096 rte_le_to_cpu_32(resp->max_bailout_time_after_reset) * 100;
5097 info->status_regs[BNXT_FW_STATUS_REG] =
5098 rte_le_to_cpu_32(resp->fw_health_status_reg);
5099 info->status_regs[BNXT_FW_HEARTBEAT_CNT_REG] =
5100 rte_le_to_cpu_32(resp->fw_heartbeat_reg);
5101 info->status_regs[BNXT_FW_RECOVERY_CNT_REG] =
5102 rte_le_to_cpu_32(resp->fw_reset_cnt_reg);
5103 info->status_regs[BNXT_FW_RESET_INPROG_REG] =
5104 rte_le_to_cpu_32(resp->reset_inprogress_reg);
5105 info->reg_array_cnt =
5106 rte_le_to_cpu_32(resp->reg_array_cnt);
5108 if (info->reg_array_cnt >= BNXT_NUM_RESET_REG) {
5113 for (i = 0; i < info->reg_array_cnt; i++) {
5114 info->reset_reg[i] =
5115 rte_le_to_cpu_32(resp->reset_reg[i]);
5116 info->reset_reg_val[i] =
5117 rte_le_to_cpu_32(resp->reset_reg_val[i]);
5118 info->delay_after_reset[i] =
5119 resp->delay_after_reset[i];
5124 /* Map the FW status registers */
5126 rc = bnxt_map_fw_health_status_regs(bp);
5129 rte_free(bp->recovery_info);
5130 bp->recovery_info = NULL;
5135 int bnxt_hwrm_fw_reset(struct bnxt *bp)
5137 struct hwrm_fw_reset_output *resp = bp->hwrm_cmd_resp_addr;
5138 struct hwrm_fw_reset_input req = {0};
5144 HWRM_PREP(&req, HWRM_FW_RESET, BNXT_USE_KONG(bp));
5146 req.embedded_proc_type =
5147 HWRM_FW_RESET_INPUT_EMBEDDED_PROC_TYPE_CHIP;
5148 req.selfrst_status =
5149 HWRM_FW_RESET_INPUT_SELFRST_STATUS_SELFRSTASAP;
5150 req.flags = HWRM_FW_RESET_INPUT_FLAGS_RESET_GRACEFUL;
5152 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req),
5155 HWRM_CHECK_RESULT();
5161 int bnxt_hwrm_port_ts_query(struct bnxt *bp, uint8_t path, uint64_t *timestamp)
5163 struct hwrm_port_ts_query_output *resp = bp->hwrm_cmd_resp_addr;
5164 struct hwrm_port_ts_query_input req = {0};
5165 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
5172 HWRM_PREP(&req, HWRM_PORT_TS_QUERY, BNXT_USE_CHIMP_MB);
5175 case BNXT_PTP_FLAGS_PATH_TX:
5176 flags |= HWRM_PORT_TS_QUERY_INPUT_FLAGS_PATH_TX;
5178 case BNXT_PTP_FLAGS_PATH_RX:
5179 flags |= HWRM_PORT_TS_QUERY_INPUT_FLAGS_PATH_RX;
5181 case BNXT_PTP_FLAGS_CURRENT_TIME:
5182 flags |= HWRM_PORT_TS_QUERY_INPUT_FLAGS_CURRENT_TIME;
5186 req.flags = rte_cpu_to_le_32(flags);
5187 req.port_id = rte_cpu_to_le_16(bp->pf.port_id);
5189 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5191 HWRM_CHECK_RESULT();
5194 *timestamp = rte_le_to_cpu_32(resp->ptp_msg_ts[0]);
5196 (uint64_t)(rte_le_to_cpu_32(resp->ptp_msg_ts[1])) << 32;
5203 int bnxt_hwrm_cfa_adv_flow_mgmt_qcaps(struct bnxt *bp)
5205 struct hwrm_cfa_adv_flow_mgnt_qcaps_output *resp =
5206 bp->hwrm_cmd_resp_addr;
5207 struct hwrm_cfa_adv_flow_mgnt_qcaps_input req = {0};
5211 if (!(bp->flags & BNXT_FLAG_ADV_FLOW_MGMT))
5214 if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp))) {
5216 "Not a PF or trusted VF. Command not supported\n");
5220 HWRM_PREP(&req, HWRM_CFA_ADV_FLOW_MGNT_QCAPS, BNXT_USE_KONG(bp));
5221 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
5223 HWRM_CHECK_RESULT();
5224 flags = rte_le_to_cpu_32(resp->flags);
5227 if (flags & HWRM_CFA_ADV_FLOW_MGNT_QCAPS_L2_HDR_SRC_FILTER_EN) {
5228 bp->flow_flags |= BNXT_FLOW_FLAG_L2_HDR_SRC_FILTER_EN;
5229 PMD_DRV_LOG(INFO, "Source L2 header filtering enabled\n");