blob: e12dd01759f5559e02e1a53d4fbddabdfde239d8 [file] [log] [blame]
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001/* ////////////////////////////////////////////////////////////////////////// */
2/* */
3/* Copyright (c) Atmel Corporation. All rights reserved. */
4/* */
5/* Module Name: wilc_wlan.c */
6/* */
7/* */
8/* //////////////////////////////////////////////////////////////////////////// */
9
10#include "wilc_wlan_if.h"
11#include "wilc_wlan.h"
Johnny Kimc5c77ba2015-05-11 14:30:56 +090012
13/********************************************
14 *
15 * Global
16 *
17 ********************************************/
Johnny Kimc5c77ba2015-05-11 14:30:56 +090018extern wilc_hif_func_t hif_sdio;
19extern wilc_hif_func_t hif_spi;
20extern wilc_cfg_func_t mac_cfg;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090021extern void WILC_WFI_mgmt_rx(u8 *buff, u32 size);
22u32 wilc_get_chipid(u8 update);
Dean Lee72ed4dc2015-06-12 14:11:44 +090023u16 Set_machw_change_vir_if(bool bValue);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090024
Johnny Kimc5c77ba2015-05-11 14:30:56 +090025
26
27typedef struct {
28 int quit;
29
30 /**
31 * input interface functions
32 **/
33 wilc_wlan_os_func_t os_func;
34 wilc_wlan_io_func_t io_func;
35 wilc_wlan_net_func_t net_func;
36 wilc_wlan_indicate_func_t indicate_func;
37
38 /**
39 * host interface functions
40 **/
41 wilc_hif_func_t hif_func;
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -070042 struct mutex *hif_lock;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090043
44 /**
45 * configuration interface functions
46 **/
47 wilc_cfg_func_t cif_func;
48 int cfg_frame_in_use;
49 wilc_cfg_frame_t cfg_frame;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090050 u32 cfg_frame_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090051 int cfg_seq_no;
52 void *cfg_wait;
53
54 /**
55 * RX buffer
56 **/
57 #ifdef MEMORY_STATIC
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090058 u32 rx_buffer_size;
Chaehyun Lim51e825f2015-09-15 14:06:14 +090059 u8 *rx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090060 u32 rx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090061 #endif
62 /**
63 * TX buffer
64 **/
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090065 u32 tx_buffer_size;
Chaehyun Lim51e825f2015-09-15 14:06:14 +090066 u8 *tx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090067 u32 tx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090068
69 /**
70 * TX queue
71 **/
72 void *txq_lock;
73
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -070074 struct semaphore *txq_add_to_head_lock;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090075 void *txq_spinlock;
76 unsigned long txq_spinlock_flags;
77
78 struct txq_entry_t *txq_head;
79 struct txq_entry_t *txq_tail;
80 int txq_entries;
81 void *txq_wait;
82 int txq_exit;
83
84 /**
85 * RX queue
86 **/
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -070087 struct mutex *rxq_lock;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090088 struct rxq_entry_t *rxq_head;
89 struct rxq_entry_t *rxq_tail;
90 int rxq_entries;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090091 int rxq_exit;
92
93
94} wilc_wlan_dev_t;
95
96static wilc_wlan_dev_t g_wlan;
97
Chaehyun Lim9af382b2015-09-16 20:11:27 +090098static inline void chip_allow_sleep(void);
99static inline void chip_wakeup(void);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900100/********************************************
101 *
102 * Debug
103 *
104 ********************************************/
105
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900106static u32 dbgflag = N_INIT | N_ERR | N_INTR | N_TXQ | N_RXQ;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900107
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900108static void wilc_debug(u32 flag, char *fmt, ...)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900109{
110 char buf[256];
111 va_list args;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900112
113 if (flag & dbgflag) {
114 va_start(args, fmt);
Hari Prasath Gujulan Elango81053222015-06-22 13:13:58 +0000115 vsprintf(buf, fmt, args);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900116 va_end(args);
117
118 if (g_wlan.os_func.os_debug)
119 g_wlan.os_func.os_debug(buf);
120 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900121}
122
123static CHIP_PS_STATE_T genuChipPSstate = CHIP_WAKEDUP;
124
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900125/*acquire_bus() and release_bus() are made static inline functions*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900126/*as a temporary workaround to fix a problem of receiving*/
127/*unknown interrupt from FW*/
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900128static inline void acquire_bus(BUS_ACQUIRE_T acquire)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900129{
130
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -0700131 mutex_lock(g_wlan.hif_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900132 #ifndef WILC_OPTIMIZE_SLEEP_INT
133 if (genuChipPSstate != CHIP_WAKEDUP)
134 #endif
135 {
136 if (acquire == ACQUIRE_AND_WAKEUP)
137 chip_wakeup();
138 }
139
140}
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900141static inline void release_bus(BUS_RELEASE_T release)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900142{
143 #ifdef WILC_OPTIMIZE_SLEEP_INT
144 if (release == RELEASE_ALLOW_SLEEP)
145 chip_allow_sleep();
146 #endif
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -0700147 mutex_unlock(g_wlan.hif_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900148}
149/********************************************
150 *
151 * Queue
152 *
153 ********************************************/
154
155static void wilc_wlan_txq_remove(struct txq_entry_t *tqe)
156{
157
158 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
159 /* unsigned long flags; */
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900160 if (tqe == p->txq_head) {
161
162 p->txq_head = tqe->next;
163 if (p->txq_head)
164 p->txq_head->prev = NULL;
165
166
167 } else if (tqe == p->txq_tail) {
168 p->txq_tail = (tqe->prev);
169 if (p->txq_tail)
170 p->txq_tail->next = NULL;
171 } else {
172 tqe->prev->next = tqe->next;
173 tqe->next->prev = tqe->prev;
174 }
175 p->txq_entries -= 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900176
177}
178
179static struct txq_entry_t *wilc_wlan_txq_remove_from_head(void)
180{
181 struct txq_entry_t *tqe;
182 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
183 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900184
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700185 spin_lock_irqsave(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900186 if (p->txq_head) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900187 tqe = p->txq_head;
188 p->txq_head = tqe->next;
189 if (p->txq_head) {
190 p->txq_head->prev = NULL;
191 }
192 p->txq_entries -= 1;
193
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900194
195
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900196
197 } else {
198 tqe = NULL;
199 }
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700200 spin_unlock_irqrestore(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900201 return tqe;
202}
203
204static void wilc_wlan_txq_add_to_tail(struct txq_entry_t *tqe)
205{
206 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
207 unsigned long flags;
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700208 spin_lock_irqsave(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900209
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900210 if (p->txq_head == NULL) {
211 tqe->next = NULL;
212 tqe->prev = NULL;
213 p->txq_head = tqe;
214 p->txq_tail = tqe;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900215 } else {
216 tqe->next = NULL;
217 tqe->prev = p->txq_tail;
218 p->txq_tail->next = tqe;
219 p->txq_tail = tqe;
220 }
221 p->txq_entries += 1;
222 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900223
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700224 spin_unlock_irqrestore(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900225
226 /**
227 * wake up TX queue
228 **/
229 PRINT_D(TX_DBG, "Wake the txq_handling\n");
230
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -0700231 up(p->txq_wait);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900232}
233
234static int wilc_wlan_txq_add_to_head(struct txq_entry_t *tqe)
235{
236 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
237 unsigned long flags;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900238 if (p->os_func.os_wait(p->txq_add_to_head_lock, CFG_PKTS_TIMEOUT))
239 return -1;
240
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700241 spin_lock_irqsave(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900242
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900243 if (p->txq_head == NULL) {
244 tqe->next = NULL;
245 tqe->prev = NULL;
246 p->txq_head = tqe;
247 p->txq_tail = tqe;
248 } else {
249 tqe->next = p->txq_head;
250 tqe->prev = NULL;
251 p->txq_head->prev = tqe;
252 p->txq_head = tqe;
253 }
254 p->txq_entries += 1;
255 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900256
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700257 spin_unlock_irqrestore(p->txq_spinlock, flags);
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -0700258 up(p->txq_add_to_head_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900259
260
261 /**
262 * wake up TX queue
263 **/
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -0700264 up(p->txq_wait);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900265 PRINT_D(TX_DBG, "Wake up the txq_handler\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900266
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900267 return 0;
268
269}
270
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900271u32 Statisitcs_totalAcks = 0, Statisitcs_DroppedAcks = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900272
273#ifdef TCP_ACK_FILTER
274struct Ack_session_info;
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530275struct Ack_session_info {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900276 u32 Ack_seq_num;
277 u32 Bigger_Ack_num;
Chaehyun Limec53adf2015-09-15 14:06:15 +0900278 u16 src_port;
279 u16 dst_port;
280 u16 status;
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530281};
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900282
283typedef struct {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900284 u32 ack_num;
285 u32 Session_index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900286 struct txq_entry_t *txqe;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900287} Pending_Acks_info_t /*Ack_info_t*/;
288
289
290
291
292struct Ack_session_info *Free_head;
293struct Ack_session_info *Alloc_head;
294
295#define TCP_FIN_MASK (1 << 0)
296#define TCP_SYN_MASK (1 << 1)
297#define TCP_Ack_MASK (1 << 4)
298#define NOT_TCP_ACK (-1)
299
300#define MAX_TCP_SESSION 25
301#define MAX_PENDING_ACKS 256
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530302struct Ack_session_info Acks_keep_track_info[2 * MAX_TCP_SESSION];
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900303Pending_Acks_info_t Pending_Acks_info[MAX_PENDING_ACKS];
304
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900305u32 PendingAcks_arrBase;
306u32 Opened_TCP_session;
307u32 Pending_Acks;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900308
309
310
Chaehyun Limfed16f22015-09-17 16:48:43 +0900311static inline int Init_TCP_tracking(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900312{
313
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900314 return 0;
315
316}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900317static inline int add_TCP_track_session(u32 src_prt, u32 dst_prt, u32 seq)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900318{
319 Acks_keep_track_info[Opened_TCP_session].Ack_seq_num = seq;
320 Acks_keep_track_info[Opened_TCP_session].Bigger_Ack_num = 0;
321 Acks_keep_track_info[Opened_TCP_session].src_port = src_prt;
322 Acks_keep_track_info[Opened_TCP_session].dst_port = dst_prt;
323 Opened_TCP_session++;
324
325 PRINT_D(TCP_ENH, "TCP Session %d to Ack %d\n", Opened_TCP_session, seq);
326 return 0;
327}
328
Chaehyun Limfed16f22015-09-17 16:48:43 +0900329static inline int Update_TCP_track_session(u32 index, u32 Ack)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900330{
331
332 if (Ack > Acks_keep_track_info[index].Bigger_Ack_num) {
333 Acks_keep_track_info[index].Bigger_Ack_num = Ack;
334 }
335 return 0;
336
337}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900338static inline int add_TCP_Pending_Ack(u32 Ack, u32 Session_index, struct txq_entry_t *txqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900339{
340 Statisitcs_totalAcks++;
341 if (Pending_Acks < MAX_PENDING_ACKS) {
342 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].ack_num = Ack;
343 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].txqe = txqe;
344 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].Session_index = Session_index;
345 txqe->tcp_PendingAck_index = PendingAcks_arrBase + Pending_Acks;
346 Pending_Acks++;
347
348 } else {
349
350 }
351 return 0;
352}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900353static inline int remove_TCP_related(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900354{
355 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
356 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900357
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700358 spin_lock_irqsave(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900359
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700360 spin_unlock_irqrestore(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900361 return 0;
362}
363
Chaehyun Limfed16f22015-09-17 16:48:43 +0900364static inline int tcp_process(struct txq_entry_t *tqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900365{
366 int ret;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900367 u8 *eth_hdr_ptr;
368 u8 *buffer = tqe->buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900369 unsigned short h_proto;
370 int i;
371 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
372 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900373
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700374 spin_lock_irqsave(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900375
376 eth_hdr_ptr = &buffer[0];
377 h_proto = ntohs(*((unsigned short *)&eth_hdr_ptr[12]));
378 if (h_proto == 0x0800) { /* IP */
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900379 u8 *ip_hdr_ptr;
380 u8 protocol;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900381
382 ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN];
383 protocol = ip_hdr_ptr[9];
384
385
386 if (protocol == 0x06) {
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900387 u8 *tcp_hdr_ptr;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900388 u32 IHL, Total_Length, Data_offset;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900389
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900390 tcp_hdr_ptr = &ip_hdr_ptr[IP_HDR_LEN];
391 IHL = (ip_hdr_ptr[0] & 0xf) << 2;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900392 Total_Length = (((u32)ip_hdr_ptr[2]) << 8) + ((u32)ip_hdr_ptr[3]);
393 Data_offset = (((u32)tcp_hdr_ptr[12] & 0xf0) >> 2);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900394 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 +0900395 u32 seq_no, Ack_no;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900396
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900397 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 +0900398
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900399 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 +0900400
401
402 for (i = 0; i < Opened_TCP_session; i++) {
403 if (Acks_keep_track_info[i].Ack_seq_num == seq_no) {
404 Update_TCP_track_session(i, Ack_no);
405 break;
406 }
407 }
408 if (i == Opened_TCP_session) {
409 add_TCP_track_session(0, 0, seq_no);
410 }
411 add_TCP_Pending_Ack(Ack_no, i, tqe);
412
413
414 }
415
416 } else {
417 ret = 0;
418 }
419 } else {
420 ret = 0;
421 }
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700422 spin_unlock_irqrestore(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900423 return ret;
424}
425
426
427static int wilc_wlan_txq_filter_dup_tcp_ack(void)
428{
429
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900430 u32 i = 0;
431 u32 Dropped = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900432 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
433
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700434 spin_lock_irqsave(p->txq_spinlock, p->txq_spinlock_flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900435 for (i = PendingAcks_arrBase; i < (PendingAcks_arrBase + Pending_Acks); i++) {
436 if (Pending_Acks_info[i].ack_num < Acks_keep_track_info[Pending_Acks_info[i].Session_index].Bigger_Ack_num) {
437 struct txq_entry_t *tqe;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900438
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530439 PRINT_D(TCP_ENH, "DROP ACK: %u\n", Pending_Acks_info[i].ack_num);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900440 tqe = Pending_Acks_info[i].txqe;
441 if (tqe) {
442 wilc_wlan_txq_remove(tqe);
443 Statisitcs_DroppedAcks++;
444 tqe->status = 1; /* mark the packet send */
445 if (tqe->tx_complete_func)
446 tqe->tx_complete_func(tqe->priv, tqe->status);
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -0700447 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900448 Dropped++;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900449 }
450 }
451 }
452 Pending_Acks = 0;
453 Opened_TCP_session = 0;
454
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530455 if (PendingAcks_arrBase == 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900456 PendingAcks_arrBase = MAX_TCP_SESSION;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530457 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900458 PendingAcks_arrBase = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900459
460
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700461 spin_unlock_irqrestore(p->txq_spinlock, p->txq_spinlock_flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900462
463 while (Dropped > 0) {
464 /*consume the semaphore count of the removed packet*/
465 p->os_func.os_wait(p->txq_wait, 1);
466 Dropped--;
467 }
468
469 return 1;
470}
471#endif
472
Dean Lee72ed4dc2015-06-12 14:11:44 +0900473bool EnableTCPAckFilter = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900474
Dean Lee72ed4dc2015-06-12 14:11:44 +0900475void Enable_TCP_ACK_Filter(bool value)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900476{
477 EnableTCPAckFilter = value;
478}
479
Dean Lee72ed4dc2015-06-12 14:11:44 +0900480bool is_TCP_ACK_Filter_Enabled(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900481{
482 return EnableTCPAckFilter;
483}
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900484
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900485static int wilc_wlan_txq_add_cfg_pkt(u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900486{
487 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
488 struct txq_entry_t *tqe;
489
490 PRINT_D(TX_DBG, "Adding config packet ...\n");
491 if (p->quit) {
492 PRINT_D(TX_DBG, "Return due to clear function\n");
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -0700493 up(p->cfg_wait);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900494 return 0;
495 }
496
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700497 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900498 if (tqe == NULL) {
499 PRINT_ER("Failed to allocate memory\n");
500 return 0;
501 }
502
503 tqe->type = WILC_CFG_PKT;
504 tqe->buffer = buffer;
505 tqe->buffer_size = buffer_size;
506 tqe->tx_complete_func = NULL;
507 tqe->priv = NULL;
508#ifdef TCP_ACK_FILTER
509 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
510#endif
511 /**
512 * Configuration packet always at the front
513 **/
514 PRINT_D(TX_DBG, "Adding the config packet at the Queue tail\n");
515
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900516 if (wilc_wlan_txq_add_to_head(tqe))
517 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900518 return 1;
519}
520
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900521static 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 +0900522{
523 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
524 struct txq_entry_t *tqe;
525
526 if (p->quit)
527 return 0;
528
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700529 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900530
531 if (tqe == NULL)
532 return 0;
533 tqe->type = WILC_NET_PKT;
534 tqe->buffer = buffer;
535 tqe->buffer_size = buffer_size;
536 tqe->tx_complete_func = func;
537 tqe->priv = priv;
538
539 PRINT_D(TX_DBG, "Adding mgmt packet at the Queue tail\n");
540#ifdef TCP_ACK_FILTER
541 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
Abdul Hussain5a66bf22015-06-16 09:44:06 +0000542 if (is_TCP_ACK_Filter_Enabled())
Glen Lee25a84832015-09-16 18:53:22 +0900543 tcp_process(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900544#endif
545 wilc_wlan_txq_add_to_tail(tqe);
546 /*return number of itemes in the queue*/
547 return p->txq_entries;
548}
Glen Leefcc6ef92015-09-16 18:53:21 +0900549
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900550/*Bug3959: transmitting mgmt frames received from host*/
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900551int 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 +0900552{
553
554 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
555 struct txq_entry_t *tqe;
556
557 if (p->quit)
558 return 0;
559
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700560 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900561
562 if (tqe == NULL)
563 return 0;
564 tqe->type = WILC_MGMT_PKT;
565 tqe->buffer = buffer;
566 tqe->buffer_size = buffer_size;
567 tqe->tx_complete_func = func;
568 tqe->priv = priv;
569#ifdef TCP_ACK_FILTER
570 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
571#endif
572 PRINT_D(TX_DBG, "Adding Network packet at the Queue tail\n");
573 wilc_wlan_txq_add_to_tail(tqe);
574 return 1;
575}
Glen Leefcc6ef92015-09-16 18:53:21 +0900576
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900577static struct txq_entry_t *wilc_wlan_txq_get_first(void)
578{
579 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
580 struct txq_entry_t *tqe;
581 unsigned long flags;
582
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700583 spin_lock_irqsave(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900584
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900585 tqe = p->txq_head;
586
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700587 spin_unlock_irqrestore(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900588
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900589
590 return tqe;
591}
592
593static struct txq_entry_t *wilc_wlan_txq_get_next(struct txq_entry_t *tqe)
594{
595 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
596 unsigned long flags;
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700597 spin_lock_irqsave(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900598
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900599 tqe = tqe->next;
Greg Kroah-Hartman17c4d5d2015-09-03 20:17:31 -0700600 spin_unlock_irqrestore(p->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900601
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900602
603 return tqe;
604}
605
606static int wilc_wlan_rxq_add(struct rxq_entry_t *rqe)
607{
608 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
609
610 if (p->quit)
611 return 0;
612
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -0700613 mutex_lock(p->rxq_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900614 if (p->rxq_head == NULL) {
615 PRINT_D(RX_DBG, "Add to Queue head\n");
616 rqe->next = NULL;
617 p->rxq_head = rqe;
618 p->rxq_tail = rqe;
619 } else {
620 PRINT_D(RX_DBG, "Add to Queue tail\n");
621 p->rxq_tail->next = rqe;
622 rqe->next = NULL;
623 p->rxq_tail = rqe;
624 }
625 p->rxq_entries += 1;
626 PRINT_D(RX_DBG, "Number of queue entries: %d\n", p->rxq_entries);
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -0700627 mutex_unlock(p->rxq_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900628 return p->rxq_entries;
629}
630
631static struct rxq_entry_t *wilc_wlan_rxq_remove(void)
632{
633 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
634
635 PRINT_D(RX_DBG, "Getting rxQ element\n");
636 if (p->rxq_head) {
637 struct rxq_entry_t *rqe;
638
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -0700639 mutex_lock(p->rxq_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900640 rqe = p->rxq_head;
641 p->rxq_head = p->rxq_head->next;
642 p->rxq_entries -= 1;
643 PRINT_D(RX_DBG, "RXQ entries decreased\n");
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -0700644 mutex_unlock(p->rxq_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900645 return rqe;
646 }
647 PRINT_D(RX_DBG, "Nothing to get from Q\n");
648 return NULL;
649}
650
651
652/********************************************
653 *
654 * Power Save handle functions
655 *
656 ********************************************/
657
658
659
660#ifdef WILC_OPTIMIZE_SLEEP_INT
661
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900662static inline void chip_allow_sleep(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900663{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900664 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900665
666 /* Clear bit 1 */
667 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
668
669 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0));
670}
671
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900672static inline void chip_wakeup(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900673{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900674 u32 reg, clk_status_reg, trials = 0;
675 u32 sleep_time;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900676
677 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
678 do {
679 g_wlan.hif_func.hif_read_reg(1, &reg);
680 /* Set bit 1 */
681 g_wlan.hif_func.hif_write_reg(1, reg | (1 << 1));
682
683 /* Clear bit 1*/
684 g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1));
685
686 do {
687 /* Wait for the chip to stabilize*/
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -0700688 usleep_range(2 * 1000, 2 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900689 /* Make sure chip is awake. This is an extra step that can be removed */
690 /* later to avoid the bus access overhead */
Dean Lee72ed4dc2015-06-12 14:11:44 +0900691 if ((wilc_get_chipid(true) == 0)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900692 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
693 }
Dean Lee72ed4dc2015-06-12 14:11:44 +0900694 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900695
Dean Lee72ed4dc2015-06-12 14:11:44 +0900696 } while (wilc_get_chipid(true) == 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900697 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
698 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
699 do {
700 /* Set bit 1 */
701 g_wlan.hif_func.hif_write_reg(0xf0, reg | (1 << 0));
702
703 /* Check the clock status */
704 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
705
706 /* in case of clocks off, wait 2ms, and check it again. */
707 /* if still off, wait for another 2ms, for a total wait of 6ms. */
708 /* If still off, redo the wake up sequence */
709 while (((clk_status_reg & 0x1) == 0) && (((++trials) % 3) == 0)) {
710 /* Wait for the chip to stabilize*/
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -0700711 usleep_range(2 * 1000, 2 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900712
713 /* Make sure chip is awake. This is an extra step that can be removed */
714 /* later to avoid the bus access overhead */
715 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
716
717 if ((clk_status_reg & 0x1) == 0) {
718 wilc_debug(N_ERR, "clocks still OFF. Wake up failed\n");
719 }
720 }
721 /* in case of failure, Reset the wakeup bit to introduce a new edge on the next loop */
722 if ((clk_status_reg & 0x1) == 0) {
723 /* Reset bit 0 */
724 g_wlan.hif_func.hif_write_reg(0xf0, reg & (~(1 << 0)));
725 }
726 } while ((clk_status_reg & 0x1) == 0);
727 }
728
729
730 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
731 g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
732 reg &= ~(1 << 0);
733 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
734
Dean Lee72ed4dc2015-06-12 14:11:44 +0900735 if (wilc_get_chipid(false) >= 0x1002b0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900736 /* Enable PALDO back right after wakeup */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900737 u32 val32;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900738
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900739 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
740 val32 |= (1 << 6);
741 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
742
743 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
744 val32 |= (1 << 6);
745 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
746 }
747 }
748 genuChipPSstate = CHIP_WAKEDUP;
749}
750#else
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900751static inline void chip_wakeup(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900752{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900753 u32 reg, trials = 0;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900754
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900755 do {
756 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
757 g_wlan.hif_func.hif_read_reg(1, &reg);
758 /* Make sure bit 1 is 0 before we start. */
759 g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1));
760 /* Set bit 1 */
761 g_wlan.hif_func.hif_write_reg(1, reg | (1 << 1));
762 /* Clear bit 1*/
763 g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1));
764 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
765 /* Make sure bit 0 is 0 before we start. */
766 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
767 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0));
768 /* Set bit 1 */
769 g_wlan.hif_func.hif_write_reg(0xf0, reg | (1 << 0));
770 /* Clear bit 1 */
771 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0));
772 }
773
774 do {
775 /* Wait for the chip to stabilize*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900776 mdelay(3);
777
778 /* Make sure chip is awake. This is an extra step that can be removed */
779 /* later to avoid the bus access overhead */
Dean Lee72ed4dc2015-06-12 14:11:44 +0900780 if ((wilc_get_chipid(true) == 0)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900781 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
782 }
Dean Lee72ed4dc2015-06-12 14:11:44 +0900783 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900784
Dean Lee72ed4dc2015-06-12 14:11:44 +0900785 } while (wilc_get_chipid(true) == 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900786
787 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
788 g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
789 reg &= ~(1 << 0);
790 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
791
Dean Lee72ed4dc2015-06-12 14:11:44 +0900792 if (wilc_get_chipid(false) >= 0x1002b0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900793 /* Enable PALDO back right after wakeup */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900794 u32 val32;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900795
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900796 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
797 val32 |= (1 << 6);
798 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
799
800 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
801 val32 |= (1 << 6);
802 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
803 }
804 }
805 genuChipPSstate = CHIP_WAKEDUP;
806}
807#endif
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900808void chip_sleep_manually(u32 u32SleepTime)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900809{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900810 if (genuChipPSstate != CHIP_WAKEDUP) {
811 /* chip is already sleeping. Do nothing */
812 return;
813 }
814 acquire_bus(ACQUIRE_ONLY);
815
816#ifdef WILC_OPTIMIZE_SLEEP_INT
817 chip_allow_sleep();
818#endif
819
820 /* Trigger the manual sleep interrupt */
821 g_wlan.hif_func.hif_write_reg(0x10a8, 1);
822
823 genuChipPSstate = CHIP_SLEEPING_MANUAL;
824 release_bus(RELEASE_ONLY);
825
826}
827
828
829/********************************************
830 *
831 * Tx, Rx queue handle functions
832 *
833 ********************************************/
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900834static int wilc_wlan_handle_txq(u32 *pu32TxqCount)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900835{
836 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
837 int i, entries = 0;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900838 u32 sum;
839 u32 reg;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900840 u8 *txb = p->tx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900841 u32 offset = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900842 int vmm_sz = 0;
843 struct txq_entry_t *tqe;
844 int ret = 0;
845 int counter;
846 int timeout;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900847 u32 vmm_table[WILC_VMM_TBL_SIZE];
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900848
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900849 p->txq_exit = 0;
850 do {
851 if (p->quit)
852 break;
853
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900854 p->os_func.os_wait(p->txq_add_to_head_lock, CFG_PKTS_TIMEOUT);
855#ifdef TCP_ACK_FILTER
856 wilc_wlan_txq_filter_dup_tcp_ack();
857#endif
858 /**
859 * build the vmm list
860 **/
861 PRINT_D(TX_DBG, "Getting the head of the TxQ\n");
862 tqe = wilc_wlan_txq_get_first();
863 i = 0;
864 sum = 0;
865 do {
866 /* if ((tqe != NULL) && (i < (8)) && */
867 /* if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE-1)) && */
868 if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE - 1)) /* reserve last entry to 0 */) {
869
870 if (tqe->type == WILC_CFG_PKT) {
871 vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET;
872 }
873 /*Bug3959: transmitting mgmt frames received from host*/
874 /*vmm_sz will only be equal to tqe->buffer_size + 4 bytes (HOST_HDR_OFFSET)*/
875 /* in other cases WILC_MGMT_PKT and WILC_DATA_PKT_MAC_HDR*/
876 else if (tqe->type == WILC_NET_PKT) {
877 vmm_sz = ETH_ETHERNET_HDR_OFFSET;
878 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900879 else {
880 vmm_sz = HOST_HDR_OFFSET;
881 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900882 vmm_sz += tqe->buffer_size;
883 PRINT_D(TX_DBG, "VMM Size before alignment = %d\n", vmm_sz);
884 if (vmm_sz & 0x3) { /* has to be word aligned */
885 vmm_sz = (vmm_sz + 4) & ~0x3;
886 }
887 if ((sum + vmm_sz) > p->tx_buffer_size) {
888 break;
889 }
890 PRINT_D(TX_DBG, "VMM Size AFTER alignment = %d\n", vmm_sz);
891 vmm_table[i] = vmm_sz / 4; /* table take the word size */
892 PRINT_D(TX_DBG, "VMMTable entry size = %d\n", vmm_table[i]);
893
894 if (tqe->type == WILC_CFG_PKT) {
895 vmm_table[i] |= (1 << 10);
896 PRINT_D(TX_DBG, "VMMTable entry changed for CFG packet = %d\n", vmm_table[i]);
897 }
898#ifdef BIG_ENDIAN
899 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
900#endif
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900901
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900902 i++;
903 sum += vmm_sz;
904 PRINT_D(TX_DBG, "sum = %d\n", sum);
905 tqe = wilc_wlan_txq_get_next(tqe);
906 } else {
907 break;
908 }
909 } while (1);
910
911 if (i == 0) { /* nothing in the queue */
912 PRINT_D(TX_DBG, "Nothing in TX-Q\n");
913 break;
914 } else {
915 PRINT_D(TX_DBG, "Mark the last entry in VMM table - number of previous entries = %d\n", i);
916 vmm_table[i] = 0x0; /* mark the last element to 0 */
917 }
918 acquire_bus(ACQUIRE_AND_WAKEUP);
919 counter = 0;
920 do {
921
922 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg);
923 if (!ret) {
924 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg vmm_tbl_entry..\n");
925 break;
926 }
927
928 if ((reg & 0x1) == 0) {
929 /**
930 * write to vmm table
931 **/
932 PRINT_D(TX_DBG, "Writing VMM table ... with Size = %d\n", ((i + 1) * 4));
933 break;
934 } else {
935 counter++;
936 if (counter > 200) {
937 counter = 0;
938 PRINT_D(TX_DBG, "Looping in tx ctrl , forcce quit\n");
939 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, 0);
940 break;
941 }
942 /**
943 * wait for vmm table is ready
944 **/
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530945 PRINT_WRN(GENERIC_DBG, "[wilc txq]: warn, vmm table not clear yet, wait...\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900946 release_bus(RELEASE_ALLOW_SLEEP);
Greg Kroah-Hartman2b922cb2015-09-04 09:30:51 -0700947 usleep_range(3000, 3000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900948 acquire_bus(ACQUIRE_AND_WAKEUP);
949 }
950 } while (!p->quit);
951
952 if (!ret) {
953 goto _end_;
954 }
955
956 timeout = 200;
957 do {
958
959 /**
960 * write to vmm table
961 **/
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900962 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 +0900963 if (!ret) {
964 wilc_debug(N_ERR, "ERR block TX of VMM table.\n");
965 break;
966 }
967
968
969 /**
970 * interrupt firmware
971 **/
972 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x2);
973 if (!ret) {
974 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg host_vmm_ctl..\n");
975 break;
976 }
977
978 /**
979 * wait for confirm...
980 **/
981
982 do {
983 ret = p->hif_func.hif_read_reg(WILC_HOST_VMM_CTL, &reg);
984 if (!ret) {
985 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg host_vmm_ctl..\n");
986 break;
987 }
988 if ((reg >> 2) & 0x1) {
989 /**
990 * Get the entries
991 **/
992 entries = ((reg >> 3) & 0x3f);
993 /* entries = ((reg>>3)&0x2f); */
994 break;
995 } else {
996 release_bus(RELEASE_ALLOW_SLEEP);
Greg Kroah-Hartman2b922cb2015-09-04 09:30:51 -0700997 usleep_range(3000, 3000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900998 acquire_bus(ACQUIRE_AND_WAKEUP);
999 PRINT_WRN(GENERIC_DBG, "Can't get VMM entery - reg = %2x\n", reg);
1000 }
1001 } while (--timeout);
1002 if (timeout <= 0) {
1003 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x0);
1004 break;
1005 }
1006
1007 if (!ret) {
1008 break;
1009 }
1010
1011 if (entries == 0) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301012 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 +09001013
1014 /* undo the transaction. */
1015 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg);
1016 if (!ret) {
1017 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg WILC_HOST_TX_CTRL..\n");
1018 break;
1019 }
1020 reg &= ~(1ul << 0);
1021 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, reg);
1022 if (!ret) {
1023 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg WILC_HOST_TX_CTRL..\n");
1024 break;
1025 }
1026 break;
1027 } else {
1028 break;
1029 }
1030 } while (1);
1031
1032 if (!ret) {
1033 goto _end_;
1034 }
1035 if (entries == 0) {
1036 ret = WILC_TX_ERR_NO_BUF;
1037 goto _end_;
1038 }
1039
1040 /* since copying data into txb takes some time, then
1041 * allow the bus lock to be released let the RX task go. */
1042 release_bus(RELEASE_ALLOW_SLEEP);
1043
1044 /**
1045 * Copy data to the TX buffer
1046 **/
1047 offset = 0;
1048 i = 0;
1049 do {
1050 tqe = wilc_wlan_txq_remove_from_head();
1051 if (tqe != NULL && (vmm_table[i] != 0)) {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001052 u32 header, buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001053
1054#ifdef BIG_ENDIAN
1055 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
1056#endif
1057 vmm_sz = (vmm_table[i] & 0x3ff); /* in word unit */
1058 vmm_sz *= 4;
1059 header = (tqe->type << 31) | (tqe->buffer_size << 15) | vmm_sz;
1060 /*Bug3959: transmitting mgmt frames received from host*/
1061 /*setting bit 30 in the host header to indicate mgmt frame*/
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301062 if (tqe->type == WILC_MGMT_PKT)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001063 header |= (1 << 30);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301064 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001065 header &= ~(1 << 30);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001066
1067#ifdef BIG_ENDIAN
1068 header = BYTE_SWAP(header);
1069#endif
1070 memcpy(&txb[offset], &header, 4);
1071 if (tqe->type == WILC_CFG_PKT) {
1072 buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET;
1073 }
1074 /*Bug3959: transmitting mgmt frames received from host*/
1075 /*buffer offset = HOST_HDR_OFFSET in other cases: WILC_MGMT_PKT*/
1076 /* and WILC_DATA_PKT_MAC_HDR*/
1077 else if (tqe->type == WILC_NET_PKT) {
1078 char *pBSSID = ((struct tx_complete_data *)(tqe->priv))->pBssid;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001079
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001080 buffer_offset = ETH_ETHERNET_HDR_OFFSET;
1081 /* copy the bssid at the sart of the buffer */
1082 memcpy(&txb[offset + 4], pBSSID, 6);
1083 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001084 else {
1085 buffer_offset = HOST_HDR_OFFSET;
1086 }
1087
1088 memcpy(&txb[offset + buffer_offset], tqe->buffer, tqe->buffer_size);
1089 offset += vmm_sz;
1090 i++;
1091 tqe->status = 1; /* mark the packet send */
1092 if (tqe->tx_complete_func)
1093 tqe->tx_complete_func(tqe->priv, tqe->status);
1094 #ifdef TCP_ACK_FILTER
1095 if (tqe->tcp_PendingAck_index != NOT_TCP_ACK) {
1096 Pending_Acks_info[tqe->tcp_PendingAck_index].txqe = NULL;
1097 }
1098 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001099 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001100 } else {
1101 break;
1102 }
1103 } while (--entries);
1104
1105 /**
1106 * lock the bus
1107 **/
1108 acquire_bus(ACQUIRE_AND_WAKEUP);
1109
1110 ret = p->hif_func.hif_clear_int_ext(ENABLE_TX_VMM);
1111 if (!ret) {
1112 wilc_debug(N_ERR, "[wilc txq]: fail can't start tx VMM ...\n");
1113 goto _end_;
1114 }
1115
1116 /**
1117 * transfer
1118 **/
1119 ret = p->hif_func.hif_block_tx_ext(0, txb, offset);
1120 if (!ret) {
1121 wilc_debug(N_ERR, "[wilc txq]: fail can't block tx ext...\n");
1122 goto _end_;
1123 }
1124
1125_end_:
1126
1127 release_bus(RELEASE_ALLOW_SLEEP);
1128 if (ret != 1)
1129 break;
1130 } while (0);
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -07001131 up(p->txq_add_to_head_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001132
1133 p->txq_exit = 1;
1134 PRINT_D(TX_DBG, "THREAD: Exiting txq\n");
1135 /* return tx[]q count */
1136 *pu32TxqCount = p->txq_entries;
1137 return ret;
1138}
1139
1140static void wilc_wlan_handle_rxq(void)
1141{
1142 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1143 int offset = 0, size, has_packet = 0;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001144 u8 *buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001145 struct rxq_entry_t *rqe;
1146
1147 p->rxq_exit = 0;
1148
1149
1150
1151
1152 do {
1153 if (p->quit) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301154 PRINT_D(RX_DBG, "exit 1st do-while due to Clean_UP function\n");
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -07001155 up(p->cfg_wait);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001156 break;
1157 }
1158 rqe = wilc_wlan_rxq_remove();
1159 if (rqe == NULL) {
1160 PRINT_D(RX_DBG, "nothing in the queue - exit 1st do-while\n");
1161 break;
1162 }
1163 buffer = rqe->buffer;
1164 size = rqe->buffer_size;
1165 PRINT_D(RX_DBG, "rxQ entery Size = %d - Address = %p\n", size, buffer);
1166 offset = 0;
1167
1168
1169
1170 do {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001171 u32 header;
1172 u32 pkt_len, pkt_offset, tp_len;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001173 int is_cfg_packet;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001174
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001175 PRINT_D(RX_DBG, "In the 2nd do-while\n");
1176 memcpy(&header, &buffer[offset], 4);
1177#ifdef BIG_ENDIAN
1178 header = BYTE_SWAP(header);
1179#endif
1180 PRINT_D(RX_DBG, "Header = %04x - Offset = %d\n", header, offset);
1181
1182
1183
1184 is_cfg_packet = (header >> 31) & 0x1;
1185 pkt_offset = (header >> 22) & 0x1ff;
1186 tp_len = (header >> 11) & 0x7ff;
1187 pkt_len = header & 0x7ff;
1188
1189 if (pkt_len == 0 || tp_len == 0) {
1190 wilc_debug(N_RXQ, "[wilc rxq]: data corrupt, packet len or tp_len is 0 [%d][%d]\n", pkt_len, tp_len);
1191 break;
1192 }
1193
1194/*bug 3887: [AP] Allow Management frames to be passed to the host*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001195 #define IS_MANAGMEMENT 0x100
1196 #define IS_MANAGMEMENT_CALLBACK 0x080
1197 #define IS_MGMT_STATUS_SUCCES 0x040
1198
1199
1200 if (pkt_offset & IS_MANAGMEMENT) {
1201 /* reset mgmt indicator bit, to use pkt_offeset in furthur calculations */
1202 pkt_offset &= ~(IS_MANAGMEMENT | IS_MANAGMEMENT_CALLBACK | IS_MGMT_STATUS_SUCCES);
1203
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001204 WILC_WFI_mgmt_rx(&buffer[offset + HOST_HDR_OFFSET], pkt_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001205 }
1206 /* BUG4530 fix */
1207 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001208 {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001209
1210 if (!is_cfg_packet) {
1211
1212 if (p->net_func.rx_indicate) {
1213 if (pkt_len > 0) {
1214 p->net_func.rx_indicate(&buffer[offset], pkt_len, pkt_offset);
1215 has_packet = 1;
1216 }
1217 }
1218 } else {
1219 wilc_cfg_rsp_t rsp;
1220
1221
1222
1223 p->cif_func.rx_indicate(&buffer[pkt_offset + offset], pkt_len, &rsp);
1224 if (rsp.type == WILC_CFG_RSP) {
1225 /**
1226 * wake up the waiting task...
1227 **/
1228 PRINT_D(RX_DBG, "p->cfg_seq_no = %d - rsp.seq_no = %d\n", p->cfg_seq_no, rsp.seq_no);
1229 if (p->cfg_seq_no == rsp.seq_no) {
Greg Kroah-Hartman8990d852015-09-03 20:07:58 -07001230 up(p->cfg_wait);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001231 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001232 } else if (rsp.type == WILC_CFG_RSP_STATUS) {
1233 /**
1234 * Call back to indicate status...
1235 **/
1236 if (p->indicate_func.mac_indicate) {
1237 p->indicate_func.mac_indicate(WILC_MAC_INDICATE_STATUS);
1238 }
1239
1240 } else if (rsp.type == WILC_CFG_RSP_SCAN) {
1241 if (p->indicate_func.mac_indicate)
1242 p->indicate_func.mac_indicate(WILC_MAC_INDICATE_SCAN);
1243 }
1244 }
1245 }
1246 offset += tp_len;
1247 if (offset >= size)
1248 break;
1249 } while (1);
1250
1251
1252#ifndef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001253 kfree(buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001254#endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001255 kfree(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001256
1257 if (has_packet) {
1258 if (p->net_func.rx_complete)
1259 p->net_func.rx_complete();
1260 }
1261 } while (1);
1262
1263 p->rxq_exit = 1;
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301264 PRINT_D(RX_DBG, "THREAD: Exiting RX thread\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001265}
1266
1267/********************************************
1268 *
1269 * Fast DMA Isr
1270 *
1271 ********************************************/
1272static void wilc_unknown_isr_ext(void)
1273{
1274 g_wlan.hif_func.hif_clear_int_ext(0);
1275}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001276static void wilc_pllupdate_isr_ext(u32 int_stats)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001277{
1278
1279 int trials = 10;
1280
1281 g_wlan.hif_func.hif_clear_int_ext(PLL_INT_CLR);
1282
1283 /* Waiting for PLL */
Greg Kroah-Hartmanc2e4c0f2015-09-03 19:09:50 -07001284 mdelay(WILC_PLL_TO);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001285
1286 /* poll till read a valid data */
Dean Lee72ed4dc2015-06-12 14:11:44 +09001287 while (!(ISWILC1000(wilc_get_chipid(true)) && --trials)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001288 PRINT_D(TX_DBG, "PLL update retrying\n");
Greg Kroah-Hartmanc2e4c0f2015-09-03 19:09:50 -07001289 mdelay(1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001290 }
1291}
1292
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001293static void wilc_sleeptimer_isr_ext(u32 int_stats1)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001294{
1295 g_wlan.hif_func.hif_clear_int_ext(SLEEP_INT_CLR);
1296#ifndef WILC_OPTIMIZE_SLEEP_INT
1297 genuChipPSstate = CHIP_SLEEPING_AUTO;
1298#endif
1299}
1300
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001301static void wilc_wlan_handle_isr_ext(u32 int_status)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001302{
1303 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1304#ifdef MEMORY_STATIC
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001305 u32 offset = p->rx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001306#endif
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001307 u8 *buffer = NULL;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001308 u32 size;
1309 u32 retries = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001310 int ret = 0;
1311 struct rxq_entry_t *rqe;
1312
1313
1314 /**
1315 * Get the rx size
1316 **/
1317
1318 size = ((int_status & 0x7fff) << 2);
1319
1320 while (!size && retries < 10) {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001321 u32 time = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001322 /*looping more secure*/
1323 /*zero size make a crashe because the dma will not happen and that will block the firmware*/
1324 wilc_debug(N_ERR, "RX Size equal zero ... Trying to read it again for %d time\n", time++);
1325 p->hif_func.hif_read_size(&size);
1326 size = ((size & 0x7fff) << 2);
1327 retries++;
1328
1329 }
1330
1331 if (size > 0) {
1332#ifdef MEMORY_STATIC
1333 if (p->rx_buffer_size - offset < size)
1334 offset = 0;
1335
1336 if (p->rx_buffer)
1337 buffer = &p->rx_buffer[offset];
1338 else {
1339 wilc_debug(N_ERR, "[wilc isr]: fail Rx Buffer is NULL...drop the packets (%d)\n", size);
1340 goto _end_;
1341 }
1342
1343#else
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001344 buffer = kmalloc(size, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001345 if (buffer == NULL) {
1346 wilc_debug(N_ERR, "[wilc isr]: fail alloc host memory...drop the packets (%d)\n", size);
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -07001347 usleep_range(100 * 1000, 100 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001348 goto _end_;
1349 }
1350#endif
1351
1352 /**
1353 * clear the chip's interrupt after getting size some register getting corrupted after clear the interrupt
1354 **/
1355 p->hif_func.hif_clear_int_ext(DATA_INT_CLR | ENABLE_RX_VMM);
1356
1357
1358 /**
1359 * start transfer
1360 **/
1361 ret = p->hif_func.hif_block_rx_ext(0, buffer, size);
1362
1363 if (!ret) {
1364 wilc_debug(N_ERR, "[wilc isr]: fail block rx...\n");
1365 goto _end_;
1366 }
1367_end_:
1368
1369
1370 if (ret) {
1371#ifdef MEMORY_STATIC
1372 offset += size;
1373 p->rx_buffer_offset = offset;
1374#endif
1375 /**
1376 * add to rx queue
1377 **/
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001378 rqe = kmalloc(sizeof(struct rxq_entry_t), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001379 if (rqe != NULL) {
1380 rqe->buffer = buffer;
1381 rqe->buffer_size = size;
1382 PRINT_D(RX_DBG, "rxq entery Size= %d - Address = %p\n", rqe->buffer_size, rqe->buffer);
1383 wilc_wlan_rxq_add(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001384 }
1385 } else {
1386#ifndef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001387 kfree(buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001388#endif
1389 }
1390 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001391 wilc_wlan_handle_rxq();
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001392}
1393
1394void wilc_handle_isr(void)
1395{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001396 u32 int_status;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001397
1398 acquire_bus(ACQUIRE_AND_WAKEUP);
1399 g_wlan.hif_func.hif_read_int(&int_status);
1400
1401 if (int_status & PLL_INT_EXT) {
1402 wilc_pllupdate_isr_ext(int_status);
1403 }
1404 if (int_status & DATA_INT_EXT) {
1405 wilc_wlan_handle_isr_ext(int_status);
1406 #ifndef WILC_OPTIMIZE_SLEEP_INT
1407 /* Chip is up and talking*/
1408 genuChipPSstate = CHIP_WAKEDUP;
1409 #endif
1410 }
1411 if (int_status & SLEEP_INT_EXT) {
1412 wilc_sleeptimer_isr_ext(int_status);
1413 }
1414
1415 if (!(int_status & (ALL_INT_EXT))) {
1416#ifdef WILC_SDIO
1417 PRINT_D(TX_DBG, ">> UNKNOWN_INTERRUPT - 0x%08x\n", int_status);
1418#endif
1419 wilc_unknown_isr_ext();
1420 }
1421#if ((!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO))
1422 linux_wlan_enable_irq();
1423#endif
1424 release_bus(RELEASE_ALLOW_SLEEP);
1425}
1426
1427/********************************************
1428 *
1429 * Firmware download
1430 *
1431 ********************************************/
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001432static int wilc_wlan_firmware_download(const u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001433{
1434 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001435 u32 offset;
1436 u32 addr, size, size2, blksz;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001437 u8 *dma_buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001438 int ret = 0;
1439
1440 blksz = (1ul << 12); /* Bug 4703: 4KB Good enough size for most platforms = PAGE_SIZE. */
1441 /* Allocate a DMA coherent buffer. */
1442
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001443 dma_buffer = kmalloc(blksz, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001444 if (dma_buffer == NULL) {
1445 /*EIO 5*/
1446 ret = -5;
1447 PRINT_ER("Can't allocate buffer for firmware download IO error\n ");
1448 goto _fail_1;
1449 }
1450
1451 PRINT_D(INIT_DBG, "Downloading firmware size = %d ...\n", buffer_size);
1452 /**
1453 * load the firmware
1454 **/
1455 offset = 0;
1456 do {
1457 memcpy(&addr, &buffer[offset], 4);
1458 memcpy(&size, &buffer[offset + 4], 4);
1459#ifdef BIG_ENDIAN
1460 addr = BYTE_SWAP(addr);
1461 size = BYTE_SWAP(size);
1462#endif
1463 acquire_bus(ACQUIRE_ONLY);
1464 offset += 8;
1465 while (((int)size) && (offset < buffer_size)) {
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301466 if (size <= blksz)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001467 size2 = size;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301468 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001469 size2 = blksz;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001470 /* Copy firmware into a DMA coherent buffer */
1471 memcpy(dma_buffer, &buffer[offset], size2);
1472 ret = p->hif_func.hif_block_tx(addr, dma_buffer, size2);
1473 if (!ret)
1474 break;
1475
1476 addr += size2;
1477 offset += size2;
1478 size -= size2;
1479 }
1480 release_bus(RELEASE_ONLY);
1481
1482 if (!ret) {
1483 /*EIO 5*/
1484 ret = -5;
1485 PRINT_ER("Can't download firmware IO error\n ");
1486 goto _fail_;
1487 }
1488 PRINT_D(INIT_DBG, "Offset = %d\n", offset);
1489 } while (offset < buffer_size);
1490
1491_fail_:
1492
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001493 kfree(dma_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001494
1495_fail_1:
1496
1497 return (ret < 0) ? ret : 0;
1498}
1499
1500/********************************************
1501 *
1502 * Common
1503 *
1504 ********************************************/
1505static int wilc_wlan_start(void)
1506{
1507 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001508 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001509 int ret;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001510 u32 chipid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001511
1512 /**
1513 * Set the host interface
1514 **/
1515#ifdef OLD_FPGA_BITFILE
1516 acquire_bus(ACQUIRE_ONLY);
1517 ret = p->hif_func.hif_read_reg(WILC_VMM_CORE_CTL, &reg);
1518 if (!ret) {
1519 wilc_debug(N_ERR, "[wilc start]: fail read reg vmm_core_ctl...\n");
1520 release_bus(RELEASE_ALLOW_SLEEP);
1521 return ret;
1522 }
1523 reg |= (p->io_func.io_type << 2);
1524 ret = p->hif_func.hif_write_reg(WILC_VMM_CORE_CTL, reg);
1525 if (!ret) {
1526 wilc_debug(N_ERR, "[wilc start]: fail write reg vmm_core_ctl...\n");
1527 release_bus(RELEASE_ONLY);
1528 return ret;
1529 }
1530#else
1531 if (p->io_func.io_type == HIF_SDIO) {
1532 reg = 0;
1533 reg |= (1 << 3); /* bug 4456 and 4557 */
1534 } else if (p->io_func.io_type == HIF_SPI) {
1535 reg = 1;
1536 }
1537 acquire_bus(ACQUIRE_ONLY);
1538 ret = p->hif_func.hif_write_reg(WILC_VMM_CORE_CFG, reg);
1539 if (!ret) {
1540 wilc_debug(N_ERR, "[wilc start]: fail write reg vmm_core_cfg...\n");
1541 release_bus(RELEASE_ONLY);
1542 /* EIO 5*/
1543 ret = -5;
1544 return ret;
1545 }
1546 reg = 0;
1547#ifdef WILC_SDIO_IRQ_GPIO
1548 reg |= WILC_HAVE_SDIO_IRQ_GPIO;
1549#endif
1550
1551#ifdef WILC_DISABLE_PMU
1552#else
1553 reg |= WILC_HAVE_USE_PMU;
1554#endif
1555
1556#ifdef WILC_SLEEP_CLK_SRC_XO
1557 reg |= WILC_HAVE_SLEEP_CLK_SRC_XO;
1558#elif defined WILC_SLEEP_CLK_SRC_RTC
1559 reg |= WILC_HAVE_SLEEP_CLK_SRC_RTC;
1560#endif
1561
1562#ifdef WILC_EXT_PA_INV_TX_RX
1563 reg |= WILC_HAVE_EXT_PA_INV_TX_RX;
1564#endif
1565
1566 reg |= WILC_HAVE_LEGACY_RF_SETTINGS;
1567
1568
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001569/*Set oscillator frequency*/
1570#ifdef XTAL_24
1571 reg |= WILC_HAVE_XTAL_24;
1572#endif
1573
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001574/*Enable/Disable GPIO configuration for FW logs*/
1575#ifdef DISABLE_WILC_UART
1576 reg |= WILC_HAVE_DISABLE_WILC_UART;
1577#endif
1578
1579 ret = p->hif_func.hif_write_reg(WILC_GP_REG_1, reg);
1580 if (!ret) {
1581 wilc_debug(N_ERR, "[wilc start]: fail write WILC_GP_REG_1 ...\n");
1582 release_bus(RELEASE_ONLY);
1583 /* EIO 5*/
1584 ret = -5;
1585 return ret;
1586 }
1587#endif
1588
1589
1590 /**
1591 * Bus related
1592 **/
1593 p->hif_func.hif_sync_ext(NUM_INT_EXT);
1594
1595 ret = p->hif_func.hif_read_reg(0x1000, &chipid);
1596 if (!ret) {
1597 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1000 ...\n");
1598 release_bus(RELEASE_ONLY);
1599 /* EIO 5*/
1600 ret = -5;
1601 return ret;
1602 }
1603
1604 /**
1605 * Go...
1606 **/
1607
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001608
1609 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1610 if ((reg & (1ul << 10)) == (1ul << 10)) {
1611 reg &= ~(1ul << 10);
1612 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1613 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1614 }
1615
1616 reg |= (1ul << 10);
1617 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1618 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1619 release_bus(RELEASE_ONLY);
1620
1621 return (ret < 0) ? ret : 0;
1622}
1623
1624void wilc_wlan_global_reset(void)
1625{
1626
1627 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001628
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001629 acquire_bus(ACQUIRE_AND_WAKEUP);
1630 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, 0x0);
1631 release_bus(RELEASE_ONLY);
1632}
1633static int wilc_wlan_stop(void)
1634{
1635 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001636 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001637 int ret;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001638 u8 timeout = 10;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001639 /**
1640 * TODO: stop the firmware, need a re-download
1641 **/
1642 acquire_bus(ACQUIRE_AND_WAKEUP);
1643
1644 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1645 if (!ret) {
1646 PRINT_ER("Error while reading reg\n");
1647 release_bus(RELEASE_ALLOW_SLEEP);
1648 return ret;
1649 }
1650
1651 reg &= ~(1 << 10);
1652
1653
1654 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1655 if (!ret) {
1656 PRINT_ER("Error while writing reg\n");
1657 release_bus(RELEASE_ALLOW_SLEEP);
1658 return ret;
1659 }
1660
1661
1662
1663 do {
1664 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1665 if (!ret) {
1666 PRINT_ER("Error while reading reg\n");
1667 release_bus(RELEASE_ALLOW_SLEEP);
1668 return ret;
1669 }
1670 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1671 /*Workaround to ensure that the chip is actually reset*/
1672 if ((reg & (1 << 10))) {
1673 PRINT_D(GENERIC_DBG, "Bit 10 not reset : Retry %d\n", timeout);
1674 reg &= ~(1 << 10);
1675 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1676 timeout--;
1677 } else {
1678 PRINT_D(GENERIC_DBG, "Bit 10 reset after : Retry %d\n", timeout);
1679 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1680 if (!ret) {
1681 PRINT_ER("Error while reading reg\n");
1682 release_bus(RELEASE_ALLOW_SLEEP);
1683 return ret;
1684 }
1685 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1686 break;
1687 }
1688
1689 } while (timeout);
1690#if 1
1691/******************************************************************************/
1692/* This was add at Bug 4595 to reset the chip while maintaining the bus state */
1693/******************************************************************************/
1694 reg = ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 8) | (1 << 9) | (1 << 26) | (1 << 29) | (1 << 30) | (1 << 31)); /**/
1695 /**/
Hari Prasath Gujulan Elango369f1902015-06-22 07:04:39 +00001696 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); /**/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001697 reg = ~(1 << 10); /**/
1698 /**/
1699 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); /**/
1700/******************************************************************************/
1701#endif
1702
1703 release_bus(RELEASE_ALLOW_SLEEP);
1704
1705 return ret;
1706}
1707
1708static void wilc_wlan_cleanup(void)
1709{
1710 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1711 struct txq_entry_t *tqe;
1712 struct rxq_entry_t *rqe;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001713 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001714 int ret;
1715
1716 p->quit = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001717 do {
1718 tqe = wilc_wlan_txq_remove_from_head();
1719 if (tqe == NULL)
1720 break;
1721 if (tqe->tx_complete_func)
1722 tqe->tx_complete_func(tqe->priv, 0);
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001723 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001724 } while (1);
1725
1726 do {
1727 rqe = wilc_wlan_rxq_remove();
1728 if (rqe == NULL)
1729 break;
1730#ifdef MEMORY_DYNAMIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001731 kfree(tqe->buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001732#endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001733 kfree(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001734 } while (1);
1735
1736 /**
1737 * clean up buffer
1738 **/
1739
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001740 #ifdef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001741 kfree(p->rx_buffer);
1742 p->rx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001743 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001744 kfree(p->tx_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001745
1746 acquire_bus(ACQUIRE_AND_WAKEUP);
1747
1748
1749 ret = p->hif_func.hif_read_reg(WILC_GP_REG_0, &reg);
1750 if (!ret) {
1751 PRINT_ER("Error while reading reg\n");
1752 release_bus(RELEASE_ALLOW_SLEEP);
1753 }
1754 PRINT_ER("Writing ABORT reg\n");
1755 ret = p->hif_func.hif_write_reg(WILC_GP_REG_0, (reg | ABORT_INT));
1756 if (!ret) {
1757 PRINT_ER("Error while writing reg\n");
1758 release_bus(RELEASE_ALLOW_SLEEP);
1759 }
1760 release_bus(RELEASE_ALLOW_SLEEP);
1761 /**
1762 * io clean up
1763 **/
1764 p->hif_func.hif_deinit(NULL);
1765
1766}
1767
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001768static int wilc_wlan_cfg_commit(int type, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001769{
1770 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1771 wilc_cfg_frame_t *cfg = &p->cfg_frame;
1772 int total_len = p->cfg_frame_offset + 4 + DRIVER_HANDLER_SIZE;
1773 int seq_no = p->cfg_seq_no % 256;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001774 int driver_handler = (u32)drvHandler;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001775
1776
1777 /**
1778 * Set up header
1779 **/
1780 if (type == WILC_CFG_SET) { /* Set */
1781 cfg->wid_header[0] = 'W';
1782 } else { /* Query */
1783 cfg->wid_header[0] = 'Q';
1784 }
1785 cfg->wid_header[1] = seq_no; /* sequence number */
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001786 cfg->wid_header[2] = (u8)total_len;
1787 cfg->wid_header[3] = (u8)(total_len >> 8);
1788 cfg->wid_header[4] = (u8)driver_handler;
1789 cfg->wid_header[5] = (u8)(driver_handler >> 8);
1790 cfg->wid_header[6] = (u8)(driver_handler >> 16);
1791 cfg->wid_header[7] = (u8)(driver_handler >> 24);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001792 p->cfg_seq_no = seq_no;
1793
1794 /**
1795 * Add to TX queue
1796 **/
1797
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001798 if (!wilc_wlan_txq_add_cfg_pkt(&cfg->wid_header[0], total_len))
1799 return -1;
1800
1801 return 0;
1802}
1803
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001804static 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 +09001805{
1806 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001807 u32 offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001808 int ret_size;
1809
1810
1811 if (p->cfg_frame_in_use)
1812 return 0;
1813
1814 if (start)
1815 p->cfg_frame_offset = 0;
1816
1817 offset = p->cfg_frame_offset;
Chaehyun Limec53adf2015-09-15 14:06:15 +09001818 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 +09001819 offset += ret_size;
1820 p->cfg_frame_offset = offset;
1821
1822 if (commit) {
1823 PRINT_D(TX_DBG, "[WILC]PACKET Commit with sequence number %d\n", p->cfg_seq_no);
1824 PRINT_D(RX_DBG, "Processing cfg_set()\n");
1825 p->cfg_frame_in_use = 1;
1826
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001827 if (wilc_wlan_cfg_commit(WILC_CFG_SET, drvHandler))
Chaehyun Lim5af6b852015-09-17 16:48:48 +09001828 ret_size = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001829
1830 if (p->os_func.os_wait(p->cfg_wait, CFG_PKTS_TIMEOUT)) {
1831 PRINT_D(TX_DBG, "Set Timed Out\n");
1832 ret_size = 0;
1833 }
1834 p->cfg_frame_in_use = 0;
1835 p->cfg_frame_offset = 0;
1836 p->cfg_seq_no += 1;
1837
1838 }
1839
1840 return ret_size;
1841}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001842static int wilc_wlan_cfg_get(int start, u32 wid, int commit, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001843{
1844 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001845 u32 offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001846 int ret_size;
1847
1848
1849 if (p->cfg_frame_in_use)
1850 return 0;
1851
1852 if (start)
1853 p->cfg_frame_offset = 0;
1854
1855 offset = p->cfg_frame_offset;
Chaehyun Limec53adf2015-09-15 14:06:15 +09001856 ret_size = p->cif_func.cfg_wid_get(p->cfg_frame.frame, offset, (u16)wid);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001857 offset += ret_size;
1858 p->cfg_frame_offset = offset;
1859
1860 if (commit) {
1861 p->cfg_frame_in_use = 1;
1862
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001863 if (wilc_wlan_cfg_commit(WILC_CFG_QUERY, drvHandler))
Chaehyun Lim5af6b852015-09-17 16:48:48 +09001864 ret_size = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001865
1866
1867 if (p->os_func.os_wait(p->cfg_wait, CFG_PKTS_TIMEOUT)) {
1868 PRINT_D(TX_DBG, "Get Timed Out\n");
1869 ret_size = 0;
1870 }
1871 PRINT_D(GENERIC_DBG, "[WILC]Get Response received\n");
1872 p->cfg_frame_in_use = 0;
1873 p->cfg_frame_offset = 0;
1874 p->cfg_seq_no += 1;
1875 }
1876
1877 return ret_size;
1878}
1879
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001880static int wilc_wlan_cfg_get_val(u32 wid, u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001881{
1882 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1883 int ret;
1884
Chaehyun Limec53adf2015-09-15 14:06:15 +09001885 ret = p->cif_func.cfg_wid_get_val((u16)wid, buffer, buffer_size);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001886
1887 return ret;
1888}
1889
1890void wilc_bus_set_max_speed(void)
1891{
1892
1893 /* Increase bus speed to max possible. */
1894 g_wlan.hif_func.hif_set_max_bus_speed();
1895}
1896
1897void wilc_bus_set_default_speed(void)
1898{
1899
1900 /* Restore bus speed to default. */
1901 g_wlan.hif_func.hif_set_default_bus_speed();
1902}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001903u32 init_chip(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001904{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001905 u32 chipid;
1906 u32 reg, ret = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001907
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001908 acquire_bus(ACQUIRE_ONLY);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001909
Dean Lee72ed4dc2015-06-12 14:11:44 +09001910 chipid = wilc_get_chipid(true);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001911
1912
1913
1914 if ((chipid & 0xfff) != 0xa0) {
1915 /**
1916 * Avoid booting from boot ROM. Make sure that Drive IRQN [SDIO platform]
1917 * or SD_DAT3 [SPI platform] to ?1?
1918 **/
1919 /* Set cortus reset register to register control. */
1920 ret = g_wlan.hif_func.hif_read_reg(0x1118, &reg);
1921 if (!ret) {
1922 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1118 ...\n");
1923 return ret;
1924 }
1925 reg |= (1 << 0);
1926 ret = g_wlan.hif_func.hif_write_reg(0x1118, reg);
1927 if (!ret) {
1928 wilc_debug(N_ERR, "[wilc start]: fail write reg 0x1118 ...\n");
1929 return ret;
1930 }
1931 /**
1932 * Write branch intruction to IRAM (0x71 trap) at location 0xFFFF0000
1933 * (Cortus map) or C0000 (AHB map).
1934 **/
1935 ret = g_wlan.hif_func.hif_write_reg(0xc0000, 0x71);
1936 if (!ret) {
1937 wilc_debug(N_ERR, "[wilc start]: fail write reg 0xc0000 ...\n");
1938 return ret;
1939 }
1940 }
1941
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001942 release_bus(RELEASE_ONLY);
1943
1944 return ret;
1945
1946}
1947
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001948u32 wilc_get_chipid(u8 update)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001949{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001950 static u32 chipid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001951 /* SDIO can't read into global variables */
1952 /* Use this variable as a temp, then copy to the global */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001953 u32 tempchipid = 0;
1954 u32 rfrevid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001955
1956 if (chipid == 0 || update != 0) {
1957 g_wlan.hif_func.hif_read_reg(0x1000, &tempchipid);
1958 g_wlan.hif_func.hif_read_reg(0x13f4, &rfrevid);
1959 if (!ISWILC1000(tempchipid)) {
1960 chipid = 0;
1961 goto _fail_;
1962 }
1963 if (tempchipid == 0x1002a0) {
1964 if (rfrevid == 0x1) { /* 1002A0 */
1965 } else { /* if (rfrevid == 0x2) */ /* 1002A1 */
1966 tempchipid = 0x1002a1;
1967 }
1968 } else if (tempchipid == 0x1002b0) {
1969 if (rfrevid == 3) { /* 1002B0 */
1970 } else if (rfrevid == 4) { /* 1002B1 */
1971 tempchipid = 0x1002b1;
1972 } else { /* if(rfrevid == 5) */ /* 1002B2 */
1973 tempchipid = 0x1002b2;
1974 }
1975 } else {
1976 }
1977
1978 chipid = tempchipid;
1979 }
1980_fail_:
1981 return chipid;
1982}
1983
1984#ifdef COMPLEMENT_BOOT
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001985u8 core_11b_ready(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001986{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001987 u32 reg_val;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001988
1989 acquire_bus(ACQUIRE_ONLY);
1990 g_wlan.hif_func.hif_write_reg(0x16082c, 1);
1991 g_wlan.hif_func.hif_write_reg(0x161600, 0x90);
1992 g_wlan.hif_func.hif_read_reg(0x161600, &reg_val);
1993 release_bus(RELEASE_ONLY);
1994
1995 if (reg_val == 0x90)
1996 return 0;
1997 else
1998 return 1;
1999}
2000#endif
2001
2002int wilc_wlan_init(wilc_wlan_inp_t *inp, wilc_wlan_oup_t *oup)
2003{
2004
2005 int ret = 0;
2006
2007 PRINT_D(INIT_DBG, "Initializing WILC_Wlan ...\n");
2008
2009 memset((void *)&g_wlan, 0, sizeof(wilc_wlan_dev_t));
2010
2011 /**
2012 * store the input
2013 **/
2014 memcpy((void *)&g_wlan.os_func, (void *)&inp->os_func, sizeof(wilc_wlan_os_func_t));
2015 memcpy((void *)&g_wlan.io_func, (void *)&inp->io_func, sizeof(wilc_wlan_io_func_t));
2016 memcpy((void *)&g_wlan.net_func, (void *)&inp->net_func, sizeof(wilc_wlan_net_func_t));
2017 memcpy((void *)&g_wlan.indicate_func, (void *)&inp->indicate_func, sizeof(wilc_wlan_net_func_t));
2018 g_wlan.hif_lock = inp->os_context.hif_critical_section;
2019 g_wlan.txq_lock = inp->os_context.txq_critical_section;
2020
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002021 g_wlan.txq_add_to_head_lock = inp->os_context.txq_add_to_head_critical_section;
2022
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002023 g_wlan.txq_spinlock = inp->os_context.txq_spin_lock;
2024
2025 g_wlan.rxq_lock = inp->os_context.rxq_critical_section;
2026 g_wlan.txq_wait = inp->os_context.txq_wait_event;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002027 g_wlan.cfg_wait = inp->os_context.cfg_wait_event;
2028 g_wlan.tx_buffer_size = inp->os_context.tx_buffer_size;
2029#if defined (MEMORY_STATIC)
2030 g_wlan.rx_buffer_size = inp->os_context.rx_buffer_size;
2031#endif
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002032 /***
2033 * host interface init
2034 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002035 if ((inp->io_func.io_type & 0x1) == HIF_SDIO) {
2036 if (!hif_sdio.hif_init(inp, wilc_debug)) {
2037 /* EIO 5 */
2038 ret = -5;
2039 goto _fail_;
2040 }
2041 memcpy((void *)&g_wlan.hif_func, &hif_sdio, sizeof(wilc_hif_func_t));
2042 } else {
2043 if ((inp->io_func.io_type & 0x1) == HIF_SPI) {
2044 /**
2045 * TODO:
2046 **/
2047 if (!hif_spi.hif_init(inp, wilc_debug)) {
2048 /* EIO 5 */
2049 ret = -5;
2050 goto _fail_;
2051 }
2052 memcpy((void *)&g_wlan.hif_func, &hif_spi, sizeof(wilc_hif_func_t));
2053 } else {
2054 /* EIO 5 */
2055 ret = -5;
2056 goto _fail_;
2057 }
2058 }
2059
2060 /***
2061 * mac interface init
2062 **/
2063 if (!mac_cfg.cfg_init(wilc_debug)) {
2064 /* ENOBUFS 105 */
2065 ret = -105;
2066 goto _fail_;
2067 }
2068 memcpy((void *)&g_wlan.cif_func, &mac_cfg, sizeof(wilc_cfg_func_t));
2069
2070
2071 /**
2072 * alloc tx, rx buffer
2073 **/
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002074 if (g_wlan.tx_buffer == NULL)
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07002075 g_wlan.tx_buffer = kmalloc(g_wlan.tx_buffer_size, GFP_KERNEL);
Arnd Bergmann7a8fd842015-06-01 21:06:45 +02002076 PRINT_D(TX_DBG, "g_wlan.tx_buffer = %p\n", g_wlan.tx_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002077
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002078 if (g_wlan.tx_buffer == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002079 /* ENOBUFS 105 */
2080 ret = -105;
2081 PRINT_ER("Can't allocate Tx Buffer");
2082 goto _fail_;
2083 }
2084
2085/* rx_buffer is not used unless we activate USE_MEM STATIC which is not applicable, allocating such memory is useless*/
2086#if defined (MEMORY_STATIC)
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002087 if (g_wlan.rx_buffer == NULL)
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07002088 g_wlan.rx_buffer = kmalloc(g_wlan.rx_buffer_size, GFP_KERNEL);
Arnd Bergmann7a8fd842015-06-01 21:06:45 +02002089 PRINT_D(TX_DBG, "g_wlan.rx_buffer =%p\n", g_wlan.rx_buffer);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002090 if (g_wlan.rx_buffer == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002091 /* ENOBUFS 105 */
2092 ret = -105;
2093 PRINT_ER("Can't allocate Rx Buffer");
2094 goto _fail_;
2095 }
2096#endif
2097
2098 /**
2099 * export functions
2100 **/
2101 oup->wlan_firmware_download = wilc_wlan_firmware_download;
2102 oup->wlan_start = wilc_wlan_start;
2103 oup->wlan_stop = wilc_wlan_stop;
2104 oup->wlan_add_to_tx_que = wilc_wlan_txq_add_net_pkt;
2105 oup->wlan_handle_tx_que = wilc_wlan_handle_txq;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002106 oup->wlan_handle_rx_isr = wilc_handle_isr;
2107 oup->wlan_cleanup = wilc_wlan_cleanup;
2108 oup->wlan_cfg_set = wilc_wlan_cfg_set;
2109 oup->wlan_cfg_get = wilc_wlan_cfg_get;
2110 oup->wlan_cfg_get_value = wilc_wlan_cfg_get_val;
2111
2112 /*Bug3959: transmitting mgmt frames received from host*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002113 oup->wlan_add_mgmt_to_tx_que = wilc_wlan_txq_add_mgmt_pkt;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002114
2115 if (!init_chip()) {
2116 /* EIO 5 */
2117 ret = -5;
2118 goto _fail_;
2119 }
2120#ifdef TCP_ACK_FILTER
2121 Init_TCP_tracking();
2122#endif
2123
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002124 return 1;
2125
2126_fail_:
2127
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002128 #ifdef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07002129 kfree(g_wlan.rx_buffer);
2130 g_wlan.rx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002131 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07002132 kfree(g_wlan.tx_buffer);
2133 g_wlan.tx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002134
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002135 return ret;
2136
2137}
2138
Dean Lee72ed4dc2015-06-12 14:11:44 +09002139u16 Set_machw_change_vir_if(bool bValue)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002140{
Chaehyun Limd85f5322015-06-11 14:35:54 +09002141 u16 ret;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002142 u32 reg;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002143
2144 /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -07002145 mutex_lock((&g_wlan)->hif_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002146 ret = (&g_wlan)->hif_func.hif_read_reg(WILC_CHANGING_VIR_IF, &reg);
2147 if (!ret) {
2148 PRINT_ER("Error while Reading reg WILC_CHANGING_VIR_IF\n");
2149 }
2150
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05302151 if (bValue)
Chaehyun Lim50b51da2015-09-16 20:11:26 +09002152 reg |= BIT(31);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05302153 else
Chaehyun Lim50b51da2015-09-16 20:11:26 +09002154 reg &= ~BIT(31);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002155
2156 ret = (&g_wlan)->hif_func.hif_write_reg(WILC_CHANGING_VIR_IF, reg);
2157
2158 if (!ret) {
2159 PRINT_ER("Error while writing reg WILC_CHANGING_VIR_IF\n");
2160 }
Greg Kroah-Hartman5e150b52015-09-03 19:32:11 -07002161 mutex_unlock((&g_wlan)->hif_lock);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002162
2163 return ret;
2164}