blob: 03593b7e50e23c6f78457e564f3302345a3a37f7 [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 +090021u32 wilc_get_chipid(u8 update);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090022
Johnny Kimc5c77ba2015-05-11 14:30:56 +090023
24
25typedef struct {
26 int quit;
27
28 /**
29 * input interface functions
30 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +090031 wilc_wlan_io_func_t io_func;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090032
33 /**
34 * host interface functions
35 **/
36 wilc_hif_func_t hif_func;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090037
38 /**
39 * configuration interface functions
40 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +090041 int cfg_frame_in_use;
42 wilc_cfg_frame_t cfg_frame;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090043 u32 cfg_frame_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090044 int cfg_seq_no;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090045
46 /**
47 * RX buffer
48 **/
49 #ifdef MEMORY_STATIC
Chaehyun Lim51e825f2015-09-15 14:06:14 +090050 u8 *rx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090051 u32 rx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090052 #endif
53 /**
54 * TX buffer
55 **/
Chaehyun Lim51e825f2015-09-15 14:06:14 +090056 u8 *tx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090057 u32 tx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090058
59 /**
60 * TX queue
61 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +090062
Johnny Kimc5c77ba2015-05-11 14:30:56 +090063 unsigned long txq_spinlock_flags;
64
65 struct txq_entry_t *txq_head;
66 struct txq_entry_t *txq_tail;
67 int txq_entries;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090068 int txq_exit;
69
70 /**
71 * RX queue
72 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +090073 struct rxq_entry_t *rxq_head;
74 struct rxq_entry_t *rxq_tail;
75 int rxq_entries;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090076 int rxq_exit;
77
78
79} wilc_wlan_dev_t;
80
81static wilc_wlan_dev_t g_wlan;
82
Chaehyun Lim9af382b2015-09-16 20:11:27 +090083static inline void chip_allow_sleep(void);
84static inline void chip_wakeup(void);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090085/********************************************
86 *
87 * Debug
88 *
89 ********************************************/
90
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090091static u32 dbgflag = N_INIT | N_ERR | N_INTR | N_TXQ | N_RXQ;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090092
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090093static void wilc_debug(u32 flag, char *fmt, ...)
Johnny Kimc5c77ba2015-05-11 14:30:56 +090094{
95 char buf[256];
96 va_list args;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090097
98 if (flag & dbgflag) {
99 va_start(args, fmt);
Hari Prasath Gujulan Elango81053222015-06-22 13:13:58 +0000100 vsprintf(buf, fmt, args);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900101 va_end(args);
102
Glen Leeef2b7842015-09-24 18:14:55 +0900103 linux_wlan_dbg(buf);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900104 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900105}
106
107static CHIP_PS_STATE_T genuChipPSstate = CHIP_WAKEDUP;
108
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900109/*acquire_bus() and release_bus() are made static inline functions*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900110/*as a temporary workaround to fix a problem of receiving*/
111/*unknown interrupt from FW*/
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900112static inline void acquire_bus(BUS_ACQUIRE_T acquire)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900113{
114
Glen Lee187f1ef2015-09-24 18:15:01 +0900115 mutex_lock(&g_linux_wlan->hif_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900116 #ifndef WILC_OPTIMIZE_SLEEP_INT
117 if (genuChipPSstate != CHIP_WAKEDUP)
118 #endif
119 {
120 if (acquire == ACQUIRE_AND_WAKEUP)
121 chip_wakeup();
122 }
123
124}
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900125static inline void release_bus(BUS_RELEASE_T release)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900126{
127 #ifdef WILC_OPTIMIZE_SLEEP_INT
128 if (release == RELEASE_ALLOW_SLEEP)
129 chip_allow_sleep();
130 #endif
Glen Lee187f1ef2015-09-24 18:15:01 +0900131 mutex_unlock(&g_linux_wlan->hif_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900132}
133/********************************************
134 *
135 * Queue
136 *
137 ********************************************/
138
139static void wilc_wlan_txq_remove(struct txq_entry_t *tqe)
140{
141
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530142 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900143 if (tqe == p->txq_head) {
144
145 p->txq_head = tqe->next;
146 if (p->txq_head)
147 p->txq_head->prev = NULL;
148
149
150 } else if (tqe == p->txq_tail) {
151 p->txq_tail = (tqe->prev);
152 if (p->txq_tail)
153 p->txq_tail->next = NULL;
154 } else {
155 tqe->prev->next = tqe->next;
156 tqe->next->prev = tqe->prev;
157 }
158 p->txq_entries -= 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900159
160}
161
Glen Lee718fc2c2015-10-29 12:18:43 +0900162static struct txq_entry_t *
163wilc_wlan_txq_remove_from_head(struct net_device *dev)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900164{
165 struct txq_entry_t *tqe;
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530166 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900167 unsigned long flags;
Glen Lee718fc2c2015-10-29 12:18:43 +0900168 perInterface_wlan_t *nic;
169 struct wilc *wilc;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900170
Glen Lee718fc2c2015-10-29 12:18:43 +0900171 nic = netdev_priv(dev);
172 wilc = nic->wilc;
173
174 spin_lock_irqsave(&wilc->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900175 if (p->txq_head) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900176 tqe = p->txq_head;
177 p->txq_head = tqe->next;
Alison Schofield39823a52015-10-08 21:18:03 -0700178 if (p->txq_head)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900179 p->txq_head->prev = NULL;
Alison Schofield39823a52015-10-08 21:18:03 -0700180
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900181 p->txq_entries -= 1;
182
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900183
184
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900185
186 } else {
187 tqe = NULL;
188 }
Glen Lee718fc2c2015-10-29 12:18:43 +0900189 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900190 return tqe;
191}
192
Glen Lee32f03322015-10-29 12:18:45 +0900193static void wilc_wlan_txq_add_to_tail(struct net_device *dev,
194 struct txq_entry_t *tqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900195{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530196 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900197 unsigned long flags;
Glen Lee32f03322015-10-29 12:18:45 +0900198 perInterface_wlan_t *nic;
199 struct wilc *wilc;
200
201 nic = netdev_priv(dev);
202 wilc = nic->wilc;
203
204 spin_lock_irqsave(&wilc->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900205
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900206 if (p->txq_head == NULL) {
207 tqe->next = NULL;
208 tqe->prev = NULL;
209 p->txq_head = tqe;
210 p->txq_tail = tqe;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900211 } else {
212 tqe->next = NULL;
213 tqe->prev = p->txq_tail;
214 p->txq_tail->next = tqe;
215 p->txq_tail = tqe;
216 }
217 p->txq_entries += 1;
218 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900219
Glen Lee32f03322015-10-29 12:18:45 +0900220 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900221
222 /**
223 * wake up TX queue
224 **/
225 PRINT_D(TX_DBG, "Wake the txq_handling\n");
226
Glen Lee32f03322015-10-29 12:18:45 +0900227 up(&wilc->txq_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900228}
229
230static int wilc_wlan_txq_add_to_head(struct txq_entry_t *tqe)
231{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530232 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900233 unsigned long flags;
Glen Leeb002e202015-09-24 18:15:05 +0900234 if (linux_wlan_lock_timeout(&g_linux_wlan->txq_add_to_head_cs,
235 CFG_PKTS_TIMEOUT))
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900236 return -1;
237
Glen Lee85e57562015-09-24 18:14:56 +0900238 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900239
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900240 if (p->txq_head == NULL) {
241 tqe->next = NULL;
242 tqe->prev = NULL;
243 p->txq_head = tqe;
244 p->txq_tail = tqe;
245 } else {
246 tqe->next = p->txq_head;
247 tqe->prev = NULL;
248 p->txq_head->prev = tqe;
249 p->txq_head = tqe;
250 }
251 p->txq_entries += 1;
252 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900253
Glen Lee85e57562015-09-24 18:14:56 +0900254 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Glen Leed5a63a82015-09-24 18:15:00 +0900255 up(&g_linux_wlan->txq_add_to_head_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900256
257
258 /**
259 * wake up TX queue
260 **/
Glen Lee5cd63632015-09-24 18:14:58 +0900261 up(&g_linux_wlan->txq_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900262 PRINT_D(TX_DBG, "Wake up the txq_handler\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900263
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900264 return 0;
265
266}
267
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900268u32 Statisitcs_totalAcks = 0, Statisitcs_DroppedAcks = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900269
270#ifdef TCP_ACK_FILTER
271struct Ack_session_info;
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530272struct Ack_session_info {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900273 u32 Ack_seq_num;
274 u32 Bigger_Ack_num;
Chaehyun Limec53adf2015-09-15 14:06:15 +0900275 u16 src_port;
276 u16 dst_port;
277 u16 status;
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530278};
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900279
280typedef struct {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900281 u32 ack_num;
282 u32 Session_index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900283 struct txq_entry_t *txqe;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900284} Pending_Acks_info_t /*Ack_info_t*/;
285
286
287
288
289struct Ack_session_info *Free_head;
290struct Ack_session_info *Alloc_head;
291
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900292#define NOT_TCP_ACK (-1)
293
294#define MAX_TCP_SESSION 25
295#define MAX_PENDING_ACKS 256
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530296struct Ack_session_info Acks_keep_track_info[2 * MAX_TCP_SESSION];
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900297Pending_Acks_info_t Pending_Acks_info[MAX_PENDING_ACKS];
298
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900299u32 PendingAcks_arrBase;
300u32 Opened_TCP_session;
301u32 Pending_Acks;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900302
303
304
Chaehyun Limfed16f22015-09-17 16:48:43 +0900305static inline int Init_TCP_tracking(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900306{
307
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900308 return 0;
309
310}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900311static inline int add_TCP_track_session(u32 src_prt, u32 dst_prt, u32 seq)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900312{
313 Acks_keep_track_info[Opened_TCP_session].Ack_seq_num = seq;
314 Acks_keep_track_info[Opened_TCP_session].Bigger_Ack_num = 0;
315 Acks_keep_track_info[Opened_TCP_session].src_port = src_prt;
316 Acks_keep_track_info[Opened_TCP_session].dst_port = dst_prt;
317 Opened_TCP_session++;
318
319 PRINT_D(TCP_ENH, "TCP Session %d to Ack %d\n", Opened_TCP_session, seq);
320 return 0;
321}
322
Chaehyun Limfed16f22015-09-17 16:48:43 +0900323static inline int Update_TCP_track_session(u32 index, u32 Ack)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900324{
325
Alison Schofield39823a52015-10-08 21:18:03 -0700326 if (Ack > Acks_keep_track_info[index].Bigger_Ack_num)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900327 Acks_keep_track_info[index].Bigger_Ack_num = Ack;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900328 return 0;
329
330}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900331static inline int add_TCP_Pending_Ack(u32 Ack, u32 Session_index, struct txq_entry_t *txqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900332{
333 Statisitcs_totalAcks++;
334 if (Pending_Acks < MAX_PENDING_ACKS) {
335 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].ack_num = Ack;
336 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].txqe = txqe;
337 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].Session_index = Session_index;
338 txqe->tcp_PendingAck_index = PendingAcks_arrBase + Pending_Acks;
339 Pending_Acks++;
340
341 } else {
342
343 }
344 return 0;
345}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900346static inline int remove_TCP_related(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900347{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530348 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900349 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900350
Glen Lee85e57562015-09-24 18:14:56 +0900351 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900352
Glen Lee85e57562015-09-24 18:14:56 +0900353 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900354 return 0;
355}
356
Glen Lee82bb18e2015-10-27 18:28:03 +0900357static inline int tcp_process(struct net_device *dev, struct txq_entry_t *tqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900358{
359 int ret;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900360 u8 *eth_hdr_ptr;
361 u8 *buffer = tqe->buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900362 unsigned short h_proto;
363 int i;
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530364 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900365 unsigned long flags;
Glen Lee82bb18e2015-10-27 18:28:03 +0900366 perInterface_wlan_t *nic;
367 struct wilc *wilc;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900368
Glen Lee82bb18e2015-10-27 18:28:03 +0900369 nic = netdev_priv(dev);
370 wilc = nic->wilc;
371
372 spin_lock_irqsave(&wilc->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900373
374 eth_hdr_ptr = &buffer[0];
375 h_proto = ntohs(*((unsigned short *)&eth_hdr_ptr[12]));
376 if (h_proto == 0x0800) { /* IP */
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900377 u8 *ip_hdr_ptr;
378 u8 protocol;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900379
380 ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN];
381 protocol = ip_hdr_ptr[9];
382
383
384 if (protocol == 0x06) {
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900385 u8 *tcp_hdr_ptr;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900386 u32 IHL, Total_Length, Data_offset;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900387
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900388 tcp_hdr_ptr = &ip_hdr_ptr[IP_HDR_LEN];
389 IHL = (ip_hdr_ptr[0] & 0xf) << 2;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900390 Total_Length = (((u32)ip_hdr_ptr[2]) << 8) + ((u32)ip_hdr_ptr[3]);
391 Data_offset = (((u32)tcp_hdr_ptr[12] & 0xf0) >> 2);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900392 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 +0900393 u32 seq_no, Ack_no;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900394
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900395 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 +0900396
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900397 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 +0900398
399
400 for (i = 0; i < Opened_TCP_session; i++) {
401 if (Acks_keep_track_info[i].Ack_seq_num == seq_no) {
402 Update_TCP_track_session(i, Ack_no);
403 break;
404 }
405 }
Alison Schofield39823a52015-10-08 21:18:03 -0700406 if (i == Opened_TCP_session)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900407 add_TCP_track_session(0, 0, seq_no);
Alison Schofield39823a52015-10-08 21:18:03 -0700408
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900409 add_TCP_Pending_Ack(Ack_no, i, tqe);
410
411
412 }
413
414 } else {
415 ret = 0;
416 }
417 } else {
418 ret = 0;
419 }
Glen Lee82bb18e2015-10-27 18:28:03 +0900420 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900421 return ret;
422}
423
424
Glen Leec029e992015-10-27 18:27:48 +0900425static int wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900426{
Glen Leec029e992015-10-27 18:27:48 +0900427 perInterface_wlan_t *nic;
428 struct wilc *wilc;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900429 u32 i = 0;
430 u32 Dropped = 0;
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530431 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900432
Glen Leec029e992015-10-27 18:27:48 +0900433 nic = netdev_priv(dev);
434 wilc = nic->wilc;
435
436 spin_lock_irqsave(&wilc->txq_spinlock, p->txq_spinlock_flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900437 for (i = PendingAcks_arrBase; i < (PendingAcks_arrBase + Pending_Acks); i++) {
438 if (Pending_Acks_info[i].ack_num < Acks_keep_track_info[Pending_Acks_info[i].Session_index].Bigger_Ack_num) {
439 struct txq_entry_t *tqe;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900440
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530441 PRINT_D(TCP_ENH, "DROP ACK: %u\n", Pending_Acks_info[i].ack_num);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900442 tqe = Pending_Acks_info[i].txqe;
443 if (tqe) {
444 wilc_wlan_txq_remove(tqe);
445 Statisitcs_DroppedAcks++;
446 tqe->status = 1; /* mark the packet send */
447 if (tqe->tx_complete_func)
448 tqe->tx_complete_func(tqe->priv, tqe->status);
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -0700449 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900450 Dropped++;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900451 }
452 }
453 }
454 Pending_Acks = 0;
455 Opened_TCP_session = 0;
456
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530457 if (PendingAcks_arrBase == 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900458 PendingAcks_arrBase = MAX_TCP_SESSION;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530459 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900460 PendingAcks_arrBase = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900461
462
Glen Leec029e992015-10-27 18:27:48 +0900463 spin_unlock_irqrestore(&wilc->txq_spinlock, p->txq_spinlock_flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900464
465 while (Dropped > 0) {
466 /*consume the semaphore count of the removed packet*/
Glen Leec029e992015-10-27 18:27:48 +0900467 linux_wlan_lock_timeout(&wilc->txq_event, 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900468 Dropped--;
469 }
470
471 return 1;
472}
473#endif
474
Dean Lee72ed4dc2015-06-12 14:11:44 +0900475bool EnableTCPAckFilter = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900476
Dean Lee72ed4dc2015-06-12 14:11:44 +0900477void Enable_TCP_ACK_Filter(bool value)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900478{
479 EnableTCPAckFilter = value;
480}
481
Dean Lee72ed4dc2015-06-12 14:11:44 +0900482bool is_TCP_ACK_Filter_Enabled(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900483{
484 return EnableTCPAckFilter;
485}
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900486
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900487static int wilc_wlan_txq_add_cfg_pkt(u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900488{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530489 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900490 struct txq_entry_t *tqe;
491
492 PRINT_D(TX_DBG, "Adding config packet ...\n");
493 if (p->quit) {
494 PRINT_D(TX_DBG, "Return due to clear function\n");
Glen Lee6a3b94f2015-09-24 18:14:59 +0900495 up(&g_linux_wlan->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900496 return 0;
497 }
498
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700499 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900500 if (tqe == NULL) {
501 PRINT_ER("Failed to allocate memory\n");
502 return 0;
503 }
504
505 tqe->type = WILC_CFG_PKT;
506 tqe->buffer = buffer;
507 tqe->buffer_size = buffer_size;
508 tqe->tx_complete_func = NULL;
509 tqe->priv = NULL;
510#ifdef TCP_ACK_FILTER
511 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
512#endif
513 /**
514 * Configuration packet always at the front
515 **/
516 PRINT_D(TX_DBG, "Adding the config packet at the Queue tail\n");
517
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900518 if (wilc_wlan_txq_add_to_head(tqe))
519 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900520 return 1;
521}
522
Glen Lee691bbd42015-10-27 18:28:02 +0900523int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
524 u32 buffer_size, wilc_tx_complete_func_t func)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900525{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530526 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900527 struct txq_entry_t *tqe;
528
529 if (p->quit)
530 return 0;
531
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700532 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900533
534 if (tqe == NULL)
535 return 0;
536 tqe->type = WILC_NET_PKT;
537 tqe->buffer = buffer;
538 tqe->buffer_size = buffer_size;
539 tqe->tx_complete_func = func;
540 tqe->priv = priv;
541
542 PRINT_D(TX_DBG, "Adding mgmt packet at the Queue tail\n");
543#ifdef TCP_ACK_FILTER
544 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
Abdul Hussain5a66bf22015-06-16 09:44:06 +0000545 if (is_TCP_ACK_Filter_Enabled())
Glen Lee82bb18e2015-10-27 18:28:03 +0900546 tcp_process(dev, tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900547#endif
Glen Lee32f03322015-10-29 12:18:45 +0900548 wilc_wlan_txq_add_to_tail(dev, tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900549 /*return number of itemes in the queue*/
550 return p->txq_entries;
551}
Glen Leefcc6ef92015-09-16 18:53:21 +0900552
Glen Lee829c4772015-10-29 12:18:44 +0900553int wilc_wlan_txq_add_mgmt_pkt(struct net_device *dev, void *priv, u8 *buffer,
554 u32 buffer_size, wilc_tx_complete_func_t func)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900555{
556
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530557 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900558 struct txq_entry_t *tqe;
559
560 if (p->quit)
561 return 0;
562
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700563 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900564
565 if (tqe == NULL)
566 return 0;
567 tqe->type = WILC_MGMT_PKT;
568 tqe->buffer = buffer;
569 tqe->buffer_size = buffer_size;
570 tqe->tx_complete_func = func;
571 tqe->priv = priv;
572#ifdef TCP_ACK_FILTER
573 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
574#endif
575 PRINT_D(TX_DBG, "Adding Network packet at the Queue tail\n");
Glen Lee32f03322015-10-29 12:18:45 +0900576 wilc_wlan_txq_add_to_tail(dev, tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900577 return 1;
578}
Glen Leefcc6ef92015-09-16 18:53:21 +0900579
Glen Lee7af05222015-10-29 12:18:41 +0900580static struct txq_entry_t *wilc_wlan_txq_get_first(struct wilc *wilc)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900581{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530582 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900583 struct txq_entry_t *tqe;
584 unsigned long flags;
585
Glen Lee7af05222015-10-29 12:18:41 +0900586 spin_lock_irqsave(&wilc->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900587
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900588 tqe = p->txq_head;
589
Glen Lee7af05222015-10-29 12:18:41 +0900590 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900591
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900592
593 return tqe;
594}
595
Glen Lee50a0b3b2015-10-27 18:28:00 +0900596static struct txq_entry_t *wilc_wlan_txq_get_next(struct wilc *wilc,
597 struct txq_entry_t *tqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900598{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900599 unsigned long flags;
Glen Lee50a0b3b2015-10-27 18:28:00 +0900600 spin_lock_irqsave(&wilc->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900601
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900602 tqe = tqe->next;
Glen Lee50a0b3b2015-10-27 18:28:00 +0900603 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900604
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900605
606 return tqe;
607}
608
Glen Leed06f3622015-10-27 18:27:59 +0900609static int wilc_wlan_rxq_add(struct wilc *wilc, struct rxq_entry_t *rqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900610{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530611 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900612
613 if (p->quit)
614 return 0;
615
Glen Leed06f3622015-10-27 18:27:59 +0900616 mutex_lock(&wilc->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900617 if (p->rxq_head == NULL) {
618 PRINT_D(RX_DBG, "Add to Queue head\n");
619 rqe->next = NULL;
620 p->rxq_head = rqe;
621 p->rxq_tail = rqe;
622 } else {
623 PRINT_D(RX_DBG, "Add to Queue tail\n");
624 p->rxq_tail->next = rqe;
625 rqe->next = NULL;
626 p->rxq_tail = rqe;
627 }
628 p->rxq_entries += 1;
629 PRINT_D(RX_DBG, "Number of queue entries: %d\n", p->rxq_entries);
Glen Leed06f3622015-10-27 18:27:59 +0900630 mutex_unlock(&wilc->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900631 return p->rxq_entries;
632}
633
Glen Leedb387632015-10-27 18:27:55 +0900634static struct rxq_entry_t *wilc_wlan_rxq_remove(struct wilc *wilc)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900635{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530636 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900637
638 PRINT_D(RX_DBG, "Getting rxQ element\n");
639 if (p->rxq_head) {
640 struct rxq_entry_t *rqe;
641
Glen Leedb387632015-10-27 18:27:55 +0900642 mutex_lock(&wilc->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900643 rqe = p->rxq_head;
644 p->rxq_head = p->rxq_head->next;
645 p->rxq_entries -= 1;
646 PRINT_D(RX_DBG, "RXQ entries decreased\n");
Glen Leedb387632015-10-27 18:27:55 +0900647 mutex_unlock(&wilc->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900648 return rqe;
649 }
650 PRINT_D(RX_DBG, "Nothing to get from Q\n");
651 return NULL;
652}
653
654
655/********************************************
656 *
657 * Power Save handle functions
658 *
659 ********************************************/
660
661
662
663#ifdef WILC_OPTIMIZE_SLEEP_INT
664
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900665static inline void chip_allow_sleep(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900666{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900667 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900668
669 /* Clear bit 1 */
670 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
671
Anish Bhattffda2032015-09-29 12:15:49 -0700672 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900673}
674
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900675static inline void chip_wakeup(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900676{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900677 u32 reg, clk_status_reg, trials = 0;
678 u32 sleep_time;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900679
680 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
681 do {
682 g_wlan.hif_func.hif_read_reg(1, &reg);
683 /* Set bit 1 */
Anish Bhattffda2032015-09-29 12:15:49 -0700684 g_wlan.hif_func.hif_write_reg(1, reg | BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900685
686 /* Clear bit 1*/
Anish Bhattffda2032015-09-29 12:15:49 -0700687 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900688
689 do {
690 /* Wait for the chip to stabilize*/
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -0700691 usleep_range(2 * 1000, 2 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900692 /* Make sure chip is awake. This is an extra step that can be removed */
693 /* later to avoid the bus access overhead */
Alison Schofield39823a52015-10-08 21:18:03 -0700694 if ((wilc_get_chipid(true) == 0))
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900695 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
Alison Schofield39823a52015-10-08 21:18:03 -0700696
Dean Lee72ed4dc2015-06-12 14:11:44 +0900697 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900698
Dean Lee72ed4dc2015-06-12 14:11:44 +0900699 } while (wilc_get_chipid(true) == 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900700 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
701 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
702 do {
703 /* Set bit 1 */
Anish Bhattffda2032015-09-29 12:15:49 -0700704 g_wlan.hif_func.hif_write_reg(0xf0, reg | BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900705
706 /* Check the clock status */
707 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
708
709 /* in case of clocks off, wait 2ms, and check it again. */
710 /* if still off, wait for another 2ms, for a total wait of 6ms. */
711 /* If still off, redo the wake up sequence */
712 while (((clk_status_reg & 0x1) == 0) && (((++trials) % 3) == 0)) {
713 /* Wait for the chip to stabilize*/
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -0700714 usleep_range(2 * 1000, 2 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900715
716 /* Make sure chip is awake. This is an extra step that can be removed */
717 /* later to avoid the bus access overhead */
718 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
719
Alison Schofield39823a52015-10-08 21:18:03 -0700720 if ((clk_status_reg & 0x1) == 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900721 wilc_debug(N_ERR, "clocks still OFF. Wake up failed\n");
Alison Schofield39823a52015-10-08 21:18:03 -0700722
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900723 }
724 /* in case of failure, Reset the wakeup bit to introduce a new edge on the next loop */
725 if ((clk_status_reg & 0x1) == 0) {
726 /* Reset bit 0 */
Anish Bhattffda2032015-09-29 12:15:49 -0700727 g_wlan.hif_func.hif_write_reg(0xf0, reg &
728 (~BIT(0)));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900729 }
730 } while ((clk_status_reg & 0x1) == 0);
731 }
732
733
734 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
735 g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -0700736 reg &= ~BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900737 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
738
Dean Lee72ed4dc2015-06-12 14:11:44 +0900739 if (wilc_get_chipid(false) >= 0x1002b0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900740 /* Enable PALDO back right after wakeup */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900741 u32 val32;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900742
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900743 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700744 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900745 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
746
747 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700748 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900749 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
750 }
751 }
752 genuChipPSstate = CHIP_WAKEDUP;
753}
754#else
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900755static inline void chip_wakeup(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900756{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900757 u32 reg, trials = 0;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900758
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900759 do {
760 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
761 g_wlan.hif_func.hif_read_reg(1, &reg);
762 /* Make sure bit 1 is 0 before we start. */
Anish Bhattffda2032015-09-29 12:15:49 -0700763 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900764 /* Set bit 1 */
Anish Bhattffda2032015-09-29 12:15:49 -0700765 g_wlan.hif_func.hif_write_reg(1, reg | BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900766 /* Clear bit 1*/
Anish Bhattffda2032015-09-29 12:15:49 -0700767 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900768 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
769 /* Make sure bit 0 is 0 before we start. */
770 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -0700771 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900772 /* Set bit 1 */
Anish Bhattffda2032015-09-29 12:15:49 -0700773 g_wlan.hif_func.hif_write_reg(0xf0, reg | BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900774 /* Clear bit 1 */
Anish Bhattffda2032015-09-29 12:15:49 -0700775 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900776 }
777
778 do {
779 /* Wait for the chip to stabilize*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900780 mdelay(3);
781
782 /* Make sure chip is awake. This is an extra step that can be removed */
783 /* later to avoid the bus access overhead */
Alison Schofield39823a52015-10-08 21:18:03 -0700784 if ((wilc_get_chipid(true) == 0))
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900785 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
Alison Schofield39823a52015-10-08 21:18:03 -0700786
Dean Lee72ed4dc2015-06-12 14:11:44 +0900787 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900788
Dean Lee72ed4dc2015-06-12 14:11:44 +0900789 } while (wilc_get_chipid(true) == 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900790
791 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
792 g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -0700793 reg &= ~BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900794 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
795
Dean Lee72ed4dc2015-06-12 14:11:44 +0900796 if (wilc_get_chipid(false) >= 0x1002b0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900797 /* Enable PALDO back right after wakeup */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900798 u32 val32;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900799
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900800 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700801 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900802 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
803
804 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700805 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900806 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
807 }
808 }
809 genuChipPSstate = CHIP_WAKEDUP;
810}
811#endif
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900812void chip_sleep_manually(u32 u32SleepTime)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900813{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900814 if (genuChipPSstate != CHIP_WAKEDUP) {
815 /* chip is already sleeping. Do nothing */
816 return;
817 }
818 acquire_bus(ACQUIRE_ONLY);
819
820#ifdef WILC_OPTIMIZE_SLEEP_INT
821 chip_allow_sleep();
822#endif
823
824 /* Trigger the manual sleep interrupt */
825 g_wlan.hif_func.hif_write_reg(0x10a8, 1);
826
827 genuChipPSstate = CHIP_SLEEPING_MANUAL;
828 release_bus(RELEASE_ONLY);
829
830}
831
832
833/********************************************
834 *
835 * Tx, Rx queue handle functions
836 *
837 ********************************************/
Glen Leea1332ca2015-10-27 18:27:47 +0900838int wilc_wlan_handle_txq(struct net_device *dev, u32 *pu32TxqCount)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900839{
840 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
841 int i, entries = 0;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900842 u32 sum;
843 u32 reg;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900844 u8 *txb = p->tx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900845 u32 offset = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900846 int vmm_sz = 0;
847 struct txq_entry_t *tqe;
848 int ret = 0;
849 int counter;
850 int timeout;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900851 u32 vmm_table[WILC_VMM_TBL_SIZE];
Glen Leea1332ca2015-10-27 18:27:47 +0900852 perInterface_wlan_t *nic;
853 struct wilc *wilc;
854
855 nic = netdev_priv(dev);
856 wilc = nic->wilc;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900857
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900858 p->txq_exit = 0;
859 do {
860 if (p->quit)
861 break;
862
Glen Leea1332ca2015-10-27 18:27:47 +0900863 linux_wlan_lock_timeout(&wilc->txq_add_to_head_cs,
Glen Leeb002e202015-09-24 18:15:05 +0900864 CFG_PKTS_TIMEOUT);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900865#ifdef TCP_ACK_FILTER
Glen Leec029e992015-10-27 18:27:48 +0900866 wilc_wlan_txq_filter_dup_tcp_ack(dev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900867#endif
868 /**
869 * build the vmm list
870 **/
871 PRINT_D(TX_DBG, "Getting the head of the TxQ\n");
Glen Lee7af05222015-10-29 12:18:41 +0900872 tqe = wilc_wlan_txq_get_first(wilc);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900873 i = 0;
874 sum = 0;
875 do {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900876 if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE - 1)) /* reserve last entry to 0 */) {
877
Alison Schofield39823a52015-10-08 21:18:03 -0700878 if (tqe->type == WILC_CFG_PKT)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900879 vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET;
Alison Schofield39823a52015-10-08 21:18:03 -0700880
881 else if (tqe->type == WILC_NET_PKT)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900882 vmm_sz = ETH_ETHERNET_HDR_OFFSET;
Alison Schofield39823a52015-10-08 21:18:03 -0700883
884 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900885 vmm_sz = HOST_HDR_OFFSET;
Alison Schofield39823a52015-10-08 21:18:03 -0700886
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900887 vmm_sz += tqe->buffer_size;
888 PRINT_D(TX_DBG, "VMM Size before alignment = %d\n", vmm_sz);
889 if (vmm_sz & 0x3) { /* has to be word aligned */
890 vmm_sz = (vmm_sz + 4) & ~0x3;
891 }
Alison Schofield39823a52015-10-08 21:18:03 -0700892 if ((sum + vmm_sz) > LINUX_TX_SIZE)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900893 break;
Alison Schofield39823a52015-10-08 21:18:03 -0700894
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900895 PRINT_D(TX_DBG, "VMM Size AFTER alignment = %d\n", vmm_sz);
896 vmm_table[i] = vmm_sz / 4; /* table take the word size */
897 PRINT_D(TX_DBG, "VMMTable entry size = %d\n", vmm_table[i]);
898
899 if (tqe->type == WILC_CFG_PKT) {
Anish Bhattffda2032015-09-29 12:15:49 -0700900 vmm_table[i] |= BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900901 PRINT_D(TX_DBG, "VMMTable entry changed for CFG packet = %d\n", vmm_table[i]);
902 }
903#ifdef BIG_ENDIAN
904 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
905#endif
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900906
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900907 i++;
908 sum += vmm_sz;
909 PRINT_D(TX_DBG, "sum = %d\n", sum);
Glen Lee50a0b3b2015-10-27 18:28:00 +0900910 tqe = wilc_wlan_txq_get_next(wilc, tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900911 } else {
912 break;
913 }
914 } while (1);
915
916 if (i == 0) { /* nothing in the queue */
917 PRINT_D(TX_DBG, "Nothing in TX-Q\n");
918 break;
919 } else {
920 PRINT_D(TX_DBG, "Mark the last entry in VMM table - number of previous entries = %d\n", i);
921 vmm_table[i] = 0x0; /* mark the last element to 0 */
922 }
923 acquire_bus(ACQUIRE_AND_WAKEUP);
924 counter = 0;
925 do {
926
927 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg);
928 if (!ret) {
929 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg vmm_tbl_entry..\n");
930 break;
931 }
932
933 if ((reg & 0x1) == 0) {
934 /**
935 * write to vmm table
936 **/
937 PRINT_D(TX_DBG, "Writing VMM table ... with Size = %d\n", ((i + 1) * 4));
938 break;
939 } else {
940 counter++;
941 if (counter > 200) {
942 counter = 0;
943 PRINT_D(TX_DBG, "Looping in tx ctrl , forcce quit\n");
944 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, 0);
945 break;
946 }
947 /**
948 * wait for vmm table is ready
949 **/
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530950 PRINT_WRN(GENERIC_DBG, "[wilc txq]: warn, vmm table not clear yet, wait...\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900951 release_bus(RELEASE_ALLOW_SLEEP);
Greg Kroah-Hartman2b922cb2015-09-04 09:30:51 -0700952 usleep_range(3000, 3000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900953 acquire_bus(ACQUIRE_AND_WAKEUP);
954 }
955 } while (!p->quit);
956
Alison Schofield39823a52015-10-08 21:18:03 -0700957 if (!ret)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900958 goto _end_;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900959
960 timeout = 200;
961 do {
962
963 /**
964 * write to vmm table
965 **/
Chaehyun Limc3ca6372015-09-20 15:51:19 +0900966 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 +0900967 if (!ret) {
968 wilc_debug(N_ERR, "ERR block TX of VMM table.\n");
969 break;
970 }
971
972
973 /**
974 * interrupt firmware
975 **/
976 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x2);
977 if (!ret) {
978 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg host_vmm_ctl..\n");
979 break;
980 }
981
982 /**
983 * wait for confirm...
984 **/
985
986 do {
987 ret = p->hif_func.hif_read_reg(WILC_HOST_VMM_CTL, &reg);
988 if (!ret) {
989 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg host_vmm_ctl..\n");
990 break;
991 }
992 if ((reg >> 2) & 0x1) {
993 /**
994 * Get the entries
995 **/
996 entries = ((reg >> 3) & 0x3f);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900997 break;
998 } else {
999 release_bus(RELEASE_ALLOW_SLEEP);
Greg Kroah-Hartman2b922cb2015-09-04 09:30:51 -07001000 usleep_range(3000, 3000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001001 acquire_bus(ACQUIRE_AND_WAKEUP);
1002 PRINT_WRN(GENERIC_DBG, "Can't get VMM entery - reg = %2x\n", reg);
1003 }
1004 } while (--timeout);
1005 if (timeout <= 0) {
1006 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x0);
1007 break;
1008 }
1009
Alison Schofield39823a52015-10-08 21:18:03 -07001010 if (!ret)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001011 break;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001012
1013 if (entries == 0) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301014 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 +09001015
1016 /* undo the transaction. */
1017 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg);
1018 if (!ret) {
1019 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg WILC_HOST_TX_CTRL..\n");
1020 break;
1021 }
Anish Bhattffda2032015-09-29 12:15:49 -07001022 reg &= ~BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001023 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, reg);
1024 if (!ret) {
1025 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg WILC_HOST_TX_CTRL..\n");
1026 break;
1027 }
1028 break;
1029 } else {
1030 break;
1031 }
1032 } while (1);
1033
Alison Schofield39823a52015-10-08 21:18:03 -07001034 if (!ret)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001035 goto _end_;
Alison Schofield39823a52015-10-08 21:18:03 -07001036
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001037 if (entries == 0) {
1038 ret = WILC_TX_ERR_NO_BUF;
1039 goto _end_;
1040 }
1041
1042 /* since copying data into txb takes some time, then
1043 * allow the bus lock to be released let the RX task go. */
1044 release_bus(RELEASE_ALLOW_SLEEP);
1045
1046 /**
1047 * Copy data to the TX buffer
1048 **/
1049 offset = 0;
1050 i = 0;
1051 do {
Glen Lee718fc2c2015-10-29 12:18:43 +09001052 tqe = wilc_wlan_txq_remove_from_head(dev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001053 if (tqe != NULL && (vmm_table[i] != 0)) {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001054 u32 header, buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001055
1056#ifdef BIG_ENDIAN
1057 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
1058#endif
1059 vmm_sz = (vmm_table[i] & 0x3ff); /* in word unit */
1060 vmm_sz *= 4;
1061 header = (tqe->type << 31) | (tqe->buffer_size << 15) | vmm_sz;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301062 if (tqe->type == WILC_MGMT_PKT)
Anish Bhattffda2032015-09-29 12:15:49 -07001063 header |= BIT(30);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301064 else
Anish Bhattffda2032015-09-29 12:15:49 -07001065 header &= ~BIT(30);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001066
1067#ifdef BIG_ENDIAN
1068 header = BYTE_SWAP(header);
1069#endif
1070 memcpy(&txb[offset], &header, 4);
1071 if (tqe->type == WILC_CFG_PKT) {
1072 buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET;
1073 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001074 else if (tqe->type == WILC_NET_PKT) {
1075 char *pBSSID = ((struct tx_complete_data *)(tqe->priv))->pBssid;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001076
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001077 buffer_offset = ETH_ETHERNET_HDR_OFFSET;
1078 /* copy the bssid at the sart of the buffer */
1079 memcpy(&txb[offset + 4], pBSSID, 6);
1080 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001081 else {
1082 buffer_offset = HOST_HDR_OFFSET;
1083 }
1084
1085 memcpy(&txb[offset + buffer_offset], tqe->buffer, tqe->buffer_size);
1086 offset += vmm_sz;
1087 i++;
1088 tqe->status = 1; /* mark the packet send */
1089 if (tqe->tx_complete_func)
1090 tqe->tx_complete_func(tqe->priv, tqe->status);
1091 #ifdef TCP_ACK_FILTER
Alison Schofield39823a52015-10-08 21:18:03 -07001092 if (tqe->tcp_PendingAck_index != NOT_TCP_ACK)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001093 Pending_Acks_info[tqe->tcp_PendingAck_index].txqe = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001094 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001095 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001096 } else {
1097 break;
1098 }
1099 } while (--entries);
1100
1101 /**
1102 * lock the bus
1103 **/
1104 acquire_bus(ACQUIRE_AND_WAKEUP);
1105
1106 ret = p->hif_func.hif_clear_int_ext(ENABLE_TX_VMM);
1107 if (!ret) {
1108 wilc_debug(N_ERR, "[wilc txq]: fail can't start tx VMM ...\n");
1109 goto _end_;
1110 }
1111
1112 /**
1113 * transfer
1114 **/
1115 ret = p->hif_func.hif_block_tx_ext(0, txb, offset);
1116 if (!ret) {
1117 wilc_debug(N_ERR, "[wilc txq]: fail can't block tx ext...\n");
1118 goto _end_;
1119 }
1120
1121_end_:
1122
1123 release_bus(RELEASE_ALLOW_SLEEP);
1124 if (ret != 1)
1125 break;
1126 } while (0);
Glen Leea1332ca2015-10-27 18:27:47 +09001127 up(&wilc->txq_add_to_head_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001128
1129 p->txq_exit = 1;
1130 PRINT_D(TX_DBG, "THREAD: Exiting txq\n");
1131 /* return tx[]q count */
1132 *pu32TxqCount = p->txq_entries;
1133 return ret;
1134}
1135
Glen Lee39ce4d32015-10-27 18:27:42 +09001136static void wilc_wlan_handle_rxq(struct wilc *wilc)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001137{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301138 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001139 int offset = 0, size, has_packet = 0;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001140 u8 *buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001141 struct rxq_entry_t *rqe;
1142
1143 p->rxq_exit = 0;
1144
1145
1146
1147
1148 do {
1149 if (p->quit) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301150 PRINT_D(RX_DBG, "exit 1st do-while due to Clean_UP function\n");
Glen Lee39ce4d32015-10-27 18:27:42 +09001151 up(&wilc->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001152 break;
1153 }
Glen Leedb387632015-10-27 18:27:55 +09001154 rqe = wilc_wlan_rxq_remove(wilc);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001155 if (rqe == NULL) {
1156 PRINT_D(RX_DBG, "nothing in the queue - exit 1st do-while\n");
1157 break;
1158 }
1159 buffer = rqe->buffer;
1160 size = rqe->buffer_size;
1161 PRINT_D(RX_DBG, "rxQ entery Size = %d - Address = %p\n", size, buffer);
1162 offset = 0;
1163
1164
1165
1166 do {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001167 u32 header;
1168 u32 pkt_len, pkt_offset, tp_len;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001169 int is_cfg_packet;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001170
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001171 PRINT_D(RX_DBG, "In the 2nd do-while\n");
1172 memcpy(&header, &buffer[offset], 4);
1173#ifdef BIG_ENDIAN
1174 header = BYTE_SWAP(header);
1175#endif
1176 PRINT_D(RX_DBG, "Header = %04x - Offset = %d\n", header, offset);
1177
1178
1179
1180 is_cfg_packet = (header >> 31) & 0x1;
1181 pkt_offset = (header >> 22) & 0x1ff;
1182 tp_len = (header >> 11) & 0x7ff;
1183 pkt_len = header & 0x7ff;
1184
1185 if (pkt_len == 0 || tp_len == 0) {
1186 wilc_debug(N_RXQ, "[wilc rxq]: data corrupt, packet len or tp_len is 0 [%d][%d]\n", pkt_len, tp_len);
1187 break;
1188 }
1189
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001190 #define IS_MANAGMEMENT 0x100
1191 #define IS_MANAGMEMENT_CALLBACK 0x080
1192 #define IS_MGMT_STATUS_SUCCES 0x040
1193
1194
1195 if (pkt_offset & IS_MANAGMEMENT) {
1196 /* reset mgmt indicator bit, to use pkt_offeset in furthur calculations */
1197 pkt_offset &= ~(IS_MANAGMEMENT | IS_MANAGMEMENT_CALLBACK | IS_MGMT_STATUS_SUCCES);
1198
Glen Lee11f4b2e2015-10-27 18:27:51 +09001199 WILC_WFI_mgmt_rx(wilc, &buffer[offset + HOST_HDR_OFFSET], pkt_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001200 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001201 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001202 {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001203
1204 if (!is_cfg_packet) {
Glen Lee63611672015-09-24 18:14:52 +09001205 if (pkt_len > 0) {
Glen Leecb1991a2015-10-27 18:27:56 +09001206 frmw_to_linux(wilc,
1207 &buffer[offset],
Glen Lee63611672015-09-24 18:14:52 +09001208 pkt_len,
1209 pkt_offset);
1210 has_packet = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001211 }
1212 } else {
1213 wilc_cfg_rsp_t rsp;
1214
1215
1216
Glen Lee30f535a2015-10-02 14:22:10 +09001217 wilc_wlan_cfg_indicate_rx(&buffer[pkt_offset + offset], pkt_len, &rsp);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001218 if (rsp.type == WILC_CFG_RSP) {
1219 /**
1220 * wake up the waiting task...
1221 **/
1222 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 -07001223 if (p->cfg_seq_no == rsp.seq_no)
Glen Lee39ce4d32015-10-27 18:27:42 +09001224 up(&wilc->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001225 } else if (rsp.type == WILC_CFG_RSP_STATUS) {
1226 /**
1227 * Call back to indicate status...
1228 **/
Glen Lee64f2b712015-10-27 18:27:43 +09001229 linux_wlan_mac_indicate(wilc, WILC_MAC_INDICATE_STATUS);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001230
1231 } else if (rsp.type == WILC_CFG_RSP_SCAN) {
Glen Lee64f2b712015-10-27 18:27:43 +09001232 linux_wlan_mac_indicate(wilc, WILC_MAC_INDICATE_SCAN);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001233 }
1234 }
1235 }
1236 offset += tp_len;
1237 if (offset >= size)
1238 break;
1239 } while (1);
1240
1241
1242#ifndef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001243 kfree(buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001244#endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001245 kfree(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001246
Alison Schofield39823a52015-10-08 21:18:03 -07001247 if (has_packet)
Glen Leec0cadaa2015-09-24 18:14:54 +09001248 linux_wlan_rx_complete();
Alison Schofield39823a52015-10-08 21:18:03 -07001249
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001250 } while (1);
1251
1252 p->rxq_exit = 1;
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301253 PRINT_D(RX_DBG, "THREAD: Exiting RX thread\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001254}
1255
1256/********************************************
1257 *
1258 * Fast DMA Isr
1259 *
1260 ********************************************/
1261static void wilc_unknown_isr_ext(void)
1262{
1263 g_wlan.hif_func.hif_clear_int_ext(0);
1264}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001265static void wilc_pllupdate_isr_ext(u32 int_stats)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001266{
1267
1268 int trials = 10;
1269
1270 g_wlan.hif_func.hif_clear_int_ext(PLL_INT_CLR);
1271
1272 /* Waiting for PLL */
Greg Kroah-Hartmanc2e4c0f2015-09-03 19:09:50 -07001273 mdelay(WILC_PLL_TO);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001274
1275 /* poll till read a valid data */
Dean Lee72ed4dc2015-06-12 14:11:44 +09001276 while (!(ISWILC1000(wilc_get_chipid(true)) && --trials)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001277 PRINT_D(TX_DBG, "PLL update retrying\n");
Greg Kroah-Hartmanc2e4c0f2015-09-03 19:09:50 -07001278 mdelay(1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001279 }
1280}
1281
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001282static void wilc_sleeptimer_isr_ext(u32 int_stats1)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001283{
1284 g_wlan.hif_func.hif_clear_int_ext(SLEEP_INT_CLR);
1285#ifndef WILC_OPTIMIZE_SLEEP_INT
1286 genuChipPSstate = CHIP_SLEEPING_AUTO;
1287#endif
1288}
1289
Glen Lee3bcd45b2015-10-27 18:27:41 +09001290static void wilc_wlan_handle_isr_ext(struct wilc *wilc, u32 int_status)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001291{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301292 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001293#ifdef MEMORY_STATIC
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001294 u32 offset = p->rx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001295#endif
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001296 u8 *buffer = NULL;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001297 u32 size;
1298 u32 retries = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001299 int ret = 0;
1300 struct rxq_entry_t *rqe;
1301
1302
1303 /**
1304 * Get the rx size
1305 **/
1306
1307 size = ((int_status & 0x7fff) << 2);
1308
1309 while (!size && retries < 10) {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001310 u32 time = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001311 /*looping more secure*/
1312 /*zero size make a crashe because the dma will not happen and that will block the firmware*/
1313 wilc_debug(N_ERR, "RX Size equal zero ... Trying to read it again for %d time\n", time++);
1314 p->hif_func.hif_read_size(&size);
1315 size = ((size & 0x7fff) << 2);
1316 retries++;
1317
1318 }
1319
1320 if (size > 0) {
1321#ifdef MEMORY_STATIC
Glen Lee03eb7262015-09-24 18:15:03 +09001322 if (LINUX_RX_SIZE - offset < size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001323 offset = 0;
1324
1325 if (p->rx_buffer)
1326 buffer = &p->rx_buffer[offset];
1327 else {
1328 wilc_debug(N_ERR, "[wilc isr]: fail Rx Buffer is NULL...drop the packets (%d)\n", size);
1329 goto _end_;
1330 }
1331
1332#else
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001333 buffer = kmalloc(size, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001334 if (buffer == NULL) {
1335 wilc_debug(N_ERR, "[wilc isr]: fail alloc host memory...drop the packets (%d)\n", size);
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -07001336 usleep_range(100 * 1000, 100 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001337 goto _end_;
1338 }
1339#endif
1340
1341 /**
1342 * clear the chip's interrupt after getting size some register getting corrupted after clear the interrupt
1343 **/
1344 p->hif_func.hif_clear_int_ext(DATA_INT_CLR | ENABLE_RX_VMM);
1345
1346
1347 /**
1348 * start transfer
1349 **/
1350 ret = p->hif_func.hif_block_rx_ext(0, buffer, size);
1351
1352 if (!ret) {
1353 wilc_debug(N_ERR, "[wilc isr]: fail block rx...\n");
1354 goto _end_;
1355 }
1356_end_:
1357
1358
1359 if (ret) {
1360#ifdef MEMORY_STATIC
1361 offset += size;
1362 p->rx_buffer_offset = offset;
1363#endif
1364 /**
1365 * add to rx queue
1366 **/
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001367 rqe = kmalloc(sizeof(struct rxq_entry_t), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001368 if (rqe != NULL) {
1369 rqe->buffer = buffer;
1370 rqe->buffer_size = size;
1371 PRINT_D(RX_DBG, "rxq entery Size= %d - Address = %p\n", rqe->buffer_size, rqe->buffer);
Glen Leed06f3622015-10-27 18:27:59 +09001372 wilc_wlan_rxq_add(wilc, rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001373 }
1374 } else {
1375#ifndef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001376 kfree(buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001377#endif
1378 }
1379 }
Glen Lee39ce4d32015-10-27 18:27:42 +09001380 wilc_wlan_handle_rxq(wilc);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001381}
1382
Glen Lee50b929e2015-10-27 18:27:40 +09001383void wilc_handle_isr(void *wilc)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001384{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001385 u32 int_status;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001386
1387 acquire_bus(ACQUIRE_AND_WAKEUP);
1388 g_wlan.hif_func.hif_read_int(&int_status);
1389
Alison Schofield39823a52015-10-08 21:18:03 -07001390 if (int_status & PLL_INT_EXT)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001391 wilc_pllupdate_isr_ext(int_status);
Alison Schofield39823a52015-10-08 21:18:03 -07001392
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001393 if (int_status & DATA_INT_EXT) {
Glen Lee3bcd45b2015-10-27 18:27:41 +09001394 wilc_wlan_handle_isr_ext(wilc, int_status);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001395 #ifndef WILC_OPTIMIZE_SLEEP_INT
1396 /* Chip is up and talking*/
1397 genuChipPSstate = CHIP_WAKEDUP;
1398 #endif
1399 }
Alison Schofield39823a52015-10-08 21:18:03 -07001400 if (int_status & SLEEP_INT_EXT)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001401 wilc_sleeptimer_isr_ext(int_status);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001402
1403 if (!(int_status & (ALL_INT_EXT))) {
1404#ifdef WILC_SDIO
1405 PRINT_D(TX_DBG, ">> UNKNOWN_INTERRUPT - 0x%08x\n", int_status);
1406#endif
1407 wilc_unknown_isr_ext();
1408 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001409 release_bus(RELEASE_ALLOW_SLEEP);
1410}
1411
1412/********************************************
1413 *
1414 * Firmware download
1415 *
1416 ********************************************/
Glen Lee63d7ab82015-10-01 16:03:32 +09001417int wilc_wlan_firmware_download(const u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001418{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301419 wilc_wlan_dev_t *p = &g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001420 u32 offset;
1421 u32 addr, size, size2, blksz;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001422 u8 *dma_buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001423 int ret = 0;
1424
Anish Bhattffda2032015-09-29 12:15:49 -07001425 blksz = BIT(12);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001426 /* Allocate a DMA coherent buffer. */
1427
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001428 dma_buffer = kmalloc(blksz, GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001429 if (dma_buffer == NULL) {
1430 /*EIO 5*/
1431 ret = -5;
1432 PRINT_ER("Can't allocate buffer for firmware download IO error\n ");
1433 goto _fail_1;
1434 }
1435
1436 PRINT_D(INIT_DBG, "Downloading firmware size = %d ...\n", buffer_size);
1437 /**
1438 * load the firmware
1439 **/
1440 offset = 0;
1441 do {
1442 memcpy(&addr, &buffer[offset], 4);
1443 memcpy(&size, &buffer[offset + 4], 4);
1444#ifdef BIG_ENDIAN
1445 addr = BYTE_SWAP(addr);
1446 size = BYTE_SWAP(size);
1447#endif
1448 acquire_bus(ACQUIRE_ONLY);
1449 offset += 8;
1450 while (((int)size) && (offset < buffer_size)) {
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301451 if (size <= blksz)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001452 size2 = size;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301453 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001454 size2 = blksz;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001455 /* Copy firmware into a DMA coherent buffer */
1456 memcpy(dma_buffer, &buffer[offset], size2);
1457 ret = p->hif_func.hif_block_tx(addr, dma_buffer, size2);
1458 if (!ret)
1459 break;
1460
1461 addr += size2;
1462 offset += size2;
1463 size -= size2;
1464 }
1465 release_bus(RELEASE_ONLY);
1466
1467 if (!ret) {
1468 /*EIO 5*/
1469 ret = -5;
1470 PRINT_ER("Can't download firmware IO error\n ");
1471 goto _fail_;
1472 }
1473 PRINT_D(INIT_DBG, "Offset = %d\n", offset);
1474 } while (offset < buffer_size);
1475
1476_fail_:
1477
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001478 kfree(dma_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001479
1480_fail_1:
1481
1482 return (ret < 0) ? ret : 0;
1483}
1484
1485/********************************************
1486 *
1487 * Common
1488 *
1489 ********************************************/
Glen Leee42563b2015-10-01 16:03:33 +09001490int wilc_wlan_start(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001491{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301492 wilc_wlan_dev_t *p = &g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001493 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001494 int ret;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001495 u32 chipid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001496
1497 /**
1498 * Set the host interface
1499 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001500 if (p->io_func.io_type == HIF_SDIO) {
1501 reg = 0;
Anish Bhattffda2032015-09-29 12:15:49 -07001502 reg |= BIT(3); /* bug 4456 and 4557 */
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001503 } else if (p->io_func.io_type == HIF_SPI) {
1504 reg = 1;
1505 }
1506 acquire_bus(ACQUIRE_ONLY);
1507 ret = p->hif_func.hif_write_reg(WILC_VMM_CORE_CFG, reg);
1508 if (!ret) {
1509 wilc_debug(N_ERR, "[wilc start]: fail write reg vmm_core_cfg...\n");
1510 release_bus(RELEASE_ONLY);
1511 /* EIO 5*/
1512 ret = -5;
1513 return ret;
1514 }
1515 reg = 0;
1516#ifdef WILC_SDIO_IRQ_GPIO
1517 reg |= WILC_HAVE_SDIO_IRQ_GPIO;
1518#endif
1519
1520#ifdef WILC_DISABLE_PMU
1521#else
1522 reg |= WILC_HAVE_USE_PMU;
1523#endif
1524
1525#ifdef WILC_SLEEP_CLK_SRC_XO
1526 reg |= WILC_HAVE_SLEEP_CLK_SRC_XO;
1527#elif defined WILC_SLEEP_CLK_SRC_RTC
1528 reg |= WILC_HAVE_SLEEP_CLK_SRC_RTC;
1529#endif
1530
1531#ifdef WILC_EXT_PA_INV_TX_RX
1532 reg |= WILC_HAVE_EXT_PA_INV_TX_RX;
1533#endif
1534
1535 reg |= WILC_HAVE_LEGACY_RF_SETTINGS;
1536
1537
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001538/*Set oscillator frequency*/
1539#ifdef XTAL_24
1540 reg |= WILC_HAVE_XTAL_24;
1541#endif
1542
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001543/*Enable/Disable GPIO configuration for FW logs*/
1544#ifdef DISABLE_WILC_UART
1545 reg |= WILC_HAVE_DISABLE_WILC_UART;
1546#endif
1547
1548 ret = p->hif_func.hif_write_reg(WILC_GP_REG_1, reg);
1549 if (!ret) {
1550 wilc_debug(N_ERR, "[wilc start]: fail write WILC_GP_REG_1 ...\n");
1551 release_bus(RELEASE_ONLY);
1552 /* EIO 5*/
1553 ret = -5;
1554 return ret;
1555 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001556
1557 /**
1558 * Bus related
1559 **/
1560 p->hif_func.hif_sync_ext(NUM_INT_EXT);
1561
1562 ret = p->hif_func.hif_read_reg(0x1000, &chipid);
1563 if (!ret) {
1564 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1000 ...\n");
1565 release_bus(RELEASE_ONLY);
1566 /* EIO 5*/
1567 ret = -5;
1568 return ret;
1569 }
1570
1571 /**
1572 * Go...
1573 **/
1574
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001575
1576 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -07001577 if ((reg & BIT(10)) == BIT(10)) {
1578 reg &= ~BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001579 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1580 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1581 }
1582
Anish Bhattffda2032015-09-29 12:15:49 -07001583 reg |= BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001584 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1585 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1586 release_bus(RELEASE_ONLY);
1587
1588 return (ret < 0) ? ret : 0;
1589}
1590
1591void wilc_wlan_global_reset(void)
1592{
1593
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301594 wilc_wlan_dev_t *p = &g_wlan;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001595
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001596 acquire_bus(ACQUIRE_AND_WAKEUP);
1597 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, 0x0);
1598 release_bus(RELEASE_ONLY);
1599}
Glen Lee8cec7412015-10-01 16:03:34 +09001600int wilc_wlan_stop(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001601{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301602 wilc_wlan_dev_t *p = &g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001603 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001604 int ret;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001605 u8 timeout = 10;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001606 /**
1607 * TODO: stop the firmware, need a re-download
1608 **/
1609 acquire_bus(ACQUIRE_AND_WAKEUP);
1610
1611 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1612 if (!ret) {
1613 PRINT_ER("Error while reading reg\n");
1614 release_bus(RELEASE_ALLOW_SLEEP);
1615 return ret;
1616 }
1617
Anish Bhattffda2032015-09-29 12:15:49 -07001618 reg &= ~BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001619
1620
1621 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1622 if (!ret) {
1623 PRINT_ER("Error while writing reg\n");
1624 release_bus(RELEASE_ALLOW_SLEEP);
1625 return ret;
1626 }
1627
1628
1629
1630 do {
1631 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1632 if (!ret) {
1633 PRINT_ER("Error while reading reg\n");
1634 release_bus(RELEASE_ALLOW_SLEEP);
1635 return ret;
1636 }
1637 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1638 /*Workaround to ensure that the chip is actually reset*/
Anish Bhattffda2032015-09-29 12:15:49 -07001639 if ((reg & BIT(10))) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001640 PRINT_D(GENERIC_DBG, "Bit 10 not reset : Retry %d\n", timeout);
Anish Bhattffda2032015-09-29 12:15:49 -07001641 reg &= ~BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001642 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1643 timeout--;
1644 } else {
1645 PRINT_D(GENERIC_DBG, "Bit 10 reset after : Retry %d\n", timeout);
1646 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1647 if (!ret) {
1648 PRINT_ER("Error while reading reg\n");
1649 release_bus(RELEASE_ALLOW_SLEEP);
1650 return ret;
1651 }
1652 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1653 break;
1654 }
1655
1656 } while (timeout);
Anish Bhattffda2032015-09-29 12:15:49 -07001657 reg = (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(8) | BIT(9) | BIT(26) |
1658 BIT(29) | BIT(30) | BIT(31));
Anish Bhatt65ead4e2015-09-29 12:15:48 -07001659
1660 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
Anish Bhattffda2032015-09-29 12:15:49 -07001661 reg = (u32)~BIT(10);
Anish Bhatt65ead4e2015-09-29 12:15:48 -07001662
1663 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001664
1665 release_bus(RELEASE_ALLOW_SLEEP);
1666
1667 return ret;
1668}
1669
Glen Lee2de7cbe2015-10-27 18:27:54 +09001670void wilc_wlan_cleanup(struct net_device *dev)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001671{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301672 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001673 struct txq_entry_t *tqe;
1674 struct rxq_entry_t *rqe;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001675 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001676 int ret;
Glen Leedb387632015-10-27 18:27:55 +09001677 perInterface_wlan_t *nic;
1678 struct wilc *wilc;
1679
1680 nic = netdev_priv(dev);
1681 wilc = nic->wilc;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001682
1683 p->quit = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001684 do {
Glen Lee718fc2c2015-10-29 12:18:43 +09001685 tqe = wilc_wlan_txq_remove_from_head(dev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001686 if (tqe == NULL)
1687 break;
1688 if (tqe->tx_complete_func)
1689 tqe->tx_complete_func(tqe->priv, 0);
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001690 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001691 } while (1);
1692
1693 do {
Glen Leedb387632015-10-27 18:27:55 +09001694 rqe = wilc_wlan_rxq_remove(wilc);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001695 if (rqe == NULL)
1696 break;
Javier Martinez Canillas6a272242015-09-22 15:24:50 +02001697#ifndef MEMORY_STATIC
1698 kfree(rqe->buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001699#endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001700 kfree(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001701 } while (1);
1702
1703 /**
1704 * clean up buffer
1705 **/
1706
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001707 #ifdef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001708 kfree(p->rx_buffer);
1709 p->rx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001710 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001711 kfree(p->tx_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001712
1713 acquire_bus(ACQUIRE_AND_WAKEUP);
1714
1715
1716 ret = p->hif_func.hif_read_reg(WILC_GP_REG_0, &reg);
1717 if (!ret) {
1718 PRINT_ER("Error while reading reg\n");
1719 release_bus(RELEASE_ALLOW_SLEEP);
1720 }
1721 PRINT_ER("Writing ABORT reg\n");
1722 ret = p->hif_func.hif_write_reg(WILC_GP_REG_0, (reg | ABORT_INT));
1723 if (!ret) {
1724 PRINT_ER("Error while writing reg\n");
1725 release_bus(RELEASE_ALLOW_SLEEP);
1726 }
1727 release_bus(RELEASE_ALLOW_SLEEP);
1728 /**
1729 * io clean up
1730 **/
1731 p->hif_func.hif_deinit(NULL);
1732
1733}
1734
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001735static int wilc_wlan_cfg_commit(int type, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001736{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301737 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001738 wilc_cfg_frame_t *cfg = &p->cfg_frame;
1739 int total_len = p->cfg_frame_offset + 4 + DRIVER_HANDLER_SIZE;
1740 int seq_no = p->cfg_seq_no % 256;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001741 int driver_handler = (u32)drvHandler;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001742
1743
1744 /**
1745 * Set up header
1746 **/
1747 if (type == WILC_CFG_SET) { /* Set */
1748 cfg->wid_header[0] = 'W';
1749 } else { /* Query */
1750 cfg->wid_header[0] = 'Q';
1751 }
1752 cfg->wid_header[1] = seq_no; /* sequence number */
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001753 cfg->wid_header[2] = (u8)total_len;
1754 cfg->wid_header[3] = (u8)(total_len >> 8);
1755 cfg->wid_header[4] = (u8)driver_handler;
1756 cfg->wid_header[5] = (u8)(driver_handler >> 8);
1757 cfg->wid_header[6] = (u8)(driver_handler >> 16);
1758 cfg->wid_header[7] = (u8)(driver_handler >> 24);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001759 p->cfg_seq_no = seq_no;
1760
1761 /**
1762 * Add to TX queue
1763 **/
1764
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001765 if (!wilc_wlan_txq_add_cfg_pkt(&cfg->wid_header[0], total_len))
1766 return -1;
1767
1768 return 0;
1769}
1770
Glen Lee1028e5a2015-10-01 16:03:40 +09001771int wilc_wlan_cfg_set(int start, u32 wid, u8 *buffer, u32 buffer_size,
1772 int commit, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001773{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301774 wilc_wlan_dev_t *p = &g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001775 u32 offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001776 int ret_size;
1777
1778
1779 if (p->cfg_frame_in_use)
1780 return 0;
1781
1782 if (start)
1783 p->cfg_frame_offset = 0;
1784
1785 offset = p->cfg_frame_offset;
Glen Lee17e8f162015-10-02 14:22:07 +09001786 ret_size = wilc_wlan_cfg_set_wid(p->cfg_frame.frame, offset, (u16)wid,
1787 buffer, buffer_size);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001788 offset += ret_size;
1789 p->cfg_frame_offset = offset;
1790
1791 if (commit) {
1792 PRINT_D(TX_DBG, "[WILC]PACKET Commit with sequence number %d\n", p->cfg_seq_no);
1793 PRINT_D(RX_DBG, "Processing cfg_set()\n");
1794 p->cfg_frame_in_use = 1;
1795
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001796 if (wilc_wlan_cfg_commit(WILC_CFG_SET, drvHandler))
Chaehyun Lim5af6b852015-09-17 16:48:48 +09001797 ret_size = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001798
Glen Leeb002e202015-09-24 18:15:05 +09001799 if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event,
1800 CFG_PKTS_TIMEOUT)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001801 PRINT_D(TX_DBG, "Set Timed Out\n");
1802 ret_size = 0;
1803 }
1804 p->cfg_frame_in_use = 0;
1805 p->cfg_frame_offset = 0;
1806 p->cfg_seq_no += 1;
1807
1808 }
1809
1810 return ret_size;
1811}
Glen Lee07056a82015-10-01 16:03:41 +09001812int wilc_wlan_cfg_get(int start, u32 wid, int commit, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001813{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301814 wilc_wlan_dev_t *p = &g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001815 u32 offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001816 int ret_size;
1817
1818
1819 if (p->cfg_frame_in_use)
1820 return 0;
1821
1822 if (start)
1823 p->cfg_frame_offset = 0;
1824
1825 offset = p->cfg_frame_offset;
Glen Leeec1b86b2015-10-02 14:22:08 +09001826 ret_size = wilc_wlan_cfg_get_wid(p->cfg_frame.frame, offset, (u16)wid);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001827 offset += ret_size;
1828 p->cfg_frame_offset = offset;
1829
1830 if (commit) {
1831 p->cfg_frame_in_use = 1;
1832
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001833 if (wilc_wlan_cfg_commit(WILC_CFG_QUERY, drvHandler))
Chaehyun Lim5af6b852015-09-17 16:48:48 +09001834 ret_size = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001835
1836
Glen Leeb002e202015-09-24 18:15:05 +09001837 if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event,
1838 CFG_PKTS_TIMEOUT)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001839 PRINT_D(TX_DBG, "Get Timed Out\n");
1840 ret_size = 0;
1841 }
1842 PRINT_D(GENERIC_DBG, "[WILC]Get Response received\n");
1843 p->cfg_frame_in_use = 0;
1844 p->cfg_frame_offset = 0;
1845 p->cfg_seq_no += 1;
1846 }
1847
1848 return ret_size;
1849}
1850
Glen Lee894de36b2015-10-01 16:03:42 +09001851int wilc_wlan_cfg_get_val(u32 wid, u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001852{
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001853 int ret;
1854
Glen Lee355cca22015-10-02 14:22:09 +09001855 ret = wilc_wlan_cfg_get_wid_value((u16)wid, buffer, buffer_size);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001856
1857 return ret;
1858}
1859
1860void wilc_bus_set_max_speed(void)
1861{
1862
1863 /* Increase bus speed to max possible. */
1864 g_wlan.hif_func.hif_set_max_bus_speed();
1865}
1866
1867void wilc_bus_set_default_speed(void)
1868{
1869
1870 /* Restore bus speed to default. */
1871 g_wlan.hif_func.hif_set_default_bus_speed();
1872}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001873u32 init_chip(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001874{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001875 u32 chipid;
1876 u32 reg, ret = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001877
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001878 acquire_bus(ACQUIRE_ONLY);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001879
Dean Lee72ed4dc2015-06-12 14:11:44 +09001880 chipid = wilc_get_chipid(true);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001881
1882
1883
1884 if ((chipid & 0xfff) != 0xa0) {
1885 /**
1886 * Avoid booting from boot ROM. Make sure that Drive IRQN [SDIO platform]
1887 * or SD_DAT3 [SPI platform] to ?1?
1888 **/
1889 /* Set cortus reset register to register control. */
1890 ret = g_wlan.hif_func.hif_read_reg(0x1118, &reg);
1891 if (!ret) {
1892 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1118 ...\n");
1893 return ret;
1894 }
Anish Bhattffda2032015-09-29 12:15:49 -07001895 reg |= BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001896 ret = g_wlan.hif_func.hif_write_reg(0x1118, reg);
1897 if (!ret) {
1898 wilc_debug(N_ERR, "[wilc start]: fail write reg 0x1118 ...\n");
1899 return ret;
1900 }
1901 /**
1902 * Write branch intruction to IRAM (0x71 trap) at location 0xFFFF0000
1903 * (Cortus map) or C0000 (AHB map).
1904 **/
1905 ret = g_wlan.hif_func.hif_write_reg(0xc0000, 0x71);
1906 if (!ret) {
1907 wilc_debug(N_ERR, "[wilc start]: fail write reg 0xc0000 ...\n");
1908 return ret;
1909 }
1910 }
1911
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001912 release_bus(RELEASE_ONLY);
1913
1914 return ret;
1915
1916}
1917
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001918u32 wilc_get_chipid(u8 update)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001919{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001920 static u32 chipid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001921 /* SDIO can't read into global variables */
1922 /* Use this variable as a temp, then copy to the global */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001923 u32 tempchipid = 0;
1924 u32 rfrevid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001925
1926 if (chipid == 0 || update != 0) {
1927 g_wlan.hif_func.hif_read_reg(0x1000, &tempchipid);
1928 g_wlan.hif_func.hif_read_reg(0x13f4, &rfrevid);
1929 if (!ISWILC1000(tempchipid)) {
1930 chipid = 0;
1931 goto _fail_;
1932 }
1933 if (tempchipid == 0x1002a0) {
1934 if (rfrevid == 0x1) { /* 1002A0 */
1935 } else { /* if (rfrevid == 0x2) */ /* 1002A1 */
1936 tempchipid = 0x1002a1;
1937 }
1938 } else if (tempchipid == 0x1002b0) {
1939 if (rfrevid == 3) { /* 1002B0 */
1940 } else if (rfrevid == 4) { /* 1002B1 */
1941 tempchipid = 0x1002b1;
1942 } else { /* if(rfrevid == 5) */ /* 1002B2 */
1943 tempchipid = 0x1002b2;
1944 }
1945 } else {
1946 }
1947
1948 chipid = tempchipid;
1949 }
1950_fail_:
1951 return chipid;
1952}
1953
Glen Leec9d48342015-10-01 16:03:43 +09001954int wilc_wlan_init(wilc_wlan_inp_t *inp)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001955{
1956
1957 int ret = 0;
1958
1959 PRINT_D(INIT_DBG, "Initializing WILC_Wlan ...\n");
1960
1961 memset((void *)&g_wlan, 0, sizeof(wilc_wlan_dev_t));
1962
1963 /**
1964 * store the input
1965 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001966 memcpy((void *)&g_wlan.io_func, (void *)&inp->io_func, sizeof(wilc_wlan_io_func_t));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001967 /***
1968 * host interface init
1969 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001970 if ((inp->io_func.io_type & 0x1) == HIF_SDIO) {
1971 if (!hif_sdio.hif_init(inp, wilc_debug)) {
1972 /* EIO 5 */
1973 ret = -5;
1974 goto _fail_;
1975 }
1976 memcpy((void *)&g_wlan.hif_func, &hif_sdio, sizeof(wilc_hif_func_t));
1977 } else {
1978 if ((inp->io_func.io_type & 0x1) == HIF_SPI) {
1979 /**
1980 * TODO:
1981 **/
1982 if (!hif_spi.hif_init(inp, wilc_debug)) {
1983 /* EIO 5 */
1984 ret = -5;
1985 goto _fail_;
1986 }
1987 memcpy((void *)&g_wlan.hif_func, &hif_spi, sizeof(wilc_hif_func_t));
1988 } else {
1989 /* EIO 5 */
1990 ret = -5;
1991 goto _fail_;
1992 }
1993 }
1994
1995 /***
1996 * mac interface init
1997 **/
Glen Lee814bc362015-10-02 14:22:11 +09001998 if (!wilc_wlan_cfg_init(wilc_debug)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001999 /* ENOBUFS 105 */
2000 ret = -105;
2001 goto _fail_;
2002 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002003
2004 /**
2005 * alloc tx, rx buffer
2006 **/
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002007 if (g_wlan.tx_buffer == NULL)
Glen Lee7015b5d2015-09-24 18:15:02 +09002008 g_wlan.tx_buffer = kmalloc(LINUX_TX_SIZE, GFP_KERNEL);
Arnd Bergmann7a8fd842015-06-01 21:06:45 +02002009 PRINT_D(TX_DBG, "g_wlan.tx_buffer = %p\n", g_wlan.tx_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002010
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002011 if (g_wlan.tx_buffer == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002012 /* ENOBUFS 105 */
2013 ret = -105;
2014 PRINT_ER("Can't allocate Tx Buffer");
2015 goto _fail_;
2016 }
2017
2018/* rx_buffer is not used unless we activate USE_MEM STATIC which is not applicable, allocating such memory is useless*/
2019#if defined (MEMORY_STATIC)
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002020 if (g_wlan.rx_buffer == NULL)
Glen Lee03eb7262015-09-24 18:15:03 +09002021 g_wlan.rx_buffer = kmalloc(LINUX_RX_SIZE, GFP_KERNEL);
Arnd Bergmann7a8fd842015-06-01 21:06:45 +02002022 PRINT_D(TX_DBG, "g_wlan.rx_buffer =%p\n", g_wlan.rx_buffer);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002023 if (g_wlan.rx_buffer == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002024 /* ENOBUFS 105 */
2025 ret = -105;
2026 PRINT_ER("Can't allocate Rx Buffer");
2027 goto _fail_;
2028 }
2029#endif
2030
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002031 if (!init_chip()) {
2032 /* EIO 5 */
2033 ret = -5;
2034 goto _fail_;
2035 }
2036#ifdef TCP_ACK_FILTER
2037 Init_TCP_tracking();
2038#endif
2039
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002040 return 1;
2041
2042_fail_:
2043
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002044 #ifdef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07002045 kfree(g_wlan.rx_buffer);
2046 g_wlan.rx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002047 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07002048 kfree(g_wlan.tx_buffer);
2049 g_wlan.tx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002050
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002051 return ret;
2052
2053}
2054
Glen Lee178c3832015-10-27 18:27:58 +09002055u16 Set_machw_change_vir_if(struct net_device *dev, bool bValue)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002056{
Chaehyun Limd85f5322015-06-11 14:35:54 +09002057 u16 ret;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002058 u32 reg;
Glen Lee178c3832015-10-27 18:27:58 +09002059 perInterface_wlan_t *nic;
2060 struct wilc *wilc;
2061
2062 nic = netdev_priv(dev);
2063 wilc = nic->wilc;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002064
2065 /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
Glen Lee178c3832015-10-27 18:27:58 +09002066 mutex_lock(&wilc->hif_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002067 ret = (&g_wlan)->hif_func.hif_read_reg(WILC_CHANGING_VIR_IF, &reg);
Alison Schofield39823a52015-10-08 21:18:03 -07002068 if (!ret)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002069 PRINT_ER("Error while Reading reg WILC_CHANGING_VIR_IF\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002070
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05302071 if (bValue)
Chaehyun Lim50b51da2015-09-16 20:11:26 +09002072 reg |= BIT(31);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05302073 else
Chaehyun Lim50b51da2015-09-16 20:11:26 +09002074 reg &= ~BIT(31);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002075
2076 ret = (&g_wlan)->hif_func.hif_write_reg(WILC_CHANGING_VIR_IF, reg);
2077
Alison Schofield39823a52015-10-08 21:18:03 -07002078 if (!ret)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002079 PRINT_ER("Error while writing reg WILC_CHANGING_VIR_IF\n");
Alison Schofield39823a52015-10-08 21:18:03 -07002080
Glen Lee178c3832015-10-27 18:27:58 +09002081 mutex_unlock(&wilc->hif_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002082
2083 return ret;
2084}