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