2 * Copyright (c) 2012-2017 Qualcomm Atheros, Inc.
3 * Copyright (c) 2018, The Linux Foundation. All rights reserved.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <linux/moduleparam.h>
19 #include <linux/if_arp.h>
20 #include <linux/etherdevice.h>
24 #include "txrx_edma.h"
26 #include "boot_loader.h"
28 #define WAIT_FOR_HALP_VOTE_MS 100
29 #define WAIT_FOR_SCAN_ABORT_MS 1000
30 #define WIL_DEFAULT_NUM_RX_STATUS_RINGS 1
31 #define WIL_BOARD_FILE_MAX_NAMELEN 128
33 bool debug_fw; /* = false; */
34 module_param(debug_fw, bool, 0444);
35 MODULE_PARM_DESC(debug_fw, " do not perform card reset. For FW debug");
38 module_param(oob_mode, byte, 0444);
39 MODULE_PARM_DESC(oob_mode,
40 " enable out of the box (OOB) mode in FW, for diagnostics and certification");
43 module_param(no_fw_recovery, bool, 0644);
44 MODULE_PARM_DESC(no_fw_recovery, " disable automatic FW error recovery");
46 /* if not set via modparam, will be set to default value of 1/8 of
47 * rx ring size during init flow
49 unsigned short rx_ring_overflow_thrsh = WIL6210_RX_HIGH_TRSH_INIT;
50 module_param(rx_ring_overflow_thrsh, ushort, 0444);
51 MODULE_PARM_DESC(rx_ring_overflow_thrsh,
52 " RX ring overflow threshold in descriptors.");
54 /* We allow allocation of more than 1 page buffers to support large packets.
55 * It is suboptimal behavior performance wise in case MTU above page size.
57 unsigned int mtu_max = TXRX_BUF_LEN_DEFAULT - WIL_MAX_MPDU_OVERHEAD;
58 static int mtu_max_set(const char *val, const struct kernel_param *kp)
62 /* sets mtu_max directly. no need to restore it in case of
63 * illegal value since we assume this will fail insmod
65 ret = param_set_uint(val, kp);
69 if (mtu_max < 68 || mtu_max > WIL_MAX_ETH_MTU)
75 static const struct kernel_param_ops mtu_max_ops = {
77 .get = param_get_uint,
80 module_param_cb(mtu_max, &mtu_max_ops, &mtu_max, 0444);
81 MODULE_PARM_DESC(mtu_max, " Max MTU value.");
83 static uint rx_ring_order = WIL_RX_RING_SIZE_ORDER_DEFAULT;
84 static uint tx_ring_order = WIL_TX_RING_SIZE_ORDER_DEFAULT;
85 static uint bcast_ring_order = WIL_BCAST_RING_SIZE_ORDER_DEFAULT;
87 static int ring_order_set(const char *val, const struct kernel_param *kp)
92 ret = kstrtouint(val, 0, &x);
96 if ((x < WIL_RING_SIZE_ORDER_MIN) || (x > WIL_RING_SIZE_ORDER_MAX))
99 *((uint *)kp->arg) = x;
104 static const struct kernel_param_ops ring_order_ops = {
105 .set = ring_order_set,
106 .get = param_get_uint,
109 module_param_cb(rx_ring_order, &ring_order_ops, &rx_ring_order, 0444);
110 MODULE_PARM_DESC(rx_ring_order, " Rx ring order; size = 1 << order");
111 module_param_cb(tx_ring_order, &ring_order_ops, &tx_ring_order, 0444);
112 MODULE_PARM_DESC(tx_ring_order, " Tx ring order; size = 1 << order");
113 module_param_cb(bcast_ring_order, &ring_order_ops, &bcast_ring_order, 0444);
114 MODULE_PARM_DESC(bcast_ring_order, " Bcast ring order; size = 1 << order");
120 WIL_BOOT_DEVELOPMENT,
124 WIL_SIG_STATUS_VANILLA = 0x0,
125 WIL_SIG_STATUS_DEVELOPMENT = 0x1,
126 WIL_SIG_STATUS_PRODUCTION = 0x2,
127 WIL_SIG_STATUS_CORRUPTED_PRODUCTION = 0x3,
130 #define RST_DELAY (20) /* msec, for loop in @wil_wait_device_ready */
131 #define RST_COUNT (1 + 1000/RST_DELAY) /* round up to be above 1 sec total */
133 #define PMU_READY_DELAY_MS (4) /* ms, for sleep in @wil_wait_device_ready */
135 #define OTP_HW_DELAY (200) /* usec, loop in @wil_wait_device_ready_talyn_mb */
136 /* round up to be above 2 ms total */
137 #define OTP_HW_COUNT (1 + 2000 / OTP_HW_DELAY)
140 * Due to a hardware issue,
141 * one has to read/write to/from NIC in 32-bit chunks;
142 * regular memcpy_fromio and siblings will
143 * not work on 64-bit platform - it uses 64-bit transactions
145 * Force 32-bit transactions to enable NIC on 64-bit platforms
147 * To avoid byte swap on big endian host, __raw_{read|write}l
148 * should be used - {read|write}l would swap bytes to provide
149 * little endian on PCI value in host endianness.
151 void wil_memcpy_fromio_32(void *dst, const volatile void __iomem *src,
155 const volatile u32 __iomem *s = src;
157 for (; count >= 4; count -= 4)
158 *d++ = __raw_readl(s++);
160 if (unlikely(count)) {
161 /* count can be 1..3 */
162 u32 tmp = __raw_readl(s);
164 memcpy(d, &tmp, count);
168 void wil_memcpy_toio_32(volatile void __iomem *dst, const void *src,
171 volatile u32 __iomem *d = dst;
174 for (; count >= 4; count -= 4)
175 __raw_writel(*s++, d++);
177 if (unlikely(count)) {
178 /* count can be 1..3 */
181 memcpy(&tmp, s, count);
182 __raw_writel(tmp, d);
186 static void wil_ring_fini_tx(struct wil6210_priv *wil, int id)
188 struct wil_ring *ring = &wil->ring_tx[id];
189 struct wil_ring_tx_data *txdata = &wil->ring_tx_data[id];
191 lockdep_assert_held(&wil->mutex);
196 wil_dbg_misc(wil, "vring_fini_tx: id=%d\n", id);
198 spin_lock_bh(&txdata->lock);
199 txdata->dot1x_open = false;
200 txdata->mid = U8_MAX;
201 txdata->enabled = 0; /* no Tx can be in progress or start anew */
202 spin_unlock_bh(&txdata->lock);
203 /* napi_synchronize waits for completion of the current NAPI but will
204 * not prevent the next NAPI run.
205 * Add a memory barrier to guarantee that txdata->enabled is zeroed
206 * before napi_synchronize so that the next scheduled NAPI will not
210 /* make sure NAPI won't touch this vring */
211 if (test_bit(wil_status_napi_en, wil->status))
212 napi_synchronize(&wil->napi_tx);
214 wil->txrx_ops.ring_fini_tx(wil, ring);
217 static void wil_disconnect_cid(struct wil6210_vif *vif, int cid,
218 u16 reason_code, bool from_event)
219 __acquires(&sta->tid_rx_lock) __releases(&sta->tid_rx_lock)
222 struct wil6210_priv *wil = vif_to_wil(vif);
223 struct net_device *ndev = vif_to_ndev(vif);
224 struct wireless_dev *wdev = vif_to_wdev(vif);
225 struct wil_sta_info *sta = &wil->sta[cid];
226 int min_ring_id = wil_get_min_tx_ring_id(wil);
229 wil_dbg_misc(wil, "disconnect_cid: CID %d, MID %d, status %d\n",
230 cid, sta->mid, sta->status);
231 /* inform upper/lower layers */
232 if (sta->status != wil_sta_unused) {
233 if (vif->mid != sta->mid) {
234 wil_err(wil, "STA MID mismatch with VIF MID(%d)\n",
236 /* let FW override sta->mid but be more strict with
237 * user space requests
243 bool del_sta = (wdev->iftype == NL80211_IFTYPE_AP) ?
244 disable_ap_sme : false;
245 wmi_disconnect_sta(vif, sta->addr, reason_code,
249 switch (wdev->iftype) {
250 case NL80211_IFTYPE_AP:
251 case NL80211_IFTYPE_P2P_GO:
252 /* AP-like interface */
253 cfg80211_del_sta(ndev, sta->addr, GFP_KERNEL);
258 sta->status = wil_sta_unused;
261 /* reorder buffers */
262 for (i = 0; i < WIL_STA_TID_NUM; i++) {
263 struct wil_tid_ampdu_rx *r;
265 spin_lock_bh(&sta->tid_rx_lock);
268 sta->tid_rx[i] = NULL;
269 wil_tid_ampdu_rx_free(wil, r);
271 spin_unlock_bh(&sta->tid_rx_lock);
274 memset(sta->tid_crypto_rx, 0, sizeof(sta->tid_crypto_rx));
275 memset(&sta->group_crypto_rx, 0, sizeof(sta->group_crypto_rx));
277 for (i = min_ring_id; i < ARRAY_SIZE(wil->ring_tx); i++) {
278 if (wil->ring2cid_tid[i][0] == cid)
279 wil_ring_fini_tx(wil, i);
282 memset(&sta->stats, 0, sizeof(sta->stats));
283 sta->stats.tx_latency_min_us = U32_MAX;
286 static bool wil_vif_is_connected(struct wil6210_priv *wil, u8 mid)
290 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
291 if (wil->sta[i].mid == mid &&
292 wil->sta[i].status == wil_sta_connected)
299 static void _wil6210_disconnect(struct wil6210_vif *vif, const u8 *bssid,
300 u16 reason_code, bool from_event)
302 struct wil6210_priv *wil = vif_to_wil(vif);
304 struct net_device *ndev;
305 struct wireless_dev *wdev;
310 ndev = vif_to_ndev(vif);
311 wdev = vif_to_wdev(vif);
314 wil_info(wil, "bssid=%pM, reason=%d, ev%s\n", bssid,
315 reason_code, from_event ? "+" : "-");
318 * - disconnect single STA, still connected
319 * - disconnect single STA, already disconnected
322 * For "disconnect all", there are 3 options:
324 * - bssid is broadcast address (ff:ff:ff:ff:ff:ff)
325 * - bssid is our MAC address
327 if (bssid && !is_broadcast_ether_addr(bssid) &&
328 !ether_addr_equal_unaligned(ndev->dev_addr, bssid)) {
329 cid = wil_find_cid(wil, vif->mid, bssid);
330 wil_dbg_misc(wil, "Disconnect %pM, CID=%d, reason=%d\n",
331 bssid, cid, reason_code);
332 if (cid >= 0) /* disconnect 1 peer */
333 wil_disconnect_cid(vif, cid, reason_code, from_event);
335 wil_dbg_misc(wil, "Disconnect all\n");
336 for (cid = 0; cid < WIL6210_MAX_CID; cid++)
337 wil_disconnect_cid(vif, cid, reason_code, from_event);
341 switch (wdev->iftype) {
342 case NL80211_IFTYPE_STATION:
343 case NL80211_IFTYPE_P2P_CLIENT:
345 wil_update_net_queues_bh(wil, vif, NULL, true);
346 netif_carrier_off(ndev);
347 if (!wil_has_other_active_ifaces(wil, ndev, false, true))
348 wil6210_bus_request(wil, WIL_DEFAULT_BUS_REQUEST_KBPS);
350 if (test_and_clear_bit(wil_vif_fwconnected, vif->status)) {
351 atomic_dec(&wil->connected_vifs);
352 cfg80211_disconnected(ndev, reason_code,
354 vif->locally_generated_disc,
356 vif->locally_generated_disc = false;
357 } else if (test_bit(wil_vif_fwconnecting, vif->status)) {
358 cfg80211_connect_result(ndev, bssid, NULL, 0, NULL, 0,
359 WLAN_STATUS_UNSPECIFIED_FAILURE,
363 clear_bit(wil_vif_fwconnecting, vif->status);
365 case NL80211_IFTYPE_AP:
366 case NL80211_IFTYPE_P2P_GO:
367 if (!wil_vif_is_connected(wil, vif->mid)) {
368 wil_update_net_queues_bh(wil, vif, NULL, true);
369 if (test_and_clear_bit(wil_vif_fwconnected,
371 atomic_dec(&wil->connected_vifs);
373 wil_update_net_queues_bh(wil, vif, NULL, false);
381 void wil_disconnect_worker(struct work_struct *work)
383 struct wil6210_vif *vif = container_of(work,
384 struct wil6210_vif, disconnect_worker);
385 struct wil6210_priv *wil = vif_to_wil(vif);
386 struct net_device *ndev = vif_to_ndev(vif);
389 struct wmi_cmd_hdr wmi;
390 struct wmi_disconnect_event evt;
393 if (test_bit(wil_vif_fwconnected, vif->status))
394 /* connect succeeded after all */
397 if (!test_bit(wil_vif_fwconnecting, vif->status))
398 /* already disconnected */
401 memset(&reply, 0, sizeof(reply));
403 rc = wmi_call(wil, WMI_DISCONNECT_CMDID, vif->mid, NULL, 0,
404 WMI_DISCONNECT_EVENTID, &reply, sizeof(reply),
405 WIL6210_DISCONNECT_TO_MS);
407 wil_err(wil, "disconnect error %d\n", rc);
411 wil_update_net_queues_bh(wil, vif, NULL, true);
412 netif_carrier_off(ndev);
413 cfg80211_connect_result(ndev, NULL, NULL, 0, NULL, 0,
414 WLAN_STATUS_UNSPECIFIED_FAILURE, GFP_KERNEL);
415 clear_bit(wil_vif_fwconnecting, vif->status);
418 static int wil_wait_for_recovery(struct wil6210_priv *wil)
420 if (wait_event_interruptible(wil->wq, wil->recovery_state !=
421 fw_recovery_pending)) {
422 wil_err(wil, "Interrupt, canceling recovery\n");
425 if (wil->recovery_state != fw_recovery_running) {
426 wil_info(wil, "Recovery cancelled\n");
429 wil_info(wil, "Proceed with recovery\n");
433 void wil_set_recovery_state(struct wil6210_priv *wil, int state)
435 wil_dbg_misc(wil, "set_recovery_state: %d -> %d\n",
436 wil->recovery_state, state);
438 wil->recovery_state = state;
439 wake_up_interruptible(&wil->wq);
442 bool wil_is_recovery_blocked(struct wil6210_priv *wil)
444 return no_fw_recovery && (wil->recovery_state == fw_recovery_pending);
447 static void wil_fw_error_worker(struct work_struct *work)
449 struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
451 struct net_device *ndev = wil->main_ndev;
452 struct wireless_dev *wdev;
454 wil_dbg_misc(wil, "fw error worker\n");
456 if (!ndev || !(ndev->flags & IFF_UP)) {
457 wil_info(wil, "No recovery - interface is down\n");
460 wdev = ndev->ieee80211_ptr;
462 /* increment @recovery_count if less then WIL6210_FW_RECOVERY_TO
463 * passed since last recovery attempt
465 if (time_is_after_jiffies(wil->last_fw_recovery +
466 WIL6210_FW_RECOVERY_TO))
467 wil->recovery_count++;
469 wil->recovery_count = 1; /* fw was alive for a long time */
471 if (wil->recovery_count > WIL6210_FW_RECOVERY_RETRIES) {
472 wil_err(wil, "too many recovery attempts (%d), giving up\n",
473 wil->recovery_count);
477 wil->last_fw_recovery = jiffies;
479 wil_info(wil, "fw error recovery requested (try %d)...\n",
480 wil->recovery_count);
482 wil->recovery_state = fw_recovery_running;
483 if (wil_wait_for_recovery(wil) != 0)
486 mutex_lock(&wil->mutex);
487 /* Needs adaptation for multiple VIFs
488 * need to go over all VIFs and consider the appropriate
491 switch (wdev->iftype) {
492 case NL80211_IFTYPE_STATION:
493 case NL80211_IFTYPE_P2P_CLIENT:
494 case NL80211_IFTYPE_MONITOR:
495 /* silent recovery, upper layers will see disconnect */
499 case NL80211_IFTYPE_AP:
500 case NL80211_IFTYPE_P2P_GO:
501 wil_info(wil, "No recovery for AP-like interface\n");
502 /* recovery in these modes is done by upper layers */
505 wil_err(wil, "No recovery - unknown interface type %d\n",
509 mutex_unlock(&wil->mutex);
512 static int wil_find_free_ring(struct wil6210_priv *wil)
515 int min_ring_id = wil_get_min_tx_ring_id(wil);
517 for (i = min_ring_id; i < WIL6210_MAX_TX_RINGS; i++) {
518 if (!wil->ring_tx[i].va)
524 int wil_ring_init_tx(struct wil6210_vif *vif, int cid)
526 struct wil6210_priv *wil = vif_to_wil(vif);
527 int rc = -EINVAL, ringid;
530 wil_err(wil, "No connection pending\n");
533 ringid = wil_find_free_ring(wil);
535 wil_err(wil, "No free vring found\n");
539 wil_dbg_wmi(wil, "Configure for connection CID %d MID %d ring %d\n",
540 cid, vif->mid, ringid);
542 rc = wil->txrx_ops.ring_init_tx(vif, ringid, 1 << tx_ring_order,
545 wil_err(wil, "init TX for CID %d MID %d vring %d failed\n",
546 cid, vif->mid, ringid);
552 int wil_bcast_init(struct wil6210_vif *vif)
554 struct wil6210_priv *wil = vif_to_wil(vif);
555 int ri = vif->bcast_ring, rc;
557 if (ri >= 0 && wil->ring_tx[ri].va)
560 ri = wil_find_free_ring(wil);
564 vif->bcast_ring = ri;
565 rc = wil->txrx_ops.ring_init_bcast(vif, ri, 1 << bcast_ring_order);
567 vif->bcast_ring = -1;
572 void wil_bcast_fini(struct wil6210_vif *vif)
574 struct wil6210_priv *wil = vif_to_wil(vif);
575 int ri = vif->bcast_ring;
580 vif->bcast_ring = -1;
581 wil_ring_fini_tx(wil, ri);
584 void wil_bcast_fini_all(struct wil6210_priv *wil)
587 struct wil6210_vif *vif;
589 for (i = 0; i < wil->max_vifs; i++) {
596 int wil_priv_init(struct wil6210_priv *wil)
600 wil_dbg_misc(wil, "priv_init\n");
602 memset(wil->sta, 0, sizeof(wil->sta));
603 for (i = 0; i < WIL6210_MAX_CID; i++) {
604 spin_lock_init(&wil->sta[i].tid_rx_lock);
605 wil->sta[i].mid = U8_MAX;
608 for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) {
609 spin_lock_init(&wil->ring_tx_data[i].lock);
610 wil->ring2cid_tid[i][0] = WIL6210_MAX_CID;
613 mutex_init(&wil->mutex);
614 mutex_init(&wil->vif_mutex);
615 mutex_init(&wil->wmi_mutex);
616 mutex_init(&wil->halp.lock);
618 init_completion(&wil->wmi_ready);
619 init_completion(&wil->wmi_call);
620 init_completion(&wil->halp.comp);
622 INIT_WORK(&wil->wmi_event_worker, wmi_event_worker);
623 INIT_WORK(&wil->fw_error_worker, wil_fw_error_worker);
625 INIT_LIST_HEAD(&wil->pending_wmi_ev);
626 spin_lock_init(&wil->wmi_ev_lock);
627 spin_lock_init(&wil->net_queue_lock);
628 init_waitqueue_head(&wil->wq);
630 wil->wmi_wq = create_singlethread_workqueue(WIL_NAME "_wmi");
634 wil->wq_service = create_singlethread_workqueue(WIL_NAME "_service");
635 if (!wil->wq_service)
638 wil->last_fw_recovery = jiffies;
639 wil->tx_interframe_timeout = WIL6210_ITR_TX_INTERFRAME_TIMEOUT_DEFAULT;
640 wil->rx_interframe_timeout = WIL6210_ITR_RX_INTERFRAME_TIMEOUT_DEFAULT;
641 wil->tx_max_burst_duration = WIL6210_ITR_TX_MAX_BURST_DURATION_DEFAULT;
642 wil->rx_max_burst_duration = WIL6210_ITR_RX_MAX_BURST_DURATION_DEFAULT;
644 if (rx_ring_overflow_thrsh == WIL6210_RX_HIGH_TRSH_INIT)
645 rx_ring_overflow_thrsh = WIL6210_RX_HIGH_TRSH_DEFAULT;
647 wil->ps_profile = WMI_PS_PROFILE_TYPE_DEFAULT;
649 wil->wakeup_trigger = WMI_WAKEUP_TRIGGER_UCAST |
650 WMI_WAKEUP_TRIGGER_BCAST;
651 memset(&wil->suspend_stats, 0, sizeof(wil->suspend_stats));
652 wil->ring_idle_trsh = 16;
654 wil->reply_mid = U8_MAX;
657 /* edma configuration can be updated via debugfs before allocation */
658 wil->num_rx_status_rings = WIL_DEFAULT_NUM_RX_STATUS_RINGS;
659 wil->tx_status_ring_order = WIL_TX_SRING_SIZE_ORDER_DEFAULT;
661 /* Rx status ring size should be bigger than the number of RX buffers
662 * in order to prevent backpressure on the status ring, which may
665 wil->rx_status_ring_order = WIL_RX_SRING_SIZE_ORDER_DEFAULT;
666 /* Number of RX buffer IDs should be bigger than the RX descriptor
667 * ring size as in HW reorder flow, the HW can consume additional
668 * buffers before releasing the previous ones.
670 wil->rx_buff_id_count = WIL_RX_BUFF_ARR_SIZE_DEFAULT;
677 destroy_workqueue(wil->wmi_wq);
682 void wil6210_bus_request(struct wil6210_priv *wil, u32 kbps)
684 if (wil->platform_ops.bus_request) {
685 wil->bus_request_kbps = kbps;
686 wil->platform_ops.bus_request(wil->platform_handle, kbps);
691 * wil6210_disconnect - disconnect one connection
692 * @vif: virtual interface context
693 * @bssid: peer to disconnect, NULL to disconnect all
694 * @reason_code: Reason code for the Disassociation frame
695 * @from_event: whether is invoked from FW event handler
697 * Disconnect and release associated resources. If invoked not from the
698 * FW event handler, issue WMI command(s) to trigger MAC disconnect.
700 void wil6210_disconnect(struct wil6210_vif *vif, const u8 *bssid,
701 u16 reason_code, bool from_event)
703 struct wil6210_priv *wil = vif_to_wil(vif);
705 wil_dbg_misc(wil, "disconnect\n");
707 del_timer_sync(&vif->connect_timer);
708 _wil6210_disconnect(vif, bssid, reason_code, from_event);
711 void wil_priv_deinit(struct wil6210_priv *wil)
713 wil_dbg_misc(wil, "priv_deinit\n");
715 wil_set_recovery_state(wil, fw_recovery_idle);
716 cancel_work_sync(&wil->fw_error_worker);
717 wmi_event_flush(wil);
718 destroy_workqueue(wil->wq_service);
719 destroy_workqueue(wil->wmi_wq);
722 static void wil_shutdown_bl(struct wil6210_priv *wil)
726 wil_s(wil, RGF_USER_BL +
727 offsetof(struct bl_dedicated_registers_v1,
728 bl_shutdown_handshake), BL_SHUTDOWN_HS_GRTD);
730 usleep_range(100, 150);
732 val = wil_r(wil, RGF_USER_BL +
733 offsetof(struct bl_dedicated_registers_v1,
734 bl_shutdown_handshake));
735 if (val & BL_SHUTDOWN_HS_RTD) {
736 wil_dbg_misc(wil, "BL is ready for halt\n");
740 wil_err(wil, "BL did not report ready for halt\n");
743 /* this format is used by ARC embedded CPU for instruction memory */
744 static inline u32 ARC_me_imm32(u32 d)
746 return ((d & 0xffff0000) >> 16) | ((d & 0x0000ffff) << 16);
749 /* defines access to interrupt vectors for wil_freeze_bl */
750 #define ARC_IRQ_VECTOR_OFFSET(N) ((N) * 8)
751 /* ARC long jump instruction */
752 #define ARC_JAL_INST (0x20200f80)
754 static void wil_freeze_bl(struct wil6210_priv *wil)
757 u32 ivt3 = ARC_IRQ_VECTOR_OFFSET(3);
759 jal = wil_r(wil, wil->iccm_base + ivt3);
760 if (jal != ARC_me_imm32(ARC_JAL_INST)) {
761 wil_dbg_misc(wil, "invalid IVT entry found, skipping\n");
765 /* prevent the target from entering deep sleep
766 * and disabling memory access
768 saved = wil_r(wil, RGF_USER_USAGE_8);
769 wil_w(wil, RGF_USER_USAGE_8, saved | BIT_USER_PREVENT_DEEP_SLEEP);
770 usleep_range(20, 25); /* let the BL process the bit */
772 /* redirect to endless loop in the INT_L1 context and let it trap */
773 wil_w(wil, wil->iccm_base + ivt3 + 4, ARC_me_imm32(ivt3));
774 usleep_range(20, 25); /* let the BL get into the trap */
776 /* verify the BL is frozen */
777 upc = wil_r(wil, RGF_USER_CPU_PC);
778 if (upc < ivt3 || (upc > (ivt3 + 8)))
779 wil_dbg_misc(wil, "BL freeze failed, PC=0x%08X\n", upc);
781 wil_w(wil, RGF_USER_USAGE_8, saved);
784 static void wil_bl_prepare_halt(struct wil6210_priv *wil)
788 /* before halting device CPU driver must make sure BL is not accessing
789 * host memory. This is done differently depending on BL version:
790 * 1. For very old BL versions the procedure is skipped
792 * 2. For old BL version we use a special trick to freeze the BL
793 * 3. For new BL versions we shutdown the BL using handshake procedure.
795 tmp = wil_r(wil, RGF_USER_BL +
796 offsetof(struct bl_dedicated_registers_v0,
797 boot_loader_struct_version));
799 wil_dbg_misc(wil, "old BL, skipping halt preparation\n");
803 tmp = wil_r(wil, RGF_USER_BL +
804 offsetof(struct bl_dedicated_registers_v1,
805 bl_shutdown_handshake));
806 ver = BL_SHUTDOWN_HS_PROT_VER(tmp);
809 wil_shutdown_bl(wil);
814 static inline void wil_halt_cpu(struct wil6210_priv *wil)
816 if (wil->hw_version >= HW_VER_TALYN_MB) {
817 wil_w(wil, RGF_USER_USER_CPU_0_TALYN_MB,
818 BIT_USER_USER_CPU_MAN_RST);
819 wil_w(wil, RGF_USER_MAC_CPU_0_TALYN_MB,
820 BIT_USER_MAC_CPU_MAN_RST);
822 wil_w(wil, RGF_USER_USER_CPU_0, BIT_USER_USER_CPU_MAN_RST);
823 wil_w(wil, RGF_USER_MAC_CPU_0, BIT_USER_MAC_CPU_MAN_RST);
827 static inline void wil_release_cpu(struct wil6210_priv *wil)
830 if (wil->hw_version >= HW_VER_TALYN_MB)
831 wil_w(wil, RGF_USER_USER_CPU_0_TALYN_MB, 1);
833 wil_w(wil, RGF_USER_USER_CPU_0, 1);
836 static void wil_set_oob_mode(struct wil6210_priv *wil, u8 mode)
838 wil_info(wil, "oob_mode to %d\n", mode);
841 wil_c(wil, RGF_USER_USAGE_6, BIT_USER_OOB_MODE |
842 BIT_USER_OOB_R2_MODE);
845 wil_c(wil, RGF_USER_USAGE_6, BIT_USER_OOB_R2_MODE);
846 wil_s(wil, RGF_USER_USAGE_6, BIT_USER_OOB_MODE);
849 wil_c(wil, RGF_USER_USAGE_6, BIT_USER_OOB_MODE);
850 wil_s(wil, RGF_USER_USAGE_6, BIT_USER_OOB_R2_MODE);
853 wil_err(wil, "invalid oob_mode: %d\n", mode);
857 static int wil_wait_device_ready(struct wil6210_priv *wil, int no_flash)
862 /* wait until device ready. */
864 msleep(PMU_READY_DELAY_MS);
866 wil_dbg_misc(wil, "Reset completed\n");
870 x = wil_r(wil, RGF_USER_BL +
871 offsetof(struct bl_dedicated_registers_v0,
874 wil_dbg_misc(wil, "BL.ready 0x%08x => 0x%08x\n",
878 if (delay++ > RST_COUNT) {
879 wil_err(wil, "Reset not completed, bl.ready 0x%08x\n",
883 } while (x != BL_READY);
885 wil_dbg_misc(wil, "Reset completed in %d ms\n",
892 static int wil_wait_device_ready_talyn_mb(struct wil6210_priv *wil)
896 bool otp_signature_err;
897 bool hw_section_done;
901 /* Wait for OTP signature test to complete */
902 usleep_range(2000, 2200);
904 wil->boot_config = WIL_BOOT_ERR;
906 /* Poll until OTP signature status is valid.
907 * In vanilla and development modes, when signature test is complete
908 * HW sets BIT_OTP_SIGNATURE_ERR_TALYN_MB.
909 * In production mode BIT_OTP_SIGNATURE_ERR_TALYN_MB remains 0, poll
910 * for signature status change to 2 or 3.
913 otp_hw = wil_r(wil, RGF_USER_OTP_HW_RD_MACHINE_1);
914 signature_status = WIL_GET_BITS(otp_hw, 8, 9);
915 otp_signature_err = otp_hw & BIT_OTP_SIGNATURE_ERR_TALYN_MB;
917 if (otp_signature_err &&
918 signature_status == WIL_SIG_STATUS_VANILLA) {
919 wil->boot_config = WIL_BOOT_VANILLA;
922 if (otp_signature_err &&
923 signature_status == WIL_SIG_STATUS_DEVELOPMENT) {
924 wil->boot_config = WIL_BOOT_DEVELOPMENT;
927 if (!otp_signature_err &&
928 signature_status == WIL_SIG_STATUS_PRODUCTION) {
929 wil->boot_config = WIL_BOOT_PRODUCTION;
932 if (!otp_signature_err &&
934 WIL_SIG_STATUS_CORRUPTED_PRODUCTION) {
935 /* Unrecognized OTP signature found. Possibly a
936 * corrupted production signature, access control
937 * is applied as in production mode, therefore
940 wil->boot_config = WIL_BOOT_PRODUCTION;
943 if (delay++ > OTP_HW_COUNT)
946 usleep_range(OTP_HW_DELAY, OTP_HW_DELAY + 10);
947 } while (!otp_signature_err && signature_status == 0);
949 if (wil->boot_config == WIL_BOOT_ERR) {
951 "invalid boot config, signature_status %d otp_signature_err %d\n",
952 signature_status, otp_signature_err);
957 "signature test done in %d usec, otp_hw 0x%x, boot_config %d\n",
958 delay * OTP_HW_DELAY, otp_hw, wil->boot_config);
960 if (wil->boot_config == WIL_BOOT_VANILLA)
961 /* Assuming not SPI boot (currently not supported) */
964 hw_section_done = otp_hw & BIT_OTP_HW_SECTION_DONE_TALYN_MB;
967 while (!hw_section_done) {
970 otp_hw = wil_r(wil, RGF_USER_OTP_HW_RD_MACHINE_1);
971 hw_section_done = otp_hw & BIT_OTP_HW_SECTION_DONE_TALYN_MB;
973 if (delay++ > RST_COUNT) {
974 wil_err(wil, "TO waiting for hw_section_done\n");
979 wil_dbg_misc(wil, "HW section done in %d ms\n", delay * RST_DELAY);
981 otp_qc_secured = wil_r(wil, RGF_OTP_QC_SECURED);
982 wil->secured_boot = otp_qc_secured & BIT_BOOT_FROM_ROM ? 1 : 0;
983 wil_dbg_misc(wil, "secured boot is %sabled\n",
984 wil->secured_boot ? "en" : "dis");
987 wil_dbg_misc(wil, "Reset completed\n");
992 static int wil_target_reset(struct wil6210_priv *wil, int no_flash)
997 wil_dbg_misc(wil, "Resetting \"%s\"...\n", wil->hw_name);
999 if (wil->hw_version < HW_VER_TALYN) {
1000 /* Clear MAC link up */
1001 wil_s(wil, RGF_HP_CTRL, BIT(15));
1002 wil_s(wil, RGF_USER_CLKS_CTL_SW_RST_MASK_0,
1003 BIT_HPAL_PERST_FROM_PAD);
1004 wil_s(wil, RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT_CAR_PERST_RST);
1010 /* clear all boot loader "ready" bits */
1011 wil_w(wil, RGF_USER_BL +
1012 offsetof(struct bl_dedicated_registers_v0,
1013 boot_loader_ready), 0);
1014 /* this should be safe to write even with old BLs */
1015 wil_w(wil, RGF_USER_BL +
1016 offsetof(struct bl_dedicated_registers_v1,
1017 bl_shutdown_handshake), 0);
1019 /* Clear Fw Download notification */
1020 wil_c(wil, RGF_USER_USAGE_6, BIT(0));
1022 wil_s(wil, RGF_CAF_OSC_CONTROL, BIT_CAF_OSC_XTAL_EN);
1023 /* XTAL stabilization should take about 3ms */
1024 usleep_range(5000, 7000);
1025 x = wil_r(wil, RGF_CAF_PLL_LOCK_STATUS);
1026 if (!(x & BIT_CAF_OSC_DIG_XTAL_STABLE)) {
1027 wil_err(wil, "Xtal stabilization timeout\n"
1028 "RGF_CAF_PLL_LOCK_STATUS = 0x%08x\n", x);
1031 /* switch 10k to XTAL*/
1032 wil_c(wil, RGF_USER_SPARROW_M_4, BIT_SPARROW_M_4_SEL_SLEEP_OR_REF);
1034 wil_c(wil, RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_CAR_AHB_SW_SEL);
1036 wil_w(wil, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x3ff81f);
1037 wil_w(wil, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0xf);
1039 if (wil->hw_version >= HW_VER_TALYN_MB) {
1040 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x7e000000);
1041 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0x0000003f);
1042 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0xc00000f0);
1043 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0xffe7fe00);
1045 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0xfe000000);
1046 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0x0000003f);
1047 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x000000f0);
1048 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0xffe7fe00);
1051 wil_w(wil, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x0);
1052 wil_w(wil, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0x0);
1054 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0);
1055 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0);
1056 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0);
1057 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
1059 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000003);
1060 /* reset A2 PCIE AHB */
1061 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00008000);
1063 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
1065 if (wil->hw_version == HW_VER_TALYN_MB)
1066 rc = wil_wait_device_ready_talyn_mb(wil);
1068 rc = wil_wait_device_ready(wil, no_flash);
1072 wil_c(wil, RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_RST_PWGD);
1074 /* enable fix for HW bug related to the SA/DA swap in AP Rx */
1075 wil_s(wil, RGF_DMA_OFUL_NID_0, BIT_DMA_OFUL_NID_0_RX_EXT_TR_EN |
1076 BIT_DMA_OFUL_NID_0_RX_EXT_A3_SRC);
1078 if (wil->hw_version < HW_VER_TALYN_MB && no_flash) {
1079 /* Reset OTP HW vectors to fit 40MHz */
1080 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME1, 0x60001);
1081 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME2, 0x20027);
1082 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME3, 0x1);
1083 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME4, 0x20027);
1084 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME5, 0x30003);
1085 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME6, 0x20002);
1086 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME7, 0x60001);
1087 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME8, 0x60001);
1088 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME9, 0x60001);
1089 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME10, 0x60001);
1090 wil_w(wil, RGF_USER_XPM_RD_DOUT_SAMPLE_TIME, 0x57);
1096 static void wil_collect_fw_info(struct wil6210_priv *wil)
1098 struct wiphy *wiphy = wil_to_wiphy(wil);
1102 wil_refresh_fw_capabilities(wil);
1104 rc = wmi_get_mgmt_retry(wil, &retry_short);
1106 wiphy->retry_short = retry_short;
1107 wil_dbg_misc(wil, "FW retry_short: %d\n", retry_short);
1111 void wil_refresh_fw_capabilities(struct wil6210_priv *wil)
1113 struct wiphy *wiphy = wil_to_wiphy(wil);
1116 wil->keep_radio_on_during_sleep =
1117 test_bit(WIL_PLATFORM_CAPA_RADIO_ON_IN_SUSPEND,
1118 wil->platform_capa) &&
1119 test_bit(WMI_FW_CAPABILITY_D3_SUSPEND, wil->fw_capabilities);
1121 wil_info(wil, "keep_radio_on_during_sleep (%d)\n",
1122 wil->keep_radio_on_during_sleep);
1124 if (test_bit(WMI_FW_CAPABILITY_RSSI_REPORTING, wil->fw_capabilities))
1125 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1127 wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
1129 if (test_bit(WMI_FW_CAPABILITY_PNO, wil->fw_capabilities)) {
1130 wiphy->max_sched_scan_reqs = 1;
1131 wiphy->max_sched_scan_ssids = WMI_MAX_PNO_SSID_NUM;
1132 wiphy->max_match_sets = WMI_MAX_PNO_SSID_NUM;
1133 wiphy->max_sched_scan_ie_len = WMI_MAX_IE_LEN;
1134 wiphy->max_sched_scan_plans = WMI_MAX_PLANS_NUM;
1137 if (test_bit(WMI_FW_CAPABILITY_TX_REQ_EXT, wil->fw_capabilities))
1138 wiphy->flags |= WIPHY_FLAG_OFFCHAN_TX;
1140 if (wil->platform_ops.set_features) {
1141 features = (test_bit(WMI_FW_CAPABILITY_REF_CLOCK_CONTROL,
1142 wil->fw_capabilities) &&
1143 test_bit(WIL_PLATFORM_CAPA_EXT_CLK,
1144 wil->platform_capa)) ?
1145 BIT(WIL_PLATFORM_FEATURE_FW_EXT_CLK_CONTROL) : 0;
1147 if (wil->n_msi == 3)
1148 features |= BIT(WIL_PLATFORM_FEATURE_TRIPLE_MSI);
1150 wil->platform_ops.set_features(wil->platform_handle, features);
1153 if (test_bit(WMI_FW_CAPABILITY_BACK_WIN_SIZE_64,
1154 wil->fw_capabilities)) {
1155 wil->max_agg_wsize = WIL_MAX_AGG_WSIZE_64;
1156 wil->max_ampdu_size = WIL_MAX_AMPDU_SIZE_128;
1158 wil->max_agg_wsize = WIL_MAX_AGG_WSIZE;
1159 wil->max_ampdu_size = WIL_MAX_AMPDU_SIZE;
1163 void wil_mbox_ring_le2cpus(struct wil6210_mbox_ring *r)
1165 le32_to_cpus(&r->base);
1166 le16_to_cpus(&r->entry_size);
1167 le16_to_cpus(&r->size);
1168 le32_to_cpus(&r->tail);
1169 le32_to_cpus(&r->head);
1172 /* construct actual board file name to use */
1173 void wil_get_board_file(struct wil6210_priv *wil, char *buf, size_t len)
1175 const char *board_file;
1176 const char *wil_talyn_fw_name = ftm_mode ? WIL_FW_NAME_FTM_TALYN :
1179 if (wil->board_file) {
1180 board_file = wil->board_file;
1182 /* If specific FW file is used for Talyn,
1183 * use specific board file
1185 if (strcmp(wil->wil_fw_name, wil_talyn_fw_name) == 0)
1186 board_file = WIL_BRD_NAME_TALYN;
1188 board_file = WIL_BOARD_FILE_NAME;
1191 strlcpy(buf, board_file, len);
1194 static int wil_get_bl_info(struct wil6210_priv *wil)
1196 struct net_device *ndev = wil->main_ndev;
1197 struct wiphy *wiphy = wil_to_wiphy(wil);
1199 struct bl_dedicated_registers_v0 bl0;
1200 struct bl_dedicated_registers_v1 bl1;
1206 wil_memcpy_fromio_32(&bl, wil->csr + HOSTADDR(RGF_USER_BL),
1208 bl_ver = le32_to_cpu(bl.bl0.boot_loader_struct_version);
1209 mac = bl.bl0.mac_address;
1212 le32_to_cpus(&bl.bl0.rf_type);
1213 le32_to_cpus(&bl.bl0.baseband_type);
1214 rf_status = 0; /* actually, unknown */
1216 "Boot Loader struct v%d: MAC = %pM RF = 0x%08x bband = 0x%08x\n",
1218 bl.bl0.rf_type, bl.bl0.baseband_type);
1219 wil_info(wil, "Boot Loader build unknown for struct v0\n");
1221 le16_to_cpus(&bl.bl1.rf_type);
1222 rf_status = le16_to_cpu(bl.bl1.rf_status);
1223 le32_to_cpus(&bl.bl1.baseband_type);
1224 le16_to_cpus(&bl.bl1.bl_version_subminor);
1225 le16_to_cpus(&bl.bl1.bl_version_build);
1227 "Boot Loader struct v%d: MAC = %pM RF = 0x%04x (status 0x%04x) bband = 0x%08x\n",
1229 bl.bl1.rf_type, rf_status,
1230 bl.bl1.baseband_type);
1231 wil_info(wil, "Boot Loader build %d.%d.%d.%d\n",
1232 bl.bl1.bl_version_major, bl.bl1.bl_version_minor,
1233 bl.bl1.bl_version_subminor, bl.bl1.bl_version_build);
1236 if (!is_valid_ether_addr(mac)) {
1237 wil_err(wil, "BL: Invalid MAC %pM\n", mac);
1241 ether_addr_copy(ndev->perm_addr, mac);
1242 ether_addr_copy(wiphy->perm_addr, mac);
1243 if (!is_valid_ether_addr(ndev->dev_addr))
1244 ether_addr_copy(ndev->dev_addr, mac);
1246 if (rf_status) {/* bad RF cable? */
1247 wil_err(wil, "RF communication error 0x%04x",
1255 static void wil_bl_crash_info(struct wil6210_priv *wil, bool is_err)
1257 u32 bl_assert_code, bl_assert_blink, bl_magic_number;
1258 u32 bl_ver = wil_r(wil, RGF_USER_BL +
1259 offsetof(struct bl_dedicated_registers_v0,
1260 boot_loader_struct_version));
1265 bl_assert_code = wil_r(wil, RGF_USER_BL +
1266 offsetof(struct bl_dedicated_registers_v1,
1268 bl_assert_blink = wil_r(wil, RGF_USER_BL +
1269 offsetof(struct bl_dedicated_registers_v1,
1271 bl_magic_number = wil_r(wil, RGF_USER_BL +
1272 offsetof(struct bl_dedicated_registers_v1,
1277 "BL assert code 0x%08x blink 0x%08x magic 0x%08x\n",
1278 bl_assert_code, bl_assert_blink, bl_magic_number);
1281 "BL assert code 0x%08x blink 0x%08x magic 0x%08x\n",
1282 bl_assert_code, bl_assert_blink, bl_magic_number);
1286 static int wil_get_otp_info(struct wil6210_priv *wil)
1288 struct net_device *ndev = wil->main_ndev;
1289 struct wiphy *wiphy = wil_to_wiphy(wil);
1293 if (wil->hw_version >= HW_VER_TALYN_MB)
1294 mac_addr = RGF_OTP_MAC_TALYN_MB;
1296 mac_addr = RGF_OTP_MAC;
1298 wil_memcpy_fromio_32(mac, wil->csr + HOSTADDR(mac_addr),
1300 if (!is_valid_ether_addr(mac)) {
1301 wil_err(wil, "Invalid MAC %pM\n", mac);
1305 ether_addr_copy(ndev->perm_addr, mac);
1306 ether_addr_copy(wiphy->perm_addr, mac);
1307 if (!is_valid_ether_addr(ndev->dev_addr))
1308 ether_addr_copy(ndev->dev_addr, mac);
1313 static int wil_wait_for_fw_ready(struct wil6210_priv *wil)
1315 ulong to = msecs_to_jiffies(2000);
1316 ulong left = wait_for_completion_timeout(&wil->wmi_ready, to);
1319 wil_err(wil, "Firmware not ready\n");
1322 wil_info(wil, "FW ready after %d ms. HW version 0x%08x\n",
1323 jiffies_to_msecs(to-left), wil->hw_version);
1328 void wil_abort_scan(struct wil6210_vif *vif, bool sync)
1330 struct wil6210_priv *wil = vif_to_wil(vif);
1332 struct cfg80211_scan_info info = {
1336 lockdep_assert_held(&wil->vif_mutex);
1338 if (!vif->scan_request)
1341 wil_dbg_misc(wil, "Abort scan_request 0x%p\n", vif->scan_request);
1342 del_timer_sync(&vif->scan_timer);
1343 mutex_unlock(&wil->vif_mutex);
1344 rc = wmi_abort_scan(vif);
1346 wait_event_interruptible_timeout(wil->wq, !vif->scan_request,
1348 WAIT_FOR_SCAN_ABORT_MS));
1350 mutex_lock(&wil->vif_mutex);
1351 if (vif->scan_request) {
1352 cfg80211_scan_done(vif->scan_request, &info);
1353 vif->scan_request = NULL;
1357 void wil_abort_scan_all_vifs(struct wil6210_priv *wil, bool sync)
1361 lockdep_assert_held(&wil->vif_mutex);
1363 for (i = 0; i < wil->max_vifs; i++) {
1364 struct wil6210_vif *vif = wil->vifs[i];
1367 wil_abort_scan(vif, sync);
1371 int wil_ps_update(struct wil6210_priv *wil, enum wmi_ps_profile_type ps_profile)
1375 if (!test_bit(WMI_FW_CAPABILITY_PS_CONFIG, wil->fw_capabilities)) {
1376 wil_err(wil, "set_power_mgmt not supported\n");
1380 rc = wmi_ps_dev_profile_cfg(wil, ps_profile);
1382 wil_err(wil, "wmi_ps_dev_profile_cfg failed (%d)\n", rc);
1384 wil->ps_profile = ps_profile;
1389 static void wil_pre_fw_config(struct wil6210_priv *wil)
1391 /* Mark FW as loaded from host */
1392 wil_s(wil, RGF_USER_USAGE_6, 1);
1394 /* clear any interrupts which on-card-firmware
1397 wil6210_clear_irq(wil);
1398 /* CAF_ICR - clear and mask */
1399 /* it is W1C, clear by writing back same value */
1400 if (wil->hw_version < HW_VER_TALYN_MB) {
1401 wil_s(wil, RGF_CAF_ICR + offsetof(struct RGF_ICR, ICR), 0);
1402 wil_w(wil, RGF_CAF_ICR + offsetof(struct RGF_ICR, IMV), ~0);
1405 RGF_CAF_ICR_TALYN_MB + offsetof(struct RGF_ICR, ICR), 0);
1406 wil_w(wil, RGF_CAF_ICR_TALYN_MB +
1407 offsetof(struct RGF_ICR, IMV), ~0);
1409 /* clear PAL_UNIT_ICR (potential D0->D3 leftover)
1410 * In Talyn-MB host cannot access this register due to
1411 * access control, hence PAL_UNIT_ICR is cleared by the FW
1413 if (wil->hw_version < HW_VER_TALYN_MB)
1414 wil_s(wil, RGF_PAL_UNIT_ICR + offsetof(struct RGF_ICR, ICR),
1417 if (wil->fw_calib_result > 0) {
1418 __le32 val = cpu_to_le32(wil->fw_calib_result |
1419 (CALIB_RESULT_SIGNATURE << 8));
1420 wil_w(wil, RGF_USER_FW_CALIB_RESULT, (u32 __force)val);
1424 static int wil_restore_vifs(struct wil6210_priv *wil)
1426 struct wil6210_vif *vif;
1427 struct net_device *ndev;
1428 struct wireless_dev *wdev;
1431 for (i = 0; i < wil->max_vifs; i++) {
1435 vif->ap_isolate = 0;
1437 ndev = vif_to_ndev(vif);
1438 wdev = vif_to_wdev(vif);
1439 rc = wmi_port_allocate(wil, vif->mid, ndev->dev_addr,
1442 wil_err(wil, "fail to restore VIF %d type %d, rc %d\n",
1443 i, wdev->iftype, rc);
1453 * We reset all the structures, and we reset the UMAC.
1454 * After calling this routine, you're expected to reload
1457 int wil_reset(struct wil6210_priv *wil, bool load_fw)
1460 unsigned long status_flags = BIT(wil_status_resetting);
1462 struct wil6210_vif *vif;
1464 wil_dbg_misc(wil, "reset\n");
1466 WARN_ON(!mutex_is_locked(&wil->mutex));
1467 WARN_ON(test_bit(wil_status_napi_en, wil->status));
1470 static const u8 mac[ETH_ALEN] = {
1471 0x00, 0xde, 0xad, 0x12, 0x34, 0x56,
1473 struct net_device *ndev = wil->main_ndev;
1475 ether_addr_copy(ndev->perm_addr, mac);
1476 ether_addr_copy(ndev->dev_addr, ndev->perm_addr);
1480 if (wil->hw_version == HW_VER_UNKNOWN)
1483 if (test_bit(WIL_PLATFORM_CAPA_T_PWR_ON_0, wil->platform_capa)) {
1484 wil_dbg_misc(wil, "Notify FW to set T_POWER_ON=0\n");
1485 wil_s(wil, RGF_USER_USAGE_8, BIT_USER_SUPPORT_T_POWER_ON_0);
1488 if (test_bit(WIL_PLATFORM_CAPA_EXT_CLK, wil->platform_capa)) {
1489 wil_dbg_misc(wil, "Notify FW on ext clock configuration\n");
1490 wil_s(wil, RGF_USER_USAGE_8, BIT_USER_EXT_CLK);
1493 if (wil->platform_ops.notify) {
1494 rc = wil->platform_ops.notify(wil->platform_handle,
1495 WIL_PLATFORM_EVT_PRE_RESET);
1497 wil_err(wil, "PRE_RESET platform notify failed, rc %d\n",
1501 set_bit(wil_status_resetting, wil->status);
1502 if (test_bit(wil_status_collecting_dumps, wil->status)) {
1503 /* Device collects crash dump, cancel the reset.
1504 * following crash dump collection, reset would take place.
1506 wil_dbg_misc(wil, "reject reset while collecting crash dump\n");
1511 mutex_lock(&wil->vif_mutex);
1512 wil_abort_scan_all_vifs(wil, false);
1513 mutex_unlock(&wil->vif_mutex);
1515 for (i = 0; i < wil->max_vifs; i++) {
1518 cancel_work_sync(&vif->disconnect_worker);
1519 wil6210_disconnect(vif, NULL,
1520 WLAN_REASON_DEAUTH_LEAVING, false);
1523 wil_bcast_fini_all(wil);
1525 /* Disable device led before reset*/
1526 wmi_led_cfg(wil, false);
1528 /* prevent NAPI from being scheduled and prevent wmi commands */
1529 mutex_lock(&wil->wmi_mutex);
1530 if (test_bit(wil_status_suspending, wil->status))
1531 status_flags |= BIT(wil_status_suspending);
1532 bitmap_and(wil->status, wil->status, &status_flags,
1534 wil_dbg_misc(wil, "wil->status (0x%lx)\n", *wil->status);
1535 mutex_unlock(&wil->wmi_mutex);
1539 wmi_event_flush(wil);
1541 flush_workqueue(wil->wq_service);
1542 flush_workqueue(wil->wmi_wq);
1544 no_flash = test_bit(hw_capa_no_flash, wil->hw_capa);
1546 wil_bl_crash_info(wil, false);
1547 wil_disable_irq(wil);
1548 rc = wil_target_reset(wil, no_flash);
1549 wil6210_clear_irq(wil);
1550 wil_enable_irq(wil);
1551 wil->txrx_ops.rx_fini(wil);
1552 wil->txrx_ops.tx_fini(wil);
1555 wil_bl_crash_info(wil, true);
1560 rc = wil_get_otp_info(wil);
1562 rc = wil_get_bl_info(wil);
1563 if (rc == -EAGAIN && !load_fw)
1564 /* ignore RF error if not going up */
1570 wil_set_oob_mode(wil, oob_mode);
1572 char board_file[WIL_BOARD_FILE_MAX_NAMELEN];
1574 if (wil->secured_boot) {
1575 wil_err(wil, "secured boot is not supported\n");
1579 board_file[0] = '\0';
1580 wil_get_board_file(wil, board_file, sizeof(board_file));
1581 wil_info(wil, "Use firmware <%s> + board <%s>\n",
1582 wil->wil_fw_name, board_file);
1585 wil_bl_prepare_halt(wil);
1588 memset(wil->fw_version, 0, sizeof(wil->fw_version));
1589 /* Loading f/w from the file */
1590 rc = wil_request_firmware(wil, wil->wil_fw_name, true);
1593 if (wil->brd_file_addr)
1594 rc = wil_request_board(wil, board_file);
1596 rc = wil_request_firmware(wil, board_file, true);
1600 wil_pre_fw_config(wil);
1601 wil_release_cpu(wil);
1604 /* init after reset */
1605 reinit_completion(&wil->wmi_ready);
1606 reinit_completion(&wil->wmi_call);
1607 reinit_completion(&wil->halp.comp);
1609 clear_bit(wil_status_resetting, wil->status);
1612 wil_unmask_irq(wil);
1614 /* we just started MAC, wait for FW ready */
1615 rc = wil_wait_for_fw_ready(wil);
1619 /* check FW is responsive */
1622 wil_err(wil, "wmi_echo failed, rc %d\n", rc);
1626 wil->txrx_ops.configure_interrupt_moderation(wil);
1628 /* Enable OFU rdy valid bug fix, to prevent hang in oful34_rx
1629 * while there is back-pressure from Host during RX
1631 if (wil->hw_version >= HW_VER_TALYN_MB)
1632 wil_s(wil, RGF_DMA_MISC_CTL,
1633 BIT_OFUL34_RDY_VALID_BUG_FIX_EN);
1635 rc = wil_restore_vifs(wil);
1637 wil_err(wil, "failed to restore vifs, rc %d\n", rc);
1641 wil_collect_fw_info(wil);
1643 if (wil->ps_profile != WMI_PS_PROFILE_TYPE_DEFAULT)
1644 wil_ps_update(wil, wil->ps_profile);
1646 if (wil->platform_ops.notify) {
1647 rc = wil->platform_ops.notify(wil->platform_handle,
1648 WIL_PLATFORM_EVT_FW_RDY);
1650 wil_err(wil, "FW_RDY notify failed, rc %d\n",
1660 clear_bit(wil_status_resetting, wil->status);
1664 void wil_fw_error_recovery(struct wil6210_priv *wil)
1666 wil_dbg_misc(wil, "starting fw error recovery\n");
1668 if (test_bit(wil_status_resetting, wil->status)) {
1669 wil_info(wil, "Reset already in progress\n");
1673 wil->recovery_state = fw_recovery_pending;
1674 schedule_work(&wil->fw_error_worker);
1677 int __wil_up(struct wil6210_priv *wil)
1679 struct net_device *ndev = wil->main_ndev;
1680 struct wireless_dev *wdev = ndev->ieee80211_ptr;
1683 WARN_ON(!mutex_is_locked(&wil->mutex));
1685 rc = wil_reset(wil, true);
1689 /* Rx RING. After MAC and beacon */
1690 rc = wil->txrx_ops.rx_init(wil, rx_ring_order);
1694 rc = wil->txrx_ops.tx_init(wil);
1698 switch (wdev->iftype) {
1699 case NL80211_IFTYPE_STATION:
1700 wil_dbg_misc(wil, "type: STATION\n");
1701 ndev->type = ARPHRD_ETHER;
1703 case NL80211_IFTYPE_AP:
1704 wil_dbg_misc(wil, "type: AP\n");
1705 ndev->type = ARPHRD_ETHER;
1707 case NL80211_IFTYPE_P2P_CLIENT:
1708 wil_dbg_misc(wil, "type: P2P_CLIENT\n");
1709 ndev->type = ARPHRD_ETHER;
1711 case NL80211_IFTYPE_P2P_GO:
1712 wil_dbg_misc(wil, "type: P2P_GO\n");
1713 ndev->type = ARPHRD_ETHER;
1715 case NL80211_IFTYPE_MONITOR:
1716 wil_dbg_misc(wil, "type: Monitor\n");
1717 ndev->type = ARPHRD_IEEE80211_RADIOTAP;
1718 /* ARPHRD_IEEE80211 or ARPHRD_IEEE80211_RADIOTAP ? */
1724 /* MAC address - pre-requisite for other commands */
1725 wmi_set_mac_address(wil, ndev->dev_addr);
1727 wil_dbg_misc(wil, "NAPI enable\n");
1728 napi_enable(&wil->napi_rx);
1729 napi_enable(&wil->napi_tx);
1730 set_bit(wil_status_napi_en, wil->status);
1732 wil6210_bus_request(wil, WIL_DEFAULT_BUS_REQUEST_KBPS);
1737 int wil_up(struct wil6210_priv *wil)
1741 wil_dbg_misc(wil, "up\n");
1743 mutex_lock(&wil->mutex);
1745 mutex_unlock(&wil->mutex);
1750 int __wil_down(struct wil6210_priv *wil)
1752 WARN_ON(!mutex_is_locked(&wil->mutex));
1754 set_bit(wil_status_resetting, wil->status);
1756 wil6210_bus_request(wil, 0);
1758 wil_disable_irq(wil);
1759 if (test_and_clear_bit(wil_status_napi_en, wil->status)) {
1760 napi_disable(&wil->napi_rx);
1761 napi_disable(&wil->napi_tx);
1762 wil_dbg_misc(wil, "NAPI disable\n");
1764 wil_enable_irq(wil);
1766 mutex_lock(&wil->vif_mutex);
1767 wil_p2p_stop_radio_operations(wil);
1768 wil_abort_scan_all_vifs(wil, false);
1769 mutex_unlock(&wil->vif_mutex);
1771 return wil_reset(wil, false);
1774 int wil_down(struct wil6210_priv *wil)
1778 wil_dbg_misc(wil, "down\n");
1780 wil_set_recovery_state(wil, fw_recovery_idle);
1781 mutex_lock(&wil->mutex);
1782 rc = __wil_down(wil);
1783 mutex_unlock(&wil->mutex);
1788 int wil_find_cid(struct wil6210_priv *wil, u8 mid, const u8 *mac)
1793 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1794 if (wil->sta[i].mid == mid &&
1795 wil->sta[i].status != wil_sta_unused &&
1796 ether_addr_equal(wil->sta[i].addr, mac)) {
1805 void wil_halp_vote(struct wil6210_priv *wil)
1808 unsigned long to_jiffies = msecs_to_jiffies(WAIT_FOR_HALP_VOTE_MS);
1810 mutex_lock(&wil->halp.lock);
1812 wil_dbg_irq(wil, "halp_vote: start, HALP ref_cnt (%d)\n",
1815 if (++wil->halp.ref_cnt == 1) {
1816 reinit_completion(&wil->halp.comp);
1817 /* mark to IRQ context to handle HALP ICR */
1818 wil->halp.handle_icr = true;
1819 wil6210_set_halp(wil);
1820 rc = wait_for_completion_timeout(&wil->halp.comp, to_jiffies);
1822 wil_err(wil, "HALP vote timed out\n");
1823 /* Mask HALP as done in case the interrupt is raised */
1824 wil->halp.handle_icr = false;
1825 wil6210_mask_halp(wil);
1828 "halp_vote: HALP vote completed after %d ms\n",
1829 jiffies_to_msecs(to_jiffies - rc));
1833 wil_dbg_irq(wil, "halp_vote: end, HALP ref_cnt (%d)\n",
1836 mutex_unlock(&wil->halp.lock);
1839 void wil_halp_unvote(struct wil6210_priv *wil)
1841 WARN_ON(wil->halp.ref_cnt == 0);
1843 mutex_lock(&wil->halp.lock);
1845 wil_dbg_irq(wil, "halp_unvote: start, HALP ref_cnt (%d)\n",
1848 if (--wil->halp.ref_cnt == 0) {
1849 wil6210_clear_halp(wil);
1850 wil_dbg_irq(wil, "HALP unvote\n");
1853 wil_dbg_irq(wil, "halp_unvote:end, HALP ref_cnt (%d)\n",
1856 mutex_unlock(&wil->halp.lock);
1859 void wil_init_txrx_ops(struct wil6210_priv *wil)
1861 if (wil->use_enhanced_dma_hw)
1862 wil_init_txrx_ops_edma(wil);
1864 wil_init_txrx_ops_legacy_dma(wil);