forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/net/wireless/ath/ath10k/wow.c
....@@ -1,18 +1,7 @@
1
+// SPDX-License-Identifier: ISC
12 /*
23 * Copyright (c) 2015-2017 Qualcomm Atheros, Inc.
34 * Copyright (c) 2018, The Linux Foundation. All rights reserved.
4
- *
5
- * Permission to use, copy, modify, and/or distribute this software for any
6
- * purpose with or without fee is hereby granted, provided that the above
7
- * copyright notice and this permission notice appear in all copies.
8
- *
9
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
165 */
176
187 #include "mac.h"
....@@ -77,7 +66,7 @@
7766 return 0;
7867 }
7968
80
-/**
69
+/*
8170 * Convert a 802.3 format to a 802.11 format.
8271 * +------------+-----------+--------+----------------+
8372 * 802.3: |dest mac(6B)|src mac(6B)|type(2B)| body... |
....@@ -88,9 +77,8 @@
8877 * 802.11: |4B|dest mac(6B)| 6B |src mac(6B)| 8B |type(2B)| body... |
8978 * +--+------------+----+-----------+---------------+-----------+
9079 */
91
-static void ath10k_wow_convert_8023_to_80211
92
- (struct cfg80211_pkt_pattern *new,
93
- const struct cfg80211_pkt_pattern *old)
80
+static void ath10k_wow_convert_8023_to_80211(struct cfg80211_pkt_pattern *new,
81
+ const struct cfg80211_pkt_pattern *old)
9482 {
9583 u8 hdr_8023_pattern[ETH_HLEN] = {};
9684 u8 hdr_8023_bit_mask[ETH_HLEN] = {};
....@@ -135,7 +123,7 @@
135123 &old_hdr_mask->h_proto,
136124 sizeof(old_hdr_mask->h_proto));
137125
138
- /* Caculate new pkt_offset */
126
+ /* Calculate new pkt_offset */
139127 if (old->pkt_offset < ETH_ALEN)
140128 new->pkt_offset = old->pkt_offset +
141129 offsetof(struct ieee80211_hdr_3addr, addr1);
....@@ -146,7 +134,7 @@
146134 else
147135 new->pkt_offset = old->pkt_offset + hdr_len + rfc_len - ETH_HLEN;
148136
149
- /* Caculate new hdr end offset */
137
+ /* Calculate new hdr end offset */
150138 if (total_len > ETH_HLEN)
151139 hdr_80211_end_offset = hdr_len + rfc_len;
152140 else if (total_len > offsetof(struct ethhdr, h_proto))
....@@ -180,6 +168,100 @@
180168 }
181169 }
182170
171
+static int ath10k_wmi_pno_check(struct ath10k *ar, u32 vdev_id,
172
+ struct cfg80211_sched_scan_request *nd_config,
173
+ struct wmi_pno_scan_req *pno)
174
+{
175
+ int i, j, ret = 0;
176
+ u8 ssid_len;
177
+
178
+ pno->enable = 1;
179
+ pno->vdev_id = vdev_id;
180
+ pno->uc_networks_count = nd_config->n_match_sets;
181
+
182
+ if (!pno->uc_networks_count ||
183
+ pno->uc_networks_count > WMI_PNO_MAX_SUPP_NETWORKS)
184
+ return -EINVAL;
185
+
186
+ if (nd_config->n_channels > WMI_PNO_MAX_NETW_CHANNELS_EX)
187
+ return -EINVAL;
188
+
189
+ /* Filling per profile params */
190
+ for (i = 0; i < pno->uc_networks_count; i++) {
191
+ ssid_len = nd_config->match_sets[i].ssid.ssid_len;
192
+
193
+ if (ssid_len == 0 || ssid_len > 32)
194
+ return -EINVAL;
195
+
196
+ pno->a_networks[i].ssid.ssid_len = __cpu_to_le32(ssid_len);
197
+
198
+ memcpy(pno->a_networks[i].ssid.ssid,
199
+ nd_config->match_sets[i].ssid.ssid,
200
+ nd_config->match_sets[i].ssid.ssid_len);
201
+ pno->a_networks[i].authentication = 0;
202
+ pno->a_networks[i].encryption = 0;
203
+ pno->a_networks[i].bcast_nw_type = 0;
204
+
205
+ /*Copying list of valid channel into request */
206
+ pno->a_networks[i].channel_count = nd_config->n_channels;
207
+ pno->a_networks[i].rssi_threshold = nd_config->match_sets[i].rssi_thold;
208
+
209
+ for (j = 0; j < nd_config->n_channels; j++) {
210
+ pno->a_networks[i].channels[j] =
211
+ nd_config->channels[j]->center_freq;
212
+ }
213
+ }
214
+
215
+ /* set scan to passive if no SSIDs are specified in the request */
216
+ if (nd_config->n_ssids == 0)
217
+ pno->do_passive_scan = true;
218
+ else
219
+ pno->do_passive_scan = false;
220
+
221
+ for (i = 0; i < nd_config->n_ssids; i++) {
222
+ j = 0;
223
+ while (j < pno->uc_networks_count) {
224
+ if (__le32_to_cpu(pno->a_networks[j].ssid.ssid_len) ==
225
+ nd_config->ssids[i].ssid_len &&
226
+ (memcmp(pno->a_networks[j].ssid.ssid,
227
+ nd_config->ssids[i].ssid,
228
+ __le32_to_cpu(pno->a_networks[j].ssid.ssid_len)) == 0)) {
229
+ pno->a_networks[j].bcast_nw_type = BCAST_HIDDEN;
230
+ break;
231
+ }
232
+ j++;
233
+ }
234
+ }
235
+
236
+ if (nd_config->n_scan_plans == 2) {
237
+ pno->fast_scan_period = nd_config->scan_plans[0].interval * MSEC_PER_SEC;
238
+ pno->fast_scan_max_cycles = nd_config->scan_plans[0].iterations;
239
+ pno->slow_scan_period =
240
+ nd_config->scan_plans[1].interval * MSEC_PER_SEC;
241
+ } else if (nd_config->n_scan_plans == 1) {
242
+ pno->fast_scan_period = nd_config->scan_plans[0].interval * MSEC_PER_SEC;
243
+ pno->fast_scan_max_cycles = 1;
244
+ pno->slow_scan_period = nd_config->scan_plans[0].interval * MSEC_PER_SEC;
245
+ } else {
246
+ ath10k_warn(ar, "Invalid number of scan plans %d !!",
247
+ nd_config->n_scan_plans);
248
+ }
249
+
250
+ if (nd_config->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
251
+ /* enable mac randomization */
252
+ pno->enable_pno_scan_randomization = 1;
253
+ memcpy(pno->mac_addr, nd_config->mac_addr, ETH_ALEN);
254
+ memcpy(pno->mac_addr_mask, nd_config->mac_addr_mask, ETH_ALEN);
255
+ }
256
+
257
+ pno->delay_start_time = nd_config->delay;
258
+
259
+ /* Current FW does not support min-max range for dwell time */
260
+ pno->active_max_time = WMI_ACTIVE_MAX_CHANNEL_TIME;
261
+ pno->passive_max_time = WMI_PASSIVE_MAX_CHANNEL_TIME;
262
+ return ret;
263
+}
264
+
183265 static int ath10k_vif_wow_set_wakeups(struct ath10k_vif *arvif,
184266 struct cfg80211_wowlan *wowlan)
185267 {
....@@ -193,7 +275,7 @@
193275 switch (arvif->vdev_type) {
194276 case WMI_VDEV_TYPE_IBSS:
195277 __set_bit(WOW_BEACON_EVENT, &wow_mask);
196
- /* fall through */
278
+ fallthrough;
197279 case WMI_VDEV_TYPE_AP:
198280 __set_bit(WOW_DEAUTH_RECVD_EVENT, &wow_mask);
199281 __set_bit(WOW_DISASSOC_RECVD_EVENT, &wow_mask);
....@@ -213,6 +295,26 @@
213295
214296 if (wowlan->magic_pkt)
215297 __set_bit(WOW_MAGIC_PKT_RECVD_EVENT, &wow_mask);
298
+
299
+ if (wowlan->nd_config) {
300
+ struct wmi_pno_scan_req *pno;
301
+ int ret;
302
+
303
+ pno = kzalloc(sizeof(*pno), GFP_KERNEL);
304
+ if (!pno)
305
+ return -ENOMEM;
306
+
307
+ ar->nlo_enabled = true;
308
+
309
+ ret = ath10k_wmi_pno_check(ar, arvif->vdev_id,
310
+ wowlan->nd_config, pno);
311
+ if (!ret) {
312
+ ath10k_wmi_wow_config_pno(ar, arvif->vdev_id, pno);
313
+ __set_bit(WOW_NLO_DETECTED_EVENT, &wow_mask);
314
+ }
315
+
316
+ kfree(pno);
317
+ }
216318 break;
217319 default:
218320 break;
....@@ -235,14 +337,15 @@
235337 if (patterns[i].mask[j / 8] & BIT(j % 8))
236338 bitmask[j] = 0xff;
237339 old_pattern.mask = bitmask;
238
- new_pattern = old_pattern;
239340
240341 if (ar->wmi.rx_decap_mode == ATH10K_HW_TXRX_NATIVE_WIFI) {
241
- if (patterns[i].pkt_offset < ETH_HLEN)
342
+ if (patterns[i].pkt_offset < ETH_HLEN) {
242343 ath10k_wow_convert_8023_to_80211(&new_pattern,
243344 &old_pattern);
244
- else
345
+ } else {
346
+ new_pattern = old_pattern;
245347 new_pattern.pkt_offset += WOW_HDR_LEN - ETH_HLEN;
348
+ }
246349 }
247350
248351 if (WARN_ON(new_pattern.pattern_len > WOW_MAX_PATTERN_SIZE))
....@@ -291,6 +394,51 @@
291394 ret = ath10k_vif_wow_set_wakeups(arvif, wowlan);
292395 if (ret) {
293396 ath10k_warn(ar, "failed to set wow wakeups on vdev %i: %d\n",
397
+ arvif->vdev_id, ret);
398
+ return ret;
399
+ }
400
+ }
401
+
402
+ return 0;
403
+}
404
+
405
+static int ath10k_vif_wow_clean_nlo(struct ath10k_vif *arvif)
406
+{
407
+ int ret = 0;
408
+ struct ath10k *ar = arvif->ar;
409
+
410
+ switch (arvif->vdev_type) {
411
+ case WMI_VDEV_TYPE_STA:
412
+ if (ar->nlo_enabled) {
413
+ struct wmi_pno_scan_req *pno;
414
+
415
+ pno = kzalloc(sizeof(*pno), GFP_KERNEL);
416
+ if (!pno)
417
+ return -ENOMEM;
418
+
419
+ pno->enable = 0;
420
+ ar->nlo_enabled = false;
421
+ ret = ath10k_wmi_wow_config_pno(ar, arvif->vdev_id, pno);
422
+ kfree(pno);
423
+ }
424
+ break;
425
+ default:
426
+ break;
427
+ }
428
+ return ret;
429
+}
430
+
431
+static int ath10k_wow_nlo_cleanup(struct ath10k *ar)
432
+{
433
+ struct ath10k_vif *arvif;
434
+ int ret = 0;
435
+
436
+ lockdep_assert_held(&ar->conf_mutex);
437
+
438
+ list_for_each_entry(arvif, &ar->arvifs, list) {
439
+ ret = ath10k_vif_wow_clean_nlo(arvif);
440
+ if (ret) {
441
+ ath10k_warn(ar, "failed to clean nlo settings on vdev %i: %d\n",
294442 arvif->vdev_id, ret);
295443 return ret;
296444 }
....@@ -374,6 +522,8 @@
374522 goto cleanup;
375523 }
376524
525
+ ath10k_mac_wait_tx_complete(ar);
526
+
377527 ret = ath10k_wow_enable(ar);
378528 if (ret) {
379529 ath10k_warn(ar, "failed to start wow: %d\n", ret);
....@@ -434,6 +584,10 @@
434584 if (ret)
435585 ath10k_warn(ar, "failed to wakeup from wow: %d\n", ret);
436586
587
+ ret = ath10k_wow_nlo_cleanup(ar);
588
+ if (ret)
589
+ ath10k_warn(ar, "failed to cleanup nlo: %d\n", ret);
590
+
437591 exit:
438592 if (ret) {
439593 switch (ar->state) {
....@@ -473,6 +627,11 @@
473627 ar->wow.wowlan_support.max_pkt_offset -= WOW_MAX_REDUCE;
474628 }
475629
630
+ if (test_bit(WMI_SERVICE_NLO, ar->wmi.svc_map)) {
631
+ ar->wow.wowlan_support.flags |= WIPHY_WOWLAN_NET_DETECT;
632
+ ar->wow.wowlan_support.max_nd_match_sets = WMI_PNO_MAX_SUPP_NETWORKS;
633
+ }
634
+
476635 ar->wow.wowlan_support.n_patterns = ar->wow.max_num_patterns;
477636 ar->hw->wiphy->wowlan = &ar->wow.wowlan_support;
478637