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