4 * IPC utility function declarations
6 * Copyright (C) ESWIN 2015-2020
8 #ifndef _ECRNX_IPC_UTILS_H_
9 #define _ECRNX_IPC_UTILS_H_
11 #include <linux/dma-mapping.h>
12 #include <linux/dmapool.h>
13 #include <linux/skbuff.h>
19 ECRNX_DEV_STACK_RESTARTING,
28 * struct ecrnx_ipc_elem - Generic IPC buffer of fixed size
30 * @addr: Host address of the buffer.
31 * @dma_addr: DMA address of the buffer.
33 struct ecrnx_ipc_elem {
39 * struct ecrnx_ipc_elem_pool - Generic pool of IPC buffers of fixed size
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
45 struct ecrnx_ipc_elem_pool {
47 struct ecrnx_ipc_elem *buf;
48 struct dma_pool *pool;
52 * struct ecrnx_ipc_elem - Generic IPC buffer of variable size
54 * @addr: Host address of the buffer.
55 * @dma_addr: DMA address of the buffer.
56 * @size: Size, in bytes, of the buffer
58 struct ecrnx_ipc_elem_var {
65 * struct ecrnx_ipc_dbgdump_elem - IPC buffer for debug dump
67 * @mutex: Mutex to protect access to debug dump
70 struct ecrnx_ipc_dbgdump_elem {
72 struct ecrnx_ipc_elem_var buf;
75 //static const u32 ecrnx_rxbuff_pattern = 0xCAFEFADE;
76 static const u32 ecrnx_rxbuff_pattern = 0xAAAAAA00;
80 * Maximum Length of Radiotap header vendor specific data(in bytes)
82 #define RADIOTAP_HDR_VEND_MAX_LEN 16
85 * Maximum Radiotap Header Length without vendor specific data (in bytes)
87 #define RADIOTAP_HDR_MAX_LEN 80
90 * Unsupported HT Frame data length (in bytes)
92 #define UNSUP_RX_VEC_DATA_LEN 2
95 * struct ecrnx_ipc_skb_elem - IPC buffer for SKB element
97 * @skb: Pointer to the skb buffer allocated
98 * @dma_addr: DMA address of the data buffer fo skb
101 struct ecrnx_ipc_skb_elem {
106 #ifdef CONFIG_ECRNX_FULLMAC
108 /* Maximum number of rx buffer the fw may use at the same time */
109 #define ECRNX_RXBUFF_MAX (64 * NX_REMOTE_STA_MAX)
112 * struct ecrnx_ipc_rxbuf_elems - IPC buffers for RX
114 * @skb: Array of buffer push to FW.
115 * @idx: Index of the last pushed skb.(Use to find the next free entry quicker)
117 * Note: contrary to softmac version, dma_addr are stored inside skb->cb.
118 * (cf &struct ecrnx_skb_cb)
120 struct ecrnx_ipc_rxbuf_elems {
121 struct sk_buff *skb[ECRNX_RXBUFF_MAX];
126 * struct ecrnx_skb_cb - Control Buffer structure for RX buffer
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
133 struct ecrnx_skb_cb {
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
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
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
154 #define ECRNX_RXBUFF_VALID_IDX(idx) ((idx) < ECRNX_RXBUFF_MAX)
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)
160 #endif /* CONFIG_ECRNX_FULLMAC */
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);
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,
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 */
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);
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);
203 void ecrnx_error_ind(struct ecrnx_hw *ecrnx_hw);
204 void ecrnx_umh_done(struct ecrnx_hw *ecrnx_hw);
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);
209 #endif /* _ECRNX_IPC_UTILS_H_ */