2 * Copyright 2014-2016 Freescale Semiconductor Inc.
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.
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
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.
32 #ifndef __FSL_DPAA2_FD_H
33 #define __FSL_DPAA2_FD_H
35 #include <linux/kernel.h>
38 * DOC: DPAA2 FD - Frame Descriptor APIs for DPAA2
40 * Frame Descriptors (FDs) are used to describe frame data in the DPAA2.
41 * Frames can be enqueued and dequeued to Frame Queues (FQs) which are consumed
42 * by the various DPAA accelerators (WRIOP, SEC, PME, DCE)
44 * There are three types of frames: single, scatter gather, and frame lists.
46 * The set of APIs in this file must be used to create, manipulate and
47 * query Frame Descriptors.
51 * struct dpaa2_fd - Struct describing FDs
52 * @words: for easier/faster copying the whole FD structure
53 * @addr: address in the FD
54 * @len: length in the FD
55 * @bpid: buffer pool ID
56 * @format_offset: format, offset, and short-length fields
58 * @ctrl: control bits...including dd, sc, va, err, etc
59 * @flc: flow context address
61 * This structure represents the basic Frame Descriptor used in the system.
66 struct dpaa2_fd_simple {
78 #define FD_SHORT_LEN_FLAG_MASK 0x1
79 #define FD_SHORT_LEN_FLAG_SHIFT 14
80 #define FD_SHORT_LEN_MASK 0x3FFFF
81 #define FD_OFFSET_MASK 0x0FFF
82 #define FD_FORMAT_MASK 0x3
83 #define FD_FORMAT_SHIFT 12
84 #define FD_BPID_MASK 0x3FFF
85 #define SG_SHORT_LEN_FLAG_MASK 0x1
86 #define SG_SHORT_LEN_FLAG_SHIFT 14
87 #define SG_SHORT_LEN_MASK 0x1FFFF
88 #define SG_OFFSET_MASK 0x0FFF
89 #define SG_FORMAT_MASK 0x3
90 #define SG_FORMAT_SHIFT 12
91 #define SG_BPID_MASK 0x3FFF
92 #define SG_FINAL_FLAG_MASK 0x1
93 #define SG_FINAL_FLAG_SHIFT 15
95 enum dpaa2_fd_format {
102 * dpaa2_fd_get_addr() - get the addr field of frame descriptor
103 * @fd: the given frame descriptor
105 * Return the address in the frame descriptor.
107 static inline dma_addr_t dpaa2_fd_get_addr(const struct dpaa2_fd *fd)
109 return (dma_addr_t)le64_to_cpu(fd->simple.addr);
113 * dpaa2_fd_set_addr() - Set the addr field of frame descriptor
114 * @fd: the given frame descriptor
115 * @addr: the address needs to be set in frame descriptor
117 static inline void dpaa2_fd_set_addr(struct dpaa2_fd *fd, dma_addr_t addr)
119 fd->simple.addr = cpu_to_le64(addr);
123 * dpaa2_fd_get_frc() - Get the frame context in the frame descriptor
124 * @fd: the given frame descriptor
126 * Return the frame context field in the frame descriptor.
128 static inline u32 dpaa2_fd_get_frc(const struct dpaa2_fd *fd)
130 return le32_to_cpu(fd->simple.frc);
134 * dpaa2_fd_set_frc() - Set the frame context in the frame descriptor
135 * @fd: the given frame descriptor
136 * @frc: the frame context needs to be set in frame descriptor
138 static inline void dpaa2_fd_set_frc(struct dpaa2_fd *fd, u32 frc)
140 fd->simple.frc = cpu_to_le32(frc);
144 * dpaa2_fd_get_ctrl() - Get the control bits in the frame descriptor
145 * @fd: the given frame descriptor
147 * Return the control bits field in the frame descriptor.
149 static inline u32 dpaa2_fd_get_ctrl(const struct dpaa2_fd *fd)
151 return le32_to_cpu(fd->simple.ctrl);
155 * dpaa2_fd_set_ctrl() - Set the control bits in the frame descriptor
156 * @fd: the given frame descriptor
157 * @ctrl: the control bits to be set in the frame descriptor
159 static inline void dpaa2_fd_set_ctrl(struct dpaa2_fd *fd, u32 ctrl)
161 fd->simple.ctrl = cpu_to_le32(ctrl);
165 * dpaa2_fd_get_flc() - Get the flow context in the frame descriptor
166 * @fd: the given frame descriptor
168 * Return the flow context in the frame descriptor.
170 static inline dma_addr_t dpaa2_fd_get_flc(const struct dpaa2_fd *fd)
172 return (dma_addr_t)le64_to_cpu(fd->simple.flc);
176 * dpaa2_fd_set_flc() - Set the flow context field of frame descriptor
177 * @fd: the given frame descriptor
178 * @flc_addr: the flow context needs to be set in frame descriptor
180 static inline void dpaa2_fd_set_flc(struct dpaa2_fd *fd, dma_addr_t flc_addr)
182 fd->simple.flc = cpu_to_le64(flc_addr);
185 static inline bool dpaa2_fd_short_len(const struct dpaa2_fd *fd)
187 return !!((le16_to_cpu(fd->simple.format_offset) >>
188 FD_SHORT_LEN_FLAG_SHIFT) & FD_SHORT_LEN_FLAG_MASK);
192 * dpaa2_fd_get_len() - Get the length in the frame descriptor
193 * @fd: the given frame descriptor
195 * Return the length field in the frame descriptor.
197 static inline u32 dpaa2_fd_get_len(const struct dpaa2_fd *fd)
199 if (dpaa2_fd_short_len(fd))
200 return le32_to_cpu(fd->simple.len) & FD_SHORT_LEN_MASK;
202 return le32_to_cpu(fd->simple.len);
206 * dpaa2_fd_set_len() - Set the length field of frame descriptor
207 * @fd: the given frame descriptor
208 * @len: the length needs to be set in frame descriptor
210 static inline void dpaa2_fd_set_len(struct dpaa2_fd *fd, u32 len)
212 fd->simple.len = cpu_to_le32(len);
216 * dpaa2_fd_get_offset() - Get the offset field in the frame descriptor
217 * @fd: the given frame descriptor
221 static inline uint16_t dpaa2_fd_get_offset(const struct dpaa2_fd *fd)
223 return le16_to_cpu(fd->simple.format_offset) & FD_OFFSET_MASK;
227 * dpaa2_fd_set_offset() - Set the offset field of frame descriptor
228 * @fd: the given frame descriptor
229 * @offset: the offset needs to be set in frame descriptor
231 static inline void dpaa2_fd_set_offset(struct dpaa2_fd *fd, uint16_t offset)
233 fd->simple.format_offset &= cpu_to_le16(~FD_OFFSET_MASK);
234 fd->simple.format_offset |= cpu_to_le16(offset);
238 * dpaa2_fd_get_format() - Get the format field in the frame descriptor
239 * @fd: the given frame descriptor
243 static inline enum dpaa2_fd_format dpaa2_fd_get_format(
244 const struct dpaa2_fd *fd)
246 return (enum dpaa2_fd_format)((le16_to_cpu(fd->simple.format_offset)
247 >> FD_FORMAT_SHIFT) & FD_FORMAT_MASK);
251 * dpaa2_fd_set_format() - Set the format field of frame descriptor
252 * @fd: the given frame descriptor
253 * @format: the format needs to be set in frame descriptor
255 static inline void dpaa2_fd_set_format(struct dpaa2_fd *fd,
256 enum dpaa2_fd_format format)
258 fd->simple.format_offset &=
259 cpu_to_le16(~(FD_FORMAT_MASK << FD_FORMAT_SHIFT));
260 fd->simple.format_offset |= cpu_to_le16(format << FD_FORMAT_SHIFT);
264 * dpaa2_fd_get_bpid() - Get the bpid field in the frame descriptor
265 * @fd: the given frame descriptor
267 * Return the buffer pool id.
269 static inline uint16_t dpaa2_fd_get_bpid(const struct dpaa2_fd *fd)
271 return le16_to_cpu(fd->simple.bpid) & FD_BPID_MASK;
275 * dpaa2_fd_set_bpid() - Set the bpid field of frame descriptor
276 * @fd: the given frame descriptor
277 * @bpid: buffer pool id to be set
279 static inline void dpaa2_fd_set_bpid(struct dpaa2_fd *fd, uint16_t bpid)
281 fd->simple.bpid &= cpu_to_le16(~(FD_BPID_MASK));
282 fd->simple.bpid |= cpu_to_le16(bpid);
286 * struct dpaa2_sg_entry - the scatter-gathering structure
287 * @addr: address of the sg entry
288 * @len: length in this sg entry
289 * @bpid: buffer pool id
290 * @format_offset: format and offset fields
292 struct dpaa2_sg_entry {
296 __le16 format_offset;
299 enum dpaa2_sg_format {
305 /* Accessors for SG entry fields */
308 * dpaa2_sg_get_addr() - Get the address from SG entry
309 * @sg: the given scatter-gathering object
311 * Return the address.
313 static inline dma_addr_t dpaa2_sg_get_addr(const struct dpaa2_sg_entry *sg)
315 return le64_to_cpu((dma_addr_t)sg->addr);
319 * dpaa2_sg_set_addr() - Set the address in SG entry
320 * @sg: the given scatter-gathering object
321 * @addr: the address to be set
323 static inline void dpaa2_sg_set_addr(struct dpaa2_sg_entry *sg, dma_addr_t addr)
325 sg->addr = cpu_to_le64(addr);
328 static inline bool dpaa2_sg_short_len(const struct dpaa2_sg_entry *sg)
330 return !!((le16_to_cpu(sg->format_offset) >> SG_SHORT_LEN_FLAG_SHIFT)
331 & SG_SHORT_LEN_FLAG_MASK);
335 * dpaa2_sg_get_len() - Get the length in SG entry
336 * @sg: the given scatter-gathering object
340 static inline u32 dpaa2_sg_get_len(const struct dpaa2_sg_entry *sg)
342 if (dpaa2_sg_short_len(sg))
343 return le32_to_cpu(sg->len) & SG_SHORT_LEN_MASK;
345 return le32_to_cpu(sg->len);
349 * dpaa2_sg_set_len() - Set the length in SG entry
350 * @sg: the given scatter-gathering object
351 * @len: the length to be set
353 static inline void dpaa2_sg_set_len(struct dpaa2_sg_entry *sg, u32 len)
355 sg->len = cpu_to_le32(len);
359 * dpaa2_sg_get_offset() - Get the offset in SG entry
360 * @sg: the given scatter-gathering object
364 static inline u16 dpaa2_sg_get_offset(const struct dpaa2_sg_entry *sg)
366 return le16_to_cpu(sg->format_offset) & SG_OFFSET_MASK;
370 * dpaa2_sg_set_offset() - Set the offset in SG entry
371 * @sg: the given scatter-gathering object
372 * @offset: the offset to be set
374 static inline void dpaa2_sg_set_offset(struct dpaa2_sg_entry *sg,
377 sg->format_offset &= cpu_to_le16(~SG_OFFSET_MASK);
378 sg->format_offset |= cpu_to_le16(offset);
382 * dpaa2_sg_get_format() - Get the SG format in SG entry
383 * @sg: the given scatter-gathering object
387 static inline enum dpaa2_sg_format
388 dpaa2_sg_get_format(const struct dpaa2_sg_entry *sg)
390 return (enum dpaa2_sg_format)((le16_to_cpu(sg->format_offset)
391 >> SG_FORMAT_SHIFT) & SG_FORMAT_MASK);
395 * dpaa2_sg_set_format() - Set the SG format in SG entry
396 * @sg: the given scatter-gathering object
397 * @format: the format to be set
399 static inline void dpaa2_sg_set_format(struct dpaa2_sg_entry *sg,
400 enum dpaa2_sg_format format)
402 sg->format_offset &= cpu_to_le16(~(SG_FORMAT_MASK << SG_FORMAT_SHIFT));
403 sg->format_offset |= cpu_to_le16(format << SG_FORMAT_SHIFT);
407 * dpaa2_sg_get_bpid() - Get the buffer pool id in SG entry
408 * @sg: the given scatter-gathering object
412 static inline u16 dpaa2_sg_get_bpid(const struct dpaa2_sg_entry *sg)
414 return le16_to_cpu(sg->bpid) & SG_BPID_MASK;
418 * dpaa2_sg_set_bpid() - Set the buffer pool id in SG entry
419 * @sg: the given scatter-gathering object
420 * @bpid: the bpid to be set
422 static inline void dpaa2_sg_set_bpid(struct dpaa2_sg_entry *sg, u16 bpid)
424 sg->bpid &= cpu_to_le16(~(SG_BPID_MASK));
425 sg->bpid |= cpu_to_le16(bpid);
429 * dpaa2_sg_is_final() - Check final bit in SG entry
430 * @sg: the given scatter-gathering object
434 static inline bool dpaa2_sg_is_final(const struct dpaa2_sg_entry *sg)
436 return !!(le16_to_cpu(sg->format_offset) >> SG_FINAL_FLAG_SHIFT);
440 * dpaa2_sg_set_final() - Set the final bit in SG entry
441 * @sg: the given scatter-gathering object
442 * @final: the final boolean to be set
444 static inline void dpaa2_sg_set_final(struct dpaa2_sg_entry *sg, bool final)
446 sg->format_offset &= cpu_to_le16(~(SG_FINAL_FLAG_MASK
447 << SG_FINAL_FLAG_SHIFT));
448 sg->format_offset |= cpu_to_le16(final << SG_FINAL_FLAG_SHIFT);
451 #endif /* __FSL_DPAA2_FD_H */