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