main.c 30 KB

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