blob: 66d5d4267327378bdff9da4bc25e36f3ccf09ca7 [file] [log] [blame]
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001#include "wilc_wlan_if.h"
Tony Cho60bd1002015-10-12 16:56:04 +09002#include "wilc_wfi_netdevice.h"
Glen Lee17e8f162015-10-02 14:22:07 +09003#include "wilc_wlan_cfg.h"
Johnny Kimc5c77ba2015-05-11 14:30:56 +09004
Johnny Kimc5c77ba2015-05-11 14:30:56 +09005extern wilc_hif_func_t hif_sdio;
6extern wilc_hif_func_t hif_spi;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09007u32 wilc_get_chipid(u8 update);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09008
Johnny Kimc5c77ba2015-05-11 14:30:56 +09009typedef struct {
10 int quit;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090011 wilc_wlan_io_func_t io_func;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090012 wilc_hif_func_t hif_func;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090013 int cfg_frame_in_use;
14 wilc_cfg_frame_t cfg_frame;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090015 u32 cfg_frame_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090016 int cfg_seq_no;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090017
Johnny Kimc5c77ba2015-05-11 14:30:56 +090018 #ifdef MEMORY_STATIC
Chaehyun Lim51e825f2015-09-15 14:06:14 +090019 u8 *rx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090020 u32 rx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090021 #endif
Chaehyun Lim51e825f2015-09-15 14:06:14 +090022 u8 *tx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090023 u32 tx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090024
Johnny Kimc5c77ba2015-05-11 14:30:56 +090025 unsigned long txq_spinlock_flags;
26
27 struct txq_entry_t *txq_head;
28 struct txq_entry_t *txq_tail;
29 int txq_entries;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090030 int txq_exit;
31
Johnny Kimc5c77ba2015-05-11 14:30:56 +090032 struct rxq_entry_t *rxq_head;
33 struct rxq_entry_t *rxq_tail;
34 int rxq_entries;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090035 int rxq_exit;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090036} wilc_wlan_dev_t;
37
38static wilc_wlan_dev_t g_wlan;
39
Chaehyun Lim9af382b2015-09-16 20:11:27 +090040static inline void chip_allow_sleep(void);
41static inline void chip_wakeup(void);
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090042static u32 dbgflag = N_INIT | N_ERR | N_INTR | N_TXQ | N_RXQ;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090043
Chaehyun Limfbc2fe12015-09-15 14:06:16 +090044static void wilc_debug(u32 flag, char *fmt, ...)
Johnny Kimc5c77ba2015-05-11 14:30:56 +090045{
46 char buf[256];
47 va_list args;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090048
49 if (flag & dbgflag) {
50 va_start(args, fmt);
Hari Prasath Gujulan Elango81053222015-06-22 13:13:58 +000051 vsprintf(buf, fmt, args);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090052 va_end(args);
53
Glen Leeef2b7842015-09-24 18:14:55 +090054 linux_wlan_dbg(buf);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090055 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +090056}
57
Leo Kimb7d1e182015-11-06 11:12:30 +090058static CHIP_PS_STATE_T chip_ps_state = CHIP_WAKEDUP;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090059
Chaehyun Lim9af382b2015-09-16 20:11:27 +090060static inline void acquire_bus(BUS_ACQUIRE_T acquire)
Johnny Kimc5c77ba2015-05-11 14:30:56 +090061{
Glen Lee187f1ef2015-09-24 18:15:01 +090062 mutex_lock(&g_linux_wlan->hif_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090063 #ifndef WILC_OPTIMIZE_SLEEP_INT
Leo Kimb7d1e182015-11-06 11:12:30 +090064 if (chip_ps_state != CHIP_WAKEDUP)
Johnny Kimc5c77ba2015-05-11 14:30:56 +090065 #endif
66 {
67 if (acquire == ACQUIRE_AND_WAKEUP)
68 chip_wakeup();
69 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +090070}
Leo Kim2d6973e2015-11-06 11:12:28 +090071
Chaehyun Lim9af382b2015-09-16 20:11:27 +090072static inline void release_bus(BUS_RELEASE_T release)
Johnny Kimc5c77ba2015-05-11 14:30:56 +090073{
74 #ifdef WILC_OPTIMIZE_SLEEP_INT
75 if (release == RELEASE_ALLOW_SLEEP)
76 chip_allow_sleep();
77 #endif
Glen Lee187f1ef2015-09-24 18:15:01 +090078 mutex_unlock(&g_linux_wlan->hif_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090079}
Johnny Kimc5c77ba2015-05-11 14:30:56 +090080
81static void wilc_wlan_txq_remove(struct txq_entry_t *tqe)
82{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +053083 wilc_wlan_dev_t *p = &g_wlan;
Leo Kim8739eeb2015-11-06 11:12:29 +090084
Johnny Kimc5c77ba2015-05-11 14:30:56 +090085 if (tqe == p->txq_head) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +090086 p->txq_head = tqe->next;
87 if (p->txq_head)
88 p->txq_head->prev = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090089 } else if (tqe == p->txq_tail) {
90 p->txq_tail = (tqe->prev);
91 if (p->txq_tail)
92 p->txq_tail->next = NULL;
93 } else {
94 tqe->prev->next = tqe->next;
95 tqe->next->prev = tqe->prev;
96 }
97 p->txq_entries -= 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090098}
99
Glen Lee718fc2c2015-10-29 12:18:43 +0900100static struct txq_entry_t *
101wilc_wlan_txq_remove_from_head(struct net_device *dev)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900102{
103 struct txq_entry_t *tqe;
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530104 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900105 unsigned long flags;
Glen Lee718fc2c2015-10-29 12:18:43 +0900106 perInterface_wlan_t *nic;
107 struct wilc *wilc;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900108
Glen Lee718fc2c2015-10-29 12:18:43 +0900109 nic = netdev_priv(dev);
110 wilc = nic->wilc;
111
112 spin_lock_irqsave(&wilc->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900113 if (p->txq_head) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900114 tqe = p->txq_head;
115 p->txq_head = tqe->next;
Alison Schofield39823a52015-10-08 21:18:03 -0700116 if (p->txq_head)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900117 p->txq_head->prev = NULL;
Alison Schofield39823a52015-10-08 21:18:03 -0700118
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900119 p->txq_entries -= 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900120 } else {
121 tqe = NULL;
122 }
Glen Lee718fc2c2015-10-29 12:18:43 +0900123 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900124 return tqe;
125}
126
Glen Lee32f03322015-10-29 12:18:45 +0900127static void wilc_wlan_txq_add_to_tail(struct net_device *dev,
128 struct txq_entry_t *tqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900129{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530130 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900131 unsigned long flags;
Glen Lee32f03322015-10-29 12:18:45 +0900132 perInterface_wlan_t *nic;
133 struct wilc *wilc;
134
135 nic = netdev_priv(dev);
136 wilc = nic->wilc;
137
138 spin_lock_irqsave(&wilc->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900139
Leo Kima4b17192015-11-06 11:12:31 +0900140 if (!p->txq_head) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900141 tqe->next = NULL;
142 tqe->prev = NULL;
143 p->txq_head = tqe;
144 p->txq_tail = tqe;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900145 } else {
146 tqe->next = NULL;
147 tqe->prev = p->txq_tail;
148 p->txq_tail->next = tqe;
149 p->txq_tail = tqe;
150 }
151 p->txq_entries += 1;
152 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900153
Glen Lee32f03322015-10-29 12:18:45 +0900154 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900155
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900156 PRINT_D(TX_DBG, "Wake the txq_handling\n");
157
Glen Lee32f03322015-10-29 12:18:45 +0900158 up(&wilc->txq_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900159}
160
161static int wilc_wlan_txq_add_to_head(struct txq_entry_t *tqe)
162{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530163 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900164 unsigned long flags;
Glen Leeb002e202015-09-24 18:15:05 +0900165 if (linux_wlan_lock_timeout(&g_linux_wlan->txq_add_to_head_cs,
166 CFG_PKTS_TIMEOUT))
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900167 return -1;
168
Glen Lee85e57562015-09-24 18:14:56 +0900169 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900170
Leo Kima4b17192015-11-06 11:12:31 +0900171 if (!p->txq_head) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900172 tqe->next = NULL;
173 tqe->prev = NULL;
174 p->txq_head = tqe;
175 p->txq_tail = tqe;
176 } else {
177 tqe->next = p->txq_head;
178 tqe->prev = NULL;
179 p->txq_head->prev = tqe;
180 p->txq_head = tqe;
181 }
182 p->txq_entries += 1;
183 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900184
Glen Lee85e57562015-09-24 18:14:56 +0900185 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Glen Leed5a63a82015-09-24 18:15:00 +0900186 up(&g_linux_wlan->txq_add_to_head_cs);
Glen Lee5cd63632015-09-24 18:14:58 +0900187 up(&g_linux_wlan->txq_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900188 PRINT_D(TX_DBG, "Wake up the txq_handler\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900189
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900190 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900191}
192
Leo Kimeb59da32015-11-06 11:12:33 +0900193u32 total_acks = 0, dropped_acks = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900194
195#ifdef TCP_ACK_FILTER
Leo Kim130a41f2015-11-06 11:12:34 +0900196struct ack_session_info;
197struct ack_session_info {
Leo Kimd06b6cb2015-11-06 11:12:35 +0900198 u32 seq_num;
Leo Kim9d54d3d2015-11-06 11:12:36 +0900199 u32 bigger_ack_num;
Chaehyun Limec53adf2015-09-15 14:06:15 +0900200 u16 src_port;
201 u16 dst_port;
202 u16 status;
Shraddha Barkeeeb1c062015-08-05 01:29:22 +0530203};
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900204
Leo Kim08b90b12015-11-06 11:12:37 +0900205struct pending_acks_info {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900206 u32 ack_num;
Leo Kim84136972015-11-06 11:12:38 +0900207 u32 session_index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900208 struct txq_entry_t *txqe;
Leo Kim08b90b12015-11-06 11:12:37 +0900209};
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900210
Leo Kim130a41f2015-11-06 11:12:34 +0900211struct ack_session_info *Free_head;
212struct ack_session_info *Alloc_head;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900213
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900214#define NOT_TCP_ACK (-1)
215
216#define MAX_TCP_SESSION 25
217#define MAX_PENDING_ACKS 256
Leo Kim32065052015-11-06 11:12:39 +0900218struct ack_session_info ack_session_info[2 * MAX_TCP_SESSION];
Leo Kim2bb17082015-11-06 11:12:40 +0900219struct pending_acks_info pending_acks_info[MAX_PENDING_ACKS];
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900220
Leo Kim2ae91ed2015-11-06 11:12:41 +0900221u32 pending_base;
Leo Kim3056ec32015-11-06 11:12:42 +0900222u32 tcp_session;
Leo Kimd12ac7e2015-11-06 11:12:43 +0900223u32 pending_acks;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900224
Leo Kimef06b5f2015-11-06 11:12:44 +0900225static inline int init_tcp_tracking(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900226{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900227 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900228}
Leo Kim2d6973e2015-11-06 11:12:28 +0900229
Leo Kim67620782015-11-06 11:12:45 +0900230static inline int add_tcp_session(u32 src_prt, u32 dst_prt, u32 seq)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900231{
Leo Kim3056ec32015-11-06 11:12:42 +0900232 ack_session_info[tcp_session].seq_num = seq;
233 ack_session_info[tcp_session].bigger_ack_num = 0;
234 ack_session_info[tcp_session].src_port = src_prt;
235 ack_session_info[tcp_session].dst_port = dst_prt;
236 tcp_session++;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900237
Leo Kim3056ec32015-11-06 11:12:42 +0900238 PRINT_D(TCP_ENH, "TCP Session %d to Ack %d\n", tcp_session, seq);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900239 return 0;
240}
241
Leo Kimb801a962015-11-06 11:12:48 +0900242static inline int update_tcp_session(u32 index, u32 ack)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900243{
Leo Kimb801a962015-11-06 11:12:48 +0900244 if (ack > ack_session_info[index].bigger_ack_num)
245 ack_session_info[index].bigger_ack_num = ack;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900246 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900247}
Leo Kim2d6973e2015-11-06 11:12:28 +0900248
Leo Kimea03f572015-11-06 11:12:49 +0900249static inline int add_tcp_pending_ack(u32 ack, u32 session_index,
Leo Kimbdc13ad2015-11-06 11:12:47 +0900250 struct txq_entry_t *txqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900251{
Leo Kim821466d2015-11-06 11:12:32 +0900252 total_acks++;
Leo Kimd12ac7e2015-11-06 11:12:43 +0900253 if (pending_acks < MAX_PENDING_ACKS) {
Leo Kimb801a962015-11-06 11:12:48 +0900254 pending_acks_info[pending_base + pending_acks].ack_num = ack;
Leo Kimd12ac7e2015-11-06 11:12:43 +0900255 pending_acks_info[pending_base + pending_acks].txqe = txqe;
Leo Kimea03f572015-11-06 11:12:49 +0900256 pending_acks_info[pending_base + pending_acks].session_index = session_index;
Leo Kimd12ac7e2015-11-06 11:12:43 +0900257 txqe->tcp_PendingAck_index = pending_base + pending_acks;
258 pending_acks++;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900259 }
260 return 0;
261}
Chaehyun Limfed16f22015-09-17 16:48:43 +0900262static inline int remove_TCP_related(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900263{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530264 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900265 unsigned long flags;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900266
Glen Lee85e57562015-09-24 18:14:56 +0900267 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900268
Glen Lee85e57562015-09-24 18:14:56 +0900269 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900270 return 0;
271}
272
Glen Lee82bb18e2015-10-27 18:28:03 +0900273static inline int tcp_process(struct net_device *dev, struct txq_entry_t *tqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900274{
275 int ret;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900276 u8 *eth_hdr_ptr;
277 u8 *buffer = tqe->buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900278 unsigned short h_proto;
279 int i;
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530280 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900281 unsigned long flags;
Glen Lee82bb18e2015-10-27 18:28:03 +0900282 perInterface_wlan_t *nic;
283 struct wilc *wilc;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900284
Glen Lee82bb18e2015-10-27 18:28:03 +0900285 nic = netdev_priv(dev);
286 wilc = nic->wilc;
287
288 spin_lock_irqsave(&wilc->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900289
290 eth_hdr_ptr = &buffer[0];
291 h_proto = ntohs(*((unsigned short *)&eth_hdr_ptr[12]));
Leo Kimac087c82015-11-06 11:12:25 +0900292 if (h_proto == 0x0800) {
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900293 u8 *ip_hdr_ptr;
294 u8 protocol;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900295
296 ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN];
297 protocol = ip_hdr_ptr[9];
298
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900299 if (protocol == 0x06) {
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900300 u8 *tcp_hdr_ptr;
Leo Kim51bffa92015-11-06 11:12:52 +0900301 u32 IHL, total_length, data_offset;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900302
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900303 tcp_hdr_ptr = &ip_hdr_ptr[IP_HDR_LEN];
304 IHL = (ip_hdr_ptr[0] & 0xf) << 2;
Leo Kim24e2dac2015-11-06 11:12:51 +0900305 total_length = ((u32)ip_hdr_ptr[2] << 8) +
306 (u32)ip_hdr_ptr[3];
Leo Kim51bffa92015-11-06 11:12:52 +0900307 data_offset = ((u32)tcp_hdr_ptr[12] & 0xf0) >> 2;
308 if (total_length == (IHL + data_offset)) {
Leo Kimf91c5d72015-11-06 11:12:53 +0900309 u32 seq_no, ack_no;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900310
Leo Kim4478c622015-11-06 11:12:54 +0900311 seq_no = ((u32)tcp_hdr_ptr[4] << 24) +
312 ((u32)tcp_hdr_ptr[5] << 16) +
313 ((u32)tcp_hdr_ptr[6] << 8) +
314 (u32)tcp_hdr_ptr[7];
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900315
Leo Kimf91c5d72015-11-06 11:12:53 +0900316 ack_no = ((u32)tcp_hdr_ptr[8] << 24) +
317 ((u32)tcp_hdr_ptr[9] << 16) +
318 ((u32)tcp_hdr_ptr[10] << 8) +
319 (u32)tcp_hdr_ptr[11];
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900320
Leo Kim3056ec32015-11-06 11:12:42 +0900321 for (i = 0; i < tcp_session; i++) {
Leo Kim32065052015-11-06 11:12:39 +0900322 if (ack_session_info[i].seq_num == seq_no) {
Leo Kimf91c5d72015-11-06 11:12:53 +0900323 update_tcp_session(i, ack_no);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900324 break;
325 }
326 }
Leo Kim3056ec32015-11-06 11:12:42 +0900327 if (i == tcp_session)
Leo Kim67620782015-11-06 11:12:45 +0900328 add_tcp_session(0, 0, seq_no);
Alison Schofield39823a52015-10-08 21:18:03 -0700329
Leo Kimf91c5d72015-11-06 11:12:53 +0900330 add_tcp_pending_ack(ack_no, i, tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900331 }
332
333 } else {
334 ret = 0;
335 }
336 } else {
337 ret = 0;
338 }
Glen Lee82bb18e2015-10-27 18:28:03 +0900339 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900340 return ret;
341}
342
Glen Leec029e992015-10-27 18:27:48 +0900343static int wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900344{
Glen Leec029e992015-10-27 18:27:48 +0900345 perInterface_wlan_t *nic;
346 struct wilc *wilc;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900347 u32 i = 0;
Leo Kim442eda42015-11-06 11:12:55 +0900348 u32 dropped = 0;
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530349 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900350
Glen Leec029e992015-10-27 18:27:48 +0900351 nic = netdev_priv(dev);
352 wilc = nic->wilc;
353
354 spin_lock_irqsave(&wilc->txq_spinlock, p->txq_spinlock_flags);
Leo Kimd12ac7e2015-11-06 11:12:43 +0900355 for (i = pending_base; i < (pending_base + pending_acks); i++) {
Leo Kim2bb17082015-11-06 11:12:40 +0900356 if (pending_acks_info[i].ack_num < ack_session_info[pending_acks_info[i].session_index].bigger_ack_num) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900357 struct txq_entry_t *tqe;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900358
Leo Kim2bb17082015-11-06 11:12:40 +0900359 PRINT_D(TCP_ENH, "DROP ACK: %u\n",
360 pending_acks_info[i].ack_num);
361 tqe = pending_acks_info[i].txqe;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900362 if (tqe) {
363 wilc_wlan_txq_remove(tqe);
Leo Kimeb59da32015-11-06 11:12:33 +0900364 dropped_acks++;
Leo Kimac087c82015-11-06 11:12:25 +0900365 tqe->status = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900366 if (tqe->tx_complete_func)
367 tqe->tx_complete_func(tqe->priv, tqe->status);
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -0700368 kfree(tqe);
Leo Kim442eda42015-11-06 11:12:55 +0900369 dropped++;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900370 }
371 }
372 }
Leo Kimd12ac7e2015-11-06 11:12:43 +0900373 pending_acks = 0;
Leo Kim3056ec32015-11-06 11:12:42 +0900374 tcp_session = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900375
Leo Kim2ae91ed2015-11-06 11:12:41 +0900376 if (pending_base == 0)
377 pending_base = MAX_TCP_SESSION;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530378 else
Leo Kim2ae91ed2015-11-06 11:12:41 +0900379 pending_base = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900380
Glen Leec029e992015-10-27 18:27:48 +0900381 spin_unlock_irqrestore(&wilc->txq_spinlock, p->txq_spinlock_flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900382
Leo Kim442eda42015-11-06 11:12:55 +0900383 while (dropped > 0) {
Glen Leec029e992015-10-27 18:27:48 +0900384 linux_wlan_lock_timeout(&wilc->txq_event, 1);
Leo Kim442eda42015-11-06 11:12:55 +0900385 dropped--;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900386 }
387
388 return 1;
389}
390#endif
391
Leo Kim7c4bafe2015-11-06 11:12:56 +0900392bool enabled = false;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900393
Leo Kimb9e04aa2015-11-06 11:12:57 +0900394void enable_tcp_ack_filter(bool value)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900395{
Leo Kim7c4bafe2015-11-06 11:12:56 +0900396 enabled = value;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900397}
398
Leo Kim44c44172015-11-06 11:12:58 +0900399bool is_tcp_ack_filter_enabled(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900400{
Leo Kim7c4bafe2015-11-06 11:12:56 +0900401 return enabled;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900402}
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900403
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900404static int wilc_wlan_txq_add_cfg_pkt(u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900405{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530406 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900407 struct txq_entry_t *tqe;
408
409 PRINT_D(TX_DBG, "Adding config packet ...\n");
410 if (p->quit) {
411 PRINT_D(TX_DBG, "Return due to clear function\n");
Glen Lee6a3b94f2015-09-24 18:14:59 +0900412 up(&g_linux_wlan->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900413 return 0;
414 }
415
Leo Kim1d401a42015-11-06 11:12:59 +0900416 tqe = kmalloc(sizeof(*tqe), GFP_ATOMIC);
Leo Kima4b17192015-11-06 11:12:31 +0900417 if (!tqe) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900418 PRINT_ER("Failed to allocate memory\n");
419 return 0;
420 }
421
422 tqe->type = WILC_CFG_PKT;
423 tqe->buffer = buffer;
424 tqe->buffer_size = buffer_size;
425 tqe->tx_complete_func = NULL;
426 tqe->priv = NULL;
427#ifdef TCP_ACK_FILTER
428 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
429#endif
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900430 PRINT_D(TX_DBG, "Adding the config packet at the Queue tail\n");
431
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900432 if (wilc_wlan_txq_add_to_head(tqe))
433 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900434 return 1;
435}
436
Glen Lee691bbd42015-10-27 18:28:02 +0900437int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
438 u32 buffer_size, wilc_tx_complete_func_t func)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900439{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530440 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900441 struct txq_entry_t *tqe;
442
443 if (p->quit)
444 return 0;
445
Leo Kim1d401a42015-11-06 11:12:59 +0900446 tqe = kmalloc(sizeof(*tqe), GFP_ATOMIC);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900447
Leo Kima4b17192015-11-06 11:12:31 +0900448 if (!tqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900449 return 0;
450 tqe->type = WILC_NET_PKT;
451 tqe->buffer = buffer;
452 tqe->buffer_size = buffer_size;
453 tqe->tx_complete_func = func;
454 tqe->priv = priv;
455
456 PRINT_D(TX_DBG, "Adding mgmt packet at the Queue tail\n");
457#ifdef TCP_ACK_FILTER
458 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
Leo Kim44c44172015-11-06 11:12:58 +0900459 if (is_tcp_ack_filter_enabled())
Glen Lee82bb18e2015-10-27 18:28:03 +0900460 tcp_process(dev, tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900461#endif
Glen Lee32f03322015-10-29 12:18:45 +0900462 wilc_wlan_txq_add_to_tail(dev, tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900463 return p->txq_entries;
464}
Glen Leefcc6ef92015-09-16 18:53:21 +0900465
Glen Lee829c4772015-10-29 12:18:44 +0900466int wilc_wlan_txq_add_mgmt_pkt(struct net_device *dev, void *priv, u8 *buffer,
467 u32 buffer_size, wilc_tx_complete_func_t func)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900468{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530469 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900470 struct txq_entry_t *tqe;
471
472 if (p->quit)
473 return 0;
474
Leo Kim1d401a42015-11-06 11:12:59 +0900475 tqe = kmalloc(sizeof(*tqe), GFP_KERNEL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900476
Leo Kima4b17192015-11-06 11:12:31 +0900477 if (!tqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900478 return 0;
479 tqe->type = WILC_MGMT_PKT;
480 tqe->buffer = buffer;
481 tqe->buffer_size = buffer_size;
482 tqe->tx_complete_func = func;
483 tqe->priv = priv;
484#ifdef TCP_ACK_FILTER
485 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
486#endif
487 PRINT_D(TX_DBG, "Adding Network packet at the Queue tail\n");
Glen Lee32f03322015-10-29 12:18:45 +0900488 wilc_wlan_txq_add_to_tail(dev, tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900489 return 1;
490}
Glen Leefcc6ef92015-09-16 18:53:21 +0900491
Glen Lee7af05222015-10-29 12:18:41 +0900492static struct txq_entry_t *wilc_wlan_txq_get_first(struct wilc *wilc)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900493{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530494 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900495 struct txq_entry_t *tqe;
496 unsigned long flags;
497
Glen Lee7af05222015-10-29 12:18:41 +0900498 spin_lock_irqsave(&wilc->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900499
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900500 tqe = p->txq_head;
501
Glen Lee7af05222015-10-29 12:18:41 +0900502 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900503
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900504 return tqe;
505}
506
Glen Lee50a0b3b2015-10-27 18:28:00 +0900507static struct txq_entry_t *wilc_wlan_txq_get_next(struct wilc *wilc,
508 struct txq_entry_t *tqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900509{
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900510 unsigned long flags;
Leo Kim8739eeb2015-11-06 11:12:29 +0900511
Glen Lee50a0b3b2015-10-27 18:28:00 +0900512 spin_lock_irqsave(&wilc->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900513
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900514 tqe = tqe->next;
Glen Lee50a0b3b2015-10-27 18:28:00 +0900515 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900516
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900517 return tqe;
518}
519
Glen Leed06f3622015-10-27 18:27:59 +0900520static int wilc_wlan_rxq_add(struct wilc *wilc, struct rxq_entry_t *rqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900521{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530522 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900523
524 if (p->quit)
525 return 0;
526
Glen Leed06f3622015-10-27 18:27:59 +0900527 mutex_lock(&wilc->rxq_cs);
Leo Kima4b17192015-11-06 11:12:31 +0900528 if (!p->rxq_head) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900529 PRINT_D(RX_DBG, "Add to Queue head\n");
530 rqe->next = NULL;
531 p->rxq_head = rqe;
532 p->rxq_tail = rqe;
533 } else {
534 PRINT_D(RX_DBG, "Add to Queue tail\n");
535 p->rxq_tail->next = rqe;
536 rqe->next = NULL;
537 p->rxq_tail = rqe;
538 }
539 p->rxq_entries += 1;
540 PRINT_D(RX_DBG, "Number of queue entries: %d\n", p->rxq_entries);
Glen Leed06f3622015-10-27 18:27:59 +0900541 mutex_unlock(&wilc->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900542 return p->rxq_entries;
543}
544
Glen Leedb387632015-10-27 18:27:55 +0900545static struct rxq_entry_t *wilc_wlan_rxq_remove(struct wilc *wilc)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900546{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530547 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900548
549 PRINT_D(RX_DBG, "Getting rxQ element\n");
550 if (p->rxq_head) {
551 struct rxq_entry_t *rqe;
552
Glen Leedb387632015-10-27 18:27:55 +0900553 mutex_lock(&wilc->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900554 rqe = p->rxq_head;
555 p->rxq_head = p->rxq_head->next;
556 p->rxq_entries -= 1;
557 PRINT_D(RX_DBG, "RXQ entries decreased\n");
Glen Leedb387632015-10-27 18:27:55 +0900558 mutex_unlock(&wilc->rxq_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900559 return rqe;
560 }
561 PRINT_D(RX_DBG, "Nothing to get from Q\n");
562 return NULL;
563}
564
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900565#ifdef WILC_OPTIMIZE_SLEEP_INT
566
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900567static inline void chip_allow_sleep(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900568{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900569 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900570
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900571 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
572
Anish Bhattffda2032015-09-29 12:15:49 -0700573 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900574}
575
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900576static inline void chip_wakeup(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900577{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900578 u32 reg, clk_status_reg, trials = 0;
579 u32 sleep_time;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900580
581 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
582 do {
583 g_wlan.hif_func.hif_read_reg(1, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -0700584 g_wlan.hif_func.hif_write_reg(1, reg | BIT(1));
Anish Bhattffda2032015-09-29 12:15:49 -0700585 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900586
587 do {
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -0700588 usleep_range(2 * 1000, 2 * 1000);
Alison Schofield39823a52015-10-08 21:18:03 -0700589 if ((wilc_get_chipid(true) == 0))
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900590 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
Alison Schofield39823a52015-10-08 21:18:03 -0700591
Dean Lee72ed4dc2015-06-12 14:11:44 +0900592 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900593
Dean Lee72ed4dc2015-06-12 14:11:44 +0900594 } while (wilc_get_chipid(true) == 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900595 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
596 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
597 do {
Anish Bhattffda2032015-09-29 12:15:49 -0700598 g_wlan.hif_func.hif_write_reg(0xf0, reg | BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900599 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
600
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900601 while (((clk_status_reg & 0x1) == 0) && (((++trials) % 3) == 0)) {
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -0700602 usleep_range(2 * 1000, 2 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900603
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900604 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
605
Alison Schofield39823a52015-10-08 21:18:03 -0700606 if ((clk_status_reg & 0x1) == 0)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900607 wilc_debug(N_ERR, "clocks still OFF. Wake up failed\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900608 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900609 if ((clk_status_reg & 0x1) == 0) {
Anish Bhattffda2032015-09-29 12:15:49 -0700610 g_wlan.hif_func.hif_write_reg(0xf0, reg &
611 (~BIT(0)));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900612 }
613 } while ((clk_status_reg & 0x1) == 0);
614 }
615
Leo Kimb7d1e182015-11-06 11:12:30 +0900616 if (chip_ps_state == CHIP_SLEEPING_MANUAL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900617 g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -0700618 reg &= ~BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900619 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
620
Dean Lee72ed4dc2015-06-12 14:11:44 +0900621 if (wilc_get_chipid(false) >= 0x1002b0) {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900622 u32 val32;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900623
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900624 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700625 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900626 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
627
628 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700629 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900630 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
631 }
632 }
Leo Kimb7d1e182015-11-06 11:12:30 +0900633 chip_ps_state = CHIP_WAKEDUP;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900634}
635#else
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900636static inline void chip_wakeup(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900637{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900638 u32 reg, trials = 0;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900639
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900640 do {
641 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
642 g_wlan.hif_func.hif_read_reg(1, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -0700643 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
Anish Bhattffda2032015-09-29 12:15:49 -0700644 g_wlan.hif_func.hif_write_reg(1, reg | BIT(1));
Anish Bhattffda2032015-09-29 12:15:49 -0700645 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900646 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900647 g_wlan.hif_func.hif_read_reg(0xf0, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -0700648 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
Anish Bhattffda2032015-09-29 12:15:49 -0700649 g_wlan.hif_func.hif_write_reg(0xf0, reg | BIT(0));
Anish Bhattffda2032015-09-29 12:15:49 -0700650 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900651 }
652
653 do {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900654 mdelay(3);
655
Alison Schofield39823a52015-10-08 21:18:03 -0700656 if ((wilc_get_chipid(true) == 0))
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900657 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
Alison Schofield39823a52015-10-08 21:18:03 -0700658
Dean Lee72ed4dc2015-06-12 14:11:44 +0900659 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900660
Dean Lee72ed4dc2015-06-12 14:11:44 +0900661 } while (wilc_get_chipid(true) == 0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900662
Leo Kimb7d1e182015-11-06 11:12:30 +0900663 if (chip_ps_state == CHIP_SLEEPING_MANUAL) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900664 g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -0700665 reg &= ~BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900666 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
667
Dean Lee72ed4dc2015-06-12 14:11:44 +0900668 if (wilc_get_chipid(false) >= 0x1002b0) {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900669 u32 val32;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900670
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900671 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700672 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900673 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
674
675 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
Anish Bhattffda2032015-09-29 12:15:49 -0700676 val32 |= BIT(6);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900677 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
678 }
679 }
Leo Kimb7d1e182015-11-06 11:12:30 +0900680 chip_ps_state = CHIP_WAKEDUP;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900681}
682#endif
Leo Kim1b721bf2015-11-06 11:13:00 +0900683void chip_sleep_manually(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900684{
Leo Kimb7d1e182015-11-06 11:12:30 +0900685 if (chip_ps_state != CHIP_WAKEDUP)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900686 return;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900687 acquire_bus(ACQUIRE_ONLY);
688
689#ifdef WILC_OPTIMIZE_SLEEP_INT
690 chip_allow_sleep();
691#endif
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900692 g_wlan.hif_func.hif_write_reg(0x10a8, 1);
693
Leo Kimb7d1e182015-11-06 11:12:30 +0900694 chip_ps_state = CHIP_SLEEPING_MANUAL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900695 release_bus(RELEASE_ONLY);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900696}
697
Glen Leea1332ca2015-10-27 18:27:47 +0900698int wilc_wlan_handle_txq(struct net_device *dev, u32 *pu32TxqCount)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900699{
700 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
701 int i, entries = 0;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900702 u32 sum;
703 u32 reg;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900704 u8 *txb = p->tx_buffer;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900705 u32 offset = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900706 int vmm_sz = 0;
707 struct txq_entry_t *tqe;
708 int ret = 0;
709 int counter;
710 int timeout;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900711 u32 vmm_table[WILC_VMM_TBL_SIZE];
Glen Leea1332ca2015-10-27 18:27:47 +0900712 perInterface_wlan_t *nic;
713 struct wilc *wilc;
714
715 nic = netdev_priv(dev);
716 wilc = nic->wilc;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900717
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900718 p->txq_exit = 0;
719 do {
720 if (p->quit)
721 break;
722
Glen Leea1332ca2015-10-27 18:27:47 +0900723 linux_wlan_lock_timeout(&wilc->txq_add_to_head_cs,
Glen Leeb002e202015-09-24 18:15:05 +0900724 CFG_PKTS_TIMEOUT);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900725#ifdef TCP_ACK_FILTER
Glen Leec029e992015-10-27 18:27:48 +0900726 wilc_wlan_txq_filter_dup_tcp_ack(dev);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900727#endif
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900728 PRINT_D(TX_DBG, "Getting the head of the TxQ\n");
Glen Lee7af05222015-10-29 12:18:41 +0900729 tqe = wilc_wlan_txq_get_first(wilc);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900730 i = 0;
731 sum = 0;
732 do {
Leo Kima4b17192015-11-06 11:12:31 +0900733 if (tqe && (i < (WILC_VMM_TBL_SIZE - 1))) {
Alison Schofield39823a52015-10-08 21:18:03 -0700734 if (tqe->type == WILC_CFG_PKT)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900735 vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET;
Alison Schofield39823a52015-10-08 21:18:03 -0700736
737 else if (tqe->type == WILC_NET_PKT)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900738 vmm_sz = ETH_ETHERNET_HDR_OFFSET;
Alison Schofield39823a52015-10-08 21:18:03 -0700739
740 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900741 vmm_sz = HOST_HDR_OFFSET;
Alison Schofield39823a52015-10-08 21:18:03 -0700742
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900743 vmm_sz += tqe->buffer_size;
744 PRINT_D(TX_DBG, "VMM Size before alignment = %d\n", vmm_sz);
Leo Kimac087c82015-11-06 11:12:25 +0900745 if (vmm_sz & 0x3)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900746 vmm_sz = (vmm_sz + 4) & ~0x3;
Leo Kimac087c82015-11-06 11:12:25 +0900747
Alison Schofield39823a52015-10-08 21:18:03 -0700748 if ((sum + vmm_sz) > LINUX_TX_SIZE)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900749 break;
Alison Schofield39823a52015-10-08 21:18:03 -0700750
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900751 PRINT_D(TX_DBG, "VMM Size AFTER alignment = %d\n", vmm_sz);
Leo Kimac087c82015-11-06 11:12:25 +0900752 vmm_table[i] = vmm_sz / 4;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900753 PRINT_D(TX_DBG, "VMMTable entry size = %d\n", vmm_table[i]);
754
755 if (tqe->type == WILC_CFG_PKT) {
Anish Bhattffda2032015-09-29 12:15:49 -0700756 vmm_table[i] |= BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900757 PRINT_D(TX_DBG, "VMMTable entry changed for CFG packet = %d\n", vmm_table[i]);
758 }
759#ifdef BIG_ENDIAN
760 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
761#endif
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900762
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900763 i++;
764 sum += vmm_sz;
765 PRINT_D(TX_DBG, "sum = %d\n", sum);
Glen Lee50a0b3b2015-10-27 18:28:00 +0900766 tqe = wilc_wlan_txq_get_next(wilc, tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900767 } else {
768 break;
769 }
770 } while (1);
771
Leo Kimac087c82015-11-06 11:12:25 +0900772 if (i == 0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900773 PRINT_D(TX_DBG, "Nothing in TX-Q\n");
774 break;
775 } else {
776 PRINT_D(TX_DBG, "Mark the last entry in VMM table - number of previous entries = %d\n", i);
Leo Kimac087c82015-11-06 11:12:25 +0900777 vmm_table[i] = 0x0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900778 }
779 acquire_bus(ACQUIRE_AND_WAKEUP);
780 counter = 0;
781 do {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900782 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg);
783 if (!ret) {
784 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg vmm_tbl_entry..\n");
785 break;
786 }
787
788 if ((reg & 0x1) == 0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900789 PRINT_D(TX_DBG, "Writing VMM table ... with Size = %d\n", ((i + 1) * 4));
790 break;
791 } else {
792 counter++;
793 if (counter > 200) {
794 counter = 0;
795 PRINT_D(TX_DBG, "Looping in tx ctrl , forcce quit\n");
796 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, 0);
797 break;
798 }
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530799 PRINT_WRN(GENERIC_DBG, "[wilc txq]: warn, vmm table not clear yet, wait...\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900800 release_bus(RELEASE_ALLOW_SLEEP);
Greg Kroah-Hartman2b922cb2015-09-04 09:30:51 -0700801 usleep_range(3000, 3000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900802 acquire_bus(ACQUIRE_AND_WAKEUP);
803 }
804 } while (!p->quit);
805
Alison Schofield39823a52015-10-08 21:18:03 -0700806 if (!ret)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900807 goto _end_;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900808
809 timeout = 200;
810 do {
Chaehyun Limc3ca6372015-09-20 15:51:19 +0900811 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 +0900812 if (!ret) {
813 wilc_debug(N_ERR, "ERR block TX of VMM table.\n");
814 break;
815 }
816
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900817 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x2);
818 if (!ret) {
819 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg host_vmm_ctl..\n");
820 break;
821 }
822
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900823 do {
824 ret = p->hif_func.hif_read_reg(WILC_HOST_VMM_CTL, &reg);
825 if (!ret) {
826 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg host_vmm_ctl..\n");
827 break;
828 }
829 if ((reg >> 2) & 0x1) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900830 entries = ((reg >> 3) & 0x3f);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900831 break;
832 } else {
833 release_bus(RELEASE_ALLOW_SLEEP);
Greg Kroah-Hartman2b922cb2015-09-04 09:30:51 -0700834 usleep_range(3000, 3000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900835 acquire_bus(ACQUIRE_AND_WAKEUP);
836 PRINT_WRN(GENERIC_DBG, "Can't get VMM entery - reg = %2x\n", reg);
837 }
838 } while (--timeout);
839 if (timeout <= 0) {
840 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x0);
841 break;
842 }
843
Alison Schofield39823a52015-10-08 21:18:03 -0700844 if (!ret)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900845 break;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900846
847 if (entries == 0) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530848 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 +0900849
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900850 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg);
851 if (!ret) {
852 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg WILC_HOST_TX_CTRL..\n");
853 break;
854 }
Anish Bhattffda2032015-09-29 12:15:49 -0700855 reg &= ~BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900856 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, reg);
857 if (!ret) {
858 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg WILC_HOST_TX_CTRL..\n");
859 break;
860 }
861 break;
862 } else {
863 break;
864 }
865 } while (1);
866
Alison Schofield39823a52015-10-08 21:18:03 -0700867 if (!ret)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900868 goto _end_;
Alison Schofield39823a52015-10-08 21:18:03 -0700869
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900870 if (entries == 0) {
871 ret = WILC_TX_ERR_NO_BUF;
872 goto _end_;
873 }
874
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900875 release_bus(RELEASE_ALLOW_SLEEP);
876
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900877 offset = 0;
878 i = 0;
879 do {
Glen Lee718fc2c2015-10-29 12:18:43 +0900880 tqe = wilc_wlan_txq_remove_from_head(dev);
Leo Kima4b17192015-11-06 11:12:31 +0900881 if (tqe && (vmm_table[i] != 0)) {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900882 u32 header, buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900883
884#ifdef BIG_ENDIAN
885 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
886#endif
Leo Kimac087c82015-11-06 11:12:25 +0900887 vmm_sz = (vmm_table[i] & 0x3ff);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900888 vmm_sz *= 4;
889 header = (tqe->type << 31) | (tqe->buffer_size << 15) | vmm_sz;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530890 if (tqe->type == WILC_MGMT_PKT)
Anish Bhattffda2032015-09-29 12:15:49 -0700891 header |= BIT(30);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530892 else
Anish Bhattffda2032015-09-29 12:15:49 -0700893 header &= ~BIT(30);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900894
895#ifdef BIG_ENDIAN
896 header = BYTE_SWAP(header);
897#endif
898 memcpy(&txb[offset], &header, 4);
899 if (tqe->type == WILC_CFG_PKT) {
900 buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET;
901 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900902 else if (tqe->type == WILC_NET_PKT) {
903 char *pBSSID = ((struct tx_complete_data *)(tqe->priv))->pBssid;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900904
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900905 buffer_offset = ETH_ETHERNET_HDR_OFFSET;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900906 memcpy(&txb[offset + 4], pBSSID, 6);
907 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900908 else {
909 buffer_offset = HOST_HDR_OFFSET;
910 }
911
912 memcpy(&txb[offset + buffer_offset], tqe->buffer, tqe->buffer_size);
913 offset += vmm_sz;
914 i++;
Leo Kimac087c82015-11-06 11:12:25 +0900915 tqe->status = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900916 if (tqe->tx_complete_func)
917 tqe->tx_complete_func(tqe->priv, tqe->status);
918 #ifdef TCP_ACK_FILTER
Alison Schofield39823a52015-10-08 21:18:03 -0700919 if (tqe->tcp_PendingAck_index != NOT_TCP_ACK)
Leo Kim2bb17082015-11-06 11:12:40 +0900920 pending_acks_info[tqe->tcp_PendingAck_index].txqe = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900921 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -0700922 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900923 } else {
924 break;
925 }
926 } while (--entries);
927
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900928 acquire_bus(ACQUIRE_AND_WAKEUP);
929
930 ret = p->hif_func.hif_clear_int_ext(ENABLE_TX_VMM);
931 if (!ret) {
932 wilc_debug(N_ERR, "[wilc txq]: fail can't start tx VMM ...\n");
933 goto _end_;
934 }
935
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900936 ret = p->hif_func.hif_block_tx_ext(0, txb, offset);
937 if (!ret) {
938 wilc_debug(N_ERR, "[wilc txq]: fail can't block tx ext...\n");
939 goto _end_;
940 }
941
942_end_:
943
944 release_bus(RELEASE_ALLOW_SLEEP);
945 if (ret != 1)
946 break;
947 } while (0);
Glen Leea1332ca2015-10-27 18:27:47 +0900948 up(&wilc->txq_add_to_head_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900949
950 p->txq_exit = 1;
951 PRINT_D(TX_DBG, "THREAD: Exiting txq\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900952 *pu32TxqCount = p->txq_entries;
953 return ret;
954}
955
Glen Lee39ce4d32015-10-27 18:27:42 +0900956static void wilc_wlan_handle_rxq(struct wilc *wilc)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900957{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +0530958 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900959 int offset = 0, size, has_packet = 0;
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900960 u8 *buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900961 struct rxq_entry_t *rqe;
962
963 p->rxq_exit = 0;
964
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900965 do {
966 if (p->quit) {
Chandra S Gorentla17aacd42015-08-08 17:41:35 +0530967 PRINT_D(RX_DBG, "exit 1st do-while due to Clean_UP function\n");
Glen Lee39ce4d32015-10-27 18:27:42 +0900968 up(&wilc->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900969 break;
970 }
Glen Leedb387632015-10-27 18:27:55 +0900971 rqe = wilc_wlan_rxq_remove(wilc);
Leo Kima4b17192015-11-06 11:12:31 +0900972 if (!rqe) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900973 PRINT_D(RX_DBG, "nothing in the queue - exit 1st do-while\n");
974 break;
975 }
976 buffer = rqe->buffer;
977 size = rqe->buffer_size;
978 PRINT_D(RX_DBG, "rxQ entery Size = %d - Address = %p\n", size, buffer);
979 offset = 0;
980
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900981 do {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +0900982 u32 header;
983 u32 pkt_len, pkt_offset, tp_len;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900984 int is_cfg_packet;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900985
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900986 PRINT_D(RX_DBG, "In the 2nd do-while\n");
987 memcpy(&header, &buffer[offset], 4);
988#ifdef BIG_ENDIAN
989 header = BYTE_SWAP(header);
990#endif
991 PRINT_D(RX_DBG, "Header = %04x - Offset = %d\n", header, offset);
992
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900993 is_cfg_packet = (header >> 31) & 0x1;
994 pkt_offset = (header >> 22) & 0x1ff;
995 tp_len = (header >> 11) & 0x7ff;
996 pkt_len = header & 0x7ff;
997
998 if (pkt_len == 0 || tp_len == 0) {
999 wilc_debug(N_RXQ, "[wilc rxq]: data corrupt, packet len or tp_len is 0 [%d][%d]\n", pkt_len, tp_len);
1000 break;
1001 }
1002
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001003 #define IS_MANAGMEMENT 0x100
1004 #define IS_MANAGMEMENT_CALLBACK 0x080
1005 #define IS_MGMT_STATUS_SUCCES 0x040
1006
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001007 if (pkt_offset & IS_MANAGMEMENT) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001008 pkt_offset &= ~(IS_MANAGMEMENT | IS_MANAGMEMENT_CALLBACK | IS_MGMT_STATUS_SUCCES);
1009
Glen Lee11f4b2e2015-10-27 18:27:51 +09001010 WILC_WFI_mgmt_rx(wilc, &buffer[offset + HOST_HDR_OFFSET], pkt_len);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001011 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001012 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001013 {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001014 if (!is_cfg_packet) {
Glen Lee63611672015-09-24 18:14:52 +09001015 if (pkt_len > 0) {
Glen Leecb1991a2015-10-27 18:27:56 +09001016 frmw_to_linux(wilc,
1017 &buffer[offset],
Glen Lee63611672015-09-24 18:14:52 +09001018 pkt_len,
1019 pkt_offset);
1020 has_packet = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001021 }
1022 } else {
1023 wilc_cfg_rsp_t rsp;
1024
Glen Lee30f535a2015-10-02 14:22:10 +09001025 wilc_wlan_cfg_indicate_rx(&buffer[pkt_offset + offset], pkt_len, &rsp);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001026 if (rsp.type == WILC_CFG_RSP) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001027 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 -07001028 if (p->cfg_seq_no == rsp.seq_no)
Glen Lee39ce4d32015-10-27 18:27:42 +09001029 up(&wilc->cfg_event);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001030 } else if (rsp.type == WILC_CFG_RSP_STATUS) {
Glen Lee64f2b712015-10-27 18:27:43 +09001031 linux_wlan_mac_indicate(wilc, WILC_MAC_INDICATE_STATUS);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001032
1033 } else if (rsp.type == WILC_CFG_RSP_SCAN) {
Glen Lee64f2b712015-10-27 18:27:43 +09001034 linux_wlan_mac_indicate(wilc, WILC_MAC_INDICATE_SCAN);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001035 }
1036 }
1037 }
1038 offset += tp_len;
1039 if (offset >= size)
1040 break;
1041 } while (1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001042#ifndef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001043 kfree(buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001044#endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001045 kfree(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001046
Alison Schofield39823a52015-10-08 21:18:03 -07001047 if (has_packet)
Glen Leec0cadaa2015-09-24 18:14:54 +09001048 linux_wlan_rx_complete();
Alison Schofield39823a52015-10-08 21:18:03 -07001049
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001050 } while (1);
1051
1052 p->rxq_exit = 1;
Chandra S Gorentla17aacd42015-08-08 17:41:35 +05301053 PRINT_D(RX_DBG, "THREAD: Exiting RX thread\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001054}
1055
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001056static void wilc_unknown_isr_ext(void)
1057{
1058 g_wlan.hif_func.hif_clear_int_ext(0);
1059}
Leo Kim2d6973e2015-11-06 11:12:28 +09001060
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001061static void wilc_pllupdate_isr_ext(u32 int_stats)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001062{
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001063 int trials = 10;
1064
1065 g_wlan.hif_func.hif_clear_int_ext(PLL_INT_CLR);
1066
Greg Kroah-Hartmanc2e4c0f2015-09-03 19:09:50 -07001067 mdelay(WILC_PLL_TO);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001068
Dean Lee72ed4dc2015-06-12 14:11:44 +09001069 while (!(ISWILC1000(wilc_get_chipid(true)) && --trials)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001070 PRINT_D(TX_DBG, "PLL update retrying\n");
Greg Kroah-Hartmanc2e4c0f2015-09-03 19:09:50 -07001071 mdelay(1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001072 }
1073}
1074
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001075static void wilc_sleeptimer_isr_ext(u32 int_stats1)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001076{
1077 g_wlan.hif_func.hif_clear_int_ext(SLEEP_INT_CLR);
1078#ifndef WILC_OPTIMIZE_SLEEP_INT
Leo Kimb7d1e182015-11-06 11:12:30 +09001079 chip_ps_state = CHIP_SLEEPING_AUTO;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001080#endif
1081}
1082
Glen Lee3bcd45b2015-10-27 18:27:41 +09001083static void wilc_wlan_handle_isr_ext(struct wilc *wilc, u32 int_status)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001084{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301085 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001086#ifdef MEMORY_STATIC
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001087 u32 offset = p->rx_buffer_offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001088#endif
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001089 u8 *buffer = NULL;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001090 u32 size;
1091 u32 retries = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001092 int ret = 0;
1093 struct rxq_entry_t *rqe;
1094
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001095 size = ((int_status & 0x7fff) << 2);
1096
1097 while (!size && retries < 10) {
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001098 u32 time = 0;
Leo Kimac087c82015-11-06 11:12:25 +09001099
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001100 wilc_debug(N_ERR, "RX Size equal zero ... Trying to read it again for %d time\n", time++);
1101 p->hif_func.hif_read_size(&size);
1102 size = ((size & 0x7fff) << 2);
1103 retries++;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001104 }
1105
1106 if (size > 0) {
1107#ifdef MEMORY_STATIC
Glen Lee03eb7262015-09-24 18:15:03 +09001108 if (LINUX_RX_SIZE - offset < size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001109 offset = 0;
1110
1111 if (p->rx_buffer)
1112 buffer = &p->rx_buffer[offset];
1113 else {
1114 wilc_debug(N_ERR, "[wilc isr]: fail Rx Buffer is NULL...drop the packets (%d)\n", size);
1115 goto _end_;
1116 }
1117
1118#else
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001119 buffer = kmalloc(size, GFP_KERNEL);
Leo Kima4b17192015-11-06 11:12:31 +09001120 if (!buffer) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001121 wilc_debug(N_ERR, "[wilc isr]: fail alloc host memory...drop the packets (%d)\n", size);
Greg Kroah-Hartman80e29c72015-08-14 19:42:23 -07001122 usleep_range(100 * 1000, 100 * 1000);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001123 goto _end_;
1124 }
1125#endif
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001126 p->hif_func.hif_clear_int_ext(DATA_INT_CLR | ENABLE_RX_VMM);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001127 ret = p->hif_func.hif_block_rx_ext(0, buffer, size);
1128
1129 if (!ret) {
1130 wilc_debug(N_ERR, "[wilc isr]: fail block rx...\n");
1131 goto _end_;
1132 }
1133_end_:
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001134 if (ret) {
1135#ifdef MEMORY_STATIC
1136 offset += size;
1137 p->rx_buffer_offset = offset;
1138#endif
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001139 rqe = kmalloc(sizeof(struct rxq_entry_t), GFP_KERNEL);
Leo Kima4b17192015-11-06 11:12:31 +09001140 if (rqe) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001141 rqe->buffer = buffer;
1142 rqe->buffer_size = size;
1143 PRINT_D(RX_DBG, "rxq entery Size= %d - Address = %p\n", rqe->buffer_size, rqe->buffer);
Glen Leed06f3622015-10-27 18:27:59 +09001144 wilc_wlan_rxq_add(wilc, rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001145 }
1146 } else {
1147#ifndef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001148 kfree(buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001149#endif
1150 }
1151 }
Glen Lee39ce4d32015-10-27 18:27:42 +09001152 wilc_wlan_handle_rxq(wilc);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001153}
1154
Glen Lee50b929e2015-10-27 18:27:40 +09001155void wilc_handle_isr(void *wilc)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001156{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001157 u32 int_status;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001158
1159 acquire_bus(ACQUIRE_AND_WAKEUP);
1160 g_wlan.hif_func.hif_read_int(&int_status);
1161
Alison Schofield39823a52015-10-08 21:18:03 -07001162 if (int_status & PLL_INT_EXT)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001163 wilc_pllupdate_isr_ext(int_status);
Alison Schofield39823a52015-10-08 21:18:03 -07001164
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001165 if (int_status & DATA_INT_EXT) {
Glen Lee3bcd45b2015-10-27 18:27:41 +09001166 wilc_wlan_handle_isr_ext(wilc, int_status);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001167 #ifndef WILC_OPTIMIZE_SLEEP_INT
Leo Kimb7d1e182015-11-06 11:12:30 +09001168 chip_ps_state = CHIP_WAKEDUP;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001169 #endif
1170 }
Alison Schofield39823a52015-10-08 21:18:03 -07001171 if (int_status & SLEEP_INT_EXT)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001172 wilc_sleeptimer_isr_ext(int_status);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001173
1174 if (!(int_status & (ALL_INT_EXT))) {
1175#ifdef WILC_SDIO
1176 PRINT_D(TX_DBG, ">> UNKNOWN_INTERRUPT - 0x%08x\n", int_status);
1177#endif
1178 wilc_unknown_isr_ext();
1179 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001180 release_bus(RELEASE_ALLOW_SLEEP);
1181}
1182
Glen Lee63d7ab82015-10-01 16:03:32 +09001183int wilc_wlan_firmware_download(const u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001184{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301185 wilc_wlan_dev_t *p = &g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001186 u32 offset;
1187 u32 addr, size, size2, blksz;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001188 u8 *dma_buffer;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001189 int ret = 0;
1190
Anish Bhattffda2032015-09-29 12:15:49 -07001191 blksz = BIT(12);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001192
Greg Kroah-Hartmanf019b9d2015-09-03 18:50:27 -07001193 dma_buffer = kmalloc(blksz, GFP_KERNEL);
Leo Kima4b17192015-11-06 11:12:31 +09001194 if (!dma_buffer) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001195 ret = -5;
1196 PRINT_ER("Can't allocate buffer for firmware download IO error\n ");
1197 goto _fail_1;
1198 }
1199
1200 PRINT_D(INIT_DBG, "Downloading firmware size = %d ...\n", buffer_size);
Leo Kimac087c82015-11-06 11:12:25 +09001201
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001202 offset = 0;
1203 do {
1204 memcpy(&addr, &buffer[offset], 4);
1205 memcpy(&size, &buffer[offset + 4], 4);
1206#ifdef BIG_ENDIAN
1207 addr = BYTE_SWAP(addr);
1208 size = BYTE_SWAP(size);
1209#endif
1210 acquire_bus(ACQUIRE_ONLY);
1211 offset += 8;
1212 while (((int)size) && (offset < buffer_size)) {
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301213 if (size <= blksz)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001214 size2 = size;
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301215 else
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001216 size2 = blksz;
Leo Kimac087c82015-11-06 11:12:25 +09001217
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001218 memcpy(dma_buffer, &buffer[offset], size2);
1219 ret = p->hif_func.hif_block_tx(addr, dma_buffer, size2);
1220 if (!ret)
1221 break;
1222
1223 addr += size2;
1224 offset += size2;
1225 size -= size2;
1226 }
1227 release_bus(RELEASE_ONLY);
1228
1229 if (!ret) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001230 ret = -5;
1231 PRINT_ER("Can't download firmware IO error\n ");
1232 goto _fail_;
1233 }
1234 PRINT_D(INIT_DBG, "Offset = %d\n", offset);
1235 } while (offset < buffer_size);
1236
1237_fail_:
1238
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001239 kfree(dma_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001240
1241_fail_1:
1242
1243 return (ret < 0) ? ret : 0;
1244}
1245
Glen Leee42563b2015-10-01 16:03:33 +09001246int wilc_wlan_start(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001247{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301248 wilc_wlan_dev_t *p = &g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001249 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001250 int ret;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001251 u32 chipid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001252
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001253 if (p->io_func.io_type == HIF_SDIO) {
1254 reg = 0;
Leo Kimac087c82015-11-06 11:12:25 +09001255 reg |= BIT(3);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001256 } else if (p->io_func.io_type == HIF_SPI) {
1257 reg = 1;
1258 }
1259 acquire_bus(ACQUIRE_ONLY);
1260 ret = p->hif_func.hif_write_reg(WILC_VMM_CORE_CFG, reg);
1261 if (!ret) {
1262 wilc_debug(N_ERR, "[wilc start]: fail write reg vmm_core_cfg...\n");
1263 release_bus(RELEASE_ONLY);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001264 ret = -5;
1265 return ret;
1266 }
1267 reg = 0;
1268#ifdef WILC_SDIO_IRQ_GPIO
1269 reg |= WILC_HAVE_SDIO_IRQ_GPIO;
1270#endif
1271
1272#ifdef WILC_DISABLE_PMU
1273#else
1274 reg |= WILC_HAVE_USE_PMU;
1275#endif
1276
1277#ifdef WILC_SLEEP_CLK_SRC_XO
1278 reg |= WILC_HAVE_SLEEP_CLK_SRC_XO;
1279#elif defined WILC_SLEEP_CLK_SRC_RTC
1280 reg |= WILC_HAVE_SLEEP_CLK_SRC_RTC;
1281#endif
1282
1283#ifdef WILC_EXT_PA_INV_TX_RX
1284 reg |= WILC_HAVE_EXT_PA_INV_TX_RX;
1285#endif
1286
1287 reg |= WILC_HAVE_LEGACY_RF_SETTINGS;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001288#ifdef XTAL_24
1289 reg |= WILC_HAVE_XTAL_24;
1290#endif
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001291#ifdef DISABLE_WILC_UART
1292 reg |= WILC_HAVE_DISABLE_WILC_UART;
1293#endif
1294
1295 ret = p->hif_func.hif_write_reg(WILC_GP_REG_1, reg);
1296 if (!ret) {
1297 wilc_debug(N_ERR, "[wilc start]: fail write WILC_GP_REG_1 ...\n");
1298 release_bus(RELEASE_ONLY);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001299 ret = -5;
1300 return ret;
1301 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001302
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001303 p->hif_func.hif_sync_ext(NUM_INT_EXT);
1304
1305 ret = p->hif_func.hif_read_reg(0x1000, &chipid);
1306 if (!ret) {
1307 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1000 ...\n");
1308 release_bus(RELEASE_ONLY);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001309 ret = -5;
1310 return ret;
1311 }
1312
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001313 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
Anish Bhattffda2032015-09-29 12:15:49 -07001314 if ((reg & BIT(10)) == BIT(10)) {
1315 reg &= ~BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001316 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1317 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1318 }
1319
Anish Bhattffda2032015-09-29 12:15:49 -07001320 reg |= BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001321 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1322 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1323 release_bus(RELEASE_ONLY);
1324
1325 return (ret < 0) ? ret : 0;
1326}
1327
1328void wilc_wlan_global_reset(void)
1329{
1330
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301331 wilc_wlan_dev_t *p = &g_wlan;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +09001332
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001333 acquire_bus(ACQUIRE_AND_WAKEUP);
1334 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, 0x0);
1335 release_bus(RELEASE_ONLY);
1336}
Glen Lee8cec7412015-10-01 16:03:34 +09001337int wilc_wlan_stop(void)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001338{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301339 wilc_wlan_dev_t *p = &g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001340 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001341 int ret;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001342 u8 timeout = 10;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001343 acquire_bus(ACQUIRE_AND_WAKEUP);
1344
1345 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1346 if (!ret) {
1347 PRINT_ER("Error while reading reg\n");
1348 release_bus(RELEASE_ALLOW_SLEEP);
1349 return ret;
1350 }
1351
Anish Bhattffda2032015-09-29 12:15:49 -07001352 reg &= ~BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001353 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1354 if (!ret) {
1355 PRINT_ER("Error while writing reg\n");
1356 release_bus(RELEASE_ALLOW_SLEEP);
1357 return ret;
1358 }
1359
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001360 do {
1361 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1362 if (!ret) {
1363 PRINT_ER("Error while reading reg\n");
1364 release_bus(RELEASE_ALLOW_SLEEP);
1365 return ret;
1366 }
1367 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
Leo Kimac087c82015-11-06 11:12:25 +09001368
Anish Bhattffda2032015-09-29 12:15:49 -07001369 if ((reg & BIT(10))) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001370 PRINT_D(GENERIC_DBG, "Bit 10 not reset : Retry %d\n", timeout);
Anish Bhattffda2032015-09-29 12:15:49 -07001371 reg &= ~BIT(10);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001372 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1373 timeout--;
1374 } else {
1375 PRINT_D(GENERIC_DBG, "Bit 10 reset after : Retry %d\n", timeout);
1376 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
1377 if (!ret) {
1378 PRINT_ER("Error while reading reg\n");
1379 release_bus(RELEASE_ALLOW_SLEEP);
1380 return ret;
1381 }
1382 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1383 break;
1384 }
1385
1386 } while (timeout);
Anish Bhattffda2032015-09-29 12:15:49 -07001387 reg = (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(8) | BIT(9) | BIT(26) |
1388 BIT(29) | BIT(30) | BIT(31));
Anish Bhatt65ead4e2015-09-29 12:15:48 -07001389
1390 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
Anish Bhattffda2032015-09-29 12:15:49 -07001391 reg = (u32)~BIT(10);
Anish Bhatt65ead4e2015-09-29 12:15:48 -07001392
1393 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001394
1395 release_bus(RELEASE_ALLOW_SLEEP);
1396
1397 return ret;
1398}
1399
Glen Lee2de7cbe2015-10-27 18:27:54 +09001400void wilc_wlan_cleanup(struct net_device *dev)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001401{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301402 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001403 struct txq_entry_t *tqe;
1404 struct rxq_entry_t *rqe;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001405 u32 reg = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001406 int ret;
Glen Leedb387632015-10-27 18:27:55 +09001407 perInterface_wlan_t *nic;
1408 struct wilc *wilc;
1409
1410 nic = netdev_priv(dev);
1411 wilc = nic->wilc;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001412
1413 p->quit = 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001414 do {
Glen Lee718fc2c2015-10-29 12:18:43 +09001415 tqe = wilc_wlan_txq_remove_from_head(dev);
Leo Kima4b17192015-11-06 11:12:31 +09001416 if (!tqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001417 break;
1418 if (tqe->tx_complete_func)
1419 tqe->tx_complete_func(tqe->priv, 0);
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001420 kfree(tqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001421 } while (1);
1422
1423 do {
Glen Leedb387632015-10-27 18:27:55 +09001424 rqe = wilc_wlan_rxq_remove(wilc);
Leo Kima4b17192015-11-06 11:12:31 +09001425 if (!rqe)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001426 break;
Javier Martinez Canillas6a272242015-09-22 15:24:50 +02001427#ifndef MEMORY_STATIC
1428 kfree(rqe->buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001429#endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001430 kfree(rqe);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001431 } while (1);
1432
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001433 #ifdef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001434 kfree(p->rx_buffer);
1435 p->rx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001436 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001437 kfree(p->tx_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001438
1439 acquire_bus(ACQUIRE_AND_WAKEUP);
1440
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001441 ret = p->hif_func.hif_read_reg(WILC_GP_REG_0, &reg);
1442 if (!ret) {
1443 PRINT_ER("Error while reading reg\n");
1444 release_bus(RELEASE_ALLOW_SLEEP);
1445 }
1446 PRINT_ER("Writing ABORT reg\n");
1447 ret = p->hif_func.hif_write_reg(WILC_GP_REG_0, (reg | ABORT_INT));
1448 if (!ret) {
1449 PRINT_ER("Error while writing reg\n");
1450 release_bus(RELEASE_ALLOW_SLEEP);
1451 }
1452 release_bus(RELEASE_ALLOW_SLEEP);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001453 p->hif_func.hif_deinit(NULL);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001454}
1455
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001456static int wilc_wlan_cfg_commit(int type, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001457{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301458 wilc_wlan_dev_t *p = &g_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001459 wilc_cfg_frame_t *cfg = &p->cfg_frame;
1460 int total_len = p->cfg_frame_offset + 4 + DRIVER_HANDLER_SIZE;
1461 int seq_no = p->cfg_seq_no % 256;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001462 int driver_handler = (u32)drvHandler;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001463
Leo Kimac087c82015-11-06 11:12:25 +09001464 if (type == WILC_CFG_SET) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001465 cfg->wid_header[0] = 'W';
Leo Kimac087c82015-11-06 11:12:25 +09001466 } else {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001467 cfg->wid_header[0] = 'Q';
1468 }
Leo Kimac087c82015-11-06 11:12:25 +09001469 cfg->wid_header[1] = seq_no;
Chaehyun Lim51e825f2015-09-15 14:06:14 +09001470 cfg->wid_header[2] = (u8)total_len;
1471 cfg->wid_header[3] = (u8)(total_len >> 8);
1472 cfg->wid_header[4] = (u8)driver_handler;
1473 cfg->wid_header[5] = (u8)(driver_handler >> 8);
1474 cfg->wid_header[6] = (u8)(driver_handler >> 16);
1475 cfg->wid_header[7] = (u8)(driver_handler >> 24);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001476 p->cfg_seq_no = seq_no;
1477
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001478 if (!wilc_wlan_txq_add_cfg_pkt(&cfg->wid_header[0], total_len))
1479 return -1;
1480
1481 return 0;
1482}
1483
Glen Lee1028e5a2015-10-01 16:03:40 +09001484int wilc_wlan_cfg_set(int start, u32 wid, u8 *buffer, u32 buffer_size,
1485 int commit, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001486{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301487 wilc_wlan_dev_t *p = &g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001488 u32 offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001489 int ret_size;
1490
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001491 if (p->cfg_frame_in_use)
1492 return 0;
1493
1494 if (start)
1495 p->cfg_frame_offset = 0;
1496
1497 offset = p->cfg_frame_offset;
Glen Lee17e8f162015-10-02 14:22:07 +09001498 ret_size = wilc_wlan_cfg_set_wid(p->cfg_frame.frame, offset, (u16)wid,
1499 buffer, buffer_size);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001500 offset += ret_size;
1501 p->cfg_frame_offset = offset;
1502
1503 if (commit) {
1504 PRINT_D(TX_DBG, "[WILC]PACKET Commit with sequence number %d\n", p->cfg_seq_no);
1505 PRINT_D(RX_DBG, "Processing cfg_set()\n");
1506 p->cfg_frame_in_use = 1;
1507
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001508 if (wilc_wlan_cfg_commit(WILC_CFG_SET, drvHandler))
Chaehyun Lim5af6b852015-09-17 16:48:48 +09001509 ret_size = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001510
Glen Leeb002e202015-09-24 18:15:05 +09001511 if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event,
1512 CFG_PKTS_TIMEOUT)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001513 PRINT_D(TX_DBG, "Set Timed Out\n");
1514 ret_size = 0;
1515 }
1516 p->cfg_frame_in_use = 0;
1517 p->cfg_frame_offset = 0;
1518 p->cfg_seq_no += 1;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001519 }
1520
1521 return ret_size;
1522}
Leo Kim2d6973e2015-11-06 11:12:28 +09001523
Glen Lee07056a82015-10-01 16:03:41 +09001524int wilc_wlan_cfg_get(int start, u32 wid, int commit, u32 drvHandler)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001525{
Shivani Bhardwaj7ee82912015-10-13 17:04:48 +05301526 wilc_wlan_dev_t *p = &g_wlan;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001527 u32 offset;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001528 int ret_size;
1529
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001530 if (p->cfg_frame_in_use)
1531 return 0;
1532
1533 if (start)
1534 p->cfg_frame_offset = 0;
1535
1536 offset = p->cfg_frame_offset;
Glen Leeec1b86b2015-10-02 14:22:08 +09001537 ret_size = wilc_wlan_cfg_get_wid(p->cfg_frame.frame, offset, (u16)wid);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001538 offset += ret_size;
1539 p->cfg_frame_offset = offset;
1540
1541 if (commit) {
1542 p->cfg_frame_in_use = 1;
1543
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001544 if (wilc_wlan_cfg_commit(WILC_CFG_QUERY, drvHandler))
Chaehyun Lim5af6b852015-09-17 16:48:48 +09001545 ret_size = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001546
Glen Leeb002e202015-09-24 18:15:05 +09001547 if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event,
1548 CFG_PKTS_TIMEOUT)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001549 PRINT_D(TX_DBG, "Get Timed Out\n");
1550 ret_size = 0;
1551 }
1552 PRINT_D(GENERIC_DBG, "[WILC]Get Response received\n");
1553 p->cfg_frame_in_use = 0;
1554 p->cfg_frame_offset = 0;
1555 p->cfg_seq_no += 1;
1556 }
1557
1558 return ret_size;
1559}
1560
Glen Lee894de36b2015-10-01 16:03:42 +09001561int wilc_wlan_cfg_get_val(u32 wid, u8 *buffer, u32 buffer_size)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001562{
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001563 int ret;
1564
Glen Lee355cca22015-10-02 14:22:09 +09001565 ret = wilc_wlan_cfg_get_wid_value((u16)wid, buffer, buffer_size);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001566
1567 return ret;
1568}
1569
1570void wilc_bus_set_max_speed(void)
1571{
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001572 g_wlan.hif_func.hif_set_max_bus_speed();
1573}
1574
1575void wilc_bus_set_default_speed(void)
1576{
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001577 g_wlan.hif_func.hif_set_default_bus_speed();
1578}
Leo Kim2d6973e2015-11-06 11:12:28 +09001579
Glen Leeae6f7722015-10-29 12:18:48 +09001580u32 init_chip(struct net_device *dev)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001581{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001582 u32 chipid;
1583 u32 reg, ret = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001584
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001585 acquire_bus(ACQUIRE_ONLY);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001586
Dean Lee72ed4dc2015-06-12 14:11:44 +09001587 chipid = wilc_get_chipid(true);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001588
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001589 if ((chipid & 0xfff) != 0xa0) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001590 ret = g_wlan.hif_func.hif_read_reg(0x1118, &reg);
1591 if (!ret) {
1592 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1118 ...\n");
1593 return ret;
1594 }
Anish Bhattffda2032015-09-29 12:15:49 -07001595 reg |= BIT(0);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001596 ret = g_wlan.hif_func.hif_write_reg(0x1118, reg);
1597 if (!ret) {
1598 wilc_debug(N_ERR, "[wilc start]: fail write reg 0x1118 ...\n");
1599 return ret;
1600 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001601 ret = g_wlan.hif_func.hif_write_reg(0xc0000, 0x71);
1602 if (!ret) {
1603 wilc_debug(N_ERR, "[wilc start]: fail write reg 0xc0000 ...\n");
1604 return ret;
1605 }
1606 }
1607
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001608 release_bus(RELEASE_ONLY);
1609
1610 return ret;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001611}
1612
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001613u32 wilc_get_chipid(u8 update)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001614{
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001615 static u32 chipid;
Chaehyun Limfbc2fe12015-09-15 14:06:16 +09001616 u32 tempchipid = 0;
1617 u32 rfrevid;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001618
1619 if (chipid == 0 || update != 0) {
1620 g_wlan.hif_func.hif_read_reg(0x1000, &tempchipid);
1621 g_wlan.hif_func.hif_read_reg(0x13f4, &rfrevid);
1622 if (!ISWILC1000(tempchipid)) {
1623 chipid = 0;
1624 goto _fail_;
1625 }
1626 if (tempchipid == 0x1002a0) {
Leo Kimac087c82015-11-06 11:12:25 +09001627 if (rfrevid == 0x1) {
1628 } else {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001629 tempchipid = 0x1002a1;
1630 }
1631 } else if (tempchipid == 0x1002b0) {
Leo Kimac087c82015-11-06 11:12:25 +09001632 if (rfrevid == 3) {
1633 } else if (rfrevid == 4) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001634 tempchipid = 0x1002b1;
Leo Kimac087c82015-11-06 11:12:25 +09001635 } else {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001636 tempchipid = 0x1002b2;
1637 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001638 }
1639
1640 chipid = tempchipid;
1641 }
1642_fail_:
1643 return chipid;
1644}
1645
Glen Lee47a466f2015-10-29 12:18:47 +09001646int wilc_wlan_init(struct net_device *dev, wilc_wlan_inp_t *inp)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001647{
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001648 int ret = 0;
1649
1650 PRINT_D(INIT_DBG, "Initializing WILC_Wlan ...\n");
1651
1652 memset((void *)&g_wlan, 0, sizeof(wilc_wlan_dev_t));
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001653 memcpy((void *)&g_wlan.io_func, (void *)&inp->io_func, sizeof(wilc_wlan_io_func_t));
Leo Kimac087c82015-11-06 11:12:25 +09001654
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001655 if ((inp->io_func.io_type & 0x1) == HIF_SDIO) {
1656 if (!hif_sdio.hif_init(inp, wilc_debug)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001657 ret = -5;
1658 goto _fail_;
1659 }
1660 memcpy((void *)&g_wlan.hif_func, &hif_sdio, sizeof(wilc_hif_func_t));
1661 } else {
1662 if ((inp->io_func.io_type & 0x1) == HIF_SPI) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001663 if (!hif_spi.hif_init(inp, wilc_debug)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001664 ret = -5;
1665 goto _fail_;
1666 }
1667 memcpy((void *)&g_wlan.hif_func, &hif_spi, sizeof(wilc_hif_func_t));
1668 } else {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001669 ret = -5;
1670 goto _fail_;
1671 }
1672 }
1673
Glen Lee814bc362015-10-02 14:22:11 +09001674 if (!wilc_wlan_cfg_init(wilc_debug)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001675 ret = -105;
1676 goto _fail_;
1677 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001678
Leo Kima4b17192015-11-06 11:12:31 +09001679 if (!g_wlan.tx_buffer)
Glen Lee7015b5d2015-09-24 18:15:02 +09001680 g_wlan.tx_buffer = kmalloc(LINUX_TX_SIZE, GFP_KERNEL);
Arnd Bergmann7a8fd842015-06-01 21:06:45 +02001681 PRINT_D(TX_DBG, "g_wlan.tx_buffer = %p\n", g_wlan.tx_buffer);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001682
Leo Kima4b17192015-11-06 11:12:31 +09001683 if (!g_wlan.tx_buffer) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001684 ret = -105;
1685 PRINT_ER("Can't allocate Tx Buffer");
1686 goto _fail_;
1687 }
1688
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001689#if defined (MEMORY_STATIC)
Leo Kima4b17192015-11-06 11:12:31 +09001690 if (!g_wlan.rx_buffer)
Glen Lee03eb7262015-09-24 18:15:03 +09001691 g_wlan.rx_buffer = kmalloc(LINUX_RX_SIZE, GFP_KERNEL);
Arnd Bergmann7a8fd842015-06-01 21:06:45 +02001692 PRINT_D(TX_DBG, "g_wlan.rx_buffer =%p\n", g_wlan.rx_buffer);
Leo Kima4b17192015-11-06 11:12:31 +09001693 if (!g_wlan.rx_buffer) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001694 ret = -105;
1695 PRINT_ER("Can't allocate Rx Buffer");
1696 goto _fail_;
1697 }
1698#endif
1699
Glen Leeae6f7722015-10-29 12:18:48 +09001700 if (!init_chip(dev)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001701 ret = -5;
1702 goto _fail_;
1703 }
1704#ifdef TCP_ACK_FILTER
Leo Kimef06b5f2015-11-06 11:12:44 +09001705 init_tcp_tracking();
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001706#endif
1707
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001708 return 1;
1709
1710_fail_:
1711
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001712 #ifdef MEMORY_STATIC
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001713 kfree(g_wlan.rx_buffer);
1714 g_wlan.rx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001715 #endif
Greg Kroah-Hartmana18dd632015-09-03 19:04:19 -07001716 kfree(g_wlan.tx_buffer);
1717 g_wlan.tx_buffer = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001718
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001719 return ret;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001720}
1721
Leo Kim2ad8c472015-11-05 14:36:35 +09001722u16 set_machw_change_vir_if(struct net_device *dev, bool bValue)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001723{
Chaehyun Limd85f5322015-06-11 14:35:54 +09001724 u16 ret;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +09001725 u32 reg;
Glen Lee178c3832015-10-27 18:27:58 +09001726 perInterface_wlan_t *nic;
1727 struct wilc *wilc;
1728
1729 nic = netdev_priv(dev);
1730 wilc = nic->wilc;
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001731
Glen Lee178c3832015-10-27 18:27:58 +09001732 mutex_lock(&wilc->hif_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001733 ret = (&g_wlan)->hif_func.hif_read_reg(WILC_CHANGING_VIR_IF, &reg);
Alison Schofield39823a52015-10-08 21:18:03 -07001734 if (!ret)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001735 PRINT_ER("Error while Reading reg WILC_CHANGING_VIR_IF\n");
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001736
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301737 if (bValue)
Chaehyun Lim50b51da2015-09-16 20:11:26 +09001738 reg |= BIT(31);
Chandra S Gorentla78174ad2015-08-08 17:41:36 +05301739 else
Chaehyun Lim50b51da2015-09-16 20:11:26 +09001740 reg &= ~BIT(31);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001741
1742 ret = (&g_wlan)->hif_func.hif_write_reg(WILC_CHANGING_VIR_IF, reg);
1743
Alison Schofield39823a52015-10-08 21:18:03 -07001744 if (!ret)
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001745 PRINT_ER("Error while writing reg WILC_CHANGING_VIR_IF\n");
Alison Schofield39823a52015-10-08 21:18:03 -07001746
Glen Lee178c3832015-10-27 18:27:58 +09001747 mutex_unlock(&wilc->hif_cs);
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001748
1749 return ret;
1750}