GNU Linux-libre 4.14.328-gnu1
[releases.git] / drivers / staging / fsl-mc / include / dpaa2-global.h
1 /*
2  * Copyright 2014-2016 Freescale Semiconductor Inc.
3  * Copyright 2016 NXP
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *     * Redistributions of source code must retain the above copyright
8  *       notice, this list of conditions and the following disclaimer.
9  *     * Redistributions in binary form must reproduce the above copyright
10  *       notice, this list of conditions and the following disclaimer in the
11  *       documentation and/or other materials provided with the distribution.
12  *     * Neither the name of Freescale Semiconductor nor the
13  *       names of its contributors may be used to endorse or promote products
14  *       derived from this software without specific prior written permission.
15  *
16  * ALTERNATIVELY, this software may be distributed under the terms of the
17  * GNU General Public License ("GPL") as published by the Free Software
18  * Foundation, either version 2 of that License or (at your option) any
19  * later version.
20  *
21  * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
22  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24  * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
25  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 #ifndef __FSL_DPAA2_GLOBAL_H
33 #define __FSL_DPAA2_GLOBAL_H
34
35 #include <linux/types.h>
36 #include <linux/cpumask.h>
37 #include "dpaa2-fd.h"
38
39 struct dpaa2_dq {
40         union {
41                 struct common {
42                         u8 verb;
43                         u8 reserved[63];
44                 } common;
45                 struct dq {
46                         u8 verb;
47                         u8 stat;
48                         __le16 seqnum;
49                         __le16 oprid;
50                         u8 reserved;
51                         u8 tok;
52                         __le32 fqid;
53                         u32 reserved2;
54                         __le32 fq_byte_cnt;
55                         __le32 fq_frm_cnt;
56                         __le64 fqd_ctx;
57                         u8 fd[32];
58                 } dq;
59                 struct scn {
60                         u8 verb;
61                         u8 stat;
62                         u8 state;
63                         u8 reserved;
64                         __le32 rid_tok;
65                         __le64 ctx;
66                 } scn;
67         };
68 };
69
70 /* Parsing frame dequeue results */
71 /* FQ empty */
72 #define DPAA2_DQ_STAT_FQEMPTY       0x80
73 /* FQ held active */
74 #define DPAA2_DQ_STAT_HELDACTIVE    0x40
75 /* FQ force eligible */
76 #define DPAA2_DQ_STAT_FORCEELIGIBLE 0x20
77 /* valid frame */
78 #define DPAA2_DQ_STAT_VALIDFRAME    0x10
79 /* FQ ODP enable */
80 #define DPAA2_DQ_STAT_ODPVALID      0x04
81 /* volatile dequeue */
82 #define DPAA2_DQ_STAT_VOLATILE      0x02
83 /* volatile dequeue command is expired */
84 #define DPAA2_DQ_STAT_EXPIRED       0x01
85
86 #define DQ_FQID_MASK            0x00FFFFFF
87 #define DQ_FRAME_COUNT_MASK     0x00FFFFFF
88
89 /**
90  * dpaa2_dq_flags() - Get the stat field of dequeue response
91  * @dq: the dequeue result.
92  */
93 static inline u32 dpaa2_dq_flags(const struct dpaa2_dq *dq)
94 {
95         return dq->dq.stat;
96 }
97
98 /**
99  * dpaa2_dq_is_pull() - Check whether the dq response is from a pull
100  *                      command.
101  * @dq: the dequeue result
102  *
103  * Return 1 for volatile(pull) dequeue, 0 for static dequeue.
104  */
105 static inline int dpaa2_dq_is_pull(const struct dpaa2_dq *dq)
106 {
107         return (int)(dpaa2_dq_flags(dq) & DPAA2_DQ_STAT_VOLATILE);
108 }
109
110 /**
111  * dpaa2_dq_is_pull_complete() - Check whether the pull command is completed.
112  * @dq: the dequeue result
113  *
114  * Return boolean.
115  */
116 static inline bool dpaa2_dq_is_pull_complete(const struct dpaa2_dq *dq)
117 {
118         return !!(dpaa2_dq_flags(dq) & DPAA2_DQ_STAT_EXPIRED);
119 }
120
121 /**
122  * dpaa2_dq_seqnum() - Get the seqnum field in dequeue response
123  * @dq: the dequeue result
124  *
125  * seqnum is valid only if VALIDFRAME flag is TRUE
126  *
127  * Return seqnum.
128  */
129 static inline u16 dpaa2_dq_seqnum(const struct dpaa2_dq *dq)
130 {
131         return le16_to_cpu(dq->dq.seqnum);
132 }
133
134 /**
135  * dpaa2_dq_odpid() - Get the odpid field in dequeue response
136  * @dq: the dequeue result
137  *
138  * odpid is valid only if ODPVALID flag is TRUE.
139  *
140  * Return odpid.
141  */
142 static inline u16 dpaa2_dq_odpid(const struct dpaa2_dq *dq)
143 {
144         return le16_to_cpu(dq->dq.oprid);
145 }
146
147 /**
148  * dpaa2_dq_fqid() - Get the fqid in dequeue response
149  * @dq: the dequeue result
150  *
151  * Return fqid.
152  */
153 static inline u32 dpaa2_dq_fqid(const struct dpaa2_dq *dq)
154 {
155         return le32_to_cpu(dq->dq.fqid) & DQ_FQID_MASK;
156 }
157
158 /**
159  * dpaa2_dq_byte_count() - Get the byte count in dequeue response
160  * @dq: the dequeue result
161  *
162  * Return the byte count remaining in the FQ.
163  */
164 static inline u32 dpaa2_dq_byte_count(const struct dpaa2_dq *dq)
165 {
166         return le32_to_cpu(dq->dq.fq_byte_cnt);
167 }
168
169 /**
170  * dpaa2_dq_frame_count() - Get the frame count in dequeue response
171  * @dq: the dequeue result
172  *
173  * Return the frame count remaining in the FQ.
174  */
175 static inline u32 dpaa2_dq_frame_count(const struct dpaa2_dq *dq)
176 {
177         return le32_to_cpu(dq->dq.fq_frm_cnt) & DQ_FRAME_COUNT_MASK;
178 }
179
180 /**
181  * dpaa2_dq_fd_ctx() - Get the frame queue context in dequeue response
182  * @dq: the dequeue result
183  *
184  * Return the frame queue context.
185  */
186 static inline u64 dpaa2_dq_fqd_ctx(const struct dpaa2_dq *dq)
187 {
188         return le64_to_cpu(dq->dq.fqd_ctx);
189 }
190
191 /**
192  * dpaa2_dq_fd() - Get the frame descriptor in dequeue response
193  * @dq: the dequeue result
194  *
195  * Return the frame descriptor.
196  */
197 static inline const struct dpaa2_fd *dpaa2_dq_fd(const struct dpaa2_dq *dq)
198 {
199         return (const struct dpaa2_fd *)&dq->dq.fd[0];
200 }
201
202 #endif /* __FSL_DPAA2_GLOBAL_H */