wifi: mt76: mt7915: wed: enable red per-band token drop
authorPeter Chiu <chui-hao.chiu@mediatek.com>
Fri, 6 Jan 2023 02:44:12 +0000 (10:44 +0800)
committerFelix Fietkau <nbd@nbd.name>
Fri, 3 Feb 2023 13:47:17 +0000 (14:47 +0100)
Enable RED to limit the number of token used by each band. If single band
uses too many tokens, it would hurt the throughput of the other bands.The
software path can solve this problem by AQL so enable RED for HW path only.

Reviewed-by: Shayne Chen <shayne.chen@mediatek.com>
Signed-off-by: Peter Chiu <chui-hao.chiu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
drivers/net/wireless/mediatek/mt76/mt7915/mcu.h
drivers/net/wireless/mediatek/mt76/mt7915/mmio.c
drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h

index 82fdf6d794bcf6d42c1272354bef8604d27bfe94..71005198ae2b5e9bc7e7057258454bf54a7ed775 100644 (file)
@@ -1171,6 +1171,7 @@ enum {
        MCU_EXT_CMD_GET_MIB_INFO = 0x5a,
        MCU_EXT_CMD_TXDPD_CAL = 0x60,
        MCU_EXT_CMD_CAL_CACHE = 0x67,
+       MCU_EXT_CMD_RED_ENABLE = 0x68,
        MCU_EXT_CMD_SET_RADAR_TH = 0x7c,
        MCU_EXT_CMD_SET_RDD_PATTERN = 0x7d,
        MCU_EXT_CMD_MWDS_SUPPORT = 0x80,
index f6e92de764cebdef021d0d3da0c5424fa08953d3..5545a8bdf1d0f8a3c458ab0b8533e446e97572c6 100644 (file)
@@ -2291,6 +2291,53 @@ mt7915_mcu_init_rx_airtime(struct mt7915_dev *dev)
                                 sizeof(req), true);
 }
 
+static int mt7915_red_set_watermark(struct mt7915_dev *dev)
+{
+#define RED_GLOBAL_TOKEN_WATERMARK 2
+       struct {
+               __le32 args[3];
+               u8 cmd;
+               u8 version;
+               u8 __rsv1[4];
+               __le16 len;
+               __le16 high_mark;
+               __le16 low_mark;
+               u8 __rsv2[12];
+       } __packed req = {
+               .args[0] = cpu_to_le32(MCU_WA_PARAM_RED_SETTING),
+               .cmd = RED_GLOBAL_TOKEN_WATERMARK,
+               .len = cpu_to_le16(sizeof(req) - sizeof(req.args)),
+               .high_mark = cpu_to_le16(MT7915_HW_TOKEN_SIZE - 256),
+               .low_mark = cpu_to_le16(MT7915_HW_TOKEN_SIZE - 256 - 1536),
+       };
+
+       return mt76_mcu_send_msg(&dev->mt76, MCU_WA_PARAM_CMD(SET), &req,
+                                sizeof(req), false);
+}
+
+static int mt7915_mcu_set_red(struct mt7915_dev *dev, bool enabled)
+{
+#define RED_DISABLE            0
+#define RED_BY_WA_ENABLE       2
+       int ret;
+       u32 red_type = enabled ? RED_BY_WA_ENABLE : RED_DISABLE;
+       __le32 req = cpu_to_le32(red_type);
+
+       if (enabled) {
+               ret = mt7915_red_set_watermark(dev);
+               if (ret < 0)
+                       return ret;
+       }
+
+       ret = mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(RED_ENABLE), &req,
+                               sizeof(req), false);
+       if (ret < 0)
+               return ret;
+
+       return mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(SET),
+                                MCU_WA_PARAM_RED, enabled, 0);
+}
+
 int mt7915_mcu_init_firmware(struct mt7915_dev *dev)
 {
        int ret;
@@ -2339,8 +2386,7 @@ int mt7915_mcu_init_firmware(struct mt7915_dev *dev)
        if (ret)
                return ret;
 
-       return mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(SET),
-                                MCU_WA_PARAM_RED, 0, 0);
+       return mt7915_mcu_set_red(dev, mtk_wed_device_active(&dev->mt76.mmio.wed));
 }
 
 int mt7915_mcu_init(struct mt7915_dev *dev)
index 29b5434bfdb8a035f7c98d773302922f7addacee..b9ea297f382c3a1fff02f66bfb0f14174c7956f0 100644 (file)
@@ -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_RED_SETTING = 0x40,
 };
 
 enum mcu_mmps_mode {
index 1a2e4df8d1b5746d0ac23ffdd1ac60cf230ca721..b9e8cfd926c9b7f13700d11656964a9b1b823378 100644 (file)
@@ -748,7 +748,7 @@ int mt7915_mmio_wed_init(struct mt7915_dev *dev, void *pdev_ptr,
                wed->wlan.wpdma_rx_glo = res->start + MT_WPDMA_GLO_CFG;
                wed->wlan.wpdma_rx = res->start + MT_RXQ_WED_DATA_RING_BASE;
        }
-       wed->wlan.nbuf = 4096;
+       wed->wlan.nbuf = MT7915_HW_TOKEN_SIZE;
        wed->wlan.tx_tbit[0] = is_mt7915(&dev->mt76) ? 4 : 30;
        wed->wlan.tx_tbit[1] = is_mt7915(&dev->mt76) ? 5 : 31;
        wed->wlan.txfree_tbit = is_mt7986(&dev->mt76) ? 2 : 1;
index 942d70c538254384d7106475f086cecf8b848c0b..3cbfb9b6a305b4d04df361942e1227aae7974f09 100644 (file)
@@ -53,6 +53,7 @@
 #define MT7916_EEPROM_SIZE             4096
 
 #define MT7915_EEPROM_BLOCK_SIZE       16
+#define MT7915_HW_TOKEN_SIZE           4096
 #define MT7915_TOKEN_SIZE              8192
 
 #define MT7915_CFEND_RATE_DEFAULT      0x49    /* OFDM 24M */