mt76: move ieee80211_hw allocation to common core
authorFelix Fietkau <nbd@nbd.name>
Sun, 20 May 2018 05:43:47 +0000 (07:43 +0200)
committerKalle Valo <kvalo@codeaurora.org>
Wed, 23 May 2018 07:58:13 +0000 (10:58 +0300)
Allows it to be shared between different drivers and locks to be
initialized earlier

Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
drivers/net/wireless/mediatek/mt76/mac80211.c
drivers/net/wireless/mediatek/mt76/mt76.h
drivers/net/wireless/mediatek/mt76/mt76x2_init.c

index d862e5e..d1044e5 100644 (file)
@@ -268,6 +268,26 @@ mt76_check_sband(struct mt76_dev *dev, int band)
        dev->hw->wiphy->bands[band] = NULL;
 }
 
+struct mt76_dev *
+mt76_alloc_device(unsigned int size, const struct ieee80211_ops *ops)
+{
+       struct ieee80211_hw *hw;
+       struct mt76_dev *dev;
+
+       hw = ieee80211_alloc_hw(size, ops);
+       if (!hw)
+               return NULL;
+
+       dev = hw->priv;
+       dev->hw = hw;
+       spin_lock_init(&dev->rx_lock);
+       spin_lock_init(&dev->lock);
+       spin_lock_init(&dev->cc_lock);
+
+       return dev;
+}
+EXPORT_SYMBOL_GPL(mt76_alloc_device);
+
 int mt76_register_device(struct mt76_dev *dev, bool vht,
                         struct ieee80211_rate *rates, int n_rates)
 {
@@ -277,8 +297,6 @@ int mt76_register_device(struct mt76_dev *dev, bool vht,
 
        dev_set_drvdata(dev->dev, dev);
 
-       spin_lock_init(&dev->lock);
-       spin_lock_init(&dev->cc_lock);
        INIT_LIST_HEAD(&dev->txwi_cache);
 
        SET_IEEE80211_DEV(hw, dev->dev);
index 2d098fa..bb158f8 100644 (file)
@@ -377,6 +377,8 @@ 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);
 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);
index b6f27b9..ec17156 100644 (file)
@@ -638,20 +638,18 @@ struct mt76x2_dev *mt76x2_alloc_device(struct device *pdev)
                .rx_poll_complete = mt76x2_rx_poll_complete,
                .sta_ps = mt76x2_sta_ps,
        };
-       struct ieee80211_hw *hw;
        struct mt76x2_dev *dev;
+       struct mt76_dev *mdev;
 
-       hw = ieee80211_alloc_hw(sizeof(*dev), &mt76x2_ops);
-       if (!hw)
+       mdev = mt76_alloc_device(sizeof(*dev), &mt76x2_ops);
+       if (!mdev)
                return NULL;
 
-       dev = hw->priv;
-       dev->mt76.dev = pdev;
-       dev->mt76.hw = hw;
-       dev->mt76.drv = &drv_ops;
+       dev = container_of(mdev, struct mt76x2_dev, mt76);
+       mdev->dev = pdev;
+       mdev->drv = &drv_ops;
        mutex_init(&dev->mutex);
        spin_lock_init(&dev->irq_lock);
-       spin_lock_init(&dev->mt76.rx_lock);
 
        return dev;
 }