1 /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
3 * Copyright 2014-2016 Freescale Semiconductor Inc.
7 #ifndef __FSL_DPAA2_FD_H
8 #define __FSL_DPAA2_FD_H
10 #include <linux/kernel.h>
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.
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
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.
41 struct dpaa2_fd_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 enum dpaa2_fd_format {
77 * dpaa2_fd_get_addr() - get the addr field of frame descriptor
78 * @fd: the given frame descriptor
80 * Return the address in the frame descriptor.
82 static inline dma_addr_t dpaa2_fd_get_addr(const struct dpaa2_fd *fd)
84 return (dma_addr_t)le64_to_cpu(fd->simple.addr);
88 * dpaa2_fd_set_addr() - Set the addr field of frame descriptor
89 * @fd: the given frame descriptor
90 * @addr: the address needs to be set in frame descriptor
92 static inline void dpaa2_fd_set_addr(struct dpaa2_fd *fd, dma_addr_t addr)
94 fd->simple.addr = cpu_to_le64(addr);
98 * dpaa2_fd_get_frc() - Get the frame context in the frame descriptor
99 * @fd: the given frame descriptor
101 * Return the frame context field in the frame descriptor.
103 static inline u32 dpaa2_fd_get_frc(const struct dpaa2_fd *fd)
105 return le32_to_cpu(fd->simple.frc);
109 * dpaa2_fd_set_frc() - Set the frame context in the frame descriptor
110 * @fd: the given frame descriptor
111 * @frc: the frame context needs to be set in frame descriptor
113 static inline void dpaa2_fd_set_frc(struct dpaa2_fd *fd, u32 frc)
115 fd->simple.frc = cpu_to_le32(frc);
119 * dpaa2_fd_get_ctrl() - Get the control bits in the frame descriptor
120 * @fd: the given frame descriptor
122 * Return the control bits field in the frame descriptor.
124 static inline u32 dpaa2_fd_get_ctrl(const struct dpaa2_fd *fd)
126 return le32_to_cpu(fd->simple.ctrl);
130 * dpaa2_fd_set_ctrl() - Set the control bits in the frame descriptor
131 * @fd: the given frame descriptor
132 * @ctrl: the control bits to be set in the frame descriptor
134 static inline void dpaa2_fd_set_ctrl(struct dpaa2_fd *fd, u32 ctrl)
136 fd->simple.ctrl = cpu_to_le32(ctrl);
140 * dpaa2_fd_get_flc() - Get the flow context in the frame descriptor
141 * @fd: the given frame descriptor
143 * Return the flow context in the frame descriptor.
145 static inline dma_addr_t dpaa2_fd_get_flc(const struct dpaa2_fd *fd)
147 return (dma_addr_t)le64_to_cpu(fd->simple.flc);
151 * dpaa2_fd_set_flc() - Set the flow context field of frame descriptor
152 * @fd: the given frame descriptor
153 * @flc_addr: the flow context needs to be set in frame descriptor
155 static inline void dpaa2_fd_set_flc(struct dpaa2_fd *fd, dma_addr_t flc_addr)
157 fd->simple.flc = cpu_to_le64(flc_addr);
160 static inline bool dpaa2_fd_short_len(const struct dpaa2_fd *fd)
162 return !!((le16_to_cpu(fd->simple.format_offset) >>
163 FD_SHORT_LEN_FLAG_SHIFT) & FD_SHORT_LEN_FLAG_MASK);
167 * dpaa2_fd_get_len() - Get the length in the frame descriptor
168 * @fd: the given frame descriptor
170 * Return the length field in the frame descriptor.
172 static inline u32 dpaa2_fd_get_len(const struct dpaa2_fd *fd)
174 if (dpaa2_fd_short_len(fd))
175 return le32_to_cpu(fd->simple.len) & FD_SHORT_LEN_MASK;
177 return le32_to_cpu(fd->simple.len);
181 * dpaa2_fd_set_len() - Set the length field of frame descriptor
182 * @fd: the given frame descriptor
183 * @len: the length needs to be set in frame descriptor
185 static inline void dpaa2_fd_set_len(struct dpaa2_fd *fd, u32 len)
187 fd->simple.len = cpu_to_le32(len);
191 * dpaa2_fd_get_offset() - Get the offset field in the frame descriptor
192 * @fd: the given frame descriptor
196 static inline uint16_t dpaa2_fd_get_offset(const struct dpaa2_fd *fd)
198 return le16_to_cpu(fd->simple.format_offset) & FD_OFFSET_MASK;
202 * dpaa2_fd_set_offset() - Set the offset field of frame descriptor
203 * @fd: the given frame descriptor
204 * @offset: the offset needs to be set in frame descriptor
206 static inline void dpaa2_fd_set_offset(struct dpaa2_fd *fd, uint16_t offset)
208 fd->simple.format_offset &= cpu_to_le16(~FD_OFFSET_MASK);
209 fd->simple.format_offset |= cpu_to_le16(offset);
213 * dpaa2_fd_get_format() - Get the format field in the frame descriptor
214 * @fd: the given frame descriptor
218 static inline enum dpaa2_fd_format dpaa2_fd_get_format(
219 const struct dpaa2_fd *fd)
221 return (enum dpaa2_fd_format)((le16_to_cpu(fd->simple.format_offset)
222 >> FD_FORMAT_SHIFT) & FD_FORMAT_MASK);
226 * dpaa2_fd_set_format() - Set the format field of frame descriptor
227 * @fd: the given frame descriptor
228 * @format: the format needs to be set in frame descriptor
230 static inline void dpaa2_fd_set_format(struct dpaa2_fd *fd,
231 enum dpaa2_fd_format format)
233 fd->simple.format_offset &=
234 cpu_to_le16(~(FD_FORMAT_MASK << FD_FORMAT_SHIFT));
235 fd->simple.format_offset |= cpu_to_le16(format << FD_FORMAT_SHIFT);
239 * dpaa2_fd_get_bpid() - Get the bpid field in the frame descriptor
240 * @fd: the given frame descriptor
242 * Return the buffer pool id.
244 static inline uint16_t dpaa2_fd_get_bpid(const struct dpaa2_fd *fd)
246 return le16_to_cpu(fd->simple.bpid) & FD_BPID_MASK;
250 * dpaa2_fd_set_bpid() - Set the bpid field of frame descriptor
251 * @fd: the given frame descriptor
252 * @bpid: buffer pool id to be set
254 static inline void dpaa2_fd_set_bpid(struct dpaa2_fd *fd, uint16_t bpid)
256 fd->simple.bpid &= cpu_to_le16(~(FD_BPID_MASK));
257 fd->simple.bpid |= cpu_to_le16(bpid);
261 * struct dpaa2_sg_entry - the scatter-gathering structure
262 * @addr: address of the sg entry
263 * @len: length in this sg entry
264 * @bpid: buffer pool id
265 * @format_offset: format and offset fields
267 struct dpaa2_sg_entry {
271 __le16 format_offset;
274 enum dpaa2_sg_format {
280 /* Accessors for SG entry fields */
283 * dpaa2_sg_get_addr() - Get the address from SG entry
284 * @sg: the given scatter-gathering object
286 * Return the address.
288 static inline dma_addr_t dpaa2_sg_get_addr(const struct dpaa2_sg_entry *sg)
290 return (dma_addr_t)le64_to_cpu(sg->addr);
294 * dpaa2_sg_set_addr() - Set the address in SG entry
295 * @sg: the given scatter-gathering object
296 * @addr: the address to be set
298 static inline void dpaa2_sg_set_addr(struct dpaa2_sg_entry *sg, dma_addr_t addr)
300 sg->addr = cpu_to_le64(addr);
303 static inline bool dpaa2_sg_short_len(const struct dpaa2_sg_entry *sg)
305 return !!((le16_to_cpu(sg->format_offset) >> SG_SHORT_LEN_FLAG_SHIFT)
306 & SG_SHORT_LEN_FLAG_MASK);
310 * dpaa2_sg_get_len() - Get the length in SG entry
311 * @sg: the given scatter-gathering object
315 static inline u32 dpaa2_sg_get_len(const struct dpaa2_sg_entry *sg)
317 if (dpaa2_sg_short_len(sg))
318 return le32_to_cpu(sg->len) & SG_SHORT_LEN_MASK;
320 return le32_to_cpu(sg->len);
324 * dpaa2_sg_set_len() - Set the length in SG entry
325 * @sg: the given scatter-gathering object
326 * @len: the length to be set
328 static inline void dpaa2_sg_set_len(struct dpaa2_sg_entry *sg, u32 len)
330 sg->len = cpu_to_le32(len);
334 * dpaa2_sg_get_offset() - Get the offset in SG entry
335 * @sg: the given scatter-gathering object
339 static inline u16 dpaa2_sg_get_offset(const struct dpaa2_sg_entry *sg)
341 return le16_to_cpu(sg->format_offset) & SG_OFFSET_MASK;
345 * dpaa2_sg_set_offset() - Set the offset in SG entry
346 * @sg: the given scatter-gathering object
347 * @offset: the offset to be set
349 static inline void dpaa2_sg_set_offset(struct dpaa2_sg_entry *sg,
352 sg->format_offset &= cpu_to_le16(~SG_OFFSET_MASK);
353 sg->format_offset |= cpu_to_le16(offset);
357 * dpaa2_sg_get_format() - Get the SG format in SG entry
358 * @sg: the given scatter-gathering object
362 static inline enum dpaa2_sg_format
363 dpaa2_sg_get_format(const struct dpaa2_sg_entry *sg)
365 return (enum dpaa2_sg_format)((le16_to_cpu(sg->format_offset)
366 >> SG_FORMAT_SHIFT) & SG_FORMAT_MASK);
370 * dpaa2_sg_set_format() - Set the SG format in SG entry
371 * @sg: the given scatter-gathering object
372 * @format: the format to be set
374 static inline void dpaa2_sg_set_format(struct dpaa2_sg_entry *sg,
375 enum dpaa2_sg_format format)
377 sg->format_offset &= cpu_to_le16(~(SG_FORMAT_MASK << SG_FORMAT_SHIFT));
378 sg->format_offset |= cpu_to_le16(format << SG_FORMAT_SHIFT);
382 * dpaa2_sg_get_bpid() - Get the buffer pool id in SG entry
383 * @sg: the given scatter-gathering object
387 static inline u16 dpaa2_sg_get_bpid(const struct dpaa2_sg_entry *sg)
389 return le16_to_cpu(sg->bpid) & SG_BPID_MASK;
393 * dpaa2_sg_set_bpid() - Set the buffer pool id in SG entry
394 * @sg: the given scatter-gathering object
395 * @bpid: the bpid to be set
397 static inline void dpaa2_sg_set_bpid(struct dpaa2_sg_entry *sg, u16 bpid)
399 sg->bpid &= cpu_to_le16(~(SG_BPID_MASK));
400 sg->bpid |= cpu_to_le16(bpid);
404 * dpaa2_sg_is_final() - Check final bit in SG entry
405 * @sg: the given scatter-gathering object
409 static inline bool dpaa2_sg_is_final(const struct dpaa2_sg_entry *sg)
411 return !!(le16_to_cpu(sg->format_offset) >> SG_FINAL_FLAG_SHIFT);
415 * dpaa2_sg_set_final() - Set the final bit in SG entry
416 * @sg: the given scatter-gathering object
417 * @final: the final boolean to be set
419 static inline void dpaa2_sg_set_final(struct dpaa2_sg_entry *sg, bool final)
421 sg->format_offset &= cpu_to_le16((~(SG_FINAL_FLAG_MASK
422 << SG_FINAL_FLAG_SHIFT)) & 0xFFFF);
423 sg->format_offset |= cpu_to_le16(final << SG_FINAL_FLAG_SHIFT);
426 #endif /* __FSL_DPAA2_FD_H */