main.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. /*
  2. * Copyright (c) 2012-2014 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. static bool no_fw_recovery;
  22. module_param(no_fw_recovery, bool, S_IRUGO | S_IWUSR);
  23. MODULE_PARM_DESC(no_fw_recovery, " disable FW error recovery");
  24. /*
  25. * Due to a hardware issue,
  26. * one has to read/write to/from NIC in 32-bit chunks;
  27. * regular memcpy_fromio and siblings will
  28. * not work on 64-bit platform - it uses 64-bit transactions
  29. *
  30. * Force 32-bit transactions to enable NIC on 64-bit platforms
  31. *
  32. * To avoid byte swap on big endian host, __raw_{read|write}l
  33. * should be used - {read|write}l would swap bytes to provide
  34. * little endian on PCI value in host endianness.
  35. */
  36. void wil_memcpy_fromio_32(void *dst, const volatile void __iomem *src,
  37. size_t count)
  38. {
  39. u32 *d = dst;
  40. const volatile u32 __iomem *s = src;
  41. /* size_t is unsigned, if (count%4 != 0) it will wrap */
  42. for (count += 4; count > 4; count -= 4)
  43. *d++ = __raw_readl(s++);
  44. }
  45. void wil_memcpy_toio_32(volatile void __iomem *dst, const void *src,
  46. size_t count)
  47. {
  48. volatile u32 __iomem *d = dst;
  49. const u32 *s = src;
  50. for (count += 4; count > 4; count -= 4)
  51. __raw_writel(*s++, d++);
  52. }
  53. static void wil_disconnect_cid(struct wil6210_priv *wil, int cid)
  54. {
  55. uint i;
  56. struct net_device *ndev = wil_to_ndev(wil);
  57. struct wireless_dev *wdev = wil->wdev;
  58. struct wil_sta_info *sta = &wil->sta[cid];
  59. wil_dbg_misc(wil, "%s(CID %d, status %d)\n", __func__, cid,
  60. sta->status);
  61. sta->data_port_open = false;
  62. if (sta->status != wil_sta_unused) {
  63. wmi_disconnect_sta(wil, sta->addr, WLAN_REASON_DEAUTH_LEAVING);
  64. switch (wdev->iftype) {
  65. case NL80211_IFTYPE_AP:
  66. case NL80211_IFTYPE_P2P_GO:
  67. /* AP-like interface */
  68. cfg80211_del_sta(ndev, sta->addr, GFP_KERNEL);
  69. break;
  70. default:
  71. break;
  72. }
  73. sta->status = wil_sta_unused;
  74. }
  75. for (i = 0; i < WIL_STA_TID_NUM; i++) {
  76. struct wil_tid_ampdu_rx *r = sta->tid_rx[i];
  77. sta->tid_rx[i] = NULL;
  78. wil_tid_ampdu_rx_free(wil, r);
  79. }
  80. for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
  81. if (wil->vring2cid_tid[i][0] == cid)
  82. wil_vring_fini_tx(wil, i);
  83. }
  84. memset(&sta->stats, 0, sizeof(sta->stats));
  85. }
  86. static void _wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid)
  87. {
  88. int cid = -ENOENT;
  89. struct net_device *ndev = wil_to_ndev(wil);
  90. struct wireless_dev *wdev = wil->wdev;
  91. might_sleep();
  92. if (bssid) {
  93. cid = wil_find_cid(wil, bssid);
  94. wil_dbg_misc(wil, "%s(%pM, CID %d)\n", __func__, bssid, cid);
  95. } else {
  96. wil_dbg_misc(wil, "%s(all)\n", __func__);
  97. }
  98. if (cid >= 0) /* disconnect 1 peer */
  99. wil_disconnect_cid(wil, cid);
  100. else /* disconnect all */
  101. for (cid = 0; cid < WIL6210_MAX_CID; cid++)
  102. wil_disconnect_cid(wil, cid);
  103. /* link state */
  104. switch (wdev->iftype) {
  105. case NL80211_IFTYPE_STATION:
  106. case NL80211_IFTYPE_P2P_CLIENT:
  107. wil_link_off(wil);
  108. if (test_bit(wil_status_fwconnected, &wil->status)) {
  109. clear_bit(wil_status_fwconnected, &wil->status);
  110. cfg80211_disconnected(ndev,
  111. WLAN_STATUS_UNSPECIFIED_FAILURE,
  112. NULL, 0, GFP_KERNEL);
  113. } else if (test_bit(wil_status_fwconnecting, &wil->status)) {
  114. cfg80211_connect_result(ndev, bssid, NULL, 0, NULL, 0,
  115. WLAN_STATUS_UNSPECIFIED_FAILURE,
  116. GFP_KERNEL);
  117. }
  118. clear_bit(wil_status_fwconnecting, &wil->status);
  119. break;
  120. default:
  121. break;
  122. }
  123. }
  124. static void wil_disconnect_worker(struct work_struct *work)
  125. {
  126. struct wil6210_priv *wil = container_of(work,
  127. struct wil6210_priv, disconnect_worker);
  128. mutex_lock(&wil->mutex);
  129. _wil6210_disconnect(wil, NULL);
  130. mutex_unlock(&wil->mutex);
  131. }
  132. static void wil_connect_timer_fn(ulong x)
  133. {
  134. struct wil6210_priv *wil = (void *)x;
  135. wil_dbg_misc(wil, "Connect timeout\n");
  136. /* reschedule to thread context - disconnect won't
  137. * run from atomic context
  138. */
  139. schedule_work(&wil->disconnect_worker);
  140. }
  141. static void wil_scan_timer_fn(ulong x)
  142. {
  143. struct wil6210_priv *wil = (void *)x;
  144. clear_bit(wil_status_fwready, &wil->status);
  145. wil_err(wil, "Scan timeout detected, start fw error recovery\n");
  146. schedule_work(&wil->fw_error_worker);
  147. }
  148. static void wil_fw_error_worker(struct work_struct *work)
  149. {
  150. struct wil6210_priv *wil = container_of(work,
  151. struct wil6210_priv, fw_error_worker);
  152. struct wireless_dev *wdev = wil->wdev;
  153. wil_dbg_misc(wil, "fw error worker\n");
  154. if (no_fw_recovery)
  155. return;
  156. /* increment @recovery_count if less then WIL6210_FW_RECOVERY_TO
  157. * passed since last recovery attempt
  158. */
  159. if (time_is_after_jiffies(wil->last_fw_recovery +
  160. WIL6210_FW_RECOVERY_TO))
  161. wil->recovery_count++;
  162. else
  163. wil->recovery_count = 1; /* fw was alive for a long time */
  164. if (wil->recovery_count > WIL6210_FW_RECOVERY_RETRIES) {
  165. wil_err(wil, "too many recovery attempts (%d), giving up\n",
  166. wil->recovery_count);
  167. return;
  168. }
  169. wil->last_fw_recovery = jiffies;
  170. mutex_lock(&wil->mutex);
  171. switch (wdev->iftype) {
  172. case NL80211_IFTYPE_STATION:
  173. case NL80211_IFTYPE_P2P_CLIENT:
  174. case NL80211_IFTYPE_MONITOR:
  175. wil_info(wil, "fw error recovery started (try %d)...\n",
  176. wil->recovery_count);
  177. wil_reset(wil);
  178. /* need to re-allocate Rx ring after reset */
  179. wil_rx_init(wil);
  180. break;
  181. case NL80211_IFTYPE_AP:
  182. case NL80211_IFTYPE_P2P_GO:
  183. /* recovery in these modes is done by upper layers */
  184. break;
  185. default:
  186. break;
  187. }
  188. mutex_unlock(&wil->mutex);
  189. }
  190. static int wil_find_free_vring(struct wil6210_priv *wil)
  191. {
  192. int i;
  193. for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) {
  194. if (!wil->vring_tx[i].va)
  195. return i;
  196. }
  197. return -EINVAL;
  198. }
  199. static void wil_connect_worker(struct work_struct *work)
  200. {
  201. int rc;
  202. struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
  203. connect_worker);
  204. int cid = wil->pending_connect_cid;
  205. int ringid = wil_find_free_vring(wil);
  206. if (cid < 0) {
  207. wil_err(wil, "No connection pending\n");
  208. return;
  209. }
  210. wil_dbg_wmi(wil, "Configure for connection CID %d\n", cid);
  211. rc = wil_vring_init_tx(wil, ringid, WIL6210_TX_RING_SIZE, cid, 0);
  212. wil->pending_connect_cid = -1;
  213. if (rc == 0) {
  214. wil->sta[cid].status = wil_sta_connected;
  215. wil_link_on(wil);
  216. } else {
  217. wil->sta[cid].status = wil_sta_unused;
  218. }
  219. }
  220. int wil_priv_init(struct wil6210_priv *wil)
  221. {
  222. wil_dbg_misc(wil, "%s()\n", __func__);
  223. memset(wil->sta, 0, sizeof(wil->sta));
  224. mutex_init(&wil->mutex);
  225. mutex_init(&wil->wmi_mutex);
  226. init_completion(&wil->wmi_ready);
  227. wil->pending_connect_cid = -1;
  228. setup_timer(&wil->connect_timer, wil_connect_timer_fn, (ulong)wil);
  229. setup_timer(&wil->scan_timer, wil_scan_timer_fn, (ulong)wil);
  230. INIT_WORK(&wil->connect_worker, wil_connect_worker);
  231. INIT_WORK(&wil->disconnect_worker, wil_disconnect_worker);
  232. INIT_WORK(&wil->wmi_event_worker, wmi_event_worker);
  233. INIT_WORK(&wil->fw_error_worker, wil_fw_error_worker);
  234. INIT_LIST_HEAD(&wil->pending_wmi_ev);
  235. spin_lock_init(&wil->wmi_ev_lock);
  236. wil->wmi_wq = create_singlethread_workqueue(WIL_NAME"_wmi");
  237. if (!wil->wmi_wq)
  238. return -EAGAIN;
  239. wil->wmi_wq_conn = create_singlethread_workqueue(WIL_NAME"_connect");
  240. if (!wil->wmi_wq_conn) {
  241. destroy_workqueue(wil->wmi_wq);
  242. return -EAGAIN;
  243. }
  244. wil->last_fw_recovery = jiffies;
  245. return 0;
  246. }
  247. void wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid)
  248. {
  249. del_timer_sync(&wil->connect_timer);
  250. _wil6210_disconnect(wil, bssid);
  251. }
  252. void wil_priv_deinit(struct wil6210_priv *wil)
  253. {
  254. del_timer_sync(&wil->scan_timer);
  255. cancel_work_sync(&wil->disconnect_worker);
  256. cancel_work_sync(&wil->fw_error_worker);
  257. mutex_lock(&wil->mutex);
  258. wil6210_disconnect(wil, NULL);
  259. mutex_unlock(&wil->mutex);
  260. wmi_event_flush(wil);
  261. destroy_workqueue(wil->wmi_wq_conn);
  262. destroy_workqueue(wil->wmi_wq);
  263. }
  264. static void wil_target_reset(struct wil6210_priv *wil)
  265. {
  266. int delay = 0;
  267. u32 hw_state;
  268. u32 rev_id;
  269. bool is_sparrow = (wil->board->board == WIL_BOARD_SPARROW);
  270. wil_dbg_misc(wil, "Resetting \"%s\"...\n", wil->board->name);
  271. /* register read */
  272. #define R(a) ioread32(wil->csr + HOSTADDR(a))
  273. /* register write */
  274. #define W(a, v) iowrite32(v, wil->csr + HOSTADDR(a))
  275. /* register set = read, OR, write */
  276. #define S(a, v) W(a, R(a) | v)
  277. /* register clear = read, AND with inverted, write */
  278. #define C(a, v) W(a, R(a) & ~v)
  279. wmb(); /* If host reorder writes here -> race in NIC */
  280. W(RGF_USER_MAC_CPU_0, BIT(1)); /* mac_cpu_man_rst */
  281. wil->hw_version = R(RGF_USER_FW_REV_ID);
  282. rev_id = wil->hw_version & 0xff;
  283. /* Clear MAC link up */
  284. S(RGF_HP_CTRL, BIT(15));
  285. /* hpal_perst_from_pad_src_n_mask */
  286. S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT(6));
  287. /* car_perst_rst_src_n_mask */
  288. S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT(7));
  289. wmb(); /* order is important here */
  290. if (is_sparrow) {
  291. W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x3ff81f);
  292. wmb(); /* order is important here */
  293. }
  294. W(RGF_USER_USER_CPU_0, BIT(1)); /* user_cpu_man_rst */
  295. wmb(); /* If host reorder writes here -> race in NIC */
  296. W(RGF_USER_MAC_CPU_0, BIT(1)); /* mac_cpu_man_rst */
  297. wmb(); /* order is important here */
  298. W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0xFE000000);
  299. W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0x0000003F);
  300. W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, is_sparrow ? 0x000000B0 : 0x00000170);
  301. W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0xFFE7FC00);
  302. wmb(); /* order is important here */
  303. if (is_sparrow) {
  304. W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x0);
  305. wmb(); /* order is important here */
  306. }
  307. W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0);
  308. W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0);
  309. W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0);
  310. W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
  311. wmb(); /* order is important here */
  312. if (is_sparrow) {
  313. W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000003);
  314. /* reset A2 PCIE AHB */
  315. W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00008000);
  316. } else {
  317. W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000001);
  318. if (rev_id == 1) {
  319. /* reset A1 BOTH PCIE AHB & PCIE RGF */
  320. W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00000080);
  321. } else {
  322. W(RGF_PCIE_LOS_COUNTER_CTL, BIT(6) | BIT(8));
  323. W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00008000);
  324. }
  325. }
  326. /* TODO: check order here!!! Erez code is different */
  327. W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
  328. wmb(); /* order is important here */
  329. /* wait until device ready */
  330. do {
  331. msleep(1);
  332. hw_state = R(RGF_USER_HW_MACHINE_STATE);
  333. if (delay++ > 100) {
  334. wil_err(wil, "Reset not completed, hw_state 0x%08x\n",
  335. hw_state);
  336. return;
  337. }
  338. } while (hw_state != HW_MACHINE_BOOT_DONE);
  339. /* TODO: Erez check rev_id != 1 */
  340. if (!is_sparrow && (rev_id != 1))
  341. W(RGF_PCIE_LOS_COUNTER_CTL, BIT(8));
  342. C(RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_RST_PWGD);
  343. wmb(); /* order is important here */
  344. wil_dbg_misc(wil, "Reset completed in %d ms\n", delay);
  345. #undef R
  346. #undef W
  347. #undef S
  348. #undef C
  349. }
  350. void wil_mbox_ring_le2cpus(struct wil6210_mbox_ring *r)
  351. {
  352. le32_to_cpus(&r->base);
  353. le16_to_cpus(&r->entry_size);
  354. le16_to_cpus(&r->size);
  355. le32_to_cpus(&r->tail);
  356. le32_to_cpus(&r->head);
  357. }
  358. static int wil_wait_for_fw_ready(struct wil6210_priv *wil)
  359. {
  360. ulong to = msecs_to_jiffies(1000);
  361. ulong left = wait_for_completion_timeout(&wil->wmi_ready, to);
  362. if (0 == left) {
  363. wil_err(wil, "Firmware not ready\n");
  364. return -ETIME;
  365. } else {
  366. wil_info(wil, "FW ready after %d ms. HW version 0x%08x\n",
  367. jiffies_to_msecs(to-left), wil->hw_version);
  368. }
  369. return 0;
  370. }
  371. /*
  372. * We reset all the structures, and we reset the UMAC.
  373. * After calling this routine, you're expected to reload
  374. * the firmware.
  375. */
  376. int wil_reset(struct wil6210_priv *wil)
  377. {
  378. int rc;
  379. WARN_ON(!mutex_is_locked(&wil->mutex));
  380. cancel_work_sync(&wil->disconnect_worker);
  381. wil6210_disconnect(wil, NULL);
  382. wil->status = 0; /* prevent NAPI from being scheduled */
  383. if (test_bit(wil_status_napi_en, &wil->status)) {
  384. napi_synchronize(&wil->napi_rx);
  385. }
  386. if (wil->scan_request) {
  387. wil_dbg_misc(wil, "Abort scan_request 0x%p\n",
  388. wil->scan_request);
  389. del_timer_sync(&wil->scan_timer);
  390. cfg80211_scan_done(wil->scan_request, true);
  391. wil->scan_request = NULL;
  392. }
  393. wil6210_disable_irq(wil);
  394. wmi_event_flush(wil);
  395. flush_workqueue(wil->wmi_wq_conn);
  396. flush_workqueue(wil->wmi_wq);
  397. /* TODO: put MAC in reset */
  398. wil_target_reset(wil);
  399. wil_rx_fini(wil);
  400. /* init after reset */
  401. wil->pending_connect_cid = -1;
  402. reinit_completion(&wil->wmi_ready);
  403. /* TODO: release MAC reset */
  404. wil6210_enable_irq(wil);
  405. /* we just started MAC, wait for FW ready */
  406. rc = wil_wait_for_fw_ready(wil);
  407. return rc;
  408. }
  409. void wil_fw_error_recovery(struct wil6210_priv *wil)
  410. {
  411. wil_dbg_misc(wil, "starting fw error recovery\n");
  412. schedule_work(&wil->fw_error_worker);
  413. }
  414. void wil_link_on(struct wil6210_priv *wil)
  415. {
  416. struct net_device *ndev = wil_to_ndev(wil);
  417. wil_dbg_misc(wil, "%s()\n", __func__);
  418. netif_carrier_on(ndev);
  419. wil_dbg_misc(wil, "netif_tx_wake : link on\n");
  420. netif_tx_wake_all_queues(ndev);
  421. }
  422. void wil_link_off(struct wil6210_priv *wil)
  423. {
  424. struct net_device *ndev = wil_to_ndev(wil);
  425. wil_dbg_misc(wil, "%s()\n", __func__);
  426. netif_tx_stop_all_queues(ndev);
  427. wil_dbg_misc(wil, "netif_tx_stop : link off\n");
  428. netif_carrier_off(ndev);
  429. }
  430. static int __wil_up(struct wil6210_priv *wil)
  431. {
  432. struct net_device *ndev = wil_to_ndev(wil);
  433. struct wireless_dev *wdev = wil->wdev;
  434. int rc;
  435. WARN_ON(!mutex_is_locked(&wil->mutex));
  436. rc = wil_reset(wil);
  437. if (rc)
  438. return rc;
  439. /* Rx VRING. After MAC and beacon */
  440. rc = wil_rx_init(wil);
  441. if (rc)
  442. return rc;
  443. switch (wdev->iftype) {
  444. case NL80211_IFTYPE_STATION:
  445. wil_dbg_misc(wil, "type: STATION\n");
  446. ndev->type = ARPHRD_ETHER;
  447. break;
  448. case NL80211_IFTYPE_AP:
  449. wil_dbg_misc(wil, "type: AP\n");
  450. ndev->type = ARPHRD_ETHER;
  451. break;
  452. case NL80211_IFTYPE_P2P_CLIENT:
  453. wil_dbg_misc(wil, "type: P2P_CLIENT\n");
  454. ndev->type = ARPHRD_ETHER;
  455. break;
  456. case NL80211_IFTYPE_P2P_GO:
  457. wil_dbg_misc(wil, "type: P2P_GO\n");
  458. ndev->type = ARPHRD_ETHER;
  459. break;
  460. case NL80211_IFTYPE_MONITOR:
  461. wil_dbg_misc(wil, "type: Monitor\n");
  462. ndev->type = ARPHRD_IEEE80211_RADIOTAP;
  463. /* ARPHRD_IEEE80211 or ARPHRD_IEEE80211_RADIOTAP ? */
  464. break;
  465. default:
  466. return -EOPNOTSUPP;
  467. }
  468. /* MAC address - pre-requisite for other commands */
  469. wmi_set_mac_address(wil, ndev->dev_addr);
  470. napi_enable(&wil->napi_rx);
  471. napi_enable(&wil->napi_tx);
  472. set_bit(wil_status_napi_en, &wil->status);
  473. return 0;
  474. }
  475. int wil_up(struct wil6210_priv *wil)
  476. {
  477. int rc;
  478. mutex_lock(&wil->mutex);
  479. rc = __wil_up(wil);
  480. mutex_unlock(&wil->mutex);
  481. return rc;
  482. }
  483. static int __wil_down(struct wil6210_priv *wil)
  484. {
  485. WARN_ON(!mutex_is_locked(&wil->mutex));
  486. clear_bit(wil_status_napi_en, &wil->status);
  487. napi_disable(&wil->napi_rx);
  488. napi_disable(&wil->napi_tx);
  489. if (wil->scan_request) {
  490. wil_dbg_misc(wil, "Abort scan_request 0x%p\n",
  491. wil->scan_request);
  492. del_timer_sync(&wil->scan_timer);
  493. cfg80211_scan_done(wil->scan_request, true);
  494. wil->scan_request = NULL;
  495. }
  496. wil6210_disconnect(wil, NULL);
  497. wil_rx_fini(wil);
  498. return 0;
  499. }
  500. int wil_down(struct wil6210_priv *wil)
  501. {
  502. int rc;
  503. mutex_lock(&wil->mutex);
  504. rc = __wil_down(wil);
  505. mutex_unlock(&wil->mutex);
  506. return rc;
  507. }
  508. int wil_find_cid(struct wil6210_priv *wil, const u8 *mac)
  509. {
  510. int i;
  511. int rc = -ENOENT;
  512. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  513. if ((wil->sta[i].status != wil_sta_unused) &&
  514. ether_addr_equal(wil->sta[i].addr, mac)) {
  515. rc = i;
  516. break;
  517. }
  518. }
  519. return rc;
  520. }