Commit a86f1d01 authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Felix Fietkau

mt76: move mt76 workqueue in common code

Move mt76 workqueue from usb to common code in order to be reused adding
low-power support for mt7663 chipset
Signed-off-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent 757b0e7f
...@@ -437,6 +437,12 @@ mt76_alloc_device(struct device *pdev, unsigned int size, ...@@ -437,6 +437,12 @@ mt76_alloc_device(struct device *pdev, unsigned int size,
tasklet_init(&dev->tx_tasklet, mt76_tx_tasklet, (unsigned long)dev); tasklet_init(&dev->tx_tasklet, mt76_tx_tasklet, (unsigned long)dev);
dev->wq = alloc_ordered_workqueue("mt76", 0);
if (!dev->wq) {
ieee80211_free_hw(hw);
return NULL;
}
return dev; return dev;
} }
EXPORT_SYMBOL_GPL(mt76_alloc_device); EXPORT_SYMBOL_GPL(mt76_alloc_device);
...@@ -490,7 +496,12 @@ EXPORT_SYMBOL_GPL(mt76_unregister_device); ...@@ -490,7 +496,12 @@ EXPORT_SYMBOL_GPL(mt76_unregister_device);
void mt76_free_device(struct mt76_dev *dev) void mt76_free_device(struct mt76_dev *dev)
{ {
mt76_tx_free(dev); if (dev->wq) {
destroy_workqueue(dev->wq);
dev->wq = NULL;
}
if (mt76_is_mmio(dev))
mt76_tx_free(dev);
ieee80211_free_hw(dev->hw); ieee80211_free_hw(dev->hw);
} }
EXPORT_SYMBOL_GPL(mt76_free_device); EXPORT_SYMBOL_GPL(mt76_free_device);
......
...@@ -423,7 +423,6 @@ struct mt76_usb { ...@@ -423,7 +423,6 @@ struct mt76_usb {
u16 data_len; u16 data_len;
struct tasklet_struct rx_tasklet; struct tasklet_struct rx_tasklet;
struct workqueue_struct *wq;
struct work_struct stat_work; struct work_struct stat_work;
u8 out_ep[__MT_EP_OUT_MAX]; u8 out_ep[__MT_EP_OUT_MAX];
...@@ -621,6 +620,8 @@ struct mt76_dev { ...@@ -621,6 +620,8 @@ struct mt76_dev {
struct mt76_testmode_data test; struct mt76_testmode_data test;
#endif #endif
struct workqueue_struct *wq;
union { union {
struct mt76_mmio mmio; struct mt76_mmio mmio;
struct mt76_usb usb; struct mt76_usb usb;
...@@ -1018,7 +1019,6 @@ int mt76u_vendor_request(struct mt76_dev *dev, u8 req, ...@@ -1018,7 +1019,6 @@ int mt76u_vendor_request(struct mt76_dev *dev, u8 req,
void *buf, size_t len); void *buf, size_t len);
void mt76u_single_wr(struct mt76_dev *dev, const u8 req, void mt76u_single_wr(struct mt76_dev *dev, const u8 req,
const u16 offset, const u32 val); const u16 offset, const u32 val);
void mt76u_deinit(struct mt76_dev *dev);
int mt76u_init(struct mt76_dev *dev, struct usb_interface *intf, int mt76u_init(struct mt76_dev *dev, struct usb_interface *intf,
bool ext); bool ext);
int mt76u_alloc_mcu_queue(struct mt76_dev *dev); int mt76u_alloc_mcu_queue(struct mt76_dev *dev);
......
...@@ -927,7 +927,7 @@ mt7615_mac_queue_rate_update(struct mt7615_phy *phy, struct mt7615_sta *sta, ...@@ -927,7 +927,7 @@ mt7615_mac_queue_rate_update(struct mt7615_phy *phy, struct mt7615_sta *sta,
mt7615_mac_update_rate_desc(phy, sta, probe_rate, rates, mt7615_mac_update_rate_desc(phy, sta, probe_rate, rates,
&wd->rate); &wd->rate);
list_add_tail(&wd->node, &dev->wd_head); list_add_tail(&wd->node, &dev->wd_head);
queue_work(dev->mt76.usb.wq, &dev->wtbl_work); queue_work(dev->mt76.wq, &dev->wtbl_work);
return 0; return 0;
} }
......
...@@ -319,7 +319,7 @@ mt7615_queue_key_update(struct mt7615_dev *dev, enum set_key_cmd cmd, ...@@ -319,7 +319,7 @@ mt7615_queue_key_update(struct mt7615_dev *dev, enum set_key_cmd cmd,
wd->key.cmd = cmd; wd->key.cmd = cmd;
list_add_tail(&wd->node, &dev->wd_head); list_add_tail(&wd->node, &dev->wd_head);
queue_work(dev->mt76.usb.wq, &dev->wtbl_work); queue_work(dev->mt76.wq, &dev->wtbl_work);
return 0; return 0;
} }
......
...@@ -349,11 +349,10 @@ static int mt7663u_probe(struct usb_interface *usb_intf, ...@@ -349,11 +349,10 @@ static int mt7663u_probe(struct usb_interface *usb_intf,
error_freeq: error_freeq:
mt76u_queues_deinit(&dev->mt76); mt76u_queues_deinit(&dev->mt76);
error: error:
mt76u_deinit(&dev->mt76);
usb_set_intfdata(usb_intf, NULL); usb_set_intfdata(usb_intf, NULL);
usb_put_dev(interface_to_usbdev(usb_intf)); usb_put_dev(interface_to_usbdev(usb_intf));
ieee80211_free_hw(mdev->hw); mt76_free_device(&dev->mt76);
return ret; return ret;
} }
...@@ -371,8 +370,7 @@ static void mt7663u_disconnect(struct usb_interface *usb_intf) ...@@ -371,8 +370,7 @@ static void mt7663u_disconnect(struct usb_interface *usb_intf)
usb_set_intfdata(usb_intf, NULL); usb_set_intfdata(usb_intf, NULL);
usb_put_dev(interface_to_usbdev(usb_intf)); usb_put_dev(interface_to_usbdev(usb_intf));
mt76u_deinit(&dev->mt76); mt76_free_device(&dev->mt76);
ieee80211_free_hw(dev->mt76.hw);
} }
#ifdef CONFIG_PM #ifdef CONFIG_PM
......
...@@ -277,9 +277,8 @@ static int mt76x0u_probe(struct usb_interface *usb_intf, ...@@ -277,9 +277,8 @@ static int mt76x0u_probe(struct usb_interface *usb_intf,
err: err:
usb_set_intfdata(usb_intf, NULL); usb_set_intfdata(usb_intf, NULL);
usb_put_dev(interface_to_usbdev(usb_intf)); usb_put_dev(interface_to_usbdev(usb_intf));
mt76u_deinit(&dev->mt76); mt76_free_device(&dev->mt76);
ieee80211_free_hw(mdev->hw);
return ret; return ret;
} }
...@@ -297,8 +296,7 @@ static void mt76x0_disconnect(struct usb_interface *usb_intf) ...@@ -297,8 +296,7 @@ static void mt76x0_disconnect(struct usb_interface *usb_intf)
usb_set_intfdata(usb_intf, NULL); usb_set_intfdata(usb_intf, NULL);
usb_put_dev(interface_to_usbdev(usb_intf)); usb_put_dev(interface_to_usbdev(usb_intf));
mt76u_deinit(&dev->mt76); mt76_free_device(&dev->mt76);
ieee80211_free_hw(dev->mt76.hw);
} }
static int __maybe_unused mt76x0_suspend(struct usb_interface *usb_intf, static int __maybe_unused mt76x0_suspend(struct usb_interface *usb_intf,
......
...@@ -75,8 +75,7 @@ static int mt76x2u_probe(struct usb_interface *intf, ...@@ -75,8 +75,7 @@ static int mt76x2u_probe(struct usb_interface *intf,
return 0; return 0;
err: err:
ieee80211_free_hw(mt76_hw(dev)); mt76_free_device(&dev->mt76);
mt76u_deinit(&dev->mt76);
usb_set_intfdata(intf, NULL); usb_set_intfdata(intf, NULL);
usb_put_dev(udev); usb_put_dev(udev);
...@@ -92,9 +91,7 @@ static void mt76x2u_disconnect(struct usb_interface *intf) ...@@ -92,9 +91,7 @@ static void mt76x2u_disconnect(struct usb_interface *intf)
set_bit(MT76_REMOVED, &dev->mphy.state); set_bit(MT76_REMOVED, &dev->mphy.state);
ieee80211_unregister_hw(hw); ieee80211_unregister_hw(hw);
mt76x2u_cleanup(dev); mt76x2u_cleanup(dev);
mt76u_deinit(&dev->mt76); mt76_free_device(&dev->mt76);
ieee80211_free_hw(hw);
usb_set_intfdata(intf, NULL); usb_set_intfdata(intf, NULL);
usb_put_dev(udev); usb_put_dev(udev);
} }
......
...@@ -842,7 +842,7 @@ static void mt76u_tx_tasklet(unsigned long data) ...@@ -842,7 +842,7 @@ static void mt76u_tx_tasklet(unsigned long data)
if (dev->drv->tx_status_data && if (dev->drv->tx_status_data &&
!test_and_set_bit(MT76_READING_STATS, &dev->phy.state)) !test_and_set_bit(MT76_READING_STATS, &dev->phy.state))
queue_work(dev->usb.wq, &dev->usb.stat_work); queue_work(dev->wq, &dev->usb.stat_work);
if (wake) if (wake)
ieee80211_wake_queue(dev->hw, i); ieee80211_wake_queue(dev->hw, i);
} }
...@@ -868,7 +868,7 @@ static void mt76u_tx_status_data(struct work_struct *work) ...@@ -868,7 +868,7 @@ static void mt76u_tx_status_data(struct work_struct *work)
} }
if (count && test_bit(MT76_STATE_RUNNING, &dev->phy.state)) if (count && test_bit(MT76_STATE_RUNNING, &dev->phy.state))
queue_work(usb->wq, &usb->stat_work); queue_work(dev->wq, &usb->stat_work);
else else
clear_bit(MT76_READING_STATS, &dev->phy.state); clear_bit(MT76_READING_STATS, &dev->phy.state);
} }
...@@ -1132,15 +1132,6 @@ static const struct mt76_queue_ops usb_queue_ops = { ...@@ -1132,15 +1132,6 @@ static const struct mt76_queue_ops usb_queue_ops = {
.kick = mt76u_tx_kick, .kick = mt76u_tx_kick,
}; };
void mt76u_deinit(struct mt76_dev *dev)
{
if (dev->usb.wq) {
destroy_workqueue(dev->usb.wq);
dev->usb.wq = NULL;
}
}
EXPORT_SYMBOL_GPL(mt76u_deinit);
int mt76u_init(struct mt76_dev *dev, int mt76u_init(struct mt76_dev *dev,
struct usb_interface *intf, bool ext) struct usb_interface *intf, bool ext)
{ {
...@@ -1163,10 +1154,6 @@ int mt76u_init(struct mt76_dev *dev, ...@@ -1163,10 +1154,6 @@ int mt76u_init(struct mt76_dev *dev,
tasklet_init(&dev->tx_tasklet, mt76u_tx_tasklet, (unsigned long)dev); tasklet_init(&dev->tx_tasklet, mt76u_tx_tasklet, (unsigned long)dev);
INIT_WORK(&usb->stat_work, mt76u_tx_status_data); INIT_WORK(&usb->stat_work, mt76u_tx_status_data);
usb->wq = alloc_workqueue("mt76u", WQ_UNBOUND, 0);
if (!usb->wq)
return -ENOMEM;
usb->data_len = usb_maxpacket(udev, usb_sndctrlpipe(udev, 0), 1); usb->data_len = usb_maxpacket(udev, usb_sndctrlpipe(udev, 0), 1);
if (usb->data_len < 32) if (usb->data_len < 32)
usb->data_len = 32; usb->data_len = 32;
...@@ -1190,7 +1177,8 @@ int mt76u_init(struct mt76_dev *dev, ...@@ -1190,7 +1177,8 @@ int mt76u_init(struct mt76_dev *dev,
return 0; return 0;
error: error:
mt76u_deinit(dev); destroy_workqueue(dev->wq);
return err; return err;
} }
EXPORT_SYMBOL_GPL(mt76u_init); EXPORT_SYMBOL_GPL(mt76u_init);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment