brintos

brintos / linux-shallow public Read only

0
0
Text · 17.6 KiB · bae490c Raw
682 lines · c
1/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */2/*3 * Copyright 2014-2016 Freescale Semiconductor Inc.4 * Copyright 2016 NXP5 *6 */7#ifndef __FSL_DPAA2_FD_H8#define __FSL_DPAA2_FD_H9 10#include <linux/byteorder/generic.h>11#include <linux/types.h>12 13/**14 * DOC: DPAA2 FD - Frame Descriptor APIs for DPAA215 *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 consumed18 * by the various DPAA accelerators (WRIOP, SEC, PME, DCE)19 *20 * There are three types of frames: single, scatter gather, and frame lists.21 *22 * The set of APIs in this file must be used to create, manipulate and23 * query Frame Descriptors.24 */25 26/**27 * struct dpaa2_fd - Struct describing FDs28 * @words:         for easier/faster copying the whole FD structure29 * @addr:          address in the FD30 * @len:           length in the FD31 * @bpid:          buffer pool ID32 * @format_offset: format, offset, and short-length fields33 * @frc:           frame context34 * @ctrl:          control bits...including dd, sc, va, err, etc35 * @flc:           flow context address36 *37 * This structure represents the basic Frame Descriptor used in the system.38 */39struct dpaa2_fd {40	union {41		u32 words[8];42		struct dpaa2_fd_simple {43			__le64 addr;44			__le32 len;45			__le16 bpid;46			__le16 format_offset;47			__le32 frc;48			__le32 ctrl;49			__le64 flc;50		} simple;51	};52};53 54#define FD_SHORT_LEN_FLAG_MASK	0x155#define FD_SHORT_LEN_FLAG_SHIFT	1456#define FD_SHORT_LEN_MASK	0x3FFFF57#define FD_OFFSET_MASK		0x0FFF58#define FD_FORMAT_MASK		0x359#define FD_FORMAT_SHIFT		1260#define FD_BPID_MASK		0x3FFF61#define SG_SHORT_LEN_FLAG_MASK	0x162#define SG_SHORT_LEN_FLAG_SHIFT	1463#define SG_SHORT_LEN_MASK	0x1FFFF64#define SG_OFFSET_MASK		0x0FFF65#define SG_FORMAT_MASK		0x366#define SG_FORMAT_SHIFT		1267#define SG_BPID_MASK		0x3FFF68#define SG_FINAL_FLAG_MASK	0x169#define SG_FINAL_FLAG_SHIFT	1570#define FL_SHORT_LEN_FLAG_MASK	0x171#define FL_SHORT_LEN_FLAG_SHIFT	1472#define FL_SHORT_LEN_MASK	0x3FFFF73#define FL_OFFSET_MASK		0x0FFF74#define FL_FORMAT_MASK		0x375#define FL_FORMAT_SHIFT		1276#define FL_BPID_MASK		0x3FFF77#define FL_FINAL_FLAG_MASK	0x178#define FL_FINAL_FLAG_SHIFT	1579 80/* Error bits in FD CTRL */81#define FD_CTRL_ERR_MASK	0x000000FF82#define FD_CTRL_UFD		0x0000000483#define FD_CTRL_SBE		0x0000000884#define FD_CTRL_FLC		0x0000001085#define FD_CTRL_FSE		0x0000002086#define FD_CTRL_FAERR		0x0000004087 88/* Annotation bits in FD CTRL */89#define FD_CTRL_PTA		0x0080000090#define FD_CTRL_PTV1		0x0040000091 92enum dpaa2_fd_format {93	dpaa2_fd_single = 0,94	dpaa2_fd_list,95	dpaa2_fd_sg96};97 98/**99 * dpaa2_fd_get_addr() - get the addr field of frame descriptor100 * @fd: the given frame descriptor101 *102 * Return the address in the frame descriptor.103 */104static inline dma_addr_t dpaa2_fd_get_addr(const struct dpaa2_fd *fd)105{106	return (dma_addr_t)le64_to_cpu(fd->simple.addr);107}108 109/**110 * dpaa2_fd_set_addr() - Set the addr field of frame descriptor111 * @fd: the given frame descriptor112 * @addr: the address needs to be set in frame descriptor113 */114static inline void dpaa2_fd_set_addr(struct dpaa2_fd *fd, dma_addr_t addr)115{116	fd->simple.addr = cpu_to_le64(addr);117}118 119/**120 * dpaa2_fd_get_frc() - Get the frame context in the frame descriptor121 * @fd: the given frame descriptor122 *123 * Return the frame context field in the frame descriptor.124 */125static inline u32 dpaa2_fd_get_frc(const struct dpaa2_fd *fd)126{127	return le32_to_cpu(fd->simple.frc);128}129 130/**131 * dpaa2_fd_set_frc() - Set the frame context in the frame descriptor132 * @fd: the given frame descriptor133 * @frc: the frame context needs to be set in frame descriptor134 */135static inline void dpaa2_fd_set_frc(struct dpaa2_fd *fd, u32 frc)136{137	fd->simple.frc = cpu_to_le32(frc);138}139 140/**141 * dpaa2_fd_get_ctrl() - Get the control bits in the frame descriptor142 * @fd: the given frame descriptor143 *144 * Return the control bits field in the frame descriptor.145 */146static inline u32 dpaa2_fd_get_ctrl(const struct dpaa2_fd *fd)147{148	return le32_to_cpu(fd->simple.ctrl);149}150 151/**152 * dpaa2_fd_set_ctrl() - Set the control bits in the frame descriptor153 * @fd: the given frame descriptor154 * @ctrl: the control bits to be set in the frame descriptor155 */156static inline void dpaa2_fd_set_ctrl(struct dpaa2_fd *fd, u32 ctrl)157{158	fd->simple.ctrl = cpu_to_le32(ctrl);159}160 161/**162 * dpaa2_fd_get_flc() - Get the flow context in the frame descriptor163 * @fd: the given frame descriptor164 *165 * Return the flow context in the frame descriptor.166 */167static inline dma_addr_t dpaa2_fd_get_flc(const struct dpaa2_fd *fd)168{169	return (dma_addr_t)le64_to_cpu(fd->simple.flc);170}171 172/**173 * dpaa2_fd_set_flc() - Set the flow context field of frame descriptor174 * @fd: the given frame descriptor175 * @flc_addr: the flow context needs to be set in frame descriptor176 */177static inline void dpaa2_fd_set_flc(struct dpaa2_fd *fd,  dma_addr_t flc_addr)178{179	fd->simple.flc = cpu_to_le64(flc_addr);180}181 182static inline bool dpaa2_fd_short_len(const struct dpaa2_fd *fd)183{184	return !!((le16_to_cpu(fd->simple.format_offset) >>185		  FD_SHORT_LEN_FLAG_SHIFT) & FD_SHORT_LEN_FLAG_MASK);186}187 188/**189 * dpaa2_fd_get_len() - Get the length in the frame descriptor190 * @fd: the given frame descriptor191 *192 * Return the length field in the frame descriptor.193 */194static inline u32 dpaa2_fd_get_len(const struct dpaa2_fd *fd)195{196	if (dpaa2_fd_short_len(fd))197		return le32_to_cpu(fd->simple.len) & FD_SHORT_LEN_MASK;198 199	return le32_to_cpu(fd->simple.len);200}201 202/**203 * dpaa2_fd_set_len() - Set the length field of frame descriptor204 * @fd: the given frame descriptor205 * @len: the length needs to be set in frame descriptor206 */207static inline void dpaa2_fd_set_len(struct dpaa2_fd *fd, u32 len)208{209	fd->simple.len = cpu_to_le32(len);210}211 212/**213 * dpaa2_fd_get_offset() - Get the offset field in the frame descriptor214 * @fd: the given frame descriptor215 *216 * Return the offset.217 */218static inline uint16_t dpaa2_fd_get_offset(const struct dpaa2_fd *fd)219{220	return le16_to_cpu(fd->simple.format_offset) & FD_OFFSET_MASK;221}222 223/**224 * dpaa2_fd_set_offset() - Set the offset field of frame descriptor225 * @fd: the given frame descriptor226 * @offset: the offset needs to be set in frame descriptor227 */228static inline void dpaa2_fd_set_offset(struct dpaa2_fd *fd, uint16_t offset)229{230	fd->simple.format_offset &= cpu_to_le16(~FD_OFFSET_MASK);231	fd->simple.format_offset |= cpu_to_le16(offset);232}233 234/**235 * dpaa2_fd_get_format() - Get the format field in the frame descriptor236 * @fd: the given frame descriptor237 *238 * Return the format.239 */240static inline enum dpaa2_fd_format dpaa2_fd_get_format(241						const struct dpaa2_fd *fd)242{243	return (enum dpaa2_fd_format)((le16_to_cpu(fd->simple.format_offset)244				      >> FD_FORMAT_SHIFT) & FD_FORMAT_MASK);245}246 247/**248 * dpaa2_fd_set_format() - Set the format field of frame descriptor249 * @fd: the given frame descriptor250 * @format: the format needs to be set in frame descriptor251 */252static inline void dpaa2_fd_set_format(struct dpaa2_fd *fd,253				       enum dpaa2_fd_format format)254{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);258}259 260/**261 * dpaa2_fd_get_bpid() - Get the bpid field in the frame descriptor262 * @fd: the given frame descriptor263 *264 * Return the buffer pool id.265 */266static inline uint16_t dpaa2_fd_get_bpid(const struct dpaa2_fd *fd)267{268	return le16_to_cpu(fd->simple.bpid) & FD_BPID_MASK;269}270 271/**272 * dpaa2_fd_set_bpid() - Set the bpid field of frame descriptor273 * @fd: the given frame descriptor274 * @bpid: buffer pool id to be set275 */276static inline void dpaa2_fd_set_bpid(struct dpaa2_fd *fd, uint16_t bpid)277{278	fd->simple.bpid &= cpu_to_le16(~(FD_BPID_MASK));279	fd->simple.bpid |= cpu_to_le16(bpid);280}281 282/**283 * struct dpaa2_sg_entry - the scatter-gathering structure284 * @addr: address of the sg entry285 * @len: length in this sg entry286 * @bpid: buffer pool id287 * @format_offset: format and offset fields288 */289struct dpaa2_sg_entry {290	__le64 addr;291	__le32 len;292	__le16 bpid;293	__le16 format_offset;294};295 296enum dpaa2_sg_format {297	dpaa2_sg_single = 0,298	dpaa2_sg_frame_data,299	dpaa2_sg_sgt_ext300};301 302/* Accessors for SG entry fields */303 304/**305 * dpaa2_sg_get_addr() - Get the address from SG entry306 * @sg: the given scatter-gathering object307 *308 * Return the address.309 */310static inline dma_addr_t dpaa2_sg_get_addr(const struct dpaa2_sg_entry *sg)311{312	return (dma_addr_t)le64_to_cpu(sg->addr);313}314 315/**316 * dpaa2_sg_set_addr() - Set the address in SG entry317 * @sg: the given scatter-gathering object318 * @addr: the address to be set319 */320static inline void dpaa2_sg_set_addr(struct dpaa2_sg_entry *sg, dma_addr_t addr)321{322	sg->addr = cpu_to_le64(addr);323}324 325static inline bool dpaa2_sg_short_len(const struct dpaa2_sg_entry *sg)326{327	return !!((le16_to_cpu(sg->format_offset) >> SG_SHORT_LEN_FLAG_SHIFT)328		& SG_SHORT_LEN_FLAG_MASK);329}330 331/**332 * dpaa2_sg_get_len() - Get the length in SG entry333 * @sg: the given scatter-gathering object334 *335 * Return the length.336 */337static inline u32 dpaa2_sg_get_len(const struct dpaa2_sg_entry *sg)338{339	if (dpaa2_sg_short_len(sg))340		return le32_to_cpu(sg->len) & SG_SHORT_LEN_MASK;341 342	return le32_to_cpu(sg->len);343}344 345/**346 * dpaa2_sg_set_len() - Set the length in SG entry347 * @sg: the given scatter-gathering object348 * @len: the length to be set349 */350static inline void dpaa2_sg_set_len(struct dpaa2_sg_entry *sg, u32 len)351{352	sg->len = cpu_to_le32(len);353}354 355/**356 * dpaa2_sg_get_offset() - Get the offset in SG entry357 * @sg: the given scatter-gathering object358 *359 * Return the offset.360 */361static inline u16 dpaa2_sg_get_offset(const struct dpaa2_sg_entry *sg)362{363	return le16_to_cpu(sg->format_offset) & SG_OFFSET_MASK;364}365 366/**367 * dpaa2_sg_set_offset() - Set the offset in SG entry368 * @sg: the given scatter-gathering object369 * @offset: the offset to be set370 */371static inline void dpaa2_sg_set_offset(struct dpaa2_sg_entry *sg,372				       u16 offset)373{374	sg->format_offset &= cpu_to_le16(~SG_OFFSET_MASK);375	sg->format_offset |= cpu_to_le16(offset);376}377 378/**379 * dpaa2_sg_get_format() - Get the SG format in SG entry380 * @sg: the given scatter-gathering object381 *382 * Return the format.383 */384static inline enum dpaa2_sg_format385	dpaa2_sg_get_format(const struct dpaa2_sg_entry *sg)386{387	return (enum dpaa2_sg_format)((le16_to_cpu(sg->format_offset)388				       >> SG_FORMAT_SHIFT) & SG_FORMAT_MASK);389}390 391/**392 * dpaa2_sg_set_format() - Set the SG format in SG entry393 * @sg: the given scatter-gathering object394 * @format: the format to be set395 */396static inline void dpaa2_sg_set_format(struct dpaa2_sg_entry *sg,397				       enum dpaa2_sg_format format)398{399	sg->format_offset &= cpu_to_le16(~(SG_FORMAT_MASK << SG_FORMAT_SHIFT));400	sg->format_offset |= cpu_to_le16(format << SG_FORMAT_SHIFT);401}402 403/**404 * dpaa2_sg_get_bpid() - Get the buffer pool id in SG entry405 * @sg: the given scatter-gathering object406 *407 * Return the bpid.408 */409static inline u16 dpaa2_sg_get_bpid(const struct dpaa2_sg_entry *sg)410{411	return le16_to_cpu(sg->bpid) & SG_BPID_MASK;412}413 414/**415 * dpaa2_sg_set_bpid() - Set the buffer pool id in SG entry416 * @sg: the given scatter-gathering object417 * @bpid: the bpid to be set418 */419static inline void dpaa2_sg_set_bpid(struct dpaa2_sg_entry *sg, u16 bpid)420{421	sg->bpid &= cpu_to_le16(~(SG_BPID_MASK));422	sg->bpid |= cpu_to_le16(bpid);423}424 425/**426 * dpaa2_sg_is_final() - Check final bit in SG entry427 * @sg: the given scatter-gathering object428 *429 * Return bool.430 */431static inline bool dpaa2_sg_is_final(const struct dpaa2_sg_entry *sg)432{433	return !!(le16_to_cpu(sg->format_offset) >> SG_FINAL_FLAG_SHIFT);434}435 436/**437 * dpaa2_sg_set_final() - Set the final bit in SG entry438 * @sg: the given scatter-gathering object439 * @final: the final boolean to be set440 */441static inline void dpaa2_sg_set_final(struct dpaa2_sg_entry *sg, bool final)442{443	sg->format_offset &= cpu_to_le16((~(SG_FINAL_FLAG_MASK444					 << SG_FINAL_FLAG_SHIFT)) & 0xFFFF);445	sg->format_offset |= cpu_to_le16(final << SG_FINAL_FLAG_SHIFT);446}447 448/**449 * struct dpaa2_fl_entry - structure for frame list entry.450 * @addr:          address in the FLE451 * @len:           length in the FLE452 * @bpid:          buffer pool ID453 * @format_offset: format, offset, and short-length fields454 * @frc:           frame context455 * @ctrl:          control bits...including pta, pvt1, pvt2, err, etc456 * @flc:           flow context address457 */458struct dpaa2_fl_entry {459	__le64 addr;460	__le32 len;461	__le16 bpid;462	__le16 format_offset;463	__le32 frc;464	__le32 ctrl;465	__le64 flc;466};467 468enum dpaa2_fl_format {469	dpaa2_fl_single = 0,470	dpaa2_fl_res,471	dpaa2_fl_sg472};473 474/**475 * dpaa2_fl_get_addr() - get the addr field of FLE476 * @fle: the given frame list entry477 *478 * Return the address in the frame list entry.479 */480static inline dma_addr_t dpaa2_fl_get_addr(const struct dpaa2_fl_entry *fle)481{482	return (dma_addr_t)le64_to_cpu(fle->addr);483}484 485/**486 * dpaa2_fl_set_addr() - Set the addr field of FLE487 * @fle: the given frame list entry488 * @addr: the address needs to be set in frame list entry489 */490static inline void dpaa2_fl_set_addr(struct dpaa2_fl_entry *fle,491				     dma_addr_t addr)492{493	fle->addr = cpu_to_le64(addr);494}495 496/**497 * dpaa2_fl_get_frc() - Get the frame context in the FLE498 * @fle: the given frame list entry499 *500 * Return the frame context field in the frame lsit entry.501 */502static inline u32 dpaa2_fl_get_frc(const struct dpaa2_fl_entry *fle)503{504	return le32_to_cpu(fle->frc);505}506 507/**508 * dpaa2_fl_set_frc() - Set the frame context in the FLE509 * @fle: the given frame list entry510 * @frc: the frame context needs to be set in frame list entry511 */512static inline void dpaa2_fl_set_frc(struct dpaa2_fl_entry *fle, u32 frc)513{514	fle->frc = cpu_to_le32(frc);515}516 517/**518 * dpaa2_fl_get_ctrl() - Get the control bits in the FLE519 * @fle: the given frame list entry520 *521 * Return the control bits field in the frame list entry.522 */523static inline u32 dpaa2_fl_get_ctrl(const struct dpaa2_fl_entry *fle)524{525	return le32_to_cpu(fle->ctrl);526}527 528/**529 * dpaa2_fl_set_ctrl() - Set the control bits in the FLE530 * @fle: the given frame list entry531 * @ctrl: the control bits to be set in the frame list entry532 */533static inline void dpaa2_fl_set_ctrl(struct dpaa2_fl_entry *fle, u32 ctrl)534{535	fle->ctrl = cpu_to_le32(ctrl);536}537 538/**539 * dpaa2_fl_get_flc() - Get the flow context in the FLE540 * @fle: the given frame list entry541 *542 * Return the flow context in the frame list entry.543 */544static inline dma_addr_t dpaa2_fl_get_flc(const struct dpaa2_fl_entry *fle)545{546	return (dma_addr_t)le64_to_cpu(fle->flc);547}548 549/**550 * dpaa2_fl_set_flc() - Set the flow context field of FLE551 * @fle: the given frame list entry552 * @flc_addr: the flow context needs to be set in frame list entry553 */554static inline void dpaa2_fl_set_flc(struct dpaa2_fl_entry *fle,555				    dma_addr_t flc_addr)556{557	fle->flc = cpu_to_le64(flc_addr);558}559 560static inline bool dpaa2_fl_short_len(const struct dpaa2_fl_entry *fle)561{562	return !!((le16_to_cpu(fle->format_offset) >>563		  FL_SHORT_LEN_FLAG_SHIFT) & FL_SHORT_LEN_FLAG_MASK);564}565 566/**567 * dpaa2_fl_get_len() - Get the length in the FLE568 * @fle: the given frame list entry569 *570 * Return the length field in the frame list entry.571 */572static inline u32 dpaa2_fl_get_len(const struct dpaa2_fl_entry *fle)573{574	if (dpaa2_fl_short_len(fle))575		return le32_to_cpu(fle->len) & FL_SHORT_LEN_MASK;576 577	return le32_to_cpu(fle->len);578}579 580/**581 * dpaa2_fl_set_len() - Set the length field of FLE582 * @fle: the given frame list entry583 * @len: the length needs to be set in frame list entry584 */585static inline void dpaa2_fl_set_len(struct dpaa2_fl_entry *fle, u32 len)586{587	fle->len = cpu_to_le32(len);588}589 590/**591 * dpaa2_fl_get_offset() - Get the offset field in the frame list entry592 * @fle: the given frame list entry593 *594 * Return the offset.595 */596static inline u16 dpaa2_fl_get_offset(const struct dpaa2_fl_entry *fle)597{598	return le16_to_cpu(fle->format_offset) & FL_OFFSET_MASK;599}600 601/**602 * dpaa2_fl_set_offset() - Set the offset field of FLE603 * @fle: the given frame list entry604 * @offset: the offset needs to be set in frame list entry605 */606static inline void dpaa2_fl_set_offset(struct dpaa2_fl_entry *fle, u16 offset)607{608	fle->format_offset &= cpu_to_le16(~FL_OFFSET_MASK);609	fle->format_offset |= cpu_to_le16(offset);610}611 612/**613 * dpaa2_fl_get_format() - Get the format field in the FLE614 * @fle: the given frame list entry615 *616 * Return the format.617 */618static inline enum dpaa2_fl_format dpaa2_fl_get_format(const struct dpaa2_fl_entry *fle)619{620	return (enum dpaa2_fl_format)((le16_to_cpu(fle->format_offset) >>621				       FL_FORMAT_SHIFT) & FL_FORMAT_MASK);622}623 624/**625 * dpaa2_fl_set_format() - Set the format field of FLE626 * @fle: the given frame list entry627 * @format: the format needs to be set in frame list entry628 */629static inline void dpaa2_fl_set_format(struct dpaa2_fl_entry *fle,630				       enum dpaa2_fl_format format)631{632	fle->format_offset &= cpu_to_le16(~(FL_FORMAT_MASK << FL_FORMAT_SHIFT));633	fle->format_offset |= cpu_to_le16(format << FL_FORMAT_SHIFT);634}635 636/**637 * dpaa2_fl_get_bpid() - Get the bpid field in the FLE638 * @fle: the given frame list entry639 *640 * Return the buffer pool id.641 */642static inline u16 dpaa2_fl_get_bpid(const struct dpaa2_fl_entry *fle)643{644	return le16_to_cpu(fle->bpid) & FL_BPID_MASK;645}646 647/**648 * dpaa2_fl_set_bpid() - Set the bpid field of FLE649 * @fle: the given frame list entry650 * @bpid: buffer pool id to be set651 */652static inline void dpaa2_fl_set_bpid(struct dpaa2_fl_entry *fle, u16 bpid)653{654	fle->bpid &= cpu_to_le16(~(FL_BPID_MASK));655	fle->bpid |= cpu_to_le16(bpid);656}657 658/**659 * dpaa2_fl_is_final() - Check final bit in FLE660 * @fle: the given frame list entry661 *662 * Return bool.663 */664static inline bool dpaa2_fl_is_final(const struct dpaa2_fl_entry *fle)665{666	return !!(le16_to_cpu(fle->format_offset) >> FL_FINAL_FLAG_SHIFT);667}668 669/**670 * dpaa2_fl_set_final() - Set the final bit in FLE671 * @fle: the given frame list entry672 * @final: the final boolean to be set673 */674static inline void dpaa2_fl_set_final(struct dpaa2_fl_entry *fle, bool final)675{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);679}680 681#endif /* __FSL_DPAA2_FD_H */682