Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1 | #include "wilc_wlan_if.h" |
Tony Cho | 60bd100 | 2015-10-12 16:56:04 +0900 | [diff] [blame] | 2 | #include "wilc_wfi_netdevice.h" |
Glen Lee | 17e8f16 | 2015-10-02 14:22:07 +0900 | [diff] [blame] | 3 | #include "wilc_wlan_cfg.h" |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 4 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 5 | extern wilc_hif_func_t hif_sdio; |
| 6 | extern wilc_hif_func_t hif_spi; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 7 | u32 wilc_get_chipid(u8 update); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 8 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 9 | typedef struct { |
| 10 | int quit; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 11 | wilc_wlan_io_func_t io_func; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 12 | wilc_hif_func_t hif_func; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 13 | int cfg_frame_in_use; |
| 14 | wilc_cfg_frame_t cfg_frame; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 15 | u32 cfg_frame_offset; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 16 | int cfg_seq_no; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 17 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 18 | #ifdef MEMORY_STATIC |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 19 | u8 *rx_buffer; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 20 | u32 rx_buffer_offset; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 21 | #endif |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 22 | u8 *tx_buffer; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 23 | u32 tx_buffer_offset; |
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 | unsigned long txq_spinlock_flags; |
| 26 | |
| 27 | struct txq_entry_t *txq_head; |
| 28 | struct txq_entry_t *txq_tail; |
| 29 | int txq_entries; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 30 | int txq_exit; |
| 31 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 32 | struct rxq_entry_t *rxq_head; |
| 33 | struct rxq_entry_t *rxq_tail; |
| 34 | int rxq_entries; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 35 | int rxq_exit; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 36 | } wilc_wlan_dev_t; |
| 37 | |
| 38 | static wilc_wlan_dev_t g_wlan; |
| 39 | |
Chaehyun Lim | 9af382b | 2015-09-16 20:11:27 +0900 | [diff] [blame] | 40 | static inline void chip_allow_sleep(void); |
| 41 | static inline void chip_wakeup(void); |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 42 | 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] | 43 | |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 44 | static void wilc_debug(u32 flag, char *fmt, ...) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 45 | { |
| 46 | char buf[256]; |
| 47 | va_list args; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 48 | |
| 49 | if (flag & dbgflag) { |
| 50 | va_start(args, fmt); |
Hari Prasath Gujulan Elango | 8105322 | 2015-06-22 13:13:58 +0000 | [diff] [blame] | 51 | vsprintf(buf, fmt, args); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 52 | va_end(args); |
| 53 | |
Glen Lee | ef2b784 | 2015-09-24 18:14:55 +0900 | [diff] [blame] | 54 | linux_wlan_dbg(buf); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 55 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 56 | } |
| 57 | |
Leo Kim | b7d1e18 | 2015-11-06 11:12:30 +0900 | [diff] [blame] | 58 | static CHIP_PS_STATE_T chip_ps_state = CHIP_WAKEDUP; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 59 | |
Chaehyun Lim | 9af382b | 2015-09-16 20:11:27 +0900 | [diff] [blame] | 60 | static inline void acquire_bus(BUS_ACQUIRE_T acquire) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 61 | { |
Glen Lee | 187f1ef | 2015-09-24 18:15:01 +0900 | [diff] [blame] | 62 | mutex_lock(&g_linux_wlan->hif_cs); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 63 | #ifndef WILC_OPTIMIZE_SLEEP_INT |
Leo Kim | b7d1e18 | 2015-11-06 11:12:30 +0900 | [diff] [blame] | 64 | if (chip_ps_state != CHIP_WAKEDUP) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 65 | #endif |
| 66 | { |
| 67 | if (acquire == ACQUIRE_AND_WAKEUP) |
| 68 | chip_wakeup(); |
| 69 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 70 | } |
Leo Kim | 2d6973e | 2015-11-06 11:12:28 +0900 | [diff] [blame] | 71 | |
Chaehyun Lim | 9af382b | 2015-09-16 20:11:27 +0900 | [diff] [blame] | 72 | static inline void release_bus(BUS_RELEASE_T release) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 73 | { |
| 74 | #ifdef WILC_OPTIMIZE_SLEEP_INT |
| 75 | if (release == RELEASE_ALLOW_SLEEP) |
| 76 | chip_allow_sleep(); |
| 77 | #endif |
Glen Lee | 187f1ef | 2015-09-24 18:15:01 +0900 | [diff] [blame] | 78 | mutex_unlock(&g_linux_wlan->hif_cs); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 79 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 80 | |
| 81 | static void wilc_wlan_txq_remove(struct txq_entry_t *tqe) |
| 82 | { |
Shivani Bhardwaj | 7ee8291 | 2015-10-13 17:04:48 +0530 | [diff] [blame] | 83 | wilc_wlan_dev_t *p = &g_wlan; |
Leo Kim | 8739eeb | 2015-11-06 11:12:29 +0900 | [diff] [blame] | 84 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 85 | if (tqe == p->txq_head) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 86 | p->txq_head = tqe->next; |
| 87 | if (p->txq_head) |
| 88 | p->txq_head->prev = NULL; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 89 | } else if (tqe == p->txq_tail) { |
| 90 | p->txq_tail = (tqe->prev); |
| 91 | if (p->txq_tail) |
| 92 | p->txq_tail->next = NULL; |
| 93 | } else { |
| 94 | tqe->prev->next = tqe->next; |
| 95 | tqe->next->prev = tqe->prev; |
| 96 | } |
| 97 | p->txq_entries -= 1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 98 | } |
| 99 | |
Glen Lee | 718fc2c | 2015-10-29 12:18:43 +0900 | [diff] [blame] | 100 | static struct txq_entry_t * |
| 101 | wilc_wlan_txq_remove_from_head(struct net_device *dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 102 | { |
| 103 | struct txq_entry_t *tqe; |
Shivani Bhardwaj | 7ee8291 | 2015-10-13 17:04:48 +0530 | [diff] [blame] | 104 | wilc_wlan_dev_t *p = &g_wlan; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 105 | unsigned long flags; |
Glen Lee | 718fc2c | 2015-10-29 12:18:43 +0900 | [diff] [blame] | 106 | perInterface_wlan_t *nic; |
| 107 | struct wilc *wilc; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 108 | |
Glen Lee | 718fc2c | 2015-10-29 12:18:43 +0900 | [diff] [blame] | 109 | nic = netdev_priv(dev); |
| 110 | wilc = nic->wilc; |
| 111 | |
| 112 | spin_lock_irqsave(&wilc->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 113 | if (p->txq_head) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 114 | tqe = p->txq_head; |
| 115 | p->txq_head = tqe->next; |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 116 | if (p->txq_head) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 117 | p->txq_head->prev = NULL; |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 118 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 119 | p->txq_entries -= 1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 120 | } else { |
| 121 | tqe = NULL; |
| 122 | } |
Glen Lee | 718fc2c | 2015-10-29 12:18:43 +0900 | [diff] [blame] | 123 | spin_unlock_irqrestore(&wilc->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 124 | return tqe; |
| 125 | } |
| 126 | |
Glen Lee | 32f0332 | 2015-10-29 12:18:45 +0900 | [diff] [blame] | 127 | static void wilc_wlan_txq_add_to_tail(struct net_device *dev, |
| 128 | struct txq_entry_t *tqe) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 129 | { |
Shivani Bhardwaj | 7ee8291 | 2015-10-13 17:04:48 +0530 | [diff] [blame] | 130 | wilc_wlan_dev_t *p = &g_wlan; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 131 | unsigned long flags; |
Glen Lee | 32f0332 | 2015-10-29 12:18:45 +0900 | [diff] [blame] | 132 | perInterface_wlan_t *nic; |
| 133 | struct wilc *wilc; |
| 134 | |
| 135 | nic = netdev_priv(dev); |
| 136 | wilc = nic->wilc; |
| 137 | |
| 138 | spin_lock_irqsave(&wilc->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 139 | |
Leo Kim | a4b1719 | 2015-11-06 11:12:31 +0900 | [diff] [blame] | 140 | if (!p->txq_head) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 141 | tqe->next = NULL; |
| 142 | tqe->prev = NULL; |
| 143 | p->txq_head = tqe; |
| 144 | p->txq_tail = tqe; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 145 | } else { |
| 146 | tqe->next = NULL; |
| 147 | tqe->prev = p->txq_tail; |
| 148 | p->txq_tail->next = tqe; |
| 149 | p->txq_tail = tqe; |
| 150 | } |
| 151 | p->txq_entries += 1; |
| 152 | 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] | 153 | |
Glen Lee | 32f0332 | 2015-10-29 12:18:45 +0900 | [diff] [blame] | 154 | spin_unlock_irqrestore(&wilc->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 155 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 156 | PRINT_D(TX_DBG, "Wake the txq_handling\n"); |
| 157 | |
Glen Lee | 32f0332 | 2015-10-29 12:18:45 +0900 | [diff] [blame] | 158 | up(&wilc->txq_event); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | static int wilc_wlan_txq_add_to_head(struct txq_entry_t *tqe) |
| 162 | { |
Shivani Bhardwaj | 7ee8291 | 2015-10-13 17:04:48 +0530 | [diff] [blame] | 163 | wilc_wlan_dev_t *p = &g_wlan; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 164 | unsigned long flags; |
Glen Lee | b002e20 | 2015-09-24 18:15:05 +0900 | [diff] [blame] | 165 | if (linux_wlan_lock_timeout(&g_linux_wlan->txq_add_to_head_cs, |
| 166 | CFG_PKTS_TIMEOUT)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 167 | return -1; |
| 168 | |
Glen Lee | 85e5756 | 2015-09-24 18:14:56 +0900 | [diff] [blame] | 169 | spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 170 | |
Leo Kim | a4b1719 | 2015-11-06 11:12:31 +0900 | [diff] [blame] | 171 | if (!p->txq_head) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 172 | tqe->next = NULL; |
| 173 | tqe->prev = NULL; |
| 174 | p->txq_head = tqe; |
| 175 | p->txq_tail = tqe; |
| 176 | } else { |
| 177 | tqe->next = p->txq_head; |
| 178 | tqe->prev = NULL; |
| 179 | p->txq_head->prev = tqe; |
| 180 | p->txq_head = tqe; |
| 181 | } |
| 182 | p->txq_entries += 1; |
| 183 | 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] | 184 | |
Glen Lee | 85e5756 | 2015-09-24 18:14:56 +0900 | [diff] [blame] | 185 | spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags); |
Glen Lee | d5a63a8 | 2015-09-24 18:15:00 +0900 | [diff] [blame] | 186 | up(&g_linux_wlan->txq_add_to_head_cs); |
Glen Lee | 5cd6363 | 2015-09-24 18:14:58 +0900 | [diff] [blame] | 187 | up(&g_linux_wlan->txq_event); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 188 | PRINT_D(TX_DBG, "Wake up the txq_handler\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 189 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 190 | return 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 191 | } |
| 192 | |
Leo Kim | eb59da3 | 2015-11-06 11:12:33 +0900 | [diff] [blame^] | 193 | u32 total_acks = 0, dropped_acks = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 194 | |
| 195 | #ifdef TCP_ACK_FILTER |
| 196 | struct Ack_session_info; |
Shraddha Barke | eeb1c06 | 2015-08-05 01:29:22 +0530 | [diff] [blame] | 197 | struct Ack_session_info { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 198 | u32 Ack_seq_num; |
| 199 | u32 Bigger_Ack_num; |
Chaehyun Lim | ec53adf | 2015-09-15 14:06:15 +0900 | [diff] [blame] | 200 | u16 src_port; |
| 201 | u16 dst_port; |
| 202 | u16 status; |
Shraddha Barke | eeb1c06 | 2015-08-05 01:29:22 +0530 | [diff] [blame] | 203 | }; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 204 | |
| 205 | typedef struct { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 206 | u32 ack_num; |
| 207 | u32 Session_index; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 208 | struct txq_entry_t *txqe; |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 209 | } Pending_Acks_info_t; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 210 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 211 | struct Ack_session_info *Free_head; |
| 212 | struct Ack_session_info *Alloc_head; |
| 213 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 214 | #define NOT_TCP_ACK (-1) |
| 215 | |
| 216 | #define MAX_TCP_SESSION 25 |
| 217 | #define MAX_PENDING_ACKS 256 |
Shraddha Barke | eeb1c06 | 2015-08-05 01:29:22 +0530 | [diff] [blame] | 218 | struct Ack_session_info Acks_keep_track_info[2 * MAX_TCP_SESSION]; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 219 | Pending_Acks_info_t Pending_Acks_info[MAX_PENDING_ACKS]; |
| 220 | |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 221 | u32 PendingAcks_arrBase; |
| 222 | u32 Opened_TCP_session; |
| 223 | u32 Pending_Acks; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 224 | |
Chaehyun Lim | fed16f2 | 2015-09-17 16:48:43 +0900 | [diff] [blame] | 225 | static inline int Init_TCP_tracking(void) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 226 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 227 | return 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 228 | } |
Leo Kim | 2d6973e | 2015-11-06 11:12:28 +0900 | [diff] [blame] | 229 | |
Chaehyun Lim | fed16f2 | 2015-09-17 16:48:43 +0900 | [diff] [blame] | 230 | 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] | 231 | { |
| 232 | Acks_keep_track_info[Opened_TCP_session].Ack_seq_num = seq; |
| 233 | Acks_keep_track_info[Opened_TCP_session].Bigger_Ack_num = 0; |
| 234 | Acks_keep_track_info[Opened_TCP_session].src_port = src_prt; |
| 235 | Acks_keep_track_info[Opened_TCP_session].dst_port = dst_prt; |
| 236 | Opened_TCP_session++; |
| 237 | |
| 238 | PRINT_D(TCP_ENH, "TCP Session %d to Ack %d\n", Opened_TCP_session, seq); |
| 239 | return 0; |
| 240 | } |
| 241 | |
Chaehyun Lim | fed16f2 | 2015-09-17 16:48:43 +0900 | [diff] [blame] | 242 | static inline int Update_TCP_track_session(u32 index, u32 Ack) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 243 | { |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 244 | if (Ack > Acks_keep_track_info[index].Bigger_Ack_num) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 245 | Acks_keep_track_info[index].Bigger_Ack_num = Ack; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 246 | return 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 247 | } |
Leo Kim | 2d6973e | 2015-11-06 11:12:28 +0900 | [diff] [blame] | 248 | |
Chaehyun Lim | fed16f2 | 2015-09-17 16:48:43 +0900 | [diff] [blame] | 249 | 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] | 250 | { |
Leo Kim | 821466d | 2015-11-06 11:12:32 +0900 | [diff] [blame] | 251 | total_acks++; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 252 | if (Pending_Acks < MAX_PENDING_ACKS) { |
| 253 | Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].ack_num = Ack; |
| 254 | Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].txqe = txqe; |
| 255 | Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].Session_index = Session_index; |
| 256 | txqe->tcp_PendingAck_index = PendingAcks_arrBase + Pending_Acks; |
| 257 | Pending_Acks++; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 258 | } else { |
| 259 | |
| 260 | } |
| 261 | return 0; |
| 262 | } |
Chaehyun Lim | fed16f2 | 2015-09-17 16:48:43 +0900 | [diff] [blame] | 263 | static inline int remove_TCP_related(void) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 264 | { |
Shivani Bhardwaj | 7ee8291 | 2015-10-13 17:04:48 +0530 | [diff] [blame] | 265 | wilc_wlan_dev_t *p = &g_wlan; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 266 | unsigned long flags; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 267 | |
Glen Lee | 85e5756 | 2015-09-24 18:14:56 +0900 | [diff] [blame] | 268 | spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 269 | |
Glen Lee | 85e5756 | 2015-09-24 18:14:56 +0900 | [diff] [blame] | 270 | spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 271 | return 0; |
| 272 | } |
| 273 | |
Glen Lee | 82bb18e | 2015-10-27 18:28:03 +0900 | [diff] [blame] | 274 | static inline int tcp_process(struct net_device *dev, struct txq_entry_t *tqe) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 275 | { |
| 276 | int ret; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 277 | u8 *eth_hdr_ptr; |
| 278 | u8 *buffer = tqe->buffer; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 279 | unsigned short h_proto; |
| 280 | int i; |
Shivani Bhardwaj | 7ee8291 | 2015-10-13 17:04:48 +0530 | [diff] [blame] | 281 | wilc_wlan_dev_t *p = &g_wlan; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 282 | unsigned long flags; |
Glen Lee | 82bb18e | 2015-10-27 18:28:03 +0900 | [diff] [blame] | 283 | perInterface_wlan_t *nic; |
| 284 | struct wilc *wilc; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 285 | |
Glen Lee | 82bb18e | 2015-10-27 18:28:03 +0900 | [diff] [blame] | 286 | nic = netdev_priv(dev); |
| 287 | wilc = nic->wilc; |
| 288 | |
| 289 | spin_lock_irqsave(&wilc->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 290 | |
| 291 | eth_hdr_ptr = &buffer[0]; |
| 292 | h_proto = ntohs(*((unsigned short *)ð_hdr_ptr[12])); |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 293 | if (h_proto == 0x0800) { |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 294 | u8 *ip_hdr_ptr; |
| 295 | u8 protocol; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 296 | |
| 297 | ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN]; |
| 298 | protocol = ip_hdr_ptr[9]; |
| 299 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 300 | if (protocol == 0x06) { |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 301 | u8 *tcp_hdr_ptr; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 302 | u32 IHL, Total_Length, Data_offset; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 303 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 304 | tcp_hdr_ptr = &ip_hdr_ptr[IP_HDR_LEN]; |
| 305 | IHL = (ip_hdr_ptr[0] & 0xf) << 2; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 306 | Total_Length = (((u32)ip_hdr_ptr[2]) << 8) + ((u32)ip_hdr_ptr[3]); |
| 307 | Data_offset = (((u32)tcp_hdr_ptr[12] & 0xf0) >> 2); |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 308 | if (Total_Length == (IHL + Data_offset)) { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 309 | u32 seq_no, Ack_no; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 310 | |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 311 | 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] | 312 | |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 313 | 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] | 314 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 315 | for (i = 0; i < Opened_TCP_session; i++) { |
| 316 | if (Acks_keep_track_info[i].Ack_seq_num == seq_no) { |
| 317 | Update_TCP_track_session(i, Ack_no); |
| 318 | break; |
| 319 | } |
| 320 | } |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 321 | if (i == Opened_TCP_session) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 322 | add_TCP_track_session(0, 0, seq_no); |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 323 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 324 | add_TCP_Pending_Ack(Ack_no, i, tqe); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | } else { |
| 328 | ret = 0; |
| 329 | } |
| 330 | } else { |
| 331 | ret = 0; |
| 332 | } |
Glen Lee | 82bb18e | 2015-10-27 18:28:03 +0900 | [diff] [blame] | 333 | spin_unlock_irqrestore(&wilc->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 334 | return ret; |
| 335 | } |
| 336 | |
Glen Lee | c029e99 | 2015-10-27 18:27:48 +0900 | [diff] [blame] | 337 | static int wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 338 | { |
Glen Lee | c029e99 | 2015-10-27 18:27:48 +0900 | [diff] [blame] | 339 | perInterface_wlan_t *nic; |
| 340 | struct wilc *wilc; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 341 | u32 i = 0; |
| 342 | u32 Dropped = 0; |
Shivani Bhardwaj | 7ee8291 | 2015-10-13 17:04:48 +0530 | [diff] [blame] | 343 | wilc_wlan_dev_t *p = &g_wlan; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 344 | |
Glen Lee | c029e99 | 2015-10-27 18:27:48 +0900 | [diff] [blame] | 345 | nic = netdev_priv(dev); |
| 346 | wilc = nic->wilc; |
| 347 | |
| 348 | spin_lock_irqsave(&wilc->txq_spinlock, p->txq_spinlock_flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 349 | for (i = PendingAcks_arrBase; i < (PendingAcks_arrBase + Pending_Acks); i++) { |
| 350 | if (Pending_Acks_info[i].ack_num < Acks_keep_track_info[Pending_Acks_info[i].Session_index].Bigger_Ack_num) { |
| 351 | struct txq_entry_t *tqe; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 352 | |
Chandra S Gorentla | 17aacd4 | 2015-08-08 17:41:35 +0530 | [diff] [blame] | 353 | 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] | 354 | tqe = Pending_Acks_info[i].txqe; |
| 355 | if (tqe) { |
| 356 | wilc_wlan_txq_remove(tqe); |
Leo Kim | eb59da3 | 2015-11-06 11:12:33 +0900 | [diff] [blame^] | 357 | dropped_acks++; |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 358 | tqe->status = 1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 359 | if (tqe->tx_complete_func) |
| 360 | tqe->tx_complete_func(tqe->priv, tqe->status); |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 361 | kfree(tqe); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 362 | Dropped++; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | } |
| 366 | Pending_Acks = 0; |
| 367 | Opened_TCP_session = 0; |
| 368 | |
Chandra S Gorentla | 78174ad | 2015-08-08 17:41:36 +0530 | [diff] [blame] | 369 | if (PendingAcks_arrBase == 0) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 370 | PendingAcks_arrBase = MAX_TCP_SESSION; |
Chandra S Gorentla | 78174ad | 2015-08-08 17:41:36 +0530 | [diff] [blame] | 371 | else |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 372 | PendingAcks_arrBase = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 373 | |
Glen Lee | c029e99 | 2015-10-27 18:27:48 +0900 | [diff] [blame] | 374 | spin_unlock_irqrestore(&wilc->txq_spinlock, p->txq_spinlock_flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 375 | |
| 376 | while (Dropped > 0) { |
Glen Lee | c029e99 | 2015-10-27 18:27:48 +0900 | [diff] [blame] | 377 | linux_wlan_lock_timeout(&wilc->txq_event, 1); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 378 | Dropped--; |
| 379 | } |
| 380 | |
| 381 | return 1; |
| 382 | } |
| 383 | #endif |
| 384 | |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 385 | bool EnableTCPAckFilter = false; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 386 | |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 387 | void Enable_TCP_ACK_Filter(bool value) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 388 | { |
| 389 | EnableTCPAckFilter = value; |
| 390 | } |
| 391 | |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 392 | bool is_TCP_ACK_Filter_Enabled(void) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 393 | { |
| 394 | return EnableTCPAckFilter; |
| 395 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 396 | |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 397 | 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] | 398 | { |
Shivani Bhardwaj | 7ee8291 | 2015-10-13 17:04:48 +0530 | [diff] [blame] | 399 | wilc_wlan_dev_t *p = &g_wlan; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 400 | struct txq_entry_t *tqe; |
| 401 | |
| 402 | PRINT_D(TX_DBG, "Adding config packet ...\n"); |
| 403 | if (p->quit) { |
| 404 | PRINT_D(TX_DBG, "Return due to clear function\n"); |
Glen Lee | 6a3b94f | 2015-09-24 18:14:59 +0900 | [diff] [blame] | 405 | up(&g_linux_wlan->cfg_event); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 406 | return 0; |
| 407 | } |
| 408 | |
Greg Kroah-Hartman | 47c632d | 2015-09-03 18:55:43 -0700 | [diff] [blame] | 409 | tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC); |
Leo Kim | a4b1719 | 2015-11-06 11:12:31 +0900 | [diff] [blame] | 410 | if (!tqe) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 411 | PRINT_ER("Failed to allocate memory\n"); |
| 412 | return 0; |
| 413 | } |
| 414 | |
| 415 | tqe->type = WILC_CFG_PKT; |
| 416 | tqe->buffer = buffer; |
| 417 | tqe->buffer_size = buffer_size; |
| 418 | tqe->tx_complete_func = NULL; |
| 419 | tqe->priv = NULL; |
| 420 | #ifdef TCP_ACK_FILTER |
| 421 | tqe->tcp_PendingAck_index = NOT_TCP_ACK; |
| 422 | #endif |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 423 | PRINT_D(TX_DBG, "Adding the config packet at the Queue tail\n"); |
| 424 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 425 | if (wilc_wlan_txq_add_to_head(tqe)) |
| 426 | return 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 427 | return 1; |
| 428 | } |
| 429 | |
Glen Lee | 691bbd4 | 2015-10-27 18:28:02 +0900 | [diff] [blame] | 430 | int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer, |
| 431 | u32 buffer_size, wilc_tx_complete_func_t func) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 432 | { |
Shivani Bhardwaj | 7ee8291 | 2015-10-13 17:04:48 +0530 | [diff] [blame] | 433 | wilc_wlan_dev_t *p = &g_wlan; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 434 | struct txq_entry_t *tqe; |
| 435 | |
| 436 | if (p->quit) |
| 437 | return 0; |
| 438 | |
Greg Kroah-Hartman | 47c632d | 2015-09-03 18:55:43 -0700 | [diff] [blame] | 439 | tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 440 | |
Leo Kim | a4b1719 | 2015-11-06 11:12:31 +0900 | [diff] [blame] | 441 | if (!tqe) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 442 | return 0; |
| 443 | tqe->type = WILC_NET_PKT; |
| 444 | tqe->buffer = buffer; |
| 445 | tqe->buffer_size = buffer_size; |
| 446 | tqe->tx_complete_func = func; |
| 447 | tqe->priv = priv; |
| 448 | |
| 449 | PRINT_D(TX_DBG, "Adding mgmt packet at the Queue tail\n"); |
| 450 | #ifdef TCP_ACK_FILTER |
| 451 | tqe->tcp_PendingAck_index = NOT_TCP_ACK; |
Abdul Hussain | 5a66bf2 | 2015-06-16 09:44:06 +0000 | [diff] [blame] | 452 | if (is_TCP_ACK_Filter_Enabled()) |
Glen Lee | 82bb18e | 2015-10-27 18:28:03 +0900 | [diff] [blame] | 453 | tcp_process(dev, tqe); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 454 | #endif |
Glen Lee | 32f0332 | 2015-10-29 12:18:45 +0900 | [diff] [blame] | 455 | wilc_wlan_txq_add_to_tail(dev, tqe); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 456 | return p->txq_entries; |
| 457 | } |
Glen Lee | fcc6ef9 | 2015-09-16 18:53:21 +0900 | [diff] [blame] | 458 | |
Glen Lee | 829c477 | 2015-10-29 12:18:44 +0900 | [diff] [blame] | 459 | int wilc_wlan_txq_add_mgmt_pkt(struct net_device *dev, void *priv, u8 *buffer, |
| 460 | u32 buffer_size, wilc_tx_complete_func_t func) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 461 | { |
Shivani Bhardwaj | 7ee8291 | 2015-10-13 17:04:48 +0530 | [diff] [blame] | 462 | wilc_wlan_dev_t *p = &g_wlan; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 463 | struct txq_entry_t *tqe; |
| 464 | |
| 465 | if (p->quit) |
| 466 | return 0; |
| 467 | |
Greg Kroah-Hartman | 47c632d | 2015-09-03 18:55:43 -0700 | [diff] [blame] | 468 | tqe = kmalloc(sizeof(struct txq_entry_t), GFP_KERNEL); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 469 | |
Leo Kim | a4b1719 | 2015-11-06 11:12:31 +0900 | [diff] [blame] | 470 | if (!tqe) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 471 | return 0; |
| 472 | tqe->type = WILC_MGMT_PKT; |
| 473 | tqe->buffer = buffer; |
| 474 | tqe->buffer_size = buffer_size; |
| 475 | tqe->tx_complete_func = func; |
| 476 | tqe->priv = priv; |
| 477 | #ifdef TCP_ACK_FILTER |
| 478 | tqe->tcp_PendingAck_index = NOT_TCP_ACK; |
| 479 | #endif |
| 480 | PRINT_D(TX_DBG, "Adding Network packet at the Queue tail\n"); |
Glen Lee | 32f0332 | 2015-10-29 12:18:45 +0900 | [diff] [blame] | 481 | wilc_wlan_txq_add_to_tail(dev, tqe); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 482 | return 1; |
| 483 | } |
Glen Lee | fcc6ef9 | 2015-09-16 18:53:21 +0900 | [diff] [blame] | 484 | |
Glen Lee | 7af0522 | 2015-10-29 12:18:41 +0900 | [diff] [blame] | 485 | static struct txq_entry_t *wilc_wlan_txq_get_first(struct wilc *wilc) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 486 | { |
Shivani Bhardwaj | 7ee8291 | 2015-10-13 17:04:48 +0530 | [diff] [blame] | 487 | wilc_wlan_dev_t *p = &g_wlan; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 488 | struct txq_entry_t *tqe; |
| 489 | unsigned long flags; |
| 490 | |
Glen Lee | 7af0522 | 2015-10-29 12:18:41 +0900 | [diff] [blame] | 491 | spin_lock_irqsave(&wilc->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 492 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 493 | tqe = p->txq_head; |
| 494 | |
Glen Lee | 7af0522 | 2015-10-29 12:18:41 +0900 | [diff] [blame] | 495 | spin_unlock_irqrestore(&wilc->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 496 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 497 | return tqe; |
| 498 | } |
| 499 | |
Glen Lee | 50a0b3b | 2015-10-27 18:28:00 +0900 | [diff] [blame] | 500 | static struct txq_entry_t *wilc_wlan_txq_get_next(struct wilc *wilc, |
| 501 | struct txq_entry_t *tqe) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 502 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 503 | unsigned long flags; |
Leo Kim | 8739eeb | 2015-11-06 11:12:29 +0900 | [diff] [blame] | 504 | |
Glen Lee | 50a0b3b | 2015-10-27 18:28:00 +0900 | [diff] [blame] | 505 | spin_lock_irqsave(&wilc->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 506 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 507 | tqe = tqe->next; |
Glen Lee | 50a0b3b | 2015-10-27 18:28:00 +0900 | [diff] [blame] | 508 | spin_unlock_irqrestore(&wilc->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 509 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 510 | return tqe; |
| 511 | } |
| 512 | |
Glen Lee | d06f362 | 2015-10-27 18:27:59 +0900 | [diff] [blame] | 513 | static int wilc_wlan_rxq_add(struct wilc *wilc, struct rxq_entry_t *rqe) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 514 | { |
Shivani Bhardwaj | 7ee8291 | 2015-10-13 17:04:48 +0530 | [diff] [blame] | 515 | wilc_wlan_dev_t *p = &g_wlan; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 516 | |
| 517 | if (p->quit) |
| 518 | return 0; |
| 519 | |
Glen Lee | d06f362 | 2015-10-27 18:27:59 +0900 | [diff] [blame] | 520 | mutex_lock(&wilc->rxq_cs); |
Leo Kim | a4b1719 | 2015-11-06 11:12:31 +0900 | [diff] [blame] | 521 | if (!p->rxq_head) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 522 | PRINT_D(RX_DBG, "Add to Queue head\n"); |
| 523 | rqe->next = NULL; |
| 524 | p->rxq_head = rqe; |
| 525 | p->rxq_tail = rqe; |
| 526 | } else { |
| 527 | PRINT_D(RX_DBG, "Add to Queue tail\n"); |
| 528 | p->rxq_tail->next = rqe; |
| 529 | rqe->next = NULL; |
| 530 | p->rxq_tail = rqe; |
| 531 | } |
| 532 | p->rxq_entries += 1; |
| 533 | PRINT_D(RX_DBG, "Number of queue entries: %d\n", p->rxq_entries); |
Glen Lee | d06f362 | 2015-10-27 18:27:59 +0900 | [diff] [blame] | 534 | mutex_unlock(&wilc->rxq_cs); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 535 | return p->rxq_entries; |
| 536 | } |
| 537 | |
Glen Lee | db38763 | 2015-10-27 18:27:55 +0900 | [diff] [blame] | 538 | static struct rxq_entry_t *wilc_wlan_rxq_remove(struct wilc *wilc) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 539 | { |
Shivani Bhardwaj | 7ee8291 | 2015-10-13 17:04:48 +0530 | [diff] [blame] | 540 | wilc_wlan_dev_t *p = &g_wlan; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 541 | |
| 542 | PRINT_D(RX_DBG, "Getting rxQ element\n"); |
| 543 | if (p->rxq_head) { |
| 544 | struct rxq_entry_t *rqe; |
| 545 | |
Glen Lee | db38763 | 2015-10-27 18:27:55 +0900 | [diff] [blame] | 546 | mutex_lock(&wilc->rxq_cs); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 547 | rqe = p->rxq_head; |
| 548 | p->rxq_head = p->rxq_head->next; |
| 549 | p->rxq_entries -= 1; |
| 550 | PRINT_D(RX_DBG, "RXQ entries decreased\n"); |
Glen Lee | db38763 | 2015-10-27 18:27:55 +0900 | [diff] [blame] | 551 | mutex_unlock(&wilc->rxq_cs); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 552 | return rqe; |
| 553 | } |
| 554 | PRINT_D(RX_DBG, "Nothing to get from Q\n"); |
| 555 | return NULL; |
| 556 | } |
| 557 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 558 | #ifdef WILC_OPTIMIZE_SLEEP_INT |
| 559 | |
Chaehyun Lim | 9af382b | 2015-09-16 20:11:27 +0900 | [diff] [blame] | 560 | static inline void chip_allow_sleep(void) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 561 | { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 562 | u32 reg = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 563 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 564 | g_wlan.hif_func.hif_read_reg(0xf0, ®); |
| 565 | |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 566 | g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0)); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 567 | } |
| 568 | |
Chaehyun Lim | 9af382b | 2015-09-16 20:11:27 +0900 | [diff] [blame] | 569 | static inline void chip_wakeup(void) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 570 | { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 571 | u32 reg, clk_status_reg, trials = 0; |
| 572 | u32 sleep_time; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 573 | |
| 574 | if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) { |
| 575 | do { |
| 576 | g_wlan.hif_func.hif_read_reg(1, ®); |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 577 | g_wlan.hif_func.hif_write_reg(1, reg | BIT(1)); |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 578 | g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1)); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 579 | |
| 580 | do { |
Greg Kroah-Hartman | 80e29c7 | 2015-08-14 19:42:23 -0700 | [diff] [blame] | 581 | usleep_range(2 * 1000, 2 * 1000); |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 582 | if ((wilc_get_chipid(true) == 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 583 | 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] | 584 | |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 585 | } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0)); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 586 | |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 587 | } while (wilc_get_chipid(true) == 0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 588 | } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) { |
| 589 | g_wlan.hif_func.hif_read_reg(0xf0, ®); |
| 590 | do { |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 591 | g_wlan.hif_func.hif_write_reg(0xf0, reg | BIT(0)); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 592 | g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg); |
| 593 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 594 | while (((clk_status_reg & 0x1) == 0) && (((++trials) % 3) == 0)) { |
Greg Kroah-Hartman | 80e29c7 | 2015-08-14 19:42:23 -0700 | [diff] [blame] | 595 | usleep_range(2 * 1000, 2 * 1000); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 596 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 597 | g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg); |
| 598 | |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 599 | if ((clk_status_reg & 0x1) == 0) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 600 | wilc_debug(N_ERR, "clocks still OFF. Wake up failed\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 601 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 602 | if ((clk_status_reg & 0x1) == 0) { |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 603 | g_wlan.hif_func.hif_write_reg(0xf0, reg & |
| 604 | (~BIT(0))); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 605 | } |
| 606 | } while ((clk_status_reg & 0x1) == 0); |
| 607 | } |
| 608 | |
Leo Kim | b7d1e18 | 2015-11-06 11:12:30 +0900 | [diff] [blame] | 609 | if (chip_ps_state == CHIP_SLEEPING_MANUAL) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 610 | g_wlan.hif_func.hif_read_reg(0x1C0C, ®); |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 611 | reg &= ~BIT(0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 612 | g_wlan.hif_func.hif_write_reg(0x1C0C, reg); |
| 613 | |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 614 | if (wilc_get_chipid(false) >= 0x1002b0) { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 615 | u32 val32; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 616 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 617 | g_wlan.hif_func.hif_read_reg(0x1e1c, &val32); |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 618 | val32 |= BIT(6); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 619 | g_wlan.hif_func.hif_write_reg(0x1e1c, val32); |
| 620 | |
| 621 | g_wlan.hif_func.hif_read_reg(0x1e9c, &val32); |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 622 | val32 |= BIT(6); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 623 | g_wlan.hif_func.hif_write_reg(0x1e9c, val32); |
| 624 | } |
| 625 | } |
Leo Kim | b7d1e18 | 2015-11-06 11:12:30 +0900 | [diff] [blame] | 626 | chip_ps_state = CHIP_WAKEDUP; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 627 | } |
| 628 | #else |
Chaehyun Lim | 9af382b | 2015-09-16 20:11:27 +0900 | [diff] [blame] | 629 | static inline void chip_wakeup(void) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 630 | { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 631 | u32 reg, trials = 0; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 632 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 633 | do { |
| 634 | if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) { |
| 635 | g_wlan.hif_func.hif_read_reg(1, ®); |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 636 | g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1)); |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 637 | g_wlan.hif_func.hif_write_reg(1, reg | BIT(1)); |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 638 | g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1)); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 639 | } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 640 | g_wlan.hif_func.hif_read_reg(0xf0, ®); |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 641 | g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0)); |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 642 | g_wlan.hif_func.hif_write_reg(0xf0, reg | BIT(0)); |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 643 | g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0)); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | do { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 647 | mdelay(3); |
| 648 | |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 649 | if ((wilc_get_chipid(true) == 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 650 | 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] | 651 | |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 652 | } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0)); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 653 | |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 654 | } while (wilc_get_chipid(true) == 0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 655 | |
Leo Kim | b7d1e18 | 2015-11-06 11:12:30 +0900 | [diff] [blame] | 656 | if (chip_ps_state == CHIP_SLEEPING_MANUAL) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 657 | g_wlan.hif_func.hif_read_reg(0x1C0C, ®); |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 658 | reg &= ~BIT(0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 659 | g_wlan.hif_func.hif_write_reg(0x1C0C, reg); |
| 660 | |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 661 | if (wilc_get_chipid(false) >= 0x1002b0) { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 662 | u32 val32; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 663 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 664 | g_wlan.hif_func.hif_read_reg(0x1e1c, &val32); |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 665 | val32 |= BIT(6); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 666 | g_wlan.hif_func.hif_write_reg(0x1e1c, val32); |
| 667 | |
| 668 | g_wlan.hif_func.hif_read_reg(0x1e9c, &val32); |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 669 | val32 |= BIT(6); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 670 | g_wlan.hif_func.hif_write_reg(0x1e9c, val32); |
| 671 | } |
| 672 | } |
Leo Kim | b7d1e18 | 2015-11-06 11:12:30 +0900 | [diff] [blame] | 673 | chip_ps_state = CHIP_WAKEDUP; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 674 | } |
| 675 | #endif |
Chaehyun Lim | 4e4467f | 2015-06-11 14:35:55 +0900 | [diff] [blame] | 676 | void chip_sleep_manually(u32 u32SleepTime) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 677 | { |
Leo Kim | b7d1e18 | 2015-11-06 11:12:30 +0900 | [diff] [blame] | 678 | if (chip_ps_state != CHIP_WAKEDUP) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 679 | return; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 680 | acquire_bus(ACQUIRE_ONLY); |
| 681 | |
| 682 | #ifdef WILC_OPTIMIZE_SLEEP_INT |
| 683 | chip_allow_sleep(); |
| 684 | #endif |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 685 | g_wlan.hif_func.hif_write_reg(0x10a8, 1); |
| 686 | |
Leo Kim | b7d1e18 | 2015-11-06 11:12:30 +0900 | [diff] [blame] | 687 | chip_ps_state = CHIP_SLEEPING_MANUAL; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 688 | release_bus(RELEASE_ONLY); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 689 | } |
| 690 | |
Glen Lee | a1332ca | 2015-10-27 18:27:47 +0900 | [diff] [blame] | 691 | int wilc_wlan_handle_txq(struct net_device *dev, u32 *pu32TxqCount) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 692 | { |
| 693 | wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan; |
| 694 | int i, entries = 0; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 695 | u32 sum; |
| 696 | u32 reg; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 697 | u8 *txb = p->tx_buffer; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 698 | u32 offset = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 699 | int vmm_sz = 0; |
| 700 | struct txq_entry_t *tqe; |
| 701 | int ret = 0; |
| 702 | int counter; |
| 703 | int timeout; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 704 | u32 vmm_table[WILC_VMM_TBL_SIZE]; |
Glen Lee | a1332ca | 2015-10-27 18:27:47 +0900 | [diff] [blame] | 705 | perInterface_wlan_t *nic; |
| 706 | struct wilc *wilc; |
| 707 | |
| 708 | nic = netdev_priv(dev); |
| 709 | wilc = nic->wilc; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 710 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 711 | p->txq_exit = 0; |
| 712 | do { |
| 713 | if (p->quit) |
| 714 | break; |
| 715 | |
Glen Lee | a1332ca | 2015-10-27 18:27:47 +0900 | [diff] [blame] | 716 | linux_wlan_lock_timeout(&wilc->txq_add_to_head_cs, |
Glen Lee | b002e20 | 2015-09-24 18:15:05 +0900 | [diff] [blame] | 717 | CFG_PKTS_TIMEOUT); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 718 | #ifdef TCP_ACK_FILTER |
Glen Lee | c029e99 | 2015-10-27 18:27:48 +0900 | [diff] [blame] | 719 | wilc_wlan_txq_filter_dup_tcp_ack(dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 720 | #endif |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 721 | PRINT_D(TX_DBG, "Getting the head of the TxQ\n"); |
Glen Lee | 7af0522 | 2015-10-29 12:18:41 +0900 | [diff] [blame] | 722 | tqe = wilc_wlan_txq_get_first(wilc); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 723 | i = 0; |
| 724 | sum = 0; |
| 725 | do { |
Leo Kim | a4b1719 | 2015-11-06 11:12:31 +0900 | [diff] [blame] | 726 | if (tqe && (i < (WILC_VMM_TBL_SIZE - 1))) { |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 727 | if (tqe->type == WILC_CFG_PKT) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 728 | vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET; |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 729 | |
| 730 | else if (tqe->type == WILC_NET_PKT) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 731 | vmm_sz = ETH_ETHERNET_HDR_OFFSET; |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 732 | |
| 733 | else |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 734 | vmm_sz = HOST_HDR_OFFSET; |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 735 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 736 | vmm_sz += tqe->buffer_size; |
| 737 | PRINT_D(TX_DBG, "VMM Size before alignment = %d\n", vmm_sz); |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 738 | if (vmm_sz & 0x3) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 739 | vmm_sz = (vmm_sz + 4) & ~0x3; |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 740 | |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 741 | if ((sum + vmm_sz) > LINUX_TX_SIZE) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 742 | break; |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 743 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 744 | PRINT_D(TX_DBG, "VMM Size AFTER alignment = %d\n", vmm_sz); |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 745 | vmm_table[i] = vmm_sz / 4; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 746 | PRINT_D(TX_DBG, "VMMTable entry size = %d\n", vmm_table[i]); |
| 747 | |
| 748 | if (tqe->type == WILC_CFG_PKT) { |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 749 | vmm_table[i] |= BIT(10); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 750 | PRINT_D(TX_DBG, "VMMTable entry changed for CFG packet = %d\n", vmm_table[i]); |
| 751 | } |
| 752 | #ifdef BIG_ENDIAN |
| 753 | vmm_table[i] = BYTE_SWAP(vmm_table[i]); |
| 754 | #endif |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 755 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 756 | i++; |
| 757 | sum += vmm_sz; |
| 758 | PRINT_D(TX_DBG, "sum = %d\n", sum); |
Glen Lee | 50a0b3b | 2015-10-27 18:28:00 +0900 | [diff] [blame] | 759 | tqe = wilc_wlan_txq_get_next(wilc, tqe); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 760 | } else { |
| 761 | break; |
| 762 | } |
| 763 | } while (1); |
| 764 | |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 765 | if (i == 0) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 766 | PRINT_D(TX_DBG, "Nothing in TX-Q\n"); |
| 767 | break; |
| 768 | } else { |
| 769 | PRINT_D(TX_DBG, "Mark the last entry in VMM table - number of previous entries = %d\n", i); |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 770 | vmm_table[i] = 0x0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 771 | } |
| 772 | acquire_bus(ACQUIRE_AND_WAKEUP); |
| 773 | counter = 0; |
| 774 | do { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 775 | ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, ®); |
| 776 | if (!ret) { |
| 777 | wilc_debug(N_ERR, "[wilc txq]: fail can't read reg vmm_tbl_entry..\n"); |
| 778 | break; |
| 779 | } |
| 780 | |
| 781 | if ((reg & 0x1) == 0) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 782 | PRINT_D(TX_DBG, "Writing VMM table ... with Size = %d\n", ((i + 1) * 4)); |
| 783 | break; |
| 784 | } else { |
| 785 | counter++; |
| 786 | if (counter > 200) { |
| 787 | counter = 0; |
| 788 | PRINT_D(TX_DBG, "Looping in tx ctrl , forcce quit\n"); |
| 789 | ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, 0); |
| 790 | break; |
| 791 | } |
Chandra S Gorentla | 17aacd4 | 2015-08-08 17:41:35 +0530 | [diff] [blame] | 792 | 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] | 793 | release_bus(RELEASE_ALLOW_SLEEP); |
Greg Kroah-Hartman | 2b922cb | 2015-09-04 09:30:51 -0700 | [diff] [blame] | 794 | usleep_range(3000, 3000); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 795 | acquire_bus(ACQUIRE_AND_WAKEUP); |
| 796 | } |
| 797 | } while (!p->quit); |
| 798 | |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 799 | if (!ret) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 800 | goto _end_; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 801 | |
| 802 | timeout = 200; |
| 803 | do { |
Chaehyun Lim | c3ca637 | 2015-09-20 15:51:19 +0900 | [diff] [blame] | 804 | 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] | 805 | if (!ret) { |
| 806 | wilc_debug(N_ERR, "ERR block TX of VMM table.\n"); |
| 807 | break; |
| 808 | } |
| 809 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 810 | ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x2); |
| 811 | if (!ret) { |
| 812 | wilc_debug(N_ERR, "[wilc txq]: fail can't write reg host_vmm_ctl..\n"); |
| 813 | break; |
| 814 | } |
| 815 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 816 | do { |
| 817 | ret = p->hif_func.hif_read_reg(WILC_HOST_VMM_CTL, ®); |
| 818 | if (!ret) { |
| 819 | wilc_debug(N_ERR, "[wilc txq]: fail can't read reg host_vmm_ctl..\n"); |
| 820 | break; |
| 821 | } |
| 822 | if ((reg >> 2) & 0x1) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 823 | entries = ((reg >> 3) & 0x3f); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 824 | break; |
| 825 | } else { |
| 826 | release_bus(RELEASE_ALLOW_SLEEP); |
Greg Kroah-Hartman | 2b922cb | 2015-09-04 09:30:51 -0700 | [diff] [blame] | 827 | usleep_range(3000, 3000); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 828 | acquire_bus(ACQUIRE_AND_WAKEUP); |
| 829 | PRINT_WRN(GENERIC_DBG, "Can't get VMM entery - reg = %2x\n", reg); |
| 830 | } |
| 831 | } while (--timeout); |
| 832 | if (timeout <= 0) { |
| 833 | ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x0); |
| 834 | break; |
| 835 | } |
| 836 | |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 837 | if (!ret) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 838 | break; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 839 | |
| 840 | if (entries == 0) { |
Chandra S Gorentla | 17aacd4 | 2015-08-08 17:41:35 +0530 | [diff] [blame] | 841 | 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] | 842 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 843 | ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, ®); |
| 844 | if (!ret) { |
| 845 | wilc_debug(N_ERR, "[wilc txq]: fail can't read reg WILC_HOST_TX_CTRL..\n"); |
| 846 | break; |
| 847 | } |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 848 | reg &= ~BIT(0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 849 | ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, reg); |
| 850 | if (!ret) { |
| 851 | wilc_debug(N_ERR, "[wilc txq]: fail can't write reg WILC_HOST_TX_CTRL..\n"); |
| 852 | break; |
| 853 | } |
| 854 | break; |
| 855 | } else { |
| 856 | break; |
| 857 | } |
| 858 | } while (1); |
| 859 | |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 860 | if (!ret) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 861 | goto _end_; |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 862 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 863 | if (entries == 0) { |
| 864 | ret = WILC_TX_ERR_NO_BUF; |
| 865 | goto _end_; |
| 866 | } |
| 867 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 868 | release_bus(RELEASE_ALLOW_SLEEP); |
| 869 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 870 | offset = 0; |
| 871 | i = 0; |
| 872 | do { |
Glen Lee | 718fc2c | 2015-10-29 12:18:43 +0900 | [diff] [blame] | 873 | tqe = wilc_wlan_txq_remove_from_head(dev); |
Leo Kim | a4b1719 | 2015-11-06 11:12:31 +0900 | [diff] [blame] | 874 | if (tqe && (vmm_table[i] != 0)) { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 875 | u32 header, buffer_offset; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 876 | |
| 877 | #ifdef BIG_ENDIAN |
| 878 | vmm_table[i] = BYTE_SWAP(vmm_table[i]); |
| 879 | #endif |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 880 | vmm_sz = (vmm_table[i] & 0x3ff); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 881 | vmm_sz *= 4; |
| 882 | header = (tqe->type << 31) | (tqe->buffer_size << 15) | vmm_sz; |
Chandra S Gorentla | 78174ad | 2015-08-08 17:41:36 +0530 | [diff] [blame] | 883 | if (tqe->type == WILC_MGMT_PKT) |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 884 | header |= BIT(30); |
Chandra S Gorentla | 78174ad | 2015-08-08 17:41:36 +0530 | [diff] [blame] | 885 | else |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 886 | header &= ~BIT(30); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 887 | |
| 888 | #ifdef BIG_ENDIAN |
| 889 | header = BYTE_SWAP(header); |
| 890 | #endif |
| 891 | memcpy(&txb[offset], &header, 4); |
| 892 | if (tqe->type == WILC_CFG_PKT) { |
| 893 | buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET; |
| 894 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 895 | else if (tqe->type == WILC_NET_PKT) { |
| 896 | char *pBSSID = ((struct tx_complete_data *)(tqe->priv))->pBssid; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 897 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 898 | buffer_offset = ETH_ETHERNET_HDR_OFFSET; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 899 | memcpy(&txb[offset + 4], pBSSID, 6); |
| 900 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 901 | else { |
| 902 | buffer_offset = HOST_HDR_OFFSET; |
| 903 | } |
| 904 | |
| 905 | memcpy(&txb[offset + buffer_offset], tqe->buffer, tqe->buffer_size); |
| 906 | offset += vmm_sz; |
| 907 | i++; |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 908 | tqe->status = 1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 909 | if (tqe->tx_complete_func) |
| 910 | tqe->tx_complete_func(tqe->priv, tqe->status); |
| 911 | #ifdef TCP_ACK_FILTER |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 912 | if (tqe->tcp_PendingAck_index != NOT_TCP_ACK) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 913 | Pending_Acks_info[tqe->tcp_PendingAck_index].txqe = NULL; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 914 | #endif |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 915 | kfree(tqe); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 916 | } else { |
| 917 | break; |
| 918 | } |
| 919 | } while (--entries); |
| 920 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 921 | acquire_bus(ACQUIRE_AND_WAKEUP); |
| 922 | |
| 923 | ret = p->hif_func.hif_clear_int_ext(ENABLE_TX_VMM); |
| 924 | if (!ret) { |
| 925 | wilc_debug(N_ERR, "[wilc txq]: fail can't start tx VMM ...\n"); |
| 926 | goto _end_; |
| 927 | } |
| 928 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 929 | ret = p->hif_func.hif_block_tx_ext(0, txb, offset); |
| 930 | if (!ret) { |
| 931 | wilc_debug(N_ERR, "[wilc txq]: fail can't block tx ext...\n"); |
| 932 | goto _end_; |
| 933 | } |
| 934 | |
| 935 | _end_: |
| 936 | |
| 937 | release_bus(RELEASE_ALLOW_SLEEP); |
| 938 | if (ret != 1) |
| 939 | break; |
| 940 | } while (0); |
Glen Lee | a1332ca | 2015-10-27 18:27:47 +0900 | [diff] [blame] | 941 | up(&wilc->txq_add_to_head_cs); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 942 | |
| 943 | p->txq_exit = 1; |
| 944 | PRINT_D(TX_DBG, "THREAD: Exiting txq\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 945 | *pu32TxqCount = p->txq_entries; |
| 946 | return ret; |
| 947 | } |
| 948 | |
Glen Lee | 39ce4d3 | 2015-10-27 18:27:42 +0900 | [diff] [blame] | 949 | static void wilc_wlan_handle_rxq(struct wilc *wilc) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 950 | { |
Shivani Bhardwaj | 7ee8291 | 2015-10-13 17:04:48 +0530 | [diff] [blame] | 951 | wilc_wlan_dev_t *p = &g_wlan; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 952 | int offset = 0, size, has_packet = 0; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 953 | u8 *buffer; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 954 | struct rxq_entry_t *rqe; |
| 955 | |
| 956 | p->rxq_exit = 0; |
| 957 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 958 | do { |
| 959 | if (p->quit) { |
Chandra S Gorentla | 17aacd4 | 2015-08-08 17:41:35 +0530 | [diff] [blame] | 960 | 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] | 961 | up(&wilc->cfg_event); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 962 | break; |
| 963 | } |
Glen Lee | db38763 | 2015-10-27 18:27:55 +0900 | [diff] [blame] | 964 | rqe = wilc_wlan_rxq_remove(wilc); |
Leo Kim | a4b1719 | 2015-11-06 11:12:31 +0900 | [diff] [blame] | 965 | if (!rqe) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 966 | PRINT_D(RX_DBG, "nothing in the queue - exit 1st do-while\n"); |
| 967 | break; |
| 968 | } |
| 969 | buffer = rqe->buffer; |
| 970 | size = rqe->buffer_size; |
| 971 | PRINT_D(RX_DBG, "rxQ entery Size = %d - Address = %p\n", size, buffer); |
| 972 | offset = 0; |
| 973 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 974 | do { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 975 | u32 header; |
| 976 | u32 pkt_len, pkt_offset, tp_len; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 977 | int is_cfg_packet; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 978 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 979 | PRINT_D(RX_DBG, "In the 2nd do-while\n"); |
| 980 | memcpy(&header, &buffer[offset], 4); |
| 981 | #ifdef BIG_ENDIAN |
| 982 | header = BYTE_SWAP(header); |
| 983 | #endif |
| 984 | PRINT_D(RX_DBG, "Header = %04x - Offset = %d\n", header, offset); |
| 985 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 986 | is_cfg_packet = (header >> 31) & 0x1; |
| 987 | pkt_offset = (header >> 22) & 0x1ff; |
| 988 | tp_len = (header >> 11) & 0x7ff; |
| 989 | pkt_len = header & 0x7ff; |
| 990 | |
| 991 | if (pkt_len == 0 || tp_len == 0) { |
| 992 | wilc_debug(N_RXQ, "[wilc rxq]: data corrupt, packet len or tp_len is 0 [%d][%d]\n", pkt_len, tp_len); |
| 993 | break; |
| 994 | } |
| 995 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 996 | #define IS_MANAGMEMENT 0x100 |
| 997 | #define IS_MANAGMEMENT_CALLBACK 0x080 |
| 998 | #define IS_MGMT_STATUS_SUCCES 0x040 |
| 999 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1000 | if (pkt_offset & IS_MANAGMEMENT) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1001 | pkt_offset &= ~(IS_MANAGMEMENT | IS_MANAGMEMENT_CALLBACK | IS_MGMT_STATUS_SUCCES); |
| 1002 | |
Glen Lee | 11f4b2e | 2015-10-27 18:27:51 +0900 | [diff] [blame] | 1003 | WILC_WFI_mgmt_rx(wilc, &buffer[offset + HOST_HDR_OFFSET], pkt_len); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1004 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1005 | else |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1006 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1007 | if (!is_cfg_packet) { |
Glen Lee | 6361167 | 2015-09-24 18:14:52 +0900 | [diff] [blame] | 1008 | if (pkt_len > 0) { |
Glen Lee | cb1991a | 2015-10-27 18:27:56 +0900 | [diff] [blame] | 1009 | frmw_to_linux(wilc, |
| 1010 | &buffer[offset], |
Glen Lee | 6361167 | 2015-09-24 18:14:52 +0900 | [diff] [blame] | 1011 | pkt_len, |
| 1012 | pkt_offset); |
| 1013 | has_packet = 1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1014 | } |
| 1015 | } else { |
| 1016 | wilc_cfg_rsp_t rsp; |
| 1017 | |
Glen Lee | 30f535a | 2015-10-02 14:22:10 +0900 | [diff] [blame] | 1018 | wilc_wlan_cfg_indicate_rx(&buffer[pkt_offset + offset], pkt_len, &rsp); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1019 | if (rsp.type == WILC_CFG_RSP) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1020 | 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] | 1021 | if (p->cfg_seq_no == rsp.seq_no) |
Glen Lee | 39ce4d3 | 2015-10-27 18:27:42 +0900 | [diff] [blame] | 1022 | up(&wilc->cfg_event); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1023 | } else if (rsp.type == WILC_CFG_RSP_STATUS) { |
Glen Lee | 64f2b71 | 2015-10-27 18:27:43 +0900 | [diff] [blame] | 1024 | linux_wlan_mac_indicate(wilc, WILC_MAC_INDICATE_STATUS); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1025 | |
| 1026 | } else if (rsp.type == WILC_CFG_RSP_SCAN) { |
Glen Lee | 64f2b71 | 2015-10-27 18:27:43 +0900 | [diff] [blame] | 1027 | linux_wlan_mac_indicate(wilc, WILC_MAC_INDICATE_SCAN); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1028 | } |
| 1029 | } |
| 1030 | } |
| 1031 | offset += tp_len; |
| 1032 | if (offset >= size) |
| 1033 | break; |
| 1034 | } while (1); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1035 | #ifndef MEMORY_STATIC |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 1036 | kfree(buffer); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1037 | #endif |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 1038 | kfree(rqe); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1039 | |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 1040 | if (has_packet) |
Glen Lee | c0cadaa | 2015-09-24 18:14:54 +0900 | [diff] [blame] | 1041 | linux_wlan_rx_complete(); |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 1042 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1043 | } while (1); |
| 1044 | |
| 1045 | p->rxq_exit = 1; |
Chandra S Gorentla | 17aacd4 | 2015-08-08 17:41:35 +0530 | [diff] [blame] | 1046 | PRINT_D(RX_DBG, "THREAD: Exiting RX thread\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1047 | } |
| 1048 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1049 | static void wilc_unknown_isr_ext(void) |
| 1050 | { |
| 1051 | g_wlan.hif_func.hif_clear_int_ext(0); |
| 1052 | } |
Leo Kim | 2d6973e | 2015-11-06 11:12:28 +0900 | [diff] [blame] | 1053 | |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1054 | static void wilc_pllupdate_isr_ext(u32 int_stats) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1055 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1056 | int trials = 10; |
| 1057 | |
| 1058 | g_wlan.hif_func.hif_clear_int_ext(PLL_INT_CLR); |
| 1059 | |
Greg Kroah-Hartman | c2e4c0f | 2015-09-03 19:09:50 -0700 | [diff] [blame] | 1060 | mdelay(WILC_PLL_TO); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1061 | |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 1062 | while (!(ISWILC1000(wilc_get_chipid(true)) && --trials)) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1063 | PRINT_D(TX_DBG, "PLL update retrying\n"); |
Greg Kroah-Hartman | c2e4c0f | 2015-09-03 19:09:50 -0700 | [diff] [blame] | 1064 | mdelay(1); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1065 | } |
| 1066 | } |
| 1067 | |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1068 | static void wilc_sleeptimer_isr_ext(u32 int_stats1) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1069 | { |
| 1070 | g_wlan.hif_func.hif_clear_int_ext(SLEEP_INT_CLR); |
| 1071 | #ifndef WILC_OPTIMIZE_SLEEP_INT |
Leo Kim | b7d1e18 | 2015-11-06 11:12:30 +0900 | [diff] [blame] | 1072 | chip_ps_state = CHIP_SLEEPING_AUTO; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1073 | #endif |
| 1074 | } |
| 1075 | |
Glen Lee | 3bcd45b | 2015-10-27 18:27:41 +0900 | [diff] [blame] | 1076 | 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] | 1077 | { |
Shivani Bhardwaj | 7ee8291 | 2015-10-13 17:04:48 +0530 | [diff] [blame] | 1078 | wilc_wlan_dev_t *p = &g_wlan; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1079 | #ifdef MEMORY_STATIC |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1080 | u32 offset = p->rx_buffer_offset; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1081 | #endif |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 1082 | u8 *buffer = NULL; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1083 | u32 size; |
| 1084 | u32 retries = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1085 | int ret = 0; |
| 1086 | struct rxq_entry_t *rqe; |
| 1087 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1088 | size = ((int_status & 0x7fff) << 2); |
| 1089 | |
| 1090 | while (!size && retries < 10) { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1091 | u32 time = 0; |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 1092 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1093 | wilc_debug(N_ERR, "RX Size equal zero ... Trying to read it again for %d time\n", time++); |
| 1094 | p->hif_func.hif_read_size(&size); |
| 1095 | size = ((size & 0x7fff) << 2); |
| 1096 | retries++; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | if (size > 0) { |
| 1100 | #ifdef MEMORY_STATIC |
Glen Lee | 03eb726 | 2015-09-24 18:15:03 +0900 | [diff] [blame] | 1101 | if (LINUX_RX_SIZE - offset < size) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1102 | offset = 0; |
| 1103 | |
| 1104 | if (p->rx_buffer) |
| 1105 | buffer = &p->rx_buffer[offset]; |
| 1106 | else { |
| 1107 | wilc_debug(N_ERR, "[wilc isr]: fail Rx Buffer is NULL...drop the packets (%d)\n", size); |
| 1108 | goto _end_; |
| 1109 | } |
| 1110 | |
| 1111 | #else |
Greg Kroah-Hartman | f019b9d | 2015-09-03 18:50:27 -0700 | [diff] [blame] | 1112 | buffer = kmalloc(size, GFP_KERNEL); |
Leo Kim | a4b1719 | 2015-11-06 11:12:31 +0900 | [diff] [blame] | 1113 | if (!buffer) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1114 | 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] | 1115 | usleep_range(100 * 1000, 100 * 1000); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1116 | goto _end_; |
| 1117 | } |
| 1118 | #endif |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1119 | p->hif_func.hif_clear_int_ext(DATA_INT_CLR | ENABLE_RX_VMM); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1120 | ret = p->hif_func.hif_block_rx_ext(0, buffer, size); |
| 1121 | |
| 1122 | if (!ret) { |
| 1123 | wilc_debug(N_ERR, "[wilc isr]: fail block rx...\n"); |
| 1124 | goto _end_; |
| 1125 | } |
| 1126 | _end_: |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1127 | if (ret) { |
| 1128 | #ifdef MEMORY_STATIC |
| 1129 | offset += size; |
| 1130 | p->rx_buffer_offset = offset; |
| 1131 | #endif |
Greg Kroah-Hartman | f019b9d | 2015-09-03 18:50:27 -0700 | [diff] [blame] | 1132 | rqe = kmalloc(sizeof(struct rxq_entry_t), GFP_KERNEL); |
Leo Kim | a4b1719 | 2015-11-06 11:12:31 +0900 | [diff] [blame] | 1133 | if (rqe) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1134 | rqe->buffer = buffer; |
| 1135 | rqe->buffer_size = size; |
| 1136 | PRINT_D(RX_DBG, "rxq entery Size= %d - Address = %p\n", rqe->buffer_size, rqe->buffer); |
Glen Lee | d06f362 | 2015-10-27 18:27:59 +0900 | [diff] [blame] | 1137 | wilc_wlan_rxq_add(wilc, rqe); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1138 | } |
| 1139 | } else { |
| 1140 | #ifndef MEMORY_STATIC |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 1141 | kfree(buffer); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1142 | #endif |
| 1143 | } |
| 1144 | } |
Glen Lee | 39ce4d3 | 2015-10-27 18:27:42 +0900 | [diff] [blame] | 1145 | wilc_wlan_handle_rxq(wilc); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1146 | } |
| 1147 | |
Glen Lee | 50b929e | 2015-10-27 18:27:40 +0900 | [diff] [blame] | 1148 | void wilc_handle_isr(void *wilc) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1149 | { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1150 | u32 int_status; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1151 | |
| 1152 | acquire_bus(ACQUIRE_AND_WAKEUP); |
| 1153 | g_wlan.hif_func.hif_read_int(&int_status); |
| 1154 | |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 1155 | if (int_status & PLL_INT_EXT) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1156 | wilc_pllupdate_isr_ext(int_status); |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 1157 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1158 | if (int_status & DATA_INT_EXT) { |
Glen Lee | 3bcd45b | 2015-10-27 18:27:41 +0900 | [diff] [blame] | 1159 | wilc_wlan_handle_isr_ext(wilc, int_status); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1160 | #ifndef WILC_OPTIMIZE_SLEEP_INT |
Leo Kim | b7d1e18 | 2015-11-06 11:12:30 +0900 | [diff] [blame] | 1161 | chip_ps_state = CHIP_WAKEDUP; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1162 | #endif |
| 1163 | } |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 1164 | if (int_status & SLEEP_INT_EXT) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1165 | wilc_sleeptimer_isr_ext(int_status); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1166 | |
| 1167 | if (!(int_status & (ALL_INT_EXT))) { |
| 1168 | #ifdef WILC_SDIO |
| 1169 | PRINT_D(TX_DBG, ">> UNKNOWN_INTERRUPT - 0x%08x\n", int_status); |
| 1170 | #endif |
| 1171 | wilc_unknown_isr_ext(); |
| 1172 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1173 | release_bus(RELEASE_ALLOW_SLEEP); |
| 1174 | } |
| 1175 | |
Glen Lee | 63d7ab8 | 2015-10-01 16:03:32 +0900 | [diff] [blame] | 1176 | int wilc_wlan_firmware_download(const u8 *buffer, u32 buffer_size) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1177 | { |
Shivani Bhardwaj | 7ee8291 | 2015-10-13 17:04:48 +0530 | [diff] [blame] | 1178 | wilc_wlan_dev_t *p = &g_wlan; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1179 | u32 offset; |
| 1180 | u32 addr, size, size2, blksz; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 1181 | u8 *dma_buffer; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1182 | int ret = 0; |
| 1183 | |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 1184 | blksz = BIT(12); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1185 | |
Greg Kroah-Hartman | f019b9d | 2015-09-03 18:50:27 -0700 | [diff] [blame] | 1186 | dma_buffer = kmalloc(blksz, GFP_KERNEL); |
Leo Kim | a4b1719 | 2015-11-06 11:12:31 +0900 | [diff] [blame] | 1187 | if (!dma_buffer) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1188 | ret = -5; |
| 1189 | PRINT_ER("Can't allocate buffer for firmware download IO error\n "); |
| 1190 | goto _fail_1; |
| 1191 | } |
| 1192 | |
| 1193 | PRINT_D(INIT_DBG, "Downloading firmware size = %d ...\n", buffer_size); |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 1194 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1195 | offset = 0; |
| 1196 | do { |
| 1197 | memcpy(&addr, &buffer[offset], 4); |
| 1198 | memcpy(&size, &buffer[offset + 4], 4); |
| 1199 | #ifdef BIG_ENDIAN |
| 1200 | addr = BYTE_SWAP(addr); |
| 1201 | size = BYTE_SWAP(size); |
| 1202 | #endif |
| 1203 | acquire_bus(ACQUIRE_ONLY); |
| 1204 | offset += 8; |
| 1205 | while (((int)size) && (offset < buffer_size)) { |
Chandra S Gorentla | 78174ad | 2015-08-08 17:41:36 +0530 | [diff] [blame] | 1206 | if (size <= blksz) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1207 | size2 = size; |
Chandra S Gorentla | 78174ad | 2015-08-08 17:41:36 +0530 | [diff] [blame] | 1208 | else |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1209 | size2 = blksz; |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 1210 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1211 | memcpy(dma_buffer, &buffer[offset], size2); |
| 1212 | ret = p->hif_func.hif_block_tx(addr, dma_buffer, size2); |
| 1213 | if (!ret) |
| 1214 | break; |
| 1215 | |
| 1216 | addr += size2; |
| 1217 | offset += size2; |
| 1218 | size -= size2; |
| 1219 | } |
| 1220 | release_bus(RELEASE_ONLY); |
| 1221 | |
| 1222 | if (!ret) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1223 | ret = -5; |
| 1224 | PRINT_ER("Can't download firmware IO error\n "); |
| 1225 | goto _fail_; |
| 1226 | } |
| 1227 | PRINT_D(INIT_DBG, "Offset = %d\n", offset); |
| 1228 | } while (offset < buffer_size); |
| 1229 | |
| 1230 | _fail_: |
| 1231 | |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 1232 | kfree(dma_buffer); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1233 | |
| 1234 | _fail_1: |
| 1235 | |
| 1236 | return (ret < 0) ? ret : 0; |
| 1237 | } |
| 1238 | |
Glen Lee | e42563b | 2015-10-01 16:03:33 +0900 | [diff] [blame] | 1239 | int wilc_wlan_start(void) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1240 | { |
Shivani Bhardwaj | 7ee8291 | 2015-10-13 17:04:48 +0530 | [diff] [blame] | 1241 | wilc_wlan_dev_t *p = &g_wlan; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1242 | u32 reg = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1243 | int ret; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1244 | u32 chipid; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1245 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1246 | if (p->io_func.io_type == HIF_SDIO) { |
| 1247 | reg = 0; |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 1248 | reg |= BIT(3); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1249 | } else if (p->io_func.io_type == HIF_SPI) { |
| 1250 | reg = 1; |
| 1251 | } |
| 1252 | acquire_bus(ACQUIRE_ONLY); |
| 1253 | ret = p->hif_func.hif_write_reg(WILC_VMM_CORE_CFG, reg); |
| 1254 | if (!ret) { |
| 1255 | wilc_debug(N_ERR, "[wilc start]: fail write reg vmm_core_cfg...\n"); |
| 1256 | release_bus(RELEASE_ONLY); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1257 | ret = -5; |
| 1258 | return ret; |
| 1259 | } |
| 1260 | reg = 0; |
| 1261 | #ifdef WILC_SDIO_IRQ_GPIO |
| 1262 | reg |= WILC_HAVE_SDIO_IRQ_GPIO; |
| 1263 | #endif |
| 1264 | |
| 1265 | #ifdef WILC_DISABLE_PMU |
| 1266 | #else |
| 1267 | reg |= WILC_HAVE_USE_PMU; |
| 1268 | #endif |
| 1269 | |
| 1270 | #ifdef WILC_SLEEP_CLK_SRC_XO |
| 1271 | reg |= WILC_HAVE_SLEEP_CLK_SRC_XO; |
| 1272 | #elif defined WILC_SLEEP_CLK_SRC_RTC |
| 1273 | reg |= WILC_HAVE_SLEEP_CLK_SRC_RTC; |
| 1274 | #endif |
| 1275 | |
| 1276 | #ifdef WILC_EXT_PA_INV_TX_RX |
| 1277 | reg |= WILC_HAVE_EXT_PA_INV_TX_RX; |
| 1278 | #endif |
| 1279 | |
| 1280 | reg |= WILC_HAVE_LEGACY_RF_SETTINGS; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1281 | #ifdef XTAL_24 |
| 1282 | reg |= WILC_HAVE_XTAL_24; |
| 1283 | #endif |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1284 | #ifdef DISABLE_WILC_UART |
| 1285 | reg |= WILC_HAVE_DISABLE_WILC_UART; |
| 1286 | #endif |
| 1287 | |
| 1288 | ret = p->hif_func.hif_write_reg(WILC_GP_REG_1, reg); |
| 1289 | if (!ret) { |
| 1290 | wilc_debug(N_ERR, "[wilc start]: fail write WILC_GP_REG_1 ...\n"); |
| 1291 | release_bus(RELEASE_ONLY); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1292 | ret = -5; |
| 1293 | return ret; |
| 1294 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1295 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1296 | p->hif_func.hif_sync_ext(NUM_INT_EXT); |
| 1297 | |
| 1298 | ret = p->hif_func.hif_read_reg(0x1000, &chipid); |
| 1299 | if (!ret) { |
| 1300 | wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1000 ...\n"); |
| 1301 | release_bus(RELEASE_ONLY); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1302 | ret = -5; |
| 1303 | return ret; |
| 1304 | } |
| 1305 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1306 | p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®); |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 1307 | if ((reg & BIT(10)) == BIT(10)) { |
| 1308 | reg &= ~BIT(10); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1309 | p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); |
| 1310 | p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®); |
| 1311 | } |
| 1312 | |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 1313 | reg |= BIT(10); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1314 | ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); |
| 1315 | p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®); |
| 1316 | release_bus(RELEASE_ONLY); |
| 1317 | |
| 1318 | return (ret < 0) ? ret : 0; |
| 1319 | } |
| 1320 | |
| 1321 | void wilc_wlan_global_reset(void) |
| 1322 | { |
| 1323 | |
Shivani Bhardwaj | 7ee8291 | 2015-10-13 17:04:48 +0530 | [diff] [blame] | 1324 | wilc_wlan_dev_t *p = &g_wlan; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 1325 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1326 | acquire_bus(ACQUIRE_AND_WAKEUP); |
| 1327 | p->hif_func.hif_write_reg(WILC_GLB_RESET_0, 0x0); |
| 1328 | release_bus(RELEASE_ONLY); |
| 1329 | } |
Glen Lee | 8cec741 | 2015-10-01 16:03:34 +0900 | [diff] [blame] | 1330 | int wilc_wlan_stop(void) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1331 | { |
Shivani Bhardwaj | 7ee8291 | 2015-10-13 17:04:48 +0530 | [diff] [blame] | 1332 | wilc_wlan_dev_t *p = &g_wlan; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1333 | u32 reg = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1334 | int ret; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 1335 | u8 timeout = 10; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1336 | acquire_bus(ACQUIRE_AND_WAKEUP); |
| 1337 | |
| 1338 | ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®); |
| 1339 | if (!ret) { |
| 1340 | PRINT_ER("Error while reading reg\n"); |
| 1341 | release_bus(RELEASE_ALLOW_SLEEP); |
| 1342 | return ret; |
| 1343 | } |
| 1344 | |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 1345 | reg &= ~BIT(10); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1346 | ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); |
| 1347 | if (!ret) { |
| 1348 | PRINT_ER("Error while writing reg\n"); |
| 1349 | release_bus(RELEASE_ALLOW_SLEEP); |
| 1350 | return ret; |
| 1351 | } |
| 1352 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1353 | do { |
| 1354 | ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®); |
| 1355 | if (!ret) { |
| 1356 | PRINT_ER("Error while reading reg\n"); |
| 1357 | release_bus(RELEASE_ALLOW_SLEEP); |
| 1358 | return ret; |
| 1359 | } |
| 1360 | PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout); |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 1361 | |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 1362 | if ((reg & BIT(10))) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1363 | PRINT_D(GENERIC_DBG, "Bit 10 not reset : Retry %d\n", timeout); |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 1364 | reg &= ~BIT(10); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1365 | ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); |
| 1366 | timeout--; |
| 1367 | } else { |
| 1368 | PRINT_D(GENERIC_DBG, "Bit 10 reset after : Retry %d\n", timeout); |
| 1369 | ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®); |
| 1370 | if (!ret) { |
| 1371 | PRINT_ER("Error while reading reg\n"); |
| 1372 | release_bus(RELEASE_ALLOW_SLEEP); |
| 1373 | return ret; |
| 1374 | } |
| 1375 | PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout); |
| 1376 | break; |
| 1377 | } |
| 1378 | |
| 1379 | } while (timeout); |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 1380 | reg = (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(8) | BIT(9) | BIT(26) | |
| 1381 | BIT(29) | BIT(30) | BIT(31)); |
Anish Bhatt | 65ead4e | 2015-09-29 12:15:48 -0700 | [diff] [blame] | 1382 | |
| 1383 | p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 1384 | reg = (u32)~BIT(10); |
Anish Bhatt | 65ead4e | 2015-09-29 12:15:48 -0700 | [diff] [blame] | 1385 | |
| 1386 | ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1387 | |
| 1388 | release_bus(RELEASE_ALLOW_SLEEP); |
| 1389 | |
| 1390 | return ret; |
| 1391 | } |
| 1392 | |
Glen Lee | 2de7cbe | 2015-10-27 18:27:54 +0900 | [diff] [blame] | 1393 | void wilc_wlan_cleanup(struct net_device *dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1394 | { |
Shivani Bhardwaj | 7ee8291 | 2015-10-13 17:04:48 +0530 | [diff] [blame] | 1395 | wilc_wlan_dev_t *p = &g_wlan; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1396 | struct txq_entry_t *tqe; |
| 1397 | struct rxq_entry_t *rqe; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1398 | u32 reg = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1399 | int ret; |
Glen Lee | db38763 | 2015-10-27 18:27:55 +0900 | [diff] [blame] | 1400 | perInterface_wlan_t *nic; |
| 1401 | struct wilc *wilc; |
| 1402 | |
| 1403 | nic = netdev_priv(dev); |
| 1404 | wilc = nic->wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1405 | |
| 1406 | p->quit = 1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1407 | do { |
Glen Lee | 718fc2c | 2015-10-29 12:18:43 +0900 | [diff] [blame] | 1408 | tqe = wilc_wlan_txq_remove_from_head(dev); |
Leo Kim | a4b1719 | 2015-11-06 11:12:31 +0900 | [diff] [blame] | 1409 | if (!tqe) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1410 | break; |
| 1411 | if (tqe->tx_complete_func) |
| 1412 | tqe->tx_complete_func(tqe->priv, 0); |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 1413 | kfree(tqe); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1414 | } while (1); |
| 1415 | |
| 1416 | do { |
Glen Lee | db38763 | 2015-10-27 18:27:55 +0900 | [diff] [blame] | 1417 | rqe = wilc_wlan_rxq_remove(wilc); |
Leo Kim | a4b1719 | 2015-11-06 11:12:31 +0900 | [diff] [blame] | 1418 | if (!rqe) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1419 | break; |
Javier Martinez Canillas | 6a27224 | 2015-09-22 15:24:50 +0200 | [diff] [blame] | 1420 | #ifndef MEMORY_STATIC |
| 1421 | kfree(rqe->buffer); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1422 | #endif |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 1423 | kfree(rqe); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1424 | } while (1); |
| 1425 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1426 | #ifdef MEMORY_STATIC |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 1427 | kfree(p->rx_buffer); |
| 1428 | p->rx_buffer = NULL; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1429 | #endif |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 1430 | kfree(p->tx_buffer); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1431 | |
| 1432 | acquire_bus(ACQUIRE_AND_WAKEUP); |
| 1433 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1434 | ret = p->hif_func.hif_read_reg(WILC_GP_REG_0, ®); |
| 1435 | if (!ret) { |
| 1436 | PRINT_ER("Error while reading reg\n"); |
| 1437 | release_bus(RELEASE_ALLOW_SLEEP); |
| 1438 | } |
| 1439 | PRINT_ER("Writing ABORT reg\n"); |
| 1440 | ret = p->hif_func.hif_write_reg(WILC_GP_REG_0, (reg | ABORT_INT)); |
| 1441 | if (!ret) { |
| 1442 | PRINT_ER("Error while writing reg\n"); |
| 1443 | release_bus(RELEASE_ALLOW_SLEEP); |
| 1444 | } |
| 1445 | release_bus(RELEASE_ALLOW_SLEEP); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1446 | p->hif_func.hif_deinit(NULL); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1447 | } |
| 1448 | |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1449 | static int wilc_wlan_cfg_commit(int type, u32 drvHandler) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1450 | { |
Shivani Bhardwaj | 7ee8291 | 2015-10-13 17:04:48 +0530 | [diff] [blame] | 1451 | wilc_wlan_dev_t *p = &g_wlan; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1452 | wilc_cfg_frame_t *cfg = &p->cfg_frame; |
| 1453 | int total_len = p->cfg_frame_offset + 4 + DRIVER_HANDLER_SIZE; |
| 1454 | int seq_no = p->cfg_seq_no % 256; |
Chaehyun Lim | 4e4467f | 2015-06-11 14:35:55 +0900 | [diff] [blame] | 1455 | int driver_handler = (u32)drvHandler; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1456 | |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 1457 | if (type == WILC_CFG_SET) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1458 | cfg->wid_header[0] = 'W'; |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 1459 | } else { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1460 | cfg->wid_header[0] = 'Q'; |
| 1461 | } |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 1462 | cfg->wid_header[1] = seq_no; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 1463 | cfg->wid_header[2] = (u8)total_len; |
| 1464 | cfg->wid_header[3] = (u8)(total_len >> 8); |
| 1465 | cfg->wid_header[4] = (u8)driver_handler; |
| 1466 | cfg->wid_header[5] = (u8)(driver_handler >> 8); |
| 1467 | cfg->wid_header[6] = (u8)(driver_handler >> 16); |
| 1468 | cfg->wid_header[7] = (u8)(driver_handler >> 24); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1469 | p->cfg_seq_no = seq_no; |
| 1470 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1471 | if (!wilc_wlan_txq_add_cfg_pkt(&cfg->wid_header[0], total_len)) |
| 1472 | return -1; |
| 1473 | |
| 1474 | return 0; |
| 1475 | } |
| 1476 | |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 1477 | int wilc_wlan_cfg_set(int start, u32 wid, u8 *buffer, u32 buffer_size, |
| 1478 | int commit, u32 drvHandler) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1479 | { |
Shivani Bhardwaj | 7ee8291 | 2015-10-13 17:04:48 +0530 | [diff] [blame] | 1480 | wilc_wlan_dev_t *p = &g_wlan; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1481 | u32 offset; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1482 | int ret_size; |
| 1483 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1484 | if (p->cfg_frame_in_use) |
| 1485 | return 0; |
| 1486 | |
| 1487 | if (start) |
| 1488 | p->cfg_frame_offset = 0; |
| 1489 | |
| 1490 | offset = p->cfg_frame_offset; |
Glen Lee | 17e8f16 | 2015-10-02 14:22:07 +0900 | [diff] [blame] | 1491 | ret_size = wilc_wlan_cfg_set_wid(p->cfg_frame.frame, offset, (u16)wid, |
| 1492 | buffer, buffer_size); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1493 | offset += ret_size; |
| 1494 | p->cfg_frame_offset = offset; |
| 1495 | |
| 1496 | if (commit) { |
| 1497 | PRINT_D(TX_DBG, "[WILC]PACKET Commit with sequence number %d\n", p->cfg_seq_no); |
| 1498 | PRINT_D(RX_DBG, "Processing cfg_set()\n"); |
| 1499 | p->cfg_frame_in_use = 1; |
| 1500 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1501 | if (wilc_wlan_cfg_commit(WILC_CFG_SET, drvHandler)) |
Chaehyun Lim | 5af6b85 | 2015-09-17 16:48:48 +0900 | [diff] [blame] | 1502 | ret_size = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1503 | |
Glen Lee | b002e20 | 2015-09-24 18:15:05 +0900 | [diff] [blame] | 1504 | if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event, |
| 1505 | CFG_PKTS_TIMEOUT)) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1506 | PRINT_D(TX_DBG, "Set Timed Out\n"); |
| 1507 | ret_size = 0; |
| 1508 | } |
| 1509 | p->cfg_frame_in_use = 0; |
| 1510 | p->cfg_frame_offset = 0; |
| 1511 | p->cfg_seq_no += 1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | return ret_size; |
| 1515 | } |
Leo Kim | 2d6973e | 2015-11-06 11:12:28 +0900 | [diff] [blame] | 1516 | |
Glen Lee | 07056a8 | 2015-10-01 16:03:41 +0900 | [diff] [blame] | 1517 | 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] | 1518 | { |
Shivani Bhardwaj | 7ee8291 | 2015-10-13 17:04:48 +0530 | [diff] [blame] | 1519 | wilc_wlan_dev_t *p = &g_wlan; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1520 | u32 offset; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1521 | int ret_size; |
| 1522 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1523 | if (p->cfg_frame_in_use) |
| 1524 | return 0; |
| 1525 | |
| 1526 | if (start) |
| 1527 | p->cfg_frame_offset = 0; |
| 1528 | |
| 1529 | offset = p->cfg_frame_offset; |
Glen Lee | ec1b86b | 2015-10-02 14:22:08 +0900 | [diff] [blame] | 1530 | 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] | 1531 | offset += ret_size; |
| 1532 | p->cfg_frame_offset = offset; |
| 1533 | |
| 1534 | if (commit) { |
| 1535 | p->cfg_frame_in_use = 1; |
| 1536 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1537 | if (wilc_wlan_cfg_commit(WILC_CFG_QUERY, drvHandler)) |
Chaehyun Lim | 5af6b85 | 2015-09-17 16:48:48 +0900 | [diff] [blame] | 1538 | ret_size = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1539 | |
Glen Lee | b002e20 | 2015-09-24 18:15:05 +0900 | [diff] [blame] | 1540 | if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event, |
| 1541 | CFG_PKTS_TIMEOUT)) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1542 | PRINT_D(TX_DBG, "Get Timed Out\n"); |
| 1543 | ret_size = 0; |
| 1544 | } |
| 1545 | PRINT_D(GENERIC_DBG, "[WILC]Get Response received\n"); |
| 1546 | p->cfg_frame_in_use = 0; |
| 1547 | p->cfg_frame_offset = 0; |
| 1548 | p->cfg_seq_no += 1; |
| 1549 | } |
| 1550 | |
| 1551 | return ret_size; |
| 1552 | } |
| 1553 | |
Glen Lee | 894de36b | 2015-10-01 16:03:42 +0900 | [diff] [blame] | 1554 | 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] | 1555 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1556 | int ret; |
| 1557 | |
Glen Lee | 355cca2 | 2015-10-02 14:22:09 +0900 | [diff] [blame] | 1558 | ret = wilc_wlan_cfg_get_wid_value((u16)wid, buffer, buffer_size); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1559 | |
| 1560 | return ret; |
| 1561 | } |
| 1562 | |
| 1563 | void wilc_bus_set_max_speed(void) |
| 1564 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1565 | g_wlan.hif_func.hif_set_max_bus_speed(); |
| 1566 | } |
| 1567 | |
| 1568 | void wilc_bus_set_default_speed(void) |
| 1569 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1570 | g_wlan.hif_func.hif_set_default_bus_speed(); |
| 1571 | } |
Leo Kim | 2d6973e | 2015-11-06 11:12:28 +0900 | [diff] [blame] | 1572 | |
Glen Lee | ae6f772 | 2015-10-29 12:18:48 +0900 | [diff] [blame] | 1573 | u32 init_chip(struct net_device *dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1574 | { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1575 | u32 chipid; |
| 1576 | u32 reg, ret = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1577 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1578 | acquire_bus(ACQUIRE_ONLY); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1579 | |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 1580 | chipid = wilc_get_chipid(true); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1581 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1582 | if ((chipid & 0xfff) != 0xa0) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1583 | ret = g_wlan.hif_func.hif_read_reg(0x1118, ®); |
| 1584 | if (!ret) { |
| 1585 | wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1118 ...\n"); |
| 1586 | return ret; |
| 1587 | } |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 1588 | reg |= BIT(0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1589 | ret = g_wlan.hif_func.hif_write_reg(0x1118, reg); |
| 1590 | if (!ret) { |
| 1591 | wilc_debug(N_ERR, "[wilc start]: fail write reg 0x1118 ...\n"); |
| 1592 | return ret; |
| 1593 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1594 | ret = g_wlan.hif_func.hif_write_reg(0xc0000, 0x71); |
| 1595 | if (!ret) { |
| 1596 | wilc_debug(N_ERR, "[wilc start]: fail write reg 0xc0000 ...\n"); |
| 1597 | return ret; |
| 1598 | } |
| 1599 | } |
| 1600 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1601 | release_bus(RELEASE_ONLY); |
| 1602 | |
| 1603 | return ret; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1604 | } |
| 1605 | |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1606 | u32 wilc_get_chipid(u8 update) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1607 | { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1608 | static u32 chipid; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1609 | u32 tempchipid = 0; |
| 1610 | u32 rfrevid; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1611 | |
| 1612 | if (chipid == 0 || update != 0) { |
| 1613 | g_wlan.hif_func.hif_read_reg(0x1000, &tempchipid); |
| 1614 | g_wlan.hif_func.hif_read_reg(0x13f4, &rfrevid); |
| 1615 | if (!ISWILC1000(tempchipid)) { |
| 1616 | chipid = 0; |
| 1617 | goto _fail_; |
| 1618 | } |
| 1619 | if (tempchipid == 0x1002a0) { |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 1620 | if (rfrevid == 0x1) { |
| 1621 | } else { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1622 | tempchipid = 0x1002a1; |
| 1623 | } |
| 1624 | } else if (tempchipid == 0x1002b0) { |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 1625 | if (rfrevid == 3) { |
| 1626 | } else if (rfrevid == 4) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1627 | tempchipid = 0x1002b1; |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 1628 | } else { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1629 | tempchipid = 0x1002b2; |
| 1630 | } |
| 1631 | } else { |
| 1632 | } |
| 1633 | |
| 1634 | chipid = tempchipid; |
| 1635 | } |
| 1636 | _fail_: |
| 1637 | return chipid; |
| 1638 | } |
| 1639 | |
Glen Lee | 47a466f | 2015-10-29 12:18:47 +0900 | [diff] [blame] | 1640 | int wilc_wlan_init(struct net_device *dev, wilc_wlan_inp_t *inp) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1641 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1642 | int ret = 0; |
| 1643 | |
| 1644 | PRINT_D(INIT_DBG, "Initializing WILC_Wlan ...\n"); |
| 1645 | |
| 1646 | memset((void *)&g_wlan, 0, sizeof(wilc_wlan_dev_t)); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1647 | memcpy((void *)&g_wlan.io_func, (void *)&inp->io_func, sizeof(wilc_wlan_io_func_t)); |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 1648 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1649 | if ((inp->io_func.io_type & 0x1) == HIF_SDIO) { |
| 1650 | if (!hif_sdio.hif_init(inp, wilc_debug)) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1651 | ret = -5; |
| 1652 | goto _fail_; |
| 1653 | } |
| 1654 | memcpy((void *)&g_wlan.hif_func, &hif_sdio, sizeof(wilc_hif_func_t)); |
| 1655 | } else { |
| 1656 | if ((inp->io_func.io_type & 0x1) == HIF_SPI) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1657 | if (!hif_spi.hif_init(inp, wilc_debug)) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1658 | ret = -5; |
| 1659 | goto _fail_; |
| 1660 | } |
| 1661 | memcpy((void *)&g_wlan.hif_func, &hif_spi, sizeof(wilc_hif_func_t)); |
| 1662 | } else { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1663 | ret = -5; |
| 1664 | goto _fail_; |
| 1665 | } |
| 1666 | } |
| 1667 | |
Glen Lee | 814bc36 | 2015-10-02 14:22:11 +0900 | [diff] [blame] | 1668 | if (!wilc_wlan_cfg_init(wilc_debug)) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1669 | ret = -105; |
| 1670 | goto _fail_; |
| 1671 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1672 | |
Leo Kim | a4b1719 | 2015-11-06 11:12:31 +0900 | [diff] [blame] | 1673 | if (!g_wlan.tx_buffer) |
Glen Lee | 7015b5d | 2015-09-24 18:15:02 +0900 | [diff] [blame] | 1674 | g_wlan.tx_buffer = kmalloc(LINUX_TX_SIZE, GFP_KERNEL); |
Arnd Bergmann | 7a8fd84 | 2015-06-01 21:06:45 +0200 | [diff] [blame] | 1675 | 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] | 1676 | |
Leo Kim | a4b1719 | 2015-11-06 11:12:31 +0900 | [diff] [blame] | 1677 | if (!g_wlan.tx_buffer) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1678 | ret = -105; |
| 1679 | PRINT_ER("Can't allocate Tx Buffer"); |
| 1680 | goto _fail_; |
| 1681 | } |
| 1682 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1683 | #if defined (MEMORY_STATIC) |
Leo Kim | a4b1719 | 2015-11-06 11:12:31 +0900 | [diff] [blame] | 1684 | if (!g_wlan.rx_buffer) |
Glen Lee | 03eb726 | 2015-09-24 18:15:03 +0900 | [diff] [blame] | 1685 | g_wlan.rx_buffer = kmalloc(LINUX_RX_SIZE, GFP_KERNEL); |
Arnd Bergmann | 7a8fd84 | 2015-06-01 21:06:45 +0200 | [diff] [blame] | 1686 | PRINT_D(TX_DBG, "g_wlan.rx_buffer =%p\n", g_wlan.rx_buffer); |
Leo Kim | a4b1719 | 2015-11-06 11:12:31 +0900 | [diff] [blame] | 1687 | if (!g_wlan.rx_buffer) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1688 | ret = -105; |
| 1689 | PRINT_ER("Can't allocate Rx Buffer"); |
| 1690 | goto _fail_; |
| 1691 | } |
| 1692 | #endif |
| 1693 | |
Glen Lee | ae6f772 | 2015-10-29 12:18:48 +0900 | [diff] [blame] | 1694 | if (!init_chip(dev)) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1695 | ret = -5; |
| 1696 | goto _fail_; |
| 1697 | } |
| 1698 | #ifdef TCP_ACK_FILTER |
| 1699 | Init_TCP_tracking(); |
| 1700 | #endif |
| 1701 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1702 | return 1; |
| 1703 | |
| 1704 | _fail_: |
| 1705 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1706 | #ifdef MEMORY_STATIC |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 1707 | kfree(g_wlan.rx_buffer); |
| 1708 | g_wlan.rx_buffer = NULL; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1709 | #endif |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 1710 | kfree(g_wlan.tx_buffer); |
| 1711 | g_wlan.tx_buffer = NULL; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1712 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1713 | return ret; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1714 | } |
| 1715 | |
Leo Kim | 2ad8c47 | 2015-11-05 14:36:35 +0900 | [diff] [blame] | 1716 | u16 set_machw_change_vir_if(struct net_device *dev, bool bValue) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1717 | { |
Chaehyun Lim | d85f532 | 2015-06-11 14:35:54 +0900 | [diff] [blame] | 1718 | u16 ret; |
Chaehyun Lim | 4e4467f | 2015-06-11 14:35:55 +0900 | [diff] [blame] | 1719 | u32 reg; |
Glen Lee | 178c383 | 2015-10-27 18:27:58 +0900 | [diff] [blame] | 1720 | perInterface_wlan_t *nic; |
| 1721 | struct wilc *wilc; |
| 1722 | |
| 1723 | nic = netdev_priv(dev); |
| 1724 | wilc = nic->wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1725 | |
Glen Lee | 178c383 | 2015-10-27 18:27:58 +0900 | [diff] [blame] | 1726 | mutex_lock(&wilc->hif_cs); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1727 | ret = (&g_wlan)->hif_func.hif_read_reg(WILC_CHANGING_VIR_IF, ®); |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 1728 | if (!ret) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1729 | PRINT_ER("Error while Reading reg WILC_CHANGING_VIR_IF\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1730 | |
Chandra S Gorentla | 78174ad | 2015-08-08 17:41:36 +0530 | [diff] [blame] | 1731 | if (bValue) |
Chaehyun Lim | 50b51da | 2015-09-16 20:11:26 +0900 | [diff] [blame] | 1732 | reg |= BIT(31); |
Chandra S Gorentla | 78174ad | 2015-08-08 17:41:36 +0530 | [diff] [blame] | 1733 | else |
Chaehyun Lim | 50b51da | 2015-09-16 20:11:26 +0900 | [diff] [blame] | 1734 | reg &= ~BIT(31); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1735 | |
| 1736 | ret = (&g_wlan)->hif_func.hif_write_reg(WILC_CHANGING_VIR_IF, reg); |
| 1737 | |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 1738 | if (!ret) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1739 | PRINT_ER("Error while writing reg WILC_CHANGING_VIR_IF\n"); |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 1740 | |
Glen Lee | 178c383 | 2015-10-27 18:27:58 +0900 | [diff] [blame] | 1741 | mutex_unlock(&wilc->hif_cs); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1742 | |
| 1743 | return ret; |
| 1744 | } |