Commit 24b1042c authored by Ming Lei's avatar Ming Lei Committed by David S. Miller

usbnet: dm9601: apply introduced usb command APIs

Acked-by: default avatarOliver Neukum <oneukum@suse.de>
Signed-off-by: default avatarMing Lei <ming.lei@canonical.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 90b8b037
...@@ -56,27 +56,12 @@ ...@@ -56,27 +56,12 @@
static int dm_read(struct usbnet *dev, u8 reg, u16 length, void *data) static int dm_read(struct usbnet *dev, u8 reg, u16 length, void *data)
{ {
void *buf; int err;
int err = -ENOMEM; err = usbnet_read_cmd(dev, DM_READ_REGS,
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
netdev_dbg(dev->net, "dm_read() reg=0x%02x length=%d\n", reg, length); 0, reg, data, length);
if(err != length && err >= 0)
buf = kmalloc(length, GFP_KERNEL);
if (!buf)
goto out;
err = usb_control_msg(dev->udev,
usb_rcvctrlpipe(dev->udev, 0),
DM_READ_REGS,
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
0, reg, buf, length, USB_CTRL_SET_TIMEOUT);
if (err == length)
memcpy(data, buf, length);
else if (err >= 0)
err = -EINVAL; err = -EINVAL;
kfree(buf);
out:
return err; return err;
} }
...@@ -87,91 +72,29 @@ static int dm_read_reg(struct usbnet *dev, u8 reg, u8 *value) ...@@ -87,91 +72,29 @@ static int dm_read_reg(struct usbnet *dev, u8 reg, u8 *value)
static int dm_write(struct usbnet *dev, u8 reg, u16 length, void *data) static int dm_write(struct usbnet *dev, u8 reg, u16 length, void *data)
{ {
void *buf = NULL; int err;
int err = -ENOMEM; err = usbnet_write_cmd(dev, DM_WRITE_REGS,
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
netdev_dbg(dev->net, "dm_write() reg=0x%02x, length=%d\n", reg, length); 0, reg, data, length);
if (data) {
buf = kmemdup(data, length, GFP_KERNEL);
if (!buf)
goto out;
}
err = usb_control_msg(dev->udev,
usb_sndctrlpipe(dev->udev, 0),
DM_WRITE_REGS,
USB_DIR_OUT | USB_TYPE_VENDOR |USB_RECIP_DEVICE,
0, reg, buf, length, USB_CTRL_SET_TIMEOUT);
kfree(buf);
if (err >= 0 && err < length) if (err >= 0 && err < length)
err = -EINVAL; err = -EINVAL;
out:
return err; return err;
} }
static int dm_write_reg(struct usbnet *dev, u8 reg, u8 value) static int dm_write_reg(struct usbnet *dev, u8 reg, u8 value)
{ {
netdev_dbg(dev->net, "dm_write_reg() reg=0x%02x, value=0x%02x\n", return usbnet_write_cmd(dev, DM_WRITE_REGS,
reg, value); USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
return usb_control_msg(dev->udev, value, reg, NULL, 0);
usb_sndctrlpipe(dev->udev, 0),
DM_WRITE_REG,
USB_DIR_OUT | USB_TYPE_VENDOR |USB_RECIP_DEVICE,
value, reg, NULL, 0, USB_CTRL_SET_TIMEOUT);
}
static void dm_write_async_callback(struct urb *urb)
{
struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
int status = urb->status;
if (status < 0)
printk(KERN_DEBUG "dm_write_async_callback() failed with %d\n",
status);
kfree(req);
usb_free_urb(urb);
} }
static void dm_write_async_helper(struct usbnet *dev, u8 reg, u8 value, static void dm_write_async_helper(struct usbnet *dev, u8 reg, u8 value,
u16 length, void *data) u16 length, void *data)
{ {
struct usb_ctrlrequest *req; usbnet_write_cmd_async(dev, DM_WRITE_REGS,
struct urb *urb; USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
int status; value, reg, data, length);
urb = usb_alloc_urb(0, GFP_ATOMIC);
if (!urb) {
netdev_err(dev->net, "Error allocating URB in dm_write_async_helper!\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 = length ? DM_WRITE_REGS : DM_WRITE_REG;
req->wValue = cpu_to_le16(value);
req->wIndex = cpu_to_le16(reg);
req->wLength = cpu_to_le16(length);
usb_fill_control_urb(urb, dev->udev,
usb_sndctrlpipe(dev->udev, 0),
(void *)req, data, length,
dm_write_async_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);
}
} }
static void dm_write_async(struct usbnet *dev, u8 reg, u16 length, void *data) static void dm_write_async(struct usbnet *dev, u8 reg, u16 length, void *data)
......
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