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