aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/usb
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2010-10-23 14:47:02 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-10-23 14:47:02 -0400
commit5f05647dd81c11a6a165ccc8f0c1370b16f3bcb0 (patch)
tree7851ef1c93aa1aba7ef327ca4b75fd35e6d10f29 /drivers/net/usb
parent02f36038c568111ad4fc433f6fa760ff5e38fab4 (diff)
parentec37a48d1d16c30b655ac5280209edf52a6775d4 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6: (1699 commits) bnx2/bnx2x: Unsupported Ethtool operations should return -EINVAL. vlan: Calling vlan_hwaccel_do_receive() is always valid. tproxy: use the interface primary IP address as a default value for --on-ip tproxy: added IPv6 support to the socket match cxgb3: function namespace cleanup tproxy: added IPv6 support to the TPROXY target tproxy: added IPv6 socket lookup function to nf_tproxy_core be2net: Changes to use only priority codes allowed by f/w tproxy: allow non-local binds of IPv6 sockets if IP_TRANSPARENT is enabled tproxy: added tproxy sockopt interface in the IPV6 layer tproxy: added udp6_lib_lookup function tproxy: added const specifiers to udp lookup functions tproxy: split off ipv6 defragmentation to a separate module l2tp: small cleanup nf_nat: restrict ICMP translation for embedded header can: mcp251x: fix generation of error frames can: mcp251x: fix endless loop in interrupt handler if CANINTF_MERRF is set can-raw: add msg_flags to distinguish local traffic 9p: client code cleanup rds: make local functions/variables static ... Fix up conflicts in net/core/dev.c, drivers/net/pcmcia/smc91c92_cs.c and drivers/net/wireless/ath/ath9k/debug.c as per David
Diffstat (limited to 'drivers/net/usb')
-rw-r--r--drivers/net/usb/Kconfig8
-rw-r--r--drivers/net/usb/Makefile1
-rw-r--r--drivers/net/usb/cx82310_eth.c346
-rw-r--r--drivers/net/usb/hso.c9
-rw-r--r--drivers/net/usb/kaweth.c9
-rw-r--r--drivers/net/usb/sierra_net.c4
-rw-r--r--drivers/net/usb/smsc95xx.c4
7 files changed, 359 insertions, 22 deletions
diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig
index d7b7018a1de1..52ffabe6db0e 100644
--- a/drivers/net/usb/Kconfig
+++ b/drivers/net/usb/Kconfig
@@ -358,6 +358,14 @@ config USB_NET_ZAURUS
358 really need this non-conformant variant of CDC Ethernet (or in 358 really need this non-conformant variant of CDC Ethernet (or in
359 some cases CDC MDLM) protocol, not "g_ether". 359 some cases CDC MDLM) protocol, not "g_ether".
360 360
361config USB_NET_CX82310_ETH
362 tristate "Conexant CX82310 USB ethernet port"
363 depends on USB_USBNET
364 help
365 Choose this option if you're using a Conexant CX82310-based ADSL
366 router with USB ethernet port. This driver is for routers only,
367 it will not work with ADSL modems (use cxacru driver instead).
368
361config USB_HSO 369config USB_HSO
362 tristate "Option USB High Speed Mobile Devices" 370 tristate "Option USB High Speed Mobile Devices"
363 depends on USB && RFKILL 371 depends on USB && RFKILL
diff --git a/drivers/net/usb/Makefile b/drivers/net/usb/Makefile
index b13a279663ba..a19b0259ae16 100644
--- a/drivers/net/usb/Makefile
+++ b/drivers/net/usb/Makefile
@@ -25,4 +25,5 @@ obj-$(CONFIG_USB_NET_INT51X1) += int51x1.o
25obj-$(CONFIG_USB_CDC_PHONET) += cdc-phonet.o 25obj-$(CONFIG_USB_CDC_PHONET) += cdc-phonet.o
26obj-$(CONFIG_USB_IPHETH) += ipheth.o 26obj-$(CONFIG_USB_IPHETH) += ipheth.o
27obj-$(CONFIG_USB_SIERRA_NET) += sierra_net.o 27obj-$(CONFIG_USB_SIERRA_NET) += sierra_net.o
28obj-$(CONFIG_USB_NET_CX82310_ETH) += cx82310_eth.o
28 29
diff --git a/drivers/net/usb/cx82310_eth.c b/drivers/net/usb/cx82310_eth.c
new file mode 100644
index 000000000000..8969f124c18c
--- /dev/null
+++ b/drivers/net/usb/cx82310_eth.c
@@ -0,0 +1,346 @@
1/*
2 * Driver for USB ethernet port of Conexant CX82310-based ADSL routers
3 * Copyright (C) 2010 by Ondrej Zary
4 * some parts inspired by the cxacru driver
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <linux/module.h>
22#include <linux/init.h>
23#include <linux/netdevice.h>
24#include <linux/etherdevice.h>
25#include <linux/ethtool.h>
26#include <linux/workqueue.h>
27#include <linux/mii.h>
28#include <linux/usb.h>
29#include <linux/usb/usbnet.h>
30
31enum cx82310_cmd {
32 CMD_START = 0x84, /* no effect? */
33 CMD_STOP = 0x85, /* no effect? */
34 CMD_GET_STATUS = 0x90, /* returns nothing? */
35 CMD_GET_MAC_ADDR = 0x91, /* read MAC address */
36 CMD_GET_LINK_STATUS = 0x92, /* not useful, link is always up */
37 CMD_ETHERNET_MODE = 0x99, /* unknown, needed during init */
38};
39
40enum cx82310_status {
41 STATUS_UNDEFINED,
42 STATUS_SUCCESS,
43 STATUS_ERROR,
44 STATUS_UNSUPPORTED,
45 STATUS_UNIMPLEMENTED,
46 STATUS_PARAMETER_ERROR,
47 STATUS_DBG_LOOPBACK,
48};
49
50#define CMD_PACKET_SIZE 64
51/* first command after power on can take around 8 seconds */
52#define CMD_TIMEOUT 15000
53#define CMD_REPLY_RETRY 5
54
55#define CX82310_MTU 1514
56#define CMD_EP 0x01
57
58/*
59 * execute control command
60 * - optionally send some data (command parameters)
61 * - optionally wait for the reply
62 * - optionally read some data from the reply
63 */
64static int cx82310_cmd(struct usbnet *dev, enum cx82310_cmd cmd, bool reply,
65 u8 *wdata, int wlen, u8 *rdata, int rlen)
66{
67 int actual_len, retries, ret;
68 struct usb_device *udev = dev->udev;
69 u8 *buf = kzalloc(CMD_PACKET_SIZE, GFP_KERNEL);
70
71 if (!buf)
72 return -ENOMEM;
73
74 /* create command packet */
75 buf[0] = cmd;
76 if (wdata)
77 memcpy(buf + 4, wdata, min_t(int, wlen, CMD_PACKET_SIZE - 4));
78
79 /* send command packet */
80 ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, CMD_EP), buf,
81 CMD_PACKET_SIZE, &actual_len, CMD_TIMEOUT);
82 if (ret < 0) {
83 dev_err(&dev->udev->dev, "send command %#x: error %d\n",
84 cmd, ret);
85 goto end;
86 }
87
88 if (reply) {
89 /* wait for reply, retry if it's empty */
90 for (retries = 0; retries < CMD_REPLY_RETRY; retries++) {
91 ret = usb_bulk_msg(udev, usb_rcvbulkpipe(udev, CMD_EP),
92 buf, CMD_PACKET_SIZE, &actual_len,
93 CMD_TIMEOUT);
94 if (ret < 0) {
95 dev_err(&dev->udev->dev,
96 "reply receive error %d\n", ret);
97 goto end;
98 }
99 if (actual_len > 0)
100 break;
101 }
102 if (actual_len == 0) {
103 dev_err(&dev->udev->dev, "no reply to command %#x\n",
104 cmd);
105 ret = -EIO;
106 goto end;
107 }
108 if (buf[0] != cmd) {
109 dev_err(&dev->udev->dev,
110 "got reply to command %#x, expected: %#x\n",
111 buf[0], cmd);
112 ret = -EIO;
113 goto end;
114 }
115 if (buf[1] != STATUS_SUCCESS) {
116 dev_err(&dev->udev->dev, "command %#x failed: %#x\n",
117 cmd, buf[1]);
118 ret = -EIO;
119 goto end;
120 }
121 if (rdata)
122 memcpy(rdata, buf + 4,
123 min_t(int, rlen, CMD_PACKET_SIZE - 4));
124 }
125end:
126 kfree(buf);
127 return ret;
128}
129
130#define partial_len data[0] /* length of partial packet data */
131#define partial_rem data[1] /* remaining (missing) data length */
132#define partial_data data[2] /* partial packet data */
133
134static int cx82310_bind(struct usbnet *dev, struct usb_interface *intf)
135{
136 int ret;
137 char buf[15];
138 struct usb_device *udev = dev->udev;
139
140 /* avoid ADSL modems - continue only if iProduct is "USB NET CARD" */
141 if (usb_string(udev, udev->descriptor.iProduct, buf, sizeof(buf)) > 0
142 && strcmp(buf, "USB NET CARD")) {
143 dev_info(&udev->dev, "ignoring: probably an ADSL modem\n");
144 return -ENODEV;
145 }
146
147 ret = usbnet_get_endpoints(dev, intf);
148 if (ret)
149 return ret;
150
151 /*
152 * this must not include ethernet header as the device can send partial
153 * packets with no header (and sometimes even empty URBs)
154 */
155 dev->net->hard_header_len = 0;
156 /* we can send at most 1514 bytes of data (+ 2-byte header) per URB */
157 dev->hard_mtu = CX82310_MTU + 2;
158 /* we can receive URBs up to 4KB from the device */
159 dev->rx_urb_size = 4096;
160
161 dev->partial_data = (unsigned long) kmalloc(dev->hard_mtu, GFP_KERNEL);
162 if (!dev->partial_data)
163 return -ENOMEM;
164
165 /* enable ethernet mode (?) */
166 ret = cx82310_cmd(dev, CMD_ETHERNET_MODE, true, "\x01", 1, NULL, 0);
167 if (ret) {
168 dev_err(&udev->dev, "unable to enable ethernet mode: %d\n",
169 ret);
170 goto err;
171 }
172
173 /* get the MAC address */
174 ret = cx82310_cmd(dev, CMD_GET_MAC_ADDR, true, NULL, 0,
175 dev->net->dev_addr, ETH_ALEN);
176 if (ret) {
177 dev_err(&udev->dev, "unable to read MAC address: %d\n", ret);
178 goto err;
179 }
180
181 /* start (does not seem to have any effect?) */
182 ret = cx82310_cmd(dev, CMD_START, false, NULL, 0, NULL, 0);
183 if (ret)
184 goto err;
185
186 return 0;
187err:
188 kfree((void *)dev->partial_data);
189 return ret;
190}
191
192static void cx82310_unbind(struct usbnet *dev, struct usb_interface *intf)
193{
194 kfree((void *)dev->partial_data);
195}
196
197/*
198 * RX is NOT easy - we can receive multiple packets per skb, each having 2-byte
199 * packet length at the beginning.
200 * The last packet might be incomplete (when it crosses the 4KB URB size),
201 * continuing in the next skb (without any headers).
202 * If a packet has odd length, there is one extra byte at the end (before next
203 * packet or at the end of the URB).
204 */
205static int cx82310_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
206{
207 int len;
208 struct sk_buff *skb2;
209
210 /*
211 * If the last skb ended with an incomplete packet, this skb contains
212 * end of that packet at the beginning.
213 */
214 if (dev->partial_rem) {
215 len = dev->partial_len + dev->partial_rem;
216 skb2 = alloc_skb(len, GFP_ATOMIC);
217 if (!skb2)
218 return 0;
219 skb_put(skb2, len);
220 memcpy(skb2->data, (void *)dev->partial_data,
221 dev->partial_len);
222 memcpy(skb2->data + dev->partial_len, skb->data,
223 dev->partial_rem);
224 usbnet_skb_return(dev, skb2);
225 skb_pull(skb, (dev->partial_rem + 1) & ~1);
226 dev->partial_rem = 0;
227 if (skb->len < 2)
228 return 1;
229 }
230
231 /* a skb can contain multiple packets */
232 while (skb->len > 1) {
233 /* first two bytes are packet length */
234 len = skb->data[0] | (skb->data[1] << 8);
235 skb_pull(skb, 2);
236
237 /* if last packet in the skb, let usbnet to process it */
238 if (len == skb->len || len + 1 == skb->len) {
239 skb_trim(skb, len);
240 break;
241 }
242
243 if (len > CX82310_MTU) {
244 dev_err(&dev->udev->dev, "RX packet too long: %d B\n",
245 len);
246 return 0;
247 }
248
249 /* incomplete packet, save it for the next skb */
250 if (len > skb->len) {
251 dev->partial_len = skb->len;
252 dev->partial_rem = len - skb->len;
253 memcpy((void *)dev->partial_data, skb->data,
254 dev->partial_len);
255 skb_pull(skb, skb->len);
256 break;
257 }
258
259 skb2 = alloc_skb(len, GFP_ATOMIC);
260 if (!skb2)
261 return 0;
262 skb_put(skb2, len);
263 memcpy(skb2->data, skb->data, len);
264 /* process the packet */
265 usbnet_skb_return(dev, skb2);
266
267 skb_pull(skb, (len + 1) & ~1);
268 }
269
270 /* let usbnet process the last packet */
271 return 1;
272}
273
274/* TX is easy, just add 2 bytes of length at the beginning */
275static struct sk_buff *cx82310_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
276 gfp_t flags)
277{
278 int len = skb->len;
279
280 if (skb_headroom(skb) < 2) {
281 struct sk_buff *skb2 = skb_copy_expand(skb, 2, 0, flags);
282 dev_kfree_skb_any(skb);
283 skb = skb2;
284 if (!skb)
285 return NULL;
286 }
287 skb_push(skb, 2);
288
289 skb->data[0] = len;
290 skb->data[1] = len >> 8;
291
292 return skb;
293}
294
295
296static const struct driver_info cx82310_info = {
297 .description = "Conexant CX82310 USB ethernet",
298 .flags = FLAG_ETHER,
299 .bind = cx82310_bind,
300 .unbind = cx82310_unbind,
301 .rx_fixup = cx82310_rx_fixup,
302 .tx_fixup = cx82310_tx_fixup,
303};
304
305#define USB_DEVICE_CLASS(vend, prod, cl, sc, pr) \
306 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
307 USB_DEVICE_ID_MATCH_DEV_INFO, \
308 .idVendor = (vend), \
309 .idProduct = (prod), \
310 .bDeviceClass = (cl), \
311 .bDeviceSubClass = (sc), \
312 .bDeviceProtocol = (pr)
313
314static const struct usb_device_id products[] = {
315 {
316 USB_DEVICE_CLASS(0x0572, 0xcb01, 0xff, 0, 0),
317 .driver_info = (unsigned long) &cx82310_info
318 },
319 { },
320};
321MODULE_DEVICE_TABLE(usb, products);
322
323static struct usb_driver cx82310_driver = {
324 .name = "cx82310_eth",
325 .id_table = products,
326 .probe = usbnet_probe,
327 .disconnect = usbnet_disconnect,
328 .suspend = usbnet_suspend,
329 .resume = usbnet_resume,
330};
331
332static int __init cx82310_init(void)
333{
334 return usb_register(&cx82310_driver);
335}
336module_init(cx82310_init);
337
338static void __exit cx82310_exit(void)
339{
340 usb_deregister(&cx82310_driver);
341}
342module_exit(cx82310_exit);
343
344MODULE_AUTHOR("Ondrej Zary");
345MODULE_DESCRIPTION("Conexant CX82310-based ADSL router USB ethernet driver");
346MODULE_LICENSE("GPL");
diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index b8e957249132..b154a94de03e 100644
--- a/drivers/net/usb/hso.c
+++ b/drivers/net/usb/hso.c
@@ -843,16 +843,7 @@ static netdev_tx_t hso_net_start_xmit(struct sk_buff *skb,
843 return NETDEV_TX_OK; 843 return NETDEV_TX_OK;
844} 844}
845 845
846static void hso_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *info)
847{
848 struct hso_net *odev = netdev_priv(net);
849
850 strncpy(info->driver, driver_name, ETHTOOL_BUSINFO_LEN);
851 usb_make_path(odev->parent->usb, info->bus_info, sizeof info->bus_info);
852}
853
854static const struct ethtool_ops ops = { 846static const struct ethtool_ops ops = {
855 .get_drvinfo = hso_get_drvinfo,
856 .get_link = ethtool_op_get_link 847 .get_link = ethtool_op_get_link
857}; 848};
858 849
diff --git a/drivers/net/usb/kaweth.c b/drivers/net/usb/kaweth.c
index 2b7b39cad1ce..5e98643a4a21 100644
--- a/drivers/net/usb/kaweth.c
+++ b/drivers/net/usb/kaweth.c
@@ -759,14 +759,6 @@ static int kaweth_close(struct net_device *net)
759 return 0; 759 return 0;
760} 760}
761 761
762static void kaweth_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
763{
764 struct kaweth_device *kaweth = netdev_priv(dev);
765
766 strlcpy(info->driver, driver_name, sizeof(info->driver));
767 usb_make_path(kaweth->dev, info->bus_info, sizeof (info->bus_info));
768}
769
770static u32 kaweth_get_link(struct net_device *dev) 762static u32 kaweth_get_link(struct net_device *dev)
771{ 763{
772 struct kaweth_device *kaweth = netdev_priv(dev); 764 struct kaweth_device *kaweth = netdev_priv(dev);
@@ -775,7 +767,6 @@ static u32 kaweth_get_link(struct net_device *dev)
775} 767}
776 768
777static const struct ethtool_ops ops = { 769static const struct ethtool_ops ops = {
778 .get_drvinfo = kaweth_get_drvinfo,
779 .get_link = kaweth_get_link 770 .get_link = kaweth_get_link
780}; 771};
781 772
diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
index ee85c8b9a858..d1ac15c95faf 100644
--- a/drivers/net/usb/sierra_net.c
+++ b/drivers/net/usb/sierra_net.c
@@ -203,7 +203,7 @@ static inline void sierra_net_set_private(struct usbnet *dev,
203/* is packet IPv4 */ 203/* is packet IPv4 */
204static inline int is_ip(struct sk_buff *skb) 204static inline int is_ip(struct sk_buff *skb)
205{ 205{
206 return (skb->protocol == cpu_to_be16(ETH_P_IP)); 206 return skb->protocol == cpu_to_be16(ETH_P_IP);
207} 207}
208 208
209/* 209/*
@@ -354,7 +354,7 @@ static void sierra_net_set_ctx_index(struct sierra_net_data *priv, u8 ctx_ix)
354 354
355static inline int sierra_net_is_valid_addrlen(u8 len) 355static inline int sierra_net_is_valid_addrlen(u8 len)
356{ 356{
357 return (len == sizeof(struct in_addr)); 357 return len == sizeof(struct in_addr);
358} 358}
359 359
360static int sierra_net_parse_lsi(struct usbnet *dev, char *data, int datalen) 360static int sierra_net_parse_lsi(struct usbnet *dev, char *data, int datalen)
diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
index 12a3c88c5282..65cb1abfbe57 100644
--- a/drivers/net/usb/smsc95xx.c
+++ b/drivers/net/usb/smsc95xx.c
@@ -805,8 +805,6 @@ static int smsc95xx_reset(struct usbnet *dev)
805 return ret; 805 return ret;
806 } 806 }
807 807
808 smsc95xx_init_mac_address(dev);
809
810 ret = smsc95xx_set_mac_address(dev); 808 ret = smsc95xx_set_mac_address(dev);
811 if (ret < 0) 809 if (ret < 0)
812 return ret; 810 return ret;
@@ -1047,6 +1045,8 @@ static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf)
1047 pdata->use_tx_csum = DEFAULT_TX_CSUM_ENABLE; 1045 pdata->use_tx_csum = DEFAULT_TX_CSUM_ENABLE;
1048 pdata->use_rx_csum = DEFAULT_RX_CSUM_ENABLE; 1046 pdata->use_rx_csum = DEFAULT_RX_CSUM_ENABLE;
1049 1047
1048 smsc95xx_init_mac_address(dev);
1049
1050 /* Init all registers */ 1050 /* Init all registers */
1051 ret = smsc95xx_reset(dev); 1051 ret = smsc95xx_reset(dev);
1052 1052