2023-06-02 15:26:08

by Shayne Chen

[permalink] [raw]
Subject: [PATCH 01/12] wifi: mt76: mt7996: move radio ctrl commands to proper functions

Move radio enable/disable commands into functions for configuring
per-phy radio.

Signed-off-by: Shayne Chen <[email protected]>
---
drivers/net/wireless/mediatek/mt76/mt7996/main.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c
index 0975774fe244..8a1edc5c1288 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c
@@ -43,6 +43,10 @@ int mt7996_run(struct ieee80211_hw *hw)
if (ret)
goto out;

+ ret = mt7996_mcu_set_radio_en(phy, true);
+ if (ret)
+ goto out;
+
ret = mt7996_mcu_set_chan_info(phy, UNI_CHANNEL_RX_PATH);
if (ret)
goto out;
@@ -82,6 +86,8 @@ static void mt7996_stop(struct ieee80211_hw *hw)

mutex_lock(&dev->mt76.mutex);

+ mt7996_mcu_set_radio_en(phy, false);
+
clear_bit(MT76_STATE_RUNNING, &phy->mt76->state);

mutex_unlock(&dev->mt76.mutex);
@@ -190,10 +196,6 @@ static int mt7996_add_interface(struct ieee80211_hw *hw,
if (ret)
goto out;

- ret = mt7996_mcu_set_radio_en(phy, true);
- if (ret)
- goto out;
-
dev->mt76.vif_mask |= BIT_ULL(mvif->mt76.idx);
phy->omac_mask |= BIT_ULL(mvif->mt76.omac_idx);

@@ -253,7 +255,6 @@ static void mt7996_remove_interface(struct ieee80211_hw *hw,
phy->monitor_vif = NULL;

mt7996_mcu_add_dev_info(phy, vif, false);
- mt7996_mcu_set_radio_en(phy, false);

rcu_assign_pointer(dev->mt76.wcid[idx], NULL);

--
2.39.2



2023-06-02 15:26:16

by Shayne Chen

[permalink] [raw]
Subject: [PATCH 09/12] wifi: mt76: mt7996: use correct phy for background radar event

From: StanleyYP Wang <[email protected]>

If driver directly uses the band_idx reported from the radar event to
access mt76_phy array, it will get the wrong phy for background radar.
Fix this by adjusting the statement.

Fixes: 98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi 7 (802.11be) devices")
Signed-off-by: StanleyYP Wang <[email protected]>
Signed-off-by: Shayne Chen <[email protected]>
---
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
index 52c6c502e9b3..48782b53f5d4 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
@@ -339,7 +339,11 @@ mt7996_mcu_rx_radar_detected(struct mt7996_dev *dev, struct sk_buff *skb)
if (r->band_idx >= ARRAY_SIZE(dev->mt76.phys))
return;

- mphy = dev->mt76.phys[r->band_idx];
+ if (dev->rdd2_phy && r->band_idx == MT_RX_SEL2)
+ mphy = dev->rdd2_phy->mt76;
+ else
+ mphy = dev->mt76.phys[r->band_idx];
+
if (!mphy)
return;

--
2.39.2


2023-06-02 15:26:24

by Shayne Chen

[permalink] [raw]
Subject: [PATCH 10/12] wifi: mt76: mt7996: fix WA event ring size

From: StanleyYP Wang <[email protected]>

Fix rx ring size of WA event to get rid of event loss and queue overflow
problems.

Fixes: 98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi 7 (802.11be) devices")
Signed-off-by: StanleyYP Wang <[email protected]>
Signed-off-by: Shayne Chen <[email protected]>
---
drivers/net/wireless/mediatek/mt76/mt7996/dma.c | 2 +-
drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/dma.c b/drivers/net/wireless/mediatek/mt76/mt7996/dma.c
index 534143465d9b..fbedaacffbba 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/dma.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/dma.c
@@ -293,7 +293,7 @@ int mt7996_dma_init(struct mt7996_dev *dev)
/* event from WA */
ret = mt76_queue_alloc(dev, &dev->mt76.q_rx[MT_RXQ_MCU_WA],
MT_RXQ_ID(MT_RXQ_MCU_WA),
- MT7996_RX_MCU_RING_SIZE,
+ MT7996_RX_MCU_RING_SIZE_WA,
MT_RX_BUF_SIZE,
MT_RXQ_RING_BASE(MT_RXQ_MCU_WA));
if (ret)
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
index 42892f06faa7..a3bd85d3df25 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
@@ -26,6 +26,7 @@

#define MT7996_RX_RING_SIZE 1536
#define MT7996_RX_MCU_RING_SIZE 512
+#define MT7996_RX_MCU_RING_SIZE_WA 1024

#define MT7996_FIRMWARE_WA "mediatek/mt7996/mt7996_wa.bin"
#define MT7996_FIRMWARE_WM "mediatek/mt7996/mt7996_wm.bin"
--
2.39.2


2023-06-02 15:26:29

by Shayne Chen

[permalink] [raw]
Subject: [PATCH 02/12] wifi: mt76: connac: add a setting bit for dsp firmware

From: Peter Chiu <[email protected]>

Add FW_START_WORKING_PDA_DSP for the indication of starting DSP
firmware download.

Signed-off-by: Peter Chiu <[email protected]>
Signed-off-by: Shayne Chen <[email protected]>
---
drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h
index ca1ce97a6d2f..4a21c237ea6e 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h
@@ -22,6 +22,7 @@

#define FW_START_OVERRIDE BIT(0)
#define FW_START_WORKING_PDA_CR4 BIT(2)
+#define FW_START_WORKING_PDA_DSP BIT(3)

#define PATCH_SEC_NOT_SUPPORT GENMASK(31, 0)
#define PATCH_SEC_TYPE_MASK GENMASK(15, 0)
--
2.39.2


2023-06-02 15:26:33

by Shayne Chen

[permalink] [raw]
Subject: [PATCH 12/12] wifi: mt76: mt7996: increase tx token size

From: Howard Hsu <[email protected]>

Align tx token size to proprietary driver, which can improve peak
throughput under MU performance tests.

Signed-off-by: Howard Hsu <[email protected]>
Signed-off-by: Shayne Chen <[email protected]>
---
drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
index a3bd85d3df25..651f53aa0cca 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
@@ -36,7 +36,7 @@
#define MT7996_EEPROM_DEFAULT "mediatek/mt7996/mt7996_eeprom.bin"
#define MT7996_EEPROM_SIZE 7680
#define MT7996_EEPROM_BLOCK_SIZE 16
-#define MT7996_TOKEN_SIZE 8192
+#define MT7996_TOKEN_SIZE 16384

#define MT7996_CFEND_RATE_DEFAULT 0x49 /* OFDM 24M */
#define MT7996_CFEND_RATE_11B 0x03 /* 11B LP, 11M */
--
2.39.2


2023-06-02 15:26:41

by Shayne Chen

[permalink] [raw]
Subject: [PATCH 05/12] wifi: mt76: mt7996: init he and eht cap for AP_VLAN

From: Peter Chiu <[email protected]>

Init he and eht capabilities for AP_VLAN type. Without this patch, the
BA response from AP_VLAN will not include the ADDBA extension tag.

Signed-off-by: Peter Chiu <[email protected]>
Signed-off-by: Shayne Chen <[email protected]>
---
drivers/net/wireless/mediatek/mt76/mt7996/init.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/init.c b/drivers/net/wireless/mediatek/mt76/mt7996/init.c
index f1b48cdda58f..004575a0479b 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/init.c
@@ -808,6 +808,7 @@ __mt7996_set_stream_he_eht_caps(struct mt7996_phy *phy,
switch (i) {
case NL80211_IFTYPE_STATION:
case NL80211_IFTYPE_AP:
+ case NL80211_IFTYPE_AP_VLAN:
#ifdef CONFIG_MAC80211_MESH
case NL80211_IFTYPE_MESH_POINT:
#endif
--
2.39.2


2023-06-02 15:26:53

by Shayne Chen

[permalink] [raw]
Subject: [PATCH 04/12] wifi: mt76: mt7996: fix bss wlan_idx when sending bss_info command

From: Peter Chiu <[email protected]>

The bmc_tx_wlan_idx should be the wlan_idx of the current bss rather
than peer AP's wlan_idx, otherwise there will appear some frame
decryption problems on station mode.

Fixes: 98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi 7 (802.11be) devices")
Reviewed-by: Shayne Chen <[email protected]>
Signed-off-by: Peter Chiu <[email protected]>
Signed-off-by: Shayne Chen <[email protected]>
---
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
index 243647dbd8c7..db51b3023654 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
@@ -712,6 +712,7 @@ mt7996_mcu_bss_basic_tlv(struct sk_buff *skb,
struct cfg80211_chan_def *chandef = &phy->chandef;
struct mt76_connac_bss_basic_tlv *bss;
u32 type = CONNECTION_INFRA_AP;
+ u16 sta_wlan_idx = wlan_idx;
struct tlv *tlv;
int idx;

@@ -731,7 +732,7 @@ mt7996_mcu_bss_basic_tlv(struct sk_buff *skb,
struct mt76_wcid *wcid;

wcid = (struct mt76_wcid *)sta->drv_priv;
- wlan_idx = wcid->idx;
+ sta_wlan_idx = wcid->idx;
}
rcu_read_unlock();
}
@@ -751,7 +752,7 @@ mt7996_mcu_bss_basic_tlv(struct sk_buff *skb,
bss->bcn_interval = cpu_to_le16(vif->bss_conf.beacon_int);
bss->dtim_period = vif->bss_conf.dtim_period;
bss->bmc_tx_wlan_idx = cpu_to_le16(wlan_idx);
- bss->sta_idx = cpu_to_le16(wlan_idx);
+ bss->sta_idx = cpu_to_le16(sta_wlan_idx);
bss->conn_type = cpu_to_le32(type);
bss->omac_idx = mvif->omac_idx;
bss->band_idx = mvif->band_idx;
--
2.39.2


2023-06-02 15:26:53

by Shayne Chen

[permalink] [raw]
Subject: [PATCH 03/12] wifi: mt76: mt7996: add dsp firmware download

From: Peter Chiu <[email protected]>

Add DSP firmware for phy-related control. The firmware is transparent to
driver, but it's necessary for the firmware download process.

Reviewed-by: Shayne Chen <[email protected]>
Signed-off-by: Peter Chiu <[email protected]>
Signed-off-by: Shayne Chen <[email protected]>
---
.../net/wireless/mediatek/mt76/mt7996/mcu.c | 94 ++++++++-----------
.../wireless/mediatek/mt76/mt7996/mt7996.h | 7 ++
.../net/wireless/mediatek/mt76/mt7996/pci.c | 1 +
3 files changed, 49 insertions(+), 53 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
index 88e2f9d0e513..243647dbd8c7 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
@@ -2155,7 +2155,7 @@ static int mt7996_load_patch(struct mt7996_dev *dev)
static int
mt7996_mcu_send_ram_firmware(struct mt7996_dev *dev,
const struct mt7996_fw_trailer *hdr,
- const u8 *data, bool is_wa)
+ const u8 *data, enum mt7996_ram_type type)
{
int i, offset = 0;
u32 override = 0, option = 0;
@@ -2167,8 +2167,10 @@ mt7996_mcu_send_ram_firmware(struct mt7996_dev *dev,

region = (const struct mt7996_fw_region *)((const u8 *)hdr -
(hdr->n_region - i) * sizeof(*region));
+ /* DSP and WA use same mode */
mode = mt76_connac_mcu_gen_dl_mode(&dev->mt76,
- region->feature_set, is_wa);
+ region->feature_set,
+ type != MT7996_RAM_TYPE_WM);
len = le32_to_cpu(region->len);
addr = le32_to_cpu(region->addr);

@@ -2195,8 +2197,10 @@ mt7996_mcu_send_ram_firmware(struct mt7996_dev *dev,
if (override)
option |= FW_START_OVERRIDE;

- if (is_wa)
+ if (type == MT7996_RAM_TYPE_WA)
option |= FW_START_WORKING_PDA_CR4;
+ else if (type == MT7996_RAM_TYPE_DSP)
+ option |= FW_START_WORKING_PDA_DSP;

return mt76_connac_mcu_start_firmware(&dev->mt76, override, option);
}
@@ -2207,56 +2211,40 @@ static int mt7996_load_ram(struct mt7996_dev *dev)
const struct firmware *fw;
int ret;

- ret = request_firmware(&fw, MT7996_FIRMWARE_WM, dev->mt76.dev);
- if (ret)
- return ret;
-
- if (!fw || !fw->data || fw->size < sizeof(*hdr)) {
- dev_err(dev->mt76.dev, "Invalid firmware\n");
- ret = -EINVAL;
- goto out;
- }
-
- hdr = (const struct mt7996_fw_trailer *)(fw->data + fw->size - sizeof(*hdr));
-
- dev_info(dev->mt76.dev, "WM Firmware Version: %.10s, Build Time: %.15s\n",
- hdr->fw_ver, hdr->build_date);
-
- ret = mt7996_mcu_send_ram_firmware(dev, hdr, fw->data, false);
- if (ret) {
- dev_err(dev->mt76.dev, "Failed to start WM firmware\n");
- goto out;
- }
-
- release_firmware(fw);
-
- ret = request_firmware(&fw, MT7996_FIRMWARE_WA, dev->mt76.dev);
- if (ret)
- return ret;
-
- if (!fw || !fw->data || fw->size < sizeof(*hdr)) {
- dev_err(dev->mt76.dev, "Invalid firmware\n");
- ret = -EINVAL;
- goto out;
- }
-
- hdr = (const struct mt7996_fw_trailer *)(fw->data + fw->size - sizeof(*hdr));
-
- dev_info(dev->mt76.dev, "WA Firmware Version: %.10s, Build Time: %.15s\n",
- hdr->fw_ver, hdr->build_date);
-
- ret = mt7996_mcu_send_ram_firmware(dev, hdr, fw->data, true);
- if (ret) {
- dev_err(dev->mt76.dev, "Failed to start WA firmware\n");
- goto out;
- }
-
- snprintf(dev->mt76.hw->wiphy->fw_version,
- sizeof(dev->mt76.hw->wiphy->fw_version),
- "%.10s-%.15s", hdr->fw_ver, hdr->build_date);
-
-out:
- release_firmware(fw);
+#define LOAD_RAM(_type) \
+ do { \
+ ret = request_firmware(&fw, MT7996_FIRMWARE_##_type, dev->mt76.dev);\
+ if (ret) \
+ return ret; \
+ \
+ if (!fw || !fw->data || fw->size < sizeof(*hdr)) { \
+ dev_err(dev->mt76.dev, "Invalid firmware\n"); \
+ release_firmware(fw); \
+ return -EINVAL; \
+ } \
+ \
+ hdr = (const struct mt7996_fw_trailer *) \
+ (fw->data + fw->size - sizeof(*hdr)); \
+ \
+ dev_info(dev->mt76.dev, \
+ "%s Firmware Version: %.10s, Build Time: %.15s\n", \
+ #_type, hdr->fw_ver, hdr->build_date); \
+ \
+ ret = mt7996_mcu_send_ram_firmware(dev, hdr, fw->data, \
+ MT7996_RAM_TYPE_##_type); \
+ if (ret) { \
+ dev_err(dev->mt76.dev, "Failed to start %s firmware\n", #_type);\
+ release_firmware(fw); \
+ return ret; \
+ } \
+ \
+ release_firmware(fw); \
+ } while (0)
+
+ LOAD_RAM(WM);
+ LOAD_RAM(DSP);
+ LOAD_RAM(WA);
+#undef LOAD_RAM

return ret;
}
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
index 4d7dcb95a620..7dfdc7384056 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
@@ -29,6 +29,7 @@

#define MT7996_FIRMWARE_WA "mediatek/mt7996/mt7996_wa.bin"
#define MT7996_FIRMWARE_WM "mediatek/mt7996/mt7996_wm.bin"
+#define MT7996_FIRMWARE_DSP "mediatek/mt7996/mt7996_dsp.bin"
#define MT7996_ROM_PATCH "mediatek/mt7996/mt7996_rom_patch.bin"

#define MT7996_EEPROM_DEFAULT "mediatek/mt7996/mt7996_eeprom.bin"
@@ -52,6 +53,12 @@ struct mt7996_sta;
struct mt7996_dfs_pulse;
struct mt7996_dfs_pattern;

+enum mt7996_ram_type {
+ MT7996_RAM_TYPE_WM,
+ MT7996_RAM_TYPE_WA,
+ MT7996_RAM_TYPE_DSP,
+};
+
enum mt7996_txq_id {
MT7996_TXQ_FWDL = 16,
MT7996_TXQ_MCU_WM,
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/pci.c b/drivers/net/wireless/mediatek/mt76/mt7996/pci.c
index 64aee3fb5445..c5301050ff8b 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/pci.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/pci.c
@@ -219,4 +219,5 @@ MODULE_DEVICE_TABLE(pci, mt7996_pci_device_table);
MODULE_DEVICE_TABLE(pci, mt7996_hif_device_table);
MODULE_FIRMWARE(MT7996_FIRMWARE_WA);
MODULE_FIRMWARE(MT7996_FIRMWARE_WM);
+MODULE_FIRMWARE(MT7996_FIRMWARE_DSP);
MODULE_FIRMWARE(MT7996_ROM_PATCH);
--
2.39.2


2023-06-02 15:26:54

by Shayne Chen

[permalink] [raw]
Subject: [PATCH 06/12] wifi: mt76: mt7996: enable VHT extended NSS BW feature

From: Peter Chiu <[email protected]>

Set SUPPORTS_VHT_EXT_NSS_BW to let the max BW capability correctly be
parsed by different devices.

Signed-off-by: Peter Chiu <[email protected]>
Signed-off-by: Shayne Chen <[email protected]>
---
drivers/net/wireless/mediatek/mt76/mt7996/init.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/init.c b/drivers/net/wireless/mediatek/mt76/mt7996/init.c
index 004575a0479b..8247153d082d 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/init.c
@@ -217,6 +217,8 @@ mt7996_init_wiphy(struct ieee80211_hw *hw)
IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
phy->mt76->sband_5g.sband.ht_cap.ampdu_density =
IEEE80211_HT_MPDU_DENSITY_1;
+
+ ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW);
}

mt76_set_stream_caps(phy->mt76, true);
--
2.39.2


2023-06-02 15:26:54

by Shayne Chen

[permalink] [raw]
Subject: [PATCH 08/12] wifi: mt76: mt7996: set ifs time by mcu command

From: Peter Chiu <[email protected]>

There's a race between driver and fw on some tx/rx control registers
when setting ifs, which will cause accidental hw queue pause problems.
Avoid this by setting ifs time with bss_info mcu command.

Reviewed-by: Shayne Chen <[email protected]>
Signed-off-by: Peter Chiu <[email protected]>
Signed-off-by: Shayne Chen <[email protected]>
---
.../net/wireless/mediatek/mt76/mt7996/mac.c | 27 +----------
.../net/wireless/mediatek/mt76/mt7996/main.c | 5 +-
.../net/wireless/mediatek/mt76/mt7996/mcu.c | 47 +++++++++++++++++++
.../net/wireless/mediatek/mt76/mt7996/mcu.h | 17 +++++++
.../wireless/mediatek/mt76/mt7996/mt7996.h | 3 +-
5 files changed, 70 insertions(+), 29 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
index 130eb7b4fd91..78d9127e63ab 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
@@ -1604,20 +1604,19 @@ void mt7996_mac_reset_counters(struct mt7996_phy *phy)
mt7996_mcu_get_chan_mib_info(phy, true);
}

-void mt7996_mac_set_timing(struct mt7996_phy *phy)
+void mt7996_mac_set_coverage_class(struct mt7996_phy *phy)
{
s16 coverage_class = phy->coverage_class;
struct mt7996_dev *dev = phy->dev;
struct mt7996_phy *phy2 = mt7996_phy2(dev);
struct mt7996_phy *phy3 = mt7996_phy3(dev);
- u32 val, reg_offset;
+ u32 reg_offset;
u32 cck = FIELD_PREP(MT_TIMEOUT_VAL_PLCP, 231) |
FIELD_PREP(MT_TIMEOUT_VAL_CCA, 48);
u32 ofdm = FIELD_PREP(MT_TIMEOUT_VAL_PLCP, 60) |
FIELD_PREP(MT_TIMEOUT_VAL_CCA, 28);
u8 band_idx = phy->mt76->band_idx;
int offset;
- bool a_band = !(phy->mt76->chandef.chan->band == NL80211_BAND_2GHZ);

if (!test_bit(MT76_STATE_RUNNING, &phy->mt76->state))
return;
@@ -1630,34 +1629,12 @@ void mt7996_mac_set_timing(struct mt7996_phy *phy)
coverage_class = max_t(s16, coverage_class,
phy3->coverage_class);

- mt76_set(dev, MT_ARB_SCR(band_idx),
- MT_ARB_SCR_TX_DISABLE | MT_ARB_SCR_RX_DISABLE);
- udelay(1);
-
offset = 3 * coverage_class;
reg_offset = FIELD_PREP(MT_TIMEOUT_VAL_PLCP, offset) |
FIELD_PREP(MT_TIMEOUT_VAL_CCA, offset);

mt76_wr(dev, MT_TMAC_CDTR(band_idx), cck + reg_offset);
mt76_wr(dev, MT_TMAC_ODTR(band_idx), ofdm + reg_offset);
- mt76_wr(dev, MT_TMAC_ICR0(band_idx),
- FIELD_PREP(MT_IFS_EIFS_OFDM, a_band ? 84 : 78) |
- FIELD_PREP(MT_IFS_RIFS, 2) |
- FIELD_PREP(MT_IFS_SIFS, 10) |
- FIELD_PREP(MT_IFS_SLOT, phy->slottime));
-
- if (!a_band)
- mt76_wr(dev, MT_TMAC_ICR1(band_idx),
- FIELD_PREP(MT_IFS_EIFS_CCK, 314));
-
- if (phy->slottime < 20 || a_band)
- val = MT7996_CFEND_RATE_DEFAULT;
- else
- val = MT7996_CFEND_RATE_11B;
-
- mt76_rmw_field(dev, MT_RATE_HRCR0(band_idx), MT_RATE_HRCR0_CFEND_RATE, val);
- mt76_clear(dev, MT_ARB_SCR(band_idx),
- MT_ARB_SCR_TX_DISABLE | MT_ARB_SCR_RX_DISABLE);
}

void mt7996_mac_enable_nf(struct mt7996_dev *dev, u8 band)
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c
index 8a1edc5c1288..6001b534b657 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c
@@ -287,7 +287,6 @@ int mt7996_set_channel(struct mt7996_phy *phy)
if (ret)
goto out;

- mt7996_mac_set_timing(phy);
ret = mt7996_dfs_init_radar_detector(phy);
mt7996_mac_cca_stats_reset(phy);

@@ -565,7 +564,7 @@ static void mt7996_bss_info_changed(struct ieee80211_hw *hw,

if (slottime != phy->slottime) {
phy->slottime = slottime;
- mt7996_mac_set_timing(phy);
+ mt7996_mcu_set_timing(phy, vif);
}
}

@@ -905,7 +904,7 @@ mt7996_set_coverage_class(struct ieee80211_hw *hw, s16 coverage_class)

mutex_lock(&dev->mt76.mutex);
phy->coverage_class = max_t(s16, coverage_class, 0);
- mt7996_mac_set_timing(phy);
+ mt7996_mac_set_coverage_class(phy);
mutex_unlock(&dev->mt76.mutex);
}

diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
index db51b3023654..52c6c502e9b3 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
@@ -701,6 +701,35 @@ mt7996_mcu_muar_config(struct mt7996_phy *phy, struct ieee80211_vif *vif,
sizeof(req), true);
}

+static void
+mt7996_mcu_bss_ifs_timing_tlv(struct sk_buff *skb, struct ieee80211_vif *vif)
+{
+ struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
+ struct mt7996_phy *phy = mvif->phy;
+ struct bss_ifs_time_tlv *ifs_time;
+ struct tlv *tlv;
+ bool a_band = !(phy->mt76->chandef.chan->band == NL80211_BAND_2GHZ);
+ u16 eifs_time = a_band ? 84 : 78;
+
+ tlv = mt7996_mcu_add_uni_tlv(skb, UNI_BSS_INFO_IFS_TIME, sizeof(*ifs_time));
+
+ ifs_time = (struct bss_ifs_time_tlv *)tlv;
+ ifs_time->slot_valid = true;
+ ifs_time->sifs_valid = true;
+ ifs_time->rifs_valid = true;
+ ifs_time->eifs_valid = true;
+
+ ifs_time->slot_time = cpu_to_le16(phy->slottime);
+ ifs_time->sifs_time = cpu_to_le16(10);
+ ifs_time->rifs_time = cpu_to_le16(2);
+ ifs_time->eifs_time = cpu_to_le16(eifs_time);
+
+ if (!a_band) {
+ ifs_time->eifs_cck_valid = true;
+ ifs_time->eifs_cck_time = cpu_to_le16(314);
+ }
+}
+
static int
mt7996_mcu_bss_basic_tlv(struct sk_buff *skb,
struct ieee80211_vif *vif,
@@ -826,6 +855,7 @@ int mt7996_mcu_add_bss_info(struct mt7996_phy *phy,
mt7996_mcu_bss_bmc_tlv(skb, vif, phy);
mt7996_mcu_bss_ra_tlv(skb, vif, phy);
mt7996_mcu_bss_txcmd_tlv(skb, true);
+ mt7996_mcu_bss_ifs_timing_tlv(skb, vif);

if (vif->bss_conf.he_support)
mt7996_mcu_bss_he_tlv(skb, vif, phy);
@@ -838,6 +868,23 @@ int mt7996_mcu_add_bss_info(struct mt7996_phy *phy,
MCU_WMWA_UNI_CMD(BSS_INFO_UPDATE), true);
}

+int mt7996_mcu_set_timing(struct mt7996_phy *phy, struct ieee80211_vif *vif)
+{
+ struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
+ struct mt7996_dev *dev = phy->dev;
+ struct sk_buff *skb;
+
+ skb = __mt7996_mcu_alloc_bss_req(&dev->mt76, &mvif->mt76,
+ MT7996_BSS_UPDATE_MAX_SIZE);
+ if (IS_ERR(skb))
+ return PTR_ERR(skb);
+
+ mt7996_mcu_bss_ifs_timing_tlv(skb, vif);
+
+ return mt76_mcu_skb_send_msg(&dev->mt76, skb,
+ MCU_WMWA_UNI_CMD(BSS_INFO_UPDATE), true);
+}
+
static int
mt7996_mcu_sta_ba(struct mt76_dev *dev, struct mt76_vif *mvif,
struct ieee80211_ampdu_params *params,
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.h b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.h
index d7075a4d0667..078f82858621 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.h
@@ -317,6 +317,22 @@ struct bss_sec_tlv {
u8 __rsv2[1];
} __packed;

+struct bss_ifs_time_tlv {
+ __le16 tag;
+ __le16 len;
+ u8 slot_valid;
+ u8 sifs_valid;
+ u8 rifs_valid;
+ u8 eifs_valid;
+ __le16 slot_time;
+ __le16 sifs_time;
+ __le16 rifs_time;
+ __le16 eifs_time;
+ u8 eifs_cck_valid;
+ u8 rsv;
+ __le16 eifs_cck_time;
+} __packed;
+
struct bss_power_save {
__le16 tag;
__le16 len;
@@ -552,6 +568,7 @@ enum {
sizeof(struct bss_txcmd_tlv) + \
sizeof(struct bss_power_save) + \
sizeof(struct bss_sec_tlv) + \
+ sizeof(struct bss_ifs_time_tlv) + \
sizeof(struct bss_mld_tlv))

#define MT7996_STA_UPDATE_MAX_SIZE (sizeof(struct sta_req_hdr) + \
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
index 7dfdc7384056..42892f06faa7 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
@@ -463,6 +463,7 @@ int mt7996_mcu_set_radar_th(struct mt7996_dev *dev, int index,
const struct mt7996_dfs_pattern *pattern);
int mt7996_mcu_set_radio_en(struct mt7996_phy *phy, bool enable);
int mt7996_mcu_set_rts_thresh(struct mt7996_phy *phy, u32 val);
+int mt7996_mcu_set_timing(struct mt7996_phy *phy, struct ieee80211_vif *vif);
int mt7996_mcu_get_chan_mib_info(struct mt7996_phy *phy, bool chan_switch);
int mt7996_mcu_rdd_cmd(struct mt7996_dev *dev, int cmd, u8 index,
u8 rx_sel, u8 val);
@@ -526,7 +527,7 @@ void mt7996_mac_write_txwi(struct mt7996_dev *dev, __le32 *txwi,
struct sk_buff *skb, struct mt76_wcid *wcid,
struct ieee80211_key_conf *key, int pid,
enum mt76_txq_id qid, u32 changed);
-void mt7996_mac_set_timing(struct mt7996_phy *phy);
+void mt7996_mac_set_coverage_class(struct mt7996_phy *phy);
int mt7996_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
struct ieee80211_sta *sta);
void mt7996_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
--
2.39.2


2023-06-02 15:26:55

by Shayne Chen

[permalink] [raw]
Subject: [PATCH 11/12] wifi: mt76: mt7996: add muru support

From: MeiChia Chiu <[email protected]>

Add sta_rec_muru() fw command to support MU-MIMO and OFDMA features.

Signed-off-by: MeiChia Chiu <[email protected]>
Signed-off-by: Shayne Chen <[email protected]>
---
.../wireless/mediatek/mt76/mt76_connac_mcu.h | 3 +-
.../net/wireless/mediatek/mt76/mt7996/mcu.c | 56 ++++++++++++++++++-
2 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h
index 3790d68525e5..48bced4e2e5d 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h
@@ -519,7 +519,8 @@ struct sta_rec_muru {
u8 uo_ra;
u8 he_2x996_tone;
u8 rx_t_frame_11ac;
- u8 rsv[3];
+ u8 rx_ctrl_frame_to_mbss;
+ u8 rsv[2];
} ofdma_ul;

struct {
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
index 48782b53f5d4..c50dcce21315 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
@@ -1102,6 +1102,59 @@ mt7996_mcu_sta_amsdu_tlv(struct mt7996_dev *dev, struct sk_buff *skb,
}
}

+static void
+mt7996_mcu_sta_muru_tlv(struct mt7996_dev *dev, struct sk_buff *skb,
+ struct ieee80211_vif *vif, struct ieee80211_sta *sta)
+{
+ struct ieee80211_he_cap_elem *elem = &sta->deflink.he_cap.he_cap_elem;
+ struct sta_rec_muru *muru;
+ struct tlv *tlv;
+
+ if (vif->type != NL80211_IFTYPE_STATION &&
+ vif->type != NL80211_IFTYPE_AP)
+ return;
+
+ tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_MURU, sizeof(*muru));
+
+ muru = (struct sta_rec_muru *)tlv;
+ muru->cfg.mimo_dl_en = vif->bss_conf.eht_mu_beamformer ||
+ vif->bss_conf.he_mu_beamformer ||
+ vif->bss_conf.vht_mu_beamformer ||
+ vif->bss_conf.vht_mu_beamformee;
+ muru->cfg.ofdma_dl_en = true;
+
+ if (sta->deflink.vht_cap.vht_supported)
+ muru->mimo_dl.vht_mu_bfee =
+ !!(sta->deflink.vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
+
+ if (!sta->deflink.he_cap.has_he)
+ return;
+
+ muru->mimo_dl.partial_bw_dl_mimo =
+ HE_PHY(CAP6_PARTIAL_BANDWIDTH_DL_MUMIMO, elem->phy_cap_info[6]);
+
+ muru->mimo_ul.full_ul_mimo =
+ HE_PHY(CAP2_UL_MU_FULL_MU_MIMO, elem->phy_cap_info[2]);
+ muru->mimo_ul.partial_ul_mimo =
+ HE_PHY(CAP2_UL_MU_PARTIAL_MU_MIMO, elem->phy_cap_info[2]);
+
+ muru->ofdma_dl.punc_pream_rx =
+ HE_PHY(CAP1_PREAMBLE_PUNC_RX_MASK, elem->phy_cap_info[1]);
+ muru->ofdma_dl.he_20m_in_40m_2g =
+ HE_PHY(CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G, elem->phy_cap_info[8]);
+ muru->ofdma_dl.he_20m_in_160m =
+ HE_PHY(CAP8_20MHZ_IN_160MHZ_HE_PPDU, elem->phy_cap_info[8]);
+ muru->ofdma_dl.he_80m_in_160m =
+ HE_PHY(CAP8_80MHZ_IN_160MHZ_HE_PPDU, elem->phy_cap_info[8]);
+
+ muru->ofdma_ul.t_frame_dur =
+ HE_MAC(CAP1_TF_MAC_PAD_DUR_MASK, elem->mac_cap_info[1]);
+ muru->ofdma_ul.mu_cascading =
+ HE_MAC(CAP2_MU_CASCADING, elem->mac_cap_info[2]);
+ muru->ofdma_ul.uo_ra =
+ HE_MAC(CAP3_OFDMA_RA, elem->mac_cap_info[3]);
+}
+
static inline bool
mt7996_is_ebf_supported(struct mt7996_phy *phy, struct ieee80211_vif *vif,
struct ieee80211_sta *sta, bool bfee)
@@ -1779,7 +1832,8 @@ int mt7996_mcu_add_sta(struct mt7996_dev *dev, struct ieee80211_vif *vif,
mt7996_mcu_sta_he_6g_tlv(skb, sta);
/* starec eht */
mt7996_mcu_sta_eht_tlv(skb, sta);
- /* TODO: starec muru */
+ /* starec muru */
+ mt7996_mcu_sta_muru_tlv(dev, skb, vif, sta);
/* starec bfee */
mt7996_mcu_sta_bfee_tlv(dev, skb, vif, sta);
/* starec hdr trans */
--
2.39.2


2023-06-02 18:09:06

by Lorenzo Bianconi

[permalink] [raw]
Subject: Re: [PATCH 03/12] wifi: mt76: mt7996: add dsp firmware download

> From: Peter Chiu <[email protected]>
>
> Add DSP firmware for phy-related control. The firmware is transparent to
> driver, but it's necessary for the firmware download process.
>
> Reviewed-by: Shayne Chen <[email protected]>
> Signed-off-by: Peter Chiu <[email protected]>
> Signed-off-by: Shayne Chen <[email protected]>
> ---
> .../net/wireless/mediatek/mt76/mt7996/mcu.c | 94 ++++++++-----------
> .../wireless/mediatek/mt76/mt7996/mt7996.h | 7 ++
> .../net/wireless/mediatek/mt76/mt7996/pci.c | 1 +
> 3 files changed, 49 insertions(+), 53 deletions(-)
>
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
> index 88e2f9d0e513..243647dbd8c7 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
> @@ -2155,7 +2155,7 @@ static int mt7996_load_patch(struct mt7996_dev *dev)
> static int
> mt7996_mcu_send_ram_firmware(struct mt7996_dev *dev,
> const struct mt7996_fw_trailer *hdr,
> - const u8 *data, bool is_wa)
> + const u8 *data, enum mt7996_ram_type type)
> {
> int i, offset = 0;
> u32 override = 0, option = 0;
> @@ -2167,8 +2167,10 @@ mt7996_mcu_send_ram_firmware(struct mt7996_dev *dev,
>
> region = (const struct mt7996_fw_region *)((const u8 *)hdr -
> (hdr->n_region - i) * sizeof(*region));
> + /* DSP and WA use same mode */
> mode = mt76_connac_mcu_gen_dl_mode(&dev->mt76,
> - region->feature_set, is_wa);
> + region->feature_set,
> + type != MT7996_RAM_TYPE_WM);
> len = le32_to_cpu(region->len);
> addr = le32_to_cpu(region->addr);
>
> @@ -2195,8 +2197,10 @@ mt7996_mcu_send_ram_firmware(struct mt7996_dev *dev,
> if (override)
> option |= FW_START_OVERRIDE;
>
> - if (is_wa)
> + if (type == MT7996_RAM_TYPE_WA)
> option |= FW_START_WORKING_PDA_CR4;
> + else if (type == MT7996_RAM_TYPE_DSP)
> + option |= FW_START_WORKING_PDA_DSP;
>
> return mt76_connac_mcu_start_firmware(&dev->mt76, override, option);
> }
> @@ -2207,56 +2211,40 @@ static int mt7996_load_ram(struct mt7996_dev *dev)
> const struct firmware *fw;
> int ret;
>
> - ret = request_firmware(&fw, MT7996_FIRMWARE_WM, dev->mt76.dev);
> - if (ret)
> - return ret;
> -
> - if (!fw || !fw->data || fw->size < sizeof(*hdr)) {
> - dev_err(dev->mt76.dev, "Invalid firmware\n");
> - ret = -EINVAL;
> - goto out;
> - }
> -
> - hdr = (const struct mt7996_fw_trailer *)(fw->data + fw->size - sizeof(*hdr));
> -
> - dev_info(dev->mt76.dev, "WM Firmware Version: %.10s, Build Time: %.15s\n",
> - hdr->fw_ver, hdr->build_date);
> -
> - ret = mt7996_mcu_send_ram_firmware(dev, hdr, fw->data, false);
> - if (ret) {
> - dev_err(dev->mt76.dev, "Failed to start WM firmware\n");
> - goto out;
> - }
> -
> - release_firmware(fw);
> -
> - ret = request_firmware(&fw, MT7996_FIRMWARE_WA, dev->mt76.dev);
> - if (ret)
> - return ret;
> -
> - if (!fw || !fw->data || fw->size < sizeof(*hdr)) {
> - dev_err(dev->mt76.dev, "Invalid firmware\n");
> - ret = -EINVAL;
> - goto out;
> - }
> -
> - hdr = (const struct mt7996_fw_trailer *)(fw->data + fw->size - sizeof(*hdr));
> -
> - dev_info(dev->mt76.dev, "WA Firmware Version: %.10s, Build Time: %.15s\n",
> - hdr->fw_ver, hdr->build_date);
> -
> - ret = mt7996_mcu_send_ram_firmware(dev, hdr, fw->data, true);
> - if (ret) {
> - dev_err(dev->mt76.dev, "Failed to start WA firmware\n");
> - goto out;
> - }
> -
> - snprintf(dev->mt76.hw->wiphy->fw_version,
> - sizeof(dev->mt76.hw->wiphy->fw_version),
> - "%.10s-%.15s", hdr->fw_ver, hdr->build_date);
> -
> -out:
> - release_firmware(fw);
> +#define LOAD_RAM(_type) \

I think it would be better to used a regular function instead of a macro, the
code would be much easier to read.

Regards,
Lorenzo

> + do { \
> + ret = request_firmware(&fw, MT7996_FIRMWARE_##_type, dev->mt76.dev);\
> + if (ret) \
> + return ret; \
> + \
> + if (!fw || !fw->data || fw->size < sizeof(*hdr)) { \
> + dev_err(dev->mt76.dev, "Invalid firmware\n"); \
> + release_firmware(fw); \
> + return -EINVAL; \
> + } \
> + \
> + hdr = (const struct mt7996_fw_trailer *) \
> + (fw->data + fw->size - sizeof(*hdr)); \
> + \
> + dev_info(dev->mt76.dev, \
> + "%s Firmware Version: %.10s, Build Time: %.15s\n", \
> + #_type, hdr->fw_ver, hdr->build_date); \
> + \
> + ret = mt7996_mcu_send_ram_firmware(dev, hdr, fw->data, \
> + MT7996_RAM_TYPE_##_type); \
> + if (ret) { \
> + dev_err(dev->mt76.dev, "Failed to start %s firmware\n", #_type);\
> + release_firmware(fw); \
> + return ret; \
> + } \
> + \
> + release_firmware(fw); \
> + } while (0)
> +
> + LOAD_RAM(WM);
> + LOAD_RAM(DSP);
> + LOAD_RAM(WA);
> +#undef LOAD_RAM
>
> return ret;
> }
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
> index 4d7dcb95a620..7dfdc7384056 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
> +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
> @@ -29,6 +29,7 @@
>
> #define MT7996_FIRMWARE_WA "mediatek/mt7996/mt7996_wa.bin"
> #define MT7996_FIRMWARE_WM "mediatek/mt7996/mt7996_wm.bin"
> +#define MT7996_FIRMWARE_DSP "mediatek/mt7996/mt7996_dsp.bin"
> #define MT7996_ROM_PATCH "mediatek/mt7996/mt7996_rom_patch.bin"
>
> #define MT7996_EEPROM_DEFAULT "mediatek/mt7996/mt7996_eeprom.bin"
> @@ -52,6 +53,12 @@ struct mt7996_sta;
> struct mt7996_dfs_pulse;
> struct mt7996_dfs_pattern;
>
> +enum mt7996_ram_type {
> + MT7996_RAM_TYPE_WM,
> + MT7996_RAM_TYPE_WA,
> + MT7996_RAM_TYPE_DSP,
> +};
> +
> enum mt7996_txq_id {
> MT7996_TXQ_FWDL = 16,
> MT7996_TXQ_MCU_WM,
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/pci.c b/drivers/net/wireless/mediatek/mt76/mt7996/pci.c
> index 64aee3fb5445..c5301050ff8b 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7996/pci.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7996/pci.c
> @@ -219,4 +219,5 @@ MODULE_DEVICE_TABLE(pci, mt7996_pci_device_table);
> MODULE_DEVICE_TABLE(pci, mt7996_hif_device_table);
> MODULE_FIRMWARE(MT7996_FIRMWARE_WA);
> MODULE_FIRMWARE(MT7996_FIRMWARE_WM);
> +MODULE_FIRMWARE(MT7996_FIRMWARE_DSP);
> MODULE_FIRMWARE(MT7996_ROM_PATCH);
> --
> 2.39.2
>


Attachments:
(No filename) (6.46 kB)
signature.asc (235.00 B)
Download all attachments

2023-06-02 18:18:20

by Lorenzo Bianconi

[permalink] [raw]
Subject: Re: [PATCH 02/12] wifi: mt76: connac: add a setting bit for dsp firmware

> From: Peter Chiu <[email protected]>
>
> Add FW_START_WORKING_PDA_DSP for the indication of starting DSP
> firmware download.
>
> Signed-off-by: Peter Chiu <[email protected]>
> Signed-off-by: Shayne Chen <[email protected]>
> ---
> drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h
> index ca1ce97a6d2f..4a21c237ea6e 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h
> +++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h
> @@ -22,6 +22,7 @@
>
> #define FW_START_OVERRIDE BIT(0)
> #define FW_START_WORKING_PDA_CR4 BIT(2)
> +#define FW_START_WORKING_PDA_DSP BIT(3)

I would say this patch can be merged with 3/12 where FW_START_WORKING_PDA_DSP
is actually used.

Regards,
Lorenzo

>
> #define PATCH_SEC_NOT_SUPPORT GENMASK(31, 0)
> #define PATCH_SEC_TYPE_MASK GENMASK(15, 0)
> --
> 2.39.2
>


Attachments:
(No filename) (1.04 kB)
signature.asc (235.00 B)
Download all attachments

2023-06-02 18:19:22

by Lorenzo Bianconi

[permalink] [raw]
Subject: Re: [PATCH 08/12] wifi: mt76: mt7996: set ifs time by mcu command

> From: Peter Chiu <[email protected]>
>
> There's a race between driver and fw on some tx/rx control registers
> when setting ifs, which will cause accidental hw queue pause problems.
> Avoid this by setting ifs time with bss_info mcu command.
>
> Reviewed-by: Shayne Chen <[email protected]>
> Signed-off-by: Peter Chiu <[email protected]>
> Signed-off-by: Shayne Chen <[email protected]>
> ---
> .../net/wireless/mediatek/mt76/mt7996/mac.c | 27 +----------
> .../net/wireless/mediatek/mt76/mt7996/main.c | 5 +-
> .../net/wireless/mediatek/mt76/mt7996/mcu.c | 47 +++++++++++++++++++
> .../net/wireless/mediatek/mt76/mt7996/mcu.h | 17 +++++++
> .../wireless/mediatek/mt76/mt7996/mt7996.h | 3 +-
> 5 files changed, 70 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
> index 130eb7b4fd91..78d9127e63ab 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
> @@ -1604,20 +1604,19 @@ void mt7996_mac_reset_counters(struct mt7996_phy *phy)
> mt7996_mcu_get_chan_mib_info(phy, true);
> }
>
> -void mt7996_mac_set_timing(struct mt7996_phy *phy)
> +void mt7996_mac_set_coverage_class(struct mt7996_phy *phy)
> {
> s16 coverage_class = phy->coverage_class;
> struct mt7996_dev *dev = phy->dev;
> struct mt7996_phy *phy2 = mt7996_phy2(dev);
> struct mt7996_phy *phy3 = mt7996_phy3(dev);
> - u32 val, reg_offset;
> + u32 reg_offset;
> u32 cck = FIELD_PREP(MT_TIMEOUT_VAL_PLCP, 231) |
> FIELD_PREP(MT_TIMEOUT_VAL_CCA, 48);
> u32 ofdm = FIELD_PREP(MT_TIMEOUT_VAL_PLCP, 60) |
> FIELD_PREP(MT_TIMEOUT_VAL_CCA, 28);
> u8 band_idx = phy->mt76->band_idx;
> int offset;
> - bool a_band = !(phy->mt76->chandef.chan->band == NL80211_BAND_2GHZ);
>
> if (!test_bit(MT76_STATE_RUNNING, &phy->mt76->state))
> return;
> @@ -1630,34 +1629,12 @@ void mt7996_mac_set_timing(struct mt7996_phy *phy)
> coverage_class = max_t(s16, coverage_class,
> phy3->coverage_class);
>
> - mt76_set(dev, MT_ARB_SCR(band_idx),
> - MT_ARB_SCR_TX_DISABLE | MT_ARB_SCR_RX_DISABLE);
> - udelay(1);
> -
> offset = 3 * coverage_class;
> reg_offset = FIELD_PREP(MT_TIMEOUT_VAL_PLCP, offset) |
> FIELD_PREP(MT_TIMEOUT_VAL_CCA, offset);
>
> mt76_wr(dev, MT_TMAC_CDTR(band_idx), cck + reg_offset);
> mt76_wr(dev, MT_TMAC_ODTR(band_idx), ofdm + reg_offset);
> - mt76_wr(dev, MT_TMAC_ICR0(band_idx),
> - FIELD_PREP(MT_IFS_EIFS_OFDM, a_band ? 84 : 78) |
> - FIELD_PREP(MT_IFS_RIFS, 2) |
> - FIELD_PREP(MT_IFS_SIFS, 10) |
> - FIELD_PREP(MT_IFS_SLOT, phy->slottime));
> -
> - if (!a_band)
> - mt76_wr(dev, MT_TMAC_ICR1(band_idx),
> - FIELD_PREP(MT_IFS_EIFS_CCK, 314));
> -
> - if (phy->slottime < 20 || a_band)
> - val = MT7996_CFEND_RATE_DEFAULT;
> - else
> - val = MT7996_CFEND_RATE_11B;
> -
> - mt76_rmw_field(dev, MT_RATE_HRCR0(band_idx), MT_RATE_HRCR0_CFEND_RATE, val);
> - mt76_clear(dev, MT_ARB_SCR(band_idx),
> - MT_ARB_SCR_TX_DISABLE | MT_ARB_SCR_RX_DISABLE);
> }
>
> void mt7996_mac_enable_nf(struct mt7996_dev *dev, u8 band)
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c
> index 8a1edc5c1288..6001b534b657 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c
> @@ -287,7 +287,6 @@ int mt7996_set_channel(struct mt7996_phy *phy)
> if (ret)
> goto out;
>
> - mt7996_mac_set_timing(phy);
> ret = mt7996_dfs_init_radar_detector(phy);
> mt7996_mac_cca_stats_reset(phy);
>
> @@ -565,7 +564,7 @@ static void mt7996_bss_info_changed(struct ieee80211_hw *hw,
>
> if (slottime != phy->slottime) {
> phy->slottime = slottime;
> - mt7996_mac_set_timing(phy);
> + mt7996_mcu_set_timing(phy, vif);
> }
> }
>
> @@ -905,7 +904,7 @@ mt7996_set_coverage_class(struct ieee80211_hw *hw, s16 coverage_class)
>
> mutex_lock(&dev->mt76.mutex);
> phy->coverage_class = max_t(s16, coverage_class, 0);
> - mt7996_mac_set_timing(phy);
> + mt7996_mac_set_coverage_class(phy);
> mutex_unlock(&dev->mt76.mutex);
> }
>
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
> index db51b3023654..52c6c502e9b3 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
> @@ -701,6 +701,35 @@ mt7996_mcu_muar_config(struct mt7996_phy *phy, struct ieee80211_vif *vif,
> sizeof(req), true);
> }
>
> +static void
> +mt7996_mcu_bss_ifs_timing_tlv(struct sk_buff *skb, struct ieee80211_vif *vif)
> +{
> + struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
> + struct mt7996_phy *phy = mvif->phy;
> + struct bss_ifs_time_tlv *ifs_time;
> + struct tlv *tlv;
> + bool a_band = !(phy->mt76->chandef.chan->band == NL80211_BAND_2GHZ);

nit: I think it is better to do it in the other way around since the band can
be even 6GHz. Something like:

bool is_2ghz_band = phy->mt76->chandef.chan->band == NL80211_BAND_2GHZ

or even just use phy->mt76->chandef.chan->band directly.

Regards,
Lorenzo

> + u16 eifs_time = a_band ? 84 : 78;
> +
> + tlv = mt7996_mcu_add_uni_tlv(skb, UNI_BSS_INFO_IFS_TIME, sizeof(*ifs_time));
> +
> + ifs_time = (struct bss_ifs_time_tlv *)tlv;
> + ifs_time->slot_valid = true;
> + ifs_time->sifs_valid = true;
> + ifs_time->rifs_valid = true;
> + ifs_time->eifs_valid = true;
> +
> + ifs_time->slot_time = cpu_to_le16(phy->slottime);
> + ifs_time->sifs_time = cpu_to_le16(10);
> + ifs_time->rifs_time = cpu_to_le16(2);
> + ifs_time->eifs_time = cpu_to_le16(eifs_time);
> +
> + if (!a_band) {
> + ifs_time->eifs_cck_valid = true;
> + ifs_time->eifs_cck_time = cpu_to_le16(314);
> + }
> +}
> +
> static int
> mt7996_mcu_bss_basic_tlv(struct sk_buff *skb,
> struct ieee80211_vif *vif,
> @@ -826,6 +855,7 @@ int mt7996_mcu_add_bss_info(struct mt7996_phy *phy,
> mt7996_mcu_bss_bmc_tlv(skb, vif, phy);
> mt7996_mcu_bss_ra_tlv(skb, vif, phy);
> mt7996_mcu_bss_txcmd_tlv(skb, true);
> + mt7996_mcu_bss_ifs_timing_tlv(skb, vif);
>
> if (vif->bss_conf.he_support)
> mt7996_mcu_bss_he_tlv(skb, vif, phy);
> @@ -838,6 +868,23 @@ int mt7996_mcu_add_bss_info(struct mt7996_phy *phy,
> MCU_WMWA_UNI_CMD(BSS_INFO_UPDATE), true);
> }
>
> +int mt7996_mcu_set_timing(struct mt7996_phy *phy, struct ieee80211_vif *vif)
> +{
> + struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
> + struct mt7996_dev *dev = phy->dev;
> + struct sk_buff *skb;
> +
> + skb = __mt7996_mcu_alloc_bss_req(&dev->mt76, &mvif->mt76,
> + MT7996_BSS_UPDATE_MAX_SIZE);
> + if (IS_ERR(skb))
> + return PTR_ERR(skb);
> +
> + mt7996_mcu_bss_ifs_timing_tlv(skb, vif);
> +
> + return mt76_mcu_skb_send_msg(&dev->mt76, skb,
> + MCU_WMWA_UNI_CMD(BSS_INFO_UPDATE), true);
> +}
> +
> static int
> mt7996_mcu_sta_ba(struct mt76_dev *dev, struct mt76_vif *mvif,
> struct ieee80211_ampdu_params *params,
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.h b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.h
> index d7075a4d0667..078f82858621 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.h
> +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.h
> @@ -317,6 +317,22 @@ struct bss_sec_tlv {
> u8 __rsv2[1];
> } __packed;
>
> +struct bss_ifs_time_tlv {
> + __le16 tag;
> + __le16 len;
> + u8 slot_valid;
> + u8 sifs_valid;
> + u8 rifs_valid;
> + u8 eifs_valid;
> + __le16 slot_time;
> + __le16 sifs_time;
> + __le16 rifs_time;
> + __le16 eifs_time;
> + u8 eifs_cck_valid;
> + u8 rsv;
> + __le16 eifs_cck_time;
> +} __packed;
> +
> struct bss_power_save {
> __le16 tag;
> __le16 len;
> @@ -552,6 +568,7 @@ enum {
> sizeof(struct bss_txcmd_tlv) + \
> sizeof(struct bss_power_save) + \
> sizeof(struct bss_sec_tlv) + \
> + sizeof(struct bss_ifs_time_tlv) + \
> sizeof(struct bss_mld_tlv))
>
> #define MT7996_STA_UPDATE_MAX_SIZE (sizeof(struct sta_req_hdr) + \
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
> index 7dfdc7384056..42892f06faa7 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
> +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
> @@ -463,6 +463,7 @@ int mt7996_mcu_set_radar_th(struct mt7996_dev *dev, int index,
> const struct mt7996_dfs_pattern *pattern);
> int mt7996_mcu_set_radio_en(struct mt7996_phy *phy, bool enable);
> int mt7996_mcu_set_rts_thresh(struct mt7996_phy *phy, u32 val);
> +int mt7996_mcu_set_timing(struct mt7996_phy *phy, struct ieee80211_vif *vif);
> int mt7996_mcu_get_chan_mib_info(struct mt7996_phy *phy, bool chan_switch);
> int mt7996_mcu_rdd_cmd(struct mt7996_dev *dev, int cmd, u8 index,
> u8 rx_sel, u8 val);
> @@ -526,7 +527,7 @@ void mt7996_mac_write_txwi(struct mt7996_dev *dev, __le32 *txwi,
> struct sk_buff *skb, struct mt76_wcid *wcid,
> struct ieee80211_key_conf *key, int pid,
> enum mt76_txq_id qid, u32 changed);
> -void mt7996_mac_set_timing(struct mt7996_phy *phy);
> +void mt7996_mac_set_coverage_class(struct mt7996_phy *phy);
> int mt7996_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
> struct ieee80211_sta *sta);
> void mt7996_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
> --
> 2.39.2
>


Attachments:
(No filename) (9.51 kB)
signature.asc (235.00 B)
Download all attachments

2023-06-07 14:30:34

by Kalle Valo

[permalink] [raw]
Subject: Re: [PATCH 03/12] wifi: mt76: mt7996: add dsp firmware download

(I moved Lorenzo's comment to better see the macro)

Lorenzo Bianconi <[email protected]> writes:

>> From: Peter Chiu <[email protected]>
>>
>> Add DSP firmware for phy-related control. The firmware is transparent to
>> driver, but it's necessary for the firmware download process.
>>
>> Reviewed-by: Shayne Chen <[email protected]>
>> Signed-off-by: Peter Chiu <[email protected]>
>> Signed-off-by: Shayne Chen <[email protected]>

[...]

>> +#define LOAD_RAM(_type) \
>> + do { \
>> + ret = request_firmware(&fw, MT7996_FIRMWARE_##_type, dev->mt76.dev);\
>> + if (ret) \
>> + return ret; \
>> + \
>> + if (!fw || !fw->data || fw->size < sizeof(*hdr)) { \
>> + dev_err(dev->mt76.dev, "Invalid firmware\n"); \
>> + release_firmware(fw); \
>> + return -EINVAL; \
>> + } \
>> + \
>> + hdr = (const struct mt7996_fw_trailer *) \
>> + (fw->data + fw->size - sizeof(*hdr)); \
>> + \
>> + dev_info(dev->mt76.dev, \
>> + "%s Firmware Version: %.10s, Build Time: %.15s\n", \
>> + #_type, hdr->fw_ver, hdr->build_date); \
>> + \
>> + ret = mt7996_mcu_send_ram_firmware(dev, hdr, fw->data, \
>> + MT7996_RAM_TYPE_##_type); \
>> + if (ret) { \
>> + dev_err(dev->mt76.dev, "Failed to start %s firmware\n", #_type);\
>> + release_firmware(fw); \
>> + return ret; \
>> + } \
>> + \
>> + release_firmware(fw); \
>> + } while (0)
>> +
>> + LOAD_RAM(WM);
>> + LOAD_RAM(DSP);
>> + LOAD_RAM(WA);
>> +#undef LOAD_RAM
>
> I think it would be better to used a regular function instead of a macro, the
> code would be much easier to read.

Yeah, a function is preferred. I think Andrew Morton says: prefer C over
CPP

--
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches