blob: d908fc8e05ce757ddf356660b322f10bfd019df5 [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;
50 void *cfg_wait;
51
52 /**
53 * RX buffer
54 **/
55 #ifdef MEMORY_STATIC
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090056 u32 rx_buffer_size;
Chaehyun Lim51e825f2015-09-15 14:06:14 +090057 u8 *rx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090058 u32 rx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090059 #endif
60 /**
61 * TX buffer
62 **/
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090063 u32 tx_buffer_size;
Chaehyun Lim51e825f2015-09-15 14:06:14 +090064 u8 *tx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090065 u32 tx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090066
67 /**
68 * TX queue
69 **/
70 void *txq_lock;
71
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -070072 struct semaphore *txq_add_to_head_lock;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090073 unsigned long txq_spinlock_flags;
74
75 struct txq_entry_t *txq_head;
76 struct txq_entry_t *txq_tail;
77 int txq_entries;
78 void *txq_wait;
79 int txq_exit;
80
81 /**
82 * RX queue
83 **/
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -070084 struct mutex *rxq_lock;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090085 struct rxq_entry_t *rxq_head;
86 struct rxq_entry_t *rxq_tail;
87 int rxq_entries;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090088 int rxq_exit;
89
90
91} wilc_wlan_dev_t;
92
93static wilc_wlan_dev_t g_wlan;
94
Chaehyun Lim9af382b2015-09-16 20:11:27 +090095static inline void chip_allow_sleep(void);
96static inline void chip_wakeup(void);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090097/********************************************
98 *
99 * Debug
100 *
101 ********************************************/
102
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900103static u32 dbgflag = N_INIT | N_ERR | N_INTR | N_TXQ | N_RXQ;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900104
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900105static void wilc_debug(u32 flag, char *fmt, ...)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900106{
107 char buf[256];
108 va_list args;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900109
110 if (flag & dbgflag) {
111 va_start(args, fmt);
Hari Prasath Gujulan Elango81053222015-06-22 13:13:58 +0000112 vsprintf(buf, fmt, args);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900113 va_end(args);
114
Glen Leeef2b7842015-09-24 18:14:55 +0900115 linux_wlan_dbg(buf);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900116 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900117}
118
119static CHIP_PS_STATE_T genuChipPSstate = CHIP_WAKEDUP;
120
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900121/*acquire_bus() and release_bus() are made static inline functions*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900122/*as a temporary workaround to fix a problem of receiving*/
123/*unknown interrupt from FW*/
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900124static inline void acquire_bus(BUS_ACQUIRE_T acquire)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900125{
126
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -0700127 mutex_lock(g_wlan.hif_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900128 #ifndef WILC_OPTIMIZE_SLEEP_INT
129 if (genuChipPSstate != CHIP_WAKEDUP)
130 #endif
131 {
132 if (acquire == ACQUIRE_AND_WAKEUP)
133 chip_wakeup();
134 }
135
136}
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900137static inline void release_bus(BUS_RELEASE_T release)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900138{
139 #ifdef WILC_OPTIMIZE_SLEEP_INT
140 if (release == RELEASE_ALLOW_SLEEP)
141 chip_allow_sleep();
142 #endif
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -0700143 mutex_unlock(g_wlan.hif_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900144}
145/********************************************
146 *
147 * Queue
148 *
149 ********************************************/
150
151static void wilc_wlan_txq_remove(struct txq_entry_t *tqe)
152{
153
154 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
155 /* unsigned long flags; */
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900156 if (tqe == p->txq_head) {
157
158 p->txq_head = tqe->next;
159 if (p->txq_head)
160 p->txq_head->prev = NULL;
161
162
163 } else if (tqe == p->txq_tail) {
164 p->txq_tail = (tqe->prev);
165 if (p->txq_tail)
166 p->txq_tail->next = NULL;
167 } else {
168 tqe->prev->next = tqe->next;
169 tqe->next->prev = tqe->prev;
170 }
171 p->txq_entries -= 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900172
173}
174
175static struct txq_entry_t *wilc_wlan_txq_remove_from_head(void)
176{
177 struct txq_entry_t *tqe;
178 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
179 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900180
Glen Lee85e57562015-09-24 18:14:56 +0900181 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900182 if (p->txq_head) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900183 tqe = p->txq_head;
184 p->txq_head = tqe->next;
185 if (p->txq_head) {
186 p->txq_head->prev = NULL;
187 }
188 p->txq_entries -= 1;
189
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900190
191
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900192
193 } else {
194 tqe = NULL;
195 }
Glen Lee85e57562015-09-24 18:14:56 +0900196 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900197 return tqe;
198}
199
200static void wilc_wlan_txq_add_to_tail(struct txq_entry_t *tqe)
201{
202 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
203 unsigned long flags;
Glen Lee85e57562015-09-24 18:14:56 +0900204 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900205
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900206 if (p->txq_head == NULL) {
207 tqe->next = NULL;
208 tqe->prev = NULL;
209 p->txq_head = tqe;
210 p->txq_tail = tqe;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900211 } else {
212 tqe->next = NULL;
213 tqe->prev = p->txq_tail;
214 p->txq_tail->next = tqe;
215 p->txq_tail = tqe;
216 }
217 p->txq_entries += 1;
218 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900219
Glen Lee85e57562015-09-24 18:14:56 +0900220 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900221
222 /**
223 * wake up TX queue
224 **/
225 PRINT_D(TX_DBG, "Wake the txq_handling\n");
226
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -0700227 up(p->txq_wait);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900228}
229
230static int wilc_wlan_txq_add_to_head(struct txq_entry_t *tqe)
231{
232 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
233 unsigned long flags;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900234 if (p->os_func.os_wait(p->txq_add_to_head_lock, CFG_PKTS_TIMEOUT))
235 return -1;
236
Glen Lee85e57562015-09-24 18:14:56 +0900237 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900238
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900239 if (p->txq_head == NULL) {
240 tqe->next = NULL;
241 tqe->prev = NULL;
242 p->txq_head = tqe;
243 p->txq_tail = tqe;
244 } else {
245 tqe->next = p->txq_head;
246 tqe->prev = NULL;
247 p->txq_head->prev = tqe;
248 p->txq_head = tqe;
249 }
250 p->txq_entries += 1;
251 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900252
Glen Lee85e57562015-09-24 18:14:56 +0900253 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -0700254 up(p->txq_add_to_head_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900255
256
257 /**
258 * wake up TX queue
259 **/
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -0700260 up(p->txq_wait);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900261 PRINT_D(TX_DBG, "Wake up the txq_handler\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900262
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900263 return 0;
264
265}
266
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900267u32 Statisitcs_totalAcks = 0, Statisitcs_DroppedAcks = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900268
269#ifdef TCP_ACK_FILTER
270struct Ack_session_info;
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530271struct Ack_session_info {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900272 u32 Ack_seq_num;
273 u32 Bigger_Ack_num;
Chaehyun Limec53adf2015-09-15 14:06:15 +0900274 u16 src_port;
275 u16 dst_port;
276 u16 status;
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530277};
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900278
279typedef struct {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900280 u32 ack_num;
281 u32 Session_index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900282 struct txq_entry_t *txqe;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900283} Pending_Acks_info_t /*Ack_info_t*/;
284
285
286
287
288struct Ack_session_info *Free_head;
289struct Ack_session_info *Alloc_head;
290
291#define TCP_FIN_MASK (1 << 0)
292#define TCP_SYN_MASK (1 << 1)
293#define TCP_Ack_MASK (1 << 4)
294#define NOT_TCP_ACK (-1)
295
296#define MAX_TCP_SESSION 25
297#define MAX_PENDING_ACKS 256
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530298struct Ack_session_info Acks_keep_track_info[2 * MAX_TCP_SESSION];
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900299Pending_Acks_info_t Pending_Acks_info[MAX_PENDING_ACKS];
300
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900301u32 PendingAcks_arrBase;
302u32 Opened_TCP_session;
303u32 Pending_Acks;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900304
305
306
Chaehyun Limfed16f22015-09-17 16:48:43 +0900307static inline int Init_TCP_tracking(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900308{
309
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900310 return 0;
311
312}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900313static inline int add_TCP_track_session(u32 src_prt, u32 dst_prt, u32 seq)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900314{
315 Acks_keep_track_info[Opened_TCP_session].Ack_seq_num = seq;
316 Acks_keep_track_info[Opened_TCP_session].Bigger_Ack_num = 0;
317 Acks_keep_track_info[Opened_TCP_session].src_port = src_prt;
318 Acks_keep_track_info[Opened_TCP_session].dst_port = dst_prt;
319 Opened_TCP_session++;
320
321 PRINT_D(TCP_ENH, "TCP Session %d to Ack %d\n", Opened_TCP_session, seq);
322 return 0;
323}
324
Chaehyun Limfed16f22015-09-17 16:48:43 +0900325static inline int Update_TCP_track_session(u32 index, u32 Ack)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900326{
327
328 if (Ack > Acks_keep_track_info[index].Bigger_Ack_num) {
329 Acks_keep_track_info[index].Bigger_Ack_num = Ack;
330 }
331 return 0;
332
333}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900334static inline int add_TCP_Pending_Ack(u32 Ack, u32 Session_index, struct txq_entry_t *txqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900335{
336 Statisitcs_totalAcks++;
337 if (Pending_Acks < MAX_PENDING_ACKS) {
338 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].ack_num = Ack;
339 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].txqe = txqe;
340 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].Session_index = Session_index;
341 txqe->tcp_PendingAck_index = PendingAcks_arrBase + Pending_Acks;
342 Pending_Acks++;
343
344 } else {
345
346 }
347 return 0;
348}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900349static inline int remove_TCP_related(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900350{
351 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
352 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900353
Glen Lee85e57562015-09-24 18:14:56 +0900354 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900355
Glen Lee85e57562015-09-24 18:14:56 +0900356 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900357 return 0;
358}
359
Chaehyun Limfed16f22015-09-17 16:48:43 +0900360static inline int tcp_process(struct txq_entry_t *tqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900361{
362 int ret;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900363 u8 *eth_hdr_ptr;
364 u8 *buffer = tqe->buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900365 unsigned short h_proto;
366 int i;
367 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
368 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900369
Glen Lee85e57562015-09-24 18:14:56 +0900370 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900371
372 eth_hdr_ptr = &buffer[0];
373 h_proto = ntohs(*((unsigned short *)&eth_hdr_ptr[12]));
374 if (h_proto == 0x0800) { /* IP */
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900375 u8 *ip_hdr_ptr;
376 u8 protocol;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900377
378 ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN];
379 protocol = ip_hdr_ptr[9];
380
381
382 if (protocol == 0x06) {
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900383 u8 *tcp_hdr_ptr;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900384 u32 IHL, Total_Length, Data_offset;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900385
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900386 tcp_hdr_ptr = &ip_hdr_ptr[IP_HDR_LEN];
387 IHL = (ip_hdr_ptr[0] & 0xf) << 2;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900388 Total_Length = (((u32)ip_hdr_ptr[2]) << 8) + ((u32)ip_hdr_ptr[3]);
389 Data_offset = (((u32)tcp_hdr_ptr[12] & 0xf0) >> 2);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900390 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 +0900391 u32 seq_no, Ack_no;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900392
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900393 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 +0900394
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900395 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 +0900396
397
398 for (i = 0; i < Opened_TCP_session; i++) {
399 if (Acks_keep_track_info[i].Ack_seq_num == seq_no) {
400 Update_TCP_track_session(i, Ack_no);
401 break;
402 }
403 }
404 if (i == Opened_TCP_session) {
405 add_TCP_track_session(0, 0, seq_no);
406 }
407 add_TCP_Pending_Ack(Ack_no, i, tqe);
408
409
410 }
411
412 } else {
413 ret = 0;
414 }
415 } else {
416 ret = 0;
417 }
Glen Lee85e57562015-09-24 18:14:56 +0900418 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900419 return ret;
420}
421
422
423static int wilc_wlan_txq_filter_dup_tcp_ack(void)
424{
425
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900426 u32 i = 0;
427 u32 Dropped = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900428 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
429
Glen Lee85e57562015-09-24 18:14:56 +0900430 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, p->txq_spinlock_flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900431 for (i = PendingAcks_arrBase; i < (PendingAcks_arrBase + Pending_Acks); i++) {
432 if (Pending_Acks_info[i].ack_num < Acks_keep_track_info[Pending_Acks_info[i].Session_index].Bigger_Ack_num) {
433 struct txq_entry_t *tqe;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900434
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530435 PRINT_D(TCP_ENH, "DROP ACK: %u\n", Pending_Acks_info[i].ack_num);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900436 tqe = Pending_Acks_info[i].txqe;
437 if (tqe) {
438 wilc_wlan_txq_remove(tqe);
439 Statisitcs_DroppedAcks++;
440 tqe->status = 1; /* mark the packet send */
441 if (tqe->tx_complete_func)
442 tqe->tx_complete_func(tqe->priv, tqe->status);
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -0700443 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900444 Dropped++;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900445 }
446 }
447 }
448 Pending_Acks = 0;
449 Opened_TCP_session = 0;
450
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530451 if (PendingAcks_arrBase == 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900452 PendingAcks_arrBase = MAX_TCP_SESSION;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530453 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900454 PendingAcks_arrBase = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900455
456
Glen Lee85e57562015-09-24 18:14:56 +0900457 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock,
458 p->txq_spinlock_flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900459
460 while (Dropped > 0) {
461 /*consume the semaphore count of the removed packet*/
462 p->os_func.os_wait(p->txq_wait, 1);
463 Dropped--;
464 }
465
466 return 1;
467}
468#endif
469
Dean Lee72ed4dc2015-06-12 14:11:44 +0900470bool EnableTCPAckFilter = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900471
Dean Lee72ed4dc2015-06-12 14:11:44 +0900472void Enable_TCP_ACK_Filter(bool value)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900473{
474 EnableTCPAckFilter = value;
475}
476
Dean Lee72ed4dc2015-06-12 14:11:44 +0900477bool is_TCP_ACK_Filter_Enabled(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900478{
479 return EnableTCPAckFilter;
480}
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900481
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900482static int wilc_wlan_txq_add_cfg_pkt(u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900483{
484 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
485 struct txq_entry_t *tqe;
486
487 PRINT_D(TX_DBG, "Adding config packet ...\n");
488 if (p->quit) {
489 PRINT_D(TX_DBG, "Return due to clear function\n");
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -0700490 up(p->cfg_wait);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900491 return 0;
492 }
493
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700494 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900495 if (tqe == NULL) {
496 PRINT_ER("Failed to allocate memory\n");
497 return 0;
498 }
499
500 tqe->type = WILC_CFG_PKT;
501 tqe->buffer = buffer;
502 tqe->buffer_size = buffer_size;
503 tqe->tx_complete_func = NULL;
504 tqe->priv = NULL;
505#ifdef TCP_ACK_FILTER
506 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
507#endif
508 /**
509 * Configuration packet always at the front
510 **/
511 PRINT_D(TX_DBG, "Adding the config packet at the Queue tail\n");
512
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900513 if (wilc_wlan_txq_add_to_head(tqe))
514 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900515 return 1;
516}
517
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900518static 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 +0900519{
520 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
521 struct txq_entry_t *tqe;
522
523 if (p->quit)
524 return 0;
525
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700526 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900527
528 if (tqe == NULL)
529 return 0;
530 tqe->type = WILC_NET_PKT;
531 tqe->buffer = buffer;
532 tqe->buffer_size = buffer_size;
533 tqe->tx_complete_func = func;
534 tqe->priv = priv;
535
536 PRINT_D(TX_DBG, "Adding mgmt packet at the Queue tail\n");
537#ifdef TCP_ACK_FILTER
538 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
Abdul Hussain5a66bf22015-06-16 09:44:06 +0000539 if (is_TCP_ACK_Filter_Enabled())
Glen Lee25a84832015-09-16 18:53:22 +0900540 tcp_process(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900541#endif
542 wilc_wlan_txq_add_to_tail(tqe);
543 /*return number of itemes in the queue*/
544 return p->txq_entries;
545}
Glen Leefcc6ef92015-09-16 18:53:21 +0900546
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900547int 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 +0900548{
549
550 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
551 struct txq_entry_t *tqe;
552
553 if (p->quit)
554 return 0;
555
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700556 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900557
558 if (tqe == NULL)
559 return 0;
560 tqe->type = WILC_MGMT_PKT;
561 tqe->buffer = buffer;
562 tqe->buffer_size = buffer_size;
563 tqe->tx_complete_func = func;
564 tqe->priv = priv;
565#ifdef TCP_ACK_FILTER
566 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
567#endif
568 PRINT_D(TX_DBG, "Adding Network packet at the Queue tail\n");
569 wilc_wlan_txq_add_to_tail(tqe);
570 return 1;
571}
Glen Leefcc6ef92015-09-16 18:53:21 +0900572
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900573static struct txq_entry_t *wilc_wlan_txq_get_first(void)
574{
575 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
576 struct txq_entry_t *tqe;
577 unsigned long flags;
578
Glen Lee85e57562015-09-24 18:14:56 +0900579 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900580
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900581 tqe = p->txq_head;
582
Glen Lee85e57562015-09-24 18:14:56 +0900583 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900584
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900585
586 return tqe;
587}
588
589static struct txq_entry_t *wilc_wlan_txq_get_next(struct txq_entry_t *tqe)
590{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900591 unsigned long flags;
Glen Lee85e57562015-09-24 18:14:56 +0900592 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900593
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900594 tqe = tqe->next;
Glen Lee85e57562015-09-24 18:14:56 +0900595 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900596
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900597
598 return tqe;
599}
600
601static int wilc_wlan_rxq_add(struct rxq_entry_t *rqe)
602{
603 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
604
605 if (p->quit)
606 return 0;
607
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -0700608 mutex_lock(p->rxq_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900609 if (p->rxq_head == NULL) {
610 PRINT_D(RX_DBG, "Add to Queue head\n");
611 rqe->next = NULL;
612 p->rxq_head = rqe;
613 p->rxq_tail = rqe;
614 } else {
615 PRINT_D(RX_DBG, "Add to Queue tail\n");
616 p->rxq_tail->next = rqe;
617 rqe->next = NULL;
618 p->rxq_tail = rqe;
619 }
620 p->rxq_entries += 1;
621 PRINT_D(RX_DBG, "Number of queue entries: %d\n", p->rxq_entries);
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -0700622 mutex_unlock(p->rxq_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900623 return p->rxq_entries;
624}
625
626static struct rxq_entry_t *wilc_wlan_rxq_remove(void)
627{
628 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
629
630 PRINT_D(RX_DBG, "Getting rxQ element\n");
631 if (p->rxq_head) {
632 struct rxq_entry_t *rqe;
633
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -0700634 mutex_lock(p->rxq_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900635 rqe = p->rxq_head;
636 p->rxq_head = p->rxq_head->next;
637 p->rxq_entries -= 1;
638 PRINT_D(RX_DBG, "RXQ entries decreased\n");
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -0700639 mutex_unlock(p->rxq_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900640 return rqe;
641 }
642 PRINT_D(RX_DBG, "Nothing to get from Q\n");
643 return NULL;
644}
645
646
647/********************************************
648 *
649 * Power Save handle functions
650 *
651 ********************************************/
652
653
654
655#ifdef WILC_OPTIMIZE_SLEEP_INT
656
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900657static inline void chip_allow_sleep(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900658{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900659 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900660
661 /* Clear bit 1 */
662 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
663
664 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0));
665}
666
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900667static inline void chip_wakeup(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900668{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900669 u32 reg, clk_status_reg, trials = 0;
670 u32 sleep_time;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900671
672 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
673 do {
674 g_wlan.hif_func.hif_read_reg(1, &reg);
675 /* Set bit 1 */
676 g_wlan.hif_func.hif_write_reg(1, reg | (1 << 1));
677
678 /* Clear bit 1*/
679 g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1));
680
681 do {
682 /* Wait for the chip to stabilize*/
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -0700683 usleep_range(2 * 1000, 2 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900684 /* Make sure chip is awake. This is an extra step that can be removed */
685 /* later to avoid the bus access overhead */
Dean Lee72ed4dc2015-06-12 14:11:44 +0900686 if ((wilc_get_chipid(true) == 0)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900687 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
688 }
Dean Lee72ed4dc2015-06-12 14:11:44 +0900689 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900690
Dean Lee72ed4dc2015-06-12 14:11:44 +0900691 } while (wilc_get_chipid(true) == 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900692 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
693 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
694 do {
695 /* Set bit 1 */
696 g_wlan.hif_func.hif_write_reg(0xf0, reg | (1 << 0));
697
698 /* Check the clock status */
699 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
700
701 /* in case of clocks off, wait 2ms, and check it again. */
702 /* if still off, wait for another 2ms, for a total wait of 6ms. */
703 /* If still off, redo the wake up sequence */
704 while (((clk_status_reg & 0x1) == 0) && (((++trials) % 3) == 0)) {
705 /* Wait for the chip to stabilize*/
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -0700706 usleep_range(2 * 1000, 2 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900707
708 /* Make sure chip is awake. This is an extra step that can be removed */
709 /* later to avoid the bus access overhead */
710 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
711
712 if ((clk_status_reg & 0x1) == 0) {
713 wilc_debug(N_ERR, "clocks still OFF. Wake up failed\n");
714 }
715 }
716 /* in case of failure, Reset the wakeup bit to introduce a new edge on the next loop */
717 if ((clk_status_reg & 0x1) == 0) {
718 /* Reset bit 0 */
719 g_wlan.hif_func.hif_write_reg(0xf0, reg & (~(1 << 0)));
720 }
721 } while ((clk_status_reg & 0x1) == 0);
722 }
723
724
725 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
726 g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
727 reg &= ~(1 << 0);
728 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
729
Dean Lee72ed4dc2015-06-12 14:11:44 +0900730 if (wilc_get_chipid(false) >= 0x1002b0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900731 /* Enable PALDO back right after wakeup */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900732 u32 val32;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900733
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900734 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
735 val32 |= (1 << 6);
736 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
737
738 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
739 val32 |= (1 << 6);
740 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
741 }
742 }
743 genuChipPSstate = CHIP_WAKEDUP;
744}
745#else
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900746static inline void chip_wakeup(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900747{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900748 u32 reg, trials = 0;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900749
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900750 do {
751 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
752 g_wlan.hif_func.hif_read_reg(1, &reg);
753 /* Make sure bit 1 is 0 before we start. */
754 g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1));
755 /* Set bit 1 */
756 g_wlan.hif_func.hif_write_reg(1, reg | (1 << 1));
757 /* Clear bit 1*/
758 g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1));
759 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
760 /* Make sure bit 0 is 0 before we start. */
761 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
762 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0));
763 /* Set bit 1 */
764 g_wlan.hif_func.hif_write_reg(0xf0, reg | (1 << 0));
765 /* Clear bit 1 */
766 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0));
767 }
768
769 do {
770 /* Wait for the chip to stabilize*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900771 mdelay(3);
772
773 /* Make sure chip is awake. This is an extra step that can be removed */
774 /* later to avoid the bus access overhead */
Dean Lee72ed4dc2015-06-12 14:11:44 +0900775 if ((wilc_get_chipid(true) == 0)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900776 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
777 }
Dean Lee72ed4dc2015-06-12 14:11:44 +0900778 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900779
Dean Lee72ed4dc2015-06-12 14:11:44 +0900780 } while (wilc_get_chipid(true) == 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900781
782 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
783 g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
784 reg &= ~(1 << 0);
785 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
786
Dean Lee72ed4dc2015-06-12 14:11:44 +0900787 if (wilc_get_chipid(false) >= 0x1002b0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900788 /* Enable PALDO back right after wakeup */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900789 u32 val32;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900790
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900791 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
792 val32 |= (1 << 6);
793 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
794
795 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
796 val32 |= (1 << 6);
797 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
798 }
799 }
800 genuChipPSstate = CHIP_WAKEDUP;
801}
802#endif
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900803void chip_sleep_manually(u32 u32SleepTime)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900804{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900805 if (genuChipPSstate != CHIP_WAKEDUP) {
806 /* chip is already sleeping. Do nothing */
807 return;
808 }
809 acquire_bus(ACQUIRE_ONLY);
810
811#ifdef WILC_OPTIMIZE_SLEEP_INT
812 chip_allow_sleep();
813#endif
814
815 /* Trigger the manual sleep interrupt */
816 g_wlan.hif_func.hif_write_reg(0x10a8, 1);
817
818 genuChipPSstate = CHIP_SLEEPING_MANUAL;
819 release_bus(RELEASE_ONLY);
820
821}
822
823
824/********************************************
825 *
826 * Tx, Rx queue handle functions
827 *
828 ********************************************/
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900829static int wilc_wlan_handle_txq(u32 *pu32TxqCount)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900830{
831 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
832 int i, entries = 0;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900833 u32 sum;
834 u32 reg;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900835 u8 *txb = p->tx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900836 u32 offset = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900837 int vmm_sz = 0;
838 struct txq_entry_t *tqe;
839 int ret = 0;
840 int counter;
841 int timeout;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900842 u32 vmm_table[WILC_VMM_TBL_SIZE];
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900843
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900844 p->txq_exit = 0;
845 do {
846 if (p->quit)
847 break;
848
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900849 p->os_func.os_wait(p->txq_add_to_head_lock, CFG_PKTS_TIMEOUT);
850#ifdef TCP_ACK_FILTER
851 wilc_wlan_txq_filter_dup_tcp_ack();
852#endif
853 /**
854 * build the vmm list
855 **/
856 PRINT_D(TX_DBG, "Getting the head of the TxQ\n");
857 tqe = wilc_wlan_txq_get_first();
858 i = 0;
859 sum = 0;
860 do {
861 /* if ((tqe != NULL) && (i < (8)) && */
862 /* if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE-1)) && */
863 if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE - 1)) /* reserve last entry to 0 */) {
864
865 if (tqe->type == WILC_CFG_PKT) {
866 vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET;
867 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900868 else if (tqe->type == WILC_NET_PKT) {
869 vmm_sz = ETH_ETHERNET_HDR_OFFSET;
870 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900871 else {
872 vmm_sz = HOST_HDR_OFFSET;
873 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900874 vmm_sz += tqe->buffer_size;
875 PRINT_D(TX_DBG, "VMM Size before alignment = %d\n", vmm_sz);
876 if (vmm_sz & 0x3) { /* has to be word aligned */
877 vmm_sz = (vmm_sz + 4) & ~0x3;
878 }
879 if ((sum + vmm_sz) > p->tx_buffer_size) {
880 break;
881 }
882 PRINT_D(TX_DBG, "VMM Size AFTER alignment = %d\n", vmm_sz);
883 vmm_table[i] = vmm_sz / 4; /* table take the word size */
884 PRINT_D(TX_DBG, "VMMTable entry size = %d\n", vmm_table[i]);
885
886 if (tqe->type == WILC_CFG_PKT) {
887 vmm_table[i] |= (1 << 10);
888 PRINT_D(TX_DBG, "VMMTable entry changed for CFG packet = %d\n", vmm_table[i]);
889 }
890#ifdef BIG_ENDIAN
891 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
892#endif
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900893
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900894 i++;
895 sum += vmm_sz;
896 PRINT_D(TX_DBG, "sum = %d\n", sum);
897 tqe = wilc_wlan_txq_get_next(tqe);
898 } else {
899 break;
900 }
901 } while (1);
902
903 if (i == 0) { /* nothing in the queue */
904 PRINT_D(TX_DBG, "Nothing in TX-Q\n");
905 break;
906 } else {
907 PRINT_D(TX_DBG, "Mark the last entry in VMM table - number of previous entries = %d\n", i);
908 vmm_table[i] = 0x0; /* mark the last element to 0 */
909 }
910 acquire_bus(ACQUIRE_AND_WAKEUP);
911 counter = 0;
912 do {
913
914 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg);
915 if (!ret) {
916 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg vmm_tbl_entry..\n");
917 break;
918 }
919
920 if ((reg & 0x1) == 0) {
921 /**
922 * write to vmm table
923 **/
924 PRINT_D(TX_DBG, "Writing VMM table ... with Size = %d\n", ((i + 1) * 4));
925 break;
926 } else {
927 counter++;
928 if (counter > 200) {
929 counter = 0;
930 PRINT_D(TX_DBG, "Looping in tx ctrl , forcce quit\n");
931 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, 0);
932 break;
933 }
934 /**
935 * wait for vmm table is ready
936 **/
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530937 PRINT_WRN(GENERIC_DBG, "[wilc txq]: warn, vmm table not clear yet, wait...\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900938 release_bus(RELEASE_ALLOW_SLEEP);
Greg Kroah-Hartman2b922cb2015-09-04 09:30:51 -0700939 usleep_range(3000, 3000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900940 acquire_bus(ACQUIRE_AND_WAKEUP);
941 }
942 } while (!p->quit);
943
944 if (!ret) {
945 goto _end_;
946 }
947
948 timeout = 200;
949 do {
950
951 /**
952 * write to vmm table
953 **/
Chaehyun Limc3ca6372015-09-20 15:51:19 +0900954 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 +0900955 if (!ret) {
956 wilc_debug(N_ERR, "ERR block TX of VMM table.\n");
957 break;
958 }
959
960
961 /**
962 * interrupt firmware
963 **/
964 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x2);
965 if (!ret) {
966 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg host_vmm_ctl..\n");
967 break;
968 }
969
970 /**
971 * wait for confirm...
972 **/
973
974 do {
975 ret = p->hif_func.hif_read_reg(WILC_HOST_VMM_CTL, &reg);
976 if (!ret) {
977 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg host_vmm_ctl..\n");
978 break;
979 }
980 if ((reg >> 2) & 0x1) {
981 /**
982 * Get the entries
983 **/
984 entries = ((reg >> 3) & 0x3f);
985 /* entries = ((reg>>3)&0x2f); */
986 break;
987 } else {
988 release_bus(RELEASE_ALLOW_SLEEP);
Greg Kroah-Hartman2b922cb2015-09-04 09:30:51 -0700989 usleep_range(3000, 3000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900990 acquire_bus(ACQUIRE_AND_WAKEUP);
991 PRINT_WRN(GENERIC_DBG, "Can't get VMM entery - reg = %2x\n", reg);
992 }
993 } while (--timeout);
994 if (timeout <= 0) {
995 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x0);
996 break;
997 }
998
999 if (!ret) {
1000 break;
1001 }
1002
1003 if (entries == 0) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301004 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 +09001005
1006 /* undo the transaction. */
1007 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg);
1008 if (!ret) {
1009 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg WILC_HOST_TX_CTRL..\n");
1010 break;
1011 }
1012 reg &= ~(1ul << 0);
1013 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, reg);
1014 if (!ret) {
1015 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg WILC_HOST_TX_CTRL..\n");
1016 break;
1017 }
1018 break;
1019 } else {
1020 break;
1021 }
1022 } while (1);
1023
1024 if (!ret) {
1025 goto _end_;
1026 }
1027 if (entries == 0) {
1028 ret = WILC_TX_ERR_NO_BUF;
1029 goto _end_;
1030 }
1031
1032 /* since copying data into txb takes some time, then
1033 * allow the bus lock to be released let the RX task go. */
1034 release_bus(RELEASE_ALLOW_SLEEP);
1035
1036 /**
1037 * Copy data to the TX buffer
1038 **/
1039 offset = 0;
1040 i = 0;
1041 do {
1042 tqe = wilc_wlan_txq_remove_from_head();
1043 if (tqe != NULL && (vmm_table[i] != 0)) {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001044 u32 header, buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001045
1046#ifdef BIG_ENDIAN
1047 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
1048#endif
1049 vmm_sz = (vmm_table[i] & 0x3ff); /* in word unit */
1050 vmm_sz *= 4;
1051 header = (tqe->type << 31) | (tqe->buffer_size << 15) | vmm_sz;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301052 if (tqe->type == WILC_MGMT_PKT)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001053 header |= (1 << 30);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301054 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001055 header &= ~(1 << 30);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001056
1057#ifdef BIG_ENDIAN
1058 header = BYTE_SWAP(header);
1059#endif
1060 memcpy(&txb[offset], &header, 4);
1061 if (tqe->type == WILC_CFG_PKT) {
1062 buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET;
1063 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001064 else if (tqe->type == WILC_NET_PKT) {
1065 char *pBSSID = ((struct tx_complete_data *)(tqe->priv))->pBssid;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001066
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001067 buffer_offset = ETH_ETHERNET_HDR_OFFSET;
1068 /* copy the bssid at the sart of the buffer */
1069 memcpy(&txb[offset + 4], pBSSID, 6);
1070 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001071 else {
1072 buffer_offset = HOST_HDR_OFFSET;
1073 }
1074
1075 memcpy(&txb[offset + buffer_offset], tqe->buffer, tqe->buffer_size);
1076 offset += vmm_sz;
1077 i++;
1078 tqe->status = 1; /* mark the packet send */
1079 if (tqe->tx_complete_func)
1080 tqe->tx_complete_func(tqe->priv, tqe->status);
1081 #ifdef TCP_ACK_FILTER
1082 if (tqe->tcp_PendingAck_index != NOT_TCP_ACK) {
1083 Pending_Acks_info[tqe->tcp_PendingAck_index].txqe = NULL;
1084 }
1085 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001086 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001087 } else {
1088 break;
1089 }
1090 } while (--entries);
1091
1092 /**
1093 * lock the bus
1094 **/
1095 acquire_bus(ACQUIRE_AND_WAKEUP);
1096
1097 ret = p->hif_func.hif_clear_int_ext(ENABLE_TX_VMM);
1098 if (!ret) {
1099 wilc_debug(N_ERR, "[wilc txq]: fail can't start tx VMM ...\n");
1100 goto _end_;
1101 }
1102
1103 /**
1104 * transfer
1105 **/
1106 ret = p->hif_func.hif_block_tx_ext(0, txb, offset);
1107 if (!ret) {
1108 wilc_debug(N_ERR, "[wilc txq]: fail can't block tx ext...\n");
1109 goto _end_;
1110 }
1111
1112_end_:
1113
1114 release_bus(RELEASE_ALLOW_SLEEP);
1115 if (ret != 1)
1116 break;
1117 } while (0);
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -07001118 up(p->txq_add_to_head_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001119
1120 p->txq_exit = 1;
1121 PRINT_D(TX_DBG, "THREAD: Exiting txq\n");
1122 /* return tx[]q count */
1123 *pu32TxqCount = p->txq_entries;
1124 return ret;
1125}
1126
1127static void wilc_wlan_handle_rxq(void)
1128{
1129 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1130 int offset = 0, size, has_packet = 0;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001131 u8 *buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001132 struct rxq_entry_t *rqe;
1133
1134 p->rxq_exit = 0;
1135
1136
1137
1138
1139 do {
1140 if (p->quit) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301141 PRINT_D(RX_DBG, "exit 1st do-while due to Clean_UP function\n");
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -07001142 up(p->cfg_wait);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001143 break;
1144 }
1145 rqe = wilc_wlan_rxq_remove();
1146 if (rqe == NULL) {
1147 PRINT_D(RX_DBG, "nothing in the queue - exit 1st do-while\n");
1148 break;
1149 }
1150 buffer = rqe->buffer;
1151 size = rqe->buffer_size;
1152 PRINT_D(RX_DBG, "rxQ entery Size = %d - Address = %p\n", size, buffer);
1153 offset = 0;
1154
1155
1156
1157 do {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001158 u32 header;
1159 u32 pkt_len, pkt_offset, tp_len;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001160 int is_cfg_packet;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001161
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001162 PRINT_D(RX_DBG, "In the 2nd do-while\n");
1163 memcpy(&header, &buffer[offset], 4);
1164#ifdef BIG_ENDIAN
1165 header = BYTE_SWAP(header);
1166#endif
1167 PRINT_D(RX_DBG, "Header = %04x - Offset = %d\n", header, offset);
1168
1169
1170
1171 is_cfg_packet = (header >> 31) & 0x1;
1172 pkt_offset = (header >> 22) & 0x1ff;
1173 tp_len = (header >> 11) & 0x7ff;
1174 pkt_len = header & 0x7ff;
1175
1176 if (pkt_len == 0 || tp_len == 0) {
1177 wilc_debug(N_RXQ, "[wilc rxq]: data corrupt, packet len or tp_len is 0 [%d][%d]\n", pkt_len, tp_len);
1178 break;
1179 }
1180
1181/*bug 3887: [AP] Allow Management frames to be passed to the host*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001182 #define IS_MANAGMEMENT 0x100
1183 #define IS_MANAGMEMENT_CALLBACK 0x080
1184 #define IS_MGMT_STATUS_SUCCES 0x040
1185
1186
1187 if (pkt_offset & IS_MANAGMEMENT) {
1188 /* reset mgmt indicator bit, to use pkt_offeset in furthur calculations */
1189 pkt_offset &= ~(IS_MANAGMEMENT | IS_MANAGMEMENT_CALLBACK | IS_MGMT_STATUS_SUCCES);
1190
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001191 WILC_WFI_mgmt_rx(&buffer[offset + HOST_HDR_OFFSET], pkt_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001192 }
1193 /* BUG4530 fix */
1194 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001195 {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001196
1197 if (!is_cfg_packet) {
Glen Lee63611672015-09-24 18:14:52 +09001198 if (pkt_len > 0) {
1199 frmw_to_linux(&buffer[offset],
1200 pkt_len,
1201 pkt_offset);
1202 has_packet = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001203 }
1204 } else {
1205 wilc_cfg_rsp_t rsp;
1206
1207
1208
1209 p->cif_func.rx_indicate(&buffer[pkt_offset + offset], pkt_len, &rsp);
1210 if (rsp.type == WILC_CFG_RSP) {
1211 /**
1212 * wake up the waiting task...
1213 **/
1214 PRINT_D(RX_DBG, "p->cfg_seq_no = %d - rsp.seq_no = %d\n", p->cfg_seq_no, rsp.seq_no);
1215 if (p->cfg_seq_no == rsp.seq_no) {
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -07001216 up(p->cfg_wait);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001217 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001218 } else if (rsp.type == WILC_CFG_RSP_STATUS) {
1219 /**
1220 * Call back to indicate status...
1221 **/
Glen Lee4417d3d2015-09-24 18:14:53 +09001222 linux_wlan_mac_indicate(WILC_MAC_INDICATE_STATUS);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001223
1224 } else if (rsp.type == WILC_CFG_RSP_SCAN) {
Glen Lee4417d3d2015-09-24 18:14:53 +09001225 linux_wlan_mac_indicate(WILC_MAC_INDICATE_SCAN);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001226 }
1227 }
1228 }
1229 offset += tp_len;
1230 if (offset >= size)
1231 break;
1232 } while (1);
1233
1234
1235#ifndef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001236 kfree(buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001237#endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001238 kfree(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001239
1240 if (has_packet) {
Glen Leec0cadaa2015-09-24 18:14:54 +09001241 linux_wlan_rx_complete();
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001242 }
1243 } while (1);
1244
1245 p->rxq_exit = 1;
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301246 PRINT_D(RX_DBG, "THREAD: Exiting RX thread\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001247}
1248
1249/********************************************
1250 *
1251 * Fast DMA Isr
1252 *
1253 ********************************************/
1254static void wilc_unknown_isr_ext(void)
1255{
1256 g_wlan.hif_func.hif_clear_int_ext(0);
1257}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001258static void wilc_pllupdate_isr_ext(u32 int_stats)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001259{
1260
1261 int trials = 10;
1262
1263 g_wlan.hif_func.hif_clear_int_ext(PLL_INT_CLR);
1264
1265 /* Waiting for PLL */
Greg Kroah-Hartmanc2e4c0f2015-09-03 19:09:50 -07001266 mdelay(WILC_PLL_TO);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001267
1268 /* poll till read a valid data */
Dean Lee72ed4dc2015-06-12 14:11:44 +09001269 while (!(ISWILC1000(wilc_get_chipid(true)) && --trials)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001270 PRINT_D(TX_DBG, "PLL update retrying\n");
Greg Kroah-Hartmanc2e4c0f2015-09-03 19:09:50 -07001271 mdelay(1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001272 }
1273}
1274
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001275static void wilc_sleeptimer_isr_ext(u32 int_stats1)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001276{
1277 g_wlan.hif_func.hif_clear_int_ext(SLEEP_INT_CLR);
1278#ifndef WILC_OPTIMIZE_SLEEP_INT
1279 genuChipPSstate = CHIP_SLEEPING_AUTO;
1280#endif
1281}
1282
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001283static void wilc_wlan_handle_isr_ext(u32 int_status)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001284{
1285 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1286#ifdef MEMORY_STATIC
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001287 u32 offset = p->rx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001288#endif
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001289 u8 *buffer = NULL;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001290 u32 size;
1291 u32 retries = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001292 int ret = 0;
1293 struct rxq_entry_t *rqe;
1294
1295
1296 /**
1297 * Get the rx size
1298 **/
1299
1300 size = ((int_status & 0x7fff) << 2);
1301
1302 while (!size && retries < 10) {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001303 u32 time = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001304 /*looping more secure*/
1305 /*zero size make a crashe because the dma will not happen and that will block the firmware*/
1306 wilc_debug(N_ERR, "RX Size equal zero ... Trying to read it again for %d time\n", time++);
1307 p->hif_func.hif_read_size(&size);
1308 size = ((size & 0x7fff) << 2);
1309 retries++;
1310
1311 }
1312
1313 if (size > 0) {
1314#ifdef MEMORY_STATIC
1315 if (p->rx_buffer_size - offset < size)
1316 offset = 0;
1317
1318 if (p->rx_buffer)
1319 buffer = &p->rx_buffer[offset];
1320 else {
1321 wilc_debug(N_ERR, "[wilc isr]: fail Rx Buffer is NULL...drop the packets (%d)\n", size);
1322 goto _end_;
1323 }
1324
1325#else
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001326 buffer = kmalloc(size, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001327 if (buffer == NULL) {
1328 wilc_debug(N_ERR, "[wilc isr]: fail alloc host memory...drop the packets (%d)\n", size);
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -07001329 usleep_range(100 * 1000, 100 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001330 goto _end_;
1331 }
1332#endif
1333
1334 /**
1335 * clear the chip's interrupt after getting size some register getting corrupted after clear the interrupt
1336 **/
1337 p->hif_func.hif_clear_int_ext(DATA_INT_CLR | ENABLE_RX_VMM);
1338
1339
1340 /**
1341 * start transfer
1342 **/
1343 ret = p->hif_func.hif_block_rx_ext(0, buffer, size);
1344
1345 if (!ret) {
1346 wilc_debug(N_ERR, "[wilc isr]: fail block rx...\n");
1347 goto _end_;
1348 }
1349_end_:
1350
1351
1352 if (ret) {
1353#ifdef MEMORY_STATIC
1354 offset += size;
1355 p->rx_buffer_offset = offset;
1356#endif
1357 /**
1358 * add to rx queue
1359 **/
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001360 rqe = kmalloc(sizeof(struct rxq_entry_t), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001361 if (rqe != NULL) {
1362 rqe->buffer = buffer;
1363 rqe->buffer_size = size;
1364 PRINT_D(RX_DBG, "rxq entery Size= %d - Address = %p\n", rqe->buffer_size, rqe->buffer);
1365 wilc_wlan_rxq_add(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001366 }
1367 } else {
1368#ifndef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001369 kfree(buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001370#endif
1371 }
1372 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001373 wilc_wlan_handle_rxq();
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001374}
1375
1376void wilc_handle_isr(void)
1377{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001378 u32 int_status;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001379
1380 acquire_bus(ACQUIRE_AND_WAKEUP);
1381 g_wlan.hif_func.hif_read_int(&int_status);
1382
1383 if (int_status & PLL_INT_EXT) {
1384 wilc_pllupdate_isr_ext(int_status);
1385 }
1386 if (int_status & DATA_INT_EXT) {
1387 wilc_wlan_handle_isr_ext(int_status);
1388 #ifndef WILC_OPTIMIZE_SLEEP_INT
1389 /* Chip is up and talking*/
1390 genuChipPSstate = CHIP_WAKEDUP;
1391 #endif
1392 }
1393 if (int_status & SLEEP_INT_EXT) {
1394 wilc_sleeptimer_isr_ext(int_status);
1395 }
1396
1397 if (!(int_status & (ALL_INT_EXT))) {
1398#ifdef WILC_SDIO
1399 PRINT_D(TX_DBG, ">> UNKNOWN_INTERRUPT - 0x%08x\n", int_status);
1400#endif
1401 wilc_unknown_isr_ext();
1402 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001403 release_bus(RELEASE_ALLOW_SLEEP);
1404}
1405
1406/********************************************
1407 *
1408 * Firmware download
1409 *
1410 ********************************************/
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001411static int wilc_wlan_firmware_download(const u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001412{
1413 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001414 u32 offset;
1415 u32 addr, size, size2, blksz;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001416 u8 *dma_buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001417 int ret = 0;
1418
Chaehyun Limc3ca6372015-09-20 15:51:19 +09001419 blksz = (1ul << 12);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001420 /* Allocate a DMA coherent buffer. */
1421
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001422 dma_buffer = kmalloc(blksz, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001423 if (dma_buffer == NULL) {
1424 /*EIO 5*/
1425 ret = -5;
1426 PRINT_ER("Can't allocate buffer for firmware download IO error\n ");
1427 goto _fail_1;
1428 }
1429
1430 PRINT_D(INIT_DBG, "Downloading firmware size = %d ...\n", buffer_size);
1431 /**
1432 * load the firmware
1433 **/
1434 offset = 0;
1435 do {
1436 memcpy(&addr, &buffer[offset], 4);
1437 memcpy(&size, &buffer[offset + 4], 4);
1438#ifdef BIG_ENDIAN
1439 addr = BYTE_SWAP(addr);
1440 size = BYTE_SWAP(size);
1441#endif
1442 acquire_bus(ACQUIRE_ONLY);
1443 offset += 8;
1444 while (((int)size) && (offset < buffer_size)) {
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301445 if (size <= blksz)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001446 size2 = size;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301447 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001448 size2 = blksz;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001449 /* Copy firmware into a DMA coherent buffer */
1450 memcpy(dma_buffer, &buffer[offset], size2);
1451 ret = p->hif_func.hif_block_tx(addr, dma_buffer, size2);
1452 if (!ret)
1453 break;
1454
1455 addr += size2;
1456 offset += size2;
1457 size -= size2;
1458 }
1459 release_bus(RELEASE_ONLY);
1460
1461 if (!ret) {
1462 /*EIO 5*/
1463 ret = -5;
1464 PRINT_ER("Can't download firmware IO error\n ");
1465 goto _fail_;
1466 }
1467 PRINT_D(INIT_DBG, "Offset = %d\n", offset);
1468 } while (offset < buffer_size);
1469
1470_fail_:
1471
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001472 kfree(dma_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001473
1474_fail_1:
1475
1476 return (ret < 0) ? ret : 0;
1477}
1478
1479/********************************************
1480 *
1481 * Common
1482 *
1483 ********************************************/
1484static int wilc_wlan_start(void)
1485{
1486 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001487 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001488 int ret;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001489 u32 chipid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001490
1491 /**
1492 * Set the host interface
1493 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001494 if (p->io_func.io_type == HIF_SDIO) {
1495 reg = 0;
1496 reg |= (1 << 3); /* bug 4456 and 4557 */
1497 } else if (p->io_func.io_type == HIF_SPI) {
1498 reg = 1;
1499 }
1500 acquire_bus(ACQUIRE_ONLY);
1501 ret = p->hif_func.hif_write_reg(WILC_VMM_CORE_CFG, reg);
1502 if (!ret) {
1503 wilc_debug(N_ERR, "[wilc start]: fail write reg vmm_core_cfg...\n");
1504 release_bus(RELEASE_ONLY);
1505 /* EIO 5*/
1506 ret = -5;
1507 return ret;
1508 }
1509 reg = 0;
1510#ifdef WILC_SDIO_IRQ_GPIO
1511 reg |= WILC_HAVE_SDIO_IRQ_GPIO;
1512#endif
1513
1514#ifdef WILC_DISABLE_PMU
1515#else
1516 reg |= WILC_HAVE_USE_PMU;
1517#endif
1518
1519#ifdef WILC_SLEEP_CLK_SRC_XO
1520 reg |= WILC_HAVE_SLEEP_CLK_SRC_XO;
1521#elif defined WILC_SLEEP_CLK_SRC_RTC
1522 reg |= WILC_HAVE_SLEEP_CLK_SRC_RTC;
1523#endif
1524
1525#ifdef WILC_EXT_PA_INV_TX_RX
1526 reg |= WILC_HAVE_EXT_PA_INV_TX_RX;
1527#endif
1528
1529 reg |= WILC_HAVE_LEGACY_RF_SETTINGS;
1530
1531
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001532/*Set oscillator frequency*/
1533#ifdef XTAL_24
1534 reg |= WILC_HAVE_XTAL_24;
1535#endif
1536
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001537/*Enable/Disable GPIO configuration for FW logs*/
1538#ifdef DISABLE_WILC_UART
1539 reg |= WILC_HAVE_DISABLE_WILC_UART;
1540#endif
1541
1542 ret = p->hif_func.hif_write_reg(WILC_GP_REG_1, reg);
1543 if (!ret) {
1544 wilc_debug(N_ERR, "[wilc start]: fail write WILC_GP_REG_1 ...\n");
1545 release_bus(RELEASE_ONLY);
1546 /* EIO 5*/
1547 ret = -5;
1548 return ret;
1549 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001550
1551 /**
1552 * Bus related
1553 **/
1554 p->hif_func.hif_sync_ext(NUM_INT_EXT);
1555
1556 ret = p->hif_func.hif_read_reg(0x1000, &chipid);
1557 if (!ret) {
1558 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1000 ...\n");
1559 release_bus(RELEASE_ONLY);
1560 /* EIO 5*/
1561 ret = -5;
1562 return ret;
1563 }
1564
1565 /**
1566 * Go...
1567 **/
1568
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001569
1570 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1571 if ((reg & (1ul << 10)) == (1ul << 10)) {
1572 reg &= ~(1ul << 10);
1573 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1574 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1575 }
1576
1577 reg |= (1ul << 10);
1578 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1579 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1580 release_bus(RELEASE_ONLY);
1581
1582 return (ret < 0) ? ret : 0;
1583}
1584
1585void wilc_wlan_global_reset(void)
1586{
1587
1588 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001589
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001590 acquire_bus(ACQUIRE_AND_WAKEUP);
1591 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, 0x0);
1592 release_bus(RELEASE_ONLY);
1593}
1594static int wilc_wlan_stop(void)
1595{
1596 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001597 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001598 int ret;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001599 u8 timeout = 10;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001600 /**
1601 * TODO: stop the firmware, need a re-download
1602 **/
1603 acquire_bus(ACQUIRE_AND_WAKEUP);
1604
1605 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1606 if (!ret) {
1607 PRINT_ER("Error while reading reg\n");
1608 release_bus(RELEASE_ALLOW_SLEEP);
1609 return ret;
1610 }
1611
1612 reg &= ~(1 << 10);
1613
1614
1615 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1616 if (!ret) {
1617 PRINT_ER("Error while writing reg\n");
1618 release_bus(RELEASE_ALLOW_SLEEP);
1619 return ret;
1620 }
1621
1622
1623
1624 do {
1625 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1626 if (!ret) {
1627 PRINT_ER("Error while reading reg\n");
1628 release_bus(RELEASE_ALLOW_SLEEP);
1629 return ret;
1630 }
1631 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1632 /*Workaround to ensure that the chip is actually reset*/
1633 if ((reg & (1 << 10))) {
1634 PRINT_D(GENERIC_DBG, "Bit 10 not reset : Retry %d\n", timeout);
1635 reg &= ~(1 << 10);
1636 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1637 timeout--;
1638 } else {
1639 PRINT_D(GENERIC_DBG, "Bit 10 reset after : Retry %d\n", timeout);
1640 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1641 if (!ret) {
1642 PRINT_ER("Error while reading reg\n");
1643 release_bus(RELEASE_ALLOW_SLEEP);
1644 return ret;
1645 }
1646 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1647 break;
1648 }
1649
1650 } while (timeout);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001651 reg = ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 8) | (1 << 9) | (1 << 26) | (1 << 29) | (1 << 30) | (1 << 31)); /**/
1652 /**/
Hari Prasath Gujulan Elango369f1902015-06-22 07:04:39 +00001653 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); /**/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001654 reg = ~(1 << 10); /**/
1655 /**/
1656 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); /**/
1657/******************************************************************************/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001658
1659 release_bus(RELEASE_ALLOW_SLEEP);
1660
1661 return ret;
1662}
1663
1664static void wilc_wlan_cleanup(void)
1665{
1666 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1667 struct txq_entry_t *tqe;
1668 struct rxq_entry_t *rqe;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001669 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001670 int ret;
1671
1672 p->quit = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001673 do {
1674 tqe = wilc_wlan_txq_remove_from_head();
1675 if (tqe == NULL)
1676 break;
1677 if (tqe->tx_complete_func)
1678 tqe->tx_complete_func(tqe->priv, 0);
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001679 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001680 } while (1);
1681
1682 do {
1683 rqe = wilc_wlan_rxq_remove();
1684 if (rqe == NULL)
1685 break;
Javier Martinez Canillas6a272242015-09-22 15:24:50 +02001686#ifndef MEMORY_STATIC
1687 kfree(rqe->buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001688#endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001689 kfree(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001690 } while (1);
1691
1692 /**
1693 * clean up buffer
1694 **/
1695
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001696 #ifdef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001697 kfree(p->rx_buffer);
1698 p->rx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001699 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001700 kfree(p->tx_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001701
1702 acquire_bus(ACQUIRE_AND_WAKEUP);
1703
1704
1705 ret = p->hif_func.hif_read_reg(WILC_GP_REG_0, &reg);
1706 if (!ret) {
1707 PRINT_ER("Error while reading reg\n");
1708 release_bus(RELEASE_ALLOW_SLEEP);
1709 }
1710 PRINT_ER("Writing ABORT reg\n");
1711 ret = p->hif_func.hif_write_reg(WILC_GP_REG_0, (reg | ABORT_INT));
1712 if (!ret) {
1713 PRINT_ER("Error while writing reg\n");
1714 release_bus(RELEASE_ALLOW_SLEEP);
1715 }
1716 release_bus(RELEASE_ALLOW_SLEEP);
1717 /**
1718 * io clean up
1719 **/
1720 p->hif_func.hif_deinit(NULL);
1721
1722}
1723
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001724static int wilc_wlan_cfg_commit(int type, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001725{
1726 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1727 wilc_cfg_frame_t *cfg = &p->cfg_frame;
1728 int total_len = p->cfg_frame_offset + 4 + DRIVER_HANDLER_SIZE;
1729 int seq_no = p->cfg_seq_no % 256;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001730 int driver_handler = (u32)drvHandler;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001731
1732
1733 /**
1734 * Set up header
1735 **/
1736 if (type == WILC_CFG_SET) { /* Set */
1737 cfg->wid_header[0] = 'W';
1738 } else { /* Query */
1739 cfg->wid_header[0] = 'Q';
1740 }
1741 cfg->wid_header[1] = seq_no; /* sequence number */
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001742 cfg->wid_header[2] = (u8)total_len;
1743 cfg->wid_header[3] = (u8)(total_len >> 8);
1744 cfg->wid_header[4] = (u8)driver_handler;
1745 cfg->wid_header[5] = (u8)(driver_handler >> 8);
1746 cfg->wid_header[6] = (u8)(driver_handler >> 16);
1747 cfg->wid_header[7] = (u8)(driver_handler >> 24);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001748 p->cfg_seq_no = seq_no;
1749
1750 /**
1751 * Add to TX queue
1752 **/
1753
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001754 if (!wilc_wlan_txq_add_cfg_pkt(&cfg->wid_header[0], total_len))
1755 return -1;
1756
1757 return 0;
1758}
1759
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001760static 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 +09001761{
1762 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001763 u32 offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001764 int ret_size;
1765
1766
1767 if (p->cfg_frame_in_use)
1768 return 0;
1769
1770 if (start)
1771 p->cfg_frame_offset = 0;
1772
1773 offset = p->cfg_frame_offset;
Chaehyun Limec53adf2015-09-15 14:06:15 +09001774 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 +09001775 offset += ret_size;
1776 p->cfg_frame_offset = offset;
1777
1778 if (commit) {
1779 PRINT_D(TX_DBG, "[WILC]PACKET Commit with sequence number %d\n", p->cfg_seq_no);
1780 PRINT_D(RX_DBG, "Processing cfg_set()\n");
1781 p->cfg_frame_in_use = 1;
1782
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001783 if (wilc_wlan_cfg_commit(WILC_CFG_SET, drvHandler))
Chaehyun Lim5af6b852015-09-17 16:48:48 +09001784 ret_size = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001785
1786 if (p->os_func.os_wait(p->cfg_wait, CFG_PKTS_TIMEOUT)) {
1787 PRINT_D(TX_DBG, "Set Timed Out\n");
1788 ret_size = 0;
1789 }
1790 p->cfg_frame_in_use = 0;
1791 p->cfg_frame_offset = 0;
1792 p->cfg_seq_no += 1;
1793
1794 }
1795
1796 return ret_size;
1797}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001798static int wilc_wlan_cfg_get(int start, u32 wid, int commit, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001799{
1800 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001801 u32 offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001802 int ret_size;
1803
1804
1805 if (p->cfg_frame_in_use)
1806 return 0;
1807
1808 if (start)
1809 p->cfg_frame_offset = 0;
1810
1811 offset = p->cfg_frame_offset;
Chaehyun Limec53adf2015-09-15 14:06:15 +09001812 ret_size = p->cif_func.cfg_wid_get(p->cfg_frame.frame, offset, (u16)wid);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001813 offset += ret_size;
1814 p->cfg_frame_offset = offset;
1815
1816 if (commit) {
1817 p->cfg_frame_in_use = 1;
1818
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001819 if (wilc_wlan_cfg_commit(WILC_CFG_QUERY, drvHandler))
Chaehyun Lim5af6b852015-09-17 16:48:48 +09001820 ret_size = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001821
1822
1823 if (p->os_func.os_wait(p->cfg_wait, CFG_PKTS_TIMEOUT)) {
1824 PRINT_D(TX_DBG, "Get Timed Out\n");
1825 ret_size = 0;
1826 }
1827 PRINT_D(GENERIC_DBG, "[WILC]Get Response received\n");
1828 p->cfg_frame_in_use = 0;
1829 p->cfg_frame_offset = 0;
1830 p->cfg_seq_no += 1;
1831 }
1832
1833 return ret_size;
1834}
1835
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001836static int wilc_wlan_cfg_get_val(u32 wid, u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001837{
1838 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1839 int ret;
1840
Chaehyun Limec53adf2015-09-15 14:06:15 +09001841 ret = p->cif_func.cfg_wid_get_val((u16)wid, buffer, buffer_size);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001842
1843 return ret;
1844}
1845
1846void wilc_bus_set_max_speed(void)
1847{
1848
1849 /* Increase bus speed to max possible. */
1850 g_wlan.hif_func.hif_set_max_bus_speed();
1851}
1852
1853void wilc_bus_set_default_speed(void)
1854{
1855
1856 /* Restore bus speed to default. */
1857 g_wlan.hif_func.hif_set_default_bus_speed();
1858}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001859u32 init_chip(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001860{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001861 u32 chipid;
1862 u32 reg, ret = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001863
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001864 acquire_bus(ACQUIRE_ONLY);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001865
Dean Lee72ed4dc2015-06-12 14:11:44 +09001866 chipid = wilc_get_chipid(true);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001867
1868
1869
1870 if ((chipid & 0xfff) != 0xa0) {
1871 /**
1872 * Avoid booting from boot ROM. Make sure that Drive IRQN [SDIO platform]
1873 * or SD_DAT3 [SPI platform] to ?1?
1874 **/
1875 /* Set cortus reset register to register control. */
1876 ret = g_wlan.hif_func.hif_read_reg(0x1118, &reg);
1877 if (!ret) {
1878 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1118 ...\n");
1879 return ret;
1880 }
1881 reg |= (1 << 0);
1882 ret = g_wlan.hif_func.hif_write_reg(0x1118, reg);
1883 if (!ret) {
1884 wilc_debug(N_ERR, "[wilc start]: fail write reg 0x1118 ...\n");
1885 return ret;
1886 }
1887 /**
1888 * Write branch intruction to IRAM (0x71 trap) at location 0xFFFF0000
1889 * (Cortus map) or C0000 (AHB map).
1890 **/
1891 ret = g_wlan.hif_func.hif_write_reg(0xc0000, 0x71);
1892 if (!ret) {
1893 wilc_debug(N_ERR, "[wilc start]: fail write reg 0xc0000 ...\n");
1894 return ret;
1895 }
1896 }
1897
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001898 release_bus(RELEASE_ONLY);
1899
1900 return ret;
1901
1902}
1903
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001904u32 wilc_get_chipid(u8 update)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001905{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001906 static u32 chipid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001907 /* SDIO can't read into global variables */
1908 /* Use this variable as a temp, then copy to the global */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001909 u32 tempchipid = 0;
1910 u32 rfrevid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001911
1912 if (chipid == 0 || update != 0) {
1913 g_wlan.hif_func.hif_read_reg(0x1000, &tempchipid);
1914 g_wlan.hif_func.hif_read_reg(0x13f4, &rfrevid);
1915 if (!ISWILC1000(tempchipid)) {
1916 chipid = 0;
1917 goto _fail_;
1918 }
1919 if (tempchipid == 0x1002a0) {
1920 if (rfrevid == 0x1) { /* 1002A0 */
1921 } else { /* if (rfrevid == 0x2) */ /* 1002A1 */
1922 tempchipid = 0x1002a1;
1923 }
1924 } else if (tempchipid == 0x1002b0) {
1925 if (rfrevid == 3) { /* 1002B0 */
1926 } else if (rfrevid == 4) { /* 1002B1 */
1927 tempchipid = 0x1002b1;
1928 } else { /* if(rfrevid == 5) */ /* 1002B2 */
1929 tempchipid = 0x1002b2;
1930 }
1931 } else {
1932 }
1933
1934 chipid = tempchipid;
1935 }
1936_fail_:
1937 return chipid;
1938}
1939
1940#ifdef COMPLEMENT_BOOT
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001941u8 core_11b_ready(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001942{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001943 u32 reg_val;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001944
1945 acquire_bus(ACQUIRE_ONLY);
1946 g_wlan.hif_func.hif_write_reg(0x16082c, 1);
1947 g_wlan.hif_func.hif_write_reg(0x161600, 0x90);
1948 g_wlan.hif_func.hif_read_reg(0x161600, &reg_val);
1949 release_bus(RELEASE_ONLY);
1950
1951 if (reg_val == 0x90)
1952 return 0;
1953 else
1954 return 1;
1955}
1956#endif
1957
1958int wilc_wlan_init(wilc_wlan_inp_t *inp, wilc_wlan_oup_t *oup)
1959{
1960
1961 int ret = 0;
1962
1963 PRINT_D(INIT_DBG, "Initializing WILC_Wlan ...\n");
1964
1965 memset((void *)&g_wlan, 0, sizeof(wilc_wlan_dev_t));
1966
1967 /**
1968 * store the input
1969 **/
1970 memcpy((void *)&g_wlan.os_func, (void *)&inp->os_func, sizeof(wilc_wlan_os_func_t));
1971 memcpy((void *)&g_wlan.io_func, (void *)&inp->io_func, sizeof(wilc_wlan_io_func_t));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001972 g_wlan.hif_lock = inp->os_context.hif_critical_section;
1973 g_wlan.txq_lock = inp->os_context.txq_critical_section;
1974
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001975 g_wlan.txq_add_to_head_lock = inp->os_context.txq_add_to_head_critical_section;
1976
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001977 g_wlan.rxq_lock = inp->os_context.rxq_critical_section;
1978 g_wlan.txq_wait = inp->os_context.txq_wait_event;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001979 g_wlan.cfg_wait = inp->os_context.cfg_wait_event;
1980 g_wlan.tx_buffer_size = inp->os_context.tx_buffer_size;
1981#if defined (MEMORY_STATIC)
1982 g_wlan.rx_buffer_size = inp->os_context.rx_buffer_size;
1983#endif
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001984 /***
1985 * host interface init
1986 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001987 if ((inp->io_func.io_type & 0x1) == HIF_SDIO) {
1988 if (!hif_sdio.hif_init(inp, wilc_debug)) {
1989 /* EIO 5 */
1990 ret = -5;
1991 goto _fail_;
1992 }
1993 memcpy((void *)&g_wlan.hif_func, &hif_sdio, sizeof(wilc_hif_func_t));
1994 } else {
1995 if ((inp->io_func.io_type & 0x1) == HIF_SPI) {
1996 /**
1997 * TODO:
1998 **/
1999 if (!hif_spi.hif_init(inp, wilc_debug)) {
2000 /* EIO 5 */
2001 ret = -5;
2002 goto _fail_;
2003 }
2004 memcpy((void *)&g_wlan.hif_func, &hif_spi, sizeof(wilc_hif_func_t));
2005 } else {
2006 /* EIO 5 */
2007 ret = -5;
2008 goto _fail_;
2009 }
2010 }
2011
2012 /***
2013 * mac interface init
2014 **/
2015 if (!mac_cfg.cfg_init(wilc_debug)) {
2016 /* ENOBUFS 105 */
2017 ret = -105;
2018 goto _fail_;
2019 }
2020 memcpy((void *)&g_wlan.cif_func, &mac_cfg, sizeof(wilc_cfg_func_t));
2021
2022
2023 /**
2024 * alloc tx, rx buffer
2025 **/
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002026 if (g_wlan.tx_buffer == NULL)
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07002027 g_wlan.tx_buffer = kmalloc(g_wlan.tx_buffer_size, GFP_KERNEL);
Arnd Bergmann7a8fd842015-06-01 21:06:45 +02002028 PRINT_D(TX_DBG, "g_wlan.tx_buffer = %p\n", g_wlan.tx_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002029
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002030 if (g_wlan.tx_buffer == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002031 /* ENOBUFS 105 */
2032 ret = -105;
2033 PRINT_ER("Can't allocate Tx Buffer");
2034 goto _fail_;
2035 }
2036
2037/* rx_buffer is not used unless we activate USE_MEM STATIC which is not applicable, allocating such memory is useless*/
2038#if defined (MEMORY_STATIC)
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002039 if (g_wlan.rx_buffer == NULL)
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07002040 g_wlan.rx_buffer = kmalloc(g_wlan.rx_buffer_size, GFP_KERNEL);
Arnd Bergmann7a8fd842015-06-01 21:06:45 +02002041 PRINT_D(TX_DBG, "g_wlan.rx_buffer =%p\n", g_wlan.rx_buffer);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002042 if (g_wlan.rx_buffer == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002043 /* ENOBUFS 105 */
2044 ret = -105;
2045 PRINT_ER("Can't allocate Rx Buffer");
2046 goto _fail_;
2047 }
2048#endif
2049
2050 /**
2051 * export functions
2052 **/
2053 oup->wlan_firmware_download = wilc_wlan_firmware_download;
2054 oup->wlan_start = wilc_wlan_start;
2055 oup->wlan_stop = wilc_wlan_stop;
2056 oup->wlan_add_to_tx_que = wilc_wlan_txq_add_net_pkt;
2057 oup->wlan_handle_tx_que = wilc_wlan_handle_txq;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002058 oup->wlan_handle_rx_isr = wilc_handle_isr;
2059 oup->wlan_cleanup = wilc_wlan_cleanup;
2060 oup->wlan_cfg_set = wilc_wlan_cfg_set;
2061 oup->wlan_cfg_get = wilc_wlan_cfg_get;
2062 oup->wlan_cfg_get_value = wilc_wlan_cfg_get_val;
2063
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002064 oup->wlan_add_mgmt_to_tx_que = wilc_wlan_txq_add_mgmt_pkt;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002065
2066 if (!init_chip()) {
2067 /* EIO 5 */
2068 ret = -5;
2069 goto _fail_;
2070 }
2071#ifdef TCP_ACK_FILTER
2072 Init_TCP_tracking();
2073#endif
2074
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002075 return 1;
2076
2077_fail_:
2078
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002079 #ifdef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07002080 kfree(g_wlan.rx_buffer);
2081 g_wlan.rx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002082 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07002083 kfree(g_wlan.tx_buffer);
2084 g_wlan.tx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002085
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002086 return ret;
2087
2088}
2089
Dean Lee72ed4dc2015-06-12 14:11:44 +09002090u16 Set_machw_change_vir_if(bool bValue)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002091{
Chaehyun Limd85f5322015-06-11 14:35:54 +09002092 u16 ret;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002093 u32 reg;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002094
2095 /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -07002096 mutex_lock((&g_wlan)->hif_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002097 ret = (&g_wlan)->hif_func.hif_read_reg(WILC_CHANGING_VIR_IF, &reg);
2098 if (!ret) {
2099 PRINT_ER("Error while Reading reg WILC_CHANGING_VIR_IF\n");
2100 }
2101
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05302102 if (bValue)
Chaehyun Lim50b51da2015-09-16 20:11:26 +09002103 reg |= BIT(31);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05302104 else
Chaehyun Lim50b51da2015-09-16 20:11:26 +09002105 reg &= ~BIT(31);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002106
2107 ret = (&g_wlan)->hif_func.hif_write_reg(WILC_CHANGING_VIR_IF, reg);
2108
2109 if (!ret) {
2110 PRINT_ER("Error while writing reg WILC_CHANGING_VIR_IF\n");
2111 }
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -07002112 mutex_unlock((&g_wlan)->hif_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002113
2114 return ret;
2115}