main.c 31 KB

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