Commit a18a494f authored by Stanislaw Gruszka's avatar Stanislaw Gruszka Committed by Felix Fietkau

mt76usb: use synchronous msg for mcu command responses

Use usb_bulk_msg for reading MCU command responses. This simplify code
a lot.

Together with 97a3005759c ("mt76usb: allow mt76u_bulk_msg be used
for reads") it also fix possible problems with rx data buffers
not being aligned and contained within single page. After doing
page_frag_alloc(1024) consecutive page_frag_alloc(PAGE_SIZE) will
alloc PAGE_SIZE buffer at PAGE_SIZE - 1024 offset.
Signed-off-by: default avatarStanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent b63aa031
...@@ -384,8 +384,7 @@ struct mt76_usb { ...@@ -384,8 +384,7 @@ struct mt76_usb {
struct mt76u_mcu { struct mt76u_mcu {
struct mutex mutex; struct mutex mutex;
struct completion cmpl; u8 *data;
struct mt76u_buf res;
u32 msg_seq; u32 msg_seq;
/* multiple reads */ /* multiple reads */
......
...@@ -311,13 +311,11 @@ static int __maybe_unused mt76x0_suspend(struct usb_interface *usb_intf, ...@@ -311,13 +311,11 @@ static int __maybe_unused mt76x0_suspend(struct usb_interface *usb_intf,
pm_message_t state) pm_message_t state)
{ {
struct mt76x02_dev *dev = usb_get_intfdata(usb_intf); struct mt76x02_dev *dev = usb_get_intfdata(usb_intf);
struct mt76_usb *usb = &dev->mt76.usb;
mt76u_stop_queues(&dev->mt76); mt76u_stop_queues(&dev->mt76);
mt76x0u_mac_stop(dev); mt76x0u_mac_stop(dev);
clear_bit(MT76_STATE_MCU_RUNNING, &dev->mt76.state); clear_bit(MT76_STATE_MCU_RUNNING, &dev->mt76.state);
mt76x0_chip_onoff(dev, false, false); mt76x0_chip_onoff(dev, false, false);
usb_kill_urb(usb->mcu.res.urb);
return 0; return 0;
} }
...@@ -328,15 +326,6 @@ static int __maybe_unused mt76x0_resume(struct usb_interface *usb_intf) ...@@ -328,15 +326,6 @@ static int __maybe_unused mt76x0_resume(struct usb_interface *usb_intf)
struct mt76_usb *usb = &dev->mt76.usb; struct mt76_usb *usb = &dev->mt76.usb;
int ret; int ret;
reinit_completion(&usb->mcu.cmpl);
ret = mt76u_submit_buf(&dev->mt76, USB_DIR_IN,
MT_EP_IN_CMD_RESP,
&usb->mcu.res, GFP_KERNEL,
mt76u_mcu_complete_urb,
&usb->mcu.cmpl);
if (ret < 0)
goto err;
ret = mt76u_submit_rx_buffers(&dev->mt76); ret = mt76u_submit_rx_buffers(&dev->mt76);
if (ret < 0) if (ret < 0)
goto err; goto err;
......
...@@ -61,33 +61,21 @@ mt76x02u_multiple_mcu_reads(struct mt76_dev *dev, u8 *data, int len) ...@@ -61,33 +61,21 @@ mt76x02u_multiple_mcu_reads(struct mt76_dev *dev, u8 *data, int len)
static int mt76x02u_mcu_wait_resp(struct mt76_dev *dev, u8 seq) static int mt76x02u_mcu_wait_resp(struct mt76_dev *dev, u8 seq)
{ {
struct mt76_usb *usb = &dev->usb; struct mt76_usb *usb = &dev->usb;
struct mt76u_buf *buf = &usb->mcu.res; u8 *data = usb->mcu.data;
struct urb *urb = buf->urb; int i, len, ret;
u8 *data = buf->buf;
int i, ret;
u32 rxfce; u32 rxfce;
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
if (!wait_for_completion_timeout(&usb->mcu.cmpl, ret = mt76u_bulk_msg(dev, data, MCU_RESP_URB_SIZE, &len, 300);
msecs_to_jiffies(300))) if (ret == -ETIMEDOUT)
continue; continue;
if (ret)
if (urb->status) goto out;
return -EIO;
if (usb->mcu.rp) if (usb->mcu.rp)
mt76x02u_multiple_mcu_reads(dev, data + 4, mt76x02u_multiple_mcu_reads(dev, data + 4, len - 8);
urb->actual_length - 8);
rxfce = get_unaligned_le32(data); rxfce = get_unaligned_le32(data);
ret = mt76u_submit_buf(dev, USB_DIR_IN,
MT_EP_IN_CMD_RESP,
buf, GFP_KERNEL,
mt76u_mcu_complete_urb,
&usb->mcu.cmpl);
if (ret)
return ret;
if (seq == FIELD_GET(MT_RX_FCE_INFO_CMD_SEQ, rxfce) && if (seq == FIELD_GET(MT_RX_FCE_INFO_CMD_SEQ, rxfce) &&
FIELD_GET(MT_RX_FCE_INFO_EVT_TYPE, rxfce) == EVT_CMD_DONE) FIELD_GET(MT_RX_FCE_INFO_EVT_TYPE, rxfce) == EVT_CMD_DONE)
return 0; return 0;
...@@ -96,9 +84,9 @@ static int mt76x02u_mcu_wait_resp(struct mt76_dev *dev, u8 seq) ...@@ -96,9 +84,9 @@ static int mt76x02u_mcu_wait_resp(struct mt76_dev *dev, u8 seq)
FIELD_GET(MT_RX_FCE_INFO_EVT_TYPE, rxfce), FIELD_GET(MT_RX_FCE_INFO_EVT_TYPE, rxfce),
seq, FIELD_GET(MT_RX_FCE_INFO_CMD_SEQ, rxfce)); seq, FIELD_GET(MT_RX_FCE_INFO_CMD_SEQ, rxfce));
} }
out:
dev_err(dev->dev, "error: %s timed out\n", __func__); dev_err(dev->dev, "error: %s failed with %d\n", __func__, ret);
return -ETIMEDOUT; return ret;
} }
static int static int
......
...@@ -100,11 +100,9 @@ static int __maybe_unused mt76x2u_suspend(struct usb_interface *intf, ...@@ -100,11 +100,9 @@ static int __maybe_unused mt76x2u_suspend(struct usb_interface *intf,
pm_message_t state) pm_message_t state)
{ {
struct mt76x02_dev *dev = usb_get_intfdata(intf); struct mt76x02_dev *dev = usb_get_intfdata(intf);
struct mt76_usb *usb = &dev->mt76.usb;
mt76u_stop_queues(&dev->mt76); mt76u_stop_queues(&dev->mt76);
mt76x2u_stop_hw(dev); mt76x2u_stop_hw(dev);
usb_kill_urb(usb->mcu.res.urb);
return 0; return 0;
} }
...@@ -115,15 +113,6 @@ static int __maybe_unused mt76x2u_resume(struct usb_interface *intf) ...@@ -115,15 +113,6 @@ static int __maybe_unused mt76x2u_resume(struct usb_interface *intf)
struct mt76_usb *usb = &dev->mt76.usb; struct mt76_usb *usb = &dev->mt76.usb;
int err; int err;
reinit_completion(&usb->mcu.cmpl);
err = mt76u_submit_buf(&dev->mt76, USB_DIR_IN,
MT_EP_IN_CMD_RESP,
&usb->mcu.res, GFP_KERNEL,
mt76u_mcu_complete_urb,
&usb->mcu.cmpl);
if (err < 0)
goto err;
err = mt76u_submit_rx_buffers(&dev->mt76); err = mt76u_submit_rx_buffers(&dev->mt76);
if (err < 0) if (err < 0)
goto err; goto err;
......
...@@ -933,7 +933,6 @@ int mt76u_init(struct mt76_dev *dev, ...@@ -933,7 +933,6 @@ int mt76u_init(struct mt76_dev *dev,
INIT_DELAYED_WORK(&usb->stat_work, mt76u_tx_status_data); INIT_DELAYED_WORK(&usb->stat_work, mt76u_tx_status_data);
skb_queue_head_init(&dev->rx_skb[MT_RXQ_MAIN]); skb_queue_head_init(&dev->rx_skb[MT_RXQ_MAIN]);
init_completion(&usb->mcu.cmpl);
mutex_init(&usb->mcu.mutex); mutex_init(&usb->mcu.mutex);
mutex_init(&usb->usb_ctrl_mtx); mutex_init(&usb->usb_ctrl_mtx);
......
...@@ -16,42 +16,19 @@ ...@@ -16,42 +16,19 @@
#include "mt76.h" #include "mt76.h"
void mt76u_mcu_complete_urb(struct urb *urb)
{
struct completion *cmpl = urb->context;
complete(cmpl);
}
EXPORT_SYMBOL_GPL(mt76u_mcu_complete_urb);
int mt76u_mcu_init_rx(struct mt76_dev *dev) int mt76u_mcu_init_rx(struct mt76_dev *dev)
{ {
struct mt76_usb *usb = &dev->usb; struct mt76_usb *usb = &dev->usb;
int err;
err = mt76u_buf_alloc(dev, &usb->mcu.res, MCU_RESP_URB_SIZE, usb->mcu.data = kmalloc(MCU_RESP_URB_SIZE, GFP_KERNEL);
MCU_RESP_URB_SIZE, GFP_KERNEL); return usb->mcu.data ? 0 : -ENOMEM;
if (err < 0)
return err;
err = mt76u_submit_buf(dev, USB_DIR_IN, MT_EP_IN_CMD_RESP,
&usb->mcu.res, GFP_KERNEL,
mt76u_mcu_complete_urb,
&usb->mcu.cmpl);
if (err < 0)
mt76u_buf_free(&usb->mcu.res);
return err;
} }
EXPORT_SYMBOL_GPL(mt76u_mcu_init_rx); EXPORT_SYMBOL_GPL(mt76u_mcu_init_rx);
void mt76u_mcu_deinit(struct mt76_dev *dev) void mt76u_mcu_deinit(struct mt76_dev *dev)
{ {
struct mt76u_buf *buf = &dev->usb.mcu.res; struct mt76_usb *usb = &dev->usb;
if (buf->urb) { kfree(usb->mcu.data);
usb_kill_urb(buf->urb);
mt76u_buf_free(buf);
}
} }
EXPORT_SYMBOL_GPL(mt76u_mcu_deinit); EXPORT_SYMBOL_GPL(mt76u_mcu_deinit);
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