Binoy Jayan | b27a6d5 | 2016-06-15 11:00:34 +0530 | [diff] [blame] | 1 | #include <linux/completion.h> |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 2 | #include "wilc_wlan_if.h" |
Arnd Bergmann | 491880e | 2015-11-16 15:04:55 +0100 | [diff] [blame] | 3 | #include "wilc_wlan.h" |
Tony Cho | 60bd100 | 2015-10-12 16:56:04 +0900 | [diff] [blame] | 4 | #include "wilc_wfi_netdevice.h" |
Glen Lee | 17e8f16 | 2015-10-02 14:22:07 +0900 | [diff] [blame] | 5 | #include "wilc_wlan_cfg.h" |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 6 | |
Leo Kim | b7d1e18 | 2015-11-06 11:12:30 +0900 | [diff] [blame] | 7 | static CHIP_PS_STATE_T chip_ps_state = CHIP_WAKEDUP; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 8 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 9 | static inline void acquire_bus(struct wilc *wilc, BUS_ACQUIRE_T acquire) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 10 | { |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 11 | mutex_lock(&wilc->hif_cs); |
Glen Lee | 33c6497 | 2016-01-25 16:35:06 +0900 | [diff] [blame] | 12 | if (acquire == ACQUIRE_AND_WAKEUP) |
| 13 | chip_wakeup(wilc); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 14 | } |
Leo Kim | 2d6973e | 2015-11-06 11:12:28 +0900 | [diff] [blame] | 15 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 16 | static inline void release_bus(struct wilc *wilc, BUS_RELEASE_T release) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 17 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 18 | if (release == RELEASE_ALLOW_SLEEP) |
Glen Lee | 00215dd | 2015-11-18 15:11:25 +0900 | [diff] [blame] | 19 | chip_allow_sleep(wilc); |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 20 | mutex_unlock(&wilc->hif_cs); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 21 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 22 | |
Glen Lee | e9576e9 | 2016-02-04 18:15:23 +0900 | [diff] [blame] | 23 | static void wilc_wlan_txq_remove(struct wilc *wilc, struct txq_entry_t *tqe) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 24 | { |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 25 | if (tqe == wilc->txq_head) { |
| 26 | wilc->txq_head = tqe->next; |
| 27 | if (wilc->txq_head) |
| 28 | wilc->txq_head->prev = NULL; |
| 29 | } else if (tqe == wilc->txq_tail) { |
| 30 | wilc->txq_tail = (tqe->prev); |
| 31 | if (wilc->txq_tail) |
| 32 | wilc->txq_tail->next = NULL; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 33 | } else { |
| 34 | tqe->prev->next = tqe->next; |
| 35 | tqe->next->prev = tqe->prev; |
| 36 | } |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 37 | wilc->txq_entries -= 1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 38 | } |
| 39 | |
Glen Lee | 718fc2c | 2015-10-29 12:18:43 +0900 | [diff] [blame] | 40 | static struct txq_entry_t * |
| 41 | wilc_wlan_txq_remove_from_head(struct net_device *dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 42 | { |
| 43 | struct txq_entry_t *tqe; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 44 | unsigned long flags; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 45 | struct wilc_vif *vif; |
Glen Lee | 718fc2c | 2015-10-29 12:18:43 +0900 | [diff] [blame] | 46 | struct wilc *wilc; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 47 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 48 | vif = netdev_priv(dev); |
| 49 | wilc = vif->wilc; |
Glen Lee | 718fc2c | 2015-10-29 12:18:43 +0900 | [diff] [blame] | 50 | |
| 51 | spin_lock_irqsave(&wilc->txq_spinlock, flags); |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 52 | if (wilc->txq_head) { |
| 53 | tqe = wilc->txq_head; |
| 54 | wilc->txq_head = tqe->next; |
| 55 | if (wilc->txq_head) |
| 56 | wilc->txq_head->prev = NULL; |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 57 | |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 58 | wilc->txq_entries -= 1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 59 | } else { |
| 60 | tqe = NULL; |
| 61 | } |
Glen Lee | 718fc2c | 2015-10-29 12:18:43 +0900 | [diff] [blame] | 62 | spin_unlock_irqrestore(&wilc->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 63 | return tqe; |
| 64 | } |
| 65 | |
Glen Lee | 32f0332 | 2015-10-29 12:18:45 +0900 | [diff] [blame] | 66 | static void wilc_wlan_txq_add_to_tail(struct net_device *dev, |
| 67 | struct txq_entry_t *tqe) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 68 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 69 | unsigned long flags; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 70 | struct wilc_vif *vif; |
Glen Lee | 32f0332 | 2015-10-29 12:18:45 +0900 | [diff] [blame] | 71 | struct wilc *wilc; |
| 72 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 73 | vif = netdev_priv(dev); |
| 74 | wilc = vif->wilc; |
Glen Lee | 32f0332 | 2015-10-29 12:18:45 +0900 | [diff] [blame] | 75 | |
| 76 | spin_lock_irqsave(&wilc->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 77 | |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 78 | if (!wilc->txq_head) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 79 | tqe->next = NULL; |
| 80 | tqe->prev = NULL; |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 81 | wilc->txq_head = tqe; |
| 82 | wilc->txq_tail = tqe; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 83 | } else { |
| 84 | tqe->next = NULL; |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 85 | tqe->prev = wilc->txq_tail; |
| 86 | wilc->txq_tail->next = tqe; |
| 87 | wilc->txq_tail = tqe; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 88 | } |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 89 | wilc->txq_entries += 1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 90 | |
Glen Lee | 32f0332 | 2015-10-29 12:18:45 +0900 | [diff] [blame] | 91 | spin_unlock_irqrestore(&wilc->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 92 | |
Binoy Jayan | b27a6d5 | 2016-06-15 11:00:34 +0530 | [diff] [blame] | 93 | complete(&wilc->txq_event); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 94 | } |
| 95 | |
Chris Park | 4d38a56 | 2016-02-04 18:15:49 +0900 | [diff] [blame] | 96 | static int wilc_wlan_txq_add_to_head(struct wilc_vif *vif, |
| 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 | 79df6a4 | 2016-02-04 18:15:31 +0900 | [diff] [blame] | 100 | struct wilc *wilc = vif->wilc; |
| 101 | |
Binoy Jayan | 334bed0 | 2016-06-15 11:00:35 +0530 | [diff] [blame] | 102 | mutex_lock(&wilc->txq_add_to_head_cs); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 103 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 104 | spin_lock_irqsave(&wilc->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 105 | |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 106 | if (!wilc->txq_head) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 107 | tqe->next = NULL; |
| 108 | tqe->prev = NULL; |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 109 | wilc->txq_head = tqe; |
| 110 | wilc->txq_tail = tqe; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 111 | } else { |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 112 | tqe->next = wilc->txq_head; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 113 | tqe->prev = NULL; |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 114 | wilc->txq_head->prev = tqe; |
| 115 | wilc->txq_head = tqe; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 116 | } |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 117 | wilc->txq_entries += 1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 118 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 119 | spin_unlock_irqrestore(&wilc->txq_spinlock, flags); |
Binoy Jayan | 334bed0 | 2016-06-15 11:00:35 +0530 | [diff] [blame] | 120 | mutex_unlock(&wilc->txq_add_to_head_cs); |
Binoy Jayan | b27a6d5 | 2016-06-15 11:00:34 +0530 | [diff] [blame] | 121 | complete(&wilc->txq_event); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 122 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 123 | return 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 124 | } |
| 125 | |
Leo Kim | 130a41f | 2015-11-06 11:12:34 +0900 | [diff] [blame] | 126 | struct ack_session_info; |
| 127 | struct ack_session_info { |
Leo Kim | d06b6cb | 2015-11-06 11:12:35 +0900 | [diff] [blame] | 128 | u32 seq_num; |
Leo Kim | 9d54d3d | 2015-11-06 11:12:36 +0900 | [diff] [blame] | 129 | u32 bigger_ack_num; |
Chaehyun Lim | ec53adf | 2015-09-15 14:06:15 +0900 | [diff] [blame] | 130 | u16 src_port; |
| 131 | u16 dst_port; |
| 132 | u16 status; |
Shraddha Barke | eeb1c06 | 2015-08-05 01:29:22 +0530 | [diff] [blame] | 133 | }; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 134 | |
Leo Kim | 08b90b1 | 2015-11-06 11:12:37 +0900 | [diff] [blame] | 135 | struct pending_acks_info { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 136 | u32 ack_num; |
Leo Kim | 8413697 | 2015-11-06 11:12:38 +0900 | [diff] [blame] | 137 | u32 session_index; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 138 | struct txq_entry_t *txqe; |
Leo Kim | 08b90b1 | 2015-11-06 11:12:37 +0900 | [diff] [blame] | 139 | }; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 140 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 141 | #define NOT_TCP_ACK (-1) |
| 142 | |
| 143 | #define MAX_TCP_SESSION 25 |
| 144 | #define MAX_PENDING_ACKS 256 |
Arnd Bergmann | 1608c40 | 2015-11-16 15:04:53 +0100 | [diff] [blame] | 145 | static struct ack_session_info ack_session_info[2 * MAX_TCP_SESSION]; |
| 146 | static struct pending_acks_info pending_acks_info[MAX_PENDING_ACKS]; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 147 | |
Arnd Bergmann | 1608c40 | 2015-11-16 15:04:53 +0100 | [diff] [blame] | 148 | static u32 pending_base; |
| 149 | static u32 tcp_session; |
| 150 | static u32 pending_acks; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 151 | |
Leo Kim | 6762078 | 2015-11-06 11:12:45 +0900 | [diff] [blame] | 152 | 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] | 153 | { |
Glen Lee | 4fd6229 | 2016-02-04 18:15:24 +0900 | [diff] [blame] | 154 | if (tcp_session < 2 * MAX_TCP_SESSION) { |
| 155 | ack_session_info[tcp_session].seq_num = seq; |
| 156 | ack_session_info[tcp_session].bigger_ack_num = 0; |
| 157 | ack_session_info[tcp_session].src_port = src_prt; |
| 158 | ack_session_info[tcp_session].dst_port = dst_prt; |
| 159 | tcp_session++; |
| 160 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 161 | return 0; |
| 162 | } |
| 163 | |
Leo Kim | b801a96 | 2015-11-06 11:12:48 +0900 | [diff] [blame] | 164 | static inline int update_tcp_session(u32 index, u32 ack) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 165 | { |
Glen Lee | 4fd6229 | 2016-02-04 18:15:24 +0900 | [diff] [blame] | 166 | if (index < 2 * MAX_TCP_SESSION && |
| 167 | ack > ack_session_info[index].bigger_ack_num) |
Leo Kim | b801a96 | 2015-11-06 11:12:48 +0900 | [diff] [blame] | 168 | ack_session_info[index].bigger_ack_num = ack; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 169 | return 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 170 | } |
Leo Kim | 2d6973e | 2015-11-06 11:12:28 +0900 | [diff] [blame] | 171 | |
Leo Kim | ea03f57 | 2015-11-06 11:12:49 +0900 | [diff] [blame] | 172 | static inline int add_tcp_pending_ack(u32 ack, u32 session_index, |
Leo Kim | 66a43a9 | 2015-11-06 11:19:50 +0900 | [diff] [blame] | 173 | struct txq_entry_t *txqe) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 174 | { |
Glen Lee | 4fd6229 | 2016-02-04 18:15:24 +0900 | [diff] [blame] | 175 | if (pending_base + pending_acks < MAX_PENDING_ACKS) { |
Leo Kim | b801a96 | 2015-11-06 11:12:48 +0900 | [diff] [blame] | 176 | pending_acks_info[pending_base + pending_acks].ack_num = ack; |
Leo Kim | d12ac7e | 2015-11-06 11:12:43 +0900 | [diff] [blame] | 177 | pending_acks_info[pending_base + pending_acks].txqe = txqe; |
Leo Kim | ea03f57 | 2015-11-06 11:12:49 +0900 | [diff] [blame] | 178 | pending_acks_info[pending_base + pending_acks].session_index = session_index; |
Glen Lee | b719302 | 2015-12-21 14:18:07 +0900 | [diff] [blame] | 179 | txqe->tcp_pending_ack_idx = pending_base + pending_acks; |
Leo Kim | d12ac7e | 2015-11-06 11:12:43 +0900 | [diff] [blame] | 180 | pending_acks++; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 181 | } |
| 182 | return 0; |
| 183 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 184 | |
Janani Ravichandran | aae9620 | 2016-02-16 14:07:00 -0500 | [diff] [blame] | 185 | static inline void tcp_process(struct net_device *dev, struct txq_entry_t *tqe) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 186 | { |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 187 | u8 *eth_hdr_ptr; |
| 188 | u8 *buffer = tqe->buffer; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 189 | unsigned short h_proto; |
| 190 | int i; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 191 | unsigned long flags; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 192 | struct wilc_vif *vif; |
Glen Lee | 82bb18e | 2015-10-27 18:28:03 +0900 | [diff] [blame] | 193 | struct wilc *wilc; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 194 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 195 | vif = netdev_priv(dev); |
| 196 | wilc = vif->wilc; |
Glen Lee | 82bb18e | 2015-10-27 18:28:03 +0900 | [diff] [blame] | 197 | |
Glen Lee | c6866cc | 2016-02-04 18:15:22 +0900 | [diff] [blame] | 198 | spin_lock_irqsave(&wilc->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 199 | |
| 200 | eth_hdr_ptr = &buffer[0]; |
| 201 | h_proto = ntohs(*((unsigned short *)ð_hdr_ptr[12])); |
Hari Prasath Gujulan Elango | a045618 | 2015-12-22 11:44:43 +0000 | [diff] [blame] | 202 | if (h_proto == ETH_P_IP) { |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 203 | u8 *ip_hdr_ptr; |
| 204 | u8 protocol; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 205 | |
| 206 | ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN]; |
| 207 | protocol = ip_hdr_ptr[9]; |
| 208 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 209 | if (protocol == 0x06) { |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 210 | u8 *tcp_hdr_ptr; |
Leo Kim | 51bffa9 | 2015-11-06 11:12:52 +0900 | [diff] [blame] | 211 | u32 IHL, total_length, data_offset; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 212 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 213 | tcp_hdr_ptr = &ip_hdr_ptr[IP_HDR_LEN]; |
| 214 | IHL = (ip_hdr_ptr[0] & 0xf) << 2; |
Leo Kim | 24e2dac | 2015-11-06 11:12:51 +0900 | [diff] [blame] | 215 | total_length = ((u32)ip_hdr_ptr[2] << 8) + |
| 216 | (u32)ip_hdr_ptr[3]; |
Leo Kim | 51bffa9 | 2015-11-06 11:12:52 +0900 | [diff] [blame] | 217 | data_offset = ((u32)tcp_hdr_ptr[12] & 0xf0) >> 2; |
| 218 | if (total_length == (IHL + data_offset)) { |
Leo Kim | f91c5d7 | 2015-11-06 11:12:53 +0900 | [diff] [blame] | 219 | u32 seq_no, ack_no; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 220 | |
Leo Kim | 4478c62 | 2015-11-06 11:12:54 +0900 | [diff] [blame] | 221 | seq_no = ((u32)tcp_hdr_ptr[4] << 24) + |
| 222 | ((u32)tcp_hdr_ptr[5] << 16) + |
| 223 | ((u32)tcp_hdr_ptr[6] << 8) + |
| 224 | (u32)tcp_hdr_ptr[7]; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 225 | |
Leo Kim | f91c5d7 | 2015-11-06 11:12:53 +0900 | [diff] [blame] | 226 | ack_no = ((u32)tcp_hdr_ptr[8] << 24) + |
| 227 | ((u32)tcp_hdr_ptr[9] << 16) + |
| 228 | ((u32)tcp_hdr_ptr[10] << 8) + |
| 229 | (u32)tcp_hdr_ptr[11]; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 230 | |
Leo Kim | 3056ec3 | 2015-11-06 11:12:42 +0900 | [diff] [blame] | 231 | for (i = 0; i < tcp_session; i++) { |
Glen Lee | 4fd6229 | 2016-02-04 18:15:24 +0900 | [diff] [blame] | 232 | if (i < 2 * MAX_TCP_SESSION && |
| 233 | ack_session_info[i].seq_num == seq_no) { |
Leo Kim | f91c5d7 | 2015-11-06 11:12:53 +0900 | [diff] [blame] | 234 | update_tcp_session(i, ack_no); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 235 | break; |
| 236 | } |
| 237 | } |
Leo Kim | 3056ec3 | 2015-11-06 11:12:42 +0900 | [diff] [blame] | 238 | if (i == tcp_session) |
Leo Kim | 6762078 | 2015-11-06 11:12:45 +0900 | [diff] [blame] | 239 | add_tcp_session(0, 0, seq_no); |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 240 | |
Leo Kim | f91c5d7 | 2015-11-06 11:12:53 +0900 | [diff] [blame] | 241 | add_tcp_pending_ack(ack_no, i, tqe); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 242 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 243 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 244 | } |
Glen Lee | 82bb18e | 2015-10-27 18:28:03 +0900 | [diff] [blame] | 245 | spin_unlock_irqrestore(&wilc->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 246 | } |
| 247 | |
Glen Lee | c029e99 | 2015-10-27 18:27:48 +0900 | [diff] [blame] | 248 | 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] | 249 | { |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 250 | struct wilc_vif *vif; |
Glen Lee | c029e99 | 2015-10-27 18:27:48 +0900 | [diff] [blame] | 251 | struct wilc *wilc; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 252 | u32 i = 0; |
Leo Kim | 442eda4 | 2015-11-06 11:12:55 +0900 | [diff] [blame] | 253 | u32 dropped = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 254 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 255 | vif = netdev_priv(dev); |
| 256 | wilc = vif->wilc; |
Glen Lee | c029e99 | 2015-10-27 18:27:48 +0900 | [diff] [blame] | 257 | |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 258 | spin_lock_irqsave(&wilc->txq_spinlock, wilc->txq_spinlock_flags); |
Leo Kim | d12ac7e | 2015-11-06 11:12:43 +0900 | [diff] [blame] | 259 | for (i = pending_base; i < (pending_base + pending_acks); i++) { |
Glen Lee | 4fd6229 | 2016-02-04 18:15:24 +0900 | [diff] [blame] | 260 | if (i >= MAX_PENDING_ACKS || |
| 261 | pending_acks_info[i].session_index >= 2 * MAX_TCP_SESSION) |
| 262 | break; |
Leo Kim | 2bb1708 | 2015-11-06 11:12:40 +0900 | [diff] [blame] | 263 | 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] | 264 | struct txq_entry_t *tqe; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 265 | |
Leo Kim | 2bb1708 | 2015-11-06 11:12:40 +0900 | [diff] [blame] | 266 | tqe = pending_acks_info[i].txqe; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 267 | if (tqe) { |
Glen Lee | e9576e9 | 2016-02-04 18:15:23 +0900 | [diff] [blame] | 268 | wilc_wlan_txq_remove(wilc, tqe); |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 269 | tqe->status = 1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 270 | if (tqe->tx_complete_func) |
Leo Kim | ab12d8c | 2015-11-06 11:19:54 +0900 | [diff] [blame] | 271 | tqe->tx_complete_func(tqe->priv, |
| 272 | tqe->status); |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 273 | kfree(tqe); |
Leo Kim | 442eda4 | 2015-11-06 11:12:55 +0900 | [diff] [blame] | 274 | dropped++; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 275 | } |
| 276 | } |
| 277 | } |
Leo Kim | d12ac7e | 2015-11-06 11:12:43 +0900 | [diff] [blame] | 278 | pending_acks = 0; |
Leo Kim | 3056ec3 | 2015-11-06 11:12:42 +0900 | [diff] [blame] | 279 | tcp_session = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 280 | |
Leo Kim | 2ae91ed | 2015-11-06 11:12:41 +0900 | [diff] [blame] | 281 | if (pending_base == 0) |
| 282 | pending_base = MAX_TCP_SESSION; |
Chandra S Gorentla | 78174ad | 2015-08-08 17:41:36 +0530 | [diff] [blame] | 283 | else |
Leo Kim | 2ae91ed | 2015-11-06 11:12:41 +0900 | [diff] [blame] | 284 | pending_base = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 285 | |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 286 | spin_unlock_irqrestore(&wilc->txq_spinlock, wilc->txq_spinlock_flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 287 | |
Leo Kim | 442eda4 | 2015-11-06 11:12:55 +0900 | [diff] [blame] | 288 | while (dropped > 0) { |
Binoy Jayan | b27a6d5 | 2016-06-15 11:00:34 +0530 | [diff] [blame] | 289 | wait_for_completion_timeout(&wilc->txq_event, |
| 290 | msecs_to_jiffies(1)); |
Leo Kim | 442eda4 | 2015-11-06 11:12:55 +0900 | [diff] [blame] | 291 | dropped--; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | return 1; |
| 295 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 296 | |
Eva Rachel Retuya | d38f5ba | 2016-02-15 13:34:17 +0800 | [diff] [blame] | 297 | static bool enabled; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 298 | |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 299 | void wilc_enable_tcp_ack_filter(bool value) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 300 | { |
Leo Kim | 7c4bafe | 2015-11-06 11:12:56 +0900 | [diff] [blame] | 301 | enabled = value; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 302 | } |
| 303 | |
Glen Lee | 79df6a4 | 2016-02-04 18:15:31 +0900 | [diff] [blame] | 304 | static int wilc_wlan_txq_add_cfg_pkt(struct wilc_vif *vif, u8 *buffer, |
| 305 | u32 buffer_size) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 306 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 307 | struct txq_entry_t *tqe; |
Glen Lee | 79df6a4 | 2016-02-04 18:15:31 +0900 | [diff] [blame] | 308 | struct wilc *wilc = vif->wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 309 | |
Glen Lee | 79df6a4 | 2016-02-04 18:15:31 +0900 | [diff] [blame] | 310 | netdev_dbg(vif->ndev, "Adding config packet ...\n"); |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 311 | if (wilc->quit) { |
Glen Lee | 79df6a4 | 2016-02-04 18:15:31 +0900 | [diff] [blame] | 312 | netdev_dbg(vif->ndev, "Return due to clear function\n"); |
Binoy Jayan | fa65969 | 2016-06-15 11:00:36 +0530 | [diff] [blame] | 313 | complete(&wilc->cfg_event); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 314 | return 0; |
| 315 | } |
| 316 | |
Leo Kim | 1d401a4 | 2015-11-06 11:12:59 +0900 | [diff] [blame] | 317 | tqe = kmalloc(sizeof(*tqe), GFP_ATOMIC); |
Anchal Jain | e27604e | 2016-03-11 19:49:50 +0530 | [diff] [blame] | 318 | if (!tqe) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 319 | return 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 320 | |
| 321 | tqe->type = WILC_CFG_PKT; |
| 322 | tqe->buffer = buffer; |
| 323 | tqe->buffer_size = buffer_size; |
| 324 | tqe->tx_complete_func = NULL; |
| 325 | tqe->priv = NULL; |
Glen Lee | b719302 | 2015-12-21 14:18:07 +0900 | [diff] [blame] | 326 | tqe->tcp_pending_ack_idx = NOT_TCP_ACK; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 327 | |
Claudiu Beznea | 245b431 | 2016-04-25 02:07:18 +0300 | [diff] [blame] | 328 | if (wilc_wlan_txq_add_to_head(vif, tqe)) { |
| 329 | kfree(tqe); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 330 | return 0; |
Claudiu Beznea | 245b431 | 2016-04-25 02:07:18 +0300 | [diff] [blame] | 331 | } |
| 332 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 333 | return 1; |
| 334 | } |
| 335 | |
Glen Lee | 691bbd4 | 2015-10-27 18:28:02 +0900 | [diff] [blame] | 336 | int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer, |
| 337 | u32 buffer_size, wilc_tx_complete_func_t func) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 338 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 339 | struct txq_entry_t *tqe; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 340 | struct wilc_vif *vif = netdev_priv(dev); |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 341 | struct wilc *wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 342 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 343 | wilc = vif->wilc; |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 344 | |
| 345 | if (wilc->quit) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 346 | return 0; |
| 347 | |
Leo Kim | 1d401a4 | 2015-11-06 11:12:59 +0900 | [diff] [blame] | 348 | tqe = kmalloc(sizeof(*tqe), GFP_ATOMIC); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 349 | |
Leo Kim | a4b1719 | 2015-11-06 11:12:31 +0900 | [diff] [blame] | 350 | if (!tqe) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 351 | return 0; |
| 352 | tqe->type = WILC_NET_PKT; |
| 353 | tqe->buffer = buffer; |
| 354 | tqe->buffer_size = buffer_size; |
| 355 | tqe->tx_complete_func = func; |
| 356 | tqe->priv = priv; |
| 357 | |
Glen Lee | b719302 | 2015-12-21 14:18:07 +0900 | [diff] [blame] | 358 | tqe->tcp_pending_ack_idx = NOT_TCP_ACK; |
Amitoj Kaur Chawla | 5a9ff74 | 2016-02-29 19:23:44 +0530 | [diff] [blame] | 359 | if (enabled) |
Glen Lee | 82bb18e | 2015-10-27 18:28:03 +0900 | [diff] [blame] | 360 | tcp_process(dev, tqe); |
Glen Lee | 32f0332 | 2015-10-29 12:18:45 +0900 | [diff] [blame] | 361 | wilc_wlan_txq_add_to_tail(dev, tqe); |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 362 | return wilc->txq_entries; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 363 | } |
Glen Lee | fcc6ef9 | 2015-09-16 18:53:21 +0900 | [diff] [blame] | 364 | |
Glen Lee | 829c477 | 2015-10-29 12:18:44 +0900 | [diff] [blame] | 365 | int wilc_wlan_txq_add_mgmt_pkt(struct net_device *dev, void *priv, u8 *buffer, |
| 366 | u32 buffer_size, wilc_tx_complete_func_t func) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 367 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 368 | struct txq_entry_t *tqe; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 369 | struct wilc_vif *vif = netdev_priv(dev); |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 370 | struct wilc *wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 371 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 372 | wilc = vif->wilc; |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 373 | |
| 374 | if (wilc->quit) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 375 | return 0; |
| 376 | |
Leo Kim | 1d401a4 | 2015-11-06 11:12:59 +0900 | [diff] [blame] | 377 | tqe = kmalloc(sizeof(*tqe), GFP_KERNEL); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 378 | |
Leo Kim | a4b1719 | 2015-11-06 11:12:31 +0900 | [diff] [blame] | 379 | if (!tqe) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 380 | return 0; |
| 381 | tqe->type = WILC_MGMT_PKT; |
| 382 | tqe->buffer = buffer; |
| 383 | tqe->buffer_size = buffer_size; |
| 384 | tqe->tx_complete_func = func; |
| 385 | tqe->priv = priv; |
Glen Lee | b719302 | 2015-12-21 14:18:07 +0900 | [diff] [blame] | 386 | tqe->tcp_pending_ack_idx = NOT_TCP_ACK; |
Glen Lee | 32f0332 | 2015-10-29 12:18:45 +0900 | [diff] [blame] | 387 | wilc_wlan_txq_add_to_tail(dev, tqe); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 388 | return 1; |
| 389 | } |
Glen Lee | fcc6ef9 | 2015-09-16 18:53:21 +0900 | [diff] [blame] | 390 | |
Glen Lee | 7af0522 | 2015-10-29 12:18:41 +0900 | [diff] [blame] | 391 | 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] | 392 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 393 | struct txq_entry_t *tqe; |
| 394 | unsigned long flags; |
| 395 | |
Glen Lee | 7af0522 | 2015-10-29 12:18:41 +0900 | [diff] [blame] | 396 | spin_lock_irqsave(&wilc->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 397 | |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 398 | tqe = wilc->txq_head; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 399 | |
Glen Lee | 7af0522 | 2015-10-29 12:18:41 +0900 | [diff] [blame] | 400 | spin_unlock_irqrestore(&wilc->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 401 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 402 | return tqe; |
| 403 | } |
| 404 | |
Glen Lee | 50a0b3b | 2015-10-27 18:28:00 +0900 | [diff] [blame] | 405 | static struct txq_entry_t *wilc_wlan_txq_get_next(struct wilc *wilc, |
| 406 | struct txq_entry_t *tqe) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 407 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 408 | unsigned long flags; |
Leo Kim | 8739eeb | 2015-11-06 11:12:29 +0900 | [diff] [blame] | 409 | |
Glen Lee | 50a0b3b | 2015-10-27 18:28:00 +0900 | [diff] [blame] | 410 | spin_lock_irqsave(&wilc->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 411 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 412 | tqe = tqe->next; |
Glen Lee | 50a0b3b | 2015-10-27 18:28:00 +0900 | [diff] [blame] | 413 | spin_unlock_irqrestore(&wilc->txq_spinlock, flags); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 414 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 415 | return tqe; |
| 416 | } |
| 417 | |
Glen Lee | d06f362 | 2015-10-27 18:27:59 +0900 | [diff] [blame] | 418 | 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] | 419 | { |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 420 | if (wilc->quit) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 421 | return 0; |
| 422 | |
Glen Lee | d06f362 | 2015-10-27 18:27:59 +0900 | [diff] [blame] | 423 | mutex_lock(&wilc->rxq_cs); |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 424 | if (!wilc->rxq_head) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 425 | rqe->next = NULL; |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 426 | wilc->rxq_head = rqe; |
| 427 | wilc->rxq_tail = rqe; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 428 | } else { |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 429 | wilc->rxq_tail->next = rqe; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 430 | rqe->next = NULL; |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 431 | wilc->rxq_tail = rqe; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 432 | } |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 433 | wilc->rxq_entries += 1; |
Glen Lee | d06f362 | 2015-10-27 18:27:59 +0900 | [diff] [blame] | 434 | mutex_unlock(&wilc->rxq_cs); |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 435 | return wilc->rxq_entries; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 436 | } |
| 437 | |
Glen Lee | db38763 | 2015-10-27 18:27:55 +0900 | [diff] [blame] | 438 | static struct rxq_entry_t *wilc_wlan_rxq_remove(struct wilc *wilc) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 439 | { |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 440 | if (wilc->rxq_head) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 441 | struct rxq_entry_t *rqe; |
| 442 | |
Glen Lee | db38763 | 2015-10-27 18:27:55 +0900 | [diff] [blame] | 443 | mutex_lock(&wilc->rxq_cs); |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 444 | rqe = wilc->rxq_head; |
| 445 | wilc->rxq_head = wilc->rxq_head->next; |
| 446 | wilc->rxq_entries -= 1; |
Glen Lee | db38763 | 2015-10-27 18:27:55 +0900 | [diff] [blame] | 447 | mutex_unlock(&wilc->rxq_cs); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 448 | return rqe; |
| 449 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 450 | return NULL; |
| 451 | } |
| 452 | |
Glen Lee | 76855ba | 2016-01-25 16:35:08 +0900 | [diff] [blame] | 453 | void chip_allow_sleep(struct wilc *wilc) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 454 | { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 455 | u32 reg = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 456 | |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 457 | wilc->hif_func->hif_read_reg(wilc, 0xf0, ®); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 458 | |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 459 | wilc->hif_func->hif_write_reg(wilc, 0xf0, reg & ~BIT(0)); |
Glen Lee | fdc2ac1 | 2016-01-25 16:35:07 +0900 | [diff] [blame] | 460 | wilc->hif_func->hif_write_reg(wilc, 0xfa, 0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 461 | } |
Glen Lee | 76855ba | 2016-01-25 16:35:08 +0900 | [diff] [blame] | 462 | EXPORT_SYMBOL_GPL(chip_allow_sleep); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 463 | |
Glen Lee | 76855ba | 2016-01-25 16:35:08 +0900 | [diff] [blame] | 464 | void chip_wakeup(struct wilc *wilc) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 465 | { |
Leo Kim | eed9e54 | 2016-02-23 21:10:53 +0900 | [diff] [blame] | 466 | u32 reg, clk_status_reg; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 467 | |
Glen Lee | a3629a9 | 2015-12-21 14:18:10 +0900 | [diff] [blame] | 468 | if ((wilc->io_type & 0x1) == HIF_SPI) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 469 | do { |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 470 | wilc->hif_func->hif_read_reg(wilc, 1, ®); |
| 471 | wilc->hif_func->hif_write_reg(wilc, 1, reg | BIT(1)); |
| 472 | wilc->hif_func->hif_write_reg(wilc, 1, reg & ~BIT(1)); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 473 | |
| 474 | do { |
Greg Kroah-Hartman | 80e29c7 | 2015-08-14 19:42:23 -0700 | [diff] [blame] | 475 | usleep_range(2 * 1000, 2 * 1000); |
Leo Kim | 7242eee | 2016-02-22 13:41:13 +0900 | [diff] [blame] | 476 | wilc_get_chipid(wilc, true); |
Leo Kim | eed9e54 | 2016-02-23 21:10:53 +0900 | [diff] [blame] | 477 | } while (wilc_get_chipid(wilc, true) == 0); |
Glen Lee | 00215dd | 2015-11-18 15:11:25 +0900 | [diff] [blame] | 478 | } while (wilc_get_chipid(wilc, true) == 0); |
Glen Lee | a3629a9 | 2015-12-21 14:18:10 +0900 | [diff] [blame] | 479 | } else if ((wilc->io_type & 0x1) == HIF_SDIO) { |
Glen Lee | fdc2ac1 | 2016-01-25 16:35:07 +0900 | [diff] [blame] | 480 | wilc->hif_func->hif_write_reg(wilc, 0xfa, 1); |
| 481 | udelay(200); |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 482 | wilc->hif_func->hif_read_reg(wilc, 0xf0, ®); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 483 | do { |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 484 | wilc->hif_func->hif_write_reg(wilc, 0xf0, |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 485 | reg | BIT(0)); |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 486 | wilc->hif_func->hif_read_reg(wilc, 0xf1, |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 487 | &clk_status_reg); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 488 | |
Leo Kim | eed9e54 | 2016-02-23 21:10:53 +0900 | [diff] [blame] | 489 | while ((clk_status_reg & 0x1) == 0) { |
Greg Kroah-Hartman | 80e29c7 | 2015-08-14 19:42:23 -0700 | [diff] [blame] | 490 | usleep_range(2 * 1000, 2 * 1000); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 491 | |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 492 | wilc->hif_func->hif_read_reg(wilc, 0xf1, |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 493 | &clk_status_reg); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 494 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 495 | if ((clk_status_reg & 0x1) == 0) { |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 496 | wilc->hif_func->hif_write_reg(wilc, 0xf0, |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 497 | reg & (~BIT(0))); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 498 | } |
| 499 | } while ((clk_status_reg & 0x1) == 0); |
| 500 | } |
| 501 | |
Leo Kim | b7d1e18 | 2015-11-06 11:12:30 +0900 | [diff] [blame] | 502 | if (chip_ps_state == CHIP_SLEEPING_MANUAL) { |
Glen Lee | fdc2ac1 | 2016-01-25 16:35:07 +0900 | [diff] [blame] | 503 | if (wilc_get_chipid(wilc, false) < 0x1002b0) { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 504 | u32 val32; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 505 | |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 506 | wilc->hif_func->hif_read_reg(wilc, 0x1e1c, &val32); |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 507 | val32 |= BIT(6); |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 508 | wilc->hif_func->hif_write_reg(wilc, 0x1e1c, val32); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 509 | |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 510 | wilc->hif_func->hif_read_reg(wilc, 0x1e9c, &val32); |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 511 | val32 |= BIT(6); |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 512 | wilc->hif_func->hif_write_reg(wilc, 0x1e9c, val32); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 513 | } |
| 514 | } |
Leo Kim | b7d1e18 | 2015-11-06 11:12:30 +0900 | [diff] [blame] | 515 | chip_ps_state = CHIP_WAKEDUP; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 516 | } |
Glen Lee | 76855ba | 2016-01-25 16:35:08 +0900 | [diff] [blame] | 517 | EXPORT_SYMBOL_GPL(chip_wakeup); |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 518 | |
Glen Lee | 00215dd | 2015-11-18 15:11:25 +0900 | [diff] [blame] | 519 | void wilc_chip_sleep_manually(struct wilc *wilc) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 520 | { |
Leo Kim | b7d1e18 | 2015-11-06 11:12:30 +0900 | [diff] [blame] | 521 | if (chip_ps_state != CHIP_WAKEDUP) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 522 | return; |
Glen Lee | 00215dd | 2015-11-18 15:11:25 +0900 | [diff] [blame] | 523 | acquire_bus(wilc, ACQUIRE_ONLY); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 524 | |
Glen Lee | 00215dd | 2015-11-18 15:11:25 +0900 | [diff] [blame] | 525 | chip_allow_sleep(wilc); |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 526 | wilc->hif_func->hif_write_reg(wilc, 0x10a8, 1); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 527 | |
Leo Kim | b7d1e18 | 2015-11-06 11:12:30 +0900 | [diff] [blame] | 528 | chip_ps_state = CHIP_SLEEPING_MANUAL; |
Glen Lee | 00215dd | 2015-11-18 15:11:25 +0900 | [diff] [blame] | 529 | release_bus(wilc, RELEASE_ONLY); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 530 | } |
Glen Lee | 76855ba | 2016-01-25 16:35:08 +0900 | [diff] [blame] | 531 | EXPORT_SYMBOL_GPL(wilc_chip_sleep_manually); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 532 | |
Glen Lee | fdc2ac1 | 2016-01-25 16:35:07 +0900 | [diff] [blame] | 533 | void host_wakeup_notify(struct wilc *wilc) |
| 534 | { |
| 535 | acquire_bus(wilc, ACQUIRE_ONLY); |
| 536 | wilc->hif_func->hif_write_reg(wilc, 0x10b0, 1); |
| 537 | release_bus(wilc, RELEASE_ONLY); |
| 538 | } |
Glen Lee | 76855ba | 2016-01-25 16:35:08 +0900 | [diff] [blame] | 539 | EXPORT_SYMBOL_GPL(host_wakeup_notify); |
Glen Lee | fdc2ac1 | 2016-01-25 16:35:07 +0900 | [diff] [blame] | 540 | |
| 541 | void host_sleep_notify(struct wilc *wilc) |
| 542 | { |
| 543 | acquire_bus(wilc, ACQUIRE_ONLY); |
| 544 | wilc->hif_func->hif_write_reg(wilc, 0x10ac, 1); |
| 545 | release_bus(wilc, RELEASE_ONLY); |
| 546 | } |
Glen Lee | 76855ba | 2016-01-25 16:35:08 +0900 | [diff] [blame] | 547 | EXPORT_SYMBOL_GPL(host_sleep_notify); |
Glen Lee | fdc2ac1 | 2016-01-25 16:35:07 +0900 | [diff] [blame] | 548 | |
Leo Kim | b1d1929 | 2015-11-06 11:13:01 +0900 | [diff] [blame] | 549 | int wilc_wlan_handle_txq(struct net_device *dev, u32 *txq_count) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 550 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 551 | int i, entries = 0; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 552 | u32 sum; |
| 553 | u32 reg; |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 554 | u8 *txb; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 555 | u32 offset = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 556 | int vmm_sz = 0; |
| 557 | struct txq_entry_t *tqe; |
| 558 | int ret = 0; |
| 559 | int counter; |
| 560 | int timeout; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 561 | u32 vmm_table[WILC_VMM_TBL_SIZE]; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 562 | struct wilc_vif *vif; |
Glen Lee | a1332ca | 2015-10-27 18:27:47 +0900 | [diff] [blame] | 563 | struct wilc *wilc; |
| 564 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 565 | vif = netdev_priv(dev); |
| 566 | wilc = vif->wilc; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 567 | |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 568 | txb = wilc->tx_buffer; |
| 569 | wilc->txq_exit = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 570 | do { |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 571 | if (wilc->quit) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 572 | break; |
| 573 | |
Binoy Jayan | 334bed0 | 2016-06-15 11:00:35 +0530 | [diff] [blame] | 574 | mutex_lock(&wilc->txq_add_to_head_cs); |
Glen Lee | c029e99 | 2015-10-27 18:27:48 +0900 | [diff] [blame] | 575 | wilc_wlan_txq_filter_dup_tcp_ack(dev); |
Glen Lee | 7af0522 | 2015-10-29 12:18:41 +0900 | [diff] [blame] | 576 | tqe = wilc_wlan_txq_get_first(wilc); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 577 | i = 0; |
| 578 | sum = 0; |
| 579 | do { |
Leo Kim | a4b1719 | 2015-11-06 11:12:31 +0900 | [diff] [blame] | 580 | if (tqe && (i < (WILC_VMM_TBL_SIZE - 1))) { |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 581 | if (tqe->type == WILC_CFG_PKT) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 582 | vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET; |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 583 | |
| 584 | else if (tqe->type == WILC_NET_PKT) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 585 | vmm_sz = ETH_ETHERNET_HDR_OFFSET; |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 586 | |
| 587 | else |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 588 | vmm_sz = HOST_HDR_OFFSET; |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 589 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 590 | vmm_sz += tqe->buffer_size; |
Chris Park | 133b22d6 | 2016-02-04 18:15:50 +0900 | [diff] [blame] | 591 | |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 592 | if (vmm_sz & 0x3) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 593 | vmm_sz = (vmm_sz + 4) & ~0x3; |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 594 | |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 595 | if ((sum + vmm_sz) > LINUX_TX_SIZE) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 596 | break; |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 597 | |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 598 | vmm_table[i] = vmm_sz / 4; |
Chris Park | 133b22d6 | 2016-02-04 18:15:50 +0900 | [diff] [blame] | 599 | if (tqe->type == WILC_CFG_PKT) |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 600 | vmm_table[i] |= BIT(10); |
Glen Lee | 9e6627a | 2015-12-21 14:18:08 +0900 | [diff] [blame] | 601 | vmm_table[i] = cpu_to_le32(vmm_table[i]); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 602 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 603 | i++; |
| 604 | sum += vmm_sz; |
Glen Lee | 50a0b3b | 2015-10-27 18:28:00 +0900 | [diff] [blame] | 605 | tqe = wilc_wlan_txq_get_next(wilc, tqe); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 606 | } else { |
| 607 | break; |
| 608 | } |
| 609 | } while (1); |
| 610 | |
Chris Park | a410479 | 2016-02-04 18:24:05 +0900 | [diff] [blame] | 611 | if (i == 0) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 612 | break; |
Rehas Sachdeva | 6e4d1a8 | 2016-02-26 18:17:45 +0530 | [diff] [blame] | 613 | vmm_table[i] = 0x0; |
Chris Park | a410479 | 2016-02-04 18:24:05 +0900 | [diff] [blame] | 614 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 615 | acquire_bus(wilc, ACQUIRE_AND_WAKEUP); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 616 | counter = 0; |
| 617 | do { |
Chris Park | 4d38a56 | 2016-02-04 18:15:49 +0900 | [diff] [blame] | 618 | ret = wilc->hif_func->hif_read_reg(wilc, |
| 619 | WILC_HOST_TX_CTRL, |
| 620 | ®); |
Chris Park | 133b22d6 | 2016-02-04 18:15:50 +0900 | [diff] [blame] | 621 | if (!ret) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 622 | break; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 623 | |
| 624 | if ((reg & 0x1) == 0) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 625 | break; |
Anchal Jain | a5c3f8d | 2016-03-13 15:14:38 +0530 | [diff] [blame] | 626 | } |
| 627 | counter++; |
| 628 | if (counter > 200) { |
| 629 | counter = 0; |
| 630 | ret = wilc->hif_func->hif_write_reg(wilc, WILC_HOST_TX_CTRL, 0); |
| 631 | break; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 632 | } |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 633 | } while (!wilc->quit); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 634 | |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 635 | if (!ret) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 636 | goto _end_; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 637 | |
| 638 | timeout = 200; |
| 639 | do { |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 640 | ret = wilc->hif_func->hif_block_tx(wilc, WILC_VMM_TBL_RX_SHADOW_BASE, (u8 *)vmm_table, ((i + 1) * 4)); |
Chris Park | 133b22d6 | 2016-02-04 18:15:50 +0900 | [diff] [blame] | 641 | if (!ret) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 642 | break; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 643 | |
Chris Park | 4d38a56 | 2016-02-04 18:15:49 +0900 | [diff] [blame] | 644 | ret = wilc->hif_func->hif_write_reg(wilc, |
| 645 | WILC_HOST_VMM_CTL, |
| 646 | 0x2); |
Chris Park | 133b22d6 | 2016-02-04 18:15:50 +0900 | [diff] [blame] | 647 | if (!ret) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 648 | break; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 649 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 650 | do { |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 651 | ret = wilc->hif_func->hif_read_reg(wilc, WILC_HOST_VMM_CTL, ®); |
Chris Park | 133b22d6 | 2016-02-04 18:15:50 +0900 | [diff] [blame] | 652 | if (!ret) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 653 | break; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 654 | if ((reg >> 2) & 0x1) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 655 | entries = ((reg >> 3) & 0x3f); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 656 | break; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 657 | } |
Anchal Jain | a5c3f8d | 2016-03-13 15:14:38 +0530 | [diff] [blame] | 658 | release_bus(wilc, RELEASE_ALLOW_SLEEP); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 659 | } while (--timeout); |
| 660 | if (timeout <= 0) { |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 661 | 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] | 662 | break; |
| 663 | } |
| 664 | |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 665 | if (!ret) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 666 | break; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 667 | |
| 668 | if (entries == 0) { |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 669 | ret = wilc->hif_func->hif_read_reg(wilc, WILC_HOST_TX_CTRL, ®); |
Chris Park | 133b22d6 | 2016-02-04 18:15:50 +0900 | [diff] [blame] | 670 | if (!ret) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 671 | break; |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 672 | reg &= ~BIT(0); |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 673 | ret = wilc->hif_func->hif_write_reg(wilc, WILC_HOST_TX_CTRL, reg); |
Chris Park | 133b22d6 | 2016-02-04 18:15:50 +0900 | [diff] [blame] | 674 | if (!ret) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 675 | break; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 676 | break; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 677 | } |
Anchal Jain | a5c3f8d | 2016-03-13 15:14:38 +0530 | [diff] [blame] | 678 | break; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 679 | } while (1); |
| 680 | |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 681 | if (!ret) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 682 | goto _end_; |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 683 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 684 | if (entries == 0) { |
| 685 | ret = WILC_TX_ERR_NO_BUF; |
| 686 | goto _end_; |
| 687 | } |
| 688 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 689 | release_bus(wilc, RELEASE_ALLOW_SLEEP); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 690 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 691 | offset = 0; |
| 692 | i = 0; |
| 693 | do { |
Glen Lee | 718fc2c | 2015-10-29 12:18:43 +0900 | [diff] [blame] | 694 | tqe = wilc_wlan_txq_remove_from_head(dev); |
Leo Kim | a4b1719 | 2015-11-06 11:12:31 +0900 | [diff] [blame] | 695 | if (tqe && (vmm_table[i] != 0)) { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 696 | u32 header, buffer_offset; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 697 | |
Glen Lee | 9e6627a | 2015-12-21 14:18:08 +0900 | [diff] [blame] | 698 | vmm_table[i] = cpu_to_le32(vmm_table[i]); |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 699 | vmm_sz = (vmm_table[i] & 0x3ff); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 700 | vmm_sz *= 4; |
Leo Kim | ab12d8c | 2015-11-06 11:19:54 +0900 | [diff] [blame] | 701 | header = (tqe->type << 31) | |
| 702 | (tqe->buffer_size << 15) | |
| 703 | vmm_sz; |
Chandra S Gorentla | 78174ad | 2015-08-08 17:41:36 +0530 | [diff] [blame] | 704 | if (tqe->type == WILC_MGMT_PKT) |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 705 | header |= BIT(30); |
Chandra S Gorentla | 78174ad | 2015-08-08 17:41:36 +0530 | [diff] [blame] | 706 | else |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 707 | header &= ~BIT(30); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 708 | |
Glen Lee | 9e6627a | 2015-12-21 14:18:08 +0900 | [diff] [blame] | 709 | header = cpu_to_le32(header); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 710 | memcpy(&txb[offset], &header, 4); |
| 711 | if (tqe->type == WILC_CFG_PKT) { |
| 712 | buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET; |
Leo Kim | 590c0a3 | 2015-11-06 11:13:02 +0900 | [diff] [blame] | 713 | } else if (tqe->type == WILC_NET_PKT) { |
Leo Kim | 5b9f526 | 2016-02-04 18:15:34 +0900 | [diff] [blame] | 714 | char *bssid = ((struct tx_complete_data *)(tqe->priv))->bssid; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 715 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 716 | buffer_offset = ETH_ETHERNET_HDR_OFFSET; |
Leo Kim | 2f7c31f | 2015-11-06 11:13:03 +0900 | [diff] [blame] | 717 | memcpy(&txb[offset + 4], bssid, 6); |
Leo Kim | 590c0a3 | 2015-11-06 11:13:02 +0900 | [diff] [blame] | 718 | } else { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 719 | buffer_offset = HOST_HDR_OFFSET; |
| 720 | } |
| 721 | |
Leo Kim | ab12d8c | 2015-11-06 11:19:54 +0900 | [diff] [blame] | 722 | memcpy(&txb[offset + buffer_offset], |
| 723 | tqe->buffer, tqe->buffer_size); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 724 | offset += vmm_sz; |
| 725 | i++; |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 726 | tqe->status = 1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 727 | if (tqe->tx_complete_func) |
Leo Kim | ab12d8c | 2015-11-06 11:19:54 +0900 | [diff] [blame] | 728 | tqe->tx_complete_func(tqe->priv, |
| 729 | tqe->status); |
Glen Lee | 4fd6229 | 2016-02-04 18:15:24 +0900 | [diff] [blame] | 730 | if (tqe->tcp_pending_ack_idx != NOT_TCP_ACK && |
| 731 | tqe->tcp_pending_ack_idx < MAX_PENDING_ACKS) |
Glen Lee | b719302 | 2015-12-21 14:18:07 +0900 | [diff] [blame] | 732 | pending_acks_info[tqe->tcp_pending_ack_idx].txqe = NULL; |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 733 | kfree(tqe); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 734 | } else { |
| 735 | break; |
| 736 | } |
| 737 | } while (--entries); |
| 738 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 739 | acquire_bus(wilc, ACQUIRE_AND_WAKEUP); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 740 | |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 741 | ret = wilc->hif_func->hif_clear_int_ext(wilc, ENABLE_TX_VMM); |
Chris Park | 133b22d6 | 2016-02-04 18:15:50 +0900 | [diff] [blame] | 742 | if (!ret) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 743 | goto _end_; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 744 | |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 745 | ret = wilc->hif_func->hif_block_tx_ext(wilc, 0, txb, offset); |
Chris Park | 133b22d6 | 2016-02-04 18:15:50 +0900 | [diff] [blame] | 746 | if (!ret) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 747 | goto _end_; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 748 | |
| 749 | _end_: |
| 750 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 751 | release_bus(wilc, RELEASE_ALLOW_SLEEP); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 752 | if (ret != 1) |
| 753 | break; |
| 754 | } while (0); |
Binoy Jayan | 334bed0 | 2016-06-15 11:00:35 +0530 | [diff] [blame] | 755 | mutex_unlock(&wilc->txq_add_to_head_cs); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 756 | |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 757 | wilc->txq_exit = 1; |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 758 | *txq_count = wilc->txq_entries; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 759 | return ret; |
| 760 | } |
| 761 | |
Glen Lee | 39ce4d3 | 2015-10-27 18:27:42 +0900 | [diff] [blame] | 762 | static void wilc_wlan_handle_rxq(struct wilc *wilc) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 763 | { |
Chris Park | 5b3b744 | 2016-02-04 18:24:27 +0900 | [diff] [blame] | 764 | int offset = 0, size; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 765 | u8 *buffer; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 766 | struct rxq_entry_t *rqe; |
| 767 | |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 768 | wilc->rxq_exit = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 769 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 770 | do { |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 771 | if (wilc->quit) { |
Binoy Jayan | fa65969 | 2016-06-15 11:00:36 +0530 | [diff] [blame] | 772 | complete(&wilc->cfg_event); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 773 | break; |
| 774 | } |
Glen Lee | db38763 | 2015-10-27 18:27:55 +0900 | [diff] [blame] | 775 | rqe = wilc_wlan_rxq_remove(wilc); |
Chris Park | 133b22d6 | 2016-02-04 18:15:50 +0900 | [diff] [blame] | 776 | if (!rqe) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 777 | break; |
Chris Park | 133b22d6 | 2016-02-04 18:15:50 +0900 | [diff] [blame] | 778 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 779 | buffer = rqe->buffer; |
| 780 | size = rqe->buffer_size; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 781 | offset = 0; |
| 782 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 783 | do { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 784 | u32 header; |
| 785 | u32 pkt_len, pkt_offset, tp_len; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 786 | int is_cfg_packet; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 787 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 788 | memcpy(&header, &buffer[offset], 4); |
Glen Lee | 9e6627a | 2015-12-21 14:18:08 +0900 | [diff] [blame] | 789 | header = cpu_to_le32(header); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 790 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 791 | is_cfg_packet = (header >> 31) & 0x1; |
| 792 | pkt_offset = (header >> 22) & 0x1ff; |
| 793 | tp_len = (header >> 11) & 0x7ff; |
| 794 | pkt_len = header & 0x7ff; |
| 795 | |
Chris Park | 133b22d6 | 2016-02-04 18:15:50 +0900 | [diff] [blame] | 796 | if (pkt_len == 0 || tp_len == 0) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 797 | break; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 798 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 799 | #define IS_MANAGMEMENT 0x100 |
| 800 | #define IS_MANAGMEMENT_CALLBACK 0x080 |
| 801 | #define IS_MGMT_STATUS_SUCCES 0x040 |
| 802 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 803 | if (pkt_offset & IS_MANAGMEMENT) { |
Leo Kim | ab12d8c | 2015-11-06 11:19:54 +0900 | [diff] [blame] | 804 | pkt_offset &= ~(IS_MANAGMEMENT | |
| 805 | IS_MANAGMEMENT_CALLBACK | |
| 806 | IS_MGMT_STATUS_SUCCES); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 807 | |
Glen Lee | 11f4b2e | 2015-10-27 18:27:51 +0900 | [diff] [blame] | 808 | WILC_WFI_mgmt_rx(wilc, &buffer[offset + HOST_HDR_OFFSET], pkt_len); |
Leo Kim | 590c0a3 | 2015-11-06 11:13:02 +0900 | [diff] [blame] | 809 | } else { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 810 | if (!is_cfg_packet) { |
Glen Lee | 6361167 | 2015-09-24 18:14:52 +0900 | [diff] [blame] | 811 | if (pkt_len > 0) { |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 812 | wilc_frmw_to_linux(wilc, |
Glen Lee | cb1991a | 2015-10-27 18:27:56 +0900 | [diff] [blame] | 813 | &buffer[offset], |
Glen Lee | 6361167 | 2015-09-24 18:14:52 +0900 | [diff] [blame] | 814 | pkt_len, |
| 815 | pkt_offset); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 816 | } |
| 817 | } else { |
Leo Kim | bcddd48 | 2015-11-06 11:20:01 +0900 | [diff] [blame] | 818 | struct wilc_cfg_rsp rsp; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 819 | |
Glen Lee | cd04d22 | 2015-12-21 14:18:42 +0900 | [diff] [blame] | 820 | 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] | 821 | if (rsp.type == WILC_CFG_RSP) { |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 822 | if (wilc->cfg_seq_no == rsp.seq_no) |
Binoy Jayan | fa65969 | 2016-06-15 11:00:36 +0530 | [diff] [blame] | 823 | complete(&wilc->cfg_event); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 824 | } else if (rsp.type == WILC_CFG_RSP_STATUS) { |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 825 | wilc_mac_indicate(wilc, WILC_MAC_INDICATE_STATUS); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 826 | |
| 827 | } else if (rsp.type == WILC_CFG_RSP_SCAN) { |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 828 | wilc_mac_indicate(wilc, WILC_MAC_INDICATE_SCAN); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 829 | } |
| 830 | } |
| 831 | } |
| 832 | offset += tp_len; |
| 833 | if (offset >= size) |
| 834 | break; |
| 835 | } while (1); |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 836 | kfree(rqe); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 837 | } while (1); |
| 838 | |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 839 | wilc->rxq_exit = 1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 840 | } |
| 841 | |
Glen Lee | 00215dd | 2015-11-18 15:11:25 +0900 | [diff] [blame] | 842 | static void wilc_unknown_isr_ext(struct wilc *wilc) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 843 | { |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 844 | wilc->hif_func->hif_clear_int_ext(wilc, 0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 845 | } |
Leo Kim | 2d6973e | 2015-11-06 11:12:28 +0900 | [diff] [blame] | 846 | |
Glen Lee | 00215dd | 2015-11-18 15:11:25 +0900 | [diff] [blame] | 847 | static void wilc_pllupdate_isr_ext(struct wilc *wilc, u32 int_stats) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 848 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 849 | int trials = 10; |
| 850 | |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 851 | wilc->hif_func->hif_clear_int_ext(wilc, PLL_INT_CLR); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 852 | |
Glen Lee | a3629a9 | 2015-12-21 14:18:10 +0900 | [diff] [blame] | 853 | if (wilc->io_type == HIF_SDIO) |
Arnd Bergmann | e28e84d | 2015-11-16 15:05:07 +0100 | [diff] [blame] | 854 | mdelay(WILC_PLL_TO_SDIO); |
| 855 | else |
| 856 | mdelay(WILC_PLL_TO_SPI); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 857 | |
Chris Park | 133b22d6 | 2016-02-04 18:15:50 +0900 | [diff] [blame] | 858 | while (!(ISWILC1000(wilc_get_chipid(wilc, true)) && --trials)) |
Greg Kroah-Hartman | c2e4c0f | 2015-09-03 19:09:50 -0700 | [diff] [blame] | 859 | mdelay(1); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 860 | } |
| 861 | |
Glen Lee | 00215dd | 2015-11-18 15:11:25 +0900 | [diff] [blame] | 862 | static void wilc_sleeptimer_isr_ext(struct wilc *wilc, u32 int_stats1) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 863 | { |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 864 | wilc->hif_func->hif_clear_int_ext(wilc, SLEEP_INT_CLR); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 865 | } |
| 866 | |
Glen Lee | 3bcd45b | 2015-10-27 18:27:41 +0900 | [diff] [blame] | 867 | 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] | 868 | { |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 869 | u32 offset = wilc->rx_buffer_offset; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 870 | u8 *buffer = NULL; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 871 | u32 size; |
| 872 | u32 retries = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 873 | int ret = 0; |
| 874 | struct rxq_entry_t *rqe; |
| 875 | |
Alison Schofield | e682e91 | 2016-02-10 21:34:41 -0800 | [diff] [blame] | 876 | size = (int_status & 0x7fff) << 2; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 877 | |
| 878 | while (!size && retries < 10) { |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 879 | wilc->hif_func->hif_read_size(wilc, &size); |
Alison Schofield | e682e91 | 2016-02-10 21:34:41 -0800 | [diff] [blame] | 880 | size = (size & 0x7fff) << 2; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 881 | retries++; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | if (size > 0) { |
Glen Lee | 03eb726 | 2015-09-24 18:15:03 +0900 | [diff] [blame] | 885 | if (LINUX_RX_SIZE - offset < size) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 886 | offset = 0; |
| 887 | |
Chris Park | 133b22d6 | 2016-02-04 18:15:50 +0900 | [diff] [blame] | 888 | if (wilc->rx_buffer) |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 889 | buffer = &wilc->rx_buffer[offset]; |
Chris Park | 133b22d6 | 2016-02-04 18:15:50 +0900 | [diff] [blame] | 890 | else |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 891 | goto _end_; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 892 | |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 893 | wilc->hif_func->hif_clear_int_ext(wilc, |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 894 | DATA_INT_CLR | ENABLE_RX_VMM); |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 895 | ret = wilc->hif_func->hif_block_rx_ext(wilc, 0, buffer, size); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 896 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 897 | _end_: |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 898 | if (ret) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 899 | offset += size; |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 900 | wilc->rx_buffer_offset = offset; |
Leo Kim | 13b01e4 | 2015-11-06 11:13:04 +0900 | [diff] [blame] | 901 | rqe = kmalloc(sizeof(*rqe), GFP_KERNEL); |
Leo Kim | a4b1719 | 2015-11-06 11:12:31 +0900 | [diff] [blame] | 902 | if (rqe) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 903 | rqe->buffer = buffer; |
| 904 | rqe->buffer_size = size; |
Glen Lee | d06f362 | 2015-10-27 18:27:59 +0900 | [diff] [blame] | 905 | wilc_wlan_rxq_add(wilc, rqe); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 906 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 907 | } |
| 908 | } |
Glen Lee | 39ce4d3 | 2015-10-27 18:27:42 +0900 | [diff] [blame] | 909 | wilc_wlan_handle_rxq(wilc); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 910 | } |
| 911 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 912 | void wilc_handle_isr(struct wilc *wilc) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 913 | { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 914 | u32 int_status; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 915 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 916 | acquire_bus(wilc, ACQUIRE_AND_WAKEUP); |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 917 | wilc->hif_func->hif_read_int(wilc, &int_status); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 918 | |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 919 | if (int_status & PLL_INT_EXT) |
Glen Lee | 00215dd | 2015-11-18 15:11:25 +0900 | [diff] [blame] | 920 | wilc_pllupdate_isr_ext(wilc, int_status); |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 921 | |
Chris Park | f06b9ba | 2016-02-04 18:15:52 +0900 | [diff] [blame] | 922 | if (int_status & DATA_INT_EXT) |
Glen Lee | 3bcd45b | 2015-10-27 18:27:41 +0900 | [diff] [blame] | 923 | wilc_wlan_handle_isr_ext(wilc, int_status); |
Chris Park | f06b9ba | 2016-02-04 18:15:52 +0900 | [diff] [blame] | 924 | |
Alison Schofield | 39823a5 | 2015-10-08 21:18:03 -0700 | [diff] [blame] | 925 | if (int_status & SLEEP_INT_EXT) |
Glen Lee | 00215dd | 2015-11-18 15:11:25 +0900 | [diff] [blame] | 926 | wilc_sleeptimer_isr_ext(wilc, int_status); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 927 | |
Chris Park | f06b9ba | 2016-02-04 18:15:52 +0900 | [diff] [blame] | 928 | if (!(int_status & (ALL_INT_EXT))) |
Glen Lee | 00215dd | 2015-11-18 15:11:25 +0900 | [diff] [blame] | 929 | wilc_unknown_isr_ext(wilc); |
Chris Park | f06b9ba | 2016-02-04 18:15:52 +0900 | [diff] [blame] | 930 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 931 | release_bus(wilc, RELEASE_ALLOW_SLEEP); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 932 | } |
Arnd Bergmann | 750ffe9 | 2015-11-16 15:05:08 +0100 | [diff] [blame] | 933 | EXPORT_SYMBOL_GPL(wilc_handle_isr); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 934 | |
Chris Park | 4d38a56 | 2016-02-04 18:15:49 +0900 | [diff] [blame] | 935 | int wilc_wlan_firmware_download(struct wilc *wilc, const u8 *buffer, |
| 936 | u32 buffer_size) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 937 | { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 938 | u32 offset; |
| 939 | u32 addr, size, size2, blksz; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 940 | u8 *dma_buffer; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 941 | int ret = 0; |
| 942 | |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 943 | blksz = BIT(12); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 944 | |
Greg Kroah-Hartman | f019b9d | 2015-09-03 18:50:27 -0700 | [diff] [blame] | 945 | dma_buffer = kmalloc(blksz, GFP_KERNEL); |
Leo Kim | 5c6021d | 2016-03-15 18:48:13 +0900 | [diff] [blame] | 946 | if (!dma_buffer) |
| 947 | return -EIO; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 948 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 949 | offset = 0; |
| 950 | do { |
| 951 | memcpy(&addr, &buffer[offset], 4); |
| 952 | memcpy(&size, &buffer[offset + 4], 4); |
Glen Lee | 9e6627a | 2015-12-21 14:18:08 +0900 | [diff] [blame] | 953 | addr = cpu_to_le32(addr); |
| 954 | size = cpu_to_le32(size); |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 955 | acquire_bus(wilc, ACQUIRE_ONLY); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 956 | offset += 8; |
| 957 | while (((int)size) && (offset < buffer_size)) { |
Chandra S Gorentla | 78174ad | 2015-08-08 17:41:36 +0530 | [diff] [blame] | 958 | if (size <= blksz) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 959 | size2 = size; |
Chandra S Gorentla | 78174ad | 2015-08-08 17:41:36 +0530 | [diff] [blame] | 960 | else |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 961 | size2 = blksz; |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 962 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 963 | memcpy(dma_buffer, &buffer[offset], size2); |
Chris Park | 4d38a56 | 2016-02-04 18:15:49 +0900 | [diff] [blame] | 964 | ret = wilc->hif_func->hif_block_tx(wilc, addr, |
| 965 | dma_buffer, size2); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 966 | if (!ret) |
| 967 | break; |
| 968 | |
| 969 | addr += size2; |
| 970 | offset += size2; |
| 971 | size -= size2; |
| 972 | } |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 973 | release_bus(wilc, RELEASE_ONLY); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 974 | |
| 975 | if (!ret) { |
Leo Kim | 92e7d18 | 2015-11-06 11:19:55 +0900 | [diff] [blame] | 976 | ret = -EIO; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 977 | goto _fail_; |
| 978 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 979 | } while (offset < buffer_size); |
| 980 | |
| 981 | _fail_: |
| 982 | |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 983 | kfree(dma_buffer); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 984 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 985 | return (ret < 0) ? ret : 0; |
| 986 | } |
| 987 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 988 | int wilc_wlan_start(struct wilc *wilc) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 989 | { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 990 | u32 reg = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 991 | int ret; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 992 | u32 chipid; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 993 | |
Glen Lee | a3629a9 | 2015-12-21 14:18:10 +0900 | [diff] [blame] | 994 | if (wilc->io_type == HIF_SDIO) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 995 | reg = 0; |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 996 | reg |= BIT(3); |
Glen Lee | a3629a9 | 2015-12-21 14:18:10 +0900 | [diff] [blame] | 997 | } else if (wilc->io_type == HIF_SPI) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 998 | reg = 1; |
| 999 | } |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 1000 | acquire_bus(wilc, ACQUIRE_ONLY); |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 1001 | 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] | 1002 | if (!ret) { |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 1003 | release_bus(wilc, RELEASE_ONLY); |
Leo Kim | 92e7d18 | 2015-11-06 11:19:55 +0900 | [diff] [blame] | 1004 | ret = -EIO; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1005 | return ret; |
| 1006 | } |
| 1007 | reg = 0; |
Glen Lee | a3629a9 | 2015-12-21 14:18:10 +0900 | [diff] [blame] | 1008 | if (wilc->io_type == HIF_SDIO && wilc->dev_irq_num) |
Arnd Bergmann | c4d139c | 2015-11-16 15:05:04 +0100 | [diff] [blame] | 1009 | reg |= WILC_HAVE_SDIO_IRQ_GPIO; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1010 | |
| 1011 | #ifdef WILC_DISABLE_PMU |
| 1012 | #else |
| 1013 | reg |= WILC_HAVE_USE_PMU; |
| 1014 | #endif |
| 1015 | |
| 1016 | #ifdef WILC_SLEEP_CLK_SRC_XO |
| 1017 | reg |= WILC_HAVE_SLEEP_CLK_SRC_XO; |
| 1018 | #elif defined WILC_SLEEP_CLK_SRC_RTC |
| 1019 | reg |= WILC_HAVE_SLEEP_CLK_SRC_RTC; |
| 1020 | #endif |
| 1021 | |
| 1022 | #ifdef WILC_EXT_PA_INV_TX_RX |
| 1023 | reg |= WILC_HAVE_EXT_PA_INV_TX_RX; |
| 1024 | #endif |
Glen Lee | fdc2ac1 | 2016-01-25 16:35:07 +0900 | [diff] [blame] | 1025 | reg |= WILC_HAVE_USE_IRQ_AS_HOST_WAKE; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1026 | reg |= WILC_HAVE_LEGACY_RF_SETTINGS; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1027 | #ifdef XTAL_24 |
| 1028 | reg |= WILC_HAVE_XTAL_24; |
| 1029 | #endif |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1030 | #ifdef DISABLE_WILC_UART |
| 1031 | reg |= WILC_HAVE_DISABLE_WILC_UART; |
| 1032 | #endif |
| 1033 | |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 1034 | 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] | 1035 | if (!ret) { |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 1036 | release_bus(wilc, RELEASE_ONLY); |
Leo Kim | 92e7d18 | 2015-11-06 11:19:55 +0900 | [diff] [blame] | 1037 | ret = -EIO; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1038 | return ret; |
| 1039 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1040 | |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 1041 | wilc->hif_func->hif_sync_ext(wilc, NUM_INT_EXT); |
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 | ret = wilc->hif_func->hif_read_reg(wilc, 0x1000, &chipid); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1044 | if (!ret) { |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 1045 | release_bus(wilc, RELEASE_ONLY); |
Leo Kim | 92e7d18 | 2015-11-06 11:19:55 +0900 | [diff] [blame] | 1046 | ret = -EIO; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1047 | return ret; |
| 1048 | } |
| 1049 | |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 1050 | wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, ®); |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 1051 | if ((reg & BIT(10)) == BIT(10)) { |
| 1052 | reg &= ~BIT(10); |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 1053 | wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg); |
| 1054 | wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, ®); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1055 | } |
| 1056 | |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 1057 | reg |= BIT(10); |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 1058 | ret = wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg); |
| 1059 | wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, ®); |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 1060 | release_bus(wilc, RELEASE_ONLY); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1061 | |
| 1062 | return (ret < 0) ? ret : 0; |
| 1063 | } |
| 1064 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 1065 | int wilc_wlan_stop(struct wilc *wilc) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1066 | { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1067 | u32 reg = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1068 | int ret; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 1069 | u8 timeout = 10; |
Chris Park | 20f4e71 | 2016-02-04 18:15:53 +0900 | [diff] [blame] | 1070 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 1071 | acquire_bus(wilc, ACQUIRE_AND_WAKEUP); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1072 | |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 1073 | ret = wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, ®); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1074 | if (!ret) { |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 1075 | release_bus(wilc, RELEASE_ALLOW_SLEEP); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1076 | return ret; |
| 1077 | } |
| 1078 | |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 1079 | reg &= ~BIT(10); |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 1080 | 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] | 1081 | if (!ret) { |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 1082 | release_bus(wilc, RELEASE_ALLOW_SLEEP); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1083 | return ret; |
| 1084 | } |
| 1085 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1086 | do { |
Chris Park | 4d38a56 | 2016-02-04 18:15:49 +0900 | [diff] [blame] | 1087 | ret = wilc->hif_func->hif_read_reg(wilc, |
| 1088 | WILC_GLB_RESET_0, ®); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1089 | if (!ret) { |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 1090 | release_bus(wilc, RELEASE_ALLOW_SLEEP); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1091 | return ret; |
| 1092 | } |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 1093 | |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 1094 | if ((reg & BIT(10))) { |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 1095 | reg &= ~BIT(10); |
Chris Park | 4d38a56 | 2016-02-04 18:15:49 +0900 | [diff] [blame] | 1096 | ret = wilc->hif_func->hif_write_reg(wilc, |
| 1097 | WILC_GLB_RESET_0, |
| 1098 | reg); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1099 | timeout--; |
| 1100 | } else { |
Chris Park | 4d38a56 | 2016-02-04 18:15:49 +0900 | [diff] [blame] | 1101 | ret = wilc->hif_func->hif_read_reg(wilc, |
| 1102 | WILC_GLB_RESET_0, |
| 1103 | ®); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1104 | if (!ret) { |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 1105 | release_bus(wilc, RELEASE_ALLOW_SLEEP); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1106 | return ret; |
| 1107 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1108 | break; |
| 1109 | } |
| 1110 | |
| 1111 | } while (timeout); |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 1112 | reg = (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(8) | BIT(9) | BIT(26) | |
| 1113 | BIT(29) | BIT(30) | BIT(31)); |
Anish Bhatt | 65ead4e | 2015-09-29 12:15:48 -0700 | [diff] [blame] | 1114 | |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 1115 | wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg); |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 1116 | reg = (u32)~BIT(10); |
Anish Bhatt | 65ead4e | 2015-09-29 12:15:48 -0700 | [diff] [blame] | 1117 | |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 1118 | 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] | 1119 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 1120 | release_bus(wilc, RELEASE_ALLOW_SLEEP); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1121 | |
| 1122 | return ret; |
| 1123 | } |
| 1124 | |
Glen Lee | 2de7cbe | 2015-10-27 18:27:54 +0900 | [diff] [blame] | 1125 | void wilc_wlan_cleanup(struct net_device *dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1126 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1127 | struct txq_entry_t *tqe; |
| 1128 | struct rxq_entry_t *rqe; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1129 | u32 reg = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1130 | int ret; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1131 | struct wilc_vif *vif; |
Glen Lee | db38763 | 2015-10-27 18:27:55 +0900 | [diff] [blame] | 1132 | struct wilc *wilc; |
| 1133 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1134 | vif = netdev_priv(dev); |
| 1135 | wilc = vif->wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1136 | |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 1137 | wilc->quit = 1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1138 | do { |
Glen Lee | 718fc2c | 2015-10-29 12:18:43 +0900 | [diff] [blame] | 1139 | tqe = wilc_wlan_txq_remove_from_head(dev); |
Leo Kim | a4b1719 | 2015-11-06 11:12:31 +0900 | [diff] [blame] | 1140 | if (!tqe) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1141 | break; |
| 1142 | if (tqe->tx_complete_func) |
| 1143 | tqe->tx_complete_func(tqe->priv, 0); |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 1144 | kfree(tqe); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1145 | } while (1); |
| 1146 | |
| 1147 | do { |
Glen Lee | db38763 | 2015-10-27 18:27:55 +0900 | [diff] [blame] | 1148 | rqe = wilc_wlan_rxq_remove(wilc); |
Leo Kim | a4b1719 | 2015-11-06 11:12:31 +0900 | [diff] [blame] | 1149 | if (!rqe) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1150 | break; |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 1151 | kfree(rqe); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1152 | } while (1); |
| 1153 | |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 1154 | kfree(wilc->rx_buffer); |
| 1155 | wilc->rx_buffer = NULL; |
| 1156 | kfree(wilc->tx_buffer); |
Glen Lee | 608b051 | 2015-12-21 14:18:50 +0900 | [diff] [blame] | 1157 | wilc->tx_buffer = NULL; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1158 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 1159 | acquire_bus(wilc, ACQUIRE_AND_WAKEUP); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1160 | |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 1161 | ret = wilc->hif_func->hif_read_reg(wilc, WILC_GP_REG_0, ®); |
Chris Park | 133b22d6 | 2016-02-04 18:15:50 +0900 | [diff] [blame] | 1162 | if (!ret) |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 1163 | release_bus(wilc, RELEASE_ALLOW_SLEEP); |
Chris Park | 133b22d6 | 2016-02-04 18:15:50 +0900 | [diff] [blame] | 1164 | |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 1165 | ret = wilc->hif_func->hif_write_reg(wilc, WILC_GP_REG_0, |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 1166 | (reg | ABORT_INT)); |
Chris Park | 133b22d6 | 2016-02-04 18:15:50 +0900 | [diff] [blame] | 1167 | if (!ret) |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 1168 | release_bus(wilc, RELEASE_ALLOW_SLEEP); |
Chris Park | 133b22d6 | 2016-02-04 18:15:50 +0900 | [diff] [blame] | 1169 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 1170 | release_bus(wilc, RELEASE_ALLOW_SLEEP); |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 1171 | wilc->hif_func->hif_deinit(NULL); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1172 | } |
| 1173 | |
Glen Lee | 79df6a4 | 2016-02-04 18:15:31 +0900 | [diff] [blame] | 1174 | static int wilc_wlan_cfg_commit(struct wilc_vif *vif, int type, |
| 1175 | u32 drv_handler) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1176 | { |
Glen Lee | 79df6a4 | 2016-02-04 18:15:31 +0900 | [diff] [blame] | 1177 | struct wilc *wilc = vif->wilc; |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 1178 | struct wilc_cfg_frame *cfg = &wilc->cfg_frame; |
| 1179 | int total_len = wilc->cfg_frame_offset + 4 + DRIVER_HANDLER_SIZE; |
| 1180 | int seq_no = wilc->cfg_seq_no % 256; |
Leo Kim | 4864167 | 2015-11-06 11:13:08 +0900 | [diff] [blame] | 1181 | int driver_handler = (u32)drv_handler; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1182 | |
Leo Kim | 076ef65 | 2015-11-06 11:13:07 +0900 | [diff] [blame] | 1183 | if (type == WILC_CFG_SET) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1184 | cfg->wid_header[0] = 'W'; |
Leo Kim | 076ef65 | 2015-11-06 11:13:07 +0900 | [diff] [blame] | 1185 | else |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1186 | cfg->wid_header[0] = 'Q'; |
Leo Kim | ac087c8 | 2015-11-06 11:12:25 +0900 | [diff] [blame] | 1187 | cfg->wid_header[1] = seq_no; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 1188 | cfg->wid_header[2] = (u8)total_len; |
| 1189 | cfg->wid_header[3] = (u8)(total_len >> 8); |
| 1190 | cfg->wid_header[4] = (u8)driver_handler; |
| 1191 | cfg->wid_header[5] = (u8)(driver_handler >> 8); |
| 1192 | cfg->wid_header[6] = (u8)(driver_handler >> 16); |
| 1193 | cfg->wid_header[7] = (u8)(driver_handler >> 24); |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 1194 | wilc->cfg_seq_no = seq_no; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1195 | |
Glen Lee | 79df6a4 | 2016-02-04 18:15:31 +0900 | [diff] [blame] | 1196 | if (!wilc_wlan_txq_add_cfg_pkt(vif, &cfg->wid_header[0], total_len)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1197 | return -1; |
| 1198 | |
| 1199 | return 0; |
| 1200 | } |
| 1201 | |
Chaehyun Lim | 70011f5 | 2016-03-28 13:55:56 +0900 | [diff] [blame] | 1202 | int wilc_wlan_cfg_set(struct wilc_vif *vif, int start, u16 wid, u8 *buffer, |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 1203 | u32 buffer_size, int commit, u32 drv_handler) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1204 | { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1205 | u32 offset; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1206 | int ret_size; |
Glen Lee | 79df6a4 | 2016-02-04 18:15:31 +0900 | [diff] [blame] | 1207 | struct wilc *wilc = vif->wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1208 | |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 1209 | if (wilc->cfg_frame_in_use) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1210 | return 0; |
| 1211 | |
| 1212 | if (start) |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 1213 | wilc->cfg_frame_offset = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1214 | |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 1215 | offset = wilc->cfg_frame_offset; |
| 1216 | ret_size = wilc_wlan_cfg_set_wid(wilc->cfg_frame.frame, offset, |
Chaehyun Lim | 70011f5 | 2016-03-28 13:55:56 +0900 | [diff] [blame] | 1217 | wid, buffer, buffer_size); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1218 | offset += ret_size; |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 1219 | wilc->cfg_frame_offset = offset; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1220 | |
| 1221 | if (commit) { |
Glen Lee | 79df6a4 | 2016-02-04 18:15:31 +0900 | [diff] [blame] | 1222 | netdev_dbg(vif->ndev, |
| 1223 | "[WILC]PACKET Commit with sequence number %d\n", |
| 1224 | wilc->cfg_seq_no); |
| 1225 | netdev_dbg(vif->ndev, "Processing cfg_set()\n"); |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 1226 | wilc->cfg_frame_in_use = 1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1227 | |
Glen Lee | 79df6a4 | 2016-02-04 18:15:31 +0900 | [diff] [blame] | 1228 | if (wilc_wlan_cfg_commit(vif, WILC_CFG_SET, drv_handler)) |
Chaehyun Lim | 5af6b85 | 2015-09-17 16:48:48 +0900 | [diff] [blame] | 1229 | ret_size = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1230 | |
Binoy Jayan | fa65969 | 2016-06-15 11:00:36 +0530 | [diff] [blame] | 1231 | if (!wait_for_completion_timeout(&wilc->cfg_event, |
| 1232 | msecs_to_jiffies(CFG_PKTS_TIMEOUT))) { |
Glen Lee | 79df6a4 | 2016-02-04 18:15:31 +0900 | [diff] [blame] | 1233 | netdev_dbg(vif->ndev, "Set Timed Out\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1234 | ret_size = 0; |
| 1235 | } |
Binoy Jayan | fa65969 | 2016-06-15 11:00:36 +0530 | [diff] [blame] | 1236 | |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 1237 | wilc->cfg_frame_in_use = 0; |
| 1238 | wilc->cfg_frame_offset = 0; |
| 1239 | wilc->cfg_seq_no += 1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | return ret_size; |
| 1243 | } |
Leo Kim | 2d6973e | 2015-11-06 11:12:28 +0900 | [diff] [blame] | 1244 | |
Chaehyun Lim | 7db699d | 2016-03-28 13:55:57 +0900 | [diff] [blame] | 1245 | int wilc_wlan_cfg_get(struct wilc_vif *vif, int start, u16 wid, int commit, |
Glen Lee | d40c99c | 2015-11-18 15:11:35 +0900 | [diff] [blame] | 1246 | u32 drv_handler) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1247 | { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1248 | u32 offset; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1249 | int ret_size; |
Glen Lee | 79df6a4 | 2016-02-04 18:15:31 +0900 | [diff] [blame] | 1250 | struct wilc *wilc = vif->wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1251 | |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 1252 | if (wilc->cfg_frame_in_use) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1253 | return 0; |
| 1254 | |
| 1255 | if (start) |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 1256 | wilc->cfg_frame_offset = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1257 | |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 1258 | offset = wilc->cfg_frame_offset; |
Chaehyun Lim | 7db699d | 2016-03-28 13:55:57 +0900 | [diff] [blame] | 1259 | ret_size = wilc_wlan_cfg_get_wid(wilc->cfg_frame.frame, offset, wid); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1260 | offset += ret_size; |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 1261 | wilc->cfg_frame_offset = offset; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1262 | |
| 1263 | if (commit) { |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 1264 | wilc->cfg_frame_in_use = 1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1265 | |
Glen Lee | 79df6a4 | 2016-02-04 18:15:31 +0900 | [diff] [blame] | 1266 | if (wilc_wlan_cfg_commit(vif, WILC_CFG_QUERY, drv_handler)) |
Chaehyun Lim | 5af6b85 | 2015-09-17 16:48:48 +0900 | [diff] [blame] | 1267 | ret_size = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1268 | |
Binoy Jayan | fa65969 | 2016-06-15 11:00:36 +0530 | [diff] [blame] | 1269 | if (!wait_for_completion_timeout(&wilc->cfg_event, |
| 1270 | msecs_to_jiffies(CFG_PKTS_TIMEOUT))) { |
Glen Lee | 79df6a4 | 2016-02-04 18:15:31 +0900 | [diff] [blame] | 1271 | netdev_dbg(vif->ndev, "Get Timed Out\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1272 | ret_size = 0; |
| 1273 | } |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 1274 | wilc->cfg_frame_in_use = 0; |
| 1275 | wilc->cfg_frame_offset = 0; |
| 1276 | wilc->cfg_seq_no += 1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | return ret_size; |
| 1280 | } |
| 1281 | |
Chaehyun Lim | c975f9d | 2016-03-28 13:55:58 +0900 | [diff] [blame] | 1282 | int wilc_wlan_cfg_get_val(u16 wid, u8 *buffer, u32 buffer_size) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1283 | { |
Chaehyun Lim | c975f9d | 2016-03-28 13:55:58 +0900 | [diff] [blame] | 1284 | return wilc_wlan_cfg_get_wid_value(wid, buffer, buffer_size); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1285 | } |
| 1286 | |
Chaehyun Lim | 6e94445 | 2016-02-11 13:46:22 +0900 | [diff] [blame] | 1287 | int wilc_send_config_pkt(struct wilc_vif *vif, u8 mode, struct wid *wids, |
Glen Lee | ef7e012 | 2016-02-04 18:15:30 +0900 | [diff] [blame] | 1288 | u32 count, u32 drv) |
| 1289 | { |
Chaehyun Lim | b330636 | 2016-02-11 13:46:25 +0900 | [diff] [blame] | 1290 | int i; |
Chaehyun Lim | 6e94445 | 2016-02-11 13:46:22 +0900 | [diff] [blame] | 1291 | int ret = 0; |
Glen Lee | ef7e012 | 2016-02-04 18:15:30 +0900 | [diff] [blame] | 1292 | |
| 1293 | if (mode == GET_CFG) { |
Chaehyun Lim | b330636 | 2016-02-11 13:46:25 +0900 | [diff] [blame] | 1294 | for (i = 0; i < count; i++) { |
| 1295 | if (!wilc_wlan_cfg_get(vif, !i, |
| 1296 | wids[i].id, |
| 1297 | (i == count - 1), |
Glen Lee | ef7e012 | 2016-02-04 18:15:30 +0900 | [diff] [blame] | 1298 | drv)) { |
| 1299 | ret = -ETIMEDOUT; |
| 1300 | break; |
| 1301 | } |
| 1302 | } |
Chaehyun Lim | b330636 | 2016-02-11 13:46:25 +0900 | [diff] [blame] | 1303 | for (i = 0; i < count; i++) { |
| 1304 | wids[i].size = wilc_wlan_cfg_get_val(wids[i].id, |
| 1305 | wids[i].val, |
| 1306 | wids[i].size); |
Glen Lee | ef7e012 | 2016-02-04 18:15:30 +0900 | [diff] [blame] | 1307 | } |
| 1308 | } else if (mode == SET_CFG) { |
Chaehyun Lim | b330636 | 2016-02-11 13:46:25 +0900 | [diff] [blame] | 1309 | for (i = 0; i < count; i++) { |
| 1310 | if (!wilc_wlan_cfg_set(vif, !i, |
| 1311 | wids[i].id, |
| 1312 | wids[i].val, |
| 1313 | wids[i].size, |
| 1314 | (i == count - 1), |
Glen Lee | ef7e012 | 2016-02-04 18:15:30 +0900 | [diff] [blame] | 1315 | drv)) { |
| 1316 | ret = -ETIMEDOUT; |
| 1317 | break; |
| 1318 | } |
| 1319 | } |
| 1320 | } |
| 1321 | |
| 1322 | return ret; |
| 1323 | } |
| 1324 | |
Arnd Bergmann | 1608c40 | 2015-11-16 15:04:53 +0100 | [diff] [blame] | 1325 | static u32 init_chip(struct net_device *dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1326 | { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1327 | u32 chipid; |
| 1328 | u32 reg, ret = 0; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1329 | struct wilc_vif *vif; |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 1330 | struct wilc *wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1331 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1332 | vif = netdev_priv(dev); |
| 1333 | wilc = vif->wilc; |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 1334 | |
| 1335 | acquire_bus(wilc, ACQUIRE_ONLY); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1336 | |
Glen Lee | 00215dd | 2015-11-18 15:11:25 +0900 | [diff] [blame] | 1337 | chipid = wilc_get_chipid(wilc, true); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1338 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1339 | if ((chipid & 0xfff) != 0xa0) { |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 1340 | ret = wilc->hif_func->hif_read_reg(wilc, 0x1118, ®); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1341 | if (!ret) { |
Leo Kim | e974b53 | 2016-02-22 13:41:11 +0900 | [diff] [blame] | 1342 | netdev_err(dev, "fail read reg 0x1118\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1343 | return ret; |
| 1344 | } |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 1345 | reg |= BIT(0); |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 1346 | ret = wilc->hif_func->hif_write_reg(wilc, 0x1118, reg); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1347 | if (!ret) { |
Leo Kim | e974b53 | 2016-02-22 13:41:11 +0900 | [diff] [blame] | 1348 | netdev_err(dev, "fail write reg 0x1118\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1349 | return ret; |
| 1350 | } |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 1351 | ret = wilc->hif_func->hif_write_reg(wilc, 0xc0000, 0x71); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1352 | if (!ret) { |
Leo Kim | e974b53 | 2016-02-22 13:41:11 +0900 | [diff] [blame] | 1353 | netdev_err(dev, "fail write reg 0xc0000\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1354 | return ret; |
| 1355 | } |
| 1356 | } |
| 1357 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 1358 | release_bus(wilc, RELEASE_ONLY); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1359 | |
| 1360 | return ret; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1361 | } |
| 1362 | |
Chris Park | 65c3f00 | 2016-02-04 18:15:54 +0900 | [diff] [blame] | 1363 | u32 wilc_get_chipid(struct wilc *wilc, bool update) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1364 | { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1365 | static u32 chipid; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1366 | u32 tempchipid = 0; |
Chris Park | 65c3f00 | 2016-02-04 18:15:54 +0900 | [diff] [blame] | 1367 | u32 rfrevid = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1368 | |
Chris Park | 65c3f00 | 2016-02-04 18:15:54 +0900 | [diff] [blame] | 1369 | if (chipid == 0 || update) { |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 1370 | wilc->hif_func->hif_read_reg(wilc, 0x1000, &tempchipid); |
| 1371 | wilc->hif_func->hif_read_reg(wilc, 0x13f4, &rfrevid); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1372 | if (!ISWILC1000(tempchipid)) { |
| 1373 | chipid = 0; |
Chris Park | 65c3f00 | 2016-02-04 18:15:54 +0900 | [diff] [blame] | 1374 | return chipid; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1375 | } |
| 1376 | if (tempchipid == 0x1002a0) { |
Chris Park | 65c3f00 | 2016-02-04 18:15:54 +0900 | [diff] [blame] | 1377 | if (rfrevid != 0x1) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1378 | tempchipid = 0x1002a1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1379 | } else if (tempchipid == 0x1002b0) { |
Chris Park | 65c3f00 | 2016-02-04 18:15:54 +0900 | [diff] [blame] | 1380 | if (rfrevid == 0x4) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1381 | tempchipid = 0x1002b1; |
Chris Park | 65c3f00 | 2016-02-04 18:15:54 +0900 | [diff] [blame] | 1382 | else if (rfrevid != 0x3) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1383 | tempchipid = 0x1002b2; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | chipid = tempchipid; |
| 1387 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1388 | return chipid; |
| 1389 | } |
| 1390 | |
Arnd Bergmann | 4bd7baf | 2015-11-16 15:04:59 +0100 | [diff] [blame] | 1391 | int wilc_wlan_init(struct net_device *dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1392 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1393 | int ret = 0; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1394 | struct wilc_vif *vif = netdev_priv(dev); |
Glen Lee | 9c80032 | 2015-11-06 18:40:22 +0900 | [diff] [blame] | 1395 | struct wilc *wilc; |
| 1396 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1397 | wilc = vif->wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1398 | |
Glen Lee | 0c94df0 | 2016-01-25 16:35:05 +0900 | [diff] [blame] | 1399 | wilc->quit = 0; |
| 1400 | |
Glen Lee | 5397cbc | 2016-01-25 16:35:09 +0900 | [diff] [blame] | 1401 | if (!wilc->hif_func->hif_init(wilc, false)) { |
Glen Lee | cdb9923 | 2015-11-06 18:39:58 +0900 | [diff] [blame] | 1402 | ret = -EIO; |
| 1403 | goto _fail_; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1404 | } |
| 1405 | |
Leo Kim | bda2b2f | 2016-02-22 13:41:15 +0900 | [diff] [blame] | 1406 | if (!wilc_wlan_cfg_init()) { |
Leo Kim | 92e7d18 | 2015-11-06 11:19:55 +0900 | [diff] [blame] | 1407 | ret = -ENOBUFS; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1408 | goto _fail_; |
| 1409 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1410 | |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 1411 | if (!wilc->tx_buffer) |
| 1412 | wilc->tx_buffer = kmalloc(LINUX_TX_SIZE, GFP_KERNEL); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1413 | |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 1414 | if (!wilc->tx_buffer) { |
Leo Kim | 92e7d18 | 2015-11-06 11:19:55 +0900 | [diff] [blame] | 1415 | ret = -ENOBUFS; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1416 | goto _fail_; |
| 1417 | } |
| 1418 | |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 1419 | if (!wilc->rx_buffer) |
| 1420 | wilc->rx_buffer = kmalloc(LINUX_RX_SIZE, GFP_KERNEL); |
Chris Park | 133b22d6 | 2016-02-04 18:15:50 +0900 | [diff] [blame] | 1421 | |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 1422 | if (!wilc->rx_buffer) { |
Leo Kim | 92e7d18 | 2015-11-06 11:19:55 +0900 | [diff] [blame] | 1423 | ret = -ENOBUFS; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1424 | goto _fail_; |
| 1425 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1426 | |
Glen Lee | ae6f772 | 2015-10-29 12:18:48 +0900 | [diff] [blame] | 1427 | if (!init_chip(dev)) { |
Leo Kim | 92e7d18 | 2015-11-06 11:19:55 +0900 | [diff] [blame] | 1428 | ret = -EIO; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1429 | goto _fail_; |
| 1430 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1431 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1432 | return 1; |
| 1433 | |
| 1434 | _fail_: |
| 1435 | |
Glen Lee | 67e2a07 | 2015-12-21 14:18:12 +0900 | [diff] [blame] | 1436 | kfree(wilc->rx_buffer); |
| 1437 | wilc->rx_buffer = NULL; |
| 1438 | kfree(wilc->tx_buffer); |
| 1439 | wilc->tx_buffer = NULL; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1440 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1441 | return ret; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1442 | } |