773177232eaf2355d34d40ff904cb8a90c341afd
[deb_dpdk.git] / drivers / bus / fslmc / qbman / include / fsl_qbman_portal.h
1 /*-
2  *   BSD LICENSE
3  *
4  * Copyright (C) 2014 Freescale Semiconductor, Inc.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *     * Redistributions of source code must retain the above copyright
9  *       notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above copyright
11  *       notice, this list of conditions and the following disclaimer in the
12  *       documentation and/or other materials provided with the distribution.
13  *     * Neither the name of Freescale Semiconductor nor the
14  *       names of its contributors may be used to endorse or promote products
15  *       derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 #ifndef _FSL_QBMAN_PORTAL_H
29 #define _FSL_QBMAN_PORTAL_H
30
31 #include <fsl_qbman_base.h>
32
33 /**
34  * DOC - QBMan portal APIs to implement the following functions:
35  * - Initialize and destroy Software portal object.
36  * - Read and write Software portal interrupt registers.
37  * - Enqueue, including setting the enqueue descriptor, and issuing enqueue
38  *   command etc.
39  * - Dequeue, including setting the dequeue descriptor, issuing dequeue command,
40  *   parsing the dequeue response in DQRR and memeory, parsing the state change
41  *   notifications etc.
42  * - Release, including setting the release descriptor, and issuing the buffer
43  *   release command.
44  * - Acquire, acquire the buffer from the given buffer pool.
45  * - FQ management.
46  * - Channel management, enable/disable CDAN with or without context.
47  */
48
49 /**
50  * qbman_swp_init() - Create a functional object representing the given
51  * QBMan portal descriptor.
52  * @d: the given qbman swp descriptor
53  *
54  * Return qbman_swp portal object for success, NULL if the object cannot
55  * be created.
56  */
57 struct qbman_swp *qbman_swp_init(const struct qbman_swp_desc *d);
58
59 /**
60  * qbman_swp_finish() - Create and destroy a functional object representing
61  * the given QBMan portal descriptor.
62  * @p: the qbman_swp object to be destroyed.
63  *
64  */
65 void qbman_swp_finish(struct qbman_swp *p);
66
67 /**
68  * qbman_swp_get_desc() - Get the descriptor of the given portal object.
69  * @p: the given portal object.
70  *
71  * Return the descriptor for this portal.
72  */
73 const struct qbman_swp_desc *qbman_swp_get_desc(struct qbman_swp *p);
74
75         /**************/
76         /* Interrupts */
77         /**************/
78
79 /* EQCR ring interrupt */
80 #define QBMAN_SWP_INTERRUPT_EQRI ((uint32_t)0x00000001)
81 /* Enqueue command dispatched interrupt */
82 #define QBMAN_SWP_INTERRUPT_EQDI ((uint32_t)0x00000002)
83 /* DQRR non-empty interrupt */
84 #define QBMAN_SWP_INTERRUPT_DQRI ((uint32_t)0x00000004)
85 /* RCR ring interrupt */
86 #define QBMAN_SWP_INTERRUPT_RCRI ((uint32_t)0x00000008)
87 /* Release command dispatched interrupt */
88 #define QBMAN_SWP_INTERRUPT_RCDI ((uint32_t)0x00000010)
89 /* Volatile dequeue command interrupt */
90 #define QBMAN_SWP_INTERRUPT_VDCI ((uint32_t)0x00000020)
91
92 /**
93  * qbman_swp_interrupt_get_vanish() - Get the data in software portal
94  * interrupt status disable register.
95  * @p: the given software portal object.
96  *
97  * Return the settings in SWP_ISDR register.
98  */
99 uint32_t qbman_swp_interrupt_get_vanish(struct qbman_swp *p);
100
101 /**
102  * qbman_swp_interrupt_set_vanish() - Set the data in software portal
103  * interrupt status disable register.
104  * @p: the given software portal object.
105  * @mask: The value to set in SWP_IDSR register.
106  */
107 void qbman_swp_interrupt_set_vanish(struct qbman_swp *p, uint32_t mask);
108
109 /**
110  * qbman_swp_interrupt_read_status() - Get the data in software portal
111  * interrupt status register.
112  * @p: the given software portal object.
113  *
114  * Return the settings in SWP_ISR register.
115  */
116 uint32_t qbman_swp_interrupt_read_status(struct qbman_swp *p);
117
118 /**
119  * qbman_swp_interrupt_clear_status() - Set the data in software portal
120  * interrupt status register.
121  * @p: the given software portal object.
122  * @mask: The value to set in SWP_ISR register.
123  */
124 void qbman_swp_interrupt_clear_status(struct qbman_swp *p, uint32_t mask);
125
126 /**
127  * qbman_swp_interrupt_get_trigger() - Get the data in software portal
128  * interrupt enable register.
129  * @p: the given software portal object.
130  *
131  * Return the settings in SWP_IER register.
132  */
133 uint32_t qbman_swp_interrupt_get_trigger(struct qbman_swp *p);
134
135 /**
136  * qbman_swp_interrupt_set_trigger() - Set the data in software portal
137  * interrupt enable register.
138  * @p: the given software portal object.
139  * @mask: The value to set in SWP_IER register.
140  */
141 void qbman_swp_interrupt_set_trigger(struct qbman_swp *p, uint32_t mask);
142
143 /**
144  * qbman_swp_interrupt_get_inhibit() - Get the data in software portal
145  * interrupt inhibit register.
146  * @p: the given software portal object.
147  *
148  * Return the settings in SWP_IIR register.
149  */
150 int qbman_swp_interrupt_get_inhibit(struct qbman_swp *p);
151
152 /**
153  * qbman_swp_interrupt_set_inhibit() - Set the data in software portal
154  * interrupt inhibit register.
155  * @p: the given software portal object.
156  * @mask: The value to set in SWP_IIR register.
157  */
158 void qbman_swp_interrupt_set_inhibit(struct qbman_swp *p, int inhibit);
159
160         /************/
161         /* Dequeues */
162         /************/
163
164 /**
165  * struct qbman_result - structure for qbman dequeue response and/or
166  * notification.
167  * @dont_manipulate_directly: the 16 32bit data to represent the whole
168  * possible qbman dequeue result.
169  */
170 struct qbman_result {
171         uint32_t dont_manipulate_directly[16];
172 };
173
174 /* TODO:
175  *A DQRI interrupt can be generated when there are dequeue results on the
176  * portal's DQRR (this mechanism does not deal with "pull" dequeues to
177  * user-supplied 'storage' addresses). There are two parameters to this
178  * interrupt source, one is a threshold and the other is a timeout. The
179  * interrupt will fire if either the fill-level of the ring exceeds 'thresh', or
180  * if the ring has been non-empty for been longer than 'timeout' nanoseconds.
181  * For timeout, an approximation to the desired nanosecond-granularity value is
182  * made, so there are get and set APIs to allow the user to see what actual
183  * timeout is set (compared to the timeout that was requested).
184  */
185 int qbman_swp_dequeue_thresh(struct qbman_swp *s, unsigned int thresh);
186 int qbman_swp_dequeue_set_timeout(struct qbman_swp *s, unsigned int timeout);
187 int qbman_swp_dequeue_get_timeout(struct qbman_swp *s, unsigned int *timeout);
188
189 /* ------------------- */
190 /* Push-mode dequeuing */
191 /* ------------------- */
192
193 /* The user of a portal can enable and disable push-mode dequeuing of up to 16
194  * channels independently. It does not specify this toggling by channel IDs, but
195  * rather by specifying the index (from 0 to 15) that has been mapped to the
196  * desired channel.
197  */
198
199 /**
200  * qbman_swp_push_get() - Get the push dequeue setup.
201  * @s: the software portal object.
202  * @channel_idx: the channel index to query.
203  * @enabled: returned boolean to show whether the push dequeue is enabled for
204  * the given channel.
205  */
206 void qbman_swp_push_get(struct qbman_swp *s, uint8_t channel_idx, int *enabled);
207
208 /**
209  * qbman_swp_push_set() - Enable or disable push dequeue.
210  * @s: the software portal object.
211  * @channel_idx: the channel index..
212  * @enable: enable or disable push dequeue.
213  *
214  * The user of a portal can enable and disable push-mode dequeuing of up to 16
215  * channels independently. It does not specify this toggling by channel IDs, but
216  * rather by specifying the index (from 0 to 15) that has been mapped to the
217  * desired channel.
218  */
219 void qbman_swp_push_set(struct qbman_swp *s, uint8_t channel_idx, int enable);
220
221 /* ------------------- */
222 /* Pull-mode dequeuing */
223 /* ------------------- */
224
225 /**
226  * struct qbman_pull_desc - the structure for pull dequeue descriptor
227  * @dont_manipulate_directly: the 6 32bit data to represent the whole
228  * possible settings for pull dequeue descriptor.
229  */
230 struct qbman_pull_desc {
231         uint32_t dont_manipulate_directly[6];
232 };
233
234 enum qbman_pull_type_e {
235         /* dequeue with priority precedence, respect intra-class scheduling */
236         qbman_pull_type_prio = 1,
237         /* dequeue with active FQ precedence, respect ICS */
238         qbman_pull_type_active,
239         /* dequeue with active FQ precedence, no ICS */
240         qbman_pull_type_active_noics
241 };
242
243 /**
244  * qbman_pull_desc_clear() - Clear the contents of a descriptor to
245  * default/starting state.
246  * @d: the pull dequeue descriptor to be cleared.
247  */
248 void qbman_pull_desc_clear(struct qbman_pull_desc *d);
249
250 /**
251  * qbman_pull_desc_set_storage()- Set the pull dequeue storage
252  * @d: the pull dequeue descriptor to be set.
253  * @storage: the pointer of the memory to store the dequeue result.
254  * @storage_phys: the physical address of the storage memory.
255  * @stash: to indicate whether write allocate is enabled.
256  *
257  * If not called, or if called with 'storage' as NULL, the result pull dequeues
258  * will produce results to DQRR. If 'storage' is non-NULL, then results are
259  * produced to the given memory location (using the physical/DMA address which
260  * the caller provides in 'storage_phys'), and 'stash' controls whether or not
261  * those writes to main-memory express a cache-warming attribute.
262  */
263 void qbman_pull_desc_set_storage(struct qbman_pull_desc *d,
264                                  struct qbman_result *storage,
265                                  dma_addr_t storage_phys,
266                                  int stash);
267 /**
268  * qbman_pull_desc_set_numframes() - Set the number of frames to be dequeued.
269  * @d: the pull dequeue descriptor to be set.
270  * @numframes: number of frames to be set, must be between 1 and 16, inclusive.
271  */
272 void qbman_pull_desc_set_numframes(struct qbman_pull_desc *d,
273                                    uint8_t numframes);
274 /**
275  * qbman_pull_desc_set_token() - Set dequeue token for pull command
276  * @d: the dequeue descriptor
277  * @token: the token to be set
278  *
279  * token is the value that shows up in the dequeue response that can be used to
280  * detect when the results have been published. The easiest technique is to zero
281  * result "storage" before issuing a dequeue, and use any non-zero 'token' value
282  */
283 void qbman_pull_desc_set_token(struct qbman_pull_desc *d, uint8_t token);
284
285 /* Exactly one of the following descriptor "actions" should be set. (Calling any
286  * one of these will replace the effect of any prior call to one of these.)
287  * - pull dequeue from the given frame queue (FQ)
288  * - pull dequeue from any FQ in the given work queue (WQ)
289  * - pull dequeue from any FQ in any WQ in the given channel
290  */
291 /**
292  * qbman_pull_desc_set_fq() - Set fqid from which the dequeue command dequeues.
293  * @fqid: the frame queue index of the given FQ.
294  */
295 void qbman_pull_desc_set_fq(struct qbman_pull_desc *d, uint32_t fqid);
296
297 /**
298  * qbman_pull_desc_set_wq() - Set wqid from which the dequeue command dequeues.
299  * @wqid: composed of channel id and wqid within the channel.
300  * @dct: the dequeue command type.
301  */
302 void qbman_pull_desc_set_wq(struct qbman_pull_desc *d, uint32_t wqid,
303                             enum qbman_pull_type_e dct);
304
305 /* qbman_pull_desc_set_channel() - Set channelid from which the dequeue command
306  * dequeues.
307  * @chid: the channel id to be dequeued.
308  * @dct: the dequeue command type.
309  */
310 void qbman_pull_desc_set_channel(struct qbman_pull_desc *d, uint32_t chid,
311                                  enum qbman_pull_type_e dct);
312
313 /**
314  * qbman_swp_pull() - Issue the pull dequeue command
315  * @s: the software portal object.
316  * @d: the software portal descriptor which has been configured with
317  * the set of qbman_pull_desc_set_*() calls.
318  *
319  * Return 0 for success, and -EBUSY if the software portal is not ready
320  * to do pull dequeue.
321  */
322 int qbman_swp_pull(struct qbman_swp *s, struct qbman_pull_desc *d);
323
324 /* -------------------------------- */
325 /* Polling DQRR for dequeue results */
326 /* -------------------------------- */
327
328 /**
329  * qbman_swp_dqrr_next() - Get an valid DQRR entry.
330  * @s: the software portal object.
331  *
332  * Return NULL if there are no unconsumed DQRR entries. Return a DQRR entry
333  * only once, so repeated calls can return a sequence of DQRR entries, without
334  * requiring they be consumed immediately or in any particular order.
335  */
336 const struct qbman_result *qbman_swp_dqrr_next(struct qbman_swp *p);
337
338 /**
339  * qbman_swp_dqrr_consume() -  Consume DQRR entries previously returned from
340  * qbman_swp_dqrr_next().
341  * @s: the software portal object.
342  * @dq: the DQRR entry to be consumed.
343  */
344 void qbman_swp_dqrr_consume(struct qbman_swp *s, const struct qbman_result *dq);
345
346 /**
347  * qbman_get_dqrr_idx() - Get dqrr index from the given dqrr
348  * @dqrr: the given dqrr object.
349  *
350  * Return dqrr index.
351  */
352 uint8_t qbman_get_dqrr_idx(struct qbman_result *dqrr);
353
354 /**
355  * qbman_get_dqrr_from_idx() - Use index to get the dqrr entry from the
356  * given portal
357  * @s: the given portal.
358  * @idx: the dqrr index.
359  *
360  * Return dqrr entry object.
361  */
362 struct qbman_result *qbman_get_dqrr_from_idx(struct qbman_swp *s, uint8_t idx);
363
364 /* ------------------------------------------------- */
365 /* Polling user-provided storage for dequeue results */
366 /* ------------------------------------------------- */
367
368 /**
369  * qbman_result_has_new_result() - Check and get the dequeue response from the
370  * dq storage memory set in pull dequeue command
371  * @s: the software portal object.
372  * @dq: the dequeue result read from the memory.
373  *
374  * Only used for user-provided storage of dequeue results, not DQRR. For
375  * efficiency purposes, the driver will perform any required endianness
376  * conversion to ensure that the user's dequeue result storage is in host-endian
377  * format (whether or not that is the same as the little-endian format that
378  * hardware DMA'd to the user's storage). As such, once the user has called
379  * qbman_result_has_new_result() and been returned a valid dequeue result,
380  * they should not call it again on the same memory location (except of course
381  * if another dequeue command has been executed to produce a new result to that
382  * location).
383  *
384  * Return 1 for getting a valid dequeue result, or 0 for not getting a valid
385  * dequeue result.
386  */
387 int qbman_result_has_new_result(struct qbman_swp *s,
388                                 const struct qbman_result *dq);
389
390 /* -------------------------------------------------------- */
391 /* Parsing dequeue entries (DQRR and user-provided storage) */
392 /* -------------------------------------------------------- */
393
394 /**
395  * qbman_result_is_DQ() - check the dequeue result is a dequeue response or not
396  * @dq: the dequeue result to be checked.
397  *
398  * DQRR entries may contain non-dequeue results, ie. notifications
399  */
400 int qbman_result_is_DQ(const struct qbman_result *dq);
401
402 /**
403  * qbman_result_is_SCN() - Check the dequeue result is notification or not
404  * @dq: the dequeue result to be checked.
405  *
406  * All the non-dequeue results (FQDAN/CDAN/CSCN/...) are "state change
407  * notifications" of one type or another. Some APIs apply to all of them, of the
408  * form qbman_result_SCN_***().
409  */
410 static inline int qbman_result_is_SCN(const struct qbman_result *dq)
411 {
412         return !qbman_result_is_DQ(dq);
413 }
414
415 /* Recognise different notification types, only required if the user allows for
416  * these to occur, and cares about them when they do.
417  */
418
419 /**
420  * qbman_result_is_FQDAN() - Check for FQ Data Availability
421  * @dq: the qbman_result object.
422  *
423  * Return 1 if this is FQDAN.
424  */
425 int qbman_result_is_FQDAN(const struct qbman_result *dq);
426
427 /**
428  * qbman_result_is_CDAN() - Check for Channel Data Availability
429  * @dq: the qbman_result object to check.
430  *
431  * Return 1 if this is CDAN.
432  */
433 int qbman_result_is_CDAN(const struct qbman_result *dq);
434
435 /**
436  * qbman_result_is_CSCN() - Check for Congestion State Change
437  * @dq: the qbman_result object to check.
438  *
439  * Return 1 if this is CSCN.
440  */
441 int qbman_result_is_CSCN(const struct qbman_result *dq);
442
443 /**
444  * qbman_result_is_BPSCN() - Check for Buffer Pool State Change.
445  * @dq: the qbman_result object to check.
446  *
447  * Return 1 if this is BPSCN.
448  */
449 int qbman_result_is_BPSCN(const struct qbman_result *dq);
450
451 /**
452  * qbman_result_is_CGCU() - Check for Congestion Group Count Update.
453  * @dq: the qbman_result object to check.
454  *
455  * Return 1 if this is CGCU.
456  */
457 int qbman_result_is_CGCU(const struct qbman_result *dq);
458
459 /* Frame queue state change notifications; (FQDAN in theory counts too as it
460  * leaves a FQ parked, but it is primarily a data availability notification)
461  */
462
463 /**
464  * qbman_result_is_FQRN() - Check for FQ Retirement Notification.
465  * @dq: the qbman_result object to check.
466  *
467  * Return 1 if this is FQRN.
468  */
469 int qbman_result_is_FQRN(const struct qbman_result *dq);
470
471 /**
472  * qbman_result_is_FQRNI() - Check for FQ Retirement Immediate
473  * @dq: the qbman_result object to check.
474  *
475  * Return 1 if this is FQRNI.
476  */
477 int qbman_result_is_FQRNI(const struct qbman_result *dq);
478
479 /**
480  * qbman_result_is_FQPN() - Check for FQ Park Notification
481  * @dq: the qbman_result object to check.
482  *
483  * Return 1 if this is FQPN.
484  */
485 int qbman_result_is_FQPN(const struct qbman_result *dq);
486
487 /* Parsing frame dequeue results (qbman_result_is_DQ() must be TRUE)
488  */
489 /* FQ empty */
490 #define QBMAN_DQ_STAT_FQEMPTY       0x80
491 /* FQ held active */
492 #define QBMAN_DQ_STAT_HELDACTIVE    0x40
493 /* FQ force eligible */
494 #define QBMAN_DQ_STAT_FORCEELIGIBLE 0x20
495 /* Valid frame */
496 #define QBMAN_DQ_STAT_VALIDFRAME    0x10
497 /* FQ ODP enable */
498 #define QBMAN_DQ_STAT_ODPVALID      0x04
499 /* Volatile dequeue */
500 #define QBMAN_DQ_STAT_VOLATILE      0x02
501 /* volatile dequeue command is expired */
502 #define QBMAN_DQ_STAT_EXPIRED       0x01
503
504 /**
505  * qbman_result_DQ_flags() - Get the STAT field of dequeue response
506  * @dq: the dequeue result.
507  *
508  * Return the state field.
509  */
510 uint32_t qbman_result_DQ_flags(const struct qbman_result *dq);
511
512 /**
513  * qbman_result_DQ_is_pull() - Check whether the dq response is from a pull
514  * command.
515  * @dq: the dequeue result.
516  *
517  * Return 1 for volatile(pull) dequeue, 0 for static dequeue.
518  */
519 static inline int qbman_result_DQ_is_pull(const struct qbman_result *dq)
520 {
521         return (int)(qbman_result_DQ_flags(dq) & QBMAN_DQ_STAT_VOLATILE);
522 }
523
524 /**
525  * qbman_result_DQ_is_pull_complete() - Check whether the pull command is
526  * completed.
527  * @dq: the dequeue result.
528  *
529  * Return boolean.
530  */
531 static inline int qbman_result_DQ_is_pull_complete(
532                                         const struct qbman_result *dq)
533 {
534         return (int)(qbman_result_DQ_flags(dq) & QBMAN_DQ_STAT_EXPIRED);
535 }
536
537 /**
538  * qbman_result_DQ_seqnum()  - Get the seqnum field in dequeue response
539  * seqnum is valid only if VALIDFRAME flag is TRUE
540  * @dq: the dequeue result.
541  *
542  * Return seqnum.
543  */
544 uint16_t qbman_result_DQ_seqnum(const struct qbman_result *dq);
545
546 /**
547  * qbman_result_DQ_odpid() - Get the seqnum field in dequeue response
548  * odpid is valid only if ODPVAILD flag is TRUE.
549  * @dq: the dequeue result.
550  *
551  * Return odpid.
552  */
553 uint16_t qbman_result_DQ_odpid(const struct qbman_result *dq);
554
555 /**
556  * qbman_result_DQ_fqid() - Get the fqid in dequeue response
557  * @dq: the dequeue result.
558  *
559  * Return fqid.
560  */
561 uint32_t qbman_result_DQ_fqid(const struct qbman_result *dq);
562
563 /**
564  * qbman_result_DQ_byte_count() - Get the byte count in dequeue response
565  * @dq: the dequeue result.
566  *
567  * Return the byte count remaining in the FQ.
568  */
569 uint32_t qbman_result_DQ_byte_count(const struct qbman_result *dq);
570
571 /**
572  * qbman_result_DQ_frame_count - Get the frame count in dequeue response
573  * @dq: the dequeue result.
574  *
575  * Return the frame count remaining in the FQ.
576  */
577 uint32_t qbman_result_DQ_frame_count(const struct qbman_result *dq);
578
579 /**
580  * qbman_result_DQ_fqd_ctx() - Get the frame queue context in dequeue response
581  * @dq: the dequeue result.
582  *
583  * Return the frame queue context.
584  */
585 uint64_t qbman_result_DQ_fqd_ctx(const struct qbman_result *dq);
586
587 /**
588  * qbman_result_DQ_fd() - Get the frame descriptor in dequeue response
589  * @dq: the dequeue result.
590  *
591  * Return the frame descriptor.
592  */
593 const struct qbman_fd *qbman_result_DQ_fd(const struct qbman_result *dq);
594
595 /* State-change notifications (FQDAN/CDAN/CSCN/...). */
596
597 /**
598  * qbman_result_SCN_state() - Get the state field in State-change notification
599  * @scn: the state change notification.
600  *
601  * Return the state in the notifiation.
602  */
603 uint8_t qbman_result_SCN_state(const struct qbman_result *scn);
604
605 /**
606  * qbman_result_SCN_rid() - Get the resource id from the notification
607  * @scn: the state change notification.
608  *
609  * Return the resource id.
610  */
611 uint32_t qbman_result_SCN_rid(const struct qbman_result *scn);
612
613 /**
614  * qbman_result_SCN_ctx() - get the context from the notification
615  * @scn: the state change notification.
616  *
617  * Return the context.
618  */
619 uint64_t qbman_result_SCN_ctx(const struct qbman_result *scn);
620
621 /**
622  * qbman_result_SCN_state_in_mem() - Get the state in notification written
623  * in memory
624  * @scn: the state change notification.
625  *
626  * Return the state.
627  */
628 uint8_t qbman_result_SCN_state_in_mem(const struct qbman_result *scn);
629
630 /**
631  * qbman_result_SCN_rid_in_mem() - Get the resource id in notification written
632  * in memory.
633  * @scn: the state change notification.
634  *
635  * Return the resource id.
636  */
637 uint32_t qbman_result_SCN_rid_in_mem(const struct qbman_result *scn);
638
639 /* Type-specific "resource IDs". Mainly for illustration purposes, though it
640  * also gives the appropriate type widths.
641  */
642 /* Get the FQID from the FQDAN */
643 #define qbman_result_FQDAN_fqid(dq) qbman_result_SCN_rid(dq)
644 /* Get the FQID from the FQRN */
645 #define qbman_result_FQRN_fqid(dq) qbman_result_SCN_rid(dq)
646 /* Get the FQID from the FQRNI */
647 #define qbman_result_FQRNI_fqid(dq) qbman_result_SCN_rid(dq)
648 /* Get the FQID from the FQPN */
649 #define qbman_result_FQPN_fqid(dq) qbman_result_SCN_rid(dq)
650 /* Get the channel ID from the CDAN */
651 #define qbman_result_CDAN_cid(dq) ((uint16_t)qbman_result_SCN_rid(dq))
652 /* Get the CGID from the CSCN */
653 #define qbman_result_CSCN_cgid(dq) ((uint16_t)qbman_result_SCN_rid(dq))
654
655 /**
656  * qbman_result_bpscn_bpid() - Get the bpid from BPSCN
657  * @scn: the state change notification.
658  *
659  * Return the buffer pool id.
660  */
661 uint16_t qbman_result_bpscn_bpid(const struct qbman_result *scn);
662
663 /**
664  * qbman_result_bpscn_has_free_bufs() - Check whether there are free
665  * buffers in the pool from BPSCN.
666  * @scn: the state change notification.
667  *
668  * Return the number of free buffers.
669  */
670 int qbman_result_bpscn_has_free_bufs(const struct qbman_result *scn);
671
672 /**
673  * qbman_result_bpscn_is_depleted() - Check BPSCN to see whether the
674  * buffer pool is depleted.
675  * @scn: the state change notification.
676  *
677  * Return the status of buffer pool depletion.
678  */
679 int qbman_result_bpscn_is_depleted(const struct qbman_result *scn);
680
681 /**
682  * qbman_result_bpscn_is_surplus() - Check BPSCN to see whether the buffer
683  * pool is surplus or not.
684  * @scn: the state change notification.
685  *
686  * Return the status of buffer pool surplus.
687  */
688 int qbman_result_bpscn_is_surplus(const struct qbman_result *scn);
689
690 /**
691  * qbman_result_bpscn_ctx() - Get the BPSCN CTX from BPSCN message
692  * @scn: the state change notification.
693  *
694  * Return the BPSCN context.
695  */
696 uint64_t qbman_result_bpscn_ctx(const struct qbman_result *scn);
697
698 /* Parsing CGCU */
699 /**
700  * qbman_result_cgcu_cgid() - Check CGCU resouce id, i.e. cgid
701  * @scn: the state change notification.
702  *
703  * Return the CGCU resource id.
704  */
705 uint16_t qbman_result_cgcu_cgid(const struct qbman_result *scn);
706
707 /**
708  * qbman_result_cgcu_icnt() - Get the I_CNT from CGCU
709  * @scn: the state change notification.
710  *
711  * Return instantaneous count in the CGCU notification.
712  */
713 uint64_t qbman_result_cgcu_icnt(const struct qbman_result *scn);
714
715         /************/
716         /* Enqueues */
717         /************/
718
719 /**
720  * struct qbman_eq_desc - structure of enqueue descriptor
721  * @dont_manipulate_directly: the 8 32bit data to represent the whole
722  * possible qbman enqueue setting in enqueue descriptor.
723  */
724 struct qbman_eq_desc {
725         uint32_t dont_manipulate_directly[8];
726 };
727
728 /**
729  * struct qbman_eq_response - structure of enqueue response
730  * @dont_manipulate_directly: the 16 32bit data to represent the whole
731  * enqueue response.
732  */
733 struct qbman_eq_response {
734         uint32_t dont_manipulate_directly[16];
735 };
736
737 /**
738  * qbman_eq_desc_clear() - Clear the contents of a descriptor to
739  * default/starting state.
740  * @d: the given enqueue descriptor.
741  */
742 void qbman_eq_desc_clear(struct qbman_eq_desc *d);
743
744 /* Exactly one of the following descriptor "actions" should be set. (Calling
745  * any one of these will replace the effect of any prior call to one of these.)
746  * - enqueue without order-restoration
747  * - enqueue with order-restoration
748  * - fill a hole in the order-restoration sequence, without any enqueue
749  * - advance NESN (Next Expected Sequence Number), without any enqueue
750  * 'respond_success' indicates whether an enqueue response should be DMA'd
751  * after success (otherwise a response is DMA'd only after failure).
752  * 'incomplete' indicates that other fragments of the same 'seqnum' are yet to
753  * be enqueued.
754  */
755
756 /**
757  * qbman_eq_desc_set_no_orp() - Set enqueue descriptor without orp
758  * @d: the enqueue descriptor.
759  * @response_success: 1 = enqueue with response always; 0 = enqueue with
760  * rejections returned on a FQ.
761  */
762 void qbman_eq_desc_set_no_orp(struct qbman_eq_desc *d, int respond_success);
763 /**
764  * qbman_eq_desc_set_orp() - Set order-resotration in the enqueue descriptor
765  * @d: the enqueue descriptor.
766  * @response_success: 1 = enqueue with response always; 0 = enqueue with
767  * rejections returned on a FQ.
768  * @opr_id: the order point record id.
769  * @seqnum: the order restoration sequence number.
770  * @incomplete: indiates whether this is the last fragments using the same
771  * sequeue number.
772  */
773 void qbman_eq_desc_set_orp(struct qbman_eq_desc *d, int respond_success,
774                            uint32_t opr_id, uint32_t seqnum, int incomplete);
775
776 /**
777  * qbman_eq_desc_set_orp_hole() - fill a hole in the order-restoration sequence
778  * without any enqueue
779  * @d: the enqueue descriptor.
780  * @opr_id: the order point record id.
781  * @seqnum: the order restoration sequence number.
782  */
783 void qbman_eq_desc_set_orp_hole(struct qbman_eq_desc *d, uint32_t opr_id,
784                                 uint32_t seqnum);
785
786 /**
787  * qbman_eq_desc_set_orp_nesn() -  advance NESN (Next Expected Sequence Number)
788  * without any enqueue
789  * @d: the enqueue descriptor.
790  * @opr_id: the order point record id.
791  * @seqnum: the order restoration sequence number.
792  */
793 void qbman_eq_desc_set_orp_nesn(struct qbman_eq_desc *d, uint32_t opr_id,
794                                 uint32_t seqnum);
795 /**
796  * qbman_eq_desc_set_response() - Set the enqueue response info.
797  * @d: the enqueue descriptor
798  * @storage_phys: the physical address of the enqueue response in memory.
799  * @stash: indicate that the write allocation enabled or not.
800  *
801  * In the case where an enqueue response is DMA'd, this determines where that
802  * response should go. (The physical/DMA address is given for hardware's
803  * benefit, but software should interpret it as a "struct qbman_eq_response"
804  * data structure.) 'stash' controls whether or not the write to main-memory
805  * expresses a cache-warming attribute.
806  */
807 void qbman_eq_desc_set_response(struct qbman_eq_desc *d,
808                                 dma_addr_t storage_phys,
809                                 int stash);
810
811 /**
812  * qbman_eq_desc_set_token() - Set token for the enqueue command
813  * @d: the enqueue descriptor
814  * @token: the token to be set.
815  *
816  * token is the value that shows up in an enqueue response that can be used to
817  * detect when the results have been published. The easiest technique is to zero
818  * result "storage" before issuing an enqueue, and use any non-zero 'token'
819  * value.
820  */
821 void qbman_eq_desc_set_token(struct qbman_eq_desc *d, uint8_t token);
822
823 /**
824  * Exactly one of the following descriptor "targets" should be set. (Calling any
825  * one of these will replace the effect of any prior call to one of these.)
826  * - enqueue to a frame queue
827  * - enqueue to a queuing destination
828  * Note, that none of these will have any affect if the "action" type has been
829  * set to "orp_hole" or "orp_nesn".
830  */
831 /**
832  * qbman_eq_desc_set_fq() - Set Frame Queue id for the enqueue command
833  * @d: the enqueue descriptor
834  * @fqid: the id of the frame queue to be enqueued.
835  */
836 void qbman_eq_desc_set_fq(struct qbman_eq_desc *d, uint32_t fqid);
837
838 /**
839  * qbman_eq_desc_set_qd() - Set Queuing Destination for the enqueue command.
840  * @d: the enqueue descriptor
841  * @qdid: the id of the queuing destination to be enqueued.
842  * @qd_bin: the queuing destination bin
843  * @qd_prio: the queuing destination priority.
844  */
845 void qbman_eq_desc_set_qd(struct qbman_eq_desc *d, uint32_t qdid,
846                           uint32_t qd_bin, uint32_t qd_prio);
847
848 /**
849  * qbman_eq_desc_set_eqdi() - enable/disable EQDI interrupt
850  * @d: the enqueue descriptor
851  * @enable: boolean to enable/disable EQDI
852  *
853  * Determines whether or not the portal's EQDI interrupt source should be
854  * asserted after the enqueue command is completed.
855  */
856 void qbman_eq_desc_set_eqdi(struct qbman_eq_desc *d, int enable);
857
858 /**
859  * qbman_eq_desc_set_dca() - Set DCA mode in the enqueue command.
860  * @d: the enqueue descriptor.
861  * @enable: enabled/disable DCA mode.
862  * @dqrr_idx: DCAP_CI, the DCAP consumer index.
863  * @park: determine the whether park the FQ or not
864  *
865  * Determines whether or not a portal DQRR entry should be consumed once the
866  * enqueue command is completed. (And if so, and the DQRR entry corresponds to a
867  * held-active (order-preserving) FQ, whether the FQ should be parked instead of
868  * being rescheduled.)
869  */
870 void qbman_eq_desc_set_dca(struct qbman_eq_desc *d, int enable,
871                            uint32_t dqrr_idx, int park);
872
873 /**
874  * qbman_swp_enqueue() - Issue an enqueue command.
875  * @s: the software portal used for enqueue.
876  * @d: the enqueue descriptor.
877  * @fd: the frame descriptor to be enqueued.
878  *
879  * Please note that 'fd' should only be NULL if the "action" of the
880  * descriptor is "orp_hole" or "orp_nesn".
881  *
882  * Return 0 for a successful enqueue, -EBUSY if the EQCR is not ready.
883  */
884 int qbman_swp_enqueue(struct qbman_swp *s, const struct qbman_eq_desc *d,
885                       const struct qbman_fd *fd);
886
887 /* TODO:
888  * qbman_swp_enqueue_thresh() - Set threshold for EQRI interrupt.
889  * @s: the software portal.
890  * @thresh: the threshold to trigger the EQRI interrupt.
891  *
892  * An EQRI interrupt can be generated when the fill-level of EQCR falls below
893  * the 'thresh' value set here. Setting thresh==0 (the default) disables.
894  */
895 int qbman_swp_enqueue_thresh(struct qbman_swp *s, unsigned int thresh);
896
897         /*******************/
898         /* Buffer releases */
899         /*******************/
900 /**
901  * struct qbman_release_desc - The structure for buffer release descriptor
902  * @dont_manipulate_directly: the 32bit data to represent the whole
903  * possible settings of qbman release descriptor.
904  */
905 struct qbman_release_desc {
906         uint32_t dont_manipulate_directly[1];
907 };
908
909 /**
910  * qbman_release_desc_clear() - Clear the contents of a descriptor to
911  * default/starting state.
912  * @d: the qbman release descriptor.
913  */
914 void qbman_release_desc_clear(struct qbman_release_desc *d);
915
916 /**
917  * qbman_release_desc_set_bpid() - Set the ID of the buffer pool to release to
918  * @d: the qbman release descriptor.
919  */
920 void qbman_release_desc_set_bpid(struct qbman_release_desc *d, uint32_t bpid);
921
922 /**
923  * qbman_release_desc_set_rcdi() - Determines whether or not the portal's RCDI
924  * interrupt source should be asserted after the release command is completed.
925  * @d: the qbman release descriptor.
926  */
927 void qbman_release_desc_set_rcdi(struct qbman_release_desc *d, int enable);
928
929 /**
930  * qbman_swp_release() - Issue a buffer release command.
931  * @s: the software portal object.
932  * @d: the release descriptor.
933  * @buffers: a pointer pointing to the buffer address to be released.
934  * @num_buffers: number of buffers to be released,  must be less than 8.
935  *
936  * Return 0 for success, -EBUSY if the release command ring is not ready.
937  */
938 int qbman_swp_release(struct qbman_swp *s, const struct qbman_release_desc *d,
939                       const uint64_t *buffers, unsigned int num_buffers);
940
941 /* TODO:
942  * qbman_swp_release_thresh() - Set threshold for RCRI interrupt
943  * @s: the software portal.
944  * @thresh: the threshold.
945  * An RCRI interrupt can be generated when the fill-level of RCR falls below
946  * the 'thresh' value set here. Setting thresh==0 (the default) disables.
947  */
948 int qbman_swp_release_thresh(struct qbman_swp *s, unsigned int thresh);
949
950         /*******************/
951         /* Buffer acquires */
952         /*******************/
953 /**
954  * qbman_swp_acquire() - Issue a buffer acquire command.
955  * @s: the software portal object.
956  * @bpid: the buffer pool index.
957  * @buffers: a pointer pointing to the acquired buffer address|es.
958  * @num_buffers: number of buffers to be acquired, must be less than 8.
959  *
960  * Return 0 for success, or negative error code if the acquire command
961  * fails.
962  */
963 int qbman_swp_acquire(struct qbman_swp *s, uint32_t bpid, uint64_t *buffers,
964                       unsigned int num_buffers);
965
966         /*****************/
967         /* FQ management */
968         /*****************/
969 /**
970  * qbman_swp_fq_schedule() - Move the fq to the scheduled state.
971  * @s: the software portal object.
972  * @fqid: the index of frame queue to be scheduled.
973  *
974  * There are a couple of different ways that a FQ can end up parked state,
975  * This schedules it.
976  *
977  * Return 0 for success, or negative error code for failure.
978  */
979 int qbman_swp_fq_schedule(struct qbman_swp *s, uint32_t fqid);
980
981 /**
982  * qbman_swp_fq_force() - Force the FQ to fully scheduled state.
983  * @s: the software portal object.
984  * @fqid: the index of frame queue to be forced.
985  *
986  * Force eligible will force a tentatively-scheduled FQ to be fully-scheduled
987  * and thus be available for selection by any channel-dequeuing behaviour (push
988  * or pull). If the FQ is subsequently "dequeued" from the channel and is still
989  * empty at the time this happens, the resulting dq_entry will have no FD.
990  * (qbman_result_DQ_fd() will return NULL.)
991  *
992  * Return 0 for success, or negative error code for failure.
993  */
994 int qbman_swp_fq_force(struct qbman_swp *s, uint32_t fqid);
995
996 /**
997  * These functions change the FQ flow-control stuff between XON/XOFF. (The
998  * default is XON.) This setting doesn't affect enqueues to the FQ, just
999  * dequeues. XOFF FQs will remain in the tenatively-scheduled state, even when
1000  * non-empty, meaning they won't be selected for scheduled dequeuing. If a FQ is
1001  * changed to XOFF after it had already become truly-scheduled to a channel, and
1002  * a pull dequeue of that channel occurs that selects that FQ for dequeuing,
1003  * then the resulting dq_entry will have no FD. (qbman_result_DQ_fd() will
1004  * return NULL.)
1005  */
1006 /**
1007  * qbman_swp_fq_xon() - XON the frame queue.
1008  * @s: the software portal object.
1009  * @fqid: the index of frame queue.
1010  *
1011  * Return 0 for success, or negative error code for failure.
1012  */
1013 int qbman_swp_fq_xon(struct qbman_swp *s, uint32_t fqid);
1014 /**
1015  * qbman_swp_fq_xoff() - XOFF the frame queue.
1016  * @s: the software portal object.
1017  * @fqid: the index of frame queue.
1018  *
1019  * Return 0 for success, or negative error code for failure.
1020  */
1021 int qbman_swp_fq_xoff(struct qbman_swp *s, uint32_t fqid);
1022
1023         /**********************/
1024         /* Channel management */
1025         /**********************/
1026
1027 /**
1028  * If the user has been allocated a channel object that is going to generate
1029  * CDANs to another channel, then these functions will be necessary.
1030  * CDAN-enabled channels only generate a single CDAN notification, after which
1031  * it they need to be reenabled before they'll generate another. (The idea is
1032  * that pull dequeuing will occur in reaction to the CDAN, followed by a
1033  * reenable step.) Each function generates a distinct command to hardware, so a
1034  * combination function is provided if the user wishes to modify the "context"
1035  * (which shows up in each CDAN message) each time they reenable, as a single
1036  * command to hardware.
1037  */
1038
1039 /**
1040  * qbman_swp_CDAN_set_context() - Set CDAN context
1041  * @s: the software portal object.
1042  * @channelid: the channel index.
1043  * @ctx: the context to be set in CDAN.
1044  *
1045  * Return 0 for success, or negative error code for failure.
1046  */
1047 int qbman_swp_CDAN_set_context(struct qbman_swp *s, uint16_t channelid,
1048                                uint64_t ctx);
1049
1050 /**
1051  * qbman_swp_CDAN_enable() - Enable CDAN for the channel.
1052  * @s: the software portal object.
1053  * @channelid: the index of the channel to generate CDAN.
1054  *
1055  * Return 0 for success, or negative error code for failure.
1056  */
1057 int qbman_swp_CDAN_enable(struct qbman_swp *s, uint16_t channelid);
1058
1059 /**
1060  * qbman_swp_CDAN_disable() - disable CDAN for the channel.
1061  * @s: the software portal object.
1062  * @channelid: the index of the channel to generate CDAN.
1063  *
1064  * Return 0 for success, or negative error code for failure.
1065  */
1066 int qbman_swp_CDAN_disable(struct qbman_swp *s, uint16_t channelid);
1067
1068 /**
1069  * qbman_swp_CDAN_set_context_enable() - Set CDAN contest and enable CDAN
1070  * @s: the software portal object.
1071  * @channelid: the index of the channel to generate CDAN.
1072  * @ctx: the context set in CDAN.
1073  *
1074  * Return 0 for success, or negative error code for failure.
1075  */
1076 int qbman_swp_CDAN_set_context_enable(struct qbman_swp *s, uint16_t channelid,
1077                                       uint64_t ctx);
1078 int qbman_swp_fill_ring(struct qbman_swp *s,
1079                         const struct qbman_eq_desc *d,
1080                        const struct qbman_fd *fd,
1081                        uint8_t burst_index);
1082 int qbman_swp_flush_ring(struct qbman_swp *s);
1083 void qbman_sync(void);
1084 int qbman_swp_send_multiple(struct qbman_swp *s,
1085                             const struct qbman_eq_desc *d,
1086                             const struct qbman_fd *fd,
1087                             int frames_to_send);
1088
1089 int qbman_check_command_complete(struct qbman_swp *s,
1090                                  const struct qbman_result *dq);
1091
1092 int qbman_get_version(void);
1093 #endif /* !_FSL_QBMAN_PORTAL_H */