2 * Copyright (c) 2012-2016 Qualcomm Atheros, Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <linux/moduleparam.h>
18 #include <linux/if_arp.h>
19 #include <linux/etherdevice.h>
24 #include "boot_loader.h"
26 bool debug_fw
; /* = false; */
27 module_param(debug_fw
, bool, S_IRUGO
);
28 MODULE_PARM_DESC(debug_fw
, " do not perform card reset. For FW debug");
31 module_param(oob_mode
, bool, S_IRUGO
);
32 MODULE_PARM_DESC(oob_mode
,
33 " enable out of the box (OOB) mode in FW, for diagnostics and certification");
36 module_param(no_fw_recovery
, bool, S_IRUGO
| S_IWUSR
);
37 MODULE_PARM_DESC(no_fw_recovery
, " disable automatic FW error recovery");
39 /* if not set via modparam, will be set to default value of 1/8 of
40 * rx ring size during init flow
42 unsigned short rx_ring_overflow_thrsh
= WIL6210_RX_HIGH_TRSH_INIT
;
43 module_param(rx_ring_overflow_thrsh
, ushort
, S_IRUGO
);
44 MODULE_PARM_DESC(rx_ring_overflow_thrsh
,
45 " RX ring overflow threshold in descriptors.");
47 /* We allow allocation of more than 1 page buffers to support large packets.
48 * It is suboptimal behavior performance wise in case MTU above page size.
50 unsigned int mtu_max
= TXRX_BUF_LEN_DEFAULT
- WIL_MAX_MPDU_OVERHEAD
;
51 static int mtu_max_set(const char *val
, const struct kernel_param
*kp
)
55 /* sets mtu_max directly. no need to restore it in case of
56 * illegal value since we assume this will fail insmod
58 ret
= param_set_uint(val
, kp
);
62 if (mtu_max
< 68 || mtu_max
> WIL_MAX_ETH_MTU
)
68 static const struct kernel_param_ops mtu_max_ops
= {
70 .get
= param_get_uint
,
73 module_param_cb(mtu_max
, &mtu_max_ops
, &mtu_max
, S_IRUGO
);
74 MODULE_PARM_DESC(mtu_max
, " Max MTU value.");
76 static uint rx_ring_order
= WIL_RX_RING_SIZE_ORDER_DEFAULT
;
77 static uint tx_ring_order
= WIL_TX_RING_SIZE_ORDER_DEFAULT
;
78 static uint bcast_ring_order
= WIL_BCAST_RING_SIZE_ORDER_DEFAULT
;
80 static int ring_order_set(const char *val
, const struct kernel_param
*kp
)
85 ret
= kstrtouint(val
, 0, &x
);
89 if ((x
< WIL_RING_SIZE_ORDER_MIN
) || (x
> WIL_RING_SIZE_ORDER_MAX
))
92 *((uint
*)kp
->arg
) = x
;
97 static const struct kernel_param_ops ring_order_ops
= {
98 .set
= ring_order_set
,
99 .get
= param_get_uint
,
102 module_param_cb(rx_ring_order
, &ring_order_ops
, &rx_ring_order
, S_IRUGO
);
103 MODULE_PARM_DESC(rx_ring_order
, " Rx ring order; size = 1 << order");
104 module_param_cb(tx_ring_order
, &ring_order_ops
, &tx_ring_order
, S_IRUGO
);
105 MODULE_PARM_DESC(tx_ring_order
, " Tx ring order; size = 1 << order");
106 module_param_cb(bcast_ring_order
, &ring_order_ops
, &bcast_ring_order
, S_IRUGO
);
107 MODULE_PARM_DESC(bcast_ring_order
, " Bcast ring order; size = 1 << order");
109 #define RST_DELAY (20) /* msec, for loop in @wil_target_reset */
110 #define RST_COUNT (1 + 1000/RST_DELAY) /* round up to be above 1 sec total */
113 * Due to a hardware issue,
114 * one has to read/write to/from NIC in 32-bit chunks;
115 * regular memcpy_fromio and siblings will
116 * not work on 64-bit platform - it uses 64-bit transactions
118 * Force 32-bit transactions to enable NIC on 64-bit platforms
120 * To avoid byte swap on big endian host, __raw_{read|write}l
121 * should be used - {read|write}l would swap bytes to provide
122 * little endian on PCI value in host endianness.
124 void wil_memcpy_fromio_32(void *dst
, const volatile void __iomem
*src
,
128 const volatile u32 __iomem
*s
= src
;
130 /* size_t is unsigned, if (count%4 != 0) it will wrap */
131 for (count
+= 4; count
> 4; count
-= 4)
132 *d
++ = __raw_readl(s
++);
135 void wil_memcpy_toio_32(volatile void __iomem
*dst
, const void *src
,
138 volatile u32 __iomem
*d
= dst
;
141 for (count
+= 4; count
> 4; count
-= 4)
142 __raw_writel(*s
++, d
++);
145 static void wil_disconnect_cid(struct wil6210_priv
*wil
, int cid
,
146 u16 reason_code
, bool from_event
)
147 __acquires(&sta
->tid_rx_lock
) __releases(&sta
->tid_rx_lock
)
150 struct net_device
*ndev
= wil_to_ndev(wil
);
151 struct wireless_dev
*wdev
= wil
->wdev
;
152 struct wil_sta_info
*sta
= &wil
->sta
[cid
];
155 wil_dbg_misc(wil
, "%s(CID %d, status %d)\n", __func__
, cid
,
157 /* inform upper/lower layers */
158 if (sta
->status
!= wil_sta_unused
) {
160 wmi_disconnect_sta(wil
, sta
->addr
, reason_code
, true);
162 switch (wdev
->iftype
) {
163 case NL80211_IFTYPE_AP
:
164 case NL80211_IFTYPE_P2P_GO
:
165 /* AP-like interface */
166 cfg80211_del_sta(ndev
, sta
->addr
, GFP_KERNEL
);
171 sta
->status
= wil_sta_unused
;
173 /* reorder buffers */
174 for (i
= 0; i
< WIL_STA_TID_NUM
; i
++) {
175 struct wil_tid_ampdu_rx
*r
;
177 spin_lock_bh(&sta
->tid_rx_lock
);
180 sta
->tid_rx
[i
] = NULL
;
181 wil_tid_ampdu_rx_free(wil
, r
);
183 spin_unlock_bh(&sta
->tid_rx_lock
);
186 memset(sta
->tid_crypto_rx
, 0, sizeof(sta
->tid_crypto_rx
));
187 memset(&sta
->group_crypto_rx
, 0, sizeof(sta
->group_crypto_rx
));
189 for (i
= 0; i
< ARRAY_SIZE(wil
->vring_tx
); i
++) {
190 if (wil
->vring2cid_tid
[i
][0] == cid
)
191 wil_vring_fini_tx(wil
, i
);
194 memset(&sta
->stats
, 0, sizeof(sta
->stats
));
197 static void _wil6210_disconnect(struct wil6210_priv
*wil
, const u8
*bssid
,
198 u16 reason_code
, bool from_event
)
201 struct net_device
*ndev
= wil_to_ndev(wil
);
202 struct wireless_dev
*wdev
= wil
->wdev
;
205 wil_info(wil
, "%s(bssid=%pM, reason=%d, ev%s)\n", __func__
, bssid
,
206 reason_code
, from_event
? "+" : "-");
209 * - disconnect single STA, still connected
210 * - disconnect single STA, already disconnected
213 * For "disconnect all", there are 3 options:
215 * - bssid is broadcast address (ff:ff:ff:ff:ff:ff)
216 * - bssid is our MAC address
218 if (bssid
&& !is_broadcast_ether_addr(bssid
) &&
219 !ether_addr_equal_unaligned(ndev
->dev_addr
, bssid
)) {
220 cid
= wil_find_cid(wil
, bssid
);
221 wil_dbg_misc(wil
, "Disconnect %pM, CID=%d, reason=%d\n",
222 bssid
, cid
, reason_code
);
223 if (cid
>= 0) /* disconnect 1 peer */
224 wil_disconnect_cid(wil
, cid
, reason_code
, from_event
);
226 wil_dbg_misc(wil
, "Disconnect all\n");
227 for (cid
= 0; cid
< WIL6210_MAX_CID
; cid
++)
228 wil_disconnect_cid(wil
, cid
, reason_code
, from_event
);
232 switch (wdev
->iftype
) {
233 case NL80211_IFTYPE_STATION
:
234 case NL80211_IFTYPE_P2P_CLIENT
:
236 netif_tx_stop_all_queues(ndev
);
237 netif_carrier_off(ndev
);
239 if (test_bit(wil_status_fwconnected
, wil
->status
)) {
240 clear_bit(wil_status_fwconnected
, wil
->status
);
241 cfg80211_disconnected(ndev
, reason_code
,
242 NULL
, 0, false, GFP_KERNEL
);
243 } else if (test_bit(wil_status_fwconnecting
, wil
->status
)) {
244 cfg80211_connect_result(ndev
, bssid
, NULL
, 0, NULL
, 0,
245 WLAN_STATUS_UNSPECIFIED_FAILURE
,
248 clear_bit(wil_status_fwconnecting
, wil
->status
);
255 static void wil_disconnect_worker(struct work_struct
*work
)
257 struct wil6210_priv
*wil
= container_of(work
,
258 struct wil6210_priv
, disconnect_worker
);
260 mutex_lock(&wil
->mutex
);
261 _wil6210_disconnect(wil
, NULL
, WLAN_REASON_UNSPECIFIED
, false);
262 mutex_unlock(&wil
->mutex
);
265 static void wil_connect_timer_fn(ulong x
)
267 struct wil6210_priv
*wil
= (void *)x
;
270 wil_err(wil
, "Connect timeout detected, disconnect station\n");
272 /* reschedule to thread context - disconnect won't
273 * run from atomic context.
274 * queue on wmi_wq to prevent race with connect event.
276 q
= queue_work(wil
->wmi_wq
, &wil
->disconnect_worker
);
277 wil_dbg_wmi(wil
, "queue_work of disconnect_worker -> %d\n", q
);
280 static void wil_scan_timer_fn(ulong x
)
282 struct wil6210_priv
*wil
= (void *)x
;
284 clear_bit(wil_status_fwready
, wil
->status
);
285 wil_err(wil
, "Scan timeout detected, start fw error recovery\n");
286 wil_fw_error_recovery(wil
);
289 static int wil_wait_for_recovery(struct wil6210_priv
*wil
)
291 if (wait_event_interruptible(wil
->wq
, wil
->recovery_state
!=
292 fw_recovery_pending
)) {
293 wil_err(wil
, "Interrupt, canceling recovery\n");
296 if (wil
->recovery_state
!= fw_recovery_running
) {
297 wil_info(wil
, "Recovery cancelled\n");
300 wil_info(wil
, "Proceed with recovery\n");
304 void wil_set_recovery_state(struct wil6210_priv
*wil
, int state
)
306 wil_dbg_misc(wil
, "%s(%d -> %d)\n", __func__
,
307 wil
->recovery_state
, state
);
309 wil
->recovery_state
= state
;
310 wake_up_interruptible(&wil
->wq
);
313 bool wil_is_recovery_blocked(struct wil6210_priv
*wil
)
315 return no_fw_recovery
&& (wil
->recovery_state
== fw_recovery_pending
);
318 static void wil_fw_error_worker(struct work_struct
*work
)
320 struct wil6210_priv
*wil
= container_of(work
, struct wil6210_priv
,
322 struct wireless_dev
*wdev
= wil
->wdev
;
324 wil_dbg_misc(wil
, "fw error worker\n");
326 if (!netif_running(wil_to_ndev(wil
))) {
327 wil_info(wil
, "No recovery - interface is down\n");
331 /* increment @recovery_count if less then WIL6210_FW_RECOVERY_TO
332 * passed since last recovery attempt
334 if (time_is_after_jiffies(wil
->last_fw_recovery
+
335 WIL6210_FW_RECOVERY_TO
))
336 wil
->recovery_count
++;
338 wil
->recovery_count
= 1; /* fw was alive for a long time */
340 if (wil
->recovery_count
> WIL6210_FW_RECOVERY_RETRIES
) {
341 wil_err(wil
, "too many recovery attempts (%d), giving up\n",
342 wil
->recovery_count
);
346 wil
->last_fw_recovery
= jiffies
;
348 mutex_lock(&wil
->mutex
);
349 switch (wdev
->iftype
) {
350 case NL80211_IFTYPE_STATION
:
351 case NL80211_IFTYPE_P2P_CLIENT
:
352 case NL80211_IFTYPE_MONITOR
:
353 wil_info(wil
, "fw error recovery requested (try %d)...\n",
354 wil
->recovery_count
);
356 wil
->recovery_state
= fw_recovery_running
;
357 if (0 != wil_wait_for_recovery(wil
))
363 case NL80211_IFTYPE_AP
:
364 case NL80211_IFTYPE_P2P_GO
:
365 wil_info(wil
, "No recovery for AP-like interface\n");
366 /* recovery in these modes is done by upper layers */
369 wil_err(wil
, "No recovery - unknown interface type %d\n",
373 mutex_unlock(&wil
->mutex
);
376 static int wil_find_free_vring(struct wil6210_priv
*wil
)
380 for (i
= 0; i
< WIL6210_MAX_TX_RINGS
; i
++) {
381 if (!wil
->vring_tx
[i
].va
)
387 int wil_tx_init(struct wil6210_priv
*wil
, int cid
)
389 int rc
= -EINVAL
, ringid
;
392 wil_err(wil
, "No connection pending\n");
395 ringid
= wil_find_free_vring(wil
);
397 wil_err(wil
, "No free vring found\n");
401 wil_dbg_wmi(wil
, "Configure for connection CID %d vring %d\n",
404 rc
= wil_vring_init_tx(wil
, ringid
, 1 << tx_ring_order
, cid
, 0);
406 wil_err(wil
, "wil_vring_init_tx for CID %d vring %d failed\n",
413 int wil_bcast_init(struct wil6210_priv
*wil
)
415 int ri
= wil
->bcast_vring
, rc
;
417 if ((ri
>= 0) && wil
->vring_tx
[ri
].va
)
420 ri
= wil_find_free_vring(wil
);
424 wil
->bcast_vring
= ri
;
425 rc
= wil_vring_init_bcast(wil
, ri
, 1 << bcast_ring_order
);
427 wil
->bcast_vring
= -1;
432 void wil_bcast_fini(struct wil6210_priv
*wil
)
434 int ri
= wil
->bcast_vring
;
439 wil
->bcast_vring
= -1;
440 wil_vring_fini_tx(wil
, ri
);
443 int wil_priv_init(struct wil6210_priv
*wil
)
447 wil_dbg_misc(wil
, "%s()\n", __func__
);
449 memset(wil
->sta
, 0, sizeof(wil
->sta
));
450 for (i
= 0; i
< WIL6210_MAX_CID
; i
++)
451 spin_lock_init(&wil
->sta
[i
].tid_rx_lock
);
453 for (i
= 0; i
< WIL6210_MAX_TX_RINGS
; i
++)
454 spin_lock_init(&wil
->vring_tx_data
[i
].lock
);
456 mutex_init(&wil
->mutex
);
457 mutex_init(&wil
->wmi_mutex
);
458 mutex_init(&wil
->probe_client_mutex
);
459 mutex_init(&wil
->p2p_wdev_mutex
);
461 init_completion(&wil
->wmi_ready
);
462 init_completion(&wil
->wmi_call
);
464 wil
->bcast_vring
= -1;
465 setup_timer(&wil
->connect_timer
, wil_connect_timer_fn
, (ulong
)wil
);
466 setup_timer(&wil
->scan_timer
, wil_scan_timer_fn
, (ulong
)wil
);
467 setup_timer(&wil
->p2p
.discovery_timer
, wil_p2p_discovery_timer_fn
,
470 INIT_WORK(&wil
->disconnect_worker
, wil_disconnect_worker
);
471 INIT_WORK(&wil
->wmi_event_worker
, wmi_event_worker
);
472 INIT_WORK(&wil
->fw_error_worker
, wil_fw_error_worker
);
473 INIT_WORK(&wil
->probe_client_worker
, wil_probe_client_worker
);
475 INIT_LIST_HEAD(&wil
->pending_wmi_ev
);
476 INIT_LIST_HEAD(&wil
->probe_client_pending
);
477 spin_lock_init(&wil
->wmi_ev_lock
);
478 init_waitqueue_head(&wil
->wq
);
480 wil
->wmi_wq
= create_singlethread_workqueue(WIL_NAME
"_wmi");
484 wil
->wq_service
= create_singlethread_workqueue(WIL_NAME
"_service");
485 if (!wil
->wq_service
)
488 wil
->last_fw_recovery
= jiffies
;
489 wil
->tx_interframe_timeout
= WIL6210_ITR_TX_INTERFRAME_TIMEOUT_DEFAULT
;
490 wil
->rx_interframe_timeout
= WIL6210_ITR_RX_INTERFRAME_TIMEOUT_DEFAULT
;
491 wil
->tx_max_burst_duration
= WIL6210_ITR_TX_MAX_BURST_DURATION_DEFAULT
;
492 wil
->rx_max_burst_duration
= WIL6210_ITR_RX_MAX_BURST_DURATION_DEFAULT
;
494 if (rx_ring_overflow_thrsh
== WIL6210_RX_HIGH_TRSH_INIT
)
495 rx_ring_overflow_thrsh
= WIL6210_RX_HIGH_TRSH_DEFAULT
;
499 destroy_workqueue(wil
->wmi_wq
);
505 * wil6210_disconnect - disconnect one connection
506 * @wil: driver context
507 * @bssid: peer to disconnect, NULL to disconnect all
508 * @reason_code: Reason code for the Disassociation frame
509 * @from_event: whether is invoked from FW event handler
511 * Disconnect and release associated resources. If invoked not from the
512 * FW event handler, issue WMI command(s) to trigger MAC disconnect.
514 void wil6210_disconnect(struct wil6210_priv
*wil
, const u8
*bssid
,
515 u16 reason_code
, bool from_event
)
517 wil_dbg_misc(wil
, "%s()\n", __func__
);
519 del_timer_sync(&wil
->connect_timer
);
520 _wil6210_disconnect(wil
, bssid
, reason_code
, from_event
);
523 void wil_priv_deinit(struct wil6210_priv
*wil
)
525 wil_dbg_misc(wil
, "%s()\n", __func__
);
527 wil_set_recovery_state(wil
, fw_recovery_idle
);
528 del_timer_sync(&wil
->scan_timer
);
529 del_timer_sync(&wil
->p2p
.discovery_timer
);
530 cancel_work_sync(&wil
->disconnect_worker
);
531 cancel_work_sync(&wil
->fw_error_worker
);
532 cancel_work_sync(&wil
->p2p
.discovery_expired_work
);
533 mutex_lock(&wil
->mutex
);
534 wil6210_disconnect(wil
, NULL
, WLAN_REASON_DEAUTH_LEAVING
, false);
535 mutex_unlock(&wil
->mutex
);
536 wmi_event_flush(wil
);
537 wil_probe_client_flush(wil
);
538 cancel_work_sync(&wil
->probe_client_worker
);
539 destroy_workqueue(wil
->wq_service
);
540 destroy_workqueue(wil
->wmi_wq
);
543 static inline void wil_halt_cpu(struct wil6210_priv
*wil
)
545 wil_w(wil
, RGF_USER_USER_CPU_0
, BIT_USER_USER_CPU_MAN_RST
);
546 wil_w(wil
, RGF_USER_MAC_CPU_0
, BIT_USER_MAC_CPU_MAN_RST
);
549 static inline void wil_release_cpu(struct wil6210_priv
*wil
)
552 wil_w(wil
, RGF_USER_USER_CPU_0
, 1);
555 static void wil_set_oob_mode(struct wil6210_priv
*wil
, bool enable
)
557 wil_info(wil
, "%s: enable=%d\n", __func__
, enable
);
559 wil_s(wil
, RGF_USER_USAGE_6
, BIT_USER_OOB_MODE
);
561 wil_c(wil
, RGF_USER_USAGE_6
, BIT_USER_OOB_MODE
);
565 static int wil_target_reset(struct wil6210_priv
*wil
)
570 wil_dbg_misc(wil
, "Resetting \"%s\"...\n", wil
->hw_name
);
572 /* Clear MAC link up */
573 wil_s(wil
, RGF_HP_CTRL
, BIT(15));
574 wil_s(wil
, RGF_USER_CLKS_CTL_SW_RST_MASK_0
, BIT_HPAL_PERST_FROM_PAD
);
575 wil_s(wil
, RGF_USER_CLKS_CTL_SW_RST_MASK_0
, BIT_CAR_PERST_RST
);
579 /* clear all boot loader "ready" bits */
580 wil_w(wil
, RGF_USER_BL
+
581 offsetof(struct bl_dedicated_registers_v0
, boot_loader_ready
), 0);
582 /* Clear Fw Download notification */
583 wil_c(wil
, RGF_USER_USAGE_6
, BIT(0));
585 wil_s(wil
, RGF_CAF_OSC_CONTROL
, BIT_CAF_OSC_XTAL_EN
);
586 /* XTAL stabilization should take about 3ms */
587 usleep_range(5000, 7000);
588 x
= wil_r(wil
, RGF_CAF_PLL_LOCK_STATUS
);
589 if (!(x
& BIT_CAF_OSC_DIG_XTAL_STABLE
)) {
590 wil_err(wil
, "Xtal stabilization timeout\n"
591 "RGF_CAF_PLL_LOCK_STATUS = 0x%08x\n", x
);
594 /* switch 10k to XTAL*/
595 wil_c(wil
, RGF_USER_SPARROW_M_4
, BIT_SPARROW_M_4_SEL_SLEEP_OR_REF
);
597 wil_c(wil
, RGF_USER_CLKS_CTL_0
, BIT_USER_CLKS_CAR_AHB_SW_SEL
);
599 wil_w(wil
, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0
, 0x3ff81f);
600 wil_w(wil
, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1
, 0xf);
602 wil_w(wil
, RGF_USER_CLKS_CTL_SW_RST_VEC_2
, 0xFE000000);
603 wil_w(wil
, RGF_USER_CLKS_CTL_SW_RST_VEC_1
, 0x0000003F);
604 wil_w(wil
, RGF_USER_CLKS_CTL_SW_RST_VEC_3
, 0x000000f0);
605 wil_w(wil
, RGF_USER_CLKS_CTL_SW_RST_VEC_0
, 0xFFE7FE00);
607 wil_w(wil
, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0
, 0x0);
608 wil_w(wil
, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1
, 0x0);
610 wil_w(wil
, RGF_USER_CLKS_CTL_SW_RST_VEC_3
, 0);
611 wil_w(wil
, RGF_USER_CLKS_CTL_SW_RST_VEC_2
, 0);
612 wil_w(wil
, RGF_USER_CLKS_CTL_SW_RST_VEC_1
, 0);
613 wil_w(wil
, RGF_USER_CLKS_CTL_SW_RST_VEC_0
, 0);
615 wil_w(wil
, RGF_USER_CLKS_CTL_SW_RST_VEC_3
, 0x00000003);
616 /* reset A2 PCIE AHB */
617 wil_w(wil
, RGF_USER_CLKS_CTL_SW_RST_VEC_2
, 0x00008000);
619 wil_w(wil
, RGF_USER_CLKS_CTL_SW_RST_VEC_0
, 0);
621 /* wait until device ready. typical time is 20..80 msec */
624 x
= wil_r(wil
, RGF_USER_BL
+
625 offsetof(struct bl_dedicated_registers_v0
,
628 wil_dbg_misc(wil
, "BL.ready 0x%08x => 0x%08x\n", x1
, x
);
631 if (delay
++ > RST_COUNT
) {
632 wil_err(wil
, "Reset not completed, bl.ready 0x%08x\n",
636 } while (x
!= BL_READY
);
638 wil_c(wil
, RGF_USER_CLKS_CTL_0
, BIT_USER_CLKS_RST_PWGD
);
640 /* enable fix for HW bug related to the SA/DA swap in AP Rx */
641 wil_s(wil
, RGF_DMA_OFUL_NID_0
, BIT_DMA_OFUL_NID_0_RX_EXT_TR_EN
|
642 BIT_DMA_OFUL_NID_0_RX_EXT_A3_SRC
);
644 wil_dbg_misc(wil
, "Reset completed in %d ms\n", delay
* RST_DELAY
);
648 void wil_mbox_ring_le2cpus(struct wil6210_mbox_ring
*r
)
650 le32_to_cpus(&r
->base
);
651 le16_to_cpus(&r
->entry_size
);
652 le16_to_cpus(&r
->size
);
653 le32_to_cpus(&r
->tail
);
654 le32_to_cpus(&r
->head
);
657 static int wil_get_bl_info(struct wil6210_priv
*wil
)
659 struct net_device
*ndev
= wil_to_ndev(wil
);
660 struct wiphy
*wiphy
= wil_to_wiphy(wil
);
662 struct bl_dedicated_registers_v0 bl0
;
663 struct bl_dedicated_registers_v1 bl1
;
669 wil_memcpy_fromio_32(&bl
, wil
->csr
+ HOSTADDR(RGF_USER_BL
),
671 bl_ver
= le32_to_cpu(bl
.bl0
.boot_loader_struct_version
);
672 mac
= bl
.bl0
.mac_address
;
675 le32_to_cpus(&bl
.bl0
.rf_type
);
676 le32_to_cpus(&bl
.bl0
.baseband_type
);
677 rf_status
= 0; /* actually, unknown */
679 "Boot Loader struct v%d: MAC = %pM RF = 0x%08x bband = 0x%08x\n",
681 bl
.bl0
.rf_type
, bl
.bl0
.baseband_type
);
682 wil_info(wil
, "Boot Loader build unknown for struct v0\n");
684 le16_to_cpus(&bl
.bl1
.rf_type
);
685 rf_status
= le16_to_cpu(bl
.bl1
.rf_status
);
686 le32_to_cpus(&bl
.bl1
.baseband_type
);
687 le16_to_cpus(&bl
.bl1
.bl_version_subminor
);
688 le16_to_cpus(&bl
.bl1
.bl_version_build
);
690 "Boot Loader struct v%d: MAC = %pM RF = 0x%04x (status 0x%04x) bband = 0x%08x\n",
692 bl
.bl1
.rf_type
, rf_status
,
693 bl
.bl1
.baseband_type
);
694 wil_info(wil
, "Boot Loader build %d.%d.%d.%d\n",
695 bl
.bl1
.bl_version_major
, bl
.bl1
.bl_version_minor
,
696 bl
.bl1
.bl_version_subminor
, bl
.bl1
.bl_version_build
);
699 if (!is_valid_ether_addr(mac
)) {
700 wil_err(wil
, "BL: Invalid MAC %pM\n", mac
);
704 ether_addr_copy(ndev
->perm_addr
, mac
);
705 ether_addr_copy(wiphy
->perm_addr
, mac
);
706 if (!is_valid_ether_addr(ndev
->dev_addr
))
707 ether_addr_copy(ndev
->dev_addr
, mac
);
709 if (rf_status
) {/* bad RF cable? */
710 wil_err(wil
, "RF communication error 0x%04x",
718 static void wil_bl_crash_info(struct wil6210_priv
*wil
, bool is_err
)
720 u32 bl_assert_code
, bl_assert_blink
, bl_magic_number
;
721 u32 bl_ver
= wil_r(wil
, RGF_USER_BL
+
722 offsetof(struct bl_dedicated_registers_v0
,
723 boot_loader_struct_version
));
728 bl_assert_code
= wil_r(wil
, RGF_USER_BL
+
729 offsetof(struct bl_dedicated_registers_v1
,
731 bl_assert_blink
= wil_r(wil
, RGF_USER_BL
+
732 offsetof(struct bl_dedicated_registers_v1
,
734 bl_magic_number
= wil_r(wil
, RGF_USER_BL
+
735 offsetof(struct bl_dedicated_registers_v1
,
740 "BL assert code 0x%08x blink 0x%08x magic 0x%08x\n",
741 bl_assert_code
, bl_assert_blink
, bl_magic_number
);
744 "BL assert code 0x%08x blink 0x%08x magic 0x%08x\n",
745 bl_assert_code
, bl_assert_blink
, bl_magic_number
);
749 static int wil_wait_for_fw_ready(struct wil6210_priv
*wil
)
751 ulong to
= msecs_to_jiffies(1000);
752 ulong left
= wait_for_completion_timeout(&wil
->wmi_ready
, to
);
755 wil_err(wil
, "Firmware not ready\n");
758 wil_info(wil
, "FW ready after %d ms. HW version 0x%08x\n",
759 jiffies_to_msecs(to
-left
), wil
->hw_version
);
765 * We reset all the structures, and we reset the UMAC.
766 * After calling this routine, you're expected to reload
769 int wil_reset(struct wil6210_priv
*wil
, bool load_fw
)
773 wil_dbg_misc(wil
, "%s()\n", __func__
);
775 WARN_ON(!mutex_is_locked(&wil
->mutex
));
776 WARN_ON(test_bit(wil_status_napi_en
, wil
->status
));
779 static const u8 mac
[ETH_ALEN
] = {
780 0x00, 0xde, 0xad, 0x12, 0x34, 0x56,
782 struct net_device
*ndev
= wil_to_ndev(wil
);
784 ether_addr_copy(ndev
->perm_addr
, mac
);
785 ether_addr_copy(ndev
->dev_addr
, ndev
->perm_addr
);
789 if (wil
->hw_version
== HW_VER_UNKNOWN
)
792 if (wil
->platform_ops
.notify
) {
793 rc
= wil
->platform_ops
.notify(wil
->platform_handle
,
794 WIL_PLATFORM_EVT_PRE_RESET
);
797 "%s: PRE_RESET platform notify failed, rc %d\n",
801 set_bit(wil_status_resetting
, wil
->status
);
803 cancel_work_sync(&wil
->disconnect_worker
);
804 wil6210_disconnect(wil
, NULL
, WLAN_REASON_DEAUTH_LEAVING
, false);
807 /* prevent NAPI from being scheduled and prevent wmi commands */
808 mutex_lock(&wil
->wmi_mutex
);
809 bitmap_zero(wil
->status
, wil_status_last
);
810 mutex_unlock(&wil
->wmi_mutex
);
812 if (wil
->scan_request
) {
813 wil_dbg_misc(wil
, "Abort scan_request 0x%p\n",
815 del_timer_sync(&wil
->scan_timer
);
816 cfg80211_scan_done(wil
->scan_request
, true);
817 wil
->scan_request
= NULL
;
822 wmi_event_flush(wil
);
824 flush_workqueue(wil
->wq_service
);
825 flush_workqueue(wil
->wmi_wq
);
827 wil_bl_crash_info(wil
, false);
828 rc
= wil_target_reset(wil
);
831 wil_bl_crash_info(wil
, true);
835 rc
= wil_get_bl_info(wil
);
836 if (rc
== -EAGAIN
&& !load_fw
) /* ignore RF error if not going up */
841 wil_set_oob_mode(wil
, oob_mode
);
843 wil_info(wil
, "Use firmware <%s> + board <%s>\n", WIL_FW_NAME
,
847 /* Loading f/w from the file */
848 rc
= wil_request_firmware(wil
, WIL_FW_NAME
);
851 rc
= wil_request_firmware(wil
, WIL_FW2_NAME
);
855 /* Mark FW as loaded from host */
856 wil_s(wil
, RGF_USER_USAGE_6
, 1);
858 /* clear any interrupts which on-card-firmware
861 wil6210_clear_irq(wil
);
862 /* CAF_ICR - clear and mask */
863 /* it is W1C, clear by writing back same value */
864 wil_s(wil
, RGF_CAF_ICR
+ offsetof(struct RGF_ICR
, ICR
), 0);
865 wil_w(wil
, RGF_CAF_ICR
+ offsetof(struct RGF_ICR
, IMV
), ~0);
867 wil_release_cpu(wil
);
870 /* init after reset */
872 reinit_completion(&wil
->wmi_ready
);
873 reinit_completion(&wil
->wmi_call
);
876 wil_configure_interrupt_moderation(wil
);
879 /* we just started MAC, wait for FW ready */
880 rc
= wil_wait_for_fw_ready(wil
);
884 /* check FW is responsive */
887 wil_err(wil
, "%s: wmi_echo failed, rc %d\n",
892 if (wil
->platform_ops
.notify
) {
893 rc
= wil
->platform_ops
.notify(wil
->platform_handle
,
894 WIL_PLATFORM_EVT_FW_RDY
);
897 "%s: FW_RDY notify failed, rc %d\n",
907 void wil_fw_error_recovery(struct wil6210_priv
*wil
)
909 wil_dbg_misc(wil
, "starting fw error recovery\n");
911 if (test_bit(wil_status_resetting
, wil
->status
)) {
912 wil_info(wil
, "Reset already in progress\n");
916 wil
->recovery_state
= fw_recovery_pending
;
917 schedule_work(&wil
->fw_error_worker
);
920 int __wil_up(struct wil6210_priv
*wil
)
922 struct net_device
*ndev
= wil_to_ndev(wil
);
923 struct wireless_dev
*wdev
= wil
->wdev
;
926 WARN_ON(!mutex_is_locked(&wil
->mutex
));
928 rc
= wil_reset(wil
, true);
932 /* Rx VRING. After MAC and beacon */
933 rc
= wil_rx_init(wil
, 1 << rx_ring_order
);
937 switch (wdev
->iftype
) {
938 case NL80211_IFTYPE_STATION
:
939 wil_dbg_misc(wil
, "type: STATION\n");
940 ndev
->type
= ARPHRD_ETHER
;
942 case NL80211_IFTYPE_AP
:
943 wil_dbg_misc(wil
, "type: AP\n");
944 ndev
->type
= ARPHRD_ETHER
;
946 case NL80211_IFTYPE_P2P_CLIENT
:
947 wil_dbg_misc(wil
, "type: P2P_CLIENT\n");
948 ndev
->type
= ARPHRD_ETHER
;
950 case NL80211_IFTYPE_P2P_GO
:
951 wil_dbg_misc(wil
, "type: P2P_GO\n");
952 ndev
->type
= ARPHRD_ETHER
;
954 case NL80211_IFTYPE_MONITOR
:
955 wil_dbg_misc(wil
, "type: Monitor\n");
956 ndev
->type
= ARPHRD_IEEE80211_RADIOTAP
;
957 /* ARPHRD_IEEE80211 or ARPHRD_IEEE80211_RADIOTAP ? */
963 /* MAC address - pre-requisite for other commands */
964 wmi_set_mac_address(wil
, ndev
->dev_addr
);
966 wil_dbg_misc(wil
, "NAPI enable\n");
967 napi_enable(&wil
->napi_rx
);
968 napi_enable(&wil
->napi_tx
);
969 set_bit(wil_status_napi_en
, wil
->status
);
971 if (wil
->platform_ops
.bus_request
)
972 wil
->platform_ops
.bus_request(wil
->platform_handle
,
973 WIL_MAX_BUS_REQUEST_KBPS
);
978 int wil_up(struct wil6210_priv
*wil
)
982 wil_dbg_misc(wil
, "%s()\n", __func__
);
984 mutex_lock(&wil
->mutex
);
986 mutex_unlock(&wil
->mutex
);
991 int __wil_down(struct wil6210_priv
*wil
)
995 WARN_ON(!mutex_is_locked(&wil
->mutex
));
997 if (wil
->platform_ops
.bus_request
)
998 wil
->platform_ops
.bus_request(wil
->platform_handle
, 0);
1000 wil_disable_irq(wil
);
1001 if (test_and_clear_bit(wil_status_napi_en
, wil
->status
)) {
1002 napi_disable(&wil
->napi_rx
);
1003 napi_disable(&wil
->napi_tx
);
1004 wil_dbg_misc(wil
, "NAPI disable\n");
1006 wil_enable_irq(wil
);
1008 (void)wil_p2p_stop_discovery(wil
);
1010 if (wil
->scan_request
) {
1011 wil_dbg_misc(wil
, "Abort scan_request 0x%p\n",
1013 del_timer_sync(&wil
->scan_timer
);
1014 cfg80211_scan_done(wil
->scan_request
, true);
1015 wil
->scan_request
= NULL
;
1018 if (test_bit(wil_status_fwconnected
, wil
->status
) ||
1019 test_bit(wil_status_fwconnecting
, wil
->status
)) {
1021 mutex_unlock(&wil
->mutex
);
1022 rc
= wmi_call(wil
, WMI_DISCONNECT_CMDID
, NULL
, 0,
1023 WMI_DISCONNECT_EVENTID
, NULL
, 0,
1024 WIL6210_DISCONNECT_TO_MS
);
1025 mutex_lock(&wil
->mutex
);
1027 wil_err(wil
, "timeout waiting for disconnect\n");
1030 wil_reset(wil
, false);
1035 int wil_down(struct wil6210_priv
*wil
)
1039 wil_dbg_misc(wil
, "%s()\n", __func__
);
1041 wil_set_recovery_state(wil
, fw_recovery_idle
);
1042 mutex_lock(&wil
->mutex
);
1043 rc
= __wil_down(wil
);
1044 mutex_unlock(&wil
->mutex
);
1049 int wil_find_cid(struct wil6210_priv
*wil
, const u8
*mac
)
1054 for (i
= 0; i
< ARRAY_SIZE(wil
->sta
); i
++) {
1055 if ((wil
->sta
[i
].status
!= wil_sta_unused
) &&
1056 ether_addr_equal(wil
->sta
[i
].addr
, mac
)) {