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