2 * Copyright (c) 2012-2014 Qualcomm Atheros, Inc.
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.
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.
17 #include <linux/moduleparam.h>
18 #include <linux/if_arp.h>
19 #include <linux/etherdevice.h>
25 #define WAIT_FOR_DISCONNECT_TIMEOUT_MS 2000
26 #define WAIT_FOR_DISCONNECT_INTERVAL_MS 10
29 module_param(no_fw_recovery, bool, S_IRUGO | S_IWUSR);
30 MODULE_PARM_DESC(no_fw_recovery, " disable automatic FW error recovery");
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.");
36 static unsigned int itr_trsh = WIL6210_ITR_TRSH_DEFAULT;
38 module_param(itr_trsh, uint, S_IRUGO);
39 MODULE_PARM_DESC(itr_trsh, " Interrupt moderation threshold, usecs.");
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.
44 unsigned int mtu_max = TXRX_BUF_LEN_DEFAULT - WIL_MAX_MPDU_OVERHEAD;
45 static int mtu_max_set(const char *val, const struct kernel_param *kp)
49 /* sets mtu_max directly. no need to restore it in case of
50 * illegal value since we assume this will fail insmod
52 ret = param_set_uint(val, kp);
56 if (mtu_max < 68 || mtu_max > WIL_MAX_ETH_MTU)
62 static struct kernel_param_ops mtu_max_ops = {
64 .get = param_get_uint,
67 module_param_cb(mtu_max, &mtu_max_ops, &mtu_max, S_IRUGO);
68 MODULE_PARM_DESC(mtu_max, " Max MTU value.");
70 static uint rx_ring_order = WIL_RX_RING_SIZE_ORDER_DEFAULT;
71 static uint tx_ring_order = WIL_TX_RING_SIZE_ORDER_DEFAULT;
73 static int ring_order_set(const char *val, const struct kernel_param *kp)
78 ret = kstrtouint(val, 0, &x);
82 if ((x < WIL_RING_SIZE_ORDER_MIN) || (x > WIL_RING_SIZE_ORDER_MAX))
85 *((uint *)kp->arg) = x;
90 static struct kernel_param_ops ring_order_ops = {
91 .set = ring_order_set,
92 .get = param_get_uint,
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");
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 */
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
109 * Force 32-bit transactions to enable NIC on 64-bit platforms
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.
115 void wil_memcpy_fromio_32(void *dst, const volatile void __iomem *src,
119 const volatile u32 __iomem *s = src;
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++);
126 void wil_memcpy_toio_32(volatile void __iomem *dst, const void *src,
129 volatile u32 __iomem *d = dst;
132 for (count += 4; count > 4; count -= 4)
133 __raw_writel(*s++, d++);
136 static void wil_disconnect_cid(struct wil6210_priv *wil, int cid,
137 u16 reason_code, bool from_event)
140 struct net_device *ndev = wil_to_ndev(wil);
141 struct wireless_dev *wdev = wil->wdev;
142 struct wil_sta_info *sta = &wil->sta[cid];
144 wil_dbg_misc(wil, "%s(CID %d, status %d)\n", __func__, cid,
147 sta->data_port_open = false;
148 if (sta->status != wil_sta_unused) {
150 wmi_disconnect_sta(wil, sta->addr, reason_code);
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);
161 sta->status = wil_sta_unused;
164 for (i = 0; i < WIL_STA_TID_NUM; i++) {
165 struct wil_tid_ampdu_rx *r;
168 spin_lock_irqsave(&sta->tid_rx_lock, flags);
171 sta->tid_rx[i] = NULL;
172 wil_tid_ampdu_rx_free(wil, r);
174 spin_unlock_irqrestore(&sta->tid_rx_lock, flags);
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);
180 memset(&sta->stats, 0, sizeof(sta->stats));
183 static void _wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid,
184 u16 reason_code, bool from_event)
187 struct net_device *ndev = wil_to_ndev(wil);
188 struct wireless_dev *wdev = wil->wdev;
191 wil_dbg_misc(wil, "%s(bssid=%pM, reason=%d, ev%s)\n", __func__, bssid,
192 reason_code, from_event ? "+" : "-");
195 * - disconnect single STA, still connected
196 * - disconnect single STA, already disconnected
199 * For "disconnect all", there are 2 options:
201 * - bssid is our MAC address
203 if (bssid && memcmp(ndev->dev_addr, bssid, ETH_ALEN)) {
204 cid = wil_find_cid(wil, bssid);
205 wil_dbg_misc(wil, "Disconnect %pM, CID=%d, reason=%d\n",
206 bssid, cid, reason_code);
207 if (cid >= 0) /* disconnect 1 peer */
208 wil_disconnect_cid(wil, cid, reason_code, from_event);
210 wil_dbg_misc(wil, "Disconnect all\n");
211 for (cid = 0; cid < WIL6210_MAX_CID; cid++)
212 wil_disconnect_cid(wil, cid, reason_code, from_event);
216 switch (wdev->iftype) {
217 case NL80211_IFTYPE_STATION:
218 case NL80211_IFTYPE_P2P_CLIENT:
220 if (test_bit(wil_status_fwconnected, wil->status)) {
221 clear_bit(wil_status_fwconnected, wil->status);
222 cfg80211_disconnected(ndev, reason_code,
223 NULL, 0, GFP_KERNEL);
224 } else if (test_bit(wil_status_fwconnecting, wil->status)) {
225 cfg80211_connect_result(ndev, bssid, NULL, 0, NULL, 0,
226 WLAN_STATUS_UNSPECIFIED_FAILURE,
229 clear_bit(wil_status_fwconnecting, wil->status);
236 static void wil_disconnect_worker(struct work_struct *work)
238 struct wil6210_priv *wil = container_of(work,
239 struct wil6210_priv, disconnect_worker);
241 mutex_lock(&wil->mutex);
242 _wil6210_disconnect(wil, NULL, WLAN_REASON_UNSPECIFIED, false);
243 mutex_unlock(&wil->mutex);
246 static void wil_connect_timer_fn(ulong x)
248 struct wil6210_priv *wil = (void *)x;
250 wil_dbg_misc(wil, "Connect timeout\n");
252 /* reschedule to thread context - disconnect won't
253 * run from atomic context
255 schedule_work(&wil->disconnect_worker);
258 static void wil_scan_timer_fn(ulong x)
260 struct wil6210_priv *wil = (void *)x;
262 clear_bit(wil_status_fwready, wil->status);
263 wil_err(wil, "Scan timeout detected, start fw error recovery\n");
264 wil->recovery_state = fw_recovery_pending;
265 schedule_work(&wil->fw_error_worker);
268 static int wil_wait_for_recovery(struct wil6210_priv *wil)
270 if (wait_event_interruptible(wil->wq, wil->recovery_state !=
271 fw_recovery_pending)) {
272 wil_err(wil, "Interrupt, canceling recovery\n");
275 if (wil->recovery_state != fw_recovery_running) {
276 wil_info(wil, "Recovery cancelled\n");
279 wil_info(wil, "Proceed with recovery\n");
283 void wil_set_recovery_state(struct wil6210_priv *wil, int state)
285 wil_dbg_misc(wil, "%s(%d -> %d)\n", __func__,
286 wil->recovery_state, state);
288 wil->recovery_state = state;
289 wake_up_interruptible(&wil->wq);
292 static void wil_fw_error_worker(struct work_struct *work)
294 struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
296 struct wireless_dev *wdev = wil->wdev;
298 wil_dbg_misc(wil, "fw error worker\n");
300 if (!netif_running(wil_to_ndev(wil))) {
301 wil_info(wil, "No recovery - interface is down\n");
305 /* increment @recovery_count if less then WIL6210_FW_RECOVERY_TO
306 * passed since last recovery attempt
308 if (time_is_after_jiffies(wil->last_fw_recovery +
309 WIL6210_FW_RECOVERY_TO))
310 wil->recovery_count++;
312 wil->recovery_count = 1; /* fw was alive for a long time */
314 if (wil->recovery_count > WIL6210_FW_RECOVERY_RETRIES) {
315 wil_err(wil, "too many recovery attempts (%d), giving up\n",
316 wil->recovery_count);
320 wil->last_fw_recovery = jiffies;
322 mutex_lock(&wil->mutex);
323 switch (wdev->iftype) {
324 case NL80211_IFTYPE_STATION:
325 case NL80211_IFTYPE_P2P_CLIENT:
326 case NL80211_IFTYPE_MONITOR:
327 wil_info(wil, "fw error recovery requested (try %d)...\n",
328 wil->recovery_count);
330 wil->recovery_state = fw_recovery_running;
331 if (0 != wil_wait_for_recovery(wil))
337 case NL80211_IFTYPE_AP:
338 case NL80211_IFTYPE_P2P_GO:
339 wil_info(wil, "No recovery for AP-like interface\n");
340 /* recovery in these modes is done by upper layers */
343 wil_err(wil, "No recovery - unknown interface type %d\n",
347 mutex_unlock(&wil->mutex);
350 static int wil_find_free_vring(struct wil6210_priv *wil)
354 for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) {
355 if (!wil->vring_tx[i].va)
361 static void wil_connect_worker(struct work_struct *work)
364 struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
366 int cid = wil->pending_connect_cid;
367 int ringid = wil_find_free_vring(wil);
370 wil_err(wil, "No connection pending\n");
374 wil_dbg_wmi(wil, "Configure for connection CID %d\n", cid);
376 rc = wil_vring_init_tx(wil, ringid, 1 << tx_ring_order, cid, 0);
377 wil->pending_connect_cid = -1;
379 wil->sta[cid].status = wil_sta_connected;
382 wil->sta[cid].status = wil_sta_unused;
386 int wil_priv_init(struct wil6210_priv *wil)
390 wil_dbg_misc(wil, "%s()\n", __func__);
392 memset(wil->sta, 0, sizeof(wil->sta));
393 for (i = 0; i < WIL6210_MAX_CID; i++)
394 spin_lock_init(&wil->sta[i].tid_rx_lock);
396 mutex_init(&wil->mutex);
397 mutex_init(&wil->wmi_mutex);
398 mutex_init(&wil->back_rx_mutex);
399 mutex_init(&wil->back_tx_mutex);
401 init_completion(&wil->wmi_ready);
402 init_completion(&wil->wmi_call);
404 wil->pending_connect_cid = -1;
405 setup_timer(&wil->connect_timer, wil_connect_timer_fn, (ulong)wil);
406 setup_timer(&wil->scan_timer, wil_scan_timer_fn, (ulong)wil);
408 INIT_WORK(&wil->connect_worker, wil_connect_worker);
409 INIT_WORK(&wil->disconnect_worker, wil_disconnect_worker);
410 INIT_WORK(&wil->wmi_event_worker, wmi_event_worker);
411 INIT_WORK(&wil->fw_error_worker, wil_fw_error_worker);
412 INIT_WORK(&wil->back_rx_worker, wil_back_rx_worker);
413 INIT_WORK(&wil->back_tx_worker, wil_back_tx_worker);
415 INIT_LIST_HEAD(&wil->pending_wmi_ev);
416 INIT_LIST_HEAD(&wil->back_rx_pending);
417 INIT_LIST_HEAD(&wil->back_tx_pending);
418 spin_lock_init(&wil->wmi_ev_lock);
419 init_waitqueue_head(&wil->wq);
421 wil->wmi_wq = create_singlethread_workqueue(WIL_NAME "_wmi");
425 wil->wq_service = create_singlethread_workqueue(WIL_NAME "_service");
426 if (!wil->wq_service)
429 wil->last_fw_recovery = jiffies;
430 wil->itr_trsh = itr_trsh;
435 destroy_workqueue(wil->wmi_wq);
441 * wil6210_disconnect - disconnect one connection
442 * @wil: driver context
443 * @bssid: peer to disconnect, NULL to disconnect all
444 * @reason_code: Reason code for the Disassociation frame
445 * @from_event: whether is invoked from FW event handler
447 * Disconnect and release associated resources. If invoked not from the
448 * FW event handler, issue WMI command(s) to trigger MAC disconnect.
450 void wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid,
451 u16 reason_code, bool from_event)
453 wil_dbg_misc(wil, "%s()\n", __func__);
455 del_timer_sync(&wil->connect_timer);
456 _wil6210_disconnect(wil, bssid, reason_code, from_event);
459 void wil_priv_deinit(struct wil6210_priv *wil)
461 wil_dbg_misc(wil, "%s()\n", __func__);
463 wil_set_recovery_state(wil, fw_recovery_idle);
464 del_timer_sync(&wil->scan_timer);
465 cancel_work_sync(&wil->disconnect_worker);
466 cancel_work_sync(&wil->fw_error_worker);
467 mutex_lock(&wil->mutex);
468 wil6210_disconnect(wil, NULL, WLAN_REASON_DEAUTH_LEAVING, false);
469 mutex_unlock(&wil->mutex);
470 wmi_event_flush(wil);
471 wil_back_rx_flush(wil);
472 cancel_work_sync(&wil->back_rx_worker);
473 wil_back_tx_flush(wil);
474 cancel_work_sync(&wil->back_tx_worker);
475 destroy_workqueue(wil->wq_service);
476 destroy_workqueue(wil->wmi_wq);
479 /* target operations */
481 #define R(a) ioread32(wil->csr + HOSTADDR(a))
482 /* register write. wmb() to make sure it is completed */
483 #define W(a, v) do { iowrite32(v, wil->csr + HOSTADDR(a)); wmb(); } while (0)
484 /* register set = read, OR, write */
485 #define S(a, v) W(a, R(a) | v)
486 /* register clear = read, AND with inverted, write */
487 #define C(a, v) W(a, R(a) & ~v)
489 static inline void wil_halt_cpu(struct wil6210_priv *wil)
491 W(RGF_USER_USER_CPU_0, BIT_USER_USER_CPU_MAN_RST);
492 W(RGF_USER_MAC_CPU_0, BIT_USER_MAC_CPU_MAN_RST);
495 static inline void wil_release_cpu(struct wil6210_priv *wil)
498 W(RGF_USER_USER_CPU_0, 1);
501 static int wil_target_reset(struct wil6210_priv *wil)
506 bool is_sparrow = (wil->board->board == WIL_BOARD_SPARROW);
508 wil_dbg_misc(wil, "Resetting \"%s\"...\n", wil->board->name);
510 wil->hw_version = R(RGF_USER_FW_REV_ID);
511 rev_id = wil->hw_version & 0xff;
513 /* Clear MAC link up */
514 S(RGF_HP_CTRL, BIT(15));
515 S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT_HPAL_PERST_FROM_PAD);
516 S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT_CAR_PERST_RST);
520 /* Clear Fw Download notification */
521 C(RGF_USER_USAGE_6, BIT(0));
524 S(RGF_CAF_OSC_CONTROL, BIT_CAF_OSC_XTAL_EN);
525 /* XTAL stabilization should take about 3ms */
526 usleep_range(5000, 7000);
527 x = R(RGF_CAF_PLL_LOCK_STATUS);
528 if (!(x & BIT_CAF_OSC_DIG_XTAL_STABLE)) {
529 wil_err(wil, "Xtal stabilization timeout\n"
530 "RGF_CAF_PLL_LOCK_STATUS = 0x%08x\n", x);
533 /* switch 10k to XTAL*/
534 C(RGF_USER_SPARROW_M_4, BIT_SPARROW_M_4_SEL_SLEEP_OR_REF);
536 C(RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_CAR_AHB_SW_SEL);
538 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x3ff81f);
539 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0xf);
542 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0xFE000000);
543 W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0x0000003F);
544 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, is_sparrow ? 0x000000f0 : 0x00000170);
545 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0xFFE7FE00);
548 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x0);
549 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0x0);
552 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0);
553 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0);
554 W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0);
555 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
558 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000003);
559 /* reset A2 PCIE AHB */
560 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00008000);
562 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000001);
564 /* reset A1 BOTH PCIE AHB & PCIE RGF */
565 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00000080);
567 W(RGF_PCIE_LOS_COUNTER_CTL, BIT(6) | BIT(8));
568 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00008000);
572 /* TODO: check order here!!! Erez code is different */
573 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
575 /* wait until device ready. typical time is 200..250 msec */
578 x = R(RGF_USER_HW_MACHINE_STATE);
579 if (delay++ > RST_COUNT) {
580 wil_err(wil, "Reset not completed, hw_state 0x%08x\n",
584 } while (x != HW_MACHINE_BOOT_DONE);
586 /* TODO: Erez check rev_id != 1 */
587 if (!is_sparrow && (rev_id != 1))
588 W(RGF_PCIE_LOS_COUNTER_CTL, BIT(8));
590 C(RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_RST_PWGD);
592 wil_dbg_misc(wil, "Reset completed in %d ms\n", delay * RST_DELAY);
597 * wil_set_itr_trsh: - apply interrupt coalescing params
599 void wil_set_itr_trsh(struct wil6210_priv *wil)
601 /* disable, use usec resolution */
602 W(RGF_DMA_ITR_CNT_CRL, BIT_DMA_ITR_CNT_CRL_EXT_TICK);
604 /* disable interrupt moderation for monitor
605 * to get better timestamp precision
607 if (wil->wdev->iftype == NL80211_IFTYPE_MONITOR)
610 wil_info(wil, "set ITR_TRSH = %d usec\n", wil->itr_trsh);
611 W(RGF_DMA_ITR_CNT_TRSH, wil->itr_trsh);
612 W(RGF_DMA_ITR_CNT_CRL, BIT_DMA_ITR_CNT_CRL_EN |
613 BIT_DMA_ITR_CNT_CRL_EXT_TICK); /* start it */
621 void wil_mbox_ring_le2cpus(struct wil6210_mbox_ring *r)
623 le32_to_cpus(&r->base);
624 le16_to_cpus(&r->entry_size);
625 le16_to_cpus(&r->size);
626 le32_to_cpus(&r->tail);
627 le32_to_cpus(&r->head);
630 static int wil_wait_for_fw_ready(struct wil6210_priv *wil)
632 ulong to = msecs_to_jiffies(1000);
633 ulong left = wait_for_completion_timeout(&wil->wmi_ready, to);
636 wil_err(wil, "Firmware not ready\n");
639 wil_info(wil, "FW ready after %d ms. HW version 0x%08x\n",
640 jiffies_to_msecs(to-left), wil->hw_version);
646 * We reset all the structures, and we reset the UMAC.
647 * After calling this routine, you're expected to reload
650 int wil_reset(struct wil6210_priv *wil)
654 wil_dbg_misc(wil, "%s()\n", __func__);
656 WARN_ON(!mutex_is_locked(&wil->mutex));
657 WARN_ON(test_bit(wil_status_napi_en, wil->status));
659 cancel_work_sync(&wil->disconnect_worker);
660 wil6210_disconnect(wil, NULL, WLAN_REASON_DEAUTH_LEAVING, false);
662 /* prevent NAPI from being scheduled */
663 bitmap_zero(wil->status, wil_status_last);
665 if (wil->scan_request) {
666 wil_dbg_misc(wil, "Abort scan_request 0x%p\n",
668 del_timer_sync(&wil->scan_timer);
669 cfg80211_scan_done(wil->scan_request, true);
670 wil->scan_request = NULL;
675 wmi_event_flush(wil);
677 flush_workqueue(wil->wq_service);
678 flush_workqueue(wil->wmi_wq);
680 rc = wil_target_reset(wil);
686 wil_info(wil, "Use firmware <%s>\n", WIL_FW_NAME);
688 /* Loading f/w from the file */
689 rc = wil_request_firmware(wil, WIL_FW_NAME);
693 /* clear any interrupts which on-card-firmware may have set */
694 wil6210_clear_irq(wil);
695 { /* CAF_ICR - clear and mask */
696 u32 a = HOSTADDR(RGF_CAF_ICR) +
697 offsetof(struct RGF_ICR, ICR);
698 u32 m = HOSTADDR(RGF_CAF_ICR) +
699 offsetof(struct RGF_ICR, IMV);
700 u32 icr = ioread32(wil->csr + a);
702 iowrite32(icr, wil->csr + a); /* W1C */
703 iowrite32(~0, wil->csr + m);
704 wmb(); /* wait for completion */
706 wil_release_cpu(wil);
708 wil_info(wil, "Use firmware from on-card flash\n");
711 /* init after reset */
712 wil->pending_connect_cid = -1;
713 reinit_completion(&wil->wmi_ready);
714 reinit_completion(&wil->wmi_call);
718 /* we just started MAC, wait for FW ready */
719 rc = wil_wait_for_fw_ready(wil);
724 void wil_fw_error_recovery(struct wil6210_priv *wil)
726 wil_dbg_misc(wil, "starting fw error recovery\n");
727 wil->recovery_state = fw_recovery_pending;
728 schedule_work(&wil->fw_error_worker);
731 void wil_link_on(struct wil6210_priv *wil)
733 struct net_device *ndev = wil_to_ndev(wil);
735 wil_dbg_misc(wil, "%s()\n", __func__);
737 netif_carrier_on(ndev);
738 wil_dbg_misc(wil, "netif_tx_wake : link on\n");
739 netif_tx_wake_all_queues(ndev);
742 void wil_link_off(struct wil6210_priv *wil)
744 struct net_device *ndev = wil_to_ndev(wil);
746 wil_dbg_misc(wil, "%s()\n", __func__);
748 netif_tx_stop_all_queues(ndev);
749 wil_dbg_misc(wil, "netif_tx_stop : link off\n");
750 netif_carrier_off(ndev);
753 int __wil_up(struct wil6210_priv *wil)
755 struct net_device *ndev = wil_to_ndev(wil);
756 struct wireless_dev *wdev = wil->wdev;
759 WARN_ON(!mutex_is_locked(&wil->mutex));
765 /* Rx VRING. After MAC and beacon */
766 rc = wil_rx_init(wil, 1 << rx_ring_order);
770 switch (wdev->iftype) {
771 case NL80211_IFTYPE_STATION:
772 wil_dbg_misc(wil, "type: STATION\n");
773 ndev->type = ARPHRD_ETHER;
775 case NL80211_IFTYPE_AP:
776 wil_dbg_misc(wil, "type: AP\n");
777 ndev->type = ARPHRD_ETHER;
779 case NL80211_IFTYPE_P2P_CLIENT:
780 wil_dbg_misc(wil, "type: P2P_CLIENT\n");
781 ndev->type = ARPHRD_ETHER;
783 case NL80211_IFTYPE_P2P_GO:
784 wil_dbg_misc(wil, "type: P2P_GO\n");
785 ndev->type = ARPHRD_ETHER;
787 case NL80211_IFTYPE_MONITOR:
788 wil_dbg_misc(wil, "type: Monitor\n");
789 ndev->type = ARPHRD_IEEE80211_RADIOTAP;
790 /* ARPHRD_IEEE80211 or ARPHRD_IEEE80211_RADIOTAP ? */
796 /* MAC address - pre-requisite for other commands */
797 wmi_set_mac_address(wil, ndev->dev_addr);
799 wil_dbg_misc(wil, "NAPI enable\n");
800 napi_enable(&wil->napi_rx);
801 napi_enable(&wil->napi_tx);
802 set_bit(wil_status_napi_en, wil->status);
804 if (wil->platform_ops.bus_request)
805 wil->platform_ops.bus_request(wil->platform_handle,
806 WIL_MAX_BUS_REQUEST_KBPS);
811 int wil_up(struct wil6210_priv *wil)
815 wil_dbg_misc(wil, "%s()\n", __func__);
817 mutex_lock(&wil->mutex);
819 mutex_unlock(&wil->mutex);
824 int __wil_down(struct wil6210_priv *wil)
826 int iter = WAIT_FOR_DISCONNECT_TIMEOUT_MS /
827 WAIT_FOR_DISCONNECT_INTERVAL_MS;
829 WARN_ON(!mutex_is_locked(&wil->mutex));
831 if (wil->platform_ops.bus_request)
832 wil->platform_ops.bus_request(wil->platform_handle, 0);
834 wil_disable_irq(wil);
835 if (test_and_clear_bit(wil_status_napi_en, wil->status)) {
836 napi_disable(&wil->napi_rx);
837 napi_disable(&wil->napi_tx);
838 wil_dbg_misc(wil, "NAPI disable\n");
842 if (wil->scan_request) {
843 wil_dbg_misc(wil, "Abort scan_request 0x%p\n",
845 del_timer_sync(&wil->scan_timer);
846 cfg80211_scan_done(wil->scan_request, true);
847 wil->scan_request = NULL;
850 if (test_bit(wil_status_fwconnected, wil->status) ||
851 test_bit(wil_status_fwconnecting, wil->status))
852 wmi_send(wil, WMI_DISCONNECT_CMDID, NULL, 0);
854 /* make sure wil is idle (not connected) */
855 mutex_unlock(&wil->mutex);
857 int idle = !test_bit(wil_status_fwconnected, wil->status) &&
858 !test_bit(wil_status_fwconnecting, wil->status);
861 msleep(WAIT_FOR_DISCONNECT_INTERVAL_MS);
863 mutex_lock(&wil->mutex);
866 wil_err(wil, "timeout waiting for idle FW/HW\n");
873 int wil_down(struct wil6210_priv *wil)
877 wil_dbg_misc(wil, "%s()\n", __func__);
879 wil_set_recovery_state(wil, fw_recovery_idle);
880 mutex_lock(&wil->mutex);
881 rc = __wil_down(wil);
882 mutex_unlock(&wil->mutex);
887 int wil_find_cid(struct wil6210_priv *wil, const u8 *mac)
892 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
893 if ((wil->sta[i].status != wil_sta_unused) &&
894 ether_addr_equal(wil->sta[i].addr, mac)) {