]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - sys/dev/qlnx/qlnxe/ecore_spq.h
MFC r316485
[FreeBSD/stable/10.git] / sys / dev / qlnx / qlnxe / ecore_spq.h
1 /*
2  * Copyright (c) 2017-2018 Cavium, Inc. 
3  * All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions
7  *  are met:
8  *
9  *  1. Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  *  2. Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  *
15  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  *  POSSIBILITY OF SUCH DAMAGE.
26  *
27  * $FreeBSD$
28  *
29  */
30
31 #ifndef __ECORE_SPQ_H__
32 #define __ECORE_SPQ_H__
33
34 #include "ecore_hsi_common.h"
35 #include "ecore_status.h"
36 #include "ecore_hsi_eth.h"
37 #include "ecore_hsi_fcoe.h"
38 #include "tcp_common.h"
39 #include "ecore_hsi_iscsi.h"
40 #include "ecore_hsi_roce.h"
41 #include "ecore_hsi_iwarp.h"
42 #include "ecore_chain.h"
43 #include "ecore_sp_api.h"
44
45 union ramrod_data
46 {
47         struct pf_start_ramrod_data                     pf_start;
48         struct pf_update_ramrod_data                    pf_update;
49         struct rl_update_ramrod_data                    rl_update;
50         struct rx_queue_start_ramrod_data               rx_queue_start;
51         struct rx_queue_update_ramrod_data              rx_queue_update;
52         struct rx_queue_stop_ramrod_data                rx_queue_stop;
53         struct tx_queue_start_ramrod_data               tx_queue_start;
54         struct tx_queue_stop_ramrod_data                tx_queue_stop;
55         struct vport_start_ramrod_data                  vport_start;
56         struct vport_stop_ramrod_data                   vport_stop;
57         struct rx_update_gft_filter_data                rx_update_gft;
58         struct vport_update_ramrod_data                 vport_update;
59         struct core_rx_start_ramrod_data                core_rx_queue_start;
60         struct core_rx_stop_ramrod_data                 core_rx_queue_stop;
61         struct core_tx_start_ramrod_data                core_tx_queue_start;
62         struct core_tx_stop_ramrod_data                 core_tx_queue_stop;
63         struct vport_filter_update_ramrod_data          vport_filter_update;
64
65         struct rdma_init_func_ramrod_data               rdma_init_func;
66         struct rdma_close_func_ramrod_data              rdma_close_func;
67         struct rdma_register_tid_ramrod_data            rdma_register_tid;
68         struct rdma_deregister_tid_ramrod_data          rdma_deregister_tid;
69         struct roce_create_qp_resp_ramrod_data          roce_create_qp_resp;
70         struct roce_create_qp_req_ramrod_data           roce_create_qp_req;
71         struct roce_modify_qp_resp_ramrod_data          roce_modify_qp_resp;
72         struct roce_modify_qp_req_ramrod_data           roce_modify_qp_req;
73         struct roce_query_qp_resp_ramrod_data           roce_query_qp_resp;
74         struct roce_query_qp_req_ramrod_data            roce_query_qp_req;
75         struct roce_destroy_qp_resp_ramrod_data         roce_destroy_qp_resp;
76         struct roce_destroy_qp_req_ramrod_data          roce_destroy_qp_req;
77         struct roce_init_func_ramrod_data               roce_init_func;
78
79         struct rdma_create_cq_ramrod_data               rdma_create_cq;
80         struct rdma_resize_cq_ramrod_data               rdma_resize_cq;
81         struct rdma_destroy_cq_ramrod_data              rdma_destroy_cq;        
82         struct rdma_srq_create_ramrod_data              rdma_create_srq;
83         struct rdma_srq_destroy_ramrod_data             rdma_destroy_srq;
84         struct rdma_srq_modify_ramrod_data              rdma_modify_srq;
85
86         struct iwarp_create_qp_ramrod_data              iwarp_create_qp;
87         struct iwarp_tcp_offload_ramrod_data            iwarp_tcp_offload;
88         struct iwarp_mpa_offload_ramrod_data            iwarp_mpa_offload;
89         struct iwarp_modify_qp_ramrod_data              iwarp_modify_qp;
90         struct iwarp_query_qp_ramrod_data               iwarp_query_qp;
91         struct iwarp_init_func_ramrod_data              iwarp_init_func;
92
93         struct fcoe_init_ramrod_params                  fcoe_init;
94         struct fcoe_conn_offload_ramrod_params          fcoe_conn_ofld;
95         struct fcoe_conn_terminate_ramrod_params        fcoe_conn_terminate;
96         struct fcoe_stat_ramrod_params                  fcoe_stat;
97
98         struct iscsi_slow_path_hdr                      iscsi_empty;
99         struct iscsi_init_ramrod_params                 iscsi_init;
100         struct iscsi_spe_func_dstry                     iscsi_destroy;
101         struct iscsi_spe_conn_offload                   iscsi_conn_offload;
102         struct iscsi_conn_update_ramrod_params          iscsi_conn_update;
103         struct iscsi_spe_conn_mac_update                iscsi_conn_mac_update;
104         struct iscsi_spe_conn_termination               iscsi_conn_terminate;
105
106         struct vf_start_ramrod_data                     vf_start;
107         struct vf_stop_ramrod_data                      vf_stop;
108 };
109
110 #define EQ_MAX_CREDIT   0xffffffff
111
112 enum spq_priority {
113         ECORE_SPQ_PRIORITY_NORMAL,
114         ECORE_SPQ_PRIORITY_HIGH,
115 };
116
117 union ecore_spq_req_comp {
118         struct ecore_spq_comp_cb cb;
119         u64                      *done_addr;
120 };
121
122 /* SPQ_MODE_EBLOCK */
123 struct ecore_spq_comp_done {
124         u64 done;
125         u8  fw_return_code;
126 };
127
128 struct ecore_spq_entry {
129         osal_list_entry_t               list;
130
131         u8                              flags;
132
133         /* HSI slow path element */
134         struct slow_path_element        elem;
135
136         union ramrod_data               ramrod;
137
138         enum spq_priority               priority;
139
140         /* pending queue for this entry */
141         osal_list_t                     *queue;
142
143         enum spq_mode                   comp_mode;
144         struct ecore_spq_comp_cb        comp_cb;
145         struct ecore_spq_comp_done      comp_done; /* SPQ_MODE_EBLOCK */
146 };
147
148 struct ecore_eq {
149         struct ecore_chain      chain;
150         u8                      eq_sb_index;    /* index within the SB */
151         __le16                  *p_fw_cons;     /* ptr to index value */
152 };
153
154 struct ecore_consq {
155         struct ecore_chain      chain;
156 };
157
158 struct ecore_spq {
159         osal_spinlock_t                 lock;
160
161         osal_list_t                     unlimited_pending;
162         osal_list_t                     pending;
163         osal_list_t                     completion_pending;
164         osal_list_t                     free_pool;
165
166         struct ecore_chain              chain;
167
168         /* allocated dma-able memory for spq entries (+ramrod data) */
169         dma_addr_t                      p_phys;
170         struct ecore_spq_entry          *p_virt;
171
172         /* Bitmap for handling out-of-order completions */
173 #define SPQ_RING_SIZE           \
174         (CORE_SPQE_PAGE_SIZE_BYTES / sizeof(struct slow_path_element))
175 #define SPQ_COMP_BMAP_SIZE      (SPQ_RING_SIZE / (sizeof(unsigned long) * 8 /* BITS_PER_LONG */))
176         unsigned long                   p_comp_bitmap[SPQ_COMP_BMAP_SIZE];
177         u8                              comp_bitmap_idx;
178 #define SPQ_COMP_BMAP_SET_BIT(p_spq, idx)                                       \
179         do {                                                                    \
180                 OSAL_SET_BIT(((idx) % SPQ_RING_SIZE), (p_spq)->p_comp_bitmap);  \
181         } while (0)
182 #define SPQ_COMP_BMAP_CLEAR_BIT(p_spq, idx)                                             \
183         do {                                                                            \
184                 OSAL_CLEAR_BIT(((idx) % SPQ_RING_SIZE), (p_spq)->p_comp_bitmap);        \
185         } while (0)
186 #define SPQ_COMP_BMAP_TEST_BIT(p_spq, idx)      \
187         (OSAL_TEST_BIT(((idx) % SPQ_RING_SIZE), (p_spq)->p_comp_bitmap))
188
189         /* Statistics */
190         u32                             unlimited_pending_count;
191         u32                             normal_count;
192         u32                             high_count;
193         u32                             comp_sent_count;
194         u32                             comp_count;
195
196         u32                             cid;
197 };
198
199 struct ecore_port;
200 struct ecore_hwfn;
201
202 /**
203  * @brief ecore_spq_post - Posts a Slow hwfn request to FW, or lacking that
204  *        Pends it to the future list.
205  *
206  * @param p_hwfn
207  * @param p_req
208  *
209  * @return enum _ecore_status_t
210  */
211 enum _ecore_status_t ecore_spq_post(struct ecore_hwfn      *p_hwfn,
212                                     struct ecore_spq_entry *p_ent,
213                                     u8                     *fw_return_code);
214
215 /**
216  * @brief ecore_spq_allocate - Alloocates & initializes the SPQ and EQ.
217  *
218  * @param p_hwfn
219  *
220  * @return enum _ecore_status_t
221  */
222 enum _ecore_status_t ecore_spq_alloc(struct ecore_hwfn  *p_hwfn);
223
224 /**
225  * @brief ecore_spq_setup - Reset the SPQ to its start state.
226  *
227  * @param p_hwfn
228  */
229 void ecore_spq_setup(struct ecore_hwfn *p_hwfn);
230
231 /**
232  * @brief ecore_spq_deallocate - Deallocates the given SPQ struct.
233  *
234  * @param p_hwfn
235  */
236 void ecore_spq_free(struct ecore_hwfn *p_hwfn);
237
238 /**
239  * @brief ecore_spq_get_entry - Obtain an entrry from the spq
240  *        free pool list.
241  *
242  *
243  *
244  * @param p_hwfn
245  * @param pp_ent
246  *
247  * @return enum _ecore_status_t
248  */
249 enum _ecore_status_t
250 ecore_spq_get_entry(struct ecore_hwfn           *p_hwfn,
251                     struct ecore_spq_entry      **pp_ent);
252
253 /**
254  * @brief ecore_spq_return_entry - Return an entry to spq free
255  *                                 pool list
256  *
257  * @param p_hwfn
258  * @param p_ent
259  */
260 void ecore_spq_return_entry(struct ecore_hwfn           *p_hwfn,
261                             struct ecore_spq_entry      *p_ent);
262 /**
263  * @brief ecore_eq_allocate - Allocates & initializes an EQ struct
264  *
265  * @param p_hwfn
266  * @param num_elem number of elements in the eq
267  *
268  * @return enum _ecore_status_t
269  */
270 enum _ecore_status_t ecore_eq_alloc(struct ecore_hwfn   *p_hwfn, u16 num_elem);
271
272 /**
273  * @brief ecore_eq_setup - Reset the EQ to its start state.
274  *
275  * @param p_hwfn
276  */
277 void ecore_eq_setup(struct ecore_hwfn *p_hwfn);
278
279 /**
280  * @brief ecore_eq_free - deallocates the given EQ struct.
281  *
282  * @param p_hwfn
283  */
284 void ecore_eq_free(struct ecore_hwfn *p_hwfn);
285
286 /**
287  * @brief ecore_eq_prod_update - update the FW with default EQ producer
288  *
289  * @param p_hwfn
290  * @param prod
291  */
292 void ecore_eq_prod_update(struct ecore_hwfn     *p_hwfn,
293                           u16                   prod);
294
295 /**
296  * @brief ecore_eq_completion - Completes currently pending EQ elements
297  *
298  * @param p_hwfn
299  * @param cookie
300  *
301  * @return enum _ecore_status_t
302  */
303 enum _ecore_status_t ecore_eq_completion(struct ecore_hwfn      *p_hwfn,
304                                          void                   *cookie);
305
306 /**
307  * @brief ecore_spq_completion - Completes a single event
308  *
309  * @param p_hwfn
310  * @param echo - echo value from cookie (used for determining completion)
311  * @param p_data - data from cookie (used in callback function if applicable)
312  *
313  * @return enum _ecore_status_t
314  */
315 enum _ecore_status_t ecore_spq_completion(struct ecore_hwfn     *p_hwfn,
316                                           __le16                echo,
317                                           u8                    fw_return_code,
318                                           union event_ring_data *p_data);
319
320 /**
321  * @brief ecore_spq_get_cid - Given p_hwfn, return cid for the hwfn's SPQ
322  *
323  * @param p_hwfn
324  *
325  * @return u32 - SPQ CID
326  */
327 u32 ecore_spq_get_cid(struct ecore_hwfn *p_hwfn);
328
329 /**
330  * @brief ecore_consq_alloc - Allocates & initializes an ConsQ struct
331  *
332  * @param p_hwfn
333  *
334  * @return enum _ecore_status_t
335  */
336 enum _ecore_status_t ecore_consq_alloc(struct ecore_hwfn *p_hwfn);
337
338 /**
339  * @brief ecore_consq_setup - Reset the ConsQ to its start state.
340  *
341  * @param p_hwfn
342  */
343 void ecore_consq_setup(struct ecore_hwfn *p_hwfn);
344
345 /**
346  * @brief ecore_consq_free - deallocates the given ConsQ struct.
347  *
348  * @param p_hwfn
349  */
350 void ecore_consq_free(struct ecore_hwfn *p_hwfn);
351
352 #endif /* __ECORE_SPQ_H__ */