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