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 #include <linux/types.h>
21 #include <linux/module.h>
22 #include <linux/moduleparam.h>
23 #include <linux/kernel.h>
24 #include <linux/usb.h>
25 #include <linux/netdevice.h>
26 #include <linux/rtnetlink.h>
27 #include <linux/etherdevice.h>
28 #include <linux/wireless.h>
29 #include <net/iw_handler.h>
30 #include <linux/vmalloc.h>
31 #include <linux/ethtool.h>
32 #include <linux/workqueue.h>
38 /***********************************************************************
40 /* number of endpoints of an interface */
41 #define NUM_EP(intf) (intf)->altsetting[0].desc.bNumEndpoints
42 #define EP(intf, nr) (intf)->altsetting[0].endpoint[(nr)].desc
43 #define GET_DEV(udev) usb_get_dev((udev))
44 #define PUT_DEV(udev) usb_put_dev((udev))
46 /* removed in 2.6.14. We will use fake value for now
47 * TODO: maybe we should just remove all lines that include
48 * URB_ASYNC_UNLINK somewhere?
50 #define URB_ASYNC_UNLINK 0
52 /***********************************************************************
54 /* ACX100 (TNETW1100) USB device: D-Link DWL-120+ */
55 #define ACX100_VENDOR_ID 0x2001
56 #define ACX100_PRODUCT_ID_UNBOOTED 0x3B01
57 #define ACX100_PRODUCT_ID_BOOTED 0x3B00
59 /* TNETW1450 USB devices */
60 #define VENDOR_ID_DLINK 0x07b8 /* D-Link Corp. */
61 #define PRODUCT_ID_WUG2400 0xb21a /* AboCom WUG2400 or SafeCom SWLUT-54125 */
62 #define VENDOR_ID_AVM_GMBH 0x057c
63 #define PRODUCT_ID_AVM_WLAN_USB 0x5601
64 #define PRODUCT_ID_AVM_WLAN_USB_si 0x6201 /* "self install" named Version:
65 * driver kills kernel on inbound scans from fritz box ?? */
66 #define VENDOR_ID_ZCOM 0x0cde
67 #define PRODUCT_ID_ZCOM_XG750 0x0017 /* not tested yet */
68 #define VENDOR_ID_TI 0x0451
69 #define PRODUCT_ID_TI_UNKNOWN 0x60c5 /* not tested yet */
71 #define ACX_USB_CTRL_TIMEOUT 5500 /* steps in ms */
73 /* Buffer size for fw upload, same for both ACX100 USB and TNETW1450 */
74 #define USB_RWMEM_MAXLEN 2048
76 /* The number of bulk URBs to use */
77 #define ACX_TX_URB_CNT 8
78 #define ACX_RX_URB_CNT 2
80 /* Should be sent to the bulkout endpoint */
81 #define ACX_USB_REQ_UPLOAD_FW 0x10
82 #define ACX_USB_REQ_ACK_CS 0x11
83 #define ACX_USB_REQ_CMD 0x12
85 /***********************************************************************
88 static int acxusb_e_probe(struct usb_interface
*, const struct usb_device_id
*);
89 static void acxusb_e_disconnect(struct usb_interface
*);
90 static void acxusb_i_complete_tx(struct urb
*);
91 static void acxusb_i_complete_rx(struct urb
*);
92 static int acxusb_e_open(struct ieee80211_hw
*);
93 static void acxusb_e_close(struct ieee80211_hw
*);
94 //static void acxusb_i_set_rx_mode(struct net_device *);
95 static int acxusb_boot(struct usb_device
*, int is_tnetw1450
, int *radio_type
);
97 static void acxusb_l_poll_rx(acx_device_t
* adev
, usb_rx_t
* rx
);
99 /*static void acxusb_i_tx_timeout(struct net_device *);*/
101 /* static void dump_device(struct usb_device *); */
102 /* static void dump_device_descriptor(struct usb_device_descriptor *); */
103 /* static void dump_config_descriptor(struct usb_config_descriptor *); */
105 /***********************************************************************
108 #define TXBUFSIZE sizeof(usb_txbuffer_t)
110 * Now, this is just plain lying, but the device insists in giving us
111 * huge packets. We supply extra space after rxbuffer. Need to understand
114 #define RXBUFSIZE (sizeof(rxbuffer_t) + \
115 (sizeof(usb_rx_t) - sizeof(struct usb_rx_plain)))
117 static const struct usb_device_id acxusb_ids
[] = {
118 {USB_DEVICE(ACX100_VENDOR_ID
, ACX100_PRODUCT_ID_BOOTED
)},
119 {USB_DEVICE(ACX100_VENDOR_ID
, ACX100_PRODUCT_ID_UNBOOTED
)},
120 {USB_DEVICE(VENDOR_ID_DLINK
, PRODUCT_ID_WUG2400
)},
121 {USB_DEVICE(VENDOR_ID_AVM_GMBH
, PRODUCT_ID_AVM_WLAN_USB
)},
122 {USB_DEVICE(VENDOR_ID_AVM_GMBH
, PRODUCT_ID_AVM_WLAN_USB_si
)},
123 {USB_DEVICE(VENDOR_ID_ZCOM
, PRODUCT_ID_ZCOM_XG750
)},
124 {USB_DEVICE(VENDOR_ID_TI
, PRODUCT_ID_TI_UNKNOWN
)},
128 MODULE_DEVICE_TABLE(usb
, acxusb_ids
);
130 /* USB driver data structure as required by the kernel's USB core */
131 static struct usb_driver
134 .probe
= acxusb_e_probe
,
135 .disconnect
= acxusb_e_disconnect
,
136 .id_table
= acxusb_ids
139 /***********************************************************************
143 ** When the function is usb_kill_urb, the urb lifecycle is stopped. This
144 ** function is usually used when the device is disconnected from the system,
145 ** in the disconnect callback. For some drivers, the usb_unlink_urb function
146 ** should be used to tell the USB core to stop an urb. This function does not
147 ** wait for the urb to be fully stopped before returning to the caller.
148 ** This is useful for stoppingthe urb while in an interrupt handler or when
149 ** a spinlock is held, as waiting for a urb to fully stop requires the ability
150 ** for the USB core to put the calling process to sleep. This function requires
151 ** that the URB_ASYNC_UNLINK flag value be set in the urb that is being asked
152 ** to be stopped in order to work properly.
154 ** (URB_ASYNC_UNLINK is obsolete, usb_unlink_urb will always be
155 ** asynchronous while usb_kill_urb is synchronous and should be called
156 ** directly (drivers/usb/core/urb.c))
158 ** In light of this, timeout is just for paranoid reasons...
160 ** Actually, it's useful for debugging. If we reach timeout, we're doing
161 ** something wrong with the urbs.
163 static void acxusb_unlink_urb(struct urb
*urb
)
168 if (urb
->status
== -EINPROGRESS
) {
172 while (--timeout
&& urb
->status
== -EINPROGRESS
) {
176 acx_log(LOG_WARNING
, L_ANY
, "urb unlink timeout!\n");
182 /***********************************************************************
183 ** EEPROM and PHY read/write helpers
185 /***********************************************************************
186 ** acxusb_s_read_phy_reg
188 int acxusb_s_read_phy_reg(acx_device_t
* adev
, u32 reg
, u8
* charbuf
)
190 /* mem_read_write_t mem; */
194 acx_log(LOG_INFO
, L_ANY
,
195 "%s doesn't seem to work yet, disabled.\n", __func__
);
198 mem.addr = cpu_to_le16(reg);
199 mem.type = cpu_to_le16(0x82);
200 mem.len = cpu_to_le32(4);
201 acx_s_issue_cmd(adev, ACX1xx_CMD_MEM_READ, &mem, sizeof(mem));
203 acx_log(LOG_DEBUG, L_REALLYVERBOSE, "read radio PHY[0x%04X]=0x%02X\n", reg, *charbuf);
211 /***********************************************************************
213 int acxusb_s_write_phy_reg(acx_device_t
* adev
, u32 reg
, u8 value
)
215 mem_read_write_t mem
;
219 mem
.addr
= cpu_to_le16(reg
);
220 mem
.type
= cpu_to_le16(0x82);
221 mem
.len
= cpu_to_le32(4);
223 acx_s_issue_cmd(adev
, ACX1xx_CMD_MEM_WRITE
, &mem
, sizeof(mem
));
224 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
225 "write radio PHY[0x%04X]=0x%02X\n", reg
, value
);
232 /***********************************************************************
233 ** acxusb_s_issue_cmd_timeo
234 ** Excecutes a command in the command mailbox
236 ** buffer = a pointer to the data.
237 ** The data must not include 4 byte command header
240 /* TODO: ideally we shall always know how much we need
241 ** and this shall be 0 */
242 #define BOGUS_SAFETY_PADDING 0x40
245 #define FUNC "issue_cmd"
249 acxusb_s_issue_cmd_timeo(acx_device_t
* adev
,
251 void *buffer
, unsigned buflen
, unsigned timeout
)
255 acxusb_s_issue_cmd_timeo_debug(acx_device_t
* adev
,
259 unsigned timeout
, const char *cmdstr
)
262 /* USB ignores timeout param */
264 struct usb_device
*usbdev
;
269 } __attribute__ ((packed
)) *loc
;
271 int acklen
, blocklen
, inpipe
, outpipe
;
277 devname
= wiphy_name(adev
->ieee
->wiphy
);
278 /* no "wlan%%d: ..." please */
279 if (!devname
|| !devname
[0] || devname
[4] == '%')
282 acx_log(LOG_DEBUG
, L_CTL
, FUNC
"(cmd:%s,buflen:%u,type:0x%04X)\n",
284 buffer
? le16_to_cpu(((acx_ie_generic_t
*) buffer
)->type
) : -1);
286 loc
= kmalloc(buflen
+ 4 + BOGUS_SAFETY_PADDING
, GFP_KERNEL
);
288 acx_log(LOG_WARNING
, L_ANY
,
289 "%s: " FUNC
"(): no memory for data buffer\n", devname
);
293 /* get context from acx_device */
294 usbdev
= adev
->usbdev
;
296 /* check which kind of command was issued */
297 loc
->cmd
= cpu_to_le16(cmd
);
300 /* NB: buflen == frmlen + 4
302 ** Interrogate: write 8 bytes: (cmd,status,rid,frmlen), then
303 ** read (cmd,status,rid,frmlen,data[frmlen]) back
305 ** Configure: write (cmd,status,rid,frmlen,data[frmlen])
307 ** Possibly bogus special handling of ACX1xx_REG_SCAN_STATUS removed
310 /* now write the parameters of the command if needed */
311 acklen
= buflen
+ 4 + BOGUS_SAFETY_PADDING
;
313 if (buffer
&& buflen
) {
314 /* if it's an QUERY command, just pass the length
315 * of parameters to read, as data */
316 if (cmd
== ACX1xx_CMD_QUERY
) {
320 memcpy(loc
->data
, buffer
, blocklen
);
322 blocklen
+= 4; /* account for cmd,status */
324 /* obtain the I/O pipes */
325 outpipe
= usb_sndctrlpipe(usbdev
, 0);
326 inpipe
= usb_rcvctrlpipe(usbdev
, 0);
327 acx_log(LOG_DEBUG
, L_CTL
, "ctrl inpipe=0x%X outpipe=0x%X\n",
329 acx_log(LOG_DEBUG
, L_CTL
,
330 "sending USB control msg (out) (blocklen=%d)\n", blocklen
);
331 acx_log_dump(LOG_DEBUG
, L_DATA
, loc
, blocklen
, "Control msg:\n");
332 result
= usb_control_msg(usbdev
, outpipe
, ACX_USB_REQ_CMD
, /* request */
333 USB_TYPE_VENDOR
| USB_DIR_OUT
, /* requesttype */
338 ACX_USB_CTRL_TIMEOUT
/* timeout in ms */
341 if (result
== -ENODEV
) {
342 acx_log(LOG_WARNING
, L_CTL
, "no device present (unplug?)\n");
346 acx_log(LOG_DEBUG
, L_CTL
, "wrote %d bytes\n", result
);
351 /* check for device acknowledge */
352 acx_log(LOG_DEBUG
, L_CTL
, "sending USB control msg (in) (acklen=%d)\n",
354 loc
->status
= 0; /* delete old status flag -> set to IDLE */
355 /* shall we zero out the rest? */
356 result
= usb_control_msg(usbdev
, inpipe
, ACX_USB_REQ_CMD
, /* request */
357 USB_TYPE_VENDOR
| USB_DIR_IN
, /* requesttype */
362 ACX_USB_CTRL_TIMEOUT
/* timeout in ms */
365 acx_log(LOG_WARNING
, L_ANY
, "%s: " FUNC
"(): USB read error %d\n",
370 acx_log_dump(LOG_DEBUG
, L_CTL
, loc
, result
, "read %d bytes:\n", result
);
373 check for result==buflen+4? Was seen:
375 query(type:ACX100_REG_DOT11_ED_THRESHOLD,len:4)
376 issue_cmd(cmd:ACX1xx_CMD_QUERY,buflen:8,type:4111)
377 ctrl inpipe=0x80000280 outpipe=0x80000200
378 sending USB control msg (out) (blocklen=8)
379 01 00 00 00 0F 10 04 00
381 sending USB control msg (in) (acklen=12) sizeof(loc->data
382 read 4 bytes <==== MUST BE 12!!
385 cmd_status
= le16_to_cpu(loc
->status
);
386 if (cmd_status
!= 1) {
387 acx_log(LOG_WARNING
, L_ANY
, "%s: " FUNC
388 "(): cmd_status is not SUCCESS: %d (%s)\n",
389 devname
, cmd_status
, acx_cmd_status_str(cmd_status
));
390 /* TODO: goto bad; ? */
392 if ((cmd
== ACX1xx_CMD_QUERY
) && buffer
&& buflen
) {
393 memcpy(buffer
, loc
->data
, buflen
);
394 acx_log(LOG_DEBUG
, L_CTL
,
395 "response frame: cmd=0x%04X status=%d\n",
396 le16_to_cpu(loc
->cmd
), cmd_status
);
403 /* Give enough info so that callers can avoid
404 ** printing their own diagnostic messages */
406 acx_log(LOG_WARNING
, L_ANY
, "%s: " FUNC
"(cmd:%s) FAILED\n",
409 acx_log(LOG_WARNING
, L_ANY
, "%s: " FUNC
"(cmd:0x%04X) FAILED\n",
419 /***********************************************************************
422 ** usbdev -> Pointer to kernel's usb_device structure
425 ** (int) Errorcode or 0 on success
427 ** This function triggers the loading of the firmware image from harddisk
428 ** and then uploads the firmware to the USB device. After uploading the
429 ** firmware and transmitting the checksum, the device resets and appears
430 ** as a new device on the USB bus (the device we can finally deal with)
433 acxusb_fw_needs_padding(firmware_image_t
*fw_image
, unsigned int usb_maxlen
)
435 unsigned int num_xfers
= ((fw_image
->size
- 1) / usb_maxlen
) + 1;
437 return ((num_xfers
% 2) == 0);
441 acxusb_boot(struct usb_device
*usbdev
, int is_tnetw1450
, int *radio_type
)
443 char filename
[sizeof("tiacx1NNusbcRR")];
445 firmware_image_t
*fw_image
= NULL
;
448 unsigned int blk_len
, inpipe
, outpipe
;
450 u32 img_checksum
, sum
;
457 /* dump_device(usbdev); */
459 usbbuf
= kmalloc(USB_RWMEM_MAXLEN
, GFP_KERNEL
);
461 acx_log(LOG_WARNING
, L_ANY
,
462 "no memory for USB transfer buffer (%d bytes)\n",
468 /* Obtain the I/O pipes */
469 outpipe
= usb_sndbulkpipe(usbdev
, 1);
470 inpipe
= usb_rcvbulkpipe(usbdev
, 2);
472 acx_log(LOG_DEBUG
, L_ANY
, "wait for device ready\n");
473 for (i
= 0; i
<= 2; i
++) {
474 result
= usb_bulk_msg(usbdev
, inpipe
,
477 &num_processed
, 2000);
479 if ((*(u32
*) & usbbuf
[4] == 0x40000001)
480 && (*(u16
*) & usbbuf
[2] == 0x1)
481 && ((*(u16
*) usbbuf
& 0x3fff) == 0)
482 && ((*(u16
*) usbbuf
& 0xc000) == 0xc000))
489 *radio_type
= usbbuf
[8];
491 /* Obtain the I/O pipes */
492 outpipe
= usb_sndctrlpipe(usbdev
, 0);
493 inpipe
= usb_rcvctrlpipe(usbdev
, 0);
495 /* FIXME: shouldn't be hardcoded */
496 *radio_type
= RADIO_MAXIM_0D
;
499 snprintf(filename
, sizeof(filename
), "tiacx1%02dusbc%02X",
500 is_tnetw1450
* 11, *radio_type
);
502 fw_image
= acx_s_read_fw(&usbdev
->dev
, filename
, &file_size
);
507 acx_log(LOG_DEBUG
, L_INIT
, "firmware size: %d bytes\n", file_size
);
509 img_checksum
= le32_to_cpu(fw_image
->chksum
);
517 memset(cmdbuf
, 0, 16);
520 acxusb_fw_needs_padding(fw_image
, USB_RWMEM_MAXLEN
);
521 tmplen
= need_padding
? file_size
- 4 : file_size
- 8;
522 *(u16
*) & cmdbuf
[0] = 0xc000;
523 *(u16
*) & cmdbuf
[2] = 0x000b;
524 *(u32
*) & cmdbuf
[4] = tmplen
;
525 *(u32
*) & cmdbuf
[8] = file_size
- 8;
526 *(u32
*) & cmdbuf
[12] = img_checksum
;
529 usb_bulk_msg(usbdev
, outpipe
, cmdbuf
, 16, &num_processed
,
534 p
= (const u8
*)&fw_image
->size
;
536 /* first calculate checksum for image size part */
537 sum
= p
[0] + p
[1] + p
[2] + p
[3];
540 /* now continue checksum for firmware data part */
541 tmplen
= le32_to_cpu(fw_image
->size
);
542 for (i
= 0; i
< tmplen
/* image size */ ; i
++) {
546 if (sum
!= le32_to_cpu(fw_image
->chksum
)) {
547 acx_log(LOG_WARNING
, L_ANY
,"FATAL: firmware upload: "
548 "checksums don't match! "
549 "(0x%08x vs. 0x%08x)\n", sum
, fw_image
->chksum
);
554 while (offset
< file_size
) {
555 blk_len
= file_size
- offset
;
556 if (blk_len
> USB_RWMEM_MAXLEN
) {
557 blk_len
= USB_RWMEM_MAXLEN
;
560 acx_log(LOG_DEBUG
, L_INIT
,
561 "uploading firmware (%d bytes, offset=%d)\n",
563 memcpy(usbbuf
, ((u8
*) fw_image
) + offset
, blk_len
);
566 for (i
= 0; i
< blk_len
; i
+= 4) {
567 *(u32
*) p
= be32_to_cpu(*(u32
*) p
);
572 usb_bulk_msg(usbdev
, outpipe
, usbbuf
, blk_len
,
574 if ((result
< 0) || (num_processed
!= blk_len
))
579 acx_log(LOG_DEBUG
, L_ANY
, "send padding\n");
580 memset(usbbuf
, 0, 4);
582 usb_bulk_msg(usbdev
, outpipe
, usbbuf
, 4,
584 if ((result
< 0) || (num_processed
!= 4))
587 acx_log(LOG_DEBUG
, L_ANY
, "read firmware upload result\n");
588 memset(cmdbuf
, 0, 20); /* additional memset */
590 usb_bulk_msg(usbdev
, inpipe
, cmdbuf
, 20, &num_processed
,
594 if (*(u32
*) & cmdbuf
[4] == 0x40000003)
596 if (*(u32
*) & cmdbuf
[4])
598 if (*(u16
*) & cmdbuf
[16] != 1)
601 val
= *(u32
*) & cmdbuf
[0];
603 || ((val
& 0xc000) != 0xc000))
606 val
= *(u32
*) & cmdbuf
[8];
609 usb_bulk_msg(usbdev
, inpipe
, cmdbuf
, 20,
610 &num_processed
, 2000);
613 val
= *(u32
*) & cmdbuf
[8];
615 /* yup, no "else" here! */
617 memset(usbbuf
, 0, 4);
619 usb_bulk_msg(usbdev
, outpipe
, usbbuf
, 4,
621 if ((result
< 0) || (!num_processed
))
625 acx_log(LOG_INFO
, L_ANY
,
626 "TNETW1450 firmware upload successful!\n");
635 /* now upload the firmware, slice the data into blocks */
637 while (offset
< file_size
) {
638 blk_len
= file_size
- offset
;
639 if (blk_len
> USB_RWMEM_MAXLEN
) {
640 blk_len
= USB_RWMEM_MAXLEN
;
642 acx_log(LOG_DEBUG
, L_INIT
,
643 "uploading firmware (%d bytes, offset=%d)\n",
645 memcpy(usbbuf
, ((u8
*) fw_image
) + offset
, blk_len
);
646 result
= usb_control_msg(usbdev
, outpipe
, ACX_USB_REQ_UPLOAD_FW
, USB_TYPE_VENDOR
| USB_DIR_OUT
, (file_size
- 8) & 0xffff, /* value */
647 (file_size
- 8) >> 16, /* index */
648 usbbuf
, /* dataptr */
650 3000 /* timeout in ms */
654 acx_log(LOG_WARNING
, L_ANY
,
655 "error %d during upload "
656 "of firmware, aborting\n", result
);
661 /* finally, send the checksum and reboot the device */
662 /* does this trigger the reboot? */
663 result
= usb_control_msg(usbdev
, outpipe
, ACX_USB_REQ_UPLOAD_FW
, USB_TYPE_VENDOR
| USB_DIR_OUT
, img_checksum
& 0xffff, /* value */
664 img_checksum
>> 16, /* index */
667 3000 /* timeout in ms */
670 acx_log(LOG_WARNING
, L_ANY
,
671 "error %d during tx of checksum, aborting\n",
675 result
= usb_control_msg(usbdev
, inpipe
, ACX_USB_REQ_ACK_CS
, USB_TYPE_VENDOR
| USB_DIR_IN
, img_checksum
& 0xffff, /* value */
676 img_checksum
>> 16, /* index */
677 usbbuf
, /* dataptr */
679 3000 /* timeout in ms */
682 acx_log(LOG_WARNING
, L_ANY
,
683 "error %d during ACK of checksum, aborting\n",
687 if (*usbbuf
!= 0x10) {
688 acx_log(LOG_WARNING
, L_ANY
, "invalid checksum?\n");
704 /* FIXME: maybe merge it with usual eeprom reading, into common code? */
705 static void acxusb_s_read_eeprom_version(acx_device_t
* adev
)
709 memset(eeprom_ver
, 0, sizeof(eeprom_ver
));
710 acx_s_query(adev
, &eeprom_ver
, ACX1FF_REG_EEPROM_VER
);
712 /* FIXME: which one of those values to take? */
713 adev
->eeprom_version
= eeprom_ver
[5];
718 * temporary helper function to at least fill important cfgopt members with
719 * useful replacement values until we figure out how one manages to fetch
720 * the configoption struct in the USB device case...
722 static int acxusb_s_fill_configoption(acx_device_t
* adev
)
724 adev
->cfgopt_probe_delay
= 200;
725 adev
->cfgopt_dot11CCAModes
= 4;
726 adev
->cfgopt_dot11Diversity
= 1;
727 adev
->cfgopt_dot11ShortPreambleOption
= 1;
728 adev
->cfgopt_dot11PBCCOption
= 1;
729 adev
->cfgopt_dot11ChannelAgility
= 0;
730 adev
->cfgopt_dot11PhyType
= 5;
731 adev
->cfgopt_dot11TempType
= 1;
735 static const struct ieee80211_ops acxusb_hw_ops
= {
736 .tx
= acx_i_start_xmit
,
737 .conf_tx
= acx_net_conf_tx
,
738 .add_interface
= acx_add_interface
,
739 .remove_interface
= acx_remove_interface
,
740 .start
= acxusb_e_open
,
741 .configure_filter
= acx_i_set_multicast_list
,
742 .stop
= acxusb_e_close
,
743 .config
= acx_net_config
,
744 .config_interface
= acx_config_interface
,
745 .set_key
= acx_net_set_key
,
746 .get_stats
= acx_e_get_stats
,
747 .get_tx_stats
= acx_net_get_tx_stats
,
750 /***********************************************************************
753 ** This function is invoked by the kernel's USB core whenever a new device is
754 ** attached to the system or the module is loaded. It is presented a usb_device
755 ** structure from which information regarding the device is obtained and evaluated.
756 ** In case this driver is able to handle one of the offered devices, it returns
757 ** a non-null pointer to a driver context and thereby claims the device.
762 acxusb_e_probe(struct usb_interface
*intf
, const struct usb_device_id
*devID
)
764 struct usb_device
*usbdev
= interface_to_usbdev(intf
);
765 acx_device_t
*adev
= NULL
;
766 struct usb_config_descriptor
*config
;
767 struct usb_endpoint_descriptor
*epdesc
;
768 struct usb_host_endpoint
*ep
;
769 struct usb_interface_descriptor
*ifdesc
;
771 int numconfigs
, numfaces
, numep
;
776 /* this one needs to be more precise in case there appears
777 * a TNETW1450 from the same vendor */
778 int is_tnetw1450
= (usbdev
->descriptor
.idVendor
!= ACX100_VENDOR_ID
);
779 struct ieee80211_hw
*ieee
;
784 /* Boot the device (i.e. upload the firmware) */
785 acxusb_boot(usbdev
, is_tnetw1450
, &radio_type
);
787 /* TNETW1450-based cards will continue right away with
788 * the same USB ID after booting */
790 /* First check if this is the "unbooted" hardware */
791 if (usbdev
->descriptor
.idProduct
== ACX100_PRODUCT_ID_UNBOOTED
) {
793 /* Boot the device (i.e. upload the firmware) */
794 acxusb_boot(usbdev
, is_tnetw1450
, &radio_type
);
796 /* DWL-120+ will first boot the firmware,
797 * then later have a *separate* probe() run
798 * since its USB ID will have changed after
800 * Since the first probe() run has no
801 * other purpose than booting the firmware,
802 * simply return immediately.
804 acx_log(LOG_INFO
, L_INIT
,
805 "finished booting, returning from probe()\n");
806 result
= OK
; /* success */
809 if (usbdev
->descriptor
.idProduct
!= ACX100_PRODUCT_ID_BOOTED
)
810 /* device not unbooted, but invalid USB ID!? */
815 /* Ok, so it's our device and it has already booted */
817 /* Allocate memory for a network device */
819 ieee
= ieee80211_alloc_hw(sizeof(*adev
), &acxusb_hw_ops
);
821 msg
= "no memory for ieee80211_dev\n";
826 ieee
->flags
&= ~IEEE80211_HW_RX_INCLUDES_FCS
;
827 /* TODO: mainline doesn't support the following flags yet */
829 ~IEEE80211_HW_MONITOR_DURING_OPER &
830 ~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
->radio_type
= radio_type
;
844 /* well, actually it's a TNETW1450, but since it
845 * seems to be sufficiently similar to TNETW1130,
846 * I don't want to change large amounts of code now */
847 adev
->chip_type
= CHIPTYPE_ACX111
;
849 adev
->chip_type
= CHIPTYPE_ACX100
;
852 adev
->usbdev
= usbdev
;
853 spin_lock_init(&adev
->spinlock
); /* initial state: unlocked */
854 mutex_init(&adev
->mutex
);
856 /* Check that this is really the hardware we know about.
857 ** If not sure, at least notify the user that he
858 ** may be in trouble...
860 numconfigs
= (int)usbdev
->descriptor
.bNumConfigurations
;
862 acx_log(LOG_WARNING
, L_ANY
, "number of configurations is %d, "
863 "this driver only knows how to handle 1, "
864 "be prepared for surprises\n", numconfigs
);
866 config
= &usbdev
->config
->desc
;
867 numfaces
= config
->bNumInterfaces
;
869 acx_log(LOG_WARNING
, L_ANY
, "number of interfaces is %d, "
870 "this driver only knows how to handle 1, "
871 "be prepared for surprises\n", numfaces
);
873 ifdesc
= &intf
->altsetting
->desc
;
874 numep
= ifdesc
->bNumEndpoints
;
875 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "# of endpoints: %d\n", numep
);
881 /* obtain information about the endpoint
882 ** addresses, begin with some default values
886 for (i
= 0; i
< numep
; i
++) {
887 ep
= usbdev
->ep_in
[i
];
891 if (epdesc
->bmAttributes
& USB_ENDPOINT_XFER_BULK
) {
892 if (epdesc
->bEndpointAddress
& 0x80)
894 epdesc
->bEndpointAddress
& 0xF;
897 epdesc
->bEndpointAddress
& 0xF;
901 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
902 "bulkout ep: 0x%X\n", adev
->bulkoutep
);
903 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "bulkin ep: 0x%X\n", adev
->bulkinep
);
905 /* already done by memset: adev->rxtruncsize = 0; */
906 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "TXBUFSIZE=%d RXBUFSIZE=%d\n",
907 (int)TXBUFSIZE
, (int)RXBUFSIZE
);
909 /* Allocate the RX/TX containers. */
910 adev
->usb_tx
= kmalloc(sizeof(usb_tx_t
) * ACX_TX_URB_CNT
, GFP_KERNEL
);
912 msg
= "no memory for tx container";
915 adev
->usb_rx
= kmalloc(sizeof(usb_rx_t
) * ACX_RX_URB_CNT
, GFP_KERNEL
);
917 msg
= "no memory for rx container";
921 /* Setup URBs for bulk-in/out messages */
922 for (i
= 0; i
< ACX_RX_URB_CNT
; i
++) {
923 adev
->usb_rx
[i
].urb
= usb_alloc_urb(0, GFP_KERNEL
);
924 if (!adev
->usb_rx
[i
].urb
) {
925 msg
= "no memory for input URB\n";
928 adev
->usb_rx
[i
].urb
->status
= 0;
929 adev
->usb_rx
[i
].adev
= adev
;
930 adev
->usb_rx
[i
].busy
= 0;
933 for (i
= 0; i
< ACX_TX_URB_CNT
; i
++) {
934 adev
->usb_tx
[i
].urb
= usb_alloc_urb(0, GFP_KERNEL
);
935 if (!adev
->usb_tx
[i
].urb
) {
936 msg
= "no memory for output URB\n";
939 adev
->usb_tx
[i
].urb
->status
= 0;
940 adev
->usb_tx
[i
].adev
= adev
;
941 adev
->usb_tx
[i
].busy
= 0;
943 adev
->tx_free
= ACX_TX_URB_CNT
;
945 usb_set_intfdata(intf
, adev
);
946 SET_IEEE80211_DEV(ieee
, &intf
->dev
);
948 /* TODO: move all of fw cmds to open()? But then we won't know our MAC addr
949 until ifup (it's available via reading ACX1xx_REG_DOT11_STATION_ID)... */
951 /* put acx out of sleep mode and initialize it */
952 acx_s_issue_cmd(adev
, ACX1xx_CMD_WAKE
, NULL
, 0);
954 result
= acx_s_init_mac(adev
);
958 /* TODO: see similar code in pci.c */
959 acxusb_s_read_eeprom_version(adev
);
960 acxusb_s_fill_configoption(adev
);
961 acx_s_set_defaults(adev
);
962 acx_s_get_firmware_version(adev
);
963 acx_display_hardware_details(adev
);
965 /* MAC_COPY(ndev->dev_addr, adev->dev_addr); */
967 err
= acx_setup_modes(adev
);
969 msg
= "can't register hwmode\n";
973 /* Register the network device */
974 acx_log(LOG_DEBUG
, L_INIT
, "registering network device\n");
975 result
= ieee80211_register_hw(adev
->ieee
);
977 msg
= "failed to register USB network device "
982 acx_proc_register_entries(ieee
);
985 acx_log(LOG_INFO
, L_ANY
, "USB module " ACX_RELEASE
986 " loaded successfully\n");
988 acx_init_task_scheduler(adev
);
991 great_inquisitor(adev
);
994 /* Everything went OK, we are happy now */
1003 for (i
= 0; i
< ACX_RX_URB_CNT
; i
++)
1004 usb_free_urb(adev
->usb_rx
[i
].urb
);
1005 kfree(adev
->usb_rx
);
1008 for (i
= 0; i
< ACX_TX_URB_CNT
; i
++)
1009 usb_free_urb(adev
->usb_tx
[i
].urb
);
1010 kfree(adev
->usb_tx
);
1012 ieee80211_free_hw(ieee
);
1019 /* no device we could handle, return error. */
1028 /***********************************************************************
1029 ** acxusb_e_disconnect()
1031 ** This function is invoked whenever the user pulls the plug from the USB
1032 ** device or the module is removed from the kernel. In these cases, the
1033 ** network devices have to be taken down and all allocated memory has
1036 void acxusb_e_disconnect(struct usb_interface
*intf
)
1038 unsigned long flags
;
1040 acx_device_t
*adev
= usb_get_intfdata(intf
);
1044 /* No WLAN device... no sense */
1048 /* Unregister network device
1050 * If the interface is up, unregister_netdev() will take
1051 * care of calling our close() function, which takes
1052 * care of unlinking the urbs, sending the device to
1054 * This can't be called with sem or lock held because
1055 * _close() will try to grab it as well if it's called,
1056 * deadlocking the machine.
1058 acx_proc_unregister_entries(adev
->ieee
);
1059 ieee80211_unregister_hw(adev
->ieee
);
1062 acx_lock(adev
, flags
);
1063 /* This device exists no more */
1064 usb_set_intfdata(intf
, NULL
);
1067 * Here we only free them. _close() took care of
1070 for (i
= 0; i
< ACX_RX_URB_CNT
; ++i
) {
1071 usb_free_urb(adev
->usb_rx
[i
].urb
);
1073 for (i
= 0; i
< ACX_TX_URB_CNT
; ++i
) {
1074 usb_free_urb(adev
->usb_tx
[i
].urb
);
1077 /* Freeing containers */
1078 kfree(adev
->usb_rx
);
1079 kfree(adev
->usb_tx
);
1081 acx_unlock(adev
, flags
);
1082 acx_sem_unlock(adev
);
1084 ieee80211_free_hw(adev
->ieee
);
1089 /***********************************************************************
1091 ** This function is called when the user sets up the network interface.
1092 ** It initializes a management timer, sets up the USB card and starts
1093 ** the network tx queue and USB receive.
1095 int acxusb_e_open(struct ieee80211_hw
*hw
)
1097 acx_device_t
*adev
= ieee2adev(hw
);
1098 unsigned long flags
;
1105 /* put the ACX100 out of sleep mode */
1106 // acx_s_issue_cmd(adev, ACX1xx_CMD_WAKE, NULL, 0);
1108 init_timer(&adev
->mgmt_timer
);
1109 adev
->mgmt_timer
.function
= acx_i_timer
;
1110 adev
->mgmt_timer
.data
= (unsigned long)adev
;
1112 /* acx_s_start needs it */
1113 SET_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
1116 /* don't acx_start_queue() here, we need to associate first */
1118 acx_lock(adev
, flags
);
1119 for (i
= 0; i
< ACX_RX_URB_CNT
; i
++) {
1120 adev
->usb_rx
[i
].urb
->status
= 0;
1123 acxusb_l_poll_rx(adev
, &adev
->usb_rx
[0]);
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 static void 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
);
1203 /***********************************************************************
1205 ** This function (re)initiates a bulk-in USB transfer on a given urb
1207 void acxusb_l_poll_rx(acx_device_t
* adev
, usb_rx_t
* rx
)
1209 struct usb_device
*usbdev
;
1212 unsigned int inpipe
;
1217 usbdev
= adev
->usbdev
;
1219 rxnum
= rx
- adev
->usb_rx
;
1221 inpipe
= usb_rcvbulkpipe(usbdev
, adev
->bulkinep
);
1222 if (unlikely(rxurb
->status
== -EINPROGRESS
)) {
1223 acx_log(LOG_WARNING
, L_ANY
,
1224 "error, rx triggered while rx urb in progress\n");
1225 /* FIXME: this is nasty, receive is being cancelled by this code
1226 * on the other hand, this should not happen anyway...
1228 usb_unlink_urb(rxurb
);
1229 } else if (unlikely(rxurb
->status
== -ECONNRESET
)) {
1230 acx_log(LOG_DEBUG
, L_USBRXTX
,
1231 "_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 acx_log(LOG_DEBUG
, L_USBRXTX
,
1246 "SUBMIT RX (%d) inpipe=0x%X size=%d errcode=%d\n",
1247 rxnum
, inpipe
, (int)RXBUFSIZE
, errcode
);
1253 /***********************************************************************
1254 ** acxusb_i_complete_rx()
1256 ** urb -> pointer to USB request block
1257 ** regs -> pointer to register-buffer for syscalls (see asm/ptrace.h)
1259 ** This function is invoked by USB subsystem whenever a bulk receive
1261 ** The received data is then committed to the network stack and the next
1262 ** USB receive is triggered.
1264 void acxusb_i_complete_rx(struct urb
*urb
)
1270 unsigned long flags
;
1271 int size
, remsize
, packetsize
, rxnum
;
1275 BUG_ON(!urb
->context
);
1277 rx
= (usb_rx_t
*) urb
->context
;
1280 acx_lock(adev
, flags
);
1283 * Happens on disconnect or close. Don't play with the urb.
1284 * Don't resubmit it. It will get unlinked by close()
1286 if (unlikely(!(adev
->dev_state_mask
& ACX_STATE_IFACE_UP
))) {
1287 acx_log(LOG_DEBUG
, L_USBRXTX
,
1288 "rx: device is down, not doing anything\n");
1292 inbuf
= &rx
->bulkin
;
1293 size
= urb
->actual_length
;
1295 rxnum
= rx
- adev
->usb_rx
;
1297 acx_log(LOG_DEBUG
, L_USBRXTX
, "RETURN RX (%d) status=%d size=%d\n",
1298 rxnum
, urb
->status
, size
);
1300 /* Send the URB that's waiting. */
1301 acx_log(LOG_DEBUG
, L_USBRXTX
, "rxnum=%d, sending=%d\n",
1303 acxusb_l_poll_rx(adev
, &adev
->usb_rx
[rxnum
^ 1]);
1305 if (unlikely(size
> sizeof(rxbuffer_t
)))
1306 acx_log(LOG_WARNING
, L_ANY
,
1307 "rx too large: %d, please report\n", size
);
1309 /* check if the transfer was aborted */
1310 switch (urb
->status
) {
1311 case 0: /* No error */
1314 acx_log(LOG_WARNING
, L_ANY
, "rx data overrun\n");
1315 adev
->rxtruncsize
= 0; /* Not valid anymore. */
1318 adev
->rxtruncsize
= 0;
1320 case -ESHUTDOWN
: /* rmmod */
1321 adev
->rxtruncsize
= 0;
1324 adev
->rxtruncsize
= 0;
1325 adev
->stats
.rx_errors
++;
1326 acx_log(LOG_WARNING
, L_ANY
, "rx error (urb status=%d)\n", urb
->status
);
1330 if (unlikely(!size
))
1331 acx_log(LOG_WARNING
, L_ANY
, "warning, encountered zerolength rx packet\n");
1333 if (urb
->transfer_buffer
!= inbuf
)
1336 /* check if previous frame was truncated
1337 ** FIXME: this code can only handle truncation
1338 ** of consecutive packets!
1341 if (adev
->rxtruncsize
) {
1344 * FIXME: packetsize UNDEFINED, says gcc. And it is, indeed.
1346 acx_log(LOG_WARNING
, L_ANY
,
1347 "handling truncated frame (truncsize=%d size=%d "
1348 "packetsize(from trunc)=%d)\n",
1349 adev
->rxtruncsize
, size
, packetsize
);
1351 ptr
= &adev
->rxtruncbuf
;
1352 packetsize
= RXBUF_BYTES_USED(ptr
);
1353 acx_log_dump(LOG_WARNING
, L_USBRXTX
, ptr
, RXBUF_HDRSIZE
,
1355 acx_log_dump(LOG_WARNING
, L_USBRXTX
, inbuf
, RXBUF_HDRSIZE
,
1356 "Dumping inbuf:\n");
1358 /* bytes needed for rxtruncbuf completion: */
1359 tail_size
= packetsize
- adev
->rxtruncsize
;
1361 if (size
< tail_size
) {
1362 /* there is not enough data to complete this packet,
1363 ** simply append the stuff to the truncation buffer
1365 memcpy(((char *)ptr
) + adev
->rxtruncsize
, inbuf
, size
);
1366 adev
->rxtruncsize
+= size
;
1369 /* ok, this data completes the previously
1370 ** truncated packet. copy it into a descriptor
1371 ** and give it to the rest of the stack */
1373 /* append tail to previously truncated part
1374 ** NB: adev->rxtruncbuf (pointed to by ptr) can't
1375 ** overflow because this is already checked before
1376 ** truncation buffer was filled. See below,
1377 ** "if (packetsize > sizeof(rxbuffer_t))..." code */
1378 memcpy(((char *)ptr
) + adev
->rxtruncsize
, inbuf
,
1381 acx_log_dump(LOG_DEBUG
, L_USBRXTX
, inbuf
,
1382 tail_size
+ RXBUF_HDRSIZE
,
1383 "full trainling packet + 12 bytes:\n");
1384 acx_l_process_rxbuf(adev
, ptr
);
1385 adev
->rxtruncsize
= 0;
1386 ptr
= (rxbuffer_t
*) (((char *)inbuf
) + tail_size
);
1387 remsize
-= tail_size
;
1389 acx_log(LOG_INFO
, L_USBRXTX
, "post-merge size=%d remsize=%d\n",
1393 /* size = USB data block size
1394 ** remsize = unprocessed USB bytes left
1395 ** ptr = current pos in USB data block
1398 if (remsize
< RXBUF_HDRSIZE
) {
1399 acx_log(LOG_WARNING
, L_ANY
, "truncated rx header (%d bytes)!\n",
1402 acx_dump_bytes(ptr
, remsize
);
1406 packetsize
= RXBUF_BYTES_USED(ptr
);
1407 acx_log(LOG_DEBUG
, L_USBRXTX
,
1408 "packet with packetsize=%d\n", packetsize
);
1410 if (RXBUF_IS_TXSTAT(ptr
)) {
1411 /* do rate handling */
1412 usb_txstatus_t
*stat
= (void *)ptr
;
1414 acx_log(LOG_DEBUG
, L_USBRXTX
,
1415 "tx: stat: mac_cnt_rcvd:%04X "
1416 "queue_index:%02X mac_status:%02X "
1417 "hostdata:%08X rate:%u ack_failures:%02X "
1418 "rts_failures:%02X rts_ok:%02X\n",
1419 stat
->mac_cnt_rcvd
, stat
->queue_index
,
1420 stat
->mac_status
, stat
->hostdata
, stat
->rate
,
1421 stat
->ack_failures
, stat
->rts_failures
,
1424 if (adev->rate_auto && client_no < VEC_SIZE(adev->sta_list)) {
1425 client_t *clt = &adev->sta_list[client_no];
1426 u16 cur = stat->hostdata >> 16;
1428 if (clt && clt->rate_cur == cur) {
1429 acx_l_handle_txrate_auto(adev, clt,
1430 cur, // intended rate
1431 stat->rate, 0, // actually used rate
1432 stat->mac_status, // error?
1433 ACX_TX_URB_CNT - adev->tx_free);
1439 if (packetsize
> sizeof(rxbuffer_t
)) {
1440 acx_log(LOG_WARNING
, L_ANY
, "packet exceeds max wlan "
1441 "frame size (%d > %d). size=%d\n",
1442 packetsize
, (int)sizeof(rxbuffer_t
), size
);
1444 acx_dump_bytes(ptr
, 16);
1445 /* FIXME: put some real error-handling in here! */
1449 if (packetsize
> remsize
) {
1450 /* frame truncation handling */
1451 acx_log_dump(LOG_WARNING
, L_USBRXTX
, ptr
, RXBUF_HDRSIZE
,
1452 "need to truncate packet (packetsize=%d, "
1453 "remsize=%d, size=%d):\n");
1454 memcpy(&adev
->rxtruncbuf
, ptr
, remsize
);
1455 adev
->rxtruncsize
= remsize
;
1459 /* packetsize <= remsize */
1460 /* now handle the received data */
1461 acx_l_process_rxbuf(adev
, ptr
);
1463 ptr
= (rxbuffer_t
*) (((char *)ptr
) + packetsize
);
1464 remsize
-= packetsize
;
1465 acx_log_dump(LOG_WARNING
, L_USBRXTX
, ptr
, RXBUF_HDRSIZE
,
1466 "more than one packet in buffer! Second packet hdr:\n");
1470 acx_unlock(adev
, flags
);
1476 /***********************************************************************
1477 ** acxusb_i_complete_tx()
1479 ** urb -> pointer to USB request block
1480 ** regs -> pointer to register-buffer for syscalls (see asm/ptrace.h)
1482 ** This function is invoked upon termination of a USB transfer.
1484 void acxusb_i_complete_tx(struct urb
*urb
)
1488 unsigned long flags
;
1493 BUG_ON(!urb
->context
);
1495 tx
= (usb_tx_t
*) urb
->context
;
1498 txnum
= tx
- adev
->usb_tx
;
1500 acx_lock(adev
, flags
);
1503 * If the iface isn't up, we don't have any right
1504 * to play with them. The urb may get unlinked.
1506 if (unlikely(!(adev
->dev_state_mask
& ACX_STATE_IFACE_UP
))) {
1507 acx_log(LOG_INFO
, L_USBRXTX
,
1508 "tx: device is down, not doing anything\n");
1512 acx_log(LOG_INFO
, L_USBRXTX
, "RETURN TX (%d): status=%d size=%d\n",
1513 txnum
, urb
->status
, urb
->actual_length
);
1515 /* handle USB transfer errors */
1516 switch (urb
->status
) {
1517 case 0: /* No error */
1525 /* FIXME: real error-handling code here please */
1527 acx_log(LOG_WARNING
, L_ANY
, "tx error, urb status=%d\n", urb
->status
);
1528 /* FIXME: real error-handling code here please */
1531 /* free the URB and check for more data */
1534 if ((adev
->tx_free
>= TX_START_QUEUE
)
1535 && (adev
->status
== ACX_STATUS_4_ASSOCIATED
)
1536 /* && (acx_queue_stopped(adev->ndev)*/) {
1537 acx_log(LOG_DEBUG
, L_BUF
,
1538 "tx: wake queue (%u free txbufs)\n", adev
->tx_free
);
1539 /* acx_wake_queue(adev->ndev, NULL); */
1543 acx_unlock(adev
, flags
);
1549 /***************************************************************
1550 ** acxusb_l_alloc_tx
1551 ** Actually returns a usb_tx_t* ptr
1553 tx_t
*acxusb_l_alloc_tx(acx_device_t
* adev
)
1560 head
= adev
->tx_head
;
1562 head
= (head
+ 1) % ACX_TX_URB_CNT
;
1563 if (!adev
->usb_tx
[head
].busy
) {
1564 acx_log(LOG_DEBUG
, L_USBRXTX
,
1565 "allocated tx %d\n", head
);
1566 tx
= &adev
->usb_tx
[head
];
1569 /* Keep a few free descs between head and tail of tx ring.
1570 ** It is not absolutely needed, just feels safer */
1571 if (adev
->tx_free
< TX_STOP_QUEUE
) {
1572 acx_log(LOG_DEBUG
, L_BUF
, "tx: stop queue "
1573 "(%u free txbufs)\n", adev
->tx_free
);
1574 /* acx_stop_queue(adev->ndev, NULL); */
1578 } while (likely(head
!= adev
->tx_head
));
1580 acx_log_ratelimited(LOG_WARNING
, L_ANY
, "tx buffers full\n");
1582 adev
->tx_head
= head
;
1588 /***************************************************************
1589 ** Used if alloc_tx()'ed buffer needs to be cancelled without doing tx
1591 void acxusb_l_dealloc_tx(tx_t
* tx_opaque
)
1593 usb_tx_t
*tx
= (usb_tx_t
*) tx_opaque
;
1598 /***************************************************************
1600 void *acxusb_l_get_txbuf(acx_device_t
* adev
, tx_t
* tx_opaque
)
1602 usb_tx_t
*tx
= (usb_tx_t
*) tx_opaque
;
1603 return &tx
->bulkout
.data
;
1607 /***************************************************************
1610 ** Can be called from IRQ (rx -> (AP bridging or mgmt response) -> tx).
1611 ** Can be called from acx_i_start_xmit (data frames from net core).
1613 void acxusb_l_tx_data(acx_device_t
* adev
, tx_t
* tx_opaque
, int wlanpkt_len
, struct ieee80211_tx_control
*ctl
,
1614 struct sk_buff
* skb
)
1616 struct usb_device
*usbdev
;
1619 usb_txbuffer_t
*txbuf
;
1621 struct ieee80211_hdr
*whdr
;
1622 unsigned int outpipe
;
1627 tx
= ((usb_tx_t
*) tx_opaque
);
1629 txbuf
= &tx
->bulkout
;
1630 whdr
= (struct ieee80211_hdr
*) txbuf
->data
;
1631 txnum
= tx
- adev
->usb_tx
;
1633 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "using buf#%d free=%d len=%d\n",
1634 txnum
, adev
->tx_free
, wlanpkt_len
);
1636 switch (adev->mode) {
1637 case ACX_MODE_0_ADHOC:
1639 clt = acx_l_sta_list_get(adev, whdr->a1);
1641 case ACX_MODE_2_STA:
1642 // clt = adev->ap_client;
1648 if (unlikely(clt && !clt->rate_cur)) {
1649 acx_log(LOG_INFO, L_ANY, "driver bug! bad ratemask\n");
1654 /* fill the USB transfer header */
1655 txbuf
->desc
= cpu_to_le16(USB_TXBUF_TXDESC
);
1656 txbuf
->mpdu_len
= cpu_to_le16(wlanpkt_len
);
1657 txbuf
->queue_index
= 1;
1658 txbuf
->rate
= ctl
->tx_rate
; //clt->rate_100;
1659 // FIXME(); //This used to have | (clt - adev->ap_client)
1660 txbuf
->hostdata
= (ctl
->tx_rate
<< 16);
1661 txbuf
->ctrl1
= DESC_CTL_FIRSTFRAG
;
1662 if (1 == adev
->preamble_cur
)
1663 SET_BIT(txbuf
->ctrl1
, DESC_CTL_SHORT_PREAMBLE
);
1665 txbuf
->data_len
= cpu_to_le16(wlanpkt_len
);
1667 acx_log_dump(LOG_DEBUG
, L_DATA
, txbuf
, wlanpkt_len
+ USB_TXBUF_HDRSIZE
,
1668 "dump of bulk out urb:\n");
1670 if (unlikely(txurb
->status
== -EINPROGRESS
)) {
1671 acx_log(LOG_WARNING
, L_ANY
,
1672 "trying to submit tx urb while already in progress\n");
1675 /* now schedule the USB transfer */
1676 usbdev
= adev
->usbdev
;
1677 outpipe
= usb_sndbulkpipe(usbdev
, adev
->bulkoutep
);
1679 usb_fill_bulk_urb(txurb
, usbdev
, outpipe
, txbuf
, /* dataptr */
1680 wlanpkt_len
+ USB_TXBUF_HDRSIZE
, /* size */
1681 acxusb_i_complete_tx
, /* handler */
1682 tx
/* handler param */
1685 txurb
->transfer_flags
= URB_ASYNC_UNLINK
| URB_ZERO_PACKET
;
1686 ucode
= usb_submit_urb(txurb
, GFP_ATOMIC
);
1687 acx_log(LOG_DEBUG
, L_USBRXTX
,
1688 "SUBMIT TX (%d): outpipe=0x%X buf=%p txsize=%d "
1689 "rate=%u errcode=%d\n", txnum
, outpipe
, txbuf
,
1690 wlanpkt_len
+ USB_TXBUF_HDRSIZE
, txbuf
->rate
, ucode
);
1692 if (unlikely(ucode
)) {
1693 acx_log(LOG_WARNING
, L_ANY
, "submit_urb() error=%d txsize=%d\n",
1694 ucode
, wlanpkt_len
+ USB_TXBUF_HDRSIZE
);
1696 /* on error, just mark the frame as done and update
1699 adev
->stats
.tx_errors
++;
1702 /* needed? if (adev->tx_free > TX_START_QUEUE) acx_wake_queue(...) */
1708 /***********************************************************************
1709 static void acxusb_i_set_rx_mode(struct net_device *ndev)
1715 /***********************************************************************
1717 #ifdef HAVE_TX_TIMEOUT
1719 void acxusb_i_tx_timeout(struct net_device *ndev)
1721 acx_device_t *adev = ndev2adev(ndev);
1722 unsigned long flags;
1727 acx_lock(adev, flags);
1728 */ /* unlink the URBs */
1729 /* for (i = 0; i < ACX_TX_URB_CNT; i++) {
1730 acxusb_unlink_urb(adev->usb_tx[i].urb);
1731 adev->usb_tx[i].busy = 0;
1733 adev->tx_free = ACX_TX_URB_CNT;
1734 */ /* TODO: stats update */
1735 /* acx_unlock(adev, flags);
1743 /***********************************************************************
1746 ** This function is invoked upon loading of the kernel module.
1747 ** It registers itself at the kernel's USB subsystem.
1749 ** Returns: Errorcode on failure, 0 on success
1751 int __init
acxusb_e_init_module(void)
1753 acx_log(LOG_INFO
, L_INIT
, "USB module " ACX_RELEASE
" initialized, "
1754 "probing for devices...\n");
1755 return usb_register(&acxusb_driver
);
1760 /***********************************************************************
1763 ** This function is invoked as last step of the module unloading. It simply
1764 ** deregisters this module at the kernel's USB subsystem.
1766 void __exit
acxusb_e_cleanup_module(void)
1768 usb_deregister(&acxusb_driver
);
1769 acx_log(LOG_INFO
, L_INIT
, "USB module " ACX_RELEASE
" unloaded\n");
1773 /***********************************************************************
1779 static void dump_device(struct usb_device
*usbdev
)
1782 struct usb_config_descriptor
*cd
;
1784 acx_log(LOG_INFO
, L_ANY
, "acx device dump:\n");
1785 acx_log(LOG_INFO
, L_ANY
, " devnum: %d\n", usbdev
->devnum
);
1786 acx_log(LOG_INFO
, L_ANY
, " speed: %d\n", usbdev
->speed
);
1787 acx_log(LOG_INFO
, L_ANY
, " tt: 0x%X\n", (unsigned int)(usbdev
->tt
));
1788 acx_log(LOG_INFO
, L_ANY
, " ttport: %d\n", (unsigned int)(usbdev
->ttport
));
1789 acx_log(LOG_INFO
, L_ANY
, " toggle[0]: 0x%X toggle[1]: 0x%X\n",
1790 (unsigned int)(usbdev
->toggle
[0]),
1791 (unsigned int)(usbdev
->toggle
[1]));
1792 /* This saw a change after 2.6.10 */
1793 acx_log(LOG_INFO
, L_ANY
, " ep_in wMaxPacketSize: ");
1794 for (i
= 0; i
< 16; ++i
)
1795 if (usbdev
->ep_in
[i
] != NULL
)
1797 usbdev
->ep_in
[i
]->desc
.wMaxPacketSize
);
1799 acx_log(LOG_INFO
, L_ANY
, " ep_out wMaxPacketSize: ");
1800 for (i
= 0; i
< ARRAY_SIZE(usbdev
->ep_out
); ++i
)
1801 if (usbdev
->ep_out
[i
] != NULL
)
1803 usbdev
->ep_out
[i
]->desc
.wMaxPacketSize
);
1805 acx_log(LOG_INFO
, L_ANY
, " parent: 0x%X\n", (unsigned int)usbdev
->parent
);
1806 acx_log(LOG_INFO
, L_ANY
, " bus: 0x%X\n", (unsigned int)usbdev
->bus
);
1808 acx_log(LOG_INFO
, L_ANY
, " configs: ");
1809 for (i
= 0; i
< usbdev
->descriptor
.bNumConfigurations
; i
++)
1810 printk("0x%X ", usbdev
->config
[i
]);
1813 acx_log(LOG_INFO
, L_ANY
, " actconfig: %p\n", usbdev
->actconfig
);
1814 dump_device_descriptor(&usbdev
->descriptor
);
1816 cd
= &usbdev
->config
->desc
;
1817 dump_config_descriptor(cd
);
1821 /***********************************************************************
1823 static void dump_config_descriptor(struct usb_config_descriptor
*cd
)
1825 acx_log(LOG_INFO
, L_ANY
, "Configuration Descriptor:\n");
1827 acx_log(LOG_INFO
, L_ANY
, "NULL\n");
1830 acx_log(LOG_INFO
, L_ANY
, " bLength: %d (0x%X)\n", cd
->bLength
, cd
->bLength
);
1831 acx_log(LOG_INFO
, L_ANY
, " bDescriptorType: %d (0x%X)\n", cd
->bDescriptorType
,
1832 cd
->bDescriptorType
);
1833 acx_log(LOG_INFO
, L_ANY
, " bNumInterfaces: %d (0x%X)\n", cd
->bNumInterfaces
,
1834 cd
->bNumInterfaces
);
1835 acx_log(LOG_INFO
, L_ANY
, " bConfigurationValue: %d (0x%X)\n", cd
->bConfigurationValue
,
1836 cd
->bConfigurationValue
);
1837 acx_log(LOG_INFO
, L_ANY
, " iConfiguration: %d (0x%X)\n", cd
->iConfiguration
,
1838 cd
->iConfiguration
);
1839 acx_log(LOG_INFO
, L_ANY
, " bmAttributes: %d (0x%X)\n", cd
->bmAttributes
,
1841 /* acx_log(LOG_INFO, L_ANY, " MaxPower: %d (0x%X)\n", cd->bMaxPower, cd->bMaxPower); */
1845 static void dump_device_descriptor(struct usb_device_descriptor
*dd
)
1847 acx_log(LOG_INFO
, L_ANY
, "Device Descriptor:\n");
1849 acx_log(LOG_INFO
, L_ANY
, "NULL\n");
1852 acx_log(LOG_INFO
, L_ANY
, " bLength: %d (0x%X)\n", dd
->bLength
, dd
->bLength
);
1853 acx_log(LOG_INFO
, L_ANY
, " bDescriptortype: %d (0x%X)\n", dd
->bDescriptorType
,
1854 dd
->bDescriptorType
);
1855 acx_log(LOG_INFO
, L_ANY
, " bcdUSB: %d (0x%X)\n", dd
->bcdUSB
, dd
->bcdUSB
);
1856 acx_log(LOG_INFO
, L_ANY
, " bDeviceClass: %d (0x%X)\n", dd
->bDeviceClass
,
1858 acx_log(LOG_INFO
, L_ANY
, " bDeviceSubClass: %d (0x%X)\n", dd
->bDeviceSubClass
,
1859 dd
->bDeviceSubClass
);
1860 acx_log(LOG_INFO
, L_ANY
, " bDeviceProtocol: %d (0x%X)\n", dd
->bDeviceProtocol
,
1861 dd
->bDeviceProtocol
);
1862 acx_log(LOG_INFO
, L_ANY
, " bMaxPacketSize0: %d (0x%X)\n", dd
->bMaxPacketSize0
,
1863 dd
->bMaxPacketSize0
);
1864 acx_log(LOG_INFO
, L_ANY
, " idVendor: %d (0x%X)\n", dd
->idVendor
, dd
->idVendor
);
1865 acx_log(LOG_INFO
, L_ANY
, " idProduct: %d (0x%X)\n", dd
->idProduct
, dd
->idProduct
);
1866 acx_log(LOG_INFO
, L_ANY
, " bcdDevice: %d (0x%X)\n", dd
->bcdDevice
, dd
->bcdDevice
);
1867 acx_log(LOG_INFO
, L_ANY
, " iManufacturer: %d (0x%X)\n", dd
->iManufacturer
,
1869 acx_log(LOG_INFO
, L_ANY
, " iProduct: %d (0x%X)\n", dd
->iProduct
, dd
->iProduct
);
1870 acx_log(LOG_INFO
, L_ANY
, " iSerialNumber: %d (0x%X)\n", dd
->iSerialNumber
,
1872 acx_log(LOG_INFO
, L_ANY
, " bNumConfigurations: %d (0x%X)\n", dd
->bNumConfigurations
,
1873 dd
->bNumConfigurations
);
1877 #endif /* ACX_DEBUG */