dpaa2-global.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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_GLOBAL_H
  8. #define __FSL_DPAA2_GLOBAL_H
  9. #include <linux/types.h>
  10. #include <linux/cpumask.h>
  11. #include "dpaa2-fd.h"
  12. struct dpaa2_dq {
  13. union {
  14. struct common {
  15. u8 verb;
  16. u8 reserved[63];
  17. } common;
  18. struct dq {
  19. u8 verb;
  20. u8 stat;
  21. __le16 seqnum;
  22. __le16 oprid;
  23. u8 reserved;
  24. u8 tok;
  25. __le32 fqid;
  26. u32 reserved2;
  27. __le32 fq_byte_cnt;
  28. __le32 fq_frm_cnt;
  29. __le64 fqd_ctx;
  30. u8 fd[32];
  31. } dq;
  32. struct scn {
  33. u8 verb;
  34. u8 stat;
  35. u8 state;
  36. u8 reserved;
  37. __le32 rid_tok;
  38. __le64 ctx;
  39. } scn;
  40. };
  41. };
  42. /* Parsing frame dequeue results */
  43. /* FQ empty */
  44. #define DPAA2_DQ_STAT_FQEMPTY 0x80
  45. /* FQ held active */
  46. #define DPAA2_DQ_STAT_HELDACTIVE 0x40
  47. /* FQ force eligible */
  48. #define DPAA2_DQ_STAT_FORCEELIGIBLE 0x20
  49. /* valid frame */
  50. #define DPAA2_DQ_STAT_VALIDFRAME 0x10
  51. /* FQ ODP enable */
  52. #define DPAA2_DQ_STAT_ODPVALID 0x04
  53. /* volatile dequeue */
  54. #define DPAA2_DQ_STAT_VOLATILE 0x02
  55. /* volatile dequeue command is expired */
  56. #define DPAA2_DQ_STAT_EXPIRED 0x01
  57. #define DQ_FQID_MASK 0x00FFFFFF
  58. #define DQ_FRAME_COUNT_MASK 0x00FFFFFF
  59. /**
  60. * dpaa2_dq_flags() - Get the stat field of dequeue response
  61. * @dq: the dequeue result.
  62. */
  63. static inline u32 dpaa2_dq_flags(const struct dpaa2_dq *dq)
  64. {
  65. return dq->dq.stat;
  66. }
  67. /**
  68. * dpaa2_dq_is_pull() - Check whether the dq response is from a pull
  69. * command.
  70. * @dq: the dequeue result
  71. *
  72. * Return 1 for volatile(pull) dequeue, 0 for static dequeue.
  73. */
  74. static inline int dpaa2_dq_is_pull(const struct dpaa2_dq *dq)
  75. {
  76. return (int)(dpaa2_dq_flags(dq) & DPAA2_DQ_STAT_VOLATILE);
  77. }
  78. /**
  79. * dpaa2_dq_is_pull_complete() - Check whether the pull command is completed.
  80. * @dq: the dequeue result
  81. *
  82. * Return boolean.
  83. */
  84. static inline bool dpaa2_dq_is_pull_complete(const struct dpaa2_dq *dq)
  85. {
  86. return !!(dpaa2_dq_flags(dq) & DPAA2_DQ_STAT_EXPIRED);
  87. }
  88. /**
  89. * dpaa2_dq_seqnum() - Get the seqnum field in dequeue response
  90. * @dq: the dequeue result
  91. *
  92. * seqnum is valid only if VALIDFRAME flag is TRUE
  93. *
  94. * Return seqnum.
  95. */
  96. static inline u16 dpaa2_dq_seqnum(const struct dpaa2_dq *dq)
  97. {
  98. return le16_to_cpu(dq->dq.seqnum);
  99. }
  100. /**
  101. * dpaa2_dq_odpid() - Get the odpid field in dequeue response
  102. * @dq: the dequeue result
  103. *
  104. * odpid is valid only if ODPVALID flag is TRUE.
  105. *
  106. * Return odpid.
  107. */
  108. static inline u16 dpaa2_dq_odpid(const struct dpaa2_dq *dq)
  109. {
  110. return le16_to_cpu(dq->dq.oprid);
  111. }
  112. /**
  113. * dpaa2_dq_fqid() - Get the fqid in dequeue response
  114. * @dq: the dequeue result
  115. *
  116. * Return fqid.
  117. */
  118. static inline u32 dpaa2_dq_fqid(const struct dpaa2_dq *dq)
  119. {
  120. return le32_to_cpu(dq->dq.fqid) & DQ_FQID_MASK;
  121. }
  122. /**
  123. * dpaa2_dq_byte_count() - Get the byte count in dequeue response
  124. * @dq: the dequeue result
  125. *
  126. * Return the byte count remaining in the FQ.
  127. */
  128. static inline u32 dpaa2_dq_byte_count(const struct dpaa2_dq *dq)
  129. {
  130. return le32_to_cpu(dq->dq.fq_byte_cnt);
  131. }
  132. /**
  133. * dpaa2_dq_frame_count() - Get the frame count in dequeue response
  134. * @dq: the dequeue result
  135. *
  136. * Return the frame count remaining in the FQ.
  137. */
  138. static inline u32 dpaa2_dq_frame_count(const struct dpaa2_dq *dq)
  139. {
  140. return le32_to_cpu(dq->dq.fq_frm_cnt) & DQ_FRAME_COUNT_MASK;
  141. }
  142. /**
  143. * dpaa2_dq_fd_ctx() - Get the frame queue context in dequeue response
  144. * @dq: the dequeue result
  145. *
  146. * Return the frame queue context.
  147. */
  148. static inline u64 dpaa2_dq_fqd_ctx(const struct dpaa2_dq *dq)
  149. {
  150. return le64_to_cpu(dq->dq.fqd_ctx);
  151. }
  152. /**
  153. * dpaa2_dq_fd() - Get the frame descriptor in dequeue response
  154. * @dq: the dequeue result
  155. *
  156. * Return the frame descriptor.
  157. */
  158. static inline const struct dpaa2_fd *dpaa2_dq_fd(const struct dpaa2_dq *dq)
  159. {
  160. return (const struct dpaa2_fd *)&dq->dq.fd[0];
  161. }
  162. #endif /* __FSL_DPAA2_GLOBAL_H */