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)
168 "Error(timeout) sending msg 0x%04x, seq_id %d\n",
169 req->req_type, req->seq_id);
176 * HWRM_PREP() should be used to prepare *ALL* HWRM commands. It grabs the
177 * spinlock, and does initial processing.
179 * HWRM_CHECK_RESULT() returns errors on failure and may not be used. It
180 * releases the spinlock only if it returns. If the regular int return codes
181 * are not used by the function, HWRM_CHECK_RESULT() should not be used
182 * directly, rather it should be copied and modified to suit the function.
184 * HWRM_UNLOCK() must be called after all response processing is completed.
186 #define HWRM_PREP(req, type, kong) do { \
187 rte_spinlock_lock(&bp->hwrm_lock); \
188 if (bp->hwrm_cmd_resp_addr == NULL) { \
189 rte_spinlock_unlock(&bp->hwrm_lock); \
192 memset(bp->hwrm_cmd_resp_addr, 0, bp->max_resp_len); \
193 (req)->req_type = rte_cpu_to_le_16(type); \
194 (req)->cmpl_ring = rte_cpu_to_le_16(-1); \
195 (req)->seq_id = kong ? rte_cpu_to_le_16(bp->kong_cmd_seq++) :\
196 rte_cpu_to_le_16(bp->chimp_cmd_seq++); \
197 (req)->target_id = rte_cpu_to_le_16(0xffff); \
198 (req)->resp_addr = rte_cpu_to_le_64(bp->hwrm_cmd_resp_dma_addr); \
201 #define HWRM_CHECK_RESULT_SILENT() do {\
203 rte_spinlock_unlock(&bp->hwrm_lock); \
206 if (resp->error_code) { \
207 rc = rte_le_to_cpu_16(resp->error_code); \
208 rte_spinlock_unlock(&bp->hwrm_lock); \
213 #define HWRM_CHECK_RESULT() do {\
215 PMD_DRV_LOG(ERR, "failed rc:%d\n", rc); \
216 rte_spinlock_unlock(&bp->hwrm_lock); \
217 if (rc == HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED) \
219 else if (rc == HWRM_ERR_CODE_RESOURCE_ALLOC_ERROR) \
221 else if (rc == HWRM_ERR_CODE_INVALID_PARAMS) \
223 else if (rc == HWRM_ERR_CODE_CMD_NOT_SUPPORTED) \
225 else if (rc == HWRM_ERR_CODE_HOT_RESET_PROGRESS) \
231 if (resp->error_code) { \
232 rc = rte_le_to_cpu_16(resp->error_code); \
233 if (resp->resp_len >= 16) { \
234 struct hwrm_err_output *tmp_hwrm_err_op = \
237 "error %d:%d:%08x:%04x\n", \
238 rc, tmp_hwrm_err_op->cmd_err, \
240 tmp_hwrm_err_op->opaque_0), \
242 tmp_hwrm_err_op->opaque_1)); \
244 PMD_DRV_LOG(ERR, "error %d\n", rc); \
246 rte_spinlock_unlock(&bp->hwrm_lock); \
247 if (rc == HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED) \
249 else if (rc == HWRM_ERR_CODE_RESOURCE_ALLOC_ERROR) \
251 else if (rc == HWRM_ERR_CODE_INVALID_PARAMS) \
253 else if (rc == HWRM_ERR_CODE_CMD_NOT_SUPPORTED) \
255 else if (rc == HWRM_ERR_CODE_HOT_RESET_PROGRESS) \
263 #define HWRM_UNLOCK() rte_spinlock_unlock(&bp->hwrm_lock)
265 int bnxt_hwrm_tf_message_direct(struct bnxt *bp,
274 bool mailbox = BNXT_USE_CHIMP_MB;
275 struct input *req = msg;
276 struct output *resp = bp->hwrm_cmd_resp_addr;
279 mailbox = BNXT_USE_KONG(bp);
281 HWRM_PREP(req, msg_type, mailbox);
283 rc = bnxt_hwrm_send_message(bp, req, msg_len, mailbox);
288 memcpy(resp_msg, resp, resp_len);
295 int bnxt_hwrm_tf_message_tunneled(struct bnxt *bp,
299 uint32_t *tf_response_code,
303 uint32_t response_len)
306 struct hwrm_cfa_tflib_input req = { .req_type = 0 };
307 struct hwrm_cfa_tflib_output *resp = bp->hwrm_cmd_resp_addr;
308 bool mailbox = BNXT_USE_CHIMP_MB;
310 if (msg_len > sizeof(req.tf_req))
314 mailbox = BNXT_USE_KONG(bp);
316 HWRM_PREP(&req, HWRM_TF, mailbox);
317 /* Build request using the user supplied request payload.
318 * TLV request size is checked at build time against HWRM
319 * request max size, thus no checking required.
321 req.tf_type = tf_type;
322 req.tf_subtype = tf_subtype;
323 memcpy(req.tf_req, msg, msg_len);
325 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), mailbox);
328 /* Copy the resp to user provided response buffer */
329 if (response != NULL)
330 /* Post process response data. We need to copy only
331 * the 'payload' as the HWRM data structure really is
332 * HWRM header + msg header + payload and the TFLIB
333 * only provided a payload place holder.
335 if (response_len != 0) {
341 /* Extract the internal tflib response code */
342 *tf_response_code = resp->tf_resp_code;
348 int bnxt_hwrm_cfa_l2_clear_rx_mask(struct bnxt *bp, struct bnxt_vnic_info *vnic)
351 struct hwrm_cfa_l2_set_rx_mask_input req = {.req_type = 0 };
352 struct hwrm_cfa_l2_set_rx_mask_output *resp = bp->hwrm_cmd_resp_addr;
354 HWRM_PREP(&req, HWRM_CFA_L2_SET_RX_MASK, BNXT_USE_CHIMP_MB);
355 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
358 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
366 int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp,
367 struct bnxt_vnic_info *vnic,
369 struct bnxt_vlan_table_entry *vlan_table)
372 struct hwrm_cfa_l2_set_rx_mask_input req = {.req_type = 0 };
373 struct hwrm_cfa_l2_set_rx_mask_output *resp = bp->hwrm_cmd_resp_addr;
376 if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
379 HWRM_PREP(&req, HWRM_CFA_L2_SET_RX_MASK, BNXT_USE_CHIMP_MB);
380 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
382 if (vnic->flags & BNXT_VNIC_INFO_BCAST)
383 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_BCAST;
384 if (vnic->flags & BNXT_VNIC_INFO_UNTAGGED)
385 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLAN_NONVLAN;
387 if (vnic->flags & BNXT_VNIC_INFO_PROMISC)
388 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_PROMISCUOUS;
390 if (vnic->flags & BNXT_VNIC_INFO_ALLMULTI) {
391 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
392 } else if (vnic->flags & BNXT_VNIC_INFO_MCAST) {
393 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_MCAST;
394 req.num_mc_entries = rte_cpu_to_le_32(vnic->mc_addr_cnt);
395 req.mc_tbl_addr = rte_cpu_to_le_64(vnic->mc_list_dma_addr);
398 if (!(mask & HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLAN_NONVLAN))
399 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLANONLY;
400 req.vlan_tag_tbl_addr =
401 rte_cpu_to_le_64(rte_malloc_virt2iova(vlan_table));
402 req.num_vlan_tags = rte_cpu_to_le_32((uint32_t)vlan_count);
404 req.mask = rte_cpu_to_le_32(mask);
406 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
414 int bnxt_hwrm_cfa_vlan_antispoof_cfg(struct bnxt *bp, uint16_t fid,
416 struct bnxt_vlan_antispoof_table_entry *vlan_table)
419 struct hwrm_cfa_vlan_antispoof_cfg_input req = {.req_type = 0 };
420 struct hwrm_cfa_vlan_antispoof_cfg_output *resp =
421 bp->hwrm_cmd_resp_addr;
424 * Older HWRM versions did not support this command, and the set_rx_mask
425 * list was used for anti-spoof. In 1.8.0, the TX path configuration was
426 * removed from set_rx_mask call, and this command was added.
428 * This command is also present from 1.7.8.11 and higher,
431 if (bp->fw_ver < ((1 << 24) | (8 << 16))) {
432 if (bp->fw_ver != ((1 << 24) | (7 << 16) | (8 << 8))) {
433 if (bp->fw_ver < ((1 << 24) | (7 << 16) | (8 << 8) |
438 HWRM_PREP(&req, HWRM_CFA_VLAN_ANTISPOOF_CFG, BNXT_USE_CHIMP_MB);
439 req.fid = rte_cpu_to_le_16(fid);
441 req.vlan_tag_mask_tbl_addr =
442 rte_cpu_to_le_64(rte_malloc_virt2iova(vlan_table));
443 req.num_vlan_entries = rte_cpu_to_le_32((uint32_t)vlan_count);
445 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
453 int bnxt_hwrm_clear_l2_filter(struct bnxt *bp,
454 struct bnxt_filter_info *filter)
457 struct bnxt_filter_info *l2_filter = filter;
458 struct bnxt_vnic_info *vnic = NULL;
459 struct hwrm_cfa_l2_filter_free_input req = {.req_type = 0 };
460 struct hwrm_cfa_l2_filter_free_output *resp = bp->hwrm_cmd_resp_addr;
462 if (filter->fw_l2_filter_id == UINT64_MAX)
465 if (filter->matching_l2_fltr_ptr)
466 l2_filter = filter->matching_l2_fltr_ptr;
468 PMD_DRV_LOG(DEBUG, "filter: %p l2_filter: %p ref_cnt: %d\n",
469 filter, l2_filter, l2_filter->l2_ref_cnt);
471 if (l2_filter->l2_ref_cnt == 0)
474 if (l2_filter->l2_ref_cnt > 0)
475 l2_filter->l2_ref_cnt--;
477 if (l2_filter->l2_ref_cnt > 0)
480 HWRM_PREP(&req, HWRM_CFA_L2_FILTER_FREE, BNXT_USE_CHIMP_MB);
482 req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
484 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
489 filter->fw_l2_filter_id = UINT64_MAX;
490 if (l2_filter->l2_ref_cnt == 0) {
491 vnic = l2_filter->vnic;
493 STAILQ_REMOVE(&vnic->filter, l2_filter,
494 bnxt_filter_info, next);
495 bnxt_free_filter(bp, l2_filter);
502 int bnxt_hwrm_set_l2_filter(struct bnxt *bp,
504 struct bnxt_filter_info *filter)
507 struct hwrm_cfa_l2_filter_alloc_input req = {.req_type = 0 };
508 struct hwrm_cfa_l2_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr;
509 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
510 const struct rte_eth_vmdq_rx_conf *conf =
511 &dev_conf->rx_adv_conf.vmdq_rx_conf;
512 uint32_t enables = 0;
513 uint16_t j = dst_id - 1;
515 //TODO: Is there a better way to add VLANs to each VNIC in case of VMDQ
516 if ((dev_conf->rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG) &&
517 conf->pool_map[j].pools & (1UL << j)) {
519 "Add vlan %u to vmdq pool %u\n",
520 conf->pool_map[j].vlan_id, j);
522 filter->l2_ivlan = conf->pool_map[j].vlan_id;
524 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN |
525 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN_MASK;
528 if (filter->fw_l2_filter_id != UINT64_MAX)
529 bnxt_hwrm_clear_l2_filter(bp, filter);
531 HWRM_PREP(&req, HWRM_CFA_L2_FILTER_ALLOC, BNXT_USE_CHIMP_MB);
533 req.flags = rte_cpu_to_le_32(filter->flags);
535 enables = filter->enables |
536 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_DST_ID;
537 req.dst_id = rte_cpu_to_le_16(dst_id);
540 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR)
541 memcpy(req.l2_addr, filter->l2_addr,
544 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR_MASK)
545 memcpy(req.l2_addr_mask, filter->l2_addr_mask,
548 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN)
549 req.l2_ovlan = filter->l2_ovlan;
551 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN)
552 req.l2_ivlan = filter->l2_ivlan;
554 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN_MASK)
555 req.l2_ovlan_mask = filter->l2_ovlan_mask;
557 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN_MASK)
558 req.l2_ivlan_mask = filter->l2_ivlan_mask;
559 if (enables & HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_SRC_ID)
560 req.src_id = rte_cpu_to_le_32(filter->src_id);
561 if (enables & HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_SRC_TYPE)
562 req.src_type = filter->src_type;
563 if (filter->pri_hint) {
564 req.pri_hint = filter->pri_hint;
565 req.l2_filter_id_hint =
566 rte_cpu_to_le_64(filter->l2_filter_id_hint);
569 req.enables = rte_cpu_to_le_32(enables);
571 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
575 filter->fw_l2_filter_id = rte_le_to_cpu_64(resp->l2_filter_id);
576 filter->flow_id = rte_le_to_cpu_32(resp->flow_id);
579 filter->l2_ref_cnt++;
584 int bnxt_hwrm_ptp_cfg(struct bnxt *bp)
586 struct hwrm_port_mac_cfg_input req = {.req_type = 0};
587 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
594 HWRM_PREP(&req, HWRM_PORT_MAC_CFG, BNXT_USE_CHIMP_MB);
597 flags |= HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_RX_TS_CAPTURE_ENABLE;
600 HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_RX_TS_CAPTURE_DISABLE;
601 if (ptp->tx_tstamp_en)
602 flags |= HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_TX_TS_CAPTURE_ENABLE;
605 HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_TX_TS_CAPTURE_DISABLE;
606 req.flags = rte_cpu_to_le_32(flags);
607 req.enables = rte_cpu_to_le_32
608 (HWRM_PORT_MAC_CFG_INPUT_ENABLES_RX_TS_CAPTURE_PTP_MSG_TYPE);
609 req.rx_ts_capture_ptp_msg_type = rte_cpu_to_le_16(ptp->rxctl);
611 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
617 static int bnxt_hwrm_ptp_qcfg(struct bnxt *bp)
620 struct hwrm_port_mac_ptp_qcfg_input req = {.req_type = 0};
621 struct hwrm_port_mac_ptp_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
622 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
627 HWRM_PREP(&req, HWRM_PORT_MAC_PTP_QCFG, BNXT_USE_CHIMP_MB);
629 req.port_id = rte_cpu_to_le_16(bp->pf->port_id);
631 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
635 if (!BNXT_CHIP_THOR(bp) &&
636 !(resp->flags & HWRM_PORT_MAC_PTP_QCFG_OUTPUT_FLAGS_DIRECT_ACCESS))
639 if (resp->flags & HWRM_PORT_MAC_PTP_QCFG_OUTPUT_FLAGS_ONE_STEP_TX_TS)
640 bp->flags |= BNXT_FLAG_FW_CAP_ONE_STEP_TX_TS;
642 ptp = rte_zmalloc("ptp_cfg", sizeof(*ptp), 0);
646 if (!BNXT_CHIP_THOR(bp)) {
647 ptp->rx_regs[BNXT_PTP_RX_TS_L] =
648 rte_le_to_cpu_32(resp->rx_ts_reg_off_lower);
649 ptp->rx_regs[BNXT_PTP_RX_TS_H] =
650 rte_le_to_cpu_32(resp->rx_ts_reg_off_upper);
651 ptp->rx_regs[BNXT_PTP_RX_SEQ] =
652 rte_le_to_cpu_32(resp->rx_ts_reg_off_seq_id);
653 ptp->rx_regs[BNXT_PTP_RX_FIFO] =
654 rte_le_to_cpu_32(resp->rx_ts_reg_off_fifo);
655 ptp->rx_regs[BNXT_PTP_RX_FIFO_ADV] =
656 rte_le_to_cpu_32(resp->rx_ts_reg_off_fifo_adv);
657 ptp->tx_regs[BNXT_PTP_TX_TS_L] =
658 rte_le_to_cpu_32(resp->tx_ts_reg_off_lower);
659 ptp->tx_regs[BNXT_PTP_TX_TS_H] =
660 rte_le_to_cpu_32(resp->tx_ts_reg_off_upper);
661 ptp->tx_regs[BNXT_PTP_TX_SEQ] =
662 rte_le_to_cpu_32(resp->tx_ts_reg_off_seq_id);
663 ptp->tx_regs[BNXT_PTP_TX_FIFO] =
664 rte_le_to_cpu_32(resp->tx_ts_reg_off_fifo);
673 void bnxt_hwrm_free_vf_info(struct bnxt *bp)
677 for (i = 0; i < bp->pf->max_vfs; i++) {
678 rte_free(bp->pf->vf_info[i].vlan_table);
679 bp->pf->vf_info[i].vlan_table = NULL;
680 rte_free(bp->pf->vf_info[i].vlan_as_table);
681 bp->pf->vf_info[i].vlan_as_table = NULL;
683 rte_free(bp->pf->vf_info);
684 bp->pf->vf_info = NULL;
687 static int __bnxt_hwrm_func_qcaps(struct bnxt *bp)
690 struct hwrm_func_qcaps_input req = {.req_type = 0 };
691 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
692 uint16_t new_max_vfs;
696 HWRM_PREP(&req, HWRM_FUNC_QCAPS, BNXT_USE_CHIMP_MB);
698 req.fid = rte_cpu_to_le_16(0xffff);
700 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
704 bp->max_ring_grps = rte_le_to_cpu_32(resp->max_hw_ring_grps);
705 flags = rte_le_to_cpu_32(resp->flags);
707 bp->pf->port_id = resp->port_id;
708 bp->pf->first_vf_id = rte_le_to_cpu_16(resp->first_vf_id);
709 bp->pf->total_vfs = rte_le_to_cpu_16(resp->max_vfs);
710 new_max_vfs = bp->pdev->max_vfs;
711 if (new_max_vfs != bp->pf->max_vfs) {
713 bnxt_hwrm_free_vf_info(bp);
714 bp->pf->vf_info = rte_zmalloc("bnxt_vf_info",
715 sizeof(bp->pf->vf_info[0]) * new_max_vfs, 0);
716 if (bp->pf->vf_info == NULL) {
717 PMD_DRV_LOG(ERR, "Alloc vf info fail\n");
720 bp->pf->max_vfs = new_max_vfs;
721 for (i = 0; i < new_max_vfs; i++) {
722 bp->pf->vf_info[i].fid =
723 bp->pf->first_vf_id + i;
724 bp->pf->vf_info[i].vlan_table =
725 rte_zmalloc("VF VLAN table",
728 if (bp->pf->vf_info[i].vlan_table == NULL)
730 "Fail to alloc VLAN table for VF %d\n",
734 bp->pf->vf_info[i].vlan_table);
735 bp->pf->vf_info[i].vlan_as_table =
736 rte_zmalloc("VF VLAN AS table",
739 if (bp->pf->vf_info[i].vlan_as_table == NULL)
741 "Alloc VLAN AS table for VF %d fail\n",
745 bp->pf->vf_info[i].vlan_as_table);
746 STAILQ_INIT(&bp->pf->vf_info[i].filter);
751 bp->fw_fid = rte_le_to_cpu_32(resp->fid);
752 if (!bnxt_check_zero_bytes(resp->mac_address, RTE_ETHER_ADDR_LEN)) {
753 bp->flags |= BNXT_FLAG_DFLT_MAC_SET;
754 memcpy(bp->mac_addr, &resp->mac_address, RTE_ETHER_ADDR_LEN);
756 bp->flags &= ~BNXT_FLAG_DFLT_MAC_SET;
758 bp->max_rsscos_ctx = rte_le_to_cpu_16(resp->max_rsscos_ctx);
759 bp->max_cp_rings = rte_le_to_cpu_16(resp->max_cmpl_rings);
760 bp->max_tx_rings = rte_le_to_cpu_16(resp->max_tx_rings);
761 bp->max_rx_rings = rte_le_to_cpu_16(resp->max_rx_rings);
762 bp->first_vf_id = rte_le_to_cpu_16(resp->first_vf_id);
763 bp->max_rx_em_flows = rte_le_to_cpu_16(resp->max_rx_em_flows);
764 bp->max_l2_ctx = rte_le_to_cpu_16(resp->max_l2_ctxs);
765 if (!BNXT_CHIP_THOR(bp))
766 bp->max_l2_ctx += bp->max_rx_em_flows;
767 /* TODO: For now, do not support VMDq/RFS on VFs. */
772 bp->max_vnics = rte_le_to_cpu_16(resp->max_vnics);
776 PMD_DRV_LOG(DEBUG, "Max l2_cntxts is %d vnics is %d\n",
777 bp->max_l2_ctx, bp->max_vnics);
778 bp->max_stat_ctx = rte_le_to_cpu_16(resp->max_stat_ctx);
780 bp->pf->total_vnics = rte_le_to_cpu_16(resp->max_vnics);
781 if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_PTP_SUPPORTED) {
782 bp->flags |= BNXT_FLAG_PTP_SUPPORTED;
783 PMD_DRV_LOG(DEBUG, "PTP SUPPORTED\n");
785 bnxt_hwrm_ptp_qcfg(bp);
789 if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_EXT_STATS_SUPPORTED)
790 bp->flags |= BNXT_FLAG_EXT_STATS_SUPPORTED;
792 if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_ERROR_RECOVERY_CAPABLE) {
793 bp->fw_cap |= BNXT_FW_CAP_ERROR_RECOVERY;
794 PMD_DRV_LOG(DEBUG, "Adapter Error recovery SUPPORTED\n");
797 if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_ERR_RECOVER_RELOAD)
798 bp->fw_cap |= BNXT_FW_CAP_ERR_RECOVER_RELOAD;
800 if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_HOT_RESET_CAPABLE)
801 bp->fw_cap |= BNXT_FW_CAP_HOT_RESET;
808 int bnxt_hwrm_func_qcaps(struct bnxt *bp)
812 rc = __bnxt_hwrm_func_qcaps(bp);
813 if (!rc && bp->hwrm_spec_code >= HWRM_SPEC_CODE_1_8_3) {
814 rc = bnxt_alloc_ctx_mem(bp);
818 rc = bnxt_hwrm_func_resc_qcaps(bp);
820 bp->flags |= BNXT_FLAG_NEW_RM;
824 * bnxt_hwrm_func_resc_qcaps can fail and cause init failure.
825 * But the error can be ignored. Return success.
831 /* VNIC cap covers capability of all VNICs. So no need to pass vnic_id */
832 int bnxt_hwrm_vnic_qcaps(struct bnxt *bp)
835 struct hwrm_vnic_qcaps_input req = {.req_type = 0 };
836 struct hwrm_vnic_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
838 HWRM_PREP(&req, HWRM_VNIC_QCAPS, BNXT_USE_CHIMP_MB);
840 req.target_id = rte_cpu_to_le_16(0xffff);
842 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
846 if (rte_le_to_cpu_32(resp->flags) &
847 HWRM_VNIC_QCAPS_OUTPUT_FLAGS_COS_ASSIGNMENT_CAP) {
848 bp->vnic_cap_flags |= BNXT_VNIC_CAP_COS_CLASSIFY;
849 PMD_DRV_LOG(INFO, "CoS assignment capability enabled\n");
852 bp->max_tpa_v2 = rte_le_to_cpu_16(resp->max_aggs_supported);
859 int bnxt_hwrm_func_reset(struct bnxt *bp)
862 struct hwrm_func_reset_input req = {.req_type = 0 };
863 struct hwrm_func_reset_output *resp = bp->hwrm_cmd_resp_addr;
865 HWRM_PREP(&req, HWRM_FUNC_RESET, BNXT_USE_CHIMP_MB);
867 req.enables = rte_cpu_to_le_32(0);
869 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
877 int bnxt_hwrm_func_driver_register(struct bnxt *bp)
881 struct hwrm_func_drv_rgtr_input req = {.req_type = 0 };
882 struct hwrm_func_drv_rgtr_output *resp = bp->hwrm_cmd_resp_addr;
884 if (bp->flags & BNXT_FLAG_REGISTERED)
887 if (bp->fw_cap & BNXT_FW_CAP_HOT_RESET)
888 flags = HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_HOT_RESET_SUPPORT;
889 if (bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY)
890 flags |= HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_ERROR_RECOVERY_SUPPORT;
892 /* PFs and trusted VFs should indicate the support of the
893 * Master capability on non Stingray platform
895 if ((BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp)) && !BNXT_STINGRAY(bp))
896 flags |= HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_MASTER_SUPPORT;
898 HWRM_PREP(&req, HWRM_FUNC_DRV_RGTR, BNXT_USE_CHIMP_MB);
899 req.enables = rte_cpu_to_le_32(HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_VER |
900 HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_ASYNC_EVENT_FWD);
901 req.ver_maj = RTE_VER_YEAR;
902 req.ver_min = RTE_VER_MONTH;
903 req.ver_upd = RTE_VER_MINOR;
906 req.enables |= rte_cpu_to_le_32(
907 HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_VF_REQ_FWD);
908 memcpy(req.vf_req_fwd, bp->pf->vf_req_fwd,
909 RTE_MIN(sizeof(req.vf_req_fwd),
910 sizeof(bp->pf->vf_req_fwd)));
913 * PF can sniff HWRM API issued by VF. This can be set up by
914 * linux driver and inherited by the DPDK PF driver. Clear
915 * this HWRM sniffer list in FW because DPDK PF driver does
918 flags |= HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_FWD_NONE_MODE;
921 req.flags = rte_cpu_to_le_32(flags);
923 req.async_event_fwd[0] |=
924 rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_LINK_STATUS_CHANGE |
925 ASYNC_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED |
926 ASYNC_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE |
927 ASYNC_CMPL_EVENT_ID_LINK_SPEED_CHANGE |
928 ASYNC_CMPL_EVENT_ID_RESET_NOTIFY);
929 if (bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY)
930 req.async_event_fwd[0] |=
931 rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_ERROR_RECOVERY);
932 req.async_event_fwd[1] |=
933 rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_PF_DRVR_UNLOAD |
934 ASYNC_CMPL_EVENT_ID_VF_CFG_CHANGE);
936 req.async_event_fwd[1] |=
937 rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_DBG_NOTIFICATION);
939 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
943 flags = rte_le_to_cpu_32(resp->flags);
944 if (flags & HWRM_FUNC_DRV_RGTR_OUTPUT_FLAGS_IF_CHANGE_SUPPORTED)
945 bp->fw_cap |= BNXT_FW_CAP_IF_CHANGE;
949 bp->flags |= BNXT_FLAG_REGISTERED;
954 int bnxt_hwrm_check_vf_rings(struct bnxt *bp)
956 if (!(BNXT_VF(bp) && (bp->flags & BNXT_FLAG_NEW_RM)))
959 return bnxt_hwrm_func_reserve_vf_resc(bp, true);
962 int bnxt_hwrm_func_reserve_vf_resc(struct bnxt *bp, bool test)
967 struct hwrm_func_vf_cfg_output *resp = bp->hwrm_cmd_resp_addr;
968 struct hwrm_func_vf_cfg_input req = {0};
970 HWRM_PREP(&req, HWRM_FUNC_VF_CFG, BNXT_USE_CHIMP_MB);
972 enables = HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_RX_RINGS |
973 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_TX_RINGS |
974 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
975 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
976 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_VNICS;
978 if (BNXT_HAS_RING_GRPS(bp)) {
979 enables |= HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS;
980 req.num_hw_ring_grps = rte_cpu_to_le_16(bp->rx_nr_rings);
983 req.num_tx_rings = rte_cpu_to_le_16(bp->tx_nr_rings);
984 req.num_rx_rings = rte_cpu_to_le_16(bp->rx_nr_rings *
985 AGG_RING_MULTIPLIER);
986 req.num_stat_ctxs = rte_cpu_to_le_16(bp->rx_nr_rings + bp->tx_nr_rings);
987 req.num_cmpl_rings = rte_cpu_to_le_16(bp->rx_nr_rings +
989 BNXT_NUM_ASYNC_CPR(bp));
990 req.num_vnics = rte_cpu_to_le_16(bp->rx_nr_rings);
991 if (bp->vf_resv_strategy ==
992 HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESV_STRATEGY_MINIMAL_STATIC) {
993 enables |= HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_VNICS |
994 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_L2_CTXS |
995 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS;
996 req.num_rsscos_ctxs = rte_cpu_to_le_16(BNXT_VF_RSV_NUM_RSS_CTX);
997 req.num_l2_ctxs = rte_cpu_to_le_16(BNXT_VF_RSV_NUM_L2_CTX);
998 req.num_vnics = rte_cpu_to_le_16(BNXT_VF_RSV_NUM_VNIC);
999 } else if (bp->vf_resv_strategy ==
1000 HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESV_STRATEGY_MAXIMAL) {
1001 enables |= HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS;
1002 req.num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx);
1006 flags = HWRM_FUNC_VF_CFG_INPUT_FLAGS_TX_ASSETS_TEST |
1007 HWRM_FUNC_VF_CFG_INPUT_FLAGS_RX_ASSETS_TEST |
1008 HWRM_FUNC_VF_CFG_INPUT_FLAGS_CMPL_ASSETS_TEST |
1009 HWRM_FUNC_VF_CFG_INPUT_FLAGS_RING_GRP_ASSETS_TEST |
1010 HWRM_FUNC_VF_CFG_INPUT_FLAGS_STAT_CTX_ASSETS_TEST |
1011 HWRM_FUNC_VF_CFG_INPUT_FLAGS_VNIC_ASSETS_TEST;
1013 if (test && BNXT_HAS_RING_GRPS(bp))
1014 flags |= HWRM_FUNC_VF_CFG_INPUT_FLAGS_RING_GRP_ASSETS_TEST;
1016 req.flags = rte_cpu_to_le_32(flags);
1017 req.enables |= rte_cpu_to_le_32(enables);
1019 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1022 HWRM_CHECK_RESULT_SILENT();
1024 HWRM_CHECK_RESULT();
1030 int bnxt_hwrm_func_resc_qcaps(struct bnxt *bp)
1033 struct hwrm_func_resource_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
1034 struct hwrm_func_resource_qcaps_input req = {0};
1036 HWRM_PREP(&req, HWRM_FUNC_RESOURCE_QCAPS, BNXT_USE_CHIMP_MB);
1037 req.fid = rte_cpu_to_le_16(0xffff);
1039 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1041 HWRM_CHECK_RESULT_SILENT();
1044 bp->max_rsscos_ctx = rte_le_to_cpu_16(resp->max_rsscos_ctx);
1045 bp->max_cp_rings = rte_le_to_cpu_16(resp->max_cmpl_rings);
1046 bp->max_tx_rings = rte_le_to_cpu_16(resp->max_tx_rings);
1047 bp->max_rx_rings = rte_le_to_cpu_16(resp->max_rx_rings);
1048 bp->max_ring_grps = rte_le_to_cpu_32(resp->max_hw_ring_grps);
1049 /* func_resource_qcaps does not return max_rx_em_flows.
1050 * So use the value provided by func_qcaps.
1052 bp->max_l2_ctx = rte_le_to_cpu_16(resp->max_l2_ctxs);
1053 if (!BNXT_CHIP_THOR(bp))
1054 bp->max_l2_ctx += bp->max_rx_em_flows;
1055 bp->max_vnics = rte_le_to_cpu_16(resp->max_vnics);
1056 bp->max_stat_ctx = rte_le_to_cpu_16(resp->max_stat_ctx);
1058 bp->max_nq_rings = rte_le_to_cpu_16(resp->max_msix);
1059 bp->vf_resv_strategy = rte_le_to_cpu_16(resp->vf_reservation_strategy);
1060 if (bp->vf_resv_strategy >
1061 HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESV_STRATEGY_MINIMAL_STATIC)
1062 bp->vf_resv_strategy =
1063 HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESERVATION_STRATEGY_MAXIMAL;
1069 int bnxt_hwrm_ver_get(struct bnxt *bp, uint32_t timeout)
1072 struct hwrm_ver_get_input req = {.req_type = 0 };
1073 struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr;
1074 uint32_t fw_version;
1075 uint16_t max_resp_len;
1076 char type[RTE_MEMZONE_NAMESIZE];
1077 uint32_t dev_caps_cfg;
1079 bp->max_req_len = HWRM_MAX_REQ_LEN;
1080 bp->hwrm_cmd_timeout = timeout;
1081 HWRM_PREP(&req, HWRM_VER_GET, BNXT_USE_CHIMP_MB);
1083 req.hwrm_intf_maj = HWRM_VERSION_MAJOR;
1084 req.hwrm_intf_min = HWRM_VERSION_MINOR;
1085 req.hwrm_intf_upd = HWRM_VERSION_UPDATE;
1087 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1089 if (bp->flags & BNXT_FLAG_FW_RESET)
1090 HWRM_CHECK_RESULT_SILENT();
1092 HWRM_CHECK_RESULT();
1094 PMD_DRV_LOG(INFO, "%d.%d.%d:%d.%d.%d\n",
1095 resp->hwrm_intf_maj_8b, resp->hwrm_intf_min_8b,
1096 resp->hwrm_intf_upd_8b, resp->hwrm_fw_maj_8b,
1097 resp->hwrm_fw_min_8b, resp->hwrm_fw_bld_8b);
1098 bp->fw_ver = (resp->hwrm_fw_maj_8b << 24) |
1099 (resp->hwrm_fw_min_8b << 16) |
1100 (resp->hwrm_fw_bld_8b << 8) |
1101 resp->hwrm_fw_rsvd_8b;
1102 PMD_DRV_LOG(INFO, "Driver HWRM version: %d.%d.%d\n",
1103 HWRM_VERSION_MAJOR, HWRM_VERSION_MINOR, HWRM_VERSION_UPDATE);
1105 fw_version = resp->hwrm_intf_maj_8b << 16;
1106 fw_version |= resp->hwrm_intf_min_8b << 8;
1107 fw_version |= resp->hwrm_intf_upd_8b;
1108 bp->hwrm_spec_code = fw_version;
1110 /* def_req_timeout value is in milliseconds */
1111 bp->hwrm_cmd_timeout = rte_le_to_cpu_16(resp->def_req_timeout);
1112 /* convert timeout to usec */
1113 bp->hwrm_cmd_timeout *= 1000;
1114 if (!bp->hwrm_cmd_timeout)
1115 bp->hwrm_cmd_timeout = DFLT_HWRM_CMD_TIMEOUT;
1117 if (resp->hwrm_intf_maj_8b != HWRM_VERSION_MAJOR) {
1118 PMD_DRV_LOG(ERR, "Unsupported firmware API version\n");
1123 if (bp->max_req_len > resp->max_req_win_len) {
1124 PMD_DRV_LOG(ERR, "Unsupported request length\n");
1127 bp->max_req_len = rte_le_to_cpu_16(resp->max_req_win_len);
1128 bp->hwrm_max_ext_req_len = rte_le_to_cpu_16(resp->max_ext_req_len);
1129 if (bp->hwrm_max_ext_req_len < HWRM_MAX_REQ_LEN)
1130 bp->hwrm_max_ext_req_len = HWRM_MAX_REQ_LEN;
1132 max_resp_len = rte_le_to_cpu_16(resp->max_resp_len);
1133 dev_caps_cfg = rte_le_to_cpu_32(resp->dev_caps_cfg);
1135 if (bp->max_resp_len != max_resp_len) {
1136 sprintf(type, "bnxt_hwrm_" PCI_PRI_FMT,
1137 bp->pdev->addr.domain, bp->pdev->addr.bus,
1138 bp->pdev->addr.devid, bp->pdev->addr.function);
1140 rte_free(bp->hwrm_cmd_resp_addr);
1142 bp->hwrm_cmd_resp_addr = rte_malloc(type, max_resp_len, 0);
1143 if (bp->hwrm_cmd_resp_addr == NULL) {
1147 bp->hwrm_cmd_resp_dma_addr =
1148 rte_malloc_virt2iova(bp->hwrm_cmd_resp_addr);
1149 if (bp->hwrm_cmd_resp_dma_addr == RTE_BAD_IOVA) {
1151 "Unable to map response buffer to physical memory.\n");
1155 bp->max_resp_len = max_resp_len;
1159 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
1161 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_REQUIRED)) {
1162 PMD_DRV_LOG(DEBUG, "Short command supported\n");
1163 bp->flags |= BNXT_FLAG_SHORT_CMD;
1166 if (((dev_caps_cfg &
1167 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
1169 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_REQUIRED)) ||
1170 bp->hwrm_max_ext_req_len > HWRM_MAX_REQ_LEN) {
1171 sprintf(type, "bnxt_hwrm_short_" PCI_PRI_FMT,
1172 bp->pdev->addr.domain, bp->pdev->addr.bus,
1173 bp->pdev->addr.devid, bp->pdev->addr.function);
1175 rte_free(bp->hwrm_short_cmd_req_addr);
1177 bp->hwrm_short_cmd_req_addr =
1178 rte_malloc(type, bp->hwrm_max_ext_req_len, 0);
1179 if (bp->hwrm_short_cmd_req_addr == NULL) {
1183 bp->hwrm_short_cmd_req_dma_addr =
1184 rte_malloc_virt2iova(bp->hwrm_short_cmd_req_addr);
1185 if (bp->hwrm_short_cmd_req_dma_addr == RTE_BAD_IOVA) {
1186 rte_free(bp->hwrm_short_cmd_req_addr);
1188 "Unable to map buffer to physical memory.\n");
1194 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_KONG_MB_CHNL_SUPPORTED) {
1195 bp->flags |= BNXT_FLAG_KONG_MB_EN;
1196 PMD_DRV_LOG(DEBUG, "Kong mailbox channel enabled\n");
1199 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_TRUSTED_VF_SUPPORTED)
1200 PMD_DRV_LOG(DEBUG, "FW supports Trusted VFs\n");
1202 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_CFA_ADV_FLOW_MGNT_SUPPORTED) {
1203 bp->fw_cap |= BNXT_FW_CAP_ADV_FLOW_MGMT;
1204 PMD_DRV_LOG(DEBUG, "FW supports advanced flow management\n");
1208 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_ADV_FLOW_COUNTERS_SUPPORTED) {
1209 PMD_DRV_LOG(DEBUG, "FW supports advanced flow counters\n");
1210 bp->fw_cap |= BNXT_FW_CAP_ADV_FLOW_COUNTERS;
1219 int bnxt_hwrm_func_driver_unregister(struct bnxt *bp, uint32_t flags)
1222 struct hwrm_func_drv_unrgtr_input req = {.req_type = 0 };
1223 struct hwrm_func_drv_unrgtr_output *resp = bp->hwrm_cmd_resp_addr;
1225 if (!(bp->flags & BNXT_FLAG_REGISTERED))
1228 HWRM_PREP(&req, HWRM_FUNC_DRV_UNRGTR, BNXT_USE_CHIMP_MB);
1231 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1233 HWRM_CHECK_RESULT();
1239 static int bnxt_hwrm_port_phy_cfg(struct bnxt *bp, struct bnxt_link_info *conf)
1242 struct hwrm_port_phy_cfg_input req = {0};
1243 struct hwrm_port_phy_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1244 uint32_t enables = 0;
1246 HWRM_PREP(&req, HWRM_PORT_PHY_CFG, BNXT_USE_CHIMP_MB);
1248 if (conf->link_up) {
1249 /* Setting Fixed Speed. But AutoNeg is ON, So disable it */
1250 if (bp->link_info->auto_mode && conf->link_speed) {
1251 req.auto_mode = HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_NONE;
1252 PMD_DRV_LOG(DEBUG, "Disabling AutoNeg\n");
1255 req.flags = rte_cpu_to_le_32(conf->phy_flags);
1256 req.force_link_speed = rte_cpu_to_le_16(conf->link_speed);
1257 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_MODE;
1259 * Note, ChiMP FW 20.2.1 and 20.2.2 return an error when we set
1260 * any auto mode, even "none".
1262 if (!conf->link_speed) {
1263 /* No speeds specified. Enable AutoNeg - all speeds */
1265 HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_ALL_SPEEDS;
1267 /* AutoNeg - Advertise speeds specified. */
1268 if (conf->auto_link_speed_mask &&
1269 !(conf->phy_flags & HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE)) {
1271 HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_SPEED_MASK;
1272 req.auto_link_speed_mask =
1273 conf->auto_link_speed_mask;
1275 HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_LINK_SPEED_MASK;
1278 req.auto_duplex = conf->duplex;
1279 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_DUPLEX;
1280 req.auto_pause = conf->auto_pause;
1281 req.force_pause = conf->force_pause;
1282 /* Set force_pause if there is no auto or if there is a force */
1283 if (req.auto_pause && !req.force_pause)
1284 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_PAUSE;
1286 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_FORCE_PAUSE;
1288 req.enables = rte_cpu_to_le_32(enables);
1291 rte_cpu_to_le_32(HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE_LINK_DWN);
1292 PMD_DRV_LOG(INFO, "Force Link Down\n");
1295 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1297 HWRM_CHECK_RESULT();
1303 static int bnxt_hwrm_port_phy_qcfg(struct bnxt *bp,
1304 struct bnxt_link_info *link_info)
1307 struct hwrm_port_phy_qcfg_input req = {0};
1308 struct hwrm_port_phy_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
1310 HWRM_PREP(&req, HWRM_PORT_PHY_QCFG, BNXT_USE_CHIMP_MB);
1312 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1314 HWRM_CHECK_RESULT();
1316 link_info->phy_link_status = resp->link;
1317 link_info->link_up =
1318 (link_info->phy_link_status ==
1319 HWRM_PORT_PHY_QCFG_OUTPUT_LINK_LINK) ? 1 : 0;
1320 link_info->link_speed = rte_le_to_cpu_16(resp->link_speed);
1321 link_info->duplex = resp->duplex_cfg;
1322 link_info->pause = resp->pause;
1323 link_info->auto_pause = resp->auto_pause;
1324 link_info->force_pause = resp->force_pause;
1325 link_info->auto_mode = resp->auto_mode;
1326 link_info->phy_type = resp->phy_type;
1327 link_info->media_type = resp->media_type;
1329 link_info->support_speeds = rte_le_to_cpu_16(resp->support_speeds);
1330 link_info->auto_link_speed = rte_le_to_cpu_16(resp->auto_link_speed);
1331 link_info->preemphasis = rte_le_to_cpu_32(resp->preemphasis);
1332 link_info->force_link_speed = rte_le_to_cpu_16(resp->force_link_speed);
1333 link_info->phy_ver[0] = resp->phy_maj;
1334 link_info->phy_ver[1] = resp->phy_min;
1335 link_info->phy_ver[2] = resp->phy_bld;
1339 PMD_DRV_LOG(DEBUG, "Link Speed %d\n", link_info->link_speed);
1340 PMD_DRV_LOG(DEBUG, "Auto Mode %d\n", link_info->auto_mode);
1341 PMD_DRV_LOG(DEBUG, "Support Speeds %x\n", link_info->support_speeds);
1342 PMD_DRV_LOG(DEBUG, "Auto Link Speed %x\n", link_info->auto_link_speed);
1343 PMD_DRV_LOG(DEBUG, "Auto Link Speed Mask %x\n",
1344 link_info->auto_link_speed_mask);
1345 PMD_DRV_LOG(DEBUG, "Forced Link Speed %x\n",
1346 link_info->force_link_speed);
1351 int bnxt_hwrm_port_phy_qcaps(struct bnxt *bp)
1354 struct hwrm_port_phy_qcaps_input req = {0};
1355 struct hwrm_port_phy_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
1357 if (BNXT_VF(bp) && !BNXT_VF_IS_TRUSTED(bp))
1360 HWRM_PREP(&req, HWRM_PORT_PHY_QCAPS, BNXT_USE_CHIMP_MB);
1362 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1364 HWRM_CHECK_RESULT();
1366 bp->port_cnt = resp->port_cnt;
1373 static bool bnxt_find_lossy_profile(struct bnxt *bp)
1377 for (i = BNXT_COS_QUEUE_COUNT - 1; i >= 0; i--) {
1378 if (bp->tx_cos_queue[i].profile ==
1379 HWRM_QUEUE_SERVICE_PROFILE_LOSSY) {
1380 bp->tx_cosq_id[0] = bp->tx_cos_queue[i].id;
1387 static void bnxt_find_first_valid_profile(struct bnxt *bp)
1391 for (i = BNXT_COS_QUEUE_COUNT - 1; i >= 0; i--) {
1392 if (bp->tx_cos_queue[i].profile !=
1393 HWRM_QUEUE_SERVICE_PROFILE_UNKNOWN &&
1394 bp->tx_cos_queue[i].id !=
1395 HWRM_QUEUE_SERVICE_PROFILE_UNKNOWN) {
1396 bp->tx_cosq_id[0] = bp->tx_cos_queue[i].id;
1402 int bnxt_hwrm_queue_qportcfg(struct bnxt *bp)
1405 struct hwrm_queue_qportcfg_input req = {.req_type = 0 };
1406 struct hwrm_queue_qportcfg_output *resp = bp->hwrm_cmd_resp_addr;
1407 uint32_t dir = HWRM_QUEUE_QPORTCFG_INPUT_FLAGS_PATH_TX;
1411 HWRM_PREP(&req, HWRM_QUEUE_QPORTCFG, BNXT_USE_CHIMP_MB);
1413 req.flags = rte_cpu_to_le_32(dir);
1414 /* HWRM Version >= 1.9.1 only if COS Classification is not required. */
1415 if (bp->hwrm_spec_code >= HWRM_VERSION_1_9_1 &&
1416 !(bp->vnic_cap_flags & BNXT_VNIC_CAP_COS_CLASSIFY))
1418 HWRM_QUEUE_QPORTCFG_INPUT_DRV_QMAP_CAP_ENABLED;
1419 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1421 HWRM_CHECK_RESULT();
1423 if (dir == HWRM_QUEUE_QPORTCFG_INPUT_FLAGS_PATH_TX) {
1424 GET_TX_QUEUE_INFO(0);
1425 GET_TX_QUEUE_INFO(1);
1426 GET_TX_QUEUE_INFO(2);
1427 GET_TX_QUEUE_INFO(3);
1428 GET_TX_QUEUE_INFO(4);
1429 GET_TX_QUEUE_INFO(5);
1430 GET_TX_QUEUE_INFO(6);
1431 GET_TX_QUEUE_INFO(7);
1433 GET_RX_QUEUE_INFO(0);
1434 GET_RX_QUEUE_INFO(1);
1435 GET_RX_QUEUE_INFO(2);
1436 GET_RX_QUEUE_INFO(3);
1437 GET_RX_QUEUE_INFO(4);
1438 GET_RX_QUEUE_INFO(5);
1439 GET_RX_QUEUE_INFO(6);
1440 GET_RX_QUEUE_INFO(7);
1445 if (dir == HWRM_QUEUE_QPORTCFG_INPUT_FLAGS_PATH_RX)
1448 if (bp->hwrm_spec_code < HWRM_VERSION_1_9_1) {
1449 bp->tx_cosq_id[0] = bp->tx_cos_queue[0].id;
1453 /* iterate and find the COSq profile to use for Tx */
1454 if (bp->vnic_cap_flags & BNXT_VNIC_CAP_COS_CLASSIFY) {
1455 for (j = 0, i = 0; i < BNXT_COS_QUEUE_COUNT; i++) {
1456 if (bp->tx_cos_queue[i].id != 0xff)
1457 bp->tx_cosq_id[j++] =
1458 bp->tx_cos_queue[i].id;
1461 /* When CoS classification is disabled, for normal NIC
1462 * operations, ideally we should look to use LOSSY.
1463 * If not found, fallback to the first valid profile
1465 if (!bnxt_find_lossy_profile(bp))
1466 bnxt_find_first_valid_profile(bp);
1471 bp->max_tc = resp->max_configurable_queues;
1472 bp->max_lltc = resp->max_configurable_lossless_queues;
1473 if (bp->max_tc > BNXT_MAX_QUEUE)
1474 bp->max_tc = BNXT_MAX_QUEUE;
1475 bp->max_q = bp->max_tc;
1477 if (dir == HWRM_QUEUE_QPORTCFG_INPUT_FLAGS_PATH_TX) {
1478 dir = HWRM_QUEUE_QPORTCFG_INPUT_FLAGS_PATH_RX;
1486 int bnxt_hwrm_ring_alloc(struct bnxt *bp,
1487 struct bnxt_ring *ring,
1488 uint32_t ring_type, uint32_t map_index,
1489 uint32_t stats_ctx_id, uint32_t cmpl_ring_id,
1490 uint16_t tx_cosq_id)
1493 uint32_t enables = 0;
1494 struct hwrm_ring_alloc_input req = {.req_type = 0 };
1495 struct hwrm_ring_alloc_output *resp = bp->hwrm_cmd_resp_addr;
1496 struct rte_mempool *mb_pool;
1497 uint16_t rx_buf_size;
1499 HWRM_PREP(&req, HWRM_RING_ALLOC, BNXT_USE_CHIMP_MB);
1501 req.page_tbl_addr = rte_cpu_to_le_64(ring->bd_dma);
1502 req.fbo = rte_cpu_to_le_32(0);
1503 /* Association of ring index with doorbell index */
1504 req.logical_id = rte_cpu_to_le_16(map_index);
1505 req.length = rte_cpu_to_le_32(ring->ring_size);
1507 switch (ring_type) {
1508 case HWRM_RING_ALLOC_INPUT_RING_TYPE_TX:
1509 req.ring_type = ring_type;
1510 req.cmpl_ring_id = rte_cpu_to_le_16(cmpl_ring_id);
1511 req.stat_ctx_id = rte_cpu_to_le_32(stats_ctx_id);
1512 req.queue_id = rte_cpu_to_le_16(tx_cosq_id);
1513 if (stats_ctx_id != INVALID_STATS_CTX_ID)
1515 HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID;
1517 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX:
1518 req.ring_type = ring_type;
1519 req.cmpl_ring_id = rte_cpu_to_le_16(cmpl_ring_id);
1520 req.stat_ctx_id = rte_cpu_to_le_32(stats_ctx_id);
1521 if (BNXT_CHIP_THOR(bp)) {
1522 mb_pool = bp->rx_queues[0]->mb_pool;
1523 rx_buf_size = rte_pktmbuf_data_room_size(mb_pool) -
1524 RTE_PKTMBUF_HEADROOM;
1525 rx_buf_size = RTE_MIN(BNXT_MAX_PKT_LEN, rx_buf_size);
1526 req.rx_buf_size = rte_cpu_to_le_16(rx_buf_size);
1528 HWRM_RING_ALLOC_INPUT_ENABLES_RX_BUF_SIZE_VALID;
1530 if (stats_ctx_id != INVALID_STATS_CTX_ID)
1532 HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID;
1534 case HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL:
1535 req.ring_type = ring_type;
1536 if (BNXT_HAS_NQ(bp)) {
1537 /* Association of cp ring with nq */
1538 req.nq_ring_id = rte_cpu_to_le_16(cmpl_ring_id);
1540 HWRM_RING_ALLOC_INPUT_ENABLES_NQ_RING_ID_VALID;
1542 req.int_mode = HWRM_RING_ALLOC_INPUT_INT_MODE_MSIX;
1544 case HWRM_RING_ALLOC_INPUT_RING_TYPE_NQ:
1545 req.ring_type = ring_type;
1546 req.page_size = BNXT_PAGE_SHFT;
1547 req.int_mode = HWRM_RING_ALLOC_INPUT_INT_MODE_MSIX;
1549 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX_AGG:
1550 req.ring_type = ring_type;
1551 req.rx_ring_id = rte_cpu_to_le_16(ring->fw_rx_ring_id);
1553 mb_pool = bp->rx_queues[0]->mb_pool;
1554 rx_buf_size = rte_pktmbuf_data_room_size(mb_pool) -
1555 RTE_PKTMBUF_HEADROOM;
1556 rx_buf_size = RTE_MIN(BNXT_MAX_PKT_LEN, rx_buf_size);
1557 req.rx_buf_size = rte_cpu_to_le_16(rx_buf_size);
1559 req.stat_ctx_id = rte_cpu_to_le_32(stats_ctx_id);
1560 enables |= HWRM_RING_ALLOC_INPUT_ENABLES_RX_RING_ID_VALID |
1561 HWRM_RING_ALLOC_INPUT_ENABLES_RX_BUF_SIZE_VALID |
1562 HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID;
1565 PMD_DRV_LOG(ERR, "hwrm alloc invalid ring type %d\n",
1570 req.enables = rte_cpu_to_le_32(enables);
1572 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1574 if (rc || resp->error_code) {
1575 if (rc == 0 && resp->error_code)
1576 rc = rte_le_to_cpu_16(resp->error_code);
1577 switch (ring_type) {
1578 case HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL:
1580 "hwrm_ring_alloc cp failed. rc:%d\n", rc);
1583 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX:
1585 "hwrm_ring_alloc rx failed. rc:%d\n", rc);
1588 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX_AGG:
1590 "hwrm_ring_alloc rx agg failed. rc:%d\n",
1594 case HWRM_RING_ALLOC_INPUT_RING_TYPE_TX:
1596 "hwrm_ring_alloc tx failed. rc:%d\n", rc);
1599 case HWRM_RING_ALLOC_INPUT_RING_TYPE_NQ:
1601 "hwrm_ring_alloc nq failed. rc:%d\n", rc);
1605 PMD_DRV_LOG(ERR, "Invalid ring. rc:%d\n", rc);
1611 ring->fw_ring_id = rte_le_to_cpu_16(resp->ring_id);
1616 int bnxt_hwrm_ring_free(struct bnxt *bp,
1617 struct bnxt_ring *ring, uint32_t ring_type)
1620 struct hwrm_ring_free_input req = {.req_type = 0 };
1621 struct hwrm_ring_free_output *resp = bp->hwrm_cmd_resp_addr;
1623 HWRM_PREP(&req, HWRM_RING_FREE, BNXT_USE_CHIMP_MB);
1625 req.ring_type = ring_type;
1626 req.ring_id = rte_cpu_to_le_16(ring->fw_ring_id);
1628 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1630 if (rc || resp->error_code) {
1631 if (rc == 0 && resp->error_code)
1632 rc = rte_le_to_cpu_16(resp->error_code);
1635 switch (ring_type) {
1636 case HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL:
1637 PMD_DRV_LOG(ERR, "hwrm_ring_free cp failed. rc:%d\n",
1640 case HWRM_RING_FREE_INPUT_RING_TYPE_RX:
1641 PMD_DRV_LOG(ERR, "hwrm_ring_free rx failed. rc:%d\n",
1644 case HWRM_RING_FREE_INPUT_RING_TYPE_TX:
1645 PMD_DRV_LOG(ERR, "hwrm_ring_free tx failed. rc:%d\n",
1648 case HWRM_RING_FREE_INPUT_RING_TYPE_NQ:
1650 "hwrm_ring_free nq failed. rc:%d\n", rc);
1652 case HWRM_RING_FREE_INPUT_RING_TYPE_RX_AGG:
1654 "hwrm_ring_free agg failed. rc:%d\n", rc);
1657 PMD_DRV_LOG(ERR, "Invalid ring, rc:%d\n", rc);
1665 int bnxt_hwrm_ring_grp_alloc(struct bnxt *bp, unsigned int idx)
1668 struct hwrm_ring_grp_alloc_input req = {.req_type = 0 };
1669 struct hwrm_ring_grp_alloc_output *resp = bp->hwrm_cmd_resp_addr;
1671 HWRM_PREP(&req, HWRM_RING_GRP_ALLOC, BNXT_USE_CHIMP_MB);
1673 req.cr = rte_cpu_to_le_16(bp->grp_info[idx].cp_fw_ring_id);
1674 req.rr = rte_cpu_to_le_16(bp->grp_info[idx].rx_fw_ring_id);
1675 req.ar = rte_cpu_to_le_16(bp->grp_info[idx].ag_fw_ring_id);
1676 req.sc = rte_cpu_to_le_16(bp->grp_info[idx].fw_stats_ctx);
1678 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1680 HWRM_CHECK_RESULT();
1682 bp->grp_info[idx].fw_grp_id = rte_le_to_cpu_16(resp->ring_group_id);
1689 int bnxt_hwrm_ring_grp_free(struct bnxt *bp, unsigned int idx)
1692 struct hwrm_ring_grp_free_input req = {.req_type = 0 };
1693 struct hwrm_ring_grp_free_output *resp = bp->hwrm_cmd_resp_addr;
1695 HWRM_PREP(&req, HWRM_RING_GRP_FREE, BNXT_USE_CHIMP_MB);
1697 req.ring_group_id = rte_cpu_to_le_16(bp->grp_info[idx].fw_grp_id);
1699 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1701 HWRM_CHECK_RESULT();
1704 bp->grp_info[idx].fw_grp_id = INVALID_HW_RING_ID;
1708 int bnxt_hwrm_stat_clear(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
1711 struct hwrm_stat_ctx_clr_stats_input req = {.req_type = 0 };
1712 struct hwrm_stat_ctx_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
1714 if (cpr->hw_stats_ctx_id == (uint32_t)HWRM_NA_SIGNATURE)
1717 HWRM_PREP(&req, HWRM_STAT_CTX_CLR_STATS, BNXT_USE_CHIMP_MB);
1719 req.stat_ctx_id = rte_cpu_to_le_32(cpr->hw_stats_ctx_id);
1721 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1723 HWRM_CHECK_RESULT();
1729 int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
1730 unsigned int idx __rte_unused)
1733 struct hwrm_stat_ctx_alloc_input req = {.req_type = 0 };
1734 struct hwrm_stat_ctx_alloc_output *resp = bp->hwrm_cmd_resp_addr;
1736 HWRM_PREP(&req, HWRM_STAT_CTX_ALLOC, BNXT_USE_CHIMP_MB);
1738 req.update_period_ms = rte_cpu_to_le_32(0);
1740 req.stats_dma_addr = rte_cpu_to_le_64(cpr->hw_stats_map);
1742 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1744 HWRM_CHECK_RESULT();
1746 cpr->hw_stats_ctx_id = rte_le_to_cpu_32(resp->stat_ctx_id);
1753 int bnxt_hwrm_stat_ctx_free(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
1754 unsigned int idx __rte_unused)
1757 struct hwrm_stat_ctx_free_input req = {.req_type = 0 };
1758 struct hwrm_stat_ctx_free_output *resp = bp->hwrm_cmd_resp_addr;
1760 HWRM_PREP(&req, HWRM_STAT_CTX_FREE, BNXT_USE_CHIMP_MB);
1762 req.stat_ctx_id = rte_cpu_to_le_32(cpr->hw_stats_ctx_id);
1764 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1766 HWRM_CHECK_RESULT();
1772 int bnxt_hwrm_vnic_alloc(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1775 struct hwrm_vnic_alloc_input req = { 0 };
1776 struct hwrm_vnic_alloc_output *resp = bp->hwrm_cmd_resp_addr;
1778 if (!BNXT_HAS_RING_GRPS(bp))
1779 goto skip_ring_grps;
1781 /* map ring groups to this vnic */
1782 PMD_DRV_LOG(DEBUG, "Alloc VNIC. Start %x, End %x\n",
1783 vnic->start_grp_id, vnic->end_grp_id);
1784 for (i = vnic->start_grp_id, j = 0; i < vnic->end_grp_id; i++, j++)
1785 vnic->fw_grp_ids[j] = bp->grp_info[i].fw_grp_id;
1787 vnic->dflt_ring_grp = bp->grp_info[vnic->start_grp_id].fw_grp_id;
1788 vnic->rss_rule = (uint16_t)HWRM_NA_SIGNATURE;
1789 vnic->cos_rule = (uint16_t)HWRM_NA_SIGNATURE;
1790 vnic->lb_rule = (uint16_t)HWRM_NA_SIGNATURE;
1793 vnic->mru = BNXT_VNIC_MRU(bp->eth_dev->data->mtu);
1794 HWRM_PREP(&req, HWRM_VNIC_ALLOC, BNXT_USE_CHIMP_MB);
1796 if (vnic->func_default)
1798 rte_cpu_to_le_32(HWRM_VNIC_ALLOC_INPUT_FLAGS_DEFAULT);
1799 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1801 HWRM_CHECK_RESULT();
1803 vnic->fw_vnic_id = rte_le_to_cpu_16(resp->vnic_id);
1805 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
1809 static int bnxt_hwrm_vnic_plcmodes_qcfg(struct bnxt *bp,
1810 struct bnxt_vnic_info *vnic,
1811 struct bnxt_plcmodes_cfg *pmode)
1814 struct hwrm_vnic_plcmodes_qcfg_input req = {.req_type = 0 };
1815 struct hwrm_vnic_plcmodes_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
1817 HWRM_PREP(&req, HWRM_VNIC_PLCMODES_QCFG, BNXT_USE_CHIMP_MB);
1819 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1821 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1823 HWRM_CHECK_RESULT();
1825 pmode->flags = rte_le_to_cpu_32(resp->flags);
1826 /* dflt_vnic bit doesn't exist in the _cfg command */
1827 pmode->flags &= ~(HWRM_VNIC_PLCMODES_QCFG_OUTPUT_FLAGS_DFLT_VNIC);
1828 pmode->jumbo_thresh = rte_le_to_cpu_16(resp->jumbo_thresh);
1829 pmode->hds_offset = rte_le_to_cpu_16(resp->hds_offset);
1830 pmode->hds_threshold = rte_le_to_cpu_16(resp->hds_threshold);
1837 static int bnxt_hwrm_vnic_plcmodes_cfg(struct bnxt *bp,
1838 struct bnxt_vnic_info *vnic,
1839 struct bnxt_plcmodes_cfg *pmode)
1842 struct hwrm_vnic_plcmodes_cfg_input req = {.req_type = 0 };
1843 struct hwrm_vnic_plcmodes_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1845 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1846 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
1850 HWRM_PREP(&req, HWRM_VNIC_PLCMODES_CFG, BNXT_USE_CHIMP_MB);
1852 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1853 req.flags = rte_cpu_to_le_32(pmode->flags);
1854 req.jumbo_thresh = rte_cpu_to_le_16(pmode->jumbo_thresh);
1855 req.hds_offset = rte_cpu_to_le_16(pmode->hds_offset);
1856 req.hds_threshold = rte_cpu_to_le_16(pmode->hds_threshold);
1857 req.enables = rte_cpu_to_le_32(
1858 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_HDS_THRESHOLD_VALID |
1859 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_HDS_OFFSET_VALID |
1860 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_JUMBO_THRESH_VALID
1863 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1865 HWRM_CHECK_RESULT();
1871 int bnxt_hwrm_vnic_cfg(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1874 struct hwrm_vnic_cfg_input req = {.req_type = 0 };
1875 struct hwrm_vnic_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1876 struct bnxt_plcmodes_cfg pmodes = { 0 };
1877 uint32_t ctx_enable_flag = 0;
1878 uint32_t enables = 0;
1880 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1881 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
1885 rc = bnxt_hwrm_vnic_plcmodes_qcfg(bp, vnic, &pmodes);
1889 HWRM_PREP(&req, HWRM_VNIC_CFG, BNXT_USE_CHIMP_MB);
1891 if (BNXT_CHIP_THOR(bp)) {
1892 int dflt_rxq = vnic->start_grp_id;
1893 struct bnxt_rx_ring_info *rxr;
1894 struct bnxt_cp_ring_info *cpr;
1895 struct bnxt_rx_queue *rxq;
1899 * The first active receive ring is used as the VNIC
1900 * default receive ring. If there are no active receive
1901 * rings (all corresponding receive queues are stopped),
1902 * the first receive ring is used.
1904 for (i = vnic->start_grp_id; i < vnic->end_grp_id; i++) {
1905 rxq = bp->eth_dev->data->rx_queues[i];
1906 if (rxq->rx_started) {
1912 rxq = bp->eth_dev->data->rx_queues[dflt_rxq];
1916 req.default_rx_ring_id =
1917 rte_cpu_to_le_16(rxr->rx_ring_struct->fw_ring_id);
1918 req.default_cmpl_ring_id =
1919 rte_cpu_to_le_16(cpr->cp_ring_struct->fw_ring_id);
1920 enables = HWRM_VNIC_CFG_INPUT_ENABLES_DEFAULT_RX_RING_ID |
1921 HWRM_VNIC_CFG_INPUT_ENABLES_DEFAULT_CMPL_RING_ID;
1925 /* Only RSS support for now TBD: COS & LB */
1926 enables = HWRM_VNIC_CFG_INPUT_ENABLES_DFLT_RING_GRP;
1927 if (vnic->lb_rule != 0xffff)
1928 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_LB_RULE;
1929 if (vnic->cos_rule != 0xffff)
1930 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_COS_RULE;
1931 if (vnic->rss_rule != (uint16_t)HWRM_NA_SIGNATURE) {
1932 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_MRU;
1933 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_RSS_RULE;
1935 if (bp->vnic_cap_flags & BNXT_VNIC_CAP_COS_CLASSIFY) {
1936 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_QUEUE_ID;
1937 req.queue_id = rte_cpu_to_le_16(vnic->cos_queue_id);
1940 enables |= ctx_enable_flag;
1941 req.dflt_ring_grp = rte_cpu_to_le_16(vnic->dflt_ring_grp);
1942 req.rss_rule = rte_cpu_to_le_16(vnic->rss_rule);
1943 req.cos_rule = rte_cpu_to_le_16(vnic->cos_rule);
1944 req.lb_rule = rte_cpu_to_le_16(vnic->lb_rule);
1947 req.enables = rte_cpu_to_le_32(enables);
1948 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1949 req.mru = rte_cpu_to_le_16(vnic->mru);
1950 /* Configure default VNIC only once. */
1951 if (vnic->func_default && !(bp->flags & BNXT_FLAG_DFLT_VNIC_SET)) {
1953 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_DEFAULT);
1954 bp->flags |= BNXT_FLAG_DFLT_VNIC_SET;
1956 if (vnic->vlan_strip)
1958 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_VLAN_STRIP_MODE);
1961 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_BD_STALL_MODE);
1962 if (vnic->roce_dual)
1963 req.flags |= rte_cpu_to_le_32(
1964 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_DUAL_VNIC_MODE);
1965 if (vnic->roce_only)
1966 req.flags |= rte_cpu_to_le_32(
1967 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_ONLY_VNIC_MODE);
1968 if (vnic->rss_dflt_cr)
1969 req.flags |= rte_cpu_to_le_32(
1970 HWRM_VNIC_QCFG_OUTPUT_FLAGS_RSS_DFLT_CR_MODE);
1972 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1974 HWRM_CHECK_RESULT();
1977 rc = bnxt_hwrm_vnic_plcmodes_cfg(bp, vnic, &pmodes);
1982 int bnxt_hwrm_vnic_qcfg(struct bnxt *bp, struct bnxt_vnic_info *vnic,
1986 struct hwrm_vnic_qcfg_input req = {.req_type = 0 };
1987 struct hwrm_vnic_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
1989 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1990 PMD_DRV_LOG(DEBUG, "VNIC QCFG ID %d\n", vnic->fw_vnic_id);
1993 HWRM_PREP(&req, HWRM_VNIC_QCFG, BNXT_USE_CHIMP_MB);
1996 rte_cpu_to_le_32(HWRM_VNIC_QCFG_INPUT_ENABLES_VF_ID_VALID);
1997 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1998 req.vf_id = rte_cpu_to_le_16(fw_vf_id);
2000 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2002 HWRM_CHECK_RESULT();
2004 vnic->dflt_ring_grp = rte_le_to_cpu_16(resp->dflt_ring_grp);
2005 vnic->rss_rule = rte_le_to_cpu_16(resp->rss_rule);
2006 vnic->cos_rule = rte_le_to_cpu_16(resp->cos_rule);
2007 vnic->lb_rule = rte_le_to_cpu_16(resp->lb_rule);
2008 vnic->mru = rte_le_to_cpu_16(resp->mru);
2009 vnic->func_default = rte_le_to_cpu_32(
2010 resp->flags) & HWRM_VNIC_QCFG_OUTPUT_FLAGS_DEFAULT;
2011 vnic->vlan_strip = rte_le_to_cpu_32(resp->flags) &
2012 HWRM_VNIC_QCFG_OUTPUT_FLAGS_VLAN_STRIP_MODE;
2013 vnic->bd_stall = rte_le_to_cpu_32(resp->flags) &
2014 HWRM_VNIC_QCFG_OUTPUT_FLAGS_BD_STALL_MODE;
2015 vnic->roce_dual = rte_le_to_cpu_32(resp->flags) &
2016 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_DUAL_VNIC_MODE;
2017 vnic->roce_only = rte_le_to_cpu_32(resp->flags) &
2018 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_ONLY_VNIC_MODE;
2019 vnic->rss_dflt_cr = rte_le_to_cpu_32(resp->flags) &
2020 HWRM_VNIC_QCFG_OUTPUT_FLAGS_RSS_DFLT_CR_MODE;
2027 int bnxt_hwrm_vnic_ctx_alloc(struct bnxt *bp,
2028 struct bnxt_vnic_info *vnic, uint16_t ctx_idx)
2032 struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req = {.req_type = 0 };
2033 struct hwrm_vnic_rss_cos_lb_ctx_alloc_output *resp =
2034 bp->hwrm_cmd_resp_addr;
2036 HWRM_PREP(&req, HWRM_VNIC_RSS_COS_LB_CTX_ALLOC, BNXT_USE_CHIMP_MB);
2038 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2039 HWRM_CHECK_RESULT();
2041 ctx_id = rte_le_to_cpu_16(resp->rss_cos_lb_ctx_id);
2042 if (!BNXT_HAS_RING_GRPS(bp))
2043 vnic->fw_grp_ids[ctx_idx] = ctx_id;
2044 else if (ctx_idx == 0)
2045 vnic->rss_rule = ctx_id;
2053 int _bnxt_hwrm_vnic_ctx_free(struct bnxt *bp,
2054 struct bnxt_vnic_info *vnic, uint16_t ctx_idx)
2057 struct hwrm_vnic_rss_cos_lb_ctx_free_input req = {.req_type = 0 };
2058 struct hwrm_vnic_rss_cos_lb_ctx_free_output *resp =
2059 bp->hwrm_cmd_resp_addr;
2061 if (ctx_idx == (uint16_t)HWRM_NA_SIGNATURE) {
2062 PMD_DRV_LOG(DEBUG, "VNIC RSS Rule %x\n", vnic->rss_rule);
2065 HWRM_PREP(&req, HWRM_VNIC_RSS_COS_LB_CTX_FREE, BNXT_USE_CHIMP_MB);
2067 req.rss_cos_lb_ctx_id = rte_cpu_to_le_16(ctx_idx);
2069 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2071 HWRM_CHECK_RESULT();
2077 int bnxt_hwrm_vnic_ctx_free(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2081 if (BNXT_CHIP_THOR(bp)) {
2084 for (j = 0; j < vnic->num_lb_ctxts; j++) {
2085 rc = _bnxt_hwrm_vnic_ctx_free(bp,
2087 vnic->fw_grp_ids[j]);
2088 vnic->fw_grp_ids[j] = INVALID_HW_RING_ID;
2090 vnic->num_lb_ctxts = 0;
2092 rc = _bnxt_hwrm_vnic_ctx_free(bp, vnic, vnic->rss_rule);
2093 vnic->rss_rule = INVALID_HW_RING_ID;
2099 int bnxt_hwrm_vnic_free(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2102 struct hwrm_vnic_free_input req = {.req_type = 0 };
2103 struct hwrm_vnic_free_output *resp = bp->hwrm_cmd_resp_addr;
2105 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
2106 PMD_DRV_LOG(DEBUG, "VNIC FREE ID %x\n", vnic->fw_vnic_id);
2110 HWRM_PREP(&req, HWRM_VNIC_FREE, BNXT_USE_CHIMP_MB);
2112 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
2114 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2116 HWRM_CHECK_RESULT();
2119 vnic->fw_vnic_id = INVALID_HW_RING_ID;
2120 /* Configure default VNIC again if necessary. */
2121 if (vnic->func_default && (bp->flags & BNXT_FLAG_DFLT_VNIC_SET))
2122 bp->flags &= ~BNXT_FLAG_DFLT_VNIC_SET;
2128 bnxt_hwrm_vnic_rss_cfg_thor(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2132 int nr_ctxs = vnic->num_lb_ctxts;
2133 struct hwrm_vnic_rss_cfg_input req = {.req_type = 0 };
2134 struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2136 for (i = 0; i < nr_ctxs; i++) {
2137 HWRM_PREP(&req, HWRM_VNIC_RSS_CFG, BNXT_USE_CHIMP_MB);
2139 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
2140 req.hash_type = rte_cpu_to_le_32(vnic->hash_type);
2141 req.hash_mode_flags = vnic->hash_mode;
2143 req.hash_key_tbl_addr =
2144 rte_cpu_to_le_64(vnic->rss_hash_key_dma_addr);
2146 req.ring_grp_tbl_addr =
2147 rte_cpu_to_le_64(vnic->rss_table_dma_addr +
2148 i * HW_HASH_INDEX_SIZE);
2149 req.ring_table_pair_index = i;
2150 req.rss_ctx_idx = rte_cpu_to_le_16(vnic->fw_grp_ids[i]);
2152 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req),
2155 HWRM_CHECK_RESULT();
2162 int bnxt_hwrm_vnic_rss_cfg(struct bnxt *bp,
2163 struct bnxt_vnic_info *vnic)
2166 struct hwrm_vnic_rss_cfg_input req = {.req_type = 0 };
2167 struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2169 if (!vnic->rss_table)
2172 if (BNXT_CHIP_THOR(bp))
2173 return bnxt_hwrm_vnic_rss_cfg_thor(bp, vnic);
2175 HWRM_PREP(&req, HWRM_VNIC_RSS_CFG, BNXT_USE_CHIMP_MB);
2177 req.hash_type = rte_cpu_to_le_32(vnic->hash_type);
2178 req.hash_mode_flags = vnic->hash_mode;
2180 req.ring_grp_tbl_addr =
2181 rte_cpu_to_le_64(vnic->rss_table_dma_addr);
2182 req.hash_key_tbl_addr =
2183 rte_cpu_to_le_64(vnic->rss_hash_key_dma_addr);
2184 req.rss_ctx_idx = rte_cpu_to_le_16(vnic->rss_rule);
2185 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
2187 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2189 HWRM_CHECK_RESULT();
2195 int bnxt_hwrm_vnic_plcmode_cfg(struct bnxt *bp,
2196 struct bnxt_vnic_info *vnic)
2199 struct hwrm_vnic_plcmodes_cfg_input req = {.req_type = 0 };
2200 struct hwrm_vnic_plcmodes_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2203 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
2204 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
2208 HWRM_PREP(&req, HWRM_VNIC_PLCMODES_CFG, BNXT_USE_CHIMP_MB);
2210 req.flags = rte_cpu_to_le_32(
2211 HWRM_VNIC_PLCMODES_CFG_INPUT_FLAGS_JUMBO_PLACEMENT);
2213 req.enables = rte_cpu_to_le_32(
2214 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_JUMBO_THRESH_VALID);
2216 size = rte_pktmbuf_data_room_size(bp->rx_queues[0]->mb_pool);
2217 size -= RTE_PKTMBUF_HEADROOM;
2218 size = RTE_MIN(BNXT_MAX_PKT_LEN, size);
2220 req.jumbo_thresh = rte_cpu_to_le_16(size);
2221 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
2223 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2225 HWRM_CHECK_RESULT();
2231 int bnxt_hwrm_vnic_tpa_cfg(struct bnxt *bp,
2232 struct bnxt_vnic_info *vnic, bool enable)
2235 struct hwrm_vnic_tpa_cfg_input req = {.req_type = 0 };
2236 struct hwrm_vnic_tpa_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2238 if (BNXT_CHIP_THOR(bp) && !bp->max_tpa_v2) {
2240 PMD_DRV_LOG(ERR, "No HW support for LRO\n");
2244 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
2245 PMD_DRV_LOG(DEBUG, "Invalid vNIC ID\n");
2249 HWRM_PREP(&req, HWRM_VNIC_TPA_CFG, BNXT_USE_CHIMP_MB);
2252 req.enables = rte_cpu_to_le_32(
2253 HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MAX_AGG_SEGS |
2254 HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MAX_AGGS |
2255 HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MIN_AGG_LEN);
2256 req.flags = rte_cpu_to_le_32(
2257 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_TPA |
2258 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_ENCAP_TPA |
2259 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_RSC_WND_UPDATE |
2260 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_GRO |
2261 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_AGG_WITH_ECN |
2262 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_AGG_WITH_SAME_GRE_SEQ);
2263 req.max_agg_segs = rte_cpu_to_le_16(BNXT_TPA_MAX_AGGS(bp));
2264 req.max_aggs = rte_cpu_to_le_16(BNXT_TPA_MAX_SEGS(bp));
2265 req.min_agg_len = rte_cpu_to_le_32(512);
2267 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
2269 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2271 HWRM_CHECK_RESULT();
2277 int bnxt_hwrm_func_vf_mac(struct bnxt *bp, uint16_t vf, const uint8_t *mac_addr)
2279 struct hwrm_func_cfg_input req = {0};
2280 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2283 req.flags = rte_cpu_to_le_32(bp->pf->vf_info[vf].func_cfg_flags);
2284 req.enables = rte_cpu_to_le_32(
2285 HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
2286 memcpy(req.dflt_mac_addr, mac_addr, sizeof(req.dflt_mac_addr));
2287 req.fid = rte_cpu_to_le_16(bp->pf->vf_info[vf].fid);
2289 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
2291 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2292 HWRM_CHECK_RESULT();
2295 bp->pf->vf_info[vf].random_mac = false;
2300 int bnxt_hwrm_func_qstats_tx_drop(struct bnxt *bp, uint16_t fid,
2304 struct hwrm_func_qstats_input req = {.req_type = 0};
2305 struct hwrm_func_qstats_output *resp = bp->hwrm_cmd_resp_addr;
2307 HWRM_PREP(&req, HWRM_FUNC_QSTATS, 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();
2316 *dropped = rte_le_to_cpu_64(resp->tx_drop_pkts);
2323 int bnxt_hwrm_func_qstats(struct bnxt *bp, uint16_t fid,
2324 struct rte_eth_stats *stats,
2325 struct hwrm_func_qstats_output *func_qstats)
2328 struct hwrm_func_qstats_input req = {.req_type = 0};
2329 struct hwrm_func_qstats_output *resp = bp->hwrm_cmd_resp_addr;
2331 HWRM_PREP(&req, HWRM_FUNC_QSTATS, BNXT_USE_CHIMP_MB);
2333 req.fid = rte_cpu_to_le_16(fid);
2335 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2337 HWRM_CHECK_RESULT();
2339 memcpy(func_qstats, resp,
2340 sizeof(struct hwrm_func_qstats_output));
2345 stats->ipackets = rte_le_to_cpu_64(resp->rx_ucast_pkts);
2346 stats->ipackets += rte_le_to_cpu_64(resp->rx_mcast_pkts);
2347 stats->ipackets += rte_le_to_cpu_64(resp->rx_bcast_pkts);
2348 stats->ibytes = rte_le_to_cpu_64(resp->rx_ucast_bytes);
2349 stats->ibytes += rte_le_to_cpu_64(resp->rx_mcast_bytes);
2350 stats->ibytes += rte_le_to_cpu_64(resp->rx_bcast_bytes);
2352 stats->opackets = rte_le_to_cpu_64(resp->tx_ucast_pkts);
2353 stats->opackets += rte_le_to_cpu_64(resp->tx_mcast_pkts);
2354 stats->opackets += rte_le_to_cpu_64(resp->tx_bcast_pkts);
2355 stats->obytes = rte_le_to_cpu_64(resp->tx_ucast_bytes);
2356 stats->obytes += rte_le_to_cpu_64(resp->tx_mcast_bytes);
2357 stats->obytes += rte_le_to_cpu_64(resp->tx_bcast_bytes);
2359 stats->imissed = rte_le_to_cpu_64(resp->rx_discard_pkts);
2360 stats->ierrors = rte_le_to_cpu_64(resp->rx_drop_pkts);
2361 stats->oerrors = rte_le_to_cpu_64(resp->tx_discard_pkts);
2369 int bnxt_hwrm_func_clr_stats(struct bnxt *bp, uint16_t fid)
2372 struct hwrm_func_clr_stats_input req = {.req_type = 0};
2373 struct hwrm_func_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
2375 HWRM_PREP(&req, HWRM_FUNC_CLR_STATS, BNXT_USE_CHIMP_MB);
2377 req.fid = rte_cpu_to_le_16(fid);
2379 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2381 HWRM_CHECK_RESULT();
2387 int bnxt_clear_all_hwrm_stat_ctxs(struct bnxt *bp)
2392 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
2393 struct bnxt_tx_queue *txq;
2394 struct bnxt_rx_queue *rxq;
2395 struct bnxt_cp_ring_info *cpr;
2397 if (i >= bp->rx_cp_nr_rings) {
2398 txq = bp->tx_queues[i - bp->rx_cp_nr_rings];
2401 rxq = bp->rx_queues[i];
2405 rc = bnxt_hwrm_stat_clear(bp, cpr);
2413 bnxt_free_all_hwrm_stat_ctxs(struct bnxt *bp)
2417 struct bnxt_cp_ring_info *cpr;
2419 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
2421 if (i >= bp->rx_cp_nr_rings) {
2422 cpr = bp->tx_queues[i - bp->rx_cp_nr_rings]->cp_ring;
2424 cpr = bp->rx_queues[i]->cp_ring;
2425 if (BNXT_HAS_RING_GRPS(bp))
2426 bp->grp_info[i].fw_stats_ctx = -1;
2428 if (cpr->hw_stats_ctx_id != HWRM_NA_SIGNATURE) {
2429 rc = bnxt_hwrm_stat_ctx_free(bp, cpr, i);
2430 cpr->hw_stats_ctx_id = HWRM_NA_SIGNATURE;
2438 int bnxt_alloc_all_hwrm_stat_ctxs(struct bnxt *bp)
2443 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
2444 struct bnxt_tx_queue *txq;
2445 struct bnxt_rx_queue *rxq;
2446 struct bnxt_cp_ring_info *cpr;
2448 if (i >= bp->rx_cp_nr_rings) {
2449 txq = bp->tx_queues[i - bp->rx_cp_nr_rings];
2452 rxq = bp->rx_queues[i];
2456 rc = bnxt_hwrm_stat_ctx_alloc(bp, cpr, i);
2465 bnxt_free_all_hwrm_ring_grps(struct bnxt *bp)
2470 if (!BNXT_HAS_RING_GRPS(bp))
2473 for (idx = 0; idx < bp->rx_cp_nr_rings; idx++) {
2475 if (bp->grp_info[idx].fw_grp_id == INVALID_HW_RING_ID)
2478 rc = bnxt_hwrm_ring_grp_free(bp, idx);
2486 void bnxt_free_nq_ring(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
2488 struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
2490 bnxt_hwrm_ring_free(bp, cp_ring,
2491 HWRM_RING_FREE_INPUT_RING_TYPE_NQ);
2492 cp_ring->fw_ring_id = INVALID_HW_RING_ID;
2493 memset(cpr->cp_desc_ring, 0, cpr->cp_ring_struct->ring_size *
2494 sizeof(*cpr->cp_desc_ring));
2495 cpr->cp_raw_cons = 0;
2499 void bnxt_free_cp_ring(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
2501 struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
2503 bnxt_hwrm_ring_free(bp, cp_ring,
2504 HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL);
2505 cp_ring->fw_ring_id = INVALID_HW_RING_ID;
2506 memset(cpr->cp_desc_ring, 0, cpr->cp_ring_struct->ring_size *
2507 sizeof(*cpr->cp_desc_ring));
2508 cpr->cp_raw_cons = 0;
2512 void bnxt_free_hwrm_rx_ring(struct bnxt *bp, int queue_index)
2514 struct bnxt_rx_queue *rxq = bp->rx_queues[queue_index];
2515 struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
2516 struct bnxt_ring *ring = rxr->rx_ring_struct;
2517 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
2519 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
2520 bnxt_hwrm_ring_free(bp, ring,
2521 HWRM_RING_FREE_INPUT_RING_TYPE_RX);
2522 ring->fw_ring_id = INVALID_HW_RING_ID;
2523 if (BNXT_HAS_RING_GRPS(bp))
2524 bp->grp_info[queue_index].rx_fw_ring_id =
2527 ring = rxr->ag_ring_struct;
2528 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
2529 bnxt_hwrm_ring_free(bp, ring,
2530 BNXT_CHIP_THOR(bp) ?
2531 HWRM_RING_FREE_INPUT_RING_TYPE_RX_AGG :
2532 HWRM_RING_FREE_INPUT_RING_TYPE_RX);
2533 if (BNXT_HAS_RING_GRPS(bp))
2534 bp->grp_info[queue_index].ag_fw_ring_id =
2537 if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID)
2538 bnxt_free_cp_ring(bp, cpr);
2540 if (BNXT_HAS_RING_GRPS(bp))
2541 bp->grp_info[queue_index].cp_fw_ring_id = INVALID_HW_RING_ID;
2545 bnxt_free_all_hwrm_rings(struct bnxt *bp)
2549 for (i = 0; i < bp->tx_cp_nr_rings; i++) {
2550 struct bnxt_tx_queue *txq = bp->tx_queues[i];
2551 struct bnxt_tx_ring_info *txr = txq->tx_ring;
2552 struct bnxt_ring *ring = txr->tx_ring_struct;
2553 struct bnxt_cp_ring_info *cpr = txq->cp_ring;
2555 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
2556 bnxt_hwrm_ring_free(bp, ring,
2557 HWRM_RING_FREE_INPUT_RING_TYPE_TX);
2558 ring->fw_ring_id = INVALID_HW_RING_ID;
2559 memset(txr->tx_desc_ring, 0,
2560 txr->tx_ring_struct->ring_size *
2561 sizeof(*txr->tx_desc_ring));
2562 memset(txr->tx_buf_ring, 0,
2563 txr->tx_ring_struct->ring_size *
2564 sizeof(*txr->tx_buf_ring));
2568 if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID) {
2569 bnxt_free_cp_ring(bp, cpr);
2570 cpr->cp_ring_struct->fw_ring_id = INVALID_HW_RING_ID;
2574 for (i = 0; i < bp->rx_cp_nr_rings; i++)
2575 bnxt_free_hwrm_rx_ring(bp, i);
2580 int bnxt_alloc_all_hwrm_ring_grps(struct bnxt *bp)
2585 if (!BNXT_HAS_RING_GRPS(bp))
2588 for (i = 0; i < bp->rx_cp_nr_rings; i++) {
2589 rc = bnxt_hwrm_ring_grp_alloc(bp, i);
2597 * HWRM utility functions
2600 void bnxt_free_hwrm_resources(struct bnxt *bp)
2602 /* Release memzone */
2603 rte_free(bp->hwrm_cmd_resp_addr);
2604 rte_free(bp->hwrm_short_cmd_req_addr);
2605 bp->hwrm_cmd_resp_addr = NULL;
2606 bp->hwrm_short_cmd_req_addr = NULL;
2607 bp->hwrm_cmd_resp_dma_addr = 0;
2608 bp->hwrm_short_cmd_req_dma_addr = 0;
2611 int bnxt_alloc_hwrm_resources(struct bnxt *bp)
2613 struct rte_pci_device *pdev = bp->pdev;
2614 char type[RTE_MEMZONE_NAMESIZE];
2616 sprintf(type, "bnxt_hwrm_" PCI_PRI_FMT, pdev->addr.domain,
2617 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
2618 bp->max_resp_len = HWRM_MAX_RESP_LEN;
2619 bp->hwrm_cmd_resp_addr = rte_malloc(type, bp->max_resp_len, 0);
2620 if (bp->hwrm_cmd_resp_addr == NULL)
2622 bp->hwrm_cmd_resp_dma_addr =
2623 rte_malloc_virt2iova(bp->hwrm_cmd_resp_addr);
2624 if (bp->hwrm_cmd_resp_dma_addr == RTE_BAD_IOVA) {
2626 "unable to map response address to physical memory\n");
2629 rte_spinlock_init(&bp->hwrm_lock);
2635 bnxt_clear_one_vnic_filter(struct bnxt *bp, struct bnxt_filter_info *filter)
2639 if (filter->filter_type == HWRM_CFA_EM_FILTER) {
2640 rc = bnxt_hwrm_clear_em_filter(bp, filter);
2643 } else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER) {
2644 rc = bnxt_hwrm_clear_ntuple_filter(bp, filter);
2649 rc = bnxt_hwrm_clear_l2_filter(bp, filter);
2654 bnxt_clear_hwrm_vnic_filters(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2656 struct bnxt_filter_info *filter;
2659 STAILQ_FOREACH(filter, &vnic->filter, next) {
2660 rc = bnxt_clear_one_vnic_filter(bp, filter);
2661 STAILQ_REMOVE(&vnic->filter, filter, bnxt_filter_info, next);
2662 bnxt_free_filter(bp, filter);
2668 bnxt_clear_hwrm_vnic_flows(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2670 struct bnxt_filter_info *filter;
2671 struct rte_flow *flow;
2674 while (!STAILQ_EMPTY(&vnic->flow_list)) {
2675 flow = STAILQ_FIRST(&vnic->flow_list);
2676 filter = flow->filter;
2677 PMD_DRV_LOG(DEBUG, "filter type %d\n", filter->filter_type);
2678 rc = bnxt_clear_one_vnic_filter(bp, filter);
2680 STAILQ_REMOVE(&vnic->flow_list, flow, rte_flow, next);
2686 int bnxt_set_hwrm_vnic_filters(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2688 struct bnxt_filter_info *filter;
2691 STAILQ_FOREACH(filter, &vnic->filter, next) {
2692 if (filter->filter_type == HWRM_CFA_EM_FILTER)
2693 rc = bnxt_hwrm_set_em_filter(bp, filter->dst_id,
2695 else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
2696 rc = bnxt_hwrm_set_ntuple_filter(bp, filter->dst_id,
2699 rc = bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id,
2708 bnxt_free_tunnel_ports(struct bnxt *bp)
2710 if (bp->vxlan_port_cnt)
2711 bnxt_hwrm_tunnel_dst_port_free(bp, bp->vxlan_fw_dst_port_id,
2712 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_VXLAN);
2714 if (bp->geneve_port_cnt)
2715 bnxt_hwrm_tunnel_dst_port_free(bp, bp->geneve_fw_dst_port_id,
2716 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_GENEVE);
2717 bp->geneve_port = 0;
2720 void bnxt_free_all_hwrm_resources(struct bnxt *bp)
2724 if (bp->vnic_info == NULL)
2728 * Cleanup VNICs in reverse order, to make sure the L2 filter
2729 * from vnic0 is last to be cleaned up.
2731 for (i = bp->max_vnics - 1; i >= 0; i--) {
2732 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
2734 if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
2737 bnxt_clear_hwrm_vnic_flows(bp, vnic);
2739 bnxt_clear_hwrm_vnic_filters(bp, vnic);
2741 bnxt_hwrm_vnic_ctx_free(bp, vnic);
2743 bnxt_hwrm_vnic_tpa_cfg(bp, vnic, false);
2745 bnxt_hwrm_vnic_free(bp, vnic);
2747 rte_free(vnic->fw_grp_ids);
2749 /* Ring resources */
2750 bnxt_free_all_hwrm_rings(bp);
2751 bnxt_free_all_hwrm_ring_grps(bp);
2752 bnxt_free_all_hwrm_stat_ctxs(bp);
2753 bnxt_free_tunnel_ports(bp);
2756 static uint16_t bnxt_parse_eth_link_duplex(uint32_t conf_link_speed)
2758 uint8_t hw_link_duplex = HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH;
2760 if ((conf_link_speed & ETH_LINK_SPEED_FIXED) == ETH_LINK_SPEED_AUTONEG)
2761 return HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH;
2763 switch (conf_link_speed) {
2764 case ETH_LINK_SPEED_10M_HD:
2765 case ETH_LINK_SPEED_100M_HD:
2767 return HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_HALF;
2769 return hw_link_duplex;
2772 static uint16_t bnxt_check_eth_link_autoneg(uint32_t conf_link)
2774 return (conf_link & ETH_LINK_SPEED_FIXED) ? 0 : 1;
2777 static uint16_t bnxt_parse_eth_link_speed(uint32_t conf_link_speed)
2779 uint16_t eth_link_speed = 0;
2781 if (conf_link_speed == ETH_LINK_SPEED_AUTONEG)
2782 return ETH_LINK_SPEED_AUTONEG;
2784 switch (conf_link_speed & ~ETH_LINK_SPEED_FIXED) {
2785 case ETH_LINK_SPEED_100M:
2786 case ETH_LINK_SPEED_100M_HD:
2789 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_100MB;
2791 case ETH_LINK_SPEED_1G:
2793 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_1GB;
2795 case ETH_LINK_SPEED_2_5G:
2797 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_2_5GB;
2799 case ETH_LINK_SPEED_10G:
2801 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_10GB;
2803 case ETH_LINK_SPEED_20G:
2805 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_20GB;
2807 case ETH_LINK_SPEED_25G:
2809 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_25GB;
2811 case ETH_LINK_SPEED_40G:
2813 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_40GB;
2815 case ETH_LINK_SPEED_50G:
2817 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_50GB;
2819 case ETH_LINK_SPEED_100G:
2821 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_100GB;
2823 case ETH_LINK_SPEED_200G:
2825 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_200GB;
2829 "Unsupported link speed %d; default to AUTO\n",
2833 return eth_link_speed;
2836 #define BNXT_SUPPORTED_SPEEDS (ETH_LINK_SPEED_100M | ETH_LINK_SPEED_100M_HD | \
2837 ETH_LINK_SPEED_1G | ETH_LINK_SPEED_2_5G | \
2838 ETH_LINK_SPEED_10G | ETH_LINK_SPEED_20G | ETH_LINK_SPEED_25G | \
2839 ETH_LINK_SPEED_40G | ETH_LINK_SPEED_50G | \
2840 ETH_LINK_SPEED_100G | ETH_LINK_SPEED_200G)
2842 static int bnxt_validate_link_speed(struct bnxt *bp)
2844 uint32_t link_speed = bp->eth_dev->data->dev_conf.link_speeds;
2845 uint16_t port_id = bp->eth_dev->data->port_id;
2846 uint32_t link_speed_capa;
2849 if (link_speed == ETH_LINK_SPEED_AUTONEG)
2852 link_speed_capa = bnxt_get_speed_capabilities(bp);
2854 if (link_speed & ETH_LINK_SPEED_FIXED) {
2855 one_speed = link_speed & ~ETH_LINK_SPEED_FIXED;
2857 if (one_speed & (one_speed - 1)) {
2859 "Invalid advertised speeds (%u) for port %u\n",
2860 link_speed, port_id);
2863 if ((one_speed & link_speed_capa) != one_speed) {
2865 "Unsupported advertised speed (%u) for port %u\n",
2866 link_speed, port_id);
2870 if (!(link_speed & link_speed_capa)) {
2872 "Unsupported advertised speeds (%u) for port %u\n",
2873 link_speed, port_id);
2881 bnxt_parse_eth_link_speed_mask(struct bnxt *bp, uint32_t link_speed)
2885 if (link_speed == ETH_LINK_SPEED_AUTONEG) {
2886 if (bp->link_info->support_speeds)
2887 return bp->link_info->support_speeds;
2888 link_speed = BNXT_SUPPORTED_SPEEDS;
2891 if (link_speed & ETH_LINK_SPEED_100M)
2892 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100MB;
2893 if (link_speed & ETH_LINK_SPEED_100M_HD)
2894 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100MB;
2895 if (link_speed & ETH_LINK_SPEED_1G)
2896 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_1GB;
2897 if (link_speed & ETH_LINK_SPEED_2_5G)
2898 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_2_5GB;
2899 if (link_speed & ETH_LINK_SPEED_10G)
2900 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_10GB;
2901 if (link_speed & ETH_LINK_SPEED_20G)
2902 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_20GB;
2903 if (link_speed & ETH_LINK_SPEED_25G)
2904 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_25GB;
2905 if (link_speed & ETH_LINK_SPEED_40G)
2906 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_40GB;
2907 if (link_speed & ETH_LINK_SPEED_50G)
2908 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_50GB;
2909 if (link_speed & ETH_LINK_SPEED_100G)
2910 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100GB;
2911 if (link_speed & ETH_LINK_SPEED_200G)
2912 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_200GB;
2916 static uint32_t bnxt_parse_hw_link_speed(uint16_t hw_link_speed)
2918 uint32_t eth_link_speed = ETH_SPEED_NUM_NONE;
2920 switch (hw_link_speed) {
2921 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100MB:
2922 eth_link_speed = ETH_SPEED_NUM_100M;
2924 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_1GB:
2925 eth_link_speed = ETH_SPEED_NUM_1G;
2927 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2_5GB:
2928 eth_link_speed = ETH_SPEED_NUM_2_5G;
2930 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_10GB:
2931 eth_link_speed = ETH_SPEED_NUM_10G;
2933 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_20GB:
2934 eth_link_speed = ETH_SPEED_NUM_20G;
2936 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_25GB:
2937 eth_link_speed = ETH_SPEED_NUM_25G;
2939 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_40GB:
2940 eth_link_speed = ETH_SPEED_NUM_40G;
2942 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_50GB:
2943 eth_link_speed = ETH_SPEED_NUM_50G;
2945 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100GB:
2946 eth_link_speed = ETH_SPEED_NUM_100G;
2948 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_200GB:
2949 eth_link_speed = ETH_SPEED_NUM_200G;
2951 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2GB:
2953 PMD_DRV_LOG(ERR, "HWRM link speed %d not defined\n",
2957 return eth_link_speed;
2960 static uint16_t bnxt_parse_hw_link_duplex(uint16_t hw_link_duplex)
2962 uint16_t eth_link_duplex = ETH_LINK_FULL_DUPLEX;
2964 switch (hw_link_duplex) {
2965 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH:
2966 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_FULL:
2968 eth_link_duplex = ETH_LINK_FULL_DUPLEX;
2970 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_HALF:
2971 eth_link_duplex = ETH_LINK_HALF_DUPLEX;
2974 PMD_DRV_LOG(ERR, "HWRM link duplex %d not defined\n",
2978 return eth_link_duplex;
2981 int bnxt_get_hwrm_link_config(struct bnxt *bp, struct rte_eth_link *link)
2984 struct bnxt_link_info *link_info = bp->link_info;
2986 rc = bnxt_hwrm_port_phy_qcfg(bp, link_info);
2989 "Get link config failed with rc %d\n", rc);
2992 if (link_info->link_speed)
2994 bnxt_parse_hw_link_speed(link_info->link_speed);
2996 link->link_speed = ETH_SPEED_NUM_NONE;
2997 link->link_duplex = bnxt_parse_hw_link_duplex(link_info->duplex);
2998 link->link_status = link_info->link_up;
2999 link->link_autoneg = link_info->auto_mode ==
3000 HWRM_PORT_PHY_QCFG_OUTPUT_AUTO_MODE_NONE ?
3001 ETH_LINK_FIXED : ETH_LINK_AUTONEG;
3006 int bnxt_set_hwrm_link_config(struct bnxt *bp, bool link_up)
3009 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
3010 struct bnxt_link_info link_req;
3011 uint16_t speed, autoneg;
3013 if (!BNXT_SINGLE_PF(bp) || BNXT_VF(bp))
3016 rc = bnxt_validate_link_speed(bp);
3020 memset(&link_req, 0, sizeof(link_req));
3021 link_req.link_up = link_up;
3025 autoneg = bnxt_check_eth_link_autoneg(dev_conf->link_speeds);
3026 if (BNXT_CHIP_THOR(bp) &&
3027 dev_conf->link_speeds == ETH_LINK_SPEED_40G) {
3028 /* 40G is not supported as part of media auto detect.
3029 * The speed should be forced and autoneg disabled
3030 * to configure 40G speed.
3032 PMD_DRV_LOG(INFO, "Disabling autoneg for 40G\n");
3036 speed = bnxt_parse_eth_link_speed(dev_conf->link_speeds);
3037 link_req.phy_flags = HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESET_PHY;
3038 /* Autoneg can be done only when the FW allows.
3039 * When user configures fixed speed of 40G and later changes to
3040 * any other speed, auto_link_speed/force_link_speed is still set
3041 * to 40G until link comes up at new speed.
3044 !(!BNXT_CHIP_THOR(bp) &&
3045 (bp->link_info->auto_link_speed ||
3046 bp->link_info->force_link_speed))) {
3047 link_req.phy_flags |=
3048 HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESTART_AUTONEG;
3049 link_req.auto_link_speed_mask =
3050 bnxt_parse_eth_link_speed_mask(bp,
3051 dev_conf->link_speeds);
3053 if (bp->link_info->phy_type ==
3054 HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET ||
3055 bp->link_info->phy_type ==
3056 HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASETE ||
3057 bp->link_info->media_type ==
3058 HWRM_PORT_PHY_QCFG_OUTPUT_MEDIA_TYPE_TP) {
3059 PMD_DRV_LOG(ERR, "10GBase-T devices must autoneg\n");
3063 link_req.phy_flags |= HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE;
3064 /* If user wants a particular speed try that first. */
3066 link_req.link_speed = speed;
3067 else if (bp->link_info->force_link_speed)
3068 link_req.link_speed = bp->link_info->force_link_speed;
3070 link_req.link_speed = bp->link_info->auto_link_speed;
3072 link_req.duplex = bnxt_parse_eth_link_duplex(dev_conf->link_speeds);
3073 link_req.auto_pause = bp->link_info->auto_pause;
3074 link_req.force_pause = bp->link_info->force_pause;
3077 rc = bnxt_hwrm_port_phy_cfg(bp, &link_req);
3080 "Set link config failed with rc %d\n", rc);
3088 int bnxt_hwrm_func_qcfg(struct bnxt *bp, uint16_t *mtu)
3090 struct hwrm_func_qcfg_input req = {0};
3091 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
3094 bp->func_svif = BNXT_SVIF_INVALID;
3097 HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
3098 req.fid = rte_cpu_to_le_16(0xffff);
3100 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3102 HWRM_CHECK_RESULT();
3104 /* Hard Coded.. 0xfff VLAN ID mask */
3105 bp->vlan = rte_le_to_cpu_16(resp->vlan) & 0xfff;
3107 svif_info = rte_le_to_cpu_16(resp->svif_info);
3108 if (svif_info & HWRM_FUNC_QCFG_OUTPUT_SVIF_INFO_SVIF_VALID)
3109 bp->func_svif = svif_info &
3110 HWRM_FUNC_QCFG_OUTPUT_SVIF_INFO_SVIF_MASK;
3112 flags = rte_le_to_cpu_16(resp->flags);
3113 if (BNXT_PF(bp) && (flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_MULTI_HOST))
3114 bp->flags |= BNXT_FLAG_MULTI_HOST;
3117 !BNXT_VF_IS_TRUSTED(bp) &&
3118 (flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_TRUSTED_VF)) {
3119 bp->flags |= BNXT_FLAG_TRUSTED_VF_EN;
3120 PMD_DRV_LOG(INFO, "Trusted VF cap enabled\n");
3121 } else if (BNXT_VF(bp) &&
3122 BNXT_VF_IS_TRUSTED(bp) &&
3123 !(flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_TRUSTED_VF)) {
3124 bp->flags &= ~BNXT_FLAG_TRUSTED_VF_EN;
3125 PMD_DRV_LOG(INFO, "Trusted VF cap disabled\n");
3129 *mtu = rte_le_to_cpu_16(resp->mtu);
3131 switch (resp->port_partition_type) {
3132 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR1_0:
3133 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR1_5:
3134 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR2_0:
3136 bp->flags |= BNXT_FLAG_NPAR_PF;
3139 bp->flags &= ~BNXT_FLAG_NPAR_PF;
3148 int bnxt_hwrm_parent_pf_qcfg(struct bnxt *bp)
3150 struct hwrm_func_qcfg_input req = {0};
3151 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
3154 if (!BNXT_VF_IS_TRUSTED(bp))
3160 bp->parent->fid = BNXT_PF_FID_INVALID;
3162 HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
3164 req.fid = rte_cpu_to_le_16(0xfffe); /* Request parent PF information. */
3166 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3168 HWRM_CHECK_RESULT();
3170 memcpy(bp->parent->mac_addr, resp->mac_address, RTE_ETHER_ADDR_LEN);
3171 bp->parent->vnic = rte_le_to_cpu_16(resp->dflt_vnic_id);
3172 bp->parent->fid = rte_le_to_cpu_16(resp->fid);
3173 bp->parent->port_id = rte_le_to_cpu_16(resp->port_id);
3175 /* FIXME: Temporary workaround - remove when firmware issue is fixed. */
3176 if (bp->parent->vnic == 0) {
3177 PMD_DRV_LOG(ERR, "Error: parent VNIC unavailable.\n");
3178 /* Use hard-coded values appropriate for current Wh+ fw. */
3179 if (bp->parent->fid == 2)
3180 bp->parent->vnic = 0x100;
3182 bp->parent->vnic = 1;
3190 int bnxt_hwrm_get_dflt_vnic_svif(struct bnxt *bp, uint16_t fid,
3191 uint16_t *vnic_id, uint16_t *svif)
3193 struct hwrm_func_qcfg_input req = {0};
3194 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
3198 HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
3199 req.fid = rte_cpu_to_le_16(fid);
3201 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3203 HWRM_CHECK_RESULT();
3206 *vnic_id = rte_le_to_cpu_16(resp->dflt_vnic_id);
3208 svif_info = rte_le_to_cpu_16(resp->svif_info);
3209 if (svif && (svif_info & HWRM_FUNC_QCFG_OUTPUT_SVIF_INFO_SVIF_VALID))
3210 *svif = svif_info & HWRM_FUNC_QCFG_OUTPUT_SVIF_INFO_SVIF_MASK;
3217 int bnxt_hwrm_port_mac_qcfg(struct bnxt *bp)
3219 struct hwrm_port_mac_qcfg_input req = {0};
3220 struct hwrm_port_mac_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
3221 uint16_t port_svif_info;
3224 bp->port_svif = BNXT_SVIF_INVALID;
3226 if (BNXT_VF(bp) && !BNXT_VF_IS_TRUSTED(bp))
3229 HWRM_PREP(&req, HWRM_PORT_MAC_QCFG, BNXT_USE_CHIMP_MB);
3231 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3233 HWRM_CHECK_RESULT_SILENT();
3235 port_svif_info = rte_le_to_cpu_16(resp->port_svif_info);
3236 if (port_svif_info &
3237 HWRM_PORT_MAC_QCFG_OUTPUT_PORT_SVIF_INFO_PORT_SVIF_VALID)
3238 bp->port_svif = port_svif_info &
3239 HWRM_PORT_MAC_QCFG_OUTPUT_PORT_SVIF_INFO_PORT_SVIF_MASK;
3246 static void copy_func_cfg_to_qcaps(struct hwrm_func_cfg_input *fcfg,
3247 struct hwrm_func_qcaps_output *qcaps)
3249 qcaps->max_rsscos_ctx = fcfg->num_rsscos_ctxs;
3250 memcpy(qcaps->mac_address, fcfg->dflt_mac_addr,
3251 sizeof(qcaps->mac_address));
3252 qcaps->max_l2_ctxs = fcfg->num_l2_ctxs;
3253 qcaps->max_rx_rings = fcfg->num_rx_rings;
3254 qcaps->max_tx_rings = fcfg->num_tx_rings;
3255 qcaps->max_cmpl_rings = fcfg->num_cmpl_rings;
3256 qcaps->max_stat_ctx = fcfg->num_stat_ctxs;
3258 qcaps->first_vf_id = 0;
3259 qcaps->max_vnics = fcfg->num_vnics;
3260 qcaps->max_decap_records = 0;
3261 qcaps->max_encap_records = 0;
3262 qcaps->max_tx_wm_flows = 0;
3263 qcaps->max_tx_em_flows = 0;
3264 qcaps->max_rx_wm_flows = 0;
3265 qcaps->max_rx_em_flows = 0;
3266 qcaps->max_flow_id = 0;
3267 qcaps->max_mcast_filters = fcfg->num_mcast_filters;
3268 qcaps->max_sp_tx_rings = 0;
3269 qcaps->max_hw_ring_grps = fcfg->num_hw_ring_grps;
3272 static int bnxt_hwrm_pf_func_cfg(struct bnxt *bp, int tx_rings)
3274 struct hwrm_func_cfg_input req = {0};
3275 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3279 enables = HWRM_FUNC_CFG_INPUT_ENABLES_MTU |
3280 HWRM_FUNC_CFG_INPUT_ENABLES_MRU |
3281 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS |
3282 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
3283 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
3284 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_TX_RINGS |
3285 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RX_RINGS |
3286 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_L2_CTXS |
3287 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_VNICS;
3289 if (BNXT_HAS_RING_GRPS(bp)) {
3290 enables |= HWRM_FUNC_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS;
3291 req.num_hw_ring_grps = rte_cpu_to_le_16(bp->max_ring_grps);
3292 } else if (BNXT_HAS_NQ(bp)) {
3293 enables |= HWRM_FUNC_CFG_INPUT_ENABLES_NUM_MSIX;
3294 req.num_msix = rte_cpu_to_le_16(bp->max_nq_rings);
3297 req.flags = rte_cpu_to_le_32(bp->pf->func_cfg_flags);
3298 req.mtu = rte_cpu_to_le_16(BNXT_MAX_MTU);
3299 req.mru = rte_cpu_to_le_16(BNXT_VNIC_MRU(bp->eth_dev->data->mtu));
3300 req.num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx);
3301 req.num_stat_ctxs = rte_cpu_to_le_16(bp->max_stat_ctx);
3302 req.num_cmpl_rings = rte_cpu_to_le_16(bp->max_cp_rings);
3303 req.num_tx_rings = rte_cpu_to_le_16(tx_rings);
3304 req.num_rx_rings = rte_cpu_to_le_16(bp->max_rx_rings);
3305 req.num_l2_ctxs = rte_cpu_to_le_16(bp->max_l2_ctx);
3306 req.num_vnics = rte_cpu_to_le_16(bp->max_vnics);
3307 req.fid = rte_cpu_to_le_16(0xffff);
3308 req.enables = rte_cpu_to_le_32(enables);
3310 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
3312 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3314 HWRM_CHECK_RESULT();
3320 static void populate_vf_func_cfg_req(struct bnxt *bp,
3321 struct hwrm_func_cfg_input *req,
3324 req->enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_MTU |
3325 HWRM_FUNC_CFG_INPUT_ENABLES_MRU |
3326 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS |
3327 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
3328 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
3329 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_TX_RINGS |
3330 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RX_RINGS |
3331 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_L2_CTXS |
3332 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_VNICS |
3333 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS);
3335 req->mtu = rte_cpu_to_le_16(bp->eth_dev->data->mtu + RTE_ETHER_HDR_LEN +
3336 RTE_ETHER_CRC_LEN + VLAN_TAG_SIZE *
3338 req->mru = rte_cpu_to_le_16(BNXT_VNIC_MRU(bp->eth_dev->data->mtu));
3339 req->num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx /
3341 req->num_stat_ctxs = rte_cpu_to_le_16(bp->max_stat_ctx / (num_vfs + 1));
3342 req->num_cmpl_rings = rte_cpu_to_le_16(bp->max_cp_rings /
3344 req->num_tx_rings = rte_cpu_to_le_16(bp->max_tx_rings / (num_vfs + 1));
3345 req->num_rx_rings = rte_cpu_to_le_16(bp->max_rx_rings / (num_vfs + 1));
3346 req->num_l2_ctxs = rte_cpu_to_le_16(bp->max_l2_ctx / (num_vfs + 1));
3347 /* TODO: For now, do not support VMDq/RFS on VFs. */
3348 req->num_vnics = rte_cpu_to_le_16(1);
3349 req->num_hw_ring_grps = rte_cpu_to_le_16(bp->max_ring_grps /
3353 static void add_random_mac_if_needed(struct bnxt *bp,
3354 struct hwrm_func_cfg_input *cfg_req,
3357 struct rte_ether_addr mac;
3359 if (bnxt_hwrm_func_qcfg_vf_default_mac(bp, vf, &mac))
3362 if (memcmp(mac.addr_bytes, "\x00\x00\x00\x00\x00", 6) == 0) {
3364 rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
3365 rte_eth_random_addr(cfg_req->dflt_mac_addr);
3366 bp->pf->vf_info[vf].random_mac = true;
3368 memcpy(cfg_req->dflt_mac_addr, mac.addr_bytes,
3369 RTE_ETHER_ADDR_LEN);
3373 static int reserve_resources_from_vf(struct bnxt *bp,
3374 struct hwrm_func_cfg_input *cfg_req,
3377 struct hwrm_func_qcaps_input req = {0};
3378 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
3381 /* Get the actual allocated values now */
3382 HWRM_PREP(&req, HWRM_FUNC_QCAPS, BNXT_USE_CHIMP_MB);
3383 req.fid = rte_cpu_to_le_16(bp->pf->vf_info[vf].fid);
3384 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3387 PMD_DRV_LOG(ERR, "hwrm_func_qcaps failed rc:%d\n", rc);
3388 copy_func_cfg_to_qcaps(cfg_req, resp);
3389 } else if (resp->error_code) {
3390 rc = rte_le_to_cpu_16(resp->error_code);
3391 PMD_DRV_LOG(ERR, "hwrm_func_qcaps error %d\n", rc);
3392 copy_func_cfg_to_qcaps(cfg_req, resp);
3395 bp->max_rsscos_ctx -= rte_le_to_cpu_16(resp->max_rsscos_ctx);
3396 bp->max_stat_ctx -= rte_le_to_cpu_16(resp->max_stat_ctx);
3397 bp->max_cp_rings -= rte_le_to_cpu_16(resp->max_cmpl_rings);
3398 bp->max_tx_rings -= rte_le_to_cpu_16(resp->max_tx_rings);
3399 bp->max_rx_rings -= rte_le_to_cpu_16(resp->max_rx_rings);
3400 bp->max_l2_ctx -= rte_le_to_cpu_16(resp->max_l2_ctxs);
3402 * TODO: While not supporting VMDq with VFs, max_vnics is always
3403 * forced to 1 in this case
3405 //bp->max_vnics -= rte_le_to_cpu_16(esp->max_vnics);
3406 bp->max_ring_grps -= rte_le_to_cpu_16(resp->max_hw_ring_grps);
3413 int bnxt_hwrm_func_qcfg_current_vf_vlan(struct bnxt *bp, int vf)
3415 struct hwrm_func_qcfg_input req = {0};
3416 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
3419 /* Check for zero MAC address */
3420 HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
3421 req.fid = rte_cpu_to_le_16(bp->pf->vf_info[vf].fid);
3422 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3423 HWRM_CHECK_RESULT();
3424 rc = rte_le_to_cpu_16(resp->vlan);
3431 static int update_pf_resource_max(struct bnxt *bp)
3433 struct hwrm_func_qcfg_input req = {0};
3434 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
3437 /* And copy the allocated numbers into the pf struct */
3438 HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
3439 req.fid = rte_cpu_to_le_16(0xffff);
3440 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3441 HWRM_CHECK_RESULT();
3443 /* Only TX ring value reflects actual allocation? TODO */
3444 bp->max_tx_rings = rte_le_to_cpu_16(resp->alloc_tx_rings);
3445 bp->pf->evb_mode = resp->evb_mode;
3452 int bnxt_hwrm_allocate_pf_only(struct bnxt *bp)
3457 PMD_DRV_LOG(ERR, "Attempt to allcoate VFs on a VF!\n");
3461 rc = bnxt_hwrm_func_qcaps(bp);
3465 bp->pf->func_cfg_flags &=
3466 ~(HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE |
3467 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE);
3468 bp->pf->func_cfg_flags |=
3469 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE;
3470 rc = bnxt_hwrm_pf_func_cfg(bp, bp->max_tx_rings);
3471 rc = __bnxt_hwrm_func_qcaps(bp);
3475 int bnxt_hwrm_allocate_vfs(struct bnxt *bp, int num_vfs)
3477 struct hwrm_func_cfg_input req = {0};
3478 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3485 PMD_DRV_LOG(ERR, "Attempt to allcoate VFs on a VF!\n");
3489 rc = bnxt_hwrm_func_qcaps(bp);
3494 bp->pf->active_vfs = num_vfs;
3497 * First, configure the PF to only use one TX ring. This ensures that
3498 * there are enough rings for all VFs.
3500 * If we don't do this, when we call func_alloc() later, we will lock
3501 * extra rings to the PF that won't be available during func_cfg() of
3504 * This has been fixed with firmware versions above 20.6.54
3506 bp->pf->func_cfg_flags &=
3507 ~(HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE |
3508 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE);
3509 bp->pf->func_cfg_flags |=
3510 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE;
3511 rc = bnxt_hwrm_pf_func_cfg(bp, 1);
3516 * Now, create and register a buffer to hold forwarded VF requests
3518 req_buf_sz = num_vfs * HWRM_MAX_REQ_LEN;
3519 bp->pf->vf_req_buf = rte_malloc("bnxt_vf_fwd", req_buf_sz,
3520 page_roundup(num_vfs * HWRM_MAX_REQ_LEN));
3521 if (bp->pf->vf_req_buf == NULL) {
3525 for (sz = 0; sz < req_buf_sz; sz += getpagesize())
3526 rte_mem_lock_page(((char *)bp->pf->vf_req_buf) + sz);
3527 for (i = 0; i < num_vfs; i++)
3528 bp->pf->vf_info[i].req_buf = ((char *)bp->pf->vf_req_buf) +
3529 (i * HWRM_MAX_REQ_LEN);
3531 rc = bnxt_hwrm_func_buf_rgtr(bp);
3535 populate_vf_func_cfg_req(bp, &req, num_vfs);
3537 bp->pf->active_vfs = 0;
3538 for (i = 0; i < num_vfs; i++) {
3539 add_random_mac_if_needed(bp, &req, i);
3541 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
3542 req.flags = rte_cpu_to_le_32(bp->pf->vf_info[i].func_cfg_flags);
3543 req.fid = rte_cpu_to_le_16(bp->pf->vf_info[i].fid);
3544 rc = bnxt_hwrm_send_message(bp,
3549 /* Clear enable flag for next pass */
3550 req.enables &= ~rte_cpu_to_le_32(
3551 HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
3553 if (rc || resp->error_code) {
3555 "Failed to initizlie VF %d\n", i);
3557 "Not all VFs available. (%d, %d)\n",
3558 rc, resp->error_code);
3565 reserve_resources_from_vf(bp, &req, i);
3566 bp->pf->active_vfs++;
3567 bnxt_hwrm_func_clr_stats(bp, bp->pf->vf_info[i].fid);
3571 * Now configure the PF to use "the rest" of the resources
3572 * We're using STD_TX_RING_MODE here though which will limit the TX
3573 * rings. This will allow QoS to function properly. Not setting this
3574 * will cause PF rings to break bandwidth settings.
3576 rc = bnxt_hwrm_pf_func_cfg(bp, bp->max_tx_rings);
3580 rc = update_pf_resource_max(bp);
3587 bnxt_hwrm_func_buf_unrgtr(bp);
3591 int bnxt_hwrm_pf_evb_mode(struct bnxt *bp)
3593 struct hwrm_func_cfg_input req = {0};
3594 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3597 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
3599 req.fid = rte_cpu_to_le_16(0xffff);
3600 req.enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_EVB_MODE);
3601 req.evb_mode = bp->pf->evb_mode;
3603 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3604 HWRM_CHECK_RESULT();
3610 int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt *bp, uint16_t port,
3611 uint8_t tunnel_type)
3613 struct hwrm_tunnel_dst_port_alloc_input req = {0};
3614 struct hwrm_tunnel_dst_port_alloc_output *resp = bp->hwrm_cmd_resp_addr;
3617 HWRM_PREP(&req, HWRM_TUNNEL_DST_PORT_ALLOC, BNXT_USE_CHIMP_MB);
3618 req.tunnel_type = tunnel_type;
3619 req.tunnel_dst_port_val = port;
3620 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3621 HWRM_CHECK_RESULT();
3623 switch (tunnel_type) {
3624 case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_VXLAN:
3625 bp->vxlan_fw_dst_port_id = resp->tunnel_dst_port_id;
3626 bp->vxlan_port = port;
3628 case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_GENEVE:
3629 bp->geneve_fw_dst_port_id = resp->tunnel_dst_port_id;
3630 bp->geneve_port = port;
3641 int bnxt_hwrm_tunnel_dst_port_free(struct bnxt *bp, uint16_t port,
3642 uint8_t tunnel_type)
3644 struct hwrm_tunnel_dst_port_free_input req = {0};
3645 struct hwrm_tunnel_dst_port_free_output *resp = bp->hwrm_cmd_resp_addr;
3648 HWRM_PREP(&req, HWRM_TUNNEL_DST_PORT_FREE, BNXT_USE_CHIMP_MB);
3650 req.tunnel_type = tunnel_type;
3651 req.tunnel_dst_port_id = rte_cpu_to_be_16(port);
3652 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3654 HWRM_CHECK_RESULT();
3660 int bnxt_hwrm_func_cfg_vf_set_flags(struct bnxt *bp, uint16_t vf,
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.flags = rte_cpu_to_le_32(flags);
3671 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3673 HWRM_CHECK_RESULT();
3679 void vf_vnic_set_rxmask_cb(struct bnxt_vnic_info *vnic, void *flagp)
3681 uint32_t *flag = flagp;
3683 vnic->flags = *flag;
3686 int bnxt_set_rx_mask_no_vlan(struct bnxt *bp, struct bnxt_vnic_info *vnic)
3688 return bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
3691 int bnxt_hwrm_func_buf_rgtr(struct bnxt *bp)
3694 struct hwrm_func_buf_rgtr_input req = {.req_type = 0 };
3695 struct hwrm_func_buf_rgtr_output *resp = bp->hwrm_cmd_resp_addr;
3697 HWRM_PREP(&req, HWRM_FUNC_BUF_RGTR, BNXT_USE_CHIMP_MB);
3699 req.req_buf_num_pages = rte_cpu_to_le_16(1);
3700 req.req_buf_page_size = rte_cpu_to_le_16(
3701 page_getenum(bp->pf->active_vfs * HWRM_MAX_REQ_LEN));
3702 req.req_buf_len = rte_cpu_to_le_16(HWRM_MAX_REQ_LEN);
3703 req.req_buf_page_addr0 =
3704 rte_cpu_to_le_64(rte_malloc_virt2iova(bp->pf->vf_req_buf));
3705 if (req.req_buf_page_addr0 == RTE_BAD_IOVA) {
3707 "unable to map buffer address to physical memory\n");
3711 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3713 HWRM_CHECK_RESULT();
3719 int bnxt_hwrm_func_buf_unrgtr(struct bnxt *bp)
3722 struct hwrm_func_buf_unrgtr_input req = {.req_type = 0 };
3723 struct hwrm_func_buf_unrgtr_output *resp = bp->hwrm_cmd_resp_addr;
3725 if (!(BNXT_PF(bp) && bp->pdev->max_vfs))
3728 HWRM_PREP(&req, HWRM_FUNC_BUF_UNRGTR, BNXT_USE_CHIMP_MB);
3730 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3732 HWRM_CHECK_RESULT();
3738 int bnxt_hwrm_func_cfg_def_cp(struct bnxt *bp)
3740 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3741 struct hwrm_func_cfg_input req = {0};
3744 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
3746 req.fid = rte_cpu_to_le_16(0xffff);
3747 req.flags = rte_cpu_to_le_32(bp->pf->func_cfg_flags);
3748 req.enables = rte_cpu_to_le_32(
3749 HWRM_FUNC_CFG_INPUT_ENABLES_ASYNC_EVENT_CR);
3750 req.async_event_cr = rte_cpu_to_le_16(
3751 bp->async_cp_ring->cp_ring_struct->fw_ring_id);
3752 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3754 HWRM_CHECK_RESULT();
3760 int bnxt_hwrm_vf_func_cfg_def_cp(struct bnxt *bp)
3762 struct hwrm_func_vf_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3763 struct hwrm_func_vf_cfg_input req = {0};
3766 HWRM_PREP(&req, HWRM_FUNC_VF_CFG, BNXT_USE_CHIMP_MB);
3768 req.enables = rte_cpu_to_le_32(
3769 HWRM_FUNC_VF_CFG_INPUT_ENABLES_ASYNC_EVENT_CR);
3770 req.async_event_cr = rte_cpu_to_le_16(
3771 bp->async_cp_ring->cp_ring_struct->fw_ring_id);
3772 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3774 HWRM_CHECK_RESULT();
3780 int bnxt_hwrm_set_default_vlan(struct bnxt *bp, int vf, uint8_t is_vf)
3782 struct hwrm_func_cfg_input req = {0};
3783 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3784 uint16_t dflt_vlan, fid;
3785 uint32_t func_cfg_flags;
3788 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
3791 dflt_vlan = bp->pf->vf_info[vf].dflt_vlan;
3792 fid = bp->pf->vf_info[vf].fid;
3793 func_cfg_flags = bp->pf->vf_info[vf].func_cfg_flags;
3795 fid = rte_cpu_to_le_16(0xffff);
3796 func_cfg_flags = bp->pf->func_cfg_flags;
3797 dflt_vlan = bp->vlan;
3800 req.flags = rte_cpu_to_le_32(func_cfg_flags);
3801 req.fid = rte_cpu_to_le_16(fid);
3802 req.enables |= rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_VLAN);
3803 req.dflt_vlan = rte_cpu_to_le_16(dflt_vlan);
3805 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3807 HWRM_CHECK_RESULT();
3813 int bnxt_hwrm_func_bw_cfg(struct bnxt *bp, uint16_t vf,
3814 uint16_t max_bw, uint16_t enables)
3816 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3817 struct hwrm_func_cfg_input req = {0};
3820 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
3822 req.fid = rte_cpu_to_le_16(bp->pf->vf_info[vf].fid);
3823 req.enables |= rte_cpu_to_le_32(enables);
3824 req.flags = rte_cpu_to_le_32(bp->pf->vf_info[vf].func_cfg_flags);
3825 req.max_bw = rte_cpu_to_le_32(max_bw);
3826 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3828 HWRM_CHECK_RESULT();
3834 int bnxt_hwrm_set_vf_vlan(struct bnxt *bp, int vf)
3836 struct hwrm_func_cfg_input req = {0};
3837 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3840 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
3842 req.flags = rte_cpu_to_le_32(bp->pf->vf_info[vf].func_cfg_flags);
3843 req.fid = rte_cpu_to_le_16(bp->pf->vf_info[vf].fid);
3844 req.enables |= rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_VLAN);
3845 req.dflt_vlan = rte_cpu_to_le_16(bp->pf->vf_info[vf].dflt_vlan);
3847 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3849 HWRM_CHECK_RESULT();
3855 int bnxt_hwrm_set_async_event_cr(struct bnxt *bp)
3860 rc = bnxt_hwrm_func_cfg_def_cp(bp);
3862 rc = bnxt_hwrm_vf_func_cfg_def_cp(bp);
3867 int bnxt_hwrm_reject_fwd_resp(struct bnxt *bp, uint16_t target_id,
3868 void *encaped, size_t ec_size)
3871 struct hwrm_reject_fwd_resp_input req = {.req_type = 0};
3872 struct hwrm_reject_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr;
3874 if (ec_size > sizeof(req.encap_request))
3877 HWRM_PREP(&req, HWRM_REJECT_FWD_RESP, BNXT_USE_CHIMP_MB);
3879 req.encap_resp_target_id = rte_cpu_to_le_16(target_id);
3880 memcpy(req.encap_request, encaped, ec_size);
3882 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3884 HWRM_CHECK_RESULT();
3890 int bnxt_hwrm_func_qcfg_vf_default_mac(struct bnxt *bp, uint16_t vf,
3891 struct rte_ether_addr *mac)
3893 struct hwrm_func_qcfg_input req = {0};
3894 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
3897 HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
3899 req.fid = rte_cpu_to_le_16(bp->pf->vf_info[vf].fid);
3900 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3902 HWRM_CHECK_RESULT();
3904 memcpy(mac->addr_bytes, resp->mac_address, RTE_ETHER_ADDR_LEN);
3911 int bnxt_hwrm_exec_fwd_resp(struct bnxt *bp, uint16_t target_id,
3912 void *encaped, size_t ec_size)
3915 struct hwrm_exec_fwd_resp_input req = {.req_type = 0};
3916 struct hwrm_exec_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr;
3918 if (ec_size > sizeof(req.encap_request))
3921 HWRM_PREP(&req, HWRM_EXEC_FWD_RESP, BNXT_USE_CHIMP_MB);
3923 req.encap_resp_target_id = rte_cpu_to_le_16(target_id);
3924 memcpy(req.encap_request, encaped, ec_size);
3926 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3928 HWRM_CHECK_RESULT();
3934 int bnxt_hwrm_ctx_qstats(struct bnxt *bp, uint32_t cid, int idx,
3935 struct rte_eth_stats *stats, uint8_t rx)
3938 struct hwrm_stat_ctx_query_input req = {.req_type = 0};
3939 struct hwrm_stat_ctx_query_output *resp = bp->hwrm_cmd_resp_addr;
3941 HWRM_PREP(&req, HWRM_STAT_CTX_QUERY, BNXT_USE_CHIMP_MB);
3943 req.stat_ctx_id = rte_cpu_to_le_32(cid);
3945 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3947 HWRM_CHECK_RESULT();
3950 stats->q_ipackets[idx] = rte_le_to_cpu_64(resp->rx_ucast_pkts);
3951 stats->q_ipackets[idx] += rte_le_to_cpu_64(resp->rx_mcast_pkts);
3952 stats->q_ipackets[idx] += rte_le_to_cpu_64(resp->rx_bcast_pkts);
3953 stats->q_ibytes[idx] = rte_le_to_cpu_64(resp->rx_ucast_bytes);
3954 stats->q_ibytes[idx] += rte_le_to_cpu_64(resp->rx_mcast_bytes);
3955 stats->q_ibytes[idx] += rte_le_to_cpu_64(resp->rx_bcast_bytes);
3956 stats->q_errors[idx] = rte_le_to_cpu_64(resp->rx_err_pkts);
3957 stats->q_errors[idx] += rte_le_to_cpu_64(resp->rx_drop_pkts);
3959 stats->q_opackets[idx] = rte_le_to_cpu_64(resp->tx_ucast_pkts);
3960 stats->q_opackets[idx] += rte_le_to_cpu_64(resp->tx_mcast_pkts);
3961 stats->q_opackets[idx] += rte_le_to_cpu_64(resp->tx_bcast_pkts);
3962 stats->q_obytes[idx] = rte_le_to_cpu_64(resp->tx_ucast_bytes);
3963 stats->q_obytes[idx] += rte_le_to_cpu_64(resp->tx_mcast_bytes);
3964 stats->q_obytes[idx] += rte_le_to_cpu_64(resp->tx_bcast_bytes);
3972 int bnxt_hwrm_port_qstats(struct bnxt *bp)
3974 struct hwrm_port_qstats_input req = {0};
3975 struct hwrm_port_qstats_output *resp = bp->hwrm_cmd_resp_addr;
3976 struct bnxt_pf_info *pf = bp->pf;
3979 HWRM_PREP(&req, HWRM_PORT_QSTATS, BNXT_USE_CHIMP_MB);
3981 req.port_id = rte_cpu_to_le_16(pf->port_id);
3982 req.tx_stat_host_addr = rte_cpu_to_le_64(bp->hw_tx_port_stats_map);
3983 req.rx_stat_host_addr = rte_cpu_to_le_64(bp->hw_rx_port_stats_map);
3984 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3986 HWRM_CHECK_RESULT();
3992 int bnxt_hwrm_port_clr_stats(struct bnxt *bp)
3994 struct hwrm_port_clr_stats_input req = {0};
3995 struct hwrm_port_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
3996 struct bnxt_pf_info *pf = bp->pf;
3999 /* Not allowed on NS2 device, NPAR, MultiHost, VF */
4000 if (!(bp->flags & BNXT_FLAG_PORT_STATS) || BNXT_VF(bp) ||
4001 BNXT_NPAR(bp) || BNXT_MH(bp) || BNXT_TOTAL_VFS(bp))
4004 HWRM_PREP(&req, HWRM_PORT_CLR_STATS, BNXT_USE_CHIMP_MB);
4006 req.port_id = rte_cpu_to_le_16(pf->port_id);
4007 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4009 HWRM_CHECK_RESULT();
4015 int bnxt_hwrm_port_led_qcaps(struct bnxt *bp)
4017 struct hwrm_port_led_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
4018 struct hwrm_port_led_qcaps_input req = {0};
4024 HWRM_PREP(&req, HWRM_PORT_LED_QCAPS, BNXT_USE_CHIMP_MB);
4025 req.port_id = bp->pf->port_id;
4026 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4028 HWRM_CHECK_RESULT();
4030 if (resp->num_leds > 0 && resp->num_leds < BNXT_MAX_LED) {
4033 bp->leds->num_leds = resp->num_leds;
4034 memcpy(bp->leds, &resp->led0_id,
4035 sizeof(bp->leds[0]) * bp->leds->num_leds);
4036 for (i = 0; i < bp->leds->num_leds; i++) {
4037 struct bnxt_led_info *led = &bp->leds[i];
4039 uint16_t caps = led->led_state_caps;
4041 if (!led->led_group_id ||
4042 !BNXT_LED_ALT_BLINK_CAP(caps)) {
4043 bp->leds->num_leds = 0;
4054 int bnxt_hwrm_port_led_cfg(struct bnxt *bp, bool led_on)
4056 struct hwrm_port_led_cfg_output *resp = bp->hwrm_cmd_resp_addr;
4057 struct hwrm_port_led_cfg_input req = {0};
4058 struct bnxt_led_cfg *led_cfg;
4059 uint8_t led_state = HWRM_PORT_LED_QCFG_OUTPUT_LED0_STATE_DEFAULT;
4060 uint16_t duration = 0;
4063 if (!bp->leds->num_leds || BNXT_VF(bp))
4066 HWRM_PREP(&req, HWRM_PORT_LED_CFG, BNXT_USE_CHIMP_MB);
4069 led_state = HWRM_PORT_LED_CFG_INPUT_LED0_STATE_BLINKALT;
4070 duration = rte_cpu_to_le_16(500);
4072 req.port_id = bp->pf->port_id;
4073 req.num_leds = bp->leds->num_leds;
4074 led_cfg = (struct bnxt_led_cfg *)&req.led0_id;
4075 for (i = 0; i < bp->leds->num_leds; i++, led_cfg++) {
4076 req.enables |= BNXT_LED_DFLT_ENABLES(i);
4077 led_cfg->led_id = bp->leds[i].led_id;
4078 led_cfg->led_state = led_state;
4079 led_cfg->led_blink_on = duration;
4080 led_cfg->led_blink_off = duration;
4081 led_cfg->led_group_id = bp->leds[i].led_group_id;
4084 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4086 HWRM_CHECK_RESULT();
4092 int bnxt_hwrm_nvm_get_dir_info(struct bnxt *bp, uint32_t *entries,
4096 struct hwrm_nvm_get_dir_info_input req = {0};
4097 struct hwrm_nvm_get_dir_info_output *resp = bp->hwrm_cmd_resp_addr;
4099 HWRM_PREP(&req, HWRM_NVM_GET_DIR_INFO, BNXT_USE_CHIMP_MB);
4101 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4103 HWRM_CHECK_RESULT();
4105 *entries = rte_le_to_cpu_32(resp->entries);
4106 *length = rte_le_to_cpu_32(resp->entry_length);
4112 int bnxt_get_nvram_directory(struct bnxt *bp, uint32_t len, uint8_t *data)
4115 uint32_t dir_entries;
4116 uint32_t entry_length;
4119 rte_iova_t dma_handle;
4120 struct hwrm_nvm_get_dir_entries_input req = {0};
4121 struct hwrm_nvm_get_dir_entries_output *resp = bp->hwrm_cmd_resp_addr;
4123 rc = bnxt_hwrm_nvm_get_dir_info(bp, &dir_entries, &entry_length);
4127 *data++ = dir_entries;
4128 *data++ = entry_length;
4130 memset(data, 0xff, len);
4132 buflen = dir_entries * entry_length;
4133 buf = rte_malloc("nvm_dir", buflen, 0);
4136 dma_handle = rte_malloc_virt2iova(buf);
4137 if (dma_handle == RTE_BAD_IOVA) {
4139 "unable to map response address to physical memory\n");
4142 HWRM_PREP(&req, HWRM_NVM_GET_DIR_ENTRIES, BNXT_USE_CHIMP_MB);
4143 req.host_dest_addr = rte_cpu_to_le_64(dma_handle);
4144 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4147 memcpy(data, buf, len > buflen ? buflen : len);
4150 HWRM_CHECK_RESULT();
4156 int bnxt_hwrm_get_nvram_item(struct bnxt *bp, uint32_t index,
4157 uint32_t offset, uint32_t length,
4162 rte_iova_t dma_handle;
4163 struct hwrm_nvm_read_input req = {0};
4164 struct hwrm_nvm_read_output *resp = bp->hwrm_cmd_resp_addr;
4166 buf = rte_malloc("nvm_item", length, 0);
4170 dma_handle = rte_malloc_virt2iova(buf);
4171 if (dma_handle == RTE_BAD_IOVA) {
4173 "unable to map response address to physical memory\n");
4176 HWRM_PREP(&req, HWRM_NVM_READ, BNXT_USE_CHIMP_MB);
4177 req.host_dest_addr = rte_cpu_to_le_64(dma_handle);
4178 req.dir_idx = rte_cpu_to_le_16(index);
4179 req.offset = rte_cpu_to_le_32(offset);
4180 req.len = rte_cpu_to_le_32(length);
4181 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4183 memcpy(data, buf, length);
4186 HWRM_CHECK_RESULT();
4192 int bnxt_hwrm_erase_nvram_directory(struct bnxt *bp, uint8_t index)
4195 struct hwrm_nvm_erase_dir_entry_input req = {0};
4196 struct hwrm_nvm_erase_dir_entry_output *resp = bp->hwrm_cmd_resp_addr;
4198 HWRM_PREP(&req, HWRM_NVM_ERASE_DIR_ENTRY, BNXT_USE_CHIMP_MB);
4199 req.dir_idx = rte_cpu_to_le_16(index);
4200 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4201 HWRM_CHECK_RESULT();
4208 int bnxt_hwrm_flash_nvram(struct bnxt *bp, uint16_t dir_type,
4209 uint16_t dir_ordinal, uint16_t dir_ext,
4210 uint16_t dir_attr, const uint8_t *data,
4214 struct hwrm_nvm_write_input req = {0};
4215 struct hwrm_nvm_write_output *resp = bp->hwrm_cmd_resp_addr;
4216 rte_iova_t dma_handle;
4219 buf = rte_malloc("nvm_write", data_len, 0);
4223 dma_handle = rte_malloc_virt2iova(buf);
4224 if (dma_handle == RTE_BAD_IOVA) {
4226 "unable to map response address to physical memory\n");
4229 memcpy(buf, data, data_len);
4231 HWRM_PREP(&req, HWRM_NVM_WRITE, BNXT_USE_CHIMP_MB);
4233 req.dir_type = rte_cpu_to_le_16(dir_type);
4234 req.dir_ordinal = rte_cpu_to_le_16(dir_ordinal);
4235 req.dir_ext = rte_cpu_to_le_16(dir_ext);
4236 req.dir_attr = rte_cpu_to_le_16(dir_attr);
4237 req.dir_data_length = rte_cpu_to_le_32(data_len);
4238 req.host_src_addr = rte_cpu_to_le_64(dma_handle);
4240 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4243 HWRM_CHECK_RESULT();
4250 bnxt_vnic_count(struct bnxt_vnic_info *vnic __rte_unused, void *cbdata)
4252 uint32_t *count = cbdata;
4254 *count = *count + 1;
4257 static int bnxt_vnic_count_hwrm_stub(struct bnxt *bp __rte_unused,
4258 struct bnxt_vnic_info *vnic __rte_unused)
4263 int bnxt_vf_vnic_count(struct bnxt *bp, uint16_t vf)
4267 bnxt_hwrm_func_vf_vnic_query_and_config(bp, vf, bnxt_vnic_count,
4268 &count, bnxt_vnic_count_hwrm_stub);
4273 static int bnxt_hwrm_func_vf_vnic_query(struct bnxt *bp, uint16_t vf,
4276 struct hwrm_func_vf_vnic_ids_query_input req = {0};
4277 struct hwrm_func_vf_vnic_ids_query_output *resp =
4278 bp->hwrm_cmd_resp_addr;
4281 /* First query all VNIC ids */
4282 HWRM_PREP(&req, HWRM_FUNC_VF_VNIC_IDS_QUERY, BNXT_USE_CHIMP_MB);
4284 req.vf_id = rte_cpu_to_le_16(bp->pf->first_vf_id + vf);
4285 req.max_vnic_id_cnt = rte_cpu_to_le_32(bp->pf->total_vnics);
4286 req.vnic_id_tbl_addr = rte_cpu_to_le_64(rte_malloc_virt2iova(vnic_ids));
4288 if (req.vnic_id_tbl_addr == RTE_BAD_IOVA) {
4291 "unable to map VNIC ID table address to physical memory\n");
4294 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4295 HWRM_CHECK_RESULT();
4296 rc = rte_le_to_cpu_32(resp->vnic_id_cnt);
4304 * This function queries the VNIC IDs for a specified VF. It then calls
4305 * the vnic_cb to update the necessary field in vnic_info with cbdata.
4306 * Then it calls the hwrm_cb function to program this new vnic configuration.
4308 int bnxt_hwrm_func_vf_vnic_query_and_config(struct bnxt *bp, uint16_t vf,
4309 void (*vnic_cb)(struct bnxt_vnic_info *, void *), void *cbdata,
4310 int (*hwrm_cb)(struct bnxt *bp, struct bnxt_vnic_info *vnic))
4312 struct bnxt_vnic_info vnic;
4314 int i, num_vnic_ids;
4319 /* First query all VNIC ids */
4320 vnic_id_sz = bp->pf->total_vnics * sizeof(*vnic_ids);
4321 vnic_ids = rte_malloc("bnxt_hwrm_vf_vnic_ids_query", vnic_id_sz,
4322 RTE_CACHE_LINE_SIZE);
4323 if (vnic_ids == NULL)
4326 for (sz = 0; sz < vnic_id_sz; sz += getpagesize())
4327 rte_mem_lock_page(((char *)vnic_ids) + sz);
4329 num_vnic_ids = bnxt_hwrm_func_vf_vnic_query(bp, vf, vnic_ids);
4331 if (num_vnic_ids < 0)
4332 return num_vnic_ids;
4334 /* Retrieve VNIC, update bd_stall then update */
4336 for (i = 0; i < num_vnic_ids; i++) {
4337 memset(&vnic, 0, sizeof(struct bnxt_vnic_info));
4338 vnic.fw_vnic_id = rte_le_to_cpu_16(vnic_ids[i]);
4339 rc = bnxt_hwrm_vnic_qcfg(bp, &vnic, bp->pf->first_vf_id + vf);
4342 if (vnic.mru <= 4) /* Indicates unallocated */
4345 vnic_cb(&vnic, cbdata);
4347 rc = hwrm_cb(bp, &vnic);
4357 int bnxt_hwrm_func_cfg_vf_set_vlan_anti_spoof(struct bnxt *bp, uint16_t vf,
4360 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
4361 struct hwrm_func_cfg_input req = {0};
4364 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
4366 req.fid = rte_cpu_to_le_16(bp->pf->vf_info[vf].fid);
4367 req.enables |= rte_cpu_to_le_32(
4368 HWRM_FUNC_CFG_INPUT_ENABLES_VLAN_ANTISPOOF_MODE);
4369 req.vlan_antispoof_mode = on ?
4370 HWRM_FUNC_CFG_INPUT_VLAN_ANTISPOOF_MODE_VALIDATE_VLAN :
4371 HWRM_FUNC_CFG_INPUT_VLAN_ANTISPOOF_MODE_NOCHECK;
4372 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4374 HWRM_CHECK_RESULT();
4380 int bnxt_hwrm_func_qcfg_vf_dflt_vnic_id(struct bnxt *bp, int vf)
4382 struct bnxt_vnic_info vnic;
4385 int num_vnic_ids, i;
4389 vnic_id_sz = bp->pf->total_vnics * sizeof(*vnic_ids);
4390 vnic_ids = rte_malloc("bnxt_hwrm_vf_vnic_ids_query", vnic_id_sz,
4391 RTE_CACHE_LINE_SIZE);
4392 if (vnic_ids == NULL)
4395 for (sz = 0; sz < vnic_id_sz; sz += getpagesize())
4396 rte_mem_lock_page(((char *)vnic_ids) + sz);
4398 rc = bnxt_hwrm_func_vf_vnic_query(bp, vf, vnic_ids);
4404 * Loop through to find the default VNIC ID.
4405 * TODO: The easier way would be to obtain the resp->dflt_vnic_id
4406 * by sending the hwrm_func_qcfg command to the firmware.
4408 for (i = 0; i < num_vnic_ids; i++) {
4409 memset(&vnic, 0, sizeof(struct bnxt_vnic_info));
4410 vnic.fw_vnic_id = rte_le_to_cpu_16(vnic_ids[i]);
4411 rc = bnxt_hwrm_vnic_qcfg(bp, &vnic,
4412 bp->pf->first_vf_id + vf);
4415 if (vnic.func_default) {
4417 return vnic.fw_vnic_id;
4420 /* Could not find a default VNIC. */
4421 PMD_DRV_LOG(ERR, "No default VNIC\n");
4427 int bnxt_hwrm_set_em_filter(struct bnxt *bp,
4429 struct bnxt_filter_info *filter)
4432 struct hwrm_cfa_em_flow_alloc_input req = {.req_type = 0 };
4433 struct hwrm_cfa_em_flow_alloc_output *resp = bp->hwrm_cmd_resp_addr;
4434 uint32_t enables = 0;
4436 if (filter->fw_em_filter_id != UINT64_MAX)
4437 bnxt_hwrm_clear_em_filter(bp, filter);
4439 HWRM_PREP(&req, HWRM_CFA_EM_FLOW_ALLOC, BNXT_USE_KONG(bp));
4441 req.flags = rte_cpu_to_le_32(filter->flags);
4443 enables = filter->enables |
4444 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_ID;
4445 req.dst_id = rte_cpu_to_le_16(dst_id);
4447 if (filter->ip_addr_type) {
4448 req.ip_addr_type = filter->ip_addr_type;
4449 enables |= HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IPADDR_TYPE;
4452 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_L2_FILTER_ID)
4453 req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
4455 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_MACADDR)
4456 memcpy(req.src_macaddr, filter->src_macaddr,
4457 RTE_ETHER_ADDR_LEN);
4459 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_MACADDR)
4460 memcpy(req.dst_macaddr, filter->dst_macaddr,
4461 RTE_ETHER_ADDR_LEN);
4463 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_OVLAN_VID)
4464 req.ovlan_vid = filter->l2_ovlan;
4466 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IVLAN_VID)
4467 req.ivlan_vid = filter->l2_ivlan;
4469 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_ETHERTYPE)
4470 req.ethertype = rte_cpu_to_be_16(filter->ethertype);
4472 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IP_PROTOCOL)
4473 req.ip_protocol = filter->ip_protocol;
4475 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_IPADDR)
4476 req.src_ipaddr[0] = rte_cpu_to_be_32(filter->src_ipaddr[0]);
4478 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_IPADDR)
4479 req.dst_ipaddr[0] = rte_cpu_to_be_32(filter->dst_ipaddr[0]);
4481 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_PORT)
4482 req.src_port = rte_cpu_to_be_16(filter->src_port);
4484 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_PORT)
4485 req.dst_port = rte_cpu_to_be_16(filter->dst_port);
4487 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_MIRROR_VNIC_ID)
4488 req.mirror_vnic_id = filter->mirror_vnic_id;
4490 req.enables = rte_cpu_to_le_32(enables);
4492 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
4494 HWRM_CHECK_RESULT();
4496 filter->fw_em_filter_id = rte_le_to_cpu_64(resp->em_filter_id);
4502 int bnxt_hwrm_clear_em_filter(struct bnxt *bp, struct bnxt_filter_info *filter)
4505 struct hwrm_cfa_em_flow_free_input req = {.req_type = 0 };
4506 struct hwrm_cfa_em_flow_free_output *resp = bp->hwrm_cmd_resp_addr;
4508 if (filter->fw_em_filter_id == UINT64_MAX)
4511 HWRM_PREP(&req, HWRM_CFA_EM_FLOW_FREE, BNXT_USE_KONG(bp));
4513 req.em_filter_id = rte_cpu_to_le_64(filter->fw_em_filter_id);
4515 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
4517 HWRM_CHECK_RESULT();
4520 filter->fw_em_filter_id = UINT64_MAX;
4521 filter->fw_l2_filter_id = UINT64_MAX;
4526 int bnxt_hwrm_set_ntuple_filter(struct bnxt *bp,
4528 struct bnxt_filter_info *filter)
4531 struct hwrm_cfa_ntuple_filter_alloc_input req = {.req_type = 0 };
4532 struct hwrm_cfa_ntuple_filter_alloc_output *resp =
4533 bp->hwrm_cmd_resp_addr;
4534 uint32_t enables = 0;
4536 if (filter->fw_ntuple_filter_id != UINT64_MAX)
4537 bnxt_hwrm_clear_ntuple_filter(bp, filter);
4539 HWRM_PREP(&req, HWRM_CFA_NTUPLE_FILTER_ALLOC, BNXT_USE_CHIMP_MB);
4541 req.flags = rte_cpu_to_le_32(filter->flags);
4543 enables = filter->enables |
4544 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_ID;
4545 req.dst_id = rte_cpu_to_le_16(dst_id);
4547 if (filter->ip_addr_type) {
4548 req.ip_addr_type = filter->ip_addr_type;
4550 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_IPADDR_TYPE;
4553 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_L2_FILTER_ID)
4554 req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
4556 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_MACADDR)
4557 memcpy(req.src_macaddr, filter->src_macaddr,
4558 RTE_ETHER_ADDR_LEN);
4560 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_ETHERTYPE)
4561 req.ethertype = rte_cpu_to_be_16(filter->ethertype);
4563 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_IP_PROTOCOL)
4564 req.ip_protocol = filter->ip_protocol;
4566 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_IPADDR)
4567 req.src_ipaddr[0] = rte_cpu_to_le_32(filter->src_ipaddr[0]);
4569 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_IPADDR_MASK)
4570 req.src_ipaddr_mask[0] =
4571 rte_cpu_to_le_32(filter->src_ipaddr_mask[0]);
4573 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_IPADDR)
4574 req.dst_ipaddr[0] = rte_cpu_to_le_32(filter->dst_ipaddr[0]);
4576 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_IPADDR_MASK)
4577 req.dst_ipaddr_mask[0] =
4578 rte_cpu_to_be_32(filter->dst_ipaddr_mask[0]);
4580 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_PORT)
4581 req.src_port = rte_cpu_to_le_16(filter->src_port);
4583 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_PORT_MASK)
4584 req.src_port_mask = rte_cpu_to_le_16(filter->src_port_mask);
4586 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_PORT)
4587 req.dst_port = rte_cpu_to_le_16(filter->dst_port);
4589 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_PORT_MASK)
4590 req.dst_port_mask = rte_cpu_to_le_16(filter->dst_port_mask);
4592 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_MIRROR_VNIC_ID)
4593 req.mirror_vnic_id = filter->mirror_vnic_id;
4595 req.enables = rte_cpu_to_le_32(enables);
4597 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4599 HWRM_CHECK_RESULT();
4601 filter->fw_ntuple_filter_id = rte_le_to_cpu_64(resp->ntuple_filter_id);
4602 filter->flow_id = rte_le_to_cpu_32(resp->flow_id);
4608 int bnxt_hwrm_clear_ntuple_filter(struct bnxt *bp,
4609 struct bnxt_filter_info *filter)
4612 struct hwrm_cfa_ntuple_filter_free_input req = {.req_type = 0 };
4613 struct hwrm_cfa_ntuple_filter_free_output *resp =
4614 bp->hwrm_cmd_resp_addr;
4616 if (filter->fw_ntuple_filter_id == UINT64_MAX)
4619 HWRM_PREP(&req, HWRM_CFA_NTUPLE_FILTER_FREE, BNXT_USE_CHIMP_MB);
4621 req.ntuple_filter_id = rte_cpu_to_le_64(filter->fw_ntuple_filter_id);
4623 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4625 HWRM_CHECK_RESULT();
4628 filter->fw_ntuple_filter_id = UINT64_MAX;
4634 bnxt_vnic_rss_configure_thor(struct bnxt *bp, struct bnxt_vnic_info *vnic)
4636 struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
4637 uint8_t *rx_queue_state = bp->eth_dev->data->rx_queue_state;
4638 struct hwrm_vnic_rss_cfg_input req = {.req_type = 0 };
4639 struct bnxt_rx_queue **rxqs = bp->rx_queues;
4640 uint16_t *ring_tbl = vnic->rss_table;
4641 int nr_ctxs = vnic->num_lb_ctxts;
4642 int max_rings = bp->rx_nr_rings;
4646 for (i = 0, k = 0; i < nr_ctxs; i++) {
4647 struct bnxt_rx_ring_info *rxr;
4648 struct bnxt_cp_ring_info *cpr;
4650 HWRM_PREP(&req, HWRM_VNIC_RSS_CFG, BNXT_USE_CHIMP_MB);
4652 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
4653 req.hash_type = rte_cpu_to_le_32(vnic->hash_type);
4654 req.hash_mode_flags = vnic->hash_mode;
4656 req.ring_grp_tbl_addr =
4657 rte_cpu_to_le_64(vnic->rss_table_dma_addr +
4658 i * BNXT_RSS_ENTRIES_PER_CTX_THOR *
4659 2 * sizeof(*ring_tbl));
4660 req.hash_key_tbl_addr =
4661 rte_cpu_to_le_64(vnic->rss_hash_key_dma_addr);
4663 req.ring_table_pair_index = i;
4664 req.rss_ctx_idx = rte_cpu_to_le_16(vnic->fw_grp_ids[i]);
4666 for (j = 0; j < 64; j++) {
4669 /* Find next active ring. */
4670 for (cnt = 0; cnt < max_rings; cnt++) {
4671 if (rx_queue_state[k] !=
4672 RTE_ETH_QUEUE_STATE_STOPPED)
4674 if (++k == max_rings)
4678 /* Return if no rings are active. */
4679 if (cnt == max_rings) {
4684 /* Add rx/cp ring pair to RSS table. */
4685 rxr = rxqs[k]->rx_ring;
4686 cpr = rxqs[k]->cp_ring;
4688 ring_id = rxr->rx_ring_struct->fw_ring_id;
4689 *ring_tbl++ = rte_cpu_to_le_16(ring_id);
4690 ring_id = cpr->cp_ring_struct->fw_ring_id;
4691 *ring_tbl++ = rte_cpu_to_le_16(ring_id);
4693 if (++k == max_rings)
4696 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req),
4699 HWRM_CHECK_RESULT();
4706 int bnxt_vnic_rss_configure(struct bnxt *bp, struct bnxt_vnic_info *vnic)
4708 unsigned int rss_idx, fw_idx, i;
4710 if (!(vnic->rss_table && vnic->hash_type))
4713 if (BNXT_CHIP_THOR(bp))
4714 return bnxt_vnic_rss_configure_thor(bp, vnic);
4716 if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
4719 if (vnic->rss_table && vnic->hash_type) {
4721 * Fill the RSS hash & redirection table with
4722 * ring group ids for all VNICs
4724 for (rss_idx = 0, fw_idx = 0; rss_idx < HW_HASH_INDEX_SIZE;
4725 rss_idx++, fw_idx++) {
4726 for (i = 0; i < bp->rx_cp_nr_rings; i++) {
4727 fw_idx %= bp->rx_cp_nr_rings;
4728 if (vnic->fw_grp_ids[fw_idx] !=
4733 if (i == bp->rx_cp_nr_rings)
4735 vnic->rss_table[rss_idx] = vnic->fw_grp_ids[fw_idx];
4737 return bnxt_hwrm_vnic_rss_cfg(bp, vnic);
4743 static void bnxt_hwrm_set_coal_params(struct bnxt_coal *hw_coal,
4744 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *req)
4748 req->num_cmpl_aggr_int = rte_cpu_to_le_16(hw_coal->num_cmpl_aggr_int);
4750 /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
4751 req->num_cmpl_dma_aggr = rte_cpu_to_le_16(hw_coal->num_cmpl_dma_aggr);
4753 /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
4754 req->num_cmpl_dma_aggr_during_int =
4755 rte_cpu_to_le_16(hw_coal->num_cmpl_dma_aggr_during_int);
4757 req->int_lat_tmr_max = rte_cpu_to_le_16(hw_coal->int_lat_tmr_max);
4759 /* min timer set to 1/2 of interrupt timer */
4760 req->int_lat_tmr_min = rte_cpu_to_le_16(hw_coal->int_lat_tmr_min);
4762 /* buf timer set to 1/4 of interrupt timer */
4763 req->cmpl_aggr_dma_tmr = rte_cpu_to_le_16(hw_coal->cmpl_aggr_dma_tmr);
4765 req->cmpl_aggr_dma_tmr_during_int =
4766 rte_cpu_to_le_16(hw_coal->cmpl_aggr_dma_tmr_during_int);
4768 flags = HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_TIMER_RESET |
4769 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_RING_IDLE;
4770 req->flags = rte_cpu_to_le_16(flags);
4773 static int bnxt_hwrm_set_coal_params_thor(struct bnxt *bp,
4774 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *agg_req)
4776 struct hwrm_ring_aggint_qcaps_input req = {0};
4777 struct hwrm_ring_aggint_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
4782 HWRM_PREP(&req, HWRM_RING_AGGINT_QCAPS, BNXT_USE_CHIMP_MB);
4783 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4784 HWRM_CHECK_RESULT();
4786 agg_req->num_cmpl_dma_aggr = resp->num_cmpl_dma_aggr_max;
4787 agg_req->cmpl_aggr_dma_tmr = resp->cmpl_aggr_dma_tmr_min;
4789 flags = HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_TIMER_RESET |
4790 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_RING_IDLE;
4791 agg_req->flags = rte_cpu_to_le_16(flags);
4793 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_ENABLES_CMPL_AGGR_DMA_TMR |
4794 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_ENABLES_NUM_CMPL_DMA_AGGR;
4795 agg_req->enables = rte_cpu_to_le_32(enables);
4801 int bnxt_hwrm_set_ring_coal(struct bnxt *bp,
4802 struct bnxt_coal *coal, uint16_t ring_id)
4804 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req = {0};
4805 struct hwrm_ring_cmpl_ring_cfg_aggint_params_output *resp =
4806 bp->hwrm_cmd_resp_addr;
4809 /* Set ring coalesce parameters only for 100G NICs */
4810 if (BNXT_CHIP_THOR(bp)) {
4811 if (bnxt_hwrm_set_coal_params_thor(bp, &req))
4813 } else if (bnxt_stratus_device(bp)) {
4814 bnxt_hwrm_set_coal_params(coal, &req);
4820 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS,
4822 req.ring_id = rte_cpu_to_le_16(ring_id);
4823 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4824 HWRM_CHECK_RESULT();
4829 #define BNXT_RTE_MEMZONE_FLAG (RTE_MEMZONE_1GB | RTE_MEMZONE_IOVA_CONTIG)
4830 int bnxt_hwrm_func_backing_store_qcaps(struct bnxt *bp)
4832 struct hwrm_func_backing_store_qcaps_input req = {0};
4833 struct hwrm_func_backing_store_qcaps_output *resp =
4834 bp->hwrm_cmd_resp_addr;
4835 struct bnxt_ctx_pg_info *ctx_pg;
4836 struct bnxt_ctx_mem_info *ctx;
4837 int total_alloc_len;
4838 int rc, i, tqm_rings;
4840 if (!BNXT_CHIP_THOR(bp) ||
4841 bp->hwrm_spec_code < HWRM_VERSION_1_9_2 ||
4846 HWRM_PREP(&req, HWRM_FUNC_BACKING_STORE_QCAPS, BNXT_USE_CHIMP_MB);
4847 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4848 HWRM_CHECK_RESULT_SILENT();
4850 total_alloc_len = sizeof(*ctx);
4851 ctx = rte_zmalloc("bnxt_ctx_mem", total_alloc_len,
4852 RTE_CACHE_LINE_SIZE);
4858 ctx->qp_max_entries = rte_le_to_cpu_32(resp->qp_max_entries);
4859 ctx->qp_min_qp1_entries =
4860 rte_le_to_cpu_16(resp->qp_min_qp1_entries);
4861 ctx->qp_max_l2_entries =
4862 rte_le_to_cpu_16(resp->qp_max_l2_entries);
4863 ctx->qp_entry_size = rte_le_to_cpu_16(resp->qp_entry_size);
4864 ctx->srq_max_l2_entries =
4865 rte_le_to_cpu_16(resp->srq_max_l2_entries);
4866 ctx->srq_max_entries = rte_le_to_cpu_32(resp->srq_max_entries);
4867 ctx->srq_entry_size = rte_le_to_cpu_16(resp->srq_entry_size);
4868 ctx->cq_max_l2_entries =
4869 rte_le_to_cpu_16(resp->cq_max_l2_entries);
4870 ctx->cq_max_entries = rte_le_to_cpu_32(resp->cq_max_entries);
4871 ctx->cq_entry_size = rte_le_to_cpu_16(resp->cq_entry_size);
4872 ctx->vnic_max_vnic_entries =
4873 rte_le_to_cpu_16(resp->vnic_max_vnic_entries);
4874 ctx->vnic_max_ring_table_entries =
4875 rte_le_to_cpu_16(resp->vnic_max_ring_table_entries);
4876 ctx->vnic_entry_size = rte_le_to_cpu_16(resp->vnic_entry_size);
4877 ctx->stat_max_entries =
4878 rte_le_to_cpu_32(resp->stat_max_entries);
4879 ctx->stat_entry_size = rte_le_to_cpu_16(resp->stat_entry_size);
4880 ctx->tqm_entry_size = rte_le_to_cpu_16(resp->tqm_entry_size);
4881 ctx->tqm_min_entries_per_ring =
4882 rte_le_to_cpu_32(resp->tqm_min_entries_per_ring);
4883 ctx->tqm_max_entries_per_ring =
4884 rte_le_to_cpu_32(resp->tqm_max_entries_per_ring);
4885 ctx->tqm_entries_multiple = resp->tqm_entries_multiple;
4886 if (!ctx->tqm_entries_multiple)
4887 ctx->tqm_entries_multiple = 1;
4888 ctx->mrav_max_entries =
4889 rte_le_to_cpu_32(resp->mrav_max_entries);
4890 ctx->mrav_entry_size = rte_le_to_cpu_16(resp->mrav_entry_size);
4891 ctx->tim_entry_size = rte_le_to_cpu_16(resp->tim_entry_size);
4892 ctx->tim_max_entries = rte_le_to_cpu_32(resp->tim_max_entries);
4893 ctx->tqm_fp_rings_count = resp->tqm_fp_rings_count;
4895 if (!ctx->tqm_fp_rings_count)
4896 ctx->tqm_fp_rings_count = bp->max_q;
4898 tqm_rings = ctx->tqm_fp_rings_count + 1;
4900 ctx_pg = rte_malloc("bnxt_ctx_pg_mem",
4901 sizeof(*ctx_pg) * tqm_rings,
4902 RTE_CACHE_LINE_SIZE);
4907 for (i = 0; i < tqm_rings; i++, ctx_pg++)
4908 ctx->tqm_mem[i] = ctx_pg;
4916 int bnxt_hwrm_func_backing_store_cfg(struct bnxt *bp, uint32_t enables)
4918 struct hwrm_func_backing_store_cfg_input req = {0};
4919 struct hwrm_func_backing_store_cfg_output *resp =
4920 bp->hwrm_cmd_resp_addr;
4921 struct bnxt_ctx_mem_info *ctx = bp->ctx;
4922 struct bnxt_ctx_pg_info *ctx_pg;
4923 uint32_t *num_entries;
4932 HWRM_PREP(&req, HWRM_FUNC_BACKING_STORE_CFG, BNXT_USE_CHIMP_MB);
4933 req.enables = rte_cpu_to_le_32(enables);
4935 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_QP) {
4936 ctx_pg = &ctx->qp_mem;
4937 req.qp_num_entries = rte_cpu_to_le_32(ctx_pg->entries);
4938 req.qp_num_qp1_entries =
4939 rte_cpu_to_le_16(ctx->qp_min_qp1_entries);
4940 req.qp_num_l2_entries =
4941 rte_cpu_to_le_16(ctx->qp_max_l2_entries);
4942 req.qp_entry_size = rte_cpu_to_le_16(ctx->qp_entry_size);
4943 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4944 &req.qpc_pg_size_qpc_lvl,
4948 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_SRQ) {
4949 ctx_pg = &ctx->srq_mem;
4950 req.srq_num_entries = rte_cpu_to_le_32(ctx_pg->entries);
4951 req.srq_num_l2_entries =
4952 rte_cpu_to_le_16(ctx->srq_max_l2_entries);
4953 req.srq_entry_size = rte_cpu_to_le_16(ctx->srq_entry_size);
4954 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4955 &req.srq_pg_size_srq_lvl,
4959 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_CQ) {
4960 ctx_pg = &ctx->cq_mem;
4961 req.cq_num_entries = rte_cpu_to_le_32(ctx_pg->entries);
4962 req.cq_num_l2_entries =
4963 rte_cpu_to_le_16(ctx->cq_max_l2_entries);
4964 req.cq_entry_size = rte_cpu_to_le_16(ctx->cq_entry_size);
4965 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4966 &req.cq_pg_size_cq_lvl,
4970 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_VNIC) {
4971 ctx_pg = &ctx->vnic_mem;
4972 req.vnic_num_vnic_entries =
4973 rte_cpu_to_le_16(ctx->vnic_max_vnic_entries);
4974 req.vnic_num_ring_table_entries =
4975 rte_cpu_to_le_16(ctx->vnic_max_ring_table_entries);
4976 req.vnic_entry_size = rte_cpu_to_le_16(ctx->vnic_entry_size);
4977 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4978 &req.vnic_pg_size_vnic_lvl,
4979 &req.vnic_page_dir);
4982 if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_STAT) {
4983 ctx_pg = &ctx->stat_mem;
4984 req.stat_num_entries = rte_cpu_to_le_16(ctx->stat_max_entries);
4985 req.stat_entry_size = rte_cpu_to_le_16(ctx->stat_entry_size);
4986 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
4987 &req.stat_pg_size_stat_lvl,
4988 &req.stat_page_dir);
4991 req.tqm_entry_size = rte_cpu_to_le_16(ctx->tqm_entry_size);
4992 num_entries = &req.tqm_sp_num_entries;
4993 pg_attr = &req.tqm_sp_pg_size_tqm_sp_lvl;
4994 pg_dir = &req.tqm_sp_page_dir;
4995 ena = HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_TQM_SP;
4996 for (i = 0; i < 9; i++, num_entries++, pg_attr++, pg_dir++, ena <<= 1) {
4997 if (!(enables & ena))
5000 req.tqm_entry_size = rte_cpu_to_le_16(ctx->tqm_entry_size);
5002 ctx_pg = ctx->tqm_mem[i];
5003 *num_entries = rte_cpu_to_le_16(ctx_pg->entries);
5004 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem, pg_attr, pg_dir);
5007 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5008 HWRM_CHECK_RESULT();
5014 int bnxt_hwrm_ext_port_qstats(struct bnxt *bp)
5016 struct hwrm_port_qstats_ext_input req = {0};
5017 struct hwrm_port_qstats_ext_output *resp = bp->hwrm_cmd_resp_addr;
5018 struct bnxt_pf_info *pf = bp->pf;
5021 if (!(bp->flags & BNXT_FLAG_EXT_RX_PORT_STATS ||
5022 bp->flags & BNXT_FLAG_EXT_TX_PORT_STATS))
5025 HWRM_PREP(&req, HWRM_PORT_QSTATS_EXT, BNXT_USE_CHIMP_MB);
5027 req.port_id = rte_cpu_to_le_16(pf->port_id);
5028 if (bp->flags & BNXT_FLAG_EXT_TX_PORT_STATS) {
5029 req.tx_stat_host_addr =
5030 rte_cpu_to_le_64(bp->hw_tx_port_stats_ext_map);
5032 rte_cpu_to_le_16(sizeof(struct tx_port_stats_ext));
5034 if (bp->flags & BNXT_FLAG_EXT_RX_PORT_STATS) {
5035 req.rx_stat_host_addr =
5036 rte_cpu_to_le_64(bp->hw_rx_port_stats_ext_map);
5038 rte_cpu_to_le_16(sizeof(struct rx_port_stats_ext));
5040 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5043 bp->fw_rx_port_stats_ext_size = 0;
5044 bp->fw_tx_port_stats_ext_size = 0;
5046 bp->fw_rx_port_stats_ext_size =
5047 rte_le_to_cpu_16(resp->rx_stat_size);
5048 bp->fw_tx_port_stats_ext_size =
5049 rte_le_to_cpu_16(resp->tx_stat_size);
5052 HWRM_CHECK_RESULT();
5059 bnxt_hwrm_tunnel_redirect(struct bnxt *bp, uint8_t type)
5061 struct hwrm_cfa_redirect_tunnel_type_alloc_input req = {0};
5062 struct hwrm_cfa_redirect_tunnel_type_alloc_output *resp =
5063 bp->hwrm_cmd_resp_addr;
5066 HWRM_PREP(&req, HWRM_CFA_REDIRECT_TUNNEL_TYPE_ALLOC, BNXT_USE_CHIMP_MB);
5067 req.tunnel_type = type;
5068 req.dest_fid = bp->fw_fid;
5069 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5070 HWRM_CHECK_RESULT();
5078 bnxt_hwrm_tunnel_redirect_free(struct bnxt *bp, uint8_t type)
5080 struct hwrm_cfa_redirect_tunnel_type_free_input req = {0};
5081 struct hwrm_cfa_redirect_tunnel_type_free_output *resp =
5082 bp->hwrm_cmd_resp_addr;
5085 HWRM_PREP(&req, HWRM_CFA_REDIRECT_TUNNEL_TYPE_FREE, BNXT_USE_CHIMP_MB);
5086 req.tunnel_type = type;
5087 req.dest_fid = bp->fw_fid;
5088 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5089 HWRM_CHECK_RESULT();
5096 int bnxt_hwrm_tunnel_redirect_query(struct bnxt *bp, uint32_t *type)
5098 struct hwrm_cfa_redirect_query_tunnel_type_input req = {0};
5099 struct hwrm_cfa_redirect_query_tunnel_type_output *resp =
5100 bp->hwrm_cmd_resp_addr;
5103 HWRM_PREP(&req, HWRM_CFA_REDIRECT_QUERY_TUNNEL_TYPE, BNXT_USE_CHIMP_MB);
5104 req.src_fid = bp->fw_fid;
5105 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5106 HWRM_CHECK_RESULT();
5109 *type = rte_le_to_cpu_32(resp->tunnel_mask);
5116 int bnxt_hwrm_tunnel_redirect_info(struct bnxt *bp, uint8_t tun_type,
5119 struct hwrm_cfa_redirect_tunnel_type_info_input req = {0};
5120 struct hwrm_cfa_redirect_tunnel_type_info_output *resp =
5121 bp->hwrm_cmd_resp_addr;
5124 HWRM_PREP(&req, HWRM_CFA_REDIRECT_TUNNEL_TYPE_INFO, BNXT_USE_CHIMP_MB);
5125 req.src_fid = bp->fw_fid;
5126 req.tunnel_type = tun_type;
5127 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5128 HWRM_CHECK_RESULT();
5131 *dst_fid = rte_le_to_cpu_16(resp->dest_fid);
5133 PMD_DRV_LOG(DEBUG, "dst_fid: %x\n", resp->dest_fid);
5140 int bnxt_hwrm_set_mac(struct bnxt *bp)
5142 struct hwrm_func_vf_cfg_output *resp = bp->hwrm_cmd_resp_addr;
5143 struct hwrm_func_vf_cfg_input req = {0};
5149 HWRM_PREP(&req, HWRM_FUNC_VF_CFG, BNXT_USE_CHIMP_MB);
5152 rte_cpu_to_le_32(HWRM_FUNC_VF_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
5153 memcpy(req.dflt_mac_addr, bp->mac_addr, RTE_ETHER_ADDR_LEN);
5155 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5157 HWRM_CHECK_RESULT();
5164 int bnxt_hwrm_if_change(struct bnxt *bp, bool up)
5166 struct hwrm_func_drv_if_change_output *resp = bp->hwrm_cmd_resp_addr;
5167 struct hwrm_func_drv_if_change_input req = {0};
5171 if (!(bp->fw_cap & BNXT_FW_CAP_IF_CHANGE))
5174 /* Do not issue FUNC_DRV_IF_CHANGE during reset recovery.
5175 * If we issue FUNC_DRV_IF_CHANGE with flags down before
5176 * FUNC_DRV_UNRGTR, FW resets before FUNC_DRV_UNRGTR
5178 if (!up && (bp->flags & BNXT_FLAG_FW_RESET))
5181 HWRM_PREP(&req, HWRM_FUNC_DRV_IF_CHANGE, BNXT_USE_CHIMP_MB);
5185 rte_cpu_to_le_32(HWRM_FUNC_DRV_IF_CHANGE_INPUT_FLAGS_UP);
5187 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5189 HWRM_CHECK_RESULT();
5190 flags = rte_le_to_cpu_32(resp->flags);
5196 if (flags & HWRM_FUNC_DRV_IF_CHANGE_OUTPUT_FLAGS_HOT_FW_RESET_DONE) {
5197 PMD_DRV_LOG(INFO, "FW reset happened while port was down\n");
5198 bp->flags |= BNXT_FLAG_IF_CHANGE_HOT_FW_RESET_DONE;
5204 int bnxt_hwrm_error_recovery_qcfg(struct bnxt *bp)
5206 struct hwrm_error_recovery_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
5207 struct bnxt_error_recovery_info *info = bp->recovery_info;
5208 struct hwrm_error_recovery_qcfg_input req = {0};
5213 /* Older FW does not have error recovery support */
5214 if (!(bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY))
5217 HWRM_PREP(&req, HWRM_ERROR_RECOVERY_QCFG, BNXT_USE_CHIMP_MB);
5219 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5221 HWRM_CHECK_RESULT();
5223 flags = rte_le_to_cpu_32(resp->flags);
5224 if (flags & HWRM_ERROR_RECOVERY_QCFG_OUTPUT_FLAGS_HOST)
5225 info->flags |= BNXT_FLAG_ERROR_RECOVERY_HOST;
5226 else if (flags & HWRM_ERROR_RECOVERY_QCFG_OUTPUT_FLAGS_CO_CPU)
5227 info->flags |= BNXT_FLAG_ERROR_RECOVERY_CO_CPU;
5229 if ((info->flags & BNXT_FLAG_ERROR_RECOVERY_CO_CPU) &&
5230 !(bp->flags & BNXT_FLAG_KONG_MB_EN)) {
5235 /* FW returned values are in units of 100msec */
5236 info->driver_polling_freq =
5237 rte_le_to_cpu_32(resp->driver_polling_freq) * 100;
5238 info->master_func_wait_period =
5239 rte_le_to_cpu_32(resp->master_func_wait_period) * 100;
5240 info->normal_func_wait_period =
5241 rte_le_to_cpu_32(resp->normal_func_wait_period) * 100;
5242 info->master_func_wait_period_after_reset =
5243 rte_le_to_cpu_32(resp->master_func_wait_period_after_reset) * 100;
5244 info->max_bailout_time_after_reset =
5245 rte_le_to_cpu_32(resp->max_bailout_time_after_reset) * 100;
5246 info->status_regs[BNXT_FW_STATUS_REG] =
5247 rte_le_to_cpu_32(resp->fw_health_status_reg);
5248 info->status_regs[BNXT_FW_HEARTBEAT_CNT_REG] =
5249 rte_le_to_cpu_32(resp->fw_heartbeat_reg);
5250 info->status_regs[BNXT_FW_RECOVERY_CNT_REG] =
5251 rte_le_to_cpu_32(resp->fw_reset_cnt_reg);
5252 info->status_regs[BNXT_FW_RESET_INPROG_REG] =
5253 rte_le_to_cpu_32(resp->reset_inprogress_reg);
5254 info->reg_array_cnt =
5255 rte_le_to_cpu_32(resp->reg_array_cnt);
5257 if (info->reg_array_cnt >= BNXT_NUM_RESET_REG) {
5262 for (i = 0; i < info->reg_array_cnt; i++) {
5263 info->reset_reg[i] =
5264 rte_le_to_cpu_32(resp->reset_reg[i]);
5265 info->reset_reg_val[i] =
5266 rte_le_to_cpu_32(resp->reset_reg_val[i]);
5267 info->delay_after_reset[i] =
5268 resp->delay_after_reset[i];
5273 /* Map the FW status registers */
5275 rc = bnxt_map_fw_health_status_regs(bp);
5278 rte_free(bp->recovery_info);
5279 bp->recovery_info = NULL;
5284 int bnxt_hwrm_fw_reset(struct bnxt *bp)
5286 struct hwrm_fw_reset_output *resp = bp->hwrm_cmd_resp_addr;
5287 struct hwrm_fw_reset_input req = {0};
5293 HWRM_PREP(&req, HWRM_FW_RESET, BNXT_USE_KONG(bp));
5295 req.embedded_proc_type =
5296 HWRM_FW_RESET_INPUT_EMBEDDED_PROC_TYPE_CHIP;
5297 req.selfrst_status =
5298 HWRM_FW_RESET_INPUT_SELFRST_STATUS_SELFRSTASAP;
5299 req.flags = HWRM_FW_RESET_INPUT_FLAGS_RESET_GRACEFUL;
5301 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req),
5304 HWRM_CHECK_RESULT();
5310 int bnxt_hwrm_port_ts_query(struct bnxt *bp, uint8_t path, uint64_t *timestamp)
5312 struct hwrm_port_ts_query_output *resp = bp->hwrm_cmd_resp_addr;
5313 struct hwrm_port_ts_query_input req = {0};
5314 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
5321 HWRM_PREP(&req, HWRM_PORT_TS_QUERY, BNXT_USE_CHIMP_MB);
5324 case BNXT_PTP_FLAGS_PATH_TX:
5325 flags |= HWRM_PORT_TS_QUERY_INPUT_FLAGS_PATH_TX;
5327 case BNXT_PTP_FLAGS_PATH_RX:
5328 flags |= HWRM_PORT_TS_QUERY_INPUT_FLAGS_PATH_RX;
5330 case BNXT_PTP_FLAGS_CURRENT_TIME:
5331 flags |= HWRM_PORT_TS_QUERY_INPUT_FLAGS_CURRENT_TIME;
5335 req.flags = rte_cpu_to_le_32(flags);
5336 req.port_id = rte_cpu_to_le_16(bp->pf->port_id);
5338 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5340 HWRM_CHECK_RESULT();
5343 *timestamp = rte_le_to_cpu_32(resp->ptp_msg_ts[0]);
5345 (uint64_t)(rte_le_to_cpu_32(resp->ptp_msg_ts[1])) << 32;
5352 int bnxt_hwrm_cfa_counter_qcaps(struct bnxt *bp, uint16_t *max_fc)
5356 struct hwrm_cfa_counter_qcaps_input req = {0};
5357 struct hwrm_cfa_counter_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
5359 if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp))) {
5361 "Not a PF or trusted VF. Command not supported\n");
5365 HWRM_PREP(&req, HWRM_CFA_COUNTER_QCAPS, BNXT_USE_KONG(bp));
5366 req.target_id = rte_cpu_to_le_16(bp->fw_fid);
5367 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
5369 HWRM_CHECK_RESULT();
5371 *max_fc = rte_le_to_cpu_16(resp->max_rx_fc);
5377 int bnxt_hwrm_ctx_rgtr(struct bnxt *bp, rte_iova_t dma_addr, uint16_t *ctx_id)
5380 struct hwrm_cfa_ctx_mem_rgtr_input req = {.req_type = 0 };
5381 struct hwrm_cfa_ctx_mem_rgtr_output *resp = bp->hwrm_cmd_resp_addr;
5383 if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp))) {
5385 "Not a PF or trusted VF. Command not supported\n");
5389 HWRM_PREP(&req, HWRM_CFA_CTX_MEM_RGTR, BNXT_USE_KONG(bp));
5391 req.page_level = HWRM_CFA_CTX_MEM_RGTR_INPUT_PAGE_LEVEL_LVL_0;
5392 req.page_size = HWRM_CFA_CTX_MEM_RGTR_INPUT_PAGE_SIZE_2M;
5393 req.page_dir = rte_cpu_to_le_64(dma_addr);
5395 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
5397 HWRM_CHECK_RESULT();
5399 *ctx_id = rte_le_to_cpu_16(resp->ctx_id);
5400 PMD_DRV_LOG(DEBUG, "ctx_id = %d\n", *ctx_id);
5407 int bnxt_hwrm_ctx_unrgtr(struct bnxt *bp, uint16_t ctx_id)
5410 struct hwrm_cfa_ctx_mem_unrgtr_input req = {.req_type = 0 };
5411 struct hwrm_cfa_ctx_mem_unrgtr_output *resp = bp->hwrm_cmd_resp_addr;
5413 if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp))) {
5415 "Not a PF or trusted VF. Command not supported\n");
5419 HWRM_PREP(&req, HWRM_CFA_CTX_MEM_UNRGTR, BNXT_USE_KONG(bp));
5421 req.ctx_id = rte_cpu_to_le_16(ctx_id);
5423 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
5425 HWRM_CHECK_RESULT();
5431 int bnxt_hwrm_cfa_counter_cfg(struct bnxt *bp, enum bnxt_flow_dir dir,
5432 uint16_t cntr, uint16_t ctx_id,
5433 uint32_t num_entries, bool enable)
5435 struct hwrm_cfa_counter_cfg_input req = {0};
5436 struct hwrm_cfa_counter_cfg_output *resp = bp->hwrm_cmd_resp_addr;
5440 if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp))) {
5442 "Not a PF or trusted VF. Command not supported\n");
5446 HWRM_PREP(&req, HWRM_CFA_COUNTER_CFG, BNXT_USE_KONG(bp));
5448 req.target_id = rte_cpu_to_le_16(bp->fw_fid);
5449 req.counter_type = rte_cpu_to_le_16(cntr);
5450 flags = enable ? HWRM_CFA_COUNTER_CFG_INPUT_FLAGS_CFG_MODE_ENABLE :
5451 HWRM_CFA_COUNTER_CFG_INPUT_FLAGS_CFG_MODE_DISABLE;
5452 flags |= HWRM_CFA_COUNTER_CFG_INPUT_FLAGS_DATA_TRANSFER_MODE_PULL;
5453 if (dir == BNXT_DIR_RX)
5454 flags |= HWRM_CFA_COUNTER_CFG_INPUT_FLAGS_PATH_RX;
5455 else if (dir == BNXT_DIR_TX)
5456 flags |= HWRM_CFA_COUNTER_CFG_INPUT_FLAGS_PATH_TX;
5457 req.flags = rte_cpu_to_le_16(flags);
5458 req.ctx_id = rte_cpu_to_le_16(ctx_id);
5459 req.num_entries = rte_cpu_to_le_32(num_entries);
5461 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
5462 HWRM_CHECK_RESULT();
5468 int bnxt_hwrm_cfa_counter_qstats(struct bnxt *bp,
5469 enum bnxt_flow_dir dir,
5471 uint16_t num_entries)
5473 struct hwrm_cfa_counter_qstats_output *resp = bp->hwrm_cmd_resp_addr;
5474 struct hwrm_cfa_counter_qstats_input req = {0};
5475 uint16_t flow_ctx_id = 0;
5479 if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp))) {
5481 "Not a PF or trusted VF. Command not supported\n");
5485 if (dir == BNXT_DIR_RX) {
5486 flow_ctx_id = bp->flow_stat->rx_fc_in_tbl.ctx_id;
5487 flags = HWRM_CFA_COUNTER_QSTATS_INPUT_FLAGS_PATH_RX;
5488 } else if (dir == BNXT_DIR_TX) {
5489 flow_ctx_id = bp->flow_stat->tx_fc_in_tbl.ctx_id;
5490 flags = HWRM_CFA_COUNTER_QSTATS_INPUT_FLAGS_PATH_TX;
5493 HWRM_PREP(&req, HWRM_CFA_COUNTER_QSTATS, BNXT_USE_KONG(bp));
5494 req.target_id = rte_cpu_to_le_16(bp->fw_fid);
5495 req.counter_type = rte_cpu_to_le_16(cntr);
5496 req.input_flow_ctx_id = rte_cpu_to_le_16(flow_ctx_id);
5497 req.num_entries = rte_cpu_to_le_16(num_entries);
5498 req.flags = rte_cpu_to_le_16(flags);
5499 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
5501 HWRM_CHECK_RESULT();
5507 int bnxt_hwrm_cfa_vfr_alloc(struct bnxt *bp, uint16_t vf_idx)
5509 struct hwrm_cfa_vfr_alloc_output *resp = bp->hwrm_cmd_resp_addr;
5510 struct hwrm_cfa_vfr_alloc_input req = {0};
5513 if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp))) {
5515 "Not a PF or trusted VF. Command not supported\n");
5519 HWRM_PREP(&req, HWRM_CFA_VFR_ALLOC, BNXT_USE_CHIMP_MB);
5520 req.vf_id = rte_cpu_to_le_16(vf_idx);
5521 snprintf(req.vfr_name, sizeof(req.vfr_name), "%svfr%d",
5522 bp->eth_dev->data->name, vf_idx);
5524 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5525 HWRM_CHECK_RESULT();
5528 PMD_DRV_LOG(DEBUG, "VFR %d allocated\n", vf_idx);
5532 int bnxt_hwrm_cfa_vfr_free(struct bnxt *bp, uint16_t vf_idx)
5534 struct hwrm_cfa_vfr_free_output *resp = bp->hwrm_cmd_resp_addr;
5535 struct hwrm_cfa_vfr_free_input req = {0};
5538 if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp))) {
5540 "Not a PF or trusted VF. Command not supported\n");
5544 HWRM_PREP(&req, HWRM_CFA_VFR_FREE, BNXT_USE_CHIMP_MB);
5545 req.vf_id = rte_cpu_to_le_16(vf_idx);
5546 snprintf(req.vfr_name, sizeof(req.vfr_name), "%svfr%d",
5547 bp->eth_dev->data->name, vf_idx);
5549 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5550 HWRM_CHECK_RESULT();
5552 PMD_DRV_LOG(DEBUG, "VFR %d freed\n", vf_idx);