Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
0002 /*
0003  * Copyright 2014-2016 Freescale Semiconductor Inc.
0004  * Copyright 2016 NXP
0005  *
0006  */
0007 #ifndef __FSL_DPAA2_GLOBAL_H
0008 #define __FSL_DPAA2_GLOBAL_H
0009 
0010 #include <linux/types.h>
0011 #include <linux/cpumask.h>
0012 #include "dpaa2-fd.h"
0013 
0014 struct dpaa2_dq {
0015     union {
0016         struct common {
0017             u8 verb;
0018             u8 reserved[63];
0019         } common;
0020         struct dq {
0021             u8 verb;
0022             u8 stat;
0023             __le16 seqnum;
0024             __le16 oprid;
0025             u8 reserved;
0026             u8 tok;
0027             __le32 fqid;
0028             u32 reserved2;
0029             __le32 fq_byte_cnt;
0030             __le32 fq_frm_cnt;
0031             __le64 fqd_ctx;
0032             u8 fd[32];
0033         } dq;
0034         struct scn {
0035             u8 verb;
0036             u8 stat;
0037             u8 state;
0038             u8 reserved;
0039             __le32 rid_tok;
0040             __le64 ctx;
0041         } scn;
0042     };
0043 };
0044 
0045 /* Parsing frame dequeue results */
0046 /* FQ empty */
0047 #define DPAA2_DQ_STAT_FQEMPTY       0x80
0048 /* FQ held active */
0049 #define DPAA2_DQ_STAT_HELDACTIVE    0x40
0050 /* FQ force eligible */
0051 #define DPAA2_DQ_STAT_FORCEELIGIBLE 0x20
0052 /* valid frame */
0053 #define DPAA2_DQ_STAT_VALIDFRAME    0x10
0054 /* FQ ODP enable */
0055 #define DPAA2_DQ_STAT_ODPVALID      0x04
0056 /* volatile dequeue */
0057 #define DPAA2_DQ_STAT_VOLATILE      0x02
0058 /* volatile dequeue command is expired */
0059 #define DPAA2_DQ_STAT_EXPIRED       0x01
0060 
0061 #define DQ_FQID_MASK        0x00FFFFFF
0062 #define DQ_FRAME_COUNT_MASK 0x00FFFFFF
0063 
0064 /**
0065  * dpaa2_dq_flags() - Get the stat field of dequeue response
0066  * @dq: the dequeue result.
0067  */
0068 static inline u32 dpaa2_dq_flags(const struct dpaa2_dq *dq)
0069 {
0070     return dq->dq.stat;
0071 }
0072 
0073 /**
0074  * dpaa2_dq_is_pull() - Check whether the dq response is from a pull
0075  *                      command.
0076  * @dq: the dequeue result
0077  *
0078  * Return 1 for volatile(pull) dequeue, 0 for static dequeue.
0079  */
0080 static inline int dpaa2_dq_is_pull(const struct dpaa2_dq *dq)
0081 {
0082     return (int)(dpaa2_dq_flags(dq) & DPAA2_DQ_STAT_VOLATILE);
0083 }
0084 
0085 /**
0086  * dpaa2_dq_is_pull_complete() - Check whether the pull command is completed.
0087  * @dq: the dequeue result
0088  *
0089  * Return boolean.
0090  */
0091 static inline bool dpaa2_dq_is_pull_complete(const struct dpaa2_dq *dq)
0092 {
0093     return !!(dpaa2_dq_flags(dq) & DPAA2_DQ_STAT_EXPIRED);
0094 }
0095 
0096 /**
0097  * dpaa2_dq_seqnum() - Get the seqnum field in dequeue response
0098  * @dq: the dequeue result
0099  *
0100  * seqnum is valid only if VALIDFRAME flag is TRUE
0101  *
0102  * Return seqnum.
0103  */
0104 static inline u16 dpaa2_dq_seqnum(const struct dpaa2_dq *dq)
0105 {
0106     return le16_to_cpu(dq->dq.seqnum);
0107 }
0108 
0109 /**
0110  * dpaa2_dq_odpid() - Get the odpid field in dequeue response
0111  * @dq: the dequeue result
0112  *
0113  * odpid is valid only if ODPVALID flag is TRUE.
0114  *
0115  * Return odpid.
0116  */
0117 static inline u16 dpaa2_dq_odpid(const struct dpaa2_dq *dq)
0118 {
0119     return le16_to_cpu(dq->dq.oprid);
0120 }
0121 
0122 /**
0123  * dpaa2_dq_fqid() - Get the fqid in dequeue response
0124  * @dq: the dequeue result
0125  *
0126  * Return fqid.
0127  */
0128 static inline u32 dpaa2_dq_fqid(const struct dpaa2_dq *dq)
0129 {
0130     return le32_to_cpu(dq->dq.fqid) & DQ_FQID_MASK;
0131 }
0132 
0133 /**
0134  * dpaa2_dq_byte_count() - Get the byte count in dequeue response
0135  * @dq: the dequeue result
0136  *
0137  * Return the byte count remaining in the FQ.
0138  */
0139 static inline u32 dpaa2_dq_byte_count(const struct dpaa2_dq *dq)
0140 {
0141     return le32_to_cpu(dq->dq.fq_byte_cnt);
0142 }
0143 
0144 /**
0145  * dpaa2_dq_frame_count() - Get the frame count in dequeue response
0146  * @dq: the dequeue result
0147  *
0148  * Return the frame count remaining in the FQ.
0149  */
0150 static inline u32 dpaa2_dq_frame_count(const struct dpaa2_dq *dq)
0151 {
0152     return le32_to_cpu(dq->dq.fq_frm_cnt) & DQ_FRAME_COUNT_MASK;
0153 }
0154 
0155 /**
0156  * dpaa2_dq_fd_ctx() - Get the frame queue context in dequeue response
0157  * @dq: the dequeue result
0158  *
0159  * Return the frame queue context.
0160  */
0161 static inline u64 dpaa2_dq_fqd_ctx(const struct dpaa2_dq *dq)
0162 {
0163     return le64_to_cpu(dq->dq.fqd_ctx);
0164 }
0165 
0166 /**
0167  * dpaa2_dq_fd() - Get the frame descriptor in dequeue response
0168  * @dq: the dequeue result
0169  *
0170  * Return the frame descriptor.
0171  */
0172 static inline const struct dpaa2_fd *dpaa2_dq_fd(const struct dpaa2_dq *dq)
0173 {
0174     return (const struct dpaa2_fd *)&dq->dq.fd[0];
0175 }
0176 
0177 #define DPAA2_CSCN_SIZE     sizeof(struct dpaa2_dq)
0178 #define DPAA2_CSCN_ALIGN    16
0179 #define DPAA2_CSCN_STATE_CG BIT(0)
0180 
0181 /**
0182  * dpaa2_cscn_state_congested() - Check congestion state
0183  * @cscn: congestion SCN (delivered to WQ or memory)
0184  *
0185 i * Return true is congested.
0186  */
0187 static inline bool dpaa2_cscn_state_congested(struct dpaa2_dq *cscn)
0188 {
0189     return !!(cscn->scn.state & DPAA2_CSCN_STATE_CG);
0190 }
0191 
0192 #endif /* __FSL_DPAA2_GLOBAL_H */