alistair23-linux/drivers/staging/otus/zdusb.c

242 lines
6.5 KiB
C
Raw Normal View History

/*
* Copyright (c) 2007-2008 Atheros Communications Inc.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* */
/* Module Name : zdusb.c */
/* */
/* Abstract */
/* This module contains plug and play handling for USB device driver*/
/* */
/* NOTES */
/* Platform dependent. */
/* */
/************************************************************************/
#ifdef MODVERSIONS
#include <linux/modversions.h>
#endif
#include <linux/module.h>
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h percpu.h is included by sched.h and module.h and thus ends up being included when building most .c files. percpu.h includes slab.h which in turn includes gfp.h making everything defined by the two files universally available and complicating inclusion dependencies. percpu.h -> slab.h dependency is about to be removed. Prepare for this change by updating users of gfp and slab facilities include those headers directly instead of assuming availability. As this conversion needs to touch large number of source files, the following script is used as the basis of conversion. http://userweb.kernel.org/~tj/misc/slabh-sweep.py The script does the followings. * Scan files for gfp and slab usages and update includes such that only the necessary includes are there. ie. if only gfp is used, gfp.h, if slab is used, slab.h. * When the script inserts a new include, it looks at the include blocks and try to put the new include such that its order conforms to its surrounding. It's put in the include block which contains core kernel includes, in the same order that the rest are ordered - alphabetical, Christmas tree, rev-Xmas-tree or at the end if there doesn't seem to be any matching order. * If the script can't find a place to put a new include (mostly because the file doesn't have fitting include block), it prints out an error message indicating which .h file needs to be added to the file. The conversion was done in the following steps. 1. The initial automatic conversion of all .c files updated slightly over 4000 files, deleting around 700 includes and adding ~480 gfp.h and ~3000 slab.h inclusions. The script emitted errors for ~400 files. 2. Each error was manually checked. Some didn't need the inclusion, some needed manual addition while adding it to implementation .h or embedding .c file was more appropriate for others. This step added inclusions to around 150 files. 3. The script was run again and the output was compared to the edits from #2 to make sure no file was left behind. 4. Several build tests were done and a couple of problems were fixed. e.g. lib/decompress_*.c used malloc/free() wrappers around slab APIs requiring slab.h to be added manually. 5. The script was run on all .h files but without automatically editing them as sprinkling gfp.h and slab.h inclusions around .h files could easily lead to inclusion dependency hell. Most gfp.h inclusion directives were ignored as stuff from gfp.h was usually wildly available and often used in preprocessor macros. Each slab.h inclusion directive was examined and added manually as necessary. 6. percpu.h was updated not to include slab.h. 7. Build test were done on the following configurations and failures were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my distributed build env didn't work with gcov compiles) and a few more options had to be turned off depending on archs to make things build (like ipr on powerpc/64 which failed due to missing writeq). * x86 and x86_64 UP and SMP allmodconfig and a custom test config. * powerpc and powerpc64 SMP allmodconfig * sparc and sparc64 SMP allmodconfig * ia64 SMP allmodconfig * s390 SMP allmodconfig * alpha SMP allmodconfig * um on x86_64 SMP allmodconfig 8. percpu.h modifications were reverted so that it could be applied as a separate patch and serve as bisection point. Given the fact that I had only a couple of failures from tests on step 6, I'm fairly confident about the coverage of this conversion patch. If there is a breakage, it's likely to be something in one of the arch headers which should be easily discoverable easily on most builds of the specific arch. Signed-off-by: Tejun Heo <tj@kernel.org> Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 02:04:11 -06:00
#include <linux/slab.h>
#include <linux/usb.h>
#include "usbdrv.h"
#include "zdusb.h"
int zfLnxAllocAllUrbs(struct usbdrv_private *macp);
void zfLnxFreeAllUrbs(struct usbdrv_private *macp);
void zfLnxUnlinkAllUrbs(struct usbdrv_private *macp);
MODULE_AUTHOR("Atheros Communications");
MODULE_DESCRIPTION("Atheros 802.11n Wireless LAN adapter");
MODULE_LICENSE("Dual BSD/GPL");
static const char driver_name[] = "Otus";
/* table of devices that work with this driver */
static const struct usb_device_id zd1221_ids[] = {
{ USB_DEVICE(VENDOR_ATHR, PRODUCT_AR9170) },
{ USB_DEVICE(VENDOR_DLINK, PRODUCT_DWA160A) },
{ USB_DEVICE(VENDOR_NETGEAR, PRODUCT_WNDA3100) },
{ USB_DEVICE(VENDOR_NETGEAR, PRODUCT_WN111v2) },
{ } /* Terminating entry */
};
MODULE_DEVICE_TABLE(usb, zd1221_ids);
extern u8_t zfLnxInitSetup(struct net_device *dev, struct usbdrv_private *macp);
extern int usbdrv_close(struct net_device *dev);
extern u8_t zfLnxClearStructs(struct net_device *dev);
extern int zfWdsClose(struct net_device *dev);
extern int zfUnregisterWdsDev(struct net_device* parentDev, u16_t wdsId);
extern int zfLnxVapClose(struct net_device *dev);
extern int zfLnxUnregisterVapDev(struct net_device* parentDev, u16_t vapId);
/* WDS */
extern struct zsWdsStruct wds[ZM_WDS_PORT_NUMBER];
/* VAP */
extern struct zsVapStruct vap[ZM_VAP_PORT_NUMBER];
static int zfLnxProbe(struct usb_interface *interface,
const struct usb_device_id *id)
{
struct usb_device *dev = interface_to_usbdev(interface);
struct net_device *net = NULL;
struct usbdrv_private *macp = NULL;
int vendor_id, product_id;
int result = 0;
usb_get_dev(dev);
vendor_id = dev->descriptor.idVendor;
product_id = dev->descriptor.idProduct;
#ifdef HMAC_DEBUG
printk(KERN_NOTICE "vendor_id = %04x\n", vendor_id);
printk(KERN_NOTICE "product_id = %04x\n", product_id);
if (dev->speed == USB_SPEED_HIGH)
printk(KERN_NOTICE "USB 2.0 Host\n");
else
printk(KERN_NOTICE "USB 1.1 Host\n");
#endif
if (!(macp = kmalloc(sizeof(struct usbdrv_private), GFP_KERNEL)))
{
printk(KERN_ERR "out of memory allocating device structure\n");
result = -ENOMEM;
goto fail;
}
/* Zero the memory */
memset(macp, 0, sizeof(struct usbdrv_private));
net = alloc_etherdev(0);
if (net == NULL)
{
printk(KERN_ERR "zfLnxProbe: Not able to alloc etherdev struct\n");
result = -ENOMEM;
goto fail1;
}
strcpy(net->name, "ath%d");
net->ml_priv = macp; //kernel 2.6
macp->udev = dev;
macp->device = net;
/* set up the endpoint information */
/* check out the endpoints */
macp->interface = interface;
//init_waitqueue_head(&macp->regSet_wait);
//init_waitqueue_head(&macp->iorwRsp_wait);
//init_waitqueue_head(&macp->term_wait);
if (!zfLnxAllocAllUrbs(macp))
{
result = -ENOMEM;
goto fail2;
}
if (!zfLnxInitSetup(net, macp))
{
result = -EIO;
goto fail3;
}
else
{
usb_set_intfdata(interface, macp);
SET_NETDEV_DEV(net, &interface->dev);
if (register_netdev(net) != 0)
{
usb_set_intfdata(interface, NULL);
goto fail3;
}
}
netif_carrier_off(net);
goto done;
fail3:
zfLnxFreeAllUrbs(macp);
fail2:
free_netdev(net); //kernel 2.6
fail1:
kfree(macp);
fail:
usb_put_dev(dev);
macp = NULL;
done:
return result;
}
static void zfLnxDisconnect(struct usb_interface *interface)
{
struct usbdrv_private *macp = (struct usbdrv_private *) usb_get_intfdata(interface);
printk(KERN_DEBUG "zfLnxDisconnect\n");
if (!macp)
{
printk(KERN_ERR "unregistering non-existant device\n");
return;
}
if (macp->driver_isolated)
{
if (macp->device->flags & IFF_UP)
usbdrv_close(macp->device);
}
#if 0
/* Close WDS */
//zfWdsClose(wds[0].dev);
/* Unregister WDS */
//zfUnregisterWdsDev(macp->device, 0);
/* Close VAP */
zfLnxVapClose(vap[0].dev);
/* Unregister VAP */
zfLnxUnregisterVapDev(macp->device, 0);
#endif
zfLnxClearStructs(macp->device);
unregister_netdev(macp->device);
usb_put_dev(interface_to_usbdev(interface));
//printk(KERN_ERR "3. zfLnxUnlinkAllUrbs\n");
//zfLnxUnlinkAllUrbs(macp);
/* Free network interface */
free_netdev(macp->device);
zfLnxFreeAllUrbs(macp);
//zfLnxClearStructs(macp->device);
kfree(macp);
macp = NULL;
usb_set_intfdata(interface, NULL);
}
static struct usb_driver zd1221_driver = {
.name = driver_name,
.probe = zfLnxProbe,
.disconnect = zfLnxDisconnect,
.id_table = zd1221_ids,
};
int __init zfLnxIinit(void)
{
printk(KERN_NOTICE "%s - version %s\n", DRIVER_NAME, VERSIONID);
return usb_register(&zd1221_driver);
}
void __exit zfLnxExit(void)
{
usb_deregister(&zd1221_driver);
}
module_init(zfLnxIinit);
module_exit(zfLnxExit);