1
/* - USB main module functions
3
* --------------------------------------------------------------------
5
* Copyright (C) 2003 ACX100 Open Source Project
7
* The contents of this file are subject to the Mozilla Public
8
* License Version 1.1 (the "License"); you may not use this file
9
* except in compliance with the License. You may obtain a copy of
10
* the License at http://www.mozilla.org/MPL/
12
* Software distributed under the License is distributed on an "AS
13
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14
* implied. See the License for the specific language governing
15
* rights and limitations under the License.
17
* Alternatively, the contents of this file may be used under the
18
* terms of the GNU Public License version 2 (the "GPL"), in which
19
* case the provisions of the GPL are applicable instead of the
20
* above. If you wish to allow the use of your version of this file
21
* only under the terms of the GPL and not to allow others to use
22
* your version of this file under the MPL, indicate your decision
23
* by deleting the provisions above and replace them with the notice
24
* and other provisions required by the GPL. If you do not delete
25
* the provisions above, a recipient may use your version of this
26
* file under either the MPL or the GPL.
28
* --------------------------------------------------------------------
30
* Inquiries regarding the ACX100 Open Source Project can be
33
* acx100-users@lists.sf.net
34
* http://acx100.sf.net
36
* --------------------------------------------------------------------
37
* USB support for TI ACX100 based devices. Many parts are taken from
41
* Martin Wawro <martin.wawro AT uni-dortmund.de>
42
* Andreas Mohr <andi AT lisas.de>
45
* - Note that this driver relies on a native little-endian byteformat
51
/* -------------------------------------------------------------------------
52
** Linux Kernel Header Files
53
** ---------------------------------------------------------------------- */
56
#include <linux/version.h>
57
#include <linux/config.h>
58
#include <linux/types.h>
59
#include <linux/module.h>
60
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
61
#include <linux/moduleparam.h>
63
#include <linux/kernel.h>
64
#include <linux/usb.h>
65
#include <linux/netdevice.h>
66
#include <linux/rtnetlink.h>
67
#include <linux/etherdevice.h>
68
#include <linux/wireless.h>
69
#if WIRELESS_EXT >= 13
70
#include <net/iw_handler.h>
72
#include <linux/vmalloc.h>
73
#include <linux/interrupt.h>
74
#include <asm/uaccess.h>
75
#include <asm/byteorder.h>
77
/* -------------------------------------------------------------------------
78
** Project Header Files
79
** ---------------------------------------------------------------------- */
81
/* FIXME: integrate nicely into src/Makefile at the time it is clear which
82
* other source files from the PCI / CardBus driver have to be linked with this
83
* one and therefore _also_ need this define - until then this hack is ok */
85
#define WLAN_HOSTIF WLAN_USB
89
/* try to make it compile for both 2.4.x and 2.6.x kernels */
90
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 0)
92
/* number of endpoints of an interface */
93
#define NUM_EP(intf) (intf)->altsetting[0].desc.bNumEndpoints
94
#define EP(intf,nr) (intf)->altsetting[0].endpoint[(nr)].desc
95
#define GET_DEV(udev) usb_get_dev((udev))
96
#define PUT_DEV(udev) usb_put_dev((udev))
97
#define SET_NETDEV_OWNER(ndev,owner) /* not needed anymore ??? */
99
#define ASYNC_UNLINK URB_ASYNC_UNLINK
101
#define ZERO_PACKET URB_ZERO_PACKET
103
/* For GFP_KERNEL vs. GFP_ATOMIC, see
104
* http://groups.google.de/groups?th=6cd2e5f77e799a23&seekm=linux.scsi.OF9C38FD78.07E54601-ON87256C24.0056B509%40boulder.ibm.com
105
* Basically GFP_KERNEL waits until an alloc succeeds, while
106
* GFP_ATOMIC should be used in situations where we need to know
107
* the result immediately, since we cannot wait (in case we're within lock
109
static inline int submit_urb(struct urb *urb, int mem_flags) {
110
return usb_submit_urb(urb, mem_flags);
112
static inline struct urb *alloc_urb(int iso_pk, int mem_flags) {
113
return usb_alloc_urb(iso_pk, mem_flags);
121
#define NUM_EP(intf) (intf)->altsetting[0].bNumEndpoints
122
#define EP(intf,nr) (intf)->altsetting[0].endpoint[(nr)]
124
#define GET_DEV(udev) usb_inc_dev_use((udev))
125
#define PUT_DEV(udev) usb_dec_dev_use((udev))
127
#ifndef SET_NETDEV_DEV
128
#define SET_NETDEV_DEV(x,y)
130
#define SET_NETDEV_OWNER(ndev,owner) ndev->owner = owner
132
#define ASYNC_UNLINK USB_ASYNC_UNLINK
133
#define QUEUE_BULK USB_QUEUE_BULK
134
#define ZERO_PACKET USB_ZERO_PACKET
136
static inline int submit_urb(struct urb *urb, int mem_flags) {
137
return usb_submit_urb(urb);
139
static inline struct urb *alloc_urb(int iso_pk, int mem_flags) {
140
return usb_alloc_urb(iso_pk);
143
static inline void usb_set_intfdata(struct usb_interface *intf, void *data) {}
145
#endif /* #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 0) */
147
/* -------------------------------------------------------------------------
149
** ---------------------------------------------------------------------- */
154
/* unsigned int debug = L_DEBUG|L_ASSOC|L_INIT|L_STD; */
155
unsigned int debug = L_STD;
158
#ifdef MODULE_LICENSE
159
MODULE_LICENSE("Dual MPL/GPL");
161
MODULE_AUTHOR("Martin Wawro <martin.wawro AT uni-dortmund.de>");
162
MODULE_DESCRIPTION("TI ACX100 WLAN USB Driver");
164
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
166
module_param(debug, uint, 0);
168
module_param(firmware_dir, charp, 0);
171
MODULE_PARM(debug, "i");
173
MODULE_PARM(firmware_dir, "s");
176
MODULE_PARM_DESC(debug, "Debug level mask: 0x0000 - 0x3fff");
177
MODULE_PARM_DESC(firmware_dir, "Directory to load acx100 firmware files from");
179
/* -------------------------------------------------------------------------
180
** Module Definitions (preprocessor based)
181
** ---------------------------------------------------------------------- */
184
#define SHORTNAME "acx_usb: "
186
#define ACX100_VENDOR_ID 0x2001
187
#define ACX100_PRODUCT_ID_UNBOOTED 0x3B01
188
#define ACX100_PRODUCT_ID_BOOTED 0x3B00
190
/* RX-Timeout: NONE (request waits forever) */
191
#define ACX100_USB_RX_TIMEOUT (0)
193
#define ACX100_USB_TX_TIMEOUT (4*HZ)
196
/* -------------------------------------------------------------------------
197
** Module Data Structures
198
** ---------------------------------------------------------------------- */
203
} acx_usb_bulk_context_t;
206
/* -------------------------------------------------------------------------
208
** ---------------------------------------------------------------------- */
211
static void * acx100usb_probe(struct usb_device *, unsigned int, const struct usb_device_id *);
212
static void acx100usb_disconnect(struct usb_device *,void *);
213
static void acx100usb_complete_tx(struct urb *);
214
static void acx100usb_complete_rx(struct urb *);
216
static int acx100usb_probe(struct usb_interface *, const struct usb_device_id *);
217
static void acx100usb_disconnect(struct usb_interface *);
218
static void acx100usb_complete_tx(struct urb *, struct pt_regs *);
219
static void acx100usb_complete_rx(struct urb *, struct pt_regs *);
221
static int acx100usb_open(struct net_device *);
222
static int acx100usb_close(struct net_device *);
223
static int acx100usb_start_xmit(struct sk_buff *,struct net_device *);
224
static void acx100usb_set_rx_mode(struct net_device *);
225
static int init_network_device(struct net_device *);
226
static int acx100usb_boot(struct usb_device *);
227
void acx100usb_tx_data(wlandevice_t *,struct txdescriptor *);
228
static void acx100usb_prepare_tx(wlandevice_t *,struct txdescriptor *);
229
static void acx100usb_trigger_next_tx(wlandevice_t *);
231
static struct net_device_stats * acx_get_stats(struct net_device *);
232
static struct iw_statistics *acx_get_wireless_stats(struct net_device *);
235
static void acx100usb_poll_rx(wlandevice_t *,int number);
236
void acx_rx(struct rxhostdescriptor *,wlandevice_t *);
238
int init_module(void);
239
void cleanup_module(void);
241
#ifdef HAVE_TX_TIMEOUT
242
static void acx100usb_tx_timeout(struct net_device *);
248
static char * acx100usb_pstatus(int);
249
extern void acx_dump_bytes(void *,int);
250
static void dump_device(struct usb_device *);
251
static void dump_device_descriptor(struct usb_device_descriptor *);
253
static void dump_endpoint_descriptor(struct usb_endpoint_descriptor *);
254
static void dump_interface_descriptor(struct usb_interface_descriptor *);
256
static void dump_config_descriptor(struct usb_config_descriptor *);
257
/* static void acx100usb_printsetup(devrequest *); */
258
/* static void acx100usb_printcmdreq(struct acx100_usb_cmdreq *) __attribute__((__unused__)); */
261
/* -------------------------------------------------------------------------
263
** ---------------------------------------------------------------------- */
265
/* FIXME: static variable, big no-no!! might disrupt operation of two USB
266
* adapters at the same time! */
267
static int disconnected=0;
269
extern const struct iw_handler_def acx_ioctl_handler_def;
271
static const struct usb_device_id acx100usb_ids[] = {
272
{ USB_DEVICE(ACX100_VENDOR_ID, ACX100_PRODUCT_ID_BOOTED) },
273
{ USB_DEVICE(ACX100_VENDOR_ID, ACX100_PRODUCT_ID_UNBOOTED) },
278
/* USB driver data structure as required by the kernel's USB core */
280
static struct usb_driver acx100usb_driver = {
281
.name = "acx_usb", /* name of the driver */
282
.probe = acx100usb_probe, /* pointer to probe() procedure */
283
.disconnect = acx100usb_disconnect, /* pointer to disconnect() procedure */
284
.id_table = acx100usb_ids
288
acx_usb_bulk_context_t rxcons[ACX100_USB_NUM_BULK_URBS];
289
acx_usb_bulk_context_t txcons[ACX100_USB_NUM_BULK_URBS];
292
/* ---------------------------------------------------------------------------
293
** acx100usb_probe():
295
** dev -> Pointer to usb_device structure that may or may not be claimed
296
** ifNum -> Interface number
297
** devID -> Device ID (vendor and product specific stuff)
298
** ---------------------------------------------------------------------------
300
** (void *) Pointer to (custom) driver context or NULL if we are not interested
301
** or unable to handle the offered device.
304
** This function is invoked by the kernel's USB core whenever a new device is
305
** attached to the system or the module is loaded. It is presented a usb_device
306
** structure from which information regarding the device is obtained and evaluated.
307
** In case this driver is able to handle one of the offered devices, it returns
308
** a non-null pointer to a driver context and thereby claims the device.
309
** ------------------------------------------------------------------------ */
312
#define OUTOFMEM NULL
313
static void * acx100usb_probe(struct usb_device *usbdev,unsigned int ifNum,const struct usb_device_id *devID)
316
#define OUTOFMEM -ENOMEM
317
static int acx100usb_probe(struct usb_interface *intf, const struct usb_device_id *devID)
319
struct usb_device *usbdev = interface_to_usbdev(intf);
322
struct net_device *dev=NULL;
323
int numconfigs,numfaces,result;
324
struct usb_config_descriptor *config;
325
struct usb_endpoint_descriptor *epdesc;
326
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
327
struct usb_host_endpoint *ep;
329
struct usb_interface_descriptor *ifdesc;
338
/* ---------------------------------------------
339
** First check if this is the "unbooted" hardware
340
** --------------------------------------------- */
341
if ((usbdev->descriptor.idVendor==ACX100_VENDOR_ID)&&(usbdev->descriptor.idProduct==ACX100_PRODUCT_ID_UNBOOTED)) {
342
/* ---------------------------------------------
343
** Boot the device (i.e. upload the firmware)
344
** --------------------------------------------- */
345
acx100usb_boot(usbdev);
346
/* ---------------------------------------------
347
** OK, we are done with booting. Normally, the
348
** ID for the unbooted device should disappear
349
** and it will not need a driver anyway...so
351
** --------------------------------------------- */
352
acxlog(L_INIT, "Finished booting, returning from probe().\n");
356
res = 0; /* is that ok?? */
360
if ((usbdev->descriptor.idVendor==ACX100_VENDOR_ID)&&(usbdev->descriptor.idProduct==ACX100_PRODUCT_ID_BOOTED)) {
361
/* ---------------------------------------------
362
** allocate memory for the device driver context
363
** --------------------------------------------- */
364
priv = kmalloc(sizeof(struct wlandevice),GFP_KERNEL);
366
printk(KERN_WARNING SHORTNAME ": could not allocate %d bytes memory for device driver context, giving up.\n",sizeof(struct wlandevice));
370
memset(priv,0,sizeof(wlandevice_t));
371
priv->chip_type = CHIPTYPE_ACX100;
372
priv->radio_type = RADIO_MAXIM_0D; /* FIXME: should be read from register (via firmware) using standard ACX code */
374
/* ---------------------------------------------
375
** Initialize the device context and also check
376
** if this is really the hardware we know about.
377
** If not sure, at least notify the user that he
378
** may be in trouble...
379
** --------------------------------------------- */
380
numconfigs=(int)(usbdev->descriptor.bNumConfigurations);
381
if (numconfigs!=1) printk(KERN_WARNING SHORTNAME ": number of configurations is %d, this version of the driver only knows how to handle 1, be prepared for surprises\n",numconfigs);
383
config = usbdev->actconfig;
385
config = &usbdev->config->desc;
387
numfaces=config->bNumInterfaces;
388
if (numfaces!=1) printk(KERN_WARNING SHORTNAME "number of interfaces is %d, this version of the driver only knows how to handle 1, be prepared for surprises\n",numfaces);
389
/* --------------------------------------------
390
* ----------------------------------------- */
392
ifdesc = config->interface->altsetting;
394
ifdesc = &(intf->altsetting->desc);
396
numep = ifdesc->bNumEndpoints;
397
acxlog(L_STD,"# of endpoints: %d\n",numep);
398
/* ------------------------------------------
399
* obtain information about the endpoint
400
* addresses, begin with some default values
401
* --------------------------------------- */
404
for (i=0;i<numep;i++) {
405
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
406
ep = usbdev->ep_in[i];
410
epdesc=usb_epnum_to_ep_desc(usbdev,i);
411
if (!epdesc) continue;
413
if ((epdesc->bmAttributes)&USB_ENDPOINT_XFER_BULK) {
414
if ((epdesc->bEndpointAddress)&0x80) priv->bulkinep=(epdesc->bEndpointAddress)&0xF;
415
else priv->bulkoutep=(epdesc->bEndpointAddress)&0xF;
418
acxlog(L_STD,"bulkout ep: 0x%X\n",priv->bulkoutep);
419
acxlog(L_STD,"bulkin ep: 0x%X\n",priv->bulkinep);
420
/* --------------------------------------------
421
** Set the packet-size equivalent to the
423
** ------------------------------------------ */
424
txbufsize=sizeof(acx100_usb_txfrm_t);
425
rxbufsize=sizeof(acx100_usbin_t);
426
rxbufsize&=~0x3f; /* make it a multiply of 6ty fucking 4 ! */
428
priv->rxtruncation=0;
429
printk(KERN_INFO SHORTNAME "txbufsize=%d rxbufsize=%d\n",txbufsize,rxbufsize);
430
/* ---------------------------------------------
431
** initialize custom spinlocks...
432
** --------------------------------------------- */
433
spin_lock_init(&(priv->usb_ctrl_lock));
434
spin_lock_init(&(priv->usb_tx_lock));
436
priv->usb_free_tx=ACX100_USB_NUM_BULK_URBS;
437
for (i=0;i<ACX100_USB_NUM_BULK_URBS;i++) {
438
priv->bulktx_states[i]=0;
440
/* ---------------------------------------------
441
** Allocate memory for a network device
442
** --------------------------------------------- */
443
dev = kmalloc(sizeof(struct net_device),GFP_ATOMIC);
445
printk(KERN_WARNING SHORTNAME ": failed to alloc netdev\n");
450
/* ---------------------------------------------
451
** Setup network device
452
** --------------------------------------------- */
453
memset(dev, 0, sizeof(struct net_device));
454
dev->init=(void *)&init_network_device;
457
/* ---------------------------------------------
458
** Setup URB for control messages
459
** --------------------------------------------- */
460
priv->ctrl_urb=alloc_urb(0, GFP_KERNEL);
461
if (!priv->ctrl_urb) {
462
printk(KERN_WARNING SHORTNAME ": failed to allocate URB\n");
468
/* ---------------------------------------------
469
** Setup URBs for bulk-in messages
470
** --------------------------------------------- */
471
for (i=0;i<ACX100_USB_NUM_BULK_URBS;i++) {
472
priv->bulkrx_urbs[i]=alloc_urb(0, GFP_KERNEL);
473
if (!priv->bulkrx_urbs[i]) {
474
printk(KERN_WARNING SHORTNAME ": failed to allocate input URB\n");
475
for (j=0;j<i;j++) usb_free_urb(priv->bulkrx_urbs[j]);
476
usb_free_urb(priv->ctrl_urb);
482
priv->bulkrx_urbs[i]->status=0;
484
/* ---------------------------------------------
485
** Setup URBs for bulk-out messages
486
** --------------------------------------------- */
487
for(i=0;i<ACX100_USB_NUM_BULK_URBS;i++) {
488
priv->bulktx_urbs[i]=alloc_urb(0, GFP_KERNEL);
489
if (!priv->bulktx_urbs[i]) {
490
printk(KERN_WARNING SHORTNAME ": failed to allocate output URB\n");
491
usb_free_urb(priv->ctrl_urb);
492
for (j=0;j<i;j++) usb_free_urb(priv->bulktx_urbs[j]);
493
for (i=0;i<ACX100_USB_NUM_BULK_URBS;i++) usb_free_urb(priv->bulkrx_urbs[i]);
499
priv->bulktx_urbs[i]->status=0;
501
/* --------------------------------------
502
** Allocate a network device name
503
** -------------------------------------- */
504
acxlog(L_INIT,"allocating device name\n");
505
result=dev_alloc_name(dev,"wlan%d");
507
printk(KERN_ERR SHORTNAME ": failed to allocate wlan device name (errcode=%d), giving up.\n",result);
509
usb_free_urb(priv->ctrl_urb);
510
for (i=0;i<ACX100_USB_NUM_BULK_URBS;i++) {
511
usb_free_urb(priv->bulkrx_urbs[i]);
512
usb_free_urb(priv->bulktx_urbs[i]);
519
usb_set_intfdata(intf, priv);
520
SET_NETDEV_DEV(dev, &intf->dev);
522
/* --------------------------------------
523
** Register the network device
524
** -------------------------------------- */
525
acxlog(L_INIT,"registering network device\n");
526
result=register_netdev(dev);
528
printk(KERN_ERR SHORTNAME "failed to register network device for USB WLAN (errcode=%d), giving up.\n",result);
530
usb_free_urb(priv->ctrl_urb);
531
for (i=0;i<ACX100_USB_NUM_BULK_URBS;i++) {
532
usb_free_urb(priv->bulkrx_urbs[i]);
533
usb_free_urb(priv->bulktx_urbs[i]);
539
#ifdef CONFIG_PROC_FS
540
if (OK != acx_proc_register_entries(dev)) {
541
acxlog(L_INIT, "/proc registration failed\n");
545
/* --------------------------------------
546
** Everything went OK, we are happy now
547
** ----------------------------------- */
555
/* --------------------------------------
556
** no device we could handle, return NULL
557
** -------------------------------------- */
571
/* ---------------------------------------------------------------------------
572
** acx100usb_disconnect():
574
** dev -> Pointer to usb_device structure handled by this module
575
** devContext -> Pointer to own device context (acx100usb_context)
576
** ---------------------------------------------------------------------------
581
** This function is invoked whenever the user pulls the plug from the USB
582
** device or the module is removed from the kernel. In these cases, the
583
** network devices have to be taken down and all allocated memory has
585
** ------------------------------------------------------------------------ */
588
static void acx100usb_disconnect(struct usb_device *usbdev, void *devContext)
590
wlandevice_t *priv = (wlandevice_t *)devContext;
592
static void acx100usb_disconnect(struct usb_interface *intf)
594
wlandevice_t *priv = usb_get_intfdata(intf);
598
if (disconnected) return;
599
/* --------------------------------------
600
** No WLAN device...no sense
601
** ----------------------------------- */
604
/* -------------------------------------
605
** stop the transmit queue...
606
** ---------------------------------- */
609
if (!acx_queue_stopped(priv->netdev)) {
610
acx_stop_queue(priv->netdev,"on USB disconnect");
613
#ifdef CONFIG_PROC_FS
614
acx_proc_unregister_entries(priv->netdev);
618
/* ---------------------------------------
619
** now abort pending URBs and free them...
620
** ------------------------------------ */
621
if (priv->ctrl_urb) {
622
if (priv->ctrl_urb->status==-EINPROGRESS) usb_unlink_urb(priv->ctrl_urb);
623
while (priv->ctrl_urb->status==-EINPROGRESS) {
626
usb_free_urb(priv->ctrl_urb);
628
for (i=0;i<ACX100_USB_NUM_BULK_URBS;i++) {
629
if (priv->bulkrx_urbs[i]) {
630
if (priv->bulkrx_urbs[i]->status==-EINPROGRESS) usb_unlink_urb(priv->bulkrx_urbs[i]);
631
while (priv->bulkrx_urbs[i]->status==-EINPROGRESS) {
634
usb_free_urb(priv->bulkrx_urbs[i]);
637
for (i=0;i<ACX100_USB_NUM_BULK_URBS;i++) {
638
if (priv->bulktx_urbs[i]) {
639
if (priv->bulktx_urbs[i]->status==-EINPROGRESS) usb_unlink_urb(priv->bulktx_urbs[i]);
640
while (priv->bulktx_urbs[i]->status==-EINPROGRESS) {
643
usb_free_urb(priv->bulktx_urbs[i]);
646
/* --------------------------------------
647
** Unregister the network devices
648
** -------------------------------------- */
651
result=unregister_netdevice(priv->netdev);
655
/* --------------------------------------
656
** finally free the WLAN device...
657
** -------------------------------------- */
658
if (priv) kfree(priv);
665
/* ---------------------------------------------------------------------------
668
** usbdev -> Pointer to kernel's usb_device structure
669
** endpoint -> Address of the endpoint for control transfers
670
** ---------------------------------------------------------------------------
672
** (int) Errorcode or 0 on success
675
** This function triggers the loading of the firmware image from harddisk
676
** and then uploads the firmware to the USB device. After uploading the
677
** firmware and transmitting the checksum, the device resets and appears
678
** as a new device on the USB bus (the device we can finally deal with)
679
** ----------------------------------------------------------------------- */
681
static int acx100usb_boot(struct usb_device *usbdev)
683
unsigned int offset=8,len,inpipe,outpipe;
687
char filename[128],*firmware,*usbbuf;
689
usbbuf = kmalloc(ACX100_USB_RWMEM_MAXLEN,GFP_KERNEL);
691
printk(KERN_ERR SHORTNAME "not enough memory for allocating USB transfer buffer (req=%d bytes)\n",ACX100_USB_RWMEM_MAXLEN);
694
if ((firmware_dir)&&(strlen(firmware_dir)>114)) {
695
printk(KERN_ERR "path in firmware_dir is too long (max. 114 chars)\n");
699
if (firmware_dir) sprintf(filename,"%s/ACX100_USB.bin",firmware_dir);
700
else sprintf(filename,"/usr/share/acx/ACX100_USB.bin");
701
acxlog(L_INIT,"loading firmware %s\n",filename);
702
firmware=(char *)acx_read_fw(&usbdev->dev, filename, &size);
707
acxlog(L_INIT,"firmware size: %d bytes\n",size);
708
/* --------------------------------------
709
** Obtain the I/O pipes
710
** -------------------------------------- */
711
outpipe=usb_sndctrlpipe(usbdev,0);
712
inpipe =usb_rcvctrlpipe(usbdev,0);
713
/* --------------------------------------
714
** now upload the firmware, slice the data
716
** -------------------------------------- */
717
while (offset<size) {
718
if ((size-offset)>=(ACX100_USB_RWMEM_MAXLEN)) len=ACX100_USB_RWMEM_MAXLEN;
719
else len=size-offset;
720
acxlog(L_INIT,"uploading firmware (%d bytes, offset=%d)\n",len,offset);
722
memcpy(usbbuf,firmware+offset,len);
723
result=usb_control_msg(usbdev,outpipe,ACX100_USB_UPLOAD_FW,USB_TYPE_VENDOR|USB_DIR_OUT,(u16)(size-8),0,usbbuf,len,3000);
727
printk(KERN_ERR SHORTNAME "error %d (%s) during upload of firmware, aborting\n",result,acx100usb_pstatus(result));
729
printk(KERN_ERR SHORTNAME "error %d during upload of firmware, aborting\n", result);
736
/* --------------------------------------
737
** finally, send the checksum and reboot
739
** -------------------------------------- */
740
csptr=(u16 *)firmware;
741
result=usb_control_msg(usbdev,outpipe,ACX100_USB_UPLOAD_FW,USB_TYPE_VENDOR|USB_DIR_OUT,csptr[0],csptr[1],NULL,0,3000); /* this triggers the reboot ? */
743
printk(KERN_ERR SHORTNAME "error %d during tx of checksum, aborting\n",result);
748
result=usb_control_msg(usbdev,inpipe,ACX100_USB_ACK_CS,USB_TYPE_VENDOR|USB_DIR_IN,csptr[0],csptr[1],usbbuf,8,3000);
750
printk(KERN_ERR SHORTNAME "error %d during ACK of checksum, aborting\n",result);
756
if (((u16 *)usbbuf)[0]!=0x10) {
758
printk(KERN_ERR SHORTNAME "invalid checksum?\n");
768
/* ---------------------------------------------------------------------------
769
** init_network_device():
771
** dev -> Pointer to network device
772
** ---------------------------------------------------------------------------
777
** Basic setup of a network device for use with the WLAN device.
778
** ------------------------------------------------------------------------- */
780
static int init_network_device(struct net_device *dev) {
783
/* --------------------------------------
784
** Setup the device and stop the queue
785
** -------------------------------------- */
787
acx_stop_queue(dev, "on init");
788
/* --------------------------------------
789
** put the ACX100 out of sleep mode
790
** ----------------------------------- */
792
acx_issue_cmd(priv,ACX1xx_CMD_WAKE,NULL,0,ACX_CMD_TIMEOUT_DEFAULT);
793
/* --------------------------------------
794
** Register the callbacks for the network
796
** -------------------------------------- */
797
dev->open = &acx100usb_open;
798
dev->stop = &acx100usb_close;
799
dev->hard_start_xmit = (void *)&acx100usb_start_xmit;
800
dev->get_stats = (void *)&acx_get_stats;
801
dev->get_wireless_stats = (void *)&acx_get_wireless_stats;
802
#if WIRELESS_EXT >= 13
803
dev->wireless_handlers = (struct iw_handler_def *)&acx_ioctl_handler_def;
805
dev->do_ioctl = (void *)&acx_ioctl_old;
807
dev->set_multicast_list = (void *)&acx100usb_set_rx_mode;
808
#ifdef HAVE_TX_TIMEOUT
809
dev->tx_timeout = &acx100usb_tx_timeout;
810
dev->watchdog_timeo = 4 * HZ; /* 400 */
812
result=acx_init_mac(dev, 1);
814
SET_MODULE_OWNER(dev);
823
/* --------------------------------------------------------------------------
826
** dev -> Pointer to network device
827
** --------------------------------------------------------------------------
832
** This function is called when the user sets up the network interface.
833
** It initializes a management timer, sets up the USB card and starts
834
** the network tx queue and USB receive.
835
** ---------------------------------------------------------------------- */
837
static int acx100usb_open(struct net_device *dev)
839
wlandevice_t *priv = (wlandevice_t *)dev->priv;
844
/* ---------------------------------
845
** put the ACX100 out of sleep mode
846
** ------------------------------ */
847
acx_issue_cmd(priv,ACX1xx_CMD_WAKE,NULL,0,ACX_CMD_TIMEOUT_DEFAULT);
849
acx_init_task_scheduler(priv);
851
init_timer(&(priv->mgmt_timer));
852
priv->mgmt_timer.function=acx_timer;
853
priv->mgmt_timer.data=(unsigned long)priv;
855
/* set ifup to 1, since acx_start needs it (FIXME: ugly) */
857
SET_BIT(priv->dev_state_mask, ACX_STATE_IFACE_UP);
861
acx_start_queue(dev, "on open");
862
for (i=0;i<ACX100_USB_NUM_BULK_URBS;i++) {
863
acx100usb_poll_rx(priv,i);
866
WLAN_MOD_INC_USE_COUNT;
873
/* ---------------------------------------------------------------------------
876
** dev -> Pointer to network device
877
** ---------------------------------------------------------------------------
882
** This function is invoked when a packet has been received by the USB
883
** part of the code. It converts the rxdescriptor to an ethernet frame and
884
** then commits the data to the network stack.
885
** ------------------------------------------------------------------------ */
887
void acx_rx(struct rxhostdescriptor *rxdesc, wlandevice_t *priv)
889
netdevice_t *dev = priv->netdev;
893
if (priv->dev_state_mask & ACX_STATE_IFACE_UP) {
894
skb = acx_rxdesc_to_ether(priv, rxdesc);
897
dev->last_rx = jiffies;
898
priv->stats.rx_packets++;
899
priv->stats.rx_bytes += skb->len;
907
/* ---------------------------------------------------------------------------
908
** acx100usb_poll_rx():
910
** priv -> Pointer to wlandevice structure
911
** ---------------------------------------------------------------------------
916
** This function initiates a bulk-in USB transfer (in case the interface
918
** ------------------------------------------------------------------------- */
920
static void acx100usb_poll_rx(wlandevice_t *priv,int number) {
921
acx100_usbin_t *inbuf;
922
struct usb_device *usbdev;
927
if (priv->dev_state_mask & ACX_STATE_IFACE_UP) {
928
inbuf=&(priv->bulkins[number]);
930
rxcons[number].device=priv;
931
rxcons[number].number=number;
932
inpipe=usb_rcvbulkpipe(usbdev,priv->bulkinep);
933
if (priv->bulkrx_urbs[number]->status==-EINPROGRESS) {
934
printk(KERN_ERR SHORTNAME "error, rx triggered while rx urb in progress\n");
935
/* FIXME: this is nasty, receive is being cancelled by this code
936
* on the other hand, this should not happen anyway...
938
usb_unlink_urb(priv->bulkrx_urbs[number]);
940
priv->bulkrx_urbs[number]->actual_length=0;
941
usb_fill_bulk_urb(priv->bulkrx_urbs[number], usbdev, inpipe, inbuf, rxbufsize, acx100usb_complete_rx, &(rxcons[number]));
942
priv->bulkrx_urbs[number]->transfer_flags=ASYNC_UNLINK|QUEUE_BULK;
944
priv->bulkrx_urbs[number]->timeout=0;
945
priv->bulkrx_urbs[number]->status=0;
947
errcode=submit_urb(priv->bulkrx_urbs[number], GFP_KERNEL);
948
/* FIXME: evaluate the error code ! */
949
acxlog(L_USBRXTX,"SUBMIT RX (%d) inpipe=0x%X size=%d errcode=%d\n",number,inpipe,rxbufsize,errcode);
957
/* ---------------------------------------------------------------------------
958
** acx100usb_complete_rx():
960
** urb -> Pointer to USB request block
961
** regs -> Pointer to register-buffer for syscalls (see asm/ptrace.h)
962
** ---------------------------------------------------------------------------
967
** This function is invoked whenever a bulk receive request returns. The
968
** received data is then committed to the network stack and the next
969
** USB receive is triggered.
970
** ------------------------------------------------------------------------- */
973
static void acx100usb_complete_rx(struct urb *urb)
975
static void acx100usb_complete_rx(struct urb *urb, struct pt_regs *regs)
979
int offset,size,number,remsize,packetsize;
981
struct rxhostdescriptor *rxdesc;
982
TIWLAN_DC *ticontext;
983
acx_usb_bulk_context_t *context;
987
printk(KERN_ERR SHORTNAME "error, urb context was NULL\n");
988
return; /* at least try to prevent the worst */
990
context=(acx_usb_bulk_context_t *)(urb->context);
991
priv=context->device;
992
number=context->number;
993
/* ----------------------------
994
** grab the TI device context
995
** -------------------------- */
996
ticontext=&(priv->dc);
997
size=urb->actual_length;
998
/* ---------------------------------------------
999
** check if the transfer was aborted...
1000
** ------------------------------------------ */
1001
acxlog(L_USBRXTX,"RETURN RX (%d) status=%d size=%d\n",number,urb->status,size);
1002
if (urb->status!=0) {
1003
switch (urb->status) {
1007
printk(KERN_ERR SHORTNAME "error in rx, data overrun -> emergency stop\n");
1008
acx100usb_close(priv->netdev);
1011
priv->stats.rx_errors++;
1012
printk(KERN_WARNING SHORTNAME "rx error (urb status=%d)\n",urb->status);
1014
if (priv->dev_state_mask & ACX_STATE_IFACE_UP) acx100usb_poll_rx(priv,number);
1017
/* ---------------------------------------------
1018
** work the receive buffer...
1019
** --------------------------------------------- */
1020
if (size==0) acxlog(L_STD,"warning, encountered zerolength rx packet\n");
1021
if ((size>0)&&(urb->transfer_buffer==&(priv->bulkins[number]))) {
1022
/* ------------------------------------------------------------------
1023
** now fill the data into the rxhostdescriptor for further processing
1024
** ---------------------------------------------------------------- */
1025
if (!(ticontext->pRxHostDescQPool)) {
1026
printk(KERN_ERR SHORTNAME "error, rxhostdescriptor pool is NULL\n");
1027
return; /* bail out before something bad happens */
1029
ptr=(rxbuffer_t *)&(priv->bulkins[number]);
1032
/* -------------------------------------------
1033
* check if previous frame was truncated...
1034
* FIXME: this code can only handle truncation
1035
* into TWO parts, NOT MORE !
1036
* ---------------------------------------- */
1037
if (priv->rxtruncation) {
1038
ptr=(rxbuffer_t *)&(priv->rxtruncbuf);
1039
packetsize=MAC_CNT_RCVD(ptr)+ACX100_RXBUF_HDRSIZE;
1040
rxdesc=&(ticontext->pRxHostDescQPool[ticontext->rx_tail]);
1041
SET_BIT(rxdesc->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
1042
rxdesc->Status=cpu_to_le32(0xF0000000); /* set the MSB, FIXME: shouldn't that be MSBit instead??? (BIT31) */
1043
acxlog(L_USBRXTX,"handling truncated frame (truncsize=%d usbsize=%d packetsize(from trunc)=%d)\n",priv->rxtruncsize,size,packetsize);
1045
if (debug&L_USBRXTX) acx_dump_bytes(ptr,12);
1046
if (debug&L_USBRXTX) acx_dump_bytes(&(priv->bulkins[number]),12);
1048
if (size<(packetsize-priv->rxtruncsize)) {
1049
/* -------------------------------------------------
1050
* there is not enough data to complete this packet
1051
* simply append the stuff to the truncation buffer
1052
* ----------------------------------------------- */
1053
memcpy(((char *)ptr)+priv->rxtruncsize,&(priv->bulkins[number]),size);
1054
priv->rxtruncsize+=size;
1058
/* ------------------------------------------
1059
* ok, this data completes the previously
1060
* truncated packet. copy it into a descriptor
1061
* and give it to the rest of the stack...
1062
* ----------------------------------------- */
1063
memcpy(rxdesc->data,ptr,priv->rxtruncsize); /* first copy the previously truncated part */
1064
ptr=(rxbuffer_t *)&(priv->bulkins[number]);
1065
memcpy(((char *)(rxdesc->data))+priv->rxtruncsize,(char *)ptr,packetsize-priv->rxtruncsize);
1067
acxlog(L_USBRXTX,"full trailing packet + 12 bytes:\n");
1068
if (debug&L_USBRXTX) acx_dump_bytes(ptr,(packetsize-priv->rxtruncsize)+ACX100_RXBUF_HDRSIZE);
1070
priv->rxtruncation=0;
1071
offset=(packetsize-priv->rxtruncsize);
1072
ptr=(rxbuffer_t *)(((char *)ptr)+offset);
1074
acx_process_rx_desc(priv);
1076
acxlog(L_USBRXTX,"post-merge offset: %d usbsize: %d remsize=%d\n",offset,size,remsize);
1078
while (offset<size) {
1079
packetsize=MAC_CNT_RCVD(ptr)+ACX100_RXBUF_HDRSIZE;
1080
acxlog(L_USBRXTX,"packet with packetsize=%d\n",packetsize);
1081
if (packetsize>sizeof(rxbuffer_t)) {
1082
printk(KERN_ERR "packetsize exceeded (got %d , max %d, usbsize=%d)\n",packetsize,sizeof(rxbuffer_t),size);
1083
/* FIXME: put some real error-handling in here ! */
1085
/* --------------------------------
1086
* skip zero-length packets...
1087
* ----------------------------- */
1088
if (packetsize==0) {
1089
offset+=ACX100_RXBUF_HDRSIZE;
1090
remsize-=ACX100_RXBUF_HDRSIZE;
1091
acxlog(L_USBRXTX,"packetsize=0, new offs=%d new rem=%d header follows:\n",offset,remsize);
1093
if (debug&L_USBRXTX) acx_dump_bytes(ptr,12);
1095
ptr=(rxbuffer_t *)(((char *)ptr)+ACX100_RXBUF_HDRSIZE);
1098
/* -------------------------------
1099
* if packet has no information,
1101
* ---------------------------- */
1102
if (remsize<=ACX100_RXBUF_HDRSIZE) {
1104
if (packetsize>remsize) {
1105
/* -----------------------------------
1106
* frame truncation handling...
1107
* --------------------------------- */
1108
acxlog(L_USBRXTX,"need to truncate this packet , packetsize=%d remain=%d offset=%d usbsize=%d\n",packetsize,remsize,offset,size);
1110
if (debug&L_USBRXTX) acx_dump_bytes(ptr,12);
1112
priv->rxtruncation=1;
1113
memcpy(&(priv->rxtruncbuf),ptr,remsize);
1114
priv->rxtruncsize=remsize;
1117
rxdesc=&(ticontext->pRxHostDescQPool[ticontext->rx_tail]);
1118
SET_BIT(rxdesc->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
1119
rxdesc->Status=cpu_to_le32(0xF0000000); /* set the MSB, FIXME: shouldn't that be MSBit instead??? (BIT31) */
1120
memcpy(rxdesc->data,ptr,packetsize);
1121
/* ---------------------------------------------
1122
** now handle the received data....
1123
** ------------------------------------------ */
1124
acx_process_rx_desc(priv);
1125
ptr=(rxbuffer_t *)(((char *)ptr)+packetsize);
1127
remsize-=packetsize;
1129
if ((remsize)&&(debug&L_USBRXTX)) {
1130
acxlog(L_USBRXTX,"more than one packet in buffer, second packet hdr follows\n");
1131
if (debug&L_USBRXTX) acx_dump_bytes(ptr,12);
1137
/* -------------------------------
1138
** look for the next rx ...
1139
** ---------------------------- */
1140
if (priv->dev_state_mask & ACX_STATE_IFACE_UP) acx100usb_poll_rx(priv,number); /* receive of frame completed, now look for the next one */
1147
/* ---------------------------------------------------------------------------
1148
** acx100usb_tx_data():
1150
** priv -> Pointer to wlandevice structure
1151
** desc -> Pointer to TX descriptor
1152
** ---------------------------------------------------------------------------
1157
** This function is called by acx_dma_tx_data() and is responsible for
1158
** sending out the data within the given txdescriptor to the USB device.
1159
** In order to avoid inconsistency on SMP systems, a Mutex is checked
1160
** that forbids other packets to disturb the USB queue when there is
1161
** more than 1 packet within the Tx queue at a time. In case there is
1162
** a transfer in progress, this function immediately returns. It is
1163
** within the responsibility of the acx100usb_complete_tx() function to
1164
** ensure that these transfers are completed after the current transfer
1165
** was finished. In case there are no transfers in progress, the Mutex
1166
** is set and the transfer is triggered.
1167
** ------------------------------------------------------------------------- */
1169
void acx100usb_tx_data(wlandevice_t *priv,struct txdescriptor *desc)
1172
/* ------------------------------------
1173
** some sanity checks...
1174
** --------------------------------- */
1175
if ((!priv)||(!desc)) return;
1176
/*-----------------------------------------------
1177
** check if there are free buffers to use...
1178
** ------------------------------------------- */
1179
if (!(priv->usb_free_tx)) return;
1180
/*-----------------------------------------------
1181
** transmit the frame...
1182
** ------------------------------------------- */
1183
acx100usb_prepare_tx(priv,desc);
1189
/* ---------------------------------------------------------------------------
1190
** acx100usb_prepare_tx():
1192
** priv -> Pointer to wlandevice structure
1193
** desc -> Pointer to TX descriptor
1194
** ---------------------------------------------------------------------------
1199
** This function inserts the given txdescriptor into the USB output buffer
1200
** and initiates the USB data transfer of the packet.
1201
** ------------------------------------------------------------------------- */
1203
static void acx100usb_prepare_tx(wlandevice_t *priv,struct txdescriptor *desc) {
1204
int bufindex,txsize,ucode,size;
1205
unsigned long flags;
1206
acx100_usb_txfrm_t *buf;
1208
struct usb_device *usbdev;
1209
unsigned int outpipe;
1210
struct txhostdescriptor *header,*payload;
1211
TIWLAN_DC *ticontext;
1214
priv->currentdesc = desc;
1215
ticontext=&(priv->dc);
1216
/* ------------------------------------------
1217
** extract header and payload from descriptor
1218
** --------------------------------------- */
1219
header = desc->fixed_size.s.host_desc;
1220
payload = desc->fixed_size.s.host_desc+1;
1221
/* ---------------------------------------------
1222
** look for a free tx buffer.....
1223
** ------------------------------------------ */
1224
spin_lock_irqsave(&(priv->usb_tx_lock),flags);
1225
for (bufindex=0;bufindex<ACX100_USB_NUM_BULK_URBS;bufindex++) {
1226
if (priv->bulktx_states[bufindex]==0) break;
1228
if (bufindex>=ACX100_USB_NUM_BULK_URBS) {
1229
printk(KERN_WARNING SHORTNAME "tx buffers full\n");
1230
spin_unlock_irqrestore(&(priv->usb_tx_lock),flags);
1233
priv->bulktx_states[bufindex]=1;
1234
priv->usb_free_tx--;
1235
acxlog(L_DEBUG,"using buf #%d (free=%d) len=%d\n",bufindex,priv->usb_free_tx,le16_to_cpu(header->length)+le16_to_cpu(payload->length));
1236
/* ----------------------------------------------
1237
** concatenate header and payload into USB buffer
1238
** ------------------------------------------- */
1239
acxlog(L_XFER,"tx_data: headerlen=%d payloadlen=%d\n",le16_to_cpu(header->length),le16_to_cpu(payload->length));
1240
buf=&(priv->bulkouts[bufindex].txfrm);
1241
size=le16_to_cpu(header->length) + le16_to_cpu(payload->length);
1242
if (size>txbufsize) {
1243
printk(KERN_WARNING SHORTNAME "error, USB buffer smaller than total data to send (%d vs. %d) -> frame dropped\n",size,txbufsize);
1244
priv->bulktx_states[bufindex]=0;
1245
priv->usb_free_tx++;
1246
spin_unlock_irqrestore(&(priv->usb_tx_lock),flags);
1249
memcpy(&(buf->data),header->data,le16_to_cpu(header->length));
1250
memcpy(((char *)&(buf->data))+le16_to_cpu(header->length),payload->data,le16_to_cpu(payload->length));
1251
/* ----------------------------------------------
1252
** fill the USB transfer header
1253
** ------------------------------------------- */
1254
buf->hdr.desc=cpu_to_le16(ACX100_USB_TX_DESC);
1255
buf->hdr.MPDUlen=cpu_to_le16(size);
1258
buf->hdr.hostData=cpu_to_le32(size|(desc->u.r1.rate)<<24);
1259
if (1 == priv->defpeer.shortpre) /* vda: TODO: when to use ap_peer? */
1260
SET_BIT(buf->hdr.ctrl1, DESC_CTL_SHORT_PREAMBLE);
1261
SET_BIT(buf->hdr.ctrl1, DESC_CTL_FIRSTFRAG);
1262
buf->hdr.txRate=desc->u.r1.rate;
1264
buf->hdr.dataLength=cpu_to_le16(size|((buf->hdr.txRate)<<24));
1265
if (WLAN_GET_FC_FTYPE(ieee2host16(((p80211_hdr_t *)header->data)->a3.fc))==WLAN_FTYPE_DATA) {
1266
SET_BIT(buf->hdr.hostData, (ACX100_USB_TXHI_ISDATA<<16));
1268
addr=(((p80211_hdr_t *)(header->data))->a3.a3);
1269
if (mac_is_directed(addr))
1270
SET_BIT(buf->hdr.hostData, cpu_to_le32((ACX100_USB_TXHI_DIRECTED<<16)));
1271
if (mac_is_bcast(addr))
1272
SET_BIT(buf->hdr.hostData, cpu_to_le32((ACX100_USB_TXHI_BROADCAST<<16)));
1273
acxlog(L_DATA,"Dump of bulk out urb:\n");
1274
if (debug&L_DATA) acx_dump_bytes(buf,size+sizeof(acx100_usb_txhdr_t));
1277
if (priv->bulktx_urbs[bufindex]->status==-EINPROGRESS) {
1278
printk(KERN_WARNING SHORTNAME "trying to subma a tx urb while already in progress\n");
1281
priv->usb_txsize=size+sizeof(acx100_usb_txhdr_t);
1282
priv->usb_txoffset=priv->usb_txsize;
1283
txsize=priv->usb_txsize;
1284
/* ---------------------------------------------
1285
** now schedule the USB transfer...
1286
** ------------------------------------------ */
1287
usbdev=priv->usbdev;
1288
outpipe=usb_sndbulkpipe(usbdev,priv->bulkoutep);
1289
txcons[bufindex].device=priv;
1290
txcons[bufindex].number=bufindex;
1291
usb_fill_bulk_urb(priv->bulktx_urbs[bufindex],usbdev,outpipe,buf,txsize,(usb_complete_t)acx100usb_complete_tx,&(txcons[bufindex]));
1292
priv->bulktx_urbs[bufindex]->transfer_flags=ASYNC_UNLINK|QUEUE_BULK|ZERO_PACKET;
1294
priv->bulktx_urbs[bufindex]->status=0;
1295
priv->bulktx_urbs[bufindex]->timeout=ACX100_USB_TX_TIMEOUT;
1297
ucode=submit_urb(priv->bulktx_urbs[bufindex], GFP_KERNEL);
1298
acxlog(L_USBRXTX,"SUBMIT TX (%d): outpipe=0x%X buf=%p txsize=%d errcode=%d\n",bufindex,outpipe,buf,txsize,ucode);
1300
printk(KERN_ERR SHORTNAME "submit_urb() return code: %d (%s:%d) txsize=%d\n",ucode,__FILE__,__LINE__,txsize);
1301
/* -------------------------------------------------
1302
** on error, just mark the frame as done and update
1303
** the statistics...
1304
** ---------------------------------------------- */
1305
priv->stats.tx_errors++;
1306
priv->bulktx_states[bufindex]=0;
1307
priv->usb_free_tx++;
1308
spin_unlock_irqrestore(&(priv->usb_tx_lock),flags);
1309
acx100usb_trigger_next_tx(priv);
1312
spin_unlock_irqrestore(&(priv->usb_tx_lock),flags);
1321
/* ---------------------------------------------------------------------------
1322
** acx100usb_complete_tx():
1324
** urb -> Pointer to USB request block
1325
** regs -> Pointer to register-buffer for syscalls (see asm/ptrace.h)
1326
** ---------------------------------------------------------------------------
1331
** This function is invoked upon termination of a USB transfer. As the
1332
** USB device is only capable of sending a limited amount of bytes per
1333
** transfer to the bulk-out endpoint, this routine checks if there are
1334
** more bytes to send and triggers subsequent transfers. In case the
1335
** transfer size exactly matches the maximum bulk-out size, it triggers
1336
** a transfer of a null-frame, telling the card that this is it. Upon
1337
** completion of a frame, it checks whether the Tx ringbuffer contains
1338
** more data to send and invokes the Tx routines if this is the case.
1339
** If there are no more occupied Tx descriptors, the Tx Mutex is unlocked
1340
** and the network queue is switched back to life again.
1341
** ------------------------------------------------------------------------- */
1344
static void acx100usb_complete_tx(struct urb *urb)
1346
static void acx100usb_complete_tx(struct urb *urb, struct pt_regs *regs)
1350
acx_usb_bulk_context_t *context;
1352
unsigned long flags;
1356
context=(acx_usb_bulk_context_t *)(urb->context);
1358
printk(KERN_ERR SHORTNAME "error, enountered NULL context in tx completion callback\n");
1359
/* FIXME: real error-handling code must go here ! */
1362
priv=context->device;
1363
index=context->number;
1364
acxlog(L_USBRXTX,"RETURN TX (%d): status=%d size=%d\n",index,urb->status,urb->actual_length);
1365
/* ------------------------------
1366
** handle USB transfer errors...
1367
** --------------------------- */
1368
if (urb->status!=0) {
1369
switch (urb->status) {
1373
printk(KERN_ERR SHORTNAME "tx error, urb status=%d\n",urb->status);
1375
/* FIXME: real error-handling code here please */
1377
/* ---------------------------------------------
1378
** free the URB and check for more data...
1379
** --------------------------------------------- */
1380
spin_lock_irqsave(&(priv->usb_tx_lock),flags);
1381
priv->usb_free_tx++;
1382
priv->bulktx_states[index]=0;
1383
spin_unlock_irqrestore(&(priv->usb_tx_lock),flags);
1384
if (priv->dev_state_mask&ACX_STATE_IFACE_UP) acx100usb_trigger_next_tx(priv);
1389
/* ---------------------------------------------------------------------------
1390
** acx100usb_trigger_next_tx():
1392
** priv -> Pointer to WLAN device structure
1393
** ---------------------------------------------------------------------------
1398
** This function is invoked when the transfer of the current txdescriptor
1399
** to send is completed OR if there went something wrong during the transfer
1400
** of the descriptor. In either case, this function checks if there are more
1401
** descriptors to send and handles the descriptors over to the
1402
** acx100usb_prepare_tx() function. If there are no more descriptors to send,
1403
** the transfer-in-progress Mutex is released and the network tx queue is
1404
** kicked back to life.
1405
** ------------------------------------------------------------------------ */
1407
static void acx100usb_trigger_next_tx(wlandevice_t *priv) {
1408
struct txdescriptor *txdesc;
1409
struct txhostdescriptor *header,*payload;
1411
struct TIWLAN_DC *ticontext;
1412
/* ----------------------------
1413
** grab the TI device context
1414
** -------------------------- */
1415
ticontext=&(priv->dc);
1416
/* ----------------------------------------------
1417
** free the txdescriptor...
1418
** ------------------------------------------- */
1419
txdesc=priv->currentdesc;
1420
header = txdesc->fixed_size.s.host_desc;
1421
payload = txdesc->fixed_size.s.host_desc+1;
1422
SET_BIT(header->Ctl_16, cpu_to_le16(DESC_CTL_DONE));
1423
SET_BIT(payload->Ctl_16, cpu_to_le16(DESC_CTL_DONE));
1424
SET_BIT(txdesc->Ctl_8, DESC_CTL_DONE);
1425
acx_clean_tx_desc(priv);
1426
/* ----------------------------------------------
1427
** check if there are still descriptors that have
1428
** to be sent. acx_clean_tx_desc() should
1429
** have set the next non-free descriptor position
1431
** ------------------------------------------- */
1432
descnum=ticontext->tx_tail;
1433
txdesc=&(ticontext->pTxDescQPool[descnum]);
1434
if (!(txdesc->Ctl_8 & DESC_CTL_HOSTOWN)) {
1435
acx100usb_prepare_tx(priv,txdesc);
1437
/* ----------------------------------------------
1438
** now wake the output queue...
1439
** ------------------------------------------- */
1440
if (priv->dev_state_mask&ACX_STATE_IFACE_UP) acx_wake_queue(priv->netdev, "for next Tx");
1445
/* ---------------------------------------------------------------------------
1446
** acx100usb_close():
1448
** dev -> Pointer to network device structure
1449
** ---------------------------------------------------------------------------
1451
** (int) 0 on success, or error-code
1454
** This function stops the network functionality of the interface (invoked
1455
** when the user calls ifconfig <wlan> down). The tx queue is halted and
1456
** the device is marked as down. In case there were any pending USB bulk
1457
** transfers, these are unlinked (asynchronously). The module in-use count
1458
** is also decreased in this function.
1459
** ------------------------------------------------------------------------- */
1461
static int acx100usb_close(struct net_device *dev)
1467
printk(KERN_ERR SHORTNAME "dev->priv empty, FAILED.\n");
1472
/* ------------------------------
1473
** Transmit a disassociate frame
1474
** --------------------------- */
1475
acx_transmit_disassoc(&client,priv);
1476
/* --------------------------------
1477
* stop the transmit queue...
1478
* ------------------------------ */
1479
if (!acx_queue_stopped(dev)) {
1480
acx_stop_queue(dev, "on iface stop");
1482
acx_flush_task_scheduler();
1483
/* --------------------------------
1484
** mark the device as DOWN
1485
** ----------------------------- */
1486
if (priv->dev_state_mask&ACX_STATE_IFACE_UP) {
1488
CLEAR_BIT(priv->dev_state_mask, ACX_STATE_IFACE_UP);
1491
/* --------------------------------------
1492
* wait until all tx are out...
1493
* ----------------------------------- */
1494
for (i=0;i<ACX100_USB_NUM_BULK_URBS;i++) {
1495
while (priv->bulktx_urbs[i]->status==-EINPROGRESS) {
1499
/* ----------------------------------------
1500
* interrupt pending bulk rx transfers ....
1501
* ------------------------------------- */
1502
for (i=0;i<ACX100_USB_NUM_BULK_URBS;i++) {
1503
if (priv->bulkrx_urbs[i]->status==-EINPROGRESS) usb_unlink_urb(priv->bulkrx_urbs[i]);
1504
while (priv->bulkrx_urbs[i]->status==-EINPROGRESS) {
1508
/* ----------------------------------------------------
1509
* stop any pending tx URBs...
1510
* ------------------------------------------------- */
1511
for (i=0;i<ACX100_USB_NUM_BULK_URBS;i++) {
1512
if (priv->bulktx_urbs[i]->status==-EINPROGRESS) usb_unlink_urb(priv->bulktx_urbs[i]);
1513
while (priv->bulktx_urbs[i]->status==-EINPROGRESS) {
1517
/* ------------------------
1518
** disable rx and tx ...
1519
** --------------------- */
1520
acx_issue_cmd(priv,ACX1xx_CMD_DISABLE_TX,NULL,0,ACX_CMD_TIMEOUT_DEFAULT);
1521
acx_issue_cmd(priv,ACX1xx_CMD_DISABLE_RX,NULL,0,ACX_CMD_TIMEOUT_DEFAULT);
1522
/* -------------------------
1523
** power down the device...
1524
** ---------------------- */
1525
acx_issue_cmd(priv,ACX1xx_CMD_SLEEP,NULL,0,ACX_CMD_TIMEOUT_DEFAULT);
1526
/* --------------------------------------------
1527
** decrease module-in-use count (if necessary)
1528
** ----------------------------------------- */
1529
if (!already_down) WLAN_MOD_DEC_USE_COUNT;
1536
/* ---------------------------------------------------------------------------
1537
** acx100usb_start_xmit():
1539
** skb -> Pointer to sk_buffer that contains the data to send
1540
** dev -> Pointer to the network device this transfer is directed to
1541
** ---------------------------------------------------------------------------
1543
** (int) 0 on success, or error-code
1546
** ------------------------------------------------------------------------- */
1548
static int acx100usb_start_xmit(struct sk_buff *skb, netdevice_t * dev) {
1550
unsigned long flags;
1551
wlandevice_t *priv = (wlandevice_t *) dev->priv;
1552
struct txdescriptor *tx_desc;
1564
if (!(priv->open)) {
1568
/* --------------------------------------
1569
** if the device is otherwise locked,
1571
** ----------------------------------- */
1572
if (acx_lock(priv, &flags))
1574
/* --------------------------------------
1575
** if the queue is halted, there is no point
1576
** in sending out data...
1577
** ----------------------------------- */
1578
if (acx_queue_stopped(dev)) {
1579
acxlog(L_STD, "%s: called when queue stopped\n", __func__);
1583
/* --------------------------------------
1584
** there is no one to talk to...
1585
** ----------------------------------- */
1586
if (priv->status != ACX_STATUS_4_ASSOCIATED) {
1587
printk(KERN_INFO SHORTNAME "trying to xmit, but not associated yet: aborting.\n");
1588
/* silently drop the packet, since we're not connected yet */
1590
priv->stats.tx_errors++;
1595
/* we're going to transmit now, so stop another packet from entering.
1596
* FIXME: most likely we shouldn't do it like that, but instead:
1597
* stop the queue during card init, then wake the queue once
1598
* we're associated to the network, then stop the queue whenever
1599
* we don't have any free Tx buffers left, and wake it again once a
1600
* Tx buffer becomes free again. And of course also stop the
1601
* queue once we lose association to the network (since it
1602
* doesn't make sense to allow more user packets if we can't
1603
* forward them to a network).
1604
* FIXME: Hmm, seems this is all wrong. We SHOULD leave the
1605
* queue open from the beginning (as long as we're not full,
1606
* and also even before we're even associated),
1607
* otherwise we'll get NETDEV WATCHDOG transmit timeouts... */
1608
acx_stop_queue(dev, "during Tx");
1611
if (acx_lock(priv,&flags)) ...
1613
memset(pb, 0, sizeof(wlan_pb_t) /*0x14*4 */ );
1615
pb->ethhostbuf = skb;
1616
pb->ethbuf = skb->data;
1619
/* ------------------------------------
1620
** get the next free tx descriptor...
1621
** -------------------------------- */
1622
tx_desc = acx_get_tx_desc(priv);
1624
acxlog(L_BINSTD,"BUG: txdesc ring full\n");
1628
/* ------------------------------------
1629
** convert the ethernet frame into our
1630
** own tx descriptor type...
1631
** -------------------------------- */
1632
acx_ether_to_txdesc(priv,tx_desc,skb);
1633
/* -------------------------
1635
** ---------------------- */
1637
dev->trans_start = jiffies;
1638
/* -----------------------------------
1639
** until the packages are flushed out,
1640
** stop the queue...
1641
** -------------------------------- */
1642
acx_stop_queue(dev, "after Tx");
1643
/* -----------------------------------
1644
** transmit the data...
1645
** -------------------------------- */
1646
acx_dma_tx_data(priv, tx_desc); /* this function finally calls acx100usb_tx_data() */
1648
/* -----------------------------------
1649
** statistical bookkeeping...
1650
** -------------------------------- */
1651
priv->stats.tx_packets++;
1652
priv->stats.tx_bytes += templen;
1654
acx_unlock(priv, &flags);
1661
static struct net_device_stats *acx_get_stats(netdevice_t *dev) {
1662
wlandevice_t *priv = (wlandevice_t *)dev->priv;
1664
FN_EXIT1((int)&priv->stats);
1665
return &priv->stats;
1670
static struct iw_statistics *acx_get_wireless_stats(netdevice_t *dev) {
1671
wlandevice_t *priv = (wlandevice_t *)dev->priv;
1673
FN_EXIT1((int)&priv->stats);
1674
return &priv->wstats;
1679
static void acx100usb_set_rx_mode(struct net_device *dev)
1685
#ifdef HAVE_TX_TIMEOUT
1686
static void acx100usb_tx_timeout(struct net_device *dev) {
1691
/* ------------------------------------
1692
** unlink the URBs....
1693
** --------------------------------- */
1694
for (i=0;i<ACX100_USB_NUM_BULK_URBS;i++) {
1695
if (priv->bulktx_urbs[i]->status==-EINPROGRESS) usb_unlink_urb(priv->bulktx_urbs[i]);
1697
/* ------------------------------------
1698
** TODO: stats update
1699
** --------------------------------- */
1708
/* ---------------------------------------------------------------------------
1712
** ---------------------------------------------------------------------------
1714
** (int) Errorcode on failure, 0 on success
1717
** This function is invoked upon loading of the kernel module. It registers
1718
** itself at the Kernel's USB subsystem.
1719
** ------------------------------------------------------------------------ */
1723
printk(KERN_INFO "Initializing acx100 WLAN USB kernel module\n");
1724
/* ------------------------------------------------------
1725
** Register this driver to the USB subsystem
1726
** --------------------------------------------------- */
1727
err=usb_register(&acx100usb_driver);
1736
/* ---------------------------------------------------------------------------
1737
** cleanup_module():
1740
** ---------------------------------------------------------------------------
1745
** This function is invoked as last step of the module unloading. It simply
1746
** deregisters this module at the Kernel's USB subsystem.
1747
** ------------------------------------------------------------------------- */
1749
void cleanup_module() {
1750
usb_deregister(&acx100usb_driver);
1751
printk(KERN_INFO "Cleaning up acx100 WLAN USB kernel module\n");
1755
/* ---------------------------------------------------------------------------
1757
** --------------------------------------------------------------------------- */
1761
static char *acx100usb_pstatus(int val)
1763
#define CASE(status) case status: return ""#status""
1765
CASE(USB_ST_NOERROR);
1767
CASE(USB_ST_BITSTUFF);
1768
CASE(USB_ST_DATAOVERRUN);
1769
CASE(USB_ST_BUFFEROVERRUN);
1770
CASE(USB_ST_BUFFERUNDERRUN);
1771
CASE(USB_ST_SHORT_PACKET);
1772
CASE(USB_ST_URB_KILLED);
1773
CASE(USB_ST_URB_PENDING);
1774
CASE(USB_ST_REMOVED);
1775
CASE(USB_ST_TIMEOUT);
1776
CASE(USB_ST_NOTSUPPORTED);
1777
CASE(USB_ST_BANDWIDTH_ERROR);
1778
CASE(USB_ST_URB_INVALID_ERROR);
1779
CASE(USB_ST_URB_REQUEST_ERROR);
1786
static char *acx100usb_pstatus(int val)
1788
static char status[80];
1791
sprintf(status, "errno %d\n", -val);
1793
sprintf(status, "length %d\n", val);
1799
static void dump_device(struct usb_device *usbdev)
1802
struct usb_config_descriptor *cd;
1804
printk(KERN_INFO "acx100 device dump:\n");
1805
printk(KERN_INFO " devnum: %d\n",usbdev->devnum);
1806
printk(KERN_INFO " speed: %d\n",usbdev->speed);
1807
printk(KERN_INFO " tt: 0x%X\n",(unsigned int)(usbdev->tt));
1808
printk(KERN_INFO " ttport: %d\n",(unsigned int)(usbdev->ttport));
1809
printk(KERN_INFO " toggle[0]: 0x%X toggle[1]: 0x%X\n",(unsigned int)(usbdev->toggle[0]),(unsigned int)(usbdev->toggle[1]));
1810
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 8)
1811
/* halted removed in 2.6.9-rc1 */
1812
/* DOH, Canbreak... err... Mandrake decided to do their very own very
1813
* special version "2.6.8.1" which already includes this change, so we
1814
* need to blacklist that version already (i.e. 2.6.8) */
1815
printk(KERN_INFO " halted[0]: 0x%X halted[1]: 0x%X\n",usbdev->halted[0],usbdev->halted[1]);
1817
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
1818
/* This saw a change after 2.6.10 */
1819
printk(KERN_INFO " ep_in wMaxPacketSize: ");
1820
for(i = 0; i < 16; ++i) printk("%d ", usbdev->ep_in[i]->desc.wMaxPacketSize);
1822
printk(KERN_INFO " ep_out wMaxPacketSize: ");
1823
for(i = 0; i < 15; ++i) printk("%d ", usbdev->ep_out[i]->desc.wMaxPacketSize);
1826
printk(KERN_INFO " epmaxpacketin: ");
1827
for (i=0;i<16;i++) printk("%d ",usbdev->epmaxpacketin[i]);
1829
printk(KERN_INFO " epmaxpacketout: ");
1830
for (i=0;i<16;i++) printk("%d ",usbdev->epmaxpacketout[i]);
1833
printk(KERN_INFO " parent: 0x%X\n",(unsigned int)(usbdev->parent));
1834
printk(KERN_INFO " bus: 0x%X\n",(unsigned int)(usbdev->bus));
1836
printk(KERN_INFO " configs: ");
1837
for (i=0;i<usbdev->descriptor.bNumConfigurations;i++) printk("0x%X ",usbdev->config[i]);
1840
printk(KERN_INFO " actconfig: %p\n",usbdev->actconfig);
1841
dump_device_descriptor(&(usbdev->descriptor));
1843
cd = usbdev->actconfig;
1845
cd = &usbdev->config->desc;
1847
dump_config_descriptor(cd);
1850
struct usb_interface *ifc;
1853
printk(KERN_INFO "iface: altsetting=%p act_altsetting=%d num_altsetting=%d max_altsetting=%d\n",ifc->altsetting,ifc->act_altsetting,ifc->num_altsetting,ifc->max_altsetting);
1854
dump_interface_descriptor(ifc->altsetting);
1855
dump_endpoint_descriptor(ifc->altsetting->endpoint);
1862
static void dump_config_descriptor(struct usb_config_descriptor *cd)
1864
printk(KERN_INFO "Configuration Descriptor:\n");
1866
printk(KERN_INFO "NULL\n");
1869
printk(KERN_INFO " bLength: %d (0x%X)\n",cd->bLength,cd->bLength);
1870
printk(KERN_INFO " bDescriptorType: %d (0x%X)\n",cd->bDescriptorType,cd->bDescriptorType);
1871
printk(KERN_INFO " bNumInterfaces: %d (0x%X)\n",cd->bNumInterfaces,cd->bNumInterfaces);
1872
printk(KERN_INFO " bConfigurationValue: %d (0x%X)\n",cd->bConfigurationValue,cd->bConfigurationValue);
1873
printk(KERN_INFO " iConfiguration: %d (0x%X)\n",cd->iConfiguration,cd->iConfiguration);
1874
printk(KERN_INFO " bmAttributes: %d (0x%X)\n",cd->bmAttributes,cd->bmAttributes);
1875
/* printk(KERN_INFO " MaxPower: %d (0x%X)\n",cd->bMaxPower,cd->bMaxPower); */
1878
static void dump_device_descriptor(struct usb_device_descriptor *dd)
1880
printk(KERN_INFO "Device Descriptor:\n");
1882
printk(KERN_INFO "NULL\n");
1885
printk(KERN_INFO " bLength: %d (0x%X)\n",dd->bLength,dd->bLength);
1886
printk(KERN_INFO " bDescriptortype: %d (0x%X)\n",dd->bDescriptorType,dd->bDescriptorType);
1887
printk(KERN_INFO " bcdUSB: %d (0x%X)\n",dd->bcdUSB,dd->bcdUSB);
1888
printk(KERN_INFO " bDeviceClass: %d (0x%X)\n",dd->bDeviceClass,dd->bDeviceClass);
1889
printk(KERN_INFO " bDeviceSubClass: %d (0x%X)\n",dd->bDeviceSubClass,dd->bDeviceSubClass);
1890
printk(KERN_INFO " bDeviceProtocol: %d (0x%X)\n",dd->bDeviceProtocol,dd->bDeviceProtocol);
1891
printk(KERN_INFO " bMaxPacketSize0: %d (0x%X)\n",dd->bMaxPacketSize0,dd->bMaxPacketSize0);
1892
printk(KERN_INFO " idVendor: %d (0x%X)\n",dd->idVendor,dd->idVendor);
1893
printk(KERN_INFO " idProduct: %d (0x%X)\n",dd->idProduct,dd->idProduct);
1894
printk(KERN_INFO " bcdDevice: %d (0x%X)\n",dd->bcdDevice,dd->bcdDevice);
1895
printk(KERN_INFO " iManufacturer: %d (0x%X)\n",dd->iManufacturer,dd->iManufacturer);
1896
printk(KERN_INFO " iProduct: %d (0x%X)\n",dd->iProduct,dd->iProduct);
1897
printk(KERN_INFO " iSerialNumber: %d (0x%X)\n",dd->iSerialNumber,dd->iSerialNumber);
1898
printk(KERN_INFO " bNumConfigurations: %d (0x%X)\n",dd->bNumConfigurations,dd->bNumConfigurations);
1902
static void dump_usbblock(char *block,int bytes)
1905
for (i=0;i<bytes;i++) {
1907
if (i!=0) printk("\n");
1910
printk("%02X ",(unsigned char)(block[i]));
1914
static void dump_endpoint_descriptor(struct usb_endpoint_descriptor *ep)
1916
printk(KERN_INFO "Endpoint Descriptor:\n");
1918
printk(KERN_INFO "NULL\n");
1921
printk(KERN_INFO " bLength: %d (0x%X)\n",ep->bLength,ep->bLength);
1922
printk(KERN_INFO " bDescriptorType: %d (0x%X)\n",ep->bDescriptorType,ep->bDescriptorType);
1923
printk(KERN_INFO " bEndpointAddress: %d (0x%X)\n",ep->bEndpointAddress,ep->bEndpointAddress);
1924
printk(KERN_INFO " bmAttributes: 0x%X\n",ep->bmAttributes);
1925
printk(KERN_INFO " wMaxPacketSize: %d (0x%X)\n",ep->wMaxPacketSize,ep->wMaxPacketSize);
1926
printk(KERN_INFO " bInterval: %d (0x%X)\n",ep->bInterval,ep->bInterval);
1927
printk(KERN_INFO " bRefresh: %d (0x%X)\n",ep->bRefresh,ep->bRefresh);
1928
printk(KERN_INFO " bSyncAdrress: %d (0x%X)\n",ep->bSynchAddress,ep->bSynchAddress);
1931
static void dump_interface_descriptor(struct usb_interface_descriptor *id)
1933
printk(KERN_INFO "Interface Descriptor:\n");
1935
printk(KERN_INFO "NULL\n");
1938
printk(KERN_INFO " bLength: %d (0x%X)\n",id->bLength,id->bLength);
1939
printk(KERN_INFO " bDescriptorType: %d (0x%X)\n",id->bDescriptorType,id->bDescriptorType);
1940
printk(KERN_INFO " bInterfaceNumber: %d (0x%X)\n",id->bInterfaceNumber,id->bInterfaceNumber);
1941
printk(KERN_INFO " bAlternateSetting: %d (0x%X)\n",id->bAlternateSetting,id->bAlternateSetting);
1942
printk(KERN_INFO " bNumEndpoints: %d (0x%X)\n",id->bNumEndpoints,id->bNumEndpoints);
1943
printk(KERN_INFO " bInterfaceClass: %d (0x%X)\n",id->bInterfaceClass,id->bInterfaceClass);
1944
printk(KERN_INFO " bInterfaceSubClass: %d (0x%X)\n",id->bInterfaceSubClass,id->bInterfaceSubClass);
1945
printk(KERN_INFO " bInterfaceProtocol: %d (0x%X)\n",id->bInterfaceProtocol,id->bInterfaceProtocol);
1946
printk(KERN_INFO " iInterface: %d (0x%X)\n",id->iInterface,id->iInterface);
1948
printk(KERN_INFO " endpoint: 0x%X\n",(unsigned int)(id->endpoint));