net:wireless:Support eswin usb wifi ECR6600U
[platform/kernel/linux-starfive.git] / drivers / net / wireless / eswin / ecrnx_utils.h
1 /**
2  * ecrnx_ipc_utils.h
3  *
4  * IPC utility function declarations
5  *
6  * Copyright (C) ESWIN 2015-2020
7  */
8 #ifndef _ECRNX_IPC_UTILS_H_
9 #define _ECRNX_IPC_UTILS_H_
10
11 #include <linux/dma-mapping.h>
12 #include <linux/dmapool.h>
13 #include <linux/skbuff.h>
14
15 #include "lmac_msg.h"
16
17 enum ecrnx_dev_flag {
18     ECRNX_DEV_RESTARTING,
19     ECRNX_DEV_STACK_RESTARTING,
20     ECRNX_DEV_STARTED,
21     ECRNX_DEV_ADDING_STA,
22 };
23
24 struct ecrnx_hw;
25 struct ecrnx_sta;
26
27 /**
28  * struct ecrnx_ipc_elem - Generic IPC buffer of fixed size
29  *
30  * @addr: Host address of the buffer.
31  * @dma_addr: DMA address of the buffer.
32  */
33 struct ecrnx_ipc_elem {
34     void *addr;
35     dma_addr_t dma_addr;
36 };
37
38 /**
39  * struct ecrnx_ipc_elem_pool - Generic pool of IPC buffers of fixed size
40  *
41  * @nb: Number of buffers currenlty allocated in the pool
42  * @buf: Array of buffers (size of array is @nb)
43  * @pool: DMA pool in which buffers have been allocated
44  */
45 struct ecrnx_ipc_elem_pool {
46     int nb;
47     struct ecrnx_ipc_elem *buf;
48     struct dma_pool *pool;
49 };
50
51 /**
52  * struct ecrnx_ipc_elem - Generic IPC buffer of variable size
53  *
54  * @addr: Host address of the buffer.
55  * @dma_addr: DMA address of the buffer.
56  * @size: Size, in bytes, of the buffer
57  */
58 struct ecrnx_ipc_elem_var {
59     void *addr;
60     dma_addr_t dma_addr;
61     size_t size;
62 };
63
64 /**
65  * struct ecrnx_ipc_dbgdump_elem - IPC buffer for debug dump
66  *
67  * @mutex: Mutex to protect access to debug dump
68  * @buf: IPC buffer
69  */
70 struct ecrnx_ipc_dbgdump_elem {
71     struct mutex mutex;
72     struct ecrnx_ipc_elem_var buf;
73 };
74
75 //static const u32 ecrnx_rxbuff_pattern = 0xCAFEFADE;
76 static const u32 ecrnx_rxbuff_pattern = 0xAAAAAA00;
77
78
79 /*
80  * Maximum Length of Radiotap header vendor specific data(in bytes)
81  */
82 #define RADIOTAP_HDR_VEND_MAX_LEN   16
83
84 /*
85  * Maximum Radiotap Header Length without vendor specific data (in bytes)
86  */
87 #define RADIOTAP_HDR_MAX_LEN        80
88
89 /*
90  * Unsupported HT Frame data length (in bytes)
91  */
92 #define UNSUP_RX_VEC_DATA_LEN       2
93
94 /**
95  * struct ecrnx_ipc_skb_elem - IPC buffer for SKB element
96  *
97  * @skb: Pointer to the skb buffer allocated
98  * @dma_addr: DMA address of the data buffer fo skb
99  *
100  */
101 struct ecrnx_ipc_skb_elem {
102     struct sk_buff *skb;
103     dma_addr_t dma_addr;
104 };
105
106 #ifdef CONFIG_ECRNX_FULLMAC
107
108 /* Maximum number of rx buffer the fw may use at the same time */
109 #define ECRNX_RXBUFF_MAX (64 * NX_REMOTE_STA_MAX)
110
111 /**
112  * struct ecrnx_ipc_rxbuf_elems - IPC buffers for RX
113  *
114  * @skb: Array of buffer push to FW.
115  * @idx: Index of the last pushed skb.(Use to find the next free entry quicker)
116  *
117  * Note: contrary to softmac version, dma_addr are stored inside skb->cb.
118  * (cf &struct ecrnx_skb_cb)
119  */
120 struct ecrnx_ipc_rxbuf_elems {
121     struct sk_buff *skb[ECRNX_RXBUFF_MAX];
122     int idx;
123 };
124
125 /**
126  * struct ecrnx_skb_cb - Control Buffer structure for RX buffer
127  *
128  * @dma_addr: DMA address of the data buffer
129  * @pattern: Known pattern (used to check pointer on skb)
130  * @idx: Index in &struct ecrnx_hw.rxbuff_table that contains address of this
131  * buffer
132  */
133 struct ecrnx_skb_cb {
134     dma_addr_t dma_addr;
135     uint32_t pattern;
136     uint32_t idx;
137 };
138
139 #define ECRNX_RXBUFF_DMA_ADDR_SET(skbuff, addr)          \
140     ((struct ecrnx_skb_cb *)(skbuff->cb))->dma_addr = addr
141 #define ECRNX_RXBUFF_DMA_ADDR_GET(skbuff)                \
142     ((struct ecrnx_skb_cb *)(skbuff->cb))->dma_addr
143
144 #define ECRNX_RXBUFF_PATTERN_SET(skbuff, pat)                \
145     ((struct ecrnx_skb_cb *)(skbuff->cb))->pattern = pat
146 #define ECRNX_RXBUFF_PATTERN_GET(skbuff)         \
147     ((struct ecrnx_skb_cb *)(skbuff->cb))->pattern
148
149 #define ECRNX_RXBUFF_IDX_SET(skbuff, val)                \
150     ((struct ecrnx_skb_cb *)(skbuff->cb))->idx = val
151 #define ECRNX_RXBUFF_IDX_GET(skbuff)             \
152     ((struct ecrnx_skb_cb *)(skbuff->cb))->idx
153
154 #define ECRNX_RXBUFF_VALID_IDX(idx) ((idx) < ECRNX_RXBUFF_MAX)
155
156 /* Used to ensure that hostid set to fw is never 0 */
157 #define ECRNX_RXBUFF_IDX_TO_HOSTID(idx) ((idx) + 1)
158 #define ECRNX_RXBUFF_HOSTID_TO_IDX(hostid) ((hostid) - 1)
159
160 #endif /* CONFIG_ECRNX_FULLMAC */
161
162
163 #ifdef CONFIG_ECRNX_SOFTMAC
164 int ecrnx_ipc_rxbuf_elem_allocs(struct ecrnx_hw *ecrnx_hw,
165                                struct ecrnx_ipc_skb_elem *elem);
166 void ecrnx_ipc_rxbuf_elem_repush(struct ecrnx_hw *ecrnx_hw,
167                                 struct ecrnx_ipc_skb_elem *elem);
168 #else
169 int ecrnx_ipc_rxbuf_elem_allocs(struct ecrnx_hw *ecrnx_hw);
170 void ecrnx_ipc_rxbuf_elem_pull(struct ecrnx_hw *ecrnx_hw, struct sk_buff *skb);
171 void ecrnx_ipc_rxbuf_elem_sync(struct ecrnx_hw *ecrnx_hw, struct sk_buff *skb,
172                               int len);
173 void ecrnx_ipc_rxdesc_elem_repush(struct ecrnx_hw *ecrnx_hw,
174                                  struct ecrnx_ipc_elem *elem);
175 void ecrnx_ipc_rxbuf_elem_repush(struct ecrnx_hw *ecrnx_hw,
176                                 struct sk_buff *skb);
177 #endif /* CONFIG_ECRNX_SOFTMAC */
178
179 void ecrnx_printf(const char *fmt, ...);
180 void ecrnx_ipc_msg_push(struct ecrnx_hw *ecrnx_hw, void *msg_buf, uint16_t len);
181 void ecrnx_ipc_txdesc_push(struct ecrnx_hw *ecrnx_hw, void *tx_desc,
182                           void *hostid, int hw_queue, int user);
183 void *ecrnx_ipc_fw_trace_desc_get(struct ecrnx_hw *ecrnx_hw);
184 int ecrnx_ipc_rxbuf_init(struct ecrnx_hw *ecrnx_hw, uint32_t rx_bufsz);
185 int ecrnx_ipc_init(struct ecrnx_hw *ecrnx_hw, u8 *shared_ram);
186 void ecrnx_ipc_deinit(struct ecrnx_hw *ecrnx_hw);
187 void ecrnx_ipc_start(struct ecrnx_hw *ecrnx_hw);
188 void ecrnx_ipc_stop(struct ecrnx_hw *ecrnx_hw);
189 void ecrnx_ipc_tx_drain(struct ecrnx_hw *ecrnx_hw);
190 bool ecrnx_ipc_tx_pending(struct ecrnx_hw *ecrnx_hw);
191
192 struct ipc_host_env_tag;
193 int ecrnx_ipc_elem_var_allocs(struct ecrnx_hw *ecrnx_hw,
194                              struct ecrnx_ipc_elem_var *elem, size_t elem_size,
195                              enum dma_data_direction dir,
196                              void *buf, const void *init,
197                              void (*push)(struct ipc_host_env_tag *, uint32_t));
198 void ecrnx_ipc_elem_var_deallocs(struct ecrnx_hw *ecrnx_hw,
199                                 struct ecrnx_ipc_elem_var *elem);
200 int ecrnx_ipc_unsup_rx_vec_elem_allocs(struct ecrnx_hw *ecrnx_hw,
201                                       struct ecrnx_ipc_skb_elem *elem);
202
203 void ecrnx_error_ind(struct ecrnx_hw *ecrnx_hw);
204 void ecrnx_umh_done(struct ecrnx_hw *ecrnx_hw);
205
206 void ecrnx_ipc_sta_buffer_init(struct ecrnx_hw *ecrnx_hw, int sta_idx);
207 void ecrnx_ipc_sta_buffer(struct ecrnx_hw *ecrnx_hw, struct ecrnx_sta *sta, int tid, int size);
208
209 #endif /* _ECRNX_IPC_UTILS_H_ */