1 /*
2  * Copyright (c) 2012-2017 Qualcomm Atheros, Inc.
3  *
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.
7  *
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.
15  */
16 
17 #include <linux/moduleparam.h>
18 #include <linux/if_arp.h>
19 #include <linux/etherdevice.h>
20 
21 #include "wil6210.h"
22 #include "txrx.h"
23 #include "wmi.h"
24 #include "boot_loader.h"
25 
26 #define WAIT_FOR_HALP_VOTE_MS 100
27 #define WAIT_FOR_SCAN_ABORT_MS 1000
28 
29 bool debug_fw; /* = false; */
30 module_param(debug_fw, bool, 0444);
31 MODULE_PARM_DESC(debug_fw, " do not perform card reset. For FW debug");
32 
33 static bool oob_mode;
34 module_param(oob_mode, bool, 0444);
35 MODULE_PARM_DESC(oob_mode,
36 		 " enable out of the box (OOB) mode in FW, for diagnostics and certification");
37 
38 bool no_fw_recovery;
39 module_param(no_fw_recovery, bool, 0644);
40 MODULE_PARM_DESC(no_fw_recovery, " disable automatic FW error recovery");
41 
42 /* if not set via modparam, will be set to default value of 1/8 of
43  * rx ring size during init flow
44  */
45 unsigned short rx_ring_overflow_thrsh = WIL6210_RX_HIGH_TRSH_INIT;
46 module_param(rx_ring_overflow_thrsh, ushort, 0444);
47 MODULE_PARM_DESC(rx_ring_overflow_thrsh,
48 		 " RX ring overflow threshold in descriptors.");
49 
50 /* We allow allocation of more than 1 page buffers to support large packets.
51  * It is suboptimal behavior performance wise in case MTU above page size.
52  */
53 unsigned int mtu_max = TXRX_BUF_LEN_DEFAULT - WIL_MAX_MPDU_OVERHEAD;
54 static int mtu_max_set(const char *val, const struct kernel_param *kp)
55 {
56 	int ret;
57 
58 	/* sets mtu_max directly. no need to restore it in case of
59 	 * illegal value since we assume this will fail insmod
60 	 */
61 	ret = param_set_uint(val, kp);
62 	if (ret)
63 		return ret;
64 
65 	if (mtu_max < 68 || mtu_max > WIL_MAX_ETH_MTU)
66 		ret = -EINVAL;
67 
68 	return ret;
69 }
70 
71 static const struct kernel_param_ops mtu_max_ops = {
72 	.set = mtu_max_set,
73 	.get = param_get_uint,
74 };
75 
76 module_param_cb(mtu_max, &mtu_max_ops, &mtu_max, 0444);
77 MODULE_PARM_DESC(mtu_max, " Max MTU value.");
78 
79 static uint rx_ring_order = WIL_RX_RING_SIZE_ORDER_DEFAULT;
80 static uint tx_ring_order = WIL_TX_RING_SIZE_ORDER_DEFAULT;
81 static uint bcast_ring_order = WIL_BCAST_RING_SIZE_ORDER_DEFAULT;
82 
83 static int ring_order_set(const char *val, const struct kernel_param *kp)
84 {
85 	int ret;
86 	uint x;
87 
88 	ret = kstrtouint(val, 0, &x);
89 	if (ret)
90 		return ret;
91 
92 	if ((x < WIL_RING_SIZE_ORDER_MIN) || (x > WIL_RING_SIZE_ORDER_MAX))
93 		return -EINVAL;
94 
95 	*((uint *)kp->arg) = x;
96 
97 	return 0;
98 }
99 
100 static const struct kernel_param_ops ring_order_ops = {
101 	.set = ring_order_set,
102 	.get = param_get_uint,
103 };
104 
105 module_param_cb(rx_ring_order, &ring_order_ops, &rx_ring_order, 0444);
106 MODULE_PARM_DESC(rx_ring_order, " Rx ring order; size = 1 << order");
107 module_param_cb(tx_ring_order, &ring_order_ops, &tx_ring_order, 0444);
108 MODULE_PARM_DESC(tx_ring_order, " Tx ring order; size = 1 << order");
109 module_param_cb(bcast_ring_order, &ring_order_ops, &bcast_ring_order, 0444);
110 MODULE_PARM_DESC(bcast_ring_order, " Bcast ring order; size = 1 << order");
111 
112 #define RST_DELAY (20) /* msec, for loop in @wil_target_reset */
113 #define RST_COUNT (1 + 1000/RST_DELAY) /* round up to be above 1 sec total */
114 
115 /*
116  * Due to a hardware issue,
117  * one has to read/write to/from NIC in 32-bit chunks;
118  * regular memcpy_fromio and siblings will
119  * not work on 64-bit platform - it uses 64-bit transactions
120  *
121  * Force 32-bit transactions to enable NIC on 64-bit platforms
122  *
123  * To avoid byte swap on big endian host, __raw_{read|write}l
124  * should be used - {read|write}l would swap bytes to provide
125  * little endian on PCI value in host endianness.
126  */
127 void wil_memcpy_fromio_32(void *dst, const volatile void __iomem *src,
128 			  size_t count)
129 {
130 	u32 *d = dst;
131 	const volatile u32 __iomem *s = src;
132 
133 	/* size_t is unsigned, if (count%4 != 0) it will wrap */
134 	for (count += 4; count > 4; count -= 4)
135 		*d++ = __raw_readl(s++);
136 }
137 
138 void wil_memcpy_fromio_halp_vote(struct wil6210_priv *wil, void *dst,
139 				 const volatile void __iomem *src, size_t count)
140 {
141 	wil_halp_vote(wil);
142 	wil_memcpy_fromio_32(dst, src, count);
143 	wil_halp_unvote(wil);
144 }
145 
146 void wil_memcpy_toio_32(volatile void __iomem *dst, const void *src,
147 			size_t count)
148 {
149 	volatile u32 __iomem *d = dst;
150 	const u32 *s = src;
151 
152 	for (count += 4; count > 4; count -= 4)
153 		__raw_writel(*s++, d++);
154 }
155 
156 void wil_memcpy_toio_halp_vote(struct wil6210_priv *wil,
157 			       volatile void __iomem *dst,
158 			       const void *src, size_t count)
159 {
160 	wil_halp_vote(wil);
161 	wil_memcpy_toio_32(dst, src, count);
162 	wil_halp_unvote(wil);
163 }
164 
165 static void wil_disconnect_cid(struct wil6210_priv *wil, int cid,
166 			       u16 reason_code, bool from_event)
167 __acquires(&sta->tid_rx_lock) __releases(&sta->tid_rx_lock)
168 {
169 	uint i;
170 	struct net_device *ndev = wil_to_ndev(wil);
171 	struct wireless_dev *wdev = wil->wdev;
172 	struct wil_sta_info *sta = &wil->sta[cid];
173 
174 	might_sleep();
175 	wil_dbg_misc(wil, "disconnect_cid: CID %d, status %d\n",
176 		     cid, sta->status);
177 	/* inform upper/lower layers */
178 	if (sta->status != wil_sta_unused) {
179 		if (!from_event) {
180 			bool del_sta = (wdev->iftype == NL80211_IFTYPE_AP) ?
181 						disable_ap_sme : false;
182 			wmi_disconnect_sta(wil, sta->addr, reason_code,
183 					   true, del_sta);
184 		}
185 
186 		switch (wdev->iftype) {
187 		case NL80211_IFTYPE_AP:
188 		case NL80211_IFTYPE_P2P_GO:
189 			/* AP-like interface */
190 			cfg80211_del_sta(ndev, sta->addr, GFP_KERNEL);
191 			break;
192 		default:
193 			break;
194 		}
195 		sta->status = wil_sta_unused;
196 	}
197 	/* reorder buffers */
198 	for (i = 0; i < WIL_STA_TID_NUM; i++) {
199 		struct wil_tid_ampdu_rx *r;
200 
201 		spin_lock_bh(&sta->tid_rx_lock);
202 
203 		r = sta->tid_rx[i];
204 		sta->tid_rx[i] = NULL;
205 		wil_tid_ampdu_rx_free(wil, r);
206 
207 		spin_unlock_bh(&sta->tid_rx_lock);
208 	}
209 	/* crypto context */
210 	memset(sta->tid_crypto_rx, 0, sizeof(sta->tid_crypto_rx));
211 	memset(&sta->group_crypto_rx, 0, sizeof(sta->group_crypto_rx));
212 	/* release vrings */
213 	for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
214 		if (wil->vring2cid_tid[i][0] == cid)
215 			wil_vring_fini_tx(wil, i);
216 	}
217 	/* statistics */
218 	memset(&sta->stats, 0, sizeof(sta->stats));
219 }
220 
221 static bool wil_is_connected(struct wil6210_priv *wil)
222 {
223 	int i;
224 
225 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
226 		if (wil->sta[i].status == wil_sta_connected)
227 			return true;
228 	}
229 
230 	return false;
231 }
232 
233 static void _wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid,
234 				u16 reason_code, bool from_event)
235 {
236 	int cid = -ENOENT;
237 	struct net_device *ndev = wil_to_ndev(wil);
238 	struct wireless_dev *wdev = wil->wdev;
239 
240 	if (unlikely(!ndev))
241 		return;
242 
243 	might_sleep();
244 	wil_info(wil, "bssid=%pM, reason=%d, ev%s\n", bssid,
245 		 reason_code, from_event ? "+" : "-");
246 
247 	/* Cases are:
248 	 * - disconnect single STA, still connected
249 	 * - disconnect single STA, already disconnected
250 	 * - disconnect all
251 	 *
252 	 * For "disconnect all", there are 3 options:
253 	 * - bssid == NULL
254 	 * - bssid is broadcast address (ff:ff:ff:ff:ff:ff)
255 	 * - bssid is our MAC address
256 	 */
257 	if (bssid && !is_broadcast_ether_addr(bssid) &&
258 	    !ether_addr_equal_unaligned(ndev->dev_addr, bssid)) {
259 		cid = wil_find_cid(wil, bssid);
260 		wil_dbg_misc(wil, "Disconnect %pM, CID=%d, reason=%d\n",
261 			     bssid, cid, reason_code);
262 		if (cid >= 0) /* disconnect 1 peer */
263 			wil_disconnect_cid(wil, cid, reason_code, from_event);
264 	} else { /* all */
265 		wil_dbg_misc(wil, "Disconnect all\n");
266 		for (cid = 0; cid < WIL6210_MAX_CID; cid++)
267 			wil_disconnect_cid(wil, cid, reason_code, from_event);
268 	}
269 
270 	/* link state */
271 	switch (wdev->iftype) {
272 	case NL80211_IFTYPE_STATION:
273 	case NL80211_IFTYPE_P2P_CLIENT:
274 		wil_bcast_fini(wil);
275 		wil_update_net_queues_bh(wil, NULL, true);
276 		netif_carrier_off(ndev);
277 
278 		if (test_bit(wil_status_fwconnected, wil->status)) {
279 			clear_bit(wil_status_fwconnected, wil->status);
280 			cfg80211_disconnected(ndev, reason_code,
281 					      NULL, 0, false, GFP_KERNEL);
282 		} else if (test_bit(wil_status_fwconnecting, wil->status)) {
283 			cfg80211_connect_result(ndev, bssid, NULL, 0, NULL, 0,
284 						WLAN_STATUS_UNSPECIFIED_FAILURE,
285 						GFP_KERNEL);
286 		}
287 		clear_bit(wil_status_fwconnecting, wil->status);
288 		break;
289 	case NL80211_IFTYPE_AP:
290 	case NL80211_IFTYPE_P2P_GO:
291 		if (!wil_is_connected(wil)) {
292 			wil_update_net_queues_bh(wil, NULL, true);
293 			clear_bit(wil_status_fwconnected, wil->status);
294 		} else {
295 			wil_update_net_queues_bh(wil, NULL, false);
296 		}
297 		break;
298 	default:
299 		break;
300 	}
301 }
302 
303 static void wil_disconnect_worker(struct work_struct *work)
304 {
305 	struct wil6210_priv *wil = container_of(work,
306 			struct wil6210_priv, disconnect_worker);
307 
308 	mutex_lock(&wil->mutex);
309 	_wil6210_disconnect(wil, NULL, WLAN_REASON_UNSPECIFIED, false);
310 	mutex_unlock(&wil->mutex);
311 }
312 
313 static void wil_connect_timer_fn(ulong x)
314 {
315 	struct wil6210_priv *wil = (void *)x;
316 	bool q;
317 
318 	wil_err(wil, "Connect timeout detected, disconnect station\n");
319 
320 	/* reschedule to thread context - disconnect won't
321 	 * run from atomic context.
322 	 * queue on wmi_wq to prevent race with connect event.
323 	 */
324 	q = queue_work(wil->wmi_wq, &wil->disconnect_worker);
325 	wil_dbg_wmi(wil, "queue_work of disconnect_worker -> %d\n", q);
326 }
327 
328 static void wil_scan_timer_fn(ulong x)
329 {
330 	struct wil6210_priv *wil = (void *)x;
331 
332 	clear_bit(wil_status_fwready, wil->status);
333 	wil_err(wil, "Scan timeout detected, start fw error recovery\n");
334 	wil_fw_error_recovery(wil);
335 }
336 
337 static int wil_wait_for_recovery(struct wil6210_priv *wil)
338 {
339 	if (wait_event_interruptible(wil->wq, wil->recovery_state !=
340 				     fw_recovery_pending)) {
341 		wil_err(wil, "Interrupt, canceling recovery\n");
342 		return -ERESTARTSYS;
343 	}
344 	if (wil->recovery_state != fw_recovery_running) {
345 		wil_info(wil, "Recovery cancelled\n");
346 		return -EINTR;
347 	}
348 	wil_info(wil, "Proceed with recovery\n");
349 	return 0;
350 }
351 
352 void wil_set_recovery_state(struct wil6210_priv *wil, int state)
353 {
354 	wil_dbg_misc(wil, "set_recovery_state: %d -> %d\n",
355 		     wil->recovery_state, state);
356 
357 	wil->recovery_state = state;
358 	wake_up_interruptible(&wil->wq);
359 }
360 
361 bool wil_is_recovery_blocked(struct wil6210_priv *wil)
362 {
363 	return no_fw_recovery && (wil->recovery_state == fw_recovery_pending);
364 }
365 
366 static void wil_fw_error_worker(struct work_struct *work)
367 {
368 	struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
369 						fw_error_worker);
370 	struct wireless_dev *wdev = wil->wdev;
371 
372 	wil_dbg_misc(wil, "fw error worker\n");
373 
374 	if (!netif_running(wil_to_ndev(wil))) {
375 		wil_info(wil, "No recovery - interface is down\n");
376 		return;
377 	}
378 
379 	/* increment @recovery_count if less then WIL6210_FW_RECOVERY_TO
380 	 * passed since last recovery attempt
381 	 */
382 	if (time_is_after_jiffies(wil->last_fw_recovery +
383 				  WIL6210_FW_RECOVERY_TO))
384 		wil->recovery_count++;
385 	else
386 		wil->recovery_count = 1; /* fw was alive for a long time */
387 
388 	if (wil->recovery_count > WIL6210_FW_RECOVERY_RETRIES) {
389 		wil_err(wil, "too many recovery attempts (%d), giving up\n",
390 			wil->recovery_count);
391 		return;
392 	}
393 
394 	wil->last_fw_recovery = jiffies;
395 
396 	wil_info(wil, "fw error recovery requested (try %d)...\n",
397 		 wil->recovery_count);
398 	if (!no_fw_recovery)
399 		wil->recovery_state = fw_recovery_running;
400 	if (wil_wait_for_recovery(wil) != 0)
401 		return;
402 
403 	mutex_lock(&wil->mutex);
404 	switch (wdev->iftype) {
405 	case NL80211_IFTYPE_STATION:
406 	case NL80211_IFTYPE_P2P_CLIENT:
407 	case NL80211_IFTYPE_MONITOR:
408 		/* silent recovery, upper layers will see disconnect */
409 		__wil_down(wil);
410 		__wil_up(wil);
411 		break;
412 	case NL80211_IFTYPE_AP:
413 	case NL80211_IFTYPE_P2P_GO:
414 		wil_info(wil, "No recovery for AP-like interface\n");
415 		/* recovery in these modes is done by upper layers */
416 		break;
417 	default:
418 		wil_err(wil, "No recovery - unknown interface type %d\n",
419 			wdev->iftype);
420 		break;
421 	}
422 	mutex_unlock(&wil->mutex);
423 }
424 
425 static int wil_find_free_vring(struct wil6210_priv *wil)
426 {
427 	int i;
428 
429 	for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) {
430 		if (!wil->vring_tx[i].va)
431 			return i;
432 	}
433 	return -EINVAL;
434 }
435 
436 int wil_tx_init(struct wil6210_priv *wil, int cid)
437 {
438 	int rc = -EINVAL, ringid;
439 
440 	if (cid < 0) {
441 		wil_err(wil, "No connection pending\n");
442 		goto out;
443 	}
444 	ringid = wil_find_free_vring(wil);
445 	if (ringid < 0) {
446 		wil_err(wil, "No free vring found\n");
447 		goto out;
448 	}
449 
450 	wil_dbg_wmi(wil, "Configure for connection CID %d vring %d\n",
451 		    cid, ringid);
452 
453 	rc = wil_vring_init_tx(wil, ringid, 1 << tx_ring_order, cid, 0);
454 	if (rc)
455 		wil_err(wil, "wil_vring_init_tx for CID %d vring %d failed\n",
456 			cid, ringid);
457 
458 out:
459 	return rc;
460 }
461 
462 int wil_bcast_init(struct wil6210_priv *wil)
463 {
464 	int ri = wil->bcast_vring, rc;
465 
466 	if ((ri >= 0) && wil->vring_tx[ri].va)
467 		return 0;
468 
469 	ri = wil_find_free_vring(wil);
470 	if (ri < 0)
471 		return ri;
472 
473 	wil->bcast_vring = ri;
474 	rc = wil_vring_init_bcast(wil, ri, 1 << bcast_ring_order);
475 	if (rc)
476 		wil->bcast_vring = -1;
477 
478 	return rc;
479 }
480 
481 void wil_bcast_fini(struct wil6210_priv *wil)
482 {
483 	int ri = wil->bcast_vring;
484 
485 	if (ri < 0)
486 		return;
487 
488 	wil->bcast_vring = -1;
489 	wil_vring_fini_tx(wil, ri);
490 }
491 
492 int wil_priv_init(struct wil6210_priv *wil)
493 {
494 	uint i;
495 
496 	wil_dbg_misc(wil, "priv_init\n");
497 
498 	memset(wil->sta, 0, sizeof(wil->sta));
499 	for (i = 0; i < WIL6210_MAX_CID; i++)
500 		spin_lock_init(&wil->sta[i].tid_rx_lock);
501 
502 	for (i = 0; i < WIL6210_MAX_TX_RINGS; i++)
503 		spin_lock_init(&wil->vring_tx_data[i].lock);
504 
505 	mutex_init(&wil->mutex);
506 	mutex_init(&wil->wmi_mutex);
507 	mutex_init(&wil->probe_client_mutex);
508 	mutex_init(&wil->p2p_wdev_mutex);
509 	mutex_init(&wil->halp.lock);
510 
511 	init_completion(&wil->wmi_ready);
512 	init_completion(&wil->wmi_call);
513 	init_completion(&wil->halp.comp);
514 
515 	wil->bcast_vring = -1;
516 	setup_timer(&wil->connect_timer, wil_connect_timer_fn, (ulong)wil);
517 	setup_timer(&wil->scan_timer, wil_scan_timer_fn, (ulong)wil);
518 	setup_timer(&wil->p2p.discovery_timer, wil_p2p_discovery_timer_fn,
519 		    (ulong)wil);
520 
521 	INIT_WORK(&wil->disconnect_worker, wil_disconnect_worker);
522 	INIT_WORK(&wil->wmi_event_worker, wmi_event_worker);
523 	INIT_WORK(&wil->fw_error_worker, wil_fw_error_worker);
524 	INIT_WORK(&wil->probe_client_worker, wil_probe_client_worker);
525 	INIT_WORK(&wil->p2p.delayed_listen_work, wil_p2p_delayed_listen_work);
526 
527 	INIT_LIST_HEAD(&wil->pending_wmi_ev);
528 	INIT_LIST_HEAD(&wil->probe_client_pending);
529 	spin_lock_init(&wil->wmi_ev_lock);
530 	spin_lock_init(&wil->net_queue_lock);
531 	wil->net_queue_stopped = 1;
532 	init_waitqueue_head(&wil->wq);
533 
534 	wil->wmi_wq = create_singlethread_workqueue(WIL_NAME "_wmi");
535 	if (!wil->wmi_wq)
536 		return -EAGAIN;
537 
538 	wil->wq_service = create_singlethread_workqueue(WIL_NAME "_service");
539 	if (!wil->wq_service)
540 		goto out_wmi_wq;
541 
542 	wil->last_fw_recovery = jiffies;
543 	wil->tx_interframe_timeout = WIL6210_ITR_TX_INTERFRAME_TIMEOUT_DEFAULT;
544 	wil->rx_interframe_timeout = WIL6210_ITR_RX_INTERFRAME_TIMEOUT_DEFAULT;
545 	wil->tx_max_burst_duration = WIL6210_ITR_TX_MAX_BURST_DURATION_DEFAULT;
546 	wil->rx_max_burst_duration = WIL6210_ITR_RX_MAX_BURST_DURATION_DEFAULT;
547 
548 	if (rx_ring_overflow_thrsh == WIL6210_RX_HIGH_TRSH_INIT)
549 		rx_ring_overflow_thrsh = WIL6210_RX_HIGH_TRSH_DEFAULT;
550 	return 0;
551 
552 out_wmi_wq:
553 	destroy_workqueue(wil->wmi_wq);
554 
555 	return -EAGAIN;
556 }
557 
558 /**
559  * wil6210_disconnect - disconnect one connection
560  * @wil: driver context
561  * @bssid: peer to disconnect, NULL to disconnect all
562  * @reason_code: Reason code for the Disassociation frame
563  * @from_event: whether is invoked from FW event handler
564  *
565  * Disconnect and release associated resources. If invoked not from the
566  * FW event handler, issue WMI command(s) to trigger MAC disconnect.
567  */
568 void wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid,
569 			u16 reason_code, bool from_event)
570 {
571 	wil_dbg_misc(wil, "disconnect\n");
572 
573 	del_timer_sync(&wil->connect_timer);
574 	_wil6210_disconnect(wil, bssid, reason_code, from_event);
575 }
576 
577 void wil_priv_deinit(struct wil6210_priv *wil)
578 {
579 	wil_dbg_misc(wil, "priv_deinit\n");
580 
581 	wil_set_recovery_state(wil, fw_recovery_idle);
582 	del_timer_sync(&wil->scan_timer);
583 	del_timer_sync(&wil->p2p.discovery_timer);
584 	cancel_work_sync(&wil->disconnect_worker);
585 	cancel_work_sync(&wil->fw_error_worker);
586 	cancel_work_sync(&wil->p2p.discovery_expired_work);
587 	cancel_work_sync(&wil->p2p.delayed_listen_work);
588 	mutex_lock(&wil->mutex);
589 	wil6210_disconnect(wil, NULL, WLAN_REASON_DEAUTH_LEAVING, false);
590 	mutex_unlock(&wil->mutex);
591 	wmi_event_flush(wil);
592 	wil_probe_client_flush(wil);
593 	cancel_work_sync(&wil->probe_client_worker);
594 	destroy_workqueue(wil->wq_service);
595 	destroy_workqueue(wil->wmi_wq);
596 }
597 
598 static inline void wil_halt_cpu(struct wil6210_priv *wil)
599 {
600 	wil_w(wil, RGF_USER_USER_CPU_0, BIT_USER_USER_CPU_MAN_RST);
601 	wil_w(wil, RGF_USER_MAC_CPU_0,  BIT_USER_MAC_CPU_MAN_RST);
602 }
603 
604 static inline void wil_release_cpu(struct wil6210_priv *wil)
605 {
606 	/* Start CPU */
607 	wil_w(wil, RGF_USER_USER_CPU_0, 1);
608 }
609 
610 static void wil_set_oob_mode(struct wil6210_priv *wil, bool enable)
611 {
612 	wil_info(wil, "enable=%d\n", enable);
613 	if (enable)
614 		wil_s(wil, RGF_USER_USAGE_6, BIT_USER_OOB_MODE);
615 	else
616 		wil_c(wil, RGF_USER_USAGE_6, BIT_USER_OOB_MODE);
617 }
618 
619 static int wil_target_reset(struct wil6210_priv *wil)
620 {
621 	int delay = 0;
622 	u32 x, x1 = 0;
623 
624 	wil_dbg_misc(wil, "Resetting \"%s\"...\n", wil->hw_name);
625 
626 	/* Clear MAC link up */
627 	wil_s(wil, RGF_HP_CTRL, BIT(15));
628 	wil_s(wil, RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT_HPAL_PERST_FROM_PAD);
629 	wil_s(wil, RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT_CAR_PERST_RST);
630 
631 	wil_halt_cpu(wil);
632 
633 	/* clear all boot loader "ready" bits */
634 	wil_w(wil, RGF_USER_BL +
635 	      offsetof(struct bl_dedicated_registers_v0, boot_loader_ready), 0);
636 	/* Clear Fw Download notification */
637 	wil_c(wil, RGF_USER_USAGE_6, BIT(0));
638 
639 	wil_s(wil, RGF_CAF_OSC_CONTROL, BIT_CAF_OSC_XTAL_EN);
640 	/* XTAL stabilization should take about 3ms */
641 	usleep_range(5000, 7000);
642 	x = wil_r(wil, RGF_CAF_PLL_LOCK_STATUS);
643 	if (!(x & BIT_CAF_OSC_DIG_XTAL_STABLE)) {
644 		wil_err(wil, "Xtal stabilization timeout\n"
645 			"RGF_CAF_PLL_LOCK_STATUS = 0x%08x\n", x);
646 		return -ETIME;
647 	}
648 	/* switch 10k to XTAL*/
649 	wil_c(wil, RGF_USER_SPARROW_M_4, BIT_SPARROW_M_4_SEL_SLEEP_OR_REF);
650 	/* 40 MHz */
651 	wil_c(wil, RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_CAR_AHB_SW_SEL);
652 
653 	wil_w(wil, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x3ff81f);
654 	wil_w(wil, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0xf);
655 
656 	wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0xFE000000);
657 	wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0x0000003F);
658 	wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x000000f0);
659 	wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0xFFE7FE00);
660 
661 	wil_w(wil, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x0);
662 	wil_w(wil, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0x0);
663 
664 	wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0);
665 	wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0);
666 	wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0);
667 	wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
668 
669 	wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000003);
670 	/* reset A2 PCIE AHB */
671 	wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00008000);
672 
673 	wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
674 
675 	/* wait until device ready. typical time is 20..80 msec */
676 	do {
677 		msleep(RST_DELAY);
678 		x = wil_r(wil, RGF_USER_BL +
679 			  offsetof(struct bl_dedicated_registers_v0,
680 				   boot_loader_ready));
681 		if (x1 != x) {
682 			wil_dbg_misc(wil, "BL.ready 0x%08x => 0x%08x\n", x1, x);
683 			x1 = x;
684 		}
685 		if (delay++ > RST_COUNT) {
686 			wil_err(wil, "Reset not completed, bl.ready 0x%08x\n",
687 				x);
688 			return -ETIME;
689 		}
690 	} while (x != BL_READY);
691 
692 	wil_c(wil, RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_RST_PWGD);
693 
694 	/* enable fix for HW bug related to the SA/DA swap in AP Rx */
695 	wil_s(wil, RGF_DMA_OFUL_NID_0, BIT_DMA_OFUL_NID_0_RX_EXT_TR_EN |
696 	      BIT_DMA_OFUL_NID_0_RX_EXT_A3_SRC);
697 
698 	wil_dbg_misc(wil, "Reset completed in %d ms\n", delay * RST_DELAY);
699 	return 0;
700 }
701 
702 static void wil_collect_fw_info(struct wil6210_priv *wil)
703 {
704 	struct wiphy *wiphy = wil_to_wiphy(wil);
705 	u8 retry_short;
706 	int rc;
707 
708 	rc = wmi_get_mgmt_retry(wil, &retry_short);
709 	if (!rc) {
710 		wiphy->retry_short = retry_short;
711 		wil_dbg_misc(wil, "FW retry_short: %d\n", retry_short);
712 	}
713 }
714 
715 void wil_mbox_ring_le2cpus(struct wil6210_mbox_ring *r)
716 {
717 	le32_to_cpus(&r->base);
718 	le16_to_cpus(&r->entry_size);
719 	le16_to_cpus(&r->size);
720 	le32_to_cpus(&r->tail);
721 	le32_to_cpus(&r->head);
722 }
723 
724 static int wil_get_bl_info(struct wil6210_priv *wil)
725 {
726 	struct net_device *ndev = wil_to_ndev(wil);
727 	struct wiphy *wiphy = wil_to_wiphy(wil);
728 	union {
729 		struct bl_dedicated_registers_v0 bl0;
730 		struct bl_dedicated_registers_v1 bl1;
731 	} bl;
732 	u32 bl_ver;
733 	u8 *mac;
734 	u16 rf_status;
735 
736 	wil_memcpy_fromio_32(&bl, wil->csr + HOSTADDR(RGF_USER_BL),
737 			     sizeof(bl));
738 	bl_ver = le32_to_cpu(bl.bl0.boot_loader_struct_version);
739 	mac = bl.bl0.mac_address;
740 
741 	if (bl_ver == 0) {
742 		le32_to_cpus(&bl.bl0.rf_type);
743 		le32_to_cpus(&bl.bl0.baseband_type);
744 		rf_status = 0; /* actually, unknown */
745 		wil_info(wil,
746 			 "Boot Loader struct v%d: MAC = %pM RF = 0x%08x bband = 0x%08x\n",
747 			 bl_ver, mac,
748 			 bl.bl0.rf_type, bl.bl0.baseband_type);
749 		wil_info(wil, "Boot Loader build unknown for struct v0\n");
750 	} else {
751 		le16_to_cpus(&bl.bl1.rf_type);
752 		rf_status = le16_to_cpu(bl.bl1.rf_status);
753 		le32_to_cpus(&bl.bl1.baseband_type);
754 		le16_to_cpus(&bl.bl1.bl_version_subminor);
755 		le16_to_cpus(&bl.bl1.bl_version_build);
756 		wil_info(wil,
757 			 "Boot Loader struct v%d: MAC = %pM RF = 0x%04x (status 0x%04x) bband = 0x%08x\n",
758 			 bl_ver, mac,
759 			 bl.bl1.rf_type, rf_status,
760 			 bl.bl1.baseband_type);
761 		wil_info(wil, "Boot Loader build %d.%d.%d.%d\n",
762 			 bl.bl1.bl_version_major, bl.bl1.bl_version_minor,
763 			 bl.bl1.bl_version_subminor, bl.bl1.bl_version_build);
764 	}
765 
766 	if (!is_valid_ether_addr(mac)) {
767 		wil_err(wil, "BL: Invalid MAC %pM\n", mac);
768 		return -EINVAL;
769 	}
770 
771 	ether_addr_copy(ndev->perm_addr, mac);
772 	ether_addr_copy(wiphy->perm_addr, mac);
773 	if (!is_valid_ether_addr(ndev->dev_addr))
774 		ether_addr_copy(ndev->dev_addr, mac);
775 
776 	if (rf_status) {/* bad RF cable? */
777 		wil_err(wil, "RF communication error 0x%04x",
778 			rf_status);
779 		return -EAGAIN;
780 	}
781 
782 	return 0;
783 }
784 
785 static void wil_bl_crash_info(struct wil6210_priv *wil, bool is_err)
786 {
787 	u32 bl_assert_code, bl_assert_blink, bl_magic_number;
788 	u32 bl_ver = wil_r(wil, RGF_USER_BL +
789 			   offsetof(struct bl_dedicated_registers_v0,
790 				    boot_loader_struct_version));
791 
792 	if (bl_ver < 2)
793 		return;
794 
795 	bl_assert_code = wil_r(wil, RGF_USER_BL +
796 			       offsetof(struct bl_dedicated_registers_v1,
797 					bl_assert_code));
798 	bl_assert_blink = wil_r(wil, RGF_USER_BL +
799 				offsetof(struct bl_dedicated_registers_v1,
800 					 bl_assert_blink));
801 	bl_magic_number = wil_r(wil, RGF_USER_BL +
802 				offsetof(struct bl_dedicated_registers_v1,
803 					 bl_magic_number));
804 
805 	if (is_err) {
806 		wil_err(wil,
807 			"BL assert code 0x%08x blink 0x%08x magic 0x%08x\n",
808 			bl_assert_code, bl_assert_blink, bl_magic_number);
809 	} else {
810 		wil_dbg_misc(wil,
811 			     "BL assert code 0x%08x blink 0x%08x magic 0x%08x\n",
812 			     bl_assert_code, bl_assert_blink, bl_magic_number);
813 	}
814 }
815 
816 static int wil_wait_for_fw_ready(struct wil6210_priv *wil)
817 {
818 	ulong to = msecs_to_jiffies(1000);
819 	ulong left = wait_for_completion_timeout(&wil->wmi_ready, to);
820 
821 	if (0 == left) {
822 		wil_err(wil, "Firmware not ready\n");
823 		return -ETIME;
824 	} else {
825 		wil_info(wil, "FW ready after %d ms. HW version 0x%08x\n",
826 			 jiffies_to_msecs(to-left), wil->hw_version);
827 	}
828 	return 0;
829 }
830 
831 void wil_abort_scan(struct wil6210_priv *wil, bool sync)
832 {
833 	int rc;
834 	struct cfg80211_scan_info info = {
835 		.aborted = true,
836 	};
837 
838 	lockdep_assert_held(&wil->p2p_wdev_mutex);
839 
840 	if (!wil->scan_request)
841 		return;
842 
843 	wil_dbg_misc(wil, "Abort scan_request 0x%p\n", wil->scan_request);
844 	del_timer_sync(&wil->scan_timer);
845 	mutex_unlock(&wil->p2p_wdev_mutex);
846 	rc = wmi_abort_scan(wil);
847 	if (!rc && sync)
848 		wait_event_interruptible_timeout(wil->wq, !wil->scan_request,
849 						 msecs_to_jiffies(
850 						 WAIT_FOR_SCAN_ABORT_MS));
851 
852 	mutex_lock(&wil->p2p_wdev_mutex);
853 	if (wil->scan_request) {
854 		cfg80211_scan_done(wil->scan_request, &info);
855 		wil->scan_request = NULL;
856 	}
857 }
858 
859 /*
860  * We reset all the structures, and we reset the UMAC.
861  * After calling this routine, you're expected to reload
862  * the firmware.
863  */
864 int wil_reset(struct wil6210_priv *wil, bool load_fw)
865 {
866 	int rc;
867 
868 	wil_dbg_misc(wil, "reset\n");
869 
870 	WARN_ON(!mutex_is_locked(&wil->mutex));
871 	WARN_ON(test_bit(wil_status_napi_en, wil->status));
872 
873 	if (debug_fw) {
874 		static const u8 mac[ETH_ALEN] = {
875 			0x00, 0xde, 0xad, 0x12, 0x34, 0x56,
876 		};
877 		struct net_device *ndev = wil_to_ndev(wil);
878 
879 		ether_addr_copy(ndev->perm_addr, mac);
880 		ether_addr_copy(ndev->dev_addr, ndev->perm_addr);
881 		return 0;
882 	}
883 
884 	if (wil->hw_version == HW_VER_UNKNOWN)
885 		return -ENODEV;
886 
887 	if (wil->platform_ops.notify) {
888 		rc = wil->platform_ops.notify(wil->platform_handle,
889 					      WIL_PLATFORM_EVT_PRE_RESET);
890 		if (rc)
891 			wil_err(wil, "PRE_RESET platform notify failed, rc %d\n",
892 				rc);
893 	}
894 
895 	set_bit(wil_status_resetting, wil->status);
896 
897 	cancel_work_sync(&wil->disconnect_worker);
898 	wil6210_disconnect(wil, NULL, WLAN_REASON_DEAUTH_LEAVING, false);
899 	wil_bcast_fini(wil);
900 
901 	/* Disable device led before reset*/
902 	wmi_led_cfg(wil, false);
903 
904 	/* prevent NAPI from being scheduled and prevent wmi commands */
905 	mutex_lock(&wil->wmi_mutex);
906 	bitmap_zero(wil->status, wil_status_last);
907 	mutex_unlock(&wil->wmi_mutex);
908 
909 	mutex_lock(&wil->p2p_wdev_mutex);
910 	wil_abort_scan(wil, false);
911 	mutex_unlock(&wil->p2p_wdev_mutex);
912 
913 	wil_mask_irq(wil);
914 
915 	wmi_event_flush(wil);
916 
917 	flush_workqueue(wil->wq_service);
918 	flush_workqueue(wil->wmi_wq);
919 
920 	wil_bl_crash_info(wil, false);
921 	wil_disable_irq(wil);
922 	rc = wil_target_reset(wil);
923 	wil6210_clear_irq(wil);
924 	wil_enable_irq(wil);
925 	wil_rx_fini(wil);
926 	if (rc) {
927 		wil_bl_crash_info(wil, true);
928 		return rc;
929 	}
930 
931 	rc = wil_get_bl_info(wil);
932 	if (rc == -EAGAIN && !load_fw) /* ignore RF error if not going up */
933 		rc = 0;
934 	if (rc)
935 		return rc;
936 
937 	wil_set_oob_mode(wil, oob_mode);
938 	if (load_fw) {
939 		wil_info(wil, "Use firmware <%s> + board <%s>\n",
940 			 wil->wil_fw_name, WIL_BOARD_FILE_NAME);
941 
942 		wil_halt_cpu(wil);
943 		memset(wil->fw_version, 0, sizeof(wil->fw_version));
944 		/* Loading f/w from the file */
945 		rc = wil_request_firmware(wil, wil->wil_fw_name, true);
946 		if (rc)
947 			return rc;
948 		rc = wil_request_firmware(wil, WIL_BOARD_FILE_NAME, true);
949 		if (rc)
950 			return rc;
951 
952 		/* Mark FW as loaded from host */
953 		wil_s(wil, RGF_USER_USAGE_6, 1);
954 
955 		/* clear any interrupts which on-card-firmware
956 		 * may have set
957 		 */
958 		wil6210_clear_irq(wil);
959 		/* CAF_ICR - clear and mask */
960 		/* it is W1C, clear by writing back same value */
961 		wil_s(wil, RGF_CAF_ICR + offsetof(struct RGF_ICR, ICR), 0);
962 		wil_w(wil, RGF_CAF_ICR + offsetof(struct RGF_ICR, IMV), ~0);
963 
964 		wil_release_cpu(wil);
965 	}
966 
967 	/* init after reset */
968 	wil->ap_isolate = 0;
969 	reinit_completion(&wil->wmi_ready);
970 	reinit_completion(&wil->wmi_call);
971 	reinit_completion(&wil->halp.comp);
972 
973 	if (load_fw) {
974 		wil_configure_interrupt_moderation(wil);
975 		wil_unmask_irq(wil);
976 
977 		/* we just started MAC, wait for FW ready */
978 		rc = wil_wait_for_fw_ready(wil);
979 		if (rc)
980 			return rc;
981 
982 		/* check FW is responsive */
983 		rc = wmi_echo(wil);
984 		if (rc) {
985 			wil_err(wil, "wmi_echo failed, rc %d\n", rc);
986 			return rc;
987 		}
988 
989 		wil_collect_fw_info(wil);
990 
991 		if (wil->platform_ops.notify) {
992 			rc = wil->platform_ops.notify(wil->platform_handle,
993 						      WIL_PLATFORM_EVT_FW_RDY);
994 			if (rc) {
995 				wil_err(wil, "FW_RDY notify failed, rc %d\n",
996 					rc);
997 				rc = 0;
998 			}
999 		}
1000 	}
1001 
1002 	return rc;
1003 }
1004 
1005 void wil_fw_error_recovery(struct wil6210_priv *wil)
1006 {
1007 	wil_dbg_misc(wil, "starting fw error recovery\n");
1008 
1009 	if (test_bit(wil_status_resetting, wil->status)) {
1010 		wil_info(wil, "Reset already in progress\n");
1011 		return;
1012 	}
1013 
1014 	wil->recovery_state = fw_recovery_pending;
1015 	schedule_work(&wil->fw_error_worker);
1016 }
1017 
1018 int __wil_up(struct wil6210_priv *wil)
1019 {
1020 	struct net_device *ndev = wil_to_ndev(wil);
1021 	struct wireless_dev *wdev = wil->wdev;
1022 	int rc;
1023 
1024 	WARN_ON(!mutex_is_locked(&wil->mutex));
1025 
1026 	rc = wil_reset(wil, true);
1027 	if (rc)
1028 		return rc;
1029 
1030 	/* Rx VRING. After MAC and beacon */
1031 	rc = wil_rx_init(wil, 1 << rx_ring_order);
1032 	if (rc)
1033 		return rc;
1034 
1035 	switch (wdev->iftype) {
1036 	case NL80211_IFTYPE_STATION:
1037 		wil_dbg_misc(wil, "type: STATION\n");
1038 		ndev->type = ARPHRD_ETHER;
1039 		break;
1040 	case NL80211_IFTYPE_AP:
1041 		wil_dbg_misc(wil, "type: AP\n");
1042 		ndev->type = ARPHRD_ETHER;
1043 		break;
1044 	case NL80211_IFTYPE_P2P_CLIENT:
1045 		wil_dbg_misc(wil, "type: P2P_CLIENT\n");
1046 		ndev->type = ARPHRD_ETHER;
1047 		break;
1048 	case NL80211_IFTYPE_P2P_GO:
1049 		wil_dbg_misc(wil, "type: P2P_GO\n");
1050 		ndev->type = ARPHRD_ETHER;
1051 		break;
1052 	case NL80211_IFTYPE_MONITOR:
1053 		wil_dbg_misc(wil, "type: Monitor\n");
1054 		ndev->type = ARPHRD_IEEE80211_RADIOTAP;
1055 		/* ARPHRD_IEEE80211 or ARPHRD_IEEE80211_RADIOTAP ? */
1056 		break;
1057 	default:
1058 		return -EOPNOTSUPP;
1059 	}
1060 
1061 	/* MAC address - pre-requisite for other commands */
1062 	wmi_set_mac_address(wil, ndev->dev_addr);
1063 
1064 	wil_dbg_misc(wil, "NAPI enable\n");
1065 	napi_enable(&wil->napi_rx);
1066 	napi_enable(&wil->napi_tx);
1067 	set_bit(wil_status_napi_en, wil->status);
1068 
1069 	if (wil->platform_ops.bus_request)
1070 		wil->platform_ops.bus_request(wil->platform_handle,
1071 					      WIL_MAX_BUS_REQUEST_KBPS);
1072 
1073 	return 0;
1074 }
1075 
1076 int wil_up(struct wil6210_priv *wil)
1077 {
1078 	int rc;
1079 
1080 	wil_dbg_misc(wil, "up\n");
1081 
1082 	mutex_lock(&wil->mutex);
1083 	rc = __wil_up(wil);
1084 	mutex_unlock(&wil->mutex);
1085 
1086 	return rc;
1087 }
1088 
1089 int __wil_down(struct wil6210_priv *wil)
1090 {
1091 	WARN_ON(!mutex_is_locked(&wil->mutex));
1092 
1093 	set_bit(wil_status_resetting, wil->status);
1094 
1095 	if (wil->platform_ops.bus_request)
1096 		wil->platform_ops.bus_request(wil->platform_handle, 0);
1097 
1098 	wil_disable_irq(wil);
1099 	if (test_and_clear_bit(wil_status_napi_en, wil->status)) {
1100 		napi_disable(&wil->napi_rx);
1101 		napi_disable(&wil->napi_tx);
1102 		wil_dbg_misc(wil, "NAPI disable\n");
1103 	}
1104 	wil_enable_irq(wil);
1105 
1106 	mutex_lock(&wil->p2p_wdev_mutex);
1107 	wil_p2p_stop_radio_operations(wil);
1108 	wil_abort_scan(wil, false);
1109 	mutex_unlock(&wil->p2p_wdev_mutex);
1110 
1111 	wil_reset(wil, false);
1112 
1113 	return 0;
1114 }
1115 
1116 int wil_down(struct wil6210_priv *wil)
1117 {
1118 	int rc;
1119 
1120 	wil_dbg_misc(wil, "down\n");
1121 
1122 	wil_set_recovery_state(wil, fw_recovery_idle);
1123 	mutex_lock(&wil->mutex);
1124 	rc = __wil_down(wil);
1125 	mutex_unlock(&wil->mutex);
1126 
1127 	return rc;
1128 }
1129 
1130 int wil_find_cid(struct wil6210_priv *wil, const u8 *mac)
1131 {
1132 	int i;
1133 	int rc = -ENOENT;
1134 
1135 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1136 		if ((wil->sta[i].status != wil_sta_unused) &&
1137 		    ether_addr_equal(wil->sta[i].addr, mac)) {
1138 			rc = i;
1139 			break;
1140 		}
1141 	}
1142 
1143 	return rc;
1144 }
1145 
1146 void wil_halp_vote(struct wil6210_priv *wil)
1147 {
1148 	unsigned long rc;
1149 	unsigned long to_jiffies = msecs_to_jiffies(WAIT_FOR_HALP_VOTE_MS);
1150 
1151 	mutex_lock(&wil->halp.lock);
1152 
1153 	wil_dbg_irq(wil, "halp_vote: start, HALP ref_cnt (%d)\n",
1154 		    wil->halp.ref_cnt);
1155 
1156 	if (++wil->halp.ref_cnt == 1) {
1157 		wil6210_set_halp(wil);
1158 		rc = wait_for_completion_timeout(&wil->halp.comp, to_jiffies);
1159 		if (!rc) {
1160 			wil_err(wil, "HALP vote timed out\n");
1161 			/* Mask HALP as done in case the interrupt is raised */
1162 			wil6210_mask_halp(wil);
1163 		} else {
1164 			wil_dbg_irq(wil,
1165 				    "halp_vote: HALP vote completed after %d ms\n",
1166 				    jiffies_to_msecs(to_jiffies - rc));
1167 		}
1168 	}
1169 
1170 	wil_dbg_irq(wil, "halp_vote: end, HALP ref_cnt (%d)\n",
1171 		    wil->halp.ref_cnt);
1172 
1173 	mutex_unlock(&wil->halp.lock);
1174 }
1175 
1176 void wil_halp_unvote(struct wil6210_priv *wil)
1177 {
1178 	WARN_ON(wil->halp.ref_cnt == 0);
1179 
1180 	mutex_lock(&wil->halp.lock);
1181 
1182 	wil_dbg_irq(wil, "halp_unvote: start, HALP ref_cnt (%d)\n",
1183 		    wil->halp.ref_cnt);
1184 
1185 	if (--wil->halp.ref_cnt == 0) {
1186 		wil6210_clear_halp(wil);
1187 		wil_dbg_irq(wil, "HALP unvote\n");
1188 	}
1189 
1190 	wil_dbg_irq(wil, "halp_unvote:end, HALP ref_cnt (%d)\n",
1191 		    wil->halp.ref_cnt);
1192 
1193 	mutex_unlock(&wil->halp.lock);
1194 }
1195