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