Frames of a flow that the hardware forwards on behalf of the driver never pass through mac80211, so the SCS and MSCS rules of the station are not applied to them. Add ieee80211_sta_flow_prio(), which lets a driver look up the user priority of a flow before it creates an offload entry. The query uses the rule lookup of the transmit path on a flow description from the driver, so that both apply the same rules in the same order. The query fails when a rule refers to a field that the description does not carry, since the answer could then differ between frames of the flow. The driver must leave such a flow to the software path. When no rule matches, the caller can pass the DSCP of a packet of the flow to get the QoS map priority for it, as the software path does. The first user, flow offload with mtk_eth_soc on mt7996, follows in a separate series. Signed-off-by: Felix Fietkau --- include/net/mac80211.h | 23 +++++++++++++++++++++- net/mac80211/scs.c | 47 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index 9ed50c6fe679..de570d72fd16 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -6793,6 +6793,29 @@ struct ieee80211_sta *ieee80211_find_sta(struct ieee80211_vif *vif, const u8 *addr); /** + * ieee80211_sta_flow_prio - look up the user priority of a flow + * + * @pubsta: the station the flow is sent to + * @info: the flow as it is sent to @pubsta, after any address translation + * @dscp: the DSCP of a packet of the flow, or negative if unknown. Used + * for the QoS map fallback only, when no SCS or MSCS rule matches. + * @prio: filled with the user priority, left untouched if no rule matches + * and @dscp is negative + * + * For drivers that forward flows in hardware without passing the frames + * through mac80211. The result is the priority that the software path + * assigns to frames of this flow. + * + * Must be called under RCU lock. Does not sleep. + * + * Return: 0 on success, or a negative error if a rule refers to a field + * that @info does not carry. Such a flow must not be offloaded. + */ +int ieee80211_sta_flow_prio(struct ieee80211_sta *pubsta, + const struct cfg80211_flow_info *info, int dscp, + u8 *prio); + +/** * ieee80211_find_sta_by_ifaddr - find a station on hardware * * @hw: pointer as obtained from ieee80211_alloc_hw() diff --git a/net/mac80211/scs.c b/net/mac80211/scs.c index 00c58eaa3057..986439035df8 100644 --- a/net/mac80211/scs.c +++ b/net/mac80211/scs.c @@ -4,6 +4,7 @@ * * Copyright (C) 2026 Felix Fietkau */ +#include #include #include #include "driver-ops.h" @@ -123,16 +124,22 @@ static bool ieee80211_mscs_lookup(struct sta_info *sta, struct ieee80211_flow_entry *entry; struct ieee80211_flow_hkey hkey; - if (!(info->present & BIT(CFG80211_FLOW_F_ETH_DA))) + if (!(info->present & BIT(CFG80211_FLOW_F_ETH_DA))) { + verdict->undecided = true; + return false; + } if (!ether_addr_equal(info->key.da, mscs->client)) return false; hkey.mscs = mscs; if (!cfg80211_flow_key_build(info, mscs->layout, CFG80211_FLOW_AS_IS, - &hkey.key)) + &hkey.key)) { + verdict->undecided = true; + return false; + } entry = rhashtable_lookup(&sta->sdata->bss->flow_tbl, &hkey, flow_rht_params); @@ -197,6 +204,42 @@ bool ieee80211_flow_classify(struct sta_info *sta, struct sk_buff *skb) return true; } +int ieee80211_sta_flow_prio(struct ieee80211_sta *pubsta, + const struct cfg80211_flow_info *info, int dscp, + u8 *prio) +{ + struct sta_info *sta = container_of(pubsta, struct sta_info, sta); + struct cfg80211_scs_verdict verdict; + struct mac80211_qos_map *qos_map; + bool match; + + /* Like ieee80211_select_queue(), which sends these as best effort */ + if (!pubsta->wme) { + *prio = 0; + + return 0; + } + + match = ieee80211_flow_lookup(sta, info, &verdict); + if (verdict.undecided) + return -EOPNOTSUPP; + + if (match) { + *prio = verdict.up; + + return 0; + } + + if (dscp < 0) + return 0; + + qos_map = rcu_dereference(sta->sdata->qos_map); + *prio = cfg80211_dscp_to_up(dscp, qos_map ? &qos_map->qos_map : NULL); + + return 0; +} +EXPORT_SYMBOL(ieee80211_sta_flow_prio); + static void ieee80211_flow_entry_free(struct ieee80211_if_ap *ap, struct ieee80211_flow_entry *entry) { -- git-series 0.9.1