Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1 | /* |
Vladimir Shulman | 1f80af2 | 2015-01-25 10:52:48 +0200 | [diff] [blame] | 2 | * Copyright (c) 2012-2015 Qualcomm Atheros, Inc. |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 17 | #include <linux/moduleparam.h> |
| 18 | #include <linux/if_arp.h> |
Vladimir Kondratiev | 108d1eb | 2014-02-27 16:20:53 +0200 | [diff] [blame] | 19 | #include <linux/etherdevice.h> |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 20 | |
| 21 | #include "wil6210.h" |
Vladimir Kondratiev | b4490f4 | 2014-02-27 16:20:44 +0200 | [diff] [blame] | 22 | #include "txrx.h" |
Dedy Lansky | f172b56 | 2014-09-10 16:34:38 +0300 | [diff] [blame] | 23 | #include "wmi.h" |
| 24 | |
| 25 | #define WAIT_FOR_DISCONNECT_TIMEOUT_MS 2000 |
| 26 | #define WAIT_FOR_DISCONNECT_INTERVAL_MS 10 |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 27 | |
Vladimir Kondratiev | c33407a | 2014-10-01 15:05:24 +0300 | [diff] [blame] | 28 | bool no_fw_recovery; |
Vladimir Kondratiev | ed6f9dc | 2014-03-17 15:34:19 +0200 | [diff] [blame] | 29 | module_param(no_fw_recovery, bool, S_IRUGO | S_IWUSR); |
Vladimir Kondratiev | c33407a | 2014-10-01 15:05:24 +0300 | [diff] [blame] | 30 | MODULE_PARM_DESC(no_fw_recovery, " disable automatic FW error recovery"); |
Vladimir Kondratiev | ed6f9dc | 2014-03-17 15:34:19 +0200 | [diff] [blame] | 31 | |
Vladimir Kondratiev | ab95462 | 2014-12-23 09:47:20 +0200 | [diff] [blame] | 32 | /* if not set via modparam, will be set to default value of 1/8 of |
| 33 | * rx ring size during init flow |
| 34 | */ |
| 35 | unsigned short rx_ring_overflow_thrsh = WIL6210_RX_HIGH_TRSH_INIT; |
| 36 | module_param(rx_ring_overflow_thrsh, ushort, S_IRUGO); |
| 37 | MODULE_PARM_DESC(rx_ring_overflow_thrsh, |
| 38 | " RX ring overflow threshold in descriptors."); |
Vladimir Kondratiev | b6b1b0e | 2014-09-22 15:31:41 +0300 | [diff] [blame] | 39 | |
Vladimir Kondratiev | 9a06bec | 2014-10-28 16:51:27 +0200 | [diff] [blame] | 40 | /* We allow allocation of more than 1 page buffers to support large packets. |
| 41 | * It is suboptimal behavior performance wise in case MTU above page size. |
| 42 | */ |
Vladimir Kondratiev | c44690a | 2014-12-23 09:47:11 +0200 | [diff] [blame] | 43 | unsigned int mtu_max = TXRX_BUF_LEN_DEFAULT - WIL_MAX_MPDU_OVERHEAD; |
Vladimir Kondratiev | 9a06bec | 2014-10-28 16:51:27 +0200 | [diff] [blame] | 44 | static int mtu_max_set(const char *val, const struct kernel_param *kp) |
| 45 | { |
| 46 | int ret; |
| 47 | |
| 48 | /* sets mtu_max directly. no need to restore it in case of |
| 49 | * illegal value since we assume this will fail insmod |
| 50 | */ |
| 51 | ret = param_set_uint(val, kp); |
| 52 | if (ret) |
| 53 | return ret; |
| 54 | |
Vladimir Kondratiev | 4590d81 | 2014-12-23 09:47:12 +0200 | [diff] [blame] | 55 | if (mtu_max < 68 || mtu_max > WIL_MAX_ETH_MTU) |
Vladimir Kondratiev | 9a06bec | 2014-10-28 16:51:27 +0200 | [diff] [blame] | 56 | ret = -EINVAL; |
| 57 | |
| 58 | return ret; |
| 59 | } |
| 60 | |
| 61 | static struct kernel_param_ops mtu_max_ops = { |
| 62 | .set = mtu_max_set, |
| 63 | .get = param_get_uint, |
| 64 | }; |
| 65 | |
| 66 | module_param_cb(mtu_max, &mtu_max_ops, &mtu_max, S_IRUGO); |
| 67 | MODULE_PARM_DESC(mtu_max, " Max MTU value."); |
| 68 | |
Vladimir Kondratiev | d3762b4 | 2014-12-01 15:35:02 +0200 | [diff] [blame] | 69 | static uint rx_ring_order = WIL_RX_RING_SIZE_ORDER_DEFAULT; |
| 70 | static uint tx_ring_order = WIL_TX_RING_SIZE_ORDER_DEFAULT; |
| 71 | |
| 72 | static int ring_order_set(const char *val, const struct kernel_param *kp) |
| 73 | { |
| 74 | int ret; |
| 75 | uint x; |
| 76 | |
| 77 | ret = kstrtouint(val, 0, &x); |
| 78 | if (ret) |
| 79 | return ret; |
| 80 | |
| 81 | if ((x < WIL_RING_SIZE_ORDER_MIN) || (x > WIL_RING_SIZE_ORDER_MAX)) |
| 82 | return -EINVAL; |
| 83 | |
| 84 | *((uint *)kp->arg) = x; |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | static struct kernel_param_ops ring_order_ops = { |
| 90 | .set = ring_order_set, |
| 91 | .get = param_get_uint, |
| 92 | }; |
| 93 | |
| 94 | module_param_cb(rx_ring_order, &ring_order_ops, &rx_ring_order, S_IRUGO); |
| 95 | MODULE_PARM_DESC(rx_ring_order, " Rx ring order; size = 1 << order"); |
| 96 | module_param_cb(tx_ring_order, &ring_order_ops, &tx_ring_order, S_IRUGO); |
| 97 | MODULE_PARM_DESC(tx_ring_order, " Tx ring order; size = 1 << order"); |
| 98 | |
Vladimir Kondratiev | 520d68e | 2014-08-06 10:31:53 +0300 | [diff] [blame] | 99 | #define RST_DELAY (20) /* msec, for loop in @wil_target_reset */ |
| 100 | #define RST_COUNT (1 + 1000/RST_DELAY) /* round up to be above 1 sec total */ |
| 101 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 102 | /* |
| 103 | * Due to a hardware issue, |
| 104 | * one has to read/write to/from NIC in 32-bit chunks; |
| 105 | * regular memcpy_fromio and siblings will |
| 106 | * not work on 64-bit platform - it uses 64-bit transactions |
| 107 | * |
| 108 | * Force 32-bit transactions to enable NIC on 64-bit platforms |
| 109 | * |
| 110 | * To avoid byte swap on big endian host, __raw_{read|write}l |
| 111 | * should be used - {read|write}l would swap bytes to provide |
| 112 | * little endian on PCI value in host endianness. |
| 113 | */ |
| 114 | void wil_memcpy_fromio_32(void *dst, const volatile void __iomem *src, |
| 115 | size_t count) |
| 116 | { |
| 117 | u32 *d = dst; |
| 118 | const volatile u32 __iomem *s = src; |
| 119 | |
| 120 | /* size_t is unsigned, if (count%4 != 0) it will wrap */ |
| 121 | for (count += 4; count > 4; count -= 4) |
| 122 | *d++ = __raw_readl(s++); |
| 123 | } |
| 124 | |
| 125 | void wil_memcpy_toio_32(volatile void __iomem *dst, const void *src, |
| 126 | size_t count) |
| 127 | { |
| 128 | volatile u32 __iomem *d = dst; |
| 129 | const u32 *s = src; |
| 130 | |
| 131 | for (count += 4; count > 4; count -= 4) |
| 132 | __raw_writel(*s++, d++); |
| 133 | } |
| 134 | |
Vladimir Kondratiev | b516fcc | 2014-10-28 16:50:08 +0200 | [diff] [blame] | 135 | static void wil_disconnect_cid(struct wil6210_priv *wil, int cid, |
Vladimir Kondratiev | 4821e6d | 2014-12-01 15:33:15 +0200 | [diff] [blame] | 136 | u16 reason_code, bool from_event) |
Vladimir Kondratiev | bd33273 | 2014-12-23 09:47:24 +0200 | [diff] [blame] | 137 | __acquires(&sta->tid_rx_lock) __releases(&sta->tid_rx_lock) |
Vladimir Kondratiev | 91886b0 | 2014-02-27 16:20:50 +0200 | [diff] [blame] | 138 | { |
| 139 | uint i; |
Vladimir Kondratiev | fc58f68 | 2014-06-16 19:37:16 +0300 | [diff] [blame] | 140 | struct net_device *ndev = wil_to_ndev(wil); |
| 141 | struct wireless_dev *wdev = wil->wdev; |
Vladimir Kondratiev | 91886b0 | 2014-02-27 16:20:50 +0200 | [diff] [blame] | 142 | struct wil_sta_info *sta = &wil->sta[cid]; |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 143 | |
Vladimir Kondratiev | bd33273 | 2014-12-23 09:47:24 +0200 | [diff] [blame] | 144 | might_sleep(); |
Vladimir Kondratiev | fc58f68 | 2014-06-16 19:37:16 +0300 | [diff] [blame] | 145 | wil_dbg_misc(wil, "%s(CID %d, status %d)\n", __func__, cid, |
| 146 | sta->status); |
Vladimir Kondratiev | 4d55a0a | 2014-02-27 16:20:54 +0200 | [diff] [blame] | 147 | |
Vladimir Kondratiev | e58c9f7 | 2014-03-17 15:34:06 +0200 | [diff] [blame] | 148 | sta->data_port_open = false; |
Vladimir Kondratiev | 4d55a0a | 2014-02-27 16:20:54 +0200 | [diff] [blame] | 149 | if (sta->status != wil_sta_unused) { |
Vladimir Kondratiev | b516fcc | 2014-10-28 16:50:08 +0200 | [diff] [blame] | 150 | if (!from_event) |
Vladimir Kondratiev | 4821e6d | 2014-12-01 15:33:15 +0200 | [diff] [blame] | 151 | wmi_disconnect_sta(wil, sta->addr, reason_code); |
Vladimir Kondratiev | b516fcc | 2014-10-28 16:50:08 +0200 | [diff] [blame] | 152 | |
Vladimir Kondratiev | fc58f68 | 2014-06-16 19:37:16 +0300 | [diff] [blame] | 153 | switch (wdev->iftype) { |
| 154 | case NL80211_IFTYPE_AP: |
| 155 | case NL80211_IFTYPE_P2P_GO: |
| 156 | /* AP-like interface */ |
| 157 | cfg80211_del_sta(ndev, sta->addr, GFP_KERNEL); |
| 158 | break; |
| 159 | default: |
| 160 | break; |
| 161 | } |
Vladimir Kondratiev | 4d55a0a | 2014-02-27 16:20:54 +0200 | [diff] [blame] | 162 | sta->status = wil_sta_unused; |
| 163 | } |
| 164 | |
Vladimir Kondratiev | 91886b0 | 2014-02-27 16:20:50 +0200 | [diff] [blame] | 165 | for (i = 0; i < WIL_STA_TID_NUM; i++) { |
Dedy Lansky | ec81b5a | 2014-09-10 16:34:42 +0300 | [diff] [blame] | 166 | struct wil_tid_ampdu_rx *r; |
Dedy Lansky | ec81b5a | 2014-09-10 16:34:42 +0300 | [diff] [blame] | 167 | |
Vladimir Kondratiev | bd33273 | 2014-12-23 09:47:24 +0200 | [diff] [blame] | 168 | spin_lock_bh(&sta->tid_rx_lock); |
Dedy Lansky | ec81b5a | 2014-09-10 16:34:42 +0300 | [diff] [blame] | 169 | |
| 170 | r = sta->tid_rx[i]; |
Vladimir Kondratiev | 91886b0 | 2014-02-27 16:20:50 +0200 | [diff] [blame] | 171 | sta->tid_rx[i] = NULL; |
| 172 | wil_tid_ampdu_rx_free(wil, r); |
Dedy Lansky | ec81b5a | 2014-09-10 16:34:42 +0300 | [diff] [blame] | 173 | |
Vladimir Kondratiev | bd33273 | 2014-12-23 09:47:24 +0200 | [diff] [blame] | 174 | spin_unlock_bh(&sta->tid_rx_lock); |
Vladimir Kondratiev | 91886b0 | 2014-02-27 16:20:50 +0200 | [diff] [blame] | 175 | } |
| 176 | for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) { |
| 177 | if (wil->vring2cid_tid[i][0] == cid) |
| 178 | wil_vring_fini_tx(wil, i); |
| 179 | } |
| 180 | memset(&sta->stats, 0, sizeof(sta->stats)); |
| 181 | } |
| 182 | |
Vladimir Kondratiev | b516fcc | 2014-10-28 16:50:08 +0200 | [diff] [blame] | 183 | static void _wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid, |
Vladimir Kondratiev | 4821e6d | 2014-12-01 15:33:15 +0200 | [diff] [blame] | 184 | u16 reason_code, bool from_event) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 185 | { |
Vladimir Kondratiev | 91886b0 | 2014-02-27 16:20:50 +0200 | [diff] [blame] | 186 | int cid = -ENOENT; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 187 | struct net_device *ndev = wil_to_ndev(wil); |
Vladimir Kondratiev | 91886b0 | 2014-02-27 16:20:50 +0200 | [diff] [blame] | 188 | struct wireless_dev *wdev = wil->wdev; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 189 | |
Vladimir Kondratiev | 91886b0 | 2014-02-27 16:20:50 +0200 | [diff] [blame] | 190 | might_sleep(); |
Vladimir Kondratiev | 100106d | 2014-12-23 09:47:07 +0200 | [diff] [blame] | 191 | wil_dbg_misc(wil, "%s(bssid=%pM, reason=%d, ev%s)\n", __func__, bssid, |
| 192 | reason_code, from_event ? "+" : "-"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 193 | |
Vladimir Kondratiev | 100106d | 2014-12-23 09:47:07 +0200 | [diff] [blame] | 194 | /* Cases are: |
| 195 | * - disconnect single STA, still connected |
| 196 | * - disconnect single STA, already disconnected |
| 197 | * - disconnect all |
| 198 | * |
| 199 | * For "disconnect all", there are 2 options: |
| 200 | * - bssid == NULL |
| 201 | * - bssid is our MAC address |
| 202 | */ |
| 203 | if (bssid && memcmp(ndev->dev_addr, bssid, ETH_ALEN)) { |
| 204 | cid = wil_find_cid(wil, bssid); |
| 205 | wil_dbg_misc(wil, "Disconnect %pM, CID=%d, reason=%d\n", |
| 206 | bssid, cid, reason_code); |
| 207 | if (cid >= 0) /* disconnect 1 peer */ |
| 208 | wil_disconnect_cid(wil, cid, reason_code, from_event); |
| 209 | } else { /* all */ |
| 210 | wil_dbg_misc(wil, "Disconnect all\n"); |
Vladimir Kondratiev | 91886b0 | 2014-02-27 16:20:50 +0200 | [diff] [blame] | 211 | for (cid = 0; cid < WIL6210_MAX_CID; cid++) |
Vladimir Kondratiev | 4821e6d | 2014-12-01 15:33:15 +0200 | [diff] [blame] | 212 | wil_disconnect_cid(wil, cid, reason_code, from_event); |
Vladimir Kondratiev | 100106d | 2014-12-23 09:47:07 +0200 | [diff] [blame] | 213 | } |
Vladimir Kondratiev | 91886b0 | 2014-02-27 16:20:50 +0200 | [diff] [blame] | 214 | |
| 215 | /* link state */ |
| 216 | switch (wdev->iftype) { |
| 217 | case NL80211_IFTYPE_STATION: |
| 218 | case NL80211_IFTYPE_P2P_CLIENT: |
Dedy Lansky | c5e96c9 | 2015-01-25 10:52:43 +0200 | [diff] [blame] | 219 | netif_tx_stop_all_queues(ndev); |
| 220 | netif_carrier_off(ndev); |
| 221 | |
Vladimir Kondratiev | 9419b6a | 2014-12-23 09:47:14 +0200 | [diff] [blame] | 222 | if (test_bit(wil_status_fwconnected, wil->status)) { |
| 223 | clear_bit(wil_status_fwconnected, wil->status); |
Vladimir Kondratiev | 4821e6d | 2014-12-01 15:33:15 +0200 | [diff] [blame] | 224 | cfg80211_disconnected(ndev, reason_code, |
Vladimir Kondratiev | 91886b0 | 2014-02-27 16:20:50 +0200 | [diff] [blame] | 225 | NULL, 0, GFP_KERNEL); |
Vladimir Kondratiev | 9419b6a | 2014-12-23 09:47:14 +0200 | [diff] [blame] | 226 | } else if (test_bit(wil_status_fwconnecting, wil->status)) { |
Vladimir Kondratiev | 91886b0 | 2014-02-27 16:20:50 +0200 | [diff] [blame] | 227 | cfg80211_connect_result(ndev, bssid, NULL, 0, NULL, 0, |
| 228 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
| 229 | GFP_KERNEL); |
Vladimir Kondratiev | b4490f4 | 2014-02-27 16:20:44 +0200 | [diff] [blame] | 230 | } |
Vladimir Kondratiev | 9419b6a | 2014-12-23 09:47:14 +0200 | [diff] [blame] | 231 | clear_bit(wil_status_fwconnecting, wil->status); |
Vladimir Kondratiev | 91886b0 | 2014-02-27 16:20:50 +0200 | [diff] [blame] | 232 | break; |
| 233 | default: |
Vladimir Kondratiev | 91886b0 | 2014-02-27 16:20:50 +0200 | [diff] [blame] | 234 | break; |
Vladimir Kondratiev | b4490f4 | 2014-02-27 16:20:44 +0200 | [diff] [blame] | 235 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | static void wil_disconnect_worker(struct work_struct *work) |
| 239 | { |
| 240 | struct wil6210_priv *wil = container_of(work, |
| 241 | struct wil6210_priv, disconnect_worker); |
| 242 | |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 243 | mutex_lock(&wil->mutex); |
Vladimir Kondratiev | 4821e6d | 2014-12-01 15:33:15 +0200 | [diff] [blame] | 244 | _wil6210_disconnect(wil, NULL, WLAN_REASON_UNSPECIFIED, false); |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 245 | mutex_unlock(&wil->mutex); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | static void wil_connect_timer_fn(ulong x) |
| 249 | { |
| 250 | struct wil6210_priv *wil = (void *)x; |
| 251 | |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 252 | wil_dbg_misc(wil, "Connect timeout\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 253 | |
| 254 | /* reschedule to thread context - disconnect won't |
| 255 | * run from atomic context |
| 256 | */ |
| 257 | schedule_work(&wil->disconnect_worker); |
| 258 | } |
| 259 | |
Vladimir Kondratiev | 047e5d7 | 2014-05-27 14:45:48 +0300 | [diff] [blame] | 260 | static void wil_scan_timer_fn(ulong x) |
| 261 | { |
| 262 | struct wil6210_priv *wil = (void *)x; |
| 263 | |
Vladimir Kondratiev | 9419b6a | 2014-12-23 09:47:14 +0200 | [diff] [blame] | 264 | clear_bit(wil_status_fwready, wil->status); |
Vladimir Kondratiev | 047e5d7 | 2014-05-27 14:45:48 +0300 | [diff] [blame] | 265 | wil_err(wil, "Scan timeout detected, start fw error recovery\n"); |
Vladimir Kondratiev | 60abbb6 | 2014-12-01 15:33:17 +0200 | [diff] [blame] | 266 | wil->recovery_state = fw_recovery_pending; |
Vladimir Kondratiev | 047e5d7 | 2014-05-27 14:45:48 +0300 | [diff] [blame] | 267 | schedule_work(&wil->fw_error_worker); |
| 268 | } |
| 269 | |
Vladimir Kondratiev | c33407a | 2014-10-01 15:05:24 +0300 | [diff] [blame] | 270 | static int wil_wait_for_recovery(struct wil6210_priv *wil) |
| 271 | { |
| 272 | if (wait_event_interruptible(wil->wq, wil->recovery_state != |
| 273 | fw_recovery_pending)) { |
| 274 | wil_err(wil, "Interrupt, canceling recovery\n"); |
| 275 | return -ERESTARTSYS; |
| 276 | } |
| 277 | if (wil->recovery_state != fw_recovery_running) { |
| 278 | wil_info(wil, "Recovery cancelled\n"); |
| 279 | return -EINTR; |
| 280 | } |
| 281 | wil_info(wil, "Proceed with recovery\n"); |
| 282 | return 0; |
| 283 | } |
| 284 | |
| 285 | void wil_set_recovery_state(struct wil6210_priv *wil, int state) |
| 286 | { |
| 287 | wil_dbg_misc(wil, "%s(%d -> %d)\n", __func__, |
| 288 | wil->recovery_state, state); |
| 289 | |
| 290 | wil->recovery_state = state; |
| 291 | wake_up_interruptible(&wil->wq); |
| 292 | } |
| 293 | |
Vladimir Kondratiev | ed6f9dc | 2014-03-17 15:34:19 +0200 | [diff] [blame] | 294 | static void wil_fw_error_worker(struct work_struct *work) |
| 295 | { |
Vladimir Kondratiev | c33407a | 2014-10-01 15:05:24 +0300 | [diff] [blame] | 296 | struct wil6210_priv *wil = container_of(work, struct wil6210_priv, |
| 297 | fw_error_worker); |
Vladimir Kondratiev | ed6f9dc | 2014-03-17 15:34:19 +0200 | [diff] [blame] | 298 | struct wireless_dev *wdev = wil->wdev; |
| 299 | |
| 300 | wil_dbg_misc(wil, "fw error worker\n"); |
| 301 | |
Vladimir Kondratiev | cded936 | 2014-10-28 16:50:06 +0200 | [diff] [blame] | 302 | if (!netif_running(wil_to_ndev(wil))) { |
| 303 | wil_info(wil, "No recovery - interface is down\n"); |
| 304 | return; |
| 305 | } |
| 306 | |
Vladimir Kondratiev | fc219ee | 2014-05-27 14:45:45 +0300 | [diff] [blame] | 307 | /* increment @recovery_count if less then WIL6210_FW_RECOVERY_TO |
| 308 | * passed since last recovery attempt |
| 309 | */ |
| 310 | if (time_is_after_jiffies(wil->last_fw_recovery + |
| 311 | WIL6210_FW_RECOVERY_TO)) |
| 312 | wil->recovery_count++; |
| 313 | else |
| 314 | wil->recovery_count = 1; /* fw was alive for a long time */ |
| 315 | |
| 316 | if (wil->recovery_count > WIL6210_FW_RECOVERY_RETRIES) { |
| 317 | wil_err(wil, "too many recovery attempts (%d), giving up\n", |
| 318 | wil->recovery_count); |
| 319 | return; |
| 320 | } |
| 321 | |
| 322 | wil->last_fw_recovery = jiffies; |
| 323 | |
Vladimir Kondratiev | 9c3bde5 | 2014-03-17 15:34:21 +0200 | [diff] [blame] | 324 | mutex_lock(&wil->mutex); |
Vladimir Kondratiev | ed6f9dc | 2014-03-17 15:34:19 +0200 | [diff] [blame] | 325 | switch (wdev->iftype) { |
| 326 | case NL80211_IFTYPE_STATION: |
| 327 | case NL80211_IFTYPE_P2P_CLIENT: |
| 328 | case NL80211_IFTYPE_MONITOR: |
Vladimir Kondratiev | c33407a | 2014-10-01 15:05:24 +0300 | [diff] [blame] | 329 | wil_info(wil, "fw error recovery requested (try %d)...\n", |
Vladimir Kondratiev | fc219ee | 2014-05-27 14:45:45 +0300 | [diff] [blame] | 330 | wil->recovery_count); |
Vladimir Kondratiev | c33407a | 2014-10-01 15:05:24 +0300 | [diff] [blame] | 331 | if (!no_fw_recovery) |
| 332 | wil->recovery_state = fw_recovery_running; |
| 333 | if (0 != wil_wait_for_recovery(wil)) |
| 334 | break; |
| 335 | |
Vladimir Kondratiev | 73d839a | 2014-09-10 16:34:50 +0300 | [diff] [blame] | 336 | __wil_down(wil); |
| 337 | __wil_up(wil); |
Vladimir Kondratiev | ed6f9dc | 2014-03-17 15:34:19 +0200 | [diff] [blame] | 338 | break; |
| 339 | case NL80211_IFTYPE_AP: |
| 340 | case NL80211_IFTYPE_P2P_GO: |
Vladimir Kondratiev | e240537 | 2014-10-28 16:50:09 +0200 | [diff] [blame] | 341 | wil_info(wil, "No recovery for AP-like interface\n"); |
Vladimir Kondratiev | ed6f9dc | 2014-03-17 15:34:19 +0200 | [diff] [blame] | 342 | /* recovery in these modes is done by upper layers */ |
| 343 | break; |
| 344 | default: |
Vladimir Kondratiev | e240537 | 2014-10-28 16:50:09 +0200 | [diff] [blame] | 345 | wil_err(wil, "No recovery - unknown interface type %d\n", |
| 346 | wdev->iftype); |
Vladimir Kondratiev | ed6f9dc | 2014-03-17 15:34:19 +0200 | [diff] [blame] | 347 | break; |
| 348 | } |
Vladimir Kondratiev | 9c3bde5 | 2014-03-17 15:34:21 +0200 | [diff] [blame] | 349 | mutex_unlock(&wil->mutex); |
Vladimir Kondratiev | ed6f9dc | 2014-03-17 15:34:19 +0200 | [diff] [blame] | 350 | } |
| 351 | |
Vladimir Kondratiev | 9a17738 | 2014-02-27 16:20:45 +0200 | [diff] [blame] | 352 | static int wil_find_free_vring(struct wil6210_priv *wil) |
| 353 | { |
| 354 | int i; |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 355 | |
Vladimir Kondratiev | 9a17738 | 2014-02-27 16:20:45 +0200 | [diff] [blame] | 356 | for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) { |
| 357 | if (!wil->vring_tx[i].va) |
| 358 | return i; |
| 359 | } |
| 360 | return -EINVAL; |
| 361 | } |
| 362 | |
Vladimir Kondratiev | d81079f | 2013-03-13 14:12:43 +0200 | [diff] [blame] | 363 | static void wil_connect_worker(struct work_struct *work) |
| 364 | { |
| 365 | int rc; |
| 366 | struct wil6210_priv *wil = container_of(work, struct wil6210_priv, |
| 367 | connect_worker); |
Dedy Lansky | c5e96c9 | 2015-01-25 10:52:43 +0200 | [diff] [blame] | 368 | struct net_device *ndev = wil_to_ndev(wil); |
| 369 | |
Vladimir Kondratiev | d81079f | 2013-03-13 14:12:43 +0200 | [diff] [blame] | 370 | int cid = wil->pending_connect_cid; |
Vladimir Kondratiev | 9a17738 | 2014-02-27 16:20:45 +0200 | [diff] [blame] | 371 | int ringid = wil_find_free_vring(wil); |
Vladimir Kondratiev | d81079f | 2013-03-13 14:12:43 +0200 | [diff] [blame] | 372 | |
| 373 | if (cid < 0) { |
| 374 | wil_err(wil, "No connection pending\n"); |
| 375 | return; |
| 376 | } |
| 377 | |
| 378 | wil_dbg_wmi(wil, "Configure for connection CID %d\n", cid); |
| 379 | |
Vladimir Kondratiev | d3762b4 | 2014-12-01 15:35:02 +0200 | [diff] [blame] | 380 | rc = wil_vring_init_tx(wil, ringid, 1 << tx_ring_order, cid, 0); |
Vladimir Kondratiev | d81079f | 2013-03-13 14:12:43 +0200 | [diff] [blame] | 381 | wil->pending_connect_cid = -1; |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 382 | if (rc == 0) { |
| 383 | wil->sta[cid].status = wil_sta_connected; |
Dedy Lansky | c5e96c9 | 2015-01-25 10:52:43 +0200 | [diff] [blame] | 384 | netif_tx_wake_all_queues(ndev); |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 385 | } else { |
| 386 | wil->sta[cid].status = wil_sta_unused; |
| 387 | } |
Vladimir Kondratiev | d81079f | 2013-03-13 14:12:43 +0200 | [diff] [blame] | 388 | } |
| 389 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 390 | int wil_priv_init(struct wil6210_priv *wil) |
| 391 | { |
Dedy Lansky | ec81b5a | 2014-09-10 16:34:42 +0300 | [diff] [blame] | 392 | uint i; |
| 393 | |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 394 | wil_dbg_misc(wil, "%s()\n", __func__); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 395 | |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 396 | memset(wil->sta, 0, sizeof(wil->sta)); |
Dedy Lansky | ec81b5a | 2014-09-10 16:34:42 +0300 | [diff] [blame] | 397 | for (i = 0; i < WIL6210_MAX_CID; i++) |
| 398 | spin_lock_init(&wil->sta[i].tid_rx_lock); |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 399 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 400 | mutex_init(&wil->mutex); |
| 401 | mutex_init(&wil->wmi_mutex); |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 402 | mutex_init(&wil->back_rx_mutex); |
Vladimir Kondratiev | 3a124ed | 2014-12-23 09:47:04 +0200 | [diff] [blame] | 403 | mutex_init(&wil->back_tx_mutex); |
Vladimir Kondratiev | 40822a9 | 2015-01-25 10:52:50 +0200 | [diff] [blame] | 404 | mutex_init(&wil->probe_client_mutex); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 405 | |
| 406 | init_completion(&wil->wmi_ready); |
Dedy Lansky | 5950264 | 2014-09-10 16:34:46 +0300 | [diff] [blame] | 407 | init_completion(&wil->wmi_call); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 408 | |
| 409 | wil->pending_connect_cid = -1; |
| 410 | setup_timer(&wil->connect_timer, wil_connect_timer_fn, (ulong)wil); |
Vladimir Kondratiev | 047e5d7 | 2014-05-27 14:45:48 +0300 | [diff] [blame] | 411 | setup_timer(&wil->scan_timer, wil_scan_timer_fn, (ulong)wil); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 412 | |
Vladimir Kondratiev | d81079f | 2013-03-13 14:12:43 +0200 | [diff] [blame] | 413 | INIT_WORK(&wil->connect_worker, wil_connect_worker); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 414 | INIT_WORK(&wil->disconnect_worker, wil_disconnect_worker); |
| 415 | INIT_WORK(&wil->wmi_event_worker, wmi_event_worker); |
Vladimir Kondratiev | ed6f9dc | 2014-03-17 15:34:19 +0200 | [diff] [blame] | 416 | INIT_WORK(&wil->fw_error_worker, wil_fw_error_worker); |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 417 | INIT_WORK(&wil->back_rx_worker, wil_back_rx_worker); |
Vladimir Kondratiev | 3a124ed | 2014-12-23 09:47:04 +0200 | [diff] [blame] | 418 | INIT_WORK(&wil->back_tx_worker, wil_back_tx_worker); |
Vladimir Kondratiev | 40822a9 | 2015-01-25 10:52:50 +0200 | [diff] [blame] | 419 | INIT_WORK(&wil->probe_client_worker, wil_probe_client_worker); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 420 | |
| 421 | INIT_LIST_HEAD(&wil->pending_wmi_ev); |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 422 | INIT_LIST_HEAD(&wil->back_rx_pending); |
Vladimir Kondratiev | 3a124ed | 2014-12-23 09:47:04 +0200 | [diff] [blame] | 423 | INIT_LIST_HEAD(&wil->back_tx_pending); |
Vladimir Kondratiev | 40822a9 | 2015-01-25 10:52:50 +0200 | [diff] [blame] | 424 | INIT_LIST_HEAD(&wil->probe_client_pending); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 425 | spin_lock_init(&wil->wmi_ev_lock); |
Vladimir Kondratiev | c33407a | 2014-10-01 15:05:24 +0300 | [diff] [blame] | 426 | init_waitqueue_head(&wil->wq); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 427 | |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 428 | wil->wmi_wq = create_singlethread_workqueue(WIL_NAME "_wmi"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 429 | if (!wil->wmi_wq) |
| 430 | return -EAGAIN; |
| 431 | |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 432 | wil->wq_service = create_singlethread_workqueue(WIL_NAME "_service"); |
| 433 | if (!wil->wq_service) |
| 434 | goto out_wmi_wq; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 435 | |
Vladimir Kondratiev | fc219ee | 2014-05-27 14:45:45 +0300 | [diff] [blame] | 436 | wil->last_fw_recovery = jiffies; |
Vladimir Shulman | 1f80af2 | 2015-01-25 10:52:48 +0200 | [diff] [blame] | 437 | wil->tx_interframe_timeout = WIL6210_ITR_TX_INTERFRAME_TIMEOUT_DEFAULT; |
| 438 | wil->rx_interframe_timeout = WIL6210_ITR_RX_INTERFRAME_TIMEOUT_DEFAULT; |
| 439 | wil->tx_max_burst_duration = WIL6210_ITR_TX_MAX_BURST_DURATION_DEFAULT; |
| 440 | wil->rx_max_burst_duration = WIL6210_ITR_RX_MAX_BURST_DURATION_DEFAULT; |
Vladimir Kondratiev | fc219ee | 2014-05-27 14:45:45 +0300 | [diff] [blame] | 441 | |
Vladimir Kondratiev | ab95462 | 2014-12-23 09:47:20 +0200 | [diff] [blame] | 442 | if (rx_ring_overflow_thrsh == WIL6210_RX_HIGH_TRSH_INIT) |
| 443 | rx_ring_overflow_thrsh = WIL6210_RX_HIGH_TRSH_DEFAULT; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 444 | return 0; |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 445 | |
| 446 | out_wmi_wq: |
| 447 | destroy_workqueue(wil->wmi_wq); |
| 448 | |
| 449 | return -EAGAIN; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 450 | } |
| 451 | |
Vladimir Kondratiev | b516fcc | 2014-10-28 16:50:08 +0200 | [diff] [blame] | 452 | /** |
| 453 | * wil6210_disconnect - disconnect one connection |
| 454 | * @wil: driver context |
| 455 | * @bssid: peer to disconnect, NULL to disconnect all |
Vladimir Kondratiev | 4821e6d | 2014-12-01 15:33:15 +0200 | [diff] [blame] | 456 | * @reason_code: Reason code for the Disassociation frame |
Vladimir Kondratiev | b516fcc | 2014-10-28 16:50:08 +0200 | [diff] [blame] | 457 | * @from_event: whether is invoked from FW event handler |
| 458 | * |
| 459 | * Disconnect and release associated resources. If invoked not from the |
| 460 | * FW event handler, issue WMI command(s) to trigger MAC disconnect. |
| 461 | */ |
| 462 | void wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid, |
Vladimir Kondratiev | 4821e6d | 2014-12-01 15:33:15 +0200 | [diff] [blame] | 463 | u16 reason_code, bool from_event) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 464 | { |
Vladimir Kondratiev | 9cf10d6 | 2014-09-10 16:34:36 +0300 | [diff] [blame] | 465 | wil_dbg_misc(wil, "%s()\n", __func__); |
| 466 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 467 | del_timer_sync(&wil->connect_timer); |
Vladimir Kondratiev | 4821e6d | 2014-12-01 15:33:15 +0200 | [diff] [blame] | 468 | _wil6210_disconnect(wil, bssid, reason_code, from_event); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | void wil_priv_deinit(struct wil6210_priv *wil) |
| 472 | { |
Vladimir Kondratiev | 9cf10d6 | 2014-09-10 16:34:36 +0300 | [diff] [blame] | 473 | wil_dbg_misc(wil, "%s()\n", __func__); |
| 474 | |
Vladimir Kondratiev | c33407a | 2014-10-01 15:05:24 +0300 | [diff] [blame] | 475 | wil_set_recovery_state(wil, fw_recovery_idle); |
Vladimir Kondratiev | 047e5d7 | 2014-05-27 14:45:48 +0300 | [diff] [blame] | 476 | del_timer_sync(&wil->scan_timer); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 477 | cancel_work_sync(&wil->disconnect_worker); |
Vladimir Kondratiev | ed6f9dc | 2014-03-17 15:34:19 +0200 | [diff] [blame] | 478 | cancel_work_sync(&wil->fw_error_worker); |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 479 | mutex_lock(&wil->mutex); |
Vladimir Kondratiev | 4821e6d | 2014-12-01 15:33:15 +0200 | [diff] [blame] | 480 | wil6210_disconnect(wil, NULL, WLAN_REASON_DEAUTH_LEAVING, false); |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 481 | mutex_unlock(&wil->mutex); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 482 | wmi_event_flush(wil); |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 483 | wil_back_rx_flush(wil); |
| 484 | cancel_work_sync(&wil->back_rx_worker); |
Vladimir Kondratiev | 3a124ed | 2014-12-23 09:47:04 +0200 | [diff] [blame] | 485 | wil_back_tx_flush(wil); |
| 486 | cancel_work_sync(&wil->back_tx_worker); |
Vladimir Kondratiev | 40822a9 | 2015-01-25 10:52:50 +0200 | [diff] [blame] | 487 | wil_probe_client_flush(wil); |
| 488 | cancel_work_sync(&wil->probe_client_worker); |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 489 | destroy_workqueue(wil->wq_service); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 490 | destroy_workqueue(wil->wmi_wq); |
| 491 | } |
| 492 | |
Vladimir Kondratiev | 151a970 | 2014-09-10 16:34:30 +0300 | [diff] [blame] | 493 | /* target operations */ |
| 494 | /* register read */ |
| 495 | #define R(a) ioread32(wil->csr + HOSTADDR(a)) |
| 496 | /* register write. wmb() to make sure it is completed */ |
| 497 | #define W(a, v) do { iowrite32(v, wil->csr + HOSTADDR(a)); wmb(); } while (0) |
| 498 | /* register set = read, OR, write */ |
| 499 | #define S(a, v) W(a, R(a) | v) |
| 500 | /* register clear = read, AND with inverted, write */ |
| 501 | #define C(a, v) W(a, R(a) & ~v) |
| 502 | |
| 503 | static inline void wil_halt_cpu(struct wil6210_priv *wil) |
| 504 | { |
| 505 | W(RGF_USER_USER_CPU_0, BIT_USER_USER_CPU_MAN_RST); |
| 506 | W(RGF_USER_MAC_CPU_0, BIT_USER_MAC_CPU_MAN_RST); |
| 507 | } |
| 508 | |
| 509 | static inline void wil_release_cpu(struct wil6210_priv *wil) |
| 510 | { |
| 511 | /* Start CPU */ |
| 512 | W(RGF_USER_USER_CPU_0, 1); |
| 513 | } |
| 514 | |
Vladimir Kondratiev | bbb2adc | 2014-08-06 10:31:52 +0300 | [diff] [blame] | 515 | static int wil_target_reset(struct wil6210_priv *wil) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 516 | { |
Vladimir Kondratiev | 98a65b5 | 2014-03-17 15:34:12 +0200 | [diff] [blame] | 517 | int delay = 0; |
Vladimir Kondratiev | 4851629 | 2014-10-28 16:50:07 +0200 | [diff] [blame] | 518 | u32 x; |
Vladimir Kondratiev | 36b10a7 | 2014-03-17 15:34:10 +0200 | [diff] [blame] | 519 | |
Vladimir Kondratiev | 1aeda13 | 2014-12-23 09:47:18 +0200 | [diff] [blame] | 520 | wil_dbg_misc(wil, "Resetting \"%s\"...\n", wil->hw_name); |
Vladimir Kondratiev | 6508281 | 2014-07-14 09:49:37 +0300 | [diff] [blame] | 521 | |
| 522 | /* Clear MAC link up */ |
| 523 | S(RGF_HP_CTRL, BIT(15)); |
Vladimir Kondratiev | 151a970 | 2014-09-10 16:34:30 +0300 | [diff] [blame] | 524 | S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT_HPAL_PERST_FROM_PAD); |
| 525 | S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT_CAR_PERST_RST); |
| 526 | |
| 527 | wil_halt_cpu(wil); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 528 | |
Vladimir Kondratiev | 2cd0f02 | 2015-02-15 14:02:30 +0200 | [diff] [blame] | 529 | /* clear all boot loader "ready" bits */ |
| 530 | W(RGF_USER_BL + offsetof(struct RGF_BL, ready), 0); |
Vladimir Kondratiev | cce47711 | 2014-12-01 15:36:31 +0200 | [diff] [blame] | 531 | /* Clear Fw Download notification */ |
| 532 | C(RGF_USER_USAGE_6, BIT(0)); |
| 533 | |
Vladimir Kondratiev | 9a5511b | 2015-02-15 14:02:31 +0200 | [diff] [blame^] | 534 | S(RGF_CAF_OSC_CONTROL, BIT_CAF_OSC_XTAL_EN); |
| 535 | /* XTAL stabilization should take about 3ms */ |
| 536 | usleep_range(5000, 7000); |
| 537 | x = R(RGF_CAF_PLL_LOCK_STATUS); |
| 538 | if (!(x & BIT_CAF_OSC_DIG_XTAL_STABLE)) { |
| 539 | wil_err(wil, "Xtal stabilization timeout\n" |
| 540 | "RGF_CAF_PLL_LOCK_STATUS = 0x%08x\n", x); |
| 541 | return -ETIME; |
Vladimir Kondratiev | 6508281 | 2014-07-14 09:49:37 +0300 | [diff] [blame] | 542 | } |
Vladimir Kondratiev | 9a5511b | 2015-02-15 14:02:31 +0200 | [diff] [blame^] | 543 | /* switch 10k to XTAL*/ |
| 544 | C(RGF_USER_SPARROW_M_4, BIT_SPARROW_M_4_SEL_SLEEP_OR_REF); |
| 545 | /* 40 MHz */ |
| 546 | C(RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_CAR_AHB_SW_SEL); |
| 547 | |
| 548 | W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x3ff81f); |
| 549 | W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0xf); |
Vladimir Kondratiev | 6508281 | 2014-07-14 09:49:37 +0300 | [diff] [blame] | 550 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 551 | W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0xFE000000); |
| 552 | W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0x0000003F); |
Vladimir Kondratiev | 9a5511b | 2015-02-15 14:02:31 +0200 | [diff] [blame^] | 553 | W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x000000f0); |
Vladimir Kondratiev | 151a970 | 2014-09-10 16:34:30 +0300 | [diff] [blame] | 554 | W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0xFFE7FE00); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 555 | |
Vladimir Kondratiev | 9a5511b | 2015-02-15 14:02:31 +0200 | [diff] [blame^] | 556 | W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x0); |
| 557 | W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0x0); |
Vladimir Kondratiev | 6508281 | 2014-07-14 09:49:37 +0300 | [diff] [blame] | 558 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 559 | W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0); |
| 560 | W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0); |
| 561 | W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0); |
| 562 | W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0); |
| 563 | |
Vladimir Kondratiev | 9a5511b | 2015-02-15 14:02:31 +0200 | [diff] [blame^] | 564 | W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000003); |
| 565 | W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00008000); /* reset A2 PCIE AHB */ |
Vladimir Kondratiev | 6508281 | 2014-07-14 09:49:37 +0300 | [diff] [blame] | 566 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 567 | W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0); |
| 568 | |
Vladimir Kondratiev | 2cd0f02 | 2015-02-15 14:02:30 +0200 | [diff] [blame] | 569 | /* wait until device ready. typical time is 20..80 msec */ |
Vladimir Kondratiev | 36b10a7 | 2014-03-17 15:34:10 +0200 | [diff] [blame] | 570 | do { |
Vladimir Kondratiev | 520d68e | 2014-08-06 10:31:53 +0300 | [diff] [blame] | 571 | msleep(RST_DELAY); |
Vladimir Kondratiev | 2cd0f02 | 2015-02-15 14:02:30 +0200 | [diff] [blame] | 572 | x = R(RGF_USER_BL + offsetof(struct RGF_BL, ready)); |
Vladimir Kondratiev | 520d68e | 2014-08-06 10:31:53 +0300 | [diff] [blame] | 573 | if (delay++ > RST_COUNT) { |
Vladimir Kondratiev | 2cd0f02 | 2015-02-15 14:02:30 +0200 | [diff] [blame] | 574 | wil_err(wil, "Reset not completed, bl.ready 0x%08x\n", |
Vladimir Kondratiev | 4851629 | 2014-10-28 16:50:07 +0200 | [diff] [blame] | 575 | x); |
Vladimir Kondratiev | bbb2adc | 2014-08-06 10:31:52 +0300 | [diff] [blame] | 576 | return -ETIME; |
Vladimir Kondratiev | 36b10a7 | 2014-03-17 15:34:10 +0200 | [diff] [blame] | 577 | } |
Vladimir Kondratiev | 2cd0f02 | 2015-02-15 14:02:30 +0200 | [diff] [blame] | 578 | } while (!(x & BIT_BL_READY)); |
Vladimir Kondratiev | 36b10a7 | 2014-03-17 15:34:10 +0200 | [diff] [blame] | 579 | |
Vladimir Kondratiev | 972072a | 2014-03-17 15:34:15 +0200 | [diff] [blame] | 580 | C(RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_RST_PWGD); |
| 581 | |
Vladimir Kondratiev | 520d68e | 2014-08-06 10:31:53 +0300 | [diff] [blame] | 582 | wil_dbg_misc(wil, "Reset completed in %d ms\n", delay * RST_DELAY); |
Vladimir Kondratiev | bbb2adc | 2014-08-06 10:31:52 +0300 | [diff] [blame] | 583 | return 0; |
Vladimir Kondratiev | 151a970 | 2014-09-10 16:34:30 +0300 | [diff] [blame] | 584 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 585 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 586 | void wil_mbox_ring_le2cpus(struct wil6210_mbox_ring *r) |
| 587 | { |
| 588 | le32_to_cpus(&r->base); |
| 589 | le16_to_cpus(&r->entry_size); |
| 590 | le16_to_cpus(&r->size); |
| 591 | le32_to_cpus(&r->tail); |
| 592 | le32_to_cpus(&r->head); |
| 593 | } |
| 594 | |
Vladimir Kondratiev | 2cd0f02 | 2015-02-15 14:02:30 +0200 | [diff] [blame] | 595 | static int wil_get_bl_info(struct wil6210_priv *wil) |
| 596 | { |
| 597 | struct net_device *ndev = wil_to_ndev(wil); |
| 598 | struct RGF_BL bl; |
| 599 | |
| 600 | wil_memcpy_fromio_32(&bl, wil->csr + HOSTADDR(RGF_USER_BL), sizeof(bl)); |
| 601 | le32_to_cpus(&bl.ready); |
| 602 | le32_to_cpus(&bl.version); |
| 603 | le32_to_cpus(&bl.rf_type); |
| 604 | le32_to_cpus(&bl.baseband_type); |
| 605 | |
| 606 | if (!is_valid_ether_addr(bl.mac_address)) { |
| 607 | wil_err(wil, "BL: Invalid MAC %pM\n", bl.mac_address); |
| 608 | return -EINVAL; |
| 609 | } |
| 610 | |
| 611 | ether_addr_copy(ndev->perm_addr, bl.mac_address); |
| 612 | if (!is_valid_ether_addr(ndev->dev_addr)) |
| 613 | ether_addr_copy(ndev->dev_addr, bl.mac_address); |
| 614 | wil_info(wil, |
| 615 | "Boot Loader: ver = %d MAC = %pM RF = 0x%08x bband = 0x%08x\n", |
| 616 | bl.version, bl.mac_address, bl.rf_type, bl.baseband_type); |
| 617 | |
| 618 | return 0; |
| 619 | } |
| 620 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 621 | static int wil_wait_for_fw_ready(struct wil6210_priv *wil) |
| 622 | { |
| 623 | ulong to = msecs_to_jiffies(1000); |
| 624 | ulong left = wait_for_completion_timeout(&wil->wmi_ready, to); |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 625 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 626 | if (0 == left) { |
| 627 | wil_err(wil, "Firmware not ready\n"); |
| 628 | return -ETIME; |
| 629 | } else { |
Vladimir Kondratiev | 15e2312 | 2014-04-08 11:36:16 +0300 | [diff] [blame] | 630 | wil_info(wil, "FW ready after %d ms. HW version 0x%08x\n", |
| 631 | jiffies_to_msecs(to-left), wil->hw_version); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 632 | } |
| 633 | return 0; |
| 634 | } |
| 635 | |
| 636 | /* |
| 637 | * We reset all the structures, and we reset the UMAC. |
| 638 | * After calling this routine, you're expected to reload |
| 639 | * the firmware. |
| 640 | */ |
Vladimir Kondratiev | 2cd0f02 | 2015-02-15 14:02:30 +0200 | [diff] [blame] | 641 | int wil_reset(struct wil6210_priv *wil, bool load_fw) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 642 | { |
| 643 | int rc; |
| 644 | |
Vladimir Kondratiev | 9cf10d6 | 2014-09-10 16:34:36 +0300 | [diff] [blame] | 645 | wil_dbg_misc(wil, "%s()\n", __func__); |
| 646 | |
Vladimir Kondratiev | 1aeda13 | 2014-12-23 09:47:18 +0200 | [diff] [blame] | 647 | if (wil->hw_version == HW_VER_UNKNOWN) |
| 648 | return -ENODEV; |
| 649 | |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 650 | WARN_ON(!mutex_is_locked(&wil->mutex)); |
Vladimir Kondratiev | 9419b6a | 2014-12-23 09:47:14 +0200 | [diff] [blame] | 651 | WARN_ON(test_bit(wil_status_napi_en, wil->status)); |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 652 | |
| 653 | cancel_work_sync(&wil->disconnect_worker); |
Vladimir Kondratiev | 4821e6d | 2014-12-01 15:33:15 +0200 | [diff] [blame] | 654 | wil6210_disconnect(wil, NULL, WLAN_REASON_DEAUTH_LEAVING, false); |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 655 | |
Vladimir Kondratiev | 9419b6a | 2014-12-23 09:47:14 +0200 | [diff] [blame] | 656 | /* prevent NAPI from being scheduled */ |
| 657 | bitmap_zero(wil->status, wil_status_last); |
Vladimir Kondratiev | 0fef181 | 2014-03-17 15:34:18 +0200 | [diff] [blame] | 658 | |
Vladimir Kondratiev | ed6f9dc | 2014-03-17 15:34:19 +0200 | [diff] [blame] | 659 | if (wil->scan_request) { |
| 660 | wil_dbg_misc(wil, "Abort scan_request 0x%p\n", |
| 661 | wil->scan_request); |
Vladimir Kondratiev | 047e5d7 | 2014-05-27 14:45:48 +0300 | [diff] [blame] | 662 | del_timer_sync(&wil->scan_timer); |
Vladimir Kondratiev | ed6f9dc | 2014-03-17 15:34:19 +0200 | [diff] [blame] | 663 | cfg80211_scan_done(wil->scan_request, true); |
| 664 | wil->scan_request = NULL; |
| 665 | } |
| 666 | |
Vladimir Kondratiev | e4dbb09 | 2014-09-10 16:34:49 +0300 | [diff] [blame] | 667 | wil_mask_irq(wil); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 668 | |
Vladimir Kondratiev | e08b590 | 2013-01-28 18:31:05 +0200 | [diff] [blame] | 669 | wmi_event_flush(wil); |
| 670 | |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 671 | flush_workqueue(wil->wq_service); |
Vladimir Kondratiev | e08b590 | 2013-01-28 18:31:05 +0200 | [diff] [blame] | 672 | flush_workqueue(wil->wmi_wq); |
| 673 | |
Vladimir Kondratiev | bbb2adc | 2014-08-06 10:31:52 +0300 | [diff] [blame] | 674 | rc = wil_target_reset(wil); |
Vladimir Kondratiev | 8bf6adb | 2014-03-17 15:34:17 +0200 | [diff] [blame] | 675 | wil_rx_fini(wil); |
Vladimir Kondratiev | bbb2adc | 2014-08-06 10:31:52 +0300 | [diff] [blame] | 676 | if (rc) |
| 677 | return rc; |
| 678 | |
Vladimir Kondratiev | 2cd0f02 | 2015-02-15 14:02:30 +0200 | [diff] [blame] | 679 | rc = wil_get_bl_info(wil); |
| 680 | if (rc) |
| 681 | return rc; |
| 682 | |
| 683 | if (load_fw) { |
| 684 | wil_info(wil, "Use firmware <%s> + board <%s>\n", WIL_FW_NAME, |
| 685 | WIL_FW2_NAME); |
| 686 | |
Vladimir Kondratiev | 151a970 | 2014-09-10 16:34:30 +0300 | [diff] [blame] | 687 | wil_halt_cpu(wil); |
| 688 | /* Loading f/w from the file */ |
| 689 | rc = wil_request_firmware(wil, WIL_FW_NAME); |
| 690 | if (rc) |
| 691 | return rc; |
Vladimir Kondratiev | 2cd0f02 | 2015-02-15 14:02:30 +0200 | [diff] [blame] | 692 | rc = wil_request_firmware(wil, WIL_FW2_NAME); |
| 693 | if (rc) |
| 694 | return rc; |
Vladimir Kondratiev | 151a970 | 2014-09-10 16:34:30 +0300 | [diff] [blame] | 695 | |
Vladimir Kondratiev | 2cd0f02 | 2015-02-15 14:02:30 +0200 | [diff] [blame] | 696 | /* Mark FW as loaded from host */ |
| 697 | S(RGF_USER_USAGE_6, 1); |
| 698 | |
| 699 | /* clear any interrupts which on-card-firmware |
| 700 | * may have set |
| 701 | */ |
Vladimir Kondratiev | 151a970 | 2014-09-10 16:34:30 +0300 | [diff] [blame] | 702 | wil6210_clear_irq(wil); |
Vladimir Kondratiev | 2cd0f02 | 2015-02-15 14:02:30 +0200 | [diff] [blame] | 703 | /* CAF_ICR - clear and mask */ |
| 704 | /* it is W1C, clear by writing back same value */ |
| 705 | S(RGF_CAF_ICR + offsetof(struct RGF_ICR, ICR), 0); |
| 706 | W(RGF_CAF_ICR + offsetof(struct RGF_ICR, IMV), ~0); |
Vladimir Kondratiev | 151a970 | 2014-09-10 16:34:30 +0300 | [diff] [blame] | 707 | |
Vladimir Kondratiev | 151a970 | 2014-09-10 16:34:30 +0300 | [diff] [blame] | 708 | wil_release_cpu(wil); |
Vladimir Kondratiev | 151a970 | 2014-09-10 16:34:30 +0300 | [diff] [blame] | 709 | } |
Vladimir Kondratiev | 8bf6adb | 2014-03-17 15:34:17 +0200 | [diff] [blame] | 710 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 711 | /* init after reset */ |
| 712 | wil->pending_connect_cid = -1; |
Wolfram Sang | 16735d0 | 2013-11-14 14:32:02 -0800 | [diff] [blame] | 713 | reinit_completion(&wil->wmi_ready); |
Dedy Lansky | 5950264 | 2014-09-10 16:34:46 +0300 | [diff] [blame] | 714 | reinit_completion(&wil->wmi_call); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 715 | |
Vladimir Kondratiev | 2cd0f02 | 2015-02-15 14:02:30 +0200 | [diff] [blame] | 716 | if (load_fw) { |
| 717 | wil_configure_interrupt_moderation(wil); |
| 718 | wil_unmask_irq(wil); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 719 | |
Vladimir Kondratiev | 2cd0f02 | 2015-02-15 14:02:30 +0200 | [diff] [blame] | 720 | /* we just started MAC, wait for FW ready */ |
| 721 | rc = wil_wait_for_fw_ready(wil); |
| 722 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 723 | |
| 724 | return rc; |
| 725 | } |
| 726 | |
Vladimir Kondratiev | 2cd0f02 | 2015-02-15 14:02:30 +0200 | [diff] [blame] | 727 | #undef R |
| 728 | #undef W |
| 729 | #undef S |
| 730 | #undef C |
| 731 | |
Vladimir Kondratiev | ed6f9dc | 2014-03-17 15:34:19 +0200 | [diff] [blame] | 732 | void wil_fw_error_recovery(struct wil6210_priv *wil) |
| 733 | { |
| 734 | wil_dbg_misc(wil, "starting fw error recovery\n"); |
Vladimir Kondratiev | c33407a | 2014-10-01 15:05:24 +0300 | [diff] [blame] | 735 | wil->recovery_state = fw_recovery_pending; |
Vladimir Kondratiev | ed6f9dc | 2014-03-17 15:34:19 +0200 | [diff] [blame] | 736 | schedule_work(&wil->fw_error_worker); |
| 737 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 738 | |
Vladimir Kondratiev | 73d839a | 2014-09-10 16:34:50 +0300 | [diff] [blame] | 739 | int __wil_up(struct wil6210_priv *wil) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 740 | { |
| 741 | struct net_device *ndev = wil_to_ndev(wil); |
| 742 | struct wireless_dev *wdev = wil->wdev; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 743 | int rc; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 744 | |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 745 | WARN_ON(!mutex_is_locked(&wil->mutex)); |
| 746 | |
Vladimir Kondratiev | 2cd0f02 | 2015-02-15 14:02:30 +0200 | [diff] [blame] | 747 | rc = wil_reset(wil, true); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 748 | if (rc) |
| 749 | return rc; |
| 750 | |
Vladimir Kondratiev | e31b256 | 2013-06-09 09:12:55 +0300 | [diff] [blame] | 751 | /* Rx VRING. After MAC and beacon */ |
Vladimir Kondratiev | d3762b4 | 2014-12-01 15:35:02 +0200 | [diff] [blame] | 752 | rc = wil_rx_init(wil, 1 << rx_ring_order); |
Vladimir Kondratiev | e31b256 | 2013-06-09 09:12:55 +0300 | [diff] [blame] | 753 | if (rc) |
| 754 | return rc; |
| 755 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 756 | switch (wdev->iftype) { |
| 757 | case NL80211_IFTYPE_STATION: |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 758 | wil_dbg_misc(wil, "type: STATION\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 759 | ndev->type = ARPHRD_ETHER; |
| 760 | break; |
| 761 | case NL80211_IFTYPE_AP: |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 762 | wil_dbg_misc(wil, "type: AP\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 763 | ndev->type = ARPHRD_ETHER; |
| 764 | break; |
| 765 | case NL80211_IFTYPE_P2P_CLIENT: |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 766 | wil_dbg_misc(wil, "type: P2P_CLIENT\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 767 | ndev->type = ARPHRD_ETHER; |
| 768 | break; |
| 769 | case NL80211_IFTYPE_P2P_GO: |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 770 | wil_dbg_misc(wil, "type: P2P_GO\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 771 | ndev->type = ARPHRD_ETHER; |
| 772 | break; |
| 773 | case NL80211_IFTYPE_MONITOR: |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 774 | wil_dbg_misc(wil, "type: Monitor\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 775 | ndev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 776 | /* ARPHRD_IEEE80211 or ARPHRD_IEEE80211_RADIOTAP ? */ |
| 777 | break; |
| 778 | default: |
| 779 | return -EOPNOTSUPP; |
| 780 | } |
| 781 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 782 | /* MAC address - pre-requisite for other commands */ |
| 783 | wmi_set_mac_address(wil, ndev->dev_addr); |
| 784 | |
Vladimir Kondratiev | 73d839a | 2014-09-10 16:34:50 +0300 | [diff] [blame] | 785 | wil_dbg_misc(wil, "NAPI enable\n"); |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 786 | napi_enable(&wil->napi_rx); |
| 787 | napi_enable(&wil->napi_tx); |
Vladimir Kondratiev | 9419b6a | 2014-12-23 09:47:14 +0200 | [diff] [blame] | 788 | set_bit(wil_status_napi_en, wil->status); |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 789 | |
Vladimir Kondratiev | f772ebf | 2014-09-10 16:34:35 +0300 | [diff] [blame] | 790 | if (wil->platform_ops.bus_request) |
| 791 | wil->platform_ops.bus_request(wil->platform_handle, |
| 792 | WIL_MAX_BUS_REQUEST_KBPS); |
| 793 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 794 | return 0; |
| 795 | } |
| 796 | |
| 797 | int wil_up(struct wil6210_priv *wil) |
| 798 | { |
| 799 | int rc; |
| 800 | |
Vladimir Kondratiev | 9cf10d6 | 2014-09-10 16:34:36 +0300 | [diff] [blame] | 801 | wil_dbg_misc(wil, "%s()\n", __func__); |
| 802 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 803 | mutex_lock(&wil->mutex); |
| 804 | rc = __wil_up(wil); |
| 805 | mutex_unlock(&wil->mutex); |
| 806 | |
| 807 | return rc; |
| 808 | } |
| 809 | |
Vladimir Kondratiev | 73d839a | 2014-09-10 16:34:50 +0300 | [diff] [blame] | 810 | int __wil_down(struct wil6210_priv *wil) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 811 | { |
Dedy Lansky | f172b56 | 2014-09-10 16:34:38 +0300 | [diff] [blame] | 812 | int iter = WAIT_FOR_DISCONNECT_TIMEOUT_MS / |
| 813 | WAIT_FOR_DISCONNECT_INTERVAL_MS; |
| 814 | |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 815 | WARN_ON(!mutex_is_locked(&wil->mutex)); |
| 816 | |
Vladimir Kondratiev | f772ebf | 2014-09-10 16:34:35 +0300 | [diff] [blame] | 817 | if (wil->platform_ops.bus_request) |
| 818 | wil->platform_ops.bus_request(wil->platform_handle, 0); |
| 819 | |
Vladimir Kondratiev | 73d839a | 2014-09-10 16:34:50 +0300 | [diff] [blame] | 820 | wil_disable_irq(wil); |
Vladimir Kondratiev | 9419b6a | 2014-12-23 09:47:14 +0200 | [diff] [blame] | 821 | if (test_and_clear_bit(wil_status_napi_en, wil->status)) { |
Vladimir Kondratiev | 73d839a | 2014-09-10 16:34:50 +0300 | [diff] [blame] | 822 | napi_disable(&wil->napi_rx); |
| 823 | napi_disable(&wil->napi_tx); |
| 824 | wil_dbg_misc(wil, "NAPI disable\n"); |
| 825 | } |
| 826 | wil_enable_irq(wil); |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 827 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 828 | if (wil->scan_request) { |
Vladimir Kondratiev | 2a91d7d | 2014-06-16 19:37:11 +0300 | [diff] [blame] | 829 | wil_dbg_misc(wil, "Abort scan_request 0x%p\n", |
| 830 | wil->scan_request); |
Vladimir Kondratiev | 047e5d7 | 2014-05-27 14:45:48 +0300 | [diff] [blame] | 831 | del_timer_sync(&wil->scan_timer); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 832 | cfg80211_scan_done(wil->scan_request, true); |
| 833 | wil->scan_request = NULL; |
| 834 | } |
| 835 | |
Vladimir Kondratiev | 9419b6a | 2014-12-23 09:47:14 +0200 | [diff] [blame] | 836 | if (test_bit(wil_status_fwconnected, wil->status) || |
| 837 | test_bit(wil_status_fwconnecting, wil->status)) |
Dedy Lansky | f172b56 | 2014-09-10 16:34:38 +0300 | [diff] [blame] | 838 | wmi_send(wil, WMI_DISCONNECT_CMDID, NULL, 0); |
| 839 | |
| 840 | /* make sure wil is idle (not connected) */ |
| 841 | mutex_unlock(&wil->mutex); |
| 842 | while (iter--) { |
Vladimir Kondratiev | 9419b6a | 2014-12-23 09:47:14 +0200 | [diff] [blame] | 843 | int idle = !test_bit(wil_status_fwconnected, wil->status) && |
| 844 | !test_bit(wil_status_fwconnecting, wil->status); |
Dedy Lansky | f172b56 | 2014-09-10 16:34:38 +0300 | [diff] [blame] | 845 | if (idle) |
| 846 | break; |
| 847 | msleep(WAIT_FOR_DISCONNECT_INTERVAL_MS); |
| 848 | } |
| 849 | mutex_lock(&wil->mutex); |
| 850 | |
| 851 | if (!iter) |
| 852 | wil_err(wil, "timeout waiting for idle FW/HW\n"); |
| 853 | |
Vladimir Kondratiev | 2cd0f02 | 2015-02-15 14:02:30 +0200 | [diff] [blame] | 854 | wil_reset(wil, false); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 855 | |
| 856 | return 0; |
| 857 | } |
| 858 | |
| 859 | int wil_down(struct wil6210_priv *wil) |
| 860 | { |
| 861 | int rc; |
| 862 | |
Vladimir Kondratiev | 9cf10d6 | 2014-09-10 16:34:36 +0300 | [diff] [blame] | 863 | wil_dbg_misc(wil, "%s()\n", __func__); |
| 864 | |
Vladimir Kondratiev | c33407a | 2014-10-01 15:05:24 +0300 | [diff] [blame] | 865 | wil_set_recovery_state(wil, fw_recovery_idle); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 866 | mutex_lock(&wil->mutex); |
| 867 | rc = __wil_down(wil); |
| 868 | mutex_unlock(&wil->mutex); |
| 869 | |
| 870 | return rc; |
| 871 | } |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 872 | |
| 873 | int wil_find_cid(struct wil6210_priv *wil, const u8 *mac) |
| 874 | { |
| 875 | int i; |
| 876 | int rc = -ENOENT; |
| 877 | |
| 878 | for (i = 0; i < ARRAY_SIZE(wil->sta); i++) { |
| 879 | if ((wil->sta[i].status != wil_sta_unused) && |
Vladimir Kondratiev | 108d1eb | 2014-02-27 16:20:53 +0200 | [diff] [blame] | 880 | ether_addr_equal(wil->sta[i].addr, mac)) { |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 881 | rc = i; |
| 882 | break; |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | return rc; |
| 887 | } |