3 * Implements the functions of the ZyDAS zd1211 MAC
5 * Copyright (C) 2004 ZyDAS Inc. All Rights Reserved.
6 * --------------------------------------------------------------------
10 * The contents of this file are subject to the Mozilla Public
11 * License Version 1.1 (the "License"); you may not use this file
12 * except in compliance with the License. You may obtain a copy of
13 * the License at http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS
16 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17 * implied. See the License for the specific language governing
18 * rights and limitations under the License.
20 * Alternatively, the contents of this file may be used under the
21 * terms of the GNU Public License version 2 (the "GPL"), in which
22 * case the provisions of the GPL are applicable instead of the
23 * above. If you wish to allow the use of your version of this file
24 * only under the terms of the GPL and not to allow others to use
25 * your version of this file under the MPL, indicate your decision
26 * by deleting the provisions above and replace them with the notice
27 * and other provisions required by the GPL. If you do not delete
28 * the provisions above, a recipient may use your version of this
29 * file under either the MPL or the GPL.
31 * -------------------------------------------------------------------- */
33 #include <linux/version.h>
36 #include <linux/modversions.h>
39 #include <linux/module.h>
41 #include <linux/usb.h>
46 #include "zdversion.h"
49 #define ZD1211_DBG_LEVEL 1
51 MODULE_AUTHOR("Yarco Yang");
52 MODULE_DESCRIPTION("ZyDAS 802.11b/g USB Wireless LAN adapter");
53 MODULE_LICENSE("GPL");
56 static const char driver_name
[] = "zd1211";
57 #elif defined(ZD1211B)
58 static const char driver_name
[] = "zd1211b";
62 /* table of devices that work with this driver */
63 static struct usb_device_id zd1211_ids
[] = {
65 { USB_DEVICE(VENDOR_ZYDAS
, 0x1215) },
66 { USB_DEVICE(VENDOR_ZYDAS
, 0xA215) },
67 { USB_DEVICE(0x0053, 0x5301) },
68 { USB_DEVICE(0x0053, 0x5302) },
69 { USB_DEVICE(0x2019, 0x5303) }, //Add, 2006.04.17
70 { USB_DEVICE(0x050D, 0x4050) },
71 { USB_DEVICE(0x050D, 0x705C) },
72 { USB_DEVICE(0x0586, 0x340F) },
73 { USB_DEVICE(0x079B, 0x0062) },
74 { USB_DEVICE(0x083A, 0x4505) },
75 { USB_DEVICE(0x083A, 0xE501) },
76 { USB_DEVICE(0x0BAF, 0x0121) },
77 { USB_DEVICE(0x0CDE, 0x001A) },
78 { USB_DEVICE(0x0DF6, 0x9075) },
79 { USB_DEVICE(0x0F88, 0x3014) },
80 { USB_DEVICE(0x1233, 0x0471) },
81 { USB_DEVICE(0x1582, 0x6003) },
83 { USB_DEVICE(VENDOR_ZYDAS
, PRODUCT_1211
) },
84 { USB_DEVICE(VENDOR_ZYDAS
, PRODUCT_A211
) },
85 { USB_DEVICE(VENDOR_ZYXEL
, PRODUCT_G220
) },
86 { USB_DEVICE(VENDOR_3COM
, PRODUCT_A727
) },
87 { USB_DEVICE(0x2019, 0xc008) },
88 { USB_DEVICE(0x2019, 0xc009) },
89 { USB_DEVICE(0x079b, 0x004a) },
90 { USB_DEVICE(0x07b8, 0x6001) },
91 { USB_DEVICE(0x0b3b, 0x1630) },
92 { USB_DEVICE(0x0b3b, 0x5630) },
93 { USB_DEVICE(0x0b3b, 0x6630) },
94 { USB_DEVICE(0x0cde, 0x0011) },
95 { USB_DEVICE(0x0df6, 0x9071) },
96 { USB_DEVICE(0x126f, 0xa006) },
97 { USB_DEVICE(0x129b, 0x1666) },
98 { USB_DEVICE(0x1435, 0x0711) },
99 { USB_DEVICE(0x0DF6, 0x9071) },
100 { USB_DEVICE(0x0105, 0x145F) },
103 { } /* Terminating entry */
107 MODULE_DEVICE_TABLE(usb
, zd1211_ids
);
108 int zd1211_FirstLoad
= 1;
109 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
110 module_param(zd1211_FirstLoad
, int, S_IRUGO
);
112 MODULE_PARM(zd1211_FirstLoad
, "i");
116 extern struct net_device
*g_dev
;
117 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
118 static void *zd1211_probe(struct usb_device
*dev
, unsigned int ifnum
, const struct usb_device_id
*id
)
120 static int zd1211_probe(struct usb_interface
*interface
, const struct usb_device_id
*id
)
123 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
124 struct usb_interface
*interface
= &dev
->actconfig
->interface
[ifnum
];
126 struct usb_device
*dev
= interface_to_usbdev(interface
);
129 struct net_device
*net
= NULL
;
130 struct zd1205_private
*macp
= NULL
;
131 int vendor_id
, product_id
;
132 int dev_index
= id
- zd1211_ids
;
135 //char serial_number[30];
136 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
137 //Drivers for USB interfaces should normally record such references in
138 //their probe() methods, when they bind to an interface, and release
139 //them by calling usb_put_dev(), in their disconnect() methods.
140 //A pointer to the device with the incremented reference counter is returned.
144 vendor_id
= zd_le16_to_cpu(dev
->descriptor
.idVendor
);
145 product_id
= zd_le16_to_cpu(dev
->descriptor
.idProduct
);
148 printk(KERN_NOTICE
"vendor_id = %04x\n", vendor_id
);
149 printk(KERN_NOTICE
"product_id = %04x\n", product_id
);
151 if (dev
->speed
== USB_SPEED_HIGH
)
152 printk(KERN_NOTICE
"USB 2.0 Host\n");
154 printk(KERN_NOTICE
"USB 1.1 Host\n");
157 //memset(serial_number, 0, 30);
158 //usb_string(dev, dev->descriptor.iSerialNumber, serial_number, 29);
159 //printk("Device serial number is %s\n", serial_number);
161 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
162 if (usb_set_configuration(dev
, dev
->config
[0].bConfigurationValue
)) {
163 printk(KERN_ERR
"usb_set_configuration() failed\n");
171 if (!(macp
= kmalloc(sizeof(struct zd1205_private
), GFP_KERNEL
))) {
172 printk(KERN_ERR
"out of memory allocating device structure\n");
177 memset(macp
, 0, sizeof(struct zd1205_private
));
181 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
182 usb_inc_dev_use(dev
);
185 net
= alloc_etherdev(0); //kernel 2.6
186 //net = alloc_etherdev(sizeof (struct zd1205_private)); //kernel 2.4
189 printk(KERN_ERR
"zd1211: Not able to alloc etherdev struct\n");
194 g_dev
= net
; //save this for CBs use
195 //macp = net->priv; //kernel 2.4
196 net
->priv
= macp
; //kernel 2.6
199 SET_MODULE_OWNER(net
);
200 macp
->dev_index
= dev_index
;
201 macp
->release
= zd_le16_to_cpu(dev
->descriptor
.bcdDevice
);
202 printk(KERN_NOTICE
"Release Ver = %04x\n", macp
->release
);
204 macp
->dbg_flag
= ZD1211_DBG_LEVEL
;
206 /* set up the endpoint information */
207 /* check out the endpoints */
208 macp
->interface
= interface
;
210 init_waitqueue_head(&macp
->regSet_wait
);
211 init_waitqueue_head(&macp
->iorwRsp_wait
);
212 init_waitqueue_head(&macp
->term_wait
);
213 init_waitqueue_head(&macp
->msdelay
);
215 if (!zd1211_alloc_all_urbs(macp
)){
216 printk("Calling zd1211_alloc_all_urbs fails\n");
221 //zd1211_DownLoadUSBCode(macp, "WS11Uext.bin", NULL, cFIRMWARE_EXT_CODE);
222 //If the driver was removed and reinstall without unplug the device.
223 //You can tell the driver not to download the firmware again by issing
224 //insmod zd1211b zd1211_FirstDown=0. Redownload causes device crash
227 if (zd1211_Download_IncludeFile(macp
) != 0){
228 printk(KERN_ERR
"zd1211_Download_IncludeFile failed\n");
235 //#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
236 // if (usb_set_configuration(dev, dev->config[0].bConfigurationValue)) {
238 // if (usb_set_interface(dev, interface->altsetting[0].desc.bInterfaceNumber, 0)){
239 // Use the lowest USBD API to issue set_configuration command.
240 if ((usb_control_msg(dev
, usb_sndctrlpipe(dev
,0),USB_REQ_SET_CONFIGURATION
,0, 1, 0, NULL
, 0, HZ
))<0)
243 printk(KERN_ERR
"usb_set_configuration() failed\n");
248 set_bit(ZD1211_RUNNING
, &macp
->flags
);
249 macp
->bUSBDeveiceAttached
= 1;
251 if (!zd1211_InitSetup(net
, macp
))
253 printk("Calling zd1211_InitSetup fails\n");
259 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
260 usb_set_intfdata(interface
, macp
);
261 SET_NETDEV_DEV(net
, &interface
->dev
);
262 //defer_kevent(macp, KEVENT_REGISTER_NET);
267 #if 1 //don't register net
268 if (register_netdev(net
) != 0)
270 printk("register_netdev fails\n");
271 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
272 usb_set_intfdata(interface
, NULL
);
282 zd1211_free_all_urbs(macp
);
285 free_netdev(net
); //kernel 2.6
292 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
298 netif_carrier_off(macp
->device
);
300 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
307 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
308 static void zd1211_disconnect(struct usb_device
*dev
, void *ptr
)
310 static void zd1211_disconnect(struct usb_interface
*interface
)
313 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
314 struct zd1205_private
*macp
= (struct zd1205_private
*) usb_get_intfdata(interface
);
316 struct zd1205_private
*macp
= (struct zd1205_private
*)ptr
;
320 printk(KERN_ERR
"unregistering non-existant device\n");
324 set_bit(ZD1211_UNPLUG
, &macp
->flags
);
325 macp
->bUSBDeveiceAttached
= 0;
327 if (macp
->driver_isolated
){
328 if (macp
->device
->flags
& IFF_UP
)
329 zd1205_close(macp
->device
);
332 unregister_netdev(macp
->device
);
334 //assuming we used keventd, it must quiesce too
335 flush_scheduled_work();
337 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
338 usb_dec_dev_use(dev
);
340 usb_put_dev(interface_to_usbdev(interface
));
344 zd1211_unlink_all_urbs(macp
);
346 zd1211_free_all_urbs(macp
);
348 zd1205_clear_structs(macp
->device
);
351 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
352 usb_set_intfdata(interface
, NULL
);
357 static struct usb_driver zd1211_driver
= {
358 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
359 //.owner = THIS_MODULE,
362 .probe
= zd1211_probe
,
363 .disconnect
= zd1211_disconnect
,
364 .id_table
= zd1211_ids
,
368 int __init
zd1211_init(void)
370 printk(KERN_NOTICE
"%s - version %s\n", DRIVER_NAME
, VERSIONID
);
371 return usb_register(&zd1211_driver
);
374 void __exit
zd1211_exit(void)
376 usb_deregister(&zd1211_driver
);
379 module_init(zd1211_init
);
380 module_exit(zd1211_exit
);