1 /**** (legal) claimer in README
2 ** Copyright (C) 2003 ACX100 Open Source Project
5 /***********************************************************************
6 ** USB support for TI ACX100 based devices. Many parts are taken from
10 ** Martin Wawro <martin.wawro AT uni-dortmund.de>
11 ** Andreas Mohr <andi AT lisas.de>
14 ** callback functions called by USB core are running in interrupt context
15 ** and thus have names with _i_.
17 #define ACX_MAC80211_USB 1
19 #include <linux/version.h>
20 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 18)
21 #include <linux/config.h>
23 #include <linux/types.h>
24 #include <linux/module.h>
25 #include <linux/moduleparam.h>
26 #include <linux/kernel.h>
27 #include <linux/usb.h>
28 #include <linux/netdevice.h>
29 #include <linux/rtnetlink.h>
30 #include <linux/etherdevice.h>
31 #include <linux/wireless.h>
32 #include <net/iw_handler.h>
33 #include <linux/vmalloc.h>
34 #include <linux/ethtool.h>
35 #include <linux/workqueue.h>
40 /***********************************************************************
42 /* number of endpoints of an interface */
43 #define NUM_EP(intf) (intf)->altsetting[0].desc.bNumEndpoints
44 #define EP(intf, nr) (intf)->altsetting[0].endpoint[(nr)].desc
45 #define GET_DEV(udev) usb_get_dev((udev))
46 #define PUT_DEV(udev) usb_put_dev((udev))
48 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
49 /* removed in 2.6.14. We will use fake value for now */
50 #define URB_ASYNC_UNLINK 0
54 /***********************************************************************
56 /* ACX100 (TNETW1100) USB device: D-Link DWL-120+ */
57 #define ACX100_VENDOR_ID 0x2001
58 #define ACX100_PRODUCT_ID_UNBOOTED 0x3B01
59 #define ACX100_PRODUCT_ID_BOOTED 0x3B00
61 /* TNETW1450 USB devices */
62 #define VENDOR_ID_DLINK 0x07b8 /* D-Link Corp. */
63 #define PRODUCT_ID_WUG2400 0xb21a /* AboCom WUG2400 or SafeCom SWLUT-54125 */
64 #define VENDOR_ID_AVM_GMBH 0x057c
65 #define PRODUCT_ID_AVM_WLAN_USB 0x5601
66 #define PRODUCT_ID_AVM_WLAN_USB_si 0x6201 /* "self install" named Version:
67 * driver kills kernel on inbound scans from fritz box ?? */
68 #define VENDOR_ID_ZCOM 0x0cde
69 #define PRODUCT_ID_ZCOM_XG750 0x0017 /* not tested yet */
70 #define VENDOR_ID_TI 0x0451
71 #define PRODUCT_ID_TI_UNKNOWN 0x60c5 /* not tested yet */
73 #define ACX_USB_CTRL_TIMEOUT 5500 /* steps in ms */
75 /* Buffer size for fw upload, same for both ACX100 USB and TNETW1450 */
76 #define USB_RWMEM_MAXLEN 2048
78 /* The number of bulk URBs to use */
79 #define ACX_TX_URB_CNT 8
80 #define ACX_RX_URB_CNT 2
82 /* Should be sent to the bulkout endpoint */
83 #define ACX_USB_REQ_UPLOAD_FW 0x10
84 #define ACX_USB_REQ_ACK_CS 0x11
85 #define ACX_USB_REQ_CMD 0x12
87 /***********************************************************************
90 static int acxusb_e_probe(struct usb_interface
*, const struct usb_device_id
*);
91 static void acxusb_e_disconnect(struct usb_interface
*);
92 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
93 static void acxusb_i_complete_tx(struct urb
*);
94 static void acxusb_i_complete_rx(struct urb
*);
96 static void acxusb_i_complete_tx(struct urb
*, struct pt_regs
*);
97 static void acxusb_i_complete_rx(struct urb
*, struct pt_regs
*);
99 static int acxusb_e_open(struct ieee80211_hw
*);
100 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
101 static int acxusb_e_close(struct ieee80211_hw
*);
103 static void acxusb_e_close(struct ieee80211_hw
*);
105 //static void acxusb_i_set_rx_mode(struct net_device *);
106 static int acxusb_boot(struct usb_device
*, int is_tnetw1450
, int *radio_type
);
108 static void acxusb_l_poll_rx(acx_device_t
* adev
, usb_rx_t
* rx
);
110 /*static void acxusb_i_tx_timeout(struct net_device *);*/
112 /* static void dump_device(struct usb_device *); */
113 /* static void dump_device_descriptor(struct usb_device_descriptor *); */
114 /* static void dump_config_descriptor(struct usb_config_descriptor *); */
116 /***********************************************************************
119 #define TXBUFSIZE sizeof(usb_txbuffer_t)
121 * Now, this is just plain lying, but the device insists in giving us
122 * huge packets. We supply extra space after rxbuffer. Need to understand
125 #define RXBUFSIZE (sizeof(rxbuffer_t) + \
126 (sizeof(usb_rx_t) - sizeof(struct usb_rx_plain)))
128 static const struct usb_device_id acxusb_ids
[] = {
129 {USB_DEVICE(ACX100_VENDOR_ID
, ACX100_PRODUCT_ID_BOOTED
)},
130 {USB_DEVICE(ACX100_VENDOR_ID
, ACX100_PRODUCT_ID_UNBOOTED
)},
131 {USB_DEVICE(VENDOR_ID_DLINK
, PRODUCT_ID_WUG2400
)},
132 {USB_DEVICE(VENDOR_ID_AVM_GMBH
, PRODUCT_ID_AVM_WLAN_USB
)},
133 {USB_DEVICE(VENDOR_ID_AVM_GMBH
, PRODUCT_ID_AVM_WLAN_USB_si
)},
134 {USB_DEVICE(VENDOR_ID_ZCOM
, PRODUCT_ID_ZCOM_XG750
)},
135 {USB_DEVICE(VENDOR_ID_TI
, PRODUCT_ID_TI_UNKNOWN
)},
139 MODULE_DEVICE_TABLE(usb
, acxusb_ids
);
141 /* USB driver data structure as required by the kernel's USB core */
142 static struct usb_driver
145 .probe
= acxusb_e_probe
,
146 .disconnect
= acxusb_e_disconnect
,
147 .id_table
= acxusb_ids
150 void acxusb_put_devname(acx_device_t
*adev
, struct ethtool_drvinfo
*info
)
153 usb_make_path(adev
->usbdev
, info
->bus_info
, sizeof info
->bus_info
);
155 /***********************************************************************
159 ** When the function is usb_kill_urb, the urb lifecycle is stopped. This
160 ** function is usually used when the device is disconnected from the system,
161 ** in the disconnect callback. For some drivers, the usb_unlink_urb function
162 ** should be used to tell the USB core to stop an urb. This function does not
163 ** wait for the urb to be fully stopped before returning to the caller.
164 ** This is useful for stoppingthe urb while in an interrupt handler or when
165 ** a spinlock is held, as waiting for a urb to fully stop requires the ability
166 ** for the USB core to put the calling process to sleep. This function requires
167 ** that the URB_ASYNC_UNLINK flag value be set in the urb that is being asked
168 ** to be stopped in order to work properly.
170 ** (URB_ASYNC_UNLINK is obsolete, usb_unlink_urb will always be
171 ** asynchronous while usb_kill_urb is synchronous and should be called
172 ** directly (drivers/usb/core/urb.c))
174 ** In light of this, timeout is just for paranoid reasons...
176 ** Actually, it's useful for debugging. If we reach timeout, we're doing
177 ** something wrong with the urbs.
179 static void acxusb_unlink_urb(struct urb
*urb
)
184 if (urb
->status
== -EINPROGRESS
) {
188 while (--timeout
&& urb
->status
== -EINPROGRESS
) {
192 printk(KERN_ERR
"acx_usb: urb unlink timeout!\n");
198 /***********************************************************************
199 ** EEPROM and PHY read/write helpers
201 /***********************************************************************
202 ** acxusb_s_read_phy_reg
204 int acxusb_s_read_phy_reg(acx_device_t
* adev
, u32 reg
, u8
* charbuf
)
206 /* mem_read_write_t mem; */
210 printk("%s doesn't seem to work yet, disabled.\n", __func__
);
213 mem.addr = cpu_to_le16(reg);
214 mem.type = cpu_to_le16(0x82);
215 mem.len = cpu_to_le32(4);
216 acx_s_issue_cmd(adev, ACX1xx_CMD_MEM_READ, &mem, sizeof(mem));
218 log(L_DEBUG, "read radio PHY[0x%04X]=0x%02X\n", reg, *charbuf);
226 /***********************************************************************
228 int acxusb_s_write_phy_reg(acx_device_t
* adev
, u32 reg
, u8 value
)
230 mem_read_write_t mem
;
234 mem
.addr
= cpu_to_le16(reg
);
235 mem
.type
= cpu_to_le16(0x82);
236 mem
.len
= cpu_to_le32(4);
238 acx_s_issue_cmd(adev
, ACX1xx_CMD_MEM_WRITE
, &mem
, sizeof(mem
));
239 log(L_DEBUG
, "write radio PHY[0x%04X]=0x%02X\n", reg
, value
);
246 /***********************************************************************
247 ** acxusb_s_issue_cmd_timeo
248 ** Excecutes a command in the command mailbox
250 ** buffer = a pointer to the data.
251 ** The data must not include 4 byte command header
254 /* TODO: ideally we shall always know how much we need
255 ** and this shall be 0 */
256 #define BOGUS_SAFETY_PADDING 0x40
259 #define FUNC "issue_cmd"
263 acxusb_s_issue_cmd_timeo(acx_device_t
* adev
,
265 void *buffer
, unsigned buflen
, unsigned timeout
)
269 acxusb_s_issue_cmd_timeo_debug(acx_device_t
* adev
,
273 unsigned timeout
, const char *cmdstr
)
276 /* USB ignores timeout param */
278 struct usb_device
*usbdev
;
285 int acklen
, blocklen
, inpipe
, outpipe
;
291 devname
= wiphy_name(adev
->ieee
->wiphy
);
292 /* no "wlan%%d: ..." please */
293 if (!devname
|| !devname
[0] || devname
[4] == '%')
296 log(L_CTL
, FUNC
"(cmd:%s,buflen:%u,type:0x%04X)\n",
298 buffer
? le16_to_cpu(((acx_ie_generic_t
*) buffer
)->type
) : -1);
300 loc
= kmalloc(buflen
+ 4 + BOGUS_SAFETY_PADDING
, GFP_KERNEL
);
302 printk("%s: " FUNC
"(): no memory for data buffer\n", devname
);
306 /* get context from acx_device */
307 usbdev
= adev
->usbdev
;
309 /* check which kind of command was issued */
310 loc
->cmd
= cpu_to_le16(cmd
);
313 /* NB: buflen == frmlen + 4
315 ** Interrogate: write 8 bytes: (cmd,status,rid,frmlen), then
316 ** read (cmd,status,rid,frmlen,data[frmlen]) back
318 ** Configure: write (cmd,status,rid,frmlen,data[frmlen])
320 ** Possibly bogus special handling of ACX1xx_IE_SCAN_STATUS removed
323 /* now write the parameters of the command if needed */
324 acklen
= buflen
+ 4 + BOGUS_SAFETY_PADDING
;
326 if (buffer
&& buflen
) {
327 /* if it's an INTERROGATE command, just pass the length
328 * of parameters to read, as data */
329 if (cmd
== ACX1xx_CMD_INTERROGATE
) {
333 memcpy(loc
->data
, buffer
, blocklen
);
335 blocklen
+= 4; /* account for cmd,status */
337 /* obtain the I/O pipes */
338 outpipe
= usb_sndctrlpipe(usbdev
, 0);
339 inpipe
= usb_rcvctrlpipe(usbdev
, 0);
340 log(L_CTL
, "ctrl inpipe=0x%X outpipe=0x%X\n", inpipe
, outpipe
);
341 log(L_CTL
, "sending USB control msg (out) (blocklen=%d)\n", blocklen
);
342 if (acx_debug
& L_DATA
)
343 acx_dump_bytes(loc
, blocklen
);
345 result
= usb_control_msg(usbdev
, outpipe
, ACX_USB_REQ_CMD
, /* request */
346 USB_TYPE_VENDOR
| USB_DIR_OUT
, /* requesttype */
351 ACX_USB_CTRL_TIMEOUT
/* timeout in ms */
354 if (result
== -ENODEV
) {
355 log(L_CTL
, "no device present (unplug?)\n");
359 log(L_CTL
, "wrote %d bytes\n", result
);
364 /* check for device acknowledge */
365 log(L_CTL
, "sending USB control msg (in) (acklen=%d)\n", acklen
);
366 loc
->status
= 0; /* delete old status flag -> set to IDLE */
367 /* shall we zero out the rest? */
368 result
= usb_control_msg(usbdev
, inpipe
, ACX_USB_REQ_CMD
, /* request */
369 USB_TYPE_VENDOR
| USB_DIR_IN
, /* requesttype */
374 ACX_USB_CTRL_TIMEOUT
/* timeout in ms */
377 printk("%s: " FUNC
"(): USB read error %d\n", devname
, result
);
380 if (acx_debug
& L_CTL
) {
381 printk("read %d bytes: ", result
);
382 acx_dump_bytes(loc
, result
);
386 check for result==buflen+4? Was seen:
388 interrogate(type:ACX100_IE_DOT11_ED_THRESHOLD,len:4)
389 issue_cmd(cmd:ACX1xx_CMD_INTERROGATE,buflen:8,type:4111)
390 ctrl inpipe=0x80000280 outpipe=0x80000200
391 sending USB control msg (out) (blocklen=8)
392 01 00 00 00 0F 10 04 00
394 sending USB control msg (in) (acklen=12) sizeof(loc->data
395 read 4 bytes <==== MUST BE 12!!
398 cmd_status
= le16_to_cpu(loc
->status
);
399 if (cmd_status
!= 1) {
400 printk("%s: " FUNC
"(): cmd_status is not SUCCESS: %d (%s)\n",
401 devname
, cmd_status
, acx_cmd_status_str(cmd_status
));
402 /* TODO: goto bad; ? */
404 if ((cmd
== ACX1xx_CMD_INTERROGATE
) && buffer
&& buflen
) {
405 memcpy(buffer
, loc
->data
, buflen
);
406 log(L_CTL
, "response frame: cmd=0x%04X status=%d\n",
407 le16_to_cpu(loc
->cmd
), cmd_status
);
414 /* Give enough info so that callers can avoid
415 ** printing their own diagnostic messages */
417 printk("%s: " FUNC
"(cmd:%s) FAILED\n", devname
, cmdstr
);
419 printk("%s: " FUNC
"(cmd:0x%04X) FAILED\n", devname
, cmd
);
428 /***********************************************************************
431 ** usbdev -> Pointer to kernel's usb_device structure
434 ** (int) Errorcode or 0 on success
436 ** This function triggers the loading of the firmware image from harddisk
437 ** and then uploads the firmware to the USB device. After uploading the
438 ** firmware and transmitting the checksum, the device resets and appears
439 ** as a new device on the USB bus (the device we can finally deal with)
442 acxusb_fw_needs_padding(firmware_image_t
*fw_image
, unsigned int usb_maxlen
)
444 unsigned int num_xfers
= ((fw_image
->size
- 1) / usb_maxlen
) + 1;
446 return ((num_xfers
% 2) == 0);
450 acxusb_boot(struct usb_device
*usbdev
, int is_tnetw1450
, int *radio_type
)
452 char filename
[sizeof("tiacx1NNusbcRR")];
454 firmware_image_t
*fw_image
= NULL
;
457 unsigned int blk_len
, inpipe
, outpipe
;
459 u32 img_checksum
, sum
;
466 /* dump_device(usbdev); */
468 usbbuf
= kmalloc(USB_RWMEM_MAXLEN
, GFP_KERNEL
);
471 "acx: no memory for USB transfer buffer (%d bytes)\n",
477 /* Obtain the I/O pipes */
478 outpipe
= usb_sndbulkpipe(usbdev
, 1);
479 inpipe
= usb_rcvbulkpipe(usbdev
, 2);
481 printk(KERN_DEBUG
"wait for device ready\n");
482 for (i
= 0; i
<= 2; i
++) {
483 result
= usb_bulk_msg(usbdev
, inpipe
,
486 &num_processed
, 2000);
488 if ((*(u32
*) & usbbuf
[4] == 0x40000001)
489 && (*(u16
*) & usbbuf
[2] == 0x1)
490 && ((*(u16
*) usbbuf
& 0x3fff) == 0)
491 && ((*(u16
*) usbbuf
& 0xc000) == 0xc000))
498 *radio_type
= usbbuf
[8];
500 /* Obtain the I/O pipes */
501 outpipe
= usb_sndctrlpipe(usbdev
, 0);
502 inpipe
= usb_rcvctrlpipe(usbdev
, 0);
504 /* FIXME: shouldn't be hardcoded */
505 *radio_type
= RADIO_MAXIM_0D
;
508 snprintf(filename
, sizeof(filename
), "tiacx1%02dusbc%02X",
509 is_tnetw1450
* 11, *radio_type
);
511 fw_image
= acx_s_read_fw(&usbdev
->dev
, filename
, &file_size
);
516 log(L_INIT
, "firmware size: %d bytes\n", file_size
);
518 img_checksum
= le32_to_cpu(fw_image
->chksum
);
526 memset(cmdbuf
, 0, 16);
529 acxusb_fw_needs_padding(fw_image
, USB_RWMEM_MAXLEN
);
530 tmplen
= need_padding
? file_size
- 4 : file_size
- 8;
531 *(u16
*) & cmdbuf
[0] = 0xc000;
532 *(u16
*) & cmdbuf
[2] = 0x000b;
533 *(u32
*) & cmdbuf
[4] = tmplen
;
534 *(u32
*) & cmdbuf
[8] = file_size
- 8;
535 *(u32
*) & cmdbuf
[12] = img_checksum
;
538 usb_bulk_msg(usbdev
, outpipe
, cmdbuf
, 16, &num_processed
,
543 p
= (const u8
*)&fw_image
->size
;
545 /* first calculate checksum for image size part */
546 sum
= p
[0] + p
[1] + p
[2] + p
[3];
549 /* now continue checksum for firmware data part */
550 tmplen
= le32_to_cpu(fw_image
->size
);
551 for (i
= 0; i
< tmplen
/* image size */ ; i
++) {
555 if (sum
!= le32_to_cpu(fw_image
->chksum
)) {
556 printk("acx: FATAL: firmware upload: "
557 "checksums don't match! "
558 "(0x%08x vs. 0x%08x)\n", sum
, fw_image
->chksum
);
563 while (offset
< file_size
) {
564 blk_len
= file_size
- offset
;
565 if (blk_len
> USB_RWMEM_MAXLEN
) {
566 blk_len
= USB_RWMEM_MAXLEN
;
570 "uploading firmware (%d bytes, offset=%d)\n",
572 memcpy(usbbuf
, ((u8
*) fw_image
) + offset
, blk_len
);
575 for (i
= 0; i
< blk_len
; i
+= 4) {
576 *(u32
*) p
= be32_to_cpu(*(u32
*) p
);
581 usb_bulk_msg(usbdev
, outpipe
, usbbuf
, blk_len
,
583 if ((result
< 0) || (num_processed
!= blk_len
))
588 printk(KERN_DEBUG
"send padding\n");
589 memset(usbbuf
, 0, 4);
591 usb_bulk_msg(usbdev
, outpipe
, usbbuf
, 4,
593 if ((result
< 0) || (num_processed
!= 4))
596 printk(KERN_DEBUG
"read firmware upload result\n");
597 memset(cmdbuf
, 0, 20); /* additional memset */
599 usb_bulk_msg(usbdev
, inpipe
, cmdbuf
, 20, &num_processed
,
603 if (*(u32
*) & cmdbuf
[4] == 0x40000003)
605 if (*(u32
*) & cmdbuf
[4])
607 if (*(u16
*) & cmdbuf
[16] != 1)
610 val
= *(u32
*) & cmdbuf
[0];
612 || ((val
& 0xc000) != 0xc000))
615 val
= *(u32
*) & cmdbuf
[8];
618 usb_bulk_msg(usbdev
, inpipe
, cmdbuf
, 20,
619 &num_processed
, 2000);
622 val
= *(u32
*) & cmdbuf
[8];
624 /* yup, no "else" here! */
626 memset(usbbuf
, 0, 4);
628 usb_bulk_msg(usbdev
, outpipe
, usbbuf
, 4,
630 if ((result
< 0) || (!num_processed
))
634 printk("TNETW1450 firmware upload successful!\n");
643 /* now upload the firmware, slice the data into blocks */
645 while (offset
< file_size
) {
646 blk_len
= file_size
- offset
;
647 if (blk_len
> USB_RWMEM_MAXLEN
) {
648 blk_len
= USB_RWMEM_MAXLEN
;
651 "uploading firmware (%d bytes, offset=%d)\n",
653 memcpy(usbbuf
, ((u8
*) fw_image
) + offset
, blk_len
);
654 result
= usb_control_msg(usbdev
, outpipe
, ACX_USB_REQ_UPLOAD_FW
, USB_TYPE_VENDOR
| USB_DIR_OUT
, (file_size
- 8) & 0xffff, /* value */
655 (file_size
- 8) >> 16, /* index */
656 usbbuf
, /* dataptr */
658 3000 /* timeout in ms */
662 printk(KERN_ERR
"acx: error %d during upload "
663 "of firmware, aborting\n", result
);
668 /* finally, send the checksum and reboot the device */
669 /* does this trigger the reboot? */
670 result
= usb_control_msg(usbdev
, outpipe
, ACX_USB_REQ_UPLOAD_FW
, USB_TYPE_VENDOR
| USB_DIR_OUT
, img_checksum
& 0xffff, /* value */
671 img_checksum
>> 16, /* index */
674 3000 /* timeout in ms */
677 printk(KERN_ERR
"acx: error %d during tx of checksum, "
678 "aborting\n", result
);
681 result
= usb_control_msg(usbdev
, inpipe
, ACX_USB_REQ_ACK_CS
, USB_TYPE_VENDOR
| USB_DIR_IN
, img_checksum
& 0xffff, /* value */
682 img_checksum
>> 16, /* index */
683 usbbuf
, /* dataptr */
685 3000 /* timeout in ms */
688 printk(KERN_ERR
"acx: error %d during ACK of checksum, "
689 "aborting\n", result
);
692 if (*usbbuf
!= 0x10) {
693 printk(KERN_ERR
"acx: invalid checksum?\n");
709 /* FIXME: maybe merge it with usual eeprom reading, into common code? */
710 static void acxusb_s_read_eeprom_version(acx_device_t
* adev
)
714 memset(eeprom_ver
, 0, sizeof(eeprom_ver
));
715 acx_s_interrogate(adev
, &eeprom_ver
, ACX1FF_IE_EEPROM_VER
);
717 /* FIXME: which one of those values to take? */
718 adev
->eeprom_version
= eeprom_ver
[5];
723 * temporary helper function to at least fill important cfgopt members with
724 * useful replacement values until we figure out how one manages to fetch
725 * the configoption struct in the USB device case...
727 static int acxusb_s_fill_configoption(acx_device_t
* adev
)
729 adev
->cfgopt_probe_delay
= 200;
730 adev
->cfgopt_dot11CCAModes
= 4;
731 adev
->cfgopt_dot11Diversity
= 1;
732 adev
->cfgopt_dot11ShortPreambleOption
= 1;
733 adev
->cfgopt_dot11PBCCOption
= 1;
734 adev
->cfgopt_dot11ChannelAgility
= 0;
735 adev
->cfgopt_dot11PhyType
= 5;
736 adev
->cfgopt_dot11TempType
= 1;
740 static const struct ieee80211_ops acxusb_hw_ops
= {
741 .tx
= acx_i_start_xmit
,
742 .conf_tx
= acx_net_conf_tx
,
743 .add_interface
= acx_add_interface
,
744 .remove_interface
= acx_remove_interface
,
745 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
746 .open
= acxusb_e_open
,
747 .reset
= acx_net_reset
,
748 .set_multicast_list
= acx_i_set_multicast_list
,
750 .start
= acxusb_e_open
,
751 .configure_filter
= acx_i_set_multicast_list
,
753 .stop
= acxusb_e_close
,
754 .config
= acx_net_config
,
755 .config_interface
= acx_config_interface
,
756 .set_key
= acx_net_set_key
,
757 .get_stats
= acx_e_get_stats
,
758 .get_tx_stats
= acx_net_get_tx_stats
,
761 /***********************************************************************
764 ** This function is invoked by the kernel's USB core whenever a new device is
765 ** attached to the system or the module is loaded. It is presented a usb_device
766 ** structure from which information regarding the device is obtained and evaluated.
767 ** In case this driver is able to handle one of the offered devices, it returns
768 ** a non-null pointer to a driver context and thereby claims the device.
773 acxusb_e_probe(struct usb_interface
*intf
, const struct usb_device_id
*devID
)
775 struct usb_device
*usbdev
= interface_to_usbdev(intf
);
776 acx_device_t
*adev
= NULL
;
777 struct usb_config_descriptor
*config
;
778 struct usb_endpoint_descriptor
*epdesc
;
779 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
780 struct usb_host_endpoint
*ep
;
782 struct usb_interface_descriptor
*ifdesc
;
784 int numconfigs
, numfaces
, numep
;
788 /* this one needs to be more precise in case there appears
789 * a TNETW1450 from the same vendor */
790 int is_tnetw1450
= (usbdev
->descriptor
.idVendor
!= ACX100_VENDOR_ID
);
791 struct ieee80211_hw
*ieee
;
796 /* Boot the device (i.e. upload the firmware) */
797 acxusb_boot(usbdev
, is_tnetw1450
, &radio_type
);
799 /* TNETW1450-based cards will continue right away with
800 * the same USB ID after booting */
802 /* First check if this is the "unbooted" hardware */
803 if (usbdev
->descriptor
.idProduct
== ACX100_PRODUCT_ID_UNBOOTED
) {
805 /* Boot the device (i.e. upload the firmware) */
806 acxusb_boot(usbdev
, is_tnetw1450
, &radio_type
);
808 /* DWL-120+ will first boot the firmware,
809 * then later have a *separate* probe() run
810 * since its USB ID will have changed after
812 * Since the first probe() run has no
813 * other purpose than booting the firmware,
814 * simply return immediately.
817 "finished booting, returning from probe()\n");
818 result
= OK
; /* success */
821 if (usbdev
->descriptor
.idProduct
!= ACX100_PRODUCT_ID_BOOTED
)
822 /* device not unbooted, but invalid USB ID!? */
827 /* Ok, so it's our device and it has already booted */
829 /* Allocate memory for a network device */
831 ieee
= ieee80211_alloc_hw(sizeof(*adev
), &acxusb_hw_ops
);
833 msg
= "acx: no memory for ieee80211_dev\n";
838 ieee
->flags
&= ~IEEE80211_HW_RX_INCLUDES_FCS
;
841 /* Register the callbacks for the network device functions */
844 /* Setup private driver context */
846 adev
= ieee2adev(ieee
);
849 adev
->dev_type
= DEVTYPE_USB
;
850 adev
->radio_type
= radio_type
;
852 /* well, actually it's a TNETW1450, but since it
853 * seems to be sufficiently similar to TNETW1130,
854 * I don't want to change large amounts of code now */
855 adev
->chip_type
= CHIPTYPE_ACX111
;
857 adev
->chip_type
= CHIPTYPE_ACX100
;
860 adev
->usbdev
= usbdev
;
861 spin_lock_init(&adev
->lock
); /* initial state: unlocked */
862 mutex_init(&adev
->mutex
);
864 /* Check that this is really the hardware we know about.
865 ** If not sure, at least notify the user that he
866 ** may be in trouble...
868 numconfigs
= (int)usbdev
->descriptor
.bNumConfigurations
;
870 printk("acx: number of configurations is %d, "
871 "this driver only knows how to handle 1, "
872 "be prepared for surprises\n", numconfigs
);
874 config
= &usbdev
->config
->desc
;
875 numfaces
= config
->bNumInterfaces
;
877 printk("acx: number of interfaces is %d, "
878 "this driver only knows how to handle 1, "
879 "be prepared for surprises\n", numfaces
);
881 ifdesc
= &intf
->altsetting
->desc
;
882 numep
= ifdesc
->bNumEndpoints
;
883 log(L_DEBUG
, "# of endpoints: %d\n", numep
);
889 /* obtain information about the endpoint
890 ** addresses, begin with some default values
894 for (i
= 0; i
< numep
; i
++) {
895 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
896 ep
= usbdev
->ep_in
[i
];
901 epdesc
= usb_epnum_to_ep_desc(usbdev
, i
);
905 if (epdesc
->bmAttributes
& USB_ENDPOINT_XFER_BULK
) {
906 if (epdesc
->bEndpointAddress
& 0x80)
908 epdesc
->bEndpointAddress
& 0xF;
911 epdesc
->bEndpointAddress
& 0xF;
915 log(L_DEBUG
, "bulkout ep: 0x%X\n", adev
->bulkoutep
);
916 log(L_DEBUG
, "bulkin ep: 0x%X\n", adev
->bulkinep
);
918 /* already done by memset: adev->rxtruncsize = 0; */
919 log(L_DEBUG
, "TXBUFSIZE=%d RXBUFSIZE=%d\n",
920 (int)TXBUFSIZE
, (int)RXBUFSIZE
);
922 /* Allocate the RX/TX containers. */
923 adev
->usb_tx
= kmalloc(sizeof(usb_tx_t
) * ACX_TX_URB_CNT
, GFP_KERNEL
);
925 msg
= "acx: no memory for tx container";
928 adev
->usb_rx
= kmalloc(sizeof(usb_rx_t
) * ACX_RX_URB_CNT
, GFP_KERNEL
);
930 msg
= "acx: no memory for rx container";
934 /* Setup URBs for bulk-in/out messages */
935 for (i
= 0; i
< ACX_RX_URB_CNT
; i
++) {
936 adev
->usb_rx
[i
].urb
= usb_alloc_urb(0, GFP_KERNEL
);
937 if (!adev
->usb_rx
[i
].urb
) {
938 msg
= "acx: no memory for input URB\n";
941 adev
->usb_rx
[i
].urb
->status
= 0;
942 adev
->usb_rx
[i
].adev
= adev
;
943 adev
->usb_rx
[i
].busy
= 0;
946 for (i
= 0; i
< ACX_TX_URB_CNT
; i
++) {
947 adev
->usb_tx
[i
].urb
= usb_alloc_urb(0, GFP_KERNEL
);
948 if (!adev
->usb_tx
[i
].urb
) {
949 msg
= "acx: no memory for output URB\n";
952 adev
->usb_tx
[i
].urb
->status
= 0;
953 adev
->usb_tx
[i
].adev
= adev
;
954 adev
->usb_tx
[i
].busy
= 0;
956 adev
->tx_free
= ACX_TX_URB_CNT
;
958 usb_set_intfdata(intf
, adev
);
959 SET_IEEE80211_DEV(ieee
, &intf
->dev
);
961 /* TODO: move all of fw cmds to open()? But then we won't know our MAC addr
962 until ifup (it's available via reading ACX1xx_IE_DOT11_STATION_ID)... */
964 /* put acx out of sleep mode and initialize it */
965 acx_s_issue_cmd(adev
, ACX1xx_CMD_WAKE
, NULL
, 0);
967 result
= acx_s_init_mac(adev
);
971 /* TODO: see similar code in pci.c */
972 acxusb_s_read_eeprom_version(adev
);
973 acxusb_s_fill_configoption(adev
);
974 acx_s_set_defaults(adev
);
975 acx_s_get_firmware_version(adev
);
976 acx_display_hardware_details(adev
);
978 /* MAC_COPY(ndev->dev_addr, adev->dev_addr); */
980 /* Register the network device */
981 log(L_INIT
, "registering network device\n");
982 result
= ieee80211_register_hw(adev
->ieee
);
984 msg
= "acx: failed to register USB network device "
989 acx_proc_register_entries(ieee
);
992 printk("acx: USB module " ACX_RELEASE
" loaded successfully\n");
994 acx_init_task_scheduler(adev
);
997 great_inquisitor(adev
);
1000 /* Everything went OK, we are happy now */
1005 printk(msg
, result
);
1009 for (i
= 0; i
< ACX_RX_URB_CNT
; i
++)
1010 usb_free_urb(adev
->usb_rx
[i
].urb
);
1011 kfree(adev
->usb_rx
);
1014 for (i
= 0; i
< ACX_TX_URB_CNT
; i
++)
1015 usb_free_urb(adev
->usb_tx
[i
].urb
);
1016 kfree(adev
->usb_tx
);
1018 ieee80211_free_hw(ieee
);
1025 /* no device we could handle, return error. */
1034 /***********************************************************************
1035 ** acxusb_e_disconnect()
1037 ** This function is invoked whenever the user pulls the plug from the USB
1038 ** device or the module is removed from the kernel. In these cases, the
1039 ** network devices have to be taken down and all allocated memory has
1042 void acxusb_e_disconnect(struct usb_interface
*intf
)
1044 unsigned long flags
;
1046 acx_device_t
*adev
= usb_get_intfdata(intf
);
1050 /* No WLAN device... no sense */
1054 /* Unregister network device
1056 * If the interface is up, unregister_netdev() will take
1057 * care of calling our close() function, which takes
1058 * care of unlinking the urbs, sending the device to
1060 * This can't be called with sem or lock held because
1061 * _close() will try to grab it as well if it's called,
1062 * deadlocking the machine.
1064 acx_proc_unregister_entries(adev
->ieee
);
1065 ieee80211_unregister_hw(adev
->ieee
);
1068 acx_lock(adev
, flags
);
1069 /* This device exists no more */
1070 usb_set_intfdata(intf
, NULL
);
1073 * Here we only free them. _close() took care of
1076 for (i
= 0; i
< ACX_RX_URB_CNT
; ++i
) {
1077 usb_free_urb(adev
->usb_rx
[i
].urb
);
1079 for (i
= 0; i
< ACX_TX_URB_CNT
; ++i
) {
1080 usb_free_urb(adev
->usb_tx
[i
].urb
);
1083 /* Freeing containers */
1084 kfree(adev
->usb_rx
);
1085 kfree(adev
->usb_tx
);
1087 acx_unlock(adev
, flags
);
1088 acx_sem_unlock(adev
);
1090 ieee80211_free_hw(adev
->ieee
);
1095 /***********************************************************************
1097 ** This function is called when the user sets up the network interface.
1098 ** It initializes a management timer, sets up the USB card and starts
1099 ** the network tx queue and USB receive.
1101 int acxusb_e_open(struct ieee80211_hw
*hw
)
1103 acx_device_t
*adev
= ieee2adev(hw
);
1104 unsigned long flags
;
1111 /* put the ACX100 out of sleep mode */
1112 // acx_s_issue_cmd(adev, ACX1xx_CMD_WAKE, NULL, 0);
1114 init_timer(&adev
->mgmt_timer
);
1115 adev
->mgmt_timer
.function
= acx_i_timer
;
1116 adev
->mgmt_timer
.data
= (unsigned long)adev
;
1118 /* acx_s_start needs it */
1119 SET_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
1122 /* don't acx_start_queue() here, we need to associate first */
1124 acx_lock(adev
, flags
);
1125 for (i
= 0; i
< ACX_RX_URB_CNT
; i
++) {
1126 adev
->usb_rx
[i
].urb
->status
= 0;
1129 acxusb_l_poll_rx(adev
, &adev
->usb_rx
[0]);
1131 acx_setup_modes(adev
);
1132 ieee80211_start_queues(adev
->ieee
);
1133 acx_unlock(adev
, flags
);
1135 acx_sem_unlock(adev
);
1142 /***********************************************************************
1145 ** This function stops the network functionality of the interface (invoked
1146 ** when the user calls ifconfig <wlan> down). The tx queue is halted and
1147 ** the device is marked as down. In case there were any pending USB bulk
1148 ** transfers, these are unlinked (asynchronously). The module in-use count
1149 ** is also decreased in this function.
1151 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
1152 int acxusb_e_close(struct ieee80211_hw
*hw
)
1154 static void acxusb_e_close(struct ieee80211_hw
*hw
)
1157 acx_device_t
*adev
= ieee2adev(hw
);
1158 unsigned long flags
;
1164 if (adev
->dev_state_mask
& ACX_STATE_IFACE_UP
)
1166 // acxusb_e_down(adev);
1167 CLEAR_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
1170 /* Code below is remarkably similar to acxpci_s_down(). Maybe we can merge them? */
1172 acx_free_modes(adev
);
1174 /* Make sure we don't get any more rx requests */
1175 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_RX
, NULL
, 0);
1176 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_TX
, NULL
, 0);
1179 * We must do FLUSH *without* holding sem to avoid a deadlock.
1180 * See pci.c:acxpci_s_down() for deails.
1182 acx_sem_unlock(adev
);
1183 flush_scheduled_work();
1186 /* Power down the device */
1187 acx_s_issue_cmd(adev
, ACX1xx_CMD_SLEEP
, NULL
, 0);
1189 /* Stop the transmit queue, mark the device as DOWN */
1190 acx_lock(adev
, flags
);
1191 // acx_stop_queue(ndev, "on ifdown");
1192 // acx_set_status(adev, ACX_STATUS_0_STOPPED);
1193 /* stop pending rx/tx urb transfers */
1194 for (i
= 0; i
< ACX_TX_URB_CNT
; i
++) {
1195 acxusb_unlink_urb(adev
->usb_tx
[i
].urb
);
1196 adev
->usb_tx
[i
].busy
= 0;
1198 for (i
= 0; i
< ACX_RX_URB_CNT
; i
++) {
1199 acxusb_unlink_urb(adev
->usb_rx
[i
].urb
);
1200 adev
->usb_rx
[i
].busy
= 0;
1202 adev
->tx_free
= ACX_TX_URB_CNT
;
1203 acx_unlock(adev
, flags
);
1205 /* Must do this outside of lock */
1206 del_timer_sync(&adev
->mgmt_timer
);
1208 acx_sem_unlock(adev
);
1211 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
1217 /***********************************************************************
1219 ** This function (re)initiates a bulk-in USB transfer on a given urb
1221 void acxusb_l_poll_rx(acx_device_t
* adev
, usb_rx_t
* rx
)
1223 struct usb_device
*usbdev
;
1226 unsigned int inpipe
;
1231 usbdev
= adev
->usbdev
;
1233 rxnum
= rx
- adev
->usb_rx
;
1235 inpipe
= usb_rcvbulkpipe(usbdev
, adev
->bulkinep
);
1236 if (unlikely(rxurb
->status
== -EINPROGRESS
)) {
1238 "acx: error, rx triggered while rx urb in progress\n");
1239 /* FIXME: this is nasty, receive is being cancelled by this code
1240 * on the other hand, this should not happen anyway...
1242 usb_unlink_urb(rxurb
);
1243 } else if (unlikely(rxurb
->status
== -ECONNRESET
)) {
1244 log(L_USBRXTX
, "acx_usb: _poll_rx: connection reset\n");
1247 rxurb
->actual_length
= 0;
1248 usb_fill_bulk_urb(rxurb
, usbdev
, inpipe
, &rx
->bulkin
, /* dataptr */
1249 RXBUFSIZE
, /* size */
1250 acxusb_i_complete_rx
, /* handler */
1251 rx
/* handler param */
1253 rxurb
->transfer_flags
= URB_ASYNC_UNLINK
;
1255 /* ATOMIC: we may be called from complete_rx() usb callback */
1256 errcode
= usb_submit_urb(rxurb
, GFP_ATOMIC
);
1257 /* FIXME: evaluate the error code! */
1258 log(L_USBRXTX
, "SUBMIT RX (%d) inpipe=0x%X size=%d errcode=%d\n",
1259 rxnum
, inpipe
, (int)RXBUFSIZE
, errcode
);
1265 /***********************************************************************
1266 ** acxusb_i_complete_rx()
1268 ** urb -> pointer to USB request block
1269 ** regs -> pointer to register-buffer for syscalls (see asm/ptrace.h)
1271 ** This function is invoked by USB subsystem whenever a bulk receive
1273 ** The received data is then committed to the network stack and the next
1274 ** USB receive is triggered.
1276 void acxusb_i_complete_rx(struct urb
*urb
)
1282 unsigned long flags
;
1283 int size
, remsize
, packetsize
, rxnum
;
1287 BUG_ON(!urb
->context
);
1289 rx
= (usb_rx_t
*) urb
->context
;
1292 acx_lock(adev
, flags
);
1295 * Happens on disconnect or close. Don't play with the urb.
1296 * Don't resubmit it. It will get unlinked by close()
1298 if (unlikely(!(adev
->dev_state_mask
& ACX_STATE_IFACE_UP
))) {
1299 log(L_USBRXTX
, "rx: device is down, not doing anything\n");
1303 inbuf
= &rx
->bulkin
;
1304 size
= urb
->actual_length
;
1306 rxnum
= rx
- adev
->usb_rx
;
1308 log(L_USBRXTX
, "RETURN RX (%d) status=%d size=%d\n",
1309 rxnum
, urb
->status
, size
);
1311 /* Send the URB that's waiting. */
1312 log(L_USBRXTX
, "rxnum=%d, sending=%d\n", rxnum
, rxnum
^ 1);
1313 acxusb_l_poll_rx(adev
, &adev
->usb_rx
[rxnum
^ 1]);
1315 if (unlikely(size
> sizeof(rxbuffer_t
)))
1316 printk("acx_usb: rx too large: %d, please report\n", size
);
1318 /* check if the transfer was aborted */
1319 switch (urb
->status
) {
1320 case 0: /* No error */
1323 printk(KERN_ERR
"acx: rx data overrun\n");
1324 adev
->rxtruncsize
= 0; /* Not valid anymore. */
1327 adev
->rxtruncsize
= 0;
1329 case -ESHUTDOWN
: /* rmmod */
1330 adev
->rxtruncsize
= 0;
1333 adev
->rxtruncsize
= 0;
1334 adev
->stats
.rx_errors
++;
1335 printk("acx: rx error (urb status=%d)\n", urb
->status
);
1339 if (unlikely(!size
))
1340 printk("acx: warning, encountered zerolength rx packet\n");
1342 if (urb
->transfer_buffer
!= inbuf
)
1345 /* check if previous frame was truncated
1346 ** FIXME: this code can only handle truncation
1347 ** of consecutive packets!
1350 if (adev
->rxtruncsize
) {
1353 ptr
= &adev
->rxtruncbuf
;
1354 packetsize
= RXBUF_BYTES_USED(ptr
);
1355 if (acx_debug
& L_USBRXTX
) {
1356 printk("handling truncated frame (truncsize=%d size=%d "
1357 "packetsize(from trunc)=%d)\n",
1358 adev
->rxtruncsize
, size
, packetsize
);
1359 acx_dump_bytes(ptr
, RXBUF_HDRSIZE
);
1360 acx_dump_bytes(inbuf
, RXBUF_HDRSIZE
);
1363 /* bytes needed for rxtruncbuf completion: */
1364 tail_size
= packetsize
- adev
->rxtruncsize
;
1366 if (size
< tail_size
) {
1367 /* there is not enough data to complete this packet,
1368 ** simply append the stuff to the truncation buffer
1370 memcpy(((char *)ptr
) + adev
->rxtruncsize
, inbuf
, size
);
1371 adev
->rxtruncsize
+= size
;
1374 /* ok, this data completes the previously
1375 ** truncated packet. copy it into a descriptor
1376 ** and give it to the rest of the stack */
1378 /* append tail to previously truncated part
1379 ** NB: adev->rxtruncbuf (pointed to by ptr) can't
1380 ** overflow because this is already checked before
1381 ** truncation buffer was filled. See below,
1382 ** "if (packetsize > sizeof(rxbuffer_t))..." code */
1383 memcpy(((char *)ptr
) + adev
->rxtruncsize
, inbuf
,
1386 if (acx_debug
& L_USBRXTX
) {
1387 printk("full trailing packet + 12 bytes:\n");
1388 acx_dump_bytes(inbuf
,
1389 tail_size
+ RXBUF_HDRSIZE
);
1391 acx_l_process_rxbuf(adev
, ptr
);
1392 adev
->rxtruncsize
= 0;
1393 ptr
= (rxbuffer_t
*) (((char *)inbuf
) + tail_size
);
1394 remsize
-= tail_size
;
1396 log(L_USBRXTX
, "post-merge size=%d remsize=%d\n",
1400 /* size = USB data block size
1401 ** remsize = unprocessed USB bytes left
1402 ** ptr = current pos in USB data block
1405 if (remsize
< RXBUF_HDRSIZE
) {
1406 printk("acx: truncated rx header (%d bytes)!\n",
1409 acx_dump_bytes(ptr
, remsize
);
1413 packetsize
= RXBUF_BYTES_USED(ptr
);
1414 log(L_USBRXTX
, "packet with packetsize=%d\n", packetsize
);
1416 if (RXBUF_IS_TXSTAT(ptr
)) {
1417 /* do rate handling */
1418 usb_txstatus_t
*stat
= (void *)ptr
;
1420 log(L_USBRXTX
, "tx: stat: mac_cnt_rcvd:%04X "
1421 "queue_index:%02X mac_status:%02X hostdata:%08X "
1422 "rate:%u ack_failures:%02X rts_failures:%02X "
1425 stat
->queue_index
, stat
->mac_status
, stat
->hostdata
,
1426 stat
->rate
, stat
->ack_failures
, stat
->rts_failures
,
1429 if (adev->rate_auto && client_no < VEC_SIZE(adev->sta_list)) {
1430 client_t *clt = &adev->sta_list[client_no];
1431 u16 cur = stat->hostdata >> 16;
1433 if (clt && clt->rate_cur == cur) {
1434 acx_l_handle_txrate_auto(adev, clt,
1435 cur, // intended rate
1436 stat->rate, 0, // actually used rate
1437 stat->mac_status, // error?
1438 ACX_TX_URB_CNT - adev->tx_free);
1444 if (packetsize
> sizeof(rxbuffer_t
)) {
1445 printk("acx: packet exceeds max wlan "
1446 "frame size (%d > %d). size=%d\n",
1447 packetsize
, (int)sizeof(rxbuffer_t
), size
);
1449 acx_dump_bytes(ptr
, 16);
1450 /* FIXME: put some real error-handling in here! */
1454 if (packetsize
> remsize
) {
1455 /* frame truncation handling */
1456 if (acx_debug
& L_USBRXTX
) {
1457 printk("need to truncate packet, "
1458 "packetsize=%d remsize=%d "
1460 packetsize
, remsize
, size
);
1461 acx_dump_bytes(ptr
, RXBUF_HDRSIZE
);
1463 memcpy(&adev
->rxtruncbuf
, ptr
, remsize
);
1464 adev
->rxtruncsize
= remsize
;
1468 /* packetsize <= remsize */
1469 /* now handle the received data */
1470 acx_l_process_rxbuf(adev
, ptr
);
1472 ptr
= (rxbuffer_t
*) (((char *)ptr
) + packetsize
);
1473 remsize
-= packetsize
;
1474 if ((acx_debug
& L_USBRXTX
) && remsize
) {
1475 printk("more than one packet in buffer, "
1476 "second packet hdr:");
1477 acx_dump_bytes(ptr
, RXBUF_HDRSIZE
);
1482 acx_unlock(adev
, flags
);
1488 /***********************************************************************
1489 ** acxusb_i_complete_tx()
1491 ** urb -> pointer to USB request block
1492 ** regs -> pointer to register-buffer for syscalls (see asm/ptrace.h)
1494 ** This function is invoked upon termination of a USB transfer.
1496 void acxusb_i_complete_tx(struct urb
*urb
)
1500 unsigned long flags
;
1505 BUG_ON(!urb
->context
);
1507 tx
= (usb_tx_t
*) urb
->context
;
1510 txnum
= tx
- adev
->usb_tx
;
1512 acx_lock(adev
, flags
);
1515 * If the iface isn't up, we don't have any right
1516 * to play with them. The urb may get unlinked.
1518 if (unlikely(!(adev
->dev_state_mask
& ACX_STATE_IFACE_UP
))) {
1519 log(L_USBRXTX
, "tx: device is down, not doing anything\n");
1523 log(L_USBRXTX
, "RETURN TX (%d): status=%d size=%d\n",
1524 txnum
, urb
->status
, urb
->actual_length
);
1526 /* handle USB transfer errors */
1527 switch (urb
->status
) {
1528 case 0: /* No error */
1536 /* FIXME: real error-handling code here please */
1538 printk(KERN_ERR
"acx: tx error, urb status=%d\n", urb
->status
);
1539 /* FIXME: real error-handling code here please */
1542 /* free the URB and check for more data */
1545 if ((adev
->tx_free
>= TX_START_QUEUE
)
1546 && (adev
->status
== ACX_STATUS_4_ASSOCIATED
)
1547 /* && (acx_queue_stopped(adev->ndev)*/) {
1548 log(L_BUF
, "tx: wake queue (%u free txbufs)\n", adev
->tx_free
);
1549 /* acx_wake_queue(adev->ndev, NULL); */
1553 acx_unlock(adev
, flags
);
1559 /***************************************************************
1560 ** acxusb_l_alloc_tx
1561 ** Actually returns a usb_tx_t* ptr
1563 tx_t
*acxusb_l_alloc_tx(acx_device_t
* adev
)
1570 head
= adev
->tx_head
;
1572 head
= (head
+ 1) % ACX_TX_URB_CNT
;
1573 if (!adev
->usb_tx
[head
].busy
) {
1574 log(L_USBRXTX
, "allocated tx %d\n", head
);
1575 tx
= &adev
->usb_tx
[head
];
1578 /* Keep a few free descs between head and tail of tx ring.
1579 ** It is not absolutely needed, just feels safer */
1580 if (adev
->tx_free
< TX_STOP_QUEUE
) {
1581 log(L_BUF
, "tx: stop queue "
1582 "(%u free txbufs)\n", adev
->tx_free
);
1583 /* acx_stop_queue(adev->ndev, NULL); */
1587 } while (likely(head
!= adev
->tx_head
));
1589 printk_ratelimited("acx: tx buffers full\n");
1591 adev
->tx_head
= head
;
1597 /***************************************************************
1598 ** Used if alloc_tx()'ed buffer needs to be cancelled without doing tx
1600 void acxusb_l_dealloc_tx(tx_t
* tx_opaque
)
1602 usb_tx_t
*tx
= (usb_tx_t
*) tx_opaque
;
1607 /***************************************************************
1609 void *acxusb_l_get_txbuf(acx_device_t
* adev
, tx_t
* tx_opaque
)
1611 usb_tx_t
*tx
= (usb_tx_t
*) tx_opaque
;
1612 return &tx
->bulkout
.data
;
1616 /***************************************************************
1619 ** Can be called from IRQ (rx -> (AP bridging or mgmt response) -> tx).
1620 ** Can be called from acx_i_start_xmit (data frames from net core).
1622 void acxusb_l_tx_data(acx_device_t
* adev
, tx_t
* tx_opaque
, int wlanpkt_len
, struct ieee80211_tx_control
*ctl
,
1623 struct sk_buff
* skb
)
1625 struct usb_device
*usbdev
;
1628 usb_txbuffer_t
*txbuf
;
1630 struct ieee80211_hdr
*whdr
;
1631 unsigned int outpipe
;
1636 tx
= ((usb_tx_t
*) tx_opaque
);
1638 txbuf
= &tx
->bulkout
;
1639 whdr
= (struct ieee80211_hdr
*) txbuf
->data
;
1640 txnum
= tx
- adev
->usb_tx
;
1642 log(L_DEBUG
, "using buf#%d free=%d len=%d\n",
1643 txnum
, adev
->tx_free
, wlanpkt_len
);
1645 switch (adev->mode) {
1646 case ACX_MODE_0_ADHOC:
1648 clt = acx_l_sta_list_get(adev, whdr->a1);
1650 case ACX_MODE_2_STA:
1651 // clt = adev->ap_client;
1657 if (unlikely(clt && !clt->rate_cur)) {
1658 printk("acx: driver bug! bad ratemask\n");
1663 /* fill the USB transfer header */
1664 txbuf
->desc
= cpu_to_le16(USB_TXBUF_TXDESC
);
1665 txbuf
->mpdu_len
= cpu_to_le16(wlanpkt_len
);
1666 txbuf
->queue_index
= 1;
1667 txbuf
->rate
= ctl
->tx_rate
; //clt->rate_100;
1668 // FIXME(); //This used to have | (clt - adev->ap_client)
1669 txbuf
->hostdata
= (ctl
->tx_rate
<< 16);
1670 txbuf
->ctrl1
= DESC_CTL_FIRSTFRAG
;
1671 if (1 == adev
->preamble_cur
)
1672 SET_BIT(txbuf
->ctrl1
, DESC_CTL_SHORT_PREAMBLE
);
1674 txbuf
->data_len
= cpu_to_le16(wlanpkt_len
);
1676 if (unlikely(acx_debug
& L_DATA
)) {
1677 printk("dump of bulk out urb:\n");
1678 acx_dump_bytes(txbuf
, wlanpkt_len
+ USB_TXBUF_HDRSIZE
);
1681 if (unlikely(txurb
->status
== -EINPROGRESS
)) {
1683 ("acx: trying to submit tx urb while already in progress\n");
1686 /* now schedule the USB transfer */
1687 usbdev
= adev
->usbdev
;
1688 outpipe
= usb_sndbulkpipe(usbdev
, adev
->bulkoutep
);
1690 usb_fill_bulk_urb(txurb
, usbdev
, outpipe
, txbuf
, /* dataptr */
1691 wlanpkt_len
+ USB_TXBUF_HDRSIZE
, /* size */
1692 acxusb_i_complete_tx
, /* handler */
1693 tx
/* handler param */
1696 txurb
->transfer_flags
= URB_ASYNC_UNLINK
| URB_ZERO_PACKET
;
1697 ucode
= usb_submit_urb(txurb
, GFP_ATOMIC
);
1698 log(L_USBRXTX
, "SUBMIT TX (%d): outpipe=0x%X buf=%p txsize=%d "
1699 "rate=%u errcode=%d\n", txnum
, outpipe
, txbuf
,
1700 wlanpkt_len
+ USB_TXBUF_HDRSIZE
, txbuf
->rate
, ucode
);
1702 if (unlikely(ucode
)) {
1703 printk(KERN_ERR
"acx: submit_urb() error=%d txsize=%d\n",
1704 ucode
, wlanpkt_len
+ USB_TXBUF_HDRSIZE
);
1706 /* on error, just mark the frame as done and update
1709 adev
->stats
.tx_errors
++;
1712 /* needed? if (adev->tx_free > TX_START_QUEUE) acx_wake_queue(...) */
1718 /***********************************************************************
1719 static void acxusb_i_set_rx_mode(struct net_device *ndev)
1725 /***********************************************************************
1727 #ifdef HAVE_TX_TIMEOUT
1729 void acxusb_i_tx_timeout(struct net_device *ndev)
1731 acx_device_t *adev = ndev2adev(ndev);
1732 unsigned long flags;
1737 acx_lock(adev, flags);
1738 */ /* unlink the URBs */
1739 /* for (i = 0; i < ACX_TX_URB_CNT; i++) {
1740 acxusb_unlink_urb(adev->usb_tx[i].urb);
1741 adev->usb_tx[i].busy = 0;
1743 adev->tx_free = ACX_TX_URB_CNT;
1744 */ /* TODO: stats update */
1745 /* acx_unlock(adev, flags);
1753 /***********************************************************************
1756 ** This function is invoked upon loading of the kernel module.
1757 ** It registers itself at the kernel's USB subsystem.
1759 ** Returns: Errorcode on failure, 0 on success
1761 int __init
acxusb_e_init_module(void)
1763 log(L_INIT
, "USB module " ACX_RELEASE
" initialized, "
1764 "probing for devices...\n");
1765 return usb_register(&acxusb_driver
);
1770 /***********************************************************************
1773 ** This function is invoked as last step of the module unloading. It simply
1774 ** deregisters this module at the kernel's USB subsystem.
1776 void __exit
acxusb_e_cleanup_module(void)
1778 usb_deregister(&acxusb_driver
);
1779 log(L_INIT
, "USB module " ACX_RELEASE
" unloaded\n");
1783 /***********************************************************************
1789 static void dump_device(struct usb_device
*usbdev
)
1792 struct usb_config_descriptor
*cd
;
1794 printk("acx device dump:\n");
1795 printk(" devnum: %d\n", usbdev
->devnum
);
1796 printk(" speed: %d\n", usbdev
->speed
);
1797 printk(" tt: 0x%X\n", (unsigned int)(usbdev
->tt
));
1798 printk(" ttport: %d\n", (unsigned int)(usbdev
->ttport
));
1799 printk(" toggle[0]: 0x%X toggle[1]: 0x%X\n",
1800 (unsigned int)(usbdev
->toggle
[0]),
1801 (unsigned int)(usbdev
->toggle
[1]));
1802 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
1803 /* This saw a change after 2.6.10 */
1804 printk(" ep_in wMaxPacketSize: ");
1805 for (i
= 0; i
< 16; ++i
)
1806 if (usbdev
->ep_in
[i
] != NULL
)
1808 usbdev
->ep_in
[i
]->desc
.wMaxPacketSize
);
1810 printk(" ep_out wMaxPacketSize: ");
1811 for (i
= 0; i
< ARRAY_SIZE(usbdev
->ep_out
); ++i
)
1812 if (usbdev
->ep_out
[i
] != NULL
)
1814 usbdev
->ep_out
[i
]->desc
.wMaxPacketSize
);
1817 printk(" epmaxpacketin: ");
1818 for (i
= 0; i
< 16; i
++)
1819 printk("%d ", usbdev
->epmaxpacketin
[i
]);
1821 printk(" epmaxpacketout: ");
1822 for (i
= 0; i
< 16; i
++)
1823 printk("%d ", usbdev
->epmaxpacketout
[i
]);
1826 printk(" parent: 0x%X\n", (unsigned int)usbdev
->parent
);
1827 printk(" bus: 0x%X\n", (unsigned int)usbdev
->bus
);
1829 printk(" configs: ");
1830 for (i
= 0; i
< usbdev
->descriptor
.bNumConfigurations
; i
++)
1831 printk("0x%X ", usbdev
->config
[i
]);
1834 printk(" actconfig: %p\n", usbdev
->actconfig
);
1835 dump_device_descriptor(&usbdev
->descriptor
);
1837 cd
= &usbdev
->config
->desc
;
1838 dump_config_descriptor(cd
);
1842 /***********************************************************************
1844 static void dump_config_descriptor(struct usb_config_descriptor
*cd
)
1846 printk("Configuration Descriptor:\n");
1851 printk(" bLength: %d (0x%X)\n", cd
->bLength
, cd
->bLength
);
1852 printk(" bDescriptorType: %d (0x%X)\n", cd
->bDescriptorType
,
1853 cd
->bDescriptorType
);
1854 printk(" bNumInterfaces: %d (0x%X)\n", cd
->bNumInterfaces
,
1855 cd
->bNumInterfaces
);
1856 printk(" bConfigurationValue: %d (0x%X)\n", cd
->bConfigurationValue
,
1857 cd
->bConfigurationValue
);
1858 printk(" iConfiguration: %d (0x%X)\n", cd
->iConfiguration
,
1859 cd
->iConfiguration
);
1860 printk(" bmAttributes: %d (0x%X)\n", cd
->bmAttributes
,
1862 /* printk(" MaxPower: %d (0x%X)\n", cd->bMaxPower, cd->bMaxPower); */
1866 static void dump_device_descriptor(struct usb_device_descriptor
*dd
)
1868 printk("Device Descriptor:\n");
1873 printk(" bLength: %d (0x%X)\n", dd
->bLength
, dd
->bLength
);
1874 printk(" bDescriptortype: %d (0x%X)\n", dd
->bDescriptorType
,
1875 dd
->bDescriptorType
);
1876 printk(" bcdUSB: %d (0x%X)\n", dd
->bcdUSB
, dd
->bcdUSB
);
1877 printk(" bDeviceClass: %d (0x%X)\n", dd
->bDeviceClass
,
1879 printk(" bDeviceSubClass: %d (0x%X)\n", dd
->bDeviceSubClass
,
1880 dd
->bDeviceSubClass
);
1881 printk(" bDeviceProtocol: %d (0x%X)\n", dd
->bDeviceProtocol
,
1882 dd
->bDeviceProtocol
);
1883 printk(" bMaxPacketSize0: %d (0x%X)\n", dd
->bMaxPacketSize0
,
1884 dd
->bMaxPacketSize0
);
1885 printk(" idVendor: %d (0x%X)\n", dd
->idVendor
, dd
->idVendor
);
1886 printk(" idProduct: %d (0x%X)\n", dd
->idProduct
, dd
->idProduct
);
1887 printk(" bcdDevice: %d (0x%X)\n", dd
->bcdDevice
, dd
->bcdDevice
);
1888 printk(" iManufacturer: %d (0x%X)\n", dd
->iManufacturer
,
1890 printk(" iProduct: %d (0x%X)\n", dd
->iProduct
, dd
->iProduct
);
1891 printk(" iSerialNumber: %d (0x%X)\n", dd
->iSerialNumber
,
1893 printk(" bNumConfigurations: %d (0x%X)\n", dd
->bNumConfigurations
,
1894 dd
->bNumConfigurations
);
1898 #endif /* ACX_DEBUG */