blob: fac16db5ff6a296ec00644434a4b01d5238d4ef3 [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;
22#if defined(PLAT_RK3026_TCHIP)
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +090023extern u8 g_wilc_initialized; /* AMR : 0422 RK3026 Crash issue */
Johnny Kimc5c77ba2015-05-11 14:30:56 +090024#endif
25extern void WILC_WFI_mgmt_rx(uint8_t *buff, uint32_t size);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090026uint32_t wilc_get_chipid(uint8_t update);
Dean Lee72ed4dc2015-06-12 14:11:44 +090027u16 Set_machw_change_vir_if(bool bValue);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090028
Johnny Kimc5c77ba2015-05-11 14:30:56 +090029
30
31typedef struct {
32 int quit;
33
34 /**
35 * input interface functions
36 **/
37 wilc_wlan_os_func_t os_func;
38 wilc_wlan_io_func_t io_func;
39 wilc_wlan_net_func_t net_func;
40 wilc_wlan_indicate_func_t indicate_func;
41
42 /**
43 * host interface functions
44 **/
45 wilc_hif_func_t hif_func;
46 void *hif_lock;
47
48 /**
49 * configuration interface functions
50 **/
51 wilc_cfg_func_t cif_func;
52 int cfg_frame_in_use;
53 wilc_cfg_frame_t cfg_frame;
54 uint32_t cfg_frame_offset;
55 int cfg_seq_no;
56 void *cfg_wait;
57
58 /**
59 * RX buffer
60 **/
61 #ifdef MEMORY_STATIC
62 uint32_t rx_buffer_size;
63 uint8_t *rx_buffer;
64 uint32_t rx_buffer_offset;
65 #endif
66 /**
67 * TX buffer
68 **/
69 uint32_t tx_buffer_size;
70 uint8_t *tx_buffer;
71 uint32_t tx_buffer_offset;
72
73 /**
74 * TX queue
75 **/
76 void *txq_lock;
77
78 /*Added by Amr - BugID_4720*/
79 void *txq_add_to_head_lock;
80 void *txq_spinlock;
81 unsigned long txq_spinlock_flags;
82
83 struct txq_entry_t *txq_head;
84 struct txq_entry_t *txq_tail;
85 int txq_entries;
86 void *txq_wait;
87 int txq_exit;
88
89 /**
90 * RX queue
91 **/
92 void *rxq_lock;
93 struct rxq_entry_t *rxq_head;
94 struct rxq_entry_t *rxq_tail;
95 int rxq_entries;
96 void *rxq_wait;
97 int rxq_exit;
98
99
100} wilc_wlan_dev_t;
101
102static wilc_wlan_dev_t g_wlan;
103
104INLINE void chip_allow_sleep(void);
105INLINE void chip_wakeup(void);
106/********************************************
107 *
108 * Debug
109 *
110 ********************************************/
111
112static uint32_t dbgflag = N_INIT | N_ERR | N_INTR | N_TXQ | N_RXQ;
113
114static void wilc_debug(uint32_t flag, char *fmt, ...)
115{
116 char buf[256];
117 va_list args;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900118
119 if (flag & dbgflag) {
120 va_start(args, fmt);
Hari Prasath Gujulan Elango81053222015-06-22 13:13:58 +0000121 vsprintf(buf, fmt, args);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900122 va_end(args);
123
124 if (g_wlan.os_func.os_debug)
125 g_wlan.os_func.os_debug(buf);
126 }
127
128 return;
129}
130
131static CHIP_PS_STATE_T genuChipPSstate = CHIP_WAKEDUP;
132
133/*BugID_5213*/
134/*acquire_bus() and release_bus() are made INLINE functions*/
135/*as a temporary workaround to fix a problem of receiving*/
136/*unknown interrupt from FW*/
137INLINE void acquire_bus(BUS_ACQUIRE_T acquire)
138{
139
140 g_wlan.os_func.os_enter_cs(g_wlan.hif_lock);
141 #ifndef WILC_OPTIMIZE_SLEEP_INT
142 if (genuChipPSstate != CHIP_WAKEDUP)
143 #endif
144 {
145 if (acquire == ACQUIRE_AND_WAKEUP)
146 chip_wakeup();
147 }
148
149}
150INLINE void release_bus(BUS_RELEASE_T release)
151{
152 #ifdef WILC_OPTIMIZE_SLEEP_INT
153 if (release == RELEASE_ALLOW_SLEEP)
154 chip_allow_sleep();
155 #endif
156 g_wlan.os_func.os_leave_cs(g_wlan.hif_lock);
157}
158/********************************************
159 *
160 * Queue
161 *
162 ********************************************/
163
164static void wilc_wlan_txq_remove(struct txq_entry_t *tqe)
165{
166
167 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
168 /* unsigned long flags; */
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900169 if (tqe == p->txq_head) {
170
171 p->txq_head = tqe->next;
172 if (p->txq_head)
173 p->txq_head->prev = NULL;
174
175
176 } else if (tqe == p->txq_tail) {
177 p->txq_tail = (tqe->prev);
178 if (p->txq_tail)
179 p->txq_tail->next = NULL;
180 } else {
181 tqe->prev->next = tqe->next;
182 tqe->next->prev = tqe->prev;
183 }
184 p->txq_entries -= 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900185
186}
187
188static struct txq_entry_t *wilc_wlan_txq_remove_from_head(void)
189{
190 struct txq_entry_t *tqe;
191 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
192 unsigned long flags;
193 p->os_func.os_spin_lock(p->txq_spinlock, &flags);
194 if (p->txq_head) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900195 tqe = p->txq_head;
196 p->txq_head = tqe->next;
197 if (p->txq_head) {
198 p->txq_head->prev = NULL;
199 }
200 p->txq_entries -= 1;
201
202 /*Added by Amr - BugID_4720*/
203
204
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900205
206 } else {
207 tqe = NULL;
208 }
209 p->os_func.os_spin_unlock(p->txq_spinlock, &flags);
210 return tqe;
211}
212
213static void wilc_wlan_txq_add_to_tail(struct txq_entry_t *tqe)
214{
215 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
216 unsigned long flags;
217 /*Added by Amr - BugID_4720*/
218 p->os_func.os_spin_lock(p->txq_spinlock, &flags);
219
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900220 if (p->txq_head == NULL) {
221 tqe->next = NULL;
222 tqe->prev = NULL;
223 p->txq_head = tqe;
224 p->txq_tail = tqe;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900225 } else {
226 tqe->next = NULL;
227 tqe->prev = p->txq_tail;
228 p->txq_tail->next = tqe;
229 p->txq_tail = tqe;
230 }
231 p->txq_entries += 1;
232 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900233
234 /*Added by Amr - BugID_4720*/
235 p->os_func.os_spin_unlock(p->txq_spinlock, &flags);
236
237 /**
238 * wake up TX queue
239 **/
240 PRINT_D(TX_DBG, "Wake the txq_handling\n");
241
242 p->os_func.os_signal(p->txq_wait);
243
244
245}
246
247static int wilc_wlan_txq_add_to_head(struct txq_entry_t *tqe)
248{
249 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
250 unsigned long flags;
251 /*Added by Amr - BugID_4720*/
252 if (p->os_func.os_wait(p->txq_add_to_head_lock, CFG_PKTS_TIMEOUT))
253 return -1;
254
255 p->os_func.os_spin_lock(p->txq_spinlock, &flags);
256
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900257 if (p->txq_head == NULL) {
258 tqe->next = NULL;
259 tqe->prev = NULL;
260 p->txq_head = tqe;
261 p->txq_tail = tqe;
262 } else {
263 tqe->next = p->txq_head;
264 tqe->prev = NULL;
265 p->txq_head->prev = tqe;
266 p->txq_head = tqe;
267 }
268 p->txq_entries += 1;
269 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900270
271 /*Added by Amr - BugID_4720*/
272 p->os_func.os_spin_unlock(p->txq_spinlock, &flags);
273 p->os_func.os_signal(p->txq_add_to_head_lock);
274
275
276 /**
277 * wake up TX queue
278 **/
279 p->os_func.os_signal(p->txq_wait);
280 PRINT_D(TX_DBG, "Wake up the txq_handler\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900281
282 /*Added by Amr - BugID_4720*/
283 return 0;
284
285}
286
287uint32_t Statisitcs_totalAcks = 0, Statisitcs_DroppedAcks = 0;
288
289#ifdef TCP_ACK_FILTER
290struct Ack_session_info;
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530291struct Ack_session_info {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900292 uint32_t Ack_seq_num;
293 uint32_t Bigger_Ack_num;
294 uint16_t src_port;
295 uint16_t dst_port;
296 uint16_t status;
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530297};
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900298
299typedef struct {
300 uint32_t ack_num;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900301 uint32_t Session_index;
302 struct txq_entry_t *txqe;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900303} Pending_Acks_info_t /*Ack_info_t*/;
304
305
306
307
308struct Ack_session_info *Free_head;
309struct Ack_session_info *Alloc_head;
310
311#define TCP_FIN_MASK (1 << 0)
312#define TCP_SYN_MASK (1 << 1)
313#define TCP_Ack_MASK (1 << 4)
314#define NOT_TCP_ACK (-1)
315
316#define MAX_TCP_SESSION 25
317#define MAX_PENDING_ACKS 256
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530318struct Ack_session_info Acks_keep_track_info[2 * MAX_TCP_SESSION];
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900319Pending_Acks_info_t Pending_Acks_info[MAX_PENDING_ACKS];
320
321uint32_t PendingAcks_arrBase;
322uint32_t Opened_TCP_session;
323uint32_t Pending_Acks;
324
325
326
327static __inline int Init_TCP_tracking(void)
328{
329
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900330 return 0;
331
332}
333static __inline int add_TCP_track_session(uint32_t src_prt, uint32_t dst_prt, uint32_t seq)
334{
335 Acks_keep_track_info[Opened_TCP_session].Ack_seq_num = seq;
336 Acks_keep_track_info[Opened_TCP_session].Bigger_Ack_num = 0;
337 Acks_keep_track_info[Opened_TCP_session].src_port = src_prt;
338 Acks_keep_track_info[Opened_TCP_session].dst_port = dst_prt;
339 Opened_TCP_session++;
340
341 PRINT_D(TCP_ENH, "TCP Session %d to Ack %d\n", Opened_TCP_session, seq);
342 return 0;
343}
344
345static __inline int Update_TCP_track_session(uint32_t index, uint32_t Ack)
346{
347
348 if (Ack > Acks_keep_track_info[index].Bigger_Ack_num) {
349 Acks_keep_track_info[index].Bigger_Ack_num = Ack;
350 }
351 return 0;
352
353}
354static __inline int add_TCP_Pending_Ack(uint32_t Ack, uint32_t Session_index, struct txq_entry_t *txqe)
355{
356 Statisitcs_totalAcks++;
357 if (Pending_Acks < MAX_PENDING_ACKS) {
358 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].ack_num = Ack;
359 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].txqe = txqe;
360 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].Session_index = Session_index;
361 txqe->tcp_PendingAck_index = PendingAcks_arrBase + Pending_Acks;
362 Pending_Acks++;
363
364 } else {
365
366 }
367 return 0;
368}
369static __inline int remove_TCP_related(void)
370{
371 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
372 unsigned long flags;
373 p->os_func.os_spin_lock(p->txq_spinlock, &flags);
374
375 p->os_func.os_spin_unlock(p->txq_spinlock, &flags);
376 return 0;
377}
378
379static __inline int tcp_process(struct txq_entry_t *tqe)
380{
381 int ret;
382 uint8_t *eth_hdr_ptr;
383 uint8_t *buffer = tqe->buffer;
384 unsigned short h_proto;
385 int i;
386 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
387 unsigned long flags;
388 p->os_func.os_spin_lock(p->txq_spinlock, &flags);
389
390 eth_hdr_ptr = &buffer[0];
391 h_proto = ntohs(*((unsigned short *)&eth_hdr_ptr[12]));
392 if (h_proto == 0x0800) { /* IP */
393 uint8_t *ip_hdr_ptr;
394 uint8_t protocol;
395
396 ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN];
397 protocol = ip_hdr_ptr[9];
398
399
400 if (protocol == 0x06) {
401 uint8_t *tcp_hdr_ptr;
402 uint32_t IHL, Total_Length, Data_offset;
403 tcp_hdr_ptr = &ip_hdr_ptr[IP_HDR_LEN];
404 IHL = (ip_hdr_ptr[0] & 0xf) << 2;
405 Total_Length = (((uint32_t)ip_hdr_ptr[2]) << 8) + ((uint32_t)ip_hdr_ptr[3]);
406 Data_offset = (((uint32_t)tcp_hdr_ptr[12] & 0xf0) >> 2);
407 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*/
408 uint32_t seq_no, Ack_no;
409 seq_no = (((uint32_t)tcp_hdr_ptr[4]) << 24) + (((uint32_t)tcp_hdr_ptr[5]) << 16) + (((uint32_t)tcp_hdr_ptr[6]) << 8) + ((uint32_t)tcp_hdr_ptr[7]);
410
411 Ack_no = (((uint32_t)tcp_hdr_ptr[8]) << 24) + (((uint32_t)tcp_hdr_ptr[9]) << 16) + (((uint32_t)tcp_hdr_ptr[10]) << 8) + ((uint32_t)tcp_hdr_ptr[11]);
412
413
414 for (i = 0; i < Opened_TCP_session; i++) {
415 if (Acks_keep_track_info[i].Ack_seq_num == seq_no) {
416 Update_TCP_track_session(i, Ack_no);
417 break;
418 }
419 }
420 if (i == Opened_TCP_session) {
421 add_TCP_track_session(0, 0, seq_no);
422 }
423 add_TCP_Pending_Ack(Ack_no, i, tqe);
424
425
426 }
427
428 } else {
429 ret = 0;
430 }
431 } else {
432 ret = 0;
433 }
434 p->os_func.os_spin_unlock(p->txq_spinlock, &flags);
435 return ret;
436}
437
438
439static int wilc_wlan_txq_filter_dup_tcp_ack(void)
440{
441
442 uint32_t i = 0;
443 uint32_t Dropped = 0;
444 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
445
446 p->os_func.os_spin_lock(p->txq_spinlock, &p->txq_spinlock_flags);
447 for (i = PendingAcks_arrBase; i < (PendingAcks_arrBase + Pending_Acks); i++) {
448 if (Pending_Acks_info[i].ack_num < Acks_keep_track_info[Pending_Acks_info[i].Session_index].Bigger_Ack_num) {
449 struct txq_entry_t *tqe;
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530450 PRINT_D(TCP_ENH, "DROP ACK: %u\n", Pending_Acks_info[i].ack_num);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900451 tqe = Pending_Acks_info[i].txqe;
452 if (tqe) {
453 wilc_wlan_txq_remove(tqe);
454 Statisitcs_DroppedAcks++;
455 tqe->status = 1; /* mark the packet send */
456 if (tqe->tx_complete_func)
457 tqe->tx_complete_func(tqe->priv, tqe->status);
458 p->os_func.os_free(tqe);
459 Dropped++;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900460 }
461 }
462 }
463 Pending_Acks = 0;
464 Opened_TCP_session = 0;
465
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530466 if (PendingAcks_arrBase == 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900467 PendingAcks_arrBase = MAX_TCP_SESSION;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530468 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900469 PendingAcks_arrBase = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900470
471
472 p->os_func.os_spin_unlock(p->txq_spinlock, &p->txq_spinlock_flags);
473
474 while (Dropped > 0) {
475 /*consume the semaphore count of the removed packet*/
476 p->os_func.os_wait(p->txq_wait, 1);
477 Dropped--;
478 }
479
480 return 1;
481}
482#endif
483
484#ifdef TCP_ENHANCEMENTS
Dean Lee72ed4dc2015-06-12 14:11:44 +0900485bool EnableTCPAckFilter = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900486
Dean Lee72ed4dc2015-06-12 14:11:44 +0900487void Enable_TCP_ACK_Filter(bool value)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900488{
489 EnableTCPAckFilter = value;
490}
491
Dean Lee72ed4dc2015-06-12 14:11:44 +0900492bool is_TCP_ACK_Filter_Enabled(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900493{
494 return EnableTCPAckFilter;
495}
496#endif
497
498static int wilc_wlan_txq_add_cfg_pkt(uint8_t *buffer, uint32_t buffer_size)
499{
500 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
501 struct txq_entry_t *tqe;
502
503 PRINT_D(TX_DBG, "Adding config packet ...\n");
504 if (p->quit) {
505 PRINT_D(TX_DBG, "Return due to clear function\n");
506 p->os_func.os_signal(p->cfg_wait);
507 return 0;
508 }
509
510 tqe = (struct txq_entry_t *)p->os_func.os_malloc_atomic(sizeof(struct txq_entry_t));
511 if (tqe == NULL) {
512 PRINT_ER("Failed to allocate memory\n");
513 return 0;
514 }
515
516 tqe->type = WILC_CFG_PKT;
517 tqe->buffer = buffer;
518 tqe->buffer_size = buffer_size;
519 tqe->tx_complete_func = NULL;
520 tqe->priv = NULL;
521#ifdef TCP_ACK_FILTER
522 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
523#endif
524 /**
525 * Configuration packet always at the front
526 **/
527 PRINT_D(TX_DBG, "Adding the config packet at the Queue tail\n");
528
529 /*Edited by Amr - BugID_4720*/
530 if (wilc_wlan_txq_add_to_head(tqe))
531 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900532 return 1;
533}
534
535static int wilc_wlan_txq_add_net_pkt(void *priv, uint8_t *buffer, uint32_t buffer_size, wilc_tx_complete_func_t func)
536{
537 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
538 struct txq_entry_t *tqe;
539
540 if (p->quit)
541 return 0;
542
543 tqe = (struct txq_entry_t *)p->os_func.os_malloc_atomic(sizeof(struct txq_entry_t));
544
545 if (tqe == NULL)
546 return 0;
547 tqe->type = WILC_NET_PKT;
548 tqe->buffer = buffer;
549 tqe->buffer_size = buffer_size;
550 tqe->tx_complete_func = func;
551 tqe->priv = priv;
552
553 PRINT_D(TX_DBG, "Adding mgmt packet at the Queue tail\n");
554#ifdef TCP_ACK_FILTER
555 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
556#ifdef TCP_ENHANCEMENTS
Abdul Hussain5a66bf22015-06-16 09:44:06 +0000557 if (is_TCP_ACK_Filter_Enabled())
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900558#endif
559 tcp_process(tqe);
560#endif
561 wilc_wlan_txq_add_to_tail(tqe);
562 /*return number of itemes in the queue*/
563 return p->txq_entries;
564}
565/*Bug3959: transmitting mgmt frames received from host*/
566#if defined(WILC_AP_EXTERNAL_MLME) || defined(WILC_P2P)
567int wilc_wlan_txq_add_mgmt_pkt(void *priv, uint8_t *buffer, uint32_t buffer_size, wilc_tx_complete_func_t func)
568{
569
570 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
571 struct txq_entry_t *tqe;
572
573 if (p->quit)
574 return 0;
575
576 tqe = (struct txq_entry_t *)p->os_func.os_malloc_atomic(sizeof(struct txq_entry_t));
577
578 if (tqe == NULL)
579 return 0;
580 tqe->type = WILC_MGMT_PKT;
581 tqe->buffer = buffer;
582 tqe->buffer_size = buffer_size;
583 tqe->tx_complete_func = func;
584 tqe->priv = priv;
585#ifdef TCP_ACK_FILTER
586 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
587#endif
588 PRINT_D(TX_DBG, "Adding Network packet at the Queue tail\n");
589 wilc_wlan_txq_add_to_tail(tqe);
590 return 1;
591}
592
593#ifdef WILC_FULLY_HOSTING_AP
594int wilc_FH_wlan_txq_add_net_pkt(void *priv, uint8_t *buffer, uint32_t buffer_size, wilc_tx_complete_func_t func)
595{
596 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
597 struct txq_entry_t *tqe;
598
599 if (p->quit)
600 return 0;
601
602 tqe = (struct txq_entry_t *)p->os_func.os_malloc_atomic(sizeof(struct txq_entry_t));
603
604 if (tqe == NULL)
605 return 0;
606 tqe->type = WILC_FH_DATA_PKT;
607 tqe->buffer = buffer;
608 tqe->buffer_size = buffer_size;
609 tqe->tx_complete_func = func;
610 tqe->priv = priv;
611 PRINT_D(TX_DBG, "Adding mgmt packet at the Queue tail\n");
612 wilc_wlan_txq_add_to_tail(tqe);
613 /*return number of itemes in the queue*/
614 return p->txq_entries;
615}
616#endif /* WILC_FULLY_HOSTING_AP*/
617#endif /*WILC_AP_EXTERNAL_MLME*/
618static struct txq_entry_t *wilc_wlan_txq_get_first(void)
619{
620 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
621 struct txq_entry_t *tqe;
622 unsigned long flags;
623
624 /*Added by Amr - BugID_4720*/
625 p->os_func.os_spin_lock(p->txq_spinlock, &flags);
626
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900627 tqe = p->txq_head;
628
629 /*Added by Amr - BugID_4720*/
630 p->os_func.os_spin_unlock(p->txq_spinlock, &flags);
631
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900632
633 return tqe;
634}
635
636static struct txq_entry_t *wilc_wlan_txq_get_next(struct txq_entry_t *tqe)
637{
638 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
639 unsigned long flags;
640 /*Added by Amr - BugID_4720*/
641 p->os_func.os_spin_lock(p->txq_spinlock, &flags);
642
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900643 tqe = tqe->next;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900644 /*Added by Amr - BugID_4720*/
645 p->os_func.os_spin_unlock(p->txq_spinlock, &flags);
646
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900647
648 return tqe;
649}
650
651static int wilc_wlan_rxq_add(struct rxq_entry_t *rqe)
652{
653 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
654
655 if (p->quit)
656 return 0;
657
658 p->os_func.os_enter_cs(p->rxq_lock);
659 if (p->rxq_head == NULL) {
660 PRINT_D(RX_DBG, "Add to Queue head\n");
661 rqe->next = NULL;
662 p->rxq_head = rqe;
663 p->rxq_tail = rqe;
664 } else {
665 PRINT_D(RX_DBG, "Add to Queue tail\n");
666 p->rxq_tail->next = rqe;
667 rqe->next = NULL;
668 p->rxq_tail = rqe;
669 }
670 p->rxq_entries += 1;
671 PRINT_D(RX_DBG, "Number of queue entries: %d\n", p->rxq_entries);
672 p->os_func.os_leave_cs(p->rxq_lock);
673 return p->rxq_entries;
674}
675
676static struct rxq_entry_t *wilc_wlan_rxq_remove(void)
677{
678 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
679
680 PRINT_D(RX_DBG, "Getting rxQ element\n");
681 if (p->rxq_head) {
682 struct rxq_entry_t *rqe;
683
684 p->os_func.os_enter_cs(p->rxq_lock);
685 rqe = p->rxq_head;
686 p->rxq_head = p->rxq_head->next;
687 p->rxq_entries -= 1;
688 PRINT_D(RX_DBG, "RXQ entries decreased\n");
689 p->os_func.os_leave_cs(p->rxq_lock);
690 return rqe;
691 }
692 PRINT_D(RX_DBG, "Nothing to get from Q\n");
693 return NULL;
694}
695
696
697/********************************************
698 *
699 * Power Save handle functions
700 *
701 ********************************************/
702
703
704
705#ifdef WILC_OPTIMIZE_SLEEP_INT
706
707INLINE void chip_allow_sleep(void)
708{
709 uint32_t reg = 0;
710
711 /* Clear bit 1 */
712 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
713
714 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0));
715}
716
717INLINE void chip_wakeup(void)
718{
719 uint32_t reg, clk_status_reg, trials = 0;
720 uint32_t sleep_time;
721
722 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
723 do {
724 g_wlan.hif_func.hif_read_reg(1, &reg);
725 /* Set bit 1 */
726 g_wlan.hif_func.hif_write_reg(1, reg | (1 << 1));
727
728 /* Clear bit 1*/
729 g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1));
730
731 do {
732 /* Wait for the chip to stabilize*/
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -0700733 usleep_range(2 * 1000, 2 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900734 /* Make sure chip is awake. This is an extra step that can be removed */
735 /* later to avoid the bus access overhead */
Dean Lee72ed4dc2015-06-12 14:11:44 +0900736 if ((wilc_get_chipid(true) == 0)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900737 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
738 }
Dean Lee72ed4dc2015-06-12 14:11:44 +0900739 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900740
Dean Lee72ed4dc2015-06-12 14:11:44 +0900741 } while (wilc_get_chipid(true) == 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900742 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
743 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
744 do {
745 /* Set bit 1 */
746 g_wlan.hif_func.hif_write_reg(0xf0, reg | (1 << 0));
747
748 /* Check the clock status */
749 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
750
751 /* in case of clocks off, wait 2ms, and check it again. */
752 /* if still off, wait for another 2ms, for a total wait of 6ms. */
753 /* If still off, redo the wake up sequence */
754 while (((clk_status_reg & 0x1) == 0) && (((++trials) % 3) == 0)) {
755 /* Wait for the chip to stabilize*/
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -0700756 usleep_range(2 * 1000, 2 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900757
758 /* Make sure chip is awake. This is an extra step that can be removed */
759 /* later to avoid the bus access overhead */
760 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
761
762 if ((clk_status_reg & 0x1) == 0) {
763 wilc_debug(N_ERR, "clocks still OFF. Wake up failed\n");
764 }
765 }
766 /* in case of failure, Reset the wakeup bit to introduce a new edge on the next loop */
767 if ((clk_status_reg & 0x1) == 0) {
768 /* Reset bit 0 */
769 g_wlan.hif_func.hif_write_reg(0xf0, reg & (~(1 << 0)));
770 }
771 } while ((clk_status_reg & 0x1) == 0);
772 }
773
774
775 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
776 g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
777 reg &= ~(1 << 0);
778 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
779
Dean Lee72ed4dc2015-06-12 14:11:44 +0900780 if (wilc_get_chipid(false) >= 0x1002b0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900781 /* Enable PALDO back right after wakeup */
782 uint32_t val32;
783 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
784 val32 |= (1 << 6);
785 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
786
787 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
788 val32 |= (1 << 6);
789 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
790 }
791 }
792 genuChipPSstate = CHIP_WAKEDUP;
793}
794#else
795INLINE void chip_wakeup(void)
796{
797 uint32_t reg, trials = 0;
798 do {
799 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
800 g_wlan.hif_func.hif_read_reg(1, &reg);
801 /* Make sure bit 1 is 0 before we start. */
802 g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1));
803 /* Set bit 1 */
804 g_wlan.hif_func.hif_write_reg(1, reg | (1 << 1));
805 /* Clear bit 1*/
806 g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1));
807 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
808 /* Make sure bit 0 is 0 before we start. */
809 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
810 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0));
811 /* Set bit 1 */
812 g_wlan.hif_func.hif_write_reg(0xf0, reg | (1 << 0));
813 /* Clear bit 1 */
814 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0));
815 }
816
817 do {
818 /* Wait for the chip to stabilize*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900819 mdelay(3);
820
821 /* Make sure chip is awake. This is an extra step that can be removed */
822 /* later to avoid the bus access overhead */
Dean Lee72ed4dc2015-06-12 14:11:44 +0900823 if ((wilc_get_chipid(true) == 0)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900824 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
825 }
Dean Lee72ed4dc2015-06-12 14:11:44 +0900826 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900827
Dean Lee72ed4dc2015-06-12 14:11:44 +0900828 } while (wilc_get_chipid(true) == 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900829
830 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
831 g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
832 reg &= ~(1 << 0);
833 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
834
Dean Lee72ed4dc2015-06-12 14:11:44 +0900835 if (wilc_get_chipid(false) >= 0x1002b0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900836 /* Enable PALDO back right after wakeup */
837 uint32_t val32;
838 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
839 val32 |= (1 << 6);
840 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
841
842 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
843 val32 |= (1 << 6);
844 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
845 }
846 }
847 genuChipPSstate = CHIP_WAKEDUP;
848}
849#endif
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900850void chip_sleep_manually(u32 u32SleepTime)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900851{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900852 if (genuChipPSstate != CHIP_WAKEDUP) {
853 /* chip is already sleeping. Do nothing */
854 return;
855 }
856 acquire_bus(ACQUIRE_ONLY);
857
858#ifdef WILC_OPTIMIZE_SLEEP_INT
859 chip_allow_sleep();
860#endif
861
862 /* Trigger the manual sleep interrupt */
863 g_wlan.hif_func.hif_write_reg(0x10a8, 1);
864
865 genuChipPSstate = CHIP_SLEEPING_MANUAL;
866 release_bus(RELEASE_ONLY);
867
868}
869
870
871/********************************************
872 *
873 * Tx, Rx queue handle functions
874 *
875 ********************************************/
876static int wilc_wlan_handle_txq(uint32_t *pu32TxqCount)
877{
878 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
879 int i, entries = 0;
880 uint32_t sum;
881 uint32_t reg;
882 uint8_t *txb = p->tx_buffer;
883 uint32_t offset = 0;
884 int vmm_sz = 0;
885 struct txq_entry_t *tqe;
886 int ret = 0;
887 int counter;
888 int timeout;
889 uint32_t vmm_table[WILC_VMM_TBL_SIZE];
890 p->txq_exit = 0;
891 do {
892 if (p->quit)
893 break;
894
895 /*Added by Amr - BugID_4720*/
896 p->os_func.os_wait(p->txq_add_to_head_lock, CFG_PKTS_TIMEOUT);
897#ifdef TCP_ACK_FILTER
898 wilc_wlan_txq_filter_dup_tcp_ack();
899#endif
900 /**
901 * build the vmm list
902 **/
903 PRINT_D(TX_DBG, "Getting the head of the TxQ\n");
904 tqe = wilc_wlan_txq_get_first();
905 i = 0;
906 sum = 0;
907 do {
908 /* if ((tqe != NULL) && (i < (8)) && */
909 /* if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE-1)) && */
910 if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE - 1)) /* reserve last entry to 0 */) {
911
912 if (tqe->type == WILC_CFG_PKT) {
913 vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET;
914 }
915 /*Bug3959: transmitting mgmt frames received from host*/
916 /*vmm_sz will only be equal to tqe->buffer_size + 4 bytes (HOST_HDR_OFFSET)*/
917 /* in other cases WILC_MGMT_PKT and WILC_DATA_PKT_MAC_HDR*/
918 else if (tqe->type == WILC_NET_PKT) {
919 vmm_sz = ETH_ETHERNET_HDR_OFFSET;
920 }
921#ifdef WILC_FULLY_HOSTING_AP
922 else if (tqe->type == WILC_FH_DATA_PKT) {
923 vmm_sz = FH_TX_HOST_HDR_OFFSET;
924 }
925#endif
926#ifdef WILC_AP_EXTERNAL_MLME
927 else {
928 vmm_sz = HOST_HDR_OFFSET;
929 }
930#endif
931 vmm_sz += tqe->buffer_size;
932 PRINT_D(TX_DBG, "VMM Size before alignment = %d\n", vmm_sz);
933 if (vmm_sz & 0x3) { /* has to be word aligned */
934 vmm_sz = (vmm_sz + 4) & ~0x3;
935 }
936 if ((sum + vmm_sz) > p->tx_buffer_size) {
937 break;
938 }
939 PRINT_D(TX_DBG, "VMM Size AFTER alignment = %d\n", vmm_sz);
940 vmm_table[i] = vmm_sz / 4; /* table take the word size */
941 PRINT_D(TX_DBG, "VMMTable entry size = %d\n", vmm_table[i]);
942
943 if (tqe->type == WILC_CFG_PKT) {
944 vmm_table[i] |= (1 << 10);
945 PRINT_D(TX_DBG, "VMMTable entry changed for CFG packet = %d\n", vmm_table[i]);
946 }
947#ifdef BIG_ENDIAN
948 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
949#endif
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900950
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900951 i++;
952 sum += vmm_sz;
953 PRINT_D(TX_DBG, "sum = %d\n", sum);
954 tqe = wilc_wlan_txq_get_next(tqe);
955 } else {
956 break;
957 }
958 } while (1);
959
960 if (i == 0) { /* nothing in the queue */
961 PRINT_D(TX_DBG, "Nothing in TX-Q\n");
962 break;
963 } else {
964 PRINT_D(TX_DBG, "Mark the last entry in VMM table - number of previous entries = %d\n", i);
965 vmm_table[i] = 0x0; /* mark the last element to 0 */
966 }
967 acquire_bus(ACQUIRE_AND_WAKEUP);
968 counter = 0;
969 do {
970
971 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg);
972 if (!ret) {
973 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg vmm_tbl_entry..\n");
974 break;
975 }
976
977 if ((reg & 0x1) == 0) {
978 /**
979 * write to vmm table
980 **/
981 PRINT_D(TX_DBG, "Writing VMM table ... with Size = %d\n", ((i + 1) * 4));
982 break;
983 } else {
984 counter++;
985 if (counter > 200) {
986 counter = 0;
987 PRINT_D(TX_DBG, "Looping in tx ctrl , forcce quit\n");
988 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, 0);
989 break;
990 }
991 /**
992 * wait for vmm table is ready
993 **/
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530994 PRINT_WRN(GENERIC_DBG, "[wilc txq]: warn, vmm table not clear yet, wait...\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900995 release_bus(RELEASE_ALLOW_SLEEP);
996 p->os_func.os_sleep(3); /* wait 3 ms */
997 acquire_bus(ACQUIRE_AND_WAKEUP);
998 }
999 } while (!p->quit);
1000
1001 if (!ret) {
1002 goto _end_;
1003 }
1004
1005 timeout = 200;
1006 do {
1007
1008 /**
1009 * write to vmm table
1010 **/
1011 ret = p->hif_func.hif_block_tx(WILC_VMM_TBL_RX_SHADOW_BASE, (uint8_t *)vmm_table, ((i + 1) * 4)); /* Bug 4477 fix */
1012 if (!ret) {
1013 wilc_debug(N_ERR, "ERR block TX of VMM table.\n");
1014 break;
1015 }
1016
1017
1018 /**
1019 * interrupt firmware
1020 **/
1021 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x2);
1022 if (!ret) {
1023 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg host_vmm_ctl..\n");
1024 break;
1025 }
1026
1027 /**
1028 * wait for confirm...
1029 **/
1030
1031 do {
1032 ret = p->hif_func.hif_read_reg(WILC_HOST_VMM_CTL, &reg);
1033 if (!ret) {
1034 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg host_vmm_ctl..\n");
1035 break;
1036 }
1037 if ((reg >> 2) & 0x1) {
1038 /**
1039 * Get the entries
1040 **/
1041 entries = ((reg >> 3) & 0x3f);
1042 /* entries = ((reg>>3)&0x2f); */
1043 break;
1044 } else {
1045 release_bus(RELEASE_ALLOW_SLEEP);
1046 p->os_func.os_sleep(3); /* wait 3 ms */
1047 acquire_bus(ACQUIRE_AND_WAKEUP);
1048 PRINT_WRN(GENERIC_DBG, "Can't get VMM entery - reg = %2x\n", reg);
1049 }
1050 } while (--timeout);
1051 if (timeout <= 0) {
1052 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x0);
1053 break;
1054 }
1055
1056 if (!ret) {
1057 break;
1058 }
1059
1060 if (entries == 0) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301061 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 +09001062
1063 /* undo the transaction. */
1064 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg);
1065 if (!ret) {
1066 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg WILC_HOST_TX_CTRL..\n");
1067 break;
1068 }
1069 reg &= ~(1ul << 0);
1070 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, reg);
1071 if (!ret) {
1072 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg WILC_HOST_TX_CTRL..\n");
1073 break;
1074 }
1075 break;
1076 } else {
1077 break;
1078 }
1079 } while (1);
1080
1081 if (!ret) {
1082 goto _end_;
1083 }
1084 if (entries == 0) {
1085 ret = WILC_TX_ERR_NO_BUF;
1086 goto _end_;
1087 }
1088
1089 /* since copying data into txb takes some time, then
1090 * allow the bus lock to be released let the RX task go. */
1091 release_bus(RELEASE_ALLOW_SLEEP);
1092
1093 /**
1094 * Copy data to the TX buffer
1095 **/
1096 offset = 0;
1097 i = 0;
1098 do {
1099 tqe = wilc_wlan_txq_remove_from_head();
1100 if (tqe != NULL && (vmm_table[i] != 0)) {
1101 uint32_t header, buffer_offset;
1102
1103#ifdef BIG_ENDIAN
1104 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
1105#endif
1106 vmm_sz = (vmm_table[i] & 0x3ff); /* in word unit */
1107 vmm_sz *= 4;
1108 header = (tqe->type << 31) | (tqe->buffer_size << 15) | vmm_sz;
1109 /*Bug3959: transmitting mgmt frames received from host*/
1110 /*setting bit 30 in the host header to indicate mgmt frame*/
1111#ifdef WILC_AP_EXTERNAL_MLME
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301112 if (tqe->type == WILC_MGMT_PKT)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001113 header |= (1 << 30);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301114 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001115 header &= ~(1 << 30);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001116#endif
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001117
1118#ifdef BIG_ENDIAN
1119 header = BYTE_SWAP(header);
1120#endif
1121 memcpy(&txb[offset], &header, 4);
1122 if (tqe->type == WILC_CFG_PKT) {
1123 buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET;
1124 }
1125 /*Bug3959: transmitting mgmt frames received from host*/
1126 /*buffer offset = HOST_HDR_OFFSET in other cases: WILC_MGMT_PKT*/
1127 /* and WILC_DATA_PKT_MAC_HDR*/
1128 else if (tqe->type == WILC_NET_PKT) {
1129 char *pBSSID = ((struct tx_complete_data *)(tqe->priv))->pBssid;
1130 buffer_offset = ETH_ETHERNET_HDR_OFFSET;
1131 /* copy the bssid at the sart of the buffer */
1132 memcpy(&txb[offset + 4], pBSSID, 6);
1133 }
1134#ifdef WILC_FULLY_HOSTING_AP
1135 else if (tqe->type == WILC_FH_DATA_PKT) {
1136 buffer_offset = FH_TX_HOST_HDR_OFFSET;
1137 }
1138#endif
1139 else {
1140 buffer_offset = HOST_HDR_OFFSET;
1141 }
1142
1143 memcpy(&txb[offset + buffer_offset], tqe->buffer, tqe->buffer_size);
1144 offset += vmm_sz;
1145 i++;
1146 tqe->status = 1; /* mark the packet send */
1147 if (tqe->tx_complete_func)
1148 tqe->tx_complete_func(tqe->priv, tqe->status);
1149 #ifdef TCP_ACK_FILTER
1150 if (tqe->tcp_PendingAck_index != NOT_TCP_ACK) {
1151 Pending_Acks_info[tqe->tcp_PendingAck_index].txqe = NULL;
1152 }
1153 #endif
1154 p->os_func.os_free(tqe);
1155 } else {
1156 break;
1157 }
1158 } while (--entries);
1159
1160 /**
1161 * lock the bus
1162 **/
1163 acquire_bus(ACQUIRE_AND_WAKEUP);
1164
1165 ret = p->hif_func.hif_clear_int_ext(ENABLE_TX_VMM);
1166 if (!ret) {
1167 wilc_debug(N_ERR, "[wilc txq]: fail can't start tx VMM ...\n");
1168 goto _end_;
1169 }
1170
1171 /**
1172 * transfer
1173 **/
1174 ret = p->hif_func.hif_block_tx_ext(0, txb, offset);
1175 if (!ret) {
1176 wilc_debug(N_ERR, "[wilc txq]: fail can't block tx ext...\n");
1177 goto _end_;
1178 }
1179
1180_end_:
1181
1182 release_bus(RELEASE_ALLOW_SLEEP);
1183 if (ret != 1)
1184 break;
1185 } while (0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001186 /*Added by Amr - BugID_4720*/
1187 p->os_func.os_signal(p->txq_add_to_head_lock);
1188
1189 p->txq_exit = 1;
1190 PRINT_D(TX_DBG, "THREAD: Exiting txq\n");
1191 /* return tx[]q count */
1192 *pu32TxqCount = p->txq_entries;
1193 return ret;
1194}
1195
1196static void wilc_wlan_handle_rxq(void)
1197{
1198 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1199 int offset = 0, size, has_packet = 0;
1200 uint8_t *buffer;
1201 struct rxq_entry_t *rqe;
1202
1203 p->rxq_exit = 0;
1204
1205
1206
1207
1208 do {
1209 if (p->quit) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301210 PRINT_D(RX_DBG, "exit 1st do-while due to Clean_UP function\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001211 p->os_func.os_signal(p->cfg_wait);
1212 break;
1213 }
1214 rqe = wilc_wlan_rxq_remove();
1215 if (rqe == NULL) {
1216 PRINT_D(RX_DBG, "nothing in the queue - exit 1st do-while\n");
1217 break;
1218 }
1219 buffer = rqe->buffer;
1220 size = rqe->buffer_size;
1221 PRINT_D(RX_DBG, "rxQ entery Size = %d - Address = %p\n", size, buffer);
1222 offset = 0;
1223
1224
1225
1226 do {
1227 uint32_t header;
1228 uint32_t pkt_len, pkt_offset, tp_len;
1229 int is_cfg_packet;
1230 PRINT_D(RX_DBG, "In the 2nd do-while\n");
1231 memcpy(&header, &buffer[offset], 4);
1232#ifdef BIG_ENDIAN
1233 header = BYTE_SWAP(header);
1234#endif
1235 PRINT_D(RX_DBG, "Header = %04x - Offset = %d\n", header, offset);
1236
1237
1238
1239 is_cfg_packet = (header >> 31) & 0x1;
1240 pkt_offset = (header >> 22) & 0x1ff;
1241 tp_len = (header >> 11) & 0x7ff;
1242 pkt_len = header & 0x7ff;
1243
1244 if (pkt_len == 0 || tp_len == 0) {
1245 wilc_debug(N_RXQ, "[wilc rxq]: data corrupt, packet len or tp_len is 0 [%d][%d]\n", pkt_len, tp_len);
1246 break;
1247 }
1248
1249/*bug 3887: [AP] Allow Management frames to be passed to the host*/
1250 #if defined(WILC_AP_EXTERNAL_MLME) || defined(WILC_P2P)
1251 #define IS_MANAGMEMENT 0x100
1252 #define IS_MANAGMEMENT_CALLBACK 0x080
1253 #define IS_MGMT_STATUS_SUCCES 0x040
1254
1255
1256 if (pkt_offset & IS_MANAGMEMENT) {
1257 /* reset mgmt indicator bit, to use pkt_offeset in furthur calculations */
1258 pkt_offset &= ~(IS_MANAGMEMENT | IS_MANAGMEMENT_CALLBACK | IS_MGMT_STATUS_SUCCES);
1259
1260#ifdef USE_WIRELESS
1261 WILC_WFI_mgmt_rx(&buffer[offset + HOST_HDR_OFFSET], pkt_len);
1262
1263#endif
1264
1265 }
1266 /* BUG4530 fix */
1267 else
1268 #endif
1269 {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001270
1271 if (!is_cfg_packet) {
1272
1273 if (p->net_func.rx_indicate) {
1274 if (pkt_len > 0) {
1275 p->net_func.rx_indicate(&buffer[offset], pkt_len, pkt_offset);
1276 has_packet = 1;
1277 }
1278 }
1279 } else {
1280 wilc_cfg_rsp_t rsp;
1281
1282
1283
1284 p->cif_func.rx_indicate(&buffer[pkt_offset + offset], pkt_len, &rsp);
1285 if (rsp.type == WILC_CFG_RSP) {
1286 /**
1287 * wake up the waiting task...
1288 **/
1289 PRINT_D(RX_DBG, "p->cfg_seq_no = %d - rsp.seq_no = %d\n", p->cfg_seq_no, rsp.seq_no);
1290 if (p->cfg_seq_no == rsp.seq_no) {
1291 p->os_func.os_signal(p->cfg_wait);
1292 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001293 } else if (rsp.type == WILC_CFG_RSP_STATUS) {
1294 /**
1295 * Call back to indicate status...
1296 **/
1297 if (p->indicate_func.mac_indicate) {
1298 p->indicate_func.mac_indicate(WILC_MAC_INDICATE_STATUS);
1299 }
1300
1301 } else if (rsp.type == WILC_CFG_RSP_SCAN) {
1302 if (p->indicate_func.mac_indicate)
1303 p->indicate_func.mac_indicate(WILC_MAC_INDICATE_SCAN);
1304 }
1305 }
1306 }
1307 offset += tp_len;
1308 if (offset >= size)
1309 break;
1310 } while (1);
1311
1312
1313#ifndef MEMORY_STATIC
1314 if (buffer != NULL)
1315 p->os_func.os_free((void *)buffer);
1316#endif
1317 if (rqe != NULL)
1318 p->os_func.os_free((void *)rqe);
1319
1320 if (has_packet) {
1321 if (p->net_func.rx_complete)
1322 p->net_func.rx_complete();
1323 }
1324 } while (1);
1325
1326 p->rxq_exit = 1;
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301327 PRINT_D(RX_DBG, "THREAD: Exiting RX thread\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001328 return;
1329}
1330
1331/********************************************
1332 *
1333 * Fast DMA Isr
1334 *
1335 ********************************************/
1336static void wilc_unknown_isr_ext(void)
1337{
1338 g_wlan.hif_func.hif_clear_int_ext(0);
1339}
1340static void wilc_pllupdate_isr_ext(uint32_t int_stats)
1341{
1342
1343 int trials = 10;
1344
1345 g_wlan.hif_func.hif_clear_int_ext(PLL_INT_CLR);
1346
1347 /* Waiting for PLL */
1348 g_wlan.os_func.os_atomic_sleep(WILC_PLL_TO);
1349
1350 /* poll till read a valid data */
Dean Lee72ed4dc2015-06-12 14:11:44 +09001351 while (!(ISWILC1000(wilc_get_chipid(true)) && --trials)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001352 PRINT_D(TX_DBG, "PLL update retrying\n");
1353 g_wlan.os_func.os_atomic_sleep(1);
1354 }
1355}
1356
1357static void wilc_sleeptimer_isr_ext(uint32_t int_stats1)
1358{
1359 g_wlan.hif_func.hif_clear_int_ext(SLEEP_INT_CLR);
1360#ifndef WILC_OPTIMIZE_SLEEP_INT
1361 genuChipPSstate = CHIP_SLEEPING_AUTO;
1362#endif
1363}
1364
1365static void wilc_wlan_handle_isr_ext(uint32_t int_status)
1366{
1367 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1368#ifdef MEMORY_STATIC
1369 uint32_t offset = p->rx_buffer_offset;
1370#endif
1371 uint8_t *buffer = NULL;
1372 uint32_t size;
1373 uint32_t retries = 0;
1374 int ret = 0;
1375 struct rxq_entry_t *rqe;
1376
1377
1378 /**
1379 * Get the rx size
1380 **/
1381
1382 size = ((int_status & 0x7fff) << 2);
1383
1384 while (!size && retries < 10) {
1385 uint32_t time = 0;
1386 /*looping more secure*/
1387 /*zero size make a crashe because the dma will not happen and that will block the firmware*/
1388 wilc_debug(N_ERR, "RX Size equal zero ... Trying to read it again for %d time\n", time++);
1389 p->hif_func.hif_read_size(&size);
1390 size = ((size & 0x7fff) << 2);
1391 retries++;
1392
1393 }
1394
1395 if (size > 0) {
1396#ifdef MEMORY_STATIC
1397 if (p->rx_buffer_size - offset < size)
1398 offset = 0;
1399
1400 if (p->rx_buffer)
1401 buffer = &p->rx_buffer[offset];
1402 else {
1403 wilc_debug(N_ERR, "[wilc isr]: fail Rx Buffer is NULL...drop the packets (%d)\n", size);
1404 goto _end_;
1405 }
1406
1407#else
1408 buffer = p->os_func.os_malloc(size);
1409 if (buffer == NULL) {
1410 wilc_debug(N_ERR, "[wilc isr]: fail alloc host memory...drop the packets (%d)\n", size);
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -07001411 usleep_range(100 * 1000, 100 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001412 goto _end_;
1413 }
1414#endif
1415
1416 /**
1417 * clear the chip's interrupt after getting size some register getting corrupted after clear the interrupt
1418 **/
1419 p->hif_func.hif_clear_int_ext(DATA_INT_CLR | ENABLE_RX_VMM);
1420
1421
1422 /**
1423 * start transfer
1424 **/
1425 ret = p->hif_func.hif_block_rx_ext(0, buffer, size);
1426
1427 if (!ret) {
1428 wilc_debug(N_ERR, "[wilc isr]: fail block rx...\n");
1429 goto _end_;
1430 }
1431_end_:
1432
1433
1434 if (ret) {
1435#ifdef MEMORY_STATIC
1436 offset += size;
1437 p->rx_buffer_offset = offset;
1438#endif
1439 /**
1440 * add to rx queue
1441 **/
1442 rqe = (struct rxq_entry_t *)p->os_func.os_malloc(sizeof(struct rxq_entry_t));
1443 if (rqe != NULL) {
1444 rqe->buffer = buffer;
1445 rqe->buffer_size = size;
1446 PRINT_D(RX_DBG, "rxq entery Size= %d - Address = %p\n", rqe->buffer_size, rqe->buffer);
1447 wilc_wlan_rxq_add(rqe);
1448 p->os_func.os_signal(p->rxq_wait);
1449 }
1450 } else {
1451#ifndef MEMORY_STATIC
1452 if (buffer != NULL)
1453 p->os_func.os_free(buffer);
1454#endif
1455 }
1456 }
1457#ifdef TCP_ENHANCEMENTS
1458 wilc_wlan_handle_rxq();
1459#endif
1460}
1461
1462void wilc_handle_isr(void)
1463{
1464 uint32_t int_status;
1465
1466 acquire_bus(ACQUIRE_AND_WAKEUP);
1467 g_wlan.hif_func.hif_read_int(&int_status);
1468
1469 if (int_status & PLL_INT_EXT) {
1470 wilc_pllupdate_isr_ext(int_status);
1471 }
1472 if (int_status & DATA_INT_EXT) {
1473 wilc_wlan_handle_isr_ext(int_status);
1474 #ifndef WILC_OPTIMIZE_SLEEP_INT
1475 /* Chip is up and talking*/
1476 genuChipPSstate = CHIP_WAKEDUP;
1477 #endif
1478 }
1479 if (int_status & SLEEP_INT_EXT) {
1480 wilc_sleeptimer_isr_ext(int_status);
1481 }
1482
1483 if (!(int_status & (ALL_INT_EXT))) {
1484#ifdef WILC_SDIO
1485 PRINT_D(TX_DBG, ">> UNKNOWN_INTERRUPT - 0x%08x\n", int_status);
1486#endif
1487 wilc_unknown_isr_ext();
1488 }
1489#if ((!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO))
1490 linux_wlan_enable_irq();
1491#endif
1492 release_bus(RELEASE_ALLOW_SLEEP);
1493}
1494
1495/********************************************
1496 *
1497 * Firmware download
1498 *
1499 ********************************************/
1500static int wilc_wlan_firmware_download(const uint8_t *buffer, uint32_t buffer_size)
1501{
1502 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1503 uint32_t offset;
1504 uint32_t addr, size, size2, blksz;
1505 uint8_t *dma_buffer;
1506 int ret = 0;
1507
1508 blksz = (1ul << 12); /* Bug 4703: 4KB Good enough size for most platforms = PAGE_SIZE. */
1509 /* Allocate a DMA coherent buffer. */
1510
1511#if (defined WILC_PREALLOC_AT_BOOT)
1512 {
1513 extern void *get_fw_buffer(void);
1514 dma_buffer = (uint8_t *)get_fw_buffer();
1515 PRINT_D(TX_DBG, "fw_buffer = 0x%x\n", dma_buffer);
1516 }
1517#else
1518 dma_buffer = (uint8_t *)g_wlan.os_func.os_malloc(blksz);
1519#endif
1520 if (dma_buffer == NULL) {
1521 /*EIO 5*/
1522 ret = -5;
1523 PRINT_ER("Can't allocate buffer for firmware download IO error\n ");
1524 goto _fail_1;
1525 }
1526
1527 PRINT_D(INIT_DBG, "Downloading firmware size = %d ...\n", buffer_size);
1528 /**
1529 * load the firmware
1530 **/
1531 offset = 0;
1532 do {
1533 memcpy(&addr, &buffer[offset], 4);
1534 memcpy(&size, &buffer[offset + 4], 4);
1535#ifdef BIG_ENDIAN
1536 addr = BYTE_SWAP(addr);
1537 size = BYTE_SWAP(size);
1538#endif
1539 acquire_bus(ACQUIRE_ONLY);
1540 offset += 8;
1541 while (((int)size) && (offset < buffer_size)) {
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301542 if (size <= blksz)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001543 size2 = size;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301544 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001545 size2 = blksz;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001546 /* Copy firmware into a DMA coherent buffer */
1547 memcpy(dma_buffer, &buffer[offset], size2);
1548 ret = p->hif_func.hif_block_tx(addr, dma_buffer, size2);
1549 if (!ret)
1550 break;
1551
1552 addr += size2;
1553 offset += size2;
1554 size -= size2;
1555 }
1556 release_bus(RELEASE_ONLY);
1557
1558 if (!ret) {
1559 /*EIO 5*/
1560 ret = -5;
1561 PRINT_ER("Can't download firmware IO error\n ");
1562 goto _fail_;
1563 }
1564 PRINT_D(INIT_DBG, "Offset = %d\n", offset);
1565 } while (offset < buffer_size);
1566
1567_fail_:
1568
1569#if (defined WILC_PREALLOC_AT_BOOT)
1570
1571#else
1572 if (dma_buffer)
1573 g_wlan.os_func.os_free(dma_buffer);
1574#endif
1575
1576_fail_1:
1577
1578 return (ret < 0) ? ret : 0;
1579}
1580
1581/********************************************
1582 *
1583 * Common
1584 *
1585 ********************************************/
1586static int wilc_wlan_start(void)
1587{
1588 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1589 uint32_t reg = 0;
1590 int ret;
1591 uint32_t chipid;
1592
1593 /**
1594 * Set the host interface
1595 **/
1596#ifdef OLD_FPGA_BITFILE
1597 acquire_bus(ACQUIRE_ONLY);
1598 ret = p->hif_func.hif_read_reg(WILC_VMM_CORE_CTL, &reg);
1599 if (!ret) {
1600 wilc_debug(N_ERR, "[wilc start]: fail read reg vmm_core_ctl...\n");
1601 release_bus(RELEASE_ALLOW_SLEEP);
1602 return ret;
1603 }
1604 reg |= (p->io_func.io_type << 2);
1605 ret = p->hif_func.hif_write_reg(WILC_VMM_CORE_CTL, reg);
1606 if (!ret) {
1607 wilc_debug(N_ERR, "[wilc start]: fail write reg vmm_core_ctl...\n");
1608 release_bus(RELEASE_ONLY);
1609 return ret;
1610 }
1611#else
1612 if (p->io_func.io_type == HIF_SDIO) {
1613 reg = 0;
1614 reg |= (1 << 3); /* bug 4456 and 4557 */
1615 } else if (p->io_func.io_type == HIF_SPI) {
1616 reg = 1;
1617 }
1618 acquire_bus(ACQUIRE_ONLY);
1619 ret = p->hif_func.hif_write_reg(WILC_VMM_CORE_CFG, reg);
1620 if (!ret) {
1621 wilc_debug(N_ERR, "[wilc start]: fail write reg vmm_core_cfg...\n");
1622 release_bus(RELEASE_ONLY);
1623 /* EIO 5*/
1624 ret = -5;
1625 return ret;
1626 }
1627 reg = 0;
1628#ifdef WILC_SDIO_IRQ_GPIO
1629 reg |= WILC_HAVE_SDIO_IRQ_GPIO;
1630#endif
1631
1632#ifdef WILC_DISABLE_PMU
1633#else
1634 reg |= WILC_HAVE_USE_PMU;
1635#endif
1636
1637#ifdef WILC_SLEEP_CLK_SRC_XO
1638 reg |= WILC_HAVE_SLEEP_CLK_SRC_XO;
1639#elif defined WILC_SLEEP_CLK_SRC_RTC
1640 reg |= WILC_HAVE_SLEEP_CLK_SRC_RTC;
1641#endif
1642
1643#ifdef WILC_EXT_PA_INV_TX_RX
1644 reg |= WILC_HAVE_EXT_PA_INV_TX_RX;
1645#endif
1646
1647 reg |= WILC_HAVE_LEGACY_RF_SETTINGS;
1648
1649
1650/*BugID_5257*/
1651/*Set oscillator frequency*/
1652#ifdef XTAL_24
1653 reg |= WILC_HAVE_XTAL_24;
1654#endif
1655
1656/*BugID_5271*/
1657/*Enable/Disable GPIO configuration for FW logs*/
1658#ifdef DISABLE_WILC_UART
1659 reg |= WILC_HAVE_DISABLE_WILC_UART;
1660#endif
1661
1662 ret = p->hif_func.hif_write_reg(WILC_GP_REG_1, reg);
1663 if (!ret) {
1664 wilc_debug(N_ERR, "[wilc start]: fail write WILC_GP_REG_1 ...\n");
1665 release_bus(RELEASE_ONLY);
1666 /* EIO 5*/
1667 ret = -5;
1668 return ret;
1669 }
1670#endif
1671
1672
1673 /**
1674 * Bus related
1675 **/
1676 p->hif_func.hif_sync_ext(NUM_INT_EXT);
1677
1678 ret = p->hif_func.hif_read_reg(0x1000, &chipid);
1679 if (!ret) {
1680 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1000 ...\n");
1681 release_bus(RELEASE_ONLY);
1682 /* EIO 5*/
1683 ret = -5;
1684 return ret;
1685 }
1686
1687 /**
1688 * Go...
1689 **/
1690
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001691
1692 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1693 if ((reg & (1ul << 10)) == (1ul << 10)) {
1694 reg &= ~(1ul << 10);
1695 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1696 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1697 }
1698
1699 reg |= (1ul << 10);
1700 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1701 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1702 release_bus(RELEASE_ONLY);
1703
1704 return (ret < 0) ? ret : 0;
1705}
1706
1707void wilc_wlan_global_reset(void)
1708{
1709
1710 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1711 acquire_bus(ACQUIRE_AND_WAKEUP);
1712 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, 0x0);
1713 release_bus(RELEASE_ONLY);
1714}
1715static int wilc_wlan_stop(void)
1716{
1717 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1718 uint32_t reg = 0;
1719 int ret;
1720 uint8_t timeout = 10;
1721 /**
1722 * TODO: stop the firmware, need a re-download
1723 **/
1724 acquire_bus(ACQUIRE_AND_WAKEUP);
1725
1726 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1727 if (!ret) {
1728 PRINT_ER("Error while reading reg\n");
1729 release_bus(RELEASE_ALLOW_SLEEP);
1730 return ret;
1731 }
1732
1733 reg &= ~(1 << 10);
1734
1735
1736 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1737 if (!ret) {
1738 PRINT_ER("Error while writing reg\n");
1739 release_bus(RELEASE_ALLOW_SLEEP);
1740 return ret;
1741 }
1742
1743
1744
1745 do {
1746 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1747 if (!ret) {
1748 PRINT_ER("Error while reading reg\n");
1749 release_bus(RELEASE_ALLOW_SLEEP);
1750 return ret;
1751 }
1752 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1753 /*Workaround to ensure that the chip is actually reset*/
1754 if ((reg & (1 << 10))) {
1755 PRINT_D(GENERIC_DBG, "Bit 10 not reset : Retry %d\n", timeout);
1756 reg &= ~(1 << 10);
1757 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1758 timeout--;
1759 } else {
1760 PRINT_D(GENERIC_DBG, "Bit 10 reset after : Retry %d\n", timeout);
1761 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1762 if (!ret) {
1763 PRINT_ER("Error while reading reg\n");
1764 release_bus(RELEASE_ALLOW_SLEEP);
1765 return ret;
1766 }
1767 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1768 break;
1769 }
1770
1771 } while (timeout);
1772#if 1
1773/******************************************************************************/
1774/* This was add at Bug 4595 to reset the chip while maintaining the bus state */
1775/******************************************************************************/
1776 reg = ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 8) | (1 << 9) | (1 << 26) | (1 << 29) | (1 << 30) | (1 << 31)); /**/
1777 /**/
Hari Prasath Gujulan Elango369f1902015-06-22 07:04:39 +00001778 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); /**/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001779 reg = ~(1 << 10); /**/
1780 /**/
1781 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); /**/
1782/******************************************************************************/
1783#endif
1784
1785 release_bus(RELEASE_ALLOW_SLEEP);
1786
1787 return ret;
1788}
1789
1790static void wilc_wlan_cleanup(void)
1791{
1792 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1793 struct txq_entry_t *tqe;
1794 struct rxq_entry_t *rqe;
1795 uint32_t reg = 0;
1796 int ret;
1797
1798 p->quit = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001799 do {
1800 tqe = wilc_wlan_txq_remove_from_head();
1801 if (tqe == NULL)
1802 break;
1803 if (tqe->tx_complete_func)
1804 tqe->tx_complete_func(tqe->priv, 0);
1805 p->os_func.os_free((void *)tqe);
1806 } while (1);
1807
1808 do {
1809 rqe = wilc_wlan_rxq_remove();
1810 if (rqe == NULL)
1811 break;
1812#ifdef MEMORY_DYNAMIC
1813 p->os_func.os_free((void *)tqe->buffer);
1814#endif
1815 p->os_func.os_free((void *)rqe);
1816 } while (1);
1817
1818 /**
1819 * clean up buffer
1820 **/
1821
1822#if (defined WILC_PREALLOC_AT_BOOT)
1823
1824#else
1825 #ifdef MEMORY_STATIC
1826 if (p->rx_buffer) {
1827 p->os_func.os_free(p->rx_buffer);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09001828 p->rx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001829 }
1830 #endif
1831 if (p->tx_buffer) {
1832 p->os_func.os_free(p->tx_buffer);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09001833 p->tx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001834 }
1835#endif
1836
1837 acquire_bus(ACQUIRE_AND_WAKEUP);
1838
1839
1840 ret = p->hif_func.hif_read_reg(WILC_GP_REG_0, &reg);
1841 if (!ret) {
1842 PRINT_ER("Error while reading reg\n");
1843 release_bus(RELEASE_ALLOW_SLEEP);
1844 }
1845 PRINT_ER("Writing ABORT reg\n");
1846 ret = p->hif_func.hif_write_reg(WILC_GP_REG_0, (reg | ABORT_INT));
1847 if (!ret) {
1848 PRINT_ER("Error while writing reg\n");
1849 release_bus(RELEASE_ALLOW_SLEEP);
1850 }
1851 release_bus(RELEASE_ALLOW_SLEEP);
1852 /**
1853 * io clean up
1854 **/
1855 p->hif_func.hif_deinit(NULL);
1856
1857}
1858
1859static int wilc_wlan_cfg_commit(int type, uint32_t drvHandler)
1860{
1861 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1862 wilc_cfg_frame_t *cfg = &p->cfg_frame;
1863 int total_len = p->cfg_frame_offset + 4 + DRIVER_HANDLER_SIZE;
1864 int seq_no = p->cfg_seq_no % 256;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001865 int driver_handler = (u32)drvHandler;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001866
1867
1868 /**
1869 * Set up header
1870 **/
1871 if (type == WILC_CFG_SET) { /* Set */
1872 cfg->wid_header[0] = 'W';
1873 } else { /* Query */
1874 cfg->wid_header[0] = 'Q';
1875 }
1876 cfg->wid_header[1] = seq_no; /* sequence number */
1877 cfg->wid_header[2] = (uint8_t)total_len;
1878 cfg->wid_header[3] = (uint8_t)(total_len >> 8);
1879 cfg->wid_header[4] = (uint8_t)driver_handler;
1880 cfg->wid_header[5] = (uint8_t)(driver_handler >> 8);
1881 cfg->wid_header[6] = (uint8_t)(driver_handler >> 16);
1882 cfg->wid_header[7] = (uint8_t)(driver_handler >> 24);
1883 p->cfg_seq_no = seq_no;
1884
1885 /**
1886 * Add to TX queue
1887 **/
1888
1889 /*Edited by Amr - BugID_4720*/
1890 if (!wilc_wlan_txq_add_cfg_pkt(&cfg->wid_header[0], total_len))
1891 return -1;
1892
1893 return 0;
1894}
1895
1896static int wilc_wlan_cfg_set(int start, uint32_t wid, uint8_t *buffer, uint32_t buffer_size, int commit, uint32_t drvHandler)
1897{
1898 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1899 uint32_t offset;
1900 int ret_size;
1901
1902
1903 if (p->cfg_frame_in_use)
1904 return 0;
1905
1906 if (start)
1907 p->cfg_frame_offset = 0;
1908
1909 offset = p->cfg_frame_offset;
1910 ret_size = p->cif_func.cfg_wid_set(p->cfg_frame.frame, offset, (uint16_t)wid, buffer, buffer_size);
1911 offset += ret_size;
1912 p->cfg_frame_offset = offset;
1913
1914 if (commit) {
1915 PRINT_D(TX_DBG, "[WILC]PACKET Commit with sequence number %d\n", p->cfg_seq_no);
1916 PRINT_D(RX_DBG, "Processing cfg_set()\n");
1917 p->cfg_frame_in_use = 1;
1918
1919 /*Edited by Amr - BugID_4720*/
1920 if (wilc_wlan_cfg_commit(WILC_CFG_SET, drvHandler))
1921 ret_size = 0; /* BugID_5213 */
1922
1923 if (p->os_func.os_wait(p->cfg_wait, CFG_PKTS_TIMEOUT)) {
1924 PRINT_D(TX_DBG, "Set Timed Out\n");
1925 ret_size = 0;
1926 }
1927 p->cfg_frame_in_use = 0;
1928 p->cfg_frame_offset = 0;
1929 p->cfg_seq_no += 1;
1930
1931 }
1932
1933 return ret_size;
1934}
1935static int wilc_wlan_cfg_get(int start, uint32_t wid, int commit, uint32_t drvHandler)
1936{
1937 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1938 uint32_t offset;
1939 int ret_size;
1940
1941
1942 if (p->cfg_frame_in_use)
1943 return 0;
1944
1945 if (start)
1946 p->cfg_frame_offset = 0;
1947
1948 offset = p->cfg_frame_offset;
1949 ret_size = p->cif_func.cfg_wid_get(p->cfg_frame.frame, offset, (uint16_t)wid);
1950 offset += ret_size;
1951 p->cfg_frame_offset = offset;
1952
1953 if (commit) {
1954 p->cfg_frame_in_use = 1;
1955
1956 /*Edited by Amr - BugID_4720*/
1957 if (wilc_wlan_cfg_commit(WILC_CFG_QUERY, drvHandler))
1958 ret_size = 0; /* BugID_5213 */
1959
1960
1961 if (p->os_func.os_wait(p->cfg_wait, CFG_PKTS_TIMEOUT)) {
1962 PRINT_D(TX_DBG, "Get Timed Out\n");
1963 ret_size = 0;
1964 }
1965 PRINT_D(GENERIC_DBG, "[WILC]Get Response received\n");
1966 p->cfg_frame_in_use = 0;
1967 p->cfg_frame_offset = 0;
1968 p->cfg_seq_no += 1;
1969 }
1970
1971 return ret_size;
1972}
1973
1974static int wilc_wlan_cfg_get_val(uint32_t wid, uint8_t *buffer, uint32_t buffer_size)
1975{
1976 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1977 int ret;
1978
1979 ret = p->cif_func.cfg_wid_get_val((uint16_t)wid, buffer, buffer_size);
1980
1981 return ret;
1982}
1983
1984void wilc_bus_set_max_speed(void)
1985{
1986
1987 /* Increase bus speed to max possible. */
1988 g_wlan.hif_func.hif_set_max_bus_speed();
1989}
1990
1991void wilc_bus_set_default_speed(void)
1992{
1993
1994 /* Restore bus speed to default. */
1995 g_wlan.hif_func.hif_set_default_bus_speed();
1996}
1997uint32_t init_chip(void)
1998{
1999 uint32_t chipid;
2000 uint32_t reg, ret = 0;
2001
2002#if defined(PLAT_RK3026_TCHIP)
2003 acquire_bus(ACQUIRE_AND_WAKEUP); /* AMR : 0422 RK3026 Crash issue */
2004#else
2005 acquire_bus(ACQUIRE_ONLY);
2006#endif
2007
Dean Lee72ed4dc2015-06-12 14:11:44 +09002008 chipid = wilc_get_chipid(true);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002009
2010
2011
2012 if ((chipid & 0xfff) != 0xa0) {
2013 /**
2014 * Avoid booting from boot ROM. Make sure that Drive IRQN [SDIO platform]
2015 * or SD_DAT3 [SPI platform] to ?1?
2016 **/
2017 /* Set cortus reset register to register control. */
2018 ret = g_wlan.hif_func.hif_read_reg(0x1118, &reg);
2019 if (!ret) {
2020 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1118 ...\n");
2021 return ret;
2022 }
2023 reg |= (1 << 0);
2024 ret = g_wlan.hif_func.hif_write_reg(0x1118, reg);
2025 if (!ret) {
2026 wilc_debug(N_ERR, "[wilc start]: fail write reg 0x1118 ...\n");
2027 return ret;
2028 }
2029 /**
2030 * Write branch intruction to IRAM (0x71 trap) at location 0xFFFF0000
2031 * (Cortus map) or C0000 (AHB map).
2032 **/
2033 ret = g_wlan.hif_func.hif_write_reg(0xc0000, 0x71);
2034 if (!ret) {
2035 wilc_debug(N_ERR, "[wilc start]: fail write reg 0xc0000 ...\n");
2036 return ret;
2037 }
2038 }
2039
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002040 release_bus(RELEASE_ONLY);
2041
2042 return ret;
2043
2044}
2045
2046uint32_t wilc_get_chipid(uint8_t update)
2047{
2048 static uint32_t chipid;
2049 /* SDIO can't read into global variables */
2050 /* Use this variable as a temp, then copy to the global */
2051 uint32_t tempchipid = 0;
2052 uint32_t rfrevid;
2053
2054 if (chipid == 0 || update != 0) {
2055 g_wlan.hif_func.hif_read_reg(0x1000, &tempchipid);
2056 g_wlan.hif_func.hif_read_reg(0x13f4, &rfrevid);
2057 if (!ISWILC1000(tempchipid)) {
2058 chipid = 0;
2059 goto _fail_;
2060 }
2061 if (tempchipid == 0x1002a0) {
2062 if (rfrevid == 0x1) { /* 1002A0 */
2063 } else { /* if (rfrevid == 0x2) */ /* 1002A1 */
2064 tempchipid = 0x1002a1;
2065 }
2066 } else if (tempchipid == 0x1002b0) {
2067 if (rfrevid == 3) { /* 1002B0 */
2068 } else if (rfrevid == 4) { /* 1002B1 */
2069 tempchipid = 0x1002b1;
2070 } else { /* if(rfrevid == 5) */ /* 1002B2 */
2071 tempchipid = 0x1002b2;
2072 }
2073 } else {
2074 }
2075
2076 chipid = tempchipid;
2077 }
2078_fail_:
2079 return chipid;
2080}
2081
2082#ifdef COMPLEMENT_BOOT
2083uint8_t core_11b_ready(void)
2084{
2085 uint32_t reg_val;
2086
2087 acquire_bus(ACQUIRE_ONLY);
2088 g_wlan.hif_func.hif_write_reg(0x16082c, 1);
2089 g_wlan.hif_func.hif_write_reg(0x161600, 0x90);
2090 g_wlan.hif_func.hif_read_reg(0x161600, &reg_val);
2091 release_bus(RELEASE_ONLY);
2092
2093 if (reg_val == 0x90)
2094 return 0;
2095 else
2096 return 1;
2097}
2098#endif
2099
2100int wilc_wlan_init(wilc_wlan_inp_t *inp, wilc_wlan_oup_t *oup)
2101{
2102
2103 int ret = 0;
2104
2105 PRINT_D(INIT_DBG, "Initializing WILC_Wlan ...\n");
2106
2107 memset((void *)&g_wlan, 0, sizeof(wilc_wlan_dev_t));
2108
2109 /**
2110 * store the input
2111 **/
2112 memcpy((void *)&g_wlan.os_func, (void *)&inp->os_func, sizeof(wilc_wlan_os_func_t));
2113 memcpy((void *)&g_wlan.io_func, (void *)&inp->io_func, sizeof(wilc_wlan_io_func_t));
2114 memcpy((void *)&g_wlan.net_func, (void *)&inp->net_func, sizeof(wilc_wlan_net_func_t));
2115 memcpy((void *)&g_wlan.indicate_func, (void *)&inp->indicate_func, sizeof(wilc_wlan_net_func_t));
2116 g_wlan.hif_lock = inp->os_context.hif_critical_section;
2117 g_wlan.txq_lock = inp->os_context.txq_critical_section;
2118
2119 /*Added by Amr - BugID_4720*/
2120 g_wlan.txq_add_to_head_lock = inp->os_context.txq_add_to_head_critical_section;
2121
2122 /*Added by Amr - BugID_4720*/
2123 g_wlan.txq_spinlock = inp->os_context.txq_spin_lock;
2124
2125 g_wlan.rxq_lock = inp->os_context.rxq_critical_section;
2126 g_wlan.txq_wait = inp->os_context.txq_wait_event;
2127 g_wlan.rxq_wait = inp->os_context.rxq_wait_event;
2128 g_wlan.cfg_wait = inp->os_context.cfg_wait_event;
2129 g_wlan.tx_buffer_size = inp->os_context.tx_buffer_size;
2130#if defined (MEMORY_STATIC)
2131 g_wlan.rx_buffer_size = inp->os_context.rx_buffer_size;
2132#endif
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002133 /***
2134 * host interface init
2135 **/
2136#if defined(PLAT_RK3026_TCHIP) /* AMR : 0422 RK3026 Crash issue */
2137 if (!g_wilc_initialized) {
2138 custom_lock_bus(g_mac_open);
2139 custom_wakeup(g_mac_open);
2140 }
2141#endif
2142
2143 if ((inp->io_func.io_type & 0x1) == HIF_SDIO) {
2144 if (!hif_sdio.hif_init(inp, wilc_debug)) {
2145 /* EIO 5 */
2146 ret = -5;
2147 goto _fail_;
2148 }
2149 memcpy((void *)&g_wlan.hif_func, &hif_sdio, sizeof(wilc_hif_func_t));
2150 } else {
2151 if ((inp->io_func.io_type & 0x1) == HIF_SPI) {
2152 /**
2153 * TODO:
2154 **/
2155 if (!hif_spi.hif_init(inp, wilc_debug)) {
2156 /* EIO 5 */
2157 ret = -5;
2158 goto _fail_;
2159 }
2160 memcpy((void *)&g_wlan.hif_func, &hif_spi, sizeof(wilc_hif_func_t));
2161 } else {
2162 /* EIO 5 */
2163 ret = -5;
2164 goto _fail_;
2165 }
2166 }
2167
2168 /***
2169 * mac interface init
2170 **/
2171 if (!mac_cfg.cfg_init(wilc_debug)) {
2172 /* ENOBUFS 105 */
2173 ret = -105;
2174 goto _fail_;
2175 }
2176 memcpy((void *)&g_wlan.cif_func, &mac_cfg, sizeof(wilc_cfg_func_t));
2177
2178
2179 /**
2180 * alloc tx, rx buffer
2181 **/
2182#if (defined WILC_PREALLOC_AT_BOOT)
2183 extern void *get_tx_buffer(void);
2184 extern void *get_rx_buffer(void);
2185
2186 PRINT_D(TX_DBG, "malloc before, g_wlan.tx_buffer = 0x%x, g_wlan.rx_buffer = 0x%x\n", g_wlan.tx_buffer, g_wlan.rx_buffer);
2187#endif
2188
2189
2190
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002191 if (g_wlan.tx_buffer == NULL)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002192#if (defined WILC_PREALLOC_AT_BOOT)
2193 g_wlan.tx_buffer = (uint8_t *)get_tx_buffer();
2194#else
2195 g_wlan.tx_buffer = (uint8_t *)g_wlan.os_func.os_malloc(g_wlan.tx_buffer_size);
2196#endif
Arnd Bergmann7a8fd842015-06-01 21:06:45 +02002197 PRINT_D(TX_DBG, "g_wlan.tx_buffer = %p\n", g_wlan.tx_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002198
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002199 if (g_wlan.tx_buffer == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002200 /* ENOBUFS 105 */
2201 ret = -105;
2202 PRINT_ER("Can't allocate Tx Buffer");
2203 goto _fail_;
2204 }
2205
2206/* rx_buffer is not used unless we activate USE_MEM STATIC which is not applicable, allocating such memory is useless*/
2207#if defined (MEMORY_STATIC)
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002208 if (g_wlan.rx_buffer == NULL)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002209 #if (defined WILC_PREALLOC_AT_BOOT)
2210 g_wlan.rx_buffer = (uint8_t *)get_rx_buffer();
2211 #else
2212 g_wlan.rx_buffer = (uint8_t *)g_wlan.os_func.os_malloc(g_wlan.rx_buffer_size);
2213 #endif
Arnd Bergmann7a8fd842015-06-01 21:06:45 +02002214 PRINT_D(TX_DBG, "g_wlan.rx_buffer =%p\n", g_wlan.rx_buffer);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002215 if (g_wlan.rx_buffer == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002216 /* ENOBUFS 105 */
2217 ret = -105;
2218 PRINT_ER("Can't allocate Rx Buffer");
2219 goto _fail_;
2220 }
2221#endif
2222
2223 /**
2224 * export functions
2225 **/
2226 oup->wlan_firmware_download = wilc_wlan_firmware_download;
2227 oup->wlan_start = wilc_wlan_start;
2228 oup->wlan_stop = wilc_wlan_stop;
2229 oup->wlan_add_to_tx_que = wilc_wlan_txq_add_net_pkt;
2230 oup->wlan_handle_tx_que = wilc_wlan_handle_txq;
2231 oup->wlan_handle_rx_que = wilc_wlan_handle_rxq;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002232 oup->wlan_handle_rx_isr = wilc_handle_isr;
2233 oup->wlan_cleanup = wilc_wlan_cleanup;
2234 oup->wlan_cfg_set = wilc_wlan_cfg_set;
2235 oup->wlan_cfg_get = wilc_wlan_cfg_get;
2236 oup->wlan_cfg_get_value = wilc_wlan_cfg_get_val;
2237
2238 /*Bug3959: transmitting mgmt frames received from host*/
2239 #if defined(WILC_AP_EXTERNAL_MLME) || defined(WILC_P2P)
2240 oup->wlan_add_mgmt_to_tx_que = wilc_wlan_txq_add_mgmt_pkt;
2241
2242 #ifdef WILC_FULLY_HOSTING_AP
2243 oup->wlan_add_data_to_tx_que = wilc_FH_wlan_txq_add_net_pkt;
2244 #endif
2245 #endif
2246
2247 if (!init_chip()) {
2248 /* EIO 5 */
2249 ret = -5;
2250 goto _fail_;
2251 }
2252#ifdef TCP_ACK_FILTER
2253 Init_TCP_tracking();
2254#endif
2255
2256#if defined(PLAT_RK3026_TCHIP) /* AMR : 0422 RK3026 Crash issue */
2257 if (!g_wilc_initialized)
2258 custom_unlock_bus(g_mac_open);
2259#endif
2260
2261 return 1;
2262
2263_fail_:
2264
2265#if (defined WILC_PREALLOC_AT_BOOT)
2266
2267#else
2268 #ifdef MEMORY_STATIC
2269 if (g_wlan.rx_buffer) {
2270 g_wlan.os_func.os_free(g_wlan.rx_buffer);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002271 g_wlan.rx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002272 }
2273 #endif
2274 if (g_wlan.tx_buffer) {
2275 g_wlan.os_func.os_free(g_wlan.tx_buffer);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002276 g_wlan.tx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002277 }
2278#endif
2279
2280#if defined(PLAT_RK3026_TCHIP) /* AMR : 0422 RK3026 Crash issue */
2281 if (!g_wilc_initialized)
2282 custom_unlock_bus(g_mac_open);
2283#endif
2284
2285 return ret;
2286
2287}
2288
2289#define BIT31 (1 << 31)
Dean Lee72ed4dc2015-06-12 14:11:44 +09002290u16 Set_machw_change_vir_if(bool bValue)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002291{
Chaehyun Limd85f5322015-06-11 14:35:54 +09002292 u16 ret;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002293 u32 reg;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002294
2295 /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
2296 (&g_wlan)->os_func.os_enter_cs((&g_wlan)->hif_lock);
2297 ret = (&g_wlan)->hif_func.hif_read_reg(WILC_CHANGING_VIR_IF, &reg);
2298 if (!ret) {
2299 PRINT_ER("Error while Reading reg WILC_CHANGING_VIR_IF\n");
2300 }
2301
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05302302 if (bValue)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002303 reg |= (BIT31);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05302304 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002305 reg &= ~(BIT31);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002306
2307 ret = (&g_wlan)->hif_func.hif_write_reg(WILC_CHANGING_VIR_IF, reg);
2308
2309 if (!ret) {
2310 PRINT_ER("Error while writing reg WILC_CHANGING_VIR_IF\n");
2311 }
2312 (&g_wlan)->os_func.os_leave_cs((&g_wlan)->hif_lock);
2313
2314 return ret;
2315}
2316
2317#ifdef WILC_FULLY_HOSTING_AP
Chaehyun Limd85f5322015-06-11 14:35:54 +09002318wilc_wlan_dev_t *Get_wlan_context(u16 *pu16size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002319{
2320 *pu16size = sizeof(wilc_wlan_dev_t);
2321 return &g_wlan;
2322}
2323#endif
2324