mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-20 16:57:58 +07:00
mt76x02u: use usb_bulk_msg to upload firmware
We don't need to send firmware data asynchronously, much simpler is just use synchronous usb_bulk_msg(). Tested-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com> Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
parent
1ffe410ee3
commit
5de4db8fcb
@ -736,6 +736,19 @@ static inline bool mt76u_check_sg(struct mt76_dev *dev)
|
|||||||
udev->speed == USB_SPEED_WIRELESS));
|
udev->speed == USB_SPEED_WIRELESS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
mt76u_bulk_msg(struct mt76_dev *dev, void *data, int len, int timeout)
|
||||||
|
{
|
||||||
|
struct usb_interface *intf = to_usb_interface(dev->dev);
|
||||||
|
struct usb_device *udev = interface_to_usbdev(intf);
|
||||||
|
struct mt76_usb *usb = &dev->usb;
|
||||||
|
unsigned int pipe;
|
||||||
|
int sent;
|
||||||
|
|
||||||
|
pipe = usb_sndbulkpipe(udev, usb->out_ep[MT_EP_OUT_INBAND_CMD]);
|
||||||
|
return usb_bulk_msg(udev, pipe, data, len, &sent, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
int mt76u_vendor_request(struct mt76_dev *dev, u8 req,
|
int mt76u_vendor_request(struct mt76_dev *dev, u8 req,
|
||||||
u8 req_type, u16 val, u16 offset,
|
u8 req_type, u16 val, u16 offset,
|
||||||
void *buf, size_t len);
|
void *buf, size_t len);
|
||||||
|
@ -106,18 +106,14 @@ static int
|
|||||||
__mt76x02u_mcu_send_msg(struct mt76_dev *dev, struct sk_buff *skb,
|
__mt76x02u_mcu_send_msg(struct mt76_dev *dev, struct sk_buff *skb,
|
||||||
int cmd, bool wait_resp)
|
int cmd, bool wait_resp)
|
||||||
{
|
{
|
||||||
struct usb_interface *intf = to_usb_interface(dev->dev);
|
|
||||||
struct usb_device *udev = interface_to_usbdev(intf);
|
|
||||||
struct mt76_usb *usb = &dev->usb;
|
struct mt76_usb *usb = &dev->usb;
|
||||||
unsigned int pipe;
|
int ret;
|
||||||
int ret, sent;
|
|
||||||
u8 seq = 0;
|
u8 seq = 0;
|
||||||
u32 info;
|
u32 info;
|
||||||
|
|
||||||
if (test_bit(MT76_REMOVED, &dev->state))
|
if (test_bit(MT76_REMOVED, &dev->state))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
pipe = usb_sndbulkpipe(udev, usb->out_ep[MT_EP_OUT_INBAND_CMD]);
|
|
||||||
if (wait_resp) {
|
if (wait_resp) {
|
||||||
seq = ++usb->mcu.msg_seq & 0xf;
|
seq = ++usb->mcu.msg_seq & 0xf;
|
||||||
if (!seq)
|
if (!seq)
|
||||||
@ -131,7 +127,7 @@ __mt76x02u_mcu_send_msg(struct mt76_dev *dev, struct sk_buff *skb,
|
|||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
ret = usb_bulk_msg(udev, pipe, skb->data, skb->len, &sent, 500);
|
ret = mt76u_bulk_msg(dev, skb->data, skb->len, 500);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
@ -253,14 +249,12 @@ void mt76x02u_mcu_fw_reset(struct mt76x02_dev *dev)
|
|||||||
EXPORT_SYMBOL_GPL(mt76x02u_mcu_fw_reset);
|
EXPORT_SYMBOL_GPL(mt76x02u_mcu_fw_reset);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
__mt76x02u_mcu_fw_send_data(struct mt76x02_dev *dev, struct mt76u_buf *buf,
|
__mt76x02u_mcu_fw_send_data(struct mt76x02_dev *dev, u8 *data,
|
||||||
const void *fw_data, int len, u32 dst_addr)
|
const void *fw_data, int len, u32 dst_addr)
|
||||||
{
|
{
|
||||||
u8 *data = sg_virt(&buf->urb->sg[0]);
|
|
||||||
DECLARE_COMPLETION_ONSTACK(cmpl);
|
|
||||||
__le32 info;
|
__le32 info;
|
||||||
u32 val;
|
u32 val;
|
||||||
int err;
|
int err, data_len;
|
||||||
|
|
||||||
info = cpu_to_le32(FIELD_PREP(MT_MCU_MSG_PORT, CPU_TX_PORT) |
|
info = cpu_to_le32(FIELD_PREP(MT_MCU_MSG_PORT, CPU_TX_PORT) |
|
||||||
FIELD_PREP(MT_MCU_MSG_LEN, len) |
|
FIELD_PREP(MT_MCU_MSG_LEN, len) |
|
||||||
@ -276,25 +270,12 @@ __mt76x02u_mcu_fw_send_data(struct mt76x02_dev *dev, struct mt76u_buf *buf,
|
|||||||
mt76u_single_wr(&dev->mt76, MT_VEND_WRITE_FCE,
|
mt76u_single_wr(&dev->mt76, MT_VEND_WRITE_FCE,
|
||||||
MT_FCE_DMA_LEN, len << 16);
|
MT_FCE_DMA_LEN, len << 16);
|
||||||
|
|
||||||
buf->len = MT_CMD_HDR_LEN + len + sizeof(info);
|
data_len = MT_CMD_HDR_LEN + len + sizeof(info);
|
||||||
err = mt76u_submit_buf(&dev->mt76, USB_DIR_OUT,
|
|
||||||
MT_EP_OUT_INBAND_CMD,
|
err = mt76u_bulk_msg(&dev->mt76, data, data_len, 1000);
|
||||||
buf, GFP_KERNEL,
|
if (err) {
|
||||||
mt76u_mcu_complete_urb, &cmpl);
|
dev_err(dev->mt76.dev, "firmware upload failed: %d\n", err);
|
||||||
if (err < 0)
|
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
if (!wait_for_completion_timeout(&cmpl,
|
|
||||||
msecs_to_jiffies(1000))) {
|
|
||||||
dev_err(dev->mt76.dev, "firmware upload timed out\n");
|
|
||||||
usb_kill_urb(buf->urb);
|
|
||||||
return -ETIMEDOUT;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mt76u_urb_error(buf->urb)) {
|
|
||||||
dev_err(dev->mt76.dev, "firmware upload failed: %d\n",
|
|
||||||
buf->urb->status);
|
|
||||||
return buf->urb->status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val = mt76_rr(dev, MT_TX_CPU_FROM_FCE_CPU_DESC_IDX);
|
val = mt76_rr(dev, MT_TX_CPU_FROM_FCE_CPU_DESC_IDX);
|
||||||
@ -307,17 +288,16 @@ __mt76x02u_mcu_fw_send_data(struct mt76x02_dev *dev, struct mt76u_buf *buf,
|
|||||||
int mt76x02u_mcu_fw_send_data(struct mt76x02_dev *dev, const void *data,
|
int mt76x02u_mcu_fw_send_data(struct mt76x02_dev *dev, const void *data,
|
||||||
int data_len, u32 max_payload, u32 offset)
|
int data_len, u32 max_payload, u32 offset)
|
||||||
{
|
{
|
||||||
int err, len, pos = 0, max_len = max_payload - 8;
|
int len, err = 0, pos = 0, max_len = max_payload - 8;
|
||||||
struct mt76u_buf buf;
|
u8 *buf;
|
||||||
|
|
||||||
err = mt76u_buf_alloc(&dev->mt76, &buf, 1, max_payload, max_payload,
|
buf = kmalloc(max_payload, GFP_KERNEL);
|
||||||
GFP_KERNEL);
|
if (!buf)
|
||||||
if (err < 0)
|
return -ENOMEM;
|
||||||
return err;
|
|
||||||
|
|
||||||
while (data_len > 0) {
|
while (data_len > 0) {
|
||||||
len = min_t(int, data_len, max_len);
|
len = min_t(int, data_len, max_len);
|
||||||
err = __mt76x02u_mcu_fw_send_data(dev, &buf, data + pos,
|
err = __mt76x02u_mcu_fw_send_data(dev, buf, data + pos,
|
||||||
len, offset + pos);
|
len, offset + pos);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
break;
|
break;
|
||||||
@ -326,7 +306,7 @@ int mt76x02u_mcu_fw_send_data(struct mt76x02_dev *dev, const void *data,
|
|||||||
pos += len;
|
pos += len;
|
||||||
usleep_range(5000, 10000);
|
usleep_range(5000, 10000);
|
||||||
}
|
}
|
||||||
mt76u_buf_free(&buf);
|
kfree(buf);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -326,7 +326,6 @@ int mt76u_buf_alloc(struct mt76_dev *dev, struct mt76u_buf *buf,
|
|||||||
|
|
||||||
return mt76u_fill_rx_sg(dev, buf, nsgs, len, sglen);
|
return mt76u_fill_rx_sg(dev, buf, nsgs, len, sglen);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(mt76u_buf_alloc);
|
|
||||||
|
|
||||||
void mt76u_buf_free(struct mt76u_buf *buf)
|
void mt76u_buf_free(struct mt76u_buf *buf)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user