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