wow.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  1. // SPDX-License-Identifier: BSD-3-Clause-Clear
  2. /*
  3. * Copyright (c) 2020 The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include <linux/delay.h>
  7. #include "mac.h"
  8. #include <net/mac80211.h>
  9. #include "core.h"
  10. #include "hif.h"
  11. #include "debug.h"
  12. #include "wmi.h"
  13. #include "wow.h"
  14. #include "dp_rx.h"
  15. static const struct wiphy_wowlan_support ath11k_wowlan_support = {
  16. .flags = WIPHY_WOWLAN_DISCONNECT |
  17. WIPHY_WOWLAN_MAGIC_PKT |
  18. WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
  19. WIPHY_WOWLAN_GTK_REKEY_FAILURE,
  20. .pattern_min_len = WOW_MIN_PATTERN_SIZE,
  21. .pattern_max_len = WOW_MAX_PATTERN_SIZE,
  22. .max_pkt_offset = WOW_MAX_PKT_OFFSET,
  23. };
  24. int ath11k_wow_enable(struct ath11k_base *ab)
  25. {
  26. struct ath11k *ar = ath11k_ab_to_ar(ab, 0);
  27. int i, ret;
  28. clear_bit(ATH11K_FLAG_HTC_SUSPEND_COMPLETE, &ab->dev_flags);
  29. for (i = 0; i < ATH11K_WOW_RETRY_NUM; i++) {
  30. reinit_completion(&ab->htc_suspend);
  31. ret = ath11k_wmi_wow_enable(ar);
  32. if (ret) {
  33. ath11k_warn(ab, "failed to issue wow enable: %d\n", ret);
  34. return ret;
  35. }
  36. ret = wait_for_completion_timeout(&ab->htc_suspend, 3 * HZ);
  37. if (ret == 0) {
  38. ath11k_warn(ab,
  39. "timed out while waiting for htc suspend completion\n");
  40. return -ETIMEDOUT;
  41. }
  42. if (test_bit(ATH11K_FLAG_HTC_SUSPEND_COMPLETE, &ab->dev_flags))
  43. /* success, suspend complete received */
  44. return 0;
  45. ath11k_warn(ab, "htc suspend not complete, retrying (try %d)\n",
  46. i);
  47. msleep(ATH11K_WOW_RETRY_WAIT_MS);
  48. }
  49. ath11k_warn(ab, "htc suspend not complete, failing after %d tries\n", i);
  50. return -ETIMEDOUT;
  51. }
  52. int ath11k_wow_wakeup(struct ath11k_base *ab)
  53. {
  54. struct ath11k *ar = ath11k_ab_to_ar(ab, 0);
  55. int ret;
  56. /* In the case of WCN6750, WoW wakeup is done
  57. * by sending SMP2P power save exit message
  58. * to the target processor.
  59. */
  60. if (ab->hw_params.smp2p_wow_exit)
  61. return 0;
  62. reinit_completion(&ab->wow.wakeup_completed);
  63. ret = ath11k_wmi_wow_host_wakeup_ind(ar);
  64. if (ret) {
  65. ath11k_warn(ab, "failed to send wow wakeup indication: %d\n",
  66. ret);
  67. return ret;
  68. }
  69. ret = wait_for_completion_timeout(&ab->wow.wakeup_completed, 3 * HZ);
  70. if (ret == 0) {
  71. ath11k_warn(ab, "timed out while waiting for wow wakeup completion\n");
  72. return -ETIMEDOUT;
  73. }
  74. return 0;
  75. }
  76. static int ath11k_wow_vif_cleanup(struct ath11k_vif *arvif)
  77. {
  78. struct ath11k *ar = arvif->ar;
  79. int i, ret;
  80. for (i = 0; i < WOW_EVENT_MAX; i++) {
  81. ret = ath11k_wmi_wow_add_wakeup_event(ar, arvif->vdev_id, i, 0);
  82. if (ret) {
  83. ath11k_warn(ar->ab, "failed to issue wow wakeup for event %s on vdev %i: %d\n",
  84. wow_wakeup_event(i), arvif->vdev_id, ret);
  85. return ret;
  86. }
  87. }
  88. for (i = 0; i < ar->wow.max_num_patterns; i++) {
  89. ret = ath11k_wmi_wow_del_pattern(ar, arvif->vdev_id, i);
  90. if (ret) {
  91. ath11k_warn(ar->ab, "failed to delete wow pattern %d for vdev %i: %d\n",
  92. i, arvif->vdev_id, ret);
  93. return ret;
  94. }
  95. }
  96. return 0;
  97. }
  98. static int ath11k_wow_cleanup(struct ath11k *ar)
  99. {
  100. struct ath11k_vif *arvif;
  101. int ret;
  102. lockdep_assert_held(&ar->conf_mutex);
  103. list_for_each_entry(arvif, &ar->arvifs, list) {
  104. ret = ath11k_wow_vif_cleanup(arvif);
  105. if (ret) {
  106. ath11k_warn(ar->ab, "failed to clean wow wakeups on vdev %i: %d\n",
  107. arvif->vdev_id, ret);
  108. return ret;
  109. }
  110. }
  111. return 0;
  112. }
  113. /* Convert a 802.3 format to a 802.11 format.
  114. * +------------+-----------+--------+----------------+
  115. * 802.3: |dest mac(6B)|src mac(6B)|type(2B)| body... |
  116. * +------------+-----------+--------+----------------+
  117. * |__ |_______ |____________ |________
  118. * | | | |
  119. * +--+------------+----+-----------+---------------+-----------+
  120. * 802.11: |4B|dest mac(6B)| 6B |src mac(6B)| 8B |type(2B)| body... |
  121. * +--+------------+----+-----------+---------------+-----------+
  122. */
  123. static void ath11k_wow_convert_8023_to_80211(struct cfg80211_pkt_pattern *new,
  124. const struct cfg80211_pkt_pattern *old)
  125. {
  126. u8 hdr_8023_pattern[ETH_HLEN] = {};
  127. u8 hdr_8023_bit_mask[ETH_HLEN] = {};
  128. u8 hdr_80211_pattern[WOW_HDR_LEN] = {};
  129. u8 hdr_80211_bit_mask[WOW_HDR_LEN] = {};
  130. int total_len = old->pkt_offset + old->pattern_len;
  131. int hdr_80211_end_offset;
  132. struct ieee80211_hdr_3addr *new_hdr_pattern =
  133. (struct ieee80211_hdr_3addr *)hdr_80211_pattern;
  134. struct ieee80211_hdr_3addr *new_hdr_mask =
  135. (struct ieee80211_hdr_3addr *)hdr_80211_bit_mask;
  136. struct ethhdr *old_hdr_pattern = (struct ethhdr *)hdr_8023_pattern;
  137. struct ethhdr *old_hdr_mask = (struct ethhdr *)hdr_8023_bit_mask;
  138. int hdr_len = sizeof(*new_hdr_pattern);
  139. struct rfc1042_hdr *new_rfc_pattern =
  140. (struct rfc1042_hdr *)(hdr_80211_pattern + hdr_len);
  141. struct rfc1042_hdr *new_rfc_mask =
  142. (struct rfc1042_hdr *)(hdr_80211_bit_mask + hdr_len);
  143. int rfc_len = sizeof(*new_rfc_pattern);
  144. memcpy(hdr_8023_pattern + old->pkt_offset,
  145. old->pattern, ETH_HLEN - old->pkt_offset);
  146. memcpy(hdr_8023_bit_mask + old->pkt_offset,
  147. old->mask, ETH_HLEN - old->pkt_offset);
  148. /* Copy destination address */
  149. memcpy(new_hdr_pattern->addr1, old_hdr_pattern->h_dest, ETH_ALEN);
  150. memcpy(new_hdr_mask->addr1, old_hdr_mask->h_dest, ETH_ALEN);
  151. /* Copy source address */
  152. memcpy(new_hdr_pattern->addr3, old_hdr_pattern->h_source, ETH_ALEN);
  153. memcpy(new_hdr_mask->addr3, old_hdr_mask->h_source, ETH_ALEN);
  154. /* Copy logic link type */
  155. memcpy(&new_rfc_pattern->snap_type,
  156. &old_hdr_pattern->h_proto,
  157. sizeof(old_hdr_pattern->h_proto));
  158. memcpy(&new_rfc_mask->snap_type,
  159. &old_hdr_mask->h_proto,
  160. sizeof(old_hdr_mask->h_proto));
  161. /* Compute new pkt_offset */
  162. if (old->pkt_offset < ETH_ALEN)
  163. new->pkt_offset = old->pkt_offset +
  164. offsetof(struct ieee80211_hdr_3addr, addr1);
  165. else if (old->pkt_offset < offsetof(struct ethhdr, h_proto))
  166. new->pkt_offset = old->pkt_offset +
  167. offsetof(struct ieee80211_hdr_3addr, addr3) -
  168. offsetof(struct ethhdr, h_source);
  169. else
  170. new->pkt_offset = old->pkt_offset + hdr_len + rfc_len - ETH_HLEN;
  171. /* Compute new hdr end offset */
  172. if (total_len > ETH_HLEN)
  173. hdr_80211_end_offset = hdr_len + rfc_len;
  174. else if (total_len > offsetof(struct ethhdr, h_proto))
  175. hdr_80211_end_offset = hdr_len + rfc_len + total_len - ETH_HLEN;
  176. else if (total_len > ETH_ALEN)
  177. hdr_80211_end_offset = total_len - ETH_ALEN +
  178. offsetof(struct ieee80211_hdr_3addr, addr3);
  179. else
  180. hdr_80211_end_offset = total_len +
  181. offsetof(struct ieee80211_hdr_3addr, addr1);
  182. new->pattern_len = hdr_80211_end_offset - new->pkt_offset;
  183. memcpy((u8 *)new->pattern,
  184. hdr_80211_pattern + new->pkt_offset,
  185. new->pattern_len);
  186. memcpy((u8 *)new->mask,
  187. hdr_80211_bit_mask + new->pkt_offset,
  188. new->pattern_len);
  189. if (total_len > ETH_HLEN) {
  190. /* Copy frame body */
  191. memcpy((u8 *)new->pattern + new->pattern_len,
  192. (void *)old->pattern + ETH_HLEN - old->pkt_offset,
  193. total_len - ETH_HLEN);
  194. memcpy((u8 *)new->mask + new->pattern_len,
  195. (void *)old->mask + ETH_HLEN - old->pkt_offset,
  196. total_len - ETH_HLEN);
  197. new->pattern_len += total_len - ETH_HLEN;
  198. }
  199. }
  200. static int ath11k_wmi_pno_check_and_convert(struct ath11k *ar, u32 vdev_id,
  201. struct cfg80211_sched_scan_request *nd_config,
  202. struct wmi_pno_scan_req *pno)
  203. {
  204. int i, j;
  205. u8 ssid_len;
  206. pno->enable = 1;
  207. pno->vdev_id = vdev_id;
  208. pno->uc_networks_count = nd_config->n_match_sets;
  209. if (!pno->uc_networks_count ||
  210. pno->uc_networks_count > WMI_PNO_MAX_SUPP_NETWORKS)
  211. return -EINVAL;
  212. if (nd_config->n_channels > WMI_PNO_MAX_NETW_CHANNELS_EX)
  213. return -EINVAL;
  214. /* Filling per profile params */
  215. for (i = 0; i < pno->uc_networks_count; i++) {
  216. ssid_len = nd_config->match_sets[i].ssid.ssid_len;
  217. if (ssid_len == 0 || ssid_len > 32)
  218. return -EINVAL;
  219. pno->a_networks[i].ssid.ssid_len = ssid_len;
  220. memcpy(pno->a_networks[i].ssid.ssid,
  221. nd_config->match_sets[i].ssid.ssid,
  222. nd_config->match_sets[i].ssid.ssid_len);
  223. pno->a_networks[i].authentication = 0;
  224. pno->a_networks[i].encryption = 0;
  225. pno->a_networks[i].bcast_nw_type = 0;
  226. /* Copying list of valid channel into request */
  227. pno->a_networks[i].channel_count = nd_config->n_channels;
  228. pno->a_networks[i].rssi_threshold = nd_config->match_sets[i].rssi_thold;
  229. for (j = 0; j < nd_config->n_channels; j++) {
  230. pno->a_networks[i].channels[j] =
  231. nd_config->channels[j]->center_freq;
  232. }
  233. }
  234. /* set scan to passive if no SSIDs are specified in the request */
  235. if (nd_config->n_ssids == 0)
  236. pno->do_passive_scan = true;
  237. else
  238. pno->do_passive_scan = false;
  239. for (i = 0; i < nd_config->n_ssids; i++) {
  240. j = 0;
  241. while (j < pno->uc_networks_count) {
  242. if (pno->a_networks[j].ssid.ssid_len ==
  243. nd_config->ssids[i].ssid_len &&
  244. (memcmp(pno->a_networks[j].ssid.ssid,
  245. nd_config->ssids[i].ssid,
  246. pno->a_networks[j].ssid.ssid_len) == 0)) {
  247. pno->a_networks[j].bcast_nw_type = BCAST_HIDDEN;
  248. break;
  249. }
  250. j++;
  251. }
  252. }
  253. if (nd_config->n_scan_plans == 2) {
  254. pno->fast_scan_period = nd_config->scan_plans[0].interval * MSEC_PER_SEC;
  255. pno->fast_scan_max_cycles = nd_config->scan_plans[0].iterations;
  256. pno->slow_scan_period =
  257. nd_config->scan_plans[1].interval * MSEC_PER_SEC;
  258. } else if (nd_config->n_scan_plans == 1) {
  259. pno->fast_scan_period = nd_config->scan_plans[0].interval * MSEC_PER_SEC;
  260. pno->fast_scan_max_cycles = 1;
  261. pno->slow_scan_period = nd_config->scan_plans[0].interval * MSEC_PER_SEC;
  262. } else {
  263. ath11k_warn(ar->ab, "Invalid number of scan plans %d !!",
  264. nd_config->n_scan_plans);
  265. }
  266. if (nd_config->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
  267. /* enable mac randomization */
  268. pno->enable_pno_scan_randomization = 1;
  269. memcpy(pno->mac_addr, nd_config->mac_addr, ETH_ALEN);
  270. memcpy(pno->mac_addr_mask, nd_config->mac_addr_mask, ETH_ALEN);
  271. }
  272. pno->delay_start_time = nd_config->delay;
  273. /* Current FW does not support min-max range for dwell time */
  274. pno->active_max_time = WMI_ACTIVE_MAX_CHANNEL_TIME;
  275. pno->passive_max_time = WMI_PASSIVE_MAX_CHANNEL_TIME;
  276. return 0;
  277. }
  278. static int ath11k_vif_wow_set_wakeups(struct ath11k_vif *arvif,
  279. struct cfg80211_wowlan *wowlan)
  280. {
  281. int ret, i;
  282. unsigned long wow_mask = 0;
  283. struct ath11k *ar = arvif->ar;
  284. const struct cfg80211_pkt_pattern *patterns = wowlan->patterns;
  285. int pattern_id = 0;
  286. /* Setup requested WOW features */
  287. switch (arvif->vdev_type) {
  288. case WMI_VDEV_TYPE_IBSS:
  289. __set_bit(WOW_BEACON_EVENT, &wow_mask);
  290. fallthrough;
  291. case WMI_VDEV_TYPE_AP:
  292. __set_bit(WOW_DEAUTH_RECVD_EVENT, &wow_mask);
  293. __set_bit(WOW_DISASSOC_RECVD_EVENT, &wow_mask);
  294. __set_bit(WOW_PROBE_REQ_WPS_IE_EVENT, &wow_mask);
  295. __set_bit(WOW_AUTH_REQ_EVENT, &wow_mask);
  296. __set_bit(WOW_ASSOC_REQ_EVENT, &wow_mask);
  297. __set_bit(WOW_HTT_EVENT, &wow_mask);
  298. __set_bit(WOW_RA_MATCH_EVENT, &wow_mask);
  299. break;
  300. case WMI_VDEV_TYPE_STA:
  301. if (wowlan->disconnect) {
  302. __set_bit(WOW_DEAUTH_RECVD_EVENT, &wow_mask);
  303. __set_bit(WOW_DISASSOC_RECVD_EVENT, &wow_mask);
  304. __set_bit(WOW_BMISS_EVENT, &wow_mask);
  305. __set_bit(WOW_CSA_IE_EVENT, &wow_mask);
  306. }
  307. if (wowlan->magic_pkt)
  308. __set_bit(WOW_MAGIC_PKT_RECVD_EVENT, &wow_mask);
  309. if (wowlan->nd_config) {
  310. struct wmi_pno_scan_req *pno;
  311. int ret;
  312. pno = kzalloc(sizeof(*pno), GFP_KERNEL);
  313. if (!pno)
  314. return -ENOMEM;
  315. ar->nlo_enabled = true;
  316. ret = ath11k_wmi_pno_check_and_convert(ar, arvif->vdev_id,
  317. wowlan->nd_config, pno);
  318. if (!ret) {
  319. ath11k_wmi_wow_config_pno(ar, arvif->vdev_id, pno);
  320. __set_bit(WOW_NLO_DETECTED_EVENT, &wow_mask);
  321. }
  322. kfree(pno);
  323. }
  324. break;
  325. default:
  326. break;
  327. }
  328. for (i = 0; i < wowlan->n_patterns; i++) {
  329. u8 bitmask[WOW_MAX_PATTERN_SIZE] = {};
  330. u8 ath_pattern[WOW_MAX_PATTERN_SIZE] = {};
  331. u8 ath_bitmask[WOW_MAX_PATTERN_SIZE] = {};
  332. struct cfg80211_pkt_pattern new_pattern = {};
  333. struct cfg80211_pkt_pattern old_pattern = patterns[i];
  334. int j;
  335. new_pattern.pattern = ath_pattern;
  336. new_pattern.mask = ath_bitmask;
  337. if (patterns[i].pattern_len > WOW_MAX_PATTERN_SIZE)
  338. continue;
  339. /* convert bytemask to bitmask */
  340. for (j = 0; j < patterns[i].pattern_len; j++)
  341. if (patterns[i].mask[j / 8] & BIT(j % 8))
  342. bitmask[j] = 0xff;
  343. old_pattern.mask = bitmask;
  344. if (ar->wmi->wmi_ab->wlan_resource_config.rx_decap_mode ==
  345. ATH11K_HW_TXRX_NATIVE_WIFI) {
  346. if (patterns[i].pkt_offset < ETH_HLEN) {
  347. u8 pattern_ext[WOW_MAX_PATTERN_SIZE] = {};
  348. memcpy(pattern_ext, old_pattern.pattern,
  349. old_pattern.pattern_len);
  350. old_pattern.pattern = pattern_ext;
  351. ath11k_wow_convert_8023_to_80211(&new_pattern,
  352. &old_pattern);
  353. } else {
  354. new_pattern = old_pattern;
  355. new_pattern.pkt_offset += WOW_HDR_LEN - ETH_HLEN;
  356. }
  357. }
  358. if (WARN_ON(new_pattern.pattern_len > WOW_MAX_PATTERN_SIZE))
  359. return -EINVAL;
  360. ret = ath11k_wmi_wow_add_pattern(ar, arvif->vdev_id,
  361. pattern_id,
  362. new_pattern.pattern,
  363. new_pattern.mask,
  364. new_pattern.pattern_len,
  365. new_pattern.pkt_offset);
  366. if (ret) {
  367. ath11k_warn(ar->ab, "failed to add pattern %i to vdev %i: %d\n",
  368. pattern_id,
  369. arvif->vdev_id, ret);
  370. return ret;
  371. }
  372. pattern_id++;
  373. __set_bit(WOW_PATTERN_MATCH_EVENT, &wow_mask);
  374. }
  375. for (i = 0; i < WOW_EVENT_MAX; i++) {
  376. if (!test_bit(i, &wow_mask))
  377. continue;
  378. ret = ath11k_wmi_wow_add_wakeup_event(ar, arvif->vdev_id, i, 1);
  379. if (ret) {
  380. ath11k_warn(ar->ab, "failed to enable wakeup event %s on vdev %i: %d\n",
  381. wow_wakeup_event(i), arvif->vdev_id, ret);
  382. return ret;
  383. }
  384. }
  385. return 0;
  386. }
  387. static int ath11k_wow_set_wakeups(struct ath11k *ar,
  388. struct cfg80211_wowlan *wowlan)
  389. {
  390. struct ath11k_vif *arvif;
  391. int ret;
  392. lockdep_assert_held(&ar->conf_mutex);
  393. list_for_each_entry(arvif, &ar->arvifs, list) {
  394. ret = ath11k_vif_wow_set_wakeups(arvif, wowlan);
  395. if (ret) {
  396. ath11k_warn(ar->ab, "failed to set wow wakeups on vdev %i: %d\n",
  397. arvif->vdev_id, ret);
  398. return ret;
  399. }
  400. }
  401. return 0;
  402. }
  403. static int ath11k_vif_wow_clean_nlo(struct ath11k_vif *arvif)
  404. {
  405. int ret = 0;
  406. struct ath11k *ar = arvif->ar;
  407. switch (arvif->vdev_type) {
  408. case WMI_VDEV_TYPE_STA:
  409. if (ar->nlo_enabled) {
  410. struct wmi_pno_scan_req *pno;
  411. pno = kzalloc(sizeof(*pno), GFP_KERNEL);
  412. if (!pno)
  413. return -ENOMEM;
  414. pno->enable = 0;
  415. ar->nlo_enabled = false;
  416. ret = ath11k_wmi_wow_config_pno(ar, arvif->vdev_id, pno);
  417. kfree(pno);
  418. }
  419. break;
  420. default:
  421. break;
  422. }
  423. return ret;
  424. }
  425. static int ath11k_wow_nlo_cleanup(struct ath11k *ar)
  426. {
  427. struct ath11k_vif *arvif;
  428. int ret;
  429. lockdep_assert_held(&ar->conf_mutex);
  430. list_for_each_entry(arvif, &ar->arvifs, list) {
  431. ret = ath11k_vif_wow_clean_nlo(arvif);
  432. if (ret) {
  433. ath11k_warn(ar->ab, "failed to clean nlo settings on vdev %i: %d\n",
  434. arvif->vdev_id, ret);
  435. return ret;
  436. }
  437. }
  438. return 0;
  439. }
  440. static int ath11k_wow_set_hw_filter(struct ath11k *ar)
  441. {
  442. struct ath11k_vif *arvif;
  443. u32 bitmap;
  444. int ret;
  445. lockdep_assert_held(&ar->conf_mutex);
  446. list_for_each_entry(arvif, &ar->arvifs, list) {
  447. bitmap = WMI_HW_DATA_FILTER_DROP_NON_ICMPV6_MC |
  448. WMI_HW_DATA_FILTER_DROP_NON_ARP_BC;
  449. ret = ath11k_wmi_hw_data_filter_cmd(ar, arvif->vdev_id,
  450. bitmap,
  451. true);
  452. if (ret) {
  453. ath11k_warn(ar->ab, "failed to set hw data filter on vdev %i: %d\n",
  454. arvif->vdev_id, ret);
  455. return ret;
  456. }
  457. }
  458. return 0;
  459. }
  460. static int ath11k_wow_clear_hw_filter(struct ath11k *ar)
  461. {
  462. struct ath11k_vif *arvif;
  463. int ret;
  464. lockdep_assert_held(&ar->conf_mutex);
  465. list_for_each_entry(arvif, &ar->arvifs, list) {
  466. ret = ath11k_wmi_hw_data_filter_cmd(ar, arvif->vdev_id, 0, false);
  467. if (ret) {
  468. ath11k_warn(ar->ab, "failed to clear hw data filter on vdev %i: %d\n",
  469. arvif->vdev_id, ret);
  470. return ret;
  471. }
  472. }
  473. return 0;
  474. }
  475. static int ath11k_wow_arp_ns_offload(struct ath11k *ar, bool enable)
  476. {
  477. struct ath11k_vif *arvif;
  478. int ret;
  479. lockdep_assert_held(&ar->conf_mutex);
  480. list_for_each_entry(arvif, &ar->arvifs, list) {
  481. if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
  482. continue;
  483. ret = ath11k_wmi_arp_ns_offload(ar, arvif, enable);
  484. if (ret) {
  485. ath11k_warn(ar->ab, "failed to set arp ns offload vdev %i: enable %d, ret %d\n",
  486. arvif->vdev_id, enable, ret);
  487. return ret;
  488. }
  489. }
  490. return 0;
  491. }
  492. static int ath11k_gtk_rekey_offload(struct ath11k *ar, bool enable)
  493. {
  494. struct ath11k_vif *arvif;
  495. int ret;
  496. lockdep_assert_held(&ar->conf_mutex);
  497. list_for_each_entry(arvif, &ar->arvifs, list) {
  498. if (arvif->vdev_type != WMI_VDEV_TYPE_STA ||
  499. !arvif->is_up ||
  500. !arvif->rekey_data.enable_offload)
  501. continue;
  502. /* get rekey info before disable rekey offload */
  503. if (!enable) {
  504. ret = ath11k_wmi_gtk_rekey_getinfo(ar, arvif);
  505. if (ret) {
  506. ath11k_warn(ar->ab, "failed to request rekey info vdev %i, ret %d\n",
  507. arvif->vdev_id, ret);
  508. return ret;
  509. }
  510. }
  511. ret = ath11k_wmi_gtk_rekey_offload(ar, arvif, enable);
  512. if (ret) {
  513. ath11k_warn(ar->ab, "failed to offload gtk reky vdev %i: enable %d, ret %d\n",
  514. arvif->vdev_id, enable, ret);
  515. return ret;
  516. }
  517. }
  518. return 0;
  519. }
  520. static int ath11k_wow_protocol_offload(struct ath11k *ar, bool enable)
  521. {
  522. int ret;
  523. ret = ath11k_wow_arp_ns_offload(ar, enable);
  524. if (ret) {
  525. ath11k_warn(ar->ab, "failed to offload ARP and NS %d %d\n",
  526. enable, ret);
  527. return ret;
  528. }
  529. ret = ath11k_gtk_rekey_offload(ar, enable);
  530. if (ret) {
  531. ath11k_warn(ar->ab, "failed to offload gtk rekey %d %d\n",
  532. enable, ret);
  533. return ret;
  534. }
  535. return 0;
  536. }
  537. static int ath11k_wow_set_keepalive(struct ath11k *ar,
  538. enum wmi_sta_keepalive_method method,
  539. u32 interval)
  540. {
  541. struct ath11k_vif *arvif;
  542. int ret;
  543. lockdep_assert_held(&ar->conf_mutex);
  544. list_for_each_entry(arvif, &ar->arvifs, list) {
  545. ret = ath11k_mac_vif_set_keepalive(arvif, method, interval);
  546. if (ret)
  547. return ret;
  548. }
  549. return 0;
  550. }
  551. int ath11k_wow_op_suspend(struct ieee80211_hw *hw,
  552. struct cfg80211_wowlan *wowlan)
  553. {
  554. struct ath11k *ar = hw->priv;
  555. int ret;
  556. ret = ath11k_mac_wait_tx_complete(ar);
  557. if (ret) {
  558. ath11k_warn(ar->ab, "failed to wait tx complete: %d\n", ret);
  559. return ret;
  560. }
  561. mutex_lock(&ar->conf_mutex);
  562. ret = ath11k_dp_rx_pktlog_stop(ar->ab, true);
  563. if (ret) {
  564. ath11k_warn(ar->ab,
  565. "failed to stop dp rx (and timer) pktlog during wow suspend: %d\n",
  566. ret);
  567. goto exit;
  568. }
  569. ret = ath11k_wow_cleanup(ar);
  570. if (ret) {
  571. ath11k_warn(ar->ab, "failed to clear wow wakeup events: %d\n",
  572. ret);
  573. goto exit;
  574. }
  575. ret = ath11k_wow_set_wakeups(ar, wowlan);
  576. if (ret) {
  577. ath11k_warn(ar->ab, "failed to set wow wakeup events: %d\n",
  578. ret);
  579. goto cleanup;
  580. }
  581. ret = ath11k_wow_protocol_offload(ar, true);
  582. if (ret) {
  583. ath11k_warn(ar->ab, "failed to set wow protocol offload events: %d\n",
  584. ret);
  585. goto cleanup;
  586. }
  587. ret = ath11k_wow_set_hw_filter(ar);
  588. if (ret) {
  589. ath11k_warn(ar->ab, "failed to set hw filter: %d\n",
  590. ret);
  591. goto cleanup;
  592. }
  593. ret = ath11k_wow_set_keepalive(ar,
  594. WMI_STA_KEEPALIVE_METHOD_NULL_FRAME,
  595. WMI_STA_KEEPALIVE_INTERVAL_DEFAULT);
  596. if (ret) {
  597. ath11k_warn(ar->ab, "failed to enable wow keepalive: %d\n", ret);
  598. goto cleanup;
  599. }
  600. ret = ath11k_wow_enable(ar->ab);
  601. if (ret) {
  602. ath11k_warn(ar->ab, "failed to start wow: %d\n", ret);
  603. goto cleanup;
  604. }
  605. ret = ath11k_dp_rx_pktlog_stop(ar->ab, false);
  606. if (ret) {
  607. ath11k_warn(ar->ab,
  608. "failed to stop dp rx pktlog during wow suspend: %d\n",
  609. ret);
  610. goto cleanup;
  611. }
  612. ath11k_ce_stop_shadow_timers(ar->ab);
  613. ath11k_dp_stop_shadow_timers(ar->ab);
  614. ath11k_hif_irq_disable(ar->ab);
  615. ath11k_hif_ce_irq_disable(ar->ab);
  616. ret = ath11k_hif_suspend(ar->ab);
  617. if (ret) {
  618. ath11k_warn(ar->ab, "failed to suspend hif: %d\n", ret);
  619. goto wakeup;
  620. }
  621. goto exit;
  622. wakeup:
  623. ath11k_wow_wakeup(ar->ab);
  624. cleanup:
  625. ath11k_wow_cleanup(ar);
  626. exit:
  627. mutex_unlock(&ar->conf_mutex);
  628. return ret ? 1 : 0;
  629. }
  630. void ath11k_wow_op_set_wakeup(struct ieee80211_hw *hw, bool enabled)
  631. {
  632. struct ath11k *ar = hw->priv;
  633. mutex_lock(&ar->conf_mutex);
  634. device_set_wakeup_enable(ar->ab->dev, enabled);
  635. mutex_unlock(&ar->conf_mutex);
  636. }
  637. int ath11k_wow_op_resume(struct ieee80211_hw *hw)
  638. {
  639. struct ath11k *ar = hw->priv;
  640. int ret;
  641. mutex_lock(&ar->conf_mutex);
  642. ret = ath11k_hif_resume(ar->ab);
  643. if (ret) {
  644. ath11k_warn(ar->ab, "failed to resume hif: %d\n", ret);
  645. goto exit;
  646. }
  647. ath11k_hif_ce_irq_enable(ar->ab);
  648. ath11k_hif_irq_enable(ar->ab);
  649. ret = ath11k_dp_rx_pktlog_start(ar->ab);
  650. if (ret) {
  651. ath11k_warn(ar->ab, "failed to start rx pktlog from wow: %d\n", ret);
  652. goto exit;
  653. }
  654. ret = ath11k_wow_wakeup(ar->ab);
  655. if (ret) {
  656. ath11k_warn(ar->ab, "failed to wakeup from wow: %d\n", ret);
  657. goto exit;
  658. }
  659. ret = ath11k_wow_nlo_cleanup(ar);
  660. if (ret) {
  661. ath11k_warn(ar->ab, "failed to cleanup nlo: %d\n", ret);
  662. goto exit;
  663. }
  664. ret = ath11k_wow_clear_hw_filter(ar);
  665. if (ret) {
  666. ath11k_warn(ar->ab, "failed to clear hw filter: %d\n", ret);
  667. goto exit;
  668. }
  669. ret = ath11k_wow_protocol_offload(ar, false);
  670. if (ret) {
  671. ath11k_warn(ar->ab, "failed to clear wow protocol offload events: %d\n",
  672. ret);
  673. goto exit;
  674. }
  675. ret = ath11k_wow_set_keepalive(ar,
  676. WMI_STA_KEEPALIVE_METHOD_NULL_FRAME,
  677. WMI_STA_KEEPALIVE_INTERVAL_DISABLE);
  678. if (ret) {
  679. ath11k_warn(ar->ab, "failed to disable wow keepalive: %d\n", ret);
  680. goto exit;
  681. }
  682. exit:
  683. if (ret) {
  684. switch (ar->state) {
  685. case ATH11K_STATE_ON:
  686. ar->state = ATH11K_STATE_RESTARTING;
  687. ret = 1;
  688. break;
  689. case ATH11K_STATE_OFF:
  690. case ATH11K_STATE_RESTARTING:
  691. case ATH11K_STATE_RESTARTED:
  692. case ATH11K_STATE_WEDGED:
  693. ath11k_warn(ar->ab, "encountered unexpected device state %d on resume, cannot recover\n",
  694. ar->state);
  695. ret = -EIO;
  696. break;
  697. }
  698. }
  699. mutex_unlock(&ar->conf_mutex);
  700. return ret;
  701. }
  702. int ath11k_wow_init(struct ath11k *ar)
  703. {
  704. if (!test_bit(WMI_TLV_SERVICE_WOW, ar->wmi->wmi_ab->svc_map))
  705. return 0;
  706. ar->wow.wowlan_support = ath11k_wowlan_support;
  707. if (ar->wmi->wmi_ab->wlan_resource_config.rx_decap_mode ==
  708. ATH11K_HW_TXRX_NATIVE_WIFI) {
  709. ar->wow.wowlan_support.pattern_max_len -= WOW_MAX_REDUCE;
  710. ar->wow.wowlan_support.max_pkt_offset -= WOW_MAX_REDUCE;
  711. }
  712. if (test_bit(WMI_TLV_SERVICE_NLO, ar->wmi->wmi_ab->svc_map)) {
  713. ar->wow.wowlan_support.flags |= WIPHY_WOWLAN_NET_DETECT;
  714. ar->wow.wowlan_support.max_nd_match_sets = WMI_PNO_MAX_SUPP_NETWORKS;
  715. }
  716. ar->wow.max_num_patterns = ATH11K_WOW_PATTERNS;
  717. ar->wow.wowlan_support.n_patterns = ar->wow.max_num_patterns;
  718. ar->hw->wiphy->wowlan = &ar->wow.wowlan_support;
  719. device_set_wakeup_capable(ar->ab->dev, true);
  720. return 0;
  721. }