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