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>
21 #include <linux/rtnetlink.h>
25 #include "txrx_edma.h"
27 #include "boot_loader.h"
29 #define WAIT_FOR_HALP_VOTE_MS 100
30 #define WAIT_FOR_SCAN_ABORT_MS 1000
31 #define WIL_DEFAULT_NUM_RX_STATUS_RINGS 1
32 #define WIL_BOARD_FILE_MAX_NAMELEN 128
34 bool debug_fw; /* = false; */
35 module_param(debug_fw, bool, 0444);
36 MODULE_PARM_DESC(debug_fw, " do not perform card reset. For FW debug");
39 module_param(oob_mode, byte, 0444);
40 MODULE_PARM_DESC(oob_mode,
41 " enable out of the box (OOB) mode in FW, for diagnostics and certification");
44 module_param(no_fw_recovery, bool, 0644);
45 MODULE_PARM_DESC(no_fw_recovery, " disable automatic FW error recovery");
47 /* if not set via modparam, will be set to default value of 1/8 of
48 * rx ring size during init flow
50 unsigned short rx_ring_overflow_thrsh = WIL6210_RX_HIGH_TRSH_INIT;
51 module_param(rx_ring_overflow_thrsh, ushort, 0444);
52 MODULE_PARM_DESC(rx_ring_overflow_thrsh,
53 " RX ring overflow threshold in descriptors.");
55 /* We allow allocation of more than 1 page buffers to support large packets.
56 * It is suboptimal behavior performance wise in case MTU above page size.
58 unsigned int mtu_max = TXRX_BUF_LEN_DEFAULT - WIL_MAX_MPDU_OVERHEAD;
59 static int mtu_max_set(const char *val, const struct kernel_param *kp)
63 /* sets mtu_max directly. no need to restore it in case of
64 * illegal value since we assume this will fail insmod
66 ret = param_set_uint(val, kp);
70 if (mtu_max < 68 || mtu_max > WIL_MAX_ETH_MTU)
76 static const struct kernel_param_ops mtu_max_ops = {
78 .get = param_get_uint,
81 module_param_cb(mtu_max, &mtu_max_ops, &mtu_max, 0444);
82 MODULE_PARM_DESC(mtu_max, " Max MTU value.");
84 static uint rx_ring_order;
85 static uint tx_ring_order = WIL_TX_RING_SIZE_ORDER_DEFAULT;
86 static uint bcast_ring_order = WIL_BCAST_RING_SIZE_ORDER_DEFAULT;
88 static int ring_order_set(const char *val, const struct kernel_param *kp)
93 ret = kstrtouint(val, 0, &x);
97 if ((x < WIL_RING_SIZE_ORDER_MIN) || (x > WIL_RING_SIZE_ORDER_MAX))
100 *((uint *)kp->arg) = x;
105 static const struct kernel_param_ops ring_order_ops = {
106 .set = ring_order_set,
107 .get = param_get_uint,
110 module_param_cb(rx_ring_order, &ring_order_ops, &rx_ring_order, 0444);
111 MODULE_PARM_DESC(rx_ring_order, " Rx ring order; size = 1 << order");
112 module_param_cb(tx_ring_order, &ring_order_ops, &tx_ring_order, 0444);
113 MODULE_PARM_DESC(tx_ring_order, " Tx ring order; size = 1 << order");
114 module_param_cb(bcast_ring_order, &ring_order_ops, &bcast_ring_order, 0444);
115 MODULE_PARM_DESC(bcast_ring_order, " Bcast ring order; size = 1 << order");
121 WIL_BOOT_DEVELOPMENT,
125 WIL_SIG_STATUS_VANILLA = 0x0,
126 WIL_SIG_STATUS_DEVELOPMENT = 0x1,
127 WIL_SIG_STATUS_PRODUCTION = 0x2,
128 WIL_SIG_STATUS_CORRUPTED_PRODUCTION = 0x3,
131 #define RST_DELAY (20) /* msec, for loop in @wil_wait_device_ready */
132 #define RST_COUNT (1 + 1000/RST_DELAY) /* round up to be above 1 sec total */
134 #define PMU_READY_DELAY_MS (4) /* ms, for sleep in @wil_wait_device_ready */
136 #define OTP_HW_DELAY (200) /* usec, loop in @wil_wait_device_ready_talyn_mb */
137 /* round up to be above 2 ms total */
138 #define OTP_HW_COUNT (1 + 2000 / OTP_HW_DELAY)
141 * Due to a hardware issue,
142 * one has to read/write to/from NIC in 32-bit chunks;
143 * regular memcpy_fromio and siblings will
144 * not work on 64-bit platform - it uses 64-bit transactions
146 * Force 32-bit transactions to enable NIC on 64-bit platforms
148 * To avoid byte swap on big endian host, __raw_{read|write}l
149 * should be used - {read|write}l would swap bytes to provide
150 * little endian on PCI value in host endianness.
152 void wil_memcpy_fromio_32(void *dst, const volatile void __iomem *src,
156 const volatile u32 __iomem *s = src;
158 for (; count >= 4; count -= 4)
159 *d++ = __raw_readl(s++);
161 if (unlikely(count)) {
162 /* count can be 1..3 */
163 u32 tmp = __raw_readl(s);
165 memcpy(d, &tmp, count);
169 void wil_memcpy_toio_32(volatile void __iomem *dst, const void *src,
172 volatile u32 __iomem *d = dst;
175 for (; count >= 4; count -= 4)
176 __raw_writel(*s++, d++);
178 if (unlikely(count)) {
179 /* count can be 1..3 */
182 memcpy(&tmp, s, count);
183 __raw_writel(tmp, d);
187 static void wil_ring_fini_tx(struct wil6210_priv *wil, int id)
189 struct wil_ring *ring = &wil->ring_tx[id];
190 struct wil_ring_tx_data *txdata = &wil->ring_tx_data[id];
192 lockdep_assert_held(&wil->mutex);
197 wil_dbg_misc(wil, "vring_fini_tx: id=%d\n", id);
199 spin_lock_bh(&txdata->lock);
200 txdata->dot1x_open = false;
201 txdata->mid = U8_MAX;
202 txdata->enabled = 0; /* no Tx can be in progress or start anew */
203 spin_unlock_bh(&txdata->lock);
204 /* napi_synchronize waits for completion of the current NAPI but will
205 * not prevent the next NAPI run.
206 * Add a memory barrier to guarantee that txdata->enabled is zeroed
207 * before napi_synchronize so that the next scheduled NAPI will not
211 /* make sure NAPI won't touch this vring */
212 if (test_bit(wil_status_napi_en, wil->status))
213 napi_synchronize(&wil->napi_tx);
215 wil->txrx_ops.ring_fini_tx(wil, ring);
218 static bool wil_vif_is_connected(struct wil6210_priv *wil, u8 mid)
222 for (i = 0; i < WIL6210_MAX_CID; i++) {
223 if (wil->sta[i].mid == mid &&
224 wil->sta[i].status == wil_sta_connected)
231 static void wil_disconnect_cid_complete(struct wil6210_vif *vif, int cid,
233 __acquires(&sta->tid_rx_lock) __releases(&sta->tid_rx_lock)
236 struct wil6210_priv *wil = vif_to_wil(vif);
237 struct net_device *ndev = vif_to_ndev(vif);
238 struct wireless_dev *wdev = vif_to_wdev(vif);
239 struct wil_sta_info *sta = &wil->sta[cid];
240 int min_ring_id = wil_get_min_tx_ring_id(wil);
244 "disconnect_cid_complete: CID %d, MID %d, status %d\n",
245 cid, sta->mid, sta->status);
246 /* inform upper layers */
247 if (sta->status != wil_sta_unused) {
248 if (vif->mid != sta->mid) {
249 wil_err(wil, "STA MID mismatch with VIF MID(%d)\n",
253 switch (wdev->iftype) {
254 case NL80211_IFTYPE_AP:
255 case NL80211_IFTYPE_P2P_GO:
256 /* AP-like interface */
257 cfg80211_del_sta(ndev, sta->addr, GFP_KERNEL);
262 sta->status = wil_sta_unused;
265 /* reorder buffers */
266 for (i = 0; i < WIL_STA_TID_NUM; i++) {
267 struct wil_tid_ampdu_rx *r;
269 spin_lock_bh(&sta->tid_rx_lock);
272 sta->tid_rx[i] = NULL;
273 wil_tid_ampdu_rx_free(wil, r);
275 spin_unlock_bh(&sta->tid_rx_lock);
278 memset(sta->tid_crypto_rx, 0, sizeof(sta->tid_crypto_rx));
279 memset(&sta->group_crypto_rx, 0, sizeof(sta->group_crypto_rx));
281 for (i = min_ring_id; i < ARRAY_SIZE(wil->ring_tx); i++) {
282 if (wil->ring2cid_tid[i][0] == cid)
283 wil_ring_fini_tx(wil, i);
286 memset(&sta->stats, 0, sizeof(sta->stats));
287 sta->stats.tx_latency_min_us = U32_MAX;
290 static void _wil6210_disconnect_complete(struct wil6210_vif *vif,
291 const u8 *bssid, u16 reason_code)
293 struct wil6210_priv *wil = vif_to_wil(vif);
295 struct net_device *ndev;
296 struct wireless_dev *wdev;
298 ndev = vif_to_ndev(vif);
299 wdev = vif_to_wdev(vif);
302 wil_info(wil, "disconnect_complete: bssid=%pM, reason=%d\n",
306 * - disconnect single STA, still connected
307 * - disconnect single STA, already disconnected
310 * For "disconnect all", there are 3 options:
312 * - bssid is broadcast address (ff:ff:ff:ff:ff:ff)
313 * - bssid is our MAC address
315 if (bssid && !is_broadcast_ether_addr(bssid) &&
316 !ether_addr_equal_unaligned(ndev->dev_addr, bssid)) {
317 cid = wil_find_cid(wil, vif->mid, bssid);
319 "Disconnect complete %pM, CID=%d, reason=%d\n",
320 bssid, cid, reason_code);
321 if (cid >= 0) /* disconnect 1 peer */
322 wil_disconnect_cid_complete(vif, cid, reason_code);
324 wil_dbg_misc(wil, "Disconnect complete all\n");
325 for (cid = 0; cid < WIL6210_MAX_CID; cid++)
326 wil_disconnect_cid_complete(vif, cid, reason_code);
330 switch (wdev->iftype) {
331 case NL80211_IFTYPE_STATION:
332 case NL80211_IFTYPE_P2P_CLIENT:
334 wil_update_net_queues_bh(wil, vif, NULL, true);
335 netif_carrier_off(ndev);
336 if (!wil_has_other_active_ifaces(wil, ndev, false, true))
337 wil6210_bus_request(wil, WIL_DEFAULT_BUS_REQUEST_KBPS);
339 if (test_and_clear_bit(wil_vif_fwconnected, vif->status)) {
340 atomic_dec(&wil->connected_vifs);
341 cfg80211_disconnected(ndev, reason_code,
343 vif->locally_generated_disc,
345 vif->locally_generated_disc = false;
346 } else if (test_bit(wil_vif_fwconnecting, vif->status)) {
347 cfg80211_connect_result(ndev, bssid, NULL, 0, NULL, 0,
348 WLAN_STATUS_UNSPECIFIED_FAILURE,
352 clear_bit(wil_vif_fwconnecting, vif->status);
353 clear_bit(wil_vif_ft_roam, vif->status);
356 case NL80211_IFTYPE_AP:
357 case NL80211_IFTYPE_P2P_GO:
358 if (!wil_vif_is_connected(wil, vif->mid)) {
359 wil_update_net_queues_bh(wil, vif, NULL, true);
360 if (test_and_clear_bit(wil_vif_fwconnected,
362 atomic_dec(&wil->connected_vifs);
364 wil_update_net_queues_bh(wil, vif, NULL, false);
372 static int wil_disconnect_cid(struct wil6210_vif *vif, int cid,
375 struct wil6210_priv *wil = vif_to_wil(vif);
376 struct wireless_dev *wdev = vif_to_wdev(vif);
377 struct wil_sta_info *sta = &wil->sta[cid];
378 bool del_sta = false;
381 wil_dbg_misc(wil, "disconnect_cid: CID %d, MID %d, status %d\n",
382 cid, sta->mid, sta->status);
384 if (sta->status == wil_sta_unused)
387 if (vif->mid != sta->mid) {
388 wil_err(wil, "STA MID mismatch with VIF MID(%d)\n", vif->mid);
392 /* inform lower layers */
393 if (wdev->iftype == NL80211_IFTYPE_AP && disable_ap_sme)
396 /* disconnect by sending command disconnect/del_sta and wait
397 * synchronously for WMI_DISCONNECT_EVENTID event.
399 return wmi_disconnect_sta(vif, sta->addr, reason_code, del_sta);
402 static void _wil6210_disconnect(struct wil6210_vif *vif, const u8 *bssid,
405 struct wil6210_priv *wil;
406 struct net_device *ndev;
412 wil = vif_to_wil(vif);
413 ndev = vif_to_ndev(vif);
416 wil_info(wil, "disconnect bssid=%pM, reason=%d\n", bssid, reason_code);
419 * - disconnect single STA, still connected
420 * - disconnect single STA, already disconnected
423 * For "disconnect all", there are 3 options:
425 * - bssid is broadcast address (ff:ff:ff:ff:ff:ff)
426 * - bssid is our MAC address
428 if (bssid && !is_broadcast_ether_addr(bssid) &&
429 !ether_addr_equal_unaligned(ndev->dev_addr, bssid)) {
430 cid = wil_find_cid(wil, vif->mid, bssid);
431 wil_dbg_misc(wil, "Disconnect %pM, CID=%d, reason=%d\n",
432 bssid, cid, reason_code);
433 if (cid >= 0) /* disconnect 1 peer */
434 wil_disconnect_cid(vif, cid, reason_code);
436 wil_dbg_misc(wil, "Disconnect all\n");
437 for (cid = 0; cid < WIL6210_MAX_CID; cid++)
438 wil_disconnect_cid(vif, cid, reason_code);
441 /* call event handler manually after processing wmi_call,
442 * to avoid deadlock - disconnect event handler acquires
443 * wil->mutex while it is already held here
445 _wil6210_disconnect_complete(vif, bssid, reason_code);
448 void wil_disconnect_worker(struct work_struct *work)
450 struct wil6210_vif *vif = container_of(work,
451 struct wil6210_vif, disconnect_worker);
452 struct wil6210_priv *wil = vif_to_wil(vif);
453 struct net_device *ndev = vif_to_ndev(vif);
456 struct wmi_cmd_hdr wmi;
457 struct wmi_disconnect_event evt;
460 if (test_bit(wil_vif_fwconnected, vif->status))
461 /* connect succeeded after all */
464 if (!test_bit(wil_vif_fwconnecting, vif->status))
465 /* already disconnected */
468 memset(&reply, 0, sizeof(reply));
470 rc = wmi_call(wil, WMI_DISCONNECT_CMDID, vif->mid, NULL, 0,
471 WMI_DISCONNECT_EVENTID, &reply, sizeof(reply),
472 WIL6210_DISCONNECT_TO_MS);
474 wil_err(wil, "disconnect error %d\n", rc);
478 wil_update_net_queues_bh(wil, vif, NULL, true);
479 netif_carrier_off(ndev);
480 cfg80211_connect_result(ndev, NULL, NULL, 0, NULL, 0,
481 WLAN_STATUS_UNSPECIFIED_FAILURE, GFP_KERNEL);
482 clear_bit(wil_vif_fwconnecting, vif->status);
485 static int wil_wait_for_recovery(struct wil6210_priv *wil)
487 if (wait_event_interruptible(wil->wq, wil->recovery_state !=
488 fw_recovery_pending)) {
489 wil_err(wil, "Interrupt, canceling recovery\n");
492 if (wil->recovery_state != fw_recovery_running) {
493 wil_info(wil, "Recovery cancelled\n");
496 wil_info(wil, "Proceed with recovery\n");
500 void wil_set_recovery_state(struct wil6210_priv *wil, int state)
502 wil_dbg_misc(wil, "set_recovery_state: %d -> %d\n",
503 wil->recovery_state, state);
505 wil->recovery_state = state;
506 wake_up_interruptible(&wil->wq);
509 bool wil_is_recovery_blocked(struct wil6210_priv *wil)
511 return no_fw_recovery && (wil->recovery_state == fw_recovery_pending);
514 static void wil_fw_error_worker(struct work_struct *work)
516 struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
518 struct net_device *ndev = wil->main_ndev;
519 struct wireless_dev *wdev;
521 wil_dbg_misc(wil, "fw error worker\n");
523 if (!ndev || !(ndev->flags & IFF_UP)) {
524 wil_info(wil, "No recovery - interface is down\n");
527 wdev = ndev->ieee80211_ptr;
529 /* increment @recovery_count if less then WIL6210_FW_RECOVERY_TO
530 * passed since last recovery attempt
532 if (time_is_after_jiffies(wil->last_fw_recovery +
533 WIL6210_FW_RECOVERY_TO))
534 wil->recovery_count++;
536 wil->recovery_count = 1; /* fw was alive for a long time */
538 if (wil->recovery_count > WIL6210_FW_RECOVERY_RETRIES) {
539 wil_err(wil, "too many recovery attempts (%d), giving up\n",
540 wil->recovery_count);
544 wil->last_fw_recovery = jiffies;
546 wil_info(wil, "fw error recovery requested (try %d)...\n",
547 wil->recovery_count);
549 wil->recovery_state = fw_recovery_running;
550 if (wil_wait_for_recovery(wil) != 0)
554 mutex_lock(&wil->mutex);
555 /* Needs adaptation for multiple VIFs
556 * need to go over all VIFs and consider the appropriate
557 * recovery because each one can have different iftype.
559 switch (wdev->iftype) {
560 case NL80211_IFTYPE_STATION:
561 case NL80211_IFTYPE_P2P_CLIENT:
562 case NL80211_IFTYPE_MONITOR:
563 /* silent recovery, upper layers will see disconnect */
567 case NL80211_IFTYPE_AP:
568 case NL80211_IFTYPE_P2P_GO:
569 if (no_fw_recovery) /* upper layers do recovery */
571 /* silent recovery, upper layers will see disconnect */
574 mutex_unlock(&wil->mutex);
575 wil_cfg80211_ap_recovery(wil);
576 mutex_lock(&wil->mutex);
577 wil_info(wil, "... completed\n");
580 wil_err(wil, "No recovery - unknown interface type %d\n",
585 mutex_unlock(&wil->mutex);
589 static int wil_find_free_ring(struct wil6210_priv *wil)
592 int min_ring_id = wil_get_min_tx_ring_id(wil);
594 for (i = min_ring_id; i < WIL6210_MAX_TX_RINGS; i++) {
595 if (!wil->ring_tx[i].va)
601 int wil_ring_init_tx(struct wil6210_vif *vif, int cid)
603 struct wil6210_priv *wil = vif_to_wil(vif);
604 int rc = -EINVAL, ringid;
607 wil_err(wil, "No connection pending\n");
610 ringid = wil_find_free_ring(wil);
612 wil_err(wil, "No free vring found\n");
616 wil_dbg_wmi(wil, "Configure for connection CID %d MID %d ring %d\n",
617 cid, vif->mid, ringid);
619 rc = wil->txrx_ops.ring_init_tx(vif, ringid, 1 << tx_ring_order,
622 wil_err(wil, "init TX for CID %d MID %d vring %d failed\n",
623 cid, vif->mid, ringid);
629 int wil_bcast_init(struct wil6210_vif *vif)
631 struct wil6210_priv *wil = vif_to_wil(vif);
632 int ri = vif->bcast_ring, rc;
634 if (ri >= 0 && wil->ring_tx[ri].va)
637 ri = wil_find_free_ring(wil);
641 vif->bcast_ring = ri;
642 rc = wil->txrx_ops.ring_init_bcast(vif, ri, 1 << bcast_ring_order);
644 vif->bcast_ring = -1;
649 void wil_bcast_fini(struct wil6210_vif *vif)
651 struct wil6210_priv *wil = vif_to_wil(vif);
652 int ri = vif->bcast_ring;
657 vif->bcast_ring = -1;
658 wil_ring_fini_tx(wil, ri);
661 void wil_bcast_fini_all(struct wil6210_priv *wil)
664 struct wil6210_vif *vif;
666 for (i = 0; i < wil->max_vifs; i++) {
673 int wil_priv_init(struct wil6210_priv *wil)
677 wil_dbg_misc(wil, "priv_init\n");
679 memset(wil->sta, 0, sizeof(wil->sta));
680 for (i = 0; i < WIL6210_MAX_CID; i++) {
681 spin_lock_init(&wil->sta[i].tid_rx_lock);
682 wil->sta[i].mid = U8_MAX;
685 for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) {
686 spin_lock_init(&wil->ring_tx_data[i].lock);
687 wil->ring2cid_tid[i][0] = WIL6210_MAX_CID;
690 mutex_init(&wil->mutex);
691 mutex_init(&wil->vif_mutex);
692 mutex_init(&wil->wmi_mutex);
693 mutex_init(&wil->halp.lock);
695 init_completion(&wil->wmi_ready);
696 init_completion(&wil->wmi_call);
697 init_completion(&wil->halp.comp);
699 INIT_WORK(&wil->wmi_event_worker, wmi_event_worker);
700 INIT_WORK(&wil->fw_error_worker, wil_fw_error_worker);
702 INIT_LIST_HEAD(&wil->pending_wmi_ev);
703 spin_lock_init(&wil->wmi_ev_lock);
704 spin_lock_init(&wil->net_queue_lock);
705 init_waitqueue_head(&wil->wq);
707 wil->wmi_wq = create_singlethread_workqueue(WIL_NAME "_wmi");
711 wil->wq_service = create_singlethread_workqueue(WIL_NAME "_service");
712 if (!wil->wq_service)
715 wil->last_fw_recovery = jiffies;
716 wil->tx_interframe_timeout = WIL6210_ITR_TX_INTERFRAME_TIMEOUT_DEFAULT;
717 wil->rx_interframe_timeout = WIL6210_ITR_RX_INTERFRAME_TIMEOUT_DEFAULT;
718 wil->tx_max_burst_duration = WIL6210_ITR_TX_MAX_BURST_DURATION_DEFAULT;
719 wil->rx_max_burst_duration = WIL6210_ITR_RX_MAX_BURST_DURATION_DEFAULT;
721 if (rx_ring_overflow_thrsh == WIL6210_RX_HIGH_TRSH_INIT)
722 rx_ring_overflow_thrsh = WIL6210_RX_HIGH_TRSH_DEFAULT;
724 wil->ps_profile = WMI_PS_PROFILE_TYPE_DEFAULT;
726 wil->wakeup_trigger = WMI_WAKEUP_TRIGGER_UCAST |
727 WMI_WAKEUP_TRIGGER_BCAST;
728 memset(&wil->suspend_stats, 0, sizeof(wil->suspend_stats));
729 wil->ring_idle_trsh = 16;
731 wil->reply_mid = U8_MAX;
734 /* edma configuration can be updated via debugfs before allocation */
735 wil->num_rx_status_rings = WIL_DEFAULT_NUM_RX_STATUS_RINGS;
736 wil->tx_status_ring_order = WIL_TX_SRING_SIZE_ORDER_DEFAULT;
738 /* Rx status ring size should be bigger than the number of RX buffers
739 * in order to prevent backpressure on the status ring, which may
742 wil->rx_status_ring_order = WIL_RX_SRING_SIZE_ORDER_DEFAULT;
743 /* Number of RX buffer IDs should be bigger than the RX descriptor
744 * ring size as in HW reorder flow, the HW can consume additional
745 * buffers before releasing the previous ones.
747 wil->rx_buff_id_count = WIL_RX_BUFF_ARR_SIZE_DEFAULT;
754 destroy_workqueue(wil->wmi_wq);
759 void wil6210_bus_request(struct wil6210_priv *wil, u32 kbps)
761 if (wil->platform_ops.bus_request) {
762 wil->bus_request_kbps = kbps;
763 wil->platform_ops.bus_request(wil->platform_handle, kbps);
768 * wil6210_disconnect - disconnect one connection
769 * @vif: virtual interface context
770 * @bssid: peer to disconnect, NULL to disconnect all
771 * @reason_code: Reason code for the Disassociation frame
773 * Disconnect and release associated resources. Issue WMI
774 * command(s) to trigger MAC disconnect. When command was issued
775 * successfully, call the wil6210_disconnect_complete function
776 * to handle the event synchronously
778 void wil6210_disconnect(struct wil6210_vif *vif, const u8 *bssid,
781 struct wil6210_priv *wil = vif_to_wil(vif);
783 wil_dbg_misc(wil, "disconnecting\n");
785 del_timer_sync(&vif->connect_timer);
786 _wil6210_disconnect(vif, bssid, reason_code);
790 * wil6210_disconnect_complete - handle disconnect event
791 * @vif: virtual interface context
792 * @bssid: peer to disconnect, NULL to disconnect all
793 * @reason_code: Reason code for the Disassociation frame
795 * Release associated resources and indicate upper layers the
796 * connection is terminated.
798 void wil6210_disconnect_complete(struct wil6210_vif *vif, const u8 *bssid,
801 struct wil6210_priv *wil = vif_to_wil(vif);
803 wil_dbg_misc(wil, "got disconnect\n");
805 del_timer_sync(&vif->connect_timer);
806 _wil6210_disconnect_complete(vif, bssid, reason_code);
809 void wil_priv_deinit(struct wil6210_priv *wil)
811 wil_dbg_misc(wil, "priv_deinit\n");
813 wil_set_recovery_state(wil, fw_recovery_idle);
814 cancel_work_sync(&wil->fw_error_worker);
815 wmi_event_flush(wil);
816 destroy_workqueue(wil->wq_service);
817 destroy_workqueue(wil->wmi_wq);
820 static void wil_shutdown_bl(struct wil6210_priv *wil)
824 wil_s(wil, RGF_USER_BL +
825 offsetof(struct bl_dedicated_registers_v1,
826 bl_shutdown_handshake), BL_SHUTDOWN_HS_GRTD);
828 usleep_range(100, 150);
830 val = wil_r(wil, RGF_USER_BL +
831 offsetof(struct bl_dedicated_registers_v1,
832 bl_shutdown_handshake));
833 if (val & BL_SHUTDOWN_HS_RTD) {
834 wil_dbg_misc(wil, "BL is ready for halt\n");
838 wil_err(wil, "BL did not report ready for halt\n");
841 /* this format is used by ARC embedded CPU for instruction memory */
842 static inline u32 ARC_me_imm32(u32 d)
844 return ((d & 0xffff0000) >> 16) | ((d & 0x0000ffff) << 16);
847 /* defines access to interrupt vectors for wil_freeze_bl */
848 #define ARC_IRQ_VECTOR_OFFSET(N) ((N) * 8)
849 /* ARC long jump instruction */
850 #define ARC_JAL_INST (0x20200f80)
852 static void wil_freeze_bl(struct wil6210_priv *wil)
855 u32 ivt3 = ARC_IRQ_VECTOR_OFFSET(3);
857 jal = wil_r(wil, wil->iccm_base + ivt3);
858 if (jal != ARC_me_imm32(ARC_JAL_INST)) {
859 wil_dbg_misc(wil, "invalid IVT entry found, skipping\n");
863 /* prevent the target from entering deep sleep
864 * and disabling memory access
866 saved = wil_r(wil, RGF_USER_USAGE_8);
867 wil_w(wil, RGF_USER_USAGE_8, saved | BIT_USER_PREVENT_DEEP_SLEEP);
868 usleep_range(20, 25); /* let the BL process the bit */
870 /* redirect to endless loop in the INT_L1 context and let it trap */
871 wil_w(wil, wil->iccm_base + ivt3 + 4, ARC_me_imm32(ivt3));
872 usleep_range(20, 25); /* let the BL get into the trap */
874 /* verify the BL is frozen */
875 upc = wil_r(wil, RGF_USER_CPU_PC);
876 if (upc < ivt3 || (upc > (ivt3 + 8)))
877 wil_dbg_misc(wil, "BL freeze failed, PC=0x%08X\n", upc);
879 wil_w(wil, RGF_USER_USAGE_8, saved);
882 static void wil_bl_prepare_halt(struct wil6210_priv *wil)
886 /* before halting device CPU driver must make sure BL is not accessing
887 * host memory. This is done differently depending on BL version:
888 * 1. For very old BL versions the procedure is skipped
890 * 2. For old BL version we use a special trick to freeze the BL
891 * 3. For new BL versions we shutdown the BL using handshake procedure.
893 tmp = wil_r(wil, RGF_USER_BL +
894 offsetof(struct bl_dedicated_registers_v0,
895 boot_loader_struct_version));
897 wil_dbg_misc(wil, "old BL, skipping halt preparation\n");
901 tmp = wil_r(wil, RGF_USER_BL +
902 offsetof(struct bl_dedicated_registers_v1,
903 bl_shutdown_handshake));
904 ver = BL_SHUTDOWN_HS_PROT_VER(tmp);
907 wil_shutdown_bl(wil);
912 static inline void wil_halt_cpu(struct wil6210_priv *wil)
914 if (wil->hw_version >= HW_VER_TALYN_MB) {
915 wil_w(wil, RGF_USER_USER_CPU_0_TALYN_MB,
916 BIT_USER_USER_CPU_MAN_RST);
917 wil_w(wil, RGF_USER_MAC_CPU_0_TALYN_MB,
918 BIT_USER_MAC_CPU_MAN_RST);
920 wil_w(wil, RGF_USER_USER_CPU_0, BIT_USER_USER_CPU_MAN_RST);
921 wil_w(wil, RGF_USER_MAC_CPU_0, BIT_USER_MAC_CPU_MAN_RST);
925 static inline void wil_release_cpu(struct wil6210_priv *wil)
928 if (wil->hw_version >= HW_VER_TALYN_MB)
929 wil_w(wil, RGF_USER_USER_CPU_0_TALYN_MB, 1);
931 wil_w(wil, RGF_USER_USER_CPU_0, 1);
934 static void wil_set_oob_mode(struct wil6210_priv *wil, u8 mode)
936 wil_info(wil, "oob_mode to %d\n", mode);
939 wil_c(wil, RGF_USER_USAGE_6, BIT_USER_OOB_MODE |
940 BIT_USER_OOB_R2_MODE);
943 wil_c(wil, RGF_USER_USAGE_6, BIT_USER_OOB_R2_MODE);
944 wil_s(wil, RGF_USER_USAGE_6, BIT_USER_OOB_MODE);
947 wil_c(wil, RGF_USER_USAGE_6, BIT_USER_OOB_MODE);
948 wil_s(wil, RGF_USER_USAGE_6, BIT_USER_OOB_R2_MODE);
951 wil_err(wil, "invalid oob_mode: %d\n", mode);
955 static int wil_wait_device_ready(struct wil6210_priv *wil, int no_flash)
960 /* wait until device ready. */
962 msleep(PMU_READY_DELAY_MS);
964 wil_dbg_misc(wil, "Reset completed\n");
968 x = wil_r(wil, RGF_USER_BL +
969 offsetof(struct bl_dedicated_registers_v0,
972 wil_dbg_misc(wil, "BL.ready 0x%08x => 0x%08x\n",
976 if (delay++ > RST_COUNT) {
977 wil_err(wil, "Reset not completed, bl.ready 0x%08x\n",
981 } while (x != BL_READY);
983 wil_dbg_misc(wil, "Reset completed in %d ms\n",
990 static int wil_wait_device_ready_talyn_mb(struct wil6210_priv *wil)
994 bool otp_signature_err;
995 bool hw_section_done;
999 /* Wait for OTP signature test to complete */
1000 usleep_range(2000, 2200);
1002 wil->boot_config = WIL_BOOT_ERR;
1004 /* Poll until OTP signature status is valid.
1005 * In vanilla and development modes, when signature test is complete
1006 * HW sets BIT_OTP_SIGNATURE_ERR_TALYN_MB.
1007 * In production mode BIT_OTP_SIGNATURE_ERR_TALYN_MB remains 0, poll
1008 * for signature status change to 2 or 3.
1011 otp_hw = wil_r(wil, RGF_USER_OTP_HW_RD_MACHINE_1);
1012 signature_status = WIL_GET_BITS(otp_hw, 8, 9);
1013 otp_signature_err = otp_hw & BIT_OTP_SIGNATURE_ERR_TALYN_MB;
1015 if (otp_signature_err &&
1016 signature_status == WIL_SIG_STATUS_VANILLA) {
1017 wil->boot_config = WIL_BOOT_VANILLA;
1020 if (otp_signature_err &&
1021 signature_status == WIL_SIG_STATUS_DEVELOPMENT) {
1022 wil->boot_config = WIL_BOOT_DEVELOPMENT;
1025 if (!otp_signature_err &&
1026 signature_status == WIL_SIG_STATUS_PRODUCTION) {
1027 wil->boot_config = WIL_BOOT_PRODUCTION;
1030 if (!otp_signature_err &&
1032 WIL_SIG_STATUS_CORRUPTED_PRODUCTION) {
1033 /* Unrecognized OTP signature found. Possibly a
1034 * corrupted production signature, access control
1035 * is applied as in production mode, therefore
1038 wil->boot_config = WIL_BOOT_PRODUCTION;
1041 if (delay++ > OTP_HW_COUNT)
1044 usleep_range(OTP_HW_DELAY, OTP_HW_DELAY + 10);
1045 } while (!otp_signature_err && signature_status == 0);
1047 if (wil->boot_config == WIL_BOOT_ERR) {
1049 "invalid boot config, signature_status %d otp_signature_err %d\n",
1050 signature_status, otp_signature_err);
1055 "signature test done in %d usec, otp_hw 0x%x, boot_config %d\n",
1056 delay * OTP_HW_DELAY, otp_hw, wil->boot_config);
1058 if (wil->boot_config == WIL_BOOT_VANILLA)
1059 /* Assuming not SPI boot (currently not supported) */
1062 hw_section_done = otp_hw & BIT_OTP_HW_SECTION_DONE_TALYN_MB;
1065 while (!hw_section_done) {
1068 otp_hw = wil_r(wil, RGF_USER_OTP_HW_RD_MACHINE_1);
1069 hw_section_done = otp_hw & BIT_OTP_HW_SECTION_DONE_TALYN_MB;
1071 if (delay++ > RST_COUNT) {
1072 wil_err(wil, "TO waiting for hw_section_done\n");
1077 wil_dbg_misc(wil, "HW section done in %d ms\n", delay * RST_DELAY);
1079 otp_qc_secured = wil_r(wil, RGF_OTP_QC_SECURED);
1080 wil->secured_boot = otp_qc_secured & BIT_BOOT_FROM_ROM ? 1 : 0;
1081 wil_dbg_misc(wil, "secured boot is %sabled\n",
1082 wil->secured_boot ? "en" : "dis");
1085 wil_dbg_misc(wil, "Reset completed\n");
1090 static int wil_target_reset(struct wil6210_priv *wil, int no_flash)
1095 wil_dbg_misc(wil, "Resetting \"%s\"...\n", wil->hw_name);
1097 if (wil->hw_version < HW_VER_TALYN) {
1098 /* Clear MAC link up */
1099 wil_s(wil, RGF_HP_CTRL, BIT(15));
1100 wil_s(wil, RGF_USER_CLKS_CTL_SW_RST_MASK_0,
1101 BIT_HPAL_PERST_FROM_PAD);
1102 wil_s(wil, RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT_CAR_PERST_RST);
1108 /* clear all boot loader "ready" bits */
1109 wil_w(wil, RGF_USER_BL +
1110 offsetof(struct bl_dedicated_registers_v0,
1111 boot_loader_ready), 0);
1112 /* this should be safe to write even with old BLs */
1113 wil_w(wil, RGF_USER_BL +
1114 offsetof(struct bl_dedicated_registers_v1,
1115 bl_shutdown_handshake), 0);
1117 /* Clear Fw Download notification */
1118 wil_c(wil, RGF_USER_USAGE_6, BIT(0));
1120 wil_s(wil, RGF_CAF_OSC_CONTROL, BIT_CAF_OSC_XTAL_EN);
1121 /* XTAL stabilization should take about 3ms */
1122 usleep_range(5000, 7000);
1123 x = wil_r(wil, RGF_CAF_PLL_LOCK_STATUS);
1124 if (!(x & BIT_CAF_OSC_DIG_XTAL_STABLE)) {
1125 wil_err(wil, "Xtal stabilization timeout\n"
1126 "RGF_CAF_PLL_LOCK_STATUS = 0x%08x\n", x);
1129 /* switch 10k to XTAL*/
1130 wil_c(wil, RGF_USER_SPARROW_M_4, BIT_SPARROW_M_4_SEL_SLEEP_OR_REF);
1132 wil_c(wil, RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_CAR_AHB_SW_SEL);
1134 wil_w(wil, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x3ff81f);
1135 wil_w(wil, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0xf);
1137 if (wil->hw_version >= HW_VER_TALYN_MB) {
1138 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x7e000000);
1139 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0x0000003f);
1140 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0xc00000f0);
1141 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0xffe7fe00);
1143 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0xfe000000);
1144 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0x0000003f);
1145 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x000000f0);
1146 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0xffe7fe00);
1149 wil_w(wil, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x0);
1150 wil_w(wil, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0x0);
1152 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0);
1153 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0);
1154 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0);
1155 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
1157 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000003);
1158 /* reset A2 PCIE AHB */
1159 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00008000);
1161 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
1163 if (wil->hw_version == HW_VER_TALYN_MB)
1164 rc = wil_wait_device_ready_talyn_mb(wil);
1166 rc = wil_wait_device_ready(wil, no_flash);
1170 wil_c(wil, RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_RST_PWGD);
1172 /* enable fix for HW bug related to the SA/DA swap in AP Rx */
1173 wil_s(wil, RGF_DMA_OFUL_NID_0, BIT_DMA_OFUL_NID_0_RX_EXT_TR_EN |
1174 BIT_DMA_OFUL_NID_0_RX_EXT_A3_SRC);
1176 if (wil->hw_version < HW_VER_TALYN_MB && no_flash) {
1177 /* Reset OTP HW vectors to fit 40MHz */
1178 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME1, 0x60001);
1179 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME2, 0x20027);
1180 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME3, 0x1);
1181 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME4, 0x20027);
1182 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME5, 0x30003);
1183 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME6, 0x20002);
1184 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME7, 0x60001);
1185 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME8, 0x60001);
1186 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME9, 0x60001);
1187 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME10, 0x60001);
1188 wil_w(wil, RGF_USER_XPM_RD_DOUT_SAMPLE_TIME, 0x57);
1194 static void wil_collect_fw_info(struct wil6210_priv *wil)
1196 struct wiphy *wiphy = wil_to_wiphy(wil);
1200 wil_refresh_fw_capabilities(wil);
1202 rc = wmi_get_mgmt_retry(wil, &retry_short);
1204 wiphy->retry_short = retry_short;
1205 wil_dbg_misc(wil, "FW retry_short: %d\n", retry_short);
1209 void wil_refresh_fw_capabilities(struct wil6210_priv *wil)
1211 struct wiphy *wiphy = wil_to_wiphy(wil);
1214 wil->keep_radio_on_during_sleep =
1215 test_bit(WIL_PLATFORM_CAPA_RADIO_ON_IN_SUSPEND,
1216 wil->platform_capa) &&
1217 test_bit(WMI_FW_CAPABILITY_D3_SUSPEND, wil->fw_capabilities);
1219 wil_info(wil, "keep_radio_on_during_sleep (%d)\n",
1220 wil->keep_radio_on_during_sleep);
1222 if (test_bit(WMI_FW_CAPABILITY_RSSI_REPORTING, wil->fw_capabilities))
1223 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1225 wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
1227 if (test_bit(WMI_FW_CAPABILITY_PNO, wil->fw_capabilities)) {
1228 wiphy->max_sched_scan_reqs = 1;
1229 wiphy->max_sched_scan_ssids = WMI_MAX_PNO_SSID_NUM;
1230 wiphy->max_match_sets = WMI_MAX_PNO_SSID_NUM;
1231 wiphy->max_sched_scan_ie_len = WMI_MAX_IE_LEN;
1232 wiphy->max_sched_scan_plans = WMI_MAX_PLANS_NUM;
1235 if (test_bit(WMI_FW_CAPABILITY_TX_REQ_EXT, wil->fw_capabilities))
1236 wiphy->flags |= WIPHY_FLAG_OFFCHAN_TX;
1238 if (wil->platform_ops.set_features) {
1239 features = (test_bit(WMI_FW_CAPABILITY_REF_CLOCK_CONTROL,
1240 wil->fw_capabilities) &&
1241 test_bit(WIL_PLATFORM_CAPA_EXT_CLK,
1242 wil->platform_capa)) ?
1243 BIT(WIL_PLATFORM_FEATURE_FW_EXT_CLK_CONTROL) : 0;
1245 if (wil->n_msi == 3)
1246 features |= BIT(WIL_PLATFORM_FEATURE_TRIPLE_MSI);
1248 wil->platform_ops.set_features(wil->platform_handle, features);
1251 if (test_bit(WMI_FW_CAPABILITY_BACK_WIN_SIZE_64,
1252 wil->fw_capabilities)) {
1253 wil->max_agg_wsize = WIL_MAX_AGG_WSIZE_64;
1254 wil->max_ampdu_size = WIL_MAX_AMPDU_SIZE_128;
1256 wil->max_agg_wsize = WIL_MAX_AGG_WSIZE;
1257 wil->max_ampdu_size = WIL_MAX_AMPDU_SIZE;
1260 update_supported_bands(wil);
1263 void wil_mbox_ring_le2cpus(struct wil6210_mbox_ring *r)
1265 le32_to_cpus(&r->base);
1266 le16_to_cpus(&r->entry_size);
1267 le16_to_cpus(&r->size);
1268 le32_to_cpus(&r->tail);
1269 le32_to_cpus(&r->head);
1272 /* construct actual board file name to use */
1273 void wil_get_board_file(struct wil6210_priv *wil, char *buf, size_t len)
1275 const char *board_file;
1276 const char *wil_talyn_fw_name = ftm_mode ? WIL_FW_NAME_FTM_TALYN :
1279 if (wil->board_file) {
1280 board_file = wil->board_file;
1282 /* If specific FW file is used for Talyn,
1283 * use specific board file
1285 if (strcmp(wil->wil_fw_name, wil_talyn_fw_name) == 0)
1286 board_file = WIL_BRD_NAME_TALYN;
1288 board_file = WIL_BOARD_FILE_NAME;
1291 strlcpy(buf, board_file, len);
1294 static int wil_get_bl_info(struct wil6210_priv *wil)
1296 struct net_device *ndev = wil->main_ndev;
1297 struct wiphy *wiphy = wil_to_wiphy(wil);
1299 struct bl_dedicated_registers_v0 bl0;
1300 struct bl_dedicated_registers_v1 bl1;
1306 wil_memcpy_fromio_32(&bl, wil->csr + HOSTADDR(RGF_USER_BL),
1308 bl_ver = le32_to_cpu(bl.bl0.boot_loader_struct_version);
1309 mac = bl.bl0.mac_address;
1312 le32_to_cpus(&bl.bl0.rf_type);
1313 le32_to_cpus(&bl.bl0.baseband_type);
1314 rf_status = 0; /* actually, unknown */
1316 "Boot Loader struct v%d: MAC = %pM RF = 0x%08x bband = 0x%08x\n",
1318 bl.bl0.rf_type, bl.bl0.baseband_type);
1319 wil_info(wil, "Boot Loader build unknown for struct v0\n");
1321 le16_to_cpus(&bl.bl1.rf_type);
1322 rf_status = le16_to_cpu(bl.bl1.rf_status);
1323 le32_to_cpus(&bl.bl1.baseband_type);
1324 le16_to_cpus(&bl.bl1.bl_version_subminor);
1325 le16_to_cpus(&bl.bl1.bl_version_build);
1327 "Boot Loader struct v%d: MAC = %pM RF = 0x%04x (status 0x%04x) bband = 0x%08x\n",
1329 bl.bl1.rf_type, rf_status,
1330 bl.bl1.baseband_type);
1331 wil_info(wil, "Boot Loader build %d.%d.%d.%d\n",
1332 bl.bl1.bl_version_major, bl.bl1.bl_version_minor,
1333 bl.bl1.bl_version_subminor, bl.bl1.bl_version_build);
1336 if (!is_valid_ether_addr(mac)) {
1337 wil_err(wil, "BL: Invalid MAC %pM\n", mac);
1341 ether_addr_copy(ndev->perm_addr, mac);
1342 ether_addr_copy(wiphy->perm_addr, mac);
1343 if (!is_valid_ether_addr(ndev->dev_addr))
1344 ether_addr_copy(ndev->dev_addr, mac);
1346 if (rf_status) {/* bad RF cable? */
1347 wil_err(wil, "RF communication error 0x%04x",
1355 static void wil_bl_crash_info(struct wil6210_priv *wil, bool is_err)
1357 u32 bl_assert_code, bl_assert_blink, bl_magic_number;
1358 u32 bl_ver = wil_r(wil, RGF_USER_BL +
1359 offsetof(struct bl_dedicated_registers_v0,
1360 boot_loader_struct_version));
1365 bl_assert_code = wil_r(wil, RGF_USER_BL +
1366 offsetof(struct bl_dedicated_registers_v1,
1368 bl_assert_blink = wil_r(wil, RGF_USER_BL +
1369 offsetof(struct bl_dedicated_registers_v1,
1371 bl_magic_number = wil_r(wil, RGF_USER_BL +
1372 offsetof(struct bl_dedicated_registers_v1,
1377 "BL assert code 0x%08x blink 0x%08x magic 0x%08x\n",
1378 bl_assert_code, bl_assert_blink, bl_magic_number);
1381 "BL assert code 0x%08x blink 0x%08x magic 0x%08x\n",
1382 bl_assert_code, bl_assert_blink, bl_magic_number);
1386 static int wil_get_otp_info(struct wil6210_priv *wil)
1388 struct net_device *ndev = wil->main_ndev;
1389 struct wiphy *wiphy = wil_to_wiphy(wil);
1393 if (wil->hw_version >= HW_VER_TALYN_MB)
1394 mac_addr = RGF_OTP_MAC_TALYN_MB;
1396 mac_addr = RGF_OTP_MAC;
1398 wil_memcpy_fromio_32(mac, wil->csr + HOSTADDR(mac_addr),
1400 if (!is_valid_ether_addr(mac)) {
1401 wil_err(wil, "Invalid MAC %pM\n", mac);
1405 ether_addr_copy(ndev->perm_addr, mac);
1406 ether_addr_copy(wiphy->perm_addr, mac);
1407 if (!is_valid_ether_addr(ndev->dev_addr))
1408 ether_addr_copy(ndev->dev_addr, mac);
1413 static int wil_wait_for_fw_ready(struct wil6210_priv *wil)
1415 ulong to = msecs_to_jiffies(2000);
1416 ulong left = wait_for_completion_timeout(&wil->wmi_ready, to);
1419 wil_err(wil, "Firmware not ready\n");
1422 wil_info(wil, "FW ready after %d ms. HW version 0x%08x\n",
1423 jiffies_to_msecs(to-left), wil->hw_version);
1428 void wil_abort_scan(struct wil6210_vif *vif, bool sync)
1430 struct wil6210_priv *wil = vif_to_wil(vif);
1432 struct cfg80211_scan_info info = {
1436 lockdep_assert_held(&wil->vif_mutex);
1438 if (!vif->scan_request)
1441 wil_dbg_misc(wil, "Abort scan_request 0x%p\n", vif->scan_request);
1442 del_timer_sync(&vif->scan_timer);
1443 mutex_unlock(&wil->vif_mutex);
1444 rc = wmi_abort_scan(vif);
1446 wait_event_interruptible_timeout(wil->wq, !vif->scan_request,
1448 WAIT_FOR_SCAN_ABORT_MS));
1450 mutex_lock(&wil->vif_mutex);
1451 if (vif->scan_request) {
1452 cfg80211_scan_done(vif->scan_request, &info);
1453 vif->scan_request = NULL;
1457 void wil_abort_scan_all_vifs(struct wil6210_priv *wil, bool sync)
1461 lockdep_assert_held(&wil->vif_mutex);
1463 for (i = 0; i < wil->max_vifs; i++) {
1464 struct wil6210_vif *vif = wil->vifs[i];
1467 wil_abort_scan(vif, sync);
1471 int wil_ps_update(struct wil6210_priv *wil, enum wmi_ps_profile_type ps_profile)
1475 if (!test_bit(WMI_FW_CAPABILITY_PS_CONFIG, wil->fw_capabilities)) {
1476 wil_err(wil, "set_power_mgmt not supported\n");
1480 rc = wmi_ps_dev_profile_cfg(wil, ps_profile);
1482 wil_err(wil, "wmi_ps_dev_profile_cfg failed (%d)\n", rc);
1484 wil->ps_profile = ps_profile;
1489 static void wil_pre_fw_config(struct wil6210_priv *wil)
1491 /* Mark FW as loaded from host */
1492 wil_s(wil, RGF_USER_USAGE_6, 1);
1494 /* clear any interrupts which on-card-firmware
1497 wil6210_clear_irq(wil);
1498 /* CAF_ICR - clear and mask */
1499 /* it is W1C, clear by writing back same value */
1500 if (wil->hw_version < HW_VER_TALYN_MB) {
1501 wil_s(wil, RGF_CAF_ICR + offsetof(struct RGF_ICR, ICR), 0);
1502 wil_w(wil, RGF_CAF_ICR + offsetof(struct RGF_ICR, IMV), ~0);
1505 RGF_CAF_ICR_TALYN_MB + offsetof(struct RGF_ICR, ICR), 0);
1506 wil_w(wil, RGF_CAF_ICR_TALYN_MB +
1507 offsetof(struct RGF_ICR, IMV), ~0);
1509 /* clear PAL_UNIT_ICR (potential D0->D3 leftover)
1510 * In Talyn-MB host cannot access this register due to
1511 * access control, hence PAL_UNIT_ICR is cleared by the FW
1513 if (wil->hw_version < HW_VER_TALYN_MB)
1514 wil_s(wil, RGF_PAL_UNIT_ICR + offsetof(struct RGF_ICR, ICR),
1517 if (wil->fw_calib_result > 0) {
1518 __le32 val = cpu_to_le32(wil->fw_calib_result |
1519 (CALIB_RESULT_SIGNATURE << 8));
1520 wil_w(wil, RGF_USER_FW_CALIB_RESULT, (u32 __force)val);
1524 static int wil_restore_vifs(struct wil6210_priv *wil)
1526 struct wil6210_vif *vif;
1527 struct net_device *ndev;
1528 struct wireless_dev *wdev;
1531 for (i = 0; i < wil->max_vifs; i++) {
1535 vif->ap_isolate = 0;
1537 ndev = vif_to_ndev(vif);
1538 wdev = vif_to_wdev(vif);
1539 rc = wmi_port_allocate(wil, vif->mid, ndev->dev_addr,
1542 wil_err(wil, "fail to restore VIF %d type %d, rc %d\n",
1543 i, wdev->iftype, rc);
1553 * We reset all the structures, and we reset the UMAC.
1554 * After calling this routine, you're expected to reload
1557 int wil_reset(struct wil6210_priv *wil, bool load_fw)
1560 unsigned long status_flags = BIT(wil_status_resetting);
1562 struct wil6210_vif *vif;
1564 wil_dbg_misc(wil, "reset\n");
1566 WARN_ON(!mutex_is_locked(&wil->mutex));
1567 WARN_ON(test_bit(wil_status_napi_en, wil->status));
1570 static const u8 mac[ETH_ALEN] = {
1571 0x00, 0xde, 0xad, 0x12, 0x34, 0x56,
1573 struct net_device *ndev = wil->main_ndev;
1575 ether_addr_copy(ndev->perm_addr, mac);
1576 ether_addr_copy(ndev->dev_addr, ndev->perm_addr);
1580 if (wil->hw_version == HW_VER_UNKNOWN)
1583 if (test_bit(WIL_PLATFORM_CAPA_T_PWR_ON_0, wil->platform_capa)) {
1584 wil_dbg_misc(wil, "Notify FW to set T_POWER_ON=0\n");
1585 wil_s(wil, RGF_USER_USAGE_8, BIT_USER_SUPPORT_T_POWER_ON_0);
1588 if (test_bit(WIL_PLATFORM_CAPA_EXT_CLK, wil->platform_capa)) {
1589 wil_dbg_misc(wil, "Notify FW on ext clock configuration\n");
1590 wil_s(wil, RGF_USER_USAGE_8, BIT_USER_EXT_CLK);
1593 if (wil->platform_ops.notify) {
1594 rc = wil->platform_ops.notify(wil->platform_handle,
1595 WIL_PLATFORM_EVT_PRE_RESET);
1597 wil_err(wil, "PRE_RESET platform notify failed, rc %d\n",
1601 set_bit(wil_status_resetting, wil->status);
1602 if (test_bit(wil_status_collecting_dumps, wil->status)) {
1603 /* Device collects crash dump, cancel the reset.
1604 * following crash dump collection, reset would take place.
1606 wil_dbg_misc(wil, "reject reset while collecting crash dump\n");
1611 mutex_lock(&wil->vif_mutex);
1612 wil_abort_scan_all_vifs(wil, false);
1613 mutex_unlock(&wil->vif_mutex);
1615 for (i = 0; i < wil->max_vifs; i++) {
1618 cancel_work_sync(&vif->disconnect_worker);
1619 wil6210_disconnect(vif, NULL,
1620 WLAN_REASON_DEAUTH_LEAVING);
1623 wil_bcast_fini_all(wil);
1625 /* Disable device led before reset*/
1626 wmi_led_cfg(wil, false);
1628 /* prevent NAPI from being scheduled and prevent wmi commands */
1629 mutex_lock(&wil->wmi_mutex);
1630 if (test_bit(wil_status_suspending, wil->status))
1631 status_flags |= BIT(wil_status_suspending);
1632 bitmap_and(wil->status, wil->status, &status_flags,
1634 wil_dbg_misc(wil, "wil->status (0x%lx)\n", *wil->status);
1635 mutex_unlock(&wil->wmi_mutex);
1639 wmi_event_flush(wil);
1641 flush_workqueue(wil->wq_service);
1642 flush_workqueue(wil->wmi_wq);
1644 no_flash = test_bit(hw_capa_no_flash, wil->hw_capa);
1646 wil_bl_crash_info(wil, false);
1647 wil_disable_irq(wil);
1648 rc = wil_target_reset(wil, no_flash);
1649 wil6210_clear_irq(wil);
1650 wil_enable_irq(wil);
1651 wil->txrx_ops.rx_fini(wil);
1652 wil->txrx_ops.tx_fini(wil);
1655 wil_bl_crash_info(wil, true);
1660 rc = wil_get_otp_info(wil);
1662 rc = wil_get_bl_info(wil);
1663 if (rc == -EAGAIN && !load_fw)
1664 /* ignore RF error if not going up */
1670 wil_set_oob_mode(wil, oob_mode);
1672 char board_file[WIL_BOARD_FILE_MAX_NAMELEN];
1674 if (wil->secured_boot) {
1675 wil_err(wil, "secured boot is not supported\n");
1679 board_file[0] = '\0';
1680 wil_get_board_file(wil, board_file, sizeof(board_file));
1681 wil_info(wil, "Use firmware <%s> + board <%s>\n",
1682 wil->wil_fw_name, board_file);
1685 wil_bl_prepare_halt(wil);
1688 memset(wil->fw_version, 0, sizeof(wil->fw_version));
1689 /* Loading f/w from the file */
1690 rc = wil_request_firmware(wil, wil->wil_fw_name, true);
1693 if (wil->brd_file_addr)
1694 rc = wil_request_board(wil, board_file);
1696 rc = wil_request_firmware(wil, board_file, true);
1700 wil_pre_fw_config(wil);
1701 wil_release_cpu(wil);
1704 /* init after reset */
1705 reinit_completion(&wil->wmi_ready);
1706 reinit_completion(&wil->wmi_call);
1707 reinit_completion(&wil->halp.comp);
1709 clear_bit(wil_status_resetting, wil->status);
1712 wil_unmask_irq(wil);
1714 /* we just started MAC, wait for FW ready */
1715 rc = wil_wait_for_fw_ready(wil);
1719 /* check FW is responsive */
1722 wil_err(wil, "wmi_echo failed, rc %d\n", rc);
1726 wil->txrx_ops.configure_interrupt_moderation(wil);
1728 /* Enable OFU rdy valid bug fix, to prevent hang in oful34_rx
1729 * while there is back-pressure from Host during RX
1731 if (wil->hw_version >= HW_VER_TALYN_MB)
1732 wil_s(wil, RGF_DMA_MISC_CTL,
1733 BIT_OFUL34_RDY_VALID_BUG_FIX_EN);
1735 rc = wil_restore_vifs(wil);
1737 wil_err(wil, "failed to restore vifs, rc %d\n", rc);
1741 wil_collect_fw_info(wil);
1743 if (wil->ps_profile != WMI_PS_PROFILE_TYPE_DEFAULT)
1744 wil_ps_update(wil, wil->ps_profile);
1746 if (wil->platform_ops.notify) {
1747 rc = wil->platform_ops.notify(wil->platform_handle,
1748 WIL_PLATFORM_EVT_FW_RDY);
1750 wil_err(wil, "FW_RDY notify failed, rc %d\n",
1760 clear_bit(wil_status_resetting, wil->status);
1764 void wil_fw_error_recovery(struct wil6210_priv *wil)
1766 wil_dbg_misc(wil, "starting fw error recovery\n");
1768 if (test_bit(wil_status_resetting, wil->status)) {
1769 wil_info(wil, "Reset already in progress\n");
1773 wil->recovery_state = fw_recovery_pending;
1774 schedule_work(&wil->fw_error_worker);
1777 int __wil_up(struct wil6210_priv *wil)
1779 struct net_device *ndev = wil->main_ndev;
1780 struct wireless_dev *wdev = ndev->ieee80211_ptr;
1783 WARN_ON(!mutex_is_locked(&wil->mutex));
1785 rc = wil_reset(wil, true);
1789 /* Rx RING. After MAC and beacon */
1790 if (rx_ring_order == 0)
1791 rx_ring_order = wil->hw_version < HW_VER_TALYN_MB ?
1792 WIL_RX_RING_SIZE_ORDER_DEFAULT :
1793 WIL_RX_RING_SIZE_ORDER_TALYN_DEFAULT;
1795 rc = wil->txrx_ops.rx_init(wil, rx_ring_order);
1799 rc = wil->txrx_ops.tx_init(wil);
1803 switch (wdev->iftype) {
1804 case NL80211_IFTYPE_STATION:
1805 wil_dbg_misc(wil, "type: STATION\n");
1806 ndev->type = ARPHRD_ETHER;
1808 case NL80211_IFTYPE_AP:
1809 wil_dbg_misc(wil, "type: AP\n");
1810 ndev->type = ARPHRD_ETHER;
1812 case NL80211_IFTYPE_P2P_CLIENT:
1813 wil_dbg_misc(wil, "type: P2P_CLIENT\n");
1814 ndev->type = ARPHRD_ETHER;
1816 case NL80211_IFTYPE_P2P_GO:
1817 wil_dbg_misc(wil, "type: P2P_GO\n");
1818 ndev->type = ARPHRD_ETHER;
1820 case NL80211_IFTYPE_MONITOR:
1821 wil_dbg_misc(wil, "type: Monitor\n");
1822 ndev->type = ARPHRD_IEEE80211_RADIOTAP;
1823 /* ARPHRD_IEEE80211 or ARPHRD_IEEE80211_RADIOTAP ? */
1829 /* MAC address - pre-requisite for other commands */
1830 wmi_set_mac_address(wil, ndev->dev_addr);
1832 wil_dbg_misc(wil, "NAPI enable\n");
1833 napi_enable(&wil->napi_rx);
1834 napi_enable(&wil->napi_tx);
1835 set_bit(wil_status_napi_en, wil->status);
1837 wil6210_bus_request(wil, WIL_DEFAULT_BUS_REQUEST_KBPS);
1842 int wil_up(struct wil6210_priv *wil)
1846 wil_dbg_misc(wil, "up\n");
1848 mutex_lock(&wil->mutex);
1850 mutex_unlock(&wil->mutex);
1855 int __wil_down(struct wil6210_priv *wil)
1857 WARN_ON(!mutex_is_locked(&wil->mutex));
1859 set_bit(wil_status_resetting, wil->status);
1861 wil6210_bus_request(wil, 0);
1863 wil_disable_irq(wil);
1864 if (test_and_clear_bit(wil_status_napi_en, wil->status)) {
1865 napi_disable(&wil->napi_rx);
1866 napi_disable(&wil->napi_tx);
1867 wil_dbg_misc(wil, "NAPI disable\n");
1869 wil_enable_irq(wil);
1871 mutex_lock(&wil->vif_mutex);
1872 wil_p2p_stop_radio_operations(wil);
1873 wil_abort_scan_all_vifs(wil, false);
1874 mutex_unlock(&wil->vif_mutex);
1876 return wil_reset(wil, false);
1879 int wil_down(struct wil6210_priv *wil)
1883 wil_dbg_misc(wil, "down\n");
1885 wil_set_recovery_state(wil, fw_recovery_idle);
1886 mutex_lock(&wil->mutex);
1887 rc = __wil_down(wil);
1888 mutex_unlock(&wil->mutex);
1893 int wil_find_cid(struct wil6210_priv *wil, u8 mid, const u8 *mac)
1898 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1899 if (wil->sta[i].mid == mid &&
1900 wil->sta[i].status != wil_sta_unused &&
1901 ether_addr_equal(wil->sta[i].addr, mac)) {
1910 void wil_halp_vote(struct wil6210_priv *wil)
1913 unsigned long to_jiffies = msecs_to_jiffies(WAIT_FOR_HALP_VOTE_MS);
1915 mutex_lock(&wil->halp.lock);
1917 wil_dbg_irq(wil, "halp_vote: start, HALP ref_cnt (%d)\n",
1920 if (++wil->halp.ref_cnt == 1) {
1921 reinit_completion(&wil->halp.comp);
1922 wil6210_set_halp(wil);
1923 rc = wait_for_completion_timeout(&wil->halp.comp, to_jiffies);
1925 wil_err(wil, "HALP vote timed out\n");
1926 /* Mask HALP as done in case the interrupt is raised */
1927 wil6210_mask_halp(wil);
1930 "halp_vote: HALP vote completed after %d ms\n",
1931 jiffies_to_msecs(to_jiffies - rc));
1935 wil_dbg_irq(wil, "halp_vote: end, HALP ref_cnt (%d)\n",
1938 mutex_unlock(&wil->halp.lock);
1941 void wil_halp_unvote(struct wil6210_priv *wil)
1943 WARN_ON(wil->halp.ref_cnt == 0);
1945 mutex_lock(&wil->halp.lock);
1947 wil_dbg_irq(wil, "halp_unvote: start, HALP ref_cnt (%d)\n",
1950 if (--wil->halp.ref_cnt == 0) {
1951 wil6210_clear_halp(wil);
1952 wil_dbg_irq(wil, "HALP unvote\n");
1955 wil_dbg_irq(wil, "halp_unvote:end, HALP ref_cnt (%d)\n",
1958 mutex_unlock(&wil->halp.lock);
1961 void wil_init_txrx_ops(struct wil6210_priv *wil)
1963 if (wil->use_enhanced_dma_hw)
1964 wil_init_txrx_ops_edma(wil);
1966 wil_init_txrx_ops_legacy_dma(wil);