Message ID | 210a8cd3ab6698401b55a3268719d194cc96e0b5.1631667941.git.objelf@gmail.com |
---|---|
State | New |
Headers | show |
Series | [v1,01/16] mt76: mt7921: refactor mac.c to be bus independent | expand |
> From: Sean Wang <sean.wang@mediatek.com> > > This is a preliminary patch to introduce mt7921s support. > > Make init.c reusable between mt7921s and mt7921e > > Tested-by: Deren Wu <deren.wu@mediatek.com> > Signed-off-by: Sean Wang <sean.wang@mediatek.com> > --- > .../wireless/mediatek/mt76/mt7921/Makefile | 4 +-- > .../net/wireless/mediatek/mt76/mt7921/dma.c | 8 ++++++ > .../net/wireless/mediatek/mt76/mt7921/init.c | 28 +------------------ > .../wireless/mediatek/mt76/mt7921/mt7921.h | 3 ++ > .../net/wireless/mediatek/mt76/mt7921/pci.c | 5 ++++ > .../wireless/mediatek/mt76/mt7921/pci_init.c | 26 +++++++++++++++++ > 6 files changed, 45 insertions(+), 29 deletions(-) > create mode 100644 drivers/net/wireless/mediatek/mt76/mt7921/pci_init.c > > diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/Makefile b/drivers/net/wireless/mediatek/mt76/mt7921/Makefile > index 4cb0b000cfe1..15f940a23ea9 100644 > --- a/drivers/net/wireless/mediatek/mt76/mt7921/Makefile > +++ b/drivers/net/wireless/mediatek/mt76/mt7921/Makefile > @@ -4,6 +4,6 @@ obj-$(CONFIG_MT7921E) += mt7921e.o > > CFLAGS_trace.o := -I$(src) > > -mt7921e-y := pci.o pci_mac.o pci_mcu.o mac.o mcu.o dma.o eeprom.o main.o \ > - init.o debugfs.o trace.o > +mt7921e-y := pci.o pci_mac.o pci_mcu.o pci_init.o mac.o mcu.o dma.o \ > + eeprom.o main.o init.o debugfs.o trace.o > mt7921e-$(CONFIG_NL80211_TESTMODE) += testmode.o > diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/dma.c b/drivers/net/wireless/mediatek/mt76/mt7921/dma.c > index d3e2036a1974..be24241fb8e6 100644 > --- a/drivers/net/wireless/mediatek/mt76/mt7921/dma.c > +++ b/drivers/net/wireless/mediatek/mt76/mt7921/dma.c > @@ -313,6 +313,11 @@ int mt7921_wpdma_reset(struct mt7921_dev *dev, bool force) > return 0; > } > > +int mt7921e_init_reset(struct mt7921_dev *dev) > +{ > + return mt7921_wpdma_reset(dev, true); > +} it seems used only in pci.c, right? maybe you can move it there and make it static. > + > int mt7921_wpdma_reinit_cond(struct mt7921_dev *dev) > { > struct mt76_connac_pm *pm = &dev->pm; > @@ -343,6 +348,9 @@ int mt7921_dma_init(struct mt7921_dev *dev) > struct mt76_bus_ops *bus_ops; > int ret; > > + dev->phy.dev = dev; > + dev->phy.mt76 = &dev->mt76.phy; > + dev->mt76.phy.priv = &dev->phy; > dev->bus_ops = dev->mt76.bus; > bus_ops = devm_kmemdup(dev->mt76.dev, dev->bus_ops, sizeof(*bus_ops), > GFP_KERNEL); > diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/init.c b/drivers/net/wireless/mediatek/mt76/mt7921/init.c > index 7c7a26102e11..f0fd32c424c6 100644 > --- a/drivers/net/wireless/mediatek/mt76/mt7921/init.c > +++ b/drivers/net/wireless/mediatek/mt76/mt7921/init.c > @@ -181,10 +181,6 @@ static int mt7921_init_hardware(struct mt7921_dev *dev) > { > int ret, idx, i; > > - ret = mt7921_dma_init(dev); > - if (ret) > - return ret; > - > set_bit(MT76_STATE_INITIALIZED, &dev->mphy.state); > > for (i = 0; i < MT7921_MCU_INIT_RETRY_COUNT; i++) { > @@ -192,7 +188,7 @@ static int mt7921_init_hardware(struct mt7921_dev *dev) > if (!ret) > break; > > - mt7921_wpdma_reset(dev, true); > + mt7921_init_reset(dev); > } > > if (i == MT7921_MCU_INIT_RETRY_COUNT) { > @@ -289,25 +285,3 @@ int mt7921_register_device(struct mt7921_dev *dev) > > return 0; > } > - > -void mt7921_unregister_device(struct mt7921_dev *dev) > -{ > - int i; > - struct mt76_connac_pm *pm = &dev->pm; > - > - mt76_unregister_device(&dev->mt76); > - mt76_for_each_q_rx(&dev->mt76, i) > - napi_disable(&dev->mt76.napi[i]); > - cancel_delayed_work_sync(&pm->ps_work); > - cancel_work_sync(&pm->wake_work); > - > - mt7921_tx_token_put(dev); > - mt7921_mcu_drv_pmctrl(dev); > - mt7921_dma_cleanup(dev); > - mt7921_wfsys_reset(dev); > - mt7921_mcu_exit(dev); > - mt7921_mcu_fw_pmctrl(dev); > - > - tasklet_disable(&dev->irq_tasklet); > - mt76_free_device(&dev->mt76); > -} > diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h b/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h > index dbace154bfa5..60f4552cb212 100644 > --- a/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h > +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h > @@ -133,11 +133,13 @@ struct mt7921_phy { > struct delayed_work scan_work; > }; > > +#define mt7921_init_reset(dev) ((dev)->hif_ops->init_reset(dev)) > #define mt7921_dev_reset(dev) ((dev)->hif_ops->reset(dev)) > #define mt7921_mcu_init(dev) ((dev)->hif_ops->mcu_init(dev)) > #define mt7921_drv_own(dev) ((dev)->hif_ops->drv_own(dev)) > #define mt7921_fw_own(dev) ((dev)->hif_ops->fw_own(dev)) > struct mt7921_hif_ops { > + int (*init_reset)(struct mt7921_dev *dev); > int (*reset)(struct mt7921_dev *dev); > int (*mcu_init)(struct mt7921_dev *dev); > int (*drv_own)(struct mt7921_dev *dev); > @@ -394,5 +396,6 @@ int mt7921e_mac_reset(struct mt7921_dev *dev); > int mt7921e_mcu_init(struct mt7921_dev *dev); > int mt7921e_mcu_drv_pmctrl(struct mt7921_dev *dev); > int mt7921e_mcu_fw_pmctrl(struct mt7921_dev *dev); > +int mt7921e_init_reset(struct mt7921_dev *dev); > > #endif > diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/pci.c b/drivers/net/wireless/mediatek/mt76/mt7921/pci.c > index b16bcee08cd7..f6bc3505b06a 100644 > --- a/drivers/net/wireless/mediatek/mt76/mt7921/pci.c > +++ b/drivers/net/wireless/mediatek/mt76/mt7921/pci.c > @@ -116,6 +116,7 @@ static int mt7921_pci_probe(struct pci_dev *pdev, > }; > > static const struct mt7921_hif_ops mt7921_pcie_ops = { > + .init_reset = mt7921e_init_reset, > .reset = mt7921e_mac_reset, > .mcu_init = mt7921e_mcu_init, > .drv_own = mt7921e_mcu_drv_pmctrl, > @@ -172,6 +173,10 @@ static int mt7921_pci_probe(struct pci_dev *pdev, > if (ret) > goto err_free_dev; > > + ret = mt7921_dma_init(dev); > + if (ret) > + goto err_free_irq; > + > ret = mt7921_register_device(dev); > if (ret) > goto err_free_irq; > diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/pci_init.c b/drivers/net/wireless/mediatek/mt76/mt7921/pci_init.c > new file mode 100644 > index 000000000000..4511fec79d43 > --- /dev/null > +++ b/drivers/net/wireless/mediatek/mt76/mt7921/pci_init.c > @@ -0,0 +1,26 @@ > +// SPDX-License-Identifier: ISC > +/* Copyright (C) 2021 MediaTek Inc. */ > + > +#include "mt7921.h" > + > +void mt7921_unregister_device(struct mt7921_dev *dev) same here, we have pci_init.c just for mt7921_unregister_device(). Just move it in pci.c and call it mt7921e_unregister_device(). Agree? Regards, Lorenzo > +{ > + int i; > + struct mt76_connac_pm *pm = &dev->pm; > + > + mt76_unregister_device(&dev->mt76); > + mt76_for_each_q_rx(&dev->mt76, i) > + napi_disable(&dev->mt76.napi[i]); > + cancel_delayed_work_sync(&pm->ps_work); > + cancel_work_sync(&pm->wake_work); > + > + mt7921_tx_token_put(dev); > + mt7921_mcu_drv_pmctrl(dev); > + mt7921_dma_cleanup(dev); > + mt7921_wfsys_reset(dev); > + mt7921_mcu_exit(dev); > + mt7921_mcu_fw_pmctrl(dev); > + > + tasklet_disable(&dev->irq_tasklet); > + mt76_free_device(&dev->mt76); > +} > -- > 2.25.1 >
diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/Makefile b/drivers/net/wireless/mediatek/mt76/mt7921/Makefile index 4cb0b000cfe1..15f940a23ea9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/Makefile +++ b/drivers/net/wireless/mediatek/mt76/mt7921/Makefile @@ -4,6 +4,6 @@ obj-$(CONFIG_MT7921E) += mt7921e.o CFLAGS_trace.o := -I$(src) -mt7921e-y := pci.o pci_mac.o pci_mcu.o mac.o mcu.o dma.o eeprom.o main.o \ - init.o debugfs.o trace.o +mt7921e-y := pci.o pci_mac.o pci_mcu.o pci_init.o mac.o mcu.o dma.o \ + eeprom.o main.o init.o debugfs.o trace.o mt7921e-$(CONFIG_NL80211_TESTMODE) += testmode.o diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/dma.c b/drivers/net/wireless/mediatek/mt76/mt7921/dma.c index d3e2036a1974..be24241fb8e6 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/dma.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/dma.c @@ -313,6 +313,11 @@ int mt7921_wpdma_reset(struct mt7921_dev *dev, bool force) return 0; } +int mt7921e_init_reset(struct mt7921_dev *dev) +{ + return mt7921_wpdma_reset(dev, true); +} + int mt7921_wpdma_reinit_cond(struct mt7921_dev *dev) { struct mt76_connac_pm *pm = &dev->pm; @@ -343,6 +348,9 @@ int mt7921_dma_init(struct mt7921_dev *dev) struct mt76_bus_ops *bus_ops; int ret; + dev->phy.dev = dev; + dev->phy.mt76 = &dev->mt76.phy; + dev->mt76.phy.priv = &dev->phy; dev->bus_ops = dev->mt76.bus; bus_ops = devm_kmemdup(dev->mt76.dev, dev->bus_ops, sizeof(*bus_ops), GFP_KERNEL); diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/init.c b/drivers/net/wireless/mediatek/mt76/mt7921/init.c index 7c7a26102e11..f0fd32c424c6 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/init.c @@ -181,10 +181,6 @@ static int mt7921_init_hardware(struct mt7921_dev *dev) { int ret, idx, i; - ret = mt7921_dma_init(dev); - if (ret) - return ret; - set_bit(MT76_STATE_INITIALIZED, &dev->mphy.state); for (i = 0; i < MT7921_MCU_INIT_RETRY_COUNT; i++) { @@ -192,7 +188,7 @@ static int mt7921_init_hardware(struct mt7921_dev *dev) if (!ret) break; - mt7921_wpdma_reset(dev, true); + mt7921_init_reset(dev); } if (i == MT7921_MCU_INIT_RETRY_COUNT) { @@ -289,25 +285,3 @@ int mt7921_register_device(struct mt7921_dev *dev) return 0; } - -void mt7921_unregister_device(struct mt7921_dev *dev) -{ - int i; - struct mt76_connac_pm *pm = &dev->pm; - - mt76_unregister_device(&dev->mt76); - mt76_for_each_q_rx(&dev->mt76, i) - napi_disable(&dev->mt76.napi[i]); - cancel_delayed_work_sync(&pm->ps_work); - cancel_work_sync(&pm->wake_work); - - mt7921_tx_token_put(dev); - mt7921_mcu_drv_pmctrl(dev); - mt7921_dma_cleanup(dev); - mt7921_wfsys_reset(dev); - mt7921_mcu_exit(dev); - mt7921_mcu_fw_pmctrl(dev); - - tasklet_disable(&dev->irq_tasklet); - mt76_free_device(&dev->mt76); -} diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h b/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h index dbace154bfa5..60f4552cb212 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h @@ -133,11 +133,13 @@ struct mt7921_phy { struct delayed_work scan_work; }; +#define mt7921_init_reset(dev) ((dev)->hif_ops->init_reset(dev)) #define mt7921_dev_reset(dev) ((dev)->hif_ops->reset(dev)) #define mt7921_mcu_init(dev) ((dev)->hif_ops->mcu_init(dev)) #define mt7921_drv_own(dev) ((dev)->hif_ops->drv_own(dev)) #define mt7921_fw_own(dev) ((dev)->hif_ops->fw_own(dev)) struct mt7921_hif_ops { + int (*init_reset)(struct mt7921_dev *dev); int (*reset)(struct mt7921_dev *dev); int (*mcu_init)(struct mt7921_dev *dev); int (*drv_own)(struct mt7921_dev *dev); @@ -394,5 +396,6 @@ int mt7921e_mac_reset(struct mt7921_dev *dev); int mt7921e_mcu_init(struct mt7921_dev *dev); int mt7921e_mcu_drv_pmctrl(struct mt7921_dev *dev); int mt7921e_mcu_fw_pmctrl(struct mt7921_dev *dev); +int mt7921e_init_reset(struct mt7921_dev *dev); #endif diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/pci.c b/drivers/net/wireless/mediatek/mt76/mt7921/pci.c index b16bcee08cd7..f6bc3505b06a 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/pci.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/pci.c @@ -116,6 +116,7 @@ static int mt7921_pci_probe(struct pci_dev *pdev, }; static const struct mt7921_hif_ops mt7921_pcie_ops = { + .init_reset = mt7921e_init_reset, .reset = mt7921e_mac_reset, .mcu_init = mt7921e_mcu_init, .drv_own = mt7921e_mcu_drv_pmctrl, @@ -172,6 +173,10 @@ static int mt7921_pci_probe(struct pci_dev *pdev, if (ret) goto err_free_dev; + ret = mt7921_dma_init(dev); + if (ret) + goto err_free_irq; + ret = mt7921_register_device(dev); if (ret) goto err_free_irq; diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/pci_init.c b/drivers/net/wireless/mediatek/mt76/mt7921/pci_init.c new file mode 100644 index 000000000000..4511fec79d43 --- /dev/null +++ b/drivers/net/wireless/mediatek/mt76/mt7921/pci_init.c @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: ISC +/* Copyright (C) 2021 MediaTek Inc. */ + +#include "mt7921.h" + +void mt7921_unregister_device(struct mt7921_dev *dev) +{ + int i; + struct mt76_connac_pm *pm = &dev->pm; + + mt76_unregister_device(&dev->mt76); + mt76_for_each_q_rx(&dev->mt76, i) + napi_disable(&dev->mt76.napi[i]); + cancel_delayed_work_sync(&pm->ps_work); + cancel_work_sync(&pm->wake_work); + + mt7921_tx_token_put(dev); + mt7921_mcu_drv_pmctrl(dev); + mt7921_dma_cleanup(dev); + mt7921_wfsys_reset(dev); + mt7921_mcu_exit(dev); + mt7921_mcu_fw_pmctrl(dev); + + tasklet_disable(&dev->irq_tasklet); + mt76_free_device(&dev->mt76); +}