linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/8] mt76: mt7921: multiple fixes
@ 2021-02-19 17:28 Lorenzo Bianconi
  2021-02-19 17:28 ` [PATCH v2 1/8] mt76: mt7921: fix suspend/resume sequence Lorenzo Bianconi
                   ` (7 more replies)
  0 siblings, 8 replies; 11+ messages in thread
From: Lorenzo Bianconi @ 2021-02-19 17:28 UTC (permalink / raw)
  To: nbd; +Cc: linux-wireless, lorenzo.bianconi, sean.wang

Align mt7921 driver to fw APIs available in linux-firmware.
Fix uninitialized pointer access.
Fix memory leak in mt7921_coredump_work
Fix suspend/resume sequence.

Changes since v1:
- drop unused variable reading rx stats
- fix suspend/resume sequence patch
- fix memory leak in mt7921_coredump_work patch

Sean Wang (8):
  mt76: mt7921: fix suspend/resume sequence
  mt76: mt7921: fix memory leak in mt7921_coredump_work
  mt76: mt7921: switch to new api for hardware beacon filter
  mt76: connac: fix up the setting for ht40 mode in
    mt76_connac_mcu_uni_add_bss
  mt76: mt7921: fixup rx bitrate statistics
  mt76: mt7921: add flush operation
  mt76: mt7921: fix uninitialized pointer access in mt7921_get_wtbl_info
  mt76: connac: update sched_scan cmd usage

 .../wireless/mediatek/mt76/mt7615/mt7615.h    |   5 -
 .../net/wireless/mediatek/mt76/mt76_connac.h  |   5 +
 .../wireless/mediatek/mt76/mt76_connac_mcu.c  |   9 +-
 .../wireless/mediatek/mt76/mt76_connac_mcu.h  |  14 +-
 .../net/wireless/mediatek/mt76/mt7921/mac.c   | 161 +++++++++---------
 .../net/wireless/mediatek/mt76/mt7921/mac.h   |  10 +-
 .../net/wireless/mediatek/mt76/mt7921/main.c  |  59 +++++--
 .../net/wireless/mediatek/mt76/mt7921/mcu.c   |  13 +-
 .../net/wireless/mediatek/mt76/mt7921/pci.c   |  14 +-
 9 files changed, 172 insertions(+), 118 deletions(-)

-- 
2.29.2


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2 1/8] mt76: mt7921: fix suspend/resume sequence
  2021-02-19 17:28 [PATCH v2 0/8] mt76: mt7921: multiple fixes Lorenzo Bianconi
@ 2021-02-19 17:28 ` Lorenzo Bianconi
  2021-02-19 17:28 ` [PATCH v2 2/8] mt76: mt7921: fix memory leak in mt7921_coredump_work Lorenzo Bianconi
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Lorenzo Bianconi @ 2021-02-19 17:28 UTC (permalink / raw)
  To: nbd; +Cc: linux-wireless, lorenzo.bianconi, sean.wang

From: Sean Wang <sean.wang@mediatek.com>

Any pcie access should happen in pci D0 state and we should give ownership
back to the device at the end of the suspend procedure.

Fixes: 1d8efc741df80 ("mt76: mt7921: introduce Runtime PM support")
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/net/wireless/mediatek/mt76/mt7921/pci.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/pci.c b/drivers/net/wireless/mediatek/mt76/mt7921/pci.c
index 33ed952d7f4c..3e430c04c97e 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/pci.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/pci.c
@@ -209,12 +209,12 @@ static int mt7921_pci_suspend(struct pci_dev *pdev, pm_message_t state)
 	/* disable interrupt */
 	mt76_wr(dev, MT_WFDMA0_HOST_INT_ENA, 0);
 
-	pci_save_state(pdev);
-	err = pci_set_power_state(pdev, pci_choose_state(pdev, state));
+	err = mt7921_mcu_fw_pmctrl(dev);
 	if (err)
 		goto restore;
 
-	err = mt7921_mcu_drv_pmctrl(dev);
+	pci_save_state(pdev);
+	err = pci_set_power_state(pdev, pci_choose_state(pdev, state));
 	if (err)
 		goto restore;
 
@@ -237,16 +237,16 @@ static int mt7921_pci_resume(struct pci_dev *pdev)
 	struct mt7921_dev *dev = container_of(mdev, struct mt7921_dev, mt76);
 	int i, err;
 
-	err = mt7921_mcu_fw_pmctrl(dev);
-	if (err < 0)
-		return err;
-
 	err = pci_set_power_state(pdev, PCI_D0);
 	if (err)
 		return err;
 
 	pci_restore_state(pdev);
 
