aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/net
diff options
context:
space:
mode:
authorDavid Brownell <david-b@pacbell.net>2005-08-31 12:52:31 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2005-09-08 19:28:30 -0400
commitf29fc259976e9f4dd1fe8ed59ccdd50e4ea61db0 (patch)
treeef2798f4b6581926082b88a8cd6cdecbd11ac39e /drivers/usb/net
parentdd7d50081f5dafd9392bd79f1ec90d553a7303c9 (diff)
[PATCH] USB: usbnet (1/9) clean up framing
This starts to prepare the core of "usbnet" to know less about various framing protocols that map Ethernet packets onto USB, so "minidrivers" can be modules that just plug into the core. - Remove some framing-specific code that cluttered the core: * net->hard_header_len records how much space to preallocate; now drivers that add their own framing (Net1080, GeneLink, Zaurus, and RNDIS) will have smoother TX paths. Even for the drivers (Zaurus, Net1080) that need trailers. * defines new dev->hard_mtu, using this "hardware" limit to check changes to the link's settable "software" mtu. * now net->hard_header_len and dev->hard_mtu are set up in the driver bind() routines, if needed. - Transaction ID is no longer specific to the Net1080 framing; RNDIS needs one too. - Creates a new "usbnet.h" header with declarations that are shared between the core and what will be separate modules. - Plus a couple other minor tweaks, like recognizing -ESHUTDOWN means the keventd work should just shut itself down asap. The core code is only about 1/3 of this large file. Splitting out the minidrivers into separate modules (e.g. ones for ASIX adapters, Zaurii and similar, CDC Ethernet, etc), in later patches, will improve maintainability and shrink typical runtime footprints. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/net')
-rw-r--r--drivers/usb/net/Kconfig1
-rw-r--r--drivers/usb/net/usbnet.c289
-rw-r--r--drivers/usb/net/usbnet.h150
3 files changed, 240 insertions, 200 deletions
diff --git a/drivers/usb/net/Kconfig b/drivers/usb/net/Kconfig
index b104430e2c6a..135d50889d81 100644
--- a/drivers/usb/net/Kconfig
+++ b/drivers/usb/net/Kconfig
@@ -247,6 +247,7 @@ config USB_CDCETHER
247 247
248 CDC Ethernet is an implementation option for DOCSIS cable modems 248 CDC Ethernet is an implementation option for DOCSIS cable modems
249 that support USB connectivity, used for non-Microsoft USB hosts. 249 that support USB connectivity, used for non-Microsoft USB hosts.
250 The Linux-USB CDC Ethernet Gadget driver is an open implementation.
250 This driver should work with at least the following devices: 251 This driver should work with at least the following devices:
251 252
252 * Ericsson PipeRider (all variants) 253 * Ericsson PipeRider (all variants)
diff --git a/drivers/usb/net/usbnet.c b/drivers/usb/net/usbnet.c
index 3c6eef4168e5..3f2cad6dc261 100644
--- a/drivers/usb/net/usbnet.c
+++ b/drivers/usb/net/usbnet.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * USB Networking Links 2 * USB Networking Links
3 * Copyright (C) 2000-2005 by David Brownell <dbrownell@users.sourceforge.net> 3 * Copyright (C) 2000-2005 by David Brownell
4 * Copyright (C) 2002 Pavel Machek <pavel@ucw.cz> 4 * Copyright (C) 2002 Pavel Machek <pavel@ucw.cz>
5 * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com> 5 * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com>
6 * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net> 6 * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
@@ -126,19 +126,18 @@
126#include <linux/init.h> 126#include <linux/init.h>
127#include <linux/netdevice.h> 127#include <linux/netdevice.h>
128#include <linux/etherdevice.h> 128#include <linux/etherdevice.h>
129#include <linux/random.h>
130#include <linux/ethtool.h> 129#include <linux/ethtool.h>
131#include <linux/workqueue.h> 130#include <linux/workqueue.h>
132#include <linux/mii.h> 131#include <linux/mii.h>
133#include <asm/uaccess.h>
134#include <asm/unaligned.h>
135#include <linux/usb.h> 132#include <linux/usb.h>
136#include <asm/io.h>
137#include <asm/scatterlist.h>
138#include <linux/mm.h> 133#include <linux/mm.h>
139#include <linux/dma-mapping.h> 134#include <linux/dma-mapping.h>
140 135
141#define DRIVER_VERSION "03-Nov-2004" 136#include <asm/unaligned.h>
137
138#include "usbnet.h"
139
140#define DRIVER_VERSION "22-Aug-2005"
142 141
143 142
144/*-------------------------------------------------------------------------*/ 143/*-------------------------------------------------------------------------*/
@@ -149,14 +148,16 @@
149 * One maximum size Ethernet packet takes twenty four of them. 148 * One maximum size Ethernet packet takes twenty four of them.
150 * For high speed, each frame comfortably fits almost 36 max size 149 * For high speed, each frame comfortably fits almost 36 max size
151 * Ethernet packets (so queues should be bigger). 150 * Ethernet packets (so queues should be bigger).
151 *
152 * REVISIT qlens should be members of 'struct usbnet'; the goal is to
153 * let the USB host controller be busy for 5msec or more before an irq
154 * is required, under load. Jumbograms change the equation.
152 */ 155 */
153#define RX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4) 156#define RX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4)
154#define TX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4) 157#define TX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4)
155 158
156// packets are always ethernet inside 159/* packets are always ethernet, sometimes wrapped in other framing */
157// ... except they can be bigger (limit of 64K with NetChip framing)
158#define MIN_PACKET sizeof(struct ethhdr) 160#define MIN_PACKET sizeof(struct ethhdr)
159#define MAX_PACKET 32768
160 161
161// reawaken network queue this soon after stopping; else watchdog barks 162// reawaken network queue this soon after stopping; else watchdog barks
162#define TX_TIMEOUT_JIFFIES (5*HZ) 163#define TX_TIMEOUT_JIFFIES (5*HZ)
@@ -166,7 +167,7 @@
166#define THROTTLE_JIFFIES (HZ/8) 167#define THROTTLE_JIFFIES (HZ/8)
167 168
168// for vendor-specific control operations 169// for vendor-specific control operations
169#define CONTROL_TIMEOUT_MS 500 170#define CONTROL_TIMEOUT_MS USB_CTRL_GET_TIMEOUT
170 171
171// between wakeups 172// between wakeups
172#define UNLINK_TIMEOUT_MS 3 173#define UNLINK_TIMEOUT_MS 3
@@ -176,109 +177,6 @@
176// randomly generated ethernet address 177// randomly generated ethernet address
177static u8 node_id [ETH_ALEN]; 178static u8 node_id [ETH_ALEN];
178 179
179// state we keep for each device we handle
180struct usbnet {
181 // housekeeping
182 struct usb_device *udev;
183 struct driver_info *driver_info;
184 wait_queue_head_t *wait;
185
186 // i/o info: pipes etc
187 unsigned in, out;
188 struct usb_host_endpoint *status;
189 unsigned maxpacket;
190 struct timer_list delay;
191
192 // protocol/interface state
193 struct net_device *net;
194 struct net_device_stats stats;
195 int msg_enable;
196 unsigned long data [5];
197
198 struct mii_if_info mii;
199
200 // various kinds of pending driver work
201 struct sk_buff_head rxq;
202 struct sk_buff_head txq;
203 struct sk_buff_head done;
204 struct urb *interrupt;
205 struct tasklet_struct bh;
206
207 struct work_struct kevent;
208 unsigned long flags;
209# define EVENT_TX_HALT 0
210# define EVENT_RX_HALT 1
211# define EVENT_RX_MEMORY 2
212# define EVENT_STS_SPLIT 3
213# define EVENT_LINK_RESET 4
214};
215
216// device-specific info used by the driver
217struct driver_info {
218 char *description;
219
220 int flags;
221/* framing is CDC Ethernet, not writing ZLPs (hw issues), or optionally: */
222#define FLAG_FRAMING_NC 0x0001 /* guard against device dropouts */
223#define FLAG_FRAMING_GL 0x0002 /* genelink batches packets */
224#define FLAG_FRAMING_Z 0x0004 /* zaurus adds a trailer */
225#define FLAG_FRAMING_RN 0x0008 /* RNDIS batches, plus huge header */
226
227#define FLAG_NO_SETINT 0x0010 /* device can't set_interface() */
228#define FLAG_ETHER 0x0020 /* maybe use "eth%d" names */
229
230#define FLAG_FRAMING_AX 0x0040 /* AX88772/178 packets */
231
232 /* init device ... can sleep, or cause probe() failure */
233 int (*bind)(struct usbnet *, struct usb_interface *);
234
235 /* cleanup device ... can sleep, but can't fail */
236 void (*unbind)(struct usbnet *, struct usb_interface *);
237
238 /* reset device ... can sleep */
239 int (*reset)(struct usbnet *);
240
241 /* see if peer is connected ... can sleep */
242 int (*check_connect)(struct usbnet *);
243
244 /* for status polling */
245 void (*status)(struct usbnet *, struct urb *);
246
247 /* link reset handling, called from defer_kevent */
248 int (*link_reset)(struct usbnet *);
249
250 /* fixup rx packet (strip framing) */
251 int (*rx_fixup)(struct usbnet *dev, struct sk_buff *skb);
252
253 /* fixup tx packet (add framing) */
254 struct sk_buff *(*tx_fixup)(struct usbnet *dev,
255 struct sk_buff *skb, unsigned flags);
256
257 // FIXME -- also an interrupt mechanism
258 // useful for at least PL2301/2302 and GL620USB-A
259 // and CDC use them to report 'is it connected' changes
260
261 /* for new devices, use the descriptor-reading code instead */
262 int in; /* rx endpoint */
263 int out; /* tx endpoint */
264
265 unsigned long data; /* Misc driver specific data */
266};
267
268// we record the state for each of our queued skbs
269enum skb_state {
270 illegal = 0,
271 tx_start, tx_done,
272 rx_start, rx_done, rx_cleanup
273};
274
275struct skb_data { // skb->cb is one of these
276 struct urb *urb;
277 struct usbnet *dev;
278 enum skb_state state;
279 size_t length;
280};
281
282static const char driver_name [] = "usbnet"; 180static const char driver_name [] = "usbnet";
283 181
284/* use ethtool to change the level for any given device */ 182/* use ethtool to change the level for any given device */
@@ -286,22 +184,6 @@ static int msg_level = -1;
286module_param (msg_level, int, 0); 184module_param (msg_level, int, 0);
287MODULE_PARM_DESC (msg_level, "Override default message level"); 185MODULE_PARM_DESC (msg_level, "Override default message level");
288 186
289
290#ifdef DEBUG
291#define devdbg(usbnet, fmt, arg...) \
292 printk(KERN_DEBUG "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
293#else
294#define devdbg(usbnet, fmt, arg...) do {} while(0)
295#endif
296
297#define deverr(usbnet, fmt, arg...) \
298 printk(KERN_ERR "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
299#define devwarn(usbnet, fmt, arg...) \
300 printk(KERN_WARNING "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
301
302#define devinfo(usbnet, fmt, arg...) \
303 printk(KERN_INFO "%s: " fmt "\n" , (usbnet)->net->name , ## arg); \
304
305/*-------------------------------------------------------------------------*/ 187/*-------------------------------------------------------------------------*/
306 188
307static void usbnet_get_drvinfo (struct net_device *, struct ethtool_drvinfo *); 189static void usbnet_get_drvinfo (struct net_device *, struct ethtool_drvinfo *);
@@ -921,6 +803,11 @@ static int ax8817x_bind(struct usbnet *dev, struct usb_interface *intf)
921 ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP); 803 ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
922 mii_nway_restart(&dev->mii); 804 mii_nway_restart(&dev->mii);
923 805
806 if (dev->driver_info->flags & FLAG_FRAMING_AX) {
807 /* REVISIT: adjust hard_header_len too */
808 dev->hard_mtu = 2048;
809 }
810
924 return 0; 811 return 0;
925out2: 812out2:
926 kfree(buf); 813 kfree(buf);
@@ -1432,9 +1319,8 @@ static int generic_cdc_bind (struct usbnet *dev, struct usb_interface *intf)
1432 info->ether->bLength); 1319 info->ether->bLength);
1433 goto bad_desc; 1320 goto bad_desc;
1434 } 1321 }
1435 dev->net->mtu = le16_to_cpup ( 1322 dev->hard_mtu = le16_to_cpu(
1436 &info->ether->wMaxSegmentSize) 1323 info->ether->wMaxSegmentSize);
1437 - ETH_HLEN;
1438 /* because of Zaurus, we may be ignoring the host 1324 /* because of Zaurus, we may be ignoring the host
1439 * side link address we were given. 1325 * side link address we were given.
1440 */ 1326 */
@@ -1988,9 +1874,17 @@ genelink_tx_fixup (struct usbnet *dev, struct sk_buff *skb, unsigned flags)
1988 return skb; 1874 return skb;
1989} 1875}
1990 1876
1877static int genelink_bind (struct usbnet *dev, struct usb_interface *intf)
1878{
1879 dev->hard_mtu = GL_RCV_BUF_SIZE;
1880 dev->net->hard_header_len += 4;
1881 return 0;
1882}
1883
1991static const struct driver_info genelink_info = { 1884static const struct driver_info genelink_info = {
1992 .description = "Genesys GeneLink", 1885 .description = "Genesys GeneLink",
1993 .flags = FLAG_FRAMING_GL | FLAG_NO_SETINT, 1886 .flags = FLAG_FRAMING_GL | FLAG_NO_SETINT,
1887 .bind = genelink_bind,
1994 .rx_fixup = genelink_rx_fixup, 1888 .rx_fixup = genelink_rx_fixup,
1995 .tx_fixup = genelink_tx_fixup, 1889 .tx_fixup = genelink_tx_fixup,
1996 1890
@@ -2015,7 +1909,6 @@ static const struct driver_info genelink_info = {
2015 * 1909 *
2016 *-------------------------------------------------------------------------*/ 1910 *-------------------------------------------------------------------------*/
2017 1911
2018#define dev_packet_id data[0]
2019#define frame_errors data[1] 1912#define frame_errors data[1]
2020 1913
2021/* 1914/*
@@ -2057,6 +1950,9 @@ struct nc_trailer {
2057 1950
2058#define MIN_FRAMED FRAMED_SIZE(0) 1951#define MIN_FRAMED FRAMED_SIZE(0)
2059 1952
1953/* packets _could_ be up to 64KB... */
1954#define NC_MAX_PACKET 32767
1955
2060 1956
2061/* 1957/*
2062 * Zero means no timeout; else, how long a 64 byte bulk packet may be queued 1958 * Zero means no timeout; else, how long a 64 byte bulk packet may be queued
@@ -2398,16 +2294,14 @@ static void nc_ensure_sync (struct usbnet *dev)
2398static int net1080_rx_fixup (struct usbnet *dev, struct sk_buff *skb) 2294static int net1080_rx_fixup (struct usbnet *dev, struct sk_buff *skb)
2399{ 2295{
2400 struct nc_header *header; 2296 struct nc_header *header;
2297 struct net_device *net = dev->net;
2401 struct nc_trailer *trailer; 2298 struct nc_trailer *trailer;
2402 u16 hdr_len, packet_len; 2299 u16 hdr_len, packet_len;
2403 2300
2404 if (!(skb->len & 0x01) 2301 if (!(skb->len & 0x01)) {
2405 || MIN_FRAMED > skb->len
2406 || skb->len > FRAMED_SIZE (dev->net->mtu)) {
2407 dev->stats.rx_frame_errors++; 2302 dev->stats.rx_frame_errors++;
2408 dbg ("rx framesize %d range %d..%d mtu %d", skb->len, 2303 dbg ("rx framesize %d range %d..%d mtu %d", skb->len,
2409 (int)MIN_FRAMED, (int)FRAMED_SIZE (dev->net->mtu), 2304 net->hard_header_len, dev->hard_mtu, net->mtu);
2410 dev->net->mtu);
2411 nc_ensure_sync (dev); 2305 nc_ensure_sync (dev);
2412 return 0; 2306 return 0;
2413 } 2307 }
@@ -2415,7 +2309,7 @@ static int net1080_rx_fixup (struct usbnet *dev, struct sk_buff *skb)
2415 header = (struct nc_header *) skb->data; 2309 header = (struct nc_header *) skb->data;
2416 hdr_len = le16_to_cpup (&header->hdr_len); 2310 hdr_len = le16_to_cpup (&header->hdr_len);
2417 packet_len = le16_to_cpup (&header->packet_len); 2311 packet_len = le16_to_cpup (&header->packet_len);
2418 if (FRAMED_SIZE (packet_len) > MAX_PACKET) { 2312 if (FRAMED_SIZE (packet_len) > NC_MAX_PACKET) {
2419 dev->stats.rx_frame_errors++; 2313 dev->stats.rx_frame_errors++;
2420 dbg ("packet too big, %d", packet_len); 2314 dbg ("packet too big, %d", packet_len);
2421 nc_ensure_sync (dev); 2315 nc_ensure_sync (dev);
@@ -2505,11 +2399,23 @@ net1080_tx_fixup (struct usbnet *dev, struct sk_buff *skb, unsigned flags)
2505 return skb2; 2399 return skb2;
2506} 2400}
2507 2401
2402static int net1080_bind (struct usbnet *dev, struct usb_interface *intf)
2403{
2404 unsigned extra = sizeof (struct nc_header)
2405 + 1
2406 + sizeof (struct nc_trailer);
2407
2408 dev->net->hard_header_len += extra;
2409 dev->hard_mtu = NC_MAX_PACKET;
2410 return 0;
2411}
2412
2508static const struct driver_info net1080_info = { 2413static const struct driver_info net1080_info = {
2509 .description = "NetChip TurboCONNECT", 2414 .description = "NetChip TurboCONNECT",
2510 .flags = FLAG_FRAMING_NC, 2415 .flags = FLAG_FRAMING_NC,
2416 .bind = net1080_bind,
2511 .reset = net1080_reset, 2417 .reset = net1080_reset,
2512 .check_connect =net1080_check_connect, 2418 .check_connect = net1080_check_connect,
2513 .rx_fixup = net1080_rx_fixup, 2419 .rx_fixup = net1080_rx_fixup,
2514 .tx_fixup = net1080_tx_fixup, 2420 .tx_fixup = net1080_tx_fixup,
2515}; 2421};
@@ -2690,11 +2596,20 @@ done:
2690 return skb; 2596 return skb;
2691} 2597}
2692 2598
2599static int zaurus_bind (struct usbnet *dev, struct usb_interface *intf)
2600{
2601 /* Belcarra's funky framing has other options; mostly
2602 * TRAILERS (!) with 4 bytes CRC, and maybe 2 pad bytes.
2603 */
2604 dev->net->hard_header_len += 6;
2605 return generic_cdc_bind(dev, intf);
2606}
2607
2693static const struct driver_info zaurus_sl5x00_info = { 2608static const struct driver_info zaurus_sl5x00_info = {
2694 .description = "Sharp Zaurus SL-5x00", 2609 .description = "Sharp Zaurus SL-5x00",
2695 .flags = FLAG_FRAMING_Z, 2610 .flags = FLAG_FRAMING_Z,
2696 .check_connect = always_connected, 2611 .check_connect = always_connected,
2697 .bind = generic_cdc_bind, 2612 .bind = zaurus_bind,
2698 .unbind = cdc_unbind, 2613 .unbind = cdc_unbind,
2699 .tx_fixup = zaurus_tx_fixup, 2614 .tx_fixup = zaurus_tx_fixup,
2700}; 2615};
@@ -2704,7 +2619,7 @@ static const struct driver_info zaurus_pxa_info = {
2704 .description = "Sharp Zaurus, PXA-2xx based", 2619 .description = "Sharp Zaurus, PXA-2xx based",
2705 .flags = FLAG_FRAMING_Z, 2620 .flags = FLAG_FRAMING_Z,
2706 .check_connect = always_connected, 2621 .check_connect = always_connected,
2707 .bind = generic_cdc_bind, 2622 .bind = zaurus_bind,
2708 .unbind = cdc_unbind, 2623 .unbind = cdc_unbind,
2709 .tx_fixup = zaurus_tx_fixup, 2624 .tx_fixup = zaurus_tx_fixup,
2710}; 2625};
@@ -2714,7 +2629,7 @@ static const struct driver_info olympus_mxl_info = {
2714 .description = "Olympus R1000", 2629 .description = "Olympus R1000",
2715 .flags = FLAG_FRAMING_Z, 2630 .flags = FLAG_FRAMING_Z,
2716 .check_connect = always_connected, 2631 .check_connect = always_connected,
2717 .bind = generic_cdc_bind, 2632 .bind = zaurus_bind,
2718 .unbind = cdc_unbind, 2633 .unbind = cdc_unbind,
2719 .tx_fixup = zaurus_tx_fixup, 2634 .tx_fixup = zaurus_tx_fixup,
2720}; 2635};
@@ -2868,22 +2783,12 @@ static const struct driver_info bogus_mdlm_info = {
2868static int usbnet_change_mtu (struct net_device *net, int new_mtu) 2783static int usbnet_change_mtu (struct net_device *net, int new_mtu)
2869{ 2784{
2870 struct usbnet *dev = netdev_priv(net); 2785 struct usbnet *dev = netdev_priv(net);
2786 int ll_mtu = new_mtu + net->hard_header_len;
2871 2787
2872 if (new_mtu <= MIN_PACKET || new_mtu > MAX_PACKET) 2788 if (new_mtu <= 0 || ll_mtu > dev->hard_mtu)
2873 return -EINVAL;
2874#ifdef CONFIG_USB_NET1080
2875 if (((dev->driver_info->flags) & FLAG_FRAMING_NC)) {
2876 if (FRAMED_SIZE (new_mtu) > MAX_PACKET)
2877 return -EINVAL;
2878 }
2879#endif
2880#ifdef CONFIG_USB_GENESYS
2881 if (((dev->driver_info->flags) & FLAG_FRAMING_GL)
2882 && new_mtu > GL_MAX_PACKET_LEN)
2883 return -EINVAL; 2789 return -EINVAL;
2884#endif
2885 // no second zero-length packet read wanted after mtu-sized packets 2790 // no second zero-length packet read wanted after mtu-sized packets
2886 if (((new_mtu + sizeof (struct ethhdr)) % dev->maxpacket) == 0) 2791 if ((ll_mtu % dev->maxpacket) == 0)
2887 return -EDOM; 2792 return -EDOM;
2888 net->mtu = new_mtu; 2793 net->mtu = new_mtu;
2889 return 0; 2794 return 0;
@@ -2943,33 +2848,8 @@ static void rx_submit (struct usbnet *dev, struct urb *urb, unsigned flags)
2943 unsigned long lockflags; 2848 unsigned long lockflags;
2944 size_t size; 2849 size_t size;
2945 2850
2946#ifdef CONFIG_USB_NET1080 2851 size = max(dev->net->hard_header_len + dev->net->mtu,
2947 if (dev->driver_info->flags & FLAG_FRAMING_NC) 2852 (unsigned)ETH_FRAME_LEN);
2948 size = FRAMED_SIZE (dev->net->mtu);
2949 else
2950#endif
2951#ifdef CONFIG_USB_GENESYS
2952 if (dev->driver_info->flags & FLAG_FRAMING_GL)
2953 size = GL_RCV_BUF_SIZE;
2954 else
2955#endif
2956#ifdef CONFIG_USB_ZAURUS
2957 if (dev->driver_info->flags & FLAG_FRAMING_Z)
2958 size = 6 + (sizeof (struct ethhdr) + dev->net->mtu);
2959 else
2960#endif
2961#ifdef CONFIG_USB_RNDIS
2962 if (dev->driver_info->flags & FLAG_FRAMING_RN)
2963 size = RNDIS_MAX_TRANSFER;
2964 else
2965#endif
2966#ifdef CONFIG_USB_AX8817X
2967 if (dev->driver_info->flags & FLAG_FRAMING_AX)
2968 size = 2048;
2969 else
2970#endif
2971 size = (sizeof (struct ethhdr) + dev->net->mtu);
2972
2973 if ((skb = alloc_skb (size + NET_IP_ALIGN, flags)) == NULL) { 2853 if ((skb = alloc_skb (size + NET_IP_ALIGN, flags)) == NULL) {
2974 if (netif_msg_rx_err (dev)) 2854 if (netif_msg_rx_err (dev))
2975 devdbg (dev, "no rx skb"); 2855 devdbg (dev, "no rx skb");
@@ -3062,7 +2942,7 @@ static void rx_complete (struct urb *urb, struct pt_regs *regs)
3062 switch (urb_status) { 2942 switch (urb_status) {
3063 // success 2943 // success
3064 case 0: 2944 case 0:
3065 if (MIN_PACKET > skb->len || skb->len > MAX_PACKET) { 2945 if (skb->len < dev->net->hard_header_len) {
3066 entry->state = rx_cleanup; 2946 entry->state = rx_cleanup;
3067 dev->stats.rx_errors++; 2947 dev->stats.rx_errors++;
3068 dev->stats.rx_length_errors++; 2948 dev->stats.rx_length_errors++;
@@ -3334,11 +3214,11 @@ static u32 usbnet_get_link (struct net_device *net)
3334{ 3214{
3335 struct usbnet *dev = netdev_priv(net); 3215 struct usbnet *dev = netdev_priv(net);
3336 3216
3337 /* If a check_connect is defined, return it's results */ 3217 /* If a check_connect is defined, return its result */
3338 if (dev->driver_info->check_connect) 3218 if (dev->driver_info->check_connect)
3339 return dev->driver_info->check_connect (dev) == 0; 3219 return dev->driver_info->check_connect (dev) == 0;
3340 3220
3341 /* Otherwise, we're up to avoid breaking scripts */ 3221 /* Otherwise, say we're up (to avoid breaking scripts) */
3342 return 1; 3222 return 1;
3343} 3223}
3344 3224
@@ -3386,19 +3266,24 @@ kevent (void *data)
3386 if (test_bit (EVENT_TX_HALT, &dev->flags)) { 3266 if (test_bit (EVENT_TX_HALT, &dev->flags)) {
3387 unlink_urbs (dev, &dev->txq); 3267 unlink_urbs (dev, &dev->txq);
3388 status = usb_clear_halt (dev->udev, dev->out); 3268 status = usb_clear_halt (dev->udev, dev->out);
3389 if (status < 0 && status != -EPIPE) { 3269 if (status < 0
3270 && status != -EPIPE
3271 && status != -ESHUTDOWN) {
3390 if (netif_msg_tx_err (dev)) 3272 if (netif_msg_tx_err (dev))
3391 deverr (dev, "can't clear tx halt, status %d", 3273 deverr (dev, "can't clear tx halt, status %d",
3392 status); 3274 status);
3393 } else { 3275 } else {
3394 clear_bit (EVENT_TX_HALT, &dev->flags); 3276 clear_bit (EVENT_TX_HALT, &dev->flags);
3395 netif_wake_queue (dev->net); 3277 if (status != -ESHUTDOWN)
3278 netif_wake_queue (dev->net);
3396 } 3279 }
3397 } 3280 }
3398 if (test_bit (EVENT_RX_HALT, &dev->flags)) { 3281 if (test_bit (EVENT_RX_HALT, &dev->flags)) {
3399 unlink_urbs (dev, &dev->rxq); 3282 unlink_urbs (dev, &dev->rxq);
3400 status = usb_clear_halt (dev->udev, dev->in); 3283 status = usb_clear_halt (dev->udev, dev->in);
3401 if (status < 0 && status != -EPIPE) { 3284 if (status < 0
3285 && status != -EPIPE
3286 && status != -ESHUTDOWN) {
3402 if (netif_msg_rx_err (dev)) 3287 if (netif_msg_rx_err (dev))
3403 deverr (dev, "can't clear rx halt, status %d", 3288 deverr (dev, "can't clear rx halt, status %d",
3404 status); 3289 status);
@@ -3574,7 +3459,7 @@ static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net)
3574 3459
3575#ifdef CONFIG_USB_NET1080 3460#ifdef CONFIG_USB_NET1080
3576 if (info->flags & FLAG_FRAMING_NC) { 3461 if (info->flags & FLAG_FRAMING_NC) {
3577 header->packet_id = cpu_to_le16 ((u16)dev->dev_packet_id++); 3462 header->packet_id = cpu_to_le16 ((u16)dev->xid++);
3578 put_unaligned (header->packet_id, &trailer->packet_id); 3463 put_unaligned (header->packet_id, &trailer->packet_id);
3579#if 0 3464#if 0
3580 devdbg (dev, "frame >tx h %d p %d id %d", 3465 devdbg (dev, "frame >tx h %d p %d id %d",
@@ -3776,6 +3661,7 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
3776 dev->net = net; 3661 dev->net = net;
3777 strcpy (net->name, "usb%d"); 3662 strcpy (net->name, "usb%d");
3778 memcpy (net->dev_addr, node_id, sizeof node_id); 3663 memcpy (net->dev_addr, node_id, sizeof node_id);
3664 dev->hard_mtu = net->mtu + net->hard_header_len;
3779 3665
3780#if 0 3666#if 0
3781// dma_supported() is deeply broken on almost all architectures 3667// dma_supported() is deeply broken on almost all architectures
@@ -3804,6 +3690,10 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
3804 if ((dev->driver_info->flags & FLAG_ETHER) != 0 3690 if ((dev->driver_info->flags & FLAG_ETHER) != 0
3805 && (net->dev_addr [0] & 0x02) == 0) 3691 && (net->dev_addr [0] & 0x02) == 0)
3806 strcpy (net->name, "eth%d"); 3692 strcpy (net->name, "eth%d");
3693
3694 /* maybe the remote can't receive an Ethernet MTU */
3695 if (net->mtu > (dev->hard_mtu - net->hard_header_len))
3696 net->mtu = dev->hard_mtu - net->hard_header_len;
3807 } else if (!info->in || info->out) 3697 } else if (!info->in || info->out)
3808 status = get_endpoints (dev, udev); 3698 status = get_endpoints (dev, udev);
3809 else { 3699 else {
@@ -3817,7 +3707,6 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
3817 status = 0; 3707 status = 0;
3818 3708
3819 } 3709 }
3820
3821 if (status == 0 && dev->status) 3710 if (status == 0 && dev->status)
3822 status = init_status (dev, udev); 3711 status = init_status (dev, udev);
3823 if (status < 0) 3712 if (status < 0)
@@ -4212,7 +4101,7 @@ static struct ethtool_ops usbnet_ethtool_ops = {
4212 4101
4213/*-------------------------------------------------------------------------*/ 4102/*-------------------------------------------------------------------------*/
4214 4103
4215static int __init usbnet_init (void) 4104static int __init usbnet_init(void)
4216{ 4105{
4217 // compiler should optimize these out 4106 // compiler should optimize these out
4218 BUG_ON (sizeof (((struct sk_buff *)0)->cb) 4107 BUG_ON (sizeof (((struct sk_buff *)0)->cb)
@@ -4226,14 +4115,14 @@ static int __init usbnet_init (void)
4226 4115
4227 return usb_register(&usbnet_driver); 4116 return usb_register(&usbnet_driver);
4228} 4117}
4229module_init (usbnet_init); 4118module_init(usbnet_init);
4230 4119
4231static void __exit usbnet_exit (void) 4120static void __exit usbnet_exit(void)
4232{ 4121{
4233 usb_deregister (&usbnet_driver); 4122 usb_deregister(&usbnet_driver);
4234} 4123}
4235module_exit (usbnet_exit); 4124module_exit(usbnet_exit);
4236 4125
4237MODULE_AUTHOR ("David Brownell <dbrownell@users.sourceforge.net>"); 4126MODULE_AUTHOR("David Brownell");
4238MODULE_DESCRIPTION ("USB Host-to-Host Link Drivers (numerous vendors)"); 4127MODULE_DESCRIPTION("USB Host-to-Host Link Drivers (numerous vendors)");
4239MODULE_LICENSE ("GPL"); 4128MODULE_LICENSE("GPL");
diff --git a/drivers/usb/net/usbnet.h b/drivers/usb/net/usbnet.h
new file mode 100644
index 000000000000..44026189a8a1
--- /dev/null
+++ b/drivers/usb/net/usbnet.h
@@ -0,0 +1,150 @@
1/*
2 * USB Networking Link Interface
3 *
4 * Copyright (C) 2000-2005 by David Brownell <dbrownell@users.sourceforge.net>
5 * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22
23#ifndef __USBNET_H
24#define __USBNET_H
25
26
27/* interface from usbnet core to each USB networking device we handle */
28struct usbnet {
29 /* housekeeping */
30 struct usb_device *udev;
31 struct driver_info *driver_info;
32 wait_queue_head_t *wait;
33
34 /* i/o info: pipes etc */
35 unsigned in, out;
36 struct usb_host_endpoint *status;
37 unsigned maxpacket;
38 struct timer_list delay;
39
40 /* protocol/interface state */
41 struct net_device *net;
42 struct net_device_stats stats;
43 int msg_enable;
44 unsigned long data [5];
45 u32 xid;
46 u32 hard_mtu; /* count any extra framing */
47 struct mii_if_info mii;
48
49 /* various kinds of pending driver work */
50 struct sk_buff_head rxq;
51 struct sk_buff_head txq;
52 struct sk_buff_head done;
53 struct urb *interrupt;
54 struct tasklet_struct bh;
55
56 struct work_struct kevent;
57 unsigned long flags;
58# define EVENT_TX_HALT 0
59# define EVENT_RX_HALT 1
60# define EVENT_RX_MEMORY 2
61# define EVENT_STS_SPLIT 3
62# define EVENT_LINK_RESET 4
63};
64
65
66/* interface from the device/framing level "minidriver" to core */
67struct driver_info {
68 char *description;
69
70 int flags;
71/* framing is CDC Ethernet, not writing ZLPs (hw issues), or optionally: */
72#define FLAG_FRAMING_NC 0x0001 /* guard against device dropouts */
73#define FLAG_FRAMING_GL 0x0002 /* genelink batches packets */
74#define FLAG_FRAMING_Z 0x0004 /* zaurus adds a trailer */
75#define FLAG_FRAMING_RN 0x0008 /* RNDIS batches, plus huge header */
76
77#define FLAG_NO_SETINT 0x0010 /* device can't set_interface() */
78#define FLAG_ETHER 0x0020 /* maybe use "eth%d" names */
79
80#define FLAG_FRAMING_AX 0x0040 /* AX88772/178 packets */
81
82 /* init device ... can sleep, or cause probe() failure */
83 int (*bind)(struct usbnet *, struct usb_interface *);
84
85 /* cleanup device ... can sleep, but can't fail */
86 void (*unbind)(struct usbnet *, struct usb_interface *);
87
88 /* reset device ... can sleep */
89 int (*reset)(struct usbnet *);
90
91 /* see if peer is connected ... can sleep */
92 int (*check_connect)(struct usbnet *);
93
94 /* for status polling */
95 void (*status)(struct usbnet *, struct urb *);
96
97 /* link reset handling, called from defer_kevent */
98 int (*link_reset)(struct usbnet *);
99
100 /* fixup rx packet (strip framing) */
101 int (*rx_fixup)(struct usbnet *dev, struct sk_buff *skb);
102
103 /* fixup tx packet (add framing) */
104 struct sk_buff *(*tx_fixup)(struct usbnet *dev,
105 struct sk_buff *skb, unsigned flags);
106
107 /* for new devices, use the descriptor-reading code instead */
108 int in; /* rx endpoint */
109 int out; /* tx endpoint */
110
111 unsigned long data; /* Misc driver specific data */
112};
113
114
115/* we record the state for each of our queued skbs */
116enum skb_state {
117 illegal = 0,
118 tx_start, tx_done,
119 rx_start, rx_done, rx_cleanup
120};
121
122struct skb_data { /* skb->cb is one of these */
123 struct urb *urb;
124 struct usbnet *dev;
125 enum skb_state state;
126 size_t length;
127};
128
129
130
131/* messaging support includes the interface name, so it must not be
132 * used before it has one ... notably, in minidriver bind() calls.
133 */
134#ifdef DEBUG
135#define devdbg(usbnet, fmt, arg...) \
136 printk(KERN_DEBUG "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
137#else
138#define devdbg(usbnet, fmt, arg...) do {} while(0)
139#endif
140
141#define deverr(usbnet, fmt, arg...) \
142 printk(KERN_ERR "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
143#define devwarn(usbnet, fmt, arg...) \
144 printk(KERN_WARNING "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
145
146#define devinfo(usbnet, fmt, arg...) \
147 printk(KERN_INFO "%s: " fmt "\n" , (usbnet)->net->name , ## arg); \
148
149
150#endif /* __USBNET_H */