net/bnxt: support async link notification
[dpdk.git] / drivers / net / bnxt / bnxt_cpr.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) Broadcom Limited.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Broadcom Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <rte_malloc.h>
35
36 #include "bnxt.h"
37 #include "bnxt_cpr.h"
38 #include "bnxt_hwrm.h"
39 #include "bnxt_ring.h"
40 #include "hsi_struct_def_dpdk.h"
41
42 /*
43  * Async event handling
44  */
45 void bnxt_handle_async_event(struct bnxt *bp,
46                              struct cmpl_base *cmp)
47 {
48         struct hwrm_async_event_cmpl *async_cmp =
49                                 (struct hwrm_async_event_cmpl *)cmp;
50         uint16_t event_id = rte_le_to_cpu_16(async_cmp->event_id);
51
52         /* TODO: HWRM async events are not defined yet */
53         /* Needs to handle: link events, error events, etc. */
54         switch (event_id) {
55         case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE:
56         case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CHANGE:
57         case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE:
58                 bnxt_link_update_op(bp->eth_dev, 0);
59                 break;
60         default:
61                 RTE_LOG(ERR, PMD, "handle_async_event id = 0x%x\n", event_id);
62                 break;
63         }
64 }
65
66 void bnxt_handle_fwd_req(struct bnxt *bp, struct cmpl_base *cmpl)
67 {
68         struct hwrm_fwd_req_cmpl *fwd_cmpl = (struct hwrm_fwd_req_cmpl *)cmpl;
69         struct input *fwd_cmd;
70         uint16_t logical_vf_id, error_code;
71
72         /* Qualify the fwd request */
73         if (fwd_cmpl->source_id < bp->pf.first_vf_id) {
74                 RTE_LOG(ERR, PMD,
75                         "FWD req's source_id 0x%x > first_vf_id 0x%x\n",
76                         fwd_cmpl->source_id, bp->pf.first_vf_id);
77                 error_code = HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED;
78                 goto reject;
79         } else if (fwd_cmpl->req_len_type >> HWRM_FWD_REQ_CMPL_REQ_LEN_SFT >
80                    128 - sizeof(struct input)) {
81                 RTE_LOG(ERR, PMD,
82                     "FWD req's cmd len 0x%x > 108 bytes allowed\n",
83                     fwd_cmpl->req_len_type >> HWRM_FWD_REQ_CMPL_REQ_LEN_SFT);
84                 error_code = HWRM_ERR_CODE_INVALID_PARAMS;
85                 goto reject;
86         }
87
88         /* Locate VF's forwarded command */
89         logical_vf_id = fwd_cmpl->source_id - bp->pf.first_vf_id;
90         fwd_cmd = (struct input *)((uint8_t *)bp->pf.vf_req_buf +
91                    (logical_vf_id * 128));
92
93         /* Provision the request */
94         switch (fwd_cmd->req_type) {
95         case HWRM_CFA_L2_FILTER_ALLOC:
96         case HWRM_CFA_L2_FILTER_FREE:
97         case HWRM_CFA_L2_FILTER_CFG:
98         case HWRM_CFA_L2_SET_RX_MASK:
99                 break;
100         default:
101                 error_code = HWRM_ERR_CODE_INVALID_PARAMS;
102                 goto reject;
103         }
104
105         /* Forward */
106         fwd_cmd->target_id = fwd_cmpl->source_id;
107         bnxt_hwrm_exec_fwd_resp(bp, fwd_cmd);
108         return;
109
110 reject:
111         /* TODO: Encap the reject error resp into the hwrm_err_iput? */
112         /* Use the error_code for the reject cmd */
113         RTE_LOG(ERR, PMD,
114                 "Error 0x%x found in the forward request\n", error_code);
115 }
116
117 /* For the default completion ring only */
118 void bnxt_free_def_cp_ring(struct bnxt *bp)
119 {
120         struct bnxt_cp_ring_info *cpr = bp->def_cp_ring;
121
122         if (cpr == NULL)
123                 return;
124
125         bnxt_free_ring(cpr->cp_ring_struct);
126         rte_free(cpr->cp_ring_struct);
127         rte_free(cpr);
128 }
129
130 /* For the default completion ring only */
131 int bnxt_init_def_ring_struct(struct bnxt *bp, unsigned int socket_id)
132 {
133         struct bnxt_cp_ring_info *cpr;
134         struct bnxt_ring *ring;
135
136         cpr = rte_zmalloc_socket("cpr",
137                                  sizeof(struct bnxt_cp_ring_info),
138                                  RTE_CACHE_LINE_SIZE, socket_id);
139         if (cpr == NULL)
140                 return -ENOMEM;
141         bp->def_cp_ring = cpr;
142
143         ring = rte_zmalloc_socket("bnxt_cp_ring_struct",
144                                   sizeof(struct bnxt_ring),
145                                   RTE_CACHE_LINE_SIZE, socket_id);
146         if (ring == NULL)
147                 return -ENOMEM;
148         cpr->cp_ring_struct = ring;
149         ring->bd = (void *)cpr->cp_desc_ring;
150         ring->bd_dma = cpr->cp_desc_mapping;
151         ring->ring_size = rte_align32pow2(DEFAULT_CP_RING_SIZE);
152         ring->ring_mask = ring->ring_size - 1;
153         ring->vmem_size = 0;
154         ring->vmem = NULL;
155
156         return 0;
157 }