wil6210: fix for memory corruption upon rmmod
[deliverable/linux.git] / drivers / net / wireless / ath / wil6210 / main.c
1 /*
2 * Copyright (c) 2012-2014 Qualcomm Atheros, Inc.
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
17 #include <linux/moduleparam.h>
18 #include <linux/if_arp.h>
19 #include <linux/etherdevice.h>
20
21 #include "wil6210.h"
22 #include "txrx.h"
23 #include "wmi.h"
24
25 #define WAIT_FOR_DISCONNECT_TIMEOUT_MS 2000
26 #define WAIT_FOR_DISCONNECT_INTERVAL_MS 10
27
28 static bool no_fw_recovery;
29 module_param(no_fw_recovery, bool, S_IRUGO | S_IWUSR);
30 MODULE_PARM_DESC(no_fw_recovery, " disable FW error recovery");
31
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
36 #define RST_DELAY (20) /* msec, for loop in @wil_target_reset */
37 #define RST_COUNT (1 + 1000/RST_DELAY) /* round up to be above 1 sec total */
38
39 /*
40 * Due to a hardware issue,
41 * one has to read/write to/from NIC in 32-bit chunks;
42 * regular memcpy_fromio and siblings will
43 * not work on 64-bit platform - it uses 64-bit transactions
44 *
45 * Force 32-bit transactions to enable NIC on 64-bit platforms
46 *
47 * To avoid byte swap on big endian host, __raw_{read|write}l
48 * should be used - {read|write}l would swap bytes to provide
49 * little endian on PCI value in host endianness.
50 */
51 void wil_memcpy_fromio_32(void *dst, const volatile void __iomem *src,
52 size_t count)
53 {
54 u32 *d = dst;
55 const volatile u32 __iomem *s = src;
56
57 /* size_t is unsigned, if (count%4 != 0) it will wrap */
58 for (count += 4; count > 4; count -= 4)
59 *d++ = __raw_readl(s++);
60 }
61
62 void wil_memcpy_toio_32(volatile void __iomem *dst, const void *src,
63 size_t count)
64 {
65 volatile u32 __iomem *d = dst;
66 const u32 *s = src;
67
68 for (count += 4; count > 4; count -= 4)
69 __raw_writel(*s++, d++);
70 }
71
72 static void wil_disconnect_cid(struct wil6210_priv *wil, int cid)
73 {
74 uint i;
75 struct net_device *ndev = wil_to_ndev(wil);
76 struct wireless_dev *wdev = wil->wdev;
77 struct wil_sta_info *sta = &wil->sta[cid];
78
79 wil_dbg_misc(wil, "%s(CID %d, status %d)\n", __func__, cid,
80 sta->status);
81
82 sta->data_port_open = false;
83 if (sta->status != wil_sta_unused) {
84 wmi_disconnect_sta(wil, sta->addr, WLAN_REASON_DEAUTH_LEAVING);
85 switch (wdev->iftype) {
86 case NL80211_IFTYPE_AP:
87 case NL80211_IFTYPE_P2P_GO:
88 /* AP-like interface */
89 cfg80211_del_sta(ndev, sta->addr, GFP_KERNEL);
90 break;
91 default:
92 break;
93 }
94 sta->status = wil_sta_unused;
95 }
96
97 for (i = 0; i < WIL_STA_TID_NUM; i++) {
98 struct wil_tid_ampdu_rx *r = sta->tid_rx[i];
99 sta->tid_rx[i] = NULL;
100 wil_tid_ampdu_rx_free(wil, r);
101 }
102 for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
103 if (wil->vring2cid_tid[i][0] == cid)
104 wil_vring_fini_tx(wil, i);
105 }
106 memset(&sta->stats, 0, sizeof(sta->stats));
107 }
108
109 static void _wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid)
110 {
111 int cid = -ENOENT;
112 struct net_device *ndev = wil_to_ndev(wil);
113 struct wireless_dev *wdev = wil->wdev;
114
115 might_sleep();
116 if (bssid) {
117 cid = wil_find_cid(wil, bssid);
118 wil_dbg_misc(wil, "%s(%pM, CID %d)\n", __func__, bssid, cid);
119 } else {
120 wil_dbg_misc(wil, "%s(all)\n", __func__);
121 }
122
123 if (cid >= 0) /* disconnect 1 peer */
124 wil_disconnect_cid(wil, cid);
125 else /* disconnect all */
126 for (cid = 0; cid < WIL6210_MAX_CID; cid++)
127 wil_disconnect_cid(wil, cid);
128
129 /* link state */
130 switch (wdev->iftype) {
131 case NL80211_IFTYPE_STATION:
132 case NL80211_IFTYPE_P2P_CLIENT:
133 wil_link_off(wil);
134 if (test_bit(wil_status_fwconnected, &wil->status)) {
135 clear_bit(wil_status_fwconnected, &wil->status);
136 cfg80211_disconnected(ndev,
137 WLAN_STATUS_UNSPECIFIED_FAILURE,
138 NULL, 0, GFP_KERNEL);
139 } else if (test_bit(wil_status_fwconnecting, &wil->status)) {
140 cfg80211_connect_result(ndev, bssid, NULL, 0, NULL, 0,
141 WLAN_STATUS_UNSPECIFIED_FAILURE,
142 GFP_KERNEL);
143 }
144 clear_bit(wil_status_fwconnecting, &wil->status);
145 break;
146 default:
147 break;
148 }
149 }
150
151 static void wil_disconnect_worker(struct work_struct *work)
152 {
153 struct wil6210_priv *wil = container_of(work,
154 struct wil6210_priv, disconnect_worker);
155
156 mutex_lock(&wil->mutex);
157 _wil6210_disconnect(wil, NULL);
158 mutex_unlock(&wil->mutex);
159 }
160
161 static void wil_connect_timer_fn(ulong x)
162 {
163 struct wil6210_priv *wil = (void *)x;
164
165 wil_dbg_misc(wil, "Connect timeout\n");
166
167 /* reschedule to thread context - disconnect won't
168 * run from atomic context
169 */
170 schedule_work(&wil->disconnect_worker);
171 }
172
173 static void wil_scan_timer_fn(ulong x)
174 {
175 struct wil6210_priv *wil = (void *)x;
176
177 clear_bit(wil_status_fwready, &wil->status);
178 wil_err(wil, "Scan timeout detected, start fw error recovery\n");
179 schedule_work(&wil->fw_error_worker);
180 }
181
182 static void wil_fw_error_worker(struct work_struct *work)
183 {
184 struct wil6210_priv *wil = container_of(work,
185 struct wil6210_priv, fw_error_worker);
186 struct wireless_dev *wdev = wil->wdev;
187
188 wil_dbg_misc(wil, "fw error worker\n");
189
190 if (no_fw_recovery)
191 return;
192
193 /* increment @recovery_count if less then WIL6210_FW_RECOVERY_TO
194 * passed since last recovery attempt
195 */
196 if (time_is_after_jiffies(wil->last_fw_recovery +
197 WIL6210_FW_RECOVERY_TO))
198 wil->recovery_count++;
199 else
200 wil->recovery_count = 1; /* fw was alive for a long time */
201
202 if (wil->recovery_count > WIL6210_FW_RECOVERY_RETRIES) {
203 wil_err(wil, "too many recovery attempts (%d), giving up\n",
204 wil->recovery_count);
205 return;
206 }
207
208 wil->last_fw_recovery = jiffies;
209
210 mutex_lock(&wil->mutex);
211 switch (wdev->iftype) {
212 case NL80211_IFTYPE_STATION:
213 case NL80211_IFTYPE_P2P_CLIENT:
214 case NL80211_IFTYPE_MONITOR:
215 wil_info(wil, "fw error recovery started (try %d)...\n",
216 wil->recovery_count);
217 wil_reset(wil);
218
219 /* need to re-allocate Rx ring after reset */
220 wil_rx_init(wil);
221 break;
222 case NL80211_IFTYPE_AP:
223 case NL80211_IFTYPE_P2P_GO:
224 /* recovery in these modes is done by upper layers */
225 break;
226 default:
227 break;
228 }
229 mutex_unlock(&wil->mutex);
230 }
231
232 static int wil_find_free_vring(struct wil6210_priv *wil)
233 {
234 int i;
235
236 for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) {
237 if (!wil->vring_tx[i].va)
238 return i;
239 }
240 return -EINVAL;
241 }
242
243 static void wil_connect_worker(struct work_struct *work)
244 {
245 int rc;
246 struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
247 connect_worker);
248 int cid = wil->pending_connect_cid;
249 int ringid = wil_find_free_vring(wil);
250
251 if (cid < 0) {
252 wil_err(wil, "No connection pending\n");
253 return;
254 }
255
256 wil_dbg_wmi(wil, "Configure for connection CID %d\n", cid);
257
258 rc = wil_vring_init_tx(wil, ringid, WIL6210_TX_RING_SIZE, cid, 0);
259 wil->pending_connect_cid = -1;
260 if (rc == 0) {
261 wil->sta[cid].status = wil_sta_connected;
262 wil_link_on(wil);
263 } else {
264 wil->sta[cid].status = wil_sta_unused;
265 }
266 }
267
268 int wil_priv_init(struct wil6210_priv *wil)
269 {
270 wil_dbg_misc(wil, "%s()\n", __func__);
271
272 memset(wil->sta, 0, sizeof(wil->sta));
273
274 mutex_init(&wil->mutex);
275 mutex_init(&wil->wmi_mutex);
276
277 init_completion(&wil->wmi_ready);
278
279 wil->pending_connect_cid = -1;
280 setup_timer(&wil->connect_timer, wil_connect_timer_fn, (ulong)wil);
281 setup_timer(&wil->scan_timer, wil_scan_timer_fn, (ulong)wil);
282
283 INIT_WORK(&wil->connect_worker, wil_connect_worker);
284 INIT_WORK(&wil->disconnect_worker, wil_disconnect_worker);
285 INIT_WORK(&wil->wmi_event_worker, wmi_event_worker);
286 INIT_WORK(&wil->fw_error_worker, wil_fw_error_worker);
287
288 INIT_LIST_HEAD(&wil->pending_wmi_ev);
289 spin_lock_init(&wil->wmi_ev_lock);
290
291 wil->wmi_wq = create_singlethread_workqueue(WIL_NAME"_wmi");
292 if (!wil->wmi_wq)
293 return -EAGAIN;
294
295 wil->wmi_wq_conn = create_singlethread_workqueue(WIL_NAME"_connect");
296 if (!wil->wmi_wq_conn) {
297 destroy_workqueue(wil->wmi_wq);
298 return -EAGAIN;
299 }
300
301 wil->last_fw_recovery = jiffies;
302
303 return 0;
304 }
305
306 void wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid)
307 {
308 wil_dbg_misc(wil, "%s()\n", __func__);
309
310 del_timer_sync(&wil->connect_timer);
311 _wil6210_disconnect(wil, bssid);
312 }
313
314 void wil_priv_deinit(struct wil6210_priv *wil)
315 {
316 wil_dbg_misc(wil, "%s()\n", __func__);
317
318 del_timer_sync(&wil->scan_timer);
319 cancel_work_sync(&wil->disconnect_worker);
320 cancel_work_sync(&wil->fw_error_worker);
321 mutex_lock(&wil->mutex);
322 wil6210_disconnect(wil, NULL);
323 mutex_unlock(&wil->mutex);
324 wmi_event_flush(wil);
325 destroy_workqueue(wil->wmi_wq_conn);
326 destroy_workqueue(wil->wmi_wq);
327 }
328
329 /* target operations */
330 /* register read */
331 #define R(a) ioread32(wil->csr + HOSTADDR(a))
332 /* register write. wmb() to make sure it is completed */
333 #define W(a, v) do { iowrite32(v, wil->csr + HOSTADDR(a)); wmb(); } while (0)
334 /* register set = read, OR, write */
335 #define S(a, v) W(a, R(a) | v)
336 /* register clear = read, AND with inverted, write */
337 #define C(a, v) W(a, R(a) & ~v)
338
339 static inline void wil_halt_cpu(struct wil6210_priv *wil)
340 {
341 W(RGF_USER_USER_CPU_0, BIT_USER_USER_CPU_MAN_RST);
342 W(RGF_USER_MAC_CPU_0, BIT_USER_MAC_CPU_MAN_RST);
343 }
344
345 static inline void wil_release_cpu(struct wil6210_priv *wil)
346 {
347 /* Start CPU */
348 W(RGF_USER_USER_CPU_0, 1);
349 }
350
351 static int wil_target_reset(struct wil6210_priv *wil)
352 {
353 int delay = 0;
354 u32 hw_state;
355 u32 rev_id;
356 bool is_sparrow = (wil->board->board == WIL_BOARD_SPARROW);
357
358 wil_dbg_misc(wil, "Resetting \"%s\"...\n", wil->board->name);
359
360 wil->hw_version = R(RGF_USER_FW_REV_ID);
361 rev_id = wil->hw_version & 0xff;
362
363 /* Clear MAC link up */
364 S(RGF_HP_CTRL, BIT(15));
365 S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT_HPAL_PERST_FROM_PAD);
366 S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT_CAR_PERST_RST);
367
368 wil_halt_cpu(wil);
369 C(RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_CAR_AHB_SW_SEL); /* 40 MHz */
370
371 if (is_sparrow) {
372 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x3ff81f);
373 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0xf);
374 }
375
376 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0xFE000000);
377 W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0x0000003F);
378 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, is_sparrow ? 0x000000f0 : 0x00000170);
379 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0xFFE7FE00);
380
381 if (is_sparrow) {
382 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x0);
383 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0x0);
384 }
385
386 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0);
387 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0);
388 W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0);
389 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
390
391 if (is_sparrow) {
392 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000003);
393 /* reset A2 PCIE AHB */
394 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00008000);
395 } else {
396 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000001);
397 if (rev_id == 1) {
398 /* reset A1 BOTH PCIE AHB & PCIE RGF */
399 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00000080);
400 } else {
401 W(RGF_PCIE_LOS_COUNTER_CTL, BIT(6) | BIT(8));
402 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00008000);
403 }
404 }
405
406 /* TODO: check order here!!! Erez code is different */
407 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
408
409 /* wait until device ready. typical time is 200..250 msec */
410 do {
411 msleep(RST_DELAY);
412 hw_state = R(RGF_USER_HW_MACHINE_STATE);
413 if (delay++ > RST_COUNT) {
414 wil_err(wil, "Reset not completed, hw_state 0x%08x\n",
415 hw_state);
416 return -ETIME;
417 }
418 } while (hw_state != HW_MACHINE_BOOT_DONE);
419
420 /* TODO: Erez check rev_id != 1 */
421 if (!is_sparrow && (rev_id != 1))
422 W(RGF_PCIE_LOS_COUNTER_CTL, BIT(8));
423
424 C(RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_RST_PWGD);
425
426 wil_dbg_misc(wil, "Reset completed in %d ms\n", delay * RST_DELAY);
427 return 0;
428 }
429
430 #undef R
431 #undef W
432 #undef S
433 #undef C
434
435 void wil_mbox_ring_le2cpus(struct wil6210_mbox_ring *r)
436 {
437 le32_to_cpus(&r->base);
438 le16_to_cpus(&r->entry_size);
439 le16_to_cpus(&r->size);
440 le32_to_cpus(&r->tail);
441 le32_to_cpus(&r->head);
442 }
443
444 static int wil_wait_for_fw_ready(struct wil6210_priv *wil)
445 {
446 ulong to = msecs_to_jiffies(1000);
447 ulong left = wait_for_completion_timeout(&wil->wmi_ready, to);
448
449 if (0 == left) {
450 wil_err(wil, "Firmware not ready\n");
451 return -ETIME;
452 } else {
453 wil_info(wil, "FW ready after %d ms. HW version 0x%08x\n",
454 jiffies_to_msecs(to-left), wil->hw_version);
455 }
456 return 0;
457 }
458
459 /*
460 * We reset all the structures, and we reset the UMAC.
461 * After calling this routine, you're expected to reload
462 * the firmware.
463 */
464 int wil_reset(struct wil6210_priv *wil)
465 {
466 int rc;
467
468 wil_dbg_misc(wil, "%s()\n", __func__);
469
470 WARN_ON(!mutex_is_locked(&wil->mutex));
471
472 cancel_work_sync(&wil->disconnect_worker);
473 wil6210_disconnect(wil, NULL);
474
475 wil->status = 0; /* prevent NAPI from being scheduled */
476 if (test_bit(wil_status_napi_en, &wil->status))
477 napi_synchronize(&wil->napi_rx);
478
479 if (wil->scan_request) {
480 wil_dbg_misc(wil, "Abort scan_request 0x%p\n",
481 wil->scan_request);
482 del_timer_sync(&wil->scan_timer);
483 cfg80211_scan_done(wil->scan_request, true);
484 wil->scan_request = NULL;
485 }
486
487 wil6210_disable_irq(wil);
488
489 wmi_event_flush(wil);
490
491 flush_workqueue(wil->wmi_wq_conn);
492 flush_workqueue(wil->wmi_wq);
493
494 rc = wil_target_reset(wil);
495 wil_rx_fini(wil);
496 if (rc)
497 return rc;
498
499 if (!no_fw_load) {
500 wil_info(wil, "Use firmware <%s>\n", WIL_FW_NAME);
501 wil_halt_cpu(wil);
502 /* Loading f/w from the file */
503 rc = wil_request_firmware(wil, WIL_FW_NAME);
504 if (rc)
505 return rc;
506
507 /* clear any interrupts which on-card-firmware may have set */
508 wil6210_clear_irq(wil);
509 { /* CAF_ICR - clear and mask */
510 u32 a = HOSTADDR(RGF_CAF_ICR) +
511 offsetof(struct RGF_ICR, ICR);
512 u32 m = HOSTADDR(RGF_CAF_ICR) +
513 offsetof(struct RGF_ICR, IMV);
514 u32 icr = ioread32(wil->csr + a);
515
516 iowrite32(icr, wil->csr + a); /* W1C */
517 iowrite32(~0, wil->csr + m);
518 wmb(); /* wait for completion */
519 }
520 wil_release_cpu(wil);
521 } else {
522 wil_info(wil, "Use firmware from on-card flash\n");
523 }
524
525 /* init after reset */
526 wil->pending_connect_cid = -1;
527 reinit_completion(&wil->wmi_ready);
528
529 wil6210_enable_irq(wil);
530
531 /* we just started MAC, wait for FW ready */
532 rc = wil_wait_for_fw_ready(wil);
533
534 return rc;
535 }
536
537 void wil_fw_error_recovery(struct wil6210_priv *wil)
538 {
539 wil_dbg_misc(wil, "starting fw error recovery\n");
540 schedule_work(&wil->fw_error_worker);
541 }
542
543 void wil_link_on(struct wil6210_priv *wil)
544 {
545 struct net_device *ndev = wil_to_ndev(wil);
546
547 wil_dbg_misc(wil, "%s()\n", __func__);
548
549 netif_carrier_on(ndev);
550 wil_dbg_misc(wil, "netif_tx_wake : link on\n");
551 netif_tx_wake_all_queues(ndev);
552 }
553
554 void wil_link_off(struct wil6210_priv *wil)
555 {
556 struct net_device *ndev = wil_to_ndev(wil);
557
558 wil_dbg_misc(wil, "%s()\n", __func__);
559
560 netif_tx_stop_all_queues(ndev);
561 wil_dbg_misc(wil, "netif_tx_stop : link off\n");
562 netif_carrier_off(ndev);
563 }
564
565 static int __wil_up(struct wil6210_priv *wil)
566 {
567 struct net_device *ndev = wil_to_ndev(wil);
568 struct wireless_dev *wdev = wil->wdev;
569 int rc;
570
571 WARN_ON(!mutex_is_locked(&wil->mutex));
572
573 rc = wil_reset(wil);
574 if (rc)
575 return rc;
576
577 /* Rx VRING. After MAC and beacon */
578 rc = wil_rx_init(wil);
579 if (rc)
580 return rc;
581
582 switch (wdev->iftype) {
583 case NL80211_IFTYPE_STATION:
584 wil_dbg_misc(wil, "type: STATION\n");
585 ndev->type = ARPHRD_ETHER;
586 break;
587 case NL80211_IFTYPE_AP:
588 wil_dbg_misc(wil, "type: AP\n");
589 ndev->type = ARPHRD_ETHER;
590 break;
591 case NL80211_IFTYPE_P2P_CLIENT:
592 wil_dbg_misc(wil, "type: P2P_CLIENT\n");
593 ndev->type = ARPHRD_ETHER;
594 break;
595 case NL80211_IFTYPE_P2P_GO:
596 wil_dbg_misc(wil, "type: P2P_GO\n");
597 ndev->type = ARPHRD_ETHER;
598 break;
599 case NL80211_IFTYPE_MONITOR:
600 wil_dbg_misc(wil, "type: Monitor\n");
601 ndev->type = ARPHRD_IEEE80211_RADIOTAP;
602 /* ARPHRD_IEEE80211 or ARPHRD_IEEE80211_RADIOTAP ? */
603 break;
604 default:
605 return -EOPNOTSUPP;
606 }
607
608 /* MAC address - pre-requisite for other commands */
609 wmi_set_mac_address(wil, ndev->dev_addr);
610
611
612 napi_enable(&wil->napi_rx);
613 napi_enable(&wil->napi_tx);
614 set_bit(wil_status_napi_en, &wil->status);
615
616 if (wil->platform_ops.bus_request)
617 wil->platform_ops.bus_request(wil->platform_handle,
618 WIL_MAX_BUS_REQUEST_KBPS);
619
620 return 0;
621 }
622
623 int wil_up(struct wil6210_priv *wil)
624 {
625 int rc;
626
627 wil_dbg_misc(wil, "%s()\n", __func__);
628
629 mutex_lock(&wil->mutex);
630 rc = __wil_up(wil);
631 mutex_unlock(&wil->mutex);
632
633 return rc;
634 }
635
636 static int __wil_down(struct wil6210_priv *wil)
637 {
638 int iter = WAIT_FOR_DISCONNECT_TIMEOUT_MS /
639 WAIT_FOR_DISCONNECT_INTERVAL_MS;
640
641 WARN_ON(!mutex_is_locked(&wil->mutex));
642
643 if (wil->platform_ops.bus_request)
644 wil->platform_ops.bus_request(wil->platform_handle, 0);
645
646 clear_bit(wil_status_napi_en, &wil->status);
647 napi_disable(&wil->napi_rx);
648 napi_disable(&wil->napi_tx);
649
650 if (wil->scan_request) {
651 wil_dbg_misc(wil, "Abort scan_request 0x%p\n",
652 wil->scan_request);
653 del_timer_sync(&wil->scan_timer);
654 cfg80211_scan_done(wil->scan_request, true);
655 wil->scan_request = NULL;
656 }
657
658 if (test_bit(wil_status_fwconnected, &wil->status) ||
659 test_bit(wil_status_fwconnecting, &wil->status))
660 wmi_send(wil, WMI_DISCONNECT_CMDID, NULL, 0);
661
662 /* make sure wil is idle (not connected) */
663 mutex_unlock(&wil->mutex);
664 while (iter--) {
665 int idle = !test_bit(wil_status_fwconnected, &wil->status) &&
666 !test_bit(wil_status_fwconnecting, &wil->status);
667 if (idle)
668 break;
669 msleep(WAIT_FOR_DISCONNECT_INTERVAL_MS);
670 }
671 mutex_lock(&wil->mutex);
672
673 if (!iter)
674 wil_err(wil, "timeout waiting for idle FW/HW\n");
675
676 wil_rx_fini(wil);
677
678 return 0;
679 }
680
681 int wil_down(struct wil6210_priv *wil)
682 {
683 int rc;
684
685 wil_dbg_misc(wil, "%s()\n", __func__);
686
687 mutex_lock(&wil->mutex);
688 rc = __wil_down(wil);
689 mutex_unlock(&wil->mutex);
690
691 return rc;
692 }
693
694 int wil_find_cid(struct wil6210_priv *wil, const u8 *mac)
695 {
696 int i;
697 int rc = -ENOENT;
698
699 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
700 if ((wil->sta[i].status != wil_sta_unused) &&
701 ether_addr_equal(wil->sta[i].addr, mac)) {
702 rc = i;
703 break;
704 }
705 }
706
707 return rc;
708 }
This page took 0.044717 seconds and 6 git commands to generate.