fsl_dpaa_fd.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2014 Freescale Semiconductor
  4. */
  5. #ifndef __FSL_DPAA_FD_H
  6. #define __FSL_DPAA_FD_H
  7. /* Place-holder for FDs, we represent it via the simplest form that we need for
  8. * now. Different overlays may be needed to support different options, etc. (It
  9. * is impractical to define One True Struct, because the resulting encoding
  10. * routines (lots of read-modify-writes) would be worst-case performance whether
  11. * or not circumstances required them.) */
  12. struct dpaa_fd {
  13. union {
  14. u32 words[8];
  15. struct dpaa_fd_simple {
  16. u32 addr_lo;
  17. u32 addr_hi;
  18. u32 len;
  19. /* offset in the MS 16 bits, BPID in the LS 16 bits */
  20. u32 bpid_offset;
  21. u32 frc; /* frame context */
  22. /* "err", "va", "cbmt", "asal", [...] */
  23. u32 ctrl;
  24. /* flow context */
  25. u32 flc_lo;
  26. u32 flc_hi;
  27. } simple;
  28. };
  29. };
  30. enum dpaa_fd_format {
  31. dpaa_fd_single = 0,
  32. dpaa_fd_list,
  33. dpaa_fd_sg
  34. };
  35. static inline u64 ldpaa_fd_get_addr(const struct dpaa_fd *fd)
  36. {
  37. return (u64)((((uint64_t)fd->simple.addr_hi) << 32)
  38. + fd->simple.addr_lo);
  39. }
  40. static inline void ldpaa_fd_set_addr(struct dpaa_fd *fd, u64 addr)
  41. {
  42. fd->simple.addr_hi = upper_32_bits(addr);
  43. fd->simple.addr_lo = lower_32_bits(addr);
  44. }
  45. static inline u32 ldpaa_fd_get_len(const struct dpaa_fd *fd)
  46. {
  47. return fd->simple.len;
  48. }
  49. static inline void ldpaa_fd_set_len(struct dpaa_fd *fd, u32 len)
  50. {
  51. fd->simple.len = len;
  52. }
  53. static inline uint16_t ldpaa_fd_get_offset(const struct dpaa_fd *fd)
  54. {
  55. return (uint16_t)(fd->simple.bpid_offset >> 16) & 0x0FFF;
  56. }
  57. static inline void ldpaa_fd_set_offset(struct dpaa_fd *fd, uint16_t offset)
  58. {
  59. fd->simple.bpid_offset &= 0xF000FFFF;
  60. fd->simple.bpid_offset |= (u32)offset << 16;
  61. }
  62. static inline uint16_t ldpaa_fd_get_bpid(const struct dpaa_fd *fd)
  63. {
  64. return (uint16_t)(fd->simple.bpid_offset & 0xFFFF);
  65. }
  66. static inline void ldpaa_fd_set_bpid(struct dpaa_fd *fd, uint16_t bpid)
  67. {
  68. fd->simple.bpid_offset &= 0xFFFF0000;
  69. fd->simple.bpid_offset |= (u32)bpid;
  70. }
  71. /* When frames are dequeued, the FDs show up inside "dequeue" result structures
  72. * (if at all, not all dequeue results contain valid FDs). This structure type
  73. * is intentionally defined without internal detail, and the only reason it
  74. * isn't declared opaquely (without size) is to allow the user to provide
  75. * suitably-sized (and aligned) memory for these entries. */
  76. struct ldpaa_dq {
  77. uint32_t dont_manipulate_directly[16];
  78. };
  79. /* Parsing frame dequeue results */
  80. #define LDPAA_DQ_STAT_FQEMPTY 0x80
  81. #define LDPAA_DQ_STAT_HELDACTIVE 0x40
  82. #define LDPAA_DQ_STAT_FORCEELIGIBLE 0x20
  83. #define LDPAA_DQ_STAT_VALIDFRAME 0x10
  84. #define LDPAA_DQ_STAT_ODPVALID 0x04
  85. #define LDPAA_DQ_STAT_VOLATILE 0x02
  86. #define LDPAA_DQ_STAT_EXPIRED 0x01
  87. uint32_t ldpaa_dq_flags(const struct ldpaa_dq *);
  88. static inline int ldpaa_dq_is_pull(const struct ldpaa_dq *dq)
  89. {
  90. return (int)(ldpaa_dq_flags(dq) & LDPAA_DQ_STAT_VOLATILE);
  91. }
  92. static inline int ldpaa_dq_is_pull_complete(
  93. const struct ldpaa_dq *dq)
  94. {
  95. return (int)(ldpaa_dq_flags(dq) & LDPAA_DQ_STAT_EXPIRED);
  96. }
  97. /* seqnum/odpid are valid only if VALIDFRAME and ODPVALID flags are TRUE */
  98. uint16_t ldpaa_dq_seqnum(const struct ldpaa_dq *);
  99. uint16_t ldpaa_dq_odpid(const struct ldpaa_dq *);
  100. uint32_t ldpaa_dq_fqid(const struct ldpaa_dq *);
  101. uint32_t ldpaa_dq_byte_count(const struct ldpaa_dq *);
  102. uint32_t ldpaa_dq_frame_count(const struct ldpaa_dq *);
  103. uint32_t ldpaa_dq_fqd_ctx_hi(const struct ldpaa_dq *);
  104. uint32_t ldpaa_dq_fqd_ctx_lo(const struct ldpaa_dq *);
  105. /* get the Frame Descriptor */
  106. const struct dpaa_fd *ldpaa_dq_fd(const struct ldpaa_dq *);
  107. #endif /* __FSL_DPAA_FD_H */