pci.c (c8e370feb361896376acc871e68408613034437b) pci.c (975e122ddb7cd6f67bff974d2ea00c5568d2014c)
1// SPDX-License-Identifier: ISC
2/* Copyright (C) 2020 MediaTek Inc.
3 *
4 */
5
6#include <linux/kernel.h>
7#include <linux/module.h>
8#include <linux/pci.h>

--- 27 unchanged lines hidden (view full) ---

36 else if (q == MT_RXQ_MCU_WA)
37 mt76_connac_irq_enable(mdev, MT_INT_RX_DONE_WM2);
38 else
39 mt76_connac_irq_enable(mdev, MT_INT_RX_DONE_WM);
40}
41
42static irqreturn_t mt7921_irq_handler(int irq, void *dev_instance)
43{
1// SPDX-License-Identifier: ISC
2/* Copyright (C) 2020 MediaTek Inc.
3 *
4 */
5
6#include <linux/kernel.h>
7#include <linux/module.h>
8#include <linux/pci.h>

--- 27 unchanged lines hidden (view full) ---

36 else if (q == MT_RXQ_MCU_WA)
37 mt76_connac_irq_enable(mdev, MT_INT_RX_DONE_WM2);
38 else
39 mt76_connac_irq_enable(mdev, MT_INT_RX_DONE_WM);
40}
41
42static irqreturn_t mt7921_irq_handler(int irq, void *dev_instance)
43{
44 struct mt7921_dev *dev = dev_instance;
44 struct mt792x_dev *dev = dev_instance;
45
46 mt76_wr(dev, MT_WFDMA0_HOST_INT_ENA, 0);
47
48 if (!test_bit(MT76_STATE_INITIALIZED, &dev->mphy.state))
49 return IRQ_NONE;
50
51 tasklet_schedule(&dev->mt76.irq_tasklet);
52
53 return IRQ_HANDLED;
54}
55
56static void mt7921_irq_tasklet(unsigned long data)
57{
45
46 mt76_wr(dev, MT_WFDMA0_HOST_INT_ENA, 0);
47
48 if (!test_bit(MT76_STATE_INITIALIZED, &dev->mphy.state))
49 return IRQ_NONE;
50
51 tasklet_schedule(&dev->mt76.irq_tasklet);
52
53 return IRQ_HANDLED;
54}
55
56static void mt7921_irq_tasklet(unsigned long data)
57{
58 struct mt7921_dev *dev = (struct mt7921_dev *)data;
58 struct mt792x_dev *dev = (struct mt792x_dev *)data;
59 u32 intr, mask = 0;
60
61 mt76_wr(dev, MT_WFDMA0_HOST_INT_ENA, 0);
62
63 intr = mt76_rr(dev, MT_WFDMA0_HOST_INT_STA);
64 intr &= dev->mt76.mmio.irqmask;
65 mt76_wr(dev, MT_WFDMA0_HOST_INT_STA, intr);
66

--- 25 unchanged lines hidden (view full) ---

92
93 if (intr & MT_INT_RX_DONE_WM2)
94 napi_schedule(&dev->mt76.napi[MT_RXQ_MCU_WA]);
95
96 if (intr & MT_INT_RX_DONE_DATA)
97 napi_schedule(&dev->mt76.napi[MT_RXQ_MAIN]);
98}
99
59 u32 intr, mask = 0;
60
61 mt76_wr(dev, MT_WFDMA0_HOST_INT_ENA, 0);
62
63 intr = mt76_rr(dev, MT_WFDMA0_HOST_INT_STA);
64 intr &= dev->mt76.mmio.irqmask;
65 mt76_wr(dev, MT_WFDMA0_HOST_INT_STA, intr);
66

--- 25 unchanged lines hidden (view full) ---

