1 /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
3 * Copyright 2014-2016 Freescale Semiconductor Inc.
7 #ifndef __FSL_DPAA2_GLOBAL_H
8 #define __FSL_DPAA2_GLOBAL_H
10 #include <linux/types.h>
11 #include <linux/cpumask.h>
45 /* Parsing frame dequeue results */
47 #define DPAA2_DQ_STAT_FQEMPTY 0x80
49 #define DPAA2_DQ_STAT_HELDACTIVE 0x40
50 /* FQ force eligible */
51 #define DPAA2_DQ_STAT_FORCEELIGIBLE 0x20
53 #define DPAA2_DQ_STAT_VALIDFRAME 0x10
55 #define DPAA2_DQ_STAT_ODPVALID 0x04
56 /* volatile dequeue */
57 #define DPAA2_DQ_STAT_VOLATILE 0x02
58 /* volatile dequeue command is expired */
59 #define DPAA2_DQ_STAT_EXPIRED 0x01
61 #define DQ_FQID_MASK 0x00FFFFFF
62 #define DQ_FRAME_COUNT_MASK 0x00FFFFFF
65 * dpaa2_dq_flags() - Get the stat field of dequeue response
66 * @dq: the dequeue result.
68 static inline u32
dpaa2_dq_flags(const struct dpaa2_dq
*dq
)
74 * dpaa2_dq_is_pull() - Check whether the dq response is from a pull
76 * @dq: the dequeue result
78 * Return 1 for volatile(pull) dequeue, 0 for static dequeue.
80 static inline int dpaa2_dq_is_pull(const struct dpaa2_dq
*dq
)
82 return (int)(dpaa2_dq_flags(dq
) & DPAA2_DQ_STAT_VOLATILE
);
86 * dpaa2_dq_is_pull_complete() - Check whether the pull command is completed.
87 * @dq: the dequeue result
91 static inline bool dpaa2_dq_is_pull_complete(const struct dpaa2_dq
*dq
)
93 return !!(dpaa2_dq_flags(dq
) & DPAA2_DQ_STAT_EXPIRED
);
97 * dpaa2_dq_seqnum() - Get the seqnum field in dequeue response
98 * @dq: the dequeue result
100 * seqnum is valid only if VALIDFRAME flag is TRUE
104 static inline u16
dpaa2_dq_seqnum(const struct dpaa2_dq
*dq
)
106 return le16_to_cpu(dq
->dq
.seqnum
);
110 * dpaa2_dq_odpid() - Get the odpid field in dequeue response
111 * @dq: the dequeue result
113 * odpid is valid only if ODPVALID flag is TRUE.
117 static inline u16
dpaa2_dq_odpid(const struct dpaa2_dq
*dq
)
119 return le16_to_cpu(dq
->dq
.oprid
);
123 * dpaa2_dq_fqid() - Get the fqid in dequeue response
124 * @dq: the dequeue result
128 static inline u32
dpaa2_dq_fqid(const struct dpaa2_dq
*dq
)
130 return le32_to_cpu(dq
->dq
.fqid
) & DQ_FQID_MASK
;
134 * dpaa2_dq_byte_count() - Get the byte count in dequeue response
135 * @dq: the dequeue result
137 * Return the byte count remaining in the FQ.
139 static inline u32
dpaa2_dq_byte_count(const struct dpaa2_dq
*dq
)
141 return le32_to_cpu(dq
->dq
.fq_byte_cnt
);
145 * dpaa2_dq_frame_count() - Get the frame count in dequeue response
146 * @dq: the dequeue result
148 * Return the frame count remaining in the FQ.
150 static inline u32
dpaa2_dq_frame_count(const struct dpaa2_dq
*dq
)
152 return le32_to_cpu(dq
->dq
.fq_frm_cnt
) & DQ_FRAME_COUNT_MASK
;
156 * dpaa2_dq_fd_ctx() - Get the frame queue context in dequeue response
157 * @dq: the dequeue result
159 * Return the frame queue context.
161 static inline u64
dpaa2_dq_fqd_ctx(const struct dpaa2_dq
*dq
)
163 return le64_to_cpu(dq
->dq
.fqd_ctx
);
167 * dpaa2_dq_fd() - Get the frame descriptor in dequeue response
168 * @dq: the dequeue result
170 * Return the frame descriptor.
172 static inline const struct dpaa2_fd
*dpaa2_dq_fd(const struct dpaa2_dq
*dq
)
174 return (const struct dpaa2_fd
*)&dq
->dq
.fd
[0];
177 #define DPAA2_CSCN_SIZE sizeof(struct dpaa2_dq)
178 #define DPAA2_CSCN_ALIGN 16
179 #define DPAA2_CSCN_STATE_CG BIT(0)
182 * dpaa2_cscn_state_congested() - Check congestion state
183 * @cscn: congestion SCN (delivered to WQ or memory)
185 i * Return true is congested.
187 static inline bool dpaa2_cscn_state_congested(struct dpaa2_dq
*cscn
)
189 return !!(cscn
->scn
.state
& DPAA2_CSCN_STATE_CG
);
192 #endif /* __FSL_DPAA2_GLOBAL_H */