mt76x{0,2}: move alloc_device common code in mt76_common module
Subsystems (2)
cover mt76x{0,2}: move alloc_device common code in mt76_common module
Move mt76x{0,2} alloc_device common code in mt76_alloc_device and remove duplicated code
Lorenzo Bianconi (4):
mt76: move alloc_device common code in mt76_alloc_device
mt76x2u: remove mt76x2u_alloc_device routine
mt76x0: remove mt76x0u_alloc_device routine
mt76x2: remove mt76x2_alloc_device routine
drivers/net/wireless/mediatek/mt76/mac80211.c | 7 ++++- drivers/net/wireless/mediatek/mt76/mt76.h | 5 ++-- .../net/wireless/mediatek/mt76/mt76x0/init.c | 22 --------------- .../wireless/mediatek/mt76/mt76x0/mt76x0.h | 4 --- .../net/wireless/mediatek/mt76/mt76x0/pci.c | 17 +++++++----- .../net/wireless/mediatek/mt76/mt76x0/usb.c | 22 ++++++++------- .../wireless/mediatek/mt76/mt76x2/mt76x2.h | 1 - .../wireless/mediatek/mt76/mt76x2/mt76x2u.h | 1 - .../net/wireless/mediatek/mt76/mt76x2/pci.c | 26 +++++++++++++----- .../wireless/mediatek/mt76/mt76x2/pci_init.c | 27 ------------------- .../net/wireless/mediatek/mt76/mt76x2/usb.c | 24 ++++++++++++----- .../wireless/mediatek/mt76/mt76x2/usb_init.c | 24 ----------------- 12 files changed, 71 insertions(+), 109 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/4 mt76: move alloc_device common code in mt76_alloc_device
Move mt76x{0,2} alloc_device common code in mt76_alloc_device and remove duplicated code
--- drivers/net/wireless/mediatek/mt76/mac80211.c | 7 ++++++- drivers/net/wireless/mediatek/mt76/mt76.h | 5 +++-- drivers/net/wireless/mediatek/mt76/mt76x0/init.c | 5 +---- drivers/net/wireless/mediatek/mt76/mt76x2/pci_init.c | 5 ++--- drivers/net/wireless/mediatek/mt76/mt76x2/usb_init.c | 5 ++--- 5 files changed, 14 insertions(+), 13 deletions(-)
drivers/net/wireless/mediatek/mt76/mac80211.c +6 -1
@@ -269,7 +269,9 @@ mt76_check_sband(struct mt76_dev *dev, int band) }struct mt76_dev * -mt76_alloc_device (unsigned int size,const struct ieee80211_ops *ops) +mt76_alloc_device (struct device *pdev,unsigned int size, +const struct ieee80211_ops *ops, +const struct mt76_driver_ops *drv_ops) {struct ieee80211_hw *hw;struct mt76_dev *dev;
@@ -280,6 +282,9 @@ mt76_alloc_device(unsigned int size, const struct ieee80211_ops *ops) dev = hw->priv; dev->hw = hw; + dev->dev = pdev; + dev->drv = drv_ops; +spin_lock_init (&dev->rx_lock);spin_lock_init (&dev->lock);spin_lock_init (&dev->cc_lock);
drivers/net/wireless/mediatek/mt76/mt76.h +3 -2
@@ -603,8 +603,9 @@ mt76_channel_state(struct mt76_dev *dev, struct ieee80211_channel *c)return &msband->chan[idx]; } -struct mt76_dev *mt76_alloc_device (unsigned int size, -const struct ieee80211_ops *ops); +struct mt76_dev *mt76_alloc_device (struct device *pdev,unsigned int size, +const struct ieee80211_ops *ops, +const struct mt76_driver_ops *drv_ops);int mt76_register_device (struct mt76_dev *dev,bool vht,struct ieee80211_rate *rates,int n_rates);void mt76_unregister_device (struct mt76_dev *dev);
drivers/net/wireless/mediatek/mt76/mt76x0/init.c +1 -4
@@ -270,13 +270,10 @@ mt76x0_alloc_device(struct device *pdev,struct mt76x02_dev *dev;struct mt76_dev *mdev; - mdev =mt76_alloc_device (sizeof (*dev), ops); + mdev =mt76_alloc_device (pdev,sizeof (*dev), ops, drv_ops);if (!mdev)return NULL ; - mdev->dev = pdev; - mdev->drv = drv_ops; - dev = container_of(mdev, struct mt76x02_dev, mt76);mutex_init (&dev->phy_mutex);
drivers/net/wireless/mediatek/mt76/mt76x2/pci_init.c +2 -3
@@ -331,13 +331,12 @@ struct mt76x02_dev *mt76x2_alloc_device(struct device *pdev)struct mt76x02_dev *dev;struct mt76_dev *mdev; - mdev =mt76_alloc_device (sizeof (*dev), &mt76x2_ops); + mdev =mt76_alloc_device (pdev,sizeof (*dev), &mt76x2_ops, + &drv_ops);if (!mdev)return NULL ; dev = container_of(mdev, struct mt76x02_dev, mt76); - mdev->dev = pdev; - mdev->drv = &drv_ops;return dev; }
drivers/net/wireless/mediatek/mt76/mt76x2/usb_init.c +2 -3
@@ -147,13 +147,12 @@ struct mt76x02_dev *mt76x2u_alloc_device(struct device *pdev)struct mt76x02_dev *dev;struct mt76_dev *mdev; - mdev =mt76_alloc_device (sizeof (*dev), &mt76x2u_ops); + mdev =mt76_alloc_device (pdev,sizeof (*dev), &mt76x2u_ops, + &drv_ops);if (!mdev)return NULL ; dev = container_of(mdev, struct mt76x02_dev, mt76); - mdev->dev = pdev; - mdev->drv = &drv_ops;return dev; }
Signature · 1 line
2.20.1
PATCH 2/4 mt76x2u: remove mt76x2u_alloc_device routine
In reply to Lorenzo BianconiRemove mt76x2u_alloc_device since it just runs mt76_alloc_device. Move mt76_alloc_device call in mt76x2u_probe
--- .../wireless/mediatek/mt76/mt76x2/mt76x2u.h | 1 - .../net/wireless/mediatek/mt76/mt76x2/usb.c | 24 ++++++++++++++----- .../wireless/mediatek/mt76/mt76x2/usb_init.c | 23 ------------------ 3 files changed, 18 insertions(+), 30 deletions(-)
drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2u.h +0 -1
@@ -29,7 +29,6 @@extern const struct ieee80211_ops mt76x2u_ops; -struct mt76x02_dev *mt76x2u_alloc_device (struct device *pdev);int mt76x2u_register_device (struct mt76x02_dev *dev);int mt76x2u_init_hardware (struct mt76x02_dev *dev);void mt76x2u_cleanup (struct mt76x02_dev *dev);
drivers/net/wireless/mediatek/mt76/mt76x2/usb.c +18 -6
@@ -36,24 +36,36 @@ static const struct usb_device_id mt76x2u_device_table[] = {static int mt76x2u_probe (struct usb_interface *intf,const struct usb_device_id *id) { +static const struct mt76_driver_ops drv_ops = { + .tx_prepare_skb = mt76x02u_tx_prepare_skb, + .tx_complete_skb = mt76x02u_tx_complete_skb, + .tx_status_data = mt76x02_tx_status_data, + .rx_skb = mt76x02_queue_rx_skb, + .sta_add = mt76x02_sta_add, + .sta_remove = mt76x02_sta_remove, + };struct usb_device *udev =interface_to_usbdev (intf);struct mt76x02_dev *dev; +struct mt76_dev *mdev;int err; - dev =mt76x2u_alloc_device (&intf->dev); -if (!dev) + mdev =mt76_alloc_device (&intf->dev,sizeof (*dev), &mt76x2u_ops, + &drv_ops); +if (!mdev)return -ENOMEM ; + dev = container_of(mdev, struct mt76x02_dev, mt76); + udev =usb_get_dev (udev);usb_reset_device (udev); -mt76x02u_init_mcu (&dev->mt76); - err =mt76u_init (&dev->mt76, intf); +mt76x02u_init_mcu (mdev); + err =mt76u_init (mdev, intf);if (err <0 ) goto err; - dev->mt76.rev =mt76_rr (dev,MT_ASIC_VERSION ); -dev_info (dev->mt76.dev,"ASIC revision: %08x\n" , dev->mt76.rev); + mdev->rev =mt76_rr (dev,MT_ASIC_VERSION ); +dev_info (mdev->dev,"ASIC revision: %08x\n" , mdev->rev); err =mt76x2u_register_device (dev);if (err <0 )
drivers/net/wireless/mediatek/mt76/mt76x2/usb_init.c +0 -23
@@ -134,29 +134,6 @@ static int mt76x2u_init_eeprom(struct mt76x02_dev *dev)return 0 ; } -struct mt76x02_dev *mt76x2u_alloc_device (struct device *pdev) -{ -static const struct mt76_driver_ops drv_ops = { - .tx_prepare_skb = mt76x02u_tx_prepare_skb, - .tx_complete_skb = mt76x02u_tx_complete_skb, - .tx_status_data = mt76x02_tx_status_data, - .rx_skb = mt76x02_queue_rx_skb, - .sta_add = mt76x02_sta_add, - .sta_remove = mt76x02_sta_remove, - }; -struct mt76x02_dev *dev; -struct mt76_dev *mdev; - - mdev =mt76_alloc_device (pdev,sizeof (*dev), &mt76x2u_ops, - &drv_ops); -if (!mdev) -return NULL ; - - dev = container_of(mdev, struct mt76x02_dev, mt76); - -return dev; -} -int mt76x2u_init_hardware (struct mt76x02_dev *dev) {int i, k, err;
Signature · 1 line
2.20.1
PATCH 3/4 mt76x0: remove mt76x0u_alloc_device routine
In reply to Lorenzo BianconiRemove mt76x0u_alloc_device since it just runs mt76_alloc_device. Move mt76_alloc_device call in mt76x0u_probe and in mt76x0e_probe
--- .../net/wireless/mediatek/mt76/mt76x0/init.c | 19 ---------------- .../wireless/mediatek/mt76/mt76x0/mt76x0.h | 4 ---- .../net/wireless/mediatek/mt76/mt76x0/pci.c | 17 +++++++++----- .../net/wireless/mediatek/mt76/mt76x0/usb.c | 22 +++++++++++-------- 4 files changed, 24 insertions(+), 38 deletions(-)
drivers/net/wireless/mediatek/mt76/mt76x0/init.c +0 -19
@@ -262,25 +262,6 @@ int mt76x0_init_hardware(struct mt76x02_dev *dev) }EXPORT_SYMBOL_GPL (mt76x0_init_hardware); -struct mt76x02_dev * -mt76x0_alloc_device (struct device *pdev, -const struct mt76_driver_ops *drv_ops, -const struct ieee80211_ops *ops) -{ -struct mt76x02_dev *dev; -struct mt76_dev *mdev; - - mdev =mt76_alloc_device (pdev,sizeof (*dev), ops, drv_ops); -if (!mdev) -return NULL ; - - dev = container_of(mdev, struct mt76x02_dev, mt76); -mutex_init (&dev->phy_mutex); - -return dev; -} -EXPORT_SYMBOL_GPL (mt76x0_alloc_device); -int mt76x0_register_device (struct mt76x02_dev *dev) {int ret;
drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h +0 -4
@@ -50,10 +50,6 @@ static inline bool is_mt7630(struct mt76x02_dev *dev) }/* Init */ -struct mt76x02_dev * -mt76x0_alloc_device (struct device *pdev, -const struct mt76_driver_ops *drv_ops, -const struct ieee80211_ops *ops);int mt76x0_init_hardware (struct mt76x02_dev *dev);int mt76x0_register_device (struct mt76x02_dev *dev);void mt76x0_chip_onoff (struct mt76x02_dev *dev,bool enable,bool reset);
drivers/net/wireless/mediatek/mt76/mt76x0/pci.c +11 -6
@@ -174,6 +174,7 @@ mt76x0e_probe(struct pci_dev *pdev, const struct pci_device_id *id) .sta_remove = mt76x02_sta_remove, };struct mt76x02_dev *dev; +struct mt76_dev *mdev;int ret; ret =pcim_enable_device (pdev);
@@ -190,16 +191,20 @@ mt76x0e_probe(struct pci_dev *pdev, const struct pci_device_id *id)if (ret)return ret; - dev =mt76x0_alloc_device (&pdev->dev, &drv_ops, &mt76x0e_ops); -if (!dev) + mdev =mt76_alloc_device (&pdev->dev,sizeof (*dev), &mt76x0e_ops, + &drv_ops); +if (!mdev)return -ENOMEM ; -mt76_mmio_init (&dev->mt76,pcim_iomap_table (pdev)[0 ]); + dev = container_of(mdev, struct mt76x02_dev, mt76); +mutex_init (&dev->phy_mutex); - dev->mt76.rev =mt76_rr (dev,MT_ASIC_VERSION ); -dev_info (dev->mt76.dev,"ASIC revision: %08x\n" , dev->mt76.rev); +mt76_mmio_init (mdev,pcim_iomap_table (pdev)[0 ]); - ret =devm_request_irq (dev->mt76.dev, pdev->irq, mt76x02_irq_handler, + mdev->rev =mt76_rr (dev,MT_ASIC_VERSION ); +dev_info (mdev->dev,"ASIC revision: %08x\n" , mdev->rev); + + ret =devm_request_irq (mdev->dev, pdev->irq, mt76x02_irq_handler,IRQF_SHARED ,KBUILD_MODNAME , dev);if (ret) goto error;
drivers/net/wireless/mediatek/mt76/mt76x0/usb.c +13 -9
@@ -223,14 +223,18 @@ static int mt76x0u_probe(struct usb_interface *usb_intf, };struct usb_device *usb_dev =interface_to_usbdev (usb_intf);struct mt76x02_dev *dev; +struct mt76_dev *mdev;u32 asic_rev, mac_rev;int ret; - dev =mt76x0_alloc_device (&usb_intf->dev, &drv_ops, - &mt76x0u_ops); -if (!dev) + mdev =mt76_alloc_device (&usb_intf->dev,sizeof (*dev), &mt76x0u_ops, + &drv_ops); +if (!mdev)return -ENOMEM ; + dev = container_of(mdev, struct mt76x02_dev, mt76); +mutex_init (&dev->phy_mutex); +/* Quirk for Archer T1U */ if (id->driver_info) dev->no_2ghz = true;
@@ -240,27 +244,27 @@ static int mt76x0u_probe(struct usb_interface *usb_intf,usb_set_intfdata (usb_intf, dev); -mt76x02u_init_mcu (&dev->mt76); - ret =mt76u_init (&dev->mt76, usb_intf); +mt76x02u_init_mcu (mdev); + ret =mt76u_init (mdev, usb_intf);if (ret) goto err;/* Disable the HW, otherwise MCU fail to initalize on hot reboot */ mt76x0_chip_onoff (dev, false, false); -if (!mt76x02_wait_for_mac (&dev->mt76)) { +if (!mt76x02_wait_for_mac (mdev)) { ret = -ETIMEDOUT ; goto err; } asic_rev =mt76_rr (dev,MT_ASIC_VERSION ); mac_rev =mt76_rr (dev,MT_MAC_CSR0 ); -dev_info (dev->mt76.dev,"ASIC revision: %08x MAC revision: %08x\n" , +dev_info (mdev->dev,"ASIC revision: %08x MAC revision: %08x\n" , asic_rev, mac_rev);/* Note: vendor driver skips this check for MT76X0U */ if (!(mt76_rr (dev,MT_EFUSE_CTRL ) &MT_EFUSE_CTRL_SEL )) -dev_warn (dev->mt76.dev,"Warning: eFUSE not present\n" ); +dev_warn (mdev->dev,"Warning: eFUSE not present\n" ); ret =mt76x0u_register_device (dev);if (ret <0 )
@@ -272,7 +276,7 @@ static int mt76x0u_probe(struct usb_interface *usb_intf,usb_set_intfdata (usb_intf,NULL );usb_put_dev (interface_to_usbdev (usb_intf)); -ieee80211_free_hw (dev->mt76.hw); +ieee80211_free_hw (mdev->hw);return ret; }
Signature · 1 line
2.20.1
PATCH 4/4 mt76x2: remove mt76x2_alloc_device routine
In reply to Lorenzo BianconiRemove mt76x2_alloc_device since it just runs mt76_alloc_device. Move mt76_alloc_device call in mt76x2_probe
--- .../wireless/mediatek/mt76/mt76x2/mt76x2.h | 1 - .../net/wireless/mediatek/mt76/mt76x2/pci.c | 26 ++++++++++++++----- .../wireless/mediatek/mt76/mt76x2/pci_init.c | 26 ------------------- 3 files changed, 20 insertions(+), 33 deletions(-)
drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2.h +0 -1
@@ -49,7 +49,6 @@ static inline bool mt76x2_channel_silent(struct mt76x02_dev *dev)extern const struct ieee80211_ops mt76x2_ops; -struct mt76x02_dev *mt76x2_alloc_device (struct device *pdev);int mt76x2_register_device (struct mt76x02_dev *dev);void mt76x2_phy_power_on (struct mt76x02_dev *dev);
drivers/net/wireless/mediatek/mt76/mt76x2/pci.c +20 -6
@@ -30,7 +30,19 @@ static const struct pci_device_id mt76pci_device_table[] = {static int mt76pci_probe (struct pci_dev *pdev,const struct pci_device_id *id) { +static const struct mt76_driver_ops drv_ops = { + .txwi_size =sizeof (struct mt76x02_txwi ), + .update_survey = mt76x02_update_channel, + .tx_prepare_skb = mt76x02_tx_prepare_skb, + .tx_complete_skb = mt76x02_tx_complete_skb, + .rx_skb = mt76x02_queue_rx_skb, + .rx_poll_complete = mt76x02_rx_poll_complete, + .sta_ps = mt76x02_sta_ps, + .sta_add = mt76x02_sta_add, + .sta_remove = mt76x02_sta_remove, + };struct mt76x02_dev *dev; +struct mt76_dev *mdev;int ret; ret =pcim_enable_device (pdev);
@@ -47,17 +59,19 @@ mt76pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)if (ret)return ret; - dev =mt76x2_alloc_device (&pdev->dev); -if (!dev) + mdev =mt76_alloc_device (&pdev->dev,sizeof (*dev), &mt76x2_ops, + &drv_ops); +if (!mdev)return -ENOMEM ; -mt76_mmio_init (&dev->mt76,pcim_iomap_table (pdev)[0 ]); + dev = container_of(mdev, struct mt76x02_dev, mt76); +mt76_mmio_init (mdev,pcim_iomap_table (pdev)[0 ]);mt76x2_reset_wlan (dev, false); - dev->mt76.rev =mt76_rr (dev,MT_ASIC_VERSION ); -dev_info (dev->mt76.dev,"ASIC revision: %08x\n" , dev->mt76.rev); + mdev->rev =mt76_rr (dev,MT_ASIC_VERSION ); +dev_info (mdev->dev,"ASIC revision: %08x\n" , mdev->rev); - ret =devm_request_irq (dev->mt76.dev, pdev->irq, mt76x02_irq_handler, + ret =devm_request_irq (mdev->dev, pdev->irq, mt76x02_irq_handler,IRQF_SHARED ,KBUILD_MODNAME , dev);if (ret) goto error;
drivers/net/wireless/mediatek/mt76/mt76x2/pci_init.c +0 -26
@@ -315,32 +315,6 @@ void mt76x2_cleanup(struct mt76x02_dev *dev)mt76x02_mcu_cleanup (dev); } -struct mt76x02_dev *mt76x2_alloc_device (struct device *pdev) -{ -static const struct mt76_driver_ops drv_ops = { - .txwi_size =sizeof (struct mt76x02_txwi ), - .update_survey = mt76x02_update_channel, - .tx_prepare_skb = mt76x02_tx_prepare_skb, - .tx_complete_skb = mt76x02_tx_complete_skb, - .rx_skb = mt76x02_queue_rx_skb, - .rx_poll_complete = mt76x02_rx_poll_complete, - .sta_ps = mt76x02_sta_ps, - .sta_add = mt76x02_sta_add, - .sta_remove = mt76x02_sta_remove, - }; -struct mt76x02_dev *dev; -struct mt76_dev *mdev; - - mdev =mt76_alloc_device (pdev,sizeof (*dev), &mt76x2_ops, - &drv_ops); -if (!mdev) -return NULL ; - - dev = container_of(mdev, struct mt76x02_dev, mt76); - -return dev; -} -int mt76x2_register_device (struct mt76x02_dev *dev) {int ret;
Signature · 1 line
2.20.1
Quoted 8 lines · Lorenzo Bianconi
Move mt76x{0,2}
alloc_devicecommon code inmt76_alloc_deviceand remove duplicated codeLorenzo Bianconi (4):
mt76: movealloc_devicecommon code inmt76_alloc_device
mt76x2u: removemt76x2u_alloc_deviceroutine
mt76x0: removemt76x0u_alloc_deviceroutine
mt76x2: removemt76x2_alloc_deviceroutine
Applied, thanks.
- Felix