blob: fbc0829126713a1e9e086cabec5c5cc03ee2658a [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"
Glen Lee17e8f162015-10-02 14:22:07 +090012#include "wilc_wlan_cfg.h"
Johnny Kimc5c77ba2015-05-11 14:30:56 +090013
14/********************************************
15 *
16 * Global
17 *
18 ********************************************/
Johnny Kimc5c77ba2015-05-11 14:30:56 +090019extern wilc_hif_func_t hif_sdio;
20extern wilc_hif_func_t hif_spi;
21extern wilc_cfg_func_t mac_cfg;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090022extern void WILC_WFI_mgmt_rx(u8 *buff, u32 size);
23u32 wilc_get_chipid(u8 update);
Dean Lee72ed4dc2015-06-12 14:11:44 +090024u16 Set_machw_change_vir_if(bool bValue);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090025
Johnny Kimc5c77ba2015-05-11 14:30:56 +090026
27
28typedef struct {
29 int quit;
30
31 /**
32 * input interface functions
33 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +090034 wilc_wlan_io_func_t io_func;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090035
36 /**
37 * host interface functions
38 **/
39 wilc_hif_func_t hif_func;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090040
41 /**
42 * configuration interface functions
43 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +090044 int cfg_frame_in_use;
45 wilc_cfg_frame_t cfg_frame;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090046 u32 cfg_frame_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090047 int cfg_seq_no;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090048
49 /**
50 * RX buffer
51 **/
52 #ifdef MEMORY_STATIC
Chaehyun Lim51e825f2015-09-15 14:06:14 +090053 u8 *rx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090054 u32 rx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090055 #endif
56 /**
57 * TX buffer
58 **/
Chaehyun Lim51e825f2015-09-15 14:06:14 +090059 u8 *tx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090060 u32 tx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090061
62 /**
63 * TX queue
64 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +090065
Johnny Kimc5c77ba2015-05-11 14:30:56 +090066 unsigned long txq_spinlock_flags;
67
68 struct txq_entry_t *txq_head;
69 struct txq_entry_t *txq_tail;
70 int txq_entries;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090071 int txq_exit;
72
73 /**
74 * RX queue
75 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +090076 struct rxq_entry_t *rxq_head;
77 struct rxq_entry_t *rxq_tail;
78 int rxq_entries;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090079 int rxq_exit;
80
81
82} wilc_wlan_dev_t;
83
84static wilc_wlan_dev_t g_wlan;
85
Chaehyun Lim9af382b2015-09-16 20:11:27 +090086static inline void chip_allow_sleep(void);
87static inline void chip_wakeup(void);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090088/********************************************
89 *
90 * Debug
91 *
92 ********************************************/
93
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090094static u32 dbgflag = N_INIT | N_ERR | N_INTR | N_TXQ | N_RXQ;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090095
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090096static void wilc_debug(u32 flag, char *fmt, ...)
Johnny Kimc5c77ba2015-05-11 14:30:56 +090097{
98 char buf[256];
99 va_list args;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900100
101 if (flag & dbgflag) {
102 va_start(args, fmt);
Hari Prasath Gujulan Elango81053222015-06-22 13:13:58 +0000103 vsprintf(buf, fmt, args);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900104 va_end(args);
105
Glen Leeef2b7842015-09-24 18:14:55 +0900106 linux_wlan_dbg(buf);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900107 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900108}
109
110static CHIP_PS_STATE_T genuChipPSstate = CHIP_WAKEDUP;
111
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900112/*acquire_bus() and release_bus() are made static inline functions*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900113/*as a temporary workaround to fix a problem of receiving*/
114/*unknown interrupt from FW*/
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900115static inline void acquire_bus(BUS_ACQUIRE_T acquire)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900116{
117
Glen Lee187f1ef2015-09-24 18:15:01 +0900118 mutex_lock(&g_linux_wlan->hif_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900119 #ifndef WILC_OPTIMIZE_SLEEP_INT
120 if (genuChipPSstate != CHIP_WAKEDUP)
121 #endif
122 {
123 if (acquire == ACQUIRE_AND_WAKEUP)
124 chip_wakeup();
125 }
126
127}
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900128static inline void release_bus(BUS_RELEASE_T release)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900129{
130 #ifdef WILC_OPTIMIZE_SLEEP_INT
131 if (release == RELEASE_ALLOW_SLEEP)
132 chip_allow_sleep();
133 #endif
Glen Lee187f1ef2015-09-24 18:15:01 +0900134 mutex_unlock(&g_linux_wlan->hif_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900135}
136/********************************************
137 *
138 * Queue
139 *
140 ********************************************/
141
142static void wilc_wlan_txq_remove(struct txq_entry_t *tqe)
143{
144
145 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
146 /* unsigned long flags; */
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900147 if (tqe == p->txq_head) {
148
149 p->txq_head = tqe->next;
150 if (p->txq_head)
151 p->txq_head->prev = NULL;
152
153
154 } else if (tqe == p->txq_tail) {
155 p->txq_tail = (tqe->prev);
156 if (p->txq_tail)
157 p->txq_tail->next = NULL;
158 } else {
159 tqe->prev->next = tqe->next;
160 tqe->next->prev = tqe->prev;
161 }
162 p->txq_entries -= 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900163
164}
165
166static struct txq_entry_t *wilc_wlan_txq_remove_from_head(void)
167{
168 struct txq_entry_t *tqe;
169 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
170 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900171
Glen Lee85e57562015-09-24 18:14:56 +0900172 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900173 if (p->txq_head) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900174 tqe = p->txq_head;
175 p->txq_head = tqe->next;
176 if (p->txq_head) {
177 p->txq_head->prev = NULL;
178 }
179 p->txq_entries -= 1;
180
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900181
182
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900183
184 } else {
185 tqe = NULL;
186 }
Glen Lee85e57562015-09-24 18:14:56 +0900187 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900188 return tqe;
189}
190
191static void wilc_wlan_txq_add_to_tail(struct txq_entry_t *tqe)
192{
193 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
194 unsigned long flags;
Glen Lee85e57562015-09-24 18:14:56 +0900195 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900196
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900197 if (p->txq_head == NULL) {
198 tqe->next = NULL;
199 tqe->prev = NULL;
200 p->txq_head = tqe;
201 p->txq_tail = tqe;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900202 } else {
203 tqe->next = NULL;
204 tqe->prev = p->txq_tail;
205 p->txq_tail->next = tqe;
206 p->txq_tail = tqe;
207 }
208 p->txq_entries += 1;
209 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900210
Glen Lee85e57562015-09-24 18:14:56 +0900211 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900212
213 /**
214 * wake up TX queue
215 **/
216 PRINT_D(TX_DBG, "Wake the txq_handling\n");
217
Glen Lee5cd63632015-09-24 18:14:58 +0900218 up(&g_linux_wlan->txq_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900219}
220
221static int wilc_wlan_txq_add_to_head(struct txq_entry_t *tqe)
222{
223 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
224 unsigned long flags;
Glen Leeb002e202015-09-24 18:15:05 +0900225 if (linux_wlan_lock_timeout(&g_linux_wlan->txq_add_to_head_cs,
226 CFG_PKTS_TIMEOUT))
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900227 return -1;
228
Glen Lee85e57562015-09-24 18:14:56 +0900229 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900230
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900231 if (p->txq_head == NULL) {
232 tqe->next = NULL;
233 tqe->prev = NULL;
234 p->txq_head = tqe;
235 p->txq_tail = tqe;
236 } else {
237 tqe->next = p->txq_head;
238 tqe->prev = NULL;
239 p->txq_head->prev = tqe;
240 p->txq_head = tqe;
241 }
242 p->txq_entries += 1;
243 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900244
Glen Lee85e57562015-09-24 18:14:56 +0900245 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Glen Leed5a63a82015-09-24 18:15:00 +0900246 up(&g_linux_wlan->txq_add_to_head_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900247
248
249 /**
250 * wake up TX queue
251 **/
Glen Lee5cd63632015-09-24 18:14:58 +0900252 up(&g_linux_wlan->txq_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900253 PRINT_D(TX_DBG, "Wake up the txq_handler\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900254
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900255 return 0;
256
257}
258
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900259u32 Statisitcs_totalAcks = 0, Statisitcs_DroppedAcks = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900260
261#ifdef TCP_ACK_FILTER
262struct Ack_session_info;
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530263struct Ack_session_info {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900264 u32 Ack_seq_num;
265 u32 Bigger_Ack_num;
Chaehyun Limec53adf2015-09-15 14:06:15 +0900266 u16 src_port;
267 u16 dst_port;
268 u16 status;
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530269};
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900270
271typedef struct {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900272 u32 ack_num;
273 u32 Session_index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900274 struct txq_entry_t *txqe;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900275} Pending_Acks_info_t /*Ack_info_t*/;
276
277
278
279
280struct Ack_session_info *Free_head;
281struct Ack_session_info *Alloc_head;
282
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900283#define NOT_TCP_ACK (-1)
284
285#define MAX_TCP_SESSION 25
286#define MAX_PENDING_ACKS 256
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530287struct Ack_session_info Acks_keep_track_info[2 * MAX_TCP_SESSION];
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900288Pending_Acks_info_t Pending_Acks_info[MAX_PENDING_ACKS];
289
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900290u32 PendingAcks_arrBase;
291u32 Opened_TCP_session;
292u32 Pending_Acks;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900293
294
295
Chaehyun Limfed16f22015-09-17 16:48:43 +0900296static inline int Init_TCP_tracking(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900297{
298
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900299 return 0;
300
301}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900302static inline int add_TCP_track_session(u32 src_prt, u32 dst_prt, u32 seq)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900303{
304 Acks_keep_track_info[Opened_TCP_session].Ack_seq_num = seq;
305 Acks_keep_track_info[Opened_TCP_session].Bigger_Ack_num = 0;
306 Acks_keep_track_info[Opened_TCP_session].src_port = src_prt;
307 Acks_keep_track_info[Opened_TCP_session].dst_port = dst_prt;
308 Opened_TCP_session++;
309
310 PRINT_D(TCP_ENH, "TCP Session %d to Ack %d\n", Opened_TCP_session, seq);
311 return 0;
312}
313
Chaehyun Limfed16f22015-09-17 16:48:43 +0900314static inline int Update_TCP_track_session(u32 index, u32 Ack)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900315{
316
317 if (Ack > Acks_keep_track_info[index].Bigger_Ack_num) {
318 Acks_keep_track_info[index].Bigger_Ack_num = Ack;
319 }
320 return 0;
321
322}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900323static inline int add_TCP_Pending_Ack(u32 Ack, u32 Session_index, struct txq_entry_t *txqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900324{
325 Statisitcs_totalAcks++;
326 if (Pending_Acks < MAX_PENDING_ACKS) {
327 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].ack_num = Ack;
328 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].txqe = txqe;
329 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].Session_index = Session_index;
330 txqe->tcp_PendingAck_index = PendingAcks_arrBase + Pending_Acks;
331 Pending_Acks++;
332
333 } else {
334
335 }
336 return 0;
337}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900338static inline int remove_TCP_related(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900339{
340 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
341 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900342
Glen Lee85e57562015-09-24 18:14:56 +0900343 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900344
Glen Lee85e57562015-09-24 18:14:56 +0900345 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900346 return 0;
347}
348
Chaehyun Limfed16f22015-09-17 16:48:43 +0900349static inline int tcp_process(struct txq_entry_t *tqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900350{
351 int ret;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900352 u8 *eth_hdr_ptr;
353 u8 *buffer = tqe->buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900354 unsigned short h_proto;
355 int i;
356 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
357 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900358
Glen Lee85e57562015-09-24 18:14:56 +0900359 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900360
361 eth_hdr_ptr = &buffer[0];
362 h_proto = ntohs(*((unsigned short *)&eth_hdr_ptr[12]));
363 if (h_proto == 0x0800) { /* IP */
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900364 u8 *ip_hdr_ptr;
365 u8 protocol;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900366
367 ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN];
368 protocol = ip_hdr_ptr[9];
369
370
371 if (protocol == 0x06) {
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900372 u8 *tcp_hdr_ptr;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900373 u32 IHL, Total_Length, Data_offset;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900374
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900375 tcp_hdr_ptr = &ip_hdr_ptr[IP_HDR_LEN];
376 IHL = (ip_hdr_ptr[0] & 0xf) << 2;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900377 Total_Length = (((u32)ip_hdr_ptr[2]) << 8) + ((u32)ip_hdr_ptr[3]);
378 Data_offset = (((u32)tcp_hdr_ptr[12] & 0xf0) >> 2);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900379 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 +0900380 u32 seq_no, Ack_no;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900381
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900382 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 +0900383
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900384 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 +0900385
386
387 for (i = 0; i < Opened_TCP_session; i++) {
388 if (Acks_keep_track_info[i].Ack_seq_num == seq_no) {
389 Update_TCP_track_session(i, Ack_no);
390 break;
391 }
392 }
393 if (i == Opened_TCP_session) {
394 add_TCP_track_session(0, 0, seq_no);
395 }
396 add_TCP_Pending_Ack(Ack_no, i, tqe);
397
398
399 }
400
401 } else {
402 ret = 0;
403 }
404 } else {
405 ret = 0;
406 }
Glen Lee85e57562015-09-24 18:14:56 +0900407 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900408 return ret;
409}
410
411
412static int wilc_wlan_txq_filter_dup_tcp_ack(void)
413{
414
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900415 u32 i = 0;
416 u32 Dropped = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900417 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
418
Glen Lee85e57562015-09-24 18:14:56 +0900419 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, p->txq_spinlock_flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900420 for (i = PendingAcks_arrBase; i < (PendingAcks_arrBase + Pending_Acks); i++) {
421 if (Pending_Acks_info[i].ack_num < Acks_keep_track_info[Pending_Acks_info[i].Session_index].Bigger_Ack_num) {
422 struct txq_entry_t *tqe;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900423
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530424 PRINT_D(TCP_ENH, "DROP ACK: %u\n", Pending_Acks_info[i].ack_num);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900425 tqe = Pending_Acks_info[i].txqe;
426 if (tqe) {
427 wilc_wlan_txq_remove(tqe);
428 Statisitcs_DroppedAcks++;
429 tqe->status = 1; /* mark the packet send */
430 if (tqe->tx_complete_func)
431 tqe->tx_complete_func(tqe->priv, tqe->status);
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -0700432 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900433 Dropped++;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900434 }
435 }
436 }
437 Pending_Acks = 0;
438 Opened_TCP_session = 0;
439
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530440 if (PendingAcks_arrBase == 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900441 PendingAcks_arrBase = MAX_TCP_SESSION;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530442 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900443 PendingAcks_arrBase = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900444
445
Glen Lee85e57562015-09-24 18:14:56 +0900446 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock,
447 p->txq_spinlock_flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900448
449 while (Dropped > 0) {
450 /*consume the semaphore count of the removed packet*/
Glen Leeb002e202015-09-24 18:15:05 +0900451 linux_wlan_lock_timeout(&g_linux_wlan->txq_event, 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900452 Dropped--;
453 }
454
455 return 1;
456}
457#endif
458
Dean Lee72ed4dc2015-06-12 14:11:44 +0900459bool EnableTCPAckFilter = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900460
Dean Lee72ed4dc2015-06-12 14:11:44 +0900461void Enable_TCP_ACK_Filter(bool value)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900462{
463 EnableTCPAckFilter = value;
464}
465
Dean Lee72ed4dc2015-06-12 14:11:44 +0900466bool is_TCP_ACK_Filter_Enabled(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900467{
468 return EnableTCPAckFilter;
469}
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900470
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900471static int wilc_wlan_txq_add_cfg_pkt(u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900472{
473 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
474 struct txq_entry_t *tqe;
475
476 PRINT_D(TX_DBG, "Adding config packet ...\n");
477 if (p->quit) {
478 PRINT_D(TX_DBG, "Return due to clear function\n");
Glen Lee6a3b94f2015-09-24 18:14:59 +0900479 up(&g_linux_wlan->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900480 return 0;
481 }
482
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700483 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900484 if (tqe == NULL) {
485 PRINT_ER("Failed to allocate memory\n");
486 return 0;
487 }
488
489 tqe->type = WILC_CFG_PKT;
490 tqe->buffer = buffer;
491 tqe->buffer_size = buffer_size;
492 tqe->tx_complete_func = NULL;
493 tqe->priv = NULL;
494#ifdef TCP_ACK_FILTER
495 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
496#endif
497 /**
498 * Configuration packet always at the front
499 **/
500 PRINT_D(TX_DBG, "Adding the config packet at the Queue tail\n");
501
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900502 if (wilc_wlan_txq_add_to_head(tqe))
503 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900504 return 1;
505}
506
Glen Lee8fc84a62015-10-01 16:03:35 +0900507int wilc_wlan_txq_add_net_pkt(void *priv, u8 *buffer, u32 buffer_size,
508 wilc_tx_complete_func_t func)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900509{
510 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
511 struct txq_entry_t *tqe;
512
513 if (p->quit)
514 return 0;
515
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700516 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900517
518 if (tqe == NULL)
519 return 0;
520 tqe->type = WILC_NET_PKT;
521 tqe->buffer = buffer;
522 tqe->buffer_size = buffer_size;
523 tqe->tx_complete_func = func;
524 tqe->priv = priv;
525
526 PRINT_D(TX_DBG, "Adding mgmt packet at the Queue tail\n");
527#ifdef TCP_ACK_FILTER
528 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
Abdul Hussain5a66bf22015-06-16 09:44:06 +0000529 if (is_TCP_ACK_Filter_Enabled())
Glen Lee25a84832015-09-16 18:53:22 +0900530 tcp_process(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900531#endif
532 wilc_wlan_txq_add_to_tail(tqe);
533 /*return number of itemes in the queue*/
534 return p->txq_entries;
535}
Glen Leefcc6ef92015-09-16 18:53:21 +0900536
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900537int 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 +0900538{
539
540 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
541 struct txq_entry_t *tqe;
542
543 if (p->quit)
544 return 0;
545
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700546 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900547
548 if (tqe == NULL)
549 return 0;
550 tqe->type = WILC_MGMT_PKT;
551 tqe->buffer = buffer;
552 tqe->buffer_size = buffer_size;
553 tqe->tx_complete_func = func;
554 tqe->priv = priv;
555#ifdef TCP_ACK_FILTER
556 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
557#endif
558 PRINT_D(TX_DBG, "Adding Network packet at the Queue tail\n");
559 wilc_wlan_txq_add_to_tail(tqe);
560 return 1;
561}
Glen Leefcc6ef92015-09-16 18:53:21 +0900562
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900563static struct txq_entry_t *wilc_wlan_txq_get_first(void)
564{
565 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
566 struct txq_entry_t *tqe;
567 unsigned long flags;
568
Glen Lee85e57562015-09-24 18:14:56 +0900569 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900570
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900571 tqe = p->txq_head;
572
Glen Lee85e57562015-09-24 18:14:56 +0900573 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900574
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900575
576 return tqe;
577}
578
579static struct txq_entry_t *wilc_wlan_txq_get_next(struct txq_entry_t *tqe)
580{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900581 unsigned long flags;
Glen Lee85e57562015-09-24 18:14:56 +0900582 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900583
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900584 tqe = tqe->next;
Glen Lee85e57562015-09-24 18:14:56 +0900585 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900586
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900587
588 return tqe;
589}
590
591static int wilc_wlan_rxq_add(struct rxq_entry_t *rqe)
592{
593 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
594
595 if (p->quit)
596 return 0;
597
Glen Lee645db602015-09-24 18:14:57 +0900598 mutex_lock(&g_linux_wlan->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900599 if (p->rxq_head == NULL) {
600 PRINT_D(RX_DBG, "Add to Queue head\n");
601 rqe->next = NULL;
602 p->rxq_head = rqe;
603 p->rxq_tail = rqe;
604 } else {
605 PRINT_D(RX_DBG, "Add to Queue tail\n");
606 p->rxq_tail->next = rqe;
607 rqe->next = NULL;
608 p->rxq_tail = rqe;
609 }
610 p->rxq_entries += 1;
611 PRINT_D(RX_DBG, "Number of queue entries: %d\n", p->rxq_entries);
Glen Lee645db602015-09-24 18:14:57 +0900612 mutex_unlock(&g_linux_wlan->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900613 return p->rxq_entries;
614}
615
616static struct rxq_entry_t *wilc_wlan_rxq_remove(void)
617{
618 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
619
620 PRINT_D(RX_DBG, "Getting rxQ element\n");
621 if (p->rxq_head) {
622 struct rxq_entry_t *rqe;
623
Glen Lee645db602015-09-24 18:14:57 +0900624 mutex_lock(&g_linux_wlan->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900625 rqe = p->rxq_head;
626 p->rxq_head = p->rxq_head->next;
627 p->rxq_entries -= 1;
628 PRINT_D(RX_DBG, "RXQ entries decreased\n");
Glen Lee645db602015-09-24 18:14:57 +0900629 mutex_unlock(&g_linux_wlan->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900630 return rqe;
631 }
632 PRINT_D(RX_DBG, "Nothing to get from Q\n");
633 return NULL;
634}
635
636
637/********************************************
638 *
639 * Power Save handle functions
640 *
641 ********************************************/
642
643
644
645#ifdef WILC_OPTIMIZE_SLEEP_INT
646
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900647static inline void chip_allow_sleep(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900648{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900649 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900650
651 /* Clear bit 1 */
652 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
653
Anish Bhattffda2032015-09-29 12:15:49 -0700654 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900655}
656
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900657static inline void chip_wakeup(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900658{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900659 u32 reg, clk_status_reg, trials = 0;
660 u32 sleep_time;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900661
662 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
663 do {
664 g_wlan.hif_func.hif_read_reg(1, &reg);
665 /* Set bit 1 */
Anish Bhattffda2032015-09-29 12:15:49 -0700666 g_wlan.hif_func.hif_write_reg(1, reg | BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900667
668 /* Clear bit 1*/
Anish Bhattffda2032015-09-29 12:15:49 -0700669 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900670
671 do {
672 /* Wait for the chip to stabilize*/
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -0700673 usleep_range(2 * 1000, 2 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900674 /* Make sure chip is awake. This is an extra step that can be removed */
675 /* later to avoid the bus access overhead */
Dean Lee72ed4dc2015-06-12 14:11:44 +0900676 if ((wilc_get_chipid(true) == 0)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900677 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
678 }
Dean Lee72ed4dc2015-06-12 14:11:44 +0900679 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900680
Dean Lee72ed4dc2015-06-12 14:11:44 +0900681 } while (wilc_get_chipid(true) == 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900682 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
683 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
684 do {
685 /* Set bit 1 */
Anish Bhattffda2032015-09-29 12:15:49 -0700686 g_wlan.hif_func.hif_write_reg(0xf0, reg | BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900687
688 /* Check the clock status */
689 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
690
691 /* in case of clocks off, wait 2ms, and check it again. */
692 /* if still off, wait for another 2ms, for a total wait of 6ms. */
693 /* If still off, redo the wake up sequence */
694 while (((clk_status_reg & 0x1) == 0) && (((++trials) % 3) == 0)) {
695 /* Wait for the chip to stabilize*/
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -0700696 usleep_range(2 * 1000, 2 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900697
698 /* Make sure chip is awake. This is an extra step that can be removed */
699 /* later to avoid the bus access overhead */
700 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
701
702 if ((clk_status_reg & 0x1) == 0) {
703 wilc_debug(N_ERR, "clocks still OFF. Wake up failed\n");
704 }
705 }
706 /* in case of failure, Reset the wakeup bit to introduce a new edge on the next loop */
707 if ((clk_status_reg & 0x1) == 0) {
708 /* Reset bit 0 */
Anish Bhattffda2032015-09-29 12:15:49 -0700709 g_wlan.hif_func.hif_write_reg(0xf0, reg &
710 (~BIT(0)));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900711 }
712 } while ((clk_status_reg & 0x1) == 0);
713 }
714
715
716 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
717 g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -0700718 reg &= ~BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900719 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
720
Dean Lee72ed4dc2015-06-12 14:11:44 +0900721 if (wilc_get_chipid(false) >= 0x1002b0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900722 /* Enable PALDO back right after wakeup */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900723 u32 val32;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900724
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900725 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700726 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900727 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
728
729 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700730 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900731 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
732 }
733 }
734 genuChipPSstate = CHIP_WAKEDUP;
735}
736#else
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900737static inline void chip_wakeup(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900738{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900739 u32 reg, trials = 0;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900740
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900741 do {
742 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
743 g_wlan.hif_func.hif_read_reg(1, &reg);
744 /* Make sure bit 1 is 0 before we start. */
Anish Bhattffda2032015-09-29 12:15:49 -0700745 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900746 /* Set bit 1 */
Anish Bhattffda2032015-09-29 12:15:49 -0700747 g_wlan.hif_func.hif_write_reg(1, reg | BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900748 /* Clear bit 1*/
Anish Bhattffda2032015-09-29 12:15:49 -0700749 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900750 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
751 /* Make sure bit 0 is 0 before we start. */
752 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -0700753 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900754 /* Set bit 1 */
Anish Bhattffda2032015-09-29 12:15:49 -0700755 g_wlan.hif_func.hif_write_reg(0xf0, reg | BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900756 /* Clear bit 1 */
Anish Bhattffda2032015-09-29 12:15:49 -0700757 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900758 }
759
760 do {
761 /* Wait for the chip to stabilize*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900762 mdelay(3);
763
764 /* Make sure chip is awake. This is an extra step that can be removed */
765 /* later to avoid the bus access overhead */
Dean Lee72ed4dc2015-06-12 14:11:44 +0900766 if ((wilc_get_chipid(true) == 0)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900767 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
768 }
Dean Lee72ed4dc2015-06-12 14:11:44 +0900769 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900770
Dean Lee72ed4dc2015-06-12 14:11:44 +0900771 } while (wilc_get_chipid(true) == 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900772
773 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
774 g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -0700775 reg &= ~BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900776 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
777
Dean Lee72ed4dc2015-06-12 14:11:44 +0900778 if (wilc_get_chipid(false) >= 0x1002b0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900779 /* Enable PALDO back right after wakeup */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900780 u32 val32;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900781
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900782 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700783 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900784 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
785
786 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700787 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900788 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
789 }
790 }
791 genuChipPSstate = CHIP_WAKEDUP;
792}
793#endif
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900794void chip_sleep_manually(u32 u32SleepTime)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900795{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900796 if (genuChipPSstate != CHIP_WAKEDUP) {
797 /* chip is already sleeping. Do nothing */
798 return;
799 }
800 acquire_bus(ACQUIRE_ONLY);
801
802#ifdef WILC_OPTIMIZE_SLEEP_INT
803 chip_allow_sleep();
804#endif
805
806 /* Trigger the manual sleep interrupt */
807 g_wlan.hif_func.hif_write_reg(0x10a8, 1);
808
809 genuChipPSstate = CHIP_SLEEPING_MANUAL;
810 release_bus(RELEASE_ONLY);
811
812}
813
814
815/********************************************
816 *
817 * Tx, Rx queue handle functions
818 *
819 ********************************************/
Glen Leef590c4c2015-10-01 16:03:36 +0900820int wilc_wlan_handle_txq(u32 *pu32TxqCount)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900821{
822 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
823 int i, entries = 0;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900824 u32 sum;
825 u32 reg;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900826 u8 *txb = p->tx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900827 u32 offset = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900828 int vmm_sz = 0;
829 struct txq_entry_t *tqe;
830 int ret = 0;
831 int counter;
832 int timeout;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900833 u32 vmm_table[WILC_VMM_TBL_SIZE];
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900834
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900835 p->txq_exit = 0;
836 do {
837 if (p->quit)
838 break;
839
Glen Leeb002e202015-09-24 18:15:05 +0900840 linux_wlan_lock_timeout(&g_linux_wlan->txq_add_to_head_cs,
841 CFG_PKTS_TIMEOUT);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900842#ifdef TCP_ACK_FILTER
843 wilc_wlan_txq_filter_dup_tcp_ack();
844#endif
845 /**
846 * build the vmm list
847 **/
848 PRINT_D(TX_DBG, "Getting the head of the TxQ\n");
849 tqe = wilc_wlan_txq_get_first();
850 i = 0;
851 sum = 0;
852 do {
853 /* if ((tqe != NULL) && (i < (8)) && */
854 /* if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE-1)) && */
855 if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE - 1)) /* reserve last entry to 0 */) {
856
857 if (tqe->type == WILC_CFG_PKT) {
858 vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET;
859 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900860 else if (tqe->type == WILC_NET_PKT) {
861 vmm_sz = ETH_ETHERNET_HDR_OFFSET;
862 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900863 else {
864 vmm_sz = HOST_HDR_OFFSET;
865 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900866 vmm_sz += tqe->buffer_size;
867 PRINT_D(TX_DBG, "VMM Size before alignment = %d\n", vmm_sz);
868 if (vmm_sz & 0x3) { /* has to be word aligned */
869 vmm_sz = (vmm_sz + 4) & ~0x3;
870 }
Glen Lee7015b5d2015-09-24 18:15:02 +0900871 if ((sum + vmm_sz) > LINUX_TX_SIZE) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900872 break;
873 }
874 PRINT_D(TX_DBG, "VMM Size AFTER alignment = %d\n", vmm_sz);
875 vmm_table[i] = vmm_sz / 4; /* table take the word size */
876 PRINT_D(TX_DBG, "VMMTable entry size = %d\n", vmm_table[i]);
877
878 if (tqe->type == WILC_CFG_PKT) {
Anish Bhattffda2032015-09-29 12:15:49 -0700879 vmm_table[i] |= BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900880 PRINT_D(TX_DBG, "VMMTable entry changed for CFG packet = %d\n", vmm_table[i]);
881 }
882#ifdef BIG_ENDIAN
883 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
884#endif
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900885
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900886 i++;
887 sum += vmm_sz;
888 PRINT_D(TX_DBG, "sum = %d\n", sum);
889 tqe = wilc_wlan_txq_get_next(tqe);
890 } else {
891 break;
892 }
893 } while (1);
894
895 if (i == 0) { /* nothing in the queue */
896 PRINT_D(TX_DBG, "Nothing in TX-Q\n");
897 break;
898 } else {
899 PRINT_D(TX_DBG, "Mark the last entry in VMM table - number of previous entries = %d\n", i);
900 vmm_table[i] = 0x0; /* mark the last element to 0 */
901 }
902 acquire_bus(ACQUIRE_AND_WAKEUP);
903 counter = 0;
904 do {
905
906 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg);
907 if (!ret) {
908 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg vmm_tbl_entry..\n");
909 break;
910 }
911
912 if ((reg & 0x1) == 0) {
913 /**
914 * write to vmm table
915 **/
916 PRINT_D(TX_DBG, "Writing VMM table ... with Size = %d\n", ((i + 1) * 4));
917 break;
918 } else {
919 counter++;
920 if (counter > 200) {
921 counter = 0;
922 PRINT_D(TX_DBG, "Looping in tx ctrl , forcce quit\n");
923 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, 0);
924 break;
925 }
926 /**
927 * wait for vmm table is ready
928 **/
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530929 PRINT_WRN(GENERIC_DBG, "[wilc txq]: warn, vmm table not clear yet, wait...\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900930 release_bus(RELEASE_ALLOW_SLEEP);
Greg Kroah-Hartman2b922cb2015-09-04 09:30:51 -0700931 usleep_range(3000, 3000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900932 acquire_bus(ACQUIRE_AND_WAKEUP);
933 }
934 } while (!p->quit);
935
936 if (!ret) {
937 goto _end_;
938 }
939
940 timeout = 200;
941 do {
942
943 /**
944 * write to vmm table
945 **/
Chaehyun Limc3ca6372015-09-20 15:51:19 +0900946 ret = p->hif_func.hif_block_tx(WILC_VMM_TBL_RX_SHADOW_BASE, (u8 *)vmm_table, ((i + 1) * 4));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900947 if (!ret) {
948 wilc_debug(N_ERR, "ERR block TX of VMM table.\n");
949 break;
950 }
951
952
953 /**
954 * interrupt firmware
955 **/
956 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x2);
957 if (!ret) {
958 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg host_vmm_ctl..\n");
959 break;
960 }
961
962 /**
963 * wait for confirm...
964 **/
965
966 do {
967 ret = p->hif_func.hif_read_reg(WILC_HOST_VMM_CTL, &reg);
968 if (!ret) {
969 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg host_vmm_ctl..\n");
970 break;
971 }
972 if ((reg >> 2) & 0x1) {
973 /**
974 * Get the entries
975 **/
976 entries = ((reg >> 3) & 0x3f);
977 /* entries = ((reg>>3)&0x2f); */
978 break;
979 } else {
980 release_bus(RELEASE_ALLOW_SLEEP);
Greg Kroah-Hartman2b922cb2015-09-04 09:30:51 -0700981 usleep_range(3000, 3000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900982 acquire_bus(ACQUIRE_AND_WAKEUP);
983 PRINT_WRN(GENERIC_DBG, "Can't get VMM entery - reg = %2x\n", reg);
984 }
985 } while (--timeout);
986 if (timeout <= 0) {
987 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x0);
988 break;
989 }
990
991 if (!ret) {
992 break;
993 }
994
995 if (entries == 0) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530996 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 +0900997
998 /* undo the transaction. */
999 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg);
1000 if (!ret) {
1001 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg WILC_HOST_TX_CTRL..\n");
1002 break;
1003 }
Anish Bhattffda2032015-09-29 12:15:49 -07001004 reg &= ~BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001005 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, reg);
1006 if (!ret) {
1007 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg WILC_HOST_TX_CTRL..\n");
1008 break;
1009 }
1010 break;
1011 } else {
1012 break;
1013 }
1014 } while (1);
1015
1016 if (!ret) {
1017 goto _end_;
1018 }
1019 if (entries == 0) {
1020 ret = WILC_TX_ERR_NO_BUF;
1021 goto _end_;
1022 }
1023
1024 /* since copying data into txb takes some time, then
1025 * allow the bus lock to be released let the RX task go. */
1026 release_bus(RELEASE_ALLOW_SLEEP);
1027
1028 /**
1029 * Copy data to the TX buffer
1030 **/
1031 offset = 0;
1032 i = 0;
1033 do {
1034 tqe = wilc_wlan_txq_remove_from_head();
1035 if (tqe != NULL && (vmm_table[i] != 0)) {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001036 u32 header, buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001037
1038#ifdef BIG_ENDIAN
1039 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
1040#endif
1041 vmm_sz = (vmm_table[i] & 0x3ff); /* in word unit */
1042 vmm_sz *= 4;
1043 header = (tqe->type << 31) | (tqe->buffer_size << 15) | vmm_sz;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301044 if (tqe->type == WILC_MGMT_PKT)
Anish Bhattffda2032015-09-29 12:15:49 -07001045 header |= BIT(30);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301046 else
Anish Bhattffda2032015-09-29 12:15:49 -07001047 header &= ~BIT(30);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001048
1049#ifdef BIG_ENDIAN
1050 header = BYTE_SWAP(header);
1051#endif
1052 memcpy(&txb[offset], &header, 4);
1053 if (tqe->type == WILC_CFG_PKT) {
1054 buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET;
1055 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001056 else if (tqe->type == WILC_NET_PKT) {
1057 char *pBSSID = ((struct tx_complete_data *)(tqe->priv))->pBssid;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001058
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001059 buffer_offset = ETH_ETHERNET_HDR_OFFSET;
1060 /* copy the bssid at the sart of the buffer */
1061 memcpy(&txb[offset + 4], pBSSID, 6);
1062 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001063 else {
1064 buffer_offset = HOST_HDR_OFFSET;
1065 }
1066
1067 memcpy(&txb[offset + buffer_offset], tqe->buffer, tqe->buffer_size);
1068 offset += vmm_sz;
1069 i++;
1070 tqe->status = 1; /* mark the packet send */
1071 if (tqe->tx_complete_func)
1072 tqe->tx_complete_func(tqe->priv, tqe->status);
1073 #ifdef TCP_ACK_FILTER
1074 if (tqe->tcp_PendingAck_index != NOT_TCP_ACK) {
1075 Pending_Acks_info[tqe->tcp_PendingAck_index].txqe = NULL;
1076 }
1077 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001078 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001079 } else {
1080 break;
1081 }
1082 } while (--entries);
1083
1084 /**
1085 * lock the bus
1086 **/
1087 acquire_bus(ACQUIRE_AND_WAKEUP);
1088
1089 ret = p->hif_func.hif_clear_int_ext(ENABLE_TX_VMM);
1090 if (!ret) {
1091 wilc_debug(N_ERR, "[wilc txq]: fail can't start tx VMM ...\n");
1092 goto _end_;
1093 }
1094
1095 /**
1096 * transfer
1097 **/
1098 ret = p->hif_func.hif_block_tx_ext(0, txb, offset);
1099 if (!ret) {
1100 wilc_debug(N_ERR, "[wilc txq]: fail can't block tx ext...\n");
1101 goto _end_;
1102 }
1103
1104_end_:
1105
1106 release_bus(RELEASE_ALLOW_SLEEP);
1107 if (ret != 1)
1108 break;
1109 } while (0);
Glen Leed5a63a82015-09-24 18:15:00 +09001110 up(&g_linux_wlan->txq_add_to_head_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001111
1112 p->txq_exit = 1;
1113 PRINT_D(TX_DBG, "THREAD: Exiting txq\n");
1114 /* return tx[]q count */
1115 *pu32TxqCount = p->txq_entries;
1116 return ret;
1117}
1118
1119static void wilc_wlan_handle_rxq(void)
1120{
1121 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1122 int offset = 0, size, has_packet = 0;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001123 u8 *buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001124 struct rxq_entry_t *rqe;
1125
1126 p->rxq_exit = 0;
1127
1128
1129
1130
1131 do {
1132 if (p->quit) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301133 PRINT_D(RX_DBG, "exit 1st do-while due to Clean_UP function\n");
Glen Lee6a3b94f2015-09-24 18:14:59 +09001134 up(&g_linux_wlan->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001135 break;
1136 }
1137 rqe = wilc_wlan_rxq_remove();
1138 if (rqe == NULL) {
1139 PRINT_D(RX_DBG, "nothing in the queue - exit 1st do-while\n");
1140 break;
1141 }
1142 buffer = rqe->buffer;
1143 size = rqe->buffer_size;
1144 PRINT_D(RX_DBG, "rxQ entery Size = %d - Address = %p\n", size, buffer);
1145 offset = 0;
1146
1147
1148
1149 do {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001150 u32 header;
1151 u32 pkt_len, pkt_offset, tp_len;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001152 int is_cfg_packet;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001153
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001154 PRINT_D(RX_DBG, "In the 2nd do-while\n");
1155 memcpy(&header, &buffer[offset], 4);
1156#ifdef BIG_ENDIAN
1157 header = BYTE_SWAP(header);
1158#endif
1159 PRINT_D(RX_DBG, "Header = %04x - Offset = %d\n", header, offset);
1160
1161
1162
1163 is_cfg_packet = (header >> 31) & 0x1;
1164 pkt_offset = (header >> 22) & 0x1ff;
1165 tp_len = (header >> 11) & 0x7ff;
1166 pkt_len = header & 0x7ff;
1167
1168 if (pkt_len == 0 || tp_len == 0) {
1169 wilc_debug(N_RXQ, "[wilc rxq]: data corrupt, packet len or tp_len is 0 [%d][%d]\n", pkt_len, tp_len);
1170 break;
1171 }
1172
1173/*bug 3887: [AP] Allow Management frames to be passed to the host*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001174 #define IS_MANAGMEMENT 0x100
1175 #define IS_MANAGMEMENT_CALLBACK 0x080
1176 #define IS_MGMT_STATUS_SUCCES 0x040
1177
1178
1179 if (pkt_offset & IS_MANAGMEMENT) {
1180 /* reset mgmt indicator bit, to use pkt_offeset in furthur calculations */
1181 pkt_offset &= ~(IS_MANAGMEMENT | IS_MANAGMEMENT_CALLBACK | IS_MGMT_STATUS_SUCCES);
1182
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001183 WILC_WFI_mgmt_rx(&buffer[offset + HOST_HDR_OFFSET], pkt_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001184 }
1185 /* BUG4530 fix */
1186 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001187 {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001188
1189 if (!is_cfg_packet) {
Glen Lee63611672015-09-24 18:14:52 +09001190 if (pkt_len > 0) {
1191 frmw_to_linux(&buffer[offset],
1192 pkt_len,
1193 pkt_offset);
1194 has_packet = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001195 }
1196 } else {
1197 wilc_cfg_rsp_t rsp;
1198
1199
1200
Glen Lee1fea5932015-09-24 18:15:06 +09001201 mac_cfg.rx_indicate(&buffer[pkt_offset + offset], pkt_len, &rsp);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001202 if (rsp.type == WILC_CFG_RSP) {
1203 /**
1204 * wake up the waiting task...
1205 **/
1206 PRINT_D(RX_DBG, "p->cfg_seq_no = %d - rsp.seq_no = %d\n", p->cfg_seq_no, rsp.seq_no);
1207 if (p->cfg_seq_no == rsp.seq_no) {
Glen Lee6a3b94f2015-09-24 18:14:59 +09001208 up(&g_linux_wlan->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001209 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001210 } else if (rsp.type == WILC_CFG_RSP_STATUS) {
1211 /**
1212 * Call back to indicate status...
1213 **/
Glen Lee4417d3d2015-09-24 18:14:53 +09001214 linux_wlan_mac_indicate(WILC_MAC_INDICATE_STATUS);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001215
1216 } else if (rsp.type == WILC_CFG_RSP_SCAN) {
Glen Lee4417d3d2015-09-24 18:14:53 +09001217 linux_wlan_mac_indicate(WILC_MAC_INDICATE_SCAN);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001218 }
1219 }
1220 }
1221 offset += tp_len;
1222 if (offset >= size)
1223 break;
1224 } while (1);
1225
1226
1227#ifndef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001228 kfree(buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001229#endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001230 kfree(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001231
1232 if (has_packet) {
Glen Leec0cadaa2015-09-24 18:14:54 +09001233 linux_wlan_rx_complete();
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001234 }
1235 } while (1);
1236
1237 p->rxq_exit = 1;
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301238 PRINT_D(RX_DBG, "THREAD: Exiting RX thread\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001239}
1240
1241/********************************************
1242 *
1243 * Fast DMA Isr
1244 *
1245 ********************************************/
1246static void wilc_unknown_isr_ext(void)
1247{
1248 g_wlan.hif_func.hif_clear_int_ext(0);
1249}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001250static void wilc_pllupdate_isr_ext(u32 int_stats)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001251{
1252
1253 int trials = 10;
1254
1255 g_wlan.hif_func.hif_clear_int_ext(PLL_INT_CLR);
1256
1257 /* Waiting for PLL */
Greg Kroah-Hartmanc2e4c0f2015-09-03 19:09:50 -07001258 mdelay(WILC_PLL_TO);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001259
1260 /* poll till read a valid data */
Dean Lee72ed4dc2015-06-12 14:11:44 +09001261 while (!(ISWILC1000(wilc_get_chipid(true)) && --trials)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001262 PRINT_D(TX_DBG, "PLL update retrying\n");
Greg Kroah-Hartmanc2e4c0f2015-09-03 19:09:50 -07001263 mdelay(1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001264 }
1265}
1266
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001267static void wilc_sleeptimer_isr_ext(u32 int_stats1)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001268{
1269 g_wlan.hif_func.hif_clear_int_ext(SLEEP_INT_CLR);
1270#ifndef WILC_OPTIMIZE_SLEEP_INT
1271 genuChipPSstate = CHIP_SLEEPING_AUTO;
1272#endif
1273}
1274
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001275static void wilc_wlan_handle_isr_ext(u32 int_status)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001276{
1277 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1278#ifdef MEMORY_STATIC
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001279 u32 offset = p->rx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001280#endif
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001281 u8 *buffer = NULL;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001282 u32 size;
1283 u32 retries = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001284 int ret = 0;
1285 struct rxq_entry_t *rqe;
1286
1287
1288 /**
1289 * Get the rx size
1290 **/
1291
1292 size = ((int_status & 0x7fff) << 2);
1293
1294 while (!size && retries < 10) {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001295 u32 time = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001296 /*looping more secure*/
1297 /*zero size make a crashe because the dma will not happen and that will block the firmware*/
1298 wilc_debug(N_ERR, "RX Size equal zero ... Trying to read it again for %d time\n", time++);
1299 p->hif_func.hif_read_size(&size);
1300 size = ((size & 0x7fff) << 2);
1301 retries++;
1302
1303 }
1304
1305 if (size > 0) {
1306#ifdef MEMORY_STATIC
Glen Lee03eb7262015-09-24 18:15:03 +09001307 if (LINUX_RX_SIZE - offset < size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001308 offset = 0;
1309
1310 if (p->rx_buffer)
1311 buffer = &p->rx_buffer[offset];
1312 else {
1313 wilc_debug(N_ERR, "[wilc isr]: fail Rx Buffer is NULL...drop the packets (%d)\n", size);
1314 goto _end_;
1315 }
1316
1317#else
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001318 buffer = kmalloc(size, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001319 if (buffer == NULL) {
1320 wilc_debug(N_ERR, "[wilc isr]: fail alloc host memory...drop the packets (%d)\n", size);
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -07001321 usleep_range(100 * 1000, 100 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001322 goto _end_;
1323 }
1324#endif
1325
1326 /**
1327 * clear the chip's interrupt after getting size some register getting corrupted after clear the interrupt
1328 **/
1329 p->hif_func.hif_clear_int_ext(DATA_INT_CLR | ENABLE_RX_VMM);
1330
1331
1332 /**
1333 * start transfer
1334 **/
1335 ret = p->hif_func.hif_block_rx_ext(0, buffer, size);
1336
1337 if (!ret) {
1338 wilc_debug(N_ERR, "[wilc isr]: fail block rx...\n");
1339 goto _end_;
1340 }
1341_end_:
1342
1343
1344 if (ret) {
1345#ifdef MEMORY_STATIC
1346 offset += size;
1347 p->rx_buffer_offset = offset;
1348#endif
1349 /**
1350 * add to rx queue
1351 **/
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001352 rqe = kmalloc(sizeof(struct rxq_entry_t), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001353 if (rqe != NULL) {
1354 rqe->buffer = buffer;
1355 rqe->buffer_size = size;
1356 PRINT_D(RX_DBG, "rxq entery Size= %d - Address = %p\n", rqe->buffer_size, rqe->buffer);
1357 wilc_wlan_rxq_add(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001358 }
1359 } else {
1360#ifndef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001361 kfree(buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001362#endif
1363 }
1364 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001365 wilc_wlan_handle_rxq();
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001366}
1367
1368void wilc_handle_isr(void)
1369{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001370 u32 int_status;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001371
1372 acquire_bus(ACQUIRE_AND_WAKEUP);
1373 g_wlan.hif_func.hif_read_int(&int_status);
1374
1375 if (int_status & PLL_INT_EXT) {
1376 wilc_pllupdate_isr_ext(int_status);
1377 }
1378 if (int_status & DATA_INT_EXT) {
1379 wilc_wlan_handle_isr_ext(int_status);
1380 #ifndef WILC_OPTIMIZE_SLEEP_INT
1381 /* Chip is up and talking*/
1382 genuChipPSstate = CHIP_WAKEDUP;
1383 #endif
1384 }
1385 if (int_status & SLEEP_INT_EXT) {
1386 wilc_sleeptimer_isr_ext(int_status);
1387 }
1388
1389 if (!(int_status & (ALL_INT_EXT))) {
1390#ifdef WILC_SDIO
1391 PRINT_D(TX_DBG, ">> UNKNOWN_INTERRUPT - 0x%08x\n", int_status);
1392#endif
1393 wilc_unknown_isr_ext();
1394 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001395 release_bus(RELEASE_ALLOW_SLEEP);
1396}
1397
1398/********************************************
1399 *
1400 * Firmware download
1401 *
1402 ********************************************/
Glen Lee63d7ab82015-10-01 16:03:32 +09001403int wilc_wlan_firmware_download(const u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001404{
1405 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001406 u32 offset;
1407 u32 addr, size, size2, blksz;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001408 u8 *dma_buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001409 int ret = 0;
1410
Anish Bhattffda2032015-09-29 12:15:49 -07001411 blksz = BIT(12);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001412 /* Allocate a DMA coherent buffer. */
1413
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001414 dma_buffer = kmalloc(blksz, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001415 if (dma_buffer == NULL) {
1416 /*EIO 5*/
1417 ret = -5;
1418 PRINT_ER("Can't allocate buffer for firmware download IO error\n ");
1419 goto _fail_1;
1420 }
1421
1422 PRINT_D(INIT_DBG, "Downloading firmware size = %d ...\n", buffer_size);
1423 /**
1424 * load the firmware
1425 **/
1426 offset = 0;
1427 do {
1428 memcpy(&addr, &buffer[offset], 4);
1429 memcpy(&size, &buffer[offset + 4], 4);
1430#ifdef BIG_ENDIAN
1431 addr = BYTE_SWAP(addr);
1432 size = BYTE_SWAP(size);
1433#endif
1434 acquire_bus(ACQUIRE_ONLY);
1435 offset += 8;
1436 while (((int)size) && (offset < buffer_size)) {
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301437 if (size <= blksz)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001438 size2 = size;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301439 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001440 size2 = blksz;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001441 /* Copy firmware into a DMA coherent buffer */
1442 memcpy(dma_buffer, &buffer[offset], size2);
1443 ret = p->hif_func.hif_block_tx(addr, dma_buffer, size2);
1444 if (!ret)
1445 break;
1446
1447 addr += size2;
1448 offset += size2;
1449 size -= size2;
1450 }
1451 release_bus(RELEASE_ONLY);
1452
1453 if (!ret) {
1454 /*EIO 5*/
1455 ret = -5;
1456 PRINT_ER("Can't download firmware IO error\n ");
1457 goto _fail_;
1458 }
1459 PRINT_D(INIT_DBG, "Offset = %d\n", offset);
1460 } while (offset < buffer_size);
1461
1462_fail_:
1463
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001464 kfree(dma_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001465
1466_fail_1:
1467
1468 return (ret < 0) ? ret : 0;
1469}
1470
1471/********************************************
1472 *
1473 * Common
1474 *
1475 ********************************************/
Glen Leee42563b2015-10-01 16:03:33 +09001476int wilc_wlan_start(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001477{
1478 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001479 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001480 int ret;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001481 u32 chipid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001482
1483 /**
1484 * Set the host interface
1485 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001486 if (p->io_func.io_type == HIF_SDIO) {
1487 reg = 0;
Anish Bhattffda2032015-09-29 12:15:49 -07001488 reg |= BIT(3); /* bug 4456 and 4557 */
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001489 } else if (p->io_func.io_type == HIF_SPI) {
1490 reg = 1;
1491 }
1492 acquire_bus(ACQUIRE_ONLY);
1493 ret = p->hif_func.hif_write_reg(WILC_VMM_CORE_CFG, reg);
1494 if (!ret) {
1495 wilc_debug(N_ERR, "[wilc start]: fail write reg vmm_core_cfg...\n");
1496 release_bus(RELEASE_ONLY);
1497 /* EIO 5*/
1498 ret = -5;
1499 return ret;
1500 }
1501 reg = 0;
1502#ifdef WILC_SDIO_IRQ_GPIO
1503 reg |= WILC_HAVE_SDIO_IRQ_GPIO;
1504#endif
1505
1506#ifdef WILC_DISABLE_PMU
1507#else
1508 reg |= WILC_HAVE_USE_PMU;
1509#endif
1510
1511#ifdef WILC_SLEEP_CLK_SRC_XO
1512 reg |= WILC_HAVE_SLEEP_CLK_SRC_XO;
1513#elif defined WILC_SLEEP_CLK_SRC_RTC
1514 reg |= WILC_HAVE_SLEEP_CLK_SRC_RTC;
1515#endif
1516
1517#ifdef WILC_EXT_PA_INV_TX_RX
1518 reg |= WILC_HAVE_EXT_PA_INV_TX_RX;
1519#endif
1520
1521 reg |= WILC_HAVE_LEGACY_RF_SETTINGS;
1522
1523
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001524/*Set oscillator frequency*/
1525#ifdef XTAL_24
1526 reg |= WILC_HAVE_XTAL_24;
1527#endif
1528
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001529/*Enable/Disable GPIO configuration for FW logs*/
1530#ifdef DISABLE_WILC_UART
1531 reg |= WILC_HAVE_DISABLE_WILC_UART;
1532#endif
1533
1534 ret = p->hif_func.hif_write_reg(WILC_GP_REG_1, reg);
1535 if (!ret) {
1536 wilc_debug(N_ERR, "[wilc start]: fail write WILC_GP_REG_1 ...\n");
1537 release_bus(RELEASE_ONLY);
1538 /* EIO 5*/
1539 ret = -5;
1540 return ret;
1541 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001542
1543 /**
1544 * Bus related
1545 **/
1546 p->hif_func.hif_sync_ext(NUM_INT_EXT);
1547
1548 ret = p->hif_func.hif_read_reg(0x1000, &chipid);
1549 if (!ret) {
1550 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1000 ...\n");
1551 release_bus(RELEASE_ONLY);
1552 /* EIO 5*/
1553 ret = -5;
1554 return ret;
1555 }
1556
1557 /**
1558 * Go...
1559 **/
1560
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001561
1562 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -07001563 if ((reg & BIT(10)) == BIT(10)) {
1564 reg &= ~BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001565 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1566 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1567 }
1568
Anish Bhattffda2032015-09-29 12:15:49 -07001569 reg |= BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001570 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1571 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1572 release_bus(RELEASE_ONLY);
1573
1574 return (ret < 0) ? ret : 0;
1575}
1576
1577void wilc_wlan_global_reset(void)
1578{
1579
1580 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001581
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001582 acquire_bus(ACQUIRE_AND_WAKEUP);
1583 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, 0x0);
1584 release_bus(RELEASE_ONLY);
1585}
Glen Lee8cec7412015-10-01 16:03:34 +09001586int wilc_wlan_stop(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001587{
1588 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001589 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001590 int ret;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001591 u8 timeout = 10;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001592 /**
1593 * TODO: stop the firmware, need a re-download
1594 **/
1595 acquire_bus(ACQUIRE_AND_WAKEUP);
1596
1597 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1598 if (!ret) {
1599 PRINT_ER("Error while reading reg\n");
1600 release_bus(RELEASE_ALLOW_SLEEP);
1601 return ret;
1602 }
1603
Anish Bhattffda2032015-09-29 12:15:49 -07001604 reg &= ~BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001605
1606
1607 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1608 if (!ret) {
1609 PRINT_ER("Error while writing reg\n");
1610 release_bus(RELEASE_ALLOW_SLEEP);
1611 return ret;
1612 }
1613
1614
1615
1616 do {
1617 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1618 if (!ret) {
1619 PRINT_ER("Error while reading reg\n");
1620 release_bus(RELEASE_ALLOW_SLEEP);
1621 return ret;
1622 }
1623 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1624 /*Workaround to ensure that the chip is actually reset*/
Anish Bhattffda2032015-09-29 12:15:49 -07001625 if ((reg & BIT(10))) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001626 PRINT_D(GENERIC_DBG, "Bit 10 not reset : Retry %d\n", timeout);
Anish Bhattffda2032015-09-29 12:15:49 -07001627 reg &= ~BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001628 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1629 timeout--;
1630 } else {
1631 PRINT_D(GENERIC_DBG, "Bit 10 reset after : Retry %d\n", timeout);
1632 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1633 if (!ret) {
1634 PRINT_ER("Error while reading reg\n");
1635 release_bus(RELEASE_ALLOW_SLEEP);
1636 return ret;
1637 }
1638 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1639 break;
1640 }
1641
1642 } while (timeout);
Anish Bhattffda2032015-09-29 12:15:49 -07001643 reg = (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(8) | BIT(9) | BIT(26) |
1644 BIT(29) | BIT(30) | BIT(31));
Anish Bhatt65ead4e2015-09-29 12:15:48 -07001645
1646 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
Anish Bhattffda2032015-09-29 12:15:49 -07001647 reg = (u32)~BIT(10);
Anish Bhatt65ead4e2015-09-29 12:15:48 -07001648
1649 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001650
1651 release_bus(RELEASE_ALLOW_SLEEP);
1652
1653 return ret;
1654}
1655
Glen Leea17e2ec2015-10-01 16:03:38 +09001656void wilc_wlan_cleanup(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001657{
1658 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1659 struct txq_entry_t *tqe;
1660 struct rxq_entry_t *rqe;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001661 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001662 int ret;
1663
1664 p->quit = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001665 do {
1666 tqe = wilc_wlan_txq_remove_from_head();
1667 if (tqe == NULL)
1668 break;
1669 if (tqe->tx_complete_func)
1670 tqe->tx_complete_func(tqe->priv, 0);
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001671 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001672 } while (1);
1673
1674 do {
1675 rqe = wilc_wlan_rxq_remove();
1676 if (rqe == NULL)
1677 break;
Javier Martinez Canillas6a272242015-09-22 15:24:50 +02001678#ifndef MEMORY_STATIC
1679 kfree(rqe->buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001680#endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001681 kfree(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001682 } while (1);
1683
1684 /**
1685 * clean up buffer
1686 **/
1687
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001688 #ifdef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001689 kfree(p->rx_buffer);
1690 p->rx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001691 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001692 kfree(p->tx_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001693
1694 acquire_bus(ACQUIRE_AND_WAKEUP);
1695
1696
1697 ret = p->hif_func.hif_read_reg(WILC_GP_REG_0, &reg);
1698 if (!ret) {
1699 PRINT_ER("Error while reading reg\n");
1700 release_bus(RELEASE_ALLOW_SLEEP);
1701 }
1702 PRINT_ER("Writing ABORT reg\n");
1703 ret = p->hif_func.hif_write_reg(WILC_GP_REG_0, (reg | ABORT_INT));
1704 if (!ret) {
1705 PRINT_ER("Error while writing reg\n");
1706 release_bus(RELEASE_ALLOW_SLEEP);
1707 }
1708 release_bus(RELEASE_ALLOW_SLEEP);
1709 /**
1710 * io clean up
1711 **/
1712 p->hif_func.hif_deinit(NULL);
1713
1714}
1715
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001716static int wilc_wlan_cfg_commit(int type, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001717{
1718 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1719 wilc_cfg_frame_t *cfg = &p->cfg_frame;
1720 int total_len = p->cfg_frame_offset + 4 + DRIVER_HANDLER_SIZE;
1721 int seq_no = p->cfg_seq_no % 256;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001722 int driver_handler = (u32)drvHandler;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001723
1724
1725 /**
1726 * Set up header
1727 **/
1728 if (type == WILC_CFG_SET) { /* Set */
1729 cfg->wid_header[0] = 'W';
1730 } else { /* Query */
1731 cfg->wid_header[0] = 'Q';
1732 }
1733 cfg->wid_header[1] = seq_no; /* sequence number */
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001734 cfg->wid_header[2] = (u8)total_len;
1735 cfg->wid_header[3] = (u8)(total_len >> 8);
1736 cfg->wid_header[4] = (u8)driver_handler;
1737 cfg->wid_header[5] = (u8)(driver_handler >> 8);
1738 cfg->wid_header[6] = (u8)(driver_handler >> 16);
1739 cfg->wid_header[7] = (u8)(driver_handler >> 24);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001740 p->cfg_seq_no = seq_no;
1741
1742 /**
1743 * Add to TX queue
1744 **/
1745
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001746 if (!wilc_wlan_txq_add_cfg_pkt(&cfg->wid_header[0], total_len))
1747 return -1;
1748
1749 return 0;
1750}
1751
Glen Lee1028e5a2015-10-01 16:03:40 +09001752int wilc_wlan_cfg_set(int start, u32 wid, u8 *buffer, u32 buffer_size,
1753 int commit, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001754{
1755 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001756 u32 offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001757 int ret_size;
1758
1759
1760 if (p->cfg_frame_in_use)
1761 return 0;
1762
1763 if (start)
1764 p->cfg_frame_offset = 0;
1765
1766 offset = p->cfg_frame_offset;
Glen Lee17e8f162015-10-02 14:22:07 +09001767 ret_size = wilc_wlan_cfg_set_wid(p->cfg_frame.frame, offset, (u16)wid,
1768 buffer, buffer_size);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001769 offset += ret_size;
1770 p->cfg_frame_offset = offset;
1771
1772 if (commit) {
1773 PRINT_D(TX_DBG, "[WILC]PACKET Commit with sequence number %d\n", p->cfg_seq_no);
1774 PRINT_D(RX_DBG, "Processing cfg_set()\n");
1775 p->cfg_frame_in_use = 1;
1776
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001777 if (wilc_wlan_cfg_commit(WILC_CFG_SET, drvHandler))
Chaehyun Lim5af6b852015-09-17 16:48:48 +09001778 ret_size = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001779
Glen Leeb002e202015-09-24 18:15:05 +09001780 if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event,
1781 CFG_PKTS_TIMEOUT)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001782 PRINT_D(TX_DBG, "Set Timed Out\n");
1783 ret_size = 0;
1784 }
1785 p->cfg_frame_in_use = 0;
1786 p->cfg_frame_offset = 0;
1787 p->cfg_seq_no += 1;
1788
1789 }
1790
1791 return ret_size;
1792}
Glen Lee07056a82015-10-01 16:03:41 +09001793int wilc_wlan_cfg_get(int start, u32 wid, int commit, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001794{
1795 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001796 u32 offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001797 int ret_size;
1798
1799
1800 if (p->cfg_frame_in_use)
1801 return 0;
1802
1803 if (start)
1804 p->cfg_frame_offset = 0;
1805
1806 offset = p->cfg_frame_offset;
Glen Leeec1b86b2015-10-02 14:22:08 +09001807 ret_size = wilc_wlan_cfg_get_wid(p->cfg_frame.frame, offset, (u16)wid);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001808 offset += ret_size;
1809 p->cfg_frame_offset = offset;
1810
1811 if (commit) {
1812 p->cfg_frame_in_use = 1;
1813
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001814 if (wilc_wlan_cfg_commit(WILC_CFG_QUERY, drvHandler))
Chaehyun Lim5af6b852015-09-17 16:48:48 +09001815 ret_size = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001816
1817
Glen Leeb002e202015-09-24 18:15:05 +09001818 if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event,
1819 CFG_PKTS_TIMEOUT)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001820 PRINT_D(TX_DBG, "Get Timed Out\n");
1821 ret_size = 0;
1822 }
1823 PRINT_D(GENERIC_DBG, "[WILC]Get Response received\n");
1824 p->cfg_frame_in_use = 0;
1825 p->cfg_frame_offset = 0;
1826 p->cfg_seq_no += 1;
1827 }
1828
1829 return ret_size;
1830}
1831
Glen Lee894de36b2015-10-01 16:03:42 +09001832int wilc_wlan_cfg_get_val(u32 wid, u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001833{
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001834 int ret;
1835
Glen Lee1fea5932015-09-24 18:15:06 +09001836 ret = mac_cfg.cfg_wid_get_val((u16)wid, buffer, buffer_size);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001837
1838 return ret;
1839}
1840
1841void wilc_bus_set_max_speed(void)
1842{
1843
1844 /* Increase bus speed to max possible. */
1845 g_wlan.hif_func.hif_set_max_bus_speed();
1846}
1847
1848void wilc_bus_set_default_speed(void)
1849{
1850
1851 /* Restore bus speed to default. */
1852 g_wlan.hif_func.hif_set_default_bus_speed();
1853}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001854u32 init_chip(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001855{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001856 u32 chipid;
1857 u32 reg, ret = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001858
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001859 acquire_bus(ACQUIRE_ONLY);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001860
Dean Lee72ed4dc2015-06-12 14:11:44 +09001861 chipid = wilc_get_chipid(true);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001862
1863
1864
1865 if ((chipid & 0xfff) != 0xa0) {
1866 /**
1867 * Avoid booting from boot ROM. Make sure that Drive IRQN [SDIO platform]
1868 * or SD_DAT3 [SPI platform] to ?1?
1869 **/
1870 /* Set cortus reset register to register control. */
1871 ret = g_wlan.hif_func.hif_read_reg(0x1118, &reg);
1872 if (!ret) {
1873 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1118 ...\n");
1874 return ret;
1875 }
Anish Bhattffda2032015-09-29 12:15:49 -07001876 reg |= BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001877 ret = g_wlan.hif_func.hif_write_reg(0x1118, reg);
1878 if (!ret) {
1879 wilc_debug(N_ERR, "[wilc start]: fail write reg 0x1118 ...\n");
1880 return ret;
1881 }
1882 /**
1883 * Write branch intruction to IRAM (0x71 trap) at location 0xFFFF0000
1884 * (Cortus map) or C0000 (AHB map).
1885 **/
1886 ret = g_wlan.hif_func.hif_write_reg(0xc0000, 0x71);
1887 if (!ret) {
1888 wilc_debug(N_ERR, "[wilc start]: fail write reg 0xc0000 ...\n");
1889 return ret;
1890 }
1891 }
1892
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001893 release_bus(RELEASE_ONLY);
1894
1895 return ret;
1896
1897}
1898
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001899u32 wilc_get_chipid(u8 update)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001900{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001901 static u32 chipid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001902 /* SDIO can't read into global variables */
1903 /* Use this variable as a temp, then copy to the global */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001904 u32 tempchipid = 0;
1905 u32 rfrevid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001906
1907 if (chipid == 0 || update != 0) {
1908 g_wlan.hif_func.hif_read_reg(0x1000, &tempchipid);
1909 g_wlan.hif_func.hif_read_reg(0x13f4, &rfrevid);
1910 if (!ISWILC1000(tempchipid)) {
1911 chipid = 0;
1912 goto _fail_;
1913 }
1914 if (tempchipid == 0x1002a0) {
1915 if (rfrevid == 0x1) { /* 1002A0 */
1916 } else { /* if (rfrevid == 0x2) */ /* 1002A1 */
1917 tempchipid = 0x1002a1;
1918 }
1919 } else if (tempchipid == 0x1002b0) {
1920 if (rfrevid == 3) { /* 1002B0 */
1921 } else if (rfrevid == 4) { /* 1002B1 */
1922 tempchipid = 0x1002b1;
1923 } else { /* if(rfrevid == 5) */ /* 1002B2 */
1924 tempchipid = 0x1002b2;
1925 }
1926 } else {
1927 }
1928
1929 chipid = tempchipid;
1930 }
1931_fail_:
1932 return chipid;
1933}
1934
1935#ifdef COMPLEMENT_BOOT
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001936u8 core_11b_ready(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001937{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001938 u32 reg_val;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001939
1940 acquire_bus(ACQUIRE_ONLY);
1941 g_wlan.hif_func.hif_write_reg(0x16082c, 1);
1942 g_wlan.hif_func.hif_write_reg(0x161600, 0x90);
1943 g_wlan.hif_func.hif_read_reg(0x161600, &reg_val);
1944 release_bus(RELEASE_ONLY);
1945
1946 if (reg_val == 0x90)
1947 return 0;
1948 else
1949 return 1;
1950}
1951#endif
1952
Glen Leec9d48342015-10-01 16:03:43 +09001953int wilc_wlan_init(wilc_wlan_inp_t *inp)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001954{
1955
1956 int ret = 0;
1957
1958 PRINT_D(INIT_DBG, "Initializing WILC_Wlan ...\n");
1959
1960 memset((void *)&g_wlan, 0, sizeof(wilc_wlan_dev_t));
1961
1962 /**
1963 * store the input
1964 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001965 memcpy((void *)&g_wlan.io_func, (void *)&inp->io_func, sizeof(wilc_wlan_io_func_t));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001966 /***
1967 * host interface init
1968 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001969 if ((inp->io_func.io_type & 0x1) == HIF_SDIO) {
1970 if (!hif_sdio.hif_init(inp, wilc_debug)) {
1971 /* EIO 5 */
1972 ret = -5;
1973 goto _fail_;
1974 }
1975 memcpy((void *)&g_wlan.hif_func, &hif_sdio, sizeof(wilc_hif_func_t));
1976 } else {
1977 if ((inp->io_func.io_type & 0x1) == HIF_SPI) {
1978 /**
1979 * TODO:
1980 **/
1981 if (!hif_spi.hif_init(inp, wilc_debug)) {
1982 /* EIO 5 */
1983 ret = -5;
1984 goto _fail_;
1985 }
1986 memcpy((void *)&g_wlan.hif_func, &hif_spi, sizeof(wilc_hif_func_t));
1987 } else {
1988 /* EIO 5 */
1989 ret = -5;
1990 goto _fail_;
1991 }
1992 }
1993
1994 /***
1995 * mac interface init
1996 **/
1997 if (!mac_cfg.cfg_init(wilc_debug)) {
1998 /* ENOBUFS 105 */
1999 ret = -105;
2000 goto _fail_;
2001 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002002
2003 /**
2004 * alloc tx, rx buffer
2005 **/
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002006 if (g_wlan.tx_buffer == NULL)
Glen Lee7015b5d2015-09-24 18:15:02 +09002007 g_wlan.tx_buffer = kmalloc(LINUX_TX_SIZE, GFP_KERNEL);
Arnd Bergmann7a8fd842015-06-01 21:06:45 +02002008 PRINT_D(TX_DBG, "g_wlan.tx_buffer = %p\n", g_wlan.tx_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002009
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002010 if (g_wlan.tx_buffer == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002011 /* ENOBUFS 105 */
2012 ret = -105;
2013 PRINT_ER("Can't allocate Tx Buffer");
2014 goto _fail_;
2015 }
2016
2017/* rx_buffer is not used unless we activate USE_MEM STATIC which is not applicable, allocating such memory is useless*/
2018#if defined (MEMORY_STATIC)
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002019 if (g_wlan.rx_buffer == NULL)
Glen Lee03eb7262015-09-24 18:15:03 +09002020 g_wlan.rx_buffer = kmalloc(LINUX_RX_SIZE, GFP_KERNEL);
Arnd Bergmann7a8fd842015-06-01 21:06:45 +02002021 PRINT_D(TX_DBG, "g_wlan.rx_buffer =%p\n", g_wlan.rx_buffer);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002022 if (g_wlan.rx_buffer == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002023 /* ENOBUFS 105 */
2024 ret = -105;
2025 PRINT_ER("Can't allocate Rx Buffer");
2026 goto _fail_;
2027 }
2028#endif
2029
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002030 if (!init_chip()) {
2031 /* EIO 5 */
2032 ret = -5;
2033 goto _fail_;
2034 }
2035#ifdef TCP_ACK_FILTER
2036 Init_TCP_tracking();
2037#endif
2038
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002039 return 1;
2040
2041_fail_:
2042
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002043 #ifdef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07002044 kfree(g_wlan.rx_buffer);
2045 g_wlan.rx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002046 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07002047 kfree(g_wlan.tx_buffer);
2048 g_wlan.tx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002049
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002050 return ret;
2051
2052}
2053
Dean Lee72ed4dc2015-06-12 14:11:44 +09002054u16 Set_machw_change_vir_if(bool bValue)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002055{
Chaehyun Limd85f5322015-06-11 14:35:54 +09002056 u16 ret;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002057 u32 reg;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002058
2059 /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
Glen Lee187f1ef2015-09-24 18:15:01 +09002060 mutex_lock(&g_linux_wlan->hif_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002061 ret = (&g_wlan)->hif_func.hif_read_reg(WILC_CHANGING_VIR_IF, &reg);
2062 if (!ret) {
2063 PRINT_ER("Error while Reading reg WILC_CHANGING_VIR_IF\n");
2064 }
2065
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05302066 if (bValue)
Chaehyun Lim50b51da2015-09-16 20:11:26 +09002067 reg |= BIT(31);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05302068 else
Chaehyun Lim50b51da2015-09-16 20:11:26 +09002069 reg &= ~BIT(31);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002070
2071 ret = (&g_wlan)->hif_func.hif_write_reg(WILC_CHANGING_VIR_IF, reg);
2072
2073 if (!ret) {
2074 PRINT_ER("Error while writing reg WILC_CHANGING_VIR_IF\n");
2075 }
Glen Lee187f1ef2015-09-24 18:15:01 +09002076 mutex_unlock(&g_linux_wlan->hif_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002077
2078 return ret;
2079}