2022-12-20 06:44:16

by Sujuan Chen (陈素娟)

[permalink] [raw]
Subject: [PATCH,v3] wifi: mt76: mt7915: add wds support when wed is enabled

The current WED only supports 256 wcid, whereas mt7986 can support up to 512 entries,
so firmware provides a rule to get sta_info by DA when wcid is set to 0x3ff by txd.
Also, WED provides a register to overwrite txd wcid, that is, wcid[9:8] can
be overwritten by 0x3 and wcid[7:0] is set to 0xff by host driver.

However, firmware is unable to get sta_info from DA as DA != RA for 4addr cases,
so firmware and wifi host driver both use wcid (256 - 271) and (768 ~ 783)
for sync up to get correct sta_info

Tested-by: Sujuan Chen <[email protected]>
Co-developed-by: Bo Jiao <[email protected]>
Signed-off-by: Bo Jiao <[email protected]>
Signed-off-by: Sujuan Chen <[email protected]>
---
v2:
- drop duplicate setting in mmio
- reduce the patch size by redefining mt76_wcid_alloc
v3:
- rework wds wcid getting flow
---
drivers/net/wireless/mediatek/mt76/mt76.h | 9 +++++
.../net/wireless/mediatek/mt76/mt7915/main.c | 32 ++++++++++++++--
.../net/wireless/mediatek/mt76/mt7915/mcu.c | 13 ++++++-
.../net/wireless/mediatek/mt76/mt7915/mcu.h | 1 +
drivers/net/wireless/mediatek/mt76/util.c | 37 +++++++++++++++++--
drivers/net/wireless/mediatek/mt76/util.h | 7 +++-
6 files changed, 90 insertions(+), 9 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
index 1037d23bc4d0..24d7d59d6ca7 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -27,6 +27,9 @@

#define MT76_TOKEN_FREE_THR 64

+#define MT76_WED_WDS_MIN 256
+#define MT76_WED_WDS_MAX 272
+
#define MT_QFLAG_WED_RING GENMASK(1, 0)
#define MT_QFLAG_WED_TYPE GENMASK(3, 2)
#define MT_QFLAG_WED BIT(4)
@@ -60,6 +63,12 @@ enum mt76_wed_type {
MT76_WED_Q_RX,
};

+enum mt76_wed_state {
+ MT76_WED_DEFAULT,
+ MT76_WED_ACTIVE,
+ MT76_WED_WDS_ACTIVE,
+};
+
struct mt76_bus_ops {
u32 (*rr)(struct mt76_dev *dev, u32 offset);
void (*wr)(struct mt76_dev *dev, u32 offset, u32 val);
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/main.c b/drivers/net/wireless/mediatek/mt76/mt7915/main.c
index 0511d6a505b0..ce95cfa1300d 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/main.c
@@ -664,8 +664,15 @@ int mt7915_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
bool ext_phy = mvif->phy != &dev->phy;
int ret, idx;
+ u8 flags = MT76_WED_DEFAULT;

- idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7915_WTBL_STA);
+ if (mtk_wed_device_active(&dev->mt76.mmio.wed) &&
+ !is_mt7915(&dev->mt76)) {
+ flags = test_bit(MT_WCID_FLAG_4ADDR, &msta->wcid.flags) ?
+ MT76_WED_WDS_ACTIVE : MT76_WED_ACTIVE;
+ }
+
+ idx = __mt76_wcid_alloc(mdev->wcid_mask, MT7915_WTBL_STA, flags);
if (idx < 0)
return -ENOSPC;