+	err = mt7921_mcu_drv_pmctrl(dev);
+	if (err < 0)
+		return 0;
+
 	/* enable interrupt */
 	mt7921_l1_wr(dev, MT_PCIE_MAC_INT_ENABLE, 0xff);
 	mt7921_irq_enable(dev, MT_INT_RX_DONE_ALL | MT_INT_TX_DONE_ALL |
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 2/8] mt76: mt7921: fix memory leak in mt7921_coredump_work
  2021-02-19 17:28 [PATCH v2 0/8] mt76: mt7921: multiple fixes Lorenzo Bianconi
  2021-02-19 17:28 ` [PATCH v2 1/8] mt76: mt7921: fix suspend/resume sequence Lorenzo Bianconi
@ 2021-02-19 17:28 ` Lorenzo Bianconi
  2021-02-19 17:28 ` [PATCH v2 3/8] mt76: mt7921: switch to new api for hardware beacon filter Lorenzo Bianconi
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Lorenzo Bianconi @ 2021-02-19 17:28 UTC (permalink / raw)
  To: nbd; +Cc: linux-wireless, lorenzo.bianconi, sean.wang

From: Sean Wang <sean.wang@mediatek.com>

Fix possible memory leak in mt7921_coredump_work.

Fixes: 1c099ab44727c ("mt76: mt7921: add MCU support")
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/net/wireless/mediatek/mt76/mt7921/mac.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
index 9468c9c3b9cf..8befa8167cde 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
@@ -1503,8 +1503,10 @@ void mt7921_coredump_work(struct work_struct *work)
 			break;
 
 		skb_pull(skb, sizeof(struct mt7921_mcu_rxd));
-		if (data + skb->len - dump > MT76_CONNAC_COREDUMP_SZ)
-			break;
+		if (data + skb->len - dump > MT76_CONNAC_COREDUMP_SZ) {
+			dev_kfree_skb(skb);
+			continue;
+		}
 
 		memcpy(data, skb->data, skb->len);
 		data += skb->len;
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 3/8] mt76: mt7921: switch to new api for hardware beacon filter
  2021-02-19 17:28 [PATCH v2 0/8] mt76: mt7921: multiple fixes Lorenzo Bianconi
  2021-02-19 17:28 ` [PATCH v2 1/8] mt76: mt7921: fix suspend/resume sequence Lorenzo Bianconi
  2021-02-19 17:28 ` [PATCH v2 2/8] mt76: mt7921: fix memory leak in mt7921_coredump_work Lorenzo Bianconi
@ 2021-02-19 17:28 ` Lorenzo Bianconi
  2021-02-24  5:28   ` Kalle Valo
  2021-02-19 17:28 ` [PATCH v2 4/8] mt76: connac: fix up the setting for ht40 mode in mt76_connac_mcu_uni_add_bss Lorenzo Bianconi
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 11+ messages in thread
From: Lorenzo Bianconi @ 2021-02-19 17:28 UTC (permalink / raw)
  To: nbd; +Cc: linux-wireless, lorenzo.bianconi, sean.wang

From: Sean Wang <sean.wang@mediatek.com>

Current firmware only supports new api for enabling hardware beacon filter.

Fixes: 1d8efc741df80 ("mt76: mt7921: introduce Runtime PM support")
Beacon filter cmd have to rely on the associatied access point's beacon
interval and DTIM information.

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 .../net/wireless/mediatek/mt76/mt7921/main.c  | 49 +++++++++++++------
 .../net/wireless/mediatek/mt76/mt7921/mcu.c   |  8 ++-
 2 files changed, 40 insertions(+), 17 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/main.c b/drivers/net/wireless/mediatek/mt76/mt7921/main.c
