1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (C) 2014 Freescale Semiconductor, Inc.
4 * Copyright 2015-2019 NXP
7 #ifndef _FSL_QBMAN_PORTAL_H
8 #define _FSL_QBMAN_PORTAL_H
10 #include <fsl_qbman_base.h>
12 #define SVR_LS1080A 0x87030000
13 #define SVR_LS2080A 0x87010000
14 #define SVR_LS2088A 0x87090000
15 #define SVR_LX2160A 0x87360000
17 /* Variable to store DPAA2 platform type */
18 extern uint32_t dpaa2_svr_family;
21 * DOC - QBMan portal APIs to implement the following functions:
22 * - Initialize and destroy Software portal object.
23 * - Read and write Software portal interrupt registers.
24 * - Enqueue, including setting the enqueue descriptor, and issuing enqueue
26 * - Dequeue, including setting the dequeue descriptor, issuing dequeue command,
27 * parsing the dequeue response in DQRR and memory, parsing the state change
29 * - Release, including setting the release descriptor, and issuing the buffer
31 * - Acquire, acquire the buffer from the given buffer pool.
33 * - Channel management, enable/disable CDAN with or without context.
37 * qbman_swp_init() - Create a functional object representing the given
38 * QBMan portal descriptor.
39 * @d: the given qbman swp descriptor
41 * Return qbman_swp portal object for success, NULL if the object cannot
44 struct qbman_swp *qbman_swp_init(const struct qbman_swp_desc *d);
47 * qbman_swp_finish() - Create and destroy a functional object representing
48 * the given QBMan portal descriptor.
49 * @p: the qbman_swp object to be destroyed.
52 void qbman_swp_finish(struct qbman_swp *p);
55 * qbman_swp_invalidate() - Invalidate the cache enabled area of the QBMan
56 * portal. This is required to be called if a portal moved to another core
57 * because the QBMan portal area is non coherent
58 * @p: the qbman_swp object to be invalidated
61 void qbman_swp_invalidate(struct qbman_swp *p);
64 * qbman_swp_get_desc() - Get the descriptor of the given portal object.
65 * @p: the given portal object.
67 * Return the descriptor for this portal.
69 const struct qbman_swp_desc *qbman_swp_get_desc(struct qbman_swp *p);
75 /* EQCR ring interrupt */
76 #define QBMAN_SWP_INTERRUPT_EQRI ((uint32_t)0x00000001)
77 /* Enqueue command dispatched interrupt */
78 #define QBMAN_SWP_INTERRUPT_EQDI ((uint32_t)0x00000002)
79 /* DQRR non-empty interrupt */
80 #define QBMAN_SWP_INTERRUPT_DQRI ((uint32_t)0x00000004)
81 /* RCR ring interrupt */
82 #define QBMAN_SWP_INTERRUPT_RCRI ((uint32_t)0x00000008)
83 /* Release command dispatched interrupt */
84 #define QBMAN_SWP_INTERRUPT_RCDI ((uint32_t)0x00000010)
85 /* Volatile dequeue command interrupt */
86 #define QBMAN_SWP_INTERRUPT_VDCI ((uint32_t)0x00000020)
89 * qbman_swp_interrupt_get_vanish() - Get the data in software portal
90 * interrupt status disable register.
91 * @p: the given software portal object.
93 * Return the settings in SWP_ISDR register.
95 uint32_t qbman_swp_interrupt_get_vanish(struct qbman_swp *p);
98 * qbman_swp_interrupt_set_vanish() - Set the data in software portal
99 * interrupt status disable register.
100 * @p: the given software portal object.
101 * @mask: The value to set in SWP_IDSR register.
103 void qbman_swp_interrupt_set_vanish(struct qbman_swp *p, uint32_t mask);
106 * qbman_swp_interrupt_read_status() - Get the data in software portal
107 * interrupt status register.
108 * @p: the given software portal object.
110 * Return the settings in SWP_ISR register.
112 uint32_t qbman_swp_interrupt_read_status(struct qbman_swp *p);
115 * qbman_swp_interrupt_clear_status() - Set the data in software portal
116 * interrupt status register.
117 * @p: the given software portal object.
118 * @mask: The value to set in SWP_ISR register.
120 void qbman_swp_interrupt_clear_status(struct qbman_swp *p, uint32_t mask);
123 * qbman_swp_dqrr_thrshld_read_status() - Get the data in software portal
124 * DQRR interrupt threshold register.
125 * @p: the given software portal object.
127 uint32_t qbman_swp_dqrr_thrshld_read_status(struct qbman_swp *p);
130 * qbman_swp_dqrr_thrshld_write() - Set the data in software portal
131 * DQRR interrupt threshold register.
132 * @p: the given software portal object.
133 * @mask: The value to set in SWP_DQRR_ITR register.
135 void qbman_swp_dqrr_thrshld_write(struct qbman_swp *p, uint32_t mask);
138 * qbman_swp_intr_timeout_read_status() - Get the data in software portal
139 * Interrupt Time-Out period register.
140 * @p: the given software portal object.
142 uint32_t qbman_swp_intr_timeout_read_status(struct qbman_swp *p);
145 * qbman_swp_intr_timeout_write() - Set the data in software portal
146 * Interrupt Time-Out period register.
147 * @p: the given software portal object.
148 * @mask: The value to set in SWP_ITPR register.
150 void qbman_swp_intr_timeout_write(struct qbman_swp *p, uint32_t mask);
153 * qbman_swp_interrupt_get_trigger() - Get the data in software portal
154 * interrupt enable register.
155 * @p: the given software portal object.
157 * Return the settings in SWP_IER register.
159 uint32_t qbman_swp_interrupt_get_trigger(struct qbman_swp *p);
162 * qbman_swp_interrupt_set_trigger() - Set the data in software portal
163 * interrupt enable register.
164 * @p: the given software portal object.
165 * @mask: The value to set in SWP_IER register.
167 void qbman_swp_interrupt_set_trigger(struct qbman_swp *p, uint32_t mask);
170 * qbman_swp_interrupt_get_inhibit() - Get the data in software portal
171 * interrupt inhibit register.
172 * @p: the given software portal object.
174 * Return the settings in SWP_IIR register.
176 int qbman_swp_interrupt_get_inhibit(struct qbman_swp *p);
179 * qbman_swp_interrupt_set_inhibit() - Set the data in software portal
180 * interrupt inhibit register.
181 * @p: the given software portal object.
182 * @mask: The value to set in SWP_IIR register.
184 void qbman_swp_interrupt_set_inhibit(struct qbman_swp *p, int inhibit);
191 * struct qbman_result - structure for qbman dequeue response and/or
193 * @dont_manipulate_directly: the 16 32bit data to represent the whole
194 * possible qbman dequeue result.
196 struct qbman_result {
200 uint8_t reserved[63];
245 *A DQRI interrupt can be generated when there are dequeue results on the
246 * portal's DQRR (this mechanism does not deal with "pull" dequeues to
247 * user-supplied 'storage' addresses). There are two parameters to this
248 * interrupt source, one is a threshold and the other is a timeout. The
249 * interrupt will fire if either the fill-level of the ring exceeds 'thresh', or
250 * if the ring has been non-empty for been longer than 'timeout' nanoseconds.
251 * For timeout, an approximation to the desired nanosecond-granularity value is
252 * made, so there are get and set APIs to allow the user to see what actual
253 * timeout is set (compared to the timeout that was requested).
255 int qbman_swp_dequeue_thresh(struct qbman_swp *s, unsigned int thresh);
256 int qbman_swp_dequeue_set_timeout(struct qbman_swp *s, unsigned int timeout);
257 int qbman_swp_dequeue_get_timeout(struct qbman_swp *s, unsigned int *timeout);
259 /* ------------------- */
260 /* Push-mode dequeuing */
261 /* ------------------- */
263 /* The user of a portal can enable and disable push-mode dequeuing of up to 16
264 * channels independently. It does not specify this toggling by channel IDs, but
265 * rather by specifying the index (from 0 to 15) that has been mapped to the
270 * qbman_swp_push_get() - Get the push dequeue setup.
271 * @s: the software portal object.
272 * @channel_idx: the channel index to query.
273 * @enabled: returned boolean to show whether the push dequeue is enabled for
276 void qbman_swp_push_get(struct qbman_swp *s, uint8_t channel_idx, int *enabled);
279 * qbman_swp_push_set() - Enable or disable push dequeue.
280 * @s: the software portal object.
281 * @channel_idx: the channel index..
282 * @enable: enable or disable push dequeue.
284 * The user of a portal can enable and disable push-mode dequeuing of up to 16
285 * channels independently. It does not specify this toggling by channel IDs, but
286 * rather by specifying the index (from 0 to 15) that has been mapped to the
289 void qbman_swp_push_set(struct qbman_swp *s, uint8_t channel_idx, int enable);
291 /* ------------------- */
292 /* Pull-mode dequeuing */
293 /* ------------------- */
296 * struct qbman_pull_desc - the structure for pull dequeue descriptor
298 struct qbman_pull_desc {
300 uint32_t dont_manipulate_directly[16];
308 uint64_t rsp_addr_virt;
314 enum qbman_pull_type_e {
315 /* dequeue with priority precedence, respect intra-class scheduling */
316 qbman_pull_type_prio = 1,
317 /* dequeue with active FQ precedence, respect ICS */
318 qbman_pull_type_active,
319 /* dequeue with active FQ precedence, no ICS */
320 qbman_pull_type_active_noics
324 * qbman_pull_desc_clear() - Clear the contents of a descriptor to
325 * default/starting state.
326 * @d: the pull dequeue descriptor to be cleared.
328 void qbman_pull_desc_clear(struct qbman_pull_desc *d);
331 * qbman_pull_desc_set_storage()- Set the pull dequeue storage
332 * @d: the pull dequeue descriptor to be set.
333 * @storage: the pointer of the memory to store the dequeue result.
334 * @storage_phys: the physical address of the storage memory.
335 * @stash: to indicate whether write allocate is enabled.
337 * If not called, or if called with 'storage' as NULL, the result pull dequeues
338 * will produce results to DQRR. If 'storage' is non-NULL, then results are
339 * produced to the given memory location (using the physical/DMA address which
340 * the caller provides in 'storage_phys'), and 'stash' controls whether or not
341 * those writes to main-memory express a cache-warming attribute.
343 void qbman_pull_desc_set_storage(struct qbman_pull_desc *d,
344 struct qbman_result *storage,
345 uint64_t storage_phys,
348 * qbman_pull_desc_set_numframes() - Set the number of frames to be dequeued.
349 * @d: the pull dequeue descriptor to be set.
350 * @numframes: number of frames to be set, must be between 1 and 16, inclusive.
352 void qbman_pull_desc_set_numframes(struct qbman_pull_desc *d,
355 * qbman_pull_desc_set_token() - Set dequeue token for pull command
356 * @d: the dequeue descriptor
357 * @token: the token to be set
359 * token is the value that shows up in the dequeue response that can be used to
360 * detect when the results have been published. The easiest technique is to zero
361 * result "storage" before issuing a dequeue, and use any non-zero 'token' value
363 void qbman_pull_desc_set_token(struct qbman_pull_desc *d, uint8_t token);
365 /* Exactly one of the following descriptor "actions" should be set. (Calling any
366 * one of these will replace the effect of any prior call to one of these.)
367 * - pull dequeue from the given frame queue (FQ)
368 * - pull dequeue from any FQ in the given work queue (WQ)
369 * - pull dequeue from any FQ in any WQ in the given channel
372 * qbman_pull_desc_set_fq() - Set fqid from which the dequeue command dequeues.
373 * @fqid: the frame queue index of the given FQ.
375 void qbman_pull_desc_set_fq(struct qbman_pull_desc *d, uint32_t fqid);
378 * qbman_pull_desc_set_wq() - Set wqid from which the dequeue command dequeues.
379 * @wqid: composed of channel id and wqid within the channel.
380 * @dct: the dequeue command type.
382 void qbman_pull_desc_set_wq(struct qbman_pull_desc *d, uint32_t wqid,
383 enum qbman_pull_type_e dct);
385 /* qbman_pull_desc_set_channel() - Set channelid from which the dequeue command
387 * @chid: the channel id to be dequeued.
388 * @dct: the dequeue command type.
390 void qbman_pull_desc_set_channel(struct qbman_pull_desc *d, uint32_t chid,
391 enum qbman_pull_type_e dct);
394 * qbman_pull_desc_set_rad() - Decide whether reschedule the fq after dequeue
396 * @rad: 1 = Reschedule the FQ after dequeue.
397 * 0 = Allow the FQ to remain active after dequeue.
399 void qbman_pull_desc_set_rad(struct qbman_pull_desc *d, int rad);
402 * qbman_swp_pull() - Issue the pull dequeue command
403 * @s: the software portal object.
404 * @d: the software portal descriptor which has been configured with
405 * the set of qbman_pull_desc_set_*() calls.
407 * Return 0 for success, and -EBUSY if the software portal is not ready
408 * to do pull dequeue.
410 int qbman_swp_pull(struct qbman_swp *s, struct qbman_pull_desc *d);
412 /* -------------------------------- */
413 /* Polling DQRR for dequeue results */
414 /* -------------------------------- */
417 * qbman_swp_dqrr_next() - Get an valid DQRR entry.
418 * @s: the software portal object.
420 * Return NULL if there are no unconsumed DQRR entries. Return a DQRR entry
421 * only once, so repeated calls can return a sequence of DQRR entries, without
422 * requiring they be consumed immediately or in any particular order.
424 const struct qbman_result *qbman_swp_dqrr_next(struct qbman_swp *p);
427 * qbman_swp_prefetch_dqrr_next() - prefetch the next DQRR entry.
428 * @s: the software portal object.
430 void qbman_swp_prefetch_dqrr_next(struct qbman_swp *s);
433 * qbman_swp_dqrr_consume() - Consume DQRR entries previously returned from
434 * qbman_swp_dqrr_next().
435 * @s: the software portal object.
436 * @dq: the DQRR entry to be consumed.
438 void qbman_swp_dqrr_consume(struct qbman_swp *s, const struct qbman_result *dq);
441 * qbman_swp_dqrr_idx_consume() - Given the DQRR index consume the DQRR entry
442 * @s: the software portal object.
443 * @dqrr_index: the DQRR index entry to be consumed.
445 void qbman_swp_dqrr_idx_consume(struct qbman_swp *s, uint8_t dqrr_index);
448 * qbman_get_dqrr_idx() - Get dqrr index from the given dqrr
449 * @dqrr: the given dqrr object.
453 uint8_t qbman_get_dqrr_idx(const struct qbman_result *dqrr);
456 * qbman_get_dqrr_from_idx() - Use index to get the dqrr entry from the
458 * @s: the given portal.
459 * @idx: the dqrr index.
461 * Return dqrr entry object.
463 struct qbman_result *qbman_get_dqrr_from_idx(struct qbman_swp *s, uint8_t idx);
465 /* ------------------------------------------------- */
466 /* Polling user-provided storage for dequeue results */
467 /* ------------------------------------------------- */
470 * qbman_result_has_new_result() - Check and get the dequeue response from the
471 * dq storage memory set in pull dequeue command
472 * @s: the software portal object.
473 * @dq: the dequeue result read from the memory.
475 * Only used for user-provided storage of dequeue results, not DQRR. For
476 * efficiency purposes, the driver will perform any required endianness
477 * conversion to ensure that the user's dequeue result storage is in host-endian
478 * format (whether or not that is the same as the little-endian format that
479 * hardware DMA'd to the user's storage). As such, once the user has called
480 * qbman_result_has_new_result() and been returned a valid dequeue result,
481 * they should not call it again on the same memory location (except of course
482 * if another dequeue command has been executed to produce a new result to that
485 * Return 1 for getting a valid dequeue result, or 0 for not getting a valid
488 int qbman_result_has_new_result(struct qbman_swp *s,
489 struct qbman_result *dq);
492 * qbman_check_command_complete() - Check if the previous issued dq commnd
493 * is completed and results are available in memory.
494 * @s: the software portal object.
495 * @dq: the dequeue result read from the memory.
497 * Return 1 for getting a valid dequeue result, or 0 for not getting a valid
500 int qbman_check_command_complete(struct qbman_result *dq);
502 int qbman_check_new_result(struct qbman_result *dq);
504 /* -------------------------------------------------------- */
505 /* Parsing dequeue entries (DQRR and user-provided storage) */
506 /* -------------------------------------------------------- */
509 * qbman_result_is_DQ() - check the dequeue result is a dequeue response or not
510 * @dq: the dequeue result to be checked.
512 * DQRR entries may contain non-dequeue results, ie. notifications
514 int qbman_result_is_DQ(const struct qbman_result *dq);
517 * qbman_result_is_SCN() - Check the dequeue result is notification or not
518 * @dq: the dequeue result to be checked.
520 * All the non-dequeue results (FQDAN/CDAN/CSCN/...) are "state change
521 * notifications" of one type or another. Some APIs apply to all of them, of the
522 * form qbman_result_SCN_***().
524 static inline int qbman_result_is_SCN(const struct qbman_result *dq)
526 return !qbman_result_is_DQ(dq);
529 /* Recognise different notification types, only required if the user allows for
530 * these to occur, and cares about them when they do.
534 * qbman_result_is_FQDAN() - Check for FQ Data Availability
535 * @dq: the qbman_result object.
537 * Return 1 if this is FQDAN.
539 int qbman_result_is_FQDAN(const struct qbman_result *dq);
542 * qbman_result_is_CDAN() - Check for Channel Data Availability
543 * @dq: the qbman_result object to check.
545 * Return 1 if this is CDAN.
547 int qbman_result_is_CDAN(const struct qbman_result *dq);
550 * qbman_result_is_CSCN() - Check for Congestion State Change
551 * @dq: the qbman_result object to check.
553 * Return 1 if this is CSCN.
555 int qbman_result_is_CSCN(const struct qbman_result *dq);
558 * qbman_result_is_BPSCN() - Check for Buffer Pool State Change.
559 * @dq: the qbman_result object to check.
561 * Return 1 if this is BPSCN.
563 int qbman_result_is_BPSCN(const struct qbman_result *dq);
566 * qbman_result_is_CGCU() - Check for Congestion Group Count Update.
567 * @dq: the qbman_result object to check.
569 * Return 1 if this is CGCU.
571 int qbman_result_is_CGCU(const struct qbman_result *dq);
573 /* Frame queue state change notifications; (FQDAN in theory counts too as it
574 * leaves a FQ parked, but it is primarily a data availability notification)
578 * qbman_result_is_FQRN() - Check for FQ Retirement Notification.
579 * @dq: the qbman_result object to check.
581 * Return 1 if this is FQRN.
583 int qbman_result_is_FQRN(const struct qbman_result *dq);
586 * qbman_result_is_FQRNI() - Check for FQ Retirement Immediate
587 * @dq: the qbman_result object to check.
589 * Return 1 if this is FQRNI.
591 int qbman_result_is_FQRNI(const struct qbman_result *dq);
594 * qbman_result_is_FQPN() - Check for FQ Park Notification
595 * @dq: the qbman_result object to check.
597 * Return 1 if this is FQPN.
599 int qbman_result_is_FQPN(const struct qbman_result *dq);
601 /* Parsing frame dequeue results (qbman_result_is_DQ() must be TRUE)
604 #define QBMAN_DQ_STAT_FQEMPTY 0x80
606 #define QBMAN_DQ_STAT_HELDACTIVE 0x40
607 /* FQ force eligible */
608 #define QBMAN_DQ_STAT_FORCEELIGIBLE 0x20
610 #define QBMAN_DQ_STAT_VALIDFRAME 0x10
612 #define QBMAN_DQ_STAT_ODPVALID 0x04
613 /* Volatile dequeue */
614 #define QBMAN_DQ_STAT_VOLATILE 0x02
615 /* volatile dequeue command is expired */
616 #define QBMAN_DQ_STAT_EXPIRED 0x01
618 #define QBMAN_EQCR_DCA_IDXMASK 0x0f
619 #define QBMAN_ENQUEUE_FLAG_DCA (1ULL << 31)
622 * qbman_result_DQ_flags() - Get the STAT field of dequeue response
623 * @dq: the dequeue result.
625 * Return the state field.
627 uint8_t qbman_result_DQ_flags(const struct qbman_result *dq);
630 * qbman_result_DQ_is_pull() - Check whether the dq response is from a pull
632 * @dq: the dequeue result.
634 * Return 1 for volatile(pull) dequeue, 0 for static dequeue.
636 static inline int qbman_result_DQ_is_pull(const struct qbman_result *dq)
638 return (int)(qbman_result_DQ_flags(dq) & QBMAN_DQ_STAT_VOLATILE);
642 * qbman_result_DQ_is_pull_complete() - Check whether the pull command is
644 * @dq: the dequeue result.
648 static inline int qbman_result_DQ_is_pull_complete(
649 const struct qbman_result *dq)
651 return (int)(qbman_result_DQ_flags(dq) & QBMAN_DQ_STAT_EXPIRED);
655 * qbman_result_DQ_seqnum() - Get the seqnum field in dequeue response
656 * seqnum is valid only if VALIDFRAME flag is TRUE
657 * @dq: the dequeue result.
661 uint16_t qbman_result_DQ_seqnum(const struct qbman_result *dq);
664 * qbman_result_DQ_odpid() - Get the seqnum field in dequeue response
665 * odpid is valid only if ODPVAILD flag is TRUE.
666 * @dq: the dequeue result.
670 uint16_t qbman_result_DQ_odpid(const struct qbman_result *dq);
673 * qbman_result_DQ_fqid() - Get the fqid in dequeue response
674 * @dq: the dequeue result.
678 uint32_t qbman_result_DQ_fqid(const struct qbman_result *dq);
681 * qbman_result_DQ_byte_count() - Get the byte count in dequeue response
682 * @dq: the dequeue result.
684 * Return the byte count remaining in the FQ.
686 uint32_t qbman_result_DQ_byte_count(const struct qbman_result *dq);
689 * qbman_result_DQ_frame_count - Get the frame count in dequeue response
690 * @dq: the dequeue result.
692 * Return the frame count remaining in the FQ.
694 uint32_t qbman_result_DQ_frame_count(const struct qbman_result *dq);
697 * qbman_result_DQ_fqd_ctx() - Get the frame queue context in dequeue response
698 * @dq: the dequeue result.
700 * Return the frame queue context.
702 uint64_t qbman_result_DQ_fqd_ctx(const struct qbman_result *dq);
705 * qbman_result_DQ_fd() - Get the frame descriptor in dequeue response
706 * @dq: the dequeue result.
708 * Return the frame descriptor.
710 const struct qbman_fd *qbman_result_DQ_fd(const struct qbman_result *dq);
712 /* State-change notifications (FQDAN/CDAN/CSCN/...). */
715 * qbman_result_SCN_state() - Get the state field in State-change notification
716 * @scn: the state change notification.
718 * Return the state in the notifiation.
720 uint8_t qbman_result_SCN_state(const struct qbman_result *scn);
723 * qbman_result_SCN_rid() - Get the resource id from the notification
724 * @scn: the state change notification.
726 * Return the resource id.
728 uint32_t qbman_result_SCN_rid(const struct qbman_result *scn);
731 * qbman_result_SCN_ctx() - get the context from the notification
732 * @scn: the state change notification.
734 * Return the context.
736 uint64_t qbman_result_SCN_ctx(const struct qbman_result *scn);
738 /* Type-specific "resource IDs". Mainly for illustration purposes, though it
739 * also gives the appropriate type widths.
741 /* Get the FQID from the FQDAN */
742 #define qbman_result_FQDAN_fqid(dq) qbman_result_SCN_rid(dq)
743 /* Get the FQID from the FQRN */
744 #define qbman_result_FQRN_fqid(dq) qbman_result_SCN_rid(dq)
745 /* Get the FQID from the FQRNI */
746 #define qbman_result_FQRNI_fqid(dq) qbman_result_SCN_rid(dq)
747 /* Get the FQID from the FQPN */
748 #define qbman_result_FQPN_fqid(dq) qbman_result_SCN_rid(dq)
749 /* Get the channel ID from the CDAN */
750 #define qbman_result_CDAN_cid(dq) ((uint16_t)qbman_result_SCN_rid(dq))
751 /* Get the CGID from the CSCN */
752 #define qbman_result_CSCN_cgid(dq) ((uint16_t)qbman_result_SCN_rid(dq))
755 * qbman_result_bpscn_bpid() - Get the bpid from BPSCN
756 * @scn: the state change notification.
758 * Return the buffer pool id.
760 uint16_t qbman_result_bpscn_bpid(const struct qbman_result *scn);
763 * qbman_result_bpscn_has_free_bufs() - Check whether there are free
764 * buffers in the pool from BPSCN.
765 * @scn: the state change notification.
767 * Return the number of free buffers.
769 int qbman_result_bpscn_has_free_bufs(const struct qbman_result *scn);
772 * qbman_result_bpscn_is_depleted() - Check BPSCN to see whether the
773 * buffer pool is depleted.
774 * @scn: the state change notification.
776 * Return the status of buffer pool depletion.
778 int qbman_result_bpscn_is_depleted(const struct qbman_result *scn);
781 * qbman_result_bpscn_is_surplus() - Check BPSCN to see whether the buffer
782 * pool is surplus or not.
783 * @scn: the state change notification.
785 * Return the status of buffer pool surplus.
787 int qbman_result_bpscn_is_surplus(const struct qbman_result *scn);
790 * qbman_result_bpscn_ctx() - Get the BPSCN CTX from BPSCN message
791 * @scn: the state change notification.
793 * Return the BPSCN context.
795 uint64_t qbman_result_bpscn_ctx(const struct qbman_result *scn);
799 * qbman_result_cgcu_cgid() - Check CGCU resouce id, i.e. cgid
800 * @scn: the state change notification.
802 * Return the CGCU resource id.
804 uint16_t qbman_result_cgcu_cgid(const struct qbman_result *scn);
807 * qbman_result_cgcu_icnt() - Get the I_CNT from CGCU
808 * @scn: the state change notification.
810 * Return instantaneous count in the CGCU notification.
812 uint64_t qbman_result_cgcu_icnt(const struct qbman_result *scn);
817 /* struct qbman_eq_desc - structure of enqueue descriptor */
818 struct qbman_eq_desc {
820 uint32_t dont_manipulate_directly[8];
840 * struct qbman_eq_response - structure of enqueue response
841 * @dont_manipulate_directly: the 16 32bit data to represent the whole
844 struct qbman_eq_response {
845 uint32_t dont_manipulate_directly[16];
849 * qbman_eq_desc_clear() - Clear the contents of a descriptor to
850 * default/starting state.
851 * @d: the given enqueue descriptor.
853 void qbman_eq_desc_clear(struct qbman_eq_desc *d);
855 /* Exactly one of the following descriptor "actions" should be set. (Calling
856 * any one of these will replace the effect of any prior call to one of these.)
857 * - enqueue without order-restoration
858 * - enqueue with order-restoration
859 * - fill a hole in the order-restoration sequence, without any enqueue
860 * - advance NESN (Next Expected Sequence Number), without any enqueue
861 * 'respond_success' indicates whether an enqueue response should be DMA'd
862 * after success (otherwise a response is DMA'd only after failure).
863 * 'incomplete' indicates that other fragments of the same 'seqnum' are yet to
868 * qbman_eq_desc_set_no_orp() - Set enqueue descriptor without orp
869 * @d: the enqueue descriptor.
870 * @response_success: 1 = enqueue with response always; 0 = enqueue with
871 * rejections returned on a FQ.
873 void qbman_eq_desc_set_no_orp(struct qbman_eq_desc *d, int respond_success);
875 * qbman_eq_desc_set_orp() - Set order-resotration in the enqueue descriptor
876 * @d: the enqueue descriptor.
877 * @response_success: 1 = enqueue with response always; 0 = enqueue with
878 * rejections returned on a FQ.
879 * @opr_id: the order point record id.
880 * @seqnum: the order restoration sequence number.
881 * @incomplete: indiates whether this is the last fragments using the same
884 void qbman_eq_desc_set_orp(struct qbman_eq_desc *d, int respond_success,
885 uint16_t opr_id, uint16_t seqnum, int incomplete);
888 * qbman_eq_desc_set_orp_hole() - fill a hole in the order-restoration sequence
889 * without any enqueue
890 * @d: the enqueue descriptor.
891 * @opr_id: the order point record id.
892 * @seqnum: the order restoration sequence number.
894 void qbman_eq_desc_set_orp_hole(struct qbman_eq_desc *d, uint16_t opr_id,
898 * qbman_eq_desc_set_orp_nesn() - advance NESN (Next Expected Sequence Number)
899 * without any enqueue
900 * @d: the enqueue descriptor.
901 * @opr_id: the order point record id.
902 * @seqnum: the order restoration sequence number.
904 void qbman_eq_desc_set_orp_nesn(struct qbman_eq_desc *d, uint16_t opr_id,
907 * qbman_eq_desc_set_response() - Set the enqueue response info.
908 * @d: the enqueue descriptor
909 * @storage_phys: the physical address of the enqueue response in memory.
910 * @stash: indicate that the write allocation enabled or not.
912 * In the case where an enqueue response is DMA'd, this determines where that
913 * response should go. (The physical/DMA address is given for hardware's
914 * benefit, but software should interpret it as a "struct qbman_eq_response"
915 * data structure.) 'stash' controls whether or not the write to main-memory
916 * expresses a cache-warming attribute.
918 void qbman_eq_desc_set_response(struct qbman_eq_desc *d,
919 uint64_t storage_phys,
923 * qbman_eq_desc_set_token() - Set token for the enqueue command
924 * @d: the enqueue descriptor
925 * @token: the token to be set.
927 * token is the value that shows up in an enqueue response that can be used to
928 * detect when the results have been published. The easiest technique is to zero
929 * result "storage" before issuing an enqueue, and use any non-zero 'token'
932 void qbman_eq_desc_set_token(struct qbman_eq_desc *d, uint8_t token);
935 * Exactly one of the following descriptor "targets" should be set. (Calling any
936 * one of these will replace the effect of any prior call to one of these.)
937 * - enqueue to a frame queue
938 * - enqueue to a queuing destination
939 * Note, that none of these will have any affect if the "action" type has been
940 * set to "orp_hole" or "orp_nesn".
943 * qbman_eq_desc_set_fq() - Set Frame Queue id for the enqueue command
944 * @d: the enqueue descriptor
945 * @fqid: the id of the frame queue to be enqueued.
947 void qbman_eq_desc_set_fq(struct qbman_eq_desc *d, uint32_t fqid);
950 * qbman_eq_desc_set_qd() - Set Queuing Destination for the enqueue command.
951 * @d: the enqueue descriptor
952 * @qdid: the id of the queuing destination to be enqueued.
953 * @qd_bin: the queuing destination bin
954 * @qd_prio: the queuing destination priority.
956 void qbman_eq_desc_set_qd(struct qbman_eq_desc *d, uint32_t qdid,
957 uint16_t qd_bin, uint8_t qd_prio);
960 * qbman_eq_desc_set_eqdi() - enable/disable EQDI interrupt
961 * @d: the enqueue descriptor
962 * @enable: boolean to enable/disable EQDI
964 * Determines whether or not the portal's EQDI interrupt source should be
965 * asserted after the enqueue command is completed.
967 void qbman_eq_desc_set_eqdi(struct qbman_eq_desc *d, int enable);
970 * qbman_eq_desc_set_dca() - Set DCA mode in the enqueue command.
971 * @d: the enqueue descriptor.
972 * @enable: enabled/disable DCA mode.
973 * @dqrr_idx: DCAP_CI, the DCAP consumer index.
974 * @park: determine the whether park the FQ or not
976 * Determines whether or not a portal DQRR entry should be consumed once the
977 * enqueue command is completed. (And if so, and the DQRR entry corresponds to a
978 * held-active (order-preserving) FQ, whether the FQ should be parked instead of
979 * being rescheduled.)
981 void qbman_eq_desc_set_dca(struct qbman_eq_desc *d, int enable,
982 uint8_t dqrr_idx, int park);
985 * qbman_result_eqresp_fd() - Get fd from enqueue response.
986 * @eqresp: enqueue response.
988 * Return the fd pointer.
990 struct qbman_fd *qbman_result_eqresp_fd(struct qbman_result *eqresp);
993 * qbman_result_eqresp_set_rspid() - Set the response id in enqueue response.
994 * @eqresp: enqueue response.
995 * @val: values to set into the response id.
997 * This value is set into the response id before the enqueue command, which,
998 * get overwritten by qbman once the enqueue command is complete.
1000 void qbman_result_eqresp_set_rspid(struct qbman_result *eqresp, uint8_t val);
1003 * qbman_result_eqresp_rspid() - Get the response id.
1004 * @eqresp: enqueue response.
1006 * Return the response id.
1008 * At the time of enqueue user provides the response id. Response id gets
1009 * copied into the enqueue response to determine if the command has been
1010 * completed, and response has been updated.
1012 uint8_t qbman_result_eqresp_rspid(struct qbman_result *eqresp);
1015 * qbman_result_eqresp_rc() - determines if enqueue command is sucessful.
1016 * @eqresp: enqueue response.
1018 * Return 0 when command is sucessful.
1020 uint8_t qbman_result_eqresp_rc(struct qbman_result *eqresp);
1023 * qbman_swp_enqueue() - Issue an enqueue command.
1024 * @s: the software portal used for enqueue.
1025 * @d: the enqueue descriptor.
1026 * @fd: the frame descriptor to be enqueued.
1028 * Please note that 'fd' should only be NULL if the "action" of the
1029 * descriptor is "orp_hole" or "orp_nesn".
1031 * Return 0 for a successful enqueue, -EBUSY if the EQCR is not ready.
1033 int qbman_swp_enqueue(struct qbman_swp *s, const struct qbman_eq_desc *d,
1034 const struct qbman_fd *fd);
1036 * qbman_swp_enqueue_multiple() - Enqueue multiple frames with same
1038 * @s: the software portal used for enqueue.
1039 * @d: the enqueue descriptor.
1040 * @fd: the frame descriptor to be enqueued.
1041 * @flags: bit-mask of QBMAN_ENQUEUE_FLAG_*** options
1042 * @num_frames: the number of the frames to be enqueued.
1044 * Return the number of enqueued frames, -EBUSY if the EQCR is not ready.
1046 int qbman_swp_enqueue_multiple(struct qbman_swp *s,
1047 const struct qbman_eq_desc *d,
1048 const struct qbman_fd *fd,
1053 * qbman_swp_enqueue_multiple_fd() - Enqueue multiple frames with same
1055 * @s: the software portal used for enqueue.
1056 * @d: the enqueue descriptor.
1057 * @fd: the frame descriptor to be enqueued.
1058 * @flags: bit-mask of QBMAN_ENQUEUE_FLAG_*** options
1059 * @num_frames: the number of the frames to be enqueued.
1061 * Return the number of enqueued frames, -EBUSY if the EQCR is not ready.
1063 int qbman_swp_enqueue_multiple_fd(struct qbman_swp *s,
1064 const struct qbman_eq_desc *d,
1065 struct qbman_fd **fd,
1070 * qbman_swp_enqueue_multiple_desc() - Enqueue multiple frames with
1071 * individual eq descriptor.
1072 * @s: the software portal used for enqueue.
1073 * @d: the enqueue descriptor.
1074 * @fd: the frame descriptor to be enqueued.
1075 * @num_frames: the number of the frames to be enqueued.
1077 * Return the number of enqueued frames, -EBUSY if the EQCR is not ready.
1079 int qbman_swp_enqueue_multiple_desc(struct qbman_swp *s,
1080 const struct qbman_eq_desc *d,
1081 const struct qbman_fd *fd,
1085 * qbman_swp_enqueue_thresh() - Set threshold for EQRI interrupt.
1086 * @s: the software portal.
1087 * @thresh: the threshold to trigger the EQRI interrupt.
1089 * An EQRI interrupt can be generated when the fill-level of EQCR falls below
1090 * the 'thresh' value set here. Setting thresh==0 (the default) disables.
1092 int qbman_swp_enqueue_thresh(struct qbman_swp *s, unsigned int thresh);
1094 /*******************/
1095 /* Buffer releases */
1096 /*******************/
1098 * struct qbman_release_desc - The structure for buffer release descriptor
1099 * @dont_manipulate_directly: the 32bit data to represent the whole
1100 * possible settings of qbman release descriptor.
1102 struct qbman_release_desc {
1104 uint32_t dont_manipulate_directly[16];
1116 * qbman_release_desc_clear() - Clear the contents of a descriptor to
1117 * default/starting state.
1118 * @d: the qbman release descriptor.
1120 void qbman_release_desc_clear(struct qbman_release_desc *d);
1123 * qbman_release_desc_set_bpid() - Set the ID of the buffer pool to release to
1124 * @d: the qbman release descriptor.
1126 void qbman_release_desc_set_bpid(struct qbman_release_desc *d, uint16_t bpid);
1129 * qbman_release_desc_set_rcdi() - Determines whether or not the portal's RCDI
1130 * interrupt source should be asserted after the release command is completed.
1131 * @d: the qbman release descriptor.
1133 void qbman_release_desc_set_rcdi(struct qbman_release_desc *d, int enable);
1136 * qbman_swp_release() - Issue a buffer release command.
1137 * @s: the software portal object.
1138 * @d: the release descriptor.
1139 * @buffers: a pointer pointing to the buffer address to be released.
1140 * @num_buffers: number of buffers to be released, must be less than 8.
1142 * Return 0 for success, -EBUSY if the release command ring is not ready.
1144 int qbman_swp_release(struct qbman_swp *s, const struct qbman_release_desc *d,
1145 const uint64_t *buffers, unsigned int num_buffers);
1148 * qbman_swp_release_thresh() - Set threshold for RCRI interrupt
1149 * @s: the software portal.
1150 * @thresh: the threshold.
1151 * An RCRI interrupt can be generated when the fill-level of RCR falls below
1152 * the 'thresh' value set here. Setting thresh==0 (the default) disables.
1154 int qbman_swp_release_thresh(struct qbman_swp *s, unsigned int thresh);
1156 /*******************/
1157 /* Buffer acquires */
1158 /*******************/
1160 * qbman_swp_acquire() - Issue a buffer acquire command.
1161 * @s: the software portal object.
1162 * @bpid: the buffer pool index.
1163 * @buffers: a pointer pointing to the acquired buffer address|es.
1164 * @num_buffers: number of buffers to be acquired, must be less than 8.
1166 * Return 0 for success, or negative error code if the acquire command
1169 int qbman_swp_acquire(struct qbman_swp *s, uint16_t bpid, uint64_t *buffers,
1170 unsigned int num_buffers);
1176 * qbman_swp_fq_schedule() - Move the fq to the scheduled state.
1177 * @s: the software portal object.
1178 * @fqid: the index of frame queue to be scheduled.
1180 * There are a couple of different ways that a FQ can end up parked state,
1181 * This schedules it.
1183 * Return 0 for success, or negative error code for failure.
1185 int qbman_swp_fq_schedule(struct qbman_swp *s, uint32_t fqid);
1188 * qbman_swp_fq_force() - Force the FQ to fully scheduled state.
1189 * @s: the software portal object.
1190 * @fqid: the index of frame queue to be forced.
1192 * Force eligible will force a tentatively-scheduled FQ to be fully-scheduled
1193 * and thus be available for selection by any channel-dequeuing behaviour (push
1194 * or pull). If the FQ is subsequently "dequeued" from the channel and is still
1195 * empty at the time this happens, the resulting dq_entry will have no FD.
1196 * (qbman_result_DQ_fd() will return NULL.)
1198 * Return 0 for success, or negative error code for failure.
1200 int qbman_swp_fq_force(struct qbman_swp *s, uint32_t fqid);
1203 * These functions change the FQ flow-control stuff between XON/XOFF. (The
1204 * default is XON.) This setting doesn't affect enqueues to the FQ, just
1205 * dequeues. XOFF FQs will remain in the tenatively-scheduled state, even when
1206 * non-empty, meaning they won't be selected for scheduled dequeuing. If a FQ is
1207 * changed to XOFF after it had already become truly-scheduled to a channel, and
1208 * a pull dequeue of that channel occurs that selects that FQ for dequeuing,
1209 * then the resulting dq_entry will have no FD. (qbman_result_DQ_fd() will
1213 * qbman_swp_fq_xon() - XON the frame queue.
1214 * @s: the software portal object.
1215 * @fqid: the index of frame queue.
1217 * Return 0 for success, or negative error code for failure.
1219 int qbman_swp_fq_xon(struct qbman_swp *s, uint32_t fqid);
1221 * qbman_swp_fq_xoff() - XOFF the frame queue.
1222 * @s: the software portal object.
1223 * @fqid: the index of frame queue.
1225 * Return 0 for success, or negative error code for failure.
1227 int qbman_swp_fq_xoff(struct qbman_swp *s, uint32_t fqid);
1229 /**********************/
1230 /* Channel management */
1231 /**********************/
1234 * If the user has been allocated a channel object that is going to generate
1235 * CDANs to another channel, then these functions will be necessary.
1236 * CDAN-enabled channels only generate a single CDAN notification, after which
1237 * it they need to be reenabled before they'll generate another. (The idea is
1238 * that pull dequeuing will occur in reaction to the CDAN, followed by a
1239 * reenable step.) Each function generates a distinct command to hardware, so a
1240 * combination function is provided if the user wishes to modify the "context"
1241 * (which shows up in each CDAN message) each time they reenable, as a single
1242 * command to hardware.
1246 * qbman_swp_CDAN_set_context() - Set CDAN context
1247 * @s: the software portal object.
1248 * @channelid: the channel index.
1249 * @ctx: the context to be set in CDAN.
1251 * Return 0 for success, or negative error code for failure.
1253 int qbman_swp_CDAN_set_context(struct qbman_swp *s, uint16_t channelid,
1257 * qbman_swp_CDAN_enable() - Enable CDAN for the channel.
1258 * @s: the software portal object.
1259 * @channelid: the index of the channel to generate CDAN.
1261 * Return 0 for success, or negative error code for failure.
1263 int qbman_swp_CDAN_enable(struct qbman_swp *s, uint16_t channelid);
1266 * qbman_swp_CDAN_disable() - disable CDAN for the channel.
1267 * @s: the software portal object.
1268 * @channelid: the index of the channel to generate CDAN.
1270 * Return 0 for success, or negative error code for failure.
1272 int qbman_swp_CDAN_disable(struct qbman_swp *s, uint16_t channelid);
1275 * qbman_swp_CDAN_set_context_enable() - Set CDAN contest and enable CDAN
1276 * @s: the software portal object.
1277 * @channelid: the index of the channel to generate CDAN.
1278 * @ctx: the context set in CDAN.
1280 * Return 0 for success, or negative error code for failure.
1282 int qbman_swp_CDAN_set_context_enable(struct qbman_swp *s, uint16_t channelid,
1284 #endif /* !_FSL_QBMAN_PORTAL_H */