1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2018 Broadcom
8 #include <rte_byteorder.h>
9 #include <rte_common.h>
10 #include <rte_cycles.h>
11 #include <rte_malloc.h>
12 #include <rte_memzone.h>
13 #include <rte_version.h>
17 #include "bnxt_filter.h"
18 #include "bnxt_hwrm.h"
21 #include "bnxt_ring.h"
24 #include "bnxt_vnic.h"
25 #include "hsi_struct_def_dpdk.h"
29 #define HWRM_CMD_TIMEOUT 10000
30 #define HWRM_SPEC_CODE_1_8_3 0x10803
31 #define HWRM_VERSION_1_9_1 0x10901
33 struct bnxt_plcmodes_cfg {
35 uint16_t jumbo_thresh;
37 uint16_t hds_threshold;
40 static int page_getenum(size_t size)
56 PMD_DRV_LOG(ERR, "Page size %zu out of range\n", size);
57 return sizeof(void *) * 8 - 1;
60 static int page_roundup(size_t size)
62 return 1 << page_getenum(size);
66 * HWRM Functions (sent to HWRM)
67 * These are named bnxt_hwrm_*() and return -1 if bnxt_hwrm_send_message()
68 * fails (ie: a timeout), and a positive non-zero HWRM error code if the HWRM
69 * command was failed by the ChiMP.
72 static int bnxt_hwrm_send_message(struct bnxt *bp, void *msg,
76 struct input *req = msg;
77 struct output *resp = bp->hwrm_cmd_resp_addr;
81 uint16_t max_req_len = bp->max_req_len;
82 struct hwrm_short_input short_input = { 0 };
84 if (bp->flags & BNXT_FLAG_SHORT_CMD) {
85 void *short_cmd_req = bp->hwrm_short_cmd_req_addr;
87 memset(short_cmd_req, 0, bp->max_req_len);
88 memcpy(short_cmd_req, req, msg_len);
90 short_input.req_type = rte_cpu_to_le_16(req->req_type);
91 short_input.signature = rte_cpu_to_le_16(
92 HWRM_SHORT_INPUT_SIGNATURE_SHORT_CMD);
93 short_input.size = rte_cpu_to_le_16(msg_len);
94 short_input.req_addr =
95 rte_cpu_to_le_64(bp->hwrm_short_cmd_req_dma_addr);
97 data = (uint32_t *)&short_input;
98 msg_len = sizeof(short_input);
100 /* Sync memory write before updating doorbell */
103 max_req_len = BNXT_HWRM_SHORT_REQ_LEN;
106 /* Write request msg to hwrm channel */
107 for (i = 0; i < msg_len; i += 4) {
108 bar = (uint8_t *)bp->bar0 + i;
109 rte_write32(*data, bar);
113 /* Zero the rest of the request space */
114 for (; i < max_req_len; i += 4) {
115 bar = (uint8_t *)bp->bar0 + i;
119 /* Ring channel doorbell */
120 bar = (uint8_t *)bp->bar0 + 0x100;
123 /* Poll for the valid bit */
124 for (i = 0; i < HWRM_CMD_TIMEOUT; i++) {
125 /* Sanity check on the resp->resp_len */
127 if (resp->resp_len && resp->resp_len <=
129 /* Last byte of resp contains the valid key */
130 valid = (uint8_t *)resp + resp->resp_len - 1;
131 if (*valid == HWRM_RESP_VALID_KEY)
137 if (i >= HWRM_CMD_TIMEOUT) {
138 PMD_DRV_LOG(ERR, "Error sending msg 0x%04x\n",
149 * HWRM_PREP() should be used to prepare *ALL* HWRM commands. It grabs the
150 * spinlock, and does initial processing.
152 * HWRM_CHECK_RESULT() returns errors on failure and may not be used. It
153 * releases the spinlock only if it returns. If the regular int return codes
154 * are not used by the function, HWRM_CHECK_RESULT() should not be used
155 * directly, rather it should be copied and modified to suit the function.
157 * HWRM_UNLOCK() must be called after all response processing is completed.
159 #define HWRM_PREP(req, type) do { \
160 rte_spinlock_lock(&bp->hwrm_lock); \
161 memset(bp->hwrm_cmd_resp_addr, 0, bp->max_resp_len); \
162 req.req_type = rte_cpu_to_le_16(HWRM_##type); \
163 req.cmpl_ring = rte_cpu_to_le_16(-1); \
164 req.seq_id = rte_cpu_to_le_16(bp->hwrm_cmd_seq++); \
165 req.target_id = rte_cpu_to_le_16(0xffff); \
166 req.resp_addr = rte_cpu_to_le_64(bp->hwrm_cmd_resp_dma_addr); \
169 #define HWRM_CHECK_RESULT_SILENT() do {\
171 rte_spinlock_unlock(&bp->hwrm_lock); \
174 if (resp->error_code) { \
175 rc = rte_le_to_cpu_16(resp->error_code); \
176 rte_spinlock_unlock(&bp->hwrm_lock); \
181 #define HWRM_CHECK_RESULT() do {\
183 PMD_DRV_LOG(ERR, "failed rc:%d\n", rc); \
184 rte_spinlock_unlock(&bp->hwrm_lock); \
187 if (resp->error_code) { \
188 rc = rte_le_to_cpu_16(resp->error_code); \
189 if (resp->resp_len >= 16) { \
190 struct hwrm_err_output *tmp_hwrm_err_op = \
193 "error %d:%d:%08x:%04x\n", \
194 rc, tmp_hwrm_err_op->cmd_err, \
196 tmp_hwrm_err_op->opaque_0), \
198 tmp_hwrm_err_op->opaque_1)); \
200 PMD_DRV_LOG(ERR, "error %d\n", rc); \
202 rte_spinlock_unlock(&bp->hwrm_lock); \
207 #define HWRM_UNLOCK() rte_spinlock_unlock(&bp->hwrm_lock)
209 int bnxt_hwrm_cfa_l2_clear_rx_mask(struct bnxt *bp, struct bnxt_vnic_info *vnic)
212 struct hwrm_cfa_l2_set_rx_mask_input req = {.req_type = 0 };
213 struct hwrm_cfa_l2_set_rx_mask_output *resp = bp->hwrm_cmd_resp_addr;
215 HWRM_PREP(req, CFA_L2_SET_RX_MASK);
216 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
219 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
227 int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp,
228 struct bnxt_vnic_info *vnic,
230 struct bnxt_vlan_table_entry *vlan_table)
233 struct hwrm_cfa_l2_set_rx_mask_input req = {.req_type = 0 };
234 struct hwrm_cfa_l2_set_rx_mask_output *resp = bp->hwrm_cmd_resp_addr;
237 if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
240 HWRM_PREP(req, CFA_L2_SET_RX_MASK);
241 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
243 /* FIXME add multicast flag, when multicast adding options is supported
246 if (vnic->flags & BNXT_VNIC_INFO_BCAST)
247 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_BCAST;
248 if (vnic->flags & BNXT_VNIC_INFO_UNTAGGED)
249 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLAN_NONVLAN;
250 if (vnic->flags & BNXT_VNIC_INFO_PROMISC)
251 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_PROMISCUOUS;
252 if (vnic->flags & BNXT_VNIC_INFO_ALLMULTI)
253 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
254 if (vnic->flags & BNXT_VNIC_INFO_MCAST)
255 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_MCAST;
256 if (vnic->mc_addr_cnt) {
257 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_MCAST;
258 req.num_mc_entries = rte_cpu_to_le_32(vnic->mc_addr_cnt);
259 req.mc_tbl_addr = rte_cpu_to_le_64(vnic->mc_list_dma_addr);
262 if (!(mask & HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLAN_NONVLAN))
263 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLANONLY;
264 req.vlan_tag_tbl_addr = rte_cpu_to_le_64(
265 rte_mem_virt2iova(vlan_table));
266 req.num_vlan_tags = rte_cpu_to_le_32((uint32_t)vlan_count);
268 req.mask = rte_cpu_to_le_32(mask);
270 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
278 int bnxt_hwrm_cfa_vlan_antispoof_cfg(struct bnxt *bp, uint16_t fid,
280 struct bnxt_vlan_antispoof_table_entry *vlan_table)
283 struct hwrm_cfa_vlan_antispoof_cfg_input req = {.req_type = 0 };
284 struct hwrm_cfa_vlan_antispoof_cfg_output *resp =
285 bp->hwrm_cmd_resp_addr;
288 * Older HWRM versions did not support this command, and the set_rx_mask
289 * list was used for anti-spoof. In 1.8.0, the TX path configuration was
290 * removed from set_rx_mask call, and this command was added.
292 * This command is also present from 1.7.8.11 and higher,
295 if (bp->fw_ver < ((1 << 24) | (8 << 16))) {
296 if (bp->fw_ver != ((1 << 24) | (7 << 16) | (8 << 8))) {
297 if (bp->fw_ver < ((1 << 24) | (7 << 16) | (8 << 8) |
302 HWRM_PREP(req, CFA_VLAN_ANTISPOOF_CFG);
303 req.fid = rte_cpu_to_le_16(fid);
305 req.vlan_tag_mask_tbl_addr =
306 rte_cpu_to_le_64(rte_mem_virt2iova(vlan_table));
307 req.num_vlan_entries = rte_cpu_to_le_32((uint32_t)vlan_count);
309 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
317 int bnxt_hwrm_clear_l2_filter(struct bnxt *bp,
318 struct bnxt_filter_info *filter)
321 struct hwrm_cfa_l2_filter_free_input req = {.req_type = 0 };
322 struct hwrm_cfa_l2_filter_free_output *resp = bp->hwrm_cmd_resp_addr;
324 if (filter->fw_l2_filter_id == UINT64_MAX)
327 HWRM_PREP(req, CFA_L2_FILTER_FREE);
329 req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
331 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
336 filter->fw_l2_filter_id = UINT64_MAX;
341 int bnxt_hwrm_set_l2_filter(struct bnxt *bp,
343 struct bnxt_filter_info *filter)
346 struct hwrm_cfa_l2_filter_alloc_input req = {.req_type = 0 };
347 struct hwrm_cfa_l2_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr;
348 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
349 const struct rte_eth_vmdq_rx_conf *conf =
350 &dev_conf->rx_adv_conf.vmdq_rx_conf;
351 uint32_t enables = 0;
352 uint16_t j = dst_id - 1;
354 //TODO: Is there a better way to add VLANs to each VNIC in case of VMDQ
355 if ((dev_conf->rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG) &&
356 conf->pool_map[j].pools & (1UL << j)) {
358 "Add vlan %u to vmdq pool %u\n",
359 conf->pool_map[j].vlan_id, j);
361 filter->l2_ivlan = conf->pool_map[j].vlan_id;
363 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN |
364 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN_MASK;
367 if (filter->fw_l2_filter_id != UINT64_MAX)
368 bnxt_hwrm_clear_l2_filter(bp, filter);
370 HWRM_PREP(req, CFA_L2_FILTER_ALLOC);
372 req.flags = rte_cpu_to_le_32(filter->flags);
374 enables = filter->enables |
375 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_DST_ID;
376 req.dst_id = rte_cpu_to_le_16(dst_id);
379 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR)
380 memcpy(req.l2_addr, filter->l2_addr,
383 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR_MASK)
384 memcpy(req.l2_addr_mask, filter->l2_addr_mask,
387 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN)
388 req.l2_ovlan = filter->l2_ovlan;
390 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN)
391 req.l2_ovlan = filter->l2_ivlan;
393 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN_MASK)
394 req.l2_ovlan_mask = filter->l2_ovlan_mask;
396 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN_MASK)
397 req.l2_ovlan_mask = filter->l2_ivlan_mask;
398 if (enables & HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_SRC_ID)
399 req.src_id = rte_cpu_to_le_32(filter->src_id);
400 if (enables & HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_SRC_TYPE)
401 req.src_type = filter->src_type;
403 req.enables = rte_cpu_to_le_32(enables);
405 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
409 filter->fw_l2_filter_id = rte_le_to_cpu_64(resp->l2_filter_id);
415 int bnxt_hwrm_ptp_cfg(struct bnxt *bp)
417 struct hwrm_port_mac_cfg_input req = {.req_type = 0};
418 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
425 HWRM_PREP(req, PORT_MAC_CFG);
428 flags |= HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_RX_TS_CAPTURE_ENABLE;
431 HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_RX_TS_CAPTURE_DISABLE;
432 if (ptp->tx_tstamp_en)
433 flags |= HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_TX_TS_CAPTURE_ENABLE;
436 HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_TX_TS_CAPTURE_DISABLE;
437 req.flags = rte_cpu_to_le_32(flags);
438 req.enables = rte_cpu_to_le_32
439 (HWRM_PORT_MAC_CFG_INPUT_ENABLES_RX_TS_CAPTURE_PTP_MSG_TYPE);
440 req.rx_ts_capture_ptp_msg_type = rte_cpu_to_le_16(ptp->rxctl);
442 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
448 static int bnxt_hwrm_ptp_qcfg(struct bnxt *bp)
451 struct hwrm_port_mac_ptp_qcfg_input req = {.req_type = 0};
452 struct hwrm_port_mac_ptp_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
453 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
455 /* if (bp->hwrm_spec_code < 0x10801 || ptp) TBD */
459 HWRM_PREP(req, PORT_MAC_PTP_QCFG);
461 req.port_id = rte_cpu_to_le_16(bp->pf.port_id);
463 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
467 if (!(resp->flags & HWRM_PORT_MAC_PTP_QCFG_OUTPUT_FLAGS_DIRECT_ACCESS))
470 ptp = rte_zmalloc("ptp_cfg", sizeof(*ptp), 0);
474 ptp->rx_regs[BNXT_PTP_RX_TS_L] =
475 rte_le_to_cpu_32(resp->rx_ts_reg_off_lower);
476 ptp->rx_regs[BNXT_PTP_RX_TS_H] =
477 rte_le_to_cpu_32(resp->rx_ts_reg_off_upper);
478 ptp->rx_regs[BNXT_PTP_RX_SEQ] =
479 rte_le_to_cpu_32(resp->rx_ts_reg_off_seq_id);
480 ptp->rx_regs[BNXT_PTP_RX_FIFO] =
481 rte_le_to_cpu_32(resp->rx_ts_reg_off_fifo);
482 ptp->rx_regs[BNXT_PTP_RX_FIFO_ADV] =
483 rte_le_to_cpu_32(resp->rx_ts_reg_off_fifo_adv);
484 ptp->tx_regs[BNXT_PTP_TX_TS_L] =
485 rte_le_to_cpu_32(resp->tx_ts_reg_off_lower);
486 ptp->tx_regs[BNXT_PTP_TX_TS_H] =
487 rte_le_to_cpu_32(resp->tx_ts_reg_off_upper);
488 ptp->tx_regs[BNXT_PTP_TX_SEQ] =
489 rte_le_to_cpu_32(resp->tx_ts_reg_off_seq_id);
490 ptp->tx_regs[BNXT_PTP_TX_FIFO] =
491 rte_le_to_cpu_32(resp->tx_ts_reg_off_fifo);
499 static int __bnxt_hwrm_func_qcaps(struct bnxt *bp)
502 struct hwrm_func_qcaps_input req = {.req_type = 0 };
503 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
504 uint16_t new_max_vfs;
508 HWRM_PREP(req, FUNC_QCAPS);
510 req.fid = rte_cpu_to_le_16(0xffff);
512 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
516 bp->max_ring_grps = rte_le_to_cpu_32(resp->max_hw_ring_grps);
517 flags = rte_le_to_cpu_32(resp->flags);
519 bp->pf.port_id = resp->port_id;
520 bp->pf.first_vf_id = rte_le_to_cpu_16(resp->first_vf_id);
521 bp->pf.total_vfs = rte_le_to_cpu_16(resp->max_vfs);
522 new_max_vfs = bp->pdev->max_vfs;
523 if (new_max_vfs != bp->pf.max_vfs) {
525 rte_free(bp->pf.vf_info);
526 bp->pf.vf_info = rte_malloc("bnxt_vf_info",
527 sizeof(bp->pf.vf_info[0]) * new_max_vfs, 0);
528 bp->pf.max_vfs = new_max_vfs;
529 for (i = 0; i < new_max_vfs; i++) {
530 bp->pf.vf_info[i].fid = bp->pf.first_vf_id + i;
531 bp->pf.vf_info[i].vlan_table =
532 rte_zmalloc("VF VLAN table",
535 if (bp->pf.vf_info[i].vlan_table == NULL)
537 "Fail to alloc VLAN table for VF %d\n",
541 bp->pf.vf_info[i].vlan_table);
542 bp->pf.vf_info[i].vlan_as_table =
543 rte_zmalloc("VF VLAN AS table",
546 if (bp->pf.vf_info[i].vlan_as_table == NULL)
548 "Alloc VLAN AS table for VF %d fail\n",
552 bp->pf.vf_info[i].vlan_as_table);
553 STAILQ_INIT(&bp->pf.vf_info[i].filter);
558 bp->fw_fid = rte_le_to_cpu_32(resp->fid);
559 memcpy(bp->dflt_mac_addr, &resp->mac_address, ETHER_ADDR_LEN);
560 bp->max_rsscos_ctx = rte_le_to_cpu_16(resp->max_rsscos_ctx);
561 bp->max_cp_rings = rte_le_to_cpu_16(resp->max_cmpl_rings);
562 bp->max_tx_rings = rte_le_to_cpu_16(resp->max_tx_rings);
563 bp->max_rx_rings = rte_le_to_cpu_16(resp->max_rx_rings);
564 bp->max_l2_ctx = rte_le_to_cpu_16(resp->max_l2_ctxs);
565 /* TODO: For now, do not support VMDq/RFS on VFs. */
570 bp->max_vnics = rte_le_to_cpu_16(resp->max_vnics);
574 bp->max_stat_ctx = rte_le_to_cpu_16(resp->max_stat_ctx);
576 bp->pf.total_vnics = rte_le_to_cpu_16(resp->max_vnics);
577 if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_PTP_SUPPORTED) {
578 bp->flags |= BNXT_FLAG_PTP_SUPPORTED;
579 PMD_DRV_LOG(INFO, "PTP SUPPORTED\n");
581 bnxt_hwrm_ptp_qcfg(bp);
590 int bnxt_hwrm_func_qcaps(struct bnxt *bp)
594 rc = __bnxt_hwrm_func_qcaps(bp);
595 if (!rc && bp->hwrm_spec_code >= HWRM_SPEC_CODE_1_8_3) {
596 rc = bnxt_hwrm_func_resc_qcaps(bp);
598 bp->flags |= BNXT_FLAG_NEW_RM;
604 int bnxt_hwrm_func_reset(struct bnxt *bp)
607 struct hwrm_func_reset_input req = {.req_type = 0 };
608 struct hwrm_func_reset_output *resp = bp->hwrm_cmd_resp_addr;
610 HWRM_PREP(req, FUNC_RESET);
612 req.enables = rte_cpu_to_le_32(0);
614 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
622 int bnxt_hwrm_func_driver_register(struct bnxt *bp)
625 struct hwrm_func_drv_rgtr_input req = {.req_type = 0 };
626 struct hwrm_func_drv_rgtr_output *resp = bp->hwrm_cmd_resp_addr;
628 if (bp->flags & BNXT_FLAG_REGISTERED)
631 HWRM_PREP(req, FUNC_DRV_RGTR);
632 req.enables = rte_cpu_to_le_32(HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_VER |
633 HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_ASYNC_EVENT_FWD);
634 req.ver_maj = RTE_VER_YEAR;
635 req.ver_min = RTE_VER_MONTH;
636 req.ver_upd = RTE_VER_MINOR;
639 req.enables |= rte_cpu_to_le_32(
640 HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_VF_REQ_FWD);
641 memcpy(req.vf_req_fwd, bp->pf.vf_req_fwd,
642 RTE_MIN(sizeof(req.vf_req_fwd),
643 sizeof(bp->pf.vf_req_fwd)));
646 * PF can sniff HWRM API issued by VF. This can be set up by
647 * linux driver and inherited by the DPDK PF driver. Clear
648 * this HWRM sniffer list in FW because DPDK PF driver does
652 rte_cpu_to_le_32(HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_FWD_NONE_MODE);
655 req.async_event_fwd[0] |=
656 rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_LINK_STATUS_CHANGE |
657 ASYNC_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED |
658 ASYNC_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE);
659 req.async_event_fwd[1] |=
660 rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_PF_DRVR_UNLOAD |
661 ASYNC_CMPL_EVENT_ID_VF_CFG_CHANGE);
663 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
668 bp->flags |= BNXT_FLAG_REGISTERED;
673 int bnxt_hwrm_check_vf_rings(struct bnxt *bp)
675 if (!(BNXT_VF(bp) && (bp->flags & BNXT_FLAG_NEW_RM)))
678 return bnxt_hwrm_func_reserve_vf_resc(bp, true);
681 int bnxt_hwrm_func_reserve_vf_resc(struct bnxt *bp, bool test)
686 struct hwrm_func_vf_cfg_output *resp = bp->hwrm_cmd_resp_addr;
687 struct hwrm_func_vf_cfg_input req = {0};
689 HWRM_PREP(req, FUNC_VF_CFG);
691 req.enables = rte_cpu_to_le_32
692 (HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_RX_RINGS |
693 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_TX_RINGS |
694 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
695 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
696 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS |
697 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_VNICS);
699 req.num_tx_rings = rte_cpu_to_le_16(bp->tx_nr_rings);
700 req.num_rx_rings = rte_cpu_to_le_16(bp->rx_nr_rings *
701 AGG_RING_MULTIPLIER);
702 req.num_stat_ctxs = rte_cpu_to_le_16(bp->rx_nr_rings + bp->tx_nr_rings);
703 req.num_cmpl_rings = rte_cpu_to_le_16(bp->rx_nr_rings +
705 req.num_hw_ring_grps = rte_cpu_to_le_16(bp->rx_nr_rings);
706 req.num_vnics = rte_cpu_to_le_16(bp->rx_nr_rings);
707 if (bp->vf_resv_strategy ==
708 HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESV_STRATEGY_MINIMAL_STATIC) {
709 enables = HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_VNICS |
710 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_L2_CTXS |
711 HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS;
712 req.enables |= rte_cpu_to_le_32(enables);
713 req.num_rsscos_ctxs = rte_cpu_to_le_16(BNXT_VF_RSV_NUM_RSS_CTX);
714 req.num_l2_ctxs = rte_cpu_to_le_16(BNXT_VF_RSV_NUM_L2_CTX);
715 req.num_vnics = rte_cpu_to_le_16(BNXT_VF_RSV_NUM_VNIC);
719 flags = HWRM_FUNC_VF_CFG_INPUT_FLAGS_TX_ASSETS_TEST |
720 HWRM_FUNC_VF_CFG_INPUT_FLAGS_RX_ASSETS_TEST |
721 HWRM_FUNC_VF_CFG_INPUT_FLAGS_CMPL_ASSETS_TEST |
722 HWRM_FUNC_VF_CFG_INPUT_FLAGS_RING_GRP_ASSETS_TEST |
723 HWRM_FUNC_VF_CFG_INPUT_FLAGS_STAT_CTX_ASSETS_TEST |
724 HWRM_FUNC_VF_CFG_INPUT_FLAGS_VNIC_ASSETS_TEST;
726 req.flags = rte_cpu_to_le_32(flags);
728 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
731 HWRM_CHECK_RESULT_SILENT();
739 int bnxt_hwrm_func_resc_qcaps(struct bnxt *bp)
742 struct hwrm_func_resource_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
743 struct hwrm_func_resource_qcaps_input req = {0};
745 HWRM_PREP(req, FUNC_RESOURCE_QCAPS);
746 req.fid = rte_cpu_to_le_16(0xffff);
748 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
753 bp->max_rsscos_ctx = rte_le_to_cpu_16(resp->max_rsscos_ctx);
754 bp->max_cp_rings = rte_le_to_cpu_16(resp->max_cmpl_rings);
755 bp->max_tx_rings = rte_le_to_cpu_16(resp->max_tx_rings);
756 bp->max_rx_rings = rte_le_to_cpu_16(resp->max_rx_rings);
757 bp->max_ring_grps = rte_le_to_cpu_32(resp->max_hw_ring_grps);
758 bp->max_l2_ctx = rte_le_to_cpu_16(resp->max_l2_ctxs);
759 bp->max_vnics = rte_le_to_cpu_16(resp->max_vnics);
760 bp->max_stat_ctx = rte_le_to_cpu_16(resp->max_stat_ctx);
762 bp->vf_resv_strategy = rte_le_to_cpu_16(resp->vf_reservation_strategy);
763 if (bp->vf_resv_strategy >
764 HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESV_STRATEGY_MINIMAL_STATIC)
765 bp->vf_resv_strategy =
766 HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESERVATION_STRATEGY_MAXIMAL;
772 int bnxt_hwrm_ver_get(struct bnxt *bp)
775 struct hwrm_ver_get_input req = {.req_type = 0 };
776 struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr;
779 uint16_t max_resp_len;
780 char type[RTE_MEMZONE_NAMESIZE];
781 uint32_t dev_caps_cfg;
783 bp->max_req_len = HWRM_MAX_REQ_LEN;
784 HWRM_PREP(req, VER_GET);
786 req.hwrm_intf_maj = HWRM_VERSION_MAJOR;
787 req.hwrm_intf_min = HWRM_VERSION_MINOR;
788 req.hwrm_intf_upd = HWRM_VERSION_UPDATE;
790 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
794 PMD_DRV_LOG(INFO, "%d.%d.%d:%d.%d.%d\n",
795 resp->hwrm_intf_maj_8b, resp->hwrm_intf_min_8b,
796 resp->hwrm_intf_upd_8b, resp->hwrm_fw_maj_8b,
797 resp->hwrm_fw_min_8b, resp->hwrm_fw_bld_8b);
798 bp->fw_ver = (resp->hwrm_fw_maj_8b << 24) |
799 (resp->hwrm_fw_min_8b << 16) |
800 (resp->hwrm_fw_bld_8b << 8) |
801 resp->hwrm_fw_rsvd_8b;
802 PMD_DRV_LOG(INFO, "Driver HWRM version: %d.%d.%d\n",
803 HWRM_VERSION_MAJOR, HWRM_VERSION_MINOR, HWRM_VERSION_UPDATE);
805 my_version = HWRM_VERSION_MAJOR << 16;
806 my_version |= HWRM_VERSION_MINOR << 8;
807 my_version |= HWRM_VERSION_UPDATE;
809 fw_version = resp->hwrm_intf_maj_8b << 16;
810 fw_version |= resp->hwrm_intf_min_8b << 8;
811 fw_version |= resp->hwrm_intf_upd_8b;
812 bp->hwrm_spec_code = fw_version;
814 if (resp->hwrm_intf_maj_8b != HWRM_VERSION_MAJOR) {
815 PMD_DRV_LOG(ERR, "Unsupported firmware API version\n");
820 if (my_version != fw_version) {
821 PMD_DRV_LOG(INFO, "BNXT Driver/HWRM API mismatch.\n");
822 if (my_version < fw_version) {
824 "Firmware API version is newer than driver.\n");
826 "The driver may be missing features.\n");
829 "Firmware API version is older than driver.\n");
831 "Not all driver features may be functional.\n");
835 if (bp->max_req_len > resp->max_req_win_len) {
836 PMD_DRV_LOG(ERR, "Unsupported request length\n");
839 bp->max_req_len = rte_le_to_cpu_16(resp->max_req_win_len);
840 max_resp_len = resp->max_resp_len;
841 dev_caps_cfg = rte_le_to_cpu_32(resp->dev_caps_cfg);
843 if (bp->max_resp_len != max_resp_len) {
844 sprintf(type, "bnxt_hwrm_%04x:%02x:%02x:%02x",
845 bp->pdev->addr.domain, bp->pdev->addr.bus,
846 bp->pdev->addr.devid, bp->pdev->addr.function);
848 rte_free(bp->hwrm_cmd_resp_addr);
850 bp->hwrm_cmd_resp_addr = rte_malloc(type, max_resp_len, 0);
851 if (bp->hwrm_cmd_resp_addr == NULL) {
855 rte_mem_lock_page(bp->hwrm_cmd_resp_addr);
856 bp->hwrm_cmd_resp_dma_addr =
857 rte_mem_virt2iova(bp->hwrm_cmd_resp_addr);
858 if (bp->hwrm_cmd_resp_dma_addr == 0) {
860 "Unable to map response buffer to physical memory.\n");
864 bp->max_resp_len = max_resp_len;
868 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
870 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_REQUIRED)) {
871 PMD_DRV_LOG(DEBUG, "Short command supported\n");
873 rte_free(bp->hwrm_short_cmd_req_addr);
875 bp->hwrm_short_cmd_req_addr = rte_malloc(type,
877 if (bp->hwrm_short_cmd_req_addr == NULL) {
881 rte_mem_lock_page(bp->hwrm_short_cmd_req_addr);
882 bp->hwrm_short_cmd_req_dma_addr =
883 rte_mem_virt2iova(bp->hwrm_short_cmd_req_addr);
884 if (bp->hwrm_short_cmd_req_dma_addr == 0) {
885 rte_free(bp->hwrm_short_cmd_req_addr);
887 "Unable to map buffer to physical memory.\n");
892 bp->flags |= BNXT_FLAG_SHORT_CMD;
900 int bnxt_hwrm_func_driver_unregister(struct bnxt *bp, uint32_t flags)
903 struct hwrm_func_drv_unrgtr_input req = {.req_type = 0 };
904 struct hwrm_func_drv_unrgtr_output *resp = bp->hwrm_cmd_resp_addr;
906 if (!(bp->flags & BNXT_FLAG_REGISTERED))
909 HWRM_PREP(req, FUNC_DRV_UNRGTR);
912 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
917 bp->flags &= ~BNXT_FLAG_REGISTERED;
922 static int bnxt_hwrm_port_phy_cfg(struct bnxt *bp, struct bnxt_link_info *conf)
925 struct hwrm_port_phy_cfg_input req = {0};
926 struct hwrm_port_phy_cfg_output *resp = bp->hwrm_cmd_resp_addr;
927 uint32_t enables = 0;
929 HWRM_PREP(req, PORT_PHY_CFG);
932 /* Setting Fixed Speed. But AutoNeg is ON, So disable it */
933 if (bp->link_info.auto_mode && conf->link_speed) {
934 req.auto_mode = HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_NONE;
935 PMD_DRV_LOG(DEBUG, "Disabling AutoNeg\n");
938 req.flags = rte_cpu_to_le_32(conf->phy_flags);
939 req.force_link_speed = rte_cpu_to_le_16(conf->link_speed);
940 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_MODE;
942 * Note, ChiMP FW 20.2.1 and 20.2.2 return an error when we set
943 * any auto mode, even "none".
945 if (!conf->link_speed) {
946 /* No speeds specified. Enable AutoNeg - all speeds */
948 HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_ALL_SPEEDS;
950 /* AutoNeg - Advertise speeds specified. */
951 if (conf->auto_link_speed_mask &&
952 !(conf->phy_flags & HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE)) {
954 HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_SPEED_MASK;
955 req.auto_link_speed_mask =
956 conf->auto_link_speed_mask;
958 HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_LINK_SPEED_MASK;
961 req.auto_duplex = conf->duplex;
962 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_DUPLEX;
963 req.auto_pause = conf->auto_pause;
964 req.force_pause = conf->force_pause;
965 /* Set force_pause if there is no auto or if there is a force */
966 if (req.auto_pause && !req.force_pause)
967 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_PAUSE;
969 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_FORCE_PAUSE;
971 req.enables = rte_cpu_to_le_32(enables);
974 rte_cpu_to_le_32(HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE_LINK_DWN);
975 PMD_DRV_LOG(INFO, "Force Link Down\n");
978 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
986 static int bnxt_hwrm_port_phy_qcfg(struct bnxt *bp,
987 struct bnxt_link_info *link_info)
990 struct hwrm_port_phy_qcfg_input req = {0};
991 struct hwrm_port_phy_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
993 HWRM_PREP(req, PORT_PHY_QCFG);
995 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
999 link_info->phy_link_status = resp->link;
1000 link_info->link_up =
1001 (link_info->phy_link_status ==
1002 HWRM_PORT_PHY_QCFG_OUTPUT_LINK_LINK) ? 1 : 0;
1003 link_info->link_speed = rte_le_to_cpu_16(resp->link_speed);
1004 link_info->duplex = resp->duplex_cfg;
1005 link_info->pause = resp->pause;
1006 link_info->auto_pause = resp->auto_pause;
1007 link_info->force_pause = resp->force_pause;
1008 link_info->auto_mode = resp->auto_mode;
1009 link_info->phy_type = resp->phy_type;
1010 link_info->media_type = resp->media_type;
1012 link_info->support_speeds = rte_le_to_cpu_16(resp->support_speeds);
1013 link_info->auto_link_speed = rte_le_to_cpu_16(resp->auto_link_speed);
1014 link_info->preemphasis = rte_le_to_cpu_32(resp->preemphasis);
1015 link_info->force_link_speed = rte_le_to_cpu_16(resp->force_link_speed);
1016 link_info->phy_ver[0] = resp->phy_maj;
1017 link_info->phy_ver[1] = resp->phy_min;
1018 link_info->phy_ver[2] = resp->phy_bld;
1022 PMD_DRV_LOG(DEBUG, "Link Speed %d\n", link_info->link_speed);
1023 PMD_DRV_LOG(DEBUG, "Auto Mode %d\n", link_info->auto_mode);
1024 PMD_DRV_LOG(DEBUG, "Support Speeds %x\n", link_info->support_speeds);
1025 PMD_DRV_LOG(DEBUG, "Auto Link Speed %x\n", link_info->auto_link_speed);
1026 PMD_DRV_LOG(DEBUG, "Auto Link Speed Mask %x\n",
1027 link_info->auto_link_speed_mask);
1028 PMD_DRV_LOG(DEBUG, "Forced Link Speed %x\n",
1029 link_info->force_link_speed);
1034 int bnxt_hwrm_queue_qportcfg(struct bnxt *bp)
1037 struct hwrm_queue_qportcfg_input req = {.req_type = 0 };
1038 struct hwrm_queue_qportcfg_output *resp = bp->hwrm_cmd_resp_addr;
1041 HWRM_PREP(req, QUEUE_QPORTCFG);
1043 req.flags = HWRM_QUEUE_QPORTCFG_INPUT_FLAGS_PATH_TX;
1044 /* HWRM Version >= 1.9.1 */
1045 if (bp->hwrm_spec_code >= HWRM_VERSION_1_9_1)
1047 HWRM_QUEUE_QPORTCFG_INPUT_DRV_QMAP_CAP_ENABLED;
1048 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1050 HWRM_CHECK_RESULT();
1052 #define GET_QUEUE_INFO(x) \
1053 bp->cos_queue[x].id = resp->queue_id##x; \
1054 bp->cos_queue[x].profile = resp->queue_id##x##_service_profile
1067 if (bp->hwrm_spec_code < HWRM_VERSION_1_9_1) {
1068 bp->tx_cosq_id = bp->cos_queue[0].id;
1070 /* iterate and find the COSq profile to use for Tx */
1071 for (i = 0; i < BNXT_COS_QUEUE_COUNT; i++) {
1072 if (bp->cos_queue[i].profile ==
1073 HWRM_QUEUE_SERVICE_PROFILE_LOSSY) {
1074 bp->tx_cosq_id = bp->cos_queue[i].id;
1079 PMD_DRV_LOG(DEBUG, "Tx Cos Queue to use: %d\n", bp->tx_cosq_id);
1084 int bnxt_hwrm_ring_alloc(struct bnxt *bp,
1085 struct bnxt_ring *ring,
1086 uint32_t ring_type, uint32_t map_index,
1087 uint32_t stats_ctx_id, uint32_t cmpl_ring_id)
1090 uint32_t enables = 0;
1091 struct hwrm_ring_alloc_input req = {.req_type = 0 };
1092 struct hwrm_ring_alloc_output *resp = bp->hwrm_cmd_resp_addr;
1094 HWRM_PREP(req, RING_ALLOC);
1096 req.page_tbl_addr = rte_cpu_to_le_64(ring->bd_dma);
1097 req.fbo = rte_cpu_to_le_32(0);
1098 /* Association of ring index with doorbell index */
1099 req.logical_id = rte_cpu_to_le_16(map_index);
1100 req.length = rte_cpu_to_le_32(ring->ring_size);
1102 switch (ring_type) {
1103 case HWRM_RING_ALLOC_INPUT_RING_TYPE_TX:
1104 req.queue_id = rte_cpu_to_le_16(bp->tx_cosq_id);
1106 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX:
1107 req.ring_type = ring_type;
1108 req.cmpl_ring_id = rte_cpu_to_le_16(cmpl_ring_id);
1109 req.stat_ctx_id = rte_cpu_to_le_16(stats_ctx_id);
1110 if (stats_ctx_id != INVALID_STATS_CTX_ID)
1112 HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID;
1114 case HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL:
1115 req.ring_type = ring_type;
1117 * TODO: Some HWRM versions crash with
1118 * HWRM_RING_ALLOC_INPUT_INT_MODE_POLL
1120 req.int_mode = HWRM_RING_ALLOC_INPUT_INT_MODE_MSIX;
1123 PMD_DRV_LOG(ERR, "hwrm alloc invalid ring type %d\n",
1128 req.enables = rte_cpu_to_le_32(enables);
1130 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1132 if (rc || resp->error_code) {
1133 if (rc == 0 && resp->error_code)
1134 rc = rte_le_to_cpu_16(resp->error_code);
1135 switch (ring_type) {
1136 case HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL:
1138 "hwrm_ring_alloc cp failed. rc:%d\n", rc);
1141 case HWRM_RING_FREE_INPUT_RING_TYPE_RX:
1143 "hwrm_ring_alloc rx failed. rc:%d\n", rc);
1146 case HWRM_RING_FREE_INPUT_RING_TYPE_TX:
1148 "hwrm_ring_alloc tx failed. rc:%d\n", rc);
1152 PMD_DRV_LOG(ERR, "Invalid ring. rc:%d\n", rc);
1158 ring->fw_ring_id = rte_le_to_cpu_16(resp->ring_id);
1163 int bnxt_hwrm_ring_free(struct bnxt *bp,
1164 struct bnxt_ring *ring, uint32_t ring_type)
1167 struct hwrm_ring_free_input req = {.req_type = 0 };
1168 struct hwrm_ring_free_output *resp = bp->hwrm_cmd_resp_addr;
1170 HWRM_PREP(req, RING_FREE);
1172 req.ring_type = ring_type;
1173 req.ring_id = rte_cpu_to_le_16(ring->fw_ring_id);
1175 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1177 if (rc || resp->error_code) {
1178 if (rc == 0 && resp->error_code)
1179 rc = rte_le_to_cpu_16(resp->error_code);
1182 switch (ring_type) {
1183 case HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL:
1184 PMD_DRV_LOG(ERR, "hwrm_ring_free cp failed. rc:%d\n",
1187 case HWRM_RING_FREE_INPUT_RING_TYPE_RX:
1188 PMD_DRV_LOG(ERR, "hwrm_ring_free rx failed. rc:%d\n",
1191 case HWRM_RING_FREE_INPUT_RING_TYPE_TX:
1192 PMD_DRV_LOG(ERR, "hwrm_ring_free tx failed. rc:%d\n",
1196 PMD_DRV_LOG(ERR, "Invalid ring, rc:%d\n", rc);
1204 int bnxt_hwrm_ring_grp_alloc(struct bnxt *bp, unsigned int idx)
1207 struct hwrm_ring_grp_alloc_input req = {.req_type = 0 };
1208 struct hwrm_ring_grp_alloc_output *resp = bp->hwrm_cmd_resp_addr;
1210 HWRM_PREP(req, RING_GRP_ALLOC);
1212 req.cr = rte_cpu_to_le_16(bp->grp_info[idx].cp_fw_ring_id);
1213 req.rr = rte_cpu_to_le_16(bp->grp_info[idx].rx_fw_ring_id);
1214 req.ar = rte_cpu_to_le_16(bp->grp_info[idx].ag_fw_ring_id);
1215 req.sc = rte_cpu_to_le_16(bp->grp_info[idx].fw_stats_ctx);
1217 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1219 HWRM_CHECK_RESULT();
1221 bp->grp_info[idx].fw_grp_id =
1222 rte_le_to_cpu_16(resp->ring_group_id);
1229 int bnxt_hwrm_ring_grp_free(struct bnxt *bp, unsigned int idx)
1232 struct hwrm_ring_grp_free_input req = {.req_type = 0 };
1233 struct hwrm_ring_grp_free_output *resp = bp->hwrm_cmd_resp_addr;
1235 HWRM_PREP(req, RING_GRP_FREE);
1237 req.ring_group_id = rte_cpu_to_le_16(bp->grp_info[idx].fw_grp_id);
1239 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1241 HWRM_CHECK_RESULT();
1244 bp->grp_info[idx].fw_grp_id = INVALID_HW_RING_ID;
1248 int bnxt_hwrm_stat_clear(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
1251 struct hwrm_stat_ctx_clr_stats_input req = {.req_type = 0 };
1252 struct hwrm_stat_ctx_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
1254 if (cpr->hw_stats_ctx_id == (uint32_t)HWRM_NA_SIGNATURE)
1257 HWRM_PREP(req, STAT_CTX_CLR_STATS);
1259 req.stat_ctx_id = rte_cpu_to_le_16(cpr->hw_stats_ctx_id);
1261 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1263 HWRM_CHECK_RESULT();
1269 int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
1270 unsigned int idx __rte_unused)
1273 struct hwrm_stat_ctx_alloc_input req = {.req_type = 0 };
1274 struct hwrm_stat_ctx_alloc_output *resp = bp->hwrm_cmd_resp_addr;
1276 HWRM_PREP(req, STAT_CTX_ALLOC);
1278 req.update_period_ms = rte_cpu_to_le_32(0);
1280 req.stats_dma_addr =
1281 rte_cpu_to_le_64(cpr->hw_stats_map);
1283 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1285 HWRM_CHECK_RESULT();
1287 cpr->hw_stats_ctx_id = rte_le_to_cpu_16(resp->stat_ctx_id);
1294 int bnxt_hwrm_stat_ctx_free(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
1295 unsigned int idx __rte_unused)
1298 struct hwrm_stat_ctx_free_input req = {.req_type = 0 };
1299 struct hwrm_stat_ctx_free_output *resp = bp->hwrm_cmd_resp_addr;
1301 HWRM_PREP(req, STAT_CTX_FREE);
1303 req.stat_ctx_id = rte_cpu_to_le_16(cpr->hw_stats_ctx_id);
1305 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1307 HWRM_CHECK_RESULT();
1313 int bnxt_hwrm_vnic_alloc(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1316 struct hwrm_vnic_alloc_input req = { 0 };
1317 struct hwrm_vnic_alloc_output *resp = bp->hwrm_cmd_resp_addr;
1319 /* map ring groups to this vnic */
1320 PMD_DRV_LOG(DEBUG, "Alloc VNIC. Start %x, End %x\n",
1321 vnic->start_grp_id, vnic->end_grp_id);
1322 for (i = vnic->start_grp_id, j = 0; i <= vnic->end_grp_id; i++, j++)
1323 vnic->fw_grp_ids[j] = bp->grp_info[i].fw_grp_id;
1324 vnic->dflt_ring_grp = bp->grp_info[vnic->start_grp_id].fw_grp_id;
1325 vnic->rss_rule = (uint16_t)HWRM_NA_SIGNATURE;
1326 vnic->cos_rule = (uint16_t)HWRM_NA_SIGNATURE;
1327 vnic->lb_rule = (uint16_t)HWRM_NA_SIGNATURE;
1328 vnic->mru = bp->eth_dev->data->mtu + ETHER_HDR_LEN +
1329 ETHER_CRC_LEN + VLAN_TAG_SIZE;
1330 HWRM_PREP(req, VNIC_ALLOC);
1332 if (vnic->func_default)
1334 rte_cpu_to_le_32(HWRM_VNIC_ALLOC_INPUT_FLAGS_DEFAULT);
1335 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1337 HWRM_CHECK_RESULT();
1339 vnic->fw_vnic_id = rte_le_to_cpu_16(resp->vnic_id);
1341 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
1345 static int bnxt_hwrm_vnic_plcmodes_qcfg(struct bnxt *bp,
1346 struct bnxt_vnic_info *vnic,
1347 struct bnxt_plcmodes_cfg *pmode)
1350 struct hwrm_vnic_plcmodes_qcfg_input req = {.req_type = 0 };
1351 struct hwrm_vnic_plcmodes_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
1353 HWRM_PREP(req, VNIC_PLCMODES_QCFG);
1355 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1357 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1359 HWRM_CHECK_RESULT();
1361 pmode->flags = rte_le_to_cpu_32(resp->flags);
1362 /* dflt_vnic bit doesn't exist in the _cfg command */
1363 pmode->flags &= ~(HWRM_VNIC_PLCMODES_QCFG_OUTPUT_FLAGS_DFLT_VNIC);
1364 pmode->jumbo_thresh = rte_le_to_cpu_16(resp->jumbo_thresh);
1365 pmode->hds_offset = rte_le_to_cpu_16(resp->hds_offset);
1366 pmode->hds_threshold = rte_le_to_cpu_16(resp->hds_threshold);
1373 static int bnxt_hwrm_vnic_plcmodes_cfg(struct bnxt *bp,
1374 struct bnxt_vnic_info *vnic,
1375 struct bnxt_plcmodes_cfg *pmode)
1378 struct hwrm_vnic_plcmodes_cfg_input req = {.req_type = 0 };
1379 struct hwrm_vnic_plcmodes_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1381 HWRM_PREP(req, VNIC_PLCMODES_CFG);
1383 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1384 req.flags = rte_cpu_to_le_32(pmode->flags);
1385 req.jumbo_thresh = rte_cpu_to_le_16(pmode->jumbo_thresh);
1386 req.hds_offset = rte_cpu_to_le_16(pmode->hds_offset);
1387 req.hds_threshold = rte_cpu_to_le_16(pmode->hds_threshold);
1388 req.enables = rte_cpu_to_le_32(
1389 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_HDS_THRESHOLD_VALID |
1390 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_HDS_OFFSET_VALID |
1391 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_JUMBO_THRESH_VALID
1394 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1396 HWRM_CHECK_RESULT();
1402 int bnxt_hwrm_vnic_cfg(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1405 struct hwrm_vnic_cfg_input req = {.req_type = 0 };
1406 struct hwrm_vnic_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1407 uint32_t ctx_enable_flag = 0;
1408 struct bnxt_plcmodes_cfg pmodes;
1410 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1411 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
1415 rc = bnxt_hwrm_vnic_plcmodes_qcfg(bp, vnic, &pmodes);
1419 HWRM_PREP(req, VNIC_CFG);
1421 /* Only RSS support for now TBD: COS & LB */
1423 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_ENABLES_DFLT_RING_GRP);
1424 if (vnic->lb_rule != 0xffff)
1425 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_LB_RULE;
1426 if (vnic->cos_rule != 0xffff)
1427 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_COS_RULE;
1428 if (vnic->rss_rule != 0xffff) {
1429 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_MRU;
1430 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_RSS_RULE;
1432 req.enables |= rte_cpu_to_le_32(ctx_enable_flag);
1433 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1434 req.dflt_ring_grp = rte_cpu_to_le_16(vnic->dflt_ring_grp);
1435 req.rss_rule = rte_cpu_to_le_16(vnic->rss_rule);
1436 req.cos_rule = rte_cpu_to_le_16(vnic->cos_rule);
1437 req.lb_rule = rte_cpu_to_le_16(vnic->lb_rule);
1438 req.mru = rte_cpu_to_le_16(vnic->mru);
1439 if (vnic->func_default)
1441 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_DEFAULT);
1442 if (vnic->vlan_strip)
1444 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_VLAN_STRIP_MODE);
1447 rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_BD_STALL_MODE);
1448 if (vnic->roce_dual)
1449 req.flags |= rte_cpu_to_le_32(
1450 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_DUAL_VNIC_MODE);
1451 if (vnic->roce_only)
1452 req.flags |= rte_cpu_to_le_32(
1453 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_ONLY_VNIC_MODE);
1454 if (vnic->rss_dflt_cr)
1455 req.flags |= rte_cpu_to_le_32(
1456 HWRM_VNIC_QCFG_OUTPUT_FLAGS_RSS_DFLT_CR_MODE);
1458 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1460 HWRM_CHECK_RESULT();
1463 rc = bnxt_hwrm_vnic_plcmodes_cfg(bp, vnic, &pmodes);
1468 int bnxt_hwrm_vnic_qcfg(struct bnxt *bp, struct bnxt_vnic_info *vnic,
1472 struct hwrm_vnic_qcfg_input req = {.req_type = 0 };
1473 struct hwrm_vnic_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
1475 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1476 PMD_DRV_LOG(DEBUG, "VNIC QCFG ID %d\n", vnic->fw_vnic_id);
1479 HWRM_PREP(req, VNIC_QCFG);
1482 rte_cpu_to_le_32(HWRM_VNIC_QCFG_INPUT_ENABLES_VF_ID_VALID);
1483 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1484 req.vf_id = rte_cpu_to_le_16(fw_vf_id);
1486 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1488 HWRM_CHECK_RESULT();
1490 vnic->dflt_ring_grp = rte_le_to_cpu_16(resp->dflt_ring_grp);
1491 vnic->rss_rule = rte_le_to_cpu_16(resp->rss_rule);
1492 vnic->cos_rule = rte_le_to_cpu_16(resp->cos_rule);
1493 vnic->lb_rule = rte_le_to_cpu_16(resp->lb_rule);
1494 vnic->mru = rte_le_to_cpu_16(resp->mru);
1495 vnic->func_default = rte_le_to_cpu_32(
1496 resp->flags) & HWRM_VNIC_QCFG_OUTPUT_FLAGS_DEFAULT;
1497 vnic->vlan_strip = rte_le_to_cpu_32(resp->flags) &
1498 HWRM_VNIC_QCFG_OUTPUT_FLAGS_VLAN_STRIP_MODE;
1499 vnic->bd_stall = rte_le_to_cpu_32(resp->flags) &
1500 HWRM_VNIC_QCFG_OUTPUT_FLAGS_BD_STALL_MODE;
1501 vnic->roce_dual = rte_le_to_cpu_32(resp->flags) &
1502 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_DUAL_VNIC_MODE;
1503 vnic->roce_only = rte_le_to_cpu_32(resp->flags) &
1504 HWRM_VNIC_QCFG_OUTPUT_FLAGS_ROCE_ONLY_VNIC_MODE;
1505 vnic->rss_dflt_cr = rte_le_to_cpu_32(resp->flags) &
1506 HWRM_VNIC_QCFG_OUTPUT_FLAGS_RSS_DFLT_CR_MODE;
1513 int bnxt_hwrm_vnic_ctx_alloc(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1516 struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req = {.req_type = 0 };
1517 struct hwrm_vnic_rss_cos_lb_ctx_alloc_output *resp =
1518 bp->hwrm_cmd_resp_addr;
1520 HWRM_PREP(req, VNIC_RSS_COS_LB_CTX_ALLOC);
1522 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1524 HWRM_CHECK_RESULT();
1526 vnic->rss_rule = rte_le_to_cpu_16(resp->rss_cos_lb_ctx_id);
1528 PMD_DRV_LOG(DEBUG, "VNIC RSS Rule %x\n", vnic->rss_rule);
1533 int bnxt_hwrm_vnic_ctx_free(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1536 struct hwrm_vnic_rss_cos_lb_ctx_free_input req = {.req_type = 0 };
1537 struct hwrm_vnic_rss_cos_lb_ctx_free_output *resp =
1538 bp->hwrm_cmd_resp_addr;
1540 if (vnic->rss_rule == 0xffff) {
1541 PMD_DRV_LOG(DEBUG, "VNIC RSS Rule %x\n", vnic->rss_rule);
1544 HWRM_PREP(req, VNIC_RSS_COS_LB_CTX_FREE);
1546 req.rss_cos_lb_ctx_id = rte_cpu_to_le_16(vnic->rss_rule);
1548 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1550 HWRM_CHECK_RESULT();
1553 vnic->rss_rule = INVALID_HW_RING_ID;
1558 int bnxt_hwrm_vnic_free(struct bnxt *bp, struct bnxt_vnic_info *vnic)
1561 struct hwrm_vnic_free_input req = {.req_type = 0 };
1562 struct hwrm_vnic_free_output *resp = bp->hwrm_cmd_resp_addr;
1564 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1565 PMD_DRV_LOG(DEBUG, "VNIC FREE ID %x\n", vnic->fw_vnic_id);
1569 HWRM_PREP(req, VNIC_FREE);
1571 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1573 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1575 HWRM_CHECK_RESULT();
1578 vnic->fw_vnic_id = INVALID_HW_RING_ID;
1582 int bnxt_hwrm_vnic_rss_cfg(struct bnxt *bp,
1583 struct bnxt_vnic_info *vnic)
1586 struct hwrm_vnic_rss_cfg_input req = {.req_type = 0 };
1587 struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1589 HWRM_PREP(req, VNIC_RSS_CFG);
1591 req.hash_type = rte_cpu_to_le_32(vnic->hash_type);
1592 req.hash_mode_flags = vnic->hash_mode;
1594 req.ring_grp_tbl_addr =
1595 rte_cpu_to_le_64(vnic->rss_table_dma_addr);
1596 req.hash_key_tbl_addr =
1597 rte_cpu_to_le_64(vnic->rss_hash_key_dma_addr);
1598 req.rss_ctx_idx = rte_cpu_to_le_16(vnic->rss_rule);
1600 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1602 HWRM_CHECK_RESULT();
1608 int bnxt_hwrm_vnic_plcmode_cfg(struct bnxt *bp,
1609 struct bnxt_vnic_info *vnic)
1612 struct hwrm_vnic_plcmodes_cfg_input req = {.req_type = 0 };
1613 struct hwrm_vnic_plcmodes_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1616 if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
1617 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
1621 HWRM_PREP(req, VNIC_PLCMODES_CFG);
1623 req.flags = rte_cpu_to_le_32(
1624 HWRM_VNIC_PLCMODES_CFG_INPUT_FLAGS_JUMBO_PLACEMENT);
1626 req.enables = rte_cpu_to_le_32(
1627 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_JUMBO_THRESH_VALID);
1629 size = rte_pktmbuf_data_room_size(bp->rx_queues[0]->mb_pool);
1630 size -= RTE_PKTMBUF_HEADROOM;
1632 req.jumbo_thresh = rte_cpu_to_le_16(size);
1633 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1635 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1637 HWRM_CHECK_RESULT();
1643 int bnxt_hwrm_vnic_tpa_cfg(struct bnxt *bp,
1644 struct bnxt_vnic_info *vnic, bool enable)
1647 struct hwrm_vnic_tpa_cfg_input req = {.req_type = 0 };
1648 struct hwrm_vnic_tpa_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1650 HWRM_PREP(req, VNIC_TPA_CFG);
1653 req.enables = rte_cpu_to_le_32(
1654 HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MAX_AGG_SEGS |
1655 HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MAX_AGGS |
1656 HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MIN_AGG_LEN);
1657 req.flags = rte_cpu_to_le_32(
1658 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_TPA |
1659 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_ENCAP_TPA |
1660 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_RSC_WND_UPDATE |
1661 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_GRO |
1662 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_AGG_WITH_ECN |
1663 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_AGG_WITH_SAME_GRE_SEQ);
1664 req.max_agg_segs = rte_cpu_to_le_16(5);
1666 rte_cpu_to_le_16(HWRM_VNIC_TPA_CFG_INPUT_MAX_AGGS_MAX);
1667 req.min_agg_len = rte_cpu_to_le_32(512);
1669 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
1671 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1673 HWRM_CHECK_RESULT();
1679 int bnxt_hwrm_func_vf_mac(struct bnxt *bp, uint16_t vf, const uint8_t *mac_addr)
1681 struct hwrm_func_cfg_input req = {0};
1682 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1685 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[vf].func_cfg_flags);
1686 req.enables = rte_cpu_to_le_32(
1687 HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
1688 memcpy(req.dflt_mac_addr, mac_addr, sizeof(req.dflt_mac_addr));
1689 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
1691 HWRM_PREP(req, FUNC_CFG);
1693 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1694 HWRM_CHECK_RESULT();
1697 bp->pf.vf_info[vf].random_mac = false;
1702 int bnxt_hwrm_func_qstats_tx_drop(struct bnxt *bp, uint16_t fid,
1706 struct hwrm_func_qstats_input req = {.req_type = 0};
1707 struct hwrm_func_qstats_output *resp = bp->hwrm_cmd_resp_addr;
1709 HWRM_PREP(req, FUNC_QSTATS);
1711 req.fid = rte_cpu_to_le_16(fid);
1713 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1715 HWRM_CHECK_RESULT();
1718 *dropped = rte_le_to_cpu_64(resp->tx_drop_pkts);
1725 int bnxt_hwrm_func_qstats(struct bnxt *bp, uint16_t fid,
1726 struct rte_eth_stats *stats)
1729 struct hwrm_func_qstats_input req = {.req_type = 0};
1730 struct hwrm_func_qstats_output *resp = bp->hwrm_cmd_resp_addr;
1732 HWRM_PREP(req, FUNC_QSTATS);
1734 req.fid = rte_cpu_to_le_16(fid);
1736 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1738 HWRM_CHECK_RESULT();
1740 stats->ipackets = rte_le_to_cpu_64(resp->rx_ucast_pkts);
1741 stats->ipackets += rte_le_to_cpu_64(resp->rx_mcast_pkts);
1742 stats->ipackets += rte_le_to_cpu_64(resp->rx_bcast_pkts);
1743 stats->ibytes = rte_le_to_cpu_64(resp->rx_ucast_bytes);
1744 stats->ibytes += rte_le_to_cpu_64(resp->rx_mcast_bytes);
1745 stats->ibytes += rte_le_to_cpu_64(resp->rx_bcast_bytes);
1747 stats->opackets = rte_le_to_cpu_64(resp->tx_ucast_pkts);
1748 stats->opackets += rte_le_to_cpu_64(resp->tx_mcast_pkts);
1749 stats->opackets += rte_le_to_cpu_64(resp->tx_bcast_pkts);
1750 stats->obytes = rte_le_to_cpu_64(resp->tx_ucast_bytes);
1751 stats->obytes += rte_le_to_cpu_64(resp->tx_mcast_bytes);
1752 stats->obytes += rte_le_to_cpu_64(resp->tx_bcast_bytes);
1754 stats->imissed = rte_le_to_cpu_64(resp->rx_discard_pkts);
1755 stats->ierrors = rte_le_to_cpu_64(resp->rx_drop_pkts);
1756 stats->oerrors = rte_le_to_cpu_64(resp->tx_discard_pkts);
1763 int bnxt_hwrm_func_clr_stats(struct bnxt *bp, uint16_t fid)
1766 struct hwrm_func_clr_stats_input req = {.req_type = 0};
1767 struct hwrm_func_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
1769 HWRM_PREP(req, FUNC_CLR_STATS);
1771 req.fid = rte_cpu_to_le_16(fid);
1773 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
1775 HWRM_CHECK_RESULT();
1782 * HWRM utility functions
1785 int bnxt_clear_all_hwrm_stat_ctxs(struct bnxt *bp)
1790 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
1791 struct bnxt_tx_queue *txq;
1792 struct bnxt_rx_queue *rxq;
1793 struct bnxt_cp_ring_info *cpr;
1795 if (i >= bp->rx_cp_nr_rings) {
1796 txq = bp->tx_queues[i - bp->rx_cp_nr_rings];
1799 rxq = bp->rx_queues[i];
1803 rc = bnxt_hwrm_stat_clear(bp, cpr);
1810 int bnxt_free_all_hwrm_stat_ctxs(struct bnxt *bp)
1814 struct bnxt_cp_ring_info *cpr;
1816 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
1818 if (i >= bp->rx_cp_nr_rings) {
1819 cpr = bp->tx_queues[i - bp->rx_cp_nr_rings]->cp_ring;
1821 cpr = bp->rx_queues[i]->cp_ring;
1822 bp->grp_info[i].fw_stats_ctx = -1;
1824 if (cpr->hw_stats_ctx_id != HWRM_NA_SIGNATURE) {
1825 rc = bnxt_hwrm_stat_ctx_free(bp, cpr, i);
1826 cpr->hw_stats_ctx_id = HWRM_NA_SIGNATURE;
1834 int bnxt_alloc_all_hwrm_stat_ctxs(struct bnxt *bp)
1839 for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
1840 struct bnxt_tx_queue *txq;
1841 struct bnxt_rx_queue *rxq;
1842 struct bnxt_cp_ring_info *cpr;
1844 if (i >= bp->rx_cp_nr_rings) {
1845 txq = bp->tx_queues[i - bp->rx_cp_nr_rings];
1848 rxq = bp->rx_queues[i];
1852 rc = bnxt_hwrm_stat_ctx_alloc(bp, cpr, i);
1860 int bnxt_free_all_hwrm_ring_grps(struct bnxt *bp)
1865 for (idx = 0; idx < bp->rx_cp_nr_rings; idx++) {
1867 if (bp->grp_info[idx].fw_grp_id == INVALID_HW_RING_ID)
1870 rc = bnxt_hwrm_ring_grp_free(bp, idx);
1878 static void bnxt_free_cp_ring(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
1880 struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
1882 bnxt_hwrm_ring_free(bp, cp_ring,
1883 HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL);
1884 cp_ring->fw_ring_id = INVALID_HW_RING_ID;
1885 memset(cpr->cp_desc_ring, 0, cpr->cp_ring_struct->ring_size *
1886 sizeof(*cpr->cp_desc_ring));
1887 cpr->cp_raw_cons = 0;
1890 void bnxt_free_hwrm_rx_ring(struct bnxt *bp, int queue_index)
1892 struct bnxt_rx_queue *rxq = bp->rx_queues[queue_index];
1893 struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
1894 struct bnxt_ring *ring = rxr->rx_ring_struct;
1895 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
1897 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
1898 bnxt_hwrm_ring_free(bp, ring,
1899 HWRM_RING_FREE_INPUT_RING_TYPE_RX);
1900 ring->fw_ring_id = INVALID_HW_RING_ID;
1901 bp->grp_info[queue_index].rx_fw_ring_id = INVALID_HW_RING_ID;
1902 memset(rxr->rx_desc_ring, 0,
1903 rxr->rx_ring_struct->ring_size *
1904 sizeof(*rxr->rx_desc_ring));
1905 memset(rxr->rx_buf_ring, 0,
1906 rxr->rx_ring_struct->ring_size *
1907 sizeof(*rxr->rx_buf_ring));
1910 ring = rxr->ag_ring_struct;
1911 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
1912 bnxt_hwrm_ring_free(bp, ring,
1913 HWRM_RING_FREE_INPUT_RING_TYPE_RX);
1914 ring->fw_ring_id = INVALID_HW_RING_ID;
1915 memset(rxr->ag_buf_ring, 0,
1916 rxr->ag_ring_struct->ring_size *
1917 sizeof(*rxr->ag_buf_ring));
1919 bp->grp_info[queue_index].ag_fw_ring_id = INVALID_HW_RING_ID;
1921 if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID)
1922 bnxt_free_cp_ring(bp, cpr);
1924 bp->grp_info[queue_index].cp_fw_ring_id = INVALID_HW_RING_ID;
1927 int bnxt_free_all_hwrm_rings(struct bnxt *bp)
1931 for (i = 0; i < bp->tx_cp_nr_rings; i++) {
1932 struct bnxt_tx_queue *txq = bp->tx_queues[i];
1933 struct bnxt_tx_ring_info *txr = txq->tx_ring;
1934 struct bnxt_ring *ring = txr->tx_ring_struct;
1935 struct bnxt_cp_ring_info *cpr = txq->cp_ring;
1937 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
1938 bnxt_hwrm_ring_free(bp, ring,
1939 HWRM_RING_FREE_INPUT_RING_TYPE_TX);
1940 ring->fw_ring_id = INVALID_HW_RING_ID;
1941 memset(txr->tx_desc_ring, 0,
1942 txr->tx_ring_struct->ring_size *
1943 sizeof(*txr->tx_desc_ring));
1944 memset(txr->tx_buf_ring, 0,
1945 txr->tx_ring_struct->ring_size *
1946 sizeof(*txr->tx_buf_ring));
1950 if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID) {
1951 bnxt_free_cp_ring(bp, cpr);
1952 cpr->cp_ring_struct->fw_ring_id = INVALID_HW_RING_ID;
1956 for (i = 0; i < bp->rx_cp_nr_rings; i++)
1957 bnxt_free_hwrm_rx_ring(bp, i);
1962 int bnxt_alloc_all_hwrm_ring_grps(struct bnxt *bp)
1967 for (i = 0; i < bp->rx_cp_nr_rings; i++) {
1968 rc = bnxt_hwrm_ring_grp_alloc(bp, i);
1975 void bnxt_free_hwrm_resources(struct bnxt *bp)
1977 /* Release memzone */
1978 rte_free(bp->hwrm_cmd_resp_addr);
1979 rte_free(bp->hwrm_short_cmd_req_addr);
1980 bp->hwrm_cmd_resp_addr = NULL;
1981 bp->hwrm_short_cmd_req_addr = NULL;
1982 bp->hwrm_cmd_resp_dma_addr = 0;
1983 bp->hwrm_short_cmd_req_dma_addr = 0;
1986 int bnxt_alloc_hwrm_resources(struct bnxt *bp)
1988 struct rte_pci_device *pdev = bp->pdev;
1989 char type[RTE_MEMZONE_NAMESIZE];
1991 sprintf(type, "bnxt_hwrm_%04x:%02x:%02x:%02x", pdev->addr.domain,
1992 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
1993 bp->max_resp_len = HWRM_MAX_RESP_LEN;
1994 bp->hwrm_cmd_resp_addr = rte_malloc(type, bp->max_resp_len, 0);
1995 rte_mem_lock_page(bp->hwrm_cmd_resp_addr);
1996 if (bp->hwrm_cmd_resp_addr == NULL)
1998 bp->hwrm_cmd_resp_dma_addr =
1999 rte_mem_virt2iova(bp->hwrm_cmd_resp_addr);
2000 if (bp->hwrm_cmd_resp_dma_addr == 0) {
2002 "unable to map response address to physical memory\n");
2005 rte_spinlock_init(&bp->hwrm_lock);
2010 int bnxt_clear_hwrm_vnic_filters(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2012 struct bnxt_filter_info *filter;
2015 STAILQ_FOREACH(filter, &vnic->filter, next) {
2016 if (filter->filter_type == HWRM_CFA_EM_FILTER)
2017 rc = bnxt_hwrm_clear_em_filter(bp, filter);
2018 else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
2019 rc = bnxt_hwrm_clear_ntuple_filter(bp, filter);
2021 rc = bnxt_hwrm_clear_l2_filter(bp, filter);
2029 bnxt_clear_hwrm_vnic_flows(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2031 struct bnxt_filter_info *filter;
2032 struct rte_flow *flow;
2035 STAILQ_FOREACH(flow, &vnic->flow_list, next) {
2036 filter = flow->filter;
2037 PMD_DRV_LOG(ERR, "filter type %d\n", filter->filter_type);
2038 if (filter->filter_type == HWRM_CFA_EM_FILTER)
2039 rc = bnxt_hwrm_clear_em_filter(bp, filter);
2040 else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
2041 rc = bnxt_hwrm_clear_ntuple_filter(bp, filter);
2043 rc = bnxt_hwrm_clear_l2_filter(bp, filter);
2045 STAILQ_REMOVE(&vnic->flow_list, flow, rte_flow, next);
2053 int bnxt_set_hwrm_vnic_filters(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2055 struct bnxt_filter_info *filter;
2058 STAILQ_FOREACH(filter, &vnic->filter, next) {
2059 if (filter->filter_type == HWRM_CFA_EM_FILTER)
2060 rc = bnxt_hwrm_set_em_filter(bp, filter->dst_id,
2062 else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
2063 rc = bnxt_hwrm_set_ntuple_filter(bp, filter->dst_id,
2066 rc = bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id,
2074 void bnxt_free_tunnel_ports(struct bnxt *bp)
2076 if (bp->vxlan_port_cnt)
2077 bnxt_hwrm_tunnel_dst_port_free(bp, bp->vxlan_fw_dst_port_id,
2078 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_VXLAN);
2080 if (bp->geneve_port_cnt)
2081 bnxt_hwrm_tunnel_dst_port_free(bp, bp->geneve_fw_dst_port_id,
2082 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_GENEVE);
2083 bp->geneve_port = 0;
2086 void bnxt_free_all_hwrm_resources(struct bnxt *bp)
2090 if (bp->vnic_info == NULL)
2094 * Cleanup VNICs in reverse order, to make sure the L2 filter
2095 * from vnic0 is last to be cleaned up.
2097 for (i = bp->nr_vnics - 1; i >= 0; i--) {
2098 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
2100 bnxt_clear_hwrm_vnic_flows(bp, vnic);
2102 bnxt_clear_hwrm_vnic_filters(bp, vnic);
2104 bnxt_hwrm_vnic_ctx_free(bp, vnic);
2106 bnxt_hwrm_vnic_tpa_cfg(bp, vnic, false);
2108 bnxt_hwrm_vnic_free(bp, vnic);
2110 /* Ring resources */
2111 bnxt_free_all_hwrm_rings(bp);
2112 bnxt_free_all_hwrm_ring_grps(bp);
2113 bnxt_free_all_hwrm_stat_ctxs(bp);
2114 bnxt_free_tunnel_ports(bp);
2117 static uint16_t bnxt_parse_eth_link_duplex(uint32_t conf_link_speed)
2119 uint8_t hw_link_duplex = HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH;
2121 if ((conf_link_speed & ETH_LINK_SPEED_FIXED) == ETH_LINK_SPEED_AUTONEG)
2122 return HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH;
2124 switch (conf_link_speed) {
2125 case ETH_LINK_SPEED_10M_HD:
2126 case ETH_LINK_SPEED_100M_HD:
2128 return HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_HALF;
2130 return hw_link_duplex;
2133 static uint16_t bnxt_check_eth_link_autoneg(uint32_t conf_link)
2135 return (conf_link & ETH_LINK_SPEED_FIXED) ? 0 : 1;
2138 static uint16_t bnxt_parse_eth_link_speed(uint32_t conf_link_speed)
2140 uint16_t eth_link_speed = 0;
2142 if (conf_link_speed == ETH_LINK_SPEED_AUTONEG)
2143 return ETH_LINK_SPEED_AUTONEG;
2145 switch (conf_link_speed & ~ETH_LINK_SPEED_FIXED) {
2146 case ETH_LINK_SPEED_100M:
2147 case ETH_LINK_SPEED_100M_HD:
2150 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_100MB;
2152 case ETH_LINK_SPEED_1G:
2154 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_1GB;
2156 case ETH_LINK_SPEED_2_5G:
2158 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_2_5GB;
2160 case ETH_LINK_SPEED_10G:
2162 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_10GB;
2164 case ETH_LINK_SPEED_20G:
2166 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_20GB;
2168 case ETH_LINK_SPEED_25G:
2170 HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_25GB;
2172 case ETH_LINK_SPEED_40G:
2174 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_40GB;
2176 case ETH_LINK_SPEED_50G:
2178 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_50GB;
2180 case ETH_LINK_SPEED_100G:
2182 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_100GB;
2186 "Unsupported link speed %d; default to AUTO\n",
2190 return eth_link_speed;
2193 #define BNXT_SUPPORTED_SPEEDS (ETH_LINK_SPEED_100M | ETH_LINK_SPEED_100M_HD | \
2194 ETH_LINK_SPEED_1G | ETH_LINK_SPEED_2_5G | \
2195 ETH_LINK_SPEED_10G | ETH_LINK_SPEED_20G | ETH_LINK_SPEED_25G | \
2196 ETH_LINK_SPEED_40G | ETH_LINK_SPEED_50G | ETH_LINK_SPEED_100G)
2198 static int bnxt_valid_link_speed(uint32_t link_speed, uint16_t port_id)
2202 if (link_speed == ETH_LINK_SPEED_AUTONEG)
2205 if (link_speed & ETH_LINK_SPEED_FIXED) {
2206 one_speed = link_speed & ~ETH_LINK_SPEED_FIXED;
2208 if (one_speed & (one_speed - 1)) {
2210 "Invalid advertised speeds (%u) for port %u\n",
2211 link_speed, port_id);
2214 if ((one_speed & BNXT_SUPPORTED_SPEEDS) != one_speed) {
2216 "Unsupported advertised speed (%u) for port %u\n",
2217 link_speed, port_id);
2221 if (!(link_speed & BNXT_SUPPORTED_SPEEDS)) {
2223 "Unsupported advertised speeds (%u) for port %u\n",
2224 link_speed, port_id);
2232 bnxt_parse_eth_link_speed_mask(struct bnxt *bp, uint32_t link_speed)
2236 if (link_speed == ETH_LINK_SPEED_AUTONEG) {
2237 if (bp->link_info.support_speeds)
2238 return bp->link_info.support_speeds;
2239 link_speed = BNXT_SUPPORTED_SPEEDS;
2242 if (link_speed & ETH_LINK_SPEED_100M)
2243 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100MB;
2244 if (link_speed & ETH_LINK_SPEED_100M_HD)
2245 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100MB;
2246 if (link_speed & ETH_LINK_SPEED_1G)
2247 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_1GB;
2248 if (link_speed & ETH_LINK_SPEED_2_5G)
2249 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_2_5GB;
2250 if (link_speed & ETH_LINK_SPEED_10G)
2251 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_10GB;
2252 if (link_speed & ETH_LINK_SPEED_20G)
2253 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_20GB;
2254 if (link_speed & ETH_LINK_SPEED_25G)
2255 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_25GB;
2256 if (link_speed & ETH_LINK_SPEED_40G)
2257 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_40GB;
2258 if (link_speed & ETH_LINK_SPEED_50G)
2259 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_50GB;
2260 if (link_speed & ETH_LINK_SPEED_100G)
2261 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100GB;
2265 static uint32_t bnxt_parse_hw_link_speed(uint16_t hw_link_speed)
2267 uint32_t eth_link_speed = ETH_SPEED_NUM_NONE;
2269 switch (hw_link_speed) {
2270 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100MB:
2271 eth_link_speed = ETH_SPEED_NUM_100M;
2273 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_1GB:
2274 eth_link_speed = ETH_SPEED_NUM_1G;
2276 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2_5GB:
2277 eth_link_speed = ETH_SPEED_NUM_2_5G;
2279 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_10GB:
2280 eth_link_speed = ETH_SPEED_NUM_10G;
2282 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_20GB:
2283 eth_link_speed = ETH_SPEED_NUM_20G;
2285 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_25GB:
2286 eth_link_speed = ETH_SPEED_NUM_25G;
2288 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_40GB:
2289 eth_link_speed = ETH_SPEED_NUM_40G;
2291 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_50GB:
2292 eth_link_speed = ETH_SPEED_NUM_50G;
2294 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100GB:
2295 eth_link_speed = ETH_SPEED_NUM_100G;
2297 case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2GB:
2299 PMD_DRV_LOG(ERR, "HWRM link speed %d not defined\n",
2303 return eth_link_speed;
2306 static uint16_t bnxt_parse_hw_link_duplex(uint16_t hw_link_duplex)
2308 uint16_t eth_link_duplex = ETH_LINK_FULL_DUPLEX;
2310 switch (hw_link_duplex) {
2311 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH:
2312 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_FULL:
2314 eth_link_duplex = ETH_LINK_FULL_DUPLEX;
2316 case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_HALF:
2317 eth_link_duplex = ETH_LINK_HALF_DUPLEX;
2320 PMD_DRV_LOG(ERR, "HWRM link duplex %d not defined\n",
2324 return eth_link_duplex;
2327 int bnxt_get_hwrm_link_config(struct bnxt *bp, struct rte_eth_link *link)
2330 struct bnxt_link_info *link_info = &bp->link_info;
2332 rc = bnxt_hwrm_port_phy_qcfg(bp, link_info);
2335 "Get link config failed with rc %d\n", rc);
2338 if (link_info->link_speed)
2340 bnxt_parse_hw_link_speed(link_info->link_speed);
2342 link->link_speed = ETH_SPEED_NUM_NONE;
2343 link->link_duplex = bnxt_parse_hw_link_duplex(link_info->duplex);
2344 link->link_status = link_info->link_up;
2345 link->link_autoneg = link_info->auto_mode ==
2346 HWRM_PORT_PHY_QCFG_OUTPUT_AUTO_MODE_NONE ?
2347 ETH_LINK_FIXED : ETH_LINK_AUTONEG;
2352 int bnxt_set_hwrm_link_config(struct bnxt *bp, bool link_up)
2355 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
2356 struct bnxt_link_info link_req;
2357 uint16_t speed, autoneg;
2359 if (!BNXT_SINGLE_PF(bp) || BNXT_VF(bp))
2362 rc = bnxt_valid_link_speed(dev_conf->link_speeds,
2363 bp->eth_dev->data->port_id);
2367 memset(&link_req, 0, sizeof(link_req));
2368 link_req.link_up = link_up;
2372 autoneg = bnxt_check_eth_link_autoneg(dev_conf->link_speeds);
2373 speed = bnxt_parse_eth_link_speed(dev_conf->link_speeds);
2374 link_req.phy_flags = HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESET_PHY;
2375 /* Autoneg can be done only when the FW allows */
2376 if (autoneg == 1 && !(bp->link_info.auto_link_speed ||
2377 bp->link_info.force_link_speed)) {
2378 link_req.phy_flags |=
2379 HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESTART_AUTONEG;
2380 link_req.auto_link_speed_mask =
2381 bnxt_parse_eth_link_speed_mask(bp,
2382 dev_conf->link_speeds);
2384 if (bp->link_info.phy_type ==
2385 HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET ||
2386 bp->link_info.phy_type ==
2387 HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASETE ||
2388 bp->link_info.media_type ==
2389 HWRM_PORT_PHY_QCFG_OUTPUT_MEDIA_TYPE_TP) {
2390 PMD_DRV_LOG(ERR, "10GBase-T devices must autoneg\n");
2394 link_req.phy_flags |= HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE;
2395 /* If user wants a particular speed try that first. */
2397 link_req.link_speed = speed;
2398 else if (bp->link_info.force_link_speed)
2399 link_req.link_speed = bp->link_info.force_link_speed;
2401 link_req.link_speed = bp->link_info.auto_link_speed;
2403 link_req.duplex = bnxt_parse_eth_link_duplex(dev_conf->link_speeds);
2404 link_req.auto_pause = bp->link_info.auto_pause;
2405 link_req.force_pause = bp->link_info.force_pause;
2408 rc = bnxt_hwrm_port_phy_cfg(bp, &link_req);
2411 "Set link config failed with rc %d\n", rc);
2419 int bnxt_hwrm_func_qcfg(struct bnxt *bp)
2421 struct hwrm_func_qcfg_input req = {0};
2422 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
2426 HWRM_PREP(req, FUNC_QCFG);
2427 req.fid = rte_cpu_to_le_16(0xffff);
2429 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2431 HWRM_CHECK_RESULT();
2433 /* Hard Coded.. 0xfff VLAN ID mask */
2434 bp->vlan = rte_le_to_cpu_16(resp->vlan) & 0xfff;
2435 flags = rte_le_to_cpu_16(resp->flags);
2436 if (BNXT_PF(bp) && (flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_MULTI_HOST))
2437 bp->flags |= BNXT_FLAG_MULTI_HOST;
2439 switch (resp->port_partition_type) {
2440 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR1_0:
2441 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR1_5:
2442 case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR2_0:
2444 bp->port_partition_type = resp->port_partition_type;
2447 bp->port_partition_type = 0;
2456 static void copy_func_cfg_to_qcaps(struct hwrm_func_cfg_input *fcfg,
2457 struct hwrm_func_qcaps_output *qcaps)
2459 qcaps->max_rsscos_ctx = fcfg->num_rsscos_ctxs;
2460 memcpy(qcaps->mac_address, fcfg->dflt_mac_addr,
2461 sizeof(qcaps->mac_address));
2462 qcaps->max_l2_ctxs = fcfg->num_l2_ctxs;
2463 qcaps->max_rx_rings = fcfg->num_rx_rings;
2464 qcaps->max_tx_rings = fcfg->num_tx_rings;
2465 qcaps->max_cmpl_rings = fcfg->num_cmpl_rings;
2466 qcaps->max_stat_ctx = fcfg->num_stat_ctxs;
2468 qcaps->first_vf_id = 0;
2469 qcaps->max_vnics = fcfg->num_vnics;
2470 qcaps->max_decap_records = 0;
2471 qcaps->max_encap_records = 0;
2472 qcaps->max_tx_wm_flows = 0;
2473 qcaps->max_tx_em_flows = 0;
2474 qcaps->max_rx_wm_flows = 0;
2475 qcaps->max_rx_em_flows = 0;
2476 qcaps->max_flow_id = 0;
2477 qcaps->max_mcast_filters = fcfg->num_mcast_filters;
2478 qcaps->max_sp_tx_rings = 0;
2479 qcaps->max_hw_ring_grps = fcfg->num_hw_ring_grps;
2482 static int bnxt_hwrm_pf_func_cfg(struct bnxt *bp, int tx_rings)
2484 struct hwrm_func_cfg_input req = {0};
2485 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2488 req.enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_MTU |
2489 HWRM_FUNC_CFG_INPUT_ENABLES_MRU |
2490 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS |
2491 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
2492 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
2493 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_TX_RINGS |
2494 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RX_RINGS |
2495 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_L2_CTXS |
2496 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_VNICS |
2497 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS);
2498 req.flags = rte_cpu_to_le_32(bp->pf.func_cfg_flags);
2499 req.mtu = rte_cpu_to_le_16(BNXT_MAX_MTU);
2500 req.mru = rte_cpu_to_le_16(bp->eth_dev->data->mtu + ETHER_HDR_LEN +
2501 ETHER_CRC_LEN + VLAN_TAG_SIZE *
2503 req.num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx);
2504 req.num_stat_ctxs = rte_cpu_to_le_16(bp->max_stat_ctx);
2505 req.num_cmpl_rings = rte_cpu_to_le_16(bp->max_cp_rings);
2506 req.num_tx_rings = rte_cpu_to_le_16(tx_rings);
2507 req.num_rx_rings = rte_cpu_to_le_16(bp->max_rx_rings);
2508 req.num_l2_ctxs = rte_cpu_to_le_16(bp->max_l2_ctx);
2509 req.num_vnics = rte_cpu_to_le_16(bp->max_vnics);
2510 req.num_hw_ring_grps = rte_cpu_to_le_16(bp->max_ring_grps);
2511 req.fid = rte_cpu_to_le_16(0xffff);
2513 HWRM_PREP(req, FUNC_CFG);
2515 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2517 HWRM_CHECK_RESULT();
2523 static void populate_vf_func_cfg_req(struct bnxt *bp,
2524 struct hwrm_func_cfg_input *req,
2527 req->enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_MTU |
2528 HWRM_FUNC_CFG_INPUT_ENABLES_MRU |
2529 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS |
2530 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
2531 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
2532 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_TX_RINGS |
2533 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RX_RINGS |
2534 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_L2_CTXS |
2535 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_VNICS |
2536 HWRM_FUNC_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS);
2538 req->mtu = rte_cpu_to_le_16(bp->eth_dev->data->mtu + ETHER_HDR_LEN +
2539 ETHER_CRC_LEN + VLAN_TAG_SIZE *
2541 req->mru = rte_cpu_to_le_16(bp->eth_dev->data->mtu + ETHER_HDR_LEN +
2542 ETHER_CRC_LEN + VLAN_TAG_SIZE *
2544 req->num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx /
2546 req->num_stat_ctxs = rte_cpu_to_le_16(bp->max_stat_ctx / (num_vfs + 1));
2547 req->num_cmpl_rings = rte_cpu_to_le_16(bp->max_cp_rings /
2549 req->num_tx_rings = rte_cpu_to_le_16(bp->max_tx_rings / (num_vfs + 1));
2550 req->num_rx_rings = rte_cpu_to_le_16(bp->max_rx_rings / (num_vfs + 1));
2551 req->num_l2_ctxs = rte_cpu_to_le_16(bp->max_l2_ctx / (num_vfs + 1));
2552 /* TODO: For now, do not support VMDq/RFS on VFs. */
2553 req->num_vnics = rte_cpu_to_le_16(1);
2554 req->num_hw_ring_grps = rte_cpu_to_le_16(bp->max_ring_grps /
2558 static void add_random_mac_if_needed(struct bnxt *bp,
2559 struct hwrm_func_cfg_input *cfg_req,
2562 struct ether_addr mac;
2564 if (bnxt_hwrm_func_qcfg_vf_default_mac(bp, vf, &mac))
2567 if (memcmp(mac.addr_bytes, "\x00\x00\x00\x00\x00", 6) == 0) {
2569 rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
2570 eth_random_addr(cfg_req->dflt_mac_addr);
2571 bp->pf.vf_info[vf].random_mac = true;
2573 memcpy(cfg_req->dflt_mac_addr, mac.addr_bytes, ETHER_ADDR_LEN);
2577 static void reserve_resources_from_vf(struct bnxt *bp,
2578 struct hwrm_func_cfg_input *cfg_req,
2581 struct hwrm_func_qcaps_input req = {0};
2582 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
2585 /* Get the actual allocated values now */
2586 HWRM_PREP(req, FUNC_QCAPS);
2587 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
2588 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2591 PMD_DRV_LOG(ERR, "hwrm_func_qcaps failed rc:%d\n", rc);
2592 copy_func_cfg_to_qcaps(cfg_req, resp);
2593 } else if (resp->error_code) {
2594 rc = rte_le_to_cpu_16(resp->error_code);
2595 PMD_DRV_LOG(ERR, "hwrm_func_qcaps error %d\n", rc);
2596 copy_func_cfg_to_qcaps(cfg_req, resp);
2599 bp->max_rsscos_ctx -= rte_le_to_cpu_16(resp->max_rsscos_ctx);
2600 bp->max_stat_ctx -= rte_le_to_cpu_16(resp->max_stat_ctx);
2601 bp->max_cp_rings -= rte_le_to_cpu_16(resp->max_cmpl_rings);
2602 bp->max_tx_rings -= rte_le_to_cpu_16(resp->max_tx_rings);
2603 bp->max_rx_rings -= rte_le_to_cpu_16(resp->max_rx_rings);
2604 bp->max_l2_ctx -= rte_le_to_cpu_16(resp->max_l2_ctxs);
2606 * TODO: While not supporting VMDq with VFs, max_vnics is always
2607 * forced to 1 in this case
2609 //bp->max_vnics -= rte_le_to_cpu_16(esp->max_vnics);
2610 bp->max_ring_grps -= rte_le_to_cpu_16(resp->max_hw_ring_grps);
2615 int bnxt_hwrm_func_qcfg_current_vf_vlan(struct bnxt *bp, int vf)
2617 struct hwrm_func_qcfg_input req = {0};
2618 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
2621 /* Check for zero MAC address */
2622 HWRM_PREP(req, FUNC_QCFG);
2623 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
2624 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2626 PMD_DRV_LOG(ERR, "hwrm_func_qcfg failed rc:%d\n", rc);
2628 } else if (resp->error_code) {
2629 rc = rte_le_to_cpu_16(resp->error_code);
2630 PMD_DRV_LOG(ERR, "hwrm_func_qcfg error %d\n", rc);
2633 rc = rte_le_to_cpu_16(resp->vlan);
2640 static int update_pf_resource_max(struct bnxt *bp)
2642 struct hwrm_func_qcfg_input req = {0};
2643 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
2646 /* And copy the allocated numbers into the pf struct */
2647 HWRM_PREP(req, FUNC_QCFG);
2648 req.fid = rte_cpu_to_le_16(0xffff);
2649 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2650 HWRM_CHECK_RESULT();
2652 /* Only TX ring value reflects actual allocation? TODO */
2653 bp->max_tx_rings = rte_le_to_cpu_16(resp->alloc_tx_rings);
2654 bp->pf.evb_mode = resp->evb_mode;
2661 int bnxt_hwrm_allocate_pf_only(struct bnxt *bp)
2666 PMD_DRV_LOG(ERR, "Attempt to allcoate VFs on a VF!\n");
2670 rc = bnxt_hwrm_func_qcaps(bp);
2674 bp->pf.func_cfg_flags &=
2675 ~(HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE |
2676 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE);
2677 bp->pf.func_cfg_flags |=
2678 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE;
2679 rc = bnxt_hwrm_pf_func_cfg(bp, bp->max_tx_rings);
2683 int bnxt_hwrm_allocate_vfs(struct bnxt *bp, int num_vfs)
2685 struct hwrm_func_cfg_input req = {0};
2686 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2693 PMD_DRV_LOG(ERR, "Attempt to allcoate VFs on a VF!\n");
2697 rc = bnxt_hwrm_func_qcaps(bp);
2702 bp->pf.active_vfs = num_vfs;
2705 * First, configure the PF to only use one TX ring. This ensures that
2706 * there are enough rings for all VFs.
2708 * If we don't do this, when we call func_alloc() later, we will lock
2709 * extra rings to the PF that won't be available during func_cfg() of
2712 * This has been fixed with firmware versions above 20.6.54
2714 bp->pf.func_cfg_flags &=
2715 ~(HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE |
2716 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE);
2717 bp->pf.func_cfg_flags |=
2718 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE;
2719 rc = bnxt_hwrm_pf_func_cfg(bp, 1);
2724 * Now, create and register a buffer to hold forwarded VF requests
2726 req_buf_sz = num_vfs * HWRM_MAX_REQ_LEN;
2727 bp->pf.vf_req_buf = rte_malloc("bnxt_vf_fwd", req_buf_sz,
2728 page_roundup(num_vfs * HWRM_MAX_REQ_LEN));
2729 if (bp->pf.vf_req_buf == NULL) {
2733 for (sz = 0; sz < req_buf_sz; sz += getpagesize())
2734 rte_mem_lock_page(((char *)bp->pf.vf_req_buf) + sz);
2735 for (i = 0; i < num_vfs; i++)
2736 bp->pf.vf_info[i].req_buf = ((char *)bp->pf.vf_req_buf) +
2737 (i * HWRM_MAX_REQ_LEN);
2739 rc = bnxt_hwrm_func_buf_rgtr(bp);
2743 populate_vf_func_cfg_req(bp, &req, num_vfs);
2745 bp->pf.active_vfs = 0;
2746 for (i = 0; i < num_vfs; i++) {
2747 add_random_mac_if_needed(bp, &req, i);
2749 HWRM_PREP(req, FUNC_CFG);
2750 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[i].func_cfg_flags);
2751 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[i].fid);
2752 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2754 /* Clear enable flag for next pass */
2755 req.enables &= ~rte_cpu_to_le_32(
2756 HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
2758 if (rc || resp->error_code) {
2760 "Failed to initizlie VF %d\n", i);
2762 "Not all VFs available. (%d, %d)\n",
2763 rc, resp->error_code);
2770 reserve_resources_from_vf(bp, &req, i);
2771 bp->pf.active_vfs++;
2772 bnxt_hwrm_func_clr_stats(bp, bp->pf.vf_info[i].fid);
2776 * Now configure the PF to use "the rest" of the resources
2777 * We're using STD_TX_RING_MODE here though which will limit the TX
2778 * rings. This will allow QoS to function properly. Not setting this
2779 * will cause PF rings to break bandwidth settings.
2781 rc = bnxt_hwrm_pf_func_cfg(bp, bp->max_tx_rings);
2785 rc = update_pf_resource_max(bp);
2792 bnxt_hwrm_func_buf_unrgtr(bp);
2796 int bnxt_hwrm_pf_evb_mode(struct bnxt *bp)
2798 struct hwrm_func_cfg_input req = {0};
2799 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2802 HWRM_PREP(req, FUNC_CFG);
2804 req.fid = rte_cpu_to_le_16(0xffff);
2805 req.enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_EVB_MODE);
2806 req.evb_mode = bp->pf.evb_mode;
2808 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2809 HWRM_CHECK_RESULT();
2815 int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt *bp, uint16_t port,
2816 uint8_t tunnel_type)
2818 struct hwrm_tunnel_dst_port_alloc_input req = {0};
2819 struct hwrm_tunnel_dst_port_alloc_output *resp = bp->hwrm_cmd_resp_addr;
2822 HWRM_PREP(req, TUNNEL_DST_PORT_ALLOC);
2823 req.tunnel_type = tunnel_type;
2824 req.tunnel_dst_port_val = port;
2825 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2826 HWRM_CHECK_RESULT();
2828 switch (tunnel_type) {
2829 case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_VXLAN:
2830 bp->vxlan_fw_dst_port_id = resp->tunnel_dst_port_id;
2831 bp->vxlan_port = port;
2833 case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_GENEVE:
2834 bp->geneve_fw_dst_port_id = resp->tunnel_dst_port_id;
2835 bp->geneve_port = port;
2846 int bnxt_hwrm_tunnel_dst_port_free(struct bnxt *bp, uint16_t port,
2847 uint8_t tunnel_type)
2849 struct hwrm_tunnel_dst_port_free_input req = {0};
2850 struct hwrm_tunnel_dst_port_free_output *resp = bp->hwrm_cmd_resp_addr;
2853 HWRM_PREP(req, TUNNEL_DST_PORT_FREE);
2855 req.tunnel_type = tunnel_type;
2856 req.tunnel_dst_port_id = rte_cpu_to_be_16(port);
2857 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2859 HWRM_CHECK_RESULT();
2865 int bnxt_hwrm_func_cfg_vf_set_flags(struct bnxt *bp, uint16_t vf,
2868 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2869 struct hwrm_func_cfg_input req = {0};
2872 HWRM_PREP(req, FUNC_CFG);
2874 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
2875 req.flags = rte_cpu_to_le_32(flags);
2876 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2878 HWRM_CHECK_RESULT();
2884 void vf_vnic_set_rxmask_cb(struct bnxt_vnic_info *vnic, void *flagp)
2886 uint32_t *flag = flagp;
2888 vnic->flags = *flag;
2891 int bnxt_set_rx_mask_no_vlan(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2893 return bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
2896 int bnxt_hwrm_func_buf_rgtr(struct bnxt *bp)
2899 struct hwrm_func_buf_rgtr_input req = {.req_type = 0 };
2900 struct hwrm_func_buf_rgtr_output *resp = bp->hwrm_cmd_resp_addr;
2902 HWRM_PREP(req, FUNC_BUF_RGTR);
2904 req.req_buf_num_pages = rte_cpu_to_le_16(1);
2905 req.req_buf_page_size = rte_cpu_to_le_16(
2906 page_getenum(bp->pf.active_vfs * HWRM_MAX_REQ_LEN));
2907 req.req_buf_len = rte_cpu_to_le_16(HWRM_MAX_REQ_LEN);
2908 req.req_buf_page_addr0 =
2909 rte_cpu_to_le_64(rte_mem_virt2iova(bp->pf.vf_req_buf));
2910 if (req.req_buf_page_addr0 == 0) {
2912 "unable to map buffer address to physical memory\n");
2916 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2918 HWRM_CHECK_RESULT();
2924 int bnxt_hwrm_func_buf_unrgtr(struct bnxt *bp)
2927 struct hwrm_func_buf_unrgtr_input req = {.req_type = 0 };
2928 struct hwrm_func_buf_unrgtr_output *resp = bp->hwrm_cmd_resp_addr;
2930 HWRM_PREP(req, FUNC_BUF_UNRGTR);
2932 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2934 HWRM_CHECK_RESULT();
2940 int bnxt_hwrm_func_cfg_def_cp(struct bnxt *bp)
2942 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2943 struct hwrm_func_cfg_input req = {0};
2946 HWRM_PREP(req, FUNC_CFG);
2948 req.fid = rte_cpu_to_le_16(0xffff);
2949 req.flags = rte_cpu_to_le_32(bp->pf.func_cfg_flags);
2950 req.enables = rte_cpu_to_le_32(
2951 HWRM_FUNC_CFG_INPUT_ENABLES_ASYNC_EVENT_CR);
2952 req.async_event_cr = rte_cpu_to_le_16(
2953 bp->def_cp_ring->cp_ring_struct->fw_ring_id);
2954 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2956 HWRM_CHECK_RESULT();
2962 int bnxt_hwrm_vf_func_cfg_def_cp(struct bnxt *bp)
2964 struct hwrm_func_vf_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2965 struct hwrm_func_vf_cfg_input req = {0};
2968 HWRM_PREP(req, FUNC_VF_CFG);
2970 req.enables = rte_cpu_to_le_32(
2971 HWRM_FUNC_CFG_INPUT_ENABLES_ASYNC_EVENT_CR);
2972 req.async_event_cr = rte_cpu_to_le_16(
2973 bp->def_cp_ring->cp_ring_struct->fw_ring_id);
2974 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
2976 HWRM_CHECK_RESULT();
2982 int bnxt_hwrm_set_default_vlan(struct bnxt *bp, int vf, uint8_t is_vf)
2984 struct hwrm_func_cfg_input req = {0};
2985 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2986 uint16_t dflt_vlan, fid;
2987 uint32_t func_cfg_flags;
2990 HWRM_PREP(req, FUNC_CFG);
2993 dflt_vlan = bp->pf.vf_info[vf].dflt_vlan;
2994 fid = bp->pf.vf_info[vf].fid;
2995 func_cfg_flags = bp->pf.vf_info[vf].func_cfg_flags;
2997 fid = rte_cpu_to_le_16(0xffff);
2998 func_cfg_flags = bp->pf.func_cfg_flags;
2999 dflt_vlan = bp->vlan;
3002 req.flags = rte_cpu_to_le_32(func_cfg_flags);
3003 req.fid = rte_cpu_to_le_16(fid);
3004 req.enables |= rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_VLAN);
3005 req.dflt_vlan = rte_cpu_to_le_16(dflt_vlan);
3007 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3009 HWRM_CHECK_RESULT();
3015 int bnxt_hwrm_func_bw_cfg(struct bnxt *bp, uint16_t vf,
3016 uint16_t max_bw, uint16_t enables)
3018 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3019 struct hwrm_func_cfg_input req = {0};
3022 HWRM_PREP(req, FUNC_CFG);
3024 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3025 req.enables |= rte_cpu_to_le_32(enables);
3026 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[vf].func_cfg_flags);
3027 req.max_bw = rte_cpu_to_le_32(max_bw);
3028 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3030 HWRM_CHECK_RESULT();
3036 int bnxt_hwrm_set_vf_vlan(struct bnxt *bp, int vf)
3038 struct hwrm_func_cfg_input req = {0};
3039 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3042 HWRM_PREP(req, FUNC_CFG);
3044 req.flags = rte_cpu_to_le_32(bp->pf.vf_info[vf].func_cfg_flags);
3045 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3046 req.enables |= rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_VLAN);
3047 req.dflt_vlan = rte_cpu_to_le_16(bp->pf.vf_info[vf].dflt_vlan);
3049 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3051 HWRM_CHECK_RESULT();
3057 int bnxt_hwrm_set_async_event_cr(struct bnxt *bp)
3062 rc = bnxt_hwrm_func_cfg_def_cp(bp);
3064 rc = bnxt_hwrm_vf_func_cfg_def_cp(bp);
3069 int bnxt_hwrm_reject_fwd_resp(struct bnxt *bp, uint16_t target_id,
3070 void *encaped, size_t ec_size)
3073 struct hwrm_reject_fwd_resp_input req = {.req_type = 0};
3074 struct hwrm_reject_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr;
3076 if (ec_size > sizeof(req.encap_request))
3079 HWRM_PREP(req, REJECT_FWD_RESP);
3081 req.encap_resp_target_id = rte_cpu_to_le_16(target_id);
3082 memcpy(req.encap_request, encaped, ec_size);
3084 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3086 HWRM_CHECK_RESULT();
3092 int bnxt_hwrm_func_qcfg_vf_default_mac(struct bnxt *bp, uint16_t vf,
3093 struct ether_addr *mac)
3095 struct hwrm_func_qcfg_input req = {0};
3096 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
3099 HWRM_PREP(req, FUNC_QCFG);
3101 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3102 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3104 HWRM_CHECK_RESULT();
3106 memcpy(mac->addr_bytes, resp->mac_address, ETHER_ADDR_LEN);
3113 int bnxt_hwrm_exec_fwd_resp(struct bnxt *bp, uint16_t target_id,
3114 void *encaped, size_t ec_size)
3117 struct hwrm_exec_fwd_resp_input req = {.req_type = 0};
3118 struct hwrm_exec_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr;
3120 if (ec_size > sizeof(req.encap_request))
3123 HWRM_PREP(req, EXEC_FWD_RESP);
3125 req.encap_resp_target_id = rte_cpu_to_le_16(target_id);
3126 memcpy(req.encap_request, encaped, ec_size);
3128 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3130 HWRM_CHECK_RESULT();
3136 int bnxt_hwrm_ctx_qstats(struct bnxt *bp, uint32_t cid, int idx,
3137 struct rte_eth_stats *stats, uint8_t rx)
3140 struct hwrm_stat_ctx_query_input req = {.req_type = 0};
3141 struct hwrm_stat_ctx_query_output *resp = bp->hwrm_cmd_resp_addr;
3143 HWRM_PREP(req, STAT_CTX_QUERY);
3145 req.stat_ctx_id = rte_cpu_to_le_32(cid);
3147 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3149 HWRM_CHECK_RESULT();
3152 stats->q_ipackets[idx] = rte_le_to_cpu_64(resp->rx_ucast_pkts);
3153 stats->q_ipackets[idx] += rte_le_to_cpu_64(resp->rx_mcast_pkts);
3154 stats->q_ipackets[idx] += rte_le_to_cpu_64(resp->rx_bcast_pkts);
3155 stats->q_ibytes[idx] = rte_le_to_cpu_64(resp->rx_ucast_bytes);
3156 stats->q_ibytes[idx] += rte_le_to_cpu_64(resp->rx_mcast_bytes);
3157 stats->q_ibytes[idx] += rte_le_to_cpu_64(resp->rx_bcast_bytes);
3158 stats->q_errors[idx] = rte_le_to_cpu_64(resp->rx_err_pkts);
3159 stats->q_errors[idx] += rte_le_to_cpu_64(resp->rx_drop_pkts);
3161 stats->q_opackets[idx] = rte_le_to_cpu_64(resp->tx_ucast_pkts);
3162 stats->q_opackets[idx] += rte_le_to_cpu_64(resp->tx_mcast_pkts);
3163 stats->q_opackets[idx] += rte_le_to_cpu_64(resp->tx_bcast_pkts);
3164 stats->q_obytes[idx] = rte_le_to_cpu_64(resp->tx_ucast_bytes);
3165 stats->q_obytes[idx] += rte_le_to_cpu_64(resp->tx_mcast_bytes);
3166 stats->q_obytes[idx] += rte_le_to_cpu_64(resp->tx_bcast_bytes);
3167 stats->q_errors[idx] += rte_le_to_cpu_64(resp->tx_err_pkts);
3176 int bnxt_hwrm_port_qstats(struct bnxt *bp)
3178 struct hwrm_port_qstats_input req = {0};
3179 struct hwrm_port_qstats_output *resp = bp->hwrm_cmd_resp_addr;
3180 struct bnxt_pf_info *pf = &bp->pf;
3183 HWRM_PREP(req, PORT_QSTATS);
3185 req.port_id = rte_cpu_to_le_16(pf->port_id);
3186 req.tx_stat_host_addr = rte_cpu_to_le_64(bp->hw_tx_port_stats_map);
3187 req.rx_stat_host_addr = rte_cpu_to_le_64(bp->hw_rx_port_stats_map);
3188 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3190 HWRM_CHECK_RESULT();
3196 int bnxt_hwrm_port_clr_stats(struct bnxt *bp)
3198 struct hwrm_port_clr_stats_input req = {0};
3199 struct hwrm_port_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
3200 struct bnxt_pf_info *pf = &bp->pf;
3203 /* Not allowed on NS2 device, NPAR, MultiHost, VF */
3204 if (!(bp->flags & BNXT_FLAG_PORT_STATS) || BNXT_VF(bp) ||
3205 BNXT_NPAR(bp) || BNXT_MH(bp) || BNXT_TOTAL_VFS(bp))
3208 HWRM_PREP(req, PORT_CLR_STATS);
3210 req.port_id = rte_cpu_to_le_16(pf->port_id);
3211 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3213 HWRM_CHECK_RESULT();
3219 int bnxt_hwrm_port_led_qcaps(struct bnxt *bp)
3221 struct hwrm_port_led_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
3222 struct hwrm_port_led_qcaps_input req = {0};
3228 HWRM_PREP(req, PORT_LED_QCAPS);
3229 req.port_id = bp->pf.port_id;
3230 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3232 HWRM_CHECK_RESULT();
3234 if (resp->num_leds > 0 && resp->num_leds < BNXT_MAX_LED) {
3237 bp->num_leds = resp->num_leds;
3238 memcpy(bp->leds, &resp->led0_id,
3239 sizeof(bp->leds[0]) * bp->num_leds);
3240 for (i = 0; i < bp->num_leds; i++) {
3241 struct bnxt_led_info *led = &bp->leds[i];
3243 uint16_t caps = led->led_state_caps;
3245 if (!led->led_group_id ||
3246 !BNXT_LED_ALT_BLINK_CAP(caps)) {
3258 int bnxt_hwrm_port_led_cfg(struct bnxt *bp, bool led_on)
3260 struct hwrm_port_led_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3261 struct hwrm_port_led_cfg_input req = {0};
3262 struct bnxt_led_cfg *led_cfg;
3263 uint8_t led_state = HWRM_PORT_LED_QCFG_OUTPUT_LED0_STATE_DEFAULT;
3264 uint16_t duration = 0;
3267 if (!bp->num_leds || BNXT_VF(bp))
3270 HWRM_PREP(req, PORT_LED_CFG);
3273 led_state = HWRM_PORT_LED_CFG_INPUT_LED0_STATE_BLINKALT;
3274 duration = rte_cpu_to_le_16(500);
3276 req.port_id = bp->pf.port_id;
3277 req.num_leds = bp->num_leds;
3278 led_cfg = (struct bnxt_led_cfg *)&req.led0_id;
3279 for (i = 0; i < bp->num_leds; i++, led_cfg++) {
3280 req.enables |= BNXT_LED_DFLT_ENABLES(i);
3281 led_cfg->led_id = bp->leds[i].led_id;
3282 led_cfg->led_state = led_state;
3283 led_cfg->led_blink_on = duration;
3284 led_cfg->led_blink_off = duration;
3285 led_cfg->led_group_id = bp->leds[i].led_group_id;
3288 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3290 HWRM_CHECK_RESULT();
3296 int bnxt_hwrm_nvm_get_dir_info(struct bnxt *bp, uint32_t *entries,
3300 struct hwrm_nvm_get_dir_info_input req = {0};
3301 struct hwrm_nvm_get_dir_info_output *resp = bp->hwrm_cmd_resp_addr;
3303 HWRM_PREP(req, NVM_GET_DIR_INFO);
3305 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3307 HWRM_CHECK_RESULT();
3311 *entries = rte_le_to_cpu_32(resp->entries);
3312 *length = rte_le_to_cpu_32(resp->entry_length);
3317 int bnxt_get_nvram_directory(struct bnxt *bp, uint32_t len, uint8_t *data)
3320 uint32_t dir_entries;
3321 uint32_t entry_length;
3324 rte_iova_t dma_handle;
3325 struct hwrm_nvm_get_dir_entries_input req = {0};
3326 struct hwrm_nvm_get_dir_entries_output *resp = bp->hwrm_cmd_resp_addr;
3328 rc = bnxt_hwrm_nvm_get_dir_info(bp, &dir_entries, &entry_length);
3332 *data++ = dir_entries;
3333 *data++ = entry_length;
3335 memset(data, 0xff, len);
3337 buflen = dir_entries * entry_length;
3338 buf = rte_malloc("nvm_dir", buflen, 0);
3339 rte_mem_lock_page(buf);
3342 dma_handle = rte_mem_virt2iova(buf);
3343 if (dma_handle == 0) {
3345 "unable to map response address to physical memory\n");
3348 HWRM_PREP(req, NVM_GET_DIR_ENTRIES);
3349 req.host_dest_addr = rte_cpu_to_le_64(dma_handle);
3350 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3352 HWRM_CHECK_RESULT();
3356 memcpy(data, buf, len > buflen ? buflen : len);
3363 int bnxt_hwrm_get_nvram_item(struct bnxt *bp, uint32_t index,
3364 uint32_t offset, uint32_t length,
3369 rte_iova_t dma_handle;
3370 struct hwrm_nvm_read_input req = {0};
3371 struct hwrm_nvm_read_output *resp = bp->hwrm_cmd_resp_addr;
3373 buf = rte_malloc("nvm_item", length, 0);
3374 rte_mem_lock_page(buf);
3378 dma_handle = rte_mem_virt2iova(buf);
3379 if (dma_handle == 0) {
3381 "unable to map response address to physical memory\n");
3384 HWRM_PREP(req, NVM_READ);
3385 req.host_dest_addr = rte_cpu_to_le_64(dma_handle);
3386 req.dir_idx = rte_cpu_to_le_16(index);
3387 req.offset = rte_cpu_to_le_32(offset);
3388 req.len = rte_cpu_to_le_32(length);
3389 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3390 HWRM_CHECK_RESULT();
3393 memcpy(data, buf, length);
3399 int bnxt_hwrm_erase_nvram_directory(struct bnxt *bp, uint8_t index)
3402 struct hwrm_nvm_erase_dir_entry_input req = {0};
3403 struct hwrm_nvm_erase_dir_entry_output *resp = bp->hwrm_cmd_resp_addr;
3405 HWRM_PREP(req, NVM_ERASE_DIR_ENTRY);
3406 req.dir_idx = rte_cpu_to_le_16(index);
3407 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3408 HWRM_CHECK_RESULT();
3415 int bnxt_hwrm_flash_nvram(struct bnxt *bp, uint16_t dir_type,
3416 uint16_t dir_ordinal, uint16_t dir_ext,
3417 uint16_t dir_attr, const uint8_t *data,
3421 struct hwrm_nvm_write_input req = {0};
3422 struct hwrm_nvm_write_output *resp = bp->hwrm_cmd_resp_addr;
3423 rte_iova_t dma_handle;
3426 HWRM_PREP(req, NVM_WRITE);
3428 req.dir_type = rte_cpu_to_le_16(dir_type);
3429 req.dir_ordinal = rte_cpu_to_le_16(dir_ordinal);
3430 req.dir_ext = rte_cpu_to_le_16(dir_ext);
3431 req.dir_attr = rte_cpu_to_le_16(dir_attr);
3432 req.dir_data_length = rte_cpu_to_le_32(data_len);
3434 buf = rte_malloc("nvm_write", data_len, 0);
3435 rte_mem_lock_page(buf);
3439 dma_handle = rte_mem_virt2iova(buf);
3440 if (dma_handle == 0) {
3442 "unable to map response address to physical memory\n");
3445 memcpy(buf, data, data_len);
3446 req.host_src_addr = rte_cpu_to_le_64(dma_handle);
3448 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3450 HWRM_CHECK_RESULT();
3458 bnxt_vnic_count(struct bnxt_vnic_info *vnic __rte_unused, void *cbdata)
3460 uint32_t *count = cbdata;
3462 *count = *count + 1;
3465 static int bnxt_vnic_count_hwrm_stub(struct bnxt *bp __rte_unused,
3466 struct bnxt_vnic_info *vnic __rte_unused)
3471 int bnxt_vf_vnic_count(struct bnxt *bp, uint16_t vf)
3475 bnxt_hwrm_func_vf_vnic_query_and_config(bp, vf, bnxt_vnic_count,
3476 &count, bnxt_vnic_count_hwrm_stub);
3481 static int bnxt_hwrm_func_vf_vnic_query(struct bnxt *bp, uint16_t vf,
3484 struct hwrm_func_vf_vnic_ids_query_input req = {0};
3485 struct hwrm_func_vf_vnic_ids_query_output *resp =
3486 bp->hwrm_cmd_resp_addr;
3489 /* First query all VNIC ids */
3490 HWRM_PREP(req, FUNC_VF_VNIC_IDS_QUERY);
3492 req.vf_id = rte_cpu_to_le_16(bp->pf.first_vf_id + vf);
3493 req.max_vnic_id_cnt = rte_cpu_to_le_32(bp->pf.total_vnics);
3494 req.vnic_id_tbl_addr = rte_cpu_to_le_64(rte_mem_virt2iova(vnic_ids));
3496 if (req.vnic_id_tbl_addr == 0) {
3499 "unable to map VNIC ID table address to physical memory\n");
3502 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3505 PMD_DRV_LOG(ERR, "hwrm_func_vf_vnic_query failed rc:%d\n", rc);
3507 } else if (resp->error_code) {
3508 rc = rte_le_to_cpu_16(resp->error_code);
3510 PMD_DRV_LOG(ERR, "hwrm_func_vf_vnic_query error %d\n", rc);
3513 rc = rte_le_to_cpu_32(resp->vnic_id_cnt);
3521 * This function queries the VNIC IDs for a specified VF. It then calls
3522 * the vnic_cb to update the necessary field in vnic_info with cbdata.
3523 * Then it calls the hwrm_cb function to program this new vnic configuration.
3525 int bnxt_hwrm_func_vf_vnic_query_and_config(struct bnxt *bp, uint16_t vf,
3526 void (*vnic_cb)(struct bnxt_vnic_info *, void *), void *cbdata,
3527 int (*hwrm_cb)(struct bnxt *bp, struct bnxt_vnic_info *vnic))
3529 struct bnxt_vnic_info vnic;
3531 int i, num_vnic_ids;
3536 /* First query all VNIC ids */
3537 vnic_id_sz = bp->pf.total_vnics * sizeof(*vnic_ids);
3538 vnic_ids = rte_malloc("bnxt_hwrm_vf_vnic_ids_query", vnic_id_sz,
3539 RTE_CACHE_LINE_SIZE);
3540 if (vnic_ids == NULL) {
3544 for (sz = 0; sz < vnic_id_sz; sz += getpagesize())
3545 rte_mem_lock_page(((char *)vnic_ids) + sz);
3547 num_vnic_ids = bnxt_hwrm_func_vf_vnic_query(bp, vf, vnic_ids);
3549 if (num_vnic_ids < 0)
3550 return num_vnic_ids;
3552 /* Retrieve VNIC, update bd_stall then update */
3554 for (i = 0; i < num_vnic_ids; i++) {
3555 memset(&vnic, 0, sizeof(struct bnxt_vnic_info));
3556 vnic.fw_vnic_id = rte_le_to_cpu_16(vnic_ids[i]);
3557 rc = bnxt_hwrm_vnic_qcfg(bp, &vnic, bp->pf.first_vf_id + vf);
3560 if (vnic.mru <= 4) /* Indicates unallocated */
3563 vnic_cb(&vnic, cbdata);
3565 rc = hwrm_cb(bp, &vnic);
3575 int bnxt_hwrm_func_cfg_vf_set_vlan_anti_spoof(struct bnxt *bp, uint16_t vf,
3578 struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3579 struct hwrm_func_cfg_input req = {0};
3582 HWRM_PREP(req, FUNC_CFG);
3584 req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
3585 req.enables |= rte_cpu_to_le_32(
3586 HWRM_FUNC_CFG_INPUT_ENABLES_VLAN_ANTISPOOF_MODE);
3587 req.vlan_antispoof_mode = on ?
3588 HWRM_FUNC_CFG_INPUT_VLAN_ANTISPOOF_MODE_VALIDATE_VLAN :
3589 HWRM_FUNC_CFG_INPUT_VLAN_ANTISPOOF_MODE_NOCHECK;
3590 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3592 HWRM_CHECK_RESULT();
3598 int bnxt_hwrm_func_qcfg_vf_dflt_vnic_id(struct bnxt *bp, int vf)
3600 struct bnxt_vnic_info vnic;
3603 int num_vnic_ids, i;
3607 vnic_id_sz = bp->pf.total_vnics * sizeof(*vnic_ids);
3608 vnic_ids = rte_malloc("bnxt_hwrm_vf_vnic_ids_query", vnic_id_sz,
3609 RTE_CACHE_LINE_SIZE);
3610 if (vnic_ids == NULL) {
3615 for (sz = 0; sz < vnic_id_sz; sz += getpagesize())
3616 rte_mem_lock_page(((char *)vnic_ids) + sz);
3618 rc = bnxt_hwrm_func_vf_vnic_query(bp, vf, vnic_ids);
3624 * Loop through to find the default VNIC ID.
3625 * TODO: The easier way would be to obtain the resp->dflt_vnic_id
3626 * by sending the hwrm_func_qcfg command to the firmware.
3628 for (i = 0; i < num_vnic_ids; i++) {
3629 memset(&vnic, 0, sizeof(struct bnxt_vnic_info));
3630 vnic.fw_vnic_id = rte_le_to_cpu_16(vnic_ids[i]);
3631 rc = bnxt_hwrm_vnic_qcfg(bp, &vnic,
3632 bp->pf.first_vf_id + vf);
3635 if (vnic.func_default) {
3637 return vnic.fw_vnic_id;
3640 /* Could not find a default VNIC. */
3641 PMD_DRV_LOG(ERR, "No default VNIC\n");
3647 int bnxt_hwrm_set_em_filter(struct bnxt *bp,
3649 struct bnxt_filter_info *filter)
3652 struct hwrm_cfa_em_flow_alloc_input req = {.req_type = 0 };
3653 struct hwrm_cfa_em_flow_alloc_output *resp = bp->hwrm_cmd_resp_addr;
3654 uint32_t enables = 0;
3656 if (filter->fw_em_filter_id != UINT64_MAX)
3657 bnxt_hwrm_clear_em_filter(bp, filter);
3659 HWRM_PREP(req, CFA_EM_FLOW_ALLOC);
3661 req.flags = rte_cpu_to_le_32(filter->flags);
3663 enables = filter->enables |
3664 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_ID;
3665 req.dst_id = rte_cpu_to_le_16(dst_id);
3667 if (filter->ip_addr_type) {
3668 req.ip_addr_type = filter->ip_addr_type;
3669 enables |= HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IPADDR_TYPE;
3672 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_L2_FILTER_ID)
3673 req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
3675 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_MACADDR)
3676 memcpy(req.src_macaddr, filter->src_macaddr,
3679 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_MACADDR)
3680 memcpy(req.dst_macaddr, filter->dst_macaddr,
3683 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_OVLAN_VID)
3684 req.ovlan_vid = filter->l2_ovlan;
3686 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IVLAN_VID)
3687 req.ivlan_vid = filter->l2_ivlan;
3689 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_ETHERTYPE)
3690 req.ethertype = rte_cpu_to_be_16(filter->ethertype);
3692 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IP_PROTOCOL)
3693 req.ip_protocol = filter->ip_protocol;
3695 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_IPADDR)
3696 req.src_ipaddr[0] = rte_cpu_to_be_32(filter->src_ipaddr[0]);
3698 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_IPADDR)
3699 req.dst_ipaddr[0] = rte_cpu_to_be_32(filter->dst_ipaddr[0]);
3701 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_PORT)
3702 req.src_port = rte_cpu_to_be_16(filter->src_port);
3704 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_PORT)
3705 req.dst_port = rte_cpu_to_be_16(filter->dst_port);
3707 HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_MIRROR_VNIC_ID)
3708 req.mirror_vnic_id = filter->mirror_vnic_id;
3710 req.enables = rte_cpu_to_le_32(enables);
3712 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3714 HWRM_CHECK_RESULT();
3716 filter->fw_em_filter_id = rte_le_to_cpu_64(resp->em_filter_id);
3722 int bnxt_hwrm_clear_em_filter(struct bnxt *bp, struct bnxt_filter_info *filter)
3725 struct hwrm_cfa_em_flow_free_input req = {.req_type = 0 };
3726 struct hwrm_cfa_em_flow_free_output *resp = bp->hwrm_cmd_resp_addr;
3728 if (filter->fw_em_filter_id == UINT64_MAX)
3731 PMD_DRV_LOG(ERR, "Clear EM filter\n");
3732 HWRM_PREP(req, CFA_EM_FLOW_FREE);
3734 req.em_filter_id = rte_cpu_to_le_64(filter->fw_em_filter_id);
3736 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3738 HWRM_CHECK_RESULT();
3741 filter->fw_em_filter_id = UINT64_MAX;
3742 filter->fw_l2_filter_id = UINT64_MAX;
3747 int bnxt_hwrm_set_ntuple_filter(struct bnxt *bp,
3749 struct bnxt_filter_info *filter)
3752 struct hwrm_cfa_ntuple_filter_alloc_input req = {.req_type = 0 };
3753 struct hwrm_cfa_ntuple_filter_alloc_output *resp =
3754 bp->hwrm_cmd_resp_addr;
3755 uint32_t enables = 0;
3757 if (filter->fw_ntuple_filter_id != UINT64_MAX)
3758 bnxt_hwrm_clear_ntuple_filter(bp, filter);
3760 HWRM_PREP(req, CFA_NTUPLE_FILTER_ALLOC);
3762 req.flags = rte_cpu_to_le_32(filter->flags);
3764 enables = filter->enables |
3765 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_ID;
3766 req.dst_id = rte_cpu_to_le_16(dst_id);
3769 if (filter->ip_addr_type) {
3770 req.ip_addr_type = filter->ip_addr_type;
3772 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_IPADDR_TYPE;
3775 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_L2_FILTER_ID)
3776 req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
3778 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_MACADDR)
3779 memcpy(req.src_macaddr, filter->src_macaddr,
3782 //HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_MACADDR)
3783 //memcpy(req.dst_macaddr, filter->dst_macaddr,
3786 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_ETHERTYPE)
3787 req.ethertype = rte_cpu_to_be_16(filter->ethertype);
3789 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_IP_PROTOCOL)
3790 req.ip_protocol = filter->ip_protocol;
3792 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_IPADDR)
3793 req.src_ipaddr[0] = rte_cpu_to_le_32(filter->src_ipaddr[0]);
3795 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_IPADDR_MASK)
3796 req.src_ipaddr_mask[0] =
3797 rte_cpu_to_le_32(filter->src_ipaddr_mask[0]);
3799 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_IPADDR)
3800 req.dst_ipaddr[0] = rte_cpu_to_le_32(filter->dst_ipaddr[0]);
3802 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_IPADDR_MASK)
3803 req.dst_ipaddr_mask[0] =
3804 rte_cpu_to_be_32(filter->dst_ipaddr_mask[0]);
3806 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_PORT)
3807 req.src_port = rte_cpu_to_le_16(filter->src_port);
3809 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_PORT_MASK)
3810 req.src_port_mask = rte_cpu_to_le_16(filter->src_port_mask);
3812 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_PORT)
3813 req.dst_port = rte_cpu_to_le_16(filter->dst_port);
3815 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_PORT_MASK)
3816 req.dst_port_mask = rte_cpu_to_le_16(filter->dst_port_mask);
3818 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_MIRROR_VNIC_ID)
3819 req.mirror_vnic_id = filter->mirror_vnic_id;
3821 req.enables = rte_cpu_to_le_32(enables);
3823 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3825 HWRM_CHECK_RESULT();
3827 filter->fw_ntuple_filter_id = rte_le_to_cpu_64(resp->ntuple_filter_id);
3833 int bnxt_hwrm_clear_ntuple_filter(struct bnxt *bp,
3834 struct bnxt_filter_info *filter)
3837 struct hwrm_cfa_ntuple_filter_free_input req = {.req_type = 0 };
3838 struct hwrm_cfa_ntuple_filter_free_output *resp =
3839 bp->hwrm_cmd_resp_addr;
3841 if (filter->fw_ntuple_filter_id == UINT64_MAX)
3844 HWRM_PREP(req, CFA_NTUPLE_FILTER_FREE);
3846 req.ntuple_filter_id = rte_cpu_to_le_64(filter->fw_ntuple_filter_id);
3848 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3850 HWRM_CHECK_RESULT();
3853 filter->fw_ntuple_filter_id = UINT64_MAX;
3858 int bnxt_vnic_rss_configure(struct bnxt *bp, struct bnxt_vnic_info *vnic)
3860 unsigned int rss_idx, fw_idx, i;
3862 if (vnic->rss_table && vnic->hash_type) {
3864 * Fill the RSS hash & redirection table with
3865 * ring group ids for all VNICs
3867 for (rss_idx = 0, fw_idx = 0; rss_idx < HW_HASH_INDEX_SIZE;
3868 rss_idx++, fw_idx++) {
3869 for (i = 0; i < bp->rx_cp_nr_rings; i++) {
3870 fw_idx %= bp->rx_cp_nr_rings;
3871 if (vnic->fw_grp_ids[fw_idx] !=
3876 if (i == bp->rx_cp_nr_rings)
3878 vnic->rss_table[rss_idx] =
3879 vnic->fw_grp_ids[fw_idx];
3881 return bnxt_hwrm_vnic_rss_cfg(bp, vnic);
3886 static void bnxt_hwrm_set_coal_params(struct bnxt_coal *hw_coal,
3887 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *req)
3891 req->num_cmpl_aggr_int = rte_cpu_to_le_16(hw_coal->num_cmpl_aggr_int);
3893 /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
3894 req->num_cmpl_dma_aggr = rte_cpu_to_le_16(hw_coal->num_cmpl_dma_aggr);
3896 /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
3897 req->num_cmpl_dma_aggr_during_int =
3898 rte_cpu_to_le_16(hw_coal->num_cmpl_dma_aggr_during_int);
3900 req->int_lat_tmr_max = rte_cpu_to_le_16(hw_coal->int_lat_tmr_max);
3902 /* min timer set to 1/2 of interrupt timer */
3903 req->int_lat_tmr_min = rte_cpu_to_le_16(hw_coal->int_lat_tmr_min);
3905 /* buf timer set to 1/4 of interrupt timer */
3906 req->cmpl_aggr_dma_tmr = rte_cpu_to_le_16(hw_coal->cmpl_aggr_dma_tmr);
3908 req->cmpl_aggr_dma_tmr_during_int =
3909 rte_cpu_to_le_16(hw_coal->cmpl_aggr_dma_tmr_during_int);
3911 flags = HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_TIMER_RESET |
3912 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_RING_IDLE;
3913 req->flags = rte_cpu_to_le_16(flags);
3916 int bnxt_hwrm_set_ring_coal(struct bnxt *bp,
3917 struct bnxt_coal *coal, uint16_t ring_id)
3919 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req = {0};
3920 struct hwrm_ring_cmpl_ring_cfg_aggint_params_output *resp =
3921 bp->hwrm_cmd_resp_addr;
3924 /* Set ring coalesce parameters only for Stratus 100G NIC */
3925 if (!bnxt_stratus_device(bp))
3928 HWRM_PREP(req, RING_CMPL_RING_CFG_AGGINT_PARAMS);
3929 bnxt_hwrm_set_coal_params(coal, &req);
3930 req.ring_id = rte_cpu_to_le_16(ring_id);
3931 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
3932 HWRM_CHECK_RESULT();