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