usbnet: asix: apply introduced usb command APIs
Acked-by: Oliver Neukum <oneukum@suse.de> Signed-off-by: Ming Lei <ming.lei@canonical.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
committed by
David S. Miller
parent
877bd862f3
commit
0bc69efb91
@@ -25,121 +25,30 @@
|
|||||||
int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
|
int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
|
||||||
u16 size, void *data)
|
u16 size, void *data)
|
||||||
{
|
{
|
||||||
void *buf;
|
int ret;
|
||||||
int err = -ENOMEM;
|
ret = usbnet_read_cmd(dev, cmd,
|
||||||
|
|
||||||
netdev_dbg(dev->net, "asix_read_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d\n",
|
|
||||||
cmd, value, index, size);
|
|
||||||
|
|
||||||
buf = kmalloc(size, GFP_KERNEL);
|
|
||||||
if (!buf)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
err = usb_control_msg(
|
|
||||||
dev->udev,
|
|
||||||
usb_rcvctrlpipe(dev->udev, 0),
|
|
||||||
cmd,
|
|
||||||
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
|
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
|
||||||
value,
|
value, index, data, size);
|
||||||
index,
|
|
||||||
buf,
|
|
||||||
size,
|
|
||||||
USB_CTRL_GET_TIMEOUT);
|
|
||||||
if (err == size)
|
|
||||||
memcpy(data, buf, size);
|
|
||||||
else if (err >= 0)
|
|
||||||
err = -EINVAL;
|
|
||||||
kfree(buf);
|
|
||||||
|
|
||||||
out:
|
if (ret != size && ret >= 0)
|
||||||
return err;
|
return -EINVAL;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int asix_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
|
int asix_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
|
||||||
u16 size, void *data)
|
u16 size, void *data)
|
||||||
{
|
{
|
||||||
void *buf = NULL;
|
return usbnet_write_cmd(dev, cmd,
|
||||||
int err = -ENOMEM;
|
|
||||||
|
|
||||||
netdev_dbg(dev->net, "asix_write_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d\n",
|
|
||||||
cmd, value, index, size);
|
|
||||||
|
|
||||||
if (data) {
|
|
||||||
buf = kmemdup(data, size, GFP_KERNEL);
|
|
||||||
if (!buf)
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = usb_control_msg(
|
|
||||||
dev->udev,
|
|
||||||
usb_sndctrlpipe(dev->udev, 0),
|
|
||||||
cmd,
|
|
||||||
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
|
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
|
||||||
value,
|
value, index, data, size);
|
||||||
index,
|
|
||||||
buf,
|
|
||||||
size,
|
|
||||||
USB_CTRL_SET_TIMEOUT);
|
|
||||||
kfree(buf);
|
|
||||||
|
|
||||||
out:
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void asix_async_cmd_callback(struct urb *urb)
|
|
||||||
{
|
|
||||||
struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
|
|
||||||
int status = urb->status;
|
|
||||||
|
|
||||||
if (status < 0)
|
|
||||||
printk(KERN_DEBUG "asix_async_cmd_callback() failed with %d",
|
|
||||||
status);
|
|
||||||
|
|
||||||
kfree(req);
|
|
||||||
usb_free_urb(urb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void asix_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
|
void asix_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
|
||||||
u16 size, void *data)
|
u16 size, void *data)
|
||||||
{
|
{
|
||||||
struct usb_ctrlrequest *req;
|
usbnet_write_cmd_async(dev, cmd,
|
||||||
int status;
|
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
|
||||||
struct urb *urb;
|
value, index, data, size);
|
||||||
|
|
||||||
netdev_dbg(dev->net, "asix_write_cmd_async() cmd=0x%02x value=0x%04x index=0x%04x size=%d\n",
|
|
||||||
cmd, value, index, size);
|
|
||||||
|
|
||||||
urb = usb_alloc_urb(0, GFP_ATOMIC);
|
|
||||||
if (!urb) {
|
|
||||||
netdev_err(dev->net, "Error allocating URB in write_cmd_async!\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC);
|
|
||||||
if (!req) {
|
|
||||||
netdev_err(dev->net, "Failed to allocate memory for control request\n");
|
|
||||||
usb_free_urb(urb);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
|
|
||||||
req->bRequest = cmd;
|
|
||||||
req->wValue = cpu_to_le16(value);
|
|
||||||
req->wIndex = cpu_to_le16(index);
|
|
||||||
req->wLength = cpu_to_le16(size);
|
|
||||||
|
|
||||||
usb_fill_control_urb(urb, dev->udev,
|
|
||||||
usb_sndctrlpipe(dev->udev, 0),
|
|
||||||
(void *)req, data, size,
|
|
||||||
asix_async_cmd_callback, req);
|
|
||||||
|
|
||||||
status = usb_submit_urb(urb, GFP_ATOMIC);
|
|
||||||
if (status < 0) {
|
|
||||||
netdev_err(dev->net, "Error submitting the control message: status=%d\n",
|
|
||||||
status);
|
|
||||||
kfree(req);
|
|
||||||
usb_free_urb(urb);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int asix_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
|
int asix_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
|
||||||
|
Reference in New Issue
Block a user