linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 1/4] mt76: fix mt76_rates for the multiple devices
@ 2021-07-13 20:15 sean.wang
  2021-07-13 20:15 ` [PATCH v3 2/4] mt76: add mt76_default_basic_rate more devices can rely on sean.wang
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: sean.wang @ 2021-07-13 20:15 UTC (permalink / raw)
  To: nbd, lorenzo.bianconi
  Cc: sean.wang, Soul.Huang, YN.Chen, Leon.Yen, Eric-SY.Chang,
	Deren.Wu, km.lin, robin.chiu, ch.yeh, posh.sun, Eric.Liang,
	Stella.Chang, jemele, yenlinlai, linux-wireless, linux-mediatek

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

PHY offset in either .hw_value or .hw_value_short for mt7615, mt7663,
mt7915 and mt7921 device all start at bit 6, not 8.

Suggested-by: Ryder Lee <ryder.lee@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
---
v2: splitted out from the patch ("mt76: mt7921: fix mgmt frame using unexpected bitrate")
    to cover more devices which have the same issue.
v3: no change.
---
 drivers/net/wireless/mediatek/mt76/mac80211.c | 24 +++++++++----------
 drivers/net/wireless/mediatek/mt76/mt76.h     | 12 +++++-----
 .../net/wireless/mediatek/mt76/mt7603/init.c  | 19 +++++++++++++--
 .../net/wireless/mediatek/mt76/mt76x02_util.c | 16 ++++++-------
 4 files changed, 43 insertions(+), 28 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wireless/mediatek/mt76/mac80211.c
index d03aedc3286b..20b2423efc19 100644
--- a/drivers/net/wireless/mediatek/mt76/mac80211.c
+++ b/drivers/net/wireless/mediatek/mt76/mac80211.c
@@ -84,18 +84,18 @@ static const struct ieee80211_tpt_blink mt76_tpt_blink[] = {
 };
 
 struct ieee80211_rate mt76_rates[] = {
-	CCK_RATE(0, 10),
-	CCK_RATE(1, 20),
-	CCK_RATE(2, 55),
-	CCK_RATE(3, 110),
-	OFDM_RATE(11, 60),
-	OFDM_RATE(15, 90),
-	OFDM_RATE(10, 120),
-	OFDM_RATE(14, 180),
-	OFDM_RATE(9,  240),
-	OFDM_RATE(13, 360),
-	OFDM_RATE(8,  480),
-	OFDM_RATE(12, 540),
+	CCK_RATE(0, 10, 6),
+	CCK_RATE(1, 20, 6),
+	CCK_RATE(2, 55, 6),
+	CCK_RATE(3, 110, 6),
+	OFDM_RATE(11, 60, 6),
+	OFDM_RATE(15, 90, 6),
+	OFDM_RATE(10, 120, 6),
+	OFDM_RATE(14, 180, 6),
+	OFDM_RATE(9,  240, 6),
+	OFDM_RATE(13, 360, 6),
+	OFDM_RATE(8,  480, 6),
+	OFDM_RATE(12, 540, 6),
 };
 EXPORT_SYMBOL_GPL(mt76_rates);
 
diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
index 25c5ceef5257..e51ab917296d 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -755,17 +755,17 @@ enum mt76_phy_type {
 	MT_PHY_TYPE_HE_MU,
 };
 
-#define CCK_RATE(_idx, _rate) {					\
+#define CCK_RATE(_idx, _rate, _offset) {			\
 	.bitrate = _rate,					\
 	.flags = IEEE80211_RATE_SHORT_PREAMBLE,			\
-	.hw_value = (MT_PHY_TYPE_CCK << 8) | (_idx),		\
-	.hw_value_short = (MT_PHY_TYPE_CCK << 8) | (4 + _idx),	\
+	.hw_value = (MT_PHY_TYPE_CCK << (_offset)) | (_idx),		\
+	.hw_value_short = (MT_PHY_TYPE_CCK << (_offset)) | (4 + _idx),	\
 }
 
-#define OFDM_RATE(_idx, _rate) {				\
+#define OFDM_RATE(_idx, _rate, _offset) {			\
 	.bitrate = _rate,					\
-	.hw_value = (MT_PHY_TYPE_OFDM << 8) | (_idx),		\
-	.hw_value_short = (MT_PHY_TYPE_OFDM << 8) | (_idx),	\
+	.hw_value = (MT_PHY_TYPE_OFDM << (_offset)) | (_idx),	\
+	.hw_value_short = (MT_PHY_TYPE_OFDM << (_offset)) | (_idx), \
 }
 
 extern struct ieee80211_rate mt76_rates[12];
diff --git a/drivers/net/wireless/mediatek/mt76/mt7603/init.c b/drivers/net/wireless/mediatek/mt76/mt7603/init.c
index 031d39a48a55..59f684b08c55 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7603/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7603/init.c
@@ -304,6 +304,21 @@ mt7603_init_hardware(struct mt7603_dev *dev)
 	return 0;
 }
 
+static struct ieee80211_rate mt7603_rates[] = {
+	CCK_RATE(0, 10, 8),
+	CCK_RATE(1, 20, 8),
+	CCK_RATE(2, 55, 8),
+	CCK_RATE(3, 110, 8),
+	OFDM_RATE(11, 60, 8),
+	OFDM_RATE(15, 90, 8),
+	OFDM_RATE(10, 120, 8),
+	OFDM_RATE(14, 180, 8),
+	OFDM_RATE(9,  240, 8),
+	OFDM_RATE(13, 360, 8),
+	OFDM_RATE(8,  480, 8),
+	OFDM_RATE(12, 540, 8),
+};
+
 static const struct ieee80211_iface_limit if_limits[] = {
 	{
 		.max = 1,
@@ -541,8 +556,8 @@ int mt7603_register_device(struct mt7603_dev *dev)
 
 	wiphy->reg_notifier = mt7603_regd_notifier;
 
-	ret = mt76_register_device(&dev->mt76, true, mt76_rates,
-				   ARRAY_SIZE(mt76_rates));
+	ret = mt76_register_device(&dev->mt76, true, mt7603_rates,
+				   ARRAY_SIZE(mt7603_rates));
 	if (ret)
 		return ret;
 
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c b/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
index ccdbab341271..70a62bf16425 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
@@ -19,14 +19,14 @@ struct ieee80211_rate mt76x02_rates[] = {
 	MT76x02_CCK_RATE(1, 20),
 	MT76x02_CCK_RATE(2, 55),
 	MT76x02_CCK_RATE(3, 110),
-	OFDM_RATE(0, 60),
-	OFDM_RATE(1, 90),
-	OFDM_RATE(2, 120),
-	OFDM_RATE(3, 180),
-	OFDM_RATE(4, 240),
-	OFDM_RATE(5, 360),
-	OFDM_RATE(6, 480),
-	OFDM_RATE(7, 540),
+	OFDM_RATE(0, 60, 8),
+	OFDM_RATE(1, 90, 8),
+	OFDM_RATE(2, 120, 8),
+	OFDM_RATE(3, 180, 8),
+	OFDM_RATE(4, 240, 8),
+	OFDM_RATE(5, 360, 8),
+	OFDM_RATE(6, 480, 8),
+	OFDM_RATE(7, 540, 8),
 };
 EXPORT_SYMBOL_GPL(mt76x02_rates);
 
-- 
2.25.1


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

* [PATCH v3 2/4] mt76: add mt76_default_basic_rate more devices can rely on
  2021-07-13 20:15 [PATCH v3 1/4] mt76: fix mt76_rates for the multiple devices sean.wang
@ 2021-07-13 20:15 ` sean.wang
  2021-07-13 20:16 ` [PATCH v3 3/4] mt76: mt7921: fix mgmt frame using unexpected bitrate sean.wang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: sean.wang @ 2021-07-13 20:15 UTC (permalink / raw)
  To: nbd, lorenzo.bianconi
  Cc: sean.wang, Soul.Huang, YN.Chen, Leon.Yen, Eric-SY.Chang,
	Deren.Wu, km.lin, robin.chiu, ch.yeh, posh.sun, Eric.Liang,
	Stella.Chang, jemele, yenlinlai, linux-wireless, linux-mediatek

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

add mt76_default_basic_rate to mt76 core more devices can rely on
to send frames which require the rate in the basic rates.

Suggested-by: Ryder Lee <ryder.lee@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
---
v3:  created in v3 that is splitted out from the patch
     ("mt76: mt7921: fix mgmt frame using unexpected bitrate") v2
     for more mt76 devices like mt7915 can reuse.
---
 drivers/net/wireless/mediatek/mt76/mac80211.c | 14 ++++++++++++++
 drivers/net/wireless/mediatek/mt76/mt76.h     |  1 +
 2 files changed, 15 insertions(+)

diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wireless/mediatek/mt76/mac80211.c
index 20b2423efc19..56e80e0fb2c2 100644
--- a/drivers/net/wireless/mediatek/mt76/mac80211.c
+++ b/drivers/net/wireless/mediatek/mt76/mac80211.c
@@ -1336,3 +1336,17 @@ mt76_init_queue(struct mt76_dev *dev, int qid, int idx, int n_desc,
 	return hwq;
 }
 EXPORT_SYMBOL_GPL(mt76_init_queue);
+
+u16 mt76_default_basic_rate(struct mt76_phy *phy, struct ieee80211_vif *vif)
+{
+	int i = ffs(vif->bss_conf.basic_rates) - 1, offset = 0;
+	struct ieee80211_rate *rate;
+
+	if (phy->chandef.chan->band == NL80211_BAND_5GHZ)
+		offset = 4;
+
+	rate = &mt76_rates[offset + i];
+
+	return rate->hw_value;
+}
+EXPORT_SYMBOL_GPL(mt76_default_basic_rate);
diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
index e51ab917296d..d34d77967780 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -881,6 +881,7 @@ int mt76_get_of_eeprom(struct mt76_dev *dev, void *data, int offset, int len);
 struct mt76_queue *
 mt76_init_queue(struct mt76_dev *dev, int qid, int idx, int n_desc,
 		int ring_base);
+u16 mt76_default_basic_rate(struct mt76_phy *phy, struct ieee80211_vif *vif);
 static inline int mt76_init_tx_queue(struct mt76_phy *phy, int qid, int idx,
 				     int n_desc, int ring_base)
 {
-- 
2.25.1


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

* [PATCH v3 3/4] mt76: mt7921: fix mgmt frame using unexpected bitrate
  2021-07-13 20:15 [PATCH v3 1/4] mt76: fix mt76_rates for the multiple devices sean.wang
  2021-07-13 20:15 ` [PATCH v3 2/4] mt76: add mt76_default_basic_rate more devices can rely on sean.wang
