Commit | Line | Data |
---|---|---|
904813cd DB |
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 | ||
904813cd | 23 | #include <linux/module.h> |
904813cd DB |
24 | #include <linux/init.h> |
25 | #include <linux/netdevice.h> | |
26 | #include <linux/etherdevice.h> | |
27 | #include <linux/ethtool.h> | |
28 | #include <linux/workqueue.h> | |
29 | #include <linux/mii.h> | |
30 | #include <linux/usb.h> | |
3692e94f | 31 | #include <linux/usb/usbnet.h> |
904813cd DB |
32 | |
33 | #include <asm/unaligned.h> | |
34 | ||
904813cd DB |
35 | |
36 | /* | |
37 | * Netchip 1080 driver ... http://www.netchip.com | |
38 | * (Sept 2004: End-of-life announcement has been sent.) | |
39 | * Used in (some) LapLink cables | |
40 | */ | |
41 | ||
42 | #define frame_errors data[1] | |
43 | ||
44 | /* | |
45 | * NetChip framing of ethernet packets, supporting additional error | |
46 | * checks for links that may drop bulk packets from inside messages. | |
47 | * Odd USB length == always short read for last usb packet. | |
48 | * - nc_header | |
49 | * - Ethernet header (14 bytes) | |
50 | * - payload | |
51 | * - (optional padding byte, if needed so length becomes odd) | |
52 | * - nc_trailer | |
53 | * | |
54 | * This framing is to be avoided for non-NetChip devices. | |
55 | */ | |
56 | ||
57 | struct nc_header { // packed: | |
58 | __le16 hdr_len; // sizeof nc_header (LE, all) | |
59 | __le16 packet_len; // payload size (including ethhdr) | |
60 | __le16 packet_id; // detects dropped packets | |
61 | #define MIN_HEADER 6 | |
62 | ||
63 | // all else is optional, and must start with: | |
64 | // __le16 vendorId; // from usb-if | |
65 | // __le16 productId; | |
66 | } __attribute__((__packed__)); | |
67 | ||
68 | #define PAD_BYTE ((unsigned char)0xAC) | |
69 | ||
70 | struct nc_trailer { | |
71 | __le16 packet_id; | |
72 | } __attribute__((__packed__)); | |
73 | ||
74 | // packets may use FLAG_FRAMING_NC and optional pad | |
75 | #define FRAMED_SIZE(mtu) (sizeof (struct nc_header) \ | |
76 | + sizeof (struct ethhdr) \ | |
77 | + (mtu) \ | |
78 | + 1 \ | |
79 | + sizeof (struct nc_trailer)) | |
80 | ||
81 | #define MIN_FRAMED FRAMED_SIZE(0) | |
82 | ||
83 | /* packets _could_ be up to 64KB... */ | |
84 | #define NC_MAX_PACKET 32767 | |
85 | ||
86 | ||
87 | /* | |
88 | * Zero means no timeout; else, how long a 64 byte bulk packet may be queued | |
89 | * before the hardware drops it. If that's done, the driver will need to | |
90 | * frame network packets to guard against the dropped USB packets. The win32 | |
91 | * driver sets this for both sides of the link. | |
92 | */ | |
93 | #define NC_READ_TTL_MS ((u8)255) // ms | |
94 | ||
95 | /* | |
96 | * We ignore most registers and EEPROM contents. | |
97 | */ | |
98 | #define REG_USBCTL ((u8)0x04) | |
99 | #define REG_TTL ((u8)0x10) | |
100 | #define REG_STATUS ((u8)0x11) | |
101 | ||
102 | /* | |
103 | * Vendor specific requests to read/write data | |
104 | */ | |
105 | #define REQUEST_REGISTER ((u8)0x10) | |
106 | #define REQUEST_EEPROM ((u8)0x11) | |
107 | ||
108 | static int | |
109 | nc_vendor_read(struct usbnet *dev, u8 req, u8 regnum, u16 *retval_ptr) | |
110 | { | |
111 | int status = usb_control_msg(dev->udev, | |
112 | usb_rcvctrlpipe(dev->udev, 0), | |
113 | req, | |
114 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | |
115 | 0, regnum, | |
116 | retval_ptr, sizeof *retval_ptr, | |
117 | USB_CTRL_GET_TIMEOUT); | |
118 | if (status > 0) | |
119 | status = 0; | |
120 | if (!status) | |
121 | le16_to_cpus(retval_ptr); | |
122 | return status; | |
123 | } | |
124 | ||
125 | static inline int | |
126 | nc_register_read(struct usbnet *dev, u8 regnum, u16 *retval_ptr) | |
127 | { | |
128 | return nc_vendor_read(dev, REQUEST_REGISTER, regnum, retval_ptr); | |
129 | } | |
130 | ||
131 | // no retval ... can become async, usable in_interrupt() | |
132 | static void | |
133 | nc_vendor_write(struct usbnet *dev, u8 req, u8 regnum, u16 value) | |
134 | { | |
135 | usb_control_msg(dev->udev, | |
136 | usb_sndctrlpipe(dev->udev, 0), | |
137 | req, | |
138 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | |
139 | value, regnum, | |
140 | NULL, 0, // data is in setup packet | |
141 | USB_CTRL_SET_TIMEOUT); | |
142 | } | |
143 | ||
144 | static inline void | |
145 | nc_register_write(struct usbnet *dev, u8 regnum, u16 value) | |
146 | { | |
147 | nc_vendor_write(dev, REQUEST_REGISTER, regnum, value); | |
148 | } | |
149 | ||
150 | ||
151 | #if 0 | |
152 | static void nc_dump_registers(struct usbnet *dev) | |
153 | { | |
154 | u8 reg; | |
155 | u16 *vp = kmalloc(sizeof (u16)); | |
156 | ||
157 | if (!vp) { | |
158 | dbg("no memory?"); | |
159 | return; | |
160 | } | |
161 | ||
162 | dbg("%s registers:", dev->net->name); | |
163 | for (reg = 0; reg < 0x20; reg++) { | |
164 | int retval; | |
165 | ||
166 | // reading some registers is trouble | |
167 | if (reg >= 0x08 && reg <= 0xf) | |
168 | continue; | |
169 | if (reg >= 0x12 && reg <= 0x1e) | |
170 | continue; | |
171 | ||
172 | retval = nc_register_read(dev, reg, vp); | |
173 | if (retval < 0) | |
174 | dbg("%s reg [0x%x] ==> error %d", | |
175 | dev->net->name, reg, retval); | |
176 | else | |
177 | dbg("%s reg [0x%x] = 0x%x", | |
178 | dev->net->name, reg, *vp); | |
179 | } | |
180 | kfree(vp); | |
181 | } | |
182 | #endif | |
183 | ||
184 | ||
185 | /*-------------------------------------------------------------------------*/ | |
186 | ||
187 | /* | |
188 | * Control register | |
189 | */ | |
190 | ||
191 | #define USBCTL_WRITABLE_MASK 0x1f0f | |
192 | // bits 15-13 reserved, r/o | |
193 | #define USBCTL_ENABLE_LANG (1 << 12) | |
194 | #define USBCTL_ENABLE_MFGR (1 << 11) | |
195 | #define USBCTL_ENABLE_PROD (1 << 10) | |
196 | #define USBCTL_ENABLE_SERIAL (1 << 9) | |
197 | #define USBCTL_ENABLE_DEFAULTS (1 << 8) | |
198 | // bits 7-4 reserved, r/o | |
199 | #define USBCTL_FLUSH_OTHER (1 << 3) | |
200 | #define USBCTL_FLUSH_THIS (1 << 2) | |
201 | #define USBCTL_DISCONN_OTHER (1 << 1) | |
202 | #define USBCTL_DISCONN_THIS (1 << 0) | |
203 | ||
204 | static inline void nc_dump_usbctl(struct usbnet *dev, u16 usbctl) | |
205 | { | |
206 | if (!netif_msg_link(dev)) | |
207 | return; | |
60b86755 JP |
208 | netdev_dbg(dev->net, "net1080 %s-%s usbctl 0x%x:%s%s%s%s%s;" |
209 | " this%s%s;" | |
210 | " other%s%s; r/o 0x%x\n", | |
211 | dev->udev->bus->bus_name, dev->udev->devpath, | |
212 | usbctl, | |
213 | (usbctl & USBCTL_ENABLE_LANG) ? " lang" : "", | |
214 | (usbctl & USBCTL_ENABLE_MFGR) ? " mfgr" : "", | |
215 | (usbctl & USBCTL_ENABLE_PROD) ? " prod" : "", | |
216 | (usbctl & USBCTL_ENABLE_SERIAL) ? " serial" : "", | |
217 | (usbctl & USBCTL_ENABLE_DEFAULTS) ? " defaults" : "", | |
218 | ||
219 | (usbctl & USBCTL_FLUSH_THIS) ? " FLUSH" : "", | |
220 | (usbctl & USBCTL_DISCONN_THIS) ? " DIS" : "", | |
221 | ||
222 | (usbctl & USBCTL_FLUSH_OTHER) ? " FLUSH" : "", | |
223 | (usbctl & USBCTL_DISCONN_OTHER) ? " DIS" : "", | |
224 | ||
225 | usbctl & ~USBCTL_WRITABLE_MASK); | |
904813cd DB |
226 | } |
227 | ||
228 | /*-------------------------------------------------------------------------*/ | |
229 | ||
230 | /* | |
231 | * Status register | |
232 | */ | |
233 | ||
234 | #define STATUS_PORT_A (1 << 15) | |
235 | ||
236 | #define STATUS_CONN_OTHER (1 << 14) | |
237 | #define STATUS_SUSPEND_OTHER (1 << 13) | |
238 | #define STATUS_MAILBOX_OTHER (1 << 12) | |
b4ee4a23 | 239 | #define STATUS_PACKETS_OTHER(n) (((n) >> 8) & 0x03) |
904813cd DB |
240 | |
241 | #define STATUS_CONN_THIS (1 << 6) | |
242 | #define STATUS_SUSPEND_THIS (1 << 5) | |
243 | #define STATUS_MAILBOX_THIS (1 << 4) | |
b4ee4a23 | 244 | #define STATUS_PACKETS_THIS(n) (((n) >> 0) & 0x03) |
904813cd DB |
245 | |
246 | #define STATUS_UNSPEC_MASK 0x0c8c | |
247 | #define STATUS_NOISE_MASK ((u16)~(0x0303|STATUS_UNSPEC_MASK)) | |
248 | ||
249 | ||
250 | static inline void nc_dump_status(struct usbnet *dev, u16 status) | |
251 | { | |
252 | if (!netif_msg_link(dev)) | |
253 | return; | |
60b86755 JP |
254 | netdev_dbg(dev->net, "net1080 %s-%s status 0x%x: this (%c) PKT=%d%s%s%s; other PKT=%d%s%s%s; unspec 0x%x\n", |
255 | dev->udev->bus->bus_name, dev->udev->devpath, | |
256 | status, | |
257 | ||
258 | // XXX the packet counts don't seem right | |
259 | // (1 at reset, not 0); maybe UNSPEC too | |
260 | ||
261 | (status & STATUS_PORT_A) ? 'A' : 'B', | |
262 | STATUS_PACKETS_THIS(status), | |
263 | (status & STATUS_CONN_THIS) ? " CON" : "", | |
264 | (status & STATUS_SUSPEND_THIS) ? " SUS" : "", | |
265 | (status & STATUS_MAILBOX_THIS) ? " MBOX" : "", | |
266 | ||
267 | STATUS_PACKETS_OTHER(status), | |
268 | (status & STATUS_CONN_OTHER) ? " CON" : "", | |
269 | (status & STATUS_SUSPEND_OTHER) ? " SUS" : "", | |
270 | (status & STATUS_MAILBOX_OTHER) ? " MBOX" : "", | |
271 | ||
272 | status & STATUS_UNSPEC_MASK); | |
904813cd DB |
273 | } |
274 | ||
275 | /*-------------------------------------------------------------------------*/ | |
276 | ||
277 | /* | |
278 | * TTL register | |
279 | */ | |
280 | ||
281 | #define TTL_THIS(ttl) (0x00ff & ttl) | |
282 | #define TTL_OTHER(ttl) (0x00ff & (ttl >> 8)) | |
283 | #define MK_TTL(this,other) ((u16)(((other)<<8)|(0x00ff&(this)))) | |
284 | ||
285 | static inline void nc_dump_ttl(struct usbnet *dev, u16 ttl) | |
286 | { | |
287 | if (netif_msg_link(dev)) | |
60b86755 JP |
288 | netdev_dbg(dev->net, "net1080 %s-%s ttl 0x%x this = %d, other = %d\n", |
289 | dev->udev->bus->bus_name, dev->udev->devpath, | |
290 | ttl, TTL_THIS(ttl), TTL_OTHER(ttl)); | |
904813cd DB |
291 | } |
292 | ||
293 | /*-------------------------------------------------------------------------*/ | |
294 | ||
295 | static int net1080_reset(struct usbnet *dev) | |
296 | { | |
297 | u16 usbctl, status, ttl; | |
298 | u16 *vp = kmalloc(sizeof (u16), GFP_KERNEL); | |
299 | int retval; | |
300 | ||
301 | if (!vp) | |
302 | return -ENOMEM; | |
303 | ||
304 | // nc_dump_registers(dev); | |
305 | ||
306 | if ((retval = nc_register_read(dev, REG_STATUS, vp)) < 0) { | |
307 | dbg("can't read %s-%s status: %d", | |
308 | dev->udev->bus->bus_name, dev->udev->devpath, retval); | |
309 | goto done; | |
310 | } | |
311 | status = *vp; | |
312 | nc_dump_status(dev, status); | |
313 | ||
314 | if ((retval = nc_register_read(dev, REG_USBCTL, vp)) < 0) { | |
315 | dbg("can't read USBCTL, %d", retval); | |
316 | goto done; | |
317 | } | |
318 | usbctl = *vp; | |
319 | nc_dump_usbctl(dev, usbctl); | |
320 | ||
321 | nc_register_write(dev, REG_USBCTL, | |
322 | USBCTL_FLUSH_THIS | USBCTL_FLUSH_OTHER); | |
323 | ||
324 | if ((retval = nc_register_read(dev, REG_TTL, vp)) < 0) { | |
325 | dbg("can't read TTL, %d", retval); | |
326 | goto done; | |
327 | } | |
328 | ttl = *vp; | |
329 | // nc_dump_ttl(dev, ttl); | |
330 | ||
331 | nc_register_write(dev, REG_TTL, | |
332 | MK_TTL(NC_READ_TTL_MS, TTL_OTHER(ttl)) ); | |
333 | dbg("%s: assigned TTL, %d ms", dev->net->name, NC_READ_TTL_MS); | |
334 | ||
335 | if (netif_msg_link(dev)) | |
60b86755 JP |
336 | netdev_info(dev->net, "port %c, peer %sconnected\n", |
337 | (status & STATUS_PORT_A) ? 'A' : 'B', | |
338 | (status & STATUS_CONN_OTHER) ? "" : "dis"); | |
904813cd DB |
339 | retval = 0; |
340 | ||
341 | done: | |
342 | kfree(vp); | |
343 | return retval; | |
344 | } | |
345 | ||
346 | static int net1080_check_connect(struct usbnet *dev) | |
347 | { | |
348 | int retval; | |
349 | u16 status; | |
350 | u16 *vp = kmalloc(sizeof (u16), GFP_KERNEL); | |
351 | ||
352 | if (!vp) | |
353 | return -ENOMEM; | |
354 | retval = nc_register_read(dev, REG_STATUS, vp); | |
355 | status = *vp; | |
356 | kfree(vp); | |
357 | if (retval != 0) { | |
358 | dbg("%s net1080_check_conn read - %d", dev->net->name, retval); | |
359 | return retval; | |
360 | } | |
361 | if ((status & STATUS_CONN_OTHER) != STATUS_CONN_OTHER) | |
362 | return -ENOLINK; | |
363 | return 0; | |
364 | } | |
365 | ||
7d12e780 | 366 | static void nc_flush_complete(struct urb *urb) |
904813cd DB |
367 | { |
368 | kfree(urb->context); | |
369 | usb_free_urb(urb); | |
370 | } | |
371 | ||
372 | static void nc_ensure_sync(struct usbnet *dev) | |
373 | { | |
374 | dev->frame_errors++; | |
375 | if (dev->frame_errors > 5) { | |
376 | struct urb *urb; | |
377 | struct usb_ctrlrequest *req; | |
378 | int status; | |
379 | ||
380 | /* Send a flush */ | |
54e6ecb2 | 381 | urb = usb_alloc_urb(0, GFP_ATOMIC); |
904813cd DB |
382 | if (!urb) |
383 | return; | |
384 | ||
385 | req = kmalloc(sizeof *req, GFP_ATOMIC); | |
386 | if (!req) { | |
387 | usb_free_urb(urb); | |
388 | return; | |
389 | } | |
390 | ||
391 | req->bRequestType = USB_DIR_OUT | |
392 | | USB_TYPE_VENDOR | |
393 | | USB_RECIP_DEVICE; | |
394 | req->bRequest = REQUEST_REGISTER; | |
395 | req->wValue = cpu_to_le16(USBCTL_FLUSH_THIS | |
396 | | USBCTL_FLUSH_OTHER); | |
397 | req->wIndex = cpu_to_le16(REG_USBCTL); | |
398 | req->wLength = cpu_to_le16(0); | |
399 | ||
400 | /* queue an async control request, we don't need | |
401 | * to do anything when it finishes except clean up. | |
402 | */ | |
403 | usb_fill_control_urb(urb, dev->udev, | |
404 | usb_sndctrlpipe(dev->udev, 0), | |
405 | (unsigned char *) req, | |
406 | NULL, 0, | |
407 | nc_flush_complete, req); | |
408 | status = usb_submit_urb(urb, GFP_ATOMIC); | |
409 | if (status) { | |
410 | kfree(req); | |
411 | usb_free_urb(urb); | |
412 | return; | |
413 | } | |
414 | ||
415 | if (netif_msg_rx_err(dev)) | |
60b86755 | 416 | netdev_dbg(dev->net, "flush net1080; too many framing errors\n"); |
904813cd DB |
417 | dev->frame_errors = 0; |
418 | } | |
419 | } | |
420 | ||
421 | static int net1080_rx_fixup(struct usbnet *dev, struct sk_buff *skb) | |
422 | { | |
423 | struct nc_header *header; | |
424 | struct nc_trailer *trailer; | |
425 | u16 hdr_len, packet_len; | |
426 | ||
427 | if (!(skb->len & 0x01)) { | |
428 | #ifdef DEBUG | |
429 | struct net_device *net = dev->net; | |
430 | dbg("rx framesize %d range %d..%d mtu %d", skb->len, | |
431 | net->hard_header_len, dev->hard_mtu, net->mtu); | |
432 | #endif | |
a22d2b36 | 433 | dev->net->stats.rx_frame_errors++; |
904813cd DB |
434 | nc_ensure_sync(dev); |
435 | return 0; | |
436 | } | |
437 | ||
438 | header = (struct nc_header *) skb->data; | |
439 | hdr_len = le16_to_cpup(&header->hdr_len); | |
440 | packet_len = le16_to_cpup(&header->packet_len); | |
441 | if (FRAMED_SIZE(packet_len) > NC_MAX_PACKET) { | |
a22d2b36 | 442 | dev->net->stats.rx_frame_errors++; |
904813cd DB |
443 | dbg("packet too big, %d", packet_len); |
444 | nc_ensure_sync(dev); | |
445 | return 0; | |
446 | } else if (hdr_len < MIN_HEADER) { | |
a22d2b36 | 447 | dev->net->stats.rx_frame_errors++; |
904813cd DB |
448 | dbg("header too short, %d", hdr_len); |
449 | nc_ensure_sync(dev); | |
450 | return 0; | |
451 | } else if (hdr_len > MIN_HEADER) { | |
452 | // out of band data for us? | |
453 | dbg("header OOB, %d bytes", hdr_len - MIN_HEADER); | |
454 | nc_ensure_sync(dev); | |
455 | // switch (vendor/product ids) { ... } | |
456 | } | |
457 | skb_pull(skb, hdr_len); | |
458 | ||
459 | trailer = (struct nc_trailer *) | |
460 | (skb->data + skb->len - sizeof *trailer); | |
461 | skb_trim(skb, skb->len - sizeof *trailer); | |
462 | ||
463 | if ((packet_len & 0x01) == 0) { | |
464 | if (skb->data [packet_len] != PAD_BYTE) { | |
a22d2b36 | 465 | dev->net->stats.rx_frame_errors++; |
904813cd DB |
466 | dbg("bad pad"); |
467 | return 0; | |
468 | } | |
469 | skb_trim(skb, skb->len - 1); | |
470 | } | |
471 | if (skb->len != packet_len) { | |
a22d2b36 | 472 | dev->net->stats.rx_frame_errors++; |
904813cd DB |
473 | dbg("bad packet len %d (expected %d)", |
474 | skb->len, packet_len); | |
475 | nc_ensure_sync(dev); | |
476 | return 0; | |
477 | } | |
478 | if (header->packet_id != get_unaligned(&trailer->packet_id)) { | |
a22d2b36 | 479 | dev->net->stats.rx_fifo_errors++; |
904813cd DB |
480 | dbg("(2+ dropped) rx packet_id mismatch 0x%x 0x%x", |
481 | le16_to_cpu(header->packet_id), | |
482 | le16_to_cpu(trailer->packet_id)); | |
483 | return 0; | |
484 | } | |
485 | #if 0 | |
60b86755 JP |
486 | netdev_dbg(dev->net, "frame <rx h %d p %d id %d\n", header->hdr_len, |
487 | header->packet_len, header->packet_id); | |
904813cd DB |
488 | #endif |
489 | dev->frame_errors = 0; | |
490 | return 1; | |
491 | } | |
492 | ||
493 | static struct sk_buff * | |
55016f10 | 494 | net1080_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags) |
904813cd | 495 | { |
904813cd DB |
496 | struct sk_buff *skb2; |
497 | struct nc_header *header = NULL; | |
498 | struct nc_trailer *trailer = NULL; | |
9bcbcf4d | 499 | int padlen = sizeof (struct nc_trailer); |
904813cd DB |
500 | int len = skb->len; |
501 | ||
9bcbcf4d | 502 | if (!((len + padlen + sizeof (struct nc_header)) & 0x01)) |
503 | padlen++; | |
904813cd DB |
504 | if (!skb_cloned(skb)) { |
505 | int headroom = skb_headroom(skb); | |
506 | int tailroom = skb_tailroom(skb); | |
507 | ||
9bcbcf4d | 508 | if (padlen <= tailroom && |
509 | sizeof(struct nc_header) <= headroom) | |
904813cd DB |
510 | /* There's enough head and tail room */ |
511 | goto encapsulate; | |
512 | ||
9bcbcf4d | 513 | if ((sizeof (struct nc_header) + padlen) < |
904813cd DB |
514 | (headroom + tailroom)) { |
515 | /* There's enough total room, so just readjust */ | |
516 | skb->data = memmove(skb->head | |
517 | + sizeof (struct nc_header), | |
518 | skb->data, skb->len); | |
27a884dc | 519 | skb_set_tail_pointer(skb, len); |
904813cd DB |
520 | goto encapsulate; |
521 | } | |
522 | } | |
523 | ||
524 | /* Create a new skb to use with the correct size */ | |
525 | skb2 = skb_copy_expand(skb, | |
526 | sizeof (struct nc_header), | |
9bcbcf4d | 527 | padlen, |
904813cd DB |
528 | flags); |
529 | dev_kfree_skb_any(skb); | |
530 | if (!skb2) | |
531 | return skb2; | |
532 | skb = skb2; | |
533 | ||
534 | encapsulate: | |
535 | /* header first */ | |
536 | header = (struct nc_header *) skb_push(skb, sizeof *header); | |
537 | header->hdr_len = cpu_to_le16(sizeof (*header)); | |
538 | header->packet_len = cpu_to_le16(len); | |
539 | header->packet_id = cpu_to_le16((u16)dev->xid++); | |
540 | ||
541 | /* maybe pad; then trailer */ | |
542 | if (!((skb->len + sizeof *trailer) & 0x01)) | |
543 | *skb_put(skb, 1) = PAD_BYTE; | |
544 | trailer = (struct nc_trailer *) skb_put(skb, sizeof *trailer); | |
545 | put_unaligned(header->packet_id, &trailer->packet_id); | |
546 | #if 0 | |
60b86755 JP |
547 | netdev_dbg(dev->net, "frame >tx h %d p %d id %d\n", |
548 | header->hdr_len, header->packet_len, | |
549 | header->packet_id); | |
904813cd DB |
550 | #endif |
551 | return skb; | |
552 | } | |
553 | ||
554 | static int net1080_bind(struct usbnet *dev, struct usb_interface *intf) | |
555 | { | |
556 | unsigned extra = sizeof (struct nc_header) | |
557 | + 1 | |
558 | + sizeof (struct nc_trailer); | |
559 | ||
560 | dev->net->hard_header_len += extra; | |
561 | dev->rx_urb_size = dev->net->hard_header_len + dev->net->mtu; | |
562 | dev->hard_mtu = NC_MAX_PACKET; | |
563 | return usbnet_get_endpoints (dev, intf); | |
564 | } | |
565 | ||
566 | static const struct driver_info net1080_info = { | |
567 | .description = "NetChip TurboCONNECT", | |
568 | .flags = FLAG_FRAMING_NC, | |
569 | .bind = net1080_bind, | |
570 | .reset = net1080_reset, | |
571 | .check_connect = net1080_check_connect, | |
572 | .rx_fixup = net1080_rx_fixup, | |
573 | .tx_fixup = net1080_tx_fixup, | |
574 | }; | |
575 | ||
576 | static const struct usb_device_id products [] = { | |
577 | { | |
578 | USB_DEVICE(0x0525, 0x1080), // NetChip ref design | |
579 | .driver_info = (unsigned long) &net1080_info, | |
580 | }, { | |
581 | USB_DEVICE(0x06D0, 0x0622), // Laplink Gold | |
582 | .driver_info = (unsigned long) &net1080_info, | |
583 | }, | |
584 | { }, // END | |
585 | }; | |
586 | MODULE_DEVICE_TABLE(usb, products); | |
587 | ||
588 | static struct usb_driver net1080_driver = { | |
904813cd DB |
589 | .name = "net1080", |
590 | .id_table = products, | |
591 | .probe = usbnet_probe, | |
592 | .disconnect = usbnet_disconnect, | |
593 | .suspend = usbnet_suspend, | |
594 | .resume = usbnet_resume, | |
595 | }; | |
596 | ||
597 | static int __init net1080_init(void) | |
598 | { | |
599 | return usb_register(&net1080_driver); | |
600 | } | |
601 | module_init(net1080_init); | |
602 | ||
603 | static void __exit net1080_exit(void) | |
604 | { | |
605 | usb_deregister(&net1080_driver); | |
606 | } | |
607 | module_exit(net1080_exit); | |
608 | ||
609 | MODULE_AUTHOR("David Brownell"); | |
610 | MODULE_DESCRIPTION("NetChip 1080 based USB Host-to-Host Links"); | |
611 | MODULE_LICENSE("GPL"); |