Skip to contentSkip to conversation

mt76: mt7915: update mt7986 patch in mt7986_wmac_adie_patch_7976()

PATCH In review Peter Chiu 3 participants 8 messages May 5, 2022

Subsystems (2)
lore
Share & tools
lore

Peter Chiu

author
#0 lore raw

PATCH 1/4 mt76: mt7915: update mt7986 patch in mt7986_wmac_adie_patch_7976()

Update mt7976 adie patch for different adie version.

---
 .../net/wireless/mediatek/mt76/mt7915/regs.h  |  1 +
 .../net/wireless/mediatek/mt76/mt7915/soc.c   | 19 +++++++++++++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7915/regs.h +1 -0
index bac76bc2770f..338dfbee0f93 100644
@@ -797,6 +797,7 @@ enum offs_rev {
 
 /* ADIE */
 #define MT_ADIE_CHIP_ID			0x02c
+#define MT_ADIE_VERSION_MASK		GENMASK(15, 0)
 #define MT_ADIE_CHIP_ID_MASK		GENMASK(31, 16)
 #define MT_ADIE_IDX0			GENMASK(15, 0)
 #define MT_ADIE_IDX1			GENMASK(31, 16)
drivers/net/wireless/mediatek/mt76/mt7915/soc.c +17 -2
index 04e62d569599..c418b5dfda7f 100644
@@ -470,17 +470,32 @@ static int mt7986_wmac_adie_xtal_trim_7976(struct mt7915_dev *dev, u8 adie)
 
 static int mt7986_wmac_adie_patch_7976(struct mt7915_dev *dev, u8 adie)
 {
+	u32 id, version, rg_xo_01, rg_xo_03;
 	int ret;
 
+	ret = mt76_wmac_spi_read(dev, adie, MT_ADIE_CHIP_ID, &id);
+	if (ret)
+		return ret;
+
+	version = FIELD_GET(MT_ADIE_VERSION_MASK, id);
+
 	ret = mt76_wmac_spi_write(dev, adie, MT_ADIE_RG_TOP_THADC, 0x4a563b00);
 	if (ret)
 		return ret;
 
-	ret = mt76_wmac_spi_write(dev, adie, MT_ADIE_RG_XO_01, 0x1d59080f);
+	if (version == 0x8a00 || version == 0x8a10 || version == 0x8b00) {
+		rg_xo_01 = 0x1d59080f;
+		rg_xo_03 = 0x34c00fe0;
+	} else {
+		rg_xo_01 = 0x1959f80f;
+		rg_xo_03 = 0x34d00fe0;
+	}
+
+	ret = mt76_wmac_spi_write(dev, adie, MT_ADIE_RG_XO_01, rg_xo_01);
 	if (ret)
 		return ret;
 
-	return mt76_wmac_spi_write(dev, adie, MT_ADIE_RG_XO_03, 0x34c00fe0);
+	return mt76_wmac_spi_write(dev, adie, MT_ADIE_RG_XO_03, rg_xo_03);
 }
 
 static int
Signature · 1 line
2.18.0
author
#1 lore raw

PATCH 2/4 mt76: mt7915: fix twt table_mask to u16 in mt7915_dev

mt7915 can support 16 twt stations so modify table_mask to u16.

Fixes 3782b69d03e7 ("mt76: mt7915: introduce mt7915_mac_add_twt_setup routine")
---
 drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h +1 -1
index 6c590eff14f1..0f51d7657caf 100644
@@ -319,7 +319,7 @@ struct mt7915_dev {
 	void *cal;
 
 	struct {
-		u8 table_mask;
+		u16 table_mask;
 		u8 n_agrt;
 	} twt;
 
Signature · 1 line
2.18.0
author
#2 lore raw

PATCH 3/4 mt76: mt7915: reject duplicated twt flows

In reply to Peter Chiu

Reject twt flows with the same parameters to prevent some potential issues causing by duplicated establishment.

---
 .../net/wireless/mediatek/mt76/mt7915/mac.c   | 31 +++++++++++++++++++
 1 file changed, 31 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7915/mac.c +31 -0
index 94a1871fbf43..ff60a3d2d26d 100644
@@ -2601,6 +2601,34 @@ static int mt7915_mac_check_twt_req(struct ieee80211_twt_setup *twt)
 	return 0;
 }
 
+static inline bool
+mt7915_mac_twt_param_equal(struct mt7915_sta *msta,
+			   struct ieee80211_twt_params *twt_agrt)
+{
+	u16 type = le16_to_cpu(twt_agrt->req_type);
+	u8 exp;
+	int i;
+
+	exp = FIELD_GET(IEEE80211_TWT_REQTYPE_WAKE_INT_EXP, type);
+	for (i = 0; i < MT7915_MAX_STA_TWT_AGRT; i++) {
+		struct mt7915_twt_flow *f;
+
+		if (!(msta->twt.flowid_mask & BIT(i)))
+			continue;
+
+		f = &msta->twt.flow[i];
+		if (f->duration == twt_agrt->min_twt_dur &&
+		    f->mantissa == twt_agrt->mantissa &&
+		    f->exp == exp &&
+		    f->protection == !!(type & IEEE80211_TWT_REQTYPE_PROTECTION) &&
+		    f->flowtype == !!(type & IEEE80211_TWT_REQTYPE_FLOWTYPE) &&
+		    f->trigger == !!(type & IEEE80211_TWT_REQTYPE_TRIGGER))
+			return true;
+	}
+
+	return false;
+}
+
 void mt7915_mac_add_twt_setup(struct ieee80211_hw *hw,
 			      struct ieee80211_sta *sta,
 			      struct ieee80211_twt_setup *twt)
@@ -2634,6 +2662,9 @@ void mt7915_mac_add_twt_setup(struct ieee80211_hw *hw,
 	exp = FIELD_GET(IEEE80211_TWT_REQTYPE_WAKE_INT_EXP, req_type);
 	sta_setup_cmd = FIELD_GET(IEEE80211_TWT_REQTYPE_SETUP_CMD, req_type);
 
+	if (mt7915_mac_twt_param_equal(msta, twt_agrt))
+		goto unlock;
+
 	flow = &msta->twt.flow[flowid];
 	memset(flow, 0, sizeof(*flow));
 	INIT_LIST_HEAD(&flow->list);
Signature · 1 line
2.18.0
#3 lore raw

Re: [PATCH 3/4] mt76: mt7915: reject duplicated twt flows

Quoted 15 lines

Reject twt flows with the same parameters to prevent some potential issues causing by duplicated establishment.

---
 .../net/wireless/mediatek/mt76/mt7915/mac.c   | 31 +++++++++++++++++++
 1 file changed, 31 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7915/mac.c +0 -0
index 94a1871fbf43..ff60a3d2d26d 100644

drivers/net/wireless/mediatek/mt76/mt7915/mac.c static int mt7915_mac_check_twt_req(struct ieee80211_twt_setup *twt) · line 2606

Quoted 6 lines
drivers/net/wireless/mediatek/mt76/mt7915/mac.c +3 -0
@@ -2601,6 +2601,34 @@ static int mt7915_mac_check_twt_req(struct ieee80211_twt_setup *twt)
 	return 0;
 }
 
+static inline bool
+mt7915_mac_twt_param_equal(struct mt7915_sta *msta,
+			   struct ieee80211_twt_params *twt_agrt)

nit: please do not use inline in .c files.

Regards,
Lorenzo

Quoted 41 lines
drivers/net/wireless/mediatek/mt76/mt7915/mac.c +28 -0
+{
+	u16 type = le16_to_cpu(twt_agrt->req_type);
+	u8 exp;
+	int i;
+
+	exp = FIELD_GET(IEEE80211_TWT_REQTYPE_WAKE_INT_EXP, type);
+	for (i = 0; i < MT7915_MAX_STA_TWT_AGRT; i++) {
+		struct mt7915_twt_flow *f;
+
+		if (!(msta->twt.flowid_mask & BIT(i)))
+			continue;
+
+		f = &msta->twt.flow[i];
+		if (f->duration == twt_agrt->min_twt_dur &&
+		    f->mantissa == twt_agrt->mantissa &&
+		    f->exp == exp &&
+		    f->protection == !!(type & IEEE80211_TWT_REQTYPE_PROTECTION) &&
+		    f->flowtype == !!(type & IEEE80211_TWT_REQTYPE_FLOWTYPE) &&
+		    f->trigger == !!(type & IEEE80211_TWT_REQTYPE_TRIGGER))
+			return true;
+	}
+
+	return false;
+}
+
 void mt7915_mac_add_twt_setup(struct ieee80211_hw *hw,
 			      struct ieee80211_sta *sta,
 			      struct ieee80211_twt_setup *twt)
@@ -2634,6 +2662,9 @@ void mt7915_mac_add_twt_setup(struct ieee80211_hw *hw,
 	exp = FIELD_GET(IEEE80211_TWT_REQTYPE_WAKE_INT_EXP, req_type);
 	sta_setup_cmd = FIELD_GET(IEEE80211_TWT_REQTYPE_SETUP_CMD, req_type);
 
+	if (mt7915_mac_twt_param_equal(msta, twt_agrt))
+		goto unlock;
+
 	flow = &msta->twt.flow[flowid];
 	memset(flow, 0, sizeof(*flow));
 	INIT_LIST_HEAD(&flow->list);
Signature · 1 line
2.18.0
maintainer
#4 lore raw

Re: [PATCH 3/4] mt76: mt7915: reject duplicated twt flows

Quoted 18 lines · Lorenzo Bianconi
Quoted 18 lines

Reject twt flows with the same parameters to prevent some potential issues causing by duplicated establishment.

---
 .../net/wireless/mediatek/mt76/mt7915/mac.c   | 31 +++++++++++++++++++
 1 file changed, 31 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7915/mac.c +0 -0
index 94a1871fbf43..ff60a3d2d26d 100644
@@ -2601,6 +2601,34 @@ static int mt7915_mac_check_twt_req(struct ieee80211_twt_setup *twt)
 	return 0;
 }
 
Quoted 5 lines

drivers/net/wireless/mediatek/mt76/mt7915/mac.c static int mt7915_mac_check_twt_req(struct ieee80211_twt_setup *twt) · line 2606

Quoted 3 lines
drivers/net/wireless/mediatek/mt76/mt7915/mac.c +3 -0
+static inline bool
+mt7915_mac_twt_param_equal(struct mt7915_sta *msta,
+			   struct ieee80211_twt_params *twt_agrt)

nit: please do not use inline in .c files.

I applied the patch already, so I folded in a fix for this.

- Felix

author
#5 lore raw

PATCH 4/4 mt76: mt7915: limit minimum twt duration

In reply to Peter Chiu

The minimum twt duration supported by mt7915 is 64 according to hardware design. Reply station with TWT_SETUP_CMD_DICTATE if min_twt_dur smaller than 64.

---
 drivers/net/wireless/mediatek/mt76/mt7915/mac.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7915/mac.c +7 -0
index ff60a3d2d26d..e912ecacb578 100644
@@ -2633,6 +2633,7 @@ void mt7915_mac_add_twt_setup(struct ieee80211_hw *hw,
 			      struct ieee80211_sta *sta,
 			      struct ieee80211_twt_setup *twt)
 {
+#define MT7915_MIN_TWT_DUR 64
 	enum ieee80211_twt_setup_cmd setup_cmd = TWT_SETUP_CMD_REJECT;
 	struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv;
 	struct ieee80211_twt_params *twt_agrt = (void *)twt->params;
@@ -2654,6 +2655,12 @@ void mt7915_mac_add_twt_setup(struct ieee80211_hw *hw,
 	if (hweight8(msta->twt.flowid_mask) == ARRAY_SIZE(msta->twt.flow))
 		goto unlock;
 
+	if (twt_agrt->min_twt_dur < MT7915_MIN_TWT_DUR) {
+		setup_cmd = TWT_SETUP_CMD_DICTATE;
+		twt_agrt->min_twt_dur = MT7915_MIN_TWT_DUR;
+		goto unlock;
+	}
+
 	flowid = ffs(~msta->twt.flowid_mask) - 1;
 	le16p_replace_bits(&twt_agrt->req_type, flowid,
 			   IEEE80211_TWT_REQTYPE_FLOWID);
Signature · 1 line
2.18.0
#6 lore raw

Re: [PATCH 4/4] mt76: mt7915: limit minimum twt duration

Quoted 14 lines

The minimum twt duration supported by mt7915 is 64 according to hardware design. Reply station with TWT_SETUP_CMD_DICTATE if min_twt_dur smaller than 64.

---
 drivers/net/wireless/mediatek/mt76/mt7915/mac.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7915/mac.c +0 -0
index ff60a3d2d26d..e912ecacb578 100644

drivers/net/wireless/mediatek/mt76/mt7915/mac.c void mt7915_mac_add_twt_setup(struct ieee80211_hw *hw, · line 2636

Quoted 4 lines
drivers/net/wireless/mediatek/mt76/mt7915/mac.c +1 -0
@@ -2633,6 +2633,7 @@ void mt7915_mac_add_twt_setup(struct ieee80211_hw *hw,
 			      struct ieee80211_sta *sta,
 			      struct ieee80211_twt_setup *twt)
 {
+#define MT7915_MIN_TWT_DUR 64

nit: can you please move MT7915_MIN_TWT_DUR in mt7915.h since we have other twt defs there?

Regards,
Lorenzo

Quoted 19 lines
drivers/net/wireless/mediatek/mt76/mt7915/mac.c +6 -0
 	enum ieee80211_twt_setup_cmd setup_cmd = TWT_SETUP_CMD_REJECT;
 	struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv;
 	struct ieee80211_twt_params *twt_agrt = (void *)twt->params;
@@ -2654,6 +2655,12 @@ void mt7915_mac_add_twt_setup(struct ieee80211_hw *hw,
 	if (hweight8(msta->twt.flowid_mask) == ARRAY_SIZE(msta->twt.flow))
 		goto unlock;
 
+	if (twt_agrt->min_twt_dur < MT7915_MIN_TWT_DUR) {
+		setup_cmd = TWT_SETUP_CMD_DICTATE;
+		twt_agrt->min_twt_dur = MT7915_MIN_TWT_DUR;
+		goto unlock;
+	}
+
 	flowid = ffs(~msta->twt.flowid_mask) - 1;
 	le16p_replace_bits(&twt_agrt->req_type, flowid,
 			   IEEE80211_TWT_REQTYPE_FLOWID);
Signature · 1 line
2.18.0
maintainer
#7 lore raw

Re: [PATCH 4/4] mt76: mt7915: limit minimum twt duration

Quoted 9 lines · Lorenzo Bianconi
Quoted 9 lines

The minimum twt duration supported by mt7915 is 64 according to hardware design. Reply station with TWT_SETUP_CMD_DICTATE if min_twt_dur smaller than 64.

---
 drivers/net/wireless/mediatek/mt76/mt7915/mac.c | 7 +++++++
 1 file changed, 7 insertions(+)
Quoted 12 lines

drivers/net/wireless/mediatek/mt76/mt7915/mac.c void mt7915_mac_add_twt_setup(struct ieee80211_hw *hw, · line 2636

Quoted 9 lines
drivers/net/wireless/mediatek/mt76/mt7915/mac.c +1 -0
index ff60a3d2d26d..e912ecacb578 100644
@@ -2633,6 +2633,7 @@ void mt7915_mac_add_twt_setup(struct ieee80211_hw *hw,
 			      struct ieee80211_sta *sta,
 			      struct ieee80211_twt_setup *twt)
 {
+#define MT7915_MIN_TWT_DUR 64

nit: can you please move MT7915_MIN_TWT_DUR in mt7915.h since we have other twt defs there?

Fixed in my tree.

- Felix