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;
407 struct wireless_dev *wdev;
413 wil = vif_to_wil(vif);
414 ndev = vif_to_ndev(vif);
415 wdev = vif_to_wdev(vif);
418 wil_info(wil, "disconnect bssid=%pM, reason=%d\n", bssid, reason_code);
421 * - disconnect single STA, still connected
422 * - disconnect single STA, already disconnected
425 * For "disconnect all", there are 3 options:
427 * - bssid is broadcast address (ff:ff:ff:ff:ff:ff)
428 * - bssid is our MAC address
430 if (bssid && !is_broadcast_ether_addr(bssid) &&
431 !ether_addr_equal_unaligned(ndev->dev_addr, bssid)) {
432 cid = wil_find_cid(wil, vif->mid, bssid);
433 wil_dbg_misc(wil, "Disconnect %pM, CID=%d, reason=%d\n",
434 bssid, cid, reason_code);
435 if (cid >= 0) /* disconnect 1 peer */
436 wil_disconnect_cid(vif, cid, reason_code);
438 wil_dbg_misc(wil, "Disconnect all\n");
439 for (cid = 0; cid < WIL6210_MAX_CID; cid++)
440 wil_disconnect_cid(vif, cid, reason_code);
443 /* call event handler manually after processing wmi_call,
444 * to avoid deadlock - disconnect event handler acquires
445 * wil->mutex while it is already held here
447 _wil6210_disconnect_complete(vif, bssid, reason_code);
450 void wil_disconnect_worker(struct work_struct *work)
452 struct wil6210_vif *vif = container_of(work,
453 struct wil6210_vif, disconnect_worker);
454 struct wil6210_priv *wil = vif_to_wil(vif);
455 struct net_device *ndev = vif_to_ndev(vif);
458 struct wmi_cmd_hdr wmi;
459 struct wmi_disconnect_event evt;
462 if (test_bit(wil_vif_fwconnected, vif->status))
463 /* connect succeeded after all */
466 if (!test_bit(wil_vif_fwconnecting, vif->status))
467 /* already disconnected */
470 memset(&reply, 0, sizeof(reply));
472 rc = wmi_call(wil, WMI_DISCONNECT_CMDID, vif->mid, NULL, 0,
473 WMI_DISCONNECT_EVENTID, &reply, sizeof(reply),
474 WIL6210_DISCONNECT_TO_MS);
476 wil_err(wil, "disconnect error %d\n", rc);
480 wil_update_net_queues_bh(wil, vif, NULL, true);
481 netif_carrier_off(ndev);
482 cfg80211_connect_result(ndev, NULL, NULL, 0, NULL, 0,
483 WLAN_STATUS_UNSPECIFIED_FAILURE, GFP_KERNEL);
484 clear_bit(wil_vif_fwconnecting, vif->status);
487 static int wil_wait_for_recovery(struct wil6210_priv *wil)
489 if (wait_event_interruptible(wil->wq, wil->recovery_state !=
490 fw_recovery_pending)) {
491 wil_err(wil, "Interrupt, canceling recovery\n");
494 if (wil->recovery_state != fw_recovery_running) {
495 wil_info(wil, "Recovery cancelled\n");
498 wil_info(wil, "Proceed with recovery\n");
502 void wil_set_recovery_state(struct wil6210_priv *wil, int state)
504 wil_dbg_misc(wil, "set_recovery_state: %d -> %d\n",
505 wil->recovery_state, state);
507 wil->recovery_state = state;
508 wake_up_interruptible(&wil->wq);
511 bool wil_is_recovery_blocked(struct wil6210_priv *wil)
513 return no_fw_recovery && (wil->recovery_state == fw_recovery_pending);
516 static void wil_fw_error_worker(struct work_struct *work)
518 struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
520 struct net_device *ndev = wil->main_ndev;
521 struct wireless_dev *wdev;
523 wil_dbg_misc(wil, "fw error worker\n");
525 if (!ndev || !(ndev->flags & IFF_UP)) {
526 wil_info(wil, "No recovery - interface is down\n");
529 wdev = ndev->ieee80211_ptr;
531 /* increment @recovery_count if less then WIL6210_FW_RECOVERY_TO
532 * passed since last recovery attempt
534 if (time_is_after_jiffies(wil->last_fw_recovery +
535 WIL6210_FW_RECOVERY_TO))
536 wil->recovery_count++;
538 wil->recovery_count = 1; /* fw was alive for a long time */
540 if (wil->recovery_count > WIL6210_FW_RECOVERY_RETRIES) {
541 wil_err(wil, "too many recovery attempts (%d), giving up\n",
542 wil->recovery_count);
546 wil->last_fw_recovery = jiffies;
548 wil_info(wil, "fw error recovery requested (try %d)...\n",
549 wil->recovery_count);
551 wil->recovery_state = fw_recovery_running;
552 if (wil_wait_for_recovery(wil) != 0)
556 mutex_lock(&wil->mutex);
557 /* Needs adaptation for multiple VIFs
558 * need to go over all VIFs and consider the appropriate
559 * recovery because each one can have different iftype.
561 switch (wdev->iftype) {
562 case NL80211_IFTYPE_STATION:
563 case NL80211_IFTYPE_P2P_CLIENT:
564 case NL80211_IFTYPE_MONITOR:
565 /* silent recovery, upper layers will see disconnect */
569 case NL80211_IFTYPE_AP:
570 case NL80211_IFTYPE_P2P_GO:
571 if (no_fw_recovery) /* upper layers do recovery */
573 /* silent recovery, upper layers will see disconnect */
576 mutex_unlock(&wil->mutex);
577 wil_cfg80211_ap_recovery(wil);
578 mutex_lock(&wil->mutex);
579 wil_info(wil, "... completed\n");
582 wil_err(wil, "No recovery - unknown interface type %d\n",
587 mutex_unlock(&wil->mutex);
591 static int wil_find_free_ring(struct wil6210_priv *wil)
594 int min_ring_id = wil_get_min_tx_ring_id(wil);
596 for (i = min_ring_id; i < WIL6210_MAX_TX_RINGS; i++) {
597 if (!wil->ring_tx[i].va)
603 int wil_ring_init_tx(struct wil6210_vif *vif, int cid)
605 struct wil6210_priv *wil = vif_to_wil(vif);
606 int rc = -EINVAL, ringid;
609 wil_err(wil, "No connection pending\n");
612 ringid = wil_find_free_ring(wil);
614 wil_err(wil, "No free vring found\n");
618 wil_dbg_wmi(wil, "Configure for connection CID %d MID %d ring %d\n",
619 cid, vif->mid, ringid);
621 rc = wil->txrx_ops.ring_init_tx(vif, ringid, 1 << tx_ring_order,
624 wil_err(wil, "init TX for CID %d MID %d vring %d failed\n",
625 cid, vif->mid, ringid);
631 int wil_bcast_init(struct wil6210_vif *vif)
633 struct wil6210_priv *wil = vif_to_wil(vif);
634 int ri = vif->bcast_ring, rc;
636 if (ri >= 0 && wil->ring_tx[ri].va)
639 ri = wil_find_free_ring(wil);
643 vif->bcast_ring = ri;
644 rc = wil->txrx_ops.ring_init_bcast(vif, ri, 1 << bcast_ring_order);
646 vif->bcast_ring = -1;
651 void wil_bcast_fini(struct wil6210_vif *vif)
653 struct wil6210_priv *wil = vif_to_wil(vif);
654 int ri = vif->bcast_ring;
659 vif->bcast_ring = -1;
660 wil_ring_fini_tx(wil, ri);
663 void wil_bcast_fini_all(struct wil6210_priv *wil)
666 struct wil6210_vif *vif;
668 for (i = 0; i < wil->max_vifs; i++) {
675 int wil_priv_init(struct wil6210_priv *wil)
679 wil_dbg_misc(wil, "priv_init\n");
681 memset(wil->sta, 0, sizeof(wil->sta));
682 for (i = 0; i < WIL6210_MAX_CID; i++) {
683 spin_lock_init(&wil->sta[i].tid_rx_lock);
684 wil->sta[i].mid = U8_MAX;
687 for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) {
688 spin_lock_init(&wil->ring_tx_data[i].lock);
689 wil->ring2cid_tid[i][0] = WIL6210_MAX_CID;
692 mutex_init(&wil->mutex);
693 mutex_init(&wil->vif_mutex);
694 mutex_init(&wil->wmi_mutex);
695 mutex_init(&wil->halp.lock);
697 init_completion(&wil->wmi_ready);
698 init_completion(&wil->wmi_call);
699 init_completion(&wil->halp.comp);
701 INIT_WORK(&wil->wmi_event_worker, wmi_event_worker);
702 INIT_WORK(&wil->fw_error_worker, wil_fw_error_worker);
704 INIT_LIST_HEAD(&wil->pending_wmi_ev);
705 spin_lock_init(&wil->wmi_ev_lock);
706 spin_lock_init(&wil->net_queue_lock);
707 init_waitqueue_head(&wil->wq);
709 wil->wmi_wq = create_singlethread_workqueue(WIL_NAME "_wmi");
713 wil->wq_service = create_singlethread_workqueue(WIL_NAME "_service");
714 if (!wil->wq_service)
717 wil->last_fw_recovery = jiffies;
718 wil->tx_interframe_timeout = WIL6210_ITR_TX_INTERFRAME_TIMEOUT_DEFAULT;
719 wil->rx_interframe_timeout = WIL6210_ITR_RX_INTERFRAME_TIMEOUT_DEFAULT;
720 wil->tx_max_burst_duration = WIL6210_ITR_TX_MAX_BURST_DURATION_DEFAULT;
721 wil->rx_max_burst_duration = WIL6210_ITR_RX_MAX_BURST_DURATION_DEFAULT;
723 if (rx_ring_overflow_thrsh == WIL6210_RX_HIGH_TRSH_INIT)
724 rx_ring_overflow_thrsh = WIL6210_RX_HIGH_TRSH_DEFAULT;
726 wil->ps_profile = WMI_PS_PROFILE_TYPE_DEFAULT;
728 wil->wakeup_trigger = WMI_WAKEUP_TRIGGER_UCAST |
729 WMI_WAKEUP_TRIGGER_BCAST;
730 memset(&wil->suspend_stats, 0, sizeof(wil->suspend_stats));
731 wil->ring_idle_trsh = 16;
733 wil->reply_mid = U8_MAX;
736 /* edma configuration can be updated via debugfs before allocation */
737 wil->num_rx_status_rings = WIL_DEFAULT_NUM_RX_STATUS_RINGS;
738 wil->tx_status_ring_order = WIL_TX_SRING_SIZE_ORDER_DEFAULT;
740 /* Rx status ring size should be bigger than the number of RX buffers
741 * in order to prevent backpressure on the status ring, which may
744 wil->rx_status_ring_order = WIL_RX_SRING_SIZE_ORDER_DEFAULT;
745 /* Number of RX buffer IDs should be bigger than the RX descriptor
746 * ring size as in HW reorder flow, the HW can consume additional
747 * buffers before releasing the previous ones.
749 wil->rx_buff_id_count = WIL_RX_BUFF_ARR_SIZE_DEFAULT;
756 destroy_workqueue(wil->wmi_wq);
761 void wil6210_bus_request(struct wil6210_priv *wil, u32 kbps)
763 if (wil->platform_ops.bus_request) {
764 wil->bus_request_kbps = kbps;
765 wil->platform_ops.bus_request(wil->platform_handle, kbps);
770 * wil6210_disconnect - disconnect one connection
771 * @vif: virtual interface context
772 * @bssid: peer to disconnect, NULL to disconnect all
773 * @reason_code: Reason code for the Disassociation frame
775 * Disconnect and release associated resources. Issue WMI
776 * command(s) to trigger MAC disconnect. When command was issued
777 * successfully, call the wil6210_disconnect_complete function
778 * to handle the event synchronously
780 void wil6210_disconnect(struct wil6210_vif *vif, const u8 *bssid,
783 struct wil6210_priv *wil = vif_to_wil(vif);
785 wil_dbg_misc(wil, "disconnecting\n");
787 del_timer_sync(&vif->connect_timer);
788 _wil6210_disconnect(vif, bssid, reason_code);
792 * wil6210_disconnect_complete - handle disconnect event
793 * @vif: virtual interface context
794 * @bssid: peer to disconnect, NULL to disconnect all
795 * @reason_code: Reason code for the Disassociation frame
797 * Release associated resources and indicate upper layers the
798 * connection is terminated.
800 void wil6210_disconnect_complete(struct wil6210_vif *vif, const u8 *bssid,
803 struct wil6210_priv *wil = vif_to_wil(vif);
805 wil_dbg_misc(wil, "got disconnect\n");
807 del_timer_sync(&vif->connect_timer);
808 _wil6210_disconnect_complete(vif, bssid, reason_code);
811 void wil_priv_deinit(struct wil6210_priv *wil)
813 wil_dbg_misc(wil, "priv_deinit\n");
815 wil_set_recovery_state(wil, fw_recovery_idle);
816 cancel_work_sync(&wil->fw_error_worker);
817 wmi_event_flush(wil);
818 destroy_workqueue(wil->wq_service);
819 destroy_workqueue(wil->wmi_wq);
822 static void wil_shutdown_bl(struct wil6210_priv *wil)
826 wil_s(wil, RGF_USER_BL +
827 offsetof(struct bl_dedicated_registers_v1,
828 bl_shutdown_handshake), BL_SHUTDOWN_HS_GRTD);
830 usleep_range(100, 150);
832 val = wil_r(wil, RGF_USER_BL +
833 offsetof(struct bl_dedicated_registers_v1,
834 bl_shutdown_handshake));
835 if (val & BL_SHUTDOWN_HS_RTD) {
836 wil_dbg_misc(wil, "BL is ready for halt\n");
840 wil_err(wil, "BL did not report ready for halt\n");
843 /* this format is used by ARC embedded CPU for instruction memory */
844 static inline u32 ARC_me_imm32(u32 d)
846 return ((d & 0xffff0000) >> 16) | ((d & 0x0000ffff) << 16);
849 /* defines access to interrupt vectors for wil_freeze_bl */
850 #define ARC_IRQ_VECTOR_OFFSET(N) ((N) * 8)
851 /* ARC long jump instruction */
852 #define ARC_JAL_INST (0x20200f80)
854 static void wil_freeze_bl(struct wil6210_priv *wil)
857 u32 ivt3 = ARC_IRQ_VECTOR_OFFSET(3);
859 jal = wil_r(wil, wil->iccm_base + ivt3);
860 if (jal != ARC_me_imm32(ARC_JAL_INST)) {
861 wil_dbg_misc(wil, "invalid IVT entry found, skipping\n");
865 /* prevent the target from entering deep sleep
866 * and disabling memory access
868 saved = wil_r(wil, RGF_USER_USAGE_8);
869 wil_w(wil, RGF_USER_USAGE_8, saved | BIT_USER_PREVENT_DEEP_SLEEP);
870 usleep_range(20, 25); /* let the BL process the bit */
872 /* redirect to endless loop in the INT_L1 context and let it trap */
873 wil_w(wil, wil->iccm_base + ivt3 + 4, ARC_me_imm32(ivt3));
874 usleep_range(20, 25); /* let the BL get into the trap */
876 /* verify the BL is frozen */
877 upc = wil_r(wil, RGF_USER_CPU_PC);
878 if (upc < ivt3 || (upc > (ivt3 + 8)))
879 wil_dbg_misc(wil, "BL freeze failed, PC=0x%08X\n", upc);
881 wil_w(wil, RGF_USER_USAGE_8, saved);
884 static void wil_bl_prepare_halt(struct wil6210_priv *wil)
888 /* before halting device CPU driver must make sure BL is not accessing
889 * host memory. This is done differently depending on BL version:
890 * 1. For very old BL versions the procedure is skipped
892 * 2. For old BL version we use a special trick to freeze the BL
893 * 3. For new BL versions we shutdown the BL using handshake procedure.
895 tmp = wil_r(wil, RGF_USER_BL +
896 offsetof(struct bl_dedicated_registers_v0,
897 boot_loader_struct_version));
899 wil_dbg_misc(wil, "old BL, skipping halt preparation\n");
903 tmp = wil_r(wil, RGF_USER_BL +
904 offsetof(struct bl_dedicated_registers_v1,
905 bl_shutdown_handshake));
906 ver = BL_SHUTDOWN_HS_PROT_VER(tmp);
909 wil_shutdown_bl(wil);
914 static inline void wil_halt_cpu(struct wil6210_priv *wil)
916 if (wil->hw_version >= HW_VER_TALYN_MB) {
917 wil_w(wil, RGF_USER_USER_CPU_0_TALYN_MB,
918 BIT_USER_USER_CPU_MAN_RST);
919 wil_w(wil, RGF_USER_MAC_CPU_0_TALYN_MB,
920 BIT_USER_MAC_CPU_MAN_RST);
922 wil_w(wil, RGF_USER_USER_CPU_0, BIT_USER_USER_CPU_MAN_RST);
923 wil_w(wil, RGF_USER_MAC_CPU_0, BIT_USER_MAC_CPU_MAN_RST);
927 static inline void wil_release_cpu(struct wil6210_priv *wil)
930 if (wil->hw_version >= HW_VER_TALYN_MB)
931 wil_w(wil, RGF_USER_USER_CPU_0_TALYN_MB, 1);
933 wil_w(wil, RGF_USER_USER_CPU_0, 1);
936 static void wil_set_oob_mode(struct wil6210_priv *wil, u8 mode)
938 wil_info(wil, "oob_mode to %d\n", mode);
941 wil_c(wil, RGF_USER_USAGE_6, BIT_USER_OOB_MODE |
942 BIT_USER_OOB_R2_MODE);
945 wil_c(wil, RGF_USER_USAGE_6, BIT_USER_OOB_R2_MODE);
946 wil_s(wil, RGF_USER_USAGE_6, BIT_USER_OOB_MODE);
949 wil_c(wil, RGF_USER_USAGE_6, BIT_USER_OOB_MODE);
950 wil_s(wil, RGF_USER_USAGE_6, BIT_USER_OOB_R2_MODE);
953 wil_err(wil, "invalid oob_mode: %d\n", mode);
957 static int wil_wait_device_ready(struct wil6210_priv *wil, int no_flash)
962 /* wait until device ready. */
964 msleep(PMU_READY_DELAY_MS);
966 wil_dbg_misc(wil, "Reset completed\n");
970 x = wil_r(wil, RGF_USER_BL +
971 offsetof(struct bl_dedicated_registers_v0,
974 wil_dbg_misc(wil, "BL.ready 0x%08x => 0x%08x\n",
978 if (delay++ > RST_COUNT) {
979 wil_err(wil, "Reset not completed, bl.ready 0x%08x\n",
983 } while (x != BL_READY);
985 wil_dbg_misc(wil, "Reset completed in %d ms\n",
992 static int wil_wait_device_ready_talyn_mb(struct wil6210_priv *wil)
996 bool otp_signature_err;
997 bool hw_section_done;
1001 /* Wait for OTP signature test to complete */
1002 usleep_range(2000, 2200);
1004 wil->boot_config = WIL_BOOT_ERR;
1006 /* Poll until OTP signature status is valid.
1007 * In vanilla and development modes, when signature test is complete
1008 * HW sets BIT_OTP_SIGNATURE_ERR_TALYN_MB.
1009 * In production mode BIT_OTP_SIGNATURE_ERR_TALYN_MB remains 0, poll
1010 * for signature status change to 2 or 3.
1013 otp_hw = wil_r(wil, RGF_USER_OTP_HW_RD_MACHINE_1);
1014 signature_status = WIL_GET_BITS(otp_hw, 8, 9);
1015 otp_signature_err = otp_hw & BIT_OTP_SIGNATURE_ERR_TALYN_MB;
1017 if (otp_signature_err &&
1018 signature_status == WIL_SIG_STATUS_VANILLA) {
1019 wil->boot_config = WIL_BOOT_VANILLA;
1022 if (otp_signature_err &&
1023 signature_status == WIL_SIG_STATUS_DEVELOPMENT) {
1024 wil->boot_config = WIL_BOOT_DEVELOPMENT;
1027 if (!otp_signature_err &&
1028 signature_status == WIL_SIG_STATUS_PRODUCTION) {
1029 wil->boot_config = WIL_BOOT_PRODUCTION;
1032 if (!otp_signature_err &&
1034 WIL_SIG_STATUS_CORRUPTED_PRODUCTION) {
1035 /* Unrecognized OTP signature found. Possibly a
1036 * corrupted production signature, access control
1037 * is applied as in production mode, therefore
1040 wil->boot_config = WIL_BOOT_PRODUCTION;
1043 if (delay++ > OTP_HW_COUNT)
1046 usleep_range(OTP_HW_DELAY, OTP_HW_DELAY + 10);
1047 } while (!otp_signature_err && signature_status == 0);
1049 if (wil->boot_config == WIL_BOOT_ERR) {
1051 "invalid boot config, signature_status %d otp_signature_err %d\n",
1052 signature_status, otp_signature_err);
1057 "signature test done in %d usec, otp_hw 0x%x, boot_config %d\n",
1058 delay * OTP_HW_DELAY, otp_hw, wil->boot_config);
1060 if (wil->boot_config == WIL_BOOT_VANILLA)
1061 /* Assuming not SPI boot (currently not supported) */
1064 hw_section_done = otp_hw & BIT_OTP_HW_SECTION_DONE_TALYN_MB;
1067 while (!hw_section_done) {
1070 otp_hw = wil_r(wil, RGF_USER_OTP_HW_RD_MACHINE_1);
1071 hw_section_done = otp_hw & BIT_OTP_HW_SECTION_DONE_TALYN_MB;
1073 if (delay++ > RST_COUNT) {
1074 wil_err(wil, "TO waiting for hw_section_done\n");
1079 wil_dbg_misc(wil, "HW section done in %d ms\n", delay * RST_DELAY);
1081 otp_qc_secured = wil_r(wil, RGF_OTP_QC_SECURED);
1082 wil->secured_boot = otp_qc_secured & BIT_BOOT_FROM_ROM ? 1 : 0;
1083 wil_dbg_misc(wil, "secured boot is %sabled\n",
1084 wil->secured_boot ? "en" : "dis");
1087 wil_dbg_misc(wil, "Reset completed\n");
1092 static int wil_target_reset(struct wil6210_priv *wil, int no_flash)
1097 wil_dbg_misc(wil, "Resetting \"%s\"...\n", wil->hw_name);
1099 if (wil->hw_version < HW_VER_TALYN) {
1100 /* Clear MAC link up */
1101 wil_s(wil, RGF_HP_CTRL, BIT(15));
1102 wil_s(wil, RGF_USER_CLKS_CTL_SW_RST_MASK_0,
1103 BIT_HPAL_PERST_FROM_PAD);
1104 wil_s(wil, RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT_CAR_PERST_RST);
1110 /* clear all boot loader "ready" bits */
1111 wil_w(wil, RGF_USER_BL +
1112 offsetof(struct bl_dedicated_registers_v0,
1113 boot_loader_ready), 0);
1114 /* this should be safe to write even with old BLs */
1115 wil_w(wil, RGF_USER_BL +
1116 offsetof(struct bl_dedicated_registers_v1,
1117 bl_shutdown_handshake), 0);
1119 /* Clear Fw Download notification */
1120 wil_c(wil, RGF_USER_USAGE_6, BIT(0));
1122 wil_s(wil, RGF_CAF_OSC_CONTROL, BIT_CAF_OSC_XTAL_EN);
1123 /* XTAL stabilization should take about 3ms */
1124 usleep_range(5000, 7000);
1125 x = wil_r(wil, RGF_CAF_PLL_LOCK_STATUS);
1126 if (!(x & BIT_CAF_OSC_DIG_XTAL_STABLE)) {
1127 wil_err(wil, "Xtal stabilization timeout\n"
1128 "RGF_CAF_PLL_LOCK_STATUS = 0x%08x\n", x);
1131 /* switch 10k to XTAL*/
1132 wil_c(wil, RGF_USER_SPARROW_M_4, BIT_SPARROW_M_4_SEL_SLEEP_OR_REF);
1134 wil_c(wil, RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_CAR_AHB_SW_SEL);
1136 wil_w(wil, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x3ff81f);
1137 wil_w(wil, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0xf);
1139 if (wil->hw_version >= HW_VER_TALYN_MB) {
1140 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x7e000000);
1141 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0x0000003f);
1142 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0xc00000f0);
1143 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0xffe7fe00);
1145 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0xfe000000);
1146 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0x0000003f);
1147 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x000000f0);
1148 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0xffe7fe00);
1151 wil_w(wil, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x0);
1152 wil_w(wil, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0x0);
1154 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0);
1155 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0);
1156 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0);
1157 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
1159 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000003);
1160 /* reset A2 PCIE AHB */
1161 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00008000);
1163 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
1165 if (wil->hw_version == HW_VER_TALYN_MB)
1166 rc = wil_wait_device_ready_talyn_mb(wil);
1168 rc = wil_wait_device_ready(wil, no_flash);
1172 wil_c(wil, RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_RST_PWGD);
1174 /* enable fix for HW bug related to the SA/DA swap in AP Rx */
1175 wil_s(wil, RGF_DMA_OFUL_NID_0, BIT_DMA_OFUL_NID_0_RX_EXT_TR_EN |
1176 BIT_DMA_OFUL_NID_0_RX_EXT_A3_SRC);
1178 if (wil->hw_version < HW_VER_TALYN_MB && no_flash) {
1179 /* Reset OTP HW vectors to fit 40MHz */
1180 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME1, 0x60001);
1181 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME2, 0x20027);
1182 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME3, 0x1);
1183 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME4, 0x20027);
1184 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME5, 0x30003);
1185 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME6, 0x20002);
1186 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME7, 0x60001);
1187 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME8, 0x60001);
1188 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME9, 0x60001);
1189 wil_w(wil, RGF_USER_XPM_IFC_RD_TIME10, 0x60001);
1190 wil_w(wil, RGF_USER_XPM_RD_DOUT_SAMPLE_TIME, 0x57);
1196 static void wil_collect_fw_info(struct wil6210_priv *wil)
1198 struct wiphy *wiphy = wil_to_wiphy(wil);
1202 wil_refresh_fw_capabilities(wil);
1204 rc = wmi_get_mgmt_retry(wil, &retry_short);
1206 wiphy->retry_short = retry_short;
1207 wil_dbg_misc(wil, "FW retry_short: %d\n", retry_short);
1211 void wil_refresh_fw_capabilities(struct wil6210_priv *wil)
1213 struct wiphy *wiphy = wil_to_wiphy(wil);
1216 wil->keep_radio_on_during_sleep =
1217 test_bit(WIL_PLATFORM_CAPA_RADIO_ON_IN_SUSPEND,
1218 wil->platform_capa) &&
1219 test_bit(WMI_FW_CAPABILITY_D3_SUSPEND, wil->fw_capabilities);
1221 wil_info(wil, "keep_radio_on_during_sleep (%d)\n",
1222 wil->keep_radio_on_during_sleep);
1224 if (test_bit(WMI_FW_CAPABILITY_RSSI_REPORTING, wil->fw_capabilities))
1225 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1227 wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
1229 if (test_bit(WMI_FW_CAPABILITY_PNO, wil->fw_capabilities)) {
1230 wiphy->max_sched_scan_reqs = 1;
1231 wiphy->max_sched_scan_ssids = WMI_MAX_PNO_SSID_NUM;
1232 wiphy->max_match_sets = WMI_MAX_PNO_SSID_NUM;
1233 wiphy->max_sched_scan_ie_len = WMI_MAX_IE_LEN;
1234 wiphy->max_sched_scan_plans = WMI_MAX_PLANS_NUM;
1237 if (test_bit(WMI_FW_CAPABILITY_TX_REQ_EXT, wil->fw_capabilities))
1238 wiphy->flags |= WIPHY_FLAG_OFFCHAN_TX;
1240 if (wil->platform_ops.set_features) {
1241 features = (test_bit(WMI_FW_CAPABILITY_REF_CLOCK_CONTROL,
1242 wil->fw_capabilities) &&
1243 test_bit(WIL_PLATFORM_CAPA_EXT_CLK,
1244 wil->platform_capa)) ?
1245 BIT(WIL_PLATFORM_FEATURE_FW_EXT_CLK_CONTROL) : 0;
1247 if (wil->n_msi == 3)
1248 features |= BIT(WIL_PLATFORM_FEATURE_TRIPLE_MSI);
1250 wil->platform_ops.set_features(wil->platform_handle, features);
1253 if (test_bit(WMI_FW_CAPABILITY_BACK_WIN_SIZE_64,
1254 wil->fw_capabilities)) {
1255 wil->max_agg_wsize = WIL_MAX_AGG_WSIZE_64;
1256 wil->max_ampdu_size = WIL_MAX_AMPDU_SIZE_128;
1258 wil->max_agg_wsize = WIL_MAX_AGG_WSIZE;
1259 wil->max_ampdu_size = WIL_MAX_AMPDU_SIZE;
1262 update_supported_bands(wil);
1265 void wil_mbox_ring_le2cpus(struct wil6210_mbox_ring *r)
1267 le32_to_cpus(&r->base);
1268 le16_to_cpus(&r->entry_size);
1269 le16_to_cpus(&r->size);
1270 le32_to_cpus(&r->tail);
1271 le32_to_cpus(&r->head);
1274 /* construct actual board file name to use */
1275 void wil_get_board_file(struct wil6210_priv *wil, char *buf, size_t len)
1277 const char *board_file;
1278 const char *wil_talyn_fw_name = ftm_mode ? WIL_FW_NAME_FTM_TALYN :
1281 if (wil->board_file) {
1282 board_file = wil->board_file;
1284 /* If specific FW file is used for Talyn,
1285 * use specific board file
1287 if (strcmp(wil->wil_fw_name, wil_talyn_fw_name) == 0)
1288 board_file = WIL_BRD_NAME_TALYN;
1290 board_file = WIL_BOARD_FILE_NAME;
1293 strlcpy(buf, board_file, len);
1296 static int wil_get_bl_info(struct wil6210_priv *wil)
1298 struct net_device *ndev = wil->main_ndev;
1299 struct wiphy *wiphy = wil_to_wiphy(wil);
1301 struct bl_dedicated_registers_v0 bl0;
1302 struct bl_dedicated_registers_v1 bl1;
1308 wil_memcpy_fromio_32(&bl, wil->csr + HOSTADDR(RGF_USER_BL),
1310 bl_ver = le32_to_cpu(bl.bl0.boot_loader_struct_version);
1311 mac = bl.bl0.mac_address;
1314 le32_to_cpus(&bl.bl0.rf_type);
1315 le32_to_cpus(&bl.bl0.baseband_type);
1316 rf_status = 0; /* actually, unknown */
1318 "Boot Loader struct v%d: MAC = %pM RF = 0x%08x bband = 0x%08x\n",
1320 bl.bl0.rf_type, bl.bl0.baseband_type);
1321 wil_info(wil, "Boot Loader build unknown for struct v0\n");
1323 le16_to_cpus(&bl.bl1.rf_type);
1324 rf_status = le16_to_cpu(bl.bl1.rf_status);
1325 le32_to_cpus(&bl.bl1.baseband_type);
1326 le16_to_cpus(&bl.bl1.bl_version_subminor);
1327 le16_to_cpus(&bl.bl1.bl_version_build);
1329 "Boot Loader struct v%d: MAC = %pM RF = 0x%04x (status 0x%04x) bband = 0x%08x\n",
1331 bl.bl1.rf_type, rf_status,
1332 bl.bl1.baseband_type);
1333 wil_info(wil, "Boot Loader build %d.%d.%d.%d\n",
1334 bl.bl1.bl_version_major, bl.bl1.bl_version_minor,
1335 bl.bl1.bl_version_subminor, bl.bl1.bl_version_build);
1338 if (!is_valid_ether_addr(mac)) {
1339 wil_err(wil, "BL: Invalid MAC %pM\n", mac);
1343 ether_addr_copy(ndev->perm_addr, mac);
1344 ether_addr_copy(wiphy->perm_addr, mac);
1345 if (!is_valid_ether_addr(ndev->dev_addr))
1346 ether_addr_copy(ndev->dev_addr, mac);
1348 if (rf_status) {/* bad RF cable? */
1349 wil_err(wil, "RF communication error 0x%04x",
1357 static void wil_bl_crash_info(struct wil6210_priv *wil, bool is_err)
1359 u32 bl_assert_code, bl_assert_blink, bl_magic_number;
1360 u32 bl_ver = wil_r(wil, RGF_USER_BL +
1361 offsetof(struct bl_dedicated_registers_v0,
1362 boot_loader_struct_version));
1367 bl_assert_code = wil_r(wil, RGF_USER_BL +
1368 offsetof(struct bl_dedicated_registers_v1,
1370 bl_assert_blink = wil_r(wil, RGF_USER_BL +
1371 offsetof(struct bl_dedicated_registers_v1,
1373 bl_magic_number = wil_r(wil, RGF_USER_BL +
1374 offsetof(struct bl_dedicated_registers_v1,
1379 "BL assert code 0x%08x blink 0x%08x magic 0x%08x\n",
1380 bl_assert_code, bl_assert_blink, bl_magic_number);
1383 "BL assert code 0x%08x blink 0x%08x magic 0x%08x\n",
1384 bl_assert_code, bl_assert_blink, bl_magic_number);
1388 static int wil_get_otp_info(struct wil6210_priv *wil)
1390 struct net_device *ndev = wil->main_ndev;
1391 struct wiphy *wiphy = wil_to_wiphy(wil);
1395 if (wil->hw_version >= HW_VER_TALYN_MB)
1396 mac_addr = RGF_OTP_MAC_TALYN_MB;
1398 mac_addr = RGF_OTP_MAC;
1400 wil_memcpy_fromio_32(mac, wil->csr + HOSTADDR(mac_addr),
1402 if (!is_valid_ether_addr(mac)) {
1403 wil_err(wil, "Invalid MAC %pM\n", mac);
1407 ether_addr_copy(ndev->perm_addr, mac);
1408 ether_addr_copy(wiphy->perm_addr, mac);
1409 if (!is_valid_ether_addr(ndev->dev_addr))
1410 ether_addr_copy(ndev->dev_addr, mac);
1415 static int wil_wait_for_fw_ready(struct wil6210_priv *wil)
1417 ulong to = msecs_to_jiffies(2000);
1418 ulong left = wait_for_completion_timeout(&wil->wmi_ready, to);
1421 wil_err(wil, "Firmware not ready\n");
1424 wil_info(wil, "FW ready after %d ms. HW version 0x%08x\n",
1425 jiffies_to_msecs(to-left), wil->hw_version);
1430 void wil_abort_scan(struct wil6210_vif *vif, bool sync)
1432 struct wil6210_priv *wil = vif_to_wil(vif);
1434 struct cfg80211_scan_info info = {
1438 lockdep_assert_held(&wil->vif_mutex);
1440 if (!vif->scan_request)
1443 wil_dbg_misc(wil, "Abort scan_request 0x%p\n", vif->scan_request);
1444 del_timer_sync(&vif->scan_timer);
1445 mutex_unlock(&wil->vif_mutex);
1446 rc = wmi_abort_scan(vif);
1448 wait_event_interruptible_timeout(wil->wq, !vif->scan_request,
1450 WAIT_FOR_SCAN_ABORT_MS));
1452 mutex_lock(&wil->vif_mutex);
1453 if (vif->scan_request) {
1454 cfg80211_scan_done(vif->scan_request, &info);
1455 vif->scan_request = NULL;
1459 void wil_abort_scan_all_vifs(struct wil6210_priv *wil, bool sync)
1463 lockdep_assert_held(&wil->vif_mutex);
1465 for (i = 0; i < wil->max_vifs; i++) {
1466 struct wil6210_vif *vif = wil->vifs[i];
1469 wil_abort_scan(vif, sync);
1473 int wil_ps_update(struct wil6210_priv *wil, enum wmi_ps_profile_type ps_profile)
1477 if (!test_bit(WMI_FW_CAPABILITY_PS_CONFIG, wil->fw_capabilities)) {
1478 wil_err(wil, "set_power_mgmt not supported\n");
1482 rc = wmi_ps_dev_profile_cfg(wil, ps_profile);
1484 wil_err(wil, "wmi_ps_dev_profile_cfg failed (%d)\n", rc);
1486 wil->ps_profile = ps_profile;
1491 static void wil_pre_fw_config(struct wil6210_priv *wil)
1493 /* Mark FW as loaded from host */
1494 wil_s(wil, RGF_USER_USAGE_6, 1);
1496 /* clear any interrupts which on-card-firmware
1499 wil6210_clear_irq(wil);
1500 /* CAF_ICR - clear and mask */
1501 /* it is W1C, clear by writing back same value */
1502 wil_s(wil, RGF_CAF_ICR + offsetof(struct RGF_ICR, ICR), 0);
1503 wil_w(wil, RGF_CAF_ICR + offsetof(struct RGF_ICR, IMV), ~0);
1504 /* clear PAL_UNIT_ICR (potential D0->D3 leftover)
1505 * In Talyn-MB host cannot access this register due to
1506 * access control, hence PAL_UNIT_ICR is cleared by the FW
1508 if (wil->hw_version < HW_VER_TALYN_MB)
1509 wil_s(wil, RGF_PAL_UNIT_ICR + offsetof(struct RGF_ICR, ICR),
1512 if (wil->fw_calib_result > 0) {
1513 __le32 val = cpu_to_le32(wil->fw_calib_result |
1514 (CALIB_RESULT_SIGNATURE << 8));
1515 wil_w(wil, RGF_USER_FW_CALIB_RESULT, (u32 __force)val);
1519 static int wil_restore_vifs(struct wil6210_priv *wil)
1521 struct wil6210_vif *vif;
1522 struct net_device *ndev;
1523 struct wireless_dev *wdev;
1526 for (i = 0; i < wil->max_vifs; i++) {
1530 vif->ap_isolate = 0;
1532 ndev = vif_to_ndev(vif);
1533 wdev = vif_to_wdev(vif);
1534 rc = wmi_port_allocate(wil, vif->mid, ndev->dev_addr,
1537 wil_err(wil, "fail to restore VIF %d type %d, rc %d\n",
1538 i, wdev->iftype, rc);
1548 * We reset all the structures, and we reset the UMAC.
1549 * After calling this routine, you're expected to reload
1552 int wil_reset(struct wil6210_priv *wil, bool load_fw)
1555 unsigned long status_flags = BIT(wil_status_resetting);
1557 struct wil6210_vif *vif;
1559 wil_dbg_misc(wil, "reset\n");
1561 WARN_ON(!mutex_is_locked(&wil->mutex));
1562 WARN_ON(test_bit(wil_status_napi_en, wil->status));
1565 static const u8 mac[ETH_ALEN] = {
1566 0x00, 0xde, 0xad, 0x12, 0x34, 0x56,
1568 struct net_device *ndev = wil->main_ndev;
1570 ether_addr_copy(ndev->perm_addr, mac);
1571 ether_addr_copy(ndev->dev_addr, ndev->perm_addr);
1575 if (wil->hw_version == HW_VER_UNKNOWN)
1578 if (test_bit(WIL_PLATFORM_CAPA_T_PWR_ON_0, wil->platform_capa)) {
1579 wil_dbg_misc(wil, "Notify FW to set T_POWER_ON=0\n");
1580 wil_s(wil, RGF_USER_USAGE_8, BIT_USER_SUPPORT_T_POWER_ON_0);
1583 if (test_bit(WIL_PLATFORM_CAPA_EXT_CLK, wil->platform_capa)) {
1584 wil_dbg_misc(wil, "Notify FW on ext clock configuration\n");
1585 wil_s(wil, RGF_USER_USAGE_8, BIT_USER_EXT_CLK);
1588 if (wil->platform_ops.notify) {
1589 rc = wil->platform_ops.notify(wil->platform_handle,
1590 WIL_PLATFORM_EVT_PRE_RESET);
1592 wil_err(wil, "PRE_RESET platform notify failed, rc %d\n",
1596 set_bit(wil_status_resetting, wil->status);
1597 if (test_bit(wil_status_collecting_dumps, wil->status)) {
1598 /* Device collects crash dump, cancel the reset.
1599 * following crash dump collection, reset would take place.
1601 wil_dbg_misc(wil, "reject reset while collecting crash dump\n");
1606 mutex_lock(&wil->vif_mutex);
1607 wil_abort_scan_all_vifs(wil, false);
1608 mutex_unlock(&wil->vif_mutex);
1610 for (i = 0; i < wil->max_vifs; i++) {
1613 cancel_work_sync(&vif->disconnect_worker);
1614 wil6210_disconnect(vif, NULL,
1615 WLAN_REASON_DEAUTH_LEAVING);
1618 wil_bcast_fini_all(wil);
1620 /* Disable device led before reset*/
1621 wmi_led_cfg(wil, false);
1623 /* prevent NAPI from being scheduled and prevent wmi commands */
1624 mutex_lock(&wil->wmi_mutex);
1625 if (test_bit(wil_status_suspending, wil->status))
1626 status_flags |= BIT(wil_status_suspending);
1627 bitmap_and(wil->status, wil->status, &status_flags,
1629 wil_dbg_misc(wil, "wil->status (0x%lx)\n", *wil->status);
1630 mutex_unlock(&wil->wmi_mutex);
1634 wmi_event_flush(wil);
1636 flush_workqueue(wil->wq_service);
1637 flush_workqueue(wil->wmi_wq);
1639 no_flash = test_bit(hw_capa_no_flash, wil->hw_capa);
1641 wil_bl_crash_info(wil, false);
1642 wil_disable_irq(wil);
1643 rc = wil_target_reset(wil, no_flash);
1644 wil6210_clear_irq(wil);
1645 wil_enable_irq(wil);
1646 wil->txrx_ops.rx_fini(wil);
1647 wil->txrx_ops.tx_fini(wil);
1650 wil_bl_crash_info(wil, true);
1655 rc = wil_get_otp_info(wil);
1657 rc = wil_get_bl_info(wil);
1658 if (rc == -EAGAIN && !load_fw)
1659 /* ignore RF error if not going up */
1665 wil_set_oob_mode(wil, oob_mode);
1667 char board_file[WIL_BOARD_FILE_MAX_NAMELEN];
1669 if (wil->secured_boot) {
1670 wil_err(wil, "secured boot is not supported\n");
1674 board_file[0] = '\0';
1675 wil_get_board_file(wil, board_file, sizeof(board_file));
1676 wil_info(wil, "Use firmware <%s> + board <%s>\n",
1677 wil->wil_fw_name, board_file);
1680 wil_bl_prepare_halt(wil);
1683 memset(wil->fw_version, 0, sizeof(wil->fw_version));
1684 /* Loading f/w from the file */
1685 rc = wil_request_firmware(wil, wil->wil_fw_name, true);
1688 if (wil->brd_file_addr)
1689 rc = wil_request_board(wil, board_file);
1691 rc = wil_request_firmware(wil, board_file, true);
1695 wil_pre_fw_config(wil);
1696 wil_release_cpu(wil);
1699 /* init after reset */
1700 reinit_completion(&wil->wmi_ready);
1701 reinit_completion(&wil->wmi_call);
1702 reinit_completion(&wil->halp.comp);
1704 clear_bit(wil_status_resetting, wil->status);
1707 wil_unmask_irq(wil);
1709 /* we just started MAC, wait for FW ready */
1710 rc = wil_wait_for_fw_ready(wil);
1714 /* check FW is responsive */
1717 wil_err(wil, "wmi_echo failed, rc %d\n", rc);
1721 wil->txrx_ops.configure_interrupt_moderation(wil);
1723 /* Enable OFU rdy valid bug fix, to prevent hang in oful34_rx
1724 * while there is back-pressure from Host during RX
1726 if (wil->hw_version >= HW_VER_TALYN_MB)
1727 wil_s(wil, RGF_DMA_MISC_CTL,
1728 BIT_OFUL34_RDY_VALID_BUG_FIX_EN);
1730 rc = wil_restore_vifs(wil);
1732 wil_err(wil, "failed to restore vifs, rc %d\n", rc);
1736 wil_collect_fw_info(wil);
1738 if (wil->ps_profile != WMI_PS_PROFILE_TYPE_DEFAULT)
1739 wil_ps_update(wil, wil->ps_profile);
1741 if (wil->platform_ops.notify) {
1742 rc = wil->platform_ops.notify(wil->platform_handle,
1743 WIL_PLATFORM_EVT_FW_RDY);
1745 wil_err(wil, "FW_RDY notify failed, rc %d\n",
1755 clear_bit(wil_status_resetting, wil->status);
1759 void wil_fw_error_recovery(struct wil6210_priv *wil)
1761 wil_dbg_misc(wil, "starting fw error recovery\n");
1763 if (test_bit(wil_status_resetting, wil->status)) {
1764 wil_info(wil, "Reset already in progress\n");
1768 wil->recovery_state = fw_recovery_pending;
1769 schedule_work(&wil->fw_error_worker);
1772 int __wil_up(struct wil6210_priv *wil)
1774 struct net_device *ndev = wil->main_ndev;
1775 struct wireless_dev *wdev = ndev->ieee80211_ptr;
1778 WARN_ON(!mutex_is_locked(&wil->mutex));
1780 rc = wil_reset(wil, true);
1784 /* Rx RING. After MAC and beacon */
1785 if (rx_ring_order == 0)
1786 rx_ring_order = wil->hw_version < HW_VER_TALYN_MB ?
1787 WIL_RX_RING_SIZE_ORDER_DEFAULT :
1788 WIL_RX_RING_SIZE_ORDER_TALYN_DEFAULT;
1790 rc = wil->txrx_ops.rx_init(wil, rx_ring_order);
1794 rc = wil->txrx_ops.tx_init(wil);
1798 switch (wdev->iftype) {
1799 case NL80211_IFTYPE_STATION:
1800 wil_dbg_misc(wil, "type: STATION\n");
1801 ndev->type = ARPHRD_ETHER;
1803 case NL80211_IFTYPE_AP:
1804 wil_dbg_misc(wil, "type: AP\n");
1805 ndev->type = ARPHRD_ETHER;
1807 case NL80211_IFTYPE_P2P_CLIENT:
1808 wil_dbg_misc(wil, "type: P2P_CLIENT\n");
1809 ndev->type = ARPHRD_ETHER;
1811 case NL80211_IFTYPE_P2P_GO:
1812 wil_dbg_misc(wil, "type: P2P_GO\n");
1813 ndev->type = ARPHRD_ETHER;
1815 case NL80211_IFTYPE_MONITOR:
1816 wil_dbg_misc(wil, "type: Monitor\n");
1817 ndev->type = ARPHRD_IEEE80211_RADIOTAP;
1818 /* ARPHRD_IEEE80211 or ARPHRD_IEEE80211_RADIOTAP ? */
1824 /* MAC address - pre-requisite for other commands */
1825 wmi_set_mac_address(wil, ndev->dev_addr);
1827 wil_dbg_misc(wil, "NAPI enable\n");
1828 napi_enable(&wil->napi_rx);
1829 napi_enable(&wil->napi_tx);
1830 set_bit(wil_status_napi_en, wil->status);
1832 wil6210_bus_request(wil, WIL_DEFAULT_BUS_REQUEST_KBPS);
1837 int wil_up(struct wil6210_priv *wil)
1841 wil_dbg_misc(wil, "up\n");
1843 mutex_lock(&wil->mutex);
1845 mutex_unlock(&wil->mutex);
1850 int __wil_down(struct wil6210_priv *wil)
1852 WARN_ON(!mutex_is_locked(&wil->mutex));
1854 set_bit(wil_status_resetting, wil->status);
1856 wil6210_bus_request(wil, 0);
1858 wil_disable_irq(wil);
1859 if (test_and_clear_bit(wil_status_napi_en, wil->status)) {
1860 napi_disable(&wil->napi_rx);
1861 napi_disable(&wil->napi_tx);
1862 wil_dbg_misc(wil, "NAPI disable\n");
1864 wil_enable_irq(wil);
1866 mutex_lock(&wil->vif_mutex);
1867 wil_p2p_stop_radio_operations(wil);
1868 wil_abort_scan_all_vifs(wil, false);
1869 mutex_unlock(&wil->vif_mutex);
1871 return wil_reset(wil, false);
1874 int wil_down(struct wil6210_priv *wil)
1878 wil_dbg_misc(wil, "down\n");
1880 wil_set_recovery_state(wil, fw_recovery_idle);
1881 mutex_lock(&wil->mutex);
1882 rc = __wil_down(wil);
1883 mutex_unlock(&wil->mutex);
1888 int wil_find_cid(struct wil6210_priv *wil, u8 mid, const u8 *mac)
1893 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1894 if (wil->sta[i].mid == mid &&
1895 wil->sta[i].status != wil_sta_unused &&
1896 ether_addr_equal(wil->sta[i].addr, mac)) {
1905 void wil_halp_vote(struct wil6210_priv *wil)
1908 unsigned long to_jiffies = msecs_to_jiffies(WAIT_FOR_HALP_VOTE_MS);
1910 mutex_lock(&wil->halp.lock);
1912 wil_dbg_irq(wil, "halp_vote: start, HALP ref_cnt (%d)\n",
1915 if (++wil->halp.ref_cnt == 1) {
1916 reinit_completion(&wil->halp.comp);
1917 wil6210_set_halp(wil);
1918 rc = wait_for_completion_timeout(&wil->halp.comp, to_jiffies);
1920 wil_err(wil, "HALP vote timed out\n");
1921 /* Mask HALP as done in case the interrupt is raised */
1922 wil6210_mask_halp(wil);
1925 "halp_vote: HALP vote completed after %d ms\n",
1926 jiffies_to_msecs(to_jiffies - rc));
1930 wil_dbg_irq(wil, "halp_vote: end, HALP ref_cnt (%d)\n",
1933 mutex_unlock(&wil->halp.lock);
1936 void wil_halp_unvote(struct wil6210_priv *wil)
1938 WARN_ON(wil->halp.ref_cnt == 0);
1940 mutex_lock(&wil->halp.lock);
1942 wil_dbg_irq(wil, "halp_unvote: start, HALP ref_cnt (%d)\n",
1945 if (--wil->halp.ref_cnt == 0) {
1946 wil6210_clear_halp(wil);
1947 wil_dbg_irq(wil, "HALP unvote\n");
1950 wil_dbg_irq(wil, "halp_unvote:end, HALP ref_cnt (%d)\n",
1953 mutex_unlock(&wil->halp.lock);
1956 void wil_init_txrx_ops(struct wil6210_priv *wil)
1958 if (wil->use_enhanced_dma_hw)
1959 wil_init_txrx_ops_edma(wil);
1961 wil_init_txrx_ops_legacy_dma(wil);