lldesc.h 5.6 KB

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