/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */1/*2* Copyright 2014-2016 Freescale Semiconductor Inc.3* Copyright 2016 NXP4*5*/6#ifndef __FSL_DPAA2_FD_H7#define __FSL_DPAA2_FD_H89#include <linux/byteorder/generic.h>10#include <linux/types.h>1112/**13* DOC: DPAA2 FD - Frame Descriptor APIs for DPAA214*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 consumed17* by the various DPAA accelerators (WRIOP, SEC, PME, DCE)18*19* There are three types of frames: single, scatter gather, and frame lists.20*21* The set of APIs in this file must be used to create, manipulate and22* query Frame Descriptors.23*/2425/**26* struct dpaa2_fd - Struct describing FDs27* @words: for easier/faster copying the whole FD structure28* @addr: address in the FD29* @len: length in the FD30* @bpid: buffer pool ID31* @format_offset: format, offset, and short-length fields32* @frc: frame context33* @ctrl: control bits...including dd, sc, va, err, etc34* @flc: flow context address35*36* This structure represents the basic Frame Descriptor used in the system.37*/38struct dpaa2_fd {39union {40u32 words[8];41struct 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;50};51};5253#define FD_SHORT_LEN_FLAG_MASK 0x154#define FD_SHORT_LEN_FLAG_SHIFT 1455#define FD_SHORT_LEN_MASK 0x3FFFF56#define FD_OFFSET_MASK 0x0FFF57#define FD_FORMAT_MASK 0x358#define FD_FORMAT_SHIFT 1259#define FD_BPID_MASK 0x3FFF60#define SG_SHORT_LEN_FLAG_MASK 0x161#define SG_SHORT_LEN_FLAG_SHIFT 1462#define SG_SHORT_LEN_MASK 0x1FFFF63#define SG_OFFSET_MASK 0x0FFF64#define SG_FORMAT_MASK 0x365#define SG_FORMAT_SHIFT 1266#define SG_BPID_MASK 0x3FFF67#define SG_FINAL_FLAG_MASK 0x168#define SG_FINAL_FLAG_SHIFT 1569#define FL_SHORT_LEN_FLAG_MASK 0x170#define FL_SHORT_LEN_FLAG_SHIFT 1471#define FL_SHORT_LEN_MASK 0x3FFFF72#define FL_OFFSET_MASK 0x0FFF73#define FL_FORMAT_MASK 0x374#define FL_FORMAT_SHIFT 1275#define FL_BPID_MASK 0x3FFF76#define FL_FINAL_FLAG_MASK 0x177#define FL_FINAL_FLAG_SHIFT 157879/* Error bits in FD CTRL */80#define FD_CTRL_ERR_MASK 0x000000FF81#define FD_CTRL_UFD 0x0000000482#define FD_CTRL_SBE 0x0000000883#define FD_CTRL_FLC 0x0000001084#define FD_CTRL_FSE 0x0000002085#define FD_CTRL_FAERR 0x000000408687/* Annotation bits in FD CTRL */88#define FD_CTRL_PTA 0x0080000089#define FD_CTRL_PTV1 0x004000009091enum dpaa2_fd_format {92dpaa2_fd_single = 0,93dpaa2_fd_list,94dpaa2_fd_sg95};9697/**98* dpaa2_fd_get_addr() - get the addr field of frame descriptor99* @fd: the given frame descriptor100*101* Return the address in the frame descriptor.102*/103static inline dma_addr_t dpaa2_fd_get_addr(const struct dpaa2_fd *fd)104{105return (dma_addr_t)le64_to_cpu(fd->simple.addr);106}107108/**109* dpaa2_fd_set_addr() - Set the addr field of frame descriptor110* @fd: the given frame descriptor111* @addr: the address needs to be set in frame descriptor112*/113static inline void dpaa2_fd_set_addr(struct dpaa2_fd *fd, dma_addr_t addr)114{115fd->simple.addr = cpu_to_le64(addr);116}117118/**119* dpaa2_fd_get_frc() - Get the frame context in the frame descriptor120* @fd: the given frame descriptor121*122* Return the frame context field in the frame descriptor.123*/124static inline u32 dpaa2_fd_get_frc(const struct dpaa2_fd *fd)125{126return le32_to_cpu(fd->simple.frc);127}128129/**130* dpaa2_fd_set_frc() - Set the frame context in the frame descriptor131* @fd: the given frame descriptor132* @frc: the frame context needs to be set in frame descriptor133*/134static inline void dpaa2_fd_set_frc(struct dpaa2_fd *fd, u32 frc)135{136fd->simple.frc = cpu_to_le32(frc);137}138139/**140* dpaa2_fd_get_ctrl() - Get the control bits in the frame descriptor141* @fd: the given frame descriptor142*143* Return the control bits field in the frame descriptor.144*/145static inline u32 dpaa2_fd_get_ctrl(const struct dpaa2_fd *fd)146{147return le32_to_cpu(fd->simple.ctrl);148}149150/**151* dpaa2_fd_set_ctrl() - Set the control bits in the frame descriptor152* @fd: the given frame descriptor153* @ctrl: the control bits to be set in the frame descriptor154*/155static inline void dpaa2_fd_set_ctrl(struct dpaa2_fd *fd, u32 ctrl)156{157fd->simple.ctrl = cpu_to_le32(ctrl);158}159160/**161* dpaa2_fd_get_flc() - Get the flow context in the frame descriptor162* @fd: the given frame descriptor163*164* Return the flow context in the frame descriptor.165*/166static inline dma_addr_t dpaa2_fd_get_flc(const struct dpaa2_fd *fd)167{168return (dma_addr_t)le64_to_cpu(fd->simple.flc);169}170171/**172* dpaa2_fd_set_flc() - Set the flow context field of frame descriptor173* @fd: the given frame descriptor174* @flc_addr: the flow context needs to be set in frame descriptor175*/176static inline void dpaa2_fd_set_flc(struct dpaa2_fd *fd, dma_addr_t flc_addr)177{178fd->simple.flc = cpu_to_le64(flc_addr);179}180181static inline bool dpaa2_fd_short_len(const struct dpaa2_fd *fd)182{183return !!((le16_to_cpu(fd->simple.format_offset) >>184FD_SHORT_LEN_FLAG_SHIFT) & FD_SHORT_LEN_FLAG_MASK);185}186187/**188* dpaa2_fd_get_len() - Get the length in the frame descriptor189* @fd: the given frame descriptor190*191* Return the length field in the frame descriptor.192*/193static inline u32 dpaa2_fd_get_len(const struct dpaa2_fd *fd)194{195if (dpaa2_fd_short_len(fd))196return le32_to_cpu(fd->simple.len) & FD_SHORT_LEN_MASK;197198return le32_to_cpu(fd->simple.len);199}200201/**202* dpaa2_fd_set_len() - Set the length field of frame descriptor203* @fd: the given frame descriptor204* @len: the length needs to be set in frame descriptor205*/206static inline void dpaa2_fd_set_len(struct dpaa2_fd *fd, u32 len)207{208fd->simple.len = cpu_to_le32(len);209}210211/**212* dpaa2_fd_get_offset() - Get the offset field in the frame descriptor213* @fd: the given frame descriptor214*215* Return the offset.216*/217static inline uint16_t dpaa2_fd_get_offset(const struct dpaa2_fd *fd)218{219return le16_to_cpu(fd->simple.format_offset) & FD_OFFSET_MASK;220}221222/**223* dpaa2_fd_set_offset() - Set the offset field of frame descriptor224* @fd: the given frame descriptor225* @offset: the offset needs to be set in frame descriptor226*/227static inline void dpaa2_fd_set_offset(struct dpaa2_fd *fd, uint16_t offset)228{229fd->simple.format_offset &= cpu_to_le16(~FD_OFFSET_MASK);230fd->simple.format_offset |= cpu_to_le16(offset);231}232233/**234* dpaa2_fd_get_format() - Get the format field in the frame descriptor235* @fd: the given frame descriptor236*237* Return the format.238*/239static inline enum dpaa2_fd_format dpaa2_fd_get_format(240const struct dpaa2_fd *fd)241{242return (enum dpaa2_fd_format)((le16_to_cpu(fd->simple.format_offset)243>> FD_FORMAT_SHIFT) & FD_FORMAT_MASK);244}245246/**247* dpaa2_fd_set_format() - Set the format field of frame descriptor248* @fd: the given frame descriptor249* @format: the format needs to be set in frame descriptor250*/251static inline void dpaa2_fd_set_format(struct dpaa2_fd *fd,252enum dpaa2_fd_format format)253{254fd->simple.format_offset &=255cpu_to_le16(~(FD_FORMAT_MASK << FD_FORMAT_SHIFT));256fd->simple.format_offset |= cpu_to_le16(format << FD_FORMAT_SHIFT);257}258259/**260* dpaa2_fd_get_bpid() - Get the bpid field in the frame descriptor261* @fd: the given frame descriptor262*263* Return the buffer pool id.264*/265static inline uint16_t dpaa2_fd_get_bpid(const struct dpaa2_fd *fd)266{267return le16_to_cpu(fd->simple.bpid) & FD_BPID_MASK;268}269270/**271* dpaa2_fd_set_bpid() - Set the bpid field of frame descriptor272* @fd: the given frame descriptor273* @bpid: buffer pool id to be set274*/275static inline void dpaa2_fd_set_bpid(struct dpaa2_fd *fd, uint16_t bpid)276{277fd->simple.bpid &= cpu_to_le16(~(FD_BPID_MASK));278fd->simple.bpid |= cpu_to_le16(bpid);279}280281/**282* struct dpaa2_sg_entry - the scatter-gathering structure283* @addr: address of the sg entry284* @len: length in this sg entry285* @bpid: buffer pool id286* @format_offset: format and offset fields287*/288struct dpaa2_sg_entry {289__le64 addr;290__le32 len;291__le16 bpid;292__le16 format_offset;293};294295enum dpaa2_sg_format {296dpaa2_sg_single = 0,297dpaa2_sg_frame_data,298dpaa2_sg_sgt_ext299};300301/* Accessors for SG entry fields */302303/**304* dpaa2_sg_get_addr() - Get the address from SG entry305* @sg: the given scatter-gathering object306*307* Return the address.308*/309static inline dma_addr_t dpaa2_sg_get_addr(const struct dpaa2_sg_entry *sg)310{311return (dma_addr_t)le64_to_cpu(sg->addr);312}313314/**315* dpaa2_sg_set_addr() - Set the address in SG entry316* @sg: the given scatter-gathering object317* @addr: the address to be set318*/319static inline void dpaa2_sg_set_addr(struct dpaa2_sg_entry *sg, dma_addr_t addr)320{321sg->addr = cpu_to_le64(addr);322}323324static inline bool dpaa2_sg_short_len(const struct dpaa2_sg_entry *sg)325{326return !!((le16_to_cpu(sg->format_offset) >> SG_SHORT_LEN_FLAG_SHIFT)327& SG_SHORT_LEN_FLAG_MASK);328}329330/**331* dpaa2_sg_get_len() - Get the length in SG entry332* @sg: the given scatter-gathering object333*334* Return the length.335*/336static inline u32 dpaa2_sg_get_len(const struct dpaa2_sg_entry *sg)337{338if (dpaa2_sg_short_len(sg))339return le32_to_cpu(sg->len) & SG_SHORT_LEN_MASK;340341return le32_to_cpu(sg->len);342}343344/**345* dpaa2_sg_set_len() - Set the length in SG entry346* @sg: the given scatter-gathering object347* @len: the length to be set348*/349static inline void dpaa2_sg_set_len(struct dpaa2_sg_entry *sg, u32 len)350{351sg->len = cpu_to_le32(len);352}353354/**355* dpaa2_sg_get_offset() - Get the offset in SG entry356* @sg: the given scatter-gathering object357*358* Return the offset.359*/360static inline u16 dpaa2_sg_get_offset(const struct dpaa2_sg_entry *sg)361{362return le16_to_cpu(sg->format_offset) & SG_OFFSET_MASK;363}364365/**366* dpaa2_sg_set_offset() - Set the offset in SG entry367* @sg: the given scatter-gathering object368* @offset: the offset to be set369*/370static inline void dpaa2_sg_set_offset(struct dpaa2_sg_entry *sg,371u16 offset)372{373sg->format_offset &= cpu_to_le16(~SG_OFFSET_MASK);374sg->format_offset |= cpu_to_le16(offset);375}376377/**378* dpaa2_sg_get_format() - Get the SG format in SG entry379* @sg: the given scatter-gathering object380*381* Return the format.382*/383static inline enum dpaa2_sg_format384dpaa2_sg_get_format(const struct dpaa2_sg_entry *sg)385{386return (enum dpaa2_sg_format)((le16_to_cpu(sg->format_offset)387>> SG_FORMAT_SHIFT) & SG_FORMAT_MASK);388}389390/**391* dpaa2_sg_set_format() - Set the SG format in SG entry392* @sg: the given scatter-gathering object393* @format: the format to be set394*/395static inline void dpaa2_sg_set_format(struct dpaa2_sg_entry *sg,396enum dpaa2_sg_format format)397{398sg->format_offset &= cpu_to_le16(~(SG_FORMAT_MASK << SG_FORMAT_SHIFT));399sg->format_offset |= cpu_to_le16(format << SG_FORMAT_SHIFT);400}401402/**403* dpaa2_sg_get_bpid() - Get the buffer pool id in SG entry404* @sg: the given scatter-gathering object405*406* Return the bpid.407*/408static inline u16 dpaa2_sg_get_bpid(const struct dpaa2_sg_entry *sg)409{410return le16_to_cpu(sg->bpid) & SG_BPID_MASK;411}412413/**414* dpaa2_sg_set_bpid() - Set the buffer pool id in SG entry415* @sg: the given scatter-gathering object416* @bpid: the bpid to be set417*/418static inline void dpaa2_sg_set_bpid(struct dpaa2_sg_entry *sg, u16 bpid)419{420sg->bpid &= cpu_to_le16(~(SG_BPID_MASK));421sg->bpid |= cpu_to_le16(bpid);422}423424/**425* dpaa2_sg_is_final() - Check final bit in SG entry426* @sg: the given scatter-gathering object427*428* Return bool.429*/430static inline bool dpaa2_sg_is_final(const struct dpaa2_sg_entry *sg)431{432return !!(le16_to_cpu(sg->format_offset) >> SG_FINAL_FLAG_SHIFT);433}434435/**436* dpaa2_sg_set_final() - Set the final bit in SG entry437* @sg: the given scatter-gathering object438* @final: the final boolean to be set439*/440static inline void dpaa2_sg_set_final(struct dpaa2_sg_entry *sg, bool final)441{442sg->format_offset &= cpu_to_le16((~(SG_FINAL_FLAG_MASK443<< SG_FINAL_FLAG_SHIFT)) & 0xFFFF);444sg->format_offset |= cpu_to_le16(final << SG_FINAL_FLAG_SHIFT);445}446447/**448* struct dpaa2_fl_entry - structure for frame list entry.449* @addr: address in the FLE450* @len: length in the FLE451* @bpid: buffer pool ID452* @format_offset: format, offset, and short-length fields453* @frc: frame context454* @ctrl: control bits...including pta, pvt1, pvt2, err, etc455* @flc: flow context address456*/457struct dpaa2_fl_entry {458__le64 addr;459__le32 len;460__le16 bpid;461__le16 format_offset;462__le32 frc;463__le32 ctrl;464__le64 flc;465};466467enum dpaa2_fl_format {468dpaa2_fl_single = 0,469dpaa2_fl_res,470dpaa2_fl_sg471};472473/**474* dpaa2_fl_get_addr() - get the addr field of FLE475* @fle: the given frame list entry476*477* Return the address in the frame list entry.478*/479static inline dma_addr_t dpaa2_fl_get_addr(const struct dpaa2_fl_entry *fle)480{481return (dma_addr_t)le64_to_cpu(fle->addr);482}483484/**485* dpaa2_fl_set_addr() - Set the addr field of FLE486* @fle: the given frame list entry487* @addr: the address needs to be set in frame list entry488*/489static inline void dpaa2_fl_set_addr(struct dpaa2_fl_entry *fle,490dma_addr_t addr)491{492fle->addr = cpu_to_le64(addr);493}494495/**496* dpaa2_fl_get_frc() - Get the frame context in the FLE497* @fle: the given frame list entry498*499* Return the frame context field in the frame lsit entry.500*/501static inline u32 dpaa2_fl_get_frc(const struct dpaa2_fl_entry *fle)502{503return le32_to_cpu(fle->frc);504}505506/**507* dpaa2_fl_set_frc() - Set the frame context in the FLE508* @fle: the given frame list entry509* @frc: the frame context needs to be set in frame list entry510*/511static inline void dpaa2_fl_set_frc(struct dpaa2_fl_entry *fle, u32 frc)512{513fle->frc = cpu_to_le32(frc);514}515516/**517* dpaa2_fl_get_ctrl() - Get the control bits in the FLE518* @fle: the given frame list entry519*520* Return the control bits field in the frame list entry.521*/522static inline u32 dpaa2_fl_get_ctrl(const struct dpaa2_fl_entry *fle)523{524return le32_to_cpu(fle->ctrl);525}526527/**528* dpaa2_fl_set_ctrl() - Set the control bits in the FLE529* @fle: the given frame list entry530* @ctrl: the control bits to be set in the frame list entry531*/532static inline void dpaa2_fl_set_ctrl(struct dpaa2_fl_entry *fle, u32 ctrl)533{534fle->ctrl = cpu_to_le32(ctrl);535}536537/**538* dpaa2_fl_get_flc() - Get the flow context in the FLE539* @fle: the given frame list entry540*541* Return the flow context in the frame list entry.542*/543static inline dma_addr_t dpaa2_fl_get_flc(const struct dpaa2_fl_entry *fle)544{545return (dma_addr_t)le64_to_cpu(fle->flc);546}547548/**549* dpaa2_fl_set_flc() - Set the flow context field of FLE550* @fle: the given frame list entry551* @flc_addr: the flow context needs to be set in frame list entry552*/553static inline void dpaa2_fl_set_flc(struct dpaa2_fl_entry *fle,554dma_addr_t flc_addr)555{556fle->flc = cpu_to_le64(flc_addr);557}558559static inline bool dpaa2_fl_short_len(const struct dpaa2_fl_entry *fle)560{561return !!((le16_to_cpu(fle->format_offset) >>562FL_SHORT_LEN_FLAG_SHIFT) & FL_SHORT_LEN_FLAG_MASK);563}564565/**566* dpaa2_fl_get_len() - Get the length in the FLE567* @fle: the given frame list entry568*569* Return the length field in the frame list entry.570*/571static inline u32 dpaa2_fl_get_len(const struct dpaa2_fl_entry *fle)572{573if (dpaa2_fl_short_len(fle))574return le32_to_cpu(fle->len) & FL_SHORT_LEN_MASK;575576return le32_to_cpu(fle->len);577}578579/**580* dpaa2_fl_set_len() - Set the length field of FLE581* @fle: the given frame list entry582* @len: the length needs to be set in frame list entry583*/584static inline void dpaa2_fl_set_len(struct dpaa2_fl_entry *fle, u32 len)585{586fle->len = cpu_to_le32(len);587}588589/**590* dpaa2_fl_get_offset() - Get the offset field in the frame list entry591* @fle: the given frame list entry592*593* Return the offset.594*/595static inline u16 dpaa2_fl_get_offset(const struct dpaa2_fl_entry *fle)596{597return le16_to_cpu(fle->format_offset) & FL_OFFSET_MASK;598}599600/**601* dpaa2_fl_set_offset() - Set the offset field of FLE602* @fle: the given frame list entry603* @offset: the offset needs to be set in frame list entry604*/605static inline void dpaa2_fl_set_offset(struct dpaa2_fl_entry *fle, u16 offset)606{607fle->format_offset &= cpu_to_le16(~FL_OFFSET_MASK);608fle->format_offset |= cpu_to_le16(offset);609}610611/**612* dpaa2_fl_get_format() - Get the format field in the FLE613* @fle: the given frame list entry614*615* Return the format.616*/617static inline enum dpaa2_fl_format dpaa2_fl_get_format(const struct dpaa2_fl_entry *fle)618{619return (enum dpaa2_fl_format)((le16_to_cpu(fle->format_offset) >>620FL_FORMAT_SHIFT) & FL_FORMAT_MASK);621}622623/**624* dpaa2_fl_set_format() - Set the format field of FLE625* @fle: the given frame list entry626* @format: the format needs to be set in frame list entry627*/628static inline void dpaa2_fl_set_format(struct dpaa2_fl_entry *fle,629enum dpaa2_fl_format format)630{631fle->format_offset &= cpu_to_le16(~(FL_FORMAT_MASK << FL_FORMAT_SHIFT));632fle->format_offset |= cpu_to_le16(format << FL_FORMAT_SHIFT);633}634635/**636* dpaa2_fl_get_bpid() - Get the bpid field in the FLE637* @fle: the given frame list entry638*639* Return the buffer pool id.640*/641static inline u16 dpaa2_fl_get_bpid(const struct dpaa2_fl_entry *fle)642{643return le16_to_cpu(fle->bpid) & FL_BPID_MASK;644}645646/**647* dpaa2_fl_set_bpid() - Set the bpid field of FLE648* @fle: the given frame list entry649* @bpid: buffer pool id to be set650*/651static inline void dpaa2_fl_set_bpid(struct dpaa2_fl_entry *fle, u16 bpid)652{653fle->bpid &= cpu_to_le16(~(FL_BPID_MASK));654fle->bpid |= cpu_to_le16(bpid);655}656657/**658* dpaa2_fl_is_final() - Check final bit in FLE659* @fle: the given frame list entry660*661* Return bool.662*/663static inline bool dpaa2_fl_is_final(const struct dpaa2_fl_entry *fle)664{665return !!(le16_to_cpu(fle->format_offset) >> FL_FINAL_FLAG_SHIFT);666}667668/**669* dpaa2_fl_set_final() - Set the final bit in FLE670* @fle: the given frame list entry671* @final: the final boolean to be set672*/673static inline void dpaa2_fl_set_final(struct dpaa2_fl_entry *fle, bool final)674{675fle->format_offset &= cpu_to_le16((~(FL_FINAL_FLAG_MASK <<676FL_FINAL_FLAG_SHIFT)) & 0xFFFF);677fle->format_offset |= cpu_to_le16(final << FL_FINAL_FLAG_SHIFT);678}679680#endif /* __FSL_DPAA2_FD_H */681682683