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
28 bool debug_fw; /* = false; */
29 module_param(debug_fw, bool, S_IRUGO);
30 MODULE_PARM_DESC(debug_fw, " do not perform card reset. For FW debug");
33 module_param(no_fw_recovery, bool, S_IRUGO | S_IWUSR);
34 MODULE_PARM_DESC(no_fw_recovery, " disable automatic FW error recovery");
36 /* if not set via modparam, will be set to default value of 1/8 of
37 * rx ring size during init flow
39 unsigned short rx_ring_overflow_thrsh = WIL6210_RX_HIGH_TRSH_INIT;
40 module_param(rx_ring_overflow_thrsh, ushort, S_IRUGO);
41 MODULE_PARM_DESC(rx_ring_overflow_thrsh,
42 " RX ring overflow threshold in descriptors.");
44 /* We allow allocation of more than 1 page buffers to support large packets.
45 * It is suboptimal behavior performance wise in case MTU above page size.
47 unsigned int mtu_max = TXRX_BUF_LEN_DEFAULT - WIL_MAX_MPDU_OVERHEAD;
48 static int mtu_max_set(const char *val, const struct kernel_param *kp)
52 /* sets mtu_max directly. no need to restore it in case of
53 * illegal value since we assume this will fail insmod
55 ret = param_set_uint(val, kp);
59 if (mtu_max < 68 || mtu_max > WIL_MAX_ETH_MTU)
65 static struct kernel_param_ops mtu_max_ops = {
67 .get = param_get_uint,
70 module_param_cb(mtu_max, &mtu_max_ops, &mtu_max, S_IRUGO);
71 MODULE_PARM_DESC(mtu_max, " Max MTU value.");
73 static uint rx_ring_order = WIL_RX_RING_SIZE_ORDER_DEFAULT;
74 static uint tx_ring_order = WIL_TX_RING_SIZE_ORDER_DEFAULT;
75 static uint bcast_ring_order = WIL_BCAST_RING_SIZE_ORDER_DEFAULT;
77 static int ring_order_set(const char *val, const struct kernel_param *kp)
82 ret = kstrtouint(val, 0, &x);
86 if ((x < WIL_RING_SIZE_ORDER_MIN) || (x > WIL_RING_SIZE_ORDER_MAX))
89 *((uint *)kp->arg) = x;
94 static struct kernel_param_ops ring_order_ops = {
95 .set = ring_order_set,
96 .get = param_get_uint,
99 module_param_cb(rx_ring_order, &ring_order_ops, &rx_ring_order, S_IRUGO);
100 MODULE_PARM_DESC(rx_ring_order, " Rx ring order; size = 1 << order");
101 module_param_cb(tx_ring_order, &ring_order_ops, &tx_ring_order, S_IRUGO);
102 MODULE_PARM_DESC(tx_ring_order, " Tx ring order; size = 1 << order");
104 #define RST_DELAY (20) /* msec, for loop in @wil_target_reset */
105 #define RST_COUNT (1 + 1000/RST_DELAY) /* round up to be above 1 sec total */
108 * Due to a hardware issue,
109 * one has to read/write to/from NIC in 32-bit chunks;
110 * regular memcpy_fromio and siblings will
111 * not work on 64-bit platform - it uses 64-bit transactions
113 * Force 32-bit transactions to enable NIC on 64-bit platforms
115 * To avoid byte swap on big endian host, __raw_{read|write}l
116 * should be used - {read|write}l would swap bytes to provide
117 * little endian on PCI value in host endianness.
119 void wil_memcpy_fromio_32(void *dst, const volatile void __iomem *src,
123 const volatile u32 __iomem *s = src;
125 /* size_t is unsigned, if (count%4 != 0) it will wrap */
126 for (count += 4; count > 4; count -= 4)
127 *d++ = __raw_readl(s++);
130 void wil_memcpy_toio_32(volatile void __iomem *dst, const void *src,
133 volatile u32 __iomem *d = dst;
136 for (count += 4; count > 4; count -= 4)
137 __raw_writel(*s++, d++);
140 static void wil_disconnect_cid(struct wil6210_priv *wil, int cid,
141 u16 reason_code, bool from_event)
142 __acquires(&sta->tid_rx_lock) __releases(&sta->tid_rx_lock)
145 struct net_device *ndev = wil_to_ndev(wil);
146 struct wireless_dev *wdev = wil->wdev;
147 struct wil_sta_info *sta = &wil->sta[cid];
150 wil_dbg_misc(wil, "%s(CID %d, status %d)\n", __func__, cid,
153 if (sta->status != wil_sta_unused) {
155 wmi_disconnect_sta(wil, sta->addr, reason_code);
157 switch (wdev->iftype) {
158 case NL80211_IFTYPE_AP:
159 case NL80211_IFTYPE_P2P_GO:
160 /* AP-like interface */
161 cfg80211_del_sta(ndev, sta->addr, GFP_KERNEL);
166 sta->status = wil_sta_unused;
169 for (i = 0; i < WIL_STA_TID_NUM; i++) {
170 struct wil_tid_ampdu_rx *r;
172 spin_lock_bh(&sta->tid_rx_lock);
175 sta->tid_rx[i] = NULL;
176 wil_tid_ampdu_rx_free(wil, r);
178 spin_unlock_bh(&sta->tid_rx_lock);
180 for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
181 if (wil->vring2cid_tid[i][0] == cid)
182 wil_vring_fini_tx(wil, i);
184 memset(&sta->stats, 0, sizeof(sta->stats));
187 static void _wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid,
188 u16 reason_code, bool from_event)
191 struct net_device *ndev = wil_to_ndev(wil);
192 struct wireless_dev *wdev = wil->wdev;
195 wil_dbg_misc(wil, "%s(bssid=%pM, reason=%d, ev%s)\n", __func__, bssid,
196 reason_code, from_event ? "+" : "-");
199 * - disconnect single STA, still connected
200 * - disconnect single STA, already disconnected
203 * For "disconnect all", there are 2 options:
205 * - bssid is our MAC address
207 if (bssid && memcmp(ndev->dev_addr, bssid, ETH_ALEN)) {
208 cid = wil_find_cid(wil, bssid);
209 wil_dbg_misc(wil, "Disconnect %pM, CID=%d, reason=%d\n",
210 bssid, cid, reason_code);
211 if (cid >= 0) /* disconnect 1 peer */
212 wil_disconnect_cid(wil, cid, reason_code, from_event);
214 wil_dbg_misc(wil, "Disconnect all\n");
215 for (cid = 0; cid < WIL6210_MAX_CID; cid++)
216 wil_disconnect_cid(wil, cid, reason_code, from_event);
220 switch (wdev->iftype) {
221 case NL80211_IFTYPE_STATION:
222 case NL80211_IFTYPE_P2P_CLIENT:
224 netif_tx_stop_all_queues(ndev);
225 netif_carrier_off(ndev);
227 if (test_bit(wil_status_fwconnected, wil->status)) {
228 clear_bit(wil_status_fwconnected, wil->status);
229 cfg80211_disconnected(ndev, reason_code,
230 NULL, 0, false, GFP_KERNEL);
231 } else if (test_bit(wil_status_fwconnecting, wil->status)) {
232 cfg80211_connect_result(ndev, bssid, NULL, 0, NULL, 0,
233 WLAN_STATUS_UNSPECIFIED_FAILURE,
236 clear_bit(wil_status_fwconnecting, wil->status);
243 static void wil_disconnect_worker(struct work_struct *work)
245 struct wil6210_priv *wil = container_of(work,
246 struct wil6210_priv, disconnect_worker);
248 mutex_lock(&wil->mutex);
249 _wil6210_disconnect(wil, NULL, WLAN_REASON_UNSPECIFIED, false);
250 mutex_unlock(&wil->mutex);
253 static void wil_connect_timer_fn(ulong x)
255 struct wil6210_priv *wil = (void *)x;
257 wil_dbg_misc(wil, "Connect timeout\n");
259 /* reschedule to thread context - disconnect won't
260 * run from atomic context
262 schedule_work(&wil->disconnect_worker);
265 static void wil_scan_timer_fn(ulong x)
267 struct wil6210_priv *wil = (void *)x;
269 clear_bit(wil_status_fwready, wil->status);
270 wil_err(wil, "Scan timeout detected, start fw error recovery\n");
271 wil->recovery_state = fw_recovery_pending;
272 schedule_work(&wil->fw_error_worker);
275 static int wil_wait_for_recovery(struct wil6210_priv *wil)
277 if (wait_event_interruptible(wil->wq, wil->recovery_state !=
278 fw_recovery_pending)) {
279 wil_err(wil, "Interrupt, canceling recovery\n");
282 if (wil->recovery_state != fw_recovery_running) {
283 wil_info(wil, "Recovery cancelled\n");
286 wil_info(wil, "Proceed with recovery\n");
290 void wil_set_recovery_state(struct wil6210_priv *wil, int state)
292 wil_dbg_misc(wil, "%s(%d -> %d)\n", __func__,
293 wil->recovery_state, state);
295 wil->recovery_state = state;
296 wake_up_interruptible(&wil->wq);
299 static void wil_fw_error_worker(struct work_struct *work)
301 struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
303 struct wireless_dev *wdev = wil->wdev;
305 wil_dbg_misc(wil, "fw error worker\n");
307 if (!netif_running(wil_to_ndev(wil))) {
308 wil_info(wil, "No recovery - interface is down\n");
312 /* increment @recovery_count if less then WIL6210_FW_RECOVERY_TO
313 * passed since last recovery attempt
315 if (time_is_after_jiffies(wil->last_fw_recovery +
316 WIL6210_FW_RECOVERY_TO))
317 wil->recovery_count++;
319 wil->recovery_count = 1; /* fw was alive for a long time */
321 if (wil->recovery_count > WIL6210_FW_RECOVERY_RETRIES) {
322 wil_err(wil, "too many recovery attempts (%d), giving up\n",
323 wil->recovery_count);
327 wil->last_fw_recovery = jiffies;
329 mutex_lock(&wil->mutex);
330 switch (wdev->iftype) {
331 case NL80211_IFTYPE_STATION:
332 case NL80211_IFTYPE_P2P_CLIENT:
333 case NL80211_IFTYPE_MONITOR:
334 wil_info(wil, "fw error recovery requested (try %d)...\n",
335 wil->recovery_count);
337 wil->recovery_state = fw_recovery_running;
338 if (0 != wil_wait_for_recovery(wil))
344 case NL80211_IFTYPE_AP:
345 case NL80211_IFTYPE_P2P_GO:
346 wil_info(wil, "No recovery for AP-like interface\n");
347 /* recovery in these modes is done by upper layers */
350 wil_err(wil, "No recovery - unknown interface type %d\n",
354 mutex_unlock(&wil->mutex);
357 static int wil_find_free_vring(struct wil6210_priv *wil)
361 for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) {
362 if (!wil->vring_tx[i].va)
368 int wil_bcast_init(struct wil6210_priv *wil)
370 int ri = wil->bcast_vring, rc;
372 if ((ri >= 0) && wil->vring_tx[ri].va)
375 ri = wil_find_free_vring(wil);
379 wil->bcast_vring = ri;
380 rc = wil_vring_init_bcast(wil, ri, 1 << bcast_ring_order);
382 wil->bcast_vring = -1;
387 void wil_bcast_fini(struct wil6210_priv *wil)
389 int ri = wil->bcast_vring;
394 wil->bcast_vring = -1;
395 wil_vring_fini_tx(wil, ri);
398 static void wil_connect_worker(struct work_struct *work)
401 struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
403 struct net_device *ndev = wil_to_ndev(wil);
405 int cid = wil->pending_connect_cid;
406 int ringid = wil_find_free_vring(wil);
409 wil_err(wil, "No connection pending\n");
413 wil_dbg_wmi(wil, "Configure for connection CID %d\n", cid);
415 rc = wil_vring_init_tx(wil, ringid, 1 << tx_ring_order, cid, 0);
416 wil->pending_connect_cid = -1;
418 wil->sta[cid].status = wil_sta_connected;
419 netif_tx_wake_all_queues(ndev);
421 wil->sta[cid].status = wil_sta_unused;
425 int wil_priv_init(struct wil6210_priv *wil)
429 wil_dbg_misc(wil, "%s()\n", __func__);
431 memset(wil->sta, 0, sizeof(wil->sta));
432 for (i = 0; i < WIL6210_MAX_CID; i++)
433 spin_lock_init(&wil->sta[i].tid_rx_lock);
435 mutex_init(&wil->mutex);
436 mutex_init(&wil->wmi_mutex);
437 mutex_init(&wil->back_rx_mutex);
438 mutex_init(&wil->back_tx_mutex);
439 mutex_init(&wil->probe_client_mutex);
441 init_completion(&wil->wmi_ready);
442 init_completion(&wil->wmi_call);
444 wil->pending_connect_cid = -1;
445 wil->bcast_vring = -1;
446 setup_timer(&wil->connect_timer, wil_connect_timer_fn, (ulong)wil);
447 setup_timer(&wil->scan_timer, wil_scan_timer_fn, (ulong)wil);
449 INIT_WORK(&wil->connect_worker, wil_connect_worker);
450 INIT_WORK(&wil->disconnect_worker, wil_disconnect_worker);
451 INIT_WORK(&wil->wmi_event_worker, wmi_event_worker);
452 INIT_WORK(&wil->fw_error_worker, wil_fw_error_worker);
453 INIT_WORK(&wil->back_rx_worker, wil_back_rx_worker);
454 INIT_WORK(&wil->back_tx_worker, wil_back_tx_worker);
455 INIT_WORK(&wil->probe_client_worker, wil_probe_client_worker);
457 INIT_LIST_HEAD(&wil->pending_wmi_ev);
458 INIT_LIST_HEAD(&wil->back_rx_pending);
459 INIT_LIST_HEAD(&wil->back_tx_pending);
460 INIT_LIST_HEAD(&wil->probe_client_pending);
461 spin_lock_init(&wil->wmi_ev_lock);
462 init_waitqueue_head(&wil->wq);
464 wil->wmi_wq = create_singlethread_workqueue(WIL_NAME "_wmi");
468 wil->wq_service = create_singlethread_workqueue(WIL_NAME "_service");
469 if (!wil->wq_service)
472 wil->last_fw_recovery = jiffies;
473 wil->tx_interframe_timeout = WIL6210_ITR_TX_INTERFRAME_TIMEOUT_DEFAULT;
474 wil->rx_interframe_timeout = WIL6210_ITR_RX_INTERFRAME_TIMEOUT_DEFAULT;
475 wil->tx_max_burst_duration = WIL6210_ITR_TX_MAX_BURST_DURATION_DEFAULT;
476 wil->rx_max_burst_duration = WIL6210_ITR_RX_MAX_BURST_DURATION_DEFAULT;
478 if (rx_ring_overflow_thrsh == WIL6210_RX_HIGH_TRSH_INIT)
479 rx_ring_overflow_thrsh = WIL6210_RX_HIGH_TRSH_DEFAULT;
483 destroy_workqueue(wil->wmi_wq);
489 * wil6210_disconnect - disconnect one connection
490 * @wil: driver context
491 * @bssid: peer to disconnect, NULL to disconnect all
492 * @reason_code: Reason code for the Disassociation frame
493 * @from_event: whether is invoked from FW event handler
495 * Disconnect and release associated resources. If invoked not from the
496 * FW event handler, issue WMI command(s) to trigger MAC disconnect.
498 void wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid,
499 u16 reason_code, bool from_event)
501 wil_dbg_misc(wil, "%s()\n", __func__);
503 del_timer_sync(&wil->connect_timer);
504 _wil6210_disconnect(wil, bssid, reason_code, from_event);
507 void wil_priv_deinit(struct wil6210_priv *wil)
509 wil_dbg_misc(wil, "%s()\n", __func__);
511 wil_set_recovery_state(wil, fw_recovery_idle);
512 del_timer_sync(&wil->scan_timer);
513 cancel_work_sync(&wil->disconnect_worker);
514 cancel_work_sync(&wil->fw_error_worker);
515 mutex_lock(&wil->mutex);
516 wil6210_disconnect(wil, NULL, WLAN_REASON_DEAUTH_LEAVING, false);
517 mutex_unlock(&wil->mutex);
518 wmi_event_flush(wil);
519 wil_back_rx_flush(wil);
520 cancel_work_sync(&wil->back_rx_worker);
521 wil_back_tx_flush(wil);
522 cancel_work_sync(&wil->back_tx_worker);
523 wil_probe_client_flush(wil);
524 cancel_work_sync(&wil->probe_client_worker);
525 destroy_workqueue(wil->wq_service);
526 destroy_workqueue(wil->wmi_wq);
529 /* target operations */
531 #define R(a) ioread32(wil->csr + HOSTADDR(a))
532 /* register write. wmb() to make sure it is completed */
533 #define W(a, v) do { iowrite32(v, wil->csr + HOSTADDR(a)); wmb(); } while (0)
534 /* register set = read, OR, write */
535 #define S(a, v) W(a, R(a) | v)
536 /* register clear = read, AND with inverted, write */
537 #define C(a, v) W(a, R(a) & ~v)
539 static inline void wil_halt_cpu(struct wil6210_priv *wil)
541 W(RGF_USER_USER_CPU_0, BIT_USER_USER_CPU_MAN_RST);
542 W(RGF_USER_MAC_CPU_0, BIT_USER_MAC_CPU_MAN_RST);
545 static inline void wil_release_cpu(struct wil6210_priv *wil)
548 W(RGF_USER_USER_CPU_0, 1);
551 static int wil_target_reset(struct wil6210_priv *wil)
556 wil_dbg_misc(wil, "Resetting \"%s\"...\n", wil->hw_name);
558 /* Clear MAC link up */
559 S(RGF_HP_CTRL, BIT(15));
560 S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT_HPAL_PERST_FROM_PAD);
561 S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT_CAR_PERST_RST);
565 /* clear all boot loader "ready" bits */
566 W(RGF_USER_BL + offsetof(struct RGF_BL, ready), 0);
567 /* Clear Fw Download notification */
568 C(RGF_USER_USAGE_6, BIT(0));
570 S(RGF_CAF_OSC_CONTROL, BIT_CAF_OSC_XTAL_EN);
571 /* XTAL stabilization should take about 3ms */
572 usleep_range(5000, 7000);
573 x = R(RGF_CAF_PLL_LOCK_STATUS);
574 if (!(x & BIT_CAF_OSC_DIG_XTAL_STABLE)) {
575 wil_err(wil, "Xtal stabilization timeout\n"
576 "RGF_CAF_PLL_LOCK_STATUS = 0x%08x\n", x);
579 /* switch 10k to XTAL*/
580 C(RGF_USER_SPARROW_M_4, BIT_SPARROW_M_4_SEL_SLEEP_OR_REF);
582 C(RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_CAR_AHB_SW_SEL);
584 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x3ff81f);
585 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0xf);
587 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0xFE000000);
588 W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0x0000003F);
589 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x000000f0);
590 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0xFFE7FE00);
592 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x0);
593 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0x0);
595 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0);
596 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0);
597 W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0);
598 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
600 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000003);
601 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00008000); /* reset A2 PCIE AHB */
603 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
605 /* wait until device ready. typical time is 20..80 msec */
608 x = R(RGF_USER_BL + offsetof(struct RGF_BL, ready));
610 wil_dbg_misc(wil, "BL.ready 0x%08x => 0x%08x\n", x1, x);
613 if (delay++ > RST_COUNT) {
614 wil_err(wil, "Reset not completed, bl.ready 0x%08x\n",
618 } while (x != BIT_BL_READY);
620 C(RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_RST_PWGD);
622 /* enable fix for HW bug related to the SA/DA swap in AP Rx */
623 S(RGF_DMA_OFUL_NID_0, BIT_DMA_OFUL_NID_0_RX_EXT_TR_EN |
624 BIT_DMA_OFUL_NID_0_RX_EXT_A3_SRC);
626 wil_dbg_misc(wil, "Reset completed in %d ms\n", delay * RST_DELAY);
630 void wil_mbox_ring_le2cpus(struct wil6210_mbox_ring *r)
632 le32_to_cpus(&r->base);
633 le16_to_cpus(&r->entry_size);
634 le16_to_cpus(&r->size);
635 le32_to_cpus(&r->tail);
636 le32_to_cpus(&r->head);
639 static int wil_get_bl_info(struct wil6210_priv *wil)
641 struct net_device *ndev = wil_to_ndev(wil);
644 wil_memcpy_fromio_32(&bl, wil->csr + HOSTADDR(RGF_USER_BL), sizeof(bl));
645 le32_to_cpus(&bl.ready);
646 le32_to_cpus(&bl.version);
647 le32_to_cpus(&bl.rf_type);
648 le32_to_cpus(&bl.baseband_type);
650 if (!is_valid_ether_addr(bl.mac_address)) {
651 wil_err(wil, "BL: Invalid MAC %pM\n", bl.mac_address);
655 ether_addr_copy(ndev->perm_addr, bl.mac_address);
656 if (!is_valid_ether_addr(ndev->dev_addr))
657 ether_addr_copy(ndev->dev_addr, bl.mac_address);
659 "Boot Loader: ver = %d MAC = %pM RF = 0x%08x bband = 0x%08x\n",
660 bl.version, bl.mac_address, bl.rf_type, bl.baseband_type);
665 static int wil_wait_for_fw_ready(struct wil6210_priv *wil)
667 ulong to = msecs_to_jiffies(1000);
668 ulong left = wait_for_completion_timeout(&wil->wmi_ready, to);
671 wil_err(wil, "Firmware not ready\n");
674 wil_info(wil, "FW ready after %d ms. HW version 0x%08x\n",
675 jiffies_to_msecs(to-left), wil->hw_version);
681 * We reset all the structures, and we reset the UMAC.
682 * After calling this routine, you're expected to reload
685 int wil_reset(struct wil6210_priv *wil, bool load_fw)
689 wil_dbg_misc(wil, "%s()\n", __func__);
691 if (wil->hw_version == HW_VER_UNKNOWN)
694 WARN_ON(!mutex_is_locked(&wil->mutex));
695 WARN_ON(test_bit(wil_status_napi_en, wil->status));
698 static const u8 mac[ETH_ALEN] = {
699 0x00, 0xde, 0xad, 0x12, 0x34, 0x56,
701 struct net_device *ndev = wil_to_ndev(wil);
703 ether_addr_copy(ndev->perm_addr, mac);
704 ether_addr_copy(ndev->dev_addr, ndev->perm_addr);
708 cancel_work_sync(&wil->disconnect_worker);
709 wil6210_disconnect(wil, NULL, WLAN_REASON_DEAUTH_LEAVING, false);
712 /* prevent NAPI from being scheduled */
713 bitmap_zero(wil->status, wil_status_last);
715 if (wil->scan_request) {
716 wil_dbg_misc(wil, "Abort scan_request 0x%p\n",
718 del_timer_sync(&wil->scan_timer);
719 cfg80211_scan_done(wil->scan_request, true);
720 wil->scan_request = NULL;
725 wmi_event_flush(wil);
727 flush_workqueue(wil->wq_service);
728 flush_workqueue(wil->wmi_wq);
730 rc = wil_target_reset(wil);
735 rc = wil_get_bl_info(wil);
740 wil_info(wil, "Use firmware <%s> + board <%s>\n", WIL_FW_NAME,
744 /* Loading f/w from the file */
745 rc = wil_request_firmware(wil, WIL_FW_NAME);
748 rc = wil_request_firmware(wil, WIL_FW2_NAME);
752 /* Mark FW as loaded from host */
753 S(RGF_USER_USAGE_6, 1);
755 /* clear any interrupts which on-card-firmware
758 wil6210_clear_irq(wil);
759 /* CAF_ICR - clear and mask */
760 /* it is W1C, clear by writing back same value */
761 S(RGF_CAF_ICR + offsetof(struct RGF_ICR, ICR), 0);
762 W(RGF_CAF_ICR + offsetof(struct RGF_ICR, IMV), ~0);
764 wil_release_cpu(wil);
767 /* init after reset */
768 wil->pending_connect_cid = -1;
770 reinit_completion(&wil->wmi_ready);
771 reinit_completion(&wil->wmi_call);
774 wil_configure_interrupt_moderation(wil);
777 /* we just started MAC, wait for FW ready */
778 rc = wil_wait_for_fw_ready(wil);
779 if (rc == 0) /* check FW is responsive */
791 void wil_fw_error_recovery(struct wil6210_priv *wil)
793 wil_dbg_misc(wil, "starting fw error recovery\n");
794 wil->recovery_state = fw_recovery_pending;
795 schedule_work(&wil->fw_error_worker);
798 int __wil_up(struct wil6210_priv *wil)
800 struct net_device *ndev = wil_to_ndev(wil);
801 struct wireless_dev *wdev = wil->wdev;
804 WARN_ON(!mutex_is_locked(&wil->mutex));
806 rc = wil_reset(wil, true);
810 /* Rx VRING. After MAC and beacon */
811 rc = wil_rx_init(wil, 1 << rx_ring_order);
815 switch (wdev->iftype) {
816 case NL80211_IFTYPE_STATION:
817 wil_dbg_misc(wil, "type: STATION\n");
818 ndev->type = ARPHRD_ETHER;
820 case NL80211_IFTYPE_AP:
821 wil_dbg_misc(wil, "type: AP\n");
822 ndev->type = ARPHRD_ETHER;
824 case NL80211_IFTYPE_P2P_CLIENT:
825 wil_dbg_misc(wil, "type: P2P_CLIENT\n");
826 ndev->type = ARPHRD_ETHER;
828 case NL80211_IFTYPE_P2P_GO:
829 wil_dbg_misc(wil, "type: P2P_GO\n");
830 ndev->type = ARPHRD_ETHER;
832 case NL80211_IFTYPE_MONITOR:
833 wil_dbg_misc(wil, "type: Monitor\n");
834 ndev->type = ARPHRD_IEEE80211_RADIOTAP;
835 /* ARPHRD_IEEE80211 or ARPHRD_IEEE80211_RADIOTAP ? */
841 /* MAC address - pre-requisite for other commands */
842 wmi_set_mac_address(wil, ndev->dev_addr);
844 wil_dbg_misc(wil, "NAPI enable\n");
845 napi_enable(&wil->napi_rx);
846 napi_enable(&wil->napi_tx);
847 set_bit(wil_status_napi_en, wil->status);
849 if (wil->platform_ops.bus_request)
850 wil->platform_ops.bus_request(wil->platform_handle,
851 WIL_MAX_BUS_REQUEST_KBPS);
856 int wil_up(struct wil6210_priv *wil)
860 wil_dbg_misc(wil, "%s()\n", __func__);
862 mutex_lock(&wil->mutex);
864 mutex_unlock(&wil->mutex);
869 int __wil_down(struct wil6210_priv *wil)
871 int iter = WAIT_FOR_DISCONNECT_TIMEOUT_MS /
872 WAIT_FOR_DISCONNECT_INTERVAL_MS;
874 WARN_ON(!mutex_is_locked(&wil->mutex));
876 if (wil->platform_ops.bus_request)
877 wil->platform_ops.bus_request(wil->platform_handle, 0);
879 wil_disable_irq(wil);
880 if (test_and_clear_bit(wil_status_napi_en, wil->status)) {
881 napi_disable(&wil->napi_rx);
882 napi_disable(&wil->napi_tx);
883 wil_dbg_misc(wil, "NAPI disable\n");
887 if (wil->scan_request) {
888 wil_dbg_misc(wil, "Abort scan_request 0x%p\n",
890 del_timer_sync(&wil->scan_timer);
891 cfg80211_scan_done(wil->scan_request, true);
892 wil->scan_request = NULL;
895 if (test_bit(wil_status_fwconnected, wil->status) ||
896 test_bit(wil_status_fwconnecting, wil->status))
897 wmi_send(wil, WMI_DISCONNECT_CMDID, NULL, 0);
899 /* make sure wil is idle (not connected) */
900 mutex_unlock(&wil->mutex);
902 int idle = !test_bit(wil_status_fwconnected, wil->status) &&
903 !test_bit(wil_status_fwconnecting, wil->status);
906 msleep(WAIT_FOR_DISCONNECT_INTERVAL_MS);
908 mutex_lock(&wil->mutex);
911 wil_err(wil, "timeout waiting for idle FW/HW\n");
913 wil_reset(wil, false);
918 int wil_down(struct wil6210_priv *wil)
922 wil_dbg_misc(wil, "%s()\n", __func__);
924 wil_set_recovery_state(wil, fw_recovery_idle);
925 mutex_lock(&wil->mutex);
926 rc = __wil_down(wil);
927 mutex_unlock(&wil->mutex);
932 int wil_find_cid(struct wil6210_priv *wil, const u8 *mac)
937 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
938 if ((wil->sta[i].status != wil_sta_unused) &&
939 ether_addr_equal(wil->sta[i].addr, mac)) {