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