ieee80211_calc_rx_airtime() and ieee80211_rate_expected_tx_airtime() multiply the duration of an AVG_PKT_SIZE frame, in 1/1024 us, by the frame length in a u32. The product is the airtime in us times 2^20, so it wraps once the airtime reaches 4096 us. At HT MCS0 a 4096 byte A-MPDU comes out as 945 us instead of 5041 us. mt76x0, mt76x2 and mt7603 compute RX airtime in software and pass the length of a whole A-MPDU to ieee80211_calc_rx_airtime(), so a station that sends at a low rate is charged a fraction of its airtime. Do the multiplication in 64 bits. Where it did not wrap, the result is the same. Found by the hosted Sashiko review of v1. Fixes: db3e1c40cf2f ("mac80211: Import airtime calculation code from mt76") Fixes: f01cfbaf9b29 ("mac80211: improve AQL aggregation estimation for low data rates") Signed-off-by: Julius Bairaktaris --- v3: - No change. v2: - New. The GSO estimate of v1 1/4 wrapped here. net/mac80211/airtime.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/net/mac80211/airtime.c b/net/mac80211/airtime.c index ee5dc524347ce..55bc451d4a9de 100644 --- a/net/mac80211/airtime.c +++ b/net/mac80211/airtime.c @@ -616,9 +616,7 @@ u32 ieee80211_calc_rx_airtime(struct ieee80211_hw *hw, if (!duration) return 0; - duration *= len; - duration /= AVG_PKT_SIZE; - duration /= 1024; + duration = div_u64(mul_u32_u32(duration, len), AVG_PKT_SIZE * 1024); return duration + overhead; } @@ -813,8 +811,7 @@ u32 ieee80211_rate_expected_tx_airtime(struct ieee80211_hw *hw, else agg_shift = 6; - duration *= len; - duration /= AVG_PKT_SIZE; + duration = div_u64(mul_u32_u32(duration, len), AVG_PKT_SIZE); duration += (overhead * 1024 >> agg_shift); return duration; -- 2.53.0 Since ieee80211_rate_expected_tx_airtime() was split out, ieee80211_calc_expected_tx_airtime() passes true to it and ignores its own ampdu argument. ieee80211_tx_dequeue() passes false for a frame on the VO queue, which AQL is then charged as part of an A-MPDU: its PHY overhead is divided by 2 to 64 instead of charged in full. Pass ampdu on. Found by an LLM review (Claude) of the airtime code. Fixes: 094dc1619cb0 ("wifi: mac80211: factor out part of ieee80211_calc_expected_tx_airtime") Signed-off-by: Julius Bairaktaris --- v3: - No change. v2: - New. net/mac80211/airtime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/mac80211/airtime.c b/net/mac80211/airtime.c index 55bc451d4a9de..d3b911fb711af 100644 --- a/net/mac80211/airtime.c +++ b/net/mac80211/airtime.c @@ -843,7 +843,7 @@ u32 ieee80211_calc_expected_tx_airtime(struct ieee80211_hw *hw, u32 duration; duration = ieee80211_rate_expected_tx_airtime(hw, tx_rate, ri, - band, true, len); + band, ampdu, len); duration /= 1024; return max_t(u32, duration, 4); -- 2.53.0 ieee80211_info_set_tx_time_est() takes the estimate as u16 and clamps it to 4095 us, but ieee80211_tx_dequeue() passes a u32. An estimate of 65536 us or more loses its upper bits before the clamp: 65540 us is charged as 4 us. Take the estimate as u32. Found by an LLM review (Claude) of the airtime code. Fixes: 7a89233ac504 ("mac80211: Use Airtime-based Queue Limits (AQL) on packet dequeue") Signed-off-by: Julius Bairaktaris --- v3: - No change. v2: - New. include/net/mac80211.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index f768ef9184eba..ba16096fea3a6 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -1425,12 +1425,12 @@ struct ieee80211_tx_info { }; static inline u16 -ieee80211_info_set_tx_time_est(struct ieee80211_tx_info *info, u16 tx_time_est) +ieee80211_info_set_tx_time_est(struct ieee80211_tx_info *info, u32 tx_time_est) { /* We only have 10 bits in tx_time_est, so store airtime * in increments of 4us and clamp the maximum to 2**12-1 */ - info->tx_time_est = min_t(u16, tx_time_est, 4095) >> 2; + info->tx_time_est = min_t(u32, tx_time_est, 4095) >> 2; return info->tx_time_est << 2; } -- 2.53.0 ieee80211_fill_rate_info() rejects every rate when the wiphy has no sband for the band it is given, although only a legacy rate is looked up in the bitrate table of the band. HT, VHT, HE and EHT durations come from the MCS tables alone. ieee80211_calc_expected_tx_airtime() takes the band from the channel context of vif->bss_conf, which an MLD vif does not have, and uses band 0 (2.4 GHz) then. On a wiphy without 2.4 GHz the last_rate_info of the station is rejected whatever its encoding, and AQL charges each frame 4 us unless last_rate holds a valid rate. On a wiphy with 2.4 GHz a legacy last_rate index is looked up in the 2.4 GHz table, where it names a different rate than in the 5 or 6 GHz table it came from. Check the band only for a legacy rate. Pass NUM_NL80211_BANDS when the vif has no channel context, and look a legacy bitrate up in each band then: its duration depends only on the bitrate and on whether it is CCK, and cfg80211 marks a bitrate as CCK in every band that has it. A legacy last_rate index cannot be resolved without its band, so that fallback gives no estimate then. Fixes: 8ed37e791960 ("mac80211: use rate provided via status->rate on ieee80211_tx_status_ext for AQL") Signed-off-by: Julius Bairaktaris --- v3: - New. Found by the hosted Sashiko review of v2, on v2 4/7: on an MLD vif ieee80211_8023_gso_fits() and the AQL charge used band 0. net/mac80211/airtime.c | 52 +++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/net/mac80211/airtime.c b/net/mac80211/airtime.c index d3b911fb711af..579e77f49e9d8 100644 --- a/net/mac80211/airtime.c +++ b/net/mac80211/airtime.c @@ -622,15 +622,34 @@ u32 ieee80211_calc_rx_airtime(struct ieee80211_hw *hw, } EXPORT_SYMBOL_GPL(ieee80211_calc_rx_airtime); -static bool ieee80211_fill_rate_info(struct ieee80211_hw *hw, - struct ieee80211_rx_status *stat, u8 band, - struct rate_info *ri) +static bool ieee80211_fill_legacy_rate(struct ieee80211_hw *hw, + struct ieee80211_rx_status *stat, + u8 band, u16 bitrate) { struct ieee80211_supported_band *sband = hw->wiphy->bands[band]; int i; - if (!ri || !sband) - return false; + if (!sband) + return false; + + for (i = 0; i < sband->n_bitrates; i++) { + if (bitrate != sband->bitrates[i].bitrate) + continue; + + stat->band = band; + stat->rate_idx = i; + return true; + } + + return false; +} + +static bool ieee80211_fill_rate_info(struct ieee80211_hw *hw, + struct ieee80211_rx_status *stat, u8 band, + struct rate_info *ri) +{ + if (!ri) + return false; /* * ieee80211_get_rate_duration() only handles these widths. Drivers @@ -678,13 +697,20 @@ static bool ieee80211_fill_rate_info(struct ieee80211_hw *hw, if (stat->encoding != RX_ENC_LEGACY) return true; - stat->rate_idx = 0; - for (i = 0; i < sband->n_bitrates; i++) { - if (ri->legacy != sband->bitrates[i].bitrate) + if (band < NUM_NL80211_BANDS) + return ieee80211_fill_legacy_rate(hw, stat, band, ri->legacy); + + /* + * The band is not known (an MLD vif). The duration of a legacy rate + * depends only on its bitrate and on whether it is CCK, and cfg80211 + * marks a bitrate as CCK (mandatory B) in every band that has it. + */ + for (band = 0; band < NUM_NL80211_BANDS; band++) { + if (band == NL80211_BAND_60GHZ || band == NL80211_BAND_S1GHZ) continue; - stat->rate_idx = i; - return true; + if (ieee80211_fill_legacy_rate(hw, stat, band, ri->legacy)) + return true; } return false; @@ -727,6 +753,9 @@ static int ieee80211_fill_rx_status(struct ieee80211_rx_status *stat, } else if (rate->flags & IEEE80211_TX_RC_MCS) { stat->encoding = RX_ENC_HT; } else { + /* a legacy rate index means nothing without its band */ + if (band >= NUM_NL80211_BANDS) + return -1; stat->encoding = RX_ENC_LEGACY; } @@ -827,11 +856,12 @@ u32 ieee80211_calc_expected_tx_airtime(struct ieee80211_hw *hw, int rateidx; bool cck, short_pream; u32 basic_rates; - u8 band = 0; + u8 band = NUM_NL80211_BANDS; u16 rate; len += 38; /* Ethernet header length */ + /* an MLD vif has no channel context here, the band is not known */ conf = rcu_dereference(vif->bss_conf.chanctx_conf); if (conf) band = conf->def.chan->band; -- 2.53.0 A driver whose hardware segments TCP frames and takes frames with fragments on its 802.3 encap path cannot say so. hw->netdev_features applies to every netdev of the hw, so a feature set there also reaches the frames that go out through the 802.11 path. Add hw->encap_netdev_features and hw->encap_gso_max_segs. When the hw supports encap offload, mac80211 sets the features on each netdev it creates, and ieee80211_8023_xmit() passes them to ieee80211_tx_skb_fixup(), so a GSO frame reaches the driver whole. ieee80211_tx_skb_fixup() segments a frame only when netif_needs_gso() says so, as validate_xmit_skb() does, instead of walking the GSO callbacks for every GSO frame. A frame the features accept went out whole before too, as skb_gso_segment() returned NULL for it; it now also goes through the linearize and checksum steps, as in the core. Whether a netdev sends with encap offload changes with its type, 4addr mode, fragmentation threshold and monitor interfaces, and mac80211 switches its netdev ops when it does. The ops of the 802.11 and monitor paths get an ndo_features_check that drops the encap features, so the stack segments, linearizes and resolves the checksum first. AQL charges a frame by tx_time_est, which ieee80211_info_set_tx_time_est() caps at 4095 us. A whole GSO frame to a slow station, or to one whose rate mac80211 does not know yet, would be charged less than its airtime. Segment such a frame in software instead; the segments keep scatter-gather. The check uses the rate of the station when the frame is queued. A GSO frame without a station, a group addressed one with IEEE80211_OFFLOAD_ENCAP_MCAST, is charged at the lowest basic rate and is always segmented. The tx statistics count a TCP GSO frame as gso_segs packets, with the headers of every segment in its length. Other segmentation offloads are rejected in encap_netdev_features, as the counters do not know them. Signed-off-by: Julius Bairaktaris --- v3: - Segment in ieee80211_tx_skb_fixup() only when netif_needs_gso() says so. Found by the hosted Sashiko review of v2. - Pass NUM_NL80211_BANDS to the AQL check when the vif has no channel context, as patch 4 makes the AQL charge do. - With AQL, segment a GSO frame that has no station (group addressed, IEEE80211_OFFLOAD_ENCAP_MCAST): AQL charges it once at the lowest basic rate, capped at 4092 us. Found by an LLM review (Claude). - Accept only TCP segmentation offload in encap_netdev_features; the tx counters know no other GSO type. Found by an LLM review (Claude). v2: - Take the encap features away per frame in ndo_features_check of the non-encap ops, instead of setting them by interface type when the netdev is created. v1 left them on a netdev changed to mesh point, whose fast path then warned in skb_checksum_help(), and never set them on P2P netdevs. Found by the hosted Sashiko review of v1. - The AQL fallback clears only the GSO bits and keeps SG. Found by the hosted Sashiko review of v1. - Segment a GSO frame for a station with no usable rate, which AQL charges as 4 us. Found by an LLM review (Claude). - Say in the kernel-doc that an encap_gso_max_segs of 0 keeps the default of the netdev. Found by an LLM review (Claude). include/net/mac80211.h | 17 ++++++++++ net/mac80211/iface.c | 28 ++++++++++++++++ net/mac80211/main.c | 8 ++++- net/mac80211/tx.c | 73 ++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 122 insertions(+), 4 deletions(-) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index ba16096fea3a6..32c1e68e33d7d 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -3271,6 +3271,21 @@ enum ieee80211_hw_flags { * @netdev_features: netdev features to be set in each netdev created * from this HW. Note that not all features are usable with mac80211, * other features will be rejected during HW registration. + * @encap_netdev_features: netdev features, in addition to @netdev_features, + * set in each netdev created from this HW when it supports 802.3 + * encapsulation offload, for the frames that are sent with it (see + * %IEEE80211_OFFLOAD_ENCAP_ENABLED). A driver sets scatter-gather and + * TCP segmentation offload (%NETIF_F_ALL_TSO) here when the hardware + * takes such frames whole; other segmentation offloads are rejected + * during HW registration. mac80211 hands a driver a frame with these + * features only with %IEEE80211_TX_CTL_HW_80211_ENCAP, and segments or + * linearizes it in software on every other path. With AQL it also + * segments a GSO frame that has no station, and one for a station when + * the airtime estimate of the whole frame is more than AQL can account + * to one frame. Such a frame starts with its 802.3 header. + * @encap_gso_max_segs: the most segments of a GSO frame the driver takes + * whole, when @encap_netdev_features has a segmentation offload; 0 + * keeps the default limit of the netdev. * * @uapsd_queues: This bitmap is included in (re)association frame to indicate * for each access category if it is uAPSD trigger-enabled and delivery- @@ -3330,6 +3345,8 @@ struct ieee80211_hw { s16 accuracy; } radiotap_timestamp; netdev_features_t netdev_features; + netdev_features_t encap_netdev_features; + u16 encap_gso_max_segs; u8 uapsd_queues; u8 uapsd_max_sp_len; u8 max_nan_de_entries; diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c index b6ed6541bc42a..85c96da3391c2 100644 --- a/net/mac80211/iface.c +++ b/net/mac80211/iface.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -960,11 +961,28 @@ static int ieee80211_netdev_setup_tc(struct net_device *dev, return drv_net_setup_tc(local, sdata, dev, type, type_data); } +/* For the netdev ops that send without the 802.3 encap offload: the frame + * is built into an 802.11 frame here, which cannot take what only the encap + * offload path takes, so the stack segments or linearizes it first. + */ +static netdev_features_t +ieee80211_netdev_features_check(struct sk_buff *skb, struct net_device *dev, + netdev_features_t features) +{ + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); + struct ieee80211_hw *hw = &sdata->local->hw; + + features &= ~(hw->encap_netdev_features & ~hw->netdev_features); + + return vlan_features_check(skb, features); +} + static const struct net_device_ops ieee80211_dataif_ops = { .ndo_open = ieee80211_open, .ndo_stop = ieee80211_stop, .ndo_uninit = ieee80211_uninit, .ndo_start_xmit = ieee80211_subif_start_xmit, + .ndo_features_check = ieee80211_netdev_features_check, .ndo_set_rx_mode = ieee80211_set_multicast_list, .ndo_set_mac_address = ieee80211_change_mac, .ndo_setup_tc = ieee80211_netdev_setup_tc, @@ -1003,6 +1021,7 @@ static const struct net_device_ops ieee80211_monitorif_ops = { .ndo_stop = ieee80211_stop, .ndo_uninit = ieee80211_uninit, .ndo_start_xmit = ieee80211_monitor_start_xmit, + .ndo_features_check = ieee80211_netdev_features_check, .ndo_set_rx_mode = ieee80211_set_multicast_list, .ndo_set_mac_address = ieee80211_change_mac, .ndo_select_queue = ieee80211_monitor_select_queue, @@ -2407,6 +2426,15 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name, sdata->u.mgd.use_4addr = params->use_4addr; ndev->features |= local->hw.netdev_features; + /* ieee80211_netdev_features_check() takes the encap features + * away from every frame sent without the encap offload + */ + if (ieee80211_hw_check(&local->hw, SUPPORTS_TX_ENCAP_OFFLOAD)) { + ndev->features |= local->hw.encap_netdev_features; + if (local->hw.encap_gso_max_segs) + netif_set_tso_max_segs(ndev, + local->hw.encap_gso_max_segs); + } ndev->priv_flags |= IFF_LIVE_ADDR_CHANGE; ndev->hw_features |= ndev->features & MAC80211_SUPPORTED_FEATURES_TX; diff --git a/net/mac80211/main.c b/net/mac80211/main.c index e03c2dbf4fb84..054ceb00b3e37 100644 --- a/net/mac80211/main.c +++ b/net/mac80211/main.c @@ -1243,7 +1243,13 @@ int ieee80211_register_hw(struct ieee80211_hw *hw) } /* Only HW csum features are currently compatible with mac80211 */ - if (WARN_ON(hw->netdev_features & ~MAC80211_SUPPORTED_FEATURES)) + if (WARN_ON((hw->netdev_features | hw->encap_netdev_features) & + ~MAC80211_SUPPORTED_FEATURES)) + return -EINVAL; + + /* the tx counters of the encap path know TCP segmentation only */ + if (WARN_ON(hw->encap_netdev_features & NETIF_F_GSO_MASK & + ~NETIF_F_ALL_TSO)) return -EINVAL; if (hw->max_report_rates == 0) diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index cb9ecac25a9cf..af15cb49e679d 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -3767,7 +3768,7 @@ ieee80211_sdata_netdev_features(struct ieee80211_sub_if_data *sdata) static struct sk_buff * ieee80211_tx_skb_fixup(struct sk_buff *skb, netdev_features_t features) { - if (skb_is_gso(skb)) { + if (netif_needs_gso(skb, features)) { struct sk_buff *segs; segs = skb_gso_segment(skb, features); @@ -4797,6 +4798,53 @@ static bool ieee80211_tx_8023(struct ieee80211_sub_if_data *sdata, return ret; } +/* A frame's airtime estimate has 10 bits, in units of 4 us. A GSO frame whose + * estimate would not fit, or that has no estimate because the rate of the + * station is not known, is charged less than it takes, so it is segmented in + * software instead. + */ +#define IEEE80211_TX_GSO_AIRTIME_MAX 4092 + +static bool ieee80211_8023_gso_fits(struct ieee80211_sub_if_data *sdata, + struct sta_info *sta, struct sk_buff *skb, + u16 queue) +{ + struct ieee80211_local *local = sdata->local; + struct ieee80211_chanctx_conf *conf; + u32 airtime; + u8 band = NUM_NL80211_BANDS; + + if (!wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL)) + return true; + + /* a frame without a station (group addressed, with + * IEEE80211_OFFLOAD_ENCAP_MCAST) is charged at the lowest basic rate; + * segment it, so that AQL charges each segment + */ + if (!sta) + return false; + + /* AQL charges the vif of the AP, as ieee80211_tx_dequeue() does */ + if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) + sdata = container_of(sdata->bss, struct ieee80211_sub_if_data, + u.ap); + + /* the estimate of ieee80211_calc_expected_tx_airtime(), which charges + * 4 us when it has no rate to estimate with + */ + conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf); + if (conf) + band = conf->def.chan->band; + + airtime = ieee80211_rate_expected_tx_airtime(&local->hw, + &sta->deflink.tx_stats.last_rate, + &sta->deflink.tx_stats.last_rate_info, + band, queue != IEEE80211_AC_VO, + skb->len + 38); + + return airtime && airtime / 1024 <= IEEE80211_TX_GSO_AIRTIME_MAX; +} + static void ieee80211_8023_xmit(struct ieee80211_sub_if_data *sdata, struct net_device *dev, struct sta_info *sta, struct ieee80211_key *key, struct sk_buff *skb) @@ -4807,6 +4855,7 @@ static void ieee80211_8023_xmit(struct ieee80211_sub_if_data *sdata, struct tid_ampdu_tx *tid_tx = NULL; struct sk_buff *seg, *next; unsigned int skbs = 0, len = 0; + netdev_features_t features; u16 queue; u8 tid; @@ -4835,7 +4884,12 @@ static void ieee80211_8023_xmit(struct ieee80211_sub_if_data *sdata, tid_tx->last_tx = jiffies; } - skb = ieee80211_tx_skb_fixup(skb, ieee80211_sdata_netdev_features(sdata)); + features = ieee80211_sdata_netdev_features(sdata) | + local->hw.encap_netdev_features; + if (skb_is_gso(skb) && !ieee80211_8023_gso_fits(sdata, sta, skb, queue)) + features &= ~NETIF_F_GSO_MASK; + + skb = ieee80211_tx_skb_fixup(skb, features); if (!skb) return; @@ -4865,8 +4919,21 @@ static void ieee80211_8023_xmit(struct ieee80211_sub_if_data *sdata, info->control.hw_key = &key->conf; skb_list_walk_safe(skb, seg, next) { - skbs++; + unsigned int segs = 1; + len += seg->len; + /* a GSO frame is one frame of the queues and of the airtime + * estimate, and as many packets of the counters as it has + * segments + */ + if (skb_is_gso(seg) && + (skb_shinfo(seg)->gso_type & + (SKB_GSO_TCPV4 | SKB_GSO_TCPV6))) { + segs = max_t(unsigned int, skb_shinfo(seg)->gso_segs, 1); + len += (segs - 1) * (skb_transport_offset(seg) + + tcp_hdrlen(seg)); + } + skbs += segs; if (seg != skb) memcpy(IEEE80211_SKB_CB(seg), info, sizeof(*info)); } -- 2.53.0 __ieee80211_rx_handle_8023() clears struct ieee80211_rx_data and never sets seqno_idx, so ieee80211_rx_8023() counts every frame received with RX_FLAG_8023 in rx_stats.msdu[0], whatever its TID. The native path takes the TID from the QoS header, which an 802.3 frame no longer has. Add a tid field to struct ieee80211_rx_status for the driver to fill, and use it as seqno_idx on the 802.3 path. A driver that does not set it leaves it 0, which counts the frame on TID 0 as before. Fixes: 80a915ec4427 ("mac80211: add rx decapsulation offload support") Signed-off-by: Julius Bairaktaris --- v3: - No change. v2: - No change. include/net/mac80211.h | 4 ++++ net/mac80211/rx.c | 3 +++ 2 files changed, 7 insertions(+) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index 32c1e68e33d7d..969d96d0bbef9 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -1770,6 +1770,9 @@ enum mac80211_rx_encoding { * @ampdu_reference: A-MPDU reference number, must be a different value for * each A-MPDU but the same for each subframe within one A-MPDU * @zero_length_psdu_type: radiotap type of the 0-length PSDU + * @tid: the TID of a frame received in 802.3 format (%RX_FLAG_8023), or + * %IEEE80211_NUM_TIDS if it has none; counts the frame in the per-TID + * statistics of its station. Not read for other frames. * @link_id: id of the link used to receive the packet. Set and used by * mac80211 internally, it uses @freq set by the driver to identify the * correct link per vif. Set to %IEEE80211_LINK_UNSPECIFIED for non-MLD @@ -1813,6 +1816,7 @@ struct ieee80211_rx_status { u8 chains; s8 chain_signal[IEEE80211_MAX_CHAINS]; u8 zero_length_psdu_type; + u8 tid; u8 link_id:4; }; diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c index a2356cd176914..9fabc9b5a9769 100644 --- a/net/mac80211/rx.c +++ b/net/mac80211/rx.c @@ -5303,6 +5303,7 @@ static void __ieee80211_rx_handle_8023(struct ieee80211_hw *hw, struct sk_buff *skb, struct list_head *list) { + struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); struct ieee80211_local *local = hw_to_local(hw); struct ieee80211_fast_rx *fast_rx; struct ieee80211_rx_data rx; @@ -5313,6 +5314,8 @@ static void __ieee80211_rx_handle_8023(struct ieee80211_hw *hw, rx.skb = skb; rx.local = local; rx.list = list; + /* the MSDU count of the station is kept per TID */ + rx.seqno_idx = min_t(u8, status->tid, IEEE80211_NUM_TIDS); I802_DEBUG_INC(local->dot11ReceivedFragmentCount); -- 2.53.0 ath11k_dp_rx_deliver_msdu() delivers frames with Ethernet decap as RX_FLAG_8023, and mac80211 counted all of them on TID 0. Pass the TID the driver keeps in rxcb->tid. Copying the rx status into skb->cb overwrites rxcb, so read it before that. On the REO path rxcb->tid is the REO queue number, which is HAL_DESC_REO_NON_QOS_TID for a frame without QoS control. The null queue descriptor path takes it from the 4-bit TID field of MPDU_START; set HAL_DESC_REO_NON_QOS_TID there as well when the MPDU has no QoS control, so mac80211 counts such a frame as non-QoS on both paths. Signed-off-by: Julius Bairaktaris --- v3: - No change. v2: - Read rxcb->tid before *rx_status = *status overwrites it. Found by the hosted Sashiko review of v1. - Report a frame without QoS control on the null queue descriptor path as HAL_DESC_REO_NON_QOS_TID. Found by an LLM review (Claude). drivers/net/wireless/ath/ath11k/dp_rx.c | 14 +++++++++++++- drivers/net/wireless/ath/ath11k/hw.c | 25 +++++++++++++++++++++++++ drivers/net/wireless/ath/ath11k/hw.h | 1 + 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath11k/dp_rx.c b/drivers/net/wireless/ath/ath11k/dp_rx.c index 6d95f7b343a55..6d09b4c10b6d0 100644 --- a/drivers/net/wireless/ath/ath11k/dp_rx.c +++ b/drivers/net/wireless/ath/ath11k/dp_rx.c @@ -70,6 +70,12 @@ static inline bool ath11k_dp_rx_h_mpdu_start_fc_valid(struct ath11k_base *ab, return ab->hw_params.hw_ops->rx_desc_get_mpdu_fc_valid(desc); } +static inline bool ath11k_dp_rx_h_mpdu_start_qos_ctrl_valid(struct ath11k_base *ab, + struct hal_rx_desc *desc) +{ + return ab->hw_params.hw_ops->rx_desc_get_mpdu_qos_ctrl_valid(desc); +} + static inline bool ath11k_dp_rx_h_mpdu_start_more_frags(struct ath11k_base *ab, struct sk_buff *skb) { @@ -2446,6 +2452,7 @@ static void ath11k_dp_rx_deliver_msdu(struct ath11k *ar, struct napi_struct *nap u8 decap = DP_RX_DECAP_TYPE_RAW; bool is_mcbc = rxcb->is_mcbc; bool is_eapol = rxcb->is_eapol; + u8 tid = rxcb->tid; if (status->encoding == RX_ENC_HE && !(status->flag & RX_FLAG_RADIOTAP_HE) && @@ -2493,6 +2500,7 @@ static void ath11k_dp_rx_deliver_msdu(struct ath11k *ar, struct napi_struct *nap rx_status = IEEE80211_SKB_RXCB(msdu); *rx_status = *status; + rx_status->tid = min_t(u8, tid, IEEE80211_NUM_TIDS); /* TODO: trace rx packet */ @@ -4001,7 +4009,11 @@ static int ath11k_dp_rx_h_null_q_desc(struct ath11k *ar, struct sk_buff *msdu, ath11k_dp_rx_h_mpdu(ar, msdu, desc, status); - rxcb->tid = ath11k_dp_rx_h_mpdu_start_tid(ar->ab, desc); + /* the REO queue number, as on the REO path */ + if (ath11k_dp_rx_h_mpdu_start_qos_ctrl_valid(ar->ab, desc)) + rxcb->tid = ath11k_dp_rx_h_mpdu_start_tid(ar->ab, desc); + else + rxcb->tid = HAL_DESC_REO_NON_QOS_TID; /* Please note that caller will having the access to msdu and completing * rx with mac80211. Need not worry about cleaning up amsdu_list. diff --git a/drivers/net/wireless/ath/ath11k/hw.c b/drivers/net/wireless/ath/ath11k/hw.c index 93f9a03c48dc0..20d0cd9687bc4 100644 --- a/drivers/net/wireless/ath/ath11k/hw.c +++ b/drivers/net/wireless/ath/ath11k/hw.c @@ -296,6 +296,12 @@ static bool ath11k_hw_ipq8074_rx_desc_get_mpdu_fc_valid(struct hal_rx_desc *desc __le32_to_cpu(desc->u.ipq8074.mpdu_start.info1)); } +static bool ath11k_hw_ipq8074_rx_desc_get_mpdu_qos_ctrl_valid(struct hal_rx_desc *desc) +{ + return !!FIELD_GET(RX_MPDU_START_INFO1_MPDU_QOS_CTRL_VALID, + __le32_to_cpu(desc->u.ipq8074.mpdu_start.info1)); +} + static u16 ath11k_hw_ipq8074_rx_desc_get_mpdu_start_seq_no(struct hal_rx_desc *desc) { return FIELD_GET(RX_MPDU_START_INFO1_MPDU_SEQ_NUM, @@ -473,6 +479,12 @@ static bool ath11k_hw_qcn9074_rx_desc_get_mpdu_fc_valid(struct hal_rx_desc *desc __le32_to_cpu(desc->u.qcn9074.mpdu_start.info11)); } +static bool ath11k_hw_qcn9074_rx_desc_get_mpdu_qos_ctrl_valid(struct hal_rx_desc *desc) +{ + return !!FIELD_GET(RX_MPDU_START_INFO11_MPDU_QOS_CTRL_VALID, + __le32_to_cpu(desc->u.qcn9074.mpdu_start.info11)); +} + static u16 ath11k_hw_qcn9074_rx_desc_get_mpdu_start_seq_no(struct hal_rx_desc *desc) { return FIELD_GET(RX_MPDU_START_INFO11_MPDU_SEQ_NUM, @@ -644,6 +656,12 @@ static bool ath11k_hw_wcn6855_rx_desc_get_mpdu_fc_valid(struct hal_rx_desc *desc __le32_to_cpu(desc->u.wcn6855.mpdu_start.info1)); } +static bool ath11k_hw_wcn6855_rx_desc_get_mpdu_qos_ctrl_valid(struct hal_rx_desc *desc) +{ + return !!FIELD_GET(RX_MPDU_START_INFO1_MPDU_QOS_CTRL_VALID, + __le32_to_cpu(desc->u.wcn6855.mpdu_start.info1)); +} + static u16 ath11k_hw_wcn6855_rx_desc_get_mpdu_start_seq_no(struct hal_rx_desc *desc) { return FIELD_GET(RX_MPDU_START_INFO1_MPDU_SEQ_NUM, @@ -917,6 +935,7 @@ const struct ath11k_hw_ops ipq8074_ops = { .rx_desc_get_ldpc_support = ath11k_hw_ipq8074_rx_desc_get_ldpc_support, .rx_desc_get_mpdu_seq_ctl_vld = ath11k_hw_ipq8074_rx_desc_get_mpdu_seq_ctl_vld, .rx_desc_get_mpdu_fc_valid = ath11k_hw_ipq8074_rx_desc_get_mpdu_fc_valid, + .rx_desc_get_mpdu_qos_ctrl_valid = ath11k_hw_ipq8074_rx_desc_get_mpdu_qos_ctrl_valid, .rx_desc_get_mpdu_start_seq_no = ath11k_hw_ipq8074_rx_desc_get_mpdu_start_seq_no, .rx_desc_get_msdu_len = ath11k_hw_ipq8074_rx_desc_get_msdu_len, .rx_desc_get_msdu_sgi = ath11k_hw_ipq8074_rx_desc_get_msdu_sgi, @@ -957,6 +976,7 @@ const struct ath11k_hw_ops ipq6018_ops = { .rx_desc_get_ldpc_support = ath11k_hw_ipq8074_rx_desc_get_ldpc_support, .rx_desc_get_mpdu_seq_ctl_vld = ath11k_hw_ipq8074_rx_desc_get_mpdu_seq_ctl_vld, .rx_desc_get_mpdu_fc_valid = ath11k_hw_ipq8074_rx_desc_get_mpdu_fc_valid, + .rx_desc_get_mpdu_qos_ctrl_valid = ath11k_hw_ipq8074_rx_desc_get_mpdu_qos_ctrl_valid, .rx_desc_get_mpdu_start_seq_no = ath11k_hw_ipq8074_rx_desc_get_mpdu_start_seq_no, .rx_desc_get_msdu_len = ath11k_hw_ipq8074_rx_desc_get_msdu_len, .rx_desc_get_msdu_sgi = ath11k_hw_ipq8074_rx_desc_get_msdu_sgi, @@ -997,6 +1017,7 @@ const struct ath11k_hw_ops qca6390_ops = { .rx_desc_get_ldpc_support = ath11k_hw_ipq8074_rx_desc_get_ldpc_support, .rx_desc_get_mpdu_seq_ctl_vld = ath11k_hw_ipq8074_rx_desc_get_mpdu_seq_ctl_vld, .rx_desc_get_mpdu_fc_valid = ath11k_hw_ipq8074_rx_desc_get_mpdu_fc_valid, + .rx_desc_get_mpdu_qos_ctrl_valid = ath11k_hw_ipq8074_rx_desc_get_mpdu_qos_ctrl_valid, .rx_desc_get_mpdu_start_seq_no = ath11k_hw_ipq8074_rx_desc_get_mpdu_start_seq_no, .rx_desc_get_msdu_len = ath11k_hw_ipq8074_rx_desc_get_msdu_len, .rx_desc_get_msdu_sgi = ath11k_hw_ipq8074_rx_desc_get_msdu_sgi, @@ -1037,6 +1058,7 @@ const struct ath11k_hw_ops qcn9074_ops = { .rx_desc_get_ldpc_support = ath11k_hw_qcn9074_rx_desc_get_ldpc_support, .rx_desc_get_mpdu_seq_ctl_vld = ath11k_hw_qcn9074_rx_desc_get_mpdu_seq_ctl_vld, .rx_desc_get_mpdu_fc_valid = ath11k_hw_qcn9074_rx_desc_get_mpdu_fc_valid, + .rx_desc_get_mpdu_qos_ctrl_valid = ath11k_hw_qcn9074_rx_desc_get_mpdu_qos_ctrl_valid, .rx_desc_get_mpdu_start_seq_no = ath11k_hw_qcn9074_rx_desc_get_mpdu_start_seq_no, .rx_desc_get_msdu_len = ath11k_hw_qcn9074_rx_desc_get_msdu_len, .rx_desc_get_msdu_sgi = ath11k_hw_qcn9074_rx_desc_get_msdu_sgi, @@ -1077,6 +1099,7 @@ const struct ath11k_hw_ops wcn6855_ops = { .rx_desc_get_ldpc_support = ath11k_hw_wcn6855_rx_desc_get_ldpc_support, .rx_desc_get_mpdu_seq_ctl_vld = ath11k_hw_wcn6855_rx_desc_get_mpdu_seq_ctl_vld, .rx_desc_get_mpdu_fc_valid = ath11k_hw_wcn6855_rx_desc_get_mpdu_fc_valid, + .rx_desc_get_mpdu_qos_ctrl_valid = ath11k_hw_wcn6855_rx_desc_get_mpdu_qos_ctrl_valid, .rx_desc_get_mpdu_start_seq_no = ath11k_hw_wcn6855_rx_desc_get_mpdu_start_seq_no, .rx_desc_get_msdu_len = ath11k_hw_wcn6855_rx_desc_get_msdu_len, .rx_desc_get_msdu_sgi = ath11k_hw_wcn6855_rx_desc_get_msdu_sgi, @@ -1117,6 +1140,7 @@ const struct ath11k_hw_ops wcn6750_ops = { .rx_desc_get_ldpc_support = ath11k_hw_qcn9074_rx_desc_get_ldpc_support, .rx_desc_get_mpdu_seq_ctl_vld = ath11k_hw_qcn9074_rx_desc_get_mpdu_seq_ctl_vld, .rx_desc_get_mpdu_fc_valid = ath11k_hw_qcn9074_rx_desc_get_mpdu_fc_valid, + .rx_desc_get_mpdu_qos_ctrl_valid = ath11k_hw_qcn9074_rx_desc_get_mpdu_qos_ctrl_valid, .rx_desc_get_mpdu_start_seq_no = ath11k_hw_qcn9074_rx_desc_get_mpdu_start_seq_no, .rx_desc_get_msdu_len = ath11k_hw_qcn9074_rx_desc_get_msdu_len, .rx_desc_get_msdu_sgi = ath11k_hw_qcn9074_rx_desc_get_msdu_sgi, @@ -1158,6 +1182,7 @@ const struct ath11k_hw_ops ipq5018_ops = { .rx_desc_get_ldpc_support = ath11k_hw_qcn9074_rx_desc_get_ldpc_support, .rx_desc_get_mpdu_seq_ctl_vld = ath11k_hw_qcn9074_rx_desc_get_mpdu_seq_ctl_vld, .rx_desc_get_mpdu_fc_valid = ath11k_hw_qcn9074_rx_desc_get_mpdu_fc_valid, + .rx_desc_get_mpdu_qos_ctrl_valid = ath11k_hw_qcn9074_rx_desc_get_mpdu_qos_ctrl_valid, .rx_desc_get_mpdu_start_seq_no = ath11k_hw_qcn9074_rx_desc_get_mpdu_start_seq_no, .rx_desc_get_msdu_len = ath11k_hw_qcn9074_rx_desc_get_msdu_len, .rx_desc_get_msdu_sgi = ath11k_hw_qcn9074_rx_desc_get_msdu_sgi, diff --git a/drivers/net/wireless/ath/ath11k/hw.h b/drivers/net/wireless/ath/ath11k/hw.h index 4996536fbd14f..3bd99d347fba5 100644 --- a/drivers/net/wireless/ath/ath11k/hw.h +++ b/drivers/net/wireless/ath/ath11k/hw.h @@ -252,6 +252,7 @@ struct ath11k_hw_ops { bool (*rx_desc_get_ldpc_support)(struct hal_rx_desc *desc); bool (*rx_desc_get_mpdu_seq_ctl_vld)(struct hal_rx_desc *desc); bool (*rx_desc_get_mpdu_fc_valid)(struct hal_rx_desc *desc); + bool (*rx_desc_get_mpdu_qos_ctrl_valid)(struct hal_rx_desc *desc); u16 (*rx_desc_get_mpdu_start_seq_no)(struct hal_rx_desc *desc); u16 (*rx_desc_get_msdu_len)(struct hal_rx_desc *desc); u8 (*rx_desc_get_msdu_sgi)(struct hal_rx_desc *desc); -- 2.53.0 ath12k_dp_rx_deliver_msdu() delivers frames with Ethernet decap as RX_FLAG_8023, and mac80211 counted all of them on TID 0. Pass the TID from the rx descriptor data of the MSDU, or IEEE80211_NUM_TIDS when the MPDU has no QoS control. The TID field has 4 bits, so add the QoS control valid bit of MPDU_START to struct hal_rx_desc_data. Signed-off-by: Julius Bairaktaris --- v3: - No change. v2: - Take the TID from rx_info instead of rxcb->tid, which *rx_status = *status overwrote before v1 read it. Found by the hosted Sashiko review of v1. - Pass IEEE80211_NUM_TIDS for a frame without QoS control. Found by an LLM review (Claude). drivers/net/wireless/ath/ath12k/dp_rx.c | 2 ++ drivers/net/wireless/ath/ath12k/hal.h | 1 + drivers/net/wireless/ath/ath12k/wifi7/hal_qcc2072.c | 8 ++++++++ drivers/net/wireless/ath/ath12k/wifi7/hal_qcn9274.c | 9 +++++++++ drivers/net/wireless/ath/ath12k/wifi7/hal_wcn7850.c | 9 +++++++++ 5 files changed, 29 insertions(+) diff --git a/drivers/net/wireless/ath/ath12k/dp_rx.c b/drivers/net/wireless/ath/ath12k/dp_rx.c index 52838ade1b1d5..cfa539df09d2c 100644 --- a/drivers/net/wireless/ath/ath12k/dp_rx.c +++ b/drivers/net/wireless/ath/ath12k/dp_rx.c @@ -1409,6 +1409,8 @@ void ath12k_dp_rx_deliver_msdu(struct ath12k_pdev_dp *dp_pdev, struct napi_struc rx_status = IEEE80211_SKB_RXCB(msdu); *rx_status = *status; + rx_status->tid = rx_info->qos_ctrl_valid ? rx_info->tid : + IEEE80211_NUM_TIDS; /* TODO: trace rx packet */ diff --git a/drivers/net/wireless/ath/ath12k/hal.h b/drivers/net/wireless/ath/ath12k/hal.h index 343e1636b4cc8..0c61a08f4374e 100644 --- a/drivers/net/wireless/ath/ath12k/hal.h +++ b/drivers/net/wireless/ath/ath12k/hal.h @@ -739,6 +739,7 @@ struct hal_rx_desc_data { is_mcbc:1, seq_ctl_valid:1, fc_valid:1, + qos_ctrl_valid:1, is_to_ds:1, is_from_ds:1; u16 msdu_len; diff --git a/drivers/net/wireless/ath/ath12k/wifi7/hal_qcc2072.c b/drivers/net/wireless/ath/ath12k/wifi7/hal_qcc2072.c index bad2b60409d91..3f0dfeedcb31d 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/hal_qcc2072.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/hal_qcc2072.c @@ -260,6 +260,12 @@ static bool ath12k_hal_rx_desc_get_mpdu_fc_valid_qcc2072(struct hal_rx_desc *des RX_MPDU_START_INFO4_MPDU_FCTRL_VALID); } +static bool ath12k_hal_rx_desc_get_mpdu_qos_ctrl_valid_qcc2072(struct hal_rx_desc *desc) +{ + return !!le32_get_bits(desc->u.qcc2072.mpdu_start.info4, + RX_MPDU_START_INFO4_MPDU_QOS_CTRL_VALID); +} + static u16 ath12k_hal_rx_desc_get_mpdu_start_seq_no_qcc2072(struct hal_rx_desc *desc) { return le32_get_bits(desc->u.qcc2072.mpdu_start.info4, @@ -403,6 +409,8 @@ static void ath12k_hal_extract_rx_desc_data_qcc2072(struct hal_rx_desc_data *rx_ rx_desc_data->seq_ctl_valid = ath12k_hal_rx_desc_get_mpdu_seq_ctl_vld_qcc2072(rx_desc); rx_desc_data->fc_valid = ath12k_hal_rx_desc_get_mpdu_fc_valid_qcc2072(rx_desc); + rx_desc_data->qos_ctrl_valid = + ath12k_hal_rx_desc_get_mpdu_qos_ctrl_valid_qcc2072(rx_desc); rx_desc_data->seq_no = ath12k_hal_rx_desc_get_mpdu_start_seq_no_qcc2072(rx_desc); rx_desc_data->msdu_len = ath12k_hal_rx_desc_get_msdu_len_qcc2072(ldesc); rx_desc_data->sgi = ath12k_hal_rx_desc_get_msdu_sgi_qcc2072(ldesc); diff --git a/drivers/net/wireless/ath/ath12k/wifi7/hal_qcn9274.c b/drivers/net/wireless/ath/ath12k/wifi7/hal_qcn9274.c index 0f85ae69b5e0c..060e5ea1f7fdf 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/hal_qcn9274.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/hal_qcn9274.c @@ -722,6 +722,13 @@ bool ath12k_hal_rx_desc_get_mpdu_fc_valid_qcn9274(struct hal_rx_desc *desc) RX_MPDU_START_INFO4_MPDU_FCTRL_VALID); } +static inline +bool ath12k_hal_rx_desc_get_mpdu_qos_ctrl_valid_qcn9274(struct hal_rx_desc *desc) +{ + return !!le32_get_bits(desc->u.qcn9274_compact.mpdu_start.info4, + RX_MPDU_START_INFO4_MPDU_QOS_CTRL_VALID); +} + static inline u16 ath12k_hal_rx_desc_get_mpdu_start_seq_no_qcn9274(struct hal_rx_desc *desc) { @@ -1024,6 +1031,8 @@ void ath12k_hal_extract_rx_desc_data_qcn9274(struct hal_rx_desc_data *rx_desc_da rx_desc_data->seq_ctl_valid = ath12k_hal_rx_desc_get_mpdu_seq_ctl_vld_qcn9274(rx_desc); rx_desc_data->fc_valid = ath12k_hal_rx_desc_get_mpdu_fc_valid_qcn9274(rx_desc); + rx_desc_data->qos_ctrl_valid = + ath12k_hal_rx_desc_get_mpdu_qos_ctrl_valid_qcn9274(rx_desc); rx_desc_data->is_from_ds = ath12k_wifi7_hal_rx_h_from_ds_qcn9274(ldesc); rx_desc_data->is_to_ds = ath12k_wifi7_hal_rx_h_to_ds_qcn9274(ldesc); rx_desc_data->seq_no = ath12k_hal_rx_desc_get_mpdu_start_seq_no_qcn9274(rx_desc); diff --git a/drivers/net/wireless/ath/ath12k/wifi7/hal_wcn7850.c b/drivers/net/wireless/ath/ath12k/wifi7/hal_wcn7850.c index 2d66d71d1b9b3..3751bf8589bac 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/hal_wcn7850.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/hal_wcn7850.c @@ -340,6 +340,13 @@ bool ath12k_hal_rx_desc_get_mpdu_fc_valid_wcn7850(struct hal_rx_desc *desc) RX_MPDU_START_INFO4_MPDU_FCTRL_VALID); } +static inline +bool ath12k_hal_rx_desc_get_mpdu_qos_ctrl_valid_wcn7850(struct hal_rx_desc *desc) +{ + return !!le32_get_bits(desc->u.wcn7850.mpdu_start.info4, + RX_MPDU_START_INFO4_MPDU_QOS_CTRL_VALID); +} + static inline u16 ath12k_hal_rx_desc_get_mpdu_start_seq_no_wcn7850(struct hal_rx_desc *desc) { @@ -620,6 +627,8 @@ void ath12k_hal_extract_rx_desc_data_wcn7850(struct hal_rx_desc_data *rx_desc_da rx_desc_data->seq_ctl_valid = ath12k_hal_rx_desc_get_mpdu_seq_ctl_vld_wcn7850(rx_desc); rx_desc_data->fc_valid = ath12k_hal_rx_desc_get_mpdu_fc_valid_wcn7850(rx_desc); + rx_desc_data->qos_ctrl_valid = + ath12k_hal_rx_desc_get_mpdu_qos_ctrl_valid_wcn7850(rx_desc); rx_desc_data->seq_no = ath12k_hal_rx_desc_get_mpdu_start_seq_no_wcn7850(rx_desc); rx_desc_data->msdu_len = ath12k_hal_rx_desc_get_msdu_len_wcn7850(ldesc); rx_desc_data->sgi = ath12k_hal_rx_desc_get_msdu_sgi_wcn7850(ldesc); -- 2.53.0