blob: c731641653238935a1e7b8616f58e5d94a2e1d0e [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"
Tony Cho60bd1002015-10-12 16:56:04 +090011#include "wilc_wfi_netdevice.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;
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
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530144 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900145 if (tqe == p->txq_head) {
146
147 p->txq_head = tqe->next;
148 if (p->txq_head)
149 p->txq_head->prev = NULL;
150
151
152 } else if (tqe == p->txq_tail) {
153 p->txq_tail = (tqe->prev);
154 if (p->txq_tail)
155 p->txq_tail->next = NULL;
156 } else {
157 tqe->prev->next = tqe->next;
158 tqe->next->prev = tqe->prev;
159 }
160 p->txq_entries -= 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900161
162}
163
164static struct txq_entry_t *wilc_wlan_txq_remove_from_head(void)
165{
166 struct txq_entry_t *tqe;
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530167 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900168 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900169
Glen Lee85e57562015-09-24 18:14:56 +0900170 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900171 if (p->txq_head) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900172 tqe = p->txq_head;
173 p->txq_head = tqe->next;
Alison Schofield39823a52015-10-08 21:18:03 -0700174 if (p->txq_head)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900175 p->txq_head->prev = NULL;
Alison Schofield39823a52015-10-08 21:18:03 -0700176
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900177 p->txq_entries -= 1;
178
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900179
180
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900181
182 } else {
183 tqe = NULL;
184 }
Glen Lee85e57562015-09-24 18:14:56 +0900185 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900186 return tqe;
187}
188
189static void wilc_wlan_txq_add_to_tail(struct txq_entry_t *tqe)
190{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530191 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900192 unsigned long flags;
Glen Lee85e57562015-09-24 18:14:56 +0900193 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900194
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900195 if (p->txq_head == NULL) {
196 tqe->next = NULL;
197 tqe->prev = NULL;
198 p->txq_head = tqe;
199 p->txq_tail = tqe;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900200 } else {
201 tqe->next = NULL;
202 tqe->prev = p->txq_tail;
203 p->txq_tail->next = tqe;
204 p->txq_tail = tqe;
205 }
206 p->txq_entries += 1;
207 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900208
Glen Lee85e57562015-09-24 18:14:56 +0900209 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900210
211 /**
212 * wake up TX queue
213 **/
214 PRINT_D(TX_DBG, "Wake the txq_handling\n");
215
Glen Lee5cd63632015-09-24 18:14:58 +0900216 up(&g_linux_wlan->txq_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900217}
218
219static int wilc_wlan_txq_add_to_head(struct txq_entry_t *tqe)
220{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530221 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900222 unsigned long flags;
Glen Leeb002e202015-09-24 18:15:05 +0900223 if (linux_wlan_lock_timeout(&g_linux_wlan->txq_add_to_head_cs,
224 CFG_PKTS_TIMEOUT))
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900225 return -1;
226
Glen Lee85e57562015-09-24 18:14:56 +0900227 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900228
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900229 if (p->txq_head == NULL) {
230 tqe->next = NULL;
231 tqe->prev = NULL;
232 p->txq_head = tqe;
233 p->txq_tail = tqe;
234 } else {
235 tqe->next = p->txq_head;
236 tqe->prev = NULL;
237 p->txq_head->prev = tqe;
238 p->txq_head = tqe;
239 }
240 p->txq_entries += 1;
241 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900242
Glen Lee85e57562015-09-24 18:14:56 +0900243 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Glen Leed5a63a82015-09-24 18:15:00 +0900244 up(&g_linux_wlan->txq_add_to_head_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900245
246
247 /**
248 * wake up TX queue
249 **/
Glen Lee5cd63632015-09-24 18:14:58 +0900250 up(&g_linux_wlan->txq_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900251 PRINT_D(TX_DBG, "Wake up the txq_handler\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900252
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900253 return 0;
254
255}
256
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900257u32 Statisitcs_totalAcks = 0, Statisitcs_DroppedAcks = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900258
259#ifdef TCP_ACK_FILTER
260struct Ack_session_info;
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530261struct Ack_session_info {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900262 u32 Ack_seq_num;
263 u32 Bigger_Ack_num;
Chaehyun Limec53adf2015-09-15 14:06:15 +0900264 u16 src_port;
265 u16 dst_port;
266 u16 status;
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530267};
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900268
269typedef struct {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900270 u32 ack_num;
271 u32 Session_index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900272 struct txq_entry_t *txqe;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900273} Pending_Acks_info_t /*Ack_info_t*/;
274
275
276
277
278struct Ack_session_info *Free_head;
279struct Ack_session_info *Alloc_head;
280
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900281#define NOT_TCP_ACK (-1)
282
283#define MAX_TCP_SESSION 25
284#define MAX_PENDING_ACKS 256
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530285struct Ack_session_info Acks_keep_track_info[2 * MAX_TCP_SESSION];
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900286Pending_Acks_info_t Pending_Acks_info[MAX_PENDING_ACKS];
287
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900288u32 PendingAcks_arrBase;
289u32 Opened_TCP_session;
290u32 Pending_Acks;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900291
292
293
Chaehyun Limfed16f22015-09-17 16:48:43 +0900294static inline int Init_TCP_tracking(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900295{
296
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900297 return 0;
298
299}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900300static inline int add_TCP_track_session(u32 src_prt, u32 dst_prt, u32 seq)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900301{
302 Acks_keep_track_info[Opened_TCP_session].Ack_seq_num = seq;
303 Acks_keep_track_info[Opened_TCP_session].Bigger_Ack_num = 0;
304 Acks_keep_track_info[Opened_TCP_session].src_port = src_prt;
305 Acks_keep_track_info[Opened_TCP_session].dst_port = dst_prt;
306 Opened_TCP_session++;
307
308 PRINT_D(TCP_ENH, "TCP Session %d to Ack %d\n", Opened_TCP_session, seq);
309 return 0;
310}
311
Chaehyun Limfed16f22015-09-17 16:48:43 +0900312static inline int Update_TCP_track_session(u32 index, u32 Ack)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900313{
314
Alison Schofield39823a52015-10-08 21:18:03 -0700315 if (Ack > Acks_keep_track_info[index].Bigger_Ack_num)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900316 Acks_keep_track_info[index].Bigger_Ack_num = Ack;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900317 return 0;
318
319}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900320static inline int add_TCP_Pending_Ack(u32 Ack, u32 Session_index, struct txq_entry_t *txqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900321{
322 Statisitcs_totalAcks++;
323 if (Pending_Acks < MAX_PENDING_ACKS) {
324 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].ack_num = Ack;
325 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].txqe = txqe;
326 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].Session_index = Session_index;
327 txqe->tcp_PendingAck_index = PendingAcks_arrBase + Pending_Acks;
328 Pending_Acks++;
329
330 } else {
331
332 }
333 return 0;
334}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900335static inline int remove_TCP_related(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900336{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530337 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900338 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900339
Glen Lee85e57562015-09-24 18:14:56 +0900340 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900341
Glen Lee85e57562015-09-24 18:14:56 +0900342 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900343 return 0;
344}
345
Chaehyun Limfed16f22015-09-17 16:48:43 +0900346static inline int tcp_process(struct txq_entry_t *tqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900347{
348 int ret;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900349 u8 *eth_hdr_ptr;
350 u8 *buffer = tqe->buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900351 unsigned short h_proto;
352 int i;
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530353 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900354 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900355
Glen Lee85e57562015-09-24 18:14:56 +0900356 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900357
358 eth_hdr_ptr = &buffer[0];
359 h_proto = ntohs(*((unsigned short *)&eth_hdr_ptr[12]));
360 if (h_proto == 0x0800) { /* IP */
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900361 u8 *ip_hdr_ptr;
362 u8 protocol;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900363
364 ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN];
365 protocol = ip_hdr_ptr[9];
366
367
368 if (protocol == 0x06) {
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900369 u8 *tcp_hdr_ptr;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900370 u32 IHL, Total_Length, Data_offset;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900371
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900372 tcp_hdr_ptr = &ip_hdr_ptr[IP_HDR_LEN];
373 IHL = (ip_hdr_ptr[0] & 0xf) << 2;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900374 Total_Length = (((u32)ip_hdr_ptr[2]) << 8) + ((u32)ip_hdr_ptr[3]);
375 Data_offset = (((u32)tcp_hdr_ptr[12] & 0xf0) >> 2);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900376 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 +0900377 u32 seq_no, Ack_no;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900378
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900379 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 +0900380
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900381 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 +0900382
383
384 for (i = 0; i < Opened_TCP_session; i++) {
385 if (Acks_keep_track_info[i].Ack_seq_num == seq_no) {
386 Update_TCP_track_session(i, Ack_no);
387 break;
388 }
389 }
Alison Schofield39823a52015-10-08 21:18:03 -0700390 if (i == Opened_TCP_session)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900391 add_TCP_track_session(0, 0, seq_no);
Alison Schofield39823a52015-10-08 21:18:03 -0700392
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900393 add_TCP_Pending_Ack(Ack_no, i, tqe);
394
395
396 }
397
398 } else {
399 ret = 0;
400 }
401 } else {
402 ret = 0;
403 }
Glen Lee85e57562015-09-24 18:14:56 +0900404 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900405 return ret;
406}
407
408
409static int wilc_wlan_txq_filter_dup_tcp_ack(void)
410{
411
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900412 u32 i = 0;
413 u32 Dropped = 0;
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530414 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900415
Glen Lee85e57562015-09-24 18:14:56 +0900416 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, p->txq_spinlock_flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900417 for (i = PendingAcks_arrBase; i < (PendingAcks_arrBase + Pending_Acks); i++) {
418 if (Pending_Acks_info[i].ack_num < Acks_keep_track_info[Pending_Acks_info[i].Session_index].Bigger_Ack_num) {
419 struct txq_entry_t *tqe;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900420
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530421 PRINT_D(TCP_ENH, "DROP ACK: %u\n", Pending_Acks_info[i].ack_num);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900422 tqe = Pending_Acks_info[i].txqe;
423 if (tqe) {
424 wilc_wlan_txq_remove(tqe);
425 Statisitcs_DroppedAcks++;
426 tqe->status = 1; /* mark the packet send */
427 if (tqe->tx_complete_func)
428 tqe->tx_complete_func(tqe->priv, tqe->status);
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -0700429 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900430 Dropped++;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900431 }
432 }
433 }
434 Pending_Acks = 0;
435 Opened_TCP_session = 0;
436
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530437 if (PendingAcks_arrBase == 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900438 PendingAcks_arrBase = MAX_TCP_SESSION;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530439 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900440 PendingAcks_arrBase = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900441
442
Glen Lee85e57562015-09-24 18:14:56 +0900443 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock,
444 p->txq_spinlock_flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900445
446 while (Dropped > 0) {
447 /*consume the semaphore count of the removed packet*/
Glen Leeb002e202015-09-24 18:15:05 +0900448 linux_wlan_lock_timeout(&g_linux_wlan->txq_event, 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900449 Dropped--;
450 }
451
452 return 1;
453}
454#endif
455
Dean Lee72ed4dc2015-06-12 14:11:44 +0900456bool EnableTCPAckFilter = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900457
Dean Lee72ed4dc2015-06-12 14:11:44 +0900458void Enable_TCP_ACK_Filter(bool value)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900459{
460 EnableTCPAckFilter = value;
461}
462
Dean Lee72ed4dc2015-06-12 14:11:44 +0900463bool is_TCP_ACK_Filter_Enabled(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900464{
465 return EnableTCPAckFilter;
466}
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900467
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900468static int wilc_wlan_txq_add_cfg_pkt(u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900469{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530470 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900471 struct txq_entry_t *tqe;
472
473 PRINT_D(TX_DBG, "Adding config packet ...\n");
474 if (p->quit) {
475 PRINT_D(TX_DBG, "Return due to clear function\n");
Glen Lee6a3b94f2015-09-24 18:14:59 +0900476 up(&g_linux_wlan->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900477 return 0;
478 }
479
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700480 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900481 if (tqe == NULL) {
482 PRINT_ER("Failed to allocate memory\n");
483 return 0;
484 }
485
486 tqe->type = WILC_CFG_PKT;
487 tqe->buffer = buffer;
488 tqe->buffer_size = buffer_size;
489 tqe->tx_complete_func = NULL;
490 tqe->priv = NULL;
491#ifdef TCP_ACK_FILTER
492 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
493#endif
494 /**
495 * Configuration packet always at the front
496 **/
497 PRINT_D(TX_DBG, "Adding the config packet at the Queue tail\n");
498
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900499 if (wilc_wlan_txq_add_to_head(tqe))
500 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900501 return 1;
502}
503
Glen Lee8fc84a62015-10-01 16:03:35 +0900504int wilc_wlan_txq_add_net_pkt(void *priv, u8 *buffer, u32 buffer_size,
505 wilc_tx_complete_func_t func)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900506{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530507 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900508 struct txq_entry_t *tqe;
509
510 if (p->quit)
511 return 0;
512
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700513 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900514
515 if (tqe == NULL)
516 return 0;
517 tqe->type = WILC_NET_PKT;
518 tqe->buffer = buffer;
519 tqe->buffer_size = buffer_size;
520 tqe->tx_complete_func = func;
521 tqe->priv = priv;
522
523 PRINT_D(TX_DBG, "Adding mgmt packet at the Queue tail\n");
524#ifdef TCP_ACK_FILTER
525 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
Abdul Hussain5a66bf22015-06-16 09:44:06 +0000526 if (is_TCP_ACK_Filter_Enabled())
Glen Lee25a84832015-09-16 18:53:22 +0900527 tcp_process(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900528#endif
529 wilc_wlan_txq_add_to_tail(tqe);
530 /*return number of itemes in the queue*/
531 return p->txq_entries;
532}
Glen Leefcc6ef92015-09-16 18:53:21 +0900533
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900534int 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 +0900535{
536
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530537 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900538 struct txq_entry_t *tqe;
539
540 if (p->quit)
541 return 0;
542
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700543 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900544
545 if (tqe == NULL)
546 return 0;
547 tqe->type = WILC_MGMT_PKT;
548 tqe->buffer = buffer;
549 tqe->buffer_size = buffer_size;
550 tqe->tx_complete_func = func;
551 tqe->priv = priv;
552#ifdef TCP_ACK_FILTER
553 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
554#endif
555 PRINT_D(TX_DBG, "Adding Network packet at the Queue tail\n");
556 wilc_wlan_txq_add_to_tail(tqe);
557 return 1;
558}
Glen Leefcc6ef92015-09-16 18:53:21 +0900559
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900560static struct txq_entry_t *wilc_wlan_txq_get_first(void)
561{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530562 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900563 struct txq_entry_t *tqe;
564 unsigned long flags;
565
Glen Lee85e57562015-09-24 18:14:56 +0900566 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900567
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900568 tqe = p->txq_head;
569
Glen Lee85e57562015-09-24 18:14:56 +0900570 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900571
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900572
573 return tqe;
574}
575
576static struct txq_entry_t *wilc_wlan_txq_get_next(struct txq_entry_t *tqe)
577{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900578 unsigned long flags;
Glen Lee85e57562015-09-24 18:14:56 +0900579 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900580
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900581 tqe = tqe->next;
Glen Lee85e57562015-09-24 18:14:56 +0900582 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900583
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900584
585 return tqe;
586}
587
588static int wilc_wlan_rxq_add(struct rxq_entry_t *rqe)
589{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530590 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900591
592 if (p->quit)
593 return 0;
594
Glen Lee645db602015-09-24 18:14:57 +0900595 mutex_lock(&g_linux_wlan->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900596 if (p->rxq_head == NULL) {
597 PRINT_D(RX_DBG, "Add to Queue head\n");
598 rqe->next = NULL;
599 p->rxq_head = rqe;
600 p->rxq_tail = rqe;
601 } else {
602 PRINT_D(RX_DBG, "Add to Queue tail\n");
603 p->rxq_tail->next = rqe;
604 rqe->next = NULL;
605 p->rxq_tail = rqe;
606 }
607 p->rxq_entries += 1;
608 PRINT_D(RX_DBG, "Number of queue entries: %d\n", p->rxq_entries);
Glen Lee645db602015-09-24 18:14:57 +0900609 mutex_unlock(&g_linux_wlan->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900610 return p->rxq_entries;
611}
612
613static struct rxq_entry_t *wilc_wlan_rxq_remove(void)
614{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530615 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900616
617 PRINT_D(RX_DBG, "Getting rxQ element\n");
618 if (p->rxq_head) {
619 struct rxq_entry_t *rqe;
620
Glen Lee645db602015-09-24 18:14:57 +0900621 mutex_lock(&g_linux_wlan->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900622 rqe = p->rxq_head;
623 p->rxq_head = p->rxq_head->next;
624 p->rxq_entries -= 1;
625 PRINT_D(RX_DBG, "RXQ entries decreased\n");
Glen Lee645db602015-09-24 18:14:57 +0900626 mutex_unlock(&g_linux_wlan->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900627 return rqe;
628 }
629 PRINT_D(RX_DBG, "Nothing to get from Q\n");
630 return NULL;
631}
632
633
634/********************************************
635 *
636 * Power Save handle functions
637 *
638 ********************************************/
639
640
641
642#ifdef WILC_OPTIMIZE_SLEEP_INT
643
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900644static inline void chip_allow_sleep(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900645{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900646 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900647
648 /* Clear bit 1 */
649 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
650
Anish Bhattffda2032015-09-29 12:15:49 -0700651 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900652}
653
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900654static inline void chip_wakeup(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900655{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900656 u32 reg, clk_status_reg, trials = 0;
657 u32 sleep_time;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900658
659 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
660 do {
661 g_wlan.hif_func.hif_read_reg(1, &reg);
662 /* Set bit 1 */
Anish Bhattffda2032015-09-29 12:15:49 -0700663 g_wlan.hif_func.hif_write_reg(1, reg | BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900664
665 /* Clear 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 do {
669 /* Wait for the chip to stabilize*/
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -0700670 usleep_range(2 * 1000, 2 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900671 /* Make sure chip is awake. This is an extra step that can be removed */
672 /* later to avoid the bus access overhead */
Alison Schofield39823a52015-10-08 21:18:03 -0700673 if ((wilc_get_chipid(true) == 0))
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900674 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
Alison Schofield39823a52015-10-08 21:18:03 -0700675
Dean Lee72ed4dc2015-06-12 14:11:44 +0900676 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900677
Dean Lee72ed4dc2015-06-12 14:11:44 +0900678 } while (wilc_get_chipid(true) == 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900679 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
680 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
681 do {
682 /* Set bit 1 */
Anish Bhattffda2032015-09-29 12:15:49 -0700683 g_wlan.hif_func.hif_write_reg(0xf0, reg | BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900684
685 /* Check the clock status */
686 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
687
688 /* in case of clocks off, wait 2ms, and check it again. */
689 /* if still off, wait for another 2ms, for a total wait of 6ms. */
690 /* If still off, redo the wake up sequence */
691 while (((clk_status_reg & 0x1) == 0) && (((++trials) % 3) == 0)) {
692 /* Wait for the chip to stabilize*/
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -0700693 usleep_range(2 * 1000, 2 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900694
695 /* Make sure chip is awake. This is an extra step that can be removed */
696 /* later to avoid the bus access overhead */
697 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
698
Alison Schofield39823a52015-10-08 21:18:03 -0700699 if ((clk_status_reg & 0x1) == 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900700 wilc_debug(N_ERR, "clocks still OFF. Wake up failed\n");
Alison Schofield39823a52015-10-08 21:18:03 -0700701
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900702 }
703 /* in case of failure, Reset the wakeup bit to introduce a new edge on the next loop */
704 if ((clk_status_reg & 0x1) == 0) {
705 /* Reset bit 0 */
Anish Bhattffda2032015-09-29 12:15:49 -0700706 g_wlan.hif_func.hif_write_reg(0xf0, reg &
707 (~BIT(0)));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900708 }
709 } while ((clk_status_reg & 0x1) == 0);
710 }
711
712
713 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
714 g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -0700715 reg &= ~BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900716 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
717
Dean Lee72ed4dc2015-06-12 14:11:44 +0900718 if (wilc_get_chipid(false) >= 0x1002b0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900719 /* Enable PALDO back right after wakeup */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900720 u32 val32;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900721
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900722 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700723 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900724 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
725
726 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700727 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900728 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
729 }
730 }
731 genuChipPSstate = CHIP_WAKEDUP;
732}
733#else
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900734static inline void chip_wakeup(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900735{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900736 u32 reg, trials = 0;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900737
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900738 do {
739 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
740 g_wlan.hif_func.hif_read_reg(1, &reg);
741 /* Make sure bit 1 is 0 before we start. */
Anish Bhattffda2032015-09-29 12:15:49 -0700742 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900743 /* Set bit 1 */
Anish Bhattffda2032015-09-29 12:15:49 -0700744 g_wlan.hif_func.hif_write_reg(1, reg | BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900745 /* Clear bit 1*/
Anish Bhattffda2032015-09-29 12:15:49 -0700746 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900747 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
748 /* Make sure bit 0 is 0 before we start. */
749 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -0700750 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900751 /* Set bit 1 */
Anish Bhattffda2032015-09-29 12:15:49 -0700752 g_wlan.hif_func.hif_write_reg(0xf0, reg | BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900753 /* Clear bit 1 */
Anish Bhattffda2032015-09-29 12:15:49 -0700754 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900755 }
756
757 do {
758 /* Wait for the chip to stabilize*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900759 mdelay(3);
760
761 /* Make sure chip is awake. This is an extra step that can be removed */
762 /* later to avoid the bus access overhead */
Alison Schofield39823a52015-10-08 21:18:03 -0700763 if ((wilc_get_chipid(true) == 0))
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900764 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
Alison Schofield39823a52015-10-08 21:18:03 -0700765
Dean Lee72ed4dc2015-06-12 14:11:44 +0900766 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900767
Dean Lee72ed4dc2015-06-12 14:11:44 +0900768 } while (wilc_get_chipid(true) == 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900769
770 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
771 g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -0700772 reg &= ~BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900773 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
774
Dean Lee72ed4dc2015-06-12 14:11:44 +0900775 if (wilc_get_chipid(false) >= 0x1002b0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900776 /* Enable PALDO back right after wakeup */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900777 u32 val32;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900778
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900779 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700780 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900781 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
782
783 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700784 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900785 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
786 }
787 }
788 genuChipPSstate = CHIP_WAKEDUP;
789}
790#endif
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900791void chip_sleep_manually(u32 u32SleepTime)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900792{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900793 if (genuChipPSstate != CHIP_WAKEDUP) {
794 /* chip is already sleeping. Do nothing */
795 return;
796 }
797 acquire_bus(ACQUIRE_ONLY);
798
799#ifdef WILC_OPTIMIZE_SLEEP_INT
800 chip_allow_sleep();
801#endif
802
803 /* Trigger the manual sleep interrupt */
804 g_wlan.hif_func.hif_write_reg(0x10a8, 1);
805
806 genuChipPSstate = CHIP_SLEEPING_MANUAL;
807 release_bus(RELEASE_ONLY);
808
809}
810
811
812/********************************************
813 *
814 * Tx, Rx queue handle functions
815 *
816 ********************************************/
Glen Leef590c4c2015-10-01 16:03:36 +0900817int wilc_wlan_handle_txq(u32 *pu32TxqCount)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900818{
819 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
820 int i, entries = 0;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900821 u32 sum;
822 u32 reg;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900823 u8 *txb = p->tx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900824 u32 offset = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900825 int vmm_sz = 0;
826 struct txq_entry_t *tqe;
827 int ret = 0;
828 int counter;
829 int timeout;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900830 u32 vmm_table[WILC_VMM_TBL_SIZE];
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900831
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900832 p->txq_exit = 0;
833 do {
834 if (p->quit)
835 break;
836
Glen Leeb002e202015-09-24 18:15:05 +0900837 linux_wlan_lock_timeout(&g_linux_wlan->txq_add_to_head_cs,
838 CFG_PKTS_TIMEOUT);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900839#ifdef TCP_ACK_FILTER
840 wilc_wlan_txq_filter_dup_tcp_ack();
841#endif
842 /**
843 * build the vmm list
844 **/
845 PRINT_D(TX_DBG, "Getting the head of the TxQ\n");
846 tqe = wilc_wlan_txq_get_first();
847 i = 0;
848 sum = 0;
849 do {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900850 if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE - 1)) /* reserve last entry to 0 */) {
851
Alison Schofield39823a52015-10-08 21:18:03 -0700852 if (tqe->type == WILC_CFG_PKT)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900853 vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET;
Alison Schofield39823a52015-10-08 21:18:03 -0700854
855 else if (tqe->type == WILC_NET_PKT)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900856 vmm_sz = ETH_ETHERNET_HDR_OFFSET;
Alison Schofield39823a52015-10-08 21:18:03 -0700857
858 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900859 vmm_sz = HOST_HDR_OFFSET;
Alison Schofield39823a52015-10-08 21:18:03 -0700860
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900861 vmm_sz += tqe->buffer_size;
862 PRINT_D(TX_DBG, "VMM Size before alignment = %d\n", vmm_sz);
863 if (vmm_sz & 0x3) { /* has to be word aligned */
864 vmm_sz = (vmm_sz + 4) & ~0x3;
865 }
Alison Schofield39823a52015-10-08 21:18:03 -0700866 if ((sum + vmm_sz) > LINUX_TX_SIZE)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900867 break;
Alison Schofield39823a52015-10-08 21:18:03 -0700868
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900869 PRINT_D(TX_DBG, "VMM Size AFTER alignment = %d\n", vmm_sz);
870 vmm_table[i] = vmm_sz / 4; /* table take the word size */
871 PRINT_D(TX_DBG, "VMMTable entry size = %d\n", vmm_table[i]);
872
873 if (tqe->type == WILC_CFG_PKT) {
Anish Bhattffda2032015-09-29 12:15:49 -0700874 vmm_table[i] |= BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900875 PRINT_D(TX_DBG, "VMMTable entry changed for CFG packet = %d\n", vmm_table[i]);
876 }
877#ifdef BIG_ENDIAN
878 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
879#endif
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900880
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900881 i++;
882 sum += vmm_sz;
883 PRINT_D(TX_DBG, "sum = %d\n", sum);
884 tqe = wilc_wlan_txq_get_next(tqe);
885 } else {
886 break;
887 }
888 } while (1);
889
890 if (i == 0) { /* nothing in the queue */
891 PRINT_D(TX_DBG, "Nothing in TX-Q\n");
892 break;
893 } else {
894 PRINT_D(TX_DBG, "Mark the last entry in VMM table - number of previous entries = %d\n", i);
895 vmm_table[i] = 0x0; /* mark the last element to 0 */
896 }
897 acquire_bus(ACQUIRE_AND_WAKEUP);
898 counter = 0;
899 do {
900
901 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg);
902 if (!ret) {
903 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg vmm_tbl_entry..\n");
904 break;
905 }
906
907 if ((reg & 0x1) == 0) {
908 /**
909 * write to vmm table
910 **/
911 PRINT_D(TX_DBG, "Writing VMM table ... with Size = %d\n", ((i + 1) * 4));
912 break;
913 } else {
914 counter++;
915 if (counter > 200) {
916 counter = 0;
917 PRINT_D(TX_DBG, "Looping in tx ctrl , forcce quit\n");
918 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, 0);
919 break;
920 }
921 /**
922 * wait for vmm table is ready
923 **/
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530924 PRINT_WRN(GENERIC_DBG, "[wilc txq]: warn, vmm table not clear yet, wait...\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900925 release_bus(RELEASE_ALLOW_SLEEP);
Greg Kroah-Hartman2b922cb2015-09-04 09:30:51 -0700926 usleep_range(3000, 3000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900927 acquire_bus(ACQUIRE_AND_WAKEUP);
928 }
929 } while (!p->quit);
930
Alison Schofield39823a52015-10-08 21:18:03 -0700931 if (!ret)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900932 goto _end_;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900933
934 timeout = 200;
935 do {
936
937 /**
938 * write to vmm table
939 **/
Chaehyun Limc3ca6372015-09-20 15:51:19 +0900940 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 +0900941 if (!ret) {
942 wilc_debug(N_ERR, "ERR block TX of VMM table.\n");
943 break;
944 }
945
946
947 /**
948 * interrupt firmware
949 **/
950 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x2);
951 if (!ret) {
952 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg host_vmm_ctl..\n");
953 break;
954 }
955
956 /**
957 * wait for confirm...
958 **/
959
960 do {
961 ret = p->hif_func.hif_read_reg(WILC_HOST_VMM_CTL, &reg);
962 if (!ret) {
963 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg host_vmm_ctl..\n");
964 break;
965 }
966 if ((reg >> 2) & 0x1) {
967 /**
968 * Get the entries
969 **/
970 entries = ((reg >> 3) & 0x3f);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900971 break;
972 } else {
973 release_bus(RELEASE_ALLOW_SLEEP);
Greg Kroah-Hartman2b922cb2015-09-04 09:30:51 -0700974 usleep_range(3000, 3000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900975 acquire_bus(ACQUIRE_AND_WAKEUP);
976 PRINT_WRN(GENERIC_DBG, "Can't get VMM entery - reg = %2x\n", reg);
977 }
978 } while (--timeout);
979 if (timeout <= 0) {
980 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x0);
981 break;
982 }
983
Alison Schofield39823a52015-10-08 21:18:03 -0700984 if (!ret)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900985 break;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900986
987 if (entries == 0) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530988 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 +0900989
990 /* undo the transaction. */
991 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg);
992 if (!ret) {
993 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg WILC_HOST_TX_CTRL..\n");
994 break;
995 }
Anish Bhattffda2032015-09-29 12:15:49 -0700996 reg &= ~BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900997 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, reg);
998 if (!ret) {
999 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg WILC_HOST_TX_CTRL..\n");
1000 break;
1001 }
1002 break;
1003 } else {
1004 break;
1005 }
1006 } while (1);
1007
Alison Schofield39823a52015-10-08 21:18:03 -07001008 if (!ret)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001009 goto _end_;
Alison Schofield39823a52015-10-08 21:18:03 -07001010
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001011 if (entries == 0) {
1012 ret = WILC_TX_ERR_NO_BUF;
1013 goto _end_;
1014 }
1015
1016 /* since copying data into txb takes some time, then
1017 * allow the bus lock to be released let the RX task go. */
1018 release_bus(RELEASE_ALLOW_SLEEP);
1019
1020 /**
1021 * Copy data to the TX buffer
1022 **/
1023 offset = 0;
1024 i = 0;
1025 do {
1026 tqe = wilc_wlan_txq_remove_from_head();
1027 if (tqe != NULL && (vmm_table[i] != 0)) {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001028 u32 header, buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001029
1030#ifdef BIG_ENDIAN
1031 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
1032#endif
1033 vmm_sz = (vmm_table[i] & 0x3ff); /* in word unit */
1034 vmm_sz *= 4;
1035 header = (tqe->type << 31) | (tqe->buffer_size << 15) | vmm_sz;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301036 if (tqe->type == WILC_MGMT_PKT)
Anish Bhattffda2032015-09-29 12:15:49 -07001037 header |= BIT(30);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301038 else
Anish Bhattffda2032015-09-29 12:15:49 -07001039 header &= ~BIT(30);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001040
1041#ifdef BIG_ENDIAN
1042 header = BYTE_SWAP(header);
1043#endif
1044 memcpy(&txb[offset], &header, 4);
1045 if (tqe->type == WILC_CFG_PKT) {
1046 buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET;
1047 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001048 else if (tqe->type == WILC_NET_PKT) {
1049 char *pBSSID = ((struct tx_complete_data *)(tqe->priv))->pBssid;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001050
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001051 buffer_offset = ETH_ETHERNET_HDR_OFFSET;
1052 /* copy the bssid at the sart of the buffer */
1053 memcpy(&txb[offset + 4], pBSSID, 6);
1054 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001055 else {
1056 buffer_offset = HOST_HDR_OFFSET;
1057 }
1058
1059 memcpy(&txb[offset + buffer_offset], tqe->buffer, tqe->buffer_size);
1060 offset += vmm_sz;
1061 i++;
1062 tqe->status = 1; /* mark the packet send */
1063 if (tqe->tx_complete_func)
1064 tqe->tx_complete_func(tqe->priv, tqe->status);
1065 #ifdef TCP_ACK_FILTER
Alison Schofield39823a52015-10-08 21:18:03 -07001066 if (tqe->tcp_PendingAck_index != NOT_TCP_ACK)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001067 Pending_Acks_info[tqe->tcp_PendingAck_index].txqe = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001068 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001069 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001070 } else {
1071 break;
1072 }
1073 } while (--entries);
1074
1075 /**
1076 * lock the bus
1077 **/
1078 acquire_bus(ACQUIRE_AND_WAKEUP);
1079
1080 ret = p->hif_func.hif_clear_int_ext(ENABLE_TX_VMM);
1081 if (!ret) {
1082 wilc_debug(N_ERR, "[wilc txq]: fail can't start tx VMM ...\n");
1083 goto _end_;
1084 }
1085
1086 /**
1087 * transfer
1088 **/
1089 ret = p->hif_func.hif_block_tx_ext(0, txb, offset);
1090 if (!ret) {
1091 wilc_debug(N_ERR, "[wilc txq]: fail can't block tx ext...\n");
1092 goto _end_;
1093 }
1094
1095_end_:
1096
1097 release_bus(RELEASE_ALLOW_SLEEP);
1098 if (ret != 1)
1099 break;
1100 } while (0);
Glen Leed5a63a82015-09-24 18:15:00 +09001101 up(&g_linux_wlan->txq_add_to_head_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001102
1103 p->txq_exit = 1;
1104 PRINT_D(TX_DBG, "THREAD: Exiting txq\n");
1105 /* return tx[]q count */
1106 *pu32TxqCount = p->txq_entries;
1107 return ret;
1108}
1109
1110static void wilc_wlan_handle_rxq(void)
1111{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301112 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001113 int offset = 0, size, has_packet = 0;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001114 u8 *buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001115 struct rxq_entry_t *rqe;
1116
1117 p->rxq_exit = 0;
1118
1119
1120
1121
1122 do {
1123 if (p->quit) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301124 PRINT_D(RX_DBG, "exit 1st do-while due to Clean_UP function\n");
Glen Lee6a3b94f2015-09-24 18:14:59 +09001125 up(&g_linux_wlan->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001126 break;
1127 }
1128 rqe = wilc_wlan_rxq_remove();
1129 if (rqe == NULL) {
1130 PRINT_D(RX_DBG, "nothing in the queue - exit 1st do-while\n");
1131 break;
1132 }
1133 buffer = rqe->buffer;
1134 size = rqe->buffer_size;
1135 PRINT_D(RX_DBG, "rxQ entery Size = %d - Address = %p\n", size, buffer);
1136 offset = 0;
1137
1138
1139
1140 do {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001141 u32 header;
1142 u32 pkt_len, pkt_offset, tp_len;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001143 int is_cfg_packet;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001144
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001145 PRINT_D(RX_DBG, "In the 2nd do-while\n");
1146 memcpy(&header, &buffer[offset], 4);
1147#ifdef BIG_ENDIAN
1148 header = BYTE_SWAP(header);
1149#endif
1150 PRINT_D(RX_DBG, "Header = %04x - Offset = %d\n", header, offset);
1151
1152
1153
1154 is_cfg_packet = (header >> 31) & 0x1;
1155 pkt_offset = (header >> 22) & 0x1ff;
1156 tp_len = (header >> 11) & 0x7ff;
1157 pkt_len = header & 0x7ff;
1158
1159 if (pkt_len == 0 || tp_len == 0) {
1160 wilc_debug(N_RXQ, "[wilc rxq]: data corrupt, packet len or tp_len is 0 [%d][%d]\n", pkt_len, tp_len);
1161 break;
1162 }
1163
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001164 #define IS_MANAGMEMENT 0x100
1165 #define IS_MANAGMEMENT_CALLBACK 0x080
1166 #define IS_MGMT_STATUS_SUCCES 0x040
1167
1168
1169 if (pkt_offset & IS_MANAGMEMENT) {
1170 /* reset mgmt indicator bit, to use pkt_offeset in furthur calculations */
1171 pkt_offset &= ~(IS_MANAGMEMENT | IS_MANAGMEMENT_CALLBACK | IS_MGMT_STATUS_SUCCES);
1172
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001173 WILC_WFI_mgmt_rx(&buffer[offset + HOST_HDR_OFFSET], pkt_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001174 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001175 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001176 {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001177
1178 if (!is_cfg_packet) {
Glen Lee63611672015-09-24 18:14:52 +09001179 if (pkt_len > 0) {
1180 frmw_to_linux(&buffer[offset],
1181 pkt_len,
1182 pkt_offset);
1183 has_packet = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001184 }
1185 } else {
1186 wilc_cfg_rsp_t rsp;
1187
1188
1189
Glen Lee30f535a2015-10-02 14:22:10 +09001190 wilc_wlan_cfg_indicate_rx(&buffer[pkt_offset + offset], pkt_len, &rsp);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001191 if (rsp.type == WILC_CFG_RSP) {
1192 /**
1193 * wake up the waiting task...
1194 **/
1195 PRINT_D(RX_DBG, "p->cfg_seq_no = %d - rsp.seq_no = %d\n", p->cfg_seq_no, rsp.seq_no);
Alison Schofield39823a52015-10-08 21:18:03 -07001196 if (p->cfg_seq_no == rsp.seq_no)
Glen Lee6a3b94f2015-09-24 18:14:59 +09001197 up(&g_linux_wlan->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001198 } else if (rsp.type == WILC_CFG_RSP_STATUS) {
1199 /**
1200 * Call back to indicate status...
1201 **/
Glen Lee4417d3d2015-09-24 18:14:53 +09001202 linux_wlan_mac_indicate(WILC_MAC_INDICATE_STATUS);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001203
1204 } else if (rsp.type == WILC_CFG_RSP_SCAN) {
Glen Lee4417d3d2015-09-24 18:14:53 +09001205 linux_wlan_mac_indicate(WILC_MAC_INDICATE_SCAN);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001206 }
1207 }
1208 }
1209 offset += tp_len;
1210 if (offset >= size)
1211 break;
1212 } while (1);
1213
1214
1215#ifndef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001216 kfree(buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001217#endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001218 kfree(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001219
Alison Schofield39823a52015-10-08 21:18:03 -07001220 if (has_packet)
Glen Leec0cadaa2015-09-24 18:14:54 +09001221 linux_wlan_rx_complete();
Alison Schofield39823a52015-10-08 21:18:03 -07001222
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001223 } while (1);
1224
1225 p->rxq_exit = 1;
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301226 PRINT_D(RX_DBG, "THREAD: Exiting RX thread\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001227}
1228
1229/********************************************
1230 *
1231 * Fast DMA Isr
1232 *
1233 ********************************************/
1234static void wilc_unknown_isr_ext(void)
1235{
1236 g_wlan.hif_func.hif_clear_int_ext(0);
1237}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001238static void wilc_pllupdate_isr_ext(u32 int_stats)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001239{
1240
1241 int trials = 10;
1242
1243 g_wlan.hif_func.hif_clear_int_ext(PLL_INT_CLR);
1244
1245 /* Waiting for PLL */
Greg Kroah-Hartmanc2e4c0f2015-09-03 19:09:50 -07001246 mdelay(WILC_PLL_TO);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001247
1248 /* poll till read a valid data */
Dean Lee72ed4dc2015-06-12 14:11:44 +09001249 while (!(ISWILC1000(wilc_get_chipid(true)) && --trials)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001250 PRINT_D(TX_DBG, "PLL update retrying\n");
Greg Kroah-Hartmanc2e4c0f2015-09-03 19:09:50 -07001251 mdelay(1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001252 }
1253}
1254
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001255static void wilc_sleeptimer_isr_ext(u32 int_stats1)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001256{
1257 g_wlan.hif_func.hif_clear_int_ext(SLEEP_INT_CLR);
1258#ifndef WILC_OPTIMIZE_SLEEP_INT
1259 genuChipPSstate = CHIP_SLEEPING_AUTO;
1260#endif
1261}
1262
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001263static void wilc_wlan_handle_isr_ext(u32 int_status)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001264{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301265 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001266#ifdef MEMORY_STATIC
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001267 u32 offset = p->rx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001268#endif
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001269 u8 *buffer = NULL;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001270 u32 size;
1271 u32 retries = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001272 int ret = 0;
1273 struct rxq_entry_t *rqe;
1274
1275
1276 /**
1277 * Get the rx size
1278 **/
1279
1280 size = ((int_status & 0x7fff) << 2);
1281
1282 while (!size && retries < 10) {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001283 u32 time = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001284 /*looping more secure*/
1285 /*zero size make a crashe because the dma will not happen and that will block the firmware*/
1286 wilc_debug(N_ERR, "RX Size equal zero ... Trying to read it again for %d time\n", time++);
1287 p->hif_func.hif_read_size(&size);
1288 size = ((size & 0x7fff) << 2);
1289 retries++;
1290
1291 }
1292
1293 if (size > 0) {
1294#ifdef MEMORY_STATIC
Glen Lee03eb7262015-09-24 18:15:03 +09001295 if (LINUX_RX_SIZE - offset < size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001296 offset = 0;
1297
1298 if (p->rx_buffer)
1299 buffer = &p->rx_buffer[offset];
1300 else {
1301 wilc_debug(N_ERR, "[wilc isr]: fail Rx Buffer is NULL...drop the packets (%d)\n", size);
1302 goto _end_;
1303 }
1304
1305#else
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001306 buffer = kmalloc(size, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001307 if (buffer == NULL) {
1308 wilc_debug(N_ERR, "[wilc isr]: fail alloc host memory...drop the packets (%d)\n", size);
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -07001309 usleep_range(100 * 1000, 100 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001310 goto _end_;
1311 }
1312#endif
1313
1314 /**
1315 * clear the chip's interrupt after getting size some register getting corrupted after clear the interrupt
1316 **/
1317 p->hif_func.hif_clear_int_ext(DATA_INT_CLR | ENABLE_RX_VMM);
1318
1319
1320 /**
1321 * start transfer
1322 **/
1323 ret = p->hif_func.hif_block_rx_ext(0, buffer, size);
1324
1325 if (!ret) {
1326 wilc_debug(N_ERR, "[wilc isr]: fail block rx...\n");
1327 goto _end_;
1328 }
1329_end_:
1330
1331
1332 if (ret) {
1333#ifdef MEMORY_STATIC
1334 offset += size;
1335 p->rx_buffer_offset = offset;
1336#endif
1337 /**
1338 * add to rx queue
1339 **/
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001340 rqe = kmalloc(sizeof(struct rxq_entry_t), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001341 if (rqe != NULL) {
1342 rqe->buffer = buffer;
1343 rqe->buffer_size = size;
1344 PRINT_D(RX_DBG, "rxq entery Size= %d - Address = %p\n", rqe->buffer_size, rqe->buffer);
1345 wilc_wlan_rxq_add(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001346 }
1347 } else {
1348#ifndef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001349 kfree(buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001350#endif
1351 }
1352 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001353 wilc_wlan_handle_rxq();
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001354}
1355
1356void wilc_handle_isr(void)
1357{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001358 u32 int_status;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001359
1360 acquire_bus(ACQUIRE_AND_WAKEUP);
1361 g_wlan.hif_func.hif_read_int(&int_status);
1362
Alison Schofield39823a52015-10-08 21:18:03 -07001363 if (int_status & PLL_INT_EXT)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001364 wilc_pllupdate_isr_ext(int_status);
Alison Schofield39823a52015-10-08 21:18:03 -07001365
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001366 if (int_status & DATA_INT_EXT) {
1367 wilc_wlan_handle_isr_ext(int_status);
1368 #ifndef WILC_OPTIMIZE_SLEEP_INT
1369 /* Chip is up and talking*/
1370 genuChipPSstate = CHIP_WAKEDUP;
1371 #endif
1372 }
Alison Schofield39823a52015-10-08 21:18:03 -07001373 if (int_status & SLEEP_INT_EXT)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001374 wilc_sleeptimer_isr_ext(int_status);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001375
1376 if (!(int_status & (ALL_INT_EXT))) {
1377#ifdef WILC_SDIO
1378 PRINT_D(TX_DBG, ">> UNKNOWN_INTERRUPT - 0x%08x\n", int_status);
1379#endif
1380 wilc_unknown_isr_ext();
1381 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001382 release_bus(RELEASE_ALLOW_SLEEP);
1383}
1384
1385/********************************************
1386 *
1387 * Firmware download
1388 *
1389 ********************************************/
Glen Lee63d7ab82015-10-01 16:03:32 +09001390int wilc_wlan_firmware_download(const u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001391{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301392 wilc_wlan_dev_t *p = &g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001393 u32 offset;
1394 u32 addr, size, size2, blksz;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001395 u8 *dma_buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001396 int ret = 0;
1397
Anish Bhattffda2032015-09-29 12:15:49 -07001398 blksz = BIT(12);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001399 /* Allocate a DMA coherent buffer. */
1400
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001401 dma_buffer = kmalloc(blksz, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001402 if (dma_buffer == NULL) {
1403 /*EIO 5*/
1404 ret = -5;
1405 PRINT_ER("Can't allocate buffer for firmware download IO error\n ");
1406 goto _fail_1;
1407 }
1408
1409 PRINT_D(INIT_DBG, "Downloading firmware size = %d ...\n", buffer_size);
1410 /**
1411 * load the firmware
1412 **/
1413 offset = 0;
1414 do {
1415 memcpy(&addr, &buffer[offset], 4);
1416 memcpy(&size, &buffer[offset + 4], 4);
1417#ifdef BIG_ENDIAN
1418 addr = BYTE_SWAP(addr);
1419 size = BYTE_SWAP(size);
1420#endif
1421 acquire_bus(ACQUIRE_ONLY);
1422 offset += 8;
1423 while (((int)size) && (offset < buffer_size)) {
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301424 if (size <= blksz)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001425 size2 = size;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301426 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001427 size2 = blksz;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001428 /* Copy firmware into a DMA coherent buffer */
1429 memcpy(dma_buffer, &buffer[offset], size2);
1430 ret = p->hif_func.hif_block_tx(addr, dma_buffer, size2);
1431 if (!ret)
1432 break;
1433
1434 addr += size2;
1435 offset += size2;
1436 size -= size2;
1437 }
1438 release_bus(RELEASE_ONLY);
1439
1440 if (!ret) {
1441 /*EIO 5*/
1442 ret = -5;
1443 PRINT_ER("Can't download firmware IO error\n ");
1444 goto _fail_;
1445 }
1446 PRINT_D(INIT_DBG, "Offset = %d\n", offset);
1447 } while (offset < buffer_size);
1448
1449_fail_:
1450
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001451 kfree(dma_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001452
1453_fail_1:
1454
1455 return (ret < 0) ? ret : 0;
1456}
1457
1458/********************************************
1459 *
1460 * Common
1461 *
1462 ********************************************/
Glen Leee42563b2015-10-01 16:03:33 +09001463int wilc_wlan_start(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001464{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301465 wilc_wlan_dev_t *p = &g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001466 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001467 int ret;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001468 u32 chipid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001469
1470 /**
1471 * Set the host interface
1472 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001473 if (p->io_func.io_type == HIF_SDIO) {
1474 reg = 0;
Anish Bhattffda2032015-09-29 12:15:49 -07001475 reg |= BIT(3); /* bug 4456 and 4557 */
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001476 } else if (p->io_func.io_type == HIF_SPI) {
1477 reg = 1;
1478 }
1479 acquire_bus(ACQUIRE_ONLY);
1480 ret = p->hif_func.hif_write_reg(WILC_VMM_CORE_CFG, reg);
1481 if (!ret) {
1482 wilc_debug(N_ERR, "[wilc start]: fail write reg vmm_core_cfg...\n");
1483 release_bus(RELEASE_ONLY);
1484 /* EIO 5*/
1485 ret = -5;
1486 return ret;
1487 }
1488 reg = 0;
1489#ifdef WILC_SDIO_IRQ_GPIO
1490 reg |= WILC_HAVE_SDIO_IRQ_GPIO;
1491#endif
1492
1493#ifdef WILC_DISABLE_PMU
1494#else
1495 reg |= WILC_HAVE_USE_PMU;
1496#endif
1497
1498#ifdef WILC_SLEEP_CLK_SRC_XO
1499 reg |= WILC_HAVE_SLEEP_CLK_SRC_XO;
1500#elif defined WILC_SLEEP_CLK_SRC_RTC
1501 reg |= WILC_HAVE_SLEEP_CLK_SRC_RTC;
1502#endif
1503
1504#ifdef WILC_EXT_PA_INV_TX_RX
1505 reg |= WILC_HAVE_EXT_PA_INV_TX_RX;
1506#endif
1507
1508 reg |= WILC_HAVE_LEGACY_RF_SETTINGS;
1509
1510
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001511/*Set oscillator frequency*/
1512#ifdef XTAL_24
1513 reg |= WILC_HAVE_XTAL_24;
1514#endif
1515
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001516/*Enable/Disable GPIO configuration for FW logs*/
1517#ifdef DISABLE_WILC_UART
1518 reg |= WILC_HAVE_DISABLE_WILC_UART;
1519#endif
1520
1521 ret = p->hif_func.hif_write_reg(WILC_GP_REG_1, reg);
1522 if (!ret) {
1523 wilc_debug(N_ERR, "[wilc start]: fail write WILC_GP_REG_1 ...\n");
1524 release_bus(RELEASE_ONLY);
1525 /* EIO 5*/
1526 ret = -5;
1527 return ret;
1528 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001529
1530 /**
1531 * Bus related
1532 **/
1533 p->hif_func.hif_sync_ext(NUM_INT_EXT);
1534
1535 ret = p->hif_func.hif_read_reg(0x1000, &chipid);
1536 if (!ret) {
1537 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1000 ...\n");
1538 release_bus(RELEASE_ONLY);
1539 /* EIO 5*/
1540 ret = -5;
1541 return ret;
1542 }
1543
1544 /**
1545 * Go...
1546 **/
1547
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001548
1549 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -07001550 if ((reg & BIT(10)) == BIT(10)) {
1551 reg &= ~BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001552 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1553 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1554 }
1555
Anish Bhattffda2032015-09-29 12:15:49 -07001556 reg |= BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001557 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1558 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1559 release_bus(RELEASE_ONLY);
1560
1561 return (ret < 0) ? ret : 0;
1562}
1563
1564void wilc_wlan_global_reset(void)
1565{
1566
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301567 wilc_wlan_dev_t *p = &g_wlan;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001568
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001569 acquire_bus(ACQUIRE_AND_WAKEUP);
1570 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, 0x0);
1571 release_bus(RELEASE_ONLY);
1572}
Glen Lee8cec7412015-10-01 16:03:34 +09001573int wilc_wlan_stop(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001574{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301575 wilc_wlan_dev_t *p = &g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001576 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001577 int ret;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001578 u8 timeout = 10;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001579 /**
1580 * TODO: stop the firmware, need a re-download
1581 **/
1582 acquire_bus(ACQUIRE_AND_WAKEUP);
1583
1584 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1585 if (!ret) {
1586 PRINT_ER("Error while reading reg\n");
1587 release_bus(RELEASE_ALLOW_SLEEP);
1588 return ret;
1589 }
1590
Anish Bhattffda2032015-09-29 12:15:49 -07001591 reg &= ~BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001592
1593
1594 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1595 if (!ret) {
1596 PRINT_ER("Error while writing reg\n");
1597 release_bus(RELEASE_ALLOW_SLEEP);
1598 return ret;
1599 }
1600
1601
1602
1603 do {
1604 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1605 if (!ret) {
1606 PRINT_ER("Error while reading reg\n");
1607 release_bus(RELEASE_ALLOW_SLEEP);
1608 return ret;
1609 }
1610 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1611 /*Workaround to ensure that the chip is actually reset*/
Anish Bhattffda2032015-09-29 12:15:49 -07001612 if ((reg & BIT(10))) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001613 PRINT_D(GENERIC_DBG, "Bit 10 not reset : Retry %d\n", timeout);
Anish Bhattffda2032015-09-29 12:15:49 -07001614 reg &= ~BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001615 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1616 timeout--;
1617 } else {
1618 PRINT_D(GENERIC_DBG, "Bit 10 reset after : Retry %d\n", timeout);
1619 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1620 if (!ret) {
1621 PRINT_ER("Error while reading reg\n");
1622 release_bus(RELEASE_ALLOW_SLEEP);
1623 return ret;
1624 }
1625 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1626 break;
1627 }
1628
1629 } while (timeout);
Anish Bhattffda2032015-09-29 12:15:49 -07001630 reg = (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(8) | BIT(9) | BIT(26) |
1631 BIT(29) | BIT(30) | BIT(31));
Anish Bhatt65ead4e2015-09-29 12:15:48 -07001632
1633 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
Anish Bhattffda2032015-09-29 12:15:49 -07001634 reg = (u32)~BIT(10);
Anish Bhatt65ead4e2015-09-29 12:15:48 -07001635
1636 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001637
1638 release_bus(RELEASE_ALLOW_SLEEP);
1639
1640 return ret;
1641}
1642
Glen Leea17e2ec2015-10-01 16:03:38 +09001643void wilc_wlan_cleanup(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001644{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301645 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001646 struct txq_entry_t *tqe;
1647 struct rxq_entry_t *rqe;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001648 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001649 int ret;
1650
1651 p->quit = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001652 do {
1653 tqe = wilc_wlan_txq_remove_from_head();
1654 if (tqe == NULL)
1655 break;
1656 if (tqe->tx_complete_func)
1657 tqe->tx_complete_func(tqe->priv, 0);
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001658 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001659 } while (1);
1660
1661 do {
1662 rqe = wilc_wlan_rxq_remove();
1663 if (rqe == NULL)
1664 break;
Javier Martinez Canillas6a272242015-09-22 15:24:50 +02001665#ifndef MEMORY_STATIC
1666 kfree(rqe->buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001667#endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001668 kfree(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001669 } while (1);
1670
1671 /**
1672 * clean up buffer
1673 **/
1674
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001675 #ifdef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001676 kfree(p->rx_buffer);
1677 p->rx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001678 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001679 kfree(p->tx_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001680
1681 acquire_bus(ACQUIRE_AND_WAKEUP);
1682
1683
1684 ret = p->hif_func.hif_read_reg(WILC_GP_REG_0, &reg);
1685 if (!ret) {
1686 PRINT_ER("Error while reading reg\n");
1687 release_bus(RELEASE_ALLOW_SLEEP);
1688 }
1689 PRINT_ER("Writing ABORT reg\n");
1690 ret = p->hif_func.hif_write_reg(WILC_GP_REG_0, (reg | ABORT_INT));
1691 if (!ret) {
1692 PRINT_ER("Error while writing reg\n");
1693 release_bus(RELEASE_ALLOW_SLEEP);
1694 }
1695 release_bus(RELEASE_ALLOW_SLEEP);
1696 /**
1697 * io clean up
1698 **/
1699 p->hif_func.hif_deinit(NULL);
1700
1701}
1702
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001703static int wilc_wlan_cfg_commit(int type, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001704{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301705 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001706 wilc_cfg_frame_t *cfg = &p->cfg_frame;
1707 int total_len = p->cfg_frame_offset + 4 + DRIVER_HANDLER_SIZE;
1708 int seq_no = p->cfg_seq_no % 256;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001709 int driver_handler = (u32)drvHandler;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001710
1711
1712 /**
1713 * Set up header
1714 **/
1715 if (type == WILC_CFG_SET) { /* Set */
1716 cfg->wid_header[0] = 'W';
1717 } else { /* Query */
1718 cfg->wid_header[0] = 'Q';
1719 }
1720 cfg->wid_header[1] = seq_no; /* sequence number */
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001721 cfg->wid_header[2] = (u8)total_len;
1722 cfg->wid_header[3] = (u8)(total_len >> 8);
1723 cfg->wid_header[4] = (u8)driver_handler;
1724 cfg->wid_header[5] = (u8)(driver_handler >> 8);
1725 cfg->wid_header[6] = (u8)(driver_handler >> 16);
1726 cfg->wid_header[7] = (u8)(driver_handler >> 24);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001727 p->cfg_seq_no = seq_no;
1728
1729 /**
1730 * Add to TX queue
1731 **/
1732
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001733 if (!wilc_wlan_txq_add_cfg_pkt(&cfg->wid_header[0], total_len))
1734 return -1;
1735
1736 return 0;
1737}
1738
Glen Lee1028e5a2015-10-01 16:03:40 +09001739int wilc_wlan_cfg_set(int start, u32 wid, u8 *buffer, u32 buffer_size,
1740 int commit, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001741{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301742 wilc_wlan_dev_t *p = &g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001743 u32 offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001744 int ret_size;
1745
1746
1747 if (p->cfg_frame_in_use)
1748 return 0;
1749
1750 if (start)
1751 p->cfg_frame_offset = 0;
1752
1753 offset = p->cfg_frame_offset;
Glen Lee17e8f162015-10-02 14:22:07 +09001754 ret_size = wilc_wlan_cfg_set_wid(p->cfg_frame.frame, offset, (u16)wid,
1755 buffer, buffer_size);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001756 offset += ret_size;
1757 p->cfg_frame_offset = offset;
1758
1759 if (commit) {
1760 PRINT_D(TX_DBG, "[WILC]PACKET Commit with sequence number %d\n", p->cfg_seq_no);
1761 PRINT_D(RX_DBG, "Processing cfg_set()\n");
1762 p->cfg_frame_in_use = 1;
1763
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001764 if (wilc_wlan_cfg_commit(WILC_CFG_SET, drvHandler))
Chaehyun Lim5af6b852015-09-17 16:48:48 +09001765 ret_size = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001766
Glen Leeb002e202015-09-24 18:15:05 +09001767 if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event,
1768 CFG_PKTS_TIMEOUT)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001769 PRINT_D(TX_DBG, "Set Timed Out\n");
1770 ret_size = 0;
1771 }
1772 p->cfg_frame_in_use = 0;
1773 p->cfg_frame_offset = 0;
1774 p->cfg_seq_no += 1;
1775
1776 }
1777
1778 return ret_size;
1779}
Glen Lee07056a82015-10-01 16:03:41 +09001780int wilc_wlan_cfg_get(int start, u32 wid, int commit, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001781{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301782 wilc_wlan_dev_t *p = &g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001783 u32 offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001784 int ret_size;
1785
1786
1787 if (p->cfg_frame_in_use)
1788 return 0;
1789
1790 if (start)
1791 p->cfg_frame_offset = 0;
1792
1793 offset = p->cfg_frame_offset;
Glen Leeec1b86b2015-10-02 14:22:08 +09001794 ret_size = wilc_wlan_cfg_get_wid(p->cfg_frame.frame, offset, (u16)wid);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001795 offset += ret_size;
1796 p->cfg_frame_offset = offset;
1797
1798 if (commit) {
1799 p->cfg_frame_in_use = 1;
1800
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001801 if (wilc_wlan_cfg_commit(WILC_CFG_QUERY, drvHandler))
Chaehyun Lim5af6b852015-09-17 16:48:48 +09001802 ret_size = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001803
1804
Glen Leeb002e202015-09-24 18:15:05 +09001805 if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event,
1806 CFG_PKTS_TIMEOUT)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001807 PRINT_D(TX_DBG, "Get Timed Out\n");
1808 ret_size = 0;
1809 }
1810 PRINT_D(GENERIC_DBG, "[WILC]Get Response received\n");
1811 p->cfg_frame_in_use = 0;
1812 p->cfg_frame_offset = 0;
1813 p->cfg_seq_no += 1;
1814 }
1815
1816 return ret_size;
1817}
1818
Glen Lee894de36b2015-10-01 16:03:42 +09001819int wilc_wlan_cfg_get_val(u32 wid, u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001820{
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001821 int ret;
1822
Glen Lee355cca22015-10-02 14:22:09 +09001823 ret = wilc_wlan_cfg_get_wid_value((u16)wid, buffer, buffer_size);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001824
1825 return ret;
1826}
1827
1828void wilc_bus_set_max_speed(void)
1829{
1830
1831 /* Increase bus speed to max possible. */
1832 g_wlan.hif_func.hif_set_max_bus_speed();
1833}
1834
1835void wilc_bus_set_default_speed(void)
1836{
1837
1838 /* Restore bus speed to default. */
1839 g_wlan.hif_func.hif_set_default_bus_speed();
1840}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001841u32 init_chip(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001842{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001843 u32 chipid;
1844 u32 reg, ret = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001845
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001846 acquire_bus(ACQUIRE_ONLY);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001847
Dean Lee72ed4dc2015-06-12 14:11:44 +09001848 chipid = wilc_get_chipid(true);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001849
1850
1851
1852 if ((chipid & 0xfff) != 0xa0) {
1853 /**
1854 * Avoid booting from boot ROM. Make sure that Drive IRQN [SDIO platform]
1855 * or SD_DAT3 [SPI platform] to ?1?
1856 **/
1857 /* Set cortus reset register to register control. */
1858 ret = g_wlan.hif_func.hif_read_reg(0x1118, &reg);
1859 if (!ret) {
1860 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1118 ...\n");
1861 return ret;
1862 }
Anish Bhattffda2032015-09-29 12:15:49 -07001863 reg |= BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001864 ret = g_wlan.hif_func.hif_write_reg(0x1118, reg);
1865 if (!ret) {
1866 wilc_debug(N_ERR, "[wilc start]: fail write reg 0x1118 ...\n");
1867 return ret;
1868 }
1869 /**
1870 * Write branch intruction to IRAM (0x71 trap) at location 0xFFFF0000
1871 * (Cortus map) or C0000 (AHB map).
1872 **/
1873 ret = g_wlan.hif_func.hif_write_reg(0xc0000, 0x71);
1874 if (!ret) {
1875 wilc_debug(N_ERR, "[wilc start]: fail write reg 0xc0000 ...\n");
1876 return ret;
1877 }
1878 }
1879
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001880 release_bus(RELEASE_ONLY);
1881
1882 return ret;
1883
1884}
1885
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001886u32 wilc_get_chipid(u8 update)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001887{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001888 static u32 chipid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001889 /* SDIO can't read into global variables */
1890 /* Use this variable as a temp, then copy to the global */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001891 u32 tempchipid = 0;
1892 u32 rfrevid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001893
1894 if (chipid == 0 || update != 0) {
1895 g_wlan.hif_func.hif_read_reg(0x1000, &tempchipid);
1896 g_wlan.hif_func.hif_read_reg(0x13f4, &rfrevid);
1897 if (!ISWILC1000(tempchipid)) {
1898 chipid = 0;
1899 goto _fail_;
1900 }
1901 if (tempchipid == 0x1002a0) {
1902 if (rfrevid == 0x1) { /* 1002A0 */
1903 } else { /* if (rfrevid == 0x2) */ /* 1002A1 */
1904 tempchipid = 0x1002a1;
1905 }
1906 } else if (tempchipid == 0x1002b0) {
1907 if (rfrevid == 3) { /* 1002B0 */
1908 } else if (rfrevid == 4) { /* 1002B1 */
1909 tempchipid = 0x1002b1;
1910 } else { /* if(rfrevid == 5) */ /* 1002B2 */
1911 tempchipid = 0x1002b2;
1912 }
1913 } else {
1914 }
1915
1916 chipid = tempchipid;
1917 }
1918_fail_:
1919 return chipid;
1920}
1921
1922#ifdef COMPLEMENT_BOOT
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001923u8 core_11b_ready(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001924{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001925 u32 reg_val;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001926
1927 acquire_bus(ACQUIRE_ONLY);
1928 g_wlan.hif_func.hif_write_reg(0x16082c, 1);
1929 g_wlan.hif_func.hif_write_reg(0x161600, 0x90);
1930 g_wlan.hif_func.hif_read_reg(0x161600, &reg_val);
1931 release_bus(RELEASE_ONLY);
1932
1933 if (reg_val == 0x90)
1934 return 0;
1935 else
1936 return 1;
1937}
1938#endif
1939
Glen Leec9d48342015-10-01 16:03:43 +09001940int wilc_wlan_init(wilc_wlan_inp_t *inp)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001941{
1942
1943 int ret = 0;
1944
1945 PRINT_D(INIT_DBG, "Initializing WILC_Wlan ...\n");
1946
1947 memset((void *)&g_wlan, 0, sizeof(wilc_wlan_dev_t));
1948
1949 /**
1950 * store the input
1951 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001952 memcpy((void *)&g_wlan.io_func, (void *)&inp->io_func, sizeof(wilc_wlan_io_func_t));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001953 /***
1954 * host interface init
1955 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001956 if ((inp->io_func.io_type & 0x1) == HIF_SDIO) {
1957 if (!hif_sdio.hif_init(inp, wilc_debug)) {
1958 /* EIO 5 */
1959 ret = -5;
1960 goto _fail_;
1961 }
1962 memcpy((void *)&g_wlan.hif_func, &hif_sdio, sizeof(wilc_hif_func_t));
1963 } else {
1964 if ((inp->io_func.io_type & 0x1) == HIF_SPI) {
1965 /**
1966 * TODO:
1967 **/
1968 if (!hif_spi.hif_init(inp, wilc_debug)) {
1969 /* EIO 5 */
1970 ret = -5;
1971 goto _fail_;
1972 }
1973 memcpy((void *)&g_wlan.hif_func, &hif_spi, sizeof(wilc_hif_func_t));
1974 } else {
1975 /* EIO 5 */
1976 ret = -5;
1977 goto _fail_;
1978 }
1979 }
1980
1981 /***
1982 * mac interface init
1983 **/
Glen Lee814bc362015-10-02 14:22:11 +09001984 if (!wilc_wlan_cfg_init(wilc_debug)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001985 /* ENOBUFS 105 */
1986 ret = -105;
1987 goto _fail_;
1988 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001989
1990 /**
1991 * alloc tx, rx buffer
1992 **/
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09001993 if (g_wlan.tx_buffer == NULL)
Glen Lee7015b5d2015-09-24 18:15:02 +09001994 g_wlan.tx_buffer = kmalloc(LINUX_TX_SIZE, GFP_KERNEL);
Arnd Bergmann7a8fd842015-06-01 21:06:45 +02001995 PRINT_D(TX_DBG, "g_wlan.tx_buffer = %p\n", g_wlan.tx_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001996
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09001997 if (g_wlan.tx_buffer == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001998 /* ENOBUFS 105 */
1999 ret = -105;
2000 PRINT_ER("Can't allocate Tx Buffer");
2001 goto _fail_;
2002 }
2003
2004/* rx_buffer is not used unless we activate USE_MEM STATIC which is not applicable, allocating such memory is useless*/
2005#if defined (MEMORY_STATIC)
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002006 if (g_wlan.rx_buffer == NULL)
Glen Lee03eb7262015-09-24 18:15:03 +09002007 g_wlan.rx_buffer = kmalloc(LINUX_RX_SIZE, GFP_KERNEL);
Arnd Bergmann7a8fd842015-06-01 21:06:45 +02002008 PRINT_D(TX_DBG, "g_wlan.rx_buffer =%p\n", g_wlan.rx_buffer);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002009 if (g_wlan.rx_buffer == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002010 /* ENOBUFS 105 */
2011 ret = -105;
2012 PRINT_ER("Can't allocate Rx Buffer");
2013 goto _fail_;
2014 }
2015#endif
2016
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002017 if (!init_chip()) {
2018 /* EIO 5 */
2019 ret = -5;
2020 goto _fail_;
2021 }
2022#ifdef TCP_ACK_FILTER
2023 Init_TCP_tracking();
2024#endif
2025
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002026 return 1;
2027
2028_fail_:
2029
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002030 #ifdef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07002031 kfree(g_wlan.rx_buffer);
2032 g_wlan.rx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002033 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07002034 kfree(g_wlan.tx_buffer);
2035 g_wlan.tx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002036
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002037 return ret;
2038
2039}
2040
Dean Lee72ed4dc2015-06-12 14:11:44 +09002041u16 Set_machw_change_vir_if(bool bValue)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002042{
Chaehyun Limd85f5322015-06-11 14:35:54 +09002043 u16 ret;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002044 u32 reg;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002045
2046 /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
Glen Lee187f1ef2015-09-24 18:15:01 +09002047 mutex_lock(&g_linux_wlan->hif_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002048 ret = (&g_wlan)->hif_func.hif_read_reg(WILC_CHANGING_VIR_IF, &reg);
Alison Schofield39823a52015-10-08 21:18:03 -07002049 if (!ret)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002050 PRINT_ER("Error while Reading reg WILC_CHANGING_VIR_IF\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002051
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05302052 if (bValue)
Chaehyun Lim50b51da2015-09-16 20:11:26 +09002053 reg |= BIT(31);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05302054 else
Chaehyun Lim50b51da2015-09-16 20:11:26 +09002055 reg &= ~BIT(31);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002056
2057 ret = (&g_wlan)->hif_func.hif_write_reg(WILC_CHANGING_VIR_IF, reg);
2058
Alison Schofield39823a52015-10-08 21:18:03 -07002059 if (!ret)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002060 PRINT_ER("Error while writing reg WILC_CHANGING_VIR_IF\n");
Alison Schofield39823a52015-10-08 21:18:03 -07002061
Glen Lee187f1ef2015-09-24 18:15:01 +09002062 mutex_unlock(&g_linux_wlan->hif_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002063
2064 return ret;
2065}