main.c 17 KB

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