main.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160
  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. might_sleep();
  197. wil_info(wil, "%s(bssid=%pM, reason=%d, ev%s)\n", __func__, bssid,
  198. reason_code, from_event ? "+" : "-");
  199. /* Cases are:
  200. * - disconnect single STA, still connected
  201. * - disconnect single STA, already disconnected
  202. * - disconnect all
  203. *
  204. * For "disconnect all", there are 3 options:
  205. * - bssid == NULL
  206. * - bssid is broadcast address (ff:ff:ff:ff:ff:ff)
  207. * - bssid is our MAC address
  208. */
  209. if (bssid && !is_broadcast_ether_addr(bssid) &&
  210. !ether_addr_equal_unaligned(ndev->dev_addr, bssid)) {
  211. cid = wil_find_cid(wil, bssid);
  212. wil_dbg_misc(wil, "Disconnect %pM, CID=%d, reason=%d\n",
  213. bssid, cid, reason_code);
  214. if (cid >= 0) /* disconnect 1 peer */
  215. wil_disconnect_cid(wil, cid, reason_code, from_event);
  216. } else { /* all */
  217. wil_dbg_misc(wil, "Disconnect all\n");
  218. for (cid = 0; cid < WIL6210_MAX_CID; cid++)
  219. wil_disconnect_cid(wil, cid, reason_code, from_event);
  220. }
  221. /* link state */
  222. switch (wdev->iftype) {
  223. case NL80211_IFTYPE_STATION:
  224. case NL80211_IFTYPE_P2P_CLIENT:
  225. wil_bcast_fini(wil);
  226. netif_tx_stop_all_queues(ndev);
  227. netif_carrier_off(ndev);
  228. if (test_bit(wil_status_fwconnected, wil->status)) {
  229. clear_bit(wil_status_fwconnected, wil->status);
  230. cfg80211_disconnected(ndev, reason_code,
  231. NULL, 0, false, GFP_KERNEL);
  232. } else if (test_bit(wil_status_fwconnecting, wil->status)) {
  233. cfg80211_connect_result(ndev, bssid, NULL, 0, NULL, 0,
  234. WLAN_STATUS_UNSPECIFIED_FAILURE,
  235. GFP_KERNEL);
  236. }
  237. clear_bit(wil_status_fwconnecting, wil->status);
  238. break;
  239. case NL80211_IFTYPE_AP:
  240. case NL80211_IFTYPE_P2P_GO:
  241. if (!wil_ap_is_connected(wil))
  242. clear_bit(wil_status_fwconnected, wil->status);
  243. break;
  244. default:
  245. break;
  246. }
  247. }
  248. static void wil_disconnect_worker(struct work_struct *work)
  249. {
  250. struct wil6210_priv *wil = container_of(work,
  251. struct wil6210_priv, disconnect_worker);
  252. mutex_lock(&wil->mutex);
  253. _wil6210_disconnect(wil, NULL, WLAN_REASON_UNSPECIFIED, false);
  254. mutex_unlock(&wil->mutex);
  255. }
  256. static void wil_connect_timer_fn(ulong x)
  257. {
  258. struct wil6210_priv *wil = (void *)x;
  259. bool q;
  260. wil_err(wil, "Connect timeout detected, disconnect station\n");
  261. /* reschedule to thread context - disconnect won't
  262. * run from atomic context.
  263. * queue on wmi_wq to prevent race with connect event.
  264. */
  265. q = queue_work(wil->wmi_wq, &wil->disconnect_worker);
  266. wil_dbg_wmi(wil, "queue_work of disconnect_worker -> %d\n", q);
  267. }
  268. static void wil_scan_timer_fn(ulong x)
  269. {
  270. struct wil6210_priv *wil = (void *)x;
  271. clear_bit(wil_status_fwready, wil->status);
  272. wil_err(wil, "Scan timeout detected, start fw error recovery\n");
  273. wil_fw_error_recovery(wil);
  274. }
  275. static int wil_wait_for_recovery(struct wil6210_priv *wil)
  276. {
  277. if (wait_event_interruptible(wil->wq, wil->recovery_state !=
  278. fw_recovery_pending)) {
  279. wil_err(wil, "Interrupt, canceling recovery\n");
  280. return -ERESTARTSYS;
  281. }
  282. if (wil->recovery_state != fw_recovery_running) {
  283. wil_info(wil, "Recovery cancelled\n");
  284. return -EINTR;
  285. }
  286. wil_info(wil, "Proceed with recovery\n");
  287. return 0;
  288. }
  289. void wil_set_recovery_state(struct wil6210_priv *wil, int state)
  290. {
  291. wil_dbg_misc(wil, "%s(%d -> %d)\n", __func__,
  292. wil->recovery_state, state);
  293. wil->recovery_state = state;
  294. wake_up_interruptible(&wil->wq);
  295. }
  296. bool wil_is_recovery_blocked(struct wil6210_priv *wil)
  297. {
  298. return no_fw_recovery && (wil->recovery_state == fw_recovery_pending);
  299. }
  300. static void wil_fw_error_worker(struct work_struct *work)
  301. {
  302. struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
  303. fw_error_worker);
  304. struct wireless_dev *wdev = wil->wdev;
  305. wil_dbg_misc(wil, "fw error worker\n");
  306. if (!netif_running(wil_to_ndev(wil))) {
  307. wil_info(wil, "No recovery - interface is down\n");
  308. return;
  309. }
  310. /* increment @recovery_count if less then WIL6210_FW_RECOVERY_TO
  311. * passed since last recovery attempt
  312. */
  313. if (time_is_after_jiffies(wil->last_fw_recovery +
  314. WIL6210_FW_RECOVERY_TO))
  315. wil->recovery_count++;
  316. else
  317. 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);
  321. return;
  322. }
  323. wil->last_fw_recovery = jiffies;
  324. mutex_lock(&wil->mutex);
  325. switch (wdev->iftype) {
  326. case NL80211_IFTYPE_STATION:
  327. case NL80211_IFTYPE_P2P_CLIENT:
  328. case NL80211_IFTYPE_MONITOR:
  329. wil_info(wil, "fw error recovery requested (try %d)...\n",
  330. wil->recovery_count);
  331. if (!no_fw_recovery)
  332. wil->recovery_state = fw_recovery_running;
  333. if (0 != wil_wait_for_recovery(wil))
  334. break;
  335. __wil_down(wil);
  336. __wil_up(wil);
  337. break;
  338. case NL80211_IFTYPE_AP:
  339. case NL80211_IFTYPE_P2P_GO:
  340. wil_info(wil, "No recovery for AP-like interface\n");
  341. /* recovery in these modes is done by upper layers */
  342. break;
  343. default:
  344. wil_err(wil, "No recovery - unknown interface type %d\n",
  345. wdev->iftype);
  346. break;
  347. }
  348. mutex_unlock(&wil->mutex);
  349. }
  350. static int wil_find_free_vring(struct wil6210_priv *wil)
  351. {
  352. int i;
  353. for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) {
  354. if (!wil->vring_tx[i].va)
  355. return i;
  356. }
  357. return -EINVAL;
  358. }
  359. int wil_tx_init(struct wil6210_priv *wil, int cid)
  360. {
  361. int rc = -EINVAL, ringid;
  362. if (cid < 0) {
  363. wil_err(wil, "No connection pending\n");
  364. goto out;
  365. }
  366. ringid = wil_find_free_vring(wil);
  367. if (ringid < 0) {
  368. wil_err(wil, "No free vring found\n");
  369. goto out;
  370. }
  371. wil_dbg_wmi(wil, "Configure for connection CID %d vring %d\n",
  372. cid, ringid);
  373. rc = wil_vring_init_tx(wil, ringid, 1 << tx_ring_order, cid, 0);
  374. if (rc)
  375. wil_err(wil, "wil_vring_init_tx for CID %d vring %d failed\n",
  376. cid, ringid);
  377. out:
  378. return rc;
  379. }
  380. int wil_bcast_init(struct wil6210_priv *wil)
  381. {
  382. int ri = wil->bcast_vring, rc;
  383. if ((ri >= 0) && wil->vring_tx[ri].va)
  384. return 0;
  385. ri = wil_find_free_vring(wil);
  386. if (ri < 0)
  387. return ri;
  388. wil->bcast_vring = ri;
  389. rc = wil_vring_init_bcast(wil, ri, 1 << bcast_ring_order);
  390. if (rc)
  391. wil->bcast_vring = -1;
  392. return rc;
  393. }
  394. void wil_bcast_fini(struct wil6210_priv *wil)
  395. {
  396. int ri = wil->bcast_vring;
  397. if (ri < 0)
  398. return;
  399. wil->bcast_vring = -1;
  400. wil_vring_fini_tx(wil, ri);
  401. }
  402. int wil_priv_init(struct wil6210_priv *wil)
  403. {
  404. uint i;
  405. wil_dbg_misc(wil, "%s()\n", __func__);
  406. memset(wil->sta, 0, sizeof(wil->sta));
  407. for (i = 0; i < WIL6210_MAX_CID; i++)
  408. spin_lock_init(&wil->sta[i].tid_rx_lock);
  409. for (i = 0; i < WIL6210_MAX_TX_RINGS; i++)
  410. spin_lock_init(&wil->vring_tx_data[i].lock);
  411. mutex_init(&wil->mutex);
  412. mutex_init(&wil->wmi_mutex);
  413. mutex_init(&wil->probe_client_mutex);
  414. mutex_init(&wil->p2p_wdev_mutex);
  415. mutex_init(&wil->halp.lock);
  416. init_completion(&wil->wmi_ready);
  417. init_completion(&wil->wmi_call);
  418. init_completion(&wil->halp.comp);
  419. wil->bcast_vring = -1;
  420. setup_timer(&wil->connect_timer, wil_connect_timer_fn, (ulong)wil);
  421. setup_timer(&wil->scan_timer, wil_scan_timer_fn, (ulong)wil);
  422. setup_timer(&wil->p2p.discovery_timer, wil_p2p_discovery_timer_fn,
  423. (ulong)wil);
  424. INIT_WORK(&wil->disconnect_worker, wil_disconnect_worker);
  425. INIT_WORK(&wil->wmi_event_worker, wmi_event_worker);
  426. INIT_WORK(&wil->fw_error_worker, wil_fw_error_worker);
  427. INIT_WORK(&wil->probe_client_worker, wil_probe_client_worker);
  428. INIT_LIST_HEAD(&wil->pending_wmi_ev);
  429. INIT_LIST_HEAD(&wil->probe_client_pending);
  430. spin_lock_init(&wil->wmi_ev_lock);
  431. init_waitqueue_head(&wil->wq);
  432. wil->wmi_wq = create_singlethread_workqueue(WIL_NAME "_wmi");
  433. if (!wil->wmi_wq)
  434. return -EAGAIN;
  435. wil->wq_service = create_singlethread_workqueue(WIL_NAME "_service");
  436. if (!wil->wq_service)
  437. goto out_wmi_wq;
  438. wil->last_fw_recovery = jiffies;
  439. wil->tx_interframe_timeout = WIL6210_ITR_TX_INTERFRAME_TIMEOUT_DEFAULT;
  440. wil->rx_interframe_timeout = WIL6210_ITR_RX_INTERFRAME_TIMEOUT_DEFAULT;
  441. wil->tx_max_burst_duration = WIL6210_ITR_TX_MAX_BURST_DURATION_DEFAULT;
  442. wil->rx_max_burst_duration = WIL6210_ITR_RX_MAX_BURST_DURATION_DEFAULT;
  443. if (rx_ring_overflow_thrsh == WIL6210_RX_HIGH_TRSH_INIT)
  444. rx_ring_overflow_thrsh = WIL6210_RX_HIGH_TRSH_DEFAULT;
  445. return 0;
  446. out_wmi_wq:
  447. destroy_workqueue(wil->wmi_wq);
  448. return -EAGAIN;
  449. }
  450. /**
  451. * wil6210_disconnect - disconnect one connection
  452. * @wil: driver context
  453. * @bssid: peer to disconnect, NULL to disconnect all
  454. * @reason_code: Reason code for the Disassociation frame
  455. * @from_event: whether is invoked from FW event handler
  456. *
  457. * Disconnect and release associated resources. If invoked not from the
  458. * FW event handler, issue WMI command(s) to trigger MAC disconnect.
  459. */
  460. void wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid,
  461. u16 reason_code, bool from_event)
  462. {
  463. wil_dbg_misc(wil, "%s()\n", __func__);
  464. del_timer_sync(&wil->connect_timer);
  465. _wil6210_disconnect(wil, bssid, reason_code, from_event);
  466. }
  467. void wil_priv_deinit(struct wil6210_priv *wil)
  468. {
  469. wil_dbg_misc(wil, "%s()\n", __func__);
  470. wil_set_recovery_state(wil, fw_recovery_idle);
  471. del_timer_sync(&wil->scan_timer);
  472. del_timer_sync(&wil->p2p.discovery_timer);
  473. cancel_work_sync(&wil->disconnect_worker);
  474. cancel_work_sync(&wil->fw_error_worker);
  475. cancel_work_sync(&wil->p2p.discovery_expired_work);
  476. mutex_lock(&wil->mutex);
  477. wil6210_disconnect(wil, NULL, WLAN_REASON_DEAUTH_LEAVING, false);
  478. mutex_unlock(&wil->mutex);
  479. wmi_event_flush(wil);
  480. wil_probe_client_flush(wil);
  481. cancel_work_sync(&wil->probe_client_worker);
  482. destroy_workqueue(wil->wq_service);
  483. destroy_workqueue(wil->wmi_wq);
  484. }
  485. static inline void wil_halt_cpu(struct wil6210_priv *wil)
  486. {
  487. wil_w(wil, RGF_USER_USER_CPU_0, BIT_USER_USER_CPU_MAN_RST);
  488. wil_w(wil, RGF_USER_MAC_CPU_0, BIT_USER_MAC_CPU_MAN_RST);
  489. }
  490. static inline void wil_release_cpu(struct wil6210_priv *wil)
  491. {
  492. /* Start CPU */
  493. wil_w(wil, RGF_USER_USER_CPU_0, 1);
  494. }
  495. static void wil_set_oob_mode(struct wil6210_priv *wil, bool enable)
  496. {
  497. wil_info(wil, "%s: enable=%d\n", __func__, enable);
  498. if (enable)
  499. wil_s(wil, RGF_USER_USAGE_6, BIT_USER_OOB_MODE);
  500. else
  501. wil_c(wil, RGF_USER_USAGE_6, BIT_USER_OOB_MODE);
  502. }
  503. static int wil_target_reset(struct wil6210_priv *wil)
  504. {
  505. int delay = 0;
  506. u32 x, x1 = 0;
  507. wil_dbg_misc(wil, "Resetting \"%s\"...\n", wil->hw_name);
  508. /* Clear MAC link up */
  509. wil_s(wil, RGF_HP_CTRL, BIT(15));
  510. wil_s(wil, RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT_HPAL_PERST_FROM_PAD);
  511. wil_s(wil, RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT_CAR_PERST_RST);
  512. wil_halt_cpu(wil);
  513. /* clear all boot loader "ready" bits */
  514. wil_w(wil, RGF_USER_BL +
  515. offsetof(struct bl_dedicated_registers_v0, boot_loader_ready), 0);
  516. /* Clear Fw Download notification */
  517. wil_c(wil, RGF_USER_USAGE_6, BIT(0));
  518. wil_s(wil, RGF_CAF_OSC_CONTROL, BIT_CAF_OSC_XTAL_EN);
  519. /* XTAL stabilization should take about 3ms */
  520. usleep_range(5000, 7000);
  521. x = wil_r(wil, RGF_CAF_PLL_LOCK_STATUS);
  522. if (!(x & BIT_CAF_OSC_DIG_XTAL_STABLE)) {
  523. wil_err(wil, "Xtal stabilization timeout\n"
  524. "RGF_CAF_PLL_LOCK_STATUS = 0x%08x\n", x);
  525. return -ETIME;
  526. }
  527. /* switch 10k to XTAL*/
  528. wil_c(wil, RGF_USER_SPARROW_M_4, BIT_SPARROW_M_4_SEL_SLEEP_OR_REF);
  529. /* 40 MHz */
  530. wil_c(wil, RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_CAR_AHB_SW_SEL);
  531. wil_w(wil, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x3ff81f);
  532. wil_w(wil, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0xf);
  533. wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0xFE000000);
  534. wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0x0000003F);
  535. wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x000000f0);
  536. wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0xFFE7FE00);
  537. wil_w(wil, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x0);
  538. wil_w(wil, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0x0);
  539. wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0);
  540. wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0);
  541. wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0);
  542. wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
  543. wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000003);
  544. /* reset A2 PCIE AHB */
  545. wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00008000);
  546. wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
  547. /* wait until device ready. typical time is 20..80 msec */
  548. do {
  549. msleep(RST_DELAY);
  550. x = wil_r(wil, RGF_USER_BL +
  551. offsetof(struct bl_dedicated_registers_v0,
  552. boot_loader_ready));
  553. if (x1 != x) {
  554. wil_dbg_misc(wil, "BL.ready 0x%08x => 0x%08x\n", x1, x);
  555. x1 = x;
  556. }
  557. if (delay++ > RST_COUNT) {
  558. wil_err(wil, "Reset not completed, bl.ready 0x%08x\n",
  559. x);
  560. return -ETIME;
  561. }
  562. } while (x != BL_READY);
  563. wil_c(wil, RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_RST_PWGD);
  564. /* enable fix for HW bug related to the SA/DA swap in AP Rx */
  565. wil_s(wil, RGF_DMA_OFUL_NID_0, BIT_DMA_OFUL_NID_0_RX_EXT_TR_EN |
  566. BIT_DMA_OFUL_NID_0_RX_EXT_A3_SRC);
  567. wil_dbg_misc(wil, "Reset completed in %d ms\n", delay * RST_DELAY);
  568. return 0;
  569. }
  570. void wil_mbox_ring_le2cpus(struct wil6210_mbox_ring *r)
  571. {
  572. le32_to_cpus(&r->base);
  573. le16_to_cpus(&r->entry_size);
  574. le16_to_cpus(&r->size);
  575. le32_to_cpus(&r->tail);
  576. le32_to_cpus(&r->head);
  577. }
  578. static int wil_get_bl_info(struct wil6210_priv *wil)
  579. {
  580. struct net_device *ndev = wil_to_ndev(wil);
  581. struct wiphy *wiphy = wil_to_wiphy(wil);
  582. union {
  583. struct bl_dedicated_registers_v0 bl0;
  584. struct bl_dedicated_registers_v1 bl1;
  585. } bl;
  586. u32 bl_ver;
  587. u8 *mac;
  588. u16 rf_status;
  589. wil_memcpy_fromio_32(&bl, wil->csr + HOSTADDR(RGF_USER_BL),
  590. sizeof(bl));
  591. bl_ver = le32_to_cpu(bl.bl0.boot_loader_struct_version);
  592. mac = bl.bl0.mac_address;
  593. if (bl_ver == 0) {
  594. le32_to_cpus(&bl.bl0.rf_type);
  595. le32_to_cpus(&bl.bl0.baseband_type);
  596. rf_status = 0; /* actually, unknown */
  597. wil_info(wil,
  598. "Boot Loader struct v%d: MAC = %pM RF = 0x%08x bband = 0x%08x\n",
  599. bl_ver, mac,
  600. bl.bl0.rf_type, bl.bl0.baseband_type);
  601. wil_info(wil, "Boot Loader build unknown for struct v0\n");
  602. } else {
  603. le16_to_cpus(&bl.bl1.rf_type);
  604. rf_status = le16_to_cpu(bl.bl1.rf_status);
  605. le32_to_cpus(&bl.bl1.baseband_type);
  606. le16_to_cpus(&bl.bl1.bl_version_subminor);
  607. le16_to_cpus(&bl.bl1.bl_version_build);
  608. wil_info(wil,
  609. "Boot Loader struct v%d: MAC = %pM RF = 0x%04x (status 0x%04x) bband = 0x%08x\n",
  610. bl_ver, mac,
  611. bl.bl1.rf_type, rf_status,
  612. bl.bl1.baseband_type);
  613. wil_info(wil, "Boot Loader build %d.%d.%d.%d\n",
  614. bl.bl1.bl_version_major, bl.bl1.bl_version_minor,
  615. bl.bl1.bl_version_subminor, bl.bl1.bl_version_build);
  616. }
  617. if (!is_valid_ether_addr(mac)) {
  618. wil_err(wil, "BL: Invalid MAC %pM\n", mac);
  619. return -EINVAL;
  620. }
  621. ether_addr_copy(ndev->perm_addr, mac);
  622. ether_addr_copy(wiphy->perm_addr, mac);
  623. if (!is_valid_ether_addr(ndev->dev_addr))
  624. ether_addr_copy(ndev->dev_addr, mac);
  625. if (rf_status) {/* bad RF cable? */
  626. wil_err(wil, "RF communication error 0x%04x",
  627. rf_status);
  628. return -EAGAIN;
  629. }
  630. return 0;
  631. }
  632. static void wil_bl_crash_info(struct wil6210_priv *wil, bool is_err)
  633. {
  634. u32 bl_assert_code, bl_assert_blink, bl_magic_number;
  635. u32 bl_ver = wil_r(wil, RGF_USER_BL +
  636. offsetof(struct bl_dedicated_registers_v0,
  637. boot_loader_struct_version));
  638. if (bl_ver < 2)
  639. return;
  640. bl_assert_code = wil_r(wil, RGF_USER_BL +
  641. offsetof(struct bl_dedicated_registers_v1,
  642. bl_assert_code));
  643. bl_assert_blink = wil_r(wil, RGF_USER_BL +
  644. offsetof(struct bl_dedicated_registers_v1,
  645. bl_assert_blink));
  646. bl_magic_number = wil_r(wil, RGF_USER_BL +
  647. offsetof(struct bl_dedicated_registers_v1,
  648. bl_magic_number));
  649. if (is_err) {
  650. wil_err(wil,
  651. "BL assert code 0x%08x blink 0x%08x magic 0x%08x\n",
  652. bl_assert_code, bl_assert_blink, bl_magic_number);
  653. } else {
  654. wil_dbg_misc(wil,
  655. "BL assert code 0x%08x blink 0x%08x magic 0x%08x\n",
  656. bl_assert_code, bl_assert_blink, bl_magic_number);
  657. }
  658. }
  659. static int wil_wait_for_fw_ready(struct wil6210_priv *wil)
  660. {
  661. ulong to = msecs_to_jiffies(1000);
  662. ulong left = wait_for_completion_timeout(&wil->wmi_ready, to);
  663. if (0 == left) {
  664. wil_err(wil, "Firmware not ready\n");
  665. return -ETIME;
  666. } else {
  667. wil_info(wil, "FW ready after %d ms. HW version 0x%08x\n",
  668. jiffies_to_msecs(to-left), wil->hw_version);
  669. }
  670. return 0;
  671. }
  672. /*
  673. * We reset all the structures, and we reset the UMAC.
  674. * After calling this routine, you're expected to reload
  675. * the firmware.
  676. */
  677. int wil_reset(struct wil6210_priv *wil, bool load_fw)
  678. {
  679. int rc;
  680. wil_dbg_misc(wil, "%s()\n", __func__);
  681. WARN_ON(!mutex_is_locked(&wil->mutex));
  682. WARN_ON(test_bit(wil_status_napi_en, wil->status));
  683. if (debug_fw) {
  684. static const u8 mac[ETH_ALEN] = {
  685. 0x00, 0xde, 0xad, 0x12, 0x34, 0x56,
  686. };
  687. struct net_device *ndev = wil_to_ndev(wil);
  688. ether_addr_copy(ndev->perm_addr, mac);
  689. ether_addr_copy(ndev->dev_addr, ndev->perm_addr);
  690. return 0;
  691. }
  692. if (wil->hw_version == HW_VER_UNKNOWN)
  693. return -ENODEV;
  694. if (wil->platform_ops.notify) {
  695. rc = wil->platform_ops.notify(wil->platform_handle,
  696. WIL_PLATFORM_EVT_PRE_RESET);
  697. if (rc)
  698. wil_err(wil,
  699. "%s: PRE_RESET platform notify failed, rc %d\n",
  700. __func__, rc);
  701. }
  702. set_bit(wil_status_resetting, wil->status);
  703. cancel_work_sync(&wil->disconnect_worker);
  704. wil6210_disconnect(wil, NULL, WLAN_REASON_DEAUTH_LEAVING, false);
  705. wil_bcast_fini(wil);
  706. /* Disable device led before reset*/
  707. wmi_led_cfg(wil, false);
  708. /* prevent NAPI from being scheduled and prevent wmi commands */
  709. mutex_lock(&wil->wmi_mutex);
  710. bitmap_zero(wil->status, wil_status_last);
  711. mutex_unlock(&wil->wmi_mutex);
  712. if (wil->scan_request) {
  713. struct cfg80211_scan_info info = {
  714. .aborted = true,
  715. };
  716. wil_dbg_misc(wil, "Abort scan_request 0x%p\n",
  717. wil->scan_request);
  718. del_timer_sync(&wil->scan_timer);
  719. cfg80211_scan_done(wil->scan_request, &info);
  720. wil->scan_request = NULL;
  721. }
  722. wil_mask_irq(wil);
  723. wmi_event_flush(wil);
  724. flush_workqueue(wil->wq_service);
  725. flush_workqueue(wil->wmi_wq);
  726. wil_bl_crash_info(wil, false);
  727. rc = wil_target_reset(wil);
  728. wil_rx_fini(wil);
  729. if (rc) {
  730. wil_bl_crash_info(wil, true);
  731. return rc;
  732. }
  733. rc = wil_get_bl_info(wil);
  734. if (rc == -EAGAIN && !load_fw) /* ignore RF error if not going up */
  735. rc = 0;
  736. if (rc)
  737. return rc;
  738. wil_set_oob_mode(wil, oob_mode);
  739. if (load_fw) {
  740. wil_info(wil, "Use firmware <%s> + board <%s>\n", WIL_FW_NAME,
  741. WIL_FW2_NAME);
  742. wil_halt_cpu(wil);
  743. /* Loading f/w from the file */
  744. rc = wil_request_firmware(wil, WIL_FW_NAME);
  745. if (rc)
  746. return rc;
  747. rc = wil_request_firmware(wil, WIL_FW2_NAME);
  748. if (rc)
  749. return rc;
  750. /* Mark FW as loaded from host */
  751. wil_s(wil, RGF_USER_USAGE_6, 1);
  752. /* clear any interrupts which on-card-firmware
  753. * may have set
  754. */
  755. wil6210_clear_irq(wil);
  756. /* CAF_ICR - clear and mask */
  757. /* it is W1C, clear by writing back same value */
  758. wil_s(wil, RGF_CAF_ICR + offsetof(struct RGF_ICR, ICR), 0);
  759. wil_w(wil, RGF_CAF_ICR + offsetof(struct RGF_ICR, IMV), ~0);
  760. wil_release_cpu(wil);
  761. }
  762. /* init after reset */
  763. wil->ap_isolate = 0;
  764. reinit_completion(&wil->wmi_ready);
  765. reinit_completion(&wil->wmi_call);
  766. reinit_completion(&wil->halp.comp);
  767. if (load_fw) {
  768. wil_configure_interrupt_moderation(wil);
  769. wil_unmask_irq(wil);
  770. /* we just started MAC, wait for FW ready */
  771. rc = wil_wait_for_fw_ready(wil);
  772. if (rc)
  773. return rc;
  774. /* check FW is responsive */
  775. rc = wmi_echo(wil);
  776. if (rc) {
  777. wil_err(wil, "%s: wmi_echo failed, rc %d\n",
  778. __func__, rc);
  779. return rc;
  780. }
  781. if (wil->platform_ops.notify) {
  782. rc = wil->platform_ops.notify(wil->platform_handle,
  783. WIL_PLATFORM_EVT_FW_RDY);
  784. if (rc) {
  785. wil_err(wil,
  786. "%s: FW_RDY notify failed, rc %d\n",
  787. __func__, rc);
  788. rc = 0;
  789. }
  790. }
  791. }
  792. return rc;
  793. }
  794. void wil_fw_error_recovery(struct wil6210_priv *wil)
  795. {
  796. wil_dbg_misc(wil, "starting fw error recovery\n");
  797. if (test_bit(wil_status_resetting, wil->status)) {
  798. wil_info(wil, "Reset already in progress\n");
  799. return;
  800. }
  801. wil->recovery_state = fw_recovery_pending;
  802. schedule_work(&wil->fw_error_worker);
  803. }
  804. int __wil_up(struct wil6210_priv *wil)
  805. {
  806. struct net_device *ndev = wil_to_ndev(wil);
  807. struct wireless_dev *wdev = wil->wdev;
  808. int rc;
  809. WARN_ON(!mutex_is_locked(&wil->mutex));
  810. rc = wil_reset(wil, true);
  811. if (rc)
  812. return rc;
  813. /* Rx VRING. After MAC and beacon */
  814. rc = wil_rx_init(wil, 1 << rx_ring_order);
  815. if (rc)
  816. return rc;
  817. switch (wdev->iftype) {
  818. case NL80211_IFTYPE_STATION:
  819. wil_dbg_misc(wil, "type: STATION\n");
  820. ndev->type = ARPHRD_ETHER;
  821. break;
  822. case NL80211_IFTYPE_AP:
  823. wil_dbg_misc(wil, "type: AP\n");
  824. ndev->type = ARPHRD_ETHER;
  825. break;
  826. case NL80211_IFTYPE_P2P_CLIENT:
  827. wil_dbg_misc(wil, "type: P2P_CLIENT\n");
  828. ndev->type = ARPHRD_ETHER;
  829. break;
  830. case NL80211_IFTYPE_P2P_GO:
  831. wil_dbg_misc(wil, "type: P2P_GO\n");
  832. ndev->type = ARPHRD_ETHER;
  833. break;
  834. case NL80211_IFTYPE_MONITOR:
  835. wil_dbg_misc(wil, "type: Monitor\n");
  836. ndev->type = ARPHRD_IEEE80211_RADIOTAP;
  837. /* ARPHRD_IEEE80211 or ARPHRD_IEEE80211_RADIOTAP ? */
  838. break;
  839. default:
  840. return -EOPNOTSUPP;
  841. }
  842. /* MAC address - pre-requisite for other commands */
  843. wmi_set_mac_address(wil, ndev->dev_addr);
  844. wil_dbg_misc(wil, "NAPI enable\n");
  845. napi_enable(&wil->napi_rx);
  846. napi_enable(&wil->napi_tx);
  847. set_bit(wil_status_napi_en, wil->status);
  848. if (wil->platform_ops.bus_request)
  849. wil->platform_ops.bus_request(wil->platform_handle,
  850. WIL_MAX_BUS_REQUEST_KBPS);
  851. return 0;
  852. }
  853. int wil_up(struct wil6210_priv *wil)
  854. {
  855. int rc;
  856. wil_dbg_misc(wil, "%s()\n", __func__);
  857. mutex_lock(&wil->mutex);
  858. rc = __wil_up(wil);
  859. mutex_unlock(&wil->mutex);
  860. return rc;
  861. }
  862. int __wil_down(struct wil6210_priv *wil)
  863. {
  864. int rc;
  865. WARN_ON(!mutex_is_locked(&wil->mutex));
  866. if (wil->platform_ops.bus_request)
  867. wil->platform_ops.bus_request(wil->platform_handle, 0);
  868. wil_disable_irq(wil);
  869. if (test_and_clear_bit(wil_status_napi_en, wil->status)) {
  870. napi_disable(&wil->napi_rx);
  871. napi_disable(&wil->napi_tx);
  872. wil_dbg_misc(wil, "NAPI disable\n");
  873. }
  874. wil_enable_irq(wil);
  875. (void)wil_p2p_stop_discovery(wil);
  876. if (wil->scan_request) {
  877. struct cfg80211_scan_info info = {
  878. .aborted = true,
  879. };
  880. wil_dbg_misc(wil, "Abort scan_request 0x%p\n",
  881. wil->scan_request);
  882. del_timer_sync(&wil->scan_timer);
  883. cfg80211_scan_done(wil->scan_request, &info);
  884. wil->scan_request = NULL;
  885. }
  886. if (test_bit(wil_status_fwconnected, wil->status) ||
  887. test_bit(wil_status_fwconnecting, wil->status)) {
  888. mutex_unlock(&wil->mutex);
  889. rc = wmi_call(wil, WMI_DISCONNECT_CMDID, NULL, 0,
  890. WMI_DISCONNECT_EVENTID, NULL, 0,
  891. WIL6210_DISCONNECT_TO_MS);
  892. mutex_lock(&wil->mutex);
  893. if (rc)
  894. wil_err(wil, "timeout waiting for disconnect\n");
  895. }
  896. wil_reset(wil, false);
  897. return 0;
  898. }
  899. int wil_down(struct wil6210_priv *wil)
  900. {
  901. int rc;
  902. wil_dbg_misc(wil, "%s()\n", __func__);
  903. wil_set_recovery_state(wil, fw_recovery_idle);
  904. mutex_lock(&wil->mutex);
  905. rc = __wil_down(wil);
  906. mutex_unlock(&wil->mutex);
  907. return rc;
  908. }
  909. int wil_find_cid(struct wil6210_priv *wil, const u8 *mac)
  910. {
  911. int i;
  912. int rc = -ENOENT;
  913. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  914. if ((wil->sta[i].status != wil_sta_unused) &&
  915. ether_addr_equal(wil->sta[i].addr, mac)) {
  916. rc = i;
  917. break;
  918. }
  919. }
  920. return rc;
  921. }
  922. void wil_halp_vote(struct wil6210_priv *wil)
  923. {
  924. unsigned long rc;
  925. unsigned long to_jiffies = msecs_to_jiffies(WAIT_FOR_HALP_VOTE_MS);
  926. mutex_lock(&wil->halp.lock);
  927. wil_dbg_misc(wil, "%s: start, HALP ref_cnt (%d)\n", __func__,
  928. wil->halp.ref_cnt);
  929. if (++wil->halp.ref_cnt == 1) {
  930. wil6210_set_halp(wil);
  931. rc = wait_for_completion_timeout(&wil->halp.comp, to_jiffies);
  932. if (!rc)
  933. wil_err(wil, "%s: HALP vote timed out\n", __func__);
  934. else
  935. wil_dbg_misc(wil,
  936. "%s: HALP vote completed after %d ms\n",
  937. __func__,
  938. jiffies_to_msecs(to_jiffies - rc));
  939. }
  940. wil_dbg_misc(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_misc(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_misc(wil, "%s: HALP unvote\n", __func__);
  953. }
  954. wil_dbg_misc(wil, "%s: end, HALP ref_cnt (%d)\n", __func__,
  955. wil->halp.ref_cnt);
  956. mutex_unlock(&wil->halp.lock);
  957. }