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