2 * Copyright (c) 2012-2015 Qualcomm Atheros, Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <linux/moduleparam.h>
18 #include <linux/if_arp.h>
19 #include <linux/etherdevice.h>
25 #define WAIT_FOR_DISCONNECT_TIMEOUT_MS 2000
26 #define WAIT_FOR_DISCONNECT_INTERVAL_MS 10
29 module_param(no_fw_recovery
, bool, S_IRUGO
| S_IWUSR
);
30 MODULE_PARM_DESC(no_fw_recovery
, " disable automatic FW error recovery");
32 /* if not set via modparam, will be set to default value of 1/8 of
33 * rx ring size during init flow
35 unsigned short rx_ring_overflow_thrsh
= WIL6210_RX_HIGH_TRSH_INIT
;
36 module_param(rx_ring_overflow_thrsh
, ushort
, S_IRUGO
);
37 MODULE_PARM_DESC(rx_ring_overflow_thrsh
,
38 " RX ring overflow threshold in descriptors.");
40 /* We allow allocation of more than 1 page buffers to support large packets.
41 * It is suboptimal behavior performance wise in case MTU above page size.
43 unsigned int mtu_max
= TXRX_BUF_LEN_DEFAULT
- WIL_MAX_MPDU_OVERHEAD
;
44 static int mtu_max_set(const char *val
, const struct kernel_param
*kp
)
48 /* sets mtu_max directly. no need to restore it in case of
49 * illegal value since we assume this will fail insmod
51 ret
= param_set_uint(val
, kp
);
55 if (mtu_max
< 68 || mtu_max
> WIL_MAX_ETH_MTU
)
61 static struct kernel_param_ops mtu_max_ops
= {
63 .get
= param_get_uint
,
66 module_param_cb(mtu_max
, &mtu_max_ops
, &mtu_max
, S_IRUGO
);
67 MODULE_PARM_DESC(mtu_max
, " Max MTU value.");
69 static uint rx_ring_order
= WIL_RX_RING_SIZE_ORDER_DEFAULT
;
70 static uint tx_ring_order
= WIL_TX_RING_SIZE_ORDER_DEFAULT
;
71 static uint bcast_ring_order
= WIL_BCAST_RING_SIZE_ORDER_DEFAULT
;
73 static int ring_order_set(const char *val
, const struct kernel_param
*kp
)
78 ret
= kstrtouint(val
, 0, &x
);
82 if ((x
< WIL_RING_SIZE_ORDER_MIN
) || (x
> WIL_RING_SIZE_ORDER_MAX
))
85 *((uint
*)kp
->arg
) = x
;
90 static struct kernel_param_ops ring_order_ops
= {
91 .set
= ring_order_set
,
92 .get
= param_get_uint
,
95 module_param_cb(rx_ring_order
, &ring_order_ops
, &rx_ring_order
, S_IRUGO
);
96 MODULE_PARM_DESC(rx_ring_order
, " Rx ring order; size = 1 << order");
97 module_param_cb(tx_ring_order
, &ring_order_ops
, &tx_ring_order
, S_IRUGO
);
98 MODULE_PARM_DESC(tx_ring_order
, " Tx ring order; size = 1 << order");
100 #define RST_DELAY (20) /* msec, for loop in @wil_target_reset */
101 #define RST_COUNT (1 + 1000/RST_DELAY) /* round up to be above 1 sec total */
104 * Due to a hardware issue,
105 * one has to read/write to/from NIC in 32-bit chunks;
106 * regular memcpy_fromio and siblings will
107 * not work on 64-bit platform - it uses 64-bit transactions
109 * Force 32-bit transactions to enable NIC on 64-bit platforms
111 * To avoid byte swap on big endian host, __raw_{read|write}l
112 * should be used - {read|write}l would swap bytes to provide
113 * little endian on PCI value in host endianness.
115 void wil_memcpy_fromio_32(void *dst
, const volatile void __iomem
*src
,
119 const volatile u32 __iomem
*s
= src
;
121 /* size_t is unsigned, if (count%4 != 0) it will wrap */
122 for (count
+= 4; count
> 4; count
-= 4)
123 *d
++ = __raw_readl(s
++);
126 void wil_memcpy_toio_32(volatile void __iomem
*dst
, const void *src
,
129 volatile u32 __iomem
*d
= dst
;
132 for (count
+= 4; count
> 4; count
-= 4)
133 __raw_writel(*s
++, d
++);
136 static void wil_disconnect_cid(struct wil6210_priv
*wil
, int cid
,
137 u16 reason_code
, bool from_event
)
138 __acquires(&sta
->tid_rx_lock
) __releases(&sta
->tid_rx_lock
)
141 struct net_device
*ndev
= wil_to_ndev(wil
);
142 struct wireless_dev
*wdev
= wil
->wdev
;
143 struct wil_sta_info
*sta
= &wil
->sta
[cid
];
146 wil_dbg_misc(wil
, "%s(CID %d, status %d)\n", __func__
, cid
,
149 sta
->data_port_open
= false;
150 if (sta
->status
!= wil_sta_unused
) {
152 wmi_disconnect_sta(wil
, sta
->addr
, reason_code
);
154 switch (wdev
->iftype
) {
155 case NL80211_IFTYPE_AP
:
156 case NL80211_IFTYPE_P2P_GO
:
157 /* AP-like interface */
158 cfg80211_del_sta(ndev
, sta
->addr
, GFP_KERNEL
);
163 sta
->status
= wil_sta_unused
;
166 for (i
= 0; i
< WIL_STA_TID_NUM
; i
++) {
167 struct wil_tid_ampdu_rx
*r
;
169 spin_lock_bh(&sta
->tid_rx_lock
);
172 sta
->tid_rx
[i
] = NULL
;
173 wil_tid_ampdu_rx_free(wil
, r
);
175 spin_unlock_bh(&sta
->tid_rx_lock
);
177 for (i
= 0; i
< ARRAY_SIZE(wil
->vring_tx
); i
++) {
178 if (wil
->vring2cid_tid
[i
][0] == cid
)
179 wil_vring_fini_tx(wil
, i
);
181 memset(&sta
->stats
, 0, sizeof(sta
->stats
));
184 static void _wil6210_disconnect(struct wil6210_priv
*wil
, const u8
*bssid
,
185 u16 reason_code
, bool from_event
)
188 struct net_device
*ndev
= wil_to_ndev(wil
);
189 struct wireless_dev
*wdev
= wil
->wdev
;
192 wil_dbg_misc(wil
, "%s(bssid=%pM, reason=%d, ev%s)\n", __func__
, bssid
,
193 reason_code
, from_event
? "+" : "-");
196 * - disconnect single STA, still connected
197 * - disconnect single STA, already disconnected
200 * For "disconnect all", there are 2 options:
202 * - bssid is our MAC address
204 if (bssid
&& memcmp(ndev
->dev_addr
, bssid
, ETH_ALEN
)) {
205 cid
= wil_find_cid(wil
, bssid
);
206 wil_dbg_misc(wil
, "Disconnect %pM, CID=%d, reason=%d\n",
207 bssid
, cid
, reason_code
);
208 if (cid
>= 0) /* disconnect 1 peer */
209 wil_disconnect_cid(wil
, cid
, reason_code
, from_event
);
211 wil_dbg_misc(wil
, "Disconnect all\n");
212 for (cid
= 0; cid
< WIL6210_MAX_CID
; cid
++)
213 wil_disconnect_cid(wil
, cid
, reason_code
, from_event
);
217 switch (wdev
->iftype
) {
218 case NL80211_IFTYPE_STATION
:
219 case NL80211_IFTYPE_P2P_CLIENT
:
221 netif_tx_stop_all_queues(ndev
);
222 netif_carrier_off(ndev
);
224 if (test_bit(wil_status_fwconnected
, wil
->status
)) {
225 clear_bit(wil_status_fwconnected
, wil
->status
);
226 cfg80211_disconnected(ndev
, reason_code
,
227 NULL
, 0, GFP_KERNEL
);
228 } else if (test_bit(wil_status_fwconnecting
, wil
->status
)) {
229 cfg80211_connect_result(ndev
, bssid
, NULL
, 0, NULL
, 0,
230 WLAN_STATUS_UNSPECIFIED_FAILURE
,
233 clear_bit(wil_status_fwconnecting
, wil
->status
);
240 static void wil_disconnect_worker(struct work_struct
*work
)
242 struct wil6210_priv
*wil
= container_of(work
,
243 struct wil6210_priv
, disconnect_worker
);
245 mutex_lock(&wil
->mutex
);
246 _wil6210_disconnect(wil
, NULL
, WLAN_REASON_UNSPECIFIED
, false);
247 mutex_unlock(&wil
->mutex
);
250 static void wil_connect_timer_fn(ulong x
)
252 struct wil6210_priv
*wil
= (void *)x
;
254 wil_dbg_misc(wil
, "Connect timeout\n");
256 /* reschedule to thread context - disconnect won't
257 * run from atomic context
259 schedule_work(&wil
->disconnect_worker
);
262 static void wil_scan_timer_fn(ulong x
)
264 struct wil6210_priv
*wil
= (void *)x
;
266 clear_bit(wil_status_fwready
, wil
->status
);
267 wil_err(wil
, "Scan timeout detected, start fw error recovery\n");
268 wil
->recovery_state
= fw_recovery_pending
;
269 schedule_work(&wil
->fw_error_worker
);
272 static int wil_wait_for_recovery(struct wil6210_priv
*wil
)
274 if (wait_event_interruptible(wil
->wq
, wil
->recovery_state
!=
275 fw_recovery_pending
)) {
276 wil_err(wil
, "Interrupt, canceling recovery\n");
279 if (wil
->recovery_state
!= fw_recovery_running
) {
280 wil_info(wil
, "Recovery cancelled\n");
283 wil_info(wil
, "Proceed with recovery\n");
287 void wil_set_recovery_state(struct wil6210_priv
*wil
, int state
)
289 wil_dbg_misc(wil
, "%s(%d -> %d)\n", __func__
,
290 wil
->recovery_state
, state
);
292 wil
->recovery_state
= state
;
293 wake_up_interruptible(&wil
->wq
);
296 static void wil_fw_error_worker(struct work_struct
*work
)
298 struct wil6210_priv
*wil
= container_of(work
, struct wil6210_priv
,
300 struct wireless_dev
*wdev
= wil
->wdev
;
302 wil_dbg_misc(wil
, "fw error worker\n");
304 if (!netif_running(wil_to_ndev(wil
))) {
305 wil_info(wil
, "No recovery - interface is down\n");
309 /* increment @recovery_count if less then WIL6210_FW_RECOVERY_TO
310 * passed since last recovery attempt
312 if (time_is_after_jiffies(wil
->last_fw_recovery
+
313 WIL6210_FW_RECOVERY_TO
))
314 wil
->recovery_count
++;
316 wil
->recovery_count
= 1; /* fw was alive for a long time */
318 if (wil
->recovery_count
> WIL6210_FW_RECOVERY_RETRIES
) {
319 wil_err(wil
, "too many recovery attempts (%d), giving up\n",
320 wil
->recovery_count
);
324 wil
->last_fw_recovery
= jiffies
;
326 mutex_lock(&wil
->mutex
);
327 switch (wdev
->iftype
) {
328 case NL80211_IFTYPE_STATION
:
329 case NL80211_IFTYPE_P2P_CLIENT
:
330 case NL80211_IFTYPE_MONITOR
:
331 wil_info(wil
, "fw error recovery requested (try %d)...\n",
332 wil
->recovery_count
);
334 wil
->recovery_state
= fw_recovery_running
;
335 if (0 != wil_wait_for_recovery(wil
))
341 case NL80211_IFTYPE_AP
:
342 case NL80211_IFTYPE_P2P_GO
:
343 wil_info(wil
, "No recovery for AP-like interface\n");
344 /* recovery in these modes is done by upper layers */
347 wil_err(wil
, "No recovery - unknown interface type %d\n",
351 mutex_unlock(&wil
->mutex
);
354 static int wil_find_free_vring(struct wil6210_priv
*wil
)
358 for (i
= 0; i
< WIL6210_MAX_TX_RINGS
; i
++) {
359 if (!wil
->vring_tx
[i
].va
)
365 int wil_bcast_init(struct wil6210_priv
*wil
)
367 int ri
= wil
->bcast_vring
, rc
;
369 if ((ri
>= 0) && wil
->vring_tx
[ri
].va
)
372 ri
= wil_find_free_vring(wil
);
376 rc
= wil_vring_init_bcast(wil
, ri
, 1 << bcast_ring_order
);
378 wil
->bcast_vring
= ri
;
383 void wil_bcast_fini(struct wil6210_priv
*wil
)
385 int ri
= wil
->bcast_vring
;
390 wil
->bcast_vring
= -1;
391 wil_vring_fini_tx(wil
, ri
);
394 static void wil_connect_worker(struct work_struct
*work
)
397 struct wil6210_priv
*wil
= container_of(work
, struct wil6210_priv
,
399 struct net_device
*ndev
= wil_to_ndev(wil
);
401 int cid
= wil
->pending_connect_cid
;
402 int ringid
= wil_find_free_vring(wil
);
405 wil_err(wil
, "No connection pending\n");
409 wil_dbg_wmi(wil
, "Configure for connection CID %d\n", cid
);
411 rc
= wil_vring_init_tx(wil
, ringid
, 1 << tx_ring_order
, cid
, 0);
412 wil
->pending_connect_cid
= -1;
414 wil
->sta
[cid
].status
= wil_sta_connected
;
415 netif_tx_wake_all_queues(ndev
);
417 wil
->sta
[cid
].status
= wil_sta_unused
;
421 int wil_priv_init(struct wil6210_priv
*wil
)
425 wil_dbg_misc(wil
, "%s()\n", __func__
);
427 memset(wil
->sta
, 0, sizeof(wil
->sta
));
428 for (i
= 0; i
< WIL6210_MAX_CID
; i
++)
429 spin_lock_init(&wil
->sta
[i
].tid_rx_lock
);
431 mutex_init(&wil
->mutex
);
432 mutex_init(&wil
->wmi_mutex
);
433 mutex_init(&wil
->back_rx_mutex
);
434 mutex_init(&wil
->back_tx_mutex
);
435 mutex_init(&wil
->probe_client_mutex
);
437 init_completion(&wil
->wmi_ready
);
438 init_completion(&wil
->wmi_call
);
440 wil
->pending_connect_cid
= -1;
441 wil
->bcast_vring
= -1;
442 setup_timer(&wil
->connect_timer
, wil_connect_timer_fn
, (ulong
)wil
);
443 setup_timer(&wil
->scan_timer
, wil_scan_timer_fn
, (ulong
)wil
);
445 INIT_WORK(&wil
->connect_worker
, wil_connect_worker
);
446 INIT_WORK(&wil
->disconnect_worker
, wil_disconnect_worker
);
447 INIT_WORK(&wil
->wmi_event_worker
, wmi_event_worker
);
448 INIT_WORK(&wil
->fw_error_worker
, wil_fw_error_worker
);
449 INIT_WORK(&wil
->back_rx_worker
, wil_back_rx_worker
);
450 INIT_WORK(&wil
->back_tx_worker
, wil_back_tx_worker
);
451 INIT_WORK(&wil
->probe_client_worker
, wil_probe_client_worker
);
453 INIT_LIST_HEAD(&wil
->pending_wmi_ev
);
454 INIT_LIST_HEAD(&wil
->back_rx_pending
);
455 INIT_LIST_HEAD(&wil
->back_tx_pending
);
456 INIT_LIST_HEAD(&wil
->probe_client_pending
);
457 spin_lock_init(&wil
->wmi_ev_lock
);
458 init_waitqueue_head(&wil
->wq
);
460 wil
->wmi_wq
= create_singlethread_workqueue(WIL_NAME
"_wmi");
464 wil
->wq_service
= create_singlethread_workqueue(WIL_NAME
"_service");
465 if (!wil
->wq_service
)
468 wil
->last_fw_recovery
= jiffies
;
469 wil
->tx_interframe_timeout
= WIL6210_ITR_TX_INTERFRAME_TIMEOUT_DEFAULT
;
470 wil
->rx_interframe_timeout
= WIL6210_ITR_RX_INTERFRAME_TIMEOUT_DEFAULT
;
471 wil
->tx_max_burst_duration
= WIL6210_ITR_TX_MAX_BURST_DURATION_DEFAULT
;
472 wil
->rx_max_burst_duration
= WIL6210_ITR_RX_MAX_BURST_DURATION_DEFAULT
;
474 if (rx_ring_overflow_thrsh
== WIL6210_RX_HIGH_TRSH_INIT
)
475 rx_ring_overflow_thrsh
= WIL6210_RX_HIGH_TRSH_DEFAULT
;
479 destroy_workqueue(wil
->wmi_wq
);
485 * wil6210_disconnect - disconnect one connection
486 * @wil: driver context
487 * @bssid: peer to disconnect, NULL to disconnect all
488 * @reason_code: Reason code for the Disassociation frame
489 * @from_event: whether is invoked from FW event handler
491 * Disconnect and release associated resources. If invoked not from the
492 * FW event handler, issue WMI command(s) to trigger MAC disconnect.
494 void wil6210_disconnect(struct wil6210_priv
*wil
, const u8
*bssid
,
495 u16 reason_code
, bool from_event
)
497 wil_dbg_misc(wil
, "%s()\n", __func__
);
499 del_timer_sync(&wil
->connect_timer
);
500 _wil6210_disconnect(wil
, bssid
, reason_code
, from_event
);
503 void wil_priv_deinit(struct wil6210_priv
*wil
)
505 wil_dbg_misc(wil
, "%s()\n", __func__
);
507 wil_set_recovery_state(wil
, fw_recovery_idle
);
508 del_timer_sync(&wil
->scan_timer
);
509 cancel_work_sync(&wil
->disconnect_worker
);
510 cancel_work_sync(&wil
->fw_error_worker
);
511 mutex_lock(&wil
->mutex
);
512 wil6210_disconnect(wil
, NULL
, WLAN_REASON_DEAUTH_LEAVING
, false);
513 mutex_unlock(&wil
->mutex
);
514 wmi_event_flush(wil
);
515 wil_back_rx_flush(wil
);
516 cancel_work_sync(&wil
->back_rx_worker
);
517 wil_back_tx_flush(wil
);
518 cancel_work_sync(&wil
->back_tx_worker
);
519 wil_probe_client_flush(wil
);
520 cancel_work_sync(&wil
->probe_client_worker
);
521 destroy_workqueue(wil
->wq_service
);
522 destroy_workqueue(wil
->wmi_wq
);
525 /* target operations */
527 #define R(a) ioread32(wil->csr + HOSTADDR(a))
528 /* register write. wmb() to make sure it is completed */
529 #define W(a, v) do { iowrite32(v, wil->csr + HOSTADDR(a)); wmb(); } while (0)
530 /* register set = read, OR, write */
531 #define S(a, v) W(a, R(a) | v)
532 /* register clear = read, AND with inverted, write */
533 #define C(a, v) W(a, R(a) & ~v)
535 static inline void wil_halt_cpu(struct wil6210_priv
*wil
)
537 W(RGF_USER_USER_CPU_0
, BIT_USER_USER_CPU_MAN_RST
);
538 W(RGF_USER_MAC_CPU_0
, BIT_USER_MAC_CPU_MAN_RST
);
541 static inline void wil_release_cpu(struct wil6210_priv
*wil
)
544 W(RGF_USER_USER_CPU_0
, 1);
547 static int wil_target_reset(struct wil6210_priv
*wil
)
552 wil_dbg_misc(wil
, "Resetting \"%s\"...\n", wil
->hw_name
);
554 /* Clear MAC link up */
555 S(RGF_HP_CTRL
, BIT(15));
556 S(RGF_USER_CLKS_CTL_SW_RST_MASK_0
, BIT_HPAL_PERST_FROM_PAD
);
557 S(RGF_USER_CLKS_CTL_SW_RST_MASK_0
, BIT_CAR_PERST_RST
);
561 /* clear all boot loader "ready" bits */
562 W(RGF_USER_BL
+ offsetof(struct RGF_BL
, ready
), 0);
563 /* Clear Fw Download notification */
564 C(RGF_USER_USAGE_6
, BIT(0));
566 S(RGF_CAF_OSC_CONTROL
, BIT_CAF_OSC_XTAL_EN
);
567 /* XTAL stabilization should take about 3ms */
568 usleep_range(5000, 7000);
569 x
= R(RGF_CAF_PLL_LOCK_STATUS
);
570 if (!(x
& BIT_CAF_OSC_DIG_XTAL_STABLE
)) {
571 wil_err(wil
, "Xtal stabilization timeout\n"
572 "RGF_CAF_PLL_LOCK_STATUS = 0x%08x\n", x
);
575 /* switch 10k to XTAL*/
576 C(RGF_USER_SPARROW_M_4
, BIT_SPARROW_M_4_SEL_SLEEP_OR_REF
);
578 C(RGF_USER_CLKS_CTL_0
, BIT_USER_CLKS_CAR_AHB_SW_SEL
);
580 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0
, 0x3ff81f);
581 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1
, 0xf);
583 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2
, 0xFE000000);
584 W(RGF_USER_CLKS_CTL_SW_RST_VEC_1
, 0x0000003F);
585 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3
, 0x000000f0);
586 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0
, 0xFFE7FE00);
588 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0
, 0x0);
589 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1
, 0x0);
591 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3
, 0);
592 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2
, 0);
593 W(RGF_USER_CLKS_CTL_SW_RST_VEC_1
, 0);
594 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0
, 0);
596 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3
, 0x00000003);
597 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2
, 0x00008000); /* reset A2 PCIE AHB */
599 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0
, 0);
601 /* wait until device ready. typical time is 20..80 msec */
604 x
= R(RGF_USER_BL
+ offsetof(struct RGF_BL
, ready
));
605 if (delay
++ > RST_COUNT
) {
606 wil_err(wil
, "Reset not completed, bl.ready 0x%08x\n",
610 } while (!(x
& BIT_BL_READY
));
612 C(RGF_USER_CLKS_CTL_0
, BIT_USER_CLKS_RST_PWGD
);
614 /* enable fix for HW bug related to the SA/DA swap in AP Rx */
615 S(RGF_DMA_OFUL_NID_0
, BIT_DMA_OFUL_NID_0_RX_EXT_TR_EN
|
616 BIT_DMA_OFUL_NID_0_RX_EXT_A3_SRC
);
618 wil_dbg_misc(wil
, "Reset completed in %d ms\n", delay
* RST_DELAY
);
622 void wil_mbox_ring_le2cpus(struct wil6210_mbox_ring
*r
)
624 le32_to_cpus(&r
->base
);
625 le16_to_cpus(&r
->entry_size
);
626 le16_to_cpus(&r
->size
);
627 le32_to_cpus(&r
->tail
);
628 le32_to_cpus(&r
->head
);
631 static int wil_get_bl_info(struct wil6210_priv
*wil
)
633 struct net_device
*ndev
= wil_to_ndev(wil
);
636 wil_memcpy_fromio_32(&bl
, wil
->csr
+ HOSTADDR(RGF_USER_BL
), sizeof(bl
));
637 le32_to_cpus(&bl
.ready
);
638 le32_to_cpus(&bl
.version
);
639 le32_to_cpus(&bl
.rf_type
);
640 le32_to_cpus(&bl
.baseband_type
);
642 if (!is_valid_ether_addr(bl
.mac_address
)) {
643 wil_err(wil
, "BL: Invalid MAC %pM\n", bl
.mac_address
);
647 ether_addr_copy(ndev
->perm_addr
, bl
.mac_address
);
648 if (!is_valid_ether_addr(ndev
->dev_addr
))
649 ether_addr_copy(ndev
->dev_addr
, bl
.mac_address
);
651 "Boot Loader: ver = %d MAC = %pM RF = 0x%08x bband = 0x%08x\n",
652 bl
.version
, bl
.mac_address
, bl
.rf_type
, bl
.baseband_type
);
657 static int wil_wait_for_fw_ready(struct wil6210_priv
*wil
)
659 ulong to
= msecs_to_jiffies(1000);
660 ulong left
= wait_for_completion_timeout(&wil
->wmi_ready
, to
);
663 wil_err(wil
, "Firmware not ready\n");
666 wil_info(wil
, "FW ready after %d ms. HW version 0x%08x\n",
667 jiffies_to_msecs(to
-left
), wil
->hw_version
);
673 * We reset all the structures, and we reset the UMAC.
674 * After calling this routine, you're expected to reload
677 int wil_reset(struct wil6210_priv
*wil
, bool load_fw
)
681 wil_dbg_misc(wil
, "%s()\n", __func__
);
683 if (wil
->hw_version
== HW_VER_UNKNOWN
)
686 WARN_ON(!mutex_is_locked(&wil
->mutex
));
687 WARN_ON(test_bit(wil_status_napi_en
, wil
->status
));
689 cancel_work_sync(&wil
->disconnect_worker
);
690 wil6210_disconnect(wil
, NULL
, WLAN_REASON_DEAUTH_LEAVING
, false);
693 /* prevent NAPI from being scheduled */
694 bitmap_zero(wil
->status
, wil_status_last
);
696 if (wil
->scan_request
) {
697 wil_dbg_misc(wil
, "Abort scan_request 0x%p\n",
699 del_timer_sync(&wil
->scan_timer
);
700 cfg80211_scan_done(wil
->scan_request
, true);
701 wil
->scan_request
= NULL
;
706 wmi_event_flush(wil
);
708 flush_workqueue(wil
->wq_service
);
709 flush_workqueue(wil
->wmi_wq
);
711 rc
= wil_target_reset(wil
);
716 rc
= wil_get_bl_info(wil
);
721 wil_info(wil
, "Use firmware <%s> + board <%s>\n", WIL_FW_NAME
,
725 /* Loading f/w from the file */
726 rc
= wil_request_firmware(wil
, WIL_FW_NAME
);
729 rc
= wil_request_firmware(wil
, WIL_FW2_NAME
);
733 /* Mark FW as loaded from host */
734 S(RGF_USER_USAGE_6
, 1);
736 /* clear any interrupts which on-card-firmware
739 wil6210_clear_irq(wil
);
740 /* CAF_ICR - clear and mask */
741 /* it is W1C, clear by writing back same value */
742 S(RGF_CAF_ICR
+ offsetof(struct RGF_ICR
, ICR
), 0);
743 W(RGF_CAF_ICR
+ offsetof(struct RGF_ICR
, IMV
), ~0);
745 wil_release_cpu(wil
);
748 /* init after reset */
749 wil
->pending_connect_cid
= -1;
751 reinit_completion(&wil
->wmi_ready
);
752 reinit_completion(&wil
->wmi_call
);
755 wil_configure_interrupt_moderation(wil
);
758 /* we just started MAC, wait for FW ready */
759 rc
= wil_wait_for_fw_ready(wil
);
760 if (rc
== 0) /* check FW is responsive */
772 void wil_fw_error_recovery(struct wil6210_priv
*wil
)
774 wil_dbg_misc(wil
, "starting fw error recovery\n");
775 wil
->recovery_state
= fw_recovery_pending
;
776 schedule_work(&wil
->fw_error_worker
);
779 int __wil_up(struct wil6210_priv
*wil
)
781 struct net_device
*ndev
= wil_to_ndev(wil
);
782 struct wireless_dev
*wdev
= wil
->wdev
;
785 WARN_ON(!mutex_is_locked(&wil
->mutex
));
787 rc
= wil_reset(wil
, true);
791 /* Rx VRING. After MAC and beacon */
792 rc
= wil_rx_init(wil
, 1 << rx_ring_order
);
796 switch (wdev
->iftype
) {
797 case NL80211_IFTYPE_STATION
:
798 wil_dbg_misc(wil
, "type: STATION\n");
799 ndev
->type
= ARPHRD_ETHER
;
801 case NL80211_IFTYPE_AP
:
802 wil_dbg_misc(wil
, "type: AP\n");
803 ndev
->type
= ARPHRD_ETHER
;
805 case NL80211_IFTYPE_P2P_CLIENT
:
806 wil_dbg_misc(wil
, "type: P2P_CLIENT\n");
807 ndev
->type
= ARPHRD_ETHER
;
809 case NL80211_IFTYPE_P2P_GO
:
810 wil_dbg_misc(wil
, "type: P2P_GO\n");
811 ndev
->type
= ARPHRD_ETHER
;
813 case NL80211_IFTYPE_MONITOR
:
814 wil_dbg_misc(wil
, "type: Monitor\n");
815 ndev
->type
= ARPHRD_IEEE80211_RADIOTAP
;
816 /* ARPHRD_IEEE80211 or ARPHRD_IEEE80211_RADIOTAP ? */
822 /* MAC address - pre-requisite for other commands */
823 wmi_set_mac_address(wil
, ndev
->dev_addr
);
825 wil_dbg_misc(wil
, "NAPI enable\n");
826 napi_enable(&wil
->napi_rx
);
827 napi_enable(&wil
->napi_tx
);
828 set_bit(wil_status_napi_en
, wil
->status
);
830 if (wil
->platform_ops
.bus_request
)
831 wil
->platform_ops
.bus_request(wil
->platform_handle
,
832 WIL_MAX_BUS_REQUEST_KBPS
);
837 int wil_up(struct wil6210_priv
*wil
)
841 wil_dbg_misc(wil
, "%s()\n", __func__
);
843 mutex_lock(&wil
->mutex
);
845 mutex_unlock(&wil
->mutex
);
850 int __wil_down(struct wil6210_priv
*wil
)
852 int iter
= WAIT_FOR_DISCONNECT_TIMEOUT_MS
/
853 WAIT_FOR_DISCONNECT_INTERVAL_MS
;
855 WARN_ON(!mutex_is_locked(&wil
->mutex
));
857 if (wil
->platform_ops
.bus_request
)
858 wil
->platform_ops
.bus_request(wil
->platform_handle
, 0);
860 wil_disable_irq(wil
);
861 if (test_and_clear_bit(wil_status_napi_en
, wil
->status
)) {
862 napi_disable(&wil
->napi_rx
);
863 napi_disable(&wil
->napi_tx
);
864 wil_dbg_misc(wil
, "NAPI disable\n");
868 if (wil
->scan_request
) {
869 wil_dbg_misc(wil
, "Abort scan_request 0x%p\n",
871 del_timer_sync(&wil
->scan_timer
);
872 cfg80211_scan_done(wil
->scan_request
, true);
873 wil
->scan_request
= NULL
;
876 if (test_bit(wil_status_fwconnected
, wil
->status
) ||
877 test_bit(wil_status_fwconnecting
, wil
->status
))
878 wmi_send(wil
, WMI_DISCONNECT_CMDID
, NULL
, 0);
880 /* make sure wil is idle (not connected) */
881 mutex_unlock(&wil
->mutex
);
883 int idle
= !test_bit(wil_status_fwconnected
, wil
->status
) &&
884 !test_bit(wil_status_fwconnecting
, wil
->status
);
887 msleep(WAIT_FOR_DISCONNECT_INTERVAL_MS
);
889 mutex_lock(&wil
->mutex
);
892 wil_err(wil
, "timeout waiting for idle FW/HW\n");
894 wil_reset(wil
, false);
899 int wil_down(struct wil6210_priv
*wil
)
903 wil_dbg_misc(wil
, "%s()\n", __func__
);
905 wil_set_recovery_state(wil
, fw_recovery_idle
);
906 mutex_lock(&wil
->mutex
);
907 rc
= __wil_down(wil
);
908 mutex_unlock(&wil
->mutex
);
913 int wil_find_cid(struct wil6210_priv
*wil
, const u8
*mac
)
918 for (i
= 0; i
< ARRAY_SIZE(wil
->sta
); i
++) {
919 if ((wil
->sta
[i
].status
!= wil_sta_unused
) &&
920 ether_addr_equal(wil
->sta
[i
].addr
, mac
)) {