main.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  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. del_timer_sync(&wil->connect_timer);
  255. _wil6210_disconnect(wil, bssid);
  256. }
  257. void wil_priv_deinit(struct wil6210_priv *wil)
  258. {
  259. del_timer_sync(&wil->scan_timer);
  260. cancel_work_sync(&wil->disconnect_worker);
  261. cancel_work_sync(&wil->fw_error_worker);
  262. mutex_lock(&wil->mutex);
  263. wil6210_disconnect(wil, NULL);
  264. mutex_unlock(&wil->mutex);
  265. wmi_event_flush(wil);
  266. destroy_workqueue(wil->wmi_wq_conn);
  267. destroy_workqueue(wil->wmi_wq);
  268. }
  269. /* target operations */
  270. /* register read */
  271. #define R(a) ioread32(wil->csr + HOSTADDR(a))
  272. /* register write. wmb() to make sure it is completed */
  273. #define W(a, v) do { iowrite32(v, wil->csr + HOSTADDR(a)); wmb(); } while (0)
  274. /* register set = read, OR, write */
  275. #define S(a, v) W(a, R(a) | v)
  276. /* register clear = read, AND with inverted, write */
  277. #define C(a, v) W(a, R(a) & ~v)
  278. static inline void wil_halt_cpu(struct wil6210_priv *wil)
  279. {
  280. W(RGF_USER_USER_CPU_0, BIT_USER_USER_CPU_MAN_RST);
  281. W(RGF_USER_MAC_CPU_0, BIT_USER_MAC_CPU_MAN_RST);
  282. }
  283. static inline void wil_release_cpu(struct wil6210_priv *wil)
  284. {
  285. /* Start CPU */
  286. W(RGF_USER_USER_CPU_0, 1);
  287. }
  288. static int wil_target_reset(struct wil6210_priv *wil)
  289. {
  290. int delay = 0;
  291. u32 hw_state;
  292. u32 rev_id;
  293. bool is_sparrow = (wil->board->board == WIL_BOARD_SPARROW);
  294. wil_dbg_misc(wil, "Resetting \"%s\"...\n", wil->board->name);
  295. wil->hw_version = R(RGF_USER_FW_REV_ID);
  296. rev_id = wil->hw_version & 0xff;
  297. /* Clear MAC link up */
  298. S(RGF_HP_CTRL, BIT(15));
  299. S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT_HPAL_PERST_FROM_PAD);
  300. S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT_CAR_PERST_RST);
  301. wil_halt_cpu(wil);
  302. C(RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_CAR_AHB_SW_SEL); /* 40 MHz */
  303. if (is_sparrow) {
  304. W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x3ff81f);
  305. W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0xf);
  306. }
  307. W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0xFE000000);
  308. W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0x0000003F);
  309. W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, is_sparrow ? 0x000000f0 : 0x00000170);
  310. W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0xFFE7FE00);
  311. if (is_sparrow) {
  312. W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x0);
  313. W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0x0);
  314. }
  315. W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0);
  316. W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0);
  317. W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0);
  318. W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
  319. if (is_sparrow) {
  320. W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000003);
  321. /* reset A2 PCIE AHB */
  322. W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00008000);
  323. } else {
  324. W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000001);
  325. if (rev_id == 1) {
  326. /* reset A1 BOTH PCIE AHB & PCIE RGF */
  327. W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00000080);
  328. } else {
  329. W(RGF_PCIE_LOS_COUNTER_CTL, BIT(6) | BIT(8));
  330. W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00008000);
  331. }
  332. }
  333. /* TODO: check order here!!! Erez code is different */
  334. W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
  335. /* wait until device ready. typical time is 200..250 msec */
  336. do {
  337. msleep(RST_DELAY);
  338. hw_state = R(RGF_USER_HW_MACHINE_STATE);
  339. if (delay++ > RST_COUNT) {
  340. wil_err(wil, "Reset not completed, hw_state 0x%08x\n",
  341. hw_state);
  342. return -ETIME;
  343. }
  344. } while (hw_state != HW_MACHINE_BOOT_DONE);
  345. /* TODO: Erez check rev_id != 1 */
  346. if (!is_sparrow && (rev_id != 1))
  347. W(RGF_PCIE_LOS_COUNTER_CTL, BIT(8));
  348. C(RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_RST_PWGD);
  349. wil_dbg_misc(wil, "Reset completed in %d ms\n", delay * RST_DELAY);
  350. return 0;
  351. }
  352. #undef R
  353. #undef W
  354. #undef S
  355. #undef C
  356. void wil_mbox_ring_le2cpus(struct wil6210_mbox_ring *r)
  357. {
  358. le32_to_cpus(&r->base);
  359. le16_to_cpus(&r->entry_size);
  360. le16_to_cpus(&r->size);
  361. le32_to_cpus(&r->tail);
  362. le32_to_cpus(&r->head);
  363. }
  364. static int wil_wait_for_fw_ready(struct wil6210_priv *wil)
  365. {
  366. ulong to = msecs_to_jiffies(1000);
  367. ulong left = wait_for_completion_timeout(&wil->wmi_ready, to);
  368. if (0 == left) {
  369. wil_err(wil, "Firmware not ready\n");
  370. return -ETIME;
  371. } else {
  372. wil_info(wil, "FW ready after %d ms. HW version 0x%08x\n",
  373. jiffies_to_msecs(to-left), wil->hw_version);
  374. }
  375. return 0;
  376. }
  377. /*
  378. * We reset all the structures, and we reset the UMAC.
  379. * After calling this routine, you're expected to reload
  380. * the firmware.
  381. */
  382. int wil_reset(struct wil6210_priv *wil)
  383. {
  384. int rc;
  385. WARN_ON(!mutex_is_locked(&wil->mutex));
  386. cancel_work_sync(&wil->disconnect_worker);
  387. wil6210_disconnect(wil, NULL);
  388. wil->status = 0; /* prevent NAPI from being scheduled */
  389. if (test_bit(wil_status_napi_en, &wil->status))
  390. napi_synchronize(&wil->napi_rx);
  391. if (wil->scan_request) {
  392. wil_dbg_misc(wil, "Abort scan_request 0x%p\n",
  393. wil->scan_request);
  394. del_timer_sync(&wil->scan_timer);
  395. cfg80211_scan_done(wil->scan_request, true);
  396. wil->scan_request = NULL;
  397. }
  398. wil6210_disable_irq(wil);
  399. wmi_event_flush(wil);
  400. flush_workqueue(wil->wmi_wq_conn);
  401. flush_workqueue(wil->wmi_wq);
  402. rc = wil_target_reset(wil);
  403. wil_rx_fini(wil);
  404. if (rc)
  405. return rc;
  406. if (!no_fw_load) {
  407. wil_info(wil, "Use firmware <%s>\n", WIL_FW_NAME);
  408. wil_halt_cpu(wil);
  409. /* Loading f/w from the file */
  410. rc = wil_request_firmware(wil, WIL_FW_NAME);
  411. if (rc)
  412. return rc;
  413. /* clear any interrupts which on-card-firmware may have set */
  414. wil6210_clear_irq(wil);
  415. { /* CAF_ICR - clear and mask */
  416. u32 a = HOSTADDR(RGF_CAF_ICR) +
  417. offsetof(struct RGF_ICR, ICR);
  418. u32 m = HOSTADDR(RGF_CAF_ICR) +
  419. offsetof(struct RGF_ICR, IMV);
  420. u32 icr = ioread32(wil->csr + a);
  421. iowrite32(icr, wil->csr + a); /* W1C */
  422. iowrite32(~0, wil->csr + m);
  423. wmb(); /* wait for completion */
  424. }
  425. wil_release_cpu(wil);
  426. } else {
  427. wil_info(wil, "Use firmware from on-card flash\n");
  428. }
  429. /* init after reset */
  430. wil->pending_connect_cid = -1;
  431. reinit_completion(&wil->wmi_ready);
  432. wil6210_enable_irq(wil);
  433. /* we just started MAC, wait for FW ready */
  434. rc = wil_wait_for_fw_ready(wil);
  435. return rc;
  436. }
  437. void wil_fw_error_recovery(struct wil6210_priv *wil)
  438. {
  439. wil_dbg_misc(wil, "starting fw error recovery\n");
  440. schedule_work(&wil->fw_error_worker);
  441. }
  442. void wil_link_on(struct wil6210_priv *wil)
  443. {
  444. struct net_device *ndev = wil_to_ndev(wil);
  445. wil_dbg_misc(wil, "%s()\n", __func__);
  446. netif_carrier_on(ndev);
  447. wil_dbg_misc(wil, "netif_tx_wake : link on\n");
  448. netif_tx_wake_all_queues(ndev);
  449. }
  450. void wil_link_off(struct wil6210_priv *wil)
  451. {
  452. struct net_device *ndev = wil_to_ndev(wil);
  453. wil_dbg_misc(wil, "%s()\n", __func__);
  454. netif_tx_stop_all_queues(ndev);
  455. wil_dbg_misc(wil, "netif_tx_stop : link off\n");
  456. netif_carrier_off(ndev);
  457. }
  458. static int __wil_up(struct wil6210_priv *wil)
  459. {
  460. struct net_device *ndev = wil_to_ndev(wil);
  461. struct wireless_dev *wdev = wil->wdev;
  462. int rc;
  463. WARN_ON(!mutex_is_locked(&wil->mutex));
  464. rc = wil_reset(wil);
  465. if (rc)
  466. return rc;
  467. /* Rx VRING. After MAC and beacon */
  468. rc = wil_rx_init(wil);
  469. if (rc)
  470. return rc;
  471. switch (wdev->iftype) {
  472. case NL80211_IFTYPE_STATION:
  473. wil_dbg_misc(wil, "type: STATION\n");
  474. ndev->type = ARPHRD_ETHER;
  475. break;
  476. case NL80211_IFTYPE_AP:
  477. wil_dbg_misc(wil, "type: AP\n");
  478. ndev->type = ARPHRD_ETHER;
  479. break;
  480. case NL80211_IFTYPE_P2P_CLIENT:
  481. wil_dbg_misc(wil, "type: P2P_CLIENT\n");
  482. ndev->type = ARPHRD_ETHER;
  483. break;
  484. case NL80211_IFTYPE_P2P_GO:
  485. wil_dbg_misc(wil, "type: P2P_GO\n");
  486. ndev->type = ARPHRD_ETHER;
  487. break;
  488. case NL80211_IFTYPE_MONITOR:
  489. wil_dbg_misc(wil, "type: Monitor\n");
  490. ndev->type = ARPHRD_IEEE80211_RADIOTAP;
  491. /* ARPHRD_IEEE80211 or ARPHRD_IEEE80211_RADIOTAP ? */
  492. break;
  493. default:
  494. return -EOPNOTSUPP;
  495. }
  496. /* MAC address - pre-requisite for other commands */
  497. wmi_set_mac_address(wil, ndev->dev_addr);
  498. napi_enable(&wil->napi_rx);
  499. napi_enable(&wil->napi_tx);
  500. set_bit(wil_status_napi_en, &wil->status);
  501. if (wil->platform_ops.bus_request)
  502. wil->platform_ops.bus_request(wil->platform_handle,
  503. WIL_MAX_BUS_REQUEST_KBPS);
  504. return 0;
  505. }
  506. int wil_up(struct wil6210_priv *wil)
  507. {
  508. int rc;
  509. mutex_lock(&wil->mutex);
  510. rc = __wil_up(wil);
  511. mutex_unlock(&wil->mutex);
  512. return rc;
  513. }
  514. static int __wil_down(struct wil6210_priv *wil)
  515. {
  516. WARN_ON(!mutex_is_locked(&wil->mutex));
  517. if (wil->platform_ops.bus_request)
  518. wil->platform_ops.bus_request(wil->platform_handle, 0);
  519. clear_bit(wil_status_napi_en, &wil->status);
  520. napi_disable(&wil->napi_rx);
  521. napi_disable(&wil->napi_tx);
  522. if (wil->scan_request) {
  523. wil_dbg_misc(wil, "Abort scan_request 0x%p\n",
  524. wil->scan_request);
  525. del_timer_sync(&wil->scan_timer);
  526. cfg80211_scan_done(wil->scan_request, true);
  527. wil->scan_request = NULL;
  528. }
  529. wil6210_disconnect(wil, NULL);
  530. wil_rx_fini(wil);
  531. return 0;
  532. }
  533. int wil_down(struct wil6210_priv *wil)
  534. {
  535. int rc;
  536. mutex_lock(&wil->mutex);
  537. rc = __wil_down(wil);
  538. mutex_unlock(&wil->mutex);
  539. return rc;
  540. }
  541. int wil_find_cid(struct wil6210_priv *wil, const u8 *mac)
  542. {
  543. int i;
  544. int rc = -ENOENT;
  545. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  546. if ((wil->sta[i].status != wil_sta_unused) &&
  547. ether_addr_equal(wil->sta[i].addr, mac)) {
  548. rc = i;
  549. break;
  550. }
  551. }
  552. return rc;
  553. }