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(L_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
;
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_IE_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 INTERROGATE command, just pass the length
315 * of parameters to read, as data */
316 if (cmd
== ACX1xx_CMD_INTERROGATE
) {
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 interrogate(type:ACX100_IE_DOT11_ED_THRESHOLD,len:4)
376 issue_cmd(cmd:ACX1xx_CMD_INTERROGATE,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_INTERROGATE
) && 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_interrogate(adev
, &eeprom_ver
, ACX1FF_IE_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
->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
->spinlock
); /* 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 acx_log(LOG_WARNING
, L_ANY
, "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 acx_log(LOG_WARNING
, L_ANY
, "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 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "# 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 ep
= usbdev
->ep_in
[i
];
892 if (epdesc
->bmAttributes
& USB_ENDPOINT_XFER_BULK
) {
893 if (epdesc
->bEndpointAddress
& 0x80)
895 epdesc
->bEndpointAddress
& 0xF;
898 epdesc
->bEndpointAddress
& 0xF;
902 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
903 "bulkout ep: 0x%X\n", adev
->bulkoutep
);
904 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "bulkin ep: 0x%X\n", adev
->bulkinep
);
906 /* already done by memset: adev->rxtruncsize = 0; */
907 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "TXBUFSIZE=%d RXBUFSIZE=%d\n",
908 (int)TXBUFSIZE
, (int)RXBUFSIZE
);
910 /* Allocate the RX/TX containers. */
911 adev
->usb_tx
= kmalloc(sizeof(usb_tx_t
) * ACX_TX_URB_CNT
, GFP_KERNEL
);
913 msg
= "no memory for tx container";
916 adev
->usb_rx
= kmalloc(sizeof(usb_rx_t
) * ACX_RX_URB_CNT
, GFP_KERNEL
);
918 msg
= "no memory for rx container";
922 /* Setup URBs for bulk-in/out messages */
923 for (i
= 0; i
< ACX_RX_URB_CNT
; i
++) {
924 adev
->usb_rx
[i
].urb
= usb_alloc_urb(0, GFP_KERNEL
);
925 if (!adev
->usb_rx
[i
].urb
) {
926 msg
= "no memory for input URB\n";
929 adev
->usb_rx
[i
].urb
->status
= 0;
930 adev
->usb_rx
[i
].adev
= adev
;
931 adev
->usb_rx
[i
].busy
= 0;
934 for (i
= 0; i
< ACX_TX_URB_CNT
; i
++) {
935 adev
->usb_tx
[i
].urb
= usb_alloc_urb(0, GFP_KERNEL
);
936 if (!adev
->usb_tx
[i
].urb
) {
937 msg
= "no memory for output URB\n";
940 adev
->usb_tx
[i
].urb
->status
= 0;
941 adev
->usb_tx
[i
].adev
= adev
;
942 adev
->usb_tx
[i
].busy
= 0;
944 adev
->tx_free
= ACX_TX_URB_CNT
;
946 usb_set_intfdata(intf
, adev
);
947 SET_IEEE80211_DEV(ieee
, &intf
->dev
);
949 /* TODO: move all of fw cmds to open()? But then we won't know our MAC addr
950 until ifup (it's available via reading ACX1xx_IE_DOT11_STATION_ID)... */
952 /* put acx out of sleep mode and initialize it */
953 acx_s_issue_cmd(adev
, ACX1xx_CMD_WAKE
, NULL
, 0);
955 result
= acx_s_init_mac(adev
);
959 /* TODO: see similar code in pci.c */
960 acxusb_s_read_eeprom_version(adev
);
961 acxusb_s_fill_configoption(adev
);
962 acx_s_set_defaults(adev
);
963 acx_s_get_firmware_version(adev
);
964 acx_display_hardware_details(adev
);
966 /* MAC_COPY(ndev->dev_addr, adev->dev_addr); */
968 err
= acx_setup_modes(adev
);
970 msg
= "can't register hwmode\n";
974 /* Register the network device */
975 acx_log(LOG_DEBUG
, L_INIT
, "registering network device\n");
976 result
= ieee80211_register_hw(adev
->ieee
);
978 msg
= "failed to register USB network device "
983 acx_proc_register_entries(ieee
);
986 acx_log(LOG_INFO
, L_ANY
, "USB module " ACX_RELEASE
987 " loaded successfully\n");
989 acx_init_task_scheduler(adev
);
992 great_inquisitor(adev
);
995 /* Everything went OK, we are happy now */
1000 printk(msg
, result
);
1004 for (i
= 0; i
< ACX_RX_URB_CNT
; i
++)
1005 usb_free_urb(adev
->usb_rx
[i
].urb
);
1006 kfree(adev
->usb_rx
);
1009 for (i
= 0; i
< ACX_TX_URB_CNT
; i
++)
1010 usb_free_urb(adev
->usb_tx
[i
].urb
);
1011 kfree(adev
->usb_tx
);
1013 ieee80211_free_hw(ieee
);
1020 /* no device we could handle, return error. */
1029 /***********************************************************************
1030 ** acxusb_e_disconnect()
1032 ** This function is invoked whenever the user pulls the plug from the USB
1033 ** device or the module is removed from the kernel. In these cases, the
1034 ** network devices have to be taken down and all allocated memory has
1037 void acxusb_e_disconnect(struct usb_interface
*intf
)
1039 unsigned long flags
;
1041 acx_device_t
*adev
= usb_get_intfdata(intf
);
1045 /* No WLAN device... no sense */
1049 /* Unregister network device
1051 * If the interface is up, unregister_netdev() will take
1052 * care of calling our close() function, which takes
1053 * care of unlinking the urbs, sending the device to
1055 * This can't be called with sem or lock held because
1056 * _close() will try to grab it as well if it's called,
1057 * deadlocking the machine.
1059 acx_proc_unregister_entries(adev
->ieee
);
1060 ieee80211_unregister_hw(adev
->ieee
);
1063 acx_lock(adev
, flags
);
1064 /* This device exists no more */
1065 usb_set_intfdata(intf
, NULL
);
1068 * Here we only free them. _close() took care of
1071 for (i
= 0; i
< ACX_RX_URB_CNT
; ++i
) {
1072 usb_free_urb(adev
->usb_rx
[i
].urb
);
1074 for (i
= 0; i
< ACX_TX_URB_CNT
; ++i
) {
1075 usb_free_urb(adev
->usb_tx
[i
].urb
);
1078 /* Freeing containers */
1079 kfree(adev
->usb_rx
);
1080 kfree(adev
->usb_tx
);
1082 acx_unlock(adev
, flags
);
1083 acx_sem_unlock(adev
);
1085 ieee80211_free_hw(adev
->ieee
);
1090 /***********************************************************************
1092 ** This function is called when the user sets up the network interface.
1093 ** It initializes a management timer, sets up the USB card and starts
1094 ** the network tx queue and USB receive.
1096 int acxusb_e_open(struct ieee80211_hw
*hw
)
1098 acx_device_t
*adev
= ieee2adev(hw
);
1099 unsigned long flags
;
1106 /* put the ACX100 out of sleep mode */
1107 // acx_s_issue_cmd(adev, ACX1xx_CMD_WAKE, NULL, 0);
1109 init_timer(&adev
->mgmt_timer
);
1110 adev
->mgmt_timer
.function
= acx_i_timer
;
1111 adev
->mgmt_timer
.data
= (unsigned long)adev
;
1113 /* acx_s_start needs it */
1114 SET_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
1117 /* don't acx_start_queue() here, we need to associate first */
1119 acx_lock(adev
, flags
);
1120 for (i
= 0; i
< ACX_RX_URB_CNT
; i
++) {
1121 adev
->usb_rx
[i
].urb
->status
= 0;
1124 acxusb_l_poll_rx(adev
, &adev
->usb_rx
[0]);
1126 ieee80211_start_queues(adev
->ieee
);
1127 acx_unlock(adev
, flags
);
1129 acx_sem_unlock(adev
);
1136 /***********************************************************************
1139 ** This function stops the network functionality of the interface (invoked
1140 ** when the user calls ifconfig <wlan> down). The tx queue is halted and
1141 ** the device is marked as down. In case there were any pending USB bulk
1142 ** transfers, these are unlinked (asynchronously). The module in-use count
1143 ** is also decreased in this function.
1145 static void acxusb_e_close(struct ieee80211_hw
*hw
)
1147 acx_device_t
*adev
= ieee2adev(hw
);
1148 unsigned long flags
;
1154 if (adev
->dev_state_mask
& ACX_STATE_IFACE_UP
)
1156 // acxusb_e_down(adev);
1157 CLEAR_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
1160 /* Code below is remarkably similar to acxpci_s_down(). Maybe we can merge them? */
1162 acx_free_modes(adev
);
1164 /* Make sure we don't get any more rx requests */
1165 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_RX
, NULL
, 0);
1166 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_TX
, NULL
, 0);
1169 * We must do FLUSH *without* holding sem to avoid a deadlock.
1170 * See pci.c:acxpci_s_down() for deails.
1172 acx_sem_unlock(adev
);
1173 flush_scheduled_work();
1176 /* Power down the device */
1177 acx_s_issue_cmd(adev
, ACX1xx_CMD_SLEEP
, NULL
, 0);
1179 /* Stop the transmit queue, mark the device as DOWN */
1180 acx_lock(adev
, flags
);
1181 // acx_stop_queue(ndev, "on ifdown");
1182 // acx_set_status(adev, ACX_STATUS_0_STOPPED);
1183 /* stop pending rx/tx urb transfers */
1184 for (i
= 0; i
< ACX_TX_URB_CNT
; i
++) {
1185 acxusb_unlink_urb(adev
->usb_tx
[i
].urb
);
1186 adev
->usb_tx
[i
].busy
= 0;
1188 for (i
= 0; i
< ACX_RX_URB_CNT
; i
++) {
1189 acxusb_unlink_urb(adev
->usb_rx
[i
].urb
);
1190 adev
->usb_rx
[i
].busy
= 0;
1192 adev
->tx_free
= ACX_TX_URB_CNT
;
1193 acx_unlock(adev
, flags
);
1195 /* Must do this outside of lock */
1196 del_timer_sync(&adev
->mgmt_timer
);
1198 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
)) {
1224 acx_log(LOG_WARNING
, L_ANY
,
1225 "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 acx_log(LOG_DEBUG
, L_USBRXTX
,
1232 "_poll_rx: connection reset\n");
1235 rxurb
->actual_length
= 0;
1236 usb_fill_bulk_urb(rxurb
, usbdev
, inpipe
, &rx
->bulkin
, /* dataptr */
1237 RXBUFSIZE
, /* size */
1238 acxusb_i_complete_rx
, /* handler */
1239 rx
/* handler param */
1241 rxurb
->transfer_flags
= URB_ASYNC_UNLINK
;
1243 /* ATOMIC: we may be called from complete_rx() usb callback */
1244 errcode
= usb_submit_urb(rxurb
, GFP_ATOMIC
);
1245 /* FIXME: evaluate the error code! */
1246 acx_log(LOG_DEBUG
, L_USBRXTX
,
1247 "SUBMIT RX (%d) inpipe=0x%X size=%d errcode=%d\n",
1248 rxnum
, inpipe
, (int)RXBUFSIZE
, errcode
);
1254 /***********************************************************************
1255 ** acxusb_i_complete_rx()
1257 ** urb -> pointer to USB request block
1258 ** regs -> pointer to register-buffer for syscalls (see asm/ptrace.h)
1260 ** This function is invoked by USB subsystem whenever a bulk receive
1262 ** The received data is then committed to the network stack and the next
1263 ** USB receive is triggered.
1265 void acxusb_i_complete_rx(struct urb
*urb
)
1271 unsigned long flags
;
1272 int size
, remsize
, packetsize
, rxnum
;
1276 BUG_ON(!urb
->context
);
1278 rx
= (usb_rx_t
*) urb
->context
;
1281 acx_lock(adev
, flags
);
1284 * Happens on disconnect or close. Don't play with the urb.
1285 * Don't resubmit it. It will get unlinked by close()
1287 if (unlikely(!(adev
->dev_state_mask
& ACX_STATE_IFACE_UP
))) {
1288 acx_log(LOG_DEBUG
, L_USBRXTX
,
1289 "rx: device is down, not doing anything\n");
1293 inbuf
= &rx
->bulkin
;
1294 size
= urb
->actual_length
;
1296 rxnum
= rx
- adev
->usb_rx
;
1298 acx_log(LOG_DEBUG
, L_USBRXTX
, "RETURN RX (%d) status=%d size=%d\n",
1299 rxnum
, urb
->status
, size
);
1301 /* Send the URB that's waiting. */
1302 acx_log(LOG_DEBUG
, L_USBRXTX
, "rxnum=%d, sending=%d\n",
1304 acxusb_l_poll_rx(adev
, &adev
->usb_rx
[rxnum
^ 1]);
1306 if (unlikely(size
> sizeof(rxbuffer_t
)))
1307 acx_log(LOG_WARNING
, L_ANY
,
1308 "rx too large: %d, please report\n", size
);
1310 /* check if the transfer was aborted */
1311 switch (urb
->status
) {
1312 case 0: /* No error */
1315 acx_log(LOG_WARNING
, L_ANY
, "rx data overrun\n");
1316 adev
->rxtruncsize
= 0; /* Not valid anymore. */
1319 adev
->rxtruncsize
= 0;
1321 case -ESHUTDOWN
: /* rmmod */
1322 adev
->rxtruncsize
= 0;
1325 adev
->rxtruncsize
= 0;
1326 adev
->stats
.rx_errors
++;
1327 acx_log(LOG_WARNING
, L_ANY
, "rx error (urb status=%d)\n", urb
->status
);
1331 if (unlikely(!size
))
1332 acx_log(LOG_WARNING
, L_ANY
, "warning, encountered zerolength rx packet\n");
1334 if (urb
->transfer_buffer
!= inbuf
)
1337 /* check if previous frame was truncated
1338 ** FIXME: this code can only handle truncation
1339 ** of consecutive packets!
1342 if (adev
->rxtruncsize
) {
1344 acx_log(LOG_WARNING
, L_ANY
,
1345 "handling truncated frame (truncsize=%d size=%d "
1346 "packetsize(from trunc)=%d)\n",
1347 adev
->rxtruncsize
, size
, packetsize
);
1349 ptr
= &adev
->rxtruncbuf
;
1350 packetsize
= RXBUF_BYTES_USED(ptr
);
1351 acx_log_dump(LOG_WARNING
, L_USBRXTX
, ptr
, RXBUF_HDRSIZE
,
1353 acx_log_dump(LOG_WARNING
, L_USBRXTX
, inbuf
, RXBUF_HDRSIZE
,
1354 "Dumping inbuf:\n");
1356 /* bytes needed for rxtruncbuf completion: */
1357 tail_size
= packetsize
- adev
->rxtruncsize
;
1359 if (size
< tail_size
) {
1360 /* there is not enough data to complete this packet,
1361 ** simply append the stuff to the truncation buffer
1363 memcpy(((char *)ptr
) + adev
->rxtruncsize
, inbuf
, size
);
1364 adev
->rxtruncsize
+= size
;
1367 /* ok, this data completes the previously
1368 ** truncated packet. copy it into a descriptor
1369 ** and give it to the rest of the stack */
1371 /* append tail to previously truncated part
1372 ** NB: adev->rxtruncbuf (pointed to by ptr) can't
1373 ** overflow because this is already checked before
1374 ** truncation buffer was filled. See below,
1375 ** "if (packetsize > sizeof(rxbuffer_t))..." code */
1376 memcpy(((char *)ptr
) + adev
->rxtruncsize
, inbuf
,
1379 acx_log_dump(LOG_DEBUG
, L_USBRXTX
, inbuf
,
1380 tail_size
+ RXBUF_HDRSIZE
,
1381 "full trainling packet + 12 bytes:\n");
1382 acx_l_process_rxbuf(adev
, ptr
);
1383 adev
->rxtruncsize
= 0;
1384 ptr
= (rxbuffer_t
*) (((char *)inbuf
) + tail_size
);
1385 remsize
-= tail_size
;
1387 acx_log(LOG_INFO
, L_USBRXTX
, "post-merge size=%d remsize=%d\n",
1391 /* size = USB data block size
1392 ** remsize = unprocessed USB bytes left
1393 ** ptr = current pos in USB data block
1396 if (remsize
< RXBUF_HDRSIZE
) {
1397 acx_log(LOG_WARNING
, L_ANY
, "truncated rx header (%d bytes)!\n",
1400 acx_dump_bytes(ptr
, remsize
);
1404 packetsize
= RXBUF_BYTES_USED(ptr
);
1405 acx_log(LOG_DEBUG
, L_USBRXTX
,
1406 "packet with packetsize=%d\n", packetsize
);
1408 if (RXBUF_IS_TXSTAT(ptr
)) {
1409 /* do rate handling */
1410 usb_txstatus_t
*stat
= (void *)ptr
;
1412 acx_log(LOG_DEBUG
, L_USBRXTX
,
1413 "tx: stat: mac_cnt_rcvd:%04X "
1414 "queue_index:%02X mac_status:%02X "
1415 "hostdata:%08X rate:%u ack_failures:%02X "
1416 "rts_failures:%02X rts_ok:%02X\n",
1417 stat
->mac_cnt_rcvd
, stat
->queue_index
,
1418 stat
->mac_status
, stat
->hostdata
, stat
->rate
,
1419 stat
->ack_failures
, stat
->rts_failures
,
1422 if (adev->rate_auto && client_no < VEC_SIZE(adev->sta_list)) {
1423 client_t *clt = &adev->sta_list[client_no];
1424 u16 cur = stat->hostdata >> 16;
1426 if (clt && clt->rate_cur == cur) {
1427 acx_l_handle_txrate_auto(adev, clt,
1428 cur, // intended rate
1429 stat->rate, 0, // actually used rate
1430 stat->mac_status, // error?
1431 ACX_TX_URB_CNT - adev->tx_free);
1437 if (packetsize
> sizeof(rxbuffer_t
)) {
1438 acx_log(LOG_WARNING
, L_ANY
, "packet exceeds max wlan "
1439 "frame size (%d > %d). size=%d\n",
1440 packetsize
, (int)sizeof(rxbuffer_t
), size
);
1442 acx_dump_bytes(ptr
, 16);
1443 /* FIXME: put some real error-handling in here! */
1447 if (packetsize
> remsize
) {
1448 /* frame truncation handling */
1449 acx_log_dump(LOG_WARNING
, L_USBRXTX
, ptr
, RXBUF_HDRSIZE
,
1450 "need to truncate packet (packetsize=%d, "
1451 "remsize=%d, size=%d):\n");
1452 memcpy(&adev
->rxtruncbuf
, ptr
, remsize
);
1453 adev
->rxtruncsize
= remsize
;
1457 /* packetsize <= remsize */
1458 /* now handle the received data */
1459 acx_l_process_rxbuf(adev
, ptr
);
1461 ptr
= (rxbuffer_t
*) (((char *)ptr
) + packetsize
);
1462 remsize
-= packetsize
;
1463 acx_log_dump(LOG_WARNING
, L_USBRXTX
, ptr
, RXBUF_HDRSIZE
,
1464 "more than one packet in buffer! Second packet hdr:\n");
1468 acx_unlock(adev
, flags
);
1474 /***********************************************************************
1475 ** acxusb_i_complete_tx()
1477 ** urb -> pointer to USB request block
1478 ** regs -> pointer to register-buffer for syscalls (see asm/ptrace.h)
1480 ** This function is invoked upon termination of a USB transfer.
1482 void acxusb_i_complete_tx(struct urb
*urb
)
1486 unsigned long flags
;
1491 BUG_ON(!urb
->context
);
1493 tx
= (usb_tx_t
*) urb
->context
;
1496 txnum
= tx
- adev
->usb_tx
;
1498 acx_lock(adev
, flags
);
1501 * If the iface isn't up, we don't have any right
1502 * to play with them. The urb may get unlinked.
1504 if (unlikely(!(adev
->dev_state_mask
& ACX_STATE_IFACE_UP
))) {
1505 acx_log(LOG_INFO
, L_USBRXTX
,
1506 "tx: device is down, not doing anything\n");
1510 acx_log(LOG_INFO
, 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 acx_log(LOG_WARNING
, L_ANY
, "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 acx_log(LOG_DEBUG
, L_BUF
,
1536 "tx: wake queue (%u free txbufs)\n", adev
->tx_free
);
1537 /* acx_wake_queue(adev->ndev, NULL); */
1541 acx_unlock(adev
, flags
);
1547 /***************************************************************
1548 ** acxusb_l_alloc_tx
1549 ** Actually returns a usb_tx_t* ptr
1551 tx_t
*acxusb_l_alloc_tx(acx_device_t
* adev
)
1558 head
= adev
->tx_head
;
1560 head
= (head
+ 1) % ACX_TX_URB_CNT
;
1561 if (!adev
->usb_tx
[head
].busy
) {
1562 acx_log(LOG_DEBUG
, L_USBRXTX
,
1563 "allocated tx %d\n", head
);
1564 tx
= &adev
->usb_tx
[head
];
1567 /* Keep a few free descs between head and tail of tx ring.
1568 ** It is not absolutely needed, just feels safer */
1569 if (adev
->tx_free
< TX_STOP_QUEUE
) {
1570 acx_log(LOG_DEBUG
, L_BUF
, "tx: stop queue "
1571 "(%u free txbufs)\n", adev
->tx_free
);
1572 /* acx_stop_queue(adev->ndev, NULL); */
1576 } while (likely(head
!= adev
->tx_head
));
1578 acx_log_ratelimited(LOG_WARNING
, L_ANY
, "tx buffers full\n");
1580 adev
->tx_head
= head
;
1586 /***************************************************************
1587 ** Used if alloc_tx()'ed buffer needs to be cancelled without doing tx
1589 void acxusb_l_dealloc_tx(tx_t
* tx_opaque
)
1591 usb_tx_t
*tx
= (usb_tx_t
*) tx_opaque
;
1596 /***************************************************************
1598 void *acxusb_l_get_txbuf(acx_device_t
* adev
, tx_t
* tx_opaque
)
1600 usb_tx_t
*tx
= (usb_tx_t
*) tx_opaque
;
1601 return &tx
->bulkout
.data
;
1605 /***************************************************************
1608 ** Can be called from IRQ (rx -> (AP bridging or mgmt response) -> tx).
1609 ** Can be called from acx_i_start_xmit (data frames from net core).
1611 void acxusb_l_tx_data(acx_device_t
* adev
, tx_t
* tx_opaque
, int wlanpkt_len
, struct ieee80211_tx_control
*ctl
,
1612 struct sk_buff
* skb
)
1614 struct usb_device
*usbdev
;
1617 usb_txbuffer_t
*txbuf
;
1619 struct ieee80211_hdr
*whdr
;
1620 unsigned int outpipe
;
1625 tx
= ((usb_tx_t
*) tx_opaque
);
1627 txbuf
= &tx
->bulkout
;
1628 whdr
= (struct ieee80211_hdr
*) txbuf
->data
;
1629 txnum
= tx
- adev
->usb_tx
;
1631 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "using buf#%d free=%d len=%d\n",
1632 txnum
, adev
->tx_free
, wlanpkt_len
);
1634 switch (adev->mode) {
1635 case ACX_MODE_0_ADHOC:
1637 clt = acx_l_sta_list_get(adev, whdr->a1);
1639 case ACX_MODE_2_STA:
1640 // clt = adev->ap_client;
1646 if (unlikely(clt && !clt->rate_cur)) {
1647 acx_log(LOG_INFO, L_ANY, "driver bug! bad ratemask\n");
1652 /* fill the USB transfer header */
1653 txbuf
->desc
= cpu_to_le16(USB_TXBUF_TXDESC
);
1654 txbuf
->mpdu_len
= cpu_to_le16(wlanpkt_len
);
1655 txbuf
->queue_index
= 1;
1656 txbuf
->rate
= ctl
->tx_rate
; //clt->rate_100;
1657 // FIXME(); //This used to have | (clt - adev->ap_client)
1658 txbuf
->hostdata
= (ctl
->tx_rate
<< 16);
1659 txbuf
->ctrl1
= DESC_CTL_FIRSTFRAG
;
1660 if (1 == adev
->preamble_cur
)
1661 SET_BIT(txbuf
->ctrl1
, DESC_CTL_SHORT_PREAMBLE
);
1663 txbuf
->data_len
= cpu_to_le16(wlanpkt_len
);
1665 acx_log_dump(LOG_DEBUG
, L_DATA
, txbuf
, wlanpkt_len
+ USB_TXBUF_HDRSIZE
,
1666 "dump of bulk out urb:\n");
1668 if (unlikely(txurb
->status
== -EINPROGRESS
)) {
1669 acx_log(LOG_WARNING
, L_ANY
,
1670 "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 acx_log(LOG_DEBUG
, L_USBRXTX
,
1686 "SUBMIT TX (%d): outpipe=0x%X buf=%p txsize=%d "
1687 "rate=%u errcode=%d\n", txnum
, outpipe
, txbuf
,
1688 wlanpkt_len
+ USB_TXBUF_HDRSIZE
, txbuf
->rate
, ucode
);
1690 if (unlikely(ucode
)) {
1691 acx_log(LOG_WARNING
, L_ANY
, "submit_urb() error=%d txsize=%d\n",
1692 ucode
, wlanpkt_len
+ USB_TXBUF_HDRSIZE
);
1694 /* on error, just mark the frame as done and update
1697 adev
->stats
.tx_errors
++;
1700 /* needed? if (adev->tx_free > TX_START_QUEUE) acx_wake_queue(...) */
1706 /***********************************************************************
1707 static void acxusb_i_set_rx_mode(struct net_device *ndev)
1713 /***********************************************************************
1715 #ifdef HAVE_TX_TIMEOUT
1717 void acxusb_i_tx_timeout(struct net_device *ndev)
1719 acx_device_t *adev = ndev2adev(ndev);
1720 unsigned long flags;
1725 acx_lock(adev, flags);
1726 */ /* unlink the URBs */
1727 /* for (i = 0; i < ACX_TX_URB_CNT; i++) {
1728 acxusb_unlink_urb(adev->usb_tx[i].urb);
1729 adev->usb_tx[i].busy = 0;
1731 adev->tx_free = ACX_TX_URB_CNT;
1732 */ /* TODO: stats update */
1733 /* acx_unlock(adev, flags);
1741 /***********************************************************************
1744 ** This function is invoked upon loading of the kernel module.
1745 ** It registers itself at the kernel's USB subsystem.
1747 ** Returns: Errorcode on failure, 0 on success
1749 int __init
acxusb_e_init_module(void)
1751 acx_log(LOG_INFO
, L_INIT
, "USB module " ACX_RELEASE
" initialized, "
1752 "probing for devices...\n");
1753 return usb_register(&acxusb_driver
);
1758 /***********************************************************************
1761 ** This function is invoked as last step of the module unloading. It simply
1762 ** deregisters this module at the kernel's USB subsystem.
1764 void __exit
acxusb_e_cleanup_module(void)
1766 usb_deregister(&acxusb_driver
);
1767 acx_log(LOG_INFO
, L_INIT
, "USB module " ACX_RELEASE
" unloaded\n");
1771 /***********************************************************************
1777 static void dump_device(struct usb_device
*usbdev
)
1780 struct usb_config_descriptor
*cd
;
1782 acx_log(LOG_INFO
, L_ANY
, "acx device dump:\n");
1783 acx_log(LOG_INFO
, L_ANY
, " devnum: %d\n", usbdev
->devnum
);
1784 acx_log(LOG_INFO
, L_ANY
, " speed: %d\n", usbdev
->speed
);
1785 acx_log(LOG_INFO
, L_ANY
, " tt: 0x%X\n", (unsigned int)(usbdev
->tt
));
1786 acx_log(LOG_INFO
, L_ANY
, " ttport: %d\n", (unsigned int)(usbdev
->ttport
));
1787 acx_log(LOG_INFO
, L_ANY
, " toggle[0]: 0x%X toggle[1]: 0x%X\n",
1788 (unsigned int)(usbdev
->toggle
[0]),
1789 (unsigned int)(usbdev
->toggle
[1]));
1790 /* This saw a change after 2.6.10 */
1791 acx_log(LOG_INFO
, L_ANY
, " 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 acx_log(LOG_INFO
, L_ANY
, " 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
);
1803 acx_log(LOG_INFO
, L_ANY
, " parent: 0x%X\n", (unsigned int)usbdev
->parent
);
1804 acx_log(LOG_INFO
, L_ANY
, " bus: 0x%X\n", (unsigned int)usbdev
->bus
);
1806 acx_log(LOG_INFO
, L_ANY
, " configs: ");
1807 for (i
= 0; i
< usbdev
->descriptor
.bNumConfigurations
; i
++)
1808 printk("0x%X ", usbdev
->config
[i
]);
1811 acx_log(LOG_INFO
, L_ANY
, " actconfig: %p\n", usbdev
->actconfig
);
1812 dump_device_descriptor(&usbdev
->descriptor
);
1814 cd
= &usbdev
->config
->desc
;
1815 dump_config_descriptor(cd
);
1819 /***********************************************************************
1821 static void dump_config_descriptor(struct usb_config_descriptor
*cd
)
1823 acx_log(LOG_INFO
, L_ANY
, "Configuration Descriptor:\n");
1825 acx_log(LOG_INFO
, L_ANY
, "NULL\n");
1828 acx_log(LOG_INFO
, L_ANY
, " bLength: %d (0x%X)\n", cd
->bLength
, cd
->bLength
);
1829 acx_log(LOG_INFO
, L_ANY
, " bDescriptorType: %d (0x%X)\n", cd
->bDescriptorType
,
1830 cd
->bDescriptorType
);
1831 acx_log(LOG_INFO
, L_ANY
, " bNumInterfaces: %d (0x%X)\n", cd
->bNumInterfaces
,
1832 cd
->bNumInterfaces
);
1833 acx_log(LOG_INFO
, L_ANY
, " bConfigurationValue: %d (0x%X)\n", cd
->bConfigurationValue
,
1834 cd
->bConfigurationValue
);
1835 acx_log(LOG_INFO
, L_ANY
, " iConfiguration: %d (0x%X)\n", cd
->iConfiguration
,
1836 cd
->iConfiguration
);
1837 acx_log(LOG_INFO
, L_ANY
, " bmAttributes: %d (0x%X)\n", cd
->bmAttributes
,
1839 /* acx_log(LOG_INFO, L_ANY, " MaxPower: %d (0x%X)\n", cd->bMaxPower, cd->bMaxPower); */
1843 static void dump_device_descriptor(struct usb_device_descriptor
*dd
)
1845 acx_log(LOG_INFO
, L_ANY
, "Device Descriptor:\n");
1847 acx_log(LOG_INFO
, L_ANY
, "NULL\n");
1850 acx_log(LOG_INFO
, L_ANY
, " bLength: %d (0x%X)\n", dd
->bLength
, dd
->bLength
);
1851 acx_log(LOG_INFO
, L_ANY
, " bDescriptortype: %d (0x%X)\n", dd
->bDescriptorType
,
1852 dd
->bDescriptorType
);
1853 acx_log(LOG_INFO
, L_ANY
, " bcdUSB: %d (0x%X)\n", dd
->bcdUSB
, dd
->bcdUSB
);
1854 acx_log(LOG_INFO
, L_ANY
, " bDeviceClass: %d (0x%X)\n", dd
->bDeviceClass
,
1856 acx_log(LOG_INFO
, L_ANY
, " bDeviceSubClass: %d (0x%X)\n", dd
->bDeviceSubClass
,
1857 dd
->bDeviceSubClass
);
1858 acx_log(LOG_INFO
, L_ANY
, " bDeviceProtocol: %d (0x%X)\n", dd
->bDeviceProtocol
,
1859 dd
->bDeviceProtocol
);
1860 acx_log(LOG_INFO
, L_ANY
, " bMaxPacketSize0: %d (0x%X)\n", dd
->bMaxPacketSize0
,
1861 dd
->bMaxPacketSize0
);
1862 acx_log(LOG_INFO
, L_ANY
, " idVendor: %d (0x%X)\n", dd
->idVendor
, dd
->idVendor
);
1863 acx_log(LOG_INFO
, L_ANY
, " idProduct: %d (0x%X)\n", dd
->idProduct
, dd
->idProduct
);
1864 acx_log(LOG_INFO
, L_ANY
, " bcdDevice: %d (0x%X)\n", dd
->bcdDevice
, dd
->bcdDevice
);
1865 acx_log(LOG_INFO
, L_ANY
, " iManufacturer: %d (0x%X)\n", dd
->iManufacturer
,
1867 acx_log(LOG_INFO
, L_ANY
, " iProduct: %d (0x%X)\n", dd
->iProduct
, dd
->iProduct
);
1868 acx_log(LOG_INFO
, L_ANY
, " iSerialNumber: %d (0x%X)\n", dd
->iSerialNumber
,
1870 acx_log(LOG_INFO
, L_ANY
, " bNumConfigurations: %d (0x%X)\n", dd
->bNumConfigurations
,
1871 dd
->bNumConfigurations
);
1875 #endif /* ACX_DEBUG */