diff mbox series

[7/8] mt76: mt7915: add support for tx-overrides

Message ID 20211118164549.3863-7-greearb@candelatech.com (mailing list archive)
State Rejected
Delegated to: Felix Fietkau
Headers show
Series [1/8] mt76: mt7915: cache sgi in wcid. | expand

Commit Message

Ben Greear Nov. 18, 2021, 4:45 p.m. UTC
From: Ben Greear <greearb@candelatech.com>

Allow setting fix rate on transmit without using full testmode
logic.

txpower, dynbw, retry count is not currently supported.
And, probably later need additional logic to not apply this
txo to non-data frames and to smaller frames, to allow
ARP and such to go through while also forcing test data frames
to arbitrary tx-rates (rates which very well may not be
received by peer.)

Signed-off-by: Ben Greear <greearb@candelatech.com>
---
 drivers/net/wireless/mediatek/mt76/mt76.h     |   4 +
 .../wireless/mediatek/mt76/mt7915/debugfs.c   | 224 ++++++++++++++++++
 .../net/wireless/mediatek/mt76/mt7915/mac.c   |  98 ++++++--
 .../wireless/mediatek/mt76/mt7915/mt7915.h    |   2 +
 4 files changed, 302 insertions(+), 26 deletions(-)

Comments

kernel test robot Nov. 19, 2021, 7:16 a.m. UTC | #1
Hi,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on kvalo-wireless-drivers-next/master]
[also build test ERROR on v5.16-rc1 next-20211118]
[cannot apply to kvalo-wireless-drivers/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/greearb-candelatech-com/mt76-mt7915-cache-sgi-in-wcid/20211119-005421
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kvalo/wireless-drivers-next.git master
config: microblaze-buildonly-randconfig-r005-20211119 (attached as .config)
compiler: microblaze-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/c742cd1ffffaeff7ab79835466b08fd5616cdce3
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review greearb-candelatech-com/mt76-mt7915-cache-sgi-in-wcid/20211119-005421
        git checkout c742cd1ffffaeff7ab79835466b08fd5616cdce3
        # save the attached .config to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=microblaze SHELL=/bin/bash drivers/net/wireless/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/net/wireless/mediatek/mt76/mt7915/mac.c: In function 'mt7915_mac_write_txwi_tm':
>> drivers/net/wireless/mediatek/mt76/mt7915/mac.c:778:37: error: 'struct mt76_phy' has no member named 'test'
     778 |                 if (skb != phy->mt76->test.tx_skb)
         |                                     ^~
   drivers/net/wireless/mediatek/mt76/mt7915/mac.c:780:32: error: 'struct mt76_phy' has no member named 'test'
     780 |                 td = &phy->mt76->test;
         |                                ^~
   In file included from include/linux/byteorder/little_endian.h:5,
                    from arch/microblaze/include/uapi/asm/byteorder.h:6,
                    from include/asm-generic/bitops/le.h:7,
                    from include/asm-generic/bitops.h:36,
                    from ./arch/microblaze/include/generated/asm/bitops.h:1,
                    from include/linux/bitops.h:33,
                    from include/linux/kernel.h:12,
                    from include/linux/skbuff.h:13,
                    from include/linux/if_ether.h:19,
                    from include/linux/etherdevice.h:20,
                    from drivers/net/wireless/mediatek/mt76/mt7915/mac.c:4:
>> drivers/net/wireless/mediatek/mt76/mt7915/mac.c:909:54: error: 'struct mt7915_phy' has no member named 'test'
     909 |                                                   phy->test.spe_idx));
         |                                                      ^~
   include/uapi/linux/byteorder/little_endian.h:33:51: note: in definition of macro '__cpu_to_le32'
      33 | #define __cpu_to_le32(x) ((__force __le32)(__u32)(x))
         |                                                   ^
   include/linux/compiler_types.h:310:9: note: in expansion of macro '__compiletime_assert'
     310 |         __compiletime_assert(condition, msg, prefix, suffix)
         |         ^~~~~~~~~~~~~~~~~~~~
   include/linux/compiler_types.h:322:9: note: in expansion of macro '_compiletime_assert'
     322 |         _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
         |         ^~~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
      39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
         |                                     ^~~~~~~~~~~~~~~~~~
   include/linux/bitfield.h:49:17: note: in expansion of macro 'BUILD_BUG_ON_MSG'
      49 |                 BUILD_BUG_ON_MSG(__builtin_constant_p(_val) ?           \
         |                 ^~~~~~~~~~~~~~~~
   include/linux/bitfield.h:94:17: note: in expansion of macro '__BF_FIELD_CHECK'
      94 |                 __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: ");    \
         |                 ^~~~~~~~~~~~~~~~
   drivers/net/wireless/mediatek/mt76/mt7915/mac.c:908:40: note: in expansion of macro 'FIELD_PREP'
     908 |                 txwi[7] |= cpu_to_le32(FIELD_PREP(MT_TXD7_SPE_IDX,
         |                                        ^~~~~~~~~~
>> drivers/net/wireless/mediatek/mt76/mt7915/mac.c:909:54: error: 'struct mt7915_phy' has no member named 'test'
     909 |                                                   phy->test.spe_idx));
         |                                                      ^~
   include/uapi/linux/byteorder/little_endian.h:33:51: note: in definition of macro '__cpu_to_le32'
      33 | #define __cpu_to_le32(x) ((__force __le32)(__u32)(x))
         |                                                   ^
   include/linux/compiler_types.h:310:9: note: in expansion of macro '__compiletime_assert'
     310 |         __compiletime_assert(condition, msg, prefix, suffix)
         |         ^~~~~~~~~~~~~~~~~~~~
   include/linux/compiler_types.h:322:9: note: in expansion of macro '_compiletime_assert'
     322 |         _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
         |         ^~~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
      39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
         |                                     ^~~~~~~~~~~~~~~~~~
   include/linux/bitfield.h:49:17: note: in expansion of macro 'BUILD_BUG_ON_MSG'
      49 |                 BUILD_BUG_ON_MSG(__builtin_constant_p(_val) ?           \
         |                 ^~~~~~~~~~~~~~~~
   include/linux/bitfield.h:94:17: note: in expansion of macro '__BF_FIELD_CHECK'
      94 |                 __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: ");    \
         |                 ^~~~~~~~~~~~~~~~
   drivers/net/wireless/mediatek/mt76/mt7915/mac.c:908:40: note: in expansion of macro 'FIELD_PREP'
     908 |                 txwi[7] |= cpu_to_le32(FIELD_PREP(MT_TXD7_SPE_IDX,
         |                                        ^~~~~~~~~~
>> drivers/net/wireless/mediatek/mt76/mt7915/mac.c:909:54: error: 'struct mt7915_phy' has no member named 'test'
     909 |                                                   phy->test.spe_idx));
         |                                                      ^~
   include/uapi/linux/byteorder/little_endian.h:33:51: note: in definition of macro '__cpu_to_le32'
      33 | #define __cpu_to_le32(x) ((__force __le32)(__u32)(x))
         |                                                   ^
   drivers/net/wireless/mediatek/mt76/mt7915/mac.c:908:40: note: in expansion of macro 'FIELD_PREP'
     908 |                 txwi[7] |= cpu_to_le32(FIELD_PREP(MT_TXD7_SPE_IDX,
         |                                        ^~~~~~~~~~
   At top level:
   drivers/net/wireless/mediatek/mt76/mt7915/mac.c:760:1: warning: 'mt7915_mac_write_txwi_tm' defined but not used [-Wunused-function]
     760 | mt7915_mac_write_txwi_tm(struct mt7915_phy *phy, struct mt76_wcid *wcid, __le32 *txwi,
         | ^~~~~~~~~~~~~~~~~~~~~~~~


vim +778 drivers/net/wireless/mediatek/mt76/mt7915/mac.c

5d8a83f0994134 Shayne Chen 2020-10-22  758  
aadf09537c575d Shayne Chen 2020-10-22  759  static void
c742cd1ffffaef Ben Greear  2021-11-18  760  mt7915_mac_write_txwi_tm(struct mt7915_phy *phy, struct mt76_wcid *wcid, __le32 *txwi,
c918c74d06457e Shayne Chen 2020-12-04  761  			 struct sk_buff *skb)
aadf09537c575d Shayne Chen 2020-10-22  762  {
c742cd1ffffaef Ben Greear  2021-11-18  763  	struct mt76_testmode_data *td;
cc91747be98f2a Shayne Chen 2021-04-12  764  	const struct ieee80211_rate *r;
c742cd1ffffaef Ben Greear  2021-11-18  765  	struct mt7915_sta *msta;
c742cd1ffffaef Ben Greear  2021-11-18  766  	u8 bw, mode, nss;
c742cd1ffffaef Ben Greear  2021-11-18  767  	u8 rate_idx;
aadf09537c575d Shayne Chen 2020-10-22  768  	u16 rateval = 0;
aadf09537c575d Shayne Chen 2020-10-22  769  	u32 val;
cc91747be98f2a Shayne Chen 2021-04-12  770  	bool cck = false;
cc91747be98f2a Shayne Chen 2021-04-12  771  	int band;
aadf09537c575d Shayne Chen 2020-10-22  772  
c742cd1ffffaef Ben Greear  2021-11-18  773  	msta = container_of(wcid, struct mt7915_sta, wcid);
c742cd1ffffaef Ben Greear  2021-11-18  774  
c742cd1ffffaef Ben Greear  2021-11-18  775  	if (msta->test.txo_active) {
c742cd1ffffaef Ben Greear  2021-11-18  776  		td = &msta->test;
c742cd1ffffaef Ben Greear  2021-11-18  777  	} else {
c918c74d06457e Shayne Chen 2020-12-04 @778  		if (skb != phy->mt76->test.tx_skb)
aadf09537c575d Shayne Chen 2020-10-22  779  			return;
c742cd1ffffaef Ben Greear  2021-11-18  780  		td = &phy->mt76->test;
c742cd1ffffaef Ben Greear  2021-11-18  781  	}
c742cd1ffffaef Ben Greear  2021-11-18  782  
c742cd1ffffaef Ben Greear  2021-11-18  783  	nss = td->tx_rate_nss;
c742cd1ffffaef Ben Greear  2021-11-18  784  	rate_idx = td->tx_rate_idx;
aadf09537c575d Shayne Chen 2020-10-22  785  
aadf09537c575d Shayne Chen 2020-10-22  786  	switch (td->tx_rate_mode) {
aadf09537c575d Shayne Chen 2020-10-22  787  	case MT76_TM_TX_MODE_HT:
aadf09537c575d Shayne Chen 2020-10-22  788  		nss = 1 + (rate_idx >> 3);
aadf09537c575d Shayne Chen 2020-10-22  789  		mode = MT_PHY_TYPE_HT;
aadf09537c575d Shayne Chen 2020-10-22  790  		break;
aadf09537c575d Shayne Chen 2020-10-22  791  	case MT76_TM_TX_MODE_VHT:
aadf09537c575d Shayne Chen 2020-10-22  792  		mode = MT_PHY_TYPE_VHT;
aadf09537c575d Shayne Chen 2020-10-22  793  		break;
aadf09537c575d Shayne Chen 2020-10-22  794  	case MT76_TM_TX_MODE_HE_SU:
aadf09537c575d Shayne Chen 2020-10-22  795  		mode = MT_PHY_TYPE_HE_SU;
aadf09537c575d Shayne Chen 2020-10-22  796  		break;
aadf09537c575d Shayne Chen 2020-10-22  797  	case MT76_TM_TX_MODE_HE_EXT_SU:
aadf09537c575d Shayne Chen 2020-10-22  798  		mode = MT_PHY_TYPE_HE_EXT_SU;
aadf09537c575d Shayne Chen 2020-10-22  799  		break;
aadf09537c575d Shayne Chen 2020-10-22  800  	case MT76_TM_TX_MODE_HE_TB:
aadf09537c575d Shayne Chen 2020-10-22  801  		mode = MT_PHY_TYPE_HE_TB;
aadf09537c575d Shayne Chen 2020-10-22  802  		break;
aadf09537c575d Shayne Chen 2020-10-22  803  	case MT76_TM_TX_MODE_HE_MU:
aadf09537c575d Shayne Chen 2020-10-22  804  		mode = MT_PHY_TYPE_HE_MU;
aadf09537c575d Shayne Chen 2020-10-22  805  		break;
cc91747be98f2a Shayne Chen 2021-04-12  806  	case MT76_TM_TX_MODE_CCK:
cc91747be98f2a Shayne Chen 2021-04-12  807  		cck = true;
cc91747be98f2a Shayne Chen 2021-04-12  808  		fallthrough;
aadf09537c575d Shayne Chen 2020-10-22  809  	case MT76_TM_TX_MODE_OFDM:
cc91747be98f2a Shayne Chen 2021-04-12  810  		band = phy->mt76->chandef.chan->band;
cc91747be98f2a Shayne Chen 2021-04-12  811  		if (band == NL80211_BAND_2GHZ && !cck)
cc91747be98f2a Shayne Chen 2021-04-12  812  			rate_idx += 4;
cc91747be98f2a Shayne Chen 2021-04-12  813  
cc91747be98f2a Shayne Chen 2021-04-12  814  		r = &phy->mt76->hw->wiphy->bands[band]->bitrates[rate_idx];
cc91747be98f2a Shayne Chen 2021-04-12  815  		val = cck ? r->hw_value_short : r->hw_value;
cc91747be98f2a Shayne Chen 2021-04-12  816  
cc91747be98f2a Shayne Chen 2021-04-12  817  		mode = val >> 8;
cc91747be98f2a Shayne Chen 2021-04-12  818  		rate_idx = val & 0xff;
cc91747be98f2a Shayne Chen 2021-04-12  819  		break;
aadf09537c575d Shayne Chen 2020-10-22  820  	default:
aadf09537c575d Shayne Chen 2020-10-22  821  		mode = MT_PHY_TYPE_OFDM;
aadf09537c575d Shayne Chen 2020-10-22  822  		break;
aadf09537c575d Shayne Chen 2020-10-22  823  	}
aadf09537c575d Shayne Chen 2020-10-22  824  
c742cd1ffffaef Ben Greear  2021-11-18  825  	if (msta->test.txo_active) {
c742cd1ffffaef Ben Greear  2021-11-18  826  		bw = td->txbw;
c742cd1ffffaef Ben Greear  2021-11-18  827  	} else {
c918c74d06457e Shayne Chen 2020-12-04  828  		switch (phy->mt76->chandef.width) {
aadf09537c575d Shayne Chen 2020-10-22  829  		case NL80211_CHAN_WIDTH_40:
aadf09537c575d Shayne Chen 2020-10-22  830  			bw = 1;
aadf09537c575d Shayne Chen 2020-10-22  831  			break;
aadf09537c575d Shayne Chen 2020-10-22  832  		case NL80211_CHAN_WIDTH_80:
aadf09537c575d Shayne Chen 2020-10-22  833  			bw = 2;
aadf09537c575d Shayne Chen 2020-10-22  834  			break;
aadf09537c575d Shayne Chen 2020-10-22  835  		case NL80211_CHAN_WIDTH_80P80:
aadf09537c575d Shayne Chen 2020-10-22  836  		case NL80211_CHAN_WIDTH_160:
aadf09537c575d Shayne Chen 2020-10-22  837  			bw = 3;
aadf09537c575d Shayne Chen 2020-10-22  838  			break;
aadf09537c575d Shayne Chen 2020-10-22  839  		default:
aadf09537c575d Shayne Chen 2020-10-22  840  			bw = 0;
aadf09537c575d Shayne Chen 2020-10-22  841  			break;
aadf09537c575d Shayne Chen 2020-10-22  842  		}
c742cd1ffffaef Ben Greear  2021-11-18  843  	}
aadf09537c575d Shayne Chen 2020-10-22  844  
aadf09537c575d Shayne Chen 2020-10-22  845  	if (td->tx_rate_stbc && nss == 1) {
aadf09537c575d Shayne Chen 2020-10-22  846  		nss++;
aadf09537c575d Shayne Chen 2020-10-22  847  		rateval |= MT_TX_RATE_STBC;
aadf09537c575d Shayne Chen 2020-10-22  848  	}
aadf09537c575d Shayne Chen 2020-10-22  849  
aadf09537c575d Shayne Chen 2020-10-22  850  	rateval |= FIELD_PREP(MT_TX_RATE_IDX, rate_idx) |
aadf09537c575d Shayne Chen 2020-10-22  851  		   FIELD_PREP(MT_TX_RATE_MODE, mode) |
aadf09537c575d Shayne Chen 2020-10-22  852  		   FIELD_PREP(MT_TX_RATE_NSS, nss - 1);
aadf09537c575d Shayne Chen 2020-10-22  853  
c742cd1ffffaef Ben Greear  2021-11-18  854  	/* TODO:  Support per-skb txpower, p.15 of txpower doc, DW2 29:24. */
aadf09537c575d Shayne Chen 2020-10-22  855  	txwi[2] |= cpu_to_le32(MT_TXD2_FIX_RATE);
aadf09537c575d Shayne Chen 2020-10-22  856  
c742cd1ffffaef Ben Greear  2021-11-18  857  	/* Looks like this sets tx attempt to exactly 1.
c742cd1ffffaef Ben Greear  2021-11-18  858  	 * TODO:  Use td->tx_xmit_count, if in txo mode.
c742cd1ffffaef Ben Greear  2021-11-18  859  	 */
aadf09537c575d Shayne Chen 2020-10-22  860  	le32p_replace_bits(&txwi[3], 1, MT_TXD3_REM_TX_COUNT);
aadf09537c575d Shayne Chen 2020-10-22  861  	if (td->tx_rate_mode < MT76_TM_TX_MODE_HT)
aadf09537c575d Shayne Chen 2020-10-22  862  		txwi[3] |= cpu_to_le32(MT_TXD3_BA_DISABLE);
aadf09537c575d Shayne Chen 2020-10-22  863  
c742cd1ffffaef Ben Greear  2021-11-18  864  	/* TODO:  Take tx_dynbw into account in txo mode. */
aadf09537c575d Shayne Chen 2020-10-22  865  	val = MT_TXD6_FIXED_BW |
aadf09537c575d Shayne Chen 2020-10-22  866  	      FIELD_PREP(MT_TXD6_BW, bw) |
aadf09537c575d Shayne Chen 2020-10-22  867  	      FIELD_PREP(MT_TXD6_TX_RATE, rateval) |
aadf09537c575d Shayne Chen 2020-10-22  868  	      FIELD_PREP(MT_TXD6_SGI, td->tx_rate_sgi);
aadf09537c575d Shayne Chen 2020-10-22  869  
aadf09537c575d Shayne Chen 2020-10-22  870  	/* for HE_SU/HE_EXT_SU PPDU
aadf09537c575d Shayne Chen 2020-10-22  871  	 * - 1x, 2x, 4x LTF + 0.8us GI
aadf09537c575d Shayne Chen 2020-10-22  872  	 * - 2x LTF + 1.6us GI, 4x LTF + 3.2us GI
aadf09537c575d Shayne Chen 2020-10-22  873  	 * for HE_MU PPDU
aadf09537c575d Shayne Chen 2020-10-22  874  	 * - 2x, 4x LTF + 0.8us GI
aadf09537c575d Shayne Chen 2020-10-22  875  	 * - 2x LTF + 1.6us GI, 4x LTF + 3.2us GI
aadf09537c575d Shayne Chen 2020-10-22  876  	 * for HE_TB PPDU
aadf09537c575d Shayne Chen 2020-10-22  877  	 * - 1x, 2x LTF + 1.6us GI
aadf09537c575d Shayne Chen 2020-10-22  878  	 * - 4x LTF + 3.2us GI
aadf09537c575d Shayne Chen 2020-10-22  879  	 */
aadf09537c575d Shayne Chen 2020-10-22  880  	if (mode >= MT_PHY_TYPE_HE_SU)
aadf09537c575d Shayne Chen 2020-10-22  881  		val |= FIELD_PREP(MT_TXD6_HELTF, td->tx_ltf);
aadf09537c575d Shayne Chen 2020-10-22  882  
cc91747be98f2a Shayne Chen 2021-04-12  883  	if (td->tx_rate_ldpc || (bw > 0 && mode >= MT_PHY_TYPE_HE_SU))
aadf09537c575d Shayne Chen 2020-10-22  884  		val |= MT_TXD6_LDPC;
aadf09537c575d Shayne Chen 2020-10-22  885  
cc91747be98f2a Shayne Chen 2021-04-12  886  	txwi[3] &= ~cpu_to_le32(MT_TXD3_SN_VALID);
aadf09537c575d Shayne Chen 2020-10-22  887  	txwi[6] |= cpu_to_le32(val);
c742cd1ffffaef Ben Greear  2021-11-18  888  
c742cd1ffffaef Ben Greear  2021-11-18  889  	if (msta->test.txo_active) {
c742cd1ffffaef Ben Greear  2021-11-18  890  		/* see mt7915_tm_set_tx_frames */
c742cd1ffffaef Ben Greear  2021-11-18  891  		static const u8 spe_idx_map[] = {0, 0, 1, 0, 3, 2, 4, 0,
c742cd1ffffaef Ben Greear  2021-11-18  892  						 9, 8, 6, 10, 16, 12, 18, 0};
c742cd1ffffaef Ben Greear  2021-11-18  893  		u32 spe_idx;
c742cd1ffffaef Ben Greear  2021-11-18  894  
c742cd1ffffaef Ben Greear  2021-11-18  895  		if (td->tx_spe_idx) {
c742cd1ffffaef Ben Greear  2021-11-18  896  			spe_idx = td->tx_spe_idx;
c742cd1ffffaef Ben Greear  2021-11-18  897  		} else {
c742cd1ffffaef Ben Greear  2021-11-18  898  			u8 tx_ant = td->tx_antenna_mask;
c742cd1ffffaef Ben Greear  2021-11-18  899  
c742cd1ffffaef Ben Greear  2021-11-18  900  			if (!tx_ant) {
c742cd1ffffaef Ben Greear  2021-11-18  901  				/* use antenna mask that matches our nss */
c742cd1ffffaef Ben Greear  2021-11-18  902  				tx_ant = GENMASK(nss - 1, 0);
c742cd1ffffaef Ben Greear  2021-11-18  903  			}
c742cd1ffffaef Ben Greear  2021-11-18  904  			spe_idx = spe_idx_map[tx_ant];
c742cd1ffffaef Ben Greear  2021-11-18  905  		}
c742cd1ffffaef Ben Greear  2021-11-18  906  		txwi[7] |= cpu_to_le32(FIELD_PREP(MT_TXD7_SPE_IDX, spe_idx));
c742cd1ffffaef Ben Greear  2021-11-18  907  	} else {
aadf09537c575d Shayne Chen 2020-10-22  908  		txwi[7] |= cpu_to_le32(FIELD_PREP(MT_TXD7_SPE_IDX,
78fc30a21cf117 Shayne Chen 2020-12-04 @909  						  phy->test.spe_idx));
c742cd1ffffaef Ben Greear  2021-11-18  910  	}
aadf09537c575d Shayne Chen 2020-10-22  911  }
aadf09537c575d Shayne Chen 2020-10-22  912  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
index 5a431b39d5c1..7bcdfef3c983 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -577,6 +577,7 @@  struct mt76_testmode_ops {
 
 struct mt76_testmode_data {
 	enum mt76_testmode_state state;
+	u8 txo_active; /* tx overrides are active */
 
 	u32 param_set[DIV_ROUND_UP(NUM_MT76_TM_ATTRS, 32)];
 	struct sk_buff *tx_skb;
@@ -591,6 +592,9 @@  struct mt76_testmode_data {
 	u8 tx_rate_ldpc;
 	u8 tx_rate_stbc;
 	u8 tx_ltf;
+	u8 txbw; /* specify TX bandwidth: 0 20Mhz, 1 40Mhz, 2 80Mhz, 3 160Mhz */
+	u8 tx_xmit_count; /* 0 means no-ack, 1 means one transmit, etc */
+	u8 tx_dynbw; /* 0:  dynamic bw disabled, 1: dynamic bw enabled */
 
 	u8 tx_antenna_mask;
 	u8 tx_spe_idx;
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c
index c5ed02cd2afc..e3f6cd18e30a 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c
@@ -190,6 +190,228 @@  mt7915_fw_util_wa_show(struct seq_file *file, void *data)
 
 DEFINE_SHOW_ATTRIBUTE(mt7915_fw_util_wa);
 
+struct mt7915_txo_worker_info {
+	char* buf;
+	int sofar;
+	int size;
+};
+
+static void mt7915_txo_worker(void *wi_data, struct ieee80211_sta *sta)
+{
+	struct mt7915_txo_worker_info *wi = wi_data;
+	struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv;
+	struct mt76_testmode_data *td = &msta->test;
+	struct ieee80211_vif *vif;
+	struct wireless_dev *wdev;
+
+	if (wi->sofar >= wi->size)
+		return; /* buffer is full */
+
+	vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);
+	wdev = ieee80211_vif_to_wdev(vif);
+
+	wi->sofar += scnprintf(wi->buf + wi->sofar, wi->size - wi->sofar,
+			       "vdev (%s) active=%d tpc=%d sgi=%d mcs=%d nss=%d"
+			       " pream=%d retries=%d dynbw=%d bw=%d\n",
+			       wdev->netdev->name,
+			       td->txo_active, td->tx_power[0],
+			       td->tx_rate_sgi, td->tx_rate_idx,
+			       td->tx_rate_nss, td->tx_rate_mode,
+			       td->tx_xmit_count, td->tx_dynbw,
+			       td->txbw);
+}
+
+static ssize_t mt7915_read_set_rate_override(struct file *file,
+					     char __user *user_buf,
+					     size_t count, loff_t *ppos)
+{
+	struct mt7915_dev *dev = file->private_data;
+        struct ieee80211_hw *hw = dev->mphy.hw;
+	char *buf2;
+	int size = 8000;
+	int rv, sofar;
+	struct mt7915_txo_worker_info wi;
+	const char buf[] =
+		"This allows specify specif tx rate parameters for all DATA"
+		" frames on a vdev\n"
+		"To set a value, you specify the dev-name and key-value pairs:\n"
+		"tpc=10 sgi=1 mcs=x nss=x pream=x retries=x dynbw=0|1 bw=x enable=0|1\n"
+		"pream: 0=cck, 1=ofdm, 2=HT, 3=VHT, 4=HE_SU\n"
+		"cck-mcs: 0=1Mbps, 1=2Mbps, 3=5.5Mbps, 3=11Mbps\n"
+		"ofdm-mcs: 0=6Mbps, 1=9Mbps, 2=12Mbps, 3=18Mbps, 4=24Mbps, 5=36Mbps,"
+		" 6=48Mbps, 7=54Mbps\n"
+		"tpc is not implemented currently, bw is 0-3 for 20-160\n"
+		" For example, wlan0:\n"
+		"echo \"wlan0 tpc=255 sgi=1 mcs=0 nss=1 pream=3 retries=1 dynbw=0 bw=0"
+		" active=1\" > ...mt76/set_rate_override\n";
+
+	buf2 = kzalloc(size, GFP_KERNEL);
+	if (!buf2)
+		return -ENOMEM;
+	strcpy(buf2, buf);
+	sofar = strlen(buf2);
+
+	wi.sofar = sofar;
+	wi.buf = buf2;
+	wi.size = size;
+
+	ieee80211_iterate_stations_atomic(hw, mt7915_txo_worker, &wi);
+
+	rv = simple_read_from_buffer(user_buf, count, ppos, buf2, wi.sofar);
+	kfree(buf2);
+	return rv;
+}
+
+/* Set the rates for specific types of traffic.
+ */
+static ssize_t mt7915_write_set_rate_override(struct file *file,
+					      const char __user *user_buf,
+					      size_t count, loff_t *ppos)
+{
+	struct mt7915_dev *dev = file->private_data;
+	struct mt7915_sta *msta;
+	struct ieee80211_vif *vif;
+	struct mt76_testmode_data *td = NULL;
+	struct wireless_dev *wdev;
+	struct mt76_wcid *wcid;
+	struct mt76_phy *mphy = &dev->mt76.phy;
+	char buf[180];
+	char tmp[20];
+	char *tok;
+	int ret, i, j;
+	unsigned int vdev_id = 0xFFFF;
+	char *bufptr = buf;
+	long rc;
+	char dev_name_match[IFNAMSIZ + 2];
+
+	memset(buf, 0, sizeof(buf));
+
+	simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
+
+	/* make sure that buf is null terminated */
+	buf[sizeof(buf) - 1] = 0;
+
+	/* drop the possible '\n' from the end */
+	if (buf[count - 1] == '\n')
+		buf[count - 1] = 0;
+
+	mutex_lock(&mphy->dev->mutex);
+
+	/* Ignore empty lines, 'echo' appends them sometimes at least. */
+	if (buf[0] == 0) {
+		ret = count;
+		goto exit;
+	}
+
+	/* String starts with vdev name, ie 'wlan0'  Find the proper vif that
+	 * matches the name.
+	 */
+	for (i = 0; i < ARRAY_SIZE(dev->mt76.wcid_mask); i++) {
+		u32 mask = dev->mt76.wcid_mask[i];
+		u32 phy_mask = dev->mt76.wcid_phy_mask[i];
+
+		if (!mask)
+			continue;
+
+		for (j = i * 32; mask; j++, mask >>= 1, phy_mask >>= 1) {
+			if (!(mask & 1))
+				continue;
+
+			wcid = rcu_dereference(dev->mt76.wcid[j]);
+			if (!wcid)
+				continue;
+
+			msta = container_of(wcid, struct mt7915_sta, wcid);
+
+			vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);
+
+			wdev = ieee80211_vif_to_wdev(vif);
+
+			if (!wdev)
+				continue;
+
+			snprintf(dev_name_match, sizeof(dev_name_match) - 1, "%s ",
+				 wdev->netdev->name);
+
+			if (strncmp(dev_name_match, buf, strlen(dev_name_match)) == 0) {
+				vdev_id = j;
+				td = &msta->test;
+				bufptr = buf + strlen(dev_name_match) - 1;
+				break;
+			}
+		}
+	}
+
+	if (vdev_id == 0xFFFF) {
+		if (strstr(buf, "active=0")) {
+			/* Ignore, we are disabling it anyway */
+			ret = count;
+			goto exit;
+		} else {
+			dev_info(dev->mt76.dev,
+				 "mt7915: set-rate-override, unknown netdev name: %s\n", buf);
+		}
+		ret = -EINVAL;
+		goto exit;
+	}
+
+#define MT7915_PARSE_LTOK(a, b)					\
+	do {								\
+		tok = strstr(bufptr, " " #a "=");			\
+		if (tok) {						\
+			char *tspace;					\
+			tok += 1; /* move past initial space */		\
+			strncpy(tmp, tok + strlen(#a "="), sizeof(tmp) - 1); \
+			tmp[sizeof(tmp) - 1] = 0;			\
+			tspace = strstr(tmp, " ");			\
+			if (tspace)					\
+				*tspace = 0;				\
+			if (kstrtol(tmp, 0, &rc) != 0)			\
+				dev_info(dev->mt76.dev,			\
+					 "mt7915: set-rate-override: " #a \
+					 "= could not be parsed, tmp: %s\n", \
+					 tmp);				\
+			else						\
+				td->b = rc;				\
+		}							\
+	} while (0)
+
+	/* TODO:  Allow configuring LTF? */
+	td->tx_ltf = 1; /* 0: HTLTF 3.2us, 1: HELTF, 6.4us, 2 HELTF 12,8us */
+
+	MT7915_PARSE_LTOK(tpc, tx_power[0]);
+	MT7915_PARSE_LTOK(sgi, tx_rate_sgi);
+	MT7915_PARSE_LTOK(mcs, tx_rate_idx);
+	MT7915_PARSE_LTOK(nss, tx_rate_nss);
+	MT7915_PARSE_LTOK(pream, tx_rate_mode);
+	MT7915_PARSE_LTOK(retries, tx_xmit_count);
+	MT7915_PARSE_LTOK(dynbw, tx_dynbw);
+	MT7915_PARSE_LTOK(bw, txbw);
+	MT7915_PARSE_LTOK(active, txo_active);
+
+	dev_info(dev->mt76.dev,
+		 "mt7915: set-rate-overrides, vdev %i(%s) active=%d tpc=%d sgi=%d mcs=%d"
+		 " nss=%d pream=%d retries=%d dynbw=%d bw=%d\n",
+		 vdev_id, dev_name_match,
+		 td->txo_active, td->tx_power[0], td->tx_rate_sgi, td->tx_rate_idx,
+		 td->tx_rate_nss, td->tx_rate_mode, td->tx_xmit_count, td->tx_dynbw,
+		 td->txbw);
+
+	ret = count;
+
+exit:
+	mutex_unlock(&mphy->dev->mutex);
+	return ret;
+}
+
+static const struct file_operations fops_set_rate_override = {
+	.read = mt7915_read_set_rate_override,
+	.write = mt7915_write_set_rate_override,
+	.open = simple_open,
+	.owner = THIS_MODULE,
+	.llseek = default_llseek,
+};
+
 static int
 mt7915_txs_for_no_skb_set(void *data, u64 val)
 {
@@ -577,6 +799,8 @@  int mt7915_init_debugfs(struct mt7915_phy *phy)
 		debugfs_create_file("radar_trigger", 0200, dir, dev,
 				    &fops_radar_trigger);
 	}
+	debugfs_create_file("set_rate_override", 0600, dir,
+			    dev, &fops_set_rate_override);
 
 	return 0;
 }
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mac.c b/drivers/net/wireless/mediatek/mt76/mt7915/mac.c
index 4f565a77770c..c3dfd22d4978 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mac.c
@@ -757,21 +757,31 @@  mt7915_mac_fill_rx_vector(struct mt7915_dev *dev, struct sk_buff *skb)
 }
 
 static void
-mt7915_mac_write_txwi_tm(struct mt7915_phy *phy, __le32 *txwi,
+mt7915_mac_write_txwi_tm(struct mt7915_phy *phy, struct mt76_wcid *wcid, __le32 *txwi,
 			 struct sk_buff *skb)
 {
-#ifdef CONFIG_NL80211_TESTMODE
-	struct mt76_testmode_data *td = &phy->mt76->test;
+	struct mt76_testmode_data *td;
 	const struct ieee80211_rate *r;
-	u8 bw, mode, nss = td->tx_rate_nss;
-	u8 rate_idx = td->tx_rate_idx;
+	struct mt7915_sta *msta;
+	u8 bw, mode, nss;
+	u8 rate_idx;
 	u16 rateval = 0;
 	u32 val;
 	bool cck = false;
 	int band;
 
-	if (skb != phy->mt76->test.tx_skb)
-		return;
+	msta = container_of(wcid, struct mt7915_sta, wcid);
+
+	if (msta->test.txo_active) {
+		td = &msta->test;
+	} else {
+		if (skb != phy->mt76->test.tx_skb)
+			return;
+		td = &phy->mt76->test;
+	}
+
+	nss = td->tx_rate_nss;
+	rate_idx = td->tx_rate_idx;
 
 	switch (td->tx_rate_mode) {
 	case MT76_TM_TX_MODE_HT:
@@ -812,20 +822,24 @@  mt7915_mac_write_txwi_tm(struct mt7915_phy *phy, __le32 *txwi,
 		break;
 	}
 
-	switch (phy->mt76->chandef.width) {
-	case NL80211_CHAN_WIDTH_40:
-		bw = 1;
-		break;
-	case NL80211_CHAN_WIDTH_80:
-		bw = 2;
-		break;
-	case NL80211_CHAN_WIDTH_80P80:
-	case NL80211_CHAN_WIDTH_160:
-		bw = 3;
-		break;
-	default:
-		bw = 0;
-		break;
+	if (msta->test.txo_active) {
+		bw = td->txbw;
+	} else {
+		switch (phy->mt76->chandef.width) {
+		case NL80211_CHAN_WIDTH_40:
+			bw = 1;
+			break;
+		case NL80211_CHAN_WIDTH_80:
+			bw = 2;
+			break;
+		case NL80211_CHAN_WIDTH_80P80:
+		case NL80211_CHAN_WIDTH_160:
+			bw = 3;
+			break;
+		default:
+			bw = 0;
+			break;
+		}
 	}
 
 	if (td->tx_rate_stbc && nss == 1) {
@@ -837,12 +851,17 @@  mt7915_mac_write_txwi_tm(struct mt7915_phy *phy, __le32 *txwi,
 		   FIELD_PREP(MT_TX_RATE_MODE, mode) |
 		   FIELD_PREP(MT_TX_RATE_NSS, nss - 1);
 
+	/* TODO:  Support per-skb txpower, p.15 of txpower doc, DW2 29:24. */
 	txwi[2] |= cpu_to_le32(MT_TXD2_FIX_RATE);
 
+	/* Looks like this sets tx attempt to exactly 1.
+	 * TODO:  Use td->tx_xmit_count, if in txo mode.
+	 */
 	le32p_replace_bits(&txwi[3], 1, MT_TXD3_REM_TX_COUNT);
 	if (td->tx_rate_mode < MT76_TM_TX_MODE_HT)
 		txwi[3] |= cpu_to_le32(MT_TXD3_BA_DISABLE);
 
+	/* TODO:  Take tx_dynbw into account in txo mode. */
 	val = MT_TXD6_FIXED_BW |
 	      FIELD_PREP(MT_TXD6_BW, bw) |
 	      FIELD_PREP(MT_TXD6_TX_RATE, rateval) |
@@ -866,9 +885,29 @@  mt7915_mac_write_txwi_tm(struct mt7915_phy *phy, __le32 *txwi,
 
 	txwi[3] &= ~cpu_to_le32(MT_TXD3_SN_VALID);
 	txwi[6] |= cpu_to_le32(val);
-	txwi[7] |= cpu_to_le32(FIELD_PREP(MT_TXD7_SPE_IDX,
-					  phy->test.spe_idx));
-#endif
+
+	if (msta->test.txo_active) {
+		/* see mt7915_tm_set_tx_frames */
+		static const u8 spe_idx_map[] = {0, 0, 1, 0, 3, 2, 4, 0,
+						 9, 8, 6, 10, 16, 12, 18, 0};
+		u32 spe_idx;
+
+		if (td->tx_spe_idx) {
+			spe_idx = td->tx_spe_idx;
+		} else {
+			u8 tx_ant = td->tx_antenna_mask;
+
+			if (!tx_ant) {
+				/* use antenna mask that matches our nss */
+				tx_ant = GENMASK(nss - 1, 0);
+			}
+			spe_idx = spe_idx_map[tx_ant];
+		}
+		txwi[7] |= cpu_to_le32(FIELD_PREP(MT_TXD7_SPE_IDX, spe_idx));
+	} else {
+		txwi[7] |= cpu_to_le32(FIELD_PREP(MT_TXD7_SPE_IDX,
+						  phy->test.spe_idx));
+	}
 }
 
 static void
@@ -1121,8 +1160,15 @@  void mt7915_mac_write_txwi(struct mt7915_dev *dev, __le32 *txwi,
 		txwi[3] |= cpu_to_le32(MT_TXD3_BA_DISABLE);
 	}
 
-	if (mt76_testmode_enabled(mphy))
-		mt7915_mac_write_txwi_tm(mphy->priv, txwi, skb);
+#ifdef CONFIG_NL80211_TESTMODE
+	{
+		struct mt7915_sta *msta;
+
+		msta = container_of(wcid, struct mt7915_sta, wcid);
+		if (mt76_testmode_enabled(mphy) || msta->test.txo_active)
+			mt7915_mac_write_txwi_tm(mphy->priv, wcid, txwi, skb);
+	}
+#endif
 }
 
 int mt7915_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h b/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
index 8b1d4664562a..86cd0fc8e9de 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
@@ -103,6 +103,8 @@  struct mt7915_sta {
 
 	struct mt7915_sta_key_conf bip;
 
+	struct mt76_testmode_data test;
+
 	struct {
 		u8 flowid_mask;
 		struct mt7915_twt_flow flow[MT7915_MAX_STA_TWT_AGRT];