developer | f79ad45 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 1 | From c5d0d7fb936620a3737fe5b71c1f59170ba42674 Mon Sep 17 00:00:00 2001 |
| 2 | From: Sujuan Chen <sujuan.chen@mediatek.com> |
| 3 | Date: Sun, 12 Jun 2022 16:38:45 +0800 |
| 4 | Subject: [PATCH 1/3] mt76 add wed tx support |
| 5 | |
| 6 | Signed-off-by: Sujuan Chen <sujuan.chen@mediatek.com> |
| 7 | --- |
| 8 | mt76_connac.h | 1 + |
| 9 | mt7915/dma.c | 59 +++++++++++++++++++------- |
| 10 | mt7915/mac.c | 4 +- |
| 11 | mt7915/mac.h | 0 |
| 12 | mt7915/main.c | 9 +++- |
| 13 | mt7915/mcu.c | 2 +- |
| 14 | mt7915/mmio.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++- |
| 15 | mt7915/mt7915.h | 2 + |
| 16 | mt7915/pci.c | 72 +------------------------------ |
| 17 | mt7915/regs.h | 15 +++++++ |
| 18 | mt7915/soc.c | 16 +++++-- |
| 19 | 11 files changed, 193 insertions(+), 97 deletions(-) |
| 20 | mode change 100644 => 100755 mt76_connac.h |
| 21 | mode change 100644 => 100755 mt7915/mac.h |
| 22 | mode change 100644 => 100755 mt7915/mmio.c |
| 23 | |
| 24 | diff --git a/mt76_connac.h b/mt76_connac.h |
| 25 | old mode 100644 |
| 26 | new mode 100755 |
| 27 | index 1d32d55b..3c493014 |
| 28 | --- a/mt76_connac.h |
| 29 | +++ b/mt76_connac.h |
| 30 | @@ -110,6 +110,7 @@ struct mt76_connac_sta_key_conf { |
| 31 | }; |
| 32 | |
| 33 | #define MT_TXP_MAX_BUF_NUM 6 |
| 34 | +#define MT_TXD_TXP_BUF_SIZE 128 |
| 35 | |
| 36 | struct mt76_connac_fw_txp { |
| 37 | __le16 flags; |
| 38 | diff --git a/mt7915/dma.c b/mt7915/dma.c |
| 39 | index 9e3d14db..71223221 100644 |
| 40 | --- a/mt7915/dma.c |
| 41 | +++ b/mt7915/dma.c |
| 42 | @@ -12,7 +12,10 @@ mt7915_init_tx_queues(struct mt7915_phy *phy, int idx, int n_desc, int ring_base |
| 43 | int i, err; |
| 44 | |
| 45 | if (mtk_wed_device_active(&phy->dev->mt76.mmio.wed)) { |
| 46 | - ring_base = MT_WED_TX_RING_BASE; |
| 47 | + if(!is_mt7986(&dev->mt76)) |
| 48 | + ring_base = MT_WED_TX_RING_BASE; |
| 49 | + else |
| 50 | + ring_base += MT_TXQ_ID(0) * MT_RING_SIZE; |
| 51 | idx -= MT_TXQ_ID(0); |
| 52 | } |
| 53 | |
| 54 | @@ -74,14 +77,23 @@ static void mt7915_dma_config(struct mt7915_dev *dev) |
| 55 | MCUQ_CONFIG(MT_MCUQ_WA, WFDMA1, MT_INT_TX_DONE_MCU_WA, MT7915_TXQ_MCU_WA); |
| 56 | MCUQ_CONFIG(MT_MCUQ_FWDL, WFDMA1, MT_INT_TX_DONE_FWDL, MT7915_TXQ_FWDL); |
| 57 | } else { |
| 58 | - RXQ_CONFIG(MT_RXQ_MAIN, WFDMA0, MT_INT_RX_DONE_BAND0_MT7916, MT7916_RXQ_BAND0); |
| 59 | + if(is_mt7916(&dev->mt76) && (mtk_wed_device_active(&dev->mt76.mmio.wed))) { |
| 60 | + RXQ_CONFIG(MT_RXQ_MAIN, WFDMA0, MT_INT_WED_RX_DONE_BAND0_MT7916, MT7916_RXQ_BAND0); |
| 61 | + RXQ_CONFIG(MT_RXQ_MCU_WA, WFDMA0, MT_INT_WED_RX_DONE_WA_MT7916, MT7916_RXQ_MCU_WA); |
| 62 | + RXQ_CONFIG(MT_RXQ_EXT, WFDMA0, MT_INT_WED_RX_DONE_BAND1_MT7916, MT7916_RXQ_BAND1); |
| 63 | + RXQ_CONFIG(MT_RXQ_MAIN_WA, WFDMA0, MT_INT_WED_RX_DONE_WA_MAIN_MT7916, MT7916_RXQ_MCU_WA_MAIN); |
| 64 | + TXQ_CONFIG(0, WFDMA0, MT_INT_WED_TX_DONE_BAND0, MT7915_TXQ_BAND0); |
| 65 | + TXQ_CONFIG(1, WFDMA0, MT_INT_WED_TX_DONE_BAND1, MT7915_TXQ_BAND1); |
| 66 | + } else { |
| 67 | + RXQ_CONFIG(MT_RXQ_MAIN, WFDMA0, MT_INT_RX_DONE_BAND0_MT7916, MT7916_RXQ_BAND0); |
| 68 | + RXQ_CONFIG(MT_RXQ_MCU_WA, WFDMA0, MT_INT_RX_DONE_WA, MT7916_RXQ_MCU_WA); |
| 69 | + RXQ_CONFIG(MT_RXQ_EXT, WFDMA0, MT_INT_RX_DONE_BAND1_MT7916, MT7916_RXQ_BAND1); |
| 70 | + RXQ_CONFIG(MT_RXQ_MAIN_WA, WFDMA0, MT_INT_RX_DONE_WA_MAIN_MT7916, MT7916_RXQ_MCU_WA_MAIN); |
| 71 | + TXQ_CONFIG(0, WFDMA0, MT_INT_TX_DONE_BAND0, MT7915_TXQ_BAND0); |
| 72 | + TXQ_CONFIG(1, WFDMA0, MT_INT_TX_DONE_BAND1, MT7915_TXQ_BAND1); |
| 73 | + } |
| 74 | RXQ_CONFIG(MT_RXQ_MCU, WFDMA0, MT_INT_RX_DONE_WM, MT7916_RXQ_MCU_WM); |
| 75 | - RXQ_CONFIG(MT_RXQ_MCU_WA, WFDMA0, MT_INT_RX_DONE_WA, MT7916_RXQ_MCU_WA); |
| 76 | - RXQ_CONFIG(MT_RXQ_EXT, WFDMA0, MT_INT_RX_DONE_BAND1_MT7916, MT7916_RXQ_BAND1); |
| 77 | RXQ_CONFIG(MT_RXQ_EXT_WA, WFDMA0, MT_INT_RX_DONE_WA_EXT_MT7916, MT7916_RXQ_MCU_WA_EXT); |
| 78 | - RXQ_CONFIG(MT_RXQ_MAIN_WA, WFDMA0, MT_INT_RX_DONE_WA_MAIN_MT7916, MT7916_RXQ_MCU_WA_MAIN); |
| 79 | - TXQ_CONFIG(0, WFDMA0, MT_INT_TX_DONE_BAND0, MT7915_TXQ_BAND0); |
| 80 | - TXQ_CONFIG(1, WFDMA0, MT_INT_TX_DONE_BAND1, MT7915_TXQ_BAND1); |
| 81 | MCUQ_CONFIG(MT_MCUQ_WM, WFDMA0, MT_INT_TX_DONE_MCU_WM, MT7915_TXQ_MCU_WM); |
| 82 | MCUQ_CONFIG(MT_MCUQ_WA, WFDMA0, MT_INT_TX_DONE_MCU_WA_MT7916, MT7915_TXQ_MCU_WA); |
| 83 | MCUQ_CONFIG(MT_MCUQ_FWDL, WFDMA0, MT_INT_TX_DONE_FWDL, MT7915_TXQ_FWDL); |
| 84 | @@ -330,7 +342,9 @@ static int mt7915_dma_enable(struct mt7915_dev *dev) |
| 85 | u32 wed_irq_mask = irq_mask; |
| 86 | |
| 87 | wed_irq_mask |= MT_INT_TX_DONE_BAND0 | MT_INT_TX_DONE_BAND1; |
| 88 | - mt76_wr(dev, MT_INT_WED_MASK_CSR, wed_irq_mask); |
| 89 | + if (!is_mt7986(&dev->mt76)) |
| 90 | + mt76_wr(dev, MT_INT_WED_MASK_CSR, wed_irq_mask); |
| 91 | + mt76_wr(dev, MT_INT_MASK_CSR, wed_irq_mask); |
| 92 | mtk_wed_device_start(&dev->mt76.mmio.wed, wed_irq_mask); |
| 93 | } |
| 94 | |
| 95 | @@ -355,15 +369,19 @@ int mt7915_dma_init(struct mt7915_dev *dev, struct mt7915_phy *phy2) |
| 96 | |
| 97 | mt7915_dma_disable(dev, true); |
| 98 | |
| 99 | - if (mtk_wed_device_active(&dev->mt76.mmio.wed)) { |
| 100 | + if (mtk_wed_device_active(&dev->mt76.mmio.wed) && !is_mt7986(mdev)) { |
| 101 | mt76_set(dev, MT_WFDMA_HOST_CONFIG, MT_WFDMA_HOST_CONFIG_WED); |
| 102 | - |
| 103 | + if(is_mt7915(mdev)) { |
| 104 | mt76_wr(dev, MT_WFDMA_WED_RING_CONTROL, |
| 105 | FIELD_PREP(MT_WFDMA_WED_RING_CONTROL_TX0, 18) | |
| 106 | FIELD_PREP(MT_WFDMA_WED_RING_CONTROL_TX1, 19) | |
| 107 | FIELD_PREP(MT_WFDMA_WED_RING_CONTROL_RX1, 1)); |
| 108 | - } else { |
| 109 | - mt76_clear(dev, MT_WFDMA_HOST_CONFIG, MT_WFDMA_HOST_CONFIG_WED); |
| 110 | + } else { |
| 111 | + mt76_wr(dev, MT_WFDMA_WED_RING_CONTROL, |
| 112 | + FIELD_PREP(MT_WFDMA_WED_RING_CONTROL_TX0, 18) | |
| 113 | + FIELD_PREP(MT_WFDMA_WED_RING_CONTROL_TX1, 19) | |
| 114 | + FIELD_PREP(MT_WFDMA_WED_RING_CONTROL_RX1, 2)); |
| 115 | + } |
| 116 | } |
| 117 | |
| 118 | /* init tx queue */ |
| 119 | @@ -417,7 +435,7 @@ int mt7915_dma_init(struct mt7915_dev *dev, struct mt7915_phy *phy2) |
| 120 | return ret; |
| 121 | |
| 122 | /* event from WA */ |
| 123 | - if (mtk_wed_device_active(&dev->mt76.mmio.wed)) { |
| 124 | + if (mtk_wed_device_active(&dev->mt76.mmio.wed) && is_mt7915(mdev)) { |
| 125 | wa_rx_base = MT_WED_RX_RING_BASE; |
| 126 | wa_rx_idx = MT7915_RXQ_MCU_WA; |
| 127 | dev->mt76.q_rx[MT_RXQ_MCU_WA].flags = MT_WED_Q_TXFREE; |
| 128 | @@ -444,11 +462,20 @@ int mt7915_dma_init(struct mt7915_dev *dev, struct mt7915_phy *phy2) |
| 129 | |
| 130 | /* tx free notify event from WA for band0 */ |
| 131 | if (!is_mt7915(mdev)) { |
| 132 | + wa_rx_base = MT_RXQ_RING_BASE(MT_RXQ_MAIN_WA); |
| 133 | + wa_rx_idx = MT_RXQ_ID(MT_RXQ_MAIN_WA); |
| 134 | + |
| 135 | + if (mtk_wed_device_active(&dev->mt76.mmio.wed)) { |
| 136 | + dev->mt76.q_rx[MT_RXQ_MAIN_WA].flags = MT_WED_Q_TXFREE; |
| 137 | + if (is_mt7916(mdev)) { |
| 138 | + wa_rx_base = MT_WED_RX_RING_BASE; |
| 139 | + wa_rx_idx = MT7915_RXQ_MCU_WA; |
| 140 | + } |
| 141 | + } |
| 142 | ret = mt76_queue_alloc(dev, &dev->mt76.q_rx[MT_RXQ_MAIN_WA], |
| 143 | - MT_RXQ_ID(MT_RXQ_MAIN_WA), |
| 144 | + wa_rx_idx, |
| 145 | MT7915_RX_MCU_RING_SIZE, |
| 146 | - MT_RX_BUF_SIZE, |
| 147 | - MT_RXQ_RING_BASE(MT_RXQ_MAIN_WA)); |
| 148 | + MT_RX_BUF_SIZE, wa_rx_base); |
| 149 | if (ret) |
| 150 | return ret; |
| 151 | } |
| 152 | diff --git a/mt7915/mac.c b/mt7915/mac.c |
| 153 | index fd0dd509..3f059bed 100644 |
| 154 | --- a/mt7915/mac.c |
| 155 | +++ b/mt7915/mac.c |
| 156 | @@ -833,9 +833,9 @@ u32 mt7915_wed_init_buf(void *ptr, dma_addr_t phys, int token_id) |
| 157 | |
| 158 | txp->token = cpu_to_le16(token_id); |
| 159 | txp->nbuf = 1; |
| 160 | - txp->buf[0] = cpu_to_le32(phys + MT_TXD_SIZE + sizeof(*txp)); |
| 161 | + txp->buf[0] = cpu_to_le32(phys + MT_TXD_TXP_BUF_SIZE); |
| 162 | |
| 163 | - return MT_TXD_SIZE + sizeof(*txp); |
| 164 | + return MT_TXD_TXP_BUF_SIZE; |
| 165 | } |
| 166 | |
| 167 | static void |
| 168 | diff --git a/mt7915/mac.h b/mt7915/mac.h |
| 169 | old mode 100644 |
| 170 | new mode 100755 |
| 171 | diff --git a/mt7915/main.c b/mt7915/main.c |
| 172 | index ebff255f..f1396eed 100644 |
| 173 | --- a/mt7915/main.c |
| 174 | +++ b/mt7915/main.c |
| 175 | @@ -1439,14 +1439,19 @@ mt7915_net_fill_forward_path(struct ieee80211_hw *hw, |
| 176 | if (!mtk_wed_device_active(wed)) |
| 177 | return -ENODEV; |
| 178 | |
| 179 | - if (msta->wcid.idx > 0xff) |
| 180 | + if (msta->wcid.idx > MT7915_WTBL_STA) |
| 181 | return -EIO; |
| 182 | |
| 183 | path->type = DEV_PATH_MTK_WDMA; |
| 184 | path->dev = ctx->dev; |
| 185 | path->mtk_wdma.wdma_idx = wed->wdma_idx; |
| 186 | path->mtk_wdma.bss = mvif->mt76.idx; |
| 187 | - path->mtk_wdma.wcid = msta->wcid.idx; |
| 188 | + /* fw will find the wcid by dest addr */ |
| 189 | + if(is_mt7915(&dev->mt76)) |
| 190 | + path->mtk_wdma.wcid = 0xff; |
| 191 | + else |
| 192 | + path->mtk_wdma.wcid = 0x3ff; |
| 193 | + |
| 194 | path->mtk_wdma.queue = phy != &dev->phy; |
| 195 | |
| 196 | ctx->dev = NULL; |
| 197 | diff --git a/mt7915/mcu.c b/mt7915/mcu.c |
| 198 | index 3344e122..9d2a7059 100644 |
| 199 | --- a/mt7915/mcu.c |
| 200 | +++ b/mt7915/mcu.c |
| 201 | @@ -2362,7 +2362,7 @@ int mt7915_run_firmware(struct mt7915_dev *dev) |
| 202 | if (ret) |
| 203 | return ret; |
| 204 | |
| 205 | - if (mtk_wed_device_active(&dev->mt76.mmio.wed)) |
| 206 | + if (mtk_wed_device_active(&dev->mt76.mmio.wed) && is_mt7915(&dev->mt76)) |
| 207 | mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(CAPABILITY), 0, 0, 0); |
| 208 | |
| 209 | ret = mt7915_mcu_set_mwds(dev, 1); |
| 210 | diff --git a/mt7915/mmio.c b/mt7915/mmio.c |
| 211 | old mode 100644 |
| 212 | new mode 100755 |
| 213 | index 6d1dbdbd..b4a3120d |
| 214 | --- a/mt7915/mmio.c |
| 215 | +++ b/mt7915/mmio.c |
| 216 | @@ -10,6 +10,9 @@ |
| 217 | #include "mac.h" |
| 218 | #include "../trace.h" |
| 219 | |
| 220 | +static bool wed_enable = true; |
| 221 | +module_param(wed_enable, bool, 0644); |
| 222 | + |
| 223 | static const u32 mt7915_reg[] = { |
| 224 | [INT_SOURCE_CSR] = 0xd7010, |
| 225 | [INT_MASK_CSR] = 0xd7014, |
| 226 | @@ -541,7 +544,11 @@ void mt7915_dual_hif_set_irq_mask(struct mt7915_dev *dev, |
| 227 | mdev->mmio.irqmask |= set; |
| 228 | |
| 229 | if (write_reg) { |
| 230 | - mt76_wr(dev, MT_INT_MASK_CSR, mdev->mmio.irqmask); |
| 231 | + if (mtk_wed_device_active(&mdev->mmio.wed)) |
| 232 | + mtk_wed_device_irq_set_mask(&mdev->mmio.wed, |
| 233 | + mdev->mmio.irqmask); |
| 234 | + else |
| 235 | + mt76_wr(dev, MT_INT_MASK_CSR, mdev->mmio.irqmask); |
| 236 | mt76_wr(dev, MT_INT1_MASK_CSR, mdev->mmio.irqmask); |
| 237 | } |
| 238 | |
| 239 | @@ -565,6 +572,8 @@ static void mt7915_irq_tasklet(struct tasklet_struct *t) |
| 240 | |
| 241 | if (mtk_wed_device_active(wed)) { |
| 242 | mtk_wed_device_irq_set_mask(wed, 0); |
| 243 | + if (dev->hif2) |
| 244 | + mt76_wr(dev, MT_INT1_MASK_CSR, 0); |
| 245 | intr = mtk_wed_device_irq_get(wed, dev->mt76.mmio.irqmask); |
| 246 | } else { |
| 247 | mt76_wr(dev, MT_INT_MASK_CSR, 0); |
| 248 | @@ -646,6 +655,105 @@ irqreturn_t mt7915_irq_handler(int irq, void *dev_instance) |
| 249 | return IRQ_HANDLED; |
| 250 | } |
| 251 | |
| 252 | +#ifdef CONFIG_NET_MEDIATEK_SOC_WED |
| 253 | +static int mt7915_wed_offload_enable(struct mtk_wed_device *wed) |
| 254 | +{ |
| 255 | + struct mt7915_dev *dev; |
| 256 | + int ret; |
| 257 | + |
| 258 | + dev = container_of(wed, struct mt7915_dev, mt76.mmio.wed); |
| 259 | + |
| 260 | + spin_lock_bh(&dev->mt76.token_lock); |
| 261 | + dev->mt76.token_size = wed->wlan.token_start; |
| 262 | + spin_unlock_bh(&dev->mt76.token_lock); |
| 263 | + |
| 264 | + ret = wait_event_timeout(dev->mt76.tx_wait, |
| 265 | + !dev->mt76.wed_token_count, HZ); |
| 266 | + if (!ret) |
| 267 | + return -EAGAIN; |
| 268 | + |
| 269 | + return 0; |
| 270 | +} |
| 271 | + |
| 272 | +static void mt7915_wed_offload_disable(struct mtk_wed_device *wed) |
| 273 | +{ |
| 274 | + struct mt7915_dev *dev; |
| 275 | + |
| 276 | + dev = container_of(wed, struct mt7915_dev, mt76.mmio.wed); |
| 277 | + |
| 278 | + spin_lock_bh(&dev->mt76.token_lock); |
| 279 | + dev->mt76.token_size = wed->wlan.token_start;//MT7915_TOKEN_SIZE; |
| 280 | + spin_unlock_bh(&dev->mt76.token_lock); |
| 281 | +} |
| 282 | +#endif |
| 283 | + |
| 284 | +int |
| 285 | +mt7915_pci_wed_init(struct mt7915_dev *dev, struct device *pdev, int *irq) |
| 286 | +{ |
| 287 | +#ifdef CONFIG_NET_MEDIATEK_SOC_WED |
| 288 | + struct mt76_dev *mdev = &dev->mt76; |
| 289 | + struct mtk_wed_device *wed = &dev->mt76.mmio.wed; |
| 290 | + u32 base; |
| 291 | + int ret; |
| 292 | + |
| 293 | + if (!wed_enable) |
| 294 | + return 0; |
| 295 | + |
| 296 | + if (dev_is_pci(pdev)) { |
| 297 | + struct pci_dev *pci_dev; |
| 298 | + |
| 299 | + pci_dev = container_of(pdev, struct pci_dev, dev); |
| 300 | + base = pci_resource_start(pci_dev, 0); |
| 301 | + wed->wlan.base = (void __iomem *)ioremap(base, pci_resource_len(pci_dev, 0)); |
| 302 | + |
| 303 | + wed->wlan.pci_dev = pci_dev; |
| 304 | + wed->wlan.bus_type = MTK_BUS_TYPE_PCIE; |
| 305 | + wed->wlan.wpdma_int = base + MT_INT_WED_SOURCE_CSR; |
| 306 | + wed->wlan.wpdma_mask = base + MT_INT_WED_MASK_CSR; |
| 307 | + } else { |
| 308 | + struct platform_device *plat_dev; |
| 309 | + struct resource *res; |
| 310 | + |
| 311 | + plat_dev = to_platform_device(pdev); |
| 312 | + res = platform_get_resource(plat_dev, IORESOURCE_MEM, 0); |
| 313 | + base = res->start; |
| 314 | + wed->wlan.base = (void __iomem *)ioremap(base, resource_size(res)); |
| 315 | + wed->wlan.bus_type = MTK_BUS_TYPE_AXI; |
| 316 | + wed->wlan.wpdma_int = base + MT_INT_SOURCE_CSR; |
| 317 | + wed->wlan.wpdma_mask = base + MT_INT_MASK_CSR; |
| 318 | + } |
| 319 | + wed->wlan.wpdma_tx = base + MT_TXQ_WED_RING_BASE; |
| 320 | + wed->wlan.wpdma_txfree = base + MT_RXQ_WED_RING_BASE; |
| 321 | + |
| 322 | + wed->wlan.tx_tbit[0] = MT_WED_TX_DONE_BAND0; |
| 323 | + wed->wlan.tx_tbit[1] = MT_WED_TX_DONE_BAND1; |
| 324 | + wed->wlan.txfree_tbit = MT_WED_TX_FREE_DONE; |
| 325 | + wed->wlan.nbuf = 7168; |
| 326 | + wed->wlan.token_start = MT7915_TOKEN_SIZE - wed->wlan.nbuf; |
| 327 | + wed->wlan.init_buf = mt7915_wed_init_buf; |
| 328 | + /* disable dynamic tx token */ |
| 329 | + wed->wlan.offload_enable = mt7915_wed_offload_enable; |
| 330 | + wed->wlan.offload_disable = mt7915_wed_offload_disable; |
| 331 | + |
| 332 | + if (mtk_wed_device_attach(wed) != 0) |
| 333 | + return 0; |
| 334 | + |
| 335 | + if (wed->ver == MTK_WED_V1) |
| 336 | + wed->wlan.wpdma_phys = base + MT_WFDMA_EXT_CSR_BASE; |
| 337 | + |
| 338 | + *irq = wed->irq; |
| 339 | + dev->mt76.dma_dev = wed->dev; |
| 340 | + mdev->token_size = wed->wlan.token_start; |
| 341 | + ret = dma_set_mask(wed->dev, DMA_BIT_MASK(32)); |
| 342 | + if (ret) |
| 343 | + return ret; |
| 344 | + |
| 345 | + return 1; |
| 346 | +#else |
| 347 | + return 0; |
| 348 | +#endif |
| 349 | +} |
| 350 | + |
| 351 | struct mt7915_dev *mt7915_mmio_probe(struct device *pdev, |
| 352 | void __iomem *mem_base, u32 device_id) |
| 353 | { |
| 354 | diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h |
| 355 | index 62350141..d7a2e594 100644 |
| 356 | --- a/mt7915/mt7915.h |
| 357 | +++ b/mt7915/mt7915.h |
| 358 | @@ -522,6 +522,8 @@ static inline void mt7986_wmac_disable(struct mt7915_dev *dev) |
| 359 | { |
| 360 | } |
| 361 | #endif |
| 362 | +int mt7915_pci_wed_init(struct mt7915_dev *dev, |
| 363 | + struct device *pdev, int *irq); |
| 364 | struct mt7915_dev *mt7915_mmio_probe(struct device *pdev, |
| 365 | void __iomem *mem_base, u32 device_id); |
| 366 | void mt7915_wfsys_reset(struct mt7915_dev *dev); |
| 367 | diff --git a/mt7915/pci.c b/mt7915/pci.c |
| 368 | index d74f6097..c5da01a9 100644 |
| 369 | --- a/mt7915/pci.c |
| 370 | +++ b/mt7915/pci.c |
| 371 | @@ -12,9 +12,6 @@ |
| 372 | #include "mac.h" |
| 373 | #include "../trace.h" |
| 374 | |
| 375 | -static bool wed_enable = false; |
| 376 | -module_param(wed_enable, bool, 0644); |
| 377 | - |
| 378 | static LIST_HEAD(hif_list); |
| 379 | static DEFINE_SPINLOCK(hif_lock); |
| 380 | static u32 hif_idx; |
| 381 | @@ -95,73 +92,6 @@ static int mt7915_pci_hif2_probe(struct pci_dev *pdev) |
| 382 | return 0; |
| 383 | } |
| 384 | |
| 385 | -#ifdef CONFIG_NET_MEDIATEK_SOC_WED |
| 386 | -static int mt7915_wed_offload_enable(struct mtk_wed_device *wed) |
| 387 | -{ |
| 388 | - struct mt7915_dev *dev; |
| 389 | - int ret; |
| 390 | - |
| 391 | - dev = container_of(wed, struct mt7915_dev, mt76.mmio.wed); |
| 392 | - |
| 393 | - spin_lock_bh(&dev->mt76.token_lock); |
| 394 | - dev->mt76.token_size = wed->wlan.token_start; |
| 395 | - spin_unlock_bh(&dev->mt76.token_lock); |
| 396 | - |
| 397 | - ret = wait_event_timeout(dev->mt76.tx_wait, |
| 398 | - !dev->mt76.wed_token_count, HZ); |
| 399 | - if (!ret) |
| 400 | - return -EAGAIN; |
| 401 | - |
| 402 | - return 0; |
| 403 | -} |
| 404 | - |
| 405 | -static void mt7915_wed_offload_disable(struct mtk_wed_device *wed) |
| 406 | -{ |
| 407 | - struct mt7915_dev *dev; |
| 408 | - |
| 409 | - dev = container_of(wed, struct mt7915_dev, mt76.mmio.wed); |
| 410 | - |
| 411 | - spin_lock_bh(&dev->mt76.token_lock); |
| 412 | - dev->mt76.token_size = MT7915_TOKEN_SIZE; |
| 413 | - spin_unlock_bh(&dev->mt76.token_lock); |
| 414 | -} |
| 415 | -#endif |
| 416 | - |
| 417 | -static int |
| 418 | -mt7915_pci_wed_init(struct mt7915_dev *dev, struct pci_dev *pdev, int *irq) |
| 419 | -{ |
| 420 | -#ifdef CONFIG_NET_MEDIATEK_SOC_WED |
| 421 | - struct mtk_wed_device *wed = &dev->mt76.mmio.wed; |
| 422 | - int ret; |
| 423 | - |
| 424 | - if (!wed_enable) |
| 425 | - return 0; |
| 426 | - |
| 427 | - wed->wlan.pci_dev = pdev; |
| 428 | - wed->wlan.wpdma_phys = pci_resource_start(pdev, 0) + |
| 429 | - MT_WFDMA_EXT_CSR_BASE; |
| 430 | - wed->wlan.nbuf = 4096; |
| 431 | - wed->wlan.token_start = MT7915_TOKEN_SIZE - wed->wlan.nbuf; |
| 432 | - wed->wlan.init_buf = mt7915_wed_init_buf; |
| 433 | - wed->wlan.offload_enable = mt7915_wed_offload_enable; |
| 434 | - wed->wlan.offload_disable = mt7915_wed_offload_disable; |
| 435 | - |
| 436 | - if (mtk_wed_device_attach(wed) != 0) |
| 437 | - return 0; |
| 438 | - |
| 439 | - *irq = wed->irq; |
| 440 | - dev->mt76.dma_dev = wed->dev; |
| 441 | - |
| 442 | - ret = dma_set_mask(wed->dev, DMA_BIT_MASK(32)); |
| 443 | - if (ret) |
| 444 | - return ret; |
| 445 | - |
| 446 | - return 1; |
| 447 | -#else |
| 448 | - return 0; |
| 449 | -#endif |
| 450 | -} |
| 451 | - |
| 452 | static int mt7915_pci_probe(struct pci_dev *pdev, |
| 453 | const struct pci_device_id *id) |
| 454 | { |
| 455 | @@ -199,7 +129,7 @@ static int mt7915_pci_probe(struct pci_dev *pdev, |
| 456 | mt7915_wfsys_reset(dev); |
| 457 | hif2 = mt7915_pci_init_hif2(pdev); |
| 458 | |
| 459 | - ret = mt7915_pci_wed_init(dev, pdev, &irq); |
| 460 | + ret = mt7915_pci_wed_init(dev, &pdev->dev, &irq); |
| 461 | if (ret < 0) |
| 462 | goto free_wed_or_irq_vector; |
| 463 | |
| 464 | diff --git a/mt7915/regs.h b/mt7915/regs.h |
| 465 | index 444440e1..ffda5f6b 100644 |
| 466 | --- a/mt7915/regs.h |
| 467 | +++ b/mt7915/regs.h |
| 468 | @@ -623,6 +623,7 @@ enum offs_rev { |
| 469 | #define MT_PCIE_RECOG_ID_MASK GENMASK(30, 0) |
| 470 | #define MT_PCIE_RECOG_ID_SEM BIT(31) |
| 471 | |
| 472 | +#define MT_INT_WED_SOURCE_CSR MT_WFDMA_EXT_CSR(0x200) |
| 473 | #define MT_INT_WED_MASK_CSR MT_WFDMA_EXT_CSR(0x204) |
| 474 | |
| 475 | #define MT_WED_TX_RING_BASE MT_WFDMA_EXT_CSR(0x300) |
| 476 | @@ -669,6 +670,13 @@ enum offs_rev { |
| 477 | #define MT_TXQ_EXT_CTRL(q) (MT_Q_BASE(__TXQ(q)) + 0x600 + \ |
| 478 | MT_TXQ_ID(q)* 0x4) |
| 479 | |
| 480 | +#define MT_TXQ_WED_RING_BASE (!is_mt7986(mdev)? 0xd7300 : 0x24420) |
| 481 | +#define MT_RXQ_WED_RING_BASE (!is_mt7986(mdev)? 0xd7410 : 0x24520) |
| 482 | + |
| 483 | +#define MT_WED_TX_DONE_BAND0 (is_mt7915(mdev)? 4 : 30) |
| 484 | +#define MT_WED_TX_DONE_BAND1 (is_mt7915(mdev)? 5 : 31) |
| 485 | +#define MT_WED_TX_FREE_DONE (is_mt7915(mdev)? 1 : 2) |
| 486 | + |
| 487 | #define MT_INT_SOURCE_CSR __REG(INT_SOURCE_CSR) |
| 488 | #define MT_INT_MASK_CSR __REG(INT_MASK_CSR) |
| 489 | |
| 490 | @@ -687,6 +695,11 @@ enum offs_rev { |
| 491 | #define MT_INT_RX_DONE_WA_MAIN_MT7916 BIT(2) |
| 492 | #define MT_INT_RX_DONE_WA_EXT_MT7916 BIT(3) |
| 493 | |
| 494 | +#define MT_INT_WED_RX_DONE_BAND0_MT7916 BIT(18) |
| 495 | +#define MT_INT_WED_RX_DONE_BAND1_MT7916 BIT(19) |
| 496 | +#define MT_INT_WED_RX_DONE_WA_MAIN_MT7916 BIT(1) |
| 497 | +#define MT_INT_WED_RX_DONE_WA_MT7916 BIT(17) |
| 498 | + |
| 499 | #define MT_INT_RX(q) (dev->q_int_mask[__RXQ(q)]) |
| 500 | #define MT_INT_TX_MCU(q) (dev->q_int_mask[(q)]) |
| 501 | |
| 502 | @@ -710,6 +723,8 @@ enum offs_rev { |
| 503 | #define MT_INT_TX_DONE_BAND0 BIT(30) |
| 504 | #define MT_INT_TX_DONE_BAND1 BIT(31) |
| 505 | #define MT_INT_TX_DONE_MCU_WA_MT7916 BIT(25) |
| 506 | +#define MT_INT_WED_TX_DONE_BAND0 BIT(4) |
| 507 | +#define MT_INT_WED_TX_DONE_BAND1 BIT(5) |
| 508 | |
| 509 | #define MT_INT_TX_DONE_MCU (MT_INT_TX_MCU(MT_MCUQ_WA) | \ |
| 510 | MT_INT_TX_MCU(MT_MCUQ_WM) | \ |
| 511 | diff --git a/mt7915/soc.c b/mt7915/soc.c |
| 512 | index 3618718d..8d0b2068 100644 |
| 513 | --- a/mt7915/soc.c |
| 514 | +++ b/mt7915/soc.c |
| 515 | @@ -1171,10 +1171,6 @@ static int mt7986_wmac_probe(struct platform_device *pdev) |
| 516 | |
| 517 | chip_id = (uintptr_t)of_device_get_match_data(&pdev->dev); |
| 518 | |
| 519 | - irq = platform_get_irq(pdev, 0); |
| 520 | - if (irq < 0) |
| 521 | - return irq; |
| 522 | - |
| 523 | mem_base = devm_platform_ioremap_resource(pdev, 0); |
| 524 | if (IS_ERR(mem_base)) { |
| 525 | dev_err(&pdev->dev, "Failed to get memory resource\n"); |
| 526 | @@ -1186,6 +1182,16 @@ static int mt7986_wmac_probe(struct platform_device *pdev) |
| 527 | return PTR_ERR(dev); |
| 528 | |
| 529 | mdev = &dev->mt76; |
| 530 | + ret = mt7915_pci_wed_init(dev, &pdev->dev, &irq); |
| 531 | + if (ret < 0) |
| 532 | + goto free_device; |
| 533 | + |
| 534 | + if (!ret) { |
| 535 | + irq = platform_get_irq(pdev, 0); |
| 536 | + if (irq < 0) |
| 537 | + return irq;; |
| 538 | + } |
| 539 | + |
| 540 | ret = devm_request_irq(mdev->dev, irq, mt7915_irq_handler, |
| 541 | IRQF_SHARED, KBUILD_MODNAME, dev); |
| 542 | if (ret) |
| 543 | @@ -1207,6 +1213,8 @@ free_irq: |
| 544 | devm_free_irq(mdev->dev, irq, dev); |
| 545 | |
| 546 | free_device: |
| 547 | + if (mtk_wed_device_active(&mdev->mmio.wed)) |
| 548 | + mtk_wed_device_detach(&mdev->mmio.wed); |
| 549 | mt76_free_device(&dev->mt76); |
| 550 | |
| 551 | return ret; |
| 552 | -- |
| 553 | 2.18.0 |
| 554 | |