Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1 | /* ////////////////////////////////////////////////////////////////////////// */ |
| 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" |
| 11 | #include "wilc_wlan.h" |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 12 | |
| 13 | /******************************************** |
| 14 | * |
| 15 | * Global |
| 16 | * |
| 17 | ********************************************/ |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 18 | extern wilc_hif_func_t hif_sdio; |
| 19 | extern wilc_hif_func_t hif_spi; |
| 20 | extern wilc_cfg_func_t mac_cfg; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 21 | extern void WILC_WFI_mgmt_rx(u8 *buff, u32 size); |
| 22 | u32 wilc_get_chipid(u8 update); |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 23 | u16 Set_machw_change_vir_if(bool bValue); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 24 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 25 | |
| 26 | |
| 27 | typedef struct { |
| 28 | int quit; |
| 29 | |
| 30 | /** |
| 31 | * input interface functions |
| 32 | **/ |
| 33 | wilc_wlan_os_func_t os_func; |
| 34 | wilc_wlan_io_func_t io_func; |
| 35 | wilc_wlan_net_func_t net_func; |
| 36 | wilc_wlan_indicate_func_t indicate_func; |
| 37 | |
| 38 | /** |
| 39 | * host interface functions |
| 40 | **/ |
| 41 | wilc_hif_func_t hif_func; |
Greg Kroah-Hartman | 5e150b5 | 2015-09-03 19:32:11 -0700 | [diff] [blame] | 42 | struct mutex *hif_lock; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * configuration interface functions |
| 46 | **/ |
| 47 | wilc_cfg_func_t cif_func; |
| 48 | int cfg_frame_in_use; |
| 49 | wilc_cfg_frame_t cfg_frame; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 50 | u32 cfg_frame_offset; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 51 | int cfg_seq_no; |
| 52 | void *cfg_wait; |
| 53 | |
| 54 | /** |
| 55 | * RX buffer |
| 56 | **/ |
| 57 | #ifdef MEMORY_STATIC |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 58 | u32 rx_buffer_size; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 59 | u8 *rx_buffer; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 60 | u32 rx_buffer_offset; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 61 | #endif |
| 62 | /** |
| 63 | * TX buffer |
| 64 | **/ |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 65 | u32 tx_buffer_size; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 66 | u8 *tx_buffer; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 67 | u32 tx_buffer_offset; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 68 | |
| 69 | /** |
| 70 | * TX queue |
| 71 | **/ |
| 72 | void *txq_lock; |
| 73 | |
| 74 | /*Added by Amr - BugID_4720*/ |
Greg Kroah-Hartman | 8990d85 | 2015-09-03 20:07:58 -0700 | [diff] [blame] | 75 | struct semaphore *txq_add_to_head_lock; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 76 | void *txq_spinlock; |
| 77 | unsigned long txq_spinlock_flags; |
| 78 | |
| 79 | struct txq_entry_t *txq_head; |
| 80 | struct txq_entry_t *txq_tail; |
| 81 | int txq_entries; |
| 82 | void *txq_wait; |
| 83 | int txq_exit; |
| 84 | |
| 85 | /** |
| 86 | * RX queue |
| 87 | **/ |
Greg Kroah-Hartman | 5e150b5 | 2015-09-03 19:32:11 -0700 | [diff] [blame] | 88 | struct mutex *rxq_lock; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 89 | struct rxq_entry_t *rxq_head; |
| 90 | struct rxq_entry_t *rxq_tail; |
| 91 | int rxq_entries; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 92 | int rxq_exit; |
| 93 | |
| 94 | |
| 95 | } wilc_wlan_dev_t; |
| 96 | |
| 97 | static wilc_wlan_dev_t g_wlan; |
| 98 | |
Chaehyun Lim | 9af382b | 2015-09-16 20:11:27 +0900 | [diff] [blame] | 99 | static inline void chip_allow_sleep(void); |
| 100 | static inline void chip_wakeup(void); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 101 | /******************************************** |
| 102 | * |
| 103 | * Debug |
| 104 | * |
| 105 | ********************************************/ |
| 106 | |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 107 | static u32 dbgflag = N_INIT | N_ERR | N_INTR | N_TXQ | N_RXQ; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 108 | |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 109 | static void wilc_debug(u32 flag, char *fmt, ...) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 110 | { |
| 111 | char buf[256]; |
| 112 | va_list args; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 113 | |
| 114 | if (flag & dbgflag) { |
| 115 | va_start(args, fmt); |
Hari Prasath Gujulan Elango | 8105322 | 2015-06-22 13:13:58 +0000 | [diff] [blame] | 116 | vsprintf(buf, fmt, args); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 117 | va_end(args); |
| 118 | |
| 119 | if (g_wlan.os_func.os_debug) |
| 120 | g_wlan.os_func.os_debug(buf); |
| 121 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | static CHIP_PS_STATE_T genuChipPSstate = CHIP_WAKEDUP; |
| 125 | |
| 126 | /*BugID_5213*/ |
Chaehyun Lim | 9af382b | 2015-09-16 20:11:27 +0900 | [diff] [blame] | 127 | /*acquire_bus() and release_bus() are made static inline functions*/ |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 128 | /*as a temporary workaround to fix a problem of receiving*/ |
| 129 | /*unknown interrupt from FW*/ |
Chaehyun Lim | 9af382b | 2015-09-16 20:11:27 +0900 | [diff] [blame] | 130 | static inline void acquire_bus(BUS_ACQUIRE_T acquire) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 131 | { |
| 132 | |
Greg Kroah-Hartman | 5e150b5 | 2015-09-03 19:32:11 -0700 | [diff] [blame] | 133 | mutex_lock(g_wlan.hif_lock); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 134 | #ifndef WILC_OPTIMIZE_SLEEP_INT |
| 135 | if (genuChipPSstate != CHIP_WAKEDUP) |
| 136 | #endif |
| 137 | { |
| 138 | if (acquire == ACQUIRE_AND_WAKEUP) |
| 139 | chip_wakeup(); |
| 140 | } |
| 141 | |
| 142 | } |
Chaehyun Lim | 9af382b | 2015-09-16 20:11:27 +0900 | [diff] [blame] | 143 | static inline void release_bus(BUS_RELEASE_T release) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 144 | { |
| 145 | #ifdef WILC_OPTIMIZE_SLEEP_INT |
| 146 | if (release == RELEASE_ALLOW_SLEEP) |
| 147 | chip_allow_sleep(); |
| 148 | #endif |
Greg Kroah-Hartman | 5e150b5 | 2015-09-03 19:32:11 -0700 | [diff] [blame] | 149 | mutex_unlock(g_wlan.hif_lock); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 150 | } |
| 151 | /******************************************** |
| 152 | * |
| 153 | * Queue |
| 154 | * |
| 155 | ********************************************/ |
| 156 | |
| 157 | static void wilc_wlan_txq_remove(struct txq_entry_t *tqe) |
| 158 | { |
| 159 | |
| 160 | wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; |
| 161 | /* unsigned long flags; */ |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 162 | if (tqe == p->txq_head) { |
| 163 | |
| 164 | p->txq_head = tqe->next; |
| 165 | if (p->txq_head) |
| 166 | p->txq_head->prev = NULL; |
| 167 | |
| 168 | |
| 169 | } else if (tqe == p->txq_tail) { |
| 170 | p->txq_tail = (tqe->prev); |
| 171 | if (p->txq_tail) |
| 172 | p->txq_tail->next = NULL; |
| 173 | } else { |
| 174 | tqe->prev->next = tqe->next; |
| 175 | tqe->next->prev = tqe->prev; |
| 176 | } |
| 177 | p->txq_entries -= 1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 178 | |
| 179 | } |
| 180 | |
| 181 | static struct txq_entry_t *wilc_wlan_txq_remove_from_head(void) |
| 182 | { |
| 183 | struct txq_entry_t *tqe; |
| 184 | wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; |
| 185 | unsigned long flags; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 186 | |
Greg Kroah-Hartman | 17c4d5d | 2015-09-03 20:17:31 -0700 | [diff] [blame] | 187 | spin_lock_irqsave(p->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 188 | if (p->txq_head) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 189 | tqe = p->txq_head; |
| 190 | p->txq_head = tqe->next; |
| 191 | if (p->txq_head) { |
| 192 | p->txq_head->prev = NULL; |
| 193 | } |
| 194 | p->txq_entries -= 1; |
| 195 | |
| 196 | /*Added by Amr - BugID_4720*/ |
| 197 | |
| 198 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 199 | |
| 200 | } else { |
| 201 | tqe = NULL; |
| 202 | } |
Greg Kroah-Hartman | 17c4d5d | 2015-09-03 20:17:31 -0700 | [diff] [blame] | 203 | spin_unlock_irqrestore(p->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 204 | return tqe; |
| 205 | } |
| 206 | |
| 207 | static void wilc_wlan_txq_add_to_tail(struct txq_entry_t *tqe) |
| 208 | { |
| 209 | wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; |
| 210 | unsigned long flags; |
| 211 | /*Added by Amr - BugID_4720*/ |
Greg Kroah-Hartman | 17c4d5d | 2015-09-03 20:17:31 -0700 | [diff] [blame] | 212 | spin_lock_irqsave(p->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 213 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 214 | if (p->txq_head == NULL) { |
| 215 | tqe->next = NULL; |
| 216 | tqe->prev = NULL; |
| 217 | p->txq_head = tqe; |
| 218 | p->txq_tail = tqe; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 219 | } else { |
| 220 | tqe->next = NULL; |
| 221 | tqe->prev = p->txq_tail; |
| 222 | p->txq_tail->next = tqe; |
| 223 | p->txq_tail = tqe; |
| 224 | } |
| 225 | p->txq_entries += 1; |
| 226 | PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 227 | |
| 228 | /*Added by Amr - BugID_4720*/ |
Greg Kroah-Hartman | 17c4d5d | 2015-09-03 20:17:31 -0700 | [diff] [blame] | 229 | spin_unlock_irqrestore(p->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 230 | |
| 231 | /** |
| 232 | * wake up TX queue |
| 233 | **/ |
| 234 | PRINT_D(TX_DBG, "Wake the txq_handling\n"); |
| 235 | |
Greg Kroah-Hartman | 8990d85 | 2015-09-03 20:07:58 -0700 | [diff] [blame] | 236 | up(p->txq_wait); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | static int wilc_wlan_txq_add_to_head(struct txq_entry_t *tqe) |
| 240 | { |
| 241 | wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; |
| 242 | unsigned long flags; |
| 243 | /*Added by Amr - BugID_4720*/ |
| 244 | if (p->os_func.os_wait(p->txq_add_to_head_lock, CFG_PKTS_TIMEOUT)) |
| 245 | return -1; |
| 246 | |
Greg Kroah-Hartman | 17c4d5d | 2015-09-03 20:17:31 -0700 | [diff] [blame] | 247 | spin_lock_irqsave(p->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 248 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 249 | if (p->txq_head == NULL) { |
| 250 | tqe->next = NULL; |
| 251 | tqe->prev = NULL; |
| 252 | p->txq_head = tqe; |
| 253 | p->txq_tail = tqe; |
| 254 | } else { |
| 255 | tqe->next = p->txq_head; |
| 256 | tqe->prev = NULL; |
| 257 | p->txq_head->prev = tqe; |
| 258 | p->txq_head = tqe; |
| 259 | } |
| 260 | p->txq_entries += 1; |
| 261 | PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 262 | |
| 263 | /*Added by Amr - BugID_4720*/ |
Greg Kroah-Hartman | 17c4d5d | 2015-09-03 20:17:31 -0700 | [diff] [blame] | 264 | spin_unlock_irqrestore(p->txq_spinlock, flags); |
Greg Kroah-Hartman | 8990d85 | 2015-09-03 20:07:58 -0700 | [diff] [blame] | 265 | up(p->txq_add_to_head_lock); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 266 | |
| 267 | |
| 268 | /** |
| 269 | * wake up TX queue |
| 270 | **/ |
Greg Kroah-Hartman | 8990d85 | 2015-09-03 20:07:58 -0700 | [diff] [blame] | 271 | up(p->txq_wait); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 272 | PRINT_D(TX_DBG, "Wake up the txq_handler\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 273 | |
| 274 | /*Added by Amr - BugID_4720*/ |
| 275 | return 0; |
| 276 | |
| 277 | } |
| 278 | |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 279 | u32 Statisitcs_totalAcks = 0, Statisitcs_DroppedAcks = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 280 | |
| 281 | #ifdef TCP_ACK_FILTER |
| 282 | struct Ack_session_info; |
Shraddha Barke | eeb1c06 | 2015-08-05 01:29:22 +0530 | [diff] [blame] | 283 | struct Ack_session_info { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 284 | u32 Ack_seq_num; |
| 285 | u32 Bigger_Ack_num; |
Chaehyun Lim | ec53adf | 2015-09-15 14:06:15 +0900 | [diff] [blame] | 286 | u16 src_port; |
| 287 | u16 dst_port; |
| 288 | u16 status; |
Shraddha Barke | eeb1c06 | 2015-08-05 01:29:22 +0530 | [diff] [blame] | 289 | }; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 290 | |
| 291 | typedef struct { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 292 | u32 ack_num; |
| 293 | u32 Session_index; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 294 | struct txq_entry_t *txqe; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 295 | } Pending_Acks_info_t /*Ack_info_t*/; |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | struct Ack_session_info *Free_head; |
| 301 | struct Ack_session_info *Alloc_head; |
| 302 | |
| 303 | #define TCP_FIN_MASK (1 << 0) |
| 304 | #define TCP_SYN_MASK (1 << 1) |
| 305 | #define TCP_Ack_MASK (1 << 4) |
| 306 | #define NOT_TCP_ACK (-1) |
| 307 | |
| 308 | #define MAX_TCP_SESSION 25 |
| 309 | #define MAX_PENDING_ACKS 256 |
Shraddha Barke | eeb1c06 | 2015-08-05 01:29:22 +0530 | [diff] [blame] | 310 | struct Ack_session_info Acks_keep_track_info[2 * MAX_TCP_SESSION]; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 311 | Pending_Acks_info_t Pending_Acks_info[MAX_PENDING_ACKS]; |
| 312 | |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 313 | u32 PendingAcks_arrBase; |
| 314 | u32 Opened_TCP_session; |
| 315 | u32 Pending_Acks; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 316 | |
| 317 | |
| 318 | |
Chaehyun Lim | fed16f2 | 2015-09-17 16:48:43 +0900 | [diff] [blame^] | 319 | static inline int Init_TCP_tracking(void) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 320 | { |
| 321 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 322 | return 0; |
| 323 | |
| 324 | } |
Chaehyun Lim | fed16f2 | 2015-09-17 16:48:43 +0900 | [diff] [blame^] | 325 | static inline int add_TCP_track_session(u32 src_prt, u32 dst_prt, u32 seq) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 326 | { |
| 327 | Acks_keep_track_info[Opened_TCP_session].Ack_seq_num = seq; |
| 328 | Acks_keep_track_info[Opened_TCP_session].Bigger_Ack_num = 0; |
| 329 | Acks_keep_track_info[Opened_TCP_session].src_port = src_prt; |
| 330 | Acks_keep_track_info[Opened_TCP_session].dst_port = dst_prt; |
| 331 | Opened_TCP_session++; |
| 332 | |
| 333 | PRINT_D(TCP_ENH, "TCP Session %d to Ack %d\n", Opened_TCP_session, seq); |
| 334 | return 0; |
| 335 | } |
| 336 | |
Chaehyun Lim | fed16f2 | 2015-09-17 16:48:43 +0900 | [diff] [blame^] | 337 | static inline int Update_TCP_track_session(u32 index, u32 Ack) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 338 | { |
| 339 | |
| 340 | if (Ack > Acks_keep_track_info[index].Bigger_Ack_num) { |
| 341 | Acks_keep_track_info[index].Bigger_Ack_num = Ack; |
| 342 | } |
| 343 | return 0; |
| 344 | |
| 345 | } |
Chaehyun Lim | fed16f2 | 2015-09-17 16:48:43 +0900 | [diff] [blame^] | 346 | static inline int add_TCP_Pending_Ack(u32 Ack, u32 Session_index, struct txq_entry_t *txqe) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 347 | { |
| 348 | Statisitcs_totalAcks++; |
| 349 | if (Pending_Acks < MAX_PENDING_ACKS) { |
| 350 | Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].ack_num = Ack; |
| 351 | Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].txqe = txqe; |
| 352 | Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].Session_index = Session_index; |
| 353 | txqe->tcp_PendingAck_index = PendingAcks_arrBase + Pending_Acks; |
| 354 | Pending_Acks++; |
| 355 | |
| 356 | } else { |
| 357 | |
| 358 | } |
| 359 | return 0; |
| 360 | } |
Chaehyun Lim | fed16f2 | 2015-09-17 16:48:43 +0900 | [diff] [blame^] | 361 | static inline int remove_TCP_related(void) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 362 | { |
| 363 | wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; |
| 364 | unsigned long flags; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 365 | |
Greg Kroah-Hartman | 17c4d5d | 2015-09-03 20:17:31 -0700 | [diff] [blame] | 366 | spin_lock_irqsave(p->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 367 | |
Greg Kroah-Hartman | 17c4d5d | 2015-09-03 20:17:31 -0700 | [diff] [blame] | 368 | spin_unlock_irqrestore(p->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 369 | return 0; |
| 370 | } |
| 371 | |
Chaehyun Lim | fed16f2 | 2015-09-17 16:48:43 +0900 | [diff] [blame^] | 372 | static inline int tcp_process(struct txq_entry_t *tqe) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 373 | { |
| 374 | int ret; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 375 | u8 *eth_hdr_ptr; |
| 376 | u8 *buffer = tqe->buffer; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 377 | unsigned short h_proto; |
| 378 | int i; |
| 379 | wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; |
| 380 | unsigned long flags; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 381 | |
Greg Kroah-Hartman | 17c4d5d | 2015-09-03 20:17:31 -0700 | [diff] [blame] | 382 | spin_lock_irqsave(p->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 383 | |
| 384 | eth_hdr_ptr = &buffer[0]; |
| 385 | h_proto = ntohs(*((unsigned short *)ð_hdr_ptr[12])); |
| 386 | if (h_proto == 0x0800) { /* IP */ |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 387 | u8 *ip_hdr_ptr; |
| 388 | u8 protocol; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 389 | |
| 390 | ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN]; |
| 391 | protocol = ip_hdr_ptr[9]; |
| 392 | |
| 393 | |
| 394 | if (protocol == 0x06) { |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 395 | u8 *tcp_hdr_ptr; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 396 | u32 IHL, Total_Length, Data_offset; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 397 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 398 | tcp_hdr_ptr = &ip_hdr_ptr[IP_HDR_LEN]; |
| 399 | IHL = (ip_hdr_ptr[0] & 0xf) << 2; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 400 | Total_Length = (((u32)ip_hdr_ptr[2]) << 8) + ((u32)ip_hdr_ptr[3]); |
| 401 | Data_offset = (((u32)tcp_hdr_ptr[12] & 0xf0) >> 2); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 402 | 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 Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 403 | u32 seq_no, Ack_no; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 404 | |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 405 | 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 Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 406 | |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 407 | 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 Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 408 | |
| 409 | |
| 410 | for (i = 0; i < Opened_TCP_session; i++) { |
| 411 | if (Acks_keep_track_info[i].Ack_seq_num == seq_no) { |
| 412 | Update_TCP_track_session(i, Ack_no); |
| 413 | break; |
| 414 | } |
| 415 | } |
| 416 | if (i == Opened_TCP_session) { |
| 417 | add_TCP_track_session(0, 0, seq_no); |
| 418 | } |
| 419 | add_TCP_Pending_Ack(Ack_no, i, tqe); |
| 420 | |
| 421 | |
| 422 | } |
| 423 | |
| 424 | } else { |
| 425 | ret = 0; |
| 426 | } |
| 427 | } else { |
| 428 | ret = 0; |
| 429 | } |
Greg Kroah-Hartman | 17c4d5d | 2015-09-03 20:17:31 -0700 | [diff] [blame] | 430 | spin_unlock_irqrestore(p->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 431 | return ret; |
| 432 | } |
| 433 | |
| 434 | |
| 435 | static int wilc_wlan_txq_filter_dup_tcp_ack(void) |
| 436 | { |
| 437 | |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 438 | u32 i = 0; |
| 439 | u32 Dropped = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 440 | wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; |
| 441 | |
Greg Kroah-Hartman | 17c4d5d | 2015-09-03 20:17:31 -0700 | [diff] [blame] | 442 | spin_lock_irqsave(p->txq_spinlock, p->txq_spinlock_flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 443 | for (i = PendingAcks_arrBase; i < (PendingAcks_arrBase + Pending_Acks); i++) { |
| 444 | if (Pending_Acks_info[i].ack_num < Acks_keep_track_info[Pending_Acks_info[i].Session_index].Bigger_Ack_num) { |
| 445 | struct txq_entry_t *tqe; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 446 | |
Chandra S Gorentla | 17aacd4 | 2015-08-08 17:41:35 +0530 | [diff] [blame] | 447 | PRINT_D(TCP_ENH, "DROP ACK: %u\n", Pending_Acks_info[i].ack_num); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 448 | tqe = Pending_Acks_info[i].txqe; |
| 449 | if (tqe) { |
| 450 | wilc_wlan_txq_remove(tqe); |
| 451 | Statisitcs_DroppedAcks++; |
| 452 | tqe->status = 1; /* mark the packet send */ |
| 453 | if (tqe->tx_complete_func) |
| 454 | tqe->tx_complete_func(tqe->priv, tqe->status); |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 455 | kfree(tqe); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 456 | Dropped++; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | } |
| 460 | Pending_Acks = 0; |
| 461 | Opened_TCP_session = 0; |
| 462 | |
Chandra S Gorentla | 78174ad | 2015-08-08 17:41:36 +0530 | [diff] [blame] | 463 | if (PendingAcks_arrBase == 0) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 464 | PendingAcks_arrBase = MAX_TCP_SESSION; |
Chandra S Gorentla | 78174ad | 2015-08-08 17:41:36 +0530 | [diff] [blame] | 465 | else |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 466 | PendingAcks_arrBase = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 467 | |
| 468 | |
Greg Kroah-Hartman | 17c4d5d | 2015-09-03 20:17:31 -0700 | [diff] [blame] | 469 | spin_unlock_irqrestore(p->txq_spinlock, p->txq_spinlock_flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 470 | |
| 471 | while (Dropped > 0) { |
| 472 | /*consume the semaphore count of the removed packet*/ |
| 473 | p->os_func.os_wait(p->txq_wait, 1); |
| 474 | Dropped--; |
| 475 | } |
| 476 | |
| 477 | return 1; |
| 478 | } |
| 479 | #endif |
| 480 | |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 481 | bool EnableTCPAckFilter = false; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 482 | |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 483 | void Enable_TCP_ACK_Filter(bool value) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 484 | { |
| 485 | EnableTCPAckFilter = value; |
| 486 | } |
| 487 | |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 488 | bool is_TCP_ACK_Filter_Enabled(void) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 489 | { |
| 490 | return EnableTCPAckFilter; |
| 491 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 492 | |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 493 | static int wilc_wlan_txq_add_cfg_pkt(u8 *buffer, u32 buffer_size) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 494 | { |
| 495 | wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; |
| 496 | struct txq_entry_t *tqe; |
| 497 | |
| 498 | PRINT_D(TX_DBG, "Adding config packet ...\n"); |
| 499 | if (p->quit) { |
| 500 | PRINT_D(TX_DBG, "Return due to clear function\n"); |
Greg Kroah-Hartman | 8990d85 | 2015-09-03 20:07:58 -0700 | [diff] [blame] | 501 | up(p->cfg_wait); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 502 | return 0; |
| 503 | } |
| 504 | |
Greg Kroah-Hartman | 47c632d | 2015-09-03 18:55:43 -0700 | [diff] [blame] | 505 | tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 506 | if (tqe == NULL) { |
| 507 | PRINT_ER("Failed to allocate memory\n"); |
| 508 | return 0; |
| 509 | } |
| 510 | |
| 511 | tqe->type = WILC_CFG_PKT; |
| 512 | tqe->buffer = buffer; |
| 513 | tqe->buffer_size = buffer_size; |
| 514 | tqe->tx_complete_func = NULL; |
| 515 | tqe->priv = NULL; |
| 516 | #ifdef TCP_ACK_FILTER |
| 517 | tqe->tcp_PendingAck_index = NOT_TCP_ACK; |
| 518 | #endif |
| 519 | /** |
| 520 | * Configuration packet always at the front |
| 521 | **/ |
| 522 | PRINT_D(TX_DBG, "Adding the config packet at the Queue tail\n"); |
| 523 | |
| 524 | /*Edited by Amr - BugID_4720*/ |
| 525 | if (wilc_wlan_txq_add_to_head(tqe)) |
| 526 | return 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 527 | return 1; |
| 528 | } |
| 529 | |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 530 | static int wilc_wlan_txq_add_net_pkt(void *priv, u8 *buffer, u32 buffer_size, wilc_tx_complete_func_t func) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 531 | { |
| 532 | wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; |
| 533 | struct txq_entry_t *tqe; |
| 534 | |
| 535 | if (p->quit) |
| 536 | return 0; |
| 537 | |
Greg Kroah-Hartman | 47c632d | 2015-09-03 18:55:43 -0700 | [diff] [blame] | 538 | tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 539 | |
| 540 | if (tqe == NULL) |
| 541 | return 0; |
| 542 | tqe->type = WILC_NET_PKT; |
| 543 | tqe->buffer = buffer; |
| 544 | tqe->buffer_size = buffer_size; |
| 545 | tqe->tx_complete_func = func; |
| 546 | tqe->priv = priv; |
| 547 | |
| 548 | PRINT_D(TX_DBG, "Adding mgmt packet at the Queue tail\n"); |
| 549 | #ifdef TCP_ACK_FILTER |
| 550 | tqe->tcp_PendingAck_index = NOT_TCP_ACK; |
Abdul Hussain | 5a66bf2 | 2015-06-16 09:44:06 +0000 | [diff] [blame] | 551 | if (is_TCP_ACK_Filter_Enabled()) |
Glen Lee | 25a8483 | 2015-09-16 18:53:22 +0900 | [diff] [blame] | 552 | tcp_process(tqe); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 553 | #endif |
| 554 | wilc_wlan_txq_add_to_tail(tqe); |
| 555 | /*return number of itemes in the queue*/ |
| 556 | return p->txq_entries; |
| 557 | } |
Glen Lee | fcc6ef9 | 2015-09-16 18:53:21 +0900 | [diff] [blame] | 558 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 559 | /*Bug3959: transmitting mgmt frames received from host*/ |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 560 | int wilc_wlan_txq_add_mgmt_pkt(void *priv, u8 *buffer, u32 buffer_size, wilc_tx_complete_func_t func) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 561 | { |
| 562 | |
| 563 | wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; |
| 564 | struct txq_entry_t *tqe; |
| 565 | |
| 566 | if (p->quit) |
| 567 | return 0; |
| 568 | |
Greg Kroah-Hartman | 47c632d | 2015-09-03 18:55:43 -0700 | [diff] [blame] | 569 | tqe = kmalloc(sizeof(struct txq_entry_t), GFP_KERNEL); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 570 | |
| 571 | if (tqe == NULL) |
| 572 | return 0; |
| 573 | tqe->type = WILC_MGMT_PKT; |
| 574 | tqe->buffer = buffer; |
| 575 | tqe->buffer_size = buffer_size; |
| 576 | tqe->tx_complete_func = func; |
| 577 | tqe->priv = priv; |
| 578 | #ifdef TCP_ACK_FILTER |
| 579 | tqe->tcp_PendingAck_index = NOT_TCP_ACK; |
| 580 | #endif |
| 581 | PRINT_D(TX_DBG, "Adding Network packet at the Queue tail\n"); |
| 582 | wilc_wlan_txq_add_to_tail(tqe); |
| 583 | return 1; |
| 584 | } |
Glen Lee | fcc6ef9 | 2015-09-16 18:53:21 +0900 | [diff] [blame] | 585 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 586 | static struct txq_entry_t *wilc_wlan_txq_get_first(void) |
| 587 | { |
| 588 | wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; |
| 589 | struct txq_entry_t *tqe; |
| 590 | unsigned long flags; |
| 591 | |
| 592 | /*Added by Amr - BugID_4720*/ |
Greg Kroah-Hartman | 17c4d5d | 2015-09-03 20:17:31 -0700 | [diff] [blame] | 593 | spin_lock_irqsave(p->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 594 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 595 | tqe = p->txq_head; |
| 596 | |
| 597 | /*Added by Amr - BugID_4720*/ |
Greg Kroah-Hartman | 17c4d5d | 2015-09-03 20:17:31 -0700 | [diff] [blame] | 598 | spin_unlock_irqrestore(p->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 599 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 600 | |
| 601 | return tqe; |
| 602 | } |
| 603 | |
| 604 | static struct txq_entry_t *wilc_wlan_txq_get_next(struct txq_entry_t *tqe) |
| 605 | { |
| 606 | wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; |
| 607 | unsigned long flags; |
| 608 | /*Added by Amr - BugID_4720*/ |
Greg Kroah-Hartman | 17c4d5d | 2015-09-03 20:17:31 -0700 | [diff] [blame] | 609 | spin_lock_irqsave(p->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 610 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 611 | tqe = tqe->next; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 612 | /*Added by Amr - BugID_4720*/ |
Greg Kroah-Hartman | 17c4d5d | 2015-09-03 20:17:31 -0700 | [diff] [blame] | 613 | spin_unlock_irqrestore(p->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 614 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 615 | |
| 616 | return tqe; |
| 617 | } |
| 618 | |
| 619 | static int wilc_wlan_rxq_add(struct rxq_entry_t *rqe) |
| 620 | { |
| 621 | wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; |
| 622 | |
| 623 | if (p->quit) |
| 624 | return 0; |
| 625 | |
Greg Kroah-Hartman | 5e150b5 | 2015-09-03 19:32:11 -0700 | [diff] [blame] | 626 | mutex_lock(p->rxq_lock); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 627 | if (p->rxq_head == NULL) { |
| 628 | PRINT_D(RX_DBG, "Add to Queue head\n"); |
| 629 | rqe->next = NULL; |
| 630 | p->rxq_head = rqe; |
| 631 | p->rxq_tail = rqe; |
| 632 | } else { |
| 633 | PRINT_D(RX_DBG, "Add to Queue tail\n"); |
| 634 | p->rxq_tail->next = rqe; |
| 635 | rqe->next = NULL; |
| 636 | p->rxq_tail = rqe; |
| 637 | } |
| 638 | p->rxq_entries += 1; |
| 639 | PRINT_D(RX_DBG, "Number of queue entries: %d\n", p->rxq_entries); |
Greg Kroah-Hartman | 5e150b5 | 2015-09-03 19:32:11 -0700 | [diff] [blame] | 640 | mutex_unlock(p->rxq_lock); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 641 | return p->rxq_entries; |
| 642 | } |
| 643 | |
| 644 | static struct rxq_entry_t *wilc_wlan_rxq_remove(void) |
| 645 | { |
| 646 | wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; |
| 647 | |
| 648 | PRINT_D(RX_DBG, "Getting rxQ element\n"); |
| 649 | if (p->rxq_head) { |
| 650 | struct rxq_entry_t *rqe; |
| 651 | |
Greg Kroah-Hartman | 5e150b5 | 2015-09-03 19:32:11 -0700 | [diff] [blame] | 652 | mutex_lock(p->rxq_lock); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 653 | rqe = p->rxq_head; |
| 654 | p->rxq_head = p->rxq_head->next; |
| 655 | p->rxq_entries -= 1; |
| 656 | PRINT_D(RX_DBG, "RXQ entries decreased\n"); |
Greg Kroah-Hartman | 5e150b5 | 2015-09-03 19:32:11 -0700 | [diff] [blame] | 657 | mutex_unlock(p->rxq_lock); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 658 | return rqe; |
| 659 | } |
| 660 | PRINT_D(RX_DBG, "Nothing to get from Q\n"); |
| 661 | return NULL; |
| 662 | } |
| 663 | |
| 664 | |
| 665 | /******************************************** |
| 666 | * |
| 667 | * Power Save handle functions |
| 668 | * |
| 669 | ********************************************/ |
| 670 | |
| 671 | |
| 672 | |
| 673 | #ifdef WILC_OPTIMIZE_SLEEP_INT |
| 674 | |
Chaehyun Lim | 9af382b | 2015-09-16 20:11:27 +0900 | [diff] [blame] | 675 | static inline void chip_allow_sleep(void) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 676 | { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 677 | u32 reg = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 678 | |
| 679 | /* Clear bit 1 */ |
| 680 | g_wlan.hif_func.hif_read_reg(0xf0, ®); |
| 681 | |
| 682 | g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0)); |
| 683 | } |
| 684 | |
Chaehyun Lim | 9af382b | 2015-09-16 20:11:27 +0900 | [diff] [blame] | 685 | static inline void chip_wakeup(void) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 686 | { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 687 | u32 reg, clk_status_reg, trials = 0; |
| 688 | u32 sleep_time; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 689 | |
| 690 | if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) { |
| 691 | do { |
| 692 | g_wlan.hif_func.hif_read_reg(1, ®); |
| 693 | /* Set bit 1 */ |
| 694 | g_wlan.hif_func.hif_write_reg(1, reg | (1 << 1)); |
| 695 | |
| 696 | /* Clear bit 1*/ |
| 697 | g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1)); |
| 698 | |
| 699 | do { |
| 700 | /* Wait for the chip to stabilize*/ |
Greg Kroah-Hartman | 80e29c7 | 2015-08-14 19:42:23 -0700 | [diff] [blame] | 701 | usleep_range(2 * 1000, 2 * 1000); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 702 | /* Make sure chip is awake. This is an extra step that can be removed */ |
| 703 | /* later to avoid the bus access overhead */ |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 704 | if ((wilc_get_chipid(true) == 0)) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 705 | wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n"); |
| 706 | } |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 707 | } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0)); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 708 | |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 709 | } while (wilc_get_chipid(true) == 0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 710 | } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) { |
| 711 | g_wlan.hif_func.hif_read_reg(0xf0, ®); |
| 712 | do { |
| 713 | /* Set bit 1 */ |
| 714 | g_wlan.hif_func.hif_write_reg(0xf0, reg | (1 << 0)); |
| 715 | |
| 716 | /* Check the clock status */ |
| 717 | g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg); |
| 718 | |
| 719 | /* in case of clocks off, wait 2ms, and check it again. */ |
| 720 | /* if still off, wait for another 2ms, for a total wait of 6ms. */ |
| 721 | /* If still off, redo the wake up sequence */ |
| 722 | while (((clk_status_reg & 0x1) == 0) && (((++trials) % 3) == 0)) { |
| 723 | /* Wait for the chip to stabilize*/ |
Greg Kroah-Hartman | 80e29c7 | 2015-08-14 19:42:23 -0700 | [diff] [blame] | 724 | usleep_range(2 * 1000, 2 * 1000); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 725 | |
| 726 | /* Make sure chip is awake. This is an extra step that can be removed */ |
| 727 | /* later to avoid the bus access overhead */ |
| 728 | g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg); |
| 729 | |
| 730 | if ((clk_status_reg & 0x1) == 0) { |
| 731 | wilc_debug(N_ERR, "clocks still OFF. Wake up failed\n"); |
| 732 | } |
| 733 | } |
| 734 | /* in case of failure, Reset the wakeup bit to introduce a new edge on the next loop */ |
| 735 | if ((clk_status_reg & 0x1) == 0) { |
| 736 | /* Reset bit 0 */ |
| 737 | g_wlan.hif_func.hif_write_reg(0xf0, reg & (~(1 << 0))); |
| 738 | } |
| 739 | } while ((clk_status_reg & 0x1) == 0); |
| 740 | } |
| 741 | |
| 742 | |
| 743 | if (genuChipPSstate == CHIP_SLEEPING_MANUAL) { |
| 744 | g_wlan.hif_func.hif_read_reg(0x1C0C, ®); |
| 745 | reg &= ~(1 << 0); |
| 746 | g_wlan.hif_func.hif_write_reg(0x1C0C, reg); |
| 747 | |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 748 | if (wilc_get_chipid(false) >= 0x1002b0) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 749 | /* Enable PALDO back right after wakeup */ |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 750 | u32 val32; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 751 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 752 | g_wlan.hif_func.hif_read_reg(0x1e1c, &val32); |
| 753 | val32 |= (1 << 6); |
| 754 | g_wlan.hif_func.hif_write_reg(0x1e1c, val32); |
| 755 | |
| 756 | g_wlan.hif_func.hif_read_reg(0x1e9c, &val32); |
| 757 | val32 |= (1 << 6); |
| 758 | g_wlan.hif_func.hif_write_reg(0x1e9c, val32); |
| 759 | } |
| 760 | } |
| 761 | genuChipPSstate = CHIP_WAKEDUP; |
| 762 | } |
| 763 | #else |
Chaehyun Lim | 9af382b | 2015-09-16 20:11:27 +0900 | [diff] [blame] | 764 | static inline void chip_wakeup(void) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 765 | { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 766 | u32 reg, trials = 0; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 767 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 768 | do { |
| 769 | if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) { |
| 770 | g_wlan.hif_func.hif_read_reg(1, ®); |
| 771 | /* Make sure bit 1 is 0 before we start. */ |
| 772 | g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1)); |
| 773 | /* Set bit 1 */ |
| 774 | g_wlan.hif_func.hif_write_reg(1, reg | (1 << 1)); |
| 775 | /* Clear bit 1*/ |
| 776 | g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1)); |
| 777 | } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) { |
| 778 | /* Make sure bit 0 is 0 before we start. */ |
| 779 | g_wlan.hif_func.hif_read_reg(0xf0, ®); |
| 780 | g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0)); |
| 781 | /* Set bit 1 */ |
| 782 | g_wlan.hif_func.hif_write_reg(0xf0, reg | (1 << 0)); |
| 783 | /* Clear bit 1 */ |
| 784 | g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0)); |
| 785 | } |
| 786 | |
| 787 | do { |
| 788 | /* Wait for the chip to stabilize*/ |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 789 | mdelay(3); |
| 790 | |
| 791 | /* Make sure chip is awake. This is an extra step that can be removed */ |
| 792 | /* later to avoid the bus access overhead */ |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 793 | if ((wilc_get_chipid(true) == 0)) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 794 | wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n"); |
| 795 | } |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 796 | } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0)); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 797 | |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 798 | } while (wilc_get_chipid(true) == 0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 799 | |
| 800 | if (genuChipPSstate == CHIP_SLEEPING_MANUAL) { |
| 801 | g_wlan.hif_func.hif_read_reg(0x1C0C, ®); |
| 802 | reg &= ~(1 << 0); |
| 803 | g_wlan.hif_func.hif_write_reg(0x1C0C, reg); |
| 804 | |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 805 | if (wilc_get_chipid(false) >= 0x1002b0) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 806 | /* Enable PALDO back right after wakeup */ |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 807 | u32 val32; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 808 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 809 | g_wlan.hif_func.hif_read_reg(0x1e1c, &val32); |
| 810 | val32 |= (1 << 6); |
| 811 | g_wlan.hif_func.hif_write_reg(0x1e1c, val32); |
| 812 | |
| 813 | g_wlan.hif_func.hif_read_reg(0x1e9c, &val32); |
| 814 | val32 |= (1 << 6); |
| 815 | g_wlan.hif_func.hif_write_reg(0x1e9c, val32); |
| 816 | } |
| 817 | } |
| 818 | genuChipPSstate = CHIP_WAKEDUP; |
| 819 | } |
| 820 | #endif |
Chaehyun Lim | 4e4467f | 2015-06-11 14:35:55 +0900 | [diff] [blame] | 821 | void chip_sleep_manually(u32 u32SleepTime) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 822 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 823 | if (genuChipPSstate != CHIP_WAKEDUP) { |
| 824 | /* chip is already sleeping. Do nothing */ |
| 825 | return; |
| 826 | } |
| 827 | acquire_bus(ACQUIRE_ONLY); |
| 828 | |
| 829 | #ifdef WILC_OPTIMIZE_SLEEP_INT |
| 830 | chip_allow_sleep(); |
| 831 | #endif |
| 832 | |
| 833 | /* Trigger the manual sleep interrupt */ |
| 834 | g_wlan.hif_func.hif_write_reg(0x10a8, 1); |
| 835 | |
| 836 | genuChipPSstate = CHIP_SLEEPING_MANUAL; |
| 837 | release_bus(RELEASE_ONLY); |
| 838 | |
| 839 | } |
| 840 | |
| 841 | |
| 842 | /******************************************** |
| 843 | * |
| 844 | * Tx, Rx queue handle functions |
| 845 | * |
| 846 | ********************************************/ |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 847 | static int wilc_wlan_handle_txq(u32 *pu32TxqCount) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 848 | { |
| 849 | wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; |
| 850 | int i, entries = 0; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 851 | u32 sum; |
| 852 | u32 reg; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 853 | u8 *txb = p->tx_buffer; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 854 | u32 offset = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 855 | int vmm_sz = 0; |
| 856 | struct txq_entry_t *tqe; |
| 857 | int ret = 0; |
| 858 | int counter; |
| 859 | int timeout; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 860 | u32 vmm_table[WILC_VMM_TBL_SIZE]; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 861 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 862 | p->txq_exit = 0; |
| 863 | do { |
| 864 | if (p->quit) |
| 865 | break; |
| 866 | |
| 867 | /*Added by Amr - BugID_4720*/ |
| 868 | p->os_func.os_wait(p->txq_add_to_head_lock, CFG_PKTS_TIMEOUT); |
| 869 | #ifdef TCP_ACK_FILTER |
| 870 | wilc_wlan_txq_filter_dup_tcp_ack(); |
| 871 | #endif |
| 872 | /** |
| 873 | * build the vmm list |
| 874 | **/ |
| 875 | PRINT_D(TX_DBG, "Getting the head of the TxQ\n"); |
| 876 | tqe = wilc_wlan_txq_get_first(); |
| 877 | i = 0; |
| 878 | sum = 0; |
| 879 | do { |
| 880 | /* if ((tqe != NULL) && (i < (8)) && */ |
| 881 | /* if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE-1)) && */ |
| 882 | if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE - 1)) /* reserve last entry to 0 */) { |
| 883 | |
| 884 | if (tqe->type == WILC_CFG_PKT) { |
| 885 | vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET; |
| 886 | } |
| 887 | /*Bug3959: transmitting mgmt frames received from host*/ |
| 888 | /*vmm_sz will only be equal to tqe->buffer_size + 4 bytes (HOST_HDR_OFFSET)*/ |
| 889 | /* in other cases WILC_MGMT_PKT and WILC_DATA_PKT_MAC_HDR*/ |
| 890 | else if (tqe->type == WILC_NET_PKT) { |
| 891 | vmm_sz = ETH_ETHERNET_HDR_OFFSET; |
| 892 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 893 | else { |
| 894 | vmm_sz = HOST_HDR_OFFSET; |
| 895 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 896 | vmm_sz += tqe->buffer_size; |
| 897 | PRINT_D(TX_DBG, "VMM Size before alignment = %d\n", vmm_sz); |
| 898 | if (vmm_sz & 0x3) { /* has to be word aligned */ |
| 899 | vmm_sz = (vmm_sz + 4) & ~0x3; |
| 900 | } |
| 901 | if ((sum + vmm_sz) > p->tx_buffer_size) { |
| 902 | break; |
| 903 | } |
| 904 | PRINT_D(TX_DBG, "VMM Size AFTER alignment = %d\n", vmm_sz); |
| 905 | vmm_table[i] = vmm_sz / 4; /* table take the word size */ |
| 906 | PRINT_D(TX_DBG, "VMMTable entry size = %d\n", vmm_table[i]); |
| 907 | |
| 908 | if (tqe->type == WILC_CFG_PKT) { |
| 909 | vmm_table[i] |= (1 << 10); |
| 910 | PRINT_D(TX_DBG, "VMMTable entry changed for CFG packet = %d\n", vmm_table[i]); |
| 911 | } |
| 912 | #ifdef BIG_ENDIAN |
| 913 | vmm_table[i] = BYTE_SWAP(vmm_table[i]); |
| 914 | #endif |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 915 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 916 | i++; |
| 917 | sum += vmm_sz; |
| 918 | PRINT_D(TX_DBG, "sum = %d\n", sum); |
| 919 | tqe = wilc_wlan_txq_get_next(tqe); |
| 920 | } else { |
| 921 | break; |
| 922 | } |
| 923 | } while (1); |
| 924 | |
| 925 | if (i == 0) { /* nothing in the queue */ |
| 926 | PRINT_D(TX_DBG, "Nothing in TX-Q\n"); |
| 927 | break; |
| 928 | } else { |
| 929 | PRINT_D(TX_DBG, "Mark the last entry in VMM table - number of previous entries = %d\n", i); |
| 930 | vmm_table[i] = 0x0; /* mark the last element to 0 */ |
| 931 | } |
| 932 | acquire_bus(ACQUIRE_AND_WAKEUP); |
| 933 | counter = 0; |
| 934 | do { |
| 935 | |
| 936 | ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, ®); |
| 937 | if (!ret) { |
| 938 | wilc_debug(N_ERR, "[wilc txq]: fail can't read reg vmm_tbl_entry..\n"); |
| 939 | break; |
| 940 | } |
| 941 | |
| 942 | if ((reg & 0x1) == 0) { |
| 943 | /** |
| 944 | * write to vmm table |
| 945 | **/ |
| 946 | PRINT_D(TX_DBG, "Writing VMM table ... with Size = %d\n", ((i + 1) * 4)); |
| 947 | break; |
| 948 | } else { |
| 949 | counter++; |
| 950 | if (counter > 200) { |
| 951 | counter = 0; |
| 952 | PRINT_D(TX_DBG, "Looping in tx ctrl , forcce quit\n"); |
| 953 | ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, 0); |
| 954 | break; |
| 955 | } |
| 956 | /** |
| 957 | * wait for vmm table is ready |
| 958 | **/ |
Chandra S Gorentla | 17aacd4 | 2015-08-08 17:41:35 +0530 | [diff] [blame] | 959 | PRINT_WRN(GENERIC_DBG, "[wilc txq]: warn, vmm table not clear yet, wait...\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 960 | release_bus(RELEASE_ALLOW_SLEEP); |
Greg Kroah-Hartman | 2b922cb | 2015-09-04 09:30:51 -0700 | [diff] [blame] | 961 | usleep_range(3000, 3000); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 962 | acquire_bus(ACQUIRE_AND_WAKEUP); |
| 963 | } |
| 964 | } while (!p->quit); |
| 965 | |
| 966 | if (!ret) { |
| 967 | goto _end_; |
| 968 | } |
| 969 | |
| 970 | timeout = 200; |
| 971 | do { |
| 972 | |
| 973 | /** |
| 974 | * write to vmm table |
| 975 | **/ |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 976 | ret = p->hif_func.hif_block_tx(WILC_VMM_TBL_RX_SHADOW_BASE, (u8 *)vmm_table, ((i + 1) * 4)); /* Bug 4477 fix */ |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 977 | if (!ret) { |
| 978 | wilc_debug(N_ERR, "ERR block TX of VMM table.\n"); |
| 979 | break; |
| 980 | } |
| 981 | |
| 982 | |
| 983 | /** |
| 984 | * interrupt firmware |
| 985 | **/ |
| 986 | ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x2); |
| 987 | if (!ret) { |
| 988 | wilc_debug(N_ERR, "[wilc txq]: fail can't write reg host_vmm_ctl..\n"); |
| 989 | break; |
| 990 | } |
| 991 | |
| 992 | /** |
| 993 | * wait for confirm... |
| 994 | **/ |
| 995 | |
| 996 | do { |
| 997 | ret = p->hif_func.hif_read_reg(WILC_HOST_VMM_CTL, ®); |
| 998 | if (!ret) { |
| 999 | wilc_debug(N_ERR, "[wilc txq]: fail can't read reg host_vmm_ctl..\n"); |
| 1000 | break; |
| 1001 | } |
| 1002 | if ((reg >> 2) & 0x1) { |
| 1003 | /** |
| 1004 | * Get the entries |
| 1005 | **/ |
| 1006 | entries = ((reg >> 3) & 0x3f); |
| 1007 | /* entries = ((reg>>3)&0x2f); */ |
| 1008 | break; |
| 1009 | } else { |
| 1010 | release_bus(RELEASE_ALLOW_SLEEP); |
Greg Kroah-Hartman | 2b922cb | 2015-09-04 09:30:51 -0700 | [diff] [blame] | 1011 | usleep_range(3000, 3000); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1012 | acquire_bus(ACQUIRE_AND_WAKEUP); |
| 1013 | PRINT_WRN(GENERIC_DBG, "Can't get VMM entery - reg = %2x\n", reg); |
| 1014 | } |
| 1015 | } while (--timeout); |
| 1016 | if (timeout <= 0) { |
| 1017 | ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x0); |
| 1018 | break; |
| 1019 | } |
| 1020 | |
| 1021 | if (!ret) { |
| 1022 | break; |
| 1023 | } |
| 1024 | |
| 1025 | if (entries == 0) { |
Chandra S Gorentla | 17aacd4 | 2015-08-08 17:41:35 +0530 | [diff] [blame] | 1026 | 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 Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1027 | |
| 1028 | /* undo the transaction. */ |
| 1029 | ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, ®); |
| 1030 | if (!ret) { |
| 1031 | wilc_debug(N_ERR, "[wilc txq]: fail can't read reg WILC_HOST_TX_CTRL..\n"); |
| 1032 | break; |
| 1033 | } |
| 1034 | reg &= ~(1ul << 0); |
| 1035 | ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, reg); |
| 1036 | if (!ret) { |
| 1037 | wilc_debug(N_ERR, "[wilc txq]: fail can't write reg WILC_HOST_TX_CTRL..\n"); |
| 1038 | break; |
| 1039 | } |
| 1040 | break; |
| 1041 | } else { |
| 1042 | break; |
| 1043 | } |
| 1044 | } while (1); |
| 1045 | |
| 1046 | if (!ret) { |
| 1047 | goto _end_; |
| 1048 | } |
| 1049 | if (entries == 0) { |
| 1050 | ret = WILC_TX_ERR_NO_BUF; |
| 1051 | goto _end_; |
| 1052 | } |
| 1053 | |
| 1054 | /* since copying data into txb takes some time, then |
| 1055 | * allow the bus lock to be released let the RX task go. */ |
| 1056 | release_bus(RELEASE_ALLOW_SLEEP); |
| 1057 | |
| 1058 | /** |
| 1059 | * Copy data to the TX buffer |
| 1060 | **/ |
| 1061 | offset = 0; |
| 1062 | i = 0; |
| 1063 | do { |
| 1064 | tqe = wilc_wlan_txq_remove_from_head(); |
| 1065 | if (tqe != NULL && (vmm_table[i] != 0)) { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1066 | u32 header, buffer_offset; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1067 | |
| 1068 | #ifdef BIG_ENDIAN |
| 1069 | vmm_table[i] = BYTE_SWAP(vmm_table[i]); |
| 1070 | #endif |
| 1071 | vmm_sz = (vmm_table[i] & 0x3ff); /* in word unit */ |
| 1072 | vmm_sz *= 4; |
| 1073 | header = (tqe->type << 31) | (tqe->buffer_size << 15) | vmm_sz; |
| 1074 | /*Bug3959: transmitting mgmt frames received from host*/ |
| 1075 | /*setting bit 30 in the host header to indicate mgmt frame*/ |
Chandra S Gorentla | 78174ad | 2015-08-08 17:41:36 +0530 | [diff] [blame] | 1076 | if (tqe->type == WILC_MGMT_PKT) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1077 | header |= (1 << 30); |
Chandra S Gorentla | 78174ad | 2015-08-08 17:41:36 +0530 | [diff] [blame] | 1078 | else |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1079 | header &= ~(1 << 30); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1080 | |
| 1081 | #ifdef BIG_ENDIAN |
| 1082 | header = BYTE_SWAP(header); |
| 1083 | #endif |
| 1084 | memcpy(&txb[offset], &header, 4); |
| 1085 | if (tqe->type == WILC_CFG_PKT) { |
| 1086 | buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET; |
| 1087 | } |
| 1088 | /*Bug3959: transmitting mgmt frames received from host*/ |
| 1089 | /*buffer offset = HOST_HDR_OFFSET in other cases: WILC_MGMT_PKT*/ |
| 1090 | /* and WILC_DATA_PKT_MAC_HDR*/ |
| 1091 | else if (tqe->type == WILC_NET_PKT) { |
| 1092 | char *pBSSID = ((struct tx_complete_data *)(tqe->priv))->pBssid; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 1093 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1094 | buffer_offset = ETH_ETHERNET_HDR_OFFSET; |
| 1095 | /* copy the bssid at the sart of the buffer */ |
| 1096 | memcpy(&txb[offset + 4], pBSSID, 6); |
| 1097 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1098 | else { |
| 1099 | buffer_offset = HOST_HDR_OFFSET; |
| 1100 | } |
| 1101 | |
| 1102 | memcpy(&txb[offset + buffer_offset], tqe->buffer, tqe->buffer_size); |
| 1103 | offset += vmm_sz; |
| 1104 | i++; |
| 1105 | tqe->status = 1; /* mark the packet send */ |
| 1106 | if (tqe->tx_complete_func) |
| 1107 | tqe->tx_complete_func(tqe->priv, tqe->status); |
| 1108 | #ifdef TCP_ACK_FILTER |
| 1109 | if (tqe->tcp_PendingAck_index != NOT_TCP_ACK) { |
| 1110 | Pending_Acks_info[tqe->tcp_PendingAck_index].txqe = NULL; |
| 1111 | } |
| 1112 | #endif |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 1113 | kfree(tqe); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1114 | } else { |
| 1115 | break; |
| 1116 | } |
| 1117 | } while (--entries); |
| 1118 | |
| 1119 | /** |
| 1120 | * lock the bus |
| 1121 | **/ |
| 1122 | acquire_bus(ACQUIRE_AND_WAKEUP); |
| 1123 | |
| 1124 | ret = p->hif_func.hif_clear_int_ext(ENABLE_TX_VMM); |
| 1125 | if (!ret) { |
| 1126 | wilc_debug(N_ERR, "[wilc txq]: fail can't start tx VMM ...\n"); |
| 1127 | goto _end_; |
| 1128 | } |
| 1129 | |
| 1130 | /** |
| 1131 | * transfer |
| 1132 | **/ |
| 1133 | ret = p->hif_func.hif_block_tx_ext(0, txb, offset); |
| 1134 | if (!ret) { |
| 1135 | wilc_debug(N_ERR, "[wilc txq]: fail can't block tx ext...\n"); |
| 1136 | goto _end_; |
| 1137 | } |
| 1138 | |
| 1139 | _end_: |
| 1140 | |
| 1141 | release_bus(RELEASE_ALLOW_SLEEP); |
| 1142 | if (ret != 1) |
| 1143 | break; |
| 1144 | } while (0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1145 | /*Added by Amr - BugID_4720*/ |
Greg Kroah-Hartman | 8990d85 | 2015-09-03 20:07:58 -0700 | [diff] [blame] | 1146 | up(p->txq_add_to_head_lock); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1147 | |
| 1148 | p->txq_exit = 1; |
| 1149 | PRINT_D(TX_DBG, "THREAD: Exiting txq\n"); |
| 1150 | /* return tx[]q count */ |
| 1151 | *pu32TxqCount = p->txq_entries; |
| 1152 | return ret; |
| 1153 | } |
| 1154 | |
| 1155 | static void wilc_wlan_handle_rxq(void) |
| 1156 | { |
| 1157 | wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; |
| 1158 | int offset = 0, size, has_packet = 0; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 1159 | u8 *buffer; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1160 | struct rxq_entry_t *rqe; |
| 1161 | |
| 1162 | p->rxq_exit = 0; |
| 1163 | |
| 1164 | |
| 1165 | |
| 1166 | |
| 1167 | do { |
| 1168 | if (p->quit) { |
Chandra S Gorentla | 17aacd4 | 2015-08-08 17:41:35 +0530 | [diff] [blame] | 1169 | PRINT_D(RX_DBG, "exit 1st do-while due to Clean_UP function\n"); |
Greg Kroah-Hartman | 8990d85 | 2015-09-03 20:07:58 -0700 | [diff] [blame] | 1170 | up(p->cfg_wait); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1171 | break; |
| 1172 | } |
| 1173 | rqe = wilc_wlan_rxq_remove(); |
| 1174 | if (rqe == NULL) { |
| 1175 | PRINT_D(RX_DBG, "nothing in the queue - exit 1st do-while\n"); |
| 1176 | break; |
| 1177 | } |
| 1178 | buffer = rqe->buffer; |
| 1179 | size = rqe->buffer_size; |
| 1180 | PRINT_D(RX_DBG, "rxQ entery Size = %d - Address = %p\n", size, buffer); |
| 1181 | offset = 0; |
| 1182 | |
| 1183 | |
| 1184 | |
| 1185 | do { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1186 | u32 header; |
| 1187 | u32 pkt_len, pkt_offset, tp_len; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1188 | int is_cfg_packet; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 1189 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1190 | PRINT_D(RX_DBG, "In the 2nd do-while\n"); |
| 1191 | memcpy(&header, &buffer[offset], 4); |
| 1192 | #ifdef BIG_ENDIAN |
| 1193 | header = BYTE_SWAP(header); |
| 1194 | #endif |
| 1195 | PRINT_D(RX_DBG, "Header = %04x - Offset = %d\n", header, offset); |
| 1196 | |
| 1197 | |
| 1198 | |
| 1199 | is_cfg_packet = (header >> 31) & 0x1; |
| 1200 | pkt_offset = (header >> 22) & 0x1ff; |
| 1201 | tp_len = (header >> 11) & 0x7ff; |
| 1202 | pkt_len = header & 0x7ff; |
| 1203 | |
| 1204 | if (pkt_len == 0 || tp_len == 0) { |
| 1205 | wilc_debug(N_RXQ, "[wilc rxq]: data corrupt, packet len or tp_len is 0 [%d][%d]\n", pkt_len, tp_len); |
| 1206 | break; |
| 1207 | } |
| 1208 | |
| 1209 | /*bug 3887: [AP] Allow Management frames to be passed to the host*/ |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1210 | #define IS_MANAGMEMENT 0x100 |
| 1211 | #define IS_MANAGMEMENT_CALLBACK 0x080 |
| 1212 | #define IS_MGMT_STATUS_SUCCES 0x040 |
| 1213 | |
| 1214 | |
| 1215 | if (pkt_offset & IS_MANAGMEMENT) { |
| 1216 | /* reset mgmt indicator bit, to use pkt_offeset in furthur calculations */ |
| 1217 | pkt_offset &= ~(IS_MANAGMEMENT | IS_MANAGMEMENT_CALLBACK | IS_MGMT_STATUS_SUCCES); |
| 1218 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1219 | WILC_WFI_mgmt_rx(&buffer[offset + HOST_HDR_OFFSET], pkt_len); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1220 | } |
| 1221 | /* BUG4530 fix */ |
| 1222 | else |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1223 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1224 | |
| 1225 | if (!is_cfg_packet) { |
| 1226 | |
| 1227 | if (p->net_func.rx_indicate) { |
| 1228 | if (pkt_len > 0) { |
| 1229 | p->net_func.rx_indicate(&buffer[offset], pkt_len, pkt_offset); |
| 1230 | has_packet = 1; |
| 1231 | } |
| 1232 | } |
| 1233 | } else { |
| 1234 | wilc_cfg_rsp_t rsp; |
| 1235 | |
| 1236 | |
| 1237 | |
| 1238 | p->cif_func.rx_indicate(&buffer[pkt_offset + offset], pkt_len, &rsp); |
| 1239 | if (rsp.type == WILC_CFG_RSP) { |
| 1240 | /** |
| 1241 | * wake up the waiting task... |
| 1242 | **/ |
| 1243 | PRINT_D(RX_DBG, "p->cfg_seq_no = %d - rsp.seq_no = %d\n", p->cfg_seq_no, rsp.seq_no); |
| 1244 | if (p->cfg_seq_no == rsp.seq_no) { |
Greg Kroah-Hartman | 8990d85 | 2015-09-03 20:07:58 -0700 | [diff] [blame] | 1245 | up(p->cfg_wait); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1246 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1247 | } else if (rsp.type == WILC_CFG_RSP_STATUS) { |
| 1248 | /** |
| 1249 | * Call back to indicate status... |
| 1250 | **/ |
| 1251 | if (p->indicate_func.mac_indicate) { |
| 1252 | p->indicate_func.mac_indicate(WILC_MAC_INDICATE_STATUS); |
| 1253 | } |
| 1254 | |
| 1255 | } else if (rsp.type == WILC_CFG_RSP_SCAN) { |
| 1256 | if (p->indicate_func.mac_indicate) |
| 1257 | p->indicate_func.mac_indicate(WILC_MAC_INDICATE_SCAN); |
| 1258 | } |
| 1259 | } |
| 1260 | } |
| 1261 | offset += tp_len; |
| 1262 | if (offset >= size) |
| 1263 | break; |
| 1264 | } while (1); |
| 1265 | |
| 1266 | |
| 1267 | #ifndef MEMORY_STATIC |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 1268 | kfree(buffer); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1269 | #endif |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 1270 | kfree(rqe); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1271 | |
| 1272 | if (has_packet) { |
| 1273 | if (p->net_func.rx_complete) |
| 1274 | p->net_func.rx_complete(); |
| 1275 | } |
| 1276 | } while (1); |
| 1277 | |
| 1278 | p->rxq_exit = 1; |
Chandra S Gorentla | 17aacd4 | 2015-08-08 17:41:35 +0530 | [diff] [blame] | 1279 | PRINT_D(RX_DBG, "THREAD: Exiting RX thread\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | /******************************************** |
| 1283 | * |
| 1284 | * Fast DMA Isr |
| 1285 | * |
| 1286 | ********************************************/ |
| 1287 | static void wilc_unknown_isr_ext(void) |
| 1288 | { |
| 1289 | g_wlan.hif_func.hif_clear_int_ext(0); |
| 1290 | } |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1291 | static void wilc_pllupdate_isr_ext(u32 int_stats) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1292 | { |
| 1293 | |
| 1294 | int trials = 10; |
| 1295 | |
| 1296 | g_wlan.hif_func.hif_clear_int_ext(PLL_INT_CLR); |
| 1297 | |
| 1298 | /* Waiting for PLL */ |
Greg Kroah-Hartman | c2e4c0f | 2015-09-03 19:09:50 -0700 | [diff] [blame] | 1299 | mdelay(WILC_PLL_TO); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1300 | |
| 1301 | /* poll till read a valid data */ |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 1302 | while (!(ISWILC1000(wilc_get_chipid(true)) && --trials)) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1303 | PRINT_D(TX_DBG, "PLL update retrying\n"); |
Greg Kroah-Hartman | c2e4c0f | 2015-09-03 19:09:50 -0700 | [diff] [blame] | 1304 | mdelay(1); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1305 | } |
| 1306 | } |
| 1307 | |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1308 | static void wilc_sleeptimer_isr_ext(u32 int_stats1) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1309 | { |
| 1310 | g_wlan.hif_func.hif_clear_int_ext(SLEEP_INT_CLR); |
| 1311 | #ifndef WILC_OPTIMIZE_SLEEP_INT |
| 1312 | genuChipPSstate = CHIP_SLEEPING_AUTO; |
| 1313 | #endif |
| 1314 | } |
| 1315 | |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1316 | static void wilc_wlan_handle_isr_ext(u32 int_status) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1317 | { |
| 1318 | wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; |
| 1319 | #ifdef MEMORY_STATIC |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1320 | u32 offset = p->rx_buffer_offset; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1321 | #endif |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 1322 | u8 *buffer = NULL; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1323 | u32 size; |
| 1324 | u32 retries = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1325 | int ret = 0; |
| 1326 | struct rxq_entry_t *rqe; |
| 1327 | |
| 1328 | |
| 1329 | /** |
| 1330 | * Get the rx size |
| 1331 | **/ |
| 1332 | |
| 1333 | size = ((int_status & 0x7fff) << 2); |
| 1334 | |
| 1335 | while (!size && retries < 10) { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1336 | u32 time = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1337 | /*looping more secure*/ |
| 1338 | /*zero size make a crashe because the dma will not happen and that will block the firmware*/ |
| 1339 | wilc_debug(N_ERR, "RX Size equal zero ... Trying to read it again for %d time\n", time++); |
| 1340 | p->hif_func.hif_read_size(&size); |
| 1341 | size = ((size & 0x7fff) << 2); |
| 1342 | retries++; |
| 1343 | |
| 1344 | } |
| 1345 | |
| 1346 | if (size > 0) { |
| 1347 | #ifdef MEMORY_STATIC |
| 1348 | if (p->rx_buffer_size - offset < size) |
| 1349 | offset = 0; |
| 1350 | |
| 1351 | if (p->rx_buffer) |
| 1352 | buffer = &p->rx_buffer[offset]; |
| 1353 | else { |
| 1354 | wilc_debug(N_ERR, "[wilc isr]: fail Rx Buffer is NULL...drop the packets (%d)\n", size); |
| 1355 | goto _end_; |
| 1356 | } |
| 1357 | |
| 1358 | #else |
Greg Kroah-Hartman | f019b9d | 2015-09-03 18:50:27 -0700 | [diff] [blame] | 1359 | buffer = kmalloc(size, GFP_KERNEL); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1360 | if (buffer == NULL) { |
| 1361 | wilc_debug(N_ERR, "[wilc isr]: fail alloc host memory...drop the packets (%d)\n", size); |
Greg Kroah-Hartman | 80e29c7 | 2015-08-14 19:42:23 -0700 | [diff] [blame] | 1362 | usleep_range(100 * 1000, 100 * 1000); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1363 | goto _end_; |
| 1364 | } |
| 1365 | #endif |
| 1366 | |
| 1367 | /** |
| 1368 | * clear the chip's interrupt after getting size some register getting corrupted after clear the interrupt |
| 1369 | **/ |
| 1370 | p->hif_func.hif_clear_int_ext(DATA_INT_CLR | ENABLE_RX_VMM); |
| 1371 | |
| 1372 | |
| 1373 | /** |
| 1374 | * start transfer |
| 1375 | **/ |
| 1376 | ret = p->hif_func.hif_block_rx_ext(0, buffer, size); |
| 1377 | |
| 1378 | if (!ret) { |
| 1379 | wilc_debug(N_ERR, "[wilc isr]: fail block rx...\n"); |
| 1380 | goto _end_; |
| 1381 | } |
| 1382 | _end_: |
| 1383 | |
| 1384 | |
| 1385 | if (ret) { |
| 1386 | #ifdef MEMORY_STATIC |
| 1387 | offset += size; |
| 1388 | p->rx_buffer_offset = offset; |
| 1389 | #endif |
| 1390 | /** |
| 1391 | * add to rx queue |
| 1392 | **/ |
Greg Kroah-Hartman | f019b9d | 2015-09-03 18:50:27 -0700 | [diff] [blame] | 1393 | rqe = kmalloc(sizeof(struct rxq_entry_t), GFP_KERNEL); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1394 | if (rqe != NULL) { |
| 1395 | rqe->buffer = buffer; |
| 1396 | rqe->buffer_size = size; |
| 1397 | PRINT_D(RX_DBG, "rxq entery Size= %d - Address = %p\n", rqe->buffer_size, rqe->buffer); |
| 1398 | wilc_wlan_rxq_add(rqe); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1399 | } |
| 1400 | } else { |
| 1401 | #ifndef MEMORY_STATIC |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 1402 | kfree(buffer); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1403 | #endif |
| 1404 | } |
| 1405 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1406 | wilc_wlan_handle_rxq(); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1407 | } |
| 1408 | |
| 1409 | void wilc_handle_isr(void) |
| 1410 | { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1411 | u32 int_status; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1412 | |
| 1413 | acquire_bus(ACQUIRE_AND_WAKEUP); |
| 1414 | g_wlan.hif_func.hif_read_int(&int_status); |
| 1415 | |
| 1416 | if (int_status & PLL_INT_EXT) { |
| 1417 | wilc_pllupdate_isr_ext(int_status); |
| 1418 | } |
| 1419 | if (int_status & DATA_INT_EXT) { |
| 1420 | wilc_wlan_handle_isr_ext(int_status); |
| 1421 | #ifndef WILC_OPTIMIZE_SLEEP_INT |
| 1422 | /* Chip is up and talking*/ |
| 1423 | genuChipPSstate = CHIP_WAKEDUP; |
| 1424 | #endif |
| 1425 | } |
| 1426 | if (int_status & SLEEP_INT_EXT) { |
| 1427 | wilc_sleeptimer_isr_ext(int_status); |
| 1428 | } |
| 1429 | |
| 1430 | if (!(int_status & (ALL_INT_EXT))) { |
| 1431 | #ifdef WILC_SDIO |
| 1432 | PRINT_D(TX_DBG, ">> UNKNOWN_INTERRUPT - 0x%08x\n", int_status); |
| 1433 | #endif |
| 1434 | wilc_unknown_isr_ext(); |
| 1435 | } |
| 1436 | #if ((!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)) |
| 1437 | linux_wlan_enable_irq(); |
| 1438 | #endif |
| 1439 | release_bus(RELEASE_ALLOW_SLEEP); |
| 1440 | } |
| 1441 | |
| 1442 | /******************************************** |
| 1443 | * |
| 1444 | * Firmware download |
| 1445 | * |
| 1446 | ********************************************/ |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1447 | static int wilc_wlan_firmware_download(const u8 *buffer, u32 buffer_size) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1448 | { |
| 1449 | wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1450 | u32 offset; |
| 1451 | u32 addr, size, size2, blksz; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 1452 | u8 *dma_buffer; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1453 | int ret = 0; |
| 1454 | |
| 1455 | blksz = (1ul << 12); /* Bug 4703: 4KB Good enough size for most platforms = PAGE_SIZE. */ |
| 1456 | /* Allocate a DMA coherent buffer. */ |
| 1457 | |
Greg Kroah-Hartman | f019b9d | 2015-09-03 18:50:27 -0700 | [diff] [blame] | 1458 | dma_buffer = kmalloc(blksz, GFP_KERNEL); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1459 | if (dma_buffer == NULL) { |
| 1460 | /*EIO 5*/ |
| 1461 | ret = -5; |
| 1462 | PRINT_ER("Can't allocate buffer for firmware download IO error\n "); |
| 1463 | goto _fail_1; |
| 1464 | } |
| 1465 | |
| 1466 | PRINT_D(INIT_DBG, "Downloading firmware size = %d ...\n", buffer_size); |
| 1467 | /** |
| 1468 | * load the firmware |
| 1469 | **/ |
| 1470 | offset = 0; |
| 1471 | do { |
| 1472 | memcpy(&addr, &buffer[offset], 4); |
| 1473 | memcpy(&size, &buffer[offset + 4], 4); |
| 1474 | #ifdef BIG_ENDIAN |
| 1475 | addr = BYTE_SWAP(addr); |
| 1476 | size = BYTE_SWAP(size); |
| 1477 | #endif |
| 1478 | acquire_bus(ACQUIRE_ONLY); |
| 1479 | offset += 8; |
| 1480 | while (((int)size) && (offset < buffer_size)) { |
Chandra S Gorentla | 78174ad | 2015-08-08 17:41:36 +0530 | [diff] [blame] | 1481 | if (size <= blksz) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1482 | size2 = size; |
Chandra S Gorentla | 78174ad | 2015-08-08 17:41:36 +0530 | [diff] [blame] | 1483 | else |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1484 | size2 = blksz; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1485 | /* Copy firmware into a DMA coherent buffer */ |
| 1486 | memcpy(dma_buffer, &buffer[offset], size2); |
| 1487 | ret = p->hif_func.hif_block_tx(addr, dma_buffer, size2); |
| 1488 | if (!ret) |
| 1489 | break; |
| 1490 | |
| 1491 | addr += size2; |
| 1492 | offset += size2; |
| 1493 | size -= size2; |
| 1494 | } |
| 1495 | release_bus(RELEASE_ONLY); |
| 1496 | |
| 1497 | if (!ret) { |
| 1498 | /*EIO 5*/ |
| 1499 | ret = -5; |
| 1500 | PRINT_ER("Can't download firmware IO error\n "); |
| 1501 | goto _fail_; |
| 1502 | } |
| 1503 | PRINT_D(INIT_DBG, "Offset = %d\n", offset); |
| 1504 | } while (offset < buffer_size); |
| 1505 | |
| 1506 | _fail_: |
| 1507 | |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 1508 | kfree(dma_buffer); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1509 | |
| 1510 | _fail_1: |
| 1511 | |
| 1512 | return (ret < 0) ? ret : 0; |
| 1513 | } |
| 1514 | |
| 1515 | /******************************************** |
| 1516 | * |
| 1517 | * Common |
| 1518 | * |
| 1519 | ********************************************/ |
| 1520 | static int wilc_wlan_start(void) |
| 1521 | { |
| 1522 | wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1523 | u32 reg = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1524 | int ret; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1525 | u32 chipid; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1526 | |
| 1527 | /** |
| 1528 | * Set the host interface |
| 1529 | **/ |
| 1530 | #ifdef OLD_FPGA_BITFILE |
| 1531 | acquire_bus(ACQUIRE_ONLY); |
| 1532 | ret = p->hif_func.hif_read_reg(WILC_VMM_CORE_CTL, ®); |
| 1533 | if (!ret) { |
| 1534 | wilc_debug(N_ERR, "[wilc start]: fail read reg vmm_core_ctl...\n"); |
| 1535 | release_bus(RELEASE_ALLOW_SLEEP); |
| 1536 | return ret; |
| 1537 | } |
| 1538 | reg |= (p->io_func.io_type << 2); |
| 1539 | ret = p->hif_func.hif_write_reg(WILC_VMM_CORE_CTL, reg); |
| 1540 | if (!ret) { |
| 1541 | wilc_debug(N_ERR, "[wilc start]: fail write reg vmm_core_ctl...\n"); |
| 1542 | release_bus(RELEASE_ONLY); |
| 1543 | return ret; |
| 1544 | } |
| 1545 | #else |
| 1546 | if (p->io_func.io_type == HIF_SDIO) { |
| 1547 | reg = 0; |
| 1548 | reg |= (1 << 3); /* bug 4456 and 4557 */ |
| 1549 | } else if (p->io_func.io_type == HIF_SPI) { |
| 1550 | reg = 1; |
| 1551 | } |
| 1552 | acquire_bus(ACQUIRE_ONLY); |
| 1553 | ret = p->hif_func.hif_write_reg(WILC_VMM_CORE_CFG, reg); |
| 1554 | if (!ret) { |
| 1555 | wilc_debug(N_ERR, "[wilc start]: fail write reg vmm_core_cfg...\n"); |
| 1556 | release_bus(RELEASE_ONLY); |
| 1557 | /* EIO 5*/ |
| 1558 | ret = -5; |
| 1559 | return ret; |
| 1560 | } |
| 1561 | reg = 0; |
| 1562 | #ifdef WILC_SDIO_IRQ_GPIO |
| 1563 | reg |= WILC_HAVE_SDIO_IRQ_GPIO; |
| 1564 | #endif |
| 1565 | |
| 1566 | #ifdef WILC_DISABLE_PMU |
| 1567 | #else |
| 1568 | reg |= WILC_HAVE_USE_PMU; |
| 1569 | #endif |
| 1570 | |
| 1571 | #ifdef WILC_SLEEP_CLK_SRC_XO |
| 1572 | reg |= WILC_HAVE_SLEEP_CLK_SRC_XO; |
| 1573 | #elif defined WILC_SLEEP_CLK_SRC_RTC |
| 1574 | reg |= WILC_HAVE_SLEEP_CLK_SRC_RTC; |
| 1575 | #endif |
| 1576 | |
| 1577 | #ifdef WILC_EXT_PA_INV_TX_RX |
| 1578 | reg |= WILC_HAVE_EXT_PA_INV_TX_RX; |
| 1579 | #endif |
| 1580 | |
| 1581 | reg |= WILC_HAVE_LEGACY_RF_SETTINGS; |
| 1582 | |
| 1583 | |
| 1584 | /*BugID_5257*/ |
| 1585 | /*Set oscillator frequency*/ |
| 1586 | #ifdef XTAL_24 |
| 1587 | reg |= WILC_HAVE_XTAL_24; |
| 1588 | #endif |
| 1589 | |
| 1590 | /*BugID_5271*/ |
| 1591 | /*Enable/Disable GPIO configuration for FW logs*/ |
| 1592 | #ifdef DISABLE_WILC_UART |
| 1593 | reg |= WILC_HAVE_DISABLE_WILC_UART; |
| 1594 | #endif |
| 1595 | |
| 1596 | ret = p->hif_func.hif_write_reg(WILC_GP_REG_1, reg); |
| 1597 | if (!ret) { |
| 1598 | wilc_debug(N_ERR, "[wilc start]: fail write WILC_GP_REG_1 ...\n"); |
| 1599 | release_bus(RELEASE_ONLY); |
| 1600 | /* EIO 5*/ |
| 1601 | ret = -5; |
| 1602 | return ret; |
| 1603 | } |
| 1604 | #endif |
| 1605 | |
| 1606 | |
| 1607 | /** |
| 1608 | * Bus related |
| 1609 | **/ |
| 1610 | p->hif_func.hif_sync_ext(NUM_INT_EXT); |
| 1611 | |
| 1612 | ret = p->hif_func.hif_read_reg(0x1000, &chipid); |
| 1613 | if (!ret) { |
| 1614 | wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1000 ...\n"); |
| 1615 | release_bus(RELEASE_ONLY); |
| 1616 | /* EIO 5*/ |
| 1617 | ret = -5; |
| 1618 | return ret; |
| 1619 | } |
| 1620 | |
| 1621 | /** |
| 1622 | * Go... |
| 1623 | **/ |
| 1624 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1625 | |
| 1626 | p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®); |
| 1627 | if ((reg & (1ul << 10)) == (1ul << 10)) { |
| 1628 | reg &= ~(1ul << 10); |
| 1629 | p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); |
| 1630 | p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®); |
| 1631 | } |
| 1632 | |
| 1633 | reg |= (1ul << 10); |
| 1634 | ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); |
| 1635 | p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®); |
| 1636 | release_bus(RELEASE_ONLY); |
| 1637 | |
| 1638 | return (ret < 0) ? ret : 0; |
| 1639 | } |
| 1640 | |
| 1641 | void wilc_wlan_global_reset(void) |
| 1642 | { |
| 1643 | |
| 1644 | wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 1645 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1646 | acquire_bus(ACQUIRE_AND_WAKEUP); |
| 1647 | p->hif_func.hif_write_reg(WILC_GLB_RESET_0, 0x0); |
| 1648 | release_bus(RELEASE_ONLY); |
| 1649 | } |
| 1650 | static int wilc_wlan_stop(void) |
| 1651 | { |
| 1652 | wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1653 | u32 reg = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1654 | int ret; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 1655 | u8 timeout = 10; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1656 | /** |
| 1657 | * TODO: stop the firmware, need a re-download |
| 1658 | **/ |
| 1659 | acquire_bus(ACQUIRE_AND_WAKEUP); |
| 1660 | |
| 1661 | ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®); |
| 1662 | if (!ret) { |
| 1663 | PRINT_ER("Error while reading reg\n"); |
| 1664 | release_bus(RELEASE_ALLOW_SLEEP); |
| 1665 | return ret; |
| 1666 | } |
| 1667 | |
| 1668 | reg &= ~(1 << 10); |
| 1669 | |
| 1670 | |
| 1671 | ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); |
| 1672 | if (!ret) { |
| 1673 | PRINT_ER("Error while writing reg\n"); |
| 1674 | release_bus(RELEASE_ALLOW_SLEEP); |
| 1675 | return ret; |
| 1676 | } |
| 1677 | |
| 1678 | |
| 1679 | |
| 1680 | do { |
| 1681 | ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®); |
| 1682 | if (!ret) { |
| 1683 | PRINT_ER("Error while reading reg\n"); |
| 1684 | release_bus(RELEASE_ALLOW_SLEEP); |
| 1685 | return ret; |
| 1686 | } |
| 1687 | PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout); |
| 1688 | /*Workaround to ensure that the chip is actually reset*/ |
| 1689 | if ((reg & (1 << 10))) { |
| 1690 | PRINT_D(GENERIC_DBG, "Bit 10 not reset : Retry %d\n", timeout); |
| 1691 | reg &= ~(1 << 10); |
| 1692 | ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); |
| 1693 | timeout--; |
| 1694 | } else { |
| 1695 | PRINT_D(GENERIC_DBG, "Bit 10 reset after : Retry %d\n", timeout); |
| 1696 | ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®); |
| 1697 | if (!ret) { |
| 1698 | PRINT_ER("Error while reading reg\n"); |
| 1699 | release_bus(RELEASE_ALLOW_SLEEP); |
| 1700 | return ret; |
| 1701 | } |
| 1702 | PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout); |
| 1703 | break; |
| 1704 | } |
| 1705 | |
| 1706 | } while (timeout); |
| 1707 | #if 1 |
| 1708 | /******************************************************************************/ |
| 1709 | /* This was add at Bug 4595 to reset the chip while maintaining the bus state */ |
| 1710 | /******************************************************************************/ |
| 1711 | reg = ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 8) | (1 << 9) | (1 << 26) | (1 << 29) | (1 << 30) | (1 << 31)); /**/ |
| 1712 | /**/ |
Hari Prasath Gujulan Elango | 369f190 | 2015-06-22 07:04:39 +0000 | [diff] [blame] | 1713 | p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); /**/ |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1714 | reg = ~(1 << 10); /**/ |
| 1715 | /**/ |
| 1716 | ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); /**/ |
| 1717 | /******************************************************************************/ |
| 1718 | #endif |
| 1719 | |
| 1720 | release_bus(RELEASE_ALLOW_SLEEP); |
| 1721 | |
| 1722 | return ret; |
| 1723 | } |
| 1724 | |
| 1725 | static void wilc_wlan_cleanup(void) |
| 1726 | { |
| 1727 | wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; |
| 1728 | struct txq_entry_t *tqe; |
| 1729 | struct rxq_entry_t *rqe; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1730 | u32 reg = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1731 | int ret; |
| 1732 | |
| 1733 | p->quit = 1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1734 | do { |
| 1735 | tqe = wilc_wlan_txq_remove_from_head(); |
| 1736 | if (tqe == NULL) |
| 1737 | break; |
| 1738 | if (tqe->tx_complete_func) |
| 1739 | tqe->tx_complete_func(tqe->priv, 0); |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 1740 | kfree(tqe); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1741 | } while (1); |
| 1742 | |
| 1743 | do { |
| 1744 | rqe = wilc_wlan_rxq_remove(); |
| 1745 | if (rqe == NULL) |
| 1746 | break; |
| 1747 | #ifdef MEMORY_DYNAMIC |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 1748 | kfree(tqe->buffer); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1749 | #endif |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 1750 | kfree(rqe); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1751 | } while (1); |
| 1752 | |
| 1753 | /** |
| 1754 | * clean up buffer |
| 1755 | **/ |
| 1756 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1757 | #ifdef MEMORY_STATIC |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 1758 | kfree(p->rx_buffer); |
| 1759 | p->rx_buffer = NULL; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1760 | #endif |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 1761 | kfree(p->tx_buffer); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1762 | |
| 1763 | acquire_bus(ACQUIRE_AND_WAKEUP); |
| 1764 | |
| 1765 | |
| 1766 | ret = p->hif_func.hif_read_reg(WILC_GP_REG_0, ®); |
| 1767 | if (!ret) { |
| 1768 | PRINT_ER("Error while reading reg\n"); |
| 1769 | release_bus(RELEASE_ALLOW_SLEEP); |
| 1770 | } |
| 1771 | PRINT_ER("Writing ABORT reg\n"); |
| 1772 | ret = p->hif_func.hif_write_reg(WILC_GP_REG_0, (reg | ABORT_INT)); |
| 1773 | if (!ret) { |
| 1774 | PRINT_ER("Error while writing reg\n"); |
| 1775 | release_bus(RELEASE_ALLOW_SLEEP); |
| 1776 | } |
| 1777 | release_bus(RELEASE_ALLOW_SLEEP); |
| 1778 | /** |
| 1779 | * io clean up |
| 1780 | **/ |
| 1781 | p->hif_func.hif_deinit(NULL); |
| 1782 | |
| 1783 | } |
| 1784 | |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1785 | static int wilc_wlan_cfg_commit(int type, u32 drvHandler) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1786 | { |
| 1787 | wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; |
| 1788 | wilc_cfg_frame_t *cfg = &p->cfg_frame; |
| 1789 | int total_len = p->cfg_frame_offset + 4 + DRIVER_HANDLER_SIZE; |
| 1790 | int seq_no = p->cfg_seq_no % 256; |
Chaehyun Lim | 4e4467f | 2015-06-11 14:35:55 +0900 | [diff] [blame] | 1791 | int driver_handler = (u32)drvHandler; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1792 | |
| 1793 | |
| 1794 | /** |
| 1795 | * Set up header |
| 1796 | **/ |
| 1797 | if (type == WILC_CFG_SET) { /* Set */ |
| 1798 | cfg->wid_header[0] = 'W'; |
| 1799 | } else { /* Query */ |
| 1800 | cfg->wid_header[0] = 'Q'; |
| 1801 | } |
| 1802 | cfg->wid_header[1] = seq_no; /* sequence number */ |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 1803 | cfg->wid_header[2] = (u8)total_len; |
| 1804 | cfg->wid_header[3] = (u8)(total_len >> 8); |
| 1805 | cfg->wid_header[4] = (u8)driver_handler; |
| 1806 | cfg->wid_header[5] = (u8)(driver_handler >> 8); |
| 1807 | cfg->wid_header[6] = (u8)(driver_handler >> 16); |
| 1808 | cfg->wid_header[7] = (u8)(driver_handler >> 24); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1809 | p->cfg_seq_no = seq_no; |
| 1810 | |
| 1811 | /** |
| 1812 | * Add to TX queue |
| 1813 | **/ |
| 1814 | |
| 1815 | /*Edited by Amr - BugID_4720*/ |
| 1816 | if (!wilc_wlan_txq_add_cfg_pkt(&cfg->wid_header[0], total_len)) |
| 1817 | return -1; |
| 1818 | |
| 1819 | return 0; |
| 1820 | } |
| 1821 | |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1822 | static int wilc_wlan_cfg_set(int start, u32 wid, u8 *buffer, u32 buffer_size, int commit, u32 drvHandler) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1823 | { |
| 1824 | wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1825 | u32 offset; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1826 | int ret_size; |
| 1827 | |
| 1828 | |
| 1829 | if (p->cfg_frame_in_use) |
| 1830 | return 0; |
| 1831 | |
| 1832 | if (start) |
| 1833 | p->cfg_frame_offset = 0; |
| 1834 | |
| 1835 | offset = p->cfg_frame_offset; |
Chaehyun Lim | ec53adf | 2015-09-15 14:06:15 +0900 | [diff] [blame] | 1836 | ret_size = p->cif_func.cfg_wid_set(p->cfg_frame.frame, offset, (u16)wid, buffer, buffer_size); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1837 | offset += ret_size; |
| 1838 | p->cfg_frame_offset = offset; |
| 1839 | |
| 1840 | if (commit) { |
| 1841 | PRINT_D(TX_DBG, "[WILC]PACKET Commit with sequence number %d\n", p->cfg_seq_no); |
| 1842 | PRINT_D(RX_DBG, "Processing cfg_set()\n"); |
| 1843 | p->cfg_frame_in_use = 1; |
| 1844 | |
| 1845 | /*Edited by Amr - BugID_4720*/ |
| 1846 | if (wilc_wlan_cfg_commit(WILC_CFG_SET, drvHandler)) |
| 1847 | ret_size = 0; /* BugID_5213 */ |
| 1848 | |
| 1849 | if (p->os_func.os_wait(p->cfg_wait, CFG_PKTS_TIMEOUT)) { |
| 1850 | PRINT_D(TX_DBG, "Set Timed Out\n"); |
| 1851 | ret_size = 0; |
| 1852 | } |
| 1853 | p->cfg_frame_in_use = 0; |
| 1854 | p->cfg_frame_offset = 0; |
| 1855 | p->cfg_seq_no += 1; |
| 1856 | |
| 1857 | } |
| 1858 | |
| 1859 | return ret_size; |
| 1860 | } |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1861 | static int wilc_wlan_cfg_get(int start, u32 wid, int commit, u32 drvHandler) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1862 | { |
| 1863 | wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1864 | u32 offset; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1865 | int ret_size; |
| 1866 | |
| 1867 | |
| 1868 | if (p->cfg_frame_in_use) |
| 1869 | return 0; |
| 1870 | |
| 1871 | if (start) |
| 1872 | p->cfg_frame_offset = 0; |
| 1873 | |
| 1874 | offset = p->cfg_frame_offset; |
Chaehyun Lim | ec53adf | 2015-09-15 14:06:15 +0900 | [diff] [blame] | 1875 | ret_size = p->cif_func.cfg_wid_get(p->cfg_frame.frame, offset, (u16)wid); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1876 | offset += ret_size; |
| 1877 | p->cfg_frame_offset = offset; |
| 1878 | |
| 1879 | if (commit) { |
| 1880 | p->cfg_frame_in_use = 1; |
| 1881 | |
| 1882 | /*Edited by Amr - BugID_4720*/ |
| 1883 | if (wilc_wlan_cfg_commit(WILC_CFG_QUERY, drvHandler)) |
| 1884 | ret_size = 0; /* BugID_5213 */ |
| 1885 | |
| 1886 | |
| 1887 | if (p->os_func.os_wait(p->cfg_wait, CFG_PKTS_TIMEOUT)) { |
| 1888 | PRINT_D(TX_DBG, "Get Timed Out\n"); |
| 1889 | ret_size = 0; |
| 1890 | } |
| 1891 | PRINT_D(GENERIC_DBG, "[WILC]Get Response received\n"); |
| 1892 | p->cfg_frame_in_use = 0; |
| 1893 | p->cfg_frame_offset = 0; |
| 1894 | p->cfg_seq_no += 1; |
| 1895 | } |
| 1896 | |
| 1897 | return ret_size; |
| 1898 | } |
| 1899 | |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1900 | static int wilc_wlan_cfg_get_val(u32 wid, u8 *buffer, u32 buffer_size) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1901 | { |
| 1902 | wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; |
| 1903 | int ret; |
| 1904 | |
Chaehyun Lim | ec53adf | 2015-09-15 14:06:15 +0900 | [diff] [blame] | 1905 | ret = p->cif_func.cfg_wid_get_val((u16)wid, buffer, buffer_size); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1906 | |
| 1907 | return ret; |
| 1908 | } |
| 1909 | |
| 1910 | void wilc_bus_set_max_speed(void) |
| 1911 | { |
| 1912 | |
| 1913 | /* Increase bus speed to max possible. */ |
| 1914 | g_wlan.hif_func.hif_set_max_bus_speed(); |
| 1915 | } |
| 1916 | |
| 1917 | void wilc_bus_set_default_speed(void) |
| 1918 | { |
| 1919 | |
| 1920 | /* Restore bus speed to default. */ |
| 1921 | g_wlan.hif_func.hif_set_default_bus_speed(); |
| 1922 | } |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1923 | u32 init_chip(void) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1924 | { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1925 | u32 chipid; |
| 1926 | u32 reg, ret = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1927 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1928 | acquire_bus(ACQUIRE_ONLY); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1929 | |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 1930 | chipid = wilc_get_chipid(true); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1931 | |
| 1932 | |
| 1933 | |
| 1934 | if ((chipid & 0xfff) != 0xa0) { |
| 1935 | /** |
| 1936 | * Avoid booting from boot ROM. Make sure that Drive IRQN [SDIO platform] |
| 1937 | * or SD_DAT3 [SPI platform] to ?1? |
| 1938 | **/ |
| 1939 | /* Set cortus reset register to register control. */ |
| 1940 | ret = g_wlan.hif_func.hif_read_reg(0x1118, ®); |
| 1941 | if (!ret) { |
| 1942 | wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1118 ...\n"); |
| 1943 | return ret; |
| 1944 | } |
| 1945 | reg |= (1 << 0); |
| 1946 | ret = g_wlan.hif_func.hif_write_reg(0x1118, reg); |
| 1947 | if (!ret) { |
| 1948 | wilc_debug(N_ERR, "[wilc start]: fail write reg 0x1118 ...\n"); |
| 1949 | return ret; |
| 1950 | } |
| 1951 | /** |
| 1952 | * Write branch intruction to IRAM (0x71 trap) at location 0xFFFF0000 |
| 1953 | * (Cortus map) or C0000 (AHB map). |
| 1954 | **/ |
| 1955 | ret = g_wlan.hif_func.hif_write_reg(0xc0000, 0x71); |
| 1956 | if (!ret) { |
| 1957 | wilc_debug(N_ERR, "[wilc start]: fail write reg 0xc0000 ...\n"); |
| 1958 | return ret; |
| 1959 | } |
| 1960 | } |
| 1961 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1962 | release_bus(RELEASE_ONLY); |
| 1963 | |
| 1964 | return ret; |
| 1965 | |
| 1966 | } |
| 1967 | |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1968 | u32 wilc_get_chipid(u8 update) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1969 | { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1970 | static u32 chipid; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1971 | /* SDIO can't read into global variables */ |
| 1972 | /* Use this variable as a temp, then copy to the global */ |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1973 | u32 tempchipid = 0; |
| 1974 | u32 rfrevid; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1975 | |
| 1976 | if (chipid == 0 || update != 0) { |
| 1977 | g_wlan.hif_func.hif_read_reg(0x1000, &tempchipid); |
| 1978 | g_wlan.hif_func.hif_read_reg(0x13f4, &rfrevid); |
| 1979 | if (!ISWILC1000(tempchipid)) { |
| 1980 | chipid = 0; |
| 1981 | goto _fail_; |
| 1982 | } |
| 1983 | if (tempchipid == 0x1002a0) { |
| 1984 | if (rfrevid == 0x1) { /* 1002A0 */ |
| 1985 | } else { /* if (rfrevid == 0x2) */ /* 1002A1 */ |
| 1986 | tempchipid = 0x1002a1; |
| 1987 | } |
| 1988 | } else if (tempchipid == 0x1002b0) { |
| 1989 | if (rfrevid == 3) { /* 1002B0 */ |
| 1990 | } else if (rfrevid == 4) { /* 1002B1 */ |
| 1991 | tempchipid = 0x1002b1; |
| 1992 | } else { /* if(rfrevid == 5) */ /* 1002B2 */ |
| 1993 | tempchipid = 0x1002b2; |
| 1994 | } |
| 1995 | } else { |
| 1996 | } |
| 1997 | |
| 1998 | chipid = tempchipid; |
| 1999 | } |
| 2000 | _fail_: |
| 2001 | return chipid; |
| 2002 | } |
| 2003 | |
| 2004 | #ifdef COMPLEMENT_BOOT |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 2005 | u8 core_11b_ready(void) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 2006 | { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 2007 | u32 reg_val; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 2008 | |
| 2009 | acquire_bus(ACQUIRE_ONLY); |
| 2010 | g_wlan.hif_func.hif_write_reg(0x16082c, 1); |
| 2011 | g_wlan.hif_func.hif_write_reg(0x161600, 0x90); |
| 2012 | g_wlan.hif_func.hif_read_reg(0x161600, ®_val); |
| 2013 | release_bus(RELEASE_ONLY); |
| 2014 | |
| 2015 | if (reg_val == 0x90) |
| 2016 | return 0; |
| 2017 | else |
| 2018 | return 1; |
| 2019 | } |
| 2020 | #endif |
| 2021 | |
| 2022 | int wilc_wlan_init(wilc_wlan_inp_t *inp, wilc_wlan_oup_t *oup) |
| 2023 | { |
| 2024 | |
| 2025 | int ret = 0; |
| 2026 | |
| 2027 | PRINT_D(INIT_DBG, "Initializing WILC_Wlan ...\n"); |
| 2028 | |
| 2029 | memset((void *)&g_wlan, 0, sizeof(wilc_wlan_dev_t)); |
| 2030 | |
| 2031 | /** |
| 2032 | * store the input |
| 2033 | **/ |
| 2034 | memcpy((void *)&g_wlan.os_func, (void *)&inp->os_func, sizeof(wilc_wlan_os_func_t)); |
| 2035 | memcpy((void *)&g_wlan.io_func, (void *)&inp->io_func, sizeof(wilc_wlan_io_func_t)); |
| 2036 | memcpy((void *)&g_wlan.net_func, (void *)&inp->net_func, sizeof(wilc_wlan_net_func_t)); |
| 2037 | memcpy((void *)&g_wlan.indicate_func, (void *)&inp->indicate_func, sizeof(wilc_wlan_net_func_t)); |
| 2038 | g_wlan.hif_lock = inp->os_context.hif_critical_section; |
| 2039 | g_wlan.txq_lock = inp->os_context.txq_critical_section; |
| 2040 | |
| 2041 | /*Added by Amr - BugID_4720*/ |
| 2042 | g_wlan.txq_add_to_head_lock = inp->os_context.txq_add_to_head_critical_section; |
| 2043 | |
| 2044 | /*Added by Amr - BugID_4720*/ |
| 2045 | g_wlan.txq_spinlock = inp->os_context.txq_spin_lock; |
| 2046 | |
| 2047 | g_wlan.rxq_lock = inp->os_context.rxq_critical_section; |
| 2048 | g_wlan.txq_wait = inp->os_context.txq_wait_event; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 2049 | g_wlan.cfg_wait = inp->os_context.cfg_wait_event; |
| 2050 | g_wlan.tx_buffer_size = inp->os_context.tx_buffer_size; |
| 2051 | #if defined (MEMORY_STATIC) |
| 2052 | g_wlan.rx_buffer_size = inp->os_context.rx_buffer_size; |
| 2053 | #endif |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 2054 | /*** |
| 2055 | * host interface init |
| 2056 | **/ |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 2057 | if ((inp->io_func.io_type & 0x1) == HIF_SDIO) { |
| 2058 | if (!hif_sdio.hif_init(inp, wilc_debug)) { |
| 2059 | /* EIO 5 */ |
| 2060 | ret = -5; |
| 2061 | goto _fail_; |
| 2062 | } |
| 2063 | memcpy((void *)&g_wlan.hif_func, &hif_sdio, sizeof(wilc_hif_func_t)); |
| 2064 | } else { |
| 2065 | if ((inp->io_func.io_type & 0x1) == HIF_SPI) { |
| 2066 | /** |
| 2067 | * TODO: |
| 2068 | **/ |
| 2069 | if (!hif_spi.hif_init(inp, wilc_debug)) { |
| 2070 | /* EIO 5 */ |
| 2071 | ret = -5; |
| 2072 | goto _fail_; |
| 2073 | } |
| 2074 | memcpy((void *)&g_wlan.hif_func, &hif_spi, sizeof(wilc_hif_func_t)); |
| 2075 | } else { |
| 2076 | /* EIO 5 */ |
| 2077 | ret = -5; |
| 2078 | goto _fail_; |
| 2079 | } |
| 2080 | } |
| 2081 | |
| 2082 | /*** |
| 2083 | * mac interface init |
| 2084 | **/ |
| 2085 | if (!mac_cfg.cfg_init(wilc_debug)) { |
| 2086 | /* ENOBUFS 105 */ |
| 2087 | ret = -105; |
| 2088 | goto _fail_; |
| 2089 | } |
| 2090 | memcpy((void *)&g_wlan.cif_func, &mac_cfg, sizeof(wilc_cfg_func_t)); |
| 2091 | |
| 2092 | |
| 2093 | /** |
| 2094 | * alloc tx, rx buffer |
| 2095 | **/ |
Greg Kroah-Hartman | b1413b6 | 2015-06-02 14:11:12 +0900 | [diff] [blame] | 2096 | if (g_wlan.tx_buffer == NULL) |
Greg Kroah-Hartman | f019b9d | 2015-09-03 18:50:27 -0700 | [diff] [blame] | 2097 | g_wlan.tx_buffer = kmalloc(g_wlan.tx_buffer_size, GFP_KERNEL); |
Arnd Bergmann | 7a8fd84 | 2015-06-01 21:06:45 +0200 | [diff] [blame] | 2098 | PRINT_D(TX_DBG, "g_wlan.tx_buffer = %p\n", g_wlan.tx_buffer); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 2099 | |
Greg Kroah-Hartman | b1413b6 | 2015-06-02 14:11:12 +0900 | [diff] [blame] | 2100 | if (g_wlan.tx_buffer == NULL) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 2101 | /* ENOBUFS 105 */ |
| 2102 | ret = -105; |
| 2103 | PRINT_ER("Can't allocate Tx Buffer"); |
| 2104 | goto _fail_; |
| 2105 | } |
| 2106 | |
| 2107 | /* rx_buffer is not used unless we activate USE_MEM STATIC which is not applicable, allocating such memory is useless*/ |
| 2108 | #if defined (MEMORY_STATIC) |
Greg Kroah-Hartman | b1413b6 | 2015-06-02 14:11:12 +0900 | [diff] [blame] | 2109 | if (g_wlan.rx_buffer == NULL) |
Greg Kroah-Hartman | f019b9d | 2015-09-03 18:50:27 -0700 | [diff] [blame] | 2110 | g_wlan.rx_buffer = kmalloc(g_wlan.rx_buffer_size, GFP_KERNEL); |
Arnd Bergmann | 7a8fd84 | 2015-06-01 21:06:45 +0200 | [diff] [blame] | 2111 | PRINT_D(TX_DBG, "g_wlan.rx_buffer =%p\n", g_wlan.rx_buffer); |
Greg Kroah-Hartman | b1413b6 | 2015-06-02 14:11:12 +0900 | [diff] [blame] | 2112 | if (g_wlan.rx_buffer == NULL) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 2113 | /* ENOBUFS 105 */ |
| 2114 | ret = -105; |
| 2115 | PRINT_ER("Can't allocate Rx Buffer"); |
| 2116 | goto _fail_; |
| 2117 | } |
| 2118 | #endif |
| 2119 | |
| 2120 | /** |
| 2121 | * export functions |
| 2122 | **/ |
| 2123 | oup->wlan_firmware_download = wilc_wlan_firmware_download; |
| 2124 | oup->wlan_start = wilc_wlan_start; |
| 2125 | oup->wlan_stop = wilc_wlan_stop; |
| 2126 | oup->wlan_add_to_tx_que = wilc_wlan_txq_add_net_pkt; |
| 2127 | oup->wlan_handle_tx_que = wilc_wlan_handle_txq; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 2128 | oup->wlan_handle_rx_isr = wilc_handle_isr; |
| 2129 | oup->wlan_cleanup = wilc_wlan_cleanup; |
| 2130 | oup->wlan_cfg_set = wilc_wlan_cfg_set; |
| 2131 | oup->wlan_cfg_get = wilc_wlan_cfg_get; |
| 2132 | oup->wlan_cfg_get_value = wilc_wlan_cfg_get_val; |
| 2133 | |
| 2134 | /*Bug3959: transmitting mgmt frames received from host*/ |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 2135 | oup->wlan_add_mgmt_to_tx_que = wilc_wlan_txq_add_mgmt_pkt; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 2136 | |
| 2137 | if (!init_chip()) { |
| 2138 | /* EIO 5 */ |
| 2139 | ret = -5; |
| 2140 | goto _fail_; |
| 2141 | } |
| 2142 | #ifdef TCP_ACK_FILTER |
| 2143 | Init_TCP_tracking(); |
| 2144 | #endif |
| 2145 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 2146 | return 1; |
| 2147 | |
| 2148 | _fail_: |
| 2149 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 2150 | #ifdef MEMORY_STATIC |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 2151 | kfree(g_wlan.rx_buffer); |
| 2152 | g_wlan.rx_buffer = NULL; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 2153 | #endif |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 2154 | kfree(g_wlan.tx_buffer); |
| 2155 | g_wlan.tx_buffer = NULL; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 2156 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 2157 | return ret; |
| 2158 | |
| 2159 | } |
| 2160 | |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 2161 | u16 Set_machw_change_vir_if(bool bValue) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 2162 | { |
Chaehyun Lim | d85f532 | 2015-06-11 14:35:54 +0900 | [diff] [blame] | 2163 | u16 ret; |
Chaehyun Lim | 4e4467f | 2015-06-11 14:35:55 +0900 | [diff] [blame] | 2164 | u32 reg; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 2165 | |
| 2166 | /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/ |
Greg Kroah-Hartman | 5e150b5 | 2015-09-03 19:32:11 -0700 | [diff] [blame] | 2167 | mutex_lock((&g_wlan)->hif_lock); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 2168 | ret = (&g_wlan)->hif_func.hif_read_reg(WILC_CHANGING_VIR_IF, ®); |
| 2169 | if (!ret) { |
| 2170 | PRINT_ER("Error while Reading reg WILC_CHANGING_VIR_IF\n"); |
| 2171 | } |
| 2172 | |
Chandra S Gorentla | 78174ad | 2015-08-08 17:41:36 +0530 | [diff] [blame] | 2173 | if (bValue) |
Chaehyun Lim | 50b51da | 2015-09-16 20:11:26 +0900 | [diff] [blame] | 2174 | reg |= BIT(31); |
Chandra S Gorentla | 78174ad | 2015-08-08 17:41:36 +0530 | [diff] [blame] | 2175 | else |
Chaehyun Lim | 50b51da | 2015-09-16 20:11:26 +0900 | [diff] [blame] | 2176 | reg &= ~BIT(31); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 2177 | |
| 2178 | ret = (&g_wlan)->hif_func.hif_write_reg(WILC_CHANGING_VIR_IF, reg); |
| 2179 | |
| 2180 | if (!ret) { |
| 2181 | PRINT_ER("Error while writing reg WILC_CHANGING_VIR_IF\n"); |
| 2182 | } |
Greg Kroah-Hartman | 5e150b5 | 2015-09-03 19:32:11 -0700 | [diff] [blame] | 2183 | mutex_unlock((&g_wlan)->hif_lock); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 2184 | |
| 2185 | return ret; |
| 2186 | } |