wifi: mt76: mt7921: introduce mt7921_get_mac80211_ops utility routine
authorLorenzo Bianconi <lorenzo@kernel.org>
Mon, 6 Mar 2023 17:50:29 +0000 (18:50 +0100)
committerFelix Fietkau <nbd@nbd.name>
Mon, 17 Apr 2023 14:08:49 +0000 (16:08 +0200)
Since the fw offload capability check is shared between pci,usb and sdio
devices, move it in common init code and reduce code duplication.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt7921/init.c
drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h
drivers/net/wireless/mediatek/mt76/mt7921/pci.c
drivers/net/wireless/mediatek/mt76/mt7921/sdio.c
drivers/net/wireless/mediatek/mt76/mt7921/usb.c

index 80c71acfe1591cc0afd898c1e08fbd6e4b4cdeb9..33681fbb2fe847a7639afbdc869f430b2932a317 100644 (file)
@@ -169,7 +169,8 @@ mt7921_mac_init_band(struct mt7921_dev *dev, u8 band)
        mt76_rmw(dev, MT_WTBLOFF_TOP_RSCR(band), mask, set);
 }
 
-u8 mt7921_check_offload_capability(struct device *dev, const char *fw_wm)
+static u8
+mt7921_get_offload_capability(struct device *dev, const char *fw_wm)
 {
        struct mt7921_fw_features *features = NULL;
        const struct mt76_connac2_fw_trailer *hdr;
@@ -220,7 +221,31 @@ out:
 
        return features ? features->data : 0;
 }
