wow.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. // SPDX-License-Identifier: ISC
  2. /*
  3. * Copyright (c) 2015-2017 Qualcomm Atheros, Inc.
  4. * Copyright (c) 2018, The Linux Foundation. All rights reserved.
  5. */
  6. #include "mac.h"
  7. #include <net/mac80211.h>
  8. #include "hif.h"
  9. #include "core.h"
  10. #include "debug.h"
  11. #include "wmi.h"
  12. #include "wmi-ops.h"
  13. static const struct wiphy_wowlan_support ath10k_wowlan_support = {
  14. .flags = WIPHY_WOWLAN_DISCONNECT |
  15. WIPHY_WOWLAN_MAGIC_PKT,
  16. .pattern_min_len = WOW_MIN_PATTERN_SIZE,
  17. .pattern_max_len = WOW_MAX_PATTERN_SIZE,
  18. .max_pkt_offset = WOW_MAX_PKT_OFFSET,
  19. };
  20. static int ath10k_wow_vif_cleanup(struct ath10k_vif *arvif)
  21. {
  22. struct ath10k *ar = arvif->ar;
  23. int i, ret;
  24. for (i = 0; i < WOW_EVENT_MAX; i++) {
  25. ret = ath10k_wmi_wow_add_wakeup_event(ar, arvif->vdev_id, i, 0);
  26. if (ret) {
  27. ath10k_warn(ar, "failed to issue wow wakeup for event %s on vdev %i: %d\n",
  28. wow_wakeup_event(i), arvif->vdev_id, ret);
  29. return ret;
  30. }
  31. }
  32. for (i = 0; i < ar->wow.max_num_patterns; i++) {
  33. ret = ath10k_wmi_wow_del_pattern(ar, arvif->vdev_id, i);
  34. if (ret) {
  35. ath10k_warn(ar, "failed to delete wow pattern %d for vdev %i: %d\n",
  36. i, arvif->vdev_id, ret);
  37. return ret;
  38. }
  39. }
  40. return 0;
  41. }
  42. static int ath10k_wow_cleanup(struct ath10k *ar)
  43. {
  44. struct ath10k_vif *arvif;
  45. int ret;
  46. lockdep_assert_held(&ar->conf_mutex);
  47. list_for_each_entry(arvif, &ar->arvifs, list) {
  48. ret = ath10k_wow_vif_cleanup(arvif);
  49. if (ret) {
  50. ath10k_warn(ar, "failed to clean wow wakeups on vdev %i: %d\n",
  51. arvif->vdev_id, ret);
  52. return ret;
  53. }
  54. }
  55. return 0;
  56. }
  57. /*
  58. * Convert a 802.3 format to a 802.11 format.
  59. * +------------+-----------+--------+----------------+
  60. * 802.3: |dest mac(6B)|src mac(6B)|type(2B)| body... |
  61. * +------------+-----------+--------+----------------+
  62. * |__ |_______ |____________ |________
  63. * | | | |
  64. * +--+------------+----+-----------+---------------+-----------+
  65. * 802.11: |4B|dest mac(6B)| 6B |src mac(6B)| 8B |type(2B)| body... |
  66. * +--+------------+----+-----------+---------------+-----------+
  67. */
  68. static void ath10k_wow_convert_8023_to_80211(struct cfg80211_pkt_pattern *new,
  69. const struct cfg80211_pkt_pattern *old)
  70. {
  71. u8 hdr_8023_pattern[ETH_HLEN] = {};
  72. u8 hdr_8023_bit_mask[ETH_HLEN] = {};
  73. u8 hdr_80211_pattern[WOW_HDR_LEN] = {};
  74. u8 hdr_80211_bit_mask[WOW_HDR_LEN] = {};
  75. int total_len = old->pkt_offset + old->pattern_len;
  76. int hdr_80211_end_offset;
  77. struct ieee80211_hdr_3addr *new_hdr_pattern =
  78. (struct ieee80211_hdr_3addr *)hdr_80211_pattern;
  79. struct ieee80211_hdr_3addr *new_hdr_mask =
  80. (struct ieee80211_hdr_3addr *)hdr_80211_bit_mask;
  81. struct ethhdr *old_hdr_pattern = (struct ethhdr *)hdr_8023_pattern;
  82. struct ethhdr *old_hdr_mask = (struct ethhdr *)hdr_8023_bit_mask;
  83. int hdr_len = sizeof(*new_hdr_pattern);
  84. struct rfc1042_hdr *new_rfc_pattern =
  85. (struct rfc1042_hdr *)(hdr_80211_pattern + hdr_len);
  86. struct rfc1042_hdr *new_rfc_mask =
  87. (struct rfc1042_hdr *)(hdr_80211_bit_mask + hdr_len);
  88. int rfc_len = sizeof(*new_rfc_pattern);
  89. memcpy(hdr_8023_pattern + old->pkt_offset,
  90. old->pattern, ETH_HLEN - old->pkt_offset);
  91. memcpy(hdr_8023_bit_mask + old->pkt_offset,
  92. old->mask, ETH_HLEN - old->pkt_offset);
  93. /* Copy destination address */
  94. memcpy(new_hdr_pattern->addr1, old_hdr_pattern->h_dest, ETH_ALEN);
  95. memcpy(new_hdr_mask->addr1, old_hdr_mask->h_dest, ETH_ALEN);
  96. /* Copy source address */
  97. memcpy(new_hdr_pattern->addr3, old_hdr_pattern->h_source, ETH_ALEN);
  98. memcpy(new_hdr_mask->addr3, old_hdr_mask->h_source, ETH_ALEN);
  99. /* Copy logic link type */
  100. memcpy(&new_rfc_pattern->snap_type,
  101. &old_hdr_pattern->h_proto,
  102. sizeof(old_hdr_pattern->h_proto));
  103. memcpy(&new_rfc_mask->snap_type,
  104. &old_hdr_mask->h_proto,
  105. sizeof(old_hdr_mask->h_proto));
  106. /* Calculate new pkt_offset */
  107. if (old->pkt_offset < ETH_ALEN)
  108. new->pkt_offset = old->pkt_offset +
  109. offsetof(struct ieee80211_hdr_3addr, addr1);
  110. else if (old->pkt_offset < offsetof(struct ethhdr, h_proto))
  111. new->pkt_offset = old->pkt_offset +
  112. offsetof(struct ieee80211_hdr_3addr, addr3) -
  113. offsetof(struct ethhdr, h_source);
  114. else
  115. new->pkt_offset = old->pkt_offset + hdr_len + rfc_len - ETH_HLEN;
  116. /* Calculate new hdr end offset */
  117. if (total_len > ETH_HLEN)
  118. hdr_80211_end_offset = hdr_len + rfc_len;
  119. else if (total_len > offsetof(struct ethhdr, h_proto))
  120. hdr_80211_end_offset = hdr_len + rfc_len + total_len - ETH_HLEN;
  121. else if (total_len > ETH_ALEN)
  122. hdr_80211_end_offset = total_len - ETH_ALEN +
  123. offsetof(struct ieee80211_hdr_3addr, addr3);
  124. else
  125. hdr_80211_end_offset = total_len +
  126. offsetof(struct ieee80211_hdr_3addr, addr1);
  127. new->pattern_len = hdr_80211_end_offset - new->pkt_offset;
  128. memcpy((u8 *)new->pattern,
  129. hdr_80211_pattern + new->pkt_offset,
  130. new->pattern_len);
  131. memcpy((u8 *)new->mask,
  132. hdr_80211_bit_mask + new->pkt_offset,
  133. new->pattern_len);
  134. if (total_len > ETH_HLEN) {
  135. /* Copy frame body */
  136. memcpy((u8 *)new->pattern + new->pattern_len,
  137. (void *)old->pattern + ETH_HLEN - old->pkt_offset,
  138. total_len - ETH_HLEN);
  139. memcpy((u8 *)new->mask + new->pattern_len,
  140. (void *)old->mask + ETH_HLEN - old->pkt_offset,
  141. total_len - ETH_HLEN);
  142. new->pattern_len += total_len - ETH_HLEN;
  143. }
  144. }
  145. static int ath10k_wmi_pno_check(struct ath10k *ar, u32 vdev_id,
  146. struct cfg80211_sched_scan_request *nd_config,
  147. struct wmi_pno_scan_req *pno)
  148. {
  149. int i, j, ret = 0;
  150. u8 ssid_len;
  151. pno->enable = 1;
  152. pno->vdev_id = vdev_id;
  153. pno->uc_networks_count = nd_config->n_match_sets;
  154. if (!pno->uc_networks_count ||
  155. pno->uc_networks_count > WMI_PNO_MAX_SUPP_NETWORKS)
  156. return -EINVAL;
  157. if (nd_config->n_channels > WMI_PNO_MAX_NETW_CHANNELS_EX)
  158. return -EINVAL;
  159. /* Filling per profile params */
  160. for (i = 0; i < pno->uc_networks_count; i++) {
  161. ssid_len = nd_config->match_sets[i].ssid.ssid_len;
  162. if (ssid_len == 0 || ssid_len > 32)
  163. return -EINVAL;
  164. pno->a_networks[i].ssid.ssid_len = __cpu_to_le32(ssid_len);
  165. memcpy(pno->a_networks[i].ssid.ssid,
  166. nd_config->match_sets[i].ssid.ssid,
  167. nd_config->match_sets[i].ssid.ssid_len);
  168. pno->a_networks[i].authentication = 0;
  169. pno->a_networks[i].encryption = 0;
  170. pno->a_networks[i].bcast_nw_type = 0;
  171. /*Copying list of valid channel into request */
  172. pno->a_networks[i].channel_count = nd_config->n_channels;
  173. pno->a_networks[i].rssi_threshold = nd_config->match_sets[i].rssi_thold;
  174. for (j = 0; j < nd_config->n_channels; j++) {
  175. pno->a_networks[i].channels[j] =
  176. nd_config->channels[j]->center_freq;
  177. }
  178. }
  179. /* set scan to passive if no SSIDs are specified in the request */
  180. if (nd_config->n_ssids == 0)
  181. pno->do_passive_scan = true;
  182. else
  183. pno->do_passive_scan = false;
  184. for (i = 0; i < nd_config->n_ssids; i++) {
  185. j = 0;
  186. while (j < pno->uc_networks_count) {
  187. if (__le32_to_cpu(pno->a_networks[j].ssid.ssid_len) ==
  188. nd_config->ssids[i].ssid_len &&
  189. (memcmp(pno->a_networks[j].ssid.ssid,
  190. nd_config->ssids[i].ssid,
  191. __le32_to_cpu(pno->a_networks[j].ssid.ssid_len)) == 0)) {
  192. pno->a_networks[j].bcast_nw_type = BCAST_HIDDEN;
  193. break;
  194. }
  195. j++;
  196. }
  197. }
  198. if (nd_config->n_scan_plans == 2) {
  199. pno->fast_scan_period = nd_config->scan_plans[0].interval * MSEC_PER_SEC;
  200. pno->fast_scan_max_cycles = nd_config->scan_plans[0].iterations;
  201. pno->slow_scan_period =
  202. nd_config->scan_plans[1].interval * MSEC_PER_SEC;
  203. } else if (nd_config->n_scan_plans == 1) {
  204. pno->fast_scan_period = nd_config->scan_plans[0].interval * MSEC_PER_SEC;
  205. pno->fast_scan_max_cycles = 1;
  206. pno->slow_scan_period = nd_config->scan_plans[0].interval * MSEC_PER_SEC;
  207. } else {
  208. ath10k_warn(ar, "Invalid number of scan plans %d !!",
  209. nd_config->n_scan_plans);
  210. }
  211. if (nd_config->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
  212. /* enable mac randomization */
  213. pno->enable_pno_scan_randomization = 1;
  214. memcpy(pno->mac_addr, nd_config->mac_addr, ETH_ALEN);
  215. memcpy(pno->mac_addr_mask, nd_config->mac_addr_mask, ETH_ALEN);
  216. }
  217. pno->delay_start_time = nd_config->delay;
  218. /* Current FW does not support min-max range for dwell time */
  219. pno->active_max_time = WMI_ACTIVE_MAX_CHANNEL_TIME;
  220. pno->passive_max_time = WMI_PASSIVE_MAX_CHANNEL_TIME;
  221. return ret;
  222. }
  223. static int ath10k_vif_wow_set_wakeups(struct ath10k_vif *arvif,
  224. struct cfg80211_wowlan *wowlan)
  225. {
  226. int ret, i;
  227. unsigned long wow_mask = 0;
  228. struct ath10k *ar = arvif->ar;
  229. const struct cfg80211_pkt_pattern *patterns = wowlan->patterns;
  230. int pattern_id = 0;
  231. /* Setup requested WOW features */
  232. switch (arvif->vdev_type) {
  233. case WMI_VDEV_TYPE_IBSS:
  234. __set_bit(WOW_BEACON_EVENT, &wow_mask);
  235. fallthrough;
  236. case WMI_VDEV_TYPE_AP:
  237. __set_bit(WOW_DEAUTH_RECVD_EVENT, &wow_mask);
  238. __set_bit(WOW_DISASSOC_RECVD_EVENT, &wow_mask);
  239. __set_bit(WOW_PROBE_REQ_WPS_IE_EVENT, &wow_mask);
  240. __set_bit(WOW_AUTH_REQ_EVENT, &wow_mask);
  241. __set_bit(WOW_ASSOC_REQ_EVENT, &wow_mask);
  242. __set_bit(WOW_HTT_EVENT, &wow_mask);
  243. __set_bit(WOW_RA_MATCH_EVENT, &wow_mask);
  244. break;
  245. case WMI_VDEV_TYPE_STA:
  246. if (wowlan->disconnect) {
  247. __set_bit(WOW_DEAUTH_RECVD_EVENT, &wow_mask);
  248. __set_bit(WOW_DISASSOC_RECVD_EVENT, &wow_mask);
  249. __set_bit(WOW_BMISS_EVENT, &wow_mask);
  250. __set_bit(WOW_CSA_IE_EVENT, &wow_mask);
  251. }
  252. if (wowlan->magic_pkt)
  253. __set_bit(WOW_MAGIC_PKT_RECVD_EVENT, &wow_mask);
  254. if (wowlan->nd_config) {
  255. struct wmi_pno_scan_req *pno;
  256. int ret;
  257. pno = kzalloc(sizeof(*pno), GFP_KERNEL);
  258. if (!pno)
  259. return -ENOMEM;
  260. ar->nlo_enabled = true;
  261. ret = ath10k_wmi_pno_check(ar, arvif->vdev_id,
  262. wowlan->nd_config, pno);
  263. if (!ret) {
  264. ath10k_wmi_wow_config_pno(ar, arvif->vdev_id, pno);
  265. __set_bit(WOW_NLO_DETECTED_EVENT, &wow_mask);
  266. }
  267. kfree(pno);
  268. }
  269. break;
  270. default:
  271. break;
  272. }
  273. for (i = 0; i < wowlan->n_patterns; i++) {
  274. u8 bitmask[WOW_MAX_PATTERN_SIZE] = {};
  275. u8 ath_pattern[WOW_MAX_PATTERN_SIZE] = {};
  276. u8 ath_bitmask[WOW_MAX_PATTERN_SIZE] = {};
  277. struct cfg80211_pkt_pattern new_pattern = {};
  278. struct cfg80211_pkt_pattern old_pattern = patterns[i];
  279. int j;
  280. new_pattern.pattern = ath_pattern;
  281. new_pattern.mask = ath_bitmask;
  282. if (patterns[i].pattern_len > WOW_MAX_PATTERN_SIZE)
  283. continue;
  284. /* convert bytemask to bitmask */
  285. for (j = 0; j < patterns[i].pattern_len; j++)
  286. if (patterns[i].mask[j / 8] & BIT(j % 8))
  287. bitmask[j] = 0xff;
  288. old_pattern.mask = bitmask;
  289. if (ar->wmi.rx_decap_mode == ATH10K_HW_TXRX_NATIVE_WIFI) {
  290. if (patterns[i].pkt_offset < ETH_HLEN) {
  291. ath10k_wow_convert_8023_to_80211(&new_pattern,
  292. &old_pattern);
  293. } else {
  294. new_pattern = old_pattern;
  295. new_pattern.pkt_offset += WOW_HDR_LEN - ETH_HLEN;
  296. }
  297. }
  298. if (WARN_ON(new_pattern.pattern_len > WOW_MAX_PATTERN_SIZE))
  299. return -EINVAL;
  300. ret = ath10k_wmi_wow_add_pattern(ar, arvif->vdev_id,
  301. pattern_id,
  302. new_pattern.pattern,
  303. new_pattern.mask,
  304. new_pattern.pattern_len,
  305. new_pattern.pkt_offset);
  306. if (ret) {
  307. ath10k_warn(ar, "failed to add pattern %i to vdev %i: %d\n",
  308. pattern_id,
  309. arvif->vdev_id, ret);
  310. return ret;
  311. }
  312. pattern_id++;
  313. __set_bit(WOW_PATTERN_MATCH_EVENT, &wow_mask);
  314. }
  315. for (i = 0; i < WOW_EVENT_MAX; i++) {
  316. if (!test_bit(i, &wow_mask))
  317. continue;
  318. ret = ath10k_wmi_wow_add_wakeup_event(ar, arvif->vdev_id, i, 1);
  319. if (ret) {
  320. ath10k_warn(ar, "failed to enable wakeup event %s on vdev %i: %d\n",
  321. wow_wakeup_event(i), arvif->vdev_id, ret);
  322. return ret;
  323. }
  324. }
  325. return 0;
  326. }
  327. static int ath10k_wow_set_wakeups(struct ath10k *ar,
  328. struct cfg80211_wowlan *wowlan)
  329. {
  330. struct ath10k_vif *arvif;
  331. int ret;
  332. lockdep_assert_held(&ar->conf_mutex);
  333. list_for_each_entry(arvif, &ar->arvifs, list) {
  334. ret = ath10k_vif_wow_set_wakeups(arvif, wowlan);
  335. if (ret) {
  336. ath10k_warn(ar, "failed to set wow wakeups on vdev %i: %d\n",
  337. arvif->vdev_id, ret);
  338. return ret;
  339. }
  340. }
  341. return 0;
  342. }
  343. static int ath10k_vif_wow_clean_nlo(struct ath10k_vif *arvif)
  344. {
  345. int ret = 0;
  346. struct ath10k *ar = arvif->ar;
  347. switch (arvif->vdev_type) {
  348. case WMI_VDEV_TYPE_STA:
  349. if (ar->nlo_enabled) {
  350. struct wmi_pno_scan_req *pno;
  351. pno = kzalloc(sizeof(*pno), GFP_KERNEL);
  352. if (!pno)
  353. return -ENOMEM;
  354. pno->enable = 0;
  355. ar->nlo_enabled = false;
  356. ret = ath10k_wmi_wow_config_pno(ar, arvif->vdev_id, pno);
  357. kfree(pno);
  358. }
  359. break;
  360. default:
  361. break;
  362. }
  363. return ret;
  364. }
  365. static int ath10k_wow_nlo_cleanup(struct ath10k *ar)
  366. {
  367. struct ath10k_vif *arvif;
  368. int ret = 0;
  369. lockdep_assert_held(&ar->conf_mutex);
  370. list_for_each_entry(arvif, &ar->arvifs, list) {
  371. ret = ath10k_vif_wow_clean_nlo(arvif);
  372. if (ret) {
  373. ath10k_warn(ar, "failed to clean nlo settings on vdev %i: %d\n",
  374. arvif->vdev_id, ret);
  375. return ret;
  376. }
  377. }
  378. return 0;
  379. }
  380. static int ath10k_wow_enable(struct ath10k *ar)
  381. {
  382. int ret;
  383. lockdep_assert_held(&ar->conf_mutex);
  384. reinit_completion(&ar->target_suspend);
  385. ret = ath10k_wmi_wow_enable(ar);
  386. if (ret) {
  387. ath10k_warn(ar, "failed to issue wow enable: %d\n", ret);
  388. return ret;
  389. }
  390. ret = wait_for_completion_timeout(&ar->target_suspend, 3 * HZ);
  391. if (ret == 0) {
  392. ath10k_warn(ar, "timed out while waiting for suspend completion\n");
  393. return -ETIMEDOUT;
  394. }
  395. return 0;
  396. }
  397. static int ath10k_wow_wakeup(struct ath10k *ar)
  398. {
  399. int ret;
  400. lockdep_assert_held(&ar->conf_mutex);
  401. reinit_completion(&ar->wow.wakeup_completed);
  402. ret = ath10k_wmi_wow_host_wakeup_ind(ar);
  403. if (ret) {
  404. ath10k_warn(ar, "failed to send wow wakeup indication: %d\n",
  405. ret);
  406. return ret;
  407. }
  408. ret = wait_for_completion_timeout(&ar->wow.wakeup_completed, 3 * HZ);
  409. if (ret == 0) {
  410. ath10k_warn(ar, "timed out while waiting for wow wakeup completion\n");
  411. return -ETIMEDOUT;
  412. }
  413. return 0;
  414. }
  415. int ath10k_wow_op_suspend(struct ieee80211_hw *hw,
  416. struct cfg80211_wowlan *wowlan)
  417. {
  418. struct ath10k *ar = hw->priv;
  419. int ret;
  420. mutex_lock(&ar->conf_mutex);
  421. if (WARN_ON(!test_bit(ATH10K_FW_FEATURE_WOWLAN_SUPPORT,
  422. ar->running_fw->fw_file.fw_features))) {
  423. ret = 1;
  424. goto exit;
  425. }
  426. ret = ath10k_wow_cleanup(ar);
  427. if (ret) {
  428. ath10k_warn(ar, "failed to clear wow wakeup events: %d\n",
  429. ret);
  430. goto exit;
  431. }
  432. ret = ath10k_wow_set_wakeups(ar, wowlan);
  433. if (ret) {
  434. ath10k_warn(ar, "failed to set wow wakeup events: %d\n",
  435. ret);
  436. goto cleanup;
  437. }
  438. ath10k_mac_wait_tx_complete(ar);
  439. ret = ath10k_wow_enable(ar);
  440. if (ret) {
  441. ath10k_warn(ar, "failed to start wow: %d\n", ret);
  442. goto cleanup;
  443. }
  444. ret = ath10k_hif_suspend(ar);
  445. if (ret) {
  446. ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
  447. goto wakeup;
  448. }
  449. goto exit;
  450. wakeup:
  451. ath10k_wow_wakeup(ar);
  452. cleanup:
  453. ath10k_wow_cleanup(ar);
  454. exit:
  455. mutex_unlock(&ar->conf_mutex);
  456. return ret ? 1 : 0;
  457. }
  458. void ath10k_wow_op_set_wakeup(struct ieee80211_hw *hw, bool enabled)
  459. {
  460. struct ath10k *ar = hw->priv;
  461. mutex_lock(&ar->conf_mutex);
  462. if (test_bit(ATH10K_FW_FEATURE_WOWLAN_SUPPORT,
  463. ar->running_fw->fw_file.fw_features)) {
  464. device_set_wakeup_enable(ar->dev, enabled);
  465. }
  466. mutex_unlock(&ar->conf_mutex);
  467. }
  468. int ath10k_wow_op_resume(struct ieee80211_hw *hw)
  469. {
  470. struct ath10k *ar = hw->priv;
  471. int ret;
  472. mutex_lock(&ar->conf_mutex);
  473. if (WARN_ON(!test_bit(ATH10K_FW_FEATURE_WOWLAN_SUPPORT,
  474. ar->running_fw->fw_file.fw_features))) {
  475. ret = 1;
  476. goto exit;
  477. }
  478. ret = ath10k_hif_resume(ar);
  479. if (ret) {
  480. ath10k_warn(ar, "failed to resume hif: %d\n", ret);
  481. goto exit;
  482. }
  483. ret = ath10k_wow_wakeup(ar);
  484. if (ret)
  485. ath10k_warn(ar, "failed to wakeup from wow: %d\n", ret);
  486. ret = ath10k_wow_nlo_cleanup(ar);
  487. if (ret)
  488. ath10k_warn(ar, "failed to cleanup nlo: %d\n", ret);
  489. exit:
  490. if (ret) {
  491. switch (ar->state) {
  492. case ATH10K_STATE_ON:
  493. ar->state = ATH10K_STATE_RESTARTING;
  494. ret = 1;
  495. break;
  496. case ATH10K_STATE_OFF:
  497. case ATH10K_STATE_RESTARTING:
  498. case ATH10K_STATE_RESTARTED:
  499. case ATH10K_STATE_UTF:
  500. case ATH10K_STATE_WEDGED:
  501. ath10k_warn(ar, "encountered unexpected device state %d on resume, cannot recover\n",
  502. ar->state);
  503. ret = -EIO;
  504. break;
  505. }
  506. }
  507. mutex_unlock(&ar->conf_mutex);
  508. return ret;
  509. }
  510. int ath10k_wow_init(struct ath10k *ar)
  511. {
  512. if (!test_bit(ATH10K_FW_FEATURE_WOWLAN_SUPPORT,
  513. ar->running_fw->fw_file.fw_features))
  514. return 0;
  515. if (WARN_ON(!test_bit(WMI_SERVICE_WOW, ar->wmi.svc_map)))
  516. return -EINVAL;
  517. ar->wow.wowlan_support = ath10k_wowlan_support;
  518. if (ar->wmi.rx_decap_mode == ATH10K_HW_TXRX_NATIVE_WIFI) {
  519. ar->wow.wowlan_support.pattern_max_len -= WOW_MAX_REDUCE;
  520. ar->wow.wowlan_support.max_pkt_offset -= WOW_MAX_REDUCE;
  521. }
  522. if (test_bit(WMI_SERVICE_NLO, ar->wmi.svc_map)) {
  523. ar->wow.wowlan_support.flags |= WIPHY_WOWLAN_NET_DETECT;
  524. ar->wow.wowlan_support.max_nd_match_sets = WMI_PNO_MAX_SUPP_NETWORKS;
  525. }
  526. ar->wow.wowlan_support.n_patterns = ar->wow.max_num_patterns;
  527. ar->hw->wiphy->wowlan = &ar->wow.wowlan_support;
  528. device_set_wakeup_capable(ar->dev, true);
  529. return 0;
  530. }