cfg80211: Add airtime statistics and settings
authorToke Høiland-Jørgensen <toke@toke.dk>
Wed, 19 Dec 2018 01:02:07 +0000 (17:02 -0800)
committerJohannes Berg <johannes.berg@intel.com>
Sat, 19 Jan 2019 08:31:35 +0000 (09:31 +0100)
This adds TX airtime statistics to the cfg80211 station dump (to go along
with the RX info already present), and adds a new parameter to set the
airtime weight of each station. The latter allows userspace to implement
policies for different stations by varying their weights.

Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
[rmanohar@codeaurora.org: fixed checkpatch warnings]
Signed-off-by: Rajkumar Manoharan <rmanohar@codeaurora.org>
[move airtime weight != 0 check into policy]
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
include/net/cfg80211.h
include/uapi/linux/nl80211.h
net/wireless/nl80211.c

index e0c41eb1c860fb53d7689d37b7f994a22931b7ba..1691f52fcc8072e76cf8f8b5bd154394a27458fc 100644 (file)
@@ -1003,6 +1003,7 @@ enum station_parameters_apply_mask {
  * @support_p2p_ps: information if station supports P2P PS mechanism
  * @he_capa: HE capabilities of station
  * @he_capa_len: the length of the HE capabilities
+ * @airtime_weight: airtime scheduler weight for this station
  */
 struct station_parameters {
        const u8 *supported_rates;
@@ -1032,6 +1033,7 @@ struct station_parameters {
        int support_p2p_ps;
        const struct ieee80211_he_cap_elem *he_capa;
        u8 he_capa_len;
+       u16 airtime_weight;
 };
 
 /**
@@ -1300,6 +1302,8 @@ struct cfg80211_tid_stats {
  *     from this peer
  * @connected_to_gate: true if mesh STA has a path to mesh gate
  * @rx_duration: aggregate PPDU duration(usecs) for all the frames from a peer
+ * @tx_duration: aggregate PPDU duration(usecs) for all the frames to a peer
+ * @airtime_weight: current airtime scheduling weight
  * @pertid: per-TID statistics, see &struct cfg80211_tid_stats, using the last
  *     (IEEE80211_NUM_TIDS) index for MSDUs not encapsulated in QoS-MPDUs.
  *     Note that this doesn't use the @filled bit, but is used if non-NULL.
@@ -1350,8 +1354,9 @@ struct station_info {
 
        u32 expected_throughput;
 
-       u64 rx_beacon;
+       u64 tx_duration;
        u64 rx_duration;
+       u64 rx_beacon;
        u8 rx_beacon_signal_avg;
        u8 connected_to_gate;
 
@@ -1359,6 +1364,8 @@ struct station_info {
        s8 ack_signal;
        s8 avg_ack_signal;
 
+       u16 airtime_weight;
+
        u32 rx_mpdu_count;
        u32 fcs_err_count;
 };
@@ -2391,6 +2398,8 @@ enum wiphy_params_flags {
        WIPHY_PARAM_TXQ_QUANTUM         = 1 << 8,
 };
 
+#define IEEE80211_DEFAULT_AIRTIME_WEIGHT       256
+
 /**
  * struct cfg80211_pmksa - PMK Security Association
  *
index 31ae5c7f10e35b67811b6bea78541b5e222dd82e..ebe79e12c82e9c42e5158c1fca157e862fb8dc30 100644 (file)
@@ -2299,6 +2299,9 @@ enum nl80211_commands {
  *     This is also used for capability advertisement in the wiphy information,
  *     with the appropriate sub-attributes.
  *
+ * @NL80211_ATTR_AIRTIME_WEIGHT: Station's weight when scheduled by the airtime
+ *     scheduler.
+ *
  * @NUM_NL80211_ATTR: total number of nl80211_attrs available
  * @NL80211_ATTR_MAX: highest attribute number currently defined
  * @__NL80211_ATTR_AFTER_LAST: internal use
@@ -2748,6 +2751,8 @@ enum nl80211_attrs {
 
        NL80211_ATTR_PEER_MEASUREMENTS,
 
+       NL80211_ATTR_AIRTIME_WEIGHT,
+
        /* add attributes here, update the policy in nl80211.c */
 
        __NL80211_ATTR_AFTER_LAST,
@@ -3125,6 +3130,9 @@ enum nl80211_sta_bss_param {
  *     might not be fully accurate.
  * @NL80211_STA_INFO_CONNECTED_TO_GATE: set to true if STA has a path to a
  *     mesh gate (u8, 0 or 1)
+ * @NL80211_STA_INFO_TX_DURATION: aggregate PPDU duration for all frames
+ *     sent to the station (u64, usec)
+ * @NL80211_STA_INFO_AIRTIME_WEIGHT: current airtime weight for station (u16)
  * @__NL80211_STA_INFO_AFTER_LAST: internal
  * @NL80211_STA_INFO_MAX: highest possible station info attribute
  */
@@ -3168,6 +3176,8 @@ enum nl80211_sta_info {
        NL80211_STA_INFO_RX_MPDUS,
        NL80211_STA_INFO_FCS_ERROR_COUNT,
        NL80211_STA_INFO_CONNECTED_TO_GATE,
+       NL80211_STA_INFO_TX_DURATION,
+       NL80211_STA_INFO_AIRTIME_WEIGHT,
 
        /* keep last */
        __NL80211_STA_INFO_AFTER_LAST,
@@ -5316,6 +5326,10 @@ enum nl80211_feature_flags {
  *      if this flag is not set. Ignoring this can leak clear text packets and/or
  *      freeze the connection.
  *
+ * @NL80211_EXT_FEATURE_AIRTIME_FAIRNESS: Driver supports getting airtime
+ *     fairness for transmitted packets and has enabled airtime fairness
+ *     scheduling.
+ *
  * @NUM_NL80211_EXT_FEATURES: number of extended features.
  * @MAX_NL80211_EXT_FEATURES: highest extended feature index.
  */
@@ -5355,6 +5369,7 @@ enum nl80211_ext_feature_index {
        NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT,
        NL80211_EXT_FEATURE_CAN_REPLACE_PTK0,
        NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER,
+       NL80211_EXT_FEATURE_AIRTIME_FAIRNESS,
 
        /* add new features before the definition below */
        NUM_NL80211_EXT_FEATURES,
index 5e49492d5911d816c85bdec83af843e0a5235c1c..a89688929b1683a4843cd09c602bc8ac6e9e6f2a 100644 (file)
@@ -557,6 +557,7 @@ const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
        [NL80211_ATTR_PEER_MEASUREMENTS] =
                NLA_POLICY_NESTED(NL80211_PMSR_FTM_REQ_ATTR_MAX,
                                  nl80211_pmsr_attr_policy),
+       [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1),
 };
 
 /* policy for the key attributes */
@@ -4851,6 +4852,11 @@ static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
        PUT_SINFO(PLID, plid, u16);
        PUT_SINFO(PLINK_STATE, plink_state, u8);
        PUT_SINFO_U64(RX_DURATION, rx_duration);
+       PUT_SINFO_U64(TX_DURATION, tx_duration);
+
+       if (wiphy_ext_feature_isset(&rdev->wiphy,
+                                   NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
+               PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16);
 
        switch (rdev->wiphy.signal_type) {
        case CFG80211_SIGNAL_TYPE_MBM:
@@ -5470,6 +5476,15 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
                        nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
        }
 
+       if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
+               params.airtime_weight =
+                       nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
+
+       if (params.airtime_weight &&
+           !wiphy_ext_feature_isset(&rdev->wiphy,
+                                    NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
+               return -EOPNOTSUPP;
+
        /* Include parameters for TDLS peer (will check later) */
        err = nl80211_set_station_tdls(info, &params);
        if (err)
@@ -5598,6 +5613,15 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
                params.plink_action =
                        nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
 
+       if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
+               params.airtime_weight =
+                       nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
+
+       if (params.airtime_weight &&
+           !wiphy_ext_feature_isset(&rdev->wiphy,
+                                    NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
+               return -EOPNOTSUPP;
+
        err = nl80211_parse_sta_channel_info(info, &params);
        if (err)
                return err;