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