1
2
3
4
5
6
7
8
9
10
11#include <common.h>
12#include <console.h>
13#include <asm/errno.h>
14#include <linux/netdevice.h>
15#include <linux/usb/ch9.h>
16#include <linux/usb/cdc.h>
17#include <linux/usb/gadget.h>
18#include <net.h>
19#include <usb.h>
20#include <malloc.h>
21#include <memalign.h>
22#include <linux/ctype.h>
23
24#include "gadget_chips.h"
25#include "rndis.h"
26
27#define USB_NET_NAME "usb_ether"
28
29#define atomic_read
30extern struct platform_data brd;
31
32
33unsigned packet_received, packet_sent;
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#define ETH_ALEN 6
70#define ETH_HLEN 14
71#define ETH_ZLEN 60
72#define ETH_DATA_LEN 1500
73#define ETH_FRAME_LEN PKTSIZE_ALIGN
74
75#define DRIVER_DESC "Ethernet Gadget"
76
77#define DRIVER_VERSION "May Day 2005"
78
79static const char shortname[] = "ether";
80static const char driver_desc[] = DRIVER_DESC;
81
82#define RX_EXTRA 20
83
84#ifndef CONFIG_USB_ETH_RNDIS
85#define rndis_uninit(x) do {} while (0)
86#define rndis_deregister(c) do {} while (0)
87#define rndis_exit() do {} while (0)
88#endif
89
90
91#define DEFAULT_FILTER (USB_CDC_PACKET_TYPE_BROADCAST \
92 |USB_CDC_PACKET_TYPE_ALL_MULTICAST \
93 |USB_CDC_PACKET_TYPE_PROMISCUOUS \
94 |USB_CDC_PACKET_TYPE_DIRECTED)
95
96#define USB_CONNECT_TIMEOUT (3 * CONFIG_SYS_HZ)
97
98
99
100struct eth_dev {
101 struct usb_gadget *gadget;
102 struct usb_request *req;
103 struct usb_request *stat_req;
104
105 u8 config;
106 struct usb_ep *in_ep, *out_ep, *status_ep;
107 const struct usb_endpoint_descriptor
108 *in, *out, *status;
109
110 struct usb_request *tx_req, *rx_req;
111
112 struct eth_device *net;
113 struct net_device_stats stats;
114 unsigned int tx_qlen;
115
116 unsigned zlp:1;
117 unsigned cdc:1;
118 unsigned rndis:1;
119 unsigned suspended:1;
120 unsigned network_started:1;
121 u16 cdc_filter;
122 unsigned long todo;
123 int mtu;
124#define WORK_RX_MEMORY 0
125 int rndis_config;
126 u8 host_mac[ETH_ALEN];
127};
128
129
130
131
132
133
134
135
136
137static struct eth_dev l_ethdev;
138static struct eth_device l_netdev;
139static struct usb_gadget_driver eth_driver;
140
141
142
143
144static inline int is_cdc(struct eth_dev *dev)
145{
146#if !defined(CONFIG_USB_ETH_SUBSET)
147 return 1;
148#elif !defined(CONFIG_USB_ETH_CDC)
149 return 0;
150#else
151 return dev->cdc;
152#endif
153}
154
155
156static inline int rndis_active(struct eth_dev *dev)
157{
158#ifdef CONFIG_USB_ETH_RNDIS
159 return dev->rndis;
160#else
161 return 0;
162#endif
163}
164
165#define subset_active(dev) (!is_cdc(dev) && !rndis_active(dev))
166#define cdc_active(dev) (is_cdc(dev) && !rndis_active(dev))
167
168#define DEFAULT_QLEN 2
169
170
171#define HS_BPS (13 * 512 * 8 * 1000 * 8)
172#define FS_BPS (19 * 64 * 1 * 1000 * 8)
173
174#ifdef CONFIG_USB_GADGET_DUALSPEED
175#define DEVSPEED USB_SPEED_HIGH
176
177#ifdef CONFIG_USB_ETH_QMULT
178#define qmult CONFIG_USB_ETH_QMULT
179#else
180#define qmult 5
181#endif
182
183
184#define qlen(gadget) \
185 (DEFAULT_QLEN*((gadget->speed == USB_SPEED_HIGH) ? qmult : 1))
186
187static inline int BITRATE(struct usb_gadget *g)
188{
189 return (g->speed == USB_SPEED_HIGH) ? HS_BPS : FS_BPS;
190}
191
192#else
193
194#define qmult 1
195
196#define DEVSPEED USB_SPEED_FULL
197
198#define qlen(gadget) DEFAULT_QLEN
199
200static inline int BITRATE(struct usb_gadget *g)
201{
202 return FS_BPS;
203}
204#endif
205
206
207
208
209
210
211
212
213
214
215
216
217#define CDC_VENDOR_NUM 0x0525
218#define CDC_PRODUCT_NUM 0xa4a1
219
220
221
222
223
224
225
226
227
228
229
230
231
232#define SIMPLE_VENDOR_NUM 0x049f
233#define SIMPLE_PRODUCT_NUM 0x505a
234
235
236
237
238
239
240
241#define RNDIS_VENDOR_NUM 0x0525
242#define RNDIS_PRODUCT_NUM 0xa4a2
243
244
245
246
247
248
249
250
251
252
253
254
255
256#if defined(CONFIG_USBNET_MANUFACTURER)
257static char *iManufacturer = CONFIG_USBNET_MANUFACTURER;
258#else
259static char *iManufacturer = "U-Boot";
260#endif
261
262
263static ushort bcdDevice;
264static char *iProduct;
265static char *iSerialNumber;
266
267static char dev_addr[18];
268
269static char host_addr[18];
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291#define STRING_MANUFACTURER 1
292#define STRING_PRODUCT 2
293#define STRING_ETHADDR 3
294#define STRING_DATA 4
295#define STRING_CONTROL 5
296#define STRING_RNDIS_CONTROL 6
297#define STRING_CDC 7
298#define STRING_SUBSET 8
299#define STRING_RNDIS 9
300#define STRING_SERIALNUMBER 10
301
302
303#define USB_BUFSIZ 256
304
305
306
307
308
309
310
311
312
313
314
315
316#define DEV_CONFIG_VALUE 1
317#define DEV_RNDIS_CONFIG_VALUE 2
318
319static struct usb_device_descriptor
320device_desc = {
321 .bLength = sizeof device_desc,
322 .bDescriptorType = USB_DT_DEVICE,
323
324 .bcdUSB = __constant_cpu_to_le16(0x0200),
325
326 .bDeviceClass = USB_CLASS_COMM,
327 .bDeviceSubClass = 0,
328 .bDeviceProtocol = 0,
329
330 .idVendor = __constant_cpu_to_le16(CDC_VENDOR_NUM),
331 .idProduct = __constant_cpu_to_le16(CDC_PRODUCT_NUM),
332 .iManufacturer = STRING_MANUFACTURER,
333 .iProduct = STRING_PRODUCT,
334 .bNumConfigurations = 1,
335};
336
337static struct usb_otg_descriptor
338otg_descriptor = {
339 .bLength = sizeof otg_descriptor,
340 .bDescriptorType = USB_DT_OTG,
341
342 .bmAttributes = USB_OTG_SRP,
343};
344
345static struct usb_config_descriptor
346eth_config = {
347 .bLength = sizeof eth_config,
348 .bDescriptorType = USB_DT_CONFIG,
349
350
351 .bNumInterfaces = 2,
352 .bConfigurationValue = DEV_CONFIG_VALUE,
353 .iConfiguration = STRING_CDC,
354 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
355 .bMaxPower = 1,
356};
357
358#ifdef CONFIG_USB_ETH_RNDIS
359static struct usb_config_descriptor
360rndis_config = {
361 .bLength = sizeof rndis_config,
362 .bDescriptorType = USB_DT_CONFIG,
363
364
365 .bNumInterfaces = 2,
366 .bConfigurationValue = DEV_RNDIS_CONFIG_VALUE,
367 .iConfiguration = STRING_RNDIS,
368 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
369 .bMaxPower = 1,
370};
371#endif
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392#ifdef CONFIG_USB_ETH_CDC
393static struct usb_interface_descriptor
394control_intf = {
395 .bLength = sizeof control_intf,
396 .bDescriptorType = USB_DT_INTERFACE,
397
398 .bInterfaceNumber = 0,
399
400 .bNumEndpoints = 1,
401 .bInterfaceClass = USB_CLASS_COMM,
402 .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET,
403 .bInterfaceProtocol = USB_CDC_PROTO_NONE,
404 .iInterface = STRING_CONTROL,
405};
406#endif
407
408#ifdef CONFIG_USB_ETH_RNDIS
409static const struct usb_interface_descriptor
410rndis_control_intf = {
411 .bLength = sizeof rndis_control_intf,
412 .bDescriptorType = USB_DT_INTERFACE,
413
414 .bInterfaceNumber = 0,
415 .bNumEndpoints = 1,
416 .bInterfaceClass = USB_CLASS_COMM,
417 .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM,
418 .bInterfaceProtocol = USB_CDC_ACM_PROTO_VENDOR,
419 .iInterface = STRING_RNDIS_CONTROL,
420};
421#endif
422
423static const struct usb_cdc_header_desc header_desc = {
424 .bLength = sizeof header_desc,
425 .bDescriptorType = USB_DT_CS_INTERFACE,
426 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
427
428 .bcdCDC = __constant_cpu_to_le16(0x0110),
429};
430
431#if defined(CONFIG_USB_ETH_CDC) || defined(CONFIG_USB_ETH_RNDIS)
432
433static const struct usb_cdc_union_desc union_desc = {
434 .bLength = sizeof union_desc,
435 .bDescriptorType = USB_DT_CS_INTERFACE,
436 .bDescriptorSubType = USB_CDC_UNION_TYPE,
437
438 .bMasterInterface0 = 0,
439 .bSlaveInterface0 = 1,
440};
441
442#endif
443
444#ifdef CONFIG_USB_ETH_RNDIS
445
446static const struct usb_cdc_call_mgmt_descriptor call_mgmt_descriptor = {
447 .bLength = sizeof call_mgmt_descriptor,
448 .bDescriptorType = USB_DT_CS_INTERFACE,
449 .bDescriptorSubType = USB_CDC_CALL_MANAGEMENT_TYPE,
450
451 .bmCapabilities = 0x00,
452 .bDataInterface = 0x01,
453};
454
455static const struct usb_cdc_acm_descriptor acm_descriptor = {
456 .bLength = sizeof acm_descriptor,
457 .bDescriptorType = USB_DT_CS_INTERFACE,
458 .bDescriptorSubType = USB_CDC_ACM_TYPE,
459
460 .bmCapabilities = 0x00,
461};
462
463#endif
464
465#ifndef CONFIG_USB_ETH_CDC
466
467
468
469
470
471
472
473static const struct usb_cdc_mdlm_desc mdlm_desc = {
474 .bLength = sizeof mdlm_desc,
475 .bDescriptorType = USB_DT_CS_INTERFACE,
476 .bDescriptorSubType = USB_CDC_MDLM_TYPE,
477
478 .bcdVersion = __constant_cpu_to_le16(0x0100),
479 .bGUID = {
480 0x5d, 0x34, 0xcf, 0x66, 0x11, 0x18, 0x11, 0xd6,
481 0xa2, 0x1a, 0x00, 0x01, 0x02, 0xca, 0x9a, 0x7f,
482 },
483};
484
485
486
487
488
489
490static const u8 mdlm_detail_desc[] = {
491 6,
492 USB_DT_CS_INTERFACE,
493 USB_CDC_MDLM_DETAIL_TYPE,
494
495 0,
496 0,
497 0,
498};
499
500#endif
501
502static const struct usb_cdc_ether_desc ether_desc = {
503 .bLength = sizeof(ether_desc),
504 .bDescriptorType = USB_DT_CS_INTERFACE,
505 .bDescriptorSubType = USB_CDC_ETHERNET_TYPE,
506
507
508 .iMACAddress = STRING_ETHADDR,
509 .bmEthernetStatistics = __constant_cpu_to_le32(0),
510 .wMaxSegmentSize = __constant_cpu_to_le16(ETH_FRAME_LEN),
511 .wNumberMCFilters = __constant_cpu_to_le16(0),
512 .bNumberPowerFilters = 0,
513};
514
515#if defined(CONFIG_USB_ETH_CDC) || defined(CONFIG_USB_ETH_RNDIS)
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532#define LOG2_STATUS_INTERVAL_MSEC 5
533#define STATUS_BYTECOUNT 16
534
535static struct usb_endpoint_descriptor
536fs_status_desc = {
537 .bLength = USB_DT_ENDPOINT_SIZE,
538 .bDescriptorType = USB_DT_ENDPOINT,
539
540 .bEndpointAddress = USB_DIR_IN,
541 .bmAttributes = USB_ENDPOINT_XFER_INT,
542 .wMaxPacketSize = __constant_cpu_to_le16(STATUS_BYTECOUNT),
543 .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC,
544};
545#endif
546
547#ifdef CONFIG_USB_ETH_CDC
548
549
550
551static const struct usb_interface_descriptor
552data_nop_intf = {
553 .bLength = sizeof data_nop_intf,
554 .bDescriptorType = USB_DT_INTERFACE,
555
556 .bInterfaceNumber = 1,
557 .bAlternateSetting = 0,
558 .bNumEndpoints = 0,
559 .bInterfaceClass = USB_CLASS_CDC_DATA,
560 .bInterfaceSubClass = 0,
561 .bInterfaceProtocol = 0,
562};
563
564
565
566static const struct usb_interface_descriptor
567data_intf = {
568 .bLength = sizeof data_intf,
569 .bDescriptorType = USB_DT_INTERFACE,
570
571 .bInterfaceNumber = 1,
572 .bAlternateSetting = 1,
573 .bNumEndpoints = 2,
574 .bInterfaceClass = USB_CLASS_CDC_DATA,
575 .bInterfaceSubClass = 0,
576 .bInterfaceProtocol = 0,
577 .iInterface = STRING_DATA,
578};
579
580#endif
581
582#ifdef CONFIG_USB_ETH_RNDIS
583
584
585
586static const struct usb_interface_descriptor
587rndis_data_intf = {
588 .bLength = sizeof rndis_data_intf,
589 .bDescriptorType = USB_DT_INTERFACE,
590
591 .bInterfaceNumber = 1,
592 .bAlternateSetting = 0,
593 .bNumEndpoints = 2,
594 .bInterfaceClass = USB_CLASS_CDC_DATA,
595 .bInterfaceSubClass = 0,
596 .bInterfaceProtocol = 0,
597 .iInterface = STRING_DATA,
598};
599
600#endif
601
602#ifdef CONFIG_USB_ETH_SUBSET
603
604
605
606
607
608
609
610
611
612static const struct usb_interface_descriptor
613subset_data_intf = {
614 .bLength = sizeof subset_data_intf,
615 .bDescriptorType = USB_DT_INTERFACE,
616
617 .bInterfaceNumber = 0,
618 .bAlternateSetting = 0,
619 .bNumEndpoints = 2,
620 .bInterfaceClass = USB_CLASS_COMM,
621 .bInterfaceSubClass = USB_CDC_SUBCLASS_MDLM,
622 .bInterfaceProtocol = 0,
623 .iInterface = STRING_DATA,
624};
625
626#endif
627
628static struct usb_endpoint_descriptor
629fs_source_desc = {
630 .bLength = USB_DT_ENDPOINT_SIZE,
631 .bDescriptorType = USB_DT_ENDPOINT,
632
633 .bEndpointAddress = USB_DIR_IN,
634 .bmAttributes = USB_ENDPOINT_XFER_BULK,
635 .wMaxPacketSize = __constant_cpu_to_le16(64),
636};
637
638static struct usb_endpoint_descriptor
639fs_sink_desc = {
640 .bLength = USB_DT_ENDPOINT_SIZE,
641 .bDescriptorType = USB_DT_ENDPOINT,
642
643 .bEndpointAddress = USB_DIR_OUT,
644 .bmAttributes = USB_ENDPOINT_XFER_BULK,
645 .wMaxPacketSize = __constant_cpu_to_le16(64),
646};
647
648static const struct usb_descriptor_header *fs_eth_function[11] = {
649 (struct usb_descriptor_header *) &otg_descriptor,
650#ifdef CONFIG_USB_ETH_CDC
651
652 (struct usb_descriptor_header *) &control_intf,
653 (struct usb_descriptor_header *) &header_desc,
654 (struct usb_descriptor_header *) &union_desc,
655 (struct usb_descriptor_header *) ðer_desc,
656
657 (struct usb_descriptor_header *) &fs_status_desc,
658
659 (struct usb_descriptor_header *) &data_nop_intf,
660 (struct usb_descriptor_header *) &data_intf,
661 (struct usb_descriptor_header *) &fs_source_desc,
662 (struct usb_descriptor_header *) &fs_sink_desc,
663 NULL,
664#endif
665};
666
667static inline void fs_subset_descriptors(void)
668{
669#ifdef CONFIG_USB_ETH_SUBSET
670
671 fs_eth_function[1] = (struct usb_descriptor_header *) &subset_data_intf;
672 fs_eth_function[2] = (struct usb_descriptor_header *) &header_desc;
673 fs_eth_function[3] = (struct usb_descriptor_header *) &mdlm_desc;
674 fs_eth_function[4] = (struct usb_descriptor_header *) &mdlm_detail_desc;
675 fs_eth_function[5] = (struct usb_descriptor_header *) ðer_desc;
676 fs_eth_function[6] = (struct usb_descriptor_header *) &fs_source_desc;
677 fs_eth_function[7] = (struct usb_descriptor_header *) &fs_sink_desc;
678 fs_eth_function[8] = NULL;
679#else
680 fs_eth_function[1] = NULL;
681#endif
682}
683
684#ifdef CONFIG_USB_ETH_RNDIS
685static const struct usb_descriptor_header *fs_rndis_function[] = {
686 (struct usb_descriptor_header *) &otg_descriptor,
687
688 (struct usb_descriptor_header *) &rndis_control_intf,
689 (struct usb_descriptor_header *) &header_desc,
690 (struct usb_descriptor_header *) &call_mgmt_descriptor,
691 (struct usb_descriptor_header *) &acm_descriptor,
692 (struct usb_descriptor_header *) &union_desc,
693 (struct usb_descriptor_header *) &fs_status_desc,
694
695 (struct usb_descriptor_header *) &rndis_data_intf,
696 (struct usb_descriptor_header *) &fs_source_desc,
697 (struct usb_descriptor_header *) &fs_sink_desc,
698 NULL,
699};
700#endif
701
702
703
704
705
706
707#if defined(CONFIG_USB_ETH_CDC) || defined(CONFIG_USB_ETH_RNDIS)
708static struct usb_endpoint_descriptor
709hs_status_desc = {
710 .bLength = USB_DT_ENDPOINT_SIZE,
711 .bDescriptorType = USB_DT_ENDPOINT,
712
713 .bmAttributes = USB_ENDPOINT_XFER_INT,
714 .wMaxPacketSize = __constant_cpu_to_le16(STATUS_BYTECOUNT),
715 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
716};
717#endif
718
719static struct usb_endpoint_descriptor
720hs_source_desc = {
721 .bLength = USB_DT_ENDPOINT_SIZE,
722 .bDescriptorType = USB_DT_ENDPOINT,
723
724 .bmAttributes = USB_ENDPOINT_XFER_BULK,
725 .wMaxPacketSize = __constant_cpu_to_le16(512),
726};
727
728static struct usb_endpoint_descriptor
729hs_sink_desc = {
730 .bLength = USB_DT_ENDPOINT_SIZE,
731 .bDescriptorType = USB_DT_ENDPOINT,
732
733 .bmAttributes = USB_ENDPOINT_XFER_BULK,
734 .wMaxPacketSize = __constant_cpu_to_le16(512),
735};
736
737static struct usb_qualifier_descriptor
738dev_qualifier = {
739 .bLength = sizeof dev_qualifier,
740 .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
741
742 .bcdUSB = __constant_cpu_to_le16(0x0200),
743 .bDeviceClass = USB_CLASS_COMM,
744
745 .bNumConfigurations = 1,
746};
747
748static const struct usb_descriptor_header *hs_eth_function[11] = {
749 (struct usb_descriptor_header *) &otg_descriptor,
750#ifdef CONFIG_USB_ETH_CDC
751
752 (struct usb_descriptor_header *) &control_intf,
753 (struct usb_descriptor_header *) &header_desc,
754 (struct usb_descriptor_header *) &union_desc,
755 (struct usb_descriptor_header *) ðer_desc,
756
757 (struct usb_descriptor_header *) &hs_status_desc,
758
759 (struct usb_descriptor_header *) &data_nop_intf,
760 (struct usb_descriptor_header *) &data_intf,
761 (struct usb_descriptor_header *) &hs_source_desc,
762 (struct usb_descriptor_header *) &hs_sink_desc,
763 NULL,
764#endif
765};
766
767static inline void hs_subset_descriptors(void)
768{
769#ifdef CONFIG_USB_ETH_SUBSET
770
771 hs_eth_function[1] = (struct usb_descriptor_header *) &subset_data_intf;
772 hs_eth_function[2] = (struct usb_descriptor_header *) &header_desc;
773 hs_eth_function[3] = (struct usb_descriptor_header *) &mdlm_desc;
774 hs_eth_function[4] = (struct usb_descriptor_header *) &mdlm_detail_desc;
775 hs_eth_function[5] = (struct usb_descriptor_header *) ðer_desc;
776 hs_eth_function[6] = (struct usb_descriptor_header *) &hs_source_desc;
777 hs_eth_function[7] = (struct usb_descriptor_header *) &hs_sink_desc;
778 hs_eth_function[8] = NULL;
779#else
780 hs_eth_function[1] = NULL;
781#endif
782}
783
784#ifdef CONFIG_USB_ETH_RNDIS
785static const struct usb_descriptor_header *hs_rndis_function[] = {
786 (struct usb_descriptor_header *) &otg_descriptor,
787
788 (struct usb_descriptor_header *) &rndis_control_intf,
789 (struct usb_descriptor_header *) &header_desc,
790 (struct usb_descriptor_header *) &call_mgmt_descriptor,
791 (struct usb_descriptor_header *) &acm_descriptor,
792 (struct usb_descriptor_header *) &union_desc,
793 (struct usb_descriptor_header *) &hs_status_desc,
794
795 (struct usb_descriptor_header *) &rndis_data_intf,
796 (struct usb_descriptor_header *) &hs_source_desc,
797 (struct usb_descriptor_header *) &hs_sink_desc,
798 NULL,
799};
800#endif
801
802
803
804static inline struct usb_endpoint_descriptor *
805ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *hs,
806 struct usb_endpoint_descriptor *fs)
807{
808 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
809 return hs;
810 return fs;
811}
812
813
814
815
816
817static char manufacturer[50];
818static char product_desc[40] = DRIVER_DESC;
819static char serial_number[20];
820
821
822static char ethaddr[2 * ETH_ALEN + 1];
823
824
825static struct usb_string strings[] = {
826 { STRING_MANUFACTURER, manufacturer, },
827 { STRING_PRODUCT, product_desc, },
828 { STRING_SERIALNUMBER, serial_number, },
829 { STRING_DATA, "Ethernet Data", },
830 { STRING_ETHADDR, ethaddr, },
831#ifdef CONFIG_USB_ETH_CDC
832 { STRING_CDC, "CDC Ethernet", },
833 { STRING_CONTROL, "CDC Communications Control", },
834#endif
835#ifdef CONFIG_USB_ETH_SUBSET
836 { STRING_SUBSET, "CDC Ethernet Subset", },
837#endif
838#ifdef CONFIG_USB_ETH_RNDIS
839 { STRING_RNDIS, "RNDIS", },
840 { STRING_RNDIS_CONTROL, "RNDIS Communications Control", },
841#endif
842 { }
843};
844
845static struct usb_gadget_strings stringtab = {
846 .language = 0x0409,
847 .strings = strings,
848};
849
850
851DEFINE_CACHE_ALIGN_BUFFER(u8, control_req, USB_BUFSIZ);
852
853#if defined(CONFIG_USB_ETH_CDC) || defined(CONFIG_USB_ETH_RNDIS)
854DEFINE_CACHE_ALIGN_BUFFER(u8, status_req, STATUS_BYTECOUNT);
855#endif
856
857
858
859
860
861
862
863static int
864config_buf(struct usb_gadget *g, u8 *buf, u8 type, unsigned index, int is_otg)
865{
866 int len;
867 const struct usb_config_descriptor *config;
868 const struct usb_descriptor_header **function;
869 int hs = 0;
870
871 if (gadget_is_dualspeed(g)) {
872 hs = (g->speed == USB_SPEED_HIGH);
873 if (type == USB_DT_OTHER_SPEED_CONFIG)
874 hs = !hs;
875 }
876#define which_fn(t) (hs ? hs_ ## t ## _function : fs_ ## t ## _function)
877
878 if (index >= device_desc.bNumConfigurations)
879 return -EINVAL;
880
881#ifdef CONFIG_USB_ETH_RNDIS
882
883
884
885
886 if (device_desc.bNumConfigurations == 2 && index == 0) {
887 config = &rndis_config;
888 function = which_fn(rndis);
889 } else
890#endif
891 {
892 config = ð_config;
893 function = which_fn(eth);
894 }
895
896
897 if (!is_otg)
898 function++;
899
900 len = usb_gadget_config_buf(config, buf, USB_BUFSIZ, function);
901 if (len < 0)
902 return len;
903 ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
904 return len;
905}
906
907
908
909static void eth_start(struct eth_dev *dev, gfp_t gfp_flags);
910static int alloc_requests(struct eth_dev *dev, unsigned n, gfp_t gfp_flags);
911
912static int
913set_ether_config(struct eth_dev *dev, gfp_t gfp_flags)
914{
915 int result = 0;
916 struct usb_gadget *gadget = dev->gadget;
917
918#if defined(CONFIG_USB_ETH_CDC) || defined(CONFIG_USB_ETH_RNDIS)
919
920 if (!subset_active(dev) && dev->status_ep) {
921 dev->status = ep_desc(gadget, &hs_status_desc,
922 &fs_status_desc);
923 dev->status_ep->driver_data = dev;
924
925 result = usb_ep_enable(dev->status_ep, dev->status);
926 if (result != 0) {
927 debug("enable %s --> %d\n",
928 dev->status_ep->name, result);
929 goto done;
930 }
931 }
932#endif
933
934 dev->in = ep_desc(gadget, &hs_source_desc, &fs_source_desc);
935 dev->in_ep->driver_data = dev;
936
937 dev->out = ep_desc(gadget, &hs_sink_desc, &fs_sink_desc);
938 dev->out_ep->driver_data = dev;
939
940
941
942
943
944
945
946
947
948
949 if (!cdc_active(dev)) {
950 result = usb_ep_enable(dev->in_ep, dev->in);
951 if (result != 0) {
952 debug("enable %s --> %d\n",
953 dev->in_ep->name, result);
954 goto done;
955 }
956
957 result = usb_ep_enable(dev->out_ep, dev->out);
958 if (result != 0) {
959 debug("enable %s --> %d\n",
960 dev->out_ep->name, result);
961 goto done;
962 }
963 }
964
965done:
966 if (result == 0)
967 result = alloc_requests(dev, qlen(gadget), gfp_flags);
968
969
970 if (result < 0) {
971 if (!subset_active(dev) && dev->status_ep)
972 (void) usb_ep_disable(dev->status_ep);
973 dev->status = NULL;
974 (void) usb_ep_disable(dev->in_ep);
975 (void) usb_ep_disable(dev->out_ep);
976 dev->in = NULL;
977 dev->out = NULL;
978 } else if (!cdc_active(dev)) {
979
980
981
982
983 eth_start(dev, GFP_ATOMIC);
984 }
985
986
987 return result;
988}
989
990static void eth_reset_config(struct eth_dev *dev)
991{
992 if (dev->config == 0)
993 return;
994
995 debug("%s\n", __func__);
996
997 rndis_uninit(dev->rndis_config);
998
999
1000
1001
1002
1003
1004 if (dev->in) {
1005 usb_ep_disable(dev->in_ep);
1006 if (dev->tx_req) {
1007 usb_ep_free_request(dev->in_ep, dev->tx_req);
1008 dev->tx_req = NULL;
1009 }
1010 }
1011 if (dev->out) {
1012 usb_ep_disable(dev->out_ep);
1013 if (dev->rx_req) {
1014 usb_ep_free_request(dev->out_ep, dev->rx_req);
1015 dev->rx_req = NULL;
1016 }
1017 }
1018 if (dev->status)
1019 usb_ep_disable(dev->status_ep);
1020
1021 dev->rndis = 0;
1022 dev->cdc_filter = 0;
1023 dev->config = 0;
1024}
1025
1026
1027
1028
1029
1030static int eth_set_config(struct eth_dev *dev, unsigned number,
1031 gfp_t gfp_flags)
1032{
1033 int result = 0;
1034 struct usb_gadget *gadget = dev->gadget;
1035
1036 if (gadget_is_sa1100(gadget)
1037 && dev->config
1038 && dev->tx_qlen != 0) {
1039
1040 error("can't change configurations");
1041 return -ESPIPE;
1042 }
1043 eth_reset_config(dev);
1044
1045 switch (number) {
1046 case DEV_CONFIG_VALUE:
1047 result = set_ether_config(dev, gfp_flags);
1048 break;
1049#ifdef CONFIG_USB_ETH_RNDIS
1050 case DEV_RNDIS_CONFIG_VALUE:
1051 dev->rndis = 1;
1052 result = set_ether_config(dev, gfp_flags);
1053 break;
1054#endif
1055 default:
1056 result = -EINVAL;
1057
1058 case 0:
1059 break;
1060 }
1061
1062 if (result) {
1063 if (number)
1064 eth_reset_config(dev);
1065 usb_gadget_vbus_draw(dev->gadget,
1066 gadget_is_otg(dev->gadget) ? 8 : 100);
1067 } else {
1068 char *speed;
1069 unsigned power;
1070
1071 power = 2 * eth_config.bMaxPower;
1072 usb_gadget_vbus_draw(dev->gadget, power);
1073
1074 switch (gadget->speed) {
1075 case USB_SPEED_FULL:
1076 speed = "full"; break;
1077#ifdef CONFIG_USB_GADGET_DUALSPEED
1078 case USB_SPEED_HIGH:
1079 speed = "high"; break;
1080#endif
1081 default:
1082 speed = "?"; break;
1083 }
1084
1085 dev->config = number;
1086 printf("%s speed config #%d: %d mA, %s, using %s\n",
1087 speed, number, power, driver_desc,
1088 rndis_active(dev)
1089 ? "RNDIS"
1090 : (cdc_active(dev)
1091 ? "CDC Ethernet"
1092 : "CDC Ethernet Subset"));
1093 }
1094 return result;
1095}
1096
1097
1098
1099#ifdef CONFIG_USB_ETH_CDC
1100
1101
1102
1103
1104
1105
1106
1107
1108static void eth_status_complete(struct usb_ep *ep, struct usb_request *req)
1109{
1110 struct usb_cdc_notification *event = req->buf;
1111 int value = req->status;
1112 struct eth_dev *dev = ep->driver_data;
1113
1114
1115 if (event->bNotificationType == USB_CDC_NOTIFY_NETWORK_CONNECTION
1116 && value == 0) {
1117 __le32 *data = req->buf + sizeof *event;
1118
1119 event->bmRequestType = 0xA1;
1120 event->bNotificationType = USB_CDC_NOTIFY_SPEED_CHANGE;
1121 event->wValue = __constant_cpu_to_le16(0);
1122 event->wIndex = __constant_cpu_to_le16(1);
1123 event->wLength = __constant_cpu_to_le16(8);
1124
1125
1126 data[0] = data[1] = cpu_to_le32(BITRATE(dev->gadget));
1127
1128 req->length = STATUS_BYTECOUNT;
1129 value = usb_ep_queue(ep, req, GFP_ATOMIC);
1130 debug("send SPEED_CHANGE --> %d\n", value);
1131 if (value == 0)
1132 return;
1133 } else if (value != -ECONNRESET) {
1134 debug("event %02x --> %d\n",
1135 event->bNotificationType, value);
1136 if (event->bNotificationType ==
1137 USB_CDC_NOTIFY_SPEED_CHANGE) {
1138 l_ethdev.network_started = 1;
1139 printf("USB network up!\n");
1140 }
1141 }
1142 req->context = NULL;
1143}
1144
1145static void issue_start_status(struct eth_dev *dev)
1146{
1147 struct usb_request *req = dev->stat_req;
1148 struct usb_cdc_notification *event;
1149 int value;
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161 usb_ep_disable(dev->status_ep);
1162 usb_ep_enable(dev->status_ep, dev->status);
1163
1164
1165
1166
1167
1168 event = req->buf;
1169 event->bmRequestType = 0xA1;
1170 event->bNotificationType = USB_CDC_NOTIFY_NETWORK_CONNECTION;
1171 event->wValue = __constant_cpu_to_le16(1);
1172 event->wIndex = __constant_cpu_to_le16(1);
1173 event->wLength = 0;
1174
1175 req->length = sizeof *event;
1176 req->complete = eth_status_complete;
1177 req->context = dev;
1178
1179 value = usb_ep_queue(dev->status_ep, req, GFP_ATOMIC);
1180 if (value < 0)
1181 debug("status buf queue --> %d\n", value);
1182}
1183
1184#endif
1185
1186
1187
1188static void eth_setup_complete(struct usb_ep *ep, struct usb_request *req)
1189{
1190 if (req->status || req->actual != req->length)
1191 debug("setup complete --> %d, %d/%d\n",
1192 req->status, req->actual, req->length);
1193}
1194
1195#ifdef CONFIG_USB_ETH_RNDIS
1196
1197static void rndis_response_complete(struct usb_ep *ep, struct usb_request *req)
1198{
1199 if (req->status || req->actual != req->length)
1200 debug("rndis response complete --> %d, %d/%d\n",
1201 req->status, req->actual, req->length);
1202
1203
1204}
1205
1206static void rndis_command_complete(struct usb_ep *ep, struct usb_request *req)
1207{
1208 struct eth_dev *dev = ep->driver_data;
1209 int status;
1210
1211
1212 status = rndis_msg_parser(dev->rndis_config, (u8 *) req->buf);
1213 if (status < 0)
1214 error("%s: rndis parse error %d", __func__, status);
1215}
1216
1217#endif
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228static int
1229eth_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1230{
1231 struct eth_dev *dev = get_gadget_data(gadget);
1232 struct usb_request *req = dev->req;
1233 int value = -EOPNOTSUPP;
1234 u16 wIndex = le16_to_cpu(ctrl->wIndex);
1235 u16 wValue = le16_to_cpu(ctrl->wValue);
1236 u16 wLength = le16_to_cpu(ctrl->wLength);
1237
1238
1239
1240
1241
1242
1243 debug("%s\n", __func__);
1244
1245 req->complete = eth_setup_complete;
1246 switch (ctrl->bRequest) {
1247
1248 case USB_REQ_GET_DESCRIPTOR:
1249 if (ctrl->bRequestType != USB_DIR_IN)
1250 break;
1251 switch (wValue >> 8) {
1252
1253 case USB_DT_DEVICE:
1254 device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
1255 value = min(wLength, (u16) sizeof device_desc);
1256 memcpy(req->buf, &device_desc, value);
1257 break;
1258 case USB_DT_DEVICE_QUALIFIER:
1259 if (!gadget_is_dualspeed(gadget))
1260 break;
1261 value = min(wLength, (u16) sizeof dev_qualifier);
1262 memcpy(req->buf, &dev_qualifier, value);
1263 break;
1264
1265 case USB_DT_OTHER_SPEED_CONFIG:
1266 if (!gadget_is_dualspeed(gadget))
1267 break;
1268
1269 case USB_DT_CONFIG:
1270 value = config_buf(gadget, req->buf,
1271 wValue >> 8,
1272 wValue & 0xff,
1273 gadget_is_otg(gadget));
1274 if (value >= 0)
1275 value = min(wLength, (u16) value);
1276 break;
1277
1278 case USB_DT_STRING:
1279 value = usb_gadget_get_string(&stringtab,
1280 wValue & 0xff, req->buf);
1281
1282 if (value >= 0)
1283 value = min(wLength, (u16) value);
1284
1285 break;
1286 }
1287 break;
1288
1289 case USB_REQ_SET_CONFIGURATION:
1290 if (ctrl->bRequestType != 0)
1291 break;
1292 if (gadget->a_hnp_support)
1293 debug("HNP available\n");
1294 else if (gadget->a_alt_hnp_support)
1295 debug("HNP needs a different root port\n");
1296 value = eth_set_config(dev, wValue, GFP_ATOMIC);
1297 break;
1298 case USB_REQ_GET_CONFIGURATION:
1299 if (ctrl->bRequestType != USB_DIR_IN)
1300 break;
1301 *(u8 *)req->buf = dev->config;
1302 value = min(wLength, (u16) 1);
1303 break;
1304
1305 case USB_REQ_SET_INTERFACE:
1306 if (ctrl->bRequestType != USB_RECIP_INTERFACE
1307 || !dev->config
1308 || wIndex > 1)
1309 break;
1310 if (!cdc_active(dev) && wIndex != 0)
1311 break;
1312
1313
1314
1315
1316
1317 if (gadget_is_pxa(gadget)) {
1318 value = eth_set_config(dev, DEV_CONFIG_VALUE,
1319 GFP_ATOMIC);
1320
1321
1322
1323
1324
1325
1326 l_ethdev.network_started = 1;
1327 debug("USB network up!\n");
1328 goto done_set_intf;
1329 }
1330
1331#ifdef CONFIG_USB_ETH_CDC
1332 switch (wIndex) {
1333 case 0:
1334 if (wValue != 0)
1335 break;
1336 if (dev->status) {
1337 usb_ep_disable(dev->status_ep);
1338 usb_ep_enable(dev->status_ep, dev->status);
1339 }
1340
1341 value = 0;
1342 break;
1343 case 1:
1344 if (wValue > 1)
1345 break;
1346 usb_ep_disable(dev->in_ep);
1347 usb_ep_disable(dev->out_ep);
1348
1349
1350
1351
1352
1353
1354 if (wValue == 1) {
1355 if (!cdc_active(dev))
1356 break;
1357 usb_ep_enable(dev->in_ep, dev->in);
1358 usb_ep_enable(dev->out_ep, dev->out);
1359 dev->cdc_filter = DEFAULT_FILTER;
1360 if (dev->status)
1361 issue_start_status(dev);
1362 eth_start(dev, GFP_ATOMIC);
1363 }
1364 value = 0;
1365 break;
1366 }
1367#else
1368
1369
1370
1371
1372 debug("set_interface ignored!\n");
1373#endif
1374
1375done_set_intf:
1376 break;
1377 case USB_REQ_GET_INTERFACE:
1378 if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE)
1379 || !dev->config
1380 || wIndex > 1)
1381 break;
1382 if (!(cdc_active(dev) || rndis_active(dev)) && wIndex != 0)
1383 break;
1384
1385
1386 if (rndis_active(dev) || wIndex != 1)
1387 *(u8 *)req->buf = 0;
1388 else {
1389
1390
1391 *(u8 *)req->buf = 1 ;
1392 }
1393 value = min(wLength, (u16) 1);
1394 break;
1395
1396#ifdef CONFIG_USB_ETH_CDC
1397 case USB_CDC_SET_ETHERNET_PACKET_FILTER:
1398
1399
1400
1401
1402 if (ctrl->bRequestType != (USB_TYPE_CLASS|USB_RECIP_INTERFACE)
1403 || !cdc_active(dev)
1404 || wLength != 0
1405 || wIndex > 1)
1406 break;
1407 debug("packet filter %02x\n", wValue);
1408 dev->cdc_filter = wValue;
1409 value = 0;
1410 break;
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420#endif
1421
1422#ifdef CONFIG_USB_ETH_RNDIS
1423
1424
1425
1426
1427 case USB_CDC_SEND_ENCAPSULATED_COMMAND:
1428 if (ctrl->bRequestType != (USB_TYPE_CLASS|USB_RECIP_INTERFACE)
1429 || !rndis_active(dev)
1430 || wLength > USB_BUFSIZ
1431 || wValue
1432 || rndis_control_intf.bInterfaceNumber
1433 != wIndex)
1434 break;
1435
1436 value = wLength;
1437 req->complete = rndis_command_complete;
1438
1439 break;
1440
1441 case USB_CDC_GET_ENCAPSULATED_RESPONSE:
1442 if ((USB_DIR_IN|USB_TYPE_CLASS|USB_RECIP_INTERFACE)
1443 == ctrl->bRequestType
1444 && rndis_active(dev)
1445
1446 && !wValue
1447 && rndis_control_intf.bInterfaceNumber
1448 == wIndex) {
1449 u8 *buf;
1450 u32 n;
1451
1452
1453 buf = rndis_get_next_response(dev->rndis_config, &n);
1454 if (buf) {
1455 memcpy(req->buf, buf, n);
1456 req->complete = rndis_response_complete;
1457 rndis_free_response(dev->rndis_config, buf);
1458 value = n;
1459 }
1460
1461 }
1462 break;
1463#endif
1464
1465 default:
1466 debug("unknown control req%02x.%02x v%04x i%04x l%d\n",
1467 ctrl->bRequestType, ctrl->bRequest,
1468 wValue, wIndex, wLength);
1469 }
1470
1471
1472 if (value >= 0) {
1473 debug("respond with data transfer before status phase\n");
1474 req->length = value;
1475 req->zero = value < wLength
1476 && (value % gadget->ep0->maxpacket) == 0;
1477 value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC);
1478 if (value < 0) {
1479 debug("ep_queue --> %d\n", value);
1480 req->status = 0;
1481 eth_setup_complete(gadget->ep0, req);
1482 }
1483 }
1484
1485
1486 return value;
1487}
1488
1489
1490
1491static void rx_complete(struct usb_ep *ep, struct usb_request *req);
1492
1493static int rx_submit(struct eth_dev *dev, struct usb_request *req,
1494 gfp_t gfp_flags)
1495{
1496 int retval = -ENOMEM;
1497 size_t size;
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512 debug("%s\n", __func__);
1513 if (!req)
1514 return -EINVAL;
1515
1516 size = (ETHER_HDR_SIZE + dev->mtu + RX_EXTRA);
1517 size += dev->out_ep->maxpacket - 1;
1518 if (rndis_active(dev))
1519 size += sizeof(struct rndis_packet_msg_type);
1520 size -= size % dev->out_ep->maxpacket;
1521
1522
1523
1524
1525
1526
1527
1528 req->buf = (u8 *)net_rx_packets[0];
1529 req->length = size;
1530 req->complete = rx_complete;
1531
1532 retval = usb_ep_queue(dev->out_ep, req, gfp_flags);
1533
1534 if (retval)
1535 error("rx submit --> %d", retval);
1536
1537 return retval;
1538}
1539
1540static void rx_complete(struct usb_ep *ep, struct usb_request *req)
1541{
1542 struct eth_dev *dev = ep->driver_data;
1543
1544 debug("%s: status %d\n", __func__, req->status);
1545 switch (req->status) {
1546
1547 case 0:
1548 if (rndis_active(dev)) {
1549
1550 int length = rndis_rm_hdr(req->buf, req->actual);
1551 if (length < 0)
1552 goto length_err;
1553 req->length -= length;
1554 req->actual -= length;
1555 }
1556 if (req->actual < ETH_HLEN || ETH_FRAME_LEN < req->actual) {
1557length_err:
1558 dev->stats.rx_errors++;
1559 dev->stats.rx_length_errors++;
1560 debug("rx length %d\n", req->length);
1561 break;
1562 }
1563
1564 dev->stats.rx_packets++;
1565 dev->stats.rx_bytes += req->length;
1566 break;
1567
1568
1569 case -ECONNRESET:
1570 case -ESHUTDOWN:
1571
1572 case -ECONNABORTED:
1573 break;
1574
1575
1576 case -EOVERFLOW:
1577 dev->stats.rx_over_errors++;
1578
1579 default:
1580 dev->stats.rx_errors++;
1581 break;
1582 }
1583
1584 packet_received = 1;
1585}
1586
1587static int alloc_requests(struct eth_dev *dev, unsigned n, gfp_t gfp_flags)
1588{
1589
1590 dev->tx_req = usb_ep_alloc_request(dev->in_ep, 0);
1591
1592 if (!dev->tx_req)
1593 goto fail1;
1594
1595 dev->rx_req = usb_ep_alloc_request(dev->out_ep, 0);
1596
1597 if (!dev->rx_req)
1598 goto fail2;
1599
1600 return 0;
1601
1602fail2:
1603 usb_ep_free_request(dev->in_ep, dev->tx_req);
1604fail1:
1605 error("can't alloc requests");
1606 return -1;
1607}
1608
1609static void tx_complete(struct usb_ep *ep, struct usb_request *req)
1610{
1611 struct eth_dev *dev = ep->driver_data;
1612
1613 debug("%s: status %s\n", __func__, (req->status) ? "failed" : "ok");
1614 switch (req->status) {
1615 default:
1616 dev->stats.tx_errors++;
1617 debug("tx err %d\n", req->status);
1618
1619 case -ECONNRESET:
1620 case -ESHUTDOWN:
1621 break;
1622 case 0:
1623 dev->stats.tx_bytes += req->length;
1624 }
1625 dev->stats.tx_packets++;
1626
1627 packet_sent = 1;
1628}
1629
1630static inline int eth_is_promisc(struct eth_dev *dev)
1631{
1632
1633 if (subset_active(dev))
1634 return 1;
1635 return dev->cdc_filter & USB_CDC_PACKET_TYPE_PROMISCUOUS;
1636}
1637
1638#if 0
1639static int eth_start_xmit (struct sk_buff *skb, struct net_device *net)
1640{
1641 struct eth_dev *dev = netdev_priv(net);
1642 int length = skb->len;
1643 int retval;
1644 struct usb_request *req = NULL;
1645 unsigned long flags;
1646
1647
1648 if (!eth_is_promisc (dev)) {
1649 u8 *dest = skb->data;
1650
1651 if (is_multicast_ethaddr(dest)) {
1652 u16 type;
1653
1654
1655
1656
1657 if (is_broadcast_ethaddr(dest))
1658 type = USB_CDC_PACKET_TYPE_BROADCAST;
1659 else
1660 type = USB_CDC_PACKET_TYPE_ALL_MULTICAST;
1661 if (!(dev->cdc_filter & type)) {
1662 dev_kfree_skb_any (skb);
1663 return 0;
1664 }
1665 }
1666
1667 }
1668
1669 spin_lock_irqsave(&dev->req_lock, flags);
1670
1671
1672
1673
1674
1675 if (list_empty(&dev->tx_reqs)) {
1676 spin_unlock_irqrestore(&dev->req_lock, flags);
1677 return 1;
1678 }
1679
1680 req = container_of (dev->tx_reqs.next, struct usb_request, list);
1681 list_del (&req->list);
1682
1683
1684 if (list_empty (&dev->tx_reqs))
1685 netif_stop_queue (net);
1686 spin_unlock_irqrestore(&dev->req_lock, flags);
1687
1688
1689
1690
1691
1692 if (rndis_active(dev)) {
1693 struct sk_buff *skb_rndis;
1694
1695 skb_rndis = skb_realloc_headroom (skb,
1696 sizeof (struct rndis_packet_msg_type));
1697 if (!skb_rndis)
1698 goto drop;
1699
1700 dev_kfree_skb_any (skb);
1701 skb = skb_rndis;
1702 rndis_add_hdr (skb);
1703 length = skb->len;
1704 }
1705 req->buf = skb->data;
1706 req->context = skb;
1707 req->complete = tx_complete;
1708
1709
1710
1711
1712
1713 req->zero = 1;
1714 if (!dev->zlp && (length % dev->in_ep->maxpacket) == 0)
1715 length++;
1716
1717 req->length = length;
1718
1719
1720 if (gadget_is_dualspeed(dev->gadget))
1721 req->no_interrupt = (dev->gadget->speed == USB_SPEED_HIGH)
1722 ? ((atomic_read(&dev->tx_qlen) % qmult) != 0)
1723 : 0;
1724
1725 retval = usb_ep_queue (dev->in_ep, req, GFP_ATOMIC);
1726 switch (retval) {
1727 default:
1728 DEBUG (dev, "tx queue err %d\n", retval);
1729 break;
1730 case 0:
1731 net->trans_start = jiffies;
1732 atomic_inc (&dev->tx_qlen);
1733 }
1734
1735 if (retval) {
1736drop:
1737 dev->stats.tx_dropped++;
1738 dev_kfree_skb_any (skb);
1739 spin_lock_irqsave(&dev->req_lock, flags);
1740 if (list_empty (&dev->tx_reqs))
1741 netif_start_queue (net);
1742 list_add (&req->list, &dev->tx_reqs);
1743 spin_unlock_irqrestore(&dev->req_lock, flags);
1744 }
1745 return 0;
1746}
1747
1748
1749#endif
1750
1751static void eth_unbind(struct usb_gadget *gadget)
1752{
1753 struct eth_dev *dev = get_gadget_data(gadget);
1754
1755 debug("%s...\n", __func__);
1756 rndis_deregister(dev->rndis_config);
1757 rndis_exit();
1758
1759
1760 if (dev->req) {
1761 usb_ep_free_request(gadget->ep0, dev->req);
1762 dev->req = NULL;
1763 }
1764 if (dev->stat_req) {
1765 usb_ep_free_request(dev->status_ep, dev->stat_req);
1766 dev->stat_req = NULL;
1767 }
1768
1769 if (dev->tx_req) {
1770 usb_ep_free_request(dev->in_ep, dev->tx_req);
1771 dev->tx_req = NULL;
1772 }
1773
1774 if (dev->rx_req) {
1775 usb_ep_free_request(dev->out_ep, dev->rx_req);
1776 dev->rx_req = NULL;
1777 }
1778
1779
1780
1781
1782 dev->gadget = NULL;
1783 set_gadget_data(gadget, NULL);
1784}
1785
1786static void eth_disconnect(struct usb_gadget *gadget)
1787{
1788 eth_reset_config(get_gadget_data(gadget));
1789
1790}
1791
1792static void eth_suspend(struct usb_gadget *gadget)
1793{
1794
1795}
1796
1797static void eth_resume(struct usb_gadget *gadget)
1798{
1799
1800}
1801
1802
1803
1804#ifdef CONFIG_USB_ETH_RNDIS
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816static void rndis_control_ack_complete(struct usb_ep *ep,
1817 struct usb_request *req)
1818{
1819 struct eth_dev *dev = ep->driver_data;
1820
1821 debug("%s...\n", __func__);
1822 if (req->status || req->actual != req->length)
1823 debug("rndis control ack complete --> %d, %d/%d\n",
1824 req->status, req->actual, req->length);
1825
1826 if (!l_ethdev.network_started) {
1827 if (rndis_get_state(dev->rndis_config)
1828 == RNDIS_DATA_INITIALIZED) {
1829 l_ethdev.network_started = 1;
1830 printf("USB RNDIS network up!\n");
1831 }
1832 }
1833
1834 req->context = NULL;
1835
1836 if (req != dev->stat_req)
1837 usb_ep_free_request(ep, req);
1838}
1839
1840static char rndis_resp_buf[8] __attribute__((aligned(sizeof(__le32))));
1841
1842static int rndis_control_ack(struct eth_device *net)
1843{
1844 struct eth_dev *dev = &l_ethdev;
1845 int length;
1846 struct usb_request *resp = dev->stat_req;
1847
1848
1849 if (!dev->status) {
1850 debug("status ENODEV\n");
1851 return -ENODEV;
1852 }
1853
1854
1855 if (resp->context) {
1856 resp = usb_ep_alloc_request(dev->status_ep, GFP_ATOMIC);
1857 if (!resp)
1858 return -ENOMEM;
1859 resp->buf = rndis_resp_buf;
1860 }
1861
1862
1863
1864
1865
1866 resp->length = 8;
1867 resp->complete = rndis_control_ack_complete;
1868 resp->context = dev;
1869
1870 *((__le32 *) resp->buf) = __constant_cpu_to_le32(1);
1871 *((__le32 *) (resp->buf + 4)) = __constant_cpu_to_le32(0);
1872
1873 length = usb_ep_queue(dev->status_ep, resp, GFP_ATOMIC);
1874 if (length < 0) {
1875 resp->status = 0;
1876 rndis_control_ack_complete(dev->status_ep, resp);
1877 }
1878
1879 return 0;
1880}
1881
1882#else
1883
1884#define rndis_control_ack NULL
1885
1886#endif
1887
1888static void eth_start(struct eth_dev *dev, gfp_t gfp_flags)
1889{
1890 if (rndis_active(dev)) {
1891 rndis_set_param_medium(dev->rndis_config,
1892 NDIS_MEDIUM_802_3,
1893 BITRATE(dev->gadget)/100);
1894 rndis_signal_connect(dev->rndis_config);
1895 }
1896}
1897
1898static int eth_stop(struct eth_dev *dev)
1899{
1900#ifdef RNDIS_COMPLETE_SIGNAL_DISCONNECT
1901 unsigned long ts;
1902 unsigned long timeout = CONFIG_SYS_HZ;
1903#endif
1904
1905 if (rndis_active(dev)) {
1906 rndis_set_param_medium(dev->rndis_config, NDIS_MEDIUM_802_3, 0);
1907 rndis_signal_disconnect(dev->rndis_config);
1908
1909#ifdef RNDIS_COMPLETE_SIGNAL_DISCONNECT
1910
1911 ts = get_timer(0);
1912 while (get_timer(ts) < timeout)
1913 usb_gadget_handle_interrupts(0);
1914#endif
1915
1916 rndis_uninit(dev->rndis_config);
1917 dev->rndis = 0;
1918 }
1919
1920 return 0;
1921}
1922
1923
1924
1925static int is_eth_addr_valid(char *str)
1926{
1927 if (strlen(str) == 17) {
1928 int i;
1929 char *p, *q;
1930 uchar ea[6];
1931
1932
1933
1934 p = str;
1935
1936 for (i = 0; i < 6; i++) {
1937 char term = (i == 5 ? '\0' : ':');
1938
1939 ea[i] = simple_strtol(p, &q, 16);
1940
1941 if ((q - p) != 2 || *q++ != term)
1942 break;
1943
1944 p = q;
1945 }
1946
1947
1948 return is_valid_ethaddr(ea);
1949 }
1950 return 0;
1951}
1952
1953static u8 nibble(unsigned char c)
1954{
1955 if (likely(isdigit(c)))
1956 return c - '0';
1957 c = toupper(c);
1958 if (likely(isxdigit(c)))
1959 return 10 + c - 'A';
1960 return 0;
1961}
1962
1963static int get_ether_addr(const char *str, u8 *dev_addr)
1964{
1965 if (str) {
1966 unsigned i;
1967
1968 for (i = 0; i < 6; i++) {
1969 unsigned char num;
1970
1971 if ((*str == '.') || (*str == ':'))
1972 str++;
1973 num = nibble(*str++) << 4;
1974 num |= (nibble(*str++));
1975 dev_addr[i] = num;
1976 }
1977 if (is_valid_ethaddr(dev_addr))
1978 return 0;
1979 }
1980 return 1;
1981}
1982
1983static int eth_bind(struct usb_gadget *gadget)
1984{
1985 struct eth_dev *dev = &l_ethdev;
1986 u8 cdc = 1, zlp = 1, rndis = 1;
1987 struct usb_ep *in_ep, *out_ep, *status_ep = NULL;
1988 int status = -ENOMEM;
1989 int gcnum;
1990 u8 tmp[7];
1991
1992
1993#ifndef CONFIG_USB_ETH_CDC
1994 cdc = 0;
1995#endif
1996#ifndef CONFIG_USB_ETH_RNDIS
1997 rndis = 0;
1998#endif
1999
2000
2001
2002
2003
2004 if (gadget_is_pxa(gadget)) {
2005
2006 cdc = 0;
2007 } else if (gadget_is_musbhdrc(gadget)) {
2008
2009 zlp = 0;
2010 } else if (gadget_is_sh(gadget)) {
2011
2012 cdc = 0;
2013 rndis = 0;
2014 } else if (gadget_is_sa1100(gadget)) {
2015
2016 zlp = 0;
2017
2018
2019
2020
2021 cdc = 0;
2022 }
2023
2024 gcnum = usb_gadget_controller_number(gadget);
2025 if (gcnum >= 0)
2026 device_desc.bcdDevice = cpu_to_le16(0x0300 + gcnum);
2027 else {
2028
2029
2030
2031
2032
2033 error("controller '%s' not recognized",
2034 gadget->name);
2035 return -ENODEV;
2036 }
2037
2038
2039
2040
2041
2042
2043
2044
2045 if (rndis) {
2046#if defined(CONFIG_USB_RNDIS_VENDOR_ID) && defined(CONFIG_USB_RNDIS_PRODUCT_ID)
2047 device_desc.idVendor =
2048 __constant_cpu_to_le16(CONFIG_USB_RNDIS_VENDOR_ID);
2049 device_desc.idProduct =
2050 __constant_cpu_to_le16(CONFIG_USB_RNDIS_PRODUCT_ID);
2051#else
2052 device_desc.idVendor =
2053 __constant_cpu_to_le16(RNDIS_VENDOR_NUM);
2054 device_desc.idProduct =
2055 __constant_cpu_to_le16(RNDIS_PRODUCT_NUM);
2056#endif
2057 sprintf(product_desc, "RNDIS/%s", driver_desc);
2058
2059
2060
2061
2062
2063
2064 } else {
2065#if defined(CONFIG_USB_CDC_VENDOR_ID) && defined(CONFIG_USB_CDC_PRODUCT_ID)
2066 device_desc.idVendor = cpu_to_le16(CONFIG_USB_CDC_VENDOR_ID);
2067 device_desc.idProduct = cpu_to_le16(CONFIG_USB_CDC_PRODUCT_ID);
2068#else
2069 if (!cdc) {
2070 device_desc.idVendor =
2071 __constant_cpu_to_le16(SIMPLE_VENDOR_NUM);
2072 device_desc.idProduct =
2073 __constant_cpu_to_le16(SIMPLE_PRODUCT_NUM);
2074 }
2075#endif
2076 }
2077
2078 if (bcdDevice)
2079 device_desc.bcdDevice = cpu_to_le16(bcdDevice);
2080 if (iManufacturer)
2081 strlcpy(manufacturer, iManufacturer, sizeof manufacturer);
2082 if (iProduct)
2083 strlcpy(product_desc, iProduct, sizeof product_desc);
2084 if (iSerialNumber) {
2085 device_desc.iSerialNumber = STRING_SERIALNUMBER,
2086 strlcpy(serial_number, iSerialNumber, sizeof serial_number);
2087 }
2088
2089
2090 usb_ep_autoconfig_reset(gadget);
2091 in_ep = usb_ep_autoconfig(gadget, &fs_source_desc);
2092 if (!in_ep) {
2093autoconf_fail:
2094 error("can't autoconfigure on %s\n",
2095 gadget->name);
2096 return -ENODEV;
2097 }
2098 in_ep->driver_data = in_ep;
2099
2100 out_ep = usb_ep_autoconfig(gadget, &fs_sink_desc);
2101 if (!out_ep)
2102 goto autoconf_fail;
2103 out_ep->driver_data = out_ep;
2104
2105#if defined(CONFIG_USB_ETH_CDC) || defined(CONFIG_USB_ETH_RNDIS)
2106
2107
2108
2109
2110 if (cdc || rndis) {
2111 status_ep = usb_ep_autoconfig(gadget, &fs_status_desc);
2112 if (status_ep) {
2113 status_ep->driver_data = status_ep;
2114 } else if (rndis) {
2115 error("can't run RNDIS on %s", gadget->name);
2116 return -ENODEV;
2117#ifdef CONFIG_USB_ETH_CDC
2118 } else if (cdc) {
2119 control_intf.bNumEndpoints = 0;
2120
2121#endif
2122 }
2123 }
2124#endif
2125
2126
2127 if (!cdc) {
2128 eth_config.bNumInterfaces = 1;
2129 eth_config.iConfiguration = STRING_SUBSET;
2130
2131
2132
2133
2134
2135 fs_subset_descriptors();
2136 hs_subset_descriptors();
2137 }
2138
2139 usb_gadget_set_selfpowered(gadget);
2140
2141
2142 if (rndis)
2143 device_desc.bNumConfigurations = 2;
2144
2145 if (gadget_is_dualspeed(gadget)) {
2146 if (rndis)
2147 dev_qualifier.bNumConfigurations = 2;
2148 else if (!cdc)
2149 dev_qualifier.bDeviceClass = USB_CLASS_VENDOR_SPEC;
2150
2151
2152 dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
2153
2154
2155 hs_source_desc.bEndpointAddress =
2156 fs_source_desc.bEndpointAddress;
2157 hs_sink_desc.bEndpointAddress =
2158 fs_sink_desc.bEndpointAddress;
2159#if defined(CONFIG_USB_ETH_CDC) || defined(CONFIG_USB_ETH_RNDIS)
2160 if (status_ep)
2161 hs_status_desc.bEndpointAddress =
2162 fs_status_desc.bEndpointAddress;
2163#endif
2164 }
2165
2166 if (gadget_is_otg(gadget)) {
2167 otg_descriptor.bmAttributes |= USB_OTG_HNP,
2168 eth_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
2169 eth_config.bMaxPower = 4;
2170#ifdef CONFIG_USB_ETH_RNDIS
2171 rndis_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
2172 rndis_config.bMaxPower = 4;
2173#endif
2174 }
2175
2176
2177
2178 dev->net = &l_netdev;
2179
2180 dev->cdc = cdc;
2181 dev->zlp = zlp;
2182
2183 dev->in_ep = in_ep;
2184 dev->out_ep = out_ep;
2185 dev->status_ep = status_ep;
2186
2187
2188
2189
2190
2191
2192
2193
2194 get_ether_addr(dev_addr, dev->net->enetaddr);
2195
2196 memset(tmp, 0, sizeof(tmp));
2197 memcpy(tmp, dev->net->enetaddr, sizeof(dev->net->enetaddr));
2198
2199 get_ether_addr(host_addr, dev->host_mac);
2200
2201 sprintf(ethaddr, "%02X%02X%02X%02X%02X%02X",
2202 dev->host_mac[0], dev->host_mac[1],
2203 dev->host_mac[2], dev->host_mac[3],
2204 dev->host_mac[4], dev->host_mac[5]);
2205
2206 if (rndis) {
2207 status = rndis_init();
2208 if (status < 0) {
2209 error("can't init RNDIS, %d", status);
2210 goto fail;
2211 }
2212 }
2213
2214
2215
2216
2217
2218 dev->mtu = PKTSIZE_ALIGN;
2219
2220
2221 dev->req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL);
2222 if (!dev->req)
2223 goto fail;
2224 dev->req->buf = control_req;
2225 dev->req->complete = eth_setup_complete;
2226
2227
2228#if defined(CONFIG_USB_ETH_CDC) || defined(CONFIG_USB_ETH_RNDIS)
2229 if (dev->status_ep) {
2230 dev->stat_req = usb_ep_alloc_request(dev->status_ep,
2231 GFP_KERNEL);
2232 if (!dev->stat_req) {
2233 usb_ep_free_request(dev->status_ep, dev->req);
2234
2235 goto fail;
2236 }
2237 dev->stat_req->buf = status_req;
2238 dev->stat_req->context = NULL;
2239 }
2240#endif
2241
2242
2243 dev->gadget = gadget;
2244 set_gadget_data(gadget, dev);
2245 gadget->ep0->driver_data = dev;
2246
2247
2248
2249
2250
2251
2252
2253 printf("using %s, OUT %s IN %s%s%s\n", gadget->name,
2254 out_ep->name, in_ep->name,
2255 status_ep ? " STATUS " : "",
2256 status_ep ? status_ep->name : ""
2257 );
2258 printf("MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
2259 dev->net->enetaddr[0], dev->net->enetaddr[1],
2260 dev->net->enetaddr[2], dev->net->enetaddr[3],
2261 dev->net->enetaddr[4], dev->net->enetaddr[5]);
2262
2263 if (cdc || rndis)
2264 printf("HOST MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
2265 dev->host_mac[0], dev->host_mac[1],
2266 dev->host_mac[2], dev->host_mac[3],
2267 dev->host_mac[4], dev->host_mac[5]);
2268
2269 if (rndis) {
2270 u32 vendorID = 0;
2271
2272
2273
2274 dev->rndis_config = rndis_register(rndis_control_ack);
2275 if (dev->rndis_config < 0) {
2276fail0:
2277 eth_unbind(gadget);
2278 debug("RNDIS setup failed\n");
2279 status = -ENODEV;
2280 goto fail;
2281 }
2282
2283
2284 rndis_set_host_mac(dev->rndis_config, dev->host_mac);
2285 if (rndis_set_param_dev(dev->rndis_config, dev->net, dev->mtu,
2286 &dev->stats, &dev->cdc_filter))
2287 goto fail0;
2288 if (rndis_set_param_vendor(dev->rndis_config, vendorID,
2289 manufacturer))
2290 goto fail0;
2291 if (rndis_set_param_medium(dev->rndis_config,
2292 NDIS_MEDIUM_802_3, 0))
2293 goto fail0;
2294 printf("RNDIS ready\n");
2295 }
2296 return 0;
2297
2298fail:
2299 error("%s failed, status = %d", __func__, status);
2300 eth_unbind(gadget);
2301 return status;
2302}
2303
2304
2305
2306static int usb_eth_init(struct eth_device *netdev, bd_t *bd)
2307{
2308 struct eth_dev *dev = &l_ethdev;
2309 struct usb_gadget *gadget;
2310 unsigned long ts;
2311 unsigned long timeout = USB_CONNECT_TIMEOUT;
2312
2313 if (!netdev) {
2314 error("received NULL ptr");
2315 goto fail;
2316 }
2317
2318 board_usb_init(0, USB_INIT_DEVICE);
2319
2320
2321#ifdef CONFIG_USBNET_DEV_ADDR
2322 strlcpy(dev_addr, CONFIG_USBNET_DEV_ADDR, sizeof(dev_addr));
2323#endif
2324#ifdef CONFIG_USBNET_HOST_ADDR
2325 strlcpy(host_addr, CONFIG_USBNET_HOST_ADDR, sizeof(host_addr));
2326#endif
2327
2328 if (getenv("usbnet_devaddr"))
2329 strlcpy(dev_addr, getenv("usbnet_devaddr"),
2330 sizeof(dev_addr));
2331
2332 if (getenv("usbnet_hostaddr"))
2333 strlcpy(host_addr, getenv("usbnet_hostaddr"),
2334 sizeof(host_addr));
2335
2336 if (!is_eth_addr_valid(dev_addr)) {
2337 error("Need valid 'usbnet_devaddr' to be set");
2338 goto fail;
2339 }
2340 if (!is_eth_addr_valid(host_addr)) {
2341 error("Need valid 'usbnet_hostaddr' to be set");
2342 goto fail;
2343 }
2344
2345 if (usb_gadget_register_driver(ð_driver) < 0)
2346 goto fail;
2347
2348 dev->network_started = 0;
2349
2350 packet_received = 0;
2351 packet_sent = 0;
2352
2353 gadget = dev->gadget;
2354 usb_gadget_connect(gadget);
2355
2356 if (getenv("cdc_connect_timeout"))
2357 timeout = simple_strtoul(getenv("cdc_connect_timeout"),
2358 NULL, 10) * CONFIG_SYS_HZ;
2359 ts = get_timer(0);
2360 while (!l_ethdev.network_started) {
2361
2362 if (ctrlc() || (get_timer(ts) > timeout)) {
2363 error("The remote end did not respond in time.");
2364 goto fail;
2365 }
2366 usb_gadget_handle_interrupts(0);
2367 }
2368
2369 packet_received = 0;
2370 rx_submit(dev, dev->rx_req, 0);
2371 return 0;
2372fail:
2373 return -1;
2374}
2375
2376static int usb_eth_send(struct eth_device *netdev, void *packet, int length)
2377{
2378 int retval;
2379 void *rndis_pkt = NULL;
2380 struct eth_dev *dev = &l_ethdev;
2381 struct usb_request *req = dev->tx_req;
2382 unsigned long ts;
2383 unsigned long timeout = USB_CONNECT_TIMEOUT;
2384
2385 debug("%s:...\n", __func__);
2386
2387
2388 if (rndis_active(dev)) {
2389 rndis_pkt = malloc(length +
2390 sizeof(struct rndis_packet_msg_type));
2391 if (!rndis_pkt) {
2392 error("No memory to alloc RNDIS packet");
2393 goto drop;
2394 }
2395 rndis_add_hdr(rndis_pkt, length);
2396 memcpy(rndis_pkt + sizeof(struct rndis_packet_msg_type),
2397 packet, length);
2398 packet = rndis_pkt;
2399 length += sizeof(struct rndis_packet_msg_type);
2400 }
2401 req->buf = packet;
2402 req->context = NULL;
2403 req->complete = tx_complete;
2404
2405
2406
2407
2408
2409
2410 req->zero = 1;
2411 if (!dev->zlp && (length % dev->in_ep->maxpacket) == 0)
2412 length++;
2413
2414 req->length = length;
2415#if 0
2416
2417 if (gadget_is_dualspeed(dev->gadget))
2418 req->no_interrupt = (dev->gadget->speed == USB_SPEED_HIGH)
2419 ? ((dev->tx_qlen % qmult) != 0) : 0;
2420#endif
2421 dev->tx_qlen = 1;
2422 ts = get_timer(0);
2423 packet_sent = 0;
2424
2425 retval = usb_ep_queue(dev->in_ep, req, GFP_ATOMIC);
2426
2427 if (!retval)
2428 debug("%s: packet queued\n", __func__);
2429 while (!packet_sent) {
2430 if (get_timer(ts) > timeout) {
2431 printf("timeout sending packets to usb ethernet\n");
2432 return -1;
2433 }
2434 usb_gadget_handle_interrupts(0);
2435 }
2436 if (rndis_pkt)
2437 free(rndis_pkt);
2438
2439 return 0;
2440drop:
2441 dev->stats.tx_dropped++;
2442 return -ENOMEM;
2443}
2444
2445static int usb_eth_recv(struct eth_device *netdev)
2446{
2447 struct eth_dev *dev = &l_ethdev;
2448
2449 usb_gadget_handle_interrupts(0);
2450
2451 if (packet_received) {
2452 debug("%s: packet received\n", __func__);
2453 if (dev->rx_req) {
2454 net_process_received_packet(net_rx_packets[0],
2455 dev->rx_req->length);
2456 packet_received = 0;
2457
2458 rx_submit(dev, dev->rx_req, 0);
2459 } else
2460 error("dev->rx_req invalid");
2461 }
2462 return 0;
2463}
2464
2465void usb_eth_halt(struct eth_device *netdev)
2466{
2467 struct eth_dev *dev = &l_ethdev;
2468
2469 if (!netdev) {
2470 error("received NULL ptr");
2471 return;
2472 }
2473
2474
2475 if (!dev->gadget)
2476 return;
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489 eth_stop(dev);
2490
2491 usb_gadget_disconnect(dev->gadget);
2492
2493
2494 if (dev->network_started) {
2495 usb_gadget_handle_interrupts(0);
2496 dev->network_started = 0;
2497 }
2498
2499 usb_gadget_unregister_driver(ð_driver);
2500 board_usb_cleanup(0, USB_INIT_DEVICE);
2501}
2502
2503static struct usb_gadget_driver eth_driver = {
2504 .speed = DEVSPEED,
2505
2506 .bind = eth_bind,
2507 .unbind = eth_unbind,
2508
2509 .setup = eth_setup,
2510 .reset = eth_disconnect,
2511 .disconnect = eth_disconnect,
2512
2513 .suspend = eth_suspend,
2514 .resume = eth_resume,
2515};
2516
2517int usb_eth_initialize(bd_t *bi)
2518{
2519 struct eth_device *netdev = &l_netdev;
2520
2521 strlcpy(netdev->name, USB_NET_NAME, sizeof(netdev->name));
2522
2523 netdev->init = usb_eth_init;
2524 netdev->send = usb_eth_send;
2525 netdev->recv = usb_eth_recv;
2526 netdev->halt = usb_eth_halt;
2527
2528#ifdef CONFIG_MCAST_TFTP
2529 #error not supported
2530#endif
2531 eth_register(netdev);
2532 return 0;
2533}
2534