blob: eec137f4089570a09d8fd8aaf9acc6831299f4ba [file] [log] [blame]
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001/* QLogic qed NIC Driver
2 * Copyright (c) 2015 QLogic Corporation
3 *
4 * This software is available under the terms of the GNU General Public License
5 * (GPL) Version 2, available from the file COPYING in the main directory of
6 * this source tree.
7 */
8
9#ifndef _QED_SP_H
10#define _QED_SP_H
11
12#include <linux/types.h>
13#include <linux/kernel.h>
14#include <linux/list.h>
15#include <linux/slab.h>
16#include <linux/spinlock.h>
17#include <linux/qed/qed_chain.h>
18#include "qed.h"
19#include "qed_hsi.h"
20
21enum spq_mode {
22 QED_SPQ_MODE_BLOCK, /* Client will poll a designated mem. address */
23 QED_SPQ_MODE_CB, /* Client supplies a callback */
24 QED_SPQ_MODE_EBLOCK, /* QED should block until completion */
25};
26
27struct qed_spq_comp_cb {
28 void (*function)(struct qed_hwfn *,
29 void *,
30 union event_ring_data *,
31 u8 fw_return_code);
32 void *cookie;
33};
34
Manish Chopracee4d262015-10-26 11:02:28 +020035/**
36 * @brief qed_eth_cqe_completion - handles the completion of a
37 * ramrod on the cqe ring
38 *
39 * @param p_hwfn
40 * @param cqe
41 *
42 * @return int
43 */
44int qed_eth_cqe_completion(struct qed_hwfn *p_hwfn,
45 struct eth_slow_path_rx_cqe *cqe);
46
47/**
48 * @file
49 *
50 * QED Slow-hwfn queue interface
51 */
52
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020053union ramrod_data {
54 struct pf_start_ramrod_data pf_start;
Manish Chopra464f6642016-04-14 01:38:29 -040055 struct pf_update_ramrod_data pf_update;
Manish Chopracee4d262015-10-26 11:02:28 +020056 struct rx_queue_start_ramrod_data rx_queue_start;
57 struct rx_queue_update_ramrod_data rx_queue_update;
58 struct rx_queue_stop_ramrod_data rx_queue_stop;
59 struct tx_queue_start_ramrod_data tx_queue_start;
60 struct tx_queue_stop_ramrod_data tx_queue_stop;
61 struct vport_start_ramrod_data vport_start;
62 struct vport_stop_ramrod_data vport_stop;
63 struct vport_update_ramrod_data vport_update;
64 struct vport_filter_update_ramrod_data vport_filter_update;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020065};
66
67#define EQ_MAX_CREDIT 0xffffffff
68
69enum spq_priority {
70 QED_SPQ_PRIORITY_NORMAL,
71 QED_SPQ_PRIORITY_HIGH,
72};
73
74union qed_spq_req_comp {
75 struct qed_spq_comp_cb cb;
76 u64 *done_addr;
77};
78
79struct qed_spq_comp_done {
80 u64 done;
81 u8 fw_return_code;
82};
83
84struct qed_spq_entry {
85 struct list_head list;
86
87 u8 flags;
88
89 /* HSI slow path element */
90 struct slow_path_element elem;
91
92 union ramrod_data ramrod;
93
94 enum spq_priority priority;
95
96 /* pending queue for this entry */
97 struct list_head *queue;
98
99 enum spq_mode comp_mode;
100 struct qed_spq_comp_cb comp_cb;
101 struct qed_spq_comp_done comp_done; /* SPQ_MODE_EBLOCK */
102};
103
104struct qed_eq {
105 struct qed_chain chain;
106 u8 eq_sb_index; /* index within the SB */
107 __le16 *p_fw_cons; /* ptr to index value */
108};
109
110struct qed_consq {
111 struct qed_chain chain;
112};
113
114struct qed_spq {
115 spinlock_t lock; /* SPQ lock */
116
117 struct list_head unlimited_pending;
118 struct list_head pending;
119 struct list_head completion_pending;
120 struct list_head free_pool;
121
122 struct qed_chain chain;
123
124 /* allocated dma-able memory for spq entries (+ramrod data) */
125 dma_addr_t p_phys;
126 struct qed_spq_entry *p_virt;
127
Tomer Tayar76a9a362015-12-07 06:25:57 -0500128#define SPQ_RING_SIZE \
129 (CORE_SPQE_PAGE_SIZE_BYTES / sizeof(struct slow_path_element))
130
131 /* Bitmap for handling out-of-order completions */
132 DECLARE_BITMAP(p_comp_bitmap, SPQ_RING_SIZE);
133 u8 comp_bitmap_idx;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200134
135 /* Statistics */
136 u32 unlimited_pending_count;
137 u32 normal_count;
138 u32 high_count;
139 u32 comp_sent_count;
140 u32 comp_count;
141
142 u32 cid;
143};
144
145/**
146 * @brief qed_spq_post - Posts a Slow hwfn request to FW, or lacking that
147 * Pends it to the future list.
148 *
149 * @param p_hwfn
150 * @param p_req
151 *
152 * @return int
153 */
154int qed_spq_post(struct qed_hwfn *p_hwfn,
155 struct qed_spq_entry *p_ent,
156 u8 *fw_return_code);
157
158/**
159 * @brief qed_spq_allocate - Alloocates & initializes the SPQ and EQ.
160 *
161 * @param p_hwfn
162 *
163 * @return int
164 */
165int qed_spq_alloc(struct qed_hwfn *p_hwfn);
166
167/**
168 * @brief qed_spq_setup - Reset the SPQ to its start state.
169 *
170 * @param p_hwfn
171 */
172void qed_spq_setup(struct qed_hwfn *p_hwfn);
173
174/**
175 * @brief qed_spq_deallocate - Deallocates the given SPQ struct.
176 *
177 * @param p_hwfn
178 */
179void qed_spq_free(struct qed_hwfn *p_hwfn);
180
181/**
182 * @brief qed_spq_get_entry - Obtain an entrry from the spq
183 * free pool list.
184 *
185 *
186 *
187 * @param p_hwfn
188 * @param pp_ent
189 *
190 * @return int
191 */
192int
193qed_spq_get_entry(struct qed_hwfn *p_hwfn,
194 struct qed_spq_entry **pp_ent);
195
196/**
197 * @brief qed_spq_return_entry - Return an entry to spq free
198 * pool list
199 *
200 * @param p_hwfn
201 * @param p_ent
202 */
203void qed_spq_return_entry(struct qed_hwfn *p_hwfn,
204 struct qed_spq_entry *p_ent);
205/**
206 * @brief qed_eq_allocate - Allocates & initializes an EQ struct
207 *
208 * @param p_hwfn
209 * @param num_elem number of elements in the eq
210 *
211 * @return struct qed_eq* - a newly allocated structure; NULL upon error.
212 */
213struct qed_eq *qed_eq_alloc(struct qed_hwfn *p_hwfn,
214 u16 num_elem);
215
216/**
217 * @brief qed_eq_setup - Reset the SPQ to its start state.
218 *
219 * @param p_hwfn
220 * @param p_eq
221 */
222void qed_eq_setup(struct qed_hwfn *p_hwfn,
223 struct qed_eq *p_eq);
224
225/**
226 * @brief qed_eq_deallocate - deallocates the given EQ struct.
227 *
228 * @param p_hwfn
229 * @param p_eq
230 */
231void qed_eq_free(struct qed_hwfn *p_hwfn,
232 struct qed_eq *p_eq);
233
234/**
235 * @brief qed_eq_prod_update - update the FW with default EQ producer
236 *
237 * @param p_hwfn
238 * @param prod
239 */
240void qed_eq_prod_update(struct qed_hwfn *p_hwfn,
241 u16 prod);
242
243/**
244 * @brief qed_eq_completion - Completes currently pending EQ elements
245 *
246 * @param p_hwfn
247 * @param cookie
248 *
249 * @return int
250 */
251int qed_eq_completion(struct qed_hwfn *p_hwfn,
252 void *cookie);
253
254/**
255 * @brief qed_spq_completion - Completes a single event
256 *
257 * @param p_hwfn
258 * @param echo - echo value from cookie (used for determining completion)
259 * @param p_data - data from cookie (used in callback function if applicable)
260 *
261 * @return int
262 */
263int qed_spq_completion(struct qed_hwfn *p_hwfn,
264 __le16 echo,
265 u8 fw_return_code,
266 union event_ring_data *p_data);
267
268/**
269 * @brief qed_spq_get_cid - Given p_hwfn, return cid for the hwfn's SPQ
270 *
271 * @param p_hwfn
272 *
273 * @return u32 - SPQ CID
274 */
275u32 qed_spq_get_cid(struct qed_hwfn *p_hwfn);
276
277/**
278 * @brief qed_consq_alloc - Allocates & initializes an ConsQ
279 * struct
280 *
281 * @param p_hwfn
282 *
283 * @return struct qed_eq* - a newly allocated structure; NULL upon error.
284 */
285struct qed_consq *qed_consq_alloc(struct qed_hwfn *p_hwfn);
286
287/**
288 * @brief qed_consq_setup - Reset the ConsQ to its start
289 * state.
290 *
291 * @param p_hwfn
292 * @param p_eq
293 */
294void qed_consq_setup(struct qed_hwfn *p_hwfn,
295 struct qed_consq *p_consq);
296
297/**
298 * @brief qed_consq_free - deallocates the given ConsQ struct.
299 *
300 * @param p_hwfn
301 * @param p_eq
302 */
303void qed_consq_free(struct qed_hwfn *p_hwfn,
304 struct qed_consq *p_consq);
305
306/**
307 * @file
308 *
309 * @brief Slow-hwfn low-level commands (Ramrods) function definitions.
310 */
311
312#define QED_SP_EQ_COMPLETION 0x01
313#define QED_SP_CQE_COMPLETION 0x02
314
Yuval Mintz06f56b82016-02-21 11:40:09 +0200315struct qed_sp_init_data {
316 u32 cid;
317 u16 opaque_fid;
318
319 /* Information regarding operation upon sending & completion */
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200320 enum spq_mode comp_mode;
321 struct qed_spq_comp_cb *p_comp_data;
322};
323
324int qed_sp_init_request(struct qed_hwfn *p_hwfn,
325 struct qed_spq_entry **pp_ent,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200326 u8 cmd,
327 u8 protocol,
Yuval Mintz06f56b82016-02-21 11:40:09 +0200328 struct qed_sp_init_data *p_data);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200329
330/**
331 * @brief qed_sp_pf_start - PF Function Start Ramrod
332 *
333 * This ramrod is sent to initialize a physical function (PF). It will
334 * configure the function related parameters and write its completion to the
335 * event ring specified in the parameters.
336 *
337 * Ramrods complete on the common event ring for the PF. This ring is
338 * allocated by the driver on host memory and its parameters are written
339 * to the internal RAM of the UStorm by the Function Start Ramrod.
340 *
341 * @param p_hwfn
Manish Chopra464f6642016-04-14 01:38:29 -0400342 * @param p_tunn
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200343 * @param mode
344 *
345 * @return int
346 */
347
348int qed_sp_pf_start(struct qed_hwfn *p_hwfn,
Manish Chopra464f6642016-04-14 01:38:29 -0400349 struct qed_tunn_start_params *p_tunn,
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500350 enum qed_mf_mode mode);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200351
352/**
353 * @brief qed_sp_pf_stop - PF Function Stop Ramrod
354 *
355 * This ramrod is sent to close a Physical Function (PF). It is the last ramrod
356 * sent and the last completion written to the PFs Event Ring. This ramrod also
357 * deletes the context for the Slowhwfn connection on this PF.
358 *
359 * @note Not required for first packet.
360 *
361 * @param p_hwfn
362 *
363 * @return int
364 */
365
366int qed_sp_pf_stop(struct qed_hwfn *p_hwfn);
367
Manish Chopra464f6642016-04-14 01:38:29 -0400368int qed_sp_pf_update_tunn_cfg(struct qed_hwfn *p_hwfn,
369 struct qed_tunn_update_params *p_tunn,
370 enum spq_mode comp_mode,
371 struct qed_spq_comp_cb *p_comp_data);
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -0400372/**
373 * @brief qed_sp_heartbeat_ramrod - Send empty Ramrod
374 *
375 * @param p_hwfn
376 *
377 * @return int
378 */
379
380int qed_sp_heartbeat_ramrod(struct qed_hwfn *p_hwfn);
381
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200382#endif