blob: 1fe1ba53cf538162daf0e6b5a82be56bea7a3578 [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;
35 wilc_wlan_net_func_t net_func;
36 wilc_wlan_indicate_func_t indicate_func;
37
38 /**
39 * host interface functions
40 **/
41 wilc_hif_func_t hif_func;
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -070042 struct mutex *hif_lock;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090043
44 /**
45 * configuration interface functions
46 **/
47 wilc_cfg_func_t cif_func;
48 int cfg_frame_in_use;
49 wilc_cfg_frame_t cfg_frame;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090050 u32 cfg_frame_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090051 int cfg_seq_no;
52 void *cfg_wait;
53
54 /**
55 * RX buffer
56 **/
57 #ifdef MEMORY_STATIC
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090058 u32 rx_buffer_size;
Chaehyun Lim51e825f2015-09-15 14:06:14 +090059 u8 *rx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090060 u32 rx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090061 #endif
62 /**
63 * TX buffer
64 **/
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090065 u32 tx_buffer_size;
Chaehyun Lim51e825f2015-09-15 14:06:14 +090066 u8 *tx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090067 u32 tx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090068
69 /**
70 * TX queue
71 **/
72 void *txq_lock;
73
74 /*Added by Amr - BugID_4720*/
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -070075 struct semaphore *txq_add_to_head_lock;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090076 void *txq_spinlock;
77 unsigned long txq_spinlock_flags;
78
79 struct txq_entry_t *txq_head;
80 struct txq_entry_t *txq_tail;
81 int txq_entries;
82 void *txq_wait;
83 int txq_exit;
84
85 /**
86 * RX queue
87 **/
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -070088 struct mutex *rxq_lock;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090089 struct rxq_entry_t *rxq_head;
90 struct rxq_entry_t *rxq_tail;
91 int rxq_entries;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090092 int rxq_exit;
93
94
95} wilc_wlan_dev_t;
96
97static wilc_wlan_dev_t g_wlan;
98
Chaehyun Lim9af382b2015-09-16 20:11:27 +090099static inline void chip_allow_sleep(void);
100static inline void chip_wakeup(void);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900101/********************************************
102 *
103 * Debug
104 *
105 ********************************************/
106
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900107static u32 dbgflag = N_INIT | N_ERR | N_INTR | N_TXQ | N_RXQ;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900108
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900109static void wilc_debug(u32 flag, char *fmt, ...)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900110{
111 char buf[256];
112 va_list args;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900113
114 if (flag & dbgflag) {
115 va_start(args, fmt);
Hari Prasath Gujulan Elango81053222015-06-22 13:13:58 +0000116 vsprintf(buf, fmt, args);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900117 va_end(args);
118
119 if (g_wlan.os_func.os_debug)
120 g_wlan.os_func.os_debug(buf);
121 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900122}
123
124static CHIP_PS_STATE_T genuChipPSstate = CHIP_WAKEDUP;
125
126/*BugID_5213*/
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900127/*acquire_bus() and release_bus() are made static inline functions*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900128/*as a temporary workaround to fix a problem of receiving*/
129/*unknown interrupt from FW*/
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900130static inline void acquire_bus(BUS_ACQUIRE_T acquire)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900131{
132
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -0700133 mutex_lock(g_wlan.hif_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900134 #ifndef WILC_OPTIMIZE_SLEEP_INT
135 if (genuChipPSstate != CHIP_WAKEDUP)
136 #endif
137 {
138 if (acquire == ACQUIRE_AND_WAKEUP)
139 chip_wakeup();
140 }
141
142}
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900143static inline void release_bus(BUS_RELEASE_T release)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900144{
145 #ifdef WILC_OPTIMIZE_SLEEP_INT
146 if (release == RELEASE_ALLOW_SLEEP)
147 chip_allow_sleep();
148 #endif
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -0700149 mutex_unlock(g_wlan.hif_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900150}
151/********************************************
152 *
153 * Queue
154 *
155 ********************************************/
156
157static void wilc_wlan_txq_remove(struct txq_entry_t *tqe)
158{
159
160 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
161 /* unsigned long flags; */
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900162 if (tqe == p->txq_head) {
163
164 p->txq_head = tqe->next;
165 if (p->txq_head)
166 p->txq_head->prev = NULL;
167
168
169 } else if (tqe == p->txq_tail) {
170 p->txq_tail = (tqe->prev);
171 if (p->txq_tail)
172 p->txq_tail->next = NULL;
173 } else {
174 tqe->prev->next = tqe->next;
175 tqe->next->prev = tqe->prev;
176 }
177 p->txq_entries -= 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900178
179}
180
181static struct txq_entry_t *wilc_wlan_txq_remove_from_head(void)
182{
183 struct txq_entry_t *tqe;
184 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
185 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900186
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700187 spin_lock_irqsave(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900188 if (p->txq_head) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900189 tqe = p->txq_head;
190 p->txq_head = tqe->next;
191 if (p->txq_head) {
192 p->txq_head->prev = NULL;
193 }
194 p->txq_entries -= 1;
195
196 /*Added by Amr - BugID_4720*/
197
198
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900199
200 } else {
201 tqe = NULL;
202 }
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700203 spin_unlock_irqrestore(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900204 return tqe;
205}
206
207static void wilc_wlan_txq_add_to_tail(struct txq_entry_t *tqe)
208{
209 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
210 unsigned long flags;
211 /*Added by Amr - BugID_4720*/
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700212 spin_lock_irqsave(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900213
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900214 if (p->txq_head == NULL) {
215 tqe->next = NULL;
216 tqe->prev = NULL;
217 p->txq_head = tqe;
218 p->txq_tail = tqe;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900219 } else {
220 tqe->next = NULL;
221 tqe->prev = p->txq_tail;
222 p->txq_tail->next = tqe;
223 p->txq_tail = tqe;
224 }
225 p->txq_entries += 1;
226 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900227
228 /*Added by Amr - BugID_4720*/
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700229 spin_unlock_irqrestore(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900230
231 /**
232 * wake up TX queue
233 **/
234 PRINT_D(TX_DBG, "Wake the txq_handling\n");
235
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -0700236 up(p->txq_wait);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900237}
238
239static int wilc_wlan_txq_add_to_head(struct txq_entry_t *tqe)
240{
241 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
242 unsigned long flags;
243 /*Added by Amr - BugID_4720*/
244 if (p->os_func.os_wait(p->txq_add_to_head_lock, CFG_PKTS_TIMEOUT))
245 return -1;
246
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700247 spin_lock_irqsave(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900248
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900249 if (p->txq_head == NULL) {
250 tqe->next = NULL;
251 tqe->prev = NULL;
252 p->txq_head = tqe;
253 p->txq_tail = tqe;
254 } else {
255 tqe->next = p->txq_head;
256 tqe->prev = NULL;
257 p->txq_head->prev = tqe;
258 p->txq_head = tqe;
259 }
260 p->txq_entries += 1;
261 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900262
263 /*Added by Amr - BugID_4720*/
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700264 spin_unlock_irqrestore(p->txq_spinlock, flags);
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -0700265 up(p->txq_add_to_head_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900266
267
268 /**
269 * wake up TX queue
270 **/
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -0700271 up(p->txq_wait);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900272 PRINT_D(TX_DBG, "Wake up the txq_handler\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900273
274 /*Added by Amr - BugID_4720*/
275 return 0;
276
277}
278
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900279u32 Statisitcs_totalAcks = 0, Statisitcs_DroppedAcks = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900280
281#ifdef TCP_ACK_FILTER
282struct Ack_session_info;
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530283struct Ack_session_info {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900284 u32 Ack_seq_num;
285 u32 Bigger_Ack_num;
Chaehyun Limec53adf2015-09-15 14:06:15 +0900286 u16 src_port;
287 u16 dst_port;
288 u16 status;
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530289};
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900290
291typedef struct {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900292 u32 ack_num;
293 u32 Session_index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900294 struct txq_entry_t *txqe;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900295} Pending_Acks_info_t /*Ack_info_t*/;
296
297
298
299
300struct Ack_session_info *Free_head;
301struct Ack_session_info *Alloc_head;
302
303#define TCP_FIN_MASK (1 << 0)
304#define TCP_SYN_MASK (1 << 1)
305#define TCP_Ack_MASK (1 << 4)
306#define NOT_TCP_ACK (-1)
307
308#define MAX_TCP_SESSION 25
309#define MAX_PENDING_ACKS 256
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530310struct Ack_session_info Acks_keep_track_info[2 * MAX_TCP_SESSION];
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900311Pending_Acks_info_t Pending_Acks_info[MAX_PENDING_ACKS];
312
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900313u32 PendingAcks_arrBase;
314u32 Opened_TCP_session;
315u32 Pending_Acks;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900316
317
318
Chaehyun Limfed16f22015-09-17 16:48:43 +0900319static inline int Init_TCP_tracking(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900320{
321
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900322 return 0;
323
324}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900325static inline int add_TCP_track_session(u32 src_prt, u32 dst_prt, u32 seq)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900326{
327 Acks_keep_track_info[Opened_TCP_session].Ack_seq_num = seq;
328 Acks_keep_track_info[Opened_TCP_session].Bigger_Ack_num = 0;
329 Acks_keep_track_info[Opened_TCP_session].src_port = src_prt;
330 Acks_keep_track_info[Opened_TCP_session].dst_port = dst_prt;
331 Opened_TCP_session++;
332
333 PRINT_D(TCP_ENH, "TCP Session %d to Ack %d\n", Opened_TCP_session, seq);
334 return 0;
335}
336
Chaehyun Limfed16f22015-09-17 16:48:43 +0900337static inline int Update_TCP_track_session(u32 index, u32 Ack)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900338{
339
340 if (Ack > Acks_keep_track_info[index].Bigger_Ack_num) {
341 Acks_keep_track_info[index].Bigger_Ack_num = Ack;
342 }
343 return 0;
344
345}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900346static inline int add_TCP_Pending_Ack(u32 Ack, u32 Session_index, struct txq_entry_t *txqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900347{
348 Statisitcs_totalAcks++;
349 if (Pending_Acks < MAX_PENDING_ACKS) {
350 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].ack_num = Ack;
351 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].txqe = txqe;
352 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].Session_index = Session_index;
353 txqe->tcp_PendingAck_index = PendingAcks_arrBase + Pending_Acks;
354 Pending_Acks++;
355
356 } else {
357
358 }
359 return 0;
360}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900361static inline int remove_TCP_related(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900362{
363 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
364 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900365
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700366 spin_lock_irqsave(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900367
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700368 spin_unlock_irqrestore(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900369 return 0;
370}
371
Chaehyun Limfed16f22015-09-17 16:48:43 +0900372static inline int tcp_process(struct txq_entry_t *tqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900373{
374 int ret;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900375 u8 *eth_hdr_ptr;
376 u8 *buffer = tqe->buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900377 unsigned short h_proto;
378 int i;
379 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
380 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900381
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700382 spin_lock_irqsave(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900383
384 eth_hdr_ptr = &buffer[0];
385 h_proto = ntohs(*((unsigned short *)&eth_hdr_ptr[12]));
386 if (h_proto == 0x0800) { /* IP */
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900387 u8 *ip_hdr_ptr;
388 u8 protocol;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900389
390 ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN];
391 protocol = ip_hdr_ptr[9];
392
393
394 if (protocol == 0x06) {
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900395 u8 *tcp_hdr_ptr;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900396 u32 IHL, Total_Length, Data_offset;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900397
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900398 tcp_hdr_ptr = &ip_hdr_ptr[IP_HDR_LEN];
399 IHL = (ip_hdr_ptr[0] & 0xf) << 2;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900400 Total_Length = (((u32)ip_hdr_ptr[2]) << 8) + ((u32)ip_hdr_ptr[3]);
401 Data_offset = (((u32)tcp_hdr_ptr[12] & 0xf0) >> 2);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900402 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 +0900403 u32 seq_no, Ack_no;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900404
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900405 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 +0900406
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900407 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 +0900408
409
410 for (i = 0; i < Opened_TCP_session; i++) {
411 if (Acks_keep_track_info[i].Ack_seq_num == seq_no) {
412 Update_TCP_track_session(i, Ack_no);
413 break;
414 }
415 }
416 if (i == Opened_TCP_session) {
417 add_TCP_track_session(0, 0, seq_no);
418 }
419 add_TCP_Pending_Ack(Ack_no, i, tqe);
420
421
422 }
423
424 } else {
425 ret = 0;
426 }
427 } else {
428 ret = 0;
429 }
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700430 spin_unlock_irqrestore(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900431 return ret;
432}
433
434
435static int wilc_wlan_txq_filter_dup_tcp_ack(void)
436{
437
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900438 u32 i = 0;
439 u32 Dropped = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900440 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
441
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700442 spin_lock_irqsave(p->txq_spinlock, p->txq_spinlock_flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900443 for (i = PendingAcks_arrBase; i < (PendingAcks_arrBase + Pending_Acks); i++) {
444 if (Pending_Acks_info[i].ack_num < Acks_keep_track_info[Pending_Acks_info[i].Session_index].Bigger_Ack_num) {
445 struct txq_entry_t *tqe;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900446
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530447 PRINT_D(TCP_ENH, "DROP ACK: %u\n", Pending_Acks_info[i].ack_num);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900448 tqe = Pending_Acks_info[i].txqe;
449 if (tqe) {
450 wilc_wlan_txq_remove(tqe);
451 Statisitcs_DroppedAcks++;
452 tqe->status = 1; /* mark the packet send */
453 if (tqe->tx_complete_func)
454 tqe->tx_complete_func(tqe->priv, tqe->status);
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -0700455 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900456 Dropped++;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900457 }
458 }
459 }
460 Pending_Acks = 0;
461 Opened_TCP_session = 0;
462
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530463 if (PendingAcks_arrBase == 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900464 PendingAcks_arrBase = MAX_TCP_SESSION;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530465 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900466 PendingAcks_arrBase = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900467
468
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700469 spin_unlock_irqrestore(p->txq_spinlock, p->txq_spinlock_flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900470
471 while (Dropped > 0) {
472 /*consume the semaphore count of the removed packet*/
473 p->os_func.os_wait(p->txq_wait, 1);
474 Dropped--;
475 }
476
477 return 1;
478}
479#endif
480
Dean Lee72ed4dc2015-06-12 14:11:44 +0900481bool EnableTCPAckFilter = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900482
Dean Lee72ed4dc2015-06-12 14:11:44 +0900483void Enable_TCP_ACK_Filter(bool value)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900484{
485 EnableTCPAckFilter = value;
486}
487
Dean Lee72ed4dc2015-06-12 14:11:44 +0900488bool is_TCP_ACK_Filter_Enabled(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900489{
490 return EnableTCPAckFilter;
491}
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900492
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900493static int wilc_wlan_txq_add_cfg_pkt(u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900494{
495 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
496 struct txq_entry_t *tqe;
497
498 PRINT_D(TX_DBG, "Adding config packet ...\n");
499 if (p->quit) {
500 PRINT_D(TX_DBG, "Return due to clear function\n");
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -0700501 up(p->cfg_wait);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900502 return 0;
503 }
504
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700505 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900506 if (tqe == NULL) {
507 PRINT_ER("Failed to allocate memory\n");
508 return 0;
509 }
510
511 tqe->type = WILC_CFG_PKT;
512 tqe->buffer = buffer;
513 tqe->buffer_size = buffer_size;
514 tqe->tx_complete_func = NULL;
515 tqe->priv = NULL;
516#ifdef TCP_ACK_FILTER
517 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
518#endif
519 /**
520 * Configuration packet always at the front
521 **/
522 PRINT_D(TX_DBG, "Adding the config packet at the Queue tail\n");
523
524 /*Edited by Amr - BugID_4720*/
525 if (wilc_wlan_txq_add_to_head(tqe))
526 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900527 return 1;
528}
529
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900530static 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 +0900531{
532 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
533 struct txq_entry_t *tqe;
534
535 if (p->quit)
536 return 0;
537
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700538 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900539
540 if (tqe == NULL)
541 return 0;
542 tqe->type = WILC_NET_PKT;
543 tqe->buffer = buffer;
544 tqe->buffer_size = buffer_size;
545 tqe->tx_complete_func = func;
546 tqe->priv = priv;
547
548 PRINT_D(TX_DBG, "Adding mgmt packet at the Queue tail\n");
549#ifdef TCP_ACK_FILTER
550 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
Abdul Hussain5a66bf22015-06-16 09:44:06 +0000551 if (is_TCP_ACK_Filter_Enabled())
Glen Lee25a84832015-09-16 18:53:22 +0900552 tcp_process(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900553#endif
554 wilc_wlan_txq_add_to_tail(tqe);
555 /*return number of itemes in the queue*/
556 return p->txq_entries;
557}
Glen Leefcc6ef92015-09-16 18:53:21 +0900558
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900559/*Bug3959: transmitting mgmt frames received from host*/
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900560int 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 +0900561{
562
563 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
564 struct txq_entry_t *tqe;
565
566 if (p->quit)
567 return 0;
568
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700569 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900570
571 if (tqe == NULL)
572 return 0;
573 tqe->type = WILC_MGMT_PKT;
574 tqe->buffer = buffer;
575 tqe->buffer_size = buffer_size;
576 tqe->tx_complete_func = func;
577 tqe->priv = priv;
578#ifdef TCP_ACK_FILTER
579 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
580#endif
581 PRINT_D(TX_DBG, "Adding Network packet at the Queue tail\n");
582 wilc_wlan_txq_add_to_tail(tqe);
583 return 1;
584}
Glen Leefcc6ef92015-09-16 18:53:21 +0900585
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900586static struct txq_entry_t *wilc_wlan_txq_get_first(void)
587{
588 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
589 struct txq_entry_t *tqe;
590 unsigned long flags;
591
592 /*Added by Amr - BugID_4720*/
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700593 spin_lock_irqsave(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900594
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900595 tqe = p->txq_head;
596
597 /*Added by Amr - BugID_4720*/
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700598 spin_unlock_irqrestore(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900599
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900600
601 return tqe;
602}
603
604static struct txq_entry_t *wilc_wlan_txq_get_next(struct txq_entry_t *tqe)
605{
606 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
607 unsigned long flags;
608 /*Added by Amr - BugID_4720*/
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700609 spin_lock_irqsave(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900610
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900611 tqe = tqe->next;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900612 /*Added by Amr - BugID_4720*/
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700613 spin_unlock_irqrestore(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900614
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900615
616 return tqe;
617}
618
619static int wilc_wlan_rxq_add(struct rxq_entry_t *rqe)
620{
621 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
622
623 if (p->quit)
624 return 0;
625
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -0700626 mutex_lock(p->rxq_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900627 if (p->rxq_head == NULL) {
628 PRINT_D(RX_DBG, "Add to Queue head\n");
629 rqe->next = NULL;
630 p->rxq_head = rqe;
631 p->rxq_tail = rqe;
632 } else {
633 PRINT_D(RX_DBG, "Add to Queue tail\n");
634 p->rxq_tail->next = rqe;
635 rqe->next = NULL;
636 p->rxq_tail = rqe;
637 }
638 p->rxq_entries += 1;
639 PRINT_D(RX_DBG, "Number of queue entries: %d\n", p->rxq_entries);
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -0700640 mutex_unlock(p->rxq_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900641 return p->rxq_entries;
642}
643
644static struct rxq_entry_t *wilc_wlan_rxq_remove(void)
645{
646 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
647
648 PRINT_D(RX_DBG, "Getting rxQ element\n");
649 if (p->rxq_head) {
650 struct rxq_entry_t *rqe;
651
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -0700652 mutex_lock(p->rxq_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900653 rqe = p->rxq_head;
654 p->rxq_head = p->rxq_head->next;
655 p->rxq_entries -= 1;
656 PRINT_D(RX_DBG, "RXQ entries decreased\n");
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -0700657 mutex_unlock(p->rxq_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900658 return rqe;
659 }
660 PRINT_D(RX_DBG, "Nothing to get from Q\n");
661 return NULL;
662}
663
664
665/********************************************
666 *
667 * Power Save handle functions
668 *
669 ********************************************/
670
671
672
673#ifdef WILC_OPTIMIZE_SLEEP_INT
674
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900675static inline void chip_allow_sleep(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900676{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900677 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900678
679 /* Clear bit 1 */
680 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
681
682 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0));
683}
684
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900685static inline void chip_wakeup(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900686{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900687 u32 reg, clk_status_reg, trials = 0;
688 u32 sleep_time;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900689
690 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
691 do {
692 g_wlan.hif_func.hif_read_reg(1, &reg);
693 /* Set bit 1 */
694 g_wlan.hif_func.hif_write_reg(1, reg | (1 << 1));
695
696 /* Clear bit 1*/
697 g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1));
698
699 do {
700 /* Wait for the chip to stabilize*/
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -0700701 usleep_range(2 * 1000, 2 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900702 /* Make sure chip is awake. This is an extra step that can be removed */
703 /* later to avoid the bus access overhead */
Dean Lee72ed4dc2015-06-12 14:11:44 +0900704 if ((wilc_get_chipid(true) == 0)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900705 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
706 }
Dean Lee72ed4dc2015-06-12 14:11:44 +0900707 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900708
Dean Lee72ed4dc2015-06-12 14:11:44 +0900709 } while (wilc_get_chipid(true) == 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900710 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
711 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
712 do {
713 /* Set bit 1 */
714 g_wlan.hif_func.hif_write_reg(0xf0, reg | (1 << 0));
715
716 /* Check the clock status */
717 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
718
719 /* in case of clocks off, wait 2ms, and check it again. */
720 /* if still off, wait for another 2ms, for a total wait of 6ms. */
721 /* If still off, redo the wake up sequence */
722 while (((clk_status_reg & 0x1) == 0) && (((++trials) % 3) == 0)) {
723 /* Wait for the chip to stabilize*/
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -0700724 usleep_range(2 * 1000, 2 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900725
726 /* Make sure chip is awake. This is an extra step that can be removed */
727 /* later to avoid the bus access overhead */
728 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
729
730 if ((clk_status_reg & 0x1) == 0) {
731 wilc_debug(N_ERR, "clocks still OFF. Wake up failed\n");
732 }
733 }
734 /* in case of failure, Reset the wakeup bit to introduce a new edge on the next loop */
735 if ((clk_status_reg & 0x1) == 0) {
736 /* Reset bit 0 */
737 g_wlan.hif_func.hif_write_reg(0xf0, reg & (~(1 << 0)));
738 }
739 } while ((clk_status_reg & 0x1) == 0);
740 }
741
742
743 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
744 g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
745 reg &= ~(1 << 0);
746 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
747
Dean Lee72ed4dc2015-06-12 14:11:44 +0900748 if (wilc_get_chipid(false) >= 0x1002b0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900749 /* Enable PALDO back right after wakeup */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900750 u32 val32;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900751
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900752 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
753 val32 |= (1 << 6);
754 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
755
756 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
757 val32 |= (1 << 6);
758 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
759 }
760 }
761 genuChipPSstate = CHIP_WAKEDUP;
762}
763#else
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900764static inline void chip_wakeup(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900765{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900766 u32 reg, trials = 0;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900767
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900768 do {
769 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
770 g_wlan.hif_func.hif_read_reg(1, &reg);
771 /* Make sure bit 1 is 0 before we start. */
772 g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1));
773 /* Set bit 1 */
774 g_wlan.hif_func.hif_write_reg(1, reg | (1 << 1));
775 /* Clear bit 1*/
776 g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1));
777 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
778 /* Make sure bit 0 is 0 before we start. */
779 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
780 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0));
781 /* Set bit 1 */
782 g_wlan.hif_func.hif_write_reg(0xf0, reg | (1 << 0));
783 /* Clear bit 1 */
784 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0));
785 }
786
787 do {
788 /* Wait for the chip to stabilize*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900789 mdelay(3);
790
791 /* Make sure chip is awake. This is an extra step that can be removed */
792 /* later to avoid the bus access overhead */
Dean Lee72ed4dc2015-06-12 14:11:44 +0900793 if ((wilc_get_chipid(true) == 0)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900794 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
795 }
Dean Lee72ed4dc2015-06-12 14:11:44 +0900796 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900797
Dean Lee72ed4dc2015-06-12 14:11:44 +0900798 } while (wilc_get_chipid(true) == 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900799
800 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
801 g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
802 reg &= ~(1 << 0);
803 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
804
Dean Lee72ed4dc2015-06-12 14:11:44 +0900805 if (wilc_get_chipid(false) >= 0x1002b0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900806 /* Enable PALDO back right after wakeup */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900807 u32 val32;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900808
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900809 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
810 val32 |= (1 << 6);
811 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
812
813 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
814 val32 |= (1 << 6);
815 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
816 }
817 }
818 genuChipPSstate = CHIP_WAKEDUP;
819}
820#endif
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900821void chip_sleep_manually(u32 u32SleepTime)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900822{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900823 if (genuChipPSstate != CHIP_WAKEDUP) {
824 /* chip is already sleeping. Do nothing */
825 return;
826 }
827 acquire_bus(ACQUIRE_ONLY);
828
829#ifdef WILC_OPTIMIZE_SLEEP_INT
830 chip_allow_sleep();
831#endif
832
833 /* Trigger the manual sleep interrupt */
834 g_wlan.hif_func.hif_write_reg(0x10a8, 1);
835
836 genuChipPSstate = CHIP_SLEEPING_MANUAL;
837 release_bus(RELEASE_ONLY);
838
839}
840
841
842/********************************************
843 *
844 * Tx, Rx queue handle functions
845 *
846 ********************************************/
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900847static int wilc_wlan_handle_txq(u32 *pu32TxqCount)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900848{
849 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
850 int i, entries = 0;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900851 u32 sum;
852 u32 reg;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900853 u8 *txb = p->tx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900854 u32 offset = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900855 int vmm_sz = 0;
856 struct txq_entry_t *tqe;
857 int ret = 0;
858 int counter;
859 int timeout;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900860 u32 vmm_table[WILC_VMM_TBL_SIZE];
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900861
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900862 p->txq_exit = 0;
863 do {
864 if (p->quit)
865 break;
866
867 /*Added by Amr - BugID_4720*/
868 p->os_func.os_wait(p->txq_add_to_head_lock, CFG_PKTS_TIMEOUT);
869#ifdef TCP_ACK_FILTER
870 wilc_wlan_txq_filter_dup_tcp_ack();
871#endif
872 /**
873 * build the vmm list
874 **/
875 PRINT_D(TX_DBG, "Getting the head of the TxQ\n");
876 tqe = wilc_wlan_txq_get_first();
877 i = 0;
878 sum = 0;
879 do {
880 /* if ((tqe != NULL) && (i < (8)) && */
881 /* if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE-1)) && */
882 if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE - 1)) /* reserve last entry to 0 */) {
883
884 if (tqe->type == WILC_CFG_PKT) {
885 vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET;
886 }
887 /*Bug3959: transmitting mgmt frames received from host*/
888 /*vmm_sz will only be equal to tqe->buffer_size + 4 bytes (HOST_HDR_OFFSET)*/
889 /* in other cases WILC_MGMT_PKT and WILC_DATA_PKT_MAC_HDR*/
890 else if (tqe->type == WILC_NET_PKT) {
891 vmm_sz = ETH_ETHERNET_HDR_OFFSET;
892 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900893 else {
894 vmm_sz = HOST_HDR_OFFSET;
895 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900896 vmm_sz += tqe->buffer_size;
897 PRINT_D(TX_DBG, "VMM Size before alignment = %d\n", vmm_sz);
898 if (vmm_sz & 0x3) { /* has to be word aligned */
899 vmm_sz = (vmm_sz + 4) & ~0x3;
900 }
901 if ((sum + vmm_sz) > p->tx_buffer_size) {
902 break;
903 }
904 PRINT_D(TX_DBG, "VMM Size AFTER alignment = %d\n", vmm_sz);
905 vmm_table[i] = vmm_sz / 4; /* table take the word size */
906 PRINT_D(TX_DBG, "VMMTable entry size = %d\n", vmm_table[i]);
907
908 if (tqe->type == WILC_CFG_PKT) {
909 vmm_table[i] |= (1 << 10);
910 PRINT_D(TX_DBG, "VMMTable entry changed for CFG packet = %d\n", vmm_table[i]);
911 }
912#ifdef BIG_ENDIAN
913 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
914#endif
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900915
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900916 i++;
917 sum += vmm_sz;
918 PRINT_D(TX_DBG, "sum = %d\n", sum);
919 tqe = wilc_wlan_txq_get_next(tqe);
920 } else {
921 break;
922 }
923 } while (1);
924
925 if (i == 0) { /* nothing in the queue */
926 PRINT_D(TX_DBG, "Nothing in TX-Q\n");
927 break;
928 } else {
929 PRINT_D(TX_DBG, "Mark the last entry in VMM table - number of previous entries = %d\n", i);
930 vmm_table[i] = 0x0; /* mark the last element to 0 */
931 }
932 acquire_bus(ACQUIRE_AND_WAKEUP);
933 counter = 0;
934 do {
935
936 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg);
937 if (!ret) {
938 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg vmm_tbl_entry..\n");
939 break;
940 }
941
942 if ((reg & 0x1) == 0) {
943 /**
944 * write to vmm table
945 **/
946 PRINT_D(TX_DBG, "Writing VMM table ... with Size = %d\n", ((i + 1) * 4));
947 break;
948 } else {
949 counter++;
950 if (counter > 200) {
951 counter = 0;
952 PRINT_D(TX_DBG, "Looping in tx ctrl , forcce quit\n");
953 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, 0);
954 break;
955 }
956 /**
957 * wait for vmm table is ready
958 **/
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530959 PRINT_WRN(GENERIC_DBG, "[wilc txq]: warn, vmm table not clear yet, wait...\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900960 release_bus(RELEASE_ALLOW_SLEEP);
Greg Kroah-Hartman2b922cb2015-09-04 09:30:51 -0700961 usleep_range(3000, 3000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900962 acquire_bus(ACQUIRE_AND_WAKEUP);
963 }
964 } while (!p->quit);
965
966 if (!ret) {
967 goto _end_;
968 }
969
970 timeout = 200;
971 do {
972
973 /**
974 * write to vmm table
975 **/
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900976 ret = p->hif_func.hif_block_tx(WILC_VMM_TBL_RX_SHADOW_BASE, (u8 *)vmm_table, ((i + 1) * 4)); /* Bug 4477 fix */
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900977 if (!ret) {
978 wilc_debug(N_ERR, "ERR block TX of VMM table.\n");
979 break;
980 }
981
982
983 /**
984 * interrupt firmware
985 **/
986 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x2);
987 if (!ret) {
988 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg host_vmm_ctl..\n");
989 break;
990 }
991
992 /**
993 * wait for confirm...
994 **/
995
996 do {
997 ret = p->hif_func.hif_read_reg(WILC_HOST_VMM_CTL, &reg);
998 if (!ret) {
999 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg host_vmm_ctl..\n");
1000 break;
1001 }
1002 if ((reg >> 2) & 0x1) {
1003 /**
1004 * Get the entries
1005 **/
1006 entries = ((reg >> 3) & 0x3f);
1007 /* entries = ((reg>>3)&0x2f); */
1008 break;
1009 } else {
1010 release_bus(RELEASE_ALLOW_SLEEP);
Greg Kroah-Hartman2b922cb2015-09-04 09:30:51 -07001011 usleep_range(3000, 3000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001012 acquire_bus(ACQUIRE_AND_WAKEUP);
1013 PRINT_WRN(GENERIC_DBG, "Can't get VMM entery - reg = %2x\n", reg);
1014 }
1015 } while (--timeout);
1016 if (timeout <= 0) {
1017 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x0);
1018 break;
1019 }
1020
1021 if (!ret) {
1022 break;
1023 }
1024
1025 if (entries == 0) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301026 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 +09001027
1028 /* undo the transaction. */
1029 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg);
1030 if (!ret) {
1031 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg WILC_HOST_TX_CTRL..\n");
1032 break;
1033 }
1034 reg &= ~(1ul << 0);
1035 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, reg);
1036 if (!ret) {
1037 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg WILC_HOST_TX_CTRL..\n");
1038 break;
1039 }
1040 break;
1041 } else {
1042 break;
1043 }
1044 } while (1);
1045
1046 if (!ret) {
1047 goto _end_;
1048 }
1049 if (entries == 0) {
1050 ret = WILC_TX_ERR_NO_BUF;
1051 goto _end_;
1052 }
1053
1054 /* since copying data into txb takes some time, then
1055 * allow the bus lock to be released let the RX task go. */
1056 release_bus(RELEASE_ALLOW_SLEEP);
1057
1058 /**
1059 * Copy data to the TX buffer
1060 **/
1061 offset = 0;
1062 i = 0;
1063 do {
1064 tqe = wilc_wlan_txq_remove_from_head();
1065 if (tqe != NULL && (vmm_table[i] != 0)) {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001066 u32 header, buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001067
1068#ifdef BIG_ENDIAN
1069 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
1070#endif
1071 vmm_sz = (vmm_table[i] & 0x3ff); /* in word unit */
1072 vmm_sz *= 4;
1073 header = (tqe->type << 31) | (tqe->buffer_size << 15) | vmm_sz;
1074 /*Bug3959: transmitting mgmt frames received from host*/
1075 /*setting bit 30 in the host header to indicate mgmt frame*/
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301076 if (tqe->type == WILC_MGMT_PKT)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001077 header |= (1 << 30);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301078 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001079 header &= ~(1 << 30);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001080
1081#ifdef BIG_ENDIAN
1082 header = BYTE_SWAP(header);
1083#endif
1084 memcpy(&txb[offset], &header, 4);
1085 if (tqe->type == WILC_CFG_PKT) {
1086 buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET;
1087 }
1088 /*Bug3959: transmitting mgmt frames received from host*/
1089 /*buffer offset = HOST_HDR_OFFSET in other cases: WILC_MGMT_PKT*/
1090 /* and WILC_DATA_PKT_MAC_HDR*/
1091 else if (tqe->type == WILC_NET_PKT) {
1092 char *pBSSID = ((struct tx_complete_data *)(tqe->priv))->pBssid;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001093
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001094 buffer_offset = ETH_ETHERNET_HDR_OFFSET;
1095 /* copy the bssid at the sart of the buffer */
1096 memcpy(&txb[offset + 4], pBSSID, 6);
1097 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001098 else {
1099 buffer_offset = HOST_HDR_OFFSET;
1100 }
1101
1102 memcpy(&txb[offset + buffer_offset], tqe->buffer, tqe->buffer_size);
1103 offset += vmm_sz;
1104 i++;
1105 tqe->status = 1; /* mark the packet send */
1106 if (tqe->tx_complete_func)
1107 tqe->tx_complete_func(tqe->priv, tqe->status);
1108 #ifdef TCP_ACK_FILTER
1109 if (tqe->tcp_PendingAck_index != NOT_TCP_ACK) {
1110 Pending_Acks_info[tqe->tcp_PendingAck_index].txqe = NULL;
1111 }
1112 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001113 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001114 } else {
1115 break;
1116 }
1117 } while (--entries);
1118
1119 /**
1120 * lock the bus
1121 **/
1122 acquire_bus(ACQUIRE_AND_WAKEUP);
1123
1124 ret = p->hif_func.hif_clear_int_ext(ENABLE_TX_VMM);
1125 if (!ret) {
1126 wilc_debug(N_ERR, "[wilc txq]: fail can't start tx VMM ...\n");
1127 goto _end_;
1128 }
1129
1130 /**
1131 * transfer
1132 **/
1133 ret = p->hif_func.hif_block_tx_ext(0, txb, offset);
1134 if (!ret) {
1135 wilc_debug(N_ERR, "[wilc txq]: fail can't block tx ext...\n");
1136 goto _end_;
1137 }
1138
1139_end_:
1140
1141 release_bus(RELEASE_ALLOW_SLEEP);
1142 if (ret != 1)
1143 break;
1144 } while (0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001145 /*Added by Amr - BugID_4720*/
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -07001146 up(p->txq_add_to_head_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001147
1148 p->txq_exit = 1;
1149 PRINT_D(TX_DBG, "THREAD: Exiting txq\n");
1150 /* return tx[]q count */
1151 *pu32TxqCount = p->txq_entries;
1152 return ret;
1153}
1154
1155static void wilc_wlan_handle_rxq(void)
1156{
1157 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1158 int offset = 0, size, has_packet = 0;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001159 u8 *buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001160 struct rxq_entry_t *rqe;
1161
1162 p->rxq_exit = 0;
1163
1164
1165
1166
1167 do {
1168 if (p->quit) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301169 PRINT_D(RX_DBG, "exit 1st do-while due to Clean_UP function\n");
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -07001170 up(p->cfg_wait);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001171 break;
1172 }
1173 rqe = wilc_wlan_rxq_remove();
1174 if (rqe == NULL) {
1175 PRINT_D(RX_DBG, "nothing in the queue - exit 1st do-while\n");
1176 break;
1177 }
1178 buffer = rqe->buffer;
1179 size = rqe->buffer_size;
1180 PRINT_D(RX_DBG, "rxQ entery Size = %d - Address = %p\n", size, buffer);
1181 offset = 0;
1182
1183
1184
1185 do {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001186 u32 header;
1187 u32 pkt_len, pkt_offset, tp_len;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001188 int is_cfg_packet;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001189
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001190 PRINT_D(RX_DBG, "In the 2nd do-while\n");
1191 memcpy(&header, &buffer[offset], 4);
1192#ifdef BIG_ENDIAN
1193 header = BYTE_SWAP(header);
1194#endif
1195 PRINT_D(RX_DBG, "Header = %04x - Offset = %d\n", header, offset);
1196
1197
1198
1199 is_cfg_packet = (header >> 31) & 0x1;
1200 pkt_offset = (header >> 22) & 0x1ff;
1201 tp_len = (header >> 11) & 0x7ff;
1202 pkt_len = header & 0x7ff;
1203
1204 if (pkt_len == 0 || tp_len == 0) {
1205 wilc_debug(N_RXQ, "[wilc rxq]: data corrupt, packet len or tp_len is 0 [%d][%d]\n", pkt_len, tp_len);
1206 break;
1207 }
1208
1209/*bug 3887: [AP] Allow Management frames to be passed to the host*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001210 #define IS_MANAGMEMENT 0x100
1211 #define IS_MANAGMEMENT_CALLBACK 0x080
1212 #define IS_MGMT_STATUS_SUCCES 0x040
1213
1214
1215 if (pkt_offset & IS_MANAGMEMENT) {
1216 /* reset mgmt indicator bit, to use pkt_offeset in furthur calculations */
1217 pkt_offset &= ~(IS_MANAGMEMENT | IS_MANAGMEMENT_CALLBACK | IS_MGMT_STATUS_SUCCES);
1218
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001219 WILC_WFI_mgmt_rx(&buffer[offset + HOST_HDR_OFFSET], pkt_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001220 }
1221 /* BUG4530 fix */
1222 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001223 {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001224
1225 if (!is_cfg_packet) {
1226
1227 if (p->net_func.rx_indicate) {
1228 if (pkt_len > 0) {
1229 p->net_func.rx_indicate(&buffer[offset], pkt_len, pkt_offset);
1230 has_packet = 1;
1231 }
1232 }
1233 } else {
1234 wilc_cfg_rsp_t rsp;
1235
1236
1237
1238 p->cif_func.rx_indicate(&buffer[pkt_offset + offset], pkt_len, &rsp);
1239 if (rsp.type == WILC_CFG_RSP) {
1240 /**
1241 * wake up the waiting task...
1242 **/
1243 PRINT_D(RX_DBG, "p->cfg_seq_no = %d - rsp.seq_no = %d\n", p->cfg_seq_no, rsp.seq_no);
1244 if (p->cfg_seq_no == rsp.seq_no) {
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -07001245 up(p->cfg_wait);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001246 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001247 } else if (rsp.type == WILC_CFG_RSP_STATUS) {
1248 /**
1249 * Call back to indicate status...
1250 **/
1251 if (p->indicate_func.mac_indicate) {
1252 p->indicate_func.mac_indicate(WILC_MAC_INDICATE_STATUS);
1253 }
1254
1255 } else if (rsp.type == WILC_CFG_RSP_SCAN) {
1256 if (p->indicate_func.mac_indicate)
1257 p->indicate_func.mac_indicate(WILC_MAC_INDICATE_SCAN);
1258 }
1259 }
1260 }
1261 offset += tp_len;
1262 if (offset >= size)
1263 break;
1264 } while (1);
1265
1266
1267#ifndef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001268 kfree(buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001269#endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001270 kfree(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001271
1272 if (has_packet) {
1273 if (p->net_func.rx_complete)
1274 p->net_func.rx_complete();
1275 }
1276 } while (1);
1277
1278 p->rxq_exit = 1;
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301279 PRINT_D(RX_DBG, "THREAD: Exiting RX thread\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001280}
1281
1282/********************************************
1283 *
1284 * Fast DMA Isr
1285 *
1286 ********************************************/
1287static void wilc_unknown_isr_ext(void)
1288{
1289 g_wlan.hif_func.hif_clear_int_ext(0);
1290}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001291static void wilc_pllupdate_isr_ext(u32 int_stats)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001292{
1293
1294 int trials = 10;
1295
1296 g_wlan.hif_func.hif_clear_int_ext(PLL_INT_CLR);
1297
1298 /* Waiting for PLL */
Greg Kroah-Hartmanc2e4c0f2015-09-03 19:09:50 -07001299 mdelay(WILC_PLL_TO);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001300
1301 /* poll till read a valid data */
Dean Lee72ed4dc2015-06-12 14:11:44 +09001302 while (!(ISWILC1000(wilc_get_chipid(true)) && --trials)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001303 PRINT_D(TX_DBG, "PLL update retrying\n");
Greg Kroah-Hartmanc2e4c0f2015-09-03 19:09:50 -07001304 mdelay(1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001305 }
1306}
1307
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001308static void wilc_sleeptimer_isr_ext(u32 int_stats1)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001309{
1310 g_wlan.hif_func.hif_clear_int_ext(SLEEP_INT_CLR);
1311#ifndef WILC_OPTIMIZE_SLEEP_INT
1312 genuChipPSstate = CHIP_SLEEPING_AUTO;
1313#endif
1314}
1315
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001316static void wilc_wlan_handle_isr_ext(u32 int_status)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001317{
1318 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1319#ifdef MEMORY_STATIC
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001320 u32 offset = p->rx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001321#endif
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001322 u8 *buffer = NULL;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001323 u32 size;
1324 u32 retries = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001325 int ret = 0;
1326 struct rxq_entry_t *rqe;
1327
1328
1329 /**
1330 * Get the rx size
1331 **/
1332
1333 size = ((int_status & 0x7fff) << 2);
1334
1335 while (!size && retries < 10) {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001336 u32 time = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001337 /*looping more secure*/
1338 /*zero size make a crashe because the dma will not happen and that will block the firmware*/
1339 wilc_debug(N_ERR, "RX Size equal zero ... Trying to read it again for %d time\n", time++);
1340 p->hif_func.hif_read_size(&size);
1341 size = ((size & 0x7fff) << 2);
1342 retries++;
1343
1344 }
1345
1346 if (size > 0) {
1347#ifdef MEMORY_STATIC
1348 if (p->rx_buffer_size - offset < size)
1349 offset = 0;
1350
1351 if (p->rx_buffer)
1352 buffer = &p->rx_buffer[offset];
1353 else {
1354 wilc_debug(N_ERR, "[wilc isr]: fail Rx Buffer is NULL...drop the packets (%d)\n", size);
1355 goto _end_;
1356 }
1357
1358#else
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001359 buffer = kmalloc(size, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001360 if (buffer == NULL) {
1361 wilc_debug(N_ERR, "[wilc isr]: fail alloc host memory...drop the packets (%d)\n", size);
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -07001362 usleep_range(100 * 1000, 100 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001363 goto _end_;
1364 }
1365#endif
1366
1367 /**
1368 * clear the chip's interrupt after getting size some register getting corrupted after clear the interrupt
1369 **/
1370 p->hif_func.hif_clear_int_ext(DATA_INT_CLR | ENABLE_RX_VMM);
1371
1372
1373 /**
1374 * start transfer
1375 **/
1376 ret = p->hif_func.hif_block_rx_ext(0, buffer, size);
1377
1378 if (!ret) {
1379 wilc_debug(N_ERR, "[wilc isr]: fail block rx...\n");
1380 goto _end_;
1381 }
1382_end_:
1383
1384
1385 if (ret) {
1386#ifdef MEMORY_STATIC
1387 offset += size;
1388 p->rx_buffer_offset = offset;
1389#endif
1390 /**
1391 * add to rx queue
1392 **/
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001393 rqe = kmalloc(sizeof(struct rxq_entry_t), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001394 if (rqe != NULL) {
1395 rqe->buffer = buffer;
1396 rqe->buffer_size = size;
1397 PRINT_D(RX_DBG, "rxq entery Size= %d - Address = %p\n", rqe->buffer_size, rqe->buffer);
1398 wilc_wlan_rxq_add(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001399 }
1400 } else {
1401#ifndef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001402 kfree(buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001403#endif
1404 }
1405 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001406 wilc_wlan_handle_rxq();
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001407}
1408
1409void wilc_handle_isr(void)
1410{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001411 u32 int_status;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001412
1413 acquire_bus(ACQUIRE_AND_WAKEUP);
1414 g_wlan.hif_func.hif_read_int(&int_status);
1415
1416 if (int_status & PLL_INT_EXT) {
1417 wilc_pllupdate_isr_ext(int_status);
1418 }
1419 if (int_status & DATA_INT_EXT) {
1420 wilc_wlan_handle_isr_ext(int_status);
1421 #ifndef WILC_OPTIMIZE_SLEEP_INT
1422 /* Chip is up and talking*/
1423 genuChipPSstate = CHIP_WAKEDUP;
1424 #endif
1425 }
1426 if (int_status & SLEEP_INT_EXT) {
1427 wilc_sleeptimer_isr_ext(int_status);
1428 }
1429
1430 if (!(int_status & (ALL_INT_EXT))) {
1431#ifdef WILC_SDIO
1432 PRINT_D(TX_DBG, ">> UNKNOWN_INTERRUPT - 0x%08x\n", int_status);
1433#endif
1434 wilc_unknown_isr_ext();
1435 }
1436#if ((!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO))
1437 linux_wlan_enable_irq();
1438#endif
1439 release_bus(RELEASE_ALLOW_SLEEP);
1440}
1441
1442/********************************************
1443 *
1444 * Firmware download
1445 *
1446 ********************************************/
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001447static int wilc_wlan_firmware_download(const u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001448{
1449 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001450 u32 offset;
1451 u32 addr, size, size2, blksz;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001452 u8 *dma_buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001453 int ret = 0;
1454
1455 blksz = (1ul << 12); /* Bug 4703: 4KB Good enough size for most platforms = PAGE_SIZE. */
1456 /* Allocate a DMA coherent buffer. */
1457
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001458 dma_buffer = kmalloc(blksz, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001459 if (dma_buffer == NULL) {
1460 /*EIO 5*/
1461 ret = -5;
1462 PRINT_ER("Can't allocate buffer for firmware download IO error\n ");
1463 goto _fail_1;
1464 }
1465
1466 PRINT_D(INIT_DBG, "Downloading firmware size = %d ...\n", buffer_size);
1467 /**
1468 * load the firmware
1469 **/
1470 offset = 0;
1471 do {
1472 memcpy(&addr, &buffer[offset], 4);
1473 memcpy(&size, &buffer[offset + 4], 4);
1474#ifdef BIG_ENDIAN
1475 addr = BYTE_SWAP(addr);
1476 size = BYTE_SWAP(size);
1477#endif
1478 acquire_bus(ACQUIRE_ONLY);
1479 offset += 8;
1480 while (((int)size) && (offset < buffer_size)) {
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301481 if (size <= blksz)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001482 size2 = size;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301483 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001484 size2 = blksz;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001485 /* Copy firmware into a DMA coherent buffer */
1486 memcpy(dma_buffer, &buffer[offset], size2);
1487 ret = p->hif_func.hif_block_tx(addr, dma_buffer, size2);
1488 if (!ret)
1489 break;
1490
1491 addr += size2;
1492 offset += size2;
1493 size -= size2;
1494 }
1495 release_bus(RELEASE_ONLY);
1496
1497 if (!ret) {
1498 /*EIO 5*/
1499 ret = -5;
1500 PRINT_ER("Can't download firmware IO error\n ");
1501 goto _fail_;
1502 }
1503 PRINT_D(INIT_DBG, "Offset = %d\n", offset);
1504 } while (offset < buffer_size);
1505
1506_fail_:
1507
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001508 kfree(dma_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001509
1510_fail_1:
1511
1512 return (ret < 0) ? ret : 0;
1513}
1514
1515/********************************************
1516 *
1517 * Common
1518 *
1519 ********************************************/
1520static int wilc_wlan_start(void)
1521{
1522 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001523 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001524 int ret;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001525 u32 chipid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001526
1527 /**
1528 * Set the host interface
1529 **/
1530#ifdef OLD_FPGA_BITFILE
1531 acquire_bus(ACQUIRE_ONLY);
1532 ret = p->hif_func.hif_read_reg(WILC_VMM_CORE_CTL, &reg);
1533 if (!ret) {
1534 wilc_debug(N_ERR, "[wilc start]: fail read reg vmm_core_ctl...\n");
1535 release_bus(RELEASE_ALLOW_SLEEP);
1536 return ret;
1537 }
1538 reg |= (p->io_func.io_type << 2);
1539 ret = p->hif_func.hif_write_reg(WILC_VMM_CORE_CTL, reg);
1540 if (!ret) {
1541 wilc_debug(N_ERR, "[wilc start]: fail write reg vmm_core_ctl...\n");
1542 release_bus(RELEASE_ONLY);
1543 return ret;
1544 }
1545#else
1546 if (p->io_func.io_type == HIF_SDIO) {
1547 reg = 0;
1548 reg |= (1 << 3); /* bug 4456 and 4557 */
1549 } else if (p->io_func.io_type == HIF_SPI) {
1550 reg = 1;
1551 }
1552 acquire_bus(ACQUIRE_ONLY);
1553 ret = p->hif_func.hif_write_reg(WILC_VMM_CORE_CFG, reg);
1554 if (!ret) {
1555 wilc_debug(N_ERR, "[wilc start]: fail write reg vmm_core_cfg...\n");
1556 release_bus(RELEASE_ONLY);
1557 /* EIO 5*/
1558 ret = -5;
1559 return ret;
1560 }
1561 reg = 0;
1562#ifdef WILC_SDIO_IRQ_GPIO
1563 reg |= WILC_HAVE_SDIO_IRQ_GPIO;
1564#endif
1565
1566#ifdef WILC_DISABLE_PMU
1567#else
1568 reg |= WILC_HAVE_USE_PMU;
1569#endif
1570
1571#ifdef WILC_SLEEP_CLK_SRC_XO
1572 reg |= WILC_HAVE_SLEEP_CLK_SRC_XO;
1573#elif defined WILC_SLEEP_CLK_SRC_RTC
1574 reg |= WILC_HAVE_SLEEP_CLK_SRC_RTC;
1575#endif
1576
1577#ifdef WILC_EXT_PA_INV_TX_RX
1578 reg |= WILC_HAVE_EXT_PA_INV_TX_RX;
1579#endif
1580
1581 reg |= WILC_HAVE_LEGACY_RF_SETTINGS;
1582
1583
1584/*BugID_5257*/
1585/*Set oscillator frequency*/
1586#ifdef XTAL_24
1587 reg |= WILC_HAVE_XTAL_24;
1588#endif
1589
1590/*BugID_5271*/
1591/*Enable/Disable GPIO configuration for FW logs*/
1592#ifdef DISABLE_WILC_UART
1593 reg |= WILC_HAVE_DISABLE_WILC_UART;
1594#endif
1595
1596 ret = p->hif_func.hif_write_reg(WILC_GP_REG_1, reg);
1597 if (!ret) {
1598 wilc_debug(N_ERR, "[wilc start]: fail write WILC_GP_REG_1 ...\n");
1599 release_bus(RELEASE_ONLY);
1600 /* EIO 5*/
1601 ret = -5;
1602 return ret;
1603 }
1604#endif
1605
1606
1607 /**
1608 * Bus related
1609 **/
1610 p->hif_func.hif_sync_ext(NUM_INT_EXT);
1611
1612 ret = p->hif_func.hif_read_reg(0x1000, &chipid);
1613 if (!ret) {
1614 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1000 ...\n");
1615 release_bus(RELEASE_ONLY);
1616 /* EIO 5*/
1617 ret = -5;
1618 return ret;
1619 }
1620
1621 /**
1622 * Go...
1623 **/
1624
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001625
1626 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1627 if ((reg & (1ul << 10)) == (1ul << 10)) {
1628 reg &= ~(1ul << 10);
1629 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1630 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1631 }
1632
1633 reg |= (1ul << 10);
1634 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1635 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1636 release_bus(RELEASE_ONLY);
1637
1638 return (ret < 0) ? ret : 0;
1639}
1640
1641void wilc_wlan_global_reset(void)
1642{
1643
1644 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001645
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001646 acquire_bus(ACQUIRE_AND_WAKEUP);
1647 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, 0x0);
1648 release_bus(RELEASE_ONLY);
1649}
1650static int wilc_wlan_stop(void)
1651{
1652 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001653 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001654 int ret;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001655 u8 timeout = 10;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001656 /**
1657 * TODO: stop the firmware, need a re-download
1658 **/
1659 acquire_bus(ACQUIRE_AND_WAKEUP);
1660
1661 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1662 if (!ret) {
1663 PRINT_ER("Error while reading reg\n");
1664 release_bus(RELEASE_ALLOW_SLEEP);
1665 return ret;
1666 }
1667
1668 reg &= ~(1 << 10);
1669
1670
1671 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1672 if (!ret) {
1673 PRINT_ER("Error while writing reg\n");
1674 release_bus(RELEASE_ALLOW_SLEEP);
1675 return ret;
1676 }
1677
1678
1679
1680 do {
1681 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1682 if (!ret) {
1683 PRINT_ER("Error while reading reg\n");
1684 release_bus(RELEASE_ALLOW_SLEEP);
1685 return ret;
1686 }
1687 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1688 /*Workaround to ensure that the chip is actually reset*/
1689 if ((reg & (1 << 10))) {
1690 PRINT_D(GENERIC_DBG, "Bit 10 not reset : Retry %d\n", timeout);
1691 reg &= ~(1 << 10);
1692 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1693 timeout--;
1694 } else {
1695 PRINT_D(GENERIC_DBG, "Bit 10 reset after : Retry %d\n", timeout);
1696 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1697 if (!ret) {
1698 PRINT_ER("Error while reading reg\n");
1699 release_bus(RELEASE_ALLOW_SLEEP);
1700 return ret;
1701 }
1702 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1703 break;
1704 }
1705
1706 } while (timeout);
1707#if 1
1708/******************************************************************************/
1709/* This was add at Bug 4595 to reset the chip while maintaining the bus state */
1710/******************************************************************************/
1711 reg = ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 8) | (1 << 9) | (1 << 26) | (1 << 29) | (1 << 30) | (1 << 31)); /**/
1712 /**/
Hari Prasath Gujulan Elango369f1902015-06-22 07:04:39 +00001713 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); /**/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001714 reg = ~(1 << 10); /**/
1715 /**/
1716 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); /**/
1717/******************************************************************************/
1718#endif
1719
1720 release_bus(RELEASE_ALLOW_SLEEP);
1721
1722 return ret;
1723}
1724
1725static void wilc_wlan_cleanup(void)
1726{
1727 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1728 struct txq_entry_t *tqe;
1729 struct rxq_entry_t *rqe;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001730 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001731 int ret;
1732
1733 p->quit = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001734 do {
1735 tqe = wilc_wlan_txq_remove_from_head();
1736 if (tqe == NULL)
1737 break;
1738 if (tqe->tx_complete_func)
1739 tqe->tx_complete_func(tqe->priv, 0);
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001740 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001741 } while (1);
1742
1743 do {
1744 rqe = wilc_wlan_rxq_remove();
1745 if (rqe == NULL)
1746 break;
1747#ifdef MEMORY_DYNAMIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001748 kfree(tqe->buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001749#endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001750 kfree(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001751 } while (1);
1752
1753 /**
1754 * clean up buffer
1755 **/
1756
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001757 #ifdef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001758 kfree(p->rx_buffer);
1759 p->rx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001760 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001761 kfree(p->tx_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001762
1763 acquire_bus(ACQUIRE_AND_WAKEUP);
1764
1765
1766 ret = p->hif_func.hif_read_reg(WILC_GP_REG_0, &reg);
1767 if (!ret) {
1768 PRINT_ER("Error while reading reg\n");
1769 release_bus(RELEASE_ALLOW_SLEEP);
1770 }
1771 PRINT_ER("Writing ABORT reg\n");
1772 ret = p->hif_func.hif_write_reg(WILC_GP_REG_0, (reg | ABORT_INT));
1773 if (!ret) {
1774 PRINT_ER("Error while writing reg\n");
1775 release_bus(RELEASE_ALLOW_SLEEP);
1776 }
1777 release_bus(RELEASE_ALLOW_SLEEP);
1778 /**
1779 * io clean up
1780 **/
1781 p->hif_func.hif_deinit(NULL);
1782
1783}
1784
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001785static int wilc_wlan_cfg_commit(int type, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001786{
1787 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1788 wilc_cfg_frame_t *cfg = &p->cfg_frame;
1789 int total_len = p->cfg_frame_offset + 4 + DRIVER_HANDLER_SIZE;
1790 int seq_no = p->cfg_seq_no % 256;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001791 int driver_handler = (u32)drvHandler;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001792
1793
1794 /**
1795 * Set up header
1796 **/
1797 if (type == WILC_CFG_SET) { /* Set */
1798 cfg->wid_header[0] = 'W';
1799 } else { /* Query */
1800 cfg->wid_header[0] = 'Q';
1801 }
1802 cfg->wid_header[1] = seq_no; /* sequence number */
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001803 cfg->wid_header[2] = (u8)total_len;
1804 cfg->wid_header[3] = (u8)(total_len >> 8);
1805 cfg->wid_header[4] = (u8)driver_handler;
1806 cfg->wid_header[5] = (u8)(driver_handler >> 8);
1807 cfg->wid_header[6] = (u8)(driver_handler >> 16);
1808 cfg->wid_header[7] = (u8)(driver_handler >> 24);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001809 p->cfg_seq_no = seq_no;
1810
1811 /**
1812 * Add to TX queue
1813 **/
1814
1815 /*Edited by Amr - BugID_4720*/
1816 if (!wilc_wlan_txq_add_cfg_pkt(&cfg->wid_header[0], total_len))
1817 return -1;
1818
1819 return 0;
1820}
1821
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001822static 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 +09001823{
1824 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001825 u32 offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001826 int ret_size;
1827
1828
1829 if (p->cfg_frame_in_use)
1830 return 0;
1831
1832 if (start)
1833 p->cfg_frame_offset = 0;
1834
1835 offset = p->cfg_frame_offset;
Chaehyun Limec53adf2015-09-15 14:06:15 +09001836 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 +09001837 offset += ret_size;
1838 p->cfg_frame_offset = offset;
1839
1840 if (commit) {
1841 PRINT_D(TX_DBG, "[WILC]PACKET Commit with sequence number %d\n", p->cfg_seq_no);
1842 PRINT_D(RX_DBG, "Processing cfg_set()\n");
1843 p->cfg_frame_in_use = 1;
1844
1845 /*Edited by Amr - BugID_4720*/
1846 if (wilc_wlan_cfg_commit(WILC_CFG_SET, drvHandler))
1847 ret_size = 0; /* BugID_5213 */
1848
1849 if (p->os_func.os_wait(p->cfg_wait, CFG_PKTS_TIMEOUT)) {
1850 PRINT_D(TX_DBG, "Set Timed Out\n");
1851 ret_size = 0;
1852 }
1853 p->cfg_frame_in_use = 0;
1854 p->cfg_frame_offset = 0;
1855 p->cfg_seq_no += 1;
1856
1857 }
1858
1859 return ret_size;
1860}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001861static int wilc_wlan_cfg_get(int start, u32 wid, int commit, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001862{
1863 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001864 u32 offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001865 int ret_size;
1866
1867
1868 if (p->cfg_frame_in_use)
1869 return 0;
1870
1871 if (start)
1872 p->cfg_frame_offset = 0;
1873
1874 offset = p->cfg_frame_offset;
Chaehyun Limec53adf2015-09-15 14:06:15 +09001875 ret_size = p->cif_func.cfg_wid_get(p->cfg_frame.frame, offset, (u16)wid);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001876 offset += ret_size;
1877 p->cfg_frame_offset = offset;
1878
1879 if (commit) {
1880 p->cfg_frame_in_use = 1;
1881
1882 /*Edited by Amr - BugID_4720*/
1883 if (wilc_wlan_cfg_commit(WILC_CFG_QUERY, drvHandler))
1884 ret_size = 0; /* BugID_5213 */
1885
1886
1887 if (p->os_func.os_wait(p->cfg_wait, CFG_PKTS_TIMEOUT)) {
1888 PRINT_D(TX_DBG, "Get Timed Out\n");
1889 ret_size = 0;
1890 }
1891 PRINT_D(GENERIC_DBG, "[WILC]Get Response received\n");
1892 p->cfg_frame_in_use = 0;
1893 p->cfg_frame_offset = 0;
1894 p->cfg_seq_no += 1;
1895 }
1896
1897 return ret_size;
1898}
1899
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001900static int wilc_wlan_cfg_get_val(u32 wid, u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001901{
1902 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1903 int ret;
1904
Chaehyun Limec53adf2015-09-15 14:06:15 +09001905 ret = p->cif_func.cfg_wid_get_val((u16)wid, buffer, buffer_size);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001906
1907 return ret;
1908}
1909
1910void wilc_bus_set_max_speed(void)
1911{
1912
1913 /* Increase bus speed to max possible. */
1914 g_wlan.hif_func.hif_set_max_bus_speed();
1915}
1916
1917void wilc_bus_set_default_speed(void)
1918{
1919
1920 /* Restore bus speed to default. */
1921 g_wlan.hif_func.hif_set_default_bus_speed();
1922}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001923u32 init_chip(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001924{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001925 u32 chipid;
1926 u32 reg, ret = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001927
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001928 acquire_bus(ACQUIRE_ONLY);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001929
Dean Lee72ed4dc2015-06-12 14:11:44 +09001930 chipid = wilc_get_chipid(true);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001931
1932
1933
1934 if ((chipid & 0xfff) != 0xa0) {
1935 /**
1936 * Avoid booting from boot ROM. Make sure that Drive IRQN [SDIO platform]
1937 * or SD_DAT3 [SPI platform] to ?1?
1938 **/
1939 /* Set cortus reset register to register control. */
1940 ret = g_wlan.hif_func.hif_read_reg(0x1118, &reg);
1941 if (!ret) {
1942 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1118 ...\n");
1943 return ret;
1944 }
1945 reg |= (1 << 0);
1946 ret = g_wlan.hif_func.hif_write_reg(0x1118, reg);
1947 if (!ret) {
1948 wilc_debug(N_ERR, "[wilc start]: fail write reg 0x1118 ...\n");
1949 return ret;
1950 }
1951 /**
1952 * Write branch intruction to IRAM (0x71 trap) at location 0xFFFF0000
1953 * (Cortus map) or C0000 (AHB map).
1954 **/
1955 ret = g_wlan.hif_func.hif_write_reg(0xc0000, 0x71);
1956 if (!ret) {
1957 wilc_debug(N_ERR, "[wilc start]: fail write reg 0xc0000 ...\n");
1958 return ret;
1959 }
1960 }
1961
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001962 release_bus(RELEASE_ONLY);
1963
1964 return ret;
1965
1966}
1967
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001968u32 wilc_get_chipid(u8 update)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001969{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001970 static u32 chipid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001971 /* SDIO can't read into global variables */
1972 /* Use this variable as a temp, then copy to the global */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001973 u32 tempchipid = 0;
1974 u32 rfrevid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001975
1976 if (chipid == 0 || update != 0) {
1977 g_wlan.hif_func.hif_read_reg(0x1000, &tempchipid);
1978 g_wlan.hif_func.hif_read_reg(0x13f4, &rfrevid);
1979 if (!ISWILC1000(tempchipid)) {
1980 chipid = 0;
1981 goto _fail_;
1982 }
1983 if (tempchipid == 0x1002a0) {
1984 if (rfrevid == 0x1) { /* 1002A0 */
1985 } else { /* if (rfrevid == 0x2) */ /* 1002A1 */
1986 tempchipid = 0x1002a1;
1987 }
1988 } else if (tempchipid == 0x1002b0) {
1989 if (rfrevid == 3) { /* 1002B0 */
1990 } else if (rfrevid == 4) { /* 1002B1 */
1991 tempchipid = 0x1002b1;
1992 } else { /* if(rfrevid == 5) */ /* 1002B2 */
1993 tempchipid = 0x1002b2;
1994 }
1995 } else {
1996 }
1997
1998 chipid = tempchipid;
1999 }
2000_fail_:
2001 return chipid;
2002}
2003
2004#ifdef COMPLEMENT_BOOT
Chaehyun Lim51e825f2015-09-15 14:06:14 +09002005u8 core_11b_ready(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002006{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09002007 u32 reg_val;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002008
2009 acquire_bus(ACQUIRE_ONLY);
2010 g_wlan.hif_func.hif_write_reg(0x16082c, 1);
2011 g_wlan.hif_func.hif_write_reg(0x161600, 0x90);
2012 g_wlan.hif_func.hif_read_reg(0x161600, &reg_val);
2013 release_bus(RELEASE_ONLY);
2014
2015 if (reg_val == 0x90)
2016 return 0;
2017 else
2018 return 1;
2019}
2020#endif
2021
2022int wilc_wlan_init(wilc_wlan_inp_t *inp, wilc_wlan_oup_t *oup)
2023{
2024
2025 int ret = 0;
2026
2027 PRINT_D(INIT_DBG, "Initializing WILC_Wlan ...\n");
2028
2029 memset((void *)&g_wlan, 0, sizeof(wilc_wlan_dev_t));
2030
2031 /**
2032 * store the input
2033 **/
2034 memcpy((void *)&g_wlan.os_func, (void *)&inp->os_func, sizeof(wilc_wlan_os_func_t));
2035 memcpy((void *)&g_wlan.io_func, (void *)&inp->io_func, sizeof(wilc_wlan_io_func_t));
2036 memcpy((void *)&g_wlan.net_func, (void *)&inp->net_func, sizeof(wilc_wlan_net_func_t));
2037 memcpy((void *)&g_wlan.indicate_func, (void *)&inp->indicate_func, sizeof(wilc_wlan_net_func_t));
2038 g_wlan.hif_lock = inp->os_context.hif_critical_section;
2039 g_wlan.txq_lock = inp->os_context.txq_critical_section;
2040
2041 /*Added by Amr - BugID_4720*/
2042 g_wlan.txq_add_to_head_lock = inp->os_context.txq_add_to_head_critical_section;
2043
2044 /*Added by Amr - BugID_4720*/
2045 g_wlan.txq_spinlock = inp->os_context.txq_spin_lock;
2046
2047 g_wlan.rxq_lock = inp->os_context.rxq_critical_section;
2048 g_wlan.txq_wait = inp->os_context.txq_wait_event;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002049 g_wlan.cfg_wait = inp->os_context.cfg_wait_event;
2050 g_wlan.tx_buffer_size = inp->os_context.tx_buffer_size;
2051#if defined (MEMORY_STATIC)
2052 g_wlan.rx_buffer_size = inp->os_context.rx_buffer_size;
2053#endif
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002054 /***
2055 * host interface init
2056 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002057 if ((inp->io_func.io_type & 0x1) == HIF_SDIO) {
2058 if (!hif_sdio.hif_init(inp, wilc_debug)) {
2059 /* EIO 5 */
2060 ret = -5;
2061 goto _fail_;
2062 }
2063 memcpy((void *)&g_wlan.hif_func, &hif_sdio, sizeof(wilc_hif_func_t));
2064 } else {
2065 if ((inp->io_func.io_type & 0x1) == HIF_SPI) {
2066 /**
2067 * TODO:
2068 **/
2069 if (!hif_spi.hif_init(inp, wilc_debug)) {
2070 /* EIO 5 */
2071 ret = -5;
2072 goto _fail_;
2073 }
2074 memcpy((void *)&g_wlan.hif_func, &hif_spi, sizeof(wilc_hif_func_t));
2075 } else {
2076 /* EIO 5 */
2077 ret = -5;
2078 goto _fail_;
2079 }
2080 }
2081
2082 /***
2083 * mac interface init
2084 **/
2085 if (!mac_cfg.cfg_init(wilc_debug)) {
2086 /* ENOBUFS 105 */
2087 ret = -105;
2088 goto _fail_;
2089 }
2090 memcpy((void *)&g_wlan.cif_func, &mac_cfg, sizeof(wilc_cfg_func_t));
2091
2092
2093 /**
2094 * alloc tx, rx buffer
2095 **/
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002096 if (g_wlan.tx_buffer == NULL)
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07002097 g_wlan.tx_buffer = kmalloc(g_wlan.tx_buffer_size, GFP_KERNEL);
Arnd Bergmann7a8fd842015-06-01 21:06:45 +02002098 PRINT_D(TX_DBG, "g_wlan.tx_buffer = %p\n", g_wlan.tx_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002099
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002100 if (g_wlan.tx_buffer == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002101 /* ENOBUFS 105 */
2102 ret = -105;
2103 PRINT_ER("Can't allocate Tx Buffer");
2104 goto _fail_;
2105 }
2106
2107/* rx_buffer is not used unless we activate USE_MEM STATIC which is not applicable, allocating such memory is useless*/
2108#if defined (MEMORY_STATIC)
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002109 if (g_wlan.rx_buffer == NULL)
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07002110 g_wlan.rx_buffer = kmalloc(g_wlan.rx_buffer_size, GFP_KERNEL);
Arnd Bergmann7a8fd842015-06-01 21:06:45 +02002111 PRINT_D(TX_DBG, "g_wlan.rx_buffer =%p\n", g_wlan.rx_buffer);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002112 if (g_wlan.rx_buffer == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002113 /* ENOBUFS 105 */
2114 ret = -105;
2115 PRINT_ER("Can't allocate Rx Buffer");
2116 goto _fail_;
2117 }
2118#endif
2119
2120 /**
2121 * export functions
2122 **/
2123 oup->wlan_firmware_download = wilc_wlan_firmware_download;
2124 oup->wlan_start = wilc_wlan_start;
2125 oup->wlan_stop = wilc_wlan_stop;
2126 oup->wlan_add_to_tx_que = wilc_wlan_txq_add_net_pkt;
2127 oup->wlan_handle_tx_que = wilc_wlan_handle_txq;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002128 oup->wlan_handle_rx_isr = wilc_handle_isr;
2129 oup->wlan_cleanup = wilc_wlan_cleanup;
2130 oup->wlan_cfg_set = wilc_wlan_cfg_set;
2131 oup->wlan_cfg_get = wilc_wlan_cfg_get;
2132 oup->wlan_cfg_get_value = wilc_wlan_cfg_get_val;
2133
2134 /*Bug3959: transmitting mgmt frames received from host*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002135 oup->wlan_add_mgmt_to_tx_que = wilc_wlan_txq_add_mgmt_pkt;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002136
2137 if (!init_chip()) {
2138 /* EIO 5 */
2139 ret = -5;
2140 goto _fail_;
2141 }
2142#ifdef TCP_ACK_FILTER
2143 Init_TCP_tracking();
2144#endif
2145
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002146 return 1;
2147
2148_fail_:
2149
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002150 #ifdef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07002151 kfree(g_wlan.rx_buffer);
2152 g_wlan.rx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002153 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07002154 kfree(g_wlan.tx_buffer);
2155 g_wlan.tx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002156
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002157 return ret;
2158
2159}
2160
Dean Lee72ed4dc2015-06-12 14:11:44 +09002161u16 Set_machw_change_vir_if(bool bValue)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002162{
Chaehyun Limd85f5322015-06-11 14:35:54 +09002163 u16 ret;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002164 u32 reg;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002165
2166 /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -07002167 mutex_lock((&g_wlan)->hif_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002168 ret = (&g_wlan)->hif_func.hif_read_reg(WILC_CHANGING_VIR_IF, &reg);
2169 if (!ret) {
2170 PRINT_ER("Error while Reading reg WILC_CHANGING_VIR_IF\n");
2171 }
2172
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05302173 if (bValue)
Chaehyun Lim50b51da2015-09-16 20:11:26 +09002174 reg |= BIT(31);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05302175 else
Chaehyun Lim50b51da2015-09-16 20:11:26 +09002176 reg &= ~BIT(31);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002177
2178 ret = (&g_wlan)->hif_func.hif_write_reg(WILC_CHANGING_VIR_IF, reg);
2179
2180 if (!ret) {
2181 PRINT_ER("Error while writing reg WILC_CHANGING_VIR_IF\n");
2182 }
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -07002183 mutex_unlock((&g_wlan)->hif_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002184
2185 return ret;
2186}