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