diff options
Diffstat (limited to 'drivers/usb/net')
-rw-r--r-- | drivers/usb/net/Kconfig | 208 | ||||
-rw-r--r-- | drivers/usb/net/Makefile | 8 | ||||
-rw-r--r-- | drivers/usb/net/asix.c | 948 | ||||
-rw-r--r-- | drivers/usb/net/catc.c | 2 | ||||
-rw-r--r-- | drivers/usb/net/cdc_ether.c | 509 | ||||
-rw-r--r-- | drivers/usb/net/cdc_subset.c | 335 | ||||
-rw-r--r-- | drivers/usb/net/gl620a.c | 407 | ||||
-rw-r--r-- | drivers/usb/net/kaweth.c | 1 | ||||
-rw-r--r-- | drivers/usb/net/net1080.c | 622 | ||||
-rw-r--r-- | drivers/usb/net/pegasus.c | 1 | ||||
-rw-r--r-- | drivers/usb/net/plusb.c | 156 | ||||
-rw-r--r-- | drivers/usb/net/rndis_host.c | 615 | ||||
-rw-r--r-- | drivers/usb/net/rtl8150.c | 1 | ||||
-rw-r--r-- | drivers/usb/net/usbnet.c | 3226 | ||||
-rw-r--r-- | drivers/usb/net/usbnet.h | 193 | ||||
-rw-r--r-- | drivers/usb/net/zaurus.c | 386 | ||||
-rw-r--r-- | drivers/usb/net/zd1201.c | 1 |
17 files changed, 4393 insertions, 3226 deletions
diff --git a/drivers/usb/net/Kconfig b/drivers/usb/net/Kconfig index b104430e2c6a..8c010bb44eb8 100644 --- a/drivers/usb/net/Kconfig +++ b/drivers/usb/net/Kconfig | |||
@@ -99,7 +99,7 @@ config USB_USBNET | |||
99 | with "minidrivers" built around a common network driver core | 99 | with "minidrivers" built around a common network driver core |
100 | that supports deep queues for efficient transfers. (This gives | 100 | that supports deep queues for efficient transfers. (This gives |
101 | better performance with small packets and at high speeds). | 101 | better performance with small packets and at high speeds). |
102 | 102 | ||
103 | The USB host runs "usbnet", and the other end of the link might be: | 103 | The USB host runs "usbnet", and the other end of the link might be: |
104 | 104 | ||
105 | - Another USB host, when using USB "network" or "data transfer" | 105 | - Another USB host, when using USB "network" or "data transfer" |
@@ -125,38 +125,63 @@ config USB_USBNET | |||
125 | To compile this driver as a module, choose M here: the | 125 | To compile this driver as a module, choose M here: the |
126 | module will be called usbnet. | 126 | module will be called usbnet. |
127 | 127 | ||
128 | comment "USB Host-to-Host Cables" | 128 | config USB_NET_AX8817X |
129 | depends on USB_USBNET | 129 | tristate "ASIX AX88xxx Based USB 2.0 Ethernet Adapters" |
130 | 130 | depends on USB_USBNET && NET_ETHERNET | |
131 | config USB_ALI_M5632 | 131 | select CRC32 |
132 | boolean "ALi M5632 based 'USB 2.0 Data Link' cables" | 132 | select MII |
133 | depends on USB_USBNET | ||
134 | default y | 133 | default y |
135 | help | 134 | help |
136 | Choose this option if you're using a host-to-host cable | 135 | This option adds support for ASIX AX88xxx based USB 2.0 |
137 | based on this design, which supports USB 2.0 high speed. | 136 | 10/100 Ethernet adapters. |
138 | 137 | ||
139 | config USB_AN2720 | 138 | This driver should work with at least the following devices: |
140 | boolean "AnchorChips 2720 based cables (Xircom PGUNET, ...)" | 139 | * Aten UC210T |
141 | depends on USB_USBNET | 140 | * ASIX AX88172 |
142 | default y | 141 | * Billionton Systems, USB2AR |
143 | help | 142 | * Buffalo LUA-U2-KTX |
144 | Choose this option if you're using a host-to-host cable | 143 | * Corega FEther USB2-TX |
145 | based on this design. Note that AnchorChips is now a | 144 | * D-Link DUB-E100 |
146 | Cypress brand. | 145 | * Hawking UF200 |
146 | * Linksys USB200M | ||
147 | * Netgear FA120 | ||
148 | * Sitecom LN-029 | ||
149 | * Intellinet USB 2.0 Ethernet | ||
150 | * ST Lab USB 2.0 Ethernet | ||
151 | * TrendNet TU2-ET100 | ||
147 | 152 | ||
148 | config USB_BELKIN | 153 | This driver creates an interface named "ethX", where X depends on |
149 | boolean "eTEK based host-to-host cables (Advance, Belkin, ...)" | 154 | what other networking devices you have in use. |
155 | |||
156 | |||
157 | config USB_NET_CDCETHER | ||
158 | tristate "CDC Ethernet support (smart devices such as cable modems)" | ||
150 | depends on USB_USBNET | 159 | depends on USB_USBNET |
151 | default y | 160 | default y |
152 | help | 161 | help |
153 | Choose this option if you're using a host-to-host cable | 162 | This option supports devices conforming to the Communication Device |
154 | based on this design: two NetChip 2890 chips and an Atmel | 163 | Class (CDC) Ethernet Control Model, a specification that's easy to |
155 | microcontroller, with LEDs that indicate traffic. | 164 | implement in device firmware. The CDC specifications are available |
165 | from <http://www.usb.org/>. | ||
156 | 166 | ||
157 | config USB_GENESYS | 167 | CDC Ethernet is an implementation option for DOCSIS cable modems |
158 | boolean "GeneSys GL620USB-A based cables" | 168 | that support USB connectivity, used for non-Microsoft USB hosts. |
159 | default y | 169 | The Linux-USB CDC Ethernet Gadget driver is an open implementation. |
170 | This driver should work with at least the following devices: | ||
171 | |||
172 | * Ericsson PipeRider (all variants) | ||
173 | * Motorola (DM100 and SB4100) | ||
174 | * Broadcom Cable Modem (reference design) | ||
175 | * Toshiba PCX1100U | ||
176 | * ... | ||
177 | |||
178 | This driver creates an interface named "ethX", where X depends on | ||
179 | what other networking devices you have in use. However, if the | ||
180 | IEEE 802 "local assignment" bit is set in the address, a "usbX" | ||
181 | name is used instead. | ||
182 | |||
183 | config USB_NET_GL620A | ||
184 | tristate "GeneSys GL620USB-A based cables" | ||
160 | depends on USB_USBNET | 185 | depends on USB_USBNET |
161 | help | 186 | help |
162 | Choose this option if you're using a host-to-host cable, | 187 | Choose this option if you're using a host-to-host cable, |
@@ -164,38 +189,78 @@ config USB_GENESYS | |||
164 | 189 | ||
165 | Note that the half-duplex "GL620USB" is not supported. | 190 | Note that the half-duplex "GL620USB" is not supported. |
166 | 191 | ||
167 | config USB_NET1080 | 192 | config USB_NET_NET1080 |
168 | boolean "NetChip 1080 based cables (Laplink, ...)" | 193 | tristate "NetChip 1080 based cables (Laplink, ...)" |
169 | default y | 194 | default y |
170 | depends on USB_USBNET | 195 | depends on USB_USBNET |
171 | help | 196 | help |
172 | Choose this option if you're using a host-to-host cable based | 197 | Choose this option if you're using a host-to-host cable based |
173 | on this design: one NetChip 1080 chips and supporting logic, | 198 | on this design: one NetChip 1080 chip and supporting logic, |
174 | supporting LEDs that indicate traffic | 199 | optionally with LEDs that indicate traffic |
175 | 200 | ||
176 | config USB_PL2301 | 201 | config USB_NET_PLUSB |
177 | boolean "Prolific PL-2301/2302 based cables" | 202 | tristate "Prolific PL-2301/2302 based cables" |
178 | default y | 203 | # if the handshake/init/reset problems, from original 'plusb', |
179 | # handshake/init/reset problems, from original 'plusb' driver | 204 | # are ever resolved ... then remove "experimental" |
180 | depends on USB_USBNET && EXPERIMENTAL | 205 | depends on USB_USBNET && EXPERIMENTAL |
181 | help | 206 | help |
182 | Choose this option if you're using a host-to-host cable | 207 | Choose this option if you're using a host-to-host cable |
183 | with one of these chips. | 208 | with one of these chips. |
184 | 209 | ||
185 | config USB_KC2190 | 210 | config USB_NET_RNDIS_HOST |
186 | boolean "KT Technology KC2190 based cables (InstaNet)" | 211 | tristate "Host for RNDIS devices (EXPERIMENTAL)" |
187 | default y | ||
188 | depends on USB_USBNET && EXPERIMENTAL | 212 | depends on USB_USBNET && EXPERIMENTAL |
213 | select USB_NET_CDCETHER | ||
189 | help | 214 | help |
190 | Choose this option if you're using a host-to-host cable | 215 | This option enables hosting "Remote NDIS" USB networking links, |
191 | with one of these chips. | 216 | as encouraged by Microsoft (instead of CDC Ethernet!) for use in |
217 | various devices that may only support this protocol. | ||
192 | 218 | ||
193 | comment "Intelligent USB Devices/Gadgets" | 219 | Avoid using this protocol unless you have no better options. |
220 | The protocol specification is incomplete, and is controlled by | ||
221 | (and for) Microsoft; it isn't an "Open" ecosystem or market. | ||
222 | |||
223 | config USB_NET_CDC_SUBSET | ||
224 | tristate "Simple USB Network Links (CDC Ethernet subset)" | ||
194 | depends on USB_USBNET | 225 | depends on USB_USBNET |
226 | help | ||
227 | This driver module supports USB network devices that can work | ||
228 | without any device-specific information. Select it if you have | ||
229 | one of these drivers. | ||
230 | |||
231 | Note that while many USB host-to-host cables can work in this mode, | ||
232 | that may mean not being able to talk to Win32 systems or more | ||
233 | commonly not being able to handle certain events (like replugging | ||
234 | the host on the other end) very well. Also, these devices will | ||
235 | not generally have permanently assigned Ethernet addresses. | ||
236 | |||
237 | config USB_ALI_M5632 | ||
238 | boolean "ALi M5632 based 'USB 2.0 Data Link' cables" | ||
239 | depends on USB_NET_CDC_SUBSET | ||
240 | help | ||
241 | Choose this option if you're using a host-to-host cable | ||
242 | based on this design, which supports USB 2.0 high speed. | ||
243 | |||
244 | config USB_AN2720 | ||
245 | boolean "AnchorChips 2720 based cables (Xircom PGUNET, ...)" | ||
246 | depends on USB_NET_CDC_SUBSET | ||
247 | help | ||
248 | Choose this option if you're using a host-to-host cable | ||
249 | based on this design. Note that AnchorChips is now a | ||
250 | Cypress brand. | ||
251 | |||
252 | config USB_BELKIN | ||
253 | boolean "eTEK based host-to-host cables (Advance, Belkin, ...)" | ||
254 | depends on USB_NET_CDC_SUBSET | ||
255 | default y | ||
256 | help | ||
257 | Choose this option if you're using a host-to-host cable | ||
258 | based on this design: two NetChip 2890 chips and an Atmel | ||
259 | microcontroller, with LEDs that indicate traffic. | ||
195 | 260 | ||
196 | config USB_ARMLINUX | 261 | config USB_ARMLINUX |
197 | boolean "Embedded ARM Linux links (iPaq, ...)" | 262 | boolean "Embedded ARM Linux links (iPaq, ...)" |
198 | depends on USB_USBNET | 263 | depends on USB_NET_CDC_SUBSET |
199 | default y | 264 | default y |
200 | help | 265 | help |
201 | Choose this option to support the "usb-eth" networking driver | 266 | Choose this option to support the "usb-eth" networking driver |
@@ -212,15 +277,15 @@ config USB_ARMLINUX | |||
212 | 277 | ||
213 | config USB_EPSON2888 | 278 | config USB_EPSON2888 |
214 | boolean "Epson 2888 based firmware (DEVELOPMENT)" | 279 | boolean "Epson 2888 based firmware (DEVELOPMENT)" |
215 | depends on USB_USBNET | 280 | depends on USB_NET_CDC_SUBSET |
216 | default y | ||
217 | help | 281 | help |
218 | Choose this option to support the usb networking links used | 282 | Choose this option to support the usb networking links used |
219 | by some sample firmware from Epson. | 283 | by some sample firmware from Epson. |
220 | 284 | ||
221 | config USB_ZAURUS | 285 | config USB_NET_ZAURUS |
222 | boolean "Sharp Zaurus (stock ROMs) and compatible" | 286 | tristate "Sharp Zaurus (stock ROMs) and compatible" |
223 | depends on USB_USBNET | 287 | depends on USB_USBNET |
288 | select USB_NET_CDCETHER | ||
224 | select CRC32 | 289 | select CRC32 |
225 | default y | 290 | default y |
226 | help | 291 | help |
@@ -235,61 +300,6 @@ config USB_ZAURUS | |||
235 | really need this non-conformant variant of CDC Ethernet (or in | 300 | really need this non-conformant variant of CDC Ethernet (or in |
236 | some cases CDC MDLM) protocol, not "g_ether". | 301 | some cases CDC MDLM) protocol, not "g_ether". |
237 | 302 | ||
238 | config USB_CDCETHER | ||
239 | boolean "CDC Ethernet support (smart devices such as cable modems)" | ||
240 | depends on USB_USBNET | ||
241 | default y | ||
242 | help | ||
243 | This option supports devices conforming to the Communication Device | ||
244 | Class (CDC) Ethernet Control Model, a specification that's easy to | ||
245 | implement in device firmware. The CDC specifications are available | ||
246 | from <http://www.usb.org/>. | ||
247 | |||
248 | CDC Ethernet is an implementation option for DOCSIS cable modems | ||
249 | that support USB connectivity, used for non-Microsoft USB hosts. | ||
250 | This driver should work with at least the following devices: | ||
251 | |||
252 | * Ericsson PipeRider (all variants) | ||
253 | * Motorola (DM100 and SB4100) | ||
254 | * Broadcom Cable Modem (reference design) | ||
255 | * Toshiba PCX1100U | ||
256 | * ... | ||
257 | |||
258 | This driver creates an interface named "ethX", where X depends on | ||
259 | what other networking devices you have in use. However, if the | ||
260 | IEEE 802 "local assignment" bit is set in the address, a "usbX" | ||
261 | name is used instead. | ||
262 | |||
263 | comment "USB Network Adapters" | ||
264 | depends on USB_USBNET | ||
265 | |||
266 | config USB_AX8817X | ||
267 | boolean "ASIX AX88xxx Based USB 2.0 Ethernet Devices" | ||
268 | depends on USB_USBNET && NET_ETHERNET | ||
269 | select CRC32 | ||
270 | select MII | ||
271 | default y | ||
272 | help | ||
273 | This option adds support for ASIX AX88xxx based USB 2.0 | ||
274 | 10/100 Ethernet devices. | ||
275 | |||
276 | This driver should work with at least the following devices: | ||
277 | * Aten UC210T | ||
278 | * ASIX AX88172 | ||
279 | * Billionton Systems, USB2AR | ||
280 | * Buffalo LUA-U2-KTX | ||
281 | * Corega FEther USB2-TX | ||
282 | * D-Link DUB-E100 | ||
283 | * Hawking UF200 | ||
284 | * Linksys USB200M | ||
285 | * Netgear FA120 | ||
286 | * Sitecom LN-029 | ||
287 | * Intellinet USB 2.0 Ethernet | ||
288 | * ST Lab USB 2.0 Ethernet | ||
289 | * TrendNet TU2-ET100 | ||
290 | |||
291 | This driver creates an interface named "ethX", where X depends on | ||
292 | what other networking devices you have in use. | ||
293 | 303 | ||
294 | config USB_ZD1201 | 304 | config USB_ZD1201 |
295 | tristate "USB ZD1201 based Wireless device support" | 305 | tristate "USB ZD1201 based Wireless device support" |
diff --git a/drivers/usb/net/Makefile b/drivers/usb/net/Makefile index fe3fd4115e1e..222c0495f791 100644 --- a/drivers/usb/net/Makefile +++ b/drivers/usb/net/Makefile | |||
@@ -6,5 +6,13 @@ obj-$(CONFIG_USB_CATC) += catc.o | |||
6 | obj-$(CONFIG_USB_KAWETH) += kaweth.o | 6 | obj-$(CONFIG_USB_KAWETH) += kaweth.o |
7 | obj-$(CONFIG_USB_PEGASUS) += pegasus.o | 7 | obj-$(CONFIG_USB_PEGASUS) += pegasus.o |
8 | obj-$(CONFIG_USB_RTL8150) += rtl8150.o | 8 | obj-$(CONFIG_USB_RTL8150) += rtl8150.o |
9 | obj-$(CONFIG_USB_NET_AX8817X) += asix.o | ||
10 | obj-$(CONFIG_USB_NET_CDCETHER) += cdc_ether.o | ||
11 | obj-$(CONFIG_USB_NET_GL620A) += gl620a.o | ||
12 | obj-$(CONFIG_USB_NET_NET1080) += net1080.o | ||
13 | obj-$(CONFIG_USB_NET_PLUSB) += plusb.o | ||
14 | obj-$(CONFIG_USB_NET_RNDIS_HOST) += rndis_host.o | ||
15 | obj-$(CONFIG_USB_NET_CDC_SUBSET) += cdc_subset.o | ||
16 | obj-$(CONFIG_USB_NET_ZAURUS) += zaurus.o | ||
9 | obj-$(CONFIG_USB_USBNET) += usbnet.o | 17 | obj-$(CONFIG_USB_USBNET) += usbnet.o |
10 | obj-$(CONFIG_USB_ZD1201) += zd1201.o | 18 | obj-$(CONFIG_USB_ZD1201) += zd1201.o |
diff --git a/drivers/usb/net/asix.c b/drivers/usb/net/asix.c new file mode 100644 index 000000000000..861f00a43750 --- /dev/null +++ b/drivers/usb/net/asix.c | |||
@@ -0,0 +1,948 @@ | |||
1 | /* | ||
2 | * ASIX AX8817X based USB 2.0 Ethernet Devices | ||
3 | * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com> | ||
4 | * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net> | ||
5 | * Copyright (c) 2002-2003 TiVo Inc. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | ||
21 | |||
22 | // #define DEBUG // error path messages, extra info | ||
23 | // #define VERBOSE // more; success messages | ||
24 | |||
25 | #include <linux/config.h> | ||
26 | #ifdef CONFIG_USB_DEBUG | ||
27 | # define DEBUG | ||
28 | #endif | ||
29 | #include <linux/module.h> | ||
30 | #include <linux/kmod.h> | ||
31 | #include <linux/sched.h> | ||
32 | #include <linux/init.h> | ||
33 | #include <linux/netdevice.h> | ||
34 | #include <linux/etherdevice.h> | ||
35 | #include <linux/ethtool.h> | ||
36 | #include <linux/workqueue.h> | ||
37 | #include <linux/mii.h> | ||
38 | #include <linux/usb.h> | ||
39 | #include <linux/crc32.h> | ||
40 | |||
41 | #include "usbnet.h" | ||
42 | |||
43 | |||
44 | /* ASIX AX8817X based USB 2.0 Ethernet Devices */ | ||
45 | |||
46 | #define AX_CMD_SET_SW_MII 0x06 | ||
47 | #define AX_CMD_READ_MII_REG 0x07 | ||
48 | #define AX_CMD_WRITE_MII_REG 0x08 | ||
49 | #define AX_CMD_SET_HW_MII 0x0a | ||
50 | #define AX_CMD_READ_EEPROM 0x0b | ||
51 | #define AX_CMD_WRITE_EEPROM 0x0c | ||
52 | #define AX_CMD_WRITE_ENABLE 0x0d | ||
53 | #define AX_CMD_WRITE_DISABLE 0x0e | ||
54 | #define AX_CMD_WRITE_RX_CTL 0x10 | ||
55 | #define AX_CMD_READ_IPG012 0x11 | ||
56 | #define AX_CMD_WRITE_IPG0 0x12 | ||
57 | #define AX_CMD_WRITE_IPG1 0x13 | ||
58 | #define AX_CMD_WRITE_IPG2 0x14 | ||
59 | #define AX_CMD_WRITE_MULTI_FILTER 0x16 | ||
60 | #define AX_CMD_READ_NODE_ID 0x17 | ||
61 | #define AX_CMD_READ_PHY_ID 0x19 | ||
62 | #define AX_CMD_READ_MEDIUM_STATUS 0x1a | ||
63 | #define AX_CMD_WRITE_MEDIUM_MODE 0x1b | ||
64 | #define AX_CMD_READ_MONITOR_MODE 0x1c | ||
65 | #define AX_CMD_WRITE_MONITOR_MODE 0x1d | ||
66 | #define AX_CMD_WRITE_GPIOS 0x1f | ||
67 | #define AX_CMD_SW_RESET 0x20 | ||
68 | #define AX_CMD_SW_PHY_STATUS 0x21 | ||
69 | #define AX_CMD_SW_PHY_SELECT 0x22 | ||
70 | #define AX88772_CMD_READ_NODE_ID 0x13 | ||
71 | |||
72 | #define AX_MONITOR_MODE 0x01 | ||
73 | #define AX_MONITOR_LINK 0x02 | ||
74 | #define AX_MONITOR_MAGIC 0x04 | ||
75 | #define AX_MONITOR_HSFS 0x10 | ||
76 | |||
77 | /* AX88172 Medium Status Register values */ | ||
78 | #define AX_MEDIUM_FULL_DUPLEX 0x02 | ||
79 | #define AX_MEDIUM_TX_ABORT_ALLOW 0x04 | ||
80 | #define AX_MEDIUM_FLOW_CONTROL_EN 0x10 | ||
81 | |||
82 | #define AX_MCAST_FILTER_SIZE 8 | ||
83 | #define AX_MAX_MCAST 64 | ||
84 | |||
85 | #define AX_EEPROM_LEN 0x40 | ||
86 | |||
87 | #define AX_SWRESET_CLEAR 0x00 | ||
88 | #define AX_SWRESET_RR 0x01 | ||
89 | #define AX_SWRESET_RT 0x02 | ||
90 | #define AX_SWRESET_PRTE 0x04 | ||
91 | #define AX_SWRESET_PRL 0x08 | ||
92 | #define AX_SWRESET_BZ 0x10 | ||
93 | #define AX_SWRESET_IPRL 0x20 | ||
94 | #define AX_SWRESET_IPPD 0x40 | ||
95 | |||
96 | #define AX88772_IPG0_DEFAULT 0x15 | ||
97 | #define AX88772_IPG1_DEFAULT 0x0c | ||
98 | #define AX88772_IPG2_DEFAULT 0x12 | ||
99 | |||
100 | #define AX88772_MEDIUM_FULL_DUPLEX 0x0002 | ||
101 | #define AX88772_MEDIUM_RESERVED 0x0004 | ||
102 | #define AX88772_MEDIUM_RX_FC_ENABLE 0x0010 | ||
103 | #define AX88772_MEDIUM_TX_FC_ENABLE 0x0020 | ||
104 | #define AX88772_MEDIUM_PAUSE_FORMAT 0x0080 | ||
105 | #define AX88772_MEDIUM_RX_ENABLE 0x0100 | ||
106 | #define AX88772_MEDIUM_100MB 0x0200 | ||
107 | #define AX88772_MEDIUM_DEFAULT \ | ||
108 | (AX88772_MEDIUM_FULL_DUPLEX | AX88772_MEDIUM_RX_FC_ENABLE | \ | ||
109 | AX88772_MEDIUM_TX_FC_ENABLE | AX88772_MEDIUM_100MB | \ | ||
110 | AX88772_MEDIUM_RESERVED | AX88772_MEDIUM_RX_ENABLE ) | ||
111 | |||
112 | #define AX_EEPROM_MAGIC 0xdeadbeef | ||
113 | |||
114 | /* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */ | ||
115 | struct ax8817x_data { | ||
116 | u8 multi_filter[AX_MCAST_FILTER_SIZE]; | ||
117 | }; | ||
118 | |||
119 | struct ax88172_int_data { | ||
120 | u16 res1; | ||
121 | u8 link; | ||
122 | u16 res2; | ||
123 | u8 status; | ||
124 | u16 res3; | ||
125 | } __attribute__ ((packed)); | ||
126 | |||
127 | static int ax8817x_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, | ||
128 | u16 size, void *data) | ||
129 | { | ||
130 | return usb_control_msg( | ||
131 | dev->udev, | ||
132 | usb_rcvctrlpipe(dev->udev, 0), | ||
133 | cmd, | ||
134 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
135 | value, | ||
136 | index, | ||
137 | data, | ||
138 | size, | ||
139 | USB_CTRL_GET_TIMEOUT); | ||
140 | } | ||
141 | |||
142 | static int ax8817x_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, | ||
143 | u16 size, void *data) | ||
144 | { | ||
145 | return usb_control_msg( | ||
146 | dev->udev, | ||
147 | usb_sndctrlpipe(dev->udev, 0), | ||
148 | cmd, | ||
149 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
150 | value, | ||
151 | index, | ||
152 | data, | ||
153 | size, | ||
154 | USB_CTRL_SET_TIMEOUT); | ||
155 | } | ||
156 | |||
157 | static void ax8817x_async_cmd_callback(struct urb *urb, struct pt_regs *regs) | ||
158 | { | ||
159 | struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context; | ||
160 | |||
161 | if (urb->status < 0) | ||
162 | printk(KERN_DEBUG "ax8817x_async_cmd_callback() failed with %d", | ||
163 | urb->status); | ||
164 | |||
165 | kfree(req); | ||
166 | usb_free_urb(urb); | ||
167 | } | ||
168 | |||
169 | static void ax8817x_status(struct usbnet *dev, struct urb *urb) | ||
170 | { | ||
171 | struct ax88172_int_data *event; | ||
172 | int link; | ||
173 | |||
174 | if (urb->actual_length < 8) | ||
175 | return; | ||
176 | |||
177 | event = urb->transfer_buffer; | ||
178 | link = event->link & 0x01; | ||
179 | if (netif_carrier_ok(dev->net) != link) { | ||
180 | if (link) { | ||
181 | netif_carrier_on(dev->net); | ||
182 | usbnet_defer_kevent (dev, EVENT_LINK_RESET ); | ||
183 | } else | ||
184 | netif_carrier_off(dev->net); | ||
185 | devdbg(dev, "ax8817x - Link Status is: %d", link); | ||
186 | } | ||
187 | } | ||
188 | |||
189 | static void | ||
190 | ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index, | ||
191 | u16 size, void *data) | ||
192 | { | ||
193 | struct usb_ctrlrequest *req; | ||
194 | int status; | ||
195 | struct urb *urb; | ||
196 | |||
197 | if ((urb = usb_alloc_urb(0, GFP_ATOMIC)) == NULL) { | ||
198 | devdbg(dev, "Error allocating URB in write_cmd_async!"); | ||
199 | return; | ||
200 | } | ||
201 | |||
202 | if ((req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC)) == NULL) { | ||
203 | deverr(dev, "Failed to allocate memory for control request"); | ||
204 | usb_free_urb(urb); | ||
205 | return; | ||
206 | } | ||
207 | |||
208 | req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE; | ||
209 | req->bRequest = cmd; | ||
210 | req->wValue = cpu_to_le16(value); | ||
211 | req->wIndex = cpu_to_le16(index); | ||
212 | req->wLength = cpu_to_le16(size); | ||
213 | |||
214 | usb_fill_control_urb(urb, dev->udev, | ||
215 | usb_sndctrlpipe(dev->udev, 0), | ||
216 | (void *)req, data, size, | ||
217 | ax8817x_async_cmd_callback, req); | ||
218 | |||
219 | if((status = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { | ||
220 | deverr(dev, "Error submitting the control message: status=%d", | ||
221 | status); | ||
222 | kfree(req); | ||
223 | usb_free_urb(urb); | ||
224 | } | ||
225 | } | ||
226 | |||
227 | static void ax8817x_set_multicast(struct net_device *net) | ||
228 | { | ||
229 | struct usbnet *dev = netdev_priv(net); | ||
230 | struct ax8817x_data *data = (struct ax8817x_data *)&dev->data; | ||
231 | u8 rx_ctl = 0x8c; | ||
232 | |||
233 | if (net->flags & IFF_PROMISC) { | ||
234 | rx_ctl |= 0x01; | ||
235 | } else if (net->flags & IFF_ALLMULTI | ||
236 | || net->mc_count > AX_MAX_MCAST) { | ||
237 | rx_ctl |= 0x02; | ||
238 | } else if (net->mc_count == 0) { | ||
239 | /* just broadcast and directed */ | ||
240 | } else { | ||
241 | /* We use the 20 byte dev->data | ||
242 | * for our 8 byte filter buffer | ||
243 | * to avoid allocating memory that | ||
244 | * is tricky to free later */ | ||
245 | struct dev_mc_list *mc_list = net->mc_list; | ||
246 | u32 crc_bits; | ||
247 | int i; | ||
248 | |||
249 | memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE); | ||
250 | |||
251 | /* Build the multicast hash filter. */ | ||
252 | for (i = 0; i < net->mc_count; i++) { | ||
253 | crc_bits = | ||
254 | ether_crc(ETH_ALEN, | ||
255 | mc_list->dmi_addr) >> 26; | ||
256 | data->multi_filter[crc_bits >> 3] |= | ||
257 | 1 << (crc_bits & 7); | ||
258 | mc_list = mc_list->next; | ||
259 | } | ||
260 | |||
261 | ax8817x_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0, | ||
262 | AX_MCAST_FILTER_SIZE, data->multi_filter); | ||
263 | |||
264 | rx_ctl |= 0x10; | ||
265 | } | ||
266 | |||
267 | ax8817x_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL); | ||
268 | } | ||
269 | |||
270 | static int ax8817x_mdio_read(struct net_device *netdev, int phy_id, int loc) | ||
271 | { | ||
272 | struct usbnet *dev = netdev_priv(netdev); | ||
273 | u16 res; | ||
274 | u8 buf[1]; | ||
275 | |||
276 | ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf); | ||
277 | ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, | ||
278 | (__u16)loc, 2, (u16 *)&res); | ||
279 | ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf); | ||
280 | |||
281 | return res & 0xffff; | ||
282 | } | ||
283 | |||
284 | /* same as above, but converts resulting value to cpu byte order */ | ||
285 | static int ax8817x_mdio_read_le(struct net_device *netdev, int phy_id, int loc) | ||
286 | { | ||
287 | return le16_to_cpu(ax8817x_mdio_read(netdev,phy_id, loc)); | ||
288 | } | ||
289 | |||
290 | static void | ||
291 | ax8817x_mdio_write(struct net_device *netdev, int phy_id, int loc, int val) | ||
292 | { | ||
293 | struct usbnet *dev = netdev_priv(netdev); | ||
294 | u16 res = val; | ||
295 | u8 buf[1]; | ||
296 | |||
297 | ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf); | ||
298 | ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, | ||
299 | (__u16)loc, 2, (u16 *)&res); | ||
300 | ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf); | ||
301 | } | ||
302 | |||
303 | /* same as above, but converts new value to le16 byte order before writing */ | ||
304 | static void | ||
305 | ax8817x_mdio_write_le(struct net_device *netdev, int phy_id, int loc, int val) | ||
306 | { | ||
307 | ax8817x_mdio_write( netdev, phy_id, loc, cpu_to_le16(val) ); | ||
308 | } | ||
309 | |||
310 | static int ax88172_link_reset(struct usbnet *dev) | ||
311 | { | ||
312 | u16 lpa; | ||
313 | u16 adv; | ||
314 | u16 res; | ||
315 | u8 mode; | ||
316 | |||
317 | mode = AX_MEDIUM_TX_ABORT_ALLOW | AX_MEDIUM_FLOW_CONTROL_EN; | ||
318 | lpa = ax8817x_mdio_read_le(dev->net, dev->mii.phy_id, MII_LPA); | ||
319 | adv = ax8817x_mdio_read_le(dev->net, dev->mii.phy_id, MII_ADVERTISE); | ||
320 | res = mii_nway_result(lpa|adv); | ||
321 | if (res & LPA_DUPLEX) | ||
322 | mode |= AX_MEDIUM_FULL_DUPLEX; | ||
323 | ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL); | ||
324 | |||
325 | return 0; | ||
326 | } | ||
327 | |||
328 | static void | ||
329 | ax8817x_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) | ||
330 | { | ||
331 | struct usbnet *dev = netdev_priv(net); | ||
332 | u8 opt; | ||
333 | |||
334 | if (ax8817x_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) { | ||
335 | wolinfo->supported = 0; | ||
336 | wolinfo->wolopts = 0; | ||
337 | return; | ||
338 | } | ||
339 | wolinfo->supported = WAKE_PHY | WAKE_MAGIC; | ||
340 | wolinfo->wolopts = 0; | ||
341 | if (opt & AX_MONITOR_MODE) { | ||
342 | if (opt & AX_MONITOR_LINK) | ||
343 | wolinfo->wolopts |= WAKE_PHY; | ||
344 | if (opt & AX_MONITOR_MAGIC) | ||
345 | wolinfo->wolopts |= WAKE_MAGIC; | ||
346 | } | ||
347 | } | ||
348 | |||
349 | static int | ||
350 | ax8817x_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) | ||
351 | { | ||
352 | struct usbnet *dev = netdev_priv(net); | ||
353 | u8 opt = 0; | ||
354 | u8 buf[1]; | ||
355 | |||
356 | if (wolinfo->wolopts & WAKE_PHY) | ||
357 | opt |= AX_MONITOR_LINK; | ||
358 | if (wolinfo->wolopts & WAKE_MAGIC) | ||
359 | opt |= AX_MONITOR_MAGIC; | ||
360 | if (opt != 0) | ||
361 | opt |= AX_MONITOR_MODE; | ||
362 | |||
363 | if (ax8817x_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE, | ||
364 | opt, 0, 0, &buf) < 0) | ||
365 | return -EINVAL; | ||
366 | |||
367 | return 0; | ||
368 | } | ||
369 | |||
370 | static int ax8817x_get_eeprom_len(struct net_device *net) | ||
371 | { | ||
372 | return AX_EEPROM_LEN; | ||
373 | } | ||
374 | |||
375 | static int ax8817x_get_eeprom(struct net_device *net, | ||
376 | struct ethtool_eeprom *eeprom, u8 *data) | ||
377 | { | ||
378 | struct usbnet *dev = netdev_priv(net); | ||
379 | u16 *ebuf = (u16 *)data; | ||
380 | int i; | ||
381 | |||
382 | /* Crude hack to ensure that we don't overwrite memory | ||
383 | * if an odd length is supplied | ||
384 | */ | ||
385 | if (eeprom->len % 2) | ||
386 | return -EINVAL; | ||
387 | |||
388 | eeprom->magic = AX_EEPROM_MAGIC; | ||
389 | |||
390 | /* ax8817x returns 2 bytes from eeprom on read */ | ||
391 | for (i=0; i < eeprom->len / 2; i++) { | ||
392 | if (ax8817x_read_cmd(dev, AX_CMD_READ_EEPROM, | ||
393 | eeprom->offset + i, 0, 2, &ebuf[i]) < 0) | ||
394 | return -EINVAL; | ||
395 | } | ||
396 | return 0; | ||
397 | } | ||
398 | |||
399 | static void ax8817x_get_drvinfo (struct net_device *net, | ||
400 | struct ethtool_drvinfo *info) | ||
401 | { | ||
402 | /* Inherit standard device info */ | ||
403 | usbnet_get_drvinfo(net, info); | ||
404 | info->eedump_len = 0x3e; | ||
405 | } | ||
406 | |||
407 | static int ax8817x_get_settings(struct net_device *net, struct ethtool_cmd *cmd) | ||
408 | { | ||
409 | struct usbnet *dev = netdev_priv(net); | ||
410 | |||
411 | return mii_ethtool_gset(&dev->mii,cmd); | ||
412 | } | ||
413 | |||
414 | static int ax8817x_set_settings(struct net_device *net, struct ethtool_cmd *cmd) | ||
415 | { | ||
416 | struct usbnet *dev = netdev_priv(net); | ||
417 | |||
418 | return mii_ethtool_sset(&dev->mii,cmd); | ||
419 | } | ||
420 | |||
421 | /* We need to override some ethtool_ops so we require our | ||
422 | own structure so we don't interfere with other usbnet | ||
423 | devices that may be connected at the same time. */ | ||
424 | static struct ethtool_ops ax8817x_ethtool_ops = { | ||
425 | .get_drvinfo = ax8817x_get_drvinfo, | ||
426 | .get_link = ethtool_op_get_link, | ||
427 | .get_msglevel = usbnet_get_msglevel, | ||
428 | .set_msglevel = usbnet_set_msglevel, | ||
429 | .get_wol = ax8817x_get_wol, | ||
430 | .set_wol = ax8817x_set_wol, | ||
431 | .get_eeprom_len = ax8817x_get_eeprom_len, | ||
432 | .get_eeprom = ax8817x_get_eeprom, | ||
433 | .get_settings = ax8817x_get_settings, | ||
434 | .set_settings = ax8817x_set_settings, | ||
435 | }; | ||
436 | |||
437 | static int ax8817x_ioctl (struct net_device *net, struct ifreq *rq, int cmd) | ||
438 | { | ||
439 | struct usbnet *dev = netdev_priv(net); | ||
440 | |||
441 | return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL); | ||
442 | } | ||
443 | |||
444 | static int ax8817x_bind(struct usbnet *dev, struct usb_interface *intf) | ||
445 | { | ||
446 | int ret = 0; | ||
447 | void *buf; | ||
448 | int i; | ||
449 | unsigned long gpio_bits = dev->driver_info->data; | ||
450 | |||
451 | usbnet_get_endpoints(dev,intf); | ||
452 | |||
453 | buf = kmalloc(ETH_ALEN, GFP_KERNEL); | ||
454 | if(!buf) { | ||
455 | ret = -ENOMEM; | ||
456 | goto out1; | ||
457 | } | ||
458 | |||
459 | /* Toggle the GPIOs in a manufacturer/model specific way */ | ||
460 | for (i = 2; i >= 0; i--) { | ||
461 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS, | ||
462 | (gpio_bits >> (i * 8)) & 0xff, 0, 0, | ||
463 | buf)) < 0) | ||
464 | goto out2; | ||
465 | msleep(5); | ||
466 | } | ||
467 | |||
468 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, | ||
469 | 0x80, 0, 0, buf)) < 0) { | ||
470 | dbg("send AX_CMD_WRITE_RX_CTL failed: %d", ret); | ||
471 | goto out2; | ||
472 | } | ||
473 | |||
474 | /* Get the MAC address */ | ||
475 | memset(buf, 0, ETH_ALEN); | ||
476 | if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_NODE_ID, | ||
477 | 0, 0, 6, buf)) < 0) { | ||
478 | dbg("read AX_CMD_READ_NODE_ID failed: %d", ret); | ||
479 | goto out2; | ||
480 | } | ||
481 | memcpy(dev->net->dev_addr, buf, ETH_ALEN); | ||
482 | |||
483 | /* Get the PHY id */ | ||
484 | if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, | ||
485 | 0, 0, 2, buf)) < 0) { | ||
486 | dbg("error on read AX_CMD_READ_PHY_ID: %02x", ret); | ||
487 | goto out2; | ||
488 | } else if (ret < 2) { | ||
489 | /* this should always return 2 bytes */ | ||
490 | dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x", | ||
491 | ret); | ||
492 | ret = -EIO; | ||
493 | goto out2; | ||
494 | } | ||
495 | |||
496 | /* Initialize MII structure */ | ||
497 | dev->mii.dev = dev->net; | ||
498 | dev->mii.mdio_read = ax8817x_mdio_read; | ||
499 | dev->mii.mdio_write = ax8817x_mdio_write; | ||
500 | dev->mii.phy_id_mask = 0x3f; | ||
501 | dev->mii.reg_num_mask = 0x1f; | ||
502 | dev->mii.phy_id = *((u8 *)buf + 1); | ||
503 | dev->net->do_ioctl = ax8817x_ioctl; | ||
504 | |||
505 | dev->net->set_multicast_list = ax8817x_set_multicast; | ||
506 | dev->net->ethtool_ops = &ax8817x_ethtool_ops; | ||
507 | |||
508 | ax8817x_mdio_write_le(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); | ||
509 | ax8817x_mdio_write_le(dev->net, dev->mii.phy_id, MII_ADVERTISE, | ||
510 | ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP); | ||
511 | mii_nway_restart(&dev->mii); | ||
512 | |||
513 | return 0; | ||
514 | out2: | ||
515 | kfree(buf); | ||
516 | out1: | ||
517 | return ret; | ||
518 | } | ||
519 | |||
520 | static struct ethtool_ops ax88772_ethtool_ops = { | ||
521 | .get_drvinfo = ax8817x_get_drvinfo, | ||
522 | .get_link = ethtool_op_get_link, | ||
523 | .get_msglevel = usbnet_get_msglevel, | ||
524 | .set_msglevel = usbnet_set_msglevel, | ||
525 | .get_wol = ax8817x_get_wol, | ||
526 | .set_wol = ax8817x_set_wol, | ||
527 | .get_eeprom_len = ax8817x_get_eeprom_len, | ||
528 | .get_eeprom = ax8817x_get_eeprom, | ||
529 | .get_settings = ax8817x_get_settings, | ||
530 | .set_settings = ax8817x_set_settings, | ||
531 | }; | ||
532 | |||
533 | static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf) | ||
534 | { | ||
535 | int ret; | ||
536 | void *buf; | ||
537 | |||
538 | usbnet_get_endpoints(dev,intf); | ||
539 | |||
540 | buf = kmalloc(6, GFP_KERNEL); | ||
541 | if(!buf) { | ||
542 | dbg ("Cannot allocate memory for buffer"); | ||
543 | ret = -ENOMEM; | ||
544 | goto out1; | ||
545 | } | ||
546 | |||
547 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS, | ||
548 | 0x00B0, 0, 0, buf)) < 0) | ||
549 | goto out2; | ||
550 | |||
551 | msleep(5); | ||
552 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_PHY_SELECT, | ||
553 | 0x0001, 0, 0, buf)) < 0) { | ||
554 | dbg("Select PHY #1 failed: %d", ret); | ||
555 | goto out2; | ||
556 | } | ||
557 | |||
558 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPPD, | ||
559 | 0, 0, buf)) < 0) { | ||
560 | dbg("Failed to power down internal PHY: %d", ret); | ||
561 | goto out2; | ||
562 | } | ||
563 | |||
564 | msleep(150); | ||
565 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_CLEAR, | ||
566 | 0, 0, buf)) < 0) { | ||
567 | dbg("Failed to perform software reset: %d", ret); | ||
568 | goto out2; | ||
569 | } | ||
570 | |||
571 | msleep(150); | ||
572 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, | ||
573 | AX_SWRESET_IPRL | AX_SWRESET_PRL, | ||
574 | 0, 0, buf)) < 0) { | ||
575 | dbg("Failed to set Internal/External PHY reset control: %d", | ||
576 | ret); | ||
577 | goto out2; | ||
578 | } | ||
579 | |||
580 | msleep(150); | ||
581 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, | ||
582 | 0x0000, 0, 0, buf)) < 0) { | ||
583 | dbg("Failed to reset RX_CTL: %d", ret); | ||
584 | goto out2; | ||
585 | } | ||
586 | |||
587 | /* Get the MAC address */ | ||
588 | memset(buf, 0, ETH_ALEN); | ||
589 | if ((ret = ax8817x_read_cmd(dev, AX88772_CMD_READ_NODE_ID, | ||
590 | 0, 0, ETH_ALEN, buf)) < 0) { | ||
591 | dbg("Failed to read MAC address: %d", ret); | ||
592 | goto out2; | ||
593 | } | ||
594 | memcpy(dev->net->dev_addr, buf, ETH_ALEN); | ||
595 | |||
596 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, | ||
597 | 0, 0, 0, buf)) < 0) { | ||
598 | dbg("Enabling software MII failed: %d", ret); | ||
599 | goto out2; | ||
600 | } | ||
601 | |||
602 | if (((ret = ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, | ||
603 | 0x0010, 2, 2, buf)) < 0) | ||
604 | || (*((u16 *)buf) != 0x003b)) { | ||
605 | dbg("Read PHY register 2 must be 0x3b00: %d", ret); | ||
606 | goto out2; | ||
607 | } | ||
608 | |||
609 | /* Initialize MII structure */ | ||
610 | dev->mii.dev = dev->net; | ||
611 | dev->mii.mdio_read = ax8817x_mdio_read; | ||
612 | dev->mii.mdio_write = ax8817x_mdio_write; | ||
613 | dev->mii.phy_id_mask = 0xff; | ||
614 | dev->mii.reg_num_mask = 0xff; | ||
615 | dev->net->do_ioctl = ax8817x_ioctl; | ||
616 | |||
617 | /* Get the PHY id */ | ||
618 | if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, | ||
619 | 0, 0, 2, buf)) < 0) { | ||
620 | dbg("Error reading PHY ID: %02x", ret); | ||
621 | goto out2; | ||
622 | } else if (ret < 2) { | ||
623 | /* this should always return 2 bytes */ | ||
624 | dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x", | ||
625 | ret); | ||
626 | ret = -EIO; | ||
627 | goto out2; | ||
628 | } | ||
629 | dev->mii.phy_id = *((u8 *)buf + 1); | ||
630 | |||
631 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_PRL, | ||
632 | 0, 0, buf)) < 0) { | ||
633 | dbg("Set external PHY reset pin level: %d", ret); | ||
634 | goto out2; | ||
635 | } | ||
636 | msleep(150); | ||
637 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, | ||
638 | AX_SWRESET_IPRL | AX_SWRESET_PRL, | ||
639 | 0, 0, buf)) < 0) { | ||
640 | dbg("Set Internal/External PHY reset control: %d", ret); | ||
641 | goto out2; | ||
642 | } | ||
643 | msleep(150); | ||
644 | |||
645 | |||
646 | dev->net->set_multicast_list = ax8817x_set_multicast; | ||
647 | dev->net->ethtool_ops = &ax88772_ethtool_ops; | ||
648 | |||
649 | ax8817x_mdio_write_le(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); | ||
650 | ax8817x_mdio_write_le(dev->net, dev->mii.phy_id, MII_ADVERTISE, | ||
651 | ADVERTISE_ALL | ADVERTISE_CSMA); | ||
652 | mii_nway_restart(&dev->mii); | ||
653 | |||
654 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, | ||
655 | AX88772_MEDIUM_DEFAULT, 0, 0, buf)) < 0) { | ||
656 | dbg("Write medium mode register: %d", ret); | ||
657 | goto out2; | ||
658 | } | ||
659 | |||
660 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_IPG0, | ||
661 | AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT, | ||
662 | AX88772_IPG2_DEFAULT, 0, buf)) < 0) { | ||
663 | dbg("Write IPG,IPG1,IPG2 failed: %d", ret); | ||
664 | goto out2; | ||
665 | } | ||
666 | if ((ret = | ||
667 | ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf)) < 0) { | ||
668 | dbg("Failed to set hardware MII: %02x", ret); | ||
669 | goto out2; | ||
670 | } | ||
671 | |||
672 | /* Set RX_CTL to default values with 2k buffer, and enable cactus */ | ||
673 | if ((ret = | ||
674 | ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x0088, 0, 0, | ||
675 | buf)) < 0) { | ||
676 | dbg("Reset RX_CTL failed: %d", ret); | ||
677 | goto out2; | ||
678 | } | ||
679 | |||
680 | kfree(buf); | ||
681 | |||
682 | /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */ | ||
683 | if (dev->driver_info->flags & FLAG_FRAMING_AX) { | ||
684 | /* hard_mtu is still the default - the device does not support | ||
685 | jumbo eth frames */ | ||
686 | dev->rx_urb_size = 2048; | ||
687 | } | ||
688 | |||
689 | return 0; | ||
690 | |||
691 | out2: | ||
692 | kfree(buf); | ||
693 | out1: | ||
694 | return ret; | ||
695 | } | ||
696 | |||
697 | static int ax88772_rx_fixup(struct usbnet *dev, struct sk_buff *skb) | ||
698 | { | ||
699 | u8 *head; | ||
700 | u32 header; | ||
701 | char *packet; | ||
702 | struct sk_buff *ax_skb; | ||
703 | u16 size; | ||
704 | |||
705 | head = (u8 *) skb->data; | ||
706 | memcpy(&header, head, sizeof(header)); | ||
707 | le32_to_cpus(&header); | ||
708 | packet = head + sizeof(header); | ||
709 | |||
710 | skb_pull(skb, 4); | ||
711 | |||
712 | while (skb->len > 0) { | ||
713 | if ((short)(header & 0x0000ffff) != | ||
714 | ~((short)((header & 0xffff0000) >> 16))) { | ||
715 | devdbg(dev,"header length data is error"); | ||
716 | } | ||
717 | /* get the packet length */ | ||
718 | size = (u16) (header & 0x0000ffff); | ||
719 | |||
720 | if ((skb->len) - ((size + 1) & 0xfffe) == 0) | ||
721 | return 2; | ||
722 | if (size > ETH_FRAME_LEN) { | ||
723 | devdbg(dev,"invalid rx length %d", size); | ||
724 | return 0; | ||
725 | } | ||
726 | ax_skb = skb_clone(skb, GFP_ATOMIC); | ||
727 | if (ax_skb) { | ||
728 | ax_skb->len = size; | ||
729 | ax_skb->data = packet; | ||
730 | ax_skb->tail = packet + size; | ||
731 | usbnet_skb_return(dev, ax_skb); | ||
732 | } else { | ||
733 | return 0; | ||
734 | } | ||
735 | |||
736 | skb_pull(skb, (size + 1) & 0xfffe); | ||
737 | |||
738 | if (skb->len == 0) | ||
739 | break; | ||
740 | |||
741 | head = (u8 *) skb->data; | ||
742 | memcpy(&header, head, sizeof(header)); | ||
743 | le32_to_cpus(&header); | ||
744 | packet = head + sizeof(header); | ||
745 | skb_pull(skb, 4); | ||
746 | } | ||
747 | |||
748 | if (skb->len < 0) { | ||
749 | devdbg(dev,"invalid rx length %d", skb->len); | ||
750 | return 0; | ||
751 | } | ||
752 | return 1; | ||
753 | } | ||
754 | |||
755 | static struct sk_buff *ax88772_tx_fixup(struct usbnet *dev, struct sk_buff *skb, | ||
756 | unsigned flags) | ||
757 | { | ||
758 | int padlen; | ||
759 | int headroom = skb_headroom(skb); | ||
760 | int tailroom = skb_tailroom(skb); | ||
761 | u32 packet_len; | ||
762 | u32 padbytes = 0xffff0000; | ||
763 | |||
764 | padlen = ((skb->len + 4) % 512) ? 0 : 4; | ||
765 | |||
766 | if ((!skb_cloned(skb)) | ||
767 | && ((headroom + tailroom) >= (4 + padlen))) { | ||
768 | if ((headroom < 4) || (tailroom < padlen)) { | ||
769 | skb->data = memmove(skb->head + 4, skb->data, skb->len); | ||
770 | skb->tail = skb->data + skb->len; | ||
771 | } | ||
772 | } else { | ||
773 | struct sk_buff *skb2; | ||
774 | skb2 = skb_copy_expand(skb, 4, padlen, flags); | ||
775 | dev_kfree_skb_any(skb); | ||
776 | skb = skb2; | ||
777 | if (!skb) | ||
778 | return NULL; | ||
779 | } | ||
780 | |||
781 | skb_push(skb, 4); | ||
782 | packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4); | ||
783 | memcpy(skb->data, &packet_len, sizeof(packet_len)); | ||
784 | |||
785 | if ((skb->len % 512) == 0) { | ||
786 | memcpy( skb->tail, &padbytes, sizeof(padbytes)); | ||
787 | skb_put(skb, sizeof(padbytes)); | ||
788 | } | ||
789 | return skb; | ||
790 | } | ||
791 | |||
792 | static int ax88772_link_reset(struct usbnet *dev) | ||
793 | { | ||
794 | u16 lpa; | ||
795 | u16 adv; | ||
796 | u16 res; | ||
797 | u16 mode; | ||
798 | |||
799 | mode = AX88772_MEDIUM_DEFAULT; | ||
800 | lpa = ax8817x_mdio_read_le(dev->net, dev->mii.phy_id, MII_LPA); | ||
801 | adv = ax8817x_mdio_read_le(dev->net, dev->mii.phy_id, MII_ADVERTISE); | ||
802 | res = mii_nway_result(lpa|adv); | ||
803 | |||
804 | if ((res & LPA_DUPLEX) == 0) | ||
805 | mode &= ~AX88772_MEDIUM_FULL_DUPLEX; | ||
806 | if ((res & LPA_100) == 0) | ||
807 | mode &= ~AX88772_MEDIUM_100MB; | ||
808 | ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL); | ||
809 | |||
810 | return 0; | ||
811 | } | ||
812 | |||
813 | static const struct driver_info ax8817x_info = { | ||
814 | .description = "ASIX AX8817x USB 2.0 Ethernet", | ||
815 | .bind = ax8817x_bind, | ||
816 | .status = ax8817x_status, | ||
817 | .link_reset = ax88172_link_reset, | ||
818 | .reset = ax88172_link_reset, | ||
819 | .flags = FLAG_ETHER, | ||
820 | .data = 0x00130103, | ||
821 | }; | ||
822 | |||
823 | static const struct driver_info dlink_dub_e100_info = { | ||
824 | .description = "DLink DUB-E100 USB Ethernet", | ||
825 | .bind = ax8817x_bind, | ||
826 | .status = ax8817x_status, | ||
827 | .link_reset = ax88172_link_reset, | ||
828 | .reset = ax88172_link_reset, | ||
829 | .flags = FLAG_ETHER, | ||
830 | .data = 0x009f9d9f, | ||
831 | }; | ||
832 | |||
833 | static const struct driver_info netgear_fa120_info = { | ||
834 | .description = "Netgear FA-120 USB Ethernet", | ||
835 | .bind = ax8817x_bind, | ||
836 | .status = ax8817x_status, | ||
837 | .link_reset = ax88172_link_reset, | ||
838 | .reset = ax88172_link_reset, | ||
839 | .flags = FLAG_ETHER, | ||
840 | .data = 0x00130103, | ||
841 | }; | ||
842 | |||
843 | static const struct driver_info hawking_uf200_info = { | ||
844 | .description = "Hawking UF200 USB Ethernet", | ||
845 | .bind = ax8817x_bind, | ||
846 | .status = ax8817x_status, | ||
847 | .link_reset = ax88172_link_reset, | ||
848 | .reset = ax88172_link_reset, | ||
849 | .flags = FLAG_ETHER, | ||
850 | .data = 0x001f1d1f, | ||
851 | }; | ||
852 | |||
853 | static const struct driver_info ax88772_info = { | ||
854 | .description = "ASIX AX88772 USB 2.0 Ethernet", | ||
855 | .bind = ax88772_bind, | ||
856 | .status = ax8817x_status, | ||
857 | .link_reset = ax88772_link_reset, | ||
858 | .reset = ax88772_link_reset, | ||
859 | .flags = FLAG_ETHER | FLAG_FRAMING_AX, | ||
860 | .rx_fixup = ax88772_rx_fixup, | ||
861 | .tx_fixup = ax88772_tx_fixup, | ||
862 | .data = 0x00130103, | ||
863 | }; | ||
864 | |||
865 | static const struct usb_device_id products [] = { | ||
866 | { | ||
867 | // Linksys USB200M | ||
868 | USB_DEVICE (0x077b, 0x2226), | ||
869 | .driver_info = (unsigned long) &ax8817x_info, | ||
870 | }, { | ||
871 | // Netgear FA120 | ||
872 | USB_DEVICE (0x0846, 0x1040), | ||
873 | .driver_info = (unsigned long) &netgear_fa120_info, | ||
874 | }, { | ||
875 | // DLink DUB-E100 | ||
876 | USB_DEVICE (0x2001, 0x1a00), | ||
877 | .driver_info = (unsigned long) &dlink_dub_e100_info, | ||
878 | }, { | ||
879 | // Intellinet, ST Lab USB Ethernet | ||
880 | USB_DEVICE (0x0b95, 0x1720), | ||
881 | .driver_info = (unsigned long) &ax8817x_info, | ||
882 | }, { | ||
883 | // Hawking UF200, TrendNet TU2-ET100 | ||
884 | USB_DEVICE (0x07b8, 0x420a), | ||
885 | .driver_info = (unsigned long) &hawking_uf200_info, | ||
886 | }, { | ||
887 | // Billionton Systems, USB2AR | ||
888 | USB_DEVICE (0x08dd, 0x90ff), | ||
889 | .driver_info = (unsigned long) &ax8817x_info, | ||
890 | }, { | ||
891 | // ATEN UC210T | ||
892 | USB_DEVICE (0x0557, 0x2009), | ||
893 | .driver_info = (unsigned long) &ax8817x_info, | ||
894 | }, { | ||
895 | // Buffalo LUA-U2-KTX | ||
896 | USB_DEVICE (0x0411, 0x003d), | ||
897 | .driver_info = (unsigned long) &ax8817x_info, | ||
898 | }, { | ||
899 | // Sitecom LN-029 "USB 2.0 10/100 Ethernet adapter" | ||
900 | USB_DEVICE (0x6189, 0x182d), | ||
901 | .driver_info = (unsigned long) &ax8817x_info, | ||
902 | }, { | ||
903 | // corega FEther USB2-TX | ||
904 | USB_DEVICE (0x07aa, 0x0017), | ||
905 | .driver_info = (unsigned long) &ax8817x_info, | ||
906 | }, { | ||
907 | // Surecom EP-1427X-2 | ||
908 | USB_DEVICE (0x1189, 0x0893), | ||
909 | .driver_info = (unsigned long) &ax8817x_info, | ||
910 | }, { | ||
911 | // goodway corp usb gwusb2e | ||
912 | USB_DEVICE (0x1631, 0x6200), | ||
913 | .driver_info = (unsigned long) &ax8817x_info, | ||
914 | }, { | ||
915 | // ASIX AX88772 10/100 | ||
916 | USB_DEVICE (0x0b95, 0x7720), | ||
917 | .driver_info = (unsigned long) &ax88772_info, | ||
918 | }, | ||
919 | { }, // END | ||
920 | }; | ||
921 | MODULE_DEVICE_TABLE(usb, products); | ||
922 | |||
923 | static struct usb_driver asix_driver = { | ||
924 | .owner = THIS_MODULE, | ||
925 | .name = "asix", | ||
926 | .id_table = products, | ||
927 | .probe = usbnet_probe, | ||
928 | .suspend = usbnet_suspend, | ||
929 | .resume = usbnet_resume, | ||
930 | .disconnect = usbnet_disconnect, | ||
931 | }; | ||
932 | |||
933 | static int __init asix_init(void) | ||
934 | { | ||
935 | return usb_register(&asix_driver); | ||
936 | } | ||
937 | module_init(asix_init); | ||
938 | |||
939 | static void __exit asix_exit(void) | ||
940 | { | ||
941 | usb_deregister(&asix_driver); | ||
942 | } | ||
943 | module_exit(asix_exit); | ||
944 | |||
945 | MODULE_AUTHOR("David Hollis"); | ||
946 | MODULE_DESCRIPTION("ASIX AX8817X based USB 2.0 Ethernet Devices"); | ||
947 | MODULE_LICENSE("GPL"); | ||
948 | |||
diff --git a/drivers/usb/net/catc.c b/drivers/usb/net/catc.c index c8be912f24e1..37ef365a2472 100644 --- a/drivers/usb/net/catc.c +++ b/drivers/usb/net/catc.c | |||
@@ -383,7 +383,6 @@ static void catc_tx_done(struct urb *urb, struct pt_regs *regs) | |||
383 | 383 | ||
384 | if (urb->status == -ECONNRESET) { | 384 | if (urb->status == -ECONNRESET) { |
385 | dbg("Tx Reset."); | 385 | dbg("Tx Reset."); |
386 | urb->transfer_flags &= ~URB_ASYNC_UNLINK; | ||
387 | urb->status = 0; | 386 | urb->status = 0; |
388 | catc->netdev->trans_start = jiffies; | 387 | catc->netdev->trans_start = jiffies; |
389 | catc->stats.tx_errors++; | 388 | catc->stats.tx_errors++; |
@@ -445,7 +444,6 @@ static void catc_tx_timeout(struct net_device *netdev) | |||
445 | struct catc *catc = netdev_priv(netdev); | 444 | struct catc *catc = netdev_priv(netdev); |
446 | 445 | ||
447 | warn("Transmit timed out."); | 446 | warn("Transmit timed out."); |
448 | catc->tx_urb->transfer_flags |= URB_ASYNC_UNLINK; | ||
449 | usb_unlink_urb(catc->tx_urb); | 447 | usb_unlink_urb(catc->tx_urb); |
450 | } | 448 | } |
451 | 449 | ||
diff --git a/drivers/usb/net/cdc_ether.c b/drivers/usb/net/cdc_ether.c new file mode 100644 index 000000000000..652b04bbf6af --- /dev/null +++ b/drivers/usb/net/cdc_ether.c | |||
@@ -0,0 +1,509 @@ | |||
1 | /* | ||
2 | * CDC Ethernet based networking peripherals | ||
3 | * Copyright (C) 2003-2005 by David Brownell | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | // #define DEBUG // error path messages, extra info | ||
21 | // #define VERBOSE // more; success messages | ||
22 | |||
23 | #include <linux/config.h> | ||
24 | #ifdef CONFIG_USB_DEBUG | ||
25 | # define DEBUG | ||
26 | #endif | ||
27 | #include <linux/module.h> | ||
28 | #include <linux/sched.h> | ||
29 | #include <linux/init.h> | ||
30 | #include <linux/netdevice.h> | ||
31 | #include <linux/etherdevice.h> | ||
32 | #include <linux/ctype.h> | ||
33 | #include <linux/ethtool.h> | ||
34 | #include <linux/workqueue.h> | ||
35 | #include <linux/mii.h> | ||
36 | #include <linux/usb.h> | ||
37 | #include <linux/usb_cdc.h> | ||
38 | |||
39 | #include "usbnet.h" | ||
40 | |||
41 | |||
42 | /* | ||
43 | * probes control interface, claims data interface, collects the bulk | ||
44 | * endpoints, activates data interface (if needed), maybe sets MTU. | ||
45 | * all pure cdc, except for certain firmware workarounds, and knowing | ||
46 | * that rndis uses one different rule. | ||
47 | */ | ||
48 | int usbnet_generic_cdc_bind(struct usbnet *dev, struct usb_interface *intf) | ||
49 | { | ||
50 | u8 *buf = intf->cur_altsetting->extra; | ||
51 | int len = intf->cur_altsetting->extralen; | ||
52 | struct usb_interface_descriptor *d; | ||
53 | struct cdc_state *info = (void *) &dev->data; | ||
54 | int status; | ||
55 | int rndis; | ||
56 | struct usb_driver *driver = driver_of(intf); | ||
57 | |||
58 | if (sizeof dev->data < sizeof *info) | ||
59 | return -EDOM; | ||
60 | |||
61 | /* expect strict spec conformance for the descriptors, but | ||
62 | * cope with firmware which stores them in the wrong place | ||
63 | */ | ||
64 | if (len == 0 && dev->udev->actconfig->extralen) { | ||
65 | /* Motorola SB4100 (and others: Brad Hards says it's | ||
66 | * from a Broadcom design) put CDC descriptors here | ||
67 | */ | ||
68 | buf = dev->udev->actconfig->extra; | ||
69 | len = dev->udev->actconfig->extralen; | ||
70 | if (len) | ||
71 | dev_dbg(&intf->dev, | ||
72 | "CDC descriptors on config\n"); | ||
73 | } | ||
74 | |||
75 | /* this assumes that if there's a non-RNDIS vendor variant | ||
76 | * of cdc-acm, it'll fail RNDIS requests cleanly. | ||
77 | */ | ||
78 | rndis = (intf->cur_altsetting->desc.bInterfaceProtocol == 0xff); | ||
79 | |||
80 | memset(info, 0, sizeof *info); | ||
81 | info->control = intf; | ||
82 | while (len > 3) { | ||
83 | if (buf [1] != USB_DT_CS_INTERFACE) | ||
84 | goto next_desc; | ||
85 | |||
86 | /* use bDescriptorSubType to identify the CDC descriptors. | ||
87 | * We expect devices with CDC header and union descriptors. | ||
88 | * For CDC Ethernet we need the ethernet descriptor. | ||
89 | * For RNDIS, ignore two (pointless) CDC modem descriptors | ||
90 | * in favor of a complicated OID-based RPC scheme doing what | ||
91 | * CDC Ethernet achieves with a simple descriptor. | ||
92 | */ | ||
93 | switch (buf [2]) { | ||
94 | case USB_CDC_HEADER_TYPE: | ||
95 | if (info->header) { | ||
96 | dev_dbg(&intf->dev, "extra CDC header\n"); | ||
97 | goto bad_desc; | ||
98 | } | ||
99 | info->header = (void *) buf; | ||
100 | if (info->header->bLength != sizeof *info->header) { | ||
101 | dev_dbg(&intf->dev, "CDC header len %u\n", | ||
102 | info->header->bLength); | ||
103 | goto bad_desc; | ||
104 | } | ||
105 | break; | ||
106 | case USB_CDC_UNION_TYPE: | ||
107 | if (info->u) { | ||
108 | dev_dbg(&intf->dev, "extra CDC union\n"); | ||
109 | goto bad_desc; | ||
110 | } | ||
111 | info->u = (void *) buf; | ||
112 | if (info->u->bLength != sizeof *info->u) { | ||
113 | dev_dbg(&intf->dev, "CDC union len %u\n", | ||
114 | info->u->bLength); | ||
115 | goto bad_desc; | ||
116 | } | ||
117 | |||
118 | /* we need a master/control interface (what we're | ||
119 | * probed with) and a slave/data interface; union | ||
120 | * descriptors sort this all out. | ||
121 | */ | ||
122 | info->control = usb_ifnum_to_if(dev->udev, | ||
123 | info->u->bMasterInterface0); | ||
124 | info->data = usb_ifnum_to_if(dev->udev, | ||
125 | info->u->bSlaveInterface0); | ||
126 | if (!info->control || !info->data) { | ||
127 | dev_dbg(&intf->dev, | ||
128 | "master #%u/%p slave #%u/%p\n", | ||
129 | info->u->bMasterInterface0, | ||
130 | info->control, | ||
131 | info->u->bSlaveInterface0, | ||
132 | info->data); | ||
133 | goto bad_desc; | ||
134 | } | ||
135 | if (info->control != intf) { | ||
136 | dev_dbg(&intf->dev, "bogus CDC Union\n"); | ||
137 | /* Ambit USB Cable Modem (and maybe others) | ||
138 | * interchanges master and slave interface. | ||
139 | */ | ||
140 | if (info->data == intf) { | ||
141 | info->data = info->control; | ||
142 | info->control = intf; | ||
143 | } else | ||
144 | goto bad_desc; | ||
145 | } | ||
146 | |||
147 | /* a data interface altsetting does the real i/o */ | ||
148 | d = &info->data->cur_altsetting->desc; | ||
149 | if (d->bInterfaceClass != USB_CLASS_CDC_DATA) { | ||
150 | dev_dbg(&intf->dev, "slave class %u\n", | ||
151 | d->bInterfaceClass); | ||
152 | goto bad_desc; | ||
153 | } | ||
154 | break; | ||
155 | case USB_CDC_ETHERNET_TYPE: | ||
156 | if (info->ether) { | ||
157 | dev_dbg(&intf->dev, "extra CDC ether\n"); | ||
158 | goto bad_desc; | ||
159 | } | ||
160 | info->ether = (void *) buf; | ||
161 | if (info->ether->bLength != sizeof *info->ether) { | ||
162 | dev_dbg(&intf->dev, "CDC ether len %u\n", | ||
163 | info->ether->bLength); | ||
164 | goto bad_desc; | ||
165 | } | ||
166 | dev->hard_mtu = le16_to_cpu( | ||
167 | info->ether->wMaxSegmentSize); | ||
168 | /* because of Zaurus, we may be ignoring the host | ||
169 | * side link address we were given. | ||
170 | */ | ||
171 | break; | ||
172 | } | ||
173 | next_desc: | ||
174 | len -= buf [0]; /* bLength */ | ||
175 | buf += buf [0]; | ||
176 | } | ||
177 | |||
178 | if (!info->header || !info->u || (!rndis && !info->ether)) { | ||
179 | dev_dbg(&intf->dev, "missing cdc %s%s%sdescriptor\n", | ||
180 | info->header ? "" : "header ", | ||
181 | info->u ? "" : "union ", | ||
182 | info->ether ? "" : "ether "); | ||
183 | goto bad_desc; | ||
184 | } | ||
185 | |||
186 | /* claim data interface and set it up ... with side effects. | ||
187 | * network traffic can't flow until an altsetting is enabled. | ||
188 | */ | ||
189 | status = usb_driver_claim_interface(driver, info->data, dev); | ||
190 | if (status < 0) | ||
191 | return status; | ||
192 | status = usbnet_get_endpoints(dev, info->data); | ||
193 | if (status < 0) { | ||
194 | /* ensure immediate exit from usbnet_disconnect */ | ||
195 | usb_set_intfdata(info->data, NULL); | ||
196 | usb_driver_release_interface(driver, info->data); | ||
197 | return status; | ||
198 | } | ||
199 | |||
200 | /* status endpoint: optional for CDC Ethernet, not RNDIS (or ACM) */ | ||
201 | dev->status = NULL; | ||
202 | if (info->control->cur_altsetting->desc.bNumEndpoints == 1) { | ||
203 | struct usb_endpoint_descriptor *desc; | ||
204 | |||
205 | dev->status = &info->control->cur_altsetting->endpoint [0]; | ||
206 | desc = &dev->status->desc; | ||
207 | if (desc->bmAttributes != USB_ENDPOINT_XFER_INT | ||
208 | || !(desc->bEndpointAddress & USB_DIR_IN) | ||
209 | || (le16_to_cpu(desc->wMaxPacketSize) | ||
210 | < sizeof(struct usb_cdc_notification)) | ||
211 | || !desc->bInterval) { | ||
212 | dev_dbg(&intf->dev, "bad notification endpoint\n"); | ||
213 | dev->status = NULL; | ||
214 | } | ||
215 | } | ||
216 | if (rndis && !dev->status) { | ||
217 | dev_dbg(&intf->dev, "missing RNDIS status endpoint\n"); | ||
218 | usb_set_intfdata(info->data, NULL); | ||
219 | usb_driver_release_interface(driver, info->data); | ||
220 | return -ENODEV; | ||
221 | } | ||
222 | return 0; | ||
223 | |||
224 | bad_desc: | ||
225 | dev_info(&dev->udev->dev, "bad CDC descriptors\n"); | ||
226 | return -ENODEV; | ||
227 | } | ||
228 | EXPORT_SYMBOL_GPL(usbnet_generic_cdc_bind); | ||
229 | |||
230 | void usbnet_cdc_unbind(struct usbnet *dev, struct usb_interface *intf) | ||
231 | { | ||
232 | struct cdc_state *info = (void *) &dev->data; | ||
233 | struct usb_driver *driver = driver_of(intf); | ||
234 | |||
235 | /* disconnect master --> disconnect slave */ | ||
236 | if (intf == info->control && info->data) { | ||
237 | /* ensure immediate exit from usbnet_disconnect */ | ||
238 | usb_set_intfdata(info->data, NULL); | ||
239 | usb_driver_release_interface(driver, info->data); | ||
240 | info->data = NULL; | ||
241 | } | ||
242 | |||
243 | /* and vice versa (just in case) */ | ||
244 | else if (intf == info->data && info->control) { | ||
245 | /* ensure immediate exit from usbnet_disconnect */ | ||
246 | usb_set_intfdata(info->control, NULL); | ||
247 | usb_driver_release_interface(driver, info->control); | ||
248 | info->control = NULL; | ||
249 | } | ||
250 | } | ||
251 | EXPORT_SYMBOL_GPL(usbnet_cdc_unbind); | ||
252 | |||
253 | |||
254 | /*------------------------------------------------------------------------- | ||
255 | * | ||
256 | * Communications Device Class, Ethernet Control model | ||
257 | * | ||
258 | * Takes two interfaces. The DATA interface is inactive till an altsetting | ||
259 | * is selected. Configuration data includes class descriptors. There's | ||
260 | * an optional status endpoint on the control interface. | ||
261 | * | ||
262 | * This should interop with whatever the 2.4 "CDCEther.c" driver | ||
263 | * (by Brad Hards) talked with, with more functionality. | ||
264 | * | ||
265 | *-------------------------------------------------------------------------*/ | ||
266 | |||
267 | static void dumpspeed(struct usbnet *dev, __le32 *speeds) | ||
268 | { | ||
269 | if (netif_msg_timer(dev)) | ||
270 | devinfo(dev, "link speeds: %u kbps up, %u kbps down", | ||
271 | __le32_to_cpu(speeds[0]) / 1000, | ||
272 | __le32_to_cpu(speeds[1]) / 1000); | ||
273 | } | ||
274 | |||
275 | static void cdc_status(struct usbnet *dev, struct urb *urb) | ||
276 | { | ||
277 | struct usb_cdc_notification *event; | ||
278 | |||
279 | if (urb->actual_length < sizeof *event) | ||
280 | return; | ||
281 | |||
282 | /* SPEED_CHANGE can get split into two 8-byte packets */ | ||
283 | if (test_and_clear_bit(EVENT_STS_SPLIT, &dev->flags)) { | ||
284 | dumpspeed(dev, (__le32 *) urb->transfer_buffer); | ||
285 | return; | ||
286 | } | ||
287 | |||
288 | event = urb->transfer_buffer; | ||
289 | switch (event->bNotificationType) { | ||
290 | case USB_CDC_NOTIFY_NETWORK_CONNECTION: | ||
291 | if (netif_msg_timer(dev)) | ||
292 | devdbg(dev, "CDC: carrier %s", | ||
293 | event->wValue ? "on" : "off"); | ||
294 | if (event->wValue) | ||
295 | netif_carrier_on(dev->net); | ||
296 | else | ||
297 | netif_carrier_off(dev->net); | ||
298 | break; | ||
299 | case USB_CDC_NOTIFY_SPEED_CHANGE: /* tx/rx rates */ | ||
300 | if (netif_msg_timer(dev)) | ||
301 | devdbg(dev, "CDC: speed change (len %d)", | ||
302 | urb->actual_length); | ||
303 | if (urb->actual_length != (sizeof *event + 8)) | ||
304 | set_bit(EVENT_STS_SPLIT, &dev->flags); | ||
305 | else | ||
306 | dumpspeed(dev, (__le32 *) &event[1]); | ||
307 | break; | ||
308 | /* USB_CDC_NOTIFY_RESPONSE_AVAILABLE can happen too (e.g. RNDIS), | ||
309 | * but there are no standard formats for the response data. | ||
310 | */ | ||
311 | default: | ||
312 | deverr(dev, "CDC: unexpected notification %02x!", | ||
313 | event->bNotificationType); | ||
314 | break; | ||
315 | } | ||
316 | } | ||
317 | |||
318 | static u8 nibble(unsigned char c) | ||
319 | { | ||
320 | if (likely(isdigit(c))) | ||
321 | return c - '0'; | ||
322 | c = toupper(c); | ||
323 | if (likely(isxdigit(c))) | ||
324 | return 10 + c - 'A'; | ||
325 | return 0; | ||
326 | } | ||
327 | |||
328 | static inline int | ||
329 | get_ethernet_addr(struct usbnet *dev, struct usb_cdc_ether_desc *e) | ||
330 | { | ||
331 | int tmp, i; | ||
332 | unsigned char buf [13]; | ||
333 | |||
334 | tmp = usb_string(dev->udev, e->iMACAddress, buf, sizeof buf); | ||
335 | if (tmp != 12) { | ||
336 | dev_dbg(&dev->udev->dev, | ||
337 | "bad MAC string %d fetch, %d\n", e->iMACAddress, tmp); | ||
338 | if (tmp >= 0) | ||
339 | tmp = -EINVAL; | ||
340 | return tmp; | ||
341 | } | ||
342 | for (i = tmp = 0; i < 6; i++, tmp += 2) | ||
343 | dev->net->dev_addr [i] = | ||
344 | (nibble(buf [tmp]) << 4) + nibble(buf [tmp + 1]); | ||
345 | return 0; | ||
346 | } | ||
347 | |||
348 | static int cdc_bind(struct usbnet *dev, struct usb_interface *intf) | ||
349 | { | ||
350 | int status; | ||
351 | struct cdc_state *info = (void *) &dev->data; | ||
352 | |||
353 | status = usbnet_generic_cdc_bind(dev, intf); | ||
354 | if (status < 0) | ||
355 | return status; | ||
356 | |||
357 | status = get_ethernet_addr(dev, info->ether); | ||
358 | if (status < 0) { | ||
359 | usb_set_intfdata(info->data, NULL); | ||
360 | usb_driver_release_interface(driver_of(intf), info->data); | ||
361 | return status; | ||
362 | } | ||
363 | |||
364 | /* FIXME cdc-ether has some multicast code too, though it complains | ||
365 | * in routine cases. info->ether describes the multicast support. | ||
366 | * Implement that here, manipulating the cdc filter as needed. | ||
367 | */ | ||
368 | return 0; | ||
369 | } | ||
370 | |||
371 | static const struct driver_info cdc_info = { | ||
372 | .description = "CDC Ethernet Device", | ||
373 | .flags = FLAG_ETHER, | ||
374 | // .check_connect = cdc_check_connect, | ||
375 | .bind = cdc_bind, | ||
376 | .unbind = usbnet_cdc_unbind, | ||
377 | .status = cdc_status, | ||
378 | }; | ||
379 | |||
380 | /*-------------------------------------------------------------------------*/ | ||
381 | |||
382 | |||
383 | static const struct usb_device_id products [] = { | ||
384 | /* | ||
385 | * BLACKLIST !! | ||
386 | * | ||
387 | * First blacklist any products that are egregiously nonconformant | ||
388 | * with the CDC Ethernet specs. Minor braindamage we cope with; when | ||
389 | * they're not even trying, needing a separate driver is only the first | ||
390 | * of the differences to show up. | ||
391 | */ | ||
392 | |||
393 | #define ZAURUS_MASTER_INTERFACE \ | ||
394 | .bInterfaceClass = USB_CLASS_COMM, \ | ||
395 | .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET, \ | ||
396 | .bInterfaceProtocol = USB_CDC_PROTO_NONE | ||
397 | |||
398 | /* SA-1100 based Sharp Zaurus ("collie"), or compatible; | ||
399 | * wire-incompatible with true CDC Ethernet implementations. | ||
400 | * (And, it seems, needlessly so...) | ||
401 | */ | ||
402 | { | ||
403 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
404 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
405 | .idVendor = 0x04DD, | ||
406 | .idProduct = 0x8004, | ||
407 | ZAURUS_MASTER_INTERFACE, | ||
408 | .driver_info = 0, | ||
409 | }, | ||
410 | |||
411 | /* PXA-25x based Sharp Zaurii. Note that it seems some of these | ||
412 | * (later models especially) may have shipped only with firmware | ||
413 | * advertising false "CDC MDLM" compatibility ... but we're not | ||
414 | * clear which models did that, so for now let's assume the worst. | ||
415 | */ | ||
416 | { | ||
417 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
418 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
419 | .idVendor = 0x04DD, | ||
420 | .idProduct = 0x8005, /* A-300 */ | ||
421 | ZAURUS_MASTER_INTERFACE, | ||
422 | .driver_info = 0, | ||
423 | }, { | ||
424 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
425 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
426 | .idVendor = 0x04DD, | ||
427 | .idProduct = 0x8006, /* B-500/SL-5600 */ | ||
428 | ZAURUS_MASTER_INTERFACE, | ||
429 | .driver_info = 0, | ||
430 | }, { | ||
431 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
432 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
433 | .idVendor = 0x04DD, | ||
434 | .idProduct = 0x8007, /* C-700 */ | ||
435 | ZAURUS_MASTER_INTERFACE, | ||
436 | .driver_info = 0, | ||
437 | }, { | ||
438 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
439 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
440 | .idVendor = 0x04DD, | ||
441 | .idProduct = 0x9031, /* C-750 C-760 */ | ||
442 | ZAURUS_MASTER_INTERFACE, | ||
443 | .driver_info = 0, | ||
444 | }, { | ||
445 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
446 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
447 | .idVendor = 0x04DD, | ||
448 | .idProduct = 0x9032, /* SL-6000 */ | ||
449 | ZAURUS_MASTER_INTERFACE, | ||
450 | .driver_info = 0, | ||
451 | }, { | ||
452 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
453 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
454 | .idVendor = 0x04DD, | ||
455 | /* reported with some C860 units */ | ||
456 | .idProduct = 0x9050, /* C-860 */ | ||
457 | ZAURUS_MASTER_INTERFACE, | ||
458 | .driver_info = 0, | ||
459 | }, | ||
460 | |||
461 | /* | ||
462 | * WHITELIST!!! | ||
463 | * | ||
464 | * CDC Ether uses two interfaces, not necessarily consecutive. | ||
465 | * We match the main interface, ignoring the optional device | ||
466 | * class so we could handle devices that aren't exclusively | ||
467 | * CDC ether. | ||
468 | * | ||
469 | * NOTE: this match must come AFTER entries blacklisting devices | ||
470 | * because of bugs/quirks in a given product (like Zaurus, above). | ||
471 | */ | ||
472 | { | ||
473 | USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ETHERNET, | ||
474 | USB_CDC_PROTO_NONE), | ||
475 | .driver_info = (unsigned long) &cdc_info, | ||
476 | }, | ||
477 | { }, // END | ||
478 | }; | ||
479 | MODULE_DEVICE_TABLE(usb, products); | ||
480 | |||
481 | static struct usb_driver cdc_driver = { | ||
482 | .owner = THIS_MODULE, | ||
483 | .name = "cdc_ether", | ||
484 | .id_table = products, | ||
485 | .probe = usbnet_probe, | ||
486 | .disconnect = usbnet_disconnect, | ||
487 | .suspend = usbnet_suspend, | ||
488 | .resume = usbnet_resume, | ||
489 | }; | ||
490 | |||
491 | |||
492 | static int __init cdc_init(void) | ||
493 | { | ||
494 | BUG_ON((sizeof(((struct usbnet *)0)->data) | ||
495 | < sizeof(struct cdc_state))); | ||
496 | |||
497 | return usb_register(&cdc_driver); | ||
498 | } | ||
499 | module_init(cdc_init); | ||
500 | |||
501 | static void __exit cdc_exit(void) | ||
502 | { | ||
503 | usb_deregister(&cdc_driver); | ||
504 | } | ||
505 | module_exit(cdc_exit); | ||
506 | |||
507 | MODULE_AUTHOR("David Brownell"); | ||
508 | MODULE_DESCRIPTION("USB CDC Ethernet devices"); | ||
509 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/net/cdc_subset.c b/drivers/usb/net/cdc_subset.c new file mode 100644 index 000000000000..f1730b685fd2 --- /dev/null +++ b/drivers/usb/net/cdc_subset.c | |||
@@ -0,0 +1,335 @@ | |||
1 | /* | ||
2 | * Simple "CDC Subset" USB Networking Links | ||
3 | * Copyright (C) 2000-2005 by David Brownell | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | #include <linux/config.h> | ||
21 | #ifdef CONFIG_USB_DEBUG | ||
22 | # define DEBUG | ||
23 | #endif | ||
24 | #include <linux/module.h> | ||
25 | #include <linux/kmod.h> | ||
26 | #include <linux/sched.h> | ||
27 | #include <linux/init.h> | ||
28 | #include <linux/netdevice.h> | ||
29 | #include <linux/etherdevice.h> | ||
30 | #include <linux/ethtool.h> | ||
31 | #include <linux/workqueue.h> | ||
32 | #include <linux/mii.h> | ||
33 | #include <linux/usb.h> | ||
34 | |||
35 | #include "usbnet.h" | ||
36 | |||
37 | |||
38 | /* | ||
39 | * This supports simple USB network links that don't require any special | ||
40 | * framing or hardware control operations. The protocol used here is a | ||
41 | * strict subset of CDC Ethernet, with three basic differences reflecting | ||
42 | * the goal that almost any hardware should run it: | ||
43 | * | ||
44 | * - Minimal runtime control: one interface, no altsettings, and | ||
45 | * no vendor or class specific control requests. If a device is | ||
46 | * configured, it is allowed to exchange packets with the host. | ||
47 | * Fancier models would mean not working on some hardware. | ||
48 | * | ||
49 | * - Minimal manufacturing control: no IEEE "Organizationally | ||
50 | * Unique ID" required, or an EEPROMs to store one. Each host uses | ||
51 | * one random "locally assigned" Ethernet address instead, which can | ||
52 | * of course be overridden using standard tools like "ifconfig". | ||
53 | * (With 2^46 such addresses, same-net collisions are quite rare.) | ||
54 | * | ||
55 | * - There is no additional framing data for USB. Packets are written | ||
56 | * exactly as in CDC Ethernet, starting with an Ethernet header and | ||
57 | * terminated by a short packet. However, the host will never send a | ||
58 | * zero length packet; some systems can't handle those robustly. | ||
59 | * | ||
60 | * Anything that can transmit and receive USB bulk packets can implement | ||
61 | * this protocol. That includes both smart peripherals and quite a lot | ||
62 | * of "host-to-host" USB cables (which embed two devices back-to-back). | ||
63 | * | ||
64 | * Note that although Linux may use many of those host-to-host links | ||
65 | * with this "cdc_subset" framing, that doesn't mean there may not be a | ||
66 | * better approach. Handling the "other end unplugs/replugs" scenario | ||
67 | * well tends to require chip-specific vendor requests. Also, Windows | ||
68 | * peers at the other end of host-to-host cables may expect their own | ||
69 | * framing to be used rather than this "cdc_subset" model. | ||
70 | */ | ||
71 | |||
72 | #if defined(CONFIG_USB_EPSON2888) || defined(CONFIG_USB_ARMLINUX) | ||
73 | /* PDA style devices are always connected if present */ | ||
74 | static int always_connected (struct usbnet *dev) | ||
75 | { | ||
76 | return 0; | ||
77 | } | ||
78 | #endif | ||
79 | |||
80 | #ifdef CONFIG_USB_ALI_M5632 | ||
81 | #define HAVE_HARDWARE | ||
82 | |||
83 | /*------------------------------------------------------------------------- | ||
84 | * | ||
85 | * ALi M5632 driver ... does high speed | ||
86 | * | ||
87 | *-------------------------------------------------------------------------*/ | ||
88 | |||
89 | static const struct driver_info ali_m5632_info = { | ||
90 | .description = "ALi M5632", | ||
91 | }; | ||
92 | |||
93 | |||
94 | #endif | ||
95 | |||
96 | |||
97 | #ifdef CONFIG_USB_AN2720 | ||
98 | #define HAVE_HARDWARE | ||
99 | |||
100 | /*------------------------------------------------------------------------- | ||
101 | * | ||
102 | * AnchorChips 2720 driver ... http://www.cypress.com | ||
103 | * | ||
104 | * This doesn't seem to have a way to detect whether the peer is | ||
105 | * connected, or need any reset handshaking. It's got pretty big | ||
106 | * internal buffers (handles most of a frame's worth of data). | ||
107 | * Chip data sheets don't describe any vendor control messages. | ||
108 | * | ||
109 | *-------------------------------------------------------------------------*/ | ||
110 | |||
111 | static const struct driver_info an2720_info = { | ||
112 | .description = "AnchorChips/Cypress 2720", | ||
113 | // no reset available! | ||
114 | // no check_connect available! | ||
115 | |||
116 | .in = 2, .out = 2, // direction distinguishes these | ||
117 | }; | ||
118 | |||
119 | #endif /* CONFIG_USB_AN2720 */ | ||
120 | |||
121 | |||
122 | #ifdef CONFIG_USB_BELKIN | ||
123 | #define HAVE_HARDWARE | ||
124 | |||
125 | /*------------------------------------------------------------------------- | ||
126 | * | ||
127 | * Belkin F5U104 ... two NetChip 2280 devices + Atmel AVR microcontroller | ||
128 | * | ||
129 | * ... also two eTEK designs, including one sold as "Advance USBNET" | ||
130 | * | ||
131 | *-------------------------------------------------------------------------*/ | ||
132 | |||
133 | static const struct driver_info belkin_info = { | ||
134 | .description = "Belkin, eTEK, or compatible", | ||
135 | }; | ||
136 | |||
137 | #endif /* CONFIG_USB_BELKIN */ | ||
138 | |||
139 | |||
140 | |||
141 | #ifdef CONFIG_USB_EPSON2888 | ||
142 | #define HAVE_HARDWARE | ||
143 | |||
144 | /*------------------------------------------------------------------------- | ||
145 | * | ||
146 | * EPSON USB clients | ||
147 | * | ||
148 | * This is the same idea as Linux PDAs (below) except the firmware in the | ||
149 | * device might not be Tux-powered. Epson provides reference firmware that | ||
150 | * implements this interface. Product developers can reuse or modify that | ||
151 | * code, such as by using their own product and vendor codes. | ||
152 | * | ||
153 | * Support was from Juro Bystricky <bystricky.juro@erd.epson.com> | ||
154 | * | ||
155 | *-------------------------------------------------------------------------*/ | ||
156 | |||
157 | static const struct driver_info epson2888_info = { | ||
158 | .description = "Epson USB Device", | ||
159 | .check_connect = always_connected, | ||
160 | |||
161 | .in = 4, .out = 3, | ||
162 | }; | ||
163 | |||
164 | #endif /* CONFIG_USB_EPSON2888 */ | ||
165 | |||
166 | |||
167 | #ifdef CONFIG_USB_KC2190 | ||
168 | #define HAVE_HARDWARE | ||
169 | static const struct driver_info kc2190_info = { | ||
170 | .description = "KC Technology KC-190", | ||
171 | }; | ||
172 | #endif /* CONFIG_USB_KC2190 */ | ||
173 | |||
174 | |||
175 | #ifdef CONFIG_USB_ARMLINUX | ||
176 | #define HAVE_HARDWARE | ||
177 | |||
178 | /*------------------------------------------------------------------------- | ||
179 | * | ||
180 | * Intel's SA-1100 chip integrates basic USB support, and is used | ||
181 | * in PDAs like some iPaqs, the Yopy, some Zaurus models, and more. | ||
182 | * When they run Linux, arch/arm/mach-sa1100/usb-eth.c may be used to | ||
183 | * network using minimal USB framing data. | ||
184 | * | ||
185 | * This describes the driver currently in standard ARM Linux kernels. | ||
186 | * The Zaurus uses a different driver (see later). | ||
187 | * | ||
188 | * PXA25x and PXA210 use XScale cores (ARM v5TE) with better USB support | ||
189 | * and different USB endpoint numbering than the SA1100 devices. The | ||
190 | * mach-pxa/usb-eth.c driver re-uses the device ids from mach-sa1100 | ||
191 | * so we rely on the endpoint descriptors. | ||
192 | * | ||
193 | *-------------------------------------------------------------------------*/ | ||
194 | |||
195 | static const struct driver_info linuxdev_info = { | ||
196 | .description = "Linux Device", | ||
197 | .check_connect = always_connected, | ||
198 | }; | ||
199 | |||
200 | static const struct driver_info yopy_info = { | ||
201 | .description = "Yopy", | ||
202 | .check_connect = always_connected, | ||
203 | }; | ||
204 | |||
205 | static const struct driver_info blob_info = { | ||
206 | .description = "Boot Loader OBject", | ||
207 | .check_connect = always_connected, | ||
208 | }; | ||
209 | |||
210 | #endif /* CONFIG_USB_ARMLINUX */ | ||
211 | |||
212 | |||
213 | /*-------------------------------------------------------------------------*/ | ||
214 | |||
215 | #ifndef HAVE_HARDWARE | ||
216 | #error You need to configure some hardware for this driver | ||
217 | #endif | ||
218 | |||
219 | /* | ||
220 | * chip vendor names won't normally be on the cables, and | ||
221 | * may not be on the device. | ||
222 | */ | ||
223 | |||
224 | static const struct usb_device_id products [] = { | ||
225 | |||
226 | #ifdef CONFIG_USB_ALI_M5632 | ||
227 | { | ||
228 | USB_DEVICE (0x0402, 0x5632), // ALi defaults | ||
229 | .driver_info = (unsigned long) &ali_m5632_info, | ||
230 | }, | ||
231 | #endif | ||
232 | |||
233 | #ifdef CONFIG_USB_AN2720 | ||
234 | { | ||
235 | USB_DEVICE (0x0547, 0x2720), // AnchorChips defaults | ||
236 | .driver_info = (unsigned long) &an2720_info, | ||
237 | }, { | ||
238 | USB_DEVICE (0x0547, 0x2727), // Xircom PGUNET | ||
239 | .driver_info = (unsigned long) &an2720_info, | ||
240 | }, | ||
241 | #endif | ||
242 | |||
243 | #ifdef CONFIG_USB_BELKIN | ||
244 | { | ||
245 | USB_DEVICE (0x050d, 0x0004), // Belkin | ||
246 | .driver_info = (unsigned long) &belkin_info, | ||
247 | }, { | ||
248 | USB_DEVICE (0x056c, 0x8100), // eTEK | ||
249 | .driver_info = (unsigned long) &belkin_info, | ||
250 | }, { | ||
251 | USB_DEVICE (0x0525, 0x9901), // Advance USBNET (eTEK) | ||
252 | .driver_info = (unsigned long) &belkin_info, | ||
253 | }, | ||
254 | #endif | ||
255 | |||
256 | #ifdef CONFIG_USB_EPSON2888 | ||
257 | { | ||
258 | USB_DEVICE (0x0525, 0x2888), // EPSON USB client | ||
259 | .driver_info = (unsigned long) &epson2888_info, | ||
260 | }, | ||
261 | #endif | ||
262 | |||
263 | #ifdef CONFIG_USB_KC2190 | ||
264 | { | ||
265 | USB_DEVICE (0x050f, 0x0190), // KC-190 | ||
266 | .driver_info = (unsigned long) &kc2190_info, | ||
267 | }, | ||
268 | #endif | ||
269 | |||
270 | #ifdef CONFIG_USB_ARMLINUX | ||
271 | /* | ||
272 | * SA-1100 using standard ARM Linux kernels, or compatible. | ||
273 | * Often used when talking to Linux PDAs (iPaq, Yopy, etc). | ||
274 | * The sa-1100 "usb-eth" driver handles the basic framing. | ||
275 | * | ||
276 | * PXA25x or PXA210 ... these use a "usb-eth" driver much like | ||
277 | * the sa1100 one, but hardware uses different endpoint numbers. | ||
278 | * | ||
279 | * Or the Linux "Ethernet" gadget on hardware that can't talk | ||
280 | * CDC Ethernet (e.g., no altsettings), in either of two modes: | ||
281 | * - acting just like the old "usb-eth" firmware, though | ||
282 | * the implementation is different | ||
283 | * - supporting RNDIS as the first/default configuration for | ||
284 | * MS-Windows interop; Linux needs to use the other config | ||
285 | */ | ||
286 | { | ||
287 | // 1183 = 0x049F, both used as hex values? | ||
288 | // Compaq "Itsy" vendor/product id | ||
289 | USB_DEVICE (0x049F, 0x505A), // usb-eth, or compatible | ||
290 | .driver_info = (unsigned long) &linuxdev_info, | ||
291 | }, { | ||
292 | USB_DEVICE (0x0E7E, 0x1001), // G.Mate "Yopy" | ||
293 | .driver_info = (unsigned long) &yopy_info, | ||
294 | }, { | ||
295 | USB_DEVICE (0x8086, 0x07d3), // "blob" bootloader | ||
296 | .driver_info = (unsigned long) &blob_info, | ||
297 | }, { | ||
298 | // Linux Ethernet/RNDIS gadget on pxa210/25x/26x, second config | ||
299 | // e.g. Gumstix, current OpenZaurus, ... | ||
300 | USB_DEVICE_VER (0x0525, 0xa4a2, 0x0203, 0x0203), | ||
301 | .driver_info = (unsigned long) &linuxdev_info, | ||
302 | }, | ||
303 | #endif | ||
304 | |||
305 | { }, // END | ||
306 | }; | ||
307 | MODULE_DEVICE_TABLE(usb, products); | ||
308 | |||
309 | /*-------------------------------------------------------------------------*/ | ||
310 | |||
311 | static struct usb_driver cdc_subset_driver = { | ||
312 | .owner = THIS_MODULE, | ||
313 | .name = "cdc_subset", | ||
314 | .probe = usbnet_probe, | ||
315 | .suspend = usbnet_suspend, | ||
316 | .resume = usbnet_resume, | ||
317 | .disconnect = usbnet_disconnect, | ||
318 | .id_table = products, | ||
319 | }; | ||
320 | |||
321 | static int __init cdc_subset_init(void) | ||
322 | { | ||
323 | return usb_register(&cdc_subset_driver); | ||
324 | } | ||
325 | module_init(cdc_subset_init); | ||
326 | |||
327 | static void __exit cdc_subset_exit(void) | ||
328 | { | ||
329 | usb_deregister(&cdc_subset_driver); | ||
330 | } | ||
331 | module_exit(cdc_subset_exit); | ||
332 | |||
333 | MODULE_AUTHOR("David Brownell"); | ||
334 | MODULE_DESCRIPTION("Simple 'CDC Subset' USB networking links"); | ||
335 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/net/gl620a.c b/drivers/usb/net/gl620a.c new file mode 100644 index 000000000000..c8763ae33c73 --- /dev/null +++ b/drivers/usb/net/gl620a.c | |||
@@ -0,0 +1,407 @@ | |||
1 | /* | ||
2 | * GeneSys GL620USB-A based links | ||
3 | * Copyright (C) 2001 by Jiun-Jie Huang <huangjj@genesyslogic.com.tw> | ||
4 | * Copyright (C) 2001 by Stanislav Brabec <utx@penguin.cz> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | */ | ||
20 | |||
21 | // #define DEBUG // error path messages, extra info | ||
22 | // #define VERBOSE // more; success messages | ||
23 | |||
24 | #include <linux/config.h> | ||
25 | #ifdef CONFIG_USB_DEBUG | ||
26 | # define DEBUG | ||
27 | #endif | ||
28 | #include <linux/module.h> | ||
29 | #include <linux/sched.h> | ||
30 | #include <linux/init.h> | ||
31 | #include <linux/netdevice.h> | ||
32 | #include <linux/etherdevice.h> | ||
33 | #include <linux/ethtool.h> | ||
34 | #include <linux/workqueue.h> | ||
35 | #include <linux/mii.h> | ||
36 | #include <linux/usb.h> | ||
37 | |||
38 | #include "usbnet.h" | ||
39 | |||
40 | |||
41 | /* | ||
42 | * GeneSys GL620USB-A (www.genesyslogic.com.tw) | ||
43 | * | ||
44 | * ... should partially interop with the Win32 driver for this hardware. | ||
45 | * The GeneSys docs imply there's some NDIS issue motivating this framing. | ||
46 | * | ||
47 | * Some info from GeneSys: | ||
48 | * - GL620USB-A is full duplex; GL620USB is only half duplex for bulk. | ||
49 | * (Some cables, like the BAFO-100c, use the half duplex version.) | ||
50 | * - For the full duplex model, the low bit of the version code says | ||
51 | * which side is which ("left/right"). | ||
52 | * - For the half duplex type, a control/interrupt handshake settles | ||
53 | * the transfer direction. (That's disabled here, partially coded.) | ||
54 | * A control URB would block until other side writes an interrupt. | ||
55 | * | ||
56 | * Original code from Jiun-Jie Huang <huangjj@genesyslogic.com.tw> | ||
57 | * and merged into "usbnet" by Stanislav Brabec <utx@penguin.cz>. | ||
58 | */ | ||
59 | |||
60 | // control msg write command | ||
61 | #define GENELINK_CONNECT_WRITE 0xF0 | ||
62 | // interrupt pipe index | ||
63 | #define GENELINK_INTERRUPT_PIPE 0x03 | ||
64 | // interrupt read buffer size | ||
65 | #define INTERRUPT_BUFSIZE 0x08 | ||
66 | // interrupt pipe interval value | ||
67 | #define GENELINK_INTERRUPT_INTERVAL 0x10 | ||
68 | // max transmit packet number per transmit | ||
69 | #define GL_MAX_TRANSMIT_PACKETS 32 | ||
70 | // max packet length | ||
71 | #define GL_MAX_PACKET_LEN 1514 | ||
72 | // max receive buffer size | ||
73 | #define GL_RCV_BUF_SIZE \ | ||
74 | (((GL_MAX_PACKET_LEN + 4) * GL_MAX_TRANSMIT_PACKETS) + 4) | ||
75 | |||
76 | struct gl_packet { | ||
77 | u32 packet_length; | ||
78 | char packet_data [1]; | ||
79 | }; | ||
80 | |||
81 | struct gl_header { | ||
82 | u32 packet_count; | ||
83 | struct gl_packet packets; | ||
84 | }; | ||
85 | |||
86 | #ifdef GENELINK_ACK | ||
87 | |||
88 | // FIXME: this code is incomplete, not debugged; it doesn't | ||
89 | // handle interrupts correctly; it should use the generic | ||
90 | // status IRQ code (which didn't exist back in 2001). | ||
91 | |||
92 | struct gl_priv { | ||
93 | struct urb *irq_urb; | ||
94 | char irq_buf [INTERRUPT_BUFSIZE]; | ||
95 | }; | ||
96 | |||
97 | static inline int gl_control_write(struct usbnet *dev, u8 request, u16 value) | ||
98 | { | ||
99 | int retval; | ||
100 | |||
101 | retval = usb_control_msg(dev->udev, | ||
102 | usb_sndctrlpipe(dev->udev, 0), | ||
103 | request, | ||
104 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | ||
105 | value, | ||
106 | 0, // index | ||
107 | 0, // data buffer | ||
108 | 0, // size | ||
109 | USB_CTRL_SET_TIMEOUT); | ||
110 | return retval; | ||
111 | } | ||
112 | |||
113 | static void gl_interrupt_complete(struct urb *urb, struct pt_regs *regs) | ||
114 | { | ||
115 | int status = urb->status; | ||
116 | |||
117 | switch (status) { | ||
118 | case 0: | ||
119 | /* success */ | ||
120 | break; | ||
121 | case -ECONNRESET: | ||
122 | case -ENOENT: | ||
123 | case -ESHUTDOWN: | ||
124 | /* this urb is terminated, clean up */ | ||
125 | dbg("%s - urb shutting down with status: %d", | ||
126 | __FUNCTION__, status); | ||
127 | return; | ||
128 | default: | ||
129 | dbg("%s - nonzero urb status received: %d", | ||
130 | __FUNCTION__, urb->status); | ||
131 | } | ||
132 | |||
133 | status = usb_submit_urb(urb, GFP_ATOMIC); | ||
134 | if (status) | ||
135 | err("%s - usb_submit_urb failed with result %d", | ||
136 | __FUNCTION__, status); | ||
137 | } | ||
138 | |||
139 | static int gl_interrupt_read(struct usbnet *dev) | ||
140 | { | ||
141 | struct gl_priv *priv = dev->priv_data; | ||
142 | int retval; | ||
143 | |||
144 | // issue usb interrupt read | ||
145 | if (priv && priv->irq_urb) { | ||
146 | // submit urb | ||
147 | if ((retval = usb_submit_urb(priv->irq_urb, GFP_KERNEL)) != 0) | ||
148 | dbg("gl_interrupt_read: submit fail - %X...", retval); | ||
149 | else | ||
150 | dbg("gl_interrupt_read: submit success..."); | ||
151 | } | ||
152 | |||
153 | return 0; | ||
154 | } | ||
155 | |||
156 | // check whether another side is connected | ||
157 | static int genelink_check_connect(struct usbnet *dev) | ||
158 | { | ||
159 | int retval; | ||
160 | |||
161 | dbg("genelink_check_connect..."); | ||
162 | |||
163 | // detect whether another side is connected | ||
164 | if ((retval = gl_control_write(dev, GENELINK_CONNECT_WRITE, 0)) != 0) { | ||
165 | dbg("%s: genelink_check_connect write fail - %X", | ||
166 | dev->net->name, retval); | ||
167 | return retval; | ||
168 | } | ||
169 | |||
170 | // usb interrupt read to ack another side | ||
171 | if ((retval = gl_interrupt_read(dev)) != 0) { | ||
172 | dbg("%s: genelink_check_connect read fail - %X", | ||
173 | dev->net->name, retval); | ||
174 | return retval; | ||
175 | } | ||
176 | |||
177 | dbg("%s: genelink_check_connect read success", dev->net->name); | ||
178 | return 0; | ||
179 | } | ||
180 | |||
181 | // allocate and initialize the private data for genelink | ||
182 | static int genelink_init(struct usbnet *dev) | ||
183 | { | ||
184 | struct gl_priv *priv; | ||
185 | |||
186 | // allocate the private data structure | ||
187 | if ((priv = kmalloc(sizeof *priv, GFP_KERNEL)) == 0) { | ||
188 | dbg("%s: cannot allocate private data per device", | ||
189 | dev->net->name); | ||
190 | return -ENOMEM; | ||
191 | } | ||
192 | |||
193 | // allocate irq urb | ||
194 | if ((priv->irq_urb = usb_alloc_urb(0, GFP_KERNEL)) == 0) { | ||
195 | dbg("%s: cannot allocate private irq urb per device", | ||
196 | dev->net->name); | ||
197 | kfree(priv); | ||
198 | return -ENOMEM; | ||
199 | } | ||
200 | |||
201 | // fill irq urb | ||
202 | usb_fill_int_urb(priv->irq_urb, dev->udev, | ||
203 | usb_rcvintpipe(dev->udev, GENELINK_INTERRUPT_PIPE), | ||
204 | priv->irq_buf, INTERRUPT_BUFSIZE, | ||
205 | gl_interrupt_complete, 0, | ||
206 | GENELINK_INTERRUPT_INTERVAL); | ||
207 | |||
208 | // set private data pointer | ||
209 | dev->priv_data = priv; | ||
210 | |||
211 | return 0; | ||
212 | } | ||
213 | |||
214 | // release the private data | ||
215 | static int genelink_free(struct usbnet *dev) | ||
216 | { | ||
217 | struct gl_priv *priv = dev->priv_data; | ||
218 | |||
219 | if (!priv) | ||
220 | return 0; | ||
221 | |||
222 | // FIXME: can't cancel here; it's synchronous, and | ||
223 | // should have happened earlier in any case (interrupt | ||
224 | // handling needs to be generic) | ||
225 | |||
226 | // cancel irq urb first | ||
227 | usb_kill_urb(priv->irq_urb); | ||
228 | |||
229 | // free irq urb | ||
230 | usb_free_urb(priv->irq_urb); | ||
231 | |||
232 | // free the private data structure | ||
233 | kfree(priv); | ||
234 | |||
235 | return 0; | ||
236 | } | ||
237 | |||
238 | #endif | ||
239 | |||
240 | static int genelink_rx_fixup(struct usbnet *dev, struct sk_buff *skb) | ||
241 | { | ||
242 | struct gl_header *header; | ||
243 | struct gl_packet *packet; | ||
244 | struct sk_buff *gl_skb; | ||
245 | u32 size; | ||
246 | |||
247 | header = (struct gl_header *) skb->data; | ||
248 | |||
249 | // get the packet count of the received skb | ||
250 | le32_to_cpus(&header->packet_count); | ||
251 | if ((header->packet_count > GL_MAX_TRANSMIT_PACKETS) | ||
252 | || (header->packet_count < 0)) { | ||
253 | dbg("genelink: invalid received packet count %d", | ||
254 | header->packet_count); | ||
255 | return 0; | ||
256 | } | ||
257 | |||
258 | // set the current packet pointer to the first packet | ||
259 | packet = &header->packets; | ||
260 | |||
261 | // decrement the length for the packet count size 4 bytes | ||
262 | skb_pull(skb, 4); | ||
263 | |||
264 | while (header->packet_count > 1) { | ||
265 | // get the packet length | ||
266 | size = le32_to_cpu(packet->packet_length); | ||
267 | |||
268 | // this may be a broken packet | ||
269 | if (size > GL_MAX_PACKET_LEN) { | ||
270 | dbg("genelink: invalid rx length %d", size); | ||
271 | return 0; | ||
272 | } | ||
273 | |||
274 | // allocate the skb for the individual packet | ||
275 | gl_skb = alloc_skb(size, GFP_ATOMIC); | ||
276 | if (gl_skb) { | ||
277 | |||
278 | // copy the packet data to the new skb | ||
279 | memcpy(skb_put(gl_skb, size), | ||
280 | packet->packet_data, size); | ||
281 | usbnet_skb_return(dev, gl_skb); | ||
282 | } | ||
283 | |||
284 | // advance to the next packet | ||
285 | packet = (struct gl_packet *) | ||
286 | &packet->packet_data [size]; | ||
287 | header->packet_count--; | ||
288 | |||
289 | // shift the data pointer to the next gl_packet | ||
290 | skb_pull(skb, size + 4); | ||
291 | } | ||
292 | |||
293 | // skip the packet length field 4 bytes | ||
294 | skb_pull(skb, 4); | ||
295 | |||
296 | if (skb->len > GL_MAX_PACKET_LEN) { | ||
297 | dbg("genelink: invalid rx length %d", skb->len); | ||
298 | return 0; | ||
299 | } | ||
300 | return 1; | ||
301 | } | ||
302 | |||
303 | static struct sk_buff * | ||
304 | genelink_tx_fixup(struct usbnet *dev, struct sk_buff *skb, unsigned flags) | ||
305 | { | ||
306 | int padlen; | ||
307 | int length = skb->len; | ||
308 | int headroom = skb_headroom(skb); | ||
309 | int tailroom = skb_tailroom(skb); | ||
310 | u32 *packet_count; | ||
311 | u32 *packet_len; | ||
312 | |||
313 | // FIXME: magic numbers, bleech | ||
314 | padlen = ((skb->len + (4 + 4*1)) % 64) ? 0 : 1; | ||
315 | |||
316 | if ((!skb_cloned(skb)) | ||
317 | && ((headroom + tailroom) >= (padlen + (4 + 4*1)))) { | ||
318 | if ((headroom < (4 + 4*1)) || (tailroom < padlen)) { | ||
319 | skb->data = memmove(skb->head + (4 + 4*1), | ||
320 | skb->data, skb->len); | ||
321 | skb->tail = skb->data + skb->len; | ||
322 | } | ||
323 | } else { | ||
324 | struct sk_buff *skb2; | ||
325 | skb2 = skb_copy_expand(skb, (4 + 4*1) , padlen, flags); | ||
326 | dev_kfree_skb_any(skb); | ||
327 | skb = skb2; | ||
328 | if (!skb) | ||
329 | return NULL; | ||
330 | } | ||
331 | |||
332 | // attach the packet count to the header | ||
333 | packet_count = (u32 *) skb_push(skb, (4 + 4*1)); | ||
334 | packet_len = packet_count + 1; | ||
335 | |||
336 | *packet_count = cpu_to_le32(1); | ||
337 | *packet_len = cpu_to_le32(length); | ||
338 | |||
339 | // add padding byte | ||
340 | if ((skb->len % dev->maxpacket) == 0) | ||
341 | skb_put(skb, 1); | ||
342 | |||
343 | return skb; | ||
344 | } | ||
345 | |||
346 | static int genelink_bind(struct usbnet *dev, struct usb_interface *intf) | ||
347 | { | ||
348 | dev->hard_mtu = GL_RCV_BUF_SIZE; | ||
349 | dev->net->hard_header_len += 4; | ||
350 | dev->in = usb_rcvbulkpipe(dev->udev, dev->driver_info->in); | ||
351 | dev->out = usb_sndbulkpipe(dev->udev, dev->driver_info->out); | ||
352 | return 0; | ||
353 | } | ||
354 | |||
355 | static const struct driver_info genelink_info = { | ||
356 | .description = "Genesys GeneLink", | ||
357 | .flags = FLAG_FRAMING_GL | FLAG_NO_SETINT, | ||
358 | .bind = genelink_bind, | ||
359 | .rx_fixup = genelink_rx_fixup, | ||
360 | .tx_fixup = genelink_tx_fixup, | ||
361 | |||
362 | .in = 1, .out = 2, | ||
363 | |||
364 | #ifdef GENELINK_ACK | ||
365 | .check_connect =genelink_check_connect, | ||
366 | #endif | ||
367 | }; | ||
368 | |||
369 | static const struct usb_device_id products [] = { | ||
370 | |||
371 | { | ||
372 | USB_DEVICE(0x05e3, 0x0502), // GL620USB-A | ||
373 | .driver_info = (unsigned long) &genelink_info, | ||
374 | }, | ||
375 | /* NOT: USB_DEVICE(0x05e3, 0x0501), // GL620USB | ||
376 | * that's half duplex, not currently supported | ||
377 | */ | ||
378 | { }, // END | ||
379 | }; | ||
380 | MODULE_DEVICE_TABLE(usb, products); | ||
381 | |||
382 | static struct usb_driver gl620a_driver = { | ||
383 | .owner = THIS_MODULE, | ||
384 | .name = "gl620a", | ||
385 | .id_table = products, | ||
386 | .probe = usbnet_probe, | ||
387 | .disconnect = usbnet_disconnect, | ||
388 | .suspend = usbnet_suspend, | ||
389 | .resume = usbnet_resume, | ||
390 | }; | ||
391 | |||
392 | static int __init usbnet_init(void) | ||
393 | { | ||
394 | return usb_register(&gl620a_driver); | ||
395 | } | ||
396 | module_init(usbnet_init); | ||
397 | |||
398 | static void __exit usbnet_exit(void) | ||
399 | { | ||
400 | usb_deregister(&gl620a_driver); | ||
401 | } | ||
402 | module_exit(usbnet_exit); | ||
403 | |||
404 | MODULE_AUTHOR("Jiun-Jie Huang"); | ||
405 | MODULE_DESCRIPTION("GL620-USB-A Host-to-Host Link cables"); | ||
406 | MODULE_LICENSE("GPL"); | ||
407 | |||
diff --git a/drivers/usb/net/kaweth.c b/drivers/usb/net/kaweth.c index 7ffa99b9760f..e04b0ce3611a 100644 --- a/drivers/usb/net/kaweth.c +++ b/drivers/usb/net/kaweth.c | |||
@@ -787,7 +787,6 @@ static int kaweth_start_xmit(struct sk_buff *skb, struct net_device *net) | |||
787 | kaweth_usb_transmit_complete, | 787 | kaweth_usb_transmit_complete, |
788 | kaweth); | 788 | kaweth); |
789 | kaweth->end = 0; | 789 | kaweth->end = 0; |
790 | kaweth->tx_urb->transfer_flags |= URB_ASYNC_UNLINK; | ||
791 | 790 | ||
792 | if((res = usb_submit_urb(kaweth->tx_urb, GFP_ATOMIC))) | 791 | if((res = usb_submit_urb(kaweth->tx_urb, GFP_ATOMIC))) |
793 | { | 792 | { |
diff --git a/drivers/usb/net/net1080.c b/drivers/usb/net/net1080.c new file mode 100644 index 000000000000..a4309c4a491b --- /dev/null +++ b/drivers/usb/net/net1080.c | |||
@@ -0,0 +1,622 @@ | |||
1 | /* | ||
2 | * Net1080 based USB host-to-host cables | ||
3 | * Copyright (C) 2000-2005 by David Brownell | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | // #define DEBUG // error path messages, extra info | ||
21 | // #define VERBOSE // more; success messages | ||
22 | |||
23 | #include <linux/config.h> | ||
24 | #ifdef CONFIG_USB_DEBUG | ||
25 | # define DEBUG | ||
26 | #endif | ||
27 | #include <linux/module.h> | ||
28 | #include <linux/sched.h> | ||
29 | #include <linux/init.h> | ||
30 | #include <linux/netdevice.h> | ||
31 | #include <linux/etherdevice.h> | ||
32 | #include <linux/ethtool.h> | ||
33 | #include <linux/workqueue.h> | ||
34 | #include <linux/mii.h> | ||
35 | #include <linux/usb.h> | ||
36 | |||
37 | #include <asm/unaligned.h> | ||
38 | |||
39 | #include "usbnet.h" | ||
40 | |||
41 | |||
42 | /* | ||
43 | * Netchip 1080 driver ... http://www.netchip.com | ||
44 | * (Sept 2004: End-of-life announcement has been sent.) | ||
45 | * Used in (some) LapLink cables | ||
46 | */ | ||
47 | |||
48 | #define frame_errors data[1] | ||
49 | |||
50 | /* | ||
51 | * NetChip framing of ethernet packets, supporting additional error | ||
52 | * checks for links that may drop bulk packets from inside messages. | ||
53 | * Odd USB length == always short read for last usb packet. | ||
54 | * - nc_header | ||
55 | * - Ethernet header (14 bytes) | ||
56 | * - payload | ||
57 | * - (optional padding byte, if needed so length becomes odd) | ||
58 | * - nc_trailer | ||
59 | * | ||
60 | * This framing is to be avoided for non-NetChip devices. | ||
61 | */ | ||
62 | |||
63 | struct nc_header { // packed: | ||
64 | __le16 hdr_len; // sizeof nc_header (LE, all) | ||
65 | __le16 packet_len; // payload size (including ethhdr) | ||
66 | __le16 packet_id; // detects dropped packets | ||
67 | #define MIN_HEADER 6 | ||
68 | |||
69 | // all else is optional, and must start with: | ||
70 | // __le16 vendorId; // from usb-if | ||
71 | // __le16 productId; | ||
72 | } __attribute__((__packed__)); | ||
73 | |||
74 | #define PAD_BYTE ((unsigned char)0xAC) | ||
75 | |||
76 | struct nc_trailer { | ||
77 | __le16 packet_id; | ||
78 | } __attribute__((__packed__)); | ||
79 | |||
80 | // packets may use FLAG_FRAMING_NC and optional pad | ||
81 | #define FRAMED_SIZE(mtu) (sizeof (struct nc_header) \ | ||
82 | + sizeof (struct ethhdr) \ | ||
83 | + (mtu) \ | ||
84 | + 1 \ | ||
85 | + sizeof (struct nc_trailer)) | ||
86 | |||
87 | #define MIN_FRAMED FRAMED_SIZE(0) | ||
88 | |||
89 | /* packets _could_ be up to 64KB... */ | ||
90 | #define NC_MAX_PACKET 32767 | ||
91 | |||
92 | |||
93 | /* | ||
94 | * Zero means no timeout; else, how long a 64 byte bulk packet may be queued | ||
95 | * before the hardware drops it. If that's done, the driver will need to | ||
96 | * frame network packets to guard against the dropped USB packets. The win32 | ||
97 | * driver sets this for both sides of the link. | ||
98 | */ | ||
99 | #define NC_READ_TTL_MS ((u8)255) // ms | ||
100 | |||
101 | /* | ||
102 | * We ignore most registers and EEPROM contents. | ||
103 | */ | ||
104 | #define REG_USBCTL ((u8)0x04) | ||
105 | #define REG_TTL ((u8)0x10) | ||
106 | #define REG_STATUS ((u8)0x11) | ||
107 | |||
108 | /* | ||
109 | * Vendor specific requests to read/write data | ||
110 | */ | ||
111 | #define REQUEST_REGISTER ((u8)0x10) | ||
112 | #define REQUEST_EEPROM ((u8)0x11) | ||
113 | |||
114 | static int | ||
115 | nc_vendor_read(struct usbnet *dev, u8 req, u8 regnum, u16 *retval_ptr) | ||
116 | { | ||
117 | int status = usb_control_msg(dev->udev, | ||
118 | usb_rcvctrlpipe(dev->udev, 0), | ||
119 | req, | ||
120 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
121 | 0, regnum, | ||
122 | retval_ptr, sizeof *retval_ptr, | ||
123 | USB_CTRL_GET_TIMEOUT); | ||
124 | if (status > 0) | ||
125 | status = 0; | ||
126 | if (!status) | ||
127 | le16_to_cpus(retval_ptr); | ||
128 | return status; | ||
129 | } | ||
130 | |||
131 | static inline int | ||
132 | nc_register_read(struct usbnet *dev, u8 regnum, u16 *retval_ptr) | ||
133 | { | ||
134 | return nc_vendor_read(dev, REQUEST_REGISTER, regnum, retval_ptr); | ||
135 | } | ||
136 | |||
137 | // no retval ... can become async, usable in_interrupt() | ||
138 | static void | ||
139 | nc_vendor_write(struct usbnet *dev, u8 req, u8 regnum, u16 value) | ||
140 | { | ||
141 | usb_control_msg(dev->udev, | ||
142 | usb_sndctrlpipe(dev->udev, 0), | ||
143 | req, | ||
144 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
145 | value, regnum, | ||
146 | NULL, 0, // data is in setup packet | ||
147 | USB_CTRL_SET_TIMEOUT); | ||
148 | } | ||
149 | |||
150 | static inline void | ||
151 | nc_register_write(struct usbnet *dev, u8 regnum, u16 value) | ||
152 | { | ||
153 | nc_vendor_write(dev, REQUEST_REGISTER, regnum, value); | ||
154 | } | ||
155 | |||
156 | |||
157 | #if 0 | ||
158 | static void nc_dump_registers(struct usbnet *dev) | ||
159 | { | ||
160 | u8 reg; | ||
161 | u16 *vp = kmalloc(sizeof (u16)); | ||
162 | |||
163 | if (!vp) { | ||
164 | dbg("no memory?"); | ||
165 | return; | ||
166 | } | ||
167 | |||
168 | dbg("%s registers:", dev->net->name); | ||
169 | for (reg = 0; reg < 0x20; reg++) { | ||
170 | int retval; | ||
171 | |||
172 | // reading some registers is trouble | ||
173 | if (reg >= 0x08 && reg <= 0xf) | ||
174 | continue; | ||
175 | if (reg >= 0x12 && reg <= 0x1e) | ||
176 | continue; | ||
177 | |||
178 | retval = nc_register_read(dev, reg, vp); | ||
179 | if (retval < 0) | ||
180 | dbg("%s reg [0x%x] ==> error %d", | ||
181 | dev->net->name, reg, retval); | ||
182 | else | ||
183 | dbg("%s reg [0x%x] = 0x%x", | ||
184 | dev->net->name, reg, *vp); | ||
185 | } | ||
186 | kfree(vp); | ||
187 | } | ||
188 | #endif | ||
189 | |||
190 | |||
191 | /*-------------------------------------------------------------------------*/ | ||
192 | |||
193 | /* | ||
194 | * Control register | ||
195 | */ | ||
196 | |||
197 | #define USBCTL_WRITABLE_MASK 0x1f0f | ||
198 | // bits 15-13 reserved, r/o | ||
199 | #define USBCTL_ENABLE_LANG (1 << 12) | ||
200 | #define USBCTL_ENABLE_MFGR (1 << 11) | ||
201 | #define USBCTL_ENABLE_PROD (1 << 10) | ||
202 | #define USBCTL_ENABLE_SERIAL (1 << 9) | ||
203 | #define USBCTL_ENABLE_DEFAULTS (1 << 8) | ||
204 | // bits 7-4 reserved, r/o | ||
205 | #define USBCTL_FLUSH_OTHER (1 << 3) | ||
206 | #define USBCTL_FLUSH_THIS (1 << 2) | ||
207 | #define USBCTL_DISCONN_OTHER (1 << 1) | ||
208 | #define USBCTL_DISCONN_THIS (1 << 0) | ||
209 | |||
210 | static inline void nc_dump_usbctl(struct usbnet *dev, u16 usbctl) | ||
211 | { | ||
212 | if (!netif_msg_link(dev)) | ||
213 | return; | ||
214 | devdbg(dev, "net1080 %s-%s usbctl 0x%x:%s%s%s%s%s;" | ||
215 | " this%s%s;" | ||
216 | " other%s%s; r/o 0x%x", | ||
217 | dev->udev->bus->bus_name, dev->udev->devpath, | ||
218 | usbctl, | ||
219 | (usbctl & USBCTL_ENABLE_LANG) ? " lang" : "", | ||
220 | (usbctl & USBCTL_ENABLE_MFGR) ? " mfgr" : "", | ||
221 | (usbctl & USBCTL_ENABLE_PROD) ? " prod" : "", | ||
222 | (usbctl & USBCTL_ENABLE_SERIAL) ? " serial" : "", | ||
223 | (usbctl & USBCTL_ENABLE_DEFAULTS) ? " defaults" : "", | ||
224 | |||
225 | (usbctl & USBCTL_FLUSH_OTHER) ? " FLUSH" : "", | ||
226 | (usbctl & USBCTL_DISCONN_OTHER) ? " DIS" : "", | ||
227 | (usbctl & USBCTL_FLUSH_THIS) ? " FLUSH" : "", | ||
228 | (usbctl & USBCTL_DISCONN_THIS) ? " DIS" : "", | ||
229 | usbctl & ~USBCTL_WRITABLE_MASK | ||
230 | ); | ||
231 | } | ||
232 | |||
233 | /*-------------------------------------------------------------------------*/ | ||
234 | |||
235 | /* | ||
236 | * Status register | ||
237 | */ | ||
238 | |||
239 | #define STATUS_PORT_A (1 << 15) | ||
240 | |||
241 | #define STATUS_CONN_OTHER (1 << 14) | ||
242 | #define STATUS_SUSPEND_OTHER (1 << 13) | ||
243 | #define STATUS_MAILBOX_OTHER (1 << 12) | ||
244 | #define STATUS_PACKETS_OTHER(n) (((n) >> 8) && 0x03) | ||
245 | |||
246 | #define STATUS_CONN_THIS (1 << 6) | ||
247 | #define STATUS_SUSPEND_THIS (1 << 5) | ||
248 | #define STATUS_MAILBOX_THIS (1 << 4) | ||
249 | #define STATUS_PACKETS_THIS(n) (((n) >> 0) && 0x03) | ||
250 | |||
251 | #define STATUS_UNSPEC_MASK 0x0c8c | ||
252 | #define STATUS_NOISE_MASK ((u16)~(0x0303|STATUS_UNSPEC_MASK)) | ||
253 | |||
254 | |||
255 | static inline void nc_dump_status(struct usbnet *dev, u16 status) | ||
256 | { | ||
257 | if (!netif_msg_link(dev)) | ||
258 | return; | ||
259 | devdbg(dev, "net1080 %s-%s status 0x%x:" | ||
260 | " this (%c) PKT=%d%s%s%s;" | ||
261 | " other PKT=%d%s%s%s; unspec 0x%x", | ||
262 | dev->udev->bus->bus_name, dev->udev->devpath, | ||
263 | status, | ||
264 | |||
265 | // XXX the packet counts don't seem right | ||
266 | // (1 at reset, not 0); maybe UNSPEC too | ||
267 | |||
268 | (status & STATUS_PORT_A) ? 'A' : 'B', | ||
269 | STATUS_PACKETS_THIS(status), | ||
270 | (status & STATUS_CONN_THIS) ? " CON" : "", | ||
271 | (status & STATUS_SUSPEND_THIS) ? " SUS" : "", | ||
272 | (status & STATUS_MAILBOX_THIS) ? " MBOX" : "", | ||
273 | |||
274 | STATUS_PACKETS_OTHER(status), | ||
275 | (status & STATUS_CONN_OTHER) ? " CON" : "", | ||
276 | (status & STATUS_SUSPEND_OTHER) ? " SUS" : "", | ||
277 | (status & STATUS_MAILBOX_OTHER) ? " MBOX" : "", | ||
278 | |||
279 | status & STATUS_UNSPEC_MASK | ||
280 | ); | ||
281 | } | ||
282 | |||
283 | /*-------------------------------------------------------------------------*/ | ||
284 | |||
285 | /* | ||
286 | * TTL register | ||
287 | */ | ||
288 | |||
289 | #define TTL_THIS(ttl) (0x00ff & ttl) | ||
290 | #define TTL_OTHER(ttl) (0x00ff & (ttl >> 8)) | ||
291 | #define MK_TTL(this,other) ((u16)(((other)<<8)|(0x00ff&(this)))) | ||
292 | |||
293 | static inline void nc_dump_ttl(struct usbnet *dev, u16 ttl) | ||
294 | { | ||
295 | if (netif_msg_link(dev)) | ||
296 | devdbg(dev, "net1080 %s-%s ttl 0x%x this = %d, other = %d", | ||
297 | dev->udev->bus->bus_name, dev->udev->devpath, | ||
298 | ttl, TTL_THIS(ttl), TTL_OTHER(ttl)); | ||
299 | } | ||
300 | |||
301 | /*-------------------------------------------------------------------------*/ | ||
302 | |||
303 | static int net1080_reset(struct usbnet *dev) | ||
304 | { | ||
305 | u16 usbctl, status, ttl; | ||
306 | u16 *vp = kmalloc(sizeof (u16), GFP_KERNEL); | ||
307 | int retval; | ||
308 | |||
309 | if (!vp) | ||
310 | return -ENOMEM; | ||
311 | |||
312 | // nc_dump_registers(dev); | ||
313 | |||
314 | if ((retval = nc_register_read(dev, REG_STATUS, vp)) < 0) { | ||
315 | dbg("can't read %s-%s status: %d", | ||
316 | dev->udev->bus->bus_name, dev->udev->devpath, retval); | ||
317 | goto done; | ||
318 | } | ||
319 | status = *vp; | ||
320 | nc_dump_status(dev, status); | ||
321 | |||
322 | if ((retval = nc_register_read(dev, REG_USBCTL, vp)) < 0) { | ||
323 | dbg("can't read USBCTL, %d", retval); | ||
324 | goto done; | ||
325 | } | ||
326 | usbctl = *vp; | ||
327 | nc_dump_usbctl(dev, usbctl); | ||
328 | |||
329 | nc_register_write(dev, REG_USBCTL, | ||
330 | USBCTL_FLUSH_THIS | USBCTL_FLUSH_OTHER); | ||
331 | |||
332 | if ((retval = nc_register_read(dev, REG_TTL, vp)) < 0) { | ||
333 | dbg("can't read TTL, %d", retval); | ||
334 | goto done; | ||
335 | } | ||
336 | ttl = *vp; | ||
337 | // nc_dump_ttl(dev, ttl); | ||
338 | |||
339 | nc_register_write(dev, REG_TTL, | ||
340 | MK_TTL(NC_READ_TTL_MS, TTL_OTHER(ttl)) ); | ||
341 | dbg("%s: assigned TTL, %d ms", dev->net->name, NC_READ_TTL_MS); | ||
342 | |||
343 | if (netif_msg_link(dev)) | ||
344 | devinfo(dev, "port %c, peer %sconnected", | ||
345 | (status & STATUS_PORT_A) ? 'A' : 'B', | ||
346 | (status & STATUS_CONN_OTHER) ? "" : "dis" | ||
347 | ); | ||
348 | retval = 0; | ||
349 | |||
350 | done: | ||
351 | kfree(vp); | ||
352 | return retval; | ||
353 | } | ||
354 | |||
355 | static int net1080_check_connect(struct usbnet *dev) | ||
356 | { | ||
357 | int retval; | ||
358 | u16 status; | ||
359 | u16 *vp = kmalloc(sizeof (u16), GFP_KERNEL); | ||
360 | |||
361 | if (!vp) | ||
362 | return -ENOMEM; | ||
363 | retval = nc_register_read(dev, REG_STATUS, vp); | ||
364 | status = *vp; | ||
365 | kfree(vp); | ||
366 | if (retval != 0) { | ||
367 | dbg("%s net1080_check_conn read - %d", dev->net->name, retval); | ||
368 | return retval; | ||
369 | } | ||
370 | if ((status & STATUS_CONN_OTHER) != STATUS_CONN_OTHER) | ||
371 | return -ENOLINK; | ||
372 | return 0; | ||
373 | } | ||
374 | |||
375 | static void nc_flush_complete(struct urb *urb, struct pt_regs *regs) | ||
376 | { | ||
377 | kfree(urb->context); | ||
378 | usb_free_urb(urb); | ||
379 | } | ||
380 | |||
381 | static void nc_ensure_sync(struct usbnet *dev) | ||
382 | { | ||
383 | dev->frame_errors++; | ||
384 | if (dev->frame_errors > 5) { | ||
385 | struct urb *urb; | ||
386 | struct usb_ctrlrequest *req; | ||
387 | int status; | ||
388 | |||
389 | /* Send a flush */ | ||
390 | urb = usb_alloc_urb(0, SLAB_ATOMIC); | ||
391 | if (!urb) | ||
392 | return; | ||
393 | |||
394 | req = kmalloc(sizeof *req, GFP_ATOMIC); | ||
395 | if (!req) { | ||
396 | usb_free_urb(urb); | ||
397 | return; | ||
398 | } | ||
399 | |||
400 | req->bRequestType = USB_DIR_OUT | ||
401 | | USB_TYPE_VENDOR | ||
402 | | USB_RECIP_DEVICE; | ||
403 | req->bRequest = REQUEST_REGISTER; | ||
404 | req->wValue = cpu_to_le16(USBCTL_FLUSH_THIS | ||
405 | | USBCTL_FLUSH_OTHER); | ||
406 | req->wIndex = cpu_to_le16(REG_USBCTL); | ||
407 | req->wLength = cpu_to_le16(0); | ||
408 | |||
409 | /* queue an async control request, we don't need | ||
410 | * to do anything when it finishes except clean up. | ||
411 | */ | ||
412 | usb_fill_control_urb(urb, dev->udev, | ||
413 | usb_sndctrlpipe(dev->udev, 0), | ||
414 | (unsigned char *) req, | ||
415 | NULL, 0, | ||
416 | nc_flush_complete, req); | ||
417 | status = usb_submit_urb(urb, GFP_ATOMIC); | ||
418 | if (status) { | ||
419 | kfree(req); | ||
420 | usb_free_urb(urb); | ||
421 | return; | ||
422 | } | ||
423 | |||
424 | if (netif_msg_rx_err(dev)) | ||
425 | devdbg(dev, "flush net1080; too many framing errors"); | ||
426 | dev->frame_errors = 0; | ||
427 | } | ||
428 | } | ||
429 | |||
430 | static int net1080_rx_fixup(struct usbnet *dev, struct sk_buff *skb) | ||
431 | { | ||
432 | struct nc_header *header; | ||
433 | struct nc_trailer *trailer; | ||
434 | u16 hdr_len, packet_len; | ||
435 | |||
436 | if (!(skb->len & 0x01)) { | ||
437 | #ifdef DEBUG | ||
438 | struct net_device *net = dev->net; | ||
439 | dbg("rx framesize %d range %d..%d mtu %d", skb->len, | ||
440 | net->hard_header_len, dev->hard_mtu, net->mtu); | ||
441 | #endif | ||
442 | dev->stats.rx_frame_errors++; | ||
443 | nc_ensure_sync(dev); | ||
444 | return 0; | ||
445 | } | ||
446 | |||
447 | header = (struct nc_header *) skb->data; | ||
448 | hdr_len = le16_to_cpup(&header->hdr_len); | ||
449 | packet_len = le16_to_cpup(&header->packet_len); | ||
450 | if (FRAMED_SIZE(packet_len) > NC_MAX_PACKET) { | ||
451 | dev->stats.rx_frame_errors++; | ||
452 | dbg("packet too big, %d", packet_len); | ||
453 | nc_ensure_sync(dev); | ||
454 | return 0; | ||
455 | } else if (hdr_len < MIN_HEADER) { | ||
456 | dev->stats.rx_frame_errors++; | ||
457 | dbg("header too short, %d", hdr_len); | ||
458 | nc_ensure_sync(dev); | ||
459 | return 0; | ||
460 | } else if (hdr_len > MIN_HEADER) { | ||
461 | // out of band data for us? | ||
462 | dbg("header OOB, %d bytes", hdr_len - MIN_HEADER); | ||
463 | nc_ensure_sync(dev); | ||
464 | // switch (vendor/product ids) { ... } | ||
465 | } | ||
466 | skb_pull(skb, hdr_len); | ||
467 | |||
468 | trailer = (struct nc_trailer *) | ||
469 | (skb->data + skb->len - sizeof *trailer); | ||
470 | skb_trim(skb, skb->len - sizeof *trailer); | ||
471 | |||
472 | if ((packet_len & 0x01) == 0) { | ||
473 | if (skb->data [packet_len] != PAD_BYTE) { | ||
474 | dev->stats.rx_frame_errors++; | ||
475 | dbg("bad pad"); | ||
476 | return 0; | ||
477 | } | ||
478 | skb_trim(skb, skb->len - 1); | ||
479 | } | ||
480 | if (skb->len != packet_len) { | ||
481 | dev->stats.rx_frame_errors++; | ||
482 | dbg("bad packet len %d (expected %d)", | ||
483 | skb->len, packet_len); | ||
484 | nc_ensure_sync(dev); | ||
485 | return 0; | ||
486 | } | ||
487 | if (header->packet_id != get_unaligned(&trailer->packet_id)) { | ||
488 | dev->stats.rx_fifo_errors++; | ||
489 | dbg("(2+ dropped) rx packet_id mismatch 0x%x 0x%x", | ||
490 | le16_to_cpu(header->packet_id), | ||
491 | le16_to_cpu(trailer->packet_id)); | ||
492 | return 0; | ||
493 | } | ||
494 | #if 0 | ||
495 | devdbg(dev, "frame <rx h %d p %d id %d", header->hdr_len, | ||
496 | header->packet_len, header->packet_id); | ||
497 | #endif | ||
498 | dev->frame_errors = 0; | ||
499 | return 1; | ||
500 | } | ||
501 | |||
502 | static struct sk_buff * | ||
503 | net1080_tx_fixup(struct usbnet *dev, struct sk_buff *skb, unsigned flags) | ||
504 | { | ||
505 | int padlen; | ||
506 | struct sk_buff *skb2; | ||
507 | struct nc_header *header = NULL; | ||
508 | struct nc_trailer *trailer = NULL; | ||
509 | int len = skb->len; | ||
510 | |||
511 | padlen = ((len + sizeof (struct nc_header) | ||
512 | + sizeof (struct nc_trailer)) & 0x01) ? 0 : 1; | ||
513 | if (!skb_cloned(skb)) { | ||
514 | int headroom = skb_headroom(skb); | ||
515 | int tailroom = skb_tailroom(skb); | ||
516 | |||
517 | if ((padlen + sizeof (struct nc_trailer)) <= tailroom | ||
518 | && sizeof (struct nc_header) <= headroom) | ||
519 | /* There's enough head and tail room */ | ||
520 | goto encapsulate; | ||
521 | |||
522 | if ((sizeof (struct nc_header) + padlen | ||
523 | + sizeof (struct nc_trailer)) < | ||
524 | (headroom + tailroom)) { | ||
525 | /* There's enough total room, so just readjust */ | ||
526 | skb->data = memmove(skb->head | ||
527 | + sizeof (struct nc_header), | ||
528 | skb->data, skb->len); | ||
529 | skb->tail = skb->data + len; | ||
530 | goto encapsulate; | ||
531 | } | ||
532 | } | ||
533 | |||
534 | /* Create a new skb to use with the correct size */ | ||
535 | skb2 = skb_copy_expand(skb, | ||
536 | sizeof (struct nc_header), | ||
537 | sizeof (struct nc_trailer) + padlen, | ||
538 | flags); | ||
539 | dev_kfree_skb_any(skb); | ||
540 | if (!skb2) | ||
541 | return skb2; | ||
542 | skb = skb2; | ||
543 | |||
544 | encapsulate: | ||
545 | /* header first */ | ||
546 | header = (struct nc_header *) skb_push(skb, sizeof *header); | ||
547 | header->hdr_len = cpu_to_le16(sizeof (*header)); | ||
548 | header->packet_len = cpu_to_le16(len); | ||
549 | header->packet_id = cpu_to_le16((u16)dev->xid++); | ||
550 | |||
551 | /* maybe pad; then trailer */ | ||
552 | if (!((skb->len + sizeof *trailer) & 0x01)) | ||
553 | *skb_put(skb, 1) = PAD_BYTE; | ||
554 | trailer = (struct nc_trailer *) skb_put(skb, sizeof *trailer); | ||
555 | put_unaligned(header->packet_id, &trailer->packet_id); | ||
556 | #if 0 | ||
557 | devdbg(dev, "frame >tx h %d p %d id %d", | ||
558 | header->hdr_len, header->packet_len, | ||
559 | header->packet_id); | ||
560 | #endif | ||
561 | return skb; | ||
562 | } | ||
563 | |||
564 | static int net1080_bind(struct usbnet *dev, struct usb_interface *intf) | ||
565 | { | ||
566 | unsigned extra = sizeof (struct nc_header) | ||
567 | + 1 | ||
568 | + sizeof (struct nc_trailer); | ||
569 | |||
570 | dev->net->hard_header_len += extra; | ||
571 | dev->rx_urb_size = dev->net->hard_header_len + dev->net->mtu; | ||
572 | dev->hard_mtu = NC_MAX_PACKET; | ||
573 | return usbnet_get_endpoints (dev, intf); | ||
574 | } | ||
575 | |||
576 | static const struct driver_info net1080_info = { | ||
577 | .description = "NetChip TurboCONNECT", | ||
578 | .flags = FLAG_FRAMING_NC, | ||
579 | .bind = net1080_bind, | ||
580 | .reset = net1080_reset, | ||
581 | .check_connect = net1080_check_connect, | ||
582 | .rx_fixup = net1080_rx_fixup, | ||
583 | .tx_fixup = net1080_tx_fixup, | ||
584 | }; | ||
585 | |||
586 | static const struct usb_device_id products [] = { | ||
587 | { | ||
588 | USB_DEVICE(0x0525, 0x1080), // NetChip ref design | ||
589 | .driver_info = (unsigned long) &net1080_info, | ||
590 | }, { | ||
591 | USB_DEVICE(0x06D0, 0x0622), // Laplink Gold | ||
592 | .driver_info = (unsigned long) &net1080_info, | ||
593 | }, | ||
594 | { }, // END | ||
595 | }; | ||
596 | MODULE_DEVICE_TABLE(usb, products); | ||
597 | |||
598 | static struct usb_driver net1080_driver = { | ||
599 | .owner = THIS_MODULE, | ||
600 | .name = "net1080", | ||
601 | .id_table = products, | ||
602 | .probe = usbnet_probe, | ||
603 | .disconnect = usbnet_disconnect, | ||
604 | .suspend = usbnet_suspend, | ||
605 | .resume = usbnet_resume, | ||
606 | }; | ||
607 | |||
608 | static int __init net1080_init(void) | ||
609 | { | ||
610 | return usb_register(&net1080_driver); | ||
611 | } | ||
612 | module_init(net1080_init); | ||
613 | |||
614 | static void __exit net1080_exit(void) | ||
615 | { | ||
616 | usb_deregister(&net1080_driver); | ||
617 | } | ||
618 | module_exit(net1080_exit); | ||
619 | |||
620 | MODULE_AUTHOR("David Brownell"); | ||
621 | MODULE_DESCRIPTION("NetChip 1080 based USB Host-to-Host Links"); | ||
622 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/net/pegasus.c b/drivers/usb/net/pegasus.c index fcd6d3ccef44..7484d34780fc 100644 --- a/drivers/usb/net/pegasus.c +++ b/drivers/usb/net/pegasus.c | |||
@@ -825,7 +825,6 @@ static void pegasus_tx_timeout(struct net_device *net) | |||
825 | pegasus_t *pegasus = netdev_priv(net); | 825 | pegasus_t *pegasus = netdev_priv(net); |
826 | if (netif_msg_timer(pegasus)) | 826 | if (netif_msg_timer(pegasus)) |
827 | printk(KERN_WARNING "%s: tx timeout\n", net->name); | 827 | printk(KERN_WARNING "%s: tx timeout\n", net->name); |
828 | pegasus->tx_urb->transfer_flags |= URB_ASYNC_UNLINK; | ||
829 | usb_unlink_urb(pegasus->tx_urb); | 828 | usb_unlink_urb(pegasus->tx_urb); |
830 | pegasus->stats.tx_errors++; | 829 | pegasus->stats.tx_errors++; |
831 | } | 830 | } |
diff --git a/drivers/usb/net/plusb.c b/drivers/usb/net/plusb.c new file mode 100644 index 000000000000..74c2b3581c76 --- /dev/null +++ b/drivers/usb/net/plusb.c | |||
@@ -0,0 +1,156 @@ | |||
1 | /* | ||
2 | * PL-2301/2302 USB host-to-host link cables | ||
3 | * Copyright (C) 2000-2005 by David Brownell | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | // #define DEBUG // error path messages, extra info | ||
21 | // #define VERBOSE // more; success messages | ||
22 | |||
23 | #include <linux/config.h> | ||
24 | #ifdef CONFIG_USB_DEBUG | ||
25 | # define DEBUG | ||
26 | #endif | ||
27 | #include <linux/module.h> | ||
28 | #include <linux/sched.h> | ||
29 | #include <linux/init.h> | ||
30 | #include <linux/netdevice.h> | ||
31 | #include <linux/etherdevice.h> | ||
32 | #include <linux/ethtool.h> | ||
33 | #include <linux/workqueue.h> | ||
34 | #include <linux/mii.h> | ||
35 | #include <linux/usb.h> | ||
36 | |||
37 | #include "usbnet.h" | ||
38 | |||
39 | |||
40 | /* | ||
41 | * Prolific PL-2301/PL-2302 driver ... http://www.prolifictech.com | ||
42 | * | ||
43 | * The protocol and handshaking used here should be bug-compatible | ||
44 | * with the Linux 2.2 "plusb" driver, by Deti Fliegl. | ||
45 | * | ||
46 | * HEADS UP: this handshaking isn't all that robust. This driver | ||
47 | * gets confused easily if you unplug one end of the cable then | ||
48 | * try to connect it again; you'll need to restart both ends. The | ||
49 | * "naplink" software (used by some PlayStation/2 deveopers) does | ||
50 | * the handshaking much better! Also, sometimes this hardware | ||
51 | * seems to get wedged under load. Prolific docs are weak, and | ||
52 | * don't identify differences between PL2301 and PL2302, much less | ||
53 | * anything to explain the different PL2302 versions observed. | ||
54 | */ | ||
55 | |||
56 | /* | ||
57 | * Bits 0-4 can be used for software handshaking; they're set from | ||
58 | * one end, cleared from the other, "read" with the interrupt byte. | ||
59 | */ | ||
60 | #define PL_S_EN (1<<7) /* (feature only) suspend enable */ | ||
61 | /* reserved bit -- rx ready (6) ? */ | ||
62 | #define PL_TX_READY (1<<5) /* (interrupt only) transmit ready */ | ||
63 | #define PL_RESET_OUT (1<<4) /* reset output pipe */ | ||
64 | #define PL_RESET_IN (1<<3) /* reset input pipe */ | ||
65 | #define PL_TX_C (1<<2) /* transmission complete */ | ||
66 | #define PL_TX_REQ (1<<1) /* transmission received */ | ||
67 | #define PL_PEER_E (1<<0) /* peer exists */ | ||
68 | |||
69 | static inline int | ||
70 | pl_vendor_req(struct usbnet *dev, u8 req, u8 val, u8 index) | ||
71 | { | ||
72 | return usb_control_msg(dev->udev, | ||
73 | usb_rcvctrlpipe(dev->udev, 0), | ||
74 | req, | ||
75 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
76 | val, index, | ||
77 | NULL, 0, | ||
78 | USB_CTRL_GET_TIMEOUT); | ||
79 | } | ||
80 | |||
81 | static inline int | ||
82 | pl_clear_QuickLink_features(struct usbnet *dev, int val) | ||
83 | { | ||
84 | return pl_vendor_req(dev, 1, (u8) val, 0); | ||
85 | } | ||
86 | |||
87 | static inline int | ||
88 | pl_set_QuickLink_features(struct usbnet *dev, int val) | ||
89 | { | ||
90 | return pl_vendor_req(dev, 3, (u8) val, 0); | ||
91 | } | ||
92 | |||
93 | static int pl_reset(struct usbnet *dev) | ||
94 | { | ||
95 | /* some units seem to need this reset, others reject it utterly. | ||
96 | * FIXME be more like "naplink" or windows drivers. | ||
97 | */ | ||
98 | (void) pl_set_QuickLink_features(dev, | ||
99 | PL_S_EN|PL_RESET_OUT|PL_RESET_IN|PL_PEER_E); | ||
100 | return 0; | ||
101 | } | ||
102 | |||
103 | static const struct driver_info prolific_info = { | ||
104 | .description = "Prolific PL-2301/PL-2302", | ||
105 | .flags = FLAG_NO_SETINT, | ||
106 | /* some PL-2302 versions seem to fail usb_set_interface() */ | ||
107 | .reset = pl_reset, | ||
108 | }; | ||
109 | |||
110 | |||
111 | /*-------------------------------------------------------------------------*/ | ||
112 | |||
113 | /* | ||
114 | * Proilific's name won't normally be on the cables, and | ||
115 | * may not be on the device. | ||
116 | */ | ||
117 | |||
118 | static const struct usb_device_id products [] = { | ||
119 | |||
120 | { | ||
121 | USB_DEVICE(0x067b, 0x0000), // PL-2301 | ||
122 | .driver_info = (unsigned long) &prolific_info, | ||
123 | }, { | ||
124 | USB_DEVICE(0x067b, 0x0001), // PL-2302 | ||
125 | .driver_info = (unsigned long) &prolific_info, | ||
126 | }, | ||
127 | |||
128 | { }, // END | ||
129 | }; | ||
130 | MODULE_DEVICE_TABLE(usb, products); | ||
131 | |||
132 | static struct usb_driver plusb_driver = { | ||
133 | .owner = THIS_MODULE, | ||
134 | .name = "plusb", | ||
135 | .id_table = products, | ||
136 | .probe = usbnet_probe, | ||
137 | .disconnect = usbnet_disconnect, | ||
138 | .suspend = usbnet_suspend, | ||
139 | .resume = usbnet_resume, | ||
140 | }; | ||
141 | |||
142 | static int __init plusb_init(void) | ||
143 | { | ||
144 | return usb_register(&plusb_driver); | ||
145 | } | ||
146 | module_init(plusb_init); | ||
147 | |||
148 | static void __exit plusb_exit(void) | ||
149 | { | ||
150 | usb_deregister(&plusb_driver); | ||
151 | } | ||
152 | module_exit(plusb_exit); | ||
153 | |||
154 | MODULE_AUTHOR("David Brownell"); | ||
155 | MODULE_DESCRIPTION("Prolific PL-2301/2302 USB Host to Host Link Driver"); | ||
156 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/net/rndis_host.c b/drivers/usb/net/rndis_host.c new file mode 100644 index 000000000000..2ed2e5fb7778 --- /dev/null +++ b/drivers/usb/net/rndis_host.c | |||
@@ -0,0 +1,615 @@ | |||
1 | /* | ||
2 | * Host Side support for RNDIS Networking Links | ||
3 | * Copyright (C) 2005 by David Brownell | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | // #define DEBUG // error path messages, extra info | ||
21 | // #define VERBOSE // more; success messages | ||
22 | |||
23 | #include <linux/config.h> | ||
24 | #ifdef CONFIG_USB_DEBUG | ||
25 | # define DEBUG | ||
26 | #endif | ||
27 | #include <linux/module.h> | ||
28 | #include <linux/sched.h> | ||
29 | #include <linux/init.h> | ||
30 | #include <linux/netdevice.h> | ||
31 | #include <linux/etherdevice.h> | ||
32 | #include <linux/ethtool.h> | ||
33 | #include <linux/workqueue.h> | ||
34 | #include <linux/mii.h> | ||
35 | #include <linux/usb.h> | ||
36 | #include <linux/usb_cdc.h> | ||
37 | |||
38 | #include "usbnet.h" | ||
39 | |||
40 | |||
41 | /* | ||
42 | * RNDIS is NDIS remoted over USB. It's a MSFT variant of CDC ACM ... of | ||
43 | * course ACM was intended for modems, not Ethernet links! USB's standard | ||
44 | * for Ethernet links is "CDC Ethernet", which is significantly simpler. | ||
45 | */ | ||
46 | |||
47 | /* | ||
48 | * CONTROL uses CDC "encapsulated commands" with funky notifications. | ||
49 | * - control-out: SEND_ENCAPSULATED | ||
50 | * - interrupt-in: RESPONSE_AVAILABLE | ||
51 | * - control-in: GET_ENCAPSULATED | ||
52 | * | ||
53 | * We'll try to ignore the RESPONSE_AVAILABLE notifications. | ||
54 | */ | ||
55 | struct rndis_msg_hdr { | ||
56 | __le32 msg_type; /* RNDIS_MSG_* */ | ||
57 | __le32 msg_len; | ||
58 | // followed by data that varies between messages | ||
59 | __le32 request_id; | ||
60 | __le32 status; | ||
61 | // ... and more | ||
62 | } __attribute__ ((packed)); | ||
63 | |||
64 | /* RNDIS defines this (absurdly huge) control timeout */ | ||
65 | #define RNDIS_CONTROL_TIMEOUT_MS (10 * 1000) | ||
66 | |||
67 | |||
68 | #define ccpu2 __constant_cpu_to_le32 | ||
69 | |||
70 | #define RNDIS_MSG_COMPLETION ccpu2(0x80000000) | ||
71 | |||
72 | /* codes for "msg_type" field of rndis messages; | ||
73 | * only the data channel uses packet messages (maybe batched); | ||
74 | * everything else goes on the control channel. | ||
75 | */ | ||
76 | #define RNDIS_MSG_PACKET ccpu2(0x00000001) /* 1-N packets */ | ||
77 | #define RNDIS_MSG_INIT ccpu2(0x00000002) | ||
78 | #define RNDIS_MSG_INIT_C (RNDIS_MSG_INIT|RNDIS_MSG_COMPLETION) | ||
79 | #define RNDIS_MSG_HALT ccpu2(0x00000003) | ||
80 | #define RNDIS_MSG_QUERY ccpu2(0x00000004) | ||
81 | #define RNDIS_MSG_QUERY_C (RNDIS_MSG_QUERY|RNDIS_MSG_COMPLETION) | ||
82 | #define RNDIS_MSG_SET ccpu2(0x00000005) | ||
83 | #define RNDIS_MSG_SET_C (RNDIS_MSG_SET|RNDIS_MSG_COMPLETION) | ||
84 | #define RNDIS_MSG_RESET ccpu2(0x00000006) | ||
85 | #define RNDIS_MSG_RESET_C (RNDIS_MSG_RESET|RNDIS_MSG_COMPLETION) | ||
86 | #define RNDIS_MSG_INDICATE ccpu2(0x00000007) | ||
87 | #define RNDIS_MSG_KEEPALIVE ccpu2(0x00000008) | ||
88 | #define RNDIS_MSG_KEEPALIVE_C (RNDIS_MSG_KEEPALIVE|RNDIS_MSG_COMPLETION) | ||
89 | |||
90 | /* codes for "status" field of completion messages */ | ||
91 | #define RNDIS_STATUS_SUCCESS ccpu2(0x00000000) | ||
92 | #define RNDIS_STATUS_FAILURE ccpu2(0xc0000001) | ||
93 | #define RNDIS_STATUS_INVALID_DATA ccpu2(0xc0010015) | ||
94 | #define RNDIS_STATUS_NOT_SUPPORTED ccpu2(0xc00000bb) | ||
95 | #define RNDIS_STATUS_MEDIA_CONNECT ccpu2(0x4001000b) | ||
96 | #define RNDIS_STATUS_MEDIA_DISCONNECT ccpu2(0x4001000c) | ||
97 | |||
98 | |||
99 | struct rndis_data_hdr { | ||
100 | __le32 msg_type; /* RNDIS_MSG_PACKET */ | ||
101 | __le32 msg_len; // rndis_data_hdr + data_len + pad | ||
102 | __le32 data_offset; // 36 -- right after header | ||
103 | __le32 data_len; // ... real packet size | ||
104 | |||
105 | __le32 oob_data_offset; // zero | ||
106 | __le32 oob_data_len; // zero | ||
107 | __le32 num_oob; // zero | ||
108 | __le32 packet_data_offset; // zero | ||
109 | |||
110 | __le32 packet_data_len; // zero | ||
111 | __le32 vc_handle; // zero | ||
112 | __le32 reserved; // zero | ||
113 | } __attribute__ ((packed)); | ||
114 | |||
115 | struct rndis_init { /* OUT */ | ||
116 | // header and: | ||
117 | __le32 msg_type; /* RNDIS_MSG_INIT */ | ||
118 | __le32 msg_len; // 24 | ||
119 | __le32 request_id; | ||
120 | __le32 major_version; // of rndis (1.0) | ||
121 | __le32 minor_version; | ||
122 | __le32 max_transfer_size; | ||
123 | } __attribute__ ((packed)); | ||
124 | |||
125 | struct rndis_init_c { /* IN */ | ||
126 | // header and: | ||
127 | __le32 msg_type; /* RNDIS_MSG_INIT_C */ | ||
128 | __le32 msg_len; | ||
129 | __le32 request_id; | ||
130 | __le32 status; | ||
131 | __le32 major_version; // of rndis (1.0) | ||
132 | __le32 minor_version; | ||
133 | __le32 device_flags; | ||
134 | __le32 medium; // zero == 802.3 | ||
135 | __le32 max_packets_per_message; | ||
136 | __le32 max_transfer_size; | ||
137 | __le32 packet_alignment; // max 7; (1<<n) bytes | ||
138 | __le32 af_list_offset; // zero | ||
139 | __le32 af_list_size; // zero | ||
140 | } __attribute__ ((packed)); | ||
141 | |||
142 | struct rndis_halt { /* OUT (no reply) */ | ||
143 | // header and: | ||
144 | __le32 msg_type; /* RNDIS_MSG_HALT */ | ||
145 | __le32 msg_len; | ||
146 | __le32 request_id; | ||
147 | } __attribute__ ((packed)); | ||
148 | |||
149 | struct rndis_query { /* OUT */ | ||
150 | // header and: | ||
151 | __le32 msg_type; /* RNDIS_MSG_QUERY */ | ||
152 | __le32 msg_len; | ||
153 | __le32 request_id; | ||
154 | __le32 oid; | ||
155 | __le32 len; | ||
156 | __le32 offset; | ||
157 | /*?*/ __le32 handle; // zero | ||
158 | } __attribute__ ((packed)); | ||
159 | |||
160 | struct rndis_query_c { /* IN */ | ||
161 | // header and: | ||
162 | __le32 msg_type; /* RNDIS_MSG_QUERY_C */ | ||
163 | __le32 msg_len; | ||
164 | __le32 request_id; | ||
165 | __le32 status; | ||
166 | __le32 len; | ||
167 | __le32 offset; | ||
168 | } __attribute__ ((packed)); | ||
169 | |||
170 | struct rndis_set { /* OUT */ | ||
171 | // header and: | ||
172 | __le32 msg_type; /* RNDIS_MSG_SET */ | ||
173 | __le32 msg_len; | ||
174 | __le32 request_id; | ||
175 | __le32 oid; | ||
176 | __le32 len; | ||
177 | __le32 offset; | ||
178 | /*?*/ __le32 handle; // zero | ||
179 | } __attribute__ ((packed)); | ||
180 | |||
181 | struct rndis_set_c { /* IN */ | ||
182 | // header and: | ||
183 | __le32 msg_type; /* RNDIS_MSG_SET_C */ | ||
184 | __le32 msg_len; | ||
185 | __le32 request_id; | ||
186 | __le32 status; | ||
187 | } __attribute__ ((packed)); | ||
188 | |||
189 | struct rndis_reset { /* IN */ | ||
190 | // header and: | ||
191 | __le32 msg_type; /* RNDIS_MSG_RESET */ | ||
192 | __le32 msg_len; | ||
193 | __le32 reserved; | ||
194 | } __attribute__ ((packed)); | ||
195 | |||
196 | struct rndis_reset_c { /* OUT */ | ||
197 | // header and: | ||
198 | __le32 msg_type; /* RNDIS_MSG_RESET_C */ | ||
199 | __le32 msg_len; | ||
200 | __le32 status; | ||
201 | __le32 addressing_lost; | ||
202 | } __attribute__ ((packed)); | ||
203 | |||
204 | struct rndis_indicate { /* IN (unrequested) */ | ||
205 | // header and: | ||
206 | __le32 msg_type; /* RNDIS_MSG_INDICATE */ | ||
207 | __le32 msg_len; | ||
208 | __le32 status; | ||
209 | __le32 length; | ||
210 | __le32 offset; | ||
211 | /**/ __le32 diag_status; | ||
212 | __le32 error_offset; | ||
213 | /**/ __le32 message; | ||
214 | } __attribute__ ((packed)); | ||
215 | |||
216 | struct rndis_keepalive { /* OUT (optionally IN) */ | ||
217 | // header and: | ||
218 | __le32 msg_type; /* RNDIS_MSG_KEEPALIVE */ | ||
219 | __le32 msg_len; | ||
220 | __le32 request_id; | ||
221 | } __attribute__ ((packed)); | ||
222 | |||
223 | struct rndis_keepalive_c { /* IN (optionally OUT) */ | ||
224 | // header and: | ||
225 | __le32 msg_type; /* RNDIS_MSG_KEEPALIVE_C */ | ||
226 | __le32 msg_len; | ||
227 | __le32 request_id; | ||
228 | __le32 status; | ||
229 | } __attribute__ ((packed)); | ||
230 | |||
231 | /* NOTE: about 30 OIDs are "mandatory" for peripherals to support ... and | ||
232 | * there are gobs more that may optionally be supported. We'll avoid as much | ||
233 | * of that mess as possible. | ||
234 | */ | ||
235 | #define OID_802_3_PERMANENT_ADDRESS ccpu2(0x01010101) | ||
236 | #define OID_GEN_CURRENT_PACKET_FILTER ccpu2(0x0001010e) | ||
237 | |||
238 | /* | ||
239 | * RNDIS notifications from device: command completion; "reverse" | ||
240 | * keepalives; etc | ||
241 | */ | ||
242 | static void rndis_status(struct usbnet *dev, struct urb *urb) | ||
243 | { | ||
244 | devdbg(dev, "rndis status urb, len %d stat %d", | ||
245 | urb->actual_length, urb->status); | ||
246 | // FIXME for keepalives, respond immediately (asynchronously) | ||
247 | // if not an RNDIS status, do like cdc_status(dev,urb) does | ||
248 | } | ||
249 | |||
250 | /* | ||
251 | * RPC done RNDIS-style. Caller guarantees: | ||
252 | * - message is properly byteswapped | ||
253 | * - there's no other request pending | ||
254 | * - buf can hold up to 1KB response (required by RNDIS spec) | ||
255 | * On return, the first few entries are already byteswapped. | ||
256 | * | ||
257 | * Call context is likely probe(), before interface name is known, | ||
258 | * which is why we won't try to use it in the diagnostics. | ||
259 | */ | ||
260 | static int rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf) | ||
261 | { | ||
262 | struct cdc_state *info = (void *) &dev->data; | ||
263 | int retval; | ||
264 | unsigned count; | ||
265 | __le32 rsp; | ||
266 | u32 xid = 0, msg_len, request_id; | ||
267 | |||
268 | /* REVISIT when this gets called from contexts other than probe() or | ||
269 | * disconnect(): either serialize, or dispatch responses on xid | ||
270 | */ | ||
271 | |||
272 | /* Issue the request; don't bother byteswapping our xid */ | ||
273 | if (likely(buf->msg_type != RNDIS_MSG_HALT | ||
274 | && buf->msg_type != RNDIS_MSG_RESET)) { | ||
275 | xid = dev->xid++; | ||
276 | if (!xid) | ||
277 | xid = dev->xid++; | ||
278 | buf->request_id = (__force __le32) xid; | ||
279 | } | ||
280 | retval = usb_control_msg(dev->udev, | ||
281 | usb_sndctrlpipe(dev->udev, 0), | ||
282 | USB_CDC_SEND_ENCAPSULATED_COMMAND, | ||
283 | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | ||
284 | 0, info->u->bMasterInterface0, | ||
285 | buf, le32_to_cpu(buf->msg_len), | ||
286 | RNDIS_CONTROL_TIMEOUT_MS); | ||
287 | if (unlikely(retval < 0 || xid == 0)) | ||
288 | return retval; | ||
289 | |||
290 | // FIXME Seems like some devices discard responses when | ||
291 | // we time out and cancel our "get response" requests... | ||
292 | // so, this is fragile. Probably need to poll for status. | ||
293 | |||
294 | /* ignore status endpoint, just poll the control channel; | ||
295 | * the request probably completed immediately | ||
296 | */ | ||
297 | rsp = buf->msg_type | RNDIS_MSG_COMPLETION; | ||
298 | for (count = 0; count < 10; count++) { | ||
299 | memset(buf, 0, 1024); | ||
300 | retval = usb_control_msg(dev->udev, | ||
301 | usb_rcvctrlpipe(dev->udev, 0), | ||
302 | USB_CDC_GET_ENCAPSULATED_RESPONSE, | ||
303 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | ||
304 | 0, info->u->bMasterInterface0, | ||
305 | buf, 1024, | ||
306 | RNDIS_CONTROL_TIMEOUT_MS); | ||
307 | if (likely(retval >= 8)) { | ||
308 | msg_len = le32_to_cpu(buf->msg_len); | ||
309 | request_id = (__force u32) buf->request_id; | ||
310 | if (likely(buf->msg_type == rsp)) { | ||
311 | if (likely(request_id == xid)) { | ||
312 | if (unlikely(rsp == RNDIS_MSG_RESET_C)) | ||
313 | return 0; | ||
314 | if (likely(RNDIS_STATUS_SUCCESS | ||
315 | == buf->status)) | ||
316 | return 0; | ||
317 | dev_dbg(&info->control->dev, | ||
318 | "rndis reply status %08x\n", | ||
319 | le32_to_cpu(buf->status)); | ||
320 | return -EL3RST; | ||
321 | } | ||
322 | dev_dbg(&info->control->dev, | ||
323 | "rndis reply id %d expected %d\n", | ||
324 | request_id, xid); | ||
325 | /* then likely retry */ | ||
326 | } else switch (buf->msg_type) { | ||
327 | case RNDIS_MSG_INDICATE: { /* fault */ | ||
328 | // struct rndis_indicate *msg = (void *)buf; | ||
329 | dev_info(&info->control->dev, | ||
330 | "rndis fault indication\n"); | ||
331 | } | ||
332 | break; | ||
333 | case RNDIS_MSG_KEEPALIVE: { /* ping */ | ||
334 | struct rndis_keepalive_c *msg = (void *)buf; | ||
335 | |||
336 | msg->msg_type = RNDIS_MSG_KEEPALIVE_C; | ||
337 | msg->msg_len = ccpu2(sizeof *msg); | ||
338 | msg->status = RNDIS_STATUS_SUCCESS; | ||
339 | retval = usb_control_msg(dev->udev, | ||
340 | usb_sndctrlpipe(dev->udev, 0), | ||
341 | USB_CDC_SEND_ENCAPSULATED_COMMAND, | ||
342 | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | ||
343 | 0, info->u->bMasterInterface0, | ||
344 | msg, sizeof *msg, | ||
345 | RNDIS_CONTROL_TIMEOUT_MS); | ||
346 | if (unlikely(retval < 0)) | ||
347 | dev_dbg(&info->control->dev, | ||
348 | "rndis keepalive err %d\n", | ||
349 | retval); | ||
350 | } | ||
351 | break; | ||
352 | default: | ||
353 | dev_dbg(&info->control->dev, | ||
354 | "unexpected rndis msg %08x len %d\n", | ||
355 | le32_to_cpu(buf->msg_type), msg_len); | ||
356 | } | ||
357 | } else { | ||
358 | /* device probably issued a protocol stall; ignore */ | ||
359 | dev_dbg(&info->control->dev, | ||
360 | "rndis response error, code %d\n", retval); | ||
361 | } | ||
362 | msleep(2); | ||
363 | } | ||
364 | dev_dbg(&info->control->dev, "rndis response timeout\n"); | ||
365 | return -ETIMEDOUT; | ||
366 | } | ||
367 | |||
368 | static int rndis_bind(struct usbnet *dev, struct usb_interface *intf) | ||
369 | { | ||
370 | int retval; | ||
371 | struct net_device *net = dev->net; | ||
372 | union { | ||
373 | void *buf; | ||
374 | struct rndis_msg_hdr *header; | ||
375 | struct rndis_init *init; | ||
376 | struct rndis_init_c *init_c; | ||
377 | struct rndis_query *get; | ||
378 | struct rndis_query_c *get_c; | ||
379 | struct rndis_set *set; | ||
380 | struct rndis_set_c *set_c; | ||
381 | } u; | ||
382 | u32 tmp; | ||
383 | |||
384 | /* we can't rely on i/o from stack working, or stack allocation */ | ||
385 | u.buf = kmalloc(1024, GFP_KERNEL); | ||
386 | if (!u.buf) | ||
387 | return -ENOMEM; | ||
388 | retval = usbnet_generic_cdc_bind(dev, intf); | ||
389 | if (retval < 0) | ||
390 | goto done; | ||
391 | |||
392 | net->hard_header_len += sizeof (struct rndis_data_hdr); | ||
393 | |||
394 | /* initialize; max transfer is 16KB at full speed */ | ||
395 | u.init->msg_type = RNDIS_MSG_INIT; | ||
396 | u.init->msg_len = ccpu2(sizeof *u.init); | ||
397 | u.init->major_version = ccpu2(1); | ||
398 | u.init->minor_version = ccpu2(0); | ||
399 | u.init->max_transfer_size = ccpu2(net->mtu + net->hard_header_len); | ||
400 | |||
401 | retval = rndis_command(dev, u.header); | ||
402 | if (unlikely(retval < 0)) { | ||
403 | /* it might not even be an RNDIS device!! */ | ||
404 | dev_err(&intf->dev, "RNDIS init failed, %d\n", retval); | ||
405 | fail: | ||
406 | usb_driver_release_interface(driver_of(intf), | ||
407 | ((struct cdc_state *)&(dev->data))->data); | ||
408 | goto done; | ||
409 | } | ||
410 | dev->hard_mtu = le32_to_cpu(u.init_c->max_transfer_size); | ||
411 | /* REVISIT: peripheral "alignment" request is ignored ... */ | ||
412 | dev_dbg(&intf->dev, "hard mtu %u, align %d\n", dev->hard_mtu, | ||
413 | 1 << le32_to_cpu(u.init_c->packet_alignment)); | ||
414 | |||
415 | /* get designated host ethernet address */ | ||
416 | memset(u.get, 0, sizeof *u.get); | ||
417 | u.get->msg_type = RNDIS_MSG_QUERY; | ||
418 | u.get->msg_len = ccpu2(sizeof *u.get); | ||
419 | u.get->oid = OID_802_3_PERMANENT_ADDRESS; | ||
420 | |||
421 | retval = rndis_command(dev, u.header); | ||
422 | if (unlikely(retval < 0)) { | ||
423 | dev_err(&intf->dev, "rndis get ethaddr, %d\n", retval); | ||
424 | goto fail; | ||
425 | } | ||
426 | tmp = le32_to_cpu(u.get_c->offset); | ||
427 | if (unlikely((tmp + 8) > (1024 - ETH_ALEN) | ||
428 | || u.get_c->len != ccpu2(ETH_ALEN))) { | ||
429 | dev_err(&intf->dev, "rndis ethaddr off %d len %d ?\n", | ||
430 | tmp, le32_to_cpu(u.get_c->len)); | ||
431 | retval = -EDOM; | ||
432 | goto fail; | ||
433 | } | ||
434 | memcpy(net->dev_addr, tmp + (char *)&u.get_c->request_id, ETH_ALEN); | ||
435 | |||
436 | /* set a nonzero filter to enable data transfers */ | ||
437 | memset(u.set, 0, sizeof *u.set); | ||
438 | u.set->msg_type = RNDIS_MSG_SET; | ||
439 | u.set->msg_len = ccpu2(4 + sizeof *u.set); | ||
440 | u.set->oid = OID_GEN_CURRENT_PACKET_FILTER; | ||
441 | u.set->len = ccpu2(4); | ||
442 | u.set->offset = ccpu2((sizeof *u.set) - 8); | ||
443 | *(__le32 *)(u.buf + sizeof *u.set) = ccpu2(DEFAULT_FILTER); | ||
444 | |||
445 | retval = rndis_command(dev, u.header); | ||
446 | if (unlikely(retval < 0)) { | ||
447 | dev_err(&intf->dev, "rndis set packet filter, %d\n", retval); | ||
448 | goto fail; | ||
449 | } | ||
450 | |||
451 | retval = 0; | ||
452 | done: | ||
453 | kfree(u.buf); | ||
454 | return retval; | ||
455 | } | ||
456 | |||
457 | static void rndis_unbind(struct usbnet *dev, struct usb_interface *intf) | ||
458 | { | ||
459 | struct rndis_halt *halt; | ||
460 | |||
461 | /* try to clear any rndis state/activity (no i/o from stack!) */ | ||
462 | halt = kcalloc(1, sizeof *halt, SLAB_KERNEL); | ||
463 | if (halt) { | ||
464 | halt->msg_type = RNDIS_MSG_HALT; | ||
465 | halt->msg_len = ccpu2(sizeof *halt); | ||
466 | (void) rndis_command(dev, (void *)halt); | ||
467 | kfree(halt); | ||
468 | } | ||
469 | |||
470 | return usbnet_cdc_unbind(dev, intf); | ||
471 | } | ||
472 | |||
473 | /* | ||
474 | * DATA -- host must not write zlps | ||
475 | */ | ||
476 | static int rndis_rx_fixup(struct usbnet *dev, struct sk_buff *skb) | ||
477 | { | ||
478 | /* peripheral may have batched packets to us... */ | ||
479 | while (likely(skb->len)) { | ||
480 | struct rndis_data_hdr *hdr = (void *)skb->data; | ||
481 | struct sk_buff *skb2; | ||
482 | u32 msg_len, data_offset, data_len; | ||
483 | |||
484 | msg_len = le32_to_cpu(hdr->msg_len); | ||
485 | data_offset = le32_to_cpu(hdr->data_offset); | ||
486 | data_len = le32_to_cpu(hdr->data_len); | ||
487 | |||
488 | /* don't choke if we see oob, per-packet data, etc */ | ||
489 | if (unlikely(hdr->msg_type != RNDIS_MSG_PACKET | ||
490 | || skb->len < msg_len | ||
491 | || (data_offset + data_len + 8) > msg_len)) { | ||
492 | dev->stats.rx_frame_errors++; | ||
493 | devdbg(dev, "bad rndis message %d/%d/%d/%d, len %d", | ||
494 | le32_to_cpu(hdr->msg_type), | ||
495 | msg_len, data_offset, data_len, skb->len); | ||
496 | return 0; | ||
497 | } | ||
498 | skb_pull(skb, 8 + data_offset); | ||
499 | |||
500 | /* at most one packet left? */ | ||
501 | if (likely((data_len - skb->len) <= sizeof *hdr)) { | ||
502 | skb_trim(skb, data_len); | ||
503 | break; | ||
504 | } | ||
505 | |||
506 | /* try to return all the packets in the batch */ | ||
507 | skb2 = skb_clone(skb, GFP_ATOMIC); | ||
508 | if (unlikely(!skb2)) | ||
509 | break; | ||
510 | skb_pull(skb, msg_len - sizeof *hdr); | ||
511 | skb_trim(skb2, data_len); | ||
512 | usbnet_skb_return(dev, skb2); | ||
513 | } | ||
514 | |||
515 | /* caller will usbnet_skb_return the remaining packet */ | ||
516 | return 1; | ||
517 | } | ||
518 | |||
519 | static struct sk_buff * | ||
520 | rndis_tx_fixup(struct usbnet *dev, struct sk_buff *skb, unsigned flags) | ||
521 | { | ||
522 | struct rndis_data_hdr *hdr; | ||
523 | struct sk_buff *skb2; | ||
524 | unsigned len = skb->len; | ||
525 | |||
526 | if (likely(!skb_cloned(skb))) { | ||
527 | int room = skb_headroom(skb); | ||
528 | |||
529 | /* enough head room as-is? */ | ||
530 | if (unlikely((sizeof *hdr) <= room)) | ||
531 | goto fill; | ||
532 | |||
533 | /* enough room, but needs to be readjusted? */ | ||
534 | room += skb_tailroom(skb); | ||
535 | if (likely((sizeof *hdr) <= room)) { | ||
536 | skb->data = memmove(skb->head + sizeof *hdr, | ||
537 | skb->data, len); | ||
538 | skb->tail = skb->data + len; | ||
539 | goto fill; | ||
540 | } | ||
541 | } | ||
542 | |||
543 | /* create a new skb, with the correct size (and tailpad) */ | ||
544 | skb2 = skb_copy_expand(skb, sizeof *hdr, 1, flags); | ||
545 | dev_kfree_skb_any(skb); | ||
546 | if (unlikely(!skb2)) | ||
547 | return skb2; | ||
548 | skb = skb2; | ||
549 | |||
550 | /* fill out the RNDIS header. we won't bother trying to batch | ||
551 | * packets; Linux minimizes wasted bandwidth through tx queues. | ||
552 | */ | ||
553 | fill: | ||
554 | hdr = (void *) __skb_push(skb, sizeof *hdr); | ||
555 | memset(hdr, 0, sizeof *hdr); | ||
556 | hdr->msg_type = RNDIS_MSG_PACKET; | ||
557 | hdr->msg_len = cpu_to_le32(skb->len); | ||
558 | hdr->data_offset = ccpu2(sizeof(*hdr) - 8); | ||
559 | hdr->data_len = cpu_to_le32(len); | ||
560 | |||
561 | /* FIXME make the last packet always be short ... */ | ||
562 | return skb; | ||
563 | } | ||
564 | |||
565 | |||
566 | static const struct driver_info rndis_info = { | ||
567 | .description = "RNDIS device", | ||
568 | .flags = FLAG_ETHER | FLAG_FRAMING_RN, | ||
569 | .bind = rndis_bind, | ||
570 | .unbind = rndis_unbind, | ||
571 | .status = rndis_status, | ||
572 | .rx_fixup = rndis_rx_fixup, | ||
573 | .tx_fixup = rndis_tx_fixup, | ||
574 | }; | ||
575 | |||
576 | #undef ccpu2 | ||
577 | |||
578 | |||
579 | /*-------------------------------------------------------------------------*/ | ||
580 | |||
581 | static const struct usb_device_id products [] = { | ||
582 | { | ||
583 | /* RNDIS is MSFT's un-official variant of CDC ACM */ | ||
584 | USB_INTERFACE_INFO(USB_CLASS_COMM, 2 /* ACM */, 0x0ff), | ||
585 | .driver_info = (unsigned long) &rndis_info, | ||
586 | }, | ||
587 | { }, // END | ||
588 | }; | ||
589 | MODULE_DEVICE_TABLE(usb, products); | ||
590 | |||
591 | static struct usb_driver rndis_driver = { | ||
592 | .owner = THIS_MODULE, | ||
593 | .name = "rndis_host", | ||
594 | .id_table = products, | ||
595 | .probe = usbnet_probe, | ||
596 | .disconnect = usbnet_disconnect, | ||
597 | .suspend = usbnet_suspend, | ||
598 | .resume = usbnet_resume, | ||
599 | }; | ||
600 | |||
601 | static int __init rndis_init(void) | ||
602 | { | ||
603 | return usb_register(&rndis_driver); | ||
604 | } | ||
605 | module_init(rndis_init); | ||
606 | |||
607 | static void __exit rndis_exit(void) | ||
608 | { | ||
609 | usb_deregister(&rndis_driver); | ||
610 | } | ||
611 | module_exit(rndis_exit); | ||
612 | |||
613 | MODULE_AUTHOR("David Brownell"); | ||
614 | MODULE_DESCRIPTION("USB Host side RNDIS driver"); | ||
615 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/net/rtl8150.c b/drivers/usb/net/rtl8150.c index 59ab40ebb394..c3d4e3589e30 100644 --- a/drivers/usb/net/rtl8150.c +++ b/drivers/usb/net/rtl8150.c | |||
@@ -653,7 +653,6 @@ static void rtl8150_tx_timeout(struct net_device *netdev) | |||
653 | { | 653 | { |
654 | rtl8150_t *dev = netdev_priv(netdev); | 654 | rtl8150_t *dev = netdev_priv(netdev); |
655 | warn("%s: Tx timeout.", netdev->name); | 655 | warn("%s: Tx timeout.", netdev->name); |
656 | dev->tx_urb->transfer_flags |= URB_ASYNC_UNLINK; | ||
657 | usb_unlink_urb(dev->tx_urb); | 656 | usb_unlink_urb(dev->tx_urb); |
658 | dev->stats.tx_errors++; | 657 | dev->stats.tx_errors++; |
659 | } | 658 | } |
diff --git a/drivers/usb/net/usbnet.c b/drivers/usb/net/usbnet.c index a2f67245f6da..6c460918d54f 100644 --- a/drivers/usb/net/usbnet.c +++ b/drivers/usb/net/usbnet.c | |||
@@ -1,10 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * USB Networking Links | 2 | * USB Network driver infrastructure |
3 | * Copyright (C) 2000-2005 by David Brownell <dbrownell@users.sourceforge.net> | 3 | * Copyright (C) 2000-2005 by David Brownell |
4 | * Copyright (C) 2002 Pavel Machek <pavel@ucw.cz> | ||
5 | * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com> | 4 | * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com> |
6 | * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net> | ||
7 | * Copyright (c) 2002-2003 TiVo Inc. | ||
8 | * | 5 | * |
9 | * This program is free software; you can redistribute it and/or modify | 6 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by | 7 | * it under the terms of the GNU General Public License as published by |
@@ -23,95 +20,15 @@ | |||
23 | 20 | ||
24 | /* | 21 | /* |
25 | * This is a generic "USB networking" framework that works with several | 22 | * This is a generic "USB networking" framework that works with several |
26 | * kinds of full and high speed networking devices: | 23 | * kinds of full and high speed networking devices: host-to-host cables, |
27 | * | 24 | * smart usb peripherals, and actual Ethernet adapters. |
28 | * + USB host-to-host "network cables", used for IP-over-USB links. | 25 | * |
29 | * These are often used for Laplink style connectivity products. | 26 | * These devices usually differ in terms of control protocols (if they |
30 | * - AnchorChip 2720 | 27 | * even have one!) and sometimes they define new framing to wrap or batch |
31 | * - Belkin, eTEK (interops with Win32 drivers) | 28 | * Ethernet packets. Otherwise, they talk to USB pretty much the same, |
32 | * - GeneSys GL620USB-A | 29 | * so interface (un)binding, endpoint I/O queues, fault handling, and other |
33 | * - NetChip 1080 (interoperates with NetChip Win32 drivers) | 30 | * issues can usefully be addressed by this framework. |
34 | * - Prolific PL-2301/2302 (replaces "plusb" driver) | 31 | */ |
35 | * - KC Technology KC2190 | ||
36 | * | ||
37 | * + Smart USB devices can support such links directly, using Internet | ||
38 | * standard protocols instead of proprietary host-to-device links. | ||
39 | * - Linux PDAs like iPaq, Yopy, and Zaurus | ||
40 | * - The BLOB boot loader (for diskless booting) | ||
41 | * - Linux "gadgets", perhaps using PXA-2xx or Net2280 controllers | ||
42 | * - Devices using EPSON's sample USB firmware | ||
43 | * - CDC-Ethernet class devices, such as many cable modems | ||
44 | * | ||
45 | * + Adapters to networks such as Ethernet. | ||
46 | * - AX8817X based USB 2.0 products | ||
47 | * | ||
48 | * Links to these devices can be bridged using Linux Ethernet bridging. | ||
49 | * With minor exceptions, these all use similar USB framing for network | ||
50 | * traffic, but need different protocols for control traffic. | ||
51 | * | ||
52 | * USB devices can implement their side of this protocol at the cost | ||
53 | * of two bulk endpoints; it's not restricted to "cable" applications. | ||
54 | * See the SA1110, Zaurus, or EPSON device/client support in this driver; | ||
55 | * slave/target drivers such as "usb-eth" (on most SA-1100 PDAs) or | ||
56 | * "g_ether" (in the Linux "gadget" framework) implement that behavior | ||
57 | * within devices. | ||
58 | * | ||
59 | * | ||
60 | * CHANGELOG: | ||
61 | * | ||
62 | * 13-sep-2000 experimental, new | ||
63 | * 10-oct-2000 usb_device_id table created. | ||
64 | * 28-oct-2000 misc fixes; mostly, discard more TTL-mangled rx packets. | ||
65 | * 01-nov-2000 usb_device_id table and probing api update by | ||
66 | * Adam J. Richter <adam@yggdrasil.com>. | ||
67 | * 18-dec-2000 (db) tx watchdog, "net1080" renaming to "usbnet", device_info | ||
68 | * and prolific support, isolate net1080-specific bits, cleanup. | ||
69 | * fix unlink_urbs oops in D3 PM resume code path. | ||
70 | * | ||
71 | * 02-feb-2001 (db) fix tx skb sharing, packet length, match_flags, ... | ||
72 | * 08-feb-2001 stubbed in "linuxdev", maybe the SA-1100 folk can use it; | ||
73 | * AnchorChips 2720 support (from spec) for testing; | ||
74 | * fix bit-ordering problem with ethernet multicast addr | ||
75 | * 19-feb-2001 Support for clearing halt conditions. SA1100 UDC support | ||
76 | * updates. Oleg Drokin (green@iXcelerator.com) | ||
77 | * 25-mar-2001 More SA-1100 updates, including workaround for ip problem | ||
78 | * expecting cleared skb->cb and framing change to match latest | ||
79 | * handhelds.org version (Oleg). Enable device IDs from the | ||
80 | * Win32 Belkin driver; other cleanups (db). | ||
81 | * 16-jul-2001 Bugfixes for uhci oops-on-unplug, Belkin support, various | ||
82 | * cleanups for problems not yet seen in the field. (db) | ||
83 | * 17-oct-2001 Handle "Advance USBNET" product, like Belkin/eTEK devices, | ||
84 | * from Ioannis Mavroukakis <i.mavroukakis@btinternet.com>; | ||
85 | * rx unlinks somehow weren't async; minor cleanup. | ||
86 | * 03-nov-2001 Merged GeneSys driver; original code from Jiun-Jie Huang | ||
87 | * <huangjj@genesyslogic.com.tw>, updated by Stanislav Brabec | ||
88 | * <utx@penguin.cz>. Made framing options (NetChip/GeneSys) | ||
89 | * tie mostly to (sub)driver info. Workaround some PL-2302 | ||
90 | * chips that seem to reject SET_INTERFACE requests. | ||
91 | * | ||
92 | * 06-apr-2002 Added ethtool support, based on a patch from Brad Hards. | ||
93 | * Level of diagnostics is more configurable; they use device | ||
94 | * location (usb_device->devpath) instead of address (2.5). | ||
95 | * For tx_fixup, memflags can't be NOIO. | ||
96 | * 07-may-2002 Generalize/cleanup keventd support, handling rx stalls (mostly | ||
97 | * for USB 2.0 TTs) and memory shortages (potential) too. (db) | ||
98 | * Use "locally assigned" IEEE802 address space. (Brad Hards) | ||
99 | * 18-oct-2002 Support for Zaurus (Pavel Machek), related cleanup (db). | ||
100 | * 14-dec-2002 Remove Zaurus-private crc32 code (Pavel); 2.5 oops fix, | ||
101 | * cleanups and stubbed PXA-250 support (db), fix for framing | ||
102 | * issues on Z, net1080, and gl620a (Toby Milne) | ||
103 | * | ||
104 | * 31-mar-2003 Use endpoint descriptors: high speed support, simpler sa1100 | ||
105 | * vs pxa25x, and CDC Ethernet. Throttle down log floods on | ||
106 | * disconnect; other cleanups. (db) Flush net1080 fifos | ||
107 | * after several sequential framing errors. (Johannes Erdfelt) | ||
108 | * 22-aug-2003 AX8817X support (Dave Hollis). | ||
109 | * 14-jun-2004 Trivial patch for AX8817X based Buffalo LUA-U2-KTX in Japan | ||
110 | * (Neil Bortnak) | ||
111 | * 03-nov-2004 Trivial patch for KC2190 (KC-190) chip. (Jonathan McDowell) | ||
112 | * | ||
113 | * 01-feb-2005 AX88772 support (Phil Chang & Dave Hollis) | ||
114 | *-------------------------------------------------------------------------*/ | ||
115 | 32 | ||
116 | // #define DEBUG // error path messages, extra info | 33 | // #define DEBUG // error path messages, extra info |
117 | // #define VERBOSE // more; success messages | 34 | // #define VERBOSE // more; success messages |
@@ -121,24 +38,18 @@ | |||
121 | # define DEBUG | 38 | # define DEBUG |
122 | #endif | 39 | #endif |
123 | #include <linux/module.h> | 40 | #include <linux/module.h> |
124 | #include <linux/kmod.h> | ||
125 | #include <linux/sched.h> | 41 | #include <linux/sched.h> |
126 | #include <linux/init.h> | 42 | #include <linux/init.h> |
127 | #include <linux/netdevice.h> | 43 | #include <linux/netdevice.h> |
128 | #include <linux/etherdevice.h> | 44 | #include <linux/etherdevice.h> |
129 | #include <linux/random.h> | ||
130 | #include <linux/ethtool.h> | 45 | #include <linux/ethtool.h> |
131 | #include <linux/workqueue.h> | 46 | #include <linux/workqueue.h> |
132 | #include <linux/mii.h> | 47 | #include <linux/mii.h> |
133 | #include <asm/uaccess.h> | ||
134 | #include <asm/unaligned.h> | ||
135 | #include <linux/usb.h> | 48 | #include <linux/usb.h> |
136 | #include <asm/io.h> | ||
137 | #include <asm/scatterlist.h> | ||
138 | #include <linux/mm.h> | ||
139 | #include <linux/dma-mapping.h> | ||
140 | 49 | ||
141 | #define DRIVER_VERSION "03-Nov-2004" | 50 | #include "usbnet.h" |
51 | |||
52 | #define DRIVER_VERSION "22-Aug-2005" | ||
142 | 53 | ||
143 | 54 | ||
144 | /*-------------------------------------------------------------------------*/ | 55 | /*-------------------------------------------------------------------------*/ |
@@ -149,15 +60,14 @@ | |||
149 | * One maximum size Ethernet packet takes twenty four of them. | 60 | * One maximum size Ethernet packet takes twenty four of them. |
150 | * For high speed, each frame comfortably fits almost 36 max size | 61 | * For high speed, each frame comfortably fits almost 36 max size |
151 | * Ethernet packets (so queues should be bigger). | 62 | * Ethernet packets (so queues should be bigger). |
63 | * | ||
64 | * REVISIT qlens should be members of 'struct usbnet'; the goal is to | ||
65 | * let the USB host controller be busy for 5msec or more before an irq | ||
66 | * is required, under load. Jumbograms change the equation. | ||
152 | */ | 67 | */ |
153 | #define RX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4) | 68 | #define RX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4) |
154 | #define TX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4) | 69 | #define TX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4) |
155 | 70 | ||
156 | // packets are always ethernet inside | ||
157 | // ... except they can be bigger (limit of 64K with NetChip framing) | ||
158 | #define MIN_PACKET sizeof(struct ethhdr) | ||
159 | #define MAX_PACKET 32768 | ||
160 | |||
161 | // reawaken network queue this soon after stopping; else watchdog barks | 71 | // reawaken network queue this soon after stopping; else watchdog barks |
162 | #define TX_TIMEOUT_JIFFIES (5*HZ) | 72 | #define TX_TIMEOUT_JIFFIES (5*HZ) |
163 | 73 | ||
@@ -165,9 +75,6 @@ | |||
165 | // us (it polls at HZ/4 usually) before we report too many false errors. | 75 | // us (it polls at HZ/4 usually) before we report too many false errors. |
166 | #define THROTTLE_JIFFIES (HZ/8) | 76 | #define THROTTLE_JIFFIES (HZ/8) |
167 | 77 | ||
168 | // for vendor-specific control operations | ||
169 | #define CONTROL_TIMEOUT_MS 500 | ||
170 | |||
171 | // between wakeups | 78 | // between wakeups |
172 | #define UNLINK_TIMEOUT_MS 3 | 79 | #define UNLINK_TIMEOUT_MS 3 |
173 | 80 | ||
@@ -176,109 +83,6 @@ | |||
176 | // randomly generated ethernet address | 83 | // randomly generated ethernet address |
177 | static u8 node_id [ETH_ALEN]; | 84 | static u8 node_id [ETH_ALEN]; |
178 | 85 | ||
179 | // state we keep for each device we handle | ||
180 | struct usbnet { | ||
181 | // housekeeping | ||
182 | struct usb_device *udev; | ||
183 | struct driver_info *driver_info; | ||
184 | wait_queue_head_t *wait; | ||
185 | |||
186 | // i/o info: pipes etc | ||
187 | unsigned in, out; | ||
188 | struct usb_host_endpoint *status; | ||
189 | unsigned maxpacket; | ||
190 | struct timer_list delay; | ||
191 | |||
192 | // protocol/interface state | ||
193 | struct net_device *net; | ||
194 | struct net_device_stats stats; | ||
195 | int msg_enable; | ||
196 | unsigned long data [5]; | ||
197 | |||
198 | struct mii_if_info mii; | ||
199 | |||
200 | // various kinds of pending driver work | ||
201 | struct sk_buff_head rxq; | ||
202 | struct sk_buff_head txq; | ||
203 | struct sk_buff_head done; | ||
204 | struct urb *interrupt; | ||
205 | struct tasklet_struct bh; | ||
206 | |||
207 | struct work_struct kevent; | ||
208 | unsigned long flags; | ||
209 | # define EVENT_TX_HALT 0 | ||
210 | # define EVENT_RX_HALT 1 | ||
211 | # define EVENT_RX_MEMORY 2 | ||
212 | # define EVENT_STS_SPLIT 3 | ||
213 | # define EVENT_LINK_RESET 4 | ||
214 | }; | ||
215 | |||
216 | // device-specific info used by the driver | ||
217 | struct driver_info { | ||
218 | char *description; | ||
219 | |||
220 | int flags; | ||
221 | /* framing is CDC Ethernet, not writing ZLPs (hw issues), or optionally: */ | ||
222 | #define FLAG_FRAMING_NC 0x0001 /* guard against device dropouts */ | ||
223 | #define FLAG_FRAMING_GL 0x0002 /* genelink batches packets */ | ||
224 | #define FLAG_FRAMING_Z 0x0004 /* zaurus adds a trailer */ | ||
225 | #define FLAG_FRAMING_RN 0x0008 /* RNDIS batches, plus huge header */ | ||
226 | |||
227 | #define FLAG_NO_SETINT 0x0010 /* device can't set_interface() */ | ||
228 | #define FLAG_ETHER 0x0020 /* maybe use "eth%d" names */ | ||
229 | |||
230 | #define FLAG_FRAMING_AX 0x0040 /* AX88772/178 packets */ | ||
231 | |||
232 | /* init device ... can sleep, or cause probe() failure */ | ||
233 | int (*bind)(struct usbnet *, struct usb_interface *); | ||
234 | |||
235 | /* cleanup device ... can sleep, but can't fail */ | ||
236 | void (*unbind)(struct usbnet *, struct usb_interface *); | ||
237 | |||
238 | /* reset device ... can sleep */ | ||
239 | int (*reset)(struct usbnet *); | ||
240 | |||
241 | /* see if peer is connected ... can sleep */ | ||
242 | int (*check_connect)(struct usbnet *); | ||
243 | |||
244 | /* for status polling */ | ||
245 | void (*status)(struct usbnet *, struct urb *); | ||
246 | |||
247 | /* link reset handling, called from defer_kevent */ | ||
248 | int (*link_reset)(struct usbnet *); | ||
249 | |||
250 | /* fixup rx packet (strip framing) */ | ||
251 | int (*rx_fixup)(struct usbnet *dev, struct sk_buff *skb); | ||
252 | |||
253 | /* fixup tx packet (add framing) */ | ||
254 | struct sk_buff *(*tx_fixup)(struct usbnet *dev, | ||
255 | struct sk_buff *skb, int flags); | ||
256 | |||
257 | // FIXME -- also an interrupt mechanism | ||
258 | // useful for at least PL2301/2302 and GL620USB-A | ||
259 | // and CDC use them to report 'is it connected' changes | ||
260 | |||
261 | /* for new devices, use the descriptor-reading code instead */ | ||
262 | int in; /* rx endpoint */ | ||
263 | int out; /* tx endpoint */ | ||
264 | |||
265 | unsigned long data; /* Misc driver specific data */ | ||
266 | }; | ||
267 | |||
268 | // we record the state for each of our queued skbs | ||
269 | enum skb_state { | ||
270 | illegal = 0, | ||
271 | tx_start, tx_done, | ||
272 | rx_start, rx_done, rx_cleanup | ||
273 | }; | ||
274 | |||
275 | struct skb_data { // skb->cb is one of these | ||
276 | struct urb *urb; | ||
277 | struct usbnet *dev; | ||
278 | enum skb_state state; | ||
279 | size_t length; | ||
280 | }; | ||
281 | |||
282 | static const char driver_name [] = "usbnet"; | 86 | static const char driver_name [] = "usbnet"; |
283 | 87 | ||
284 | /* use ethtool to change the level for any given device */ | 88 | /* use ethtool to change the level for any given device */ |
@@ -286,39 +90,10 @@ static int msg_level = -1; | |||
286 | module_param (msg_level, int, 0); | 90 | module_param (msg_level, int, 0); |
287 | MODULE_PARM_DESC (msg_level, "Override default message level"); | 91 | MODULE_PARM_DESC (msg_level, "Override default message level"); |
288 | 92 | ||
289 | |||
290 | #ifdef DEBUG | ||
291 | #define devdbg(usbnet, fmt, arg...) \ | ||
292 | printk(KERN_DEBUG "%s: " fmt "\n" , (usbnet)->net->name , ## arg) | ||
293 | #else | ||
294 | #define devdbg(usbnet, fmt, arg...) do {} while(0) | ||
295 | #endif | ||
296 | |||
297 | #define deverr(usbnet, fmt, arg...) \ | ||
298 | printk(KERN_ERR "%s: " fmt "\n" , (usbnet)->net->name , ## arg) | ||
299 | #define devwarn(usbnet, fmt, arg...) \ | ||
300 | printk(KERN_WARNING "%s: " fmt "\n" , (usbnet)->net->name , ## arg) | ||
301 | |||
302 | #define devinfo(usbnet, fmt, arg...) \ | ||
303 | printk(KERN_INFO "%s: " fmt "\n" , (usbnet)->net->name , ## arg); \ | ||
304 | |||
305 | /*-------------------------------------------------------------------------*/ | 93 | /*-------------------------------------------------------------------------*/ |
306 | 94 | ||
307 | static void usbnet_get_drvinfo (struct net_device *, struct ethtool_drvinfo *); | ||
308 | static u32 usbnet_get_link (struct net_device *); | ||
309 | static u32 usbnet_get_msglevel (struct net_device *); | ||
310 | static void usbnet_set_msglevel (struct net_device *, u32); | ||
311 | static void defer_kevent (struct usbnet *, int); | ||
312 | |||
313 | /* mostly for PDA style devices, which are always connected if present */ | ||
314 | static int always_connected (struct usbnet *dev) | ||
315 | { | ||
316 | return 0; | ||
317 | } | ||
318 | |||
319 | /* handles CDC Ethernet and many other network "bulk data" interfaces */ | 95 | /* handles CDC Ethernet and many other network "bulk data" interfaces */ |
320 | static int | 96 | int usbnet_get_endpoints(struct usbnet *dev, struct usb_interface *intf) |
321 | get_endpoints (struct usbnet *dev, struct usb_interface *intf) | ||
322 | { | 97 | { |
323 | int tmp; | 98 | int tmp; |
324 | struct usb_host_interface *alt = NULL; | 99 | struct usb_host_interface *alt = NULL; |
@@ -382,6 +157,7 @@ get_endpoints (struct usbnet *dev, struct usb_interface *intf) | |||
382 | dev->status = status; | 157 | dev->status = status; |
383 | return 0; | 158 | return 0; |
384 | } | 159 | } |
160 | EXPORT_SYMBOL_GPL(usbnet_get_endpoints); | ||
385 | 161 | ||
386 | static void intr_complete (struct urb *urb, struct pt_regs *regs); | 162 | static void intr_complete (struct urb *urb, struct pt_regs *regs); |
387 | 163 | ||
@@ -421,7 +197,11 @@ static int init_status (struct usbnet *dev, struct usb_interface *intf) | |||
421 | return 0; | 197 | return 0; |
422 | } | 198 | } |
423 | 199 | ||
424 | static void skb_return (struct usbnet *dev, struct sk_buff *skb) | 200 | /* Passes this packet up the stack, updating its accounting. |
201 | * Some link protocols batch packets, so their rx_fixup paths | ||
202 | * can return clones as well as just modify the original skb. | ||
203 | */ | ||
204 | void usbnet_skb_return (struct usbnet *dev, struct sk_buff *skb) | ||
425 | { | 205 | { |
426 | int status; | 206 | int status; |
427 | 207 | ||
@@ -438,2425 +218,7 @@ static void skb_return (struct usbnet *dev, struct sk_buff *skb) | |||
438 | if (status != NET_RX_SUCCESS && netif_msg_rx_err (dev)) | 218 | if (status != NET_RX_SUCCESS && netif_msg_rx_err (dev)) |
439 | devdbg (dev, "netif_rx status %d", status); | 219 | devdbg (dev, "netif_rx status %d", status); |
440 | } | 220 | } |
441 | 221 | EXPORT_SYMBOL_GPL(usbnet_skb_return); | |
442 | |||
443 | #ifdef CONFIG_USB_ALI_M5632 | ||
444 | #define HAVE_HARDWARE | ||
445 | |||
446 | /*------------------------------------------------------------------------- | ||
447 | * | ||
448 | * ALi M5632 driver ... does high speed | ||
449 | * | ||
450 | *-------------------------------------------------------------------------*/ | ||
451 | |||
452 | static const struct driver_info ali_m5632_info = { | ||
453 | .description = "ALi M5632", | ||
454 | }; | ||
455 | |||
456 | |||
457 | #endif | ||
458 | |||
459 | |||
460 | #ifdef CONFIG_USB_AN2720 | ||
461 | #define HAVE_HARDWARE | ||
462 | |||
463 | /*------------------------------------------------------------------------- | ||
464 | * | ||
465 | * AnchorChips 2720 driver ... http://www.cypress.com | ||
466 | * | ||
467 | * This doesn't seem to have a way to detect whether the peer is | ||
468 | * connected, or need any reset handshaking. It's got pretty big | ||
469 | * internal buffers (handles most of a frame's worth of data). | ||
470 | * Chip data sheets don't describe any vendor control messages. | ||
471 | * | ||
472 | *-------------------------------------------------------------------------*/ | ||
473 | |||
474 | static const struct driver_info an2720_info = { | ||
475 | .description = "AnchorChips/Cypress 2720", | ||
476 | // no reset available! | ||
477 | // no check_connect available! | ||
478 | |||
479 | .in = 2, .out = 2, // direction distinguishes these | ||
480 | }; | ||
481 | |||
482 | #endif /* CONFIG_USB_AN2720 */ | ||
483 | |||
484 | |||
485 | #ifdef CONFIG_USB_AX8817X | ||
486 | /* ASIX AX8817X based USB 2.0 Ethernet Devices */ | ||
487 | |||
488 | #define HAVE_HARDWARE | ||
489 | #define NEED_MII | ||
490 | |||
491 | #include <linux/crc32.h> | ||
492 | |||
493 | #define AX_CMD_SET_SW_MII 0x06 | ||
494 | #define AX_CMD_READ_MII_REG 0x07 | ||
495 | #define AX_CMD_WRITE_MII_REG 0x08 | ||
496 | #define AX_CMD_SET_HW_MII 0x0a | ||
497 | #define AX_CMD_READ_EEPROM 0x0b | ||
498 | #define AX_CMD_WRITE_EEPROM 0x0c | ||
499 | #define AX_CMD_WRITE_ENABLE 0x0d | ||
500 | #define AX_CMD_WRITE_DISABLE 0x0e | ||
501 | #define AX_CMD_WRITE_RX_CTL 0x10 | ||
502 | #define AX_CMD_READ_IPG012 0x11 | ||
503 | #define AX_CMD_WRITE_IPG0 0x12 | ||
504 | #define AX_CMD_WRITE_IPG1 0x13 | ||
505 | #define AX_CMD_WRITE_IPG2 0x14 | ||
506 | #define AX_CMD_WRITE_MULTI_FILTER 0x16 | ||
507 | #define AX_CMD_READ_NODE_ID 0x17 | ||
508 | #define AX_CMD_READ_PHY_ID 0x19 | ||
509 | #define AX_CMD_READ_MEDIUM_STATUS 0x1a | ||
510 | #define AX_CMD_WRITE_MEDIUM_MODE 0x1b | ||
511 | #define AX_CMD_READ_MONITOR_MODE 0x1c | ||
512 | #define AX_CMD_WRITE_MONITOR_MODE 0x1d | ||
513 | #define AX_CMD_WRITE_GPIOS 0x1f | ||
514 | #define AX_CMD_SW_RESET 0x20 | ||
515 | #define AX_CMD_SW_PHY_STATUS 0x21 | ||
516 | #define AX_CMD_SW_PHY_SELECT 0x22 | ||
517 | #define AX88772_CMD_READ_NODE_ID 0x13 | ||
518 | |||
519 | #define AX_MONITOR_MODE 0x01 | ||
520 | #define AX_MONITOR_LINK 0x02 | ||
521 | #define AX_MONITOR_MAGIC 0x04 | ||
522 | #define AX_MONITOR_HSFS 0x10 | ||
523 | |||
524 | /* AX88172 Medium Status Register values */ | ||
525 | #define AX_MEDIUM_FULL_DUPLEX 0x02 | ||
526 | #define AX_MEDIUM_TX_ABORT_ALLOW 0x04 | ||
527 | #define AX_MEDIUM_FLOW_CONTROL_EN 0x10 | ||
528 | |||
529 | #define AX_MCAST_FILTER_SIZE 8 | ||
530 | #define AX_MAX_MCAST 64 | ||
531 | |||
532 | #define AX_EEPROM_LEN 0x40 | ||
533 | |||
534 | #define AX_SWRESET_CLEAR 0x00 | ||
535 | #define AX_SWRESET_RR 0x01 | ||
536 | #define AX_SWRESET_RT 0x02 | ||
537 | #define AX_SWRESET_PRTE 0x04 | ||
538 | #define AX_SWRESET_PRL 0x08 | ||
539 | #define AX_SWRESET_BZ 0x10 | ||
540 | #define AX_SWRESET_IPRL 0x20 | ||
541 | #define AX_SWRESET_IPPD 0x40 | ||
542 | |||
543 | #define AX88772_IPG0_DEFAULT 0x15 | ||
544 | #define AX88772_IPG1_DEFAULT 0x0c | ||
545 | #define AX88772_IPG2_DEFAULT 0x12 | ||
546 | |||
547 | #define AX88772_MEDIUM_FULL_DUPLEX 0x0002 | ||
548 | #define AX88772_MEDIUM_RESERVED 0x0004 | ||
549 | #define AX88772_MEDIUM_RX_FC_ENABLE 0x0010 | ||
550 | #define AX88772_MEDIUM_TX_FC_ENABLE 0x0020 | ||
551 | #define AX88772_MEDIUM_PAUSE_FORMAT 0x0080 | ||
552 | #define AX88772_MEDIUM_RX_ENABLE 0x0100 | ||
553 | #define AX88772_MEDIUM_100MB 0x0200 | ||
554 | #define AX88772_MEDIUM_DEFAULT \ | ||
555 | (AX88772_MEDIUM_FULL_DUPLEX | AX88772_MEDIUM_RX_FC_ENABLE | \ | ||
556 | AX88772_MEDIUM_TX_FC_ENABLE | AX88772_MEDIUM_100MB | \ | ||
557 | AX88772_MEDIUM_RESERVED | AX88772_MEDIUM_RX_ENABLE ) | ||
558 | |||
559 | #define AX_EEPROM_MAGIC 0xdeadbeef | ||
560 | |||
561 | /* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */ | ||
562 | struct ax8817x_data { | ||
563 | u8 multi_filter[AX_MCAST_FILTER_SIZE]; | ||
564 | }; | ||
565 | |||
566 | struct ax88172_int_data { | ||
567 | u16 res1; | ||
568 | u8 link; | ||
569 | u16 res2; | ||
570 | u8 status; | ||
571 | u16 res3; | ||
572 | } __attribute__ ((packed)); | ||
573 | |||
574 | static int ax8817x_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, | ||
575 | u16 size, void *data) | ||
576 | { | ||
577 | return usb_control_msg( | ||
578 | dev->udev, | ||
579 | usb_rcvctrlpipe(dev->udev, 0), | ||
580 | cmd, | ||
581 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
582 | value, | ||
583 | index, | ||
584 | data, | ||
585 | size, | ||
586 | CONTROL_TIMEOUT_MS); | ||
587 | } | ||
588 | |||
589 | static int ax8817x_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, | ||
590 | u16 size, void *data) | ||
591 | { | ||
592 | return usb_control_msg( | ||
593 | dev->udev, | ||
594 | usb_sndctrlpipe(dev->udev, 0), | ||
595 | cmd, | ||
596 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
597 | value, | ||
598 | index, | ||
599 | data, | ||
600 | size, | ||
601 | CONTROL_TIMEOUT_MS); | ||
602 | } | ||
603 | |||
604 | static void ax8817x_async_cmd_callback(struct urb *urb, struct pt_regs *regs) | ||
605 | { | ||
606 | struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context; | ||
607 | |||
608 | if (urb->status < 0) | ||
609 | printk(KERN_DEBUG "ax8817x_async_cmd_callback() failed with %d", | ||
610 | urb->status); | ||
611 | |||
612 | kfree(req); | ||
613 | usb_free_urb(urb); | ||
614 | } | ||
615 | |||
616 | static void ax8817x_status(struct usbnet *dev, struct urb *urb) | ||
617 | { | ||
618 | struct ax88172_int_data *event; | ||
619 | int link; | ||
620 | |||
621 | if (urb->actual_length < 8) | ||
622 | return; | ||
623 | |||
624 | event = urb->transfer_buffer; | ||
625 | link = event->link & 0x01; | ||
626 | if (netif_carrier_ok(dev->net) != link) { | ||
627 | if (link) { | ||
628 | netif_carrier_on(dev->net); | ||
629 | defer_kevent (dev, EVENT_LINK_RESET ); | ||
630 | } else | ||
631 | netif_carrier_off(dev->net); | ||
632 | devdbg(dev, "ax8817x - Link Status is: %d", link); | ||
633 | } | ||
634 | } | ||
635 | |||
636 | static void ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index, | ||
637 | u16 size, void *data) | ||
638 | { | ||
639 | struct usb_ctrlrequest *req; | ||
640 | int status; | ||
641 | struct urb *urb; | ||
642 | |||
643 | if ((urb = usb_alloc_urb(0, GFP_ATOMIC)) == NULL) { | ||
644 | devdbg(dev, "Error allocating URB in write_cmd_async!"); | ||
645 | return; | ||
646 | } | ||
647 | |||
648 | if ((req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC)) == NULL) { | ||
649 | deverr(dev, "Failed to allocate memory for control request"); | ||
650 | usb_free_urb(urb); | ||
651 | return; | ||
652 | } | ||
653 | |||
654 | req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE; | ||
655 | req->bRequest = cmd; | ||
656 | req->wValue = cpu_to_le16(value); | ||
657 | req->wIndex = cpu_to_le16(index); | ||
658 | req->wLength = cpu_to_le16(size); | ||
659 | |||
660 | usb_fill_control_urb(urb, dev->udev, | ||
661 | usb_sndctrlpipe(dev->udev, 0), | ||
662 | (void *)req, data, size, | ||
663 | ax8817x_async_cmd_callback, req); | ||
664 | |||
665 | if((status = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { | ||
666 | deverr(dev, "Error submitting the control message: status=%d", status); | ||
667 | kfree(req); | ||
668 | usb_free_urb(urb); | ||
669 | } | ||
670 | } | ||
671 | |||
672 | static void ax8817x_set_multicast(struct net_device *net) | ||
673 | { | ||
674 | struct usbnet *dev = netdev_priv(net); | ||
675 | struct ax8817x_data *data = (struct ax8817x_data *)&dev->data; | ||
676 | u8 rx_ctl = 0x8c; | ||
677 | |||
678 | if (net->flags & IFF_PROMISC) { | ||
679 | rx_ctl |= 0x01; | ||
680 | } else if (net->flags & IFF_ALLMULTI | ||
681 | || net->mc_count > AX_MAX_MCAST) { | ||
682 | rx_ctl |= 0x02; | ||
683 | } else if (net->mc_count == 0) { | ||
684 | /* just broadcast and directed */ | ||
685 | } else { | ||
686 | /* We use the 20 byte dev->data | ||
687 | * for our 8 byte filter buffer | ||
688 | * to avoid allocating memory that | ||
689 | * is tricky to free later */ | ||
690 | struct dev_mc_list *mc_list = net->mc_list; | ||
691 | u32 crc_bits; | ||
692 | int i; | ||
693 | |||
694 | memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE); | ||
695 | |||
696 | /* Build the multicast hash filter. */ | ||
697 | for (i = 0; i < net->mc_count; i++) { | ||
698 | crc_bits = | ||
699 | ether_crc(ETH_ALEN, | ||
700 | mc_list->dmi_addr) >> 26; | ||
701 | data->multi_filter[crc_bits >> 3] |= | ||
702 | 1 << (crc_bits & 7); | ||
703 | mc_list = mc_list->next; | ||
704 | } | ||
705 | |||
706 | ax8817x_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0, | ||
707 | AX_MCAST_FILTER_SIZE, data->multi_filter); | ||
708 | |||
709 | rx_ctl |= 0x10; | ||
710 | } | ||
711 | |||
712 | ax8817x_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL); | ||
713 | } | ||
714 | |||
715 | static int ax8817x_mdio_read(struct net_device *netdev, int phy_id, int loc) | ||
716 | { | ||
717 | struct usbnet *dev = netdev_priv(netdev); | ||
718 | u16 res; | ||
719 | u8 buf[1]; | ||
720 | |||
721 | ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf); | ||
722 | ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res); | ||
723 | ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf); | ||
724 | |||
725 | return res & 0xffff; | ||
726 | } | ||
727 | |||
728 | static void ax8817x_mdio_write(struct net_device *netdev, int phy_id, int loc, int val) | ||
729 | { | ||
730 | struct usbnet *dev = netdev_priv(netdev); | ||
731 | u16 res = val; | ||
732 | u8 buf[1]; | ||
733 | |||
734 | ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf); | ||
735 | ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res); | ||
736 | ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf); | ||
737 | } | ||
738 | |||
739 | static int ax88172_link_reset(struct usbnet *dev) | ||
740 | { | ||
741 | u16 lpa; | ||
742 | u8 mode; | ||
743 | |||
744 | mode = AX_MEDIUM_TX_ABORT_ALLOW | AX_MEDIUM_FLOW_CONTROL_EN; | ||
745 | lpa = ax8817x_mdio_read(dev->net, dev->mii.phy_id, MII_LPA); | ||
746 | if (lpa & LPA_DUPLEX) | ||
747 | mode |= AX_MEDIUM_FULL_DUPLEX; | ||
748 | ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL); | ||
749 | |||
750 | return 0; | ||
751 | } | ||
752 | |||
753 | static void ax8817x_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) | ||
754 | { | ||
755 | struct usbnet *dev = netdev_priv(net); | ||
756 | u8 opt; | ||
757 | |||
758 | if (ax8817x_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) { | ||
759 | wolinfo->supported = 0; | ||
760 | wolinfo->wolopts = 0; | ||
761 | return; | ||
762 | } | ||
763 | wolinfo->supported = WAKE_PHY | WAKE_MAGIC; | ||
764 | wolinfo->wolopts = 0; | ||
765 | if (opt & AX_MONITOR_MODE) { | ||
766 | if (opt & AX_MONITOR_LINK) | ||
767 | wolinfo->wolopts |= WAKE_PHY; | ||
768 | if (opt & AX_MONITOR_MAGIC) | ||
769 | wolinfo->wolopts |= WAKE_MAGIC; | ||
770 | } | ||
771 | } | ||
772 | |||
773 | static int ax8817x_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) | ||
774 | { | ||
775 | struct usbnet *dev = netdev_priv(net); | ||
776 | u8 opt = 0; | ||
777 | u8 buf[1]; | ||
778 | |||
779 | if (wolinfo->wolopts & WAKE_PHY) | ||
780 | opt |= AX_MONITOR_LINK; | ||
781 | if (wolinfo->wolopts & WAKE_MAGIC) | ||
782 | opt |= AX_MONITOR_MAGIC; | ||
783 | if (opt != 0) | ||
784 | opt |= AX_MONITOR_MODE; | ||
785 | |||
786 | if (ax8817x_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE, | ||
787 | opt, 0, 0, &buf) < 0) | ||
788 | return -EINVAL; | ||
789 | |||
790 | return 0; | ||
791 | } | ||
792 | |||
793 | static int ax8817x_get_eeprom_len(struct net_device *net) | ||
794 | { | ||
795 | return AX_EEPROM_LEN; | ||
796 | } | ||
797 | |||
798 | static int ax8817x_get_eeprom(struct net_device *net, | ||
799 | struct ethtool_eeprom *eeprom, u8 *data) | ||
800 | { | ||
801 | struct usbnet *dev = netdev_priv(net); | ||
802 | u16 *ebuf = (u16 *)data; | ||
803 | int i; | ||
804 | |||
805 | /* Crude hack to ensure that we don't overwrite memory | ||
806 | * if an odd length is supplied | ||
807 | */ | ||
808 | if (eeprom->len % 2) | ||
809 | return -EINVAL; | ||
810 | |||
811 | eeprom->magic = AX_EEPROM_MAGIC; | ||
812 | |||
813 | /* ax8817x returns 2 bytes from eeprom on read */ | ||
814 | for (i=0; i < eeprom->len / 2; i++) { | ||
815 | if (ax8817x_read_cmd(dev, AX_CMD_READ_EEPROM, | ||
816 | eeprom->offset + i, 0, 2, &ebuf[i]) < 0) | ||
817 | return -EINVAL; | ||
818 | } | ||
819 | return 0; | ||
820 | } | ||
821 | |||
822 | static void ax8817x_get_drvinfo (struct net_device *net, | ||
823 | struct ethtool_drvinfo *info) | ||
824 | { | ||
825 | /* Inherit standard device info */ | ||
826 | usbnet_get_drvinfo(net, info); | ||
827 | info->eedump_len = 0x3e; | ||
828 | } | ||
829 | |||
830 | static int ax8817x_get_settings(struct net_device *net, struct ethtool_cmd *cmd) | ||
831 | { | ||
832 | struct usbnet *dev = netdev_priv(net); | ||
833 | |||
834 | return mii_ethtool_gset(&dev->mii,cmd); | ||
835 | } | ||
836 | |||
837 | static int ax8817x_set_settings(struct net_device *net, struct ethtool_cmd *cmd) | ||
838 | { | ||
839 | struct usbnet *dev = netdev_priv(net); | ||
840 | |||
841 | return mii_ethtool_sset(&dev->mii,cmd); | ||
842 | } | ||
843 | |||
844 | /* We need to override some ethtool_ops so we require our | ||
845 | own structure so we don't interfere with other usbnet | ||
846 | devices that may be connected at the same time. */ | ||
847 | static struct ethtool_ops ax8817x_ethtool_ops = { | ||
848 | .get_drvinfo = ax8817x_get_drvinfo, | ||
849 | .get_link = ethtool_op_get_link, | ||
850 | .get_msglevel = usbnet_get_msglevel, | ||
851 | .set_msglevel = usbnet_set_msglevel, | ||
852 | .get_wol = ax8817x_get_wol, | ||
853 | .set_wol = ax8817x_set_wol, | ||
854 | .get_eeprom_len = ax8817x_get_eeprom_len, | ||
855 | .get_eeprom = ax8817x_get_eeprom, | ||
856 | .get_settings = ax8817x_get_settings, | ||
857 | .set_settings = ax8817x_set_settings, | ||
858 | }; | ||
859 | |||
860 | static int ax8817x_bind(struct usbnet *dev, struct usb_interface *intf) | ||
861 | { | ||
862 | int ret = 0; | ||
863 | void *buf; | ||
864 | int i; | ||
865 | unsigned long gpio_bits = dev->driver_info->data; | ||
866 | |||
867 | get_endpoints(dev,intf); | ||
868 | |||
869 | buf = kmalloc(ETH_ALEN, GFP_KERNEL); | ||
870 | if(!buf) { | ||
871 | ret = -ENOMEM; | ||
872 | goto out1; | ||
873 | } | ||
874 | |||
875 | /* Toggle the GPIOs in a manufacturer/model specific way */ | ||
876 | for (i = 2; i >= 0; i--) { | ||
877 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS, | ||
878 | (gpio_bits >> (i * 8)) & 0xff, 0, 0, | ||
879 | buf)) < 0) | ||
880 | goto out2; | ||
881 | msleep(5); | ||
882 | } | ||
883 | |||
884 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x80, 0, 0, buf)) < 0) { | ||
885 | dbg("send AX_CMD_WRITE_RX_CTL failed: %d", ret); | ||
886 | goto out2; | ||
887 | } | ||
888 | |||
889 | /* Get the MAC address */ | ||
890 | memset(buf, 0, ETH_ALEN); | ||
891 | if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, 6, buf)) < 0) { | ||
892 | dbg("read AX_CMD_READ_NODE_ID failed: %d", ret); | ||
893 | goto out2; | ||
894 | } | ||
895 | memcpy(dev->net->dev_addr, buf, ETH_ALEN); | ||
896 | |||
897 | /* Get the PHY id */ | ||
898 | if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf)) < 0) { | ||
899 | dbg("error on read AX_CMD_READ_PHY_ID: %02x", ret); | ||
900 | goto out2; | ||
901 | } else if (ret < 2) { | ||
902 | /* this should always return 2 bytes */ | ||
903 | dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x", ret); | ||
904 | ret = -EIO; | ||
905 | goto out2; | ||
906 | } | ||
907 | |||
908 | /* Initialize MII structure */ | ||
909 | dev->mii.dev = dev->net; | ||
910 | dev->mii.mdio_read = ax8817x_mdio_read; | ||
911 | dev->mii.mdio_write = ax8817x_mdio_write; | ||
912 | dev->mii.phy_id_mask = 0x3f; | ||
913 | dev->mii.reg_num_mask = 0x1f; | ||
914 | dev->mii.phy_id = *((u8 *)buf + 1); | ||
915 | |||
916 | dev->net->set_multicast_list = ax8817x_set_multicast; | ||
917 | dev->net->ethtool_ops = &ax8817x_ethtool_ops; | ||
918 | |||
919 | ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); | ||
920 | ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE, | ||
921 | ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP); | ||
922 | mii_nway_restart(&dev->mii); | ||
923 | |||
924 | return 0; | ||
925 | out2: | ||
926 | kfree(buf); | ||
927 | out1: | ||
928 | return ret; | ||
929 | } | ||
930 | |||
931 | static struct ethtool_ops ax88772_ethtool_ops = { | ||
932 | .get_drvinfo = ax8817x_get_drvinfo, | ||
933 | .get_link = ethtool_op_get_link, | ||
934 | .get_msglevel = usbnet_get_msglevel, | ||
935 | .set_msglevel = usbnet_set_msglevel, | ||
936 | .get_wol = ax8817x_get_wol, | ||
937 | .set_wol = ax8817x_set_wol, | ||
938 | .get_eeprom_len = ax8817x_get_eeprom_len, | ||
939 | .get_eeprom = ax8817x_get_eeprom, | ||
940 | .get_settings = ax8817x_get_settings, | ||
941 | .set_settings = ax8817x_set_settings, | ||
942 | }; | ||
943 | |||
944 | static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf) | ||
945 | { | ||
946 | int ret; | ||
947 | void *buf; | ||
948 | |||
949 | get_endpoints(dev,intf); | ||
950 | |||
951 | buf = kmalloc(6, GFP_KERNEL); | ||
952 | if(!buf) { | ||
953 | dbg ("Cannot allocate memory for buffer"); | ||
954 | ret = -ENOMEM; | ||
955 | goto out1; | ||
956 | } | ||
957 | |||
958 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS, | ||
959 | 0x00B0, 0, 0, buf)) < 0) | ||
960 | goto out2; | ||
961 | |||
962 | msleep(5); | ||
963 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_PHY_SELECT, 0x0001, 0, 0, buf)) < 0) { | ||
964 | dbg("Select PHY #1 failed: %d", ret); | ||
965 | goto out2; | ||
966 | } | ||
967 | |||
968 | if ((ret = | ||
969 | ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPPD, 0, 0, buf)) < 0) { | ||
970 | dbg("Failed to power down internal PHY: %d", ret); | ||
971 | goto out2; | ||
972 | } | ||
973 | |||
974 | msleep(150); | ||
975 | if ((ret = | ||
976 | ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_CLEAR, 0, 0, buf)) < 0) { | ||
977 | dbg("Failed to perform software reset: %d", ret); | ||
978 | goto out2; | ||
979 | } | ||
980 | |||
981 | msleep(150); | ||
982 | if ((ret = | ||
983 | ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPRL | AX_SWRESET_PRL, 0, 0, buf)) < 0) { | ||
984 | dbg("Failed to set Internal/External PHY reset control: %d", ret); | ||
985 | goto out2; | ||
986 | } | ||
987 | |||
988 | msleep(150); | ||
989 | if ((ret = | ||
990 | ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x0000, 0, 0, | ||
991 | buf)) < 0) { | ||
992 | dbg("Failed to reset RX_CTL: %d", ret); | ||
993 | goto out2; | ||
994 | } | ||
995 | |||
996 | /* Get the MAC address */ | ||
997 | memset(buf, 0, ETH_ALEN); | ||
998 | if ((ret = ax8817x_read_cmd(dev, AX88772_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf)) < 0) { | ||
999 | dbg("Failed to read MAC address: %d", ret); | ||
1000 | goto out2; | ||
1001 | } | ||
1002 | memcpy(dev->net->dev_addr, buf, ETH_ALEN); | ||
1003 | |||
1004 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, buf)) < 0) { | ||
1005 | dbg("Enabling software MII failed: %d", ret); | ||
1006 | goto out2; | ||
1007 | } | ||
1008 | |||
1009 | if (((ret = | ||
1010 | ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, 0x0010, 2, 2, buf)) < 0) | ||
1011 | || (*((u16 *)buf) != 0x003b)) { | ||
1012 | dbg("Read PHY register 2 must be 0x3b00: %d", ret); | ||
1013 | goto out2; | ||
1014 | } | ||
1015 | |||
1016 | /* Initialize MII structure */ | ||
1017 | dev->mii.dev = dev->net; | ||
1018 | dev->mii.mdio_read = ax8817x_mdio_read; | ||
1019 | dev->mii.mdio_write = ax8817x_mdio_write; | ||
1020 | dev->mii.phy_id_mask = 0xff; | ||
1021 | dev->mii.reg_num_mask = 0xff; | ||
1022 | |||
1023 | /* Get the PHY id */ | ||
1024 | if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf)) < 0) { | ||
1025 | dbg("Error reading PHY ID: %02x", ret); | ||
1026 | goto out2; | ||
1027 | } else if (ret < 2) { | ||
1028 | /* this should always return 2 bytes */ | ||
1029 | dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x", | ||
1030 | ret); | ||
1031 | ret = -EIO; | ||
1032 | goto out2; | ||
1033 | } | ||
1034 | dev->mii.phy_id = *((u8 *)buf + 1); | ||
1035 | |||
1036 | if ((ret = | ||
1037 | ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_PRL, 0, 0, buf)) < 0) { | ||
1038 | dbg("Set external PHY reset pin level: %d", ret); | ||
1039 | goto out2; | ||
1040 | } | ||
1041 | msleep(150); | ||
1042 | if ((ret = | ||
1043 | ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPRL | AX_SWRESET_PRL, 0, 0, buf)) < 0) { | ||
1044 | dbg("Set Internal/External PHY reset control: %d", ret); | ||
1045 | goto out2; | ||
1046 | } | ||
1047 | msleep(150); | ||
1048 | |||
1049 | |||
1050 | dev->net->set_multicast_list = ax8817x_set_multicast; | ||
1051 | dev->net->ethtool_ops = &ax88772_ethtool_ops; | ||
1052 | |||
1053 | ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); | ||
1054 | ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE, | ||
1055 | ADVERTISE_ALL | ADVERTISE_CSMA); | ||
1056 | mii_nway_restart(&dev->mii); | ||
1057 | |||
1058 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, AX88772_MEDIUM_DEFAULT, 0, 0, buf)) < 0) { | ||
1059 | dbg("Write medium mode register: %d", ret); | ||
1060 | goto out2; | ||
1061 | } | ||
1062 | |||
1063 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_IPG0, AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,AX88772_IPG2_DEFAULT, 0, buf)) < 0) { | ||
1064 | dbg("Write IPG,IPG1,IPG2 failed: %d", ret); | ||
1065 | goto out2; | ||
1066 | } | ||
1067 | if ((ret = | ||
1068 | ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf)) < 0) { | ||
1069 | dbg("Failed to set hardware MII: %02x", ret); | ||
1070 | goto out2; | ||
1071 | } | ||
1072 | |||
1073 | /* Set RX_CTL to default values with 2k buffer, and enable cactus */ | ||
1074 | if ((ret = | ||
1075 | ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x0088, 0, 0, | ||
1076 | buf)) < 0) { | ||
1077 | dbg("Reset RX_CTL failed: %d", ret); | ||
1078 | goto out2; | ||
1079 | } | ||
1080 | |||
1081 | kfree(buf); | ||
1082 | |||
1083 | return 0; | ||
1084 | |||
1085 | out2: | ||
1086 | kfree(buf); | ||
1087 | out1: | ||
1088 | return ret; | ||
1089 | } | ||
1090 | |||
1091 | static int ax88772_rx_fixup(struct usbnet *dev, struct sk_buff *skb) | ||
1092 | { | ||
1093 | u32 *header; | ||
1094 | char *packet; | ||
1095 | struct sk_buff *ax_skb; | ||
1096 | u16 size; | ||
1097 | |||
1098 | header = (u32 *) skb->data; | ||
1099 | le32_to_cpus(header); | ||
1100 | packet = (char *)(header + 1); | ||
1101 | |||
1102 | skb_pull(skb, 4); | ||
1103 | |||
1104 | while (skb->len > 0) { | ||
1105 | if ((short)(*header & 0x0000ffff) != | ||
1106 | ~((short)((*header & 0xffff0000) >> 16))) { | ||
1107 | devdbg(dev,"header length data is error"); | ||
1108 | } | ||
1109 | /* get the packet length */ | ||
1110 | size = (u16) (*header & 0x0000ffff); | ||
1111 | |||
1112 | if ((skb->len) - ((size + 1) & 0xfffe) == 0) | ||
1113 | return 2; | ||
1114 | if (size > ETH_FRAME_LEN) { | ||
1115 | devdbg(dev,"invalid rx length %d", size); | ||
1116 | return 0; | ||
1117 | } | ||
1118 | ax_skb = skb_clone(skb, GFP_ATOMIC); | ||
1119 | if (ax_skb) { | ||
1120 | ax_skb->len = size; | ||
1121 | ax_skb->data = packet; | ||
1122 | ax_skb->tail = packet + size; | ||
1123 | skb_return(dev, ax_skb); | ||
1124 | } else { | ||
1125 | return 0; | ||
1126 | } | ||
1127 | |||
1128 | skb_pull(skb, (size + 1) & 0xfffe); | ||
1129 | |||
1130 | if (skb->len == 0) | ||
1131 | break; | ||
1132 | |||
1133 | header = (u32 *) skb->data; | ||
1134 | le32_to_cpus(header); | ||
1135 | packet = (char *)(header + 1); | ||
1136 | skb_pull(skb, 4); | ||
1137 | } | ||
1138 | |||
1139 | if (skb->len < 0) { | ||
1140 | devdbg(dev,"invalid rx length %d", skb->len); | ||
1141 | return 0; | ||
1142 | } | ||
1143 | return 1; | ||
1144 | } | ||
1145 | |||
1146 | static struct sk_buff *ax88772_tx_fixup(struct usbnet *dev, struct sk_buff *skb, | ||
1147 | int flags) | ||
1148 | { | ||
1149 | int padlen; | ||
1150 | int headroom = skb_headroom(skb); | ||
1151 | int tailroom = skb_tailroom(skb); | ||
1152 | u32 *packet_len; | ||
1153 | u32 *padbytes_ptr; | ||
1154 | |||
1155 | padlen = ((skb->len + 4) % 512) ? 0 : 4; | ||
1156 | |||
1157 | if ((!skb_cloned(skb)) | ||
1158 | && ((headroom + tailroom) >= (4 + padlen))) { | ||
1159 | if ((headroom < 4) || (tailroom < padlen)) { | ||
1160 | skb->data = memmove(skb->head + 4, skb->data, skb->len); | ||
1161 | skb->tail = skb->data + skb->len; | ||
1162 | } | ||
1163 | } else { | ||
1164 | struct sk_buff *skb2; | ||
1165 | skb2 = skb_copy_expand(skb, 4, padlen, flags); | ||
1166 | dev_kfree_skb_any(skb); | ||
1167 | skb = skb2; | ||
1168 | if (!skb) | ||
1169 | return NULL; | ||
1170 | } | ||
1171 | |||
1172 | packet_len = (u32 *) skb_push(skb, 4); | ||
1173 | |||
1174 | packet_len = (u32 *) skb->data; | ||
1175 | *packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4); | ||
1176 | |||
1177 | if ((skb->len % 512) == 0) { | ||
1178 | padbytes_ptr = (u32 *) skb->tail; | ||
1179 | *padbytes_ptr = 0xffff0000; | ||
1180 | skb_put(skb, padlen); | ||
1181 | } | ||
1182 | return skb; | ||
1183 | } | ||
1184 | |||
1185 | static int ax88772_link_reset(struct usbnet *dev) | ||
1186 | { | ||
1187 | u16 lpa; | ||
1188 | u16 mode; | ||
1189 | |||
1190 | mode = AX88772_MEDIUM_DEFAULT; | ||
1191 | lpa = ax8817x_mdio_read(dev->net, dev->mii.phy_id, MII_LPA); | ||
1192 | |||
1193 | if ((lpa & LPA_DUPLEX) == 0) | ||
1194 | mode &= ~AX88772_MEDIUM_FULL_DUPLEX; | ||
1195 | if ((lpa & LPA_100) == 0) | ||
1196 | mode &= ~AX88772_MEDIUM_100MB; | ||
1197 | ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL); | ||
1198 | |||
1199 | return 0; | ||
1200 | } | ||
1201 | |||
1202 | static const struct driver_info ax8817x_info = { | ||
1203 | .description = "ASIX AX8817x USB 2.0 Ethernet", | ||
1204 | .bind = ax8817x_bind, | ||
1205 | .status = ax8817x_status, | ||
1206 | .link_reset = ax88172_link_reset, | ||
1207 | .reset = ax88172_link_reset, | ||
1208 | .flags = FLAG_ETHER, | ||
1209 | .data = 0x00130103, | ||
1210 | }; | ||
1211 | |||
1212 | static const struct driver_info dlink_dub_e100_info = { | ||
1213 | .description = "DLink DUB-E100 USB Ethernet", | ||
1214 | .bind = ax8817x_bind, | ||
1215 | .status = ax8817x_status, | ||
1216 | .link_reset = ax88172_link_reset, | ||
1217 | .reset = ax88172_link_reset, | ||
1218 | .flags = FLAG_ETHER, | ||
1219 | .data = 0x009f9d9f, | ||
1220 | }; | ||
1221 | |||
1222 | static const struct driver_info netgear_fa120_info = { | ||
1223 | .description = "Netgear FA-120 USB Ethernet", | ||
1224 | .bind = ax8817x_bind, | ||
1225 | .status = ax8817x_status, | ||
1226 | .link_reset = ax88172_link_reset, | ||
1227 | .reset = ax88172_link_reset, | ||
1228 | .flags = FLAG_ETHER, | ||
1229 | .data = 0x00130103, | ||
1230 | }; | ||
1231 | |||
1232 | static const struct driver_info hawking_uf200_info = { | ||
1233 | .description = "Hawking UF200 USB Ethernet", | ||
1234 | .bind = ax8817x_bind, | ||
1235 | .status = ax8817x_status, | ||
1236 | .link_reset = ax88172_link_reset, | ||
1237 | .reset = ax88172_link_reset, | ||
1238 | .flags = FLAG_ETHER, | ||
1239 | .data = 0x001f1d1f, | ||
1240 | }; | ||
1241 | |||
1242 | static const struct driver_info ax88772_info = { | ||
1243 | .description = "ASIX AX88772 USB 2.0 Ethernet", | ||
1244 | .bind = ax88772_bind, | ||
1245 | .status = ax8817x_status, | ||
1246 | .link_reset = ax88772_link_reset, | ||
1247 | .reset = ax88772_link_reset, | ||
1248 | .flags = FLAG_ETHER | FLAG_FRAMING_AX, | ||
1249 | .rx_fixup = ax88772_rx_fixup, | ||
1250 | .tx_fixup = ax88772_tx_fixup, | ||
1251 | .data = 0x00130103, | ||
1252 | }; | ||
1253 | |||
1254 | #endif /* CONFIG_USB_AX8817X */ | ||
1255 | |||
1256 | |||
1257 | |||
1258 | #ifdef CONFIG_USB_BELKIN | ||
1259 | #define HAVE_HARDWARE | ||
1260 | |||
1261 | /*------------------------------------------------------------------------- | ||
1262 | * | ||
1263 | * Belkin F5U104 ... two NetChip 2280 devices + Atmel microcontroller | ||
1264 | * | ||
1265 | * ... also two eTEK designs, including one sold as "Advance USBNET" | ||
1266 | * | ||
1267 | *-------------------------------------------------------------------------*/ | ||
1268 | |||
1269 | static const struct driver_info belkin_info = { | ||
1270 | .description = "Belkin, eTEK, or compatible", | ||
1271 | }; | ||
1272 | |||
1273 | #endif /* CONFIG_USB_BELKIN */ | ||
1274 | |||
1275 | |||
1276 | |||
1277 | /*------------------------------------------------------------------------- | ||
1278 | * | ||
1279 | * Communications Device Class declarations. | ||
1280 | * Used by CDC Ethernet, and some CDC variants | ||
1281 | * | ||
1282 | *-------------------------------------------------------------------------*/ | ||
1283 | |||
1284 | #ifdef CONFIG_USB_CDCETHER | ||
1285 | #define NEED_GENERIC_CDC | ||
1286 | #endif | ||
1287 | |||
1288 | #ifdef CONFIG_USB_ZAURUS | ||
1289 | /* Ethernet variant uses funky framing, broken ethernet addressing */ | ||
1290 | #define NEED_GENERIC_CDC | ||
1291 | #endif | ||
1292 | |||
1293 | #ifdef CONFIG_USB_RNDIS | ||
1294 | /* ACM variant uses even funkier framing, complex control RPC scheme */ | ||
1295 | #define NEED_GENERIC_CDC | ||
1296 | #endif | ||
1297 | |||
1298 | |||
1299 | #ifdef NEED_GENERIC_CDC | ||
1300 | |||
1301 | #include <linux/usb_cdc.h> | ||
1302 | |||
1303 | struct cdc_state { | ||
1304 | struct usb_cdc_header_desc *header; | ||
1305 | struct usb_cdc_union_desc *u; | ||
1306 | struct usb_cdc_ether_desc *ether; | ||
1307 | struct usb_interface *control; | ||
1308 | struct usb_interface *data; | ||
1309 | }; | ||
1310 | |||
1311 | static struct usb_driver usbnet_driver; | ||
1312 | |||
1313 | /* | ||
1314 | * probes control interface, claims data interface, collects the bulk | ||
1315 | * endpoints, activates data interface (if needed), maybe sets MTU. | ||
1316 | * all pure cdc, except for certain firmware workarounds. | ||
1317 | */ | ||
1318 | static int generic_cdc_bind (struct usbnet *dev, struct usb_interface *intf) | ||
1319 | { | ||
1320 | u8 *buf = intf->cur_altsetting->extra; | ||
1321 | int len = intf->cur_altsetting->extralen; | ||
1322 | struct usb_interface_descriptor *d; | ||
1323 | struct cdc_state *info = (void *) &dev->data; | ||
1324 | int status; | ||
1325 | int rndis; | ||
1326 | |||
1327 | if (sizeof dev->data < sizeof *info) | ||
1328 | return -EDOM; | ||
1329 | |||
1330 | /* expect strict spec conformance for the descriptors, but | ||
1331 | * cope with firmware which stores them in the wrong place | ||
1332 | */ | ||
1333 | if (len == 0 && dev->udev->actconfig->extralen) { | ||
1334 | /* Motorola SB4100 (and others: Brad Hards says it's | ||
1335 | * from a Broadcom design) put CDC descriptors here | ||
1336 | */ | ||
1337 | buf = dev->udev->actconfig->extra; | ||
1338 | len = dev->udev->actconfig->extralen; | ||
1339 | if (len) | ||
1340 | dev_dbg (&intf->dev, | ||
1341 | "CDC descriptors on config\n"); | ||
1342 | } | ||
1343 | |||
1344 | /* this assumes that if there's a non-RNDIS vendor variant | ||
1345 | * of cdc-acm, it'll fail RNDIS requests cleanly. | ||
1346 | */ | ||
1347 | rndis = (intf->cur_altsetting->desc.bInterfaceProtocol == 0xff); | ||
1348 | |||
1349 | memset (info, 0, sizeof *info); | ||
1350 | info->control = intf; | ||
1351 | while (len > 3) { | ||
1352 | if (buf [1] != USB_DT_CS_INTERFACE) | ||
1353 | goto next_desc; | ||
1354 | |||
1355 | /* use bDescriptorSubType to identify the CDC descriptors. | ||
1356 | * We expect devices with CDC header and union descriptors. | ||
1357 | * For CDC Ethernet we need the ethernet descriptor. | ||
1358 | * For RNDIS, ignore two (pointless) CDC modem descriptors | ||
1359 | * in favor of a complicated OID-based RPC scheme doing what | ||
1360 | * CDC Ethernet achieves with a simple descriptor. | ||
1361 | */ | ||
1362 | switch (buf [2]) { | ||
1363 | case USB_CDC_HEADER_TYPE: | ||
1364 | if (info->header) { | ||
1365 | dev_dbg (&intf->dev, "extra CDC header\n"); | ||
1366 | goto bad_desc; | ||
1367 | } | ||
1368 | info->header = (void *) buf; | ||
1369 | if (info->header->bLength != sizeof *info->header) { | ||
1370 | dev_dbg (&intf->dev, "CDC header len %u\n", | ||
1371 | info->header->bLength); | ||
1372 | goto bad_desc; | ||
1373 | } | ||
1374 | break; | ||
1375 | case USB_CDC_UNION_TYPE: | ||
1376 | if (info->u) { | ||
1377 | dev_dbg (&intf->dev, "extra CDC union\n"); | ||
1378 | goto bad_desc; | ||
1379 | } | ||
1380 | info->u = (void *) buf; | ||
1381 | if (info->u->bLength != sizeof *info->u) { | ||
1382 | dev_dbg (&intf->dev, "CDC union len %u\n", | ||
1383 | info->u->bLength); | ||
1384 | goto bad_desc; | ||
1385 | } | ||
1386 | |||
1387 | /* we need a master/control interface (what we're | ||
1388 | * probed with) and a slave/data interface; union | ||
1389 | * descriptors sort this all out. | ||
1390 | */ | ||
1391 | info->control = usb_ifnum_to_if(dev->udev, | ||
1392 | info->u->bMasterInterface0); | ||
1393 | info->data = usb_ifnum_to_if(dev->udev, | ||
1394 | info->u->bSlaveInterface0); | ||
1395 | if (!info->control || !info->data) { | ||
1396 | dev_dbg (&intf->dev, | ||
1397 | "master #%u/%p slave #%u/%p\n", | ||
1398 | info->u->bMasterInterface0, | ||
1399 | info->control, | ||
1400 | info->u->bSlaveInterface0, | ||
1401 | info->data); | ||
1402 | goto bad_desc; | ||
1403 | } | ||
1404 | if (info->control != intf) { | ||
1405 | dev_dbg (&intf->dev, "bogus CDC Union\n"); | ||
1406 | /* Ambit USB Cable Modem (and maybe others) | ||
1407 | * interchanges master and slave interface. | ||
1408 | */ | ||
1409 | if (info->data == intf) { | ||
1410 | info->data = info->control; | ||
1411 | info->control = intf; | ||
1412 | } else | ||
1413 | goto bad_desc; | ||
1414 | } | ||
1415 | |||
1416 | /* a data interface altsetting does the real i/o */ | ||
1417 | d = &info->data->cur_altsetting->desc; | ||
1418 | if (d->bInterfaceClass != USB_CLASS_CDC_DATA) { | ||
1419 | dev_dbg (&intf->dev, "slave class %u\n", | ||
1420 | d->bInterfaceClass); | ||
1421 | goto bad_desc; | ||
1422 | } | ||
1423 | break; | ||
1424 | case USB_CDC_ETHERNET_TYPE: | ||
1425 | if (info->ether) { | ||
1426 | dev_dbg (&intf->dev, "extra CDC ether\n"); | ||
1427 | goto bad_desc; | ||
1428 | } | ||
1429 | info->ether = (void *) buf; | ||
1430 | if (info->ether->bLength != sizeof *info->ether) { | ||
1431 | dev_dbg (&intf->dev, "CDC ether len %u\n", | ||
1432 | info->ether->bLength); | ||
1433 | goto bad_desc; | ||
1434 | } | ||
1435 | dev->net->mtu = le16_to_cpup ( | ||
1436 | &info->ether->wMaxSegmentSize) | ||
1437 | - ETH_HLEN; | ||
1438 | /* because of Zaurus, we may be ignoring the host | ||
1439 | * side link address we were given. | ||
1440 | */ | ||
1441 | break; | ||
1442 | } | ||
1443 | next_desc: | ||
1444 | len -= buf [0]; /* bLength */ | ||
1445 | buf += buf [0]; | ||
1446 | } | ||
1447 | |||
1448 | if (!info->header || !info->u || (!rndis && !info->ether)) { | ||
1449 | dev_dbg (&intf->dev, "missing cdc %s%s%sdescriptor\n", | ||
1450 | info->header ? "" : "header ", | ||
1451 | info->u ? "" : "union ", | ||
1452 | info->ether ? "" : "ether "); | ||
1453 | goto bad_desc; | ||
1454 | } | ||
1455 | |||
1456 | /* claim data interface and set it up ... with side effects. | ||
1457 | * network traffic can't flow until an altsetting is enabled. | ||
1458 | */ | ||
1459 | status = usb_driver_claim_interface (&usbnet_driver, info->data, dev); | ||
1460 | if (status < 0) | ||
1461 | return status; | ||
1462 | status = get_endpoints (dev, info->data); | ||
1463 | if (status < 0) { | ||
1464 | /* ensure immediate exit from usbnet_disconnect */ | ||
1465 | usb_set_intfdata(info->data, NULL); | ||
1466 | usb_driver_release_interface (&usbnet_driver, info->data); | ||
1467 | return status; | ||
1468 | } | ||
1469 | |||
1470 | /* status endpoint: optional for CDC Ethernet, not RNDIS (or ACM) */ | ||
1471 | dev->status = NULL; | ||
1472 | if (info->control->cur_altsetting->desc.bNumEndpoints == 1) { | ||
1473 | struct usb_endpoint_descriptor *desc; | ||
1474 | |||
1475 | dev->status = &info->control->cur_altsetting->endpoint [0]; | ||
1476 | desc = &dev->status->desc; | ||
1477 | if (desc->bmAttributes != USB_ENDPOINT_XFER_INT | ||
1478 | || !(desc->bEndpointAddress & USB_DIR_IN) | ||
1479 | || (le16_to_cpu(desc->wMaxPacketSize) | ||
1480 | < sizeof (struct usb_cdc_notification)) | ||
1481 | || !desc->bInterval) { | ||
1482 | dev_dbg (&intf->dev, "bad notification endpoint\n"); | ||
1483 | dev->status = NULL; | ||
1484 | } | ||
1485 | } | ||
1486 | if (rndis && !dev->status) { | ||
1487 | dev_dbg (&intf->dev, "missing RNDIS status endpoint\n"); | ||
1488 | usb_set_intfdata(info->data, NULL); | ||
1489 | usb_driver_release_interface (&usbnet_driver, info->data); | ||
1490 | return -ENODEV; | ||
1491 | } | ||
1492 | return 0; | ||
1493 | |||
1494 | bad_desc: | ||
1495 | dev_info (&dev->udev->dev, "bad CDC descriptors\n"); | ||
1496 | return -ENODEV; | ||
1497 | } | ||
1498 | |||
1499 | static void cdc_unbind (struct usbnet *dev, struct usb_interface *intf) | ||
1500 | { | ||
1501 | struct cdc_state *info = (void *) &dev->data; | ||
1502 | |||
1503 | /* disconnect master --> disconnect slave */ | ||
1504 | if (intf == info->control && info->data) { | ||
1505 | /* ensure immediate exit from usbnet_disconnect */ | ||
1506 | usb_set_intfdata(info->data, NULL); | ||
1507 | usb_driver_release_interface (&usbnet_driver, info->data); | ||
1508 | info->data = NULL; | ||
1509 | } | ||
1510 | |||
1511 | /* and vice versa (just in case) */ | ||
1512 | else if (intf == info->data && info->control) { | ||
1513 | /* ensure immediate exit from usbnet_disconnect */ | ||
1514 | usb_set_intfdata(info->control, NULL); | ||
1515 | usb_driver_release_interface (&usbnet_driver, info->control); | ||
1516 | info->control = NULL; | ||
1517 | } | ||
1518 | } | ||
1519 | |||
1520 | #endif /* NEED_GENERIC_CDC */ | ||
1521 | |||
1522 | |||
1523 | #ifdef CONFIG_USB_CDCETHER | ||
1524 | #define HAVE_HARDWARE | ||
1525 | |||
1526 | /*------------------------------------------------------------------------- | ||
1527 | * | ||
1528 | * Communications Device Class, Ethernet Control model | ||
1529 | * | ||
1530 | * Takes two interfaces. The DATA interface is inactive till an altsetting | ||
1531 | * is selected. Configuration data includes class descriptors. | ||
1532 | * | ||
1533 | * This should interop with whatever the 2.4 "CDCEther.c" driver | ||
1534 | * (by Brad Hards) talked with. | ||
1535 | * | ||
1536 | *-------------------------------------------------------------------------*/ | ||
1537 | |||
1538 | #include <linux/ctype.h> | ||
1539 | |||
1540 | |||
1541 | static void dumpspeed (struct usbnet *dev, __le32 *speeds) | ||
1542 | { | ||
1543 | if (netif_msg_timer (dev)) | ||
1544 | devinfo (dev, "link speeds: %u kbps up, %u kbps down", | ||
1545 | __le32_to_cpu(speeds[0]) / 1000, | ||
1546 | __le32_to_cpu(speeds[1]) / 1000); | ||
1547 | } | ||
1548 | |||
1549 | static void cdc_status (struct usbnet *dev, struct urb *urb) | ||
1550 | { | ||
1551 | struct usb_cdc_notification *event; | ||
1552 | |||
1553 | if (urb->actual_length < sizeof *event) | ||
1554 | return; | ||
1555 | |||
1556 | /* SPEED_CHANGE can get split into two 8-byte packets */ | ||
1557 | if (test_and_clear_bit (EVENT_STS_SPLIT, &dev->flags)) { | ||
1558 | dumpspeed (dev, (__le32 *) urb->transfer_buffer); | ||
1559 | return; | ||
1560 | } | ||
1561 | |||
1562 | event = urb->transfer_buffer; | ||
1563 | switch (event->bNotificationType) { | ||
1564 | case USB_CDC_NOTIFY_NETWORK_CONNECTION: | ||
1565 | if (netif_msg_timer (dev)) | ||
1566 | devdbg (dev, "CDC: carrier %s", | ||
1567 | event->wValue ? "on" : "off"); | ||
1568 | if (event->wValue) | ||
1569 | netif_carrier_on(dev->net); | ||
1570 | else | ||
1571 | netif_carrier_off(dev->net); | ||
1572 | break; | ||
1573 | case USB_CDC_NOTIFY_SPEED_CHANGE: /* tx/rx rates */ | ||
1574 | if (netif_msg_timer (dev)) | ||
1575 | devdbg (dev, "CDC: speed change (len %d)", | ||
1576 | urb->actual_length); | ||
1577 | if (urb->actual_length != (sizeof *event + 8)) | ||
1578 | set_bit (EVENT_STS_SPLIT, &dev->flags); | ||
1579 | else | ||
1580 | dumpspeed (dev, (__le32 *) &event[1]); | ||
1581 | break; | ||
1582 | // case USB_CDC_NOTIFY_RESPONSE_AVAILABLE: /* RNDIS; or unsolicited */ | ||
1583 | default: | ||
1584 | deverr (dev, "CDC: unexpected notification %02x!", | ||
1585 | event->bNotificationType); | ||
1586 | break; | ||
1587 | } | ||
1588 | } | ||
1589 | |||
1590 | static u8 nibble (unsigned char c) | ||
1591 | { | ||
1592 | if (likely (isdigit (c))) | ||
1593 | return c - '0'; | ||
1594 | c = toupper (c); | ||
1595 | if (likely (isxdigit (c))) | ||
1596 | return 10 + c - 'A'; | ||
1597 | return 0; | ||
1598 | } | ||
1599 | |||
1600 | static inline int | ||
1601 | get_ethernet_addr (struct usbnet *dev, struct usb_cdc_ether_desc *e) | ||
1602 | { | ||
1603 | int tmp, i; | ||
1604 | unsigned char buf [13]; | ||
1605 | |||
1606 | tmp = usb_string (dev->udev, e->iMACAddress, buf, sizeof buf); | ||
1607 | if (tmp != 12) { | ||
1608 | dev_dbg (&dev->udev->dev, | ||
1609 | "bad MAC string %d fetch, %d\n", e->iMACAddress, tmp); | ||
1610 | if (tmp >= 0) | ||
1611 | tmp = -EINVAL; | ||
1612 | return tmp; | ||
1613 | } | ||
1614 | for (i = tmp = 0; i < 6; i++, tmp += 2) | ||
1615 | dev->net->dev_addr [i] = | ||
1616 | (nibble (buf [tmp]) << 4) + nibble (buf [tmp + 1]); | ||
1617 | return 0; | ||
1618 | } | ||
1619 | |||
1620 | static int cdc_bind (struct usbnet *dev, struct usb_interface *intf) | ||
1621 | { | ||
1622 | int status; | ||
1623 | struct cdc_state *info = (void *) &dev->data; | ||
1624 | |||
1625 | status = generic_cdc_bind (dev, intf); | ||
1626 | if (status < 0) | ||
1627 | return status; | ||
1628 | |||
1629 | status = get_ethernet_addr (dev, info->ether); | ||
1630 | if (status < 0) { | ||
1631 | usb_set_intfdata(info->data, NULL); | ||
1632 | usb_driver_release_interface (&usbnet_driver, info->data); | ||
1633 | return status; | ||
1634 | } | ||
1635 | |||
1636 | /* FIXME cdc-ether has some multicast code too, though it complains | ||
1637 | * in routine cases. info->ether describes the multicast support. | ||
1638 | */ | ||
1639 | return 0; | ||
1640 | } | ||
1641 | |||
1642 | static const struct driver_info cdc_info = { | ||
1643 | .description = "CDC Ethernet Device", | ||
1644 | .flags = FLAG_ETHER, | ||
1645 | // .check_connect = cdc_check_connect, | ||
1646 | .bind = cdc_bind, | ||
1647 | .unbind = cdc_unbind, | ||
1648 | .status = cdc_status, | ||
1649 | }; | ||
1650 | |||
1651 | #endif /* CONFIG_USB_CDCETHER */ | ||
1652 | |||
1653 | |||
1654 | |||
1655 | #ifdef CONFIG_USB_EPSON2888 | ||
1656 | #define HAVE_HARDWARE | ||
1657 | |||
1658 | /*------------------------------------------------------------------------- | ||
1659 | * | ||
1660 | * EPSON USB clients | ||
1661 | * | ||
1662 | * This is the same idea as Linux PDAs (below) except the firmware in the | ||
1663 | * device might not be Tux-powered. Epson provides reference firmware that | ||
1664 | * implements this interface. Product developers can reuse or modify that | ||
1665 | * code, such as by using their own product and vendor codes. | ||
1666 | * | ||
1667 | * Support was from Juro Bystricky <bystricky.juro@erd.epson.com> | ||
1668 | * | ||
1669 | *-------------------------------------------------------------------------*/ | ||
1670 | |||
1671 | static const struct driver_info epson2888_info = { | ||
1672 | .description = "Epson USB Device", | ||
1673 | .check_connect = always_connected, | ||
1674 | |||
1675 | .in = 4, .out = 3, | ||
1676 | }; | ||
1677 | |||
1678 | #endif /* CONFIG_USB_EPSON2888 */ | ||
1679 | |||
1680 | |||
1681 | #ifdef CONFIG_USB_GENESYS | ||
1682 | #define HAVE_HARDWARE | ||
1683 | |||
1684 | /*------------------------------------------------------------------------- | ||
1685 | * | ||
1686 | * GeneSys GL620USB-A (www.genesyslogic.com.tw) | ||
1687 | * | ||
1688 | * ... should partially interop with the Win32 driver for this hardware | ||
1689 | * The GeneSys docs imply there's some NDIS issue motivating this framing. | ||
1690 | * | ||
1691 | * Some info from GeneSys: | ||
1692 | * - GL620USB-A is full duplex; GL620USB is only half duplex for bulk. | ||
1693 | * (Some cables, like the BAFO-100c, use the half duplex version.) | ||
1694 | * - For the full duplex model, the low bit of the version code says | ||
1695 | * which side is which ("left/right"). | ||
1696 | * - For the half duplex type, a control/interrupt handshake settles | ||
1697 | * the transfer direction. (That's disabled here, partially coded.) | ||
1698 | * A control URB would block until other side writes an interrupt. | ||
1699 | * | ||
1700 | * Original code from Jiun-Jie Huang <huangjj@genesyslogic.com.tw> | ||
1701 | * and merged into "usbnet" by Stanislav Brabec <utx@penguin.cz>. | ||
1702 | * | ||
1703 | *-------------------------------------------------------------------------*/ | ||
1704 | |||
1705 | // control msg write command | ||
1706 | #define GENELINK_CONNECT_WRITE 0xF0 | ||
1707 | // interrupt pipe index | ||
1708 | #define GENELINK_INTERRUPT_PIPE 0x03 | ||
1709 | // interrupt read buffer size | ||
1710 | #define INTERRUPT_BUFSIZE 0x08 | ||
1711 | // interrupt pipe interval value | ||
1712 | #define GENELINK_INTERRUPT_INTERVAL 0x10 | ||
1713 | // max transmit packet number per transmit | ||
1714 | #define GL_MAX_TRANSMIT_PACKETS 32 | ||
1715 | // max packet length | ||
1716 | #define GL_MAX_PACKET_LEN 1514 | ||
1717 | // max receive buffer size | ||
1718 | #define GL_RCV_BUF_SIZE \ | ||
1719 | (((GL_MAX_PACKET_LEN + 4) * GL_MAX_TRANSMIT_PACKETS) + 4) | ||
1720 | |||
1721 | struct gl_packet { | ||
1722 | u32 packet_length; | ||
1723 | char packet_data [1]; | ||
1724 | }; | ||
1725 | |||
1726 | struct gl_header { | ||
1727 | u32 packet_count; | ||
1728 | struct gl_packet packets; | ||
1729 | }; | ||
1730 | |||
1731 | #ifdef GENELINK_ACK | ||
1732 | |||
1733 | // FIXME: this code is incomplete, not debugged; it doesn't | ||
1734 | // handle interrupts correctly. interrupts should be generic | ||
1735 | // code like all other device I/O, anyway. | ||
1736 | |||
1737 | struct gl_priv { | ||
1738 | struct urb *irq_urb; | ||
1739 | char irq_buf [INTERRUPT_BUFSIZE]; | ||
1740 | }; | ||
1741 | |||
1742 | static inline int gl_control_write (struct usbnet *dev, u8 request, u16 value) | ||
1743 | { | ||
1744 | int retval; | ||
1745 | |||
1746 | retval = usb_control_msg (dev->udev, | ||
1747 | usb_sndctrlpipe (dev->udev, 0), | ||
1748 | request, | ||
1749 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | ||
1750 | value, | ||
1751 | 0, // index | ||
1752 | 0, // data buffer | ||
1753 | 0, // size | ||
1754 | CONTROL_TIMEOUT_MS); | ||
1755 | return retval; | ||
1756 | } | ||
1757 | |||
1758 | static void gl_interrupt_complete (struct urb *urb, struct pt_regs *regs) | ||
1759 | { | ||
1760 | int status = urb->status; | ||
1761 | |||
1762 | switch (status) { | ||
1763 | case 0: | ||
1764 | /* success */ | ||
1765 | break; | ||
1766 | case -ECONNRESET: | ||
1767 | case -ENOENT: | ||
1768 | case -ESHUTDOWN: | ||
1769 | /* this urb is terminated, clean up */ | ||
1770 | dbg("%s - urb shutting down with status: %d", | ||
1771 | __FUNCTION__, status); | ||
1772 | return; | ||
1773 | default: | ||
1774 | dbg("%s - nonzero urb status received: %d", | ||
1775 | __FUNCTION__, urb->status); | ||
1776 | } | ||
1777 | |||
1778 | status = usb_submit_urb (urb, GFP_ATOMIC); | ||
1779 | if (status) | ||
1780 | err ("%s - usb_submit_urb failed with result %d", | ||
1781 | __FUNCTION__, status); | ||
1782 | } | ||
1783 | |||
1784 | static int gl_interrupt_read (struct usbnet *dev) | ||
1785 | { | ||
1786 | struct gl_priv *priv = dev->priv_data; | ||
1787 | int retval; | ||
1788 | |||
1789 | // issue usb interrupt read | ||
1790 | if (priv && priv->irq_urb) { | ||
1791 | // submit urb | ||
1792 | if ((retval = usb_submit_urb (priv->irq_urb, GFP_KERNEL)) != 0) | ||
1793 | dbg ("gl_interrupt_read: submit fail - %X...", retval); | ||
1794 | else | ||
1795 | dbg ("gl_interrupt_read: submit success..."); | ||
1796 | } | ||
1797 | |||
1798 | return 0; | ||
1799 | } | ||
1800 | |||
1801 | // check whether another side is connected | ||
1802 | static int genelink_check_connect (struct usbnet *dev) | ||
1803 | { | ||
1804 | int retval; | ||
1805 | |||
1806 | dbg ("genelink_check_connect..."); | ||
1807 | |||
1808 | // detect whether another side is connected | ||
1809 | if ((retval = gl_control_write (dev, GENELINK_CONNECT_WRITE, 0)) != 0) { | ||
1810 | dbg ("%s: genelink_check_connect write fail - %X", | ||
1811 | dev->net->name, retval); | ||
1812 | return retval; | ||
1813 | } | ||
1814 | |||
1815 | // usb interrupt read to ack another side | ||
1816 | if ((retval = gl_interrupt_read (dev)) != 0) { | ||
1817 | dbg ("%s: genelink_check_connect read fail - %X", | ||
1818 | dev->net->name, retval); | ||
1819 | return retval; | ||
1820 | } | ||
1821 | |||
1822 | dbg ("%s: genelink_check_connect read success", dev->net->name); | ||
1823 | return 0; | ||
1824 | } | ||
1825 | |||
1826 | // allocate and initialize the private data for genelink | ||
1827 | static int genelink_init (struct usbnet *dev) | ||
1828 | { | ||
1829 | struct gl_priv *priv; | ||
1830 | |||
1831 | // allocate the private data structure | ||
1832 | if ((priv = kmalloc (sizeof *priv, GFP_KERNEL)) == 0) { | ||
1833 | dbg ("%s: cannot allocate private data per device", | ||
1834 | dev->net->name); | ||
1835 | return -ENOMEM; | ||
1836 | } | ||
1837 | |||
1838 | // allocate irq urb | ||
1839 | if ((priv->irq_urb = usb_alloc_urb (0, GFP_KERNEL)) == 0) { | ||
1840 | dbg ("%s: cannot allocate private irq urb per device", | ||
1841 | dev->net->name); | ||
1842 | kfree (priv); | ||
1843 | return -ENOMEM; | ||
1844 | } | ||
1845 | |||
1846 | // fill irq urb | ||
1847 | usb_fill_int_urb (priv->irq_urb, dev->udev, | ||
1848 | usb_rcvintpipe (dev->udev, GENELINK_INTERRUPT_PIPE), | ||
1849 | priv->irq_buf, INTERRUPT_BUFSIZE, | ||
1850 | gl_interrupt_complete, 0, | ||
1851 | GENELINK_INTERRUPT_INTERVAL); | ||
1852 | |||
1853 | // set private data pointer | ||
1854 | dev->priv_data = priv; | ||
1855 | |||
1856 | return 0; | ||
1857 | } | ||
1858 | |||
1859 | // release the private data | ||
1860 | static int genelink_free (struct usbnet *dev) | ||
1861 | { | ||
1862 | struct gl_priv *priv = dev->priv_data; | ||
1863 | |||
1864 | if (!priv) | ||
1865 | return 0; | ||
1866 | |||
1867 | // FIXME: can't cancel here; it's synchronous, and | ||
1868 | // should have happened earlier in any case (interrupt | ||
1869 | // handling needs to be generic) | ||
1870 | |||
1871 | // cancel irq urb first | ||
1872 | usb_kill_urb (priv->irq_urb); | ||
1873 | |||
1874 | // free irq urb | ||
1875 | usb_free_urb (priv->irq_urb); | ||
1876 | |||
1877 | // free the private data structure | ||
1878 | kfree (priv); | ||
1879 | |||
1880 | return 0; | ||
1881 | } | ||
1882 | |||
1883 | #endif | ||
1884 | |||
1885 | static int genelink_rx_fixup (struct usbnet *dev, struct sk_buff *skb) | ||
1886 | { | ||
1887 | struct gl_header *header; | ||
1888 | struct gl_packet *packet; | ||
1889 | struct sk_buff *gl_skb; | ||
1890 | u32 size; | ||
1891 | |||
1892 | header = (struct gl_header *) skb->data; | ||
1893 | |||
1894 | // get the packet count of the received skb | ||
1895 | le32_to_cpus (&header->packet_count); | ||
1896 | if ((header->packet_count > GL_MAX_TRANSMIT_PACKETS) | ||
1897 | || (header->packet_count < 0)) { | ||
1898 | dbg ("genelink: invalid received packet count %d", | ||
1899 | header->packet_count); | ||
1900 | return 0; | ||
1901 | } | ||
1902 | |||
1903 | // set the current packet pointer to the first packet | ||
1904 | packet = &header->packets; | ||
1905 | |||
1906 | // decrement the length for the packet count size 4 bytes | ||
1907 | skb_pull (skb, 4); | ||
1908 | |||
1909 | while (header->packet_count > 1) { | ||
1910 | // get the packet length | ||
1911 | size = packet->packet_length; | ||
1912 | |||
1913 | // this may be a broken packet | ||
1914 | if (size > GL_MAX_PACKET_LEN) { | ||
1915 | dbg ("genelink: invalid rx length %d", size); | ||
1916 | return 0; | ||
1917 | } | ||
1918 | |||
1919 | // allocate the skb for the individual packet | ||
1920 | gl_skb = alloc_skb (size, GFP_ATOMIC); | ||
1921 | if (gl_skb) { | ||
1922 | |||
1923 | // copy the packet data to the new skb | ||
1924 | memcpy(skb_put(gl_skb, size), packet->packet_data, size); | ||
1925 | skb_return (dev, gl_skb); | ||
1926 | } | ||
1927 | |||
1928 | // advance to the next packet | ||
1929 | packet = (struct gl_packet *) | ||
1930 | &packet->packet_data [size]; | ||
1931 | header->packet_count--; | ||
1932 | |||
1933 | // shift the data pointer to the next gl_packet | ||
1934 | skb_pull (skb, size + 4); | ||
1935 | } | ||
1936 | |||
1937 | // skip the packet length field 4 bytes | ||
1938 | skb_pull (skb, 4); | ||
1939 | |||
1940 | if (skb->len > GL_MAX_PACKET_LEN) { | ||
1941 | dbg ("genelink: invalid rx length %d", skb->len); | ||
1942 | return 0; | ||
1943 | } | ||
1944 | return 1; | ||
1945 | } | ||
1946 | |||
1947 | static struct sk_buff * | ||
1948 | genelink_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags) | ||
1949 | { | ||
1950 | int padlen; | ||
1951 | int length = skb->len; | ||
1952 | int headroom = skb_headroom (skb); | ||
1953 | int tailroom = skb_tailroom (skb); | ||
1954 | u32 *packet_count; | ||
1955 | u32 *packet_len; | ||
1956 | |||
1957 | // FIXME: magic numbers, bleech | ||
1958 | padlen = ((skb->len + (4 + 4*1)) % 64) ? 0 : 1; | ||
1959 | |||
1960 | if ((!skb_cloned (skb)) | ||
1961 | && ((headroom + tailroom) >= (padlen + (4 + 4*1)))) { | ||
1962 | if ((headroom < (4 + 4*1)) || (tailroom < padlen)) { | ||
1963 | skb->data = memmove (skb->head + (4 + 4*1), | ||
1964 | skb->data, skb->len); | ||
1965 | skb->tail = skb->data + skb->len; | ||
1966 | } | ||
1967 | } else { | ||
1968 | struct sk_buff *skb2; | ||
1969 | skb2 = skb_copy_expand (skb, (4 + 4*1) , padlen, flags); | ||
1970 | dev_kfree_skb_any (skb); | ||
1971 | skb = skb2; | ||
1972 | if (!skb) | ||
1973 | return NULL; | ||
1974 | } | ||
1975 | |||
1976 | // attach the packet count to the header | ||
1977 | packet_count = (u32 *) skb_push (skb, (4 + 4*1)); | ||
1978 | packet_len = packet_count + 1; | ||
1979 | |||
1980 | // FIXME little endian? | ||
1981 | *packet_count = 1; | ||
1982 | *packet_len = length; | ||
1983 | |||
1984 | // add padding byte | ||
1985 | if ((skb->len % dev->maxpacket) == 0) | ||
1986 | skb_put (skb, 1); | ||
1987 | |||
1988 | return skb; | ||
1989 | } | ||
1990 | |||
1991 | static const struct driver_info genelink_info = { | ||
1992 | .description = "Genesys GeneLink", | ||
1993 | .flags = FLAG_FRAMING_GL | FLAG_NO_SETINT, | ||
1994 | .rx_fixup = genelink_rx_fixup, | ||
1995 | .tx_fixup = genelink_tx_fixup, | ||
1996 | |||
1997 | .in = 1, .out = 2, | ||
1998 | |||
1999 | #ifdef GENELINK_ACK | ||
2000 | .check_connect =genelink_check_connect, | ||
2001 | #endif | ||
2002 | }; | ||
2003 | |||
2004 | #endif /* CONFIG_USB_GENESYS */ | ||
2005 | |||
2006 | |||
2007 | |||
2008 | #ifdef CONFIG_USB_NET1080 | ||
2009 | #define HAVE_HARDWARE | ||
2010 | |||
2011 | /*------------------------------------------------------------------------- | ||
2012 | * | ||
2013 | * Netchip 1080 driver ... http://www.netchip.com | ||
2014 | * Used in LapLink cables | ||
2015 | * | ||
2016 | *-------------------------------------------------------------------------*/ | ||
2017 | |||
2018 | #define dev_packet_id data[0] | ||
2019 | #define frame_errors data[1] | ||
2020 | |||
2021 | /* | ||
2022 | * NetChip framing of ethernet packets, supporting additional error | ||
2023 | * checks for links that may drop bulk packets from inside messages. | ||
2024 | * Odd USB length == always short read for last usb packet. | ||
2025 | * - nc_header | ||
2026 | * - Ethernet header (14 bytes) | ||
2027 | * - payload | ||
2028 | * - (optional padding byte, if needed so length becomes odd) | ||
2029 | * - nc_trailer | ||
2030 | * | ||
2031 | * This framing is to be avoided for non-NetChip devices. | ||
2032 | */ | ||
2033 | |||
2034 | struct nc_header { // packed: | ||
2035 | __le16 hdr_len; // sizeof nc_header (LE, all) | ||
2036 | __le16 packet_len; // payload size (including ethhdr) | ||
2037 | __le16 packet_id; // detects dropped packets | ||
2038 | #define MIN_HEADER 6 | ||
2039 | |||
2040 | // all else is optional, and must start with: | ||
2041 | // u16 vendorId; // from usb-if | ||
2042 | // u16 productId; | ||
2043 | } __attribute__((__packed__)); | ||
2044 | |||
2045 | #define PAD_BYTE ((unsigned char)0xAC) | ||
2046 | |||
2047 | struct nc_trailer { | ||
2048 | __le16 packet_id; | ||
2049 | } __attribute__((__packed__)); | ||
2050 | |||
2051 | // packets may use FLAG_FRAMING_NC and optional pad | ||
2052 | #define FRAMED_SIZE(mtu) (sizeof (struct nc_header) \ | ||
2053 | + sizeof (struct ethhdr) \ | ||
2054 | + (mtu) \ | ||
2055 | + 1 \ | ||
2056 | + sizeof (struct nc_trailer)) | ||
2057 | |||
2058 | #define MIN_FRAMED FRAMED_SIZE(0) | ||
2059 | |||
2060 | |||
2061 | /* | ||
2062 | * Zero means no timeout; else, how long a 64 byte bulk packet may be queued | ||
2063 | * before the hardware drops it. If that's done, the driver will need to | ||
2064 | * frame network packets to guard against the dropped USB packets. The win32 | ||
2065 | * driver sets this for both sides of the link. | ||
2066 | */ | ||
2067 | #define NC_READ_TTL_MS ((u8)255) // ms | ||
2068 | |||
2069 | /* | ||
2070 | * We ignore most registers and EEPROM contents. | ||
2071 | */ | ||
2072 | #define REG_USBCTL ((u8)0x04) | ||
2073 | #define REG_TTL ((u8)0x10) | ||
2074 | #define REG_STATUS ((u8)0x11) | ||
2075 | |||
2076 | /* | ||
2077 | * Vendor specific requests to read/write data | ||
2078 | */ | ||
2079 | #define REQUEST_REGISTER ((u8)0x10) | ||
2080 | #define REQUEST_EEPROM ((u8)0x11) | ||
2081 | |||
2082 | static int | ||
2083 | nc_vendor_read (struct usbnet *dev, u8 req, u8 regnum, u16 *retval_ptr) | ||
2084 | { | ||
2085 | int status = usb_control_msg (dev->udev, | ||
2086 | usb_rcvctrlpipe (dev->udev, 0), | ||
2087 | req, | ||
2088 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
2089 | 0, regnum, | ||
2090 | retval_ptr, sizeof *retval_ptr, | ||
2091 | CONTROL_TIMEOUT_MS); | ||
2092 | if (status > 0) | ||
2093 | status = 0; | ||
2094 | if (!status) | ||
2095 | le16_to_cpus (retval_ptr); | ||
2096 | return status; | ||
2097 | } | ||
2098 | |||
2099 | static inline int | ||
2100 | nc_register_read (struct usbnet *dev, u8 regnum, u16 *retval_ptr) | ||
2101 | { | ||
2102 | return nc_vendor_read (dev, REQUEST_REGISTER, regnum, retval_ptr); | ||
2103 | } | ||
2104 | |||
2105 | // no retval ... can become async, usable in_interrupt() | ||
2106 | static void | ||
2107 | nc_vendor_write (struct usbnet *dev, u8 req, u8 regnum, u16 value) | ||
2108 | { | ||
2109 | usb_control_msg (dev->udev, | ||
2110 | usb_sndctrlpipe (dev->udev, 0), | ||
2111 | req, | ||
2112 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
2113 | value, regnum, | ||
2114 | NULL, 0, // data is in setup packet | ||
2115 | CONTROL_TIMEOUT_MS); | ||
2116 | } | ||
2117 | |||
2118 | static inline void | ||
2119 | nc_register_write (struct usbnet *dev, u8 regnum, u16 value) | ||
2120 | { | ||
2121 | nc_vendor_write (dev, REQUEST_REGISTER, regnum, value); | ||
2122 | } | ||
2123 | |||
2124 | |||
2125 | #if 0 | ||
2126 | static void nc_dump_registers (struct usbnet *dev) | ||
2127 | { | ||
2128 | u8 reg; | ||
2129 | u16 *vp = kmalloc (sizeof (u16)); | ||
2130 | |||
2131 | if (!vp) { | ||
2132 | dbg ("no memory?"); | ||
2133 | return; | ||
2134 | } | ||
2135 | |||
2136 | dbg ("%s registers:", dev->net->name); | ||
2137 | for (reg = 0; reg < 0x20; reg++) { | ||
2138 | int retval; | ||
2139 | |||
2140 | // reading some registers is trouble | ||
2141 | if (reg >= 0x08 && reg <= 0xf) | ||
2142 | continue; | ||
2143 | if (reg >= 0x12 && reg <= 0x1e) | ||
2144 | continue; | ||
2145 | |||
2146 | retval = nc_register_read (dev, reg, vp); | ||
2147 | if (retval < 0) | ||
2148 | dbg ("%s reg [0x%x] ==> error %d", | ||
2149 | dev->net->name, reg, retval); | ||
2150 | else | ||
2151 | dbg ("%s reg [0x%x] = 0x%x", | ||
2152 | dev->net->name, reg, *vp); | ||
2153 | } | ||
2154 | kfree (vp); | ||
2155 | } | ||
2156 | #endif | ||
2157 | |||
2158 | |||
2159 | /*-------------------------------------------------------------------------*/ | ||
2160 | |||
2161 | /* | ||
2162 | * Control register | ||
2163 | */ | ||
2164 | |||
2165 | #define USBCTL_WRITABLE_MASK 0x1f0f | ||
2166 | // bits 15-13 reserved, r/o | ||
2167 | #define USBCTL_ENABLE_LANG (1 << 12) | ||
2168 | #define USBCTL_ENABLE_MFGR (1 << 11) | ||
2169 | #define USBCTL_ENABLE_PROD (1 << 10) | ||
2170 | #define USBCTL_ENABLE_SERIAL (1 << 9) | ||
2171 | #define USBCTL_ENABLE_DEFAULTS (1 << 8) | ||
2172 | // bits 7-4 reserved, r/o | ||
2173 | #define USBCTL_FLUSH_OTHER (1 << 3) | ||
2174 | #define USBCTL_FLUSH_THIS (1 << 2) | ||
2175 | #define USBCTL_DISCONN_OTHER (1 << 1) | ||
2176 | #define USBCTL_DISCONN_THIS (1 << 0) | ||
2177 | |||
2178 | static inline void nc_dump_usbctl (struct usbnet *dev, u16 usbctl) | ||
2179 | { | ||
2180 | if (!netif_msg_link (dev)) | ||
2181 | return; | ||
2182 | devdbg (dev, "net1080 %s-%s usbctl 0x%x:%s%s%s%s%s;" | ||
2183 | " this%s%s;" | ||
2184 | " other%s%s; r/o 0x%x", | ||
2185 | dev->udev->bus->bus_name, dev->udev->devpath, | ||
2186 | usbctl, | ||
2187 | (usbctl & USBCTL_ENABLE_LANG) ? " lang" : "", | ||
2188 | (usbctl & USBCTL_ENABLE_MFGR) ? " mfgr" : "", | ||
2189 | (usbctl & USBCTL_ENABLE_PROD) ? " prod" : "", | ||
2190 | (usbctl & USBCTL_ENABLE_SERIAL) ? " serial" : "", | ||
2191 | (usbctl & USBCTL_ENABLE_DEFAULTS) ? " defaults" : "", | ||
2192 | |||
2193 | (usbctl & USBCTL_FLUSH_OTHER) ? " FLUSH" : "", | ||
2194 | (usbctl & USBCTL_DISCONN_OTHER) ? " DIS" : "", | ||
2195 | (usbctl & USBCTL_FLUSH_THIS) ? " FLUSH" : "", | ||
2196 | (usbctl & USBCTL_DISCONN_THIS) ? " DIS" : "", | ||
2197 | usbctl & ~USBCTL_WRITABLE_MASK | ||
2198 | ); | ||
2199 | } | ||
2200 | |||
2201 | /*-------------------------------------------------------------------------*/ | ||
2202 | |||
2203 | /* | ||
2204 | * Status register | ||
2205 | */ | ||
2206 | |||
2207 | #define STATUS_PORT_A (1 << 15) | ||
2208 | |||
2209 | #define STATUS_CONN_OTHER (1 << 14) | ||
2210 | #define STATUS_SUSPEND_OTHER (1 << 13) | ||
2211 | #define STATUS_MAILBOX_OTHER (1 << 12) | ||
2212 | #define STATUS_PACKETS_OTHER(n) (((n) >> 8) && 0x03) | ||
2213 | |||
2214 | #define STATUS_CONN_THIS (1 << 6) | ||
2215 | #define STATUS_SUSPEND_THIS (1 << 5) | ||
2216 | #define STATUS_MAILBOX_THIS (1 << 4) | ||
2217 | #define STATUS_PACKETS_THIS(n) (((n) >> 0) && 0x03) | ||
2218 | |||
2219 | #define STATUS_UNSPEC_MASK 0x0c8c | ||
2220 | #define STATUS_NOISE_MASK ((u16)~(0x0303|STATUS_UNSPEC_MASK)) | ||
2221 | |||
2222 | |||
2223 | static inline void nc_dump_status (struct usbnet *dev, u16 status) | ||
2224 | { | ||
2225 | if (!netif_msg_link (dev)) | ||
2226 | return; | ||
2227 | devdbg (dev, "net1080 %s-%s status 0x%x:" | ||
2228 | " this (%c) PKT=%d%s%s%s;" | ||
2229 | " other PKT=%d%s%s%s; unspec 0x%x", | ||
2230 | dev->udev->bus->bus_name, dev->udev->devpath, | ||
2231 | status, | ||
2232 | |||
2233 | // XXX the packet counts don't seem right | ||
2234 | // (1 at reset, not 0); maybe UNSPEC too | ||
2235 | |||
2236 | (status & STATUS_PORT_A) ? 'A' : 'B', | ||
2237 | STATUS_PACKETS_THIS (status), | ||
2238 | (status & STATUS_CONN_THIS) ? " CON" : "", | ||
2239 | (status & STATUS_SUSPEND_THIS) ? " SUS" : "", | ||
2240 | (status & STATUS_MAILBOX_THIS) ? " MBOX" : "", | ||
2241 | |||
2242 | STATUS_PACKETS_OTHER (status), | ||
2243 | (status & STATUS_CONN_OTHER) ? " CON" : "", | ||
2244 | (status & STATUS_SUSPEND_OTHER) ? " SUS" : "", | ||
2245 | (status & STATUS_MAILBOX_OTHER) ? " MBOX" : "", | ||
2246 | |||
2247 | status & STATUS_UNSPEC_MASK | ||
2248 | ); | ||
2249 | } | ||
2250 | |||
2251 | /*-------------------------------------------------------------------------*/ | ||
2252 | |||
2253 | /* | ||
2254 | * TTL register | ||
2255 | */ | ||
2256 | |||
2257 | #define TTL_THIS(ttl) (0x00ff & ttl) | ||
2258 | #define TTL_OTHER(ttl) (0x00ff & (ttl >> 8)) | ||
2259 | #define MK_TTL(this,other) ((u16)(((other)<<8)|(0x00ff&(this)))) | ||
2260 | |||
2261 | static inline void nc_dump_ttl (struct usbnet *dev, u16 ttl) | ||
2262 | { | ||
2263 | if (netif_msg_link (dev)) | ||
2264 | devdbg (dev, "net1080 %s-%s ttl 0x%x this = %d, other = %d", | ||
2265 | dev->udev->bus->bus_name, dev->udev->devpath, | ||
2266 | ttl, TTL_THIS (ttl), TTL_OTHER (ttl)); | ||
2267 | } | ||
2268 | |||
2269 | /*-------------------------------------------------------------------------*/ | ||
2270 | |||
2271 | static int net1080_reset (struct usbnet *dev) | ||
2272 | { | ||
2273 | u16 usbctl, status, ttl; | ||
2274 | u16 *vp = kmalloc (sizeof (u16), GFP_KERNEL); | ||
2275 | int retval; | ||
2276 | |||
2277 | if (!vp) | ||
2278 | return -ENOMEM; | ||
2279 | |||
2280 | // nc_dump_registers (dev); | ||
2281 | |||
2282 | if ((retval = nc_register_read (dev, REG_STATUS, vp)) < 0) { | ||
2283 | dbg ("can't read %s-%s status: %d", | ||
2284 | dev->udev->bus->bus_name, dev->udev->devpath, retval); | ||
2285 | goto done; | ||
2286 | } | ||
2287 | status = *vp; | ||
2288 | nc_dump_status (dev, status); | ||
2289 | |||
2290 | if ((retval = nc_register_read (dev, REG_USBCTL, vp)) < 0) { | ||
2291 | dbg ("can't read USBCTL, %d", retval); | ||
2292 | goto done; | ||
2293 | } | ||
2294 | usbctl = *vp; | ||
2295 | nc_dump_usbctl (dev, usbctl); | ||
2296 | |||
2297 | nc_register_write (dev, REG_USBCTL, | ||
2298 | USBCTL_FLUSH_THIS | USBCTL_FLUSH_OTHER); | ||
2299 | |||
2300 | if ((retval = nc_register_read (dev, REG_TTL, vp)) < 0) { | ||
2301 | dbg ("can't read TTL, %d", retval); | ||
2302 | goto done; | ||
2303 | } | ||
2304 | ttl = *vp; | ||
2305 | // nc_dump_ttl (dev, ttl); | ||
2306 | |||
2307 | nc_register_write (dev, REG_TTL, | ||
2308 | MK_TTL (NC_READ_TTL_MS, TTL_OTHER (ttl)) ); | ||
2309 | dbg ("%s: assigned TTL, %d ms", dev->net->name, NC_READ_TTL_MS); | ||
2310 | |||
2311 | if (netif_msg_link (dev)) | ||
2312 | devinfo (dev, "port %c, peer %sconnected", | ||
2313 | (status & STATUS_PORT_A) ? 'A' : 'B', | ||
2314 | (status & STATUS_CONN_OTHER) ? "" : "dis" | ||
2315 | ); | ||
2316 | retval = 0; | ||
2317 | |||
2318 | done: | ||
2319 | kfree (vp); | ||
2320 | return retval; | ||
2321 | } | ||
2322 | |||
2323 | static int net1080_check_connect (struct usbnet *dev) | ||
2324 | { | ||
2325 | int retval; | ||
2326 | u16 status; | ||
2327 | u16 *vp = kmalloc (sizeof (u16), GFP_KERNEL); | ||
2328 | |||
2329 | if (!vp) | ||
2330 | return -ENOMEM; | ||
2331 | retval = nc_register_read (dev, REG_STATUS, vp); | ||
2332 | status = *vp; | ||
2333 | kfree (vp); | ||
2334 | if (retval != 0) { | ||
2335 | dbg ("%s net1080_check_conn read - %d", dev->net->name, retval); | ||
2336 | return retval; | ||
2337 | } | ||
2338 | if ((status & STATUS_CONN_OTHER) != STATUS_CONN_OTHER) | ||
2339 | return -ENOLINK; | ||
2340 | return 0; | ||
2341 | } | ||
2342 | |||
2343 | static void nc_flush_complete (struct urb *urb, struct pt_regs *regs) | ||
2344 | { | ||
2345 | kfree (urb->context); | ||
2346 | usb_free_urb(urb); | ||
2347 | } | ||
2348 | |||
2349 | static void nc_ensure_sync (struct usbnet *dev) | ||
2350 | { | ||
2351 | dev->frame_errors++; | ||
2352 | if (dev->frame_errors > 5) { | ||
2353 | struct urb *urb; | ||
2354 | struct usb_ctrlrequest *req; | ||
2355 | int status; | ||
2356 | |||
2357 | /* Send a flush */ | ||
2358 | urb = usb_alloc_urb (0, SLAB_ATOMIC); | ||
2359 | if (!urb) | ||
2360 | return; | ||
2361 | |||
2362 | req = kmalloc (sizeof *req, GFP_ATOMIC); | ||
2363 | if (!req) { | ||
2364 | usb_free_urb (urb); | ||
2365 | return; | ||
2366 | } | ||
2367 | |||
2368 | req->bRequestType = USB_DIR_OUT | ||
2369 | | USB_TYPE_VENDOR | ||
2370 | | USB_RECIP_DEVICE; | ||
2371 | req->bRequest = REQUEST_REGISTER; | ||
2372 | req->wValue = cpu_to_le16 (USBCTL_FLUSH_THIS | ||
2373 | | USBCTL_FLUSH_OTHER); | ||
2374 | req->wIndex = cpu_to_le16 (REG_USBCTL); | ||
2375 | req->wLength = cpu_to_le16 (0); | ||
2376 | |||
2377 | /* queue an async control request, we don't need | ||
2378 | * to do anything when it finishes except clean up. | ||
2379 | */ | ||
2380 | usb_fill_control_urb (urb, dev->udev, | ||
2381 | usb_sndctrlpipe (dev->udev, 0), | ||
2382 | (unsigned char *) req, | ||
2383 | NULL, 0, | ||
2384 | nc_flush_complete, req); | ||
2385 | status = usb_submit_urb (urb, GFP_ATOMIC); | ||
2386 | if (status) { | ||
2387 | kfree (req); | ||
2388 | usb_free_urb (urb); | ||
2389 | return; | ||
2390 | } | ||
2391 | |||
2392 | if (netif_msg_rx_err (dev)) | ||
2393 | devdbg (dev, "flush net1080; too many framing errors"); | ||
2394 | dev->frame_errors = 0; | ||
2395 | } | ||
2396 | } | ||
2397 | |||
2398 | static int net1080_rx_fixup (struct usbnet *dev, struct sk_buff *skb) | ||
2399 | { | ||
2400 | struct nc_header *header; | ||
2401 | struct nc_trailer *trailer; | ||
2402 | u16 hdr_len, packet_len; | ||
2403 | |||
2404 | if (!(skb->len & 0x01) | ||
2405 | || MIN_FRAMED > skb->len | ||
2406 | || skb->len > FRAMED_SIZE (dev->net->mtu)) { | ||
2407 | dev->stats.rx_frame_errors++; | ||
2408 | dbg ("rx framesize %d range %d..%d mtu %d", skb->len, | ||
2409 | (int)MIN_FRAMED, (int)FRAMED_SIZE (dev->net->mtu), | ||
2410 | dev->net->mtu); | ||
2411 | nc_ensure_sync (dev); | ||
2412 | return 0; | ||
2413 | } | ||
2414 | |||
2415 | header = (struct nc_header *) skb->data; | ||
2416 | hdr_len = le16_to_cpup (&header->hdr_len); | ||
2417 | packet_len = le16_to_cpup (&header->packet_len); | ||
2418 | if (FRAMED_SIZE (packet_len) > MAX_PACKET) { | ||
2419 | dev->stats.rx_frame_errors++; | ||
2420 | dbg ("packet too big, %d", packet_len); | ||
2421 | nc_ensure_sync (dev); | ||
2422 | return 0; | ||
2423 | } else if (hdr_len < MIN_HEADER) { | ||
2424 | dev->stats.rx_frame_errors++; | ||
2425 | dbg ("header too short, %d", hdr_len); | ||
2426 | nc_ensure_sync (dev); | ||
2427 | return 0; | ||
2428 | } else if (hdr_len > MIN_HEADER) { | ||
2429 | // out of band data for us? | ||
2430 | dbg ("header OOB, %d bytes", hdr_len - MIN_HEADER); | ||
2431 | nc_ensure_sync (dev); | ||
2432 | // switch (vendor/product ids) { ... } | ||
2433 | } | ||
2434 | skb_pull (skb, hdr_len); | ||
2435 | |||
2436 | trailer = (struct nc_trailer *) | ||
2437 | (skb->data + skb->len - sizeof *trailer); | ||
2438 | skb_trim (skb, skb->len - sizeof *trailer); | ||
2439 | |||
2440 | if ((packet_len & 0x01) == 0) { | ||
2441 | if (skb->data [packet_len] != PAD_BYTE) { | ||
2442 | dev->stats.rx_frame_errors++; | ||
2443 | dbg ("bad pad"); | ||
2444 | return 0; | ||
2445 | } | ||
2446 | skb_trim (skb, skb->len - 1); | ||
2447 | } | ||
2448 | if (skb->len != packet_len) { | ||
2449 | dev->stats.rx_frame_errors++; | ||
2450 | dbg ("bad packet len %d (expected %d)", | ||
2451 | skb->len, packet_len); | ||
2452 | nc_ensure_sync (dev); | ||
2453 | return 0; | ||
2454 | } | ||
2455 | if (header->packet_id != get_unaligned (&trailer->packet_id)) { | ||
2456 | dev->stats.rx_fifo_errors++; | ||
2457 | dbg ("(2+ dropped) rx packet_id mismatch 0x%x 0x%x", | ||
2458 | le16_to_cpu (header->packet_id), | ||
2459 | le16_to_cpu (trailer->packet_id)); | ||
2460 | return 0; | ||
2461 | } | ||
2462 | #if 0 | ||
2463 | devdbg (dev, "frame <rx h %d p %d id %d", header->hdr_len, | ||
2464 | header->packet_len, header->packet_id); | ||
2465 | #endif | ||
2466 | dev->frame_errors = 0; | ||
2467 | return 1; | ||
2468 | } | ||
2469 | |||
2470 | static struct sk_buff * | ||
2471 | net1080_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags) | ||
2472 | { | ||
2473 | int padlen; | ||
2474 | struct sk_buff *skb2; | ||
2475 | |||
2476 | padlen = ((skb->len + sizeof (struct nc_header) | ||
2477 | + sizeof (struct nc_trailer)) & 0x01) ? 0 : 1; | ||
2478 | if (!skb_cloned (skb)) { | ||
2479 | int headroom = skb_headroom (skb); | ||
2480 | int tailroom = skb_tailroom (skb); | ||
2481 | |||
2482 | if ((padlen + sizeof (struct nc_trailer)) <= tailroom | ||
2483 | && sizeof (struct nc_header) <= headroom) | ||
2484 | /* There's enough head and tail room */ | ||
2485 | return skb; | ||
2486 | |||
2487 | if ((sizeof (struct nc_header) + padlen | ||
2488 | + sizeof (struct nc_trailer)) < | ||
2489 | (headroom + tailroom)) { | ||
2490 | /* There's enough total room, so just readjust */ | ||
2491 | skb->data = memmove (skb->head | ||
2492 | + sizeof (struct nc_header), | ||
2493 | skb->data, skb->len); | ||
2494 | skb->tail = skb->data + skb->len; | ||
2495 | return skb; | ||
2496 | } | ||
2497 | } | ||
2498 | |||
2499 | /* Create a new skb to use with the correct size */ | ||
2500 | skb2 = skb_copy_expand (skb, | ||
2501 | sizeof (struct nc_header), | ||
2502 | sizeof (struct nc_trailer) + padlen, | ||
2503 | flags); | ||
2504 | dev_kfree_skb_any (skb); | ||
2505 | return skb2; | ||
2506 | } | ||
2507 | |||
2508 | static const struct driver_info net1080_info = { | ||
2509 | .description = "NetChip TurboCONNECT", | ||
2510 | .flags = FLAG_FRAMING_NC, | ||
2511 | .reset = net1080_reset, | ||
2512 | .check_connect =net1080_check_connect, | ||
2513 | .rx_fixup = net1080_rx_fixup, | ||
2514 | .tx_fixup = net1080_tx_fixup, | ||
2515 | }; | ||
2516 | |||
2517 | #endif /* CONFIG_USB_NET1080 */ | ||
2518 | |||
2519 | |||
2520 | |||
2521 | #ifdef CONFIG_USB_PL2301 | ||
2522 | #define HAVE_HARDWARE | ||
2523 | |||
2524 | /*------------------------------------------------------------------------- | ||
2525 | * | ||
2526 | * Prolific PL-2301/PL-2302 driver ... http://www.prolifictech.com | ||
2527 | * | ||
2528 | * The protocol and handshaking used here should be bug-compatible | ||
2529 | * with the Linux 2.2 "plusb" driver, by Deti Fliegl. | ||
2530 | * | ||
2531 | *-------------------------------------------------------------------------*/ | ||
2532 | |||
2533 | /* | ||
2534 | * Bits 0-4 can be used for software handshaking; they're set from | ||
2535 | * one end, cleared from the other, "read" with the interrupt byte. | ||
2536 | */ | ||
2537 | #define PL_S_EN (1<<7) /* (feature only) suspend enable */ | ||
2538 | /* reserved bit -- rx ready (6) ? */ | ||
2539 | #define PL_TX_READY (1<<5) /* (interrupt only) transmit ready */ | ||
2540 | #define PL_RESET_OUT (1<<4) /* reset output pipe */ | ||
2541 | #define PL_RESET_IN (1<<3) /* reset input pipe */ | ||
2542 | #define PL_TX_C (1<<2) /* transmission complete */ | ||
2543 | #define PL_TX_REQ (1<<1) /* transmission received */ | ||
2544 | #define PL_PEER_E (1<<0) /* peer exists */ | ||
2545 | |||
2546 | static inline int | ||
2547 | pl_vendor_req (struct usbnet *dev, u8 req, u8 val, u8 index) | ||
2548 | { | ||
2549 | return usb_control_msg (dev->udev, | ||
2550 | usb_rcvctrlpipe (dev->udev, 0), | ||
2551 | req, | ||
2552 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
2553 | val, index, | ||
2554 | NULL, 0, | ||
2555 | CONTROL_TIMEOUT_MS); | ||
2556 | } | ||
2557 | |||
2558 | static inline int | ||
2559 | pl_clear_QuickLink_features (struct usbnet *dev, int val) | ||
2560 | { | ||
2561 | return pl_vendor_req (dev, 1, (u8) val, 0); | ||
2562 | } | ||
2563 | |||
2564 | static inline int | ||
2565 | pl_set_QuickLink_features (struct usbnet *dev, int val) | ||
2566 | { | ||
2567 | return pl_vendor_req (dev, 3, (u8) val, 0); | ||
2568 | } | ||
2569 | |||
2570 | /*-------------------------------------------------------------------------*/ | ||
2571 | |||
2572 | static int pl_reset (struct usbnet *dev) | ||
2573 | { | ||
2574 | /* some units seem to need this reset, others reject it utterly. | ||
2575 | * FIXME be more like "naplink" or windows drivers. | ||
2576 | */ | ||
2577 | (void) pl_set_QuickLink_features (dev, | ||
2578 | PL_S_EN|PL_RESET_OUT|PL_RESET_IN|PL_PEER_E); | ||
2579 | return 0; | ||
2580 | } | ||
2581 | |||
2582 | static const struct driver_info prolific_info = { | ||
2583 | .description = "Prolific PL-2301/PL-2302", | ||
2584 | .flags = FLAG_NO_SETINT, | ||
2585 | /* some PL-2302 versions seem to fail usb_set_interface() */ | ||
2586 | .reset = pl_reset, | ||
2587 | }; | ||
2588 | |||
2589 | #endif /* CONFIG_USB_PL2301 */ | ||
2590 | |||
2591 | |||
2592 | #ifdef CONFIG_USB_KC2190 | ||
2593 | #define HAVE_HARDWARE | ||
2594 | static const struct driver_info kc2190_info = { | ||
2595 | .description = "KC Technology KC-190", | ||
2596 | }; | ||
2597 | #endif /* CONFIG_USB_KC2190 */ | ||
2598 | |||
2599 | |||
2600 | #ifdef CONFIG_USB_ARMLINUX | ||
2601 | #define HAVE_HARDWARE | ||
2602 | |||
2603 | /*------------------------------------------------------------------------- | ||
2604 | * | ||
2605 | * Intel's SA-1100 chip integrates basic USB support, and is used | ||
2606 | * in PDAs like some iPaqs, the Yopy, some Zaurus models, and more. | ||
2607 | * When they run Linux, arch/arm/mach-sa1100/usb-eth.c may be used to | ||
2608 | * network using minimal USB framing data. | ||
2609 | * | ||
2610 | * This describes the driver currently in standard ARM Linux kernels. | ||
2611 | * The Zaurus uses a different driver (see later). | ||
2612 | * | ||
2613 | * PXA25x and PXA210 use XScale cores (ARM v5TE) with better USB support | ||
2614 | * and different USB endpoint numbering than the SA1100 devices. The | ||
2615 | * mach-pxa/usb-eth.c driver re-uses the device ids from mach-sa1100 | ||
2616 | * so we rely on the endpoint descriptors. | ||
2617 | * | ||
2618 | *-------------------------------------------------------------------------*/ | ||
2619 | |||
2620 | static const struct driver_info linuxdev_info = { | ||
2621 | .description = "Linux Device", | ||
2622 | .check_connect = always_connected, | ||
2623 | }; | ||
2624 | |||
2625 | static const struct driver_info yopy_info = { | ||
2626 | .description = "Yopy", | ||
2627 | .check_connect = always_connected, | ||
2628 | }; | ||
2629 | |||
2630 | static const struct driver_info blob_info = { | ||
2631 | .description = "Boot Loader OBject", | ||
2632 | .check_connect = always_connected, | ||
2633 | }; | ||
2634 | |||
2635 | #endif /* CONFIG_USB_ARMLINUX */ | ||
2636 | |||
2637 | |||
2638 | #ifdef CONFIG_USB_ZAURUS | ||
2639 | #define HAVE_HARDWARE | ||
2640 | |||
2641 | #include <linux/crc32.h> | ||
2642 | |||
2643 | /*------------------------------------------------------------------------- | ||
2644 | * | ||
2645 | * Zaurus is also a SA-1110 based PDA, but one using a different driver | ||
2646 | * (and framing) for its USB slave/gadget controller than the case above. | ||
2647 | * | ||
2648 | * For the current version of that driver, the main way that framing is | ||
2649 | * nonstandard (also from perspective of the CDC ethernet model!) is a | ||
2650 | * crc32, added to help detect when some sa1100 usb-to-memory DMA errata | ||
2651 | * haven't been fully worked around. Also, all Zaurii use the same | ||
2652 | * default Ethernet address. | ||
2653 | * | ||
2654 | * PXA based models use the same framing, and also can't implement | ||
2655 | * set_interface properly. | ||
2656 | * | ||
2657 | * All known Zaurii lie about their standards conformance. Most lie by | ||
2658 | * saying they support CDC Ethernet. Some lie and say they support CDC | ||
2659 | * MDLM (as if for access to cell phone modems). Someone, please beat | ||
2660 | * on Sharp (and other such vendors) for a while with a cluestick. | ||
2661 | * | ||
2662 | *-------------------------------------------------------------------------*/ | ||
2663 | |||
2664 | static struct sk_buff * | ||
2665 | zaurus_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags) | ||
2666 | { | ||
2667 | int padlen; | ||
2668 | struct sk_buff *skb2; | ||
2669 | |||
2670 | padlen = 2; | ||
2671 | if (!skb_cloned (skb)) { | ||
2672 | int tailroom = skb_tailroom (skb); | ||
2673 | if ((padlen + 4) <= tailroom) | ||
2674 | goto done; | ||
2675 | } | ||
2676 | skb2 = skb_copy_expand (skb, 0, 4 + padlen, flags); | ||
2677 | dev_kfree_skb_any (skb); | ||
2678 | skb = skb2; | ||
2679 | if (skb) { | ||
2680 | u32 fcs; | ||
2681 | done: | ||
2682 | fcs = crc32_le (~0, skb->data, skb->len); | ||
2683 | fcs = ~fcs; | ||
2684 | |||
2685 | *skb_put (skb, 1) = fcs & 0xff; | ||
2686 | *skb_put (skb, 1) = (fcs>> 8) & 0xff; | ||
2687 | *skb_put (skb, 1) = (fcs>>16) & 0xff; | ||
2688 | *skb_put (skb, 1) = (fcs>>24) & 0xff; | ||
2689 | } | ||
2690 | return skb; | ||
2691 | } | ||
2692 | |||
2693 | static const struct driver_info zaurus_sl5x00_info = { | ||
2694 | .description = "Sharp Zaurus SL-5x00", | ||
2695 | .flags = FLAG_FRAMING_Z, | ||
2696 | .check_connect = always_connected, | ||
2697 | .bind = generic_cdc_bind, | ||
2698 | .unbind = cdc_unbind, | ||
2699 | .tx_fixup = zaurus_tx_fixup, | ||
2700 | }; | ||
2701 | #define ZAURUS_STRONGARM_INFO ((unsigned long)&zaurus_sl5x00_info) | ||
2702 | |||
2703 | static const struct driver_info zaurus_pxa_info = { | ||
2704 | .description = "Sharp Zaurus, PXA-2xx based", | ||
2705 | .flags = FLAG_FRAMING_Z, | ||
2706 | .check_connect = always_connected, | ||
2707 | .bind = generic_cdc_bind, | ||
2708 | .unbind = cdc_unbind, | ||
2709 | .tx_fixup = zaurus_tx_fixup, | ||
2710 | }; | ||
2711 | #define ZAURUS_PXA_INFO ((unsigned long)&zaurus_pxa_info) | ||
2712 | |||
2713 | static const struct driver_info olympus_mxl_info = { | ||
2714 | .description = "Olympus R1000", | ||
2715 | .flags = FLAG_FRAMING_Z, | ||
2716 | .check_connect = always_connected, | ||
2717 | .bind = generic_cdc_bind, | ||
2718 | .unbind = cdc_unbind, | ||
2719 | .tx_fixup = zaurus_tx_fixup, | ||
2720 | }; | ||
2721 | #define OLYMPUS_MXL_INFO ((unsigned long)&olympus_mxl_info) | ||
2722 | |||
2723 | |||
2724 | /* Some more recent products using Lineo/Belcarra code will wrongly claim | ||
2725 | * CDC MDLM conformance. They aren't conformant: data endpoints live | ||
2726 | * in the control interface, there's no data interface, and it's not used | ||
2727 | * to talk to a cell phone radio. But at least we can detect these two | ||
2728 | * pseudo-classes, rather than growing this product list with entries for | ||
2729 | * each new nonconformant product (sigh). | ||
2730 | */ | ||
2731 | static const u8 safe_guid[16] = { | ||
2732 | 0x5d, 0x34, 0xcf, 0x66, 0x11, 0x18, 0x11, 0xd6, | ||
2733 | 0xa2, 0x1a, 0x00, 0x01, 0x02, 0xca, 0x9a, 0x7f, | ||
2734 | }; | ||
2735 | static const u8 blan_guid[16] = { | ||
2736 | 0x74, 0xf0, 0x3d, 0xbd, 0x1e, 0xc1, 0x44, 0x70, | ||
2737 | 0xa3, 0x67, 0x71, 0x34, 0xc9, 0xf5, 0x54, 0x37, | ||
2738 | }; | ||
2739 | |||
2740 | static int blan_mdlm_bind (struct usbnet *dev, struct usb_interface *intf) | ||
2741 | { | ||
2742 | u8 *buf = intf->cur_altsetting->extra; | ||
2743 | int len = intf->cur_altsetting->extralen; | ||
2744 | struct usb_cdc_mdlm_desc *desc = NULL; | ||
2745 | struct usb_cdc_mdlm_detail_desc *detail = NULL; | ||
2746 | |||
2747 | while (len > 3) { | ||
2748 | if (buf [1] != USB_DT_CS_INTERFACE) | ||
2749 | goto next_desc; | ||
2750 | |||
2751 | /* use bDescriptorSubType, and just verify that we get a | ||
2752 | * "BLAN" (or "SAFE") descriptor. | ||
2753 | */ | ||
2754 | switch (buf [2]) { | ||
2755 | case USB_CDC_MDLM_TYPE: | ||
2756 | if (desc) { | ||
2757 | dev_dbg (&intf->dev, "extra MDLM\n"); | ||
2758 | goto bad_desc; | ||
2759 | } | ||
2760 | desc = (void *) buf; | ||
2761 | if (desc->bLength != sizeof *desc) { | ||
2762 | dev_dbg (&intf->dev, "MDLM len %u\n", | ||
2763 | desc->bLength); | ||
2764 | goto bad_desc; | ||
2765 | } | ||
2766 | /* expect bcdVersion 1.0, ignore */ | ||
2767 | if (memcmp(&desc->bGUID, blan_guid, 16) | ||
2768 | && memcmp(&desc->bGUID, safe_guid, 16) ) { | ||
2769 | /* hey, this one might _really_ be MDLM! */ | ||
2770 | dev_dbg (&intf->dev, "MDLM guid\n"); | ||
2771 | goto bad_desc; | ||
2772 | } | ||
2773 | break; | ||
2774 | case USB_CDC_MDLM_DETAIL_TYPE: | ||
2775 | if (detail) { | ||
2776 | dev_dbg (&intf->dev, "extra MDLM detail\n"); | ||
2777 | goto bad_desc; | ||
2778 | } | ||
2779 | detail = (void *) buf; | ||
2780 | switch (detail->bGuidDescriptorType) { | ||
2781 | case 0: /* "SAFE" */ | ||
2782 | if (detail->bLength != (sizeof *detail + 2)) | ||
2783 | goto bad_detail; | ||
2784 | break; | ||
2785 | case 1: /* "BLAN" */ | ||
2786 | if (detail->bLength != (sizeof *detail + 3)) | ||
2787 | goto bad_detail; | ||
2788 | break; | ||
2789 | default: | ||
2790 | goto bad_detail; | ||
2791 | } | ||
2792 | |||
2793 | /* assuming we either noticed BLAN already, or will | ||
2794 | * find it soon, there are some data bytes here: | ||
2795 | * - bmNetworkCapabilities (unused) | ||
2796 | * - bmDataCapabilities (bits, see below) | ||
2797 | * - bPad (ignored, for PADAFTER -- BLAN-only) | ||
2798 | * bits are: | ||
2799 | * - 0x01 -- Zaurus framing (add CRC) | ||
2800 | * - 0x02 -- PADBEFORE (CRC includes some padding) | ||
2801 | * - 0x04 -- PADAFTER (some padding after CRC) | ||
2802 | * - 0x08 -- "fermat" packet mangling (for hw bugs) | ||
2803 | * the PADBEFORE appears not to matter; we interop | ||
2804 | * with devices that use it and those that don't. | ||
2805 | */ | ||
2806 | if ((detail->bDetailData[1] & ~02) != 0x01) { | ||
2807 | /* bmDataCapabilites == 0 would be fine too, | ||
2808 | * but framing is minidriver-coupled for now. | ||
2809 | */ | ||
2810 | bad_detail: | ||
2811 | dev_dbg (&intf->dev, | ||
2812 | "bad MDLM detail, %d %d %d\n", | ||
2813 | detail->bLength, | ||
2814 | detail->bDetailData[0], | ||
2815 | detail->bDetailData[2]); | ||
2816 | goto bad_desc; | ||
2817 | } | ||
2818 | break; | ||
2819 | } | ||
2820 | next_desc: | ||
2821 | len -= buf [0]; /* bLength */ | ||
2822 | buf += buf [0]; | ||
2823 | } | ||
2824 | |||
2825 | if (!desc || !detail) { | ||
2826 | dev_dbg (&intf->dev, "missing cdc mdlm %s%sdescriptor\n", | ||
2827 | desc ? "" : "func ", | ||
2828 | detail ? "" : "detail "); | ||
2829 | goto bad_desc; | ||
2830 | } | ||
2831 | |||
2832 | /* There's probably a CDC Ethernet descriptor there, but we can't | ||
2833 | * rely on the Ethernet address it provides since not all vendors | ||
2834 | * bother to make it unique. Likewise there's no point in tracking | ||
2835 | * of the CDC event notifications. | ||
2836 | */ | ||
2837 | return get_endpoints (dev, intf); | ||
2838 | |||
2839 | bad_desc: | ||
2840 | dev_info (&dev->udev->dev, "unsupported MDLM descriptors\n"); | ||
2841 | return -ENODEV; | ||
2842 | } | ||
2843 | |||
2844 | static const struct driver_info bogus_mdlm_info = { | ||
2845 | .description = "pseudo-MDLM (BLAN) device", | ||
2846 | .flags = FLAG_FRAMING_Z, | ||
2847 | .check_connect = always_connected, | ||
2848 | .tx_fixup = zaurus_tx_fixup, | ||
2849 | .bind = blan_mdlm_bind, | ||
2850 | }; | ||
2851 | |||
2852 | #else | ||
2853 | |||
2854 | /* blacklist all those devices */ | ||
2855 | #define ZAURUS_STRONGARM_INFO 0 | ||
2856 | #define ZAURUS_PXA_INFO 0 | ||
2857 | #define OLYMPUS_MXL_INFO 0 | ||
2858 | |||
2859 | #endif | ||
2860 | 222 | ||
2861 | 223 | ||
2862 | /*------------------------------------------------------------------------- | 224 | /*------------------------------------------------------------------------- |
@@ -2868,22 +230,12 @@ static const struct driver_info bogus_mdlm_info = { | |||
2868 | static int usbnet_change_mtu (struct net_device *net, int new_mtu) | 230 | static int usbnet_change_mtu (struct net_device *net, int new_mtu) |
2869 | { | 231 | { |
2870 | struct usbnet *dev = netdev_priv(net); | 232 | struct usbnet *dev = netdev_priv(net); |
233 | int ll_mtu = new_mtu + net->hard_header_len; | ||
2871 | 234 | ||
2872 | if (new_mtu <= MIN_PACKET || new_mtu > MAX_PACKET) | 235 | if (new_mtu <= 0 || ll_mtu > dev->hard_mtu) |
2873 | return -EINVAL; | 236 | return -EINVAL; |
2874 | #ifdef CONFIG_USB_NET1080 | ||
2875 | if (((dev->driver_info->flags) & FLAG_FRAMING_NC)) { | ||
2876 | if (FRAMED_SIZE (new_mtu) > MAX_PACKET) | ||
2877 | return -EINVAL; | ||
2878 | } | ||
2879 | #endif | ||
2880 | #ifdef CONFIG_USB_GENESYS | ||
2881 | if (((dev->driver_info->flags) & FLAG_FRAMING_GL) | ||
2882 | && new_mtu > GL_MAX_PACKET_LEN) | ||
2883 | return -EINVAL; | ||
2884 | #endif | ||
2885 | // no second zero-length packet read wanted after mtu-sized packets | 237 | // no second zero-length packet read wanted after mtu-sized packets |
2886 | if (((new_mtu + sizeof (struct ethhdr)) % dev->maxpacket) == 0) | 238 | if ((ll_mtu % dev->maxpacket) == 0) |
2887 | return -EDOM; | 239 | return -EDOM; |
2888 | net->mtu = new_mtu; | 240 | net->mtu = new_mtu; |
2889 | return 0; | 241 | return 0; |
@@ -2922,7 +274,7 @@ static void defer_bh(struct usbnet *dev, struct sk_buff *skb, struct sk_buff_hea | |||
2922 | * NOTE: annoying asymmetry: if it's active, schedule_work() fails, | 274 | * NOTE: annoying asymmetry: if it's active, schedule_work() fails, |
2923 | * but tasklet_schedule() doesn't. hope the failure is rare. | 275 | * but tasklet_schedule() doesn't. hope the failure is rare. |
2924 | */ | 276 | */ |
2925 | static void defer_kevent (struct usbnet *dev, int work) | 277 | void usbnet_defer_kevent (struct usbnet *dev, int work) |
2926 | { | 278 | { |
2927 | set_bit (work, &dev->flags); | 279 | set_bit (work, &dev->flags); |
2928 | if (!schedule_work (&dev->kevent)) | 280 | if (!schedule_work (&dev->kevent)) |
@@ -2930,50 +282,24 @@ static void defer_kevent (struct usbnet *dev, int work) | |||
2930 | else | 282 | else |
2931 | devdbg (dev, "kevent %d scheduled", work); | 283 | devdbg (dev, "kevent %d scheduled", work); |
2932 | } | 284 | } |
285 | EXPORT_SYMBOL_GPL(usbnet_defer_kevent); | ||
2933 | 286 | ||
2934 | /*-------------------------------------------------------------------------*/ | 287 | /*-------------------------------------------------------------------------*/ |
2935 | 288 | ||
2936 | static void rx_complete (struct urb *urb, struct pt_regs *regs); | 289 | static void rx_complete (struct urb *urb, struct pt_regs *regs); |
2937 | 290 | ||
2938 | static void rx_submit (struct usbnet *dev, struct urb *urb, int flags) | 291 | static void rx_submit (struct usbnet *dev, struct urb *urb, unsigned flags) |
2939 | { | 292 | { |
2940 | struct sk_buff *skb; | 293 | struct sk_buff *skb; |
2941 | struct skb_data *entry; | 294 | struct skb_data *entry; |
2942 | int retval = 0; | 295 | int retval = 0; |
2943 | unsigned long lockflags; | 296 | unsigned long lockflags; |
2944 | size_t size; | 297 | size_t size = dev->rx_urb_size; |
2945 | |||
2946 | #ifdef CONFIG_USB_NET1080 | ||
2947 | if (dev->driver_info->flags & FLAG_FRAMING_NC) | ||
2948 | size = FRAMED_SIZE (dev->net->mtu); | ||
2949 | else | ||
2950 | #endif | ||
2951 | #ifdef CONFIG_USB_GENESYS | ||
2952 | if (dev->driver_info->flags & FLAG_FRAMING_GL) | ||
2953 | size = GL_RCV_BUF_SIZE; | ||
2954 | else | ||
2955 | #endif | ||
2956 | #ifdef CONFIG_USB_ZAURUS | ||
2957 | if (dev->driver_info->flags & FLAG_FRAMING_Z) | ||
2958 | size = 6 + (sizeof (struct ethhdr) + dev->net->mtu); | ||
2959 | else | ||
2960 | #endif | ||
2961 | #ifdef CONFIG_USB_RNDIS | ||
2962 | if (dev->driver_info->flags & FLAG_FRAMING_RN) | ||
2963 | size = RNDIS_MAX_TRANSFER; | ||
2964 | else | ||
2965 | #endif | ||
2966 | #ifdef CONFIG_USB_AX8817X | ||
2967 | if (dev->driver_info->flags & FLAG_FRAMING_AX) | ||
2968 | size = 2048; | ||
2969 | else | ||
2970 | #endif | ||
2971 | size = (sizeof (struct ethhdr) + dev->net->mtu); | ||
2972 | 298 | ||
2973 | if ((skb = alloc_skb (size + NET_IP_ALIGN, flags)) == NULL) { | 299 | if ((skb = alloc_skb (size + NET_IP_ALIGN, flags)) == NULL) { |
2974 | if (netif_msg_rx_err (dev)) | 300 | if (netif_msg_rx_err (dev)) |
2975 | devdbg (dev, "no rx skb"); | 301 | devdbg (dev, "no rx skb"); |
2976 | defer_kevent (dev, EVENT_RX_MEMORY); | 302 | usbnet_defer_kevent (dev, EVENT_RX_MEMORY); |
2977 | usb_free_urb (urb); | 303 | usb_free_urb (urb); |
2978 | return; | 304 | return; |
2979 | } | 305 | } |
@@ -2987,7 +313,6 @@ static void rx_submit (struct usbnet *dev, struct urb *urb, int flags) | |||
2987 | 313 | ||
2988 | usb_fill_bulk_urb (urb, dev->udev, dev->in, | 314 | usb_fill_bulk_urb (urb, dev->udev, dev->in, |
2989 | skb->data, size, rx_complete, skb); | 315 | skb->data, size, rx_complete, skb); |
2990 | urb->transfer_flags |= URB_ASYNC_UNLINK; | ||
2991 | 316 | ||
2992 | spin_lock_irqsave (&dev->rxq.lock, lockflags); | 317 | spin_lock_irqsave (&dev->rxq.lock, lockflags); |
2993 | 318 | ||
@@ -2996,10 +321,10 @@ static void rx_submit (struct usbnet *dev, struct urb *urb, int flags) | |||
2996 | && !test_bit (EVENT_RX_HALT, &dev->flags)) { | 321 | && !test_bit (EVENT_RX_HALT, &dev->flags)) { |
2997 | switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){ | 322 | switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){ |
2998 | case -EPIPE: | 323 | case -EPIPE: |
2999 | defer_kevent (dev, EVENT_RX_HALT); | 324 | usbnet_defer_kevent (dev, EVENT_RX_HALT); |
3000 | break; | 325 | break; |
3001 | case -ENOMEM: | 326 | case -ENOMEM: |
3002 | defer_kevent (dev, EVENT_RX_MEMORY); | 327 | usbnet_defer_kevent (dev, EVENT_RX_MEMORY); |
3003 | break; | 328 | break; |
3004 | case -ENODEV: | 329 | case -ENODEV: |
3005 | if (netif_msg_ifdown (dev)) | 330 | if (netif_msg_ifdown (dev)) |
@@ -3037,7 +362,7 @@ static inline void rx_process (struct usbnet *dev, struct sk_buff *skb) | |||
3037 | // else network stack removes extra byte if we forced a short packet | 362 | // else network stack removes extra byte if we forced a short packet |
3038 | 363 | ||
3039 | if (skb->len) | 364 | if (skb->len) |
3040 | skb_return (dev, skb); | 365 | usbnet_skb_return (dev, skb); |
3041 | else { | 366 | else { |
3042 | if (netif_msg_rx_err (dev)) | 367 | if (netif_msg_rx_err (dev)) |
3043 | devdbg (dev, "drop"); | 368 | devdbg (dev, "drop"); |
@@ -3063,7 +388,7 @@ static void rx_complete (struct urb *urb, struct pt_regs *regs) | |||
3063 | switch (urb_status) { | 388 | switch (urb_status) { |
3064 | // success | 389 | // success |
3065 | case 0: | 390 | case 0: |
3066 | if (MIN_PACKET > skb->len || skb->len > MAX_PACKET) { | 391 | if (skb->len < dev->net->hard_header_len) { |
3067 | entry->state = rx_cleanup; | 392 | entry->state = rx_cleanup; |
3068 | dev->stats.rx_errors++; | 393 | dev->stats.rx_errors++; |
3069 | dev->stats.rx_length_errors++; | 394 | dev->stats.rx_length_errors++; |
@@ -3078,7 +403,7 @@ static void rx_complete (struct urb *urb, struct pt_regs *regs) | |||
3078 | // storm, recovering as needed. | 403 | // storm, recovering as needed. |
3079 | case -EPIPE: | 404 | case -EPIPE: |
3080 | dev->stats.rx_errors++; | 405 | dev->stats.rx_errors++; |
3081 | defer_kevent (dev, EVENT_RX_HALT); | 406 | usbnet_defer_kevent (dev, EVENT_RX_HALT); |
3082 | // FALLTHROUGH | 407 | // FALLTHROUGH |
3083 | 408 | ||
3084 | // software-driven interface shutdown | 409 | // software-driven interface shutdown |
@@ -3320,55 +645,58 @@ done: | |||
3320 | 645 | ||
3321 | /*-------------------------------------------------------------------------*/ | 646 | /*-------------------------------------------------------------------------*/ |
3322 | 647 | ||
3323 | static void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info) | 648 | /* ethtool methods; minidrivers may need to add some more, but |
649 | * they'll probably want to use this base set. | ||
650 | */ | ||
651 | |||
652 | void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info) | ||
3324 | { | 653 | { |
3325 | struct usbnet *dev = netdev_priv(net); | 654 | struct usbnet *dev = netdev_priv(net); |
3326 | 655 | ||
656 | /* REVISIT don't always return "usbnet" */ | ||
3327 | strncpy (info->driver, driver_name, sizeof info->driver); | 657 | strncpy (info->driver, driver_name, sizeof info->driver); |
3328 | strncpy (info->version, DRIVER_VERSION, sizeof info->version); | 658 | strncpy (info->version, DRIVER_VERSION, sizeof info->version); |
3329 | strncpy (info->fw_version, dev->driver_info->description, | 659 | strncpy (info->fw_version, dev->driver_info->description, |
3330 | sizeof info->fw_version); | 660 | sizeof info->fw_version); |
3331 | usb_make_path (dev->udev, info->bus_info, sizeof info->bus_info); | 661 | usb_make_path (dev->udev, info->bus_info, sizeof info->bus_info); |
3332 | } | 662 | } |
663 | EXPORT_SYMBOL_GPL(usbnet_get_drvinfo); | ||
3333 | 664 | ||
3334 | static u32 usbnet_get_link (struct net_device *net) | 665 | static u32 usbnet_get_link (struct net_device *net) |
3335 | { | 666 | { |
3336 | struct usbnet *dev = netdev_priv(net); | 667 | struct usbnet *dev = netdev_priv(net); |
3337 | 668 | ||
3338 | /* If a check_connect is defined, return it's results */ | 669 | /* If a check_connect is defined, return its result */ |
3339 | if (dev->driver_info->check_connect) | 670 | if (dev->driver_info->check_connect) |
3340 | return dev->driver_info->check_connect (dev) == 0; | 671 | return dev->driver_info->check_connect (dev) == 0; |
3341 | 672 | ||
3342 | /* Otherwise, we're up to avoid breaking scripts */ | 673 | /* Otherwise, say we're up (to avoid breaking scripts) */ |
3343 | return 1; | 674 | return 1; |
3344 | } | 675 | } |
3345 | 676 | ||
3346 | static u32 usbnet_get_msglevel (struct net_device *net) | 677 | u32 usbnet_get_msglevel (struct net_device *net) |
3347 | { | 678 | { |
3348 | struct usbnet *dev = netdev_priv(net); | 679 | struct usbnet *dev = netdev_priv(net); |
3349 | 680 | ||
3350 | return dev->msg_enable; | 681 | return dev->msg_enable; |
3351 | } | 682 | } |
683 | EXPORT_SYMBOL_GPL(usbnet_get_msglevel); | ||
3352 | 684 | ||
3353 | static void usbnet_set_msglevel (struct net_device *net, u32 level) | 685 | void usbnet_set_msglevel (struct net_device *net, u32 level) |
3354 | { | 686 | { |
3355 | struct usbnet *dev = netdev_priv(net); | 687 | struct usbnet *dev = netdev_priv(net); |
3356 | 688 | ||
3357 | dev->msg_enable = level; | 689 | dev->msg_enable = level; |
3358 | } | 690 | } |
691 | EXPORT_SYMBOL_GPL(usbnet_set_msglevel); | ||
3359 | 692 | ||
3360 | static int usbnet_ioctl (struct net_device *net, struct ifreq *rq, int cmd) | 693 | /* drivers may override default ethtool_ops in their bind() routine */ |
3361 | { | 694 | static struct ethtool_ops usbnet_ethtool_ops = { |
3362 | #ifdef NEED_MII | 695 | .get_drvinfo = usbnet_get_drvinfo, |
3363 | { | 696 | .get_link = usbnet_get_link, |
3364 | struct usbnet *dev = netdev_priv(net); | 697 | .get_msglevel = usbnet_get_msglevel, |
3365 | 698 | .set_msglevel = usbnet_set_msglevel, | |
3366 | if (dev->mii.mdio_read != NULL && dev->mii.mdio_write != NULL) | 699 | }; |
3367 | return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL); | ||
3368 | } | ||
3369 | #endif | ||
3370 | return -EOPNOTSUPP; | ||
3371 | } | ||
3372 | 700 | ||
3373 | /*-------------------------------------------------------------------------*/ | 701 | /*-------------------------------------------------------------------------*/ |
3374 | 702 | ||
@@ -3387,19 +715,24 @@ kevent (void *data) | |||
3387 | if (test_bit (EVENT_TX_HALT, &dev->flags)) { | 715 | if (test_bit (EVENT_TX_HALT, &dev->flags)) { |
3388 | unlink_urbs (dev, &dev->txq); | 716 | unlink_urbs (dev, &dev->txq); |
3389 | status = usb_clear_halt (dev->udev, dev->out); | 717 | status = usb_clear_halt (dev->udev, dev->out); |
3390 | if (status < 0 && status != -EPIPE) { | 718 | if (status < 0 |
719 | && status != -EPIPE | ||
720 | && status != -ESHUTDOWN) { | ||
3391 | if (netif_msg_tx_err (dev)) | 721 | if (netif_msg_tx_err (dev)) |
3392 | deverr (dev, "can't clear tx halt, status %d", | 722 | deverr (dev, "can't clear tx halt, status %d", |
3393 | status); | 723 | status); |
3394 | } else { | 724 | } else { |
3395 | clear_bit (EVENT_TX_HALT, &dev->flags); | 725 | clear_bit (EVENT_TX_HALT, &dev->flags); |
3396 | netif_wake_queue (dev->net); | 726 | if (status != -ESHUTDOWN) |
727 | netif_wake_queue (dev->net); | ||
3397 | } | 728 | } |
3398 | } | 729 | } |
3399 | if (test_bit (EVENT_RX_HALT, &dev->flags)) { | 730 | if (test_bit (EVENT_RX_HALT, &dev->flags)) { |
3400 | unlink_urbs (dev, &dev->rxq); | 731 | unlink_urbs (dev, &dev->rxq); |
3401 | status = usb_clear_halt (dev->udev, dev->in); | 732 | status = usb_clear_halt (dev->udev, dev->in); |
3402 | if (status < 0 && status != -EPIPE) { | 733 | if (status < 0 |
734 | && status != -EPIPE | ||
735 | && status != -ESHUTDOWN) { | ||
3403 | if (netif_msg_rx_err (dev)) | 736 | if (netif_msg_rx_err (dev)) |
3404 | deverr (dev, "can't clear rx halt, status %d", | 737 | deverr (dev, "can't clear rx halt, status %d", |
3405 | status); | 738 | status); |
@@ -3458,7 +791,7 @@ static void tx_complete (struct urb *urb, struct pt_regs *regs) | |||
3458 | 791 | ||
3459 | switch (urb->status) { | 792 | switch (urb->status) { |
3460 | case -EPIPE: | 793 | case -EPIPE: |
3461 | defer_kevent (dev, EVENT_TX_HALT); | 794 | usbnet_defer_kevent (dev, EVENT_TX_HALT); |
3462 | break; | 795 | break; |
3463 | 796 | ||
3464 | /* software-driven interface shutdown */ | 797 | /* software-driven interface shutdown */ |
@@ -3515,10 +848,6 @@ static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net) | |||
3515 | struct skb_data *entry; | 848 | struct skb_data *entry; |
3516 | struct driver_info *info = dev->driver_info; | 849 | struct driver_info *info = dev->driver_info; |
3517 | unsigned long flags; | 850 | unsigned long flags; |
3518 | #ifdef CONFIG_USB_NET1080 | ||
3519 | struct nc_header *header = NULL; | ||
3520 | struct nc_trailer *trailer = NULL; | ||
3521 | #endif /* CONFIG_USB_NET1080 */ | ||
3522 | 851 | ||
3523 | // some devices want funky USB-level framing, for | 852 | // some devices want funky USB-level framing, for |
3524 | // win32 driver (usually) and/or hardware quirks | 853 | // win32 driver (usually) and/or hardware quirks |
@@ -3544,24 +873,8 @@ static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net) | |||
3544 | entry->state = tx_start; | 873 | entry->state = tx_start; |
3545 | entry->length = length; | 874 | entry->length = length; |
3546 | 875 | ||
3547 | // FIXME: reorganize a bit, so that fixup() fills out NetChip | ||
3548 | // framing too. (Packet ID update needs the spinlock...) | ||
3549 | // [ BETTER: we already own net->xmit_lock, that's enough ] | ||
3550 | |||
3551 | #ifdef CONFIG_USB_NET1080 | ||
3552 | if (info->flags & FLAG_FRAMING_NC) { | ||
3553 | header = (struct nc_header *) skb_push (skb, sizeof *header); | ||
3554 | header->hdr_len = cpu_to_le16 (sizeof (*header)); | ||
3555 | header->packet_len = cpu_to_le16 (length); | ||
3556 | if (!((skb->len + sizeof *trailer) & 0x01)) | ||
3557 | *skb_put (skb, 1) = PAD_BYTE; | ||
3558 | trailer = (struct nc_trailer *) skb_put (skb, sizeof *trailer); | ||
3559 | } | ||
3560 | #endif /* CONFIG_USB_NET1080 */ | ||
3561 | |||
3562 | usb_fill_bulk_urb (urb, dev->udev, dev->out, | 876 | usb_fill_bulk_urb (urb, dev->udev, dev->out, |
3563 | skb->data, skb->len, tx_complete, skb); | 877 | skb->data, skb->len, tx_complete, skb); |
3564 | urb->transfer_flags |= URB_ASYNC_UNLINK; | ||
3565 | 878 | ||
3566 | /* don't assume the hardware handles USB_ZERO_PACKET | 879 | /* don't assume the hardware handles USB_ZERO_PACKET |
3567 | * NOTE: strictly conforming cdc-ether devices should expect | 880 | * NOTE: strictly conforming cdc-ether devices should expect |
@@ -3574,22 +887,10 @@ static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net) | |||
3574 | 887 | ||
3575 | spin_lock_irqsave (&dev->txq.lock, flags); | 888 | spin_lock_irqsave (&dev->txq.lock, flags); |
3576 | 889 | ||
3577 | #ifdef CONFIG_USB_NET1080 | ||
3578 | if (info->flags & FLAG_FRAMING_NC) { | ||
3579 | header->packet_id = cpu_to_le16 ((u16)dev->dev_packet_id++); | ||
3580 | put_unaligned (header->packet_id, &trailer->packet_id); | ||
3581 | #if 0 | ||
3582 | devdbg (dev, "frame >tx h %d p %d id %d", | ||
3583 | header->hdr_len, header->packet_len, | ||
3584 | header->packet_id); | ||
3585 | #endif | ||
3586 | } | ||
3587 | #endif /* CONFIG_USB_NET1080 */ | ||
3588 | |||
3589 | switch ((retval = usb_submit_urb (urb, GFP_ATOMIC))) { | 890 | switch ((retval = usb_submit_urb (urb, GFP_ATOMIC))) { |
3590 | case -EPIPE: | 891 | case -EPIPE: |
3591 | netif_stop_queue (net); | 892 | netif_stop_queue (net); |
3592 | defer_kevent (dev, EVENT_TX_HALT); | 893 | usbnet_defer_kevent (dev, EVENT_TX_HALT); |
3593 | break; | 894 | break; |
3594 | default: | 895 | default: |
3595 | if (netif_msg_tx_err (dev)) | 896 | if (netif_msg_tx_err (dev)) |
@@ -3692,7 +993,7 @@ static void usbnet_bh (unsigned long param) | |||
3692 | 993 | ||
3693 | // precondition: never called in_interrupt | 994 | // precondition: never called in_interrupt |
3694 | 995 | ||
3695 | static void usbnet_disconnect (struct usb_interface *intf) | 996 | void usbnet_disconnect (struct usb_interface *intf) |
3696 | { | 997 | { |
3697 | struct usbnet *dev; | 998 | struct usbnet *dev; |
3698 | struct usb_device *xdev; | 999 | struct usb_device *xdev; |
@@ -3706,7 +1007,8 @@ static void usbnet_disconnect (struct usb_interface *intf) | |||
3706 | xdev = interface_to_usbdev (intf); | 1007 | xdev = interface_to_usbdev (intf); |
3707 | 1008 | ||
3708 | if (netif_msg_probe (dev)) | 1009 | if (netif_msg_probe (dev)) |
3709 | devinfo (dev, "unregister usbnet usb-%s-%s, %s", | 1010 | devinfo (dev, "unregister '%s' usb-%s-%s, %s", |
1011 | intf->dev.driver->name, | ||
3710 | xdev->bus->bus_name, xdev->devpath, | 1012 | xdev->bus->bus_name, xdev->devpath, |
3711 | dev->driver_info->description); | 1013 | dev->driver_info->description); |
3712 | 1014 | ||
@@ -3722,15 +1024,14 @@ static void usbnet_disconnect (struct usb_interface *intf) | |||
3722 | free_netdev(net); | 1024 | free_netdev(net); |
3723 | usb_put_dev (xdev); | 1025 | usb_put_dev (xdev); |
3724 | } | 1026 | } |
1027 | EXPORT_SYMBOL_GPL(usbnet_disconnect); | ||
3725 | 1028 | ||
3726 | 1029 | ||
3727 | /*-------------------------------------------------------------------------*/ | 1030 | /*-------------------------------------------------------------------------*/ |
3728 | 1031 | ||
3729 | static struct ethtool_ops usbnet_ethtool_ops; | ||
3730 | |||
3731 | // precondition: never called in_interrupt | 1032 | // precondition: never called in_interrupt |
3732 | 1033 | ||
3733 | static int | 1034 | int |
3734 | usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) | 1035 | usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) |
3735 | { | 1036 | { |
3736 | struct usbnet *dev; | 1037 | struct usbnet *dev; |
@@ -3779,6 +1080,10 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) | |||
3779 | strcpy (net->name, "usb%d"); | 1080 | strcpy (net->name, "usb%d"); |
3780 | memcpy (net->dev_addr, node_id, sizeof node_id); | 1081 | memcpy (net->dev_addr, node_id, sizeof node_id); |
3781 | 1082 | ||
1083 | /* rx and tx sides can use different message sizes; | ||
1084 | * bind() should set rx_urb_size in that case. | ||
1085 | */ | ||
1086 | dev->hard_mtu = net->mtu + net->hard_header_len; | ||
3782 | #if 0 | 1087 | #if 0 |
3783 | // dma_supported() is deeply broken on almost all architectures | 1088 | // dma_supported() is deeply broken on almost all architectures |
3784 | // possible with some EHCI controllers | 1089 | // possible with some EHCI controllers |
@@ -3793,7 +1098,6 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) | |||
3793 | net->stop = usbnet_stop; | 1098 | net->stop = usbnet_stop; |
3794 | net->watchdog_timeo = TX_TIMEOUT_JIFFIES; | 1099 | net->watchdog_timeo = TX_TIMEOUT_JIFFIES; |
3795 | net->tx_timeout = usbnet_tx_timeout; | 1100 | net->tx_timeout = usbnet_tx_timeout; |
3796 | net->do_ioctl = usbnet_ioctl; | ||
3797 | net->ethtool_ops = &usbnet_ethtool_ops; | 1101 | net->ethtool_ops = &usbnet_ethtool_ops; |
3798 | 1102 | ||
3799 | // allow device-specific bind/init procedures | 1103 | // allow device-specific bind/init procedures |
@@ -3806,8 +1110,12 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) | |||
3806 | if ((dev->driver_info->flags & FLAG_ETHER) != 0 | 1110 | if ((dev->driver_info->flags & FLAG_ETHER) != 0 |
3807 | && (net->dev_addr [0] & 0x02) == 0) | 1111 | && (net->dev_addr [0] & 0x02) == 0) |
3808 | strcpy (net->name, "eth%d"); | 1112 | strcpy (net->name, "eth%d"); |
3809 | } else if (!info->in || info->out) | 1113 | |
3810 | status = get_endpoints (dev, udev); | 1114 | /* maybe the remote can't receive an Ethernet MTU */ |
1115 | if (net->mtu > (dev->hard_mtu - net->hard_header_len)) | ||
1116 | net->mtu = dev->hard_mtu - net->hard_header_len; | ||
1117 | } else if (!info->in || !info->out) | ||
1118 | status = usbnet_get_endpoints (dev, udev); | ||
3811 | else { | 1119 | else { |
3812 | dev->in = usb_rcvbulkpipe (xdev, info->in); | 1120 | dev->in = usb_rcvbulkpipe (xdev, info->in); |
3813 | dev->out = usb_sndbulkpipe (xdev, info->out); | 1121 | dev->out = usb_sndbulkpipe (xdev, info->out); |
@@ -3819,12 +1127,13 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) | |||
3819 | status = 0; | 1127 | status = 0; |
3820 | 1128 | ||
3821 | } | 1129 | } |
3822 | |||
3823 | if (status == 0 && dev->status) | 1130 | if (status == 0 && dev->status) |
3824 | status = init_status (dev, udev); | 1131 | status = init_status (dev, udev); |
3825 | if (status < 0) | 1132 | if (status < 0) |
3826 | goto out1; | 1133 | goto out1; |
3827 | 1134 | ||
1135 | if (!dev->rx_urb_size) | ||
1136 | dev->rx_urb_size = dev->hard_mtu; | ||
3828 | dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1); | 1137 | dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1); |
3829 | 1138 | ||
3830 | SET_NETDEV_DEV(net, &udev->dev); | 1139 | SET_NETDEV_DEV(net, &udev->dev); |
@@ -3832,8 +1141,9 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) | |||
3832 | if (status) | 1141 | if (status) |
3833 | goto out3; | 1142 | goto out3; |
3834 | if (netif_msg_probe (dev)) | 1143 | if (netif_msg_probe (dev)) |
3835 | devinfo (dev, "register usbnet at usb-%s-%s, %s, " | 1144 | devinfo (dev, "register '%s' at usb-%s-%s, %s, " |
3836 | "%02x:%02x:%02x:%02x:%02x:%02x", | 1145 | "%02x:%02x:%02x:%02x:%02x:%02x", |
1146 | udev->dev.driver->name, | ||
3837 | xdev->bus->bus_name, xdev->devpath, | 1147 | xdev->bus->bus_name, xdev->devpath, |
3838 | dev->driver_info->description, | 1148 | dev->driver_info->description, |
3839 | net->dev_addr [0], net->dev_addr [1], | 1149 | net->dev_addr [0], net->dev_addr [1], |
@@ -3857,12 +1167,15 @@ out: | |||
3857 | usb_put_dev(xdev); | 1167 | usb_put_dev(xdev); |
3858 | return status; | 1168 | return status; |
3859 | } | 1169 | } |
1170 | EXPORT_SYMBOL_GPL(usbnet_probe); | ||
3860 | 1171 | ||
3861 | /*-------------------------------------------------------------------------*/ | 1172 | /*-------------------------------------------------------------------------*/ |
3862 | 1173 | ||
3863 | #ifdef CONFIG_PM | 1174 | /* FIXME these suspend/resume methods assume non-CDC style |
1175 | * devices, with only one interface. | ||
1176 | */ | ||
3864 | 1177 | ||
3865 | static int usbnet_suspend (struct usb_interface *intf, pm_message_t message) | 1178 | int usbnet_suspend (struct usb_interface *intf, pm_message_t message) |
3866 | { | 1179 | { |
3867 | struct usbnet *dev = usb_get_intfdata(intf); | 1180 | struct usbnet *dev = usb_get_intfdata(intf); |
3868 | 1181 | ||
@@ -3875,8 +1188,9 @@ static int usbnet_suspend (struct usb_interface *intf, pm_message_t message) | |||
3875 | intf->dev.power.power_state = PMSG_SUSPEND; | 1188 | intf->dev.power.power_state = PMSG_SUSPEND; |
3876 | return 0; | 1189 | return 0; |
3877 | } | 1190 | } |
1191 | EXPORT_SYMBOL_GPL(usbnet_suspend); | ||
3878 | 1192 | ||
3879 | static int usbnet_resume (struct usb_interface *intf) | 1193 | int usbnet_resume (struct usb_interface *intf) |
3880 | { | 1194 | { |
3881 | struct usbnet *dev = usb_get_intfdata(intf); | 1195 | struct usbnet *dev = usb_get_intfdata(intf); |
3882 | 1196 | ||
@@ -3885,357 +1199,27 @@ static int usbnet_resume (struct usb_interface *intf) | |||
3885 | tasklet_schedule (&dev->bh); | 1199 | tasklet_schedule (&dev->bh); |
3886 | return 0; | 1200 | return 0; |
3887 | } | 1201 | } |
1202 | EXPORT_SYMBOL_GPL(usbnet_resume); | ||
3888 | 1203 | ||
3889 | #else /* !CONFIG_PM */ | ||
3890 | |||
3891 | #define usbnet_suspend NULL | ||
3892 | #define usbnet_resume NULL | ||
3893 | |||
3894 | #endif /* CONFIG_PM */ | ||
3895 | |||
3896 | /*-------------------------------------------------------------------------*/ | ||
3897 | |||
3898 | #ifndef HAVE_HARDWARE | ||
3899 | #error You need to configure some hardware for this driver | ||
3900 | #endif | ||
3901 | |||
3902 | /* | ||
3903 | * chip vendor names won't normally be on the cables, and | ||
3904 | * may not be on the device. | ||
3905 | */ | ||
3906 | |||
3907 | static const struct usb_device_id products [] = { | ||
3908 | |||
3909 | #ifdef CONFIG_USB_ALI_M5632 | ||
3910 | { | ||
3911 | USB_DEVICE (0x0402, 0x5632), // ALi defaults | ||
3912 | .driver_info = (unsigned long) &ali_m5632_info, | ||
3913 | }, | ||
3914 | #endif | ||
3915 | |||
3916 | #ifdef CONFIG_USB_AN2720 | ||
3917 | { | ||
3918 | USB_DEVICE (0x0547, 0x2720), // AnchorChips defaults | ||
3919 | .driver_info = (unsigned long) &an2720_info, | ||
3920 | }, { | ||
3921 | USB_DEVICE (0x0547, 0x2727), // Xircom PGUNET | ||
3922 | .driver_info = (unsigned long) &an2720_info, | ||
3923 | }, | ||
3924 | #endif | ||
3925 | |||
3926 | #ifdef CONFIG_USB_BELKIN | ||
3927 | { | ||
3928 | USB_DEVICE (0x050d, 0x0004), // Belkin | ||
3929 | .driver_info = (unsigned long) &belkin_info, | ||
3930 | }, { | ||
3931 | USB_DEVICE (0x056c, 0x8100), // eTEK | ||
3932 | .driver_info = (unsigned long) &belkin_info, | ||
3933 | }, { | ||
3934 | USB_DEVICE (0x0525, 0x9901), // Advance USBNET (eTEK) | ||
3935 | .driver_info = (unsigned long) &belkin_info, | ||
3936 | }, | ||
3937 | #endif | ||
3938 | |||
3939 | #ifdef CONFIG_USB_AX8817X | ||
3940 | { | ||
3941 | // Linksys USB200M | ||
3942 | USB_DEVICE (0x077b, 0x2226), | ||
3943 | .driver_info = (unsigned long) &ax8817x_info, | ||
3944 | }, { | ||
3945 | // Netgear FA120 | ||
3946 | USB_DEVICE (0x0846, 0x1040), | ||
3947 | .driver_info = (unsigned long) &netgear_fa120_info, | ||
3948 | }, { | ||
3949 | // DLink DUB-E100 | ||
3950 | USB_DEVICE (0x2001, 0x1a00), | ||
3951 | .driver_info = (unsigned long) &dlink_dub_e100_info, | ||
3952 | }, { | ||
3953 | // Intellinet, ST Lab USB Ethernet | ||
3954 | USB_DEVICE (0x0b95, 0x1720), | ||
3955 | .driver_info = (unsigned long) &ax8817x_info, | ||
3956 | }, { | ||
3957 | // Hawking UF200, TrendNet TU2-ET100 | ||
3958 | USB_DEVICE (0x07b8, 0x420a), | ||
3959 | .driver_info = (unsigned long) &hawking_uf200_info, | ||
3960 | }, { | ||
3961 | // Billionton Systems, USB2AR | ||
3962 | USB_DEVICE (0x08dd, 0x90ff), | ||
3963 | .driver_info = (unsigned long) &ax8817x_info, | ||
3964 | }, { | ||
3965 | // ATEN UC210T | ||
3966 | USB_DEVICE (0x0557, 0x2009), | ||
3967 | .driver_info = (unsigned long) &ax8817x_info, | ||
3968 | }, { | ||
3969 | // Buffalo LUA-U2-KTX | ||
3970 | USB_DEVICE (0x0411, 0x003d), | ||
3971 | .driver_info = (unsigned long) &ax8817x_info, | ||
3972 | }, { | ||
3973 | // Sitecom LN-029 "USB 2.0 10/100 Ethernet adapter" | ||
3974 | USB_DEVICE (0x6189, 0x182d), | ||
3975 | .driver_info = (unsigned long) &ax8817x_info, | ||
3976 | }, { | ||
3977 | // corega FEther USB2-TX | ||
3978 | USB_DEVICE (0x07aa, 0x0017), | ||
3979 | .driver_info = (unsigned long) &ax8817x_info, | ||
3980 | }, { | ||
3981 | // Surecom EP-1427X-2 | ||
3982 | USB_DEVICE (0x1189, 0x0893), | ||
3983 | .driver_info = (unsigned long) &ax8817x_info, | ||
3984 | }, { | ||
3985 | // goodway corp usb gwusb2e | ||
3986 | USB_DEVICE (0x1631, 0x6200), | ||
3987 | .driver_info = (unsigned long) &ax8817x_info, | ||
3988 | }, { | ||
3989 | // ASIX AX88772 10/100 | ||
3990 | USB_DEVICE (0x0b95, 0x7720), | ||
3991 | .driver_info = (unsigned long) &ax88772_info, | ||
3992 | }, | ||
3993 | #endif | ||
3994 | |||
3995 | #ifdef CONFIG_USB_EPSON2888 | ||
3996 | { | ||
3997 | USB_DEVICE (0x0525, 0x2888), // EPSON USB client | ||
3998 | .driver_info = (unsigned long) &epson2888_info, | ||
3999 | }, | ||
4000 | #endif | ||
4001 | |||
4002 | #ifdef CONFIG_USB_GENESYS | ||
4003 | { | ||
4004 | USB_DEVICE (0x05e3, 0x0502), // GL620USB-A | ||
4005 | .driver_info = (unsigned long) &genelink_info, | ||
4006 | }, | ||
4007 | /* NOT: USB_DEVICE (0x05e3, 0x0501), // GL620USB | ||
4008 | * that's half duplex, not currently supported | ||
4009 | */ | ||
4010 | #endif | ||
4011 | |||
4012 | #ifdef CONFIG_USB_NET1080 | ||
4013 | { | ||
4014 | USB_DEVICE (0x0525, 0x1080), // NetChip ref design | ||
4015 | .driver_info = (unsigned long) &net1080_info, | ||
4016 | }, { | ||
4017 | USB_DEVICE (0x06D0, 0x0622), // Laplink Gold | ||
4018 | .driver_info = (unsigned long) &net1080_info, | ||
4019 | }, | ||
4020 | #endif | ||
4021 | |||
4022 | #ifdef CONFIG_USB_PL2301 | ||
4023 | { | ||
4024 | USB_DEVICE (0x067b, 0x0000), // PL-2301 | ||
4025 | .driver_info = (unsigned long) &prolific_info, | ||
4026 | }, { | ||
4027 | USB_DEVICE (0x067b, 0x0001), // PL-2302 | ||
4028 | .driver_info = (unsigned long) &prolific_info, | ||
4029 | }, | ||
4030 | #endif | ||
4031 | |||
4032 | #ifdef CONFIG_USB_KC2190 | ||
4033 | { | ||
4034 | USB_DEVICE (0x050f, 0x0190), // KC-190 | ||
4035 | .driver_info = (unsigned long) &kc2190_info, | ||
4036 | }, | ||
4037 | #endif | ||
4038 | |||
4039 | #ifdef CONFIG_USB_RNDIS | ||
4040 | { | ||
4041 | /* RNDIS is MSFT's un-official variant of CDC ACM */ | ||
4042 | USB_INTERFACE_INFO (USB_CLASS_COMM, 2 /* ACM */, 0x0ff), | ||
4043 | .driver_info = (unsigned long) &rndis_info, | ||
4044 | }, | ||
4045 | #endif | ||
4046 | |||
4047 | #ifdef CONFIG_USB_ARMLINUX | ||
4048 | /* | ||
4049 | * SA-1100 using standard ARM Linux kernels, or compatible. | ||
4050 | * Often used when talking to Linux PDAs (iPaq, Yopy, etc). | ||
4051 | * The sa-1100 "usb-eth" driver handles the basic framing. | ||
4052 | * | ||
4053 | * PXA25x or PXA210 ... these use a "usb-eth" driver much like | ||
4054 | * the sa1100 one, but hardware uses different endpoint numbers. | ||
4055 | * | ||
4056 | * Or the Linux "Ethernet" gadget on hardware that can't talk | ||
4057 | * CDC Ethernet (e.g., no altsettings), in either of two modes: | ||
4058 | * - acting just like the old "usb-eth" firmware, though | ||
4059 | * the implementation is different | ||
4060 | * - supporting RNDIS as the first/default configuration for | ||
4061 | * MS-Windows interop; Linux needs to use the other config | ||
4062 | */ | ||
4063 | { | ||
4064 | // 1183 = 0x049F, both used as hex values? | ||
4065 | // Compaq "Itsy" vendor/product id | ||
4066 | USB_DEVICE (0x049F, 0x505A), // usb-eth, or compatible | ||
4067 | .driver_info = (unsigned long) &linuxdev_info, | ||
4068 | }, { | ||
4069 | USB_DEVICE (0x0E7E, 0x1001), // G.Mate "Yopy" | ||
4070 | .driver_info = (unsigned long) &yopy_info, | ||
4071 | }, { | ||
4072 | USB_DEVICE (0x8086, 0x07d3), // "blob" bootloader | ||
4073 | .driver_info = (unsigned long) &blob_info, | ||
4074 | }, { | ||
4075 | // Linux Ethernet/RNDIS gadget on pxa210/25x/26x | ||
4076 | // e.g. Gumstix, current OpenZaurus, ... | ||
4077 | USB_DEVICE_VER (0x0525, 0xa4a2, 0x0203, 0x0203), | ||
4078 | .driver_info = (unsigned long) &linuxdev_info, | ||
4079 | }, | ||
4080 | #endif | ||
4081 | |||
4082 | #if defined(CONFIG_USB_ZAURUS) || defined(CONFIG_USB_CDCETHER) | ||
4083 | /* | ||
4084 | * SA-1100 based Sharp Zaurus ("collie"), or compatible. | ||
4085 | * Same idea as above, but different framing. | ||
4086 | * | ||
4087 | * PXA-2xx based models are also lying-about-cdc. | ||
4088 | * Some models don't even tell the same lies ... | ||
4089 | * | ||
4090 | * NOTE: OpenZaurus versions with 2.6 kernels won't use these entries, | ||
4091 | * unlike the older ones with 2.4 "embedix" kernels. | ||
4092 | * | ||
4093 | * NOTE: These entries do double-duty, serving as blacklist entries | ||
4094 | * whenever Zaurus support isn't enabled, but CDC Ethernet is. | ||
4095 | */ | ||
4096 | #define ZAURUS_MASTER_INTERFACE \ | ||
4097 | .bInterfaceClass = USB_CLASS_COMM, \ | ||
4098 | .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET, \ | ||
4099 | .bInterfaceProtocol = USB_CDC_PROTO_NONE | ||
4100 | { | ||
4101 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
4102 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
4103 | .idVendor = 0x04DD, | ||
4104 | .idProduct = 0x8004, | ||
4105 | ZAURUS_MASTER_INTERFACE, | ||
4106 | .driver_info = ZAURUS_STRONGARM_INFO, | ||
4107 | }, { | ||
4108 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
4109 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
4110 | .idVendor = 0x04DD, | ||
4111 | .idProduct = 0x8005, /* A-300 */ | ||
4112 | ZAURUS_MASTER_INTERFACE, | ||
4113 | .driver_info = ZAURUS_PXA_INFO, | ||
4114 | }, { | ||
4115 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
4116 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
4117 | .idVendor = 0x04DD, | ||
4118 | .idProduct = 0x8006, /* B-500/SL-5600 */ | ||
4119 | ZAURUS_MASTER_INTERFACE, | ||
4120 | .driver_info = ZAURUS_PXA_INFO, | ||
4121 | }, { | ||
4122 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
4123 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
4124 | .idVendor = 0x04DD, | ||
4125 | .idProduct = 0x8007, /* C-700 */ | ||
4126 | ZAURUS_MASTER_INTERFACE, | ||
4127 | .driver_info = ZAURUS_PXA_INFO, | ||
4128 | }, { | ||
4129 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
4130 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
4131 | .idVendor = 0x04DD, | ||
4132 | .idProduct = 0x9031, /* C-750 C-760 */ | ||
4133 | ZAURUS_MASTER_INTERFACE, | ||
4134 | .driver_info = ZAURUS_PXA_INFO, | ||
4135 | }, { | ||
4136 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
4137 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
4138 | .idVendor = 0x04DD, | ||
4139 | .idProduct = 0x9032, /* SL-6000 */ | ||
4140 | ZAURUS_MASTER_INTERFACE, | ||
4141 | .driver_info = ZAURUS_PXA_INFO, | ||
4142 | }, { | ||
4143 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
4144 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
4145 | .idVendor = 0x04DD, | ||
4146 | /* reported with some C860 units */ | ||
4147 | .idProduct = 0x9050, /* C-860 */ | ||
4148 | ZAURUS_MASTER_INTERFACE, | ||
4149 | .driver_info = ZAURUS_PXA_INFO, | ||
4150 | }, | ||
4151 | |||
4152 | #ifdef CONFIG_USB_ZAURUS | ||
4153 | /* At least some (reports vary) PXA units have very different lies | ||
4154 | * about their standards support: they claim to be cell phones with | ||
4155 | * direct access to their radios. (They don't conform to CDC MDLM.) | ||
4156 | */ | ||
4157 | { | ||
4158 | USB_INTERFACE_INFO (USB_CLASS_COMM, USB_CDC_SUBCLASS_MDLM, | ||
4159 | USB_CDC_PROTO_NONE), | ||
4160 | .driver_info = (unsigned long) &bogus_mdlm_info, | ||
4161 | }, | ||
4162 | #endif | ||
4163 | |||
4164 | /* Olympus has some models with a Zaurus-compatible option. | ||
4165 | * R-1000 uses a FreeScale i.MXL cpu (ARMv4T) | ||
4166 | */ | ||
4167 | { | ||
4168 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
4169 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
4170 | .idVendor = 0x07B4, | ||
4171 | .idProduct = 0x0F02, /* R-1000 */ | ||
4172 | ZAURUS_MASTER_INTERFACE, | ||
4173 | .driver_info = OLYMPUS_MXL_INFO, | ||
4174 | }, | ||
4175 | #endif | ||
4176 | |||
4177 | #ifdef CONFIG_USB_CDCETHER | ||
4178 | { | ||
4179 | /* CDC Ether uses two interfaces, not necessarily consecutive. | ||
4180 | * We match the main interface, ignoring the optional device | ||
4181 | * class so we could handle devices that aren't exclusively | ||
4182 | * CDC ether. | ||
4183 | * | ||
4184 | * NOTE: this match must come AFTER entries working around | ||
4185 | * bugs/quirks in a given product (like Zaurus, above). | ||
4186 | */ | ||
4187 | USB_INTERFACE_INFO (USB_CLASS_COMM, USB_CDC_SUBCLASS_ETHERNET, | ||
4188 | USB_CDC_PROTO_NONE), | ||
4189 | .driver_info = (unsigned long) &cdc_info, | ||
4190 | }, | ||
4191 | #endif | ||
4192 | |||
4193 | { }, // END | ||
4194 | }; | ||
4195 | MODULE_DEVICE_TABLE (usb, products); | ||
4196 | |||
4197 | static struct usb_driver usbnet_driver = { | ||
4198 | .owner = THIS_MODULE, | ||
4199 | .name = driver_name, | ||
4200 | .id_table = products, | ||
4201 | .probe = usbnet_probe, | ||
4202 | .disconnect = usbnet_disconnect, | ||
4203 | .suspend = usbnet_suspend, | ||
4204 | .resume = usbnet_resume, | ||
4205 | }; | ||
4206 | |||
4207 | /* Default ethtool_ops assigned. Devices can override in their bind() routine */ | ||
4208 | static struct ethtool_ops usbnet_ethtool_ops = { | ||
4209 | .get_drvinfo = usbnet_get_drvinfo, | ||
4210 | .get_link = usbnet_get_link, | ||
4211 | .get_msglevel = usbnet_get_msglevel, | ||
4212 | .set_msglevel = usbnet_set_msglevel, | ||
4213 | }; | ||
4214 | 1204 | ||
4215 | /*-------------------------------------------------------------------------*/ | 1205 | /*-------------------------------------------------------------------------*/ |
4216 | 1206 | ||
4217 | static int __init usbnet_init (void) | 1207 | static int __init usbnet_init(void) |
4218 | { | 1208 | { |
4219 | // compiler should optimize these out | 1209 | /* compiler should optimize this out */ |
4220 | BUG_ON (sizeof (((struct sk_buff *)0)->cb) | 1210 | BUG_ON (sizeof (((struct sk_buff *)0)->cb) |
4221 | < sizeof (struct skb_data)); | 1211 | < sizeof (struct skb_data)); |
4222 | #ifdef CONFIG_USB_CDCETHER | ||
4223 | BUG_ON ((sizeof (((struct usbnet *)0)->data) | ||
4224 | < sizeof (struct cdc_state))); | ||
4225 | #endif | ||
4226 | 1212 | ||
4227 | random_ether_addr(node_id); | 1213 | random_ether_addr(node_id); |
4228 | 1214 | return 0; | |
4229 | return usb_register(&usbnet_driver); | ||
4230 | } | 1215 | } |
4231 | module_init (usbnet_init); | 1216 | module_init(usbnet_init); |
4232 | 1217 | ||
4233 | static void __exit usbnet_exit (void) | 1218 | static void __exit usbnet_exit(void) |
4234 | { | 1219 | { |
4235 | usb_deregister (&usbnet_driver); | ||
4236 | } | 1220 | } |
4237 | module_exit (usbnet_exit); | 1221 | module_exit(usbnet_exit); |
4238 | 1222 | ||
4239 | MODULE_AUTHOR ("David Brownell <dbrownell@users.sourceforge.net>"); | 1223 | MODULE_AUTHOR("David Brownell"); |
4240 | MODULE_DESCRIPTION ("USB Host-to-Host Link Drivers (numerous vendors)"); | 1224 | MODULE_DESCRIPTION("USB network driver framework"); |
4241 | MODULE_LICENSE ("GPL"); | 1225 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/usb/net/usbnet.h b/drivers/usb/net/usbnet.h new file mode 100644 index 000000000000..7aa0abd1a9bd --- /dev/null +++ b/drivers/usb/net/usbnet.h | |||
@@ -0,0 +1,193 @@ | |||
1 | /* | ||
2 | * USB Networking Link Interface | ||
3 | * | ||
4 | * Copyright (C) 2000-2005 by David Brownell <dbrownell@users.sourceforge.net> | ||
5 | * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | ||
21 | |||
22 | |||
23 | #ifndef __USBNET_H | ||
24 | #define __USBNET_H | ||
25 | |||
26 | |||
27 | /* interface from usbnet core to each USB networking link we handle */ | ||
28 | struct usbnet { | ||
29 | /* housekeeping */ | ||
30 | struct usb_device *udev; | ||
31 | struct driver_info *driver_info; | ||
32 | wait_queue_head_t *wait; | ||
33 | |||
34 | /* i/o info: pipes etc */ | ||
35 | unsigned in, out; | ||
36 | struct usb_host_endpoint *status; | ||
37 | unsigned maxpacket; | ||
38 | struct timer_list delay; | ||
39 | |||
40 | /* protocol/interface state */ | ||
41 | struct net_device *net; | ||
42 | struct net_device_stats stats; | ||
43 | int msg_enable; | ||
44 | unsigned long data [5]; | ||
45 | u32 xid; | ||
46 | u32 hard_mtu; /* count any extra framing */ | ||
47 | size_t rx_urb_size; /* size for rx urbs */ | ||
48 | struct mii_if_info mii; | ||
49 | |||
50 | /* various kinds of pending driver work */ | ||
51 | struct sk_buff_head rxq; | ||
52 | struct sk_buff_head txq; | ||
53 | struct sk_buff_head done; | ||
54 | struct urb *interrupt; | ||
55 | struct tasklet_struct bh; | ||
56 | |||
57 | struct work_struct kevent; | ||
58 | unsigned long flags; | ||
59 | # define EVENT_TX_HALT 0 | ||
60 | # define EVENT_RX_HALT 1 | ||
61 | # define EVENT_RX_MEMORY 2 | ||
62 | # define EVENT_STS_SPLIT 3 | ||
63 | # define EVENT_LINK_RESET 4 | ||
64 | }; | ||
65 | |||
66 | static inline struct usb_driver *driver_of(struct usb_interface *intf) | ||
67 | { | ||
68 | return to_usb_driver(intf->dev.driver); | ||
69 | } | ||
70 | |||
71 | /* interface from the device/framing level "minidriver" to core */ | ||
72 | struct driver_info { | ||
73 | char *description; | ||
74 | |||
75 | int flags; | ||
76 | /* framing is CDC Ethernet, not writing ZLPs (hw issues), or optionally: */ | ||
77 | #define FLAG_FRAMING_NC 0x0001 /* guard against device dropouts */ | ||
78 | #define FLAG_FRAMING_GL 0x0002 /* genelink batches packets */ | ||
79 | #define FLAG_FRAMING_Z 0x0004 /* zaurus adds a trailer */ | ||
80 | #define FLAG_FRAMING_RN 0x0008 /* RNDIS batches, plus huge header */ | ||
81 | |||
82 | #define FLAG_NO_SETINT 0x0010 /* device can't set_interface() */ | ||
83 | #define FLAG_ETHER 0x0020 /* maybe use "eth%d" names */ | ||
84 | |||
85 | #define FLAG_FRAMING_AX 0x0040 /* AX88772/178 packets */ | ||
86 | |||
87 | /* init device ... can sleep, or cause probe() failure */ | ||
88 | int (*bind)(struct usbnet *, struct usb_interface *); | ||
89 | |||
90 | /* cleanup device ... can sleep, but can't fail */ | ||
91 | void (*unbind)(struct usbnet *, struct usb_interface *); | ||
92 | |||
93 | /* reset device ... can sleep */ | ||
94 | int (*reset)(struct usbnet *); | ||
95 | |||
96 | /* see if peer is connected ... can sleep */ | ||
97 | int (*check_connect)(struct usbnet *); | ||
98 | |||
99 | /* for status polling */ | ||
100 | void (*status)(struct usbnet *, struct urb *); | ||
101 | |||
102 | /* link reset handling, called from defer_kevent */ | ||
103 | int (*link_reset)(struct usbnet *); | ||
104 | |||
105 | /* fixup rx packet (strip framing) */ | ||
106 | int (*rx_fixup)(struct usbnet *dev, struct sk_buff *skb); | ||
107 | |||
108 | /* fixup tx packet (add framing) */ | ||
109 | struct sk_buff *(*tx_fixup)(struct usbnet *dev, | ||
110 | struct sk_buff *skb, unsigned flags); | ||
111 | |||
112 | /* for new devices, use the descriptor-reading code instead */ | ||
113 | int in; /* rx endpoint */ | ||
114 | int out; /* tx endpoint */ | ||
115 | |||
116 | unsigned long data; /* Misc driver specific data */ | ||
117 | }; | ||
118 | |||
119 | /* Minidrivers are just drivers using the "usbnet" core as a powerful | ||
120 | * network-specific subroutine library ... that happens to do pretty | ||
121 | * much everything except custom framing and chip-specific stuff. | ||
122 | */ | ||
123 | extern int usbnet_probe(struct usb_interface *, const struct usb_device_id *); | ||
124 | extern int usbnet_suspend (struct usb_interface *, pm_message_t ); | ||
125 | extern int usbnet_resume (struct usb_interface *); | ||
126 | extern void usbnet_disconnect(struct usb_interface *); | ||
127 | |||
128 | |||
129 | /* Drivers that reuse some of the standard USB CDC infrastructure | ||
130 | * (notably, using multiple interfaces according to the the CDC | ||
131 | * union descriptor) get some helper code. | ||
132 | */ | ||
133 | struct cdc_state { | ||
134 | struct usb_cdc_header_desc *header; | ||
135 | struct usb_cdc_union_desc *u; | ||
136 | struct usb_cdc_ether_desc *ether; | ||
137 | struct usb_interface *control; | ||
138 | struct usb_interface *data; | ||
139 | }; | ||
140 | |||
141 | extern int usbnet_generic_cdc_bind (struct usbnet *, struct usb_interface *); | ||
142 | extern void usbnet_cdc_unbind (struct usbnet *, struct usb_interface *); | ||
143 | |||
144 | /* CDC and RNDIS support the same host-chosen packet filters for IN transfers */ | ||
145 | #define DEFAULT_FILTER (USB_CDC_PACKET_TYPE_BROADCAST \ | ||
146 | |USB_CDC_PACKET_TYPE_ALL_MULTICAST \ | ||
147 | |USB_CDC_PACKET_TYPE_PROMISCUOUS \ | ||
148 | |USB_CDC_PACKET_TYPE_DIRECTED) | ||
149 | |||
150 | |||
151 | /* we record the state for each of our queued skbs */ | ||
152 | enum skb_state { | ||
153 | illegal = 0, | ||
154 | tx_start, tx_done, | ||
155 | rx_start, rx_done, rx_cleanup | ||
156 | }; | ||
157 | |||
158 | struct skb_data { /* skb->cb is one of these */ | ||
159 | struct urb *urb; | ||
160 | struct usbnet *dev; | ||
161 | enum skb_state state; | ||
162 | size_t length; | ||
163 | }; | ||
164 | |||
165 | |||
166 | extern int usbnet_get_endpoints(struct usbnet *, struct usb_interface *); | ||
167 | extern void usbnet_defer_kevent (struct usbnet *, int); | ||
168 | extern void usbnet_skb_return (struct usbnet *, struct sk_buff *); | ||
169 | |||
170 | extern u32 usbnet_get_msglevel (struct net_device *); | ||
171 | extern void usbnet_set_msglevel (struct net_device *, u32); | ||
172 | extern void usbnet_get_drvinfo (struct net_device *, struct ethtool_drvinfo *); | ||
173 | |||
174 | /* messaging support includes the interface name, so it must not be | ||
175 | * used before it has one ... notably, in minidriver bind() calls. | ||
176 | */ | ||
177 | #ifdef DEBUG | ||
178 | #define devdbg(usbnet, fmt, arg...) \ | ||
179 | printk(KERN_DEBUG "%s: " fmt "\n" , (usbnet)->net->name , ## arg) | ||
180 | #else | ||
181 | #define devdbg(usbnet, fmt, arg...) do {} while(0) | ||
182 | #endif | ||
183 | |||
184 | #define deverr(usbnet, fmt, arg...) \ | ||
185 | printk(KERN_ERR "%s: " fmt "\n" , (usbnet)->net->name , ## arg) | ||
186 | #define devwarn(usbnet, fmt, arg...) \ | ||
187 | printk(KERN_WARNING "%s: " fmt "\n" , (usbnet)->net->name , ## arg) | ||
188 | |||
189 | #define devinfo(usbnet, fmt, arg...) \ | ||
190 | printk(KERN_INFO "%s: " fmt "\n" , (usbnet)->net->name , ## arg); \ | ||
191 | |||
192 | |||
193 | #endif /* __USBNET_H */ | ||
diff --git a/drivers/usb/net/zaurus.c b/drivers/usb/net/zaurus.c new file mode 100644 index 000000000000..ee3b892aeabc --- /dev/null +++ b/drivers/usb/net/zaurus.c | |||
@@ -0,0 +1,386 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2002 Pavel Machek <pavel@ucw.cz> | ||
3 | * Copyright (C) 2002-2005 by David Brownell | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | // #define DEBUG // error path messages, extra info | ||
21 | // #define VERBOSE // more; success messages | ||
22 | |||
23 | #include <linux/config.h> | ||
24 | #ifdef CONFIG_USB_DEBUG | ||
25 | # define DEBUG | ||
26 | #endif | ||
27 | #include <linux/module.h> | ||
28 | #include <linux/sched.h> | ||
29 | #include <linux/init.h> | ||
30 | #include <linux/netdevice.h> | ||
31 | #include <linux/ethtool.h> | ||
32 | #include <linux/workqueue.h> | ||
33 | #include <linux/mii.h> | ||
34 | #include <linux/crc32.h> | ||
35 | #include <linux/usb.h> | ||
36 | #include <linux/usb_cdc.h> | ||
37 | |||
38 | #include "usbnet.h" | ||
39 | |||
40 | |||
41 | /* | ||
42 | * All known Zaurii lie about their standards conformance. At least | ||
43 | * the earliest SA-1100 models lie by saying they support CDC Ethernet. | ||
44 | * Some later models (especially PXA-25x and PXA-27x based ones) lie | ||
45 | * and say they support CDC MDLM (for access to cell phone modems). | ||
46 | * | ||
47 | * There are non-Zaurus products that use these same protocols too. | ||
48 | * | ||
49 | * The annoying thing is that at the same time Sharp was developing | ||
50 | * that annoying standards-breaking software, the Linux community had | ||
51 | * a simple "CDC Subset" working reliably on the same SA-1100 hardware. | ||
52 | * That is, the same functionality but not violating standards. | ||
53 | * | ||
54 | * The CDC Ethernet nonconformance points are troublesome to hosts | ||
55 | * with a true CDC Ethernet implementation: | ||
56 | * - Framing appends a CRC, which the spec says drivers "must not" do; | ||
57 | * - Transfers data in altsetting zero, instead of altsetting 1; | ||
58 | * - All these peripherals use the same ethernet address. | ||
59 | * | ||
60 | * The CDC MDLM nonconformance is less immediately troublesome, since all | ||
61 | * MDLM implementations are quasi-proprietary anyway. | ||
62 | */ | ||
63 | |||
64 | static struct sk_buff * | ||
65 | zaurus_tx_fixup(struct usbnet *dev, struct sk_buff *skb, unsigned flags) | ||
66 | { | ||
67 | int padlen; | ||
68 | struct sk_buff *skb2; | ||
69 | |||
70 | padlen = 2; | ||
71 | if (!skb_cloned(skb)) { | ||
72 | int tailroom = skb_tailroom(skb); | ||
73 | if ((padlen + 4) <= tailroom) | ||
74 | goto done; | ||
75 | } | ||
76 | skb2 = skb_copy_expand(skb, 0, 4 + padlen, flags); | ||
77 | dev_kfree_skb_any(skb); | ||
78 | skb = skb2; | ||
79 | if (skb) { | ||
80 | u32 fcs; | ||
81 | done: | ||
82 | fcs = crc32_le(~0, skb->data, skb->len); | ||
83 | fcs = ~fcs; | ||
84 | |||
85 | *skb_put (skb, 1) = fcs & 0xff; | ||
86 | *skb_put (skb, 1) = (fcs>> 8) & 0xff; | ||
87 | *skb_put (skb, 1) = (fcs>>16) & 0xff; | ||
88 | *skb_put (skb, 1) = (fcs>>24) & 0xff; | ||
89 | } | ||
90 | return skb; | ||
91 | } | ||
92 | |||
93 | static int zaurus_bind(struct usbnet *dev, struct usb_interface *intf) | ||
94 | { | ||
95 | /* Belcarra's funky framing has other options; mostly | ||
96 | * TRAILERS (!) with 4 bytes CRC, and maybe 2 pad bytes. | ||
97 | */ | ||
98 | dev->net->hard_header_len += 6; | ||
99 | dev->rx_urb_size = dev->net->hard_header_len + dev->net->mtu; | ||
100 | return usbnet_generic_cdc_bind(dev, intf); | ||
101 | } | ||
102 | |||
103 | /* PDA style devices are always connected if present */ | ||
104 | static int always_connected (struct usbnet *dev) | ||
105 | { | ||
106 | return 0; | ||
107 | } | ||
108 | |||
109 | static const struct driver_info zaurus_sl5x00_info = { | ||
110 | .description = "Sharp Zaurus SL-5x00", | ||
111 | .flags = FLAG_FRAMING_Z, | ||
112 | .check_connect = always_connected, | ||
113 | .bind = zaurus_bind, | ||
114 | .unbind = usbnet_cdc_unbind, | ||
115 | .tx_fixup = zaurus_tx_fixup, | ||
116 | }; | ||
117 | #define ZAURUS_STRONGARM_INFO ((unsigned long)&zaurus_sl5x00_info) | ||
118 | |||
119 | static const struct driver_info zaurus_pxa_info = { | ||
120 | .description = "Sharp Zaurus, PXA-2xx based", | ||
121 | .flags = FLAG_FRAMING_Z, | ||
122 | .check_connect = always_connected, | ||
123 | .bind = zaurus_bind, | ||
124 | .unbind = usbnet_cdc_unbind, | ||
125 | .tx_fixup = zaurus_tx_fixup, | ||
126 | }; | ||
127 | #define ZAURUS_PXA_INFO ((unsigned long)&zaurus_pxa_info) | ||
128 | |||
129 | static const struct driver_info olympus_mxl_info = { | ||
130 | .description = "Olympus R1000", | ||
131 | .flags = FLAG_FRAMING_Z, | ||
132 | .check_connect = always_connected, | ||
133 | .bind = zaurus_bind, | ||
134 | .unbind = usbnet_cdc_unbind, | ||
135 | .tx_fixup = zaurus_tx_fixup, | ||
136 | }; | ||
137 | #define OLYMPUS_MXL_INFO ((unsigned long)&olympus_mxl_info) | ||
138 | |||
139 | |||
140 | /* Some more recent products using Lineo/Belcarra code will wrongly claim | ||
141 | * CDC MDLM conformance. They aren't conformant: data endpoints live | ||
142 | * in the control interface, there's no data interface, and it's not used | ||
143 | * to talk to a cell phone radio. But at least we can detect these two | ||
144 | * pseudo-classes, rather than growing this product list with entries for | ||
145 | * each new nonconformant product (sigh). | ||
146 | */ | ||
147 | static const u8 safe_guid[16] = { | ||
148 | 0x5d, 0x34, 0xcf, 0x66, 0x11, 0x18, 0x11, 0xd6, | ||
149 | 0xa2, 0x1a, 0x00, 0x01, 0x02, 0xca, 0x9a, 0x7f, | ||
150 | }; | ||
151 | static const u8 blan_guid[16] = { | ||
152 | 0x74, 0xf0, 0x3d, 0xbd, 0x1e, 0xc1, 0x44, 0x70, | ||
153 | 0xa3, 0x67, 0x71, 0x34, 0xc9, 0xf5, 0x54, 0x37, | ||
154 | }; | ||
155 | |||
156 | static int blan_mdlm_bind(struct usbnet *dev, struct usb_interface *intf) | ||
157 | { | ||
158 | u8 *buf = intf->cur_altsetting->extra; | ||
159 | int len = intf->cur_altsetting->extralen; | ||
160 | struct usb_cdc_mdlm_desc *desc = NULL; | ||
161 | struct usb_cdc_mdlm_detail_desc *detail = NULL; | ||
162 | |||
163 | while (len > 3) { | ||
164 | if (buf [1] != USB_DT_CS_INTERFACE) | ||
165 | goto next_desc; | ||
166 | |||
167 | /* use bDescriptorSubType, and just verify that we get a | ||
168 | * "BLAN" (or "SAFE") descriptor. | ||
169 | */ | ||
170 | switch (buf [2]) { | ||
171 | case USB_CDC_MDLM_TYPE: | ||
172 | if (desc) { | ||
173 | dev_dbg(&intf->dev, "extra MDLM\n"); | ||
174 | goto bad_desc; | ||
175 | } | ||
176 | desc = (void *) buf; | ||
177 | if (desc->bLength != sizeof *desc) { | ||
178 | dev_dbg(&intf->dev, "MDLM len %u\n", | ||
179 | desc->bLength); | ||
180 | goto bad_desc; | ||
181 | } | ||
182 | /* expect bcdVersion 1.0, ignore */ | ||
183 | if (memcmp(&desc->bGUID, blan_guid, 16) | ||
184 | && memcmp(&desc->bGUID, safe_guid, 16) ) { | ||
185 | /* hey, this one might _really_ be MDLM! */ | ||
186 | dev_dbg(&intf->dev, "MDLM guid\n"); | ||
187 | goto bad_desc; | ||
188 | } | ||
189 | break; | ||
190 | case USB_CDC_MDLM_DETAIL_TYPE: | ||
191 | if (detail) { | ||
192 | dev_dbg(&intf->dev, "extra MDLM detail\n"); | ||
193 | goto bad_desc; | ||
194 | } | ||
195 | detail = (void *) buf; | ||
196 | switch (detail->bGuidDescriptorType) { | ||
197 | case 0: /* "SAFE" */ | ||
198 | if (detail->bLength != (sizeof *detail + 2)) | ||
199 | goto bad_detail; | ||
200 | break; | ||
201 | case 1: /* "BLAN" */ | ||
202 | if (detail->bLength != (sizeof *detail + 3)) | ||
203 | goto bad_detail; | ||
204 | break; | ||
205 | default: | ||
206 | goto bad_detail; | ||
207 | } | ||
208 | |||
209 | /* assuming we either noticed BLAN already, or will | ||
210 | * find it soon, there are some data bytes here: | ||
211 | * - bmNetworkCapabilities (unused) | ||
212 | * - bmDataCapabilities (bits, see below) | ||
213 | * - bPad (ignored, for PADAFTER -- BLAN-only) | ||
214 | * bits are: | ||
215 | * - 0x01 -- Zaurus framing (add CRC) | ||
216 | * - 0x02 -- PADBEFORE (CRC includes some padding) | ||
217 | * - 0x04 -- PADAFTER (some padding after CRC) | ||
218 | * - 0x08 -- "fermat" packet mangling (for hw bugs) | ||
219 | * the PADBEFORE appears not to matter; we interop | ||
220 | * with devices that use it and those that don't. | ||
221 | */ | ||
222 | if ((detail->bDetailData[1] & ~0x02) != 0x01) { | ||
223 | /* bmDataCapabilites == 0 would be fine too, | ||
224 | * but framing is minidriver-coupled for now. | ||
225 | */ | ||
226 | bad_detail: | ||
227 | dev_dbg(&intf->dev, | ||
228 | "bad MDLM detail, %d %d %d\n", | ||
229 | detail->bLength, | ||
230 | detail->bDetailData[0], | ||
231 | detail->bDetailData[2]); | ||
232 | goto bad_desc; | ||
233 | } | ||
234 | break; | ||
235 | } | ||
236 | next_desc: | ||
237 | len -= buf [0]; /* bLength */ | ||
238 | buf += buf [0]; | ||
239 | } | ||
240 | |||
241 | if (!desc || !detail) { | ||
242 | dev_dbg(&intf->dev, "missing cdc mdlm %s%sdescriptor\n", | ||
243 | desc ? "" : "func ", | ||
244 | detail ? "" : "detail "); | ||
245 | goto bad_desc; | ||
246 | } | ||
247 | |||
248 | /* There's probably a CDC Ethernet descriptor there, but we can't | ||
249 | * rely on the Ethernet address it provides since not all vendors | ||
250 | * bother to make it unique. Likewise there's no point in tracking | ||
251 | * of the CDC event notifications. | ||
252 | */ | ||
253 | return usbnet_get_endpoints(dev, intf); | ||
254 | |||
255 | bad_desc: | ||
256 | dev_info(&dev->udev->dev, "unsupported MDLM descriptors\n"); | ||
257 | return -ENODEV; | ||
258 | } | ||
259 | |||
260 | static const struct driver_info bogus_mdlm_info = { | ||
261 | .description = "pseudo-MDLM (BLAN) device", | ||
262 | .flags = FLAG_FRAMING_Z, | ||
263 | .check_connect = always_connected, | ||
264 | .tx_fixup = zaurus_tx_fixup, | ||
265 | .bind = blan_mdlm_bind, | ||
266 | }; | ||
267 | |||
268 | static const struct usb_device_id products [] = { | ||
269 | #define ZAURUS_MASTER_INTERFACE \ | ||
270 | .bInterfaceClass = USB_CLASS_COMM, \ | ||
271 | .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET, \ | ||
272 | .bInterfaceProtocol = USB_CDC_PROTO_NONE | ||
273 | |||
274 | /* SA-1100 based Sharp Zaurus ("collie"), or compatible. */ | ||
275 | { | ||
276 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
277 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
278 | .idVendor = 0x04DD, | ||
279 | .idProduct = 0x8004, | ||
280 | ZAURUS_MASTER_INTERFACE, | ||
281 | .driver_info = ZAURUS_STRONGARM_INFO, | ||
282 | }, | ||
283 | |||
284 | /* PXA-2xx based models are also lying-about-cdc. If you add any | ||
285 | * more devices that claim to be CDC Ethernet, make sure they get | ||
286 | * added to the blacklist in cdc_ether too. | ||
287 | * | ||
288 | * NOTE: OpenZaurus versions with 2.6 kernels won't use these entries, | ||
289 | * unlike the older ones with 2.4 "embedix" kernels. | ||
290 | */ | ||
291 | { | ||
292 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
293 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
294 | .idVendor = 0x04DD, | ||
295 | .idProduct = 0x8005, /* A-300 */ | ||
296 | ZAURUS_MASTER_INTERFACE, | ||
297 | .driver_info = ZAURUS_PXA_INFO, | ||
298 | }, { | ||
299 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
300 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
301 | .idVendor = 0x04DD, | ||
302 | .idProduct = 0x8006, /* B-500/SL-5600 */ | ||
303 | ZAURUS_MASTER_INTERFACE, | ||
304 | .driver_info = ZAURUS_PXA_INFO, | ||
305 | }, { | ||
306 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
307 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
308 | .idVendor = 0x04DD, | ||
309 | .idProduct = 0x8007, /* C-700 */ | ||
310 | ZAURUS_MASTER_INTERFACE, | ||
311 | .driver_info = ZAURUS_PXA_INFO, | ||
312 | }, { | ||
313 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
314 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
315 | .idVendor = 0x04DD, | ||
316 | .idProduct = 0x9031, /* C-750 C-760 */ | ||
317 | ZAURUS_MASTER_INTERFACE, | ||
318 | .driver_info = ZAURUS_PXA_INFO, | ||
319 | }, { | ||
320 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
321 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
322 | .idVendor = 0x04DD, | ||
323 | .idProduct = 0x9032, /* SL-6000 */ | ||
324 | ZAURUS_MASTER_INTERFACE, | ||
325 | .driver_info = ZAURUS_PXA_INFO, | ||
326 | }, { | ||
327 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
328 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
329 | .idVendor = 0x04DD, | ||
330 | /* reported with some C860 units */ | ||
331 | .idProduct = 0x9050, /* C-860 */ | ||
332 | ZAURUS_MASTER_INTERFACE, | ||
333 | .driver_info = ZAURUS_PXA_INFO, | ||
334 | }, | ||
335 | |||
336 | |||
337 | /* At least some of the newest PXA units have very different lies about | ||
338 | * their standards support: they claim to be cell phones offering | ||
339 | * direct access to their radios! (No, they don't conform to CDC MDLM.) | ||
340 | */ | ||
341 | { | ||
342 | USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_MDLM, | ||
343 | USB_CDC_PROTO_NONE), | ||
344 | .driver_info = (unsigned long) &bogus_mdlm_info, | ||
345 | }, | ||
346 | |||
347 | /* Olympus has some models with a Zaurus-compatible option. | ||
348 | * R-1000 uses a FreeScale i.MXL cpu (ARMv4T) | ||
349 | */ | ||
350 | { | ||
351 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
352 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
353 | .idVendor = 0x07B4, | ||
354 | .idProduct = 0x0F02, /* R-1000 */ | ||
355 | ZAURUS_MASTER_INTERFACE, | ||
356 | .driver_info = OLYMPUS_MXL_INFO, | ||
357 | }, | ||
358 | { }, // END | ||
359 | }; | ||
360 | MODULE_DEVICE_TABLE(usb, products); | ||
361 | |||
362 | static struct usb_driver zaurus_driver = { | ||
363 | .owner = THIS_MODULE, | ||
364 | .name = "zaurus", | ||
365 | .id_table = products, | ||
366 | .probe = usbnet_probe, | ||
367 | .disconnect = usbnet_disconnect, | ||
368 | .suspend = usbnet_suspend, | ||
369 | .resume = usbnet_resume, | ||
370 | }; | ||
371 | |||
372 | static int __init zaurus_init(void) | ||
373 | { | ||
374 | return usb_register(&zaurus_driver); | ||
375 | } | ||
376 | module_init(zaurus_init); | ||
377 | |||
378 | static void __exit zaurus_exit(void) | ||
379 | { | ||
380 | usb_deregister(&zaurus_driver); | ||
381 | } | ||
382 | module_exit(zaurus_exit); | ||
383 | |||
384 | MODULE_AUTHOR("Pavel Machek, David Brownell"); | ||
385 | MODULE_DESCRIPTION("Sharp Zaurus PDA, and compatible products"); | ||
386 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/net/zd1201.c b/drivers/usb/net/zd1201.c index fc013978837e..c4e479ee926a 100644 --- a/drivers/usb/net/zd1201.c +++ b/drivers/usb/net/zd1201.c | |||
@@ -847,7 +847,6 @@ static void zd1201_tx_timeout(struct net_device *dev) | |||
847 | return; | 847 | return; |
848 | dev_warn(&zd->usb->dev, "%s: TX timeout, shooting down urb\n", | 848 | dev_warn(&zd->usb->dev, "%s: TX timeout, shooting down urb\n", |
849 | dev->name); | 849 | dev->name); |
850 | zd->tx_urb->transfer_flags |= URB_ASYNC_UNLINK; | ||
851 | usb_unlink_urb(zd->tx_urb); | 850 | usb_unlink_urb(zd->tx_urb); |
852 | zd->stats.tx_errors++; | 851 | zd->stats.tx_errors++; |
853 | /* Restart the timeout to quiet the watchdog: */ | 852 | /* Restart the timeout to quiet the watchdog: */ |