staging: rtl8188eu: rename HalSetBrateCfg() - style
[linux/fpc-iii.git] / include / soc / fsl / dpaa2-fd.h
blob2576abaa7779dc3d4d1ba69859b1320e190fbec5
1 /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
2 /*
3 * Copyright 2014-2016 Freescale Semiconductor Inc.
4 * Copyright 2016 NXP
6 */
7 #ifndef __FSL_DPAA2_FD_H
8 #define __FSL_DPAA2_FD_H
10 #include <linux/kernel.h>
12 /**
13 * DOC: DPAA2 FD - Frame Descriptor APIs for DPAA2
15 * Frame Descriptors (FDs) are used to describe frame data in the DPAA2.
16 * Frames can be enqueued and dequeued to Frame Queues (FQs) which are consumed
17 * by the various DPAA accelerators (WRIOP, SEC, PME, DCE)
19 * There are three types of frames: single, scatter gather, and frame lists.
21 * The set of APIs in this file must be used to create, manipulate and
22 * query Frame Descriptors.
25 /**
26 * struct dpaa2_fd - Struct describing FDs
27 * @words: for easier/faster copying the whole FD structure
28 * @addr: address in the FD
29 * @len: length in the FD
30 * @bpid: buffer pool ID
31 * @format_offset: format, offset, and short-length fields
32 * @frc: frame context
33 * @ctrl: control bits...including dd, sc, va, err, etc
34 * @flc: flow context address
36 * This structure represents the basic Frame Descriptor used in the system.
38 struct dpaa2_fd {
39 union {
40 u32 words[8];
41 struct dpaa2_fd_simple {
42 __le64 addr;
43 __le32 len;
44 __le16 bpid;
45 __le16 format_offset;
46 __le32 frc;
47 __le32 ctrl;
48 __le64 flc;
49 } simple;
53 #define FD_SHORT_LEN_FLAG_MASK 0x1
54 #define FD_SHORT_LEN_FLAG_SHIFT 14
55 #define FD_SHORT_LEN_MASK 0x3FFFF
56 #define FD_OFFSET_MASK 0x0FFF
57 #define FD_FORMAT_MASK 0x3
58 #define FD_FORMAT_SHIFT 12
59 #define FD_BPID_MASK 0x3FFF
60 #define SG_SHORT_LEN_FLAG_MASK 0x1
61 #define SG_SHORT_LEN_FLAG_SHIFT 14
62 #define SG_SHORT_LEN_MASK 0x1FFFF
63 #define SG_OFFSET_MASK 0x0FFF
64 #define SG_FORMAT_MASK 0x3
65 #define SG_FORMAT_SHIFT 12
66 #define SG_BPID_MASK 0x3FFF
67 #define SG_FINAL_FLAG_MASK 0x1
68 #define SG_FINAL_FLAG_SHIFT 15
70 /* Error bits in FD CTRL */
71 #define FD_CTRL_ERR_MASK 0x000000FF
72 #define FD_CTRL_UFD 0x00000004
73 #define FD_CTRL_SBE 0x00000008
74 #define FD_CTRL_FLC 0x00000010
75 #define FD_CTRL_FSE 0x00000020
76 #define FD_CTRL_FAERR 0x00000040
78 /* Annotation bits in FD CTRL */
79 #define FD_CTRL_PTA 0x00800000
80 #define FD_CTRL_PTV1 0x00400000
82 enum dpaa2_fd_format {
83 dpaa2_fd_single = 0,
84 dpaa2_fd_list,
85 dpaa2_fd_sg
88 /**
89 * dpaa2_fd_get_addr() - get the addr field of frame descriptor
90 * @fd: the given frame descriptor
92 * Return the address in the frame descriptor.
94 static inline dma_addr_t dpaa2_fd_get_addr(const struct dpaa2_fd *fd)
96 return (dma_addr_t)le64_to_cpu(fd->simple.addr);
99 /**
100 * dpaa2_fd_set_addr() - Set the addr field of frame descriptor
101 * @fd: the given frame descriptor
102 * @addr: the address needs to be set in frame descriptor
104 static inline void dpaa2_fd_set_addr(struct dpaa2_fd *fd, dma_addr_t addr)
106 fd->simple.addr = cpu_to_le64(addr);
110 * dpaa2_fd_get_frc() - Get the frame context in the frame descriptor
111 * @fd: the given frame descriptor
113 * Return the frame context field in the frame descriptor.
115 static inline u32 dpaa2_fd_get_frc(const struct dpaa2_fd *fd)
117 return le32_to_cpu(fd->simple.frc);
121 * dpaa2_fd_set_frc() - Set the frame context in the frame descriptor
122 * @fd: the given frame descriptor
123 * @frc: the frame context needs to be set in frame descriptor
125 static inline void dpaa2_fd_set_frc(struct dpaa2_fd *fd, u32 frc)
127 fd->simple.frc = cpu_to_le32(frc);
131 * dpaa2_fd_get_ctrl() - Get the control bits in the frame descriptor
132 * @fd: the given frame descriptor
134 * Return the control bits field in the frame descriptor.
136 static inline u32 dpaa2_fd_get_ctrl(const struct dpaa2_fd *fd)
138 return le32_to_cpu(fd->simple.ctrl);
142 * dpaa2_fd_set_ctrl() - Set the control bits in the frame descriptor
143 * @fd: the given frame descriptor
144 * @ctrl: the control bits to be set in the frame descriptor
146 static inline void dpaa2_fd_set_ctrl(struct dpaa2_fd *fd, u32 ctrl)
148 fd->simple.ctrl = cpu_to_le32(ctrl);
152 * dpaa2_fd_get_flc() - Get the flow context in the frame descriptor
153 * @fd: the given frame descriptor
155 * Return the flow context in the frame descriptor.
157 static inline dma_addr_t dpaa2_fd_get_flc(const struct dpaa2_fd *fd)
159 return (dma_addr_t)le64_to_cpu(fd->simple.flc);
163 * dpaa2_fd_set_flc() - Set the flow context field of frame descriptor
164 * @fd: the given frame descriptor
165 * @flc_addr: the flow context needs to be set in frame descriptor
167 static inline void dpaa2_fd_set_flc(struct dpaa2_fd *fd, dma_addr_t flc_addr)
169 fd->simple.flc = cpu_to_le64(flc_addr);
172 static inline bool dpaa2_fd_short_len(const struct dpaa2_fd *fd)
174 return !!((le16_to_cpu(fd->simple.format_offset) >>
175 FD_SHORT_LEN_FLAG_SHIFT) & FD_SHORT_LEN_FLAG_MASK);
179 * dpaa2_fd_get_len() - Get the length in the frame descriptor
180 * @fd: the given frame descriptor
182 * Return the length field in the frame descriptor.
184 static inline u32 dpaa2_fd_get_len(const struct dpaa2_fd *fd)
186 if (dpaa2_fd_short_len(fd))
187 return le32_to_cpu(fd->simple.len) & FD_SHORT_LEN_MASK;
189 return le32_to_cpu(fd->simple.len);
193 * dpaa2_fd_set_len() - Set the length field of frame descriptor
194 * @fd: the given frame descriptor
195 * @len: the length needs to be set in frame descriptor
197 static inline void dpaa2_fd_set_len(struct dpaa2_fd *fd, u32 len)
199 fd->simple.len = cpu_to_le32(len);
203 * dpaa2_fd_get_offset() - Get the offset field in the frame descriptor
204 * @fd: the given frame descriptor
206 * Return the offset.
208 static inline uint16_t dpaa2_fd_get_offset(const struct dpaa2_fd *fd)
210 return le16_to_cpu(fd->simple.format_offset) & FD_OFFSET_MASK;
214 * dpaa2_fd_set_offset() - Set the offset field of frame descriptor
215 * @fd: the given frame descriptor
216 * @offset: the offset needs to be set in frame descriptor
218 static inline void dpaa2_fd_set_offset(struct dpaa2_fd *fd, uint16_t offset)
220 fd->simple.format_offset &= cpu_to_le16(~FD_OFFSET_MASK);
221 fd->simple.format_offset |= cpu_to_le16(offset);
225 * dpaa2_fd_get_format() - Get the format field in the frame descriptor
226 * @fd: the given frame descriptor
228 * Return the format.
230 static inline enum dpaa2_fd_format dpaa2_fd_get_format(
231 const struct dpaa2_fd *fd)
233 return (enum dpaa2_fd_format)((le16_to_cpu(fd->simple.format_offset)
234 >> FD_FORMAT_SHIFT) & FD_FORMAT_MASK);
238 * dpaa2_fd_set_format() - Set the format field of frame descriptor
239 * @fd: the given frame descriptor
240 * @format: the format needs to be set in frame descriptor
242 static inline void dpaa2_fd_set_format(struct dpaa2_fd *fd,
243 enum dpaa2_fd_format format)
245 fd->simple.format_offset &=
246 cpu_to_le16(~(FD_FORMAT_MASK << FD_FORMAT_SHIFT));
247 fd->simple.format_offset |= cpu_to_le16(format << FD_FORMAT_SHIFT);
251 * dpaa2_fd_get_bpid() - Get the bpid field in the frame descriptor
252 * @fd: the given frame descriptor
254 * Return the buffer pool id.
256 static inline uint16_t dpaa2_fd_get_bpid(const struct dpaa2_fd *fd)
258 return le16_to_cpu(fd->simple.bpid) & FD_BPID_MASK;
262 * dpaa2_fd_set_bpid() - Set the bpid field of frame descriptor
263 * @fd: the given frame descriptor
264 * @bpid: buffer pool id to be set
266 static inline void dpaa2_fd_set_bpid(struct dpaa2_fd *fd, uint16_t bpid)
268 fd->simple.bpid &= cpu_to_le16(~(FD_BPID_MASK));
269 fd->simple.bpid |= cpu_to_le16(bpid);
273 * struct dpaa2_sg_entry - the scatter-gathering structure
274 * @addr: address of the sg entry
275 * @len: length in this sg entry
276 * @bpid: buffer pool id
277 * @format_offset: format and offset fields
279 struct dpaa2_sg_entry {
280 __le64 addr;
281 __le32 len;
282 __le16 bpid;
283 __le16 format_offset;
286 enum dpaa2_sg_format {
287 dpaa2_sg_single = 0,
288 dpaa2_sg_frame_data,
289 dpaa2_sg_sgt_ext
292 /* Accessors for SG entry fields */
295 * dpaa2_sg_get_addr() - Get the address from SG entry
296 * @sg: the given scatter-gathering object
298 * Return the address.
300 static inline dma_addr_t dpaa2_sg_get_addr(const struct dpaa2_sg_entry *sg)
302 return (dma_addr_t)le64_to_cpu(sg->addr);
306 * dpaa2_sg_set_addr() - Set the address in SG entry
307 * @sg: the given scatter-gathering object
308 * @addr: the address to be set
310 static inline void dpaa2_sg_set_addr(struct dpaa2_sg_entry *sg, dma_addr_t addr)
312 sg->addr = cpu_to_le64(addr);
315 static inline bool dpaa2_sg_short_len(const struct dpaa2_sg_entry *sg)
317 return !!((le16_to_cpu(sg->format_offset) >> SG_SHORT_LEN_FLAG_SHIFT)
318 & SG_SHORT_LEN_FLAG_MASK);
322 * dpaa2_sg_get_len() - Get the length in SG entry
323 * @sg: the given scatter-gathering object
325 * Return the length.
327 static inline u32 dpaa2_sg_get_len(const struct dpaa2_sg_entry *sg)
329 if (dpaa2_sg_short_len(sg))
330 return le32_to_cpu(sg->len) & SG_SHORT_LEN_MASK;
332 return le32_to_cpu(sg->len);
336 * dpaa2_sg_set_len() - Set the length in SG entry
337 * @sg: the given scatter-gathering object
338 * @len: the length to be set
340 static inline void dpaa2_sg_set_len(struct dpaa2_sg_entry *sg, u32 len)
342 sg->len = cpu_to_le32(len);
346 * dpaa2_sg_get_offset() - Get the offset in SG entry
347 * @sg: the given scatter-gathering object
349 * Return the offset.
351 static inline u16 dpaa2_sg_get_offset(const struct dpaa2_sg_entry *sg)
353 return le16_to_cpu(sg->format_offset) & SG_OFFSET_MASK;
357 * dpaa2_sg_set_offset() - Set the offset in SG entry
358 * @sg: the given scatter-gathering object
359 * @offset: the offset to be set
361 static inline void dpaa2_sg_set_offset(struct dpaa2_sg_entry *sg,
362 u16 offset)
364 sg->format_offset &= cpu_to_le16(~SG_OFFSET_MASK);
365 sg->format_offset |= cpu_to_le16(offset);
369 * dpaa2_sg_get_format() - Get the SG format in SG entry
370 * @sg: the given scatter-gathering object
372 * Return the format.
374 static inline enum dpaa2_sg_format
375 dpaa2_sg_get_format(const struct dpaa2_sg_entry *sg)
377 return (enum dpaa2_sg_format)((le16_to_cpu(sg->format_offset)
378 >> SG_FORMAT_SHIFT) & SG_FORMAT_MASK);
382 * dpaa2_sg_set_format() - Set the SG format in SG entry
383 * @sg: the given scatter-gathering object
384 * @format: the format to be set
386 static inline void dpaa2_sg_set_format(struct dpaa2_sg_entry *sg,
387 enum dpaa2_sg_format format)
389 sg->format_offset &= cpu_to_le16(~(SG_FORMAT_MASK << SG_FORMAT_SHIFT));
390 sg->format_offset |= cpu_to_le16(format << SG_FORMAT_SHIFT);
394 * dpaa2_sg_get_bpid() - Get the buffer pool id in SG entry
395 * @sg: the given scatter-gathering object
397 * Return the bpid.
399 static inline u16 dpaa2_sg_get_bpid(const struct dpaa2_sg_entry *sg)
401 return le16_to_cpu(sg->bpid) & SG_BPID_MASK;
405 * dpaa2_sg_set_bpid() - Set the buffer pool id in SG entry
406 * @sg: the given scatter-gathering object
407 * @bpid: the bpid to be set
409 static inline void dpaa2_sg_set_bpid(struct dpaa2_sg_entry *sg, u16 bpid)
411 sg->bpid &= cpu_to_le16(~(SG_BPID_MASK));
412 sg->bpid |= cpu_to_le16(bpid);
416 * dpaa2_sg_is_final() - Check final bit in SG entry
417 * @sg: the given scatter-gathering object
419 * Return bool.
421 static inline bool dpaa2_sg_is_final(const struct dpaa2_sg_entry *sg)
423 return !!(le16_to_cpu(sg->format_offset) >> SG_FINAL_FLAG_SHIFT);
427 * dpaa2_sg_set_final() - Set the final bit in SG entry
428 * @sg: the given scatter-gathering object
429 * @final: the final boolean to be set
431 static inline void dpaa2_sg_set_final(struct dpaa2_sg_entry *sg, bool final)
433 sg->format_offset &= cpu_to_le16((~(SG_FINAL_FLAG_MASK
434 << SG_FINAL_FLAG_SHIFT)) & 0xFFFF);
435 sg->format_offset |= cpu_to_le16(final << SG_FINAL_FLAG_SHIFT);
438 #endif /* __FSL_DPAA2_FD_H */