1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <common.h>
23#include <usb.h>
24
25#include "usb_ether.h"
26
27typedef void (*usb_eth_before_probe)(void);
28typedef int (*usb_eth_probe)(struct usb_device *dev, unsigned int ifnum,
29 struct ueth_data *ss);
30typedef int (*usb_eth_get_info)(struct usb_device *dev, struct ueth_data *ss,
31 struct eth_device *dev_desc);
32
33struct usb_eth_prob_dev {
34 usb_eth_before_probe before_probe;
35 usb_eth_probe probe;
36 usb_eth_get_info get_info;
37};
38
39
40static const struct usb_eth_prob_dev prob_dev[] = {
41#ifdef CONFIG_USB_ETHER_ASIX
42 {
43 .before_probe = asix_eth_before_probe,
44 .probe = asix_eth_probe,
45 .get_info = asix_eth_get_info,
46 },
47#endif
48#ifdef CONFIG_USB_ETHER_SMSC95XX
49 {
50 .before_probe = smsc95xx_eth_before_probe,
51 .probe = smsc95xx_eth_probe,
52 .get_info = smsc95xx_eth_get_info,
53 },
54#endif
55 { },
56};
57
58static int usb_max_eth_dev;
59static struct ueth_data usb_eth[USB_MAX_ETH_DEV];
60
61
62
63
64int is_eth_dev_on_usb_host(void)
65{
66 int i;
67 struct eth_device *dev = eth_get_dev();
68
69 if (dev) {
70 for (i = 0; i < usb_max_eth_dev; i++)
71 if (&usb_eth[i].eth_dev == dev)
72 return 1;
73 }
74 return 0;
75}
76
77
78
79
80
81static void probe_valid_drivers(struct usb_device *dev)
82{
83 struct eth_device *eth;
84 int j;
85
86 for (j = 0; prob_dev[j].probe && prob_dev[j].get_info; j++) {
87 if (!prob_dev[j].probe(dev, 0, &usb_eth[usb_max_eth_dev]))
88 continue;
89
90
91
92 eth = &usb_eth[usb_max_eth_dev].eth_dev;
93 if (prob_dev[j].get_info(dev,
94 &usb_eth[usb_max_eth_dev],
95 eth)) {
96
97
98 usb_max_eth_dev++;
99
100
101
102
103
104
105 eth_register(eth);
106 if (eth_write_hwaddr(eth, "usbeth",
107 usb_max_eth_dev - 1))
108 puts("Warning: failed to set MAC address\n");
109 break;
110 }
111 }
112 }
113
114
115
116
117
118
119int usb_host_eth_scan(int mode)
120{
121 int i, old_async;
122 struct usb_device *dev;
123
124
125 if (mode == 1)
126 printf(" scanning usb for ethernet devices... ");
127
128 old_async = usb_disable_asynch(1);
129
130
131 for (i = 0; i < usb_max_eth_dev; i++)
132 eth_unregister(&usb_eth[i].eth_dev);
133
134 memset(usb_eth, 0, sizeof(usb_eth));
135
136 for (i = 0; prob_dev[i].probe; i++) {
137 if (prob_dev[i].before_probe)
138 prob_dev[i].before_probe();
139 }
140
141 usb_max_eth_dev = 0;
142 for (i = 0; i < USB_MAX_DEVICE; i++) {
143 dev = usb_get_dev_index(i);
144 debug("i=%d\n", i);
145 if (dev == NULL)
146 break;
147
148
149 probe_valid_drivers(dev);
150
151
152 if (usb_max_eth_dev == USB_MAX_ETH_DEV) {
153 printf("max USB Ethernet Device reached: %d stopping\n",
154 usb_max_eth_dev);
155 break;
156 }
157 }
158
159 usb_disable_asynch(old_async);
160 printf("%d Ethernet Device(s) found\n", usb_max_eth_dev);
161 if (usb_max_eth_dev > 0)
162 return 0;
163 return -1;
164}
165