1 /*
2 * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #ifndef _ROM_LLDESC_H_
8 #define _ROM_LLDESC_H_
9
10 #include <stdint.h>
11
12 #include "sys/queue.h"
13 #include "esp_rom_lldesc.h"
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 #define LLDESC_TX_MBLK_SIZE 268 /* */
20 #define LLDESC_RX_SMBLK_SIZE 64 /* small block size, for small mgmt frame */
21 #define LLDESC_RX_MBLK_SIZE 524 /* rx is large sinec we want to contain mgmt frame in one block*/
22 #define LLDESC_RX_AMPDU_ENTRY_MBLK_SIZE 64 /* it is a small buffer which is a cycle link*/
23 #define LLDESC_RX_AMPDU_LEN_MBLK_SIZE 256 /*for ampdu entry*/
24 #ifdef ESP_MAC_5
25 #define LLDESC_TX_MBLK_NUM 116 /* 64K / 256 */
26 #define LLDESC_RX_MBLK_NUM 82 /* 64K / 512 MAX 172*/
27 #define LLDESC_RX_AMPDU_ENTRY_MBLK_NUM 4
28 #define LLDESC_RX_AMPDU_LEN_MLBK_NUM 12
29 #else
30 #ifdef SBUF_RXTX
31 #define LLDESC_TX_MBLK_NUM_MAX (2 * 48) /* 23K / 260 - 8 */
32 #define LLDESC_RX_MBLK_NUM_MAX (2 * 48) /* 23K / 524 */
33 #define LLDESC_TX_MBLK_NUM_MIN (2 * 16) /* 23K / 260 - 8 */
34 #define LLDESC_RX_MBLK_NUM_MIN (2 * 16) /* 23K / 524 */
35 #endif
36 #define LLDESC_TX_MBLK_NUM 10 //(2 * 32) /* 23K / 260 - 8 */
37
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
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 typedef struct tx_ampdu_entry_s {
49 uint32_t sub_len : 12,
50 dili_num : 7,
51 : 1,
52 null_byte: 2,
53 data : 1,
54 enc : 1,
55 seq : 8;
56 } tx_ampdu_entry_t;
57
58 typedef struct lldesc_chain_s {
59 lldesc_t *head;
60 lldesc_t *tail;
61 } lldesc_chain_t;
62
63 #ifdef SBUF_RXTX
64 enum sbuf_mask_s {
65 SBUF_MOVE_NO = 0,
66 SBUF_MOVE_TX2RX,
67 SBUF_MOVE_RX2TX,
68 } ;
69
70 #define SBUF_MOVE_STEP 8
71 #endif
72 #define LLDESC_SIZE sizeof(struct lldesc_s)
73
74 /* SLC Descriptor */
75 #define LLDESC_OWNER_MASK 0x80000000
76 #define LLDESC_OWNER_SHIFT 31
77 #define LLDESC_SW_OWNED 0
78 #define LLDESC_HW_OWNED 1
79
80 #define LLDESC_EOF_MASK 0x40000000
81 #define LLDESC_EOF_SHIFT 30
82
83 #define LLDESC_SOSF_MASK 0x20000000
84 #define LLDESC_SOSF_SHIFT 29
85
86 #define LLDESC_LENGTH_MASK 0x00fff000
87 #define LLDESC_LENGTH_SHIFT 12
88
89 #define LLDESC_SIZE_MASK 0x00000fff
90 #define LLDESC_SIZE_SHIFT 0
91
92 #define LLDESC_ADDR_MASK 0x000fffff
93
lldesc_get_chain_length(lldesc_t * head)94 static inline uint32_t lldesc_get_chain_length(lldesc_t *head)
95 {
96 lldesc_t *ds = head;
97 uint32_t len = 0;
98
99 while (ds) {
100 len += ds->length;
101 ds = STAILQ_NEXT(ds, qe);
102 }
103
104 return len;
105 }
106
lldesc_config(lldesc_t * ds,uint8_t owner,uint8_t eof,uint8_t sosf,uint16_t len)107 static inline void lldesc_config(lldesc_t *ds, uint8_t owner, uint8_t eof, uint8_t sosf, uint16_t len)
108 {
109 ds->owner = owner;
110 ds->eof = eof;
111 ds->sosf = sosf;
112 ds->length = len;
113 }
114
115 #define LLDESC_CONFIG(_desc, _owner, _eof, _sosf, _len) do { \
116 (_desc)->owner = (_owner); \
117 (_desc)->eof = (_eof); \
118 (_desc)->sosf = (_sosf); \
119 (_desc)->length = (_len); \
120 } while(0)
121
122 #define LLDESC_FROM_HOST_CLEANUP(ds) LLDESC_CONFIG((ds), LLDESC_HW_OWNED, 0, 0, 0)
123
124 #define LLDESC_MAC_RX_CLEANUP(ds) LLDESC_CONFIG((ds), LLDESC_HW_OWNED, 0, 0, (ds)->size)
125
126 #define LLDESC_TO_HOST_CLEANUP(ds) LLDESC_CONFIG((ds), LLDESC_HW_OWNED, 0, 0, 0)
127
128 #ifdef __cplusplus
129 }
130 #endif
131
132 #endif /* _ROM_LLDESC_H_ */
133