blob: 14a56d69c665f0b0c295fe49e4e29c8a46856dff [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
162static struct txq_entry_t *wilc_wlan_txq_remove_from_head(void)
163{
164 struct txq_entry_t *tqe;
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530165 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900166 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900167
Glen Lee85e57562015-09-24 18:14:56 +0900168 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900169 if (p->txq_head) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900170 tqe = p->txq_head;
171 p->txq_head = tqe->next;
Alison Schofield39823a52015-10-08 21:18:03 -0700172 if (p->txq_head)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900173 p->txq_head->prev = NULL;
Alison Schofield39823a52015-10-08 21:18:03 -0700174
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900175 p->txq_entries -= 1;
176
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900177
178
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900179
180 } else {
181 tqe = NULL;
182 }
Glen Lee85e57562015-09-24 18:14:56 +0900183 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900184 return tqe;
185}
186
187static void wilc_wlan_txq_add_to_tail(struct txq_entry_t *tqe)
188{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530189 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900190 unsigned long flags;
Glen Lee85e57562015-09-24 18:14:56 +0900191 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900192
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900193 if (p->txq_head == NULL) {
194 tqe->next = NULL;
195 tqe->prev = NULL;
196 p->txq_head = tqe;
197 p->txq_tail = tqe;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900198 } else {
199 tqe->next = NULL;
200 tqe->prev = p->txq_tail;
201 p->txq_tail->next = tqe;
202 p->txq_tail = tqe;
203 }
204 p->txq_entries += 1;
205 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900206
Glen Lee85e57562015-09-24 18:14:56 +0900207 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900208
209 /**
210 * wake up TX queue
211 **/
212 PRINT_D(TX_DBG, "Wake the txq_handling\n");
213
Glen Lee5cd63632015-09-24 18:14:58 +0900214 up(&g_linux_wlan->txq_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900215}
216
217static int wilc_wlan_txq_add_to_head(struct txq_entry_t *tqe)
218{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530219 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900220 unsigned long flags;
Glen Leeb002e202015-09-24 18:15:05 +0900221 if (linux_wlan_lock_timeout(&g_linux_wlan->txq_add_to_head_cs,
222 CFG_PKTS_TIMEOUT))
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900223 return -1;
224
Glen Lee85e57562015-09-24 18:14:56 +0900225 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900226
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900227 if (p->txq_head == NULL) {
228 tqe->next = NULL;
229 tqe->prev = NULL;
230 p->txq_head = tqe;
231 p->txq_tail = tqe;
232 } else {
233 tqe->next = p->txq_head;
234 tqe->prev = NULL;
235 p->txq_head->prev = tqe;
236 p->txq_head = tqe;
237 }
238 p->txq_entries += 1;
239 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900240
Glen Lee85e57562015-09-24 18:14:56 +0900241 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Glen Leed5a63a82015-09-24 18:15:00 +0900242 up(&g_linux_wlan->txq_add_to_head_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900243
244
245 /**
246 * wake up TX queue
247 **/
Glen Lee5cd63632015-09-24 18:14:58 +0900248 up(&g_linux_wlan->txq_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900249 PRINT_D(TX_DBG, "Wake up the txq_handler\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900250
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900251 return 0;
252
253}
254
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900255u32 Statisitcs_totalAcks = 0, Statisitcs_DroppedAcks = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900256
257#ifdef TCP_ACK_FILTER
258struct Ack_session_info;
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530259struct Ack_session_info {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900260 u32 Ack_seq_num;
261 u32 Bigger_Ack_num;
Chaehyun Limec53adf2015-09-15 14:06:15 +0900262 u16 src_port;
263 u16 dst_port;
264 u16 status;
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530265};
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900266
267typedef struct {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900268 u32 ack_num;
269 u32 Session_index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900270 struct txq_entry_t *txqe;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900271} Pending_Acks_info_t /*Ack_info_t*/;
272
273
274
275
276struct Ack_session_info *Free_head;
277struct Ack_session_info *Alloc_head;
278
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900279#define NOT_TCP_ACK (-1)
280
281#define MAX_TCP_SESSION 25
282#define MAX_PENDING_ACKS 256
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530283struct Ack_session_info Acks_keep_track_info[2 * MAX_TCP_SESSION];
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900284Pending_Acks_info_t Pending_Acks_info[MAX_PENDING_ACKS];
285
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900286u32 PendingAcks_arrBase;
287u32 Opened_TCP_session;
288u32 Pending_Acks;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900289
290
291
Chaehyun Limfed16f22015-09-17 16:48:43 +0900292static inline int Init_TCP_tracking(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900293{
294
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900295 return 0;
296
297}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900298static inline int add_TCP_track_session(u32 src_prt, u32 dst_prt, u32 seq)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900299{
300 Acks_keep_track_info[Opened_TCP_session].Ack_seq_num = seq;
301 Acks_keep_track_info[Opened_TCP_session].Bigger_Ack_num = 0;
302 Acks_keep_track_info[Opened_TCP_session].src_port = src_prt;
303 Acks_keep_track_info[Opened_TCP_session].dst_port = dst_prt;
304 Opened_TCP_session++;
305
306 PRINT_D(TCP_ENH, "TCP Session %d to Ack %d\n", Opened_TCP_session, seq);
307 return 0;
308}
309
Chaehyun Limfed16f22015-09-17 16:48:43 +0900310static inline int Update_TCP_track_session(u32 index, u32 Ack)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900311{
312
Alison Schofield39823a52015-10-08 21:18:03 -0700313 if (Ack > Acks_keep_track_info[index].Bigger_Ack_num)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900314 Acks_keep_track_info[index].Bigger_Ack_num = Ack;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900315 return 0;
316
317}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900318static inline int add_TCP_Pending_Ack(u32 Ack, u32 Session_index, struct txq_entry_t *txqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900319{
320 Statisitcs_totalAcks++;
321 if (Pending_Acks < MAX_PENDING_ACKS) {
322 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].ack_num = Ack;
323 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].txqe = txqe;
324 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].Session_index = Session_index;
325 txqe->tcp_PendingAck_index = PendingAcks_arrBase + Pending_Acks;
326 Pending_Acks++;
327
328 } else {
329
330 }
331 return 0;
332}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900333static inline int remove_TCP_related(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900334{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530335 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900336 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900337
Glen Lee85e57562015-09-24 18:14:56 +0900338 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900339
Glen Lee85e57562015-09-24 18:14:56 +0900340 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900341 return 0;
342}
343
Chaehyun Limfed16f22015-09-17 16:48:43 +0900344static inline int tcp_process(struct txq_entry_t *tqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900345{
346 int ret;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900347 u8 *eth_hdr_ptr;
348 u8 *buffer = tqe->buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900349 unsigned short h_proto;
350 int i;
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530351 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900352 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900353
Glen Lee85e57562015-09-24 18:14:56 +0900354 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900355
356 eth_hdr_ptr = &buffer[0];
357 h_proto = ntohs(*((unsigned short *)&eth_hdr_ptr[12]));
358 if (h_proto == 0x0800) { /* IP */
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900359 u8 *ip_hdr_ptr;
360 u8 protocol;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900361
362 ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN];
363 protocol = ip_hdr_ptr[9];
364
365
366 if (protocol == 0x06) {
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900367 u8 *tcp_hdr_ptr;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900368 u32 IHL, Total_Length, Data_offset;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900369
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900370 tcp_hdr_ptr = &ip_hdr_ptr[IP_HDR_LEN];
371 IHL = (ip_hdr_ptr[0] & 0xf) << 2;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900372 Total_Length = (((u32)ip_hdr_ptr[2]) << 8) + ((u32)ip_hdr_ptr[3]);
373 Data_offset = (((u32)tcp_hdr_ptr[12] & 0xf0) >> 2);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900374 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 +0900375 u32 seq_no, Ack_no;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900376
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900377 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 +0900378
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900379 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 +0900380
381
382 for (i = 0; i < Opened_TCP_session; i++) {
383 if (Acks_keep_track_info[i].Ack_seq_num == seq_no) {
384 Update_TCP_track_session(i, Ack_no);
385 break;
386 }
387 }
Alison Schofield39823a52015-10-08 21:18:03 -0700388 if (i == Opened_TCP_session)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900389 add_TCP_track_session(0, 0, seq_no);
Alison Schofield39823a52015-10-08 21:18:03 -0700390
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900391 add_TCP_Pending_Ack(Ack_no, i, tqe);
392
393
394 }
395
396 } else {
397 ret = 0;
398 }
399 } else {
400 ret = 0;
401 }
Glen Lee85e57562015-09-24 18:14:56 +0900402 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900403 return ret;
404}
405
406
Glen Leec029e992015-10-27 18:27:48 +0900407static int wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900408{
Glen Leec029e992015-10-27 18:27:48 +0900409 perInterface_wlan_t *nic;
410 struct wilc *wilc;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900411 u32 i = 0;
412 u32 Dropped = 0;
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530413 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900414
Glen Leec029e992015-10-27 18:27:48 +0900415 nic = netdev_priv(dev);
416 wilc = nic->wilc;
417
418 spin_lock_irqsave(&wilc->txq_spinlock, p->txq_spinlock_flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900419 for (i = PendingAcks_arrBase; i < (PendingAcks_arrBase + Pending_Acks); i++) {
420 if (Pending_Acks_info[i].ack_num < Acks_keep_track_info[Pending_Acks_info[i].Session_index].Bigger_Ack_num) {
421 struct txq_entry_t *tqe;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900422
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530423 PRINT_D(TCP_ENH, "DROP ACK: %u\n", Pending_Acks_info[i].ack_num);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900424 tqe = Pending_Acks_info[i].txqe;
425 if (tqe) {
426 wilc_wlan_txq_remove(tqe);
427 Statisitcs_DroppedAcks++;
428 tqe->status = 1; /* mark the packet send */
429 if (tqe->tx_complete_func)
430 tqe->tx_complete_func(tqe->priv, tqe->status);
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -0700431 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900432 Dropped++;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900433 }
434 }
435 }
436 Pending_Acks = 0;
437 Opened_TCP_session = 0;
438
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530439 if (PendingAcks_arrBase == 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900440 PendingAcks_arrBase = MAX_TCP_SESSION;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530441 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900442 PendingAcks_arrBase = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900443
444
Glen Leec029e992015-10-27 18:27:48 +0900445 spin_unlock_irqrestore(&wilc->txq_spinlock, p->txq_spinlock_flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900446
447 while (Dropped > 0) {
448 /*consume the semaphore count of the removed packet*/
Glen Leec029e992015-10-27 18:27:48 +0900449 linux_wlan_lock_timeout(&wilc->txq_event, 1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900450 Dropped--;
451 }
452
453 return 1;
454}
455#endif
456
Dean Lee72ed4dc2015-06-12 14:11:44 +0900457bool EnableTCPAckFilter = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900458
Dean Lee72ed4dc2015-06-12 14:11:44 +0900459void Enable_TCP_ACK_Filter(bool value)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900460{
461 EnableTCPAckFilter = value;
462}
463
Dean Lee72ed4dc2015-06-12 14:11:44 +0900464bool is_TCP_ACK_Filter_Enabled(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900465{
466 return EnableTCPAckFilter;
467}
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900468
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900469static int wilc_wlan_txq_add_cfg_pkt(u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900470{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530471 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900472 struct txq_entry_t *tqe;
473
474 PRINT_D(TX_DBG, "Adding config packet ...\n");
475 if (p->quit) {
476 PRINT_D(TX_DBG, "Return due to clear function\n");
Glen Lee6a3b94f2015-09-24 18:14:59 +0900477 up(&g_linux_wlan->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900478 return 0;
479 }
480
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700481 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900482 if (tqe == NULL) {
483 PRINT_ER("Failed to allocate memory\n");
484 return 0;
485 }
486
487 tqe->type = WILC_CFG_PKT;
488 tqe->buffer = buffer;
489 tqe->buffer_size = buffer_size;
490 tqe->tx_complete_func = NULL;
491 tqe->priv = NULL;
492#ifdef TCP_ACK_FILTER
493 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
494#endif
495 /**
496 * Configuration packet always at the front
497 **/
498 PRINT_D(TX_DBG, "Adding the config packet at the Queue tail\n");
499
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900500 if (wilc_wlan_txq_add_to_head(tqe))
501 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900502 return 1;
503}
504
Glen Lee691bbd42015-10-27 18:28:02 +0900505int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
506 u32 buffer_size, wilc_tx_complete_func_t func)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900507{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530508 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900509 struct txq_entry_t *tqe;
510
511 if (p->quit)
512 return 0;
513
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700514 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900515
516 if (tqe == NULL)
517 return 0;
518 tqe->type = WILC_NET_PKT;
519 tqe->buffer = buffer;
520 tqe->buffer_size = buffer_size;
521 tqe->tx_complete_func = func;
522 tqe->priv = priv;
523
524 PRINT_D(TX_DBG, "Adding mgmt packet at the Queue tail\n");
525#ifdef TCP_ACK_FILTER
526 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
Abdul Hussain5a66bf22015-06-16 09:44:06 +0000527 if (is_TCP_ACK_Filter_Enabled())
Glen Lee25a84832015-09-16 18:53:22 +0900528 tcp_process(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900529#endif
530 wilc_wlan_txq_add_to_tail(tqe);
531 /*return number of itemes in the queue*/
532 return p->txq_entries;
533}
Glen Leefcc6ef92015-09-16 18:53:21 +0900534
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900535int wilc_wlan_txq_add_mgmt_pkt(void *priv, u8 *buffer, u32 buffer_size, wilc_tx_complete_func_t func)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900536{
537
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530538 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900539 struct txq_entry_t *tqe;
540
541 if (p->quit)
542 return 0;
543
Greg Kroah-Hartman47c632d2015-09-03 18:55:43 -0700544 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900545
546 if (tqe == NULL)
547 return 0;
548 tqe->type = WILC_MGMT_PKT;
549 tqe->buffer = buffer;
550 tqe->buffer_size = buffer_size;
551 tqe->tx_complete_func = func;
552 tqe->priv = priv;
553#ifdef TCP_ACK_FILTER
554 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
555#endif
556 PRINT_D(TX_DBG, "Adding Network packet at the Queue tail\n");
557 wilc_wlan_txq_add_to_tail(tqe);
558 return 1;
559}
Glen Leefcc6ef92015-09-16 18:53:21 +0900560
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900561static struct txq_entry_t *wilc_wlan_txq_get_first(void)
562{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530563 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900564 struct txq_entry_t *tqe;
565 unsigned long flags;
566
Glen Lee85e57562015-09-24 18:14:56 +0900567 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900568
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900569 tqe = p->txq_head;
570
Glen Lee85e57562015-09-24 18:14:56 +0900571 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900572
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900573
574 return tqe;
575}
576
Glen Lee50a0b3b2015-10-27 18:28:00 +0900577static struct txq_entry_t *wilc_wlan_txq_get_next(struct wilc *wilc,
578 struct txq_entry_t *tqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900579{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900580 unsigned long flags;
Glen Lee50a0b3b2015-10-27 18:28:00 +0900581 spin_lock_irqsave(&wilc->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900582
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900583 tqe = tqe->next;
Glen Lee50a0b3b2015-10-27 18:28:00 +0900584 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900585
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900586
587 return tqe;
588}
589
Glen Leed06f3622015-10-27 18:27:59 +0900590static int wilc_wlan_rxq_add(struct wilc *wilc, struct rxq_entry_t *rqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900591{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530592 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900593
594 if (p->quit)
595 return 0;
596
Glen Leed06f3622015-10-27 18:27:59 +0900597 mutex_lock(&wilc->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900598 if (p->rxq_head == NULL) {
599 PRINT_D(RX_DBG, "Add to Queue head\n");
600 rqe->next = NULL;
601 p->rxq_head = rqe;
602 p->rxq_tail = rqe;
603 } else {
604 PRINT_D(RX_DBG, "Add to Queue tail\n");
605 p->rxq_tail->next = rqe;
606 rqe->next = NULL;
607 p->rxq_tail = rqe;
608 }
609 p->rxq_entries += 1;
610 PRINT_D(RX_DBG, "Number of queue entries: %d\n", p->rxq_entries);
Glen Leed06f3622015-10-27 18:27:59 +0900611 mutex_unlock(&wilc->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900612 return p->rxq_entries;
613}
614
Glen Leedb387632015-10-27 18:27:55 +0900615static struct rxq_entry_t *wilc_wlan_rxq_remove(struct wilc *wilc)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900616{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530617 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900618
619 PRINT_D(RX_DBG, "Getting rxQ element\n");
620 if (p->rxq_head) {
621 struct rxq_entry_t *rqe;
622
Glen Leedb387632015-10-27 18:27:55 +0900623 mutex_lock(&wilc->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900624 rqe = p->rxq_head;
625 p->rxq_head = p->rxq_head->next;
626 p->rxq_entries -= 1;
627 PRINT_D(RX_DBG, "RXQ entries decreased\n");
Glen Leedb387632015-10-27 18:27:55 +0900628 mutex_unlock(&wilc->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900629 return rqe;
630 }
631 PRINT_D(RX_DBG, "Nothing to get from Q\n");
632 return NULL;
633}
634
635
636/********************************************
637 *
638 * Power Save handle functions
639 *
640 ********************************************/
641
642
643
644#ifdef WILC_OPTIMIZE_SLEEP_INT
645
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900646static inline void chip_allow_sleep(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900647{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900648 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900649
650 /* Clear bit 1 */
651 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
652
Anish Bhattffda2032015-09-29 12:15:49 -0700653 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900654}
655
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900656static inline void chip_wakeup(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900657{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900658 u32 reg, clk_status_reg, trials = 0;
659 u32 sleep_time;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900660
661 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
662 do {
663 g_wlan.hif_func.hif_read_reg(1, &reg);
664 /* Set bit 1 */
Anish Bhattffda2032015-09-29 12:15:49 -0700665 g_wlan.hif_func.hif_write_reg(1, reg | BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900666
667 /* Clear bit 1*/
Anish Bhattffda2032015-09-29 12:15:49 -0700668 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900669
670 do {
671 /* Wait for the chip to stabilize*/
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -0700672 usleep_range(2 * 1000, 2 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900673 /* Make sure chip is awake. This is an extra step that can be removed */
674 /* later to avoid the bus access overhead */
Alison Schofield39823a52015-10-08 21:18:03 -0700675 if ((wilc_get_chipid(true) == 0))
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900676 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
Alison Schofield39823a52015-10-08 21:18:03 -0700677
Dean Lee72ed4dc2015-06-12 14:11:44 +0900678 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900679
Dean Lee72ed4dc2015-06-12 14:11:44 +0900680 } while (wilc_get_chipid(true) == 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900681 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
682 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
683 do {
684 /* Set bit 1 */
Anish Bhattffda2032015-09-29 12:15:49 -0700685 g_wlan.hif_func.hif_write_reg(0xf0, reg | BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900686
687 /* Check the clock status */
688 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
689
690 /* in case of clocks off, wait 2ms, and check it again. */
691 /* if still off, wait for another 2ms, for a total wait of 6ms. */
692 /* If still off, redo the wake up sequence */
693 while (((clk_status_reg & 0x1) == 0) && (((++trials) % 3) == 0)) {
694 /* Wait for the chip to stabilize*/
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -0700695 usleep_range(2 * 1000, 2 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900696
697 /* Make sure chip is awake. This is an extra step that can be removed */
698 /* later to avoid the bus access overhead */
699 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
700
Alison Schofield39823a52015-10-08 21:18:03 -0700701 if ((clk_status_reg & 0x1) == 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900702 wilc_debug(N_ERR, "clocks still OFF. Wake up failed\n");
Alison Schofield39823a52015-10-08 21:18:03 -0700703
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900704 }
705 /* in case of failure, Reset the wakeup bit to introduce a new edge on the next loop */
706 if ((clk_status_reg & 0x1) == 0) {
707 /* Reset bit 0 */
Anish Bhattffda2032015-09-29 12:15:49 -0700708 g_wlan.hif_func.hif_write_reg(0xf0, reg &
709 (~BIT(0)));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900710 }
711 } while ((clk_status_reg & 0x1) == 0);
712 }
713
714
715 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
716 g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -0700717 reg &= ~BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900718 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
719
Dean Lee72ed4dc2015-06-12 14:11:44 +0900720 if (wilc_get_chipid(false) >= 0x1002b0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900721 /* Enable PALDO back right after wakeup */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900722 u32 val32;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900723
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900724 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700725 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900726 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
727
728 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700729 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900730 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
731 }
732 }
733 genuChipPSstate = CHIP_WAKEDUP;
734}
735#else
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900736static inline void chip_wakeup(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900737{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900738 u32 reg, trials = 0;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900739
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900740 do {
741 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
742 g_wlan.hif_func.hif_read_reg(1, &reg);
743 /* Make sure bit 1 is 0 before we start. */
Anish Bhattffda2032015-09-29 12:15:49 -0700744 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900745 /* Set bit 1 */
Anish Bhattffda2032015-09-29 12:15:49 -0700746 g_wlan.hif_func.hif_write_reg(1, reg | BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900747 /* Clear bit 1*/
Anish Bhattffda2032015-09-29 12:15:49 -0700748 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900749 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
750 /* Make sure bit 0 is 0 before we start. */
751 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -0700752 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900753 /* Set bit 1 */
Anish Bhattffda2032015-09-29 12:15:49 -0700754 g_wlan.hif_func.hif_write_reg(0xf0, reg | BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900755 /* Clear bit 1 */
Anish Bhattffda2032015-09-29 12:15:49 -0700756 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900757 }
758
759 do {
760 /* Wait for the chip to stabilize*/
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900761 mdelay(3);
762
763 /* Make sure chip is awake. This is an extra step that can be removed */
764 /* later to avoid the bus access overhead */
Alison Schofield39823a52015-10-08 21:18:03 -0700765 if ((wilc_get_chipid(true) == 0))
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900766 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
Alison Schofield39823a52015-10-08 21:18:03 -0700767
Dean Lee72ed4dc2015-06-12 14:11:44 +0900768 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900769
Dean Lee72ed4dc2015-06-12 14:11:44 +0900770 } while (wilc_get_chipid(true) == 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900771
772 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
773 g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -0700774 reg &= ~BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900775 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
776
Dean Lee72ed4dc2015-06-12 14:11:44 +0900777 if (wilc_get_chipid(false) >= 0x1002b0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900778 /* Enable PALDO back right after wakeup */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900779 u32 val32;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900780
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900781 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700782 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900783 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
784
785 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700786 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900787 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
788 }
789 }
790 genuChipPSstate = CHIP_WAKEDUP;
791}
792#endif
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900793void chip_sleep_manually(u32 u32SleepTime)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900794{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900795 if (genuChipPSstate != CHIP_WAKEDUP) {
796 /* chip is already sleeping. Do nothing */
797 return;
798 }
799 acquire_bus(ACQUIRE_ONLY);
800
801#ifdef WILC_OPTIMIZE_SLEEP_INT
802 chip_allow_sleep();
803#endif
804
805 /* Trigger the manual sleep interrupt */
806 g_wlan.hif_func.hif_write_reg(0x10a8, 1);
807
808 genuChipPSstate = CHIP_SLEEPING_MANUAL;
809 release_bus(RELEASE_ONLY);
810
811}
812
813
814/********************************************
815 *
816 * Tx, Rx queue handle functions
817 *
818 ********************************************/
Glen Leea1332ca2015-10-27 18:27:47 +0900819int wilc_wlan_handle_txq(struct net_device *dev, u32 *pu32TxqCount)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900820{
821 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
822 int i, entries = 0;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900823 u32 sum;
824 u32 reg;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900825 u8 *txb = p->tx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900826 u32 offset = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900827 int vmm_sz = 0;
828 struct txq_entry_t *tqe;
829 int ret = 0;
830 int counter;
831 int timeout;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900832 u32 vmm_table[WILC_VMM_TBL_SIZE];
Glen Leea1332ca2015-10-27 18:27:47 +0900833 perInterface_wlan_t *nic;
834 struct wilc *wilc;
835
836 nic = netdev_priv(dev);
837 wilc = nic->wilc;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900838
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900839 p->txq_exit = 0;
840 do {
841 if (p->quit)
842 break;
843
Glen Leea1332ca2015-10-27 18:27:47 +0900844 linux_wlan_lock_timeout(&wilc->txq_add_to_head_cs,
Glen Leeb002e202015-09-24 18:15:05 +0900845 CFG_PKTS_TIMEOUT);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900846#ifdef TCP_ACK_FILTER
Glen Leec029e992015-10-27 18:27:48 +0900847 wilc_wlan_txq_filter_dup_tcp_ack(dev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900848#endif
849 /**
850 * build the vmm list
851 **/
852 PRINT_D(TX_DBG, "Getting the head of the TxQ\n");
853 tqe = wilc_wlan_txq_get_first();
854 i = 0;
855 sum = 0;
856 do {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900857 if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE - 1)) /* reserve last entry to 0 */) {
858
Alison Schofield39823a52015-10-08 21:18:03 -0700859 if (tqe->type == WILC_CFG_PKT)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900860 vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET;
Alison Schofield39823a52015-10-08 21:18:03 -0700861
862 else if (tqe->type == WILC_NET_PKT)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900863 vmm_sz = ETH_ETHERNET_HDR_OFFSET;
Alison Schofield39823a52015-10-08 21:18:03 -0700864
865 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900866 vmm_sz = HOST_HDR_OFFSET;
Alison Schofield39823a52015-10-08 21:18:03 -0700867
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900868 vmm_sz += tqe->buffer_size;
869 PRINT_D(TX_DBG, "VMM Size before alignment = %d\n", vmm_sz);
870 if (vmm_sz & 0x3) { /* has to be word aligned */
871 vmm_sz = (vmm_sz + 4) & ~0x3;
872 }
Alison Schofield39823a52015-10-08 21:18:03 -0700873 if ((sum + vmm_sz) > LINUX_TX_SIZE)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900874 break;
Alison Schofield39823a52015-10-08 21:18:03 -0700875
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900876 PRINT_D(TX_DBG, "VMM Size AFTER alignment = %d\n", vmm_sz);
877 vmm_table[i] = vmm_sz / 4; /* table take the word size */
878 PRINT_D(TX_DBG, "VMMTable entry size = %d\n", vmm_table[i]);
879
880 if (tqe->type == WILC_CFG_PKT) {
Anish Bhattffda2032015-09-29 12:15:49 -0700881 vmm_table[i] |= BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900882 PRINT_D(TX_DBG, "VMMTable entry changed for CFG packet = %d\n", vmm_table[i]);
883 }
884#ifdef BIG_ENDIAN
885 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
886#endif
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900887
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900888 i++;
889 sum += vmm_sz;
890 PRINT_D(TX_DBG, "sum = %d\n", sum);
Glen Lee50a0b3b2015-10-27 18:28:00 +0900891 tqe = wilc_wlan_txq_get_next(wilc, tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900892 } else {
893 break;
894 }
895 } while (1);
896
897 if (i == 0) { /* nothing in the queue */
898 PRINT_D(TX_DBG, "Nothing in TX-Q\n");
899 break;
900 } else {
901 PRINT_D(TX_DBG, "Mark the last entry in VMM table - number of previous entries = %d\n", i);
902 vmm_table[i] = 0x0; /* mark the last element to 0 */
903 }
904 acquire_bus(ACQUIRE_AND_WAKEUP);
905 counter = 0;
906 do {
907
908 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg);
909 if (!ret) {
910 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg vmm_tbl_entry..\n");
911 break;
912 }
913
914 if ((reg & 0x1) == 0) {
915 /**
916 * write to vmm table
917 **/
918 PRINT_D(TX_DBG, "Writing VMM table ... with Size = %d\n", ((i + 1) * 4));
919 break;
920 } else {
921 counter++;
922 if (counter > 200) {
923 counter = 0;
924 PRINT_D(TX_DBG, "Looping in tx ctrl , forcce quit\n");
925 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, 0);
926 break;
927 }
928 /**
929 * wait for vmm table is ready
930 **/
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530931 PRINT_WRN(GENERIC_DBG, "[wilc txq]: warn, vmm table not clear yet, wait...\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900932 release_bus(RELEASE_ALLOW_SLEEP);
Greg Kroah-Hartman2b922cb2015-09-04 09:30:51 -0700933 usleep_range(3000, 3000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900934 acquire_bus(ACQUIRE_AND_WAKEUP);
935 }
936 } while (!p->quit);
937
Alison Schofield39823a52015-10-08 21:18:03 -0700938 if (!ret)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900939 goto _end_;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900940
941 timeout = 200;
942 do {
943
944 /**
945 * write to vmm table
946 **/
Chaehyun Limc3ca6372015-09-20 15:51:19 +0900947 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 +0900948 if (!ret) {
949 wilc_debug(N_ERR, "ERR block TX of VMM table.\n");
950 break;
951 }
952
953
954 /**
955 * interrupt firmware
956 **/
957 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x2);
958 if (!ret) {
959 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg host_vmm_ctl..\n");
960 break;
961 }
962
963 /**
964 * wait for confirm...
965 **/
966
967 do {
968 ret = p->hif_func.hif_read_reg(WILC_HOST_VMM_CTL, &reg);
969 if (!ret) {
970 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg host_vmm_ctl..\n");
971 break;
972 }
973 if ((reg >> 2) & 0x1) {
974 /**
975 * Get the entries
976 **/
977 entries = ((reg >> 3) & 0x3f);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900978 break;
979 } else {
980 release_bus(RELEASE_ALLOW_SLEEP);
Greg Kroah-Hartman2b922cb2015-09-04 09:30:51 -0700981 usleep_range(3000, 3000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900982 acquire_bus(ACQUIRE_AND_WAKEUP);
983 PRINT_WRN(GENERIC_DBG, "Can't get VMM entery - reg = %2x\n", reg);
984 }
985 } while (--timeout);
986 if (timeout <= 0) {
987 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x0);
988 break;
989 }
990
Alison Schofield39823a52015-10-08 21:18:03 -0700991 if (!ret)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900992 break;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900993
994 if (entries == 0) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530995 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 +0900996
997 /* undo the transaction. */
998 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg);
999 if (!ret) {
1000 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg WILC_HOST_TX_CTRL..\n");
1001 break;
1002 }
Anish Bhattffda2032015-09-29 12:15:49 -07001003 reg &= ~BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001004 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, reg);
1005 if (!ret) {
1006 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg WILC_HOST_TX_CTRL..\n");
1007 break;
1008 }
1009 break;
1010 } else {
1011 break;
1012 }
1013 } while (1);
1014
Alison Schofield39823a52015-10-08 21:18:03 -07001015 if (!ret)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001016 goto _end_;
Alison Schofield39823a52015-10-08 21:18:03 -07001017
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001018 if (entries == 0) {
1019 ret = WILC_TX_ERR_NO_BUF;
1020 goto _end_;
1021 }
1022
1023 /* since copying data into txb takes some time, then
1024 * allow the bus lock to be released let the RX task go. */
1025 release_bus(RELEASE_ALLOW_SLEEP);
1026
1027 /**
1028 * Copy data to the TX buffer
1029 **/
1030 offset = 0;
1031 i = 0;
1032 do {
1033 tqe = wilc_wlan_txq_remove_from_head();
1034 if (tqe != NULL && (vmm_table[i] != 0)) {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001035 u32 header, buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001036
1037#ifdef BIG_ENDIAN
1038 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
1039#endif
1040 vmm_sz = (vmm_table[i] & 0x3ff); /* in word unit */
1041 vmm_sz *= 4;
1042 header = (tqe->type << 31) | (tqe->buffer_size << 15) | vmm_sz;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301043 if (tqe->type == WILC_MGMT_PKT)
Anish Bhattffda2032015-09-29 12:15:49 -07001044 header |= BIT(30);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301045 else
Anish Bhattffda2032015-09-29 12:15:49 -07001046 header &= ~BIT(30);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001047
1048#ifdef BIG_ENDIAN
1049 header = BYTE_SWAP(header);
1050#endif
1051 memcpy(&txb[offset], &header, 4);
1052 if (tqe->type == WILC_CFG_PKT) {
1053 buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET;
1054 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001055 else if (tqe->type == WILC_NET_PKT) {
1056 char *pBSSID = ((struct tx_complete_data *)(tqe->priv))->pBssid;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001057
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001058 buffer_offset = ETH_ETHERNET_HDR_OFFSET;
1059 /* copy the bssid at the sart of the buffer */
1060 memcpy(&txb[offset + 4], pBSSID, 6);
1061 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001062 else {
1063 buffer_offset = HOST_HDR_OFFSET;
1064 }
1065
1066 memcpy(&txb[offset + buffer_offset], tqe->buffer, tqe->buffer_size);
1067 offset += vmm_sz;
1068 i++;
1069 tqe->status = 1; /* mark the packet send */
1070 if (tqe->tx_complete_func)
1071 tqe->tx_complete_func(tqe->priv, tqe->status);
1072 #ifdef TCP_ACK_FILTER
Alison Schofield39823a52015-10-08 21:18:03 -07001073 if (tqe->tcp_PendingAck_index != NOT_TCP_ACK)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001074 Pending_Acks_info[tqe->tcp_PendingAck_index].txqe = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001075 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001076 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001077 } else {
1078 break;
1079 }
1080 } while (--entries);
1081
1082 /**
1083 * lock the bus
1084 **/
1085 acquire_bus(ACQUIRE_AND_WAKEUP);
1086
1087 ret = p->hif_func.hif_clear_int_ext(ENABLE_TX_VMM);
1088 if (!ret) {
1089 wilc_debug(N_ERR, "[wilc txq]: fail can't start tx VMM ...\n");
1090 goto _end_;
1091 }
1092
1093 /**
1094 * transfer
1095 **/
1096 ret = p->hif_func.hif_block_tx_ext(0, txb, offset);
1097 if (!ret) {
1098 wilc_debug(N_ERR, "[wilc txq]: fail can't block tx ext...\n");
1099 goto _end_;
1100 }
1101
1102_end_:
1103
1104 release_bus(RELEASE_ALLOW_SLEEP);
1105 if (ret != 1)
1106 break;
1107 } while (0);
Glen Leea1332ca2015-10-27 18:27:47 +09001108 up(&wilc->txq_add_to_head_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001109
1110 p->txq_exit = 1;
1111 PRINT_D(TX_DBG, "THREAD: Exiting txq\n");
1112 /* return tx[]q count */
1113 *pu32TxqCount = p->txq_entries;
1114 return ret;
1115}
1116
Glen Lee39ce4d32015-10-27 18:27:42 +09001117static void wilc_wlan_handle_rxq(struct wilc *wilc)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001118{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301119 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001120 int offset = 0, size, has_packet = 0;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001121 u8 *buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001122 struct rxq_entry_t *rqe;
1123
1124 p->rxq_exit = 0;
1125
1126
1127
1128
1129 do {
1130 if (p->quit) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301131 PRINT_D(RX_DBG, "exit 1st do-while due to Clean_UP function\n");
Glen Lee39ce4d32015-10-27 18:27:42 +09001132 up(&wilc->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001133 break;
1134 }
Glen Leedb387632015-10-27 18:27:55 +09001135 rqe = wilc_wlan_rxq_remove(wilc);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001136 if (rqe == NULL) {
1137 PRINT_D(RX_DBG, "nothing in the queue - exit 1st do-while\n");
1138 break;
1139 }
1140 buffer = rqe->buffer;
1141 size = rqe->buffer_size;
1142 PRINT_D(RX_DBG, "rxQ entery Size = %d - Address = %p\n", size, buffer);
1143 offset = 0;
1144
1145
1146
1147 do {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001148 u32 header;
1149 u32 pkt_len, pkt_offset, tp_len;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001150 int is_cfg_packet;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001151
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001152 PRINT_D(RX_DBG, "In the 2nd do-while\n");
1153 memcpy(&header, &buffer[offset], 4);
1154#ifdef BIG_ENDIAN
1155 header = BYTE_SWAP(header);
1156#endif
1157 PRINT_D(RX_DBG, "Header = %04x - Offset = %d\n", header, offset);
1158
1159
1160
1161 is_cfg_packet = (header >> 31) & 0x1;
1162 pkt_offset = (header >> 22) & 0x1ff;
1163 tp_len = (header >> 11) & 0x7ff;
1164 pkt_len = header & 0x7ff;
1165
1166 if (pkt_len == 0 || tp_len == 0) {
1167 wilc_debug(N_RXQ, "[wilc rxq]: data corrupt, packet len or tp_len is 0 [%d][%d]\n", pkt_len, tp_len);
1168 break;
1169 }
1170
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001171 #define IS_MANAGMEMENT 0x100
1172 #define IS_MANAGMEMENT_CALLBACK 0x080
1173 #define IS_MGMT_STATUS_SUCCES 0x040
1174
1175
1176 if (pkt_offset & IS_MANAGMEMENT) {
1177 /* reset mgmt indicator bit, to use pkt_offeset in furthur calculations */
1178 pkt_offset &= ~(IS_MANAGMEMENT | IS_MANAGMEMENT_CALLBACK | IS_MGMT_STATUS_SUCCES);
1179
Glen Lee11f4b2e2015-10-27 18:27:51 +09001180 WILC_WFI_mgmt_rx(wilc, &buffer[offset + HOST_HDR_OFFSET], pkt_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001181 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001182 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001183 {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001184
1185 if (!is_cfg_packet) {
Glen Lee63611672015-09-24 18:14:52 +09001186 if (pkt_len > 0) {
Glen Leecb1991a2015-10-27 18:27:56 +09001187 frmw_to_linux(wilc,
1188 &buffer[offset],
Glen Lee63611672015-09-24 18:14:52 +09001189 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);
Glen Leed06f3622015-10-27 18:27:59 +09001353 wilc_wlan_rxq_add(wilc, 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 Lee2de7cbe2015-10-27 18:27:54 +09001651void wilc_wlan_cleanup(struct net_device *dev)
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;
Glen Leedb387632015-10-27 18:27:55 +09001658 perInterface_wlan_t *nic;
1659 struct wilc *wilc;
1660
1661 nic = netdev_priv(dev);
1662 wilc = nic->wilc;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001663
1664 p->quit = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001665 do {
1666 tqe = wilc_wlan_txq_remove_from_head();
1667 if (tqe == NULL)
1668 break;
1669 if (tqe->tx_complete_func)
1670 tqe->tx_complete_func(tqe->priv, 0);
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001671 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001672 } while (1);
1673
1674 do {
Glen Leedb387632015-10-27 18:27:55 +09001675 rqe = wilc_wlan_rxq_remove(wilc);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001676 if (rqe == NULL)
1677 break;
Javier Martinez Canillas6a272242015-09-22 15:24:50 +02001678#ifndef MEMORY_STATIC
1679 kfree(rqe->buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001680#endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001681 kfree(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001682 } while (1);
1683
1684 /**
1685 * clean up buffer
1686 **/
1687
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001688 #ifdef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001689 kfree(p->rx_buffer);
1690 p->rx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001691 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001692 kfree(p->tx_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001693
1694 acquire_bus(ACQUIRE_AND_WAKEUP);
1695
1696
1697 ret = p->hif_func.hif_read_reg(WILC_GP_REG_0, &reg);
1698 if (!ret) {
1699 PRINT_ER("Error while reading reg\n");
1700 release_bus(RELEASE_ALLOW_SLEEP);
1701 }
1702 PRINT_ER("Writing ABORT reg\n");
1703 ret = p->hif_func.hif_write_reg(WILC_GP_REG_0, (reg | ABORT_INT));
1704 if (!ret) {
1705 PRINT_ER("Error while writing reg\n");
1706 release_bus(RELEASE_ALLOW_SLEEP);
1707 }
1708 release_bus(RELEASE_ALLOW_SLEEP);
1709 /**
1710 * io clean up
1711 **/
1712 p->hif_func.hif_deinit(NULL);
1713
1714}
1715
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001716static int wilc_wlan_cfg_commit(int type, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001717{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301718 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001719 wilc_cfg_frame_t *cfg = &p->cfg_frame;
1720 int total_len = p->cfg_frame_offset + 4 + DRIVER_HANDLER_SIZE;
1721 int seq_no = p->cfg_seq_no % 256;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001722 int driver_handler = (u32)drvHandler;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001723
1724
1725 /**
1726 * Set up header
1727 **/
1728 if (type == WILC_CFG_SET) { /* Set */
1729 cfg->wid_header[0] = 'W';
1730 } else { /* Query */
1731 cfg->wid_header[0] = 'Q';
1732 }
1733 cfg->wid_header[1] = seq_no; /* sequence number */
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001734 cfg->wid_header[2] = (u8)total_len;
1735 cfg->wid_header[3] = (u8)(total_len >> 8);
1736 cfg->wid_header[4] = (u8)driver_handler;
1737 cfg->wid_header[5] = (u8)(driver_handler >> 8);
1738 cfg->wid_header[6] = (u8)(driver_handler >> 16);
1739 cfg->wid_header[7] = (u8)(driver_handler >> 24);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001740 p->cfg_seq_no = seq_no;
1741
1742 /**
1743 * Add to TX queue
1744 **/
1745
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001746 if (!wilc_wlan_txq_add_cfg_pkt(&cfg->wid_header[0], total_len))
1747 return -1;
1748
1749 return 0;
1750}
1751
Glen Lee1028e5a2015-10-01 16:03:40 +09001752int wilc_wlan_cfg_set(int start, u32 wid, u8 *buffer, u32 buffer_size,
1753 int commit, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001754{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301755 wilc_wlan_dev_t *p = &g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001756 u32 offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001757 int ret_size;
1758
1759
1760 if (p->cfg_frame_in_use)
1761 return 0;
1762
1763 if (start)
1764 p->cfg_frame_offset = 0;
1765
1766 offset = p->cfg_frame_offset;
Glen Lee17e8f162015-10-02 14:22:07 +09001767 ret_size = wilc_wlan_cfg_set_wid(p->cfg_frame.frame, offset, (u16)wid,
1768 buffer, buffer_size);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001769 offset += ret_size;
1770 p->cfg_frame_offset = offset;
1771
1772 if (commit) {
1773 PRINT_D(TX_DBG, "[WILC]PACKET Commit with sequence number %d\n", p->cfg_seq_no);
1774 PRINT_D(RX_DBG, "Processing cfg_set()\n");
1775 p->cfg_frame_in_use = 1;
1776
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001777 if (wilc_wlan_cfg_commit(WILC_CFG_SET, drvHandler))
Chaehyun Lim5af6b852015-09-17 16:48:48 +09001778 ret_size = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001779
Glen Leeb002e202015-09-24 18:15:05 +09001780 if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event,
1781 CFG_PKTS_TIMEOUT)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001782 PRINT_D(TX_DBG, "Set Timed Out\n");
1783 ret_size = 0;
1784 }
1785 p->cfg_frame_in_use = 0;
1786 p->cfg_frame_offset = 0;
1787 p->cfg_seq_no += 1;
1788
1789 }
1790
1791 return ret_size;
1792}
Glen Lee07056a82015-10-01 16:03:41 +09001793int wilc_wlan_cfg_get(int start, u32 wid, int commit, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001794{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301795 wilc_wlan_dev_t *p = &g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001796 u32 offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001797 int ret_size;
1798
1799
1800 if (p->cfg_frame_in_use)
1801 return 0;
1802
1803 if (start)
1804 p->cfg_frame_offset = 0;
1805
1806 offset = p->cfg_frame_offset;
Glen Leeec1b86b2015-10-02 14:22:08 +09001807 ret_size = wilc_wlan_cfg_get_wid(p->cfg_frame.frame, offset, (u16)wid);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001808 offset += ret_size;
1809 p->cfg_frame_offset = offset;
1810
1811 if (commit) {
1812 p->cfg_frame_in_use = 1;
1813
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001814 if (wilc_wlan_cfg_commit(WILC_CFG_QUERY, drvHandler))
Chaehyun Lim5af6b852015-09-17 16:48:48 +09001815 ret_size = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001816
1817
Glen Leeb002e202015-09-24 18:15:05 +09001818 if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event,
1819 CFG_PKTS_TIMEOUT)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001820 PRINT_D(TX_DBG, "Get Timed Out\n");
1821 ret_size = 0;
1822 }
1823 PRINT_D(GENERIC_DBG, "[WILC]Get Response received\n");
1824 p->cfg_frame_in_use = 0;
1825 p->cfg_frame_offset = 0;
1826 p->cfg_seq_no += 1;
1827 }
1828
1829 return ret_size;
1830}
1831
Glen Lee894de36b2015-10-01 16:03:42 +09001832int wilc_wlan_cfg_get_val(u32 wid, u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001833{
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001834 int ret;
1835
Glen Lee355cca22015-10-02 14:22:09 +09001836 ret = wilc_wlan_cfg_get_wid_value((u16)wid, buffer, buffer_size);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001837
1838 return ret;
1839}
1840
1841void wilc_bus_set_max_speed(void)
1842{
1843
1844 /* Increase bus speed to max possible. */
1845 g_wlan.hif_func.hif_set_max_bus_speed();
1846}
1847
1848void wilc_bus_set_default_speed(void)
1849{
1850
1851 /* Restore bus speed to default. */
1852 g_wlan.hif_func.hif_set_default_bus_speed();
1853}
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001854u32 init_chip(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001855{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001856 u32 chipid;
1857 u32 reg, ret = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001858
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001859 acquire_bus(ACQUIRE_ONLY);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001860
Dean Lee72ed4dc2015-06-12 14:11:44 +09001861 chipid = wilc_get_chipid(true);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001862
1863
1864
1865 if ((chipid & 0xfff) != 0xa0) {
1866 /**
1867 * Avoid booting from boot ROM. Make sure that Drive IRQN [SDIO platform]
1868 * or SD_DAT3 [SPI platform] to ?1?
1869 **/
1870 /* Set cortus reset register to register control. */
1871 ret = g_wlan.hif_func.hif_read_reg(0x1118, &reg);
1872 if (!ret) {
1873 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1118 ...\n");
1874 return ret;
1875 }
Anish Bhattffda2032015-09-29 12:15:49 -07001876 reg |= BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001877 ret = g_wlan.hif_func.hif_write_reg(0x1118, reg);
1878 if (!ret) {
1879 wilc_debug(N_ERR, "[wilc start]: fail write reg 0x1118 ...\n");
1880 return ret;
1881 }
1882 /**
1883 * Write branch intruction to IRAM (0x71 trap) at location 0xFFFF0000
1884 * (Cortus map) or C0000 (AHB map).
1885 **/
1886 ret = g_wlan.hif_func.hif_write_reg(0xc0000, 0x71);
1887 if (!ret) {
1888 wilc_debug(N_ERR, "[wilc start]: fail write reg 0xc0000 ...\n");
1889 return ret;
1890 }
1891 }
1892
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001893 release_bus(RELEASE_ONLY);
1894
1895 return ret;
1896
1897}
1898
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001899u32 wilc_get_chipid(u8 update)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001900{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001901 static u32 chipid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001902 /* SDIO can't read into global variables */
1903 /* Use this variable as a temp, then copy to the global */
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001904 u32 tempchipid = 0;
1905 u32 rfrevid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001906
1907 if (chipid == 0 || update != 0) {
1908 g_wlan.hif_func.hif_read_reg(0x1000, &tempchipid);
1909 g_wlan.hif_func.hif_read_reg(0x13f4, &rfrevid);
1910 if (!ISWILC1000(tempchipid)) {
1911 chipid = 0;
1912 goto _fail_;
1913 }
1914 if (tempchipid == 0x1002a0) {
1915 if (rfrevid == 0x1) { /* 1002A0 */
1916 } else { /* if (rfrevid == 0x2) */ /* 1002A1 */
1917 tempchipid = 0x1002a1;
1918 }
1919 } else if (tempchipid == 0x1002b0) {
1920 if (rfrevid == 3) { /* 1002B0 */
1921 } else if (rfrevid == 4) { /* 1002B1 */
1922 tempchipid = 0x1002b1;
1923 } else { /* if(rfrevid == 5) */ /* 1002B2 */
1924 tempchipid = 0x1002b2;
1925 }
1926 } else {
1927 }
1928
1929 chipid = tempchipid;
1930 }
1931_fail_:
1932 return chipid;
1933}
1934
Glen Leec9d48342015-10-01 16:03:43 +09001935int wilc_wlan_init(wilc_wlan_inp_t *inp)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001936{
1937
1938 int ret = 0;
1939
1940 PRINT_D(INIT_DBG, "Initializing WILC_Wlan ...\n");
1941
1942 memset((void *)&g_wlan, 0, sizeof(wilc_wlan_dev_t));
1943
1944 /**
1945 * store the input
1946 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001947 memcpy((void *)&g_wlan.io_func, (void *)&inp->io_func, sizeof(wilc_wlan_io_func_t));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001948 /***
1949 * host interface init
1950 **/
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001951 if ((inp->io_func.io_type & 0x1) == HIF_SDIO) {
1952 if (!hif_sdio.hif_init(inp, wilc_debug)) {
1953 /* EIO 5 */
1954 ret = -5;
1955 goto _fail_;
1956 }
1957 memcpy((void *)&g_wlan.hif_func, &hif_sdio, sizeof(wilc_hif_func_t));
1958 } else {
1959 if ((inp->io_func.io_type & 0x1) == HIF_SPI) {
1960 /**
1961 * TODO:
1962 **/
1963 if (!hif_spi.hif_init(inp, wilc_debug)) {
1964 /* EIO 5 */
1965 ret = -5;
1966 goto _fail_;
1967 }
1968 memcpy((void *)&g_wlan.hif_func, &hif_spi, sizeof(wilc_hif_func_t));
1969 } else {
1970 /* EIO 5 */
1971 ret = -5;
1972 goto _fail_;
1973 }
1974 }
1975
1976 /***
1977 * mac interface init
1978 **/
Glen Lee814bc362015-10-02 14:22:11 +09001979 if (!wilc_wlan_cfg_init(wilc_debug)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001980 /* ENOBUFS 105 */
1981 ret = -105;
1982 goto _fail_;
1983 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001984
1985 /**
1986 * alloc tx, rx buffer
1987 **/
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09001988 if (g_wlan.tx_buffer == NULL)
Glen Lee7015b5d2015-09-24 18:15:02 +09001989 g_wlan.tx_buffer = kmalloc(LINUX_TX_SIZE, GFP_KERNEL);
Arnd Bergmann7a8fd842015-06-01 21:06:45 +02001990 PRINT_D(TX_DBG, "g_wlan.tx_buffer = %p\n", g_wlan.tx_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001991
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09001992 if (g_wlan.tx_buffer == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001993 /* ENOBUFS 105 */
1994 ret = -105;
1995 PRINT_ER("Can't allocate Tx Buffer");
1996 goto _fail_;
1997 }
1998
1999/* rx_buffer is not used unless we activate USE_MEM STATIC which is not applicable, allocating such memory is useless*/
2000#if defined (MEMORY_STATIC)
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002001 if (g_wlan.rx_buffer == NULL)
Glen Lee03eb7262015-09-24 18:15:03 +09002002 g_wlan.rx_buffer = kmalloc(LINUX_RX_SIZE, GFP_KERNEL);
Arnd Bergmann7a8fd842015-06-01 21:06:45 +02002003 PRINT_D(TX_DBG, "g_wlan.rx_buffer =%p\n", g_wlan.rx_buffer);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +09002004 if (g_wlan.rx_buffer == NULL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002005 /* ENOBUFS 105 */
2006 ret = -105;
2007 PRINT_ER("Can't allocate Rx Buffer");
2008 goto _fail_;
2009 }
2010#endif
2011
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002012 if (!init_chip()) {
2013 /* EIO 5 */
2014 ret = -5;
2015 goto _fail_;
2016 }
2017#ifdef TCP_ACK_FILTER
2018 Init_TCP_tracking();
2019#endif
2020
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002021 return 1;
2022
2023_fail_:
2024
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002025 #ifdef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07002026 kfree(g_wlan.rx_buffer);
2027 g_wlan.rx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002028 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07002029 kfree(g_wlan.tx_buffer);
2030 g_wlan.tx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002031
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002032 return ret;
2033
2034}
2035
Glen Lee178c3832015-10-27 18:27:58 +09002036u16 Set_machw_change_vir_if(struct net_device *dev, bool bValue)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002037{
Chaehyun Limd85f5322015-06-11 14:35:54 +09002038 u16 ret;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09002039 u32 reg;
Glen Lee178c3832015-10-27 18:27:58 +09002040 perInterface_wlan_t *nic;
2041 struct wilc *wilc;
2042
2043 nic = netdev_priv(dev);
2044 wilc = nic->wilc;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002045
2046 /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
Glen Lee178c3832015-10-27 18:27:58 +09002047 mutex_lock(&wilc->hif_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002048 ret = (&g_wlan)->hif_func.hif_read_reg(WILC_CHANGING_VIR_IF, &reg);
Alison Schofield39823a52015-10-08 21:18:03 -07002049 if (!ret)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002050 PRINT_ER("Error while Reading reg WILC_CHANGING_VIR_IF\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002051
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05302052 if (bValue)
Chaehyun Lim50b51da2015-09-16 20:11:26 +09002053 reg |= BIT(31);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05302054 else
Chaehyun Lim50b51da2015-09-16 20:11:26 +09002055 reg &= ~BIT(31);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002056
2057 ret = (&g_wlan)->hif_func.hif_write_reg(WILC_CHANGING_VIR_IF, reg);
2058
Alison Schofield39823a52015-10-08 21:18:03 -07002059 if (!ret)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002060 PRINT_ER("Error while writing reg WILC_CHANGING_VIR_IF\n");
Alison Schofield39823a52015-10-08 21:18:03 -07002061
Glen Lee178c3832015-10-27 18:27:58 +09002062 mutex_unlock(&wilc->hif_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09002063
2064 return ret;
2065}