2 * Copyright (c) 2012-2015 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 /* if not set via modparam, will be set to default value of 1/8 of
33 * rx ring size during init flow
35 unsigned short rx_ring_overflow_thrsh = WIL6210_RX_HIGH_TRSH_INIT;
36 module_param(rx_ring_overflow_thrsh, ushort, S_IRUGO);
37 MODULE_PARM_DESC(rx_ring_overflow_thrsh,
38 " RX ring overflow threshold in descriptors.");
40 /* We allow allocation of more than 1 page buffers to support large packets.
41 * It is suboptimal behavior performance wise in case MTU above page size.
43 unsigned int mtu_max = TXRX_BUF_LEN_DEFAULT - WIL_MAX_MPDU_OVERHEAD;
44 static int mtu_max_set(const char *val, const struct kernel_param *kp)
48 /* sets mtu_max directly. no need to restore it in case of
49 * illegal value since we assume this will fail insmod
51 ret = param_set_uint(val, kp);
55 if (mtu_max < 68 || mtu_max > WIL_MAX_ETH_MTU)
61 static struct kernel_param_ops mtu_max_ops = {
63 .get = param_get_uint,
66 module_param_cb(mtu_max, &mtu_max_ops, &mtu_max, S_IRUGO);
67 MODULE_PARM_DESC(mtu_max, " Max MTU value.");
69 static uint rx_ring_order = WIL_RX_RING_SIZE_ORDER_DEFAULT;
70 static uint tx_ring_order = WIL_TX_RING_SIZE_ORDER_DEFAULT;
72 static int ring_order_set(const char *val, const struct kernel_param *kp)
77 ret = kstrtouint(val, 0, &x);
81 if ((x < WIL_RING_SIZE_ORDER_MIN) || (x > WIL_RING_SIZE_ORDER_MAX))
84 *((uint *)kp->arg) = x;
89 static struct kernel_param_ops ring_order_ops = {
90 .set = ring_order_set,
91 .get = param_get_uint,
94 module_param_cb(rx_ring_order, &ring_order_ops, &rx_ring_order, S_IRUGO);
95 MODULE_PARM_DESC(rx_ring_order, " Rx ring order; size = 1 << order");
96 module_param_cb(tx_ring_order, &ring_order_ops, &tx_ring_order, S_IRUGO);
97 MODULE_PARM_DESC(tx_ring_order, " Tx ring order; size = 1 << order");
99 #define RST_DELAY (20) /* msec, for loop in @wil_target_reset */
100 #define RST_COUNT (1 + 1000/RST_DELAY) /* round up to be above 1 sec total */
103 * Due to a hardware issue,
104 * one has to read/write to/from NIC in 32-bit chunks;
105 * regular memcpy_fromio and siblings will
106 * not work on 64-bit platform - it uses 64-bit transactions
108 * Force 32-bit transactions to enable NIC on 64-bit platforms
110 * To avoid byte swap on big endian host, __raw_{read|write}l
111 * should be used - {read|write}l would swap bytes to provide
112 * little endian on PCI value in host endianness.
114 void wil_memcpy_fromio_32(void *dst, const volatile void __iomem *src,
118 const volatile u32 __iomem *s = src;
120 /* size_t is unsigned, if (count%4 != 0) it will wrap */
121 for (count += 4; count > 4; count -= 4)
122 *d++ = __raw_readl(s++);
125 void wil_memcpy_toio_32(volatile void __iomem *dst, const void *src,
128 volatile u32 __iomem *d = dst;
131 for (count += 4; count > 4; count -= 4)
132 __raw_writel(*s++, d++);
135 static void wil_disconnect_cid(struct wil6210_priv *wil, int cid,
136 u16 reason_code, bool from_event)
137 __acquires(&sta->tid_rx_lock) __releases(&sta->tid_rx_lock)
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];
145 wil_dbg_misc(wil, "%s(CID %d, status %d)\n", __func__, cid,
148 sta->data_port_open = false;
149 if (sta->status != wil_sta_unused) {
151 wmi_disconnect_sta(wil, sta->addr, reason_code);
153 switch (wdev->iftype) {
154 case NL80211_IFTYPE_AP:
155 case NL80211_IFTYPE_P2P_GO:
156 /* AP-like interface */
157 cfg80211_del_sta(ndev, sta->addr, GFP_KERNEL);
162 sta->status = wil_sta_unused;
165 for (i = 0; i < WIL_STA_TID_NUM; i++) {
166 struct wil_tid_ampdu_rx *r;
168 spin_lock_bh(&sta->tid_rx_lock);
171 sta->tid_rx[i] = NULL;
172 wil_tid_ampdu_rx_free(wil, r);
174 spin_unlock_bh(&sta->tid_rx_lock);
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:
219 netif_tx_stop_all_queues(ndev);
220 netif_carrier_off(ndev);
222 if (test_bit(wil_status_fwconnected, wil->status)) {
223 clear_bit(wil_status_fwconnected, wil->status);
224 cfg80211_disconnected(ndev, reason_code,
225 NULL, 0, GFP_KERNEL);
226 } else if (test_bit(wil_status_fwconnecting, wil->status)) {
227 cfg80211_connect_result(ndev, bssid, NULL, 0, NULL, 0,
228 WLAN_STATUS_UNSPECIFIED_FAILURE,
231 clear_bit(wil_status_fwconnecting, wil->status);
238 static void wil_disconnect_worker(struct work_struct *work)
240 struct wil6210_priv *wil = container_of(work,
241 struct wil6210_priv, disconnect_worker);
243 mutex_lock(&wil->mutex);
244 _wil6210_disconnect(wil, NULL, WLAN_REASON_UNSPECIFIED, false);
245 mutex_unlock(&wil->mutex);
248 static void wil_connect_timer_fn(ulong x)
250 struct wil6210_priv *wil = (void *)x;
252 wil_dbg_misc(wil, "Connect timeout\n");
254 /* reschedule to thread context - disconnect won't
255 * run from atomic context
257 schedule_work(&wil->disconnect_worker);
260 static void wil_scan_timer_fn(ulong x)
262 struct wil6210_priv *wil = (void *)x;
264 clear_bit(wil_status_fwready, wil->status);
265 wil_err(wil, "Scan timeout detected, start fw error recovery\n");
266 wil->recovery_state = fw_recovery_pending;
267 schedule_work(&wil->fw_error_worker);
270 static int wil_wait_for_recovery(struct wil6210_priv *wil)
272 if (wait_event_interruptible(wil->wq, wil->recovery_state !=
273 fw_recovery_pending)) {
274 wil_err(wil, "Interrupt, canceling recovery\n");
277 if (wil->recovery_state != fw_recovery_running) {
278 wil_info(wil, "Recovery cancelled\n");
281 wil_info(wil, "Proceed with recovery\n");
285 void wil_set_recovery_state(struct wil6210_priv *wil, int state)
287 wil_dbg_misc(wil, "%s(%d -> %d)\n", __func__,
288 wil->recovery_state, state);
290 wil->recovery_state = state;
291 wake_up_interruptible(&wil->wq);
294 static void wil_fw_error_worker(struct work_struct *work)
296 struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
298 struct wireless_dev *wdev = wil->wdev;
300 wil_dbg_misc(wil, "fw error worker\n");
302 if (!netif_running(wil_to_ndev(wil))) {
303 wil_info(wil, "No recovery - interface is down\n");
307 /* increment @recovery_count if less then WIL6210_FW_RECOVERY_TO
308 * passed since last recovery attempt
310 if (time_is_after_jiffies(wil->last_fw_recovery +
311 WIL6210_FW_RECOVERY_TO))
312 wil->recovery_count++;
314 wil->recovery_count = 1; /* fw was alive for a long time */
316 if (wil->recovery_count > WIL6210_FW_RECOVERY_RETRIES) {
317 wil_err(wil, "too many recovery attempts (%d), giving up\n",
318 wil->recovery_count);
322 wil->last_fw_recovery = jiffies;
324 mutex_lock(&wil->mutex);
325 switch (wdev->iftype) {
326 case NL80211_IFTYPE_STATION:
327 case NL80211_IFTYPE_P2P_CLIENT:
328 case NL80211_IFTYPE_MONITOR:
329 wil_info(wil, "fw error recovery requested (try %d)...\n",
330 wil->recovery_count);
332 wil->recovery_state = fw_recovery_running;
333 if (0 != wil_wait_for_recovery(wil))
339 case NL80211_IFTYPE_AP:
340 case NL80211_IFTYPE_P2P_GO:
341 wil_info(wil, "No recovery for AP-like interface\n");
342 /* recovery in these modes is done by upper layers */
345 wil_err(wil, "No recovery - unknown interface type %d\n",
349 mutex_unlock(&wil->mutex);
352 static int wil_find_free_vring(struct wil6210_priv *wil)
356 for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) {
357 if (!wil->vring_tx[i].va)
363 static void wil_connect_worker(struct work_struct *work)
366 struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
368 struct net_device *ndev = wil_to_ndev(wil);
370 int cid = wil->pending_connect_cid;
371 int ringid = wil_find_free_vring(wil);
374 wil_err(wil, "No connection pending\n");
378 wil_dbg_wmi(wil, "Configure for connection CID %d\n", cid);
380 rc = wil_vring_init_tx(wil, ringid, 1 << tx_ring_order, cid, 0);
381 wil->pending_connect_cid = -1;
383 wil->sta[cid].status = wil_sta_connected;
384 netif_tx_wake_all_queues(ndev);
386 wil->sta[cid].status = wil_sta_unused;
390 int wil_priv_init(struct wil6210_priv *wil)
394 wil_dbg_misc(wil, "%s()\n", __func__);
396 memset(wil->sta, 0, sizeof(wil->sta));
397 for (i = 0; i < WIL6210_MAX_CID; i++)
398 spin_lock_init(&wil->sta[i].tid_rx_lock);
400 mutex_init(&wil->mutex);
401 mutex_init(&wil->wmi_mutex);
402 mutex_init(&wil->back_rx_mutex);
403 mutex_init(&wil->back_tx_mutex);
404 mutex_init(&wil->probe_client_mutex);
406 init_completion(&wil->wmi_ready);
407 init_completion(&wil->wmi_call);
409 wil->pending_connect_cid = -1;
410 setup_timer(&wil->connect_timer, wil_connect_timer_fn, (ulong)wil);
411 setup_timer(&wil->scan_timer, wil_scan_timer_fn, (ulong)wil);
413 INIT_WORK(&wil->connect_worker, wil_connect_worker);
414 INIT_WORK(&wil->disconnect_worker, wil_disconnect_worker);
415 INIT_WORK(&wil->wmi_event_worker, wmi_event_worker);
416 INIT_WORK(&wil->fw_error_worker, wil_fw_error_worker);
417 INIT_WORK(&wil->back_rx_worker, wil_back_rx_worker);
418 INIT_WORK(&wil->back_tx_worker, wil_back_tx_worker);
419 INIT_WORK(&wil->probe_client_worker, wil_probe_client_worker);
421 INIT_LIST_HEAD(&wil->pending_wmi_ev);
422 INIT_LIST_HEAD(&wil->back_rx_pending);
423 INIT_LIST_HEAD(&wil->back_tx_pending);
424 INIT_LIST_HEAD(&wil->probe_client_pending);
425 spin_lock_init(&wil->wmi_ev_lock);
426 init_waitqueue_head(&wil->wq);
428 wil->wmi_wq = create_singlethread_workqueue(WIL_NAME "_wmi");
432 wil->wq_service = create_singlethread_workqueue(WIL_NAME "_service");
433 if (!wil->wq_service)
436 wil->last_fw_recovery = jiffies;
437 wil->tx_interframe_timeout = WIL6210_ITR_TX_INTERFRAME_TIMEOUT_DEFAULT;
438 wil->rx_interframe_timeout = WIL6210_ITR_RX_INTERFRAME_TIMEOUT_DEFAULT;
439 wil->tx_max_burst_duration = WIL6210_ITR_TX_MAX_BURST_DURATION_DEFAULT;
440 wil->rx_max_burst_duration = WIL6210_ITR_RX_MAX_BURST_DURATION_DEFAULT;
442 if (rx_ring_overflow_thrsh == WIL6210_RX_HIGH_TRSH_INIT)
443 rx_ring_overflow_thrsh = WIL6210_RX_HIGH_TRSH_DEFAULT;
447 destroy_workqueue(wil->wmi_wq);
453 * wil6210_disconnect - disconnect one connection
454 * @wil: driver context
455 * @bssid: peer to disconnect, NULL to disconnect all
456 * @reason_code: Reason code for the Disassociation frame
457 * @from_event: whether is invoked from FW event handler
459 * Disconnect and release associated resources. If invoked not from the
460 * FW event handler, issue WMI command(s) to trigger MAC disconnect.
462 void wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid,
463 u16 reason_code, bool from_event)
465 wil_dbg_misc(wil, "%s()\n", __func__);
467 del_timer_sync(&wil->connect_timer);
468 _wil6210_disconnect(wil, bssid, reason_code, from_event);
471 void wil_priv_deinit(struct wil6210_priv *wil)
473 wil_dbg_misc(wil, "%s()\n", __func__);
475 wil_set_recovery_state(wil, fw_recovery_idle);
476 del_timer_sync(&wil->scan_timer);
477 cancel_work_sync(&wil->disconnect_worker);
478 cancel_work_sync(&wil->fw_error_worker);
479 mutex_lock(&wil->mutex);
480 wil6210_disconnect(wil, NULL, WLAN_REASON_DEAUTH_LEAVING, false);
481 mutex_unlock(&wil->mutex);
482 wmi_event_flush(wil);
483 wil_back_rx_flush(wil);
484 cancel_work_sync(&wil->back_rx_worker);
485 wil_back_tx_flush(wil);
486 cancel_work_sync(&wil->back_tx_worker);
487 wil_probe_client_flush(wil);
488 cancel_work_sync(&wil->probe_client_worker);
489 destroy_workqueue(wil->wq_service);
490 destroy_workqueue(wil->wmi_wq);
493 /* target operations */
495 #define R(a) ioread32(wil->csr + HOSTADDR(a))
496 /* register write. wmb() to make sure it is completed */
497 #define W(a, v) do { iowrite32(v, wil->csr + HOSTADDR(a)); wmb(); } while (0)
498 /* register set = read, OR, write */
499 #define S(a, v) W(a, R(a) | v)
500 /* register clear = read, AND with inverted, write */
501 #define C(a, v) W(a, R(a) & ~v)
503 static inline void wil_halt_cpu(struct wil6210_priv *wil)
505 W(RGF_USER_USER_CPU_0, BIT_USER_USER_CPU_MAN_RST);
506 W(RGF_USER_MAC_CPU_0, BIT_USER_MAC_CPU_MAN_RST);
509 static inline void wil_release_cpu(struct wil6210_priv *wil)
512 W(RGF_USER_USER_CPU_0, 1);
515 static int wil_target_reset(struct wil6210_priv *wil)
519 bool is_reset_v2 = test_bit(hw_capability_reset_v2,
520 wil->hw_capabilities);
522 wil_dbg_misc(wil, "Resetting \"%s\"...\n", wil->hw_name);
524 /* Clear MAC link up */
525 S(RGF_HP_CTRL, BIT(15));
526 S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT_HPAL_PERST_FROM_PAD);
527 S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT_CAR_PERST_RST);
531 /* clear all boot loader "ready" bits */
532 W(RGF_USER_BL + offsetof(struct RGF_BL, ready), 0);
533 /* Clear Fw Download notification */
534 C(RGF_USER_USAGE_6, BIT(0));
537 S(RGF_CAF_OSC_CONTROL, BIT_CAF_OSC_XTAL_EN);
538 /* XTAL stabilization should take about 3ms */
539 usleep_range(5000, 7000);
540 x = R(RGF_CAF_PLL_LOCK_STATUS);
541 if (!(x & BIT_CAF_OSC_DIG_XTAL_STABLE)) {
542 wil_err(wil, "Xtal stabilization timeout\n"
543 "RGF_CAF_PLL_LOCK_STATUS = 0x%08x\n", x);
546 /* switch 10k to XTAL*/
547 C(RGF_USER_SPARROW_M_4, BIT_SPARROW_M_4_SEL_SLEEP_OR_REF);
549 C(RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_CAR_AHB_SW_SEL);
551 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x3ff81f);
552 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0xf);
555 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0xFE000000);
556 W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0x0000003F);
557 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3,
558 is_reset_v2 ? 0x000000f0 : 0x00000170);
559 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0xFFE7FE00);
562 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x0);
563 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0x0);
566 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0);
567 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0);
568 W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0);
569 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
572 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000003);
573 /* reset A2 PCIE AHB */
574 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00008000);
576 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000001);
577 W(RGF_PCIE_LOS_COUNTER_CTL, BIT(6) | BIT(8));
578 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00008000);
581 /* TODO: check order here!!! Erez code is different */
582 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
584 /* wait until device ready. typical time is 20..80 msec */
587 x = R(RGF_USER_BL + offsetof(struct RGF_BL, ready));
588 if (delay++ > RST_COUNT) {
589 wil_err(wil, "Reset not completed, bl.ready 0x%08x\n",
593 } while (!(x & BIT_BL_READY));
596 W(RGF_PCIE_LOS_COUNTER_CTL, BIT(8));
598 C(RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_RST_PWGD);
600 wil_dbg_misc(wil, "Reset completed in %d ms\n", delay * RST_DELAY);
604 void wil_mbox_ring_le2cpus(struct wil6210_mbox_ring *r)
606 le32_to_cpus(&r->base);
607 le16_to_cpus(&r->entry_size);
608 le16_to_cpus(&r->size);
609 le32_to_cpus(&r->tail);
610 le32_to_cpus(&r->head);
613 static int wil_get_bl_info(struct wil6210_priv *wil)
615 struct net_device *ndev = wil_to_ndev(wil);
618 wil_memcpy_fromio_32(&bl, wil->csr + HOSTADDR(RGF_USER_BL), sizeof(bl));
619 le32_to_cpus(&bl.ready);
620 le32_to_cpus(&bl.version);
621 le32_to_cpus(&bl.rf_type);
622 le32_to_cpus(&bl.baseband_type);
624 if (!is_valid_ether_addr(bl.mac_address)) {
625 wil_err(wil, "BL: Invalid MAC %pM\n", bl.mac_address);
629 ether_addr_copy(ndev->perm_addr, bl.mac_address);
630 if (!is_valid_ether_addr(ndev->dev_addr))
631 ether_addr_copy(ndev->dev_addr, bl.mac_address);
633 "Boot Loader: ver = %d MAC = %pM RF = 0x%08x bband = 0x%08x\n",
634 bl.version, bl.mac_address, bl.rf_type, bl.baseband_type);
639 static int wil_wait_for_fw_ready(struct wil6210_priv *wil)
641 ulong to = msecs_to_jiffies(1000);
642 ulong left = wait_for_completion_timeout(&wil->wmi_ready, to);
645 wil_err(wil, "Firmware not ready\n");
648 wil_info(wil, "FW ready after %d ms. HW version 0x%08x\n",
649 jiffies_to_msecs(to-left), wil->hw_version);
655 * We reset all the structures, and we reset the UMAC.
656 * After calling this routine, you're expected to reload
659 int wil_reset(struct wil6210_priv *wil, bool load_fw)
663 wil_dbg_misc(wil, "%s()\n", __func__);
665 if (wil->hw_version == HW_VER_UNKNOWN)
668 WARN_ON(!mutex_is_locked(&wil->mutex));
669 WARN_ON(test_bit(wil_status_napi_en, wil->status));
671 cancel_work_sync(&wil->disconnect_worker);
672 wil6210_disconnect(wil, NULL, WLAN_REASON_DEAUTH_LEAVING, false);
674 /* prevent NAPI from being scheduled */
675 bitmap_zero(wil->status, wil_status_last);
677 if (wil->scan_request) {
678 wil_dbg_misc(wil, "Abort scan_request 0x%p\n",
680 del_timer_sync(&wil->scan_timer);
681 cfg80211_scan_done(wil->scan_request, true);
682 wil->scan_request = NULL;
687 wmi_event_flush(wil);
689 flush_workqueue(wil->wq_service);
690 flush_workqueue(wil->wmi_wq);
692 rc = wil_target_reset(wil);
697 rc = wil_get_bl_info(wil);
702 wil_info(wil, "Use firmware <%s> + board <%s>\n", WIL_FW_NAME,
706 /* Loading f/w from the file */
707 rc = wil_request_firmware(wil, WIL_FW_NAME);
710 rc = wil_request_firmware(wil, WIL_FW2_NAME);
714 /* Mark FW as loaded from host */
715 S(RGF_USER_USAGE_6, 1);
717 /* clear any interrupts which on-card-firmware
720 wil6210_clear_irq(wil);
721 /* CAF_ICR - clear and mask */
722 /* it is W1C, clear by writing back same value */
723 S(RGF_CAF_ICR + offsetof(struct RGF_ICR, ICR), 0);
724 W(RGF_CAF_ICR + offsetof(struct RGF_ICR, IMV), ~0);
726 wil_release_cpu(wil);
729 /* init after reset */
730 wil->pending_connect_cid = -1;
731 reinit_completion(&wil->wmi_ready);
732 reinit_completion(&wil->wmi_call);
735 wil_configure_interrupt_moderation(wil);
738 /* we just started MAC, wait for FW ready */
739 rc = wil_wait_for_fw_ready(wil);
750 void wil_fw_error_recovery(struct wil6210_priv *wil)
752 wil_dbg_misc(wil, "starting fw error recovery\n");
753 wil->recovery_state = fw_recovery_pending;
754 schedule_work(&wil->fw_error_worker);
757 int __wil_up(struct wil6210_priv *wil)
759 struct net_device *ndev = wil_to_ndev(wil);
760 struct wireless_dev *wdev = wil->wdev;
763 WARN_ON(!mutex_is_locked(&wil->mutex));
765 rc = wil_reset(wil, true);
769 /* Rx VRING. After MAC and beacon */
770 rc = wil_rx_init(wil, 1 << rx_ring_order);
774 switch (wdev->iftype) {
775 case NL80211_IFTYPE_STATION:
776 wil_dbg_misc(wil, "type: STATION\n");
777 ndev->type = ARPHRD_ETHER;
779 case NL80211_IFTYPE_AP:
780 wil_dbg_misc(wil, "type: AP\n");
781 ndev->type = ARPHRD_ETHER;
783 case NL80211_IFTYPE_P2P_CLIENT:
784 wil_dbg_misc(wil, "type: P2P_CLIENT\n");
785 ndev->type = ARPHRD_ETHER;
787 case NL80211_IFTYPE_P2P_GO:
788 wil_dbg_misc(wil, "type: P2P_GO\n");
789 ndev->type = ARPHRD_ETHER;
791 case NL80211_IFTYPE_MONITOR:
792 wil_dbg_misc(wil, "type: Monitor\n");
793 ndev->type = ARPHRD_IEEE80211_RADIOTAP;
794 /* ARPHRD_IEEE80211 or ARPHRD_IEEE80211_RADIOTAP ? */
800 /* MAC address - pre-requisite for other commands */
801 wmi_set_mac_address(wil, ndev->dev_addr);
803 wil_dbg_misc(wil, "NAPI enable\n");
804 napi_enable(&wil->napi_rx);
805 napi_enable(&wil->napi_tx);
806 set_bit(wil_status_napi_en, wil->status);
808 if (wil->platform_ops.bus_request)
809 wil->platform_ops.bus_request(wil->platform_handle,
810 WIL_MAX_BUS_REQUEST_KBPS);
815 int wil_up(struct wil6210_priv *wil)
819 wil_dbg_misc(wil, "%s()\n", __func__);
821 mutex_lock(&wil->mutex);
823 mutex_unlock(&wil->mutex);
828 int __wil_down(struct wil6210_priv *wil)
830 int iter = WAIT_FOR_DISCONNECT_TIMEOUT_MS /
831 WAIT_FOR_DISCONNECT_INTERVAL_MS;
833 WARN_ON(!mutex_is_locked(&wil->mutex));
835 if (wil->platform_ops.bus_request)
836 wil->platform_ops.bus_request(wil->platform_handle, 0);
838 wil_disable_irq(wil);
839 if (test_and_clear_bit(wil_status_napi_en, wil->status)) {
840 napi_disable(&wil->napi_rx);
841 napi_disable(&wil->napi_tx);
842 wil_dbg_misc(wil, "NAPI disable\n");
846 if (wil->scan_request) {
847 wil_dbg_misc(wil, "Abort scan_request 0x%p\n",
849 del_timer_sync(&wil->scan_timer);
850 cfg80211_scan_done(wil->scan_request, true);
851 wil->scan_request = NULL;
854 if (test_bit(wil_status_fwconnected, wil->status) ||
855 test_bit(wil_status_fwconnecting, wil->status))
856 wmi_send(wil, WMI_DISCONNECT_CMDID, NULL, 0);
858 /* make sure wil is idle (not connected) */
859 mutex_unlock(&wil->mutex);
861 int idle = !test_bit(wil_status_fwconnected, wil->status) &&
862 !test_bit(wil_status_fwconnecting, wil->status);
865 msleep(WAIT_FOR_DISCONNECT_INTERVAL_MS);
867 mutex_lock(&wil->mutex);
870 wil_err(wil, "timeout waiting for idle FW/HW\n");
872 wil_reset(wil, false);
877 int wil_down(struct wil6210_priv *wil)
881 wil_dbg_misc(wil, "%s()\n", __func__);
883 wil_set_recovery_state(wil, fw_recovery_idle);
884 mutex_lock(&wil->mutex);
885 rc = __wil_down(wil);
886 mutex_unlock(&wil->mutex);
891 int wil_find_cid(struct wil6210_priv *wil, const u8 *mac)
896 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
897 if ((wil->sta[i].status != wil_sta_unused) &&
898 ether_addr_equal(wil->sta[i].addr, mac)) {