blob: fe7382e65ff9799ecdb4041342ac09f1d0955f71 [file] [log] [blame]
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001/* ////////////////////////////////////////////////////////////////////////// */
2/* */
3/* Copyright (c) Atmel Corporation. All rights reserved. */
4/* */
5/* Module Name: wilc_wlan.c */
6/* */
7/* */
8/* //////////////////////////////////////////////////////////////////////////// */
9
10#include "wilc_wlan_if.h"
11#include "wilc_wlan.h"
Johnny Kimc5c77ba2015-05-11 14:30:56 +090012
13/********************************************
14 *
15 * Global
16 *
17 ********************************************/
Johnny Kimc5c77ba2015-05-11 14:30:56 +090018extern wilc_hif_func_t hif_sdio;
19extern wilc_hif_func_t hif_spi;
20extern wilc_cfg_func_t mac_cfg;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090021extern void WILC_WFI_mgmt_rx(u8 *buff, u32 size);
22u32 wilc_get_chipid(u8 update);
Dean Lee72ed4dc2015-06-12 14:11:44 +090023u16 Set_machw_change_vir_if(bool bValue);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090024
Johnny Kimc5c77ba2015-05-11 14:30:56 +090025
26
27typedef struct {
28 int quit;
29
30 /**
31 * input interface functions
32 **/
33 wilc_wlan_os_func_t os_func;
34 wilc_wlan_io_func_t io_func;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090035
36 /**
37 * host interface functions
38 **/
39 wilc_hif_func_t hif_func;
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -070040 struct mutex *hif_lock;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090041
42 /**
43 * configuration interface functions
44 **/
45 wilc_cfg_func_t cif_func;
46 int cfg_frame_in_use;
47 wilc_cfg_frame_t cfg_frame;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090048 u32 cfg_frame_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090049 int cfg_seq_no;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090050
51 /**
52 * RX buffer
53 **/
54 #ifdef MEMORY_STATIC
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090055 u32 rx_buffer_size;
Chaehyun Lim51e825f2015-09-15 14:06:14 +090056 u8 *rx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090057 u32 rx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090058 #endif
59 /**
60 * TX buffer
61 **/
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090062 u32 tx_buffer_size;
Chaehyun Lim51e825f2015-09-15 14:06:14 +090063 u8 *tx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090064 u32 tx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090065
66 /**
67 * TX queue
68 **/
69 void *txq_lock;
70
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -070071 struct semaphore *txq_add_to_head_lock;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090072 unsigned long txq_spinlock_flags;
73
74 struct txq_entry_t *txq_head;
75 struct txq_entry_t *txq_tail;
76 int txq_entries;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090077 int txq_exit;
78
79 /**
80 * RX queue
81 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +090082 struct rxq_entry_t *rxq_head;
83 struct rxq_entry_t *rxq_tail;
84 int rxq_entries;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090085 int rxq_exit;
86
87
88} wilc_wlan_dev_t;
89
90static wilc_wlan_dev_t g_wlan;
91
Chaehyun Lim9af382b2015-09-16 20:11:27 +090092static inline void chip_allow_sleep(void);
93static inline void chip_wakeup(void);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090094/********************************************
95 *
96 * Debug
97 *
98 ********************************************/
99
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900100static u32 dbgflag = N_INIT | N_ERR | N_INTR | N_TXQ | N_RXQ;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900101
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900102static void wilc_debug(u32 flag, char *fmt, ...)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900103{
104 char buf[256];
105 va_list args;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900106
107 if (flag & dbgflag) {
108 va_start(args, fmt);
Hari Prasath Gujulan Elango81053222015-06-22 13:13:58 +0000109 vsprintf(buf, fmt, args);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900110 va_end(args);
111
Glen Leeef2b7842015-09-24 18:14:55 +0900112 linux_wlan_dbg(buf);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900113 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900114}
115
116static CHIP_PS_STATE_T genuChipPSstate = CHIP_WAKEDUP;
117
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900118/*acquire_bus() and release_bus() are made static inline functions*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900119/*as a temporary workaround to fix a problem of receiving*/
120/*unknown interrupt from FW*/
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900121static inline void acquire_bus(BUS_ACQUIRE_T acquire)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900122{
123
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -0700124 mutex_lock(g_wlan.hif_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900125 #ifndef WILC_OPTIMIZE_SLEEP_INT
126 if (genuChipPSstate != CHIP_WAKEDUP)
127 #endif
128 {
129 if (acquire == ACQUIRE_AND_WAKEUP)
130 chip_wakeup();
131 }
132
133}
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900134static inline void release_bus(BUS_RELEASE_T release)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900135{
136 #ifdef WILC_OPTIMIZE_SLEEP_INT
137 if (release == RELEASE_ALLOW_SLEEP)
138 chip_allow_sleep();
139 #endif
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -0700140 mutex_unlock(g_wlan.hif_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900141}
142/********************************************
143 *
144 * Queue
145 *
146 ********************************************/
147
148static void wilc_wlan_txq_remove(struct txq_entry_t *tqe)
149{
150
151 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
152 /* unsigned long flags; */
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900153 if (tqe == p->txq_head) {
154
155 p->txq_head = tqe->next;
156 if (p->txq_head)
157 p->txq_head->prev = NULL;
158
159
160 } else if (tqe == p->txq_tail) {
161 p->txq_tail = (tqe->prev);
162 if (p->txq_tail)
163 p->txq_tail->next = NULL;
164 } else {
165 tqe->prev->next = tqe->next;
166 tqe->next->prev = tqe->prev;
167 }
168 p->txq_entries -= 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900169
170}
171
172static struct txq_entry_t *wilc_wlan_txq_remove_from_head(void)
173{
174 struct txq_entry_t *tqe;
175 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
176 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900177
Glen Lee85e57562015-09-24 18:14:56 +0900178 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900179 if (p->txq_head) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900180 tqe = p->txq_head;
181 p->txq_head = tqe->next;
182 if (p->txq_head) {
183 p->txq_head->prev = NULL;
184 }
185 p->txq_entries -= 1;
186
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900187
188
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900189
190 } else {
191 tqe = NULL;
192 }
Glen Lee85e57562015-09-24 18:14:56 +0900193 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900194 return tqe;
195}
196
197static void wilc_wlan_txq_add_to_tail(struct txq_entry_t *tqe)
198{
199 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
200 unsigned long flags;
Glen Lee85e57562015-09-24 18:14:56 +0900201 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900202
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900203 if (p->txq_head == NULL) {
204 tqe->next = NULL;
205 tqe->prev = NULL;
206 p->txq_head = tqe;
207 p->txq_tail = tqe;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900208 } else {
209 tqe->next = NULL;
210 tqe->prev = p->txq_tail;
211 p->txq_tail->next = tqe;
212 p->txq_tail = tqe;
213 }
214 p->txq_entries += 1;
215 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900216
Glen Lee85e57562015-09-24 18:14:56 +0900217 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900218
219 /**
220 * wake up TX queue
221 **/
222 PRINT_D(TX_DBG, "Wake the txq_handling\n");
223
Glen Lee5cd63632015-09-24 18:14:58 +0900224 up(&g_linux_wlan->txq_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900225}
226
227static int wilc_wlan_txq_add_to_head(struct txq_entry_t *tqe)
228{
229 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
230 unsigned long flags;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900231 if (p->os_func.os_wait(p->txq_add_to_head_lock, CFG_PKTS_TIMEOUT))
232 return -1;
233
Glen Lee85e57562015-09-24 18:14:56 +0900234 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900235
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900236 if (p->txq_head == NULL) {
237 tqe->next = NULL;
238 tqe->prev = NULL;
239 p->txq_head = tqe;
240 p->txq_tail = tqe;
241 } else {
242 tqe->next = p->txq_head;
243 tqe->prev = NULL;
244 p->txq_head->prev = tqe;
245 p->txq_head = tqe;
246 }
247 p->txq_entries += 1;
248 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900249
Glen Lee85e57562015-09-24 18:14:56 +0900250 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -0700251 up(p->txq_add_to_head_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900252
253
254 /**
255 * wake up TX queue
256 **/
Glen Lee5cd63632015-09-24 18:14:58 +0900257 up(&g_linux_wlan->txq_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900258 PRINT_D(TX_DBG, "Wake up the txq_handler\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900259
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900260 return 0;
261
262}
263
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900264u32 Statisitcs_totalAcks = 0, Statisitcs_DroppedAcks = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900265
266#ifdef TCP_ACK_FILTER
267struct Ack_session_info;
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530268struct Ack_session_info {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900269 u32 Ack_seq_num;
270 u32 Bigger_Ack_num;
Chaehyun Limec53adf2015-09-15 14:06:15 +0900271 u16 src_port;
272 u16 dst_port;
273 u16 status;
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530274};
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900275
276typedef struct {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900277 u32 ack_num;
278 u32 Session_index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900279 struct txq_entry_t *txqe;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900280} Pending_Acks_info_t /*Ack_info_t*/;
281
282
283
284
285struct Ack_session_info *Free_head;
286struct Ack_session_info *Alloc_head;
287
288#define TCP_FIN_MASK (1 << 0)
289#define TCP_SYN_MASK (1 << 1)
290#define TCP_Ack_MASK (1 << 4)
291#define NOT_TCP_ACK (-1)
292
293#define MAX_TCP_SESSION 25
294#define MAX_PENDING_ACKS 256
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530295struct Ack_session_info Acks_keep_track_info[2 * MAX_TCP_SESSION];
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900296Pending_Acks_info_t Pending_Acks_info[MAX_PENDING_ACKS];
297
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900298u32 PendingAcks_arrBase;
299u32 Opened_TCP_session;
300u32 Pending_Acks;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900301
302
303
Chaehyun Limfed16f22015-09-17 16:48:43 +0900304static inline int Init_TCP_tracking(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900305{
306
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900307 return 0;
308
309}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900310static inline int add_TCP_track_session(u32 src_prt, u32 dst_prt, u32 seq)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900311{
312 Acks_keep_track_info[Opened_TCP_session].Ack_seq_num = seq;
313 Acks_keep_track_info[Opened_TCP_session].Bigger_Ack_num = 0;
314 Acks_keep_track_info[Opened_TCP_session].src_port = src_prt;
315 Acks_keep_track_info[Opened_TCP_session].dst_port = dst_prt;
316 Opened_TCP_session++;
317
318 PRINT_D(TCP_ENH, "TCP Session %d to Ack %d\n", Opened_TCP_session, seq);
319 return 0;
320}
321
Chaehyun Limfed16f22015-09-17 16:48:43 +0900322static inline int Update_TCP_track_session(u32 index, u32 Ack)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900323{
324
325 if (Ack > Acks_keep_track_info[index].Bigger_Ack_num) {
326 Acks_keep_track_info[index].Bigger_Ack_num = Ack;
327 }
328 return 0;
329
330}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900331static inline int add_TCP_Pending_Ack(u32 Ack, u32 Session_index, struct txq_entry_t *txqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900332{
333 Statisitcs_totalAcks++;
334 if (Pending_Acks < MAX_PENDING_ACKS) {
335 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].ack_num = Ack;
336 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].txqe = txqe;
337 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].Session_index = Session_index;
338 txqe->tcp_PendingAck_index = PendingAcks_arrBase + Pending_Acks;
339 Pending_Acks++;
340
341 } else {
342
343 }
344 return 0;
345}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900346static inline int remove_TCP_related(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900347{
348 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
349 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900350
Glen Lee85e57562015-09-24 18:14:56 +0900351 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900352
Glen Lee85e57562015-09-24 18:14:56 +0900353 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900354 return 0;
355}
356
Chaehyun Limfed16f22015-09-17 16:48:43 +0900357static inline int tcp_process(struct txq_entry_t *tqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900358{
359 int ret;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900360 u8 *eth_hdr_ptr;
361 u8 *buffer = tqe->buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900362 unsigned short h_proto;
363 int i;
364 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
365 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900366
Glen Lee85e57562015-09-24 18:14:56 +0900367 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900368
369 eth_hdr_ptr = &buffer[0];
370 h_proto = ntohs(*((unsigned short *)&eth_hdr_ptr[12]));
371 if (h_proto == 0x0800) { /* IP */
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900372 u8 *ip_hdr_ptr;
373 u8 protocol;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900374
375 ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN];
376 protocol = ip_hdr_ptr[9];
377
378
379 if (protocol == 0x06) {
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900380 u8 *tcp_hdr_ptr;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900381 u32 IHL, Total_Length, Data_offset;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900382
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900383 tcp_hdr_ptr = &ip_hdr_ptr[IP_HDR_LEN];
384 IHL = (ip_hdr_ptr[0] & 0xf) << 2;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900385 Total_Length = (((u32)ip_hdr_ptr[2]) << 8) + ((u32)ip_hdr_ptr[3]);
386 Data_offset = (((u32)tcp_hdr_ptr[12] & 0xf0) >> 2);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900387 if (Total_Length == (IHL + Data_offset)) { /*we want to recognize the clear Acks(packet only carry Ack infos not with data) so data size must be equal zero*/
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900388 u32 seq_no, Ack_no;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900389
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900390 seq_no = (((u32)tcp_hdr_ptr[4]) << 24) + (((u32)tcp_hdr_ptr[5]) << 16) + (((u32)tcp_hdr_ptr[6]) << 8) + ((u32)tcp_hdr_ptr[7]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900391
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900392 Ack_no = (((u32)tcp_hdr_ptr[8]) << 24) + (((u32)tcp_hdr_ptr[9]) << 16) + (((u32)tcp_hdr_ptr[10]) << 8) + ((u32)tcp_hdr_ptr[11]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900393
394
395 for (i = 0; i < Opened_TCP_session; i++) {
396 if (Acks_keep_track_info[i].Ack_seq_num == seq_no) {
397 Update_TCP_track_session(i, Ack_no);
398 break;
399 }
400 }
401 if (i == Opened_TCP_session) {
402 add_TCP_track_session(0, 0, seq_no);
403 }
404 add_TCP_Pending_Ack(Ack_no, i, tqe);
405
406
407 }
408
409 } else {
410 ret = 0;
411 }
412 } else {
413 ret = 0;
414 }
Glen Lee85e57562015-09-24 18:14:56 +0900415 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900416 return ret;
417}
418
419
420static int wilc_wlan_txq_filter_dup_tcp_ack(void)
421{
422
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900423 u32 i = 0;
424 u32 Dropped = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900425 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
426
Glen Lee85e57562015-09-24 18:14:56 +0900427 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, p->txq_spinlock_flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900428 for (i = PendingAcks_arrBase; i < (PendingAcks_arrBase + Pending_Acks); i++) {
429 if (Pending_Acks_info[i].ack_num < Acks_keep_track_info[Pending_Acks_info[i].Session_index].Bigger_Ack_num) {
430 struct txq_entry_t *tqe;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900431
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530432 PRINT_D(TCP_ENH, "DROP ACK: %u\n", Pending_Acks_info[i].ack_num);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900433 tqe = Pending_Acks_info[i].txqe;
434 if (tqe) {
435 wilc_wlan_txq_remove(tqe);
436 Statisitcs_DroppedAcks++;
437 tqe->status = 1; /* mark the packet send */
438 if (tqe->tx_complete_func)
439 tqe->tx_complete_func(tqe->priv, tqe->status);
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -0700440 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900441 Dropped++;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900442 }
443 }
444 }
445 Pending_Acks = 0;
446 Opened_TCP_session = 0;
447
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530448 if (PendingAcks_arrBase == 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900449 PendingAcks_arrBase = MAX_TCP_SESSION;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530450 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900451 PendingAcks_arrBase = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900452
453
Glen Lee85e57562015-09-24 18:14:56 +0900454 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock,
455 p->txq_spinlock_flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900456
457 while (Dropped > 0) {
458 /*consume the semaphore count of the removed packet*/
Glen Lee5cd63632015-09-24 18:14:58 +0900459 p->os_func.os_wait(&g_linux_wlan->txq_event, 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900460 Dropped--;
461 }
462
463 return 1;
464}
465#endif
466
Dean Lee72ed4dc2015-06-12 14:11:44 +0900467bool EnableTCPAckFilter = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900468
Dean Lee72ed4dc2015-06-12 14:11:44 +0900469void Enable_TCP_ACK_Filter(bool value)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900470{
471 EnableTCPAckFilter = value;
472}
473
Dean Lee72ed4dc2015-06-12 14:11:44 +0900474bool is_TCP_ACK_Filter_Enabled(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900475{
476 return EnableTCPAckFilter;
477}
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900478
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900479static int wilc_wlan_txq_add_cfg_pkt(u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900480{
481 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
482 struct txq_entry_t *tqe;
483
484 PRINT_D(TX_DBG, "Adding config packet ...\n");
485 if (p->quit) {
486 PRINT_D(TX_DBG, "Return due to clear function\n");
Glen Lee6a3b94f2015-09-24 18:14:59 +0900487 up(&g_linux_wlan->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900488 return 0;
489 }
490
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700491 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900492 if (tqe == NULL) {
493 PRINT_ER("Failed to allocate memory\n");
494 return 0;
495 }
496
497 tqe->type = WILC_CFG_PKT;
498 tqe->buffer = buffer;
499 tqe->buffer_size = buffer_size;
500 tqe->tx_complete_func = NULL;
501 tqe->priv = NULL;
502#ifdef TCP_ACK_FILTER
503 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
504#endif
505 /**
506 * Configuration packet always at the front
507 **/
508 PRINT_D(TX_DBG, "Adding the config packet at the Queue tail\n");
509
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900510 if (wilc_wlan_txq_add_to_head(tqe))
511 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900512 return 1;
513}
514
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900515static int wilc_wlan_txq_add_net_pkt(void *priv, u8 *buffer, u32 buffer_size, wilc_tx_complete_func_t func)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900516{
517 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
518 struct txq_entry_t *tqe;
519
520 if (p->quit)
521 return 0;
522
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700523 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900524
525 if (tqe == NULL)
526 return 0;
527 tqe->type = WILC_NET_PKT;
528 tqe->buffer = buffer;
529 tqe->buffer_size = buffer_size;
530 tqe->tx_complete_func = func;
531 tqe->priv = priv;
532
533 PRINT_D(TX_DBG, "Adding mgmt packet at the Queue tail\n");
534#ifdef TCP_ACK_FILTER
535 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
Abdul Hussain5a66bf22015-06-16 09:44:06 +0000536 if (is_TCP_ACK_Filter_Enabled())
Glen Lee25a84832015-09-16 18:53:22 +0900537 tcp_process(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900538#endif
539 wilc_wlan_txq_add_to_tail(tqe);
540 /*return number of itemes in the queue*/
541 return p->txq_entries;
542}
Glen Leefcc6ef92015-09-16 18:53:21 +0900543
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900544int wilc_wlan_txq_add_mgmt_pkt(void *priv, u8 *buffer, u32 buffer_size, wilc_tx_complete_func_t func)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900545{
546
547 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
548 struct txq_entry_t *tqe;
549
550 if (p->quit)
551 return 0;
552
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700553 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900554
555 if (tqe == NULL)
556 return 0;
557 tqe->type = WILC_MGMT_PKT;
558 tqe->buffer = buffer;
559 tqe->buffer_size = buffer_size;
560 tqe->tx_complete_func = func;
561 tqe->priv = priv;
562#ifdef TCP_ACK_FILTER
563 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
564#endif
565 PRINT_D(TX_DBG, "Adding Network packet at the Queue tail\n");
566 wilc_wlan_txq_add_to_tail(tqe);
567 return 1;
568}
Glen Leefcc6ef92015-09-16 18:53:21 +0900569
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900570static struct txq_entry_t *wilc_wlan_txq_get_first(void)
571{
572 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
573 struct txq_entry_t *tqe;
574 unsigned long flags;
575
Glen Lee85e57562015-09-24 18:14:56 +0900576 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900577
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900578 tqe = p->txq_head;
579
Glen Lee85e57562015-09-24 18:14:56 +0900580 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900581
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900582
583 return tqe;
584}
585
586static struct txq_entry_t *wilc_wlan_txq_get_next(struct txq_entry_t *tqe)
587{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900588 unsigned long flags;
Glen Lee85e57562015-09-24 18:14:56 +0900589 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900590
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900591 tqe = tqe->next;
Glen Lee85e57562015-09-24 18:14:56 +0900592 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900593
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900594
595 return tqe;
596}
597
598static int wilc_wlan_rxq_add(struct rxq_entry_t *rqe)
599{
600 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
601
602 if (p->quit)
603 return 0;
604
Glen Lee645db602015-09-24 18:14:57 +0900605 mutex_lock(&g_linux_wlan->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900606 if (p->rxq_head == NULL) {
607 PRINT_D(RX_DBG, "Add to Queue head\n");
608 rqe->next = NULL;
609 p->rxq_head = rqe;
610 p->rxq_tail = rqe;
611 } else {
612 PRINT_D(RX_DBG, "Add to Queue tail\n");
613 p->rxq_tail->next = rqe;
614 rqe->next = NULL;
615 p->rxq_tail = rqe;
616 }
617 p->rxq_entries += 1;
618 PRINT_D(RX_DBG, "Number of queue entries: %d\n", p->rxq_entries);
Glen Lee645db602015-09-24 18:14:57 +0900619 mutex_unlock(&g_linux_wlan->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900620 return p->rxq_entries;
621}
622
623static struct rxq_entry_t *wilc_wlan_rxq_remove(void)
624{
625 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
626
627 PRINT_D(RX_DBG, "Getting rxQ element\n");
628 if (p->rxq_head) {
629 struct rxq_entry_t *rqe;
630
Glen Lee645db602015-09-24 18:14:57 +0900631 mutex_lock(&g_linux_wlan->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900632 rqe = p->rxq_head;
633 p->rxq_head = p->rxq_head->next;
634 p->rxq_entries -= 1;
635 PRINT_D(RX_DBG, "RXQ entries decreased\n");
Glen Lee645db602015-09-24 18:14:57 +0900636 mutex_unlock(&g_linux_wlan->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900637 return rqe;
638 }
639 PRINT_D(RX_DBG, "Nothing to get from Q\n");
640 return NULL;
641}
642
643
644/********************************************
645 *
646 * Power Save handle functions
647 *
648 ********************************************/
649
650
651
652#ifdef WILC_OPTIMIZE_SLEEP_INT
653
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900654static inline void chip_allow_sleep(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900655{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900656 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900657
658 /* Clear bit 1 */
659 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
660
661 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0));
662}
663
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900664static inline void chip_wakeup(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900665{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900666 u32 reg, clk_status_reg, trials = 0;
667 u32 sleep_time;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900668
669 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
670 do {
671 g_wlan.hif_func.hif_read_reg(1, &reg);
672 /* Set bit 1 */
673 g_wlan.hif_func.hif_write_reg(1, reg | (1 << 1));
674
675 /* Clear bit 1*/
676 g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1));
677
678 do {
679 /* Wait for the chip to stabilize*/
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -0700680 usleep_range(2 * 1000, 2 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900681 /* Make sure chip is awake. This is an extra step that can be removed */
682 /* later to avoid the bus access overhead */
Dean Lee72ed4dc2015-06-12 14:11:44 +0900683 if ((wilc_get_chipid(true) == 0)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900684 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
685 }
Dean Lee72ed4dc2015-06-12 14:11:44 +0900686 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900687
Dean Lee72ed4dc2015-06-12 14:11:44 +0900688 } while (wilc_get_chipid(true) == 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900689 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
690 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
691 do {
692 /* Set bit 1 */
693 g_wlan.hif_func.hif_write_reg(0xf0, reg | (1 << 0));
694
695 /* Check the clock status */
696 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
697
698 /* in case of clocks off, wait 2ms, and check it again. */
699 /* if still off, wait for another 2ms, for a total wait of 6ms. */
700 /* If still off, redo the wake up sequence */
701 while (((clk_status_reg & 0x1) == 0) && (((++trials) % 3) == 0)) {
702 /* Wait for the chip to stabilize*/
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -0700703 usleep_range(2 * 1000, 2 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900704
705 /* Make sure chip is awake. This is an extra step that can be removed */
706 /* later to avoid the bus access overhead */
707 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
708
709 if ((clk_status_reg & 0x1) == 0) {
710 wilc_debug(N_ERR, "clocks still OFF. Wake up failed\n");
711 }
712 }
713 /* in case of failure, Reset the wakeup bit to introduce a new edge on the next loop */
714 if ((clk_status_reg & 0x1) == 0) {
715 /* Reset bit 0 */
716 g_wlan.hif_func.hif_write_reg(0xf0, reg & (~(1 << 0)));
717 }
718 } while ((clk_status_reg & 0x1) == 0);
719 }
720
721
722 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
723 g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
724 reg &= ~(1 << 0);
725 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
726
Dean Lee72ed4dc2015-06-12 14:11:44 +0900727 if (wilc_get_chipid(false) >= 0x1002b0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900728 /* Enable PALDO back right after wakeup */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900729 u32 val32;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900730
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900731 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
732 val32 |= (1 << 6);
733 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
734
735 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
736 val32 |= (1 << 6);
737 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
738 }
739 }
740 genuChipPSstate = CHIP_WAKEDUP;
741}
742#else
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900743static inline void chip_wakeup(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900744{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900745 u32 reg, trials = 0;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900746
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900747 do {
748 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
749 g_wlan.hif_func.hif_read_reg(1, &reg);
750 /* Make sure bit 1 is 0 before we start. */
751 g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1));
752 /* Set bit 1 */
753 g_wlan.hif_func.hif_write_reg(1, reg | (1 << 1));
754 /* Clear bit 1*/
755 g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1));
756 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
757 /* Make sure bit 0 is 0 before we start. */
758 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
759 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0));
760 /* Set bit 1 */
761 g_wlan.hif_func.hif_write_reg(0xf0, reg | (1 << 0));
762 /* Clear bit 1 */
763 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0));
764 }
765
766 do {
767 /* Wait for the chip to stabilize*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900768 mdelay(3);
769
770 /* Make sure chip is awake. This is an extra step that can be removed */
771 /* later to avoid the bus access overhead */
Dean Lee72ed4dc2015-06-12 14:11:44 +0900772 if ((wilc_get_chipid(true) == 0)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900773 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
774 }
Dean Lee72ed4dc2015-06-12 14:11:44 +0900775 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900776
Dean Lee72ed4dc2015-06-12 14:11:44 +0900777 } while (wilc_get_chipid(true) == 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900778
779 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
780 g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
781 reg &= ~(1 << 0);
782 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
783
Dean Lee72ed4dc2015-06-12 14:11:44 +0900784 if (wilc_get_chipid(false) >= 0x1002b0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900785 /* Enable PALDO back right after wakeup */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900786 u32 val32;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900787
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900788 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
789 val32 |= (1 << 6);
790 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
791
792 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
793 val32 |= (1 << 6);
794 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
795 }
796 }
797 genuChipPSstate = CHIP_WAKEDUP;
798}
799#endif
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900800void chip_sleep_manually(u32 u32SleepTime)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900801{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900802 if (genuChipPSstate != CHIP_WAKEDUP) {
803 /* chip is already sleeping. Do nothing */
804 return;
805 }
806 acquire_bus(ACQUIRE_ONLY);
807
808#ifdef WILC_OPTIMIZE_SLEEP_INT
809 chip_allow_sleep();
810#endif
811
812 /* Trigger the manual sleep interrupt */
813 g_wlan.hif_func.hif_write_reg(0x10a8, 1);
814
815 genuChipPSstate = CHIP_SLEEPING_MANUAL;
816 release_bus(RELEASE_ONLY);
817
818}
819
820
821/********************************************
822 *
823 * Tx, Rx queue handle functions
824 *
825 ********************************************/
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900826static int wilc_wlan_handle_txq(u32 *pu32TxqCount)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900827{
828 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
829 int i, entries = 0;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900830 u32 sum;
831 u32 reg;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900832 u8 *txb = p->tx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900833 u32 offset = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900834 int vmm_sz = 0;
835 struct txq_entry_t *tqe;
836 int ret = 0;
837 int counter;
838 int timeout;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900839 u32 vmm_table[WILC_VMM_TBL_SIZE];
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900840
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900841 p->txq_exit = 0;
842 do {
843 if (p->quit)
844 break;
845
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900846 p->os_func.os_wait(p->txq_add_to_head_lock, CFG_PKTS_TIMEOUT);
847#ifdef TCP_ACK_FILTER
848 wilc_wlan_txq_filter_dup_tcp_ack();
849#endif
850 /**
851 * build the vmm list
852 **/
853 PRINT_D(TX_DBG, "Getting the head of the TxQ\n");
854 tqe = wilc_wlan_txq_get_first();
855 i = 0;
856 sum = 0;
857 do {
858 /* if ((tqe != NULL) && (i < (8)) && */
859 /* if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE-1)) && */
860 if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE - 1)) /* reserve last entry to 0 */) {
861
862 if (tqe->type == WILC_CFG_PKT) {
863 vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET;
864 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900865 else if (tqe->type == WILC_NET_PKT) {
866 vmm_sz = ETH_ETHERNET_HDR_OFFSET;
867 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900868 else {
869 vmm_sz = HOST_HDR_OFFSET;
870 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900871 vmm_sz += tqe->buffer_size;
872 PRINT_D(TX_DBG, "VMM Size before alignment = %d\n", vmm_sz);
873 if (vmm_sz & 0x3) { /* has to be word aligned */
874 vmm_sz = (vmm_sz + 4) & ~0x3;
875 }
876 if ((sum + vmm_sz) > p->tx_buffer_size) {
877 break;
878 }
879 PRINT_D(TX_DBG, "VMM Size AFTER alignment = %d\n", vmm_sz);
880 vmm_table[i] = vmm_sz / 4; /* table take the word size */
881 PRINT_D(TX_DBG, "VMMTable entry size = %d\n", vmm_table[i]);
882
883 if (tqe->type == WILC_CFG_PKT) {
884 vmm_table[i] |= (1 << 10);
885 PRINT_D(TX_DBG, "VMMTable entry changed for CFG packet = %d\n", vmm_table[i]);
886 }
887#ifdef BIG_ENDIAN
888 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
889#endif
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900890
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900891 i++;
892 sum += vmm_sz;
893 PRINT_D(TX_DBG, "sum = %d\n", sum);
894 tqe = wilc_wlan_txq_get_next(tqe);
895 } else {
896 break;
897 }
898 } while (1);
899
900 if (i == 0) { /* nothing in the queue */
901 PRINT_D(TX_DBG, "Nothing in TX-Q\n");
902 break;
903 } else {
904 PRINT_D(TX_DBG, "Mark the last entry in VMM table - number of previous entries = %d\n", i);
905 vmm_table[i] = 0x0; /* mark the last element to 0 */
906 }
907 acquire_bus(ACQUIRE_AND_WAKEUP);
908 counter = 0;
909 do {
910
911 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg);
912 if (!ret) {
913 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg vmm_tbl_entry..\n");
914 break;
915 }
916
917 if ((reg & 0x1) == 0) {
918 /**
919 * write to vmm table
920 **/
921 PRINT_D(TX_DBG, "Writing VMM table ... with Size = %d\n", ((i + 1) * 4));
922 break;
923 } else {
924 counter++;
925 if (counter > 200) {
926 counter = 0;
927 PRINT_D(TX_DBG, "Looping in tx ctrl , forcce quit\n");
928 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, 0);
929 break;
930 }
931 /**
932 * wait for vmm table is ready
933 **/
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530934 PRINT_WRN(GENERIC_DBG, "[wilc txq]: warn, vmm table not clear yet, wait...\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900935 release_bus(RELEASE_ALLOW_SLEEP);
Greg Kroah-Hartman2b922cb2015-09-04 09:30:51 -0700936 usleep_range(3000, 3000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900937 acquire_bus(ACQUIRE_AND_WAKEUP);
938 }
939 } while (!p->quit);
940
941 if (!ret) {
942 goto _end_;
943 }
944
945 timeout = 200;
946 do {
947
948 /**
949 * write to vmm table
950 **/
Chaehyun Limc3ca6372015-09-20 15:51:19 +0900951 ret = p->hif_func.hif_block_tx(WILC_VMM_TBL_RX_SHADOW_BASE, (u8 *)vmm_table, ((i + 1) * 4));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900952 if (!ret) {
953 wilc_debug(N_ERR, "ERR block TX of VMM table.\n");
954 break;
955 }
956
957
958 /**
959 * interrupt firmware
960 **/
961 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x2);
962 if (!ret) {
963 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg host_vmm_ctl..\n");
964 break;
965 }
966
967 /**
968 * wait for confirm...
969 **/
970
971 do {
972 ret = p->hif_func.hif_read_reg(WILC_HOST_VMM_CTL, &reg);
973 if (!ret) {
974 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg host_vmm_ctl..\n");
975 break;
976 }
977 if ((reg >> 2) & 0x1) {
978 /**
979 * Get the entries
980 **/
981 entries = ((reg >> 3) & 0x3f);
982 /* entries = ((reg>>3)&0x2f); */
983 break;
984 } else {
985 release_bus(RELEASE_ALLOW_SLEEP);
Greg Kroah-Hartman2b922cb2015-09-04 09:30:51 -0700986 usleep_range(3000, 3000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900987 acquire_bus(ACQUIRE_AND_WAKEUP);
988 PRINT_WRN(GENERIC_DBG, "Can't get VMM entery - reg = %2x\n", reg);
989 }
990 } while (--timeout);
991 if (timeout <= 0) {
992 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x0);
993 break;
994 }
995
996 if (!ret) {
997 break;
998 }
999
1000 if (entries == 0) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301001 PRINT_WRN(GENERIC_DBG, "[wilc txq]: no more buffer in the chip (reg: %08x), retry later [[ %d, %x ]]\n", reg, i, vmm_table[i - 1]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001002
1003 /* undo the transaction. */
1004 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg);
1005 if (!ret) {
1006 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg WILC_HOST_TX_CTRL..\n");
1007 break;
1008 }
1009 reg &= ~(1ul << 0);
1010 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, reg);
1011 if (!ret) {
1012 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg WILC_HOST_TX_CTRL..\n");
1013 break;
1014 }
1015 break;
1016 } else {
1017 break;
1018 }
1019 } while (1);
1020
1021 if (!ret) {
1022 goto _end_;
1023 }
1024 if (entries == 0) {
1025 ret = WILC_TX_ERR_NO_BUF;
1026 goto _end_;
1027 }
1028
1029 /* since copying data into txb takes some time, then
1030 * allow the bus lock to be released let the RX task go. */
1031 release_bus(RELEASE_ALLOW_SLEEP);
1032
1033 /**
1034 * Copy data to the TX buffer
1035 **/
1036 offset = 0;
1037 i = 0;
1038 do {
1039 tqe = wilc_wlan_txq_remove_from_head();
1040 if (tqe != NULL && (vmm_table[i] != 0)) {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001041 u32 header, buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001042
1043#ifdef BIG_ENDIAN
1044 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
1045#endif
1046 vmm_sz = (vmm_table[i] & 0x3ff); /* in word unit */
1047 vmm_sz *= 4;
1048 header = (tqe->type << 31) | (tqe->buffer_size << 15) | vmm_sz;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301049 if (tqe->type == WILC_MGMT_PKT)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001050 header |= (1 << 30);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301051 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001052 header &= ~(1 << 30);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001053
1054#ifdef BIG_ENDIAN
1055 header = BYTE_SWAP(header);
1056#endif
1057 memcpy(&txb[offset], &header, 4);
1058 if (tqe->type == WILC_CFG_PKT) {
1059 buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET;
1060 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001061 else if (tqe->type == WILC_NET_PKT) {
1062 char *pBSSID = ((struct tx_complete_data *)(tqe->priv))->pBssid;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001063
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001064 buffer_offset = ETH_ETHERNET_HDR_OFFSET;
1065 /* copy the bssid at the sart of the buffer */
1066 memcpy(&txb[offset + 4], pBSSID, 6);
1067 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001068 else {
1069 buffer_offset = HOST_HDR_OFFSET;
1070 }
1071
1072 memcpy(&txb[offset + buffer_offset], tqe->buffer, tqe->buffer_size);
1073 offset += vmm_sz;
1074 i++;
1075 tqe->status = 1; /* mark the packet send */
1076 if (tqe->tx_complete_func)
1077 tqe->tx_complete_func(tqe->priv, tqe->status);
1078 #ifdef TCP_ACK_FILTER
1079 if (tqe->tcp_PendingAck_index != NOT_TCP_ACK) {
1080 Pending_Acks_info[tqe->tcp_PendingAck_index].txqe = NULL;
1081 }
1082 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001083 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001084 } else {
1085 break;
1086 }
1087 } while (--entries);
1088
1089 /**
1090 * lock the bus
1091 **/
1092 acquire_bus(ACQUIRE_AND_WAKEUP);
1093
1094 ret = p->hif_func.hif_clear_int_ext(ENABLE_TX_VMM);
1095 if (!ret) {
1096 wilc_debug(N_ERR, "[wilc txq]: fail can't start tx VMM ...\n");
1097 goto _end_;
1098 }
1099
1100 /**
1101 * transfer
1102 **/
1103 ret = p->hif_func.hif_block_tx_ext(0, txb, offset);
1104 if (!ret) {
1105 wilc_debug(N_ERR, "[wilc txq]: fail can't block tx ext...\n");
1106 goto _end_;
1107 }
1108
1109_end_:
1110
1111 release_bus(RELEASE_ALLOW_SLEEP);
1112 if (ret != 1)
1113 break;
1114 } while (0);
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -07001115 up(p->txq_add_to_head_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001116
1117 p->txq_exit = 1;
1118 PRINT_D(TX_DBG, "THREAD: Exiting txq\n");
1119 /* return tx[]q count */
1120 *pu32TxqCount = p->txq_entries;
1121 return ret;
1122}
1123
1124static void wilc_wlan_handle_rxq(void)
1125{
1126 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1127 int offset = 0, size, has_packet = 0;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001128 u8 *buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001129 struct rxq_entry_t *rqe;
1130
1131 p->rxq_exit = 0;
1132
1133
1134
1135
1136 do {
1137 if (p->quit) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301138 PRINT_D(RX_DBG, "exit 1st do-while due to Clean_UP function\n");
Glen Lee6a3b94f2015-09-24 18:14:59 +09001139 up(&g_linux_wlan->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001140 break;
1141 }
1142 rqe = wilc_wlan_rxq_remove();
1143 if (rqe == NULL) {
1144 PRINT_D(RX_DBG, "nothing in the queue - exit 1st do-while\n");
1145 break;
1146 }
1147 buffer = rqe->buffer;
1148 size = rqe->buffer_size;
1149 PRINT_D(RX_DBG, "rxQ entery Size = %d - Address = %p\n", size, buffer);
1150 offset = 0;
1151
1152
1153
1154 do {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001155 u32 header;
1156 u32 pkt_len, pkt_offset, tp_len;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001157 int is_cfg_packet;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001158
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001159 PRINT_D(RX_DBG, "In the 2nd do-while\n");
1160 memcpy(&header, &buffer[offset], 4);
1161#ifdef BIG_ENDIAN
1162 header = BYTE_SWAP(header);
1163#endif
1164 PRINT_D(RX_DBG, "Header = %04x - Offset = %d\n", header, offset);
1165
1166
1167
1168 is_cfg_packet = (header >> 31) & 0x1;
1169 pkt_offset = (header >> 22) & 0x1ff;
1170 tp_len = (header >> 11) & 0x7ff;
1171 pkt_len = header & 0x7ff;
1172
1173 if (pkt_len == 0 || tp_len == 0) {
1174 wilc_debug(N_RXQ, "[wilc rxq]: data corrupt, packet len or tp_len is 0 [%d][%d]\n", pkt_len, tp_len);
1175 break;
1176 }
1177
1178/*bug 3887: [AP] Allow Management frames to be passed to the host*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001179 #define IS_MANAGMEMENT 0x100
1180 #define IS_MANAGMEMENT_CALLBACK 0x080
1181 #define IS_MGMT_STATUS_SUCCES 0x040
1182
1183
1184 if (pkt_offset & IS_MANAGMEMENT) {
1185 /* reset mgmt indicator bit, to use pkt_offeset in furthur calculations */
1186 pkt_offset &= ~(IS_MANAGMEMENT | IS_MANAGMEMENT_CALLBACK | IS_MGMT_STATUS_SUCCES);
1187
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001188 WILC_WFI_mgmt_rx(&buffer[offset + HOST_HDR_OFFSET], pkt_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001189 }
1190 /* BUG4530 fix */
1191 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001192 {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001193
1194 if (!is_cfg_packet) {
Glen Lee63611672015-09-24 18:14:52 +09001195 if (pkt_len > 0) {
1196 frmw_to_linux(&buffer[offset],
1197 pkt_len,
1198 pkt_offset);
1199 has_packet = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001200 }
1201 } else {
1202 wilc_cfg_rsp_t rsp;
1203
1204
1205
1206 p->cif_func.rx_indicate(&buffer[pkt_offset + offset], pkt_len, &rsp);
1207 if (rsp.type == WILC_CFG_RSP) {
1208 /**
1209 * wake up the waiting task...
1210 **/
1211 PRINT_D(RX_DBG, "p->cfg_seq_no = %d - rsp.seq_no = %d\n", p->cfg_seq_no, rsp.seq_no);
1212 if (p->cfg_seq_no == rsp.seq_no) {
Glen Lee6a3b94f2015-09-24 18:14:59 +09001213 up(&g_linux_wlan->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001214 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001215 } else if (rsp.type == WILC_CFG_RSP_STATUS) {
1216 /**
1217 * Call back to indicate status...
1218 **/
Glen Lee4417d3d2015-09-24 18:14:53 +09001219 linux_wlan_mac_indicate(WILC_MAC_INDICATE_STATUS);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001220
1221 } else if (rsp.type == WILC_CFG_RSP_SCAN) {
Glen Lee4417d3d2015-09-24 18:14:53 +09001222 linux_wlan_mac_indicate(WILC_MAC_INDICATE_SCAN);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001223 }
1224 }
1225 }
1226 offset += tp_len;
1227 if (offset >= size)
1228 break;
1229 } while (1);
1230
1231
1232#ifndef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001233 kfree(buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001234#endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001235 kfree(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001236
1237 if (has_packet) {
Glen Leec0cadaa2015-09-24 18:14:54 +09001238 linux_wlan_rx_complete();
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001239 }
1240 } while (1);
1241
1242 p->rxq_exit = 1;
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301243 PRINT_D(RX_DBG, "THREAD: Exiting RX thread\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001244}
1245
1246/********************************************
1247 *
1248 * Fast DMA Isr
1249 *
1250 ********************************************/
1251static void wilc_unknown_isr_ext(void)
1252{
1253 g_wlan.hif_func.hif_clear_int_ext(0);
1254}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001255static void wilc_pllupdate_isr_ext(u32 int_stats)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001256{
1257
1258 int trials = 10;
1259
1260 g_wlan.hif_func.hif_clear_int_ext(PLL_INT_CLR);
1261
1262 /* Waiting for PLL */
Greg Kroah-Hartmanc2e4c0f2015-09-03 19:09:50 -07001263 mdelay(WILC_PLL_TO);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001264
1265 /* poll till read a valid data */
Dean Lee72ed4dc2015-06-12 14:11:44 +09001266 while (!(ISWILC1000(wilc_get_chipid(true)) && --trials)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001267 PRINT_D(TX_DBG, "PLL update retrying\n");
Greg Kroah-Hartmanc2e4c0f2015-09-03 19:09:50 -07001268 mdelay(1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001269 }
1270}
1271
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001272static void wilc_sleeptimer_isr_ext(u32 int_stats1)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001273{
1274 g_wlan.hif_func.hif_clear_int_ext(SLEEP_INT_CLR);
1275#ifndef WILC_OPTIMIZE_SLEEP_INT
1276 genuChipPSstate = CHIP_SLEEPING_AUTO;
1277#endif
1278}
1279
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001280static void wilc_wlan_handle_isr_ext(u32 int_status)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001281{
1282 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1283#ifdef MEMORY_STATIC
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001284 u32 offset = p->rx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001285#endif
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001286 u8 *buffer = NULL;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001287 u32 size;
1288 u32 retries = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001289 int ret = 0;
1290 struct rxq_entry_t *rqe;
1291
1292
1293 /**
1294 * Get the rx size
1295 **/
1296
1297 size = ((int_status & 0x7fff) << 2);
1298
1299 while (!size && retries < 10) {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001300 u32 time = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001301 /*looping more secure*/
1302 /*zero size make a crashe because the dma will not happen and that will block the firmware*/
1303 wilc_debug(N_ERR, "RX Size equal zero ... Trying to read it again for %d time\n", time++);
1304 p->hif_func.hif_read_size(&size);
1305 size = ((size & 0x7fff) << 2);
1306 retries++;
1307
1308 }
1309
1310 if (size > 0) {
1311#ifdef MEMORY_STATIC
1312 if (p->rx_buffer_size - offset < size)
1313 offset = 0;
1314
1315 if (p->rx_buffer)
1316 buffer = &p->rx_buffer[offset];
1317 else {
1318 wilc_debug(N_ERR, "[wilc isr]: fail Rx Buffer is NULL...drop the packets (%d)\n", size);
1319 goto _end_;
1320 }
1321
1322#else
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001323 buffer = kmalloc(size, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001324 if (buffer == NULL) {
1325 wilc_debug(N_ERR, "[wilc isr]: fail alloc host memory...drop the packets (%d)\n", size);
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -07001326 usleep_range(100 * 1000, 100 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001327 goto _end_;
1328 }
1329#endif
1330
1331 /**
1332 * clear the chip's interrupt after getting size some register getting corrupted after clear the interrupt
1333 **/
1334 p->hif_func.hif_clear_int_ext(DATA_INT_CLR | ENABLE_RX_VMM);
1335
1336
1337 /**
1338 * start transfer
1339 **/
1340 ret = p->hif_func.hif_block_rx_ext(0, buffer, size);
1341
1342 if (!ret) {
1343 wilc_debug(N_ERR, "[wilc isr]: fail block rx...\n");
1344 goto _end_;
1345 }
1346_end_:
1347
1348
1349 if (ret) {
1350#ifdef MEMORY_STATIC
1351 offset += size;
1352 p->rx_buffer_offset = offset;
1353#endif
1354 /**
1355 * add to rx queue
1356 **/
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001357 rqe = kmalloc(sizeof(struct rxq_entry_t), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001358 if (rqe != NULL) {
1359 rqe->buffer = buffer;
1360 rqe->buffer_size = size;
1361 PRINT_D(RX_DBG, "rxq entery Size= %d - Address = %p\n", rqe->buffer_size, rqe->buffer);
1362 wilc_wlan_rxq_add(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001363 }
1364 } else {
1365#ifndef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001366 kfree(buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001367#endif
1368 }
1369 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001370 wilc_wlan_handle_rxq();
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001371}
1372
1373void wilc_handle_isr(void)
1374{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001375 u32 int_status;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001376
1377 acquire_bus(ACQUIRE_AND_WAKEUP);
1378 g_wlan.hif_func.hif_read_int(&int_status);
1379
1380 if (int_status & PLL_INT_EXT) {
1381 wilc_pllupdate_isr_ext(int_status);
1382 }
1383 if (int_status & DATA_INT_EXT) {
1384 wilc_wlan_handle_isr_ext(int_status);
1385 #ifndef WILC_OPTIMIZE_SLEEP_INT
1386 /* Chip is up and talking*/
1387 genuChipPSstate = CHIP_WAKEDUP;
1388 #endif
1389 }
1390 if (int_status & SLEEP_INT_EXT) {
1391 wilc_sleeptimer_isr_ext(int_status);
1392 }
1393
1394 if (!(int_status & (ALL_INT_EXT))) {
1395#ifdef WILC_SDIO
1396 PRINT_D(TX_DBG, ">> UNKNOWN_INTERRUPT - 0x%08x\n", int_status);
1397#endif
1398 wilc_unknown_isr_ext();
1399 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001400 release_bus(RELEASE_ALLOW_SLEEP);
1401}
1402
1403/********************************************
1404 *
1405 * Firmware download
1406 *
1407 ********************************************/
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001408static int wilc_wlan_firmware_download(const u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001409{
1410 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001411 u32 offset;
1412 u32 addr, size, size2, blksz;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001413 u8 *dma_buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001414 int ret = 0;
1415
Chaehyun Limc3ca6372015-09-20 15:51:19 +09001416 blksz = (1ul << 12);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001417 /* Allocate a DMA coherent buffer. */
1418
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001419 dma_buffer = kmalloc(blksz, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001420 if (dma_buffer == NULL) {
1421 /*EIO 5*/
1422 ret = -5;
1423 PRINT_ER("Can't allocate buffer for firmware download IO error\n ");
1424 goto _fail_1;
1425 }
1426
1427 PRINT_D(INIT_DBG, "Downloading firmware size = %d ...\n", buffer_size);
1428 /**
1429 * load the firmware
1430 **/
1431 offset = 0;
1432 do {
1433 memcpy(&addr, &buffer[offset], 4);
1434 memcpy(&size, &buffer[offset + 4], 4);
1435#ifdef BIG_ENDIAN
1436 addr = BYTE_SWAP(addr);
1437 size = BYTE_SWAP(size);
1438#endif
1439 acquire_bus(ACQUIRE_ONLY);
1440 offset += 8;
1441 while (((int)size) && (offset < buffer_size)) {
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301442 if (size <= blksz)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001443 size2 = size;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301444 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001445 size2 = blksz;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001446 /* Copy firmware into a DMA coherent buffer */
1447 memcpy(dma_buffer, &buffer[offset], size2);
1448 ret = p->hif_func.hif_block_tx(addr, dma_buffer, size2);
1449 if (!ret)
1450 break;
1451
1452 addr += size2;
1453 offset += size2;
1454 size -= size2;
1455 }
1456 release_bus(RELEASE_ONLY);
1457
1458 if (!ret) {
1459 /*EIO 5*/
1460 ret = -5;
1461 PRINT_ER("Can't download firmware IO error\n ");
1462 goto _fail_;
1463 }
1464 PRINT_D(INIT_DBG, "Offset = %d\n", offset);
1465 } while (offset < buffer_size);
1466
1467_fail_:
1468
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001469 kfree(dma_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001470
1471_fail_1:
1472
1473 return (ret < 0) ? ret : 0;
1474}
1475
1476/********************************************
1477 *
1478 * Common
1479 *
1480 ********************************************/
1481static int wilc_wlan_start(void)
1482{
1483 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001484 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001485 int ret;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001486 u32 chipid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001487
1488 /**
1489 * Set the host interface
1490 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001491 if (p->io_func.io_type == HIF_SDIO) {
1492 reg = 0;
1493 reg |= (1 << 3); /* bug 4456 and 4557 */
1494 } else if (p->io_func.io_type == HIF_SPI) {
1495 reg = 1;
1496 }
1497 acquire_bus(ACQUIRE_ONLY);
1498 ret = p->hif_func.hif_write_reg(WILC_VMM_CORE_CFG, reg);
1499 if (!ret) {
1500 wilc_debug(N_ERR, "[wilc start]: fail write reg vmm_core_cfg...\n");
1501 release_bus(RELEASE_ONLY);
1502 /* EIO 5*/
1503 ret = -5;
1504 return ret;
1505 }
1506 reg = 0;
1507#ifdef WILC_SDIO_IRQ_GPIO
1508 reg |= WILC_HAVE_SDIO_IRQ_GPIO;
1509#endif
1510
1511#ifdef WILC_DISABLE_PMU
1512#else
1513 reg |= WILC_HAVE_USE_PMU;
1514#endif
1515
1516#ifdef WILC_SLEEP_CLK_SRC_XO
1517 reg |= WILC_HAVE_SLEEP_CLK_SRC_XO;
1518#elif defined WILC_SLEEP_CLK_SRC_RTC
1519 reg |= WILC_HAVE_SLEEP_CLK_SRC_RTC;
1520#endif
1521
1522#ifdef WILC_EXT_PA_INV_TX_RX
1523 reg |= WILC_HAVE_EXT_PA_INV_TX_RX;
1524#endif
1525
1526 reg |= WILC_HAVE_LEGACY_RF_SETTINGS;
1527
1528
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001529/*Set oscillator frequency*/
1530#ifdef XTAL_24
1531 reg |= WILC_HAVE_XTAL_24;
1532#endif
1533
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001534/*Enable/Disable GPIO configuration for FW logs*/
1535#ifdef DISABLE_WILC_UART
1536 reg |= WILC_HAVE_DISABLE_WILC_UART;
1537#endif
1538
1539 ret = p->hif_func.hif_write_reg(WILC_GP_REG_1, reg);
1540 if (!ret) {
1541 wilc_debug(N_ERR, "[wilc start]: fail write WILC_GP_REG_1 ...\n");
1542 release_bus(RELEASE_ONLY);
1543 /* EIO 5*/
1544 ret = -5;
1545 return ret;
1546 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001547
1548 /**
1549 * Bus related
1550 **/
1551 p->hif_func.hif_sync_ext(NUM_INT_EXT);
1552
1553 ret = p->hif_func.hif_read_reg(0x1000, &chipid);
1554 if (!ret) {
1555 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1000 ...\n");
1556 release_bus(RELEASE_ONLY);
1557 /* EIO 5*/
1558 ret = -5;
1559 return ret;
1560 }
1561
1562 /**
1563 * Go...
1564 **/
1565
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001566
1567 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1568 if ((reg & (1ul << 10)) == (1ul << 10)) {
1569 reg &= ~(1ul << 10);
1570 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1571 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1572 }
1573
1574 reg |= (1ul << 10);
1575 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1576 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1577 release_bus(RELEASE_ONLY);
1578
1579 return (ret < 0) ? ret : 0;
1580}
1581
1582void wilc_wlan_global_reset(void)
1583{
1584
1585 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001586
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001587 acquire_bus(ACQUIRE_AND_WAKEUP);
1588 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, 0x0);
1589 release_bus(RELEASE_ONLY);
1590}
1591static int wilc_wlan_stop(void)
1592{
1593 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001594 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001595 int ret;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001596 u8 timeout = 10;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001597 /**
1598 * TODO: stop the firmware, need a re-download
1599 **/
1600 acquire_bus(ACQUIRE_AND_WAKEUP);
1601
1602 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1603 if (!ret) {
1604 PRINT_ER("Error while reading reg\n");
1605 release_bus(RELEASE_ALLOW_SLEEP);
1606 return ret;
1607 }
1608
1609 reg &= ~(1 << 10);
1610
1611
1612 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1613 if (!ret) {
1614 PRINT_ER("Error while writing reg\n");
1615 release_bus(RELEASE_ALLOW_SLEEP);
1616 return ret;
1617 }
1618
1619
1620
1621 do {
1622 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1623 if (!ret) {
1624 PRINT_ER("Error while reading reg\n");
1625 release_bus(RELEASE_ALLOW_SLEEP);
1626 return ret;
1627 }
1628 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1629 /*Workaround to ensure that the chip is actually reset*/
1630 if ((reg & (1 << 10))) {
1631 PRINT_D(GENERIC_DBG, "Bit 10 not reset : Retry %d\n", timeout);
1632 reg &= ~(1 << 10);
1633 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1634 timeout--;
1635 } else {
1636 PRINT_D(GENERIC_DBG, "Bit 10 reset after : Retry %d\n", timeout);
1637 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1638 if (!ret) {
1639 PRINT_ER("Error while reading reg\n");
1640 release_bus(RELEASE_ALLOW_SLEEP);
1641 return ret;
1642 }
1643 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1644 break;
1645 }
1646
1647 } while (timeout);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001648 reg = ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 8) | (1 << 9) | (1 << 26) | (1 << 29) | (1 << 30) | (1 << 31)); /**/
1649 /**/
Hari Prasath Gujulan Elango369f1902015-06-22 07:04:39 +00001650 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); /**/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001651 reg = ~(1 << 10); /**/
1652 /**/
1653 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); /**/
1654/******************************************************************************/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001655
1656 release_bus(RELEASE_ALLOW_SLEEP);
1657
1658 return ret;
1659}
1660
1661static void wilc_wlan_cleanup(void)
1662{
1663 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1664 struct txq_entry_t *tqe;
1665 struct rxq_entry_t *rqe;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001666 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001667 int ret;
1668
1669 p->quit = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001670 do {
1671 tqe = wilc_wlan_txq_remove_from_head();
1672 if (tqe == NULL)
1673 break;
1674 if (tqe->tx_complete_func)
1675 tqe->tx_complete_func(tqe->priv, 0);
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001676 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001677 } while (1);
1678
1679 do {
1680 rqe = wilc_wlan_rxq_remove();
1681 if (rqe == NULL)
1682 break;
Javier Martinez Canillas6a272242015-09-22 15:24:50 +02001683#ifndef MEMORY_STATIC
1684 kfree(rqe->buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001685#endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001686 kfree(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001687 } while (1);
1688
1689 /**
1690 * clean up buffer
1691 **/
1692
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001693 #ifdef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001694 kfree(p->rx_buffer);
1695 p->rx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001696 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001697 kfree(p->tx_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001698
1699 acquire_bus(ACQUIRE_AND_WAKEUP);
1700
1701
1702 ret = p->hif_func.hif_read_reg(WILC_GP_REG_0, &reg);
1703 if (!ret) {
1704 PRINT_ER("Error while reading reg\n");
1705 release_bus(RELEASE_ALLOW_SLEEP);
1706 }
1707 PRINT_ER("Writing ABORT reg\n");
1708 ret = p->hif_func.hif_write_reg(WILC_GP_REG_0, (reg | ABORT_INT));
1709 if (!ret) {
1710 PRINT_ER("Error while writing reg\n");
1711 release_bus(RELEASE_ALLOW_SLEEP);
1712 }
1713 release_bus(RELEASE_ALLOW_SLEEP);
1714 /**
1715 * io clean up
1716 **/
1717 p->hif_func.hif_deinit(NULL);
1718
1719}
1720
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001721static int wilc_wlan_cfg_commit(int type, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001722{
1723 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1724 wilc_cfg_frame_t *cfg = &p->cfg_frame;
1725 int total_len = p->cfg_frame_offset + 4 + DRIVER_HANDLER_SIZE;
1726 int seq_no = p->cfg_seq_no % 256;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001727 int driver_handler = (u32)drvHandler;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001728
1729
1730 /**
1731 * Set up header
1732 **/
1733 if (type == WILC_CFG_SET) { /* Set */
1734 cfg->wid_header[0] = 'W';
1735 } else { /* Query */
1736 cfg->wid_header[0] = 'Q';
1737 }
1738 cfg->wid_header[1] = seq_no; /* sequence number */
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001739 cfg->wid_header[2] = (u8)total_len;
1740 cfg->wid_header[3] = (u8)(total_len >> 8);
1741 cfg->wid_header[4] = (u8)driver_handler;
1742 cfg->wid_header[5] = (u8)(driver_handler >> 8);
1743 cfg->wid_header[6] = (u8)(driver_handler >> 16);
1744 cfg->wid_header[7] = (u8)(driver_handler >> 24);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001745 p->cfg_seq_no = seq_no;
1746
1747 /**
1748 * Add to TX queue
1749 **/
1750
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001751 if (!wilc_wlan_txq_add_cfg_pkt(&cfg->wid_header[0], total_len))
1752 return -1;
1753
1754 return 0;
1755}
1756
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001757static int wilc_wlan_cfg_set(int start, u32 wid, u8 *buffer, u32 buffer_size, int commit, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001758{
1759 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001760 u32 offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001761 int ret_size;
1762
1763
1764 if (p->cfg_frame_in_use)
1765 return 0;
1766
1767 if (start)
1768 p->cfg_frame_offset = 0;
1769
1770 offset = p->cfg_frame_offset;
Chaehyun Limec53adf2015-09-15 14:06:15 +09001771 ret_size = p->cif_func.cfg_wid_set(p->cfg_frame.frame, offset, (u16)wid, buffer, buffer_size);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001772 offset += ret_size;
1773 p->cfg_frame_offset = offset;
1774
1775 if (commit) {
1776 PRINT_D(TX_DBG, "[WILC]PACKET Commit with sequence number %d\n", p->cfg_seq_no);
1777 PRINT_D(RX_DBG, "Processing cfg_set()\n");
1778 p->cfg_frame_in_use = 1;
1779
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001780 if (wilc_wlan_cfg_commit(WILC_CFG_SET, drvHandler))
Chaehyun Lim5af6b852015-09-17 16:48:48 +09001781 ret_size = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001782
Glen Lee6a3b94f2015-09-24 18:14:59 +09001783 if (p->os_func.os_wait(&g_linux_wlan->cfg_event,
1784 CFG_PKTS_TIMEOUT)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001785 PRINT_D(TX_DBG, "Set Timed Out\n");
1786 ret_size = 0;
1787 }
1788 p->cfg_frame_in_use = 0;
1789 p->cfg_frame_offset = 0;
1790 p->cfg_seq_no += 1;
1791
1792 }
1793
1794 return ret_size;
1795}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001796static int wilc_wlan_cfg_get(int start, u32 wid, int commit, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001797{
1798 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001799 u32 offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001800 int ret_size;
1801
1802
1803 if (p->cfg_frame_in_use)
1804 return 0;
1805
1806 if (start)
1807 p->cfg_frame_offset = 0;
1808
1809 offset = p->cfg_frame_offset;
Chaehyun Limec53adf2015-09-15 14:06:15 +09001810 ret_size = p->cif_func.cfg_wid_get(p->cfg_frame.frame, offset, (u16)wid);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001811 offset += ret_size;
1812 p->cfg_frame_offset = offset;
1813
1814 if (commit) {
1815 p->cfg_frame_in_use = 1;
1816
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001817 if (wilc_wlan_cfg_commit(WILC_CFG_QUERY, drvHandler))
Chaehyun Lim5af6b852015-09-17 16:48:48 +09001818 ret_size = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001819
1820
Glen Lee6a3b94f2015-09-24 18:14:59 +09001821 if (p->os_func.os_wait(&g_linux_wlan->cfg_event,
1822 CFG_PKTS_TIMEOUT)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001823 PRINT_D(TX_DBG, "Get Timed Out\n");
1824 ret_size = 0;
1825 }
1826 PRINT_D(GENERIC_DBG, "[WILC]Get Response received\n");
1827 p->cfg_frame_in_use = 0;
1828 p->cfg_frame_offset = 0;
1829 p->cfg_seq_no += 1;
1830 }
1831
1832 return ret_size;
1833}
1834
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001835static int wilc_wlan_cfg_get_val(u32 wid, u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001836{
1837 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1838 int ret;
1839
Chaehyun Limec53adf2015-09-15 14:06:15 +09001840 ret = p->cif_func.cfg_wid_get_val((u16)wid, buffer, buffer_size);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001841
1842 return ret;
1843}
1844
1845void wilc_bus_set_max_speed(void)
1846{
1847
1848 /* Increase bus speed to max possible. */
1849 g_wlan.hif_func.hif_set_max_bus_speed();
1850}
1851
1852void wilc_bus_set_default_speed(void)
1853{
1854
1855 /* Restore bus speed to default. */
1856 g_wlan.hif_func.hif_set_default_bus_speed();
1857}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001858u32 init_chip(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001859{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001860 u32 chipid;
1861 u32 reg, ret = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001862
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001863 acquire_bus(ACQUIRE_ONLY);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001864
Dean Lee72ed4dc2015-06-12 14:11:44 +09001865 chipid = wilc_get_chipid(true);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001866
1867
1868
1869 if ((chipid & 0xfff) != 0xa0) {
1870 /**
1871 * Avoid booting from boot ROM. Make sure that Drive IRQN [SDIO platform]
1872 * or SD_DAT3 [SPI platform] to ?1?
1873 **/
1874 /* Set cortus reset register to register control. */
1875 ret = g_wlan.hif_func.hif_read_reg(0x1118, &reg);
1876 if (!ret) {
1877 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1118 ...\n");
1878 return ret;
1879 }
1880 reg |= (1 << 0);
1881 ret = g_wlan.hif_func.hif_write_reg(0x1118, reg);
1882 if (!ret) {
1883 wilc_debug(N_ERR, "[wilc start]: fail write reg 0x1118 ...\n");
1884 return ret;
1885 }
1886 /**
1887 * Write branch intruction to IRAM (0x71 trap) at location 0xFFFF0000
1888 * (Cortus map) or C0000 (AHB map).
1889 **/
1890 ret = g_wlan.hif_func.hif_write_reg(0xc0000, 0x71);
1891 if (!ret) {
1892 wilc_debug(N_ERR, "[wilc start]: fail write reg 0xc0000 ...\n");
1893 return ret;
1894 }
1895 }
1896
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001897 release_bus(RELEASE_ONLY);
1898
1899 return ret;
1900
1901}
1902
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001903u32 wilc_get_chipid(u8 update)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001904{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001905 static u32 chipid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001906 /* SDIO can't read into global variables */
1907 /* Use this variable as a temp, then copy to the global */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001908 u32 tempchipid = 0;
1909 u32 rfrevid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001910
1911 if (chipid == 0 || update != 0) {
1912 g_wlan.hif_func.hif_read_reg(0x1000, &tempchipid);
1913 g_wlan.hif_func.hif_read_reg(0x13f4, &rfrevid);
1914 if (!ISWILC1000(tempchipid)) {
1915 chipid = 0;
1916 goto _fail_;
1917 }
1918 if (tempchipid == 0x1002a0) {
1919 if (rfrevid == 0x1) { /* 1002A0 */
1920 } else { /* if (rfrevid == 0x2) */ /* 1002A1 */
1921 tempchipid = 0x1002a1;
1922 }
1923 } else if (tempchipid == 0x1002b0) {
1924 if (rfrevid == 3) { /* 1002B0 */
1925 } else if (rfrevid == 4) { /* 1002B1 */
1926 tempchipid = 0x1002b1;
1927 } else { /* if(rfrevid == 5) */ /* 1002B2 */
1928 tempchipid = 0x1002b2;
1929 }
1930 } else {
1931 }
1932
1933 chipid = tempchipid;
1934 }
1935_fail_:
1936 return chipid;
1937}
1938
1939#ifdef COMPLEMENT_BOOT
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001940u8 core_11b_ready(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001941{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001942 u32 reg_val;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001943
1944 acquire_bus(ACQUIRE_ONLY);
1945 g_wlan.hif_func.hif_write_reg(0x16082c, 1);
1946 g_wlan.hif_func.hif_write_reg(0x161600, 0x90);
1947 g_wlan.hif_func.hif_read_reg(0x161600, &reg_val);
1948 release_bus(RELEASE_ONLY);
1949
1950 if (reg_val == 0x90)
1951 return 0;
1952 else
1953 return 1;
1954}
1955#endif
1956
1957int wilc_wlan_init(wilc_wlan_inp_t *inp, wilc_wlan_oup_t *oup)
1958{
1959
1960 int ret = 0;
1961
1962 PRINT_D(INIT_DBG, "Initializing WILC_Wlan ...\n");
1963
1964 memset((void *)&g_wlan, 0, sizeof(wilc_wlan_dev_t));
1965
1966 /**
1967 * store the input
1968 **/
1969 memcpy((void *)&g_wlan.os_func, (void *)&inp->os_func, sizeof(wilc_wlan_os_func_t));
1970 memcpy((void *)&g_wlan.io_func, (void *)&inp->io_func, sizeof(wilc_wlan_io_func_t));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001971 g_wlan.hif_lock = inp->os_context.hif_critical_section;
1972 g_wlan.txq_lock = inp->os_context.txq_critical_section;
1973
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001974 g_wlan.txq_add_to_head_lock = inp->os_context.txq_add_to_head_critical_section;
1975
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001976 g_wlan.tx_buffer_size = inp->os_context.tx_buffer_size;
1977#if defined (MEMORY_STATIC)
1978 g_wlan.rx_buffer_size = inp->os_context.rx_buffer_size;
1979#endif
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001980 /***
1981 * host interface init
1982 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001983 if ((inp->io_func.io_type & 0x1) == HIF_SDIO) {
1984 if (!hif_sdio.hif_init(inp, wilc_debug)) {
1985 /* EIO 5 */
1986 ret = -5;
1987 goto _fail_;
1988 }
1989 memcpy((void *)&g_wlan.hif_func, &hif_sdio, sizeof(wilc_hif_func_t));
1990 } else {
1991 if ((inp->io_func.io_type & 0x1) == HIF_SPI) {
1992 /**
1993 * TODO:
1994 **/
1995 if (!hif_spi.hif_init(inp, wilc_debug)) {
1996 /* EIO 5 */
1997 ret = -5;
1998 goto _fail_;
1999 }
2000 memcpy((void *)&g_wlan.hif_func, &hif_spi, sizeof(wilc_hif_func_t));
2001 } else {
2002 /* EIO 5 */
2003 ret = -5;
2004 goto _fail_;
2005 }
2006 }
2007
2008 /***
2009 * mac interface init
2010 **/
2011 if (!mac_cfg.cfg_init(wilc_debug)) {
2012 /* ENOBUFS 105 */
2013 ret = -105;
2014 goto _fail_;
2015 }
2016 memcpy((void *)&g_wlan.cif_func, &mac_cfg, sizeof(wilc_cfg_func_t));
2017
2018
2019 /**
2020 * alloc tx, rx buffer
2021 **/
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002022 if (g_wlan.tx_buffer == NULL)
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07002023 g_wlan.tx_buffer = kmalloc(g_wlan.tx_buffer_size, GFP_KERNEL);
Arnd Bergmann7a8fd842015-06-01 21:06:45 +02002024 PRINT_D(TX_DBG, "g_wlan.tx_buffer = %p\n", g_wlan.tx_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002025
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002026 if (g_wlan.tx_buffer == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002027 /* ENOBUFS 105 */
2028 ret = -105;
2029 PRINT_ER("Can't allocate Tx Buffer");
2030 goto _fail_;
2031 }
2032
2033/* rx_buffer is not used unless we activate USE_MEM STATIC which is not applicable, allocating such memory is useless*/
2034#if defined (MEMORY_STATIC)
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002035 if (g_wlan.rx_buffer == NULL)
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07002036 g_wlan.rx_buffer = kmalloc(g_wlan.rx_buffer_size, GFP_KERNEL);
Arnd Bergmann7a8fd842015-06-01 21:06:45 +02002037 PRINT_D(TX_DBG, "g_wlan.rx_buffer =%p\n", g_wlan.rx_buffer);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002038 if (g_wlan.rx_buffer == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002039 /* ENOBUFS 105 */
2040 ret = -105;
2041 PRINT_ER("Can't allocate Rx Buffer");
2042 goto _fail_;
2043 }
2044#endif
2045
2046 /**
2047 * export functions
2048 **/
2049 oup->wlan_firmware_download = wilc_wlan_firmware_download;
2050 oup->wlan_start = wilc_wlan_start;
2051 oup->wlan_stop = wilc_wlan_stop;
2052 oup->wlan_add_to_tx_que = wilc_wlan_txq_add_net_pkt;
2053 oup->wlan_handle_tx_que = wilc_wlan_handle_txq;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002054 oup->wlan_handle_rx_isr = wilc_handle_isr;
2055 oup->wlan_cleanup = wilc_wlan_cleanup;
2056 oup->wlan_cfg_set = wilc_wlan_cfg_set;
2057 oup->wlan_cfg_get = wilc_wlan_cfg_get;
2058 oup->wlan_cfg_get_value = wilc_wlan_cfg_get_val;
2059
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002060 oup->wlan_add_mgmt_to_tx_que = wilc_wlan_txq_add_mgmt_pkt;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002061
2062 if (!init_chip()) {
2063 /* EIO 5 */
2064 ret = -5;
2065 goto _fail_;
2066 }
2067#ifdef TCP_ACK_FILTER
2068 Init_TCP_tracking();
2069#endif
2070
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002071 return 1;
2072
2073_fail_:
2074
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002075 #ifdef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07002076 kfree(g_wlan.rx_buffer);
2077 g_wlan.rx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002078 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07002079 kfree(g_wlan.tx_buffer);
2080 g_wlan.tx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002081
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002082 return ret;
2083
2084}
2085
Dean Lee72ed4dc2015-06-12 14:11:44 +09002086u16 Set_machw_change_vir_if(bool bValue)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002087{
Chaehyun Limd85f5322015-06-11 14:35:54 +09002088 u16 ret;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002089 u32 reg;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002090
2091 /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -07002092 mutex_lock((&g_wlan)->hif_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002093 ret = (&g_wlan)->hif_func.hif_read_reg(WILC_CHANGING_VIR_IF, &reg);
2094 if (!ret) {
2095 PRINT_ER("Error while Reading reg WILC_CHANGING_VIR_IF\n");
2096 }
2097
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05302098 if (bValue)
Chaehyun Lim50b51da2015-09-16 20:11:26 +09002099 reg |= BIT(31);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05302100 else
Chaehyun Lim50b51da2015-09-16 20:11:26 +09002101 reg &= ~BIT(31);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002102
2103 ret = (&g_wlan)->hif_func.hif_write_reg(WILC_CHANGING_VIR_IF, reg);
2104
2105 if (!ret) {
2106 PRINT_ER("Error while writing reg WILC_CHANGING_VIR_IF\n");
2107 }
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -07002108 mutex_unlock((&g_wlan)->hif_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002109
2110 return ret;
2111}