blob: 788e706f1adda9f9f4d84b5788cc5b35c530d4b4 [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"
12#define INLINE static __inline
13
14/********************************************
15 *
16 * Global
17 *
18 ********************************************/
Johnny Kimc5c77ba2015-05-11 14:30:56 +090019extern wilc_hif_func_t hif_sdio;
20extern wilc_hif_func_t hif_spi;
21extern wilc_cfg_func_t mac_cfg;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090022extern void WILC_WFI_mgmt_rx(u8 *buff, u32 size);
23u32 wilc_get_chipid(u8 update);
Dean Lee72ed4dc2015-06-12 14:11:44 +090024u16 Set_machw_change_vir_if(bool bValue);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090025
Johnny Kimc5c77ba2015-05-11 14:30:56 +090026
27
28typedef struct {
29 int quit;
30
31 /**
32 * input interface functions
33 **/
34 wilc_wlan_os_func_t os_func;
35 wilc_wlan_io_func_t io_func;
36 wilc_wlan_net_func_t net_func;
37 wilc_wlan_indicate_func_t indicate_func;
38
39 /**
40 * host interface functions
41 **/
42 wilc_hif_func_t hif_func;
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -070043 struct mutex *hif_lock;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090044
45 /**
46 * configuration interface functions
47 **/
48 wilc_cfg_func_t cif_func;
49 int cfg_frame_in_use;
50 wilc_cfg_frame_t cfg_frame;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090051 u32 cfg_frame_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090052 int cfg_seq_no;
53 void *cfg_wait;
54
55 /**
56 * RX buffer
57 **/
58 #ifdef MEMORY_STATIC
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090059 u32 rx_buffer_size;
Chaehyun Lim51e825f2015-09-15 14:06:14 +090060 u8 *rx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090061 u32 rx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090062 #endif
63 /**
64 * TX buffer
65 **/
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090066 u32 tx_buffer_size;
Chaehyun Lim51e825f2015-09-15 14:06:14 +090067 u8 *tx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090068 u32 tx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090069
70 /**
71 * TX queue
72 **/
73 void *txq_lock;
74
75 /*Added by Amr - BugID_4720*/
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -070076 struct semaphore *txq_add_to_head_lock;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090077 void *txq_spinlock;
78 unsigned long txq_spinlock_flags;
79
80 struct txq_entry_t *txq_head;
81 struct txq_entry_t *txq_tail;
82 int txq_entries;
83 void *txq_wait;
84 int txq_exit;
85
86 /**
87 * RX queue
88 **/
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -070089 struct mutex *rxq_lock;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090090 struct rxq_entry_t *rxq_head;
91 struct rxq_entry_t *rxq_tail;
92 int rxq_entries;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090093 int rxq_exit;
94
95
96} wilc_wlan_dev_t;
97
98static wilc_wlan_dev_t g_wlan;
99
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900100static inline void chip_allow_sleep(void);
101static inline void chip_wakeup(void);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900102/********************************************
103 *
104 * Debug
105 *
106 ********************************************/
107
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900108static u32 dbgflag = N_INIT | N_ERR | N_INTR | N_TXQ | N_RXQ;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900109
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900110static void wilc_debug(u32 flag, char *fmt, ...)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900111{
112 char buf[256];
113 va_list args;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900114
115 if (flag & dbgflag) {
116 va_start(args, fmt);
Hari Prasath Gujulan Elango81053222015-06-22 13:13:58 +0000117 vsprintf(buf, fmt, args);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900118 va_end(args);
119
120 if (g_wlan.os_func.os_debug)
121 g_wlan.os_func.os_debug(buf);
122 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900123}
124
125static CHIP_PS_STATE_T genuChipPSstate = CHIP_WAKEDUP;
126
127/*BugID_5213*/
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900128/*acquire_bus() and release_bus() are made static inline functions*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900129/*as a temporary workaround to fix a problem of receiving*/
130/*unknown interrupt from FW*/
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900131static inline void acquire_bus(BUS_ACQUIRE_T acquire)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900132{
133
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -0700134 mutex_lock(g_wlan.hif_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900135 #ifndef WILC_OPTIMIZE_SLEEP_INT
136 if (genuChipPSstate != CHIP_WAKEDUP)
137 #endif
138 {
139 if (acquire == ACQUIRE_AND_WAKEUP)
140 chip_wakeup();
141 }
142
143}
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900144static inline void release_bus(BUS_RELEASE_T release)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900145{
146 #ifdef WILC_OPTIMIZE_SLEEP_INT
147 if (release == RELEASE_ALLOW_SLEEP)
148 chip_allow_sleep();
149 #endif
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -0700150 mutex_unlock(g_wlan.hif_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900151}
152/********************************************
153 *
154 * Queue
155 *
156 ********************************************/
157
158static void wilc_wlan_txq_remove(struct txq_entry_t *tqe)
159{
160
161 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
162 /* unsigned long flags; */
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900163 if (tqe == p->txq_head) {
164
165 p->txq_head = tqe->next;
166 if (p->txq_head)
167 p->txq_head->prev = NULL;
168
169
170 } else if (tqe == p->txq_tail) {
171 p->txq_tail = (tqe->prev);
172 if (p->txq_tail)
173 p->txq_tail->next = NULL;
174 } else {
175 tqe->prev->next = tqe->next;
176 tqe->next->prev = tqe->prev;
177 }
178 p->txq_entries -= 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900179
180}
181
182static struct txq_entry_t *wilc_wlan_txq_remove_from_head(void)
183{
184 struct txq_entry_t *tqe;
185 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
186 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900187
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700188 spin_lock_irqsave(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900189 if (p->txq_head) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900190 tqe = p->txq_head;
191 p->txq_head = tqe->next;
192 if (p->txq_head) {
193 p->txq_head->prev = NULL;
194 }
195 p->txq_entries -= 1;
196
197 /*Added by Amr - BugID_4720*/
198
199
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900200
201 } else {
202 tqe = NULL;
203 }
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700204 spin_unlock_irqrestore(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900205 return tqe;
206}
207
208static void wilc_wlan_txq_add_to_tail(struct txq_entry_t *tqe)
209{
210 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
211 unsigned long flags;
212 /*Added by Amr - BugID_4720*/
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700213 spin_lock_irqsave(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900214
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900215 if (p->txq_head == NULL) {
216 tqe->next = NULL;
217 tqe->prev = NULL;
218 p->txq_head = tqe;
219 p->txq_tail = tqe;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900220 } else {
221 tqe->next = NULL;
222 tqe->prev = p->txq_tail;
223 p->txq_tail->next = tqe;
224 p->txq_tail = tqe;
225 }
226 p->txq_entries += 1;
227 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900228
229 /*Added by Amr - BugID_4720*/
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700230 spin_unlock_irqrestore(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900231
232 /**
233 * wake up TX queue
234 **/
235 PRINT_D(TX_DBG, "Wake the txq_handling\n");
236
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -0700237 up(p->txq_wait);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900238}
239
240static int wilc_wlan_txq_add_to_head(struct txq_entry_t *tqe)
241{
242 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
243 unsigned long flags;
244 /*Added by Amr - BugID_4720*/
245 if (p->os_func.os_wait(p->txq_add_to_head_lock, CFG_PKTS_TIMEOUT))
246 return -1;
247
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700248 spin_lock_irqsave(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900249
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900250 if (p->txq_head == NULL) {
251 tqe->next = NULL;
252 tqe->prev = NULL;
253 p->txq_head = tqe;
254 p->txq_tail = tqe;
255 } else {
256 tqe->next = p->txq_head;
257 tqe->prev = NULL;
258 p->txq_head->prev = tqe;
259 p->txq_head = tqe;
260 }
261 p->txq_entries += 1;
262 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900263
264 /*Added by Amr - BugID_4720*/
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700265 spin_unlock_irqrestore(p->txq_spinlock, flags);
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -0700266 up(p->txq_add_to_head_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900267
268
269 /**
270 * wake up TX queue
271 **/
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -0700272 up(p->txq_wait);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900273 PRINT_D(TX_DBG, "Wake up the txq_handler\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900274
275 /*Added by Amr - BugID_4720*/
276 return 0;
277
278}
279
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900280u32 Statisitcs_totalAcks = 0, Statisitcs_DroppedAcks = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900281
282#ifdef TCP_ACK_FILTER
283struct Ack_session_info;
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530284struct Ack_session_info {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900285 u32 Ack_seq_num;
286 u32 Bigger_Ack_num;
Chaehyun Limec53adf2015-09-15 14:06:15 +0900287 u16 src_port;
288 u16 dst_port;
289 u16 status;
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530290};
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900291
292typedef struct {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900293 u32 ack_num;
294 u32 Session_index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900295 struct txq_entry_t *txqe;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900296} Pending_Acks_info_t /*Ack_info_t*/;
297
298
299
300
301struct Ack_session_info *Free_head;
302struct Ack_session_info *Alloc_head;
303
304#define TCP_FIN_MASK (1 << 0)
305#define TCP_SYN_MASK (1 << 1)
306#define TCP_Ack_MASK (1 << 4)
307#define NOT_TCP_ACK (-1)
308
309#define MAX_TCP_SESSION 25
310#define MAX_PENDING_ACKS 256
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530311struct Ack_session_info Acks_keep_track_info[2 * MAX_TCP_SESSION];
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900312Pending_Acks_info_t Pending_Acks_info[MAX_PENDING_ACKS];
313
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900314u32 PendingAcks_arrBase;
315u32 Opened_TCP_session;
316u32 Pending_Acks;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900317
318
319
320static __inline int Init_TCP_tracking(void)
321{
322
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900323 return 0;
324
325}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900326static __inline int add_TCP_track_session(u32 src_prt, u32 dst_prt, u32 seq)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900327{
328 Acks_keep_track_info[Opened_TCP_session].Ack_seq_num = seq;
329 Acks_keep_track_info[Opened_TCP_session].Bigger_Ack_num = 0;
330 Acks_keep_track_info[Opened_TCP_session].src_port = src_prt;
331 Acks_keep_track_info[Opened_TCP_session].dst_port = dst_prt;
332 Opened_TCP_session++;
333
334 PRINT_D(TCP_ENH, "TCP Session %d to Ack %d\n", Opened_TCP_session, seq);
335 return 0;
336}
337
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900338static __inline int Update_TCP_track_session(u32 index, u32 Ack)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900339{
340
341 if (Ack > Acks_keep_track_info[index].Bigger_Ack_num) {
342 Acks_keep_track_info[index].Bigger_Ack_num = Ack;
343 }
344 return 0;
345
346}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900347static __inline int add_TCP_Pending_Ack(u32 Ack, u32 Session_index, struct txq_entry_t *txqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900348{
349 Statisitcs_totalAcks++;
350 if (Pending_Acks < MAX_PENDING_ACKS) {
351 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].ack_num = Ack;
352 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].txqe = txqe;
353 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].Session_index = Session_index;
354 txqe->tcp_PendingAck_index = PendingAcks_arrBase + Pending_Acks;
355 Pending_Acks++;
356
357 } else {
358
359 }
360 return 0;
361}
362static __inline int remove_TCP_related(void)
363{
364 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
365 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900366
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700367 spin_lock_irqsave(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900368
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700369 spin_unlock_irqrestore(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900370 return 0;
371}
372
373static __inline int tcp_process(struct txq_entry_t *tqe)
374{
375 int ret;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900376 u8 *eth_hdr_ptr;
377 u8 *buffer = tqe->buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900378 unsigned short h_proto;
379 int i;
380 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
381 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900382
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700383 spin_lock_irqsave(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900384
385 eth_hdr_ptr = &buffer[0];
386 h_proto = ntohs(*((unsigned short *)&eth_hdr_ptr[12]));
387 if (h_proto == 0x0800) { /* IP */
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900388 u8 *ip_hdr_ptr;
389 u8 protocol;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900390
391 ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN];
392 protocol = ip_hdr_ptr[9];
393
394
395 if (protocol == 0x06) {
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900396 u8 *tcp_hdr_ptr;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900397 u32 IHL, Total_Length, Data_offset;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900398
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900399 tcp_hdr_ptr = &ip_hdr_ptr[IP_HDR_LEN];
400 IHL = (ip_hdr_ptr[0] & 0xf) << 2;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900401 Total_Length = (((u32)ip_hdr_ptr[2]) << 8) + ((u32)ip_hdr_ptr[3]);
402 Data_offset = (((u32)tcp_hdr_ptr[12] & 0xf0) >> 2);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900403 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 +0900404 u32 seq_no, Ack_no;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900405
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900406 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 +0900407
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900408 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 +0900409
410
411 for (i = 0; i < Opened_TCP_session; i++) {
412 if (Acks_keep_track_info[i].Ack_seq_num == seq_no) {
413 Update_TCP_track_session(i, Ack_no);
414 break;
415 }
416 }
417 if (i == Opened_TCP_session) {
418 add_TCP_track_session(0, 0, seq_no);
419 }
420 add_TCP_Pending_Ack(Ack_no, i, tqe);
421
422
423 }
424
425 } else {
426 ret = 0;
427 }
428 } else {
429 ret = 0;
430 }
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700431 spin_unlock_irqrestore(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900432 return ret;
433}
434
435
436static int wilc_wlan_txq_filter_dup_tcp_ack(void)
437{
438
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900439 u32 i = 0;
440 u32 Dropped = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900441 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
442
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700443 spin_lock_irqsave(p->txq_spinlock, p->txq_spinlock_flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900444 for (i = PendingAcks_arrBase; i < (PendingAcks_arrBase + Pending_Acks); i++) {
445 if (Pending_Acks_info[i].ack_num < Acks_keep_track_info[Pending_Acks_info[i].Session_index].Bigger_Ack_num) {
446 struct txq_entry_t *tqe;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900447
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530448 PRINT_D(TCP_ENH, "DROP ACK: %u\n", Pending_Acks_info[i].ack_num);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900449 tqe = Pending_Acks_info[i].txqe;
450 if (tqe) {
451 wilc_wlan_txq_remove(tqe);
452 Statisitcs_DroppedAcks++;
453 tqe->status = 1; /* mark the packet send */
454 if (tqe->tx_complete_func)
455 tqe->tx_complete_func(tqe->priv, tqe->status);
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -0700456 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900457 Dropped++;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900458 }
459 }
460 }
461 Pending_Acks = 0;
462 Opened_TCP_session = 0;
463
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530464 if (PendingAcks_arrBase == 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900465 PendingAcks_arrBase = MAX_TCP_SESSION;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530466 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900467 PendingAcks_arrBase = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900468
469
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700470 spin_unlock_irqrestore(p->txq_spinlock, p->txq_spinlock_flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900471
472 while (Dropped > 0) {
473 /*consume the semaphore count of the removed packet*/
474 p->os_func.os_wait(p->txq_wait, 1);
475 Dropped--;
476 }
477
478 return 1;
479}
480#endif
481
Dean Lee72ed4dc2015-06-12 14:11:44 +0900482bool EnableTCPAckFilter = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900483
Dean Lee72ed4dc2015-06-12 14:11:44 +0900484void Enable_TCP_ACK_Filter(bool value)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900485{
486 EnableTCPAckFilter = value;
487}
488
Dean Lee72ed4dc2015-06-12 14:11:44 +0900489bool is_TCP_ACK_Filter_Enabled(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900490{
491 return EnableTCPAckFilter;
492}
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900493
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900494static int wilc_wlan_txq_add_cfg_pkt(u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900495{
496 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
497 struct txq_entry_t *tqe;
498
499 PRINT_D(TX_DBG, "Adding config packet ...\n");
500 if (p->quit) {
501 PRINT_D(TX_DBG, "Return due to clear function\n");
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -0700502 up(p->cfg_wait);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900503 return 0;
504 }
505
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700506 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900507 if (tqe == NULL) {
508 PRINT_ER("Failed to allocate memory\n");
509 return 0;
510 }
511
512 tqe->type = WILC_CFG_PKT;
513 tqe->buffer = buffer;
514 tqe->buffer_size = buffer_size;
515 tqe->tx_complete_func = NULL;
516 tqe->priv = NULL;
517#ifdef TCP_ACK_FILTER
518 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
519#endif
520 /**
521 * Configuration packet always at the front
522 **/
523 PRINT_D(TX_DBG, "Adding the config packet at the Queue tail\n");
524
525 /*Edited by Amr - BugID_4720*/
526 if (wilc_wlan_txq_add_to_head(tqe))
527 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900528 return 1;
529}
530
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900531static 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 +0900532{
533 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
534 struct txq_entry_t *tqe;
535
536 if (p->quit)
537 return 0;
538
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700539 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900540
541 if (tqe == NULL)
542 return 0;
543 tqe->type = WILC_NET_PKT;
544 tqe->buffer = buffer;
545 tqe->buffer_size = buffer_size;
546 tqe->tx_complete_func = func;
547 tqe->priv = priv;
548
549 PRINT_D(TX_DBG, "Adding mgmt packet at the Queue tail\n");
550#ifdef TCP_ACK_FILTER
551 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
Abdul Hussain5a66bf22015-06-16 09:44:06 +0000552 if (is_TCP_ACK_Filter_Enabled())
Glen Lee25a84832015-09-16 18:53:22 +0900553 tcp_process(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900554#endif
555 wilc_wlan_txq_add_to_tail(tqe);
556 /*return number of itemes in the queue*/
557 return p->txq_entries;
558}
Glen Leefcc6ef92015-09-16 18:53:21 +0900559
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900560/*Bug3959: transmitting mgmt frames received from host*/
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900561int 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 +0900562{
563
564 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
565 struct txq_entry_t *tqe;
566
567 if (p->quit)
568 return 0;
569
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700570 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900571
572 if (tqe == NULL)
573 return 0;
574 tqe->type = WILC_MGMT_PKT;
575 tqe->buffer = buffer;
576 tqe->buffer_size = buffer_size;
577 tqe->tx_complete_func = func;
578 tqe->priv = priv;
579#ifdef TCP_ACK_FILTER
580 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
581#endif
582 PRINT_D(TX_DBG, "Adding Network packet at the Queue tail\n");
583 wilc_wlan_txq_add_to_tail(tqe);
584 return 1;
585}
Glen Leefcc6ef92015-09-16 18:53:21 +0900586
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900587static struct txq_entry_t *wilc_wlan_txq_get_first(void)
588{
589 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
590 struct txq_entry_t *tqe;
591 unsigned long flags;
592
593 /*Added by Amr - BugID_4720*/
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700594 spin_lock_irqsave(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900595
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900596 tqe = p->txq_head;
597
598 /*Added by Amr - BugID_4720*/
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700599 spin_unlock_irqrestore(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900600
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900601
602 return tqe;
603}
604
605static struct txq_entry_t *wilc_wlan_txq_get_next(struct txq_entry_t *tqe)
606{
607 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
608 unsigned long flags;
609 /*Added by Amr - BugID_4720*/
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700610 spin_lock_irqsave(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900611
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900612 tqe = tqe->next;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900613 /*Added by Amr - BugID_4720*/
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700614 spin_unlock_irqrestore(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900615
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900616
617 return tqe;
618}
619
620static int wilc_wlan_rxq_add(struct rxq_entry_t *rqe)
621{
622 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
623
624 if (p->quit)
625 return 0;
626
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -0700627 mutex_lock(p->rxq_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900628 if (p->rxq_head == NULL) {
629 PRINT_D(RX_DBG, "Add to Queue head\n");
630 rqe->next = NULL;
631 p->rxq_head = rqe;
632 p->rxq_tail = rqe;
633 } else {
634 PRINT_D(RX_DBG, "Add to Queue tail\n");
635 p->rxq_tail->next = rqe;
636 rqe->next = NULL;
637 p->rxq_tail = rqe;
638 }
639 p->rxq_entries += 1;
640 PRINT_D(RX_DBG, "Number of queue entries: %d\n", p->rxq_entries);
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -0700641 mutex_unlock(p->rxq_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900642 return p->rxq_entries;
643}
644
645static struct rxq_entry_t *wilc_wlan_rxq_remove(void)
646{
647 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
648
649 PRINT_D(RX_DBG, "Getting rxQ element\n");
650 if (p->rxq_head) {
651 struct rxq_entry_t *rqe;
652
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -0700653 mutex_lock(p->rxq_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900654 rqe = p->rxq_head;
655 p->rxq_head = p->rxq_head->next;
656 p->rxq_entries -= 1;
657 PRINT_D(RX_DBG, "RXQ entries decreased\n");
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -0700658 mutex_unlock(p->rxq_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900659 return rqe;
660 }
661 PRINT_D(RX_DBG, "Nothing to get from Q\n");
662 return NULL;
663}
664
665
666/********************************************
667 *
668 * Power Save handle functions
669 *
670 ********************************************/
671
672
673
674#ifdef WILC_OPTIMIZE_SLEEP_INT
675
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900676static inline void chip_allow_sleep(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900677{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900678 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900679
680 /* Clear bit 1 */
681 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
682
683 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0));
684}
685
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900686static inline void chip_wakeup(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900687{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900688 u32 reg, clk_status_reg, trials = 0;
689 u32 sleep_time;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900690
691 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
692 do {
693 g_wlan.hif_func.hif_read_reg(1, &reg);
694 /* Set bit 1 */
695 g_wlan.hif_func.hif_write_reg(1, reg | (1 << 1));
696
697 /* Clear bit 1*/
698 g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1));
699
700 do {
701 /* Wait for the chip to stabilize*/
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -0700702 usleep_range(2 * 1000, 2 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900703 /* Make sure chip is awake. This is an extra step that can be removed */
704 /* later to avoid the bus access overhead */
Dean Lee72ed4dc2015-06-12 14:11:44 +0900705 if ((wilc_get_chipid(true) == 0)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900706 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
707 }
Dean Lee72ed4dc2015-06-12 14:11:44 +0900708 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900709
Dean Lee72ed4dc2015-06-12 14:11:44 +0900710 } while (wilc_get_chipid(true) == 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900711 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
712 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
713 do {
714 /* Set bit 1 */
715 g_wlan.hif_func.hif_write_reg(0xf0, reg | (1 << 0));
716
717 /* Check the clock status */
718 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
719
720 /* in case of clocks off, wait 2ms, and check it again. */
721 /* if still off, wait for another 2ms, for a total wait of 6ms. */
722 /* If still off, redo the wake up sequence */
723 while (((clk_status_reg & 0x1) == 0) && (((++trials) % 3) == 0)) {
724 /* Wait for the chip to stabilize*/
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -0700725 usleep_range(2 * 1000, 2 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900726
727 /* Make sure chip is awake. This is an extra step that can be removed */
728 /* later to avoid the bus access overhead */
729 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
730
731 if ((clk_status_reg & 0x1) == 0) {
732 wilc_debug(N_ERR, "clocks still OFF. Wake up failed\n");
733 }
734 }
735 /* in case of failure, Reset the wakeup bit to introduce a new edge on the next loop */
736 if ((clk_status_reg & 0x1) == 0) {
737 /* Reset bit 0 */
738 g_wlan.hif_func.hif_write_reg(0xf0, reg & (~(1 << 0)));
739 }
740 } while ((clk_status_reg & 0x1) == 0);
741 }
742
743
744 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
745 g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
746 reg &= ~(1 << 0);
747 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
748
Dean Lee72ed4dc2015-06-12 14:11:44 +0900749 if (wilc_get_chipid(false) >= 0x1002b0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900750 /* Enable PALDO back right after wakeup */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900751 u32 val32;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900752
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900753 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
754 val32 |= (1 << 6);
755 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
756
757 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
758 val32 |= (1 << 6);
759 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
760 }
761 }
762 genuChipPSstate = CHIP_WAKEDUP;
763}
764#else
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900765static inline void chip_wakeup(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900766{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900767 u32 reg, trials = 0;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900768
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900769 do {
770 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
771 g_wlan.hif_func.hif_read_reg(1, &reg);
772 /* Make sure bit 1 is 0 before we start. */
773 g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1));
774 /* Set bit 1 */
775 g_wlan.hif_func.hif_write_reg(1, reg | (1 << 1));
776 /* Clear bit 1*/
777 g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1));
778 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
779 /* Make sure bit 0 is 0 before we start. */
780 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
781 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0));
782 /* Set bit 1 */
783 g_wlan.hif_func.hif_write_reg(0xf0, reg | (1 << 0));
784 /* Clear bit 1 */
785 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0));
786 }
787
788 do {
789 /* Wait for the chip to stabilize*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900790 mdelay(3);
791
792 /* Make sure chip is awake. This is an extra step that can be removed */
793 /* later to avoid the bus access overhead */
Dean Lee72ed4dc2015-06-12 14:11:44 +0900794 if ((wilc_get_chipid(true) == 0)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900795 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
796 }
Dean Lee72ed4dc2015-06-12 14:11:44 +0900797 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900798
Dean Lee72ed4dc2015-06-12 14:11:44 +0900799 } while (wilc_get_chipid(true) == 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900800
801 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
802 g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
803 reg &= ~(1 << 0);
804 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
805
Dean Lee72ed4dc2015-06-12 14:11:44 +0900806 if (wilc_get_chipid(false) >= 0x1002b0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900807 /* Enable PALDO back right after wakeup */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900808 u32 val32;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900809
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900810 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
811 val32 |= (1 << 6);
812 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
813
814 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
815 val32 |= (1 << 6);
816 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
817 }
818 }
819 genuChipPSstate = CHIP_WAKEDUP;
820}
821#endif
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900822void chip_sleep_manually(u32 u32SleepTime)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900823{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900824 if (genuChipPSstate != CHIP_WAKEDUP) {
825 /* chip is already sleeping. Do nothing */
826 return;
827 }
828 acquire_bus(ACQUIRE_ONLY);
829
830#ifdef WILC_OPTIMIZE_SLEEP_INT
831 chip_allow_sleep();
832#endif
833
834 /* Trigger the manual sleep interrupt */
835 g_wlan.hif_func.hif_write_reg(0x10a8, 1);
836
837 genuChipPSstate = CHIP_SLEEPING_MANUAL;
838 release_bus(RELEASE_ONLY);
839
840}
841
842
843/********************************************
844 *
845 * Tx, Rx queue handle functions
846 *
847 ********************************************/
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900848static int wilc_wlan_handle_txq(u32 *pu32TxqCount)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900849{
850 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
851 int i, entries = 0;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900852 u32 sum;
853 u32 reg;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900854 u8 *txb = p->tx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900855 u32 offset = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900856 int vmm_sz = 0;
857 struct txq_entry_t *tqe;
858 int ret = 0;
859 int counter;
860 int timeout;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900861 u32 vmm_table[WILC_VMM_TBL_SIZE];
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900862
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900863 p->txq_exit = 0;
864 do {
865 if (p->quit)
866 break;
867
868 /*Added by Amr - BugID_4720*/
869 p->os_func.os_wait(p->txq_add_to_head_lock, CFG_PKTS_TIMEOUT);
870#ifdef TCP_ACK_FILTER
871 wilc_wlan_txq_filter_dup_tcp_ack();
872#endif
873 /**
874 * build the vmm list
875 **/
876 PRINT_D(TX_DBG, "Getting the head of the TxQ\n");
877 tqe = wilc_wlan_txq_get_first();
878 i = 0;
879 sum = 0;
880 do {
881 /* if ((tqe != NULL) && (i < (8)) && */
882 /* if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE-1)) && */
883 if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE - 1)) /* reserve last entry to 0 */) {
884
885 if (tqe->type == WILC_CFG_PKT) {
886 vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET;
887 }
888 /*Bug3959: transmitting mgmt frames received from host*/
889 /*vmm_sz will only be equal to tqe->buffer_size + 4 bytes (HOST_HDR_OFFSET)*/
890 /* in other cases WILC_MGMT_PKT and WILC_DATA_PKT_MAC_HDR*/
891 else if (tqe->type == WILC_NET_PKT) {
892 vmm_sz = ETH_ETHERNET_HDR_OFFSET;
893 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900894 else {
895 vmm_sz = HOST_HDR_OFFSET;
896 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900897 vmm_sz += tqe->buffer_size;
898 PRINT_D(TX_DBG, "VMM Size before alignment = %d\n", vmm_sz);
899 if (vmm_sz & 0x3) { /* has to be word aligned */
900 vmm_sz = (vmm_sz + 4) & ~0x3;
901 }
902 if ((sum + vmm_sz) > p->tx_buffer_size) {
903 break;
904 }
905 PRINT_D(TX_DBG, "VMM Size AFTER alignment = %d\n", vmm_sz);
906 vmm_table[i] = vmm_sz / 4; /* table take the word size */
907 PRINT_D(TX_DBG, "VMMTable entry size = %d\n", vmm_table[i]);
908
909 if (tqe->type == WILC_CFG_PKT) {
910 vmm_table[i] |= (1 << 10);
911 PRINT_D(TX_DBG, "VMMTable entry changed for CFG packet = %d\n", vmm_table[i]);
912 }
913#ifdef BIG_ENDIAN
914 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
915#endif
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900916
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900917 i++;
918 sum += vmm_sz;
919 PRINT_D(TX_DBG, "sum = %d\n", sum);
920 tqe = wilc_wlan_txq_get_next(tqe);
921 } else {
922 break;
923 }
924 } while (1);
925
926 if (i == 0) { /* nothing in the queue */
927 PRINT_D(TX_DBG, "Nothing in TX-Q\n");
928 break;
929 } else {
930 PRINT_D(TX_DBG, "Mark the last entry in VMM table - number of previous entries = %d\n", i);
931 vmm_table[i] = 0x0; /* mark the last element to 0 */
932 }
933 acquire_bus(ACQUIRE_AND_WAKEUP);
934 counter = 0;
935 do {
936
937 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg);
938 if (!ret) {
939 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg vmm_tbl_entry..\n");
940 break;
941 }
942
943 if ((reg & 0x1) == 0) {
944 /**
945 * write to vmm table
946 **/
947 PRINT_D(TX_DBG, "Writing VMM table ... with Size = %d\n", ((i + 1) * 4));
948 break;
949 } else {
950 counter++;
951 if (counter > 200) {
952 counter = 0;
953 PRINT_D(TX_DBG, "Looping in tx ctrl , forcce quit\n");
954 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, 0);
955 break;
956 }
957 /**
958 * wait for vmm table is ready
959 **/
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530960 PRINT_WRN(GENERIC_DBG, "[wilc txq]: warn, vmm table not clear yet, wait...\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900961 release_bus(RELEASE_ALLOW_SLEEP);
Greg Kroah-Hartman2b922cb2015-09-04 09:30:51 -0700962 usleep_range(3000, 3000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900963 acquire_bus(ACQUIRE_AND_WAKEUP);
964 }
965 } while (!p->quit);
966
967 if (!ret) {
968 goto _end_;
969 }
970
971 timeout = 200;
972 do {
973
974 /**
975 * write to vmm table
976 **/
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900977 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 +0900978 if (!ret) {
979 wilc_debug(N_ERR, "ERR block TX of VMM table.\n");
980 break;
981 }
982
983
984 /**
985 * interrupt firmware
986 **/
987 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x2);
988 if (!ret) {
989 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg host_vmm_ctl..\n");
990 break;
991 }
992
993 /**
994 * wait for confirm...
995 **/
996
997 do {
998 ret = p->hif_func.hif_read_reg(WILC_HOST_VMM_CTL, &reg);
999 if (!ret) {
1000 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg host_vmm_ctl..\n");
1001 break;
1002 }
1003 if ((reg >> 2) & 0x1) {
1004 /**
1005 * Get the entries
1006 **/
1007 entries = ((reg >> 3) & 0x3f);
1008 /* entries = ((reg>>3)&0x2f); */
1009 break;
1010 } else {
1011 release_bus(RELEASE_ALLOW_SLEEP);
Greg Kroah-Hartman2b922cb2015-09-04 09:30:51 -07001012 usleep_range(3000, 3000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001013 acquire_bus(ACQUIRE_AND_WAKEUP);
1014 PRINT_WRN(GENERIC_DBG, "Can't get VMM entery - reg = %2x\n", reg);
1015 }
1016 } while (--timeout);
1017 if (timeout <= 0) {
1018 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x0);
1019 break;
1020 }
1021
1022 if (!ret) {
1023 break;
1024 }
1025
1026 if (entries == 0) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301027 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 +09001028
1029 /* undo the transaction. */
1030 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg);
1031 if (!ret) {
1032 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg WILC_HOST_TX_CTRL..\n");
1033 break;
1034 }
1035 reg &= ~(1ul << 0);
1036 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, reg);
1037 if (!ret) {
1038 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg WILC_HOST_TX_CTRL..\n");
1039 break;
1040 }
1041 break;
1042 } else {
1043 break;
1044 }
1045 } while (1);
1046
1047 if (!ret) {
1048 goto _end_;
1049 }
1050 if (entries == 0) {
1051 ret = WILC_TX_ERR_NO_BUF;
1052 goto _end_;
1053 }
1054
1055 /* since copying data into txb takes some time, then
1056 * allow the bus lock to be released let the RX task go. */
1057 release_bus(RELEASE_ALLOW_SLEEP);
1058
1059 /**
1060 * Copy data to the TX buffer
1061 **/
1062 offset = 0;
1063 i = 0;
1064 do {
1065 tqe = wilc_wlan_txq_remove_from_head();
1066 if (tqe != NULL && (vmm_table[i] != 0)) {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001067 u32 header, buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001068
1069#ifdef BIG_ENDIAN
1070 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
1071#endif
1072 vmm_sz = (vmm_table[i] & 0x3ff); /* in word unit */
1073 vmm_sz *= 4;
1074 header = (tqe->type << 31) | (tqe->buffer_size << 15) | vmm_sz;
1075 /*Bug3959: transmitting mgmt frames received from host*/
1076 /*setting bit 30 in the host header to indicate mgmt frame*/
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301077 if (tqe->type == WILC_MGMT_PKT)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001078 header |= (1 << 30);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301079 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001080 header &= ~(1 << 30);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001081
1082#ifdef BIG_ENDIAN
1083 header = BYTE_SWAP(header);
1084#endif
1085 memcpy(&txb[offset], &header, 4);
1086 if (tqe->type == WILC_CFG_PKT) {
1087 buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET;
1088 }
1089 /*Bug3959: transmitting mgmt frames received from host*/
1090 /*buffer offset = HOST_HDR_OFFSET in other cases: WILC_MGMT_PKT*/
1091 /* and WILC_DATA_PKT_MAC_HDR*/
1092 else if (tqe->type == WILC_NET_PKT) {
1093 char *pBSSID = ((struct tx_complete_data *)(tqe->priv))->pBssid;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001094
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001095 buffer_offset = ETH_ETHERNET_HDR_OFFSET;
1096 /* copy the bssid at the sart of the buffer */
1097 memcpy(&txb[offset + 4], pBSSID, 6);
1098 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001099 else {
1100 buffer_offset = HOST_HDR_OFFSET;
1101 }
1102
1103 memcpy(&txb[offset + buffer_offset], tqe->buffer, tqe->buffer_size);
1104 offset += vmm_sz;
1105 i++;
1106 tqe->status = 1; /* mark the packet send */
1107 if (tqe->tx_complete_func)
1108 tqe->tx_complete_func(tqe->priv, tqe->status);
1109 #ifdef TCP_ACK_FILTER
1110 if (tqe->tcp_PendingAck_index != NOT_TCP_ACK) {
1111 Pending_Acks_info[tqe->tcp_PendingAck_index].txqe = NULL;
1112 }
1113 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001114 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001115 } else {
1116 break;
1117 }
1118 } while (--entries);
1119
1120 /**
1121 * lock the bus
1122 **/
1123 acquire_bus(ACQUIRE_AND_WAKEUP);
1124
1125 ret = p->hif_func.hif_clear_int_ext(ENABLE_TX_VMM);
1126 if (!ret) {
1127 wilc_debug(N_ERR, "[wilc txq]: fail can't start tx VMM ...\n");
1128 goto _end_;
1129 }
1130
1131 /**
1132 * transfer
1133 **/
1134 ret = p->hif_func.hif_block_tx_ext(0, txb, offset);
1135 if (!ret) {
1136 wilc_debug(N_ERR, "[wilc txq]: fail can't block tx ext...\n");
1137 goto _end_;
1138 }
1139
1140_end_:
1141
1142 release_bus(RELEASE_ALLOW_SLEEP);
1143 if (ret != 1)
1144 break;
1145 } while (0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001146 /*Added by Amr - BugID_4720*/
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -07001147 up(p->txq_add_to_head_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001148
1149 p->txq_exit = 1;
1150 PRINT_D(TX_DBG, "THREAD: Exiting txq\n");
1151 /* return tx[]q count */
1152 *pu32TxqCount = p->txq_entries;
1153 return ret;
1154}
1155
1156static void wilc_wlan_handle_rxq(void)
1157{
1158 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1159 int offset = 0, size, has_packet = 0;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001160 u8 *buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001161 struct rxq_entry_t *rqe;
1162
1163 p->rxq_exit = 0;
1164
1165
1166
1167
1168 do {
1169 if (p->quit) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301170 PRINT_D(RX_DBG, "exit 1st do-while due to Clean_UP function\n");
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -07001171 up(p->cfg_wait);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001172 break;
1173 }
1174 rqe = wilc_wlan_rxq_remove();
1175 if (rqe == NULL) {
1176 PRINT_D(RX_DBG, "nothing in the queue - exit 1st do-while\n");
1177 break;
1178 }
1179 buffer = rqe->buffer;
1180 size = rqe->buffer_size;
1181 PRINT_D(RX_DBG, "rxQ entery Size = %d - Address = %p\n", size, buffer);
1182 offset = 0;
1183
1184
1185
1186 do {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001187 u32 header;
1188 u32 pkt_len, pkt_offset, tp_len;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001189 int is_cfg_packet;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001190
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001191 PRINT_D(RX_DBG, "In the 2nd do-while\n");
1192 memcpy(&header, &buffer[offset], 4);
1193#ifdef BIG_ENDIAN
1194 header = BYTE_SWAP(header);
1195#endif
1196 PRINT_D(RX_DBG, "Header = %04x - Offset = %d\n", header, offset);
1197
1198
1199
1200 is_cfg_packet = (header >> 31) & 0x1;
1201 pkt_offset = (header >> 22) & 0x1ff;
1202 tp_len = (header >> 11) & 0x7ff;
1203 pkt_len = header & 0x7ff;
1204
1205 if (pkt_len == 0 || tp_len == 0) {
1206 wilc_debug(N_RXQ, "[wilc rxq]: data corrupt, packet len or tp_len is 0 [%d][%d]\n", pkt_len, tp_len);
1207 break;
1208 }
1209
1210/*bug 3887: [AP] Allow Management frames to be passed to the host*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001211 #define IS_MANAGMEMENT 0x100
1212 #define IS_MANAGMEMENT_CALLBACK 0x080
1213 #define IS_MGMT_STATUS_SUCCES 0x040
1214
1215
1216 if (pkt_offset & IS_MANAGMEMENT) {
1217 /* reset mgmt indicator bit, to use pkt_offeset in furthur calculations */
1218 pkt_offset &= ~(IS_MANAGMEMENT | IS_MANAGMEMENT_CALLBACK | IS_MGMT_STATUS_SUCCES);
1219
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001220 WILC_WFI_mgmt_rx(&buffer[offset + HOST_HDR_OFFSET], pkt_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001221 }
1222 /* BUG4530 fix */
1223 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001224 {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001225
1226 if (!is_cfg_packet) {
1227
1228 if (p->net_func.rx_indicate) {
1229 if (pkt_len > 0) {
1230 p->net_func.rx_indicate(&buffer[offset], pkt_len, pkt_offset);
1231 has_packet = 1;
1232 }
1233 }
1234 } else {
1235 wilc_cfg_rsp_t rsp;
1236
1237
1238
1239 p->cif_func.rx_indicate(&buffer[pkt_offset + offset], pkt_len, &rsp);
1240 if (rsp.type == WILC_CFG_RSP) {
1241 /**
1242 * wake up the waiting task...
1243 **/
1244 PRINT_D(RX_DBG, "p->cfg_seq_no = %d - rsp.seq_no = %d\n", p->cfg_seq_no, rsp.seq_no);
1245 if (p->cfg_seq_no == rsp.seq_no) {
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -07001246 up(p->cfg_wait);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001247 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001248 } else if (rsp.type == WILC_CFG_RSP_STATUS) {
1249 /**
1250 * Call back to indicate status...
1251 **/
1252 if (p->indicate_func.mac_indicate) {
1253 p->indicate_func.mac_indicate(WILC_MAC_INDICATE_STATUS);
1254 }
1255
1256 } else if (rsp.type == WILC_CFG_RSP_SCAN) {
1257 if (p->indicate_func.mac_indicate)
1258 p->indicate_func.mac_indicate(WILC_MAC_INDICATE_SCAN);
1259 }
1260 }
1261 }
1262 offset += tp_len;
1263 if (offset >= size)
1264 break;
1265 } while (1);
1266
1267
1268#ifndef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001269 kfree(buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001270#endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001271 kfree(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001272
1273 if (has_packet) {
1274 if (p->net_func.rx_complete)
1275 p->net_func.rx_complete();
1276 }
1277 } while (1);
1278
1279 p->rxq_exit = 1;
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301280 PRINT_D(RX_DBG, "THREAD: Exiting RX thread\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001281}
1282
1283/********************************************
1284 *
1285 * Fast DMA Isr
1286 *
1287 ********************************************/
1288static void wilc_unknown_isr_ext(void)
1289{
1290 g_wlan.hif_func.hif_clear_int_ext(0);
1291}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001292static void wilc_pllupdate_isr_ext(u32 int_stats)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001293{
1294
1295 int trials = 10;
1296
1297 g_wlan.hif_func.hif_clear_int_ext(PLL_INT_CLR);
1298
1299 /* Waiting for PLL */
Greg Kroah-Hartmanc2e4c0f2015-09-03 19:09:50 -07001300 mdelay(WILC_PLL_TO);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001301
1302 /* poll till read a valid data */
Dean Lee72ed4dc2015-06-12 14:11:44 +09001303 while (!(ISWILC1000(wilc_get_chipid(true)) && --trials)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001304 PRINT_D(TX_DBG, "PLL update retrying\n");
Greg Kroah-Hartmanc2e4c0f2015-09-03 19:09:50 -07001305 mdelay(1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001306 }
1307}
1308
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001309static void wilc_sleeptimer_isr_ext(u32 int_stats1)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001310{
1311 g_wlan.hif_func.hif_clear_int_ext(SLEEP_INT_CLR);
1312#ifndef WILC_OPTIMIZE_SLEEP_INT
1313 genuChipPSstate = CHIP_SLEEPING_AUTO;
1314#endif
1315}
1316
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001317static void wilc_wlan_handle_isr_ext(u32 int_status)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001318{
1319 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1320#ifdef MEMORY_STATIC
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001321 u32 offset = p->rx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001322#endif
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001323 u8 *buffer = NULL;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001324 u32 size;
1325 u32 retries = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001326 int ret = 0;
1327 struct rxq_entry_t *rqe;
1328
1329
1330 /**
1331 * Get the rx size
1332 **/
1333
1334 size = ((int_status & 0x7fff) << 2);
1335
1336 while (!size && retries < 10) {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001337 u32 time = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001338 /*looping more secure*/
1339 /*zero size make a crashe because the dma will not happen and that will block the firmware*/
1340 wilc_debug(N_ERR, "RX Size equal zero ... Trying to read it again for %d time\n", time++);
1341 p->hif_func.hif_read_size(&size);
1342 size = ((size & 0x7fff) << 2);
1343 retries++;
1344
1345 }
1346
1347 if (size > 0) {
1348#ifdef MEMORY_STATIC
1349 if (p->rx_buffer_size - offset < size)
1350 offset = 0;
1351
1352 if (p->rx_buffer)
1353 buffer = &p->rx_buffer[offset];
1354 else {
1355 wilc_debug(N_ERR, "[wilc isr]: fail Rx Buffer is NULL...drop the packets (%d)\n", size);
1356 goto _end_;
1357 }
1358
1359#else
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001360 buffer = kmalloc(size, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001361 if (buffer == NULL) {
1362 wilc_debug(N_ERR, "[wilc isr]: fail alloc host memory...drop the packets (%d)\n", size);
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -07001363 usleep_range(100 * 1000, 100 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001364 goto _end_;
1365 }
1366#endif
1367
1368 /**
1369 * clear the chip's interrupt after getting size some register getting corrupted after clear the interrupt
1370 **/
1371 p->hif_func.hif_clear_int_ext(DATA_INT_CLR | ENABLE_RX_VMM);
1372
1373
1374 /**
1375 * start transfer
1376 **/
1377 ret = p->hif_func.hif_block_rx_ext(0, buffer, size);
1378
1379 if (!ret) {
1380 wilc_debug(N_ERR, "[wilc isr]: fail block rx...\n");
1381 goto _end_;
1382 }
1383_end_:
1384
1385
1386 if (ret) {
1387#ifdef MEMORY_STATIC
1388 offset += size;
1389 p->rx_buffer_offset = offset;
1390#endif
1391 /**
1392 * add to rx queue
1393 **/
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001394 rqe = kmalloc(sizeof(struct rxq_entry_t), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001395 if (rqe != NULL) {
1396 rqe->buffer = buffer;
1397 rqe->buffer_size = size;
1398 PRINT_D(RX_DBG, "rxq entery Size= %d - Address = %p\n", rqe->buffer_size, rqe->buffer);
1399 wilc_wlan_rxq_add(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001400 }
1401 } else {
1402#ifndef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001403 kfree(buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001404#endif
1405 }
1406 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001407 wilc_wlan_handle_rxq();
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001408}
1409
1410void wilc_handle_isr(void)
1411{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001412 u32 int_status;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001413
1414 acquire_bus(ACQUIRE_AND_WAKEUP);
1415 g_wlan.hif_func.hif_read_int(&int_status);
1416
1417 if (int_status & PLL_INT_EXT) {
1418 wilc_pllupdate_isr_ext(int_status);
1419 }
1420 if (int_status & DATA_INT_EXT) {
1421 wilc_wlan_handle_isr_ext(int_status);
1422 #ifndef WILC_OPTIMIZE_SLEEP_INT
1423 /* Chip is up and talking*/
1424 genuChipPSstate = CHIP_WAKEDUP;
1425 #endif
1426 }
1427 if (int_status & SLEEP_INT_EXT) {
1428 wilc_sleeptimer_isr_ext(int_status);
1429 }
1430
1431 if (!(int_status & (ALL_INT_EXT))) {
1432#ifdef WILC_SDIO
1433 PRINT_D(TX_DBG, ">> UNKNOWN_INTERRUPT - 0x%08x\n", int_status);
1434#endif
1435 wilc_unknown_isr_ext();
1436 }
1437#if ((!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO))
1438 linux_wlan_enable_irq();
1439#endif
1440 release_bus(RELEASE_ALLOW_SLEEP);
1441}
1442
1443/********************************************
1444 *
1445 * Firmware download
1446 *
1447 ********************************************/
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001448static int wilc_wlan_firmware_download(const u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001449{
1450 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001451 u32 offset;
1452 u32 addr, size, size2, blksz;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001453 u8 *dma_buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001454 int ret = 0;
1455
1456 blksz = (1ul << 12); /* Bug 4703: 4KB Good enough size for most platforms = PAGE_SIZE. */
1457 /* Allocate a DMA coherent buffer. */
1458
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001459 dma_buffer = kmalloc(blksz, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001460 if (dma_buffer == NULL) {
1461 /*EIO 5*/
1462 ret = -5;
1463 PRINT_ER("Can't allocate buffer for firmware download IO error\n ");
1464 goto _fail_1;
1465 }
1466
1467 PRINT_D(INIT_DBG, "Downloading firmware size = %d ...\n", buffer_size);
1468 /**
1469 * load the firmware
1470 **/
1471 offset = 0;
1472 do {
1473 memcpy(&addr, &buffer[offset], 4);
1474 memcpy(&size, &buffer[offset + 4], 4);
1475#ifdef BIG_ENDIAN
1476 addr = BYTE_SWAP(addr);
1477 size = BYTE_SWAP(size);
1478#endif
1479 acquire_bus(ACQUIRE_ONLY);
1480 offset += 8;
1481 while (((int)size) && (offset < buffer_size)) {
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301482 if (size <= blksz)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001483 size2 = size;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301484 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001485 size2 = blksz;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001486 /* Copy firmware into a DMA coherent buffer */
1487 memcpy(dma_buffer, &buffer[offset], size2);
1488 ret = p->hif_func.hif_block_tx(addr, dma_buffer, size2);
1489 if (!ret)
1490 break;
1491
1492 addr += size2;
1493 offset += size2;
1494 size -= size2;
1495 }
1496 release_bus(RELEASE_ONLY);
1497
1498 if (!ret) {
1499 /*EIO 5*/
1500 ret = -5;
1501 PRINT_ER("Can't download firmware IO error\n ");
1502 goto _fail_;
1503 }
1504 PRINT_D(INIT_DBG, "Offset = %d\n", offset);
1505 } while (offset < buffer_size);
1506
1507_fail_:
1508
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001509 kfree(dma_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001510
1511_fail_1:
1512
1513 return (ret < 0) ? ret : 0;
1514}
1515
1516/********************************************
1517 *
1518 * Common
1519 *
1520 ********************************************/
1521static int wilc_wlan_start(void)
1522{
1523 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001524 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001525 int ret;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001526 u32 chipid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001527
1528 /**
1529 * Set the host interface
1530 **/
1531#ifdef OLD_FPGA_BITFILE
1532 acquire_bus(ACQUIRE_ONLY);
1533 ret = p->hif_func.hif_read_reg(WILC_VMM_CORE_CTL, &reg);
1534 if (!ret) {
1535 wilc_debug(N_ERR, "[wilc start]: fail read reg vmm_core_ctl...\n");
1536 release_bus(RELEASE_ALLOW_SLEEP);
1537 return ret;
1538 }
1539 reg |= (p->io_func.io_type << 2);
1540 ret = p->hif_func.hif_write_reg(WILC_VMM_CORE_CTL, reg);
1541 if (!ret) {
1542 wilc_debug(N_ERR, "[wilc start]: fail write reg vmm_core_ctl...\n");
1543 release_bus(RELEASE_ONLY);
1544 return ret;
1545 }
1546#else
1547 if (p->io_func.io_type == HIF_SDIO) {
1548 reg = 0;
1549 reg |= (1 << 3); /* bug 4456 and 4557 */
1550 } else if (p->io_func.io_type == HIF_SPI) {
1551 reg = 1;
1552 }
1553 acquire_bus(ACQUIRE_ONLY);
1554 ret = p->hif_func.hif_write_reg(WILC_VMM_CORE_CFG, reg);
1555 if (!ret) {
1556 wilc_debug(N_ERR, "[wilc start]: fail write reg vmm_core_cfg...\n");
1557 release_bus(RELEASE_ONLY);
1558 /* EIO 5*/
1559 ret = -5;
1560 return ret;
1561 }
1562 reg = 0;
1563#ifdef WILC_SDIO_IRQ_GPIO
1564 reg |= WILC_HAVE_SDIO_IRQ_GPIO;
1565#endif
1566
1567#ifdef WILC_DISABLE_PMU
1568#else
1569 reg |= WILC_HAVE_USE_PMU;
1570#endif
1571
1572#ifdef WILC_SLEEP_CLK_SRC_XO
1573 reg |= WILC_HAVE_SLEEP_CLK_SRC_XO;
1574#elif defined WILC_SLEEP_CLK_SRC_RTC
1575 reg |= WILC_HAVE_SLEEP_CLK_SRC_RTC;
1576#endif
1577
1578#ifdef WILC_EXT_PA_INV_TX_RX
1579 reg |= WILC_HAVE_EXT_PA_INV_TX_RX;
1580#endif
1581
1582 reg |= WILC_HAVE_LEGACY_RF_SETTINGS;
1583
1584
1585/*BugID_5257*/
1586/*Set oscillator frequency*/
1587#ifdef XTAL_24
1588 reg |= WILC_HAVE_XTAL_24;
1589#endif
1590
1591/*BugID_5271*/
1592/*Enable/Disable GPIO configuration for FW logs*/
1593#ifdef DISABLE_WILC_UART
1594 reg |= WILC_HAVE_DISABLE_WILC_UART;
1595#endif
1596
1597 ret = p->hif_func.hif_write_reg(WILC_GP_REG_1, reg);
1598 if (!ret) {
1599 wilc_debug(N_ERR, "[wilc start]: fail write WILC_GP_REG_1 ...\n");
1600 release_bus(RELEASE_ONLY);
1601 /* EIO 5*/
1602 ret = -5;
1603 return ret;
1604 }
1605#endif
1606
1607
1608 /**
1609 * Bus related
1610 **/
1611 p->hif_func.hif_sync_ext(NUM_INT_EXT);
1612
1613 ret = p->hif_func.hif_read_reg(0x1000, &chipid);
1614 if (!ret) {
1615 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1000 ...\n");
1616 release_bus(RELEASE_ONLY);
1617 /* EIO 5*/
1618 ret = -5;
1619 return ret;
1620 }
1621
1622 /**
1623 * Go...
1624 **/
1625
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001626
1627 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1628 if ((reg & (1ul << 10)) == (1ul << 10)) {
1629 reg &= ~(1ul << 10);
1630 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1631 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1632 }
1633
1634 reg |= (1ul << 10);
1635 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1636 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1637 release_bus(RELEASE_ONLY);
1638
1639 return (ret < 0) ? ret : 0;
1640}
1641
1642void wilc_wlan_global_reset(void)
1643{
1644
1645 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001646
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001647 acquire_bus(ACQUIRE_AND_WAKEUP);
1648 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, 0x0);
1649 release_bus(RELEASE_ONLY);
1650}
1651static int wilc_wlan_stop(void)
1652{
1653 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001654 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001655 int ret;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001656 u8 timeout = 10;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001657 /**
1658 * TODO: stop the firmware, need a re-download
1659 **/
1660 acquire_bus(ACQUIRE_AND_WAKEUP);
1661
1662 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1663 if (!ret) {
1664 PRINT_ER("Error while reading reg\n");
1665 release_bus(RELEASE_ALLOW_SLEEP);
1666 return ret;
1667 }
1668
1669 reg &= ~(1 << 10);
1670
1671
1672 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1673 if (!ret) {
1674 PRINT_ER("Error while writing reg\n");
1675 release_bus(RELEASE_ALLOW_SLEEP);
1676 return ret;
1677 }
1678
1679
1680
1681 do {
1682 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1683 if (!ret) {
1684 PRINT_ER("Error while reading reg\n");
1685 release_bus(RELEASE_ALLOW_SLEEP);
1686 return ret;
1687 }
1688 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1689 /*Workaround to ensure that the chip is actually reset*/
1690 if ((reg & (1 << 10))) {
1691 PRINT_D(GENERIC_DBG, "Bit 10 not reset : Retry %d\n", timeout);
1692 reg &= ~(1 << 10);
1693 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1694 timeout--;
1695 } else {
1696 PRINT_D(GENERIC_DBG, "Bit 10 reset after : Retry %d\n", timeout);
1697 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1698 if (!ret) {
1699 PRINT_ER("Error while reading reg\n");
1700 release_bus(RELEASE_ALLOW_SLEEP);
1701 return ret;
1702 }
1703 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1704 break;
1705 }
1706
1707 } while (timeout);
1708#if 1
1709/******************************************************************************/
1710/* This was add at Bug 4595 to reset the chip while maintaining the bus state */
1711/******************************************************************************/
1712 reg = ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 8) | (1 << 9) | (1 << 26) | (1 << 29) | (1 << 30) | (1 << 31)); /**/
1713 /**/
Hari Prasath Gujulan Elango369f1902015-06-22 07:04:39 +00001714 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); /**/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001715 reg = ~(1 << 10); /**/
1716 /**/
1717 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); /**/
1718/******************************************************************************/
1719#endif
1720
1721 release_bus(RELEASE_ALLOW_SLEEP);
1722
1723 return ret;
1724}
1725
1726static void wilc_wlan_cleanup(void)
1727{
1728 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1729 struct txq_entry_t *tqe;
1730 struct rxq_entry_t *rqe;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001731 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001732 int ret;
1733
1734 p->quit = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001735 do {
1736 tqe = wilc_wlan_txq_remove_from_head();
1737 if (tqe == NULL)
1738 break;
1739 if (tqe->tx_complete_func)
1740 tqe->tx_complete_func(tqe->priv, 0);
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001741 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001742 } while (1);
1743
1744 do {
1745 rqe = wilc_wlan_rxq_remove();
1746 if (rqe == NULL)
1747 break;
1748#ifdef MEMORY_DYNAMIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001749 kfree(tqe->buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001750#endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001751 kfree(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001752 } while (1);
1753
1754 /**
1755 * clean up buffer
1756 **/
1757
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001758 #ifdef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001759 kfree(p->rx_buffer);
1760 p->rx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001761 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001762 kfree(p->tx_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001763
1764 acquire_bus(ACQUIRE_AND_WAKEUP);
1765
1766
1767 ret = p->hif_func.hif_read_reg(WILC_GP_REG_0, &reg);
1768 if (!ret) {
1769 PRINT_ER("Error while reading reg\n");
1770 release_bus(RELEASE_ALLOW_SLEEP);
1771 }
1772 PRINT_ER("Writing ABORT reg\n");
1773 ret = p->hif_func.hif_write_reg(WILC_GP_REG_0, (reg | ABORT_INT));
1774 if (!ret) {
1775 PRINT_ER("Error while writing reg\n");
1776 release_bus(RELEASE_ALLOW_SLEEP);
1777 }
1778 release_bus(RELEASE_ALLOW_SLEEP);
1779 /**
1780 * io clean up
1781 **/
1782 p->hif_func.hif_deinit(NULL);
1783
1784}
1785
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001786static int wilc_wlan_cfg_commit(int type, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001787{
1788 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1789 wilc_cfg_frame_t *cfg = &p->cfg_frame;
1790 int total_len = p->cfg_frame_offset + 4 + DRIVER_HANDLER_SIZE;
1791 int seq_no = p->cfg_seq_no % 256;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001792 int driver_handler = (u32)drvHandler;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001793
1794
1795 /**
1796 * Set up header
1797 **/
1798 if (type == WILC_CFG_SET) { /* Set */
1799 cfg->wid_header[0] = 'W';
1800 } else { /* Query */
1801 cfg->wid_header[0] = 'Q';
1802 }
1803 cfg->wid_header[1] = seq_no; /* sequence number */
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001804 cfg->wid_header[2] = (u8)total_len;
1805 cfg->wid_header[3] = (u8)(total_len >> 8);
1806 cfg->wid_header[4] = (u8)driver_handler;
1807 cfg->wid_header[5] = (u8)(driver_handler >> 8);
1808 cfg->wid_header[6] = (u8)(driver_handler >> 16);
1809 cfg->wid_header[7] = (u8)(driver_handler >> 24);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001810 p->cfg_seq_no = seq_no;
1811
1812 /**
1813 * Add to TX queue
1814 **/
1815
1816 /*Edited by Amr - BugID_4720*/
1817 if (!wilc_wlan_txq_add_cfg_pkt(&cfg->wid_header[0], total_len))
1818 return -1;
1819
1820 return 0;
1821}
1822
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001823static 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 +09001824{
1825 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001826 u32 offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001827 int ret_size;
1828
1829
1830 if (p->cfg_frame_in_use)
1831 return 0;
1832
1833 if (start)
1834 p->cfg_frame_offset = 0;
1835
1836 offset = p->cfg_frame_offset;
Chaehyun Limec53adf2015-09-15 14:06:15 +09001837 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 +09001838 offset += ret_size;
1839 p->cfg_frame_offset = offset;
1840
1841 if (commit) {
1842 PRINT_D(TX_DBG, "[WILC]PACKET Commit with sequence number %d\n", p->cfg_seq_no);
1843 PRINT_D(RX_DBG, "Processing cfg_set()\n");
1844 p->cfg_frame_in_use = 1;
1845
1846 /*Edited by Amr - BugID_4720*/
1847 if (wilc_wlan_cfg_commit(WILC_CFG_SET, drvHandler))
1848 ret_size = 0; /* BugID_5213 */
1849
1850 if (p->os_func.os_wait(p->cfg_wait, CFG_PKTS_TIMEOUT)) {
1851 PRINT_D(TX_DBG, "Set Timed Out\n");
1852 ret_size = 0;
1853 }
1854 p->cfg_frame_in_use = 0;
1855 p->cfg_frame_offset = 0;
1856 p->cfg_seq_no += 1;
1857
1858 }
1859
1860 return ret_size;
1861}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001862static int wilc_wlan_cfg_get(int start, u32 wid, int commit, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001863{
1864 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001865 u32 offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001866 int ret_size;
1867
1868
1869 if (p->cfg_frame_in_use)
1870 return 0;
1871
1872 if (start)
1873 p->cfg_frame_offset = 0;
1874
1875 offset = p->cfg_frame_offset;
Chaehyun Limec53adf2015-09-15 14:06:15 +09001876 ret_size = p->cif_func.cfg_wid_get(p->cfg_frame.frame, offset, (u16)wid);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001877 offset += ret_size;
1878 p->cfg_frame_offset = offset;
1879
1880 if (commit) {
1881 p->cfg_frame_in_use = 1;
1882
1883 /*Edited by Amr - BugID_4720*/
1884 if (wilc_wlan_cfg_commit(WILC_CFG_QUERY, drvHandler))
1885 ret_size = 0; /* BugID_5213 */
1886
1887
1888 if (p->os_func.os_wait(p->cfg_wait, CFG_PKTS_TIMEOUT)) {
1889 PRINT_D(TX_DBG, "Get Timed Out\n");
1890 ret_size = 0;
1891 }
1892 PRINT_D(GENERIC_DBG, "[WILC]Get Response received\n");
1893 p->cfg_frame_in_use = 0;
1894 p->cfg_frame_offset = 0;
1895 p->cfg_seq_no += 1;
1896 }
1897
1898 return ret_size;
1899}
1900
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001901static int wilc_wlan_cfg_get_val(u32 wid, u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001902{
1903 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1904 int ret;
1905
Chaehyun Limec53adf2015-09-15 14:06:15 +09001906 ret = p->cif_func.cfg_wid_get_val((u16)wid, buffer, buffer_size);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001907
1908 return ret;
1909}
1910
1911void wilc_bus_set_max_speed(void)
1912{
1913
1914 /* Increase bus speed to max possible. */
1915 g_wlan.hif_func.hif_set_max_bus_speed();
1916}
1917
1918void wilc_bus_set_default_speed(void)
1919{
1920
1921 /* Restore bus speed to default. */
1922 g_wlan.hif_func.hif_set_default_bus_speed();
1923}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001924u32 init_chip(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001925{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001926 u32 chipid;
1927 u32 reg, ret = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001928
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001929 acquire_bus(ACQUIRE_ONLY);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001930
Dean Lee72ed4dc2015-06-12 14:11:44 +09001931 chipid = wilc_get_chipid(true);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001932
1933
1934
1935 if ((chipid & 0xfff) != 0xa0) {
1936 /**
1937 * Avoid booting from boot ROM. Make sure that Drive IRQN [SDIO platform]
1938 * or SD_DAT3 [SPI platform] to ?1?
1939 **/
1940 /* Set cortus reset register to register control. */
1941 ret = g_wlan.hif_func.hif_read_reg(0x1118, &reg);
1942 if (!ret) {
1943 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1118 ...\n");
1944 return ret;
1945 }
1946 reg |= (1 << 0);
1947 ret = g_wlan.hif_func.hif_write_reg(0x1118, reg);
1948 if (!ret) {
1949 wilc_debug(N_ERR, "[wilc start]: fail write reg 0x1118 ...\n");
1950 return ret;
1951 }
1952 /**
1953 * Write branch intruction to IRAM (0x71 trap) at location 0xFFFF0000
1954 * (Cortus map) or C0000 (AHB map).
1955 **/
1956 ret = g_wlan.hif_func.hif_write_reg(0xc0000, 0x71);
1957 if (!ret) {
1958 wilc_debug(N_ERR, "[wilc start]: fail write reg 0xc0000 ...\n");
1959 return ret;
1960 }
1961 }
1962
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001963 release_bus(RELEASE_ONLY);
1964
1965 return ret;
1966
1967}
1968
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001969u32 wilc_get_chipid(u8 update)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001970{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001971 static u32 chipid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001972 /* SDIO can't read into global variables */
1973 /* Use this variable as a temp, then copy to the global */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001974 u32 tempchipid = 0;
1975 u32 rfrevid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001976
1977 if (chipid == 0 || update != 0) {
1978 g_wlan.hif_func.hif_read_reg(0x1000, &tempchipid);
1979 g_wlan.hif_func.hif_read_reg(0x13f4, &rfrevid);
1980 if (!ISWILC1000(tempchipid)) {
1981 chipid = 0;
1982 goto _fail_;
1983 }
1984 if (tempchipid == 0x1002a0) {
1985 if (rfrevid == 0x1) { /* 1002A0 */
1986 } else { /* if (rfrevid == 0x2) */ /* 1002A1 */
1987 tempchipid = 0x1002a1;
1988 }
1989 } else if (tempchipid == 0x1002b0) {
1990 if (rfrevid == 3) { /* 1002B0 */
1991 } else if (rfrevid == 4) { /* 1002B1 */
1992 tempchipid = 0x1002b1;
1993 } else { /* if(rfrevid == 5) */ /* 1002B2 */
1994 tempchipid = 0x1002b2;
1995 }
1996 } else {
1997 }
1998
1999 chipid = tempchipid;
2000 }
2001_fail_:
2002 return chipid;
2003}
2004
2005#ifdef COMPLEMENT_BOOT
Chaehyun Lim51e825f2015-09-15 14:06:14 +09002006u8 core_11b_ready(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002007{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09002008 u32 reg_val;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002009
2010 acquire_bus(ACQUIRE_ONLY);
2011 g_wlan.hif_func.hif_write_reg(0x16082c, 1);
2012 g_wlan.hif_func.hif_write_reg(0x161600, 0x90);
2013 g_wlan.hif_func.hif_read_reg(0x161600, &reg_val);
2014 release_bus(RELEASE_ONLY);
2015
2016 if (reg_val == 0x90)
2017 return 0;
2018 else
2019 return 1;
2020}
2021#endif
2022
2023int wilc_wlan_init(wilc_wlan_inp_t *inp, wilc_wlan_oup_t *oup)
2024{
2025
2026 int ret = 0;
2027
2028 PRINT_D(INIT_DBG, "Initializing WILC_Wlan ...\n");
2029
2030 memset((void *)&g_wlan, 0, sizeof(wilc_wlan_dev_t));
2031
2032 /**
2033 * store the input
2034 **/
2035 memcpy((void *)&g_wlan.os_func, (void *)&inp->os_func, sizeof(wilc_wlan_os_func_t));
2036 memcpy((void *)&g_wlan.io_func, (void *)&inp->io_func, sizeof(wilc_wlan_io_func_t));
2037 memcpy((void *)&g_wlan.net_func, (void *)&inp->net_func, sizeof(wilc_wlan_net_func_t));
2038 memcpy((void *)&g_wlan.indicate_func, (void *)&inp->indicate_func, sizeof(wilc_wlan_net_func_t));
2039 g_wlan.hif_lock = inp->os_context.hif_critical_section;
2040 g_wlan.txq_lock = inp->os_context.txq_critical_section;
2041
2042 /*Added by Amr - BugID_4720*/
2043 g_wlan.txq_add_to_head_lock = inp->os_context.txq_add_to_head_critical_section;
2044
2045 /*Added by Amr - BugID_4720*/
2046 g_wlan.txq_spinlock = inp->os_context.txq_spin_lock;
2047
2048 g_wlan.rxq_lock = inp->os_context.rxq_critical_section;
2049 g_wlan.txq_wait = inp->os_context.txq_wait_event;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002050 g_wlan.cfg_wait = inp->os_context.cfg_wait_event;
2051 g_wlan.tx_buffer_size = inp->os_context.tx_buffer_size;
2052#if defined (MEMORY_STATIC)
2053 g_wlan.rx_buffer_size = inp->os_context.rx_buffer_size;
2054#endif
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002055 /***
2056 * host interface init
2057 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002058 if ((inp->io_func.io_type & 0x1) == HIF_SDIO) {
2059 if (!hif_sdio.hif_init(inp, wilc_debug)) {
2060 /* EIO 5 */
2061 ret = -5;
2062 goto _fail_;
2063 }
2064 memcpy((void *)&g_wlan.hif_func, &hif_sdio, sizeof(wilc_hif_func_t));
2065 } else {
2066 if ((inp->io_func.io_type & 0x1) == HIF_SPI) {
2067 /**
2068 * TODO:
2069 **/
2070 if (!hif_spi.hif_init(inp, wilc_debug)) {
2071 /* EIO 5 */
2072 ret = -5;
2073 goto _fail_;
2074 }
2075 memcpy((void *)&g_wlan.hif_func, &hif_spi, sizeof(wilc_hif_func_t));
2076 } else {
2077 /* EIO 5 */
2078 ret = -5;
2079 goto _fail_;
2080 }
2081 }
2082
2083 /***
2084 * mac interface init
2085 **/
2086 if (!mac_cfg.cfg_init(wilc_debug)) {
2087 /* ENOBUFS 105 */
2088 ret = -105;
2089 goto _fail_;
2090 }
2091 memcpy((void *)&g_wlan.cif_func, &mac_cfg, sizeof(wilc_cfg_func_t));
2092
2093
2094 /**
2095 * alloc tx, rx buffer
2096 **/
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002097 if (g_wlan.tx_buffer == NULL)
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07002098 g_wlan.tx_buffer = kmalloc(g_wlan.tx_buffer_size, GFP_KERNEL);
Arnd Bergmann7a8fd842015-06-01 21:06:45 +02002099 PRINT_D(TX_DBG, "g_wlan.tx_buffer = %p\n", g_wlan.tx_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002100
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002101 if (g_wlan.tx_buffer == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002102 /* ENOBUFS 105 */
2103 ret = -105;
2104 PRINT_ER("Can't allocate Tx Buffer");
2105 goto _fail_;
2106 }
2107
2108/* rx_buffer is not used unless we activate USE_MEM STATIC which is not applicable, allocating such memory is useless*/
2109#if defined (MEMORY_STATIC)
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002110 if (g_wlan.rx_buffer == NULL)
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07002111 g_wlan.rx_buffer = kmalloc(g_wlan.rx_buffer_size, GFP_KERNEL);
Arnd Bergmann7a8fd842015-06-01 21:06:45 +02002112 PRINT_D(TX_DBG, "g_wlan.rx_buffer =%p\n", g_wlan.rx_buffer);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002113 if (g_wlan.rx_buffer == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002114 /* ENOBUFS 105 */
2115 ret = -105;
2116 PRINT_ER("Can't allocate Rx Buffer");
2117 goto _fail_;
2118 }
2119#endif
2120
2121 /**
2122 * export functions
2123 **/
2124 oup->wlan_firmware_download = wilc_wlan_firmware_download;
2125 oup->wlan_start = wilc_wlan_start;
2126 oup->wlan_stop = wilc_wlan_stop;
2127 oup->wlan_add_to_tx_que = wilc_wlan_txq_add_net_pkt;
2128 oup->wlan_handle_tx_que = wilc_wlan_handle_txq;
2129 oup->wlan_handle_rx_que = wilc_wlan_handle_rxq;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002130 oup->wlan_handle_rx_isr = wilc_handle_isr;
2131 oup->wlan_cleanup = wilc_wlan_cleanup;
2132 oup->wlan_cfg_set = wilc_wlan_cfg_set;
2133 oup->wlan_cfg_get = wilc_wlan_cfg_get;
2134 oup->wlan_cfg_get_value = wilc_wlan_cfg_get_val;
2135
2136 /*Bug3959: transmitting mgmt frames received from host*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002137 oup->wlan_add_mgmt_to_tx_que = wilc_wlan_txq_add_mgmt_pkt;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002138
2139 if (!init_chip()) {
2140 /* EIO 5 */
2141 ret = -5;
2142 goto _fail_;
2143 }
2144#ifdef TCP_ACK_FILTER
2145 Init_TCP_tracking();
2146#endif
2147
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002148 return 1;
2149
2150_fail_:
2151
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002152 #ifdef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07002153 kfree(g_wlan.rx_buffer);
2154 g_wlan.rx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002155 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07002156 kfree(g_wlan.tx_buffer);
2157 g_wlan.tx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002158
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002159 return ret;
2160
2161}
2162
Dean Lee72ed4dc2015-06-12 14:11:44 +09002163u16 Set_machw_change_vir_if(bool bValue)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002164{
Chaehyun Limd85f5322015-06-11 14:35:54 +09002165 u16 ret;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002166 u32 reg;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002167
2168 /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -07002169 mutex_lock((&g_wlan)->hif_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002170 ret = (&g_wlan)->hif_func.hif_read_reg(WILC_CHANGING_VIR_IF, &reg);
2171 if (!ret) {
2172 PRINT_ER("Error while Reading reg WILC_CHANGING_VIR_IF\n");
2173 }
2174
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05302175 if (bValue)
Chaehyun Lim50b51da2015-09-16 20:11:26 +09002176 reg |= BIT(31);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05302177 else
Chaehyun Lim50b51da2015-09-16 20:11:26 +09002178 reg &= ~BIT(31);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002179
2180 ret = (&g_wlan)->hif_func.hif_write_reg(WILC_CHANGING_VIR_IF, reg);
2181
2182 if (!ret) {
2183 PRINT_ER("Error while writing reg WILC_CHANGING_VIR_IF\n");
2184 }
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -07002185 mutex_unlock((&g_wlan)->hif_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002186
2187 return ret;
2188}