@@ -1115,12 +1122,27 @@ static void mt7915_sta_set_4addr(struct ieee80211_hw *hw,
{
struct mt7915_dev *dev = mt7915_hw_dev(hw);
struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv;
+ int min = MT76_WED_WDS_MIN, max = MT76_WED_WDS_MAX;

if (enabled)
set_bit(MT_WCID_FLAG_4ADDR, &msta->wcid.flags);
else
clear_bit(MT_WCID_FLAG_4ADDR, &msta->wcid.flags);

+ if (mtk_wed_device_active(&dev->mt76.mmio.wed) &&
+ !is_mt7915(&dev->mt76) &&
+ (msta->wcid.idx < min || msta->wcid.idx > max - 1)) {
+ struct ieee80211_sta *pre_sta;
+
+ pre_sta = kzalloc(sizeof(*sta) + sizeof(*msta), GFP_KERNEL);
+ mt76_sta_pre_rcu_remove(hw, vif, sta);
+ memmove(pre_sta, sta, sizeof(*sta) + sizeof(*msta));
+ mt7915_sta_add(hw, vif, sta);
+ synchronize_rcu();
+ mt7915_sta_remove(hw, vif, pre_sta);
+ kfree(pre_sta);
+ }
+
mt76_connac_mcu_wtbl_update_hdr_trans(&dev->mt76, vif, sta);
}

@@ -1485,15 +1507,19 @@ mt7915_net_fill_forward_path(struct ieee80211_hw *hw,
if (!mtk_wed_device_active(wed))
return -ENODEV;

- if (msta->wcid.idx > 0xff)
+ if (msta->wcid.idx > MT7915_WTBL_STA)
return -EIO;

path->type = DEV_PATH_MTK_WDMA;
path->dev = ctx->dev;
path->mtk_wdma.wdma_idx = wed->wdma_idx;
path->mtk_wdma.bss = mvif->mt76.idx;
- path->mtk_wdma.wcid = is_mt7915(&dev->mt76) ? msta->wcid.idx : 0x3ff;
path->mtk_wdma.queue = phy != &dev->phy;
+ if (test_bit(MT_WCID_FLAG_4ADDR, &msta->wcid.flags) ||
+ is_mt7915(&dev->mt76))
+ path->mtk_wdma.wcid = msta->wcid.idx;
+ else
+ path->mtk_wdma.wcid = 0x3ff;

ctx->dev = NULL;

diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
index 37a3c1f082d9..c566ea0f5022 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
@@ -2323,8 +2323,17 @@ int mt7915_mcu_init_firmware(struct mt7915_dev *dev)
if (ret)
return ret;

- if (mtk_wed_device_active(&dev->mt76.mmio.wed) && is_mt7915(&dev->mt76))
- mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(CAPABILITY), 0, 0, 0);
+ if (mtk_wed_device_active(&dev->mt76.mmio.wed)) {
+ if (is_mt7915(&dev->mt76))
+ ret = mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(CAPABILITY),
+ 0, 0, 0);
+ else
+ ret = mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(SET),
+ MCU_WA_PARAM_WED_VERSION,
+ dev->mt76.mmio.wed.rev_id, 0);
+ if (ret)
+ return ret;
+ }

ret = mt7915_mcu_set_mwds(dev, 1);
if (ret)
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h
index 29b5434bfdb8..f96cdf1cc626 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h
@@ -278,6 +278,7 @@ enum {
MCU_WA_PARAM_PDMA_RX = 0x04,
MCU_WA_PARAM_CPU_UTIL = 0x0b,
MCU_WA_PARAM_RED = 0x0e,
+ MCU_WA_PARAM_WED_VERSION = 0x32,
};

