aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/otus/zdusb.c
diff options
context:
space:
mode:
authorLuis R. Rodriguez <lrodriguez@atheros.com>2008-10-28 01:44:22 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2009-01-06 16:52:10 -0500
commit4bd43f507c7e2f225f58235226a8381fd6bbff1a (patch)
treea603a8ecc7fbb98ad06a1eda170532f301df01b3 /drivers/staging/otus/zdusb.c
parente543c241412f5f68d6948968f1a6c2cbb5fad7ff (diff)
Staging: add otus Atheros wireless network driver
Initial dump of the otus USB wireless network driver. It builds properly, but a lot of work needs to be done cleaning it up before it can be merged into the wireless driver tree. Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/otus/zdusb.c')
-rw-r--r--drivers/staging/otus/zdusb.c295
1 files changed, 295 insertions, 0 deletions
diff --git a/drivers/staging/otus/zdusb.c b/drivers/staging/otus/zdusb.c
new file mode 100644
index 00000000000..24831f71981
--- /dev/null
+++ b/drivers/staging/otus/zdusb.c
@@ -0,0 +1,295 @@
1/*
2 * Copyright (c) 2007-2008 Atheros Communications Inc.
3 *
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.
7 *
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.
15 */
16/* */
17/* Module Name : zdusb.c */
18/* */
19/* Abstract */
20/* This module contains plug and play handling for USB device driver*/
21/* */
22/* NOTES */
23/* Platform dependent. */
24/* */
25/************************************************************************/
26
27#include <linux/version.h>
28#ifdef MODVERSIONS
29#include <linux/modversions.h>
30#endif
31
32#include <linux/module.h>
33#include <linux/usb.h>
34
35#include "usbdrv.h"
36#include "zdusb.h"
37
38int zfLnxAllocAllUrbs(struct usbdrv_private *macp);
39void zfLnxFreeAllUrbs(struct usbdrv_private *macp);
40void zfLnxUnlinkAllUrbs(struct usbdrv_private *macp);
41
42MODULE_AUTHOR("Atheros Communications");
43MODULE_DESCRIPTION("Atheros 802.11n Wireless LAN adapter");
44MODULE_LICENSE("Dual BSD/GPL");
45
46static const char driver_name[] = "Otus";
47
48/* table of devices that work with this driver */
49static 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 */
54};
55
56MODULE_DEVICE_TABLE(usb, zd1221_ids);
57
58extern u8_t zfLnxInitSetup(struct net_device *dev, struct usbdrv_private *macp);
59extern int usbdrv_close(struct net_device *dev);
60extern u8_t zfLnxClearStructs(struct net_device *dev);
61extern int zfWdsClose(struct net_device *dev);
62extern int zfUnregisterWdsDev(struct net_device* parentDev, u16_t wdsId);
63extern int zfLnxVapClose(struct net_device *dev);
64extern int zfLnxUnregisterVapDev(struct net_device* parentDev, u16_t vapId);
65
66/* WDS */
67extern struct zsWdsStruct wds[ZM_WDS_PORT_NUMBER];
68
69/* VAP */
70extern struct zsVapStruct vap[ZM_VAP_PORT_NUMBER];
71
72#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
73static void *zfLnxProbe(struct usb_device *dev, unsigned int ifnum,
74 const struct usb_device_id *id)
75{
76 struct usb_interface *interface = &dev->actconfig->interface[ifnum];
77#else
78static int zfLnxProbe(struct usb_interface *interface,
79 const struct usb_device_id *id)
80{
81 struct usb_device *dev = interface_to_usbdev(interface);
82#endif
83
84 struct net_device *net = NULL;
85 struct usbdrv_private *macp = NULL;
86 int vendor_id, product_id;
87 int result = 0;
88
89#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
90 usb_get_dev(dev);
91#endif
92
93 vendor_id = dev->descriptor.idVendor;
94 product_id = dev->descriptor.idProduct;
95
96#ifdef HMAC_DEBUG
97 printk(KERN_NOTICE "vendor_id = %04x\n", vendor_id);
98 printk(KERN_NOTICE "product_id = %04x\n", product_id);
99
100 if (dev->speed == USB_SPEED_HIGH)
101 printk(KERN_NOTICE "USB 2.0 Host\n");
102 else
103 printk(KERN_NOTICE "USB 1.1 Host\n");
104#endif
105
106#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
107 if (usb_set_configuration(dev, dev->config[0].bConfigurationValue))
108 {
109 printk(KERN_ERR "usb_set_configuration() failed\n");
110 result = -EIO;
111 goto fail;
112 }
113#endif
114
115 if (!(macp = kmalloc(sizeof(struct usbdrv_private), GFP_KERNEL)))
116 {
117 printk(KERN_ERR "out of memory allocating device structure\n");
118 result = -ENOMEM;
119 goto fail;
120 }
121
122 /* Zero the memory */
123 memset(macp, 0, sizeof(struct usbdrv_private));
124
125#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
126 usb_inc_dev_use(dev);
127#endif
128
129 net = alloc_etherdev(0);
130
131 if (net == NULL)
132 {
133 printk(KERN_ERR "zfLnxProbe: Not able to alloc etherdev struct\n");
134 result = -ENOMEM;
135 goto fail1;
136 }
137
138 strcpy(net->name, "ath%d");
139
140#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24))
141 SET_MODULE_OWNER(net);
142#endif
143
144 net->priv = macp; //kernel 2.6
145 macp->udev = dev;
146 macp->device = net;
147
148 /* set up the endpoint information */
149 /* check out the endpoints */
150 macp->interface = interface;
151
152 //init_waitqueue_head(&macp->regSet_wait);
153 //init_waitqueue_head(&macp->iorwRsp_wait);
154 //init_waitqueue_head(&macp->term_wait);
155
156 if (!zfLnxAllocAllUrbs(macp))
157 {
158 result = -ENOMEM;
159 goto fail2;
160 }
161
162 if (!zfLnxInitSetup(net, macp))
163 {
164 result = -EIO;
165 goto fail3;
166 }
167 else
168 {
169#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
170 usb_set_intfdata(interface, macp);
171 SET_NETDEV_DEV(net, &interface->dev);
172#endif
173
174 if (register_netdev(net) != 0)
175 {
176#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
177 usb_set_intfdata(interface, NULL);
178#endif
179 goto fail3;
180 }
181 }
182
183 netif_carrier_off(net);
184 goto done;
185
186fail3:
187 zfLnxFreeAllUrbs(macp);
188fail2:
189 free_netdev(net); //kernel 2.6
190fail1:
191 kfree(macp);
192
193fail:
194#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
195 usb_put_dev(dev);
196#endif
197 macp = NULL;
198
199done:
200#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
201 return macp;
202#else
203 return result;
204#endif
205}
206
207#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
208static void zfLnxDisconnect(struct usb_device *dev, void *ptr)
209#else
210static void zfLnxDisconnect(struct usb_interface *interface)
211#endif
212{
213#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
214 struct usbdrv_private *macp = (struct usbdrv_private *) usb_get_intfdata(interface);
215#else
216 struct usbdrv_private *macp = (struct usbdrv_private *)ptr;
217#endif
218
219 printk(KERN_DEBUG "zfLnxDisconnect\n");
220
221 if (!macp)
222 {
223 printk(KERN_ERR "unregistering non-existant device\n");
224 return;
225 }
226
227 if (macp->driver_isolated)
228 {
229 if (macp->device->flags & IFF_UP)
230 usbdrv_close(macp->device);
231 }
232
233#if 0
234 /* Close WDS */
235 //zfWdsClose(wds[0].dev);
236 /* Unregister WDS */
237 //zfUnregisterWdsDev(macp->device, 0);
238
239 /* Close VAP */
240 zfLnxVapClose(vap[0].dev);
241 /* Unregister VAP */
242 zfLnxUnregisterVapDev(macp->device, 0);
243#endif
244
245 zfLnxClearStructs(macp->device);
246
247 unregister_netdev(macp->device);
248
249#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
250 usb_dec_dev_use(dev);
251#else
252 usb_put_dev(interface_to_usbdev(interface));
253#endif
254
255 //printk(KERN_ERR "3. zfLnxUnlinkAllUrbs\n");
256 //zfLnxUnlinkAllUrbs(macp);
257
258 /* Free network interface */
259 free_netdev(macp->device);
260
261 zfLnxFreeAllUrbs(macp);
262 //zfLnxClearStructs(macp->device);
263 kfree(macp);
264 macp = NULL;
265
266#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
267 usb_set_intfdata(interface, NULL);
268#endif
269}
270
271static 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,
275 #endif
276#endif
277 .name = driver_name,
278 .probe = zfLnxProbe,
279 .disconnect = zfLnxDisconnect,
280 .id_table = zd1221_ids,
281};
282
283int __init zfLnxIinit(void)
284{
285 printk(KERN_NOTICE "%s - version %s\n", DRIVER_NAME, VERSIONID);
286 return usb_register(&zd1221_driver);
287}
288
289void __exit zfLnxExit(void)
290{
291 usb_deregister(&zd1221_driver);
292}
293
294module_init(zfLnxIinit);
295module_exit(zfLnxExit);