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