dpaa2-fd.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
  2. /*
  3. * Copyright 2014-2016 Freescale Semiconductor Inc.
  4. * Copyright 2016 NXP
  5. *
  6. */
  7. #ifndef __FSL_DPAA2_FD_H
  8. #define __FSL_DPAA2_FD_H
  9. #include <linux/kernel.h>
  10. /**
  11. * DOC: DPAA2 FD - Frame Descriptor APIs for DPAA2
  12. *
  13. * Frame Descriptors (FDs) are used to describe frame data in the DPAA2.
  14. * Frames can be enqueued and dequeued to Frame Queues (FQs) which are consumed
  15. * by the various DPAA accelerators (WRIOP, SEC, PME, DCE)
  16. *
  17. * There are three types of frames: single, scatter gather, and frame lists.
  18. *
  19. * The set of APIs in this file must be used to create, manipulate and
  20. * query Frame Descriptors.
  21. */
  22. /**
  23. * struct dpaa2_fd - Struct describing FDs
  24. * @words: for easier/faster copying the whole FD structure
  25. * @addr: address in the FD
  26. * @len: length in the FD
  27. * @bpid: buffer pool ID
  28. * @format_offset: format, offset, and short-length fields
  29. * @frc: frame context
  30. * @ctrl: control bits...including dd, sc, va, err, etc
  31. * @flc: flow context address
  32. *
  33. * This structure represents the basic Frame Descriptor used in the system.
  34. */
  35. struct dpaa2_fd {
  36. union {
  37. u32 words[8];
  38. struct dpaa2_fd_simple {
  39. __le64 addr;
  40. __le32 len;
  41. __le16 bpid;
  42. __le16 format_offset;
  43. __le32 frc;
  44. __le32 ctrl;
  45. __le64 flc;
  46. } simple;
  47. };
  48. };
  49. #define FD_SHORT_LEN_FLAG_MASK 0x1
  50. #define FD_SHORT_LEN_FLAG_SHIFT 14
  51. #define FD_SHORT_LEN_MASK 0x3FFFF
  52. #define FD_OFFSET_MASK 0x0FFF
  53. #define FD_FORMAT_MASK 0x3
  54. #define FD_FORMAT_SHIFT 12
  55. #define FD_BPID_MASK 0x3FFF
  56. #define SG_SHORT_LEN_FLAG_MASK 0x1
  57. #define SG_SHORT_LEN_FLAG_SHIFT 14
  58. #define SG_SHORT_LEN_MASK 0x1FFFF
  59. #define SG_OFFSET_MASK 0x0FFF
  60. #define SG_FORMAT_MASK 0x3
  61. #define SG_FORMAT_SHIFT 12
  62. #define SG_BPID_MASK 0x3FFF
  63. #define SG_FINAL_FLAG_MASK 0x1
  64. #define SG_FINAL_FLAG_SHIFT 15
  65. /* Error bits in FD CTRL */
  66. #define FD_CTRL_ERR_MASK 0x000000FF
  67. #define FD_CTRL_UFD 0x00000004
  68. #define FD_CTRL_SBE 0x00000008
  69. #define FD_CTRL_FLC 0x00000010
  70. #define FD_CTRL_FSE 0x00000020
  71. #define FD_CTRL_FAERR 0x00000040
  72. /* Annotation bits in FD CTRL */
  73. #define FD_CTRL_PTA 0x00800000
  74. #define FD_CTRL_PTV1 0x00400000
  75. enum dpaa2_fd_format {
  76. dpaa2_fd_single = 0,
  77. dpaa2_fd_list,
  78. dpaa2_fd_sg
  79. };
  80. /**
  81. * dpaa2_fd_get_addr() - get the addr field of frame descriptor
  82. * @fd: the given frame descriptor
  83. *
  84. * Return the address in the frame descriptor.
  85. */
  86. static inline dma_addr_t dpaa2_fd_get_addr(const struct dpaa2_fd *fd)
  87. {
  88. return (dma_addr_t)le64_to_cpu(fd->simple.addr);
  89. }
  90. /**
  91. * dpaa2_fd_set_addr() - Set the addr field of frame descriptor
  92. * @fd: the given frame descriptor
  93. * @addr: the address needs to be set in frame descriptor
  94. */
  95. static inline void dpaa2_fd_set_addr(struct dpaa2_fd *fd, dma_addr_t addr)
  96. {
  97. fd->simple.addr = cpu_to_le64(addr);
  98. }
  99. /**
  100. * dpaa2_fd_get_frc() - Get the frame context in the frame descriptor
  101. * @fd: the given frame descriptor
  102. *
  103. * Return the frame context field in the frame descriptor.
  104. */
  105. static inline u32 dpaa2_fd_get_frc(const struct dpaa2_fd *fd)
  106. {
  107. return le32_to_cpu(fd->simple.frc);
  108. }
  109. /**
  110. * dpaa2_fd_set_frc() - Set the frame context in the frame descriptor
  111. * @fd: the given frame descriptor
  112. * @frc: the frame context needs to be set in frame descriptor
  113. */
  114. static inline void dpaa2_fd_set_frc(struct dpaa2_fd *fd, u32 frc)
  115. {
  116. fd->simple.frc = cpu_to_le32(frc);
  117. }
  118. /**
  119. * dpaa2_fd_get_ctrl() - Get the control bits in the frame descriptor
  120. * @fd: the given frame descriptor
  121. *
  122. * Return the control bits field in the frame descriptor.
  123. */
  124. static inline u32 dpaa2_fd_get_ctrl(const struct dpaa2_fd *fd)
  125. {
  126. return le32_to_cpu(fd->simple.ctrl);
  127. }
  128. /**
  129. * dpaa2_fd_set_ctrl() - Set the control bits in the frame descriptor
  130. * @fd: the given frame descriptor
  131. * @ctrl: the control bits to be set in the frame descriptor
  132. */
  133. static inline void dpaa2_fd_set_ctrl(struct dpaa2_fd *fd, u32 ctrl)
  134. {
  135. fd->simple.ctrl = cpu_to_le32(ctrl);
  136. }
  137. /**
  138. * dpaa2_fd_get_flc() - Get the flow context in the frame descriptor
  139. * @fd: the given frame descriptor
  140. *
  141. * Return the flow context in the frame descriptor.
  142. */
  143. static inline dma_addr_t dpaa2_fd_get_flc(const struct dpaa2_fd *fd)
  144. {
  145. return (dma_addr_t)le64_to_cpu(fd->simple.flc);
  146. }
  147. /**
  148. * dpaa2_fd_set_flc() - Set the flow context field of frame descriptor
  149. * @fd: the given frame descriptor
  150. * @flc_addr: the flow context needs to be set in frame descriptor
  151. */
  152. static inline void dpaa2_fd_set_flc(struct dpaa2_fd *fd, dma_addr_t flc_addr)
  153. {
  154. fd->simple.flc = cpu_to_le64(flc_addr);
  155. }
  156. static inline bool dpaa2_fd_short_len(const struct dpaa2_fd *fd)
  157. {
  158. return !!((le16_to_cpu(fd->simple.format_offset) >>
  159. FD_SHORT_LEN_FLAG_SHIFT) & FD_SHORT_LEN_FLAG_MASK);
  160. }
  161. /**
  162. * dpaa2_fd_get_len() - Get the length in the frame descriptor
  163. * @fd: the given frame descriptor
  164. *
  165. * Return the length field in the frame descriptor.
  166. */
  167. static inline u32 dpaa2_fd_get_len(const struct dpaa2_fd *fd)
  168. {
  169. if (dpaa2_fd_short_len(fd))
  170. return le32_to_cpu(fd->simple.len) & FD_SHORT_LEN_MASK;
  171. return le32_to_cpu(fd->simple.len);
  172. }
  173. /**
  174. * dpaa2_fd_set_len() - Set the length field of frame descriptor
  175. * @fd: the given frame descriptor
  176. * @len: the length needs to be set in frame descriptor
  177. */
  178. static inline void dpaa2_fd_set_len(struct dpaa2_fd *fd, u32 len)
  179. {
  180. fd->simple.len = cpu_to_le32(len);
  181. }
  182. /**
  183. * dpaa2_fd_get_offset() - Get the offset field in the frame descriptor
  184. * @fd: the given frame descriptor
  185. *
  186. * Return the offset.
  187. */
  188. static inline uint16_t dpaa2_fd_get_offset(const struct dpaa2_fd *fd)
  189. {
  190. return le16_to_cpu(fd->simple.format_offset) & FD_OFFSET_MASK;
  191. }
  192. /**
  193. * dpaa2_fd_set_offset() - Set the offset field of frame descriptor
  194. * @fd: the given frame descriptor
  195. * @offset: the offset needs to be set in frame descriptor
  196. */
  197. static inline void dpaa2_fd_set_offset(struct dpaa2_fd *fd, uint16_t offset)
  198. {
  199. fd->simple.format_offset &= cpu_to_le16(~FD_OFFSET_MASK);
  200. fd->simple.format_offset |= cpu_to_le16(offset);
  201. }
  202. /**
  203. * dpaa2_fd_get_format() - Get the format field in the frame descriptor
  204. * @fd: the given frame descriptor
  205. *
  206. * Return the format.
  207. */
  208. static inline enum dpaa2_fd_format dpaa2_fd_get_format(
  209. const struct dpaa2_fd *fd)
  210. {
  211. return (enum dpaa2_fd_format)((le16_to_cpu(fd->simple.format_offset)
  212. >> FD_FORMAT_SHIFT) & FD_FORMAT_MASK);
  213. }
  214. /**
  215. * dpaa2_fd_set_format() - Set the format field of frame descriptor
  216. * @fd: the given frame descriptor
  217. * @format: the format needs to be set in frame descriptor
  218. */
  219. static inline void dpaa2_fd_set_format(struct dpaa2_fd *fd,
  220. enum dpaa2_fd_format format)
  221. {
  222. fd->simple.format_offset &=
  223. cpu_to_le16(~(FD_FORMAT_MASK << FD_FORMAT_SHIFT));
  224. fd->simple.format_offset |= cpu_to_le16(format << FD_FORMAT_SHIFT);
  225. }
  226. /**
  227. * dpaa2_fd_get_bpid() - Get the bpid field in the frame descriptor
  228. * @fd: the given frame descriptor
  229. *
  230. * Return the buffer pool id.
  231. */
  232. static inline uint16_t dpaa2_fd_get_bpid(const struct dpaa2_fd *fd)
  233. {
  234. return le16_to_cpu(fd->simple.bpid) & FD_BPID_MASK;
  235. }
  236. /**
  237. * dpaa2_fd_set_bpid() - Set the bpid field of frame descriptor
  238. * @fd: the given frame descriptor
  239. * @bpid: buffer pool id to be set
  240. */
  241. static inline void dpaa2_fd_set_bpid(struct dpaa2_fd *fd, uint16_t bpid)
  242. {
  243. fd->simple.bpid &= cpu_to_le16(~(FD_BPID_MASK));
  244. fd->simple.bpid |= cpu_to_le16(bpid);
  245. }
  246. /**
  247. * struct dpaa2_sg_entry - the scatter-gathering structure
  248. * @addr: address of the sg entry
  249. * @len: length in this sg entry
  250. * @bpid: buffer pool id
  251. * @format_offset: format and offset fields
  252. */
  253. struct dpaa2_sg_entry {
  254. __le64 addr;
  255. __le32 len;
  256. __le16 bpid;
  257. __le16 format_offset;
  258. };
  259. enum dpaa2_sg_format {
  260. dpaa2_sg_single = 0,
  261. dpaa2_sg_frame_data,
  262. dpaa2_sg_sgt_ext
  263. };
  264. /* Accessors for SG entry fields */
  265. /**
  266. * dpaa2_sg_get_addr() - Get the address from SG entry
  267. * @sg: the given scatter-gathering object
  268. *
  269. * Return the address.
  270. */
  271. static inline dma_addr_t dpaa2_sg_get_addr(const struct dpaa2_sg_entry *sg)
  272. {
  273. return (dma_addr_t)le64_to_cpu(sg->addr);
  274. }
  275. /**
  276. * dpaa2_sg_set_addr() - Set the address in SG entry
  277. * @sg: the given scatter-gathering object
  278. * @addr: the address to be set
  279. */
  280. static inline void dpaa2_sg_set_addr(struct dpaa2_sg_entry *sg, dma_addr_t addr)
  281. {
  282. sg->addr = cpu_to_le64(addr);
  283. }
  284. static inline bool dpaa2_sg_short_len(const struct dpaa2_sg_entry *sg)
  285. {
  286. return !!((le16_to_cpu(sg->format_offset) >> SG_SHORT_LEN_FLAG_SHIFT)
  287. & SG_SHORT_LEN_FLAG_MASK);
  288. }
  289. /**
  290. * dpaa2_sg_get_len() - Get the length in SG entry
  291. * @sg: the given scatter-gathering object
  292. *
  293. * Return the length.
  294. */
  295. static inline u32 dpaa2_sg_get_len(const struct dpaa2_sg_entry *sg)
  296. {
  297. if (dpaa2_sg_short_len(sg))
  298. return le32_to_cpu(sg->len) & SG_SHORT_LEN_MASK;
  299. return le32_to_cpu(sg->len);
  300. }
  301. /**
  302. * dpaa2_sg_set_len() - Set the length in SG entry
  303. * @sg: the given scatter-gathering object
  304. * @len: the length to be set
  305. */
  306. static inline void dpaa2_sg_set_len(struct dpaa2_sg_entry *sg, u32 len)
  307. {
  308. sg->len = cpu_to_le32(len);
  309. }
  310. /**
  311. * dpaa2_sg_get_offset() - Get the offset in SG entry
  312. * @sg: the given scatter-gathering object
  313. *
  314. * Return the offset.
  315. */
  316. static inline u16 dpaa2_sg_get_offset(const struct dpaa2_sg_entry *sg)
  317. {
  318. return le16_to_cpu(sg->format_offset) & SG_OFFSET_MASK;
  319. }
  320. /**
  321. * dpaa2_sg_set_offset() - Set the offset in SG entry
  322. * @sg: the given scatter-gathering object
  323. * @offset: the offset to be set
  324. */
  325. static inline void dpaa2_sg_set_offset(struct dpaa2_sg_entry *sg,
  326. u16 offset)
  327. {
  328. sg->format_offset &= cpu_to_le16(~SG_OFFSET_MASK);
  329. sg->format_offset |= cpu_to_le16(offset);
  330. }
  331. /**
  332. * dpaa2_sg_get_format() - Get the SG format in SG entry
  333. * @sg: the given scatter-gathering object
  334. *
  335. * Return the format.
  336. */
  337. static inline enum dpaa2_sg_format
  338. dpaa2_sg_get_format(const struct dpaa2_sg_entry *sg)
  339. {
  340. return (enum dpaa2_sg_format)((le16_to_cpu(sg->format_offset)
  341. >> SG_FORMAT_SHIFT) & SG_FORMAT_MASK);
  342. }
  343. /**
  344. * dpaa2_sg_set_format() - Set the SG format in SG entry
  345. * @sg: the given scatter-gathering object
  346. * @format: the format to be set
  347. */
  348. static inline void dpaa2_sg_set_format(struct dpaa2_sg_entry *sg,
  349. enum dpaa2_sg_format format)
  350. {
  351. sg->format_offset &= cpu_to_le16(~(SG_FORMAT_MASK << SG_FORMAT_SHIFT));
  352. sg->format_offset |= cpu_to_le16(format << SG_FORMAT_SHIFT);
  353. }
  354. /**
  355. * dpaa2_sg_get_bpid() - Get the buffer pool id in SG entry
  356. * @sg: the given scatter-gathering object
  357. *
  358. * Return the bpid.
  359. */
  360. static inline u16 dpaa2_sg_get_bpid(const struct dpaa2_sg_entry *sg)
  361. {
  362. return le16_to_cpu(sg->bpid) & SG_BPID_MASK;
  363. }
  364. /**
  365. * dpaa2_sg_set_bpid() - Set the buffer pool id in SG entry
  366. * @sg: the given scatter-gathering object
  367. * @bpid: the bpid to be set
  368. */
  369. static inline void dpaa2_sg_set_bpid(struct dpaa2_sg_entry *sg, u16 bpid)
  370. {
  371. sg->bpid &= cpu_to_le16(~(SG_BPID_MASK));
  372. sg->bpid |= cpu_to_le16(bpid);
  373. }
  374. /**
  375. * dpaa2_sg_is_final() - Check final bit in SG entry
  376. * @sg: the given scatter-gathering object
  377. *
  378. * Return bool.
  379. */
  380. static inline bool dpaa2_sg_is_final(const struct dpaa2_sg_entry *sg)
  381. {
  382. return !!(le16_to_cpu(sg->format_offset) >> SG_FINAL_FLAG_SHIFT);
  383. }
  384. /**
  385. * dpaa2_sg_set_final() - Set the final bit in SG entry
  386. * @sg: the given scatter-gathering object
  387. * @final: the final boolean to be set
  388. */
  389. static inline void dpaa2_sg_set_final(struct dpaa2_sg_entry *sg, bool final)
  390. {
  391. sg->format_offset &= cpu_to_le16((~(SG_FINAL_FLAG_MASK
  392. << SG_FINAL_FLAG_SHIFT)) & 0xFFFF);
  393. sg->format_offset |= cpu_to_le16(final << SG_FINAL_FLAG_SHIFT);
  394. }
  395. #endif /* __FSL_DPAA2_FD_H */