7d9be3e96adaf33d27d4e3b3e6819abbb90cbc95
[dpdk.git] / drivers / net / qede / base / ecore_spq.h
1 /*
2  * Copyright (c) 2016 - 2018 Cavium Inc.
3  * All rights reserved.
4  * www.cavium.com
5  *
6  * See LICENSE.qede_pmd for copyright and licensing details.
7  */
8
9 #ifndef __ECORE_SPQ_H__
10 #define __ECORE_SPQ_H__
11
12 #include "ecore_hsi_common.h"
13 #include "ecore_status.h"
14 #include "ecore_hsi_eth.h"
15 #include "ecore_chain.h"
16 #include "ecore_sp_api.h"
17
18 union ramrod_data {
19         struct pf_start_ramrod_data                     pf_start;
20         struct pf_update_ramrod_data                    pf_update;
21         struct rl_update_ramrod_data                    rl_update;
22         struct rx_queue_start_ramrod_data               rx_queue_start;
23         struct rx_queue_update_ramrod_data              rx_queue_update;
24         struct rx_queue_stop_ramrod_data                rx_queue_stop;
25         struct tx_queue_start_ramrod_data               tx_queue_start;
26         struct tx_queue_stop_ramrod_data                tx_queue_stop;
27         struct vport_start_ramrod_data                  vport_start;
28         struct vport_stop_ramrod_data                   vport_stop;
29         struct rx_update_gft_filter_data                rx_update_gft;
30         struct vport_update_ramrod_data                 vport_update;
31         struct core_rx_start_ramrod_data                core_rx_queue_start;
32         struct core_rx_stop_ramrod_data                 core_rx_queue_stop;
33         struct core_tx_start_ramrod_data                core_tx_queue_start;
34         struct core_tx_stop_ramrod_data                 core_tx_queue_stop;
35         struct vport_filter_update_ramrod_data          vport_filter_update;
36
37         struct vf_start_ramrod_data                     vf_start;
38         struct vf_stop_ramrod_data                      vf_stop;
39 };
40
41 #define EQ_MAX_CREDIT   0xffffffff
42
43 enum spq_priority {
44         ECORE_SPQ_PRIORITY_NORMAL,
45         ECORE_SPQ_PRIORITY_HIGH,
46 };
47
48 union ecore_spq_req_comp {
49         struct ecore_spq_comp_cb cb;
50         u64                      *done_addr;
51 };
52
53 /* SPQ_MODE_EBLOCK */
54 struct ecore_spq_comp_done {
55         u64 done;
56         u8  fw_return_code;
57 };
58
59 struct ecore_spq_entry {
60         osal_list_entry_t               list;
61
62         u8                              flags;
63
64         /* HSI slow path element */
65         struct slow_path_element        elem;
66
67         union ramrod_data               ramrod;
68
69         enum spq_priority               priority;
70
71         /* pending queue for this entry */
72         osal_list_t                     *queue;
73
74         enum spq_mode                   comp_mode;
75         struct ecore_spq_comp_cb        comp_cb;
76         struct ecore_spq_comp_done      comp_done; /* SPQ_MODE_EBLOCK */
77 };
78
79 struct ecore_eq {
80         struct ecore_chain      chain;
81         u8                      eq_sb_index;    /* index within the SB */
82         __le16                  *p_fw_cons;     /* ptr to index value */
83 };
84
85 struct ecore_consq {
86         struct ecore_chain      chain;
87 };
88
89 typedef enum _ecore_status_t
90 (*ecore_spq_async_comp_cb)(struct ecore_hwfn *p_hwfn,
91                            u8 opcode,
92                            u16 echo,
93                            union event_ring_data *data,
94                            u8 fw_return_code);
95
96 enum _ecore_status_t
97 ecore_spq_register_async_cb(struct ecore_hwfn *p_hwfn,
98                             enum protocol_type protocol_id,
99                             ecore_spq_async_comp_cb cb);
100
101 void
102 ecore_spq_unregister_async_cb(struct ecore_hwfn *p_hwfn,
103                               enum protocol_type protocol_id);
104
105 struct ecore_spq {
106         osal_spinlock_t                 lock;
107
108         osal_list_t                     unlimited_pending;
109         osal_list_t                     pending;
110         osal_list_t                     completion_pending;
111         osal_list_t                     free_pool;
112
113         struct ecore_chain              chain;
114
115         /* allocated dma-able memory for spq entries (+ramrod data) */
116         dma_addr_t                      p_phys;
117         struct ecore_spq_entry          *p_virt;
118
119         /* SPQ max sleep iterations used in __ecore_spq_block() */
120         u32                             block_sleep_max_iter;
121
122         /* Bitmap for handling out-of-order completions */
123 #define SPQ_RING_SIZE           \
124         (CORE_SPQE_PAGE_SIZE_BYTES / sizeof(struct slow_path_element))
125 /* BITS_PER_LONG */
126 #define SPQ_COMP_BMAP_SIZE      (SPQ_RING_SIZE / (sizeof(unsigned long) * 8))
127         unsigned long                   p_comp_bitmap[SPQ_COMP_BMAP_SIZE];
128         u8                              comp_bitmap_idx;
129 #define SPQ_COMP_BMAP_SET_BIT(p_spq, idx)                               \
130         (OSAL_SET_BIT(((idx) % SPQ_RING_SIZE), (p_spq)->p_comp_bitmap))
131
132 #define SPQ_COMP_BMAP_CLEAR_BIT(p_spq, idx)                             \
133         (OSAL_CLEAR_BIT(((idx) % SPQ_RING_SIZE), (p_spq)->p_comp_bitmap))
134
135 #define SPQ_COMP_BMAP_TEST_BIT(p_spq, idx)      \
136         (OSAL_TEST_BIT(((idx) % SPQ_RING_SIZE), (p_spq)->p_comp_bitmap))
137
138         /* Statistics */
139         u32                             unlimited_pending_count;
140         u32                             normal_count;
141         u32                             high_count;
142         u32                             comp_sent_count;
143         u32                             comp_count;
144
145         u32                             cid;
146
147         u32                             db_addr_offset;
148         struct core_db_data             db_data;
149         ecore_spq_async_comp_cb         async_comp_cb[MAX_PROTOCOL_TYPE];
150 };
151
152 struct ecore_port;
153 struct ecore_hwfn;
154
155 /**
156  * @brief ecore_set_spq_block_timeout - calculates the maximum sleep
157  * iterations used in __ecore_spq_block();
158  *
159  * @param p_hwfn
160  * @param spq_timeout_ms
161  */
162 void ecore_set_spq_block_timeout(struct ecore_hwfn *p_hwfn,
163                                  u32 spq_timeout_ms);
164
165 /**
166  * @brief ecore_spq_post - Posts a Slow hwfn request to FW, or lacking that
167  *        Pends it to the future list.
168  *
169  * @param p_hwfn
170  * @param p_req
171  *
172  * @return enum _ecore_status_t
173  */
174 enum _ecore_status_t ecore_spq_post(struct ecore_hwfn      *p_hwfn,
175                                     struct ecore_spq_entry *p_ent,
176                                     u8                     *fw_return_code);
177
178 /**
179  * @brief ecore_spq_allocate - Alloocates & initializes the SPQ and EQ.
180  *
181  * @param p_hwfn
182  *
183  * @return enum _ecore_status_t
184  */
185 enum _ecore_status_t ecore_spq_alloc(struct ecore_hwfn  *p_hwfn);
186
187 /**
188  * @brief ecore_spq_setup - Reset the SPQ to its start state.
189  *
190  * @param p_hwfn
191  */
192 void ecore_spq_setup(struct ecore_hwfn *p_hwfn);
193
194 /**
195  * @brief ecore_spq_deallocate - Deallocates the given SPQ struct.
196  *
197  * @param p_hwfn
198  */
199 void ecore_spq_free(struct ecore_hwfn *p_hwfn);
200
201 /**
202  * @brief ecore_spq_get_entry - Obtain an entrry from the spq
203  *        free pool list.
204  *
205  *
206  *
207  * @param p_hwfn
208  * @param pp_ent
209  *
210  * @return enum _ecore_status_t
211  */
212 enum _ecore_status_t
213 ecore_spq_get_entry(struct ecore_hwfn           *p_hwfn,
214                     struct ecore_spq_entry      **pp_ent);
215
216 /**
217  * @brief ecore_spq_return_entry - Return an entry to spq free
218  *                                 pool list
219  *
220  * @param p_hwfn
221  * @param p_ent
222  */
223 void ecore_spq_return_entry(struct ecore_hwfn           *p_hwfn,
224                             struct ecore_spq_entry      *p_ent);
225 /**
226  * @brief ecore_eq_allocate - Allocates & initializes an EQ struct
227  *
228  * @param p_hwfn
229  * @param num_elem number of elements in the eq
230  *
231  * @return enum _ecore_status_t
232  */
233 enum _ecore_status_t ecore_eq_alloc(struct ecore_hwfn   *p_hwfn, u16 num_elem);
234
235 /**
236  * @brief ecore_eq_setup - Reset the EQ to its start state.
237  *
238  * @param p_hwfn
239  */
240 void ecore_eq_setup(struct ecore_hwfn *p_hwfn);
241
242 /**
243  * @brief ecore_eq_free - deallocates the given EQ struct.
244  *
245  * @param p_hwfn
246  */
247 void ecore_eq_free(struct ecore_hwfn *p_hwfn);
248
249 /**
250  * @brief ecore_eq_prod_update - update the FW with default EQ producer
251  *
252  * @param p_hwfn
253  * @param prod
254  */
255 void ecore_eq_prod_update(struct ecore_hwfn     *p_hwfn,
256                           u16                   prod);
257
258 /**
259  * @brief ecore_eq_completion - Completes currently pending EQ elements
260  *
261  * @param p_hwfn
262  * @param cookie
263  *
264  * @return enum _ecore_status_t
265  */
266 enum _ecore_status_t ecore_eq_completion(struct ecore_hwfn      *p_hwfn,
267                                          void                   *cookie);
268
269 /**
270  * @brief ecore_spq_completion - Completes a single event
271  *
272  * @param p_hwfn
273  * @param echo - echo value from cookie (used for determining completion)
274  * @param p_data - data from cookie (used in callback function if applicable)
275  *
276  * @return enum _ecore_status_t
277  */
278 enum _ecore_status_t ecore_spq_completion(struct ecore_hwfn     *p_hwfn,
279                                           __le16                echo,
280                                           u8                    fw_return_code,
281                                           union event_ring_data *p_data);
282
283 /**
284  * @brief ecore_spq_get_cid - Given p_hwfn, return cid for the hwfn's SPQ
285  *
286  * @param p_hwfn
287  *
288  * @return u32 - SPQ CID
289  */
290 u32 ecore_spq_get_cid(struct ecore_hwfn *p_hwfn);
291
292 /**
293  * @brief ecore_consq_alloc - Allocates & initializes an ConsQ struct
294  *
295  * @param p_hwfn
296  *
297  * @return enum _ecore_status_t
298  */
299 enum _ecore_status_t ecore_consq_alloc(struct ecore_hwfn *p_hwfn);
300
301 /**
302  * @brief ecore_consq_setup - Reset the ConsQ to its start state.
303  *
304  * @param p_hwfn
305  */
306 void ecore_consq_setup(struct ecore_hwfn *p_hwfn);
307
308 /**
309  * @brief ecore_consq_free - deallocates the given ConsQ struct.
310  *
311  * @param p_hwfn
312  */
313 void ecore_consq_free(struct ecore_hwfn *p_hwfn);
314
315 #endif /* __ECORE_SPQ_H__ */