92
93 if (intr & MT_INT_RX_DONE_WM2)
94 napi_schedule(&dev->mt76.napi[MT_RXQ_MCU_WA]);
95
96 if (intr & MT_INT_RX_DONE_DATA)
97 napi_schedule(&dev->mt76.napi[MT_RXQ_MAIN]);
98}
99
100static int mt7921e_init_reset(struct mt7921_dev *dev)
100static int mt7921e_init_reset(struct mt792x_dev *dev)
101{
102 return mt7921_wpdma_reset(dev, true);
103}
104
101{
102 return mt7921_wpdma_reset(dev, true);
103}
104
105static void mt7921e_unregister_device(struct mt7921_dev *dev)
105static void mt7921e_unregister_device(struct mt792x_dev *dev)
106{
107 int i;
108 struct mt76_connac_pm *pm = &dev->pm;
109
110 cancel_work_sync(&dev->init_work);
111 mt76_unregister_device(&dev->mt76);
112 mt76_for_each_q_rx(&dev->mt76, i)
113 napi_disable(&dev->mt76.napi[i]);

--- 5 unchanged lines hidden (view full) ---

119 __mt7921_mcu_drv_pmctrl(dev);
120 mt7921_dma_cleanup(dev);
121 mt7921_wfsys_reset(dev);
122 skb_queue_purge(&dev->mt76.mcu.res_q);
123
124 tasklet_disable(&dev->mt76.irq_tasklet);
125}
126
106{
107 int i;
108 struct mt76_connac_pm *pm = &dev->pm;
109
110 cancel_work_sync(&dev->init_work);
111 mt76_unregister_device(&dev->mt76);
112 mt76_for_each_q_rx(&dev->mt76, i)
113 napi_disable(&dev->mt76.napi[i]);

--- 5 unchanged lines hidden (view full) ---

119 __mt7921_mcu_drv_pmctrl(dev);
120 mt7921_dma_cleanup(dev);
121 mt7921_wfsys_reset(dev);
122 skb_queue_purge(&dev->mt76.mcu.res_q);
123
124 tasklet_disable(&dev->mt76.irq_tasklet);
125}
126
127static u32 __mt7921_reg_addr(struct mt7921_dev *dev, u32 addr)
127static u32 __mt7921_reg_addr(struct mt792x_dev *dev, u32 addr)
128{
129 static const struct mt76_connac_reg_map fixed_map[] = {
130 { 0x820d0000, 0x30000, 0x10000 }, /* WF_LMAC_TOP (WF_WTBLON) */
131 { 0x820ed000, 0x24800, 0x00800 }, /* WF_LMAC_TOP BN0 (WF_MIB) */
132 { 0x820e4000, 0x21000, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_TMAC) */
133 { 0x820e7000, 0x21e00, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_DMA) */
134 { 0x820eb000, 0x24200, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_LPON) */
135 { 0x820e2000, 0x20800, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_AGG) */

--- 62 unchanged lines hidden (view full) ---

198 dev_err(dev->mt76.dev, "Access currently unsupported address %08x\n",
199 addr);
200
201 return 0;
202}
203
204static u32 mt7921_rr(struct mt76_dev *mdev, u32 offset)
205{
128{
129 static const struct mt76_connac_reg_map fixed_map[] = {
130 { 0x820d0000, 0x30000, 0x10000 }, /* WF_LMAC_TOP (WF_WTBLON) */
131 { 0x820ed000, 0x24800, 0x00800 }, /* WF_LMAC_TOP BN0 (WF_MIB) */
132 { 0x820e4000, 0x21000, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_TMAC) */
133 { 0x820e7000, 0x21e00, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_DMA) */
134 { 0x820eb000, 0x24200, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_LPON) */
135 { 0x820e2000, 0x20800, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_AGG) */

--- 62 unchanged lines hidden (view full) ---

198 dev_err(dev->mt76.dev, "Access currently unsupported address %08x\n",
199 addr);
200
201 return 0;
202}
203
204static u32 mt7921_rr(struct mt76_dev *mdev, u32 offset)
205{
206 struct mt7921_dev *dev = container_of(mdev, struct mt7921_dev, mt76);
206 struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
207 u32 addr = __mt7921_reg_addr(dev, offset);
208
209 return dev->bus_ops->rr(mdev, addr);
210}
211
212static void mt7921_wr(struct mt76_dev *mdev, u32 offset, u32 val)
213{
207 u32 addr = __mt7921_reg_addr(dev, offset);
208
209 return dev->bus_ops->rr(mdev, addr);
210}
211
212static void mt7921_wr(struct mt76_dev *mdev, u32 offset, u32 val)
213{
214 struct mt7921_dev *dev = container_of(mdev, struct mt7921_dev, mt76);
214 struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
215 u32 addr = __mt7921_reg_addr(dev, offset);
216
217 dev->bus_ops->wr(mdev, addr, val);
218}
219
220static u32 mt7921_rmw(struct mt76_dev *mdev, u32 offset, u32 mask, u32 val)
221{
215 u32 addr = __mt7921_reg_addr(dev, offset);
216
217 dev->bus_ops->wr(mdev, addr, val);
218}
219
220static u32 mt7921_rmw(struct mt76_dev *mdev, u32 offset, u32 mask, u32 val)
221{
222 struct mt7921_dev *dev = container_of(mdev, struct mt7921_dev, mt76);
222 struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
223 u32 addr = __mt7921_reg_addr(dev, offset);
224
225 return dev->bus_ops->rmw(mdev, addr, mask, val);
226}
227
228static int mt7921_pci_probe(struct pci_dev *pdev,
229 const struct pci_device_id *id)
230{

--- 20 unchanged lines hidden (view full) ---

251 .init_reset = mt7921e_init_reset,
252 .reset = mt7921e_mac_reset,
253 .mcu_init = mt7921e_mcu_init,
254 .drv_own = mt7921e_mcu_drv_pmctrl,
255 .fw_own = mt7921e_mcu_fw_pmctrl,
256 };
257 struct ieee80211_ops *ops;
258 struct mt76_bus_ops *bus_ops;
223 u32 addr = __mt7921_reg_addr(dev, offset);
224
225 return dev->bus_ops->rmw(mdev, addr, mask, val);
226}
227
228static int mt7921_pci_probe(struct pci_dev *pdev,
229 const struct pci_device_id *id)
230{

--- 20 unchanged lines hidden (view full) ---

251 .init_reset = mt7921e_init_reset,
252 .reset = mt7921e_mac_reset,
253 .mcu_init = mt7921e_mcu_init,
254 .drv_own = mt7921e_mcu_drv_pmctrl,
255 .fw_own = mt7921e_mcu_fw_pmctrl,
256 };
257 struct ieee80211_ops *ops;
258 struct mt76_bus_ops *bus_ops;
259 struct mt7921_dev *dev;
259 struct mt792x_dev *dev;
260 struct mt76_dev *mdev;
261 u8 features;
262 int ret;
263 u16 cmd;
264
265 ret = pcim_enable_device(pdev);
266 if (ret)
267 return ret;

--- 30 unchanged lines hidden (view full) ---

298 mdev = mt76_alloc_device(&pdev->dev, sizeof(*dev), ops, &drv_ops);
299 if (!mdev) {
300 ret = -ENOMEM;
301 goto err_free_pci_vec;
302 }
303
304 pci_set_drvdata(pdev, mdev);
305
260 struct mt76_dev *mdev;
261 u8 features;
262 int ret;
263 u16 cmd;
264
265 ret = pcim_enable_device(pdev);
266 if (ret)
267 return ret;

--- 30 unchanged lines hidden (view full) ---

298 mdev = mt76_alloc_device(&pdev->dev, sizeof(*dev), ops, &drv_ops);
299 if (!mdev) {
300 ret = -ENOMEM;
301 goto err_free_pci_vec;
302 }
303
304 pci_set_drvdata(pdev, mdev);
305
306 dev = container_of(mdev, struct mt7921_dev, mt76);
306 dev = container_of(mdev, struct mt792x_dev, mt76);
307 dev->fw_features = features;
308 dev->hif_ops = &mt7921_pcie_ops;
309 mt76_mmio_init(&dev->mt76, pcim_iomap_table(pdev)[0]);
310 tasklet_init(&mdev->irq_tasklet, mt7921_irq_tasklet, (unsigned long)dev);
311
312 dev->phy.dev = dev;
313 dev->phy.mt76 = &dev->mt76.phy;
314 dev->mt76.phy.priv = &dev->phy;

--- 53 unchanged lines hidden (view full) ---

368 pci_free_irq_vectors(pdev);
369
370 return ret;
371}
372
373static void mt7921_pci_remove(struct pci_dev *pdev)
374{
375 struct mt76_dev *mdev = pci_get_drvdata(pdev);
307 dev->fw_features = features;
308 dev->hif_ops = &mt7921_pcie_ops;
309 mt76_mmio_init(&dev->mt76, pcim_iomap_table(pdev)[0]);
310 tasklet_init(&mdev->irq_tasklet, mt7921_irq_tasklet, (unsigned long)dev);
311
312 dev->phy.dev = dev;
313 dev->phy.mt76 = &dev->mt76.phy;
314 dev->mt76.phy.priv = &dev->phy;

--- 53 unchanged lines hidden (view full) ---

368 pci_free_irq_vectors(pdev);
369
370 return ret;
371}
372
373static void mt7921_pci_remove(struct pci_dev *pdev)
374{
375 struct mt76_dev *mdev = pci_get_drvdata(pdev);
376 struct mt7921_dev *dev = container_of(mdev, struct mt7921_dev, mt76);
376 struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
377
378 mt7921e_unregister_device(dev);
379 devm_free_irq(&pdev->dev, pdev->irq, dev);
380 mt76_free_device(&dev->mt76);
381 pci_free_irq_vectors(pdev);
382}
383
384static int mt7921_pci_suspend(struct device *device)
385{
386 struct pci_dev *pdev = to_pci_dev(device);
387 struct mt76_dev *mdev = pci_get_drvdata(pdev);
377
378 mt7921e_unregister_device(dev);
379 devm_free_irq(&pdev->dev, pdev->irq, dev);
380 mt76_free_device(&dev->mt76);
381 pci_free_irq_vectors(pdev);
382}
383
384static int mt7921_pci_suspend(struct device *device)
385{
386 struct pci_dev *pdev = to_pci_dev(device);
387 struct mt76_dev *mdev = pci_get_drvdata(pdev);
388 struct mt7921_dev *dev = container_of(mdev, struct mt7921_dev, mt76);
388 struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
389 struct mt76_connac_pm *pm = &dev->pm;
390 int i, err;
391
392 pm->suspended = true;
393 flush_work(&dev->reset_work);
394 cancel_delayed_work_sync(&pm->ps_work);
395 cancel_work_sync(&pm->wake_work);
396

--- 57 unchanged lines hidden (view full) ---

454
455 return err;
456}
457
458static int mt7921_pci_resume(struct device *device)
459{
460 struct pci_dev *pdev = to_pci_dev(device);
461 struct mt76_dev *mdev = pci_get_drvdata(pdev);
389 struct mt76_connac_pm *pm = &dev->pm;
390 int i, err;
391
392 pm->suspended = true;
393 flush_work(&dev->reset_work);
394 cancel_delayed_work_sync(&pm->ps_work);
395 cancel_work_sync(&pm->wake_work);
396

--- 57 unchanged lines hidden (view full) ---

454
455 return err;
456}
457
458static int mt7921_pci_resume(struct device *device)
459{
460 struct pci_dev *pdev = to_pci_dev(device);
461 struct mt76_dev *mdev = pci_get_drvdata(pdev);
462 struct mt7921_dev *dev = container_of(mdev, struct mt7921_dev, mt76);
462 struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
463 struct mt76_connac_pm *pm = &dev->pm;
464 int i, err;
465
466 err = mt7921_mcu_drv_pmctrl(dev);
467 if (err < 0)
468 goto failed;
469
470 mt7921_wpdma_reinit_cond(dev);

--- 63 unchanged lines hidden ---
463 struct mt76_connac_pm *pm = &dev->pm;
464 int i, err;
465
466 err = mt7921_mcu_drv_pmctrl(dev);
467 if (err < 0)
468 goto failed;
469
470 mt7921_wpdma_reinit_cond(dev);

--- 63 unchanged lines hidden ---