1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2018 Broadcom
6 #include <rte_malloc.h>
8 #include <rte_cycles.h>
12 #include "bnxt_hwrm.h"
13 #include "bnxt_ring.h"
14 #include "hsi_struct_def_dpdk.h"
16 void bnxt_wait_for_device_shutdown(struct bnxt *bp)
18 uint32_t val, timeout;
20 /* if HWRM_FUNC_QCAPS_OUTPUT_FLAGS_ERR_RECOVER_RELOAD is set
21 * in HWRM_FUNC_QCAPS command, wait for FW_STATUS to set
22 * the SHUTDOWN bit in health register
24 if (!(bp->recovery_info &&
25 (bp->flags & BNXT_FLAG_FW_CAP_ERR_RECOVER_RELOAD)))
28 /* Driver has to wait for fw_reset_max_msecs or shutdown bit which comes
29 * first for FW to collect crash dump.
31 timeout = bp->fw_reset_max_msecs;
33 /* Driver has to poll for shutdown bit in fw_status register
35 * 1. in case of hot fw upgrade, this bit will be set after all
36 * function drivers unregistered with fw.
37 * 2. in case of fw initiated error recovery, this bit will be
38 * set after fw has collected the core dump
41 val = bnxt_read_fw_status_reg(bp, BNXT_FW_STATUS_REG);
42 if (val & BNXT_FW_STATUS_SHUTDOWN)
51 * Async event handling
53 void bnxt_handle_async_event(struct bnxt *bp,
54 struct cmpl_base *cmp)
56 struct hwrm_async_event_cmpl *async_cmp =
57 (struct hwrm_async_event_cmpl *)cmp;
58 uint16_t event_id = rte_le_to_cpu_16(async_cmp->event_id);
59 struct bnxt_error_recovery_info *info;
62 /* TODO: HWRM async events are not defined yet */
63 /* Needs to handle: link events, error events, etc. */
65 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE:
66 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CHANGE:
67 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE:
69 bnxt_link_update_op(bp->eth_dev, 1);
71 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD:
72 PMD_DRV_LOG(INFO, "Async event: PF driver unloaded\n");
74 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE:
75 PMD_DRV_LOG(INFO, "Async event: VF config changed\n");
76 bnxt_hwrm_func_qcfg(bp, NULL);
78 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED:
79 PMD_DRV_LOG(INFO, "Port conn async event\n");
81 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_RESET_NOTIFY:
82 event_data = rte_le_to_cpu_32(async_cmp->event_data1);
83 /* timestamp_lo/hi values are in units of 100ms */
84 bp->fw_reset_max_msecs = async_cmp->timestamp_hi ?
85 rte_le_to_cpu_16(async_cmp->timestamp_hi) * 100 :
86 BNXT_MAX_FW_RESET_TIMEOUT;
87 bp->fw_reset_min_msecs = async_cmp->timestamp_lo ?
88 async_cmp->timestamp_lo * 100 :
89 BNXT_MIN_FW_READY_TIMEOUT;
90 if ((event_data & EVENT_DATA1_REASON_CODE_MASK) ==
91 EVENT_DATA1_REASON_CODE_FW_EXCEPTION_FATAL) {
93 "Firmware fatal reset event received\n");
94 bp->flags |= BNXT_FLAG_FATAL_ERROR;
97 "Firmware non-fatal reset event received\n");
100 bp->flags |= BNXT_FLAG_FW_RESET;
101 rte_eal_alarm_set(US_PER_MS, bnxt_dev_reset_and_resume,
104 case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_ERROR_RECOVERY:
105 info = bp->recovery_info;
110 PMD_DRV_LOG(INFO, "Error recovery async event received\n");
112 event_data = rte_le_to_cpu_32(async_cmp->event_data1) &
113 EVENT_DATA1_FLAGS_MASK;
115 if (event_data & EVENT_DATA1_FLAGS_MASTER_FUNC)
116 info->flags |= BNXT_FLAG_MASTER_FUNC;
118 info->flags &= ~BNXT_FLAG_MASTER_FUNC;
120 if (event_data & EVENT_DATA1_FLAGS_RECOVERY_ENABLED)
121 info->flags |= BNXT_FLAG_RECOVERY_ENABLED;
123 info->flags &= ~BNXT_FLAG_RECOVERY_ENABLED;
125 PMD_DRV_LOG(INFO, "recovery enabled(%d), master function(%d)\n",
126 bnxt_is_recovery_enabled(bp),
127 bnxt_is_master_func(bp));
129 if (bp->flags & BNXT_FLAG_FW_HEALTH_CHECK_SCHEDULED)
132 info->last_heart_beat =
133 bnxt_read_fw_status_reg(bp, BNXT_FW_HEARTBEAT_CNT_REG);
134 info->last_reset_counter =
135 bnxt_read_fw_status_reg(bp, BNXT_FW_RECOVERY_CNT_REG);
137 bnxt_schedule_fw_health_check(bp);
140 PMD_DRV_LOG(DEBUG, "handle_async_event id = 0x%x\n", event_id);
145 void bnxt_handle_fwd_req(struct bnxt *bp, struct cmpl_base *cmpl)
147 struct hwrm_exec_fwd_resp_input *fwreq;
148 struct hwrm_fwd_req_cmpl *fwd_cmpl = (struct hwrm_fwd_req_cmpl *)cmpl;
149 struct input *fwd_cmd;
155 if (bp->pf.active_vfs <= 0) {
156 PMD_DRV_LOG(ERR, "Forwarded VF with no active VFs\n");
160 /* Qualify the fwd request */
161 fw_vf_id = rte_le_to_cpu_16(fwd_cmpl->source_id);
162 vf_id = fw_vf_id - bp->pf.first_vf_id;
164 req_len = (rte_le_to_cpu_16(fwd_cmpl->req_len_type) &
165 HWRM_FWD_REQ_CMPL_REQ_LEN_MASK) >>
166 HWRM_FWD_REQ_CMPL_REQ_LEN_SFT;
167 if (req_len > sizeof(fwreq->encap_request))
168 req_len = sizeof(fwreq->encap_request);
170 /* Locate VF's forwarded command */
171 fwd_cmd = (struct input *)bp->pf.vf_info[vf_id].req_buf;
173 if (fw_vf_id < bp->pf.first_vf_id ||
174 fw_vf_id >= (bp->pf.first_vf_id) + bp->pf.active_vfs) {
176 "FWD req's source_id 0x%x out of range 0x%x - 0x%x (%d %d)\n",
177 fw_vf_id, bp->pf.first_vf_id,
178 (bp->pf.first_vf_id) + bp->pf.active_vfs - 1,
179 bp->pf.first_vf_id, bp->pf.active_vfs);
183 if (bnxt_rcv_msg_from_vf(bp, vf_id, fwd_cmd) == true) {
185 * In older firmware versions, the MAC had to be all zeros for
186 * the VF to set it's MAC via hwrm_func_vf_cfg. Set to all
187 * zeros if it's being configured and has been ok'd by caller.
189 if (fwd_cmd->req_type == HWRM_FUNC_VF_CFG) {
190 struct hwrm_func_vf_cfg_input *vfc = (void *)fwd_cmd;
193 HWRM_FUNC_VF_CFG_INPUT_ENABLES_DFLT_MAC_ADDR) {
194 bnxt_hwrm_func_vf_mac(bp, vf_id,
195 (const uint8_t *)"\x00\x00\x00\x00\x00");
198 if (fwd_cmd->req_type == HWRM_CFA_L2_SET_RX_MASK) {
199 struct hwrm_cfa_l2_set_rx_mask_input *srm =
202 srm->vlan_tag_tbl_addr = rte_cpu_to_le_64(0);
203 srm->num_vlan_tags = rte_cpu_to_le_32(0);
204 srm->mask &= ~rte_cpu_to_le_32(
205 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLANONLY |
206 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLAN_NONVLAN |
207 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ANYVLAN_NONVLAN);
210 rc = bnxt_hwrm_exec_fwd_resp(bp, fw_vf_id, fwd_cmd, req_len);
213 "Failed to send FWD req VF 0x%x, type 0x%x.\n",
214 fw_vf_id - bp->pf.first_vf_id,
215 rte_le_to_cpu_16(fwd_cmd->req_type));
221 rc = bnxt_hwrm_reject_fwd_resp(bp, fw_vf_id, fwd_cmd, req_len);
224 "Failed to send REJECT req VF 0x%x, type 0x%x.\n",
225 fw_vf_id - bp->pf.first_vf_id,
226 rte_le_to_cpu_16(fwd_cmd->req_type));
232 int bnxt_event_hwrm_resp_handler(struct bnxt *bp, struct cmpl_base *cmp)
236 if (bp == NULL || cmp == NULL) {
237 PMD_DRV_LOG(ERR, "invalid NULL argument\n");
241 if (unlikely(is_bnxt_in_error(bp)))
244 switch (CMP_TYPE(cmp)) {
245 case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT:
246 /* Handle any async event */
247 bnxt_handle_async_event(bp, cmp);
250 case CMPL_BASE_TYPE_HWRM_FWD_RESP:
251 /* Handle HWRM forwarded responses */
252 bnxt_handle_fwd_req(bp, cmp);
256 /* Ignore any other events */
257 PMD_DRV_LOG(DEBUG, "Ignoring %02x completion\n", CMP_TYPE(cmp));
264 bool bnxt_is_master_func(struct bnxt *bp)
266 if (bp->recovery_info->flags & BNXT_FLAG_MASTER_FUNC)
272 bool bnxt_is_recovery_enabled(struct bnxt *bp)
274 struct bnxt_error_recovery_info *info;
276 info = bp->recovery_info;
277 if (info && (info->flags & BNXT_FLAG_RECOVERY_ENABLED))