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