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 static int acxusb_e_close(struct ieee80211_hw
*);
101 //static void acxusb_i_set_rx_mode(struct net_device *);
102 static int acxusb_boot(struct usb_device
*, int is_tnetw1450
, int *radio_type
);
104 static void acxusb_l_poll_rx(acx_device_t
* adev
, usb_rx_t
* rx
);
106 /*static void acxusb_i_tx_timeout(struct net_device *);*/
108 /* static void dump_device(struct usb_device *); */
109 /* static void dump_device_descriptor(struct usb_device_descriptor *); */
110 /* static void dump_config_descriptor(struct usb_config_descriptor *); */
112 /***********************************************************************
115 #define TXBUFSIZE sizeof(usb_txbuffer_t)
117 * Now, this is just plain lying, but the device insists in giving us
118 * huge packets. We supply extra space after rxbuffer. Need to understand
121 #define RXBUFSIZE (sizeof(rxbuffer_t) + \
122 (sizeof(usb_rx_t) - sizeof(struct usb_rx_plain)))
124 static const struct usb_device_id acxusb_ids
[] = {
125 {USB_DEVICE(ACX100_VENDOR_ID
, ACX100_PRODUCT_ID_BOOTED
)},
126 {USB_DEVICE(ACX100_VENDOR_ID
, ACX100_PRODUCT_ID_UNBOOTED
)},
127 {USB_DEVICE(VENDOR_ID_DLINK
, PRODUCT_ID_WUG2400
)},
128 {USB_DEVICE(VENDOR_ID_AVM_GMBH
, PRODUCT_ID_AVM_WLAN_USB
)},
129 {USB_DEVICE(VENDOR_ID_AVM_GMBH
, PRODUCT_ID_AVM_WLAN_USB_si
)},
130 {USB_DEVICE(VENDOR_ID_ZCOM
, PRODUCT_ID_ZCOM_XG750
)},
131 {USB_DEVICE(VENDOR_ID_TI
, PRODUCT_ID_TI_UNKNOWN
)},
135 MODULE_DEVICE_TABLE(usb
, acxusb_ids
);
137 /* USB driver data structure as required by the kernel's USB core */
138 static struct usb_driver
141 .probe
= acxusb_e_probe
,
142 .disconnect
= acxusb_e_disconnect
,
143 .id_table
= acxusb_ids
146 void acxusb_put_devname(acx_device_t
*adev
, struct ethtool_drvinfo
*info
)
149 usb_make_path(adev
->usbdev
, info
->bus_info
, sizeof info
->bus_info
);
151 /***********************************************************************
155 ** When the function is usb_kill_urb, the urb lifecycle is stopped. This
156 ** function is usually used when the device is disconnected from the system,
157 ** in the disconnect callback. For some drivers, the usb_unlink_urb function
158 ** should be used to tell the USB core to stop an urb. This function does not
159 ** wait for the urb to be fully stopped before returning to the caller.
160 ** This is useful for stoppingthe urb while in an interrupt handler or when
161 ** a spinlock is held, as waiting for a urb to fully stop requires the ability
162 ** for the USB core to put the calling process to sleep. This function requires
163 ** that the URB_ASYNC_UNLINK flag value be set in the urb that is being asked
164 ** to be stopped in order to work properly.
166 ** (URB_ASYNC_UNLINK is obsolete, usb_unlink_urb will always be
167 ** asynchronous while usb_kill_urb is synchronous and should be called
168 ** directly (drivers/usb/core/urb.c))
170 ** In light of this, timeout is just for paranoid reasons...
172 ** Actually, it's useful for debugging. If we reach timeout, we're doing
173 ** something wrong with the urbs.
175 static void acxusb_unlink_urb(struct urb
*urb
)
180 if (urb
->status
== -EINPROGRESS
) {
184 while (--timeout
&& urb
->status
== -EINPROGRESS
) {
188 printk(KERN_ERR
"acx_usb: urb unlink timeout!\n");
194 /***********************************************************************
195 ** EEPROM and PHY read/write helpers
197 /***********************************************************************
198 ** acxusb_s_read_phy_reg
200 int acxusb_s_read_phy_reg(acx_device_t
* adev
, u32 reg
, u8
* charbuf
)
202 /* mem_read_write_t mem; */
206 printk("%s doesn't seem to work yet, disabled.\n", __func__
);
209 mem.addr = cpu_to_le16(reg);
210 mem.type = cpu_to_le16(0x82);
211 mem.len = cpu_to_le32(4);
212 acx_s_issue_cmd(adev, ACX1xx_CMD_MEM_READ, &mem, sizeof(mem));
214 log(L_DEBUG, "read radio PHY[0x%04X]=0x%02X\n", reg, *charbuf);
222 /***********************************************************************
224 int acxusb_s_write_phy_reg(acx_device_t
* adev
, u32 reg
, u8 value
)
226 mem_read_write_t mem
;
230 mem
.addr
= cpu_to_le16(reg
);
231 mem
.type
= cpu_to_le16(0x82);
232 mem
.len
= cpu_to_le32(4);
234 acx_s_issue_cmd(adev
, ACX1xx_CMD_MEM_WRITE
, &mem
, sizeof(mem
));
235 log(L_DEBUG
, "write radio PHY[0x%04X]=0x%02X\n", reg
, value
);
242 /***********************************************************************
243 ** acxusb_s_issue_cmd_timeo
244 ** Excecutes a command in the command mailbox
246 ** buffer = a pointer to the data.
247 ** The data must not include 4 byte command header
250 /* TODO: ideally we shall always know how much we need
251 ** and this shall be 0 */
252 #define BOGUS_SAFETY_PADDING 0x40
255 #define FUNC "issue_cmd"
259 acxusb_s_issue_cmd_timeo(acx_device_t
* adev
,
261 void *buffer
, unsigned buflen
, unsigned timeout
)
265 acxusb_s_issue_cmd_timeo_debug(acx_device_t
* adev
,
269 unsigned timeout
, const char *cmdstr
)
272 /* USB ignores timeout param */
274 struct usb_device
*usbdev
;
281 int acklen
, blocklen
, inpipe
, outpipe
;
287 devname
= wiphy_name(adev
->ieee
->wiphy
);
288 /* no "wlan%%d: ..." please */
289 if (!devname
|| !devname
[0] || devname
[4] == '%')
292 log(L_CTL
, FUNC
"(cmd:%s,buflen:%u,type:0x%04X)\n",
294 buffer
? le16_to_cpu(((acx_ie_generic_t
*) buffer
)->type
) : -1);
296 loc
= kmalloc(buflen
+ 4 + BOGUS_SAFETY_PADDING
, GFP_KERNEL
);
298 printk("%s: " FUNC
"(): no memory for data buffer\n", devname
);
302 /* get context from acx_device */
303 usbdev
= adev
->usbdev
;
305 /* check which kind of command was issued */
306 loc
->cmd
= cpu_to_le16(cmd
);
309 /* NB: buflen == frmlen + 4
311 ** Interrogate: write 8 bytes: (cmd,status,rid,frmlen), then
312 ** read (cmd,status,rid,frmlen,data[frmlen]) back
314 ** Configure: write (cmd,status,rid,frmlen,data[frmlen])
316 ** Possibly bogus special handling of ACX1xx_IE_SCAN_STATUS removed
319 /* now write the parameters of the command if needed */
320 acklen
= buflen
+ 4 + BOGUS_SAFETY_PADDING
;
322 if (buffer
&& buflen
) {
323 /* if it's an INTERROGATE command, just pass the length
324 * of parameters to read, as data */
325 if (cmd
== ACX1xx_CMD_INTERROGATE
) {
329 memcpy(loc
->data
, buffer
, blocklen
);
331 blocklen
+= 4; /* account for cmd,status */
333 /* obtain the I/O pipes */
334 outpipe
= usb_sndctrlpipe(usbdev
, 0);
335 inpipe
= usb_rcvctrlpipe(usbdev
, 0);
336 log(L_CTL
, "ctrl inpipe=0x%X outpipe=0x%X\n", inpipe
, outpipe
);
337 log(L_CTL
, "sending USB control msg (out) (blocklen=%d)\n", blocklen
);
338 if (acx_debug
& L_DATA
)
339 acx_dump_bytes(loc
, blocklen
);
341 result
= usb_control_msg(usbdev
, outpipe
, ACX_USB_REQ_CMD
, /* request */
342 USB_TYPE_VENDOR
| USB_DIR_OUT
, /* requesttype */
347 ACX_USB_CTRL_TIMEOUT
/* timeout in ms */
350 if (result
== -ENODEV
) {
351 log(L_CTL
, "no device present (unplug?)\n");
355 log(L_CTL
, "wrote %d bytes\n", result
);
360 /* check for device acknowledge */
361 log(L_CTL
, "sending USB control msg (in) (acklen=%d)\n", acklen
);
362 loc
->status
= 0; /* delete old status flag -> set to IDLE */
363 /* shall we zero out the rest? */
364 result
= usb_control_msg(usbdev
, inpipe
, ACX_USB_REQ_CMD
, /* request */
365 USB_TYPE_VENDOR
| USB_DIR_IN
, /* requesttype */
370 ACX_USB_CTRL_TIMEOUT
/* timeout in ms */
373 printk("%s: " FUNC
"(): USB read error %d\n", devname
, result
);
376 if (acx_debug
& L_CTL
) {
377 printk("read %d bytes: ", result
);
378 acx_dump_bytes(loc
, result
);
382 check for result==buflen+4? Was seen:
384 interrogate(type:ACX100_IE_DOT11_ED_THRESHOLD,len:4)
385 issue_cmd(cmd:ACX1xx_CMD_INTERROGATE,buflen:8,type:4111)
386 ctrl inpipe=0x80000280 outpipe=0x80000200
387 sending USB control msg (out) (blocklen=8)
388 01 00 00 00 0F 10 04 00
390 sending USB control msg (in) (acklen=12) sizeof(loc->data
391 read 4 bytes <==== MUST BE 12!!
394 cmd_status
= le16_to_cpu(loc
->status
);
395 if (cmd_status
!= 1) {
396 printk("%s: " FUNC
"(): cmd_status is not SUCCESS: %d (%s)\n",
397 devname
, cmd_status
, acx_cmd_status_str(cmd_status
));
398 /* TODO: goto bad; ? */
400 if ((cmd
== ACX1xx_CMD_INTERROGATE
) && buffer
&& buflen
) {
401 memcpy(buffer
, loc
->data
, buflen
);
402 log(L_CTL
, "response frame: cmd=0x%04X status=%d\n",
403 le16_to_cpu(loc
->cmd
), cmd_status
);
410 /* Give enough info so that callers can avoid
411 ** printing their own diagnostic messages */
413 printk("%s: " FUNC
"(cmd:%s) FAILED\n", devname
, cmdstr
);
415 printk("%s: " FUNC
"(cmd:0x%04X) FAILED\n", devname
, cmd
);
424 /***********************************************************************
427 ** usbdev -> Pointer to kernel's usb_device structure
430 ** (int) Errorcode or 0 on success
432 ** This function triggers the loading of the firmware image from harddisk
433 ** and then uploads the firmware to the USB device. After uploading the
434 ** firmware and transmitting the checksum, the device resets and appears
435 ** as a new device on the USB bus (the device we can finally deal with)
438 acxusb_fw_needs_padding(firmware_image_t
*fw_image
, unsigned int usb_maxlen
)
440 unsigned int num_xfers
= ((fw_image
->size
- 1) / usb_maxlen
) + 1;
442 return ((num_xfers
% 2) == 0);
446 acxusb_boot(struct usb_device
*usbdev
, int is_tnetw1450
, int *radio_type
)
448 char filename
[sizeof("tiacx1NNusbcRR")];
450 firmware_image_t
*fw_image
= NULL
;
453 unsigned int blk_len
, inpipe
, outpipe
;
455 u32 img_checksum
, sum
;
462 /* dump_device(usbdev); */
464 usbbuf
= kmalloc(USB_RWMEM_MAXLEN
, GFP_KERNEL
);
467 "acx: no memory for USB transfer buffer (%d bytes)\n",
473 /* Obtain the I/O pipes */
474 outpipe
= usb_sndbulkpipe(usbdev
, 1);
475 inpipe
= usb_rcvbulkpipe(usbdev
, 2);
477 printk(KERN_DEBUG
"wait for device ready\n");
478 for (i
= 0; i
<= 2; i
++) {
479 result
= usb_bulk_msg(usbdev
, inpipe
,
482 &num_processed
, 2000);
484 if ((*(u32
*) & usbbuf
[4] == 0x40000001)
485 && (*(u16
*) & usbbuf
[2] == 0x1)
486 && ((*(u16
*) usbbuf
& 0x3fff) == 0)
487 && ((*(u16
*) usbbuf
& 0xc000) == 0xc000))
494 *radio_type
= usbbuf
[8];
496 /* Obtain the I/O pipes */
497 outpipe
= usb_sndctrlpipe(usbdev
, 0);
498 inpipe
= usb_rcvctrlpipe(usbdev
, 0);
500 /* FIXME: shouldn't be hardcoded */
501 *radio_type
= RADIO_MAXIM_0D
;
504 snprintf(filename
, sizeof(filename
), "tiacx1%02dusbc%02X",
505 is_tnetw1450
* 11, *radio_type
);
507 fw_image
= acx_s_read_fw(&usbdev
->dev
, filename
, &file_size
);
512 log(L_INIT
, "firmware size: %d bytes\n", file_size
);
514 img_checksum
= le32_to_cpu(fw_image
->chksum
);
522 memset(cmdbuf
, 0, 16);
525 acxusb_fw_needs_padding(fw_image
, USB_RWMEM_MAXLEN
);
526 tmplen
= need_padding
? file_size
- 4 : file_size
- 8;
527 *(u16
*) & cmdbuf
[0] = 0xc000;
528 *(u16
*) & cmdbuf
[2] = 0x000b;
529 *(u32
*) & cmdbuf
[4] = tmplen
;
530 *(u32
*) & cmdbuf
[8] = file_size
- 8;
531 *(u32
*) & cmdbuf
[12] = img_checksum
;
534 usb_bulk_msg(usbdev
, outpipe
, cmdbuf
, 16, &num_processed
,
539 p
= (const u8
*)&fw_image
->size
;
541 /* first calculate checksum for image size part */
542 sum
= p
[0] + p
[1] + p
[2] + p
[3];
545 /* now continue checksum for firmware data part */
546 tmplen
= le32_to_cpu(fw_image
->size
);
547 for (i
= 0; i
< tmplen
/* image size */ ; i
++) {
551 if (sum
!= le32_to_cpu(fw_image
->chksum
)) {
552 printk("acx: FATAL: firmware upload: "
553 "checksums don't match! "
554 "(0x%08x vs. 0x%08x)\n", sum
, fw_image
->chksum
);
559 while (offset
< file_size
) {
560 blk_len
= file_size
- offset
;
561 if (blk_len
> USB_RWMEM_MAXLEN
) {
562 blk_len
= USB_RWMEM_MAXLEN
;
566 "uploading firmware (%d bytes, offset=%d)\n",
568 memcpy(usbbuf
, ((u8
*) fw_image
) + offset
, blk_len
);
571 for (i
= 0; i
< blk_len
; i
+= 4) {
572 *(u32
*) p
= be32_to_cpu(*(u32
*) p
);
577 usb_bulk_msg(usbdev
, outpipe
, usbbuf
, blk_len
,
579 if ((result
< 0) || (num_processed
!= blk_len
))
584 printk(KERN_DEBUG
"send padding\n");
585 memset(usbbuf
, 0, 4);
587 usb_bulk_msg(usbdev
, outpipe
, usbbuf
, 4,
589 if ((result
< 0) || (num_processed
!= 4))
592 printk(KERN_DEBUG
"read firmware upload result\n");
593 memset(cmdbuf
, 0, 20); /* additional memset */
595 usb_bulk_msg(usbdev
, inpipe
, cmdbuf
, 20, &num_processed
,
599 if (*(u32
*) & cmdbuf
[4] == 0x40000003)
601 if (*(u32
*) & cmdbuf
[4])
603 if (*(u16
*) & cmdbuf
[16] != 1)
606 val
= *(u32
*) & cmdbuf
[0];
608 || ((val
& 0xc000) != 0xc000))
611 val
= *(u32
*) & cmdbuf
[8];
614 usb_bulk_msg(usbdev
, inpipe
, cmdbuf
, 20,
615 &num_processed
, 2000);
618 val
= *(u32
*) & cmdbuf
[8];
620 /* yup, no "else" here! */
622 memset(usbbuf
, 0, 4);
624 usb_bulk_msg(usbdev
, outpipe
, usbbuf
, 4,
626 if ((result
< 0) || (!num_processed
))
630 printk("TNETW1450 firmware upload successful!\n");
639 /* now upload the firmware, slice the data into blocks */
641 while (offset
< file_size
) {
642 blk_len
= file_size
- offset
;
643 if (blk_len
> USB_RWMEM_MAXLEN
) {
644 blk_len
= USB_RWMEM_MAXLEN
;
647 "uploading firmware (%d bytes, offset=%d)\n",
649 memcpy(usbbuf
, ((u8
*) fw_image
) + offset
, blk_len
);
650 result
= usb_control_msg(usbdev
, outpipe
, ACX_USB_REQ_UPLOAD_FW
, USB_TYPE_VENDOR
| USB_DIR_OUT
, (file_size
- 8) & 0xffff, /* value */
651 (file_size
- 8) >> 16, /* index */
652 usbbuf
, /* dataptr */
654 3000 /* timeout in ms */
658 printk(KERN_ERR
"acx: error %d during upload "
659 "of firmware, aborting\n", result
);
664 /* finally, send the checksum and reboot the device */
665 /* does this trigger the reboot? */
666 result
= usb_control_msg(usbdev
, outpipe
, ACX_USB_REQ_UPLOAD_FW
, USB_TYPE_VENDOR
| USB_DIR_OUT
, img_checksum
& 0xffff, /* value */
667 img_checksum
>> 16, /* index */
670 3000 /* timeout in ms */
673 printk(KERN_ERR
"acx: error %d during tx of checksum, "
674 "aborting\n", result
);
677 result
= usb_control_msg(usbdev
, inpipe
, ACX_USB_REQ_ACK_CS
, USB_TYPE_VENDOR
| USB_DIR_IN
, img_checksum
& 0xffff, /* value */
678 img_checksum
>> 16, /* index */
679 usbbuf
, /* dataptr */
681 3000 /* timeout in ms */
684 printk(KERN_ERR
"acx: error %d during ACK of checksum, "
685 "aborting\n", result
);
688 if (*usbbuf
!= 0x10) {
689 printk(KERN_ERR
"acx: invalid checksum?\n");
705 /* FIXME: maybe merge it with usual eeprom reading, into common code? */
706 static void acxusb_s_read_eeprom_version(acx_device_t
* adev
)
710 memset(eeprom_ver
, 0, sizeof(eeprom_ver
));
711 acx_s_interrogate(adev
, &eeprom_ver
, ACX1FF_IE_EEPROM_VER
);
713 /* FIXME: which one of those values to take? */
714 adev
->eeprom_version
= eeprom_ver
[5];
719 * temporary helper function to at least fill important cfgopt members with
720 * useful replacement values until we figure out how one manages to fetch
721 * the configoption struct in the USB device case...
723 static int acxusb_s_fill_configoption(acx_device_t
* adev
)
725 adev
->cfgopt_probe_delay
= 200;
726 adev
->cfgopt_dot11CCAModes
= 4;
727 adev
->cfgopt_dot11Diversity
= 1;
728 adev
->cfgopt_dot11ShortPreambleOption
= 1;
729 adev
->cfgopt_dot11PBCCOption
= 1;
730 adev
->cfgopt_dot11ChannelAgility
= 0;
731 adev
->cfgopt_dot11PhyType
= 5;
732 adev
->cfgopt_dot11TempType
= 1;
736 static const struct ieee80211_ops acxusb_hw_ops
= {
737 .tx
= acx_i_start_xmit
,
738 .conf_tx
= acx_net_conf_tx
,
739 .add_interface
= acx_add_interface
,
740 .remove_interface
= acx_remove_interface
,
741 .open
= acxusb_e_open
,
742 .stop
= acxusb_e_close
,
743 .reset
= acx_net_reset
,
744 .config
= acx_net_config
,
745 .config_interface
= acx_config_interface
,
746 .set_multicast_list
= acx_i_set_multicast_list
,
747 .set_key
= acx_net_set_key
,
748 .get_stats
= acx_e_get_stats
,
749 .get_tx_stats
= acx_net_get_tx_stats
,
752 /***********************************************************************
755 ** This function is invoked by the kernel's USB core whenever a new device is
756 ** attached to the system or the module is loaded. It is presented a usb_device
757 ** structure from which information regarding the device is obtained and evaluated.
758 ** In case this driver is able to handle one of the offered devices, it returns
759 ** a non-null pointer to a driver context and thereby claims the device.
764 acxusb_e_probe(struct usb_interface
*intf
, const struct usb_device_id
*devID
)
766 struct usb_device
*usbdev
= interface_to_usbdev(intf
);
767 acx_device_t
*adev
= NULL
;
768 struct usb_config_descriptor
*config
;
769 struct usb_endpoint_descriptor
*epdesc
;
770 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
771 struct usb_host_endpoint
*ep
;
773 struct usb_interface_descriptor
*ifdesc
;
775 int numconfigs
, numfaces
, numep
;
779 /* this one needs to be more precise in case there appears
780 * a TNETW1450 from the same vendor */
781 int is_tnetw1450
= (usbdev
->descriptor
.idVendor
!= ACX100_VENDOR_ID
);
782 struct ieee80211_hw
*ieee
;
787 /* Boot the device (i.e. upload the firmware) */
788 acxusb_boot(usbdev
, is_tnetw1450
, &radio_type
);
790 /* TNETW1450-based cards will continue right away with
791 * the same USB ID after booting */
793 /* First check if this is the "unbooted" hardware */
794 if (usbdev
->descriptor
.idProduct
== ACX100_PRODUCT_ID_UNBOOTED
) {
796 /* Boot the device (i.e. upload the firmware) */
797 acxusb_boot(usbdev
, is_tnetw1450
, &radio_type
);
799 /* DWL-120+ will first boot the firmware,
800 * then later have a *separate* probe() run
801 * since its USB ID will have changed after
803 * Since the first probe() run has no
804 * other purpose than booting the firmware,
805 * simply return immediately.
808 "finished booting, returning from probe()\n");
809 result
= OK
; /* success */
812 if (usbdev
->descriptor
.idProduct
!= ACX100_PRODUCT_ID_BOOTED
)
813 /* device not unbooted, but invalid USB ID!? */
818 /* Ok, so it's our device and it has already booted */
820 /* Allocate memory for a network device */
822 ieee
= ieee80211_alloc_hw(sizeof(*adev
), &acxusb_hw_ops
);
824 msg
= "acx: no memory for ieee80211_dev\n";
829 ieee
->flags
&= ~IEEE80211_HW_RX_INCLUDES_FCS
&
830 ~IEEE80211_HW_MONITOR_DURING_OPER
&
831 ~IEEE80211_HW_WEP_INCLUDE_IV
;
834 /* Register the callbacks for the network device functions */
837 /* Setup private driver context */
839 adev
= ieee2adev(ieee
);
842 adev
->dev_type
= DEVTYPE_USB
;
843 adev
->radio_type
= radio_type
;
845 /* well, actually it's a TNETW1450, but since it
846 * seems to be sufficiently similar to TNETW1130,
847 * I don't want to change large amounts of code now */
848 adev
->chip_type
= CHIPTYPE_ACX111
;
850 adev
->chip_type
= CHIPTYPE_ACX100
;
853 adev
->usbdev
= usbdev
;
854 spin_lock_init(&adev
->lock
); /* initial state: unlocked */
855 mutex_init(&adev
->mutex
);
857 /* Check that this is really the hardware we know about.
858 ** If not sure, at least notify the user that he
859 ** may be in trouble...
861 numconfigs
= (int)usbdev
->descriptor
.bNumConfigurations
;
863 printk("acx: number of configurations is %d, "
864 "this driver only knows how to handle 1, "
865 "be prepared for surprises\n", numconfigs
);
867 config
= &usbdev
->config
->desc
;
868 numfaces
= config
->bNumInterfaces
;
870 printk("acx: number of interfaces is %d, "
871 "this driver only knows how to handle 1, "
872 "be prepared for surprises\n", numfaces
);
874 ifdesc
= &intf
->altsetting
->desc
;
875 numep
= ifdesc
->bNumEndpoints
;
876 log(L_DEBUG
, "# of endpoints: %d\n", numep
);
882 /* obtain information about the endpoint
883 ** addresses, begin with some default values
887 for (i
= 0; i
< numep
; i
++) {
888 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
889 ep
= usbdev
->ep_in
[i
];
894 epdesc
= usb_epnum_to_ep_desc(usbdev
, i
);
898 if (epdesc
->bmAttributes
& USB_ENDPOINT_XFER_BULK
) {
899 if (epdesc
->bEndpointAddress
& 0x80)
901 epdesc
->bEndpointAddress
& 0xF;
904 epdesc
->bEndpointAddress
& 0xF;
908 log(L_DEBUG
, "bulkout ep: 0x%X\n", adev
->bulkoutep
);
909 log(L_DEBUG
, "bulkin ep: 0x%X\n", adev
->bulkinep
);
911 /* already done by memset: adev->rxtruncsize = 0; */
912 log(L_DEBUG
, "TXBUFSIZE=%d RXBUFSIZE=%d\n",
913 (int)TXBUFSIZE
, (int)RXBUFSIZE
);
915 /* Allocate the RX/TX containers. */
916 adev
->usb_tx
= kmalloc(sizeof(usb_tx_t
) * ACX_TX_URB_CNT
, GFP_KERNEL
);
918 msg
= "acx: no memory for tx container";
921 adev
->usb_rx
= kmalloc(sizeof(usb_rx_t
) * ACX_RX_URB_CNT
, GFP_KERNEL
);
923 msg
= "acx: no memory for rx container";
927 /* Setup URBs for bulk-in/out messages */
928 for (i
= 0; i
< ACX_RX_URB_CNT
; i
++) {
929 adev
->usb_rx
[i
].urb
= usb_alloc_urb(0, GFP_KERNEL
);
930 if (!adev
->usb_rx
[i
].urb
) {
931 msg
= "acx: no memory for input URB\n";
934 adev
->usb_rx
[i
].urb
->status
= 0;
935 adev
->usb_rx
[i
].adev
= adev
;
936 adev
->usb_rx
[i
].busy
= 0;
939 for (i
= 0; i
< ACX_TX_URB_CNT
; i
++) {
940 adev
->usb_tx
[i
].urb
= usb_alloc_urb(0, GFP_KERNEL
);
941 if (!adev
->usb_tx
[i
].urb
) {
942 msg
= "acx: no memory for output URB\n";
945 adev
->usb_tx
[i
].urb
->status
= 0;
946 adev
->usb_tx
[i
].adev
= adev
;
947 adev
->usb_tx
[i
].busy
= 0;
949 adev
->tx_free
= ACX_TX_URB_CNT
;
951 usb_set_intfdata(intf
, adev
);
952 SET_IEEE80211_DEV(ieee
, &intf
->dev
);
954 /* TODO: move all of fw cmds to open()? But then we won't know our MAC addr
955 until ifup (it's available via reading ACX1xx_IE_DOT11_STATION_ID)... */
957 /* put acx out of sleep mode and initialize it */
958 acx_s_issue_cmd(adev
, ACX1xx_CMD_WAKE
, NULL
, 0);
960 result
= acx_s_init_mac(adev
);
964 /* TODO: see similar code in pci.c */
965 acxusb_s_read_eeprom_version(adev
);
966 acxusb_s_fill_configoption(adev
);
967 acx_s_set_defaults(adev
);
968 acx_s_get_firmware_version(adev
);
969 acx_display_hardware_details(adev
);
971 /* MAC_COPY(ndev->dev_addr, adev->dev_addr); */
973 /* Register the network device */
974 log(L_INIT
, "registering network device\n");
975 result
= ieee80211_register_hw(adev
->ieee
);
977 msg
= "acx: failed to register USB network device "
982 acx_proc_register_entries(ieee
);
985 printk("acx: USB module " ACX_RELEASE
" loaded successfully\n");
987 acx_init_task_scheduler(adev
);
990 great_inquisitor(adev
);
993 /* Everything went OK, we are happy now */
1002 for (i
= 0; i
< ACX_RX_URB_CNT
; i
++)
1003 usb_free_urb(adev
->usb_rx
[i
].urb
);
1004 kfree(adev
->usb_rx
);
1007 for (i
= 0; i
< ACX_TX_URB_CNT
; i
++)
1008 usb_free_urb(adev
->usb_tx
[i
].urb
);
1009 kfree(adev
->usb_tx
);
1011 ieee80211_free_hw(ieee
);
1018 /* no device we could handle, return error. */
1027 /***********************************************************************
1028 ** acxusb_e_disconnect()
1030 ** This function is invoked whenever the user pulls the plug from the USB
1031 ** device or the module is removed from the kernel. In these cases, the
1032 ** network devices have to be taken down and all allocated memory has
1035 void acxusb_e_disconnect(struct usb_interface
*intf
)
1037 unsigned long flags
;
1039 acx_device_t
*adev
= usb_get_intfdata(intf
);
1043 /* No WLAN device... no sense */
1047 /* Unregister network device
1049 * If the interface is up, unregister_netdev() will take
1050 * care of calling our close() function, which takes
1051 * care of unlinking the urbs, sending the device to
1053 * This can't be called with sem or lock held because
1054 * _close() will try to grab it as well if it's called,
1055 * deadlocking the machine.
1057 acx_proc_unregister_entries(adev
->ieee
);
1058 ieee80211_unregister_hw(adev
->ieee
);
1061 acx_lock(adev
, flags
);
1062 /* This device exists no more */
1063 usb_set_intfdata(intf
, NULL
);
1066 * Here we only free them. _close() took care of
1069 for (i
= 0; i
< ACX_RX_URB_CNT
; ++i
) {
1070 usb_free_urb(adev
->usb_rx
[i
].urb
);
1072 for (i
= 0; i
< ACX_TX_URB_CNT
; ++i
) {
1073 usb_free_urb(adev
->usb_tx
[i
].urb
);
1076 /* Freeing containers */
1077 kfree(adev
->usb_rx
);
1078 kfree(adev
->usb_tx
);
1080 acx_unlock(adev
, flags
);
1081 acx_sem_unlock(adev
);
1083 ieee80211_free_hw(adev
->ieee
);
1088 /***********************************************************************
1090 ** This function is called when the user sets up the network interface.
1091 ** It initializes a management timer, sets up the USB card and starts
1092 ** the network tx queue and USB receive.
1094 int acxusb_e_open(struct ieee80211_hw
*hw
)
1096 acx_device_t
*adev
= ieee2adev(hw
);
1097 unsigned long flags
;
1104 /* put the ACX100 out of sleep mode */
1105 // acx_s_issue_cmd(adev, ACX1xx_CMD_WAKE, NULL, 0);
1107 init_timer(&adev
->mgmt_timer
);
1108 adev
->mgmt_timer
.function
= acx_i_timer
;
1109 adev
->mgmt_timer
.data
= (unsigned long)adev
;
1111 /* acx_s_start needs it */
1112 SET_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
1115 /* don't acx_start_queue() here, we need to associate first */
1117 acx_lock(adev
, flags
);
1118 for (i
= 0; i
< ACX_RX_URB_CNT
; i
++) {
1119 adev
->usb_rx
[i
].urb
->status
= 0;
1122 acxusb_l_poll_rx(adev
, &adev
->usb_rx
[0]);
1124 acx_setup_modes(adev
);
1125 ieee80211_start_queues(adev
->ieee
);
1126 acx_unlock(adev
, flags
);
1128 acx_sem_unlock(adev
);
1135 /***********************************************************************
1138 ** This function stops the network functionality of the interface (invoked
1139 ** when the user calls ifconfig <wlan> down). The tx queue is halted and
1140 ** the device is marked as down. In case there were any pending USB bulk
1141 ** transfers, these are unlinked (asynchronously). The module in-use count
1142 ** is also decreased in this function.
1144 int acxusb_e_close(struct ieee80211_hw
*hw
)
1146 acx_device_t
*adev
= ieee2adev(hw
);
1147 unsigned long flags
;
1153 if (adev
->dev_state_mask
& ACX_STATE_IFACE_UP
)
1155 // acxusb_e_down(adev);
1156 CLEAR_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
1159 /* Code below is remarkably similar to acxpci_s_down(). Maybe we can merge them? */
1161 acx_free_modes(adev
);
1163 /* Make sure we don't get any more rx requests */
1164 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_RX
, NULL
, 0);
1165 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_TX
, NULL
, 0);
1168 * We must do FLUSH *without* holding sem to avoid a deadlock.
1169 * See pci.c:acxpci_s_down() for deails.
1171 acx_sem_unlock(adev
);
1172 flush_scheduled_work();
1175 /* Power down the device */
1176 acx_s_issue_cmd(adev
, ACX1xx_CMD_SLEEP
, NULL
, 0);
1178 /* Stop the transmit queue, mark the device as DOWN */
1179 acx_lock(adev
, flags
);
1180 // acx_stop_queue(ndev, "on ifdown");
1181 // acx_set_status(adev, ACX_STATUS_0_STOPPED);
1182 /* stop pending rx/tx urb transfers */
1183 for (i
= 0; i
< ACX_TX_URB_CNT
; i
++) {
1184 acxusb_unlink_urb(adev
->usb_tx
[i
].urb
);
1185 adev
->usb_tx
[i
].busy
= 0;
1187 for (i
= 0; i
< ACX_RX_URB_CNT
; i
++) {
1188 acxusb_unlink_urb(adev
->usb_rx
[i
].urb
);
1189 adev
->usb_rx
[i
].busy
= 0;
1191 adev
->tx_free
= ACX_TX_URB_CNT
;
1192 acx_unlock(adev
, flags
);
1194 /* Must do this outside of lock */
1195 del_timer_sync(&adev
->mgmt_timer
);
1197 acx_sem_unlock(adev
);
1204 /***********************************************************************
1206 ** This function (re)initiates a bulk-in USB transfer on a given urb
1208 void acxusb_l_poll_rx(acx_device_t
* adev
, usb_rx_t
* rx
)
1210 struct usb_device
*usbdev
;
1213 unsigned int inpipe
;
1218 usbdev
= adev
->usbdev
;
1220 rxnum
= rx
- adev
->usb_rx
;
1222 inpipe
= usb_rcvbulkpipe(usbdev
, adev
->bulkinep
);
1223 if (unlikely(rxurb
->status
== -EINPROGRESS
)) {
1225 "acx: error, rx triggered while rx urb in progress\n");
1226 /* FIXME: this is nasty, receive is being cancelled by this code
1227 * on the other hand, this should not happen anyway...
1229 usb_unlink_urb(rxurb
);
1230 } else if (unlikely(rxurb
->status
== -ECONNRESET
)) {
1231 log(L_USBRXTX
, "acx_usb: _poll_rx: connection reset\n");
1234 rxurb
->actual_length
= 0;
1235 usb_fill_bulk_urb(rxurb
, usbdev
, inpipe
, &rx
->bulkin
, /* dataptr */
1236 RXBUFSIZE
, /* size */
1237 acxusb_i_complete_rx
, /* handler */
1238 rx
/* handler param */
1240 rxurb
->transfer_flags
= URB_ASYNC_UNLINK
;
1242 /* ATOMIC: we may be called from complete_rx() usb callback */
1243 errcode
= usb_submit_urb(rxurb
, GFP_ATOMIC
);
1244 /* FIXME: evaluate the error code! */
1245 log(L_USBRXTX
, "SUBMIT RX (%d) inpipe=0x%X size=%d errcode=%d\n",
1246 rxnum
, inpipe
, (int)RXBUFSIZE
, errcode
);
1252 /***********************************************************************
1253 ** acxusb_i_complete_rx()
1255 ** urb -> pointer to USB request block
1256 ** regs -> pointer to register-buffer for syscalls (see asm/ptrace.h)
1258 ** This function is invoked by USB subsystem whenever a bulk receive
1260 ** The received data is then committed to the network stack and the next
1261 ** USB receive is triggered.
1263 void acxusb_i_complete_rx(struct urb
*urb
)
1269 unsigned long flags
;
1270 int size
, remsize
, packetsize
, rxnum
;
1274 BUG_ON(!urb
->context
);
1276 rx
= (usb_rx_t
*) urb
->context
;
1279 acx_lock(adev
, flags
);
1282 * Happens on disconnect or close. Don't play with the urb.
1283 * Don't resubmit it. It will get unlinked by close()
1285 if (unlikely(!(adev
->dev_state_mask
& ACX_STATE_IFACE_UP
))) {
1286 log(L_USBRXTX
, "rx: device is down, not doing anything\n");
1290 inbuf
= &rx
->bulkin
;
1291 size
= urb
->actual_length
;
1293 rxnum
= rx
- adev
->usb_rx
;
1295 log(L_USBRXTX
, "RETURN RX (%d) status=%d size=%d\n",
1296 rxnum
, urb
->status
, size
);
1298 /* Send the URB that's waiting. */
1299 log(L_USBRXTX
, "rxnum=%d, sending=%d\n", rxnum
, rxnum
^ 1);
1300 acxusb_l_poll_rx(adev
, &adev
->usb_rx
[rxnum
^ 1]);
1302 if (unlikely(size
> sizeof(rxbuffer_t
)))
1303 printk("acx_usb: rx too large: %d, please report\n", size
);
1305 /* check if the transfer was aborted */
1306 switch (urb
->status
) {
1307 case 0: /* No error */
1310 printk(KERN_ERR
"acx: rx data overrun\n");
1311 adev
->rxtruncsize
= 0; /* Not valid anymore. */
1314 adev
->rxtruncsize
= 0;
1316 case -ESHUTDOWN
: /* rmmod */
1317 adev
->rxtruncsize
= 0;
1320 adev
->rxtruncsize
= 0;
1321 adev
->stats
.rx_errors
++;
1322 printk("acx: rx error (urb status=%d)\n", urb
->status
);
1326 if (unlikely(!size
))
1327 printk("acx: warning, encountered zerolength rx packet\n");
1329 if (urb
->transfer_buffer
!= inbuf
)
1332 /* check if previous frame was truncated
1333 ** FIXME: this code can only handle truncation
1334 ** of consecutive packets!
1337 if (adev
->rxtruncsize
) {
1340 ptr
= &adev
->rxtruncbuf
;
1341 packetsize
= RXBUF_BYTES_USED(ptr
);
1342 if (acx_debug
& L_USBRXTX
) {
1343 printk("handling truncated frame (truncsize=%d size=%d "
1344 "packetsize(from trunc)=%d)\n",
1345 adev
->rxtruncsize
, size
, packetsize
);
1346 acx_dump_bytes(ptr
, RXBUF_HDRSIZE
);
1347 acx_dump_bytes(inbuf
, RXBUF_HDRSIZE
);
1350 /* bytes needed for rxtruncbuf completion: */
1351 tail_size
= packetsize
- adev
->rxtruncsize
;
1353 if (size
< tail_size
) {
1354 /* there is not enough data to complete this packet,
1355 ** simply append the stuff to the truncation buffer
1357 memcpy(((char *)ptr
) + adev
->rxtruncsize
, inbuf
, size
);
1358 adev
->rxtruncsize
+= size
;
1361 /* ok, this data completes the previously
1362 ** truncated packet. copy it into a descriptor
1363 ** and give it to the rest of the stack */
1365 /* append tail to previously truncated part
1366 ** NB: adev->rxtruncbuf (pointed to by ptr) can't
1367 ** overflow because this is already checked before
1368 ** truncation buffer was filled. See below,
1369 ** "if (packetsize > sizeof(rxbuffer_t))..." code */
1370 memcpy(((char *)ptr
) + adev
->rxtruncsize
, inbuf
,
1373 if (acx_debug
& L_USBRXTX
) {
1374 printk("full trailing packet + 12 bytes:\n");
1375 acx_dump_bytes(inbuf
,
1376 tail_size
+ RXBUF_HDRSIZE
);
1378 acx_l_process_rxbuf(adev
, ptr
);
1379 adev
->rxtruncsize
= 0;
1380 ptr
= (rxbuffer_t
*) (((char *)inbuf
) + tail_size
);
1381 remsize
-= tail_size
;
1383 log(L_USBRXTX
, "post-merge size=%d remsize=%d\n",
1387 /* size = USB data block size
1388 ** remsize = unprocessed USB bytes left
1389 ** ptr = current pos in USB data block
1392 if (remsize
< RXBUF_HDRSIZE
) {
1393 printk("acx: truncated rx header (%d bytes)!\n",
1396 acx_dump_bytes(ptr
, remsize
);
1400 packetsize
= RXBUF_BYTES_USED(ptr
);
1401 log(L_USBRXTX
, "packet with packetsize=%d\n", packetsize
);
1403 if (RXBUF_IS_TXSTAT(ptr
)) {
1404 /* do rate handling */
1405 usb_txstatus_t
*stat
= (void *)ptr
;
1407 log(L_USBRXTX
, "tx: stat: mac_cnt_rcvd:%04X "
1408 "queue_index:%02X mac_status:%02X hostdata:%08X "
1409 "rate:%u ack_failures:%02X rts_failures:%02X "
1412 stat
->queue_index
, stat
->mac_status
, stat
->hostdata
,
1413 stat
->rate
, stat
->ack_failures
, stat
->rts_failures
,
1416 if (adev->rate_auto && client_no < VEC_SIZE(adev->sta_list)) {
1417 client_t *clt = &adev->sta_list[client_no];
1418 u16 cur = stat->hostdata >> 16;
1420 if (clt && clt->rate_cur == cur) {
1421 acx_l_handle_txrate_auto(adev, clt,
1422 cur, // intended rate
1423 stat->rate, 0, // actually used rate
1424 stat->mac_status, // error?
1425 ACX_TX_URB_CNT - adev->tx_free);
1431 if (packetsize
> sizeof(rxbuffer_t
)) {
1432 printk("acx: packet exceeds max wlan "
1433 "frame size (%d > %d). size=%d\n",
1434 packetsize
, (int)sizeof(rxbuffer_t
), size
);
1436 acx_dump_bytes(ptr
, 16);
1437 /* FIXME: put some real error-handling in here! */
1441 if (packetsize
> remsize
) {
1442 /* frame truncation handling */
1443 if (acx_debug
& L_USBRXTX
) {
1444 printk("need to truncate packet, "
1445 "packetsize=%d remsize=%d "
1447 packetsize
, remsize
, size
);
1448 acx_dump_bytes(ptr
, RXBUF_HDRSIZE
);
1450 memcpy(&adev
->rxtruncbuf
, ptr
, remsize
);
1451 adev
->rxtruncsize
= remsize
;
1455 /* packetsize <= remsize */
1456 /* now handle the received data */
1457 acx_l_process_rxbuf(adev
, ptr
);
1459 ptr
= (rxbuffer_t
*) (((char *)ptr
) + packetsize
);
1460 remsize
-= packetsize
;
1461 if ((acx_debug
& L_USBRXTX
) && remsize
) {
1462 printk("more than one packet in buffer, "
1463 "second packet hdr:");
1464 acx_dump_bytes(ptr
, RXBUF_HDRSIZE
);
1469 acx_unlock(adev
, flags
);
1475 /***********************************************************************
1476 ** acxusb_i_complete_tx()
1478 ** urb -> pointer to USB request block
1479 ** regs -> pointer to register-buffer for syscalls (see asm/ptrace.h)
1481 ** This function is invoked upon termination of a USB transfer.
1483 void acxusb_i_complete_tx(struct urb
*urb
)
1487 unsigned long flags
;
1492 BUG_ON(!urb
->context
);
1494 tx
= (usb_tx_t
*) urb
->context
;
1497 txnum
= tx
- adev
->usb_tx
;
1499 acx_lock(adev
, flags
);
1502 * If the iface isn't up, we don't have any right
1503 * to play with them. The urb may get unlinked.
1505 if (unlikely(!(adev
->dev_state_mask
& ACX_STATE_IFACE_UP
))) {
1506 log(L_USBRXTX
, "tx: device is down, not doing anything\n");
1510 log(L_USBRXTX
, "RETURN TX (%d): status=%d size=%d\n",
1511 txnum
, urb
->status
, urb
->actual_length
);
1513 /* handle USB transfer errors */
1514 switch (urb
->status
) {
1515 case 0: /* No error */
1523 /* FIXME: real error-handling code here please */
1525 printk(KERN_ERR
"acx: tx error, urb status=%d\n", urb
->status
);
1526 /* FIXME: real error-handling code here please */
1529 /* free the URB and check for more data */
1532 if ((adev
->tx_free
>= TX_START_QUEUE
)
1533 && (adev
->status
== ACX_STATUS_4_ASSOCIATED
)
1534 /* && (acx_queue_stopped(adev->ndev)*/) {
1535 log(L_BUF
, "tx: wake queue (%u free txbufs)\n", adev
->tx_free
);
1536 /* acx_wake_queue(adev->ndev, NULL); */
1540 acx_unlock(adev
, flags
);
1546 /***************************************************************
1547 ** acxusb_l_alloc_tx
1548 ** Actually returns a usb_tx_t* ptr
1550 tx_t
*acxusb_l_alloc_tx(acx_device_t
* adev
)
1557 head
= adev
->tx_head
;
1559 head
= (head
+ 1) % ACX_TX_URB_CNT
;
1560 if (!adev
->usb_tx
[head
].busy
) {
1561 log(L_USBRXTX
, "allocated tx %d\n", head
);
1562 tx
= &adev
->usb_tx
[head
];
1565 /* Keep a few free descs between head and tail of tx ring.
1566 ** It is not absolutely needed, just feels safer */
1567 if (adev
->tx_free
< TX_STOP_QUEUE
) {
1568 log(L_BUF
, "tx: stop queue "
1569 "(%u free txbufs)\n", adev
->tx_free
);
1570 /* acx_stop_queue(adev->ndev, NULL); */
1574 } while (likely(head
!= adev
->tx_head
));
1576 printk_ratelimited("acx: tx buffers full\n");
1578 adev
->tx_head
= head
;
1584 /***************************************************************
1585 ** Used if alloc_tx()'ed buffer needs to be cancelled without doing tx
1587 void acxusb_l_dealloc_tx(tx_t
* tx_opaque
)
1589 usb_tx_t
*tx
= (usb_tx_t
*) tx_opaque
;
1594 /***************************************************************
1596 void *acxusb_l_get_txbuf(acx_device_t
* adev
, tx_t
* tx_opaque
)
1598 usb_tx_t
*tx
= (usb_tx_t
*) tx_opaque
;
1599 return &tx
->bulkout
.data
;
1603 /***************************************************************
1606 ** Can be called from IRQ (rx -> (AP bridging or mgmt response) -> tx).
1607 ** Can be called from acx_i_start_xmit (data frames from net core).
1609 void acxusb_l_tx_data(acx_device_t
* adev
, tx_t
* tx_opaque
, int wlanpkt_len
, struct ieee80211_tx_control
*ctl
,
1610 struct sk_buff
* skb
)
1612 struct usb_device
*usbdev
;
1615 usb_txbuffer_t
*txbuf
;
1617 struct ieee80211_hdr
*whdr
;
1618 unsigned int outpipe
;
1623 tx
= ((usb_tx_t
*) tx_opaque
);
1625 txbuf
= &tx
->bulkout
;
1626 whdr
= (struct ieee80211_hdr
*) txbuf
->data
;
1627 txnum
= tx
- adev
->usb_tx
;
1629 log(L_DEBUG
, "using buf#%d free=%d len=%d\n",
1630 txnum
, adev
->tx_free
, wlanpkt_len
);
1632 switch (adev->mode) {
1633 case ACX_MODE_0_ADHOC:
1635 clt = acx_l_sta_list_get(adev, whdr->a1);
1637 case ACX_MODE_2_STA:
1638 // clt = adev->ap_client;
1644 if (unlikely(clt && !clt->rate_cur)) {
1645 printk("acx: driver bug! bad ratemask\n");
1650 /* fill the USB transfer header */
1651 txbuf
->desc
= cpu_to_le16(USB_TXBUF_TXDESC
);
1652 txbuf
->mpdu_len
= cpu_to_le16(wlanpkt_len
);
1653 txbuf
->queue_index
= 1;
1654 txbuf
->rate
= ctl
->tx_rate
; //clt->rate_100;
1655 // FIXME(); //This used to have | (clt - adev->ap_client)
1656 txbuf
->hostdata
= (ctl
->tx_rate
<< 16);
1657 txbuf
->ctrl1
= DESC_CTL_FIRSTFRAG
;
1658 if (1 == adev
->preamble_cur
)
1659 SET_BIT(txbuf
->ctrl1
, DESC_CTL_SHORT_PREAMBLE
);
1661 txbuf
->data_len
= cpu_to_le16(wlanpkt_len
);
1663 if (unlikely(acx_debug
& L_DATA
)) {
1664 printk("dump of bulk out urb:\n");
1665 acx_dump_bytes(txbuf
, wlanpkt_len
+ USB_TXBUF_HDRSIZE
);
1668 if (unlikely(txurb
->status
== -EINPROGRESS
)) {
1670 ("acx: trying to submit tx urb while already in progress\n");
1673 /* now schedule the USB transfer */
1674 usbdev
= adev
->usbdev
;
1675 outpipe
= usb_sndbulkpipe(usbdev
, adev
->bulkoutep
);
1677 usb_fill_bulk_urb(txurb
, usbdev
, outpipe
, txbuf
, /* dataptr */
1678 wlanpkt_len
+ USB_TXBUF_HDRSIZE
, /* size */
1679 acxusb_i_complete_tx
, /* handler */
1680 tx
/* handler param */
1683 txurb
->transfer_flags
= URB_ASYNC_UNLINK
| URB_ZERO_PACKET
;
1684 ucode
= usb_submit_urb(txurb
, GFP_ATOMIC
);
1685 log(L_USBRXTX
, "SUBMIT TX (%d): outpipe=0x%X buf=%p txsize=%d "
1686 "rate=%u errcode=%d\n", txnum
, outpipe
, txbuf
,
1687 wlanpkt_len
+ USB_TXBUF_HDRSIZE
, txbuf
->rate
, ucode
);
1689 if (unlikely(ucode
)) {
1690 printk(KERN_ERR
"acx: submit_urb() error=%d txsize=%d\n",
1691 ucode
, wlanpkt_len
+ USB_TXBUF_HDRSIZE
);
1693 /* on error, just mark the frame as done and update
1696 adev
->stats
.tx_errors
++;
1699 /* needed? if (adev->tx_free > TX_START_QUEUE) acx_wake_queue(...) */
1705 /***********************************************************************
1706 static void acxusb_i_set_rx_mode(struct net_device *ndev)
1712 /***********************************************************************
1714 #ifdef HAVE_TX_TIMEOUT
1716 void acxusb_i_tx_timeout(struct net_device *ndev)
1718 acx_device_t *adev = ndev2adev(ndev);
1719 unsigned long flags;
1724 acx_lock(adev, flags);
1725 */ /* unlink the URBs */
1726 /* for (i = 0; i < ACX_TX_URB_CNT; i++) {
1727 acxusb_unlink_urb(adev->usb_tx[i].urb);
1728 adev->usb_tx[i].busy = 0;
1730 adev->tx_free = ACX_TX_URB_CNT;
1731 */ /* TODO: stats update */
1732 /* acx_unlock(adev, flags);
1740 /***********************************************************************
1743 ** This function is invoked upon loading of the kernel module.
1744 ** It registers itself at the kernel's USB subsystem.
1746 ** Returns: Errorcode on failure, 0 on success
1748 int __init
acxusb_e_init_module(void)
1750 log(L_INIT
, "USB module " ACX_RELEASE
" initialized, "
1751 "probing for devices...\n");
1752 return usb_register(&acxusb_driver
);
1757 /***********************************************************************
1760 ** This function is invoked as last step of the module unloading. It simply
1761 ** deregisters this module at the kernel's USB subsystem.
1763 void __exit
acxusb_e_cleanup_module(void)
1765 usb_deregister(&acxusb_driver
);
1766 log(L_INIT
, "USB module " ACX_RELEASE
" unloaded\n");
1770 /***********************************************************************
1776 static void dump_device(struct usb_device
*usbdev
)
1779 struct usb_config_descriptor
*cd
;
1781 printk("acx device dump:\n");
1782 printk(" devnum: %d\n", usbdev
->devnum
);
1783 printk(" speed: %d\n", usbdev
->speed
);
1784 printk(" tt: 0x%X\n", (unsigned int)(usbdev
->tt
));
1785 printk(" ttport: %d\n", (unsigned int)(usbdev
->ttport
));
1786 printk(" toggle[0]: 0x%X toggle[1]: 0x%X\n",
1787 (unsigned int)(usbdev
->toggle
[0]),
1788 (unsigned int)(usbdev
->toggle
[1]));
1789 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
1790 /* This saw a change after 2.6.10 */
1791 printk(" ep_in wMaxPacketSize: ");
1792 for (i
= 0; i
< 16; ++i
)
1793 if (usbdev
->ep_in
[i
] != NULL
)
1795 usbdev
->ep_in
[i
]->desc
.wMaxPacketSize
);
1797 printk(" ep_out wMaxPacketSize: ");
1798 for (i
= 0; i
< ARRAY_SIZE(usbdev
->ep_out
); ++i
)
1799 if (usbdev
->ep_out
[i
] != NULL
)
1801 usbdev
->ep_out
[i
]->desc
.wMaxPacketSize
);
1804 printk(" epmaxpacketin: ");
1805 for (i
= 0; i
< 16; i
++)
1806 printk("%d ", usbdev
->epmaxpacketin
[i
]);
1808 printk(" epmaxpacketout: ");
1809 for (i
= 0; i
< 16; i
++)
1810 printk("%d ", usbdev
->epmaxpacketout
[i
]);
1813 printk(" parent: 0x%X\n", (unsigned int)usbdev
->parent
);
1814 printk(" bus: 0x%X\n", (unsigned int)usbdev
->bus
);
1816 printk(" configs: ");
1817 for (i
= 0; i
< usbdev
->descriptor
.bNumConfigurations
; i
++)
1818 printk("0x%X ", usbdev
->config
[i
]);
1821 printk(" actconfig: %p\n", usbdev
->actconfig
);
1822 dump_device_descriptor(&usbdev
->descriptor
);
1824 cd
= &usbdev
->config
->desc
;
1825 dump_config_descriptor(cd
);
1829 /***********************************************************************
1831 static void dump_config_descriptor(struct usb_config_descriptor
*cd
)
1833 printk("Configuration Descriptor:\n");
1838 printk(" bLength: %d (0x%X)\n", cd
->bLength
, cd
->bLength
);
1839 printk(" bDescriptorType: %d (0x%X)\n", cd
->bDescriptorType
,
1840 cd
->bDescriptorType
);
1841 printk(" bNumInterfaces: %d (0x%X)\n", cd
->bNumInterfaces
,
1842 cd
->bNumInterfaces
);
1843 printk(" bConfigurationValue: %d (0x%X)\n", cd
->bConfigurationValue
,
1844 cd
->bConfigurationValue
);
1845 printk(" iConfiguration: %d (0x%X)\n", cd
->iConfiguration
,
1846 cd
->iConfiguration
);
1847 printk(" bmAttributes: %d (0x%X)\n", cd
->bmAttributes
,
1849 /* printk(" MaxPower: %d (0x%X)\n", cd->bMaxPower, cd->bMaxPower); */
1853 static void dump_device_descriptor(struct usb_device_descriptor
*dd
)
1855 printk("Device Descriptor:\n");
1860 printk(" bLength: %d (0x%X)\n", dd
->bLength
, dd
->bLength
);
1861 printk(" bDescriptortype: %d (0x%X)\n", dd
->bDescriptorType
,
1862 dd
->bDescriptorType
);
1863 printk(" bcdUSB: %d (0x%X)\n", dd
->bcdUSB
, dd
->bcdUSB
);
1864 printk(" bDeviceClass: %d (0x%X)\n", dd
->bDeviceClass
,
1866 printk(" bDeviceSubClass: %d (0x%X)\n", dd
->bDeviceSubClass
,
1867 dd
->bDeviceSubClass
);
1868 printk(" bDeviceProtocol: %d (0x%X)\n", dd
->bDeviceProtocol
,
1869 dd
->bDeviceProtocol
);
1870 printk(" bMaxPacketSize0: %d (0x%X)\n", dd
->bMaxPacketSize0
,
1871 dd
->bMaxPacketSize0
);
1872 printk(" idVendor: %d (0x%X)\n", dd
->idVendor
, dd
->idVendor
);
1873 printk(" idProduct: %d (0x%X)\n", dd
->idProduct
, dd
->idProduct
);
1874 printk(" bcdDevice: %d (0x%X)\n", dd
->bcdDevice
, dd
->bcdDevice
);
1875 printk(" iManufacturer: %d (0x%X)\n", dd
->iManufacturer
,
1877 printk(" iProduct: %d (0x%X)\n", dd
->iProduct
, dd
->iProduct
);
1878 printk(" iSerialNumber: %d (0x%X)\n", dd
->iSerialNumber
,
1880 printk(" bNumConfigurations: %d (0x%X)\n", dd
->bNumConfigurations
,
1881 dd
->bNumConfigurations
);
1885 #endif /* ACX_DEBUG */