blob: 745953c6b65101e65b74bdff42478f47034cea4f [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 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +090033 wilc_wlan_io_func_t io_func;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090034
35 /**
36 * host interface functions
37 **/
38 wilc_hif_func_t hif_func;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090039
40 /**
41 * configuration interface functions
42 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +090043 int cfg_frame_in_use;
44 wilc_cfg_frame_t cfg_frame;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090045 u32 cfg_frame_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090046 int cfg_seq_no;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090047
48 /**
49 * RX buffer
50 **/
51 #ifdef MEMORY_STATIC
Chaehyun Lim51e825f2015-09-15 14:06:14 +090052 u8 *rx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090053 u32 rx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090054 #endif
55 /**
56 * TX buffer
57 **/
Chaehyun Lim51e825f2015-09-15 14:06:14 +090058 u8 *tx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090059 u32 tx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090060
61 /**
62 * TX queue
63 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +090064
Johnny Kimc5c77ba2015-05-11 14:30:56 +090065 unsigned long txq_spinlock_flags;
66
67 struct txq_entry_t *txq_head;
68 struct txq_entry_t *txq_tail;
69 int txq_entries;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090070 int txq_exit;
71
72 /**
73 * RX queue
74 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +090075 struct rxq_entry_t *rxq_head;
76 struct rxq_entry_t *rxq_tail;
77 int rxq_entries;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090078 int rxq_exit;
79
80
81} wilc_wlan_dev_t;
82
83static wilc_wlan_dev_t g_wlan;
84
Chaehyun Lim9af382b2015-09-16 20:11:27 +090085static inline void chip_allow_sleep(void);
86static inline void chip_wakeup(void);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090087/********************************************
88 *
89 * Debug
90 *
91 ********************************************/
92
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090093static u32 dbgflag = N_INIT | N_ERR | N_INTR | N_TXQ | N_RXQ;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090094
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090095static void wilc_debug(u32 flag, char *fmt, ...)
Johnny Kimc5c77ba2015-05-11 14:30:56 +090096{
97 char buf[256];
98 va_list args;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090099
100 if (flag & dbgflag) {
101 va_start(args, fmt);
Hari Prasath Gujulan Elango81053222015-06-22 13:13:58 +0000102 vsprintf(buf, fmt, args);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900103 va_end(args);
104
Glen Leeef2b7842015-09-24 18:14:55 +0900105 linux_wlan_dbg(buf);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900106 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900107}
108
109static CHIP_PS_STATE_T genuChipPSstate = CHIP_WAKEDUP;
110
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900111/*acquire_bus() and release_bus() are made static inline functions*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900112/*as a temporary workaround to fix a problem of receiving*/
113/*unknown interrupt from FW*/
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900114static inline void acquire_bus(BUS_ACQUIRE_T acquire)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900115{
116
Glen Lee187f1ef2015-09-24 18:15:01 +0900117 mutex_lock(&g_linux_wlan->hif_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900118 #ifndef WILC_OPTIMIZE_SLEEP_INT
119 if (genuChipPSstate != CHIP_WAKEDUP)
120 #endif
121 {
122 if (acquire == ACQUIRE_AND_WAKEUP)
123 chip_wakeup();
124 }
125
126}
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900127static inline void release_bus(BUS_RELEASE_T release)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900128{
129 #ifdef WILC_OPTIMIZE_SLEEP_INT
130 if (release == RELEASE_ALLOW_SLEEP)
131 chip_allow_sleep();
132 #endif
Glen Lee187f1ef2015-09-24 18:15:01 +0900133 mutex_unlock(&g_linux_wlan->hif_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900134}
135/********************************************
136 *
137 * Queue
138 *
139 ********************************************/
140
141static void wilc_wlan_txq_remove(struct txq_entry_t *tqe)
142{
143
144 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
145 /* unsigned long flags; */
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900146 if (tqe == p->txq_head) {
147
148 p->txq_head = tqe->next;
149 if (p->txq_head)
150 p->txq_head->prev = NULL;
151
152
153 } else if (tqe == p->txq_tail) {
154 p->txq_tail = (tqe->prev);
155 if (p->txq_tail)
156 p->txq_tail->next = NULL;
157 } else {
158 tqe->prev->next = tqe->next;
159 tqe->next->prev = tqe->prev;
160 }
161 p->txq_entries -= 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900162
163}
164
165static struct txq_entry_t *wilc_wlan_txq_remove_from_head(void)
166{
167 struct txq_entry_t *tqe;
168 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
169 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900170
Glen Lee85e57562015-09-24 18:14:56 +0900171 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900172 if (p->txq_head) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900173 tqe = p->txq_head;
174 p->txq_head = tqe->next;
175 if (p->txq_head) {
176 p->txq_head->prev = NULL;
177 }
178 p->txq_entries -= 1;
179
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900180
181
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900182
183 } else {
184 tqe = NULL;
185 }
Glen Lee85e57562015-09-24 18:14:56 +0900186 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900187 return tqe;
188}
189
190static void wilc_wlan_txq_add_to_tail(struct txq_entry_t *tqe)
191{
192 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
193 unsigned long flags;
Glen Lee85e57562015-09-24 18:14:56 +0900194 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900195
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900196 if (p->txq_head == NULL) {
197 tqe->next = NULL;
198 tqe->prev = NULL;
199 p->txq_head = tqe;
200 p->txq_tail = tqe;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900201 } else {
202 tqe->next = NULL;
203 tqe->prev = p->txq_tail;
204 p->txq_tail->next = tqe;
205 p->txq_tail = tqe;
206 }
207 p->txq_entries += 1;
208 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900209
Glen Lee85e57562015-09-24 18:14:56 +0900210 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900211
212 /**
213 * wake up TX queue
214 **/
215 PRINT_D(TX_DBG, "Wake the txq_handling\n");
216
Glen Lee5cd63632015-09-24 18:14:58 +0900217 up(&g_linux_wlan->txq_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900218}
219
220static int wilc_wlan_txq_add_to_head(struct txq_entry_t *tqe)
221{
222 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
223 unsigned long flags;
Glen Leeb002e202015-09-24 18:15:05 +0900224 if (linux_wlan_lock_timeout(&g_linux_wlan->txq_add_to_head_cs,
225 CFG_PKTS_TIMEOUT))
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900226 return -1;
227
Glen Lee85e57562015-09-24 18:14:56 +0900228 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900229
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900230 if (p->txq_head == NULL) {
231 tqe->next = NULL;
232 tqe->prev = NULL;
233 p->txq_head = tqe;
234 p->txq_tail = tqe;
235 } else {
236 tqe->next = p->txq_head;
237 tqe->prev = NULL;
238 p->txq_head->prev = tqe;
239 p->txq_head = tqe;
240 }
241 p->txq_entries += 1;
242 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900243
Glen Lee85e57562015-09-24 18:14:56 +0900244 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Glen Leed5a63a82015-09-24 18:15:00 +0900245 up(&g_linux_wlan->txq_add_to_head_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900246
247
248 /**
249 * wake up TX queue
250 **/
Glen Lee5cd63632015-09-24 18:14:58 +0900251 up(&g_linux_wlan->txq_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900252 PRINT_D(TX_DBG, "Wake up the txq_handler\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900253
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900254 return 0;
255
256}
257
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900258u32 Statisitcs_totalAcks = 0, Statisitcs_DroppedAcks = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900259
260#ifdef TCP_ACK_FILTER
261struct Ack_session_info;
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530262struct Ack_session_info {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900263 u32 Ack_seq_num;
264 u32 Bigger_Ack_num;
Chaehyun Limec53adf2015-09-15 14:06:15 +0900265 u16 src_port;
266 u16 dst_port;
267 u16 status;
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530268};
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900269
270typedef struct {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900271 u32 ack_num;
272 u32 Session_index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900273 struct txq_entry_t *txqe;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900274} Pending_Acks_info_t /*Ack_info_t*/;
275
276
277
278
279struct Ack_session_info *Free_head;
280struct Ack_session_info *Alloc_head;
281
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900282#define NOT_TCP_ACK (-1)
283
284#define MAX_TCP_SESSION 25
285#define MAX_PENDING_ACKS 256
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530286struct Ack_session_info Acks_keep_track_info[2 * MAX_TCP_SESSION];
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900287Pending_Acks_info_t Pending_Acks_info[MAX_PENDING_ACKS];
288
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900289u32 PendingAcks_arrBase;
290u32 Opened_TCP_session;
291u32 Pending_Acks;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900292
293
294
Chaehyun Limfed16f22015-09-17 16:48:43 +0900295static inline int Init_TCP_tracking(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900296{
297
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900298 return 0;
299
300}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900301static inline int add_TCP_track_session(u32 src_prt, u32 dst_prt, u32 seq)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900302{
303 Acks_keep_track_info[Opened_TCP_session].Ack_seq_num = seq;
304 Acks_keep_track_info[Opened_TCP_session].Bigger_Ack_num = 0;
305 Acks_keep_track_info[Opened_TCP_session].src_port = src_prt;
306 Acks_keep_track_info[Opened_TCP_session].dst_port = dst_prt;
307 Opened_TCP_session++;
308
309 PRINT_D(TCP_ENH, "TCP Session %d to Ack %d\n", Opened_TCP_session, seq);
310 return 0;
311}
312
Chaehyun Limfed16f22015-09-17 16:48:43 +0900313static inline int Update_TCP_track_session(u32 index, u32 Ack)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900314{
315
316 if (Ack > Acks_keep_track_info[index].Bigger_Ack_num) {
317 Acks_keep_track_info[index].Bigger_Ack_num = Ack;
318 }
319 return 0;
320
321}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900322static inline int add_TCP_Pending_Ack(u32 Ack, u32 Session_index, struct txq_entry_t *txqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900323{
324 Statisitcs_totalAcks++;
325 if (Pending_Acks < MAX_PENDING_ACKS) {
326 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].ack_num = Ack;
327 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].txqe = txqe;
328 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].Session_index = Session_index;
329 txqe->tcp_PendingAck_index = PendingAcks_arrBase + Pending_Acks;
330 Pending_Acks++;
331
332 } else {
333
334 }
335 return 0;
336}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900337static inline int remove_TCP_related(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900338{
339 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
340 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900341
Glen Lee85e57562015-09-24 18:14:56 +0900342 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900343
Glen Lee85e57562015-09-24 18:14:56 +0900344 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900345 return 0;
346}
347
Chaehyun Limfed16f22015-09-17 16:48:43 +0900348static inline int tcp_process(struct txq_entry_t *tqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900349{
350 int ret;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900351 u8 *eth_hdr_ptr;
352 u8 *buffer = tqe->buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900353 unsigned short h_proto;
354 int i;
355 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
356 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900357
Glen Lee85e57562015-09-24 18:14:56 +0900358 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900359
360 eth_hdr_ptr = &buffer[0];
361 h_proto = ntohs(*((unsigned short *)&eth_hdr_ptr[12]));
362 if (h_proto == 0x0800) { /* IP */
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900363 u8 *ip_hdr_ptr;
364 u8 protocol;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900365
366 ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN];
367 protocol = ip_hdr_ptr[9];
368
369
370 if (protocol == 0x06) {
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900371 u8 *tcp_hdr_ptr;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900372 u32 IHL, Total_Length, Data_offset;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900373
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900374 tcp_hdr_ptr = &ip_hdr_ptr[IP_HDR_LEN];
375 IHL = (ip_hdr_ptr[0] & 0xf) << 2;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900376 Total_Length = (((u32)ip_hdr_ptr[2]) << 8) + ((u32)ip_hdr_ptr[3]);
377 Data_offset = (((u32)tcp_hdr_ptr[12] & 0xf0) >> 2);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900378 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 +0900379 u32 seq_no, Ack_no;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900380
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900381 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 +0900382
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900383 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 +0900384
385
386 for (i = 0; i < Opened_TCP_session; i++) {
387 if (Acks_keep_track_info[i].Ack_seq_num == seq_no) {
388 Update_TCP_track_session(i, Ack_no);
389 break;
390 }
391 }
392 if (i == Opened_TCP_session) {
393 add_TCP_track_session(0, 0, seq_no);
394 }
395 add_TCP_Pending_Ack(Ack_no, i, tqe);
396
397
398 }
399
400 } else {
401 ret = 0;
402 }
403 } else {
404 ret = 0;
405 }
Glen Lee85e57562015-09-24 18:14:56 +0900406 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900407 return ret;
408}
409
410
411static int wilc_wlan_txq_filter_dup_tcp_ack(void)
412{
413
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900414 u32 i = 0;
415 u32 Dropped = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900416 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
417
Glen Lee85e57562015-09-24 18:14:56 +0900418 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, p->txq_spinlock_flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900419 for (i = PendingAcks_arrBase; i < (PendingAcks_arrBase + Pending_Acks); i++) {
420 if (Pending_Acks_info[i].ack_num < Acks_keep_track_info[Pending_Acks_info[i].Session_index].Bigger_Ack_num) {
421 struct txq_entry_t *tqe;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900422
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530423 PRINT_D(TCP_ENH, "DROP ACK: %u\n", Pending_Acks_info[i].ack_num);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900424 tqe = Pending_Acks_info[i].txqe;
425 if (tqe) {
426 wilc_wlan_txq_remove(tqe);
427 Statisitcs_DroppedAcks++;
428 tqe->status = 1; /* mark the packet send */
429 if (tqe->tx_complete_func)
430 tqe->tx_complete_func(tqe->priv, tqe->status);
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -0700431 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900432 Dropped++;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900433 }
434 }
435 }
436 Pending_Acks = 0;
437 Opened_TCP_session = 0;
438
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530439 if (PendingAcks_arrBase == 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900440 PendingAcks_arrBase = MAX_TCP_SESSION;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530441 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900442 PendingAcks_arrBase = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900443
444
Glen Lee85e57562015-09-24 18:14:56 +0900445 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock,
446 p->txq_spinlock_flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900447
448 while (Dropped > 0) {
449 /*consume the semaphore count of the removed packet*/
Glen Leeb002e202015-09-24 18:15:05 +0900450 linux_wlan_lock_timeout(&g_linux_wlan->txq_event, 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900451 Dropped--;
452 }
453
454 return 1;
455}
456#endif
457
Dean Lee72ed4dc2015-06-12 14:11:44 +0900458bool EnableTCPAckFilter = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900459
Dean Lee72ed4dc2015-06-12 14:11:44 +0900460void Enable_TCP_ACK_Filter(bool value)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900461{
462 EnableTCPAckFilter = value;
463}
464
Dean Lee72ed4dc2015-06-12 14:11:44 +0900465bool is_TCP_ACK_Filter_Enabled(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900466{
467 return EnableTCPAckFilter;
468}
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900469
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900470static int wilc_wlan_txq_add_cfg_pkt(u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900471{
472 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
473 struct txq_entry_t *tqe;
474
475 PRINT_D(TX_DBG, "Adding config packet ...\n");
476 if (p->quit) {
477 PRINT_D(TX_DBG, "Return due to clear function\n");
Glen Lee6a3b94f2015-09-24 18:14:59 +0900478 up(&g_linux_wlan->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900479 return 0;
480 }
481
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700482 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900483 if (tqe == NULL) {
484 PRINT_ER("Failed to allocate memory\n");
485 return 0;
486 }
487
488 tqe->type = WILC_CFG_PKT;
489 tqe->buffer = buffer;
490 tqe->buffer_size = buffer_size;
491 tqe->tx_complete_func = NULL;
492 tqe->priv = NULL;
493#ifdef TCP_ACK_FILTER
494 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
495#endif
496 /**
497 * Configuration packet always at the front
498 **/
499 PRINT_D(TX_DBG, "Adding the config packet at the Queue tail\n");
500
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900501 if (wilc_wlan_txq_add_to_head(tqe))
502 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900503 return 1;
504}
505
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900506static 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 +0900507{
508 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
509 struct txq_entry_t *tqe;
510
511 if (p->quit)
512 return 0;
513
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700514 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900515
516 if (tqe == NULL)
517 return 0;
518 tqe->type = WILC_NET_PKT;
519 tqe->buffer = buffer;
520 tqe->buffer_size = buffer_size;
521 tqe->tx_complete_func = func;
522 tqe->priv = priv;
523
524 PRINT_D(TX_DBG, "Adding mgmt packet at the Queue tail\n");
525#ifdef TCP_ACK_FILTER
526 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
Abdul Hussain5a66bf22015-06-16 09:44:06 +0000527 if (is_TCP_ACK_Filter_Enabled())
Glen Lee25a84832015-09-16 18:53:22 +0900528 tcp_process(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900529#endif
530 wilc_wlan_txq_add_to_tail(tqe);
531 /*return number of itemes in the queue*/
532 return p->txq_entries;
533}
Glen Leefcc6ef92015-09-16 18:53:21 +0900534
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900535int 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 +0900536{
537
538 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
539 struct txq_entry_t *tqe;
540
541 if (p->quit)
542 return 0;
543
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700544 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900545
546 if (tqe == NULL)
547 return 0;
548 tqe->type = WILC_MGMT_PKT;
549 tqe->buffer = buffer;
550 tqe->buffer_size = buffer_size;
551 tqe->tx_complete_func = func;
552 tqe->priv = priv;
553#ifdef TCP_ACK_FILTER
554 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
555#endif
556 PRINT_D(TX_DBG, "Adding Network packet at the Queue tail\n");
557 wilc_wlan_txq_add_to_tail(tqe);
558 return 1;
559}
Glen Leefcc6ef92015-09-16 18:53:21 +0900560
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900561static struct txq_entry_t *wilc_wlan_txq_get_first(void)
562{
563 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
564 struct txq_entry_t *tqe;
565 unsigned long flags;
566
Glen Lee85e57562015-09-24 18:14:56 +0900567 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900568
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900569 tqe = p->txq_head;
570
Glen Lee85e57562015-09-24 18:14:56 +0900571 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900572
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900573
574 return tqe;
575}
576
577static struct txq_entry_t *wilc_wlan_txq_get_next(struct txq_entry_t *tqe)
578{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900579 unsigned long flags;
Glen Lee85e57562015-09-24 18:14:56 +0900580 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900581
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900582 tqe = tqe->next;
Glen Lee85e57562015-09-24 18:14:56 +0900583 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900584
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900585
586 return tqe;
587}
588
589static int wilc_wlan_rxq_add(struct rxq_entry_t *rqe)
590{
591 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
592
593 if (p->quit)
594 return 0;
595
Glen Lee645db602015-09-24 18:14:57 +0900596 mutex_lock(&g_linux_wlan->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900597 if (p->rxq_head == NULL) {
598 PRINT_D(RX_DBG, "Add to Queue head\n");
599 rqe->next = NULL;
600 p->rxq_head = rqe;
601 p->rxq_tail = rqe;
602 } else {
603 PRINT_D(RX_DBG, "Add to Queue tail\n");
604 p->rxq_tail->next = rqe;
605 rqe->next = NULL;
606 p->rxq_tail = rqe;
607 }
608 p->rxq_entries += 1;
609 PRINT_D(RX_DBG, "Number of queue entries: %d\n", p->rxq_entries);
Glen Lee645db602015-09-24 18:14:57 +0900610 mutex_unlock(&g_linux_wlan->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900611 return p->rxq_entries;
612}
613
614static struct rxq_entry_t *wilc_wlan_rxq_remove(void)
615{
616 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
617
618 PRINT_D(RX_DBG, "Getting rxQ element\n");
619 if (p->rxq_head) {
620 struct rxq_entry_t *rqe;
621
Glen Lee645db602015-09-24 18:14:57 +0900622 mutex_lock(&g_linux_wlan->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900623 rqe = p->rxq_head;
624 p->rxq_head = p->rxq_head->next;
625 p->rxq_entries -= 1;
626 PRINT_D(RX_DBG, "RXQ entries decreased\n");
Glen Lee645db602015-09-24 18:14:57 +0900627 mutex_unlock(&g_linux_wlan->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900628 return rqe;
629 }
630 PRINT_D(RX_DBG, "Nothing to get from Q\n");
631 return NULL;
632}
633
634
635/********************************************
636 *
637 * Power Save handle functions
638 *
639 ********************************************/
640
641
642
643#ifdef WILC_OPTIMIZE_SLEEP_INT
644
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900645static inline void chip_allow_sleep(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900646{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900647 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900648
649 /* Clear bit 1 */
650 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
651
Anish Bhattffda2032015-09-29 12:15:49 -0700652 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900653}
654
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900655static inline void chip_wakeup(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900656{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900657 u32 reg, clk_status_reg, trials = 0;
658 u32 sleep_time;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900659
660 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
661 do {
662 g_wlan.hif_func.hif_read_reg(1, &reg);
663 /* Set bit 1 */
Anish Bhattffda2032015-09-29 12:15:49 -0700664 g_wlan.hif_func.hif_write_reg(1, reg | BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900665
666 /* Clear bit 1*/
Anish Bhattffda2032015-09-29 12:15:49 -0700667 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900668
669 do {
670 /* Wait for the chip to stabilize*/
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -0700671 usleep_range(2 * 1000, 2 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900672 /* Make sure chip is awake. This is an extra step that can be removed */
673 /* later to avoid the bus access overhead */
Dean Lee72ed4dc2015-06-12 14:11:44 +0900674 if ((wilc_get_chipid(true) == 0)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900675 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
676 }
Dean Lee72ed4dc2015-06-12 14:11:44 +0900677 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900678
Dean Lee72ed4dc2015-06-12 14:11:44 +0900679 } while (wilc_get_chipid(true) == 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900680 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
681 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
682 do {
683 /* Set bit 1 */
Anish Bhattffda2032015-09-29 12:15:49 -0700684 g_wlan.hif_func.hif_write_reg(0xf0, reg | BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900685
686 /* Check the clock status */
687 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
688
689 /* in case of clocks off, wait 2ms, and check it again. */
690 /* if still off, wait for another 2ms, for a total wait of 6ms. */
691 /* If still off, redo the wake up sequence */
692 while (((clk_status_reg & 0x1) == 0) && (((++trials) % 3) == 0)) {
693 /* Wait for the chip to stabilize*/
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -0700694 usleep_range(2 * 1000, 2 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900695
696 /* Make sure chip is awake. This is an extra step that can be removed */
697 /* later to avoid the bus access overhead */
698 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
699
700 if ((clk_status_reg & 0x1) == 0) {
701 wilc_debug(N_ERR, "clocks still OFF. Wake up failed\n");
702 }
703 }
704 /* in case of failure, Reset the wakeup bit to introduce a new edge on the next loop */
705 if ((clk_status_reg & 0x1) == 0) {
706 /* Reset bit 0 */
Anish Bhattffda2032015-09-29 12:15:49 -0700707 g_wlan.hif_func.hif_write_reg(0xf0, reg &
708 (~BIT(0)));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900709 }
710 } while ((clk_status_reg & 0x1) == 0);
711 }
712
713
714 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
715 g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -0700716 reg &= ~BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900717 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
718
Dean Lee72ed4dc2015-06-12 14:11:44 +0900719 if (wilc_get_chipid(false) >= 0x1002b0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900720 /* Enable PALDO back right after wakeup */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900721 u32 val32;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900722
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900723 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700724 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900725 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
726
727 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700728 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900729 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
730 }
731 }
732 genuChipPSstate = CHIP_WAKEDUP;
733}
734#else
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900735static inline void chip_wakeup(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900736{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900737 u32 reg, trials = 0;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900738
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900739 do {
740 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
741 g_wlan.hif_func.hif_read_reg(1, &reg);
742 /* Make sure bit 1 is 0 before we start. */
Anish Bhattffda2032015-09-29 12:15:49 -0700743 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900744 /* Set bit 1 */
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 /* Clear 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 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
749 /* Make sure bit 0 is 0 before we start. */
750 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -0700751 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900752 /* Set bit 1 */
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 /* Clear 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 }
757
758 do {
759 /* Wait for the chip to stabilize*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900760 mdelay(3);
761
762 /* Make sure chip is awake. This is an extra step that can be removed */
763 /* later to avoid the bus access overhead */
Dean Lee72ed4dc2015-06-12 14:11:44 +0900764 if ((wilc_get_chipid(true) == 0)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900765 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
766 }
Dean Lee72ed4dc2015-06-12 14:11:44 +0900767 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900768
Dean Lee72ed4dc2015-06-12 14:11:44 +0900769 } while (wilc_get_chipid(true) == 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900770
771 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
772 g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -0700773 reg &= ~BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900774 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
775
Dean Lee72ed4dc2015-06-12 14:11:44 +0900776 if (wilc_get_chipid(false) >= 0x1002b0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900777 /* Enable PALDO back right after wakeup */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900778 u32 val32;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900779
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900780 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700781 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900782 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
783
784 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700785 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900786 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
787 }
788 }
789 genuChipPSstate = CHIP_WAKEDUP;
790}
791#endif
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900792void chip_sleep_manually(u32 u32SleepTime)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900793{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900794 if (genuChipPSstate != CHIP_WAKEDUP) {
795 /* chip is already sleeping. Do nothing */
796 return;
797 }
798 acquire_bus(ACQUIRE_ONLY);
799
800#ifdef WILC_OPTIMIZE_SLEEP_INT
801 chip_allow_sleep();
802#endif
803
804 /* Trigger the manual sleep interrupt */
805 g_wlan.hif_func.hif_write_reg(0x10a8, 1);
806
807 genuChipPSstate = CHIP_SLEEPING_MANUAL;
808 release_bus(RELEASE_ONLY);
809
810}
811
812
813/********************************************
814 *
815 * Tx, Rx queue handle functions
816 *
817 ********************************************/
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900818static int wilc_wlan_handle_txq(u32 *pu32TxqCount)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900819{
820 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
821 int i, entries = 0;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900822 u32 sum;
823 u32 reg;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900824 u8 *txb = p->tx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900825 u32 offset = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900826 int vmm_sz = 0;
827 struct txq_entry_t *tqe;
828 int ret = 0;
829 int counter;
830 int timeout;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900831 u32 vmm_table[WILC_VMM_TBL_SIZE];
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900832
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900833 p->txq_exit = 0;
834 do {
835 if (p->quit)
836 break;
837
Glen Leeb002e202015-09-24 18:15:05 +0900838 linux_wlan_lock_timeout(&g_linux_wlan->txq_add_to_head_cs,
839 CFG_PKTS_TIMEOUT);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900840#ifdef TCP_ACK_FILTER
841 wilc_wlan_txq_filter_dup_tcp_ack();
842#endif
843 /**
844 * build the vmm list
845 **/
846 PRINT_D(TX_DBG, "Getting the head of the TxQ\n");
847 tqe = wilc_wlan_txq_get_first();
848 i = 0;
849 sum = 0;
850 do {
851 /* if ((tqe != NULL) && (i < (8)) && */
852 /* if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE-1)) && */
853 if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE - 1)) /* reserve last entry to 0 */) {
854
855 if (tqe->type == WILC_CFG_PKT) {
856 vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET;
857 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900858 else if (tqe->type == WILC_NET_PKT) {
859 vmm_sz = ETH_ETHERNET_HDR_OFFSET;
860 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900861 else {
862 vmm_sz = HOST_HDR_OFFSET;
863 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900864 vmm_sz += tqe->buffer_size;
865 PRINT_D(TX_DBG, "VMM Size before alignment = %d\n", vmm_sz);
866 if (vmm_sz & 0x3) { /* has to be word aligned */
867 vmm_sz = (vmm_sz + 4) & ~0x3;
868 }
Glen Lee7015b5d2015-09-24 18:15:02 +0900869 if ((sum + vmm_sz) > LINUX_TX_SIZE) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900870 break;
871 }
872 PRINT_D(TX_DBG, "VMM Size AFTER alignment = %d\n", vmm_sz);
873 vmm_table[i] = vmm_sz / 4; /* table take the word size */
874 PRINT_D(TX_DBG, "VMMTable entry size = %d\n", vmm_table[i]);
875
876 if (tqe->type == WILC_CFG_PKT) {
Anish Bhattffda2032015-09-29 12:15:49 -0700877 vmm_table[i] |= BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900878 PRINT_D(TX_DBG, "VMMTable entry changed for CFG packet = %d\n", vmm_table[i]);
879 }
880#ifdef BIG_ENDIAN
881 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
882#endif
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900883
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900884 i++;
885 sum += vmm_sz;
886 PRINT_D(TX_DBG, "sum = %d\n", sum);
887 tqe = wilc_wlan_txq_get_next(tqe);
888 } else {
889 break;
890 }
891 } while (1);
892
893 if (i == 0) { /* nothing in the queue */
894 PRINT_D(TX_DBG, "Nothing in TX-Q\n");
895 break;
896 } else {
897 PRINT_D(TX_DBG, "Mark the last entry in VMM table - number of previous entries = %d\n", i);
898 vmm_table[i] = 0x0; /* mark the last element to 0 */
899 }
900 acquire_bus(ACQUIRE_AND_WAKEUP);
901 counter = 0;
902 do {
903
904 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg);
905 if (!ret) {
906 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg vmm_tbl_entry..\n");
907 break;
908 }
909
910 if ((reg & 0x1) == 0) {
911 /**
912 * write to vmm table
913 **/
914 PRINT_D(TX_DBG, "Writing VMM table ... with Size = %d\n", ((i + 1) * 4));
915 break;
916 } else {
917 counter++;
918 if (counter > 200) {
919 counter = 0;
920 PRINT_D(TX_DBG, "Looping in tx ctrl , forcce quit\n");
921 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, 0);
922 break;
923 }
924 /**
925 * wait for vmm table is ready
926 **/
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530927 PRINT_WRN(GENERIC_DBG, "[wilc txq]: warn, vmm table not clear yet, wait...\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900928 release_bus(RELEASE_ALLOW_SLEEP);
Greg Kroah-Hartman2b922cb2015-09-04 09:30:51 -0700929 usleep_range(3000, 3000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900930 acquire_bus(ACQUIRE_AND_WAKEUP);
931 }
932 } while (!p->quit);
933
934 if (!ret) {
935 goto _end_;
936 }
937
938 timeout = 200;
939 do {
940
941 /**
942 * write to vmm table
943 **/
Chaehyun Limc3ca6372015-09-20 15:51:19 +0900944 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 +0900945 if (!ret) {
946 wilc_debug(N_ERR, "ERR block TX of VMM table.\n");
947 break;
948 }
949
950
951 /**
952 * interrupt firmware
953 **/
954 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x2);
955 if (!ret) {
956 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg host_vmm_ctl..\n");
957 break;
958 }
959
960 /**
961 * wait for confirm...
962 **/
963
964 do {
965 ret = p->hif_func.hif_read_reg(WILC_HOST_VMM_CTL, &reg);
966 if (!ret) {
967 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg host_vmm_ctl..\n");
968 break;
969 }
970 if ((reg >> 2) & 0x1) {
971 /**
972 * Get the entries
973 **/
974 entries = ((reg >> 3) & 0x3f);
975 /* entries = ((reg>>3)&0x2f); */
976 break;
977 } else {
978 release_bus(RELEASE_ALLOW_SLEEP);
Greg Kroah-Hartman2b922cb2015-09-04 09:30:51 -0700979 usleep_range(3000, 3000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900980 acquire_bus(ACQUIRE_AND_WAKEUP);
981 PRINT_WRN(GENERIC_DBG, "Can't get VMM entery - reg = %2x\n", reg);
982 }
983 } while (--timeout);
984 if (timeout <= 0) {
985 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x0);
986 break;
987 }
988
989 if (!ret) {
990 break;
991 }
992
993 if (entries == 0) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530994 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 +0900995
996 /* undo the transaction. */
997 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg);
998 if (!ret) {
999 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg WILC_HOST_TX_CTRL..\n");
1000 break;
1001 }
Anish Bhattffda2032015-09-29 12:15:49 -07001002 reg &= ~BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001003 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, reg);
1004 if (!ret) {
1005 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg WILC_HOST_TX_CTRL..\n");
1006 break;
1007 }
1008 break;
1009 } else {
1010 break;
1011 }
1012 } while (1);
1013
1014 if (!ret) {
1015 goto _end_;
1016 }
1017 if (entries == 0) {
1018 ret = WILC_TX_ERR_NO_BUF;
1019 goto _end_;
1020 }
1021
1022 /* since copying data into txb takes some time, then
1023 * allow the bus lock to be released let the RX task go. */
1024 release_bus(RELEASE_ALLOW_SLEEP);
1025
1026 /**
1027 * Copy data to the TX buffer
1028 **/
1029 offset = 0;
1030 i = 0;
1031 do {
1032 tqe = wilc_wlan_txq_remove_from_head();
1033 if (tqe != NULL && (vmm_table[i] != 0)) {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001034 u32 header, buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001035
1036#ifdef BIG_ENDIAN
1037 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
1038#endif
1039 vmm_sz = (vmm_table[i] & 0x3ff); /* in word unit */
1040 vmm_sz *= 4;
1041 header = (tqe->type << 31) | (tqe->buffer_size << 15) | vmm_sz;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301042 if (tqe->type == WILC_MGMT_PKT)
Anish Bhattffda2032015-09-29 12:15:49 -07001043 header |= BIT(30);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301044 else
Anish Bhattffda2032015-09-29 12:15:49 -07001045 header &= ~BIT(30);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001046
1047#ifdef BIG_ENDIAN
1048 header = BYTE_SWAP(header);
1049#endif
1050 memcpy(&txb[offset], &header, 4);
1051 if (tqe->type == WILC_CFG_PKT) {
1052 buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET;
1053 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001054 else if (tqe->type == WILC_NET_PKT) {
1055 char *pBSSID = ((struct tx_complete_data *)(tqe->priv))->pBssid;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001056
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001057 buffer_offset = ETH_ETHERNET_HDR_OFFSET;
1058 /* copy the bssid at the sart of the buffer */
1059 memcpy(&txb[offset + 4], pBSSID, 6);
1060 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001061 else {
1062 buffer_offset = HOST_HDR_OFFSET;
1063 }
1064
1065 memcpy(&txb[offset + buffer_offset], tqe->buffer, tqe->buffer_size);
1066 offset += vmm_sz;
1067 i++;
1068 tqe->status = 1; /* mark the packet send */
1069 if (tqe->tx_complete_func)
1070 tqe->tx_complete_func(tqe->priv, tqe->status);
1071 #ifdef TCP_ACK_FILTER
1072 if (tqe->tcp_PendingAck_index != NOT_TCP_ACK) {
1073 Pending_Acks_info[tqe->tcp_PendingAck_index].txqe = NULL;
1074 }
1075 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001076 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001077 } else {
1078 break;
1079 }
1080 } while (--entries);
1081
1082 /**
1083 * lock the bus
1084 **/
1085 acquire_bus(ACQUIRE_AND_WAKEUP);
1086
1087 ret = p->hif_func.hif_clear_int_ext(ENABLE_TX_VMM);
1088 if (!ret) {
1089 wilc_debug(N_ERR, "[wilc txq]: fail can't start tx VMM ...\n");
1090 goto _end_;
1091 }
1092
1093 /**
1094 * transfer
1095 **/
1096 ret = p->hif_func.hif_block_tx_ext(0, txb, offset);
1097 if (!ret) {
1098 wilc_debug(N_ERR, "[wilc txq]: fail can't block tx ext...\n");
1099 goto _end_;
1100 }
1101
1102_end_:
1103
1104 release_bus(RELEASE_ALLOW_SLEEP);
1105 if (ret != 1)
1106 break;
1107 } while (0);
Glen Leed5a63a82015-09-24 18:15:00 +09001108 up(&g_linux_wlan->txq_add_to_head_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001109
1110 p->txq_exit = 1;
1111 PRINT_D(TX_DBG, "THREAD: Exiting txq\n");
1112 /* return tx[]q count */
1113 *pu32TxqCount = p->txq_entries;
1114 return ret;
1115}
1116
1117static void wilc_wlan_handle_rxq(void)
1118{
1119 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1120 int offset = 0, size, has_packet = 0;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001121 u8 *buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001122 struct rxq_entry_t *rqe;
1123
1124 p->rxq_exit = 0;
1125
1126
1127
1128
1129 do {
1130 if (p->quit) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301131 PRINT_D(RX_DBG, "exit 1st do-while due to Clean_UP function\n");
Glen Lee6a3b94f2015-09-24 18:14:59 +09001132 up(&g_linux_wlan->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001133 break;
1134 }
1135 rqe = wilc_wlan_rxq_remove();
1136 if (rqe == NULL) {
1137 PRINT_D(RX_DBG, "nothing in the queue - exit 1st do-while\n");
1138 break;
1139 }
1140 buffer = rqe->buffer;
1141 size = rqe->buffer_size;
1142 PRINT_D(RX_DBG, "rxQ entery Size = %d - Address = %p\n", size, buffer);
1143 offset = 0;
1144
1145
1146
1147 do {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001148 u32 header;
1149 u32 pkt_len, pkt_offset, tp_len;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001150 int is_cfg_packet;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001151
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001152 PRINT_D(RX_DBG, "In the 2nd do-while\n");
1153 memcpy(&header, &buffer[offset], 4);
1154#ifdef BIG_ENDIAN
1155 header = BYTE_SWAP(header);
1156#endif
1157 PRINT_D(RX_DBG, "Header = %04x - Offset = %d\n", header, offset);
1158
1159
1160
1161 is_cfg_packet = (header >> 31) & 0x1;
1162 pkt_offset = (header >> 22) & 0x1ff;
1163 tp_len = (header >> 11) & 0x7ff;
1164 pkt_len = header & 0x7ff;
1165
1166 if (pkt_len == 0 || tp_len == 0) {
1167 wilc_debug(N_RXQ, "[wilc rxq]: data corrupt, packet len or tp_len is 0 [%d][%d]\n", pkt_len, tp_len);
1168 break;
1169 }
1170
1171/*bug 3887: [AP] Allow Management frames to be passed to the host*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001172 #define IS_MANAGMEMENT 0x100
1173 #define IS_MANAGMEMENT_CALLBACK 0x080
1174 #define IS_MGMT_STATUS_SUCCES 0x040
1175
1176
1177 if (pkt_offset & IS_MANAGMEMENT) {
1178 /* reset mgmt indicator bit, to use pkt_offeset in furthur calculations */
1179 pkt_offset &= ~(IS_MANAGMEMENT | IS_MANAGMEMENT_CALLBACK | IS_MGMT_STATUS_SUCCES);
1180
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001181 WILC_WFI_mgmt_rx(&buffer[offset + HOST_HDR_OFFSET], pkt_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001182 }
1183 /* BUG4530 fix */
1184 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001185 {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001186
1187 if (!is_cfg_packet) {
Glen Lee63611672015-09-24 18:14:52 +09001188 if (pkt_len > 0) {
1189 frmw_to_linux(&buffer[offset],
1190 pkt_len,
1191 pkt_offset);
1192 has_packet = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001193 }
1194 } else {
1195 wilc_cfg_rsp_t rsp;
1196
1197
1198
Glen Lee1fea5932015-09-24 18:15:06 +09001199 mac_cfg.rx_indicate(&buffer[pkt_offset + offset], pkt_len, &rsp);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001200 if (rsp.type == WILC_CFG_RSP) {
1201 /**
1202 * wake up the waiting task...
1203 **/
1204 PRINT_D(RX_DBG, "p->cfg_seq_no = %d - rsp.seq_no = %d\n", p->cfg_seq_no, rsp.seq_no);
1205 if (p->cfg_seq_no == rsp.seq_no) {
Glen Lee6a3b94f2015-09-24 18:14:59 +09001206 up(&g_linux_wlan->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001207 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001208 } else if (rsp.type == WILC_CFG_RSP_STATUS) {
1209 /**
1210 * Call back to indicate status...
1211 **/
Glen Lee4417d3d2015-09-24 18:14:53 +09001212 linux_wlan_mac_indicate(WILC_MAC_INDICATE_STATUS);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001213
1214 } else if (rsp.type == WILC_CFG_RSP_SCAN) {
Glen Lee4417d3d2015-09-24 18:14:53 +09001215 linux_wlan_mac_indicate(WILC_MAC_INDICATE_SCAN);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001216 }
1217 }
1218 }
1219 offset += tp_len;
1220 if (offset >= size)
1221 break;
1222 } while (1);
1223
1224
1225#ifndef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001226 kfree(buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001227#endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001228 kfree(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001229
1230 if (has_packet) {
Glen Leec0cadaa2015-09-24 18:14:54 +09001231 linux_wlan_rx_complete();
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001232 }
1233 } while (1);
1234
1235 p->rxq_exit = 1;
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301236 PRINT_D(RX_DBG, "THREAD: Exiting RX thread\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001237}
1238
1239/********************************************
1240 *
1241 * Fast DMA Isr
1242 *
1243 ********************************************/
1244static void wilc_unknown_isr_ext(void)
1245{
1246 g_wlan.hif_func.hif_clear_int_ext(0);
1247}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001248static void wilc_pllupdate_isr_ext(u32 int_stats)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001249{
1250
1251 int trials = 10;
1252
1253 g_wlan.hif_func.hif_clear_int_ext(PLL_INT_CLR);
1254
1255 /* Waiting for PLL */
Greg Kroah-Hartmanc2e4c0f2015-09-03 19:09:50 -07001256 mdelay(WILC_PLL_TO);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001257
1258 /* poll till read a valid data */
Dean Lee72ed4dc2015-06-12 14:11:44 +09001259 while (!(ISWILC1000(wilc_get_chipid(true)) && --trials)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001260 PRINT_D(TX_DBG, "PLL update retrying\n");
Greg Kroah-Hartmanc2e4c0f2015-09-03 19:09:50 -07001261 mdelay(1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001262 }
1263}
1264
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001265static void wilc_sleeptimer_isr_ext(u32 int_stats1)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001266{
1267 g_wlan.hif_func.hif_clear_int_ext(SLEEP_INT_CLR);
1268#ifndef WILC_OPTIMIZE_SLEEP_INT
1269 genuChipPSstate = CHIP_SLEEPING_AUTO;
1270#endif
1271}
1272
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001273static void wilc_wlan_handle_isr_ext(u32 int_status)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001274{
1275 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1276#ifdef MEMORY_STATIC
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001277 u32 offset = p->rx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001278#endif
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001279 u8 *buffer = NULL;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001280 u32 size;
1281 u32 retries = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001282 int ret = 0;
1283 struct rxq_entry_t *rqe;
1284
1285
1286 /**
1287 * Get the rx size
1288 **/
1289
1290 size = ((int_status & 0x7fff) << 2);
1291
1292 while (!size && retries < 10) {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001293 u32 time = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001294 /*looping more secure*/
1295 /*zero size make a crashe because the dma will not happen and that will block the firmware*/
1296 wilc_debug(N_ERR, "RX Size equal zero ... Trying to read it again for %d time\n", time++);
1297 p->hif_func.hif_read_size(&size);
1298 size = ((size & 0x7fff) << 2);
1299 retries++;
1300
1301 }
1302
1303 if (size > 0) {
1304#ifdef MEMORY_STATIC
Glen Lee03eb7262015-09-24 18:15:03 +09001305 if (LINUX_RX_SIZE - offset < size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001306 offset = 0;
1307
1308 if (p->rx_buffer)
1309 buffer = &p->rx_buffer[offset];
1310 else {
1311 wilc_debug(N_ERR, "[wilc isr]: fail Rx Buffer is NULL...drop the packets (%d)\n", size);
1312 goto _end_;
1313 }
1314
1315#else
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001316 buffer = kmalloc(size, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001317 if (buffer == NULL) {
1318 wilc_debug(N_ERR, "[wilc isr]: fail alloc host memory...drop the packets (%d)\n", size);
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -07001319 usleep_range(100 * 1000, 100 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001320 goto _end_;
1321 }
1322#endif
1323
1324 /**
1325 * clear the chip's interrupt after getting size some register getting corrupted after clear the interrupt
1326 **/
1327 p->hif_func.hif_clear_int_ext(DATA_INT_CLR | ENABLE_RX_VMM);
1328
1329
1330 /**
1331 * start transfer
1332 **/
1333 ret = p->hif_func.hif_block_rx_ext(0, buffer, size);
1334
1335 if (!ret) {
1336 wilc_debug(N_ERR, "[wilc isr]: fail block rx...\n");
1337 goto _end_;
1338 }
1339_end_:
1340
1341
1342 if (ret) {
1343#ifdef MEMORY_STATIC
1344 offset += size;
1345 p->rx_buffer_offset = offset;
1346#endif
1347 /**
1348 * add to rx queue
1349 **/
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001350 rqe = kmalloc(sizeof(struct rxq_entry_t), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001351 if (rqe != NULL) {
1352 rqe->buffer = buffer;
1353 rqe->buffer_size = size;
1354 PRINT_D(RX_DBG, "rxq entery Size= %d - Address = %p\n", rqe->buffer_size, rqe->buffer);
1355 wilc_wlan_rxq_add(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001356 }
1357 } else {
1358#ifndef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001359 kfree(buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001360#endif
1361 }
1362 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001363 wilc_wlan_handle_rxq();
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001364}
1365
1366void wilc_handle_isr(void)
1367{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001368 u32 int_status;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001369
1370 acquire_bus(ACQUIRE_AND_WAKEUP);
1371 g_wlan.hif_func.hif_read_int(&int_status);
1372
1373 if (int_status & PLL_INT_EXT) {
1374 wilc_pllupdate_isr_ext(int_status);
1375 }
1376 if (int_status & DATA_INT_EXT) {
1377 wilc_wlan_handle_isr_ext(int_status);
1378 #ifndef WILC_OPTIMIZE_SLEEP_INT
1379 /* Chip is up and talking*/
1380 genuChipPSstate = CHIP_WAKEDUP;
1381 #endif
1382 }
1383 if (int_status & SLEEP_INT_EXT) {
1384 wilc_sleeptimer_isr_ext(int_status);
1385 }
1386
1387 if (!(int_status & (ALL_INT_EXT))) {
1388#ifdef WILC_SDIO
1389 PRINT_D(TX_DBG, ">> UNKNOWN_INTERRUPT - 0x%08x\n", int_status);
1390#endif
1391 wilc_unknown_isr_ext();
1392 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001393 release_bus(RELEASE_ALLOW_SLEEP);
1394}
1395
1396/********************************************
1397 *
1398 * Firmware download
1399 *
1400 ********************************************/
Glen Lee63d7ab82015-10-01 16:03:32 +09001401int wilc_wlan_firmware_download(const u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001402{
1403 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001404 u32 offset;
1405 u32 addr, size, size2, blksz;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001406 u8 *dma_buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001407 int ret = 0;
1408
Anish Bhattffda2032015-09-29 12:15:49 -07001409 blksz = BIT(12);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001410 /* Allocate a DMA coherent buffer. */
1411
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001412 dma_buffer = kmalloc(blksz, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001413 if (dma_buffer == NULL) {
1414 /*EIO 5*/
1415 ret = -5;
1416 PRINT_ER("Can't allocate buffer for firmware download IO error\n ");
1417 goto _fail_1;
1418 }
1419
1420 PRINT_D(INIT_DBG, "Downloading firmware size = %d ...\n", buffer_size);
1421 /**
1422 * load the firmware
1423 **/
1424 offset = 0;
1425 do {
1426 memcpy(&addr, &buffer[offset], 4);
1427 memcpy(&size, &buffer[offset + 4], 4);
1428#ifdef BIG_ENDIAN
1429 addr = BYTE_SWAP(addr);
1430 size = BYTE_SWAP(size);
1431#endif
1432 acquire_bus(ACQUIRE_ONLY);
1433 offset += 8;
1434 while (((int)size) && (offset < buffer_size)) {
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301435 if (size <= blksz)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001436 size2 = size;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301437 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001438 size2 = blksz;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001439 /* Copy firmware into a DMA coherent buffer */
1440 memcpy(dma_buffer, &buffer[offset], size2);
1441 ret = p->hif_func.hif_block_tx(addr, dma_buffer, size2);
1442 if (!ret)
1443 break;
1444
1445 addr += size2;
1446 offset += size2;
1447 size -= size2;
1448 }
1449 release_bus(RELEASE_ONLY);
1450
1451 if (!ret) {
1452 /*EIO 5*/
1453 ret = -5;
1454 PRINT_ER("Can't download firmware IO error\n ");
1455 goto _fail_;
1456 }
1457 PRINT_D(INIT_DBG, "Offset = %d\n", offset);
1458 } while (offset < buffer_size);
1459
1460_fail_:
1461
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001462 kfree(dma_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001463
1464_fail_1:
1465
1466 return (ret < 0) ? ret : 0;
1467}
1468
1469/********************************************
1470 *
1471 * Common
1472 *
1473 ********************************************/
Glen Leee42563b2015-10-01 16:03:33 +09001474int wilc_wlan_start(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001475{
1476 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001477 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001478 int ret;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001479 u32 chipid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001480
1481 /**
1482 * Set the host interface
1483 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001484 if (p->io_func.io_type == HIF_SDIO) {
1485 reg = 0;
Anish Bhattffda2032015-09-29 12:15:49 -07001486 reg |= BIT(3); /* bug 4456 and 4557 */
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001487 } else if (p->io_func.io_type == HIF_SPI) {
1488 reg = 1;
1489 }
1490 acquire_bus(ACQUIRE_ONLY);
1491 ret = p->hif_func.hif_write_reg(WILC_VMM_CORE_CFG, reg);
1492 if (!ret) {
1493 wilc_debug(N_ERR, "[wilc start]: fail write reg vmm_core_cfg...\n");
1494 release_bus(RELEASE_ONLY);
1495 /* EIO 5*/
1496 ret = -5;
1497 return ret;
1498 }
1499 reg = 0;
1500#ifdef WILC_SDIO_IRQ_GPIO
1501 reg |= WILC_HAVE_SDIO_IRQ_GPIO;
1502#endif
1503
1504#ifdef WILC_DISABLE_PMU
1505#else
1506 reg |= WILC_HAVE_USE_PMU;
1507#endif
1508
1509#ifdef WILC_SLEEP_CLK_SRC_XO
1510 reg |= WILC_HAVE_SLEEP_CLK_SRC_XO;
1511#elif defined WILC_SLEEP_CLK_SRC_RTC
1512 reg |= WILC_HAVE_SLEEP_CLK_SRC_RTC;
1513#endif
1514
1515#ifdef WILC_EXT_PA_INV_TX_RX
1516 reg |= WILC_HAVE_EXT_PA_INV_TX_RX;
1517#endif
1518
1519 reg |= WILC_HAVE_LEGACY_RF_SETTINGS;
1520
1521
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001522/*Set oscillator frequency*/
1523#ifdef XTAL_24
1524 reg |= WILC_HAVE_XTAL_24;
1525#endif
1526
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001527/*Enable/Disable GPIO configuration for FW logs*/
1528#ifdef DISABLE_WILC_UART
1529 reg |= WILC_HAVE_DISABLE_WILC_UART;
1530#endif
1531
1532 ret = p->hif_func.hif_write_reg(WILC_GP_REG_1, reg);
1533 if (!ret) {
1534 wilc_debug(N_ERR, "[wilc start]: fail write WILC_GP_REG_1 ...\n");
1535 release_bus(RELEASE_ONLY);
1536 /* EIO 5*/
1537 ret = -5;
1538 return ret;
1539 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001540
1541 /**
1542 * Bus related
1543 **/
1544 p->hif_func.hif_sync_ext(NUM_INT_EXT);
1545
1546 ret = p->hif_func.hif_read_reg(0x1000, &chipid);
1547 if (!ret) {
1548 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1000 ...\n");
1549 release_bus(RELEASE_ONLY);
1550 /* EIO 5*/
1551 ret = -5;
1552 return ret;
1553 }
1554
1555 /**
1556 * Go...
1557 **/
1558
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001559
1560 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -07001561 if ((reg & BIT(10)) == BIT(10)) {
1562 reg &= ~BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001563 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1564 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1565 }
1566
Anish Bhattffda2032015-09-29 12:15:49 -07001567 reg |= BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001568 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1569 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1570 release_bus(RELEASE_ONLY);
1571
1572 return (ret < 0) ? ret : 0;
1573}
1574
1575void wilc_wlan_global_reset(void)
1576{
1577
1578 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001579
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001580 acquire_bus(ACQUIRE_AND_WAKEUP);
1581 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, 0x0);
1582 release_bus(RELEASE_ONLY);
1583}
Glen Lee8cec7412015-10-01 16:03:34 +09001584int wilc_wlan_stop(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001585{
1586 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001587 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001588 int ret;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001589 u8 timeout = 10;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001590 /**
1591 * TODO: stop the firmware, need a re-download
1592 **/
1593 acquire_bus(ACQUIRE_AND_WAKEUP);
1594
1595 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1596 if (!ret) {
1597 PRINT_ER("Error while reading reg\n");
1598 release_bus(RELEASE_ALLOW_SLEEP);
1599 return ret;
1600 }
1601
Anish Bhattffda2032015-09-29 12:15:49 -07001602 reg &= ~BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001603
1604
1605 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1606 if (!ret) {
1607 PRINT_ER("Error while writing reg\n");
1608 release_bus(RELEASE_ALLOW_SLEEP);
1609 return ret;
1610 }
1611
1612
1613
1614 do {
1615 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1616 if (!ret) {
1617 PRINT_ER("Error while reading reg\n");
1618 release_bus(RELEASE_ALLOW_SLEEP);
1619 return ret;
1620 }
1621 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1622 /*Workaround to ensure that the chip is actually reset*/
Anish Bhattffda2032015-09-29 12:15:49 -07001623 if ((reg & BIT(10))) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001624 PRINT_D(GENERIC_DBG, "Bit 10 not reset : Retry %d\n", timeout);
Anish Bhattffda2032015-09-29 12:15:49 -07001625 reg &= ~BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001626 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1627 timeout--;
1628 } else {
1629 PRINT_D(GENERIC_DBG, "Bit 10 reset after : Retry %d\n", timeout);
1630 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1631 if (!ret) {
1632 PRINT_ER("Error while reading reg\n");
1633 release_bus(RELEASE_ALLOW_SLEEP);
1634 return ret;
1635 }
1636 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1637 break;
1638 }
1639
1640 } while (timeout);
Anish Bhattffda2032015-09-29 12:15:49 -07001641 reg = (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(8) | BIT(9) | BIT(26) |
1642 BIT(29) | BIT(30) | BIT(31));
Anish Bhatt65ead4e2015-09-29 12:15:48 -07001643
1644 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
Anish Bhattffda2032015-09-29 12:15:49 -07001645 reg = (u32)~BIT(10);
Anish Bhatt65ead4e2015-09-29 12:15:48 -07001646
1647 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001648
1649 release_bus(RELEASE_ALLOW_SLEEP);
1650
1651 return ret;
1652}
1653
1654static void wilc_wlan_cleanup(void)
1655{
1656 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1657 struct txq_entry_t *tqe;
1658 struct rxq_entry_t *rqe;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001659 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001660 int ret;
1661
1662 p->quit = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001663 do {
1664 tqe = wilc_wlan_txq_remove_from_head();
1665 if (tqe == NULL)
1666 break;
1667 if (tqe->tx_complete_func)
1668 tqe->tx_complete_func(tqe->priv, 0);
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001669 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001670 } while (1);
1671
1672 do {
1673 rqe = wilc_wlan_rxq_remove();
1674 if (rqe == NULL)
1675 break;
Javier Martinez Canillas6a272242015-09-22 15:24:50 +02001676#ifndef MEMORY_STATIC
1677 kfree(rqe->buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001678#endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001679 kfree(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001680 } while (1);
1681
1682 /**
1683 * clean up buffer
1684 **/
1685
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001686 #ifdef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001687 kfree(p->rx_buffer);
1688 p->rx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001689 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001690 kfree(p->tx_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001691
1692 acquire_bus(ACQUIRE_AND_WAKEUP);
1693
1694
1695 ret = p->hif_func.hif_read_reg(WILC_GP_REG_0, &reg);
1696 if (!ret) {
1697 PRINT_ER("Error while reading reg\n");
1698 release_bus(RELEASE_ALLOW_SLEEP);
1699 }
1700 PRINT_ER("Writing ABORT reg\n");
1701 ret = p->hif_func.hif_write_reg(WILC_GP_REG_0, (reg | ABORT_INT));
1702 if (!ret) {
1703 PRINT_ER("Error while writing reg\n");
1704 release_bus(RELEASE_ALLOW_SLEEP);
1705 }
1706 release_bus(RELEASE_ALLOW_SLEEP);
1707 /**
1708 * io clean up
1709 **/
1710 p->hif_func.hif_deinit(NULL);
1711
1712}
1713
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001714static int wilc_wlan_cfg_commit(int type, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001715{
1716 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1717 wilc_cfg_frame_t *cfg = &p->cfg_frame;
1718 int total_len = p->cfg_frame_offset + 4 + DRIVER_HANDLER_SIZE;
1719 int seq_no = p->cfg_seq_no % 256;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001720 int driver_handler = (u32)drvHandler;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001721
1722
1723 /**
1724 * Set up header
1725 **/
1726 if (type == WILC_CFG_SET) { /* Set */
1727 cfg->wid_header[0] = 'W';
1728 } else { /* Query */
1729 cfg->wid_header[0] = 'Q';
1730 }
1731 cfg->wid_header[1] = seq_no; /* sequence number */
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001732 cfg->wid_header[2] = (u8)total_len;
1733 cfg->wid_header[3] = (u8)(total_len >> 8);
1734 cfg->wid_header[4] = (u8)driver_handler;
1735 cfg->wid_header[5] = (u8)(driver_handler >> 8);
1736 cfg->wid_header[6] = (u8)(driver_handler >> 16);
1737 cfg->wid_header[7] = (u8)(driver_handler >> 24);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001738 p->cfg_seq_no = seq_no;
1739
1740 /**
1741 * Add to TX queue
1742 **/
1743
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001744 if (!wilc_wlan_txq_add_cfg_pkt(&cfg->wid_header[0], total_len))
1745 return -1;
1746
1747 return 0;
1748}
1749
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001750static 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 +09001751{
1752 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001753 u32 offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001754 int ret_size;
1755
1756
1757 if (p->cfg_frame_in_use)
1758 return 0;
1759
1760 if (start)
1761 p->cfg_frame_offset = 0;
1762
1763 offset = p->cfg_frame_offset;
Glen Lee1fea5932015-09-24 18:15:06 +09001764 ret_size = mac_cfg.cfg_wid_set(p->cfg_frame.frame, offset, (u16)wid,
1765 buffer, buffer_size);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001766 offset += ret_size;
1767 p->cfg_frame_offset = offset;
1768
1769 if (commit) {
1770 PRINT_D(TX_DBG, "[WILC]PACKET Commit with sequence number %d\n", p->cfg_seq_no);
1771 PRINT_D(RX_DBG, "Processing cfg_set()\n");
1772 p->cfg_frame_in_use = 1;
1773
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001774 if (wilc_wlan_cfg_commit(WILC_CFG_SET, drvHandler))
Chaehyun Lim5af6b852015-09-17 16:48:48 +09001775 ret_size = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001776
Glen Leeb002e202015-09-24 18:15:05 +09001777 if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event,
1778 CFG_PKTS_TIMEOUT)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001779 PRINT_D(TX_DBG, "Set Timed Out\n");
1780 ret_size = 0;
1781 }
1782 p->cfg_frame_in_use = 0;
1783 p->cfg_frame_offset = 0;
1784 p->cfg_seq_no += 1;
1785
1786 }
1787
1788 return ret_size;
1789}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001790static int wilc_wlan_cfg_get(int start, u32 wid, int commit, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001791{
1792 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001793 u32 offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001794 int ret_size;
1795
1796
1797 if (p->cfg_frame_in_use)
1798 return 0;
1799
1800 if (start)
1801 p->cfg_frame_offset = 0;
1802
1803 offset = p->cfg_frame_offset;
Glen Lee1fea5932015-09-24 18:15:06 +09001804 ret_size = mac_cfg.cfg_wid_get(p->cfg_frame.frame, offset, (u16)wid);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001805 offset += ret_size;
1806 p->cfg_frame_offset = offset;
1807
1808 if (commit) {
1809 p->cfg_frame_in_use = 1;
1810
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001811 if (wilc_wlan_cfg_commit(WILC_CFG_QUERY, drvHandler))
Chaehyun Lim5af6b852015-09-17 16:48:48 +09001812 ret_size = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001813
1814
Glen Leeb002e202015-09-24 18:15:05 +09001815 if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event,
1816 CFG_PKTS_TIMEOUT)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001817 PRINT_D(TX_DBG, "Get Timed Out\n");
1818 ret_size = 0;
1819 }
1820 PRINT_D(GENERIC_DBG, "[WILC]Get Response received\n");
1821 p->cfg_frame_in_use = 0;
1822 p->cfg_frame_offset = 0;
1823 p->cfg_seq_no += 1;
1824 }
1825
1826 return ret_size;
1827}
1828
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001829static int wilc_wlan_cfg_get_val(u32 wid, u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001830{
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001831 int ret;
1832
Glen Lee1fea5932015-09-24 18:15:06 +09001833 ret = mac_cfg.cfg_wid_get_val((u16)wid, buffer, buffer_size);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001834
1835 return ret;
1836}
1837
1838void wilc_bus_set_max_speed(void)
1839{
1840
1841 /* Increase bus speed to max possible. */
1842 g_wlan.hif_func.hif_set_max_bus_speed();
1843}
1844
1845void wilc_bus_set_default_speed(void)
1846{
1847
1848 /* Restore bus speed to default. */
1849 g_wlan.hif_func.hif_set_default_bus_speed();
1850}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001851u32 init_chip(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001852{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001853 u32 chipid;
1854 u32 reg, ret = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001855
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001856 acquire_bus(ACQUIRE_ONLY);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001857
Dean Lee72ed4dc2015-06-12 14:11:44 +09001858 chipid = wilc_get_chipid(true);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001859
1860
1861
1862 if ((chipid & 0xfff) != 0xa0) {
1863 /**
1864 * Avoid booting from boot ROM. Make sure that Drive IRQN [SDIO platform]
1865 * or SD_DAT3 [SPI platform] to ?1?
1866 **/
1867 /* Set cortus reset register to register control. */
1868 ret = g_wlan.hif_func.hif_read_reg(0x1118, &reg);
1869 if (!ret) {
1870 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1118 ...\n");
1871 return ret;
1872 }
Anish Bhattffda2032015-09-29 12:15:49 -07001873 reg |= BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001874 ret = g_wlan.hif_func.hif_write_reg(0x1118, reg);
1875 if (!ret) {
1876 wilc_debug(N_ERR, "[wilc start]: fail write reg 0x1118 ...\n");
1877 return ret;
1878 }
1879 /**
1880 * Write branch intruction to IRAM (0x71 trap) at location 0xFFFF0000
1881 * (Cortus map) or C0000 (AHB map).
1882 **/
1883 ret = g_wlan.hif_func.hif_write_reg(0xc0000, 0x71);
1884 if (!ret) {
1885 wilc_debug(N_ERR, "[wilc start]: fail write reg 0xc0000 ...\n");
1886 return ret;
1887 }
1888 }
1889
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001890 release_bus(RELEASE_ONLY);
1891
1892 return ret;
1893
1894}
1895
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001896u32 wilc_get_chipid(u8 update)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001897{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001898 static u32 chipid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001899 /* SDIO can't read into global variables */
1900 /* Use this variable as a temp, then copy to the global */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001901 u32 tempchipid = 0;
1902 u32 rfrevid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001903
1904 if (chipid == 0 || update != 0) {
1905 g_wlan.hif_func.hif_read_reg(0x1000, &tempchipid);
1906 g_wlan.hif_func.hif_read_reg(0x13f4, &rfrevid);
1907 if (!ISWILC1000(tempchipid)) {
1908 chipid = 0;
1909 goto _fail_;
1910 }
1911 if (tempchipid == 0x1002a0) {
1912 if (rfrevid == 0x1) { /* 1002A0 */
1913 } else { /* if (rfrevid == 0x2) */ /* 1002A1 */
1914 tempchipid = 0x1002a1;
1915 }
1916 } else if (tempchipid == 0x1002b0) {
1917 if (rfrevid == 3) { /* 1002B0 */
1918 } else if (rfrevid == 4) { /* 1002B1 */
1919 tempchipid = 0x1002b1;
1920 } else { /* if(rfrevid == 5) */ /* 1002B2 */
1921 tempchipid = 0x1002b2;
1922 }
1923 } else {
1924 }
1925
1926 chipid = tempchipid;
1927 }
1928_fail_:
1929 return chipid;
1930}
1931
1932#ifdef COMPLEMENT_BOOT
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001933u8 core_11b_ready(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001934{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001935 u32 reg_val;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001936
1937 acquire_bus(ACQUIRE_ONLY);
1938 g_wlan.hif_func.hif_write_reg(0x16082c, 1);
1939 g_wlan.hif_func.hif_write_reg(0x161600, 0x90);
1940 g_wlan.hif_func.hif_read_reg(0x161600, &reg_val);
1941 release_bus(RELEASE_ONLY);
1942
1943 if (reg_val == 0x90)
1944 return 0;
1945 else
1946 return 1;
1947}
1948#endif
1949
1950int wilc_wlan_init(wilc_wlan_inp_t *inp, wilc_wlan_oup_t *oup)
1951{
1952
1953 int ret = 0;
1954
1955 PRINT_D(INIT_DBG, "Initializing WILC_Wlan ...\n");
1956
1957 memset((void *)&g_wlan, 0, sizeof(wilc_wlan_dev_t));
1958
1959 /**
1960 * store the input
1961 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001962 memcpy((void *)&g_wlan.io_func, (void *)&inp->io_func, sizeof(wilc_wlan_io_func_t));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001963 /***
1964 * host interface init
1965 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001966 if ((inp->io_func.io_type & 0x1) == HIF_SDIO) {
1967 if (!hif_sdio.hif_init(inp, wilc_debug)) {
1968 /* EIO 5 */
1969 ret = -5;
1970 goto _fail_;
1971 }
1972 memcpy((void *)&g_wlan.hif_func, &hif_sdio, sizeof(wilc_hif_func_t));
1973 } else {
1974 if ((inp->io_func.io_type & 0x1) == HIF_SPI) {
1975 /**
1976 * TODO:
1977 **/
1978 if (!hif_spi.hif_init(inp, wilc_debug)) {
1979 /* EIO 5 */
1980 ret = -5;
1981 goto _fail_;
1982 }
1983 memcpy((void *)&g_wlan.hif_func, &hif_spi, sizeof(wilc_hif_func_t));
1984 } else {
1985 /* EIO 5 */
1986 ret = -5;
1987 goto _fail_;
1988 }
1989 }
1990
1991 /***
1992 * mac interface init
1993 **/
1994 if (!mac_cfg.cfg_init(wilc_debug)) {
1995 /* ENOBUFS 105 */
1996 ret = -105;
1997 goto _fail_;
1998 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001999
2000 /**
2001 * alloc tx, rx buffer
2002 **/
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002003 if (g_wlan.tx_buffer == NULL)
Glen Lee7015b5d2015-09-24 18:15:02 +09002004 g_wlan.tx_buffer = kmalloc(LINUX_TX_SIZE, GFP_KERNEL);
Arnd Bergmann7a8fd842015-06-01 21:06:45 +02002005 PRINT_D(TX_DBG, "g_wlan.tx_buffer = %p\n", g_wlan.tx_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002006
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002007 if (g_wlan.tx_buffer == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002008 /* ENOBUFS 105 */
2009 ret = -105;
2010 PRINT_ER("Can't allocate Tx Buffer");
2011 goto _fail_;
2012 }
2013
2014/* rx_buffer is not used unless we activate USE_MEM STATIC which is not applicable, allocating such memory is useless*/
2015#if defined (MEMORY_STATIC)
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002016 if (g_wlan.rx_buffer == NULL)
Glen Lee03eb7262015-09-24 18:15:03 +09002017 g_wlan.rx_buffer = kmalloc(LINUX_RX_SIZE, GFP_KERNEL);
Arnd Bergmann7a8fd842015-06-01 21:06:45 +02002018 PRINT_D(TX_DBG, "g_wlan.rx_buffer =%p\n", g_wlan.rx_buffer);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002019 if (g_wlan.rx_buffer == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002020 /* ENOBUFS 105 */
2021 ret = -105;
2022 PRINT_ER("Can't allocate Rx Buffer");
2023 goto _fail_;
2024 }
2025#endif
2026
2027 /**
2028 * export functions
2029 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002030 oup->wlan_add_to_tx_que = wilc_wlan_txq_add_net_pkt;
2031 oup->wlan_handle_tx_que = wilc_wlan_handle_txq;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002032 oup->wlan_handle_rx_isr = wilc_handle_isr;
2033 oup->wlan_cleanup = wilc_wlan_cleanup;
2034 oup->wlan_cfg_set = wilc_wlan_cfg_set;
2035 oup->wlan_cfg_get = wilc_wlan_cfg_get;
2036 oup->wlan_cfg_get_value = wilc_wlan_cfg_get_val;
2037
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002038 oup->wlan_add_mgmt_to_tx_que = wilc_wlan_txq_add_mgmt_pkt;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002039
2040 if (!init_chip()) {
2041 /* EIO 5 */
2042 ret = -5;
2043 goto _fail_;
2044 }
2045#ifdef TCP_ACK_FILTER
2046 Init_TCP_tracking();
2047#endif
2048
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002049 return 1;
2050
2051_fail_:
2052
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002053 #ifdef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07002054 kfree(g_wlan.rx_buffer);
2055 g_wlan.rx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002056 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07002057 kfree(g_wlan.tx_buffer);
2058 g_wlan.tx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002059
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002060 return ret;
2061
2062}
2063
Dean Lee72ed4dc2015-06-12 14:11:44 +09002064u16 Set_machw_change_vir_if(bool bValue)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002065{
Chaehyun Limd85f5322015-06-11 14:35:54 +09002066 u16 ret;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002067 u32 reg;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002068
2069 /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
Glen Lee187f1ef2015-09-24 18:15:01 +09002070 mutex_lock(&g_linux_wlan->hif_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002071 ret = (&g_wlan)->hif_func.hif_read_reg(WILC_CHANGING_VIR_IF, &reg);
2072 if (!ret) {
2073 PRINT_ER("Error while Reading reg WILC_CHANGING_VIR_IF\n");
2074 }
2075
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05302076 if (bValue)
Chaehyun Lim50b51da2015-09-16 20:11:26 +09002077 reg |= BIT(31);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05302078 else
Chaehyun Lim50b51da2015-09-16 20:11:26 +09002079 reg &= ~BIT(31);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002080
2081 ret = (&g_wlan)->hif_func.hif_write_reg(WILC_CHANGING_VIR_IF, reg);
2082
2083 if (!ret) {
2084 PRINT_ER("Error while writing reg WILC_CHANGING_VIR_IF\n");
2085 }
Glen Lee187f1ef2015-09-24 18:15:01 +09002086 mutex_unlock(&g_linux_wlan->hif_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002087
2088 return ret;
2089}