^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2010-2013 Felix Fietkau <nbd@openwrt.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2019-2020 Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/ieee80211.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <net/mac80211.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "rate.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "sta_info.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "rc80211_minstrel.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "rc80211_minstrel_ht.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define AVG_AMPDU_SIZE 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define AVG_PKT_SIZE 1200
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define SAMPLE_SWITCH_THR 100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) /* Number of bits for an average sized packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define MCS_NBITS ((AVG_PKT_SIZE * AVG_AMPDU_SIZE) << 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) /* Number of symbols for a packet with (bps) bits per symbol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define MCS_NSYMS(bps) DIV_ROUND_UP(MCS_NBITS, (bps))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) /* Transmission time (nanoseconds) for a packet containing (syms) symbols */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define MCS_SYMBOL_TIME(sgi, syms) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) (sgi ? \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) ((syms) * 18000 + 4000) / 5 : /* syms * 3.6 us */ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) ((syms) * 1000) << 2 /* syms * 4 us */ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /* Transmit duration for the raw data part of an average sized packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define MCS_DURATION(streams, sgi, bps) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) (MCS_SYMBOL_TIME(sgi, MCS_NSYMS((streams) * (bps))) / AVG_AMPDU_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define BW_20 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define BW_40 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define BW_80 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * Define group sort order: HT40 -> SGI -> #streams
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define GROUP_IDX(_streams, _sgi, _ht40) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) MINSTREL_HT_GROUP_0 + \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) MINSTREL_MAX_STREAMS * 2 * _ht40 + \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) MINSTREL_MAX_STREAMS * _sgi + \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) _streams - 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define _MAX(a, b) (((a)>(b))?(a):(b))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define GROUP_SHIFT(duration) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) _MAX(0, 16 - __builtin_clz(duration))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) /* MCS rate information for an MCS group */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define __MCS_GROUP(_streams, _sgi, _ht40, _s) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) [GROUP_IDX(_streams, _sgi, _ht40)] = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .streams = _streams, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) .shift = _s, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) .bw = _ht40, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) .flags = \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) IEEE80211_TX_RC_MCS | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) (_sgi ? IEEE80211_TX_RC_SHORT_GI : 0) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) (_ht40 ? IEEE80211_TX_RC_40_MHZ_WIDTH : 0), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) .duration = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) MCS_DURATION(_streams, _sgi, _ht40 ? 54 : 26) >> _s, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) MCS_DURATION(_streams, _sgi, _ht40 ? 108 : 52) >> _s, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) MCS_DURATION(_streams, _sgi, _ht40 ? 162 : 78) >> _s, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) MCS_DURATION(_streams, _sgi, _ht40 ? 216 : 104) >> _s, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) MCS_DURATION(_streams, _sgi, _ht40 ? 324 : 156) >> _s, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) MCS_DURATION(_streams, _sgi, _ht40 ? 432 : 208) >> _s, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) MCS_DURATION(_streams, _sgi, _ht40 ? 486 : 234) >> _s, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) MCS_DURATION(_streams, _sgi, _ht40 ? 540 : 260) >> _s \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #define MCS_GROUP_SHIFT(_streams, _sgi, _ht40) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) GROUP_SHIFT(MCS_DURATION(_streams, _sgi, _ht40 ? 54 : 26))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #define MCS_GROUP(_streams, _sgi, _ht40) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) __MCS_GROUP(_streams, _sgi, _ht40, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) MCS_GROUP_SHIFT(_streams, _sgi, _ht40))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #define VHT_GROUP_IDX(_streams, _sgi, _bw) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) (MINSTREL_VHT_GROUP_0 + \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) MINSTREL_MAX_STREAMS * 2 * (_bw) + \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) MINSTREL_MAX_STREAMS * (_sgi) + \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) (_streams) - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) #define BW2VBPS(_bw, r3, r2, r1) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) (_bw == BW_80 ? r3 : _bw == BW_40 ? r2 : r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #define __VHT_GROUP(_streams, _sgi, _bw, _s) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) [VHT_GROUP_IDX(_streams, _sgi, _bw)] = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) .streams = _streams, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) .shift = _s, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) .bw = _bw, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) .flags = \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) IEEE80211_TX_RC_VHT_MCS | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) (_sgi ? IEEE80211_TX_RC_SHORT_GI : 0) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) (_bw == BW_80 ? IEEE80211_TX_RC_80_MHZ_WIDTH : \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) _bw == BW_40 ? IEEE80211_TX_RC_40_MHZ_WIDTH : 0), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) .duration = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) MCS_DURATION(_streams, _sgi, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) BW2VBPS(_bw, 117, 54, 26)) >> _s, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) MCS_DURATION(_streams, _sgi, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) BW2VBPS(_bw, 234, 108, 52)) >> _s, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) MCS_DURATION(_streams, _sgi, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) BW2VBPS(_bw, 351, 162, 78)) >> _s, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) MCS_DURATION(_streams, _sgi, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) BW2VBPS(_bw, 468, 216, 104)) >> _s, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) MCS_DURATION(_streams, _sgi, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) BW2VBPS(_bw, 702, 324, 156)) >> _s, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) MCS_DURATION(_streams, _sgi, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) BW2VBPS(_bw, 936, 432, 208)) >> _s, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) MCS_DURATION(_streams, _sgi, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) BW2VBPS(_bw, 1053, 486, 234)) >> _s, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) MCS_DURATION(_streams, _sgi, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) BW2VBPS(_bw, 1170, 540, 260)) >> _s, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) MCS_DURATION(_streams, _sgi, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) BW2VBPS(_bw, 1404, 648, 312)) >> _s, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) MCS_DURATION(_streams, _sgi, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) BW2VBPS(_bw, 1560, 720, 346)) >> _s \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) #define VHT_GROUP_SHIFT(_streams, _sgi, _bw) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) GROUP_SHIFT(MCS_DURATION(_streams, _sgi, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) BW2VBPS(_bw, 117, 54, 26)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #define VHT_GROUP(_streams, _sgi, _bw) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) __VHT_GROUP(_streams, _sgi, _bw, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) VHT_GROUP_SHIFT(_streams, _sgi, _bw))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) #define CCK_DURATION(_bitrate, _short, _len) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) (1000 * (10 /* SIFS */ + \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) (_short ? 72 + 24 : 144 + 48) + \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) (8 * (_len + 4) * 10) / (_bitrate)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) #define CCK_ACK_DURATION(_bitrate, _short) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) (CCK_DURATION((_bitrate > 10 ? 20 : 10), false, 60) + \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) CCK_DURATION(_bitrate, _short, AVG_PKT_SIZE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) #define CCK_DURATION_LIST(_short, _s) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) CCK_ACK_DURATION(10, _short) >> _s, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) CCK_ACK_DURATION(20, _short) >> _s, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) CCK_ACK_DURATION(55, _short) >> _s, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) CCK_ACK_DURATION(110, _short) >> _s
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) #define __CCK_GROUP(_s) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) [MINSTREL_CCK_GROUP] = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) .streams = 1, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) .flags = 0, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) .shift = _s, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) .duration = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) CCK_DURATION_LIST(false, _s), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) CCK_DURATION_LIST(true, _s) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) #define CCK_GROUP_SHIFT \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) GROUP_SHIFT(CCK_ACK_DURATION(10, false))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) #define CCK_GROUP __CCK_GROUP(CCK_GROUP_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) static bool minstrel_vht_only = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) module_param(minstrel_vht_only, bool, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) MODULE_PARM_DESC(minstrel_vht_only,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) "Use only VHT rates when VHT is supported by sta.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * To enable sufficiently targeted rate sampling, MCS rates are divided into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * groups, based on the number of streams and flags (HT40, SGI) that they
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * Sortorder has to be fixed for GROUP_IDX macro to be applicable:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * BW -> SGI -> #streams
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) const struct mcs_group minstrel_mcs_groups[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) MCS_GROUP(1, 0, BW_20),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) MCS_GROUP(2, 0, BW_20),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) MCS_GROUP(3, 0, BW_20),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) MCS_GROUP(4, 0, BW_20),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) MCS_GROUP(1, 1, BW_20),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) MCS_GROUP(2, 1, BW_20),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) MCS_GROUP(3, 1, BW_20),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) MCS_GROUP(4, 1, BW_20),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) MCS_GROUP(1, 0, BW_40),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) MCS_GROUP(2, 0, BW_40),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) MCS_GROUP(3, 0, BW_40),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) MCS_GROUP(4, 0, BW_40),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) MCS_GROUP(1, 1, BW_40),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) MCS_GROUP(2, 1, BW_40),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) MCS_GROUP(3, 1, BW_40),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) MCS_GROUP(4, 1, BW_40),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) CCK_GROUP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) VHT_GROUP(1, 0, BW_20),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) VHT_GROUP(2, 0, BW_20),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) VHT_GROUP(3, 0, BW_20),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) VHT_GROUP(4, 0, BW_20),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) VHT_GROUP(1, 1, BW_20),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) VHT_GROUP(2, 1, BW_20),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) VHT_GROUP(3, 1, BW_20),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) VHT_GROUP(4, 1, BW_20),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) VHT_GROUP(1, 0, BW_40),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) VHT_GROUP(2, 0, BW_40),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) VHT_GROUP(3, 0, BW_40),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) VHT_GROUP(4, 0, BW_40),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) VHT_GROUP(1, 1, BW_40),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) VHT_GROUP(2, 1, BW_40),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) VHT_GROUP(3, 1, BW_40),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) VHT_GROUP(4, 1, BW_40),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) VHT_GROUP(1, 0, BW_80),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) VHT_GROUP(2, 0, BW_80),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) VHT_GROUP(3, 0, BW_80),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) VHT_GROUP(4, 0, BW_80),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) VHT_GROUP(1, 1, BW_80),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) VHT_GROUP(2, 1, BW_80),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) VHT_GROUP(3, 1, BW_80),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) VHT_GROUP(4, 1, BW_80),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static u8 sample_table[SAMPLE_COLUMNS][MCS_GROUP_RATES] __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) minstrel_ht_update_rates(struct minstrel_priv *mp, struct minstrel_ht_sta *mi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) * Some VHT MCSes are invalid (when Ndbps / Nes is not an integer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) * e.g for MCS9@20MHzx1Nss: Ndbps=8x52*(5/6) Nes=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * Returns the valid mcs map for struct minstrel_mcs_group_data.supported
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static u16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) minstrel_get_valid_vht_rates(int bw, int nss, __le16 mcs_map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) u16 mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (bw == BW_20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (nss != 3 && nss != 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) mask = BIT(9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) } else if (bw == BW_80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (nss == 3 || nss == 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) mask = BIT(6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) else if (nss == 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) mask = BIT(9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) WARN_ON(bw != BW_40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) switch ((le16_to_cpu(mcs_map) >> (2 * (nss - 1))) & 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) case IEEE80211_VHT_MCS_SUPPORT_0_7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) mask |= 0x300;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) case IEEE80211_VHT_MCS_SUPPORT_0_8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) mask |= 0x200;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) case IEEE80211_VHT_MCS_SUPPORT_0_9:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) mask = 0x3ff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) return 0x3ff & ~mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * Look up an MCS group index based on mac80211 rate information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) minstrel_ht_get_group_idx(struct ieee80211_tx_rate *rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) return GROUP_IDX((rate->idx / 8) + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) !!(rate->flags & IEEE80211_TX_RC_SHORT_GI),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) !!(rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) minstrel_vht_get_group_idx(struct ieee80211_tx_rate *rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) return VHT_GROUP_IDX(ieee80211_rate_get_vht_nss(rate),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) !!(rate->flags & IEEE80211_TX_RC_SHORT_GI),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) !!(rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 2*!!(rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) static struct minstrel_rate_stats *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) minstrel_ht_get_stats(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) struct ieee80211_tx_rate *rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) int group, idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) if (rate->flags & IEEE80211_TX_RC_MCS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) group = minstrel_ht_get_group_idx(rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) idx = rate->idx % 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) group = minstrel_vht_get_group_idx(rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) idx = ieee80211_rate_get_vht_mcs(rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) group = MINSTREL_CCK_GROUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) for (idx = 0; idx < ARRAY_SIZE(mp->cck_rates); idx++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if (rate->idx == mp->cck_rates[idx])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) /* short preamble */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) if ((mi->supported[group] & BIT(idx + 4)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) (rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) idx += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) return &mi->groups[group].rates[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) static inline struct minstrel_rate_stats *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) minstrel_get_ratestats(struct minstrel_ht_sta *mi, int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) return &mi->groups[index / MCS_GROUP_RATES].rates[index % MCS_GROUP_RATES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) static unsigned int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) minstrel_ht_avg_ampdu_len(struct minstrel_ht_sta *mi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if (!mi->avg_ampdu_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) return AVG_AMPDU_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) return MINSTREL_TRUNC(mi->avg_ampdu_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) * Return current throughput based on the average A-MPDU length, taking into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) * account the expected number of retransmissions and their expected length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) minstrel_ht_get_tp_avg(struct minstrel_ht_sta *mi, int group, int rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) int prob_avg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) unsigned int nsecs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) /* do not account throughput if sucess prob is below 10% */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) if (prob_avg < MINSTREL_FRAC(10, 100))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) if (group != MINSTREL_CCK_GROUP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) nsecs = 1000 * mi->overhead / minstrel_ht_avg_ampdu_len(mi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) nsecs += minstrel_mcs_groups[group].duration[rate] <<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) minstrel_mcs_groups[group].shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) * For the throughput calculation, limit the probability value to 90% to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) * account for collision related packet error rate fluctuation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) * (prob is scaled - see MINSTREL_FRAC above)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) if (prob_avg > MINSTREL_FRAC(90, 100))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) return MINSTREL_TRUNC(100000 * ((MINSTREL_FRAC(90, 100) * 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) / nsecs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) return MINSTREL_TRUNC(100000 * ((prob_avg * 1000) / nsecs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) * Find & sort topmost throughput rates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) * If multiple rates provide equal throughput the sorting is based on their
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) * current success probability. Higher success probability is preferred among
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) * MCS groups, CCK rates do not provide aggregation and are therefore at last.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) minstrel_ht_sort_best_tp_rates(struct minstrel_ht_sta *mi, u16 index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) u16 *tp_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) int cur_group, cur_idx, cur_tp_avg, cur_prob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) int tmp_group, tmp_idx, tmp_tp_avg, tmp_prob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) int j = MAX_THR_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) cur_group = index / MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) cur_idx = index % MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) cur_prob = mi->groups[cur_group].rates[cur_idx].prob_avg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) cur_tp_avg = minstrel_ht_get_tp_avg(mi, cur_group, cur_idx, cur_prob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) tmp_group = tp_list[j - 1] / MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) tmp_idx = tp_list[j - 1] % MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) tmp_prob = mi->groups[tmp_group].rates[tmp_idx].prob_avg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) tmp_tp_avg = minstrel_ht_get_tp_avg(mi, tmp_group, tmp_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) tmp_prob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) if (cur_tp_avg < tmp_tp_avg ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) (cur_tp_avg == tmp_tp_avg && cur_prob <= tmp_prob))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) j--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) } while (j > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) if (j < MAX_THR_RATES - 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) memmove(&tp_list[j + 1], &tp_list[j], (sizeof(*tp_list) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) (MAX_THR_RATES - (j + 1))));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) if (j < MAX_THR_RATES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) tp_list[j] = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) * Find and set the topmost probability rate per sta and per group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) minstrel_ht_set_best_prob_rate(struct minstrel_ht_sta *mi, u16 index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) struct minstrel_mcs_group_data *mg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) struct minstrel_rate_stats *mrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) int tmp_group, tmp_idx, tmp_tp_avg, tmp_prob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) int max_tp_group, cur_tp_avg, cur_group, cur_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) int max_gpr_group, max_gpr_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) int max_gpr_tp_avg, max_gpr_prob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) cur_group = index / MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) cur_idx = index % MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) mg = &mi->groups[index / MCS_GROUP_RATES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) mrs = &mg->rates[index % MCS_GROUP_RATES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) tmp_group = mi->max_prob_rate / MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) tmp_idx = mi->max_prob_rate % MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) tmp_prob = mi->groups[tmp_group].rates[tmp_idx].prob_avg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) tmp_tp_avg = minstrel_ht_get_tp_avg(mi, tmp_group, tmp_idx, tmp_prob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) /* if max_tp_rate[0] is from MCS_GROUP max_prob_rate get selected from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) * MCS_GROUP as well as CCK_GROUP rates do not allow aggregation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) max_tp_group = mi->max_tp_rate[0] / MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) if((index / MCS_GROUP_RATES == MINSTREL_CCK_GROUP) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) (max_tp_group != MINSTREL_CCK_GROUP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) max_gpr_group = mg->max_group_prob_rate / MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) max_gpr_idx = mg->max_group_prob_rate % MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) max_gpr_prob = mi->groups[max_gpr_group].rates[max_gpr_idx].prob_avg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) if (mrs->prob_avg > MINSTREL_FRAC(75, 100)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) cur_tp_avg = minstrel_ht_get_tp_avg(mi, cur_group, cur_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) mrs->prob_avg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) if (cur_tp_avg > tmp_tp_avg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) mi->max_prob_rate = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) max_gpr_tp_avg = minstrel_ht_get_tp_avg(mi, max_gpr_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) max_gpr_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) max_gpr_prob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) if (cur_tp_avg > max_gpr_tp_avg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) mg->max_group_prob_rate = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) if (mrs->prob_avg > tmp_prob)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) mi->max_prob_rate = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) if (mrs->prob_avg > max_gpr_prob)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) mg->max_group_prob_rate = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) * Assign new rate set per sta and use CCK rates only if the fastest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) * rate (max_tp_rate[0]) is from CCK group. This prohibits such sorted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) * rate sets where MCS and CCK rates are mixed, because CCK rates can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) * not use aggregation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) minstrel_ht_assign_best_tp_rates(struct minstrel_ht_sta *mi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) u16 tmp_mcs_tp_rate[MAX_THR_RATES],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) u16 tmp_cck_tp_rate[MAX_THR_RATES])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) unsigned int tmp_group, tmp_idx, tmp_cck_tp, tmp_mcs_tp, tmp_prob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) tmp_group = tmp_cck_tp_rate[0] / MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) tmp_idx = tmp_cck_tp_rate[0] % MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) tmp_prob = mi->groups[tmp_group].rates[tmp_idx].prob_avg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) tmp_cck_tp = minstrel_ht_get_tp_avg(mi, tmp_group, tmp_idx, tmp_prob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) tmp_group = tmp_mcs_tp_rate[0] / MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) tmp_idx = tmp_mcs_tp_rate[0] % MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) tmp_prob = mi->groups[tmp_group].rates[tmp_idx].prob_avg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) tmp_mcs_tp = minstrel_ht_get_tp_avg(mi, tmp_group, tmp_idx, tmp_prob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) if (tmp_cck_tp > tmp_mcs_tp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) for(i = 0; i < MAX_THR_RATES; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) minstrel_ht_sort_best_tp_rates(mi, tmp_cck_tp_rate[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) tmp_mcs_tp_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) * Try to increase robustness of max_prob rate by decrease number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) * streams if possible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) minstrel_ht_prob_rate_reduce_streams(struct minstrel_ht_sta *mi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) struct minstrel_mcs_group_data *mg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) int tmp_max_streams, group, tmp_idx, tmp_prob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) int tmp_tp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) tmp_max_streams = minstrel_mcs_groups[mi->max_tp_rate[0] /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) MCS_GROUP_RATES].streams;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) for (group = 0; group < ARRAY_SIZE(minstrel_mcs_groups); group++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) mg = &mi->groups[group];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) if (!mi->supported[group] || group == MINSTREL_CCK_GROUP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) tmp_idx = mg->max_group_prob_rate % MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) tmp_prob = mi->groups[group].rates[tmp_idx].prob_avg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) if (tmp_tp < minstrel_ht_get_tp_avg(mi, group, tmp_idx, tmp_prob) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) (minstrel_mcs_groups[group].streams < tmp_max_streams)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) mi->max_prob_rate = mg->max_group_prob_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) tmp_tp = minstrel_ht_get_tp_avg(mi, group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) tmp_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) tmp_prob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) minstrel_get_duration(int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) const struct mcs_group *group = &minstrel_mcs_groups[index / MCS_GROUP_RATES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) unsigned int duration = group->duration[index % MCS_GROUP_RATES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) return duration << group->shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) minstrel_ht_probe_group(struct minstrel_ht_sta *mi, const struct mcs_group *tp_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) int tp_idx, const struct mcs_group *group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) if (group->bw < tp_group->bw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) if (group->streams == tp_group->streams)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) if (tp_idx < 4 && group->streams == tp_group->streams - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) return group->streams == tp_group->streams + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) minstrel_ht_find_probe_rates(struct minstrel_ht_sta *mi, u16 *rates, int *n_rates,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) bool faster_rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) const struct mcs_group *group, *tp_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) int i, g, max_dur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) int tp_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) tp_group = &minstrel_mcs_groups[mi->max_tp_rate[0] / MCS_GROUP_RATES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) tp_idx = mi->max_tp_rate[0] % MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) max_dur = minstrel_get_duration(mi->max_tp_rate[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) if (faster_rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) max_dur -= max_dur / 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) for (g = 0; g < MINSTREL_GROUPS_NB; g++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) u16 supported = mi->supported[g];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) if (!supported)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) group = &minstrel_mcs_groups[g];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) if (!minstrel_ht_probe_group(mi, tp_group, tp_idx, group))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) for (i = 0; supported; supported >>= 1, i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) if (!(supported & 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) if ((group->duration[i] << group->shift) > max_dur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) idx = g * MCS_GROUP_RATES + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) if (idx == mi->max_tp_rate[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) rates[(*n_rates)++] = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) minstrel_ht_rate_sample_switch(struct minstrel_priv *mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) struct minstrel_ht_sta *mi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) struct minstrel_rate_stats *mrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) u16 rates[MINSTREL_GROUPS_NB];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) int n_rates = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) int probe_rate = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) bool faster_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) u8 random;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) * Use rate switching instead of probing packets for devices with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) * little control over retry fallback behavior
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) if (mp->hw->max_rates > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) * If the current EWMA prob is >75%, look for a rate that's 6.25%
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) * faster than the max tp rate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) * If that fails, look again for a rate that is at least as fast
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) mrs = minstrel_get_ratestats(mi, mi->max_tp_rate[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) faster_rate = mrs->prob_avg > MINSTREL_FRAC(75, 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) minstrel_ht_find_probe_rates(mi, rates, &n_rates, faster_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) if (!n_rates && faster_rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) minstrel_ht_find_probe_rates(mi, rates, &n_rates, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) /* If no suitable rate was found, try to pick the next one in the group */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) if (!n_rates) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) int g_idx = mi->max_tp_rate[0] / MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) u16 supported = mi->supported[g_idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) supported >>= mi->max_tp_rate[0] % MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) for (i = 0; supported; supported >>= 1, i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) if (!(supported & 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) probe_rate = mi->max_tp_rate[0] + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) if (n_rates > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) random = prandom_u32();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) i = random % n_rates;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) probe_rate = rates[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) mi->sample_rate = probe_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) mi->sample_mode = MINSTREL_SAMPLE_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) * Update rate statistics and select new primary rates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) * Rules for rate selection:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) * - max_prob_rate must use only one stream, as a tradeoff between delivery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) * probability and throughput during strong fluctuations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) * - as long as the max prob rate has a probability of more than 75%, pick
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) * higher throughput rates, even if the probablity is a bit lower
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) minstrel_ht_update_stats(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) bool sample)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) struct minstrel_mcs_group_data *mg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) struct minstrel_rate_stats *mrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) int group, i, j, cur_prob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) u16 tmp_mcs_tp_rate[MAX_THR_RATES], tmp_group_tp_rate[MAX_THR_RATES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) u16 tmp_cck_tp_rate[MAX_THR_RATES], index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) mi->sample_mode = MINSTREL_SAMPLE_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) if (sample) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) mi->total_packets_cur = mi->total_packets -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) mi->total_packets_last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) mi->total_packets_last = mi->total_packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) if (!mp->sample_switch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) sample = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) if (mi->total_packets_cur < SAMPLE_SWITCH_THR && mp->sample_switch != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) sample = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) if (mi->ampdu_packets > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) if (!ieee80211_hw_check(mp->hw, TX_STATUS_NO_AMPDU_LEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) mi->avg_ampdu_len = minstrel_ewma(mi->avg_ampdu_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) MINSTREL_FRAC(mi->ampdu_len, mi->ampdu_packets),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) EWMA_LEVEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) mi->avg_ampdu_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) mi->ampdu_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) mi->ampdu_packets = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) mi->sample_slow = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) mi->sample_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) memset(tmp_mcs_tp_rate, 0, sizeof(tmp_mcs_tp_rate));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) memset(tmp_cck_tp_rate, 0, sizeof(tmp_cck_tp_rate));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) if (mi->supported[MINSTREL_CCK_GROUP])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) for (j = 0; j < ARRAY_SIZE(tmp_cck_tp_rate); j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) tmp_cck_tp_rate[j] = MINSTREL_CCK_GROUP * MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) if (mi->supported[MINSTREL_VHT_GROUP_0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) index = MINSTREL_VHT_GROUP_0 * MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) index = MINSTREL_HT_GROUP_0 * MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) for (j = 0; j < ARRAY_SIZE(tmp_mcs_tp_rate); j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) tmp_mcs_tp_rate[j] = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) /* Find best rate sets within all MCS groups*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) for (group = 0; group < ARRAY_SIZE(minstrel_mcs_groups); group++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) mg = &mi->groups[group];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) if (!mi->supported[group])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) mi->sample_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) /* (re)Initialize group rate indexes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) for(j = 0; j < MAX_THR_RATES; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) tmp_group_tp_rate[j] = MCS_GROUP_RATES * group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) for (i = 0; i < MCS_GROUP_RATES; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) if (!(mi->supported[group] & BIT(i)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) index = MCS_GROUP_RATES * group + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) mrs = &mg->rates[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) mrs->retry_updated = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) minstrel_calc_rate_stats(mp, mrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) cur_prob = mrs->prob_avg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) if (minstrel_ht_get_tp_avg(mi, group, i, cur_prob) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) /* Find max throughput rate set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) if (group != MINSTREL_CCK_GROUP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) minstrel_ht_sort_best_tp_rates(mi, index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) tmp_mcs_tp_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) } else if (group == MINSTREL_CCK_GROUP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) minstrel_ht_sort_best_tp_rates(mi, index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) tmp_cck_tp_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) /* Find max throughput rate set within a group */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) minstrel_ht_sort_best_tp_rates(mi, index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) tmp_group_tp_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) /* Find max probability rate per group and global */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) minstrel_ht_set_best_prob_rate(mi, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) memcpy(mg->max_group_tp_rate, tmp_group_tp_rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) sizeof(mg->max_group_tp_rate));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) /* Assign new rate set per sta */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) minstrel_ht_assign_best_tp_rates(mi, tmp_mcs_tp_rate, tmp_cck_tp_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) memcpy(mi->max_tp_rate, tmp_mcs_tp_rate, sizeof(mi->max_tp_rate));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) /* Try to increase robustness of max_prob_rate*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) minstrel_ht_prob_rate_reduce_streams(mi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) /* try to sample all available rates during each interval */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) mi->sample_count *= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) if (mp->new_avg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) mi->sample_count /= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) if (sample)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) minstrel_ht_rate_sample_switch(mp, mi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) #ifdef CONFIG_MAC80211_DEBUGFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) /* use fixed index if set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) if (mp->fixed_rate_idx != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) for (i = 0; i < 4; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) mi->max_tp_rate[i] = mp->fixed_rate_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) mi->max_prob_rate = mp->fixed_rate_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) mi->sample_mode = MINSTREL_SAMPLE_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) /* Reset update timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) mi->last_stats_update = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) minstrel_ht_txstat_valid(struct minstrel_priv *mp, struct ieee80211_tx_rate *rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) if (rate->idx < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) if (!rate->count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) if (rate->flags & IEEE80211_TX_RC_MCS ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) rate->flags & IEEE80211_TX_RC_VHT_MCS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) return rate->idx == mp->cck_rates[0] ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) rate->idx == mp->cck_rates[1] ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) rate->idx == mp->cck_rates[2] ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) rate->idx == mp->cck_rates[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) minstrel_set_next_sample_idx(struct minstrel_ht_sta *mi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) struct minstrel_mcs_group_data *mg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) mi->sample_group++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) mi->sample_group %= ARRAY_SIZE(minstrel_mcs_groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) mg = &mi->groups[mi->sample_group];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) if (!mi->supported[mi->sample_group])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) if (++mg->index >= MCS_GROUP_RATES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) mg->index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) if (++mg->column >= ARRAY_SIZE(sample_table))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) mg->column = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) minstrel_downgrade_rate(struct minstrel_ht_sta *mi, u16 *idx, bool primary)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) int group, orig_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) orig_group = group = *idx / MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) while (group > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) group--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) if (!mi->supported[group])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) if (minstrel_mcs_groups[group].streams >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) minstrel_mcs_groups[orig_group].streams)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) if (primary)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) *idx = mi->groups[group].max_group_tp_rate[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) *idx = mi->groups[group].max_group_tp_rate[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) minstrel_aggr_check(struct ieee80211_sta *pubsta, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) u16 tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) if (skb_get_queue_mapping(skb) == IEEE80211_AC_VO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) if (unlikely(!ieee80211_is_data_qos(hdr->frame_control)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) if (unlikely(skb->protocol == cpu_to_be16(ETH_P_PAE)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) tid = ieee80211_get_tid(hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) if (likely(sta->ampdu_mlme.tid_tx[tid]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) ieee80211_start_tx_ba_session(pubsta, tid, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) minstrel_ht_tx_status(void *priv, struct ieee80211_supported_band *sband,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) void *priv_sta, struct ieee80211_tx_status *st)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) struct ieee80211_tx_info *info = st->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) struct minstrel_ht_sta_priv *msp = priv_sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) struct minstrel_ht_sta *mi = &msp->ht;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) struct ieee80211_tx_rate *ar = info->status.rates;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) struct minstrel_rate_stats *rate, *rate2, *rate_sample = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) struct minstrel_priv *mp = priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) u32 update_interval = mp->update_interval / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) bool last, update = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) bool sample_status = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) if (!msp->is_ht)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) return mac80211_minstrel.tx_status_ext(priv, sband,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) &msp->legacy, st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) /* This packet was aggregated but doesn't carry status info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) if ((info->flags & IEEE80211_TX_CTL_AMPDU) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) !(info->flags & IEEE80211_TX_STAT_AMPDU))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) if (!(info->flags & IEEE80211_TX_STAT_AMPDU)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) info->status.ampdu_ack_len =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) (info->flags & IEEE80211_TX_STAT_ACK ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) info->status.ampdu_len = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) mi->ampdu_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) mi->ampdu_len += info->status.ampdu_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) if (!mi->sample_wait && !mi->sample_tries && mi->sample_count > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) int avg_ampdu_len = minstrel_ht_avg_ampdu_len(mi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) mi->sample_wait = 16 + 2 * avg_ampdu_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) mi->sample_tries = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) mi->sample_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) if (info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) mi->sample_packets += info->status.ampdu_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) if (mi->sample_mode != MINSTREL_SAMPLE_IDLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) rate_sample = minstrel_get_ratestats(mi, mi->sample_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) last = !minstrel_ht_txstat_valid(mp, &ar[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) for (i = 0; !last; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) last = (i == IEEE80211_TX_MAX_RATES - 1) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) !minstrel_ht_txstat_valid(mp, &ar[i + 1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) rate = minstrel_ht_get_stats(mp, mi, &ar[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) if (rate == rate_sample)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) sample_status = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) if (last)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) rate->success += info->status.ampdu_ack_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) rate->attempts += ar[i].count * info->status.ampdu_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) switch (mi->sample_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) case MINSTREL_SAMPLE_IDLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) if (mp->new_avg &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) (mp->hw->max_rates > 1 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) mi->total_packets_cur < SAMPLE_SWITCH_THR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) update_interval /= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) case MINSTREL_SAMPLE_ACTIVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) if (!sample_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) mi->sample_mode = MINSTREL_SAMPLE_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) update = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) case MINSTREL_SAMPLE_PENDING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) if (sample_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) update = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) minstrel_ht_update_stats(mp, mi, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) if (mp->hw->max_rates > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) * check for sudden death of spatial multiplexing,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) * downgrade to a lower number of streams if necessary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) rate = minstrel_get_ratestats(mi, mi->max_tp_rate[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) if (rate->attempts > 30 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) rate->success < rate->attempts / 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) minstrel_downgrade_rate(mi, &mi->max_tp_rate[0], true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) update = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) rate2 = minstrel_get_ratestats(mi, mi->max_tp_rate[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) if (rate2->attempts > 30 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) rate2->success < rate2->attempts / 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) minstrel_downgrade_rate(mi, &mi->max_tp_rate[1], false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) update = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) if (time_after(jiffies, mi->last_stats_update + update_interval)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) update = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) minstrel_ht_update_stats(mp, mi, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) if (update)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) minstrel_ht_update_rates(mp, mi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) minstrel_calc_retransmit(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) struct minstrel_rate_stats *mrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) unsigned int tx_time, tx_time_rtscts, tx_time_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) unsigned int cw = mp->cw_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) unsigned int ctime = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) unsigned int t_slot = 9; /* FIXME */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) unsigned int ampdu_len = minstrel_ht_avg_ampdu_len(mi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) unsigned int overhead = 0, overhead_rtscts = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) mrs = minstrel_get_ratestats(mi, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) if (mrs->prob_avg < MINSTREL_FRAC(1, 10)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) mrs->retry_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) mrs->retry_count_rtscts = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) mrs->retry_count = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) mrs->retry_count_rtscts = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) mrs->retry_updated = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) tx_time_data = minstrel_get_duration(index) * ampdu_len / 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) /* Contention time for first 2 tries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) ctime = (t_slot * cw) >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) cw = min((cw << 1) | 1, mp->cw_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) ctime += (t_slot * cw) >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) cw = min((cw << 1) | 1, mp->cw_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) if (index / MCS_GROUP_RATES != MINSTREL_CCK_GROUP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) overhead = mi->overhead;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) overhead_rtscts = mi->overhead_rtscts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) /* Total TX time for data and Contention after first 2 tries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) tx_time = ctime + 2 * (overhead + tx_time_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) tx_time_rtscts = ctime + 2 * (overhead_rtscts + tx_time_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) /* See how many more tries we can fit inside segment size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) /* Contention time for this try */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) ctime = (t_slot * cw) >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) cw = min((cw << 1) | 1, mp->cw_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) /* Total TX time after this try */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) tx_time += ctime + overhead + tx_time_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) tx_time_rtscts += ctime + overhead_rtscts + tx_time_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) if (tx_time_rtscts < mp->segment_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) mrs->retry_count_rtscts++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) } while ((tx_time < mp->segment_size) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) (++mrs->retry_count < mp->max_retry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) minstrel_ht_set_rate(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) struct ieee80211_sta_rates *ratetbl, int offset, int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) const struct mcs_group *group = &minstrel_mcs_groups[index / MCS_GROUP_RATES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) struct minstrel_rate_stats *mrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) u8 idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) u16 flags = group->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) mrs = minstrel_get_ratestats(mi, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) if (!mrs->retry_updated)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) minstrel_calc_retransmit(mp, mi, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) if (mrs->prob_avg < MINSTREL_FRAC(20, 100) || !mrs->retry_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) ratetbl->rate[offset].count = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) ratetbl->rate[offset].count_rts = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) ratetbl->rate[offset].count_cts = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) ratetbl->rate[offset].count = mrs->retry_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) ratetbl->rate[offset].count_cts = mrs->retry_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) ratetbl->rate[offset].count_rts = mrs->retry_count_rtscts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) if (index / MCS_GROUP_RATES == MINSTREL_CCK_GROUP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) idx = mp->cck_rates[index % ARRAY_SIZE(mp->cck_rates)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) else if (flags & IEEE80211_TX_RC_VHT_MCS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) idx = ((group->streams - 1) << 4) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) ((index % MCS_GROUP_RATES) & 0xF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) idx = index % MCS_GROUP_RATES + (group->streams - 1) * 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) /* enable RTS/CTS if needed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) * - if station is in dynamic SMPS (and streams > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) * - for fallback rates, to increase chances of getting through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) if (offset > 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) (mi->sta->smps_mode == IEEE80211_SMPS_DYNAMIC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) group->streams > 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) ratetbl->rate[offset].count = ratetbl->rate[offset].count_rts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) flags |= IEEE80211_TX_RC_USE_RTS_CTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) ratetbl->rate[offset].idx = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) ratetbl->rate[offset].flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) minstrel_ht_get_prob_avg(struct minstrel_ht_sta *mi, int rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) int group = rate / MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) rate %= MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) return mi->groups[group].rates[rate].prob_avg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) minstrel_ht_get_max_amsdu_len(struct minstrel_ht_sta *mi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) int group = mi->max_prob_rate / MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) const struct mcs_group *g = &minstrel_mcs_groups[group];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) int rate = mi->max_prob_rate % MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) unsigned int duration;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) /* Disable A-MSDU if max_prob_rate is bad */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) if (mi->groups[group].rates[rate].prob_avg < MINSTREL_FRAC(50, 100))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) duration = g->duration[rate];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) duration <<= g->shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) /* If the rate is slower than single-stream MCS1, make A-MSDU limit small */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) if (duration > MCS_DURATION(1, 0, 52))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) return 500;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) * If the rate is slower than single-stream MCS4, limit A-MSDU to usual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) * data packet size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) if (duration > MCS_DURATION(1, 0, 104))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) return 1600;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) * If the rate is slower than single-stream MCS7, or if the max throughput
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) * rate success probability is less than 75%, limit A-MSDU to twice the usual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) * data packet size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) if (duration > MCS_DURATION(1, 0, 260) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) (minstrel_ht_get_prob_avg(mi, mi->max_tp_rate[0]) <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) MINSTREL_FRAC(75, 100)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) return 3200;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) * HT A-MPDU limits maximum MPDU size under BA agreement to 4095 bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) * Since aggregation sessions are started/stopped without txq flush, use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) * the limit here to avoid the complexity of having to de-aggregate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) * packets in the queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) if (!mi->sta->vht_cap.vht_supported)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) return IEEE80211_MAX_MPDU_LEN_HT_BA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) /* unlimited */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) minstrel_ht_update_rates(struct minstrel_priv *mp, struct minstrel_ht_sta *mi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) struct ieee80211_sta_rates *rates;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) u16 first_rate = mi->max_tp_rate[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) if (mi->sample_mode == MINSTREL_SAMPLE_ACTIVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) first_rate = mi->sample_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) rates = kzalloc(sizeof(*rates), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) if (!rates)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) /* Start with max_tp_rate[0] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) minstrel_ht_set_rate(mp, mi, rates, i++, first_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) if (mp->hw->max_rates >= 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) /* At least 3 tx rates supported, use max_tp_rate[1] next */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) minstrel_ht_set_rate(mp, mi, rates, i++, mi->max_tp_rate[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) if (mp->hw->max_rates >= 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) minstrel_ht_set_rate(mp, mi, rates, i++, mi->max_prob_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) mi->sta->max_rc_amsdu_len = minstrel_ht_get_max_amsdu_len(mi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) rates->rate[i].idx = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) rate_control_set_rates(mp->hw, mi->sta, rates);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) minstrel_get_sample_rate(struct minstrel_priv *mp, struct minstrel_ht_sta *mi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) struct minstrel_rate_stats *mrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) struct minstrel_mcs_group_data *mg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) unsigned int sample_dur, sample_group, cur_max_tp_streams;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) int tp_rate1, tp_rate2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) int sample_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) if (mp->hw->max_rates == 1 && mp->sample_switch &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) (mi->total_packets_cur >= SAMPLE_SWITCH_THR ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) mp->sample_switch == 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) if (mi->sample_wait > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) mi->sample_wait--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) if (!mi->sample_tries)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) sample_group = mi->sample_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) mg = &mi->groups[sample_group];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) sample_idx = sample_table[mg->column][mg->index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) minstrel_set_next_sample_idx(mi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) if (!(mi->supported[sample_group] & BIT(sample_idx)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) mrs = &mg->rates[sample_idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) sample_idx += sample_group * MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) /* Set tp_rate1, tp_rate2 to the highest / second highest max_tp_rate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) if (minstrel_get_duration(mi->max_tp_rate[0]) >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) minstrel_get_duration(mi->max_tp_rate[1])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) tp_rate1 = mi->max_tp_rate[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) tp_rate2 = mi->max_tp_rate[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) tp_rate1 = mi->max_tp_rate[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) tp_rate2 = mi->max_tp_rate[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) * Sampling might add some overhead (RTS, no aggregation)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) * to the frame. Hence, don't use sampling for the highest currently
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) * used highest throughput or probability rate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) if (sample_idx == mi->max_tp_rate[0] || sample_idx == mi->max_prob_rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) * Do not sample if the probability is already higher than 95%,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) * or if the rate is 3 times slower than the current max probability
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) * rate, to avoid wasting airtime.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) sample_dur = minstrel_get_duration(sample_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) if (mrs->prob_avg > MINSTREL_FRAC(95, 100) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) minstrel_get_duration(mi->max_prob_rate) * 3 < sample_dur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) * For devices with no configurable multi-rate retry, skip sampling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) * below the per-group max throughput rate, and only use one sampling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) * attempt per rate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) if (mp->hw->max_rates == 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) (minstrel_get_duration(mg->max_group_tp_rate[0]) < sample_dur ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) mrs->attempts))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) /* Skip already sampled slow rates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) if (sample_dur >= minstrel_get_duration(tp_rate1) && mrs->attempts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) * Make sure that lower rates get sampled only occasionally,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) * if the link is working perfectly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) cur_max_tp_streams = minstrel_mcs_groups[tp_rate1 /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) MCS_GROUP_RATES].streams;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) if (sample_dur >= minstrel_get_duration(tp_rate2) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) (cur_max_tp_streams - 1 <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) minstrel_mcs_groups[sample_group].streams ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) sample_dur >= minstrel_get_duration(mi->max_prob_rate))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) if (mrs->sample_skipped < 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) if (mi->sample_slow++ > 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) mi->sample_tries--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) return sample_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) minstrel_ht_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) struct ieee80211_tx_rate_control *txrc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) const struct mcs_group *sample_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) struct ieee80211_tx_info *info = IEEE80211_SKB_CB(txrc->skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) struct ieee80211_tx_rate *rate = &info->status.rates[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) struct minstrel_ht_sta_priv *msp = priv_sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) struct minstrel_ht_sta *mi = &msp->ht;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) struct minstrel_priv *mp = priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) int sample_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) if (!msp->is_ht)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) return mac80211_minstrel.get_rate(priv, sta, &msp->legacy, txrc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) if (!(info->flags & IEEE80211_TX_CTL_AMPDU) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) mi->max_prob_rate / MCS_GROUP_RATES != MINSTREL_CCK_GROUP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) minstrel_aggr_check(sta, txrc->skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) info->flags |= mi->tx_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) #ifdef CONFIG_MAC80211_DEBUGFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) if (mp->fixed_rate_idx != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) /* Don't use EAPOL frames for sampling on non-mrr hw */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) if (mp->hw->max_rates == 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) (info->control.flags & IEEE80211_TX_CTRL_PORT_CTRL_PROTO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) sample_idx = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) sample_idx = minstrel_get_sample_rate(mp, mi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) mi->total_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) /* wraparound */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) if (mi->total_packets == ~0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) mi->total_packets = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) mi->sample_packets = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) if (sample_idx < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) sample_group = &minstrel_mcs_groups[sample_idx / MCS_GROUP_RATES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) sample_idx %= MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) if (sample_group == &minstrel_mcs_groups[MINSTREL_CCK_GROUP] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) (sample_idx >= 4) != txrc->short_preamble)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) rate->count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) if (sample_group == &minstrel_mcs_groups[MINSTREL_CCK_GROUP]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) int idx = sample_idx % ARRAY_SIZE(mp->cck_rates);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) rate->idx = mp->cck_rates[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) } else if (sample_group->flags & IEEE80211_TX_RC_VHT_MCS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) ieee80211_rate_set_vht(rate, sample_idx % MCS_GROUP_RATES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) sample_group->streams);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) rate->idx = sample_idx + (sample_group->streams - 1) * 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) rate->flags = sample_group->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) minstrel_ht_update_cck(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) struct ieee80211_supported_band *sband,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) struct ieee80211_sta *sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) if (sband->band != NL80211_BAND_2GHZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) if (!ieee80211_hw_check(mp->hw, SUPPORTS_HT_CCK_RATES))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) mi->cck_supported = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) mi->cck_supported_short = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) for (i = 0; i < 4; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) if (!rate_supported(sta, sband->band, mp->cck_rates[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) mi->cck_supported |= BIT(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) if (sband->bitrates[i].flags & IEEE80211_RATE_SHORT_PREAMBLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) mi->cck_supported_short |= BIT(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) mi->supported[MINSTREL_CCK_GROUP] = mi->cck_supported;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) minstrel_ht_update_caps(void *priv, struct ieee80211_supported_band *sband,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) struct cfg80211_chan_def *chandef,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) struct ieee80211_sta *sta, void *priv_sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) struct minstrel_priv *mp = priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) struct minstrel_ht_sta_priv *msp = priv_sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) struct minstrel_ht_sta *mi = &msp->ht;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) struct ieee80211_mcs_info *mcs = &sta->ht_cap.mcs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) u16 ht_cap = sta->ht_cap.cap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) int use_vht;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) int n_supported = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) int ack_dur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) int stbc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) bool ldpc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) /* fall back to the old minstrel for legacy stations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) if (!sta->ht_cap.ht_supported)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) goto use_legacy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) BUILD_BUG_ON(ARRAY_SIZE(minstrel_mcs_groups) != MINSTREL_GROUPS_NB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) if (vht_cap->vht_supported)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) use_vht = vht_cap->vht_mcs.tx_mcs_map != cpu_to_le16(~0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) use_vht = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) msp->is_ht = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) memset(mi, 0, sizeof(*mi));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) mi->sta = sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) mi->last_stats_update = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) ack_dur = ieee80211_frame_duration(sband->band, 10, 60, 1, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) mi->overhead = ieee80211_frame_duration(sband->band, 0, 60, 1, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) mi->overhead += ack_dur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) mi->overhead_rtscts = mi->overhead + 2 * ack_dur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) mi->avg_ampdu_len = MINSTREL_FRAC(1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) /* When using MRR, sample more on the first attempt, without delay */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) if (mp->has_mrr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) mi->sample_count = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) mi->sample_wait = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) mi->sample_count = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) mi->sample_wait = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) mi->sample_tries = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) if (!use_vht) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) stbc = (ht_cap & IEEE80211_HT_CAP_RX_STBC) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) IEEE80211_HT_CAP_RX_STBC_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) ldpc = ht_cap & IEEE80211_HT_CAP_LDPC_CODING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) stbc = (vht_cap->cap & IEEE80211_VHT_CAP_RXSTBC_MASK) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) IEEE80211_VHT_CAP_RXSTBC_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) ldpc = vht_cap->cap & IEEE80211_VHT_CAP_RXLDPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) mi->tx_flags |= stbc << IEEE80211_TX_CTL_STBC_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) if (ldpc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) mi->tx_flags |= IEEE80211_TX_CTL_LDPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) for (i = 0; i < ARRAY_SIZE(mi->groups); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) u32 gflags = minstrel_mcs_groups[i].flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) int bw, nss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) mi->supported[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) if (i == MINSTREL_CCK_GROUP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) minstrel_ht_update_cck(mp, mi, sband, sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) if (gflags & IEEE80211_TX_RC_SHORT_GI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) if (gflags & IEEE80211_TX_RC_40_MHZ_WIDTH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) if (!(ht_cap & IEEE80211_HT_CAP_SGI_40))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) if (!(ht_cap & IEEE80211_HT_CAP_SGI_20))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) if (gflags & IEEE80211_TX_RC_40_MHZ_WIDTH &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) sta->bandwidth < IEEE80211_STA_RX_BW_40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) nss = minstrel_mcs_groups[i].streams;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) /* Mark MCS > 7 as unsupported if STA is in static SMPS mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) if (sta->smps_mode == IEEE80211_SMPS_STATIC && nss > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) /* HT rate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) if (gflags & IEEE80211_TX_RC_MCS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) if (use_vht && minstrel_vht_only)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) mi->supported[i] = mcs->rx_mask[nss - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) if (mi->supported[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) n_supported++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) /* VHT rate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) if (!vht_cap->vht_supported ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) WARN_ON(!(gflags & IEEE80211_TX_RC_VHT_MCS)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) WARN_ON(gflags & IEEE80211_TX_RC_160_MHZ_WIDTH))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) if (gflags & IEEE80211_TX_RC_80_MHZ_WIDTH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) if (sta->bandwidth < IEEE80211_STA_RX_BW_80 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) ((gflags & IEEE80211_TX_RC_SHORT_GI) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) !(vht_cap->cap & IEEE80211_VHT_CAP_SHORT_GI_80))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) if (gflags & IEEE80211_TX_RC_40_MHZ_WIDTH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) bw = BW_40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) else if (gflags & IEEE80211_TX_RC_80_MHZ_WIDTH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) bw = BW_80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) bw = BW_20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) mi->supported[i] = minstrel_get_valid_vht_rates(bw, nss,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) vht_cap->vht_mcs.tx_mcs_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) if (mi->supported[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) n_supported++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) if (!n_supported)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) goto use_legacy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) mi->supported[MINSTREL_CCK_GROUP] |= mi->cck_supported_short << 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) /* create an initial rate table with the lowest supported rates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) minstrel_ht_update_stats(mp, mi, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) minstrel_ht_update_rates(mp, mi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) use_legacy:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) msp->is_ht = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) memset(&msp->legacy, 0, sizeof(msp->legacy));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) msp->legacy.r = msp->ratelist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) msp->legacy.sample_table = msp->sample_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) return mac80211_minstrel.rate_init(priv, sband, chandef, sta,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) &msp->legacy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) minstrel_ht_rate_init(void *priv, struct ieee80211_supported_band *sband,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) struct cfg80211_chan_def *chandef,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) struct ieee80211_sta *sta, void *priv_sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) minstrel_ht_update_caps(priv, sband, chandef, sta, priv_sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) minstrel_ht_rate_update(void *priv, struct ieee80211_supported_band *sband,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) struct cfg80211_chan_def *chandef,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) struct ieee80211_sta *sta, void *priv_sta,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) u32 changed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) minstrel_ht_update_caps(priv, sband, chandef, sta, priv_sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) static void *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) minstrel_ht_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) struct ieee80211_supported_band *sband;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) struct minstrel_ht_sta_priv *msp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) struct minstrel_priv *mp = priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) struct ieee80211_hw *hw = mp->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) int max_rates = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) for (i = 0; i < NUM_NL80211_BANDS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) sband = hw->wiphy->bands[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) if (sband && sband->n_bitrates > max_rates)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) max_rates = sband->n_bitrates;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) msp = kzalloc(sizeof(*msp), gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) if (!msp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) msp->ratelist = kcalloc(max_rates, sizeof(struct minstrel_rate), gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) if (!msp->ratelist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) msp->sample_table = kmalloc_array(max_rates, SAMPLE_COLUMNS, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) if (!msp->sample_table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) goto error1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) return msp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) error1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) kfree(msp->ratelist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) kfree(msp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) minstrel_ht_free_sta(void *priv, struct ieee80211_sta *sta, void *priv_sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) struct minstrel_ht_sta_priv *msp = priv_sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) kfree(msp->sample_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) kfree(msp->ratelist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) kfree(msp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) minstrel_ht_init_cck_rates(struct minstrel_priv *mp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) static const int bitrates[4] = { 10, 20, 55, 110 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) struct ieee80211_supported_band *sband;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) u32 rate_flags = ieee80211_chandef_rate_flags(&mp->hw->conf.chandef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) sband = mp->hw->wiphy->bands[NL80211_BAND_2GHZ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) if (!sband)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) for (i = 0; i < sband->n_bitrates; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) struct ieee80211_rate *rate = &sband->bitrates[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) if (rate->flags & IEEE80211_RATE_ERP_G)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) for (j = 0; j < ARRAY_SIZE(bitrates); j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) if (rate->bitrate != bitrates[j])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) mp->cck_rates[j] = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) static void *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) minstrel_ht_alloc(struct ieee80211_hw *hw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) struct minstrel_priv *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) mp = kzalloc(sizeof(struct minstrel_priv), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) if (!mp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) mp->sample_switch = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) /* contention window settings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) * Just an approximation. Using the per-queue values would complicate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) * the calculations and is probably unnecessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) mp->cw_min = 15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) mp->cw_max = 1023;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) /* number of packets (in %) to use for sampling other rates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) * sample less often for non-mrr packets, because the overhead
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) * is much higher than with mrr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) mp->lookaround_rate = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) mp->lookaround_rate_mrr = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) /* maximum time that the hw is allowed to stay in one MRR segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) mp->segment_size = 6000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) if (hw->max_rate_tries > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) mp->max_retry = hw->max_rate_tries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) /* safe default, does not necessarily have to match hw properties */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) mp->max_retry = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) if (hw->max_rates >= 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) mp->has_mrr = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) mp->hw = hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) mp->update_interval = HZ / 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) mp->new_avg = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) minstrel_ht_init_cck_rates(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) return mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) #ifdef CONFIG_MAC80211_DEBUGFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) static void minstrel_ht_add_debugfs(struct ieee80211_hw *hw, void *priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) struct dentry *debugfsdir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) struct minstrel_priv *mp = priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) mp->fixed_rate_idx = (u32) -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) debugfs_create_u32("fixed_rate_idx", S_IRUGO | S_IWUGO, debugfsdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) &mp->fixed_rate_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) debugfs_create_u32("sample_switch", S_IRUGO | S_IWUSR, debugfsdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) &mp->sample_switch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) debugfs_create_bool("new_avg", S_IRUGO | S_IWUSR, debugfsdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) &mp->new_avg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) minstrel_ht_free(void *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) kfree(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) static u32 minstrel_ht_get_expected_throughput(void *priv_sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) struct minstrel_ht_sta_priv *msp = priv_sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) struct minstrel_ht_sta *mi = &msp->ht;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) int i, j, prob, tp_avg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) if (!msp->is_ht)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) return mac80211_minstrel.get_expected_throughput(priv_sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) i = mi->max_tp_rate[0] / MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) j = mi->max_tp_rate[0] % MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) prob = mi->groups[i].rates[j].prob_avg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) /* convert tp_avg from pkt per second in kbps */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) tp_avg = minstrel_ht_get_tp_avg(mi, i, j, prob) * 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) tp_avg = tp_avg * AVG_PKT_SIZE * 8 / 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) return tp_avg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) static const struct rate_control_ops mac80211_minstrel_ht = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) .name = "minstrel_ht",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) .tx_status_ext = minstrel_ht_tx_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) .get_rate = minstrel_ht_get_rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) .rate_init = minstrel_ht_rate_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) .rate_update = minstrel_ht_rate_update,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) .alloc_sta = minstrel_ht_alloc_sta,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) .free_sta = minstrel_ht_free_sta,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) .alloc = minstrel_ht_alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) .free = minstrel_ht_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) #ifdef CONFIG_MAC80211_DEBUGFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) .add_debugfs = minstrel_ht_add_debugfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) .add_sta_debugfs = minstrel_ht_add_sta_debugfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) .get_expected_throughput = minstrel_ht_get_expected_throughput,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) static void __init init_sample_table(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) int col, i, new_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) u8 rnd[MCS_GROUP_RATES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) memset(sample_table, 0xff, sizeof(sample_table));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) for (col = 0; col < SAMPLE_COLUMNS; col++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) prandom_bytes(rnd, sizeof(rnd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) for (i = 0; i < MCS_GROUP_RATES; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) new_idx = (i + rnd[i]) % MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) while (sample_table[col][new_idx] != 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) new_idx = (new_idx + 1) % MCS_GROUP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) sample_table[col][new_idx] = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) int __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) rc80211_minstrel_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) init_sample_table();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) return ieee80211_rate_control_register(&mac80211_minstrel_ht);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) rc80211_minstrel_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) ieee80211_rate_control_unregister(&mac80211_minstrel_ht);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) }