| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
| David Brownell | 090ffa9 | 2005-08-31 09:54:50 -0700 | [diff] [blame] | 2 | * USB Network driver infrastructure | 
| David Brownell | f29fc25 | 2005-08-31 09:52:31 -0700 | [diff] [blame] | 3 | * Copyright (C) 2000-2005 by David Brownell | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | /* | 
|  | 22 | * This is a generic "USB networking" framework that works with several | 
| David Brownell | 090ffa9 | 2005-08-31 09:54:50 -0700 | [diff] [blame] | 23 | * kinds of full and high speed networking devices:  host-to-host cables, | 
|  | 24 | * smart usb peripherals, and actual Ethernet adapters. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | * | 
| David Brownell | 090ffa9 | 2005-08-31 09:54:50 -0700 | [diff] [blame] | 26 | * These devices usually differ in terms of control protocols (if they | 
|  | 27 | * even have one!) and sometimes they define new framing to wrap or batch | 
|  | 28 | * Ethernet packets.  Otherwise, they talk to USB pretty much the same, | 
|  | 29 | * so interface (un)binding, endpoint I/O queues, fault handling, and other | 
|  | 30 | * issues can usefully be addressed by this framework. | 
|  | 31 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 |  | 
|  | 33 | // #define	DEBUG			// error path messages, extra info | 
|  | 34 | // #define	VERBOSE			// more; success messages | 
|  | 35 |  | 
|  | 36 | #include <linux/config.h> | 
|  | 37 | #ifdef	CONFIG_USB_DEBUG | 
|  | 38 | #   define DEBUG | 
|  | 39 | #endif | 
|  | 40 | #include <linux/module.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <linux/sched.h> | 
|  | 42 | #include <linux/init.h> | 
|  | 43 | #include <linux/netdevice.h> | 
|  | 44 | #include <linux/etherdevice.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/ethtool.h> | 
|  | 46 | #include <linux/workqueue.h> | 
|  | 47 | #include <linux/mii.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <linux/usb.h> | 
| David Brownell | f29fc25 | 2005-08-31 09:52:31 -0700 | [diff] [blame] | 49 |  | 
|  | 50 | #include "usbnet.h" | 
|  | 51 |  | 
|  | 52 | #define DRIVER_VERSION		"22-Aug-2005" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 |  | 
|  | 54 |  | 
|  | 55 | /*-------------------------------------------------------------------------*/ | 
|  | 56 |  | 
|  | 57 | /* | 
|  | 58 | * Nineteen USB 1.1 max size bulk transactions per frame (ms), max. | 
|  | 59 | * Several dozen bytes of IPv4 data can fit in two such transactions. | 
|  | 60 | * One maximum size Ethernet packet takes twenty four of them. | 
|  | 61 | * For high speed, each frame comfortably fits almost 36 max size | 
|  | 62 | * Ethernet packets (so queues should be bigger). | 
| David Brownell | f29fc25 | 2005-08-31 09:52:31 -0700 | [diff] [blame] | 63 | * | 
|  | 64 | * REVISIT qlens should be members of 'struct usbnet'; the goal is to | 
|  | 65 | * let the USB host controller be busy for 5msec or more before an irq | 
|  | 66 | * is required, under load.  Jumbograms change the equation. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | */ | 
|  | 68 | #define	RX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4) | 
|  | 69 | #define	TX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4) | 
|  | 70 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | // reawaken network queue this soon after stopping; else watchdog barks | 
|  | 72 | #define TX_TIMEOUT_JIFFIES	(5*HZ) | 
|  | 73 |  | 
|  | 74 | // throttle rx/tx briefly after some faults, so khubd might disconnect() | 
|  | 75 | // us (it polls at HZ/4 usually) before we report too many false errors. | 
|  | 76 | #define THROTTLE_JIFFIES	(HZ/8) | 
|  | 77 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | // between wakeups | 
|  | 79 | #define UNLINK_TIMEOUT_MS	3 | 
|  | 80 |  | 
|  | 81 | /*-------------------------------------------------------------------------*/ | 
|  | 82 |  | 
|  | 83 | // randomly generated ethernet address | 
|  | 84 | static u8	node_id [ETH_ALEN]; | 
|  | 85 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | static const char driver_name [] = "usbnet"; | 
|  | 87 |  | 
|  | 88 | /* use ethtool to change the level for any given device */ | 
|  | 89 | static int msg_level = -1; | 
|  | 90 | module_param (msg_level, int, 0); | 
|  | 91 | MODULE_PARM_DESC (msg_level, "Override default message level"); | 
|  | 92 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | /*-------------------------------------------------------------------------*/ | 
|  | 94 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | /* handles CDC Ethernet and many other network "bulk data" interfaces */ | 
| David Brownell | 2e55cc7 | 2005-08-31 09:53:10 -0700 | [diff] [blame] | 96 | int usbnet_get_endpoints(struct usbnet *dev, struct usb_interface *intf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | { | 
|  | 98 | int				tmp; | 
|  | 99 | struct usb_host_interface	*alt = NULL; | 
|  | 100 | struct usb_host_endpoint	*in = NULL, *out = NULL; | 
|  | 101 | struct usb_host_endpoint	*status = NULL; | 
|  | 102 |  | 
|  | 103 | for (tmp = 0; tmp < intf->num_altsetting; tmp++) { | 
|  | 104 | unsigned	ep; | 
|  | 105 |  | 
|  | 106 | in = out = status = NULL; | 
|  | 107 | alt = intf->altsetting + tmp; | 
|  | 108 |  | 
|  | 109 | /* take the first altsetting with in-bulk + out-bulk; | 
|  | 110 | * remember any status endpoint, just in case; | 
|  | 111 | * ignore other endpoints and altsetttings. | 
|  | 112 | */ | 
|  | 113 | for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) { | 
|  | 114 | struct usb_host_endpoint	*e; | 
|  | 115 | int				intr = 0; | 
|  | 116 |  | 
|  | 117 | e = alt->endpoint + ep; | 
|  | 118 | switch (e->desc.bmAttributes) { | 
|  | 119 | case USB_ENDPOINT_XFER_INT: | 
|  | 120 | if (!(e->desc.bEndpointAddress & USB_DIR_IN)) | 
|  | 121 | continue; | 
|  | 122 | intr = 1; | 
|  | 123 | /* FALLTHROUGH */ | 
|  | 124 | case USB_ENDPOINT_XFER_BULK: | 
|  | 125 | break; | 
|  | 126 | default: | 
|  | 127 | continue; | 
|  | 128 | } | 
|  | 129 | if (e->desc.bEndpointAddress & USB_DIR_IN) { | 
|  | 130 | if (!intr && !in) | 
|  | 131 | in = e; | 
|  | 132 | else if (intr && !status) | 
|  | 133 | status = e; | 
|  | 134 | } else { | 
|  | 135 | if (!out) | 
|  | 136 | out = e; | 
|  | 137 | } | 
|  | 138 | } | 
|  | 139 | if (in && out) | 
|  | 140 | break; | 
|  | 141 | } | 
|  | 142 | if (!alt || !in || !out) | 
|  | 143 | return -EINVAL; | 
|  | 144 |  | 
|  | 145 | if (alt->desc.bAlternateSetting != 0 | 
|  | 146 | || !(dev->driver_info->flags & FLAG_NO_SETINT)) { | 
|  | 147 | tmp = usb_set_interface (dev->udev, alt->desc.bInterfaceNumber, | 
|  | 148 | alt->desc.bAlternateSetting); | 
|  | 149 | if (tmp < 0) | 
|  | 150 | return tmp; | 
|  | 151 | } | 
|  | 152 |  | 
|  | 153 | dev->in = usb_rcvbulkpipe (dev->udev, | 
|  | 154 | in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); | 
|  | 155 | dev->out = usb_sndbulkpipe (dev->udev, | 
|  | 156 | out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); | 
|  | 157 | dev->status = status; | 
|  | 158 | return 0; | 
|  | 159 | } | 
| David Brownell | 2e55cc7 | 2005-08-31 09:53:10 -0700 | [diff] [blame] | 160 | EXPORT_SYMBOL_GPL(usbnet_get_endpoints); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 |  | 
|  | 162 | static void intr_complete (struct urb *urb, struct pt_regs *regs); | 
|  | 163 |  | 
|  | 164 | static int init_status (struct usbnet *dev, struct usb_interface *intf) | 
|  | 165 | { | 
|  | 166 | char		*buf = NULL; | 
|  | 167 | unsigned	pipe = 0; | 
|  | 168 | unsigned	maxp; | 
|  | 169 | unsigned	period; | 
|  | 170 |  | 
|  | 171 | if (!dev->driver_info->status) | 
|  | 172 | return 0; | 
|  | 173 |  | 
|  | 174 | pipe = usb_rcvintpipe (dev->udev, | 
|  | 175 | dev->status->desc.bEndpointAddress | 
|  | 176 | & USB_ENDPOINT_NUMBER_MASK); | 
|  | 177 | maxp = usb_maxpacket (dev->udev, pipe, 0); | 
|  | 178 |  | 
|  | 179 | /* avoid 1 msec chatter:  min 8 msec poll rate */ | 
|  | 180 | period = max ((int) dev->status->desc.bInterval, | 
|  | 181 | (dev->udev->speed == USB_SPEED_HIGH) ? 7 : 3); | 
|  | 182 |  | 
|  | 183 | buf = kmalloc (maxp, SLAB_KERNEL); | 
|  | 184 | if (buf) { | 
|  | 185 | dev->interrupt = usb_alloc_urb (0, SLAB_KERNEL); | 
|  | 186 | if (!dev->interrupt) { | 
|  | 187 | kfree (buf); | 
|  | 188 | return -ENOMEM; | 
|  | 189 | } else { | 
|  | 190 | usb_fill_int_urb(dev->interrupt, dev->udev, pipe, | 
|  | 191 | buf, maxp, intr_complete, dev, period); | 
|  | 192 | dev_dbg(&intf->dev, | 
|  | 193 | "status ep%din, %d bytes period %d\n", | 
|  | 194 | usb_pipeendpoint(pipe), maxp, period); | 
|  | 195 | } | 
|  | 196 | } | 
|  | 197 | return  0; | 
|  | 198 | } | 
|  | 199 |  | 
| David Brownell | 2e55cc7 | 2005-08-31 09:53:10 -0700 | [diff] [blame] | 200 | /* Passes this packet up the stack, updating its accounting. | 
|  | 201 | * Some link protocols batch packets, so their rx_fixup paths | 
|  | 202 | * can return clones as well as just modify the original skb. | 
|  | 203 | */ | 
|  | 204 | void usbnet_skb_return (struct usbnet *dev, struct sk_buff *skb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | { | 
|  | 206 | int	status; | 
|  | 207 |  | 
|  | 208 | skb->dev = dev->net; | 
|  | 209 | skb->protocol = eth_type_trans (skb, dev->net); | 
|  | 210 | dev->stats.rx_packets++; | 
|  | 211 | dev->stats.rx_bytes += skb->len; | 
|  | 212 |  | 
|  | 213 | if (netif_msg_rx_status (dev)) | 
| Al Viro | 5330e92 | 2005-04-26 11:26:53 -0700 | [diff] [blame] | 214 | devdbg (dev, "< rx, len %zu, type 0x%x", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | skb->len + sizeof (struct ethhdr), skb->protocol); | 
|  | 216 | memset (skb->cb, 0, sizeof (struct skb_data)); | 
|  | 217 | status = netif_rx (skb); | 
|  | 218 | if (status != NET_RX_SUCCESS && netif_msg_rx_err (dev)) | 
|  | 219 | devdbg (dev, "netif_rx status %d", status); | 
|  | 220 | } | 
| David Brownell | 2e55cc7 | 2005-08-31 09:53:10 -0700 | [diff] [blame] | 221 | EXPORT_SYMBOL_GPL(usbnet_skb_return); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 |  | 
|  | 223 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | /*------------------------------------------------------------------------- | 
|  | 225 | * | 
|  | 226 | * Network Device Driver (peer link to "Host Device", from USB host) | 
|  | 227 | * | 
|  | 228 | *-------------------------------------------------------------------------*/ | 
|  | 229 |  | 
|  | 230 | static int usbnet_change_mtu (struct net_device *net, int new_mtu) | 
|  | 231 | { | 
|  | 232 | struct usbnet	*dev = netdev_priv(net); | 
| David Brownell | f29fc25 | 2005-08-31 09:52:31 -0700 | [diff] [blame] | 233 | int		ll_mtu = new_mtu + net->hard_header_len; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 |  | 
| David Brownell | f29fc25 | 2005-08-31 09:52:31 -0700 | [diff] [blame] | 235 | if (new_mtu <= 0 || ll_mtu > dev->hard_mtu) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | // no second zero-length packet read wanted after mtu-sized packets | 
| David Brownell | f29fc25 | 2005-08-31 09:52:31 -0700 | [diff] [blame] | 238 | if ((ll_mtu % dev->maxpacket) == 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | return -EDOM; | 
|  | 240 | net->mtu = new_mtu; | 
|  | 241 | return 0; | 
|  | 242 | } | 
|  | 243 |  | 
|  | 244 | /*-------------------------------------------------------------------------*/ | 
|  | 245 |  | 
|  | 246 | static struct net_device_stats *usbnet_get_stats (struct net_device *net) | 
|  | 247 | { | 
|  | 248 | struct usbnet	*dev = netdev_priv(net); | 
|  | 249 | return &dev->stats; | 
|  | 250 | } | 
|  | 251 |  | 
|  | 252 | /*-------------------------------------------------------------------------*/ | 
|  | 253 |  | 
|  | 254 | /* some LK 2.4 HCDs oopsed if we freed or resubmitted urbs from | 
|  | 255 | * completion callbacks.  2.5 should have fixed those bugs... | 
|  | 256 | */ | 
|  | 257 |  | 
| David S. Miller | 8728b83 | 2005-08-09 19:25:21 -0700 | [diff] [blame] | 258 | static void defer_bh(struct usbnet *dev, struct sk_buff *skb, struct sk_buff_head *list) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | unsigned long		flags; | 
|  | 261 |  | 
| David S. Miller | 8728b83 | 2005-08-09 19:25:21 -0700 | [diff] [blame] | 262 | spin_lock_irqsave(&list->lock, flags); | 
|  | 263 | __skb_unlink(skb, list); | 
|  | 264 | spin_unlock(&list->lock); | 
|  | 265 | spin_lock(&dev->done.lock); | 
|  | 266 | __skb_queue_tail(&dev->done, skb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | if (dev->done.qlen == 1) | 
| David S. Miller | 8728b83 | 2005-08-09 19:25:21 -0700 | [diff] [blame] | 268 | tasklet_schedule(&dev->bh); | 
|  | 269 | spin_unlock_irqrestore(&dev->done.lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | } | 
|  | 271 |  | 
|  | 272 | /* some work can't be done in tasklets, so we use keventd | 
|  | 273 | * | 
|  | 274 | * NOTE:  annoying asymmetry:  if it's active, schedule_work() fails, | 
|  | 275 | * but tasklet_schedule() doesn't.  hope the failure is rare. | 
|  | 276 | */ | 
| David Brownell | 2e55cc7 | 2005-08-31 09:53:10 -0700 | [diff] [blame] | 277 | void usbnet_defer_kevent (struct usbnet *dev, int work) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | { | 
|  | 279 | set_bit (work, &dev->flags); | 
|  | 280 | if (!schedule_work (&dev->kevent)) | 
|  | 281 | deverr (dev, "kevent %d may have been dropped", work); | 
|  | 282 | else | 
|  | 283 | devdbg (dev, "kevent %d scheduled", work); | 
|  | 284 | } | 
| David Brownell | 2e55cc7 | 2005-08-31 09:53:10 -0700 | [diff] [blame] | 285 | EXPORT_SYMBOL_GPL(usbnet_defer_kevent); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 |  | 
|  | 287 | /*-------------------------------------------------------------------------*/ | 
|  | 288 |  | 
|  | 289 | static void rx_complete (struct urb *urb, struct pt_regs *regs); | 
|  | 290 |  | 
| Al Viro | 55016f1 | 2005-10-21 03:21:58 -0400 | [diff] [blame] | 291 | static void rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | { | 
|  | 293 | struct sk_buff		*skb; | 
|  | 294 | struct skb_data		*entry; | 
|  | 295 | int			retval = 0; | 
|  | 296 | unsigned long		lockflags; | 
| David Brownell | 2e55cc7 | 2005-08-31 09:53:10 -0700 | [diff] [blame] | 297 | size_t			size = dev->rx_urb_size; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | if ((skb = alloc_skb (size + NET_IP_ALIGN, flags)) == NULL) { | 
|  | 300 | if (netif_msg_rx_err (dev)) | 
|  | 301 | devdbg (dev, "no rx skb"); | 
| David Brownell | 2e55cc7 | 2005-08-31 09:53:10 -0700 | [diff] [blame] | 302 | usbnet_defer_kevent (dev, EVENT_RX_MEMORY); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | usb_free_urb (urb); | 
|  | 304 | return; | 
|  | 305 | } | 
|  | 306 | skb_reserve (skb, NET_IP_ALIGN); | 
|  | 307 |  | 
|  | 308 | entry = (struct skb_data *) skb->cb; | 
|  | 309 | entry->urb = urb; | 
|  | 310 | entry->dev = dev; | 
|  | 311 | entry->state = rx_start; | 
|  | 312 | entry->length = 0; | 
|  | 313 |  | 
|  | 314 | usb_fill_bulk_urb (urb, dev->udev, dev->in, | 
|  | 315 | skb->data, size, rx_complete, skb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 |  | 
|  | 317 | spin_lock_irqsave (&dev->rxq.lock, lockflags); | 
|  | 318 |  | 
|  | 319 | if (netif_running (dev->net) | 
|  | 320 | && netif_device_present (dev->net) | 
|  | 321 | && !test_bit (EVENT_RX_HALT, &dev->flags)) { | 
|  | 322 | switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){ | 
|  | 323 | case -EPIPE: | 
| David Brownell | 2e55cc7 | 2005-08-31 09:53:10 -0700 | [diff] [blame] | 324 | usbnet_defer_kevent (dev, EVENT_RX_HALT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | break; | 
|  | 326 | case -ENOMEM: | 
| David Brownell | 2e55cc7 | 2005-08-31 09:53:10 -0700 | [diff] [blame] | 327 | usbnet_defer_kevent (dev, EVENT_RX_MEMORY); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | break; | 
|  | 329 | case -ENODEV: | 
|  | 330 | if (netif_msg_ifdown (dev)) | 
|  | 331 | devdbg (dev, "device gone"); | 
|  | 332 | netif_device_detach (dev->net); | 
|  | 333 | break; | 
|  | 334 | default: | 
|  | 335 | if (netif_msg_rx_err (dev)) | 
|  | 336 | devdbg (dev, "rx submit, %d", retval); | 
|  | 337 | tasklet_schedule (&dev->bh); | 
|  | 338 | break; | 
|  | 339 | case 0: | 
|  | 340 | __skb_queue_tail (&dev->rxq, skb); | 
|  | 341 | } | 
|  | 342 | } else { | 
|  | 343 | if (netif_msg_ifdown (dev)) | 
|  | 344 | devdbg (dev, "rx: stopped"); | 
|  | 345 | retval = -ENOLINK; | 
|  | 346 | } | 
|  | 347 | spin_unlock_irqrestore (&dev->rxq.lock, lockflags); | 
|  | 348 | if (retval) { | 
|  | 349 | dev_kfree_skb_any (skb); | 
|  | 350 | usb_free_urb (urb); | 
|  | 351 | } | 
|  | 352 | } | 
|  | 353 |  | 
|  | 354 |  | 
|  | 355 | /*-------------------------------------------------------------------------*/ | 
|  | 356 |  | 
|  | 357 | static inline void rx_process (struct usbnet *dev, struct sk_buff *skb) | 
|  | 358 | { | 
|  | 359 | if (dev->driver_info->rx_fixup | 
|  | 360 | && !dev->driver_info->rx_fixup (dev, skb)) | 
|  | 361 | goto error; | 
|  | 362 | // else network stack removes extra byte if we forced a short packet | 
|  | 363 |  | 
|  | 364 | if (skb->len) | 
| David Brownell | 2e55cc7 | 2005-08-31 09:53:10 -0700 | [diff] [blame] | 365 | usbnet_skb_return (dev, skb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | else { | 
|  | 367 | if (netif_msg_rx_err (dev)) | 
|  | 368 | devdbg (dev, "drop"); | 
|  | 369 | error: | 
|  | 370 | dev->stats.rx_errors++; | 
|  | 371 | skb_queue_tail (&dev->done, skb); | 
|  | 372 | } | 
|  | 373 | } | 
|  | 374 |  | 
|  | 375 | /*-------------------------------------------------------------------------*/ | 
|  | 376 |  | 
|  | 377 | static void rx_complete (struct urb *urb, struct pt_regs *regs) | 
|  | 378 | { | 
|  | 379 | struct sk_buff		*skb = (struct sk_buff *) urb->context; | 
|  | 380 | struct skb_data		*entry = (struct skb_data *) skb->cb; | 
|  | 381 | struct usbnet		*dev = entry->dev; | 
|  | 382 | int			urb_status = urb->status; | 
|  | 383 |  | 
|  | 384 | skb_put (skb, urb->actual_length); | 
|  | 385 | entry->state = rx_done; | 
|  | 386 | entry->urb = NULL; | 
|  | 387 |  | 
|  | 388 | switch (urb_status) { | 
|  | 389 | // success | 
|  | 390 | case 0: | 
| David Brownell | f29fc25 | 2005-08-31 09:52:31 -0700 | [diff] [blame] | 391 | if (skb->len < dev->net->hard_header_len) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | entry->state = rx_cleanup; | 
|  | 393 | dev->stats.rx_errors++; | 
|  | 394 | dev->stats.rx_length_errors++; | 
|  | 395 | if (netif_msg_rx_err (dev)) | 
|  | 396 | devdbg (dev, "rx length %d", skb->len); | 
|  | 397 | } | 
|  | 398 | break; | 
|  | 399 |  | 
|  | 400 | // stalls need manual reset. this is rare ... except that | 
|  | 401 | // when going through USB 2.0 TTs, unplug appears this way. | 
|  | 402 | // we avoid the highspeed version of the ETIMEOUT/EILSEQ | 
|  | 403 | // storm, recovering as needed. | 
|  | 404 | case -EPIPE: | 
|  | 405 | dev->stats.rx_errors++; | 
| David Brownell | 2e55cc7 | 2005-08-31 09:53:10 -0700 | [diff] [blame] | 406 | usbnet_defer_kevent (dev, EVENT_RX_HALT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | // FALLTHROUGH | 
|  | 408 |  | 
|  | 409 | // software-driven interface shutdown | 
|  | 410 | case -ECONNRESET:		// async unlink | 
|  | 411 | case -ESHUTDOWN:		// hardware gone | 
|  | 412 | if (netif_msg_ifdown (dev)) | 
|  | 413 | devdbg (dev, "rx shutdown, code %d", urb_status); | 
|  | 414 | goto block; | 
|  | 415 |  | 
|  | 416 | // we get controller i/o faults during khubd disconnect() delays. | 
|  | 417 | // throttle down resubmits, to avoid log floods; just temporarily, | 
|  | 418 | // so we still recover when the fault isn't a khubd delay. | 
|  | 419 | case -EPROTO:		// ehci | 
|  | 420 | case -ETIMEDOUT:		// ohci | 
|  | 421 | case -EILSEQ:		// uhci | 
|  | 422 | dev->stats.rx_errors++; | 
|  | 423 | if (!timer_pending (&dev->delay)) { | 
|  | 424 | mod_timer (&dev->delay, jiffies + THROTTLE_JIFFIES); | 
|  | 425 | if (netif_msg_link (dev)) | 
|  | 426 | devdbg (dev, "rx throttle %d", urb_status); | 
|  | 427 | } | 
|  | 428 | block: | 
|  | 429 | entry->state = rx_cleanup; | 
|  | 430 | entry->urb = urb; | 
|  | 431 | urb = NULL; | 
|  | 432 | break; | 
|  | 433 |  | 
|  | 434 | // data overrun ... flush fifo? | 
|  | 435 | case -EOVERFLOW: | 
|  | 436 | dev->stats.rx_over_errors++; | 
|  | 437 | // FALLTHROUGH | 
|  | 438 |  | 
|  | 439 | default: | 
|  | 440 | entry->state = rx_cleanup; | 
|  | 441 | dev->stats.rx_errors++; | 
|  | 442 | if (netif_msg_rx_err (dev)) | 
|  | 443 | devdbg (dev, "rx status %d", urb_status); | 
|  | 444 | break; | 
|  | 445 | } | 
|  | 446 |  | 
| David S. Miller | 8728b83 | 2005-08-09 19:25:21 -0700 | [diff] [blame] | 447 | defer_bh(dev, skb, &dev->rxq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 |  | 
|  | 449 | if (urb) { | 
|  | 450 | if (netif_running (dev->net) | 
|  | 451 | && !test_bit (EVENT_RX_HALT, &dev->flags)) { | 
|  | 452 | rx_submit (dev, urb, GFP_ATOMIC); | 
|  | 453 | return; | 
|  | 454 | } | 
|  | 455 | usb_free_urb (urb); | 
|  | 456 | } | 
|  | 457 | if (netif_msg_rx_err (dev)) | 
|  | 458 | devdbg (dev, "no read resubmitted"); | 
|  | 459 | } | 
|  | 460 |  | 
|  | 461 | static void intr_complete (struct urb *urb, struct pt_regs *regs) | 
|  | 462 | { | 
|  | 463 | struct usbnet	*dev = urb->context; | 
|  | 464 | int		status = urb->status; | 
|  | 465 |  | 
|  | 466 | switch (status) { | 
|  | 467 | /* success */ | 
|  | 468 | case 0: | 
|  | 469 | dev->driver_info->status(dev, urb); | 
|  | 470 | break; | 
|  | 471 |  | 
|  | 472 | /* software-driven interface shutdown */ | 
|  | 473 | case -ENOENT:		// urb killed | 
|  | 474 | case -ESHUTDOWN:		// hardware gone | 
|  | 475 | if (netif_msg_ifdown (dev)) | 
|  | 476 | devdbg (dev, "intr shutdown, code %d", status); | 
|  | 477 | return; | 
|  | 478 |  | 
|  | 479 | /* NOTE:  not throttling like RX/TX, since this endpoint | 
|  | 480 | * already polls infrequently | 
|  | 481 | */ | 
|  | 482 | default: | 
|  | 483 | devdbg (dev, "intr status %d", status); | 
|  | 484 | break; | 
|  | 485 | } | 
|  | 486 |  | 
|  | 487 | if (!netif_running (dev->net)) | 
|  | 488 | return; | 
|  | 489 |  | 
|  | 490 | memset(urb->transfer_buffer, 0, urb->transfer_buffer_length); | 
|  | 491 | status = usb_submit_urb (urb, GFP_ATOMIC); | 
|  | 492 | if (status != 0 && netif_msg_timer (dev)) | 
|  | 493 | deverr(dev, "intr resubmit --> %d", status); | 
|  | 494 | } | 
|  | 495 |  | 
|  | 496 | /*-------------------------------------------------------------------------*/ | 
|  | 497 |  | 
|  | 498 | // unlink pending rx/tx; completion handlers do all other cleanup | 
|  | 499 |  | 
|  | 500 | static int unlink_urbs (struct usbnet *dev, struct sk_buff_head *q) | 
|  | 501 | { | 
|  | 502 | unsigned long		flags; | 
|  | 503 | struct sk_buff		*skb, *skbnext; | 
|  | 504 | int			count = 0; | 
|  | 505 |  | 
|  | 506 | spin_lock_irqsave (&q->lock, flags); | 
|  | 507 | for (skb = q->next; skb != (struct sk_buff *) q; skb = skbnext) { | 
|  | 508 | struct skb_data		*entry; | 
|  | 509 | struct urb		*urb; | 
|  | 510 | int			retval; | 
|  | 511 |  | 
|  | 512 | entry = (struct skb_data *) skb->cb; | 
|  | 513 | urb = entry->urb; | 
|  | 514 | skbnext = skb->next; | 
|  | 515 |  | 
|  | 516 | // during some PM-driven resume scenarios, | 
|  | 517 | // these (async) unlinks complete immediately | 
|  | 518 | retval = usb_unlink_urb (urb); | 
|  | 519 | if (retval != -EINPROGRESS && retval != 0) | 
|  | 520 | devdbg (dev, "unlink urb err, %d", retval); | 
|  | 521 | else | 
|  | 522 | count++; | 
|  | 523 | } | 
|  | 524 | spin_unlock_irqrestore (&q->lock, flags); | 
|  | 525 | return count; | 
|  | 526 | } | 
|  | 527 |  | 
|  | 528 |  | 
|  | 529 | /*-------------------------------------------------------------------------*/ | 
|  | 530 |  | 
|  | 531 | // precondition: never called in_interrupt | 
|  | 532 |  | 
|  | 533 | static int usbnet_stop (struct net_device *net) | 
|  | 534 | { | 
|  | 535 | struct usbnet		*dev = netdev_priv(net); | 
|  | 536 | int			temp; | 
|  | 537 | DECLARE_WAIT_QUEUE_HEAD (unlink_wakeup); | 
|  | 538 | DECLARE_WAITQUEUE (wait, current); | 
|  | 539 |  | 
|  | 540 | netif_stop_queue (net); | 
|  | 541 |  | 
|  | 542 | if (netif_msg_ifdown (dev)) | 
|  | 543 | devinfo (dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld", | 
|  | 544 | dev->stats.rx_packets, dev->stats.tx_packets, | 
|  | 545 | dev->stats.rx_errors, dev->stats.tx_errors | 
|  | 546 | ); | 
|  | 547 |  | 
|  | 548 | // ensure there are no more active urbs | 
|  | 549 | add_wait_queue (&unlink_wakeup, &wait); | 
|  | 550 | dev->wait = &unlink_wakeup; | 
|  | 551 | temp = unlink_urbs (dev, &dev->txq) + unlink_urbs (dev, &dev->rxq); | 
|  | 552 |  | 
|  | 553 | // maybe wait for deletions to finish. | 
| David S. Miller | b03efcf | 2005-07-08 14:57:23 -0700 | [diff] [blame] | 554 | while (!skb_queue_empty(&dev->rxq) && | 
|  | 555 | !skb_queue_empty(&dev->txq) && | 
|  | 556 | !skb_queue_empty(&dev->done)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | msleep(UNLINK_TIMEOUT_MS); | 
|  | 558 | if (netif_msg_ifdown (dev)) | 
|  | 559 | devdbg (dev, "waited for %d urb completions", temp); | 
|  | 560 | } | 
|  | 561 | dev->wait = NULL; | 
|  | 562 | remove_wait_queue (&unlink_wakeup, &wait); | 
|  | 563 |  | 
|  | 564 | usb_kill_urb(dev->interrupt); | 
|  | 565 |  | 
|  | 566 | /* deferred work (task, timer, softirq) must also stop. | 
|  | 567 | * can't flush_scheduled_work() until we drop rtnl (later), | 
|  | 568 | * else workers could deadlock; so make workers a NOP. | 
|  | 569 | */ | 
|  | 570 | dev->flags = 0; | 
|  | 571 | del_timer_sync (&dev->delay); | 
|  | 572 | tasklet_kill (&dev->bh); | 
|  | 573 |  | 
|  | 574 | return 0; | 
|  | 575 | } | 
|  | 576 |  | 
|  | 577 | /*-------------------------------------------------------------------------*/ | 
|  | 578 |  | 
|  | 579 | // posts reads, and enables write queuing | 
|  | 580 |  | 
|  | 581 | // precondition: never called in_interrupt | 
|  | 582 |  | 
|  | 583 | static int usbnet_open (struct net_device *net) | 
|  | 584 | { | 
|  | 585 | struct usbnet		*dev = netdev_priv(net); | 
|  | 586 | int			retval = 0; | 
|  | 587 | struct driver_info	*info = dev->driver_info; | 
|  | 588 |  | 
|  | 589 | // put into "known safe" state | 
|  | 590 | if (info->reset && (retval = info->reset (dev)) < 0) { | 
|  | 591 | if (netif_msg_ifup (dev)) | 
|  | 592 | devinfo (dev, | 
|  | 593 | "open reset fail (%d) usbnet usb-%s-%s, %s", | 
|  | 594 | retval, | 
|  | 595 | dev->udev->bus->bus_name, dev->udev->devpath, | 
|  | 596 | info->description); | 
|  | 597 | goto done; | 
|  | 598 | } | 
|  | 599 |  | 
|  | 600 | // insist peer be connected | 
|  | 601 | if (info->check_connect && (retval = info->check_connect (dev)) < 0) { | 
|  | 602 | if (netif_msg_ifup (dev)) | 
|  | 603 | devdbg (dev, "can't open; %d", retval); | 
|  | 604 | goto done; | 
|  | 605 | } | 
|  | 606 |  | 
|  | 607 | /* start any status interrupt transfer */ | 
|  | 608 | if (dev->interrupt) { | 
|  | 609 | retval = usb_submit_urb (dev->interrupt, GFP_KERNEL); | 
|  | 610 | if (retval < 0) { | 
|  | 611 | if (netif_msg_ifup (dev)) | 
|  | 612 | deverr (dev, "intr submit %d", retval); | 
|  | 613 | goto done; | 
|  | 614 | } | 
|  | 615 | } | 
|  | 616 |  | 
|  | 617 | netif_start_queue (net); | 
|  | 618 | if (netif_msg_ifup (dev)) { | 
|  | 619 | char	*framing; | 
|  | 620 |  | 
|  | 621 | if (dev->driver_info->flags & FLAG_FRAMING_NC) | 
|  | 622 | framing = "NetChip"; | 
|  | 623 | else if (dev->driver_info->flags & FLAG_FRAMING_GL) | 
|  | 624 | framing = "GeneSys"; | 
|  | 625 | else if (dev->driver_info->flags & FLAG_FRAMING_Z) | 
|  | 626 | framing = "Zaurus"; | 
|  | 627 | else if (dev->driver_info->flags & FLAG_FRAMING_RN) | 
|  | 628 | framing = "RNDIS"; | 
|  | 629 | else if (dev->driver_info->flags & FLAG_FRAMING_AX) | 
|  | 630 | framing = "ASIX"; | 
|  | 631 | else | 
|  | 632 | framing = "simple"; | 
|  | 633 |  | 
|  | 634 | devinfo (dev, "open: enable queueing " | 
|  | 635 | "(rx %d, tx %d) mtu %d %s framing", | 
|  | 636 | RX_QLEN (dev), TX_QLEN (dev), dev->net->mtu, | 
|  | 637 | framing); | 
|  | 638 | } | 
|  | 639 |  | 
|  | 640 | // delay posting reads until we're fully open | 
|  | 641 | tasklet_schedule (&dev->bh); | 
|  | 642 | done: | 
|  | 643 | return retval; | 
|  | 644 | } | 
|  | 645 |  | 
|  | 646 | /*-------------------------------------------------------------------------*/ | 
|  | 647 |  | 
| David Brownell | 2e55cc7 | 2005-08-31 09:53:10 -0700 | [diff] [blame] | 648 | /* ethtool methods; minidrivers may need to add some more, but | 
|  | 649 | * they'll probably want to use this base set. | 
|  | 650 | */ | 
|  | 651 |  | 
|  | 652 | void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | { | 
|  | 654 | struct usbnet *dev = netdev_priv(net); | 
|  | 655 |  | 
| David Brownell | 2e55cc7 | 2005-08-31 09:53:10 -0700 | [diff] [blame] | 656 | /* REVISIT don't always return "usbnet" */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | strncpy (info->driver, driver_name, sizeof info->driver); | 
|  | 658 | strncpy (info->version, DRIVER_VERSION, sizeof info->version); | 
|  | 659 | strncpy (info->fw_version, dev->driver_info->description, | 
|  | 660 | sizeof info->fw_version); | 
|  | 661 | usb_make_path (dev->udev, info->bus_info, sizeof info->bus_info); | 
|  | 662 | } | 
| David Brownell | 2e55cc7 | 2005-08-31 09:53:10 -0700 | [diff] [blame] | 663 | EXPORT_SYMBOL_GPL(usbnet_get_drvinfo); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 |  | 
|  | 665 | static u32 usbnet_get_link (struct net_device *net) | 
|  | 666 | { | 
|  | 667 | struct usbnet *dev = netdev_priv(net); | 
|  | 668 |  | 
| David Brownell | f29fc25 | 2005-08-31 09:52:31 -0700 | [diff] [blame] | 669 | /* If a check_connect is defined, return its result */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | if (dev->driver_info->check_connect) | 
|  | 671 | return dev->driver_info->check_connect (dev) == 0; | 
|  | 672 |  | 
| David Brownell | f29fc25 | 2005-08-31 09:52:31 -0700 | [diff] [blame] | 673 | /* Otherwise, say we're up (to avoid breaking scripts) */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | return 1; | 
|  | 675 | } | 
|  | 676 |  | 
| David Brownell | 2e55cc7 | 2005-08-31 09:53:10 -0700 | [diff] [blame] | 677 | u32 usbnet_get_msglevel (struct net_device *net) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | { | 
|  | 679 | struct usbnet *dev = netdev_priv(net); | 
|  | 680 |  | 
|  | 681 | return dev->msg_enable; | 
|  | 682 | } | 
| David Brownell | 2e55cc7 | 2005-08-31 09:53:10 -0700 | [diff] [blame] | 683 | EXPORT_SYMBOL_GPL(usbnet_get_msglevel); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 |  | 
| David Brownell | 2e55cc7 | 2005-08-31 09:53:10 -0700 | [diff] [blame] | 685 | void usbnet_set_msglevel (struct net_device *net, u32 level) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | { | 
|  | 687 | struct usbnet *dev = netdev_priv(net); | 
|  | 688 |  | 
|  | 689 | dev->msg_enable = level; | 
|  | 690 | } | 
| David Brownell | 2e55cc7 | 2005-08-31 09:53:10 -0700 | [diff] [blame] | 691 | EXPORT_SYMBOL_GPL(usbnet_set_msglevel); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 |  | 
| David Brownell | 2e55cc7 | 2005-08-31 09:53:10 -0700 | [diff] [blame] | 693 | /* drivers may override default ethtool_ops in their bind() routine */ | 
|  | 694 | static struct ethtool_ops usbnet_ethtool_ops = { | 
|  | 695 | .get_drvinfo		= usbnet_get_drvinfo, | 
|  | 696 | .get_link		= usbnet_get_link, | 
|  | 697 | .get_msglevel		= usbnet_get_msglevel, | 
|  | 698 | .set_msglevel		= usbnet_set_msglevel, | 
|  | 699 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 |  | 
|  | 701 | /*-------------------------------------------------------------------------*/ | 
|  | 702 |  | 
|  | 703 | /* work that cannot be done in interrupt context uses keventd. | 
|  | 704 | * | 
|  | 705 | * NOTE:  with 2.5 we could do more of this using completion callbacks, | 
|  | 706 | * especially now that control transfers can be queued. | 
|  | 707 | */ | 
|  | 708 | static void | 
|  | 709 | kevent (void *data) | 
|  | 710 | { | 
|  | 711 | struct usbnet		*dev = data; | 
|  | 712 | int			status; | 
|  | 713 |  | 
|  | 714 | /* usb_clear_halt() needs a thread context */ | 
|  | 715 | if (test_bit (EVENT_TX_HALT, &dev->flags)) { | 
|  | 716 | unlink_urbs (dev, &dev->txq); | 
|  | 717 | status = usb_clear_halt (dev->udev, dev->out); | 
| David Brownell | f29fc25 | 2005-08-31 09:52:31 -0700 | [diff] [blame] | 718 | if (status < 0 | 
|  | 719 | && status != -EPIPE | 
|  | 720 | && status != -ESHUTDOWN) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | if (netif_msg_tx_err (dev)) | 
|  | 722 | deverr (dev, "can't clear tx halt, status %d", | 
|  | 723 | status); | 
|  | 724 | } else { | 
|  | 725 | clear_bit (EVENT_TX_HALT, &dev->flags); | 
| David Brownell | f29fc25 | 2005-08-31 09:52:31 -0700 | [diff] [blame] | 726 | if (status != -ESHUTDOWN) | 
|  | 727 | netif_wake_queue (dev->net); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | } | 
|  | 729 | } | 
|  | 730 | if (test_bit (EVENT_RX_HALT, &dev->flags)) { | 
|  | 731 | unlink_urbs (dev, &dev->rxq); | 
|  | 732 | status = usb_clear_halt (dev->udev, dev->in); | 
| David Brownell | f29fc25 | 2005-08-31 09:52:31 -0700 | [diff] [blame] | 733 | if (status < 0 | 
|  | 734 | && status != -EPIPE | 
|  | 735 | && status != -ESHUTDOWN) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | if (netif_msg_rx_err (dev)) | 
|  | 737 | deverr (dev, "can't clear rx halt, status %d", | 
|  | 738 | status); | 
|  | 739 | } else { | 
|  | 740 | clear_bit (EVENT_RX_HALT, &dev->flags); | 
|  | 741 | tasklet_schedule (&dev->bh); | 
|  | 742 | } | 
|  | 743 | } | 
|  | 744 |  | 
|  | 745 | /* tasklet could resubmit itself forever if memory is tight */ | 
|  | 746 | if (test_bit (EVENT_RX_MEMORY, &dev->flags)) { | 
|  | 747 | struct urb	*urb = NULL; | 
|  | 748 |  | 
|  | 749 | if (netif_running (dev->net)) | 
|  | 750 | urb = usb_alloc_urb (0, GFP_KERNEL); | 
|  | 751 | else | 
|  | 752 | clear_bit (EVENT_RX_MEMORY, &dev->flags); | 
|  | 753 | if (urb != NULL) { | 
|  | 754 | clear_bit (EVENT_RX_MEMORY, &dev->flags); | 
|  | 755 | rx_submit (dev, urb, GFP_KERNEL); | 
|  | 756 | tasklet_schedule (&dev->bh); | 
|  | 757 | } | 
|  | 758 | } | 
|  | 759 |  | 
| David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame] | 760 | if (test_bit (EVENT_LINK_RESET, &dev->flags)) { | 
|  | 761 | struct driver_info 	*info = dev->driver_info; | 
|  | 762 | int			retval = 0; | 
|  | 763 |  | 
|  | 764 | clear_bit (EVENT_LINK_RESET, &dev->flags); | 
|  | 765 | if(info->link_reset && (retval = info->link_reset(dev)) < 0) { | 
|  | 766 | devinfo(dev, "link reset failed (%d) usbnet usb-%s-%s, %s", | 
|  | 767 | retval, | 
|  | 768 | dev->udev->bus->bus_name, dev->udev->devpath, | 
|  | 769 | info->description); | 
|  | 770 | } | 
|  | 771 | } | 
|  | 772 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | if (dev->flags) | 
|  | 774 | devdbg (dev, "kevent done, flags = 0x%lx", | 
|  | 775 | dev->flags); | 
|  | 776 | } | 
|  | 777 |  | 
|  | 778 | /*-------------------------------------------------------------------------*/ | 
|  | 779 |  | 
|  | 780 | static void tx_complete (struct urb *urb, struct pt_regs *regs) | 
|  | 781 | { | 
|  | 782 | struct sk_buff		*skb = (struct sk_buff *) urb->context; | 
|  | 783 | struct skb_data		*entry = (struct skb_data *) skb->cb; | 
|  | 784 | struct usbnet		*dev = entry->dev; | 
|  | 785 |  | 
|  | 786 | if (urb->status == 0) { | 
|  | 787 | dev->stats.tx_packets++; | 
|  | 788 | dev->stats.tx_bytes += entry->length; | 
|  | 789 | } else { | 
|  | 790 | dev->stats.tx_errors++; | 
|  | 791 |  | 
|  | 792 | switch (urb->status) { | 
|  | 793 | case -EPIPE: | 
| David Brownell | 2e55cc7 | 2005-08-31 09:53:10 -0700 | [diff] [blame] | 794 | usbnet_defer_kevent (dev, EVENT_TX_HALT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | break; | 
|  | 796 |  | 
|  | 797 | /* software-driven interface shutdown */ | 
|  | 798 | case -ECONNRESET:		// async unlink | 
|  | 799 | case -ESHUTDOWN:		// hardware gone | 
|  | 800 | break; | 
|  | 801 |  | 
|  | 802 | // like rx, tx gets controller i/o faults during khubd delays | 
|  | 803 | // and so it uses the same throttling mechanism. | 
|  | 804 | case -EPROTO:		// ehci | 
|  | 805 | case -ETIMEDOUT:	// ohci | 
|  | 806 | case -EILSEQ:		// uhci | 
|  | 807 | if (!timer_pending (&dev->delay)) { | 
|  | 808 | mod_timer (&dev->delay, | 
|  | 809 | jiffies + THROTTLE_JIFFIES); | 
|  | 810 | if (netif_msg_link (dev)) | 
|  | 811 | devdbg (dev, "tx throttle %d", | 
|  | 812 | urb->status); | 
|  | 813 | } | 
|  | 814 | netif_stop_queue (dev->net); | 
|  | 815 | break; | 
|  | 816 | default: | 
|  | 817 | if (netif_msg_tx_err (dev)) | 
|  | 818 | devdbg (dev, "tx err %d", entry->urb->status); | 
|  | 819 | break; | 
|  | 820 | } | 
|  | 821 | } | 
|  | 822 |  | 
|  | 823 | urb->dev = NULL; | 
|  | 824 | entry->state = tx_done; | 
| David S. Miller | 8728b83 | 2005-08-09 19:25:21 -0700 | [diff] [blame] | 825 | defer_bh(dev, skb, &dev->txq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | } | 
|  | 827 |  | 
|  | 828 | /*-------------------------------------------------------------------------*/ | 
|  | 829 |  | 
|  | 830 | static void usbnet_tx_timeout (struct net_device *net) | 
|  | 831 | { | 
|  | 832 | struct usbnet		*dev = netdev_priv(net); | 
|  | 833 |  | 
|  | 834 | unlink_urbs (dev, &dev->txq); | 
|  | 835 | tasklet_schedule (&dev->bh); | 
|  | 836 |  | 
|  | 837 | // FIXME: device recovery -- reset? | 
|  | 838 | } | 
|  | 839 |  | 
|  | 840 | /*-------------------------------------------------------------------------*/ | 
|  | 841 |  | 
|  | 842 | static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net) | 
|  | 843 | { | 
|  | 844 | struct usbnet		*dev = netdev_priv(net); | 
|  | 845 | int			length; | 
|  | 846 | int			retval = NET_XMIT_SUCCESS; | 
|  | 847 | struct urb		*urb = NULL; | 
|  | 848 | struct skb_data		*entry; | 
|  | 849 | struct driver_info	*info = dev->driver_info; | 
|  | 850 | unsigned long		flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 |  | 
|  | 852 | // some devices want funky USB-level framing, for | 
|  | 853 | // win32 driver (usually) and/or hardware quirks | 
|  | 854 | if (info->tx_fixup) { | 
|  | 855 | skb = info->tx_fixup (dev, skb, GFP_ATOMIC); | 
|  | 856 | if (!skb) { | 
|  | 857 | if (netif_msg_tx_err (dev)) | 
|  | 858 | devdbg (dev, "can't tx_fixup skb"); | 
|  | 859 | goto drop; | 
|  | 860 | } | 
|  | 861 | } | 
|  | 862 | length = skb->len; | 
|  | 863 |  | 
|  | 864 | if (!(urb = usb_alloc_urb (0, GFP_ATOMIC))) { | 
|  | 865 | if (netif_msg_tx_err (dev)) | 
|  | 866 | devdbg (dev, "no urb"); | 
|  | 867 | goto drop; | 
|  | 868 | } | 
|  | 869 |  | 
|  | 870 | entry = (struct skb_data *) skb->cb; | 
|  | 871 | entry->urb = urb; | 
|  | 872 | entry->dev = dev; | 
|  | 873 | entry->state = tx_start; | 
|  | 874 | entry->length = length; | 
|  | 875 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | usb_fill_bulk_urb (urb, dev->udev, dev->out, | 
|  | 877 | skb->data, skb->len, tx_complete, skb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 |  | 
|  | 879 | /* don't assume the hardware handles USB_ZERO_PACKET | 
|  | 880 | * NOTE:  strictly conforming cdc-ether devices should expect | 
|  | 881 | * the ZLP here, but ignore the one-byte packet. | 
|  | 882 | * | 
|  | 883 | * FIXME zero that byte, if it doesn't require a new skb. | 
|  | 884 | */ | 
|  | 885 | if ((length % dev->maxpacket) == 0) | 
|  | 886 | urb->transfer_buffer_length++; | 
|  | 887 |  | 
|  | 888 | spin_lock_irqsave (&dev->txq.lock, flags); | 
|  | 889 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | switch ((retval = usb_submit_urb (urb, GFP_ATOMIC))) { | 
|  | 891 | case -EPIPE: | 
|  | 892 | netif_stop_queue (net); | 
| David Brownell | 2e55cc7 | 2005-08-31 09:53:10 -0700 | [diff] [blame] | 893 | usbnet_defer_kevent (dev, EVENT_TX_HALT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | break; | 
|  | 895 | default: | 
|  | 896 | if (netif_msg_tx_err (dev)) | 
|  | 897 | devdbg (dev, "tx: submit urb err %d", retval); | 
|  | 898 | break; | 
|  | 899 | case 0: | 
|  | 900 | net->trans_start = jiffies; | 
|  | 901 | __skb_queue_tail (&dev->txq, skb); | 
|  | 902 | if (dev->txq.qlen >= TX_QLEN (dev)) | 
|  | 903 | netif_stop_queue (net); | 
|  | 904 | } | 
|  | 905 | spin_unlock_irqrestore (&dev->txq.lock, flags); | 
|  | 906 |  | 
|  | 907 | if (retval) { | 
|  | 908 | if (netif_msg_tx_err (dev)) | 
|  | 909 | devdbg (dev, "drop, code %d", retval); | 
|  | 910 | drop: | 
|  | 911 | retval = NET_XMIT_SUCCESS; | 
|  | 912 | dev->stats.tx_dropped++; | 
|  | 913 | if (skb) | 
|  | 914 | dev_kfree_skb_any (skb); | 
|  | 915 | usb_free_urb (urb); | 
|  | 916 | } else if (netif_msg_tx_queued (dev)) { | 
|  | 917 | devdbg (dev, "> tx, len %d, type 0x%x", | 
|  | 918 | length, skb->protocol); | 
|  | 919 | } | 
|  | 920 | return retval; | 
|  | 921 | } | 
|  | 922 |  | 
|  | 923 |  | 
|  | 924 | /*-------------------------------------------------------------------------*/ | 
|  | 925 |  | 
|  | 926 | // tasklet (work deferred from completions, in_irq) or timer | 
|  | 927 |  | 
|  | 928 | static void usbnet_bh (unsigned long param) | 
|  | 929 | { | 
|  | 930 | struct usbnet		*dev = (struct usbnet *) param; | 
|  | 931 | struct sk_buff		*skb; | 
|  | 932 | struct skb_data		*entry; | 
|  | 933 |  | 
|  | 934 | while ((skb = skb_dequeue (&dev->done))) { | 
|  | 935 | entry = (struct skb_data *) skb->cb; | 
|  | 936 | switch (entry->state) { | 
|  | 937 | case rx_done: | 
|  | 938 | entry->state = rx_cleanup; | 
|  | 939 | rx_process (dev, skb); | 
|  | 940 | continue; | 
|  | 941 | case tx_done: | 
|  | 942 | case rx_cleanup: | 
|  | 943 | usb_free_urb (entry->urb); | 
|  | 944 | dev_kfree_skb (skb); | 
|  | 945 | continue; | 
|  | 946 | default: | 
|  | 947 | devdbg (dev, "bogus skb state %d", entry->state); | 
|  | 948 | } | 
|  | 949 | } | 
|  | 950 |  | 
|  | 951 | // waiting for all pending urbs to complete? | 
|  | 952 | if (dev->wait) { | 
|  | 953 | if ((dev->txq.qlen + dev->rxq.qlen + dev->done.qlen) == 0) { | 
|  | 954 | wake_up (dev->wait); | 
|  | 955 | } | 
|  | 956 |  | 
|  | 957 | // or are we maybe short a few urbs? | 
|  | 958 | } else if (netif_running (dev->net) | 
|  | 959 | && netif_device_present (dev->net) | 
|  | 960 | && !timer_pending (&dev->delay) | 
|  | 961 | && !test_bit (EVENT_RX_HALT, &dev->flags)) { | 
|  | 962 | int	temp = dev->rxq.qlen; | 
|  | 963 | int	qlen = RX_QLEN (dev); | 
|  | 964 |  | 
|  | 965 | if (temp < qlen) { | 
|  | 966 | struct urb	*urb; | 
|  | 967 | int		i; | 
|  | 968 |  | 
|  | 969 | // don't refill the queue all at once | 
|  | 970 | for (i = 0; i < 10 && dev->rxq.qlen < qlen; i++) { | 
|  | 971 | urb = usb_alloc_urb (0, GFP_ATOMIC); | 
|  | 972 | if (urb != NULL) | 
|  | 973 | rx_submit (dev, urb, GFP_ATOMIC); | 
|  | 974 | } | 
|  | 975 | if (temp != dev->rxq.qlen && netif_msg_link (dev)) | 
|  | 976 | devdbg (dev, "rxqlen %d --> %d", | 
|  | 977 | temp, dev->rxq.qlen); | 
|  | 978 | if (dev->rxq.qlen < qlen) | 
|  | 979 | tasklet_schedule (&dev->bh); | 
|  | 980 | } | 
|  | 981 | if (dev->txq.qlen < TX_QLEN (dev)) | 
|  | 982 | netif_wake_queue (dev->net); | 
|  | 983 | } | 
|  | 984 | } | 
|  | 985 |  | 
|  | 986 |  | 
|  | 987 |  | 
|  | 988 | /*------------------------------------------------------------------------- | 
|  | 989 | * | 
|  | 990 | * USB Device Driver support | 
|  | 991 | * | 
|  | 992 | *-------------------------------------------------------------------------*/ | 
|  | 993 |  | 
|  | 994 | // precondition: never called in_interrupt | 
|  | 995 |  | 
| David Brownell | 38bde1d | 2005-08-31 09:52:45 -0700 | [diff] [blame] | 996 | void usbnet_disconnect (struct usb_interface *intf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | { | 
|  | 998 | struct usbnet		*dev; | 
|  | 999 | struct usb_device	*xdev; | 
|  | 1000 | struct net_device	*net; | 
|  | 1001 |  | 
|  | 1002 | dev = usb_get_intfdata(intf); | 
|  | 1003 | usb_set_intfdata(intf, NULL); | 
|  | 1004 | if (!dev) | 
|  | 1005 | return; | 
|  | 1006 |  | 
|  | 1007 | xdev = interface_to_usbdev (intf); | 
|  | 1008 |  | 
|  | 1009 | if (netif_msg_probe (dev)) | 
| David Brownell | 38bde1d | 2005-08-31 09:52:45 -0700 | [diff] [blame] | 1010 | devinfo (dev, "unregister '%s' usb-%s-%s, %s", | 
|  | 1011 | intf->dev.driver->name, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | xdev->bus->bus_name, xdev->devpath, | 
|  | 1013 | dev->driver_info->description); | 
|  | 1014 |  | 
|  | 1015 | net = dev->net; | 
|  | 1016 | unregister_netdev (net); | 
|  | 1017 |  | 
|  | 1018 | /* we don't hold rtnl here ... */ | 
|  | 1019 | flush_scheduled_work (); | 
|  | 1020 |  | 
|  | 1021 | if (dev->driver_info->unbind) | 
|  | 1022 | dev->driver_info->unbind (dev, intf); | 
|  | 1023 |  | 
|  | 1024 | free_netdev(net); | 
|  | 1025 | usb_put_dev (xdev); | 
|  | 1026 | } | 
| David Brownell | 38bde1d | 2005-08-31 09:52:45 -0700 | [diff] [blame] | 1027 | EXPORT_SYMBOL_GPL(usbnet_disconnect); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 |  | 
|  | 1029 |  | 
|  | 1030 | /*-------------------------------------------------------------------------*/ | 
|  | 1031 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | // precondition: never called in_interrupt | 
|  | 1033 |  | 
| David Brownell | 38bde1d | 2005-08-31 09:52:45 -0700 | [diff] [blame] | 1034 | int | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) | 
|  | 1036 | { | 
|  | 1037 | struct usbnet			*dev; | 
|  | 1038 | struct net_device 		*net; | 
|  | 1039 | struct usb_host_interface	*interface; | 
|  | 1040 | struct driver_info		*info; | 
|  | 1041 | struct usb_device		*xdev; | 
|  | 1042 | int				status; | 
|  | 1043 |  | 
|  | 1044 | info = (struct driver_info *) prod->driver_info; | 
|  | 1045 | if (!info) { | 
|  | 1046 | dev_dbg (&udev->dev, "blacklisted by %s\n", driver_name); | 
|  | 1047 | return -ENODEV; | 
|  | 1048 | } | 
|  | 1049 | xdev = interface_to_usbdev (udev); | 
|  | 1050 | interface = udev->cur_altsetting; | 
|  | 1051 |  | 
|  | 1052 | usb_get_dev (xdev); | 
|  | 1053 |  | 
|  | 1054 | status = -ENOMEM; | 
|  | 1055 |  | 
|  | 1056 | // set up our own records | 
|  | 1057 | net = alloc_etherdev(sizeof(*dev)); | 
|  | 1058 | if (!net) { | 
|  | 1059 | dbg ("can't kmalloc dev"); | 
|  | 1060 | goto out; | 
|  | 1061 | } | 
|  | 1062 |  | 
|  | 1063 | dev = netdev_priv(net); | 
|  | 1064 | dev->udev = xdev; | 
|  | 1065 | dev->driver_info = info; | 
|  | 1066 | dev->msg_enable = netif_msg_init (msg_level, NETIF_MSG_DRV | 
|  | 1067 | | NETIF_MSG_PROBE | NETIF_MSG_LINK); | 
|  | 1068 | skb_queue_head_init (&dev->rxq); | 
|  | 1069 | skb_queue_head_init (&dev->txq); | 
|  | 1070 | skb_queue_head_init (&dev->done); | 
|  | 1071 | dev->bh.func = usbnet_bh; | 
|  | 1072 | dev->bh.data = (unsigned long) dev; | 
|  | 1073 | INIT_WORK (&dev->kevent, kevent, dev); | 
|  | 1074 | dev->delay.function = usbnet_bh; | 
|  | 1075 | dev->delay.data = (unsigned long) dev; | 
|  | 1076 | init_timer (&dev->delay); | 
|  | 1077 |  | 
|  | 1078 | SET_MODULE_OWNER (net); | 
|  | 1079 | dev->net = net; | 
|  | 1080 | strcpy (net->name, "usb%d"); | 
|  | 1081 | memcpy (net->dev_addr, node_id, sizeof node_id); | 
|  | 1082 |  | 
| David Brownell | 2e55cc7 | 2005-08-31 09:53:10 -0700 | [diff] [blame] | 1083 | /* rx and tx sides can use different message sizes; | 
|  | 1084 | * bind() should set rx_urb_size in that case. | 
|  | 1085 | */ | 
|  | 1086 | dev->hard_mtu = net->mtu + net->hard_header_len; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | #if 0 | 
|  | 1088 | // dma_supported() is deeply broken on almost all architectures | 
|  | 1089 | // possible with some EHCI controllers | 
|  | 1090 | if (dma_supported (&udev->dev, DMA_64BIT_MASK)) | 
|  | 1091 | net->features |= NETIF_F_HIGHDMA; | 
|  | 1092 | #endif | 
|  | 1093 |  | 
|  | 1094 | net->change_mtu = usbnet_change_mtu; | 
|  | 1095 | net->get_stats = usbnet_get_stats; | 
|  | 1096 | net->hard_start_xmit = usbnet_start_xmit; | 
|  | 1097 | net->open = usbnet_open; | 
|  | 1098 | net->stop = usbnet_stop; | 
|  | 1099 | net->watchdog_timeo = TX_TIMEOUT_JIFFIES; | 
|  | 1100 | net->tx_timeout = usbnet_tx_timeout; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | net->ethtool_ops = &usbnet_ethtool_ops; | 
|  | 1102 |  | 
|  | 1103 | // allow device-specific bind/init procedures | 
|  | 1104 | // NOTE net->name still not usable ... | 
|  | 1105 | if (info->bind) { | 
|  | 1106 | status = info->bind (dev, udev); | 
|  | 1107 | // heuristic:  "usb%d" for links we know are two-host, | 
|  | 1108 | // else "eth%d" when there's reasonable doubt.  userspace | 
|  | 1109 | // can rename the link if it knows better. | 
|  | 1110 | if ((dev->driver_info->flags & FLAG_ETHER) != 0 | 
|  | 1111 | && (net->dev_addr [0] & 0x02) == 0) | 
|  | 1112 | strcpy (net->name, "eth%d"); | 
| David Brownell | f29fc25 | 2005-08-31 09:52:31 -0700 | [diff] [blame] | 1113 |  | 
|  | 1114 | /* maybe the remote can't receive an Ethernet MTU */ | 
|  | 1115 | if (net->mtu > (dev->hard_mtu - net->hard_header_len)) | 
|  | 1116 | net->mtu = dev->hard_mtu - net->hard_header_len; | 
| David Brownell | 2e55cc7 | 2005-08-31 09:53:10 -0700 | [diff] [blame] | 1117 | } else if (!info->in || !info->out) | 
|  | 1118 | status = usbnet_get_endpoints (dev, udev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | else { | 
|  | 1120 | dev->in = usb_rcvbulkpipe (xdev, info->in); | 
|  | 1121 | dev->out = usb_sndbulkpipe (xdev, info->out); | 
|  | 1122 | if (!(info->flags & FLAG_NO_SETINT)) | 
|  | 1123 | status = usb_set_interface (xdev, | 
|  | 1124 | interface->desc.bInterfaceNumber, | 
|  | 1125 | interface->desc.bAlternateSetting); | 
|  | 1126 | else | 
|  | 1127 | status = 0; | 
|  | 1128 |  | 
|  | 1129 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | if (status == 0 && dev->status) | 
|  | 1131 | status = init_status (dev, udev); | 
|  | 1132 | if (status < 0) | 
|  | 1133 | goto out1; | 
|  | 1134 |  | 
| David Brownell | 2e55cc7 | 2005-08-31 09:53:10 -0700 | [diff] [blame] | 1135 | if (!dev->rx_urb_size) | 
|  | 1136 | dev->rx_urb_size = dev->hard_mtu; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1); | 
|  | 1138 |  | 
|  | 1139 | SET_NETDEV_DEV(net, &udev->dev); | 
|  | 1140 | status = register_netdev (net); | 
|  | 1141 | if (status) | 
|  | 1142 | goto out3; | 
|  | 1143 | if (netif_msg_probe (dev)) | 
| David Brownell | 38bde1d | 2005-08-31 09:52:45 -0700 | [diff] [blame] | 1144 | devinfo (dev, "register '%s' at usb-%s-%s, %s, " | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | "%02x:%02x:%02x:%02x:%02x:%02x", | 
| David Brownell | 38bde1d | 2005-08-31 09:52:45 -0700 | [diff] [blame] | 1146 | udev->dev.driver->name, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | xdev->bus->bus_name, xdev->devpath, | 
|  | 1148 | dev->driver_info->description, | 
|  | 1149 | net->dev_addr [0], net->dev_addr [1], | 
|  | 1150 | net->dev_addr [2], net->dev_addr [3], | 
|  | 1151 | net->dev_addr [4], net->dev_addr [5]); | 
|  | 1152 |  | 
|  | 1153 | // ok, it's ready to go. | 
|  | 1154 | usb_set_intfdata (udev, dev); | 
|  | 1155 |  | 
|  | 1156 | // start as if the link is up | 
|  | 1157 | netif_device_attach (net); | 
|  | 1158 |  | 
|  | 1159 | return 0; | 
|  | 1160 |  | 
|  | 1161 | out3: | 
|  | 1162 | if (info->unbind) | 
|  | 1163 | info->unbind (dev, udev); | 
|  | 1164 | out1: | 
|  | 1165 | free_netdev(net); | 
|  | 1166 | out: | 
|  | 1167 | usb_put_dev(xdev); | 
|  | 1168 | return status; | 
|  | 1169 | } | 
| David Brownell | 38bde1d | 2005-08-31 09:52:45 -0700 | [diff] [blame] | 1170 | EXPORT_SYMBOL_GPL(usbnet_probe); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 |  | 
|  | 1172 | /*-------------------------------------------------------------------------*/ | 
|  | 1173 |  | 
| David Brownell | 38bde1d | 2005-08-31 09:52:45 -0700 | [diff] [blame] | 1174 | /* FIXME these suspend/resume methods assume non-CDC style | 
|  | 1175 | * devices, with only one interface. | 
|  | 1176 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 |  | 
| David Brownell | 38bde1d | 2005-08-31 09:52:45 -0700 | [diff] [blame] | 1178 | int usbnet_suspend (struct usb_interface *intf, pm_message_t message) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | { | 
|  | 1180 | struct usbnet		*dev = usb_get_intfdata(intf); | 
|  | 1181 |  | 
| David Brownell | 27d72e8 | 2005-04-18 17:39:22 -0700 | [diff] [blame] | 1182 | /* accelerate emptying of the rx and queues, to avoid | 
|  | 1183 | * having everything error out. | 
|  | 1184 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | netif_device_detach (dev->net); | 
| David Brownell | 27d72e8 | 2005-04-18 17:39:22 -0700 | [diff] [blame] | 1186 | (void) unlink_urbs (dev, &dev->rxq); | 
|  | 1187 | (void) unlink_urbs (dev, &dev->txq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | return 0; | 
|  | 1189 | } | 
| David Brownell | 38bde1d | 2005-08-31 09:52:45 -0700 | [diff] [blame] | 1190 | EXPORT_SYMBOL_GPL(usbnet_suspend); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 |  | 
| David Brownell | 38bde1d | 2005-08-31 09:52:45 -0700 | [diff] [blame] | 1192 | int usbnet_resume (struct usb_interface *intf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | { | 
|  | 1194 | struct usbnet		*dev = usb_get_intfdata(intf); | 
|  | 1195 |  | 
|  | 1196 | netif_device_attach (dev->net); | 
| David Brownell | 27d72e8 | 2005-04-18 17:39:22 -0700 | [diff] [blame] | 1197 | tasklet_schedule (&dev->bh); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | return 0; | 
|  | 1199 | } | 
| David Brownell | 38bde1d | 2005-08-31 09:52:45 -0700 | [diff] [blame] | 1200 | EXPORT_SYMBOL_GPL(usbnet_resume); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 |  | 
|  | 1203 | /*-------------------------------------------------------------------------*/ | 
|  | 1204 |  | 
| David Brownell | f29fc25 | 2005-08-31 09:52:31 -0700 | [diff] [blame] | 1205 | static int __init usbnet_init(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | { | 
| David Brownell | 090ffa9 | 2005-08-31 09:54:50 -0700 | [diff] [blame] | 1207 | /* compiler should optimize this out */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | BUG_ON (sizeof (((struct sk_buff *)0)->cb) | 
|  | 1209 | < sizeof (struct skb_data)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 |  | 
|  | 1211 | random_ether_addr(node_id); | 
| David Brownell | 090ffa9 | 2005-08-31 09:54:50 -0700 | [diff] [blame] | 1212 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | } | 
| David Brownell | f29fc25 | 2005-08-31 09:52:31 -0700 | [diff] [blame] | 1214 | module_init(usbnet_init); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 |  | 
| David Brownell | f29fc25 | 2005-08-31 09:52:31 -0700 | [diff] [blame] | 1216 | static void __exit usbnet_exit(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | } | 
| David Brownell | f29fc25 | 2005-08-31 09:52:31 -0700 | [diff] [blame] | 1219 | module_exit(usbnet_exit); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 |  | 
| David Brownell | f29fc25 | 2005-08-31 09:52:31 -0700 | [diff] [blame] | 1221 | MODULE_AUTHOR("David Brownell"); | 
| David Brownell | 090ffa9 | 2005-08-31 09:54:50 -0700 | [diff] [blame] | 1222 | MODULE_DESCRIPTION("USB network driver framework"); | 
| David Brownell | f29fc25 | 2005-08-31 09:52:31 -0700 | [diff] [blame] | 1223 | MODULE_LICENSE("GPL"); |