bus/fslmc: remove unused funcs and align names in QBMAN
[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_dqrr_thrshld_read_status() - Get the data in software portal
128  * DQRR interrupt threshold register.
129  * @p: the given software portal object.
130  */
131 uint32_t qbman_swp_dqrr_thrshld_read_status(struct qbman_swp *p);
132
133 /**
134  * qbman_swp_dqrr_thrshld_write() - Set the data in software portal
135  * DQRR interrupt threshold register.
136  * @p: the given software portal object.
137  * @mask: The value to set in SWP_DQRR_ITR register.
138  */
139 void qbman_swp_dqrr_thrshld_write(struct qbman_swp *p, uint32_t mask);
140
141 /**
142  * qbman_swp_intr_timeout_read_status() - Get the data in software portal
143  * Interrupt Time-Out period register.
144  * @p: the given software portal object.
145  */
146 uint32_t qbman_swp_intr_timeout_read_status(struct qbman_swp *p);
147
148 /**
149  * qbman_swp_intr_timeout_write() - Set the data in software portal
150  * Interrupt Time-Out period register.
151  * @p: the given software portal object.
152  * @mask: The value to set in SWP_ITPR register.
153  */
154 void qbman_swp_intr_timeout_write(struct qbman_swp *p, uint32_t mask);
155
156 /**
157  * qbman_swp_interrupt_get_trigger() - Get the data in software portal
158  * interrupt enable register.
159  * @p: the given software portal object.
160  *
161  * Return the settings in SWP_IER register.
162  */
163 uint32_t qbman_swp_interrupt_get_trigger(struct qbman_swp *p);
164
165 /**
166  * qbman_swp_interrupt_set_trigger() - Set the data in software portal
167  * interrupt enable register.
168  * @p: the given software portal object.
169  * @mask: The value to set in SWP_IER register.
170  */
171 void qbman_swp_interrupt_set_trigger(struct qbman_swp *p, uint32_t mask);
172
173 /**
174  * qbman_swp_interrupt_get_inhibit() - Get the data in software portal
175  * interrupt inhibit register.
176  * @p: the given software portal object.
177  *
178  * Return the settings in SWP_IIR register.
179  */
180 int qbman_swp_interrupt_get_inhibit(struct qbman_swp *p);
181
182 /**
183  * qbman_swp_interrupt_set_inhibit() - Set the data in software portal
184  * interrupt inhibit register.
185  * @p: the given software portal object.
186  * @mask: The value to set in SWP_IIR register.
187  */
188 void qbman_swp_interrupt_set_inhibit(struct qbman_swp *p, int inhibit);
189
190         /************/
191         /* Dequeues */
192         /************/
193
194 /**
195  * struct qbman_result - structure for qbman dequeue response and/or
196  * notification.
197  * @donot_manipulate_directly: the 16 32bit data to represent the whole
198  * possible qbman dequeue result.
199  */
200 struct qbman_result {
201         union {
202                 struct common {
203                         uint8_t verb;
204                         uint8_t reserved[63];
205                 } common;
206                 struct dq {
207                         uint8_t verb;
208                         uint8_t stat;
209                         __le16 seqnum;
210                         __le16 oprid;
211                         uint8_t reserved;
212                         uint8_t tok;
213                         __le32 fqid;
214                         uint32_t reserved2;
215                         __le32 fq_byte_cnt;
216                         __le32 fq_frm_cnt;
217                         __le64 fqd_ctx;
218                         uint8_t fd[32];
219                 } dq;
220                 struct scn {
221                         uint8_t verb;
222                         uint8_t stat;
223                         uint8_t state;
224                         uint8_t reserved;
225                         __le32 rid_tok;
226                         __le64 ctx;
227                 } scn;
228         };
229 };
230
231 /* TODO:
232  *A DQRI interrupt can be generated when there are dequeue results on the
233  * portal's DQRR (this mechanism does not deal with "pull" dequeues to
234  * user-supplied 'storage' addresses). There are two parameters to this
235  * interrupt source, one is a threshold and the other is a timeout. The
236  * interrupt will fire if either the fill-level of the ring exceeds 'thresh', or
237  * if the ring has been non-empty for been longer than 'timeout' nanoseconds.
238  * For timeout, an approximation to the desired nanosecond-granularity value is
239  * made, so there are get and set APIs to allow the user to see what actual
240  * timeout is set (compared to the timeout that was requested).
241  */
242 int qbman_swp_dequeue_thresh(struct qbman_swp *s, unsigned int thresh);
243 int qbman_swp_dequeue_set_timeout(struct qbman_swp *s, unsigned int timeout);
244 int qbman_swp_dequeue_get_timeout(struct qbman_swp *s, unsigned int *timeout);
245
246 /* ------------------- */
247 /* Push-mode dequeuing */
248 /* ------------------- */
249
250 /* The user of a portal can enable and disable push-mode dequeuing of up to 16
251  * channels independently. It does not specify this toggling by channel IDs, but
252  * rather by specifying the index (from 0 to 15) that has been mapped to the
253  * desired channel.
254  */
255
256 /**
257  * qbman_swp_push_get() - Get the push dequeue setup.
258  * @s: the software portal object.
259  * @channel_idx: the channel index to query.
260  * @enabled: returned boolean to show whether the push dequeue is enabled for
261  * the given channel.
262  */
263 void qbman_swp_push_get(struct qbman_swp *s, uint8_t channel_idx, int *enabled);
264
265 /**
266  * qbman_swp_push_set() - Enable or disable push dequeue.
267  * @s: the software portal object.
268  * @channel_idx: the channel index..
269  * @enable: enable or disable push dequeue.
270  *
271  * The user of a portal can enable and disable push-mode dequeuing of up to 16
272  * channels independently. It does not specify this toggling by channel IDs, but
273  * rather by specifying the index (from 0 to 15) that has been mapped to the
274  * desired channel.
275  */
276 void qbman_swp_push_set(struct qbman_swp *s, uint8_t channel_idx, int enable);
277
278 /* ------------------- */
279 /* Pull-mode dequeuing */
280 /* ------------------- */
281
282 /**
283  * struct qbman_pull_desc - the structure for pull dequeue descriptor
284  */
285 struct qbman_pull_desc {
286         union {
287                 uint32_t donot_manipulate_directly[16];
288                 struct pull {
289                         uint8_t verb;
290                         uint8_t numf;
291                         uint8_t tok;
292                         uint8_t reserved;
293                         uint32_t dq_src;
294                         uint64_t rsp_addr;
295                         uint64_t rsp_addr_virt;
296                         uint8_t padding[40];
297                 } pull;
298         };
299 };
300
301 enum qbman_pull_type_e {
302         /* dequeue with priority precedence, respect intra-class scheduling */
303         qbman_pull_type_prio = 1,
304         /* dequeue with active FQ precedence, respect ICS */
305         qbman_pull_type_active,
306         /* dequeue with active FQ precedence, no ICS */
307         qbman_pull_type_active_noics
308 };
309
310 /**
311  * qbman_pull_desc_clear() - Clear the contents of a descriptor to
312  * default/starting state.
313  * @d: the pull dequeue descriptor to be cleared.
314  */
315 void qbman_pull_desc_clear(struct qbman_pull_desc *d);
316
317 /**
318  * qbman_pull_desc_set_storage()- Set the pull dequeue storage
319  * @d: the pull dequeue descriptor to be set.
320  * @storage: the pointer of the memory to store the dequeue result.
321  * @storage_phys: the physical address of the storage memory.
322  * @stash: to indicate whether write allocate is enabled.
323  *
324  * If not called, or if called with 'storage' as NULL, the result pull dequeues
325  * will produce results to DQRR. If 'storage' is non-NULL, then results are
326  * produced to the given memory location (using the physical/DMA address which
327  * the caller provides in 'storage_phys'), and 'stash' controls whether or not
328  * those writes to main-memory express a cache-warming attribute.
329  */
330 void qbman_pull_desc_set_storage(struct qbman_pull_desc *d,
331                                  struct qbman_result *storage,
332                                  dma_addr_t storage_phys,
333                                  int stash);
334 /**
335  * qbman_pull_desc_set_numframes() - Set the number of frames to be dequeued.
336  * @d: the pull dequeue descriptor to be set.
337  * @numframes: number of frames to be set, must be between 1 and 16, inclusive.
338  */
339 void qbman_pull_desc_set_numframes(struct qbman_pull_desc *d,
340                                    uint8_t numframes);
341 /**
342  * qbman_pull_desc_set_token() - Set dequeue token for pull command
343  * @d: the dequeue descriptor
344  * @token: the token to be set
345  *
346  * token is the value that shows up in the dequeue response that can be used to
347  * detect when the results have been published. The easiest technique is to zero
348  * result "storage" before issuing a dequeue, and use any non-zero 'token' value
349  */
350 void qbman_pull_desc_set_token(struct qbman_pull_desc *d, uint8_t token);
351
352 /* Exactly one of the following descriptor "actions" should be set. (Calling any
353  * one of these will replace the effect of any prior call to one of these.)
354  * - pull dequeue from the given frame queue (FQ)
355  * - pull dequeue from any FQ in the given work queue (WQ)
356  * - pull dequeue from any FQ in any WQ in the given channel
357  */
358 /**
359  * qbman_pull_desc_set_fq() - Set fqid from which the dequeue command dequeues.
360  * @fqid: the frame queue index of the given FQ.
361  */
362 void qbman_pull_desc_set_fq(struct qbman_pull_desc *d, uint32_t fqid);
363
364 /**
365  * qbman_pull_desc_set_wq() - Set wqid from which the dequeue command dequeues.
366  * @wqid: composed of channel id and wqid within the channel.
367  * @dct: the dequeue command type.
368  */
369 void qbman_pull_desc_set_wq(struct qbman_pull_desc *d, uint32_t wqid,
370                             enum qbman_pull_type_e dct);
371
372 /* qbman_pull_desc_set_channel() - Set channelid from which the dequeue command
373  * dequeues.
374  * @chid: the channel id to be dequeued.
375  * @dct: the dequeue command type.
376  */
377 void qbman_pull_desc_set_channel(struct qbman_pull_desc *d, uint32_t chid,
378                                  enum qbman_pull_type_e dct);
379
380 /**
381  * qbman_swp_pull() - Issue the pull dequeue command
382  * @s: the software portal object.
383  * @d: the software portal descriptor which has been configured with
384  * the set of qbman_pull_desc_set_*() calls.
385  *
386  * Return 0 for success, and -EBUSY if the software portal is not ready
387  * to do pull dequeue.
388  */
389 int qbman_swp_pull(struct qbman_swp *s, struct qbman_pull_desc *d);
390
391 /* -------------------------------- */
392 /* Polling DQRR for dequeue results */
393 /* -------------------------------- */
394
395 /**
396  * qbman_swp_dqrr_next() - Get an valid DQRR entry.
397  * @s: the software portal object.
398  *
399  * Return NULL if there are no unconsumed DQRR entries. Return a DQRR entry
400  * only once, so repeated calls can return a sequence of DQRR entries, without
401  * requiring they be consumed immediately or in any particular order.
402  */
403 const struct qbman_result *qbman_swp_dqrr_next(struct qbman_swp *p);
404
405 /**
406  * qbman_swp_dqrr_consume() -  Consume DQRR entries previously returned from
407  * qbman_swp_dqrr_next().
408  * @s: the software portal object.
409  * @dq: the DQRR entry to be consumed.
410  */
411 void qbman_swp_dqrr_consume(struct qbman_swp *s, const struct qbman_result *dq);
412
413 /**
414  * qbman_get_dqrr_idx() - Get dqrr index from the given dqrr
415  * @dqrr: the given dqrr object.
416  *
417  * Return dqrr index.
418  */
419 uint8_t qbman_get_dqrr_idx(const struct qbman_result *dqrr);
420
421 /**
422  * qbman_get_dqrr_from_idx() - Use index to get the dqrr entry from the
423  * given portal
424  * @s: the given portal.
425  * @idx: the dqrr index.
426  *
427  * Return dqrr entry object.
428  */
429 struct qbman_result *qbman_get_dqrr_from_idx(struct qbman_swp *s, uint8_t idx);
430
431 /* ------------------------------------------------- */
432 /* Polling user-provided storage for dequeue results */
433 /* ------------------------------------------------- */
434
435 /**
436  * qbman_result_has_new_result() - Check and get the dequeue response from the
437  * dq storage memory set in pull dequeue command
438  * @s: the software portal object.
439  * @dq: the dequeue result read from the memory.
440  *
441  * Only used for user-provided storage of dequeue results, not DQRR. For
442  * efficiency purposes, the driver will perform any required endianness
443  * conversion to ensure that the user's dequeue result storage is in host-endian
444  * format (whether or not that is the same as the little-endian format that
445  * hardware DMA'd to the user's storage). As such, once the user has called
446  * qbman_result_has_new_result() and been returned a valid dequeue result,
447  * they should not call it again on the same memory location (except of course
448  * if another dequeue command has been executed to produce a new result to that
449  * location).
450  *
451  * Return 1 for getting a valid dequeue result, or 0 for not getting a valid
452  * dequeue result.
453  */
454 int qbman_result_has_new_result(struct qbman_swp *s,
455                                 struct qbman_result *dq);
456
457 /**
458  * qbman_check_command_complete() - Check if the previous issued dq commnd
459  * is completed and results are available in memory.
460  * @s: the software portal object.
461  * @dq: the dequeue result read from the memory.
462  *
463  * Return 1 for getting a valid dequeue result, or 0 for not getting a valid
464  * dequeue result.
465  */
466 int qbman_check_command_complete(struct qbman_result *dq);
467
468 int qbman_check_new_result(struct qbman_result *dq);
469
470 /* -------------------------------------------------------- */
471 /* Parsing dequeue entries (DQRR and user-provided storage) */
472 /* -------------------------------------------------------- */
473
474 /**
475  * qbman_result_is_DQ() - check the dequeue result is a dequeue response or not
476  * @dq: the dequeue result to be checked.
477  *
478  * DQRR entries may contain non-dequeue results, ie. notifications
479  */
480 int qbman_result_is_DQ(const struct qbman_result *dq);
481
482 /**
483  * qbman_result_is_SCN() - Check the dequeue result is notification or not
484  * @dq: the dequeue result to be checked.
485  *
486  * All the non-dequeue results (FQDAN/CDAN/CSCN/...) are "state change
487  * notifications" of one type or another. Some APIs apply to all of them, of the
488  * form qbman_result_SCN_***().
489  */
490 static inline int qbman_result_is_SCN(const struct qbman_result *dq)
491 {
492         return !qbman_result_is_DQ(dq);
493 }
494
495 /* Recognise different notification types, only required if the user allows for
496  * these to occur, and cares about them when they do.
497  */
498
499 /**
500  * qbman_result_is_FQDAN() - Check for FQ Data Availability
501  * @dq: the qbman_result object.
502  *
503  * Return 1 if this is FQDAN.
504  */
505 int qbman_result_is_FQDAN(const struct qbman_result *dq);
506
507 /**
508  * qbman_result_is_CDAN() - Check for Channel Data Availability
509  * @dq: the qbman_result object to check.
510  *
511  * Return 1 if this is CDAN.
512  */
513 int qbman_result_is_CDAN(const struct qbman_result *dq);
514
515 /**
516  * qbman_result_is_CSCN() - Check for Congestion State Change
517  * @dq: the qbman_result object to check.
518  *
519  * Return 1 if this is CSCN.
520  */
521 int qbman_result_is_CSCN(const struct qbman_result *dq);
522
523 /**
524  * qbman_result_is_BPSCN() - Check for Buffer Pool State Change.
525  * @dq: the qbman_result object to check.
526  *
527  * Return 1 if this is BPSCN.
528  */
529 int qbman_result_is_BPSCN(const struct qbman_result *dq);
530
531 /**
532  * qbman_result_is_CGCU() - Check for Congestion Group Count Update.
533  * @dq: the qbman_result object to check.
534  *
535  * Return 1 if this is CGCU.
536  */
537 int qbman_result_is_CGCU(const struct qbman_result *dq);
538
539 /* Frame queue state change notifications; (FQDAN in theory counts too as it
540  * leaves a FQ parked, but it is primarily a data availability notification)
541  */
542
543 /**
544  * qbman_result_is_FQRN() - Check for FQ Retirement Notification.
545  * @dq: the qbman_result object to check.
546  *
547  * Return 1 if this is FQRN.
548  */
549 int qbman_result_is_FQRN(const struct qbman_result *dq);
550
551 /**
552  * qbman_result_is_FQRNI() - Check for FQ Retirement Immediate
553  * @dq: the qbman_result object to check.
554  *
555  * Return 1 if this is FQRNI.
556  */
557 int qbman_result_is_FQRNI(const struct qbman_result *dq);
558
559 /**
560  * qbman_result_is_FQPN() - Check for FQ Park Notification
561  * @dq: the qbman_result object to check.
562  *
563  * Return 1 if this is FQPN.
564  */
565 int qbman_result_is_FQPN(const struct qbman_result *dq);
566
567 /* Parsing frame dequeue results (qbman_result_is_DQ() must be TRUE)
568  */
569 /* FQ empty */
570 #define QBMAN_DQ_STAT_FQEMPTY       0x80
571 /* FQ held active */
572 #define QBMAN_DQ_STAT_HELDACTIVE    0x40
573 /* FQ force eligible */
574 #define QBMAN_DQ_STAT_FORCEELIGIBLE 0x20
575 /* Valid frame */
576 #define QBMAN_DQ_STAT_VALIDFRAME    0x10
577 /* FQ ODP enable */
578 #define QBMAN_DQ_STAT_ODPVALID      0x04
579 /* Volatile dequeue */
580 #define QBMAN_DQ_STAT_VOLATILE      0x02
581 /* volatile dequeue command is expired */
582 #define QBMAN_DQ_STAT_EXPIRED       0x01
583
584 /**
585  * qbman_result_DQ_flags() - Get the STAT field of dequeue response
586  * @dq: the dequeue result.
587  *
588  * Return the state field.
589  */
590 uint8_t qbman_result_DQ_flags(const struct qbman_result *dq);
591
592 /**
593  * qbman_result_DQ_is_pull() - Check whether the dq response is from a pull
594  * command.
595  * @dq: the dequeue result.
596  *
597  * Return 1 for volatile(pull) dequeue, 0 for static dequeue.
598  */
599 static inline int qbman_result_DQ_is_pull(const struct qbman_result *dq)
600 {
601         return (int)(qbman_result_DQ_flags(dq) & QBMAN_DQ_STAT_VOLATILE);
602 }
603
604 /**
605  * qbman_result_DQ_is_pull_complete() - Check whether the pull command is
606  * completed.
607  * @dq: the dequeue result.
608  *
609  * Return boolean.
610  */
611 static inline int qbman_result_DQ_is_pull_complete(
612                                         const struct qbman_result *dq)
613 {
614         return (int)(qbman_result_DQ_flags(dq) & QBMAN_DQ_STAT_EXPIRED);
615 }
616
617 /**
618  * qbman_result_DQ_seqnum()  - Get the seqnum field in dequeue response
619  * seqnum is valid only if VALIDFRAME flag is TRUE
620  * @dq: the dequeue result.
621  *
622  * Return seqnum.
623  */
624 uint16_t qbman_result_DQ_seqnum(const struct qbman_result *dq);
625
626 /**
627  * qbman_result_DQ_odpid() - Get the seqnum field in dequeue response
628  * odpid is valid only if ODPVAILD flag is TRUE.
629  * @dq: the dequeue result.
630  *
631  * Return odpid.
632  */
633 uint16_t qbman_result_DQ_odpid(const struct qbman_result *dq);
634
635 /**
636  * qbman_result_DQ_fqid() - Get the fqid in dequeue response
637  * @dq: the dequeue result.
638  *
639  * Return fqid.
640  */
641 uint32_t qbman_result_DQ_fqid(const struct qbman_result *dq);
642
643 /**
644  * qbman_result_DQ_byte_count() - Get the byte count in dequeue response
645  * @dq: the dequeue result.
646  *
647  * Return the byte count remaining in the FQ.
648  */
649 uint32_t qbman_result_DQ_byte_count(const struct qbman_result *dq);
650
651 /**
652  * qbman_result_DQ_frame_count - Get the frame count in dequeue response
653  * @dq: the dequeue result.
654  *
655  * Return the frame count remaining in the FQ.
656  */
657 uint32_t qbman_result_DQ_frame_count(const struct qbman_result *dq);
658
659 /**
660  * qbman_result_DQ_fqd_ctx() - Get the frame queue context in dequeue response
661  * @dq: the dequeue result.
662  *
663  * Return the frame queue context.
664  */
665 uint64_t qbman_result_DQ_fqd_ctx(const struct qbman_result *dq);
666
667 /**
668  * qbman_result_DQ_fd() - Get the frame descriptor in dequeue response
669  * @dq: the dequeue result.
670  *
671  * Return the frame descriptor.
672  */
673 const struct qbman_fd *qbman_result_DQ_fd(const struct qbman_result *dq);
674
675 /* State-change notifications (FQDAN/CDAN/CSCN/...). */
676
677 /**
678  * qbman_result_SCN_state() - Get the state field in State-change notification
679  * @scn: the state change notification.
680  *
681  * Return the state in the notifiation.
682  */
683 uint8_t qbman_result_SCN_state(const struct qbman_result *scn);
684
685 /**
686  * qbman_result_SCN_rid() - Get the resource id from the notification
687  * @scn: the state change notification.
688  *
689  * Return the resource id.
690  */
691 uint32_t qbman_result_SCN_rid(const struct qbman_result *scn);
692
693 /**
694  * qbman_result_SCN_ctx() - get the context from the notification
695  * @scn: the state change notification.
696  *
697  * Return the context.
698  */
699 uint64_t qbman_result_SCN_ctx(const struct qbman_result *scn);
700
701 /* Type-specific "resource IDs". Mainly for illustration purposes, though it
702  * also gives the appropriate type widths.
703  */
704 /* Get the FQID from the FQDAN */
705 #define qbman_result_FQDAN_fqid(dq) qbman_result_SCN_rid(dq)
706 /* Get the FQID from the FQRN */
707 #define qbman_result_FQRN_fqid(dq) qbman_result_SCN_rid(dq)
708 /* Get the FQID from the FQRNI */
709 #define qbman_result_FQRNI_fqid(dq) qbman_result_SCN_rid(dq)
710 /* Get the FQID from the FQPN */
711 #define qbman_result_FQPN_fqid(dq) qbman_result_SCN_rid(dq)
712 /* Get the channel ID from the CDAN */
713 #define qbman_result_CDAN_cid(dq) ((uint16_t)qbman_result_SCN_rid(dq))
714 /* Get the CGID from the CSCN */
715 #define qbman_result_CSCN_cgid(dq) ((uint16_t)qbman_result_SCN_rid(dq))
716
717 /**
718  * qbman_result_bpscn_bpid() - Get the bpid from BPSCN
719  * @scn: the state change notification.
720  *
721  * Return the buffer pool id.
722  */
723 uint16_t qbman_result_bpscn_bpid(const struct qbman_result *scn);
724
725 /**
726  * qbman_result_bpscn_has_free_bufs() - Check whether there are free
727  * buffers in the pool from BPSCN.
728  * @scn: the state change notification.
729  *
730  * Return the number of free buffers.
731  */
732 int qbman_result_bpscn_has_free_bufs(const struct qbman_result *scn);
733
734 /**
735  * qbman_result_bpscn_is_depleted() - Check BPSCN to see whether the
736  * buffer pool is depleted.
737  * @scn: the state change notification.
738  *
739  * Return the status of buffer pool depletion.
740  */
741 int qbman_result_bpscn_is_depleted(const struct qbman_result *scn);
742
743 /**
744  * qbman_result_bpscn_is_surplus() - Check BPSCN to see whether the buffer
745  * pool is surplus or not.
746  * @scn: the state change notification.
747  *
748  * Return the status of buffer pool surplus.
749  */
750 int qbman_result_bpscn_is_surplus(const struct qbman_result *scn);
751
752 /**
753  * qbman_result_bpscn_ctx() - Get the BPSCN CTX from BPSCN message
754  * @scn: the state change notification.
755  *
756  * Return the BPSCN context.
757  */
758 uint64_t qbman_result_bpscn_ctx(const struct qbman_result *scn);
759
760 /* Parsing CGCU */
761 /**
762  * qbman_result_cgcu_cgid() - Check CGCU resouce id, i.e. cgid
763  * @scn: the state change notification.
764  *
765  * Return the CGCU resource id.
766  */
767 uint16_t qbman_result_cgcu_cgid(const struct qbman_result *scn);
768
769 /**
770  * qbman_result_cgcu_icnt() - Get the I_CNT from CGCU
771  * @scn: the state change notification.
772  *
773  * Return instantaneous count in the CGCU notification.
774  */
775 uint64_t qbman_result_cgcu_icnt(const struct qbman_result *scn);
776
777         /************/
778         /* Enqueues */
779         /************/
780
781 /* struct qbman_eq_desc - structure of enqueue descriptor */
782 struct qbman_eq_desc {
783         union {
784                 uint32_t donot_manipulate_directly[8];
785                 struct eq {
786                         uint8_t verb;
787                         uint8_t dca;
788                         uint16_t seqnum;
789                         uint16_t orpid;
790                         uint16_t reserved1;
791                         uint32_t tgtid;
792                         uint32_t tag;
793                         uint16_t qdbin;
794                         uint8_t qpri;
795                         uint8_t reserved[3];
796                         uint8_t wae;
797                         uint8_t rspid;
798                         uint64_t rsp_addr;
799                         uint8_t fd[32];
800                 } eq;
801         };
802 };
803
804 /**
805  * struct qbman_eq_response - structure of enqueue response
806  * @donot_manipulate_directly: the 16 32bit data to represent the whole
807  * enqueue response.
808  */
809 struct qbman_eq_response {
810         uint32_t donot_manipulate_directly[16];
811 };
812
813 /**
814  * qbman_eq_desc_clear() - Clear the contents of a descriptor to
815  * default/starting state.
816  * @d: the given enqueue descriptor.
817  */
818 void qbman_eq_desc_clear(struct qbman_eq_desc *d);
819
820 /* Exactly one of the following descriptor "actions" should be set. (Calling
821  * any one of these will replace the effect of any prior call to one of these.)
822  * - enqueue without order-restoration
823  * - enqueue with order-restoration
824  * - fill a hole in the order-restoration sequence, without any enqueue
825  * - advance NESN (Next Expected Sequence Number), without any enqueue
826  * 'respond_success' indicates whether an enqueue response should be DMA'd
827  * after success (otherwise a response is DMA'd only after failure).
828  * 'incomplete' indicates that other fragments of the same 'seqnum' are yet to
829  * be enqueued.
830  */
831
832 /**
833  * qbman_eq_desc_set_no_orp() - Set enqueue descriptor without orp
834  * @d: the enqueue descriptor.
835  * @response_success: 1 = enqueue with response always; 0 = enqueue with
836  * rejections returned on a FQ.
837  */
838 void qbman_eq_desc_set_no_orp(struct qbman_eq_desc *d, int respond_success);
839 /**
840  * qbman_eq_desc_set_orp() - Set order-resotration in the enqueue descriptor
841  * @d: the enqueue descriptor.
842  * @response_success: 1 = enqueue with response always; 0 = enqueue with
843  * rejections returned on a FQ.
844  * @opr_id: the order point record id.
845  * @seqnum: the order restoration sequence number.
846  * @incomplete: indiates whether this is the last fragments using the same
847  * sequeue number.
848  */
849 void qbman_eq_desc_set_orp(struct qbman_eq_desc *d, int respond_success,
850                            uint16_t opr_id, uint16_t seqnum, int incomplete);
851
852 /**
853  * qbman_eq_desc_set_orp_hole() - fill a hole in the order-restoration sequence
854  * without any enqueue
855  * @d: the enqueue descriptor.
856  * @opr_id: the order point record id.
857  * @seqnum: the order restoration sequence number.
858  */
859 void qbman_eq_desc_set_orp_hole(struct qbman_eq_desc *d, uint16_t opr_id,
860                                 uint16_t seqnum);
861
862 /**
863  * qbman_eq_desc_set_orp_nesn() -  advance NESN (Next Expected Sequence Number)
864  * without any enqueue
865  * @d: the enqueue descriptor.
866  * @opr_id: the order point record id.
867  * @seqnum: the order restoration sequence number.
868  */
869 void qbman_eq_desc_set_orp_nesn(struct qbman_eq_desc *d, uint16_t opr_id,
870                                 uint16_t seqnum);
871 /**
872  * qbman_eq_desc_set_response() - Set the enqueue response info.
873  * @d: the enqueue descriptor
874  * @storage_phys: the physical address of the enqueue response in memory.
875  * @stash: indicate that the write allocation enabled or not.
876  *
877  * In the case where an enqueue response is DMA'd, this determines where that
878  * response should go. (The physical/DMA address is given for hardware's
879  * benefit, but software should interpret it as a "struct qbman_eq_response"
880  * data structure.) 'stash' controls whether or not the write to main-memory
881  * expresses a cache-warming attribute.
882  */
883 void qbman_eq_desc_set_response(struct qbman_eq_desc *d,
884                                 dma_addr_t storage_phys,
885                                 int stash);
886
887 /**
888  * qbman_eq_desc_set_token() - Set token for the enqueue command
889  * @d: the enqueue descriptor
890  * @token: the token to be set.
891  *
892  * token is the value that shows up in an enqueue response that can be used to
893  * detect when the results have been published. The easiest technique is to zero
894  * result "storage" before issuing an enqueue, and use any non-zero 'token'
895  * value.
896  */
897 void qbman_eq_desc_set_token(struct qbman_eq_desc *d, uint8_t token);
898
899 /**
900  * Exactly one of the following descriptor "targets" should be set. (Calling any
901  * one of these will replace the effect of any prior call to one of these.)
902  * - enqueue to a frame queue
903  * - enqueue to a queuing destination
904  * Note, that none of these will have any affect if the "action" type has been
905  * set to "orp_hole" or "orp_nesn".
906  */
907 /**
908  * qbman_eq_desc_set_fq() - Set Frame Queue id for the enqueue command
909  * @d: the enqueue descriptor
910  * @fqid: the id of the frame queue to be enqueued.
911  */
912 void qbman_eq_desc_set_fq(struct qbman_eq_desc *d, uint32_t fqid);
913
914 /**
915  * qbman_eq_desc_set_qd() - Set Queuing Destination for the enqueue command.
916  * @d: the enqueue descriptor
917  * @qdid: the id of the queuing destination to be enqueued.
918  * @qd_bin: the queuing destination bin
919  * @qd_prio: the queuing destination priority.
920  */
921 void qbman_eq_desc_set_qd(struct qbman_eq_desc *d, uint32_t qdid,
922                           uint16_t qd_bin, uint8_t qd_prio);
923
924 /**
925  * qbman_eq_desc_set_eqdi() - enable/disable EQDI interrupt
926  * @d: the enqueue descriptor
927  * @enable: boolean to enable/disable EQDI
928  *
929  * Determines whether or not the portal's EQDI interrupt source should be
930  * asserted after the enqueue command is completed.
931  */
932 void qbman_eq_desc_set_eqdi(struct qbman_eq_desc *d, int enable);
933
934 /**
935  * qbman_eq_desc_set_dca() - Set DCA mode in the enqueue command.
936  * @d: the enqueue descriptor.
937  * @enable: enabled/disable DCA mode.
938  * @dqrr_idx: DCAP_CI, the DCAP consumer index.
939  * @park: determine the whether park the FQ or not
940  *
941  * Determines whether or not a portal DQRR entry should be consumed once the
942  * enqueue command is completed. (And if so, and the DQRR entry corresponds to a
943  * held-active (order-preserving) FQ, whether the FQ should be parked instead of
944  * being rescheduled.)
945  */
946 void qbman_eq_desc_set_dca(struct qbman_eq_desc *d, int enable,
947                            uint8_t dqrr_idx, int park);
948
949 /**
950  * qbman_swp_enqueue() - Issue an enqueue command.
951  * @s: the software portal used for enqueue.
952  * @d: the enqueue descriptor.
953  * @fd: the frame descriptor to be enqueued.
954  *
955  * Please note that 'fd' should only be NULL if the "action" of the
956  * descriptor is "orp_hole" or "orp_nesn".
957  *
958  * Return 0 for a successful enqueue, -EBUSY if the EQCR is not ready.
959  */
960 int qbman_swp_enqueue(struct qbman_swp *s, const struct qbman_eq_desc *d,
961                       const struct qbman_fd *fd);
962 /**
963  * qbman_swp_enqueue_multiple() - Enqueue multiple frames with same
964                                   eq descriptor
965  * @s: the software portal used for enqueue.
966  * @d: the enqueue descriptor.
967  * @fd: the frame descriptor to be enqueued.
968  * @num_frames: the number of the frames to be enqueued.
969  *
970  * Return the number of enqueued frames, -EBUSY if the EQCR is not ready.
971  */
972 int qbman_swp_enqueue_multiple(struct qbman_swp *s,
973                                const struct qbman_eq_desc *d,
974                                const struct qbman_fd *fd,
975                                int num_frames);
976 /**
977  * qbman_swp_enqueue_multiple_desc() - Enqueue multiple frames with
978  *                                     individual eq descriptor.
979  * @s: the software portal used for enqueue.
980  * @d: the enqueue descriptor.
981  * @fd: the frame descriptor to be enqueued.
982  * @num_frames: the number of the frames to be enqueued.
983  *
984  * Return the number of enqueued frames, -EBUSY if the EQCR is not ready.
985  */
986 int qbman_swp_enqueue_multiple_desc(struct qbman_swp *s,
987                                     const struct qbman_eq_desc *d,
988                                     const struct qbman_fd *fd,
989                                     int num_frames);
990
991 /* TODO:
992  * qbman_swp_enqueue_thresh() - Set threshold for EQRI interrupt.
993  * @s: the software portal.
994  * @thresh: the threshold to trigger the EQRI interrupt.
995  *
996  * An EQRI interrupt can be generated when the fill-level of EQCR falls below
997  * the 'thresh' value set here. Setting thresh==0 (the default) disables.
998  */
999 int qbman_swp_enqueue_thresh(struct qbman_swp *s, unsigned int thresh);
1000
1001         /*******************/
1002         /* Buffer releases */
1003         /*******************/
1004 /**
1005  * struct qbman_release_desc - The structure for buffer release descriptor
1006  * @donot_manipulate_directly: the 32bit data to represent the whole
1007  * possible settings of qbman release descriptor.
1008  */
1009 struct qbman_release_desc {
1010         union {
1011                 uint32_t donot_manipulate_directly[16];
1012                 struct br {
1013                         uint8_t verb;
1014                         uint8_t reserved;
1015                         uint16_t bpid;
1016                         uint32_t reserved2;
1017                         uint64_t buf[7];
1018                 } br;
1019         };
1020 };
1021
1022 /**
1023  * qbman_release_desc_clear() - Clear the contents of a descriptor to
1024  * default/starting state.
1025  * @d: the qbman release descriptor.
1026  */
1027 void qbman_release_desc_clear(struct qbman_release_desc *d);
1028
1029 /**
1030  * qbman_release_desc_set_bpid() - Set the ID of the buffer pool to release to
1031  * @d: the qbman release descriptor.
1032  */
1033 void qbman_release_desc_set_bpid(struct qbman_release_desc *d, uint16_t bpid);
1034
1035 /**
1036  * qbman_release_desc_set_rcdi() - Determines whether or not the portal's RCDI
1037  * interrupt source should be asserted after the release command is completed.
1038  * @d: the qbman release descriptor.
1039  */
1040 void qbman_release_desc_set_rcdi(struct qbman_release_desc *d, int enable);
1041
1042 /**
1043  * qbman_swp_release() - Issue a buffer release command.
1044  * @s: the software portal object.
1045  * @d: the release descriptor.
1046  * @buffers: a pointer pointing to the buffer address to be released.
1047  * @num_buffers: number of buffers to be released,  must be less than 8.
1048  *
1049  * Return 0 for success, -EBUSY if the release command ring is not ready.
1050  */
1051 int qbman_swp_release(struct qbman_swp *s, const struct qbman_release_desc *d,
1052                       const uint64_t *buffers, unsigned int num_buffers);
1053
1054 /* TODO:
1055  * qbman_swp_release_thresh() - Set threshold for RCRI interrupt
1056  * @s: the software portal.
1057  * @thresh: the threshold.
1058  * An RCRI interrupt can be generated when the fill-level of RCR falls below
1059  * the 'thresh' value set here. Setting thresh==0 (the default) disables.
1060  */
1061 int qbman_swp_release_thresh(struct qbman_swp *s, unsigned int thresh);
1062
1063         /*******************/
1064         /* Buffer acquires */
1065         /*******************/
1066 /**
1067  * qbman_swp_acquire() - Issue a buffer acquire command.
1068  * @s: the software portal object.
1069  * @bpid: the buffer pool index.
1070  * @buffers: a pointer pointing to the acquired buffer address|es.
1071  * @num_buffers: number of buffers to be acquired, must be less than 8.
1072  *
1073  * Return 0 for success, or negative error code if the acquire command
1074  * fails.
1075  */
1076 int qbman_swp_acquire(struct qbman_swp *s, uint16_t bpid, uint64_t *buffers,
1077                       unsigned int num_buffers);
1078
1079         /*****************/
1080         /* FQ management */
1081         /*****************/
1082 /**
1083  * qbman_swp_fq_schedule() - Move the fq to the scheduled state.
1084  * @s: the software portal object.
1085  * @fqid: the index of frame queue to be scheduled.
1086  *
1087  * There are a couple of different ways that a FQ can end up parked state,
1088  * This schedules it.
1089  *
1090  * Return 0 for success, or negative error code for failure.
1091  */
1092 int qbman_swp_fq_schedule(struct qbman_swp *s, uint32_t fqid);
1093
1094 /**
1095  * qbman_swp_fq_force() - Force the FQ to fully scheduled state.
1096  * @s: the software portal object.
1097  * @fqid: the index of frame queue to be forced.
1098  *
1099  * Force eligible will force a tentatively-scheduled FQ to be fully-scheduled
1100  * and thus be available for selection by any channel-dequeuing behaviour (push
1101  * or pull). If the FQ is subsequently "dequeued" from the channel and is still
1102  * empty at the time this happens, the resulting dq_entry will have no FD.
1103  * (qbman_result_DQ_fd() will return NULL.)
1104  *
1105  * Return 0 for success, or negative error code for failure.
1106  */
1107 int qbman_swp_fq_force(struct qbman_swp *s, uint32_t fqid);
1108
1109 /**
1110  * These functions change the FQ flow-control stuff between XON/XOFF. (The
1111  * default is XON.) This setting doesn't affect enqueues to the FQ, just
1112  * dequeues. XOFF FQs will remain in the tenatively-scheduled state, even when
1113  * non-empty, meaning they won't be selected for scheduled dequeuing. If a FQ is
1114  * changed to XOFF after it had already become truly-scheduled to a channel, and
1115  * a pull dequeue of that channel occurs that selects that FQ for dequeuing,
1116  * then the resulting dq_entry will have no FD. (qbman_result_DQ_fd() will
1117  * return NULL.)
1118  */
1119 /**
1120  * qbman_swp_fq_xon() - XON the frame queue.
1121  * @s: the software portal object.
1122  * @fqid: the index of frame queue.
1123  *
1124  * Return 0 for success, or negative error code for failure.
1125  */
1126 int qbman_swp_fq_xon(struct qbman_swp *s, uint32_t fqid);
1127 /**
1128  * qbman_swp_fq_xoff() - XOFF the frame queue.
1129  * @s: the software portal object.
1130  * @fqid: the index of frame queue.
1131  *
1132  * Return 0 for success, or negative error code for failure.
1133  */
1134 int qbman_swp_fq_xoff(struct qbman_swp *s, uint32_t fqid);
1135
1136         /**********************/
1137         /* Channel management */
1138         /**********************/
1139
1140 /**
1141  * If the user has been allocated a channel object that is going to generate
1142  * CDANs to another channel, then these functions will be necessary.
1143  * CDAN-enabled channels only generate a single CDAN notification, after which
1144  * it they need to be reenabled before they'll generate another. (The idea is
1145  * that pull dequeuing will occur in reaction to the CDAN, followed by a
1146  * reenable step.) Each function generates a distinct command to hardware, so a
1147  * combination function is provided if the user wishes to modify the "context"
1148  * (which shows up in each CDAN message) each time they reenable, as a single
1149  * command to hardware.
1150  */
1151
1152 /**
1153  * qbman_swp_CDAN_set_context() - Set CDAN context
1154  * @s: the software portal object.
1155  * @channelid: the channel index.
1156  * @ctx: the context to be set in CDAN.
1157  *
1158  * Return 0 for success, or negative error code for failure.
1159  */
1160 int qbman_swp_CDAN_set_context(struct qbman_swp *s, uint16_t channelid,
1161                                uint64_t ctx);
1162
1163 /**
1164  * qbman_swp_CDAN_enable() - Enable CDAN for the channel.
1165  * @s: the software portal object.
1166  * @channelid: the index of the channel to generate CDAN.
1167  *
1168  * Return 0 for success, or negative error code for failure.
1169  */
1170 int qbman_swp_CDAN_enable(struct qbman_swp *s, uint16_t channelid);
1171
1172 /**
1173  * qbman_swp_CDAN_disable() - disable CDAN for the channel.
1174  * @s: the software portal object.
1175  * @channelid: the index of the channel to generate CDAN.
1176  *
1177  * Return 0 for success, or negative error code for failure.
1178  */
1179 int qbman_swp_CDAN_disable(struct qbman_swp *s, uint16_t channelid);
1180
1181 /**
1182  * qbman_swp_CDAN_set_context_enable() - Set CDAN contest and enable CDAN
1183  * @s: the software portal object.
1184  * @channelid: the index of the channel to generate CDAN.
1185  * @ctx: the context set in CDAN.
1186  *
1187  * Return 0 for success, or negative error code for failure.
1188  */
1189 int qbman_swp_CDAN_set_context_enable(struct qbman_swp *s, uint16_t channelid,
1190                                       uint64_t ctx);
1191 #endif /* !_FSL_QBMAN_PORTAL_H */