]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/staging/otus/zdusb.c
Staging: otus: Hoist assign from if
[net-next-2.6.git] / drivers / staging / otus / zdusb.c
CommitLineData
4bd43f50
LR
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
4bd43f50
LR
27#ifdef MODVERSIONS
28#include <linux/modversions.h>
29#endif
30
31#include <linux/module.h>
5a0e3ad6 32#include <linux/slab.h>
4bd43f50
LR
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 */
a457732b 49static const struct usb_device_id zd1221_ids[] = {
4bd43f50
LR
50 { USB_DEVICE(VENDOR_ATHR, PRODUCT_AR9170) },
51 { USB_DEVICE(VENDOR_DLINK, PRODUCT_DWA160A) },
5672487d
DN
52 { USB_DEVICE(VENDOR_NETGEAR, PRODUCT_WNDA3100) },
53 { USB_DEVICE(VENDOR_NETGEAR, PRODUCT_WN111v2) },
4bd43f50
LR
54 { } /* Terminating entry */
55};
56
57MODULE_DEVICE_TABLE(usb, zd1221_ids);
58
59extern u8_t zfLnxInitSetup(struct net_device *dev, struct usbdrv_private *macp);
60extern int usbdrv_close(struct net_device *dev);
61extern u8_t zfLnxClearStructs(struct net_device *dev);
62extern int zfWdsClose(struct net_device *dev);
63extern int zfUnregisterWdsDev(struct net_device* parentDev, u16_t wdsId);
64extern int zfLnxVapClose(struct net_device *dev);
65extern int zfLnxUnregisterVapDev(struct net_device* parentDev, u16_t vapId);
66
67/* WDS */
68extern struct zsWdsStruct wds[ZM_WDS_PORT_NUMBER];
69
70/* VAP */
71extern struct zsVapStruct vap[ZM_VAP_PORT_NUMBER];
72
4bd43f50
LR
73static int zfLnxProbe(struct usb_interface *interface,
74 const struct usb_device_id *id)
75{
76 struct usb_device *dev = interface_to_usbdev(interface);
4bd43f50
LR
77
78 struct net_device *net = NULL;
79 struct usbdrv_private *macp = NULL;
80 int vendor_id, product_id;
81 int result = 0;
82
4bd43f50 83 usb_get_dev(dev);
4bd43f50
LR
84
85 vendor_id = dev->descriptor.idVendor;
86 product_id = dev->descriptor.idProduct;
87
88#ifdef HMAC_DEBUG
89 printk(KERN_NOTICE "vendor_id = %04x\n", vendor_id);
90 printk(KERN_NOTICE "product_id = %04x\n", product_id);
91
92 if (dev->speed == USB_SPEED_HIGH)
93 printk(KERN_NOTICE "USB 2.0 Host\n");
94 else
95 printk(KERN_NOTICE "USB 1.1 Host\n");
96#endif
97
62fa4526
JP
98 macp = kmalloc(sizeof(struct usbdrv_private), GFP_KERNEL);
99 if (!macp)
4bd43f50
LR
100 {
101 printk(KERN_ERR "out of memory allocating device structure\n");
102 result = -ENOMEM;
103 goto fail;
104 }
105
106 /* Zero the memory */
107 memset(macp, 0, sizeof(struct usbdrv_private));
108
4bd43f50
LR
109 net = alloc_etherdev(0);
110
111 if (net == NULL)
112 {
113 printk(KERN_ERR "zfLnxProbe: Not able to alloc etherdev struct\n");
114 result = -ENOMEM;
115 goto fail1;
116 }
117
118 strcpy(net->name, "ath%d");
119
da3e8908 120 net->ml_priv = macp; //kernel 2.6
4bd43f50
LR
121 macp->udev = dev;
122 macp->device = net;
123
124 /* set up the endpoint information */
125 /* check out the endpoints */
126 macp->interface = interface;
127
128 //init_waitqueue_head(&macp->regSet_wait);
129 //init_waitqueue_head(&macp->iorwRsp_wait);
130 //init_waitqueue_head(&macp->term_wait);
131
132 if (!zfLnxAllocAllUrbs(macp))
133 {
134 result = -ENOMEM;
135 goto fail2;
136 }
137
138 if (!zfLnxInitSetup(net, macp))
139 {
140 result = -EIO;
141 goto fail3;
142 }
143 else
144 {
4bd43f50
LR
145 usb_set_intfdata(interface, macp);
146 SET_NETDEV_DEV(net, &interface->dev);
4bd43f50
LR
147
148 if (register_netdev(net) != 0)
149 {
4bd43f50 150 usb_set_intfdata(interface, NULL);
4bd43f50
LR
151 goto fail3;
152 }
153 }
154
155 netif_carrier_off(net);
156 goto done;
157
158fail3:
159 zfLnxFreeAllUrbs(macp);
160fail2:
161 free_netdev(net); //kernel 2.6
162fail1:
163 kfree(macp);
164
165fail:
4bd43f50 166 usb_put_dev(dev);
4bd43f50
LR
167 macp = NULL;
168
169done:
4bd43f50 170 return result;
4bd43f50
LR
171}
172
4bd43f50 173static void zfLnxDisconnect(struct usb_interface *interface)
4bd43f50 174{
4bd43f50 175 struct usbdrv_private *macp = (struct usbdrv_private *) usb_get_intfdata(interface);
4bd43f50
LR
176
177 printk(KERN_DEBUG "zfLnxDisconnect\n");
178
179 if (!macp)
180 {
181 printk(KERN_ERR "unregistering non-existant device\n");
182 return;
183 }
184
185 if (macp->driver_isolated)
186 {
187 if (macp->device->flags & IFF_UP)
188 usbdrv_close(macp->device);
189 }
190
191#if 0
192 /* Close WDS */
193 //zfWdsClose(wds[0].dev);
194 /* Unregister WDS */
195 //zfUnregisterWdsDev(macp->device, 0);
196
197 /* Close VAP */
198 zfLnxVapClose(vap[0].dev);
199 /* Unregister VAP */
200 zfLnxUnregisterVapDev(macp->device, 0);
201#endif
202
203 zfLnxClearStructs(macp->device);
204
205 unregister_netdev(macp->device);
206
4bd43f50 207 usb_put_dev(interface_to_usbdev(interface));
4bd43f50
LR
208
209 //printk(KERN_ERR "3. zfLnxUnlinkAllUrbs\n");
210 //zfLnxUnlinkAllUrbs(macp);
211
212 /* Free network interface */
213 free_netdev(macp->device);
214
215 zfLnxFreeAllUrbs(macp);
216 //zfLnxClearStructs(macp->device);
217 kfree(macp);
218 macp = NULL;
219
4bd43f50 220 usb_set_intfdata(interface, NULL);
4bd43f50
LR
221}
222
223static struct usb_driver zd1221_driver = {
4bd43f50
LR
224 .name = driver_name,
225 .probe = zfLnxProbe,
226 .disconnect = zfLnxDisconnect,
227 .id_table = zd1221_ids,
228};
229
230int __init zfLnxIinit(void)
231{
232 printk(KERN_NOTICE "%s - version %s\n", DRIVER_NAME, VERSIONID);
233 return usb_register(&zd1221_driver);
234}
235
236void __exit zfLnxExit(void)
237{
238 usb_deregister(&zd1221_driver);
239}
240
241module_init(zfLnxIinit);
242module_exit(zfLnxExit);