2 * Copyright (c) 2007-2008 Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 /* Module Name : zdusb.c */
20 /* This module contains plug and play handling for USB device driver*/
23 /* Platform dependent. */
25 /************************************************************************/
27 #include <linux/version.h>
29 #include <linux/modversions.h>
32 #include <linux/module.h>
33 #include <linux/usb.h>
38 int zfLnxAllocAllUrbs(struct usbdrv_private *macp);
39 void zfLnxFreeAllUrbs(struct usbdrv_private *macp);
40 void zfLnxUnlinkAllUrbs(struct usbdrv_private *macp);
42 MODULE_AUTHOR("Atheros Communications");
43 MODULE_DESCRIPTION("Atheros 802.11n Wireless LAN adapter");
44 MODULE_LICENSE("Dual BSD/GPL");
46 static const char driver_name[] = "Otus";
48 /* table of devices that work with this driver */
49 static struct usb_device_id zd1221_ids [] = {
50 { USB_DEVICE(VENDOR_ATHR, PRODUCT_AR9170) },
51 { USB_DEVICE(VENDOR_DLINK, PRODUCT_DWA160A) },
52 { USB_DEVICE(0x0846, 0x9010) },
53 { } /* Terminating entry */
56 MODULE_DEVICE_TABLE(usb, zd1221_ids);
58 extern u8_t zfLnxInitSetup(struct net_device *dev, struct usbdrv_private *macp);
59 extern int usbdrv_close(struct net_device *dev);
60 extern u8_t zfLnxClearStructs(struct net_device *dev);
61 extern int zfWdsClose(struct net_device *dev);
62 extern int zfUnregisterWdsDev(struct net_device* parentDev, u16_t wdsId);
63 extern int zfLnxVapClose(struct net_device *dev);
64 extern int zfLnxUnregisterVapDev(struct net_device* parentDev, u16_t vapId);
67 extern struct zsWdsStruct wds[ZM_WDS_PORT_NUMBER];
70 extern struct zsVapStruct vap[ZM_VAP_PORT_NUMBER];
72 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
73 static void *zfLnxProbe(struct usb_device *dev, unsigned int ifnum,
74 const struct usb_device_id *id)
76 struct usb_interface *interface = &dev->actconfig->interface[ifnum];
78 static int zfLnxProbe(struct usb_interface *interface,
79 const struct usb_device_id *id)
81 struct usb_device *dev = interface_to_usbdev(interface);
84 struct net_device *net = NULL;
85 struct usbdrv_private *macp = NULL;
86 int vendor_id, product_id;
89 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
93 vendor_id = dev->descriptor.idVendor;
94 product_id = dev->descriptor.idProduct;
97 printk(KERN_NOTICE "vendor_id = %04x\n", vendor_id);
98 printk(KERN_NOTICE "product_id = %04x\n", product_id);
100 if (dev->speed == USB_SPEED_HIGH)
101 printk(KERN_NOTICE "USB 2.0 Host\n");
103 printk(KERN_NOTICE "USB 1.1 Host\n");
106 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
107 if (usb_set_configuration(dev, dev->config[0].bConfigurationValue))
109 printk(KERN_ERR "usb_set_configuration() failed\n");
115 if (!(macp = kmalloc(sizeof(struct usbdrv_private), GFP_KERNEL)))
117 printk(KERN_ERR "out of memory allocating device structure\n");
122 /* Zero the memory */
123 memset(macp, 0, sizeof(struct usbdrv_private));
125 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
126 usb_inc_dev_use(dev);
129 net = alloc_etherdev(0);
133 printk(KERN_ERR "zfLnxProbe: Not able to alloc etherdev struct\n");
138 strcpy(net->name, "ath%d");
140 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24))
141 SET_MODULE_OWNER(net);
144 net->ml_priv = macp; //kernel 2.6
148 /* set up the endpoint information */
149 /* check out the endpoints */
150 macp->interface = interface;
152 //init_waitqueue_head(&macp->regSet_wait);
153 //init_waitqueue_head(&macp->iorwRsp_wait);
154 //init_waitqueue_head(&macp->term_wait);
156 if (!zfLnxAllocAllUrbs(macp))
162 if (!zfLnxInitSetup(net, macp))
169 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
170 usb_set_intfdata(interface, macp);
171 SET_NETDEV_DEV(net, &interface->dev);
174 if (register_netdev(net) != 0)
176 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
177 usb_set_intfdata(interface, NULL);
183 netif_carrier_off(net);
187 zfLnxFreeAllUrbs(macp);
189 free_netdev(net); //kernel 2.6
194 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
200 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
207 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
208 static void zfLnxDisconnect(struct usb_device *dev, void *ptr)
210 static void zfLnxDisconnect(struct usb_interface *interface)
213 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
214 struct usbdrv_private *macp = (struct usbdrv_private *) usb_get_intfdata(interface);
216 struct usbdrv_private *macp = (struct usbdrv_private *)ptr;
219 printk(KERN_DEBUG "zfLnxDisconnect\n");
223 printk(KERN_ERR "unregistering non-existant device\n");
227 if (macp->driver_isolated)
229 if (macp->device->flags & IFF_UP)
230 usbdrv_close(macp->device);
235 //zfWdsClose(wds[0].dev);
237 //zfUnregisterWdsDev(macp->device, 0);
240 zfLnxVapClose(vap[0].dev);
242 zfLnxUnregisterVapDev(macp->device, 0);
245 zfLnxClearStructs(macp->device);
247 unregister_netdev(macp->device);
249 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
250 usb_dec_dev_use(dev);
252 usb_put_dev(interface_to_usbdev(interface));
255 //printk(KERN_ERR "3. zfLnxUnlinkAllUrbs\n");
256 //zfLnxUnlinkAllUrbs(macp);
258 /* Free network interface */
259 free_netdev(macp->device);
261 zfLnxFreeAllUrbs(macp);
262 //zfLnxClearStructs(macp->device);
266 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
267 usb_set_intfdata(interface, NULL);
271 static struct usb_driver zd1221_driver = {
272 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
273 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15))
274 .owner = THIS_MODULE,
279 .disconnect = zfLnxDisconnect,
280 .id_table = zd1221_ids,
283 int __init zfLnxIinit(void)
285 printk(KERN_NOTICE "%s - version %s\n", DRIVER_NAME, VERSIONID);
286 return usb_register(&zd1221_driver);
289 void __exit zfLnxExit(void)
291 usb_deregister(&zd1221_driver);
294 module_init(zfLnxIinit);
295 module_exit(zfLnxExit);