aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/usb/asix_common.c
diff options
context:
space:
mode:
authorMing Lei <ming.lei@canonical.com>2012-10-24 15:46:55 -0400
committerDavid S. Miller <davem@davemloft.net>2012-10-26 03:36:50 -0400
commit0bc69efb91824ecb17b5590beb0e33090f48bc18 (patch)
treedf271e05974fe0444d5f2c12dc906f5e9776ec2e /drivers/net/usb/asix_common.c
parent877bd862f32b815d54ab5fc10a4fd903d7bf3012 (diff)
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>
Diffstat (limited to 'drivers/net/usb/asix_common.c')
-rw-r--r--drivers/net/usb/asix_common.c117
1 files changed, 13 insertions, 104 deletions
diff --git a/drivers/net/usb/asix_common.c b/drivers/net/usb/asix_common.c
index 774d9ce2dafc..50d167330d38 100644
--- a/drivers/net/usb/asix_common.c
+++ b/drivers/net/usb/asix_common.c
@@ -25,121 +25,30 @@
25int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, 25int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
26 u16 size, void *data) 26 u16 size, void *data)
27{ 27{
28 void *buf; 28 int ret;
29 int err = -ENOMEM; 29 ret = usbnet_read_cmd(dev, cmd,
30 30 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
31 netdev_dbg(dev->net, "asix_read_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d\n", 31 value, index, data, size);
32 cmd, value, index, size);
33
34 buf = kmalloc(size, GFP_KERNEL);
35 if (!buf)
36 goto out;
37
38 err = usb_control_msg(
39 dev->udev,
40 usb_rcvctrlpipe(dev->udev, 0),
41 cmd,
42 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
43 value,
44 index,
45 buf,
46 size,
47 USB_CTRL_GET_TIMEOUT);
48 if (err == size)
49 memcpy(data, buf, size);
50 else if (err >= 0)
51 err = -EINVAL;
52 kfree(buf);
53 32
54out: 33 if (ret != size && ret >= 0)
55 return err; 34 return -EINVAL;
35 return ret;
56} 36}
57 37
58int asix_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, 38int asix_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
59 u16 size, void *data) 39 u16 size, void *data)
60{ 40{
61 void *buf = NULL; 41 return usbnet_write_cmd(dev, cmd,
62 int err = -ENOMEM; 42 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
63 43 value, index, data, size);
64 netdev_dbg(dev->net, "asix_write_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d\n",
65 cmd, value, index, size);
66
67 if (data) {
68 buf = kmemdup(data, size, GFP_KERNEL);
69 if (!buf)
70 goto out;
71 }
72
73 err = usb_control_msg(
74 dev->udev,
75 usb_sndctrlpipe(dev->udev, 0),
76 cmd,
77 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
78 value,
79 index,
80 buf,
81 size,
82 USB_CTRL_SET_TIMEOUT);
83 kfree(buf);
84
85out:
86 return err;
87}
88
89static void asix_async_cmd_callback(struct urb *urb)
90{
91 struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
92 int status = urb->status;
93
94 if (status < 0)
95 printk(KERN_DEBUG "asix_async_cmd_callback() failed with %d",
96 status);
97
98 kfree(req);
99 usb_free_urb(urb);
100} 44}
101 45
102void asix_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index, 46void asix_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
103 u16 size, void *data) 47 u16 size, void *data)
104{ 48{
105 struct usb_ctrlrequest *req; 49 usbnet_write_cmd_async(dev, cmd,
106 int status; 50 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
107 struct urb *urb; 51 value, index, data, size);
108
109 netdev_dbg(dev->net, "asix_write_cmd_async() cmd=0x%02x value=0x%04x index=0x%04x size=%d\n",
110 cmd, value, index, size);
111
112 urb = usb_alloc_urb(0, GFP_ATOMIC);
113 if (!urb) {
114 netdev_err(dev->net, "Error allocating URB in write_cmd_async!\n");
115 return;
116 }
117
118 req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC);
119 if (!req) {
120 netdev_err(dev->net, "Failed to allocate memory for control request\n");
121 usb_free_urb(urb);
122 return;
123 }
124
125 req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
126 req->bRequest = cmd;
127 req->wValue = cpu_to_le16(value);
128 req->wIndex = cpu_to_le16(index);
129 req->wLength = cpu_to_le16(size);
130
131 usb_fill_control_urb(urb, dev->udev,
132 usb_sndctrlpipe(dev->udev, 0),
133 (void *)req, data, size,
134 asix_async_cmd_callback, req);
135
136 status = usb_submit_urb(urb, GFP_ATOMIC);
137 if (status < 0) {
138 netdev_err(dev->net, "Error submitting the control message: status=%d\n",
139 status);
140 kfree(req);
141 usb_free_urb(urb);
142 }
143} 52}
144 53
145int asix_rx_fixup(struct usbnet *dev, struct sk_buff *skb) 54int asix_rx_fixup(struct usbnet *dev, struct sk_buff *skb)