-EXPORT_SYMBOL_GPL(mt7921_check_offload_capability);
+
+struct ieee80211_ops *
+mt7921_get_mac80211_ops(struct device *dev, void *drv_data, u8 *fw_features)
+{
+       struct ieee80211_ops *ops;
+
+       ops = devm_kmemdup(dev, &mt7921_ops, sizeof(mt7921_ops), GFP_KERNEL);
+       if (!ops)
+               return NULL;
+
+       *fw_features = mt7921_get_offload_capability(dev, drv_data);
+       if (!(*fw_features & MT7921_FW_CAP_CNM)) {
+               ops->remain_on_channel = NULL;
+               ops->cancel_remain_on_channel = NULL;
+               ops->add_chanctx = NULL;
+               ops->remove_chanctx = NULL;
+               ops->change_chanctx = NULL;
+               ops->assign_vif_chanctx = NULL;
+               ops->unassign_vif_chanctx = NULL;
+               ops->mgd_prepare_tx = NULL;
+               ops->mgd_complete_tx = NULL;
+       }
+       return ops;
+}
+EXPORT_SYMBOL_GPL(mt7921_get_mac80211_ops);
 
 int mt7921_mac_init(struct mt7921_dev *dev)
 {
index 1af70dac723bc9d65c3f099a03674ce4f74746ac..b1dceeafa54ee9465a4e695ea7d24a77ad4b8849 100644 (file)
@@ -593,5 +593,6 @@ int mt7921_mcu_set_roc(struct mt7921_phy *phy, struct mt7921_vif *vif,
                       enum mt7921_roc_req type, u8 token_id);
 int mt7921_mcu_abort_roc(struct mt7921_phy *phy, struct mt7921_vif *vif,
                         u8 token_id);
-u8 mt7921_check_offload_capability(struct device *dev, const char *fw_wm);
+struct ieee80211_ops *mt7921_get_mac80211_ops(struct device *dev,
+                                             void *drv_data, u8 *fw_features);
 #endif
index 1a8a54a46dcc850743102dd72c229dd1b068d9e3..b520cd2581702f9fb8bcae6b074583cd9e1155ad 100644 (file)
@@ -256,7 +256,6 @@ static int mt7921_pci_probe(struct pci_dev *pdev,
                .drv_own = mt7921e_mcu_drv_pmctrl,
                .fw_own = mt7921e_mcu_fw_pmctrl,
        };
-
        struct ieee80211_ops *ops;
        struct mt76_bus_ops *bus_ops;
        struct mt7921_dev *dev;
@@ -285,27 +284,13 @@ static int mt7921_pci_probe(struct pci_dev *pdev,
        if (mt7921_disable_aspm)
                mt76_pci_disable_aspm(pdev);
 
-       features = mt7921_check_offload_capability(&pdev->dev, (const char *)
-                                                  id->driver_data);
-       ops = devm_kmemdup(&pdev->dev, &mt7921_ops, sizeof(mt7921_ops),
-                          GFP_KERNEL);
+       ops = mt7921_get_mac80211_ops(&pdev->dev, (void *)id->driver_data,
+                                     &features);
        if (!ops) {
                ret = -ENOMEM;
                goto err_free_pci_vec;
        }
 
-       if (!(features & MT7921_FW_CAP_CNM)) {
-               ops->remain_on_channel = NULL;
-               ops->cancel_remain_on_channel = NULL;
-               ops->add_chanctx = NULL;
-               ops->remove_chanctx = NULL;
-               ops->change_chanctx = NULL;
-               ops->assign_vif_chanctx = NULL;
-               ops->unassign_vif_chanctx = NULL;
-               ops->mgd_prepare_tx = NULL;
-               ops->mgd_complete_tx = NULL;
-       }
-
        mdev = mt76_alloc_device(&pdev->dev, sizeof(*dev), ops, &drv_ops);
        if (!mdev) {
                ret = -ENOMEM;
index 8ce4252b8ae7c74ffd436210a7194eacaef331c0..584921fb25b583dd374b6ce877630a9585b4ae40 100644 (file)
@@ -122,33 +122,17 @@ static int mt7921s_probe(struct sdio_func *func,
                .drv_own = mt7921s_mcu_drv_pmctrl,
                .fw_own = mt7921s_mcu_fw_pmctrl,
        };
-
        struct ieee80211_ops *ops;
        struct mt7921_dev *dev;
        struct mt76_dev *mdev;
        u8 features;
        int ret;
 
-       features = mt7921_check_offload_capability(&func->dev, (const char *)
-                                                  id->driver_data);
-
-       ops = devm_kmemdup(&func->dev, &mt7921_ops, sizeof(mt7921_ops),
-                          GFP_KERNEL);
+       ops = mt7921_get_mac80211_ops(&func->dev, (void *)id->driver_data,
+                                     &features);
        if (!ops)
                return -ENOMEM;
 
-       if (!(features & MT7921_FW_CAP_CNM)) {
-               ops->remain_on_channel = NULL;
-               ops->cancel_remain_on_channel = NULL;
-               ops->add_chanctx = NULL;
-               ops->remove_chanctx = NULL;
-               ops->change_chanctx = NULL;
-               ops->assign_vif_chanctx = NULL;
-               ops->unassign_vif_chanctx = NULL;
-               ops->mgd_prepare_tx = NULL;
-               ops->mgd_complete_tx = NULL;
-       }
-
        mdev = mt76_alloc_device(&func->dev, sizeof(*dev), ops, &drv_ops);
        if (!mdev)
                return -ENOMEM;
index 8fef09ed29c91490cee9ba08fc031cf4f390d6e6..376bf89a70d8bb86b484a97a212c574239eb63f8 100644 (file)
@@ -210,27 +210,12 @@ static int mt7921u_probe(struct usb_interface *usb_intf,
        u8 features;
        int ret;
 
-       features = mt7921_check_offload_capability(&usb_intf->dev, (const char *)
-                                                  id->driver_info);
-       ops = devm_kmemdup(&usb_intf->dev, &mt7921_ops, sizeof(mt7921_ops),
-                          GFP_KERNEL);
+       ops = mt7921_get_mac80211_ops(&usb_intf->dev, (void *)id->driver_info,
+                                     &features);
        if (!ops)
                return -ENOMEM;
 
-       if (!(features & MT7921_FW_CAP_CNM)) {
-               ops->remain_on_channel = NULL;
-               ops->cancel_remain_on_channel = NULL;
-               ops->add_chanctx = NULL;
-               ops->remove_chanctx = NULL;
-               ops->change_chanctx = NULL;
-               ops->assign_vif_chanctx = NULL;
-               ops->unassign_vif_chanctx = NULL;
-               ops->mgd_prepare_tx = NULL;
-               ops->mgd_complete_tx = NULL;
-       }
-
        ops->stop = mt7921u_stop;
-
        mdev = mt76_alloc_device(&usb_intf->dev, sizeof(*dev), ops, &drv_ops);
        if (!mdev)
                return -ENOMEM;