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