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