diff options
author | David Brownell <david-b@pacbell.net> | 2005-08-31 12:53:26 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2005-09-08 19:28:31 -0400 |
commit | 904813cd8a0b334189da285bb05af0b18b062502 (patch) | |
tree | b602c3a1b8907dcd9dc43193f41477cfc402fcc2 /drivers/usb | |
parent | 2e55cc7210fef90f88201e860d8767594974574e (diff) |
[PATCH] USB: usbnet (4/9) module for net1080 cables
As with the "cdc_subset" and "asix" drivers, this just moves the net1080
support into its one driver module. In this case there's a small bit of
extra cleanup involved, moving some funky framing logic into the tx_fixup()
routine (resolving a long overdue FIXME).
Minor historical note: "usbnet" started out as "net1080", then got
generalized to make it easier for other network drivers to reuse the
urb queueing and fault management code here.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb')
-rw-r--r-- | drivers/usb/net/Kconfig | 18 | ||||
-rw-r--r-- | drivers/usb/net/Makefile | 1 | ||||
-rw-r--r-- | drivers/usb/net/net1080.c | 622 | ||||
-rw-r--r-- | drivers/usb/net/usbnet.c | 571 |
4 files changed, 632 insertions, 580 deletions
diff --git a/drivers/usb/net/Kconfig b/drivers/usb/net/Kconfig index 4fb51b998cc8..0aa8637e5ff3 100644 --- a/drivers/usb/net/Kconfig +++ b/drivers/usb/net/Kconfig | |||
@@ -138,15 +138,6 @@ config USB_GENESYS | |||
138 | 138 | ||
139 | Note that the half-duplex "GL620USB" is not supported. | 139 | Note that the half-duplex "GL620USB" is not supported. |
140 | 140 | ||
141 | config USB_NET1080 | ||
142 | boolean "NetChip 1080 based cables (Laplink, ...)" | ||
143 | default y | ||
144 | depends on USB_USBNET | ||
145 | help | ||
146 | Choose this option if you're using a host-to-host cable based | ||
147 | on this design: one NetChip 1080 chips and supporting logic, | ||
148 | supporting LEDs that indicate traffic | ||
149 | |||
150 | config USB_PL2301 | 141 | config USB_PL2301 |
151 | boolean "Prolific PL-2301/2302 based cables" | 142 | boolean "Prolific PL-2301/2302 based cables" |
152 | default y | 143 | default y |
@@ -233,6 +224,15 @@ config USB_NET_AX8817X | |||
233 | what other networking devices you have in use. | 224 | what other networking devices you have in use. |
234 | 225 | ||
235 | 226 | ||
227 | config USB_NET_NET1080 | ||
228 | tristate "NetChip 1080 based cables (Laplink, ...)" | ||
229 | default y | ||
230 | depends on USB_USBNET | ||
231 | help | ||
232 | Choose this option if you're using a host-to-host cable based | ||
233 | on this design: one NetChip 1080 chip and supporting logic, | ||
234 | optionally with LEDs that indicate traffic | ||
235 | |||
236 | config USB_NET_CDC_SUBSET | 236 | config USB_NET_CDC_SUBSET |
237 | tristate "Simple USB Network Links (CDC Ethernet subset)" | 237 | tristate "Simple USB Network Links (CDC Ethernet subset)" |
238 | depends on USB_USBNET | 238 | depends on USB_USBNET |
diff --git a/drivers/usb/net/Makefile b/drivers/usb/net/Makefile index 60dc91e5cdbf..14d554080aa5 100644 --- a/drivers/usb/net/Makefile +++ b/drivers/usb/net/Makefile | |||
@@ -7,6 +7,7 @@ obj-$(CONFIG_USB_KAWETH) += kaweth.o | |||
7 | obj-$(CONFIG_USB_PEGASUS) += pegasus.o | 7 | obj-$(CONFIG_USB_PEGASUS) += pegasus.o |
8 | obj-$(CONFIG_USB_RTL8150) += rtl8150.o | 8 | obj-$(CONFIG_USB_RTL8150) += rtl8150.o |
9 | obj-$(CONFIG_USB_NET_AX8817X) += asix.o | 9 | obj-$(CONFIG_USB_NET_AX8817X) += asix.o |
10 | obj-$(CONFIG_USB_NET_NET1080) += net1080.o | ||
10 | obj-$(CONFIG_USB_NET_CDC_SUBSET) += cdc_subset.o | 11 | obj-$(CONFIG_USB_NET_CDC_SUBSET) += cdc_subset.o |
11 | obj-$(CONFIG_USB_USBNET) += usbnet.o | 12 | obj-$(CONFIG_USB_USBNET) += usbnet.o |
12 | obj-$(CONFIG_USB_ZD1201) += zd1201.o | 13 | obj-$(CONFIG_USB_ZD1201) += zd1201.o |
diff --git a/drivers/usb/net/net1080.c b/drivers/usb/net/net1080.c new file mode 100644 index 000000000000..a4309c4a491b --- /dev/null +++ b/drivers/usb/net/net1080.c | |||
@@ -0,0 +1,622 @@ | |||
1 | /* | ||
2 | * Net1080 based USB host-to-host cables | ||
3 | * Copyright (C) 2000-2005 by David Brownell | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | // #define DEBUG // error path messages, extra info | ||
21 | // #define VERBOSE // more; success messages | ||
22 | |||
23 | #include <linux/config.h> | ||
24 | #ifdef CONFIG_USB_DEBUG | ||
25 | # define DEBUG | ||
26 | #endif | ||
27 | #include <linux/module.h> | ||
28 | #include <linux/sched.h> | ||
29 | #include <linux/init.h> | ||
30 | #include <linux/netdevice.h> | ||
31 | #include <linux/etherdevice.h> | ||
32 | #include <linux/ethtool.h> | ||
33 | #include <linux/workqueue.h> | ||
34 | #include <linux/mii.h> | ||
35 | #include <linux/usb.h> | ||
36 | |||
37 | #include <asm/unaligned.h> | ||
38 | |||
39 | #include "usbnet.h" | ||
40 | |||
41 | |||
42 | /* | ||
43 | * Netchip 1080 driver ... http://www.netchip.com | ||
44 | * (Sept 2004: End-of-life announcement has been sent.) | ||
45 | * Used in (some) LapLink cables | ||
46 | */ | ||
47 | |||
48 | #define frame_errors data[1] | ||
49 | |||
50 | /* | ||
51 | * NetChip framing of ethernet packets, supporting additional error | ||
52 | * checks for links that may drop bulk packets from inside messages. | ||
53 | * Odd USB length == always short read for last usb packet. | ||
54 | * - nc_header | ||
55 | * - Ethernet header (14 bytes) | ||
56 | * - payload | ||
57 | * - (optional padding byte, if needed so length becomes odd) | ||
58 | * - nc_trailer | ||
59 | * | ||
60 | * This framing is to be avoided for non-NetChip devices. | ||
61 | */ | ||
62 | |||
63 | struct nc_header { // packed: | ||
64 | __le16 hdr_len; // sizeof nc_header (LE, all) | ||
65 | __le16 packet_len; // payload size (including ethhdr) | ||
66 | __le16 packet_id; // detects dropped packets | ||
67 | #define MIN_HEADER 6 | ||
68 | |||
69 | // all else is optional, and must start with: | ||
70 | // __le16 vendorId; // from usb-if | ||
71 | // __le16 productId; | ||
72 | } __attribute__((__packed__)); | ||
73 | |||
74 | #define PAD_BYTE ((unsigned char)0xAC) | ||
75 | |||
76 | struct nc_trailer { | ||
77 | __le16 packet_id; | ||
78 | } __attribute__((__packed__)); | ||
79 | |||
80 | // packets may use FLAG_FRAMING_NC and optional pad | ||
81 | #define FRAMED_SIZE(mtu) (sizeof (struct nc_header) \ | ||
82 | + sizeof (struct ethhdr) \ | ||
83 | + (mtu) \ | ||
84 | + 1 \ | ||
85 | + sizeof (struct nc_trailer)) | ||
86 | |||
87 | #define MIN_FRAMED FRAMED_SIZE(0) | ||
88 | |||
89 | /* packets _could_ be up to 64KB... */ | ||
90 | #define NC_MAX_PACKET 32767 | ||
91 | |||
92 | |||
93 | /* | ||
94 | * Zero means no timeout; else, how long a 64 byte bulk packet may be queued | ||
95 | * before the hardware drops it. If that's done, the driver will need to | ||
96 | * frame network packets to guard against the dropped USB packets. The win32 | ||
97 | * driver sets this for both sides of the link. | ||
98 | */ | ||
99 | #define NC_READ_TTL_MS ((u8)255) // ms | ||
100 | |||
101 | /* | ||
102 | * We ignore most registers and EEPROM contents. | ||
103 | */ | ||
104 | #define REG_USBCTL ((u8)0x04) | ||
105 | #define REG_TTL ((u8)0x10) | ||
106 | #define REG_STATUS ((u8)0x11) | ||
107 | |||
108 | /* | ||
109 | * Vendor specific requests to read/write data | ||
110 | */ | ||
111 | #define REQUEST_REGISTER ((u8)0x10) | ||
112 | #define REQUEST_EEPROM ((u8)0x11) | ||
113 | |||
114 | static int | ||
115 | nc_vendor_read(struct usbnet *dev, u8 req, u8 regnum, u16 *retval_ptr) | ||
116 | { | ||
117 | int status = usb_control_msg(dev->udev, | ||
118 | usb_rcvctrlpipe(dev->udev, 0), | ||
119 | req, | ||
120 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
121 | 0, regnum, | ||
122 | retval_ptr, sizeof *retval_ptr, | ||
123 | USB_CTRL_GET_TIMEOUT); | ||
124 | if (status > 0) | ||
125 | status = 0; | ||
126 | if (!status) | ||
127 | le16_to_cpus(retval_ptr); | ||
128 | return status; | ||
129 | } | ||
130 | |||
131 | static inline int | ||
132 | nc_register_read(struct usbnet *dev, u8 regnum, u16 *retval_ptr) | ||
133 | { | ||
134 | return nc_vendor_read(dev, REQUEST_REGISTER, regnum, retval_ptr); | ||
135 | } | ||
136 | |||
137 | // no retval ... can become async, usable in_interrupt() | ||
138 | static void | ||
139 | nc_vendor_write(struct usbnet *dev, u8 req, u8 regnum, u16 value) | ||
140 | { | ||
141 | usb_control_msg(dev->udev, | ||
142 | usb_sndctrlpipe(dev->udev, 0), | ||
143 | req, | ||
144 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
145 | value, regnum, | ||
146 | NULL, 0, // data is in setup packet | ||
147 | USB_CTRL_SET_TIMEOUT); | ||
148 | } | ||
149 | |||
150 | static inline void | ||
151 | nc_register_write(struct usbnet *dev, u8 regnum, u16 value) | ||
152 | { | ||
153 | nc_vendor_write(dev, REQUEST_REGISTER, regnum, value); | ||
154 | } | ||
155 | |||
156 | |||
157 | #if 0 | ||
158 | static void nc_dump_registers(struct usbnet *dev) | ||
159 | { | ||
160 | u8 reg; | ||
161 | u16 *vp = kmalloc(sizeof (u16)); | ||
162 | |||
163 | if (!vp) { | ||
164 | dbg("no memory?"); | ||
165 | return; | ||
166 | } | ||
167 | |||
168 | dbg("%s registers:", dev->net->name); | ||
169 | for (reg = 0; reg < 0x20; reg++) { | ||
170 | int retval; | ||
171 | |||
172 | // reading some registers is trouble | ||
173 | if (reg >= 0x08 && reg <= 0xf) | ||
174 | continue; | ||
175 | if (reg >= 0x12 && reg <= 0x1e) | ||
176 | continue; | ||
177 | |||
178 | retval = nc_register_read(dev, reg, vp); | ||
179 | if (retval < 0) | ||
180 | dbg("%s reg [0x%x] ==> error %d", | ||
181 | dev->net->name, reg, retval); | ||
182 | else | ||
183 | dbg("%s reg [0x%x] = 0x%x", | ||
184 | dev->net->name, reg, *vp); | ||
185 | } | ||
186 | kfree(vp); | ||
187 | } | ||
188 | #endif | ||
189 | |||
190 | |||
191 | /*-------------------------------------------------------------------------*/ | ||
192 | |||
193 | /* | ||
194 | * Control register | ||
195 | */ | ||
196 | |||
197 | #define USBCTL_WRITABLE_MASK 0x1f0f | ||
198 | // bits 15-13 reserved, r/o | ||
199 | #define USBCTL_ENABLE_LANG (1 << 12) | ||
200 | #define USBCTL_ENABLE_MFGR (1 << 11) | ||
201 | #define USBCTL_ENABLE_PROD (1 << 10) | ||
202 | #define USBCTL_ENABLE_SERIAL (1 << 9) | ||
203 | #define USBCTL_ENABLE_DEFAULTS (1 << 8) | ||
204 | // bits 7-4 reserved, r/o | ||
205 | #define USBCTL_FLUSH_OTHER (1 << 3) | ||
206 | #define USBCTL_FLUSH_THIS (1 << 2) | ||
207 | #define USBCTL_DISCONN_OTHER (1 << 1) | ||
208 | #define USBCTL_DISCONN_THIS (1 << 0) | ||
209 | |||
210 | static inline void nc_dump_usbctl(struct usbnet *dev, u16 usbctl) | ||
211 | { | ||
212 | if (!netif_msg_link(dev)) | ||
213 | return; | ||
214 | devdbg(dev, "net1080 %s-%s usbctl 0x%x:%s%s%s%s%s;" | ||
215 | " this%s%s;" | ||
216 | " other%s%s; r/o 0x%x", | ||
217 | dev->udev->bus->bus_name, dev->udev->devpath, | ||
218 | usbctl, | ||
219 | (usbctl & USBCTL_ENABLE_LANG) ? " lang" : "", | ||
220 | (usbctl & USBCTL_ENABLE_MFGR) ? " mfgr" : "", | ||
221 | (usbctl & USBCTL_ENABLE_PROD) ? " prod" : "", | ||
222 | (usbctl & USBCTL_ENABLE_SERIAL) ? " serial" : "", | ||
223 | (usbctl & USBCTL_ENABLE_DEFAULTS) ? " defaults" : "", | ||
224 | |||
225 | (usbctl & USBCTL_FLUSH_OTHER) ? " FLUSH" : "", | ||
226 | (usbctl & USBCTL_DISCONN_OTHER) ? " DIS" : "", | ||
227 | (usbctl & USBCTL_FLUSH_THIS) ? " FLUSH" : "", | ||
228 | (usbctl & USBCTL_DISCONN_THIS) ? " DIS" : "", | ||
229 | usbctl & ~USBCTL_WRITABLE_MASK | ||
230 | ); | ||
231 | } | ||
232 | |||
233 | /*-------------------------------------------------------------------------*/ | ||
234 | |||
235 | /* | ||
236 | * Status register | ||
237 | */ | ||
238 | |||
239 | #define STATUS_PORT_A (1 << 15) | ||
240 | |||
241 | #define STATUS_CONN_OTHER (1 << 14) | ||
242 | #define STATUS_SUSPEND_OTHER (1 << 13) | ||
243 | #define STATUS_MAILBOX_OTHER (1 << 12) | ||
244 | #define STATUS_PACKETS_OTHER(n) (((n) >> 8) && 0x03) | ||
245 | |||
246 | #define STATUS_CONN_THIS (1 << 6) | ||
247 | #define STATUS_SUSPEND_THIS (1 << 5) | ||
248 | #define STATUS_MAILBOX_THIS (1 << 4) | ||
249 | #define STATUS_PACKETS_THIS(n) (((n) >> 0) && 0x03) | ||
250 | |||
251 | #define STATUS_UNSPEC_MASK 0x0c8c | ||
252 | #define STATUS_NOISE_MASK ((u16)~(0x0303|STATUS_UNSPEC_MASK)) | ||
253 | |||
254 | |||
255 | static inline void nc_dump_status(struct usbnet *dev, u16 status) | ||
256 | { | ||
257 | if (!netif_msg_link(dev)) | ||
258 | return; | ||
259 | devdbg(dev, "net1080 %s-%s status 0x%x:" | ||
260 | " this (%c) PKT=%d%s%s%s;" | ||
261 | " other PKT=%d%s%s%s; unspec 0x%x", | ||
262 | dev->udev->bus->bus_name, dev->udev->devpath, | ||
263 | status, | ||
264 | |||
265 | // XXX the packet counts don't seem right | ||
266 | // (1 at reset, not 0); maybe UNSPEC too | ||
267 | |||
268 | (status & STATUS_PORT_A) ? 'A' : 'B', | ||
269 | STATUS_PACKETS_THIS(status), | ||
270 | (status & STATUS_CONN_THIS) ? " CON" : "", | ||
271 | (status & STATUS_SUSPEND_THIS) ? " SUS" : "", | ||
272 | (status & STATUS_MAILBOX_THIS) ? " MBOX" : "", | ||
273 | |||
274 | STATUS_PACKETS_OTHER(status), | ||
275 | (status & STATUS_CONN_OTHER) ? " CON" : "", | ||
276 | (status & STATUS_SUSPEND_OTHER) ? " SUS" : "", | ||
277 | (status & STATUS_MAILBOX_OTHER) ? " MBOX" : "", | ||
278 | |||
279 | status & STATUS_UNSPEC_MASK | ||
280 | ); | ||
281 | } | ||
282 | |||
283 | /*-------------------------------------------------------------------------*/ | ||
284 | |||
285 | /* | ||
286 | * TTL register | ||
287 | */ | ||
288 | |||
289 | #define TTL_THIS(ttl) (0x00ff & ttl) | ||
290 | #define TTL_OTHER(ttl) (0x00ff & (ttl >> 8)) | ||
291 | #define MK_TTL(this,other) ((u16)(((other)<<8)|(0x00ff&(this)))) | ||
292 | |||
293 | static inline void nc_dump_ttl(struct usbnet *dev, u16 ttl) | ||
294 | { | ||
295 | if (netif_msg_link(dev)) | ||
296 | devdbg(dev, "net1080 %s-%s ttl 0x%x this = %d, other = %d", | ||
297 | dev->udev->bus->bus_name, dev->udev->devpath, | ||
298 | ttl, TTL_THIS(ttl), TTL_OTHER(ttl)); | ||
299 | } | ||
300 | |||
301 | /*-------------------------------------------------------------------------*/ | ||
302 | |||
303 | static int net1080_reset(struct usbnet *dev) | ||
304 | { | ||
305 | u16 usbctl, status, ttl; | ||
306 | u16 *vp = kmalloc(sizeof (u16), GFP_KERNEL); | ||
307 | int retval; | ||
308 | |||
309 | if (!vp) | ||
310 | return -ENOMEM; | ||
311 | |||
312 | // nc_dump_registers(dev); | ||
313 | |||
314 | if ((retval = nc_register_read(dev, REG_STATUS, vp)) < 0) { | ||
315 | dbg("can't read %s-%s status: %d", | ||
316 | dev->udev->bus->bus_name, dev->udev->devpath, retval); | ||
317 | goto done; | ||
318 | } | ||
319 | status = *vp; | ||
320 | nc_dump_status(dev, status); | ||
321 | |||
322 | if ((retval = nc_register_read(dev, REG_USBCTL, vp)) < 0) { | ||
323 | dbg("can't read USBCTL, %d", retval); | ||
324 | goto done; | ||
325 | } | ||
326 | usbctl = *vp; | ||
327 | nc_dump_usbctl(dev, usbctl); | ||
328 | |||
329 | nc_register_write(dev, REG_USBCTL, | ||
330 | USBCTL_FLUSH_THIS | USBCTL_FLUSH_OTHER); | ||
331 | |||
332 | if ((retval = nc_register_read(dev, REG_TTL, vp)) < 0) { | ||
333 | dbg("can't read TTL, %d", retval); | ||
334 | goto done; | ||
335 | } | ||
336 | ttl = *vp; | ||
337 | // nc_dump_ttl(dev, ttl); | ||
338 | |||
339 | nc_register_write(dev, REG_TTL, | ||
340 | MK_TTL(NC_READ_TTL_MS, TTL_OTHER(ttl)) ); | ||
341 | dbg("%s: assigned TTL, %d ms", dev->net->name, NC_READ_TTL_MS); | ||
342 | |||
343 | if (netif_msg_link(dev)) | ||
344 | devinfo(dev, "port %c, peer %sconnected", | ||
345 | (status & STATUS_PORT_A) ? 'A' : 'B', | ||
346 | (status & STATUS_CONN_OTHER) ? "" : "dis" | ||
347 | ); | ||
348 | retval = 0; | ||
349 | |||
350 | done: | ||
351 | kfree(vp); | ||
352 | return retval; | ||
353 | } | ||
354 | |||
355 | static int net1080_check_connect(struct usbnet *dev) | ||
356 | { | ||
357 | int retval; | ||
358 | u16 status; | ||
359 | u16 *vp = kmalloc(sizeof (u16), GFP_KERNEL); | ||
360 | |||
361 | if (!vp) | ||
362 | return -ENOMEM; | ||
363 | retval = nc_register_read(dev, REG_STATUS, vp); | ||
364 | status = *vp; | ||
365 | kfree(vp); | ||
366 | if (retval != 0) { | ||
367 | dbg("%s net1080_check_conn read - %d", dev->net->name, retval); | ||
368 | return retval; | ||
369 | } | ||
370 | if ((status & STATUS_CONN_OTHER) != STATUS_CONN_OTHER) | ||
371 | return -ENOLINK; | ||
372 | return 0; | ||
373 | } | ||
374 | |||
375 | static void nc_flush_complete(struct urb *urb, struct pt_regs *regs) | ||
376 | { | ||
377 | kfree(urb->context); | ||
378 | usb_free_urb(urb); | ||
379 | } | ||
380 | |||
381 | static void nc_ensure_sync(struct usbnet *dev) | ||
382 | { | ||
383 | dev->frame_errors++; | ||
384 | if (dev->frame_errors > 5) { | ||
385 | struct urb *urb; | ||
386 | struct usb_ctrlrequest *req; | ||
387 | int status; | ||
388 | |||
389 | /* Send a flush */ | ||
390 | urb = usb_alloc_urb(0, SLAB_ATOMIC); | ||
391 | if (!urb) | ||
392 | return; | ||
393 | |||
394 | req = kmalloc(sizeof *req, GFP_ATOMIC); | ||
395 | if (!req) { | ||
396 | usb_free_urb(urb); | ||
397 | return; | ||
398 | } | ||
399 | |||
400 | req->bRequestType = USB_DIR_OUT | ||
401 | | USB_TYPE_VENDOR | ||
402 | | USB_RECIP_DEVICE; | ||
403 | req->bRequest = REQUEST_REGISTER; | ||
404 | req->wValue = cpu_to_le16(USBCTL_FLUSH_THIS | ||
405 | | USBCTL_FLUSH_OTHER); | ||
406 | req->wIndex = cpu_to_le16(REG_USBCTL); | ||
407 | req->wLength = cpu_to_le16(0); | ||
408 | |||
409 | /* queue an async control request, we don't need | ||
410 | * to do anything when it finishes except clean up. | ||
411 | */ | ||
412 | usb_fill_control_urb(urb, dev->udev, | ||
413 | usb_sndctrlpipe(dev->udev, 0), | ||
414 | (unsigned char *) req, | ||
415 | NULL, 0, | ||
416 | nc_flush_complete, req); | ||
417 | status = usb_submit_urb(urb, GFP_ATOMIC); | ||
418 | if (status) { | ||
419 | kfree(req); | ||
420 | usb_free_urb(urb); | ||
421 | return; | ||
422 | } | ||
423 | |||
424 | if (netif_msg_rx_err(dev)) | ||
425 | devdbg(dev, "flush net1080; too many framing errors"); | ||
426 | dev->frame_errors = 0; | ||
427 | } | ||
428 | } | ||
429 | |||
430 | static int net1080_rx_fixup(struct usbnet *dev, struct sk_buff *skb) | ||
431 | { | ||
432 | struct nc_header *header; | ||
433 | struct nc_trailer *trailer; | ||
434 | u16 hdr_len, packet_len; | ||
435 | |||
436 | if (!(skb->len & 0x01)) { | ||
437 | #ifdef DEBUG | ||
438 | struct net_device *net = dev->net; | ||
439 | dbg("rx framesize %d range %d..%d mtu %d", skb->len, | ||
440 | net->hard_header_len, dev->hard_mtu, net->mtu); | ||
441 | #endif | ||
442 | dev->stats.rx_frame_errors++; | ||
443 | nc_ensure_sync(dev); | ||
444 | return 0; | ||
445 | } | ||
446 | |||
447 | header = (struct nc_header *) skb->data; | ||
448 | hdr_len = le16_to_cpup(&header->hdr_len); | ||
449 | packet_len = le16_to_cpup(&header->packet_len); | ||
450 | if (FRAMED_SIZE(packet_len) > NC_MAX_PACKET) { | ||
451 | dev->stats.rx_frame_errors++; | ||
452 | dbg("packet too big, %d", packet_len); | ||
453 | nc_ensure_sync(dev); | ||
454 | return 0; | ||
455 | } else if (hdr_len < MIN_HEADER) { | ||
456 | dev->stats.rx_frame_errors++; | ||
457 | dbg("header too short, %d", hdr_len); | ||
458 | nc_ensure_sync(dev); | ||
459 | return 0; | ||
460 | } else if (hdr_len > MIN_HEADER) { | ||
461 | // out of band data for us? | ||
462 | dbg("header OOB, %d bytes", hdr_len - MIN_HEADER); | ||
463 | nc_ensure_sync(dev); | ||
464 | // switch (vendor/product ids) { ... } | ||
465 | } | ||
466 | skb_pull(skb, hdr_len); | ||
467 | |||
468 | trailer = (struct nc_trailer *) | ||
469 | (skb->data + skb->len - sizeof *trailer); | ||
470 | skb_trim(skb, skb->len - sizeof *trailer); | ||
471 | |||
472 | if ((packet_len & 0x01) == 0) { | ||
473 | if (skb->data [packet_len] != PAD_BYTE) { | ||
474 | dev->stats.rx_frame_errors++; | ||
475 | dbg("bad pad"); | ||
476 | return 0; | ||
477 | } | ||
478 | skb_trim(skb, skb->len - 1); | ||
479 | } | ||
480 | if (skb->len != packet_len) { | ||
481 | dev->stats.rx_frame_errors++; | ||
482 | dbg("bad packet len %d (expected %d)", | ||
483 | skb->len, packet_len); | ||
484 | nc_ensure_sync(dev); | ||
485 | return 0; | ||
486 | } | ||
487 | if (header->packet_id != get_unaligned(&trailer->packet_id)) { | ||
488 | dev->stats.rx_fifo_errors++; | ||
489 | dbg("(2+ dropped) rx packet_id mismatch 0x%x 0x%x", | ||
490 | le16_to_cpu(header->packet_id), | ||
491 | le16_to_cpu(trailer->packet_id)); | ||
492 | return 0; | ||
493 | } | ||
494 | #if 0 | ||
495 | devdbg(dev, "frame <rx h %d p %d id %d", header->hdr_len, | ||
496 | header->packet_len, header->packet_id); | ||
497 | #endif | ||
498 | dev->frame_errors = 0; | ||
499 | return 1; | ||
500 | } | ||
501 | |||
502 | static struct sk_buff * | ||
503 | net1080_tx_fixup(struct usbnet *dev, struct sk_buff *skb, unsigned flags) | ||
504 | { | ||
505 | int padlen; | ||
506 | struct sk_buff *skb2; | ||
507 | struct nc_header *header = NULL; | ||
508 | struct nc_trailer *trailer = NULL; | ||
509 | int len = skb->len; | ||
510 | |||
511 | padlen = ((len + sizeof (struct nc_header) | ||
512 | + sizeof (struct nc_trailer)) & 0x01) ? 0 : 1; | ||
513 | if (!skb_cloned(skb)) { | ||
514 | int headroom = skb_headroom(skb); | ||
515 | int tailroom = skb_tailroom(skb); | ||
516 | |||
517 | if ((padlen + sizeof (struct nc_trailer)) <= tailroom | ||
518 | && sizeof (struct nc_header) <= headroom) | ||
519 | /* There's enough head and tail room */ | ||
520 | goto encapsulate; | ||
521 | |||
522 | if ((sizeof (struct nc_header) + padlen | ||
523 | + sizeof (struct nc_trailer)) < | ||
524 | (headroom + tailroom)) { | ||
525 | /* There's enough total room, so just readjust */ | ||
526 | skb->data = memmove(skb->head | ||
527 | + sizeof (struct nc_header), | ||
528 | skb->data, skb->len); | ||
529 | skb->tail = skb->data + len; | ||
530 | goto encapsulate; | ||
531 | } | ||
532 | } | ||
533 | |||
534 | /* Create a new skb to use with the correct size */ | ||
535 | skb2 = skb_copy_expand(skb, | ||
536 | sizeof (struct nc_header), | ||
537 | sizeof (struct nc_trailer) + padlen, | ||
538 | flags); | ||
539 | dev_kfree_skb_any(skb); | ||
540 | if (!skb2) | ||
541 | return skb2; | ||
542 | skb = skb2; | ||
543 | |||
544 | encapsulate: | ||
545 | /* header first */ | ||
546 | header = (struct nc_header *) skb_push(skb, sizeof *header); | ||
547 | header->hdr_len = cpu_to_le16(sizeof (*header)); | ||
548 | header->packet_len = cpu_to_le16(len); | ||
549 | header->packet_id = cpu_to_le16((u16)dev->xid++); | ||
550 | |||
551 | /* maybe pad; then trailer */ | ||
552 | if (!((skb->len + sizeof *trailer) & 0x01)) | ||
553 | *skb_put(skb, 1) = PAD_BYTE; | ||
554 | trailer = (struct nc_trailer *) skb_put(skb, sizeof *trailer); | ||
555 | put_unaligned(header->packet_id, &trailer->packet_id); | ||
556 | #if 0 | ||
557 | devdbg(dev, "frame >tx h %d p %d id %d", | ||
558 | header->hdr_len, header->packet_len, | ||
559 | header->packet_id); | ||
560 | #endif | ||
561 | return skb; | ||
562 | } | ||
563 | |||
564 | static int net1080_bind(struct usbnet *dev, struct usb_interface *intf) | ||
565 | { | ||
566 | unsigned extra = sizeof (struct nc_header) | ||
567 | + 1 | ||
568 | + sizeof (struct nc_trailer); | ||
569 | |||
570 | dev->net->hard_header_len += extra; | ||
571 | dev->rx_urb_size = dev->net->hard_header_len + dev->net->mtu; | ||
572 | dev->hard_mtu = NC_MAX_PACKET; | ||
573 | return usbnet_get_endpoints (dev, intf); | ||
574 | } | ||
575 | |||
576 | static const struct driver_info net1080_info = { | ||
577 | .description = "NetChip TurboCONNECT", | ||
578 | .flags = FLAG_FRAMING_NC, | ||
579 | .bind = net1080_bind, | ||
580 | .reset = net1080_reset, | ||
581 | .check_connect = net1080_check_connect, | ||
582 | .rx_fixup = net1080_rx_fixup, | ||
583 | .tx_fixup = net1080_tx_fixup, | ||
584 | }; | ||
585 | |||
586 | static const struct usb_device_id products [] = { | ||
587 | { | ||
588 | USB_DEVICE(0x0525, 0x1080), // NetChip ref design | ||
589 | .driver_info = (unsigned long) &net1080_info, | ||
590 | }, { | ||
591 | USB_DEVICE(0x06D0, 0x0622), // Laplink Gold | ||
592 | .driver_info = (unsigned long) &net1080_info, | ||
593 | }, | ||
594 | { }, // END | ||
595 | }; | ||
596 | MODULE_DEVICE_TABLE(usb, products); | ||
597 | |||
598 | static struct usb_driver net1080_driver = { | ||
599 | .owner = THIS_MODULE, | ||
600 | .name = "net1080", | ||
601 | .id_table = products, | ||
602 | .probe = usbnet_probe, | ||
603 | .disconnect = usbnet_disconnect, | ||
604 | .suspend = usbnet_suspend, | ||
605 | .resume = usbnet_resume, | ||
606 | }; | ||
607 | |||
608 | static int __init net1080_init(void) | ||
609 | { | ||
610 | return usb_register(&net1080_driver); | ||
611 | } | ||
612 | module_init(net1080_init); | ||
613 | |||
614 | static void __exit net1080_exit(void) | ||
615 | { | ||
616 | usb_deregister(&net1080_driver); | ||
617 | } | ||
618 | module_exit(net1080_exit); | ||
619 | |||
620 | MODULE_AUTHOR("David Brownell"); | ||
621 | MODULE_DESCRIPTION("NetChip 1080 based USB Host-to-Host Links"); | ||
622 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/net/usbnet.c b/drivers/usb/net/usbnet.c index 99a488140140..590bf31ae1f4 100644 --- a/drivers/usb/net/usbnet.c +++ b/drivers/usb/net/usbnet.c | |||
@@ -119,7 +119,6 @@ | |||
119 | # define DEBUG | 119 | # define DEBUG |
120 | #endif | 120 | #endif |
121 | #include <linux/module.h> | 121 | #include <linux/module.h> |
122 | #include <linux/kmod.h> | ||
123 | #include <linux/sched.h> | 122 | #include <linux/sched.h> |
124 | #include <linux/init.h> | 123 | #include <linux/init.h> |
125 | #include <linux/netdevice.h> | 124 | #include <linux/netdevice.h> |
@@ -128,10 +127,6 @@ | |||
128 | #include <linux/workqueue.h> | 127 | #include <linux/workqueue.h> |
129 | #include <linux/mii.h> | 128 | #include <linux/mii.h> |
130 | #include <linux/usb.h> | 129 | #include <linux/usb.h> |
131 | #include <linux/mm.h> | ||
132 | #include <linux/dma-mapping.h> | ||
133 | |||
134 | #include <asm/unaligned.h> | ||
135 | 130 | ||
136 | #include "usbnet.h" | 131 | #include "usbnet.h" |
137 | 132 | ||
@@ -1030,531 +1025,6 @@ static const struct driver_info genelink_info = { | |||
1030 | 1025 | ||
1031 | 1026 | ||
1032 | 1027 | ||
1033 | #ifdef CONFIG_USB_NET1080 | ||
1034 | #define HAVE_HARDWARE | ||
1035 | |||
1036 | /*------------------------------------------------------------------------- | ||
1037 | * | ||
1038 | * Netchip 1080 driver ... http://www.netchip.com | ||
1039 | * Used in LapLink cables | ||
1040 | * | ||
1041 | *-------------------------------------------------------------------------*/ | ||
1042 | |||
1043 | #define frame_errors data[1] | ||
1044 | |||
1045 | /* | ||
1046 | * NetChip framing of ethernet packets, supporting additional error | ||
1047 | * checks for links that may drop bulk packets from inside messages. | ||
1048 | * Odd USB length == always short read for last usb packet. | ||
1049 | * - nc_header | ||
1050 | * - Ethernet header (14 bytes) | ||
1051 | * - payload | ||
1052 | * - (optional padding byte, if needed so length becomes odd) | ||
1053 | * - nc_trailer | ||
1054 | * | ||
1055 | * This framing is to be avoided for non-NetChip devices. | ||
1056 | */ | ||
1057 | |||
1058 | struct nc_header { // packed: | ||
1059 | __le16 hdr_len; // sizeof nc_header (LE, all) | ||
1060 | __le16 packet_len; // payload size (including ethhdr) | ||
1061 | __le16 packet_id; // detects dropped packets | ||
1062 | #define MIN_HEADER 6 | ||
1063 | |||
1064 | // all else is optional, and must start with: | ||
1065 | // u16 vendorId; // from usb-if | ||
1066 | // u16 productId; | ||
1067 | } __attribute__((__packed__)); | ||
1068 | |||
1069 | #define PAD_BYTE ((unsigned char)0xAC) | ||
1070 | |||
1071 | struct nc_trailer { | ||
1072 | __le16 packet_id; | ||
1073 | } __attribute__((__packed__)); | ||
1074 | |||
1075 | // packets may use FLAG_FRAMING_NC and optional pad | ||
1076 | #define FRAMED_SIZE(mtu) (sizeof (struct nc_header) \ | ||
1077 | + sizeof (struct ethhdr) \ | ||
1078 | + (mtu) \ | ||
1079 | + 1 \ | ||
1080 | + sizeof (struct nc_trailer)) | ||
1081 | |||
1082 | #define MIN_FRAMED FRAMED_SIZE(0) | ||
1083 | |||
1084 | /* packets _could_ be up to 64KB... */ | ||
1085 | #define NC_MAX_PACKET 32767 | ||
1086 | |||
1087 | |||
1088 | /* | ||
1089 | * Zero means no timeout; else, how long a 64 byte bulk packet may be queued | ||
1090 | * before the hardware drops it. If that's done, the driver will need to | ||
1091 | * frame network packets to guard against the dropped USB packets. The win32 | ||
1092 | * driver sets this for both sides of the link. | ||
1093 | */ | ||
1094 | #define NC_READ_TTL_MS ((u8)255) // ms | ||
1095 | |||
1096 | /* | ||
1097 | * We ignore most registers and EEPROM contents. | ||
1098 | */ | ||
1099 | #define REG_USBCTL ((u8)0x04) | ||
1100 | #define REG_TTL ((u8)0x10) | ||
1101 | #define REG_STATUS ((u8)0x11) | ||
1102 | |||
1103 | /* | ||
1104 | * Vendor specific requests to read/write data | ||
1105 | */ | ||
1106 | #define REQUEST_REGISTER ((u8)0x10) | ||
1107 | #define REQUEST_EEPROM ((u8)0x11) | ||
1108 | |||
1109 | static int | ||
1110 | nc_vendor_read (struct usbnet *dev, u8 req, u8 regnum, u16 *retval_ptr) | ||
1111 | { | ||
1112 | int status = usb_control_msg (dev->udev, | ||
1113 | usb_rcvctrlpipe (dev->udev, 0), | ||
1114 | req, | ||
1115 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
1116 | 0, regnum, | ||
1117 | retval_ptr, sizeof *retval_ptr, | ||
1118 | CONTROL_TIMEOUT_MS); | ||
1119 | if (status > 0) | ||
1120 | status = 0; | ||
1121 | if (!status) | ||
1122 | le16_to_cpus (retval_ptr); | ||
1123 | return status; | ||
1124 | } | ||
1125 | |||
1126 | static inline int | ||
1127 | nc_register_read (struct usbnet *dev, u8 regnum, u16 *retval_ptr) | ||
1128 | { | ||
1129 | return nc_vendor_read (dev, REQUEST_REGISTER, regnum, retval_ptr); | ||
1130 | } | ||
1131 | |||
1132 | // no retval ... can become async, usable in_interrupt() | ||
1133 | static void | ||
1134 | nc_vendor_write (struct usbnet *dev, u8 req, u8 regnum, u16 value) | ||
1135 | { | ||
1136 | usb_control_msg (dev->udev, | ||
1137 | usb_sndctrlpipe (dev->udev, 0), | ||
1138 | req, | ||
1139 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
1140 | value, regnum, | ||
1141 | NULL, 0, // data is in setup packet | ||
1142 | CONTROL_TIMEOUT_MS); | ||
1143 | } | ||
1144 | |||
1145 | static inline void | ||
1146 | nc_register_write (struct usbnet *dev, u8 regnum, u16 value) | ||
1147 | { | ||
1148 | nc_vendor_write (dev, REQUEST_REGISTER, regnum, value); | ||
1149 | } | ||
1150 | |||
1151 | |||
1152 | #if 0 | ||
1153 | static void nc_dump_registers (struct usbnet *dev) | ||
1154 | { | ||
1155 | u8 reg; | ||
1156 | u16 *vp = kmalloc (sizeof (u16)); | ||
1157 | |||
1158 | if (!vp) { | ||
1159 | dbg ("no memory?"); | ||
1160 | return; | ||
1161 | } | ||
1162 | |||
1163 | dbg ("%s registers:", dev->net->name); | ||
1164 | for (reg = 0; reg < 0x20; reg++) { | ||
1165 | int retval; | ||
1166 | |||
1167 | // reading some registers is trouble | ||
1168 | if (reg >= 0x08 && reg <= 0xf) | ||
1169 | continue; | ||
1170 | if (reg >= 0x12 && reg <= 0x1e) | ||
1171 | continue; | ||
1172 | |||
1173 | retval = nc_register_read (dev, reg, vp); | ||
1174 | if (retval < 0) | ||
1175 | dbg ("%s reg [0x%x] ==> error %d", | ||
1176 | dev->net->name, reg, retval); | ||
1177 | else | ||
1178 | dbg ("%s reg [0x%x] = 0x%x", | ||
1179 | dev->net->name, reg, *vp); | ||
1180 | } | ||
1181 | kfree (vp); | ||
1182 | } | ||
1183 | #endif | ||
1184 | |||
1185 | |||
1186 | /*-------------------------------------------------------------------------*/ | ||
1187 | |||
1188 | /* | ||
1189 | * Control register | ||
1190 | */ | ||
1191 | |||
1192 | #define USBCTL_WRITABLE_MASK 0x1f0f | ||
1193 | // bits 15-13 reserved, r/o | ||
1194 | #define USBCTL_ENABLE_LANG (1 << 12) | ||
1195 | #define USBCTL_ENABLE_MFGR (1 << 11) | ||
1196 | #define USBCTL_ENABLE_PROD (1 << 10) | ||
1197 | #define USBCTL_ENABLE_SERIAL (1 << 9) | ||
1198 | #define USBCTL_ENABLE_DEFAULTS (1 << 8) | ||
1199 | // bits 7-4 reserved, r/o | ||
1200 | #define USBCTL_FLUSH_OTHER (1 << 3) | ||
1201 | #define USBCTL_FLUSH_THIS (1 << 2) | ||
1202 | #define USBCTL_DISCONN_OTHER (1 << 1) | ||
1203 | #define USBCTL_DISCONN_THIS (1 << 0) | ||
1204 | |||
1205 | static inline void nc_dump_usbctl (struct usbnet *dev, u16 usbctl) | ||
1206 | { | ||
1207 | if (!netif_msg_link (dev)) | ||
1208 | return; | ||
1209 | devdbg (dev, "net1080 %s-%s usbctl 0x%x:%s%s%s%s%s;" | ||
1210 | " this%s%s;" | ||
1211 | " other%s%s; r/o 0x%x", | ||
1212 | dev->udev->bus->bus_name, dev->udev->devpath, | ||
1213 | usbctl, | ||
1214 | (usbctl & USBCTL_ENABLE_LANG) ? " lang" : "", | ||
1215 | (usbctl & USBCTL_ENABLE_MFGR) ? " mfgr" : "", | ||
1216 | (usbctl & USBCTL_ENABLE_PROD) ? " prod" : "", | ||
1217 | (usbctl & USBCTL_ENABLE_SERIAL) ? " serial" : "", | ||
1218 | (usbctl & USBCTL_ENABLE_DEFAULTS) ? " defaults" : "", | ||
1219 | |||
1220 | (usbctl & USBCTL_FLUSH_OTHER) ? " FLUSH" : "", | ||
1221 | (usbctl & USBCTL_DISCONN_OTHER) ? " DIS" : "", | ||
1222 | (usbctl & USBCTL_FLUSH_THIS) ? " FLUSH" : "", | ||
1223 | (usbctl & USBCTL_DISCONN_THIS) ? " DIS" : "", | ||
1224 | usbctl & ~USBCTL_WRITABLE_MASK | ||
1225 | ); | ||
1226 | } | ||
1227 | |||
1228 | /*-------------------------------------------------------------------------*/ | ||
1229 | |||
1230 | /* | ||
1231 | * Status register | ||
1232 | */ | ||
1233 | |||
1234 | #define STATUS_PORT_A (1 << 15) | ||
1235 | |||
1236 | #define STATUS_CONN_OTHER (1 << 14) | ||
1237 | #define STATUS_SUSPEND_OTHER (1 << 13) | ||
1238 | #define STATUS_MAILBOX_OTHER (1 << 12) | ||
1239 | #define STATUS_PACKETS_OTHER(n) (((n) >> 8) && 0x03) | ||
1240 | |||
1241 | #define STATUS_CONN_THIS (1 << 6) | ||
1242 | #define STATUS_SUSPEND_THIS (1 << 5) | ||
1243 | #define STATUS_MAILBOX_THIS (1 << 4) | ||
1244 | #define STATUS_PACKETS_THIS(n) (((n) >> 0) && 0x03) | ||
1245 | |||
1246 | #define STATUS_UNSPEC_MASK 0x0c8c | ||
1247 | #define STATUS_NOISE_MASK ((u16)~(0x0303|STATUS_UNSPEC_MASK)) | ||
1248 | |||
1249 | |||
1250 | static inline void nc_dump_status (struct usbnet *dev, u16 status) | ||
1251 | { | ||
1252 | if (!netif_msg_link (dev)) | ||
1253 | return; | ||
1254 | devdbg (dev, "net1080 %s-%s status 0x%x:" | ||
1255 | " this (%c) PKT=%d%s%s%s;" | ||
1256 | " other PKT=%d%s%s%s; unspec 0x%x", | ||
1257 | dev->udev->bus->bus_name, dev->udev->devpath, | ||
1258 | status, | ||
1259 | |||
1260 | // XXX the packet counts don't seem right | ||
1261 | // (1 at reset, not 0); maybe UNSPEC too | ||
1262 | |||
1263 | (status & STATUS_PORT_A) ? 'A' : 'B', | ||
1264 | STATUS_PACKETS_THIS (status), | ||
1265 | (status & STATUS_CONN_THIS) ? " CON" : "", | ||
1266 | (status & STATUS_SUSPEND_THIS) ? " SUS" : "", | ||
1267 | (status & STATUS_MAILBOX_THIS) ? " MBOX" : "", | ||
1268 | |||
1269 | STATUS_PACKETS_OTHER (status), | ||
1270 | (status & STATUS_CONN_OTHER) ? " CON" : "", | ||
1271 | (status & STATUS_SUSPEND_OTHER) ? " SUS" : "", | ||
1272 | (status & STATUS_MAILBOX_OTHER) ? " MBOX" : "", | ||
1273 | |||
1274 | status & STATUS_UNSPEC_MASK | ||
1275 | ); | ||
1276 | } | ||
1277 | |||
1278 | /*-------------------------------------------------------------------------*/ | ||
1279 | |||
1280 | /* | ||
1281 | * TTL register | ||
1282 | */ | ||
1283 | |||
1284 | #define TTL_THIS(ttl) (0x00ff & ttl) | ||
1285 | #define TTL_OTHER(ttl) (0x00ff & (ttl >> 8)) | ||
1286 | #define MK_TTL(this,other) ((u16)(((other)<<8)|(0x00ff&(this)))) | ||
1287 | |||
1288 | static inline void nc_dump_ttl (struct usbnet *dev, u16 ttl) | ||
1289 | { | ||
1290 | if (netif_msg_link (dev)) | ||
1291 | devdbg (dev, "net1080 %s-%s ttl 0x%x this = %d, other = %d", | ||
1292 | dev->udev->bus->bus_name, dev->udev->devpath, | ||
1293 | ttl, TTL_THIS (ttl), TTL_OTHER (ttl)); | ||
1294 | } | ||
1295 | |||
1296 | /*-------------------------------------------------------------------------*/ | ||
1297 | |||
1298 | static int net1080_reset (struct usbnet *dev) | ||
1299 | { | ||
1300 | u16 usbctl, status, ttl; | ||
1301 | u16 *vp = kmalloc (sizeof (u16), GFP_KERNEL); | ||
1302 | int retval; | ||
1303 | |||
1304 | if (!vp) | ||
1305 | return -ENOMEM; | ||
1306 | |||
1307 | // nc_dump_registers (dev); | ||
1308 | |||
1309 | if ((retval = nc_register_read (dev, REG_STATUS, vp)) < 0) { | ||
1310 | dbg ("can't read %s-%s status: %d", | ||
1311 | dev->udev->bus->bus_name, dev->udev->devpath, retval); | ||
1312 | goto done; | ||
1313 | } | ||
1314 | status = *vp; | ||
1315 | nc_dump_status (dev, status); | ||
1316 | |||
1317 | if ((retval = nc_register_read (dev, REG_USBCTL, vp)) < 0) { | ||
1318 | dbg ("can't read USBCTL, %d", retval); | ||
1319 | goto done; | ||
1320 | } | ||
1321 | usbctl = *vp; | ||
1322 | nc_dump_usbctl (dev, usbctl); | ||
1323 | |||
1324 | nc_register_write (dev, REG_USBCTL, | ||
1325 | USBCTL_FLUSH_THIS | USBCTL_FLUSH_OTHER); | ||
1326 | |||
1327 | if ((retval = nc_register_read (dev, REG_TTL, vp)) < 0) { | ||
1328 | dbg ("can't read TTL, %d", retval); | ||
1329 | goto done; | ||
1330 | } | ||
1331 | ttl = *vp; | ||
1332 | // nc_dump_ttl (dev, ttl); | ||
1333 | |||
1334 | nc_register_write (dev, REG_TTL, | ||
1335 | MK_TTL (NC_READ_TTL_MS, TTL_OTHER (ttl)) ); | ||
1336 | dbg ("%s: assigned TTL, %d ms", dev->net->name, NC_READ_TTL_MS); | ||
1337 | |||
1338 | if (netif_msg_link (dev)) | ||
1339 | devinfo (dev, "port %c, peer %sconnected", | ||
1340 | (status & STATUS_PORT_A) ? 'A' : 'B', | ||
1341 | (status & STATUS_CONN_OTHER) ? "" : "dis" | ||
1342 | ); | ||
1343 | retval = 0; | ||
1344 | |||
1345 | done: | ||
1346 | kfree (vp); | ||
1347 | return retval; | ||
1348 | } | ||
1349 | |||
1350 | static int net1080_check_connect (struct usbnet *dev) | ||
1351 | { | ||
1352 | int retval; | ||
1353 | u16 status; | ||
1354 | u16 *vp = kmalloc (sizeof (u16), GFP_KERNEL); | ||
1355 | |||
1356 | if (!vp) | ||
1357 | return -ENOMEM; | ||
1358 | retval = nc_register_read (dev, REG_STATUS, vp); | ||
1359 | status = *vp; | ||
1360 | kfree (vp); | ||
1361 | if (retval != 0) { | ||
1362 | dbg ("%s net1080_check_conn read - %d", dev->net->name, retval); | ||
1363 | return retval; | ||
1364 | } | ||
1365 | if ((status & STATUS_CONN_OTHER) != STATUS_CONN_OTHER) | ||
1366 | return -ENOLINK; | ||
1367 | return 0; | ||
1368 | } | ||
1369 | |||
1370 | static void nc_flush_complete (struct urb *urb, struct pt_regs *regs) | ||
1371 | { | ||
1372 | kfree (urb->context); | ||
1373 | usb_free_urb(urb); | ||
1374 | } | ||
1375 | |||
1376 | static void nc_ensure_sync (struct usbnet *dev) | ||
1377 | { | ||
1378 | dev->frame_errors++; | ||
1379 | if (dev->frame_errors > 5) { | ||
1380 | struct urb *urb; | ||
1381 | struct usb_ctrlrequest *req; | ||
1382 | int status; | ||
1383 | |||
1384 | /* Send a flush */ | ||
1385 | urb = usb_alloc_urb (0, SLAB_ATOMIC); | ||
1386 | if (!urb) | ||
1387 | return; | ||
1388 | |||
1389 | req = kmalloc (sizeof *req, GFP_ATOMIC); | ||
1390 | if (!req) { | ||
1391 | usb_free_urb (urb); | ||
1392 | return; | ||
1393 | } | ||
1394 | |||
1395 | req->bRequestType = USB_DIR_OUT | ||
1396 | | USB_TYPE_VENDOR | ||
1397 | | USB_RECIP_DEVICE; | ||
1398 | req->bRequest = REQUEST_REGISTER; | ||
1399 | req->wValue = cpu_to_le16 (USBCTL_FLUSH_THIS | ||
1400 | | USBCTL_FLUSH_OTHER); | ||
1401 | req->wIndex = cpu_to_le16 (REG_USBCTL); | ||
1402 | req->wLength = cpu_to_le16 (0); | ||
1403 | |||
1404 | /* queue an async control request, we don't need | ||
1405 | * to do anything when it finishes except clean up. | ||
1406 | */ | ||
1407 | usb_fill_control_urb (urb, dev->udev, | ||
1408 | usb_sndctrlpipe (dev->udev, 0), | ||
1409 | (unsigned char *) req, | ||
1410 | NULL, 0, | ||
1411 | nc_flush_complete, req); | ||
1412 | status = usb_submit_urb (urb, GFP_ATOMIC); | ||
1413 | if (status) { | ||
1414 | kfree (req); | ||
1415 | usb_free_urb (urb); | ||
1416 | return; | ||
1417 | } | ||
1418 | |||
1419 | if (netif_msg_rx_err (dev)) | ||
1420 | devdbg (dev, "flush net1080; too many framing errors"); | ||
1421 | dev->frame_errors = 0; | ||
1422 | } | ||
1423 | } | ||
1424 | |||
1425 | static int net1080_rx_fixup (struct usbnet *dev, struct sk_buff *skb) | ||
1426 | { | ||
1427 | struct nc_header *header; | ||
1428 | struct net_device *net = dev->net; | ||
1429 | struct nc_trailer *trailer; | ||
1430 | u16 hdr_len, packet_len; | ||
1431 | |||
1432 | if (!(skb->len & 0x01)) { | ||
1433 | dev->stats.rx_frame_errors++; | ||
1434 | dbg ("rx framesize %d range %d..%d mtu %d", skb->len, | ||
1435 | net->hard_header_len, dev->hard_mtu, net->mtu); | ||
1436 | nc_ensure_sync (dev); | ||
1437 | return 0; | ||
1438 | } | ||
1439 | |||
1440 | header = (struct nc_header *) skb->data; | ||
1441 | hdr_len = le16_to_cpup (&header->hdr_len); | ||
1442 | packet_len = le16_to_cpup (&header->packet_len); | ||
1443 | if (FRAMED_SIZE (packet_len) > NC_MAX_PACKET) { | ||
1444 | dev->stats.rx_frame_errors++; | ||
1445 | dbg ("packet too big, %d", packet_len); | ||
1446 | nc_ensure_sync (dev); | ||
1447 | return 0; | ||
1448 | } else if (hdr_len < MIN_HEADER) { | ||
1449 | dev->stats.rx_frame_errors++; | ||
1450 | dbg ("header too short, %d", hdr_len); | ||
1451 | nc_ensure_sync (dev); | ||
1452 | return 0; | ||
1453 | } else if (hdr_len > MIN_HEADER) { | ||
1454 | // out of band data for us? | ||
1455 | dbg ("header OOB, %d bytes", hdr_len - MIN_HEADER); | ||
1456 | nc_ensure_sync (dev); | ||
1457 | // switch (vendor/product ids) { ... } | ||
1458 | } | ||
1459 | skb_pull (skb, hdr_len); | ||
1460 | |||
1461 | trailer = (struct nc_trailer *) | ||
1462 | (skb->data + skb->len - sizeof *trailer); | ||
1463 | skb_trim (skb, skb->len - sizeof *trailer); | ||
1464 | |||
1465 | if ((packet_len & 0x01) == 0) { | ||
1466 | if (skb->data [packet_len] != PAD_BYTE) { | ||
1467 | dev->stats.rx_frame_errors++; | ||
1468 | dbg ("bad pad"); | ||
1469 | return 0; | ||
1470 | } | ||
1471 | skb_trim (skb, skb->len - 1); | ||
1472 | } | ||
1473 | if (skb->len != packet_len) { | ||
1474 | dev->stats.rx_frame_errors++; | ||
1475 | dbg ("bad packet len %d (expected %d)", | ||
1476 | skb->len, packet_len); | ||
1477 | nc_ensure_sync (dev); | ||
1478 | return 0; | ||
1479 | } | ||
1480 | if (header->packet_id != get_unaligned (&trailer->packet_id)) { | ||
1481 | dev->stats.rx_fifo_errors++; | ||
1482 | dbg ("(2+ dropped) rx packet_id mismatch 0x%x 0x%x", | ||
1483 | le16_to_cpu (header->packet_id), | ||
1484 | le16_to_cpu (trailer->packet_id)); | ||
1485 | return 0; | ||
1486 | } | ||
1487 | #if 0 | ||
1488 | devdbg (dev, "frame <rx h %d p %d id %d", header->hdr_len, | ||
1489 | header->packet_len, header->packet_id); | ||
1490 | #endif | ||
1491 | dev->frame_errors = 0; | ||
1492 | return 1; | ||
1493 | } | ||
1494 | |||
1495 | static struct sk_buff * | ||
1496 | net1080_tx_fixup (struct usbnet *dev, struct sk_buff *skb, unsigned flags) | ||
1497 | { | ||
1498 | int padlen; | ||
1499 | struct sk_buff *skb2; | ||
1500 | |||
1501 | padlen = ((skb->len + sizeof (struct nc_header) | ||
1502 | + sizeof (struct nc_trailer)) & 0x01) ? 0 : 1; | ||
1503 | if (!skb_cloned (skb)) { | ||
1504 | int headroom = skb_headroom (skb); | ||
1505 | int tailroom = skb_tailroom (skb); | ||
1506 | |||
1507 | if ((padlen + sizeof (struct nc_trailer)) <= tailroom | ||
1508 | && sizeof (struct nc_header) <= headroom) | ||
1509 | /* There's enough head and tail room */ | ||
1510 | return skb; | ||
1511 | |||
1512 | if ((sizeof (struct nc_header) + padlen | ||
1513 | + sizeof (struct nc_trailer)) < | ||
1514 | (headroom + tailroom)) { | ||
1515 | /* There's enough total room, so just readjust */ | ||
1516 | skb->data = memmove (skb->head | ||
1517 | + sizeof (struct nc_header), | ||
1518 | skb->data, skb->len); | ||
1519 | skb->tail = skb->data + skb->len; | ||
1520 | return skb; | ||
1521 | } | ||
1522 | } | ||
1523 | |||
1524 | /* Create a new skb to use with the correct size */ | ||
1525 | skb2 = skb_copy_expand (skb, | ||
1526 | sizeof (struct nc_header), | ||
1527 | sizeof (struct nc_trailer) + padlen, | ||
1528 | flags); | ||
1529 | dev_kfree_skb_any (skb); | ||
1530 | return skb2; | ||
1531 | } | ||
1532 | |||
1533 | static int net1080_bind (struct usbnet *dev, struct usb_interface *intf) | ||
1534 | { | ||
1535 | unsigned extra = sizeof (struct nc_header) | ||
1536 | + 1 | ||
1537 | + sizeof (struct nc_trailer); | ||
1538 | |||
1539 | dev->net->hard_header_len += extra; | ||
1540 | dev->hard_mtu = NC_MAX_PACKET; | ||
1541 | return 0; | ||
1542 | } | ||
1543 | |||
1544 | static const struct driver_info net1080_info = { | ||
1545 | .description = "NetChip TurboCONNECT", | ||
1546 | .flags = FLAG_FRAMING_NC, | ||
1547 | .bind = net1080_bind, | ||
1548 | .reset = net1080_reset, | ||
1549 | .check_connect = net1080_check_connect, | ||
1550 | .rx_fixup = net1080_rx_fixup, | ||
1551 | .tx_fixup = net1080_tx_fixup, | ||
1552 | }; | ||
1553 | |||
1554 | #endif /* CONFIG_USB_NET1080 */ | ||
1555 | |||
1556 | |||
1557 | |||
1558 | #ifdef CONFIG_USB_PL2301 | 1028 | #ifdef CONFIG_USB_PL2301 |
1559 | #define HAVE_HARDWARE | 1029 | #define HAVE_HARDWARE |
1560 | 1030 | ||
@@ -2486,10 +1956,6 @@ static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net) | |||
2486 | struct skb_data *entry; | 1956 | struct skb_data *entry; |
2487 | struct driver_info *info = dev->driver_info; | 1957 | struct driver_info *info = dev->driver_info; |
2488 | unsigned long flags; | 1958 | unsigned long flags; |
2489 | #ifdef CONFIG_USB_NET1080 | ||
2490 | struct nc_header *header = NULL; | ||
2491 | struct nc_trailer *trailer = NULL; | ||
2492 | #endif /* CONFIG_USB_NET1080 */ | ||
2493 | 1959 | ||
2494 | // some devices want funky USB-level framing, for | 1960 | // some devices want funky USB-level framing, for |
2495 | // win32 driver (usually) and/or hardware quirks | 1961 | // win32 driver (usually) and/or hardware quirks |
@@ -2515,21 +1981,6 @@ static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net) | |||
2515 | entry->state = tx_start; | 1981 | entry->state = tx_start; |
2516 | entry->length = length; | 1982 | entry->length = length; |
2517 | 1983 | ||
2518 | // FIXME: reorganize a bit, so that fixup() fills out NetChip | ||
2519 | // framing too. (Packet ID update needs the spinlock...) | ||
2520 | // [ BETTER: we already own net->xmit_lock, that's enough ] | ||
2521 | |||
2522 | #ifdef CONFIG_USB_NET1080 | ||
2523 | if (info->flags & FLAG_FRAMING_NC) { | ||
2524 | header = (struct nc_header *) skb_push (skb, sizeof *header); | ||
2525 | header->hdr_len = cpu_to_le16 (sizeof (*header)); | ||
2526 | header->packet_len = cpu_to_le16 (length); | ||
2527 | if (!((skb->len + sizeof *trailer) & 0x01)) | ||
2528 | *skb_put (skb, 1) = PAD_BYTE; | ||
2529 | trailer = (struct nc_trailer *) skb_put (skb, sizeof *trailer); | ||
2530 | } | ||
2531 | #endif /* CONFIG_USB_NET1080 */ | ||
2532 | |||
2533 | usb_fill_bulk_urb (urb, dev->udev, dev->out, | 1984 | usb_fill_bulk_urb (urb, dev->udev, dev->out, |
2534 | skb->data, skb->len, tx_complete, skb); | 1985 | skb->data, skb->len, tx_complete, skb); |
2535 | 1986 | ||
@@ -2544,18 +1995,6 @@ static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net) | |||
2544 | 1995 | ||
2545 | spin_lock_irqsave (&dev->txq.lock, flags); | 1996 | spin_lock_irqsave (&dev->txq.lock, flags); |
2546 | 1997 | ||
2547 | #ifdef CONFIG_USB_NET1080 | ||
2548 | if (info->flags & FLAG_FRAMING_NC) { | ||
2549 | header->packet_id = cpu_to_le16 ((u16)dev->xid++); | ||
2550 | put_unaligned (header->packet_id, &trailer->packet_id); | ||
2551 | #if 0 | ||
2552 | devdbg (dev, "frame >tx h %d p %d id %d", | ||
2553 | header->hdr_len, header->packet_len, | ||
2554 | header->packet_id); | ||
2555 | #endif | ||
2556 | } | ||
2557 | #endif /* CONFIG_USB_NET1080 */ | ||
2558 | |||
2559 | switch ((retval = usb_submit_urb (urb, GFP_ATOMIC))) { | 1998 | switch ((retval = usb_submit_urb (urb, GFP_ATOMIC))) { |
2560 | case -EPIPE: | 1999 | case -EPIPE: |
2561 | netif_stop_queue (net); | 2000 | netif_stop_queue (net); |
@@ -2894,16 +2333,6 @@ static const struct usb_device_id products [] = { | |||
2894 | */ | 2333 | */ |
2895 | #endif | 2334 | #endif |
2896 | 2335 | ||
2897 | #ifdef CONFIG_USB_NET1080 | ||
2898 | { | ||
2899 | USB_DEVICE (0x0525, 0x1080), // NetChip ref design | ||
2900 | .driver_info = (unsigned long) &net1080_info, | ||
2901 | }, { | ||
2902 | USB_DEVICE (0x06D0, 0x0622), // Laplink Gold | ||
2903 | .driver_info = (unsigned long) &net1080_info, | ||
2904 | }, | ||
2905 | #endif | ||
2906 | |||
2907 | #ifdef CONFIG_USB_PL2301 | 2336 | #ifdef CONFIG_USB_PL2301 |
2908 | { | 2337 | { |
2909 | USB_DEVICE (0x067b, 0x0000), // PL-2301 | 2338 | USB_DEVICE (0x067b, 0x0000), // PL-2301 |