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)
505 bool is_reset_v2 = test_bit(hw_capability_reset_v2,
506 wil->hw_capabilities);
508 wil_dbg_misc(wil, "Resetting \"%s\"...\n", wil->hw_name);
510 /* Clear MAC link up */
511 S(RGF_HP_CTRL, BIT(15));
512 S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT_HPAL_PERST_FROM_PAD);
513 S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT_CAR_PERST_RST);
517 /* Clear Fw Download notification */
518 C(RGF_USER_USAGE_6, BIT(0));
521 S(RGF_CAF_OSC_CONTROL, BIT_CAF_OSC_XTAL_EN);
522 /* XTAL stabilization should take about 3ms */
523 usleep_range(5000, 7000);
524 x = R(RGF_CAF_PLL_LOCK_STATUS);
525 if (!(x & BIT_CAF_OSC_DIG_XTAL_STABLE)) {
526 wil_err(wil, "Xtal stabilization timeout\n"
527 "RGF_CAF_PLL_LOCK_STATUS = 0x%08x\n", x);
530 /* switch 10k to XTAL*/
531 C(RGF_USER_SPARROW_M_4, BIT_SPARROW_M_4_SEL_SLEEP_OR_REF);
533 C(RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_CAR_AHB_SW_SEL);
535 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x3ff81f);
536 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0xf);
539 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0xFE000000);
540 W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0x0000003F);
541 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3,
542 is_reset_v2 ? 0x000000f0 : 0x00000170);
543 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0xFFE7FE00);
546 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x0);
547 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0x0);
550 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0);
551 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0);
552 W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0);
553 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
556 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000003);
557 /* reset A2 PCIE AHB */
558 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00008000);
560 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000001);
561 W(RGF_PCIE_LOS_COUNTER_CTL, BIT(6) | BIT(8));
562 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00008000);
565 /* TODO: check order here!!! Erez code is different */
566 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
568 /* wait until device ready. typical time is 200..250 msec */
571 x = R(RGF_USER_HW_MACHINE_STATE);
572 if (delay++ > RST_COUNT) {
573 wil_err(wil, "Reset not completed, hw_state 0x%08x\n",
577 } while (x != HW_MACHINE_BOOT_DONE);
580 W(RGF_PCIE_LOS_COUNTER_CTL, BIT(8));
582 C(RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_RST_PWGD);
584 wil_dbg_misc(wil, "Reset completed in %d ms\n", delay * RST_DELAY);
589 * wil_set_itr_trsh: - apply interrupt coalescing params
591 void wil_set_itr_trsh(struct wil6210_priv *wil)
593 /* disable, use usec resolution */
594 W(RGF_DMA_ITR_CNT_CRL, BIT_DMA_ITR_CNT_CRL_EXT_TICK);
596 /* disable interrupt moderation for monitor
597 * to get better timestamp precision
599 if (wil->wdev->iftype == NL80211_IFTYPE_MONITOR)
602 wil_info(wil, "set ITR_TRSH = %d usec\n", wil->itr_trsh);
603 W(RGF_DMA_ITR_CNT_TRSH, wil->itr_trsh);
604 W(RGF_DMA_ITR_CNT_CRL, BIT_DMA_ITR_CNT_CRL_EN |
605 BIT_DMA_ITR_CNT_CRL_EXT_TICK); /* start it */
613 void wil_mbox_ring_le2cpus(struct wil6210_mbox_ring *r)
615 le32_to_cpus(&r->base);
616 le16_to_cpus(&r->entry_size);
617 le16_to_cpus(&r->size);
618 le32_to_cpus(&r->tail);
619 le32_to_cpus(&r->head);
622 static int wil_wait_for_fw_ready(struct wil6210_priv *wil)
624 ulong to = msecs_to_jiffies(1000);
625 ulong left = wait_for_completion_timeout(&wil->wmi_ready, to);
628 wil_err(wil, "Firmware not ready\n");
631 wil_info(wil, "FW ready after %d ms. HW version 0x%08x\n",
632 jiffies_to_msecs(to-left), wil->hw_version);
638 * We reset all the structures, and we reset the UMAC.
639 * After calling this routine, you're expected to reload
642 int wil_reset(struct wil6210_priv *wil)
646 wil_dbg_misc(wil, "%s()\n", __func__);
648 if (wil->hw_version == HW_VER_UNKNOWN)
651 WARN_ON(!mutex_is_locked(&wil->mutex));
652 WARN_ON(test_bit(wil_status_napi_en, wil->status));
654 cancel_work_sync(&wil->disconnect_worker);
655 wil6210_disconnect(wil, NULL, WLAN_REASON_DEAUTH_LEAVING, false);
657 /* prevent NAPI from being scheduled */
658 bitmap_zero(wil->status, wil_status_last);
660 if (wil->scan_request) {
661 wil_dbg_misc(wil, "Abort scan_request 0x%p\n",
663 del_timer_sync(&wil->scan_timer);
664 cfg80211_scan_done(wil->scan_request, true);
665 wil->scan_request = NULL;
670 wmi_event_flush(wil);
672 flush_workqueue(wil->wq_service);
673 flush_workqueue(wil->wmi_wq);
675 rc = wil_target_reset(wil);
681 wil_info(wil, "Use firmware <%s>\n", WIL_FW_NAME);
683 /* Loading f/w from the file */
684 rc = wil_request_firmware(wil, WIL_FW_NAME);
688 /* clear any interrupts which on-card-firmware may have set */
689 wil6210_clear_irq(wil);
690 { /* CAF_ICR - clear and mask */
691 u32 a = HOSTADDR(RGF_CAF_ICR) +
692 offsetof(struct RGF_ICR, ICR);
693 u32 m = HOSTADDR(RGF_CAF_ICR) +
694 offsetof(struct RGF_ICR, IMV);
695 u32 icr = ioread32(wil->csr + a);
697 iowrite32(icr, wil->csr + a); /* W1C */
698 iowrite32(~0, wil->csr + m);
699 wmb(); /* wait for completion */
701 wil_release_cpu(wil);
703 wil_info(wil, "Use firmware from on-card flash\n");
706 /* init after reset */
707 wil->pending_connect_cid = -1;
708 reinit_completion(&wil->wmi_ready);
709 reinit_completion(&wil->wmi_call);
713 /* we just started MAC, wait for FW ready */
714 rc = wil_wait_for_fw_ready(wil);
719 void wil_fw_error_recovery(struct wil6210_priv *wil)
721 wil_dbg_misc(wil, "starting fw error recovery\n");
722 wil->recovery_state = fw_recovery_pending;
723 schedule_work(&wil->fw_error_worker);
726 void wil_link_on(struct wil6210_priv *wil)
728 struct net_device *ndev = wil_to_ndev(wil);
730 wil_dbg_misc(wil, "%s()\n", __func__);
732 netif_carrier_on(ndev);
733 wil_dbg_misc(wil, "netif_tx_wake : link on\n");
734 netif_tx_wake_all_queues(ndev);
737 void wil_link_off(struct wil6210_priv *wil)
739 struct net_device *ndev = wil_to_ndev(wil);
741 wil_dbg_misc(wil, "%s()\n", __func__);
743 netif_tx_stop_all_queues(ndev);
744 wil_dbg_misc(wil, "netif_tx_stop : link off\n");
745 netif_carrier_off(ndev);
748 int __wil_up(struct wil6210_priv *wil)
750 struct net_device *ndev = wil_to_ndev(wil);
751 struct wireless_dev *wdev = wil->wdev;
754 WARN_ON(!mutex_is_locked(&wil->mutex));
760 /* Rx VRING. After MAC and beacon */
761 rc = wil_rx_init(wil, 1 << rx_ring_order);
765 switch (wdev->iftype) {
766 case NL80211_IFTYPE_STATION:
767 wil_dbg_misc(wil, "type: STATION\n");
768 ndev->type = ARPHRD_ETHER;
770 case NL80211_IFTYPE_AP:
771 wil_dbg_misc(wil, "type: AP\n");
772 ndev->type = ARPHRD_ETHER;
774 case NL80211_IFTYPE_P2P_CLIENT:
775 wil_dbg_misc(wil, "type: P2P_CLIENT\n");
776 ndev->type = ARPHRD_ETHER;
778 case NL80211_IFTYPE_P2P_GO:
779 wil_dbg_misc(wil, "type: P2P_GO\n");
780 ndev->type = ARPHRD_ETHER;
782 case NL80211_IFTYPE_MONITOR:
783 wil_dbg_misc(wil, "type: Monitor\n");
784 ndev->type = ARPHRD_IEEE80211_RADIOTAP;
785 /* ARPHRD_IEEE80211 or ARPHRD_IEEE80211_RADIOTAP ? */
791 /* MAC address - pre-requisite for other commands */
792 wmi_set_mac_address(wil, ndev->dev_addr);
794 wil_dbg_misc(wil, "NAPI enable\n");
795 napi_enable(&wil->napi_rx);
796 napi_enable(&wil->napi_tx);
797 set_bit(wil_status_napi_en, wil->status);
799 if (wil->platform_ops.bus_request)
800 wil->platform_ops.bus_request(wil->platform_handle,
801 WIL_MAX_BUS_REQUEST_KBPS);
806 int wil_up(struct wil6210_priv *wil)
810 wil_dbg_misc(wil, "%s()\n", __func__);
812 mutex_lock(&wil->mutex);
814 mutex_unlock(&wil->mutex);
819 int __wil_down(struct wil6210_priv *wil)
821 int iter = WAIT_FOR_DISCONNECT_TIMEOUT_MS /
822 WAIT_FOR_DISCONNECT_INTERVAL_MS;
824 WARN_ON(!mutex_is_locked(&wil->mutex));
826 if (wil->platform_ops.bus_request)
827 wil->platform_ops.bus_request(wil->platform_handle, 0);
829 wil_disable_irq(wil);
830 if (test_and_clear_bit(wil_status_napi_en, wil->status)) {
831 napi_disable(&wil->napi_rx);
832 napi_disable(&wil->napi_tx);
833 wil_dbg_misc(wil, "NAPI disable\n");
837 if (wil->scan_request) {
838 wil_dbg_misc(wil, "Abort scan_request 0x%p\n",
840 del_timer_sync(&wil->scan_timer);
841 cfg80211_scan_done(wil->scan_request, true);
842 wil->scan_request = NULL;
845 if (test_bit(wil_status_fwconnected, wil->status) ||
846 test_bit(wil_status_fwconnecting, wil->status))
847 wmi_send(wil, WMI_DISCONNECT_CMDID, NULL, 0);
849 /* make sure wil is idle (not connected) */
850 mutex_unlock(&wil->mutex);
852 int idle = !test_bit(wil_status_fwconnected, wil->status) &&
853 !test_bit(wil_status_fwconnecting, wil->status);
856 msleep(WAIT_FOR_DISCONNECT_INTERVAL_MS);
858 mutex_lock(&wil->mutex);
861 wil_err(wil, "timeout waiting for idle FW/HW\n");
868 int wil_down(struct wil6210_priv *wil)
872 wil_dbg_misc(wil, "%s()\n", __func__);
874 wil_set_recovery_state(wil, fw_recovery_idle);
875 mutex_lock(&wil->mutex);
876 rc = __wil_down(wil);
877 mutex_unlock(&wil->mutex);
882 int wil_find_cid(struct wil6210_priv *wil, const u8 *mac)
887 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
888 if ((wil->sta[i].status != wil_sta_unused) &&
889 ether_addr_equal(wil->sta[i].addr, mac)) {