lldesc.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // Copyright 2020 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef _ROM_LLDESC_H_
  15. #define _ROM_LLDESC_H_
  16. #include <stdint.h>
  17. #include "sys/queue.h"
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. #define LLDESC_TX_MBLK_SIZE 268 /* */
  22. #define LLDESC_RX_SMBLK_SIZE 64 /* small block size, for small mgmt frame */
  23. #define LLDESC_RX_MBLK_SIZE 524 /* rx is large sinec we want to contain mgmt frame in one block*/
  24. #define LLDESC_RX_AMPDU_ENTRY_MBLK_SIZE 64 /* it is a small buffer which is a cycle link*/
  25. #define LLDESC_RX_AMPDU_LEN_MBLK_SIZE 256 /*for ampdu entry*/
  26. #ifdef ESP_MAC_5
  27. #define LLDESC_TX_MBLK_NUM 116 /* 64K / 256 */
  28. #define LLDESC_RX_MBLK_NUM 82 /* 64K / 512 MAX 172*/
  29. #define LLDESC_RX_AMPDU_ENTRY_MBLK_NUM 4
  30. #define LLDESC_RX_AMPDU_LEN_MLBK_NUM 12
  31. #else
  32. #ifdef SBUF_RXTX
  33. #define LLDESC_TX_MBLK_NUM_MAX (2 * 48) /* 23K / 260 - 8 */
  34. #define LLDESC_RX_MBLK_NUM_MAX (2 * 48) /* 23K / 524 */
  35. #define LLDESC_TX_MBLK_NUM_MIN (2 * 16) /* 23K / 260 - 8 */
  36. #define LLDESC_RX_MBLK_NUM_MIN (2 * 16) /* 23K / 524 */
  37. #endif
  38. #define LLDESC_TX_MBLK_NUM 10 //(2 * 32) /* 23K / 260 - 8 */
  39. #ifdef IEEE80211_RX_AMPDU
  40. #define LLDESC_RX_MBLK_NUM 30
  41. #else
  42. #define LLDESC_RX_MBLK_NUM 10
  43. #endif /*IEEE80211_RX_AMPDU*/
  44. #define LLDESC_RX_AMPDU_ENTRY_MBLK_NUM 4
  45. #define LLDESC_RX_AMPDU_LEN_MLBK_NUM 8
  46. #endif /* !ESP_MAC_5 */
  47. /*
  48. * SLC2 DMA Desc struct, aka lldesc_t
  49. *
  50. * --------------------------------------------------------------
  51. * | own | EoF | sub_sof | 5'b0 | length [11:0] | size [11:0] |
  52. * --------------------------------------------------------------
  53. * | buf_ptr [31:0] |
  54. * --------------------------------------------------------------
  55. * | next_desc_ptr [31:0] |
  56. * --------------------------------------------------------------
  57. */
  58. /* this bitfield is start from the LSB!!! */
  59. typedef struct lldesc_s {
  60. volatile uint32_t size : 12,
  61. length: 12,
  62. offset: 5, /* h/w reserved 5bit, s/w use it as offset in buffer */
  63. sosf : 1, /* start of sub-frame */
  64. eof : 1, /* end of frame */
  65. owner : 1; /* hw or sw */
  66. volatile const uint8_t *buf; /* point to buffer data */
  67. union {
  68. volatile uint32_t empty;
  69. STAILQ_ENTRY(lldesc_s) qe; /* pointing to the next desc */
  70. };
  71. } lldesc_t;
  72. typedef struct tx_ampdu_entry_s {
  73. uint32_t sub_len : 12,
  74. dili_num : 7,
  75. : 1,
  76. null_byte: 2,
  77. data : 1,
  78. enc : 1,
  79. seq : 8;
  80. } tx_ampdu_entry_t;
  81. typedef struct lldesc_chain_s {
  82. lldesc_t *head;
  83. lldesc_t *tail;
  84. } lldesc_chain_t;
  85. #ifdef SBUF_RXTX
  86. enum sbuf_mask_s {
  87. SBUF_MOVE_NO = 0,
  88. SBUF_MOVE_TX2RX,
  89. SBUF_MOVE_RX2TX,
  90. } ;
  91. #define SBUF_MOVE_STEP 8
  92. #endif
  93. #define LLDESC_SIZE sizeof(struct lldesc_s)
  94. /* SLC Descriptor */
  95. #define LLDESC_OWNER_MASK 0x80000000
  96. #define LLDESC_OWNER_SHIFT 31
  97. #define LLDESC_SW_OWNED 0
  98. #define LLDESC_HW_OWNED 1
  99. #define LLDESC_EOF_MASK 0x40000000
  100. #define LLDESC_EOF_SHIFT 30
  101. #define LLDESC_SOSF_MASK 0x20000000
  102. #define LLDESC_SOSF_SHIFT 29
  103. #define LLDESC_LENGTH_MASK 0x00fff000
  104. #define LLDESC_LENGTH_SHIFT 12
  105. #define LLDESC_SIZE_MASK 0x00000fff
  106. #define LLDESC_SIZE_SHIFT 0
  107. #define LLDESC_ADDR_MASK 0x000fffff
  108. void lldesc_build_chain(uint8_t *descptr, uint32_t desclen, uint8_t *mblkptr, uint32_t buflen, uint32_t blksz, uint8_t owner,
  109. lldesc_t **head,
  110. #ifdef TO_HOST_RESTART
  111. lldesc_t **one_before_tail,
  112. #endif
  113. lldesc_t **tail);
  114. lldesc_t *lldesc_num2link(lldesc_t *head, uint16_t nblks);
  115. lldesc_t *lldesc_set_owner(lldesc_t *head, uint16_t nblks, uint8_t owner);
  116. static inline uint32_t lldesc_get_chain_length(lldesc_t *head)
  117. {
  118. lldesc_t *ds = head;
  119. uint32_t len = 0;
  120. while (ds) {
  121. len += ds->length;
  122. ds = STAILQ_NEXT(ds, qe);
  123. }
  124. return len;
  125. }
  126. static inline void lldesc_config(lldesc_t *ds, uint8_t owner, uint8_t eof, uint8_t sosf, uint16_t len)
  127. {
  128. ds->owner = owner;
  129. ds->eof = eof;
  130. ds->sosf = sosf;
  131. ds->length = len;
  132. }
  133. #define LLDESC_CONFIG(_desc, _owner, _eof, _sosf, _len) do { \
  134. (_desc)->owner = (_owner); \
  135. (_desc)->eof = (_eof); \
  136. (_desc)->sosf = (_sosf); \
  137. (_desc)->length = (_len); \
  138. } while(0)
  139. #define LLDESC_FROM_HOST_CLEANUP(ds) LLDESC_CONFIG((ds), LLDESC_HW_OWNED, 0, 0, 0)
  140. #define LLDESC_MAC_RX_CLEANUP(ds) LLDESC_CONFIG((ds), LLDESC_HW_OWNED, 0, 0, (ds)->size)
  141. #define LLDESC_TO_HOST_CLEANUP(ds) LLDESC_CONFIG((ds), LLDESC_HW_OWNED, 0, 0, 0)
  142. #ifdef __cplusplus
  143. }
  144. #endif
  145. #endif /* _ROM_LLDESC_H_ */