blob: de6c4ddbf45a75988e2f79df375f57d91a213085 [file] [log] [blame]
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001#ifndef WILC_WLAN_H
2#define WILC_WLAN_H
3
Arnd Bergmann491880e2015-11-16 15:04:55 +01004#include <linux/types.h>
5
Leo Kim7cf241a2015-11-06 11:19:56 +09006#define ISWILC1000(id) ((id & 0xfffff000) == 0x100000 ? 1 : 0)
Arnd Bergmann491880e2015-11-16 15:04:55 +01007
Johnny Kimc5c77ba2015-05-11 14:30:56 +09008/********************************************
9 *
10 * Mac eth header length
11 *
12 ********************************************/
Leo Kim7cf241a2015-11-06 11:19:56 +090013#define DRIVER_HANDLER_SIZE 4
14#define MAX_MAC_HDR_LEN 26 /* QOS_MAC_HDR_LEN */
15#define SUB_MSDU_HEADER_LENGTH 14
16#define SNAP_HDR_LEN 8
17#define ETHERNET_HDR_LEN 14
18#define WORD_ALIGNMENT_PAD 0
Johnny Kimc5c77ba2015-05-11 14:30:56 +090019
Leo Kim7cf241a2015-11-06 11:19:56 +090020#define ETH_ETHERNET_HDR_OFFSET (MAX_MAC_HDR_LEN + \
21 SUB_MSDU_HEADER_LENGTH + \
22 SNAP_HDR_LEN - \
23 ETHERNET_HDR_LEN + \
24 WORD_ALIGNMENT_PAD)
Johnny Kimc5c77ba2015-05-11 14:30:56 +090025
Leo Kim7cf241a2015-11-06 11:19:56 +090026#define HOST_HDR_OFFSET 4
27#define ETHERNET_HDR_LEN 14
28#define IP_HDR_LEN 20
29#define IP_HDR_OFFSET ETHERNET_HDR_LEN
30#define UDP_HDR_OFFSET (IP_HDR_LEN + IP_HDR_OFFSET)
31#define UDP_HDR_LEN 8
32#define UDP_DATA_OFFSET (UDP_HDR_OFFSET + UDP_HDR_LEN)
33#define ETH_CONFIG_PKT_HDR_LEN UDP_DATA_OFFSET
Johnny Kimc5c77ba2015-05-11 14:30:56 +090034
Leo Kim7cf241a2015-11-06 11:19:56 +090035#define ETH_CONFIG_PKT_HDR_OFFSET (ETH_ETHERNET_HDR_OFFSET + \
36 ETH_CONFIG_PKT_HDR_LEN)
Johnny Kimc5c77ba2015-05-11 14:30:56 +090037
38/********************************************
39 *
Johnny Kimc5c77ba2015-05-11 14:30:56 +090040 * Register Defines
41 *
42 ********************************************/
Leo Kim7cf241a2015-11-06 11:19:56 +090043#define WILC_PERIPH_REG_BASE 0x1000
44#define WILC_CHANGING_VIR_IF 0x108c
45#define WILC_CHIPID WILC_PERIPH_REG_BASE
46#define WILC_GLB_RESET_0 (WILC_PERIPH_REG_BASE + 0x400)
47#define WILC_PIN_MUX_0 (WILC_PERIPH_REG_BASE + 0x408)
48#define WILC_HOST_TX_CTRL (WILC_PERIPH_REG_BASE + 0x6c)
49#define WILC_HOST_RX_CTRL_0 (WILC_PERIPH_REG_BASE + 0x70)
50#define WILC_HOST_RX_CTRL_1 (WILC_PERIPH_REG_BASE + 0x74)
51#define WILC_HOST_VMM_CTL (WILC_PERIPH_REG_BASE + 0x78)
52#define WILC_HOST_RX_CTRL (WILC_PERIPH_REG_BASE + 0x80)
53#define WILC_HOST_RX_EXTRA_SIZE (WILC_PERIPH_REG_BASE + 0x84)
54#define WILC_HOST_TX_CTRL_1 (WILC_PERIPH_REG_BASE + 0x88)
55#define WILC_MISC (WILC_PERIPH_REG_BASE + 0x428)
56#define WILC_INTR_REG_BASE (WILC_PERIPH_REG_BASE + 0xa00)
57#define WILC_INTR_ENABLE WILC_INTR_REG_BASE
58#define WILC_INTR2_ENABLE (WILC_INTR_REG_BASE + 4)
Johnny Kimc5c77ba2015-05-11 14:30:56 +090059
Leo Kim7cf241a2015-11-06 11:19:56 +090060#define WILC_INTR_POLARITY (WILC_INTR_REG_BASE + 0x10)
61#define WILC_INTR_TYPE (WILC_INTR_REG_BASE + 0x20)
62#define WILC_INTR_CLEAR (WILC_INTR_REG_BASE + 0x30)
63#define WILC_INTR_STATUS (WILC_INTR_REG_BASE + 0x40)
Johnny Kimc5c77ba2015-05-11 14:30:56 +090064
Leo Kim7cf241a2015-11-06 11:19:56 +090065#define WILC_VMM_TBL_SIZE 64
66#define WILC_VMM_TX_TBL_BASE 0x150400
67#define WILC_VMM_RX_TBL_BASE 0x150500
Johnny Kimc5c77ba2015-05-11 14:30:56 +090068
Leo Kim7cf241a2015-11-06 11:19:56 +090069#define WILC_VMM_BASE 0x150000
70#define WILC_VMM_CORE_CTL WILC_VMM_BASE
71#define WILC_VMM_TBL_CTL (WILC_VMM_BASE + 0x4)
72#define WILC_VMM_TBL_ENTRY (WILC_VMM_BASE + 0x8)
73#define WILC_VMM_TBL0_SIZE (WILC_VMM_BASE + 0xc)
74#define WILC_VMM_TO_HOST_SIZE (WILC_VMM_BASE + 0x10)
75#define WILC_VMM_CORE_CFG (WILC_VMM_BASE + 0x14)
76#define WILC_VMM_TBL_ACTIVE (WILC_VMM_BASE + 040)
77#define WILC_VMM_TBL_STATUS (WILC_VMM_BASE + 0x44)
Johnny Kimc5c77ba2015-05-11 14:30:56 +090078
Leo Kim7cf241a2015-11-06 11:19:56 +090079#define WILC_SPI_REG_BASE 0xe800
80#define WILC_SPI_CTL WILC_SPI_REG_BASE
81#define WILC_SPI_MASTER_DMA_ADDR (WILC_SPI_REG_BASE + 0x4)
82#define WILC_SPI_MASTER_DMA_COUNT (WILC_SPI_REG_BASE + 0x8)
83#define WILC_SPI_SLAVE_DMA_ADDR (WILC_SPI_REG_BASE + 0xc)
84#define WILC_SPI_SLAVE_DMA_COUNT (WILC_SPI_REG_BASE + 0x10)
85#define WILC_SPI_TX_MODE (WILC_SPI_REG_BASE + 0x20)
86#define WILC_SPI_PROTOCOL_CONFIG (WILC_SPI_REG_BASE + 0x24)
87#define WILC_SPI_INTR_CTL (WILC_SPI_REG_BASE + 0x2c)
Johnny Kimc5c77ba2015-05-11 14:30:56 +090088
Leo Kim7cf241a2015-11-06 11:19:56 +090089#define WILC_SPI_PROTOCOL_OFFSET (WILC_SPI_PROTOCOL_CONFIG - \
90 WILC_SPI_REG_BASE)
Johnny Kimc5c77ba2015-05-11 14:30:56 +090091
Leo Kim7cf241a2015-11-06 11:19:56 +090092#define WILC_AHB_DATA_MEM_BASE 0x30000
93#define WILC_AHB_SHARE_MEM_BASE 0xd0000
Johnny Kimc5c77ba2015-05-11 14:30:56 +090094
Leo Kim7cf241a2015-11-06 11:19:56 +090095#define WILC_VMM_TBL_RX_SHADOW_BASE WILC_AHB_SHARE_MEM_BASE
96#define WILC_VMM_TBL_RX_SHADOW_SIZE 256
Johnny Kimc5c77ba2015-05-11 14:30:56 +090097
Leo Kim7cf241a2015-11-06 11:19:56 +090098#define WILC_GP_REG_0 0x149c
99#define WILC_GP_REG_1 0x14a0
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900100
Leo Kim97c14e82015-11-06 11:19:57 +0900101#define WILC_HAVE_SDIO_IRQ_GPIO BIT(0)
102#define WILC_HAVE_USE_PMU BIT(1)
103#define WILC_HAVE_SLEEP_CLK_SRC_RTC BIT(2)
104#define WILC_HAVE_SLEEP_CLK_SRC_XO BIT(3)
105#define WILC_HAVE_EXT_PA_INV_TX_RX BIT(4)
106#define WILC_HAVE_LEGACY_RF_SETTINGS BIT(5)
107#define WILC_HAVE_XTAL_24 BIT(6)
108#define WILC_HAVE_DISABLE_WILC_UART BIT(7)
Glen Leefdc2ac12016-01-25 16:35:07 +0900109#define WILC_HAVE_USE_IRQ_AS_HOST_WAKE BIT(8)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900110
111/********************************************
112 *
113 * Wlan Defines
114 *
115 ********************************************/
Leo Kim7cf241a2015-11-06 11:19:56 +0900116#define WILC_CFG_PKT 1
117#define WILC_NET_PKT 0
118#define WILC_MGMT_PKT 2
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900119
Leo Kim7cf241a2015-11-06 11:19:56 +0900120#define WILC_CFG_SET 1
121#define WILC_CFG_QUERY 0
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900122
Leo Kim7cf241a2015-11-06 11:19:56 +0900123#define WILC_CFG_RSP 1
124#define WILC_CFG_RSP_STATUS 2
125#define WILC_CFG_RSP_SCAN 3
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900126
Arnd Bergmanne28e84d2015-11-16 15:05:07 +0100127#define WILC_PLL_TO_SDIO 4
128#define WILC_PLL_TO_SPI 2
Leo Kim7cf241a2015-11-06 11:19:56 +0900129#define ABORT_INT BIT(31)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900130
Chris Parkc09632e2016-02-22 13:12:09 +0900131#define LINUX_RX_SIZE (96 * 1024)
132#define LINUX_TX_SIZE (64 * 1024)
133
Chris Park50fa2ee2016-02-22 13:41:17 +0900134#define MODALIAS "WILC_SPI"
135#define GPIO_NUM 0x44
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900136/*******************************************/
137/* E0 and later Interrupt flags. */
138/*******************************************/
139/*******************************************/
140/* E0 and later Interrupt flags. */
141/* IRQ Status word */
142/* 15:0 = DMA count in words. */
143/* 16: INT0 flag */
144/* 17: INT1 flag */
145/* 18: INT2 flag */
146/* 19: INT3 flag */
147/* 20: INT4 flag */
148/* 21: INT5 flag */
149/*******************************************/
Leo Kim7cf241a2015-11-06 11:19:56 +0900150#define IRG_FLAGS_OFFSET 16
151#define IRQ_DMA_WD_CNT_MASK ((1ul << IRG_FLAGS_OFFSET) - 1)
Leo Kim97c14e82015-11-06 11:19:57 +0900152#define INT_0 BIT(IRG_FLAGS_OFFSET)
153#define INT_1 BIT(IRG_FLAGS_OFFSET + 1)
154#define INT_2 BIT(IRG_FLAGS_OFFSET + 2)
155#define INT_3 BIT(IRG_FLAGS_OFFSET + 3)
156#define INT_4 BIT(IRG_FLAGS_OFFSET + 4)
157#define INT_5 BIT(IRG_FLAGS_OFFSET + 5)
Leo Kim7cf241a2015-11-06 11:19:56 +0900158#define MAX_NUM_INT 6
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900159
160/*******************************************/
161/* E0 and later Interrupt flags. */
162/* IRQ Clear word */
163/* 0: Clear INT0 */
164/* 1: Clear INT1 */
165/* 2: Clear INT2 */
166/* 3: Clear INT3 */
167/* 4: Clear INT4 */
168/* 5: Clear INT5 */
169/* 6: Select VMM table 1 */
170/* 7: Select VMM table 2 */
171/* 8: Enable VMM */
172/*******************************************/
Leo Kim7cf241a2015-11-06 11:19:56 +0900173#define CLR_INT0 BIT(0)
174#define CLR_INT1 BIT(1)
175#define CLR_INT2 BIT(2)
176#define CLR_INT3 BIT(3)
177#define CLR_INT4 BIT(4)
178#define CLR_INT5 BIT(5)
179#define SEL_VMM_TBL0 BIT(6)
180#define SEL_VMM_TBL1 BIT(7)
181#define EN_VMM BIT(8)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900182
Leo Kim7cf241a2015-11-06 11:19:56 +0900183#define DATA_INT_EXT INT_0
184#define PLL_INT_EXT INT_1
185#define SLEEP_INT_EXT INT_2
186#define ALL_INT_EXT (DATA_INT_EXT | PLL_INT_EXT | SLEEP_INT_EXT)
187#define NUM_INT_EXT 3
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900188
Leo Kim7cf241a2015-11-06 11:19:56 +0900189#define DATA_INT_CLR CLR_INT0
190#define PLL_INT_CLR CLR_INT1
191#define SLEEP_INT_CLR CLR_INT2
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900192
Leo Kim7cf241a2015-11-06 11:19:56 +0900193#define ENABLE_RX_VMM (SEL_VMM_TBL1 | EN_VMM)
194#define ENABLE_TX_VMM (SEL_VMM_TBL0 | EN_VMM)
Joshua Houghtoneeeb5fb2016-08-01 19:17:25 +0000195/*time for expiring the completion of cfg packets*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900196#define CFG_PKTS_TIMEOUT 2000
197/********************************************
198 *
199 * Debug Type
200 *
201 ********************************************/
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900202typedef void (*wilc_debug_func)(u32, char *, ...);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900203
204/********************************************
205 *
206 * Tx/Rx Queue Structure
207 *
208 ********************************************/
209
210struct txq_entry_t {
211 struct txq_entry_t *next;
212 struct txq_entry_t *prev;
213 int type;
Glen Leeb7193022015-12-21 14:18:07 +0900214 int tcp_pending_ack_idx;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900215 u8 *buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900216 int buffer_size;
217 void *priv;
218 int status;
219 void (*tx_complete_func)(void *, int);
220};
221
222struct rxq_entry_t {
223 struct rxq_entry_t *next;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900224 u8 *buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900225 int buffer_size;
226};
227
228/********************************************
229 *
230 * Host IF Structure
231 *
232 ********************************************/
Glen Lee9c800322015-11-06 18:40:22 +0900233struct wilc;
Leo Kim48d0aa92015-11-06 11:20:02 +0900234struct wilc_hif_func {
Glen Lee5397cbc2016-01-25 16:35:09 +0900235 int (*hif_init)(struct wilc *, bool resume);
Glen Lee49dcd0d2015-11-18 15:11:26 +0900236 int (*hif_deinit)(struct wilc *);
237 int (*hif_read_reg)(struct wilc *, u32, u32 *);
238 int (*hif_write_reg)(struct wilc *, u32, u32);
239 int (*hif_block_rx)(struct wilc *, u32, u8 *, u32);
240 int (*hif_block_tx)(struct wilc *, u32, u8 *, u32);
Glen Lee49dcd0d2015-11-18 15:11:26 +0900241 int (*hif_read_int)(struct wilc *, u32 *);
242 int (*hif_clear_int_ext)(struct wilc *, u32);
243 int (*hif_read_size)(struct wilc *, u32 *);
244 int (*hif_block_tx_ext)(struct wilc *, u32, u8 *, u32);
245 int (*hif_block_rx_ext)(struct wilc *, u32, u8 *, u32);
246 int (*hif_sync_ext)(struct wilc *, int);
Arnd Bergmann5547c1f2015-11-16 15:05:06 +0100247 int (*enable_interrupt)(struct wilc *nic);
248 void (*disable_interrupt)(struct wilc *nic);
Leo Kim48d0aa92015-11-06 11:20:02 +0900249};
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900250
Arnd Bergmann7d37a4a2015-11-16 15:05:05 +0100251extern const struct wilc_hif_func wilc_hif_spi;
252extern const struct wilc_hif_func wilc_hif_sdio;
Arnd Bergmann491880e2015-11-16 15:04:55 +0100253
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900254/********************************************
255 *
256 * Configuration Structure
257 *
258 ********************************************/
259
Leo Kim7cf241a2015-11-06 11:19:56 +0900260#define MAX_CFG_FRAME_SIZE 1468
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900261
Leo Kim14cdc0a2015-11-06 11:19:59 +0900262struct wilc_cfg_frame {
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900263 u8 ether_header[14];
264 u8 ip_header[20];
265 u8 udp_header[8];
266 u8 wid_header[8];
267 u8 frame[MAX_CFG_FRAME_SIZE];
Leo Kim14cdc0a2015-11-06 11:19:59 +0900268};
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900269
Leo Kimbcddd482015-11-06 11:20:01 +0900270struct wilc_cfg_rsp {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900271 int type;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900272 u32 seq_no;
Leo Kimbcddd482015-11-06 11:20:01 +0900273};
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900274
Arnd Bergmann491880e2015-11-16 15:04:55 +0100275struct wilc;
Glen Lee79df6a42016-02-04 18:15:31 +0900276struct wilc_vif;
Arnd Bergmann491880e2015-11-16 15:04:55 +0100277
Chris Park4d38a562016-02-04 18:15:49 +0900278int wilc_wlan_firmware_download(struct wilc *wilc, const u8 *buffer,
279 u32 buffer_size);
Arnd Bergmann562ed3f2015-11-16 15:05:10 +0100280int wilc_wlan_start(struct wilc *);
281int wilc_wlan_stop(struct wilc *);
Glen Lee691bbd42015-10-27 18:28:02 +0900282int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
283 u32 buffer_size, wilc_tx_complete_func_t func);
Leo Kimb1d19292015-11-06 11:13:01 +0900284int wilc_wlan_handle_txq(struct net_device *dev, u32 *txq_count);
Arnd Bergmann562ed3f2015-11-16 15:05:10 +0100285void wilc_handle_isr(struct wilc *wilc);
Glen Lee2de7cbe2015-10-27 18:27:54 +0900286void wilc_wlan_cleanup(struct net_device *dev);
Chaehyun Lim70011f52016-03-28 13:55:56 +0900287int wilc_wlan_cfg_set(struct wilc_vif *vif, int start, u16 wid, u8 *buffer,
Glen Lee89758e12015-11-18 15:11:34 +0900288 u32 buffer_size, int commit, u32 drv_handler);
Chaehyun Lim7db699d2016-03-28 13:55:57 +0900289int wilc_wlan_cfg_get(struct wilc_vif *vif, int start, u16 wid, int commit,
Glen Leed40c99c2015-11-18 15:11:35 +0900290 u32 drv_handler);
Chaehyun Limc975f9d2016-03-28 13:55:58 +0900291int wilc_wlan_cfg_get_val(u16 wid, u8 *buffer, u32 buffer_size);
Glen Lee829c4772015-10-29 12:18:44 +0900292int wilc_wlan_txq_add_mgmt_pkt(struct net_device *dev, void *priv, u8 *buffer,
293 u32 buffer_size, wilc_tx_complete_func_t func);
Glen Lee00215dd2015-11-18 15:11:25 +0900294void wilc_chip_sleep_manually(struct wilc *wilc);
Arnd Bergmann491880e2015-11-16 15:04:55 +0100295
296void wilc_enable_tcp_ack_filter(bool value);
Arnd Bergmann562ed3f2015-11-16 15:05:10 +0100297int wilc_wlan_get_num_conn_ifcs(struct wilc *);
Arnd Bergmann491880e2015-11-16 15:04:55 +0100298int wilc_mac_xmit(struct sk_buff *skb, struct net_device *dev);
299
300int wilc_mac_open(struct net_device *ndev);
301int wilc_mac_close(struct net_device *ndev);
302
Arnd Bergmann491880e2015-11-16 15:04:55 +0100303void WILC_WFI_p2p_rx(struct net_device *dev, u8 *buff, u32 size);
Glen Leefdc2ac12016-01-25 16:35:07 +0900304void host_wakeup_notify(struct wilc *wilc);
305void host_sleep_notify(struct wilc *wilc);
Arnd Bergmann491880e2015-11-16 15:04:55 +0100306extern bool wilc_enable_ps;
Glen Lee76855ba2016-01-25 16:35:08 +0900307void chip_allow_sleep(struct wilc *wilc);
308void chip_wakeup(struct wilc *wilc);
Chaehyun Lim6e944452016-02-11 13:46:22 +0900309int wilc_send_config_pkt(struct wilc_vif *vif, u8 mode, struct wid *wids,
Glen Leeef7e0122016-02-04 18:15:30 +0900310 u32 count, u32 drv);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900311#endif