net/bnxt: handle reset notify async event from FW
[dpdk.git] / drivers / net / bnxt / bnxt_cpr.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2014-2018 Broadcom
3  * All rights reserved.
4  */
5
6 #include <rte_malloc.h>
7 #include <rte_alarm.h>
8
9 #include "bnxt.h"
10 #include "bnxt_cpr.h"
11 #include "bnxt_hwrm.h"
12 #include "bnxt_ring.h"
13 #include "hsi_struct_def_dpdk.h"
14
15 /*
16  * Async event handling
17  */
18 void bnxt_handle_async_event(struct bnxt *bp,
19                              struct cmpl_base *cmp)
20 {
21         struct hwrm_async_event_cmpl *async_cmp =
22                                 (struct hwrm_async_event_cmpl *)cmp;
23         uint16_t event_id = rte_le_to_cpu_16(async_cmp->event_id);
24
25         /* TODO: HWRM async events are not defined yet */
26         /* Needs to handle: link events, error events, etc. */
27         switch (event_id) {
28         case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE:
29         case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CHANGE:
30         case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE:
31                 /* FALLTHROUGH */
32                 bnxt_link_update_op(bp->eth_dev, 1);
33                 break;
34         case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD:
35                 PMD_DRV_LOG(INFO, "Async event: PF driver unloaded\n");
36                 break;
37         case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE:
38                 PMD_DRV_LOG(INFO, "Async event: VF config changed\n");
39                 bnxt_hwrm_func_qcfg(bp, NULL);
40                 break;
41         case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED:
42                 PMD_DRV_LOG(INFO, "Port conn async event\n");
43                 break;
44         case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_RESET_NOTIFY:
45                 /* timestamp_lo/hi values are in units of 100ms */
46                 bp->fw_reset_max_msecs = async_cmp->timestamp_hi ?
47                         rte_le_to_cpu_16(async_cmp->timestamp_hi) * 100 :
48                         BNXT_MAX_FW_RESET_TIMEOUT;
49                 bp->fw_reset_min_msecs = async_cmp->timestamp_lo ?
50                         async_cmp->timestamp_lo * 100 :
51                         BNXT_MIN_FW_READY_TIMEOUT;
52                 PMD_DRV_LOG(INFO,
53                             "Firmware non-fatal reset event received\n");
54
55                 bp->flags |= BNXT_FLAG_FW_RESET;
56                 rte_eal_alarm_set(US_PER_MS, bnxt_dev_reset_and_resume,
57                                   (void *)bp);
58                 break;
59         default:
60                 PMD_DRV_LOG(INFO, "handle_async_event id = 0x%x\n", event_id);
61                 break;
62         }
63 }
64
65 void bnxt_handle_fwd_req(struct bnxt *bp, struct cmpl_base *cmpl)
66 {
67         struct hwrm_exec_fwd_resp_input *fwreq;
68         struct hwrm_fwd_req_cmpl *fwd_cmpl = (struct hwrm_fwd_req_cmpl *)cmpl;
69         struct input *fwd_cmd;
70         uint16_t fw_vf_id;
71         uint16_t vf_id;
72         uint16_t req_len;
73         int rc;
74
75         if (bp->pf.active_vfs <= 0) {
76                 PMD_DRV_LOG(ERR, "Forwarded VF with no active VFs\n");
77                 return;
78         }
79
80         /* Qualify the fwd request */
81         fw_vf_id = rte_le_to_cpu_16(fwd_cmpl->source_id);
82         vf_id = fw_vf_id - bp->pf.first_vf_id;
83
84         req_len = (rte_le_to_cpu_16(fwd_cmpl->req_len_type) &
85                    HWRM_FWD_REQ_CMPL_REQ_LEN_MASK) >>
86                 HWRM_FWD_REQ_CMPL_REQ_LEN_SFT;
87         if (req_len > sizeof(fwreq->encap_request))
88                 req_len = sizeof(fwreq->encap_request);
89
90         /* Locate VF's forwarded command */
91         fwd_cmd = (struct input *)bp->pf.vf_info[vf_id].req_buf;
92
93         if (fw_vf_id < bp->pf.first_vf_id ||
94             fw_vf_id >= (bp->pf.first_vf_id) + bp->pf.active_vfs) {
95                 PMD_DRV_LOG(ERR,
96                 "FWD req's source_id 0x%x out of range 0x%x - 0x%x (%d %d)\n",
97                         fw_vf_id, bp->pf.first_vf_id,
98                         (bp->pf.first_vf_id) + bp->pf.active_vfs - 1,
99                         bp->pf.first_vf_id, bp->pf.active_vfs);
100                 goto reject;
101         }
102
103         if (bnxt_rcv_msg_from_vf(bp, vf_id, fwd_cmd) == true) {
104                 /*
105                  * In older firmware versions, the MAC had to be all zeros for
106                  * the VF to set it's MAC via hwrm_func_vf_cfg. Set to all
107                  * zeros if it's being configured and has been ok'd by caller.
108                  */
109                 if (fwd_cmd->req_type == HWRM_FUNC_VF_CFG) {
110                         struct hwrm_func_vf_cfg_input *vfc = (void *)fwd_cmd;
111
112                         if (vfc->enables &
113                             HWRM_FUNC_VF_CFG_INPUT_ENABLES_DFLT_MAC_ADDR) {
114                                 bnxt_hwrm_func_vf_mac(bp, vf_id,
115                                 (const uint8_t *)"\x00\x00\x00\x00\x00");
116                         }
117                 }
118                 if (fwd_cmd->req_type == HWRM_CFA_L2_SET_RX_MASK) {
119                         struct hwrm_cfa_l2_set_rx_mask_input *srm =
120                                                         (void *)fwd_cmd;
121
122                         srm->vlan_tag_tbl_addr = rte_cpu_to_le_64(0);
123                         srm->num_vlan_tags = rte_cpu_to_le_32(0);
124                         srm->mask &= ~rte_cpu_to_le_32(
125                                 HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLANONLY |
126                             HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLAN_NONVLAN |
127                             HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ANYVLAN_NONVLAN);
128                 }
129                 /* Forward */
130                 rc = bnxt_hwrm_exec_fwd_resp(bp, fw_vf_id, fwd_cmd, req_len);
131                 if (rc) {
132                         PMD_DRV_LOG(ERR,
133                                 "Failed to send FWD req VF 0x%x, type 0x%x.\n",
134                                 fw_vf_id - bp->pf.first_vf_id,
135                                 rte_le_to_cpu_16(fwd_cmd->req_type));
136                 }
137                 return;
138         }
139
140 reject:
141         rc = bnxt_hwrm_reject_fwd_resp(bp, fw_vf_id, fwd_cmd, req_len);
142         if (rc) {
143                 PMD_DRV_LOG(ERR,
144                         "Failed to send REJECT req VF 0x%x, type 0x%x.\n",
145                         fw_vf_id - bp->pf.first_vf_id,
146                         rte_le_to_cpu_16(fwd_cmd->req_type));
147         }
148
149         return;
150 }
151
152 int bnxt_event_hwrm_resp_handler(struct bnxt *bp, struct cmpl_base *cmp)
153 {
154         bool evt = 0;
155
156         if (bp == NULL || cmp == NULL) {
157                 PMD_DRV_LOG(ERR, "invalid NULL argument\n");
158                 return evt;
159         }
160
161         if (unlikely(is_bnxt_in_error(bp)))
162                 return 0;
163
164         switch (CMP_TYPE(cmp)) {
165         case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT:
166                 /* Handle any async event */
167                 bnxt_handle_async_event(bp, cmp);
168                 evt = 1;
169                 break;
170         case CMPL_BASE_TYPE_HWRM_FWD_RESP:
171                 /* Handle HWRM forwarded responses */
172                 bnxt_handle_fwd_req(bp, cmp);
173                 evt = 1;
174                 break;
175         default:
176                 /* Ignore any other events */
177                 PMD_DRV_LOG(INFO, "Ignoring %02x completion\n", CMP_TYPE(cmp));
178                 break;
179         }
180
181         return evt;
182 }