blob: 63712a2ef9bee839b9b81f8162d879fe3031c5f6 [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
Glen Leec029e992015-10-27 18:27:48 +0900409static int wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900410{
Glen Leec029e992015-10-27 18:27:48 +0900411 perInterface_wlan_t *nic;
412 struct wilc *wilc;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900413 u32 i = 0;
414 u32 Dropped = 0;
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530415 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900416
Glen Leec029e992015-10-27 18:27:48 +0900417 nic = netdev_priv(dev);
418 wilc = nic->wilc;
419
420 spin_lock_irqsave(&wilc->txq_spinlock, p->txq_spinlock_flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900421 for (i = PendingAcks_arrBase; i < (PendingAcks_arrBase + Pending_Acks); i++) {
422 if (Pending_Acks_info[i].ack_num < Acks_keep_track_info[Pending_Acks_info[i].Session_index].Bigger_Ack_num) {
423 struct txq_entry_t *tqe;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900424
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530425 PRINT_D(TCP_ENH, "DROP ACK: %u\n", Pending_Acks_info[i].ack_num);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900426 tqe = Pending_Acks_info[i].txqe;
427 if (tqe) {
428 wilc_wlan_txq_remove(tqe);
429 Statisitcs_DroppedAcks++;
430 tqe->status = 1; /* mark the packet send */
431 if (tqe->tx_complete_func)
432 tqe->tx_complete_func(tqe->priv, tqe->status);
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -0700433 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900434 Dropped++;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900435 }
436 }
437 }
438 Pending_Acks = 0;
439 Opened_TCP_session = 0;
440
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530441 if (PendingAcks_arrBase == 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900442 PendingAcks_arrBase = MAX_TCP_SESSION;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530443 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900444 PendingAcks_arrBase = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900445
446
Glen Leec029e992015-10-27 18:27:48 +0900447 spin_unlock_irqrestore(&wilc->txq_spinlock, p->txq_spinlock_flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900448
449 while (Dropped > 0) {
450 /*consume the semaphore count of the removed packet*/
Glen Leec029e992015-10-27 18:27:48 +0900451 linux_wlan_lock_timeout(&wilc->txq_event, 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900452 Dropped--;
453 }
454
455 return 1;
456}
457#endif
458
Dean Lee72ed4dc2015-06-12 14:11:44 +0900459bool EnableTCPAckFilter = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900460
Dean Lee72ed4dc2015-06-12 14:11:44 +0900461void Enable_TCP_ACK_Filter(bool value)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900462{
463 EnableTCPAckFilter = value;
464}
465
Dean Lee72ed4dc2015-06-12 14:11:44 +0900466bool is_TCP_ACK_Filter_Enabled(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900467{
468 return EnableTCPAckFilter;
469}
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900470
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900471static int wilc_wlan_txq_add_cfg_pkt(u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900472{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530473 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900474 struct txq_entry_t *tqe;
475
476 PRINT_D(TX_DBG, "Adding config packet ...\n");
477 if (p->quit) {
478 PRINT_D(TX_DBG, "Return due to clear function\n");
Glen Lee6a3b94f2015-09-24 18:14:59 +0900479 up(&g_linux_wlan->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900480 return 0;
481 }
482
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700483 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900484 if (tqe == NULL) {
485 PRINT_ER("Failed to allocate memory\n");
486 return 0;
487 }
488
489 tqe->type = WILC_CFG_PKT;
490 tqe->buffer = buffer;
491 tqe->buffer_size = buffer_size;
492 tqe->tx_complete_func = NULL;
493 tqe->priv = NULL;
494#ifdef TCP_ACK_FILTER
495 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
496#endif
497 /**
498 * Configuration packet always at the front
499 **/
500 PRINT_D(TX_DBG, "Adding the config packet at the Queue tail\n");
501
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900502 if (wilc_wlan_txq_add_to_head(tqe))
503 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900504 return 1;
505}
506
Glen Lee8fc84a62015-10-01 16:03:35 +0900507int wilc_wlan_txq_add_net_pkt(void *priv, u8 *buffer, u32 buffer_size,
508 wilc_tx_complete_func_t func)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900509{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530510 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900511 struct txq_entry_t *tqe;
512
513 if (p->quit)
514 return 0;
515
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700516 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900517
518 if (tqe == NULL)
519 return 0;
520 tqe->type = WILC_NET_PKT;
521 tqe->buffer = buffer;
522 tqe->buffer_size = buffer_size;
523 tqe->tx_complete_func = func;
524 tqe->priv = priv;
525
526 PRINT_D(TX_DBG, "Adding mgmt packet at the Queue tail\n");
527#ifdef TCP_ACK_FILTER
528 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
Abdul Hussain5a66bf22015-06-16 09:44:06 +0000529 if (is_TCP_ACK_Filter_Enabled())
Glen Lee25a84832015-09-16 18:53:22 +0900530 tcp_process(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900531#endif
532 wilc_wlan_txq_add_to_tail(tqe);
533 /*return number of itemes in the queue*/
534 return p->txq_entries;
535}
Glen Leefcc6ef92015-09-16 18:53:21 +0900536
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900537int wilc_wlan_txq_add_mgmt_pkt(void *priv, u8 *buffer, u32 buffer_size, wilc_tx_complete_func_t func)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900538{
539
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530540 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900541 struct txq_entry_t *tqe;
542
543 if (p->quit)
544 return 0;
545
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700546 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900547
548 if (tqe == NULL)
549 return 0;
550 tqe->type = WILC_MGMT_PKT;
551 tqe->buffer = buffer;
552 tqe->buffer_size = buffer_size;
553 tqe->tx_complete_func = func;
554 tqe->priv = priv;
555#ifdef TCP_ACK_FILTER
556 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
557#endif
558 PRINT_D(TX_DBG, "Adding Network packet at the Queue tail\n");
559 wilc_wlan_txq_add_to_tail(tqe);
560 return 1;
561}
Glen Leefcc6ef92015-09-16 18:53:21 +0900562
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900563static struct txq_entry_t *wilc_wlan_txq_get_first(void)
564{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530565 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900566 struct txq_entry_t *tqe;
567 unsigned long flags;
568
Glen Lee85e57562015-09-24 18:14:56 +0900569 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900570
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900571 tqe = p->txq_head;
572
Glen Lee85e57562015-09-24 18:14:56 +0900573 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900574
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900575
576 return tqe;
577}
578
579static struct txq_entry_t *wilc_wlan_txq_get_next(struct txq_entry_t *tqe)
580{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900581 unsigned long flags;
Glen Lee85e57562015-09-24 18:14:56 +0900582 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900583
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900584 tqe = tqe->next;
Glen Lee85e57562015-09-24 18:14:56 +0900585 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900586
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900587
588 return tqe;
589}
590
591static int wilc_wlan_rxq_add(struct rxq_entry_t *rqe)
592{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530593 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900594
595 if (p->quit)
596 return 0;
597
Glen Lee645db602015-09-24 18:14:57 +0900598 mutex_lock(&g_linux_wlan->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900599 if (p->rxq_head == NULL) {
600 PRINT_D(RX_DBG, "Add to Queue head\n");
601 rqe->next = NULL;
602 p->rxq_head = rqe;
603 p->rxq_tail = rqe;
604 } else {
605 PRINT_D(RX_DBG, "Add to Queue tail\n");
606 p->rxq_tail->next = rqe;
607 rqe->next = NULL;
608 p->rxq_tail = rqe;
609 }
610 p->rxq_entries += 1;
611 PRINT_D(RX_DBG, "Number of queue entries: %d\n", p->rxq_entries);
Glen Lee645db602015-09-24 18:14:57 +0900612 mutex_unlock(&g_linux_wlan->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900613 return p->rxq_entries;
614}
615
616static struct rxq_entry_t *wilc_wlan_rxq_remove(void)
617{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530618 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900619
620 PRINT_D(RX_DBG, "Getting rxQ element\n");
621 if (p->rxq_head) {
622 struct rxq_entry_t *rqe;
623
Glen Lee645db602015-09-24 18:14:57 +0900624 mutex_lock(&g_linux_wlan->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900625 rqe = p->rxq_head;
626 p->rxq_head = p->rxq_head->next;
627 p->rxq_entries -= 1;
628 PRINT_D(RX_DBG, "RXQ entries decreased\n");
Glen Lee645db602015-09-24 18:14:57 +0900629 mutex_unlock(&g_linux_wlan->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900630 return rqe;
631 }
632 PRINT_D(RX_DBG, "Nothing to get from Q\n");
633 return NULL;
634}
635
636
637/********************************************
638 *
639 * Power Save handle functions
640 *
641 ********************************************/
642
643
644
645#ifdef WILC_OPTIMIZE_SLEEP_INT
646
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900647static inline void chip_allow_sleep(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900648{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900649 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900650
651 /* Clear bit 1 */
652 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
653
Anish Bhattffda2032015-09-29 12:15:49 -0700654 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900655}
656
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900657static inline void chip_wakeup(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900658{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900659 u32 reg, clk_status_reg, trials = 0;
660 u32 sleep_time;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900661
662 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
663 do {
664 g_wlan.hif_func.hif_read_reg(1, &reg);
665 /* Set bit 1 */
Anish Bhattffda2032015-09-29 12:15:49 -0700666 g_wlan.hif_func.hif_write_reg(1, reg | BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900667
668 /* Clear bit 1*/
Anish Bhattffda2032015-09-29 12:15:49 -0700669 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900670
671 do {
672 /* Wait for the chip to stabilize*/
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -0700673 usleep_range(2 * 1000, 2 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900674 /* Make sure chip is awake. This is an extra step that can be removed */
675 /* later to avoid the bus access overhead */
Alison Schofield39823a52015-10-08 21:18:03 -0700676 if ((wilc_get_chipid(true) == 0))
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900677 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
Alison Schofield39823a52015-10-08 21:18:03 -0700678
Dean Lee72ed4dc2015-06-12 14:11:44 +0900679 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900680
Dean Lee72ed4dc2015-06-12 14:11:44 +0900681 } while (wilc_get_chipid(true) == 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900682 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
683 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
684 do {
685 /* Set bit 1 */
Anish Bhattffda2032015-09-29 12:15:49 -0700686 g_wlan.hif_func.hif_write_reg(0xf0, reg | BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900687
688 /* Check the clock status */
689 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
690
691 /* in case of clocks off, wait 2ms, and check it again. */
692 /* if still off, wait for another 2ms, for a total wait of 6ms. */
693 /* If still off, redo the wake up sequence */
694 while (((clk_status_reg & 0x1) == 0) && (((++trials) % 3) == 0)) {
695 /* Wait for the chip to stabilize*/
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -0700696 usleep_range(2 * 1000, 2 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900697
698 /* Make sure chip is awake. This is an extra step that can be removed */
699 /* later to avoid the bus access overhead */
700 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
701
Alison Schofield39823a52015-10-08 21:18:03 -0700702 if ((clk_status_reg & 0x1) == 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900703 wilc_debug(N_ERR, "clocks still OFF. Wake up failed\n");
Alison Schofield39823a52015-10-08 21:18:03 -0700704
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900705 }
706 /* in case of failure, Reset the wakeup bit to introduce a new edge on the next loop */
707 if ((clk_status_reg & 0x1) == 0) {
708 /* Reset bit 0 */
Anish Bhattffda2032015-09-29 12:15:49 -0700709 g_wlan.hif_func.hif_write_reg(0xf0, reg &
710 (~BIT(0)));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900711 }
712 } while ((clk_status_reg & 0x1) == 0);
713 }
714
715
716 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
717 g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -0700718 reg &= ~BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900719 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
720
Dean Lee72ed4dc2015-06-12 14:11:44 +0900721 if (wilc_get_chipid(false) >= 0x1002b0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900722 /* Enable PALDO back right after wakeup */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900723 u32 val32;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900724
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900725 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700726 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900727 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
728
729 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700730 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900731 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
732 }
733 }
734 genuChipPSstate = CHIP_WAKEDUP;
735}
736#else
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900737static inline void chip_wakeup(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900738{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900739 u32 reg, trials = 0;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900740
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900741 do {
742 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
743 g_wlan.hif_func.hif_read_reg(1, &reg);
744 /* Make sure bit 1 is 0 before we start. */
Anish Bhattffda2032015-09-29 12:15:49 -0700745 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900746 /* Set bit 1 */
Anish Bhattffda2032015-09-29 12:15:49 -0700747 g_wlan.hif_func.hif_write_reg(1, reg | BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900748 /* Clear bit 1*/
Anish Bhattffda2032015-09-29 12:15:49 -0700749 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900750 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
751 /* Make sure bit 0 is 0 before we start. */
752 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -0700753 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900754 /* Set bit 1 */
Anish Bhattffda2032015-09-29 12:15:49 -0700755 g_wlan.hif_func.hif_write_reg(0xf0, reg | BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900756 /* Clear bit 1 */
Anish Bhattffda2032015-09-29 12:15:49 -0700757 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900758 }
759
760 do {
761 /* Wait for the chip to stabilize*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900762 mdelay(3);
763
764 /* Make sure chip is awake. This is an extra step that can be removed */
765 /* later to avoid the bus access overhead */
Alison Schofield39823a52015-10-08 21:18:03 -0700766 if ((wilc_get_chipid(true) == 0))
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900767 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
Alison Schofield39823a52015-10-08 21:18:03 -0700768
Dean Lee72ed4dc2015-06-12 14:11:44 +0900769 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900770
Dean Lee72ed4dc2015-06-12 14:11:44 +0900771 } while (wilc_get_chipid(true) == 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900772
773 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
774 g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -0700775 reg &= ~BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900776 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
777
Dean Lee72ed4dc2015-06-12 14:11:44 +0900778 if (wilc_get_chipid(false) >= 0x1002b0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900779 /* Enable PALDO back right after wakeup */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900780 u32 val32;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900781
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900782 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700783 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900784 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
785
786 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700787 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900788 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
789 }
790 }
791 genuChipPSstate = CHIP_WAKEDUP;
792}
793#endif
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900794void chip_sleep_manually(u32 u32SleepTime)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900795{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900796 if (genuChipPSstate != CHIP_WAKEDUP) {
797 /* chip is already sleeping. Do nothing */
798 return;
799 }
800 acquire_bus(ACQUIRE_ONLY);
801
802#ifdef WILC_OPTIMIZE_SLEEP_INT
803 chip_allow_sleep();
804#endif
805
806 /* Trigger the manual sleep interrupt */
807 g_wlan.hif_func.hif_write_reg(0x10a8, 1);
808
809 genuChipPSstate = CHIP_SLEEPING_MANUAL;
810 release_bus(RELEASE_ONLY);
811
812}
813
814
815/********************************************
816 *
817 * Tx, Rx queue handle functions
818 *
819 ********************************************/
Glen Leea1332ca2015-10-27 18:27:47 +0900820int wilc_wlan_handle_txq(struct net_device *dev, u32 *pu32TxqCount)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900821{
822 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
823 int i, entries = 0;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900824 u32 sum;
825 u32 reg;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900826 u8 *txb = p->tx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900827 u32 offset = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900828 int vmm_sz = 0;
829 struct txq_entry_t *tqe;
830 int ret = 0;
831 int counter;
832 int timeout;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900833 u32 vmm_table[WILC_VMM_TBL_SIZE];
Glen Leea1332ca2015-10-27 18:27:47 +0900834 perInterface_wlan_t *nic;
835 struct wilc *wilc;
836
837 nic = netdev_priv(dev);
838 wilc = nic->wilc;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900839
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900840 p->txq_exit = 0;
841 do {
842 if (p->quit)
843 break;
844
Glen Leea1332ca2015-10-27 18:27:47 +0900845 linux_wlan_lock_timeout(&wilc->txq_add_to_head_cs,
Glen Leeb002e202015-09-24 18:15:05 +0900846 CFG_PKTS_TIMEOUT);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900847#ifdef TCP_ACK_FILTER
Glen Leec029e992015-10-27 18:27:48 +0900848 wilc_wlan_txq_filter_dup_tcp_ack(dev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900849#endif
850 /**
851 * build the vmm list
852 **/
853 PRINT_D(TX_DBG, "Getting the head of the TxQ\n");
854 tqe = wilc_wlan_txq_get_first();
855 i = 0;
856 sum = 0;
857 do {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900858 if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE - 1)) /* reserve last entry to 0 */) {
859
Alison Schofield39823a52015-10-08 21:18:03 -0700860 if (tqe->type == WILC_CFG_PKT)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900861 vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET;
Alison Schofield39823a52015-10-08 21:18:03 -0700862
863 else if (tqe->type == WILC_NET_PKT)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900864 vmm_sz = ETH_ETHERNET_HDR_OFFSET;
Alison Schofield39823a52015-10-08 21:18:03 -0700865
866 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900867 vmm_sz = HOST_HDR_OFFSET;
Alison Schofield39823a52015-10-08 21:18:03 -0700868
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900869 vmm_sz += tqe->buffer_size;
870 PRINT_D(TX_DBG, "VMM Size before alignment = %d\n", vmm_sz);
871 if (vmm_sz & 0x3) { /* has to be word aligned */
872 vmm_sz = (vmm_sz + 4) & ~0x3;
873 }
Alison Schofield39823a52015-10-08 21:18:03 -0700874 if ((sum + vmm_sz) > LINUX_TX_SIZE)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900875 break;
Alison Schofield39823a52015-10-08 21:18:03 -0700876
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900877 PRINT_D(TX_DBG, "VMM Size AFTER alignment = %d\n", vmm_sz);
878 vmm_table[i] = vmm_sz / 4; /* table take the word size */
879 PRINT_D(TX_DBG, "VMMTable entry size = %d\n", vmm_table[i]);
880
881 if (tqe->type == WILC_CFG_PKT) {
Anish Bhattffda2032015-09-29 12:15:49 -0700882 vmm_table[i] |= BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900883 PRINT_D(TX_DBG, "VMMTable entry changed for CFG packet = %d\n", vmm_table[i]);
884 }
885#ifdef BIG_ENDIAN
886 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
887#endif
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900888
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900889 i++;
890 sum += vmm_sz;
891 PRINT_D(TX_DBG, "sum = %d\n", sum);
892 tqe = wilc_wlan_txq_get_next(tqe);
893 } else {
894 break;
895 }
896 } while (1);
897
898 if (i == 0) { /* nothing in the queue */
899 PRINT_D(TX_DBG, "Nothing in TX-Q\n");
900 break;
901 } else {
902 PRINT_D(TX_DBG, "Mark the last entry in VMM table - number of previous entries = %d\n", i);
903 vmm_table[i] = 0x0; /* mark the last element to 0 */
904 }
905 acquire_bus(ACQUIRE_AND_WAKEUP);
906 counter = 0;
907 do {
908
909 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg);
910 if (!ret) {
911 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg vmm_tbl_entry..\n");
912 break;
913 }
914
915 if ((reg & 0x1) == 0) {
916 /**
917 * write to vmm table
918 **/
919 PRINT_D(TX_DBG, "Writing VMM table ... with Size = %d\n", ((i + 1) * 4));
920 break;
921 } else {
922 counter++;
923 if (counter > 200) {
924 counter = 0;
925 PRINT_D(TX_DBG, "Looping in tx ctrl , forcce quit\n");
926 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, 0);
927 break;
928 }
929 /**
930 * wait for vmm table is ready
931 **/
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530932 PRINT_WRN(GENERIC_DBG, "[wilc txq]: warn, vmm table not clear yet, wait...\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900933 release_bus(RELEASE_ALLOW_SLEEP);
Greg Kroah-Hartman2b922cb2015-09-04 09:30:51 -0700934 usleep_range(3000, 3000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900935 acquire_bus(ACQUIRE_AND_WAKEUP);
936 }
937 } while (!p->quit);
938
Alison Schofield39823a52015-10-08 21:18:03 -0700939 if (!ret)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900940 goto _end_;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900941
942 timeout = 200;
943 do {
944
945 /**
946 * write to vmm table
947 **/
Chaehyun Limc3ca6372015-09-20 15:51:19 +0900948 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 +0900949 if (!ret) {
950 wilc_debug(N_ERR, "ERR block TX of VMM table.\n");
951 break;
952 }
953
954
955 /**
956 * interrupt firmware
957 **/
958 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x2);
959 if (!ret) {
960 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg host_vmm_ctl..\n");
961 break;
962 }
963
964 /**
965 * wait for confirm...
966 **/
967
968 do {
969 ret = p->hif_func.hif_read_reg(WILC_HOST_VMM_CTL, &reg);
970 if (!ret) {
971 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg host_vmm_ctl..\n");
972 break;
973 }
974 if ((reg >> 2) & 0x1) {
975 /**
976 * Get the entries
977 **/
978 entries = ((reg >> 3) & 0x3f);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900979 break;
980 } else {
981 release_bus(RELEASE_ALLOW_SLEEP);
Greg Kroah-Hartman2b922cb2015-09-04 09:30:51 -0700982 usleep_range(3000, 3000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900983 acquire_bus(ACQUIRE_AND_WAKEUP);
984 PRINT_WRN(GENERIC_DBG, "Can't get VMM entery - reg = %2x\n", reg);
985 }
986 } while (--timeout);
987 if (timeout <= 0) {
988 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x0);
989 break;
990 }
991
Alison Schofield39823a52015-10-08 21:18:03 -0700992 if (!ret)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900993 break;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900994
995 if (entries == 0) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530996 PRINT_WRN(GENERIC_DBG, "[wilc txq]: no more buffer in the chip (reg: %08x), retry later [[ %d, %x ]]\n", reg, i, vmm_table[i - 1]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900997
998 /* undo the transaction. */
999 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg);
1000 if (!ret) {
1001 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg WILC_HOST_TX_CTRL..\n");
1002 break;
1003 }
Anish Bhattffda2032015-09-29 12:15:49 -07001004 reg &= ~BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001005 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, reg);
1006 if (!ret) {
1007 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg WILC_HOST_TX_CTRL..\n");
1008 break;
1009 }
1010 break;
1011 } else {
1012 break;
1013 }
1014 } while (1);
1015
Alison Schofield39823a52015-10-08 21:18:03 -07001016 if (!ret)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001017 goto _end_;
Alison Schofield39823a52015-10-08 21:18:03 -07001018
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001019 if (entries == 0) {
1020 ret = WILC_TX_ERR_NO_BUF;
1021 goto _end_;
1022 }
1023
1024 /* since copying data into txb takes some time, then
1025 * allow the bus lock to be released let the RX task go. */
1026 release_bus(RELEASE_ALLOW_SLEEP);
1027
1028 /**
1029 * Copy data to the TX buffer
1030 **/
1031 offset = 0;
1032 i = 0;
1033 do {
1034 tqe = wilc_wlan_txq_remove_from_head();
1035 if (tqe != NULL && (vmm_table[i] != 0)) {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001036 u32 header, buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001037
1038#ifdef BIG_ENDIAN
1039 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
1040#endif
1041 vmm_sz = (vmm_table[i] & 0x3ff); /* in word unit */
1042 vmm_sz *= 4;
1043 header = (tqe->type << 31) | (tqe->buffer_size << 15) | vmm_sz;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301044 if (tqe->type == WILC_MGMT_PKT)
Anish Bhattffda2032015-09-29 12:15:49 -07001045 header |= BIT(30);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301046 else
Anish Bhattffda2032015-09-29 12:15:49 -07001047 header &= ~BIT(30);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001048
1049#ifdef BIG_ENDIAN
1050 header = BYTE_SWAP(header);
1051#endif
1052 memcpy(&txb[offset], &header, 4);
1053 if (tqe->type == WILC_CFG_PKT) {
1054 buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET;
1055 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001056 else if (tqe->type == WILC_NET_PKT) {
1057 char *pBSSID = ((struct tx_complete_data *)(tqe->priv))->pBssid;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001058
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001059 buffer_offset = ETH_ETHERNET_HDR_OFFSET;
1060 /* copy the bssid at the sart of the buffer */
1061 memcpy(&txb[offset + 4], pBSSID, 6);
1062 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001063 else {
1064 buffer_offset = HOST_HDR_OFFSET;
1065 }
1066
1067 memcpy(&txb[offset + buffer_offset], tqe->buffer, tqe->buffer_size);
1068 offset += vmm_sz;
1069 i++;
1070 tqe->status = 1; /* mark the packet send */
1071 if (tqe->tx_complete_func)
1072 tqe->tx_complete_func(tqe->priv, tqe->status);
1073 #ifdef TCP_ACK_FILTER
Alison Schofield39823a52015-10-08 21:18:03 -07001074 if (tqe->tcp_PendingAck_index != NOT_TCP_ACK)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001075 Pending_Acks_info[tqe->tcp_PendingAck_index].txqe = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001076 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001077 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001078 } else {
1079 break;
1080 }
1081 } while (--entries);
1082
1083 /**
1084 * lock the bus
1085 **/
1086 acquire_bus(ACQUIRE_AND_WAKEUP);
1087
1088 ret = p->hif_func.hif_clear_int_ext(ENABLE_TX_VMM);
1089 if (!ret) {
1090 wilc_debug(N_ERR, "[wilc txq]: fail can't start tx VMM ...\n");
1091 goto _end_;
1092 }
1093
1094 /**
1095 * transfer
1096 **/
1097 ret = p->hif_func.hif_block_tx_ext(0, txb, offset);
1098 if (!ret) {
1099 wilc_debug(N_ERR, "[wilc txq]: fail can't block tx ext...\n");
1100 goto _end_;
1101 }
1102
1103_end_:
1104
1105 release_bus(RELEASE_ALLOW_SLEEP);
1106 if (ret != 1)
1107 break;
1108 } while (0);
Glen Leea1332ca2015-10-27 18:27:47 +09001109 up(&wilc->txq_add_to_head_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001110
1111 p->txq_exit = 1;
1112 PRINT_D(TX_DBG, "THREAD: Exiting txq\n");
1113 /* return tx[]q count */
1114 *pu32TxqCount = p->txq_entries;
1115 return ret;
1116}
1117
Glen Lee39ce4d32015-10-27 18:27:42 +09001118static void wilc_wlan_handle_rxq(struct wilc *wilc)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001119{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301120 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001121 int offset = 0, size, has_packet = 0;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001122 u8 *buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001123 struct rxq_entry_t *rqe;
1124
1125 p->rxq_exit = 0;
1126
1127
1128
1129
1130 do {
1131 if (p->quit) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301132 PRINT_D(RX_DBG, "exit 1st do-while due to Clean_UP function\n");
Glen Lee39ce4d32015-10-27 18:27:42 +09001133 up(&wilc->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001134 break;
1135 }
1136 rqe = wilc_wlan_rxq_remove();
1137 if (rqe == NULL) {
1138 PRINT_D(RX_DBG, "nothing in the queue - exit 1st do-while\n");
1139 break;
1140 }
1141 buffer = rqe->buffer;
1142 size = rqe->buffer_size;
1143 PRINT_D(RX_DBG, "rxQ entery Size = %d - Address = %p\n", size, buffer);
1144 offset = 0;
1145
1146
1147
1148 do {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001149 u32 header;
1150 u32 pkt_len, pkt_offset, tp_len;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001151 int is_cfg_packet;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001152
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001153 PRINT_D(RX_DBG, "In the 2nd do-while\n");
1154 memcpy(&header, &buffer[offset], 4);
1155#ifdef BIG_ENDIAN
1156 header = BYTE_SWAP(header);
1157#endif
1158 PRINT_D(RX_DBG, "Header = %04x - Offset = %d\n", header, offset);
1159
1160
1161
1162 is_cfg_packet = (header >> 31) & 0x1;
1163 pkt_offset = (header >> 22) & 0x1ff;
1164 tp_len = (header >> 11) & 0x7ff;
1165 pkt_len = header & 0x7ff;
1166
1167 if (pkt_len == 0 || tp_len == 0) {
1168 wilc_debug(N_RXQ, "[wilc rxq]: data corrupt, packet len or tp_len is 0 [%d][%d]\n", pkt_len, tp_len);
1169 break;
1170 }
1171
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 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001183 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001184 {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001185
1186 if (!is_cfg_packet) {
Glen Lee63611672015-09-24 18:14:52 +09001187 if (pkt_len > 0) {
1188 frmw_to_linux(&buffer[offset],
1189 pkt_len,
1190 pkt_offset);
1191 has_packet = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001192 }
1193 } else {
1194 wilc_cfg_rsp_t rsp;
1195
1196
1197
Glen Lee30f535a2015-10-02 14:22:10 +09001198 wilc_wlan_cfg_indicate_rx(&buffer[pkt_offset + offset], pkt_len, &rsp);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001199 if (rsp.type == WILC_CFG_RSP) {
1200 /**
1201 * wake up the waiting task...
1202 **/
1203 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 -07001204 if (p->cfg_seq_no == rsp.seq_no)
Glen Lee39ce4d32015-10-27 18:27:42 +09001205 up(&wilc->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001206 } else if (rsp.type == WILC_CFG_RSP_STATUS) {
1207 /**
1208 * Call back to indicate status...
1209 **/
Glen Lee64f2b712015-10-27 18:27:43 +09001210 linux_wlan_mac_indicate(wilc, WILC_MAC_INDICATE_STATUS);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001211
1212 } else if (rsp.type == WILC_CFG_RSP_SCAN) {
Glen Lee64f2b712015-10-27 18:27:43 +09001213 linux_wlan_mac_indicate(wilc, WILC_MAC_INDICATE_SCAN);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001214 }
1215 }
1216 }
1217 offset += tp_len;
1218 if (offset >= size)
1219 break;
1220 } while (1);
1221
1222
1223#ifndef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001224 kfree(buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001225#endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001226 kfree(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001227
Alison Schofield39823a52015-10-08 21:18:03 -07001228 if (has_packet)
Glen Leec0cadaa2015-09-24 18:14:54 +09001229 linux_wlan_rx_complete();
Alison Schofield39823a52015-10-08 21:18:03 -07001230
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001231 } while (1);
1232
1233 p->rxq_exit = 1;
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301234 PRINT_D(RX_DBG, "THREAD: Exiting RX thread\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001235}
1236
1237/********************************************
1238 *
1239 * Fast DMA Isr
1240 *
1241 ********************************************/
1242static void wilc_unknown_isr_ext(void)
1243{
1244 g_wlan.hif_func.hif_clear_int_ext(0);
1245}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001246static void wilc_pllupdate_isr_ext(u32 int_stats)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001247{
1248
1249 int trials = 10;
1250
1251 g_wlan.hif_func.hif_clear_int_ext(PLL_INT_CLR);
1252
1253 /* Waiting for PLL */
Greg Kroah-Hartmanc2e4c0f2015-09-03 19:09:50 -07001254 mdelay(WILC_PLL_TO);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001255
1256 /* poll till read a valid data */
Dean Lee72ed4dc2015-06-12 14:11:44 +09001257 while (!(ISWILC1000(wilc_get_chipid(true)) && --trials)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001258 PRINT_D(TX_DBG, "PLL update retrying\n");
Greg Kroah-Hartmanc2e4c0f2015-09-03 19:09:50 -07001259 mdelay(1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001260 }
1261}
1262
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001263static void wilc_sleeptimer_isr_ext(u32 int_stats1)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001264{
1265 g_wlan.hif_func.hif_clear_int_ext(SLEEP_INT_CLR);
1266#ifndef WILC_OPTIMIZE_SLEEP_INT
1267 genuChipPSstate = CHIP_SLEEPING_AUTO;
1268#endif
1269}
1270
Glen Lee3bcd45b2015-10-27 18:27:41 +09001271static void wilc_wlan_handle_isr_ext(struct wilc *wilc, u32 int_status)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001272{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301273 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001274#ifdef MEMORY_STATIC
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001275 u32 offset = p->rx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001276#endif
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001277 u8 *buffer = NULL;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001278 u32 size;
1279 u32 retries = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001280 int ret = 0;
1281 struct rxq_entry_t *rqe;
1282
1283
1284 /**
1285 * Get the rx size
1286 **/
1287
1288 size = ((int_status & 0x7fff) << 2);
1289
1290 while (!size && retries < 10) {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001291 u32 time = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001292 /*looping more secure*/
1293 /*zero size make a crashe because the dma will not happen and that will block the firmware*/
1294 wilc_debug(N_ERR, "RX Size equal zero ... Trying to read it again for %d time\n", time++);
1295 p->hif_func.hif_read_size(&size);
1296 size = ((size & 0x7fff) << 2);
1297 retries++;
1298
1299 }
1300
1301 if (size > 0) {
1302#ifdef MEMORY_STATIC
Glen Lee03eb7262015-09-24 18:15:03 +09001303 if (LINUX_RX_SIZE - offset < size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001304 offset = 0;
1305
1306 if (p->rx_buffer)
1307 buffer = &p->rx_buffer[offset];
1308 else {
1309 wilc_debug(N_ERR, "[wilc isr]: fail Rx Buffer is NULL...drop the packets (%d)\n", size);
1310 goto _end_;
1311 }
1312
1313#else
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001314 buffer = kmalloc(size, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001315 if (buffer == NULL) {
1316 wilc_debug(N_ERR, "[wilc isr]: fail alloc host memory...drop the packets (%d)\n", size);
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -07001317 usleep_range(100 * 1000, 100 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001318 goto _end_;
1319 }
1320#endif
1321
1322 /**
1323 * clear the chip's interrupt after getting size some register getting corrupted after clear the interrupt
1324 **/
1325 p->hif_func.hif_clear_int_ext(DATA_INT_CLR | ENABLE_RX_VMM);
1326
1327
1328 /**
1329 * start transfer
1330 **/
1331 ret = p->hif_func.hif_block_rx_ext(0, buffer, size);
1332
1333 if (!ret) {
1334 wilc_debug(N_ERR, "[wilc isr]: fail block rx...\n");
1335 goto _end_;
1336 }
1337_end_:
1338
1339
1340 if (ret) {
1341#ifdef MEMORY_STATIC
1342 offset += size;
1343 p->rx_buffer_offset = offset;
1344#endif
1345 /**
1346 * add to rx queue
1347 **/
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001348 rqe = kmalloc(sizeof(struct rxq_entry_t), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001349 if (rqe != NULL) {
1350 rqe->buffer = buffer;
1351 rqe->buffer_size = size;
1352 PRINT_D(RX_DBG, "rxq entery Size= %d - Address = %p\n", rqe->buffer_size, rqe->buffer);
1353 wilc_wlan_rxq_add(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001354 }
1355 } else {
1356#ifndef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001357 kfree(buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001358#endif
1359 }
1360 }
Glen Lee39ce4d32015-10-27 18:27:42 +09001361 wilc_wlan_handle_rxq(wilc);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001362}
1363
Glen Lee50b929e2015-10-27 18:27:40 +09001364void wilc_handle_isr(void *wilc)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001365{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001366 u32 int_status;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001367
1368 acquire_bus(ACQUIRE_AND_WAKEUP);
1369 g_wlan.hif_func.hif_read_int(&int_status);
1370
Alison Schofield39823a52015-10-08 21:18:03 -07001371 if (int_status & PLL_INT_EXT)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001372 wilc_pllupdate_isr_ext(int_status);
Alison Schofield39823a52015-10-08 21:18:03 -07001373
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001374 if (int_status & DATA_INT_EXT) {
Glen Lee3bcd45b2015-10-27 18:27:41 +09001375 wilc_wlan_handle_isr_ext(wilc, int_status);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001376 #ifndef WILC_OPTIMIZE_SLEEP_INT
1377 /* Chip is up and talking*/
1378 genuChipPSstate = CHIP_WAKEDUP;
1379 #endif
1380 }
Alison Schofield39823a52015-10-08 21:18:03 -07001381 if (int_status & SLEEP_INT_EXT)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001382 wilc_sleeptimer_isr_ext(int_status);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001383
1384 if (!(int_status & (ALL_INT_EXT))) {
1385#ifdef WILC_SDIO
1386 PRINT_D(TX_DBG, ">> UNKNOWN_INTERRUPT - 0x%08x\n", int_status);
1387#endif
1388 wilc_unknown_isr_ext();
1389 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001390 release_bus(RELEASE_ALLOW_SLEEP);
1391}
1392
1393/********************************************
1394 *
1395 * Firmware download
1396 *
1397 ********************************************/
Glen Lee63d7ab82015-10-01 16:03:32 +09001398int wilc_wlan_firmware_download(const u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001399{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301400 wilc_wlan_dev_t *p = &g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001401 u32 offset;
1402 u32 addr, size, size2, blksz;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001403 u8 *dma_buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001404 int ret = 0;
1405
Anish Bhattffda2032015-09-29 12:15:49 -07001406 blksz = BIT(12);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001407 /* Allocate a DMA coherent buffer. */
1408
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001409 dma_buffer = kmalloc(blksz, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001410 if (dma_buffer == NULL) {
1411 /*EIO 5*/
1412 ret = -5;
1413 PRINT_ER("Can't allocate buffer for firmware download IO error\n ");
1414 goto _fail_1;
1415 }
1416
1417 PRINT_D(INIT_DBG, "Downloading firmware size = %d ...\n", buffer_size);
1418 /**
1419 * load the firmware
1420 **/
1421 offset = 0;
1422 do {
1423 memcpy(&addr, &buffer[offset], 4);
1424 memcpy(&size, &buffer[offset + 4], 4);
1425#ifdef BIG_ENDIAN
1426 addr = BYTE_SWAP(addr);
1427 size = BYTE_SWAP(size);
1428#endif
1429 acquire_bus(ACQUIRE_ONLY);
1430 offset += 8;
1431 while (((int)size) && (offset < buffer_size)) {
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301432 if (size <= blksz)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001433 size2 = size;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301434 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001435 size2 = blksz;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001436 /* Copy firmware into a DMA coherent buffer */
1437 memcpy(dma_buffer, &buffer[offset], size2);
1438 ret = p->hif_func.hif_block_tx(addr, dma_buffer, size2);
1439 if (!ret)
1440 break;
1441
1442 addr += size2;
1443 offset += size2;
1444 size -= size2;
1445 }
1446 release_bus(RELEASE_ONLY);
1447
1448 if (!ret) {
1449 /*EIO 5*/
1450 ret = -5;
1451 PRINT_ER("Can't download firmware IO error\n ");
1452 goto _fail_;
1453 }
1454 PRINT_D(INIT_DBG, "Offset = %d\n", offset);
1455 } while (offset < buffer_size);
1456
1457_fail_:
1458
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001459 kfree(dma_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001460
1461_fail_1:
1462
1463 return (ret < 0) ? ret : 0;
1464}
1465
1466/********************************************
1467 *
1468 * Common
1469 *
1470 ********************************************/
Glen Leee42563b2015-10-01 16:03:33 +09001471int wilc_wlan_start(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001472{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301473 wilc_wlan_dev_t *p = &g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001474 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001475 int ret;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001476 u32 chipid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001477
1478 /**
1479 * Set the host interface
1480 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001481 if (p->io_func.io_type == HIF_SDIO) {
1482 reg = 0;
Anish Bhattffda2032015-09-29 12:15:49 -07001483 reg |= BIT(3); /* bug 4456 and 4557 */
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001484 } else if (p->io_func.io_type == HIF_SPI) {
1485 reg = 1;
1486 }
1487 acquire_bus(ACQUIRE_ONLY);
1488 ret = p->hif_func.hif_write_reg(WILC_VMM_CORE_CFG, reg);
1489 if (!ret) {
1490 wilc_debug(N_ERR, "[wilc start]: fail write reg vmm_core_cfg...\n");
1491 release_bus(RELEASE_ONLY);
1492 /* EIO 5*/
1493 ret = -5;
1494 return ret;
1495 }
1496 reg = 0;
1497#ifdef WILC_SDIO_IRQ_GPIO
1498 reg |= WILC_HAVE_SDIO_IRQ_GPIO;
1499#endif
1500
1501#ifdef WILC_DISABLE_PMU
1502#else
1503 reg |= WILC_HAVE_USE_PMU;
1504#endif
1505
1506#ifdef WILC_SLEEP_CLK_SRC_XO
1507 reg |= WILC_HAVE_SLEEP_CLK_SRC_XO;
1508#elif defined WILC_SLEEP_CLK_SRC_RTC
1509 reg |= WILC_HAVE_SLEEP_CLK_SRC_RTC;
1510#endif
1511
1512#ifdef WILC_EXT_PA_INV_TX_RX
1513 reg |= WILC_HAVE_EXT_PA_INV_TX_RX;
1514#endif
1515
1516 reg |= WILC_HAVE_LEGACY_RF_SETTINGS;
1517
1518
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001519/*Set oscillator frequency*/
1520#ifdef XTAL_24
1521 reg |= WILC_HAVE_XTAL_24;
1522#endif
1523
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001524/*Enable/Disable GPIO configuration for FW logs*/
1525#ifdef DISABLE_WILC_UART
1526 reg |= WILC_HAVE_DISABLE_WILC_UART;
1527#endif
1528
1529 ret = p->hif_func.hif_write_reg(WILC_GP_REG_1, reg);
1530 if (!ret) {
1531 wilc_debug(N_ERR, "[wilc start]: fail write WILC_GP_REG_1 ...\n");
1532 release_bus(RELEASE_ONLY);
1533 /* EIO 5*/
1534 ret = -5;
1535 return ret;
1536 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001537
1538 /**
1539 * Bus related
1540 **/
1541 p->hif_func.hif_sync_ext(NUM_INT_EXT);
1542
1543 ret = p->hif_func.hif_read_reg(0x1000, &chipid);
1544 if (!ret) {
1545 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1000 ...\n");
1546 release_bus(RELEASE_ONLY);
1547 /* EIO 5*/
1548 ret = -5;
1549 return ret;
1550 }
1551
1552 /**
1553 * Go...
1554 **/
1555
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001556
1557 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -07001558 if ((reg & BIT(10)) == BIT(10)) {
1559 reg &= ~BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001560 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1561 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1562 }
1563
Anish Bhattffda2032015-09-29 12:15:49 -07001564 reg |= BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001565 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1566 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1567 release_bus(RELEASE_ONLY);
1568
1569 return (ret < 0) ? ret : 0;
1570}
1571
1572void wilc_wlan_global_reset(void)
1573{
1574
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301575 wilc_wlan_dev_t *p = &g_wlan;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001576
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001577 acquire_bus(ACQUIRE_AND_WAKEUP);
1578 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, 0x0);
1579 release_bus(RELEASE_ONLY);
1580}
Glen Lee8cec7412015-10-01 16:03:34 +09001581int wilc_wlan_stop(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001582{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301583 wilc_wlan_dev_t *p = &g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001584 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001585 int ret;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001586 u8 timeout = 10;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001587 /**
1588 * TODO: stop the firmware, need a re-download
1589 **/
1590 acquire_bus(ACQUIRE_AND_WAKEUP);
1591
1592 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1593 if (!ret) {
1594 PRINT_ER("Error while reading reg\n");
1595 release_bus(RELEASE_ALLOW_SLEEP);
1596 return ret;
1597 }
1598
Anish Bhattffda2032015-09-29 12:15:49 -07001599 reg &= ~BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001600
1601
1602 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1603 if (!ret) {
1604 PRINT_ER("Error while writing reg\n");
1605 release_bus(RELEASE_ALLOW_SLEEP);
1606 return ret;
1607 }
1608
1609
1610
1611 do {
1612 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1613 if (!ret) {
1614 PRINT_ER("Error while reading reg\n");
1615 release_bus(RELEASE_ALLOW_SLEEP);
1616 return ret;
1617 }
1618 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1619 /*Workaround to ensure that the chip is actually reset*/
Anish Bhattffda2032015-09-29 12:15:49 -07001620 if ((reg & BIT(10))) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001621 PRINT_D(GENERIC_DBG, "Bit 10 not reset : Retry %d\n", timeout);
Anish Bhattffda2032015-09-29 12:15:49 -07001622 reg &= ~BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001623 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1624 timeout--;
1625 } else {
1626 PRINT_D(GENERIC_DBG, "Bit 10 reset after : Retry %d\n", timeout);
1627 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1628 if (!ret) {
1629 PRINT_ER("Error while reading reg\n");
1630 release_bus(RELEASE_ALLOW_SLEEP);
1631 return ret;
1632 }
1633 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1634 break;
1635 }
1636
1637 } while (timeout);
Anish Bhattffda2032015-09-29 12:15:49 -07001638 reg = (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(8) | BIT(9) | BIT(26) |
1639 BIT(29) | BIT(30) | BIT(31));
Anish Bhatt65ead4e2015-09-29 12:15:48 -07001640
1641 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
Anish Bhattffda2032015-09-29 12:15:49 -07001642 reg = (u32)~BIT(10);
Anish Bhatt65ead4e2015-09-29 12:15:48 -07001643
1644 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001645
1646 release_bus(RELEASE_ALLOW_SLEEP);
1647
1648 return ret;
1649}
1650
Glen Leea17e2ec2015-10-01 16:03:38 +09001651void wilc_wlan_cleanup(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001652{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301653 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001654 struct txq_entry_t *tqe;
1655 struct rxq_entry_t *rqe;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001656 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001657 int ret;
1658
1659 p->quit = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001660 do {
1661 tqe = wilc_wlan_txq_remove_from_head();
1662 if (tqe == NULL)
1663 break;
1664 if (tqe->tx_complete_func)
1665 tqe->tx_complete_func(tqe->priv, 0);
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001666 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001667 } while (1);
1668
1669 do {
1670 rqe = wilc_wlan_rxq_remove();
1671 if (rqe == NULL)
1672 break;
Javier Martinez Canillas6a272242015-09-22 15:24:50 +02001673#ifndef MEMORY_STATIC
1674 kfree(rqe->buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001675#endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001676 kfree(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001677 } while (1);
1678
1679 /**
1680 * clean up buffer
1681 **/
1682
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001683 #ifdef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001684 kfree(p->rx_buffer);
1685 p->rx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001686 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001687 kfree(p->tx_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001688
1689 acquire_bus(ACQUIRE_AND_WAKEUP);
1690
1691
1692 ret = p->hif_func.hif_read_reg(WILC_GP_REG_0, &reg);
1693 if (!ret) {
1694 PRINT_ER("Error while reading reg\n");
1695 release_bus(RELEASE_ALLOW_SLEEP);
1696 }
1697 PRINT_ER("Writing ABORT reg\n");
1698 ret = p->hif_func.hif_write_reg(WILC_GP_REG_0, (reg | ABORT_INT));
1699 if (!ret) {
1700 PRINT_ER("Error while writing reg\n");
1701 release_bus(RELEASE_ALLOW_SLEEP);
1702 }
1703 release_bus(RELEASE_ALLOW_SLEEP);
1704 /**
1705 * io clean up
1706 **/
1707 p->hif_func.hif_deinit(NULL);
1708
1709}
1710
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001711static int wilc_wlan_cfg_commit(int type, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001712{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301713 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001714 wilc_cfg_frame_t *cfg = &p->cfg_frame;
1715 int total_len = p->cfg_frame_offset + 4 + DRIVER_HANDLER_SIZE;
1716 int seq_no = p->cfg_seq_no % 256;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001717 int driver_handler = (u32)drvHandler;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001718
1719
1720 /**
1721 * Set up header
1722 **/
1723 if (type == WILC_CFG_SET) { /* Set */
1724 cfg->wid_header[0] = 'W';
1725 } else { /* Query */
1726 cfg->wid_header[0] = 'Q';
1727 }
1728 cfg->wid_header[1] = seq_no; /* sequence number */
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001729 cfg->wid_header[2] = (u8)total_len;
1730 cfg->wid_header[3] = (u8)(total_len >> 8);
1731 cfg->wid_header[4] = (u8)driver_handler;
1732 cfg->wid_header[5] = (u8)(driver_handler >> 8);
1733 cfg->wid_header[6] = (u8)(driver_handler >> 16);
1734 cfg->wid_header[7] = (u8)(driver_handler >> 24);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001735 p->cfg_seq_no = seq_no;
1736
1737 /**
1738 * Add to TX queue
1739 **/
1740
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001741 if (!wilc_wlan_txq_add_cfg_pkt(&cfg->wid_header[0], total_len))
1742 return -1;
1743
1744 return 0;
1745}
1746
Glen Lee1028e5a2015-10-01 16:03:40 +09001747int wilc_wlan_cfg_set(int start, u32 wid, u8 *buffer, u32 buffer_size,
1748 int commit, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001749{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301750 wilc_wlan_dev_t *p = &g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001751 u32 offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001752 int ret_size;
1753
1754
1755 if (p->cfg_frame_in_use)
1756 return 0;
1757
1758 if (start)
1759 p->cfg_frame_offset = 0;
1760
1761 offset = p->cfg_frame_offset;
Glen Lee17e8f162015-10-02 14:22:07 +09001762 ret_size = wilc_wlan_cfg_set_wid(p->cfg_frame.frame, offset, (u16)wid,
1763 buffer, buffer_size);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001764 offset += ret_size;
1765 p->cfg_frame_offset = offset;
1766
1767 if (commit) {
1768 PRINT_D(TX_DBG, "[WILC]PACKET Commit with sequence number %d\n", p->cfg_seq_no);
1769 PRINT_D(RX_DBG, "Processing cfg_set()\n");
1770 p->cfg_frame_in_use = 1;
1771
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001772 if (wilc_wlan_cfg_commit(WILC_CFG_SET, drvHandler))
Chaehyun Lim5af6b852015-09-17 16:48:48 +09001773 ret_size = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001774
Glen Leeb002e202015-09-24 18:15:05 +09001775 if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event,
1776 CFG_PKTS_TIMEOUT)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001777 PRINT_D(TX_DBG, "Set Timed Out\n");
1778 ret_size = 0;
1779 }
1780 p->cfg_frame_in_use = 0;
1781 p->cfg_frame_offset = 0;
1782 p->cfg_seq_no += 1;
1783
1784 }
1785
1786 return ret_size;
1787}
Glen Lee07056a82015-10-01 16:03:41 +09001788int wilc_wlan_cfg_get(int start, u32 wid, int commit, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001789{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301790 wilc_wlan_dev_t *p = &g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001791 u32 offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001792 int ret_size;
1793
1794
1795 if (p->cfg_frame_in_use)
1796 return 0;
1797
1798 if (start)
1799 p->cfg_frame_offset = 0;
1800
1801 offset = p->cfg_frame_offset;
Glen Leeec1b86b2015-10-02 14:22:08 +09001802 ret_size = wilc_wlan_cfg_get_wid(p->cfg_frame.frame, offset, (u16)wid);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001803 offset += ret_size;
1804 p->cfg_frame_offset = offset;
1805
1806 if (commit) {
1807 p->cfg_frame_in_use = 1;
1808
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001809 if (wilc_wlan_cfg_commit(WILC_CFG_QUERY, drvHandler))
Chaehyun Lim5af6b852015-09-17 16:48:48 +09001810 ret_size = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001811
1812
Glen Leeb002e202015-09-24 18:15:05 +09001813 if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event,
1814 CFG_PKTS_TIMEOUT)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001815 PRINT_D(TX_DBG, "Get Timed Out\n");
1816 ret_size = 0;
1817 }
1818 PRINT_D(GENERIC_DBG, "[WILC]Get Response received\n");
1819 p->cfg_frame_in_use = 0;
1820 p->cfg_frame_offset = 0;
1821 p->cfg_seq_no += 1;
1822 }
1823
1824 return ret_size;
1825}
1826
Glen Lee894de36b2015-10-01 16:03:42 +09001827int wilc_wlan_cfg_get_val(u32 wid, u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001828{
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001829 int ret;
1830
Glen Lee355cca22015-10-02 14:22:09 +09001831 ret = wilc_wlan_cfg_get_wid_value((u16)wid, buffer, buffer_size);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001832
1833 return ret;
1834}
1835
1836void wilc_bus_set_max_speed(void)
1837{
1838
1839 /* Increase bus speed to max possible. */
1840 g_wlan.hif_func.hif_set_max_bus_speed();
1841}
1842
1843void wilc_bus_set_default_speed(void)
1844{
1845
1846 /* Restore bus speed to default. */
1847 g_wlan.hif_func.hif_set_default_bus_speed();
1848}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001849u32 init_chip(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001850{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001851 u32 chipid;
1852 u32 reg, ret = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001853
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001854 acquire_bus(ACQUIRE_ONLY);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001855
Dean Lee72ed4dc2015-06-12 14:11:44 +09001856 chipid = wilc_get_chipid(true);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001857
1858
1859
1860 if ((chipid & 0xfff) != 0xa0) {
1861 /**
1862 * Avoid booting from boot ROM. Make sure that Drive IRQN [SDIO platform]
1863 * or SD_DAT3 [SPI platform] to ?1?
1864 **/
1865 /* Set cortus reset register to register control. */
1866 ret = g_wlan.hif_func.hif_read_reg(0x1118, &reg);
1867 if (!ret) {
1868 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1118 ...\n");
1869 return ret;
1870 }
Anish Bhattffda2032015-09-29 12:15:49 -07001871 reg |= BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001872 ret = g_wlan.hif_func.hif_write_reg(0x1118, reg);
1873 if (!ret) {
1874 wilc_debug(N_ERR, "[wilc start]: fail write reg 0x1118 ...\n");
1875 return ret;
1876 }
1877 /**
1878 * Write branch intruction to IRAM (0x71 trap) at location 0xFFFF0000
1879 * (Cortus map) or C0000 (AHB map).
1880 **/
1881 ret = g_wlan.hif_func.hif_write_reg(0xc0000, 0x71);
1882 if (!ret) {
1883 wilc_debug(N_ERR, "[wilc start]: fail write reg 0xc0000 ...\n");
1884 return ret;
1885 }
1886 }
1887
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001888 release_bus(RELEASE_ONLY);
1889
1890 return ret;
1891
1892}
1893
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001894u32 wilc_get_chipid(u8 update)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001895{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001896 static u32 chipid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001897 /* SDIO can't read into global variables */
1898 /* Use this variable as a temp, then copy to the global */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001899 u32 tempchipid = 0;
1900 u32 rfrevid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001901
1902 if (chipid == 0 || update != 0) {
1903 g_wlan.hif_func.hif_read_reg(0x1000, &tempchipid);
1904 g_wlan.hif_func.hif_read_reg(0x13f4, &rfrevid);
1905 if (!ISWILC1000(tempchipid)) {
1906 chipid = 0;
1907 goto _fail_;
1908 }
1909 if (tempchipid == 0x1002a0) {
1910 if (rfrevid == 0x1) { /* 1002A0 */
1911 } else { /* if (rfrevid == 0x2) */ /* 1002A1 */
1912 tempchipid = 0x1002a1;
1913 }
1914 } else if (tempchipid == 0x1002b0) {
1915 if (rfrevid == 3) { /* 1002B0 */
1916 } else if (rfrevid == 4) { /* 1002B1 */
1917 tempchipid = 0x1002b1;
1918 } else { /* if(rfrevid == 5) */ /* 1002B2 */
1919 tempchipid = 0x1002b2;
1920 }
1921 } else {
1922 }
1923
1924 chipid = tempchipid;
1925 }
1926_fail_:
1927 return chipid;
1928}
1929
Glen Leec9d48342015-10-01 16:03:43 +09001930int wilc_wlan_init(wilc_wlan_inp_t *inp)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001931{
1932
1933 int ret = 0;
1934
1935 PRINT_D(INIT_DBG, "Initializing WILC_Wlan ...\n");
1936
1937 memset((void *)&g_wlan, 0, sizeof(wilc_wlan_dev_t));
1938
1939 /**
1940 * store the input
1941 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001942 memcpy((void *)&g_wlan.io_func, (void *)&inp->io_func, sizeof(wilc_wlan_io_func_t));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001943 /***
1944 * host interface init
1945 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001946 if ((inp->io_func.io_type & 0x1) == HIF_SDIO) {
1947 if (!hif_sdio.hif_init(inp, wilc_debug)) {
1948 /* EIO 5 */
1949 ret = -5;
1950 goto _fail_;
1951 }
1952 memcpy((void *)&g_wlan.hif_func, &hif_sdio, sizeof(wilc_hif_func_t));
1953 } else {
1954 if ((inp->io_func.io_type & 0x1) == HIF_SPI) {
1955 /**
1956 * TODO:
1957 **/
1958 if (!hif_spi.hif_init(inp, wilc_debug)) {
1959 /* EIO 5 */
1960 ret = -5;
1961 goto _fail_;
1962 }
1963 memcpy((void *)&g_wlan.hif_func, &hif_spi, sizeof(wilc_hif_func_t));
1964 } else {
1965 /* EIO 5 */
1966 ret = -5;
1967 goto _fail_;
1968 }
1969 }
1970
1971 /***
1972 * mac interface init
1973 **/
Glen Lee814bc362015-10-02 14:22:11 +09001974 if (!wilc_wlan_cfg_init(wilc_debug)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001975 /* ENOBUFS 105 */
1976 ret = -105;
1977 goto _fail_;
1978 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001979
1980 /**
1981 * alloc tx, rx buffer
1982 **/
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09001983 if (g_wlan.tx_buffer == NULL)
Glen Lee7015b5d2015-09-24 18:15:02 +09001984 g_wlan.tx_buffer = kmalloc(LINUX_TX_SIZE, GFP_KERNEL);
Arnd Bergmann7a8fd842015-06-01 21:06:45 +02001985 PRINT_D(TX_DBG, "g_wlan.tx_buffer = %p\n", g_wlan.tx_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001986
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09001987 if (g_wlan.tx_buffer == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001988 /* ENOBUFS 105 */
1989 ret = -105;
1990 PRINT_ER("Can't allocate Tx Buffer");
1991 goto _fail_;
1992 }
1993
1994/* rx_buffer is not used unless we activate USE_MEM STATIC which is not applicable, allocating such memory is useless*/
1995#if defined (MEMORY_STATIC)
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09001996 if (g_wlan.rx_buffer == NULL)
Glen Lee03eb7262015-09-24 18:15:03 +09001997 g_wlan.rx_buffer = kmalloc(LINUX_RX_SIZE, GFP_KERNEL);
Arnd Bergmann7a8fd842015-06-01 21:06:45 +02001998 PRINT_D(TX_DBG, "g_wlan.rx_buffer =%p\n", g_wlan.rx_buffer);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09001999 if (g_wlan.rx_buffer == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002000 /* ENOBUFS 105 */
2001 ret = -105;
2002 PRINT_ER("Can't allocate Rx Buffer");
2003 goto _fail_;
2004 }
2005#endif
2006
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002007 if (!init_chip()) {
2008 /* EIO 5 */
2009 ret = -5;
2010 goto _fail_;
2011 }
2012#ifdef TCP_ACK_FILTER
2013 Init_TCP_tracking();
2014#endif
2015
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002016 return 1;
2017
2018_fail_:
2019
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002020 #ifdef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07002021 kfree(g_wlan.rx_buffer);
2022 g_wlan.rx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002023 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07002024 kfree(g_wlan.tx_buffer);
2025 g_wlan.tx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002026
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002027 return ret;
2028
2029}
2030
Dean Lee72ed4dc2015-06-12 14:11:44 +09002031u16 Set_machw_change_vir_if(bool bValue)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002032{
Chaehyun Limd85f5322015-06-11 14:35:54 +09002033 u16 ret;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002034 u32 reg;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002035
2036 /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
Glen Lee187f1ef2015-09-24 18:15:01 +09002037 mutex_lock(&g_linux_wlan->hif_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002038 ret = (&g_wlan)->hif_func.hif_read_reg(WILC_CHANGING_VIR_IF, &reg);
Alison Schofield39823a52015-10-08 21:18:03 -07002039 if (!ret)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002040 PRINT_ER("Error while Reading reg WILC_CHANGING_VIR_IF\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002041
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05302042 if (bValue)
Chaehyun Lim50b51da2015-09-16 20:11:26 +09002043 reg |= BIT(31);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05302044 else
Chaehyun Lim50b51da2015-09-16 20:11:26 +09002045 reg &= ~BIT(31);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002046
2047 ret = (&g_wlan)->hif_func.hif_write_reg(WILC_CHANGING_VIR_IF, reg);
2048
Alison Schofield39823a52015-10-08 21:18:03 -07002049 if (!ret)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002050 PRINT_ER("Error while writing reg WILC_CHANGING_VIR_IF\n");
Alison Schofield39823a52015-10-08 21:18:03 -07002051
Glen Lee187f1ef2015-09-24 18:15:01 +09002052 mutex_unlock(&g_linux_wlan->hif_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002053
2054 return ret;
2055}