enum mcu_mmps_mode {
diff --git a/drivers/net/wireless/mediatek/mt76/util.c b/drivers/net/wireless/mediatek/mt76/util.c
index 581964425468..0112f1bd7219 100644
--- a/drivers/net/wireless/mediatek/mt76/util.c
+++ b/drivers/net/wireless/mediatek/mt76/util.c
@@ -42,9 +42,11 @@ bool __mt76_poll_msec(struct mt76_dev *dev, u32 offset, u32 mask, u32 val,
}
EXPORT_SYMBOL_GPL(__mt76_poll_msec);

-int mt76_wcid_alloc(u32 *mask, int size)
+int __mt76_wcid_alloc(u32 *mask, int size, u8 flag)
{
int i, idx = 0, cur;
+ int min = MT76_WED_WDS_MIN;
+ int max = MT76_WED_WDS_MAX;

for (i = 0; i < DIV_ROUND_UP(size, 32); i++) {
idx = ffs(~mask[i]);
@@ -53,16 +55,45 @@ int mt76_wcid_alloc(u32 *mask, int size)

idx--;
cur = i * 32 + idx;
- if (cur >= size)
+
+ switch (flag) {
+ case MT76_WED_ACTIVE:
+ if (cur >= min && cur < max)
+ continue;
+
+ if (cur >= size) {
+ u32 end = max - min - 1;
+
+ i = min / 32;
+ idx = ffs(~mask[i] & GENMASK(end, 0));
+ if (!idx)
+ goto error;
+ idx--;
+ cur = min + idx;
+ }
+
break;
+ case MT76_WED_WDS_ACTIVE:
+ if (cur < min)
+ continue;
+ if (cur >= max)
+ goto error;
+
+ break;
+ default:
+ if (cur >= size)
+ goto error;
+ break;
+ }

mask[i] |= BIT(idx);
return cur;
}

+error:
return -1;
}
-EXPORT_SYMBOL_GPL(mt76_wcid_alloc);
+EXPORT_SYMBOL_GPL(__mt76_wcid_alloc);

int mt76_get_min_avg_rssi(struct mt76_dev *dev, bool ext_phy)
{
diff --git a/drivers/net/wireless/mediatek/mt76/util.h b/drivers/net/wireless/mediatek/mt76/util.h
index 260965dde94c..99b7263c0a20 100644
--- a/drivers/net/wireless/mediatek/mt76/util.h
+++ b/drivers/net/wireless/mediatek/mt76/util.h
@@ -27,7 +27,12 @@ enum {
#define MT76_INCR(_var, _size) \
(_var = (((_var) + 1) % (_size)))

-int mt76_wcid_alloc(u32 *mask, int size);
+int __mt76_wcid_alloc(u32 *mask, int size, u8 flags);
+
+static inline int mt76_wcid_alloc(u32 *mask, int size)
+{
+ return __mt76_wcid_alloc(mask, size, 0);
+}

static inline void
mt76_wcid_mask_set(u32 *mask, int idx)
--
2.18.0


2022-12-22 16:45:27

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH,v3] wifi: mt76: mt7915: add wds support when wed is enabled

Hi Sujuan,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on wireless-next/main]
[also build test ERROR on wireless/main linus/master next-20221220]
[cannot apply to v6.1]
[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#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Sujuan-Chen/wifi-mt76-mt7915-add-wds-support-when-wed-is-enabled/20221220-143454
base: https://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next.git main
patch link: https://lore.kernel.org/r/6f80d1b49a97d2a08f6ec45f335a1fc8de21ebb9.1671454422.git.sujuan.chen%40mediatek.com
patch subject: [PATCH,v3] wifi: mt76: mt7915: add wds support when wed is enabled
config: x86_64-allyesconfig
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
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/intel-lab-lkp/linux/commit/91549c10e7cbfff9de335774417ffa2c7197bd40
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Sujuan-Chen/wifi-mt76-mt7915-add-wds-support-when-wed-is-enabled/20221220-143454
git checkout 91549c10e7cbfff9de335774417ffa2c7197bd40
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

>> drivers/net/wireless/mediatek/mt76/mt7915/mcu.c:2320:26: error: no member named 'rev_id' in 'struct mtk_wed_device'
dev->mt76.mmio.wed.rev_id, 0);
~~~~~~~~~~~~~~~~~~ ^
1 error generated.


vim +2320 drivers/net/wireless/mediatek/mt76/mt7915/mcu.c

2280
2281 int mt7915_mcu_init_firmware(struct mt7915_dev *dev)
2282 {
2283 int ret;
2284
2285 /* force firmware operation mode into normal state,
2286 * which should be set before firmware download stage.
2287 */
2288 mt76_wr(dev, MT_SWDEF_MODE, MT_SWDEF_NORMAL_MODE);
2289
2290 ret = mt7915_driver_own(dev, 0);
2291 if (ret)
2292 return ret;
2293 /* set driver own for band1 when two hif exist */
2294 if (dev->hif2) {
2295 ret = mt7915_driver_own(dev, 1);
2296 if (ret)
2297 return ret;
2298 }
2299
2300 ret = mt7915_load_firmware(dev);
2301 if (ret)
2302 return ret;
2303
2304 set_bit(MT76_STATE_MCU_RUNNING, &dev->mphy.state);
2305 ret = mt7915_mcu_fw_log_2_host(dev, MCU_FW_LOG_WM, 0);
2306 if (ret)
2307 return ret;
2308
2309 ret = mt7915_mcu_fw_log_2_host(dev, MCU_FW_LOG_WA, 0);
2310 if (ret)
2311 return ret;
2312
2313 if (mtk_wed_device_active(&dev->mt76.mmio.wed)) {
2314 if (is_mt7915(&dev->mt76))
2315 ret = mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(CAPABILITY),
2316 0, 0, 0);
2317 else
2318 ret = mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(SET),
2319 MCU_WA_PARAM_WED_VERSION,
> 2320 dev->mt76.mmio.wed.rev_id, 0);
2321 if (ret)
2322 return ret;
2323 }
2324
2325 ret = mt7915_mcu_set_mwds(dev, 1);
2326 if (ret)
2327 return ret;
2328
2329 ret = mt7915_mcu_set_muru_ctrl(dev, MURU_SET_PLATFORM_TYPE,
2330 MURU_PLATFORM_TYPE_PERF_LEVEL_2);
2331 if (ret)
2332 return ret;
2333
2334 ret = mt7915_mcu_init_rx_airtime(dev);
2335 if (ret)
2336 return ret;
2337
2338 return mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(SET),
2339 MCU_WA_PARAM_RED, 0, 0);
2340 }
2341

--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (4.18 kB)
config (292.34 kB)
Download all attachments