summaryrefslogtreecommitdiff
path: root/drivers/net/wireless/mediatek/mt76/mt7921/usb.c
diff options
context:
space:
mode:
authorLorenzo Bianconi <lorenzo@kernel.org>2023-06-28 15:07:19 +0800
committerFelix Fietkau <nbd@nbd.name>2023-07-26 11:36:15 +0200
commitd28e1a48952e60fe47bba5b79fdbafc65f6c892b (patch)
tree0a34595f4850a373f1b07b6afbc268850054a30a /drivers/net/wireless/mediatek/mt76/mt7921/usb.c
parent29f5a494f7a22ab4661dc835c1d208e1a61793e7 (diff)
wifi: mt76: mt792x: introduce mt792x-usb module
Add usb shared code between mt7921 and mt7925 chipset to mt792x-usb module. Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org> Signed-off-by: Deren Wu <deren.wu@mediatek.com> Signed-off-by: Felix Fietkau <nbd@nbd.name>
Diffstat (limited to 'drivers/net/wireless/mediatek/mt76/mt7921/usb.c')
-rw-r--r--drivers/net/wireless/mediatek/mt76/mt7921/usb.c162
1 files changed, 67 insertions, 95 deletions
diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/usb.c b/drivers/net/wireless/mediatek/mt76/mt7921/usb.c
index 0a31e7076324..c3981bc893ac 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/usb.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/usb.c
@@ -24,83 +24,6 @@ static const struct usb_device_id mt7921u_device_table[] = {
{ },
};
-static u32 mt7921u_rr(struct mt76_dev *dev, u32 addr)
-{
- u32 ret;
-
- mutex_lock(&dev->usb.usb_ctrl_mtx);
- ret = ___mt76u_rr(dev, MT_VEND_READ_EXT,
- USB_DIR_IN | MT_USB_TYPE_VENDOR, addr);
- mutex_unlock(&dev->usb.usb_ctrl_mtx);
-
- return ret;
-}
-
-static void mt7921u_wr(struct mt76_dev *dev, u32 addr, u32 val)
-{
- mutex_lock(&dev->usb.usb_ctrl_mtx);
- ___mt76u_wr(dev, MT_VEND_WRITE_EXT,
- USB_DIR_OUT | MT_USB_TYPE_VENDOR, addr, val);
- mutex_unlock(&dev->usb.usb_ctrl_mtx);
-}
-
-static u32 mt7921u_rmw(struct mt76_dev *dev, u32 addr,
- u32 mask, u32 val)
-{
- mutex_lock(&dev->usb.usb_ctrl_mtx);
- val |= ___mt76u_rr(dev, MT_VEND_READ_EXT,
- USB_DIR_IN | MT_USB_TYPE_VENDOR, addr) & ~mask;
- ___mt76u_wr(dev, MT_VEND_WRITE_EXT,
- USB_DIR_OUT | MT_USB_TYPE_VENDOR, addr, val);
- mutex_unlock(&dev->usb.usb_ctrl_mtx);
-
- return val;
-}
-
-static void mt7921u_copy(struct mt76_dev *dev, u32 offset,
- const void *data, int len)
-{
- struct mt76_usb *usb = &dev->usb;
- int ret, i = 0, batch_len;
- const u8 *val = data;
-
- len = round_up(len, 4);
-
- mutex_lock(&usb->usb_ctrl_mtx);
- while (i < len) {
- batch_len = min_t(int, usb->data_len, len - i);
- memcpy(usb->data, val + i, batch_len);
- ret = __mt76u_vendor_request(dev, MT_VEND_WRITE_EXT,
- USB_DIR_OUT | MT_USB_TYPE_VENDOR,
- (offset + i) >> 16, offset + i,
- usb->data, batch_len);
- if (ret < 0)
- break;
-
- i += batch_len;
- }
- mutex_unlock(&usb->usb_ctrl_mtx);
-}
-
-int mt7921u_mcu_power_on(struct mt792x_dev *dev)
-{
- int ret;
-
- ret = mt76u_vendor_request(&dev->mt76, MT_VEND_POWER_ON,
- USB_DIR_OUT | MT_USB_TYPE_VENDOR,
- 0x0, 0x1, NULL, 0);
- if (ret)
- return ret;
-
- if (!mt76_poll_msec(dev, MT_CONN_ON_MISC, MT_TOP_MISC2_FW_PWR_ON,
- MT_TOP_MISC2_FW_PWR_ON, 500)) {
- dev_err(dev->mt76.dev, "Timeout for power on\n");
- ret = -EIO;
- }
-
- return ret;
-}
-
static int
mt7921u_mcu_send_message(struct mt76_dev *mdev, struct sk_buff *skb,
int cmd, int *seq)
@@ -155,20 +78,69 @@ static int mt7921u_mcu_init(struct mt792x_dev *dev)
return 0;
}
-static void mt7921u_stop(struct ieee80211_hw *hw)
+static int mt7921u_mac_reset(struct mt792x_dev *dev)
{
- struct mt792x_dev *dev = mt792x_hw_dev(hw);
+ int err;
+
+ mt76_txq_schedule_all(&dev->mphy);
+ mt76_worker_disable(&dev->mt76.tx_worker);
+
+ set_bit(MT76_RESET, &dev->mphy.state);
+ set_bit(MT76_MCU_RESET, &dev->mphy.state);
+ wake_up(&dev->mt76.mcu.wait);
+ skb_queue_purge(&dev->mt76.mcu.res_q);
+
+ mt76u_stop_rx(&dev->mt76);
mt76u_stop_tx(&dev->mt76);
- mt7921_stop(hw);
+
+ mt792xu_wfsys_reset(dev);
+
+ clear_bit(MT76_MCU_RESET, &dev->mphy.state);
+ err = mt76u_resume_rx(&dev->mt76);
+ if (err)
+ goto out;
+
+ err = mt792xu_mcu_power_on(dev);
+ if (err)
+ goto out;
+
+ err = mt792xu_dma_init(dev, false);
+ if (err)
+ goto out;
+
+ mt76_wr(dev, MT_SWDEF_MODE, MT_SWDEF_NORMAL_MODE);
+ mt76_set(dev, MT_UDMA_TX_QSEL, MT_FW_DL_EN);
+
+ err = mt7921_run_firmware(dev);
+ if (err)
+ goto out;
+
+ mt76_clear(dev, MT_UDMA_TX_QSEL, MT_FW_DL_EN);
+
+ err = mt7921_mcu_set_eeprom(dev);
+ if (err)
+ goto out;
+
+ err = mt7921_mac_init(dev);
+ if (err)
+ goto out;
+
+ err = __mt7921_start(&dev->phy);
+out:
+ clear_bit(MT76_RESET, &dev->mphy.state);
+
+ mt76_worker_enable(&dev->mt76.tx_worker);
+
+ return err;
}
-static void mt7921u_cleanup(struct mt792x_dev *dev)
+static void mt7921u_stop(struct ieee80211_hw *hw)
{
- clear_bit(MT76_STATE_INITIALIZED, &dev->mphy.state);
- mt7921u_wfsys_reset(dev);
- skb_queue_purge(&dev->mt76.mcu.res_q);
- mt76u_queues_deinit(&dev->mt76);
+ struct mt792x_dev *dev = mt792x_hw_dev(hw);
+
+ mt76u_stop_tx(&dev->mt76);
+ mt7921_stop(hw);
}
static int mt7921u_probe(struct usb_interface *usb_intf,
@@ -193,15 +165,15 @@ static int mt7921u_probe(struct usb_interface *usb_intf,
};
static const struct mt792x_hif_ops hif_ops = {
.mcu_init = mt7921u_mcu_init,
- .init_reset = mt7921u_init_reset,
+ .init_reset = mt792xu_init_reset,
.reset = mt7921u_mac_reset,
};
static struct mt76_bus_ops bus_ops = {
- .rr = mt7921u_rr,
- .wr = mt7921u_wr,
- .rmw = mt7921u_rmw,
+ .rr = mt792xu_rr,
+ .wr = mt792xu_wr,
+ .rmw = mt792xu_rmw,
.read_copy = mt76u_read_copy,
- .write_copy = mt7921u_copy,
+ .write_copy = mt792xu_copy,
.type = MT76_BUS_USB,
};
struct usb_device *udev = interface_to_usbdev(usb_intf);
@@ -240,12 +212,12 @@ static int mt7921u_probe(struct usb_interface *usb_intf,
dev_dbg(mdev->dev, "ASIC revision: %04x\n", mdev->rev);
if (mt76_get_field(dev, MT_CONN_ON_MISC, MT_TOP_MISC2_FW_N9_RDY)) {
- ret = mt7921u_wfsys_reset(dev);
+ ret = mt792xu_wfsys_reset(dev);
if (ret)
goto error;
}
- ret = mt7921u_mcu_power_on(dev);
+ ret = mt792xu_mcu_power_on(dev);
if (ret)
goto error;
@@ -257,7 +229,7 @@ static int mt7921u_probe(struct usb_interface *usb_intf,
if (ret)
goto error;
- ret = mt7921u_dma_init(dev, false);
+ ret = mt792xu_dma_init(dev, false);
if (ret)
goto error;
@@ -291,7 +263,7 @@ static void mt7921u_disconnect(struct usb_interface *usb_intf)
return;
mt76_unregister_device(&dev->mt76);
- mt7921u_cleanup(dev);
+ mt792xu_cleanup(dev);
usb_set_intfdata(usb_intf, NULL);
usb_put_dev(interface_to_usbdev(usb_intf));
@@ -350,7 +322,7 @@ static int mt7921u_resume(struct usb_interface *intf)
}
if (reinit || mt792x_dma_need_reinit(dev)) {
- err = mt7921u_dma_init(dev, true);
+ err = mt792xu_dma_init(dev, true);
if (err)
goto failed;
}