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