main.c 31 KB

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