main.c 32 KB

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