1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117#include <linux/config.h>
118#ifdef CONFIG_USB_DEBUG
119# define DEBUG
120#endif
121#include <linux/module.h>
122#include <linux/kmod.h>
123#include <linux/sched.h>
124#include <linux/init.h>
125#include <linux/netdevice.h>
126#include <linux/etherdevice.h>
127#include <linux/random.h>
128#include <linux/ethtool.h>
129#include <linux/workqueue.h>
130#include <linux/mii.h>
131#include <asm/uaccess.h>
132#include <asm/unaligned.h>
133#include <linux/usb.h>
134#include <asm/io.h>
135#include <asm/scatterlist.h>
136#include <linux/mm.h>
137#include <linux/dma-mapping.h>
138
139#define DRIVER_VERSION "03-Nov-2004"
140
141
142
143
144
145
146
147
148
149
150
151#define RX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4)
152#define TX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4)
153
154
155
156#define MIN_PACKET sizeof(struct ethhdr)
157#define MAX_PACKET 32768
158
159
160#define TX_TIMEOUT_JIFFIES (5*HZ)
161
162
163
164#define THROTTLE_JIFFIES (HZ/8)
165
166
167#define CONTROL_TIMEOUT_MS (500)
168#define CONTROL_TIMEOUT_JIFFIES ((CONTROL_TIMEOUT_MS * HZ)/1000)
169
170
171#define UNLINK_TIMEOUT_MS 3
172
173
174
175
176static u8 node_id [ETH_ALEN];
177
178
179struct usbnet {
180
181 struct usb_device *udev;
182 struct driver_info *driver_info;
183 wait_queue_head_t *wait;
184
185
186 unsigned in, out;
187 unsigned maxpacket;
188 struct timer_list delay;
189
190
191 struct net_device *net;
192 struct net_device_stats stats;
193 int msg_level;
194 unsigned long data [5];
195
196 struct mii_if_info mii;
197
198
199 struct sk_buff_head rxq;
200 struct sk_buff_head txq;
201 struct sk_buff_head done;
202 struct tasklet_struct bh;
203
204 struct work_struct kevent;
205 unsigned long flags;
206# define EVENT_TX_HALT 0
207# define EVENT_RX_HALT 1
208# define EVENT_RX_MEMORY 2
209};
210
211
212struct driver_info {
213 char *description;
214
215 int flags;
216
217#define FLAG_FRAMING_NC 0x0001
218#define FLAG_FRAMING_GL 0x0002
219#define FLAG_FRAMING_Z 0x0004
220#define FLAG_FRAMING_RN 0x0008
221
222#define FLAG_NO_SETINT 0x0010
223#define FLAG_ETHER 0x0020
224
225
226 int (*bind)(struct usbnet *, struct usb_interface *);
227
228
229 void (*unbind)(struct usbnet *, struct usb_interface *);
230
231
232 int (*reset)(struct usbnet *);
233
234
235 int (*check_connect)(struct usbnet *);
236
237
238 int (*rx_fixup)(struct usbnet *dev, struct sk_buff *skb);
239
240
241 struct sk_buff *(*tx_fixup)(struct usbnet *dev,
242 struct sk_buff *skb, int flags);
243
244
245
246
247
248
249 int in;
250 int out;
251
252 unsigned long data;
253};
254
255
256enum skb_state {
257 illegal = 0,
258 tx_start, tx_done,
259 rx_start, rx_done, rx_cleanup
260};
261
262struct skb_data {
263 struct urb *urb;
264 struct usbnet *dev;
265 enum skb_state state;
266 size_t length;
267};
268
269static const char driver_name [] = "usbnet";
270
271
272static int msg_level = 1;
273module_param (msg_level, int, 0);
274MODULE_PARM_DESC (msg_level, "Initial message level (default = 1)");
275
276
277#define RUN_CONTEXT (in_irq () ? "in_irq" \
278 : (in_interrupt () ? "in_interrupt" : "can sleep"))
279
280#ifdef DEBUG
281#define devdbg(usbnet, fmt, arg...) \
282 printk(KERN_DEBUG "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
283#else
284#define devdbg(usbnet, fmt, arg...) do {} while(0)
285#endif
286
287#define deverr(usbnet, fmt, arg...) \
288 printk(KERN_ERR "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
289#define devwarn(usbnet, fmt, arg...) \
290 printk(KERN_WARNING "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
291
292#define devinfo(usbnet, fmt, arg...) \
293 do { if ((usbnet)->msg_level >= 1) \
294 printk(KERN_INFO "%s: " fmt "\n" , (usbnet)->net->name , ## arg); \
295 } while (0)
296
297
298
299static void usbnet_get_drvinfo (struct net_device *, struct ethtool_drvinfo *);
300static u32 usbnet_get_link (struct net_device *);
301static u32 usbnet_get_msglevel (struct net_device *);
302static void usbnet_set_msglevel (struct net_device *, u32);
303
304
305static int always_connected (struct usbnet *dev)
306{
307 return 0;
308}
309
310
311static int
312get_endpoints (struct usbnet *dev, struct usb_interface *intf)
313{
314 int tmp;
315 struct usb_host_interface *alt;
316 struct usb_host_endpoint *in, *out;
317
318 for (tmp = 0; tmp < intf->num_altsetting; tmp++) {
319 unsigned ep;
320
321 in = out = NULL;
322 alt = intf->altsetting + tmp;
323
324
325
326
327 for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) {
328 struct usb_host_endpoint *e;
329
330 e = alt->endpoint + ep;
331 if (e->desc.bmAttributes != USB_ENDPOINT_XFER_BULK)
332 continue;
333 if (e->desc.bEndpointAddress & USB_DIR_IN) {
334 if (!in)
335 in = e;
336 } else {
337 if (!out)
338 out = e;
339 }
340 if (in && out)
341 goto found;
342 }
343 }
344 return -EINVAL;
345
346found:
347 if (alt->desc.bAlternateSetting != 0
348 || !(dev->driver_info->flags & FLAG_NO_SETINT)) {
349 tmp = usb_set_interface (dev->udev, alt->desc.bInterfaceNumber,
350 alt->desc.bAlternateSetting);
351 if (tmp < 0)
352 return tmp;
353 }
354
355 dev->in = usb_rcvbulkpipe (dev->udev,
356 in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
357 dev->out = usb_sndbulkpipe (dev->udev,
358 out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
359 return 0;
360}
361
362static void skb_return (struct usbnet *dev, struct sk_buff *skb)
363{
364 int status;
365
366 skb->dev = dev->net;
367 skb->protocol = eth_type_trans (skb, dev->net);
368 dev->stats.rx_packets++;
369 dev->stats.rx_bytes += skb->len;
370
371#ifdef VERBOSE
372 devdbg (dev, "< rx, len %d, type 0x%x",
373 skb->len + sizeof (struct ethhdr), skb->protocol);
374#endif
375 memset (skb->cb, 0, sizeof (struct skb_data));
376 status = netif_rx (skb);
377 if (status != NET_RX_SUCCESS)
378 devdbg (dev, "netif_rx status %d", status);
379}
380
381
382#ifdef CONFIG_USB_ALI_M5632
383#define HAVE_HARDWARE
384
385
386
387
388
389
390
391static const struct driver_info ali_m5632_info = {
392 .description = "ALi M5632",
393};
394
395
396#endif
397
398
399#ifdef CONFIG_USB_AN2720
400#define HAVE_HARDWARE
401
402
403
404
405
406
407
408
409
410
411
412
413static const struct driver_info an2720_info = {
414 .description = "AnchorChips/Cypress 2720",
415
416
417
418 .in = 2, .out = 2,
419};
420
421#endif
422
423
424#ifdef CONFIG_USB_AX8817X
425
426
427#define HAVE_HARDWARE
428#define NEED_MII
429
430#include <linux/crc32.h>
431
432#define AX_CMD_SET_SW_MII 0x06
433#define AX_CMD_READ_MII_REG 0x07
434#define AX_CMD_WRITE_MII_REG 0x08
435#define AX_CMD_SET_HW_MII 0x0a
436#define AX_CMD_READ_EEPROM 0x0b
437#define AX_CMD_WRITE_EEPROM 0x0c
438#define AX_CMD_WRITE_RX_CTL 0x10
439#define AX_CMD_READ_IPG012 0x11
440#define AX_CMD_WRITE_IPG0 0x12
441#define AX_CMD_WRITE_IPG1 0x13
442#define AX_CMD_WRITE_IPG2 0x14
443#define AX_CMD_WRITE_MULTI_FILTER 0x16
444#define AX_CMD_READ_NODE_ID 0x17
445#define AX_CMD_READ_PHY_ID 0x19
446#define AX_CMD_WRITE_MEDIUM_MODE 0x1b
447#define AX_CMD_READ_MONITOR_MODE 0x1c
448#define AX_CMD_WRITE_MONITOR_MODE 0x1d
449#define AX_CMD_WRITE_GPIOS 0x1f
450
451#define AX_MONITOR_MODE 0x01
452#define AX_MONITOR_LINK 0x02
453#define AX_MONITOR_MAGIC 0x04
454#define AX_MONITOR_HSFS 0x10
455
456#define AX_MCAST_FILTER_SIZE 8
457#define AX_MAX_MCAST 64
458
459#define AX_INTERRUPT_BUFSIZE 8
460
461
462struct ax8817x_data {
463 u8 multi_filter[AX_MCAST_FILTER_SIZE];
464 struct urb *int_urb;
465 u8 *int_buf;
466};
467
468static int ax8817x_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
469 u16 size, void *data)
470{
471 return usb_control_msg(
472 dev->udev,
473 usb_rcvctrlpipe(dev->udev, 0),
474 cmd,
475 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
476 value,
477 index,
478 data,
479 size,
480 CONTROL_TIMEOUT_JIFFIES);
481}
482
483static int ax8817x_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
484 u16 size, void *data)
485{
486 return usb_control_msg(
487 dev->udev,
488 usb_sndctrlpipe(dev->udev, 0),
489 cmd,
490 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
491 value,
492 index,
493 data,
494 size,
495 CONTROL_TIMEOUT_JIFFIES);
496}
497
498static void ax8817x_async_cmd_callback(struct urb *urb, struct pt_regs *regs)
499{
500 struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
501
502 if (urb->status < 0)
503 printk(KERN_DEBUG "ax8817x_async_cmd_callback() failed with %d",
504 urb->status);
505
506 kfree(req);
507 usb_free_urb(urb);
508}
509
510static void ax8817x_interrupt_complete(struct urb *urb, struct pt_regs *regs)
511{
512 struct usbnet *dev = (struct usbnet *)urb->context;
513 struct ax8817x_data *data = (struct ax8817x_data *)&dev->data;
514 int link;
515
516 if (urb->status < 0) {
517 printk(KERN_DEBUG "ax8817x_interrupt_complete() failed with %d",
518 urb->status);
519 } else {
520 if (data->int_buf[5] == 0x90) {
521 link = data->int_buf[2] & 0x01;
522 if (netif_carrier_ok(dev->net) != link) {
523 if (link)
524 netif_carrier_on(dev->net);
525 else
526 netif_carrier_off(dev->net);
527 devdbg(dev, "ax8817x - Link Status is: %d", link);
528 }
529 }
530 usb_submit_urb(data->int_urb, GFP_ATOMIC);
531 }
532}
533
534static void ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
535 u16 size, void *data)
536{
537 struct usb_ctrlrequest *req;
538 int status;
539 struct urb *urb;
540
541 if ((urb = usb_alloc_urb(0, GFP_ATOMIC)) == NULL) {
542 devdbg(dev, "Error allocating URB in write_cmd_async!");
543 return;
544 }
545
546 if ((req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC)) == NULL) {
547 deverr(dev, "Failed to allocate memory for control request");
548 usb_free_urb(urb);
549 return;
550 }
551
552 req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
553 req->bRequest = cmd;
554 req->wValue = cpu_to_le16(value);
555 req->wIndex = cpu_to_le16(index);
556 req->wLength = cpu_to_le16(size);
557
558 usb_fill_control_urb(urb, dev->udev,
559 usb_sndctrlpipe(dev->udev, 0),
560 (void *)req, data, size,
561 ax8817x_async_cmd_callback, req);
562
563 if((status = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
564 deverr(dev, "Error submitting the control message: status=%d", status);
565 kfree(req);
566 usb_free_urb(urb);
567 }
568}
569
570static void ax8817x_set_multicast(struct net_device *net)
571{
572 struct usbnet *dev = netdev_priv(net);
573 struct ax8817x_data *data = (struct ax8817x_data *)&dev->data;
574 u8 rx_ctl = 0x8c;
575
576 if (net->flags & IFF_PROMISC) {
577 rx_ctl |= 0x01;
578 } else if (net->flags & IFF_ALLMULTI
579 || net->mc_count > AX_MAX_MCAST) {
580 rx_ctl |= 0x02;
581 } else if (net->mc_count == 0) {
582
583 } else {
584
585
586
587
588 struct dev_mc_list *mc_list = net->mc_list;
589 u32 crc_bits;
590 int i;
591
592 memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE);
593
594
595 for (i = 0; i < net->mc_count; i++) {
596 crc_bits =
597 ether_crc(ETH_ALEN,
598 mc_list->dmi_addr) >> 26;
599 data->multi_filter[crc_bits >> 3] |=
600 1 << (crc_bits & 7);
601 mc_list = mc_list->next;
602 }
603
604 ax8817x_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
605 AX_MCAST_FILTER_SIZE, data->multi_filter);
606
607 rx_ctl |= 0x10;
608 }
609
610 ax8817x_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
611}
612
613static int ax8817x_mdio_read(struct net_device *netdev, int phy_id, int loc)
614{
615 struct usbnet *dev = netdev_priv(netdev);
616 u16 res;
617 u8 buf[1];
618
619 ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf);
620 ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res);
621 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf);
622
623 return res & 0xffff;
624}
625
626static void ax8817x_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
627{
628 struct usbnet *dev = netdev_priv(netdev);
629 u16 res = val;
630 u8 buf[1];
631
632 ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf);
633 ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res);
634 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf);
635}
636
637static void ax8817x_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
638{
639 struct usbnet *dev = netdev_priv(net);
640 u8 opt;
641
642 if (ax8817x_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) {
643 wolinfo->supported = 0;
644 wolinfo->wolopts = 0;
645 return;
646 }
647 wolinfo->supported = WAKE_PHY | WAKE_MAGIC;
648 wolinfo->wolopts = 0;
649 if (opt & AX_MONITOR_MODE) {
650 if (opt & AX_MONITOR_LINK)
651 wolinfo->wolopts |= WAKE_PHY;
652 if (opt & AX_MONITOR_MAGIC)
653 wolinfo->wolopts |= WAKE_MAGIC;
654 }
655}
656
657static int ax8817x_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
658{
659 struct usbnet *dev = netdev_priv(net);
660 u8 opt = 0;
661 u8 buf[1];
662
663 if (wolinfo->wolopts & WAKE_PHY)
664 opt |= AX_MONITOR_LINK;
665 if (wolinfo->wolopts & WAKE_MAGIC)
666 opt |= AX_MONITOR_MAGIC;
667 if (opt != 0)
668 opt |= AX_MONITOR_MODE;
669
670 if (ax8817x_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE,
671 opt, 0, 0, &buf) < 0)
672 return -EINVAL;
673
674 return 0;
675}
676
677static int ax8817x_get_eeprom(struct net_device *net,
678 struct ethtool_eeprom *eeprom, u8 *data)
679{
680 struct usbnet *dev = netdev_priv(net);
681 u16 *ebuf = (u16 *)data;
682 int i;
683
684
685
686
687 if (eeprom->len % 2)
688 return -EINVAL;
689
690
691 for (i=0; i < eeprom->len / 2; i++) {
692 if (ax8817x_read_cmd(dev, AX_CMD_READ_EEPROM,
693 eeprom->offset + i, 0, 2, &ebuf[i]) < 0)
694 return -EINVAL;
695 }
696 return i * 2;
697}
698
699static void ax8817x_get_drvinfo (struct net_device *net,
700 struct ethtool_drvinfo *info)
701{
702
703 usbnet_get_drvinfo(net, info);
704 info->eedump_len = 0x3e;
705}
706
707static int ax8817x_get_settings(struct net_device *net, struct ethtool_cmd *cmd)
708{
709 struct usbnet *dev = netdev_priv(net);
710
711 return mii_ethtool_gset(&dev->mii,cmd);
712}
713
714static int ax8817x_set_settings(struct net_device *net, struct ethtool_cmd *cmd)
715{
716 struct usbnet *dev = netdev_priv(net);
717
718 return mii_ethtool_sset(&dev->mii,cmd);
719}
720
721
722
723
724static struct ethtool_ops ax8817x_ethtool_ops = {
725 .get_drvinfo = ax8817x_get_drvinfo,
726 .get_link = ethtool_op_get_link,
727 .get_msglevel = usbnet_get_msglevel,
728 .set_msglevel = usbnet_set_msglevel,
729 .get_wol = ax8817x_get_wol,
730 .set_wol = ax8817x_set_wol,
731 .get_eeprom = ax8817x_get_eeprom,
732 .get_settings = ax8817x_get_settings,
733 .set_settings = ax8817x_set_settings,
734};
735
736static int ax8817x_bind(struct usbnet *dev, struct usb_interface *intf)
737{
738 int ret;
739 u8 buf[6];
740 int i;
741 unsigned long gpio_bits = dev->driver_info->data;
742 struct ax8817x_data *data = (struct ax8817x_data *)dev->data;
743
744 dev->in = usb_rcvbulkpipe(dev->udev, 3);
745 dev->out = usb_sndbulkpipe(dev->udev, 2);
746
747
748 if ((data->int_urb = usb_alloc_urb (0, GFP_KERNEL)) == NULL) {
749 dbg ("%s: cannot allocate interrupt URB",
750 dev->net->name);
751 return -ENOMEM;
752 }
753
754 if ((data->int_buf = kmalloc(AX_INTERRUPT_BUFSIZE, GFP_KERNEL)) == NULL) {
755 dbg ("%s: cannot allocate memory for interrupt buffer",
756 dev->net->name);
757 usb_free_urb(data->int_urb);
758 return -ENOMEM;
759 }
760 memset(data->int_buf, 0, AX_INTERRUPT_BUFSIZE);
761
762 usb_fill_int_urb (data->int_urb, dev->udev,
763 usb_rcvintpipe (dev->udev, 1),
764 data->int_buf, AX_INTERRUPT_BUFSIZE,
765 ax8817x_interrupt_complete, dev,
766 dev->udev->speed == USB_SPEED_HIGH ? 8 : 100);
767
768
769 for (i = 2; i >= 0; i--) {
770 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS,
771 (gpio_bits >> (i * 8)) & 0xff, 0, 0,
772 buf)) < 0)
773 return ret;
774 msleep(5);
775 }
776
777 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x80, 0, 0, buf)) < 0) {
778 dbg("send AX_CMD_WRITE_RX_CTL failed: %d", ret);
779 return ret;
780 }
781
782
783 memset(buf, 0, ETH_ALEN);
784 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, 6, buf)) < 0) {
785 dbg("read AX_CMD_READ_NODE_ID failed: %d", ret);
786 return ret;
787 }
788 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
789
790
791 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf)) < 0) {
792 dbg("error on read AX_CMD_READ_PHY_ID: %02x", ret);
793 return ret;
794 } else if (ret < 2) {
795
796 dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x", ret);
797 return -EIO;
798 }
799
800
801 dev->mii.dev = dev->net;
802 dev->mii.mdio_read = ax8817x_mdio_read;
803 dev->mii.mdio_write = ax8817x_mdio_write;
804 dev->mii.phy_id_mask = 0x3f;
805 dev->mii.reg_num_mask = 0x1f;
806 dev->mii.phy_id = buf[1];
807
808 dev->net->set_multicast_list = ax8817x_set_multicast;
809 dev->net->ethtool_ops = &ax8817x_ethtool_ops;
810
811 ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR,
812 cpu_to_le16(BMCR_RESET));
813 ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
814 cpu_to_le16(ADVERTISE_ALL | ADVERTISE_CSMA | 0x0400));
815 mii_nway_restart(&dev->mii);
816
817 if((ret = usb_submit_urb(data->int_urb, GFP_KERNEL)) < 0) {
818 dbg("Failed to submit interrupt URB: %02x", ret);
819 usb_free_urb(data->int_urb);
820 return ret;
821 }
822
823 return 0;
824}
825
826static void ax8817x_unbind(struct usbnet *dev, struct usb_interface *intf)
827{
828 struct ax8817x_data *data = (struct ax8817x_data *)dev->data;
829
830 usb_kill_urb(data->int_urb);
831 usb_free_urb(data->int_urb);
832 kfree(data->int_buf);
833}
834
835static const struct driver_info ax8817x_info = {
836 .description = "ASIX AX8817x USB 2.0 Ethernet",
837 .bind = ax8817x_bind,
838 .unbind = ax8817x_unbind,
839 .flags = FLAG_ETHER,
840 .data = 0x00130103,
841};
842
843static const struct driver_info dlink_dub_e100_info = {
844 .description = "DLink DUB-E100 USB Ethernet",
845 .bind = ax8817x_bind,
846 .unbind = ax8817x_unbind,
847 .flags = FLAG_ETHER,
848 .data = 0x009f9d9f,
849};
850
851static const struct driver_info netgear_fa120_info = {
852 .description = "Netgear FA-120 USB Ethernet",
853 .bind = ax8817x_bind,
854 .unbind = ax8817x_unbind,
855 .flags = FLAG_ETHER,
856 .data = 0x00130103,
857};
858
859static const struct driver_info hawking_uf200_info = {
860 .description = "Hawking UF200 USB Ethernet",
861 .bind = ax8817x_bind,
862 .unbind = ax8817x_unbind,
863 .flags = FLAG_ETHER,
864 .data = 0x001f1d1f,
865};
866
867#endif
868
869
870
871#ifdef CONFIG_USB_BELKIN
872#define HAVE_HARDWARE
873
874
875
876
877
878
879
880
881
882static const struct driver_info belkin_info = {
883 .description = "Belkin, eTEK, or compatible",
884};
885
886#endif
887
888
889
890
891
892
893
894
895
896
897#ifdef CONFIG_USB_CDCETHER
898#define NEED_GENERIC_CDC
899#endif
900
901#ifdef CONFIG_USB_ZAURUS
902
903#define NEED_GENERIC_CDC
904#endif
905
906#ifdef CONFIG_USB_RNDIS
907
908#define NEED_GENERIC_CDC
909#endif
910
911
912#ifdef NEED_GENERIC_CDC
913
914
915struct header_desc {
916 u8 bLength;
917 u8 bDescriptorType;
918 u8 bDescriptorSubType;
919
920 u16 bcdCDC;
921} __attribute__ ((packed));
922
923
924struct union_desc {
925 u8 bLength;
926 u8 bDescriptorType;
927 u8 bDescriptorSubType;
928
929 u8 bMasterInterface0;
930 u8 bSlaveInterface0;
931
932} __attribute__ ((packed));
933
934
935struct ether_desc {
936 u8 bLength;
937 u8 bDescriptorType;
938 u8 bDescriptorSubType;
939
940 u8 iMACAddress;
941 u32 bmEthernetStatistics;
942 __le16 wMaxSegmentSize;
943 __le16 wNumberMCFilters;
944 u8 bNumberPowerFilters;
945} __attribute__ ((packed));
946
947struct cdc_state {
948 struct header_desc *header;
949 struct union_desc *u;
950 struct ether_desc *ether;
951 struct usb_interface *control;
952 struct usb_interface *data;
953};
954
955static struct usb_driver usbnet_driver;
956
957
958
959
960
961
962static int generic_cdc_bind (struct usbnet *dev, struct usb_interface *intf)
963{
964 u8 *buf = intf->cur_altsetting->extra;
965 int len = intf->cur_altsetting->extralen;
966 struct usb_interface_descriptor *d;
967 struct cdc_state *info = (void *) &dev->data;
968 int status;
969 int rndis;
970
971 if (sizeof dev->data < sizeof *info)
972 return -EDOM;
973
974
975
976
977 if (len == 0 && dev->udev->actconfig->extralen) {
978
979
980
981 buf = dev->udev->actconfig->extra;
982 len = dev->udev->actconfig->extralen;
983 if (len)
984 dev_dbg (&intf->dev,
985 "CDC descriptors on config\n");
986 }
987
988
989
990
991 rndis = (intf->cur_altsetting->desc.bInterfaceProtocol == 0xff);
992
993 memset (info, 0, sizeof *info);
994 info->control = intf;
995 while (len > 3) {
996 if (buf [1] != USB_DT_CS_INTERFACE)
997 goto next_desc;
998
999
1000
1001
1002
1003
1004
1005
1006 switch (buf [2]) {
1007 case 0x00:
1008 if (info->header) {
1009 dev_dbg (&intf->dev, "extra CDC header\n");
1010 goto bad_desc;
1011 }
1012 info->header = (void *) buf;
1013 if (info->header->bLength != sizeof *info->header) {
1014 dev_dbg (&intf->dev, "CDC header len %u\n",
1015 info->header->bLength);
1016 goto bad_desc;
1017 }
1018 break;
1019 case 0x06:
1020 if (info->u) {
1021 dev_dbg (&intf->dev, "extra CDC union\n");
1022 goto bad_desc;
1023 }
1024 info->u = (void *) buf;
1025 if (info->u->bLength != sizeof *info->u) {
1026 dev_dbg (&intf->dev, "CDC union len %u\n",
1027 info->u->bLength);
1028 goto bad_desc;
1029 }
1030
1031
1032
1033
1034
1035 info->control = usb_ifnum_to_if(dev->udev,
1036 info->u->bMasterInterface0);
1037 info->data = usb_ifnum_to_if(dev->udev,
1038 info->u->bSlaveInterface0);
1039 if (!info->control || !info->data) {
1040 dev_dbg (&intf->dev,
1041 "master #%u/%p slave #%u/%p\n",
1042 info->u->bMasterInterface0,
1043 info->control,
1044 info->u->bSlaveInterface0,
1045 info->data);
1046 goto bad_desc;
1047 }
1048 if (info->control != intf) {
1049 dev_dbg (&intf->dev, "bogus CDC Union\n");
1050
1051
1052
1053 if (info->data == intf) {
1054 info->data = info->control;
1055 info->control = intf;
1056 } else
1057 goto bad_desc;
1058 }
1059
1060
1061 d = &info->data->cur_altsetting->desc;
1062 if (d->bInterfaceClass != USB_CLASS_CDC_DATA) {
1063 dev_dbg (&intf->dev, "slave class %u\n",
1064 d->bInterfaceClass);
1065 goto bad_desc;
1066 }
1067 break;
1068 case 0x0F:
1069 if (info->ether) {
1070 dev_dbg (&intf->dev, "extra CDC ether\n");
1071 goto bad_desc;
1072 }
1073 info->ether = (void *) buf;
1074 if (info->ether->bLength != sizeof *info->ether) {
1075 dev_dbg (&intf->dev, "CDC ether len %u\n",
1076 info->u->bLength);
1077 goto bad_desc;
1078 }
1079 dev->net->mtu = le16_to_cpup (
1080 &info->ether->wMaxSegmentSize)
1081 - ETH_HLEN;
1082
1083
1084
1085 break;
1086 }
1087next_desc:
1088 len -= buf [0];
1089 buf += buf [0];
1090 }
1091
1092 if (!info->header || !info->u || (!rndis && !info->ether)) {
1093 dev_dbg (&intf->dev, "missing cdc %s%s%sdescriptor\n",
1094 info->header ? "" : "header ",
1095 info->u ? "" : "union ",
1096 info->ether ? "" : "ether ");
1097 goto bad_desc;
1098 }
1099
1100
1101
1102
1103 status = usb_driver_claim_interface (&usbnet_driver, info->data, dev);
1104 if (status < 0)
1105 return status;
1106 status = get_endpoints (dev, info->data);
1107 if (status < 0) {
1108
1109 usb_set_intfdata(info->data, NULL);
1110 usb_driver_release_interface (&usbnet_driver, info->data);
1111 return status;
1112 }
1113 return 0;
1114
1115bad_desc:
1116 dev_info (&dev->udev->dev, "bad CDC descriptors\n");
1117 return -ENODEV;
1118}
1119
1120static void cdc_unbind (struct usbnet *dev, struct usb_interface *intf)
1121{
1122 struct cdc_state *info = (void *) &dev->data;
1123
1124
1125 if (intf == info->control && info->data) {
1126
1127 usb_set_intfdata(info->data, NULL);
1128 usb_driver_release_interface (&usbnet_driver, info->data);
1129 info->data = NULL;
1130 }
1131
1132
1133 else if (intf == info->data && info->control) {
1134
1135 usb_set_intfdata(info->control, NULL);
1136 usb_driver_release_interface (&usbnet_driver, info->control);
1137 info->control = NULL;
1138 }
1139}
1140
1141#endif
1142
1143
1144#ifdef CONFIG_USB_CDCETHER
1145#define HAVE_HARDWARE
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159#include <linux/ctype.h>
1160
1161static u8 nibble (unsigned char c)
1162{
1163 if (likely (isdigit (c)))
1164 return c - '0';
1165 c = toupper (c);
1166 if (likely (isxdigit (c)))
1167 return 10 + c - 'A';
1168 return 0;
1169}
1170
1171static inline int
1172get_ethernet_addr (struct usbnet *dev, struct ether_desc *e)
1173{
1174 int tmp, i;
1175 unsigned char buf [13];
1176
1177 tmp = usb_string (dev->udev, e->iMACAddress, buf, sizeof buf);
1178 if (tmp != 12) {
1179 dev_dbg (&dev->udev->dev,
1180 "bad MAC string %d fetch, %d\n", e->iMACAddress, tmp);
1181 if (tmp >= 0)
1182 tmp = -EINVAL;
1183 return tmp;
1184 }
1185 for (i = tmp = 0; i < 6; i++, tmp += 2)
1186 dev->net->dev_addr [i] =
1187 (nibble (buf [tmp]) << 4) + nibble (buf [tmp + 1]);
1188 return 0;
1189}
1190
1191static int cdc_bind (struct usbnet *dev, struct usb_interface *intf)
1192{
1193 int status;
1194 struct cdc_state *info = (void *) &dev->data;
1195
1196 status = generic_cdc_bind (dev, intf);
1197 if (status < 0)
1198 return status;
1199
1200 status = get_ethernet_addr (dev, info->ether);
1201 if (status < 0) {
1202 usb_set_intfdata(info->data, NULL);
1203 usb_driver_release_interface (&usbnet_driver, info->data);
1204 return status;
1205 }
1206
1207
1208
1209
1210 return 0;
1211}
1212
1213static const struct driver_info cdc_info = {
1214 .description = "CDC Ethernet Device",
1215 .flags = FLAG_ETHER,
1216
1217 .bind = cdc_bind,
1218 .unbind = cdc_unbind,
1219};
1220
1221#endif
1222
1223
1224
1225#ifdef CONFIG_USB_EPSON2888
1226#define HAVE_HARDWARE
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241static const struct driver_info epson2888_info = {
1242 .description = "Epson USB Device",
1243 .check_connect = always_connected,
1244
1245 .in = 4, .out = 3,
1246};
1247
1248#endif
1249
1250
1251#ifdef CONFIG_USB_GENESYS
1252#define HAVE_HARDWARE
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276#define GENELINK_CONNECT_WRITE 0xF0
1277
1278#define GENELINK_INTERRUPT_PIPE 0x03
1279
1280#define INTERRUPT_BUFSIZE 0x08
1281
1282#define GENELINK_INTERRUPT_INTERVAL 0x10
1283
1284#define GL_MAX_TRANSMIT_PACKETS 32
1285
1286#define GL_MAX_PACKET_LEN 1514
1287
1288#define GL_RCV_BUF_SIZE \
1289 (((GL_MAX_PACKET_LEN + 4) * GL_MAX_TRANSMIT_PACKETS) + 4)
1290
1291struct gl_packet {
1292 u32 packet_length;
1293 char packet_data [1];
1294};
1295
1296struct gl_header {
1297 u32 packet_count;
1298 struct gl_packet packets;
1299};
1300
1301#ifdef GENELINK_ACK
1302
1303
1304
1305
1306
1307struct gl_priv {
1308 struct urb *irq_urb;
1309 char irq_buf [INTERRUPT_BUFSIZE];
1310};
1311
1312static inline int gl_control_write (struct usbnet *dev, u8 request, u16 value)
1313{
1314 int retval;
1315
1316 retval = usb_control_msg (dev->udev,
1317 usb_sndctrlpipe (dev->udev, 0),
1318 request,
1319 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
1320 value,
1321 0,
1322 0,
1323 0,
1324 CONTROL_TIMEOUT_JIFFIES);
1325 return retval;
1326}
1327
1328static void gl_interrupt_complete (struct urb *urb, struct pt_regs *regs)
1329{
1330 int status = urb->status;
1331
1332 switch (status) {
1333 case 0:
1334
1335 break;
1336 case -ECONNRESET:
1337 case -ENOENT:
1338 case -ESHUTDOWN:
1339
1340 dbg("%s - urb shutting down with status: %d",
1341 __FUNCTION__, status);
1342 return;
1343 default:
1344 dbg("%s - nonzero urb status received: %d",
1345 __FUNCTION__, urb->status);
1346 }
1347
1348 status = usb_submit_urb (urb, GFP_ATOMIC);
1349 if (status)
1350 err ("%s - usb_submit_urb failed with result %d",
1351 __FUNCTION__, status);
1352}
1353
1354static int gl_interrupt_read (struct usbnet *dev)
1355{
1356 struct gl_priv *priv = dev->priv_data;
1357 int retval;
1358
1359
1360 if (priv && priv->irq_urb) {
1361
1362 if ((retval = usb_submit_urb (priv->irq_urb, GFP_KERNEL)) != 0)
1363 dbg ("gl_interrupt_read: submit fail - %X...", retval);
1364 else
1365 dbg ("gl_interrupt_read: submit success...");
1366 }
1367
1368 return 0;
1369}
1370
1371
1372static int genelink_check_connect (struct usbnet *dev)
1373{
1374 int retval;
1375
1376 dbg ("genelink_check_connect...");
1377
1378
1379 if ((retval = gl_control_write (dev, GENELINK_CONNECT_WRITE, 0)) != 0) {
1380 dbg ("%s: genelink_check_connect write fail - %X",
1381 dev->net->name, retval);
1382 return retval;
1383 }
1384
1385
1386 if ((retval = gl_interrupt_read (dev)) != 0) {
1387 dbg ("%s: genelink_check_connect read fail - %X",
1388 dev->net->name, retval);
1389 return retval;
1390 }
1391
1392 dbg ("%s: genelink_check_connect read success", dev->net->name);
1393 return 0;
1394}
1395
1396
1397static int genelink_init (struct usbnet *dev)
1398{
1399 struct gl_priv *priv;
1400
1401
1402 if ((priv = kmalloc (sizeof *priv, GFP_KERNEL)) == 0) {
1403 dbg ("%s: cannot allocate private data per device",
1404 dev->net->name);
1405 return -ENOMEM;
1406 }
1407
1408
1409 if ((priv->irq_urb = usb_alloc_urb (0, GFP_KERNEL)) == 0) {
1410 dbg ("%s: cannot allocate private irq urb per device",
1411 dev->net->name);
1412 kfree (priv);
1413 return -ENOMEM;
1414 }
1415
1416
1417 usb_fill_int_urb (priv->irq_urb, dev->udev,
1418 usb_rcvintpipe (dev->udev, GENELINK_INTERRUPT_PIPE),
1419 priv->irq_buf, INTERRUPT_BUFSIZE,
1420 gl_interrupt_complete, 0,
1421 GENELINK_INTERRUPT_INTERVAL);
1422
1423
1424 dev->priv_data = priv;
1425
1426 return 0;
1427}
1428
1429
1430static int genelink_free (struct usbnet *dev)
1431{
1432 struct gl_priv *priv = dev->priv_data;
1433
1434 if (!priv)
1435 return 0;
1436
1437
1438
1439
1440
1441
1442 usb_kill_urb (priv->irq_urb);
1443
1444
1445 usb_free_urb (priv->irq_urb);
1446
1447
1448 kfree (priv);
1449
1450 return 0;
1451}
1452
1453#endif
1454
1455static int genelink_rx_fixup (struct usbnet *dev, struct sk_buff *skb)
1456{
1457 struct gl_header *header;
1458 struct gl_packet *packet;
1459 struct sk_buff *gl_skb;
1460 u32 size;
1461
1462 header = (struct gl_header *) skb->data;
1463
1464
1465 le32_to_cpus (&header->packet_count);
1466 if ((header->packet_count > GL_MAX_TRANSMIT_PACKETS)
1467 || (header->packet_count < 0)) {
1468 dbg ("genelink: invalid received packet count %d",
1469 header->packet_count);
1470 return 0;
1471 }
1472
1473
1474 packet = &header->packets;
1475
1476
1477 skb_pull (skb, 4);
1478
1479 while (header->packet_count > 1) {
1480
1481 size = packet->packet_length;
1482
1483
1484 if (size > GL_MAX_PACKET_LEN) {
1485 dbg ("genelink: invalid rx length %d", size);
1486 return 0;
1487 }
1488
1489
1490 gl_skb = alloc_skb (size, GFP_ATOMIC);
1491 if (gl_skb) {
1492
1493
1494 memcpy(skb_put(gl_skb, size), packet->packet_data, size);
1495 skb_return (dev, skb);
1496 }
1497
1498
1499 packet = (struct gl_packet *)
1500 &packet->packet_data [size];
1501 header->packet_count--;
1502
1503
1504 skb_pull (skb, size + 4);
1505 }
1506
1507
1508 skb_pull (skb, 4);
1509
1510 if (skb->len > GL_MAX_PACKET_LEN) {
1511 dbg ("genelink: invalid rx length %d", skb->len);
1512 return 0;
1513 }
1514 return 1;
1515}
1516
1517static struct sk_buff *
1518genelink_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags)
1519{
1520 int padlen;
1521 int length = skb->len;
1522 int headroom = skb_headroom (skb);
1523 int tailroom = skb_tailroom (skb);
1524 u32 *packet_count;
1525 u32 *packet_len;
1526
1527
1528 padlen = ((skb->len + (4 + 4*1)) % 64) ? 0 : 1;
1529
1530 if ((!skb_cloned (skb))
1531 && ((headroom + tailroom) >= (padlen + (4 + 4*1)))) {
1532 if ((headroom < (4 + 4*1)) || (tailroom < padlen)) {
1533 skb->data = memmove (skb->head + (4 + 4*1),
1534 skb->data, skb->len);
1535 skb->tail = skb->data + skb->len;
1536 }
1537 } else {
1538 struct sk_buff *skb2;
1539 skb2 = skb_copy_expand (skb, (4 + 4*1) , padlen, flags);
1540 dev_kfree_skb_any (skb);
1541 skb = skb2;
1542 if (!skb)
1543 return NULL;
1544 }
1545
1546
1547 packet_count = (u32 *) skb_push (skb, (4 + 4*1));
1548 packet_len = packet_count + 1;
1549
1550
1551 *packet_count = 1;
1552 *packet_len = length;
1553
1554
1555 if ((skb->len % dev->maxpacket) == 0)
1556 skb_put (skb, 1);
1557
1558 return skb;
1559}
1560
1561static const struct driver_info genelink_info = {
1562 .description = "Genesys GeneLink",
1563 .flags = FLAG_FRAMING_GL | FLAG_NO_SETINT,
1564 .rx_fixup = genelink_rx_fixup,
1565 .tx_fixup = genelink_tx_fixup,
1566
1567 .in = 1, .out = 2,
1568
1569#ifdef GENELINK_ACK
1570 .check_connect =genelink_check_connect,
1571#endif
1572};
1573
1574#endif
1575
1576
1577
1578#ifdef CONFIG_USB_NET1080
1579#define HAVE_HARDWARE
1580
1581
1582
1583
1584
1585
1586
1587
1588#define dev_packet_id data[0]
1589#define frame_errors data[1]
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604struct nc_header {
1605 u16 hdr_len;
1606 u16 packet_len;
1607 u16 packet_id;
1608#define MIN_HEADER 6
1609
1610
1611
1612
1613} __attribute__((__packed__));
1614
1615#define PAD_BYTE ((unsigned char)0xAC)
1616
1617struct nc_trailer {
1618 u16 packet_id;
1619} __attribute__((__packed__));
1620
1621
1622#define FRAMED_SIZE(mtu) (sizeof (struct nc_header) \
1623 + sizeof (struct ethhdr) \
1624 + (mtu) \
1625 + 1 \
1626 + sizeof (struct nc_trailer))
1627
1628#define MIN_FRAMED FRAMED_SIZE(0)
1629
1630
1631
1632
1633
1634
1635
1636
1637#define NC_READ_TTL_MS ((u8)255)
1638
1639
1640
1641
1642#define REG_USBCTL ((u8)0x04)
1643#define REG_TTL ((u8)0x10)
1644#define REG_STATUS ((u8)0x11)
1645
1646
1647
1648
1649#define REQUEST_REGISTER ((u8)0x10)
1650#define REQUEST_EEPROM ((u8)0x11)
1651
1652static int
1653nc_vendor_read (struct usbnet *dev, u8 req, u8 regnum, u16 *retval_ptr)
1654{
1655 int status = usb_control_msg (dev->udev,
1656 usb_rcvctrlpipe (dev->udev, 0),
1657 req,
1658 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1659 0, regnum,
1660 retval_ptr, sizeof *retval_ptr,
1661 CONTROL_TIMEOUT_JIFFIES);
1662 if (status > 0)
1663 status = 0;
1664 if (!status)
1665 le16_to_cpus (retval_ptr);
1666 return status;
1667}
1668
1669static inline int
1670nc_register_read (struct usbnet *dev, u8 regnum, u16 *retval_ptr)
1671{
1672 return nc_vendor_read (dev, REQUEST_REGISTER, regnum, retval_ptr);
1673}
1674
1675
1676static void
1677nc_vendor_write (struct usbnet *dev, u8 req, u8 regnum, u16 value)
1678{
1679 usb_control_msg (dev->udev,
1680 usb_sndctrlpipe (dev->udev, 0),
1681 req,
1682 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1683 value, regnum,
1684 NULL, 0,
1685 CONTROL_TIMEOUT_JIFFIES);
1686}
1687
1688static inline void
1689nc_register_write (struct usbnet *dev, u8 regnum, u16 value)
1690{
1691 nc_vendor_write (dev, REQUEST_REGISTER, regnum, value);
1692}
1693
1694
1695#if 0
1696static void nc_dump_registers (struct usbnet *dev)
1697{
1698 u8 reg;
1699 u16 *vp = kmalloc (sizeof (u16));
1700
1701 if (!vp) {
1702 dbg ("no memory?");
1703 return;
1704 }
1705
1706 dbg ("%s registers:", dev->net->name);
1707 for (reg = 0; reg < 0x20; reg++) {
1708 int retval;
1709
1710
1711 if (reg >= 0x08 && reg <= 0xf)
1712 continue;
1713 if (reg >= 0x12 && reg <= 0x1e)
1714 continue;
1715
1716 retval = nc_register_read (dev, reg, vp);
1717 if (retval < 0)
1718 dbg ("%s reg [0x%x] ==> error %d",
1719 dev->net->name, reg, retval);
1720 else
1721 dbg ("%s reg [0x%x] = 0x%x",
1722 dev->net->name, reg, *vp);
1723 }
1724 kfree (vp);
1725}
1726#endif
1727
1728
1729
1730
1731
1732
1733
1734
1735#define USBCTL_WRITABLE_MASK 0x1f0f
1736
1737#define USBCTL_ENABLE_LANG (1 << 12)
1738#define USBCTL_ENABLE_MFGR (1 << 11)
1739#define USBCTL_ENABLE_PROD (1 << 10)
1740#define USBCTL_ENABLE_SERIAL (1 << 9)
1741#define USBCTL_ENABLE_DEFAULTS (1 << 8)
1742
1743#define USBCTL_FLUSH_OTHER (1 << 3)
1744#define USBCTL_FLUSH_THIS (1 << 2)
1745#define USBCTL_DISCONN_OTHER (1 << 1)
1746#define USBCTL_DISCONN_THIS (1 << 0)
1747
1748static inline void nc_dump_usbctl (struct usbnet *dev, u16 usbctl)
1749{
1750#ifdef DEBUG
1751 devdbg (dev, "net1080 %s-%s usbctl 0x%x:%s%s%s%s%s;"
1752 " this%s%s;"
1753 " other%s%s; r/o 0x%x",
1754 dev->udev->bus->bus_name, dev->udev->devpath,
1755 usbctl,
1756 (usbctl & USBCTL_ENABLE_LANG) ? " lang" : "",
1757 (usbctl & USBCTL_ENABLE_MFGR) ? " mfgr" : "",
1758 (usbctl & USBCTL_ENABLE_PROD) ? " prod" : "",
1759 (usbctl & USBCTL_ENABLE_SERIAL) ? " serial" : "",
1760 (usbctl & USBCTL_ENABLE_DEFAULTS) ? " defaults" : "",
1761
1762 (usbctl & USBCTL_FLUSH_OTHER) ? " FLUSH" : "",
1763 (usbctl & USBCTL_DISCONN_OTHER) ? " DIS" : "",
1764 (usbctl & USBCTL_FLUSH_THIS) ? " FLUSH" : "",
1765 (usbctl & USBCTL_DISCONN_THIS) ? " DIS" : "",
1766 usbctl & ~USBCTL_WRITABLE_MASK
1767 );
1768#endif
1769}
1770
1771
1772
1773
1774
1775
1776
1777#define STATUS_PORT_A (1 << 15)
1778
1779#define STATUS_CONN_OTHER (1 << 14)
1780#define STATUS_SUSPEND_OTHER (1 << 13)
1781#define STATUS_MAILBOX_OTHER (1 << 12)
1782#define STATUS_PACKETS_OTHER(n) (((n) >> 8) && 0x03)
1783
1784#define STATUS_CONN_THIS (1 << 6)
1785#define STATUS_SUSPEND_THIS (1 << 5)
1786#define STATUS_MAILBOX_THIS (1 << 4)
1787#define STATUS_PACKETS_THIS(n) (((n) >> 0) && 0x03)
1788
1789#define STATUS_UNSPEC_MASK 0x0c8c
1790#define STATUS_NOISE_MASK ((u16)~(0x0303|STATUS_UNSPEC_MASK))
1791
1792
1793static inline void nc_dump_status (struct usbnet *dev, u16 status)
1794{
1795#ifdef DEBUG
1796 devdbg (dev, "net1080 %s-%s status 0x%x:"
1797 " this (%c) PKT=%d%s%s%s;"
1798 " other PKT=%d%s%s%s; unspec 0x%x",
1799 dev->udev->bus->bus_name, dev->udev->devpath,
1800 status,
1801
1802
1803
1804
1805 (status & STATUS_PORT_A) ? 'A' : 'B',
1806 STATUS_PACKETS_THIS (status),
1807 (status & STATUS_CONN_THIS) ? " CON" : "",
1808 (status & STATUS_SUSPEND_THIS) ? " SUS" : "",
1809 (status & STATUS_MAILBOX_THIS) ? " MBOX" : "",
1810
1811 STATUS_PACKETS_OTHER (status),
1812 (status & STATUS_CONN_OTHER) ? " CON" : "",
1813 (status & STATUS_SUSPEND_OTHER) ? " SUS" : "",
1814 (status & STATUS_MAILBOX_OTHER) ? " MBOX" : "",
1815
1816 status & STATUS_UNSPEC_MASK
1817 );
1818#endif
1819}
1820
1821
1822
1823
1824
1825
1826
1827#define TTL_THIS(ttl) (0x00ff & ttl)
1828#define TTL_OTHER(ttl) (0x00ff & (ttl >> 8))
1829#define MK_TTL(this,other) ((u16)(((other)<<8)|(0x00ff&(this))))
1830
1831static inline void nc_dump_ttl (struct usbnet *dev, u16 ttl)
1832{
1833#ifdef DEBUG
1834 devdbg (dev, "net1080 %s-%s ttl 0x%x this = %d, other = %d",
1835 dev->udev->bus->bus_name, dev->udev->devpath,
1836 ttl,
1837
1838 TTL_THIS (ttl),
1839 TTL_OTHER (ttl)
1840 );
1841#endif
1842}
1843
1844
1845
1846static int net1080_reset (struct usbnet *dev)
1847{
1848 u16 usbctl, status, ttl;
1849 u16 *vp = kmalloc (sizeof (u16), GFP_KERNEL);
1850 int retval;
1851
1852 if (!vp)
1853 return -ENOMEM;
1854
1855
1856
1857 if ((retval = nc_register_read (dev, REG_STATUS, vp)) < 0) {
1858 dbg ("can't read %s-%s status: %d",
1859 dev->udev->bus->bus_name, dev->udev->devpath, retval);
1860 goto done;
1861 }
1862 status = *vp;
1863
1864
1865 if ((retval = nc_register_read (dev, REG_USBCTL, vp)) < 0) {
1866 dbg ("can't read USBCTL, %d", retval);
1867 goto done;
1868 }
1869 usbctl = *vp;
1870
1871
1872 nc_register_write (dev, REG_USBCTL,
1873 USBCTL_FLUSH_THIS | USBCTL_FLUSH_OTHER);
1874
1875 if ((retval = nc_register_read (dev, REG_TTL, vp)) < 0) {
1876 dbg ("can't read TTL, %d", retval);
1877 goto done;
1878 }
1879 ttl = *vp;
1880
1881
1882 nc_register_write (dev, REG_TTL,
1883 MK_TTL (NC_READ_TTL_MS, TTL_OTHER (ttl)) );
1884 dbg ("%s: assigned TTL, %d ms", dev->net->name, NC_READ_TTL_MS);
1885
1886 if (dev->msg_level >= 2)
1887 devinfo (dev, "port %c, peer %sconnected",
1888 (status & STATUS_PORT_A) ? 'A' : 'B',
1889 (status & STATUS_CONN_OTHER) ? "" : "dis"
1890 );
1891 retval = 0;
1892
1893done:
1894 kfree (vp);
1895 return retval;
1896}
1897
1898static int net1080_check_connect (struct usbnet *dev)
1899{
1900 int retval;
1901 u16 status;
1902 u16 *vp = kmalloc (sizeof (u16), GFP_KERNEL);
1903
1904 if (!vp)
1905 return -ENOMEM;
1906 retval = nc_register_read (dev, REG_STATUS, vp);
1907 status = *vp;
1908 kfree (vp);
1909 if (retval != 0) {
1910 dbg ("%s net1080_check_conn read - %d", dev->net->name, retval);
1911 return retval;
1912 }
1913 if ((status & STATUS_CONN_OTHER) != STATUS_CONN_OTHER)
1914 return -ENOLINK;
1915 return 0;
1916}
1917
1918static void nc_flush_complete (struct urb *urb, struct pt_regs *regs)
1919{
1920 kfree (urb->context);
1921 usb_free_urb(urb);
1922}
1923
1924static void nc_ensure_sync (struct usbnet *dev)
1925{
1926 dev->frame_errors++;
1927 if (dev->frame_errors > 5) {
1928 struct urb *urb;
1929 struct usb_ctrlrequest *req;
1930 int status;
1931
1932
1933 urb = usb_alloc_urb (0, SLAB_ATOMIC);
1934 if (!urb)
1935 return;
1936
1937 req = kmalloc (sizeof *req, GFP_ATOMIC);
1938 if (!req) {
1939 usb_free_urb (urb);
1940 return;
1941 }
1942
1943 req->bRequestType = USB_DIR_OUT
1944 | USB_TYPE_VENDOR
1945 | USB_RECIP_DEVICE;
1946 req->bRequest = REQUEST_REGISTER;
1947 req->wValue = cpu_to_le16 (USBCTL_FLUSH_THIS
1948 | USBCTL_FLUSH_OTHER);
1949 req->wIndex = cpu_to_le16 (REG_USBCTL);
1950 req->wLength = cpu_to_le16 (0);
1951
1952
1953
1954
1955 usb_fill_control_urb (urb, dev->udev,
1956 usb_sndctrlpipe (dev->udev, 0),
1957 (unsigned char *) req,
1958 NULL, 0,
1959 nc_flush_complete, req);
1960 status = usb_submit_urb (urb, GFP_ATOMIC);
1961 if (status) {
1962 kfree (req);
1963 usb_free_urb (urb);
1964 return;
1965 }
1966
1967 devdbg (dev, "flush net1080; too many framing errors");
1968 dev->frame_errors = 0;
1969 }
1970}
1971
1972static int net1080_rx_fixup (struct usbnet *dev, struct sk_buff *skb)
1973{
1974 struct nc_header *header;
1975 struct nc_trailer *trailer;
1976
1977 if (!(skb->len & 0x01)
1978 || MIN_FRAMED > skb->len
1979 || skb->len > FRAMED_SIZE (dev->net->mtu)) {
1980 dev->stats.rx_frame_errors++;
1981 dbg ("rx framesize %d range %d..%d mtu %d", skb->len,
1982 (int)MIN_FRAMED, (int)FRAMED_SIZE (dev->net->mtu),
1983 dev->net->mtu);
1984 nc_ensure_sync (dev);
1985 return 0;
1986 }
1987
1988 header = (struct nc_header *) skb->data;
1989 le16_to_cpus (&header->hdr_len);
1990 le16_to_cpus (&header->packet_len);
1991 if (FRAMED_SIZE (header->packet_len) > MAX_PACKET) {
1992 dev->stats.rx_frame_errors++;
1993 dbg ("packet too big, %d", header->packet_len);
1994 nc_ensure_sync (dev);
1995 return 0;
1996 } else if (header->hdr_len < MIN_HEADER) {
1997 dev->stats.rx_frame_errors++;
1998 dbg ("header too short, %d", header->hdr_len);
1999 nc_ensure_sync (dev);
2000 return 0;
2001 } else if (header->hdr_len > MIN_HEADER) {
2002
2003 dbg ("header OOB, %d bytes",
2004 header->hdr_len - MIN_HEADER);
2005 nc_ensure_sync (dev);
2006
2007 }
2008 skb_pull (skb, header->hdr_len);
2009
2010 trailer = (struct nc_trailer *)
2011 (skb->data + skb->len - sizeof *trailer);
2012 skb_trim (skb, skb->len - sizeof *trailer);
2013
2014 if ((header->packet_len & 0x01) == 0) {
2015 if (skb->data [header->packet_len] != PAD_BYTE) {
2016 dev->stats.rx_frame_errors++;
2017 dbg ("bad pad");
2018 return 0;
2019 }
2020 skb_trim (skb, skb->len - 1);
2021 }
2022 if (skb->len != header->packet_len) {
2023 dev->stats.rx_frame_errors++;
2024 dbg ("bad packet len %d (expected %d)",
2025 skb->len, header->packet_len);
2026 nc_ensure_sync (dev);
2027 return 0;
2028 }
2029 if (header->packet_id != get_unaligned (&trailer->packet_id)) {
2030 dev->stats.rx_fifo_errors++;
2031 dbg ("(2+ dropped) rx packet_id mismatch 0x%x 0x%x",
2032 header->packet_id, trailer->packet_id);
2033 return 0;
2034 }
2035#if 0
2036 devdbg (dev, "frame <rx h %d p %d id %d", header->hdr_len,
2037 header->packet_len, header->packet_id);
2038#endif
2039 dev->frame_errors = 0;
2040 return 1;
2041}
2042
2043static struct sk_buff *
2044net1080_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags)
2045{
2046 int padlen;
2047 struct sk_buff *skb2;
2048
2049 padlen = ((skb->len + sizeof (struct nc_header)
2050 + sizeof (struct nc_trailer)) & 0x01) ? 0 : 1;
2051 if (!skb_cloned (skb)) {
2052 int headroom = skb_headroom (skb);
2053 int tailroom = skb_tailroom (skb);
2054
2055 if ((padlen + sizeof (struct nc_trailer)) <= tailroom
2056 && sizeof (struct nc_header) <= headroom)
2057
2058 return skb;
2059
2060 if ((sizeof (struct nc_header) + padlen
2061 + sizeof (struct nc_trailer)) <
2062 (headroom + tailroom)) {
2063
2064 skb->data = memmove (skb->head
2065 + sizeof (struct nc_header),
2066 skb->data, skb->len);
2067 skb->tail = skb->data + skb->len;
2068 return skb;
2069 }
2070 }
2071
2072
2073 skb2 = skb_copy_expand (skb,
2074 sizeof (struct nc_header),
2075 sizeof (struct nc_trailer) + padlen,
2076 flags);
2077 dev_kfree_skb_any (skb);
2078 return skb2;
2079}
2080
2081static const struct driver_info net1080_info = {
2082 .description = "NetChip TurboCONNECT",
2083 .flags = FLAG_FRAMING_NC,
2084 .reset = net1080_reset,
2085 .check_connect =net1080_check_connect,
2086 .rx_fixup = net1080_rx_fixup,
2087 .tx_fixup = net1080_tx_fixup,
2088};
2089
2090#endif
2091
2092
2093
2094#ifdef CONFIG_USB_PL2301
2095#define HAVE_HARDWARE
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110#define PL_S_EN (1<<7)
2111
2112#define PL_TX_READY (1<<5)
2113#define PL_RESET_OUT (1<<4)
2114#define PL_RESET_IN (1<<3)
2115#define PL_TX_C (1<<2)
2116#define PL_TX_REQ (1<<1)
2117#define PL_PEER_E (1<<0)
2118
2119static inline int
2120pl_vendor_req (struct usbnet *dev, u8 req, u8 val, u8 index)
2121{
2122 return usb_control_msg (dev->udev,
2123 usb_rcvctrlpipe (dev->udev, 0),
2124 req,
2125 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2126 val, index,
2127 NULL, 0,
2128 CONTROL_TIMEOUT_JIFFIES);
2129}
2130
2131static inline int
2132pl_clear_QuickLink_features (struct usbnet *dev, int val)
2133{
2134 return pl_vendor_req (dev, 1, (u8) val, 0);
2135}
2136
2137static inline int
2138pl_set_QuickLink_features (struct usbnet *dev, int val)
2139{
2140 return pl_vendor_req (dev, 3, (u8) val, 0);
2141}
2142
2143
2144
2145static int pl_reset (struct usbnet *dev)
2146{
2147
2148
2149
2150 (void) pl_set_QuickLink_features (dev,
2151 PL_S_EN|PL_RESET_OUT|PL_RESET_IN|PL_PEER_E);
2152 return 0;
2153}
2154
2155static const struct driver_info prolific_info = {
2156 .description = "Prolific PL-2301/PL-2302",
2157 .flags = FLAG_NO_SETINT,
2158
2159 .reset = pl_reset,
2160};
2161
2162#endif
2163
2164
2165#ifdef CONFIG_USB_KC2190
2166#define HAVE_HARDWARE
2167static const struct driver_info kc2190_info = {
2168 .description = "KC Technology KC-190",
2169};
2170#endif
2171
2172
2173#ifdef CONFIG_USB_ARMLINUX
2174#define HAVE_HARDWARE
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193static const struct driver_info linuxdev_info = {
2194 .description = "Linux Device",
2195 .check_connect = always_connected,
2196};
2197
2198static const struct driver_info yopy_info = {
2199 .description = "Yopy",
2200 .check_connect = always_connected,
2201};
2202
2203static const struct driver_info blob_info = {
2204 .description = "Boot Loader OBject",
2205 .check_connect = always_connected,
2206};
2207
2208#endif
2209
2210
2211#ifdef CONFIG_USB_ZAURUS
2212#define HAVE_HARDWARE
2213
2214#include <linux/crc32.h>
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231static struct sk_buff *
2232zaurus_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags)
2233{
2234 int padlen;
2235 struct sk_buff *skb2;
2236
2237 padlen = 2;
2238 if (!skb_cloned (skb)) {
2239 int tailroom = skb_tailroom (skb);
2240 if ((padlen + 4) <= tailroom)
2241 goto done;
2242 }
2243 skb2 = skb_copy_expand (skb, 0, 4 + padlen, flags);
2244 dev_kfree_skb_any (skb);
2245 skb = skb2;
2246 if (skb) {
2247 u32 fcs;
2248done:
2249 fcs = crc32_le (~0, skb->data, skb->len);
2250 fcs = ~fcs;
2251
2252 *skb_put (skb, 1) = fcs & 0xff;
2253 *skb_put (skb, 1) = (fcs>> 8) & 0xff;
2254 *skb_put (skb, 1) = (fcs>>16) & 0xff;
2255 *skb_put (skb, 1) = (fcs>>24) & 0xff;
2256 }
2257 return skb;
2258}
2259
2260static const struct driver_info zaurus_sl5x00_info = {
2261 .description = "Sharp Zaurus SL-5x00",
2262 .flags = FLAG_FRAMING_Z,
2263 .check_connect = always_connected,
2264 .bind = generic_cdc_bind,
2265 .unbind = cdc_unbind,
2266 .tx_fixup = zaurus_tx_fixup,
2267};
2268#define ZAURUS_STRONGARM_INFO ((unsigned long)&zaurus_sl5x00_info)
2269
2270static const struct driver_info zaurus_pxa_info = {
2271 .description = "Sharp Zaurus, PXA-2xx based",
2272 .flags = FLAG_FRAMING_Z,
2273 .check_connect = always_connected,
2274 .bind = generic_cdc_bind,
2275 .unbind = cdc_unbind,
2276 .tx_fixup = zaurus_tx_fixup,
2277};
2278#define ZAURUS_PXA_INFO ((unsigned long)&zaurus_pxa_info)
2279
2280static const struct driver_info olympus_mxl_info = {
2281 .description = "Olympus R1000",
2282 .flags = FLAG_FRAMING_Z,
2283 .check_connect = always_connected,
2284 .bind = generic_cdc_bind,
2285 .unbind = cdc_unbind,
2286 .tx_fixup = zaurus_tx_fixup,
2287};
2288#define OLYMPUS_MXL_INFO ((unsigned long)&olympus_mxl_info)
2289
2290#else
2291
2292
2293#define ZAURUS_STRONGARM_INFO 0
2294#define ZAURUS_PXA_INFO 0
2295#define OLYMPUS_MXL_INFO 0
2296
2297#endif
2298
2299
2300
2301
2302
2303
2304
2305
2306static int usbnet_change_mtu (struct net_device *net, int new_mtu)
2307{
2308 struct usbnet *dev = netdev_priv(net);
2309
2310 if (new_mtu <= MIN_PACKET || new_mtu > MAX_PACKET)
2311 return -EINVAL;
2312#ifdef CONFIG_USB_NET1080
2313 if (((dev->driver_info->flags) & FLAG_FRAMING_NC)) {
2314 if (FRAMED_SIZE (new_mtu) > MAX_PACKET)
2315 return -EINVAL;
2316 }
2317#endif
2318#ifdef CONFIG_USB_GENESYS
2319 if (((dev->driver_info->flags) & FLAG_FRAMING_GL)
2320 && new_mtu > GL_MAX_PACKET_LEN)
2321 return -EINVAL;
2322#endif
2323
2324 if (((new_mtu + sizeof (struct ethhdr)) % dev->maxpacket) == 0)
2325 return -EDOM;
2326 net->mtu = new_mtu;
2327 return 0;
2328}
2329
2330
2331
2332static struct net_device_stats *usbnet_get_stats (struct net_device *net)
2333{
2334 struct usbnet *dev = netdev_priv(net);
2335 return &dev->stats;
2336}
2337
2338
2339
2340
2341
2342
2343
2344static void defer_bh (struct usbnet *dev, struct sk_buff *skb)
2345{
2346 struct sk_buff_head *list = skb->list;
2347 unsigned long flags;
2348
2349 spin_lock_irqsave (&list->lock, flags);
2350 __skb_unlink (skb, list);
2351 spin_unlock (&list->lock);
2352 spin_lock (&dev->done.lock);
2353 __skb_queue_tail (&dev->done, skb);
2354 if (dev->done.qlen == 1)
2355 tasklet_schedule (&dev->bh);
2356 spin_unlock_irqrestore (&dev->done.lock, flags);
2357}
2358
2359
2360
2361
2362
2363
2364static void defer_kevent (struct usbnet *dev, int work)
2365{
2366 set_bit (work, &dev->flags);
2367 if (!schedule_work (&dev->kevent))
2368 deverr (dev, "kevent %d may have been dropped", work);
2369 else
2370 devdbg (dev, "kevent %d scheduled", work);
2371}
2372
2373
2374
2375static void rx_complete (struct urb *urb, struct pt_regs *regs);
2376
2377static void rx_submit (struct usbnet *dev, struct urb *urb, int flags)
2378{
2379 struct sk_buff *skb;
2380 struct skb_data *entry;
2381 int retval = 0;
2382 unsigned long lockflags;
2383 size_t size;
2384
2385#ifdef CONFIG_USB_NET1080
2386 if (dev->driver_info->flags & FLAG_FRAMING_NC)
2387 size = FRAMED_SIZE (dev->net->mtu);
2388 else
2389#endif
2390#ifdef CONFIG_USB_GENESYS
2391 if (dev->driver_info->flags & FLAG_FRAMING_GL)
2392 size = GL_RCV_BUF_SIZE;
2393 else
2394#endif
2395#ifdef CONFIG_USB_ZAURUS
2396 if (dev->driver_info->flags & FLAG_FRAMING_Z)
2397 size = 6 + (sizeof (struct ethhdr) + dev->net->mtu);
2398 else
2399#endif
2400#ifdef CONFIG_USB_RNDIS
2401 if (dev->driver_info->flags & FLAG_FRAMING_RN)
2402 size = RNDIS_MAX_TRANSFER;
2403 else
2404#endif
2405 size = (sizeof (struct ethhdr) + dev->net->mtu);
2406
2407 if ((skb = alloc_skb (size, flags)) == NULL) {
2408 devdbg (dev, "no rx skb");
2409 defer_kevent (dev, EVENT_RX_MEMORY);
2410 usb_free_urb (urb);
2411 return;
2412 }
2413
2414 entry = (struct skb_data *) skb->cb;
2415 entry->urb = urb;
2416 entry->dev = dev;
2417 entry->state = rx_start;
2418 entry->length = 0;
2419
2420 usb_fill_bulk_urb (urb, dev->udev, dev->in,
2421 skb->data, size, rx_complete, skb);
2422 urb->transfer_flags |= URB_ASYNC_UNLINK;
2423
2424 spin_lock_irqsave (&dev->rxq.lock, lockflags);
2425
2426 if (netif_running (dev->net)
2427 && netif_device_present (dev->net)
2428 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
2429 switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){
2430 case -EPIPE:
2431 defer_kevent (dev, EVENT_RX_HALT);
2432 break;
2433 case -ENOMEM:
2434 defer_kevent (dev, EVENT_RX_MEMORY);
2435 break;
2436 case -ENODEV:
2437 devdbg (dev, "device gone");
2438 netif_device_detach (dev->net);
2439 break;
2440 default:
2441 devdbg (dev, "rx submit, %d", retval);
2442 tasklet_schedule (&dev->bh);
2443 break;
2444 case 0:
2445 __skb_queue_tail (&dev->rxq, skb);
2446 }
2447 } else {
2448 devdbg (dev, "rx: stopped");
2449 retval = -ENOLINK;
2450 }
2451 spin_unlock_irqrestore (&dev->rxq.lock, lockflags);
2452 if (retval) {
2453 dev_kfree_skb_any (skb);
2454 usb_free_urb (urb);
2455 }
2456}
2457
2458
2459
2460
2461static inline void rx_process (struct usbnet *dev, struct sk_buff *skb)
2462{
2463 if (dev->driver_info->rx_fixup
2464 && !dev->driver_info->rx_fixup (dev, skb))
2465 goto error;
2466
2467
2468 if (skb->len)
2469 skb_return (dev, skb);
2470 else {
2471 devdbg (dev, "drop");
2472error:
2473 dev->stats.rx_errors++;
2474 skb_queue_tail (&dev->done, skb);
2475 }
2476}
2477
2478
2479
2480static void rx_complete (struct urb *urb, struct pt_regs *regs)
2481{
2482 struct sk_buff *skb = (struct sk_buff *) urb->context;
2483 struct skb_data *entry = (struct skb_data *) skb->cb;
2484 struct usbnet *dev = entry->dev;
2485 int urb_status = urb->status;
2486
2487 skb_put (skb, urb->actual_length);
2488 entry->state = rx_done;
2489 entry->urb = NULL;
2490
2491 switch (urb_status) {
2492
2493 case 0:
2494 if (MIN_PACKET > skb->len || skb->len > MAX_PACKET) {
2495 entry->state = rx_cleanup;
2496 dev->stats.rx_errors++;
2497 dev->stats.rx_length_errors++;
2498 devdbg (dev, "rx length %d", skb->len);
2499 }
2500 break;
2501
2502
2503
2504
2505
2506 case -EPIPE:
2507 dev->stats.rx_errors++;
2508 defer_kevent (dev, EVENT_RX_HALT);
2509
2510
2511
2512 case -ECONNRESET:
2513 case -ESHUTDOWN:
2514#ifdef VERBOSE
2515 devdbg (dev, "rx shutdown, code %d", urb_status);
2516#endif
2517 goto block;
2518
2519
2520
2521
2522 case -EPROTO:
2523 case -ETIMEDOUT:
2524 case -EILSEQ:
2525 dev->stats.rx_errors++;
2526 if (!timer_pending (&dev->delay)) {
2527 mod_timer (&dev->delay, jiffies + THROTTLE_JIFFIES);
2528 devdbg (dev, "rx throttle %d", urb_status);
2529 }
2530block:
2531 entry->state = rx_cleanup;
2532 entry->urb = urb;
2533 urb = NULL;
2534 break;
2535
2536
2537 case -EOVERFLOW:
2538 dev->stats.rx_over_errors++;
2539
2540
2541 default:
2542 entry->state = rx_cleanup;
2543 dev->stats.rx_errors++;
2544 devdbg (dev, "rx status %d", urb_status);
2545 break;
2546 }
2547
2548 defer_bh (dev, skb);
2549
2550 if (urb) {
2551 if (netif_running (dev->net)
2552 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
2553 rx_submit (dev, urb, GFP_ATOMIC);
2554 return;
2555 }
2556 usb_free_urb (urb);
2557 }
2558#ifdef VERBOSE
2559 devdbg (dev, "no read resubmitted");
2560#endif
2561}
2562
2563
2564
2565
2566
2567static int unlink_urbs (struct usbnet *dev, struct sk_buff_head *q)
2568{
2569 unsigned long flags;
2570 struct sk_buff *skb, *skbnext;
2571 int count = 0;
2572
2573 spin_lock_irqsave (&q->lock, flags);
2574 for (skb = q->next; skb != (struct sk_buff *) q; skb = skbnext) {
2575 struct skb_data *entry;
2576 struct urb *urb;
2577 int retval;
2578
2579 entry = (struct skb_data *) skb->cb;
2580 urb = entry->urb;
2581 skbnext = skb->next;
2582
2583
2584
2585 retval = usb_unlink_urb (urb);
2586 if (retval != -EINPROGRESS && retval != 0)
2587 devdbg (dev, "unlink urb err, %d", retval);
2588 else
2589 count++;
2590 }
2591 spin_unlock_irqrestore (&q->lock, flags);
2592 return count;
2593}
2594
2595
2596
2597
2598
2599
2600static int usbnet_stop (struct net_device *net)
2601{
2602 struct usbnet *dev = netdev_priv(net);
2603 int temp;
2604 DECLARE_WAIT_QUEUE_HEAD (unlink_wakeup);
2605 DECLARE_WAITQUEUE (wait, current);
2606
2607 netif_stop_queue (net);
2608
2609 if (dev->msg_level >= 2)
2610 devinfo (dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld",
2611 dev->stats.rx_packets, dev->stats.tx_packets,
2612 dev->stats.rx_errors, dev->stats.tx_errors
2613 );
2614
2615
2616 add_wait_queue (&unlink_wakeup, &wait);
2617 dev->wait = &unlink_wakeup;
2618 temp = unlink_urbs (dev, &dev->txq) + unlink_urbs (dev, &dev->rxq);
2619
2620
2621 while (skb_queue_len (&dev->rxq)
2622 && skb_queue_len (&dev->txq)
2623 && skb_queue_len (&dev->done)) {
2624 msleep(UNLINK_TIMEOUT_MS);
2625 devdbg (dev, "waited for %d urb completions", temp);
2626 }
2627 dev->wait = NULL;
2628 remove_wait_queue (&unlink_wakeup, &wait);
2629
2630
2631
2632
2633
2634 dev->flags = 0;
2635 del_timer_sync (&dev->delay);
2636 tasklet_kill (&dev->bh);
2637
2638 return 0;
2639}
2640
2641
2642
2643
2644
2645
2646
2647static int usbnet_open (struct net_device *net)
2648{
2649 struct usbnet *dev = netdev_priv(net);
2650 int retval = 0;
2651 struct driver_info *info = dev->driver_info;
2652
2653
2654 if (info->reset && (retval = info->reset (dev)) < 0) {
2655 devinfo (dev, "open reset fail (%d) usbnet usb-%s-%s, %s",
2656 retval,
2657 dev->udev->bus->bus_name, dev->udev->devpath,
2658 info->description);
2659 goto done;
2660 }
2661
2662
2663 if (info->check_connect && (retval = info->check_connect (dev)) < 0) {
2664 devdbg (dev, "can't open; %d", retval);
2665 goto done;
2666 }
2667
2668 netif_start_queue (net);
2669 if (dev->msg_level >= 2) {
2670 char *framing;
2671
2672 if (dev->driver_info->flags & FLAG_FRAMING_NC)
2673 framing = "NetChip";
2674 else if (dev->driver_info->flags & FLAG_FRAMING_GL)
2675 framing = "GeneSys";
2676 else if (dev->driver_info->flags & FLAG_FRAMING_Z)
2677 framing = "Zaurus";
2678 else if (dev->driver_info->flags & FLAG_FRAMING_RN)
2679 framing = "RNDIS";
2680 else
2681 framing = "simple";
2682
2683 devinfo (dev, "open: enable queueing "
2684 "(rx %d, tx %d) mtu %d %s framing",
2685 RX_QLEN (dev), TX_QLEN (dev), dev->net->mtu,
2686 framing);
2687 }
2688
2689
2690 tasklet_schedule (&dev->bh);
2691done:
2692 return retval;
2693}
2694
2695
2696
2697static void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info)
2698{
2699 struct usbnet *dev = netdev_priv(net);
2700
2701 strncpy (info->driver, driver_name, sizeof info->driver);
2702 strncpy (info->version, DRIVER_VERSION, sizeof info->version);
2703 strncpy (info->fw_version, dev->driver_info->description,
2704 sizeof info->fw_version);
2705 usb_make_path (dev->udev, info->bus_info, sizeof info->bus_info);
2706}
2707
2708static u32 usbnet_get_link (struct net_device *net)
2709{
2710 struct usbnet *dev = netdev_priv(net);
2711
2712
2713 if (dev->driver_info->check_connect)
2714 return dev->driver_info->check_connect (dev) == 0;
2715
2716
2717 return 1;
2718}
2719
2720static u32 usbnet_get_msglevel (struct net_device *net)
2721{
2722 struct usbnet *dev = netdev_priv(net);
2723
2724 return dev->msg_level;
2725}
2726
2727static void usbnet_set_msglevel (struct net_device *net, u32 level)
2728{
2729 struct usbnet *dev = netdev_priv(net);
2730
2731 dev->msg_level = level;
2732}
2733
2734static int usbnet_ioctl (struct net_device *net, struct ifreq *rq, int cmd)
2735{
2736#ifdef NEED_MII
2737 {
2738 struct usbnet *dev = netdev_priv(net);
2739
2740 if (dev->mii.mdio_read != NULL && dev->mii.mdio_write != NULL)
2741 return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
2742 }
2743#endif
2744 return -EOPNOTSUPP;
2745}
2746
2747
2748
2749
2750
2751
2752
2753
2754static void
2755kevent (void *data)
2756{
2757 struct usbnet *dev = data;
2758 int status;
2759
2760
2761 if (test_bit (EVENT_TX_HALT, &dev->flags)) {
2762 unlink_urbs (dev, &dev->txq);
2763 status = usb_clear_halt (dev->udev, dev->out);
2764 if (status < 0 && status != -EPIPE)
2765 deverr (dev, "can't clear tx halt, status %d",
2766 status);
2767 else {
2768 clear_bit (EVENT_TX_HALT, &dev->flags);
2769 netif_wake_queue (dev->net);
2770 }
2771 }
2772 if (test_bit (EVENT_RX_HALT, &dev->flags)) {
2773 unlink_urbs (dev, &dev->rxq);
2774 status = usb_clear_halt (dev->udev, dev->in);
2775 if (status < 0 && status != -EPIPE)
2776 deverr (dev, "can't clear rx halt, status %d",
2777 status);
2778 else {
2779 clear_bit (EVENT_RX_HALT, &dev->flags);
2780 tasklet_schedule (&dev->bh);
2781 }
2782 }
2783
2784
2785 if (test_bit (EVENT_RX_MEMORY, &dev->flags)) {
2786 struct urb *urb = NULL;
2787
2788 if (netif_running (dev->net))
2789 urb = usb_alloc_urb (0, GFP_KERNEL);
2790 else
2791 clear_bit (EVENT_RX_MEMORY, &dev->flags);
2792 if (urb != NULL) {
2793 clear_bit (EVENT_RX_MEMORY, &dev->flags);
2794 rx_submit (dev, urb, GFP_KERNEL);
2795 tasklet_schedule (&dev->bh);
2796 }
2797 }
2798
2799 if (dev->flags)
2800 devdbg (dev, "kevent done, flags = 0x%lx",
2801 dev->flags);
2802}
2803
2804
2805
2806static void tx_complete (struct urb *urb, struct pt_regs *regs)
2807{
2808 struct sk_buff *skb = (struct sk_buff *) urb->context;
2809 struct skb_data *entry = (struct skb_data *) skb->cb;
2810 struct usbnet *dev = entry->dev;
2811
2812 if (urb->status == 0) {
2813 dev->stats.tx_packets++;
2814 dev->stats.tx_bytes += entry->length;
2815 } else {
2816 dev->stats.tx_errors++;
2817
2818 switch (urb->status) {
2819 case -EPIPE:
2820 defer_kevent (dev, EVENT_TX_HALT);
2821 break;
2822
2823
2824
2825 case -EPROTO:
2826 case -ETIMEDOUT:
2827 case -EILSEQ:
2828 if (!timer_pending (&dev->delay)) {
2829 mod_timer (&dev->delay,
2830 jiffies + THROTTLE_JIFFIES);
2831 devdbg (dev, "tx throttle %d", urb->status);
2832 }
2833 netif_stop_queue (dev->net);
2834 break;
2835 default:
2836 devdbg (dev, "tx err %d", entry->urb->status);
2837 break;
2838 }
2839 }
2840
2841 urb->dev = NULL;
2842 entry->state = tx_done;
2843 defer_bh (dev, skb);
2844}
2845
2846
2847
2848static void usbnet_tx_timeout (struct net_device *net)
2849{
2850 struct usbnet *dev = netdev_priv(net);
2851
2852 unlink_urbs (dev, &dev->txq);
2853 tasklet_schedule (&dev->bh);
2854
2855
2856}
2857
2858
2859
2860static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net)
2861{
2862 struct usbnet *dev = netdev_priv(net);
2863 int length;
2864 int retval = NET_XMIT_SUCCESS;
2865 struct urb *urb = NULL;
2866 struct skb_data *entry;
2867 struct driver_info *info = dev->driver_info;
2868 unsigned long flags;
2869#ifdef CONFIG_USB_NET1080
2870 struct nc_header *header = NULL;
2871 struct nc_trailer *trailer = NULL;
2872#endif
2873
2874
2875
2876 if (info->tx_fixup) {
2877 skb = info->tx_fixup (dev, skb, GFP_ATOMIC);
2878 if (!skb) {
2879 devdbg (dev, "can't tx_fixup skb");
2880 goto drop;
2881 }
2882 }
2883 length = skb->len;
2884
2885 if (!(urb = usb_alloc_urb (0, GFP_ATOMIC))) {
2886 devdbg (dev, "no urb");
2887 goto drop;
2888 }
2889
2890 entry = (struct skb_data *) skb->cb;
2891 entry->urb = urb;
2892 entry->dev = dev;
2893 entry->state = tx_start;
2894 entry->length = length;
2895
2896
2897
2898
2899
2900#ifdef CONFIG_USB_NET1080
2901 if (info->flags & FLAG_FRAMING_NC) {
2902 header = (struct nc_header *) skb_push (skb, sizeof *header);
2903 header->hdr_len = cpu_to_le16 (sizeof (*header));
2904 header->packet_len = cpu_to_le16 (length);
2905 if (!((skb->len + sizeof *trailer) & 0x01))
2906 *skb_put (skb, 1) = PAD_BYTE;
2907 trailer = (struct nc_trailer *) skb_put (skb, sizeof *trailer);
2908 }
2909#endif
2910
2911 usb_fill_bulk_urb (urb, dev->udev, dev->out,
2912 skb->data, skb->len, tx_complete, skb);
2913 urb->transfer_flags |= URB_ASYNC_UNLINK;
2914
2915
2916
2917
2918
2919
2920
2921 if ((length % dev->maxpacket) == 0)
2922 urb->transfer_buffer_length++;
2923
2924 spin_lock_irqsave (&dev->txq.lock, flags);
2925
2926#ifdef CONFIG_USB_NET1080
2927 if (info->flags & FLAG_FRAMING_NC) {
2928 header->packet_id = cpu_to_le16 ((u16)dev->dev_packet_id++);
2929 put_unaligned (header->packet_id, &trailer->packet_id);
2930#if 0
2931 devdbg (dev, "frame >tx h %d p %d id %d",
2932 header->hdr_len, header->packet_len,
2933 header->packet_id);
2934#endif
2935 }
2936#endif
2937
2938 switch ((retval = usb_submit_urb (urb, GFP_ATOMIC))) {
2939 case -EPIPE:
2940 netif_stop_queue (net);
2941 defer_kevent (dev, EVENT_TX_HALT);
2942 break;
2943 default:
2944 devdbg (dev, "tx: submit urb err %d", retval);
2945 break;
2946 case 0:
2947 net->trans_start = jiffies;
2948 __skb_queue_tail (&dev->txq, skb);
2949 if (dev->txq.qlen >= TX_QLEN (dev))
2950 netif_stop_queue (net);
2951 }
2952 spin_unlock_irqrestore (&dev->txq.lock, flags);
2953
2954 if (retval) {
2955 devdbg (dev, "drop, code %d", retval);
2956drop:
2957 retval = NET_XMIT_SUCCESS;
2958 dev->stats.tx_dropped++;
2959 if (skb)
2960 dev_kfree_skb_any (skb);
2961 usb_free_urb (urb);
2962#ifdef VERBOSE
2963 } else {
2964 devdbg (dev, "> tx, len %d, type 0x%x",
2965 length, skb->protocol);
2966#endif
2967 }
2968 return retval;
2969}
2970
2971
2972
2973
2974
2975
2976static void usbnet_bh (unsigned long param)
2977{
2978 struct usbnet *dev = (struct usbnet *) param;
2979 struct sk_buff *skb;
2980 struct skb_data *entry;
2981
2982 while ((skb = skb_dequeue (&dev->done))) {
2983 entry = (struct skb_data *) skb->cb;
2984 switch (entry->state) {
2985 case rx_done:
2986 entry->state = rx_cleanup;
2987 rx_process (dev, skb);
2988 continue;
2989 case tx_done:
2990 case rx_cleanup:
2991 usb_free_urb (entry->urb);
2992 dev_kfree_skb (skb);
2993 continue;
2994 default:
2995 devdbg (dev, "bogus skb state %d", entry->state);
2996 }
2997 }
2998
2999
3000 if (dev->wait) {
3001 if ((dev->txq.qlen + dev->rxq.qlen + dev->done.qlen) == 0) {
3002 wake_up (dev->wait);
3003 }
3004
3005
3006 } else if (netif_running (dev->net)
3007 && netif_device_present (dev->net)
3008 && !timer_pending (&dev->delay)
3009 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
3010 int temp = dev->rxq.qlen;
3011 int qlen = RX_QLEN (dev);
3012
3013 if (temp < qlen) {
3014 struct urb *urb;
3015 int i;
3016
3017
3018 for (i = 0; i < 10 && dev->rxq.qlen < qlen; i++) {
3019 urb = usb_alloc_urb (0, GFP_ATOMIC);
3020 if (urb != NULL)
3021 rx_submit (dev, urb, GFP_ATOMIC);
3022 }
3023 if (temp != dev->rxq.qlen)
3024 devdbg (dev, "rxqlen %d --> %d",
3025 temp, dev->rxq.qlen);
3026 if (dev->rxq.qlen < qlen)
3027 tasklet_schedule (&dev->bh);
3028 }
3029 if (dev->txq.qlen < TX_QLEN (dev))
3030 netif_wake_queue (dev->net);
3031 }
3032}
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044static void usbnet_disconnect (struct usb_interface *intf)
3045{
3046 struct usbnet *dev;
3047 struct usb_device *xdev;
3048 struct net_device *net;
3049
3050 dev = usb_get_intfdata(intf);
3051 usb_set_intfdata(intf, NULL);
3052 if (!dev)
3053 return;
3054
3055 xdev = interface_to_usbdev (intf);
3056
3057 devinfo (dev, "unregister usbnet usb-%s-%s, %s",
3058 xdev->bus->bus_name, xdev->devpath,
3059 dev->driver_info->description);
3060
3061 net = dev->net;
3062 unregister_netdev (net);
3063
3064
3065 flush_scheduled_work ();
3066
3067 if (dev->driver_info->unbind)
3068 dev->driver_info->unbind (dev, intf);
3069
3070 free_netdev(net);
3071 usb_put_dev (xdev);
3072}
3073
3074
3075
3076
3077static struct ethtool_ops usbnet_ethtool_ops;
3078
3079
3080
3081static int
3082usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
3083{
3084 struct usbnet *dev;
3085 struct net_device *net;
3086 struct usb_host_interface *interface;
3087 struct driver_info *info;
3088 struct usb_device *xdev;
3089 int status;
3090
3091 info = (struct driver_info *) prod->driver_info;
3092 if (!info) {
3093 dev_dbg (&udev->dev, "blacklisted by %s\n", driver_name);
3094 return -ENODEV;
3095 }
3096 xdev = interface_to_usbdev (udev);
3097 interface = udev->cur_altsetting;
3098
3099 usb_get_dev (xdev);
3100
3101 status = -ENOMEM;
3102
3103
3104 net = alloc_etherdev(sizeof(*dev));
3105 if (!net) {
3106 dbg ("can't kmalloc dev");
3107 goto out;
3108 }
3109
3110 dev = netdev_priv(net);
3111 dev->udev = xdev;
3112 dev->driver_info = info;
3113 dev->msg_level = msg_level;
3114 skb_queue_head_init (&dev->rxq);
3115 skb_queue_head_init (&dev->txq);
3116 skb_queue_head_init (&dev->done);
3117 dev->bh.func = usbnet_bh;
3118 dev->bh.data = (unsigned long) dev;
3119 INIT_WORK (&dev->kevent, kevent, dev);
3120 dev->delay.function = usbnet_bh;
3121 dev->delay.data = (unsigned long) dev;
3122 init_timer (&dev->delay);
3123
3124 SET_MODULE_OWNER (net);
3125 dev->net = net;
3126 strcpy (net->name, "usb%d");
3127 memcpy (net->dev_addr, node_id, sizeof node_id);
3128
3129#if 0
3130
3131
3132 if (dma_supported (&udev->dev, 0xffffffffffffffffULL))
3133 net->features |= NETIF_F_HIGHDMA;
3134#endif
3135
3136 net->change_mtu = usbnet_change_mtu;
3137 net->get_stats = usbnet_get_stats;
3138 net->hard_start_xmit = usbnet_start_xmit;
3139 net->open = usbnet_open;
3140 net->stop = usbnet_stop;
3141 net->watchdog_timeo = TX_TIMEOUT_JIFFIES;
3142 net->tx_timeout = usbnet_tx_timeout;
3143 net->do_ioctl = usbnet_ioctl;
3144 net->ethtool_ops = &usbnet_ethtool_ops;
3145
3146
3147
3148 if (info->bind) {
3149 status = info->bind (dev, udev);
3150
3151
3152
3153 if ((dev->driver_info->flags & FLAG_ETHER) != 0
3154 && (net->dev_addr [0] & 0x02) == 0)
3155 strcpy (net->name, "eth%d");
3156 } else if (!info->in || info->out)
3157 status = get_endpoints (dev, udev);
3158 else {
3159 dev->in = usb_rcvbulkpipe (xdev, info->in);
3160 dev->out = usb_sndbulkpipe (xdev, info->out);
3161 if (!(info->flags & FLAG_NO_SETINT))
3162 status = usb_set_interface (xdev,
3163 interface->desc.bInterfaceNumber,
3164 interface->desc.bAlternateSetting);
3165 else
3166 status = 0;
3167
3168 }
3169 if (status < 0)
3170 goto out1;
3171
3172 dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1);
3173
3174 SET_NETDEV_DEV(net, &udev->dev);
3175 status = register_netdev (net);
3176 if (status)
3177 goto out3;
3178 devinfo (dev, "register usbnet at usb-%s-%s, %s",
3179 xdev->bus->bus_name, xdev->devpath,
3180 dev->driver_info->description);
3181
3182
3183 usb_set_intfdata (udev, dev);
3184
3185
3186 netif_device_attach (net);
3187
3188 return 0;
3189
3190out3:
3191 if (info->unbind)
3192 info->unbind (dev, udev);
3193out1:
3194 free_netdev(net);
3195out:
3196 usb_put_dev(xdev);
3197 return status;
3198}
3199
3200
3201
3202
3203#ifndef HAVE_HARDWARE
3204#error You need to configure some hardware for this driver
3205#endif
3206
3207
3208
3209
3210
3211
3212static const struct usb_device_id products [] = {
3213
3214#ifdef CONFIG_USB_ALI_M5632
3215{
3216 USB_DEVICE (0x0402, 0x5632),
3217 .driver_info = (unsigned long) &ali_m5632_info,
3218},
3219#endif
3220
3221#ifdef CONFIG_USB_AN2720
3222{
3223 USB_DEVICE (0x0547, 0x2720),
3224 .driver_info = (unsigned long) &an2720_info,
3225}, {
3226 USB_DEVICE (0x0547, 0x2727),
3227 .driver_info = (unsigned long) &an2720_info,
3228},
3229#endif
3230
3231#ifdef CONFIG_USB_BELKIN
3232{
3233 USB_DEVICE (0x050d, 0x0004),
3234 .driver_info = (unsigned long) &belkin_info,
3235}, {
3236 USB_DEVICE (0x056c, 0x8100),
3237 .driver_info = (unsigned long) &belkin_info,
3238}, {
3239 USB_DEVICE (0x0525, 0x9901),
3240 .driver_info = (unsigned long) &belkin_info,
3241},
3242#endif
3243
3244#ifdef CONFIG_USB_AX8817X
3245{
3246
3247 USB_DEVICE (0x077b, 0x2226),
3248 .driver_info = (unsigned long) &ax8817x_info,
3249}, {
3250
3251 USB_DEVICE (0x0846, 0x1040),
3252 .driver_info = (unsigned long) &netgear_fa120_info,
3253}, {
3254
3255 USB_DEVICE (0x2001, 0x1a00),
3256 .driver_info = (unsigned long) &dlink_dub_e100_info,
3257}, {
3258
3259 USB_DEVICE (0x0b95, 0x1720),
3260 .driver_info = (unsigned long) &ax8817x_info,
3261}, {
3262
3263 USB_DEVICE (0x07b8, 0x420a),
3264 .driver_info = (unsigned long) &hawking_uf200_info,
3265}, {
3266
3267 USB_DEVICE (0x08dd, 0x90ff),
3268 .driver_info = (unsigned long) &ax8817x_info,
3269}, {
3270
3271 USB_DEVICE (0x0557, 0x2009),
3272 .driver_info = (unsigned long) &ax8817x_info,
3273}, {
3274
3275 USB_DEVICE (0x0411, 0x003d),
3276 .driver_info = (unsigned long) &ax8817x_info,
3277}, {
3278
3279 USB_DEVICE (0x6189, 0x182d),
3280 .driver_info = (unsigned long) &ax8817x_info,
3281}, {
3282
3283 USB_DEVICE (0x07aa, 0x0017),
3284 .driver_info = (unsigned long) &ax8817x_info,
3285}, {
3286
3287 USB_DEVICE (0x1189, 0x0893),
3288 .driver_info = (unsigned long) &ax8817x_info,
3289}, {
3290
3291 USB_DEVICE (0x1631, 0x6200),
3292 .driver_info = (unsigned long) &ax8817x_info,
3293},
3294#endif
3295
3296#ifdef CONFIG_USB_EPSON2888
3297{
3298 USB_DEVICE (0x0525, 0x2888),
3299 .driver_info = (unsigned long) &epson2888_info,
3300},
3301#endif
3302
3303#ifdef CONFIG_USB_GENESYS
3304{
3305 USB_DEVICE (0x05e3, 0x0502),
3306 .driver_info = (unsigned long) &genelink_info,
3307},
3308
3309
3310
3311#endif
3312
3313#ifdef CONFIG_USB_NET1080
3314{
3315 USB_DEVICE (0x0525, 0x1080),
3316 .driver_info = (unsigned long) &net1080_info,
3317}, {
3318 USB_DEVICE (0x06D0, 0x0622),
3319 .driver_info = (unsigned long) &net1080_info,
3320},
3321#endif
3322
3323#ifdef CONFIG_USB_PL2301
3324{
3325 USB_DEVICE (0x067b, 0x0000),
3326 .driver_info = (unsigned long) &prolific_info,
3327}, {
3328 USB_DEVICE (0x067b, 0x0001),
3329 .driver_info = (unsigned long) &prolific_info,
3330},
3331#endif
3332
3333#ifdef CONFIG_USB_KC2190
3334{
3335 USB_DEVICE (0x050f, 0x0190),
3336 .driver_info = (unsigned long) &kc2190_info,
3337},
3338#endif
3339
3340#ifdef CONFIG_USB_RNDIS
3341{
3342
3343 USB_INTERFACE_INFO (USB_CLASS_COMM, 2 , 0x0ff),
3344 .driver_info = (unsigned long) &rndis_info,
3345},
3346#endif
3347
3348#ifdef CONFIG_USB_ARMLINUX
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364{
3365
3366
3367 USB_DEVICE (0x049F, 0x505A),
3368 .driver_info = (unsigned long) &linuxdev_info,
3369}, {
3370 USB_DEVICE (0x0E7E, 0x1001),
3371 .driver_info = (unsigned long) &yopy_info,
3372}, {
3373 USB_DEVICE (0x8086, 0x07d3),
3374 .driver_info = (unsigned long) &blob_info,
3375}, {
3376
3377 USB_DEVICE_VER (0x0525, 0xa4a2, 0x0203, 0x0203),
3378 .driver_info = (unsigned long) &linuxdev_info,
3379},
3380#endif
3381
3382#if defined(CONFIG_USB_ZAURUS) || defined(CONFIG_USB_CDCETHER)
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392{
3393 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3394 | USB_DEVICE_ID_MATCH_DEVICE,
3395 .idVendor = 0x04DD,
3396 .idProduct = 0x8004,
3397
3398 .bInterfaceClass = USB_CLASS_COMM,
3399 .bInterfaceSubClass = 6 ,
3400 .bInterfaceProtocol = 0,
3401 .driver_info = ZAURUS_STRONGARM_INFO,
3402}, {
3403 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3404 | USB_DEVICE_ID_MATCH_DEVICE,
3405 .idVendor = 0x04DD,
3406 .idProduct = 0x8005,
3407 .bInterfaceClass = USB_CLASS_COMM,
3408 .bInterfaceSubClass = 6 ,
3409 .bInterfaceProtocol = 0x00,
3410 .driver_info = ZAURUS_PXA_INFO,
3411}, {
3412 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3413 | USB_DEVICE_ID_MATCH_DEVICE,
3414 .idVendor = 0x04DD,
3415 .idProduct = 0x8006,
3416 .bInterfaceClass = USB_CLASS_COMM,
3417 .bInterfaceSubClass = 6 ,
3418 .bInterfaceProtocol = 0x00,
3419 .driver_info = ZAURUS_PXA_INFO,
3420}, {
3421 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3422 | USB_DEVICE_ID_MATCH_DEVICE,
3423 .idVendor = 0x04DD,
3424 .idProduct = 0x8007,
3425 .bInterfaceClass = USB_CLASS_COMM,
3426 .bInterfaceSubClass = 6 ,
3427 .bInterfaceProtocol = 0x00,
3428 .driver_info = ZAURUS_PXA_INFO,
3429}, {
3430 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3431 | USB_DEVICE_ID_MATCH_DEVICE,
3432 .idVendor = 0x04DD,
3433 .idProduct = 0x9031,
3434 .bInterfaceClass = USB_CLASS_COMM,
3435 .bInterfaceSubClass = 6 ,
3436 .bInterfaceProtocol = 0x00,
3437 .driver_info = ZAURUS_PXA_INFO,
3438}, {
3439 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3440 | USB_DEVICE_ID_MATCH_DEVICE,
3441 .idVendor = 0x04DD,
3442 .idProduct = 0x9032,
3443 .bInterfaceClass = USB_CLASS_COMM,
3444 .bInterfaceSubClass = 6 ,
3445 .bInterfaceProtocol = 0x00,
3446 .driver_info = ZAURUS_PXA_INFO,
3447}, {
3448 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3449 | USB_DEVICE_ID_MATCH_DEVICE,
3450 .idVendor = 0x04DD,
3451 .idProduct = 0x9050,
3452 .bInterfaceClass = USB_CLASS_COMM,
3453 .bInterfaceSubClass = 6 ,
3454 .bInterfaceProtocol = 0x00,
3455 .driver_info = ZAURUS_PXA_INFO,
3456},
3457
3458
3459
3460
3461{
3462 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3463 | USB_DEVICE_ID_MATCH_DEVICE,
3464 .idVendor = 0x07B4,
3465 .idProduct = 0x0F02,
3466 .bInterfaceClass = USB_CLASS_COMM,
3467 .bInterfaceSubClass = 6 ,
3468 .bInterfaceProtocol = 0x00,
3469 .driver_info = OLYMPUS_MXL_INFO,
3470},
3471#endif
3472
3473#ifdef CONFIG_USB_CDCETHER
3474{
3475
3476
3477
3478
3479
3480
3481
3482
3483 USB_INTERFACE_INFO (USB_CLASS_COMM, 6 , 0),
3484 .driver_info = (unsigned long) &cdc_info,
3485},
3486#endif
3487
3488 { },
3489};
3490MODULE_DEVICE_TABLE (usb, products);
3491
3492static struct usb_driver usbnet_driver = {
3493 .owner = THIS_MODULE,
3494 .name = driver_name,
3495 .id_table = products,
3496 .probe = usbnet_probe,
3497 .disconnect = usbnet_disconnect,
3498};
3499
3500
3501static struct ethtool_ops usbnet_ethtool_ops = {
3502 .get_drvinfo = usbnet_get_drvinfo,
3503 .get_link = usbnet_get_link,
3504 .get_msglevel = usbnet_get_msglevel,
3505 .set_msglevel = usbnet_set_msglevel,
3506};
3507
3508
3509
3510static int __init usbnet_init (void)
3511{
3512
3513 BUG_ON (sizeof (((struct sk_buff *)0)->cb)
3514 < sizeof (struct skb_data));
3515#ifdef CONFIG_USB_CDCETHER
3516 BUG_ON ((sizeof (((struct usbnet *)0)->data)
3517 < sizeof (struct cdc_state)));
3518#endif
3519
3520 random_ether_addr(node_id);
3521
3522 return usb_register(&usbnet_driver);
3523}
3524module_init (usbnet_init);
3525
3526static void __exit usbnet_exit (void)
3527{
3528 usb_deregister (&usbnet_driver);
3529}
3530module_exit (usbnet_exit);
3531
3532MODULE_AUTHOR ("David Brownell <dbrownell@users.sourceforge.net>");
3533MODULE_DESCRIPTION ("USB Host-to-Host Link Drivers (numerous vendors)");
3534MODULE_LICENSE ("GPL");
3535