index 729f6c42cdde..11d85cf9cfb8 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/main.c
@@ -295,15 +295,6 @@ static int mt7921_add_interface(struct ieee80211_hw *hw,
 	if (ret)
 		goto out;
 
-	if (dev->pm.enable) {
-		ret = mt7921_mcu_set_bss_pm(dev, vif, true);
-		if (ret)
-			goto out;
-
-		vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
-		mt76_set(dev, MT_WF_RFCR(0), MT_WF_RFCR_DROP_OTHER_BEACON);
-	}
-
 	dev->mt76.vif_mask |= BIT(mvif->mt76.idx);
 	phy->omac_mask |= BIT_ULL(mvif->mt76.omac_idx);
 
@@ -349,13 +340,6 @@ static void mt7921_remove_interface(struct ieee80211_hw *hw,
 		phy->monitor_vif = NULL;
 
 	mt76_connac_free_pending_tx_skbs(&dev->pm, &msta->wcid);
-
-	if (dev->pm.enable) {
-		mt7921_mcu_set_bss_pm(dev, vif, false);
-		mt76_clear(dev, MT_WF_RFCR(0),
-			   MT_WF_RFCR_DROP_OTHER_BEACON);
-	}
-
 	mt76_connac_mcu_uni_add_dev(&dev->mphy, vif, &mvif->sta.wcid, false);
 
 	rcu_assign_pointer(dev->mt76.wcid[idx], NULL);
@@ -561,6 +545,36 @@ static void mt7921_configure_filter(struct ieee80211_hw *hw,
 	mt7921_mutex_release(dev);
 }
 
+static int
+mt7921_bss_bcnft_apply(struct mt7921_dev *dev, struct ieee80211_vif *vif,
+		       bool assoc)
+{
+	int ret;
+
+	if (!dev->pm.enable)
+		return 0;
+
+	if (assoc) {
+		ret = mt7921_mcu_uni_bss_bcnft(dev, vif, true);
+		if (ret)
+			return ret;
+
+		vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
+		mt76_set(dev, MT_WF_RFCR(0), MT_WF_RFCR_DROP_OTHER_BEACON);
+
+		return 0;
+	}
+
+	ret = mt7921_mcu_set_bss_pm(dev, vif, false);
+	if (ret)
+		return ret;
+
+	vif->driver_flags &= ~IEEE80211_VIF_BEACON_FILTER;
+	mt76_clear(dev, MT_WF_RFCR(0), MT_WF_RFCR_DROP_OTHER_BEACON);
+
+	return 0;
+}
+
 static void mt7921_bss_info_changed(struct ieee80211_hw *hw,
 				    struct ieee80211_vif *vif,
 				    struct ieee80211_bss_conf *info,
@@ -587,6 +601,9 @@ static void mt7921_bss_info_changed(struct ieee80211_hw *hw,
 	if (changed & BSS_CHANGED_PS)
 		mt7921_mcu_uni_bss_ps(dev, vif);
 
+	if (changed & BSS_CHANGED_ASSOC)
+		mt7921_bss_bcnft_apply(dev, vif, info->assoc);
+
 	mt7921_mutex_release(dev);
 }
 
diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c
index db125cd22b91..d784c75d47bf 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c
@@ -1294,8 +1294,14 @@ mt7921_pm_interface_iter(void *priv, u8 *mac, struct ieee80211_vif *vif)
 {
 	struct mt7921_phy *phy = priv;
 	struct mt7921_dev *dev = phy->dev;
+	int ret;
+
+	if (dev->pm.enable)
+		ret = mt7921_mcu_uni_bss_bcnft(dev, vif, true);
+	else
+		ret = mt7921_mcu_set_bss_pm(dev, vif, false);
 
-	if (mt7921_mcu_set_bss_pm(dev, vif, dev->pm.enable))
+	if (ret)
 		return;
 
 	if (dev->pm.enable) {
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 4/8] mt76: connac: fix up the setting for ht40 mode in mt76_connac_mcu_uni_add_bss
  2021-02-19 17:28 [PATCH v2 0/8] mt76: mt7921: multiple fixes Lorenzo Bianconi
                   ` (2 preceding siblings ...)
  2021-02-19 17:28 ` [PATCH v2 3/8] mt76: mt7921: switch to new api for hardware beacon filter Lorenzo Bianconi
@ 2021-02-19 17:28 ` Lorenzo Bianconi
  2021-02-19 17:28 ` [PATCH v2 5/8] mt76: mt7921: fixup rx bitrate statistics Lorenzo Bianconi
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Lorenzo Bianconi @ 2021-02-19 17:28 UTC (permalink / raw)
  To: nbd; +Cc: linux-wireless, lorenzo.bianconi, sean.wang

From: Sean Wang <sean.wang@mediatek.com>

Use proper value for ht40 mode configuration in mt76_connac_mcu_uni_add_bss
routine and not ht20 one

Fixes: d0e274af2f2e4 ("mt76: mt76_connac: create mcu library")
Co-developed-by: Soul Huang <Soul.Huang@mediatek.com>
Signed-off-by: Soul Huang <Soul.Huang@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
index ac8d6ad76054..81515419b5b6 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
@@ -1198,6 +1198,7 @@ int mt76_connac_mcu_uni_add_bss(struct mt76_phy *phy,
 			.center_chan = ieee80211_frequency_to_channel(freq1),
 			.center_chan2 = ieee80211_frequency_to_channel(freq2),
 			.tx_streams = hweight8(phy->antenna_mask),
+			.ht_op_info = 4, /* set HT 40M allowed */
 			.rx_streams = phy->chainmask,
 			.short_st = true,
 		},
@@ -1290,6 +1291,7 @@ int mt76_connac_mcu_uni_add_bss(struct mt76_phy *phy,
 	case NL80211_CHAN_WIDTH_20:
 	default:
 		rlm_req.rlm.bw = CMD_CBW_20MHZ;
+		rlm_req.rlm.ht_op_info = 0;
 		break;
 	}
 
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 5/8] mt76: mt7921: fixup rx bitrate statistics
  2021-02-19 17:28 [PATCH v2 0/8] mt76: mt7921: multiple fixes Lorenzo Bianconi
                   ` (3 preceding siblings ...)
  2021-02-19 17:28 ` [PATCH v2 4/8] mt76: connac: fix up the setting for ht40 mode in mt76_connac_mcu_uni_add_bss Lorenzo Bianconi
@ 2021-02-19 17:28 ` Lorenzo Bianconi
  2021-02-19 17:28 ` [PATCH v2 6/8] mt76: mt7921: add flush operation Lorenzo Bianconi
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Lorenzo Bianconi @ 2021-02-19 17:28 UTC (permalink / raw)
  To: nbd; +Cc: linux-wireless, lorenzo.bianconi, sean.wang

From: Sean Wang <sean.wang@mediatek.com>

Since the related rx bitrate fields have been moved to group3 in Rxv,
fix rx bitrate statistics in mt7921_mac_fill_rx routine.

Fixes: 163f4d22c118d ("mt76: mt7921: add MAC support")
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 .../net/wireless/mediatek/mt76/mt7921/mac.c   | 155 +++++++++---------
 .../net/wireless/mediatek/mt76/mt7921/mac.h   |  10 +-
 2 files changed, 86 insertions(+), 79 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
index 8befa8167cde..76d5f194706f 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
@@ -400,7 +400,9 @@ int mt7921_mac_fill_rx(struct mt7921_dev *dev, struct sk_buff *skb)
 
 	/* RXD Group 3 - P-RXV */
 	if (rxd1 & MT_RXD1_NORMAL_GROUP_3) {
-		u32 v0, v1, v2;
+		u8 stbc, gi;
+		u32 v0, v1;
+		bool cck;
 
 		rxv = rxd;
 		rxd += 2;
@@ -409,7 +411,6 @@ int mt7921_mac_fill_rx(struct mt7921_dev *dev, struct sk_buff *skb)
 
 		v0 = le32_to_cpu(rxv[0]);
 		v1 = le32_to_cpu(rxv[1]);
-		v2 = le32_to_cpu(rxv[2]);
 
 		if (v0 & MT_PRXV_HT_AD_CODE)
 			status->enc_flags |= RX_ENC_FLAG_LDPC;
@@ -429,87 +430,87 @@ int mt7921_mac_fill_rx(struct mt7921_dev *dev, struct sk_buff *skb)
 					     status->chain_signal[i]);
 		}
 
-		/* RXD Group 5 - C-RXV */
-		if (rxd1 & MT_RXD1_NORMAL_GROUP_5) {
-			u8 stbc = FIELD_GET(MT_CRXV_HT_STBC, v2);
-			u8 gi = FIELD_GET(MT_CRXV_HT_SHORT_GI, v2);
-			bool cck = false;
+		stbc = FIELD_GET(MT_PRXV_STBC, v0);
+		gi = FIELD_GET(MT_PRXV_SGI, v0);
+		cck = false;
 
-			rxd += 18;
-			if ((u8 *)rxd - skb->data >= skb->len)
-				return -EINVAL;
+		idx = i = FIELD_GET(MT_PRXV_TX_RATE, v0);
+		mode = FIELD_GET(MT_PRXV_TX_MODE, v0);
 
-			idx = i = FIELD_GET(MT_PRXV_TX_RATE, v0);
-			mode = FIELD_GET(MT_CRXV_TX_MODE, v2);
-
-			switch (mode) {
-			case MT_PHY_TYPE_CCK:
-				cck = true;
-				fallthrough;
-			case MT_PHY_TYPE_OFDM:
-				i = mt76_get_rate(&dev->mt76, sband, i, cck);
-				break;
-			case MT_PHY_TYPE_HT_GF:
-			case MT_PHY_TYPE_HT:
-				status->encoding = RX_ENC_HT;
-				if (i > 31)
-					return -EINVAL;
-				break;
-			case MT_PHY_TYPE_VHT:
-				status->nss =
-					FIELD_GET(MT_PRXV_NSTS, v0) + 1;
-				status->encoding = RX_ENC_VHT;
-				if (i > 9)
-					return -EINVAL;
-				break;
-			case MT_PHY_TYPE_HE_MU:
-				status->flag |= RX_FLAG_RADIOTAP_HE_MU;
-				fallthrough;
-			case MT_PHY_TYPE_HE_SU:
-			case MT_PHY_TYPE_HE_EXT_SU:
-			case MT_PHY_TYPE_HE_TB:
-				status->nss =
-					FIELD_GET(MT_PRXV_NSTS, v0) + 1;
-				status->encoding = RX_ENC_HE;
-				status->flag |= RX_FLAG_RADIOTAP_HE;
-				i &= GENMASK(3, 0);
-
-				if (gi <= NL80211_RATE_INFO_HE_GI_3_2)
-					status->he_gi = gi;
-
-				status->he_dcm = !!(idx & MT_PRXV_TX_DCM);
-				break;
-			default:
+		switch (mode) {
+		case MT_PHY_TYPE_CCK:
+			cck = true;
+			fallthrough;
+		case MT_PHY_TYPE_OFDM:
+			i = mt76_get_rate(&dev->mt76, sband, i, cck);
+			break;
+		case MT_PHY_TYPE_HT_GF:
+		case MT_PHY_TYPE_HT:
+			status->encoding = RX_ENC_HT;
+			if (i > 31)
 				return -EINVAL;
-			}
-			status->rate_idx = i;
-
-			switch (FIELD_GET(MT_CRXV_FRAME_MODE, v2)) {
-			case IEEE80211_STA_RX_BW_20:
-				break;
-			case IEEE80211_STA_RX_BW_40:
-				if (mode & MT_PHY_TYPE_HE_EXT_SU &&
-				    (idx & MT_PRXV_TX_ER_SU_106T)) {
-					status->bw = RATE_INFO_BW_HE_RU;
-					status->he_ru =
-						NL80211_RATE_INFO_HE_RU_ALLOC_106;
-				} else {
-					status->bw = RATE_INFO_BW_40;
-				}
-				break;
-			case IEEE80211_STA_RX_BW_80:
-				status->bw = RATE_INFO_BW_80;
-				break;
-			case IEEE80211_STA_RX_BW_160:
-				status->bw = RATE_INFO_BW_160;
-				break;
-			default:
+			break;
+		case MT_PHY_TYPE_VHT:
+			status->nss =
+				FIELD_GET(MT_PRXV_NSTS, v0) + 1;
+			status->encoding = RX_ENC_VHT;
+			if (i > 9)
 				return -EINVAL;
+			break;
+		case MT_PHY_TYPE_HE_MU:
+			status->flag |= RX_FLAG_RADIOTAP_HE_MU;
+			fallthrough;
+		case MT_PHY_TYPE_HE_SU:
+		case MT_PHY_TYPE_HE_EXT_SU:
+		case MT_PHY_TYPE_HE_TB:
+			status->nss =
+				FIELD_GET(MT_PRXV_NSTS, v0) + 1;
+			status->encoding = RX_ENC_HE;
+			status->flag |= RX_FLAG_RADIOTAP_HE;
+			i &= GENMASK(3, 0);
+
+			if (gi <= NL80211_RATE_INFO_HE_GI_3_2)
+				status->he_gi = gi;
+
+			status->he_dcm = !!(idx & MT_PRXV_TX_DCM);
+			break;
+		default:
+			return -EINVAL;
+		}
+
+		status->rate_idx = i;
+
+		switch (FIELD_GET(MT_PRXV_FRAME_MODE, v0)) {
+		case IEEE80211_STA_RX_BW_20:
+			break;
+		case IEEE80211_STA_RX_BW_40:
+			if (mode & MT_PHY_TYPE_HE_EXT_SU &&
+			    (idx & MT_PRXV_TX_ER_SU_106T)) {
+				status->bw = RATE_INFO_BW_HE_RU;
+				status->he_ru =
+					NL80211_RATE_INFO_HE_RU_ALLOC_106;
+			} else {
+				status->bw = RATE_INFO_BW_40;
 			}
+			break;
+		case IEEE80211_STA_RX_BW_80:
+			status->bw = RATE_INFO_BW_80;
+			break;
+		case IEEE80211_STA_RX_BW_160:
+			status->bw = RATE_INFO_BW_160;
+			break;
+		default:
+			return -EINVAL;
+		}
+
+		status->enc_flags |= RX_ENC_FLAG_STBC_MASK * stbc;
+		if (mode < MT_PHY_TYPE_HE_SU && gi)
+			status->enc_flags |= RX_ENC_FLAG_SHORT_GI;
 
-			status->enc_flags |= RX_ENC_FLAG_STBC_MASK * stbc;
-			if (mode < MT_PHY_TYPE_HE_SU && gi)
-				status->enc_flags |= RX_ENC_FLAG_SHORT_GI;
+		if (rxd1 & MT_RXD1_NORMAL_GROUP_5) {
+			rxd += 18;
+			if ((u8 *)rxd - skb->data >= skb->len)
+				return -EINVAL;
 		}
 	}
 
diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mac.h b/drivers/net/wireless/mediatek/mt76/mt7921/mac.h
index a0c1fa0f20e4..109c8849d106 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/mac.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/mac.h
@@ -97,18 +97,24 @@ enum rx_pkt_type {
 #define MT_RXD3_NORMAL_PF_MODE		BIT(29)
 #define MT_RXD3_NORMAL_PF_STS		GENMASK(31, 30)
 
-/* P-RXV */
+/* P-RXV DW0 */
 #define MT_PRXV_TX_RATE			GENMASK(6, 0)
 #define MT_PRXV_TX_DCM			BIT(4)
 #define MT_PRXV_TX_ER_SU_106T		BIT(5)
 #define MT_PRXV_NSTS			GENMASK(9, 7)
 #define MT_PRXV_HT_AD_CODE		BIT(11)
+#define MT_PRXV_FRAME_MODE		GENMASK(14, 12)
+#define MT_PRXV_SGI			GENMASK(16, 15)
+#define MT_PRXV_STBC			GENMASK(23, 22)
+#define MT_PRXV_TX_MODE			GENMASK(27, 24)
 #define MT_PRXV_HE_RU_ALLOC_L		GENMASK(31, 28)
-#define MT_PRXV_HE_RU_ALLOC_H		GENMASK(3, 0)
+
+/* P-RXV DW1 */
 #define MT_PRXV_RCPI3			GENMASK(31, 24)
 #define MT_PRXV_RCPI2			GENMASK(23, 16)
 #define MT_PRXV_RCPI1			GENMASK(15, 8)
 #define MT_PRXV_RCPI0			GENMASK(7, 0)
+#define MT_PRXV_HE_RU_ALLOC_H		GENMASK(3, 0)
 
 /* C-RXV */
 #define MT_CRXV_HT_STBC			GENMASK(1, 0)
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 6/8] mt76: mt7921: add flush operation
  2021-02-19 17:28 [PATCH v2 0/8] mt76: mt7921: multiple fixes Lorenzo Bianconi
                   ` (4 preceding siblings ...)
  2021-02-19 17:28 ` [PATCH v2 5/8] mt76: mt7921: fixup rx bitrate statistics Lorenzo Bianconi
@ 2021-02-19 17:28 ` Lorenzo Bianconi
  2021-02-19 17:28 ` [PATCH v2 7/8] mt76: mt7921: fix uninitialized pointer access in mt7921_get_wtbl_info Lorenzo Bianconi
  2021-02-19 17:28 ` [PATCH v2 8/8] mt76: connac: update sched_scan cmd usage Lorenzo Bianconi
  7 siblings, 0 replies; 11+ messages in thread
From: Lorenzo Bianconi @ 2021-02-19 17:28 UTC (permalink / raw)
  To: nbd; +Cc: linux-wireless, lorenzo.bianconi, sean.wang

From: Sean Wang <sean.wang@mediatek.com>

add flush operation to make sure cfg80211_mlme_deauth is able to flush
the deauthtication frame into air immediately.

Co-developed-by: YN Chen <YN.Chen@mediatek.com>
Signed-off-by: YN Chen <YN.Chen@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/net/wireless/mediatek/mt76/mt7921/main.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/main.c b/drivers/net/wireless/mediatek/mt76/mt7921/main.c
index 11d85cf9cfb8..f7552f5201b4 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/main.c
@@ -1137,6 +1137,15 @@ static void mt7921_set_rekey_data(struct ieee80211_hw *hw,
 }
 #endif /* CONFIG_PM */
 
+static void mt7921_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+			 u32 queues, bool drop)
+{
+	struct mt7921_dev *dev = mt7921_hw_dev(hw);
+
+	wait_event_timeout(dev->mt76.tx_wait, !mt76_has_tx_pending(&dev->mphy),
+			   HZ / 2);
+}
+
 const struct ieee80211_ops mt7921_ops = {
 	.tx = mt7921_tx,
 	.start = mt7921_start,
@@ -1175,4 +1184,5 @@ const struct ieee80211_ops mt7921_ops = {
 	.set_wakeup = mt7921_set_wakeup,
 	.set_rekey_data = mt7921_set_rekey_data,
 #endif /* CONFIG_PM */
+	.flush = mt7921_flush,
 };
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 7/8] mt76: mt7921: fix uninitialized pointer access in mt7921_get_wtbl_info
  2021-02-19 17:28 [PATCH v2 0/8] mt76: mt7921: multiple fixes Lorenzo Bianconi
                   ` (5 preceding siblings ...)
  2021-02-19 17:28 ` [PATCH v2 6/8] mt76: mt7921: add flush operation Lorenzo Bianconi
@ 2021-02-19 17:28 ` Lorenzo Bianconi
  2021-02-19 17:28 ` [PATCH v2 8/8] mt76: connac: update sched_scan cmd usage Lorenzo Bianconi
  7 siblings, 0 replies; 11+ messages in thread
From: Lorenzo Bianconi @ 2021-02-19 17:28 UTC (permalink / raw)
  To: nbd; +Cc: linux-wireless, lorenzo.bianconi, sean.wang

From: Sean Wang <sean.wang@mediatek.com>

fix possible uninitialized pointer access in mt7921_get_wtbl_info
routine

[  270.073205] wlp1s0: deauthenticating from 9c:5c:8e:c9:93:14 by local choice (Reason: 3=DEAUTH_LEAVING)
[  270.094918] 8<--- cut here ---
[  270.097988] Unable to handle kernel NULL pointer dereference at virtual address 0000000a
[  270.106120] pgd = 7ac68838
[  270.108842] [0000000a] *pgd=00000000
[  270.112426] Internal error: Oops: 805 [#1] SMP ARM
[  270.117216] Modules linked in: mt7921e mt76_connac_lib mt76
[  270.122803] CPU: 0 PID: 7 Comm: kworker/u8:0 Tainted: G        W         5.11.0-rc2+ #67
[  270.130891] Hardware name: Mediatek Cortex-A7 (Device Tree)
[  270.136459] Workqueue: phy0 mt7921_mac_work [mt7921e]
[  270.141557] PC is at mt7921_get_wtbl_info+0x224/0x2d8 [mt7921e]
[  270.147498] LR is at 0x0
[  270.150026] pc : [<bf030398>]    lr : [<00000000>]    psr: 60000013

...

[  270.317696] 7fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[  270.325869] 7fe0: 00000000 00000000 00000000 00000000 00000013 00000000 00000000 00000000
[  270.334043] [<bf030398>] (mt7921_get_wtbl_info [mt7921e]) from [<bf02ea9c>] (mt7921_mac_work+0x298/0x2c0 [mt7921e])
[  270.344529] [<bf02ea9c>] (mt7921_mac_work [mt7921e]) from [<c013cde8>] (process_one_work+0x1f0/0x538)
[  270.353780] [<c013cde8>] (process_one_work) from [<c013d17c>] (worker_thread+0x4c/0x55c)
[  270.361874] [<c013d17c>] (worker_thread) from [<c01447a8>] (kthread+0x124/0x150)
[  270.369275] [<c01447a8>] (kthread) from [<c0100150>] (ret_from_fork+0x14/0x24)
[  270.376501] Exception stack(0xc19c7fb0 to 0xc19c7ff8)
[  270.381550] 7fa0:                                     00000000 00000000 00000000 00000000
[  270.389724] 7fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[  270.397896] 7fe0: 00000000 00000000 00000000 00000000 00000013 00000000
[  270.404509] Code: e59de012 e1cdc1b6 e1cdc1b8 e59dc016 (e582e00a)

Fixes: 1c099ab44727c ("mt76: mt7921: add MCU support")
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/net/wireless/mediatek/mt76/mt7921/mcu.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c
index d784c75d47bf..58de7f32a625 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c
@@ -404,11 +404,10 @@ mt7921_mcu_tx_rate_report(struct mt7921_dev *dev, struct sk_buff *skb,
 
 	if (wlan_idx >= MT76_N_WCIDS)
 		return;
+
 	wcid = rcu_dereference(dev->mt76.wcid[wlan_idx]);
-	if (!wcid) {
-		stats->tx_rate = rate;
+	if (!wcid)
 		return;
-	}
 
 	msta = container_of(wcid, struct mt7921_sta, wcid);
 	stats = &msta->stats;
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 8/8] mt76: connac: update sched_scan cmd usage
  2021-02-19 17:28 [PATCH v2 0/8] mt76: mt7921: multiple fixes Lorenzo Bianconi
                   ` (6 preceding siblings ...)
  2021-02-19 17:28 ` [PATCH v2 7/8] mt76: mt7921: fix uninitialized pointer access in mt7921_get_wtbl_info Lorenzo Bianconi
@ 2021-02-19 17:28 ` Lorenzo Bianconi
  7 siblings, 0 replies; 11+ messages in thread
From: Lorenzo Bianconi @ 2021-02-19 17:28 UTC (permalink / raw)
  To: nbd; +Cc: linux-wireless, lorenzo.bianconi, sean.wang

From: Sean Wang <sean.wang@mediatek.com>

Update sched_scan command usage according to the current firmware
submitted into linux-firmware.git.

Fixes: 80fc1e37c0eb ("mt76: mt7921: rely on mt76_connac_mcu module for sched_scan and hw_scan")
Co-developed-by: Soul Huang <Soul.Huang@mediatek.com>
Signed-off-by: Soul Huang <Soul.Huang@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h |  5 -----
 drivers/net/wireless/mediatek/mt76/mt76_connac.h   |  5 +++++
 .../net/wireless/mediatek/mt76/mt76_connac_mcu.c   |  7 +++++--
 .../net/wireless/mediatek/mt76/mt76_connac_mcu.h   | 14 +++++++++++---
 4 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h b/drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h
index 491841bc6291..5ef19fbee6bd 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h
@@ -408,11 +408,6 @@ static inline bool is_mt7615(struct mt76_dev *dev)
 	return mt76_chip(dev) == 0x7615 || mt76_chip(dev) == 0x7611;
 }
 
-static inline bool is_mt7663(struct mt76_dev *dev)
-{
-	return mt76_chip(dev) == 0x7663;
-}
-
 static inline bool is_mt7611(struct mt76_dev *dev)
 {
 	return mt76_chip(dev) == 0x7611;
diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac.h b/drivers/net/wireless/mediatek/mt76/mt76_connac.h
index 0d58606391b0..b811f3c410a1 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76_connac.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76_connac.h
@@ -73,6 +73,11 @@ static inline bool is_mt7921(struct mt76_dev *dev)
 	return mt76_chip(dev) == 0x7961;
 }
 
+static inline bool is_mt7663(struct mt76_dev *dev)
+{
+	return mt76_chip(dev) == 0x7663;
+}
+
 int mt76_connac_pm_wake(struct mt76_phy *phy, struct mt76_connac_pm *pm);
 void mt76_connac_power_save_sched(struct mt76_phy *phy,
 				  struct mt76_connac_pm *pm);
diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
index 81515419b5b6..125e02b34a5f 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
@@ -1438,10 +1438,13 @@ int mt76_connac_mcu_sched_scan_req(struct mt76_phy *phy,
 	req->version = 1;
 	req->seq_num = mvif->scan_seq_num | ext_phy << 7;
 
-	if (sreq->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
-		get_random_mask_addr(req->random_mac, sreq->mac_addr,
+	if (is_mt7663(phy->dev) &&
+	    (sreq->flags & NL80211_SCAN_FLAG_RANDOM_ADDR)) {
+		get_random_mask_addr(req->mt7663.random_mac, sreq->mac_addr,
 				     sreq->mac_addr_mask);
 		req->scan_func = 1;
+	} else if (is_mt7921(phy->dev)) {
+		req->mt7921.bss_idx = mvif->idx;
 	}
 
 	req->ssids_num = sreq->n_ssids;
diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h
index 9c26b90655a7..8478f019f5d3 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h
@@ -756,11 +756,19 @@ struct mt76_connac_sched_scan_req {
 	u8 channel_type;
 	u8 channels_num;
 	u8 intervals_num;
-	u8 scan_func; /* BIT(0) eable random mac address */
+	u8 scan_func; /* MT7663: BIT(0) eable random mac address */
 	struct mt76_connac_mcu_scan_channel channels[64];
 	__le16 intervals[MT76_CONNAC_MAX_SCHED_SCAN_INTERVAL];
-	u8 random_mac[ETH_ALEN]; /* valid when BIT(0) in scan_func is set */
-	u8 pad2[58];
+	union {
+		struct {
+			u8 random_mac[ETH_ALEN];
+			u8 pad2[58];
+		} mt7663;
+		struct {
+			u8 bss_idx;
+			u8 pad2[63];
+		} mt7921;
+	};
 } __packed;
 
 struct mt76_connac_sched_scan_done {
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 3/8] mt76: mt7921: switch to new api for hardware beacon filter
  2021-02-19 17:28 ` [PATCH v2 3/8] mt76: mt7921: switch to new api for hardware beacon filter Lorenzo Bianconi
@ 2021-02-24  5:28   ` Kalle Valo
  2021-02-24  8:36     ` Lorenzo Bianconi
  0 siblings, 1 reply; 11+ messages in thread
From: Kalle Valo @ 2021-02-24  5:28 UTC (permalink / raw)
  To: Lorenzo Bianconi; +Cc: nbd, linux-wireless, lorenzo.bianconi, sean.wang

Lorenzo Bianconi <lorenzo@kernel.org> writes:

> From: Sean Wang <sean.wang@mediatek.com>
>
> Current firmware only supports new api for enabling hardware beacon filter.
>
> Fixes: 1d8efc741df80 ("mt76: mt7921: introduce Runtime PM support")
> Beacon filter cmd have to rely on the associatied access point's beacon
> interval and DTIM information.
>
> Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>

The Fixes tag is in odd place.

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

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 3/8] mt76: mt7921: switch to new api for hardware beacon filter
  2021-02-24  5:28   ` Kalle Valo
@ 2021-02-24  8:36     ` Lorenzo Bianconi
  0 siblings, 0 replies; 11+ messages in thread
From: Lorenzo Bianconi @ 2021-02-24  8:36 UTC (permalink / raw)
  To: Kalle Valo; +Cc: nbd, linux-wireless, lorenzo.bianconi, sean.wang

[-- Attachment #1: Type: text/plain, Size: 795 bytes --]

> Lorenzo Bianconi <lorenzo@kernel.org> writes:
> 
> > From: Sean Wang <sean.wang@mediatek.com>
> >
> > Current firmware only supports new api for enabling hardware beacon filter.
> >
> > Fixes: 1d8efc741df80 ("mt76: mt7921: introduce Runtime PM support")
> > Beacon filter cmd have to rely on the associatied access point's beacon
> > interval and DTIM information.
> >
> > Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> 
> The Fixes tag is in odd place.

yes, I agree :)

@Felix: do I need to resubmit or can you take care of this?

Regards,
Lorenzo

> 
> -- 
> https://patchwork.kernel.org/project/linux-wireless/list/
> 
> https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-02-24  8:37 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-19 17:28 [PATCH v2 0/8] mt76: mt7921: multiple fixes Lorenzo Bianconi
2021-02-19 17:28 ` [PATCH v2 1/8] mt76: mt7921: fix suspend/resume sequence Lorenzo Bianconi
2021-02-19 17:28 ` [PATCH v2 2/8] mt76: mt7921: fix memory leak in mt7921_coredump_work Lorenzo Bianconi
2021-02-19 17:28 ` [PATCH v2 3/8] mt76: mt7921: switch to new api for hardware beacon filter Lorenzo Bianconi
2021-02-24  5:28   ` Kalle Valo
2021-02-24  8:36     ` Lorenzo Bianconi
2021-02-19 17:28 ` [PATCH v2 4/8] mt76: connac: fix up the setting for ht40 mode in mt76_connac_mcu_uni_add_bss Lorenzo Bianconi
2021-02-19 17:28 ` [PATCH v2 5/8] mt76: mt7921: fixup rx bitrate statistics Lorenzo Bianconi
2021-02-19 17:28 ` [PATCH v2 6/8] mt76: mt7921: add flush operation Lorenzo Bianconi
2021-02-19 17:28 ` [PATCH v2 7/8] mt76: mt7921: fix uninitialized pointer access in mt7921_get_wtbl_info Lorenzo Bianconi
2021-02-19 17:28 ` [PATCH v2 8/8] mt76: connac: update sched_scan cmd usage Lorenzo Bianconi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).