ath10k: Convert wow pattern from 802.3 to 802.11
PATCH 1/1 ath10k: Convert wow pattern from 802.3 to 802.11
When trying to set wow wakeup patterns it fails with this command:
iw phyxx wowlan enable patterns offset xx+ IP address xx.xx.xx.xx
The reason is that the wow pattern from upper layer is in 802.3 format for this case, it need to convert it to 802.11 format. The input offset parameter is used for 802.3, but the actual offset firmware need depends on rx_decap_mode, so that it needs to be recalculated. Pattern of 802.3 packet is not same with 802.11 packet. If the rx_decap_mode is ATH10K_HW_TXRX_NATIVE_WIFI, then firmware will receive data packet with 802.11 format from hardware.
Convert graph:
-----------------------------------------------------------------------
802.3 |dest mac(6B)|src mac(6B)|type(2B)| body... |
|__ |_______ |_____________ |___________
| | | |
802.11 |4B|dest mac(6B)| 6B |src mac(6B)| 8B |type(2B)| body... |-----------------------------------------------------------------------
Tested with QCA6174 hw3.0 with firmware WLAN.RM.4.4.1-00099-QCARMSWPZ-1, but this will also affect QCA9377. This has always failed, so it's not a regression with new firmware releases.
--- drivers/net/wireless/ath/ath10k/wmi.h | 4 ++ drivers/net/wireless/ath/ath10k/wow.c | 128 ++++++++++++++++++++++++++++++++-- 2 files changed, 126 insertions(+), 6 deletions(-)
drivers/net/wireless/ath/ath10k/wmi.h +4 -0
@@ -6724,6 +6724,10 @@ struct wmi_wow_ev_arg {#define WOW_MIN_PATTERN_SIZE 1#define WOW_MAX_PATTERN_SIZE 148#define WOW_MAX_PKT_OFFSET 128 +#define WOW_HDR_LEN (sizeof(struct ieee80211_hdr_3addr) + \ + sizeof(struct rfc1042_hdr)) +#define WOW_MAX_REDUCE (WOW_HDR_LEN - sizeof(struct ethhdr) - \ + offsetof(struct ieee80211_hdr_3addr, addr1))enum wmi_tdls_state {WMI_TDLS_DISABLE ,
drivers/net/wireless/ath/ath10k/wow.c +122 -6
161 lines not on this page · raw message
Signature · 1 line
2.7.4
Hi,
Quoted 12 lines · Wen Gong
When trying to set wow wakeup patterns it fails with this command:
iw phyxx wowlan enable patterns offset xx+ IP address xx.xx.xx.xx
The reason is that the wow pattern from upper layer is in 802.3 format for this case, it need to convert it to 802.11 format. The input offset parameter is used for 802.3, but the actual offset firmware need depends on
rx_decap_mode, so that it needs to be recalculated. Pattern of 802.3 packet is not same with 802.11 packet. If therx_decap_modeisATH10K_HW_TXRX_NATIVE_WIFI, then firmware will receive data packet with 802.11 format from hardware.
Quoted 7 lines
Convert graph:
-----------------------------------------------------------------------
802.3 |dest mac(6B)|src mac(6B)|type(2B)| body... ||__ |_______ |_____________ |___________ | | | | 802.11 |4B|dest mac(6B)| 6B |src mac(6B)| 8B |type(2B)| body... |-----------------------------------------------------------------------
It feels like this could go into the code comments? Or at least some short version of it. (But hey, text is cheap, and who doesn't love ASCII art?)
Quoted 138 lines
Tested with QCA6174 hw3.0 with firmware WLAN.RM.4.4.1-00099-QCARMSWPZ-1, but this will also affect QCA9377. This has always failed, so it's not a regression with new firmware releases.
Signed-off-by Wen Gong <[email protected]>--- drivers/net/wireless/ath/ath10k/wmi.h | 4 ++ drivers/net/wireless/ath/ath10k/wow.c | 128 ++++++++++++++++++++++++++++++++-- 2 files changed, 126 insertions(+), 6 deletions(-)drivers/net/wireless/ath/ath10k/wmi.h +4
-0@@ -6724,6 +6724,10 @@ struct wmi_wow_ev_arg {#define WOW_MIN_PATTERN_SIZE 1#define WOW_MAX_PATTERN_SIZE 148#define WOW_MAX_PKT_OFFSET 128 +#define WOW_HDR_LEN (sizeof(struct ieee80211_hdr_3addr) + \ + sizeof(struct rfc1042_hdr)) +#define WOW_MAX_REDUCE (WOW_HDR_LEN - sizeof(struct ethhdr) - \ + offsetof(struct ieee80211_hdr_3addr, addr1))enum wmi_tdls_state {WMI_TDLS_DISABLE ,drivers/net/wireless/ath/ath10k/wow.c +93
-0@@ -1,5 +1,6 @@/* * Copyright (c) 2015-2017 Qualcomm Atheros, Inc. +* Copyright (c) 2018, The Linux Foundation. All rights reserved. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -76,6 +77,98 @@ static int ath10k_wow_cleanup(struct ath10k *ar)return 0 ; } +static void ath10k_wow_convert_8023_to_80211 + (struct cfg80211_pkt_pattern *new, +const struct cfg80211_pkt_pattern *old) +{ +u8 hdr_8023_pattern[ETH_HLEN ] = {}; +u8 hdr_8023_bit_mask[ETH_HLEN ] = {}; +u8 hdr_80211_pattern[WOW_HDR_LEN ] = {}; +u8 hdr_80211_bit_mask[WOW_HDR_LEN ] = {}; + +int total_len = old->pkt_offset + old->pattern_len; +int hdr_80211_end_offset; + +struct ieee80211_hdr_3addr *new_hdr_pattern = + (struct ieee80211_hdr_3addr *)hdr_80211_pattern; +struct ieee80211_hdr_3addr *new_hdr_mask = + (struct ieee80211_hdr_3addr *)hdr_80211_bit_mask; +struct ethhdr *old_hdr_pattern = (struct ethhdr *)hdr_8023_pattern; +struct ethhdr *old_hdr_mask = (struct ethhdr *)hdr_8023_bit_mask; +int hdr_len =sizeof (*new_hdr_pattern); + +struct rfc1042_hdr *new_rfc_pattern = + (struct rfc1042_hdr *)(hdr_80211_pattern + hdr_len); +struct rfc1042_hdr *new_rfc_mask = + (struct rfc1042_hdr *)(hdr_80211_bit_mask + hdr_len); +int rfc_len =sizeof (*new_rfc_pattern); + +memcpy (hdr_8023_pattern + old->pkt_offset, + old->pattern,ETH_HLEN - old->pkt_offset); +memcpy (hdr_8023_bit_mask + old->pkt_offset, + old->mask,ETH_HLEN - old->pkt_offset); + +/* Copy destination address */ +memcpy (new_hdr_pattern->addr1, old_hdr_pattern->h_dest,ETH_ALEN ); +memcpy (new_hdr_mask->addr1, old_hdr_mask->h_dest,ETH_ALEN ); + +/* Copy source address */ +memcpy (new_hdr_pattern->addr3, old_hdr_pattern->h_source,ETH_ALEN ); +memcpy (new_hdr_mask->addr3, old_hdr_mask->h_source,ETH_ALEN ); + +/* Copy logic link type */ +memcpy (&new_rfc_pattern->snap_type, + &old_hdr_pattern->h_proto, +sizeof (old_hdr_pattern->h_proto)); +memcpy (&new_rfc_mask->snap_type, + &old_hdr_mask->h_proto, +sizeof (old_hdr_mask->h_proto)); + +/* Caculate new pkt_offset */ +if (old->pkt_offset <ETH_ALEN ) + new->pkt_offset = old->pkt_offset + + offsetof(struct ieee80211_hdr_3addr , addr1); +else if (old->pkt_offset < offsetof(struct ethhdr , h_proto)) + new->pkt_offset = old->pkt_offset + + offsetof(struct ieee80211_hdr_3addr , addr3) - + offsetof(struct ethhdr , h_source); +else + new->pkt_offset = old->pkt_offset + hdr_len + rfc_len -ETH_HLEN ; + +/* Caculate new hdr end offset */ +if (total_len >ETH_HLEN ) + hdr_80211_end_offset = hdr_len + rfc_len; +else if (total_len > offsetof(struct ethhdr , h_proto)) + hdr_80211_end_offset = hdr_len + rfc_len + total_len -ETH_HLEN ; +else if (total_len >ETH_ALEN ) + hdr_80211_end_offset = total_len -ETH_ALEN + + offsetof(struct ieee80211_hdr_3addr , addr3); +else + hdr_80211_end_offset = total_len + + offsetof(struct ieee80211_hdr_3addr , addr1); + + new->pattern_len = hdr_80211_end_offset - new->pkt_offset; + +memcpy ((u8 *)new->pattern, + hdr_80211_pattern + new->pkt_offset, + new->pattern_len); +memcpy ((u8 *)new->mask, + hdr_80211_bit_mask + new->pkt_offset, + new->pattern_len); + +if (total_len >ETH_HLEN ) { +/* Copy frame body */ +memcpy ((u8 *)new->pattern + new->pattern_len, + (void *)old->pattern +ETH_HLEN - old->pkt_offset, + total_len -ETH_HLEN ); +memcpy ((u8 *)new->mask + new->pattern_len, + (void *)old->mask +ETH_HLEN - old->pkt_offset, + total_len -ETH_HLEN ); + + new->pattern_len += total_len -ETH_HLEN ; + } +} +static int ath10k_vif_wow_set_wakeups (struct ath10k_vif *arvif,struct cfg80211_wowlan *wowlan) {
drivers/net/wireless/ath/ath10k/wow.c static int ath10k_vif_wow_set_wakeups(struct ath10k_vif *arvif, · line 213
Quoted 5 lines
drivers/net/wireless/ath/ath10k/wow.c +2
-0@@ -116,22 +209,39 @@ static int ath10k_vif_wow_set_wakeups(struct ath10k_vif *arvif,for (i =0 ; i < wowlan->n_patterns; i++) {u8 bitmask[WOW_MAX_PATTERN_SIZE ] = {}; +u8 ath_pattern[WOW_MAX_PATTERN_SIZE ] = {}; +u8 ath_bitmask[WOW_MAX_PATTERN_SIZE ] = {};
So now we've got 3 * 148 = 444 bytes on the stack just for this? Seems like it's getting a little large for kernel code, but maybe not too bad. I guess we can go with this until somebody runs into a real problem...
Otherwise, seems to work for me:
Quoted 56 lines
drivers/net/wireless/ath/ath10k/wow.c +27
-6+struct cfg80211_pkt_pattern new_pattern = {}; +struct cfg80211_pkt_pattern old_pattern = patterns[i];int j; - + new_pattern.pattern = ath_pattern; + new_pattern.mask = ath_bitmask;if (patterns[i].pattern_len >WOW_MAX_PATTERN_SIZE )continue ; -/* convert bytemask to bitmask */ for (j =0 ; j < patterns[i].pattern_len; j++)if (patterns[i].mask[j /8 ] &BIT (j %8 )) bitmask[j] =0xff ; + old_pattern.mask = bitmask; + new_pattern = old_pattern; + +if (ar->wmi.rx_decap_mode ==ATH10K_HW_TXRX_NATIVE_WIFI ) { +if (patterns[i].pkt_offset <ETH_HLEN ) +ath10k_wow_convert_8023_to_80211 (&new_pattern, + &old_pattern); +else + new_pattern.pkt_offset +=WOW_HDR_LEN -ETH_HLEN ; + } + +if (WARN_ON (new_pattern.pattern_len >WOW_MAX_PATTERN_SIZE )) +return -EINVAL ; ret =ath10k_wmi_wow_add_pattern (ar, arvif->vdev_id, pattern_id, - patterns[i].pattern, - bitmask, - patterns[i].pattern_len, - patterns[i].pkt_offset); + new_pattern.pattern, + new_pattern.mask, + new_pattern.pattern_len, + new_pattern.pkt_offset);if (ret) { ath10k_warn(ar, "failed to add pattern %i to vdev %i: %d\n", pattern_id,@@ -345,6 +455,12 @@ int ath10k_wow_init(struct ath10k *ar)return -EINVAL ; ar->wow.wowlan_support = ath10k_wowlan_support; + +if (ar->wmi.rx_decap_mode ==ATH10K_HW_TXRX_NATIVE_WIFI ) { + ar->wow.wowlan_support.pattern_max_len -=WOW_MAX_REDUCE ; + ar->wow.wowlan_support.max_pkt_offset -=WOW_MAX_REDUCE ; + } + ar->wow.wowlan_support.n_patterns = ar->wow.max_num_patterns; ar->hw->wiphy->wowlan = &ar->wow.wowlan_support;Signature · 1 line
2.7.4
Hi,
I will move the convert graph from comments to code. And new graph like this:
/**
+ * Convert a 802.3 format to a 802.11 format.
+ * +------------+-----------+--------+----------------+ + * 802.3: |dest mac(6B)|src mac(6B)|type(2B)| body... | + * +------------+-----------+--------+----------------+ + * |__ |_______ |____________ |________ + * | | | | + * +--+------------+----+-----------+---------------+-----------+ + * 802.11: |4B|dest mac(6B)| 6B |src mac(6B)| 8B |type(2B)| body... | + * +--+------------+----+-----------+---------------+-----------+
+ */
+static void ath10k_wow_convert_8023_to_80211
+ (struct cfg80211_pkt_pattern *new,
+ const struct cfg80211_pkt_pattern *old)
And the 444 bytes on stack will remain since the comments is: "we can go with this until somebody runs into a real problem"
Thanks
Gong Wen
Quoted 261 lines
-----Original Message-----
From: ath10k [mailto:[email protected]] On Behalf Of Brian Norris
Sent: Thursday, April 12, 2018 7:13 AM
To: Wen Gong <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [PATCH] ath10k: Convert wow pattern from 802.3 to 802.11Hi,
Quoted 12 lines · Wen Gong
When trying to set wow wakeup patterns it fails with this command:
iw phyxx wowlan enable patterns offset xx+ IP address xx.xx.xx.xx
The reason is that the wow pattern from upper layer is in 802.3 format for this case, it need to convert it to 802.11 format. The input offset parameter is used for 802.3, but the actual offset firmware need depends on
rx_decap_mode, so that it needs to be recalculated. Pattern of 802.3 packet is not same with 802.11 packet. If therx_decap_modeisATH10K_HW_TXRX_NATIVE_WIFI, then firmware will receive data packet with 802.11 format from hardware.Quoted 8 lines
Convert graph:
-----------------------------------------------------------------------
802.3 |dest mac(6B)|src mac(6B)|type(2B)| body... ||__ |_______ |_____________ |___________ | | | | 802.11 |4B|dest mac(6B)| 6B |src mac(6B)| 8B |type(2B)| body... |----------------------------------------------------------------------
-It feels like this could go into the code comments? Or at least some short version of it. (But hey, text is cheap, and who doesn't love ASCII art?)
Quoted 19 lines
Tested with QCA6174 hw3.0 with firmware WLAN.RM.4.4.1-00099-QCARMSWPZ-1, but this will also affect QCA9377. This has always failed, so it's not a regression with new firmware releases.
Signed-off-by Wen Gong <[email protected]>--- drivers/net/wireless/ath/ath10k/wmi.h | 4 ++ drivers/net/wireless/ath/ath10k/wow.c | 128 ++++++++++++++++++++++++++++++++-- 2 files changed, 126 insertions(+), 6 deletions(-)drivers/net/wireless/ath/ath10k/wmi.h +0
-0drivers/net/wireless/ath/ath10k/wmi.h struct wmi_wow_ev_arg { · line 6729
Quoted 6 lines
drivers/net/wireless/ath/ath10k/wmi.h +3
-0@@ -6724,6 +6724,10 @@ struct wmi_wow_ev_arg {#define WOW_MIN_PATTERN_SIZE 1#define WOW_MAX_PATTERN_SIZE 148#define WOW_MAX_PKT_OFFSET 128 +#define WOW_HDR_LEN (sizeof(struct ieee80211_hdr_3addr) + \ + sizeof(struct rfc1042_hdr)) +#define WOW_MAX_REDUCE (WOW_HDR_LEN - sizeof(structethhdr) - \
Quoted 16 lines
drivers/net/wireless/ath/ath10k/wmi.h +1
-0+ offsetof(struct ieee80211_hdr_3addr, addr1)) enum wmi_tdls_state { WMI_TDLS_DISABLE,drivers/net/wireless/ath/ath10k/wow.c +1
-0@@ -1,5 +1,6 @@/* * Copyright (c) 2015-2017 Qualcomm Atheros, Inc. +* Copyright (c) 2018, The Linux Foundation. All rights reserved. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the Quoted 1 line
above @@ -76,6 +77,98 @@ static int ath10k_wow_cleanup(struct ath10k
*ar)
drivers/net/wireless/ath/ath10k/wow.c static int ath10k_wow_cleanup(struct ath10k *ar)
Quoted 6 lines
drivers/net/wireless/ath/ath10k/wow.c +3
-0return 0 ; } +static void ath10k_wow_convert_8023_to_80211 + (struct cfg80211_pkt_pattern *new, + const struct cfg80211_pkt_pattern*old) {
Quoted 19 lines
drivers/net/wireless/ath/ath10k/wow.c +19
-0+u8 hdr_8023_pattern[ETH_HLEN ] = {}; +u8 hdr_8023_bit_mask[ETH_HLEN ] = {}; +u8 hdr_80211_pattern[WOW_HDR_LEN ] = {}; +u8 hdr_80211_bit_mask[WOW_HDR_LEN ] = {}; + +int total_len = old->pkt_offset + old->pattern_len; +int hdr_80211_end_offset; + +struct ieee80211_hdr_3addr *new_hdr_pattern = + (struct ieee80211_hdr_3addr *)hdr_80211_pattern; +struct ieee80211_hdr_3addr *new_hdr_mask = + (struct ieee80211_hdr_3addr *)hdr_80211_bit_mask; +struct ethhdr *old_hdr_pattern = (struct ethhdr *)hdr_8023_pattern; +struct ethhdr *old_hdr_mask = (struct ethhdr *)hdr_8023_bit_mask; +int hdr_len =sizeof (*new_hdr_pattern); + +struct rfc1042_hdr *new_rfc_pattern = + (struct rfc1042_hdr *)(hdr_80211_pattern + hdr_len); + struct rfc1042_hdr *new_rfc_mask =drivers/net/wireless/ath/ath10k/wow.c static int ath10k_wow_cleanup(struct ath10k *ar)
Quoted 10 lines
drivers/net/wireless/ath/ath10k/wow.c +10
-0+ (struct rfc1042_hdr *)(hdr_80211_bit_mask + hdr_len); +int rfc_len =sizeof (*new_rfc_pattern); + +memcpy (hdr_8023_pattern + old->pkt_offset, + old->pattern,ETH_HLEN - old->pkt_offset); +memcpy (hdr_8023_bit_mask + old->pkt_offset, + old->mask,ETH_HLEN - old->pkt_offset); + +/* Copy destination address */ + memcpy(new_hdr_pattern->addr1, old_hdr_pattern->h_dest,
ETH_ALEN);drivers/net/wireless/ath/ath10k/wow.c static int ath10k_wow_cleanup(struct ath10k *ar)
Quoted 4 lines
drivers/net/wireless/ath/ath10k/wow.c +4
-0+memcpy (new_hdr_mask->addr1, old_hdr_mask->h_dest,ETH_ALEN ); + +/* Copy source address */ + memcpy(new_hdr_pattern->addr3, old_hdr_pattern->h_source,
ETH_ALEN);drivers/net/wireless/ath/ath10k/wow.c
Quoted 1 line
drivers/net/wireless/ath/ath10k/wow.c +1
-0+ memcpy(new_hdr_mask->addr3, old_hdr_mask->h_source,
ETH_ALEN);Quoted 9 lines
drivers/net/wireless/ath/ath10k/wow.c +9
-0+ +/* Copy logic link type */ +memcpy (&new_rfc_pattern->snap_type, + &old_hdr_pattern->h_proto, +sizeof (old_hdr_pattern->h_proto)); +memcpy (&new_rfc_mask->snap_type, + &old_hdr_mask->h_proto, +sizeof (old_hdr_mask->h_proto)); +drivers/net/wireless/ath/ath10k/wow.c static int ath10k_wow_cleanup(struct ath10k *ar)
Quoted 10 lines
drivers/net/wireless/ath/ath10k/wow.c +10
-0+/* Caculate new pkt_offset */ +if (old->pkt_offset <ETH_ALEN ) + new->pkt_offset = old->pkt_offset + + offsetof(struct ieee80211_hdr_3addr , addr1); +else if (old->pkt_offset < offsetof(struct ethhdr , h_proto)) + new->pkt_offset = old->pkt_offset + + offsetof(struct ieee80211_hdr_3addr , addr3) - + offsetof(struct ethhdr , h_source); +else + new->pkt_offset = old->pkt_offset + hdr_len + rfc_len -
ETH_HLEN;drivers/net/wireless/ath/ath10k/wow.c static int ath10k_wow_cleanup(struct ath10k *ar)
Quoted 6 lines
drivers/net/wireless/ath/ath10k/wow.c +6
-0+ +/* Caculate new hdr end offset */ +if (total_len >ETH_HLEN ) + hdr_80211_end_offset = hdr_len + rfc_len; +else if (total_len > offsetof(struct ethhdr , h_proto)) + hdr_80211_end_offset = hdr_len + rfc_len + total_len -
ETH_HLEN;Quoted 21 lines
drivers/net/wireless/ath/ath10k/wow.c +21
-0+else if (total_len >ETH_ALEN ) + hdr_80211_end_offset = total_len -ETH_ALEN + + offsetof(struct ieee80211_hdr_3addr , addr3); +else + hdr_80211_end_offset = total_len + + offsetof(struct ieee80211_hdr_3addr , addr1); + + new->pattern_len = hdr_80211_end_offset - new->pkt_offset; + +memcpy ((u8 *)new->pattern, + hdr_80211_pattern + new->pkt_offset, + new->pattern_len); +memcpy ((u8 *)new->mask, + hdr_80211_bit_mask + new->pkt_offset, + new->pattern_len); + +if (total_len >ETH_HLEN ) { +/* Copy frame body */ +memcpy ((u8 *)new->pattern + new->pattern_len, + (void *)old->pattern +ETH_HLEN - old->pkt_offset, + total_len -ETH_HLEN );drivers/net/wireless/ath/ath10k/wow.c static int ath10k_wow_cleanup(struct ath10k *ar)
Quoted 10 lines
drivers/net/wireless/ath/ath10k/wow.c +8
-0+memcpy ((u8 *)new->mask + new->pattern_len, + (void *)old->mask +ETH_HLEN - old->pkt_offset, + total_len -ETH_HLEN ); + + new->pattern_len += total_len -ETH_HLEN ; + } +} +static int ath10k_vif_wow_set_wakeups (struct ath10k_vif *arvif, struct cfg80211_wowlan *wowlan) { @@-116,22 +209,39 @@
drivers/net/wireless/ath/ath10k/wow.c static int ath10k_vif_wow_set_wakeups(struct ath10k_vif *arvif, · line 213
Quoted 6 lines
static int ath10k_vif_wow_set_wakeups(struct
ath10k_vif*arvif,drivers/net/wireless/ath/ath10k/wow.c +2
-0for (i =0 ; i < wowlan->n_patterns; i++) {u8 bitmask[WOW_MAX_PATTERN_SIZE ] = {}; +u8 ath_pattern[WOW_MAX_PATTERN_SIZE ] = {}; +u8 ath_bitmask[WOW_MAX_PATTERN_SIZE ] = {};So now we've got 3 * 148 = 444 bytes on the stack just for this? Seems like it's getting a little large for kernel code, but maybe not too bad.
I guess we can go with this until somebody runs into a real problem...Otherwise, seems to work for me:
Tested-by Brian Norris <[email protected]>Reviewed-by Brian Norris <[email protected]>Quoted 7 lines
drivers/net/wireless/ath/ath10k/wow.c +4
-1+struct cfg80211_pkt_pattern new_pattern = {}; +struct cfg80211_pkt_pattern old_pattern = patterns[i];int j; - + new_pattern.pattern = ath_pattern; + new_pattern.mask = ath_bitmask;if (patterns[i].pattern_len >WOW_MAX_PATTERN_SIZE )drivers/net/wireless/ath/ath10k/wow.c static int ath10k_vif_wow_set_wakeups(struct ath10k_vif *arvif,
Quoted 10 lines
drivers/net/wireless/ath/ath10k/wow.c +4
-1continue ; -/* convert bytemask to bitmask */ for (j =0 ; j < patterns[i].pattern_len; j++)if (patterns[i].mask[j /8 ] &BIT (j %8 )) bitmask[j] =0xff ; + old_pattern.mask = bitmask; + new_pattern = old_pattern; + + if (ar->wmi.rx_decap_mode ==
ATH10K_HW_TXRX_NATIVE_WIFI) {drivers/net/wireless/ath/ath10k/wow.c static int ath10k_vif_wow_set_wakeups(struct ath10k_vif *arvif, · line 235
Quoted 2 lines
drivers/net/wireless/ath/ath10k/wow.c +2
-0+if (patterns[i].pkt_offset <ETH_HLEN ) +ath10k_wow_convert_8023_to_80211(&new_pattern,Quoted 1 line
+
&old_pattern);drivers/net/wireless/ath/ath10k/wow.c
Quoted 2 lines
drivers/net/wireless/ath/ath10k/wow.c +2
-0+else + new_pattern.pkt_offset += WOW_HDR_LEN -
ETH_HLEN;drivers/net/wireless/ath/ath10k/wow.c static int ath10k_wow_cleanup(struct ath10k *ar)
Quoted 3 lines
drivers/net/wireless/ath/ath10k/wow.c +3
-0+ } + + if (WARN_ON(new_pattern.pattern_len >
WOW_MAX_PATTERN_SIZE))Quoted 4 lines
drivers/net/wireless/ath/ath10k/wow.c +1
-0+return -EINVAL ; ret = ath10k_wmi_wow_add_pattern(ar, arvif->vdev_id, pattern_id,drivers/net/wireless/ath/ath10k/wow.c static int ath10k_vif_wow_set_wakeups(struct ath10k_vif *arvif,
Quoted 10 lines
drivers/net/wireless/ath/ath10k/wow.c +4
-4- patterns[i].pattern, - bitmask, - patterns[i].pattern_len, - patterns[i].pkt_offset); + new_pattern.pattern, + new_pattern.mask, + new_pattern.pattern_len, + new_pattern.pkt_offset);if (ret) { ath10k_warn(ar, "failed to add pattern %i tovdev %i: %d\n",
drivers/net/wireless/ath/ath10k/wow.c int ath10k_wow_init(struct ath10k *ar) · line 460
Quoted 8 lines
drivers/net/wireless/ath/ath10k/wow.c +3
-0pattern_id,@@ -345,6 +455,12 @@ int ath10k_wow_init(struct ath10k *ar)return -EINVAL ; ar->wow.wowlan_support = ath10k_wowlan_support; + +if (ar->wmi.rx_decap_mode ==ATH10K_HW_TXRX_NATIVE_WIFI ) { + ar->wow.wowlan_support.pattern_max_len -=
WOW_MAX_REDUCE;drivers/net/wireless/ath/ath10k/wow.c int ath10k_wow_init(struct ath10k *ar) · line 461
Quoted 1 line
drivers/net/wireless/ath/ath10k/wow.c +1
-0+ ar->wow.wowlan_support.max_pkt_offset -=
WOW_MAX_REDUCE;Quoted 6 lines
drivers/net/wireless/ath/ath10k/wow.c +2
-0+ } + ar->wow.wowlan_support.n_patterns = ar- wow.max_num_patterns; ar->hw->wiphy->wowlan = &ar->wow.wowlan_support;
Quoted 8 lines
Quoted 3 lines
--
2.7.4_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k
_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k
Hi,
I will move the convert graph from comments to code and send Patch V2. And new graph like this:
/**
+ * Convert a 802.3 format to a 802.11 format.
+ * +------------+-----------+--------+----------------+
+ * 802.3: |dest mac(6B)|src mac(6B)|type(2B)| body... |
+ * +------------+-----------+--------+----------------+
+ * |__ |_______ |____________ |________
+ * | | | |
+ * +--+------------+----+-----------+---------------+-----------+
+ * 802.11: |4B|dest mac(6B)| 6B |src mac(6B)| 8B |type(2B)| body... |
+ * +--+------------+----+-----------+---------------+-----------+
+ */
+static void ath10k_wow_convert_8023_to_80211
+ (struct cfg80211_pkt_pattern *new,
+ const struct cfg80211_pkt_pattern *old)
And the 444 bytes on stack will remain since the comments is: "we can go with this until somebody runs into a real problem"
Quoted 240 lines · Brian Norris
Hi,
Quoted 12 lines · Wen Gong
When trying to set wow wakeup patterns it fails with this command:
iw phyxx wowlan enable patterns offset xx+ IP address xx.xx.xx.xx
The reason is that the wow pattern from upper layer is in 802.3 format for this case, it need to convert it to 802.11 format. The input offset parameter is used for 802.3, but the actual offset firmware need depends on
rx_decap_mode, so that it needs to be recalculated. Pattern of 802.3 packet is not same with 802.11 packet. If therx_decap_modeisATH10K_HW_TXRX_NATIVE_WIFI, then firmware will receive data packet with 802.11 format from hardware.Quoted 7 lines
Convert graph:
-----------------------------------------------------------------------
802.3 |dest mac(6B)|src mac(6B)|type(2B)| body... ||__ |_______ |_____________ |___________ | | | | 802.11 |4B|dest mac(6B)| 6B |src mac(6B)| 8B |type(2B)| body... |-----------------------------------------------------------------------
It feels like this could go into the code comments? Or at least some short version of it. (But hey, text is cheap, and who doesn't love ASCII art?)
Quoted 141 lines
Tested with QCA6174 hw3.0 with firmware WLAN.RM.4.4.1-00099-QCARMSWPZ-1, but this will also affect QCA9377. This has always failed, so it's not a regression with new firmware releases.
Signed-off-by Wen Gong <[email protected]>--- drivers/net/wireless/ath/ath10k/wmi.h | 4 ++ drivers/net/wireless/ath/ath10k/wow.c | 128 ++++++++++++++++++++++++++++++++-- 2 files changed, 126 insertions(+), 6 deletions(-)drivers/net/wireless/ath/ath10k/wmi.h +4
-0@@ -6724,6 +6724,10 @@ struct wmi_wow_ev_arg {#define WOW_MIN_PATTERN_SIZE 1#define WOW_MAX_PATTERN_SIZE 148#define WOW_MAX_PKT_OFFSET 128 +#define WOW_HDR_LEN (sizeof(struct ieee80211_hdr_3addr) + \ + sizeof(struct rfc1042_hdr)) +#define WOW_MAX_REDUCE (WOW_HDR_LEN - sizeof(struct ethhdr) - \ + offsetof(struct ieee80211_hdr_3addr, addr1))enum wmi_tdls_state {WMI_TDLS_DISABLE ,drivers/net/wireless/ath/ath10k/wow.c +1
-0@@ -1,5 +1,6 @@/* * Copyright (c) 2015-2017 Qualcomm Atheros, Inc. +* Copyright (c) 2018, The Linux Foundation. All rights reserved. * * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the
abovedrivers/net/wireless/ath/ath10k/wow.c +92
-0@@ -76,6 +77,98 @@ static int ath10k_wow_cleanup(struct ath10k *ar)return 0 ; } +static void ath10k_wow_convert_8023_to_80211 + (struct cfg80211_pkt_pattern *new, +const struct cfg80211_pkt_pattern *old) +{ +u8 hdr_8023_pattern[ETH_HLEN ] = {}; +u8 hdr_8023_bit_mask[ETH_HLEN ] = {}; +u8 hdr_80211_pattern[WOW_HDR_LEN ] = {}; +u8 hdr_80211_bit_mask[WOW_HDR_LEN ] = {}; + +int total_len = old->pkt_offset + old->pattern_len; +int hdr_80211_end_offset; + +struct ieee80211_hdr_3addr *new_hdr_pattern = + (struct ieee80211_hdr_3addr *)hdr_80211_pattern; +struct ieee80211_hdr_3addr *new_hdr_mask = + (struct ieee80211_hdr_3addr *)hdr_80211_bit_mask; +struct ethhdr *old_hdr_pattern = (struct ethhdr *)hdr_8023_pattern; +struct ethhdr *old_hdr_mask = (struct ethhdr *)hdr_8023_bit_mask; +int hdr_len =sizeof (*new_hdr_pattern); + +struct rfc1042_hdr *new_rfc_pattern = + (struct rfc1042_hdr *)(hdr_80211_pattern + hdr_len); +struct rfc1042_hdr *new_rfc_mask = + (struct rfc1042_hdr *)(hdr_80211_bit_mask + hdr_len); +int rfc_len =sizeof (*new_rfc_pattern); + +memcpy (hdr_8023_pattern + old->pkt_offset, + old->pattern,ETH_HLEN - old->pkt_offset); +memcpy (hdr_8023_bit_mask + old->pkt_offset, + old->mask,ETH_HLEN - old->pkt_offset); + +/* Copy destination address */ +memcpy (new_hdr_pattern->addr1, old_hdr_pattern->h_dest,ETH_ALEN ); +memcpy (new_hdr_mask->addr1, old_hdr_mask->h_dest,ETH_ALEN ); + +/* Copy source address */ +memcpy (new_hdr_pattern->addr3, old_hdr_pattern->h_source,ETH_ALEN ); +memcpy (new_hdr_mask->addr3, old_hdr_mask->h_source,ETH_ALEN ); + +/* Copy logic link type */ +memcpy (&new_rfc_pattern->snap_type, + &old_hdr_pattern->h_proto, +sizeof (old_hdr_pattern->h_proto)); +memcpy (&new_rfc_mask->snap_type, + &old_hdr_mask->h_proto, +sizeof (old_hdr_mask->h_proto)); + +/* Caculate new pkt_offset */ +if (old->pkt_offset <ETH_ALEN ) + new->pkt_offset = old->pkt_offset + + offsetof(struct ieee80211_hdr_3addr , addr1); +else if (old->pkt_offset < offsetof(struct ethhdr , h_proto)) + new->pkt_offset = old->pkt_offset + + offsetof(struct ieee80211_hdr_3addr , addr3) - + offsetof(struct ethhdr , h_source); +else + new->pkt_offset = old->pkt_offset + hdr_len + rfc_len -ETH_HLEN ; + +/* Caculate new hdr end offset */ +if (total_len >ETH_HLEN ) + hdr_80211_end_offset = hdr_len + rfc_len; +else if (total_len > offsetof(struct ethhdr , h_proto)) + hdr_80211_end_offset = hdr_len + rfc_len + total_len -ETH_HLEN ; +else if (total_len >ETH_ALEN ) + hdr_80211_end_offset = total_len -ETH_ALEN + + offsetof(struct ieee80211_hdr_3addr , addr3); +else + hdr_80211_end_offset = total_len + + offsetof(struct ieee80211_hdr_3addr , addr1); + + new->pattern_len = hdr_80211_end_offset - new->pkt_offset; + +memcpy ((u8 *)new->pattern, + hdr_80211_pattern + new->pkt_offset, + new->pattern_len); +memcpy ((u8 *)new->mask, + hdr_80211_bit_mask + new->pkt_offset, + new->pattern_len); + +if (total_len >ETH_HLEN ) { +/* Copy frame body */ +memcpy ((u8 *)new->pattern + new->pattern_len, + (void *)old->pattern +ETH_HLEN - old->pkt_offset, + total_len -ETH_HLEN ); +memcpy ((u8 *)new->mask + new->pattern_len, + (void *)old->mask +ETH_HLEN - old->pkt_offset, + total_len -ETH_HLEN ); + + new->pattern_len += total_len -ETH_HLEN ; + } +} +static int ath10k_vif_wow_set_wakeups (struct ath10k_vif *arvif,struct cfg80211_wowlan *wowlan) {drivers/net/wireless/ath/ath10k/wow.c static int ath10k_vif_wow_set_wakeups(struct · line 214
Quoted 6 lines
drivers/net/wireless/ath/ath10k/wow.c +2
-0@@ -116,22 +209,39 @@ static int ath10k_vif_wow_set_wakeups(struct ath10k_vif *arvif, for (i = 0; i < wowlan->n_patterns; i++) {u8 bitmask[WOW_MAX_PATTERN_SIZE ] = {}; +u8 ath_pattern[WOW_MAX_PATTERN_SIZE ] = {}; +u8 ath_bitmask[WOW_MAX_PATTERN_SIZE ] = {};So now we've got 3 * 148 = 444 bytes on the stack just for this? Seems like it's getting a little large for kernel code, but maybe not too bad. I guess we can go with this until somebody runs into a real problem...
Otherwise, seems to work for me:
Tested-by Brian Norris <[email protected]>Reviewed-by Brian Norris <[email protected]>Quoted 56 lines
drivers/net/wireless/ath/ath10k/wow.c +21
-6+struct cfg80211_pkt_pattern new_pattern = {}; +struct cfg80211_pkt_pattern old_pattern = patterns[i];int j; - + new_pattern.pattern = ath_pattern; + new_pattern.mask = ath_bitmask;if (patterns[i].pattern_len >WOW_MAX_PATTERN_SIZE )continue ; -/* convert bytemask to bitmask */ for (j =0 ; j < patterns[i].pattern_len; j++)if (patterns[i].mask[j /8 ] &BIT (j %8 )) bitmask[j] =0xff ; + old_pattern.mask = bitmask; + new_pattern = old_pattern; + +if (ar->wmi.rx_decap_mode ==ATH10K_HW_TXRX_NATIVE_WIFI ) { +if (patterns[i].pkt_offset <ETH_HLEN ) +ath10k_wow_convert_8023_to_80211 (&new_pattern, + &old_pattern); +else + new_pattern.pkt_offset +=WOW_HDR_LEN -ETH_HLEN ; + } + +if (WARN_ON (new_pattern.pattern_len >WOW_MAX_PATTERN_SIZE )) +return -EINVAL ; ret =ath10k_wmi_wow_add_pattern (ar, arvif->vdev_id, pattern_id, - patterns[i].pattern, - bitmask, - patterns[i].pattern_len, - patterns[i].pkt_offset); + new_pattern.pattern, + new_pattern.mask, + new_pattern.pattern_len, + new_pattern.pkt_offset);if (ret) { ath10k_warn(ar, "failed to add pattern %i to vdev %i: %d\n",drivers/net/wireless/ath/ath10k/wow.c +6
-1pattern_id,@@ -345,6 +455,12 @@ int ath10k_wow_init(struct ath10k *ar)return -EINVAL ; ar->wow.wowlan_support = ath10k_wowlan_support; + +if (ar->wmi.rx_decap_mode ==ATH10K_HW_TXRX_NATIVE_WIFI ) { + ar->wow.wowlan_support.pattern_max_len -=WOW_MAX_REDUCE ; + ar->wow.wowlan_support.max_pkt_offset -=WOW_MAX_REDUCE ; + } + ar->wow.wowlan_support.n_patterns = ar->wow.max_num_patterns; ar->hw->wiphy->wowlan = &ar->wow.wowlan_support; --2.7.4