.. | .. |
---|
| 1 | +// SPDX-License-Identifier: ISC |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (c) 2015-2017 Qualcomm Atheros, Inc. |
---|
3 | 4 | * 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. |
---|
16 | 5 | */ |
---|
17 | 6 | |
---|
18 | 7 | #include "mac.h" |
---|
.. | .. |
---|
77 | 66 | return 0; |
---|
78 | 67 | } |
---|
79 | 68 | |
---|
80 | | -/** |
---|
| 69 | +/* |
---|
81 | 70 | * Convert a 802.3 format to a 802.11 format. |
---|
82 | 71 | * +------------+-----------+--------+----------------+ |
---|
83 | 72 | * 802.3: |dest mac(6B)|src mac(6B)|type(2B)| body... | |
---|
.. | .. |
---|
88 | 77 | * 802.11: |4B|dest mac(6B)| 6B |src mac(6B)| 8B |type(2B)| body... | |
---|
89 | 78 | * +--+------------+----+-----------+---------------+-----------+ |
---|
90 | 79 | */ |
---|
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) |
---|
94 | 82 | { |
---|
95 | 83 | u8 hdr_8023_pattern[ETH_HLEN] = {}; |
---|
96 | 84 | u8 hdr_8023_bit_mask[ETH_HLEN] = {}; |
---|
.. | .. |
---|
135 | 123 | &old_hdr_mask->h_proto, |
---|
136 | 124 | sizeof(old_hdr_mask->h_proto)); |
---|
137 | 125 | |
---|
138 | | - /* Caculate new pkt_offset */ |
---|
| 126 | + /* Calculate new pkt_offset */ |
---|
139 | 127 | if (old->pkt_offset < ETH_ALEN) |
---|
140 | 128 | new->pkt_offset = old->pkt_offset + |
---|
141 | 129 | offsetof(struct ieee80211_hdr_3addr, addr1); |
---|
.. | .. |
---|
146 | 134 | else |
---|
147 | 135 | new->pkt_offset = old->pkt_offset + hdr_len + rfc_len - ETH_HLEN; |
---|
148 | 136 | |
---|
149 | | - /* Caculate new hdr end offset */ |
---|
| 137 | + /* Calculate new hdr end offset */ |
---|
150 | 138 | if (total_len > ETH_HLEN) |
---|
151 | 139 | hdr_80211_end_offset = hdr_len + rfc_len; |
---|
152 | 140 | else if (total_len > offsetof(struct ethhdr, h_proto)) |
---|
.. | .. |
---|
180 | 168 | } |
---|
181 | 169 | } |
---|
182 | 170 | |
---|
| 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 | + |
---|
183 | 265 | static int ath10k_vif_wow_set_wakeups(struct ath10k_vif *arvif, |
---|
184 | 266 | struct cfg80211_wowlan *wowlan) |
---|
185 | 267 | { |
---|
.. | .. |
---|
193 | 275 | switch (arvif->vdev_type) { |
---|
194 | 276 | case WMI_VDEV_TYPE_IBSS: |
---|
195 | 277 | __set_bit(WOW_BEACON_EVENT, &wow_mask); |
---|
196 | | - /* fall through */ |
---|
| 278 | + fallthrough; |
---|
197 | 279 | case WMI_VDEV_TYPE_AP: |
---|
198 | 280 | __set_bit(WOW_DEAUTH_RECVD_EVENT, &wow_mask); |
---|
199 | 281 | __set_bit(WOW_DISASSOC_RECVD_EVENT, &wow_mask); |
---|
.. | .. |
---|
213 | 295 | |
---|
214 | 296 | if (wowlan->magic_pkt) |
---|
215 | 297 | __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 | + } |
---|
216 | 318 | break; |
---|
217 | 319 | default: |
---|
218 | 320 | break; |
---|
.. | .. |
---|
235 | 337 | if (patterns[i].mask[j / 8] & BIT(j % 8)) |
---|
236 | 338 | bitmask[j] = 0xff; |
---|
237 | 339 | old_pattern.mask = bitmask; |
---|
238 | | - new_pattern = old_pattern; |
---|
239 | 340 | |
---|
240 | 341 | 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) { |
---|
242 | 343 | ath10k_wow_convert_8023_to_80211(&new_pattern, |
---|
243 | 344 | &old_pattern); |
---|
244 | | - else |
---|
| 345 | + } else { |
---|
| 346 | + new_pattern = old_pattern; |
---|
245 | 347 | new_pattern.pkt_offset += WOW_HDR_LEN - ETH_HLEN; |
---|
| 348 | + } |
---|
246 | 349 | } |
---|
247 | 350 | |
---|
248 | 351 | if (WARN_ON(new_pattern.pattern_len > WOW_MAX_PATTERN_SIZE)) |
---|
.. | .. |
---|
291 | 394 | ret = ath10k_vif_wow_set_wakeups(arvif, wowlan); |
---|
292 | 395 | if (ret) { |
---|
293 | 396 | 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", |
---|
294 | 442 | arvif->vdev_id, ret); |
---|
295 | 443 | return ret; |
---|
296 | 444 | } |
---|
.. | .. |
---|
374 | 522 | goto cleanup; |
---|
375 | 523 | } |
---|
376 | 524 | |
---|
| 525 | + ath10k_mac_wait_tx_complete(ar); |
---|
| 526 | + |
---|
377 | 527 | ret = ath10k_wow_enable(ar); |
---|
378 | 528 | if (ret) { |
---|
379 | 529 | ath10k_warn(ar, "failed to start wow: %d\n", ret); |
---|
.. | .. |
---|
434 | 584 | if (ret) |
---|
435 | 585 | ath10k_warn(ar, "failed to wakeup from wow: %d\n", ret); |
---|
436 | 586 | |
---|
| 587 | + ret = ath10k_wow_nlo_cleanup(ar); |
---|
| 588 | + if (ret) |
---|
| 589 | + ath10k_warn(ar, "failed to cleanup nlo: %d\n", ret); |
---|
| 590 | + |
---|
437 | 591 | exit: |
---|
438 | 592 | if (ret) { |
---|
439 | 593 | switch (ar->state) { |
---|
.. | .. |
---|
473 | 627 | ar->wow.wowlan_support.max_pkt_offset -= WOW_MAX_REDUCE; |
---|
474 | 628 | } |
---|
475 | 629 | |
---|
| 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 | + |
---|
476 | 635 | ar->wow.wowlan_support.n_patterns = ar->wow.max_num_patterns; |
---|
477 | 636 | ar->hw->wiphy->wowlan = &ar->wow.wowlan_support; |
---|
478 | 637 | |
---|