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/byteorder/generic.h>
11 #include <linux/types.h>
14 * DOC: DPAA2 FD - Frame Descriptor APIs for DPAA2
16 * Frame Descriptors (FDs) are used to describe frame data in the DPAA2.
17 * Frames can be enqueued and dequeued to Frame Queues (FQs) which are consumed
18 * by the various DPAA accelerators (WRIOP, SEC, PME, DCE)
20 * There are three types of frames: single, scatter gather, and frame lists.
22 * The set of APIs in this file must be used to create, manipulate and
23 * query Frame Descriptors.
27 * struct dpaa2_fd - Struct describing FDs
28 * @words: for easier/faster copying the whole FD structure
29 * @addr: address in the FD
30 * @len: length in the FD
31 * @bpid: buffer pool ID
32 * @format_offset: format, offset, and short-length fields
34 * @ctrl: control bits...including dd, sc, va, err, etc
35 * @flc: flow context address
37 * This structure represents the basic Frame Descriptor used in the system.
42 struct dpaa2_fd_simple
{
54 #define FD_SHORT_LEN_FLAG_MASK 0x1
55 #define FD_SHORT_LEN_FLAG_SHIFT 14
56 #define FD_SHORT_LEN_MASK 0x3FFFF
57 #define FD_OFFSET_MASK 0x0FFF
58 #define FD_FORMAT_MASK 0x3
59 #define FD_FORMAT_SHIFT 12
60 #define FD_BPID_MASK 0x3FFF
61 #define SG_SHORT_LEN_FLAG_MASK 0x1
62 #define SG_SHORT_LEN_FLAG_SHIFT 14
63 #define SG_SHORT_LEN_MASK 0x1FFFF
64 #define SG_OFFSET_MASK 0x0FFF
65 #define SG_FORMAT_MASK 0x3
66 #define SG_FORMAT_SHIFT 12
67 #define SG_BPID_MASK 0x3FFF
68 #define SG_FINAL_FLAG_MASK 0x1
69 #define SG_FINAL_FLAG_SHIFT 15
70 #define FL_SHORT_LEN_FLAG_MASK 0x1
71 #define FL_SHORT_LEN_FLAG_SHIFT 14
72 #define FL_SHORT_LEN_MASK 0x3FFFF
73 #define FL_OFFSET_MASK 0x0FFF
74 #define FL_FORMAT_MASK 0x3
75 #define FL_FORMAT_SHIFT 12
76 #define FL_BPID_MASK 0x3FFF
77 #define FL_FINAL_FLAG_MASK 0x1
78 #define FL_FINAL_FLAG_SHIFT 15
80 /* Error bits in FD CTRL */
81 #define FD_CTRL_ERR_MASK 0x000000FF
82 #define FD_CTRL_UFD 0x00000004
83 #define FD_CTRL_SBE 0x00000008
84 #define FD_CTRL_FLC 0x00000010
85 #define FD_CTRL_FSE 0x00000020
86 #define FD_CTRL_FAERR 0x00000040
88 /* Annotation bits in FD CTRL */
89 #define FD_CTRL_PTA 0x00800000
90 #define FD_CTRL_PTV1 0x00400000
92 enum dpaa2_fd_format
{
99 * dpaa2_fd_get_addr() - get the addr field of frame descriptor
100 * @fd: the given frame descriptor
102 * Return the address in the frame descriptor.
104 static inline dma_addr_t
dpaa2_fd_get_addr(const struct dpaa2_fd
*fd
)
106 return (dma_addr_t
)le64_to_cpu(fd
->simple
.addr
);
110 * dpaa2_fd_set_addr() - Set the addr field of frame descriptor
111 * @fd: the given frame descriptor
112 * @addr: the address needs to be set in frame descriptor
114 static inline void dpaa2_fd_set_addr(struct dpaa2_fd
*fd
, dma_addr_t addr
)
116 fd
->simple
.addr
= cpu_to_le64(addr
);
120 * dpaa2_fd_get_frc() - Get the frame context in the frame descriptor
121 * @fd: the given frame descriptor
123 * Return the frame context field in the frame descriptor.
125 static inline u32
dpaa2_fd_get_frc(const struct dpaa2_fd
*fd
)
127 return le32_to_cpu(fd
->simple
.frc
);
131 * dpaa2_fd_set_frc() - Set the frame context in the frame descriptor
132 * @fd: the given frame descriptor
133 * @frc: the frame context needs to be set in frame descriptor
135 static inline void dpaa2_fd_set_frc(struct dpaa2_fd
*fd
, u32 frc
)
137 fd
->simple
.frc
= cpu_to_le32(frc
);
141 * dpaa2_fd_get_ctrl() - Get the control bits in the frame descriptor
142 * @fd: the given frame descriptor
144 * Return the control bits field in the frame descriptor.
146 static inline u32
dpaa2_fd_get_ctrl(const struct dpaa2_fd
*fd
)
148 return le32_to_cpu(fd
->simple
.ctrl
);
152 * dpaa2_fd_set_ctrl() - Set the control bits in the frame descriptor
153 * @fd: the given frame descriptor
154 * @ctrl: the control bits to be set in the frame descriptor
156 static inline void dpaa2_fd_set_ctrl(struct dpaa2_fd
*fd
, u32 ctrl
)
158 fd
->simple
.ctrl
= cpu_to_le32(ctrl
);
162 * dpaa2_fd_get_flc() - Get the flow context in the frame descriptor
163 * @fd: the given frame descriptor
165 * Return the flow context in the frame descriptor.
167 static inline dma_addr_t
dpaa2_fd_get_flc(const struct dpaa2_fd
*fd
)
169 return (dma_addr_t
)le64_to_cpu(fd
->simple
.flc
);
173 * dpaa2_fd_set_flc() - Set the flow context field of frame descriptor
174 * @fd: the given frame descriptor
175 * @flc_addr: the flow context needs to be set in frame descriptor
177 static inline void dpaa2_fd_set_flc(struct dpaa2_fd
*fd
, dma_addr_t flc_addr
)
179 fd
->simple
.flc
= cpu_to_le64(flc_addr
);
182 static inline bool dpaa2_fd_short_len(const struct dpaa2_fd
*fd
)
184 return !!((le16_to_cpu(fd
->simple
.format_offset
) >>
185 FD_SHORT_LEN_FLAG_SHIFT
) & FD_SHORT_LEN_FLAG_MASK
);
189 * dpaa2_fd_get_len() - Get the length in the frame descriptor
190 * @fd: the given frame descriptor
192 * Return the length field in the frame descriptor.
194 static inline u32
dpaa2_fd_get_len(const struct dpaa2_fd
*fd
)
196 if (dpaa2_fd_short_len(fd
))
197 return le32_to_cpu(fd
->simple
.len
) & FD_SHORT_LEN_MASK
;
199 return le32_to_cpu(fd
->simple
.len
);
203 * dpaa2_fd_set_len() - Set the length field of frame descriptor
204 * @fd: the given frame descriptor
205 * @len: the length needs to be set in frame descriptor
207 static inline void dpaa2_fd_set_len(struct dpaa2_fd
*fd
, u32 len
)
209 fd
->simple
.len
= cpu_to_le32(len
);
213 * dpaa2_fd_get_offset() - Get the offset field in the frame descriptor
214 * @fd: the given frame descriptor
218 static inline uint16_t dpaa2_fd_get_offset(const struct dpaa2_fd
*fd
)
220 return le16_to_cpu(fd
->simple
.format_offset
) & FD_OFFSET_MASK
;
224 * dpaa2_fd_set_offset() - Set the offset field of frame descriptor
225 * @fd: the given frame descriptor
226 * @offset: the offset needs to be set in frame descriptor
228 static inline void dpaa2_fd_set_offset(struct dpaa2_fd
*fd
, uint16_t offset
)
230 fd
->simple
.format_offset
&= cpu_to_le16(~FD_OFFSET_MASK
);
231 fd
->simple
.format_offset
|= cpu_to_le16(offset
);
235 * dpaa2_fd_get_format() - Get the format field in the frame descriptor
236 * @fd: the given frame descriptor
240 static inline enum dpaa2_fd_format
dpaa2_fd_get_format(
241 const struct dpaa2_fd
*fd
)
243 return (enum dpaa2_fd_format
)((le16_to_cpu(fd
->simple
.format_offset
)
244 >> FD_FORMAT_SHIFT
) & FD_FORMAT_MASK
);
248 * dpaa2_fd_set_format() - Set the format field of frame descriptor
249 * @fd: the given frame descriptor
250 * @format: the format needs to be set in frame descriptor
252 static inline void dpaa2_fd_set_format(struct dpaa2_fd
*fd
,
253 enum dpaa2_fd_format format
)
255 fd
->simple
.format_offset
&=
256 cpu_to_le16(~(FD_FORMAT_MASK
<< FD_FORMAT_SHIFT
));
257 fd
->simple
.format_offset
|= cpu_to_le16(format
<< FD_FORMAT_SHIFT
);
261 * dpaa2_fd_get_bpid() - Get the bpid field in the frame descriptor
262 * @fd: the given frame descriptor
264 * Return the buffer pool id.
266 static inline uint16_t dpaa2_fd_get_bpid(const struct dpaa2_fd
*fd
)
268 return le16_to_cpu(fd
->simple
.bpid
) & FD_BPID_MASK
;
272 * dpaa2_fd_set_bpid() - Set the bpid field of frame descriptor
273 * @fd: the given frame descriptor
274 * @bpid: buffer pool id to be set
276 static inline void dpaa2_fd_set_bpid(struct dpaa2_fd
*fd
, uint16_t bpid
)
278 fd
->simple
.bpid
&= cpu_to_le16(~(FD_BPID_MASK
));
279 fd
->simple
.bpid
|= cpu_to_le16(bpid
);
283 * struct dpaa2_sg_entry - the scatter-gathering structure
284 * @addr: address of the sg entry
285 * @len: length in this sg entry
286 * @bpid: buffer pool id
287 * @format_offset: format and offset fields
289 struct dpaa2_sg_entry
{
293 __le16 format_offset
;
296 enum dpaa2_sg_format
{
302 /* Accessors for SG entry fields */
305 * dpaa2_sg_get_addr() - Get the address from SG entry
306 * @sg: the given scatter-gathering object
308 * Return the address.
310 static inline dma_addr_t
dpaa2_sg_get_addr(const struct dpaa2_sg_entry
*sg
)
312 return (dma_addr_t
)le64_to_cpu(sg
->addr
);
316 * dpaa2_sg_set_addr() - Set the address in SG entry
317 * @sg: the given scatter-gathering object
318 * @addr: the address to be set
320 static inline void dpaa2_sg_set_addr(struct dpaa2_sg_entry
*sg
, dma_addr_t addr
)
322 sg
->addr
= cpu_to_le64(addr
);
325 static inline bool dpaa2_sg_short_len(const struct dpaa2_sg_entry
*sg
)
327 return !!((le16_to_cpu(sg
->format_offset
) >> SG_SHORT_LEN_FLAG_SHIFT
)
328 & SG_SHORT_LEN_FLAG_MASK
);
332 * dpaa2_sg_get_len() - Get the length in SG entry
333 * @sg: the given scatter-gathering object
337 static inline u32
dpaa2_sg_get_len(const struct dpaa2_sg_entry
*sg
)
339 if (dpaa2_sg_short_len(sg
))
340 return le32_to_cpu(sg
->len
) & SG_SHORT_LEN_MASK
;
342 return le32_to_cpu(sg
->len
);
346 * dpaa2_sg_set_len() - Set the length in SG entry
347 * @sg: the given scatter-gathering object
348 * @len: the length to be set
350 static inline void dpaa2_sg_set_len(struct dpaa2_sg_entry
*sg
, u32 len
)
352 sg
->len
= cpu_to_le32(len
);
356 * dpaa2_sg_get_offset() - Get the offset in SG entry
357 * @sg: the given scatter-gathering object
361 static inline u16
dpaa2_sg_get_offset(const struct dpaa2_sg_entry
*sg
)
363 return le16_to_cpu(sg
->format_offset
) & SG_OFFSET_MASK
;
367 * dpaa2_sg_set_offset() - Set the offset in SG entry
368 * @sg: the given scatter-gathering object
369 * @offset: the offset to be set
371 static inline void dpaa2_sg_set_offset(struct dpaa2_sg_entry
*sg
,
374 sg
->format_offset
&= cpu_to_le16(~SG_OFFSET_MASK
);
375 sg
->format_offset
|= cpu_to_le16(offset
);
379 * dpaa2_sg_get_format() - Get the SG format in SG entry
380 * @sg: the given scatter-gathering object
384 static inline enum dpaa2_sg_format
385 dpaa2_sg_get_format(const struct dpaa2_sg_entry
*sg
)
387 return (enum dpaa2_sg_format
)((le16_to_cpu(sg
->format_offset
)
388 >> SG_FORMAT_SHIFT
) & SG_FORMAT_MASK
);
392 * dpaa2_sg_set_format() - Set the SG format in SG entry
393 * @sg: the given scatter-gathering object
394 * @format: the format to be set
396 static inline void dpaa2_sg_set_format(struct dpaa2_sg_entry
*sg
,
397 enum dpaa2_sg_format format
)
399 sg
->format_offset
&= cpu_to_le16(~(SG_FORMAT_MASK
<< SG_FORMAT_SHIFT
));
400 sg
->format_offset
|= cpu_to_le16(format
<< SG_FORMAT_SHIFT
);
404 * dpaa2_sg_get_bpid() - Get the buffer pool id in SG entry
405 * @sg: the given scatter-gathering object
409 static inline u16
dpaa2_sg_get_bpid(const struct dpaa2_sg_entry
*sg
)
411 return le16_to_cpu(sg
->bpid
) & SG_BPID_MASK
;
415 * dpaa2_sg_set_bpid() - Set the buffer pool id in SG entry
416 * @sg: the given scatter-gathering object
417 * @bpid: the bpid to be set
419 static inline void dpaa2_sg_set_bpid(struct dpaa2_sg_entry
*sg
, u16 bpid
)
421 sg
->bpid
&= cpu_to_le16(~(SG_BPID_MASK
));
422 sg
->bpid
|= cpu_to_le16(bpid
);
426 * dpaa2_sg_is_final() - Check final bit in SG entry
427 * @sg: the given scatter-gathering object
431 static inline bool dpaa2_sg_is_final(const struct dpaa2_sg_entry
*sg
)
433 return !!(le16_to_cpu(sg
->format_offset
) >> SG_FINAL_FLAG_SHIFT
);
437 * dpaa2_sg_set_final() - Set the final bit in SG entry
438 * @sg: the given scatter-gathering object
439 * @final: the final boolean to be set
441 static inline void dpaa2_sg_set_final(struct dpaa2_sg_entry
*sg
, bool final
)
443 sg
->format_offset
&= cpu_to_le16((~(SG_FINAL_FLAG_MASK
444 << SG_FINAL_FLAG_SHIFT
)) & 0xFFFF);
445 sg
->format_offset
|= cpu_to_le16(final
<< SG_FINAL_FLAG_SHIFT
);
449 * struct dpaa2_fl_entry - structure for frame list entry.
450 * @addr: address in the FLE
451 * @len: length in the FLE
452 * @bpid: buffer pool ID
453 * @format_offset: format, offset, and short-length fields
454 * @frc: frame context
455 * @ctrl: control bits...including pta, pvt1, pvt2, err, etc
456 * @flc: flow context address
458 struct dpaa2_fl_entry
{
462 __le16 format_offset
;
468 enum dpaa2_fl_format
{
475 * dpaa2_fl_get_addr() - get the addr field of FLE
476 * @fle: the given frame list entry
478 * Return the address in the frame list entry.
480 static inline dma_addr_t
dpaa2_fl_get_addr(const struct dpaa2_fl_entry
*fle
)
482 return (dma_addr_t
)le64_to_cpu(fle
->addr
);
486 * dpaa2_fl_set_addr() - Set the addr field of FLE
487 * @fle: the given frame list entry
488 * @addr: the address needs to be set in frame list entry
490 static inline void dpaa2_fl_set_addr(struct dpaa2_fl_entry
*fle
,
493 fle
->addr
= cpu_to_le64(addr
);
497 * dpaa2_fl_get_frc() - Get the frame context in the FLE
498 * @fle: the given frame list entry
500 * Return the frame context field in the frame lsit entry.
502 static inline u32
dpaa2_fl_get_frc(const struct dpaa2_fl_entry
*fle
)
504 return le32_to_cpu(fle
->frc
);
508 * dpaa2_fl_set_frc() - Set the frame context in the FLE
509 * @fle: the given frame list entry
510 * @frc: the frame context needs to be set in frame list entry
512 static inline void dpaa2_fl_set_frc(struct dpaa2_fl_entry
*fle
, u32 frc
)
514 fle
->frc
= cpu_to_le32(frc
);
518 * dpaa2_fl_get_ctrl() - Get the control bits in the FLE
519 * @fle: the given frame list entry
521 * Return the control bits field in the frame list entry.
523 static inline u32
dpaa2_fl_get_ctrl(const struct dpaa2_fl_entry
*fle
)
525 return le32_to_cpu(fle
->ctrl
);
529 * dpaa2_fl_set_ctrl() - Set the control bits in the FLE
530 * @fle: the given frame list entry
531 * @ctrl: the control bits to be set in the frame list entry
533 static inline void dpaa2_fl_set_ctrl(struct dpaa2_fl_entry
*fle
, u32 ctrl
)
535 fle
->ctrl
= cpu_to_le32(ctrl
);
539 * dpaa2_fl_get_flc() - Get the flow context in the FLE
540 * @fle: the given frame list entry
542 * Return the flow context in the frame list entry.
544 static inline dma_addr_t
dpaa2_fl_get_flc(const struct dpaa2_fl_entry
*fle
)
546 return (dma_addr_t
)le64_to_cpu(fle
->flc
);
550 * dpaa2_fl_set_flc() - Set the flow context field of FLE
551 * @fle: the given frame list entry
552 * @flc_addr: the flow context needs to be set in frame list entry
554 static inline void dpaa2_fl_set_flc(struct dpaa2_fl_entry
*fle
,
557 fle
->flc
= cpu_to_le64(flc_addr
);
560 static inline bool dpaa2_fl_short_len(const struct dpaa2_fl_entry
*fle
)
562 return !!((le16_to_cpu(fle
->format_offset
) >>
563 FL_SHORT_LEN_FLAG_SHIFT
) & FL_SHORT_LEN_FLAG_MASK
);
567 * dpaa2_fl_get_len() - Get the length in the FLE
568 * @fle: the given frame list entry
570 * Return the length field in the frame list entry.
572 static inline u32
dpaa2_fl_get_len(const struct dpaa2_fl_entry
*fle
)
574 if (dpaa2_fl_short_len(fle
))
575 return le32_to_cpu(fle
->len
) & FL_SHORT_LEN_MASK
;
577 return le32_to_cpu(fle
->len
);
581 * dpaa2_fl_set_len() - Set the length field of FLE
582 * @fle: the given frame list entry
583 * @len: the length needs to be set in frame list entry
585 static inline void dpaa2_fl_set_len(struct dpaa2_fl_entry
*fle
, u32 len
)
587 fle
->len
= cpu_to_le32(len
);
591 * dpaa2_fl_get_offset() - Get the offset field in the frame list entry
592 * @fle: the given frame list entry
596 static inline u16
dpaa2_fl_get_offset(const struct dpaa2_fl_entry
*fle
)
598 return le16_to_cpu(fle
->format_offset
) & FL_OFFSET_MASK
;
602 * dpaa2_fl_set_offset() - Set the offset field of FLE
603 * @fle: the given frame list entry
604 * @offset: the offset needs to be set in frame list entry
606 static inline void dpaa2_fl_set_offset(struct dpaa2_fl_entry
*fle
, u16 offset
)
608 fle
->format_offset
&= cpu_to_le16(~FL_OFFSET_MASK
);
609 fle
->format_offset
|= cpu_to_le16(offset
);
613 * dpaa2_fl_get_format() - Get the format field in the FLE
614 * @fle: the given frame list entry
618 static inline enum dpaa2_fl_format
dpaa2_fl_get_format(const struct dpaa2_fl_entry
*fle
)
620 return (enum dpaa2_fl_format
)((le16_to_cpu(fle
->format_offset
) >>
621 FL_FORMAT_SHIFT
) & FL_FORMAT_MASK
);
625 * dpaa2_fl_set_format() - Set the format field of FLE
626 * @fle: the given frame list entry
627 * @format: the format needs to be set in frame list entry
629 static inline void dpaa2_fl_set_format(struct dpaa2_fl_entry
*fle
,
630 enum dpaa2_fl_format format
)
632 fle
->format_offset
&= cpu_to_le16(~(FL_FORMAT_MASK
<< FL_FORMAT_SHIFT
));
633 fle
->format_offset
|= cpu_to_le16(format
<< FL_FORMAT_SHIFT
);
637 * dpaa2_fl_get_bpid() - Get the bpid field in the FLE
638 * @fle: the given frame list entry
640 * Return the buffer pool id.
642 static inline u16
dpaa2_fl_get_bpid(const struct dpaa2_fl_entry
*fle
)
644 return le16_to_cpu(fle
->bpid
) & FL_BPID_MASK
;
648 * dpaa2_fl_set_bpid() - Set the bpid field of FLE
649 * @fle: the given frame list entry
650 * @bpid: buffer pool id to be set
652 static inline void dpaa2_fl_set_bpid(struct dpaa2_fl_entry
*fle
, u16 bpid
)
654 fle
->bpid
&= cpu_to_le16(~(FL_BPID_MASK
));
655 fle
->bpid
|= cpu_to_le16(bpid
);
659 * dpaa2_fl_is_final() - Check final bit in FLE
660 * @fle: the given frame list entry
664 static inline bool dpaa2_fl_is_final(const struct dpaa2_fl_entry
*fle
)
666 return !!(le16_to_cpu(fle
->format_offset
) >> FL_FINAL_FLAG_SHIFT
);
670 * dpaa2_fl_set_final() - Set the final bit in FLE
671 * @fle: the given frame list entry
672 * @final: the final boolean to be set
674 static inline void dpaa2_fl_set_final(struct dpaa2_fl_entry
*fle
, bool final
)
676 fle
->format_offset
&= cpu_to_le16((~(FL_FINAL_FLAG_MASK
<<
677 FL_FINAL_FLAG_SHIFT
)) & 0xFFFF);
678 fle
->format_offset
|= cpu_to_le16(final
<< FL_FINAL_FLAG_SHIFT
);
681 #endif /* __FSL_DPAA2_FD_H */