aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/net
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/net')
-rw-r--r--drivers/usb/net/Kconfig307
-rw-r--r--drivers/usb/net/Makefile12
-rw-r--r--drivers/usb/net/catc.c960
-rw-r--r--drivers/usb/net/kaweth.c1271
-rw-r--r--drivers/usb/net/kawethfw.h557
-rw-r--r--drivers/usb/net/pegasus.c1408
-rw-r--r--drivers/usb/net/pegasus.h298
-rw-r--r--drivers/usb/net/rtl8150.c942
-rw-r--r--drivers/usb/net/usbnet.c4106
-rw-r--r--drivers/usb/net/zd1201.c1905
-rw-r--r--drivers/usb/net/zd1201.h147
11 files changed, 11913 insertions, 0 deletions
diff --git a/drivers/usb/net/Kconfig b/drivers/usb/net/Kconfig
new file mode 100644
index 000000000000..db64c908d4a7
--- /dev/null
+++ b/drivers/usb/net/Kconfig
@@ -0,0 +1,307 @@
1#
2# USB Network devices configuration
3#
4comment "Networking support is needed for USB Network Adapter support"
5 depends on USB && !NET
6
7menu "USB Network Adapters"
8 depends on USB && NET
9
10config USB_CATC
11 tristate "USB CATC NetMate-based Ethernet device support (EXPERIMENTAL)"
12 depends on EXPERIMENTAL
13 select CRC32
14 ---help---
15 Say Y if you want to use one of the following 10Mbps USB Ethernet
16 device based on the EL1210A chip. Supported devices are:
17 Belkin F5U011
18 Belkin F5U111
19 CATC NetMate
20 CATC NetMate II
21 smartBridges smartNIC
22
23 This driver makes the adapter appear as a normal Ethernet interface,
24 typically on eth0, if it is the only ethernet device, or perhaps on
25 eth1, if you have a PCI or ISA ethernet card installed.
26
27 To compile this driver as a module, choose M here: the
28 module will be called catc.
29
30config USB_KAWETH
31 tristate "USB KLSI KL5USB101-based ethernet device support"
32 ---help---
33 Say Y here if you want to use one of the following 10Mbps only
34 USB Ethernet adapters based on the KLSI KL5KUSB101B chipset:
35 3Com 3C19250
36 ADS USB-10BT
37 ATEN USB Ethernet
38 ASANTE USB To Ethernet Adapter
39 AOX Endpoints USB Ethernet
40 Correga K.K.
41 D-Link DSB-650C and DU-E10
42 Entrega / Portgear E45
43 I-O DATA USB-ET/T
44 Jaton USB Ethernet Device Adapter
45 Kingston Technology USB Ethernet Adapter
46 Linksys USB10T
47 Mobility USB-Ethernet Adapter
48 NetGear EA-101
49 Peracom Enet and Enet2
50 Portsmith Express Ethernet Adapter
51 Shark Pocket Adapter
52 SMC 2202USB
53 Sony Vaio port extender
54
55 This driver is likely to work with most 10Mbps only USB Ethernet
56 adapters, including some "no brand" devices. It does NOT work on
57 SmartBridges smartNIC or on Belkin F5U111 devices - you should use
58 the CATC NetMate driver for those. If you are not sure which one
59 you need, select both, and the correct one should be selected for
60 you.
61
62 This driver makes the adapter appear as a normal Ethernet interface,
63 typically on eth0, if it is the only ethernet device, or perhaps on
64 eth1, if you have a PCI or ISA ethernet card installed.
65
66 To compile this driver as a module, choose M here: the
67 module will be called kaweth.
68
69config USB_PEGASUS
70 tristate "USB Pegasus/Pegasus-II based ethernet device support"
71 select MII
72 ---help---
73 Say Y here if you know you have Pegasus or Pegasus-II based adapter.
74 If in doubt then look at <file:drivers/usb/net/pegasus.h> for the
75 complete list of supported devices.
76
77 If your particular adapter is not in the list and you are _sure_ it
78 is Pegasus or Pegasus II based then send me
79 <petkan@users.sourceforge.net> vendor and device IDs.
80
81 To compile this driver as a module, choose M here: the
82 module will be called pegasus.
83
84config USB_RTL8150
85 tristate "USB RTL8150 based ethernet device support (EXPERIMENTAL)"
86 depends on EXPERIMENTAL
87 help
88 Say Y here if you have RTL8150 based usb-ethernet adapter.
89 Send me <petkan@users.sourceforge.net> any comments you may have.
90 You can also check for updates at <http://pegasus2.sourceforge.net/>.
91
92 To compile this driver as a module, choose M here: the
93 module will be called rtl8150.
94
95config USB_USBNET
96 tristate "Multi-purpose USB Networking Framework"
97 ---help---
98 This driver supports several kinds of network links over USB,
99 with "minidrivers" built around a common network driver core
100 that supports deep queues for efficient transfers. (This gives
101 better performance with small packets and at high speeds).
102
103 The USB host runs "usbnet", and the other end of the link might be:
104
105 - Another USB host, when using USB "network" or "data transfer"
106 cables. These are often used to network laptops to PCs, like
107 "Laplink" parallel cables or some motherboards. These rely
108 on specialized chips from many suppliers.
109
110 - An intelligent USB gadget, perhaps embedding a Linux system.
111 These include PDAs running Linux (iPaq, Yopy, Zaurus, and
112 others), and devices that interoperate using the standard
113 CDC-Ethernet specification (including many cable modems).
114
115 - Network adapter hardware (like those for 10/100 Ethernet) which
116 uses this driver framework.
117
118 The link will appear with a name like "usb0", when the link is
119 a two-node link, or "eth0" for most CDC-Ethernet devices. Those
120 two-node links are most easily managed with Ethernet Bridging
121 (CONFIG_BRIDGE) instead of routing.
122
123 For more information see <http://www.linux-usb.org/usbnet/>.
124
125 To compile this driver as a module, choose M here: the
126 module will be called usbnet.
127
128comment "USB Host-to-Host Cables"
129 depends on USB_USBNET
130
131config USB_ALI_M5632
132 boolean "ALi M5632 based 'USB 2.0 Data Link' cables"
133 depends on USB_USBNET
134 default y
135 help
136 Choose this option if you're using a host-to-host cable
137 based on this design, which supports USB 2.0 high speed.
138
139config USB_AN2720
140 boolean "AnchorChips 2720 based cables (Xircom PGUNET, ...)"
141 depends on USB_USBNET
142 default y
143 help
144 Choose this option if you're using a host-to-host cable
145 based on this design. Note that AnchorChips is now a
146 Cypress brand.
147
148config USB_BELKIN
149 boolean "eTEK based host-to-host cables (Advance, Belkin, ...)"
150 depends on USB_USBNET
151 default y
152 help
153 Choose this option if you're using a host-to-host cable
154 based on this design: two NetChip 2890 chips and an Atmel
155 microcontroller, with LEDs that indicate traffic.
156
157config USB_GENESYS
158 boolean "GeneSys GL620USB-A based cables"
159 default y
160 depends on USB_USBNET
161 help
162 Choose this option if you're using a host-to-host cable,
163 or PC2PC motherboard, with this chip.
164
165 Note that the half-duplex "GL620USB" is not supported.
166
167config USB_NET1080
168 boolean "NetChip 1080 based cables (Laplink, ...)"
169 default y
170 depends on USB_USBNET
171 help
172 Choose this option if you're using a host-to-host cable based
173 on this design: one NetChip 1080 chips and supporting logic,
174 supporting LEDs that indicate traffic
175
176config USB_PL2301
177 boolean "Prolific PL-2301/2302 based cables"
178 default y
179 # handshake/init/reset problems, from original 'plusb' driver
180 depends on USB_USBNET && EXPERIMENTAL
181 help
182 Choose this option if you're using a host-to-host cable
183 with one of these chips.
184
185config USB_KC2190
186 boolean "KT Technology KC2190 based cables (InstaNet)"
187 default y
188 depends on USB_USBNET && EXPERIMENTAL
189 help
190 Choose this option if you're using a host-to-host cable
191 with one of these chips.
192
193comment "Intelligent USB Devices/Gadgets"
194 depends on USB_USBNET
195
196config USB_ARMLINUX
197 boolean "Embedded ARM Linux links (iPaq, ...)"
198 depends on USB_USBNET
199 default y
200 help
201 Choose this option to support the "usb-eth" networking driver
202 used by most of the ARM Linux community with device controllers
203 such as the SA-11x0 and PXA-25x UDCs, or the tftp capabilities
204 in some PXA versions of the "blob" boot loader.
205
206 Linux-based "Gumstix" PXA-25x based systems use this protocol
207 to talk with other Linux systems.
208
209 Although the ROMs shipped with Sharp Zaurus products use a
210 different link level framing protocol, you can have them use
211 this simpler protocol by installing a different kernel.
212
213config USB_EPSON2888
214 boolean "Epson 2888 based firmware (DEVELOPMENT)"
215 depends on USB_USBNET
216 default y
217 help
218 Choose this option to support the usb networking links used
219 by some sample firmware from Epson.
220
221config USB_ZAURUS
222 boolean "Sharp Zaurus (stock ROMs)"
223 depends on USB_USBNET
224 select CRC32
225 default y
226 help
227 Choose this option to support the usb networking links used by
228 Zaurus models like the SL-5000D, SL-5500, SL-5600, A-300, B-500.
229
230 If you install an alternate ROM image, you may no longer need
231 to support this protocol. Only the "eth-fd" driver really needs
232 this non-conformant variant of CDC Ethernet protocol.
233
234config USB_CDCETHER
235 boolean "CDC Ethernet support (smart devices such as cable modems)"
236 depends on USB_USBNET
237 default y
238 help
239 This option supports devices conforming to the Communication Device
240 Class (CDC) Ethernet Control Model, a specification that's easy to
241 implement in device firmware. The CDC specifications are available
242 from <http://www.usb.org/>.
243
244 CDC Ethernet is an implementation option for DOCSIS cable modems
245 that support USB connectivity, used for non-Microsoft USB hosts.
246 This driver should work with at least the following devices:
247
248 * Ericsson PipeRider (all variants)
249 * Motorola (DM100 and SB4100)
250 * Broadcom Cable Modem (reference design)
251 * Toshiba PCX1100U
252 * ...
253
254 This driver creates an interface named "ethX", where X depends on
255 what other networking devices you have in use. However, if the
256 IEEE 802 "local assignment" bit is set in the address, a "usbX"
257 name is used instead.
258
259comment "USB Network Adapters"
260 depends on USB_USBNET
261
262config USB_AX8817X
263 boolean "ASIX AX88xxx Based USB 2.0 Ethernet Devices"
264 depends on USB_USBNET && NET_ETHERNET
265 select CRC32
266 select MII
267 default y
268 help
269 This option adds support for ASIX AX88xxx based USB 2.0
270 10/100 Ethernet devices.
271
272 This driver should work with at least the following devices:
273 * Aten UC210T
274 * ASIX AX88172
275 * Billionton Systems, USB2AR
276 * Buffalo LUA-U2-KTX
277 * Corega FEther USB2-TX
278 * D-Link DUB-E100
279 * Hawking UF200
280 * Linksys USB200M
281 * Netgear FA120
282 * Sitecom LN-029
283 * Intellinet USB 2.0 Ethernet
284 * ST Lab USB 2.0 Ethernet
285 * TrendNet TU2-ET100
286
287 This driver creates an interface named "ethX", where X depends on
288 what other networking devices you have in use.
289
290config USB_ZD1201
291 tristate "USB ZD1201 based Wireless device support"
292 depends on NET_RADIO
293 select FW_LOADER
294 ---help---
295 Say Y if you want to use wireless LAN adapters based on the ZyDAS
296 ZD1201 chip.
297
298 This driver makes the adapter appear as a normal Ethernet interface,
299 typically on wlan0.
300
301 The zd1201 device requires external firmware to be loaded.
302 This can be found at http://linux-lc100020.sourceforge.net/
303
304 To compile this driver as a module, choose M here: the
305 module will be called zd1201.
306
307endmenu
diff --git a/drivers/usb/net/Makefile b/drivers/usb/net/Makefile
new file mode 100644
index 000000000000..16f352195512
--- /dev/null
+++ b/drivers/usb/net/Makefile
@@ -0,0 +1,12 @@
1#
2# Makefile for USB Network drivers
3#
4
5obj-$(CONFIG_USB_CATC) += catc.o
6obj-$(CONFIG_USB_KAWETH) += kaweth.o
7obj-$(CONFIG_USB_PEGASUS) += pegasus.o
8obj-$(CONFIG_USB_RTL8150) += rtl8150.o
9obj-$(CONFIG_USB_USBNET) += usbnet.o
10obj-$(CONFIG_USB_ZD1201) += zd1201.o
11
12CFLAGS_zd1201.o = -Idrivers/net/wireless/
diff --git a/drivers/usb/net/catc.c b/drivers/usb/net/catc.c
new file mode 100644
index 000000000000..c8be912f24e1
--- /dev/null
+++ b/drivers/usb/net/catc.c
@@ -0,0 +1,960 @@
1/*
2 * Copyright (c) 2001 Vojtech Pavlik
3 *
4 * CATC EL1210A NetMate USB Ethernet driver
5 *
6 * Sponsored by SuSE
7 *
8 * Based on the work of
9 * Donald Becker
10 *
11 * Old chipset support added by Simon Evans <spse@secret.org.uk> 2002
12 * - adds support for Belkin F5U011
13 */
14
15/*
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 *
30 * Should you need to contact me, the author, you can do so either by
31 * e-mail - mail your message to <vojtech@suse.cz>, or by paper mail:
32 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
33 */
34
35#include <linux/init.h>
36#include <linux/module.h>
37#include <linux/kernel.h>
38#include <linux/string.h>
39#include <linux/slab.h>
40#include <linux/netdevice.h>
41#include <linux/etherdevice.h>
42#include <linux/skbuff.h>
43#include <linux/spinlock.h>
44#include <linux/ethtool.h>
45#include <linux/crc32.h>
46#include <linux/bitops.h>
47#include <asm/uaccess.h>
48
49#undef DEBUG
50
51#include <linux/usb.h>
52
53/*
54 * Version information.
55 */
56
57#define DRIVER_VERSION "v2.8"
58#define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@suse.cz>"
59#define DRIVER_DESC "CATC EL1210A NetMate USB Ethernet driver"
60#define SHORT_DRIVER_DESC "EL1210A NetMate USB Ethernet"
61
62MODULE_AUTHOR(DRIVER_AUTHOR);
63MODULE_DESCRIPTION(DRIVER_DESC);
64MODULE_LICENSE("GPL");
65
66static const char driver_name[] = "catc";
67
68/*
69 * Some defines.
70 */
71
72#define STATS_UPDATE (HZ) /* Time between stats updates */
73#define TX_TIMEOUT (5*HZ) /* Max time the queue can be stopped */
74#define PKT_SZ 1536 /* Max Ethernet packet size */
75#define RX_MAX_BURST 15 /* Max packets per rx buffer (> 0, < 16) */
76#define TX_MAX_BURST 15 /* Max full sized packets per tx buffer (> 0) */
77#define CTRL_QUEUE 16 /* Max control requests in flight (power of two) */
78#define RX_PKT_SZ 1600 /* Max size of receive packet for F5U011 */
79
80/*
81 * Control requests.
82 */
83
84enum control_requests {
85 ReadMem = 0xf1,
86 GetMac = 0xf2,
87 Reset = 0xf4,
88 SetMac = 0xf5,
89 SetRxMode = 0xf5, /* F5U011 only */
90 WriteROM = 0xf8,
91 SetReg = 0xfa,
92 GetReg = 0xfb,
93 WriteMem = 0xfc,
94 ReadROM = 0xfd,
95};
96
97/*
98 * Registers.
99 */
100
101enum register_offsets {
102 TxBufCount = 0x20,
103 RxBufCount = 0x21,
104 OpModes = 0x22,
105 TxQed = 0x23,
106 RxQed = 0x24,
107 MaxBurst = 0x25,
108 RxUnit = 0x60,
109 EthStatus = 0x61,
110 StationAddr0 = 0x67,
111 EthStats = 0x69,
112 LEDCtrl = 0x81,
113};
114
115enum eth_stats {
116 TxSingleColl = 0x00,
117 TxMultiColl = 0x02,
118 TxExcessColl = 0x04,
119 RxFramErr = 0x06,
120};
121
122enum op_mode_bits {
123 Op3MemWaits = 0x03,
124 OpLenInclude = 0x08,
125 OpRxMerge = 0x10,
126 OpTxMerge = 0x20,
127 OpWin95bugfix = 0x40,
128 OpLoopback = 0x80,
129};
130
131enum rx_filter_bits {
132 RxEnable = 0x01,
133 RxPolarity = 0x02,
134 RxForceOK = 0x04,
135 RxMultiCast = 0x08,
136 RxPromisc = 0x10,
137 AltRxPromisc = 0x20, /* F5U011 uses different bit */
138};
139
140enum led_values {
141 LEDFast = 0x01,
142 LEDSlow = 0x02,
143 LEDFlash = 0x03,
144 LEDPulse = 0x04,
145 LEDLink = 0x08,
146};
147
148enum link_status {
149 LinkNoChange = 0,
150 LinkGood = 1,
151 LinkBad = 2
152};
153
154/*
155 * The catc struct.
156 */
157
158#define CTRL_RUNNING 0
159#define RX_RUNNING 1
160#define TX_RUNNING 2
161
162struct catc {
163 struct net_device *netdev;
164 struct usb_device *usbdev;
165
166 struct net_device_stats stats;
167 unsigned long flags;
168
169 unsigned int tx_ptr, tx_idx;
170 unsigned int ctrl_head, ctrl_tail;
171 spinlock_t tx_lock, ctrl_lock;
172
173 u8 tx_buf[2][TX_MAX_BURST * (PKT_SZ + 2)];
174 u8 rx_buf[RX_MAX_BURST * (PKT_SZ + 2)];
175 u8 irq_buf[2];
176 u8 ctrl_buf[64];
177 struct usb_ctrlrequest ctrl_dr;
178
179 struct timer_list timer;
180 u8 stats_buf[8];
181 u16 stats_vals[4];
182 unsigned long last_stats;
183
184 u8 multicast[64];
185
186 struct ctrl_queue {
187 u8 dir;
188 u8 request;
189 u16 value;
190 u16 index;
191 void *buf;
192 int len;
193 void (*callback)(struct catc *catc, struct ctrl_queue *q);
194 } ctrl_queue[CTRL_QUEUE];
195
196 struct urb *tx_urb, *rx_urb, *irq_urb, *ctrl_urb;
197
198 u8 is_f5u011; /* Set if device is an F5U011 */
199 u8 rxmode[2]; /* Used for F5U011 */
200 atomic_t recq_sz; /* Used for F5U011 - counter of waiting rx packets */
201};
202
203/*
204 * Useful macros.
205 */
206
207#define catc_get_mac(catc, mac) catc_ctrl_msg(catc, USB_DIR_IN, GetMac, 0, 0, mac, 6)
208#define catc_reset(catc) catc_ctrl_msg(catc, USB_DIR_OUT, Reset, 0, 0, NULL, 0)
209#define catc_set_reg(catc, reg, val) catc_ctrl_msg(catc, USB_DIR_OUT, SetReg, val, reg, NULL, 0)
210#define catc_get_reg(catc, reg, buf) catc_ctrl_msg(catc, USB_DIR_IN, GetReg, 0, reg, buf, 1)
211#define catc_write_mem(catc, addr, buf, size) catc_ctrl_msg(catc, USB_DIR_OUT, WriteMem, 0, addr, buf, size)
212#define catc_read_mem(catc, addr, buf, size) catc_ctrl_msg(catc, USB_DIR_IN, ReadMem, 0, addr, buf, size)
213
214#define f5u011_rxmode(catc, rxmode) catc_ctrl_msg(catc, USB_DIR_OUT, SetRxMode, 0, 1, rxmode, 2)
215#define f5u011_rxmode_async(catc, rxmode) catc_ctrl_async(catc, USB_DIR_OUT, SetRxMode, 0, 1, &rxmode, 2, NULL)
216#define f5u011_mchash_async(catc, hash) catc_ctrl_async(catc, USB_DIR_OUT, SetRxMode, 0, 2, &hash, 8, NULL)
217
218#define catc_set_reg_async(catc, reg, val) catc_ctrl_async(catc, USB_DIR_OUT, SetReg, val, reg, NULL, 0, NULL)
219#define catc_get_reg_async(catc, reg, cb) catc_ctrl_async(catc, USB_DIR_IN, GetReg, 0, reg, NULL, 1, cb)
220#define catc_write_mem_async(catc, addr, buf, size) catc_ctrl_async(catc, USB_DIR_OUT, WriteMem, 0, addr, buf, size, NULL)
221
222/*
223 * Receive routines.
224 */
225
226static void catc_rx_done(struct urb *urb, struct pt_regs *regs)
227{
228 struct catc *catc = urb->context;
229 u8 *pkt_start = urb->transfer_buffer;
230 struct sk_buff *skb;
231 int pkt_len, pkt_offset = 0;
232
233 if (!catc->is_f5u011) {
234 clear_bit(RX_RUNNING, &catc->flags);
235 pkt_offset = 2;
236 }
237
238 if (urb->status) {
239 dbg("rx_done, status %d, length %d", urb->status, urb->actual_length);
240 return;
241 }
242
243 do {
244 if(!catc->is_f5u011) {
245 pkt_len = le16_to_cpup((__le16*)pkt_start);
246 if (pkt_len > urb->actual_length) {
247 catc->stats.rx_length_errors++;
248 catc->stats.rx_errors++;
249 break;
250 }
251 } else {
252 pkt_len = urb->actual_length;
253 }
254
255 if (!(skb = dev_alloc_skb(pkt_len)))
256 return;
257
258 skb->dev = catc->netdev;
259 eth_copy_and_sum(skb, pkt_start + pkt_offset, pkt_len, 0);
260 skb_put(skb, pkt_len);
261
262 skb->protocol = eth_type_trans(skb, catc->netdev);
263 netif_rx(skb);
264
265 catc->stats.rx_packets++;
266 catc->stats.rx_bytes += pkt_len;
267
268 /* F5U011 only does one packet per RX */
269 if (catc->is_f5u011)
270 break;
271 pkt_start += (((pkt_len + 1) >> 6) + 1) << 6;
272
273 } while (pkt_start - (u8 *) urb->transfer_buffer < urb->actual_length);
274
275 catc->netdev->last_rx = jiffies;
276
277 if (catc->is_f5u011) {
278 if (atomic_read(&catc->recq_sz)) {
279 int status;
280 atomic_dec(&catc->recq_sz);
281 dbg("getting extra packet");
282 urb->dev = catc->usbdev;
283 if ((status = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
284 dbg("submit(rx_urb) status %d", status);
285 }
286 } else {
287 clear_bit(RX_RUNNING, &catc->flags);
288 }
289 }
290}
291
292static void catc_irq_done(struct urb *urb, struct pt_regs *regs)
293{
294 struct catc *catc = urb->context;
295 u8 *data = urb->transfer_buffer;
296 int status;
297 unsigned int hasdata = 0, linksts = LinkNoChange;
298
299 if (!catc->is_f5u011) {
300 hasdata = data[1] & 0x80;
301 if (data[1] & 0x40)
302 linksts = LinkGood;
303 else if (data[1] & 0x20)
304 linksts = LinkBad;
305 } else {
306 hasdata = (unsigned int)(be16_to_cpup((__be16*)data) & 0x0fff);
307 if (data[0] == 0x90)
308 linksts = LinkGood;
309 else if (data[0] == 0xA0)
310 linksts = LinkBad;
311 }
312
313 switch (urb->status) {
314 case 0: /* success */
315 break;
316 case -ECONNRESET: /* unlink */
317 case -ENOENT:
318 case -ESHUTDOWN:
319 return;
320 /* -EPIPE: should clear the halt */
321 default: /* error */
322 dbg("irq_done, status %d, data %02x %02x.", urb->status, data[0], data[1]);
323 goto resubmit;
324 }
325
326 if (linksts == LinkGood) {
327 netif_carrier_on(catc->netdev);
328 dbg("link ok");
329 }
330
331 if (linksts == LinkBad) {
332 netif_carrier_off(catc->netdev);
333 dbg("link bad");
334 }
335
336 if (hasdata) {
337 if (test_and_set_bit(RX_RUNNING, &catc->flags)) {
338 if (catc->is_f5u011)
339 atomic_inc(&catc->recq_sz);
340 } else {
341 catc->rx_urb->dev = catc->usbdev;
342 if ((status = usb_submit_urb(catc->rx_urb, GFP_ATOMIC)) < 0) {
343 err("submit(rx_urb) status %d", status);
344 }
345 }
346 }
347resubmit:
348 status = usb_submit_urb (urb, SLAB_ATOMIC);
349 if (status)
350 err ("can't resubmit intr, %s-%s, status %d",
351 catc->usbdev->bus->bus_name,
352 catc->usbdev->devpath, status);
353}
354
355/*
356 * Transmit routines.
357 */
358
359static void catc_tx_run(struct catc *catc)
360{
361 int status;
362
363 if (catc->is_f5u011)
364 catc->tx_ptr = (catc->tx_ptr + 63) & ~63;
365
366 catc->tx_urb->transfer_buffer_length = catc->tx_ptr;
367 catc->tx_urb->transfer_buffer = catc->tx_buf[catc->tx_idx];
368 catc->tx_urb->dev = catc->usbdev;
369
370 if ((status = usb_submit_urb(catc->tx_urb, GFP_ATOMIC)) < 0)
371 err("submit(tx_urb), status %d", status);
372
373 catc->tx_idx = !catc->tx_idx;
374 catc->tx_ptr = 0;
375
376 catc->netdev->trans_start = jiffies;
377}
378
379static void catc_tx_done(struct urb *urb, struct pt_regs *regs)
380{
381 struct catc *catc = urb->context;
382 unsigned long flags;
383
384 if (urb->status == -ECONNRESET) {
385 dbg("Tx Reset.");
386 urb->transfer_flags &= ~URB_ASYNC_UNLINK;
387 urb->status = 0;
388 catc->netdev->trans_start = jiffies;
389 catc->stats.tx_errors++;
390 clear_bit(TX_RUNNING, &catc->flags);
391 netif_wake_queue(catc->netdev);
392 return;
393 }
394
395 if (urb->status) {
396 dbg("tx_done, status %d, length %d", urb->status, urb->actual_length);
397 return;
398 }
399
400 spin_lock_irqsave(&catc->tx_lock, flags);
401
402 if (catc->tx_ptr)
403 catc_tx_run(catc);
404 else
405 clear_bit(TX_RUNNING, &catc->flags);
406
407 netif_wake_queue(catc->netdev);
408
409 spin_unlock_irqrestore(&catc->tx_lock, flags);
410}
411
412static int catc_hard_start_xmit(struct sk_buff *skb, struct net_device *netdev)
413{
414 struct catc *catc = netdev_priv(netdev);
415 unsigned long flags;
416 char *tx_buf;
417
418 spin_lock_irqsave(&catc->tx_lock, flags);
419
420 catc->tx_ptr = (((catc->tx_ptr - 1) >> 6) + 1) << 6;
421 tx_buf = catc->tx_buf[catc->tx_idx] + catc->tx_ptr;
422 *((u16*)tx_buf) = (catc->is_f5u011) ? cpu_to_be16((u16)skb->len) : cpu_to_le16((u16)skb->len);
423 memcpy(tx_buf + 2, skb->data, skb->len);
424 catc->tx_ptr += skb->len + 2;
425
426 if (!test_and_set_bit(TX_RUNNING, &catc->flags))
427 catc_tx_run(catc);
428
429 if ((catc->is_f5u011 && catc->tx_ptr)
430 || (catc->tx_ptr >= ((TX_MAX_BURST - 1) * (PKT_SZ + 2))))
431 netif_stop_queue(netdev);
432
433 spin_unlock_irqrestore(&catc->tx_lock, flags);
434
435 catc->stats.tx_bytes += skb->len;
436 catc->stats.tx_packets++;
437
438 dev_kfree_skb(skb);
439
440 return 0;
441}
442
443static void catc_tx_timeout(struct net_device *netdev)
444{
445 struct catc *catc = netdev_priv(netdev);
446
447 warn("Transmit timed out.");
448 catc->tx_urb->transfer_flags |= URB_ASYNC_UNLINK;
449 usb_unlink_urb(catc->tx_urb);
450}
451
452/*
453 * Control messages.
454 */
455
456static int catc_ctrl_msg(struct catc *catc, u8 dir, u8 request, u16 value, u16 index, void *buf, int len)
457{
458 int retval = usb_control_msg(catc->usbdev,
459 dir ? usb_rcvctrlpipe(catc->usbdev, 0) : usb_sndctrlpipe(catc->usbdev, 0),
460 request, 0x40 | dir, value, index, buf, len, 1000);
461 return retval < 0 ? retval : 0;
462}
463
464static void catc_ctrl_run(struct catc *catc)
465{
466 struct ctrl_queue *q = catc->ctrl_queue + catc->ctrl_tail;
467 struct usb_device *usbdev = catc->usbdev;
468 struct urb *urb = catc->ctrl_urb;
469 struct usb_ctrlrequest *dr = &catc->ctrl_dr;
470 int status;
471
472 dr->bRequest = q->request;
473 dr->bRequestType = 0x40 | q->dir;
474 dr->wValue = cpu_to_le16(q->value);
475 dr->wIndex = cpu_to_le16(q->index);
476 dr->wLength = cpu_to_le16(q->len);
477
478 urb->pipe = q->dir ? usb_rcvctrlpipe(usbdev, 0) : usb_sndctrlpipe(usbdev, 0);
479 urb->transfer_buffer_length = q->len;
480 urb->transfer_buffer = catc->ctrl_buf;
481 urb->setup_packet = (void *) dr;
482 urb->dev = usbdev;
483
484 if (!q->dir && q->buf && q->len)
485 memcpy(catc->ctrl_buf, q->buf, q->len);
486
487 if ((status = usb_submit_urb(catc->ctrl_urb, GFP_KERNEL)))
488 err("submit(ctrl_urb) status %d", status);
489}
490
491static void catc_ctrl_done(struct urb *urb, struct pt_regs *regs)
492{
493 struct catc *catc = urb->context;
494 struct ctrl_queue *q;
495 unsigned long flags;
496
497 if (urb->status)
498 dbg("ctrl_done, status %d, len %d.", urb->status, urb->actual_length);
499
500 spin_lock_irqsave(&catc->ctrl_lock, flags);
501
502 q = catc->ctrl_queue + catc->ctrl_tail;
503
504 if (q->dir) {
505 if (q->buf && q->len)
506 memcpy(q->buf, catc->ctrl_buf, q->len);
507 else
508 q->buf = catc->ctrl_buf;
509 }
510
511 if (q->callback)
512 q->callback(catc, q);
513
514 catc->ctrl_tail = (catc->ctrl_tail + 1) & (CTRL_QUEUE - 1);
515
516 if (catc->ctrl_head != catc->ctrl_tail)
517 catc_ctrl_run(catc);
518 else
519 clear_bit(CTRL_RUNNING, &catc->flags);
520
521 spin_unlock_irqrestore(&catc->ctrl_lock, flags);
522}
523
524static int catc_ctrl_async(struct catc *catc, u8 dir, u8 request, u16 value,
525 u16 index, void *buf, int len, void (*callback)(struct catc *catc, struct ctrl_queue *q))
526{
527 struct ctrl_queue *q;
528 int retval = 0;
529 unsigned long flags;
530
531 spin_lock_irqsave(&catc->ctrl_lock, flags);
532
533 q = catc->ctrl_queue + catc->ctrl_head;
534
535 q->dir = dir;
536 q->request = request;
537 q->value = value;
538 q->index = index;
539 q->buf = buf;
540 q->len = len;
541 q->callback = callback;
542
543 catc->ctrl_head = (catc->ctrl_head + 1) & (CTRL_QUEUE - 1);
544
545 if (catc->ctrl_head == catc->ctrl_tail) {
546 err("ctrl queue full");
547 catc->ctrl_tail = (catc->ctrl_tail + 1) & (CTRL_QUEUE - 1);
548 retval = -1;
549 }
550
551 if (!test_and_set_bit(CTRL_RUNNING, &catc->flags))
552 catc_ctrl_run(catc);
553
554 spin_unlock_irqrestore(&catc->ctrl_lock, flags);
555
556 return retval;
557}
558
559/*
560 * Statistics.
561 */
562
563static void catc_stats_done(struct catc *catc, struct ctrl_queue *q)
564{
565 int index = q->index - EthStats;
566 u16 data, last;
567
568 catc->stats_buf[index] = *((char *)q->buf);
569
570 if (index & 1)
571 return;
572
573 data = ((u16)catc->stats_buf[index] << 8) | catc->stats_buf[index + 1];
574 last = catc->stats_vals[index >> 1];
575
576 switch (index) {
577 case TxSingleColl:
578 case TxMultiColl:
579 catc->stats.collisions += data - last;
580 break;
581 case TxExcessColl:
582 catc->stats.tx_aborted_errors += data - last;
583 catc->stats.tx_errors += data - last;
584 break;
585 case RxFramErr:
586 catc->stats.rx_frame_errors += data - last;
587 catc->stats.rx_errors += data - last;
588 break;
589 }
590
591 catc->stats_vals[index >> 1] = data;
592}
593
594static void catc_stats_timer(unsigned long data)
595{
596 struct catc *catc = (void *) data;
597 int i;
598
599 for (i = 0; i < 8; i++)
600 catc_get_reg_async(catc, EthStats + 7 - i, catc_stats_done);
601
602 mod_timer(&catc->timer, jiffies + STATS_UPDATE);
603}
604
605static struct net_device_stats *catc_get_stats(struct net_device *netdev)
606{
607 struct catc *catc = netdev_priv(netdev);
608 return &catc->stats;
609}
610
611/*
612 * Receive modes. Broadcast, Multicast, Promisc.
613 */
614
615static void catc_multicast(unsigned char *addr, u8 *multicast)
616{
617 u32 crc;
618
619 crc = ether_crc_le(6, addr);
620 multicast[(crc >> 3) & 0x3f] |= 1 << (crc & 7);
621}
622
623static void catc_set_multicast_list(struct net_device *netdev)
624{
625 struct catc *catc = netdev_priv(netdev);
626 struct dev_mc_list *mc;
627 u8 broadcast[6];
628 u8 rx = RxEnable | RxPolarity | RxMultiCast;
629 int i;
630
631 memset(broadcast, 0xff, 6);
632 memset(catc->multicast, 0, 64);
633
634 catc_multicast(broadcast, catc->multicast);
635 catc_multicast(netdev->dev_addr, catc->multicast);
636
637 if (netdev->flags & IFF_PROMISC) {
638 memset(catc->multicast, 0xff, 64);
639 rx |= (!catc->is_f5u011) ? RxPromisc : AltRxPromisc;
640 }
641
642 if (netdev->flags & IFF_ALLMULTI) {
643 memset(catc->multicast, 0xff, 64);
644 } else {
645 for (i = 0, mc = netdev->mc_list; mc && i < netdev->mc_count; i++, mc = mc->next) {
646 u32 crc = ether_crc_le(6, mc->dmi_addr);
647 if (!catc->is_f5u011) {
648 catc->multicast[(crc >> 3) & 0x3f] |= 1 << (crc & 7);
649 } else {
650 catc->multicast[7-(crc >> 29)] |= 1 << ((crc >> 26) & 7);
651 }
652 }
653 }
654 if (!catc->is_f5u011) {
655 catc_set_reg_async(catc, RxUnit, rx);
656 catc_write_mem_async(catc, 0xfa80, catc->multicast, 64);
657 } else {
658 f5u011_mchash_async(catc, catc->multicast);
659 if (catc->rxmode[0] != rx) {
660 catc->rxmode[0] = rx;
661 dbg("Setting RX mode to %2.2X %2.2X", catc->rxmode[0], catc->rxmode[1]);
662 f5u011_rxmode_async(catc, catc->rxmode);
663 }
664 }
665}
666
667static void catc_get_drvinfo(struct net_device *dev,
668 struct ethtool_drvinfo *info)
669{
670 struct catc *catc = netdev_priv(dev);
671 strncpy(info->driver, driver_name, ETHTOOL_BUSINFO_LEN);
672 strncpy(info->version, DRIVER_VERSION, ETHTOOL_BUSINFO_LEN);
673 usb_make_path (catc->usbdev, info->bus_info, sizeof info->bus_info);
674}
675
676static int catc_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
677{
678 struct catc *catc = netdev_priv(dev);
679 if (!catc->is_f5u011)
680 return -EOPNOTSUPP;
681
682 cmd->supported = SUPPORTED_10baseT_Half | SUPPORTED_TP;
683 cmd->advertising = ADVERTISED_10baseT_Half | ADVERTISED_TP;
684 cmd->speed = SPEED_10;
685 cmd->duplex = DUPLEX_HALF;
686 cmd->port = PORT_TP;
687 cmd->phy_address = 0;
688 cmd->transceiver = XCVR_INTERNAL;
689 cmd->autoneg = AUTONEG_DISABLE;
690 cmd->maxtxpkt = 1;
691 cmd->maxrxpkt = 1;
692 return 0;
693}
694
695static struct ethtool_ops ops = {
696 .get_drvinfo = catc_get_drvinfo,
697 .get_settings = catc_get_settings,
698 .get_link = ethtool_op_get_link
699};
700
701/*
702 * Open, close.
703 */
704
705static int catc_open(struct net_device *netdev)
706{
707 struct catc *catc = netdev_priv(netdev);
708 int status;
709
710 catc->irq_urb->dev = catc->usbdev;
711 if ((status = usb_submit_urb(catc->irq_urb, GFP_KERNEL)) < 0) {
712 err("submit(irq_urb) status %d", status);
713 return -1;
714 }
715
716 netif_start_queue(netdev);
717
718 if (!catc->is_f5u011)
719 mod_timer(&catc->timer, jiffies + STATS_UPDATE);
720
721 return 0;
722}
723
724static int catc_stop(struct net_device *netdev)
725{
726 struct catc *catc = netdev_priv(netdev);
727
728 netif_stop_queue(netdev);
729
730 if (!catc->is_f5u011)
731 del_timer_sync(&catc->timer);
732
733 usb_kill_urb(catc->rx_urb);
734 usb_kill_urb(catc->tx_urb);
735 usb_kill_urb(catc->irq_urb);
736 usb_kill_urb(catc->ctrl_urb);
737
738 return 0;
739}
740
741/*
742 * USB probe, disconnect.
743 */
744
745static int catc_probe(struct usb_interface *intf, const struct usb_device_id *id)
746{
747 struct usb_device *usbdev = interface_to_usbdev(intf);
748 struct net_device *netdev;
749 struct catc *catc;
750 u8 broadcast[6];
751 int i, pktsz;
752
753 if (usb_set_interface(usbdev,
754 intf->altsetting->desc.bInterfaceNumber, 1)) {
755 err("Can't set altsetting 1.");
756 return -EIO;
757 }
758
759 netdev = alloc_etherdev(sizeof(struct catc));
760 if (!netdev)
761 return -ENOMEM;
762
763 catc = netdev_priv(netdev);
764
765 netdev->open = catc_open;
766 netdev->hard_start_xmit = catc_hard_start_xmit;
767 netdev->stop = catc_stop;
768 netdev->get_stats = catc_get_stats;
769 netdev->tx_timeout = catc_tx_timeout;
770 netdev->watchdog_timeo = TX_TIMEOUT;
771 netdev->set_multicast_list = catc_set_multicast_list;
772 SET_ETHTOOL_OPS(netdev, &ops);
773
774 catc->usbdev = usbdev;
775 catc->netdev = netdev;
776
777 spin_lock_init(&catc->tx_lock);
778 spin_lock_init(&catc->ctrl_lock);
779
780 init_timer(&catc->timer);
781 catc->timer.data = (long) catc;
782 catc->timer.function = catc_stats_timer;
783
784 catc->ctrl_urb = usb_alloc_urb(0, GFP_KERNEL);
785 catc->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
786 catc->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
787 catc->irq_urb = usb_alloc_urb(0, GFP_KERNEL);
788 if ((!catc->ctrl_urb) || (!catc->tx_urb) ||
789 (!catc->rx_urb) || (!catc->irq_urb)) {
790 err("No free urbs available.");
791 if (catc->ctrl_urb)
792 usb_free_urb(catc->ctrl_urb);
793 if (catc->tx_urb)
794 usb_free_urb(catc->tx_urb);
795 if (catc->rx_urb)
796 usb_free_urb(catc->rx_urb);
797 if (catc->irq_urb)
798 usb_free_urb(catc->irq_urb);
799 free_netdev(netdev);
800 return -ENOMEM;
801 }
802
803 /* The F5U011 has the same vendor/product as the netmate but a device version of 0x130 */
804 if (le16_to_cpu(usbdev->descriptor.idVendor) == 0x0423 &&
805 le16_to_cpu(usbdev->descriptor.idProduct) == 0xa &&
806 le16_to_cpu(catc->usbdev->descriptor.bcdDevice) == 0x0130) {
807 dbg("Testing for f5u011");
808 catc->is_f5u011 = 1;
809 atomic_set(&catc->recq_sz, 0);
810 pktsz = RX_PKT_SZ;
811 } else {
812 pktsz = RX_MAX_BURST * (PKT_SZ + 2);
813 }
814
815 usb_fill_control_urb(catc->ctrl_urb, usbdev, usb_sndctrlpipe(usbdev, 0),
816 NULL, NULL, 0, catc_ctrl_done, catc);
817
818 usb_fill_bulk_urb(catc->tx_urb, usbdev, usb_sndbulkpipe(usbdev, 1),
819 NULL, 0, catc_tx_done, catc);
820
821 usb_fill_bulk_urb(catc->rx_urb, usbdev, usb_rcvbulkpipe(usbdev, 1),
822 catc->rx_buf, pktsz, catc_rx_done, catc);
823
824 usb_fill_int_urb(catc->irq_urb, usbdev, usb_rcvintpipe(usbdev, 2),
825 catc->irq_buf, 2, catc_irq_done, catc, 1);
826
827 if (!catc->is_f5u011) {
828 dbg("Checking memory size\n");
829
830 i = 0x12345678;
831 catc_write_mem(catc, 0x7a80, &i, 4);
832 i = 0x87654321;
833 catc_write_mem(catc, 0xfa80, &i, 4);
834 catc_read_mem(catc, 0x7a80, &i, 4);
835
836 switch (i) {
837 case 0x12345678:
838 catc_set_reg(catc, TxBufCount, 8);
839 catc_set_reg(catc, RxBufCount, 32);
840 dbg("64k Memory\n");
841 break;
842 default:
843 warn("Couldn't detect memory size, assuming 32k");
844 case 0x87654321:
845 catc_set_reg(catc, TxBufCount, 4);
846 catc_set_reg(catc, RxBufCount, 16);
847 dbg("32k Memory\n");
848 break;
849 }
850
851 dbg("Getting MAC from SEEROM.");
852
853 catc_get_mac(catc, netdev->dev_addr);
854
855 dbg("Setting MAC into registers.");
856
857 for (i = 0; i < 6; i++)
858 catc_set_reg(catc, StationAddr0 - i, netdev->dev_addr[i]);
859
860 dbg("Filling the multicast list.");
861
862 memset(broadcast, 0xff, 6);
863 catc_multicast(broadcast, catc->multicast);
864 catc_multicast(netdev->dev_addr, catc->multicast);
865 catc_write_mem(catc, 0xfa80, catc->multicast, 64);
866
867 dbg("Clearing error counters.");
868
869 for (i = 0; i < 8; i++)
870 catc_set_reg(catc, EthStats + i, 0);
871 catc->last_stats = jiffies;
872
873 dbg("Enabling.");
874
875 catc_set_reg(catc, MaxBurst, RX_MAX_BURST);
876 catc_set_reg(catc, OpModes, OpTxMerge | OpRxMerge | OpLenInclude | Op3MemWaits);
877 catc_set_reg(catc, LEDCtrl, LEDLink);
878 catc_set_reg(catc, RxUnit, RxEnable | RxPolarity | RxMultiCast);
879 } else {
880 dbg("Performing reset\n");
881 catc_reset(catc);
882 catc_get_mac(catc, netdev->dev_addr);
883
884 dbg("Setting RX Mode");
885 catc->rxmode[0] = RxEnable | RxPolarity | RxMultiCast;
886 catc->rxmode[1] = 0;
887 f5u011_rxmode(catc, catc->rxmode);
888 }
889 dbg("Init done.");
890 printk(KERN_INFO "%s: %s USB Ethernet at usb-%s-%s, ",
891 netdev->name, (catc->is_f5u011) ? "Belkin F5U011" : "CATC EL1210A NetMate",
892 usbdev->bus->bus_name, usbdev->devpath);
893 for (i = 0; i < 5; i++) printk("%2.2x:", netdev->dev_addr[i]);
894 printk("%2.2x.\n", netdev->dev_addr[i]);
895 usb_set_intfdata(intf, catc);
896
897 SET_NETDEV_DEV(netdev, &intf->dev);
898 if (register_netdev(netdev) != 0) {
899 usb_set_intfdata(intf, NULL);
900 usb_free_urb(catc->ctrl_urb);
901 usb_free_urb(catc->tx_urb);
902 usb_free_urb(catc->rx_urb);
903 usb_free_urb(catc->irq_urb);
904 free_netdev(netdev);
905 return -EIO;
906 }
907 return 0;
908}
909
910static void catc_disconnect(struct usb_interface *intf)
911{
912 struct catc *catc = usb_get_intfdata(intf);
913
914 usb_set_intfdata(intf, NULL);
915 if (catc) {
916 unregister_netdev(catc->netdev);
917 usb_free_urb(catc->ctrl_urb);
918 usb_free_urb(catc->tx_urb);
919 usb_free_urb(catc->rx_urb);
920 usb_free_urb(catc->irq_urb);
921 free_netdev(catc->netdev);
922 }
923}
924
925/*
926 * Module functions and tables.
927 */
928
929static struct usb_device_id catc_id_table [] = {
930 { USB_DEVICE(0x0423, 0xa) }, /* CATC Netmate, Belkin F5U011 */
931 { USB_DEVICE(0x0423, 0xc) }, /* CATC Netmate II, Belkin F5U111 */
932 { USB_DEVICE(0x08d1, 0x1) }, /* smartBridges smartNIC */
933 { }
934};
935
936MODULE_DEVICE_TABLE(usb, catc_id_table);
937
938static struct usb_driver catc_driver = {
939 .owner = THIS_MODULE,
940 .name = driver_name,
941 .probe = catc_probe,
942 .disconnect = catc_disconnect,
943 .id_table = catc_id_table,
944};
945
946static int __init catc_init(void)
947{
948 int result = usb_register(&catc_driver);
949 if (result == 0)
950 info(DRIVER_VERSION " " DRIVER_DESC);
951 return result;
952}
953
954static void __exit catc_exit(void)
955{
956 usb_deregister(&catc_driver);
957}
958
959module_init(catc_init);
960module_exit(catc_exit);
diff --git a/drivers/usb/net/kaweth.c b/drivers/usb/net/kaweth.c
new file mode 100644
index 000000000000..a9a7cf4a38eb
--- /dev/null
+++ b/drivers/usb/net/kaweth.c
@@ -0,0 +1,1271 @@
1/****************************************************************
2 *
3 * kaweth.c - driver for KL5KUSB101 based USB->Ethernet
4 *
5 * (c) 2000 Interlan Communications
6 * (c) 2000 Stephane Alnet
7 * (C) 2001 Brad Hards
8 * (C) 2002 Oliver Neukum
9 *
10 * Original author: The Zapman <zapman@interlan.net>
11 * Inspired by, and much credit goes to Michael Rothwell
12 * <rothwell@interlan.net> for the test equipment, help, and patience
13 * Based off of (and with thanks to) Petko Manolov's pegaus.c driver.
14 * Also many thanks to Joel Silverman and Ed Surprenant at Kawasaki
15 * for providing the firmware and driver resources.
16 *
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License as
19 * published by the Free Software Foundation; either version 2, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software Foundation,
29 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 *
31 ****************************************************************/
32
33/* TODO:
34 * Fix in_interrupt() problem
35 * Develop test procedures for USB net interfaces
36 * Run test procedures
37 * Fix bugs from previous two steps
38 * Snoop other OSs for any tricks we're not doing
39 * SMP locking
40 * Reduce arbitrary timeouts
41 * Smart multicast support
42 * Temporary MAC change support
43 * Tunable SOFs parameter - ioctl()?
44 * Ethernet stats collection
45 * Code formatting improvements
46 */
47
48#include <linux/module.h>
49#include <linux/sched.h>
50#include <linux/slab.h>
51#include <linux/string.h>
52#include <linux/init.h>
53#include <linux/delay.h>
54#include <linux/netdevice.h>
55#include <linux/etherdevice.h>
56#include <linux/usb.h>
57#include <linux/types.h>
58#include <linux/ethtool.h>
59#include <linux/pci.h>
60#include <linux/dma-mapping.h>
61#include <linux/wait.h>
62#include <asm/uaccess.h>
63#include <asm/semaphore.h>
64#include <asm/byteorder.h>
65
66#undef DEBUG
67
68#ifdef DEBUG
69#define kaweth_dbg(format, arg...) printk(KERN_DEBUG __FILE__ ": " format "\n" ,##arg)
70#else
71#define kaweth_dbg(format, arg...) do {} while (0)
72#endif
73#define kaweth_err(format, arg...) printk(KERN_ERR __FILE__ ": " format "\n" ,##arg)
74#define kaweth_info(format, arg...) printk(KERN_INFO __FILE__ ": " format "\n" , ##arg)
75#define kaweth_warn(format, arg...) printk(KERN_WARNING __FILE__ ": " format "\n" , ##arg)
76
77
78#include "kawethfw.h"
79
80#define KAWETH_MTU 1514
81#define KAWETH_BUF_SIZE 1664
82#define KAWETH_TX_TIMEOUT (5 * HZ)
83#define KAWETH_SCRATCH_SIZE 32
84#define KAWETH_FIRMWARE_BUF_SIZE 4096
85#define KAWETH_CONTROL_TIMEOUT (30 * HZ)
86
87#define KAWETH_STATUS_BROKEN 0x0000001
88#define KAWETH_STATUS_CLOSING 0x0000002
89
90#define KAWETH_PACKET_FILTER_PROMISCUOUS 0x01
91#define KAWETH_PACKET_FILTER_ALL_MULTICAST 0x02
92#define KAWETH_PACKET_FILTER_DIRECTED 0x04
93#define KAWETH_PACKET_FILTER_BROADCAST 0x08
94#define KAWETH_PACKET_FILTER_MULTICAST 0x10
95
96/* Table 7 */
97#define KAWETH_COMMAND_GET_ETHERNET_DESC 0x00
98#define KAWETH_COMMAND_MULTICAST_FILTERS 0x01
99#define KAWETH_COMMAND_SET_PACKET_FILTER 0x02
100#define KAWETH_COMMAND_STATISTICS 0x03
101#define KAWETH_COMMAND_SET_TEMP_MAC 0x06
102#define KAWETH_COMMAND_GET_TEMP_MAC 0x07
103#define KAWETH_COMMAND_SET_URB_SIZE 0x08
104#define KAWETH_COMMAND_SET_SOFS_WAIT 0x09
105#define KAWETH_COMMAND_SCAN 0xFF
106
107#define KAWETH_SOFS_TO_WAIT 0x05
108
109#define INTBUFFERSIZE 4
110
111#define STATE_OFFSET 0
112#define STATE_MASK 0x40
113#define STATE_SHIFT 5
114
115
116MODULE_AUTHOR("Michael Zappe <zapman@interlan.net>, Stephane Alnet <stephane@u-picardie.fr>, Brad Hards <bhards@bigpond.net.au> and Oliver Neukum <oliver@neukum.org>");
117MODULE_DESCRIPTION("KL5USB101 USB Ethernet driver");
118MODULE_LICENSE("GPL");
119
120static const char driver_name[] = "kaweth";
121
122static int kaweth_probe(
123 struct usb_interface *intf,
124 const struct usb_device_id *id /* from id_table */
125 );
126static void kaweth_disconnect(struct usb_interface *intf);
127static int kaweth_internal_control_msg(struct usb_device *usb_dev,
128 unsigned int pipe,
129 struct usb_ctrlrequest *cmd, void *data,
130 int len, int timeout);
131
132/****************************************************************
133 * usb_device_id
134 ****************************************************************/
135static struct usb_device_id usb_klsi_table[] = {
136 { USB_DEVICE(0x03e8, 0x0008) }, /* AOX Endpoints USB Ethernet */
137 { USB_DEVICE(0x04bb, 0x0901) }, /* I-O DATA USB-ET/T */
138 { USB_DEVICE(0x0506, 0x03e8) }, /* 3Com 3C19250 */
139 { USB_DEVICE(0x0506, 0x11f8) }, /* 3Com 3C460 */
140 { USB_DEVICE(0x0557, 0x2002) }, /* ATEN USB Ethernet */
141 { USB_DEVICE(0x0557, 0x4000) }, /* D-Link DSB-650C */
142 { USB_DEVICE(0x0565, 0x0002) }, /* Peracom Enet */
143 { USB_DEVICE(0x0565, 0x0003) }, /* Optus@Home UEP1045A */
144 { USB_DEVICE(0x0565, 0x0005) }, /* Peracom Enet2 */
145 { USB_DEVICE(0x05e9, 0x0008) }, /* KLSI KL5KUSB101B */
146 { USB_DEVICE(0x05e9, 0x0009) }, /* KLSI KL5KUSB101B (Board change) */
147 { USB_DEVICE(0x066b, 0x2202) }, /* Linksys USB10T */
148 { USB_DEVICE(0x06e1, 0x0008) }, /* ADS USB-10BT */
149 { USB_DEVICE(0x06e1, 0x0009) }, /* ADS USB-10BT */
150 { USB_DEVICE(0x0707, 0x0100) }, /* SMC 2202USB */
151 { USB_DEVICE(0x07aa, 0x0001) }, /* Correga K.K. */
152 { USB_DEVICE(0x07b8, 0x4000) }, /* D-Link DU-E10 */
153 { USB_DEVICE(0x0846, 0x1001) }, /* NetGear EA-101 */
154 { USB_DEVICE(0x0846, 0x1002) }, /* NetGear EA-101 */
155 { USB_DEVICE(0x085a, 0x0008) }, /* PortGear Ethernet Adapter */
156 { USB_DEVICE(0x085a, 0x0009) }, /* PortGear Ethernet Adapter */
157 { USB_DEVICE(0x087d, 0x5704) }, /* Jaton USB Ethernet Device Adapter */
158 { USB_DEVICE(0x0951, 0x0008) }, /* Kingston Technology USB Ethernet Adapter */
159 { USB_DEVICE(0x095a, 0x3003) }, /* Portsmith Express Ethernet Adapter */
160 { USB_DEVICE(0x10bd, 0x1427) }, /* ASANTE USB To Ethernet Adapter */
161 { USB_DEVICE(0x1342, 0x0204) }, /* Mobility USB-Ethernet Adapter */
162 { USB_DEVICE(0x13d2, 0x0400) }, /* Shark Pocket Adapter */
163 { USB_DEVICE(0x1485, 0x0001) }, /* Silicom U2E */
164 { USB_DEVICE(0x1485, 0x0002) }, /* Psion Dacom Gold Port Ethernet */
165 { USB_DEVICE(0x1645, 0x0005) }, /* Entrega E45 */
166 { USB_DEVICE(0x1645, 0x0008) }, /* Entrega USB Ethernet Adapter */
167 { USB_DEVICE(0x1645, 0x8005) }, /* PortGear Ethernet Adapter */
168 { USB_DEVICE(0x2001, 0x4000) }, /* D-link DSB-650C */
169 {} /* Null terminator */
170};
171
172MODULE_DEVICE_TABLE (usb, usb_klsi_table);
173
174/****************************************************************
175 * kaweth_driver
176 ****************************************************************/
177static struct usb_driver kaweth_driver = {
178 .owner = THIS_MODULE,
179 .name = driver_name,
180 .probe = kaweth_probe,
181 .disconnect = kaweth_disconnect,
182 .id_table = usb_klsi_table,
183};
184
185typedef __u8 eth_addr_t[6];
186
187/****************************************************************
188 * usb_eth_dev
189 ****************************************************************/
190struct usb_eth_dev {
191 char *name;
192 __u16 vendor;
193 __u16 device;
194 void *pdata;
195};
196
197/****************************************************************
198 * kaweth_ethernet_configuration
199 * Refer Table 8
200 ****************************************************************/
201struct kaweth_ethernet_configuration
202{
203 __u8 size;
204 __u8 reserved1;
205 __u8 reserved2;
206 eth_addr_t hw_addr;
207 __u32 statistics_mask;
208 __le16 segment_size;
209 __u16 max_multicast_filters;
210 __u8 reserved3;
211} __attribute__ ((packed));
212
213/****************************************************************
214 * kaweth_device
215 ****************************************************************/
216struct kaweth_device
217{
218 spinlock_t device_lock;
219
220 __u32 status;
221 int end;
222 int removed;
223 int suspend_lowmem_rx;
224 int suspend_lowmem_ctrl;
225 int linkstate;
226 struct work_struct lowmem_work;
227
228 struct usb_device *dev;
229 struct net_device *net;
230 wait_queue_head_t term_wait;
231
232 struct urb *rx_urb;
233 struct urb *tx_urb;
234 struct urb *irq_urb;
235
236 dma_addr_t intbufferhandle;
237 __u8 *intbuffer;
238 dma_addr_t rxbufferhandle;
239 __u8 *rx_buf;
240
241
242 struct sk_buff *tx_skb;
243
244 __u8 *firmware_buf;
245 __u8 scratch[KAWETH_SCRATCH_SIZE];
246 __u16 packet_filter_bitmap;
247
248 struct kaweth_ethernet_configuration configuration;
249
250 struct net_device_stats stats;
251};
252
253
254/****************************************************************
255 * kaweth_control
256 ****************************************************************/
257static int kaweth_control(struct kaweth_device *kaweth,
258 unsigned int pipe,
259 __u8 request,
260 __u8 requesttype,
261 __u16 value,
262 __u16 index,
263 void *data,
264 __u16 size,
265 int timeout)
266{
267 struct usb_ctrlrequest *dr;
268
269 kaweth_dbg("kaweth_control()");
270
271 if(in_interrupt()) {
272 kaweth_dbg("in_interrupt()");
273 return -EBUSY;
274 }
275
276 dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC);
277
278 if (!dr) {
279 kaweth_dbg("kmalloc() failed");
280 return -ENOMEM;
281 }
282
283 dr->bRequestType= requesttype;
284 dr->bRequest = request;
285 dr->wValue = cpu_to_le16p(&value);
286 dr->wIndex = cpu_to_le16p(&index);
287 dr->wLength = cpu_to_le16p(&size);
288
289 return kaweth_internal_control_msg(kaweth->dev,
290 pipe,
291 dr,
292 data,
293 size,
294 timeout);
295}
296
297/****************************************************************
298 * kaweth_read_configuration
299 ****************************************************************/
300static int kaweth_read_configuration(struct kaweth_device *kaweth)
301{
302 int retval;
303
304 kaweth_dbg("Reading kaweth configuration");
305
306 retval = kaweth_control(kaweth,
307 usb_rcvctrlpipe(kaweth->dev, 0),
308 KAWETH_COMMAND_GET_ETHERNET_DESC,
309 USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_DEVICE,
310 0,
311 0,
312 (void *)&kaweth->configuration,
313 sizeof(kaweth->configuration),
314 KAWETH_CONTROL_TIMEOUT);
315
316 return retval;
317}
318
319/****************************************************************
320 * kaweth_set_urb_size
321 ****************************************************************/
322static int kaweth_set_urb_size(struct kaweth_device *kaweth, __u16 urb_size)
323{
324 int retval;
325
326 kaweth_dbg("Setting URB size to %d", (unsigned)urb_size);
327
328 retval = kaweth_control(kaweth,
329 usb_sndctrlpipe(kaweth->dev, 0),
330 KAWETH_COMMAND_SET_URB_SIZE,
331 USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
332 urb_size,
333 0,
334 (void *)&kaweth->scratch,
335 0,
336 KAWETH_CONTROL_TIMEOUT);
337
338 return retval;
339}
340
341/****************************************************************
342 * kaweth_set_sofs_wait
343 ****************************************************************/
344static int kaweth_set_sofs_wait(struct kaweth_device *kaweth, __u16 sofs_wait)
345{
346 int retval;
347
348 kaweth_dbg("Set SOFS wait to %d", (unsigned)sofs_wait);
349
350 retval = kaweth_control(kaweth,
351 usb_sndctrlpipe(kaweth->dev, 0),
352 KAWETH_COMMAND_SET_SOFS_WAIT,
353 USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
354 sofs_wait,
355 0,
356 (void *)&kaweth->scratch,
357 0,
358 KAWETH_CONTROL_TIMEOUT);
359
360 return retval;
361}
362
363/****************************************************************
364 * kaweth_set_receive_filter
365 ****************************************************************/
366static int kaweth_set_receive_filter(struct kaweth_device *kaweth,
367 __u16 receive_filter)
368{
369 int retval;
370
371 kaweth_dbg("Set receive filter to %d", (unsigned)receive_filter);
372
373 retval = kaweth_control(kaweth,
374 usb_sndctrlpipe(kaweth->dev, 0),
375 KAWETH_COMMAND_SET_PACKET_FILTER,
376 USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
377 receive_filter,
378 0,
379 (void *)&kaweth->scratch,
380 0,
381 KAWETH_CONTROL_TIMEOUT);
382
383 return retval;
384}
385
386/****************************************************************
387 * kaweth_download_firmware
388 ****************************************************************/
389static int kaweth_download_firmware(struct kaweth_device *kaweth,
390 __u8 *data,
391 __u16 data_len,
392 __u8 interrupt,
393 __u8 type)
394{
395 if(data_len > KAWETH_FIRMWARE_BUF_SIZE) {
396 kaweth_err("Firmware too big: %d", data_len);
397 return -ENOSPC;
398 }
399
400 memcpy(kaweth->firmware_buf, data, data_len);
401
402 kaweth->firmware_buf[2] = (data_len & 0xFF) - 7;
403 kaweth->firmware_buf[3] = data_len >> 8;
404 kaweth->firmware_buf[4] = type;
405 kaweth->firmware_buf[5] = interrupt;
406
407 kaweth_dbg("High: %i, Low:%i", kaweth->firmware_buf[3],
408 kaweth->firmware_buf[2]);
409
410 kaweth_dbg("Downloading firmware at %p to kaweth device at %p",
411 data,
412 kaweth);
413 kaweth_dbg("Firmware length: %d", data_len);
414
415 return kaweth_control(kaweth,
416 usb_sndctrlpipe(kaweth->dev, 0),
417 KAWETH_COMMAND_SCAN,
418 USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
419 0,
420 0,
421 (void *)kaweth->firmware_buf,
422 data_len,
423 KAWETH_CONTROL_TIMEOUT);
424}
425
426/****************************************************************
427 * kaweth_trigger_firmware
428 ****************************************************************/
429static int kaweth_trigger_firmware(struct kaweth_device *kaweth,
430 __u8 interrupt)
431{
432 kaweth->firmware_buf[0] = 0xB6;
433 kaweth->firmware_buf[1] = 0xC3;
434 kaweth->firmware_buf[2] = 0x01;
435 kaweth->firmware_buf[3] = 0x00;
436 kaweth->firmware_buf[4] = 0x06;
437 kaweth->firmware_buf[5] = interrupt;
438 kaweth->firmware_buf[6] = 0x00;
439 kaweth->firmware_buf[7] = 0x00;
440
441 kaweth_dbg("Triggering firmware");
442
443 return kaweth_control(kaweth,
444 usb_sndctrlpipe(kaweth->dev, 0),
445 KAWETH_COMMAND_SCAN,
446 USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
447 0,
448 0,
449 (void *)kaweth->firmware_buf,
450 8,
451 KAWETH_CONTROL_TIMEOUT);
452}
453
454/****************************************************************
455 * kaweth_reset
456 ****************************************************************/
457static int kaweth_reset(struct kaweth_device *kaweth)
458{
459 int result;
460
461 kaweth_dbg("kaweth_reset(%p)", kaweth);
462 result = kaweth_control(kaweth,
463 usb_sndctrlpipe(kaweth->dev, 0),
464 USB_REQ_SET_CONFIGURATION,
465 0,
466 kaweth->dev->config[0].desc.bConfigurationValue,
467 0,
468 NULL,
469 0,
470 KAWETH_CONTROL_TIMEOUT);
471
472 udelay(10000);
473
474 kaweth_dbg("kaweth_reset() returns %d.",result);
475
476 return result;
477}
478
479static void kaweth_usb_receive(struct urb *, struct pt_regs *regs);
480static int kaweth_resubmit_rx_urb(struct kaweth_device *, int);
481
482/****************************************************************
483 int_callback
484*****************************************************************/
485
486static void kaweth_resubmit_int_urb(struct kaweth_device *kaweth, int mf)
487{
488 int status;
489
490 status = usb_submit_urb (kaweth->irq_urb, mf);
491 if (unlikely(status == -ENOMEM)) {
492 kaweth->suspend_lowmem_ctrl = 1;
493 schedule_delayed_work(&kaweth->lowmem_work, HZ/4);
494 } else {
495 kaweth->suspend_lowmem_ctrl = 0;
496 }
497
498 if (status)
499 err ("can't resubmit intr, %s-%s, status %d",
500 kaweth->dev->bus->bus_name,
501 kaweth->dev->devpath, status);
502}
503
504static void int_callback(struct urb *u, struct pt_regs *regs)
505{
506 struct kaweth_device *kaweth = u->context;
507 int act_state;
508
509 switch (u->status) {
510 case 0: /* success */
511 break;
512 case -ECONNRESET: /* unlink */
513 case -ENOENT:
514 case -ESHUTDOWN:
515 return;
516 /* -EPIPE: should clear the halt */
517 default: /* error */
518 goto resubmit;
519 }
520
521 /* we check the link state to report changes */
522 if (kaweth->linkstate != (act_state = ( kaweth->intbuffer[STATE_OFFSET] | STATE_MASK) >> STATE_SHIFT)) {
523 if (!act_state)
524 netif_carrier_on(kaweth->net);
525 else
526 netif_carrier_off(kaweth->net);
527
528 kaweth->linkstate = act_state;
529 }
530resubmit:
531 kaweth_resubmit_int_urb(kaweth, GFP_ATOMIC);
532}
533
534static void kaweth_resubmit_tl(void *d)
535{
536 struct kaweth_device *kaweth = (struct kaweth_device *)d;
537
538 if (kaweth->status | KAWETH_STATUS_CLOSING)
539 return;
540
541 if (kaweth->suspend_lowmem_rx)
542 kaweth_resubmit_rx_urb(kaweth, GFP_NOIO);
543
544 if (kaweth->suspend_lowmem_ctrl)
545 kaweth_resubmit_int_urb(kaweth, GFP_NOIO);
546}
547
548
549/****************************************************************
550 * kaweth_resubmit_rx_urb
551 ****************************************************************/
552static int kaweth_resubmit_rx_urb(struct kaweth_device *kaweth,
553 int mem_flags)
554{
555 int result;
556
557 usb_fill_bulk_urb(kaweth->rx_urb,
558 kaweth->dev,
559 usb_rcvbulkpipe(kaweth->dev, 1),
560 kaweth->rx_buf,
561 KAWETH_BUF_SIZE,
562 kaweth_usb_receive,
563 kaweth);
564 kaweth->rx_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
565 kaweth->rx_urb->transfer_dma = kaweth->rxbufferhandle;
566
567 if((result = usb_submit_urb(kaweth->rx_urb, mem_flags))) {
568 if (result == -ENOMEM) {
569 kaweth->suspend_lowmem_rx = 1;
570 schedule_delayed_work(&kaweth->lowmem_work, HZ/4);
571 }
572 kaweth_err("resubmitting rx_urb %d failed", result);
573 } else {
574 kaweth->suspend_lowmem_rx = 0;
575 }
576
577 return result;
578}
579
580static void kaweth_async_set_rx_mode(struct kaweth_device *kaweth);
581
582/****************************************************************
583 * kaweth_usb_receive
584 ****************************************************************/
585static void kaweth_usb_receive(struct urb *urb, struct pt_regs *regs)
586{
587 struct kaweth_device *kaweth = urb->context;
588 struct net_device *net = kaweth->net;
589
590 int count = urb->actual_length;
591 int count2 = urb->transfer_buffer_length;
592
593 __u16 pkt_len = le16_to_cpup((__le16 *)kaweth->rx_buf);
594
595 struct sk_buff *skb;
596
597 if(unlikely(urb->status == -ECONNRESET || urb->status == -ESHUTDOWN))
598 /* we are killed - set a flag and wake the disconnect handler */
599 {
600 kaweth->end = 1;
601 wake_up(&kaweth->term_wait);
602 return;
603 }
604
605 if (kaweth->status & KAWETH_STATUS_CLOSING)
606 return;
607
608 if(urb->status && urb->status != -EREMOTEIO && count != 1) {
609 kaweth_err("%s RX status: %d count: %d packet_len: %d",
610 net->name,
611 urb->status,
612 count,
613 (int)pkt_len);
614 kaweth_resubmit_rx_urb(kaweth, GFP_ATOMIC);
615 return;
616 }
617
618 if(kaweth->net && (count > 2)) {
619 if(pkt_len > (count - 2)) {
620 kaweth_err("Packet length too long for USB frame (pkt_len: %x, count: %x)",pkt_len, count);
621 kaweth_err("Packet len & 2047: %x", pkt_len & 2047);
622 kaweth_err("Count 2: %x", count2);
623 kaweth_resubmit_rx_urb(kaweth, GFP_ATOMIC);
624 return;
625 }
626
627 if(!(skb = dev_alloc_skb(pkt_len+2))) {
628 kaweth_resubmit_rx_urb(kaweth, GFP_ATOMIC);
629 return;
630 }
631
632 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
633
634 skb->dev = net;
635
636 eth_copy_and_sum(skb, kaweth->rx_buf + 2, pkt_len, 0);
637
638 skb_put(skb, pkt_len);
639
640 skb->protocol = eth_type_trans(skb, net);
641
642 netif_rx(skb);
643
644 kaweth->stats.rx_packets++;
645 kaweth->stats.rx_bytes += pkt_len;
646 }
647
648 kaweth_resubmit_rx_urb(kaweth, GFP_ATOMIC);
649}
650
651/****************************************************************
652 * kaweth_open
653 ****************************************************************/
654static int kaweth_open(struct net_device *net)
655{
656 struct kaweth_device *kaweth = netdev_priv(net);
657 int res;
658
659 kaweth_dbg("Opening network device.");
660
661 res = kaweth_resubmit_rx_urb(kaweth, GFP_KERNEL);
662 if (res)
663 return -EIO;
664
665 usb_fill_int_urb(
666 kaweth->irq_urb,
667 kaweth->dev,
668 usb_rcvintpipe(kaweth->dev, 3),
669 kaweth->intbuffer,
670 INTBUFFERSIZE,
671 int_callback,
672 kaweth,
673 250); /* overriding the descriptor */
674 kaweth->irq_urb->transfer_dma = kaweth->intbufferhandle;
675 kaweth->irq_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
676
677 res = usb_submit_urb(kaweth->irq_urb, GFP_KERNEL);
678 if (res) {
679 usb_kill_urb(kaweth->rx_urb);
680 return -EIO;
681 }
682
683 netif_start_queue(net);
684
685 kaweth_async_set_rx_mode(kaweth);
686 return 0;
687}
688
689/****************************************************************
690 * kaweth_close
691 ****************************************************************/
692static int kaweth_close(struct net_device *net)
693{
694 struct kaweth_device *kaweth = netdev_priv(net);
695
696 netif_stop_queue(net);
697
698 kaweth->status |= KAWETH_STATUS_CLOSING;
699
700 usb_kill_urb(kaweth->irq_urb);
701 usb_kill_urb(kaweth->rx_urb);
702
703 flush_scheduled_work();
704
705 /* a scheduled work may have resubmitted,
706 we hit them again */
707 usb_kill_urb(kaweth->irq_urb);
708 usb_kill_urb(kaweth->rx_urb);
709
710 kaweth->status &= ~KAWETH_STATUS_CLOSING;
711
712 return 0;
713}
714
715static void kaweth_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
716{
717
718 strlcpy(info->driver, driver_name, sizeof(info->driver));
719}
720
721static struct ethtool_ops ops = {
722 .get_drvinfo = kaweth_get_drvinfo
723};
724
725/****************************************************************
726 * kaweth_usb_transmit_complete
727 ****************************************************************/
728static void kaweth_usb_transmit_complete(struct urb *urb, struct pt_regs *regs)
729{
730 struct kaweth_device *kaweth = urb->context;
731 struct sk_buff *skb = kaweth->tx_skb;
732
733 if (unlikely(urb->status != 0))
734 if (urb->status != -ENOENT)
735 kaweth_dbg("%s: TX status %d.", kaweth->net->name, urb->status);
736
737 netif_wake_queue(kaweth->net);
738 dev_kfree_skb_irq(skb);
739}
740
741/****************************************************************
742 * kaweth_start_xmit
743 ****************************************************************/
744static int kaweth_start_xmit(struct sk_buff *skb, struct net_device *net)
745{
746 struct kaweth_device *kaweth = netdev_priv(net);
747 __le16 *private_header;
748
749 int res;
750
751 spin_lock(&kaweth->device_lock);
752
753 if (kaweth->removed) {
754 /* our device is undergoing disconnection - we bail out */
755 spin_unlock(&kaweth->device_lock);
756 dev_kfree_skb_irq(skb);
757 return 0;
758 }
759
760 kaweth_async_set_rx_mode(kaweth);
761 netif_stop_queue(net);
762
763 /* We now decide whether we can put our special header into the sk_buff */
764 if (skb_cloned(skb) || skb_headroom(skb) < 2) {
765 /* no such luck - we make our own */
766 struct sk_buff *copied_skb;
767 copied_skb = skb_copy_expand(skb, 2, 0, GFP_ATOMIC);
768 dev_kfree_skb_irq(skb);
769 skb = copied_skb;
770 if (!copied_skb) {
771 kaweth->stats.tx_errors++;
772 netif_start_queue(net);
773 spin_unlock(&kaweth->device_lock);
774 return 0;
775 }
776 }
777
778 private_header = (__le16 *)__skb_push(skb, 2);
779 *private_header = cpu_to_le16(skb->len-2);
780 kaweth->tx_skb = skb;
781
782 usb_fill_bulk_urb(kaweth->tx_urb,
783 kaweth->dev,
784 usb_sndbulkpipe(kaweth->dev, 2),
785 private_header,
786 skb->len,
787 kaweth_usb_transmit_complete,
788 kaweth);
789 kaweth->end = 0;
790 kaweth->tx_urb->transfer_flags |= URB_ASYNC_UNLINK;
791
792 if((res = usb_submit_urb(kaweth->tx_urb, GFP_ATOMIC)))
793 {
794 kaweth_warn("kaweth failed tx_urb %d", res);
795 kaweth->stats.tx_errors++;
796
797 netif_start_queue(net);
798 dev_kfree_skb_irq(skb);
799 }
800 else
801 {
802 kaweth->stats.tx_packets++;
803 kaweth->stats.tx_bytes += skb->len;
804 net->trans_start = jiffies;
805 }
806
807 spin_unlock(&kaweth->device_lock);
808
809 return 0;
810}
811
812/****************************************************************
813 * kaweth_set_rx_mode
814 ****************************************************************/
815static void kaweth_set_rx_mode(struct net_device *net)
816{
817 struct kaweth_device *kaweth = netdev_priv(net);
818
819 __u16 packet_filter_bitmap = KAWETH_PACKET_FILTER_DIRECTED |
820 KAWETH_PACKET_FILTER_BROADCAST |
821 KAWETH_PACKET_FILTER_MULTICAST;
822
823 kaweth_dbg("Setting Rx mode to %d", packet_filter_bitmap);
824
825 netif_stop_queue(net);
826
827 if (net->flags & IFF_PROMISC) {
828 packet_filter_bitmap |= KAWETH_PACKET_FILTER_PROMISCUOUS;
829 }
830 else if ((net->mc_count) || (net->flags & IFF_ALLMULTI)) {
831 packet_filter_bitmap |= KAWETH_PACKET_FILTER_ALL_MULTICAST;
832 }
833
834 kaweth->packet_filter_bitmap = packet_filter_bitmap;
835 netif_wake_queue(net);
836}
837
838/****************************************************************
839 * kaweth_async_set_rx_mode
840 ****************************************************************/
841static void kaweth_async_set_rx_mode(struct kaweth_device *kaweth)
842{
843 __u16 packet_filter_bitmap = kaweth->packet_filter_bitmap;
844 kaweth->packet_filter_bitmap = 0;
845 if (packet_filter_bitmap == 0)
846 return;
847
848 {
849 int result;
850 result = kaweth_control(kaweth,
851 usb_sndctrlpipe(kaweth->dev, 0),
852 KAWETH_COMMAND_SET_PACKET_FILTER,
853 USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
854 packet_filter_bitmap,
855 0,
856 (void *)&kaweth->scratch,
857 0,
858 KAWETH_CONTROL_TIMEOUT);
859
860 if(result < 0) {
861 kaweth_err("Failed to set Rx mode: %d", result);
862 }
863 else {
864 kaweth_dbg("Set Rx mode to %d", packet_filter_bitmap);
865 }
866 }
867}
868
869/****************************************************************
870 * kaweth_netdev_stats
871 ****************************************************************/
872static struct net_device_stats *kaweth_netdev_stats(struct net_device *dev)
873{
874 struct kaweth_device *kaweth = netdev_priv(dev);
875 return &kaweth->stats;
876}
877
878/****************************************************************
879 * kaweth_tx_timeout
880 ****************************************************************/
881static void kaweth_tx_timeout(struct net_device *net)
882{
883 struct kaweth_device *kaweth = netdev_priv(net);
884
885 kaweth_warn("%s: Tx timed out. Resetting.", net->name);
886 kaweth->stats.tx_errors++;
887 net->trans_start = jiffies;
888
889 usb_unlink_urb(kaweth->tx_urb);
890}
891
892/****************************************************************
893 * kaweth_probe
894 ****************************************************************/
895static int kaweth_probe(
896 struct usb_interface *intf,
897 const struct usb_device_id *id /* from id_table */
898 )
899{
900 struct usb_device *dev = interface_to_usbdev(intf);
901 struct kaweth_device *kaweth;
902 struct net_device *netdev;
903 const eth_addr_t bcast_addr = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
904 int result = 0;
905
906 kaweth_dbg("Kawasaki Device Probe (Device number:%d): 0x%4.4x:0x%4.4x:0x%4.4x",
907 dev->devnum,
908 le16_to_cpu(dev->descriptor.idVendor),
909 le16_to_cpu(dev->descriptor.idProduct),
910 le16_to_cpu(dev->descriptor.bcdDevice));
911
912 kaweth_dbg("Device at %p", dev);
913
914 kaweth_dbg("Descriptor length: %x type: %x",
915 (int)dev->descriptor.bLength,
916 (int)dev->descriptor.bDescriptorType);
917
918 netdev = alloc_etherdev(sizeof(*kaweth));
919 if (!netdev)
920 return -ENOMEM;
921
922 kaweth = netdev_priv(netdev);
923 kaweth->dev = dev;
924 kaweth->net = netdev;
925
926 spin_lock_init(&kaweth->device_lock);
927 init_waitqueue_head(&kaweth->term_wait);
928
929 kaweth_dbg("Resetting.");
930
931 kaweth_reset(kaweth);
932
933 /*
934 * If high byte of bcdDevice is nonzero, firmware is already
935 * downloaded. Don't try to do it again, or we'll hang the device.
936 */
937
938 if (le16_to_cpu(dev->descriptor.bcdDevice) >> 8) {
939 kaweth_info("Firmware present in device.");
940 } else {
941 /* Download the firmware */
942 kaweth_info("Downloading firmware...");
943 kaweth->firmware_buf = (__u8 *)__get_free_page(GFP_KERNEL);
944 if ((result = kaweth_download_firmware(kaweth,
945 kaweth_new_code,
946 len_kaweth_new_code,
947 100,
948 2)) < 0) {
949 kaweth_err("Error downloading firmware (%d)", result);
950 goto err_fw;
951 }
952
953 if ((result = kaweth_download_firmware(kaweth,
954 kaweth_new_code_fix,
955 len_kaweth_new_code_fix,
956 100,
957 3)) < 0) {
958 kaweth_err("Error downloading firmware fix (%d)", result);
959 goto err_fw;
960 }
961
962 if ((result = kaweth_download_firmware(kaweth,
963 kaweth_trigger_code,
964 len_kaweth_trigger_code,
965 126,
966 2)) < 0) {
967 kaweth_err("Error downloading trigger code (%d)", result);
968 goto err_fw;
969
970 }
971
972 if ((result = kaweth_download_firmware(kaweth,
973 kaweth_trigger_code_fix,
974 len_kaweth_trigger_code_fix,
975 126,
976 3)) < 0) {
977 kaweth_err("Error downloading trigger code fix (%d)", result);
978 goto err_fw;
979 }
980
981
982 if ((result = kaweth_trigger_firmware(kaweth, 126)) < 0) {
983 kaweth_err("Error triggering firmware (%d)", result);
984 goto err_fw;
985 }
986
987 /* Device will now disappear for a moment... */
988 kaweth_info("Firmware loaded. I'll be back...");
989err_fw:
990 free_page((unsigned long)kaweth->firmware_buf);
991 free_netdev(netdev);
992 return -EIO;
993 }
994
995 result = kaweth_read_configuration(kaweth);
996
997 if(result < 0) {
998 kaweth_err("Error reading configuration (%d), no net device created", result);
999 goto err_free_netdev;
1000 }
1001
1002 kaweth_info("Statistics collection: %x", kaweth->configuration.statistics_mask);
1003 kaweth_info("Multicast filter limit: %x", kaweth->configuration.max_multicast_filters & ((1 << 15) - 1));
1004 kaweth_info("MTU: %d", le16_to_cpu(kaweth->configuration.segment_size));
1005 kaweth_info("Read MAC address %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x",
1006 (int)kaweth->configuration.hw_addr[0],
1007 (int)kaweth->configuration.hw_addr[1],
1008 (int)kaweth->configuration.hw_addr[2],
1009 (int)kaweth->configuration.hw_addr[3],
1010 (int)kaweth->configuration.hw_addr[4],
1011 (int)kaweth->configuration.hw_addr[5]);
1012
1013 if(!memcmp(&kaweth->configuration.hw_addr,
1014 &bcast_addr,
1015 sizeof(bcast_addr))) {
1016 kaweth_err("Firmware not functioning properly, no net device created");
1017 goto err_free_netdev;
1018 }
1019
1020 if(kaweth_set_urb_size(kaweth, KAWETH_BUF_SIZE) < 0) {
1021 kaweth_dbg("Error setting URB size");
1022 goto err_free_netdev;
1023 }
1024
1025 if(kaweth_set_sofs_wait(kaweth, KAWETH_SOFS_TO_WAIT) < 0) {
1026 kaweth_err("Error setting SOFS wait");
1027 goto err_free_netdev;
1028 }
1029
1030 result = kaweth_set_receive_filter(kaweth,
1031 KAWETH_PACKET_FILTER_DIRECTED |
1032 KAWETH_PACKET_FILTER_BROADCAST |
1033 KAWETH_PACKET_FILTER_MULTICAST);
1034
1035 if(result < 0) {
1036 kaweth_err("Error setting receive filter");
1037 goto err_free_netdev;
1038 }
1039
1040 kaweth_dbg("Initializing net device.");
1041
1042 kaweth->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
1043 if (!kaweth->tx_urb)
1044 goto err_free_netdev;
1045 kaweth->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
1046 if (!kaweth->rx_urb)
1047 goto err_only_tx;
1048 kaweth->irq_urb = usb_alloc_urb(0, GFP_KERNEL);
1049 if (!kaweth->irq_urb)
1050 goto err_tx_and_rx;
1051
1052 kaweth->intbuffer = usb_buffer_alloc( kaweth->dev,
1053 INTBUFFERSIZE,
1054 GFP_KERNEL,
1055 &kaweth->intbufferhandle);
1056 if (!kaweth->intbuffer)
1057 goto err_tx_and_rx_and_irq;
1058 kaweth->rx_buf = usb_buffer_alloc( kaweth->dev,
1059 KAWETH_BUF_SIZE,
1060 GFP_KERNEL,
1061 &kaweth->rxbufferhandle);
1062 if (!kaweth->rx_buf)
1063 goto err_all_but_rxbuf;
1064
1065 memcpy(netdev->broadcast, &bcast_addr, sizeof(bcast_addr));
1066 memcpy(netdev->dev_addr, &kaweth->configuration.hw_addr,
1067 sizeof(kaweth->configuration.hw_addr));
1068
1069 netdev->open = kaweth_open;
1070 netdev->stop = kaweth_close;
1071
1072 netdev->watchdog_timeo = KAWETH_TX_TIMEOUT;
1073 netdev->tx_timeout = kaweth_tx_timeout;
1074
1075 netdev->hard_start_xmit = kaweth_start_xmit;
1076 netdev->set_multicast_list = kaweth_set_rx_mode;
1077 netdev->get_stats = kaweth_netdev_stats;
1078 netdev->mtu = le16_to_cpu(kaweth->configuration.segment_size);
1079 SET_ETHTOOL_OPS(netdev, &ops);
1080
1081 /* kaweth is zeroed as part of alloc_netdev */
1082
1083 INIT_WORK(&kaweth->lowmem_work, kaweth_resubmit_tl, (void *)kaweth);
1084
1085 SET_MODULE_OWNER(netdev);
1086
1087 usb_set_intfdata(intf, kaweth);
1088
1089#if 0
1090// dma_supported() is deeply broken on almost all architectures
1091 if (dma_supported (&intf->dev, 0xffffffffffffffffULL))
1092 kaweth->net->features |= NETIF_F_HIGHDMA;
1093#endif
1094
1095 SET_NETDEV_DEV(netdev, &intf->dev);
1096 if (register_netdev(netdev) != 0) {
1097 kaweth_err("Error registering netdev.");
1098 goto err_intfdata;
1099 }
1100
1101 kaweth_info("kaweth interface created at %s", kaweth->net->name);
1102
1103 kaweth_dbg("Kaweth probe returning.");
1104
1105 return 0;
1106
1107err_intfdata:
1108 usb_set_intfdata(intf, NULL);
1109 usb_buffer_free(kaweth->dev, KAWETH_BUF_SIZE, (void *)kaweth->rx_buf, kaweth->rxbufferhandle);
1110err_all_but_rxbuf:
1111 usb_buffer_free(kaweth->dev, INTBUFFERSIZE, (void *)kaweth->intbuffer, kaweth->intbufferhandle);
1112err_tx_and_rx_and_irq:
1113 usb_free_urb(kaweth->irq_urb);
1114err_tx_and_rx:
1115 usb_free_urb(kaweth->rx_urb);
1116err_only_tx:
1117 usb_free_urb(kaweth->tx_urb);
1118err_free_netdev:
1119 free_netdev(netdev);
1120
1121 return -EIO;
1122}
1123
1124/****************************************************************
1125 * kaweth_disconnect
1126 ****************************************************************/
1127static void kaweth_disconnect(struct usb_interface *intf)
1128{
1129 struct kaweth_device *kaweth = usb_get_intfdata(intf);
1130 struct net_device *netdev;
1131
1132 kaweth_info("Unregistering");
1133
1134 usb_set_intfdata(intf, NULL);
1135 if (!kaweth) {
1136 kaweth_warn("unregistering non-existant device");
1137 return;
1138 }
1139 netdev = kaweth->net;
1140 kaweth->removed = 1;
1141 usb_kill_urb(kaweth->irq_urb);
1142 usb_kill_urb(kaweth->rx_urb);
1143 usb_kill_urb(kaweth->tx_urb);
1144
1145 kaweth_dbg("Unregistering net device");
1146 unregister_netdev(netdev);
1147
1148 usb_free_urb(kaweth->rx_urb);
1149 usb_free_urb(kaweth->tx_urb);
1150 usb_free_urb(kaweth->irq_urb);
1151
1152 usb_buffer_free(kaweth->dev, KAWETH_BUF_SIZE, (void *)kaweth->rx_buf, kaweth->rxbufferhandle);
1153 usb_buffer_free(kaweth->dev, INTBUFFERSIZE, (void *)kaweth->intbuffer, kaweth->intbufferhandle);
1154
1155 free_netdev(netdev);
1156}
1157
1158
1159// FIXME this completion stuff is a modified clone of
1160// an OLD version of some stuff in usb.c ...
1161struct usb_api_data {
1162 wait_queue_head_t wqh;
1163 int done;
1164};
1165
1166/*-------------------------------------------------------------------*
1167 * completion handler for compatibility wrappers (sync control/bulk) *
1168 *-------------------------------------------------------------------*/
1169static void usb_api_blocking_completion(struct urb *urb, struct pt_regs *regs)
1170{
1171 struct usb_api_data *awd = (struct usb_api_data *)urb->context;
1172
1173 awd->done=1;
1174 wake_up(&awd->wqh);
1175}
1176
1177/*-------------------------------------------------------------------*
1178 * COMPATIBILITY STUFF *
1179 *-------------------------------------------------------------------*/
1180
1181// Starts urb and waits for completion or timeout
1182static int usb_start_wait_urb(struct urb *urb, int timeout, int* actual_length)
1183{
1184 struct usb_api_data awd;
1185 int status;
1186
1187 init_waitqueue_head(&awd.wqh);
1188 awd.done = 0;
1189
1190 urb->context = &awd;
1191 status = usb_submit_urb(urb, GFP_NOIO);
1192 if (status) {
1193 // something went wrong
1194 usb_free_urb(urb);
1195 return status;
1196 }
1197
1198 if (!wait_event_timeout(awd.wqh, awd.done, timeout)) {
1199 // timeout
1200 kaweth_warn("usb_control/bulk_msg: timeout");
1201 usb_kill_urb(urb); // remove urb safely
1202 status = -ETIMEDOUT;
1203 }
1204 else {
1205 status = urb->status;
1206 }
1207
1208 if (actual_length) {
1209 *actual_length = urb->actual_length;
1210 }
1211
1212 usb_free_urb(urb);
1213 return status;
1214}
1215
1216/*-------------------------------------------------------------------*/
1217// returns status (negative) or length (positive)
1218static int kaweth_internal_control_msg(struct usb_device *usb_dev,
1219 unsigned int pipe,
1220 struct usb_ctrlrequest *cmd, void *data,
1221 int len, int timeout)
1222{
1223 struct urb *urb;
1224 int retv;
1225 int length;
1226
1227 urb = usb_alloc_urb(0, GFP_NOIO);
1228 if (!urb)
1229 return -ENOMEM;
1230
1231 usb_fill_control_urb(urb, usb_dev, pipe, (unsigned char*)cmd, data,
1232 len, usb_api_blocking_completion, NULL);
1233
1234 retv = usb_start_wait_urb(urb, timeout, &length);
1235 if (retv < 0) {
1236 return retv;
1237 }
1238 else {
1239 return length;
1240 }
1241}
1242
1243
1244/****************************************************************
1245 * kaweth_init
1246 ****************************************************************/
1247static int __init kaweth_init(void)
1248{
1249 kaweth_dbg("Driver loading");
1250 return usb_register(&kaweth_driver);
1251}
1252
1253/****************************************************************
1254 * kaweth_exit
1255 ****************************************************************/
1256static void __exit kaweth_exit(void)
1257{
1258 usb_deregister(&kaweth_driver);
1259}
1260
1261module_init(kaweth_init);
1262module_exit(kaweth_exit);
1263
1264
1265
1266
1267
1268
1269
1270
1271
diff --git a/drivers/usb/net/kawethfw.h b/drivers/usb/net/kawethfw.h
new file mode 100644
index 000000000000..cf85fcb0d1a6
--- /dev/null
+++ b/drivers/usb/net/kawethfw.h
@@ -0,0 +1,557 @@
1/******************************************/
2/* NOTE: B6/C3 is data header signature */
3/* 0xAA/0xBB is data length = total */
4/* bytes - 7, 0xCC is type, 0xDD is */
5/* interrupt to use. */
6/******************************************/
7
8/****************************************************************
9 * kaweth_trigger_code
10 ****************************************************************/
11static __u8 kaweth_trigger_code[] =
12{
13 0xB6, 0xC3, 0xAA, 0xBB, 0xCC, 0xDD,
14 0xc8, 0x07, 0xa0, 0x00, 0xf0, 0x07, 0x5e, 0x00,
15 0x06, 0x00, 0xf0, 0x07, 0x0a, 0x00, 0x08, 0x00,
16 0xf0, 0x09, 0x00, 0x00, 0x02, 0x00, 0xe7, 0x07,
17 0x36, 0x00, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x00,
18 0x04, 0x00, 0xe7, 0x07, 0x50, 0xc3, 0x10, 0xc0,
19 0xf0, 0x09, 0x0e, 0xc0, 0x00, 0x00, 0xe7, 0x87,
20 0x01, 0x00, 0x0e, 0xc0, 0x97, 0xcf, 0xd7, 0x09,
21 0x00, 0xc0, 0x17, 0x02, 0xc8, 0x07, 0xa0, 0x00,
22 0xe7, 0x17, 0x50, 0xc3, 0x10, 0xc0, 0x30, 0xd8,
23 0x04, 0x00, 0x30, 0x5c, 0x08, 0x00, 0x04, 0x00,
24 0xb0, 0xc0, 0x06, 0x00, 0xc8, 0x05, 0xe7, 0x05,
25 0x00, 0xc0, 0xc0, 0xdf, 0x97, 0xcf, 0x49, 0xaf,
26 0xc0, 0x07, 0x00, 0x00, 0x60, 0xaf, 0x4a, 0xaf,
27 0x00, 0x0c, 0x0c, 0x00, 0x40, 0xd2, 0x00, 0x1c,
28 0x0c, 0x00, 0x40, 0xd2, 0x30, 0x00, 0x08, 0x00,
29 0xf0, 0x07, 0x00, 0x00, 0x04, 0x00, 0xf0, 0x07,
30 0x86, 0x00, 0x06, 0x00, 0x67, 0xcf, 0x27, 0x0c,
31 0x02, 0x00, 0x00, 0x00, 0x27, 0x0c, 0x00, 0x00,
32 0x0e, 0xc0, 0x49, 0xaf, 0x64, 0xaf, 0xc0, 0x07,
33 0x00, 0x00, 0x4b, 0xaf, 0x4a, 0xaf, 0x5a, 0xcf,
34 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
35 0x00, 0x00, 0x94, 0x00, 0x05, 0x00,
36 0x00, 0x00
37};
38/****************************************************************
39 * kaweth_trigger_code_fix
40 ****************************************************************/
41static __u8 kaweth_trigger_code_fix[] =
42{
43 0xB6, 0xC3, 0xAA, 0xBB, 0xCC, 0xDD,
44 0x02, 0x00, 0x06, 0x00, 0x18, 0x00, 0x3e, 0x00,
45 0x80, 0x00, 0x98, 0x00, 0xaa, 0x00,
46 0x00, 0x00
47};
48
49/****************************************************************
50 * kaweth_new_code
51 ****************************************************************/
52static __u8 kaweth_new_code[] =
53{
54 0xB6, 0xC3, 0xAA, 0xBB, 0xCC, 0xDD,
55 0x9f, 0xcf, 0xde, 0x06, 0xe7, 0x57, 0x00, 0x00,
56 0xc4, 0x06, 0x97, 0xc1, 0xe7, 0x67, 0xff, 0x1f,
57 0x28, 0xc0, 0xe7, 0x87, 0x00, 0x04, 0x24, 0xc0,
58 0xe7, 0x67, 0xff, 0xf9, 0x22, 0xc0, 0x97, 0xcf,
59 0xd7, 0x09, 0x00, 0xc0, 0xe7, 0x09, 0xa2, 0xc0,
60 0xbe, 0x06, 0x9f, 0xaf, 0x36, 0x00, 0xe7, 0x05,
61 0x00, 0xc0, 0xa7, 0xcf, 0xbc, 0x06, 0x97, 0xcf,
62 0xe7, 0x57, 0x00, 0x00, 0xb8, 0x06, 0xa7, 0xa1,
63 0xb8, 0x06, 0x97, 0xcf, 0xe7, 0x57, 0x00, 0x00,
64 0x14, 0x08, 0x0a, 0xc0, 0xe7, 0x57, 0x00, 0x00,
65 0xa4, 0xc0, 0xa7, 0xc0, 0x7a, 0x06, 0x9f, 0xaf,
66 0x92, 0x07, 0xe7, 0x07, 0x00, 0x00, 0x14, 0x08,
67 0xe7, 0x57, 0xff, 0xff, 0xba, 0x06, 0x9f, 0xa0,
68 0x38, 0x00, 0xe7, 0x59, 0xba, 0x06, 0xbe, 0x06,
69 0x9f, 0xa0, 0x38, 0x00, 0xc8, 0x09, 0xca, 0x06,
70 0x08, 0x62, 0x9f, 0xa1, 0x36, 0x08, 0xc0, 0x09,
71 0x76, 0x06, 0x00, 0x60, 0xa7, 0xc0, 0x7a, 0x06,
72 0x9f, 0xaf, 0xcc, 0x02, 0xe7, 0x57, 0x00, 0x00,
73 0xb8, 0x06, 0xa7, 0xc1, 0x7a, 0x06, 0x9f, 0xaf,
74 0x04, 0x00, 0xe7, 0x57, 0x00, 0x00, 0x8e, 0x06,
75 0x0a, 0xc1, 0xe7, 0x09, 0x20, 0xc0, 0x10, 0x08,
76 0xe7, 0xd0, 0x10, 0x08, 0xe7, 0x67, 0x40, 0x00,
77 0x10, 0x08, 0x9f, 0xaf, 0x92, 0x0c, 0xc0, 0x09,
78 0xd0, 0x06, 0x00, 0x60, 0x05, 0xc4, 0xc0, 0x59,
79 0xbe, 0x06, 0x02, 0xc0, 0x9f, 0xaf, 0xec, 0x00,
80 0x9f, 0xaf, 0x34, 0x02, 0xe7, 0x57, 0x00, 0x00,
81 0xa6, 0x06, 0x9f, 0xa0, 0x7a, 0x02, 0xa7, 0xcf,
82 0x7a, 0x06, 0x48, 0x02, 0xe7, 0x09, 0xbe, 0x06,
83 0xd0, 0x06, 0xc8, 0x37, 0x04, 0x00, 0x9f, 0xaf,
84 0x08, 0x03, 0x97, 0xcf, 0xe7, 0x57, 0x00, 0x00,
85 0xce, 0x06, 0x97, 0xc0, 0xd7, 0x09, 0x00, 0xc0,
86 0xc1, 0xdf, 0xc8, 0x09, 0xc6, 0x06, 0x08, 0x62,
87 0x14, 0xc0, 0x27, 0x04, 0xc6, 0x06, 0x10, 0x94,
88 0xf0, 0x07, 0x10, 0x08, 0x02, 0x00, 0xc1, 0x07,
89 0x01, 0x00, 0x70, 0x00, 0x04, 0x00, 0xf0, 0x07,
90 0x30, 0x01, 0x06, 0x00, 0x50, 0xaf, 0xe7, 0x07,
91 0xff, 0xff, 0xd0, 0x06, 0xe7, 0x07, 0x00, 0x00,
92 0xce, 0x06, 0xe7, 0x05, 0x00, 0xc0, 0x97, 0xcf,
93 0xd7, 0x09, 0x00, 0xc0, 0xc1, 0xdf, 0x48, 0x02,
94 0xd0, 0x09, 0xc6, 0x06, 0x27, 0x02, 0xc6, 0x06,
95 0xe7, 0x05, 0x00, 0xc0, 0x97, 0xcf, 0x48, 0x02,
96 0xc8, 0x37, 0x04, 0x00, 0x00, 0x0c, 0x0c, 0x00,
97 0x00, 0x60, 0x21, 0xc0, 0xc0, 0x37, 0x3e, 0x00,
98 0x23, 0xc9, 0xc0, 0x57, 0xb4, 0x05, 0x1b, 0xc8,
99 0xc0, 0x17, 0x3f, 0x00, 0xc0, 0x67, 0xc0, 0xff,
100 0x30, 0x00, 0x08, 0x00, 0xf0, 0x07, 0x00, 0x00,
101 0x04, 0x00, 0x00, 0x02, 0xc0, 0x17, 0x4c, 0x00,
102 0x30, 0x00, 0x06, 0x00, 0xf0, 0x07, 0xa0, 0x01,
103 0x0a, 0x00, 0x48, 0x02, 0xc1, 0x07, 0x02, 0x00,
104 0xd7, 0x09, 0x00, 0xc0, 0xc1, 0xdf, 0x51, 0xaf,
105 0xe7, 0x05, 0x00, 0xc0, 0x97, 0xcf, 0x9f, 0xaf,
106 0x08, 0x03, 0x9f, 0xaf, 0x7a, 0x02, 0x97, 0xcf,
107 0x9f, 0xaf, 0x7a, 0x02, 0xc9, 0x37, 0x04, 0x00,
108 0xc1, 0xdf, 0xc8, 0x09, 0xa2, 0x06, 0x50, 0x02,
109 0x67, 0x02, 0xa2, 0x06, 0xd1, 0x07, 0x00, 0x00,
110 0x27, 0xd8, 0xaa, 0x06, 0xc0, 0xdf, 0x9f, 0xaf,
111 0xc4, 0x01, 0x97, 0xcf, 0xe7, 0x57, 0x00, 0x00,
112 0xd2, 0x06, 0x97, 0xc1, 0xe7, 0x57, 0x01, 0x00,
113 0xa8, 0x06, 0x97, 0xc0, 0xc8, 0x09, 0xa0, 0x06,
114 0x08, 0x62, 0x97, 0xc0, 0x00, 0x02, 0xc0, 0x17,
115 0x0e, 0x00, 0x27, 0x00, 0x34, 0x01, 0x27, 0x0c,
116 0x0c, 0x00, 0x36, 0x01, 0xe7, 0x07, 0x50, 0xc3,
117 0x12, 0xc0, 0xe7, 0x07, 0xcc, 0x0b, 0x02, 0x00,
118 0xe7, 0x07, 0x01, 0x00, 0xa8, 0x06, 0xe7, 0x07,
119 0x05, 0x00, 0x90, 0xc0, 0x97, 0xcf, 0xc8, 0x09,
120 0xa4, 0x06, 0x08, 0x62, 0x02, 0xc0, 0x10, 0x64,
121 0x07, 0xc1, 0xe7, 0x07, 0x00, 0x00, 0x9e, 0x06,
122 0xe7, 0x07, 0x72, 0x04, 0x24, 0x00, 0x97, 0xcf,
123 0x27, 0x04, 0xa4, 0x06, 0xc8, 0x17, 0x0e, 0x00,
124 0x27, 0x02, 0x9e, 0x06, 0xe7, 0x07, 0x80, 0x04,
125 0x24, 0x00, 0x97, 0xcf, 0xd7, 0x09, 0x00, 0xc0,
126 0xc1, 0xdf, 0xe7, 0x57, 0x00, 0x00, 0x90, 0x06,
127 0x13, 0xc1, 0x9f, 0xaf, 0x06, 0x02, 0xe7, 0x57,
128 0x00, 0x00, 0x9e, 0x06, 0x13, 0xc0, 0xe7, 0x09,
129 0x9e, 0x06, 0x30, 0x01, 0xe7, 0x07, 0xf2, 0x05,
130 0x32, 0x01, 0xe7, 0x07, 0x10, 0x00, 0x96, 0xc0,
131 0xe7, 0x09, 0x9e, 0x06, 0x90, 0x06, 0x04, 0xcf,
132 0xe7, 0x57, 0x00, 0x00, 0x9e, 0x06, 0x02, 0xc1,
133 0x9f, 0xaf, 0x06, 0x02, 0xe7, 0x05, 0x00, 0xc0,
134 0x97, 0xcf, 0xd7, 0x09, 0x00, 0xc0, 0xc1, 0xdf,
135 0x08, 0x92, 0xe7, 0x57, 0x02, 0x00, 0xaa, 0x06,
136 0x02, 0xc3, 0xc8, 0x09, 0xa4, 0x06, 0x27, 0x02,
137 0xa6, 0x06, 0x08, 0x62, 0x03, 0xc1, 0xe7, 0x05,
138 0x00, 0xc0, 0x97, 0xcf, 0x27, 0x04, 0xa4, 0x06,
139 0xe7, 0x05, 0x00, 0xc0, 0xf0, 0x07, 0x40, 0x00,
140 0x08, 0x00, 0xf0, 0x07, 0x00, 0x00, 0x04, 0x00,
141 0x00, 0x02, 0xc0, 0x17, 0x0c, 0x00, 0x30, 0x00,
142 0x06, 0x00, 0xf0, 0x07, 0x46, 0x01, 0x0a, 0x00,
143 0xc8, 0x17, 0x04, 0x00, 0xc1, 0x07, 0x02, 0x00,
144 0x51, 0xaf, 0x97, 0xcf, 0xe7, 0x57, 0x00, 0x00,
145 0x96, 0x06, 0x97, 0xc0, 0xc1, 0xdf, 0xc8, 0x09,
146 0x96, 0x06, 0x27, 0x04, 0x96, 0x06, 0x27, 0x52,
147 0x98, 0x06, 0x03, 0xc1, 0xe7, 0x07, 0x96, 0x06,
148 0x98, 0x06, 0xc0, 0xdf, 0x17, 0x02, 0xc8, 0x17,
149 0x0e, 0x00, 0x9f, 0xaf, 0xba, 0x03, 0xc8, 0x05,
150 0x00, 0x60, 0x03, 0xc0, 0x9f, 0xaf, 0x24, 0x03,
151 0x97, 0xcf, 0x9f, 0xaf, 0x08, 0x03, 0x97, 0xcf,
152 0x57, 0x02, 0xc9, 0x07, 0xa4, 0x06, 0xd7, 0x09,
153 0x00, 0xc0, 0xc1, 0xdf, 0x08, 0x62, 0x1b, 0xc0,
154 0x50, 0x04, 0x11, 0x02, 0xe7, 0x05, 0x00, 0xc0,
155 0xc9, 0x05, 0x97, 0xcf, 0x97, 0x02, 0xca, 0x09,
156 0xd6, 0x06, 0xf2, 0x17, 0x01, 0x00, 0x04, 0x00,
157 0xf2, 0x27, 0x00, 0x00, 0x06, 0x00, 0xca, 0x17,
158 0x2c, 0x00, 0xf8, 0x77, 0x01, 0x00, 0x0e, 0x00,
159 0x06, 0xc0, 0xca, 0xd9, 0xf8, 0x57, 0xff, 0x00,
160 0x0e, 0x00, 0x01, 0xc1, 0xca, 0xd9, 0x22, 0x1c,
161 0x0c, 0x00, 0xe2, 0x27, 0x00, 0x00, 0xe2, 0x17,
162 0x01, 0x00, 0xe2, 0x27, 0x00, 0x00, 0xca, 0x05,
163 0x00, 0x0c, 0x0c, 0x00, 0xc0, 0x17, 0x41, 0x00,
164 0xc0, 0x67, 0xc0, 0xff, 0x30, 0x00, 0x08, 0x00,
165 0x00, 0x02, 0xc0, 0x17, 0x0c, 0x00, 0x30, 0x00,
166 0x06, 0x00, 0xf0, 0x07, 0xda, 0x00, 0x0a, 0x00,
167 0xf0, 0x07, 0x00, 0x00, 0x04, 0x00, 0x00, 0x0c,
168 0x08, 0x00, 0x40, 0xd1, 0x01, 0x00, 0xc0, 0x19,
169 0xce, 0x06, 0xc0, 0x59, 0xc2, 0x06, 0x04, 0xc9,
170 0x49, 0xaf, 0x9f, 0xaf, 0xec, 0x00, 0x4a, 0xaf,
171 0x67, 0x10, 0xce, 0x06, 0xc8, 0x17, 0x04, 0x00,
172 0xc1, 0x07, 0x01, 0x00, 0xd7, 0x09, 0x00, 0xc0,
173 0xc1, 0xdf, 0x50, 0xaf, 0xe7, 0x05, 0x00, 0xc0,
174 0x97, 0xcf, 0xc0, 0x07, 0x01, 0x00, 0xc1, 0x09,
175 0xac, 0x06, 0xc1, 0x77, 0x01, 0x00, 0x97, 0xc1,
176 0xd8, 0x77, 0x01, 0x00, 0x12, 0xc0, 0xc9, 0x07,
177 0x6a, 0x06, 0x9f, 0xaf, 0x08, 0x04, 0x04, 0xc1,
178 0xc1, 0x77, 0x08, 0x00, 0x13, 0xc0, 0x97, 0xcf,
179 0xc1, 0x77, 0x02, 0x00, 0x97, 0xc1, 0xc1, 0x77,
180 0x10, 0x00, 0x0c, 0xc0, 0x9f, 0xaf, 0x2c, 0x04,
181 0x97, 0xcf, 0xc1, 0x77, 0x04, 0x00, 0x06, 0xc0,
182 0xc9, 0x07, 0x70, 0x06, 0x9f, 0xaf, 0x08, 0x04,
183 0x97, 0xc0, 0x00, 0xcf, 0x00, 0x90, 0x97, 0xcf,
184 0x50, 0x54, 0x97, 0xc1, 0x70, 0x5c, 0x02, 0x00,
185 0x02, 0x00, 0x97, 0xc1, 0x70, 0x5c, 0x04, 0x00,
186 0x04, 0x00, 0x97, 0xcf, 0x80, 0x01, 0xc0, 0x00,
187 0x60, 0x00, 0x30, 0x00, 0x18, 0x00, 0x0c, 0x00,
188 0x06, 0x00, 0x00, 0x00, 0xcb, 0x09, 0xb2, 0x06,
189 0xcc, 0x09, 0xb4, 0x06, 0x0b, 0x53, 0x11, 0xc0,
190 0xc9, 0x02, 0xca, 0x07, 0x1c, 0x04, 0x9f, 0xaf,
191 0x08, 0x04, 0x97, 0xc0, 0x0a, 0xc8, 0x82, 0x08,
192 0x0a, 0xcf, 0x82, 0x08, 0x9f, 0xaf, 0x08, 0x04,
193 0x97, 0xc0, 0x05, 0xc2, 0x89, 0x30, 0x82, 0x60,
194 0x78, 0xc1, 0x00, 0x90, 0x97, 0xcf, 0x89, 0x10,
195 0x09, 0x53, 0x79, 0xc2, 0x89, 0x30, 0x82, 0x08,
196 0x7a, 0xcf, 0xc0, 0xdf, 0x97, 0xcf, 0xc0, 0xdf,
197 0x97, 0xcf, 0xe7, 0x09, 0x96, 0xc0, 0x92, 0x06,
198 0xe7, 0x09, 0x98, 0xc0, 0x94, 0x06, 0x0f, 0xcf,
199 0xe7, 0x09, 0x96, 0xc0, 0x92, 0x06, 0xe7, 0x09,
200 0x98, 0xc0, 0x94, 0x06, 0xe7, 0x09, 0x9e, 0x06,
201 0x30, 0x01, 0xe7, 0x07, 0xf2, 0x05, 0x32, 0x01,
202 0xe7, 0x07, 0x10, 0x00, 0x96, 0xc0, 0xd7, 0x09,
203 0x00, 0xc0, 0x17, 0x02, 0xc8, 0x09, 0x90, 0x06,
204 0xc8, 0x37, 0x0e, 0x00, 0xe7, 0x77, 0x2a, 0x00,
205 0x92, 0x06, 0x30, 0xc0, 0x97, 0x02, 0xca, 0x09,
206 0xd6, 0x06, 0xe7, 0x77, 0x20, 0x00, 0x92, 0x06,
207 0x0e, 0xc0, 0xf2, 0x17, 0x01, 0x00, 0x10, 0x00,
208 0xf2, 0x27, 0x00, 0x00, 0x12, 0x00, 0xe7, 0x77,
209 0x0a, 0x00, 0x92, 0x06, 0xca, 0x05, 0x1e, 0xc0,
210 0x97, 0x02, 0xca, 0x09, 0xd6, 0x06, 0xf2, 0x17,
211 0x01, 0x00, 0x0c, 0x00, 0xf2, 0x27, 0x00, 0x00,
212 0x0e, 0x00, 0xe7, 0x77, 0x02, 0x00, 0x92, 0x06,
213 0x07, 0xc0, 0xf2, 0x17, 0x01, 0x00, 0x44, 0x00,
214 0xf2, 0x27, 0x00, 0x00, 0x46, 0x00, 0x06, 0xcf,
215 0xf2, 0x17, 0x01, 0x00, 0x60, 0x00, 0xf2, 0x27,
216 0x00, 0x00, 0x62, 0x00, 0xca, 0x05, 0x9f, 0xaf,
217 0x08, 0x03, 0x0f, 0xcf, 0x57, 0x02, 0x09, 0x02,
218 0xf1, 0x09, 0x94, 0x06, 0x0c, 0x00, 0xf1, 0xda,
219 0x0c, 0x00, 0xc8, 0x09, 0x98, 0x06, 0x50, 0x02,
220 0x67, 0x02, 0x98, 0x06, 0xd1, 0x07, 0x00, 0x00,
221 0xc9, 0x05, 0xe7, 0x09, 0x9e, 0x06, 0x90, 0x06,
222 0xe7, 0x57, 0x00, 0x00, 0x90, 0x06, 0x02, 0xc0,
223 0x9f, 0xaf, 0x06, 0x02, 0xc8, 0x05, 0xe7, 0x05,
224 0x00, 0xc0, 0xc0, 0xdf, 0x97, 0xcf, 0xd7, 0x09,
225 0x00, 0xc0, 0x17, 0x00, 0x17, 0x02, 0x97, 0x02,
226 0xc0, 0x09, 0x92, 0xc0, 0xe7, 0x07, 0x04, 0x00,
227 0x90, 0xc0, 0xca, 0x09, 0xd6, 0x06, 0xe7, 0x07,
228 0x00, 0x00, 0xa8, 0x06, 0xe7, 0x07, 0x6a, 0x04,
229 0x02, 0x00, 0xc0, 0x77, 0x02, 0x00, 0x08, 0xc0,
230 0xf2, 0x17, 0x01, 0x00, 0x50, 0x00, 0xf2, 0x27,
231 0x00, 0x00, 0x52, 0x00, 0x9f, 0xcf, 0x24, 0x06,
232 0xc0, 0x77, 0x10, 0x00, 0x06, 0xc0, 0xf2, 0x17,
233 0x01, 0x00, 0x58, 0x00, 0xf2, 0x27, 0x00, 0x00,
234 0x5a, 0x00, 0xc0, 0x77, 0x80, 0x00, 0x06, 0xc0,
235 0xf2, 0x17, 0x01, 0x00, 0x70, 0x00, 0xf2, 0x27,
236 0x00, 0x00, 0x72, 0x00, 0xc0, 0x77, 0x08, 0x00,
237 0x1d, 0xc1, 0xf2, 0x17, 0x01, 0x00, 0x08, 0x00,
238 0xf2, 0x27, 0x00, 0x00, 0x0a, 0x00, 0xc0, 0x77,
239 0x00, 0x02, 0x06, 0xc0, 0xf2, 0x17, 0x01, 0x00,
240 0x64, 0x00, 0xf2, 0x27, 0x00, 0x00, 0x66, 0x00,
241 0xc0, 0x77, 0x40, 0x00, 0x06, 0xc0, 0xf2, 0x17,
242 0x01, 0x00, 0x5c, 0x00, 0xf2, 0x27, 0x00, 0x00,
243 0x5e, 0x00, 0xc0, 0x77, 0x01, 0x00, 0x01, 0xc0,
244 0x1b, 0xcf, 0x1a, 0xcf, 0xf2, 0x17, 0x01, 0x00,
245 0x00, 0x00, 0xf2, 0x27, 0x00, 0x00, 0x02, 0x00,
246 0xc8, 0x09, 0x34, 0x01, 0xca, 0x17, 0x14, 0x00,
247 0xd8, 0x77, 0x01, 0x00, 0x05, 0xc0, 0xca, 0xd9,
248 0xd8, 0x57, 0xff, 0x00, 0x01, 0xc0, 0xca, 0xd9,
249 0xe2, 0x19, 0x94, 0xc0, 0xe2, 0x27, 0x00, 0x00,
250 0xe2, 0x17, 0x01, 0x00, 0xe2, 0x27, 0x00, 0x00,
251 0x9f, 0xaf, 0x40, 0x06, 0x9f, 0xaf, 0xc4, 0x01,
252 0xe7, 0x57, 0x00, 0x00, 0xd2, 0x06, 0x9f, 0xa1,
253 0x0e, 0x0a, 0xca, 0x05, 0xc8, 0x05, 0xc0, 0x05,
254 0xe7, 0x05, 0x00, 0xc0, 0xc0, 0xdf, 0x97, 0xcf,
255 0xc8, 0x09, 0xa0, 0x06, 0x08, 0x62, 0x97, 0xc0,
256 0x27, 0x04, 0xa0, 0x06, 0x27, 0x52, 0xa2, 0x06,
257 0x03, 0xc1, 0xe7, 0x07, 0xa0, 0x06, 0xa2, 0x06,
258 0x9f, 0xaf, 0x08, 0x03, 0xe7, 0x57, 0x00, 0x00,
259 0xaa, 0x06, 0x02, 0xc0, 0x27, 0xda, 0xaa, 0x06,
260 0x97, 0xcf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
261 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
262 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
263 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
264 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
265 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
266 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
267 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
268 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
269 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
270 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
271 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00,
272 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
273 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
274 0x00, 0x00, 0xff, 0xff, 0xfb, 0x13, 0xe7, 0x57,
275 0x00, 0x80, 0xb2, 0x00, 0x06, 0xc2, 0xe7, 0x07,
276 0xee, 0x0b, 0x12, 0x00, 0xe7, 0x07, 0x34, 0x0c,
277 0xb2, 0x00, 0xe7, 0x07, 0xc6, 0x07, 0xf2, 0x02,
278 0xc8, 0x09, 0xb4, 0x00, 0xf8, 0x07, 0x02, 0x00,
279 0x0d, 0x00, 0xd7, 0x09, 0x0e, 0xc0, 0xe7, 0x07,
280 0x00, 0x00, 0x0e, 0xc0, 0xc8, 0x09, 0xde, 0x00,
281 0xc8, 0x17, 0x09, 0x00, 0xc9, 0x07, 0xda, 0x06,
282 0xc0, 0x07, 0x04, 0x00, 0x68, 0x0a, 0x00, 0xda,
283 0x7d, 0xc1, 0xe7, 0x09, 0xc0, 0x00, 0x7c, 0x06,
284 0xe7, 0x09, 0xbe, 0x00, 0x78, 0x06, 0xe7, 0x09,
285 0x10, 0x00, 0xbc, 0x06, 0xc8, 0x07, 0xd6, 0x07,
286 0x9f, 0xaf, 0xae, 0x07, 0x9f, 0xaf, 0x00, 0x0a,
287 0xc8, 0x09, 0xde, 0x00, 0x00, 0x0e, 0x0f, 0x00,
288 0x41, 0x90, 0x9f, 0xde, 0x06, 0x00, 0x44, 0xaf,
289 0x27, 0x00, 0xb2, 0x06, 0x27, 0x00, 0xb4, 0x06,
290 0x27, 0x00, 0xb6, 0x06, 0xc0, 0x07, 0x74, 0x00,
291 0x44, 0xaf, 0x27, 0x00, 0xd6, 0x06, 0x08, 0x00,
292 0x00, 0x90, 0xc1, 0x07, 0x3a, 0x00, 0x20, 0x00,
293 0x01, 0xda, 0x7d, 0xc1, 0x9f, 0xaf, 0xba, 0x09,
294 0xc0, 0x07, 0x44, 0x00, 0x48, 0xaf, 0x27, 0x00,
295 0x7a, 0x06, 0x9f, 0xaf, 0x96, 0x0a, 0xe7, 0x07,
296 0x01, 0x00, 0xc0, 0x06, 0xe7, 0x05, 0x0e, 0xc0,
297 0x97, 0xcf, 0x49, 0xaf, 0xe7, 0x87, 0x43, 0x00,
298 0x0e, 0xc0, 0xe7, 0x07, 0xff, 0xff, 0xbe, 0x06,
299 0x9f, 0xaf, 0xae, 0x0a, 0xc0, 0x07, 0x01, 0x00,
300 0x60, 0xaf, 0x4a, 0xaf, 0x97, 0xcf, 0x00, 0x08,
301 0x09, 0x08, 0x11, 0x08, 0x00, 0xda, 0x7c, 0xc1,
302 0x97, 0xcf, 0x67, 0x04, 0xcc, 0x02, 0xc0, 0xdf,
303 0x51, 0x94, 0xb1, 0xaf, 0x06, 0x00, 0xc1, 0xdf,
304 0xc9, 0x09, 0xcc, 0x02, 0x49, 0x62, 0x75, 0xc1,
305 0xc0, 0xdf, 0xa7, 0xcf, 0xd6, 0x02, 0x0e, 0x00,
306 0x24, 0x00, 0x80, 0x04, 0x22, 0x00, 0x4e, 0x05,
307 0xd0, 0x00, 0x0e, 0x0a, 0xaa, 0x00, 0x30, 0x08,
308 0xbe, 0x00, 0x4a, 0x0a, 0x10, 0x00, 0x20, 0x00,
309 0x04, 0x00, 0x6e, 0x04, 0x02, 0x00, 0x6a, 0x04,
310 0x06, 0x00, 0x00, 0x00, 0x24, 0xc0, 0x04, 0x04,
311 0x28, 0xc0, 0xfe, 0xfb, 0x1e, 0xc0, 0x00, 0x04,
312 0x22, 0xc0, 0xff, 0xf4, 0xc0, 0x00, 0x90, 0x09,
313 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x56, 0x08,
314 0x60, 0x08, 0xd0, 0x08, 0xda, 0x08, 0x00, 0x09,
315 0x04, 0x09, 0x08, 0x09, 0x32, 0x09, 0x42, 0x09,
316 0x50, 0x09, 0x52, 0x09, 0x5a, 0x09, 0x5a, 0x09,
317 0x27, 0x02, 0xca, 0x06, 0x97, 0xcf, 0xe7, 0x07,
318 0x00, 0x00, 0xca, 0x06, 0x0a, 0x0e, 0x01, 0x00,
319 0xca, 0x57, 0x0e, 0x00, 0x9f, 0xc3, 0x5a, 0x09,
320 0xca, 0x37, 0x00, 0x00, 0x9f, 0xc2, 0x5a, 0x09,
321 0x0a, 0xd2, 0xb2, 0xcf, 0x16, 0x08, 0xc8, 0x09,
322 0xde, 0x00, 0x07, 0x06, 0x9f, 0xcf, 0x6c, 0x09,
323 0x17, 0x02, 0xc8, 0x09, 0xde, 0x00, 0x00, 0x0e,
324 0x0f, 0x00, 0x41, 0x90, 0x9f, 0xde, 0x06, 0x00,
325 0xc8, 0x05, 0x30, 0x50, 0x06, 0x00, 0x9f, 0xc8,
326 0x5a, 0x09, 0x27, 0x0c, 0x02, 0x00, 0xb0, 0x06,
327 0xc0, 0x09, 0xb2, 0x06, 0x27, 0x00, 0xb4, 0x06,
328 0xe7, 0x07, 0x00, 0x00, 0xae, 0x06, 0x27, 0x00,
329 0x80, 0x06, 0x00, 0x1c, 0x06, 0x00, 0x27, 0x00,
330 0xb6, 0x06, 0x41, 0x90, 0x67, 0x50, 0xb0, 0x06,
331 0x0d, 0xc0, 0x67, 0x00, 0x7e, 0x06, 0x27, 0x0c,
332 0x06, 0x00, 0x82, 0x06, 0xe7, 0x07, 0xbc, 0x08,
333 0x84, 0x06, 0xc8, 0x07, 0x7e, 0x06, 0x41, 0x90,
334 0x51, 0xaf, 0x97, 0xcf, 0x9f, 0xaf, 0x48, 0x0c,
335 0xe7, 0x09, 0xb6, 0x06, 0xb4, 0x06, 0xe7, 0x09,
336 0xb0, 0x06, 0xae, 0x06, 0x59, 0xaf, 0x97, 0xcf,
337 0x27, 0x0c, 0x02, 0x00, 0xac, 0x06, 0x59, 0xaf,
338 0x97, 0xcf, 0x09, 0x0c, 0x02, 0x00, 0x09, 0xda,
339 0x49, 0xd2, 0xc9, 0x19, 0xd6, 0x06, 0xc8, 0x07,
340 0x7e, 0x06, 0xe0, 0x07, 0x00, 0x00, 0x60, 0x02,
341 0xe0, 0x07, 0x04, 0x00, 0xd0, 0x07, 0xcc, 0x08,
342 0x48, 0xdb, 0x41, 0x90, 0x50, 0xaf, 0x97, 0xcf,
343 0x59, 0xaf, 0x97, 0xcf, 0x59, 0xaf, 0x97, 0xcf,
344 0xf0, 0x57, 0x06, 0x00, 0x06, 0x00, 0x25, 0xc1,
345 0xe7, 0x07, 0x70, 0x06, 0x80, 0x06, 0x41, 0x90,
346 0x67, 0x00, 0x7e, 0x06, 0x27, 0x0c, 0x06, 0x00,
347 0x82, 0x06, 0xe7, 0x07, 0x8c, 0x09, 0x84, 0x06,
348 0xc8, 0x07, 0x7e, 0x06, 0x41, 0x90, 0x51, 0xaf,
349 0x97, 0xcf, 0x07, 0x0c, 0x06, 0x00, 0xc7, 0x57,
350 0x06, 0x00, 0x0f, 0xc1, 0xc8, 0x07, 0x70, 0x06,
351 0x15, 0xcf, 0x00, 0x0c, 0x02, 0x00, 0x00, 0xda,
352 0x40, 0xd1, 0x27, 0x00, 0xc2, 0x06, 0x1e, 0xcf,
353 0x1d, 0xcf, 0x27, 0x0c, 0x02, 0x00, 0xcc, 0x06,
354 0x19, 0xcf, 0x27, 0x02, 0x20, 0x01, 0xe7, 0x07,
355 0x08, 0x00, 0x22, 0x01, 0xe7, 0x07, 0x13, 0x00,
356 0xb0, 0xc0, 0x97, 0xcf, 0x41, 0x90, 0x67, 0x00,
357 0x7e, 0x06, 0xe7, 0x01, 0x82, 0x06, 0x27, 0x02,
358 0x80, 0x06, 0xe7, 0x07, 0x8c, 0x09, 0x84, 0x06,
359 0xc8, 0x07, 0x7e, 0x06, 0xc1, 0x07, 0x00, 0x80,
360 0x50, 0xaf, 0x97, 0xcf, 0x59, 0xaf, 0x97, 0xcf,
361 0x00, 0x60, 0x05, 0xc0, 0xe7, 0x07, 0x00, 0x00,
362 0xc4, 0x06, 0xa7, 0xcf, 0x7c, 0x06, 0x9f, 0xaf,
363 0x00, 0x0a, 0xe7, 0x07, 0x01, 0x00, 0xc4, 0x06,
364 0x49, 0xaf, 0xd7, 0x09, 0x00, 0xc0, 0x07, 0xaf,
365 0xe7, 0x05, 0x00, 0xc0, 0x4a, 0xaf, 0xa7, 0xcf,
366 0x7c, 0x06, 0xc0, 0x07, 0xfe, 0x7f, 0x44, 0xaf,
367 0x40, 0x00, 0xc0, 0x37, 0x00, 0x01, 0x41, 0x90,
368 0xc0, 0x37, 0x08, 0x00, 0xdf, 0xde, 0x50, 0x06,
369 0xc0, 0x57, 0x10, 0x00, 0x02, 0xc2, 0xc0, 0x07,
370 0x10, 0x00, 0x27, 0x00, 0x9a, 0x06, 0x41, 0x90,
371 0x9f, 0xde, 0x40, 0x06, 0x44, 0xaf, 0x27, 0x00,
372 0x9c, 0x06, 0xc0, 0x09, 0x9a, 0x06, 0x41, 0x90,
373 0x00, 0xd2, 0x00, 0xd8, 0x9f, 0xde, 0x08, 0x00,
374 0x44, 0xaf, 0x27, 0x00, 0xc8, 0x06, 0x97, 0xcf,
375 0xe7, 0x87, 0x00, 0x84, 0x28, 0xc0, 0xe7, 0x67,
376 0xff, 0xfb, 0x24, 0xc0, 0x97, 0xcf, 0xe7, 0x87,
377 0x01, 0x00, 0xd2, 0x06, 0xe7, 0x57, 0x00, 0x00,
378 0xa8, 0x06, 0x97, 0xc1, 0x9f, 0xaf, 0x00, 0x0a,
379 0xe7, 0x87, 0x00, 0x06, 0x22, 0xc0, 0xe7, 0x07,
380 0x00, 0x00, 0x90, 0xc0, 0xe7, 0x67, 0xfe, 0xff,
381 0x3e, 0xc0, 0xe7, 0x07, 0x26, 0x00, 0x0a, 0xc0,
382 0xe7, 0x87, 0x01, 0x00, 0x3e, 0xc0, 0xe7, 0x07,
383 0xff, 0xff, 0xbe, 0x06, 0x9f, 0xaf, 0x10, 0x0b,
384 0x97, 0xcf, 0x17, 0x00, 0xa7, 0xaf, 0x78, 0x06,
385 0xc0, 0x05, 0x27, 0x00, 0x76, 0x06, 0xe7, 0x87,
386 0x01, 0x00, 0xd2, 0x06, 0x9f, 0xaf, 0x00, 0x0a,
387 0xe7, 0x07, 0x0c, 0x00, 0x40, 0xc0, 0x9f, 0xaf,
388 0x10, 0x0b, 0x00, 0x90, 0x27, 0x00, 0xa6, 0x06,
389 0x27, 0x00, 0xaa, 0x06, 0xe7, 0x09, 0xb2, 0x06,
390 0xb4, 0x06, 0x27, 0x00, 0xae, 0x06, 0x27, 0x00,
391 0xac, 0x06, 0x9f, 0xaf, 0xae, 0x0a, 0xc0, 0x07,
392 0x00, 0x00, 0x27, 0x00, 0xb2, 0x02, 0x27, 0x00,
393 0xb4, 0x02, 0x27, 0x00, 0x8e, 0x06, 0xc0, 0x07,
394 0x06, 0x00, 0xc8, 0x09, 0xde, 0x00, 0xc8, 0x17,
395 0x03, 0x00, 0xc9, 0x07, 0x70, 0x06, 0x29, 0x0a,
396 0x00, 0xda, 0x7d, 0xc1, 0x97, 0xcf, 0xd7, 0x09,
397 0x00, 0xc0, 0xc1, 0xdf, 0x00, 0x90, 0x27, 0x00,
398 0x96, 0x06, 0xe7, 0x07, 0x96, 0x06, 0x98, 0x06,
399 0x27, 0x00, 0xa0, 0x06, 0xe7, 0x07, 0xa0, 0x06,
400 0xa2, 0x06, 0x27, 0x00, 0xa6, 0x06, 0x27, 0x00,
401 0x90, 0x06, 0x27, 0x00, 0x9e, 0x06, 0xc8, 0x09,
402 0x9c, 0x06, 0xc1, 0x09, 0x9a, 0x06, 0xc9, 0x07,
403 0xa4, 0x06, 0x11, 0x02, 0x09, 0x02, 0xc8, 0x17,
404 0x40, 0x06, 0x01, 0xda, 0x7a, 0xc1, 0x51, 0x94,
405 0xc8, 0x09, 0xc8, 0x06, 0xc9, 0x07, 0xc6, 0x06,
406 0xc1, 0x09, 0x9a, 0x06, 0x11, 0x02, 0x09, 0x02,
407 0xc8, 0x17, 0x08, 0x00, 0x01, 0xda, 0x7a, 0xc1,
408 0x51, 0x94, 0xe7, 0x05, 0x00, 0xc0, 0x97, 0xcf,
409 0xe7, 0x57, 0x00, 0x00, 0x76, 0x06, 0x97, 0xc0,
410 0x9f, 0xaf, 0x04, 0x00, 0xe7, 0x09, 0xbe, 0x06,
411 0xba, 0x06, 0xe7, 0x57, 0xff, 0xff, 0xba, 0x06,
412 0x04, 0xc1, 0xe7, 0x07, 0x10, 0x0b, 0xb8, 0x06,
413 0x97, 0xcf, 0xe7, 0x17, 0x32, 0x00, 0xba, 0x06,
414 0xe7, 0x67, 0xff, 0x07, 0xba, 0x06, 0xe7, 0x07,
415 0x46, 0x0b, 0xb8, 0x06, 0x97, 0xcf, 0xe7, 0x57,
416 0x00, 0x00, 0xc0, 0x06, 0x23, 0xc0, 0xe7, 0x07,
417 0x04, 0x00, 0x90, 0xc0, 0xe7, 0x07, 0x00, 0x80,
418 0x80, 0xc0, 0xe7, 0x07, 0x00, 0x00, 0x80, 0xc0,
419 0xe7, 0x07, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0x07,
420 0x00, 0x00, 0xc0, 0x07, 0x00, 0x00, 0xc0, 0x07,
421 0x00, 0x00, 0xe7, 0x07, 0x00, 0x00, 0x80, 0xc0,
422 0xe7, 0x07, 0x00, 0x80, 0x80, 0xc0, 0xe7, 0x07,
423 0x00, 0x80, 0x40, 0xc0, 0xc0, 0x07, 0x00, 0x00,
424 0xe7, 0x07, 0x00, 0x00, 0x40, 0xc0, 0xe7, 0x07,
425 0x00, 0x00, 0x80, 0xc0, 0xe7, 0x07, 0x04, 0x00,
426 0x90, 0xc0, 0xe7, 0x07, 0x00, 0x02, 0x40, 0xc0,
427 0xe7, 0x07, 0x0c, 0x02, 0x40, 0xc0, 0xe7, 0x07,
428 0x00, 0x00, 0xc0, 0x06, 0xe7, 0x07, 0x00, 0x00,
429 0xb8, 0x06, 0xe7, 0x07, 0x00, 0x00, 0xd2, 0x06,
430 0xd7, 0x09, 0x00, 0xc0, 0xc1, 0xdf, 0x9f, 0xaf,
431 0x34, 0x02, 0xe7, 0x05, 0x00, 0xc0, 0x9f, 0xaf,
432 0xc4, 0x01, 0x97, 0xcf, 0xd7, 0x09, 0x00, 0xc0,
433 0x17, 0x00, 0x17, 0x02, 0x97, 0x02, 0xe7, 0x57,
434 0x00, 0x00, 0xa8, 0x06, 0x06, 0xc0, 0xc0, 0x09,
435 0x92, 0xc0, 0xc0, 0x77, 0x09, 0x02, 0x9f, 0xc1,
436 0x5c, 0x05, 0x9f, 0xcf, 0x32, 0x06, 0xd7, 0x09,
437 0x0e, 0xc0, 0xe7, 0x07, 0x00, 0x00, 0x0e, 0xc0,
438 0x9f, 0xaf, 0x02, 0x0c, 0xe7, 0x05, 0x0e, 0xc0,
439 0x97, 0xcf, 0xd7, 0x09, 0x00, 0xc0, 0x17, 0x02,
440 0xc8, 0x09, 0xb0, 0xc0, 0xe7, 0x67, 0xfe, 0x7f,
441 0xb0, 0xc0, 0xc8, 0x77, 0x00, 0x20, 0x9f, 0xc1,
442 0x64, 0xeb, 0xe7, 0x57, 0x00, 0x00, 0xc8, 0x02,
443 0x9f, 0xc1, 0x80, 0xeb, 0xc8, 0x99, 0xca, 0x02,
444 0xc8, 0x67, 0x04, 0x00, 0x9f, 0xc1, 0x96, 0xeb,
445 0x9f, 0xcf, 0x4c, 0xeb, 0xe7, 0x07, 0x00, 0x00,
446 0xa6, 0xc0, 0xe7, 0x09, 0xb0, 0xc0, 0xc8, 0x02,
447 0xe7, 0x07, 0x03, 0x00, 0xb0, 0xc0, 0x97, 0xcf,
448 0xc0, 0x09, 0xb0, 0x06, 0xc0, 0x37, 0x01, 0x00,
449 0x97, 0xc9, 0xc9, 0x09, 0xb2, 0x06, 0x02, 0x00,
450 0x41, 0x90, 0x48, 0x02, 0xc9, 0x17, 0x06, 0x00,
451 0x9f, 0xaf, 0x08, 0x04, 0x9f, 0xa2, 0x72, 0x0c,
452 0x02, 0xda, 0x77, 0xc1, 0x41, 0x60, 0x71, 0xc1,
453 0x97, 0xcf, 0x17, 0x02, 0x57, 0x02, 0x43, 0x04,
454 0x21, 0x04, 0xe0, 0x00, 0x43, 0x04, 0x21, 0x04,
455 0xe0, 0x00, 0x43, 0x04, 0x21, 0x04, 0xe0, 0x00,
456 0xc1, 0x07, 0x01, 0x00, 0xc9, 0x05, 0xc8, 0x05,
457 0x97, 0xcf, 0xe7, 0x07, 0x01, 0x00, 0x8e, 0x06,
458 0xc8, 0x07, 0x86, 0x06, 0xe7, 0x07, 0x00, 0x00,
459 0x86, 0x06, 0xe7, 0x07, 0x10, 0x08, 0x88, 0x06,
460 0xe7, 0x07, 0x04, 0x00, 0x8a, 0x06, 0xe7, 0x07,
461 0xbc, 0x0c, 0x8c, 0x06, 0xc1, 0x07, 0x03, 0x80,
462 0x50, 0xaf, 0x97, 0xcf, 0xe7, 0x07, 0x00, 0x00,
463 0x8e, 0x06, 0x97, 0xcf,
464 0x00, 0x00
465};
466
467/****************************************************************
468 * kaweth_new_code_fix
469 ****************************************************************/
470static __u8 kaweth_new_code_fix[] =
471{
472 0xB6, 0xC3, 0xAA, 0xBB, 0xCC, 0xDD,
473 0x02, 0x00, 0x08, 0x00, 0x28, 0x00, 0x2c, 0x00,
474 0x34, 0x00, 0x3c, 0x00, 0x40, 0x00, 0x48, 0x00,
475 0x54, 0x00, 0x58, 0x00, 0x5e, 0x00, 0x64, 0x00,
476 0x68, 0x00, 0x6e, 0x00, 0x6c, 0x00, 0x72, 0x00,
477 0x76, 0x00, 0x7c, 0x00, 0x80, 0x00, 0x86, 0x00,
478 0x8a, 0x00, 0x90, 0x00, 0x94, 0x00, 0x98, 0x00,
479 0x9e, 0x00, 0xa6, 0x00, 0xaa, 0x00, 0xb0, 0x00,
480 0xb4, 0x00, 0xb8, 0x00, 0xc0, 0x00, 0xc6, 0x00,
481 0xca, 0x00, 0xd0, 0x00, 0xd4, 0x00, 0xd8, 0x00,
482 0xe0, 0x00, 0xde, 0x00, 0xe8, 0x00, 0xf0, 0x00,
483 0xfc, 0x00, 0x04, 0x01, 0x0a, 0x01, 0x18, 0x01,
484 0x22, 0x01, 0x28, 0x01, 0x3a, 0x01, 0x3e, 0x01,
485 0x7e, 0x01, 0x98, 0x01, 0x9c, 0x01, 0xa2, 0x01,
486 0xac, 0x01, 0xb2, 0x01, 0xba, 0x01, 0xc0, 0x01,
487 0xc8, 0x01, 0xd0, 0x01, 0xd6, 0x01, 0xf4, 0x01,
488 0xfc, 0x01, 0x08, 0x02, 0x16, 0x02, 0x1a, 0x02,
489 0x22, 0x02, 0x2a, 0x02, 0x2e, 0x02, 0x3e, 0x02,
490 0x44, 0x02, 0x4a, 0x02, 0x50, 0x02, 0x64, 0x02,
491 0x62, 0x02, 0x6c, 0x02, 0x72, 0x02, 0x86, 0x02,
492 0x8c, 0x02, 0x90, 0x02, 0x9e, 0x02, 0xbc, 0x02,
493 0xd0, 0x02, 0xd8, 0x02, 0xdc, 0x02, 0xe0, 0x02,
494 0xe8, 0x02, 0xe6, 0x02, 0xf4, 0x02, 0xfe, 0x02,
495 0x04, 0x03, 0x0c, 0x03, 0x28, 0x03, 0x7c, 0x03,
496 0x90, 0x03, 0x94, 0x03, 0x9c, 0x03, 0xa2, 0x03,
497 0xc0, 0x03, 0xd0, 0x03, 0xd4, 0x03, 0xee, 0x03,
498 0xfa, 0x03, 0xfe, 0x03, 0x2e, 0x04, 0x32, 0x04,
499 0x3c, 0x04, 0x40, 0x04, 0x4e, 0x04, 0x76, 0x04,
500 0x7c, 0x04, 0x84, 0x04, 0x8a, 0x04, 0x8e, 0x04,
501 0xa6, 0x04, 0xb0, 0x04, 0xb8, 0x04, 0xbe, 0x04,
502 0xd2, 0x04, 0xdc, 0x04, 0xee, 0x04, 0x10, 0x05,
503 0x1a, 0x05, 0x24, 0x05, 0x2a, 0x05, 0x36, 0x05,
504 0x34, 0x05, 0x3c, 0x05, 0x42, 0x05, 0x64, 0x05,
505 0x6a, 0x05, 0x6e, 0x05, 0x86, 0x05, 0x22, 0x06,
506 0x26, 0x06, 0x2c, 0x06, 0x30, 0x06, 0x42, 0x06,
507 0x4a, 0x06, 0x4e, 0x06, 0x56, 0x06, 0x54, 0x06,
508 0x5a, 0x06, 0x60, 0x06, 0x66, 0x06, 0xe8, 0x06,
509 0xee, 0x06, 0xf4, 0x06, 0x16, 0x07, 0x26, 0x07,
510 0x2c, 0x07, 0x32, 0x07, 0x36, 0x07, 0x3a, 0x07,
511 0x3e, 0x07, 0x52, 0x07, 0x56, 0x07, 0x5a, 0x07,
512 0x64, 0x07, 0x76, 0x07, 0x7a, 0x07, 0x80, 0x07,
513 0x84, 0x07, 0x8a, 0x07, 0x9e, 0x07, 0xa2, 0x07,
514 0xda, 0x07, 0xde, 0x07, 0xe2, 0x07, 0xe6, 0x07,
515 0xea, 0x07, 0xee, 0x07, 0xf2, 0x07, 0xf6, 0x07,
516 0x0e, 0x08, 0x16, 0x08, 0x18, 0x08, 0x1a, 0x08,
517 0x1c, 0x08, 0x1e, 0x08, 0x20, 0x08, 0x22, 0x08,
518 0x24, 0x08, 0x26, 0x08, 0x28, 0x08, 0x2a, 0x08,
519 0x2c, 0x08, 0x2e, 0x08, 0x32, 0x08, 0x3a, 0x08,
520 0x46, 0x08, 0x4e, 0x08, 0x54, 0x08, 0x5e, 0x08,
521 0x78, 0x08, 0x7e, 0x08, 0x82, 0x08, 0x86, 0x08,
522 0x8c, 0x08, 0x90, 0x08, 0x98, 0x08, 0x9e, 0x08,
523 0xa4, 0x08, 0xaa, 0x08, 0xb0, 0x08, 0xae, 0x08,
524 0xb4, 0x08, 0xbe, 0x08, 0xc4, 0x08, 0xc2, 0x08,
525 0xca, 0x08, 0xc8, 0x08, 0xd4, 0x08, 0xe4, 0x08,
526 0xe8, 0x08, 0xf6, 0x08, 0x14, 0x09, 0x12, 0x09,
527 0x1a, 0x09, 0x20, 0x09, 0x26, 0x09, 0x24, 0x09,
528 0x2a, 0x09, 0x3e, 0x09, 0x4c, 0x09, 0x56, 0x09,
529 0x70, 0x09, 0x74, 0x09, 0x78, 0x09, 0x7e, 0x09,
530 0x7c, 0x09, 0x82, 0x09, 0x98, 0x09, 0x9c, 0x09,
531 0xa0, 0x09, 0xa6, 0x09, 0xb8, 0x09, 0xdc, 0x09,
532 0xe8, 0x09, 0xec, 0x09, 0xfc, 0x09, 0x12, 0x0a,
533 0x18, 0x0a, 0x1e, 0x0a, 0x42, 0x0a, 0x46, 0x0a,
534 0x4e, 0x0a, 0x54, 0x0a, 0x5a, 0x0a, 0x5e, 0x0a,
535 0x68, 0x0a, 0x6e, 0x0a, 0x72, 0x0a, 0x78, 0x0a,
536 0x76, 0x0a, 0x7c, 0x0a, 0x80, 0x0a, 0x84, 0x0a,
537 0x94, 0x0a, 0xa4, 0x0a, 0xb8, 0x0a, 0xbe, 0x0a,
538 0xbc, 0x0a, 0xc2, 0x0a, 0xc8, 0x0a, 0xc6, 0x0a,
539 0xcc, 0x0a, 0xd0, 0x0a, 0xd4, 0x0a, 0xd8, 0x0a,
540 0xdc, 0x0a, 0xe0, 0x0a, 0xf2, 0x0a, 0xf6, 0x0a,
541 0xfa, 0x0a, 0x14, 0x0b, 0x1a, 0x0b, 0x20, 0x0b,
542 0x1e, 0x0b, 0x26, 0x0b, 0x2e, 0x0b, 0x2c, 0x0b,
543 0x36, 0x0b, 0x3c, 0x0b, 0x42, 0x0b, 0x40, 0x0b,
544 0x4a, 0x0b, 0xaa, 0x0b, 0xb0, 0x0b, 0xb6, 0x0b,
545 0xc0, 0x0b, 0xc8, 0x0b, 0xda, 0x0b, 0xe8, 0x0b,
546 0xec, 0x0b, 0xfa, 0x0b, 0x4a, 0x0c, 0x54, 0x0c,
547 0x62, 0x0c, 0x66, 0x0c, 0x96, 0x0c, 0x9a, 0x0c,
548 0xa0, 0x0c, 0xa6, 0x0c, 0xa4, 0x0c, 0xac, 0x0c,
549 0xb2, 0x0c, 0xb0, 0x0c, 0xc0, 0x0c,
550 0x00, 0x00
551};
552
553
554static const int len_kaweth_trigger_code = sizeof(kaweth_trigger_code);
555static const int len_kaweth_trigger_code_fix = sizeof(kaweth_trigger_code_fix);
556static const int len_kaweth_new_code = sizeof(kaweth_new_code);
557static const int len_kaweth_new_code_fix = sizeof(kaweth_new_code_fix);
diff --git a/drivers/usb/net/pegasus.c b/drivers/usb/net/pegasus.c
new file mode 100644
index 000000000000..f6c19d73b7da
--- /dev/null
+++ b/drivers/usb/net/pegasus.c
@@ -0,0 +1,1408 @@
1/*
2 * Copyright (c) 1999-2005 Petko Manolov (petkan@users.sourceforge.net)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ChangeLog:
9 * .... Most of the time spent on reading sources & docs.
10 * v0.2.x First official release for the Linux kernel.
11 * v0.3.0 Beutified and structured, some bugs fixed.
12 * v0.3.x URBifying bulk requests and bugfixing. First relatively
13 * stable release. Still can touch device's registers only
14 * from top-halves.
15 * v0.4.0 Control messages remained unurbified are now URBs.
16 * Now we can touch the HW at any time.
17 * v0.4.9 Control urbs again use process context to wait. Argh...
18 * Some long standing bugs (enable_net_traffic) fixed.
19 * Also nasty trick about resubmiting control urb from
20 * interrupt context used. Please let me know how it
21 * behaves. Pegasus II support added since this version.
22 * TODO: suppressing HCD warnings spewage on disconnect.
23 * v0.4.13 Ethernet address is now set at probe(), not at open()
24 * time as this seems to break dhcpd.
25 * v0.5.0 branch to 2.5.x kernels
26 * v0.5.1 ethtool support added
27 * v0.5.5 rx socket buffers are in a pool and the their allocation
28 * is out of the interrupt routine.
29 */
30
31#undef DEBUG
32
33#include <linux/sched.h>
34#include <linux/slab.h>
35#include <linux/init.h>
36#include <linux/delay.h>
37#include <linux/netdevice.h>
38#include <linux/etherdevice.h>
39#include <linux/ethtool.h>
40#include <linux/mii.h>
41#include <linux/usb.h>
42#include <linux/module.h>
43#include <asm/byteorder.h>
44#include <asm/uaccess.h>
45#include "pegasus.h"
46
47/*
48 * Version Information
49 */
50#define DRIVER_VERSION "v0.6.12 (2005/01/13)"
51#define DRIVER_AUTHOR "Petko Manolov <petkan@users.sourceforge.net>"
52#define DRIVER_DESC "Pegasus/Pegasus II USB Ethernet driver"
53
54static const char driver_name[] = "pegasus";
55
56#undef PEGASUS_WRITE_EEPROM
57#define BMSR_MEDIA (BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | \
58 BMSR_100FULL | BMSR_ANEGCAPABLE)
59
60static int loopback = 0;
61static int mii_mode = 0;
62static int multicast_filter_limit = 32;
63
64static struct usb_eth_dev usb_dev_id[] = {
65#define PEGASUS_DEV(pn, vid, pid, flags) \
66 {.name = pn, .vendor = vid, .device = pid, .private = flags},
67#include "pegasus.h"
68#undef PEGASUS_DEV
69 {NULL, 0, 0, 0}
70};
71
72static struct usb_device_id pegasus_ids[] = {
73#define PEGASUS_DEV(pn, vid, pid, flags) \
74 {.match_flags = USB_DEVICE_ID_MATCH_DEVICE, .idVendor = vid, .idProduct = pid},
75#include "pegasus.h"
76#undef PEGASUS_DEV
77 {}
78};
79
80MODULE_AUTHOR(DRIVER_AUTHOR);
81MODULE_DESCRIPTION(DRIVER_DESC);
82MODULE_LICENSE("GPL");
83module_param(loopback, bool, 0);
84module_param(mii_mode, bool, 0);
85MODULE_PARM_DESC(loopback, "Enable MAC loopback mode (bit 0)");
86MODULE_PARM_DESC(mii_mode, "Enable HomePNA mode (bit 0),default=MII mode = 0");
87
88/* use ethtool to change the level for any given device */
89static int msg_level = -1;
90module_param (msg_level, int, 0);
91MODULE_PARM_DESC (msg_level, "Override default message level");
92
93MODULE_DEVICE_TABLE(usb, pegasus_ids);
94
95static int update_eth_regs_async(pegasus_t *);
96/* Aargh!!! I _really_ hate such tweaks */
97static void ctrl_callback(struct urb *urb, struct pt_regs *regs)
98{
99 pegasus_t *pegasus = urb->context;
100
101 if (!pegasus)
102 return;
103
104 switch (urb->status) {
105 case 0:
106 if (pegasus->flags & ETH_REGS_CHANGE) {
107 pegasus->flags &= ~ETH_REGS_CHANGE;
108 pegasus->flags |= ETH_REGS_CHANGED;
109 update_eth_regs_async(pegasus);
110 return;
111 }
112 break;
113 case -EINPROGRESS:
114 return;
115 case -ENOENT:
116 break;
117 default:
118 if (netif_msg_drv(pegasus))
119 dev_err(&pegasus->intf->dev, "%s, status %d\n",
120 __FUNCTION__, urb->status);
121 }
122 pegasus->flags &= ~ETH_REGS_CHANGED;
123 wake_up(&pegasus->ctrl_wait);
124}
125
126static int get_registers(pegasus_t * pegasus, __u16 indx, __u16 size,
127 void *data)
128{
129 int ret;
130 char *buffer;
131 DECLARE_WAITQUEUE(wait, current);
132
133 buffer = kmalloc(size, GFP_KERNEL);
134 if (!buffer) {
135 if (netif_msg_drv(pegasus))
136 dev_warn(&pegasus->intf->dev, "out of memory in %s\n",
137 __FUNCTION__);
138 return -ENOMEM;
139 }
140 add_wait_queue(&pegasus->ctrl_wait, &wait);
141 set_current_state(TASK_UNINTERRUPTIBLE);
142 while (pegasus->flags & ETH_REGS_CHANGED)
143 schedule();
144 remove_wait_queue(&pegasus->ctrl_wait, &wait);
145 set_current_state(TASK_RUNNING);
146
147 pegasus->dr.bRequestType = PEGASUS_REQT_READ;
148 pegasus->dr.bRequest = PEGASUS_REQ_GET_REGS;
149 pegasus->dr.wValue = cpu_to_le16(0);
150 pegasus->dr.wIndex = cpu_to_le16p(&indx);
151 pegasus->dr.wLength = cpu_to_le16p(&size);
152 pegasus->ctrl_urb->transfer_buffer_length = size;
153
154 usb_fill_control_urb(pegasus->ctrl_urb, pegasus->usb,
155 usb_rcvctrlpipe(pegasus->usb, 0),
156 (char *) &pegasus->dr,
157 buffer, size, ctrl_callback, pegasus);
158
159 add_wait_queue(&pegasus->ctrl_wait, &wait);
160 set_current_state(TASK_UNINTERRUPTIBLE);
161
162 /* using ATOMIC, we'd never wake up if we slept */
163 if ((ret = usb_submit_urb(pegasus->ctrl_urb, GFP_ATOMIC))) {
164 if (netif_msg_drv(pegasus))
165 dev_err(&pegasus->intf->dev, "%s, status %d\n",
166 __FUNCTION__, ret);
167 goto out;
168 }
169
170 schedule();
171out:
172 remove_wait_queue(&pegasus->ctrl_wait, &wait);
173 memcpy(data, buffer, size);
174 kfree(buffer);
175
176 return ret;
177}
178
179static int set_registers(pegasus_t * pegasus, __u16 indx, __u16 size,
180 void *data)
181{
182 int ret;
183 char *buffer;
184 DECLARE_WAITQUEUE(wait, current);
185
186 buffer = kmalloc(size, GFP_KERNEL);
187 if (!buffer) {
188 if (netif_msg_drv(pegasus))
189 dev_warn(&pegasus->intf->dev, "out of memory in %s\n",
190 __FUNCTION__);
191 return -ENOMEM;
192 }
193 memcpy(buffer, data, size);
194
195 add_wait_queue(&pegasus->ctrl_wait, &wait);
196 set_current_state(TASK_UNINTERRUPTIBLE);
197 while (pegasus->flags & ETH_REGS_CHANGED)
198 schedule();
199 remove_wait_queue(&pegasus->ctrl_wait, &wait);
200 set_current_state(TASK_RUNNING);
201
202 pegasus->dr.bRequestType = PEGASUS_REQT_WRITE;
203 pegasus->dr.bRequest = PEGASUS_REQ_SET_REGS;
204 pegasus->dr.wValue = cpu_to_le16(0);
205 pegasus->dr.wIndex = cpu_to_le16p(&indx);
206 pegasus->dr.wLength = cpu_to_le16p(&size);
207 pegasus->ctrl_urb->transfer_buffer_length = size;
208
209 usb_fill_control_urb(pegasus->ctrl_urb, pegasus->usb,
210 usb_sndctrlpipe(pegasus->usb, 0),
211 (char *) &pegasus->dr,
212 buffer, size, ctrl_callback, pegasus);
213
214 add_wait_queue(&pegasus->ctrl_wait, &wait);
215 set_current_state(TASK_UNINTERRUPTIBLE);
216
217 if ((ret = usb_submit_urb(pegasus->ctrl_urb, GFP_ATOMIC))) {
218 if (netif_msg_drv(pegasus))
219 dev_err(&pegasus->intf->dev, "%s, status %d\n",
220 __FUNCTION__, ret);
221 goto out;
222 }
223
224 schedule();
225out:
226 remove_wait_queue(&pegasus->ctrl_wait, &wait);
227 kfree(buffer);
228
229 return ret;
230}
231
232static int set_register(pegasus_t * pegasus, __u16 indx, __u8 data)
233{
234 int ret;
235 char *tmp;
236 DECLARE_WAITQUEUE(wait, current);
237
238 tmp = kmalloc(1, GFP_KERNEL);
239 if (!tmp) {
240 if (netif_msg_drv(pegasus))
241 dev_warn(&pegasus->intf->dev, "out of memory in %s\n",
242 __FUNCTION__);
243 return -ENOMEM;
244 }
245 memcpy(tmp, &data, 1);
246 add_wait_queue(&pegasus->ctrl_wait, &wait);
247 set_current_state(TASK_UNINTERRUPTIBLE);
248 while (pegasus->flags & ETH_REGS_CHANGED)
249 schedule();
250 remove_wait_queue(&pegasus->ctrl_wait, &wait);
251 set_current_state(TASK_RUNNING);
252
253 pegasus->dr.bRequestType = PEGASUS_REQT_WRITE;
254 pegasus->dr.bRequest = PEGASUS_REQ_SET_REG;
255 pegasus->dr.wValue = cpu_to_le16(data);
256 pegasus->dr.wIndex = cpu_to_le16p(&indx);
257 pegasus->dr.wLength = cpu_to_le16(1);
258 pegasus->ctrl_urb->transfer_buffer_length = 1;
259
260 usb_fill_control_urb(pegasus->ctrl_urb, pegasus->usb,
261 usb_sndctrlpipe(pegasus->usb, 0),
262 (char *) &pegasus->dr,
263 &tmp, 1, ctrl_callback, pegasus);
264
265 add_wait_queue(&pegasus->ctrl_wait, &wait);
266 set_current_state(TASK_UNINTERRUPTIBLE);
267
268 if ((ret = usb_submit_urb(pegasus->ctrl_urb, GFP_ATOMIC))) {
269 if (netif_msg_drv(pegasus))
270 dev_err(&pegasus->intf->dev, "%s, status %d\n",
271 __FUNCTION__, ret);
272 goto out;
273 }
274
275 schedule();
276out:
277 remove_wait_queue(&pegasus->ctrl_wait, &wait);
278 kfree(tmp);
279
280 return ret;
281}
282
283static int update_eth_regs_async(pegasus_t * pegasus)
284{
285 int ret;
286
287 pegasus->dr.bRequestType = PEGASUS_REQT_WRITE;
288 pegasus->dr.bRequest = PEGASUS_REQ_SET_REGS;
289 pegasus->dr.wValue = 0;
290 pegasus->dr.wIndex = cpu_to_le16(EthCtrl0);
291 pegasus->dr.wLength = cpu_to_le16(3);
292 pegasus->ctrl_urb->transfer_buffer_length = 3;
293
294 usb_fill_control_urb(pegasus->ctrl_urb, pegasus->usb,
295 usb_sndctrlpipe(pegasus->usb, 0),
296 (char *) &pegasus->dr,
297 pegasus->eth_regs, 3, ctrl_callback, pegasus);
298
299 if ((ret = usb_submit_urb(pegasus->ctrl_urb, GFP_ATOMIC)))
300 if (netif_msg_drv(pegasus))
301 dev_err(&pegasus->intf->dev, "%s, status %d\n",
302 __FUNCTION__, ret);
303
304 return ret;
305}
306
307static int read_mii_word(pegasus_t * pegasus, __u8 phy, __u8 indx, __u16 * regd)
308{
309 int i;
310 __u8 data[4] = { phy, 0, 0, indx };
311 __le16 regdi;
312 int ret;
313
314 ret = set_register(pegasus, PhyCtrl, 0);
315 ret = set_registers(pegasus, PhyAddr, sizeof (data), data);
316 ret = set_register(pegasus, PhyCtrl, (indx | PHY_READ));
317 for (i = 0; i < REG_TIMEOUT; i++) {
318 ret = get_registers(pegasus, PhyCtrl, 1, data);
319 if (data[0] & PHY_DONE)
320 break;
321 }
322 if (i < REG_TIMEOUT) {
323 ret = get_registers(pegasus, PhyData, 2, &regdi);
324 *regd = le16_to_cpu(regdi);
325 return 1;
326 }
327 if (netif_msg_drv(pegasus))
328 dev_warn(&pegasus->intf->dev, "fail %s\n", __FUNCTION__);
329
330 return 0;
331}
332
333static int mdio_read(struct net_device *dev, int phy_id, int loc)
334{
335 pegasus_t *pegasus = (pegasus_t *) netdev_priv(dev);
336 u16 res;
337
338 read_mii_word(pegasus, phy_id, loc, &res);
339 return (int)res;
340}
341
342static int write_mii_word(pegasus_t * pegasus, __u8 phy, __u8 indx, __u16 regd)
343{
344 int i;
345 __u8 data[4] = { phy, 0, 0, indx };
346 int ret;
347
348 data[1] = (u8) regd;
349 data[2] = (u8) (regd >> 8);
350 ret = set_register(pegasus, PhyCtrl, 0);
351 ret = set_registers(pegasus, PhyAddr, sizeof(data), data);
352 ret = set_register(pegasus, PhyCtrl, (indx | PHY_WRITE));
353 for (i = 0; i < REG_TIMEOUT; i++) {
354 ret = get_registers(pegasus, PhyCtrl, 1, data);
355 if (data[0] & PHY_DONE)
356 break;
357 }
358 if (i < REG_TIMEOUT)
359 return 0;
360
361 if (netif_msg_drv(pegasus))
362 dev_warn(&pegasus->intf->dev, "fail %s\n", __FUNCTION__);
363 return 1;
364}
365
366static void mdio_write(struct net_device *dev, int phy_id, int loc, int val)
367{
368 pegasus_t *pegasus = (pegasus_t *) netdev_priv(dev);
369
370 write_mii_word(pegasus, phy_id, loc, val);
371}
372
373static int read_eprom_word(pegasus_t * pegasus, __u8 index, __u16 * retdata)
374{
375 int i;
376 __u8 tmp;
377 __le16 retdatai;
378 int ret;
379
380 ret = set_register(pegasus, EpromCtrl, 0);
381 ret = set_register(pegasus, EpromOffset, index);
382 ret = set_register(pegasus, EpromCtrl, EPROM_READ);
383
384 for (i = 0; i < REG_TIMEOUT; i++) {
385 ret = get_registers(pegasus, EpromCtrl, 1, &tmp);
386 if (tmp & EPROM_DONE)
387 break;
388 }
389 if (i < REG_TIMEOUT) {
390 ret = get_registers(pegasus, EpromData, 2, &retdatai);
391 *retdata = le16_to_cpu(retdatai);
392 return 0;
393 }
394
395 if (netif_msg_drv(pegasus))
396 dev_warn(&pegasus->intf->dev, "fail %s\n", __FUNCTION__);
397 return -1;
398}
399
400#ifdef PEGASUS_WRITE_EEPROM
401static inline void enable_eprom_write(pegasus_t * pegasus)
402{
403 __u8 tmp;
404 int ret;
405
406 ret = get_registers(pegasus, EthCtrl2, 1, &tmp);
407 ret = set_register(pegasus, EthCtrl2, tmp | EPROM_WR_ENABLE);
408}
409
410static inline void disable_eprom_write(pegasus_t * pegasus)
411{
412 __u8 tmp;
413 int ret;
414
415 ret = get_registers(pegasus, EthCtrl2, 1, &tmp);
416 ret = set_register(pegasus, EpromCtrl, 0);
417 ret = set_register(pegasus, EthCtrl2, tmp & ~EPROM_WR_ENABLE);
418}
419
420static int write_eprom_word(pegasus_t * pegasus, __u8 index, __u16 data)
421{
422 int i;
423 __u8 tmp, d[4] = { 0x3f, 0, 0, EPROM_WRITE };
424 int ret;
425
426 ret = set_registers(pegasus, EpromOffset, 4, d);
427 enable_eprom_write(pegasus);
428 ret = set_register(pegasus, EpromOffset, index);
429 ret = set_registers(pegasus, EpromData, 2, &data);
430 ret = set_register(pegasus, EpromCtrl, EPROM_WRITE);
431
432 for (i = 0; i < REG_TIMEOUT; i++) {
433 ret = get_registers(pegasus, EpromCtrl, 1, &tmp);
434 if (tmp & EPROM_DONE)
435 break;
436 }
437 disable_eprom_write(pegasus);
438 if (i < REG_TIMEOUT)
439 return 0;
440 if (netif_msg_drv(pegasus))
441 dev_warn(&pegasus->intf->dev, "fail %s\n", __FUNCTION__);
442 return -1;
443}
444#endif /* PEGASUS_WRITE_EEPROM */
445
446static inline void get_node_id(pegasus_t * pegasus, __u8 * id)
447{
448 int i;
449 __u16 w16;
450
451 for (i = 0; i < 3; i++) {
452 read_eprom_word(pegasus, i, &w16);
453 ((__le16 *) id)[i] = cpu_to_le16p(&w16);
454 }
455}
456
457static void set_ethernet_addr(pegasus_t * pegasus)
458{
459 __u8 node_id[6];
460 int ret;
461
462 get_node_id(pegasus, node_id);
463 ret = set_registers(pegasus, EthID, sizeof (node_id), node_id);
464 memcpy(pegasus->net->dev_addr, node_id, sizeof (node_id));
465}
466
467static inline int reset_mac(pegasus_t * pegasus)
468{
469 __u8 data = 0x8;
470 int i;
471 int ret;
472
473 ret = set_register(pegasus, EthCtrl1, data);
474 for (i = 0; i < REG_TIMEOUT; i++) {
475 ret = get_registers(pegasus, EthCtrl1, 1, &data);
476 if (~data & 0x08) {
477 if (loopback & 1)
478 break;
479 if (mii_mode && (pegasus->features & HAS_HOME_PNA))
480 ret = set_register(pegasus, Gpio1, 0x34);
481 else
482 ret = set_register(pegasus, Gpio1, 0x26);
483 ret = set_register(pegasus, Gpio0, pegasus->features);
484 ret = set_register(pegasus, Gpio0, DEFAULT_GPIO_SET);
485 break;
486 }
487 }
488 if (i == REG_TIMEOUT)
489 return 1;
490
491 if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS ||
492 usb_dev_id[pegasus->dev_index].vendor == VENDOR_DLINK) {
493 ret = set_register(pegasus, Gpio0, 0x24);
494 ret = set_register(pegasus, Gpio0, 0x26);
495 }
496 if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_ELCON) {
497 __u16 auxmode;
498 read_mii_word(pegasus, 3, 0x1b, &auxmode);
499 write_mii_word(pegasus, 3, 0x1b, auxmode | 4);
500 }
501
502 return 0;
503}
504
505static int enable_net_traffic(struct net_device *dev, struct usb_device *usb)
506{
507 __u16 linkpart;
508 __u8 data[4];
509 pegasus_t *pegasus = netdev_priv(dev);
510 int ret;
511
512 read_mii_word(pegasus, pegasus->phy, MII_LPA, &linkpart);
513 data[0] = 0xc9;
514 data[1] = 0;
515 if (linkpart & (ADVERTISE_100FULL | ADVERTISE_10FULL))
516 data[1] |= 0x20; /* set full duplex */
517 if (linkpart & (ADVERTISE_100FULL | ADVERTISE_100HALF))
518 data[1] |= 0x10; /* set 100 Mbps */
519 if (mii_mode)
520 data[1] = 0;
521 data[2] = (loopback & 1) ? 0x09 : 0x01;
522
523 memcpy(pegasus->eth_regs, data, sizeof (data));
524 ret = set_registers(pegasus, EthCtrl0, 3, data);
525
526 if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS ||
527 usb_dev_id[pegasus->dev_index].vendor == VENDOR_DLINK) {
528 u16 auxmode;
529 read_mii_word(pegasus, 0, 0x1b, &auxmode);
530 write_mii_word(pegasus, 0, 0x1b, auxmode | 4);
531 }
532
533 return 0;
534}
535
536static void fill_skb_pool(pegasus_t * pegasus)
537{
538 int i;
539
540 for (i = 0; i < RX_SKBS; i++) {
541 if (pegasus->rx_pool[i])
542 continue;
543 pegasus->rx_pool[i] = dev_alloc_skb(PEGASUS_MTU + 2);
544 /*
545 ** we give up if the allocation fail. the tasklet will be
546 ** rescheduled again anyway...
547 */
548 if (pegasus->rx_pool[i] == NULL)
549 return;
550 pegasus->rx_pool[i]->dev = pegasus->net;
551 skb_reserve(pegasus->rx_pool[i], 2);
552 }
553}
554
555static void free_skb_pool(pegasus_t * pegasus)
556{
557 int i;
558
559 for (i = 0; i < RX_SKBS; i++) {
560 if (pegasus->rx_pool[i]) {
561 dev_kfree_skb(pegasus->rx_pool[i]);
562 pegasus->rx_pool[i] = NULL;
563 }
564 }
565}
566
567static inline struct sk_buff *pull_skb(pegasus_t * pegasus)
568{
569 int i;
570 struct sk_buff *skb;
571
572 for (i = 0; i < RX_SKBS; i++) {
573 if (likely(pegasus->rx_pool[i] != NULL)) {
574 skb = pegasus->rx_pool[i];
575 pegasus->rx_pool[i] = NULL;
576 return skb;
577 }
578 }
579 return NULL;
580}
581
582static void read_bulk_callback(struct urb *urb, struct pt_regs *regs)
583{
584 pegasus_t *pegasus = urb->context;
585 struct net_device *net;
586 int rx_status, count = urb->actual_length;
587 u8 *buf = urb->transfer_buffer;
588 __u16 pkt_len;
589
590 if (!pegasus)
591 return;
592
593 net = pegasus->net;
594 if (!netif_device_present(net) || !netif_running(net))
595 return;
596
597 switch (urb->status) {
598 case 0:
599 break;
600 case -ETIMEDOUT:
601 if (netif_msg_rx_err(pegasus))
602 pr_debug("%s: reset MAC\n", net->name);
603 pegasus->flags &= ~PEGASUS_RX_BUSY;
604 break;
605 case -EPIPE: /* stall, or disconnect from TT */
606 /* FIXME schedule work to clear the halt */
607 if (netif_msg_rx_err(pegasus))
608 printk(KERN_WARNING "%s: no rx stall recovery\n",
609 net->name);
610 return;
611 case -ENOENT:
612 case -ECONNRESET:
613 case -ESHUTDOWN:
614 if (netif_msg_ifdown(pegasus))
615 pr_debug("%s: rx unlink, %d\n", net->name, urb->status);
616 return;
617 default:
618 if (netif_msg_rx_err(pegasus))
619 pr_debug("%s: RX status %d\n", net->name, urb->status);
620 goto goon;
621 }
622
623 if (!count || count < 4)
624 goto goon;
625
626 rx_status = buf[count - 2];
627 if (rx_status & 0x1e) {
628 if (netif_msg_rx_err(pegasus))
629 pr_debug("%s: RX packet error %x\n",
630 net->name, rx_status);
631 pegasus->stats.rx_errors++;
632 if (rx_status & 0x06) // long or runt
633 pegasus->stats.rx_length_errors++;
634 if (rx_status & 0x08)
635 pegasus->stats.rx_crc_errors++;
636 if (rx_status & 0x10) // extra bits
637 pegasus->stats.rx_frame_errors++;
638 goto goon;
639 }
640 if (pegasus->chip == 0x8513) {
641 pkt_len = le32_to_cpu(*(__le32 *)urb->transfer_buffer);
642 pkt_len &= 0x0fff;
643 pegasus->rx_skb->data += 2;
644 } else {
645 pkt_len = buf[count - 3] << 8;
646 pkt_len += buf[count - 4];
647 pkt_len &= 0xfff;
648 pkt_len -= 8;
649 }
650
651 /*
652 * at this point we are sure pegasus->rx_skb != NULL
653 * so we go ahead and pass up the packet.
654 */
655 skb_put(pegasus->rx_skb, pkt_len);
656 pegasus->rx_skb->protocol = eth_type_trans(pegasus->rx_skb, net);
657 netif_rx(pegasus->rx_skb);
658 pegasus->stats.rx_packets++;
659 pegasus->stats.rx_bytes += pkt_len;
660
661 if (pegasus->flags & PEGASUS_UNPLUG)
662 return;
663
664 spin_lock(&pegasus->rx_pool_lock);
665 pegasus->rx_skb = pull_skb(pegasus);
666 spin_unlock(&pegasus->rx_pool_lock);
667
668 if (pegasus->rx_skb == NULL)
669 goto tl_sched;
670goon:
671 usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb,
672 usb_rcvbulkpipe(pegasus->usb, 1),
673 pegasus->rx_skb->data, PEGASUS_MTU + 8,
674 read_bulk_callback, pegasus);
675 if (usb_submit_urb(pegasus->rx_urb, GFP_ATOMIC)) {
676 pegasus->flags |= PEGASUS_RX_URB_FAIL;
677 goto tl_sched;
678 } else {
679 pegasus->flags &= ~PEGASUS_RX_URB_FAIL;
680 }
681
682 return;
683
684tl_sched:
685 tasklet_schedule(&pegasus->rx_tl);
686}
687
688static void rx_fixup(unsigned long data)
689{
690 pegasus_t *pegasus;
691 unsigned long flags;
692
693 pegasus = (pegasus_t *) data;
694 if (pegasus->flags & PEGASUS_UNPLUG)
695 return;
696
697 spin_lock_irqsave(&pegasus->rx_pool_lock, flags);
698 fill_skb_pool(pegasus);
699 if (pegasus->flags & PEGASUS_RX_URB_FAIL)
700 if (pegasus->rx_skb)
701 goto try_again;
702 if (pegasus->rx_skb == NULL) {
703 pegasus->rx_skb = pull_skb(pegasus);
704 }
705 if (pegasus->rx_skb == NULL) {
706 if (netif_msg_rx_err(pegasus))
707 printk(KERN_WARNING "%s: low on memory\n",
708 pegasus->net->name);
709 tasklet_schedule(&pegasus->rx_tl);
710 goto done;
711 }
712 usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb,
713 usb_rcvbulkpipe(pegasus->usb, 1),
714 pegasus->rx_skb->data, PEGASUS_MTU + 8,
715 read_bulk_callback, pegasus);
716try_again:
717 if (usb_submit_urb(pegasus->rx_urb, GFP_ATOMIC)) {
718 pegasus->flags |= PEGASUS_RX_URB_FAIL;
719 tasklet_schedule(&pegasus->rx_tl);
720 } else {
721 pegasus->flags &= ~PEGASUS_RX_URB_FAIL;
722 }
723done:
724 spin_unlock_irqrestore(&pegasus->rx_pool_lock, flags);
725}
726
727static void write_bulk_callback(struct urb *urb, struct pt_regs *regs)
728{
729 pegasus_t *pegasus = urb->context;
730 struct net_device *net = pegasus->net;
731
732 if (!pegasus)
733 return;
734
735 if (!netif_device_present(net) || !netif_running(net))
736 return;
737
738 switch (urb->status) {
739 case -EPIPE:
740 /* FIXME schedule_work() to clear the tx halt */
741 netif_stop_queue(net);
742 if (netif_msg_tx_err(pegasus))
743 printk(KERN_WARNING "%s: no tx stall recovery\n",
744 net->name);
745 return;
746 case -ENOENT:
747 case -ECONNRESET:
748 case -ESHUTDOWN:
749 if (netif_msg_ifdown(pegasus))
750 pr_debug("%s: tx unlink, %d\n", net->name, urb->status);
751 return;
752 default:
753 if (netif_msg_tx_err(pegasus))
754 pr_info("%s: TX status %d\n", net->name, urb->status);
755 /* FALL THROUGH */
756 case 0:
757 break;
758 }
759
760 net->trans_start = jiffies;
761 netif_wake_queue(net);
762}
763
764static void intr_callback(struct urb *urb, struct pt_regs *regs)
765{
766 pegasus_t *pegasus = urb->context;
767 struct net_device *net;
768 int status;
769
770 if (!pegasus)
771 return;
772 net = pegasus->net;
773
774 switch (urb->status) {
775 case 0:
776 break;
777 case -ECONNRESET: /* unlink */
778 case -ENOENT:
779 case -ESHUTDOWN:
780 return;
781 default:
782 /* some Pegasus-I products report LOTS of data
783 * toggle errors... avoid log spamming
784 */
785 if (netif_msg_timer(pegasus))
786 pr_debug("%s: intr status %d\n", net->name,
787 urb->status);
788 }
789
790 if (urb->actual_length >= 6) {
791 u8 * d = urb->transfer_buffer;
792
793 /* byte 0 == tx_status1, reg 2B */
794 if (d[0] & (TX_UNDERRUN|EXCESSIVE_COL
795 |LATE_COL|JABBER_TIMEOUT)) {
796 pegasus->stats.tx_errors++;
797 if (d[0] & TX_UNDERRUN)
798 pegasus->stats.tx_fifo_errors++;
799 if (d[0] & (EXCESSIVE_COL | JABBER_TIMEOUT))
800 pegasus->stats.tx_aborted_errors++;
801 if (d[0] & LATE_COL)
802 pegasus->stats.tx_window_errors++;
803 }
804
805 /* d[5].LINK_STATUS lies on some adapters.
806 * d[0].NO_CARRIER kicks in only with failed TX.
807 * ... so monitoring with MII may be safest.
808 */
809 if (d[0] & NO_CARRIER)
810 netif_carrier_off(net);
811 else
812 netif_carrier_on(net);
813
814 /* bytes 3-4 == rx_lostpkt, reg 2E/2F */
815 pegasus->stats.rx_missed_errors += ((d[3] & 0x7f) << 8) | d[4];
816 }
817
818 status = usb_submit_urb(urb, SLAB_ATOMIC);
819 if (status && netif_msg_timer(pegasus))
820 printk(KERN_ERR "%s: can't resubmit interrupt urb, %d\n",
821 net->name, status);
822}
823
824static void pegasus_tx_timeout(struct net_device *net)
825{
826 pegasus_t *pegasus = netdev_priv(net);
827 if (netif_msg_timer(pegasus))
828 printk(KERN_WARNING "%s: tx timeout\n", net->name);
829 pegasus->tx_urb->transfer_flags |= URB_ASYNC_UNLINK;
830 usb_unlink_urb(pegasus->tx_urb);
831 pegasus->stats.tx_errors++;
832}
833
834static int pegasus_start_xmit(struct sk_buff *skb, struct net_device *net)
835{
836 pegasus_t *pegasus = netdev_priv(net);
837 int count = ((skb->len + 2) & 0x3f) ? skb->len + 2 : skb->len + 3;
838 int res;
839 __u16 l16 = skb->len;
840
841 netif_stop_queue(net);
842
843 ((__le16 *) pegasus->tx_buff)[0] = cpu_to_le16(l16);
844 memcpy(pegasus->tx_buff + 2, skb->data, skb->len);
845 usb_fill_bulk_urb(pegasus->tx_urb, pegasus->usb,
846 usb_sndbulkpipe(pegasus->usb, 2),
847 pegasus->tx_buff, count,
848 write_bulk_callback, pegasus);
849 if ((res = usb_submit_urb(pegasus->tx_urb, GFP_ATOMIC))) {
850 if (netif_msg_tx_err(pegasus))
851 printk(KERN_WARNING "%s: fail tx, %d\n",
852 net->name, res);
853 switch (res) {
854 case -EPIPE: /* stall, or disconnect from TT */
855 /* cleanup should already have been scheduled */
856 break;
857 case -ENODEV: /* disconnect() upcoming */
858 break;
859 default:
860 pegasus->stats.tx_errors++;
861 netif_start_queue(net);
862 }
863 } else {
864 pegasus->stats.tx_packets++;
865 pegasus->stats.tx_bytes += skb->len;
866 net->trans_start = jiffies;
867 }
868 dev_kfree_skb(skb);
869
870 return 0;
871}
872
873static struct net_device_stats *pegasus_netdev_stats(struct net_device *dev)
874{
875 return &((pegasus_t *) netdev_priv(dev))->stats;
876}
877
878static inline void disable_net_traffic(pegasus_t * pegasus)
879{
880 int tmp = 0;
881 int ret;
882
883 ret = set_registers(pegasus, EthCtrl0, 2, &tmp);
884}
885
886static inline void get_interrupt_interval(pegasus_t * pegasus)
887{
888 __u8 data[2];
889
890 read_eprom_word(pegasus, 4, (__u16 *) data);
891 if (data[1] < 0x80) {
892 if (netif_msg_timer(pegasus))
893 dev_info(&pegasus->intf->dev,
894 "intr interval changed from %ums to %ums\n",
895 data[1], 0x80);
896 data[1] = 0x80;
897#ifdef PEGASUS_WRITE_EEPROM
898 write_eprom_word(pegasus, 4, *(__u16 *) data);
899#endif
900 }
901 pegasus->intr_interval = data[1];
902}
903
904static void set_carrier(struct net_device *net)
905{
906 pegasus_t *pegasus = netdev_priv(net);
907 u16 tmp;
908
909 if (read_mii_word(pegasus, pegasus->phy, MII_BMSR, &tmp))
910 return;
911 if (tmp & BMSR_LSTATUS)
912 netif_carrier_on(net);
913 else
914 netif_carrier_off(net);
915}
916
917static void free_all_urbs(pegasus_t * pegasus)
918{
919 usb_free_urb(pegasus->intr_urb);
920 usb_free_urb(pegasus->tx_urb);
921 usb_free_urb(pegasus->rx_urb);
922 usb_free_urb(pegasus->ctrl_urb);
923}
924
925static void unlink_all_urbs(pegasus_t * pegasus)
926{
927 usb_kill_urb(pegasus->intr_urb);
928 usb_kill_urb(pegasus->tx_urb);
929 usb_kill_urb(pegasus->rx_urb);
930 usb_kill_urb(pegasus->ctrl_urb);
931}
932
933static int alloc_urbs(pegasus_t * pegasus)
934{
935 pegasus->ctrl_urb = usb_alloc_urb(0, GFP_KERNEL);
936 if (!pegasus->ctrl_urb) {
937 return 0;
938 }
939 pegasus->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
940 if (!pegasus->rx_urb) {
941 usb_free_urb(pegasus->ctrl_urb);
942 return 0;
943 }
944 pegasus->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
945 if (!pegasus->tx_urb) {
946 usb_free_urb(pegasus->rx_urb);
947 usb_free_urb(pegasus->ctrl_urb);
948 return 0;
949 }
950 pegasus->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
951 if (!pegasus->intr_urb) {
952 usb_free_urb(pegasus->tx_urb);
953 usb_free_urb(pegasus->rx_urb);
954 usb_free_urb(pegasus->ctrl_urb);
955 return 0;
956 }
957
958 return 1;
959}
960
961static int pegasus_open(struct net_device *net)
962{
963 pegasus_t *pegasus = netdev_priv(net);
964 int res;
965
966 if (pegasus->rx_skb == NULL)
967 pegasus->rx_skb = pull_skb(pegasus);
968 /*
969 ** Note: no point to free the pool. it is empty :-)
970 */
971 if (!pegasus->rx_skb)
972 return -ENOMEM;
973
974 res = set_registers(pegasus, EthID, 6, net->dev_addr);
975
976 usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb,
977 usb_rcvbulkpipe(pegasus->usb, 1),
978 pegasus->rx_skb->data, PEGASUS_MTU + 8,
979 read_bulk_callback, pegasus);
980 if ((res = usb_submit_urb(pegasus->rx_urb, GFP_KERNEL))) {
981 if (netif_msg_ifup(pegasus))
982 pr_debug("%s: failed rx_urb, %d", net->name, res);
983 goto exit;
984 }
985
986 usb_fill_int_urb(pegasus->intr_urb, pegasus->usb,
987 usb_rcvintpipe(pegasus->usb, 3),
988 pegasus->intr_buff, sizeof (pegasus->intr_buff),
989 intr_callback, pegasus, pegasus->intr_interval);
990 if ((res = usb_submit_urb(pegasus->intr_urb, GFP_KERNEL))) {
991 if (netif_msg_ifup(pegasus))
992 pr_debug("%s: failed intr_urb, %d\n", net->name, res);
993 usb_kill_urb(pegasus->rx_urb);
994 goto exit;
995 }
996 if ((res = enable_net_traffic(net, pegasus->usb))) {
997 if (netif_msg_ifup(pegasus))
998 pr_debug("%s: can't enable_net_traffic() - %d\n",
999 net->name, res);
1000 res = -EIO;
1001 usb_kill_urb(pegasus->rx_urb);
1002 usb_kill_urb(pegasus->intr_urb);
1003 free_skb_pool(pegasus);
1004 goto exit;
1005 }
1006 set_carrier(net);
1007 netif_start_queue(net);
1008 if (netif_msg_ifup(pegasus))
1009 pr_debug("%s: open\n", net->name);
1010 res = 0;
1011exit:
1012 return res;
1013}
1014
1015static int pegasus_close(struct net_device *net)
1016{
1017 pegasus_t *pegasus = netdev_priv(net);
1018
1019 netif_stop_queue(net);
1020 if (!(pegasus->flags & PEGASUS_UNPLUG))
1021 disable_net_traffic(pegasus);
1022 tasklet_kill(&pegasus->rx_tl);
1023 unlink_all_urbs(pegasus);
1024
1025 return 0;
1026}
1027
1028static void pegasus_get_drvinfo(struct net_device *dev,
1029 struct ethtool_drvinfo *info)
1030{
1031 pegasus_t *pegasus = netdev_priv(dev);
1032 strncpy(info->driver, driver_name, sizeof (info->driver) - 1);
1033 strncpy(info->version, DRIVER_VERSION, sizeof (info->version) - 1);
1034 usb_make_path(pegasus->usb, info->bus_info, sizeof (info->bus_info));
1035}
1036
1037/* also handles three patterns of some kind in hardware */
1038#define WOL_SUPPORTED (WAKE_MAGIC|WAKE_PHY)
1039
1040static void
1041pegasus_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
1042{
1043 pegasus_t *pegasus = netdev_priv(dev);
1044
1045 wol->supported = WAKE_MAGIC | WAKE_PHY;
1046 wol->wolopts = pegasus->wolopts;
1047}
1048
1049static int
1050pegasus_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
1051{
1052 pegasus_t *pegasus = netdev_priv(dev);
1053 u8 reg78 = 0x04;
1054
1055 if (wol->wolopts & ~WOL_SUPPORTED)
1056 return -EINVAL;
1057
1058 if (wol->wolopts & WAKE_MAGIC)
1059 reg78 |= 0x80;
1060 if (wol->wolopts & WAKE_PHY)
1061 reg78 |= 0x40;
1062 /* FIXME this 0x10 bit still needs to get set in the chip... */
1063 if (wol->wolopts)
1064 pegasus->eth_regs[0] |= 0x10;
1065 else
1066 pegasus->eth_regs[0] &= ~0x10;
1067 pegasus->wolopts = wol->wolopts;
1068 return set_register(pegasus, WakeupControl, reg78);
1069}
1070
1071static inline void pegasus_reset_wol(struct net_device *dev)
1072{
1073 struct ethtool_wolinfo wol;
1074
1075 memset(&wol, 0, sizeof wol);
1076 (void) pegasus_set_wol(dev, &wol);
1077}
1078
1079static int
1080pegasus_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
1081{
1082 pegasus_t *pegasus;
1083
1084 if (in_atomic())
1085 return 0;
1086
1087 pegasus = netdev_priv(dev);
1088 mii_ethtool_gset(&pegasus->mii, ecmd);
1089
1090 return 0;
1091}
1092
1093static int
1094pegasus_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
1095{
1096 pegasus_t *pegasus = netdev_priv(dev);
1097 return mii_ethtool_sset(&pegasus->mii, ecmd);
1098}
1099
1100static int pegasus_nway_reset(struct net_device *dev)
1101{
1102 pegasus_t *pegasus = netdev_priv(dev);
1103 return mii_nway_restart(&pegasus->mii);
1104}
1105
1106static u32 pegasus_get_link(struct net_device *dev)
1107{
1108 pegasus_t *pegasus = netdev_priv(dev);
1109 return mii_link_ok(&pegasus->mii);
1110}
1111
1112static u32 pegasus_get_msglevel(struct net_device *dev)
1113{
1114 pegasus_t *pegasus = netdev_priv(dev);
1115 return pegasus->msg_enable;
1116}
1117
1118static void pegasus_set_msglevel(struct net_device *dev, u32 v)
1119{
1120 pegasus_t *pegasus = netdev_priv(dev);
1121 pegasus->msg_enable = v;
1122}
1123
1124static struct ethtool_ops ops = {
1125 .get_drvinfo = pegasus_get_drvinfo,
1126 .get_settings = pegasus_get_settings,
1127 .set_settings = pegasus_set_settings,
1128 .nway_reset = pegasus_nway_reset,
1129 .get_link = pegasus_get_link,
1130 .get_msglevel = pegasus_get_msglevel,
1131 .set_msglevel = pegasus_set_msglevel,
1132 .get_wol = pegasus_get_wol,
1133 .set_wol = pegasus_set_wol,
1134};
1135
1136static int pegasus_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
1137{
1138 __u16 *data = (__u16 *) & rq->ifr_ifru;
1139 pegasus_t *pegasus = netdev_priv(net);
1140 int res;
1141
1142 switch (cmd) {
1143 case SIOCDEVPRIVATE:
1144 data[0] = pegasus->phy;
1145 case SIOCDEVPRIVATE + 1:
1146 read_mii_word(pegasus, data[0], data[1] & 0x1f, &data[3]);
1147 res = 0;
1148 break;
1149 case SIOCDEVPRIVATE + 2:
1150 if (!capable(CAP_NET_ADMIN))
1151 return -EPERM;
1152 write_mii_word(pegasus, pegasus->phy, data[1] & 0x1f, data[2]);
1153 res = 0;
1154 break;
1155 default:
1156 res = -EOPNOTSUPP;
1157 }
1158 return res;
1159}
1160
1161static void pegasus_set_multicast(struct net_device *net)
1162{
1163 pegasus_t *pegasus = netdev_priv(net);
1164
1165 if (net->flags & IFF_PROMISC) {
1166 pegasus->eth_regs[EthCtrl2] |= RX_PROMISCUOUS;
1167 if (netif_msg_link(pegasus))
1168 pr_info("%s: Promiscuous mode enabled.\n", net->name);
1169 } else if ((net->mc_count > multicast_filter_limit) ||
1170 (net->flags & IFF_ALLMULTI)) {
1171 pegasus->eth_regs[EthCtrl0] |= RX_MULTICAST;
1172 pegasus->eth_regs[EthCtrl2] &= ~RX_PROMISCUOUS;
1173 if (netif_msg_link(pegasus))
1174 pr_info("%s: set allmulti\n", net->name);
1175 } else {
1176 pegasus->eth_regs[EthCtrl0] &= ~RX_MULTICAST;
1177 pegasus->eth_regs[EthCtrl2] &= ~RX_PROMISCUOUS;
1178 }
1179
1180 pegasus->flags |= ETH_REGS_CHANGE;
1181 ctrl_callback(pegasus->ctrl_urb, NULL);
1182}
1183
1184static __u8 mii_phy_probe(pegasus_t * pegasus)
1185{
1186 int i;
1187 __u16 tmp;
1188
1189 for (i = 0; i < 32; i++) {
1190 read_mii_word(pegasus, i, MII_BMSR, &tmp);
1191 if (tmp == 0 || tmp == 0xffff || (tmp & BMSR_MEDIA) == 0)
1192 continue;
1193 else
1194 return i;
1195 }
1196
1197 return 0xff;
1198}
1199
1200static inline void setup_pegasus_II(pegasus_t * pegasus)
1201{
1202 __u8 data = 0xa5;
1203 int ret;
1204
1205 ret = set_register(pegasus, Reg1d, 0);
1206 ret = set_register(pegasus, Reg7b, 1);
1207 mdelay(100);
1208 if ((pegasus->features & HAS_HOME_PNA) && mii_mode)
1209 ret = set_register(pegasus, Reg7b, 0);
1210 else
1211 ret = set_register(pegasus, Reg7b, 2);
1212
1213 ret = set_register(pegasus, 0x83, data);
1214 ret = get_registers(pegasus, 0x83, 1, &data);
1215
1216 if (data == 0xa5) {
1217 pegasus->chip = 0x8513;
1218 } else {
1219 pegasus->chip = 0;
1220 }
1221
1222 ret = set_register(pegasus, 0x80, 0xc0);
1223 ret = set_register(pegasus, 0x83, 0xff);
1224 ret = set_register(pegasus, 0x84, 0x01);
1225
1226 if (pegasus->features & HAS_HOME_PNA && mii_mode)
1227 ret = set_register(pegasus, Reg81, 6);
1228 else
1229 ret = set_register(pegasus, Reg81, 2);
1230}
1231
1232
1233static struct workqueue_struct *pegasus_workqueue = NULL;
1234#define CARRIER_CHECK_DELAY (2 * HZ)
1235
1236static void check_carrier(void *data)
1237{
1238 pegasus_t *pegasus = data;
1239 set_carrier(pegasus->net);
1240 if (!(pegasus->flags & PEGASUS_UNPLUG)) {
1241 queue_delayed_work(pegasus_workqueue, &pegasus->carrier_check,
1242 CARRIER_CHECK_DELAY);
1243 }
1244}
1245
1246static int pegasus_probe(struct usb_interface *intf,
1247 const struct usb_device_id *id)
1248{
1249 struct usb_device *dev = interface_to_usbdev(intf);
1250 struct net_device *net;
1251 pegasus_t *pegasus;
1252 int dev_index = id - pegasus_ids;
1253 int res = -ENOMEM;
1254
1255 usb_get_dev(dev);
1256 net = alloc_etherdev(sizeof(struct pegasus));
1257 if (!net) {
1258 dev_err(&intf->dev, "can't allocate %s\n", "device");
1259 goto out;
1260 }
1261
1262 pegasus = netdev_priv(net);
1263 memset(pegasus, 0, sizeof (struct pegasus));
1264 pegasus->dev_index = dev_index;
1265 init_waitqueue_head(&pegasus->ctrl_wait);
1266
1267 if (!alloc_urbs(pegasus)) {
1268 dev_err(&intf->dev, "can't allocate %s\n", "urbs");
1269 goto out1;
1270 }
1271
1272 tasklet_init(&pegasus->rx_tl, rx_fixup, (unsigned long) pegasus);
1273
1274 INIT_WORK(&pegasus->carrier_check, check_carrier, pegasus);
1275
1276 pegasus->intf = intf;
1277 pegasus->usb = dev;
1278 pegasus->net = net;
1279 SET_MODULE_OWNER(net);
1280 net->open = pegasus_open;
1281 net->stop = pegasus_close;
1282 net->watchdog_timeo = PEGASUS_TX_TIMEOUT;
1283 net->tx_timeout = pegasus_tx_timeout;
1284 net->do_ioctl = pegasus_ioctl;
1285 net->hard_start_xmit = pegasus_start_xmit;
1286 net->set_multicast_list = pegasus_set_multicast;
1287 net->get_stats = pegasus_netdev_stats;
1288 SET_ETHTOOL_OPS(net, &ops);
1289 pegasus->mii.dev = net;
1290 pegasus->mii.mdio_read = mdio_read;
1291 pegasus->mii.mdio_write = mdio_write;
1292 pegasus->mii.phy_id_mask = 0x1f;
1293 pegasus->mii.reg_num_mask = 0x1f;
1294 spin_lock_init(&pegasus->rx_pool_lock);
1295 pegasus->msg_enable = netif_msg_init (msg_level, NETIF_MSG_DRV
1296 | NETIF_MSG_PROBE | NETIF_MSG_LINK);
1297
1298 pegasus->features = usb_dev_id[dev_index].private;
1299 get_interrupt_interval(pegasus);
1300 if (reset_mac(pegasus)) {
1301 dev_err(&intf->dev, "can't reset MAC\n");
1302 res = -EIO;
1303 goto out2;
1304 }
1305 set_ethernet_addr(pegasus);
1306 fill_skb_pool(pegasus);
1307 if (pegasus->features & PEGASUS_II) {
1308 dev_info(&intf->dev, "setup Pegasus II specific registers\n");
1309 setup_pegasus_II(pegasus);
1310 }
1311 pegasus->phy = mii_phy_probe(pegasus);
1312 if (pegasus->phy == 0xff) {
1313 dev_warn(&intf->dev, "can't locate MII phy, using default\n");
1314 pegasus->phy = 1;
1315 }
1316 pegasus->mii.phy_id = pegasus->phy;
1317 usb_set_intfdata(intf, pegasus);
1318 SET_NETDEV_DEV(net, &intf->dev);
1319 pegasus_reset_wol(net);
1320 res = register_netdev(net);
1321 if (res)
1322 goto out3;
1323 queue_delayed_work(pegasus_workqueue, &pegasus->carrier_check,
1324 CARRIER_CHECK_DELAY);
1325
1326 dev_info(&intf->dev, "%s, %s, %02x:%02x:%02x:%02x:%02x:%02x\n",
1327 net->name,
1328 usb_dev_id[dev_index].name,
1329 net->dev_addr [0], net->dev_addr [1],
1330 net->dev_addr [2], net->dev_addr [3],
1331 net->dev_addr [4], net->dev_addr [5]);
1332 return 0;
1333
1334out3:
1335 usb_set_intfdata(intf, NULL);
1336 free_skb_pool(pegasus);
1337out2:
1338 free_all_urbs(pegasus);
1339out1:
1340 free_netdev(net);
1341out:
1342 usb_put_dev(dev);
1343 return res;
1344}
1345
1346static void pegasus_disconnect(struct usb_interface *intf)
1347{
1348 struct pegasus *pegasus = usb_get_intfdata(intf);
1349
1350 usb_set_intfdata(intf, NULL);
1351 if (!pegasus) {
1352 dev_dbg(&intf->dev, "unregistering non-bound device?\n");
1353 return;
1354 }
1355
1356 pegasus->flags |= PEGASUS_UNPLUG;
1357 cancel_delayed_work(&pegasus->carrier_check);
1358 unregister_netdev(pegasus->net);
1359 usb_put_dev(interface_to_usbdev(intf));
1360 free_all_urbs(pegasus);
1361 free_skb_pool(pegasus);
1362 if (pegasus->rx_skb)
1363 dev_kfree_skb(pegasus->rx_skb);
1364 free_netdev(pegasus->net);
1365}
1366
1367static int pegasus_suspend (struct usb_interface *intf, pm_message_t state)
1368{
1369 struct pegasus *pegasus = usb_get_intfdata(intf);
1370
1371 netif_device_detach (pegasus->net);
1372 return 0;
1373}
1374
1375static int pegasus_resume (struct usb_interface *intf)
1376{
1377 struct pegasus *pegasus = usb_get_intfdata(intf);
1378
1379 netif_device_attach (pegasus->net);
1380 return 0;
1381}
1382
1383static struct usb_driver pegasus_driver = {
1384 .name = driver_name,
1385 .probe = pegasus_probe,
1386 .disconnect = pegasus_disconnect,
1387 .id_table = pegasus_ids,
1388 .suspend = pegasus_suspend,
1389 .resume = pegasus_resume,
1390};
1391
1392static int __init pegasus_init(void)
1393{
1394 pr_info("%s: %s, " DRIVER_DESC "\n", driver_name, DRIVER_VERSION);
1395 pegasus_workqueue = create_singlethread_workqueue("pegasus");
1396 if (!pegasus_workqueue)
1397 return -ENOMEM;
1398 return usb_register(&pegasus_driver);
1399}
1400
1401static void __exit pegasus_exit(void)
1402{
1403 destroy_workqueue(pegasus_workqueue);
1404 usb_deregister(&pegasus_driver);
1405}
1406
1407module_init(pegasus_init);
1408module_exit(pegasus_exit);
diff --git a/drivers/usb/net/pegasus.h b/drivers/usb/net/pegasus.h
new file mode 100644
index 000000000000..13ccedef5c7e
--- /dev/null
+++ b/drivers/usb/net/pegasus.h
@@ -0,0 +1,298 @@
1/*
2 * Copyright (c) 1999-2003 Petko Manolov - Petkan (petkan@users.sourceforge.net)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as published
6 * by the Free Software Foundation.
7 */
8
9
10#ifndef PEGASUS_DEV
11
12#define PEGASUS_II 0x80000000
13#define HAS_HOME_PNA 0x40000000
14
15#define PEGASUS_MTU 1536
16#define RX_SKBS 4
17
18#define EPROM_WRITE 0x01
19#define EPROM_READ 0x02
20#define EPROM_DONE 0x04
21#define EPROM_WR_ENABLE 0x10
22#define EPROM_LOAD 0x20
23
24#define PHY_DONE 0x80
25#define PHY_READ 0x40
26#define PHY_WRITE 0x20
27#define DEFAULT_GPIO_RESET 0x24
28#define LINKSYS_GPIO_RESET 0x24
29#define DEFAULT_GPIO_SET 0x26
30
31#define PEGASUS_PRESENT 0x00000001
32#define PEGASUS_TX_BUSY 0x00000004
33#define PEGASUS_RX_BUSY 0x00000008
34#define CTRL_URB_RUNNING 0x00000010
35#define CTRL_URB_SLEEP 0x00000020
36#define PEGASUS_UNPLUG 0x00000040
37#define PEGASUS_RX_URB_FAIL 0x00000080
38#define ETH_REGS_CHANGE 0x40000000
39#define ETH_REGS_CHANGED 0x80000000
40
41#define RX_MULTICAST 2
42#define RX_PROMISCUOUS 4
43
44#define REG_TIMEOUT (HZ)
45#define PEGASUS_TX_TIMEOUT (HZ*10)
46
47#define TX_UNDERRUN 0x80
48#define EXCESSIVE_COL 0x40
49#define LATE_COL 0x20
50#define NO_CARRIER 0x10
51#define LOSS_CARRIER 0x08
52#define JABBER_TIMEOUT 0x04
53
54#define LINK_STATUS 0x01
55
56#define PEGASUS_REQT_READ 0xc0
57#define PEGASUS_REQT_WRITE 0x40
58#define PEGASUS_REQ_GET_REGS 0xf0
59#define PEGASUS_REQ_SET_REGS 0xf1
60#define PEGASUS_REQ_SET_REG PEGASUS_REQ_SET_REGS
61
62enum pegasus_registers {
63 EthCtrl0 = 0,
64 EthCtrl1 = 1,
65 EthCtrl2 = 2,
66 EthID = 0x10,
67 Reg1d = 0x1d,
68 EpromOffset = 0x20,
69 EpromData = 0x21, /* 0x21 low, 0x22 high byte */
70 EpromCtrl = 0x23,
71 PhyAddr = 0x25,
72 PhyData = 0x26, /* 0x26 low, 0x27 high byte */
73 PhyCtrl = 0x28,
74 UsbStst = 0x2a,
75 EthTxStat0 = 0x2b,
76 EthTxStat1 = 0x2c,
77 EthRxStat = 0x2d,
78 WakeupControl = 0x78,
79 Reg7b = 0x7b,
80 Gpio0 = 0x7e,
81 Gpio1 = 0x7f,
82 Reg81 = 0x81,
83};
84
85
86typedef struct pegasus {
87 struct usb_device *usb;
88 struct usb_interface *intf;
89 struct net_device *net;
90 struct net_device_stats stats;
91 struct mii_if_info mii;
92 unsigned flags;
93 unsigned features;
94 u32 msg_enable;
95 u32 wolopts;
96 int dev_index;
97 int intr_interval;
98 struct tasklet_struct rx_tl;
99 struct work_struct carrier_check;
100 struct urb *ctrl_urb, *rx_urb, *tx_urb, *intr_urb;
101 struct sk_buff *rx_pool[RX_SKBS];
102 struct sk_buff *rx_skb;
103 struct usb_ctrlrequest dr;
104 wait_queue_head_t ctrl_wait;
105 spinlock_t rx_pool_lock;
106 int chip;
107 unsigned char intr_buff[8];
108 __u8 tx_buff[PEGASUS_MTU];
109 __u8 eth_regs[4];
110 __u8 phy;
111 __u8 gpio_res;
112} pegasus_t;
113
114
115struct usb_eth_dev {
116 char *name;
117 __u16 vendor;
118 __u16 device;
119 __u32 private; /* LSB is gpio reset value */
120};
121
122#define VENDOR_3COM 0x0506
123#define VENDOR_ABOCOM 0x07b8
124#define VENDOR_ACCTON 0x083a
125#define VENDOR_ADMTEK 0x07a6
126#define VENDOR_AEILAB 0x3334
127#define VENDOR_ALLIEDTEL 0x07c9
128#define VENDOR_ATEN 0x0557
129#define VENDOR_BELKIN 0x050d
130#define VENDOR_BILLIONTON 0x08dd
131#define VENDOR_COMPAQ 0x049f
132#define VENDOR_COREGA 0x07aa
133#define VENDOR_DLINK 0x2001
134#define VENDOR_ELCON 0x0db7
135#define VENDOR_ELSA 0x05cc
136#define VENDOR_GIGABYTE 0x1044
137#define VENDOR_HAWKING 0x0e66
138#define VENDOR_HP 0x03f0
139#define VENDOR_IODATA 0x04bb
140#define VENDOR_KINGSTON 0x0951
141#define VENDOR_LANEED 0x056e
142#define VENDOR_LINKSYS 0x066b
143#define VENDOR_MELCO 0x0411
144#define VENDOR_MICROSOFT 0x045e
145#define VENDOR_MOBILITY 0x1342
146#define VENDOR_NETGEAR 0x0846
147#define VENDOR_OCT 0x0b39
148#define VENDOR_SMARTBRIDGES 0x08d1
149#define VENDOR_SMC 0x0707
150#define VENDOR_SOHOWARE 0x15e8
151#define VENDOR_SIEMENS 0x067c
152
153
154#else /* PEGASUS_DEV */
155
156PEGASUS_DEV( "3Com USB Ethernet 3C460B", VENDOR_3COM, 0x4601,
157 DEFAULT_GPIO_RESET | PEGASUS_II )
158PEGASUS_DEV( "ATEN USB Ethernet UC-110T", VENDOR_ATEN, 0x2007,
159 DEFAULT_GPIO_RESET | PEGASUS_II )
160PEGASUS_DEV( "USB HPNA/Ethernet", VENDOR_ABOCOM, 0x110c,
161 DEFAULT_GPIO_RESET | PEGASUS_II | HAS_HOME_PNA )
162PEGASUS_DEV( "USB HPNA/Ethernet", VENDOR_ABOCOM, 0x4104,
163 DEFAULT_GPIO_RESET | HAS_HOME_PNA )
164PEGASUS_DEV( "USB HPNA/Ethernet", VENDOR_ABOCOM, 0x4004,
165 DEFAULT_GPIO_RESET | HAS_HOME_PNA )
166PEGASUS_DEV( "USB HPNA/Ethernet", VENDOR_ABOCOM, 0x4007,
167 DEFAULT_GPIO_RESET | HAS_HOME_PNA )
168PEGASUS_DEV( "USB 10/100 Fast Ethernet", VENDOR_ABOCOM, 0x4102,
169 DEFAULT_GPIO_RESET | PEGASUS_II )
170PEGASUS_DEV( "USB 10/100 Fast Ethernet", VENDOR_ABOCOM, 0x4002,
171 DEFAULT_GPIO_RESET )
172PEGASUS_DEV( "USB 10/100 Fast Ethernet", VENDOR_ABOCOM, 0x400b,
173 DEFAULT_GPIO_RESET | PEGASUS_II )
174PEGASUS_DEV( "USB 10/100 Fast Ethernet", VENDOR_ABOCOM, 0x400c,
175 DEFAULT_GPIO_RESET | PEGASUS_II )
176PEGASUS_DEV( "USB 10/100 Fast Ethernet", VENDOR_ABOCOM, 0xabc1,
177 DEFAULT_GPIO_RESET )
178PEGASUS_DEV( "USB 10/100 Fast Ethernet", VENDOR_ABOCOM, 0x200c,
179 DEFAULT_GPIO_RESET | PEGASUS_II )
180PEGASUS_DEV( "Accton USB 10/100 Ethernet Adapter", VENDOR_ACCTON, 0x1046,
181 DEFAULT_GPIO_RESET )
182PEGASUS_DEV( "SpeedStream USB 10/100 Ethernet", VENDOR_ACCTON, 0x5046,
183 DEFAULT_GPIO_RESET | PEGASUS_II )
184PEGASUS_DEV( "ADMtek ADM8511 \"Pegasus II\" USB Ethernet",
185 VENDOR_ADMTEK, 0x8511,
186 DEFAULT_GPIO_RESET | PEGASUS_II | HAS_HOME_PNA )
187PEGASUS_DEV( "ADMtek ADM8513 \"Pegasus II\" USB Ethernet",
188 VENDOR_ADMTEK, 0x8513,
189 DEFAULT_GPIO_RESET | PEGASUS_II )
190PEGASUS_DEV( "ADMtek ADM8515 \"Pegasus II\" USB-2.0 Ethernet",
191 VENDOR_ADMTEK, 0x8515,
192 DEFAULT_GPIO_RESET | PEGASUS_II )
193PEGASUS_DEV( "ADMtek AN986 \"Pegasus\" USB Ethernet (evaluation board)",
194 VENDOR_ADMTEK, 0x0986,
195 DEFAULT_GPIO_RESET | HAS_HOME_PNA )
196PEGASUS_DEV( "AN986A USB MAC", VENDOR_ADMTEK, 1986,
197 DEFAULT_GPIO_RESET | PEGASUS_II )
198PEGASUS_DEV( "AEI USB Fast Ethernet Adapter", VENDOR_AEILAB, 0x1701,
199 DEFAULT_GPIO_RESET | PEGASUS_II )
200PEGASUS_DEV( "Allied Telesyn Int. AT-USB100", VENDOR_ALLIEDTEL, 0xb100,
201 DEFAULT_GPIO_RESET | PEGASUS_II )
202PEGASUS_DEV( "Belkin F5D5050 USB Ethernet", VENDOR_BELKIN, 0x0121,
203 DEFAULT_GPIO_RESET | PEGASUS_II )
204PEGASUS_DEV( "Billionton USB-100", VENDOR_BILLIONTON, 0x0986,
205 DEFAULT_GPIO_RESET )
206PEGASUS_DEV( "Billionton USBLP-100", VENDOR_BILLIONTON, 0x0987,
207 DEFAULT_GPIO_RESET | HAS_HOME_PNA )
208PEGASUS_DEV( "iPAQ Networking 10/100 USB", VENDOR_COMPAQ, 0x8511,
209 DEFAULT_GPIO_RESET | PEGASUS_II )
210PEGASUS_DEV( "Billionton USBEL-100", VENDOR_BILLIONTON, 0x0988,
211 DEFAULT_GPIO_RESET )
212PEGASUS_DEV( "Billionton USBE-100", VENDOR_BILLIONTON, 0x8511,
213 DEFAULT_GPIO_RESET | PEGASUS_II )
214PEGASUS_DEV( "Corega FEter USB-TX", VENDOR_COREGA, 0x0004,
215 DEFAULT_GPIO_RESET )
216PEGASUS_DEV( "Corega FEter USB-TXS", VENDOR_COREGA, 0x000d,
217 DEFAULT_GPIO_RESET | PEGASUS_II )
218PEGASUS_DEV( "D-Link DSB-650TX", VENDOR_DLINK, 0x4001,
219 LINKSYS_GPIO_RESET )
220PEGASUS_DEV( "D-Link DSB-650TX", VENDOR_DLINK, 0x4002,
221 LINKSYS_GPIO_RESET )
222PEGASUS_DEV( "D-Link DSB-650TX", VENDOR_DLINK, 0x4102,
223 LINKSYS_GPIO_RESET | PEGASUS_II )
224PEGASUS_DEV( "D-Link DSB-650TX", VENDOR_DLINK, 0x400b,
225 LINKSYS_GPIO_RESET | PEGASUS_II )
226PEGASUS_DEV( "D-Link DSB-650TX", VENDOR_DLINK, 0x200c,
227 LINKSYS_GPIO_RESET | PEGASUS_II )
228PEGASUS_DEV( "D-Link DSB-650TX(PNA)", VENDOR_DLINK, 0x4003,
229 DEFAULT_GPIO_RESET | HAS_HOME_PNA )
230PEGASUS_DEV( "D-Link DSB-650", VENDOR_DLINK, 0xabc1,
231 DEFAULT_GPIO_RESET )
232PEGASUS_DEV( "GOLDPFEIL USB Adapter", VENDOR_ELCON, 0x0002,
233 DEFAULT_GPIO_RESET | PEGASUS_II | HAS_HOME_PNA )
234PEGASUS_DEV( "EasiDock Ethernet", VENDOR_MOBILITY, 0x0304,
235 DEFAULT_GPIO_RESET )
236PEGASUS_DEV( "Elsa Micolink USB2Ethernet", VENDOR_ELSA, 0x3000,
237 DEFAULT_GPIO_RESET )
238PEGASUS_DEV( "GIGABYTE GN-BR402W Wireless Router", VENDOR_GIGABYTE, 0x8002,
239 DEFAULT_GPIO_RESET )
240PEGASUS_DEV( "Hawking UF100 10/100 Ethernet", VENDOR_HAWKING, 0x400c,
241 DEFAULT_GPIO_RESET | PEGASUS_II )
242PEGASUS_DEV( "HP hn210c Ethernet USB", VENDOR_HP, 0x811c,
243 DEFAULT_GPIO_RESET | PEGASUS_II )
244PEGASUS_DEV( "IO DATA USB ET/TX", VENDOR_IODATA, 0x0904,
245 DEFAULT_GPIO_RESET )
246PEGASUS_DEV( "IO DATA USB ET/TX-S", VENDOR_IODATA, 0x0913,
247 DEFAULT_GPIO_RESET | PEGASUS_II )
248PEGASUS_DEV( "Kingston KNU101TX Ethernet", VENDOR_KINGSTON, 0x000a,
249 DEFAULT_GPIO_RESET)
250PEGASUS_DEV( "LANEED USB Ethernet LD-USB/TX", VENDOR_LANEED, 0x4002,
251 DEFAULT_GPIO_RESET )
252PEGASUS_DEV( "LANEED USB Ethernet LD-USB/TX", VENDOR_LANEED, 0x400b,
253 DEFAULT_GPIO_RESET | PEGASUS_II )
254PEGASUS_DEV( "LANEED USB Ethernet LD-USB/T", VENDOR_LANEED, 0xabc1,
255 DEFAULT_GPIO_RESET )
256PEGASUS_DEV( "LANEED USB Ethernet LD-USB/TX", VENDOR_LANEED, 0x200c,
257 DEFAULT_GPIO_RESET | PEGASUS_II )
258PEGASUS_DEV( "Linksys USB10TX", VENDOR_LINKSYS, 0x2202,
259 LINKSYS_GPIO_RESET )
260PEGASUS_DEV( "Linksys USB100TX", VENDOR_LINKSYS, 0x2203,
261 LINKSYS_GPIO_RESET )
262PEGASUS_DEV( "Linksys USB100TX", VENDOR_LINKSYS, 0x2204,
263 LINKSYS_GPIO_RESET | HAS_HOME_PNA )
264PEGASUS_DEV( "Linksys USB10T Ethernet Adapter", VENDOR_LINKSYS, 0x2206,
265 LINKSYS_GPIO_RESET | PEGASUS_II)
266PEGASUS_DEV( "Linksys USB USB100TX", VENDOR_LINKSYS, 0x400b,
267 LINKSYS_GPIO_RESET | PEGASUS_II )
268PEGASUS_DEV( "Linksys USB10TX", VENDOR_LINKSYS, 0x200c,
269 LINKSYS_GPIO_RESET | PEGASUS_II )
270PEGASUS_DEV( "MELCO/BUFFALO LUA-TX", VENDOR_MELCO, 0x0001,
271 DEFAULT_GPIO_RESET )
272PEGASUS_DEV( "MELCO/BUFFALO LUA-TX", VENDOR_MELCO, 0x0005,
273 DEFAULT_GPIO_RESET )
274PEGASUS_DEV( "MELCO/BUFFALO LUA2-TX", VENDOR_MELCO, 0x0009,
275 DEFAULT_GPIO_RESET | PEGASUS_II )
276PEGASUS_DEV( "Microsoft MN-110", VENDOR_MICROSOFT, 0x007a,
277 DEFAULT_GPIO_RESET | PEGASUS_II )
278PEGASUS_DEV( "NETGEAR FA101", VENDOR_NETGEAR, 0x1020,
279 DEFAULT_GPIO_RESET | PEGASUS_II )
280PEGASUS_DEV( "OCT Inc.", VENDOR_OCT, 0x0109,
281 DEFAULT_GPIO_RESET | PEGASUS_II )
282PEGASUS_DEV( "OCT USB TO Ethernet", VENDOR_OCT, 0x0901,
283 DEFAULT_GPIO_RESET | PEGASUS_II )
284PEGASUS_DEV( "smartNIC 2 PnP Adapter", VENDOR_SMARTBRIDGES, 0x0003,
285 DEFAULT_GPIO_RESET | PEGASUS_II )
286PEGASUS_DEV( "SMC 202 USB Ethernet", VENDOR_SMC, 0x0200,
287 DEFAULT_GPIO_RESET )
288PEGASUS_DEV( "SMC 2206 USB Ethernet", VENDOR_SMC, 0x0201,
289 DEFAULT_GPIO_RESET | PEGASUS_II)
290PEGASUS_DEV( "SOHOware NUB100 Ethernet", VENDOR_SOHOWARE, 0x9100,
291 DEFAULT_GPIO_RESET )
292PEGASUS_DEV( "SOHOware NUB110 Ethernet", VENDOR_SOHOWARE, 0x9110,
293 DEFAULT_GPIO_RESET | PEGASUS_II )
294PEGASUS_DEV( "SpeedStream USB 10/100 Ethernet", VENDOR_SIEMENS, 0x1001,
295 DEFAULT_GPIO_RESET | PEGASUS_II )
296
297
298#endif /* PEGASUS_DEV */
diff --git a/drivers/usb/net/rtl8150.c b/drivers/usb/net/rtl8150.c
new file mode 100644
index 000000000000..8fb223385f2f
--- /dev/null
+++ b/drivers/usb/net/rtl8150.c
@@ -0,0 +1,942 @@
1/*
2 * Copyright (c) 2002 Petko Manolov (petkan@users.sourceforge.net)
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * version 2 as published by the Free Software Foundation.
7 */
8
9#include <linux/config.h>
10#include <linux/sched.h>
11#include <linux/init.h>
12#include <linux/signal.h>
13#include <linux/slab.h>
14#include <linux/module.h>
15#include <linux/netdevice.h>
16#include <linux/etherdevice.h>
17#include <linux/mii.h>
18#include <linux/ethtool.h>
19#include <linux/usb.h>
20#include <asm/uaccess.h>
21
22/* Version Information */
23#define DRIVER_VERSION "v0.6.2 (2004/08/27)"
24#define DRIVER_AUTHOR "Petko Manolov <petkan@users.sourceforge.net>"
25#define DRIVER_DESC "rtl8150 based usb-ethernet driver"
26
27#define IDR 0x0120
28#define MAR 0x0126
29#define CR 0x012e
30#define TCR 0x012f
31#define RCR 0x0130
32#define TSR 0x0132
33#define RSR 0x0133
34#define CON0 0x0135
35#define CON1 0x0136
36#define MSR 0x0137
37#define PHYADD 0x0138
38#define PHYDAT 0x0139
39#define PHYCNT 0x013b
40#define GPPC 0x013d
41#define BMCR 0x0140
42#define BMSR 0x0142
43#define ANAR 0x0144
44#define ANLP 0x0146
45#define AER 0x0148
46#define CSCR 0x014C /* This one has the link status */
47#define CSCR_LINK_STATUS (1 << 3)
48
49#define IDR_EEPROM 0x1202
50
51#define PHY_READ 0
52#define PHY_WRITE 0x20
53#define PHY_GO 0x40
54
55#define MII_TIMEOUT 10
56#define INTBUFSIZE 8
57
58#define RTL8150_REQT_READ 0xc0
59#define RTL8150_REQT_WRITE 0x40
60#define RTL8150_REQ_GET_REGS 0x05
61#define RTL8150_REQ_SET_REGS 0x05
62
63
64/* Transmit status register errors */
65#define TSR_ECOL (1<<5)
66#define TSR_LCOL (1<<4)
67#define TSR_LOSS_CRS (1<<3)
68#define TSR_JBR (1<<2)
69#define TSR_ERRORS (TSR_ECOL | TSR_LCOL | TSR_LOSS_CRS | TSR_JBR)
70/* Receive status register errors */
71#define RSR_CRC (1<<2)
72#define RSR_FAE (1<<1)
73#define RSR_ERRORS (RSR_CRC | RSR_FAE)
74
75/* Media status register definitions */
76#define MSR_DUPLEX (1<<4)
77#define MSR_SPEED (1<<3)
78#define MSR_LINK (1<<2)
79
80/* Interrupt pipe data */
81#define INT_TSR 0x00
82#define INT_RSR 0x01
83#define INT_MSR 0x02
84#define INT_WAKSR 0x03
85#define INT_TXOK_CNT 0x04
86#define INT_RXLOST_CNT 0x05
87#define INT_CRERR_CNT 0x06
88#define INT_COL_CNT 0x07
89
90/* Transmit status register errors */
91#define TSR_ECOL (1<<5)
92#define TSR_LCOL (1<<4)
93#define TSR_LOSS_CRS (1<<3)
94#define TSR_JBR (1<<2)
95#define TSR_ERRORS (TSR_ECOL | TSR_LCOL | TSR_LOSS_CRS | TSR_JBR)
96/* Receive status register errors */
97#define RSR_CRC (1<<2)
98#define RSR_FAE (1<<1)
99#define RSR_ERRORS (RSR_CRC | RSR_FAE)
100
101/* Media status register definitions */
102#define MSR_DUPLEX (1<<4)
103#define MSR_SPEED (1<<3)
104#define MSR_LINK (1<<2)
105
106/* Interrupt pipe data */
107#define INT_TSR 0x00
108#define INT_RSR 0x01
109#define INT_MSR 0x02
110#define INT_WAKSR 0x03
111#define INT_TXOK_CNT 0x04
112#define INT_RXLOST_CNT 0x05
113#define INT_CRERR_CNT 0x06
114#define INT_COL_CNT 0x07
115
116
117#define RTL8150_MTU 1540
118#define RTL8150_TX_TIMEOUT (HZ)
119#define RX_SKB_POOL_SIZE 4
120
121/* rtl8150 flags */
122#define RTL8150_HW_CRC 0
123#define RX_REG_SET 1
124#define RTL8150_UNPLUG 2
125#define RX_URB_FAIL 3
126
127/* Define these values to match your device */
128#define VENDOR_ID_REALTEK 0x0bda
129#define VENDOR_ID_MELCO 0x0411
130#define VENDOR_ID_MICRONET 0x3980
131#define VENDOR_ID_LONGSHINE 0x07b8
132
133#define PRODUCT_ID_RTL8150 0x8150
134#define PRODUCT_ID_LUAKTX 0x0012
135#define PRODUCT_ID_LCS8138TX 0x401a
136#define PRODUCT_ID_SP128AR 0x0003
137
138#undef EEPROM_WRITE
139
140/* table of devices that work with this driver */
141static struct usb_device_id rtl8150_table[] = {
142 {USB_DEVICE(VENDOR_ID_REALTEK, PRODUCT_ID_RTL8150)},
143 {USB_DEVICE(VENDOR_ID_MELCO, PRODUCT_ID_LUAKTX)},
144 {USB_DEVICE(VENDOR_ID_MICRONET, PRODUCT_ID_SP128AR)},
145 {USB_DEVICE(VENDOR_ID_LONGSHINE, PRODUCT_ID_LCS8138TX)},
146 {}
147};
148
149MODULE_DEVICE_TABLE(usb, rtl8150_table);
150
151struct rtl8150 {
152 unsigned long flags;
153 struct usb_device *udev;
154 struct tasklet_struct tl;
155 struct net_device_stats stats;
156 struct net_device *netdev;
157 struct urb *rx_urb, *tx_urb, *intr_urb, *ctrl_urb;
158 struct sk_buff *tx_skb, *rx_skb;
159 struct sk_buff *rx_skb_pool[RX_SKB_POOL_SIZE];
160 spinlock_t rx_pool_lock;
161 struct usb_ctrlrequest dr;
162 int intr_interval;
163 __le16 rx_creg;
164 u8 *intr_buff;
165 u8 phy;
166};
167
168typedef struct rtl8150 rtl8150_t;
169
170static unsigned long multicast_filter_limit = 32;
171
172static void fill_skb_pool(rtl8150_t *);
173static void free_skb_pool(rtl8150_t *);
174static inline struct sk_buff *pull_skb(rtl8150_t *);
175static void rtl8150_disconnect(struct usb_interface *intf);
176static int rtl8150_probe(struct usb_interface *intf,
177 const struct usb_device_id *id);
178
179static const char driver_name [] = "rtl8150";
180
181static struct usb_driver rtl8150_driver = {
182 .owner = THIS_MODULE,
183 .name = driver_name,
184 .probe = rtl8150_probe,
185 .disconnect = rtl8150_disconnect,
186 .id_table = rtl8150_table,
187};
188
189/*
190**
191** device related part of the code
192**
193*/
194static int get_registers(rtl8150_t * dev, u16 indx, u16 size, void *data)
195{
196 return usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
197 RTL8150_REQ_GET_REGS, RTL8150_REQT_READ,
198 indx, 0, data, size, 500);
199}
200
201static int set_registers(rtl8150_t * dev, u16 indx, u16 size, void *data)
202{
203 return usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0),
204 RTL8150_REQ_SET_REGS, RTL8150_REQT_WRITE,
205 indx, 0, data, size, 500);
206}
207
208static void ctrl_callback(struct urb *urb, struct pt_regs *regs)
209{
210 rtl8150_t *dev;
211
212 switch (urb->status) {
213 case 0:
214 break;
215 case -EINPROGRESS:
216 break;
217 case -ENOENT:
218 break;
219 default:
220 warn("ctrl urb status %d", urb->status);
221 }
222 dev = urb->context;
223 clear_bit(RX_REG_SET, &dev->flags);
224}
225
226static int async_set_registers(rtl8150_t * dev, u16 indx, u16 size)
227{
228 int ret;
229
230 if (test_bit(RX_REG_SET, &dev->flags))
231 return -EAGAIN;
232
233 dev->dr.bRequestType = RTL8150_REQT_WRITE;
234 dev->dr.bRequest = RTL8150_REQ_SET_REGS;
235 dev->dr.wValue = cpu_to_le16(indx);
236 dev->dr.wIndex = 0;
237 dev->dr.wLength = cpu_to_le16(size);
238 dev->ctrl_urb->transfer_buffer_length = size;
239 usb_fill_control_urb(dev->ctrl_urb, dev->udev,
240 usb_sndctrlpipe(dev->udev, 0), (char *) &dev->dr,
241 &dev->rx_creg, size, ctrl_callback, dev);
242 if ((ret = usb_submit_urb(dev->ctrl_urb, GFP_ATOMIC)))
243 err("control request submission failed: %d", ret);
244 else
245 set_bit(RX_REG_SET, &dev->flags);
246
247 return ret;
248}
249
250static int read_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 * reg)
251{
252 int i;
253 u8 data[3], tmp;
254
255 data[0] = phy;
256 data[1] = data[2] = 0;
257 tmp = indx | PHY_READ | PHY_GO;
258 i = 0;
259
260 set_registers(dev, PHYADD, sizeof(data), data);
261 set_registers(dev, PHYCNT, 1, &tmp);
262 do {
263 get_registers(dev, PHYCNT, 1, data);
264 } while ((data[0] & PHY_GO) && (i++ < MII_TIMEOUT));
265
266 if (i < MII_TIMEOUT) {
267 get_registers(dev, PHYDAT, 2, data);
268 *reg = data[0] | (data[1] << 8);
269 return 0;
270 } else
271 return 1;
272}
273
274static int write_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 reg)
275{
276 int i;
277 u8 data[3], tmp;
278
279 data[0] = phy;
280 *(data + 1) = cpu_to_le16p(&reg);
281 tmp = indx | PHY_WRITE | PHY_GO;
282 i = 0;
283
284 set_registers(dev, PHYADD, sizeof(data), data);
285 set_registers(dev, PHYCNT, 1, &tmp);
286 do {
287 get_registers(dev, PHYCNT, 1, data);
288 } while ((data[0] & PHY_GO) && (i++ < MII_TIMEOUT));
289
290 if (i < MII_TIMEOUT)
291 return 0;
292 else
293 return 1;
294}
295
296static inline void set_ethernet_addr(rtl8150_t * dev)
297{
298 u8 node_id[6];
299
300 get_registers(dev, IDR, sizeof(node_id), node_id);
301 memcpy(dev->netdev->dev_addr, node_id, sizeof(node_id));
302}
303
304static int rtl8150_set_mac_address(struct net_device *netdev, void *p)
305{
306 struct sockaddr *addr = p;
307 rtl8150_t *dev = netdev_priv(netdev);
308 int i;
309
310 if (netif_running(netdev))
311 return -EBUSY;
312
313 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
314 dbg("%s: Setting MAC address to ", netdev->name);
315 for (i = 0; i < 5; i++)
316 dbg("%02X:", netdev->dev_addr[i]);
317 dbg("%02X\n", netdev->dev_addr[i]);
318 /* Set the IDR registers. */
319 set_registers(dev, IDR, sizeof(netdev->dev_addr), netdev->dev_addr);
320#ifdef EEPROM_WRITE
321 {
322 u8 cr;
323 /* Get the CR contents. */
324 get_registers(dev, CR, 1, &cr);
325 /* Set the WEPROM bit (eeprom write enable). */
326 cr |= 0x20;
327 set_registers(dev, CR, 1, &cr);
328 /* Write the MAC address into eeprom. Eeprom writes must be word-sized,
329 so we need to split them up. */
330 for (i = 0; i * 2 < netdev->addr_len; i++) {
331 set_registers(dev, IDR_EEPROM + (i * 2), 2,
332 netdev->dev_addr + (i * 2));
333 }
334 /* Clear the WEPROM bit (preventing accidental eeprom writes). */
335 cr &= 0xdf;
336 set_registers(dev, CR, 1, &cr);
337 }
338#endif
339 return 0;
340}
341
342static int rtl8150_reset(rtl8150_t * dev)
343{
344 u8 data = 0x10;
345 int i = HZ;
346
347 set_registers(dev, CR, 1, &data);
348 do {
349 get_registers(dev, CR, 1, &data);
350 } while ((data & 0x10) && --i);
351
352 return (i > 0) ? 1 : 0;
353}
354
355static int alloc_all_urbs(rtl8150_t * dev)
356{
357 dev->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
358 if (!dev->rx_urb)
359 return 0;
360 dev->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
361 if (!dev->tx_urb) {
362 usb_free_urb(dev->rx_urb);
363 return 0;
364 }
365 dev->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
366 if (!dev->intr_urb) {
367 usb_free_urb(dev->rx_urb);
368 usb_free_urb(dev->tx_urb);
369 return 0;
370 }
371 dev->ctrl_urb = usb_alloc_urb(0, GFP_KERNEL);
372 if (!dev->intr_urb) {
373 usb_free_urb(dev->rx_urb);
374 usb_free_urb(dev->tx_urb);
375 usb_free_urb(dev->intr_urb);
376 return 0;
377 }
378
379 return 1;
380}
381
382static void free_all_urbs(rtl8150_t * dev)
383{
384 usb_free_urb(dev->rx_urb);
385 usb_free_urb(dev->tx_urb);
386 usb_free_urb(dev->intr_urb);
387 usb_free_urb(dev->ctrl_urb);
388}
389
390static void unlink_all_urbs(rtl8150_t * dev)
391{
392 usb_kill_urb(dev->rx_urb);
393 usb_kill_urb(dev->tx_urb);
394 usb_kill_urb(dev->intr_urb);
395 usb_kill_urb(dev->ctrl_urb);
396}
397
398static inline struct sk_buff *pull_skb(rtl8150_t *dev)
399{
400 struct sk_buff *skb;
401 int i;
402
403 for (i = 0; i < RX_SKB_POOL_SIZE; i++) {
404 if (dev->rx_skb_pool[i]) {
405 skb = dev->rx_skb_pool[i];
406 dev->rx_skb_pool[i] = NULL;
407 return skb;
408 }
409 }
410 return NULL;
411}
412
413static void read_bulk_callback(struct urb *urb, struct pt_regs *regs)
414{
415 rtl8150_t *dev;
416 unsigned pkt_len, res;
417 struct sk_buff *skb;
418 struct net_device *netdev;
419 u16 rx_stat;
420
421 dev = urb->context;
422 if (!dev)
423 return;
424 if (test_bit(RTL8150_UNPLUG, &dev->flags))
425 return;
426 netdev = dev->netdev;
427 if (!netif_device_present(netdev))
428 return;
429
430 switch (urb->status) {
431 case 0:
432 break;
433 case -ENOENT:
434 return; /* the urb is in unlink state */
435 case -ETIMEDOUT:
436 warn("may be reset is needed?..");
437 goto goon;
438 default:
439 warn("Rx status %d", urb->status);
440 goto goon;
441 }
442
443 if (!dev->rx_skb)
444 goto resched;
445 /* protect against short packets (tell me why we got some?!?) */
446 if (urb->actual_length < 4)
447 goto goon;
448
449 res = urb->actual_length;
450 rx_stat = le16_to_cpu(*(__le16 *)(urb->transfer_buffer + res - 4));
451 pkt_len = res - 4;
452
453 skb_put(dev->rx_skb, pkt_len);
454 dev->rx_skb->protocol = eth_type_trans(dev->rx_skb, netdev);
455 netif_rx(dev->rx_skb);
456 dev->stats.rx_packets++;
457 dev->stats.rx_bytes += pkt_len;
458
459 spin_lock(&dev->rx_pool_lock);
460 skb = pull_skb(dev);
461 spin_unlock(&dev->rx_pool_lock);
462 if (!skb)
463 goto resched;
464
465 dev->rx_skb = skb;
466goon:
467 usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
468 dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
469 if (usb_submit_urb(dev->rx_urb, GFP_ATOMIC)) {
470 set_bit(RX_URB_FAIL, &dev->flags);
471 goto resched;
472 } else {
473 clear_bit(RX_URB_FAIL, &dev->flags);
474 }
475
476 return;
477resched:
478 tasklet_schedule(&dev->tl);
479}
480
481static void rx_fixup(unsigned long data)
482{
483 rtl8150_t *dev;
484 struct sk_buff *skb;
485
486 dev = (rtl8150_t *)data;
487
488 spin_lock_irq(&dev->rx_pool_lock);
489 fill_skb_pool(dev);
490 spin_unlock_irq(&dev->rx_pool_lock);
491 if (test_bit(RX_URB_FAIL, &dev->flags))
492 if (dev->rx_skb)
493 goto try_again;
494 spin_lock_irq(&dev->rx_pool_lock);
495 skb = pull_skb(dev);
496 spin_unlock_irq(&dev->rx_pool_lock);
497 if (skb == NULL)
498 goto tlsched;
499 dev->rx_skb = skb;
500 usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
501 dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
502try_again:
503 if (usb_submit_urb(dev->rx_urb, GFP_ATOMIC)) {
504 set_bit(RX_URB_FAIL, &dev->flags);
505 goto tlsched;
506 } else {
507 clear_bit(RX_URB_FAIL, &dev->flags);
508 }
509
510 return;
511tlsched:
512 tasklet_schedule(&dev->tl);
513}
514
515static void write_bulk_callback(struct urb *urb, struct pt_regs *regs)
516{
517 rtl8150_t *dev;
518
519 dev = urb->context;
520 if (!dev)
521 return;
522 dev_kfree_skb_irq(dev->tx_skb);
523 if (!netif_device_present(dev->netdev))
524 return;
525 if (urb->status)
526 info("%s: Tx status %d", dev->netdev->name, urb->status);
527 dev->netdev->trans_start = jiffies;
528 netif_wake_queue(dev->netdev);
529}
530
531static void intr_callback(struct urb *urb, struct pt_regs *regs)
532{
533 rtl8150_t *dev;
534 __u8 *d;
535 int status;
536
537 dev = urb->context;
538 if (!dev)
539 return;
540 switch (urb->status) {
541 case 0: /* success */
542 break;
543 case -ECONNRESET: /* unlink */
544 case -ENOENT:
545 case -ESHUTDOWN:
546 return;
547 /* -EPIPE: should clear the halt */
548 default:
549 info("%s: intr status %d", dev->netdev->name, urb->status);
550 goto resubmit;
551 }
552
553 d = urb->transfer_buffer;
554 if (d[0] & TSR_ERRORS) {
555 dev->stats.tx_errors++;
556 if (d[INT_TSR] & (TSR_ECOL | TSR_JBR))
557 dev->stats.tx_aborted_errors++;
558 if (d[INT_TSR] & TSR_LCOL)
559 dev->stats.tx_window_errors++;
560 if (d[INT_TSR] & TSR_LOSS_CRS)
561 dev->stats.tx_carrier_errors++;
562 }
563 /* Report link status changes to the network stack */
564 if ((d[INT_MSR] & MSR_LINK) == 0) {
565 if (netif_carrier_ok(dev->netdev)) {
566 netif_carrier_off(dev->netdev);
567 dbg("%s: LINK LOST\n", __func__);
568 }
569 } else {
570 if (!netif_carrier_ok(dev->netdev)) {
571 netif_carrier_on(dev->netdev);
572 dbg("%s: LINK CAME BACK\n", __func__);
573 }
574 }
575
576resubmit:
577 status = usb_submit_urb (urb, SLAB_ATOMIC);
578 if (status)
579 err ("can't resubmit intr, %s-%s/input0, status %d",
580 dev->udev->bus->bus_name,
581 dev->udev->devpath, status);
582}
583
584
585/*
586**
587** network related part of the code
588**
589*/
590
591static void fill_skb_pool(rtl8150_t *dev)
592{
593 struct sk_buff *skb;
594 int i;
595
596 for (i = 0; i < RX_SKB_POOL_SIZE; i++) {
597 if (dev->rx_skb_pool[i])
598 continue;
599 skb = dev_alloc_skb(RTL8150_MTU + 2);
600 if (!skb) {
601 return;
602 }
603 skb->dev = dev->netdev;
604 skb_reserve(skb, 2);
605 dev->rx_skb_pool[i] = skb;
606 }
607}
608
609static void free_skb_pool(rtl8150_t *dev)
610{
611 int i;
612
613 for (i = 0; i < RX_SKB_POOL_SIZE; i++)
614 if (dev->rx_skb_pool[i])
615 dev_kfree_skb(dev->rx_skb_pool[i]);
616}
617
618static int enable_net_traffic(rtl8150_t * dev)
619{
620 u8 cr, tcr, rcr, msr;
621
622 if (!rtl8150_reset(dev)) {
623 warn("%s - device reset failed", __FUNCTION__);
624 }
625 /* RCR bit7=1 attach Rx info at the end; =0 HW CRC (which is broken) */
626 rcr = 0x9e;
627 dev->rx_creg = cpu_to_le16(rcr);
628 tcr = 0xd8;
629 cr = 0x0c;
630 if (!(rcr & 0x80))
631 set_bit(RTL8150_HW_CRC, &dev->flags);
632 set_registers(dev, RCR, 1, &rcr);
633 set_registers(dev, TCR, 1, &tcr);
634 set_registers(dev, CR, 1, &cr);
635 get_registers(dev, MSR, 1, &msr);
636
637 return 0;
638}
639
640static void disable_net_traffic(rtl8150_t * dev)
641{
642 u8 cr;
643
644 get_registers(dev, CR, 1, &cr);
645 cr &= 0xf3;
646 set_registers(dev, CR, 1, &cr);
647}
648
649static struct net_device_stats *rtl8150_netdev_stats(struct net_device *dev)
650{
651 return &((rtl8150_t *)netdev_priv(dev))->stats;
652}
653
654static void rtl8150_tx_timeout(struct net_device *netdev)
655{
656 rtl8150_t *dev = netdev_priv(netdev);
657 warn("%s: Tx timeout.", netdev->name);
658 dev->tx_urb->transfer_flags |= URB_ASYNC_UNLINK;
659 usb_unlink_urb(dev->tx_urb);
660 dev->stats.tx_errors++;
661}
662
663static void rtl8150_set_multicast(struct net_device *netdev)
664{
665 rtl8150_t *dev = netdev_priv(netdev);
666 netif_stop_queue(netdev);
667 if (netdev->flags & IFF_PROMISC) {
668 dev->rx_creg |= cpu_to_le16(0x0001);
669 info("%s: promiscuous mode", netdev->name);
670 } else if ((netdev->mc_count > multicast_filter_limit) ||
671 (netdev->flags & IFF_ALLMULTI)) {
672 dev->rx_creg &= cpu_to_le16(0xfffe);
673 dev->rx_creg |= cpu_to_le16(0x0002);
674 info("%s: allmulti set", netdev->name);
675 } else {
676 /* ~RX_MULTICAST, ~RX_PROMISCUOUS */
677 dev->rx_creg &= cpu_to_le16(0x00fc);
678 }
679 async_set_registers(dev, RCR, 2);
680 netif_wake_queue(netdev);
681}
682
683static int rtl8150_start_xmit(struct sk_buff *skb, struct net_device *netdev)
684{
685 rtl8150_t *dev = netdev_priv(netdev);
686 int count, res;
687
688 netif_stop_queue(netdev);
689 count = (skb->len < 60) ? 60 : skb->len;
690 count = (count & 0x3f) ? count : count + 1;
691 dev->tx_skb = skb;
692 usb_fill_bulk_urb(dev->tx_urb, dev->udev, usb_sndbulkpipe(dev->udev, 2),
693 skb->data, count, write_bulk_callback, dev);
694 if ((res = usb_submit_urb(dev->tx_urb, GFP_ATOMIC))) {
695 warn("failed tx_urb %d\n", res);
696 dev->stats.tx_errors++;
697 netif_start_queue(netdev);
698 } else {
699 dev->stats.tx_packets++;
700 dev->stats.tx_bytes += skb->len;
701 netdev->trans_start = jiffies;
702 }
703
704 return 0;
705}
706
707
708static void set_carrier(struct net_device *netdev)
709{
710 rtl8150_t *dev = netdev_priv(netdev);
711 short tmp;
712
713 get_registers(dev, CSCR, 2, &tmp);
714 if (tmp & CSCR_LINK_STATUS)
715 netif_carrier_on(netdev);
716 else
717 netif_carrier_off(netdev);
718}
719
720static int rtl8150_open(struct net_device *netdev)
721{
722 rtl8150_t *dev = netdev_priv(netdev);
723 int res;
724
725 if (dev->rx_skb == NULL)
726 dev->rx_skb = pull_skb(dev);
727 if (!dev->rx_skb)
728 return -ENOMEM;
729
730 set_registers(dev, IDR, 6, netdev->dev_addr);
731
732 usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
733 dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
734 if ((res = usb_submit_urb(dev->rx_urb, GFP_KERNEL)))
735 warn("%s: rx_urb submit failed: %d", __FUNCTION__, res);
736 usb_fill_int_urb(dev->intr_urb, dev->udev, usb_rcvintpipe(dev->udev, 3),
737 dev->intr_buff, INTBUFSIZE, intr_callback,
738 dev, dev->intr_interval);
739 if ((res = usb_submit_urb(dev->intr_urb, GFP_KERNEL)))
740 warn("%s: intr_urb submit failed: %d", __FUNCTION__, res);
741 netif_start_queue(netdev);
742 enable_net_traffic(dev);
743 set_carrier(netdev);
744
745 return res;
746}
747
748static int rtl8150_close(struct net_device *netdev)
749{
750 rtl8150_t *dev = netdev_priv(netdev);
751 int res = 0;
752
753 netif_stop_queue(netdev);
754 if (!test_bit(RTL8150_UNPLUG, &dev->flags))
755 disable_net_traffic(dev);
756 unlink_all_urbs(dev);
757
758 return res;
759}
760
761static void rtl8150_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *info)
762{
763 rtl8150_t *dev = netdev_priv(netdev);
764
765 strncpy(info->driver, driver_name, ETHTOOL_BUSINFO_LEN);
766 strncpy(info->version, DRIVER_VERSION, ETHTOOL_BUSINFO_LEN);
767 usb_make_path(dev->udev, info->bus_info, sizeof info->bus_info);
768}
769
770static int rtl8150_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
771{
772 rtl8150_t *dev = netdev_priv(netdev);
773 short lpa, bmcr;
774
775 ecmd->supported = (SUPPORTED_10baseT_Half |
776 SUPPORTED_10baseT_Full |
777 SUPPORTED_100baseT_Half |
778 SUPPORTED_100baseT_Full |
779 SUPPORTED_Autoneg |
780 SUPPORTED_TP | SUPPORTED_MII);
781 ecmd->port = PORT_TP;
782 ecmd->transceiver = XCVR_INTERNAL;
783 ecmd->phy_address = dev->phy;
784 get_registers(dev, BMCR, 2, &bmcr);
785 get_registers(dev, ANLP, 2, &lpa);
786 if (bmcr & BMCR_ANENABLE) {
787 ecmd->autoneg = AUTONEG_ENABLE;
788 ecmd->speed = (lpa & (LPA_100HALF | LPA_100FULL)) ?
789 SPEED_100 : SPEED_10;
790 if (ecmd->speed == SPEED_100)
791 ecmd->duplex = (lpa & LPA_100FULL) ?
792 DUPLEX_FULL : DUPLEX_HALF;
793 else
794 ecmd->duplex = (lpa & LPA_10FULL) ?
795 DUPLEX_FULL : DUPLEX_HALF;
796 } else {
797 ecmd->autoneg = AUTONEG_DISABLE;
798 ecmd->speed = (bmcr & BMCR_SPEED100) ?
799 SPEED_100 : SPEED_10;
800 ecmd->duplex = (bmcr & BMCR_FULLDPLX) ?
801 DUPLEX_FULL : DUPLEX_HALF;
802 }
803 return 0;
804}
805
806static struct ethtool_ops ops = {
807 .get_drvinfo = rtl8150_get_drvinfo,
808 .get_settings = rtl8150_get_settings,
809 .get_link = ethtool_op_get_link
810};
811
812static int rtl8150_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
813{
814 rtl8150_t *dev = netdev_priv(netdev);
815 u16 *data = (u16 *) & rq->ifr_ifru;
816 int res = 0;
817
818 switch (cmd) {
819 case SIOCDEVPRIVATE:
820 data[0] = dev->phy;
821 case SIOCDEVPRIVATE + 1:
822 read_mii_word(dev, dev->phy, (data[1] & 0x1f), &data[3]);
823 break;
824 case SIOCDEVPRIVATE + 2:
825 if (!capable(CAP_NET_ADMIN))
826 return -EPERM;
827 write_mii_word(dev, dev->phy, (data[1] & 0x1f), data[2]);
828 break;
829 default:
830 res = -EOPNOTSUPP;
831 }
832
833 return res;
834}
835
836static int rtl8150_probe(struct usb_interface *intf,
837 const struct usb_device_id *id)
838{
839 struct usb_device *udev = interface_to_usbdev(intf);
840 rtl8150_t *dev;
841 struct net_device *netdev;
842
843 netdev = alloc_etherdev(sizeof(rtl8150_t));
844 if (!netdev) {
845 err("Out of memory");
846 return -ENOMEM;
847 }
848
849 dev = netdev_priv(netdev);
850 memset(dev, 0, sizeof(rtl8150_t));
851
852 dev->intr_buff = kmalloc(INTBUFSIZE, GFP_KERNEL);
853 if (!dev->intr_buff) {
854 free_netdev(netdev);
855 return -ENOMEM;
856 }
857
858 tasklet_init(&dev->tl, rx_fixup, (unsigned long)dev);
859 spin_lock_init(&dev->rx_pool_lock);
860
861 dev->udev = udev;
862 dev->netdev = netdev;
863 SET_MODULE_OWNER(netdev);
864 netdev->open = rtl8150_open;
865 netdev->stop = rtl8150_close;
866 netdev->do_ioctl = rtl8150_ioctl;
867 netdev->watchdog_timeo = RTL8150_TX_TIMEOUT;
868 netdev->tx_timeout = rtl8150_tx_timeout;
869 netdev->hard_start_xmit = rtl8150_start_xmit;
870 netdev->set_multicast_list = rtl8150_set_multicast;
871 netdev->set_mac_address = rtl8150_set_mac_address;
872 netdev->get_stats = rtl8150_netdev_stats;
873 netdev->mtu = RTL8150_MTU;
874 SET_ETHTOOL_OPS(netdev, &ops);
875 dev->intr_interval = 100; /* 100ms */
876
877 if (!alloc_all_urbs(dev)) {
878 err("out of memory");
879 goto out;
880 }
881 if (!rtl8150_reset(dev)) {
882 err("couldn't reset the device");
883 goto out1;
884 }
885 fill_skb_pool(dev);
886 set_ethernet_addr(dev);
887 info("%s: rtl8150 is detected", netdev->name);
888
889 usb_set_intfdata(intf, dev);
890 SET_NETDEV_DEV(netdev, &intf->dev);
891 if (register_netdev(netdev) != 0) {
892 err("couldn't register the device");
893 goto out2;
894 }
895 return 0;
896
897out2:
898 usb_set_intfdata(intf, NULL);
899 free_skb_pool(dev);
900out1:
901 free_all_urbs(dev);
902out:
903 kfree(dev->intr_buff);
904 free_netdev(netdev);
905 return -EIO;
906}
907
908static void rtl8150_disconnect(struct usb_interface *intf)
909{
910 rtl8150_t *dev = usb_get_intfdata(intf);
911
912 usb_set_intfdata(intf, NULL);
913 if (dev) {
914 set_bit(RTL8150_UNPLUG, &dev->flags);
915 unregister_netdev(dev->netdev);
916 unlink_all_urbs(dev);
917 free_all_urbs(dev);
918 free_skb_pool(dev);
919 if (dev->rx_skb)
920 dev_kfree_skb(dev->rx_skb);
921 kfree(dev->intr_buff);
922 free_netdev(dev->netdev);
923 }
924}
925
926static int __init usb_rtl8150_init(void)
927{
928 info(DRIVER_DESC " " DRIVER_VERSION);
929 return usb_register(&rtl8150_driver);
930}
931
932static void __exit usb_rtl8150_exit(void)
933{
934 usb_deregister(&rtl8150_driver);
935}
936
937module_init(usb_rtl8150_init);
938module_exit(usb_rtl8150_exit);
939
940MODULE_AUTHOR(DRIVER_AUTHOR);
941MODULE_DESCRIPTION(DRIVER_DESC);
942MODULE_LICENSE("GPL");
diff --git a/drivers/usb/net/usbnet.c b/drivers/usb/net/usbnet.c
new file mode 100644
index 000000000000..dd8b4456ea35
--- /dev/null
+++ b/drivers/usb/net/usbnet.c
@@ -0,0 +1,4106 @@
1/*
2 * USB Networking Links
3 * Copyright (C) 2000-2003 by David Brownell <dbrownell@users.sourceforge.net>
4 * Copyright (C) 2002 Pavel Machek <pavel@ucw.cz>
5 * 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 *
9 * 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
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24/*
25 * This is a generic "USB networking" framework that works with several
26 * kinds of full and high speed networking devices:
27 *
28 * + USB host-to-host "network cables", used for IP-over-USB links.
29 * These are often used for Laplink style connectivity products.
30 * - AnchorChip 2720
31 * - Belkin, eTEK (interops with Win32 drivers)
32 * - GeneSys GL620USB-A
33 * - NetChip 1080 (interoperates with NetChip Win32 drivers)
34 * - Prolific PL-2301/2302 (replaces "plusb" driver)
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
116// #define DEBUG // error path messages, extra info
117// #define VERBOSE // more; success messages
118
119#include <linux/config.h>
120#ifdef CONFIG_USB_DEBUG
121# define DEBUG
122#endif
123#include <linux/module.h>
124#include <linux/kmod.h>
125#include <linux/sched.h>
126#include <linux/init.h>
127#include <linux/netdevice.h>
128#include <linux/etherdevice.h>
129#include <linux/random.h>
130#include <linux/ethtool.h>
131#include <linux/workqueue.h>
132#include <linux/mii.h>
133#include <asm/uaccess.h>
134#include <asm/unaligned.h>
135#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
141#define DRIVER_VERSION "03-Nov-2004"
142
143
144/*-------------------------------------------------------------------------*/
145
146/*
147 * Nineteen USB 1.1 max size bulk transactions per frame (ms), max.
148 * Several dozen bytes of IPv4 data can fit in two such transactions.
149 * One maximum size Ethernet packet takes twenty four of them.
150 * For high speed, each frame comfortably fits almost 36 max size
151 * Ethernet packets (so queues should be bigger).
152 */
153#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)
155
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
162#define TX_TIMEOUT_JIFFIES (5*HZ)
163
164// throttle rx/tx briefly after some faults, so khubd might disconnect()
165// us (it polls at HZ/4 usually) before we report too many false errors.
166#define THROTTLE_JIFFIES (HZ/8)
167
168// for vendor-specific control operations
169#define CONTROL_TIMEOUT_MS 500
170
171// between wakeups
172#define UNLINK_TIMEOUT_MS 3
173
174/*-------------------------------------------------------------------------*/
175
176// randomly generated ethernet address
177static u8 node_id [ETH_ALEN];
178
179// state we keep for each device we handle
180struct 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};
214
215// device-specific info used by the driver
216struct driver_info {
217 char *description;
218
219 int flags;
220/* framing is CDC Ethernet, not writing ZLPs (hw issues), or optionally: */
221#define FLAG_FRAMING_NC 0x0001 /* guard against device dropouts */
222#define FLAG_FRAMING_GL 0x0002 /* genelink batches packets */
223#define FLAG_FRAMING_Z 0x0004 /* zaurus adds a trailer */
224#define FLAG_FRAMING_RN 0x0008 /* RNDIS batches, plus huge header */
225
226#define FLAG_NO_SETINT 0x0010 /* device can't set_interface() */
227#define FLAG_ETHER 0x0020 /* maybe use "eth%d" names */
228
229#define FLAG_FRAMING_AX 0x0040 /* AX88772/178 packets */
230
231 /* init device ... can sleep, or cause probe() failure */
232 int (*bind)(struct usbnet *, struct usb_interface *);
233
234 /* cleanup device ... can sleep, but can't fail */
235 void (*unbind)(struct usbnet *, struct usb_interface *);
236
237 /* reset device ... can sleep */
238 int (*reset)(struct usbnet *);
239
240 /* see if peer is connected ... can sleep */
241 int (*check_connect)(struct usbnet *);
242
243 /* for status polling */
244 void (*status)(struct usbnet *, struct urb *);
245
246 /* fixup rx packet (strip framing) */
247 int (*rx_fixup)(struct usbnet *dev, struct sk_buff *skb);
248
249 /* fixup tx packet (add framing) */
250 struct sk_buff *(*tx_fixup)(struct usbnet *dev,
251 struct sk_buff *skb, int flags);
252
253 // FIXME -- also an interrupt mechanism
254 // useful for at least PL2301/2302 and GL620USB-A
255 // and CDC use them to report 'is it connected' changes
256
257 /* for new devices, use the descriptor-reading code instead */
258 int in; /* rx endpoint */
259 int out; /* tx endpoint */
260
261 unsigned long data; /* Misc driver specific data */
262};
263
264// we record the state for each of our queued skbs
265enum skb_state {
266 illegal = 0,
267 tx_start, tx_done,
268 rx_start, rx_done, rx_cleanup
269};
270
271struct skb_data { // skb->cb is one of these
272 struct urb *urb;
273 struct usbnet *dev;
274 enum skb_state state;
275 size_t length;
276};
277
278static const char driver_name [] = "usbnet";
279
280/* use ethtool to change the level for any given device */
281static int msg_level = -1;
282module_param (msg_level, int, 0);
283MODULE_PARM_DESC (msg_level, "Override default message level");
284
285
286#ifdef DEBUG
287#define devdbg(usbnet, fmt, arg...) \
288 printk(KERN_DEBUG "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
289#else
290#define devdbg(usbnet, fmt, arg...) do {} while(0)
291#endif
292
293#define deverr(usbnet, fmt, arg...) \
294 printk(KERN_ERR "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
295#define devwarn(usbnet, fmt, arg...) \
296 printk(KERN_WARNING "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
297
298#define devinfo(usbnet, fmt, arg...) \
299 printk(KERN_INFO "%s: " fmt "\n" , (usbnet)->net->name , ## arg); \
300
301/*-------------------------------------------------------------------------*/
302
303static void usbnet_get_drvinfo (struct net_device *, struct ethtool_drvinfo *);
304static u32 usbnet_get_link (struct net_device *);
305static u32 usbnet_get_msglevel (struct net_device *);
306static void usbnet_set_msglevel (struct net_device *, u32);
307
308/* mostly for PDA style devices, which are always connected if present */
309static int always_connected (struct usbnet *dev)
310{
311 return 0;
312}
313
314/* handles CDC Ethernet and many other network "bulk data" interfaces */
315static int
316get_endpoints (struct usbnet *dev, struct usb_interface *intf)
317{
318 int tmp;
319 struct usb_host_interface *alt = NULL;
320 struct usb_host_endpoint *in = NULL, *out = NULL;
321 struct usb_host_endpoint *status = NULL;
322
323 for (tmp = 0; tmp < intf->num_altsetting; tmp++) {
324 unsigned ep;
325
326 in = out = status = NULL;
327 alt = intf->altsetting + tmp;
328
329 /* take the first altsetting with in-bulk + out-bulk;
330 * remember any status endpoint, just in case;
331 * ignore other endpoints and altsetttings.
332 */
333 for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) {
334 struct usb_host_endpoint *e;
335 int intr = 0;
336
337 e = alt->endpoint + ep;
338 switch (e->desc.bmAttributes) {
339 case USB_ENDPOINT_XFER_INT:
340 if (!(e->desc.bEndpointAddress & USB_DIR_IN))
341 continue;
342 intr = 1;
343 /* FALLTHROUGH */
344 case USB_ENDPOINT_XFER_BULK:
345 break;
346 default:
347 continue;
348 }
349 if (e->desc.bEndpointAddress & USB_DIR_IN) {
350 if (!intr && !in)
351 in = e;
352 else if (intr && !status)
353 status = e;
354 } else {
355 if (!out)
356 out = e;
357 }
358 }
359 if (in && out)
360 break;
361 }
362 if (!alt || !in || !out)
363 return -EINVAL;
364
365 if (alt->desc.bAlternateSetting != 0
366 || !(dev->driver_info->flags & FLAG_NO_SETINT)) {
367 tmp = usb_set_interface (dev->udev, alt->desc.bInterfaceNumber,
368 alt->desc.bAlternateSetting);
369 if (tmp < 0)
370 return tmp;
371 }
372
373 dev->in = usb_rcvbulkpipe (dev->udev,
374 in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
375 dev->out = usb_sndbulkpipe (dev->udev,
376 out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
377 dev->status = status;
378 return 0;
379}
380
381static void intr_complete (struct urb *urb, struct pt_regs *regs);
382
383static int init_status (struct usbnet *dev, struct usb_interface *intf)
384{
385 char *buf = NULL;
386 unsigned pipe = 0;
387 unsigned maxp;
388 unsigned period;
389
390 if (!dev->driver_info->status)
391 return 0;
392
393 pipe = usb_rcvintpipe (dev->udev,
394 dev->status->desc.bEndpointAddress
395 & USB_ENDPOINT_NUMBER_MASK);
396 maxp = usb_maxpacket (dev->udev, pipe, 0);
397
398 /* avoid 1 msec chatter: min 8 msec poll rate */
399 period = max ((int) dev->status->desc.bInterval,
400 (dev->udev->speed == USB_SPEED_HIGH) ? 7 : 3);
401
402 buf = kmalloc (maxp, SLAB_KERNEL);
403 if (buf) {
404 dev->interrupt = usb_alloc_urb (0, SLAB_KERNEL);
405 if (!dev->interrupt) {
406 kfree (buf);
407 return -ENOMEM;
408 } else {
409 usb_fill_int_urb(dev->interrupt, dev->udev, pipe,
410 buf, maxp, intr_complete, dev, period);
411 dev_dbg(&intf->dev,
412 "status ep%din, %d bytes period %d\n",
413 usb_pipeendpoint(pipe), maxp, period);
414 }
415 }
416 return 0;
417}
418
419static void skb_return (struct usbnet *dev, struct sk_buff *skb)
420{
421 int status;
422
423 skb->dev = dev->net;
424 skb->protocol = eth_type_trans (skb, dev->net);
425 dev->stats.rx_packets++;
426 dev->stats.rx_bytes += skb->len;
427
428 if (netif_msg_rx_status (dev))
429 devdbg (dev, "< rx, len %d, type 0x%x",
430 skb->len + sizeof (struct ethhdr), skb->protocol);
431 memset (skb->cb, 0, sizeof (struct skb_data));
432 status = netif_rx (skb);
433 if (status != NET_RX_SUCCESS && netif_msg_rx_err (dev))
434 devdbg (dev, "netif_rx status %d", status);
435}
436
437
438#ifdef CONFIG_USB_ALI_M5632
439#define HAVE_HARDWARE
440
441/*-------------------------------------------------------------------------
442 *
443 * ALi M5632 driver ... does high speed
444 *
445 *-------------------------------------------------------------------------*/
446
447static const struct driver_info ali_m5632_info = {
448 .description = "ALi M5632",
449};
450
451
452#endif
453
454
455#ifdef CONFIG_USB_AN2720
456#define HAVE_HARDWARE
457
458/*-------------------------------------------------------------------------
459 *
460 * AnchorChips 2720 driver ... http://www.cypress.com
461 *
462 * This doesn't seem to have a way to detect whether the peer is
463 * connected, or need any reset handshaking. It's got pretty big
464 * internal buffers (handles most of a frame's worth of data).
465 * Chip data sheets don't describe any vendor control messages.
466 *
467 *-------------------------------------------------------------------------*/
468
469static const struct driver_info an2720_info = {
470 .description = "AnchorChips/Cypress 2720",
471 // no reset available!
472 // no check_connect available!
473
474 .in = 2, .out = 2, // direction distinguishes these
475};
476
477#endif /* CONFIG_USB_AN2720 */
478
479
480#ifdef CONFIG_USB_AX8817X
481/* ASIX AX8817X based USB 2.0 Ethernet Devices */
482
483#define HAVE_HARDWARE
484#define NEED_MII
485
486#include <linux/crc32.h>
487
488#define AX_CMD_SET_SW_MII 0x06
489#define AX_CMD_READ_MII_REG 0x07
490#define AX_CMD_WRITE_MII_REG 0x08
491#define AX_CMD_SET_HW_MII 0x0a
492#define AX_CMD_READ_EEPROM 0x0b
493#define AX_CMD_WRITE_EEPROM 0x0c
494#define AX_CMD_WRITE_ENABLE 0x0d
495#define AX_CMD_WRITE_DISABLE 0x0e
496#define AX_CMD_WRITE_RX_CTL 0x10
497#define AX_CMD_READ_IPG012 0x11
498#define AX_CMD_WRITE_IPG0 0x12
499#define AX_CMD_WRITE_IPG1 0x13
500#define AX_CMD_WRITE_IPG2 0x14
501#define AX_CMD_WRITE_MULTI_FILTER 0x16
502#define AX_CMD_READ_NODE_ID 0x17
503#define AX_CMD_READ_PHY_ID 0x19
504#define AX_CMD_WRITE_MEDIUM_MODE 0x1b
505#define AX_CMD_READ_MONITOR_MODE 0x1c
506#define AX_CMD_WRITE_MONITOR_MODE 0x1d
507#define AX_CMD_WRITE_GPIOS 0x1f
508#define AX_CMD_SW_RESET 0x20
509#define AX_CMD_SW_PHY_STATUS 0x21
510#define AX_CMD_SW_PHY_SELECT 0x22
511#define AX88772_CMD_READ_NODE_ID 0x13
512
513#define AX_MONITOR_MODE 0x01
514#define AX_MONITOR_LINK 0x02
515#define AX_MONITOR_MAGIC 0x04
516#define AX_MONITOR_HSFS 0x10
517
518#define AX_MCAST_FILTER_SIZE 8
519#define AX_MAX_MCAST 64
520
521#define AX_INTERRUPT_BUFSIZE 8
522
523#define AX_EEPROM_LEN 0x40
524
525#define AX_SWRESET_CLEAR 0x00
526#define AX_SWRESET_RR 0x01
527#define AX_SWRESET_RT 0x02
528#define AX_SWRESET_PRTE 0x04
529#define AX_SWRESET_PRL 0x08
530#define AX_SWRESET_BZ 0x10
531#define AX_SWRESET_IPRL 0x20
532#define AX_SWRESET_IPPD 0x40
533
534#define AX88772_IPG0_DEFAULT 0x15
535#define AX88772_IPG1_DEFAULT 0x0c
536#define AX88772_IPG2_DEFAULT 0x12
537
538#define AX_EEPROM_MAGIC 0xdeadbeef
539
540/* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
541struct ax8817x_data {
542 u8 multi_filter[AX_MCAST_FILTER_SIZE];
543 struct urb *int_urb;
544 u8 *int_buf;
545};
546
547static int ax8817x_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
548 u16 size, void *data)
549{
550 return usb_control_msg(
551 dev->udev,
552 usb_rcvctrlpipe(dev->udev, 0),
553 cmd,
554 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
555 value,
556 index,
557 data,
558 size,
559 CONTROL_TIMEOUT_MS);
560}
561
562static int ax8817x_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
563 u16 size, void *data)
564{
565 return usb_control_msg(
566 dev->udev,
567 usb_sndctrlpipe(dev->udev, 0),
568 cmd,
569 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
570 value,
571 index,
572 data,
573 size,
574 CONTROL_TIMEOUT_MS);
575}
576
577static void ax8817x_async_cmd_callback(struct urb *urb, struct pt_regs *regs)
578{
579 struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
580
581 if (urb->status < 0)
582 printk(KERN_DEBUG "ax8817x_async_cmd_callback() failed with %d",
583 urb->status);
584
585 kfree(req);
586 usb_free_urb(urb);
587}
588
589static void ax8817x_interrupt_complete(struct urb *urb, struct pt_regs *regs)
590{
591 struct usbnet *dev = (struct usbnet *)urb->context;
592 struct ax8817x_data *data = (struct ax8817x_data *)&dev->data;
593 int link;
594
595 if (urb->status < 0) {
596 devdbg(dev,"ax8817x_interrupt_complete() failed with %d",
597 urb->status);
598 } else {
599 link = data->int_buf[2] & 0x01;
600 if (netif_carrier_ok(dev->net) != link) {
601 if (link)
602 netif_carrier_on(dev->net);
603 else
604 netif_carrier_off(dev->net);
605 devdbg(dev, "ax8817x - Link Status is: %d", link);
606 }
607 usb_submit_urb(data->int_urb, GFP_ATOMIC);
608 }
609}
610
611static void ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
612 u16 size, void *data)
613{
614 struct usb_ctrlrequest *req;
615 int status;
616 struct urb *urb;
617
618 if ((urb = usb_alloc_urb(0, GFP_ATOMIC)) == NULL) {
619 devdbg(dev, "Error allocating URB in write_cmd_async!");
620 return;
621 }
622
623 if ((req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC)) == NULL) {
624 deverr(dev, "Failed to allocate memory for control request");
625 usb_free_urb(urb);
626 return;
627 }
628
629 req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
630 req->bRequest = cmd;
631 req->wValue = cpu_to_le16(value);
632 req->wIndex = cpu_to_le16(index);
633 req->wLength = cpu_to_le16(size);
634
635 usb_fill_control_urb(urb, dev->udev,
636 usb_sndctrlpipe(dev->udev, 0),
637 (void *)req, data, size,
638 ax8817x_async_cmd_callback, req);
639
640 if((status = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
641 deverr(dev, "Error submitting the control message: status=%d", status);
642 kfree(req);
643 usb_free_urb(urb);
644 }
645}
646
647static void ax8817x_set_multicast(struct net_device *net)
648{
649 struct usbnet *dev = netdev_priv(net);
650 struct ax8817x_data *data = (struct ax8817x_data *)&dev->data;
651 u8 rx_ctl = 0x8c;
652
653 if (net->flags & IFF_PROMISC) {
654 rx_ctl |= 0x01;
655 } else if (net->flags & IFF_ALLMULTI
656 || net->mc_count > AX_MAX_MCAST) {
657 rx_ctl |= 0x02;
658 } else if (net->mc_count == 0) {
659 /* just broadcast and directed */
660 } else {
661 /* We use the 20 byte dev->data
662 * for our 8 byte filter buffer
663 * to avoid allocating memory that
664 * is tricky to free later */
665 struct dev_mc_list *mc_list = net->mc_list;
666 u32 crc_bits;
667 int i;
668
669 memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE);
670
671 /* Build the multicast hash filter. */
672 for (i = 0; i < net->mc_count; i++) {
673 crc_bits =
674 ether_crc(ETH_ALEN,
675 mc_list->dmi_addr) >> 26;
676 data->multi_filter[crc_bits >> 3] |=
677 1 << (crc_bits & 7);
678 mc_list = mc_list->next;
679 }
680
681 ax8817x_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
682 AX_MCAST_FILTER_SIZE, data->multi_filter);
683
684 rx_ctl |= 0x10;
685 }
686
687 ax8817x_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
688}
689
690static int ax8817x_mdio_read(struct net_device *netdev, int phy_id, int loc)
691{
692 struct usbnet *dev = netdev_priv(netdev);
693 u16 res;
694 u8 buf[1];
695
696 ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf);
697 ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res);
698 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf);
699
700 return res & 0xffff;
701}
702
703static void ax8817x_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
704{
705 struct usbnet *dev = netdev_priv(netdev);
706 u16 res = val;
707 u8 buf[1];
708
709 ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf);
710 ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res);
711 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf);
712}
713
714static void ax8817x_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
715{
716 struct usbnet *dev = netdev_priv(net);
717 u8 opt;
718
719 if (ax8817x_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) {
720 wolinfo->supported = 0;
721 wolinfo->wolopts = 0;
722 return;
723 }
724 wolinfo->supported = WAKE_PHY | WAKE_MAGIC;
725 wolinfo->wolopts = 0;
726 if (opt & AX_MONITOR_MODE) {
727 if (opt & AX_MONITOR_LINK)
728 wolinfo->wolopts |= WAKE_PHY;
729 if (opt & AX_MONITOR_MAGIC)
730 wolinfo->wolopts |= WAKE_MAGIC;
731 }
732}
733
734static int ax8817x_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
735{
736 struct usbnet *dev = netdev_priv(net);
737 u8 opt = 0;
738 u8 buf[1];
739
740 if (wolinfo->wolopts & WAKE_PHY)
741 opt |= AX_MONITOR_LINK;
742 if (wolinfo->wolopts & WAKE_MAGIC)
743 opt |= AX_MONITOR_MAGIC;
744 if (opt != 0)
745 opt |= AX_MONITOR_MODE;
746
747 if (ax8817x_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE,
748 opt, 0, 0, &buf) < 0)
749 return -EINVAL;
750
751 return 0;
752}
753
754static int ax8817x_get_eeprom_len(struct net_device *net)
755{
756 return AX_EEPROM_LEN;
757}
758
759static int ax8817x_get_eeprom(struct net_device *net,
760 struct ethtool_eeprom *eeprom, u8 *data)
761{
762 struct usbnet *dev = netdev_priv(net);
763 u16 *ebuf = (u16 *)data;
764 int i;
765
766 /* Crude hack to ensure that we don't overwrite memory
767 * if an odd length is supplied
768 */
769 if (eeprom->len % 2)
770 return -EINVAL;
771
772 eeprom->magic = AX_EEPROM_MAGIC;
773
774 /* ax8817x returns 2 bytes from eeprom on read */
775 for (i=0; i < eeprom->len / 2; i++) {
776 if (ax8817x_read_cmd(dev, AX_CMD_READ_EEPROM,
777 eeprom->offset + i, 0, 2, &ebuf[i]) < 0)
778 return -EINVAL;
779 }
780 return 0;
781}
782
783static void ax8817x_get_drvinfo (struct net_device *net,
784 struct ethtool_drvinfo *info)
785{
786 /* Inherit standard device info */
787 usbnet_get_drvinfo(net, info);
788 info->eedump_len = 0x3e;
789}
790
791static int ax8817x_get_settings(struct net_device *net, struct ethtool_cmd *cmd)
792{
793 struct usbnet *dev = netdev_priv(net);
794
795 return mii_ethtool_gset(&dev->mii,cmd);
796}
797
798static int ax8817x_set_settings(struct net_device *net, struct ethtool_cmd *cmd)
799{
800 struct usbnet *dev = netdev_priv(net);
801
802 return mii_ethtool_sset(&dev->mii,cmd);
803}
804
805/* We need to override some ethtool_ops so we require our
806 own structure so we don't interfere with other usbnet
807 devices that may be connected at the same time. */
808static struct ethtool_ops ax8817x_ethtool_ops = {
809 .get_drvinfo = ax8817x_get_drvinfo,
810 .get_link = ethtool_op_get_link,
811 .get_msglevel = usbnet_get_msglevel,
812 .set_msglevel = usbnet_set_msglevel,
813 .get_wol = ax8817x_get_wol,
814 .set_wol = ax8817x_set_wol,
815 .get_eeprom_len = ax8817x_get_eeprom_len,
816 .get_eeprom = ax8817x_get_eeprom,
817 .get_settings = ax8817x_get_settings,
818 .set_settings = ax8817x_set_settings,
819};
820
821static int ax8817x_bind(struct usbnet *dev, struct usb_interface *intf)
822{
823 int ret = 0;
824 void *buf;
825 int i;
826 unsigned long gpio_bits = dev->driver_info->data;
827 struct ax8817x_data *data = (struct ax8817x_data *)dev->data;
828
829 get_endpoints(dev,intf);
830
831 if ((data->int_urb = usb_alloc_urb (0, GFP_KERNEL)) == NULL) {
832 dbg ("%s: cannot allocate interrupt URB",
833 dev->net->name);
834 ret = -ENOMEM;
835 goto out1;
836 }
837
838 if ((data->int_buf = kmalloc(AX_INTERRUPT_BUFSIZE, GFP_KERNEL)) == NULL) {
839 dbg ("%s: cannot allocate memory for interrupt buffer",
840 dev->net->name);
841 ret = -ENOMEM;
842 goto out1;
843 }
844 memset(data->int_buf, 0, AX_INTERRUPT_BUFSIZE);
845
846 usb_fill_int_urb (data->int_urb, dev->udev,
847 usb_rcvintpipe (dev->udev, 1),
848 data->int_buf, AX_INTERRUPT_BUFSIZE,
849 ax8817x_interrupt_complete, dev,
850 dev->udev->speed == USB_SPEED_HIGH ? 8 : 100);
851
852 buf = kmalloc(ETH_ALEN, GFP_KERNEL);
853 if(!buf) {
854 ret = -ENOMEM;
855 goto out2;
856 }
857
858 /* Toggle the GPIOs in a manufacturer/model specific way */
859 for (i = 2; i >= 0; i--) {
860 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS,
861 (gpio_bits >> (i * 8)) & 0xff, 0, 0,
862 buf)) < 0)
863 goto out3;
864 msleep(5);
865 }
866
867 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x80, 0, 0, buf)) < 0) {
868 dbg("send AX_CMD_WRITE_RX_CTL failed: %d", ret);
869 goto out3;
870 }
871
872 /* Get the MAC address */
873 memset(buf, 0, ETH_ALEN);
874 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, 6, buf)) < 0) {
875 dbg("read AX_CMD_READ_NODE_ID failed: %d", ret);
876 goto out3;
877 }
878 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
879
880 /* Get the PHY id */
881 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf)) < 0) {
882 dbg("error on read AX_CMD_READ_PHY_ID: %02x", ret);
883 goto out3;
884 } else if (ret < 2) {
885 /* this should always return 2 bytes */
886 dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x", ret);
887 ret = -EIO;
888 goto out3;
889 }
890
891 /* Initialize MII structure */
892 dev->mii.dev = dev->net;
893 dev->mii.mdio_read = ax8817x_mdio_read;
894 dev->mii.mdio_write = ax8817x_mdio_write;
895 dev->mii.phy_id_mask = 0x3f;
896 dev->mii.reg_num_mask = 0x1f;
897 dev->mii.phy_id = *((u8 *)buf + 1);
898
899 dev->net->set_multicast_list = ax8817x_set_multicast;
900 dev->net->ethtool_ops = &ax8817x_ethtool_ops;
901
902 ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR,
903 cpu_to_le16(BMCR_RESET));
904 ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
905 cpu_to_le16(ADVERTISE_ALL | ADVERTISE_CSMA | 0x0400));
906 mii_nway_restart(&dev->mii);
907
908 if((ret = usb_submit_urb(data->int_urb, GFP_KERNEL)) < 0) {
909 dbg("Failed to submit interrupt URB: %02x", ret);
910 goto out2;
911 }
912
913 return 0;
914out3:
915 kfree(buf);
916out2:
917 kfree(data->int_buf);
918out1:
919 usb_free_urb(data->int_urb);
920 return ret;
921}
922
923static void ax8817x_unbind(struct usbnet *dev, struct usb_interface *intf)
924{
925 struct ax8817x_data *data = (struct ax8817x_data *)dev->data;
926
927 usb_kill_urb(data->int_urb);
928 usb_free_urb(data->int_urb);
929 kfree(data->int_buf);
930}
931
932static struct ethtool_ops ax88772_ethtool_ops = {
933 .get_drvinfo = ax8817x_get_drvinfo,
934 .get_link = ethtool_op_get_link,
935 .get_msglevel = usbnet_get_msglevel,
936 .set_msglevel = usbnet_set_msglevel,
937 .get_wol = ax8817x_get_wol,
938 .set_wol = ax8817x_set_wol,
939 .get_eeprom_len = ax8817x_get_eeprom_len,
940 .get_eeprom = ax8817x_get_eeprom,
941 .get_settings = ax8817x_get_settings,
942 .set_settings = ax8817x_set_settings,
943};
944
945static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
946{
947 int ret;
948 void *buf;
949 struct ax8817x_data *data = (struct ax8817x_data *)dev->data;
950
951 get_endpoints(dev,intf);
952
953 if ((data->int_urb = usb_alloc_urb (0, GFP_KERNEL)) == 0) {
954 dbg ("Cannot allocate interrupt URB");
955 ret = -ENOMEM;
956 goto out1;
957 }
958
959 if ((data->int_buf = kmalloc(AX_INTERRUPT_BUFSIZE, GFP_KERNEL)) == NULL) {
960 dbg ("Cannot allocate memory for interrupt buffer");
961 ret = -ENOMEM;
962 goto out1;
963 }
964 memset(data->int_buf, 0, AX_INTERRUPT_BUFSIZE);
965
966 usb_fill_int_urb (data->int_urb, dev->udev,
967 usb_rcvintpipe (dev->udev, 1),
968 data->int_buf, AX_INTERRUPT_BUFSIZE,
969 ax8817x_interrupt_complete, dev,
970 dev->udev->speed == USB_SPEED_HIGH ? 8 : 100);
971
972 buf = kmalloc(6, GFP_KERNEL);
973 if(!buf) {
974 dbg ("Cannot allocate memory for buffer");
975 ret = -ENOMEM;
976 goto out2;
977 }
978
979 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS,
980 0x00B0, 0, 0, buf)) < 0)
981 goto out3;
982
983 msleep(5);
984 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_PHY_SELECT, 0x0001, 0, 0, buf)) < 0) {
985 dbg("Select PHY #1 failed: %d", ret);
986 goto out3;
987 }
988
989 if ((ret =
990 ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPPD, 0, 0, buf)) < 0) {
991 dbg("Failed to power down internal PHY: %d", ret);
992 goto out3;
993 }
994
995 msleep(150);
996 if ((ret =
997 ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_CLEAR, 0, 0, buf)) < 0) {
998 dbg("Failed to perform software reset: %d", ret);
999 goto out3;
1000 }
1001
1002 msleep(150);
1003 if ((ret =
1004 ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPRL | AX_SWRESET_PRL, 0, 0, buf)) < 0) {
1005 dbg("Failed to set Internal/External PHY reset control: %d", ret);
1006 goto out3;
1007 }
1008
1009 msleep(150);
1010 if ((ret =
1011 ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x0000, 0, 0,
1012 buf)) < 0) {
1013 dbg("Failed to reset RX_CTL: %d", ret);
1014 goto out3;
1015 }
1016
1017 /* Get the MAC address */
1018 memset(buf, 0, ETH_ALEN);
1019 if ((ret = ax8817x_read_cmd(dev, AX88772_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf)) < 0) {
1020 dbg("Failed to read MAC address: %d", ret);
1021 goto out3;
1022 }
1023 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
1024
1025 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, buf)) < 0) {
1026 dbg("Enabling software MII failed: %d", ret);
1027 goto out3;
1028 }
1029
1030 if (((ret =
1031 ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, 0x0010, 2, 2, buf)) < 0)
1032 || (*((u16 *)buf) != 0x003b)) {
1033 dbg("Read PHY register 2 must be 0x3b00: %d", ret);
1034 goto out3;
1035 }
1036
1037 /* Initialize MII structure */
1038 dev->mii.dev = dev->net;
1039 dev->mii.mdio_read = ax8817x_mdio_read;
1040 dev->mii.mdio_write = ax8817x_mdio_write;
1041 dev->mii.phy_id_mask = 0xff;
1042 dev->mii.reg_num_mask = 0xff;
1043
1044 /* Get the PHY id */
1045 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf)) < 0) {
1046 dbg("Error reading PHY ID: %02x", ret);
1047 goto out3;
1048 } else if (ret < 2) {
1049 /* this should always return 2 bytes */
1050 dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x",
1051 ret);
1052 ret = -EIO;
1053 goto out3;
1054 }
1055 dev->mii.phy_id = *((u8 *)buf + 1);
1056
1057 if ((ret =
1058 ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_PRL, 0, 0, buf)) < 0) {
1059 dbg("Set external PHY reset pin level: %d", ret);
1060 goto out3;
1061 }
1062 msleep(150);
1063 if ((ret =
1064 ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPRL | AX_SWRESET_PRL, 0, 0, buf)) < 0) {
1065 dbg("Set Internal/External PHY reset control: %d", ret);
1066 goto out3;
1067 }
1068 msleep(150);
1069
1070
1071 dev->net->set_multicast_list = ax8817x_set_multicast;
1072 dev->net->ethtool_ops = &ax88772_ethtool_ops;
1073
1074 ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR,
1075 cpu_to_le16(BMCR_RESET));
1076 ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
1077 cpu_to_le16(ADVERTISE_ALL | ADVERTISE_CSMA));
1078 mii_nway_restart(&dev->mii);
1079
1080 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, 0x0336, 0, 0, buf)) < 0) {
1081 dbg("Write medium mode register: %d", ret);
1082 goto out3;
1083 }
1084
1085 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_IPG0, AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,AX88772_IPG2_DEFAULT, 0, buf)) < 0) {
1086 dbg("Write IPG,IPG1,IPG2 failed: %d", ret);
1087 goto out3;
1088 }
1089 if ((ret =
1090 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf)) < 0) {
1091 dbg("Failed to set hardware MII: %02x", ret);
1092 goto out3;
1093 }
1094
1095 /* Set RX_CTL to default values with 2k buffer, and enable cactus */
1096 if ((ret =
1097 ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x0088, 0, 0,
1098 buf)) < 0) {
1099 dbg("Reset RX_CTL failed: %d", ret);
1100 goto out3;
1101 }
1102
1103 if((ret = usb_submit_urb(data->int_urb, GFP_KERNEL)) < 0) {
1104 dbg("Failed to submit interrupt URB: %02x", ret);
1105 goto out3;
1106 }
1107
1108 kfree(buf);
1109
1110 return 0;
1111
1112out3:
1113 kfree(buf);
1114out2:
1115 kfree(data->int_buf);
1116out1:
1117 usb_free_urb(data->int_urb);
1118
1119 return ret;
1120}
1121
1122static int ax88772_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
1123{
1124 u32 *header;
1125 char *packet;
1126 struct sk_buff *ax_skb;
1127 u16 size;
1128
1129 header = (u32 *) skb->data;
1130 le32_to_cpus(header);
1131 packet = (char *)(header + 1);
1132
1133 skb_pull(skb, 4);
1134
1135 while (skb->len > 0) {
1136 if ((short)(*header & 0x0000ffff) !=
1137 ~((short)((*header & 0xffff0000) >> 16))) {
1138 devdbg(dev,"header length data is error");
1139 }
1140 /* get the packet length */
1141 size = (u16) (*header & 0x0000ffff);
1142
1143 if ((skb->len) - ((size + 1) & 0xfffe) == 0)
1144 return 2;
1145 if (size > ETH_FRAME_LEN) {
1146 devdbg(dev,"invalid rx length %d", size);
1147 return 0;
1148 }
1149 ax_skb = skb_clone(skb, GFP_ATOMIC);
1150 if (ax_skb) {
1151 ax_skb->len = size;
1152 ax_skb->data = packet;
1153 ax_skb->tail = packet + size;
1154 skb_return(dev, ax_skb);
1155 } else {
1156 return 0;
1157 }
1158
1159 skb_pull(skb, (size + 1) & 0xfffe);
1160
1161 if (skb->len == 0)
1162 break;
1163
1164 header = (u32 *) skb->data;
1165 le32_to_cpus(header);
1166 packet = (char *)(header + 1);
1167 skb_pull(skb, 4);
1168 }
1169
1170 if (skb->len < 0) {
1171 devdbg(dev,"invalid rx length %d", skb->len);
1172 return 0;
1173 }
1174 return 1;
1175}
1176
1177static struct sk_buff *ax88772_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
1178 int flags)
1179{
1180 int padlen;
1181 int headroom = skb_headroom(skb);
1182 int tailroom = skb_tailroom(skb);
1183 u32 *packet_len;
1184 u32 *padbytes_ptr;
1185
1186 padlen = ((skb->len + 4) % 512) ? 0 : 4;
1187
1188 if ((!skb_cloned(skb))
1189 && ((headroom + tailroom) >= (4 + padlen))) {
1190 if ((headroom < 4) || (tailroom < padlen)) {
1191 skb->data = memmove(skb->head + 4, skb->data, skb->len);
1192 skb->tail = skb->data + skb->len;
1193 }
1194 } else {
1195 struct sk_buff *skb2;
1196 skb2 = skb_copy_expand(skb, 4, padlen, flags);
1197 dev_kfree_skb_any(skb);
1198 skb = skb2;
1199 if (!skb)
1200 return NULL;
1201 }
1202
1203 packet_len = (u32 *) skb_push(skb, 4);
1204
1205 packet_len = (u32 *) skb->data;
1206 *packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4);
1207
1208 if ((skb->len % 512) == 0) {
1209 padbytes_ptr = (u32 *) skb->tail;
1210 *padbytes_ptr = 0xffff0000;
1211 skb_put(skb, padlen);
1212 }
1213 return skb;
1214}
1215
1216static const struct driver_info ax8817x_info = {
1217 .description = "ASIX AX8817x USB 2.0 Ethernet",
1218 .bind = ax8817x_bind,
1219 .unbind = ax8817x_unbind,
1220 .flags = FLAG_ETHER,
1221 .data = 0x00130103,
1222};
1223
1224static const struct driver_info dlink_dub_e100_info = {
1225 .description = "DLink DUB-E100 USB Ethernet",
1226 .bind = ax8817x_bind,
1227 .unbind = ax8817x_unbind,
1228 .flags = FLAG_ETHER,
1229 .data = 0x009f9d9f,
1230};
1231
1232static const struct driver_info netgear_fa120_info = {
1233 .description = "Netgear FA-120 USB Ethernet",
1234 .bind = ax8817x_bind,
1235 .unbind = ax8817x_unbind,
1236 .flags = FLAG_ETHER,
1237 .data = 0x00130103,
1238};
1239
1240static const struct driver_info hawking_uf200_info = {
1241 .description = "Hawking UF200 USB Ethernet",
1242 .bind = ax8817x_bind,
1243 .unbind = ax8817x_unbind,
1244 .flags = FLAG_ETHER,
1245 .data = 0x001f1d1f,
1246};
1247
1248static const struct driver_info ax88772_info = {
1249 .description = "ASIX AX88772 USB 2.0 Ethernet",
1250 .bind = ax88772_bind,
1251 .unbind = ax8817x_unbind,
1252 .flags = FLAG_ETHER | FLAG_FRAMING_AX,
1253 .rx_fixup = ax88772_rx_fixup,
1254 .tx_fixup = ax88772_tx_fixup,
1255 .data = 0x00130103,
1256};
1257
1258#endif /* CONFIG_USB_AX8817X */
1259
1260
1261
1262#ifdef CONFIG_USB_BELKIN
1263#define HAVE_HARDWARE
1264
1265/*-------------------------------------------------------------------------
1266 *
1267 * Belkin F5U104 ... two NetChip 2280 devices + Atmel microcontroller
1268 *
1269 * ... also two eTEK designs, including one sold as "Advance USBNET"
1270 *
1271 *-------------------------------------------------------------------------*/
1272
1273static const struct driver_info belkin_info = {
1274 .description = "Belkin, eTEK, or compatible",
1275};
1276
1277#endif /* CONFIG_USB_BELKIN */
1278
1279
1280
1281/*-------------------------------------------------------------------------
1282 *
1283 * Communications Device Class declarations.
1284 * Used by CDC Ethernet, and some CDC variants
1285 *
1286 *-------------------------------------------------------------------------*/
1287
1288#ifdef CONFIG_USB_CDCETHER
1289#define NEED_GENERIC_CDC
1290#endif
1291
1292#ifdef CONFIG_USB_ZAURUS
1293/* Ethernet variant uses funky framing, broken ethernet addressing */
1294#define NEED_GENERIC_CDC
1295#endif
1296
1297#ifdef CONFIG_USB_RNDIS
1298/* ACM variant uses even funkier framing, complex control RPC scheme */
1299#define NEED_GENERIC_CDC
1300#endif
1301
1302
1303#ifdef NEED_GENERIC_CDC
1304
1305#include <linux/usb_cdc.h>
1306
1307struct cdc_state {
1308 struct usb_cdc_header_desc *header;
1309 struct usb_cdc_union_desc *u;
1310 struct usb_cdc_ether_desc *ether;
1311 struct usb_interface *control;
1312 struct usb_interface *data;
1313};
1314
1315static struct usb_driver usbnet_driver;
1316
1317/*
1318 * probes control interface, claims data interface, collects the bulk
1319 * endpoints, activates data interface (if needed), maybe sets MTU.
1320 * all pure cdc, except for certain firmware workarounds.
1321 */
1322static int generic_cdc_bind (struct usbnet *dev, struct usb_interface *intf)
1323{
1324 u8 *buf = intf->cur_altsetting->extra;
1325 int len = intf->cur_altsetting->extralen;
1326 struct usb_interface_descriptor *d;
1327 struct cdc_state *info = (void *) &dev->data;
1328 int status;
1329 int rndis;
1330
1331 if (sizeof dev->data < sizeof *info)
1332 return -EDOM;
1333
1334 /* expect strict spec conformance for the descriptors, but
1335 * cope with firmware which stores them in the wrong place
1336 */
1337 if (len == 0 && dev->udev->actconfig->extralen) {
1338 /* Motorola SB4100 (and others: Brad Hards says it's
1339 * from a Broadcom design) put CDC descriptors here
1340 */
1341 buf = dev->udev->actconfig->extra;
1342 len = dev->udev->actconfig->extralen;
1343 if (len)
1344 dev_dbg (&intf->dev,
1345 "CDC descriptors on config\n");
1346 }
1347
1348 /* this assumes that if there's a non-RNDIS vendor variant
1349 * of cdc-acm, it'll fail RNDIS requests cleanly.
1350 */
1351 rndis = (intf->cur_altsetting->desc.bInterfaceProtocol == 0xff);
1352
1353 memset (info, 0, sizeof *info);
1354 info->control = intf;
1355 while (len > 3) {
1356 if (buf [1] != USB_DT_CS_INTERFACE)
1357 goto next_desc;
1358
1359 /* use bDescriptorSubType to identify the CDC descriptors.
1360 * We expect devices with CDC header and union descriptors.
1361 * For CDC Ethernet we need the ethernet descriptor.
1362 * For RNDIS, ignore two (pointless) CDC modem descriptors
1363 * in favor of a complicated OID-based RPC scheme doing what
1364 * CDC Ethernet achieves with a simple descriptor.
1365 */
1366 switch (buf [2]) {
1367 case USB_CDC_HEADER_TYPE:
1368 if (info->header) {
1369 dev_dbg (&intf->dev, "extra CDC header\n");
1370 goto bad_desc;
1371 }
1372 info->header = (void *) buf;
1373 if (info->header->bLength != sizeof *info->header) {
1374 dev_dbg (&intf->dev, "CDC header len %u\n",
1375 info->header->bLength);
1376 goto bad_desc;
1377 }
1378 break;
1379 case USB_CDC_UNION_TYPE:
1380 if (info->u) {
1381 dev_dbg (&intf->dev, "extra CDC union\n");
1382 goto bad_desc;
1383 }
1384 info->u = (void *) buf;
1385 if (info->u->bLength != sizeof *info->u) {
1386 dev_dbg (&intf->dev, "CDC union len %u\n",
1387 info->u->bLength);
1388 goto bad_desc;
1389 }
1390
1391 /* we need a master/control interface (what we're
1392 * probed with) and a slave/data interface; union
1393 * descriptors sort this all out.
1394 */
1395 info->control = usb_ifnum_to_if(dev->udev,
1396 info->u->bMasterInterface0);
1397 info->data = usb_ifnum_to_if(dev->udev,
1398 info->u->bSlaveInterface0);
1399 if (!info->control || !info->data) {
1400 dev_dbg (&intf->dev,
1401 "master #%u/%p slave #%u/%p\n",
1402 info->u->bMasterInterface0,
1403 info->control,
1404 info->u->bSlaveInterface0,
1405 info->data);
1406 goto bad_desc;
1407 }
1408 if (info->control != intf) {
1409 dev_dbg (&intf->dev, "bogus CDC Union\n");
1410 /* Ambit USB Cable Modem (and maybe others)
1411 * interchanges master and slave interface.
1412 */
1413 if (info->data == intf) {
1414 info->data = info->control;
1415 info->control = intf;
1416 } else
1417 goto bad_desc;
1418 }
1419
1420 /* a data interface altsetting does the real i/o */
1421 d = &info->data->cur_altsetting->desc;
1422 if (d->bInterfaceClass != USB_CLASS_CDC_DATA) {
1423 dev_dbg (&intf->dev, "slave class %u\n",
1424 d->bInterfaceClass);
1425 goto bad_desc;
1426 }
1427 break;
1428 case USB_CDC_ETHERNET_TYPE:
1429 if (info->ether) {
1430 dev_dbg (&intf->dev, "extra CDC ether\n");
1431 goto bad_desc;
1432 }
1433 info->ether = (void *) buf;
1434 if (info->ether->bLength != sizeof *info->ether) {
1435 dev_dbg (&intf->dev, "CDC ether len %u\n",
1436 info->u->bLength);
1437 goto bad_desc;
1438 }
1439 dev->net->mtu = le16_to_cpup (
1440 &info->ether->wMaxSegmentSize)
1441 - ETH_HLEN;
1442 /* because of Zaurus, we may be ignoring the host
1443 * side link address we were given.
1444 */
1445 break;
1446 }
1447next_desc:
1448 len -= buf [0]; /* bLength */
1449 buf += buf [0];
1450 }
1451
1452 if (!info->header || !info->u || (!rndis && !info->ether)) {
1453 dev_dbg (&intf->dev, "missing cdc %s%s%sdescriptor\n",
1454 info->header ? "" : "header ",
1455 info->u ? "" : "union ",
1456 info->ether ? "" : "ether ");
1457 goto bad_desc;
1458 }
1459
1460 /* claim data interface and set it up ... with side effects.
1461 * network traffic can't flow until an altsetting is enabled.
1462 */
1463 status = usb_driver_claim_interface (&usbnet_driver, info->data, dev);
1464 if (status < 0)
1465 return status;
1466 status = get_endpoints (dev, info->data);
1467 if (status < 0) {
1468 /* ensure immediate exit from usbnet_disconnect */
1469 usb_set_intfdata(info->data, NULL);
1470 usb_driver_release_interface (&usbnet_driver, info->data);
1471 return status;
1472 }
1473
1474 /* status endpoint: optional for CDC Ethernet, not RNDIS (or ACM) */
1475 dev->status = NULL;
1476 if (info->control->cur_altsetting->desc.bNumEndpoints == 1) {
1477 struct usb_endpoint_descriptor *desc;
1478
1479 dev->status = &info->control->cur_altsetting->endpoint [0];
1480 desc = &dev->status->desc;
1481 if (desc->bmAttributes != USB_ENDPOINT_XFER_INT
1482 || !(desc->bEndpointAddress & USB_DIR_IN)
1483 || (le16_to_cpu(desc->wMaxPacketSize)
1484 < sizeof (struct usb_cdc_notification))
1485 || !desc->bInterval) {
1486 dev_dbg (&intf->dev, "bad notification endpoint\n");
1487 dev->status = NULL;
1488 }
1489 }
1490 if (rndis && !dev->status) {
1491 dev_dbg (&intf->dev, "missing RNDIS status endpoint\n");
1492 usb_set_intfdata(info->data, NULL);
1493 usb_driver_release_interface (&usbnet_driver, info->data);
1494 return -ENODEV;
1495 }
1496 return 0;
1497
1498bad_desc:
1499 dev_info (&dev->udev->dev, "bad CDC descriptors\n");
1500 return -ENODEV;
1501}
1502
1503static void cdc_unbind (struct usbnet *dev, struct usb_interface *intf)
1504{
1505 struct cdc_state *info = (void *) &dev->data;
1506
1507 /* disconnect master --> disconnect slave */
1508 if (intf == info->control && info->data) {
1509 /* ensure immediate exit from usbnet_disconnect */
1510 usb_set_intfdata(info->data, NULL);
1511 usb_driver_release_interface (&usbnet_driver, info->data);
1512 info->data = NULL;
1513 }
1514
1515 /* and vice versa (just in case) */
1516 else if (intf == info->data && info->control) {
1517 /* ensure immediate exit from usbnet_disconnect */
1518 usb_set_intfdata(info->control, NULL);
1519 usb_driver_release_interface (&usbnet_driver, info->control);
1520 info->control = NULL;
1521 }
1522}
1523
1524
1525static void dumpspeed (struct usbnet *dev, __le32 *speeds)
1526{
1527 if (netif_msg_timer (dev))
1528 devinfo (dev, "link speeds: %u kbps up, %u kbps down",
1529 __le32_to_cpu(speeds[0]) / 1000,
1530 __le32_to_cpu(speeds[1]) / 1000);
1531}
1532
1533static void cdc_status (struct usbnet *dev, struct urb *urb)
1534{
1535 struct usb_cdc_notification *event;
1536
1537 if (urb->actual_length < sizeof *event)
1538 return;
1539
1540 /* SPEED_CHANGE can get split into two 8-byte packets */
1541 if (test_and_clear_bit (EVENT_STS_SPLIT, &dev->flags)) {
1542 dumpspeed (dev, (__le32 *) urb->transfer_buffer);
1543 return;
1544 }
1545
1546 event = urb->transfer_buffer;
1547 switch (event->bNotificationType) {
1548 case USB_CDC_NOTIFY_NETWORK_CONNECTION:
1549 if (netif_msg_timer (dev))
1550 devdbg (dev, "CDC: carrier %s",
1551 event->wValue ? "on" : "off");
1552 if (event->wValue)
1553 netif_carrier_on(dev->net);
1554 else
1555 netif_carrier_off(dev->net);
1556 break;
1557 case USB_CDC_NOTIFY_SPEED_CHANGE: /* tx/rx rates */
1558 if (netif_msg_timer (dev))
1559 devdbg (dev, "CDC: speed change (len %d)",
1560 urb->actual_length);
1561 if (urb->actual_length != (sizeof *event + 8))
1562 set_bit (EVENT_STS_SPLIT, &dev->flags);
1563 else
1564 dumpspeed (dev, (__le32 *) &event[1]);
1565 break;
1566 // case USB_CDC_NOTIFY_RESPONSE_AVAILABLE: /* RNDIS; or unsolicited */
1567 default:
1568 deverr (dev, "CDC: unexpected notification %02x!",
1569 event->bNotificationType);
1570 break;
1571 }
1572}
1573
1574#endif /* NEED_GENERIC_CDC */
1575
1576
1577#ifdef CONFIG_USB_CDCETHER
1578#define HAVE_HARDWARE
1579
1580/*-------------------------------------------------------------------------
1581 *
1582 * Communications Device Class, Ethernet Control model
1583 *
1584 * Takes two interfaces. The DATA interface is inactive till an altsetting
1585 * is selected. Configuration data includes class descriptors.
1586 *
1587 * This should interop with whatever the 2.4 "CDCEther.c" driver
1588 * (by Brad Hards) talked with.
1589 *
1590 *-------------------------------------------------------------------------*/
1591
1592#include <linux/ctype.h>
1593
1594static u8 nibble (unsigned char c)
1595{
1596 if (likely (isdigit (c)))
1597 return c - '0';
1598 c = toupper (c);
1599 if (likely (isxdigit (c)))
1600 return 10 + c - 'A';
1601 return 0;
1602}
1603
1604static inline int
1605get_ethernet_addr (struct usbnet *dev, struct usb_cdc_ether_desc *e)
1606{
1607 int tmp, i;
1608 unsigned char buf [13];
1609
1610 tmp = usb_string (dev->udev, e->iMACAddress, buf, sizeof buf);
1611 if (tmp != 12) {
1612 dev_dbg (&dev->udev->dev,
1613 "bad MAC string %d fetch, %d\n", e->iMACAddress, tmp);
1614 if (tmp >= 0)
1615 tmp = -EINVAL;
1616 return tmp;
1617 }
1618 for (i = tmp = 0; i < 6; i++, tmp += 2)
1619 dev->net->dev_addr [i] =
1620 (nibble (buf [tmp]) << 4) + nibble (buf [tmp + 1]);
1621 return 0;
1622}
1623
1624static int cdc_bind (struct usbnet *dev, struct usb_interface *intf)
1625{
1626 int status;
1627 struct cdc_state *info = (void *) &dev->data;
1628
1629 status = generic_cdc_bind (dev, intf);
1630 if (status < 0)
1631 return status;
1632
1633 status = get_ethernet_addr (dev, info->ether);
1634 if (status < 0) {
1635 usb_set_intfdata(info->data, NULL);
1636 usb_driver_release_interface (&usbnet_driver, info->data);
1637 return status;
1638 }
1639
1640 /* FIXME cdc-ether has some multicast code too, though it complains
1641 * in routine cases. info->ether describes the multicast support.
1642 */
1643 return 0;
1644}
1645
1646static const struct driver_info cdc_info = {
1647 .description = "CDC Ethernet Device",
1648 .flags = FLAG_ETHER,
1649 // .check_connect = cdc_check_connect,
1650 .bind = cdc_bind,
1651 .unbind = cdc_unbind,
1652 .status = cdc_status,
1653};
1654
1655#endif /* CONFIG_USB_CDCETHER */
1656
1657
1658
1659#ifdef CONFIG_USB_EPSON2888
1660#define HAVE_HARDWARE
1661
1662/*-------------------------------------------------------------------------
1663 *
1664 * EPSON USB clients
1665 *
1666 * This is the same idea as Linux PDAs (below) except the firmware in the
1667 * device might not be Tux-powered. Epson provides reference firmware that
1668 * implements this interface. Product developers can reuse or modify that
1669 * code, such as by using their own product and vendor codes.
1670 *
1671 * Support was from Juro Bystricky <bystricky.juro@erd.epson.com>
1672 *
1673 *-------------------------------------------------------------------------*/
1674
1675static const struct driver_info epson2888_info = {
1676 .description = "Epson USB Device",
1677 .check_connect = always_connected,
1678
1679 .in = 4, .out = 3,
1680};
1681
1682#endif /* CONFIG_USB_EPSON2888 */
1683
1684
1685#ifdef CONFIG_USB_GENESYS
1686#define HAVE_HARDWARE
1687
1688/*-------------------------------------------------------------------------
1689 *
1690 * GeneSys GL620USB-A (www.genesyslogic.com.tw)
1691 *
1692 * ... should partially interop with the Win32 driver for this hardware
1693 * The GeneSys docs imply there's some NDIS issue motivating this framing.
1694 *
1695 * Some info from GeneSys:
1696 * - GL620USB-A is full duplex; GL620USB is only half duplex for bulk.
1697 * (Some cables, like the BAFO-100c, use the half duplex version.)
1698 * - For the full duplex model, the low bit of the version code says
1699 * which side is which ("left/right").
1700 * - For the half duplex type, a control/interrupt handshake settles
1701 * the transfer direction. (That's disabled here, partially coded.)
1702 * A control URB would block until other side writes an interrupt.
1703 *
1704 * Original code from Jiun-Jie Huang <huangjj@genesyslogic.com.tw>
1705 * and merged into "usbnet" by Stanislav Brabec <utx@penguin.cz>.
1706 *
1707 *-------------------------------------------------------------------------*/
1708
1709// control msg write command
1710#define GENELINK_CONNECT_WRITE 0xF0
1711// interrupt pipe index
1712#define GENELINK_INTERRUPT_PIPE 0x03
1713// interrupt read buffer size
1714#define INTERRUPT_BUFSIZE 0x08
1715// interrupt pipe interval value
1716#define GENELINK_INTERRUPT_INTERVAL 0x10
1717// max transmit packet number per transmit
1718#define GL_MAX_TRANSMIT_PACKETS 32
1719// max packet length
1720#define GL_MAX_PACKET_LEN 1514
1721// max receive buffer size
1722#define GL_RCV_BUF_SIZE \
1723 (((GL_MAX_PACKET_LEN + 4) * GL_MAX_TRANSMIT_PACKETS) + 4)
1724
1725struct gl_packet {
1726 u32 packet_length;
1727 char packet_data [1];
1728};
1729
1730struct gl_header {
1731 u32 packet_count;
1732 struct gl_packet packets;
1733};
1734
1735#ifdef GENELINK_ACK
1736
1737// FIXME: this code is incomplete, not debugged; it doesn't
1738// handle interrupts correctly. interrupts should be generic
1739// code like all other device I/O, anyway.
1740
1741struct gl_priv {
1742 struct urb *irq_urb;
1743 char irq_buf [INTERRUPT_BUFSIZE];
1744};
1745
1746static inline int gl_control_write (struct usbnet *dev, u8 request, u16 value)
1747{
1748 int retval;
1749
1750 retval = usb_control_msg (dev->udev,
1751 usb_sndctrlpipe (dev->udev, 0),
1752 request,
1753 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
1754 value,
1755 0, // index
1756 0, // data buffer
1757 0, // size
1758 CONTROL_TIMEOUT_MS);
1759 return retval;
1760}
1761
1762static void gl_interrupt_complete (struct urb *urb, struct pt_regs *regs)
1763{
1764 int status = urb->status;
1765
1766 switch (status) {
1767 case 0:
1768 /* success */
1769 break;
1770 case -ECONNRESET:
1771 case -ENOENT:
1772 case -ESHUTDOWN:
1773 /* this urb is terminated, clean up */
1774 dbg("%s - urb shutting down with status: %d",
1775 __FUNCTION__, status);
1776 return;
1777 default:
1778 dbg("%s - nonzero urb status received: %d",
1779 __FUNCTION__, urb->status);
1780 }
1781
1782 status = usb_submit_urb (urb, GFP_ATOMIC);
1783 if (status)
1784 err ("%s - usb_submit_urb failed with result %d",
1785 __FUNCTION__, status);
1786}
1787
1788static int gl_interrupt_read (struct usbnet *dev)
1789{
1790 struct gl_priv *priv = dev->priv_data;
1791 int retval;
1792
1793 // issue usb interrupt read
1794 if (priv && priv->irq_urb) {
1795 // submit urb
1796 if ((retval = usb_submit_urb (priv->irq_urb, GFP_KERNEL)) != 0)
1797 dbg ("gl_interrupt_read: submit fail - %X...", retval);
1798 else
1799 dbg ("gl_interrupt_read: submit success...");
1800 }
1801
1802 return 0;
1803}
1804
1805// check whether another side is connected
1806static int genelink_check_connect (struct usbnet *dev)
1807{
1808 int retval;
1809
1810 dbg ("genelink_check_connect...");
1811
1812 // detect whether another side is connected
1813 if ((retval = gl_control_write (dev, GENELINK_CONNECT_WRITE, 0)) != 0) {
1814 dbg ("%s: genelink_check_connect write fail - %X",
1815 dev->net->name, retval);
1816 return retval;
1817 }
1818
1819 // usb interrupt read to ack another side
1820 if ((retval = gl_interrupt_read (dev)) != 0) {
1821 dbg ("%s: genelink_check_connect read fail - %X",
1822 dev->net->name, retval);
1823 return retval;
1824 }
1825
1826 dbg ("%s: genelink_check_connect read success", dev->net->name);
1827 return 0;
1828}
1829
1830// allocate and initialize the private data for genelink
1831static int genelink_init (struct usbnet *dev)
1832{
1833 struct gl_priv *priv;
1834
1835 // allocate the private data structure
1836 if ((priv = kmalloc (sizeof *priv, GFP_KERNEL)) == 0) {
1837 dbg ("%s: cannot allocate private data per device",
1838 dev->net->name);
1839 return -ENOMEM;
1840 }
1841
1842 // allocate irq urb
1843 if ((priv->irq_urb = usb_alloc_urb (0, GFP_KERNEL)) == 0) {
1844 dbg ("%s: cannot allocate private irq urb per device",
1845 dev->net->name);
1846 kfree (priv);
1847 return -ENOMEM;
1848 }
1849
1850 // fill irq urb
1851 usb_fill_int_urb (priv->irq_urb, dev->udev,
1852 usb_rcvintpipe (dev->udev, GENELINK_INTERRUPT_PIPE),
1853 priv->irq_buf, INTERRUPT_BUFSIZE,
1854 gl_interrupt_complete, 0,
1855 GENELINK_INTERRUPT_INTERVAL);
1856
1857 // set private data pointer
1858 dev->priv_data = priv;
1859
1860 return 0;
1861}
1862
1863// release the private data
1864static int genelink_free (struct usbnet *dev)
1865{
1866 struct gl_priv *priv = dev->priv_data;
1867
1868 if (!priv)
1869 return 0;
1870
1871// FIXME: can't cancel here; it's synchronous, and
1872// should have happened earlier in any case (interrupt
1873// handling needs to be generic)
1874
1875 // cancel irq urb first
1876 usb_kill_urb (priv->irq_urb);
1877
1878 // free irq urb
1879 usb_free_urb (priv->irq_urb);
1880
1881 // free the private data structure
1882 kfree (priv);
1883
1884 return 0;
1885}
1886
1887#endif
1888
1889static int genelink_rx_fixup (struct usbnet *dev, struct sk_buff *skb)
1890{
1891 struct gl_header *header;
1892 struct gl_packet *packet;
1893 struct sk_buff *gl_skb;
1894 u32 size;
1895
1896 header = (struct gl_header *) skb->data;
1897
1898 // get the packet count of the received skb
1899 le32_to_cpus (&header->packet_count);
1900 if ((header->packet_count > GL_MAX_TRANSMIT_PACKETS)
1901 || (header->packet_count < 0)) {
1902 dbg ("genelink: invalid received packet count %d",
1903 header->packet_count);
1904 return 0;
1905 }
1906
1907 // set the current packet pointer to the first packet
1908 packet = &header->packets;
1909
1910 // decrement the length for the packet count size 4 bytes
1911 skb_pull (skb, 4);
1912
1913 while (header->packet_count > 1) {
1914 // get the packet length
1915 size = packet->packet_length;
1916
1917 // this may be a broken packet
1918 if (size > GL_MAX_PACKET_LEN) {
1919 dbg ("genelink: invalid rx length %d", size);
1920 return 0;
1921 }
1922
1923 // allocate the skb for the individual packet
1924 gl_skb = alloc_skb (size, GFP_ATOMIC);
1925 if (gl_skb) {
1926
1927 // copy the packet data to the new skb
1928 memcpy(skb_put(gl_skb, size), packet->packet_data, size);
1929 skb_return (dev, skb);
1930 }
1931
1932 // advance to the next packet
1933 packet = (struct gl_packet *)
1934 &packet->packet_data [size];
1935 header->packet_count--;
1936
1937 // shift the data pointer to the next gl_packet
1938 skb_pull (skb, size + 4);
1939 }
1940
1941 // skip the packet length field 4 bytes
1942 skb_pull (skb, 4);
1943
1944 if (skb->len > GL_MAX_PACKET_LEN) {
1945 dbg ("genelink: invalid rx length %d", skb->len);
1946 return 0;
1947 }
1948 return 1;
1949}
1950
1951static struct sk_buff *
1952genelink_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags)
1953{
1954 int padlen;
1955 int length = skb->len;
1956 int headroom = skb_headroom (skb);
1957 int tailroom = skb_tailroom (skb);
1958 u32 *packet_count;
1959 u32 *packet_len;
1960
1961 // FIXME: magic numbers, bleech
1962 padlen = ((skb->len + (4 + 4*1)) % 64) ? 0 : 1;
1963
1964 if ((!skb_cloned (skb))
1965 && ((headroom + tailroom) >= (padlen + (4 + 4*1)))) {
1966 if ((headroom < (4 + 4*1)) || (tailroom < padlen)) {
1967 skb->data = memmove (skb->head + (4 + 4*1),
1968 skb->data, skb->len);
1969 skb->tail = skb->data + skb->len;
1970 }
1971 } else {
1972 struct sk_buff *skb2;
1973 skb2 = skb_copy_expand (skb, (4 + 4*1) , padlen, flags);
1974 dev_kfree_skb_any (skb);
1975 skb = skb2;
1976 if (!skb)
1977 return NULL;
1978 }
1979
1980 // attach the packet count to the header
1981 packet_count = (u32 *) skb_push (skb, (4 + 4*1));
1982 packet_len = packet_count + 1;
1983
1984 // FIXME little endian?
1985 *packet_count = 1;
1986 *packet_len = length;
1987
1988 // add padding byte
1989 if ((skb->len % dev->maxpacket) == 0)
1990 skb_put (skb, 1);
1991
1992 return skb;
1993}
1994
1995static const struct driver_info genelink_info = {
1996 .description = "Genesys GeneLink",
1997 .flags = FLAG_FRAMING_GL | FLAG_NO_SETINT,
1998 .rx_fixup = genelink_rx_fixup,
1999 .tx_fixup = genelink_tx_fixup,
2000
2001 .in = 1, .out = 2,
2002
2003#ifdef GENELINK_ACK
2004 .check_connect =genelink_check_connect,
2005#endif
2006};
2007
2008#endif /* CONFIG_USB_GENESYS */
2009
2010
2011
2012#ifdef CONFIG_USB_NET1080
2013#define HAVE_HARDWARE
2014
2015/*-------------------------------------------------------------------------
2016 *
2017 * Netchip 1080 driver ... http://www.netchip.com
2018 * Used in LapLink cables
2019 *
2020 *-------------------------------------------------------------------------*/
2021
2022#define dev_packet_id data[0]
2023#define frame_errors data[1]
2024
2025/*
2026 * NetChip framing of ethernet packets, supporting additional error
2027 * checks for links that may drop bulk packets from inside messages.
2028 * Odd USB length == always short read for last usb packet.
2029 * - nc_header
2030 * - Ethernet header (14 bytes)
2031 * - payload
2032 * - (optional padding byte, if needed so length becomes odd)
2033 * - nc_trailer
2034 *
2035 * This framing is to be avoided for non-NetChip devices.
2036 */
2037
2038struct nc_header { // packed:
2039 __le16 hdr_len; // sizeof nc_header (LE, all)
2040 __le16 packet_len; // payload size (including ethhdr)
2041 __le16 packet_id; // detects dropped packets
2042#define MIN_HEADER 6
2043
2044 // all else is optional, and must start with:
2045 // u16 vendorId; // from usb-if
2046 // u16 productId;
2047} __attribute__((__packed__));
2048
2049#define PAD_BYTE ((unsigned char)0xAC)
2050
2051struct nc_trailer {
2052 __le16 packet_id;
2053} __attribute__((__packed__));
2054
2055// packets may use FLAG_FRAMING_NC and optional pad
2056#define FRAMED_SIZE(mtu) (sizeof (struct nc_header) \
2057 + sizeof (struct ethhdr) \
2058 + (mtu) \
2059 + 1 \
2060 + sizeof (struct nc_trailer))
2061
2062#define MIN_FRAMED FRAMED_SIZE(0)
2063
2064
2065/*
2066 * Zero means no timeout; else, how long a 64 byte bulk packet may be queued
2067 * before the hardware drops it. If that's done, the driver will need to
2068 * frame network packets to guard against the dropped USB packets. The win32
2069 * driver sets this for both sides of the link.
2070 */
2071#define NC_READ_TTL_MS ((u8)255) // ms
2072
2073/*
2074 * We ignore most registers and EEPROM contents.
2075 */
2076#define REG_USBCTL ((u8)0x04)
2077#define REG_TTL ((u8)0x10)
2078#define REG_STATUS ((u8)0x11)
2079
2080/*
2081 * Vendor specific requests to read/write data
2082 */
2083#define REQUEST_REGISTER ((u8)0x10)
2084#define REQUEST_EEPROM ((u8)0x11)
2085
2086static int
2087nc_vendor_read (struct usbnet *dev, u8 req, u8 regnum, u16 *retval_ptr)
2088{
2089 int status = usb_control_msg (dev->udev,
2090 usb_rcvctrlpipe (dev->udev, 0),
2091 req,
2092 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2093 0, regnum,
2094 retval_ptr, sizeof *retval_ptr,
2095 CONTROL_TIMEOUT_MS);
2096 if (status > 0)
2097 status = 0;
2098 if (!status)
2099 le16_to_cpus (retval_ptr);
2100 return status;
2101}
2102
2103static inline int
2104nc_register_read (struct usbnet *dev, u8 regnum, u16 *retval_ptr)
2105{
2106 return nc_vendor_read (dev, REQUEST_REGISTER, regnum, retval_ptr);
2107}
2108
2109// no retval ... can become async, usable in_interrupt()
2110static void
2111nc_vendor_write (struct usbnet *dev, u8 req, u8 regnum, u16 value)
2112{
2113 usb_control_msg (dev->udev,
2114 usb_sndctrlpipe (dev->udev, 0),
2115 req,
2116 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2117 value, regnum,
2118 NULL, 0, // data is in setup packet
2119 CONTROL_TIMEOUT_MS);
2120}
2121
2122static inline void
2123nc_register_write (struct usbnet *dev, u8 regnum, u16 value)
2124{
2125 nc_vendor_write (dev, REQUEST_REGISTER, regnum, value);
2126}
2127
2128
2129#if 0
2130static void nc_dump_registers (struct usbnet *dev)
2131{
2132 u8 reg;
2133 u16 *vp = kmalloc (sizeof (u16));
2134
2135 if (!vp) {
2136 dbg ("no memory?");
2137 return;
2138 }
2139
2140 dbg ("%s registers:", dev->net->name);
2141 for (reg = 0; reg < 0x20; reg++) {
2142 int retval;
2143
2144 // reading some registers is trouble
2145 if (reg >= 0x08 && reg <= 0xf)
2146 continue;
2147 if (reg >= 0x12 && reg <= 0x1e)
2148 continue;
2149
2150 retval = nc_register_read (dev, reg, vp);
2151 if (retval < 0)
2152 dbg ("%s reg [0x%x] ==> error %d",
2153 dev->net->name, reg, retval);
2154 else
2155 dbg ("%s reg [0x%x] = 0x%x",
2156 dev->net->name, reg, *vp);
2157 }
2158 kfree (vp);
2159}
2160#endif
2161
2162
2163/*-------------------------------------------------------------------------*/
2164
2165/*
2166 * Control register
2167 */
2168
2169#define USBCTL_WRITABLE_MASK 0x1f0f
2170// bits 15-13 reserved, r/o
2171#define USBCTL_ENABLE_LANG (1 << 12)
2172#define USBCTL_ENABLE_MFGR (1 << 11)
2173#define USBCTL_ENABLE_PROD (1 << 10)
2174#define USBCTL_ENABLE_SERIAL (1 << 9)
2175#define USBCTL_ENABLE_DEFAULTS (1 << 8)
2176// bits 7-4 reserved, r/o
2177#define USBCTL_FLUSH_OTHER (1 << 3)
2178#define USBCTL_FLUSH_THIS (1 << 2)
2179#define USBCTL_DISCONN_OTHER (1 << 1)
2180#define USBCTL_DISCONN_THIS (1 << 0)
2181
2182static inline void nc_dump_usbctl (struct usbnet *dev, u16 usbctl)
2183{
2184 if (!netif_msg_link (dev))
2185 return;
2186 devdbg (dev, "net1080 %s-%s usbctl 0x%x:%s%s%s%s%s;"
2187 " this%s%s;"
2188 " other%s%s; r/o 0x%x",
2189 dev->udev->bus->bus_name, dev->udev->devpath,
2190 usbctl,
2191 (usbctl & USBCTL_ENABLE_LANG) ? " lang" : "",
2192 (usbctl & USBCTL_ENABLE_MFGR) ? " mfgr" : "",
2193 (usbctl & USBCTL_ENABLE_PROD) ? " prod" : "",
2194 (usbctl & USBCTL_ENABLE_SERIAL) ? " serial" : "",
2195 (usbctl & USBCTL_ENABLE_DEFAULTS) ? " defaults" : "",
2196
2197 (usbctl & USBCTL_FLUSH_OTHER) ? " FLUSH" : "",
2198 (usbctl & USBCTL_DISCONN_OTHER) ? " DIS" : "",
2199 (usbctl & USBCTL_FLUSH_THIS) ? " FLUSH" : "",
2200 (usbctl & USBCTL_DISCONN_THIS) ? " DIS" : "",
2201 usbctl & ~USBCTL_WRITABLE_MASK
2202 );
2203}
2204
2205/*-------------------------------------------------------------------------*/
2206
2207/*
2208 * Status register
2209 */
2210
2211#define STATUS_PORT_A (1 << 15)
2212
2213#define STATUS_CONN_OTHER (1 << 14)
2214#define STATUS_SUSPEND_OTHER (1 << 13)
2215#define STATUS_MAILBOX_OTHER (1 << 12)
2216#define STATUS_PACKETS_OTHER(n) (((n) >> 8) && 0x03)
2217
2218#define STATUS_CONN_THIS (1 << 6)
2219#define STATUS_SUSPEND_THIS (1 << 5)
2220#define STATUS_MAILBOX_THIS (1 << 4)
2221#define STATUS_PACKETS_THIS(n) (((n) >> 0) && 0x03)
2222
2223#define STATUS_UNSPEC_MASK 0x0c8c
2224#define STATUS_NOISE_MASK ((u16)~(0x0303|STATUS_UNSPEC_MASK))
2225
2226
2227static inline void nc_dump_status (struct usbnet *dev, u16 status)
2228{
2229 if (!netif_msg_link (dev))
2230 return;
2231 devdbg (dev, "net1080 %s-%s status 0x%x:"
2232 " this (%c) PKT=%d%s%s%s;"
2233 " other PKT=%d%s%s%s; unspec 0x%x",
2234 dev->udev->bus->bus_name, dev->udev->devpath,
2235 status,
2236
2237 // XXX the packet counts don't seem right
2238 // (1 at reset, not 0); maybe UNSPEC too
2239
2240 (status & STATUS_PORT_A) ? 'A' : 'B',
2241 STATUS_PACKETS_THIS (status),
2242 (status & STATUS_CONN_THIS) ? " CON" : "",
2243 (status & STATUS_SUSPEND_THIS) ? " SUS" : "",
2244 (status & STATUS_MAILBOX_THIS) ? " MBOX" : "",
2245
2246 STATUS_PACKETS_OTHER (status),
2247 (status & STATUS_CONN_OTHER) ? " CON" : "",
2248 (status & STATUS_SUSPEND_OTHER) ? " SUS" : "",
2249 (status & STATUS_MAILBOX_OTHER) ? " MBOX" : "",
2250
2251 status & STATUS_UNSPEC_MASK
2252 );
2253}
2254
2255/*-------------------------------------------------------------------------*/
2256
2257/*
2258 * TTL register
2259 */
2260
2261#define TTL_THIS(ttl) (0x00ff & ttl)
2262#define TTL_OTHER(ttl) (0x00ff & (ttl >> 8))
2263#define MK_TTL(this,other) ((u16)(((other)<<8)|(0x00ff&(this))))
2264
2265static inline void nc_dump_ttl (struct usbnet *dev, u16 ttl)
2266{
2267 if (netif_msg_link (dev))
2268 devdbg (dev, "net1080 %s-%s ttl 0x%x this = %d, other = %d",
2269 dev->udev->bus->bus_name, dev->udev->devpath,
2270 ttl, TTL_THIS (ttl), TTL_OTHER (ttl));
2271}
2272
2273/*-------------------------------------------------------------------------*/
2274
2275static int net1080_reset (struct usbnet *dev)
2276{
2277 u16 usbctl, status, ttl;
2278 u16 *vp = kmalloc (sizeof (u16), GFP_KERNEL);
2279 int retval;
2280
2281 if (!vp)
2282 return -ENOMEM;
2283
2284 // nc_dump_registers (dev);
2285
2286 if ((retval = nc_register_read (dev, REG_STATUS, vp)) < 0) {
2287 dbg ("can't read %s-%s status: %d",
2288 dev->udev->bus->bus_name, dev->udev->devpath, retval);
2289 goto done;
2290 }
2291 status = *vp;
2292 nc_dump_status (dev, status);
2293
2294 if ((retval = nc_register_read (dev, REG_USBCTL, vp)) < 0) {
2295 dbg ("can't read USBCTL, %d", retval);
2296 goto done;
2297 }
2298 usbctl = *vp;
2299 nc_dump_usbctl (dev, usbctl);
2300
2301 nc_register_write (dev, REG_USBCTL,
2302 USBCTL_FLUSH_THIS | USBCTL_FLUSH_OTHER);
2303
2304 if ((retval = nc_register_read (dev, REG_TTL, vp)) < 0) {
2305 dbg ("can't read TTL, %d", retval);
2306 goto done;
2307 }
2308 ttl = *vp;
2309 // nc_dump_ttl (dev, ttl);
2310
2311 nc_register_write (dev, REG_TTL,
2312 MK_TTL (NC_READ_TTL_MS, TTL_OTHER (ttl)) );
2313 dbg ("%s: assigned TTL, %d ms", dev->net->name, NC_READ_TTL_MS);
2314
2315 if (netif_msg_link (dev))
2316 devinfo (dev, "port %c, peer %sconnected",
2317 (status & STATUS_PORT_A) ? 'A' : 'B',
2318 (status & STATUS_CONN_OTHER) ? "" : "dis"
2319 );
2320 retval = 0;
2321
2322done:
2323 kfree (vp);
2324 return retval;
2325}
2326
2327static int net1080_check_connect (struct usbnet *dev)
2328{
2329 int retval;
2330 u16 status;
2331 u16 *vp = kmalloc (sizeof (u16), GFP_KERNEL);
2332
2333 if (!vp)
2334 return -ENOMEM;
2335 retval = nc_register_read (dev, REG_STATUS, vp);
2336 status = *vp;
2337 kfree (vp);
2338 if (retval != 0) {
2339 dbg ("%s net1080_check_conn read - %d", dev->net->name, retval);
2340 return retval;
2341 }
2342 if ((status & STATUS_CONN_OTHER) != STATUS_CONN_OTHER)
2343 return -ENOLINK;
2344 return 0;
2345}
2346
2347static void nc_flush_complete (struct urb *urb, struct pt_regs *regs)
2348{
2349 kfree (urb->context);
2350 usb_free_urb(urb);
2351}
2352
2353static void nc_ensure_sync (struct usbnet *dev)
2354{
2355 dev->frame_errors++;
2356 if (dev->frame_errors > 5) {
2357 struct urb *urb;
2358 struct usb_ctrlrequest *req;
2359 int status;
2360
2361 /* Send a flush */
2362 urb = usb_alloc_urb (0, SLAB_ATOMIC);
2363 if (!urb)
2364 return;
2365
2366 req = kmalloc (sizeof *req, GFP_ATOMIC);
2367 if (!req) {
2368 usb_free_urb (urb);
2369 return;
2370 }
2371
2372 req->bRequestType = USB_DIR_OUT
2373 | USB_TYPE_VENDOR
2374 | USB_RECIP_DEVICE;
2375 req->bRequest = REQUEST_REGISTER;
2376 req->wValue = cpu_to_le16 (USBCTL_FLUSH_THIS
2377 | USBCTL_FLUSH_OTHER);
2378 req->wIndex = cpu_to_le16 (REG_USBCTL);
2379 req->wLength = cpu_to_le16 (0);
2380
2381 /* queue an async control request, we don't need
2382 * to do anything when it finishes except clean up.
2383 */
2384 usb_fill_control_urb (urb, dev->udev,
2385 usb_sndctrlpipe (dev->udev, 0),
2386 (unsigned char *) req,
2387 NULL, 0,
2388 nc_flush_complete, req);
2389 status = usb_submit_urb (urb, GFP_ATOMIC);
2390 if (status) {
2391 kfree (req);
2392 usb_free_urb (urb);
2393 return;
2394 }
2395
2396 if (netif_msg_rx_err (dev))
2397 devdbg (dev, "flush net1080; too many framing errors");
2398 dev->frame_errors = 0;
2399 }
2400}
2401
2402static int net1080_rx_fixup (struct usbnet *dev, struct sk_buff *skb)
2403{
2404 struct nc_header *header;
2405 struct nc_trailer *trailer;
2406 u16 hdr_len, packet_len;
2407
2408 if (!(skb->len & 0x01)
2409 || MIN_FRAMED > skb->len
2410 || skb->len > FRAMED_SIZE (dev->net->mtu)) {
2411 dev->stats.rx_frame_errors++;
2412 dbg ("rx framesize %d range %d..%d mtu %d", skb->len,
2413 (int)MIN_FRAMED, (int)FRAMED_SIZE (dev->net->mtu),
2414 dev->net->mtu);
2415 nc_ensure_sync (dev);
2416 return 0;
2417 }
2418
2419 header = (struct nc_header *) skb->data;
2420 hdr_len = le16_to_cpup (&header->hdr_len);
2421 packet_len = le16_to_cpup (&header->packet_len);
2422 if (FRAMED_SIZE (packet_len) > MAX_PACKET) {
2423 dev->stats.rx_frame_errors++;
2424 dbg ("packet too big, %d", packet_len);
2425 nc_ensure_sync (dev);
2426 return 0;
2427 } else if (hdr_len < MIN_HEADER) {
2428 dev->stats.rx_frame_errors++;
2429 dbg ("header too short, %d", hdr_len);
2430 nc_ensure_sync (dev);
2431 return 0;
2432 } else if (hdr_len > MIN_HEADER) {
2433 // out of band data for us?
2434 dbg ("header OOB, %d bytes", hdr_len - MIN_HEADER);
2435 nc_ensure_sync (dev);
2436 // switch (vendor/product ids) { ... }
2437 }
2438 skb_pull (skb, hdr_len);
2439
2440 trailer = (struct nc_trailer *)
2441 (skb->data + skb->len - sizeof *trailer);
2442 skb_trim (skb, skb->len - sizeof *trailer);
2443
2444 if ((packet_len & 0x01) == 0) {
2445 if (skb->data [packet_len] != PAD_BYTE) {
2446 dev->stats.rx_frame_errors++;
2447 dbg ("bad pad");
2448 return 0;
2449 }
2450 skb_trim (skb, skb->len - 1);
2451 }
2452 if (skb->len != packet_len) {
2453 dev->stats.rx_frame_errors++;
2454 dbg ("bad packet len %d (expected %d)",
2455 skb->len, packet_len);
2456 nc_ensure_sync (dev);
2457 return 0;
2458 }
2459 if (header->packet_id != get_unaligned (&trailer->packet_id)) {
2460 dev->stats.rx_fifo_errors++;
2461 dbg ("(2+ dropped) rx packet_id mismatch 0x%x 0x%x",
2462 le16_to_cpu (header->packet_id),
2463 le16_to_cpu (trailer->packet_id));
2464 return 0;
2465 }
2466#if 0
2467 devdbg (dev, "frame <rx h %d p %d id %d", header->hdr_len,
2468 header->packet_len, header->packet_id);
2469#endif
2470 dev->frame_errors = 0;
2471 return 1;
2472}
2473
2474static struct sk_buff *
2475net1080_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags)
2476{
2477 int padlen;
2478 struct sk_buff *skb2;
2479
2480 padlen = ((skb->len + sizeof (struct nc_header)
2481 + sizeof (struct nc_trailer)) & 0x01) ? 0 : 1;
2482 if (!skb_cloned (skb)) {
2483 int headroom = skb_headroom (skb);
2484 int tailroom = skb_tailroom (skb);
2485
2486 if ((padlen + sizeof (struct nc_trailer)) <= tailroom
2487 && sizeof (struct nc_header) <= headroom)
2488 /* There's enough head and tail room */
2489 return skb;
2490
2491 if ((sizeof (struct nc_header) + padlen
2492 + sizeof (struct nc_trailer)) <
2493 (headroom + tailroom)) {
2494 /* There's enough total room, so just readjust */
2495 skb->data = memmove (skb->head
2496 + sizeof (struct nc_header),
2497 skb->data, skb->len);
2498 skb->tail = skb->data + skb->len;
2499 return skb;
2500 }
2501 }
2502
2503 /* Create a new skb to use with the correct size */
2504 skb2 = skb_copy_expand (skb,
2505 sizeof (struct nc_header),
2506 sizeof (struct nc_trailer) + padlen,
2507 flags);
2508 dev_kfree_skb_any (skb);
2509 return skb2;
2510}
2511
2512static const struct driver_info net1080_info = {
2513 .description = "NetChip TurboCONNECT",
2514 .flags = FLAG_FRAMING_NC,
2515 .reset = net1080_reset,
2516 .check_connect =net1080_check_connect,
2517 .rx_fixup = net1080_rx_fixup,
2518 .tx_fixup = net1080_tx_fixup,
2519};
2520
2521#endif /* CONFIG_USB_NET1080 */
2522
2523
2524
2525#ifdef CONFIG_USB_PL2301
2526#define HAVE_HARDWARE
2527
2528/*-------------------------------------------------------------------------
2529 *
2530 * Prolific PL-2301/PL-2302 driver ... http://www.prolifictech.com
2531 *
2532 * The protocol and handshaking used here should be bug-compatible
2533 * with the Linux 2.2 "plusb" driver, by Deti Fliegl.
2534 *
2535 *-------------------------------------------------------------------------*/
2536
2537/*
2538 * Bits 0-4 can be used for software handshaking; they're set from
2539 * one end, cleared from the other, "read" with the interrupt byte.
2540 */
2541#define PL_S_EN (1<<7) /* (feature only) suspend enable */
2542/* reserved bit -- rx ready (6) ? */
2543#define PL_TX_READY (1<<5) /* (interrupt only) transmit ready */
2544#define PL_RESET_OUT (1<<4) /* reset output pipe */
2545#define PL_RESET_IN (1<<3) /* reset input pipe */
2546#define PL_TX_C (1<<2) /* transmission complete */
2547#define PL_TX_REQ (1<<1) /* transmission received */
2548#define PL_PEER_E (1<<0) /* peer exists */
2549
2550static inline int
2551pl_vendor_req (struct usbnet *dev, u8 req, u8 val, u8 index)
2552{
2553 return usb_control_msg (dev->udev,
2554 usb_rcvctrlpipe (dev->udev, 0),
2555 req,
2556 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2557 val, index,
2558 NULL, 0,
2559 CONTROL_TIMEOUT_MS);
2560}
2561
2562static inline int
2563pl_clear_QuickLink_features (struct usbnet *dev, int val)
2564{
2565 return pl_vendor_req (dev, 1, (u8) val, 0);
2566}
2567
2568static inline int
2569pl_set_QuickLink_features (struct usbnet *dev, int val)
2570{
2571 return pl_vendor_req (dev, 3, (u8) val, 0);
2572}
2573
2574/*-------------------------------------------------------------------------*/
2575
2576static int pl_reset (struct usbnet *dev)
2577{
2578 /* some units seem to need this reset, others reject it utterly.
2579 * FIXME be more like "naplink" or windows drivers.
2580 */
2581 (void) pl_set_QuickLink_features (dev,
2582 PL_S_EN|PL_RESET_OUT|PL_RESET_IN|PL_PEER_E);
2583 return 0;
2584}
2585
2586static const struct driver_info prolific_info = {
2587 .description = "Prolific PL-2301/PL-2302",
2588 .flags = FLAG_NO_SETINT,
2589 /* some PL-2302 versions seem to fail usb_set_interface() */
2590 .reset = pl_reset,
2591};
2592
2593#endif /* CONFIG_USB_PL2301 */
2594
2595
2596#ifdef CONFIG_USB_KC2190
2597#define HAVE_HARDWARE
2598static const struct driver_info kc2190_info = {
2599 .description = "KC Technology KC-190",
2600};
2601#endif /* CONFIG_USB_KC2190 */
2602
2603
2604#ifdef CONFIG_USB_ARMLINUX
2605#define HAVE_HARDWARE
2606
2607/*-------------------------------------------------------------------------
2608 *
2609 * Intel's SA-1100 chip integrates basic USB support, and is used
2610 * in PDAs like some iPaqs, the Yopy, some Zaurus models, and more.
2611 * When they run Linux, arch/arm/mach-sa1100/usb-eth.c may be used to
2612 * network using minimal USB framing data.
2613 *
2614 * This describes the driver currently in standard ARM Linux kernels.
2615 * The Zaurus uses a different driver (see later).
2616 *
2617 * PXA25x and PXA210 use XScale cores (ARM v5TE) with better USB support
2618 * and different USB endpoint numbering than the SA1100 devices. The
2619 * mach-pxa/usb-eth.c driver re-uses the device ids from mach-sa1100
2620 * so we rely on the endpoint descriptors.
2621 *
2622 *-------------------------------------------------------------------------*/
2623
2624static const struct driver_info linuxdev_info = {
2625 .description = "Linux Device",
2626 .check_connect = always_connected,
2627};
2628
2629static const struct driver_info yopy_info = {
2630 .description = "Yopy",
2631 .check_connect = always_connected,
2632};
2633
2634static const struct driver_info blob_info = {
2635 .description = "Boot Loader OBject",
2636 .check_connect = always_connected,
2637};
2638
2639#endif /* CONFIG_USB_ARMLINUX */
2640
2641
2642#ifdef CONFIG_USB_ZAURUS
2643#define HAVE_HARDWARE
2644
2645#include <linux/crc32.h>
2646
2647/*-------------------------------------------------------------------------
2648 *
2649 * Zaurus is also a SA-1110 based PDA, but one using a different driver
2650 * (and framing) for its USB slave/gadget controller than the case above.
2651 *
2652 * For the current version of that driver, the main way that framing is
2653 * nonstandard (also from perspective of the CDC ethernet model!) is a
2654 * crc32, added to help detect when some sa1100 usb-to-memory DMA errata
2655 * haven't been fully worked around. Also, all Zaurii use the same
2656 * default Ethernet address.
2657 *
2658 * PXA based models use the same framing, and also can't implement
2659 * set_interface properly.
2660 *
2661 * All known Zaurii lie about their standards conformance. Most lie by
2662 * saying they support CDC Ethernet. Some lie and say they support CDC
2663 * MDLM (as if for access to cell phone modems). Someone, please beat
2664 * on Sharp for a while with a cluestick.
2665 *
2666 *-------------------------------------------------------------------------*/
2667
2668static struct sk_buff *
2669zaurus_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags)
2670{
2671 int padlen;
2672 struct sk_buff *skb2;
2673
2674 padlen = 2;
2675 if (!skb_cloned (skb)) {
2676 int tailroom = skb_tailroom (skb);
2677 if ((padlen + 4) <= tailroom)
2678 goto done;
2679 }
2680 skb2 = skb_copy_expand (skb, 0, 4 + padlen, flags);
2681 dev_kfree_skb_any (skb);
2682 skb = skb2;
2683 if (skb) {
2684 u32 fcs;
2685done:
2686 fcs = crc32_le (~0, skb->data, skb->len);
2687 fcs = ~fcs;
2688
2689 *skb_put (skb, 1) = fcs & 0xff;
2690 *skb_put (skb, 1) = (fcs>> 8) & 0xff;
2691 *skb_put (skb, 1) = (fcs>>16) & 0xff;
2692 *skb_put (skb, 1) = (fcs>>24) & 0xff;
2693 }
2694 return skb;
2695}
2696
2697static const struct driver_info zaurus_sl5x00_info = {
2698 .description = "Sharp Zaurus SL-5x00",
2699 .flags = FLAG_FRAMING_Z,
2700 .check_connect = always_connected,
2701 .bind = generic_cdc_bind,
2702 .unbind = cdc_unbind,
2703 .tx_fixup = zaurus_tx_fixup,
2704};
2705#define ZAURUS_STRONGARM_INFO ((unsigned long)&zaurus_sl5x00_info)
2706
2707static const struct driver_info zaurus_pxa_info = {
2708 .description = "Sharp Zaurus, PXA-2xx based",
2709 .flags = FLAG_FRAMING_Z,
2710 .check_connect = always_connected,
2711 .bind = generic_cdc_bind,
2712 .unbind = cdc_unbind,
2713 .tx_fixup = zaurus_tx_fixup,
2714};
2715#define ZAURUS_PXA_INFO ((unsigned long)&zaurus_pxa_info)
2716
2717static const struct driver_info zaurus_pxa_mdlm_info = {
2718 .description = "Sharp Zaurus, PXA-255 based",
2719 .flags = FLAG_FRAMING_Z,
2720 .check_connect = always_connected,
2721 .tx_fixup = zaurus_tx_fixup,
2722};
2723
2724static const struct driver_info olympus_mxl_info = {
2725 .description = "Olympus R1000",
2726 .flags = FLAG_FRAMING_Z,
2727 .check_connect = always_connected,
2728 .bind = generic_cdc_bind,
2729 .unbind = cdc_unbind,
2730 .tx_fixup = zaurus_tx_fixup,
2731};
2732#define OLYMPUS_MXL_INFO ((unsigned long)&olympus_mxl_info)
2733
2734#else
2735
2736/* blacklist all those devices */
2737#define ZAURUS_STRONGARM_INFO 0
2738#define ZAURUS_PXA_INFO 0
2739#define OLYMPUS_MXL_INFO 0
2740
2741#endif
2742
2743
2744/*-------------------------------------------------------------------------
2745 *
2746 * Network Device Driver (peer link to "Host Device", from USB host)
2747 *
2748 *-------------------------------------------------------------------------*/
2749
2750static int usbnet_change_mtu (struct net_device *net, int new_mtu)
2751{
2752 struct usbnet *dev = netdev_priv(net);
2753
2754 if (new_mtu <= MIN_PACKET || new_mtu > MAX_PACKET)
2755 return -EINVAL;
2756#ifdef CONFIG_USB_NET1080
2757 if (((dev->driver_info->flags) & FLAG_FRAMING_NC)) {
2758 if (FRAMED_SIZE (new_mtu) > MAX_PACKET)
2759 return -EINVAL;
2760 }
2761#endif
2762#ifdef CONFIG_USB_GENESYS
2763 if (((dev->driver_info->flags) & FLAG_FRAMING_GL)
2764 && new_mtu > GL_MAX_PACKET_LEN)
2765 return -EINVAL;
2766#endif
2767 // no second zero-length packet read wanted after mtu-sized packets
2768 if (((new_mtu + sizeof (struct ethhdr)) % dev->maxpacket) == 0)
2769 return -EDOM;
2770 net->mtu = new_mtu;
2771 return 0;
2772}
2773
2774/*-------------------------------------------------------------------------*/
2775
2776static struct net_device_stats *usbnet_get_stats (struct net_device *net)
2777{
2778 struct usbnet *dev = netdev_priv(net);
2779 return &dev->stats;
2780}
2781
2782/*-------------------------------------------------------------------------*/
2783
2784/* some LK 2.4 HCDs oopsed if we freed or resubmitted urbs from
2785 * completion callbacks. 2.5 should have fixed those bugs...
2786 */
2787
2788static void defer_bh (struct usbnet *dev, struct sk_buff *skb)
2789{
2790 struct sk_buff_head *list = skb->list;
2791 unsigned long flags;
2792
2793 spin_lock_irqsave (&list->lock, flags);
2794 __skb_unlink (skb, list);
2795 spin_unlock (&list->lock);
2796 spin_lock (&dev->done.lock);
2797 __skb_queue_tail (&dev->done, skb);
2798 if (dev->done.qlen == 1)
2799 tasklet_schedule (&dev->bh);
2800 spin_unlock_irqrestore (&dev->done.lock, flags);
2801}
2802
2803/* some work can't be done in tasklets, so we use keventd
2804 *
2805 * NOTE: annoying asymmetry: if it's active, schedule_work() fails,
2806 * but tasklet_schedule() doesn't. hope the failure is rare.
2807 */
2808static void defer_kevent (struct usbnet *dev, int work)
2809{
2810 set_bit (work, &dev->flags);
2811 if (!schedule_work (&dev->kevent))
2812 deverr (dev, "kevent %d may have been dropped", work);
2813 else
2814 devdbg (dev, "kevent %d scheduled", work);
2815}
2816
2817/*-------------------------------------------------------------------------*/
2818
2819static void rx_complete (struct urb *urb, struct pt_regs *regs);
2820
2821static void rx_submit (struct usbnet *dev, struct urb *urb, int flags)
2822{
2823 struct sk_buff *skb;
2824 struct skb_data *entry;
2825 int retval = 0;
2826 unsigned long lockflags;
2827 size_t size;
2828
2829#ifdef CONFIG_USB_NET1080
2830 if (dev->driver_info->flags & FLAG_FRAMING_NC)
2831 size = FRAMED_SIZE (dev->net->mtu);
2832 else
2833#endif
2834#ifdef CONFIG_USB_GENESYS
2835 if (dev->driver_info->flags & FLAG_FRAMING_GL)
2836 size = GL_RCV_BUF_SIZE;
2837 else
2838#endif
2839#ifdef CONFIG_USB_ZAURUS
2840 if (dev->driver_info->flags & FLAG_FRAMING_Z)
2841 size = 6 + (sizeof (struct ethhdr) + dev->net->mtu);
2842 else
2843#endif
2844#ifdef CONFIG_USB_RNDIS
2845 if (dev->driver_info->flags & FLAG_FRAMING_RN)
2846 size = RNDIS_MAX_TRANSFER;
2847 else
2848#endif
2849#ifdef CONFIG_USB_AX8817X
2850 if (dev->driver_info->flags & FLAG_FRAMING_AX)
2851 size = 2048;
2852 else
2853#endif
2854 size = (sizeof (struct ethhdr) + dev->net->mtu);
2855
2856 if ((skb = alloc_skb (size + NET_IP_ALIGN, flags)) == NULL) {
2857 if (netif_msg_rx_err (dev))
2858 devdbg (dev, "no rx skb");
2859 defer_kevent (dev, EVENT_RX_MEMORY);
2860 usb_free_urb (urb);
2861 return;
2862 }
2863 skb_reserve (skb, NET_IP_ALIGN);
2864
2865 entry = (struct skb_data *) skb->cb;
2866 entry->urb = urb;
2867 entry->dev = dev;
2868 entry->state = rx_start;
2869 entry->length = 0;
2870
2871 usb_fill_bulk_urb (urb, dev->udev, dev->in,
2872 skb->data, size, rx_complete, skb);
2873 urb->transfer_flags |= URB_ASYNC_UNLINK;
2874
2875 spin_lock_irqsave (&dev->rxq.lock, lockflags);
2876
2877 if (netif_running (dev->net)
2878 && netif_device_present (dev->net)
2879 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
2880 switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){
2881 case -EPIPE:
2882 defer_kevent (dev, EVENT_RX_HALT);
2883 break;
2884 case -ENOMEM:
2885 defer_kevent (dev, EVENT_RX_MEMORY);
2886 break;
2887 case -ENODEV:
2888 if (netif_msg_ifdown (dev))
2889 devdbg (dev, "device gone");
2890 netif_device_detach (dev->net);
2891 break;
2892 default:
2893 if (netif_msg_rx_err (dev))
2894 devdbg (dev, "rx submit, %d", retval);
2895 tasklet_schedule (&dev->bh);
2896 break;
2897 case 0:
2898 __skb_queue_tail (&dev->rxq, skb);
2899 }
2900 } else {
2901 if (netif_msg_ifdown (dev))
2902 devdbg (dev, "rx: stopped");
2903 retval = -ENOLINK;
2904 }
2905 spin_unlock_irqrestore (&dev->rxq.lock, lockflags);
2906 if (retval) {
2907 dev_kfree_skb_any (skb);
2908 usb_free_urb (urb);
2909 }
2910}
2911
2912
2913/*-------------------------------------------------------------------------*/
2914
2915static inline void rx_process (struct usbnet *dev, struct sk_buff *skb)
2916{
2917 if (dev->driver_info->rx_fixup
2918 && !dev->driver_info->rx_fixup (dev, skb))
2919 goto error;
2920 // else network stack removes extra byte if we forced a short packet
2921
2922 if (skb->len)
2923 skb_return (dev, skb);
2924 else {
2925 if (netif_msg_rx_err (dev))
2926 devdbg (dev, "drop");
2927error:
2928 dev->stats.rx_errors++;
2929 skb_queue_tail (&dev->done, skb);
2930 }
2931}
2932
2933/*-------------------------------------------------------------------------*/
2934
2935static void rx_complete (struct urb *urb, struct pt_regs *regs)
2936{
2937 struct sk_buff *skb = (struct sk_buff *) urb->context;
2938 struct skb_data *entry = (struct skb_data *) skb->cb;
2939 struct usbnet *dev = entry->dev;
2940 int urb_status = urb->status;
2941
2942 skb_put (skb, urb->actual_length);
2943 entry->state = rx_done;
2944 entry->urb = NULL;
2945
2946 switch (urb_status) {
2947 // success
2948 case 0:
2949 if (MIN_PACKET > skb->len || skb->len > MAX_PACKET) {
2950 entry->state = rx_cleanup;
2951 dev->stats.rx_errors++;
2952 dev->stats.rx_length_errors++;
2953 if (netif_msg_rx_err (dev))
2954 devdbg (dev, "rx length %d", skb->len);
2955 }
2956 break;
2957
2958 // stalls need manual reset. this is rare ... except that
2959 // when going through USB 2.0 TTs, unplug appears this way.
2960 // we avoid the highspeed version of the ETIMEOUT/EILSEQ
2961 // storm, recovering as needed.
2962 case -EPIPE:
2963 dev->stats.rx_errors++;
2964 defer_kevent (dev, EVENT_RX_HALT);
2965 // FALLTHROUGH
2966
2967 // software-driven interface shutdown
2968 case -ECONNRESET: // async unlink
2969 case -ESHUTDOWN: // hardware gone
2970 if (netif_msg_ifdown (dev))
2971 devdbg (dev, "rx shutdown, code %d", urb_status);
2972 goto block;
2973
2974 // we get controller i/o faults during khubd disconnect() delays.
2975 // throttle down resubmits, to avoid log floods; just temporarily,
2976 // so we still recover when the fault isn't a khubd delay.
2977 case -EPROTO: // ehci
2978 case -ETIMEDOUT: // ohci
2979 case -EILSEQ: // uhci
2980 dev->stats.rx_errors++;
2981 if (!timer_pending (&dev->delay)) {
2982 mod_timer (&dev->delay, jiffies + THROTTLE_JIFFIES);
2983 if (netif_msg_link (dev))
2984 devdbg (dev, "rx throttle %d", urb_status);
2985 }
2986block:
2987 entry->state = rx_cleanup;
2988 entry->urb = urb;
2989 urb = NULL;
2990 break;
2991
2992 // data overrun ... flush fifo?
2993 case -EOVERFLOW:
2994 dev->stats.rx_over_errors++;
2995 // FALLTHROUGH
2996
2997 default:
2998 entry->state = rx_cleanup;
2999 dev->stats.rx_errors++;
3000 if (netif_msg_rx_err (dev))
3001 devdbg (dev, "rx status %d", urb_status);
3002 break;
3003 }
3004
3005 defer_bh (dev, skb);
3006
3007 if (urb) {
3008 if (netif_running (dev->net)
3009 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
3010 rx_submit (dev, urb, GFP_ATOMIC);
3011 return;
3012 }
3013 usb_free_urb (urb);
3014 }
3015 if (netif_msg_rx_err (dev))
3016 devdbg (dev, "no read resubmitted");
3017}
3018
3019static void intr_complete (struct urb *urb, struct pt_regs *regs)
3020{
3021 struct usbnet *dev = urb->context;
3022 int status = urb->status;
3023
3024 switch (status) {
3025 /* success */
3026 case 0:
3027 dev->driver_info->status(dev, urb);
3028 break;
3029
3030 /* software-driven interface shutdown */
3031 case -ENOENT: // urb killed
3032 case -ESHUTDOWN: // hardware gone
3033 if (netif_msg_ifdown (dev))
3034 devdbg (dev, "intr shutdown, code %d", status);
3035 return;
3036
3037 /* NOTE: not throttling like RX/TX, since this endpoint
3038 * already polls infrequently
3039 */
3040 default:
3041 devdbg (dev, "intr status %d", status);
3042 break;
3043 }
3044
3045 if (!netif_running (dev->net))
3046 return;
3047
3048 memset(urb->transfer_buffer, 0, urb->transfer_buffer_length);
3049 status = usb_submit_urb (urb, GFP_ATOMIC);
3050 if (status != 0 && netif_msg_timer (dev))
3051 deverr(dev, "intr resubmit --> %d", status);
3052}
3053
3054/*-------------------------------------------------------------------------*/
3055
3056// unlink pending rx/tx; completion handlers do all other cleanup
3057
3058static int unlink_urbs (struct usbnet *dev, struct sk_buff_head *q)
3059{
3060 unsigned long flags;
3061 struct sk_buff *skb, *skbnext;
3062 int count = 0;
3063
3064 spin_lock_irqsave (&q->lock, flags);
3065 for (skb = q->next; skb != (struct sk_buff *) q; skb = skbnext) {
3066 struct skb_data *entry;
3067 struct urb *urb;
3068 int retval;
3069
3070 entry = (struct skb_data *) skb->cb;
3071 urb = entry->urb;
3072 skbnext = skb->next;
3073
3074 // during some PM-driven resume scenarios,
3075 // these (async) unlinks complete immediately
3076 retval = usb_unlink_urb (urb);
3077 if (retval != -EINPROGRESS && retval != 0)
3078 devdbg (dev, "unlink urb err, %d", retval);
3079 else
3080 count++;
3081 }
3082 spin_unlock_irqrestore (&q->lock, flags);
3083 return count;
3084}
3085
3086
3087/*-------------------------------------------------------------------------*/
3088
3089// precondition: never called in_interrupt
3090
3091static int usbnet_stop (struct net_device *net)
3092{
3093 struct usbnet *dev = netdev_priv(net);
3094 int temp;
3095 DECLARE_WAIT_QUEUE_HEAD (unlink_wakeup);
3096 DECLARE_WAITQUEUE (wait, current);
3097
3098 netif_stop_queue (net);
3099
3100 if (netif_msg_ifdown (dev))
3101 devinfo (dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld",
3102 dev->stats.rx_packets, dev->stats.tx_packets,
3103 dev->stats.rx_errors, dev->stats.tx_errors
3104 );
3105
3106 // ensure there are no more active urbs
3107 add_wait_queue (&unlink_wakeup, &wait);
3108 dev->wait = &unlink_wakeup;
3109 temp = unlink_urbs (dev, &dev->txq) + unlink_urbs (dev, &dev->rxq);
3110
3111 // maybe wait for deletions to finish.
3112 while (skb_queue_len (&dev->rxq)
3113 && skb_queue_len (&dev->txq)
3114 && skb_queue_len (&dev->done)) {
3115 msleep(UNLINK_TIMEOUT_MS);
3116 if (netif_msg_ifdown (dev))
3117 devdbg (dev, "waited for %d urb completions", temp);
3118 }
3119 dev->wait = NULL;
3120 remove_wait_queue (&unlink_wakeup, &wait);
3121
3122 usb_kill_urb(dev->interrupt);
3123
3124 /* deferred work (task, timer, softirq) must also stop.
3125 * can't flush_scheduled_work() until we drop rtnl (later),
3126 * else workers could deadlock; so make workers a NOP.
3127 */
3128 dev->flags = 0;
3129 del_timer_sync (&dev->delay);
3130 tasklet_kill (&dev->bh);
3131
3132 return 0;
3133}
3134
3135/*-------------------------------------------------------------------------*/
3136
3137// posts reads, and enables write queuing
3138
3139// precondition: never called in_interrupt
3140
3141static int usbnet_open (struct net_device *net)
3142{
3143 struct usbnet *dev = netdev_priv(net);
3144 int retval = 0;
3145 struct driver_info *info = dev->driver_info;
3146
3147 // put into "known safe" state
3148 if (info->reset && (retval = info->reset (dev)) < 0) {
3149 if (netif_msg_ifup (dev))
3150 devinfo (dev,
3151 "open reset fail (%d) usbnet usb-%s-%s, %s",
3152 retval,
3153 dev->udev->bus->bus_name, dev->udev->devpath,
3154 info->description);
3155 goto done;
3156 }
3157
3158 // insist peer be connected
3159 if (info->check_connect && (retval = info->check_connect (dev)) < 0) {
3160 if (netif_msg_ifup (dev))
3161 devdbg (dev, "can't open; %d", retval);
3162 goto done;
3163 }
3164
3165 /* start any status interrupt transfer */
3166 if (dev->interrupt) {
3167 retval = usb_submit_urb (dev->interrupt, GFP_KERNEL);
3168 if (retval < 0) {
3169 if (netif_msg_ifup (dev))
3170 deverr (dev, "intr submit %d", retval);
3171 goto done;
3172 }
3173 }
3174
3175 netif_start_queue (net);
3176 if (netif_msg_ifup (dev)) {
3177 char *framing;
3178
3179 if (dev->driver_info->flags & FLAG_FRAMING_NC)
3180 framing = "NetChip";
3181 else if (dev->driver_info->flags & FLAG_FRAMING_GL)
3182 framing = "GeneSys";
3183 else if (dev->driver_info->flags & FLAG_FRAMING_Z)
3184 framing = "Zaurus";
3185 else if (dev->driver_info->flags & FLAG_FRAMING_RN)
3186 framing = "RNDIS";
3187 else if (dev->driver_info->flags & FLAG_FRAMING_AX)
3188 framing = "ASIX";
3189 else
3190 framing = "simple";
3191
3192 devinfo (dev, "open: enable queueing "
3193 "(rx %d, tx %d) mtu %d %s framing",
3194 RX_QLEN (dev), TX_QLEN (dev), dev->net->mtu,
3195 framing);
3196 }
3197
3198 // delay posting reads until we're fully open
3199 tasklet_schedule (&dev->bh);
3200done:
3201 return retval;
3202}
3203
3204/*-------------------------------------------------------------------------*/
3205
3206static void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info)
3207{
3208 struct usbnet *dev = netdev_priv(net);
3209
3210 strncpy (info->driver, driver_name, sizeof info->driver);
3211 strncpy (info->version, DRIVER_VERSION, sizeof info->version);
3212 strncpy (info->fw_version, dev->driver_info->description,
3213 sizeof info->fw_version);
3214 usb_make_path (dev->udev, info->bus_info, sizeof info->bus_info);
3215}
3216
3217static u32 usbnet_get_link (struct net_device *net)
3218{
3219 struct usbnet *dev = netdev_priv(net);
3220
3221 /* If a check_connect is defined, return it's results */
3222 if (dev->driver_info->check_connect)
3223 return dev->driver_info->check_connect (dev) == 0;
3224
3225 /* Otherwise, we're up to avoid breaking scripts */
3226 return 1;
3227}
3228
3229static u32 usbnet_get_msglevel (struct net_device *net)
3230{
3231 struct usbnet *dev = netdev_priv(net);
3232
3233 return dev->msg_enable;
3234}
3235
3236static void usbnet_set_msglevel (struct net_device *net, u32 level)
3237{
3238 struct usbnet *dev = netdev_priv(net);
3239
3240 dev->msg_enable = level;
3241}
3242
3243static int usbnet_ioctl (struct net_device *net, struct ifreq *rq, int cmd)
3244{
3245#ifdef NEED_MII
3246 {
3247 struct usbnet *dev = netdev_priv(net);
3248
3249 if (dev->mii.mdio_read != NULL && dev->mii.mdio_write != NULL)
3250 return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
3251 }
3252#endif
3253 return -EOPNOTSUPP;
3254}
3255
3256/*-------------------------------------------------------------------------*/
3257
3258/* work that cannot be done in interrupt context uses keventd.
3259 *
3260 * NOTE: with 2.5 we could do more of this using completion callbacks,
3261 * especially now that control transfers can be queued.
3262 */
3263static void
3264kevent (void *data)
3265{
3266 struct usbnet *dev = data;
3267 int status;
3268
3269 /* usb_clear_halt() needs a thread context */
3270 if (test_bit (EVENT_TX_HALT, &dev->flags)) {
3271 unlink_urbs (dev, &dev->txq);
3272 status = usb_clear_halt (dev->udev, dev->out);
3273 if (status < 0 && status != -EPIPE) {
3274 if (netif_msg_tx_err (dev))
3275 deverr (dev, "can't clear tx halt, status %d",
3276 status);
3277 } else {
3278 clear_bit (EVENT_TX_HALT, &dev->flags);
3279 netif_wake_queue (dev->net);
3280 }
3281 }
3282 if (test_bit (EVENT_RX_HALT, &dev->flags)) {
3283 unlink_urbs (dev, &dev->rxq);
3284 status = usb_clear_halt (dev->udev, dev->in);
3285 if (status < 0 && status != -EPIPE) {
3286 if (netif_msg_rx_err (dev))
3287 deverr (dev, "can't clear rx halt, status %d",
3288 status);
3289 } else {
3290 clear_bit (EVENT_RX_HALT, &dev->flags);
3291 tasklet_schedule (&dev->bh);
3292 }
3293 }
3294
3295 /* tasklet could resubmit itself forever if memory is tight */
3296 if (test_bit (EVENT_RX_MEMORY, &dev->flags)) {
3297 struct urb *urb = NULL;
3298
3299 if (netif_running (dev->net))
3300 urb = usb_alloc_urb (0, GFP_KERNEL);
3301 else
3302 clear_bit (EVENT_RX_MEMORY, &dev->flags);
3303 if (urb != NULL) {
3304 clear_bit (EVENT_RX_MEMORY, &dev->flags);
3305 rx_submit (dev, urb, GFP_KERNEL);
3306 tasklet_schedule (&dev->bh);
3307 }
3308 }
3309
3310 if (dev->flags)
3311 devdbg (dev, "kevent done, flags = 0x%lx",
3312 dev->flags);
3313}
3314
3315/*-------------------------------------------------------------------------*/
3316
3317static void tx_complete (struct urb *urb, struct pt_regs *regs)
3318{
3319 struct sk_buff *skb = (struct sk_buff *) urb->context;
3320 struct skb_data *entry = (struct skb_data *) skb->cb;
3321 struct usbnet *dev = entry->dev;
3322
3323 if (urb->status == 0) {
3324 dev->stats.tx_packets++;
3325 dev->stats.tx_bytes += entry->length;
3326 } else {
3327 dev->stats.tx_errors++;
3328
3329 switch (urb->status) {
3330 case -EPIPE:
3331 defer_kevent (dev, EVENT_TX_HALT);
3332 break;
3333
3334 /* software-driven interface shutdown */
3335 case -ECONNRESET: // async unlink
3336 case -ESHUTDOWN: // hardware gone
3337 break;
3338
3339 // like rx, tx gets controller i/o faults during khubd delays
3340 // and so it uses the same throttling mechanism.
3341 case -EPROTO: // ehci
3342 case -ETIMEDOUT: // ohci
3343 case -EILSEQ: // uhci
3344 if (!timer_pending (&dev->delay)) {
3345 mod_timer (&dev->delay,
3346 jiffies + THROTTLE_JIFFIES);
3347 if (netif_msg_link (dev))
3348 devdbg (dev, "tx throttle %d",
3349 urb->status);
3350 }
3351 netif_stop_queue (dev->net);
3352 break;
3353 default:
3354 if (netif_msg_tx_err (dev))
3355 devdbg (dev, "tx err %d", entry->urb->status);
3356 break;
3357 }
3358 }
3359
3360 urb->dev = NULL;
3361 entry->state = tx_done;
3362 defer_bh (dev, skb);
3363}
3364
3365/*-------------------------------------------------------------------------*/
3366
3367static void usbnet_tx_timeout (struct net_device *net)
3368{
3369 struct usbnet *dev = netdev_priv(net);
3370
3371 unlink_urbs (dev, &dev->txq);
3372 tasklet_schedule (&dev->bh);
3373
3374 // FIXME: device recovery -- reset?
3375}
3376
3377/*-------------------------------------------------------------------------*/
3378
3379static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net)
3380{
3381 struct usbnet *dev = netdev_priv(net);
3382 int length;
3383 int retval = NET_XMIT_SUCCESS;
3384 struct urb *urb = NULL;
3385 struct skb_data *entry;
3386 struct driver_info *info = dev->driver_info;
3387 unsigned long flags;
3388#ifdef CONFIG_USB_NET1080
3389 struct nc_header *header = NULL;
3390 struct nc_trailer *trailer = NULL;
3391#endif /* CONFIG_USB_NET1080 */
3392
3393 // some devices want funky USB-level framing, for
3394 // win32 driver (usually) and/or hardware quirks
3395 if (info->tx_fixup) {
3396 skb = info->tx_fixup (dev, skb, GFP_ATOMIC);
3397 if (!skb) {
3398 if (netif_msg_tx_err (dev))
3399 devdbg (dev, "can't tx_fixup skb");
3400 goto drop;
3401 }
3402 }
3403 length = skb->len;
3404
3405 if (!(urb = usb_alloc_urb (0, GFP_ATOMIC))) {
3406 if (netif_msg_tx_err (dev))
3407 devdbg (dev, "no urb");
3408 goto drop;
3409 }
3410
3411 entry = (struct skb_data *) skb->cb;
3412 entry->urb = urb;
3413 entry->dev = dev;
3414 entry->state = tx_start;
3415 entry->length = length;
3416
3417 // FIXME: reorganize a bit, so that fixup() fills out NetChip
3418 // framing too. (Packet ID update needs the spinlock...)
3419 // [ BETTER: we already own net->xmit_lock, that's enough ]
3420
3421#ifdef CONFIG_USB_NET1080
3422 if (info->flags & FLAG_FRAMING_NC) {
3423 header = (struct nc_header *) skb_push (skb, sizeof *header);
3424 header->hdr_len = cpu_to_le16 (sizeof (*header));
3425 header->packet_len = cpu_to_le16 (length);
3426 if (!((skb->len + sizeof *trailer) & 0x01))
3427 *skb_put (skb, 1) = PAD_BYTE;
3428 trailer = (struct nc_trailer *) skb_put (skb, sizeof *trailer);
3429 }
3430#endif /* CONFIG_USB_NET1080 */
3431
3432 usb_fill_bulk_urb (urb, dev->udev, dev->out,
3433 skb->data, skb->len, tx_complete, skb);
3434 urb->transfer_flags |= URB_ASYNC_UNLINK;
3435
3436 /* don't assume the hardware handles USB_ZERO_PACKET
3437 * NOTE: strictly conforming cdc-ether devices should expect
3438 * the ZLP here, but ignore the one-byte packet.
3439 *
3440 * FIXME zero that byte, if it doesn't require a new skb.
3441 */
3442 if ((length % dev->maxpacket) == 0)
3443 urb->transfer_buffer_length++;
3444
3445 spin_lock_irqsave (&dev->txq.lock, flags);
3446
3447#ifdef CONFIG_USB_NET1080
3448 if (info->flags & FLAG_FRAMING_NC) {
3449 header->packet_id = cpu_to_le16 ((u16)dev->dev_packet_id++);
3450 put_unaligned (header->packet_id, &trailer->packet_id);
3451#if 0
3452 devdbg (dev, "frame >tx h %d p %d id %d",
3453 header->hdr_len, header->packet_len,
3454 header->packet_id);
3455#endif
3456 }
3457#endif /* CONFIG_USB_NET1080 */
3458
3459 switch ((retval = usb_submit_urb (urb, GFP_ATOMIC))) {
3460 case -EPIPE:
3461 netif_stop_queue (net);
3462 defer_kevent (dev, EVENT_TX_HALT);
3463 break;
3464 default:
3465 if (netif_msg_tx_err (dev))
3466 devdbg (dev, "tx: submit urb err %d", retval);
3467 break;
3468 case 0:
3469 net->trans_start = jiffies;
3470 __skb_queue_tail (&dev->txq, skb);
3471 if (dev->txq.qlen >= TX_QLEN (dev))
3472 netif_stop_queue (net);
3473 }
3474 spin_unlock_irqrestore (&dev->txq.lock, flags);
3475
3476 if (retval) {
3477 if (netif_msg_tx_err (dev))
3478 devdbg (dev, "drop, code %d", retval);
3479drop:
3480 retval = NET_XMIT_SUCCESS;
3481 dev->stats.tx_dropped++;
3482 if (skb)
3483 dev_kfree_skb_any (skb);
3484 usb_free_urb (urb);
3485 } else if (netif_msg_tx_queued (dev)) {
3486 devdbg (dev, "> tx, len %d, type 0x%x",
3487 length, skb->protocol);
3488 }
3489 return retval;
3490}
3491
3492
3493/*-------------------------------------------------------------------------*/
3494
3495// tasklet (work deferred from completions, in_irq) or timer
3496
3497static void usbnet_bh (unsigned long param)
3498{
3499 struct usbnet *dev = (struct usbnet *) param;
3500 struct sk_buff *skb;
3501 struct skb_data *entry;
3502
3503 while ((skb = skb_dequeue (&dev->done))) {
3504 entry = (struct skb_data *) skb->cb;
3505 switch (entry->state) {
3506 case rx_done:
3507 entry->state = rx_cleanup;
3508 rx_process (dev, skb);
3509 continue;
3510 case tx_done:
3511 case rx_cleanup:
3512 usb_free_urb (entry->urb);
3513 dev_kfree_skb (skb);
3514 continue;
3515 default:
3516 devdbg (dev, "bogus skb state %d", entry->state);
3517 }
3518 }
3519
3520 // waiting for all pending urbs to complete?
3521 if (dev->wait) {
3522 if ((dev->txq.qlen + dev->rxq.qlen + dev->done.qlen) == 0) {
3523 wake_up (dev->wait);
3524 }
3525
3526 // or are we maybe short a few urbs?
3527 } else if (netif_running (dev->net)
3528 && netif_device_present (dev->net)
3529 && !timer_pending (&dev->delay)
3530 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
3531 int temp = dev->rxq.qlen;
3532 int qlen = RX_QLEN (dev);
3533
3534 if (temp < qlen) {
3535 struct urb *urb;
3536 int i;
3537
3538 // don't refill the queue all at once
3539 for (i = 0; i < 10 && dev->rxq.qlen < qlen; i++) {
3540 urb = usb_alloc_urb (0, GFP_ATOMIC);
3541 if (urb != NULL)
3542 rx_submit (dev, urb, GFP_ATOMIC);
3543 }
3544 if (temp != dev->rxq.qlen && netif_msg_link (dev))
3545 devdbg (dev, "rxqlen %d --> %d",
3546 temp, dev->rxq.qlen);
3547 if (dev->rxq.qlen < qlen)
3548 tasklet_schedule (&dev->bh);
3549 }
3550 if (dev->txq.qlen < TX_QLEN (dev))
3551 netif_wake_queue (dev->net);
3552 }
3553}
3554
3555
3556
3557/*-------------------------------------------------------------------------
3558 *
3559 * USB Device Driver support
3560 *
3561 *-------------------------------------------------------------------------*/
3562
3563// precondition: never called in_interrupt
3564
3565static void usbnet_disconnect (struct usb_interface *intf)
3566{
3567 struct usbnet *dev;
3568 struct usb_device *xdev;
3569 struct net_device *net;
3570
3571 dev = usb_get_intfdata(intf);
3572 usb_set_intfdata(intf, NULL);
3573 if (!dev)
3574 return;
3575
3576 xdev = interface_to_usbdev (intf);
3577
3578 if (netif_msg_probe (dev))
3579 devinfo (dev, "unregister usbnet usb-%s-%s, %s",
3580 xdev->bus->bus_name, xdev->devpath,
3581 dev->driver_info->description);
3582
3583 net = dev->net;
3584 unregister_netdev (net);
3585
3586 /* we don't hold rtnl here ... */
3587 flush_scheduled_work ();
3588
3589 if (dev->driver_info->unbind)
3590 dev->driver_info->unbind (dev, intf);
3591
3592 free_netdev(net);
3593 usb_put_dev (xdev);
3594}
3595
3596
3597/*-------------------------------------------------------------------------*/
3598
3599static struct ethtool_ops usbnet_ethtool_ops;
3600
3601// precondition: never called in_interrupt
3602
3603static int
3604usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
3605{
3606 struct usbnet *dev;
3607 struct net_device *net;
3608 struct usb_host_interface *interface;
3609 struct driver_info *info;
3610 struct usb_device *xdev;
3611 int status;
3612
3613 info = (struct driver_info *) prod->driver_info;
3614 if (!info) {
3615 dev_dbg (&udev->dev, "blacklisted by %s\n", driver_name);
3616 return -ENODEV;
3617 }
3618 xdev = interface_to_usbdev (udev);
3619 interface = udev->cur_altsetting;
3620
3621 usb_get_dev (xdev);
3622
3623 status = -ENOMEM;
3624
3625 // set up our own records
3626 net = alloc_etherdev(sizeof(*dev));
3627 if (!net) {
3628 dbg ("can't kmalloc dev");
3629 goto out;
3630 }
3631
3632 dev = netdev_priv(net);
3633 dev->udev = xdev;
3634 dev->driver_info = info;
3635 dev->msg_enable = netif_msg_init (msg_level, NETIF_MSG_DRV
3636 | NETIF_MSG_PROBE | NETIF_MSG_LINK);
3637 skb_queue_head_init (&dev->rxq);
3638 skb_queue_head_init (&dev->txq);
3639 skb_queue_head_init (&dev->done);
3640 dev->bh.func = usbnet_bh;
3641 dev->bh.data = (unsigned long) dev;
3642 INIT_WORK (&dev->kevent, kevent, dev);
3643 dev->delay.function = usbnet_bh;
3644 dev->delay.data = (unsigned long) dev;
3645 init_timer (&dev->delay);
3646
3647 SET_MODULE_OWNER (net);
3648 dev->net = net;
3649 strcpy (net->name, "usb%d");
3650 memcpy (net->dev_addr, node_id, sizeof node_id);
3651
3652#if 0
3653// dma_supported() is deeply broken on almost all architectures
3654 // possible with some EHCI controllers
3655 if (dma_supported (&udev->dev, DMA_64BIT_MASK))
3656 net->features |= NETIF_F_HIGHDMA;
3657#endif
3658
3659 net->change_mtu = usbnet_change_mtu;
3660 net->get_stats = usbnet_get_stats;
3661 net->hard_start_xmit = usbnet_start_xmit;
3662 net->open = usbnet_open;
3663 net->stop = usbnet_stop;
3664 net->watchdog_timeo = TX_TIMEOUT_JIFFIES;
3665 net->tx_timeout = usbnet_tx_timeout;
3666 net->do_ioctl = usbnet_ioctl;
3667 net->ethtool_ops = &usbnet_ethtool_ops;
3668
3669 // allow device-specific bind/init procedures
3670 // NOTE net->name still not usable ...
3671 if (info->bind) {
3672 status = info->bind (dev, udev);
3673 // heuristic: "usb%d" for links we know are two-host,
3674 // else "eth%d" when there's reasonable doubt. userspace
3675 // can rename the link if it knows better.
3676 if ((dev->driver_info->flags & FLAG_ETHER) != 0
3677 && (net->dev_addr [0] & 0x02) == 0)
3678 strcpy (net->name, "eth%d");
3679 } else if (!info->in || info->out)
3680 status = get_endpoints (dev, udev);
3681 else {
3682 dev->in = usb_rcvbulkpipe (xdev, info->in);
3683 dev->out = usb_sndbulkpipe (xdev, info->out);
3684 if (!(info->flags & FLAG_NO_SETINT))
3685 status = usb_set_interface (xdev,
3686 interface->desc.bInterfaceNumber,
3687 interface->desc.bAlternateSetting);
3688 else
3689 status = 0;
3690
3691 }
3692
3693 if (status == 0 && dev->status)
3694 status = init_status (dev, udev);
3695 if (status < 0)
3696 goto out1;
3697
3698 dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1);
3699
3700 SET_NETDEV_DEV(net, &udev->dev);
3701 status = register_netdev (net);
3702 if (status)
3703 goto out3;
3704 if (netif_msg_probe (dev))
3705 devinfo (dev, "register usbnet at usb-%s-%s, %s, "
3706 "%02x:%02x:%02x:%02x:%02x:%02x",
3707 xdev->bus->bus_name, xdev->devpath,
3708 dev->driver_info->description,
3709 net->dev_addr [0], net->dev_addr [1],
3710 net->dev_addr [2], net->dev_addr [3],
3711 net->dev_addr [4], net->dev_addr [5]);
3712
3713 // ok, it's ready to go.
3714 usb_set_intfdata (udev, dev);
3715
3716 // start as if the link is up
3717 netif_device_attach (net);
3718
3719 return 0;
3720
3721out3:
3722 if (info->unbind)
3723 info->unbind (dev, udev);
3724out1:
3725 free_netdev(net);
3726out:
3727 usb_put_dev(xdev);
3728 return status;
3729}
3730
3731/*-------------------------------------------------------------------------*/
3732
3733#ifdef CONFIG_PM
3734
3735static int usbnet_suspend (struct usb_interface *intf, u32 state)
3736{
3737 struct usbnet *dev = usb_get_intfdata(intf);
3738
3739 netif_device_detach (dev->net);
3740 return 0;
3741}
3742
3743static int usbnet_resume (struct usb_interface *intf)
3744{
3745 struct usbnet *dev = usb_get_intfdata(intf);
3746
3747 netif_device_attach (dev->net);
3748 return 0;
3749}
3750
3751#else /* !CONFIG_PM */
3752
3753#define usbnet_suspend NULL
3754#define usbnet_resume NULL
3755
3756#endif /* CONFIG_PM */
3757
3758/*-------------------------------------------------------------------------*/
3759
3760#ifndef HAVE_HARDWARE
3761#error You need to configure some hardware for this driver
3762#endif
3763
3764/*
3765 * chip vendor names won't normally be on the cables, and
3766 * may not be on the device.
3767 */
3768
3769static const struct usb_device_id products [] = {
3770
3771#ifdef CONFIG_USB_ALI_M5632
3772{
3773 USB_DEVICE (0x0402, 0x5632), // ALi defaults
3774 .driver_info = (unsigned long) &ali_m5632_info,
3775},
3776#endif
3777
3778#ifdef CONFIG_USB_AN2720
3779{
3780 USB_DEVICE (0x0547, 0x2720), // AnchorChips defaults
3781 .driver_info = (unsigned long) &an2720_info,
3782}, {
3783 USB_DEVICE (0x0547, 0x2727), // Xircom PGUNET
3784 .driver_info = (unsigned long) &an2720_info,
3785},
3786#endif
3787
3788#ifdef CONFIG_USB_BELKIN
3789{
3790 USB_DEVICE (0x050d, 0x0004), // Belkin
3791 .driver_info = (unsigned long) &belkin_info,
3792}, {
3793 USB_DEVICE (0x056c, 0x8100), // eTEK
3794 .driver_info = (unsigned long) &belkin_info,
3795}, {
3796 USB_DEVICE (0x0525, 0x9901), // Advance USBNET (eTEK)
3797 .driver_info = (unsigned long) &belkin_info,
3798},
3799#endif
3800
3801#ifdef CONFIG_USB_AX8817X
3802{
3803 // Linksys USB200M
3804 USB_DEVICE (0x077b, 0x2226),
3805 .driver_info = (unsigned long) &ax8817x_info,
3806}, {
3807 // Netgear FA120
3808 USB_DEVICE (0x0846, 0x1040),
3809 .driver_info = (unsigned long) &netgear_fa120_info,
3810}, {
3811 // DLink DUB-E100
3812 USB_DEVICE (0x2001, 0x1a00),
3813 .driver_info = (unsigned long) &dlink_dub_e100_info,
3814}, {
3815 // Intellinet, ST Lab USB Ethernet
3816 USB_DEVICE (0x0b95, 0x1720),
3817 .driver_info = (unsigned long) &ax8817x_info,
3818}, {
3819 // Hawking UF200, TrendNet TU2-ET100
3820 USB_DEVICE (0x07b8, 0x420a),
3821 .driver_info = (unsigned long) &hawking_uf200_info,
3822}, {
3823 // Billionton Systems, USB2AR
3824 USB_DEVICE (0x08dd, 0x90ff),
3825 .driver_info = (unsigned long) &ax8817x_info,
3826}, {
3827 // ATEN UC210T
3828 USB_DEVICE (0x0557, 0x2009),
3829 .driver_info = (unsigned long) &ax8817x_info,
3830}, {
3831 // Buffalo LUA-U2-KTX
3832 USB_DEVICE (0x0411, 0x003d),
3833 .driver_info = (unsigned long) &ax8817x_info,
3834}, {
3835 // Sitecom LN-029 "USB 2.0 10/100 Ethernet adapter"
3836 USB_DEVICE (0x6189, 0x182d),
3837 .driver_info = (unsigned long) &ax8817x_info,
3838}, {
3839 // corega FEther USB2-TX
3840 USB_DEVICE (0x07aa, 0x0017),
3841 .driver_info = (unsigned long) &ax8817x_info,
3842}, {
3843 // Surecom EP-1427X-2
3844 USB_DEVICE (0x1189, 0x0893),
3845 .driver_info = (unsigned long) &ax8817x_info,
3846}, {
3847 // goodway corp usb gwusb2e
3848 USB_DEVICE (0x1631, 0x6200),
3849 .driver_info = (unsigned long) &ax8817x_info,
3850}, {
3851 // ASIX AX88772 10/100
3852 USB_DEVICE (0x0b95, 0x7720),
3853 .driver_info = (unsigned long) &ax88772_info,
3854},
3855#endif
3856
3857#ifdef CONFIG_USB_EPSON2888
3858{
3859 USB_DEVICE (0x0525, 0x2888), // EPSON USB client
3860 .driver_info = (unsigned long) &epson2888_info,
3861},
3862#endif
3863
3864#ifdef CONFIG_USB_GENESYS
3865{
3866 USB_DEVICE (0x05e3, 0x0502), // GL620USB-A
3867 .driver_info = (unsigned long) &genelink_info,
3868},
3869 /* NOT: USB_DEVICE (0x05e3, 0x0501), // GL620USB
3870 * that's half duplex, not currently supported
3871 */
3872#endif
3873
3874#ifdef CONFIG_USB_NET1080
3875{
3876 USB_DEVICE (0x0525, 0x1080), // NetChip ref design
3877 .driver_info = (unsigned long) &net1080_info,
3878}, {
3879 USB_DEVICE (0x06D0, 0x0622), // Laplink Gold
3880 .driver_info = (unsigned long) &net1080_info,
3881},
3882#endif
3883
3884#ifdef CONFIG_USB_PL2301
3885{
3886 USB_DEVICE (0x067b, 0x0000), // PL-2301
3887 .driver_info = (unsigned long) &prolific_info,
3888}, {
3889 USB_DEVICE (0x067b, 0x0001), // PL-2302
3890 .driver_info = (unsigned long) &prolific_info,
3891},
3892#endif
3893
3894#ifdef CONFIG_USB_KC2190
3895{
3896 USB_DEVICE (0x050f, 0x0190), // KC-190
3897 .driver_info = (unsigned long) &kc2190_info,
3898},
3899#endif
3900
3901#ifdef CONFIG_USB_RNDIS
3902{
3903 /* RNDIS is MSFT's un-official variant of CDC ACM */
3904 USB_INTERFACE_INFO (USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
3905 .driver_info = (unsigned long) &rndis_info,
3906},
3907#endif
3908
3909#ifdef CONFIG_USB_ARMLINUX
3910/*
3911 * SA-1100 using standard ARM Linux kernels, or compatible.
3912 * Often used when talking to Linux PDAs (iPaq, Yopy, etc).
3913 * The sa-1100 "usb-eth" driver handles the basic framing.
3914 *
3915 * PXA25x or PXA210 ... these use a "usb-eth" driver much like
3916 * the sa1100 one, but hardware uses different endpoint numbers.
3917 *
3918 * Or the Linux "Ethernet" gadget on hardware that can't talk
3919 * CDC Ethernet (e.g., no altsettings), in either of two modes:
3920 * - acting just like the old "usb-eth" firmware, though
3921 * the implementation is different
3922 * - supporting RNDIS as the first/default configuration for
3923 * MS-Windows interop; Linux needs to use the other config
3924 */
3925{
3926 // 1183 = 0x049F, both used as hex values?
3927 // Compaq "Itsy" vendor/product id
3928 USB_DEVICE (0x049F, 0x505A), // usb-eth, or compatible
3929 .driver_info = (unsigned long) &linuxdev_info,
3930}, {
3931 USB_DEVICE (0x0E7E, 0x1001), // G.Mate "Yopy"
3932 .driver_info = (unsigned long) &yopy_info,
3933}, {
3934 USB_DEVICE (0x8086, 0x07d3), // "blob" bootloader
3935 .driver_info = (unsigned long) &blob_info,
3936}, {
3937 // Linux Ethernet/RNDIS gadget on pxa210/25x/26x
3938 // e.g. Gumstix, current OpenZaurus, ...
3939 USB_DEVICE_VER (0x0525, 0xa4a2, 0x0203, 0x0203),
3940 .driver_info = (unsigned long) &linuxdev_info,
3941},
3942#endif
3943
3944#if defined(CONFIG_USB_ZAURUS) || defined(CONFIG_USB_CDCETHER)
3945/*
3946 * SA-1100 based Sharp Zaurus ("collie"), or compatible.
3947 * Same idea as above, but different framing.
3948 *
3949 * PXA-2xx based models are also lying-about-cdc.
3950 * Some models don't even tell the same lies ...
3951 *
3952 * NOTE: OpenZaurus versions with 2.6 kernels won't use these entries,
3953 * unlike the older ones with 2.4 "embedix" kernels.
3954 *
3955 * NOTE: These entries do double-duty, serving as blacklist entries
3956 * whenever Zaurus support isn't enabled, but CDC Ethernet is.
3957 */
3958#define ZAURUS_MASTER_INTERFACE \
3959 .bInterfaceClass = USB_CLASS_COMM, \
3960 .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET, \
3961 .bInterfaceProtocol = USB_CDC_PROTO_NONE
3962{
3963 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3964 | USB_DEVICE_ID_MATCH_DEVICE,
3965 .idVendor = 0x04DD,
3966 .idProduct = 0x8004,
3967 ZAURUS_MASTER_INTERFACE,
3968 .driver_info = ZAURUS_STRONGARM_INFO,
3969}, {
3970 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3971 | USB_DEVICE_ID_MATCH_DEVICE,
3972 .idVendor = 0x04DD,
3973 .idProduct = 0x8005, /* A-300 */
3974 ZAURUS_MASTER_INTERFACE,
3975 .driver_info = ZAURUS_PXA_INFO,
3976}, {
3977 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3978 | USB_DEVICE_ID_MATCH_DEVICE,
3979 .idVendor = 0x04DD,
3980 .idProduct = 0x8006, /* B-500/SL-5600 */
3981 ZAURUS_MASTER_INTERFACE,
3982 .driver_info = ZAURUS_PXA_INFO,
3983}, {
3984 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3985 | USB_DEVICE_ID_MATCH_DEVICE,
3986 .idVendor = 0x04DD,
3987 .idProduct = 0x8007, /* C-700 */
3988 ZAURUS_MASTER_INTERFACE,
3989 .driver_info = ZAURUS_PXA_INFO,
3990}, {
3991 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3992 | USB_DEVICE_ID_MATCH_DEVICE,
3993 .idVendor = 0x04DD,
3994 .idProduct = 0x9031, /* C-750 C-760 */
3995 ZAURUS_MASTER_INTERFACE,
3996 .driver_info = ZAURUS_PXA_INFO,
3997}, {
3998 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3999 | USB_DEVICE_ID_MATCH_DEVICE,
4000 .idVendor = 0x04DD,
4001 .idProduct = 0x9032, /* SL-6000 */
4002 ZAURUS_MASTER_INTERFACE,
4003 .driver_info = ZAURUS_PXA_INFO,
4004}, {
4005 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
4006 | USB_DEVICE_ID_MATCH_DEVICE,
4007 .idVendor = 0x04DD,
4008 /* reported with some C860 units */
4009 .idProduct = 0x9050, /* C-860 */
4010 ZAURUS_MASTER_INTERFACE,
4011 .driver_info = ZAURUS_PXA_INFO,
4012#ifdef CONFIG_USB_ZAURUS
4013 /* at least some (reports vary) C-860 units have very different
4014 * lies about their standards support.
4015 */
4016}, {
4017 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
4018 | USB_DEVICE_ID_MATCH_DEVICE,
4019 .idVendor = 0x04DD,
4020 /* reported with some C860 units */
4021 .idProduct = 0x9031, /* C-860 */
4022 .bInterfaceClass = USB_CLASS_COMM,
4023 .bInterfaceSubClass = USB_CDC_SUBCLASS_MDLM,
4024 .bInterfaceProtocol = USB_CDC_PROTO_NONE,
4025 .driver_info = (unsigned long) &zaurus_pxa_mdlm_info,
4026#endif
4027},
4028
4029/* Olympus has some models with a Zaurus-compatible option.
4030 * R-1000 uses a FreeScale i.MXL cpu (ARMv4T)
4031 */
4032{
4033 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
4034 | USB_DEVICE_ID_MATCH_DEVICE,
4035 .idVendor = 0x07B4,
4036 .idProduct = 0x0F02, /* R-1000 */
4037 ZAURUS_MASTER_INTERFACE,
4038 .driver_info = OLYMPUS_MXL_INFO,
4039},
4040#endif
4041
4042#ifdef CONFIG_USB_CDCETHER
4043{
4044 /* CDC Ether uses two interfaces, not necessarily consecutive.
4045 * We match the main interface, ignoring the optional device
4046 * class so we could handle devices that aren't exclusively
4047 * CDC ether.
4048 *
4049 * NOTE: this match must come AFTER entries working around
4050 * bugs/quirks in a given product (like Zaurus, above).
4051 */
4052 USB_INTERFACE_INFO (USB_CLASS_COMM, USB_CDC_SUBCLASS_ETHERNET,
4053 USB_CDC_PROTO_NONE),
4054 .driver_info = (unsigned long) &cdc_info,
4055},
4056#endif
4057
4058 { }, // END
4059};
4060MODULE_DEVICE_TABLE (usb, products);
4061
4062static struct usb_driver usbnet_driver = {
4063 .owner = THIS_MODULE,
4064 .name = driver_name,
4065 .id_table = products,
4066 .probe = usbnet_probe,
4067 .disconnect = usbnet_disconnect,
4068 .suspend = usbnet_suspend,
4069 .resume = usbnet_resume,
4070};
4071
4072/* Default ethtool_ops assigned. Devices can override in their bind() routine */
4073static struct ethtool_ops usbnet_ethtool_ops = {
4074 .get_drvinfo = usbnet_get_drvinfo,
4075 .get_link = usbnet_get_link,
4076 .get_msglevel = usbnet_get_msglevel,
4077 .set_msglevel = usbnet_set_msglevel,
4078};
4079
4080/*-------------------------------------------------------------------------*/
4081
4082static int __init usbnet_init (void)
4083{
4084 // compiler should optimize these out
4085 BUG_ON (sizeof (((struct sk_buff *)0)->cb)
4086 < sizeof (struct skb_data));
4087#ifdef CONFIG_USB_CDCETHER
4088 BUG_ON ((sizeof (((struct usbnet *)0)->data)
4089 < sizeof (struct cdc_state)));
4090#endif
4091
4092 random_ether_addr(node_id);
4093
4094 return usb_register(&usbnet_driver);
4095}
4096module_init (usbnet_init);
4097
4098static void __exit usbnet_exit (void)
4099{
4100 usb_deregister (&usbnet_driver);
4101}
4102module_exit (usbnet_exit);
4103
4104MODULE_AUTHOR ("David Brownell <dbrownell@users.sourceforge.net>");
4105MODULE_DESCRIPTION ("USB Host-to-Host Link Drivers (numerous vendors)");
4106MODULE_LICENSE ("GPL");
diff --git a/drivers/usb/net/zd1201.c b/drivers/usb/net/zd1201.c
new file mode 100644
index 000000000000..938025e2c646
--- /dev/null
+++ b/drivers/usb/net/zd1201.c
@@ -0,0 +1,1905 @@
1/*
2 * Driver for ZyDAS zd1201 based wireless USB devices.
3 *
4 * Copyright (c) 2004, 2005 Jeroen Vreeken (pe1rxq@amsat.org)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 *
10 * Parts of this driver have been derived from a wlan-ng version
11 * modified by ZyDAS. They also made documentation available, thanks!
12 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
13 */
14
15#include <linux/module.h>
16#include <linux/usb.h>
17#include <linux/netdevice.h>
18#include <linux/etherdevice.h>
19#include <linux/wireless.h>
20#include <net/iw_handler.h>
21#include <linux/string.h>
22#include <linux/if_arp.h>
23#include <linux/firmware.h>
24#include <ieee802_11.h>
25#include "zd1201.h"
26
27static struct usb_device_id zd1201_table[] = {
28 {USB_DEVICE(0x0586, 0x3400)}, /* Peabird Wireless USB Adapter */
29 {USB_DEVICE(0x0ace, 0x1201)}, /* ZyDAS ZD1201 Wireless USB Adapter */
30 {USB_DEVICE(0x050d, 0x6051)}, /* Belkin F5D6051 usb adapter */
31 {USB_DEVICE(0x0db0, 0x6823)}, /* MSI UB11B usb adapter */
32 {}
33};
34
35static int ap = 0; /* Are we an AP or a normal station? */
36
37#define ZD1201_VERSION "0.15"
38
39MODULE_AUTHOR("Jeroen Vreeken <pe1rxq@amsat.org>");
40MODULE_DESCRIPTION("Driver for ZyDAS ZD1201 based USB Wireless adapters");
41MODULE_VERSION(ZD1201_VERSION);
42MODULE_LICENSE("GPL");
43module_param(ap, int, 0);
44MODULE_PARM_DESC(ap, "If non-zero Access Point firmware will be loaded");
45MODULE_DEVICE_TABLE(usb, zd1201_table);
46
47
48int zd1201_fw_upload(struct usb_device *dev, int apfw)
49{
50 const struct firmware *fw_entry;
51 char* data;
52 unsigned long len;
53 int err;
54 unsigned char ret;
55 char *buf;
56 char *fwfile;
57
58 if (apfw)
59 fwfile = "zd1201-ap.fw";
60 else
61 fwfile = "zd1201.fw";
62
63 err = request_firmware(&fw_entry, fwfile, &dev->dev);
64 if (err) {
65 dev_err(&dev->dev, "Failed to load %s firmware file!\n", fwfile);
66 dev_err(&dev->dev, "Make sure the hotplug firmware loader is installed.\n");
67 dev_err(&dev->dev, "Goto http://linux-lc100020.sourceforge.net for more info\n");
68 return err;
69 }
70
71 data = fw_entry->data;
72 len = fw_entry->size;
73
74 buf = kmalloc(1024, GFP_ATOMIC);
75 if (!buf)
76 goto exit;
77
78 while (len > 0) {
79 int translen = (len > 1024) ? 1024 : len;
80 memcpy(buf, data, translen);
81
82 err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 0,
83 USB_DIR_OUT | 0x40, 0, 0, buf, translen,
84 ZD1201_FW_TIMEOUT);
85 if (err < 0)
86 goto exit;
87
88 len -= translen;
89 data += translen;
90 }
91
92 err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 0x2,
93 USB_DIR_OUT | 0x40, 0, 0, NULL, 0, ZD1201_FW_TIMEOUT);
94 if (err < 0)
95 goto exit;
96
97 err = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 0x4,
98 USB_DIR_IN | 0x40, 0,0, &ret, sizeof(ret), ZD1201_FW_TIMEOUT);
99 if (err < 0)
100 goto exit;
101
102 if (ret & 0x80) {
103 err = -EIO;
104 goto exit;
105 }
106
107 err = 0;
108exit:
109 if (buf)
110 kfree(buf);
111 release_firmware(fw_entry);
112 return err;
113}
114
115void zd1201_usbfree(struct urb *urb, struct pt_regs *regs)
116{
117 struct zd1201 *zd = urb->context;
118
119 switch(urb->status) {
120 case -EILSEQ:
121 case -ENODEV:
122 case -ETIMEDOUT:
123 case -ENOENT:
124 case -EPIPE:
125 case -EOVERFLOW:
126 case -ESHUTDOWN:
127 dev_warn(&zd->usb->dev, "%s: urb failed: %d\n",
128 zd->dev->name, urb->status);
129 }
130
131 kfree(urb->transfer_buffer);
132 usb_free_urb(urb);
133 return;
134}
135
136/* cmdreq message:
137 u32 type
138 u16 cmd
139 u16 parm0
140 u16 parm1
141 u16 parm2
142 u8 pad[4]
143
144 total: 4 + 2 + 2 + 2 + 2 + 4 = 16
145*/
146int zd1201_docmd(struct zd1201 *zd, int cmd, int parm0, int parm1, int parm2)
147{
148 unsigned char *command;
149 int ret;
150 struct urb *urb;
151
152 command = kmalloc(16, GFP_ATOMIC);
153 if (!command)
154 return -ENOMEM;
155
156 *((__le32*)command) = cpu_to_le32(ZD1201_USB_CMDREQ);
157 *((__le16*)&command[4]) = cpu_to_le16(cmd);
158 *((__le16*)&command[6]) = cpu_to_le16(parm0);
159 *((__le16*)&command[8]) = cpu_to_le16(parm1);
160 *((__le16*)&command[10])= cpu_to_le16(parm2);
161
162 urb = usb_alloc_urb(0, GFP_ATOMIC);
163 if (!urb) {
164 kfree(command);
165 return -ENOMEM;
166 }
167 usb_fill_bulk_urb(urb, zd->usb, usb_sndbulkpipe(zd->usb, zd->endp_out2),
168 command, 16, zd1201_usbfree, zd);
169 ret = usb_submit_urb(urb, GFP_ATOMIC);
170 if (ret) {
171 kfree(command);
172 usb_free_urb(urb);
173 }
174
175 return ret;
176}
177
178/* Callback after sending out a packet */
179void zd1201_usbtx(struct urb *urb, struct pt_regs *regs)
180{
181 struct zd1201 *zd = urb->context;
182 netif_wake_queue(zd->dev);
183 return;
184}
185
186/* Incomming data */
187void zd1201_usbrx(struct urb *urb, struct pt_regs *regs)
188{
189 struct zd1201 *zd = urb->context;
190 int free = 0;
191 unsigned char *data = urb->transfer_buffer;
192 struct sk_buff *skb;
193 unsigned char type;
194
195 if (!zd) {
196 free = 1;
197 goto exit;
198 }
199
200 switch(urb->status) {
201 case -EILSEQ:
202 case -ENODEV:
203 case -ETIMEDOUT:
204 case -ENOENT:
205 case -EPIPE:
206 case -EOVERFLOW:
207 case -ESHUTDOWN:
208 dev_warn(&zd->usb->dev, "%s: rx urb failed: %d\n",
209 zd->dev->name, urb->status);
210 free = 1;
211 goto exit;
212 }
213
214 if (urb->status != 0 || urb->actual_length == 0)
215 goto resubmit;
216
217 type = data[0];
218 if (type == ZD1201_PACKET_EVENTSTAT || type == ZD1201_PACKET_RESOURCE) {
219 memcpy(zd->rxdata, data, urb->actual_length);
220 zd->rxlen = urb->actual_length;
221 zd->rxdatas = 1;
222 wake_up(&zd->rxdataq);
223 }
224 /* Info frame */
225 if (type == ZD1201_PACKET_INQUIRE) {
226 int i = 0;
227 unsigned short infotype, framelen, copylen;
228 framelen = le16_to_cpu(*(__le16*)&data[4]);
229 infotype = le16_to_cpu(*(__le16*)&data[6]);
230
231 if (infotype == ZD1201_INF_LINKSTATUS) {
232 short linkstatus;
233
234 linkstatus = le16_to_cpu(*(__le16*)&data[8]);
235 switch(linkstatus) {
236 case 1:
237 netif_carrier_on(zd->dev);
238 break;
239 case 2:
240 netif_carrier_off(zd->dev);
241 break;
242 case 3:
243 netif_carrier_off(zd->dev);
244 break;
245 case 4:
246 netif_carrier_on(zd->dev);
247 break;
248 default:
249 netif_carrier_off(zd->dev);
250 }
251 goto resubmit;
252 }
253 if (infotype == ZD1201_INF_ASSOCSTATUS) {
254 short status = le16_to_cpu(*(__le16*)(data+8));
255 int event;
256 union iwreq_data wrqu;
257
258 switch (status) {
259 case ZD1201_ASSOCSTATUS_STAASSOC:
260 case ZD1201_ASSOCSTATUS_REASSOC:
261 event = IWEVREGISTERED;
262 break;
263 case ZD1201_ASSOCSTATUS_DISASSOC:
264 case ZD1201_ASSOCSTATUS_ASSOCFAIL:
265 case ZD1201_ASSOCSTATUS_AUTHFAIL:
266 default:
267 event = IWEVEXPIRED;
268 }
269 memcpy(wrqu.addr.sa_data, data+10, ETH_ALEN);
270 wrqu.addr.sa_family = ARPHRD_ETHER;
271
272 /* Send event to user space */
273 wireless_send_event(zd->dev, event, &wrqu, NULL);
274
275 goto resubmit;
276 }
277 if (infotype == ZD1201_INF_AUTHREQ) {
278 union iwreq_data wrqu;
279
280 memcpy(wrqu.addr.sa_data, data+8, ETH_ALEN);
281 wrqu.addr.sa_family = ARPHRD_ETHER;
282 /* There isn't a event that trully fits this request.
283 We assume that userspace will be smart enough to
284 see a new station being expired and sends back a
285 authstation ioctl to authorize it. */
286 wireless_send_event(zd->dev, IWEVEXPIRED, &wrqu, NULL);
287 goto resubmit;
288 }
289 /* Other infotypes are handled outside this handler */
290 zd->rxlen = 0;
291 while (i < urb->actual_length) {
292 copylen = le16_to_cpu(*(__le16*)&data[i+2]);
293 /* Sanity check, sometimes we get junk */
294 if (copylen+zd->rxlen > sizeof(zd->rxdata))
295 break;
296 memcpy(zd->rxdata+zd->rxlen, data+i+4, copylen);
297 zd->rxlen += copylen;
298 i += 64;
299 }
300 if (i >= urb->actual_length) {
301 zd->rxdatas = 1;
302 wake_up(&zd->rxdataq);
303 }
304 goto resubmit;
305 }
306 /* Actual data */
307 if (data[urb->actual_length-1] == ZD1201_PACKET_RXDATA) {
308 int datalen = urb->actual_length-1;
309 unsigned short len, fc, seq;
310 struct hlist_node *node;
311
312 len = ntohs(*(__be16 *)&data[datalen-2]);
313 if (len>datalen)
314 len=datalen;
315 fc = le16_to_cpu(*(__le16 *)&data[datalen-16]);
316 seq = le16_to_cpu(*(__le16 *)&data[datalen-24]);
317
318 if(zd->monitor) {
319 if (datalen < 24)
320 goto resubmit;
321 if (!(skb = dev_alloc_skb(datalen+24)))
322 goto resubmit;
323
324 memcpy(skb_put(skb, 2), &data[datalen-16], 2);
325 memcpy(skb_put(skb, 2), &data[datalen-2], 2);
326 memcpy(skb_put(skb, 6), &data[datalen-14], 6);
327 memcpy(skb_put(skb, 6), &data[datalen-22], 6);
328 memcpy(skb_put(skb, 6), &data[datalen-8], 6);
329 memcpy(skb_put(skb, 2), &data[datalen-24], 2);
330 memcpy(skb_put(skb, len), data, len);
331 skb->dev = zd->dev;
332 skb->dev->last_rx = jiffies;
333 skb->protocol = eth_type_trans(skb, zd->dev);
334 zd->stats.rx_packets++;
335 zd->stats.rx_bytes += skb->len;
336 netif_rx(skb);
337 goto resubmit;
338 }
339
340 if ((seq & IEEE802_11_SCTL_FRAG) ||
341 (fc & IEEE802_11_FCTL_MOREFRAGS)) {
342 struct zd1201_frag *frag = NULL;
343 char *ptr;
344
345 if (datalen<14)
346 goto resubmit;
347 if ((seq & IEEE802_11_SCTL_FRAG) == 0) {
348 frag = kmalloc(sizeof(struct zd1201_frag*),
349 GFP_ATOMIC);
350 if (!frag)
351 goto resubmit;
352 skb = dev_alloc_skb(IEEE802_11_DATA_LEN +14+2);
353 if (!skb) {
354 kfree(frag);
355 goto resubmit;
356 }
357 frag->skb = skb;
358 frag->seq = seq & IEEE802_11_SCTL_SEQ;
359 skb_reserve(skb, 2);
360 memcpy(skb_put(skb, 12), &data[datalen-14], 12);
361 memcpy(skb_put(skb, 2), &data[6], 2);
362 memcpy(skb_put(skb, len), data+8, len);
363 hlist_add_head(&frag->fnode, &zd->fraglist);
364 goto resubmit;
365 }
366 hlist_for_each_entry(frag, node, &zd->fraglist, fnode)
367 if(frag->seq == (seq&IEEE802_11_SCTL_SEQ))
368 break;
369 if (!frag)
370 goto resubmit;
371 skb = frag->skb;
372 ptr = skb_put(skb, len);
373 if (ptr)
374 memcpy(ptr, data+8, len);
375 if (fc & IEEE802_11_FCTL_MOREFRAGS)
376 goto resubmit;
377 hlist_del_init(&frag->fnode);
378 kfree(frag);
379 /* Fallthrough */
380 } else {
381 if (datalen<14)
382 goto resubmit;
383 skb = dev_alloc_skb(len + 14 + 2);
384 if (!skb)
385 goto resubmit;
386 skb_reserve(skb, 2);
387 memcpy(skb_put(skb, 12), &data[datalen-14], 12);
388 memcpy(skb_put(skb, 2), &data[6], 2);
389 memcpy(skb_put(skb, len), data+8, len);
390 }
391 skb->dev = zd->dev;
392 skb->dev->last_rx = jiffies;
393 skb->protocol = eth_type_trans(skb, zd->dev);
394 zd->stats.rx_packets++;
395 zd->stats.rx_bytes += skb->len;
396 netif_rx(skb);
397 }
398resubmit:
399 memset(data, 0, ZD1201_RXSIZE);
400
401 urb->status = 0;
402 urb->dev = zd->usb;
403 if(usb_submit_urb(urb, GFP_ATOMIC))
404 free = 1;
405
406exit:
407 if (free) {
408 zd->rxlen = 0;
409 zd->rxdatas = 1;
410 wake_up(&zd->rxdataq);
411 kfree(urb->transfer_buffer);
412 }
413 return;
414}
415
416static int zd1201_getconfig(struct zd1201 *zd, int rid, void *riddata,
417 unsigned int riddatalen)
418{
419 int err;
420 int i = 0;
421 int code;
422 int rid_fid;
423 int length;
424 unsigned char *pdata;
425
426 zd->rxdatas = 0;
427 err = zd1201_docmd(zd, ZD1201_CMDCODE_ACCESS, rid, 0, 0);
428 if (err)
429 return err;
430
431 wait_event_interruptible(zd->rxdataq, zd->rxdatas);
432 if (!zd->rxlen)
433 return -EIO;
434
435 code = le16_to_cpu(*(__le16*)(&zd->rxdata[4]));
436 rid_fid = le16_to_cpu(*(__le16*)(&zd->rxdata[6]));
437 length = le16_to_cpu(*(__le16*)(&zd->rxdata[8]));
438 if (length > zd->rxlen)
439 length = zd->rxlen-6;
440
441 /* If access bit is not on, then error */
442 if ((code & ZD1201_ACCESSBIT) != ZD1201_ACCESSBIT || rid_fid != rid )
443 return -EINVAL;
444
445 /* Not enough buffer for allocating data */
446 if (riddatalen != (length - 4)) {
447 dev_dbg(&zd->usb->dev, "riddatalen mismatches, expected=%u, (packet=%u) length=%u, rid=0x%04X, rid_fid=0x%04X\n",
448 riddatalen, zd->rxlen, length, rid, rid_fid);
449 return -ENODATA;
450 }
451
452 zd->rxdatas = 0;
453 /* Issue SetRxRid commnd */
454 err = zd1201_docmd(zd, ZD1201_CMDCODE_SETRXRID, rid, 0, length);
455 if (err)
456 return err;
457
458 /* Receive RID record from resource packets */
459 wait_event_interruptible(zd->rxdataq, zd->rxdatas);
460 if (!zd->rxlen)
461 return -EIO;
462
463 if (zd->rxdata[zd->rxlen - 1] != ZD1201_PACKET_RESOURCE) {
464 dev_dbg(&zd->usb->dev, "Packet type mismatch: 0x%x not 0x3\n",
465 zd->rxdata[zd->rxlen-1]);
466 return -EINVAL;
467 }
468
469 /* Set the data pointer and received data length */
470 pdata = zd->rxdata;
471 length = zd->rxlen;
472
473 do {
474 int actual_length;
475
476 actual_length = (length > 64) ? 64 : length;
477
478 if(pdata[0] != 0x3) {
479 dev_dbg(&zd->usb->dev, "Rx Resource packet type error: %02X\n",
480 pdata[0]);
481 return -EINVAL;
482 }
483
484 if (actual_length != 64) {
485 /* Trim the last packet type byte */
486 actual_length--;
487 }
488
489 /* Skip the 4 bytes header (RID length and RID) */
490 if(i == 0) {
491 pdata += 8;
492 actual_length -= 8;
493 }
494 else {
495 pdata += 4;
496 actual_length -= 4;
497 }
498
499 memcpy(riddata, pdata, actual_length);
500 riddata += actual_length;
501 pdata += actual_length;
502 length -= 64;
503 i++;
504 } while (length > 0);
505
506 return 0;
507}
508
509/*
510 * resreq:
511 * byte type
512 * byte sequence
513 * u16 reserved
514 * byte data[12]
515 * total: 16
516 */
517static int zd1201_setconfig(struct zd1201 *zd, int rid, void *buf, int len, int wait)
518{
519 int err;
520 unsigned char *request;
521 int reqlen;
522 char seq=0;
523 struct urb *urb;
524 unsigned int gfp_mask = wait ? GFP_NOIO : GFP_ATOMIC;
525
526 len += 4; /* first 4 are for header */
527
528 zd->rxdatas = 0;
529 zd->rxlen = 0;
530 for (seq=0; len > 0; seq++) {
531 request = kmalloc(16, gfp_mask);
532 if (!request)
533 return -ENOMEM;
534 urb = usb_alloc_urb(0, gfp_mask);
535 if (!urb) {
536 kfree(request);
537 return -ENOMEM;
538 }
539 memset(request, 0, 16);
540 reqlen = len>12 ? 12 : len;
541 request[0] = ZD1201_USB_RESREQ;
542 request[1] = seq;
543 request[2] = 0;
544 request[3] = 0;
545 if (request[1] == 0) {
546 /* add header */
547 *(__le16*)&request[4] = cpu_to_le16((len-2+1)/2);
548 *(__le16*)&request[6] = cpu_to_le16(rid);
549 memcpy(request+8, buf, reqlen-4);
550 buf += reqlen-4;
551 } else {
552 memcpy(request+4, buf, reqlen);
553 buf += reqlen;
554 }
555
556 len -= reqlen;
557
558 usb_fill_bulk_urb(urb, zd->usb, usb_sndbulkpipe(zd->usb,
559 zd->endp_out2), request, 16, zd1201_usbfree, zd);
560 err = usb_submit_urb(urb, gfp_mask);
561 if (err)
562 goto err;
563 }
564
565 request = kmalloc(16, gfp_mask);
566 if (!request)
567 return -ENOMEM;
568 urb = usb_alloc_urb(0, gfp_mask);
569 if (!urb) {
570 kfree(request);
571 return -ENOMEM;
572 }
573 *((__le32*)request) = cpu_to_le32(ZD1201_USB_CMDREQ);
574 *((__le16*)&request[4]) =
575 cpu_to_le16(ZD1201_CMDCODE_ACCESS|ZD1201_ACCESSBIT);
576 *((__le16*)&request[6]) = cpu_to_le16(rid);
577 *((__le16*)&request[8]) = cpu_to_le16(0);
578 *((__le16*)&request[10]) = cpu_to_le16(0);
579 usb_fill_bulk_urb(urb, zd->usb, usb_sndbulkpipe(zd->usb, zd->endp_out2),
580 request, 16, zd1201_usbfree, zd);
581 err = usb_submit_urb(urb, gfp_mask);
582 if (err)
583 goto err;
584
585 if (wait) {
586 wait_event_interruptible(zd->rxdataq, zd->rxdatas);
587 if (!zd->rxlen || le16_to_cpu(*(__le16*)&zd->rxdata[6]) != rid) {
588 dev_dbg(&zd->usb->dev, "wrong or no RID received\n");
589 }
590 }
591
592 return 0;
593err:
594 kfree(request);
595 usb_free_urb(urb);
596 return err;
597}
598
599static inline int zd1201_getconfig16(struct zd1201 *zd, int rid, short *val)
600{
601 int err;
602 __le16 zdval;
603
604 err = zd1201_getconfig(zd, rid, &zdval, sizeof(__le16));
605 if (err)
606 return err;
607 *val = le16_to_cpu(zdval);
608 return 0;
609}
610
611static inline int zd1201_setconfig16(struct zd1201 *zd, int rid, short val)
612{
613 __le16 zdval = cpu_to_le16(val);
614 return (zd1201_setconfig(zd, rid, &zdval, sizeof(__le16), 1));
615}
616
617int zd1201_drvr_start(struct zd1201 *zd)
618{
619 int err, i;
620 short max;
621 __le16 zdmax;
622 unsigned char *buffer;
623
624 buffer = kmalloc(ZD1201_RXSIZE, GFP_KERNEL);
625 if (!buffer)
626 return -ENOMEM;
627 memset(buffer, 0, ZD1201_RXSIZE);
628
629 usb_fill_bulk_urb(zd->rx_urb, zd->usb,
630 usb_rcvbulkpipe(zd->usb, zd->endp_in), buffer, ZD1201_RXSIZE,
631 zd1201_usbrx, zd);
632
633 err = usb_submit_urb(zd->rx_urb, GFP_KERNEL);
634 if (err)
635 goto err_buffer;
636
637 err = zd1201_docmd(zd, ZD1201_CMDCODE_INIT, 0, 0, 0);
638 if (err)
639 goto err_urb;
640
641 err = zd1201_getconfig(zd, ZD1201_RID_CNFMAXTXBUFFERNUMBER, &zdmax,
642 sizeof(__le16));
643 if (err)
644 goto err_urb;
645
646 max = le16_to_cpu(zdmax);
647 for (i=0; i<max; i++) {
648 err = zd1201_docmd(zd, ZD1201_CMDCODE_ALLOC, 1514, 0, 0);
649 if (err)
650 goto err_urb;
651 }
652
653 return 0;
654
655err_urb:
656 usb_kill_urb(zd->rx_urb);
657 return err;
658err_buffer:
659 kfree(buffer);
660 return err;
661}
662
663/* Magic alert: The firmware doesn't seem to like the MAC state being
664 * toggled in promisc (aka monitor) mode.
665 * (It works a number of times, but will halt eventually)
666 * So we turn it of before disabling and on after enabling if needed.
667 */
668static int zd1201_enable(struct zd1201 *zd)
669{
670 int err;
671
672 if (zd->mac_enabled)
673 return 0;
674
675 err = zd1201_docmd(zd, ZD1201_CMDCODE_ENABLE, 0, 0, 0);
676 if (!err)
677 zd->mac_enabled = 1;
678
679 if (zd->monitor)
680 err = zd1201_setconfig16(zd, ZD1201_RID_PROMISCUOUSMODE, 1);
681
682 return err;
683}
684
685static int zd1201_disable(struct zd1201 *zd)
686{
687 int err;
688
689 if (!zd->mac_enabled)
690 return 0;
691 if (zd->monitor) {
692 err = zd1201_setconfig16(zd, ZD1201_RID_PROMISCUOUSMODE, 0);
693 if (err)
694 return err;
695 }
696
697 err = zd1201_docmd(zd, ZD1201_CMDCODE_DISABLE, 0, 0, 0);
698 if (!err)
699 zd->mac_enabled = 0;
700 return err;
701}
702
703static int zd1201_mac_reset(struct zd1201 *zd)
704{
705 if (!zd->mac_enabled)
706 return 0;
707 zd1201_disable(zd);
708 return zd1201_enable(zd);
709}
710
711static int zd1201_join(struct zd1201 *zd, char *essid, int essidlen)
712{
713 int err, val;
714 char buf[IW_ESSID_MAX_SIZE+2];
715
716 err = zd1201_disable(zd);
717 if (err)
718 return err;
719
720 val = ZD1201_CNFAUTHENTICATION_OPENSYSTEM;
721 val |= ZD1201_CNFAUTHENTICATION_SHAREDKEY;
722 err = zd1201_setconfig16(zd, ZD1201_RID_CNFAUTHENTICATION, val);
723 if (err)
724 return err;
725
726 *(__le16 *)buf = cpu_to_le16(essidlen);
727 memcpy(buf+2, essid, essidlen);
728 if (!zd->ap) { /* Normal station */
729 err = zd1201_setconfig(zd, ZD1201_RID_CNFDESIREDSSID, buf,
730 IW_ESSID_MAX_SIZE+2, 1);
731 if (err)
732 return err;
733 } else { /* AP */
734 err = zd1201_setconfig(zd, ZD1201_RID_CNFOWNSSID, buf,
735 IW_ESSID_MAX_SIZE+2, 1);
736 if (err)
737 return err;
738 }
739
740 err = zd1201_setconfig(zd, ZD1201_RID_CNFOWNMACADDR,
741 zd->dev->dev_addr, zd->dev->addr_len, 1);
742 if (err)
743 return err;
744
745 err = zd1201_enable(zd);
746 if (err)
747 return err;
748
749 msleep(100);
750 return 0;
751}
752
753static int zd1201_net_open(struct net_device *dev)
754{
755 struct zd1201 *zd = (struct zd1201 *)dev->priv;
756
757 /* Start MAC with wildcard if no essid set */
758 if (!zd->mac_enabled)
759 zd1201_join(zd, zd->essid, zd->essidlen);
760 netif_start_queue(dev);
761
762 return 0;
763}
764
765static int zd1201_net_stop(struct net_device *dev)
766{
767 netif_stop_queue(dev);
768
769 return 0;
770}
771
772/*
773 RFC 1042 encapsulates Ethernet frames in 802.11 frames
774 by prefixing them with 0xaa, 0xaa, 0x03) followed by a SNAP OID of 0
775 (0x00, 0x00, 0x00). Zd requires an additionnal padding, copy
776 of ethernet addresses, length of the standard RFC 1042 packet
777 and a command byte (which is nul for tx).
778
779 tx frame (from Wlan NG):
780 RFC 1042:
781 llc 0xAA 0xAA 0x03 (802.2 LLC)
782 snap 0x00 0x00 0x00 (Ethernet encapsulated)
783 type 2 bytes, Ethernet type field
784 payload (minus eth header)
785 Zydas specific:
786 padding 1B if (skb->len+8+1)%64==0
787 Eth MAC addr 12 bytes, Ethernet MAC addresses
788 length 2 bytes, RFC 1042 packet length
789 (llc+snap+type+payload)
790 zd 1 null byte, zd1201 packet type
791 */
792static int zd1201_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
793{
794 struct zd1201 *zd = (struct zd1201 *)dev->priv;
795 unsigned char *txbuf = zd->txdata;
796 int txbuflen, pad = 0, err;
797 struct urb *urb = zd->tx_urb;
798
799 if (!zd->mac_enabled || zd->monitor) {
800 zd->stats.tx_dropped++;
801 kfree_skb(skb);
802 return 0;
803 }
804 netif_stop_queue(dev);
805
806 txbuflen = skb->len + 8 + 1;
807 if (txbuflen%64 == 0) {
808 pad = 1;
809 txbuflen++;
810 }
811 txbuf[0] = 0xAA;
812 txbuf[1] = 0xAA;
813 txbuf[2] = 0x03;
814 txbuf[3] = 0x00; /* rfc1042 */
815 txbuf[4] = 0x00;
816 txbuf[5] = 0x00;
817
818 memcpy(txbuf+6, skb->data+12, skb->len-12);
819 if (pad)
820 txbuf[skb->len-12+6]=0;
821 memcpy(txbuf+skb->len-12+6+pad, skb->data, 12);
822 *(__be16*)&txbuf[skb->len+6+pad] = htons(skb->len-12+6);
823 txbuf[txbuflen-1] = 0;
824
825 usb_fill_bulk_urb(urb, zd->usb, usb_sndbulkpipe(zd->usb, zd->endp_out),
826 txbuf, txbuflen, zd1201_usbtx, zd);
827
828 err = usb_submit_urb(zd->tx_urb, GFP_ATOMIC);
829 if (err) {
830 zd->stats.tx_errors++;
831 netif_start_queue(dev);
832 return err;
833 }
834 zd->stats.tx_packets++;
835 zd->stats.tx_bytes += skb->len;
836 dev->trans_start = jiffies;
837 kfree_skb(skb);
838
839 return 0;
840}
841
842static void zd1201_tx_timeout(struct net_device *dev)
843{
844 struct zd1201 *zd = (struct zd1201 *)dev->priv;
845
846 if (!zd)
847 return;
848 dev_warn(&zd->usb->dev, "%s: TX timeout, shooting down urb\n",
849 dev->name);
850 zd->tx_urb->transfer_flags |= URB_ASYNC_UNLINK;
851 usb_unlink_urb(zd->tx_urb);
852 zd->stats.tx_errors++;
853 /* Restart the timeout to quiet the watchdog: */
854 dev->trans_start = jiffies;
855}
856
857static int zd1201_set_mac_address(struct net_device *dev, void *p)
858{
859 struct sockaddr *addr = p;
860 struct zd1201 *zd = (struct zd1201 *)dev->priv;
861 int err;
862
863 if (!zd)
864 return -ENODEV;
865
866 err = zd1201_setconfig(zd, ZD1201_RID_CNFOWNMACADDR,
867 addr->sa_data, dev->addr_len, 1);
868 if (err)
869 return err;
870 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
871
872 return zd1201_mac_reset(zd);
873}
874
875static struct net_device_stats *zd1201_get_stats(struct net_device *dev)
876{
877 struct zd1201 *zd = (struct zd1201 *)dev->priv;
878
879 return &zd->stats;
880}
881
882static struct iw_statistics *zd1201_get_wireless_stats(struct net_device *dev)
883{
884 struct zd1201 *zd = (struct zd1201 *)dev->priv;
885
886 return &zd->iwstats;
887}
888
889static void zd1201_set_multicast(struct net_device *dev)
890{
891 struct zd1201 *zd = (struct zd1201 *)dev->priv;
892 struct dev_mc_list *mc = dev->mc_list;
893 unsigned char reqbuf[ETH_ALEN*ZD1201_MAXMULTI];
894 int i;
895
896 if (dev->mc_count > ZD1201_MAXMULTI)
897 return;
898
899 for (i=0; i<dev->mc_count; i++) {
900 memcpy(reqbuf+i*ETH_ALEN, mc->dmi_addr, ETH_ALEN);
901 mc = mc->next;
902 }
903 zd1201_setconfig(zd, ZD1201_RID_CNFGROUPADDRESS, reqbuf,
904 dev->mc_count*ETH_ALEN, 0);
905
906}
907
908static int zd1201_config_commit(struct net_device *dev,
909 struct iw_request_info *info, struct iw_point *data, char *essid)
910{
911 struct zd1201 *zd = (struct zd1201 *)dev->priv;
912
913 return zd1201_mac_reset(zd);
914}
915
916static int zd1201_get_name(struct net_device *dev,
917 struct iw_request_info *info, char *name, char *extra)
918{
919 strcpy(name, "IEEE 802.11b");
920
921 return 0;
922}
923
924static int zd1201_set_freq(struct net_device *dev,
925 struct iw_request_info *info, struct iw_freq *freq, char *extra)
926{
927 struct zd1201 *zd = (struct zd1201 *)dev->priv;
928 short channel = 0;
929 int err;
930
931 if (freq->e == 0)
932 channel = freq->m;
933 else {
934 if (freq->m >= 2482)
935 channel = 14;
936 if (freq->m >= 2407)
937 channel = (freq->m-2407)/5;
938 }
939
940 err = zd1201_setconfig16(zd, ZD1201_RID_CNFOWNCHANNEL, channel);
941 if (err)
942 return err;
943
944 zd1201_mac_reset(zd);
945
946 return 0;
947}
948
949static int zd1201_get_freq(struct net_device *dev,
950 struct iw_request_info *info, struct iw_freq *freq, char *extra)
951{
952 struct zd1201 *zd = (struct zd1201 *)dev->priv;
953 short channel;
954 int err;
955
956 err = zd1201_getconfig16(zd, ZD1201_RID_CNFOWNCHANNEL, &channel);
957 if (err)
958 return err;
959 freq->e = 0;
960 freq->m = channel;
961
962 return 0;
963}
964
965static int zd1201_set_mode(struct net_device *dev,
966 struct iw_request_info *info, __u32 *mode, char *extra)
967{
968 struct zd1201 *zd = (struct zd1201 *)dev->priv;
969 short porttype, monitor = 0;
970 unsigned char buffer[IW_ESSID_MAX_SIZE+2];
971 int err;
972
973 if (zd->ap) {
974 if (*mode != IW_MODE_MASTER)
975 return -EINVAL;
976 return 0;
977 }
978
979 err = zd1201_setconfig16(zd, ZD1201_RID_PROMISCUOUSMODE, 0);
980 if (err)
981 return err;
982 zd->dev->type = ARPHRD_ETHER;
983 switch(*mode) {
984 case IW_MODE_MONITOR:
985 monitor = 1;
986 zd->dev->type = ARPHRD_IEEE80211;
987 /* Make sure we are no longer associated with by
988 setting an 'impossible' essid.
989 (otherwise we mess up firmware)
990 */
991 zd1201_join(zd, "\0-*#\0", 5);
992 /* Put port in pIBSS */
993 case 8: /* No pseudo-IBSS in wireless extensions (yet) */
994 porttype = ZD1201_PORTTYPE_PSEUDOIBSS;
995 break;
996 case IW_MODE_ADHOC:
997 porttype = ZD1201_PORTTYPE_IBSS;
998 break;
999 case IW_MODE_INFRA:
1000 porttype = ZD1201_PORTTYPE_BSS;
1001 break;
1002 default:
1003 return -EINVAL;
1004 }
1005
1006 err = zd1201_setconfig16(zd, ZD1201_RID_CNFPORTTYPE, porttype);
1007 if (err)
1008 return err;
1009 if (zd->monitor && !monitor) {
1010 zd1201_disable(zd);
1011 *(__le16 *)buffer = cpu_to_le16(zd->essidlen);
1012 memcpy(buffer+2, zd->essid, zd->essidlen);
1013 err = zd1201_setconfig(zd, ZD1201_RID_CNFDESIREDSSID,
1014 buffer, IW_ESSID_MAX_SIZE+2, 1);
1015 if (err)
1016 return err;
1017 }
1018 zd->monitor=monitor;
1019 /* If monitor mode is set we don't actually turn it on here since it
1020 * is done during mac reset anyway (see zd1201_mac_enable).
1021 */
1022
1023 zd1201_mac_reset(zd);
1024
1025 return 0;
1026}
1027
1028static int zd1201_get_mode(struct net_device *dev,
1029 struct iw_request_info *info, __u32 *mode, char *extra)
1030{
1031 struct zd1201 *zd = (struct zd1201 *)dev->priv;
1032 short porttype;
1033 int err;
1034
1035 err = zd1201_getconfig16(zd, ZD1201_RID_CNFPORTTYPE, &porttype);
1036 if (err)
1037 return err;
1038 switch(porttype) {
1039 case ZD1201_PORTTYPE_IBSS:
1040 *mode = IW_MODE_ADHOC;
1041 break;
1042 case ZD1201_PORTTYPE_BSS:
1043 *mode = IW_MODE_INFRA;
1044 break;
1045 case ZD1201_PORTTYPE_WDS:
1046 *mode = IW_MODE_REPEAT;
1047 break;
1048 case ZD1201_PORTTYPE_PSEUDOIBSS:
1049 *mode = 8;/* No Pseudo-IBSS... */
1050 break;
1051 case ZD1201_PORTTYPE_AP:
1052 *mode = IW_MODE_MASTER;
1053 break;
1054 default:
1055 dev_dbg(&zd->usb->dev, "Unknown porttype: %d\n",
1056 porttype);
1057 *mode = IW_MODE_AUTO;
1058 }
1059 if (zd->monitor)
1060 *mode = IW_MODE_MONITOR;
1061
1062 return 0;
1063}
1064
1065static int zd1201_get_range(struct net_device *dev,
1066 struct iw_request_info *info, struct iw_point *wrq, char *extra)
1067{
1068 struct iw_range *range = (struct iw_range *)extra;
1069
1070 wrq->length = sizeof(struct iw_range);
1071 memset(range, 0, sizeof(struct iw_range));
1072 range->we_version_compiled = WIRELESS_EXT;
1073 range->we_version_source = WIRELESS_EXT;
1074
1075 range->max_qual.qual = 128;
1076 range->max_qual.level = 128;
1077 range->max_qual.noise = 128;
1078 range->max_qual.updated = 7;
1079
1080 range->encoding_size[0] = 5;
1081 range->encoding_size[1] = 13;
1082 range->num_encoding_sizes = 2;
1083 range->max_encoding_tokens = ZD1201_NUMKEYS;
1084
1085 range->num_bitrates = 4;
1086 range->bitrate[0] = 1000000;
1087 range->bitrate[1] = 2000000;
1088 range->bitrate[2] = 5500000;
1089 range->bitrate[3] = 11000000;
1090
1091 range->min_rts = 0;
1092 range->min_frag = ZD1201_FRAGMIN;
1093 range->max_rts = ZD1201_RTSMAX;
1094 range->min_frag = ZD1201_FRAGMAX;
1095
1096 return 0;
1097}
1098
1099/* Little bit of magic here: we only get the quality if we poll
1100 * for it, and we never get an actual request to trigger such
1101 * a poll. Therefore we 'asume' that the user will soon ask for
1102 * the stats after asking the bssid.
1103 */
1104static int zd1201_get_wap(struct net_device *dev,
1105 struct iw_request_info *info, struct sockaddr *ap_addr, char *extra)
1106{
1107 struct zd1201 *zd = (struct zd1201 *)dev->priv;
1108 unsigned char buffer[6];
1109
1110 if (!zd1201_getconfig(zd, ZD1201_RID_COMMSQUALITY, buffer, 6)) {
1111 /* Unfortunatly the quality and noise reported is useless.
1112 they seem to be accumulators that increase until you
1113 read them, unless we poll on a fixed interval we can't
1114 use them
1115 */
1116 /*zd->iwstats.qual.qual = le16_to_cpu(((__le16 *)buffer)[0]);*/
1117 zd->iwstats.qual.level = le16_to_cpu(((__le16 *)buffer)[1]);
1118 /*zd->iwstats.qual.noise = le16_to_cpu(((__le16 *)buffer)[2]);*/
1119 zd->iwstats.qual.updated = 2;
1120 }
1121
1122 return zd1201_getconfig(zd,ZD1201_RID_CURRENTBSSID,ap_addr->sa_data,6);
1123}
1124
1125static int zd1201_set_scan(struct net_device *dev,
1126 struct iw_request_info *info, struct iw_point *srq, char *extra)
1127{
1128 /* We do everything in get_scan */
1129 return 0;
1130}
1131
1132static int zd1201_get_scan(struct net_device *dev,
1133 struct iw_request_info *info, struct iw_point *srq, char *extra)
1134{
1135 struct zd1201 *zd = (struct zd1201 *)dev->priv;
1136 int err, i, j, enabled_save;
1137 struct iw_event iwe;
1138 char *cev = extra;
1139 char *end_buf = extra + IW_SCAN_MAX_DATA;
1140
1141 /* No scanning in AP mode */
1142 if (zd->ap)
1143 return -EOPNOTSUPP;
1144
1145 /* Scan doesn't seem to work if disabled */
1146 enabled_save = zd->mac_enabled;
1147 zd1201_enable(zd);
1148
1149 zd->rxdatas = 0;
1150 err = zd1201_docmd(zd, ZD1201_CMDCODE_INQUIRE,
1151 ZD1201_INQ_SCANRESULTS, 0, 0);
1152 if (err)
1153 return err;
1154
1155 wait_event_interruptible(zd->rxdataq, zd->rxdatas);
1156 if (!zd->rxlen)
1157 return -EIO;
1158
1159 if (le16_to_cpu(*(__le16*)&zd->rxdata[2]) != ZD1201_INQ_SCANRESULTS)
1160 return -EIO;
1161
1162 for(i=8; i<zd->rxlen; i+=62) {
1163 iwe.cmd = SIOCGIWAP;
1164 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1165 memcpy(iwe.u.ap_addr.sa_data, zd->rxdata+i+6, 6);
1166 cev = iwe_stream_add_event(cev, end_buf, &iwe, IW_EV_ADDR_LEN);
1167
1168 iwe.cmd = SIOCGIWESSID;
1169 iwe.u.data.length = zd->rxdata[i+16];
1170 iwe.u.data.flags = 1;
1171 cev = iwe_stream_add_point(cev, end_buf, &iwe, zd->rxdata+i+18);
1172
1173 iwe.cmd = SIOCGIWMODE;
1174 if (zd->rxdata[i+14]&0x01)
1175 iwe.u.mode = IW_MODE_MASTER;
1176 else
1177 iwe.u.mode = IW_MODE_ADHOC;
1178 cev = iwe_stream_add_event(cev, end_buf, &iwe, IW_EV_UINT_LEN);
1179
1180 iwe.cmd = SIOCGIWFREQ;
1181 iwe.u.freq.m = zd->rxdata[i+0];
1182 iwe.u.freq.e = 0;
1183 cev = iwe_stream_add_event(cev, end_buf, &iwe, IW_EV_FREQ_LEN);
1184
1185 iwe.cmd = SIOCGIWRATE;
1186 iwe.u.bitrate.fixed = 0;
1187 iwe.u.bitrate.disabled = 0;
1188 for (j=0; j<10; j++) if (zd->rxdata[i+50+j]) {
1189 iwe.u.bitrate.value = (zd->rxdata[i+50+j]&0x7f)*500000;
1190 cev=iwe_stream_add_event(cev, end_buf, &iwe,
1191 IW_EV_PARAM_LEN);
1192 }
1193
1194 iwe.cmd = SIOCGIWENCODE;
1195 iwe.u.data.length = 0;
1196 if (zd->rxdata[i+14]&0x10)
1197 iwe.u.data.flags = IW_ENCODE_ENABLED;
1198 else
1199 iwe.u.data.flags = IW_ENCODE_DISABLED;
1200 cev = iwe_stream_add_point(cev, end_buf, &iwe, NULL);
1201
1202 iwe.cmd = IWEVQUAL;
1203 iwe.u.qual.qual = zd->rxdata[i+4];
1204 iwe.u.qual.noise= zd->rxdata[i+2]/10-100;
1205 iwe.u.qual.level = (256+zd->rxdata[i+4]*100)/255-100;
1206 iwe.u.qual.updated = 7;
1207 cev = iwe_stream_add_event(cev, end_buf, &iwe, IW_EV_QUAL_LEN);
1208 }
1209
1210 if (!enabled_save)
1211 zd1201_disable(zd);
1212
1213 srq->length = cev - extra;
1214 srq->flags = 0;
1215
1216 return 0;
1217}
1218
1219static int zd1201_set_essid(struct net_device *dev,
1220 struct iw_request_info *info, struct iw_point *data, char *essid)
1221{
1222 struct zd1201 *zd = (struct zd1201 *)dev->priv;
1223
1224 if (data->length > IW_ESSID_MAX_SIZE)
1225 return -EINVAL;
1226 if (data->length < 1)
1227 data->length = 1;
1228 zd->essidlen = data->length-1;
1229 memset(zd->essid, 0, IW_ESSID_MAX_SIZE+1);
1230 memcpy(zd->essid, essid, data->length);
1231 return zd1201_join(zd, zd->essid, zd->essidlen);
1232}
1233
1234static int zd1201_get_essid(struct net_device *dev,
1235 struct iw_request_info *info, struct iw_point *data, char *essid)
1236{
1237 struct zd1201 *zd = (struct zd1201 *)dev->priv;
1238
1239 memcpy(essid, zd->essid, zd->essidlen);
1240 data->flags = 1;
1241 data->length = zd->essidlen;
1242
1243 return 0;
1244}
1245
1246static int zd1201_get_nick(struct net_device *dev, struct iw_request_info *info,
1247 struct iw_point *data, char *nick)
1248{
1249 strcpy(nick, "zd1201");
1250 data->flags = 1;
1251 data->length = strlen(nick);
1252 return 0;
1253}
1254
1255static int zd1201_set_rate(struct net_device *dev,
1256 struct iw_request_info *info, struct iw_param *rrq, char *extra)
1257{
1258 struct zd1201 *zd = (struct zd1201 *)dev->priv;
1259 short rate;
1260 int err;
1261
1262 switch (rrq->value) {
1263 case 1000000:
1264 rate = ZD1201_RATEB1;
1265 break;
1266 case 2000000:
1267 rate = ZD1201_RATEB2;
1268 break;
1269 case 5500000:
1270 rate = ZD1201_RATEB5;
1271 break;
1272 case 11000000:
1273 default:
1274 rate = ZD1201_RATEB11;
1275 break;
1276 }
1277 if (!rrq->fixed) { /* Also enable all lower bitrates */
1278 rate |= rate-1;
1279 }
1280
1281 err = zd1201_setconfig16(zd, ZD1201_RID_TXRATECNTL, rate);
1282 if (err)
1283 return err;
1284
1285 return zd1201_mac_reset(zd);
1286}
1287
1288static int zd1201_get_rate(struct net_device *dev,
1289 struct iw_request_info *info, struct iw_param *rrq, char *extra)
1290{
1291 struct zd1201 *zd = (struct zd1201 *)dev->priv;
1292 short rate;
1293 int err;
1294
1295 err = zd1201_getconfig16(zd, ZD1201_RID_CURRENTTXRATE, &rate);
1296 if (err)
1297 return err;
1298
1299 switch(rate) {
1300 case 1:
1301 rrq->value = 1000000;
1302 break;
1303 case 2:
1304 rrq->value = 2000000;
1305 break;
1306 case 5:
1307 rrq->value = 5500000;
1308 break;
1309 case 11:
1310 rrq->value = 11000000;
1311 break;
1312 default:
1313 rrq->value = 0;
1314 }
1315 rrq->fixed = 0;
1316 rrq->disabled = 0;
1317
1318 return 0;
1319}
1320
1321static int zd1201_set_rts(struct net_device *dev, struct iw_request_info *info,
1322 struct iw_param *rts, char *extra)
1323{
1324 struct zd1201 *zd = (struct zd1201 *)dev->priv;
1325 int err;
1326 short val = rts->value;
1327
1328 if (rts->disabled || !rts->fixed)
1329 val = ZD1201_RTSMAX;
1330 if (val > ZD1201_RTSMAX)
1331 return -EINVAL;
1332 if (val < 0)
1333 return -EINVAL;
1334
1335 err = zd1201_setconfig16(zd, ZD1201_RID_CNFRTSTHRESHOLD, val);
1336 if (err)
1337 return err;
1338 return zd1201_mac_reset(zd);
1339}
1340
1341static int zd1201_get_rts(struct net_device *dev, struct iw_request_info *info,
1342 struct iw_param *rts, char *extra)
1343{
1344 struct zd1201 *zd = (struct zd1201 *)dev->priv;
1345 short rtst;
1346 int err;
1347
1348 err = zd1201_getconfig16(zd, ZD1201_RID_CNFRTSTHRESHOLD, &rtst);
1349 if (err)
1350 return err;
1351 rts->value = rtst;
1352 rts->disabled = (rts->value == ZD1201_RTSMAX);
1353 rts->fixed = 1;
1354
1355 return 0;
1356}
1357
1358static int zd1201_set_frag(struct net_device *dev, struct iw_request_info *info,
1359 struct iw_param *frag, char *extra)
1360{
1361 struct zd1201 *zd = (struct zd1201 *)dev->priv;
1362 int err;
1363 short val = frag->value;
1364
1365 if (frag->disabled || !frag->fixed)
1366 val = ZD1201_FRAGMAX;
1367 if (val > ZD1201_FRAGMAX)
1368 return -EINVAL;
1369 if (val < ZD1201_FRAGMIN)
1370 return -EINVAL;
1371 if (val & 1)
1372 return -EINVAL;
1373 err = zd1201_setconfig16(zd, ZD1201_RID_CNFFRAGTHRESHOLD, val);
1374 if (err)
1375 return err;
1376 return zd1201_mac_reset(zd);
1377}
1378
1379static int zd1201_get_frag(struct net_device *dev, struct iw_request_info *info,
1380 struct iw_param *frag, char *extra)
1381{
1382 struct zd1201 *zd = (struct zd1201 *)dev->priv;
1383 short fragt;
1384 int err;
1385
1386 err = zd1201_getconfig16(zd, ZD1201_RID_CNFFRAGTHRESHOLD, &fragt);
1387 if (err)
1388 return err;
1389 frag->value = fragt;
1390 frag->disabled = (frag->value == ZD1201_FRAGMAX);
1391 frag->fixed = 1;
1392
1393 return 0;
1394}
1395
1396static int zd1201_set_retry(struct net_device *dev,
1397 struct iw_request_info *info, struct iw_param *rrq, char *extra)
1398{
1399 return 0;
1400}
1401
1402static int zd1201_get_retry(struct net_device *dev,
1403 struct iw_request_info *info, struct iw_param *rrq, char *extra)
1404{
1405 return 0;
1406}
1407
1408static int zd1201_set_encode(struct net_device *dev,
1409 struct iw_request_info *info, struct iw_point *erq, char *key)
1410{
1411 struct zd1201 *zd = (struct zd1201 *)dev->priv;
1412 short i;
1413 int err, rid;
1414
1415 if (erq->length > ZD1201_MAXKEYLEN)
1416 return -EINVAL;
1417
1418 i = (erq->flags & IW_ENCODE_INDEX)-1;
1419 if (i == -1) {
1420 err = zd1201_getconfig16(zd,ZD1201_RID_CNFDEFAULTKEYID,&i);
1421 if (err)
1422 return err;
1423 } else {
1424 err = zd1201_setconfig16(zd, ZD1201_RID_CNFDEFAULTKEYID, i);
1425 if (err)
1426 return err;
1427 }
1428
1429 if (i < 0 || i >= ZD1201_NUMKEYS)
1430 return -EINVAL;
1431
1432 rid = ZD1201_RID_CNFDEFAULTKEY0 + i;
1433 err = zd1201_setconfig(zd, rid, key, erq->length, 1);
1434 if (err)
1435 return err;
1436 zd->encode_keylen[i] = erq->length;
1437 memcpy(zd->encode_keys[i], key, erq->length);
1438
1439 i=0;
1440 if (!(erq->flags & IW_ENCODE_DISABLED & IW_ENCODE_MODE)) {
1441 i |= 0x01;
1442 zd->encode_enabled = 1;
1443 } else
1444 zd->encode_enabled = 0;
1445 if (erq->flags & IW_ENCODE_RESTRICTED & IW_ENCODE_MODE) {
1446 i |= 0x02;
1447 zd->encode_restricted = 1;
1448 } else
1449 zd->encode_restricted = 0;
1450 err = zd1201_setconfig16(zd, ZD1201_RID_CNFWEBFLAGS, i);
1451 if (err)
1452 return err;
1453
1454 if (zd->encode_enabled)
1455 i = ZD1201_CNFAUTHENTICATION_SHAREDKEY;
1456 else
1457 i = ZD1201_CNFAUTHENTICATION_OPENSYSTEM;
1458 err = zd1201_setconfig16(zd, ZD1201_RID_CNFAUTHENTICATION, i);
1459 if (err)
1460 return err;
1461
1462 return zd1201_mac_reset(zd);
1463}
1464
1465static int zd1201_get_encode(struct net_device *dev,
1466 struct iw_request_info *info, struct iw_point *erq, char *key)
1467{
1468 struct zd1201 *zd = (struct zd1201 *)dev->priv;
1469 short i;
1470 int err;
1471
1472 if (zd->encode_enabled)
1473 erq->flags = IW_ENCODE_ENABLED;
1474 else
1475 erq->flags = IW_ENCODE_DISABLED;
1476 if (zd->encode_restricted)
1477 erq->flags |= IW_ENCODE_RESTRICTED;
1478 else
1479 erq->flags |= IW_ENCODE_OPEN;
1480
1481 i = (erq->flags & IW_ENCODE_INDEX) -1;
1482 if (i == -1) {
1483 err = zd1201_getconfig16(zd, ZD1201_RID_CNFDEFAULTKEYID, &i);
1484 if (err)
1485 return err;
1486 }
1487 if (i<0 || i>= ZD1201_NUMKEYS)
1488 return -EINVAL;
1489
1490 erq->flags |= i+1;
1491
1492 erq->length = zd->encode_keylen[i];
1493 memcpy(key, zd->encode_keys[i], erq->length);
1494
1495 return 0;
1496}
1497
1498static int zd1201_set_power(struct net_device *dev,
1499 struct iw_request_info *info, struct iw_param *vwrq, char *extra)
1500{
1501 struct zd1201 *zd = (struct zd1201 *)dev->priv;
1502 short enabled, duration, level;
1503 int err;
1504
1505 enabled = vwrq->disabled ? 0 : 1;
1506 if (enabled) {
1507 if (vwrq->flags & IW_POWER_PERIOD) {
1508 duration = vwrq->value;
1509 err = zd1201_setconfig16(zd,
1510 ZD1201_RID_CNFMAXSLEEPDURATION, duration);
1511 if (err)
1512 return err;
1513 goto out;
1514 }
1515 if (vwrq->flags & IW_POWER_TIMEOUT) {
1516 err = zd1201_getconfig16(zd,
1517 ZD1201_RID_CNFMAXSLEEPDURATION, &duration);
1518 if (err)
1519 return err;
1520 level = vwrq->value * 4 / duration;
1521 if (level > 4)
1522 level = 4;
1523 if (level < 0)
1524 level = 0;
1525 err = zd1201_setconfig16(zd, ZD1201_RID_CNFPMEPS,
1526 level);
1527 if (err)
1528 return err;
1529 goto out;
1530 }
1531 return -EINVAL;
1532 }
1533out:
1534 err = zd1201_setconfig16(zd, ZD1201_RID_CNFPMENABLED, enabled);
1535 if (err)
1536 return err;
1537
1538 return 0;
1539}
1540
1541static int zd1201_get_power(struct net_device *dev,
1542 struct iw_request_info *info, struct iw_param *vwrq, char *extra)
1543{
1544 struct zd1201 *zd = (struct zd1201 *)dev->priv;
1545 short enabled, level, duration;
1546 int err;
1547
1548 err = zd1201_getconfig16(zd, ZD1201_RID_CNFPMENABLED, &enabled);
1549 if (err)
1550 return err;
1551 err = zd1201_getconfig16(zd, ZD1201_RID_CNFPMEPS, &level);
1552 if (err)
1553 return err;
1554 err = zd1201_getconfig16(zd, ZD1201_RID_CNFMAXSLEEPDURATION, &duration);
1555 if (err)
1556 return err;
1557 vwrq->disabled = enabled ? 0 : 1;
1558 if (vwrq->flags & IW_POWER_TYPE) {
1559 if (vwrq->flags & IW_POWER_PERIOD) {
1560 vwrq->value = duration;
1561 vwrq->flags = IW_POWER_PERIOD;
1562 } else {
1563 vwrq->value = duration * level / 4;
1564 vwrq->flags = IW_POWER_TIMEOUT;
1565 }
1566 }
1567 if (vwrq->flags & IW_POWER_MODE) {
1568 if (enabled && level)
1569 vwrq->flags = IW_POWER_UNICAST_R;
1570 else
1571 vwrq->flags = IW_POWER_ALL_R;
1572 }
1573
1574 return 0;
1575}
1576
1577
1578static const iw_handler zd1201_iw_handler[] =
1579{
1580 (iw_handler) zd1201_config_commit, /* SIOCSIWCOMMIT */
1581 (iw_handler) zd1201_get_name, /* SIOCGIWNAME */
1582 (iw_handler) NULL, /* SIOCSIWNWID */
1583 (iw_handler) NULL, /* SIOCGIWNWID */
1584 (iw_handler) zd1201_set_freq, /* SIOCSIWFREQ */
1585 (iw_handler) zd1201_get_freq, /* SIOCGIWFREQ */
1586 (iw_handler) zd1201_set_mode, /* SIOCSIWMODE */
1587 (iw_handler) zd1201_get_mode, /* SIOCGIWMODE */
1588 (iw_handler) NULL, /* SIOCSIWSENS */
1589 (iw_handler) NULL, /* SIOCGIWSENS */
1590 (iw_handler) NULL, /* SIOCSIWRANGE */
1591 (iw_handler) zd1201_get_range, /* SIOCGIWRANGE */
1592 (iw_handler) NULL, /* SIOCSIWPRIV */
1593 (iw_handler) NULL, /* SIOCGIWPRIV */
1594 (iw_handler) NULL, /* SIOCSIWSTATS */
1595 (iw_handler) NULL, /* SIOCGIWSTATS */
1596 (iw_handler) NULL, /* SIOCSIWSPY */
1597 (iw_handler) NULL, /* SIOCGIWSPY */
1598 (iw_handler) NULL, /* -- hole -- */
1599 (iw_handler) NULL, /* -- hole -- */
1600 (iw_handler) NULL/*zd1201_set_wap*/, /* SIOCSIWAP */
1601 (iw_handler) zd1201_get_wap, /* SIOCGIWAP */
1602 (iw_handler) NULL, /* -- hole -- */
1603 (iw_handler) NULL, /* SIOCGIWAPLIST */
1604 (iw_handler) zd1201_set_scan, /* SIOCSIWSCAN */
1605 (iw_handler) zd1201_get_scan, /* SIOCGIWSCAN */
1606 (iw_handler) zd1201_set_essid, /* SIOCSIWESSID */
1607 (iw_handler) zd1201_get_essid, /* SIOCGIWESSID */
1608 (iw_handler) NULL, /* SIOCSIWNICKN */
1609 (iw_handler) zd1201_get_nick, /* SIOCGIWNICKN */
1610 (iw_handler) NULL, /* -- hole -- */
1611 (iw_handler) NULL, /* -- hole -- */
1612 (iw_handler) zd1201_set_rate, /* SIOCSIWRATE */
1613 (iw_handler) zd1201_get_rate, /* SIOCGIWRATE */
1614 (iw_handler) zd1201_set_rts, /* SIOCSIWRTS */
1615 (iw_handler) zd1201_get_rts, /* SIOCGIWRTS */
1616 (iw_handler) zd1201_set_frag, /* SIOCSIWFRAG */
1617 (iw_handler) zd1201_get_frag, /* SIOCGIWFRAG */
1618 (iw_handler) NULL, /* SIOCSIWTXPOW */
1619 (iw_handler) NULL, /* SIOCGIWTXPOW */
1620 (iw_handler) zd1201_set_retry, /* SIOCSIWRETRY */
1621 (iw_handler) zd1201_get_retry, /* SIOCGIWRETRY */
1622 (iw_handler) zd1201_set_encode, /* SIOCSIWENCODE */
1623 (iw_handler) zd1201_get_encode, /* SIOCGIWENCODE */
1624 (iw_handler) zd1201_set_power, /* SIOCSIWPOWER */
1625 (iw_handler) zd1201_get_power, /* SIOCGIWPOWER */
1626};
1627
1628static int zd1201_set_hostauth(struct net_device *dev,
1629 struct iw_request_info *info, struct iw_param *rrq, char *extra)
1630{
1631 struct zd1201 *zd = (struct zd1201 *)dev->priv;
1632 int err;
1633
1634 if (!zd->ap)
1635 return -EOPNOTSUPP;
1636
1637 err = zd1201_setconfig16(zd, ZD1201_RID_CNFHOSTAUTH, rrq->value);
1638 if (err)
1639 return err;
1640 return 0;
1641}
1642
1643static int zd1201_get_hostauth(struct net_device *dev,
1644 struct iw_request_info *info, struct iw_param *rrq, char *extra)
1645{
1646 struct zd1201 *zd = (struct zd1201 *)dev->priv;
1647 short hostauth;
1648 int err;
1649
1650 if (!zd->ap)
1651 return -EOPNOTSUPP;
1652
1653 err = zd1201_getconfig16(zd, ZD1201_RID_CNFHOSTAUTH, &hostauth);
1654 if (err)
1655 return err;
1656 rrq->value = hostauth;
1657 rrq->fixed = 1;
1658
1659 return 0;
1660}
1661
1662static int zd1201_auth_sta(struct net_device *dev,
1663 struct iw_request_info *info, struct sockaddr *sta, char *extra)
1664{
1665 struct zd1201 *zd = (struct zd1201 *)dev->priv;
1666 unsigned char buffer[10];
1667
1668 if (!zd->ap)
1669 return -EOPNOTSUPP;
1670
1671 memcpy(buffer, sta->sa_data, ETH_ALEN);
1672 *(short*)(buffer+6) = 0; /* 0==success, 1==failure */
1673 *(short*)(buffer+8) = 0;
1674
1675 return zd1201_setconfig(zd, ZD1201_RID_AUTHENTICATESTA, buffer, 10, 1);
1676}
1677
1678static int zd1201_set_maxassoc(struct net_device *dev,
1679 struct iw_request_info *info, struct iw_param *rrq, char *extra)
1680{
1681 struct zd1201 *zd = (struct zd1201 *)dev->priv;
1682 int err;
1683
1684 if (!zd->ap)
1685 return -EOPNOTSUPP;
1686
1687 err = zd1201_setconfig16(zd, ZD1201_RID_CNFMAXASSOCSTATIONS, rrq->value);
1688 if (err)
1689 return err;
1690 return 0;
1691}
1692
1693static int zd1201_get_maxassoc(struct net_device *dev,
1694 struct iw_request_info *info, struct iw_param *rrq, char *extra)
1695{
1696 struct zd1201 *zd = (struct zd1201 *)dev->priv;
1697 short maxassoc;
1698 int err;
1699
1700 if (!zd->ap)
1701 return -EOPNOTSUPP;
1702
1703 err = zd1201_getconfig16(zd, ZD1201_RID_CNFMAXASSOCSTATIONS, &maxassoc);
1704 if (err)
1705 return err;
1706 rrq->value = maxassoc;
1707 rrq->fixed = 1;
1708
1709 return 0;
1710}
1711
1712static const iw_handler zd1201_private_handler[] = {
1713 (iw_handler) zd1201_set_hostauth, /* ZD1201SIWHOSTAUTH */
1714 (iw_handler) zd1201_get_hostauth, /* ZD1201GIWHOSTAUTH */
1715 (iw_handler) zd1201_auth_sta, /* ZD1201SIWAUTHSTA */
1716 (iw_handler) NULL, /* nothing to get */
1717 (iw_handler) zd1201_set_maxassoc, /* ZD1201SIMAXASSOC */
1718 (iw_handler) zd1201_get_maxassoc, /* ZD1201GIMAXASSOC */
1719};
1720
1721static const struct iw_priv_args zd1201_private_args[] = {
1722 { ZD1201SIWHOSTAUTH, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1723 IW_PRIV_TYPE_NONE, "sethostauth" },
1724 { ZD1201GIWHOSTAUTH, IW_PRIV_TYPE_NONE,
1725 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostauth" },
1726 { ZD1201SIWAUTHSTA, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1,
1727 IW_PRIV_TYPE_NONE, "authstation" },
1728 { ZD1201SIWMAXASSOC, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1729 IW_PRIV_TYPE_NONE, "setmaxassoc" },
1730 { ZD1201GIWMAXASSOC, IW_PRIV_TYPE_NONE,
1731 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmaxassoc" },
1732};
1733
1734static const struct iw_handler_def zd1201_iw_handlers = {
1735 .num_standard = sizeof(zd1201_iw_handler)/sizeof(iw_handler),
1736 .num_private = sizeof(zd1201_private_handler)/sizeof(iw_handler),
1737 .num_private_args = sizeof(zd1201_private_args)/sizeof(struct iw_priv_args),
1738 .standard = (iw_handler *)zd1201_iw_handler,
1739 .private = (iw_handler *)zd1201_private_handler,
1740 .private_args = (struct iw_priv_args *) zd1201_private_args,
1741};
1742
1743int zd1201_probe(struct usb_interface *interface, const struct usb_device_id *id)
1744{
1745 struct zd1201 *zd;
1746 struct usb_device *usb;
1747 int i, err;
1748 short porttype;
1749 char buf[IW_ESSID_MAX_SIZE+2];
1750
1751 usb = interface_to_usbdev(interface);
1752
1753 zd = kmalloc(sizeof(struct zd1201), GFP_KERNEL);
1754 if (!zd) {
1755 return -ENOMEM;
1756 }
1757 memset(zd, 0, sizeof(struct zd1201));
1758 zd->ap = ap;
1759 zd->usb = usb;
1760 zd->removed = 0;
1761 init_waitqueue_head(&zd->rxdataq);
1762 INIT_HLIST_HEAD(&zd->fraglist);
1763
1764 err = zd1201_fw_upload(usb, zd->ap);
1765 if (err) {
1766 dev_err(&usb->dev, "zd1201 firmware upload failed: %d\n", err);
1767 goto err_zd;
1768 }
1769
1770 zd->endp_in = 1;
1771 zd->endp_out = 1;
1772 zd->endp_out2 = 2;
1773 zd->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
1774 zd->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
1775 if (!zd->rx_urb || !zd->tx_urb)
1776 goto err_zd;
1777
1778 for(i = 0; i<100; i++)
1779 udelay(1000);
1780
1781 err = zd1201_drvr_start(zd);
1782 if (err)
1783 goto err_zd;
1784
1785 err = zd1201_setconfig16(zd, ZD1201_RID_CNFMAXDATALEN, 2312);
1786 if (err)
1787 goto err_start;
1788
1789 err = zd1201_setconfig16(zd, ZD1201_RID_TXRATECNTL,
1790 ZD1201_RATEB1 | ZD1201_RATEB2 | ZD1201_RATEB5 | ZD1201_RATEB11);
1791 if (err)
1792 goto err_start;
1793
1794 zd->dev = alloc_etherdev(0);
1795 if (!zd->dev)
1796 goto err_start;
1797
1798 zd->dev->priv = zd;
1799 zd->dev->open = zd1201_net_open;
1800 zd->dev->stop = zd1201_net_stop;
1801 zd->dev->get_stats = zd1201_get_stats;
1802 zd->dev->get_wireless_stats = zd1201_get_wireless_stats;
1803 zd->dev->wireless_handlers =
1804 (struct iw_handler_def *)&zd1201_iw_handlers;
1805 zd->dev->hard_start_xmit = zd1201_hard_start_xmit;
1806 zd->dev->watchdog_timeo = ZD1201_TX_TIMEOUT;
1807 zd->dev->tx_timeout = zd1201_tx_timeout;
1808 zd->dev->set_multicast_list = zd1201_set_multicast;
1809 zd->dev->set_mac_address = zd1201_set_mac_address;
1810 strcpy(zd->dev->name, "wlan%d");
1811
1812 err = zd1201_getconfig(zd, ZD1201_RID_CNFOWNMACADDR,
1813 zd->dev->dev_addr, zd->dev->addr_len);
1814 if (err)
1815 goto err_net;
1816
1817 /* Set wildcard essid to match zd->essid */
1818 *(__le16 *)buf = cpu_to_le16(0);
1819 err = zd1201_setconfig(zd, ZD1201_RID_CNFDESIREDSSID, buf,
1820 IW_ESSID_MAX_SIZE+2, 1);
1821 if (err)
1822 goto err_net;
1823
1824 if (zd->ap)
1825 porttype = ZD1201_PORTTYPE_AP;
1826 else
1827 porttype = ZD1201_PORTTYPE_BSS;
1828 err = zd1201_setconfig16(zd, ZD1201_RID_CNFPORTTYPE, porttype);
1829 if (err)
1830 goto err_net;
1831
1832 err = register_netdev(zd->dev);
1833 if (err)
1834 goto err_net;
1835 dev_info(&usb->dev, "%s: ZD1201 USB Wireless interface\n",
1836 zd->dev->name);
1837
1838 usb_set_intfdata(interface, zd);
1839 return 0;
1840
1841err_net:
1842 free_netdev(zd->dev);
1843err_start:
1844 /* Leave the device in reset state */
1845 zd1201_docmd(zd, ZD1201_CMDCODE_INIT, 0, 0, 0);
1846err_zd:
1847 if (zd->tx_urb)
1848 usb_free_urb(zd->tx_urb);
1849 if (zd->rx_urb)
1850 usb_free_urb(zd->rx_urb);
1851 kfree(zd);
1852 return err;
1853}
1854
1855void zd1201_disconnect(struct usb_interface *interface)
1856{
1857 struct zd1201 *zd=(struct zd1201 *)usb_get_intfdata(interface);
1858 struct hlist_node *node, *node2;
1859 struct zd1201_frag *frag;
1860
1861 if (!zd)
1862 return;
1863 usb_set_intfdata(interface, NULL);
1864 if (zd->dev) {
1865 unregister_netdev(zd->dev);
1866 free_netdev(zd->dev);
1867 }
1868
1869 hlist_for_each_entry_safe(frag, node, node2, &zd->fraglist, fnode) {
1870 hlist_del_init(&frag->fnode);
1871 kfree_skb(frag->skb);
1872 kfree(frag);
1873 }
1874
1875 if (zd->tx_urb) {
1876 usb_kill_urb(zd->tx_urb);
1877 usb_free_urb(zd->tx_urb);
1878 }
1879 if (zd->rx_urb) {
1880 usb_kill_urb(zd->rx_urb);
1881 usb_free_urb(zd->rx_urb);
1882 }
1883 kfree(zd);
1884}
1885
1886struct usb_driver zd1201_usb = {
1887 .owner = THIS_MODULE,
1888 .name = "zd1201",
1889 .probe = zd1201_probe,
1890 .disconnect = zd1201_disconnect,
1891 .id_table = zd1201_table,
1892};
1893
1894static int __init zd1201_init(void)
1895{
1896 return usb_register(&zd1201_usb);
1897}
1898
1899static void __exit zd1201_cleanup(void)
1900{
1901 usb_deregister(&zd1201_usb);
1902}
1903
1904module_init(zd1201_init);
1905module_exit(zd1201_cleanup);
diff --git a/drivers/usb/net/zd1201.h b/drivers/usb/net/zd1201.h
new file mode 100644
index 000000000000..1627c71e8052
--- /dev/null
+++ b/drivers/usb/net/zd1201.h
@@ -0,0 +1,147 @@
1/*
2 * Copyright (c) 2004, 2005 Jeroen Vreeken (pe1rxq@amsat.org)
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * version 2 as published by the Free Software Foundation.
7 *
8 * Parts of this driver have been derived from a wlan-ng version
9 * modified by ZyDAS.
10 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
11 */
12
13#ifndef _INCLUDE_ZD1201_H_
14#define _INCLUDE_ZD1201_H_
15
16#define ZD1201_NUMKEYS 4
17#define ZD1201_MAXKEYLEN 13
18#define ZD1201_MAXMULTI 16
19#define ZD1201_FRAGMAX 2500
20#define ZD1201_FRAGMIN 256
21#define ZD1201_RTSMAX 2500
22
23#define ZD1201_RXSIZE 3000
24
25struct zd1201 {
26 struct usb_device *usb;
27 int removed;
28 struct net_device *dev;
29 struct net_device_stats stats;
30 struct iw_statistics iwstats;
31
32 int endp_in;
33 int endp_out;
34 int endp_out2;
35 struct urb *rx_urb;
36 struct urb *tx_urb;
37
38 unsigned char rxdata[ZD1201_RXSIZE];
39 int rxlen;
40 wait_queue_head_t rxdataq;
41 int rxdatas;
42 struct hlist_head fraglist;
43 unsigned char txdata[ZD1201_RXSIZE];
44
45 int ap;
46 char essid[IW_ESSID_MAX_SIZE+1];
47 int essidlen;
48 int mac_enabled;
49 int monitor;
50 int encode_enabled;
51 int encode_restricted;
52 unsigned char encode_keys[ZD1201_NUMKEYS][ZD1201_MAXKEYLEN];
53 int encode_keylen[ZD1201_NUMKEYS];
54};
55
56struct zd1201_frag {
57 struct hlist_node fnode;
58 int seq;
59 struct sk_buff *skb;
60};
61
62#define ZD1201SIWHOSTAUTH SIOCIWFIRSTPRIV
63#define ZD1201GIWHOSTAUTH ZD1201SIWHOSTAUTH+1
64#define ZD1201SIWAUTHSTA SIOCIWFIRSTPRIV+2
65#define ZD1201SIWMAXASSOC SIOCIWFIRSTPRIV+4
66#define ZD1201GIWMAXASSOC ZD1201SIWMAXASSOC+1
67
68#define ZD1201_FW_TIMEOUT (1000)
69
70#define ZD1201_TX_TIMEOUT (2000)
71
72#define ZD1201_USB_CMDREQ 0
73#define ZD1201_USB_RESREQ 1
74
75#define ZD1201_CMDCODE_INIT 0x00
76#define ZD1201_CMDCODE_ENABLE 0x01
77#define ZD1201_CMDCODE_DISABLE 0x02
78#define ZD1201_CMDCODE_ALLOC 0x0a
79#define ZD1201_CMDCODE_INQUIRE 0x11
80#define ZD1201_CMDCODE_SETRXRID 0x17
81#define ZD1201_CMDCODE_ACCESS 0x21
82
83#define ZD1201_PACKET_EVENTSTAT 0x0
84#define ZD1201_PACKET_RXDATA 0x1
85#define ZD1201_PACKET_INQUIRE 0x2
86#define ZD1201_PACKET_RESOURCE 0x3
87
88#define ZD1201_ACCESSBIT 0x0100
89
90#define ZD1201_RID_CNFPORTTYPE 0xfc00
91#define ZD1201_RID_CNFOWNMACADDR 0xfc01
92#define ZD1201_RID_CNFDESIREDSSID 0xfc02
93#define ZD1201_RID_CNFOWNCHANNEL 0xfc03
94#define ZD1201_RID_CNFOWNSSID 0xfc04
95#define ZD1201_RID_CNFMAXDATALEN 0xfc07
96#define ZD1201_RID_CNFPMENABLED 0xfc09
97#define ZD1201_RID_CNFPMEPS 0xfc0a
98#define ZD1201_RID_CNFMAXSLEEPDURATION 0xfc0c
99#define ZD1201_RID_CNFDEFAULTKEYID 0xfc23
100#define ZD1201_RID_CNFDEFAULTKEY0 0xfc24
101#define ZD1201_RID_CNFDEFAULTKEY1 0xfc25
102#define ZD1201_RID_CNFDEFAULTKEY2 0xfc26
103#define ZD1201_RID_CNFDEFAULTKEY3 0xfc27
104#define ZD1201_RID_CNFWEBFLAGS 0xfc28
105#define ZD1201_RID_CNFAUTHENTICATION 0xfc2a
106#define ZD1201_RID_CNFMAXASSOCSTATIONS 0xfc2b
107#define ZD1201_RID_CNFHOSTAUTH 0xfc2e
108#define ZD1201_RID_CNFGROUPADDRESS 0xfc80
109#define ZD1201_RID_CNFFRAGTHRESHOLD 0xfc82
110#define ZD1201_RID_CNFRTSTHRESHOLD 0xfc83
111#define ZD1201_RID_TXRATECNTL 0xfc84
112#define ZD1201_RID_PROMISCUOUSMODE 0xfc85
113#define ZD1201_RID_CNFBASICRATES 0xfcb3
114#define ZD1201_RID_AUTHENTICATESTA 0xfce3
115#define ZD1201_RID_CURRENTBSSID 0xfd42
116#define ZD1201_RID_COMMSQUALITY 0xfd43
117#define ZD1201_RID_CURRENTTXRATE 0xfd44
118#define ZD1201_RID_CNFMAXTXBUFFERNUMBER 0xfda0
119#define ZD1201_RID_CURRENTCHANNEL 0xfdc1
120
121#define ZD1201_INQ_SCANRESULTS 0xf101
122
123#define ZD1201_INF_LINKSTATUS 0xf200
124#define ZD1201_INF_ASSOCSTATUS 0xf201
125#define ZD1201_INF_AUTHREQ 0xf202
126
127#define ZD1201_ASSOCSTATUS_STAASSOC 0x1
128#define ZD1201_ASSOCSTATUS_REASSOC 0x2
129#define ZD1201_ASSOCSTATUS_DISASSOC 0x3
130#define ZD1201_ASSOCSTATUS_ASSOCFAIL 0x4
131#define ZD1201_ASSOCSTATUS_AUTHFAIL 0x5
132
133#define ZD1201_PORTTYPE_IBSS 0
134#define ZD1201_PORTTYPE_BSS 1
135#define ZD1201_PORTTYPE_WDS 2
136#define ZD1201_PORTTYPE_PSEUDOIBSS 3
137#define ZD1201_PORTTYPE_AP 6
138
139#define ZD1201_RATEB1 1
140#define ZD1201_RATEB2 2
141#define ZD1201_RATEB5 4 /* 5.5 really, but 5 is shorter :) */
142#define ZD1201_RATEB11 8
143
144#define ZD1201_CNFAUTHENTICATION_OPENSYSTEM 0x0001
145#define ZD1201_CNFAUTHENTICATION_SHAREDKEY 0x0002
146
147#endif /* _INCLUDE_ZD1201_H_ */