@ 2021-07-13 20:16 ` sean.wang
  2021-07-13 20:16 ` [PATCH v3 4/4] mt76: mt7915: " sean.wang
  2021-07-15 18:09 ` [PATCH v3 1/4] mt76: fix mt76_rates for the multiple devices Felix Fietkau
  3 siblings, 0 replies; 5+ messages in thread
From: sean.wang @ 2021-07-13 20:16 UTC (permalink / raw)
  To: nbd, lorenzo.bianconi
  Cc: sean.wang, Soul.Huang, YN.Chen, Leon.Yen, Eric-SY.Chang,
	Deren.Wu, km.lin, robin.chiu, ch.yeh, posh.sun, Eric.Liang,
	Stella.Chang, jemele, yenlinlai, linux-wireless, linux-mediatek

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

Fix the current driver mgmt frame is not respecting the basic rates field
provided by the AP and then unconditionally is using the lowest (1 or 6
Mbps) rate.

For example, if the AP only supported basic rate {24, 36, 48, 54} Mbps,
mt7921 cannot send mgmt frame with the rate not in the group. So,
instead, we pick up the lowest basic rate the AP can support to send.

Fixes: 163f4d22c118 ("mt76: mt7921: add MAC support")
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
---
v2:  1. introduce another patch ("mt76: fix mt76_rates for the multiple devices")
	for those devices which have the same issue.
     2. drop the own mt7921_rates, the unused macro and variable.
v3:  1. introduce and rely on another patch
	("mt76: add mt76_default_basic_rate more devices can rely on").
     2. add Fixes tag.
---
 drivers/net/wireless/mediatek/mt76/mt7921/mac.c    | 5 +----
 drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h | 2 --
 2 files changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
index 7fe2e3a50428..a4ce362286eb 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
@@ -815,10 +815,7 @@ void mt7921_mac_write_txwi(struct mt7921_dev *dev, __le32 *txwi,
 		/* hardware won't add HTC for mgmt/ctrl frame */
 		txwi[2] |= cpu_to_le32(MT_TXD2_HTC_VLD);
 
-		if (mphy->chandef.chan->band == NL80211_BAND_5GHZ)
-			rate = MT7921_5G_RATE_DEFAULT;
-		else
-			rate = MT7921_2G_RATE_DEFAULT;
+		rate = mt76_default_basic_rate(mphy, vif);
 
 		val = MT_TXD6_FIXED_BW |
 		      FIELD_PREP(MT_TXD6_TX_RATE, rate);
diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h b/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h
index 2d8bd6bfc820..be16d528a923 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h
@@ -38,8 +38,6 @@
 
 #define MT7921_CFEND_RATE_DEFAULT	0x49	/* OFDM 24M */
 #define MT7921_CFEND_RATE_11B		0x03	/* 11B LP, 11M */
-#define MT7921_5G_RATE_DEFAULT		0x4b	/* OFDM 6M */
-#define MT7921_2G_RATE_DEFAULT		0x0	/* CCK 1M */
 
 #define MT7921_SKU_RATE_NUM		161
 #define MT7921_SKU_MAX_DELTA_IDX	MT7921_SKU_RATE_NUM
-- 
2.25.1


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

* [PATCH v3 4/4] mt76: mt7915: fix mgmt frame using unexpected bitrate
  2021-07-13 20:15 [PATCH v3 1/4] mt76: fix mt76_rates for the multiple devices sean.wang
  2021-07-13 20:15 ` [PATCH v3 2/4] mt76: add mt76_default_basic_rate more devices can rely on sean.wang
  2021-07-13 20:16 ` [PATCH v3 3/4] mt76: mt7921: fix mgmt frame using unexpected bitrate sean.wang
@ 2021-07-13 20:16 ` sean.wang
  2021-07-15 18:09 ` [PATCH v3 1/4] mt76: fix mt76_rates for the multiple devices Felix Fietkau
  3 siblings, 0 replies; 5+ messages in thread
From: sean.wang @ 2021-07-13 20:16 UTC (permalink / raw)
  To: nbd, lorenzo.bianconi
  Cc: sean.wang, Soul.Huang, YN.Chen, Leon.Yen, Eric-SY.Chang,
	Deren.Wu, km.lin, robin.chiu, ch.yeh, posh.sun, Eric.Liang,
	Stella.Chang, jemele, yenlinlai, linux-wireless, linux-mediatek

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

Fix the current driver mgmt frame is not respecting the basic rates field
provided by the AP and then unconditionally is using the lowest (1 or 6
Mbps) rate.

For example, if the AP only supported basic rate {24, 36, 48, 54} Mbps,
mt7921 cannot send mgmt frame with the rate not in the group. So,
instead, we pick up the lowest basic rate the AP can support to send.

Fixes: e57b7901469f ("mt76: add mac80211 driver for MT7915 PCIe-based chipsets")
Suggested-by: Ryder Lee <ryder.lee@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
---
v3: created in v3 to solve the same issue found in mt7921.
---
 drivers/net/wireless/mediatek/mt76/mt7915/mac.c    | 5 +----
 drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h | 2 --
 2 files changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mac.c b/drivers/net/wireless/mediatek/mt76/mt7915/mac.c
index 2462704094b0..b48249518459 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mac.c
@@ -979,10 +979,7 @@ void mt7915_mac_write_txwi(struct mt7915_dev *dev, __le32 *txwi,
 		/* hardware won't add HTC for mgmt/ctrl frame */
 		txwi[2] |= cpu_to_le32(MT_TXD2_HTC_VLD);
 
-		if (mphy->chandef.chan->band == NL80211_BAND_5GHZ)
-			rate = MT7915_5G_RATE_DEFAULT;
-		else
-			rate = MT7915_2G_RATE_DEFAULT;
+		rate = mt76_default_basic_rate(mphy, vif);
 
 		val = MT_TXD6_FIXED_BW |
 		      FIELD_PREP(MT_TXD6_TX_RATE, rate);
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h b/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
index 3f613fae6218..b41a31ad316d 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
@@ -36,8 +36,6 @@
 
 #define MT7915_CFEND_RATE_DEFAULT	0x49	/* OFDM 24M */
 #define MT7915_CFEND_RATE_11B		0x03	/* 11B LP, 11M */
-#define MT7915_5G_RATE_DEFAULT		0x4b	/* OFDM 6M */
-#define MT7915_2G_RATE_DEFAULT		0x0	/* CCK 1M */
 
 #define MT7915_THERMAL_THROTTLE_MAX	100
 
-- 
2.25.1


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

* Re: [PATCH v3 1/4] mt76: fix mt76_rates for the multiple devices
  2021-07-13 20:15 [PATCH v3 1/4] mt76: fix mt76_rates for the multiple devices sean.wang
                   ` (2 preceding siblings ...)
  2021-07-13 20:16 ` [PATCH v3 4/4] mt76: mt7915: " sean.wang
@ 2021-07-15 18:09 ` Felix Fietkau
  3 siblings, 0 replies; 5+ messages in thread
