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