|
| 1 | +From: Felix Fietkau <nbd@nbd.name> |
| 2 | +Date: Wed, 10 Jun 2026 11:22:25 +0000 |
| 3 | +Subject: [PATCH] wifi: mac80211: notify driver on airtime weight changes |
| 4 | + |
| 5 | +Add a new sta_set_airtime_weight driver op so drivers can program the |
| 6 | +airtime fairness weight into hardware. The op is called when the weight |
| 7 | +is updated via sta_apply_parameters, and on station upload if a |
| 8 | +non-default weight is already set. |
| 9 | + |
| 10 | +Signed-off-by: Felix Fietkau <nbd@nbd.name> |
| 11 | +--- |
| 12 | + |
| 13 | +--- a/include/net/mac80211.h |
| 14 | ++++ b/include/net/mac80211.h |
| 15 | +@@ -4484,6 +4484,8 @@ struct ieee80211_prep_tx_info { |
| 16 | + * @set_sar_specs: Update the SAR (TX power) settings. |
| 17 | + * @sta_set_decap_offload: Called to notify the driver when a station is allowed |
| 18 | + * to use rx decapsulation offload |
| 19 | ++ * @sta_set_airtime_weight: Called to notify the driver of a change to a |
| 20 | ++ * station's airtime fairness weight, so it can be programmed in hardware. |
| 21 | + * @add_twt_setup: Update hw with TWT agreement parameters received from the peer. |
| 22 | + * This callback allows the hw to check if requested parameters |
| 23 | + * are supported and if there is enough room for a new agreement. |
| 24 | +@@ -4896,6 +4898,9 @@ struct ieee80211_ops { |
| 25 | + void (*sta_set_decap_offload)(struct ieee80211_hw *hw, |
| 26 | + struct ieee80211_vif *vif, |
| 27 | + struct ieee80211_sta *sta, bool enabled); |
| 28 | ++ void (*sta_set_airtime_weight)(struct ieee80211_hw *hw, |
| 29 | ++ struct ieee80211_vif *vif, |
| 30 | ++ struct ieee80211_sta *sta, u16 weight); |
| 31 | + void (*add_twt_setup)(struct ieee80211_hw *hw, |
| 32 | + struct ieee80211_sta *sta, |
| 33 | + struct ieee80211_twt_setup *twt); |
| 34 | +--- a/net/mac80211/cfg.c |
| 35 | ++++ b/net/mac80211/cfg.c |
| 36 | +@@ -2298,8 +2298,12 @@ static int sta_apply_parameters(struct i |
| 37 | + if (ieee80211_vif_is_mesh(&sdata->vif)) |
| 38 | + sta_apply_mesh_params(local, sta, params); |
| 39 | + |
| 40 | +- if (params->airtime_weight) |
| 41 | ++ if (params->airtime_weight) { |
| 42 | + sta->airtime_weight = params->airtime_weight; |
| 43 | ++ if (sta->uploaded) |
| 44 | ++ drv_sta_set_airtime_weight(local, sdata, &sta->sta, |
| 45 | ++ sta->airtime_weight); |
| 46 | ++ } |
| 47 | + |
| 48 | + /* set the STA state after all sta info from usermode has been set */ |
| 49 | + if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) || |
| 50 | +--- a/net/mac80211/driver-ops.c |
| 51 | ++++ b/net/mac80211/driver-ops.c |
| 52 | +@@ -157,6 +157,10 @@ int drv_sta_state(struct ieee80211_local |
| 53 | + sta->uploaded = true; |
| 54 | + if (rcu_access_pointer(sta->sta.rates)) |
| 55 | + drv_sta_rate_tbl_update(local, sdata, &sta->sta); |
| 56 | ++ if (sta->airtime_weight != IEEE80211_DEFAULT_AIRTIME_WEIGHT) |
| 57 | ++ drv_sta_set_airtime_weight(local, sdata, |
| 58 | ++ &sta->sta, |
| 59 | ++ sta->airtime_weight); |
| 60 | + } |
| 61 | + } else if (old_state == IEEE80211_STA_ASSOC && |
| 62 | + new_state == IEEE80211_STA_AUTH) { |
| 63 | +--- a/net/mac80211/driver-ops.h |
| 64 | ++++ b/net/mac80211/driver-ops.h |
| 65 | +@@ -1633,6 +1633,25 @@ static inline void drv_sta_set_decap_off |
| 66 | + trace_drv_return_void(local); |
| 67 | + } |
| 68 | + |
| 69 | ++static inline void drv_sta_set_airtime_weight(struct ieee80211_local *local, |
| 70 | ++ struct ieee80211_sub_if_data *sdata, |
| 71 | ++ struct ieee80211_sta *sta, |
| 72 | ++ u16 weight) |
| 73 | ++{ |
| 74 | ++ sdata = get_bss_sdata(sdata); |
| 75 | ++ |
| 76 | ++ might_sleep(); |
| 77 | ++ lockdep_assert_wiphy(local->hw.wiphy); |
| 78 | ++ if (!check_sdata_in_driver(sdata)) |
| 79 | ++ return; |
| 80 | ++ |
| 81 | ++ trace_drv_sta_set_airtime_weight(local, sdata, sta, weight); |
| 82 | ++ if (local->ops->sta_set_airtime_weight) |
| 83 | ++ local->ops->sta_set_airtime_weight(&local->hw, &sdata->vif, sta, |
| 84 | ++ weight); |
| 85 | ++ trace_drv_return_void(local); |
| 86 | ++} |
| 87 | ++ |
| 88 | + static inline void drv_add_twt_setup(struct ieee80211_local *local, |
| 89 | + struct ieee80211_sub_if_data *sdata, |
| 90 | + struct ieee80211_sta *sta, |
| 91 | +--- a/net/mac80211/sta_info.c |
| 92 | ++++ b/net/mac80211/sta_info.c |
| 93 | +@@ -832,8 +832,13 @@ static int sta_info_insert_drv_state(str |
| 94 | + * Drivers using legacy sta_add/sta_remove callbacks only |
| 95 | + * get uploaded set to true after sta_add is called. |
| 96 | + */ |
| 97 | +- if (!local->ops->sta_add) |
| 98 | ++ if (!local->ops->sta_add) { |
| 99 | + sta->uploaded = true; |
| 100 | ++ if (sta->airtime_weight != IEEE80211_DEFAULT_AIRTIME_WEIGHT) |
| 101 | ++ drv_sta_set_airtime_weight(local, sdata, |
| 102 | ++ &sta->sta, |
| 103 | ++ sta->airtime_weight); |
| 104 | ++ } |
| 105 | + return 0; |
| 106 | + } |
| 107 | + |
| 108 | +--- a/net/mac80211/trace.h |
| 109 | ++++ b/net/mac80211/trace.h |
| 110 | +@@ -2481,6 +2481,33 @@ DEFINE_EVENT(sta_flag_evt, drv_sta_set_d |
| 111 | + TP_ARGS(local, sdata, sta, enabled) |
| 112 | + ); |
| 113 | + |
| 114 | ++TRACE_EVENT(drv_sta_set_airtime_weight, |
| 115 | ++ TP_PROTO(struct ieee80211_local *local, |
| 116 | ++ struct ieee80211_sub_if_data *sdata, |
| 117 | ++ struct ieee80211_sta *sta, u16 weight), |
| 118 | ++ |
| 119 | ++ TP_ARGS(local, sdata, sta, weight), |
| 120 | ++ |
| 121 | ++ TP_STRUCT__entry( |
| 122 | ++ LOCAL_ENTRY |
| 123 | ++ VIF_ENTRY |
| 124 | ++ STA_ENTRY |
| 125 | ++ __field(u16, weight) |
| 126 | ++ ), |
| 127 | ++ |
| 128 | ++ TP_fast_assign( |
| 129 | ++ LOCAL_ASSIGN; |
| 130 | ++ VIF_ASSIGN; |
| 131 | ++ STA_ASSIGN; |
| 132 | ++ __entry->weight = weight; |
| 133 | ++ ), |
| 134 | ++ |
| 135 | ++ TP_printk( |
| 136 | ++ LOCAL_PR_FMT VIF_PR_FMT STA_PR_FMT " weight:%u", |
| 137 | ++ LOCAL_PR_ARG, VIF_PR_ARG, STA_PR_ARG, __entry->weight |
| 138 | ++ ) |
| 139 | ++); |
| 140 | ++ |
| 141 | + TRACE_EVENT(drv_add_twt_setup, |
| 142 | + TP_PROTO(struct ieee80211_local *local, |
| 143 | + struct ieee80211_sta *sta, |
0 commit comments