blob: 873029f2fe0d8e701c26a10f954793ce6287a90f [file] [log] [blame]
developere35b8e42023-10-16 11:04:00 +08001From 3fdeeee1f24b09fc0d08b6a386e06c6146e83d9c Mon Sep 17 00:00:00 2001
developer281084d2023-06-19 12:03:50 +08002From: Shayne Chen <shayne.chen@mediatek.com>
3Date: Tue, 23 May 2023 15:49:03 +0800
developere35b8e42023-10-16 11:04:00 +08004Subject: [PATCH 07/98] wifi: mt76: mt7996: make band capability init flexible
developer281084d2023-06-19 12:03:50 +08005
6There're some variations of mt7996 chipset which only support two-band,
7so parse the adie combination to correctly set band capability.
8
9Change-Id: Ifcb49504f02f5cc6a23c626e30b4f0e1360fe157
10Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
11---
developere35b8e42023-10-16 11:04:00 +080012 mt7996/dma.c | 14 +++++++-------
developer281084d2023-06-19 12:03:50 +080013 mt7996/init.c | 29 ++++++++++++++++++-----------
14 mt7996/mcu.c | 13 +++++--------
15 mt7996/mt7996.h | 11 +++++++++++
16 mt7996/regs.h | 3 +++
developere35b8e42023-10-16 11:04:00 +080017 5 files changed, 44 insertions(+), 26 deletions(-)
developer281084d2023-06-19 12:03:50 +080018
19diff --git a/mt7996/dma.c b/mt7996/dma.c
developere35b8e42023-10-16 11:04:00 +080020index 2221d22..3d04470 100644
developer281084d2023-06-19 12:03:50 +080021--- a/mt7996/dma.c
22+++ b/mt7996/dma.c
developere35b8e42023-10-16 11:04:00 +080023@@ -222,13 +222,13 @@ void mt7996_dma_start(struct mt7996_dev *dev, bool reset, bool wed_reset)
24 /* enable interrupts for TX/RX rings */
25 irq_mask = MT_INT_MCU_CMD | MT_INT_RX_DONE_MCU | MT_INT_TX_DONE_MCU;
developer281084d2023-06-19 12:03:50 +080026
27- if (!dev->mphy.band_idx)
28+ if (mt7996_band_valid(dev, MT_BAND0))
29 irq_mask |= MT_INT_BAND0_RX_DONE;
30
31- if (dev->dbdc_support)
32+ if (mt7996_band_valid(dev, MT_BAND1))
33 irq_mask |= MT_INT_BAND1_RX_DONE;
34
35- if (dev->tbtc_support)
36+ if (mt7996_band_valid(dev, MT_BAND2))
37 irq_mask |= MT_INT_BAND2_RX_DONE;
38
developere35b8e42023-10-16 11:04:00 +080039 if (mtk_wed_device_active(wed) && wed_reset) {
40@@ -354,7 +354,7 @@ int mt7996_dma_rro_init(struct mt7996_dev *dev)
developer281084d2023-06-19 12:03:50 +080041 if (ret)
42 return ret;
43
developere35b8e42023-10-16 11:04:00 +080044- if (dev->dbdc_support) {
45+ if (mt7996_band_valid(dev, MT_BAND1)) {
46 /* rx msdu page queue for band1 */
47 mdev->q_rx[MT_RXQ_MSDU_PAGE_BAND1].flags =
48 MT_WED_RRO_Q_MSDU_PG(1) | MT_QFLAG_WED_RRO_EN;
49@@ -368,7 +368,7 @@ int mt7996_dma_rro_init(struct mt7996_dev *dev)
50 return ret;
51 }
52
53- if (dev->tbtc_support) {
54+ if (mt7996_band_valid(dev, MT_BAND2)) {
55 /* rx msdu page queue for band2 */
56 mdev->q_rx[MT_RXQ_MSDU_PAGE_BAND2].flags =
57 MT_WED_RRO_Q_MSDU_PG(2) | MT_QFLAG_WED_RRO_EN;
58@@ -488,7 +488,7 @@ int mt7996_dma_init(struct mt7996_dev *dev)
59 if (ret)
60 return ret;
61
developer281084d2023-06-19 12:03:50 +080062- if (dev->tbtc_support || dev->mphy.band_idx == MT_BAND2) {
63+ if (mt7996_band_valid(dev, MT_BAND2)) {
64 /* rx data queue for band2 */
developere35b8e42023-10-16 11:04:00 +080065 rx_base = MT_RXQ_RING_BASE(MT_RXQ_BAND2) + hif1_ofs;
developer281084d2023-06-19 12:03:50 +080066 ret = mt76_queue_alloc(dev, &dev->mt76.q_rx[MT_RXQ_BAND2],
developere35b8e42023-10-16 11:04:00 +080067@@ -542,7 +542,7 @@ int mt7996_dma_init(struct mt7996_dev *dev)
68 if (ret)
69 return ret;
70
71- if (dev->tbtc_support || dev->mphy.band_idx == MT_BAND2) {
72+ if (mt7996_band_valid(dev, MT_BAND2)) {
73 /* rx rro data queue for band2 */
74 dev->mt76.q_rx[MT_RXQ_RRO_BAND2].flags =
75 MT_WED_RRO_Q_DATA(1) | MT_QFLAG_WED_RRO_EN;
developer281084d2023-06-19 12:03:50 +080076diff --git a/mt7996/init.c b/mt7996/init.c
developere35b8e42023-10-16 11:04:00 +080077index de4a5f7..2e6efc5 100644
developer281084d2023-06-19 12:03:50 +080078--- a/mt7996/init.c
79+++ b/mt7996/init.c
developere35b8e42023-10-16 11:04:00 +080080@@ -539,11 +539,7 @@ static int mt7996_register_phy(struct mt7996_dev *dev, struct mt7996_phy *phy,
developer281084d2023-06-19 12:03:50 +080081 int ret;
developere35b8e42023-10-16 11:04:00 +080082 struct mtk_wed_device *wed = &dev->mt76.mmio.wed;
developer281084d2023-06-19 12:03:50 +080083
84- if (band != MT_BAND1 && band != MT_BAND2)
85- return 0;
86-
87- if ((band == MT_BAND1 && !dev->dbdc_support) ||
88- (band == MT_BAND2 && !dev->tbtc_support))
89+ if (!mt7996_band_valid(dev, band) || band == MT_BAND0)
90 return 0;
91
92 if (phy)
developere35b8e42023-10-16 11:04:00 +080093@@ -782,8 +778,10 @@ static int mt7996_init_hardware(struct mt7996_dev *dev)
developer281084d2023-06-19 12:03:50 +080094
95 INIT_WORK(&dev->init_work, mt7996_init_work);
96
97- dev->dbdc_support = true;
98- dev->tbtc_support = true;
99+ dev->dbdc_support = mt7996_band_valid(dev, MT_BAND1) ||
100+ mt7996_band_valid(dev, MT_BAND2);
101+ dev->tbtc_support = mt7996_band_valid(dev, MT_BAND1) &&
102+ mt7996_band_valid(dev, MT_BAND2);
103
104 ret = mt7996_dma_init(dev);
105 if (ret)
developere35b8e42023-10-16 11:04:00 +0800106@@ -1217,8 +1215,6 @@ int mt7996_register_device(struct mt7996_dev *dev)
developer281084d2023-06-19 12:03:50 +0800107 if (ret)
108 return ret;
109
110- ieee80211_queue_work(mt76_hw(dev), &dev->init_work);
111-
112 ret = mt7996_register_phy(dev, mt7996_phy2(dev), MT_BAND1);
113 if (ret)
114 return ret;
developere35b8e42023-10-16 11:04:00 +0800115@@ -1227,13 +1223,24 @@ int mt7996_register_device(struct mt7996_dev *dev)
developer281084d2023-06-19 12:03:50 +0800116 if (ret)
117 return ret;
118
119+ ieee80211_queue_work(mt76_hw(dev), &dev->init_work);
120+
121 dev->recovery.hw_init_done = true;
122
123 ret = mt7996_init_debugfs(&dev->phy);
124 if (ret)
125- return ret;
126+ goto error;
127
128- return mt7996_coredump_register(dev);
129+ ret = mt7996_coredump_register(dev);
130+ if (ret)
131+ goto error;
132+
133+ return 0;
134+
135+error:
136+ cancel_work_sync(&dev->init_work);
137+
138+ return ret;
139 }
140
141 void mt7996_unregister_device(struct mt7996_dev *dev)
142diff --git a/mt7996/mcu.c b/mt7996/mcu.c
developere35b8e42023-10-16 11:04:00 +0800143index 8320c8c..84f362b 100644
developer281084d2023-06-19 12:03:50 +0800144--- a/mt7996/mcu.c
145+++ b/mt7996/mcu.c
developer36fe7092023-09-27 12:24:47 +0800146@@ -2767,7 +2767,7 @@ mt7996_mcu_init_rx_airtime(struct mt7996_dev *dev)
developer281084d2023-06-19 12:03:50 +0800147 {
148 struct uni_header hdr = {};
149 struct sk_buff *skb;
150- int len, num;
151+ int len, num, i;
152
153 num = 2 + 2 * (dev->dbdc_support + dev->tbtc_support);
154 len = sizeof(hdr) + num * sizeof(struct vow_rx_airtime);
developer36fe7092023-09-27 12:24:47 +0800155@@ -2777,13 +2777,10 @@ mt7996_mcu_init_rx_airtime(struct mt7996_dev *dev)
developer281084d2023-06-19 12:03:50 +0800156
157 skb_put_data(skb, &hdr, sizeof(hdr));
158
159- mt7996_add_rx_airtime_tlv(skb, dev->mt76.phy.band_idx);
160-
161- if (dev->dbdc_support)
162- mt7996_add_rx_airtime_tlv(skb, MT_BAND1);
163-
164- if (dev->tbtc_support)
165- mt7996_add_rx_airtime_tlv(skb, MT_BAND2);
166+ for (i = 0; i < __MT_MAX_BAND; i++) {
167+ if (mt7996_band_valid(dev, i))
168+ mt7996_add_rx_airtime_tlv(skb, i);
169+ }
170
171 return mt76_mcu_skb_send_msg(&dev->mt76, skb,
172 MCU_WM_UNI_CMD(VOW), true);
173diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h
developere35b8e42023-10-16 11:04:00 +0800174index e1972e9..137d5a2 100644
developer281084d2023-06-19 12:03:50 +0800175--- a/mt7996/mt7996.h
176+++ b/mt7996/mt7996.h
developere35b8e42023-10-16 11:04:00 +0800177@@ -381,6 +381,17 @@ mt7996_phy3(struct mt7996_dev *dev)
developer281084d2023-06-19 12:03:50 +0800178 return __mt7996_phy(dev, MT_BAND2);
179 }
180
181+static inline bool
182+mt7996_band_valid(struct mt7996_dev *dev, u8 band)
183+{
184+ /* tri-band support */
185+ if (band <= MT_BAND2 &&
186+ mt76_get_field(dev, MT_PAD_GPIO, MT_PAD_GPIO_ADIE_COMB) <= 1)
187+ return true;
188+
189+ return band == MT_BAND0 || band == MT_BAND2;
190+}
191+
192 extern const struct ieee80211_ops mt7996_ops;
193 extern struct pci_driver mt7996_pci_driver;
194 extern struct pci_driver mt7996_hif_driver;
195diff --git a/mt7996/regs.h b/mt7996/regs.h
developere35b8e42023-10-16 11:04:00 +0800196index 854390d..a4d5ad8 100644
developer281084d2023-06-19 12:03:50 +0800197--- a/mt7996/regs.h
198+++ b/mt7996/regs.h
developere35b8e42023-10-16 11:04:00 +0800199@@ -602,6 +602,9 @@ enum base_rev {
developer281084d2023-06-19 12:03:50 +0800200 #define MT_TOP_MISC MT_TOP(0xf0)
201 #define MT_TOP_MISC_FW_STATE GENMASK(2, 0)
202
203+#define MT_PAD_GPIO 0x700056f0
204+#define MT_PAD_GPIO_ADIE_COMB GENMASK(16, 15)
205+
206 #define MT_HW_REV 0x70010204
207 #define MT_WF_SUBSYS_RST 0x70028600
208
209--
developer36fe7092023-09-27 12:24:47 +08002102.18.0
developer281084d2023-06-19 12:03:50 +0800211