From: Felix Fietkau @ 2021-07-15 18:09 UTC (permalink / raw)
  To: sean.wang, lorenzo.bianconi
  Cc: Soul.Huang, YN.Chen, Leon.Yen, Eric-SY.Chang, Deren.Wu, km.lin,
	robin.chiu, ch.yeh, posh.sun, Eric.Liang, Stella.Chang, jemele,
	yenlinlai, linux-wireless, linux-mediatek


On 2021-07-13 22:15, sean.wang@mediatek.com wrote:
> From: Sean Wang <sean.wang@mediatek.com>
> 
> PHY offset in either .hw_value or .hw_value_short for mt7615, mt7663,
> mt7915 and mt7921 device all start at bit 6, not 8.
> 
> Suggested-by: Ryder Lee <ryder.lee@mediatek.com>
> Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Unfortunately this patch causes a few regressions.
Since tx and rx handling is different in their use of the PHY mode bits,
the PHY part should of hw_value should be masked out when filling the tx
rateval. There are a few places in the code that rely on the fixed shift
of 8, including the generic function mt76_get_rate.
This patch should be dropped, and the bit offset differences dealt with
in the other patches of this series.
I will send an updated version

- Felix

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

end of thread, other threads:[~2021-07-15 18:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-13 20:15 [PATCH v3 1/4] mt76: fix mt76_rates for the multiple devices sean.wang
2021-07-13 20:15 ` [PATCH v3 2/4] mt76: add mt76_default_basic_rate more devices can rely on sean.wang
2021-07-13 20:16 ` [PATCH v3 3/4] mt76: mt7921: fix mgmt frame using unexpected bitrate sean.wang
2021-07-13 20:16 ` [PATCH v3 4/4] mt76: mt7915: " sean.wang
2021-07-15 18:09 ` [PATCH v3 1/4] mt76: fix mt76_rates for the multiple devices Felix Fietkau

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).