1 /**** (legal) claimer in README
2 ** Copyright (C) 2003 ACX100 Open Source Project
4 #define ACX_MAC80211_PCI 1
6 #include <linux/version.h>
8 /* Linux 2.6.18+ uses <linux/utsrelease.h> */
10 #include <linux/utsrelease.h>
13 #include <linux/compiler.h> /* required for Lx 2.6.8 ?? */
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/moduleparam.h>
17 #include <linux/sched.h>
18 #include <linux/types.h>
19 #include <linux/skbuff.h>
20 #include <linux/slab.h>
21 #include <linux/if_arp.h>
22 #include <linux/rtnetlink.h>
23 #include <linux/wireless.h>
24 #include <net/iw_handler.h>
25 #include <linux/netdevice.h>
26 #include <linux/ioport.h>
27 #include <linux/pci.h>
29 #include <linux/vmalloc.h>
30 #include <linux/ethtool.h>
31 #include <linux/dma-mapping.h>
32 #include <linux/workqueue.h>
34 #include <linux/vlynq.h>
39 /***********************************************************************
42 #define PCI_TYPE (PCI_USES_MEM | PCI_ADDR0 | PCI_NO_ACPI_WAKE)
43 #define PCI_ACX100_REGION1 0x01
44 #define PCI_ACX100_REGION1_SIZE 0x1000 /* Memory size - 4K bytes */
45 #define PCI_ACX100_REGION2 0x02
46 #define PCI_ACX100_REGION2_SIZE 0x10000 /* Memory size - 64K bytes */
48 #define PCI_ACX111_REGION1 0x00
49 #define PCI_ACX111_REGION1_SIZE 0x2000 /* Memory size - 8K bytes */
50 #define PCI_ACX111_REGION2 0x01
51 #define PCI_ACX111_REGION2_SIZE 0x20000 /* Memory size - 128K bytes */
53 /* Texas Instruments Vendor ID */
54 #define PCI_VENDOR_ID_TI 0x104c
56 /* ACX100 22Mb/s WLAN controller */
57 #define PCI_DEVICE_ID_TI_TNETW1100A 0x8400
58 #define PCI_DEVICE_ID_TI_TNETW1100B 0x8401
60 /* ACX111 54Mb/s WLAN controller */
61 #define PCI_DEVICE_ID_TI_TNETW1130 0x9066
63 /* PCI Class & Sub-Class code, Network-'Other controller' */
64 #define PCI_CLASS_NETWORK_OTHERS 0x0280
66 #define CARD_EEPROM_ID_SIZE 6
69 /* From include/linux/pci.h */
76 #define PCI_POWER_ERROR -1
78 #endif /* CONFIG_PCI */
80 /***********************************************************************
83 static irqreturn_t
acxpci_i_interrupt(int irq
, void *dev_id
);
85 static void disable_acx_irq(acx_device_t
* adev
);
87 static int acxpci_e_open(struct ieee80211_hw
*hw
);
88 static void acxpci_e_close(struct ieee80211_hw
*hw
);
89 static void acxpci_s_up(struct ieee80211_hw
*hw
);
90 static void acxpci_s_down(struct ieee80211_hw
*hw
);
92 void acxpci_put_devname(acx_device_t
*adev
, struct ethtool_drvinfo
*info
)
94 strncpy(info
->bus_info
,pci_name(adev
->pdev
), ETHTOOL_BUSINFO_LEN
);
97 /***********************************************************************
103 /* OS I/O routines *always* be endianness-clean but having them doesn't hurt */
104 #define acx_readl(v) le32_to_cpu(readl((v)))
105 #define acx_readw(v) le16_to_cpu(readw((v)))
106 #define acx_writew(v,r) writew(le16_to_cpu((v)), r)
107 #define acx_writel(v,r) writel(le32_to_cpu((v)), r)
110 /* #define INLINE_IO static */
111 #define INLINE_IO static inline
113 INLINE_IO u32
read_reg32(acx_device_t
* adev
, unsigned int offset
)
115 #if ACX_IO_WIDTH == 32
116 return acx_readl((u8
*) adev
->iobase
+ adev
->io
[offset
]);
118 return acx_readw((u8
*) adev
->iobase
+ adev
->io
[offset
])
119 + (acx_readw((u8
*) adev
->iobase
+ adev
->io
[offset
] + 2) << 16);
123 INLINE_IO u16
read_reg16(acx_device_t
* adev
, unsigned int offset
)
125 return acx_readw((u8
*) adev
->iobase
+ adev
->io
[offset
]);
128 INLINE_IO u8
read_reg8(acx_device_t
* adev
, unsigned int offset
)
130 return readb((u8
*) adev
->iobase
+ adev
->io
[offset
]);
133 INLINE_IO
void write_reg32(acx_device_t
* adev
, unsigned int offset
, u32 val
)
135 #if ACX_IO_WIDTH == 32
136 acx_writel(val
, (u8
*) adev
->iobase
+ adev
->io
[offset
]);
138 acx_writew(val
& 0xffff, (u8
*) adev
->iobase
+ adev
->io
[offset
]);
139 acx_writew(val
>> 16, (u8
*) adev
->iobase
+ adev
->io
[offset
] + 2);
143 INLINE_IO
void write_reg16(acx_device_t
* adev
, unsigned int offset
, u16 val
)
145 acx_writew(val
, (u8
*) adev
->iobase
+ adev
->io
[offset
]);
148 INLINE_IO
void write_reg8(acx_device_t
* adev
, unsigned int offset
, u8 val
)
150 writeb(val
, (u8
*) adev
->iobase
+ adev
->io
[offset
]);
153 /* Handle PCI posting properly:
154 * Make sure that writes reach the adapter in case they require to be executed
155 * *before* the next write, by reading a random (and safely accessible) register.
156 * This call has to be made if there is no read following (which would flush the data
157 * to the adapter), yet the written data has to reach the adapter immediately. */
158 INLINE_IO
void write_flush(acx_device_t
* adev
)
160 /* readb(adev->iobase + adev->io[IO_ACX_INFO_MAILBOX_OFFS]); */
161 /* faster version (accesses the first register, IO_ACX_SOFT_RESET,
162 * which should also be safe): */
166 INLINE_IO
int adev_present(acx_device_t
* adev
)
168 /* fast version (accesses the first register, IO_ACX_SOFT_RESET,
169 * which should be safe): */
170 return acx_readl(adev
->iobase
) != 0xffffffff;
174 /***********************************************************************
176 static inline txdesc_t
*get_txdesc(acx_device_t
* adev
, int index
)
178 return (txdesc_t
*) (((u8
*) adev
->txdesc_start
) +
179 index
* adev
->txdesc_size
);
182 static inline txdesc_t
*advance_txdesc(acx_device_t
* adev
, txdesc_t
* txdesc
,
185 return (txdesc_t
*) (((u8
*) txdesc
) + inc
* adev
->txdesc_size
);
188 static txhostdesc_t
*get_txhostdesc(acx_device_t
* adev
, txdesc_t
* txdesc
)
190 int index
= (u8
*) txdesc
- (u8
*) adev
->txdesc_start
;
194 if (unlikely(ACX_DEBUG
&& (index
% adev
->txdesc_size
))) {
195 printk("bad txdesc ptr %p\n", txdesc
);
198 index
/= adev
->txdesc_size
;
199 if (unlikely(ACX_DEBUG
&& (index
>= TX_CNT
))) {
200 printk("bad txdesc ptr %p\n", txdesc
);
206 return &adev
->txhostdesc_start
[index
* 2];
213 /***********************************************************************
214 ** EEPROM and PHY read/write helpers
216 /***********************************************************************
217 ** acxpci_read_eeprom_byte
219 ** Function called to read an octet in the EEPROM.
221 ** This function is used by acxpci_e_probe to check if the
222 ** connected card is a legal one or not.
225 ** adev ptr to acx_device structure
226 ** addr address to read in the EEPROM
227 ** charbuf ptr to a char. This is where the read octet
231 int acxpci_read_eeprom_byte(acx_device_t
* adev
, u32 addr
, u8
* charbuf
)
238 write_reg32(adev
, IO_ACX_EEPROM_CFG
, 0);
239 write_reg32(adev
, IO_ACX_EEPROM_ADDR
, addr
);
241 write_reg32(adev
, IO_ACX_EEPROM_CTL
, 2);
244 while (read_reg16(adev
, IO_ACX_EEPROM_CTL
)) {
245 /* scheduling away instead of CPU burning loop
246 * doesn't seem to work here at all:
247 * awful delay, sometimes also failure.
248 * Doesn't matter anyway (only small delay). */
249 if (unlikely(!--count
)) {
250 printk("%s: timeout waiting for EEPROM read\n",
251 wiphy_name(adev
->ieee
->wiphy
));
258 *charbuf
= read_reg8(adev
, IO_ACX_EEPROM_DATA
);
259 log(L_DEBUG
, "EEPROM at 0x%04X = 0x%02X\n", addr
, *charbuf
);
268 /***********************************************************************
269 ** We don't lock hw accesses here since we never r/w eeprom in IRQ
270 ** Note: this function sleeps only because of GFP_KERNEL alloc
274 acxpci_s_write_eeprom(acx_device_t
* adev
, u32 addr
, u32 len
,
277 u8
*data_verify
= NULL
;
283 printk("acx: WARNING! I would write to EEPROM now. "
284 "Since I really DON'T want to unless you know "
285 "what you're doing (THIS CODE WILL PROBABLY "
286 "NOT WORK YET!), I will abort that now. And "
287 "definitely make sure to make a "
288 "/proc/driver/acx_wlan0_eeprom backup copy first!!! "
289 "(the EEPROM content includes the PCI config header!! "
290 "If you kill important stuff, then you WILL "
291 "get in trouble and people DID get in trouble already)\n");
296 data_verify
= kmalloc(len
, GFP_KERNEL
);
301 /* first we need to enable the OE (EEPROM Output Enable) GPIO line
302 * to be able to write to the EEPROM.
303 * NOTE: an EEPROM writing success has been reported,
304 * but you probably have to modify GPIO_OUT, too,
305 * and you probably need to activate a different GPIO
307 gpio_orig
= read_reg16(adev
, IO_ACX_GPIO_OE
);
308 write_reg16(adev
, IO_ACX_GPIO_OE
, gpio_orig
& ~1);
311 /* ok, now start writing the data out */
312 for (i
= 0; i
< len
; i
++) {
313 write_reg32(adev
, IO_ACX_EEPROM_CFG
, 0);
314 write_reg32(adev
, IO_ACX_EEPROM_ADDR
, addr
+ i
);
315 write_reg32(adev
, IO_ACX_EEPROM_DATA
, *(charbuf
+ i
));
317 write_reg32(adev
, IO_ACX_EEPROM_CTL
, 1);
320 while (read_reg16(adev
, IO_ACX_EEPROM_CTL
)) {
321 if (unlikely(!--count
)) {
322 printk("WARNING, DANGER!!! "
323 "Timeout waiting for EEPROM write\n");
330 /* disable EEPROM writing */
331 write_reg16(adev
, IO_ACX_GPIO_OE
, gpio_orig
);
334 /* now start a verification run */
335 for (i
= 0; i
< len
; i
++) {
336 write_reg32(adev
, IO_ACX_EEPROM_CFG
, 0);
337 write_reg32(adev
, IO_ACX_EEPROM_ADDR
, addr
+ i
);
339 write_reg32(adev
, IO_ACX_EEPROM_CTL
, 2);
342 while (read_reg16(adev
, IO_ACX_EEPROM_CTL
)) {
343 if (unlikely(!--count
)) {
344 printk("timeout waiting for EEPROM read\n");
350 data_verify
[i
] = read_reg16(adev
, IO_ACX_EEPROM_DATA
);
353 if (0 == memcmp(charbuf
, data_verify
, len
))
354 result
= OK
; /* read data matches, success */
364 /***********************************************************************
365 ** acxpci_s_read_phy_reg
367 ** Messing with rx/tx disabling and enabling here
368 ** (write_reg32(adev, IO_ACX_ENABLE, 0b000000xx)) kills traffic
370 int acxpci_s_read_phy_reg(acx_device_t
* adev
, u32 reg
, u8
* charbuf
)
377 write_reg32(adev
, IO_ACX_PHY_ADDR
, reg
);
379 write_reg32(adev
, IO_ACX_PHY_CTL
, 2);
382 while (read_reg32(adev
, IO_ACX_PHY_CTL
)) {
383 /* scheduling away instead of CPU burning loop
384 * doesn't seem to work here at all:
385 * awful delay, sometimes also failure.
386 * Doesn't matter anyway (only small delay). */
387 if (unlikely(!--count
)) {
388 printk("%s: timeout waiting for phy read\n",
389 wiphy_name(adev
->ieee
->wiphy
));
396 log(L_DEBUG
, "count was %u\n", count
);
397 *charbuf
= read_reg8(adev
, IO_ACX_PHY_DATA
);
399 log(L_DEBUG
, "radio PHY at 0x%04X = 0x%02X\n", *charbuf
, reg
);
401 goto fail
; /* silence compiler warning */
408 /***********************************************************************
410 int acxpci_s_write_phy_reg(acx_device_t
* adev
, u32 reg
, u8 value
)
414 /* mprusko said that 32bit accesses result in distorted sensitivity
415 * on his card. Unconfirmed, looks like it's not true (most likely since we
416 * now properly flush writes). */
417 write_reg32(adev
, IO_ACX_PHY_DATA
, value
);
418 write_reg32(adev
, IO_ACX_PHY_ADDR
, reg
);
420 write_reg32(adev
, IO_ACX_PHY_CTL
, 1);
422 log(L_DEBUG
, "radio PHY write 0x%02X at 0x%04X\n", value
, reg
);
429 #define NO_AUTO_INCREMENT 1
431 /***********************************************************************
434 ** Write the firmware image into the card.
437 ** adev wlan device structure
438 ** fw_image firmware image.
441 ** 1 firmware image corrupted
444 ** Standard csum implementation + write to IO
447 acxpci_s_write_fw(acx_device_t
* adev
, const firmware_image_t
*fw_image
,
452 /* we skip the first four bytes which contain the control sum */
454 const u8
*p
= (u8
*) fw_image
+ 4;
458 /* start the image checksum by adding the image size value */
459 sum
= p
[0] + p
[1] + p
[2] + p
[3];
462 write_reg32(adev
, IO_ACX_SLV_END_CTL
, 0);
464 #if NO_AUTO_INCREMENT
465 write_reg32(adev
, IO_ACX_SLV_MEM_CTL
, 0); /* use basic mode */
467 write_reg32(adev
, IO_ACX_SLV_MEM_CTL
, 1); /* use autoincrement mode */
468 write_reg32(adev
, IO_ACX_SLV_MEM_ADDR
, offset
); /* configure start address */
473 size
= le32_to_cpu(fw_image
->size
) & (~3);
475 while (likely(len
< size
)) {
476 v32
= be32_to_cpu(*(u32
*) p
);
477 sum
+= p
[0] + p
[1] + p
[2] + p
[3];
481 #if NO_AUTO_INCREMENT
482 write_reg32(adev
, IO_ACX_SLV_MEM_ADDR
, offset
+ len
- 4);
485 write_reg32(adev
, IO_ACX_SLV_MEM_DATA
, v32
);
488 log(L_DEBUG
, "firmware written, size:%d sum1:%x sum2:%x\n",
489 size
, sum
, le32_to_cpu(fw_image
->chksum
));
491 /* compare our checksum with the stored image checksum */
492 FN_EXIT1(sum
!= le32_to_cpu(fw_image
->chksum
));
493 return (sum
!= le32_to_cpu(fw_image
->chksum
));
497 /***********************************************************************
498 ** acxpci_s_validate_fw
500 ** Compare the firmware image given with
501 ** the firmware image written into the card.
504 ** adev wlan device structure
505 ** fw_image firmware image.
508 ** NOT_OK firmware image corrupted or not correctly written
511 ** Origin: Standard csum + Read IO
514 acxpci_s_validate_fw(acx_device_t
* adev
, const firmware_image_t
*fw_image
,
520 /* we skip the first four bytes which contain the control sum */
521 const u8
*p
= (u8
*) fw_image
+ 4;
525 /* start the image checksum by adding the image size value */
526 sum
= p
[0] + p
[1] + p
[2] + p
[3];
529 write_reg32(adev
, IO_ACX_SLV_END_CTL
, 0);
531 #if NO_AUTO_INCREMENT
532 write_reg32(adev
, IO_ACX_SLV_MEM_CTL
, 0); /* use basic mode */
534 write_reg32(adev
, IO_ACX_SLV_MEM_CTL
, 1); /* use autoincrement mode */
535 write_reg32(adev
, IO_ACX_SLV_MEM_ADDR
, offset
); /* configure start address */
539 size
= le32_to_cpu(fw_image
->size
) & (~3);
541 while (likely(len
< size
)) {
542 v32
= be32_to_cpu(*(u32
*) p
);
546 #if NO_AUTO_INCREMENT
547 write_reg32(adev
, IO_ACX_SLV_MEM_ADDR
, offset
+ len
- 4);
549 w32
= read_reg32(adev
, IO_ACX_SLV_MEM_DATA
);
551 if (unlikely(w32
!= v32
)) {
552 printk("acx: FATAL: firmware upload: "
553 "data parts at offset %d don't match (0x%08X vs. 0x%08X)! "
554 "I/O timing issues or defective memory, with DWL-xx0+? "
555 "ACX_IO_WIDTH=16 may help. Please report\n",
562 (u8
) w32
+ (u8
) (w32
>> 8) + (u8
) (w32
>> 16) +
566 /* sum control verification */
567 if (result
!= NOT_OK
) {
568 if (sum
!= le32_to_cpu(fw_image
->chksum
)) {
569 printk("acx: FATAL: firmware upload: "
570 "checksums don't match!\n");
580 /***********************************************************************
581 ** acxpci_s_upload_fw
583 ** Called from acx_reset_dev
585 ** Origin: Derived from FW dissection
587 static int acxpci_s_upload_fw(acx_device_t
* adev
)
589 firmware_image_t
*fw_image
= NULL
;
593 char filename
[sizeof("tiacx1NNcNN")];
597 /* print exact chipset and radio ID to make sure people
598 * really get a clue on which files exactly they need to provide.
599 * Firmware loading is a frequent end-user PITA with these chipsets.
601 printk( "acx: need firmware for acx1%02d chipset with radio ID %02X\n"
602 "Please provide via firmware hotplug:\n"
603 "either combined firmware (single file named 'tiacx1%02dc%02X')\n"
604 "or two files (base firmware file 'tiacx1%02d' "
605 "+ radio fw 'tiacx1%02dr%02X')\n",
606 IS_ACX111(adev
)*11, adev
->radio_type
,
607 IS_ACX111(adev
)*11, adev
->radio_type
,
609 IS_ACX111(adev
)*11, adev
->radio_type
612 /* print exact chipset and radio ID to make sure people really get a clue on which files exactly they are supposed to provide,
613 * since firmware loading is the biggest enduser PITA with these chipsets.
614 * Not printing radio ID in 0xHEX in order to not confuse them into wrong file naming */
615 printk( "acx: need to load firmware for acx1%02d chipset with radio ID %02x, please provide via firmware hotplug:\n"
616 "acx: either one file only (<c>ombined firmware image file, radio-specific) or two files (radio-less base image file *plus* separate <r>adio-specific extension file)\n",
617 IS_ACX111(adev
)*11, adev
->radio_type
);
619 /* Try combined, then main image */
620 adev
->need_radio_fw
= 0;
621 snprintf(filename
, sizeof(filename
), "tiacx1%02dc%02X",
622 IS_ACX111(adev
) * 11, adev
->radio_type
);
624 fw_image
= acx_s_read_fw(adev
->bus_dev
, filename
, &file_size
);
626 adev
->need_radio_fw
= 1;
627 filename
[sizeof("tiacx1NN") - 1] = '\0';
629 acx_s_read_fw(adev
->bus_dev
, filename
, &file_size
);
636 for (try = 1; try <= 5; try++) {
637 res
= acxpci_s_write_fw(adev
, fw_image
, 0);
638 log(L_DEBUG
| L_INIT
, "acx_write_fw (main/combined): %d\n", res
);
640 res
= acxpci_s_validate_fw(adev
, fw_image
, 0);
641 log(L_DEBUG
| L_INIT
, "acx_validate_fw "
642 "(main/combined): %d\n", res
);
646 SET_BIT(adev
->dev_state_mask
, ACX_STATE_FW_LOADED
);
649 printk("acx: firmware upload attempt #%d FAILED, "
650 "retrying...\n", try);
651 acx_s_mwait(1000); /* better wait for a while... */
661 /***********************************************************************
662 ** acxpci_s_upload_radio
664 ** Uploads the appropriate radio module firmware into the card.
666 ** Origin: Standard Read/Write to IO
668 int acxpci_s_upload_radio(acx_device_t
* adev
)
671 firmware_image_t
*radio_image
;
672 acx_cmd_radioinit_t radioinit
;
677 char filename
[sizeof("tiacx1NNrNN")];
679 if (!adev
->need_radio_fw
)
684 acx_s_interrogate(adev
, &mm
, ACX1xx_IE_MEMORY_MAP
);
685 offset
= le32_to_cpu(mm
.CodeEnd
);
687 snprintf(filename
, sizeof(filename
), "tiacx1%02dr%02X",
688 IS_ACX111(adev
) * 11, adev
->radio_type
);
689 radio_image
= acx_s_read_fw(adev
->bus_dev
, filename
, &size
);
691 printk("acx: can't load radio module '%s'\n", filename
);
695 acx_s_issue_cmd(adev
, ACX1xx_CMD_SLEEP
, NULL
, 0);
697 for (try = 1; try <= 5; try++) {
698 res
= acxpci_s_write_fw(adev
, radio_image
, offset
);
699 log(L_DEBUG
| L_INIT
, "acx_write_fw (radio): %d\n", res
);
701 res
= acxpci_s_validate_fw(adev
, radio_image
, offset
);
702 log(L_DEBUG
| L_INIT
, "acx_validate_fw (radio): %d\n",
708 printk("acx: radio firmware upload attempt #%d FAILED, "
709 "retrying...\n", try);
710 acx_s_mwait(1000); /* better wait for a while... */
713 acx_s_issue_cmd(adev
, ACX1xx_CMD_WAKE
, NULL
, 0);
714 radioinit
.offset
= cpu_to_le32(offset
);
715 /* no endian conversion needed, remains in card CPU area: */
716 radioinit
.len
= radio_image
->size
;
723 /* will take a moment so let's have a big timeout */
724 acx_s_issue_cmd_timeo(adev
, ACX1xx_CMD_RADIOINIT
,
725 &radioinit
, sizeof(radioinit
),
726 CMD_TIMEOUT_MS(1000));
728 res
= acx_s_interrogate(adev
, &mm
, ACX1xx_IE_MEMORY_MAP
);
735 /***********************************************************************
736 ** acxpci_l_reset_mac
739 ** Call context: reset_dev
741 ** Origin: Standard Read/Write to IO
743 static void acxpci_l_reset_mac(acx_device_t
* adev
)
750 temp
= read_reg16(adev
, IO_ACX_ECPU_CTRL
) | 0x1;
751 write_reg16(adev
, IO_ACX_ECPU_CTRL
, temp
);
753 /* now do soft reset of eCPU, set bit */
754 temp
= read_reg16(adev
, IO_ACX_SOFT_RESET
) | 0x1;
755 log(L_DEBUG
, "enable soft reset\n");
756 write_reg16(adev
, IO_ACX_SOFT_RESET
, temp
);
759 /* now clear bit again: deassert eCPU reset */
760 log(L_DEBUG
, "disable soft reset and go to init mode");
761 write_reg16(adev
, IO_ACX_SOFT_RESET
, temp
& ~0x1);
763 /* now start a burst read from initial EEPROM */
764 temp
= read_reg16(adev
, IO_ACX_EE_START
) | 0x1;
765 write_reg16(adev
, IO_ACX_EE_START
, temp
);
772 /***********************************************************************
773 ** acxpci_s_verify_init
775 static int acxpci_s_verify_init(acx_device_t
* adev
)
778 unsigned long timeout
;
782 timeout
= jiffies
+ 2 * HZ
;
784 u16 irqstat
= read_reg16(adev
, IO_ACX_IRQ_STATUS_NON_DES
);
785 if (irqstat
& HOST_INT_FCS_THRESHOLD
) {
787 write_reg16(adev
, IO_ACX_IRQ_ACK
,
788 HOST_INT_FCS_THRESHOLD
);
791 if (time_after(jiffies
, timeout
))
793 /* Init may take up to ~0.5 sec total */
802 /***********************************************************************
803 ** A few low-level helpers
805 ** Note: these functions are not protected by lock
806 ** and thus are never allowed to be called from IRQ.
807 ** Also they must not race with fw upload which uses same hw regs
810 /***********************************************************************
811 ** acxpci_write_cmd_type_status
813 ** Origin: Common linux implementation
817 acxpci_write_cmd_type_status(acx_device_t
* adev
, u16 type
, u16 status
)
820 acx_writel(type
| (status
<< 16), adev
->cmd_area
);
826 /***********************************************************************
827 ** acxpci_read_cmd_type_status
829 ** Origin: Common linux implementation
831 static u32
acxpci_read_cmd_type_status(acx_device_t
* adev
)
833 u32 cmd_type
, cmd_status
;
837 cmd_type
= acx_readl(adev
->cmd_area
);
838 cmd_status
= (cmd_type
>> 16);
839 cmd_type
= (u16
) cmd_type
;
841 log(L_CTL
, "cmd_type:%04X cmd_status:%04X [%s]\n",
842 cmd_type
, cmd_status
, acx_cmd_status_str(cmd_status
));
844 FN_EXIT1(cmd_status
);
849 /***********************************************************************
850 ** acxpci_s_reset_dev
853 ** netdevice that contains the adev variable
858 ** device is hard reset
862 ** This resets the device using low level hardware calls
863 ** as well as uploads and verifies the firmware to the card
866 static inline void init_mboxes(acx_device_t
* adev
)
868 u32 cmd_offs
, info_offs
;
872 cmd_offs
= read_reg32(adev
, IO_ACX_CMD_MAILBOX_OFFS
);
873 info_offs
= read_reg32(adev
, IO_ACX_INFO_MAILBOX_OFFS
);
874 adev
->cmd_area
= (u8
*) adev
->iobase2
+ cmd_offs
;
875 adev
->info_area
= (u8
*) adev
->iobase2
+ info_offs
;
876 log(L_DEBUG
, "iobase2=%p\n"
877 "cmd_mbox_offset=%X cmd_area=%p\n"
878 "info_mbox_offset=%X info_area=%p\n",
880 cmd_offs
, adev
->cmd_area
, info_offs
, adev
->info_area
);
885 static inline void read_eeprom_area(acx_device_t
* adev
)
893 for (offs
= 0x8c; offs
< 0xb9; offs
++)
894 acxpci_read_eeprom_byte(adev
, offs
, &tmp
);
901 int acxpci_s_reset_dev(acx_device_t
* adev
)
903 const char *msg
= "";
912 /* reset the device to make sure the eCPU is stopped
913 * to upload the firmware correctly */
915 acx_lock(adev
, flags
);
918 acxpci_l_reset_mac(adev
);
921 ecpu_ctrl
= read_reg16(adev
, IO_ACX_ECPU_CTRL
) & 1;
923 msg
= "eCPU is already running. ";
927 if (read_reg16(adev
, IO_ACX_SOR_CFG
) & 2) {
928 /* eCPU most likely means "embedded CPU" */
929 msg
= "eCPU did not start after boot from flash. ";
933 /* check sense on reset flags */
934 if (read_reg16(adev
, IO_ACX_SOR_CFG
) & 0x10) {
935 printk("%s: eCPU did not start after boot (SOR), "
936 "is this fatal?\n", wiphy_name(adev
->ieee
->wiphy
));
939 /* scan, if any, is stopped now, setting corresponding IRQ bit */
940 SET_BIT(adev
->irq_status
, HOST_INT_SCAN_COMPLETE
);
942 acx_unlock(adev
, flags
);
944 /* need to know radio type before fw load */
945 /* Need to wait for arrival of this information in a loop,
946 * most probably since eCPU runs some init code from EEPROM
947 * (started burst read in reset_mac()) which also
948 * sets the radio type ID */
952 hardware_info
= read_reg16(adev
, IO_ACX_EEPROM_INFORMATION
);
954 msg
= "eCPU didn't indicate radio type";
958 } while (!(hardware_info
& 0xff00)); /* radio type still zero? */
960 /* printk("DEBUG: count %d\n", count); */
961 adev
->form_factor
= hardware_info
& 0xff;
962 adev
->radio_type
= hardware_info
>> 8;
964 /* load the firmware */
965 if (OK
!= acxpci_s_upload_fw(adev
))
968 /* acx_s_mwait(10); this one really shouldn't be required */
970 /* now start eCPU by clearing bit */
971 write_reg16(adev
, IO_ACX_ECPU_CTRL
, ecpu_ctrl
& ~0x1);
972 log(L_DEBUG
, "booted eCPU up and waiting for completion...\n");
974 /* wait for eCPU bootup */
975 if (OK
!= acxpci_s_verify_init(adev
)) {
976 msg
= "timeout waiting for eCPU. ";
979 log(L_DEBUG
, "eCPU has woken up, card is ready to be configured\n");
982 acxpci_write_cmd_type_status(adev
, 0, 0);
984 /* test that EEPROM is readable */
985 read_eeprom_area(adev
);
990 /* Finish error message. Indicate which function failed */
992 acx_unlock(adev
, flags
);
994 printk("acx: %sreset_dev() FAILED\n", msg
);
1001 /***********************************************************************
1002 ** acxpci_s_issue_cmd_timeo
1004 ** Sends command to fw, extract result
1006 ** NB: we do _not_ take lock inside, so be sure to not touch anything
1007 ** which may interfere with IRQ handler operation
1009 ** TODO: busy wait is a bit silly, so:
1010 ** 1) stop doing many iters - go to sleep after first
1011 ** 2) go to waitqueue based approach: wait, not poll!
1014 #define FUNC "issue_cmd"
1018 acxpci_s_issue_cmd_timeo(acx_device_t
* adev
,
1020 void *buffer
, unsigned buflen
, unsigned cmd_timeout
)
1024 acxpci_s_issue_cmd_timeo_debug(acx_device_t
* adev
,
1028 unsigned cmd_timeout
, const char *cmdstr
)
1030 unsigned long start
= jiffies
;
1032 const char *devname
;
1036 unsigned long timeout
;
1040 devname
= wiphy_name(adev
->ieee
->wiphy
);
1041 if (!devname
|| !devname
[0] || devname
[4] == '%')
1044 log(L_CTL
, FUNC
"(cmd:%s,buflen:%u,timeout:%ums,type:0x%04X)\n",
1045 cmdstr
, buflen
, cmd_timeout
,
1046 buffer
? le16_to_cpu(((acx_ie_generic_t
*) buffer
)->type
) : -1);
1048 if (!(adev
->dev_state_mask
& ACX_STATE_FW_LOADED
)) {
1049 printk("%s: " FUNC
"(): firmware is not loaded yet, "
1050 "cannot execute commands!\n", devname
);
1054 if ((acx_debug
& L_DEBUG
) && (cmd
!= ACX1xx_CMD_INTERROGATE
)) {
1055 printk("input buffer (len=%u):\n", buflen
);
1056 acx_dump_bytes(buffer
, buflen
);
1059 /* wait for firmware to become idle for our command submission */
1061 counter
= (timeout
* 1000 / HZ
) - 1; /* in ms */
1064 cmd_status
= acxpci_read_cmd_type_status(adev
);
1065 /* Test for IDLE state */
1068 if (counter
% 8 == 0) {
1069 if (time_after(jiffies
, timeout
)) {
1073 /* we waited 8 iterations, no luck. Sleep 8 ms */
1076 } while (likely(--counter
));
1079 /* the card doesn't get idle, we're in trouble */
1080 printk("%s: " FUNC
"(): cmd_status is not IDLE: 0x%04X!=0\n",
1081 devname
, cmd_status
);
1083 } else if (counter
< 190) { /* if waited >10ms... */
1084 log(L_CTL
| L_DEBUG
, FUNC
"(): waited for IDLE %dms. "
1085 "Please report\n", 199 - counter
);
1088 /* now write the parameters of the command if needed */
1089 if (buffer
&& buflen
) {
1090 /* if it's an INTERROGATE command, just pass the length
1091 * of parameters to read, as data */
1093 if (cmd
== ACX1xx_CMD_INTERROGATE
)
1094 memset_io(adev
->cmd_area
+ 4, 0xAA, buflen
);
1096 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1097 memcpy_toio(adev
->cmd_area
+ 4, buffer
,
1098 (cmd
== ACX1xx_CMD_INTERROGATE
) ? 4 : buflen
);
1100 /* now write the actual command type */
1101 acxpci_write_cmd_type_status(adev
, cmd
, 0);
1102 /* execute command */
1103 write_reg16(adev
, IO_ACX_INT_TRIG
, INT_TRIG_CMD
);
1106 /* wait for firmware to process command */
1108 /* Ensure nonzero and not too large timeout.
1109 ** Also converts e.g. 100->99, 200->199
1110 ** which is nice but not essential */
1111 cmd_timeout
= (cmd_timeout
- 1) | 1;
1112 if (unlikely(cmd_timeout
> 1199))
1114 /* clear CMD_COMPLETE bit. can be set only by IRQ handler: */
1115 CLEAR_BIT(adev
->irq_status
, HOST_INT_CMD_COMPLETE
);
1116 /* we schedule away sometimes (timeout can be large) */
1117 counter
= cmd_timeout
;
1118 timeout
= jiffies
+ HZ
;
1120 if (!adev
->irqs_active
) { /* IRQ disabled: poll */
1121 irqtype
= read_reg16(adev
, IO_ACX_IRQ_STATUS_NON_DES
);
1122 if (irqtype
& HOST_INT_CMD_COMPLETE
) {
1123 write_reg16(adev
, IO_ACX_IRQ_ACK
,
1124 HOST_INT_CMD_COMPLETE
);
1127 } else { /* Wait when IRQ will set the bit */
1128 irqtype
= adev
->irq_status
;
1129 if (irqtype
& HOST_INT_CMD_COMPLETE
)
1133 if (counter
% 8 == 0) {
1134 if (time_after(jiffies
, timeout
)) {
1138 /* we waited 8 iterations, no luck. Sleep 8 ms */
1141 } while (likely(--counter
));
1143 /* save state for debugging */
1144 cmd_status
= acxpci_read_cmd_type_status(adev
);
1146 /* put the card in IDLE state */
1147 acxpci_write_cmd_type_status(adev
, 0, 0);
1149 if ((cmd_timeout
- counter
) == 0) { /* timed out! */
1150 printk("%s: " FUNC
"(): timed out %s for CMD_COMPLETE. "
1151 "irq bits:0x%04X irq_status:0x%04X timeout:%dms "
1152 "cmd_status:%d (%s)\n",
1153 devname
, (adev
->irqs_active
) ? "waiting" : "polling",
1154 irqtype
, adev
->irq_status
, cmd_timeout
,
1155 cmd_status
, acx_cmd_status_str(cmd_status
));
1156 printk("hack: don't do: 'goto bad;'\ncounter: %d cmd_timeout: %d cmd_timeout-counter: %d\n",counter
, cmd_timeout
, cmd_timeout
- counter
);
1157 } else if (counter
== 0) { /* maybe timed out! */
1158 log(L_CTL
| L_DEBUG
, FUNC
"(): %s for CMD_COMPLETE %dms. "
1159 "count:%d. Please report\n",
1160 (adev
->irqs_active
) ? "waited" : "polled",
1161 cmd_timeout
- counter
, counter
);
1162 } else if ((cmd_timeout
- counter
) > 30) { /* if waited >30ms... */
1163 log(L_CTL
| L_DEBUG
, FUNC
"(): %s for CMD_COMPLETE %dms. "
1164 "count:%d. Please report\n",
1165 (adev
->irqs_active
) ? "waited" : "polled",
1166 cmd_timeout
- counter
, counter
);
1169 if (1 != cmd_status
) { /* it is not a 'Success' */
1170 printk("%s: " FUNC
"(): cmd_status is not SUCCESS: %d (%s). "
1171 "Took %dms of %d\n",
1172 devname
, cmd_status
, acx_cmd_status_str(cmd_status
),
1173 cmd_timeout
- counter
, cmd_timeout
);
1174 /* zero out result buffer
1175 * WARNING: this will trash stack in case of illegally large input
1177 if (buffer
&& buflen
)
1178 memset(buffer
, 0, buflen
);
1182 /* read in result parameters if needed */
1183 if (buffer
&& buflen
&& (cmd
== ACX1xx_CMD_INTERROGATE
)) {
1184 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1185 memcpy_fromio(buffer
, adev
->cmd_area
+ 4, buflen
);
1186 if (acx_debug
& L_DEBUG
) {
1187 printk("output buffer (len=%u): ", buflen
);
1188 acx_dump_bytes(buffer
, buflen
);
1192 log(L_CTL
, FUNC
"(%s): took %ld jiffies to complete\n",
1193 cmdstr
, jiffies
- start
);
1198 /* Give enough info so that callers can avoid
1199 ** printing their own diagnostic messages */
1201 printk("%s: " FUNC
"(cmd:%s) FAILED\n", devname
, cmdstr
);
1203 printk("%s: " FUNC
"(cmd:0x%04X) FAILED\n", devname
, cmd
);
1211 /***********************************************************************
1213 #ifdef NONESSENTIAL_FEATURES
1214 typedef struct device_id
{
1215 unsigned char id
[6];
1220 static const device_id_t device_ids
[] = {
1222 {'G', 'l', 'o', 'b', 'a', 'l'},
1227 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
1229 "SpeedStream SS1021 or Gigafast WF721-AEX"},
1231 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85},
1233 "DrayTek Vigor 520"},
1235 {'?', '?', '?', '?', '?', '?'},
1237 "Level One WPC-0200"},
1239 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1244 static void acx_show_card_eeprom_id(acx_device_t
* adev
)
1246 unsigned char buffer
[CARD_EEPROM_ID_SIZE
];
1251 memset(&buffer
, 0, CARD_EEPROM_ID_SIZE
);
1252 /* use direct EEPROM access */
1253 for (i
= 0; i
< CARD_EEPROM_ID_SIZE
; i
++) {
1254 if (OK
!= acxpci_read_eeprom_byte(adev
,
1255 ACX100_EEPROM_ID_OFFSET
+ i
,
1257 printk("acx: reading EEPROM FAILED\n");
1262 for (i
= 0; i
< ARRAY_SIZE(device_ids
); i
++) {
1263 if (!memcmp(&buffer
, device_ids
[i
].id
, CARD_EEPROM_ID_SIZE
)) {
1264 if (device_ids
[i
].descr
) {
1265 printk("acx: EEPROM card ID string check "
1266 "found %s card ID: is this %s?\n",
1267 device_ids
[i
].descr
, device_ids
[i
].type
);
1272 if (i
== ARRAY_SIZE(device_ids
)) {
1273 printk("acx: EEPROM card ID string check found "
1274 "unknown card: expected 'Global', got '%.*s\'. "
1275 "Please report\n", CARD_EEPROM_ID_SIZE
, buffer
);
1279 #endif /* NONESSENTIAL_FEATURES */
1282 /***********************************************************************
1283 ** acxpci_free_desc_queues
1285 ** Releases the queues that have been allocated, the
1286 ** others have been initialised to NULL so this
1287 ** function can be used if only part of the queues were allocated.
1291 free_coherent(struct pci_dev
*hwdev
, size_t size
,
1292 void *vaddr
, dma_addr_t dma_handle
)
1294 dma_free_coherent(hwdev
== NULL
? NULL
: &hwdev
->dev
,
1295 size
, vaddr
, dma_handle
);
1299 void acxpci_free_desc_queues(acx_device_t
* adev
)
1301 unsigned long flags
;
1303 #define ACX_FREE_QUEUE(size, ptr, phyaddr) \
1305 free_coherent(NULL, size, ptr, phyaddr); \
1312 ACX_FREE_QUEUE(adev
->txhostdesc_area_size
, adev
->txhostdesc_start
,
1313 adev
->txhostdesc_startphy
);
1314 ACX_FREE_QUEUE(adev
->txbuf_area_size
, adev
->txbuf_start
,
1315 adev
->txbuf_startphy
);
1317 acx_lock(adev
, flags
);
1318 adev
->txdesc_start
= NULL
;
1319 acx_unlock(adev
, flags
);
1321 ACX_FREE_QUEUE(adev
->rxhostdesc_area_size
, adev
->rxhostdesc_start
,
1322 adev
->rxhostdesc_startphy
);
1323 ACX_FREE_QUEUE(adev
->rxbuf_area_size
, adev
->rxbuf_start
,
1324 adev
->rxbuf_startphy
);
1326 acx_lock(adev
, flags
);
1327 adev
->rxdesc_start
= NULL
;
1328 acx_unlock(adev
, flags
);
1334 /***********************************************************************
1335 ** acxpci_s_delete_dma_regions
1337 static void acxpci_s_delete_dma_regions(acx_device_t
* adev
)
1340 /* disable radio Tx/Rx. Shouldn't we use the firmware commands
1341 * here instead? Or are we that much down the road that it's no
1342 * longer possible here? */
1343 write_reg16(adev
, IO_ACX_ENABLE
, 0);
1347 /* NO locking for all parts of acxpci_free_desc_queues because:
1348 * while calling dma_free_coherent() interrupts need to be 'free'
1349 * but if you spinlock the whole function (acxpci_free_desc_queues)
1350 * you'll get an error */
1351 acxpci_free_desc_queues(adev
);
1357 /***********************************************************************
1360 ** Probe routine called when a PCI device w/ matching ID is found.
1361 ** Here's the sequence:
1362 ** - Allocate the PCI resources.
1363 ** - Read the PCMCIA attribute memory to make sure we have a WLAN card
1365 ** - Initialize the dev and wlan data
1366 ** - Initialize the MAC
1368 ** pdev - ptr to pci device structure containing info about pci configuration
1369 ** id - ptr to the device id entry that matched this device
1371 static const u16 IO_ACX100
[] = {
1372 0x0000, /* IO_ACX_SOFT_RESET */
1374 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1375 0x0018, /* IO_ACX_SLV_MEM_DATA */
1376 0x001c, /* IO_ACX_SLV_MEM_CTL */
1377 0x0020, /* IO_ACX_SLV_END_CTL */
1379 0x0034, /* IO_ACX_FEMR */
1381 0x007c, /* IO_ACX_INT_TRIG */
1382 0x0098, /* IO_ACX_IRQ_MASK */
1383 0x00a4, /* IO_ACX_IRQ_STATUS_NON_DES */
1384 0x00a8, /* IO_ACX_IRQ_STATUS_CLEAR */
1385 0x00ac, /* IO_ACX_IRQ_ACK */
1386 0x00b0, /* IO_ACX_HINT_TRIG */
1388 0x0104, /* IO_ACX_ENABLE */
1390 0x0250, /* IO_ACX_EEPROM_CTL */
1391 0x0254, /* IO_ACX_EEPROM_ADDR */
1392 0x0258, /* IO_ACX_EEPROM_DATA */
1393 0x025c, /* IO_ACX_EEPROM_CFG */
1395 0x0268, /* IO_ACX_PHY_ADDR */
1396 0x026c, /* IO_ACX_PHY_DATA */
1397 0x0270, /* IO_ACX_PHY_CTL */
1399 0x0290, /* IO_ACX_GPIO_OE */
1401 0x0298, /* IO_ACX_GPIO_OUT */
1403 0x02a4, /* IO_ACX_CMD_MAILBOX_OFFS */
1404 0x02a8, /* IO_ACX_INFO_MAILBOX_OFFS */
1405 0x02ac, /* IO_ACX_EEPROM_INFORMATION */
1407 0x02d0, /* IO_ACX_EE_START */
1408 0x02d4, /* IO_ACX_SOR_CFG */
1409 0x02d8 /* IO_ACX_ECPU_CTRL */
1412 static const u16 IO_ACX111
[] = {
1413 0x0000, /* IO_ACX_SOFT_RESET */
1415 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1416 0x0018, /* IO_ACX_SLV_MEM_DATA */
1417 0x001c, /* IO_ACX_SLV_MEM_CTL */
1418 0x0020, /* IO_ACX_SLV_END_CTL */
1420 0x0034, /* IO_ACX_FEMR */
1422 0x00b4, /* IO_ACX_INT_TRIG */
1423 0x00d4, /* IO_ACX_IRQ_MASK */
1424 /* we do mean NON_DES (0xf0), not NON_DES_MASK which is at 0xe0: */
1425 0x00f0, /* IO_ACX_IRQ_STATUS_NON_DES */
1426 0x00e4, /* IO_ACX_IRQ_STATUS_CLEAR */
1427 0x00e8, /* IO_ACX_IRQ_ACK */
1428 0x00ec, /* IO_ACX_HINT_TRIG */
1430 0x01d0, /* IO_ACX_ENABLE */
1432 0x0338, /* IO_ACX_EEPROM_CTL */
1433 0x033c, /* IO_ACX_EEPROM_ADDR */
1434 0x0340, /* IO_ACX_EEPROM_DATA */
1435 0x0344, /* IO_ACX_EEPROM_CFG */
1437 0x0350, /* IO_ACX_PHY_ADDR */
1438 0x0354, /* IO_ACX_PHY_DATA */
1439 0x0358, /* IO_ACX_PHY_CTL */
1441 0x0374, /* IO_ACX_GPIO_OE */
1443 0x037c, /* IO_ACX_GPIO_OUT */
1445 0x0388, /* IO_ACX_CMD_MAILBOX_OFFS */
1446 0x038c, /* IO_ACX_INFO_MAILBOX_OFFS */
1447 0x0390, /* IO_ACX_EEPROM_INFORMATION */
1449 0x0100, /* IO_ACX_EE_START */
1450 0x0104, /* IO_ACX_SOR_CFG */
1451 0x0108, /* IO_ACX_ECPU_CTRL */
1454 static const struct ieee80211_ops acxpci_hw_ops
= {
1455 .tx
= acx_i_start_xmit
,
1456 .conf_tx
= acx_net_conf_tx
,
1457 .add_interface
= acx_add_interface
,
1458 .remove_interface
= acx_remove_interface
,
1459 .start
= acxpci_e_open
,
1460 .configure_filter
= acx_i_set_multicast_list
,
1461 .stop
= acxpci_e_close
,
1462 .config
= acx_net_config
,
1463 .config_interface
= acx_config_interface
,
1464 .set_key
= acx_net_set_key
,
1465 .get_stats
= acx_e_get_stats
,
1466 .get_tx_stats
= acx_net_get_tx_stats
,
1471 static int __devinit
1472 acxpci_e_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1474 acx111_ie_configoption_t co
;
1475 unsigned long mem_region1
= 0;
1476 unsigned long mem_region2
= 0;
1477 unsigned long mem_region1_size
;
1478 unsigned long mem_region2_size
;
1479 unsigned long phymem1
;
1480 unsigned long phymem2
;
1483 acx_device_t
*adev
= NULL
;
1484 const char *chip_name
;
1488 struct ieee80211_hw
*ieee
;
1492 ieee
= ieee80211_alloc_hw(sizeof(struct acx_device
), &acxpci_hw_ops
);
1494 printk("acx: could not allocate ieee80211 structure %s\n",
1496 goto fail_alloc_netdev
;
1498 ieee
->flags
&= ~IEEE80211_HW_RX_INCLUDES_FCS
;
1499 /* TODO: mainline doesn't support the following flags yet */
1501 ~IEEE80211_HW_MONITOR_DURING_OPER &
1502 ~IEEE80211_HW_WEP_INCLUDE_IV;
1506 /* (NB: memsets to 0 entire area) */
1508 printk("acx: could not allocate ieee structure %s\n",
1510 goto fail_alloc_netdev
;
1513 adev
= ieee2adev(ieee
);
1515 memset(adev
, 0, sizeof(*adev
));
1516 /** Set up our private interface **/
1517 spin_lock_init(&adev
->spinlock
); /* initial state: unlocked */
1518 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
1519 printk("mutex_init(&adev->mutex); // adev = 0x%px\n", adev
);
1520 mutex_init(&adev
->mutex
);
1521 /* since nobody can see new netdev yet, we can as well
1522 ** just _presume_ that we're under sem (instead of actually taking it): */
1523 /* acx_sem_lock(adev); */
1526 adev
->bus_dev
= &pdev
->dev
;
1527 adev
->dev_type
= DEVTYPE_PCI
;
1529 /** Finished with private interface **/
1531 /** begin board specific inits **/
1532 pci_set_drvdata(pdev
, ieee
);
1534 /* Enable the PCI device */
1535 if (pci_enable_device(pdev
)) {
1536 printk("acx: pci_enable_device() FAILED\n");
1538 goto fail_pci_enable_device
;
1541 /* enable busmastering (required for CardBus) */
1542 pci_set_master(pdev
);
1545 /* chiptype is u8 but id->driver_data is ulong
1546 ** Works for now (possible values are 1 and 2) */
1547 chip_type
= (u8
) id
->driver_data
;
1548 /* acx100 and acx111 have different PCI memory regions */
1549 if (chip_type
== CHIPTYPE_ACX100
) {
1550 chip_name
= "ACX100";
1551 mem_region1
= PCI_ACX100_REGION1
;
1552 mem_region1_size
= PCI_ACX100_REGION1_SIZE
;
1554 mem_region2
= PCI_ACX100_REGION2
;
1555 mem_region2_size
= PCI_ACX100_REGION2_SIZE
;
1556 } else if (chip_type
== CHIPTYPE_ACX111
) {
1557 chip_name
= "ACX111";
1558 mem_region1
= PCI_ACX111_REGION1
;
1559 mem_region1_size
= PCI_ACX111_REGION1_SIZE
;
1561 mem_region2
= PCI_ACX111_REGION2
;
1562 mem_region2_size
= PCI_ACX111_REGION2_SIZE
;
1564 printk("acx: unknown chip type 0x%04X\n", chip_type
);
1565 goto fail_unknown_chiptype
;
1568 /* Figure out our resources */
1569 phymem1
= pci_resource_start(pdev
, mem_region1
);
1570 phymem2
= pci_resource_start(pdev
, mem_region2
);
1571 if (!request_mem_region
1572 (phymem1
, pci_resource_len(pdev
, mem_region1
), "acx_1")) {
1573 printk("acx: cannot reserve PCI memory region 1 (are you sure "
1574 "you have CardBus support in kernel?)\n");
1575 goto fail_request_mem_region1
;
1577 if (!request_mem_region
1578 (phymem2
, pci_resource_len(pdev
, mem_region2
), "acx_2")) {
1579 printk("acx: cannot reserve PCI memory region 2\n");
1580 goto fail_request_mem_region2
;
1582 /* this used to be ioremap(), but ioremap_nocache()
1583 * is much less risky, right? (and slower?)
1584 * FIXME: we may want to go back to cached variant if it's
1585 * certain that our code really properly handles
1586 * cached operation (memory barriers, volatile?, ...)
1587 * (but always keep this comment here regardless!)
1588 * Possibly make this a driver config setting?
1591 mem1
= ioremap_nocache(phymem1
, mem_region1_size
);
1593 printk("acx: ioremap() FAILED\n");
1596 mem2
= ioremap_nocache(phymem2
, mem_region2_size
);
1598 printk("acx: ioremap() #2 FAILED\n");
1602 printk("acx: found %s-based wireless network card at %s, irq:%d, "
1603 "phymem1:0x%lX, phymem2:0x%lX, mem1:0x%p, mem1_size:%ld, "
1604 "mem2:0x%p, mem2_size:%ld\n",
1605 chip_name
, pci_name(pdev
), pdev
->irq
, phymem1
, phymem2
,
1606 mem1
, mem_region1_size
, mem2
, mem_region2_size
);
1607 log(L_ANY
, "initial debug setting is 0x%04X\n", acx_debug
);
1608 adev
->chip_type
= chip_type
;
1609 adev
->chip_name
= chip_name
;
1610 adev
->io
= (CHIPTYPE_ACX100
== chip_type
) ? IO_ACX100
: IO_ACX111
;
1611 adev
->membase
= phymem1
;
1612 adev
->iobase
= mem1
;
1613 adev
->membase2
= phymem2
;
1614 adev
->iobase2
= mem2
;
1615 adev
->irq
= pdev
->irq
;
1618 if (0 == pdev
->irq
) {
1619 printk("acx: can't use IRQ 0\n");
1622 SET_IEEE80211_DEV(ieee
, &pdev
->dev
);
1625 /* to find crashes due to weird driver access
1626 * to unconfigured interface (ifup) */
1627 adev
->mgmt_timer
.function
= (void (*)(unsigned long))0x0000dead;
1630 #ifdef NONESSENTIAL_FEATURES
1631 acx_show_card_eeprom_id(adev
);
1632 #endif /* NONESSENTIAL_FEATURES */
1635 /* ok, pci setup is finished, now start initializing the card */
1637 /* NB: read_reg() reads may return bogus data before reset_dev(),
1638 * since the firmware which directly controls large parts of the I/O
1639 * registers isn't initialized yet.
1640 * acx100 seems to be more affected than acx111 */
1641 if (OK
!= acxpci_s_reset_dev(adev
))
1644 if (IS_ACX100(adev
)) {
1645 /* ACX100: configopt struct in cmd mailbox - directly after reset */
1646 memcpy_fromio(&co
, adev
->cmd_area
, sizeof(co
));
1649 if (OK
!= acx_s_init_mac(adev
))
1652 if (IS_ACX111(adev
)) {
1653 /* ACX111: configopt struct needs to be queried after full init */
1654 acx_s_interrogate(adev
, &co
, ACX111_IE_CONFIG_OPTIONS
);
1656 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
1657 if (OK
!= acxpci_read_eeprom_byte(adev
, 0x05, &adev
->eeprom_version
))
1658 goto fail_read_eeprom_version
;
1660 acx_s_parse_configoption(adev
, &co
);
1661 acx_s_set_defaults(adev
);
1662 acx_s_get_firmware_version(adev
); /* needs to be after acx_s_init_mac() */
1663 acx_display_hardware_details(adev
);
1665 /* Register the card, AFTER everything else has been set up,
1666 * since otherwise an ioctl could step on our feet due to
1667 * firmware operations happening in parallel or uninitialized data */
1670 acx_proc_register_entries(ieee
);
1672 /* Now we have our device, so make sure the kernel doesn't try
1673 * to send packets even though we're not associated to a network yet */
1675 /* after register_netdev() userspace may start working with dev
1676 * (in particular, on other CPUs), we only need to up the sem */
1677 /* acx_sem_unlock(adev); */
1679 printk("acx " ACX_RELEASE
": net device %s, driver compiled "
1680 "against wireless extensions %d and Linux %s\n",
1681 wiphy_name(adev
->ieee
->wiphy
), WIRELESS_EXT
, UTS_RELEASE
);
1683 MAC_COPY(adev
->ieee
->wiphy
->perm_addr
, adev
->dev_addr
);
1685 log(L_IRQ
| L_INIT
, "using IRQ %d\n", pdev
->irq
);
1687 /** done with board specific setup **/
1689 /* need to be able to restore PCI state after a suspend */
1691 pci_save_state(pdev
);
1695 acx_init_task_scheduler(adev
);
1696 err
= ieee80211_register_hw(adev
->ieee
);
1698 printk("acx: ieee80211_register_hw() FAILED: %d\n", err
);
1699 goto fail_register_netdev
;
1702 great_inquisitor(adev
);
1708 /* error paths: undo everything in reverse order... */
1711 acxpci_s_delete_dma_regions(adev
);
1712 pci_set_drvdata(pdev
, NULL
);
1715 fail_read_eeprom_version
:
1727 release_mem_region(pci_resource_start(pdev
, mem_region2
),
1728 pci_resource_len(pdev
, mem_region2
));
1729 fail_request_mem_region2
:
1731 release_mem_region(pci_resource_start(pdev
, mem_region1
),
1732 pci_resource_len(pdev
, mem_region1
));
1733 fail_request_mem_region1
:
1734 fail_unknown_chiptype
:
1736 pci_disable_device(pdev
);
1737 fail_pci_enable_device
:
1740 pci_set_power_state(pdev
, PCI_D3hot
);
1742 fail_register_netdev
:
1743 ieee80211_free_hw(ieee
);
1750 /***********************************************************************
1753 ** Shut device down (if not hot unplugged)
1754 ** and deallocate PCI resources for the acx chip.
1756 ** pdev - ptr to PCI device structure containing info about pci configuration
1758 static void __devexit
acxpci_e_remove(struct pci_dev
*pdev
)
1760 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*)pci_get_drvdata(pdev
);
1761 acx_device_t
*adev
= ieee2adev(hw
);
1762 unsigned long mem_region1
, mem_region2
;
1763 unsigned long flags
;
1767 log(L_DEBUG
, "%s: card is unused. Skipping any release code\n",
1773 adev
->initialized
= 0;
1775 /* If device wasn't hot unplugged... */
1776 if (adev_present(adev
)) {
1778 /* disable both Tx and Rx to shut radio down properly */
1779 if (adev
->initialized
) {
1780 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_TX
, NULL
, 0);
1781 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_RX
, NULL
, 0);
1784 /* put the eCPU to sleep to save power
1785 * Halting is not possible currently,
1786 * since not supported by all firmware versions */
1787 acx_s_issue_cmd(adev
, ACX100_CMD_SLEEP
, NULL
, 0);
1789 acx_lock(adev
, flags
);
1790 /* disable power LED to save power :-) */
1791 log(L_INIT
, "switching off power LED to save power\n");
1792 acxpci_l_power_led(adev
, 0);
1794 if (IS_ACX111(adev
)) {
1795 /* FIXME: does this actually keep halting the eCPU?
1796 * I don't think so...
1798 acxpci_l_reset_mac(adev
);
1802 temp
= read_reg16(adev
, IO_ACX_ECPU_CTRL
) | 0x1;
1803 write_reg16(adev
, IO_ACX_ECPU_CTRL
, temp
);
1806 acx_unlock(adev
, flags
);
1810 /* unregister the device to not let the kernel
1811 * (e.g. ioctls) access a half-deconfigured device
1812 * NB: this will cause acxpci_e_close() to be called,
1813 * thus we shouldn't call it under sem!
1814 * Well, netdev did, but ieee80211 stack does not, so we
1815 * have to do so manually...
1818 log(L_INIT
, "removing device %s\n", wiphy_name(adev
->ieee
->wiphy
));
1819 ieee80211_unregister_hw(adev
->ieee
);
1821 /* unregister_netdev ensures that no references to us left.
1822 * For paranoid reasons we continue to follow the rules */
1825 if (adev
->dev_state_mask
& ACX_STATE_IFACE_UP
) {
1827 CLEAR_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
1830 acx_proc_unregister_entries(adev
->ieee
);
1832 if (IS_ACX100(adev
)) {
1833 mem_region1
= PCI_ACX100_REGION1
;
1834 mem_region2
= PCI_ACX100_REGION2
;
1836 mem_region1
= PCI_ACX111_REGION1
;
1837 mem_region2
= PCI_ACX111_REGION2
;
1840 /* finally, clean up PCI bus state */
1841 acxpci_s_delete_dma_regions(adev
);
1843 iounmap(adev
->iobase
);
1845 iounmap(adev
->iobase2
);
1846 release_mem_region(pci_resource_start(pdev
, mem_region1
),
1847 pci_resource_len(pdev
, mem_region1
));
1848 release_mem_region(pci_resource_start(pdev
, mem_region2
),
1849 pci_resource_len(pdev
, mem_region2
));
1850 pci_disable_device(pdev
);
1852 /* remove dev registration */
1854 free_irq(adev
->irq
, adev
);
1855 acx_sem_unlock(adev
);
1857 /* Free netdev (quite late,
1858 * since otherwise we might get caught off-guard
1859 * by a netdev timeout handler execution
1860 * expecting to see a working dev...) */
1861 ieee80211_free_hw(adev
->ieee
);
1863 /* put device into ACPI D3 mode (shutdown) */
1865 pci_set_power_state(pdev
, PCI_D3hot
);
1872 /***********************************************************************
1873 ** TODO: PM code needs to be fixed / debugged / tested.
1877 acxpci_e_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1879 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
1883 printk("acx: suspend handler is experimental!\n");
1884 printk("sus: dev %p\n", hw
);
1886 /* if (!netif_running(ndev))
1889 adev
= ieee2adev(hw
);
1890 printk("sus: adev %p\n", adev
);
1894 ieee80211_unregister_hw(hw
); /* this one cannot sleep */
1896 /* down() does not set it to 0xffff, but here we really want that */
1897 write_reg16(adev
, IO_ACX_IRQ_MASK
, 0xffff);
1898 write_reg16(adev
, IO_ACX_FEMR
, 0x0);
1899 acxpci_s_delete_dma_regions(adev
);
1900 pci_save_state(pdev
);
1901 pci_set_power_state(pdev
, PCI_D3hot
);
1903 acx_sem_unlock(adev
);
1909 static int acxpci_e_resume(struct pci_dev
*pdev
)
1911 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
1916 printk("acx: resume handler is experimental!\n");
1917 printk("rsm: got dev %p\n", hw
);
1920 adev
= ieee2adev(hw
);
1921 printk("rsm: got adev %p\n", adev
);
1925 pci_set_power_state(pdev
, PCI_D0
);
1926 printk("rsm: power state PCI_D0 set\n");
1927 pci_restore_state(pdev
);
1928 printk("rsm: PCI state restored\n");
1930 if (OK
!= acxpci_s_reset_dev(adev
))
1932 printk("rsm: device reset done\n");
1933 if (OK
!= acx_s_init_mac(adev
))
1935 printk("rsm: init MAC done\n");
1938 printk("rsm: acx up done\n");
1940 /* now even reload all card parameters as they were before suspend,
1941 * and possibly be back in the network again already :-) */
1942 if (ACX_STATE_IFACE_UP
& adev
->dev_state_mask
) {
1943 adev
->set_mask
= GETSET_ALL
;
1944 acx_s_update_card_settings(adev
);
1945 printk("rsm: settings updated\n");
1947 ieee80211_register_hw(hw
);
1948 printk("rsm: device attached\n");
1951 acx_sem_unlock(adev
);
1952 /* we need to return OK here anyway, right? */
1956 #endif /* CONFIG_PM */
1957 #endif /* CONFIG_PCI */
1959 /***********************************************************************
1962 ** This function is called by acxpci_e_open (when ifconfig sets the device as up)
1965 ** - Enables on-card interrupt requests
1966 ** - calls acx_s_start
1969 static void enable_acx_irq(acx_device_t
* adev
)
1972 write_reg16(adev
, IO_ACX_IRQ_MASK
, adev
->irq_mask
);
1973 write_reg16(adev
, IO_ACX_FEMR
, 0x8000);
1974 adev
->irqs_active
= 1;
1978 static void acxpci_s_up(struct ieee80211_hw
*hw
)
1980 acx_device_t
*adev
= ieee2adev(hw
);
1981 unsigned long flags
;
1985 acx_lock(adev
, flags
);
1986 enable_acx_irq(adev
);
1987 acx_unlock(adev
, flags
);
1989 /* acx fw < 1.9.3.e has a hardware timer, and older drivers
1990 ** used to use it. But we don't do that anymore, our OS
1991 ** has reliable software timers */
1992 init_timer(&adev
->mgmt_timer
);
1993 adev
->mgmt_timer
.function
= acx_i_timer
;
1994 adev
->mgmt_timer
.data
= (unsigned long)adev
;
1996 /* Need to set ACX_STATE_IFACE_UP first, or else
1997 ** timer won't be started by acx_set_status() */
1998 SET_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
2006 /***********************************************************************
2009 ** NB: device may be already hot unplugged if called from acxpci_e_remove()
2011 ** Disables on-card interrupt request, stops softirq and timer, stops queue,
2012 ** sets status == STOPPED
2015 static void disable_acx_irq(acx_device_t
* adev
)
2019 /* I guess mask is not 0xffff because acx100 won't signal
2020 ** cmd completion then (needed for ifup).
2021 ** I can't ifconfig up after ifconfig down'ing on my acx100 */
2022 write_reg16(adev
, IO_ACX_IRQ_MASK
, adev
->irq_mask_off
);
2023 write_reg16(adev
, IO_ACX_FEMR
, 0x0);
2024 adev
->irqs_active
= 0;
2029 static void acxpci_s_down(struct ieee80211_hw
*hw
)
2031 acx_device_t
*adev
= ieee2adev(hw
);
2035 /* Disable IRQs first, so that IRQs cannot race with us */
2036 /* then wait until interrupts have finished executing on other CPUs */
2037 disable_acx_irq(adev
); /* NO sem-locking here? */
2038 synchronize_irq(adev
->irq
);
2040 /* we really don't want to have an asynchronous tasklet disturb us
2041 ** after something vital for its job has been shut down, so
2042 ** end all remaining work now.
2044 ** NB: carrier_off (done by set_status below) would lead to
2045 ** not yet fully understood deadlock in flush_scheduled_work().
2046 ** That's why we do FLUSH first.
2048 ** NB2: we have a bad locking bug here: flush_scheduled_work()
2049 ** waits for acx_e_after_interrupt_task to complete if it is running
2050 ** on another CPU, but acx_e_after_interrupt_task
2051 ** will sleep on sem forever, because it is taken by us!
2052 ** Work around that by temporary sem unlock.
2053 ** This will fail miserably if we'll be hit by concurrent
2054 ** iwconfig or something in between. TODO! */
2055 acx_sem_unlock(adev
);
2056 flush_scheduled_work();
2059 /* This is possible:
2060 ** flush_scheduled_work -> acx_e_after_interrupt_task ->
2061 ** -> set_status(ASSOCIATED) -> wake_queue()
2062 ** That's why we stop queue _after_ flush_scheduled_work
2063 ** lock/unlock is just paranoia, maybe not needed */
2065 /* kernel/timer.c says it's illegal to del_timer_sync()
2066 ** a timer which restarts itself. We guarantee this cannot
2067 ** ever happen because acx_i_timer() never does this if
2068 ** status is ACX_STATUS_0_STOPPED */
2069 del_timer_sync(&adev
->mgmt_timer
);
2074 #ifdef CONFIG_NET_POLL_CONTROLLER
2075 void acxpci_net_poll_controller(struct net_device *net_dev)
2077 acx_device_t *adev = ndev2adev(net_dev);
2078 unsigned long flags;
2080 local_irq_save(flags);
2081 acxpci_i_interrupt(adev->irq, adev);
2082 local_irq_restore(flags);
2084 #endif*/ /* CONFIG_NET_POLL_CONTROLLER */
2086 /***********************************************************************
2089 ** Called as a result of SIOCSIFFLAGS ioctl changing the flags bit IFF_UP
2090 ** from clear to set. In other words: ifconfig up.
2094 ** >0 f/w reported error
2095 ** <0 driver reported error
2097 static int acxpci_e_open(struct ieee80211_hw
*hw
)
2099 acx_device_t
*adev
= ieee2adev(hw
);
2106 adev
->initialized
= 0;
2108 /* TODO: pci_set_power_state(pdev, PCI_D0); ? */
2110 /* request shared IRQ handler */
2112 (adev
->irq
, acxpci_i_interrupt
, IRQF_SHARED
, KBUILD_MODNAME
, adev
)) {
2113 printk("%s: request_irq FAILED\n", wiphy_name(adev
->ieee
->wiphy
));
2117 log(L_DEBUG
| L_IRQ
, "request_irq %d successful\n", adev
->irq
);
2122 /* We don't currently have to do anything else.
2123 * The setup of the MAC should be subsequently completed via
2124 * the mlme commands.
2125 * Higher layers know we're ready from dev->start==1 and
2126 * dev->tbusy==0. Our rx path knows to pass up received/
2127 * frames because of dev->flags&IFF_UP is true.
2129 acx_setup_modes(adev
);
2130 ieee80211_start_queues(adev
->ieee
);
2132 adev
->initialized
= 1;
2134 acx_sem_unlock(adev
);
2141 /***********************************************************************
2144 ** This function stops the network functionality of the interface (invoked
2145 ** when the user calls ifconfig <wlan> down). The tx queue is halted and
2146 ** the device is marked as down.
2148 ** Called as a result of SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
2149 ** from set to clear. I.e. called by "ifconfig DEV down"
2153 ** >0 f/w reported error
2154 ** <0 driver reported error
2156 static void acxpci_e_close(struct ieee80211_hw
*hw
)
2158 acx_device_t
*adev
= ieee2adev(hw
);
2165 CLEAR_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
2166 if (adev
->initialized
) {
2171 acx_free_modes(adev
);
2172 /* disable all IRQs, release shared IRQ handler */
2173 write_reg16(adev
, IO_ACX_IRQ_MASK
, 0xffff);
2174 write_reg16(adev
, IO_ACX_FEMR
, 0x0);
2176 /* TODO: pci_set_power_state(pdev, PCI_D3hot); ? */
2178 /* We currently don't have to do anything else.
2179 * Higher layers know we're not ready from dev->start==0 and
2180 * dev->tbusy==1. Our rx path knows to not pass up received
2181 * frames because of dev->flags&IFF_UP is false.
2183 acx_sem_unlock(adev
);
2185 log(L_INIT
, "closed device\n");
2192 /***************************************************************
2193 ** acxpci_l_process_rxdesc
2195 ** Called directly and only from the IRQ handler
2199 static inline void log_rxbuffer(const acx_device_t
* adev
)
2203 static void log_rxbuffer(const acx_device_t
* adev
)
2205 register const struct rxhostdesc
*rxhostdesc
;
2208 /* no FN_ENTER here, we don't want that */
2210 rxhostdesc
= adev
->rxhostdesc_start
;
2211 if (unlikely(!rxhostdesc
))
2213 for (i
= 0; i
< RX_CNT
; i
++) {
2214 if ((rxhostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
2215 && (rxhostdesc
->Status
& cpu_to_le32(DESC_STATUS_FULL
)))
2216 printk("rx: buf %d full\n", i
);
2222 static void acxpci_l_process_rxdesc(acx_device_t
* adev
)
2224 register rxhostdesc_t
*hostdesc
;
2225 unsigned count
, tail
;
2229 if (unlikely(acx_debug
& L_BUFR
))
2232 /* First, have a loop to determine the first descriptor that's
2233 * full, just in case there's a mismatch between our current
2234 * rx_tail and the full descriptor we're supposed to handle. */
2235 tail
= adev
->rx_tail
;
2238 hostdesc
= &adev
->rxhostdesc_start
[tail
];
2239 /* advance tail regardless of outcome of the below test */
2240 tail
= (tail
+ 1) % RX_CNT
;
2242 if ((hostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
2243 && (hostdesc
->Status
& cpu_to_le32(DESC_STATUS_FULL
)))
2244 break; /* found it! */
2246 if (unlikely(!--count
)) /* hmm, no luck: all descs empty, bail out */
2250 /* now process descriptors, starting with the first we figured out */
2252 log(L_BUFR
, "rx: tail=%u Ctl_16=%04X Status=%08X\n",
2253 tail
, hostdesc
->Ctl_16
, hostdesc
->Status
);
2255 acx_l_process_rxbuf(adev
, hostdesc
->data
);
2256 hostdesc
->Status
= 0;
2257 /* flush all writes before adapter sees CTL_HOSTOWN change */
2259 /* Host no longer owns this, needs to be LAST */
2260 CLEAR_BIT(hostdesc
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
2262 /* ok, descriptor is handled, now check the next descriptor */
2263 hostdesc
= &adev
->rxhostdesc_start
[tail
];
2265 /* if next descriptor is empty, then bail out */
2266 if (!(hostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
2267 || !(hostdesc
->Status
& cpu_to_le32(DESC_STATUS_FULL
)))
2270 tail
= (tail
+ 1) % RX_CNT
;
2273 adev
->rx_tail
= tail
;
2279 /***********************************************************************
2280 ** acxpci_i_interrupt
2282 ** IRQ handler (atomic context, must not sleep, blah, blah)
2285 /* scan is complete. all frames now on the receive queue are valid */
2286 #define INFO_SCAN_COMPLETE 0x0001
2287 #define INFO_WEP_KEY_NOT_FOUND 0x0002
2288 /* hw has been reset as the result of a watchdog timer timeout */
2289 #define INFO_WATCH_DOG_RESET 0x0003
2290 /* failed to send out NULL frame from PS mode notification to AP */
2291 /* recommended action: try entering 802.11 PS mode again */
2292 #define INFO_PS_FAIL 0x0004
2293 /* encryption/decryption process on a packet failed */
2294 #define INFO_IV_ICV_FAILURE 0x0005
2296 /* Info mailbox format:
2299 more bytes may follow
2300 rumors say about status:
2301 0x0000 info available (set by hw)
2302 0x0001 information received (must be set by host)
2303 0x1000 info available, mailbox overflowed (messages lost) (set by hw)
2304 but in practice we've seen:
2305 0x9000 when we did not set status to 0x0001 on prev message
2306 0x1001 when we did set it
2307 0x0000 was never seen
2308 conclusion: this is really a bitfield:
2309 0x1000 is 'info available' bit
2310 'mailbox overflowed' bit is 0x8000, not 0x1000
2311 value of 0x0000 probably means that there are no messages at all
2312 P.S. I dunno how in hell hw is supposed to notice that messages are lost -
2313 it does NOT clear bit 0x0001, and this bit will probably stay forever set
2314 after we set it once. Let's hope this will be fixed in firmware someday
2317 static void handle_info_irq(acx_device_t
* adev
)
2320 static const char *const info_type_msg
[] = {
2323 "WEP key not found",
2324 "internal watchdog reset was done",
2325 "failed to send powersave (NULL frame) notification to AP",
2326 "encrypt/decrypt on a packet has failed",
2327 "TKIP tx keys disabled",
2328 "TKIP rx keys disabled",
2329 "TKIP rx: key ID not found",
2337 "TKIP IV value exceeds thresh"
2340 u32 info_type
, info_status
;
2342 info_type
= acx_readl(adev
->info_area
);
2343 info_status
= (info_type
>> 16);
2344 info_type
= (u16
) info_type
;
2346 /* inform fw that we have read this info message */
2347 acx_writel(info_type
| 0x00010000, adev
->info_area
);
2348 write_reg16(adev
, IO_ACX_INT_TRIG
, INT_TRIG_INFOACK
);
2351 log(L_CTL
, "info_type:%04X info_status:%04X\n", info_type
, info_status
);
2353 log(L_IRQ
, "got Info IRQ: status %04X type %04X: %s\n",
2354 info_status
, info_type
,
2355 info_type_msg
[(info_type
>= ARRAY_SIZE(info_type_msg
)) ?
2361 static void log_unusual_irq(u16 irqtype
)
2364 if (!printk_ratelimit())
2369 if (irqtype
& HOST_INT_RX_DATA
) {
2372 /* HOST_INT_TX_COMPLETE */
2373 if (irqtype
& HOST_INT_TX_XFER
) {
2376 /* HOST_INT_RX_COMPLETE */
2377 if (irqtype
& HOST_INT_DTIM
) {
2380 if (irqtype
& HOST_INT_BEACON
) {
2383 if (irqtype
& HOST_INT_TIMER
) {
2384 log(L_IRQ
, " Timer");
2386 if (irqtype
& HOST_INT_KEY_NOT_FOUND
) {
2387 printk(" Key_Not_Found");
2389 if (irqtype
& HOST_INT_IV_ICV_FAILURE
) {
2390 printk(" IV_ICV_Failure (crypto)");
2392 /* HOST_INT_CMD_COMPLETE */
2394 if (irqtype
& HOST_INT_OVERFLOW
) {
2395 printk(" Overflow");
2397 if (irqtype
& HOST_INT_PROCESS_ERROR
) {
2398 printk(" Process_Error");
2400 /* HOST_INT_SCAN_COMPLETE */
2401 if (irqtype
& HOST_INT_FCS_THRESHOLD
) {
2402 printk(" FCS_Threshold");
2404 if (irqtype
& HOST_INT_UNKNOWN
) {
2407 printk(" IRQ(s)\n");
2410 /* FIXME: update_link_quality_led was a stub - let's comment it and avoid
2411 * compiler warnings */
2413 static void update_link_quality_led(acx_device_t * adev)
2418 acx_signal_determine_quality(adev->wstats.qual.level,
2419 adev->wstats.qual.noise);
2420 if (qual > adev->brange_max_quality)
2421 qual = adev->brange_max_quality;
2423 if (time_after(jiffies, adev->brange_time_last_state_change +
2425 HZ / 2 * (unsigned long)qual /
2426 adev->brange_max_quality))) {
2427 acxpci_l_power_led(adev, (adev->brange_last_state == 0));
2428 adev->brange_last_state ^= 1; // toggle
2429 adev->brange_time_last_state_change = jiffies;
2434 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* a la orinoco.c */
2436 /* Interrupt handler bottom-half */
2437 void acx_interrupt_tasklet(struct work_struct
*work
)
2440 #ifdef CONFIG_ACX_MAC80211_DEBUG
2441 u32 _handled
= 0x00000000;
2442 # define acxirq_handled(irq) do { _handled |= (irq); } while (0)
2444 # define acxirq_handled(irq) do { /* nothing */ } while (0)
2445 #endif /* CONFIG_ACX_MAC80211_DEBUG */
2446 acx_device_t
*adev
= container_of(work
,struct acx_device
, after_interrupt_task
);
2447 // unsigned int irqcount = MAX_IRQLOOPS_PER_JIFFY;
2452 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2456 irqtype
= adev
->irq_reason
;
2457 adev
->irq_reason
= 0;
2459 #define IRQ_ITERATE 0
2461 if (jiffies
!= adev
->irq_last_jiffies
) {
2462 adev
->irq_loops_this_jiffy
= 0;
2463 adev
->irq_last_jiffies
= jiffies
;
2466 /* safety condition; we'll normally abort loop below
2467 * in case no IRQ type occurred */
2468 while (likely(--irqcount
)) {
2470 /* ACK all IRQs ASAP */
2473 /* Handle most important IRQ types first */
2474 if (irqtype
& HOST_INT_RX_COMPLETE
) {
2475 log(L_IRQ
, "got Rx_Complete IRQ\n");
2476 acxpci_l_process_rxdesc(adev
);
2478 if (irqtype
& HOST_INT_TX_COMPLETE
) {
2479 log(L_IRQ
, "got Tx_Complete IRQ\n");
2480 /* don't clean up on each Tx complete, wait a bit
2481 * unless we're going towards full, in which case
2482 * we do it immediately, too (otherwise we might lockup
2483 * with a full Tx buffer if we go into
2484 * acxpci_l_clean_txdesc() at a time when we won't wakeup
2485 * the net queue in there for some reason...) */
2486 // if (adev->tx_free <= TX_START_CLEAN) {
2487 acxpci_l_clean_txdesc(adev
);
2491 /* Less frequent ones */
2493 | HOST_INT_CMD_COMPLETE
2494 | HOST_INT_INFO
| HOST_INT_SCAN_COMPLETE
)) {
2495 if (irqtype
& HOST_INT_INFO
) {
2496 handle_info_irq(adev
);
2498 if (irqtype
& HOST_INT_SCAN_COMPLETE
) {
2499 log(L_IRQ
, "got Scan_Complete IRQ\n");
2500 /* need to do that in process context */
2501 /* remember that fw is not scanning anymore */
2502 SET_BIT(adev
->irq_status
,
2503 HOST_INT_SCAN_COMPLETE
);
2507 /* These we just log, but either they happen rarely
2508 * or we keep them masked out */
2509 if (irqtype
& (0 | HOST_INT_RX_DATA
2510 /* | HOST_INT_TX_COMPLETE */
2512 /* | HOST_INT_RX_COMPLETE */
2516 | HOST_INT_KEY_NOT_FOUND
2517 | HOST_INT_IV_ICV_FAILURE
2518 /* | HOST_INT_CMD_COMPLETE */
2519 /* | HOST_INT_INFO */
2520 | HOST_INT_OVERFLOW
| HOST_INT_PROCESS_ERROR
2521 /* | HOST_INT_SCAN_COMPLETE */
2522 | HOST_INT_FCS_THRESHOLD
| HOST_INT_UNKNOWN
)) {
2523 log_unusual_irq(irqtype
);
2526 unmasked
= read_reg16(adev
, IO_ACX_IRQ_STATUS_CLEAR
);
2527 irqtype
= unmasked
& ~adev
->irq_mask
;
2528 /* Bail out if no new IRQ bits or if all are masked out */
2533 (++adev
->irq_loops_this_jiffy
> MAX_IRQLOOPS_PER_JIFFY
)) {
2535 "acx: too many interrupts per jiffy!\n");
2536 /* Looks like card floods us with IRQs! Try to stop that */
2537 write_reg16(adev
, IO_ACX_IRQ_MASK
, 0xffff);
2538 /* This will short-circuit all future attempts to handle IRQ.
2539 * We cant do much more... */
2545 /* Routine to perform blink with range
2546 * FIXME: update_link_quality_led is a stub - add proper code and enable this again:
2547 if (unlikely(adev->led_power == 2))
2548 update_link_quality_led(adev);
2551 /* write_flush(adev); - not needed, last op was read anyway */
2552 acx_sem_unlock(adev
);
2555 if (adev
->after_interrupt_jobs
)
2556 acx_e_after_interrupt_task(&adev
->after_interrupt_task
);
2564 static irqreturn_t
acxpci_i_interrupt(int irq
, void *dev_id
)
2566 acx_device_t
*adev
= dev_id
;
2567 unsigned long flags
;
2568 register u16 irqtype
;
2576 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2579 acx_lock(adev
, flags
);
2581 unmasked
= read_reg16(adev
, IO_ACX_IRQ_STATUS_CLEAR
);
2582 if (unlikely(0xffff == unmasked
)) {
2583 /* 0xffff value hints at missing hardware,
2584 * so don't do anything.
2585 * Not very clean, but other drivers do the same... */
2586 log(L_IRQ
, "IRQ type:FFFF - device removed? IRQ_NONE\n");
2590 /* We will check only "interesting" IRQ types */
2591 irqtype
= unmasked
& ~adev
->irq_mask
;
2593 /* We are on a shared IRQ line and it wasn't our IRQ */
2595 "IRQ type:%04X, mask:%04X - all are masked, IRQ_NONE\n",
2596 unmasked
, adev
->irq_mask
);
2600 /* Go ahead and ACK our interrupt */
2601 write_reg16(adev
, IO_ACX_IRQ_ACK
, 0xffff);
2602 if (irqtype
& HOST_INT_CMD_COMPLETE
) {
2603 log(L_IRQ
, "got Command_Complete IRQ\n");
2604 /* save the state for the running issue_cmd() */
2605 SET_BIT(adev
->irq_status
, HOST_INT_CMD_COMPLETE
);
2608 /* Only accept IRQs, if we are initialized properly.
2609 * This avoids an RX race while initializing.
2610 * We should probably not enable IRQs before we are initialized
2611 * completely, but some careful work is needed to fix this. I think it
2612 * is best to stay with this cheap workaround for now... .
2614 if (likely(adev
->initialized
)) {
2615 /* disable all IRQs. They are enabled again in the bottom half. */
2616 /* save the reason code and call our bottom half. */
2617 adev
->irq_reason
= irqtype
;
2619 if ((irqtype
& HOST_INT_RX_COMPLETE
) || (irqtype
& HOST_INT_TX_COMPLETE
))
2620 acx_schedule_task(adev
, 0);
2623 acx_unlock(adev
, flags
);
2627 acx_unlock(adev
, flags
);
2634 /***********************************************************************
2635 ** acxpci_l_power_led
2637 void acxpci_l_power_led(acx_device_t
* adev
, int enable
)
2639 u16 gpio_pled
= IS_ACX111(adev
) ? 0x0040 : 0x0800;
2641 /* A hack. Not moving message rate limiting to adev->xxx
2642 * (it's only a debug message after all) */
2643 static int rate_limit
= 0;
2645 if (rate_limit
++ < 3)
2646 log(L_IOCTL
, "Please report in case toggling the power "
2647 "LED doesn't work for your card!\n");
2649 write_reg16(adev
, IO_ACX_GPIO_OUT
,
2650 read_reg16(adev
, IO_ACX_GPIO_OUT
) & ~gpio_pled
);
2652 write_reg16(adev
, IO_ACX_GPIO_OUT
,
2653 read_reg16(adev
, IO_ACX_GPIO_OUT
) | gpio_pled
);
2657 /***********************************************************************
2661 /***********************************************************************
2665 acx111pci_ioctl_info(struct net_device
*ndev
,
2666 struct iw_request_info
*info
,
2667 struct iw_param
*vwrq
, char *extra
)
2670 acx_device_t
*adev
= ndev2adev(ndev
);
2673 rxhostdesc_t
*rxhostdesc
;
2674 txhostdesc_t
*txhostdesc
;
2675 struct acx111_ie_memoryconfig memconf
;
2676 struct acx111_ie_queueconfig queueconf
;
2677 unsigned long flags
;
2682 char ratefallback
[0x5];
2684 if (!(acx_debug
& (L_IOCTL
| L_DEBUG
)))
2686 /* using printk() since we checked debug flag already */
2690 if (!IS_ACX111(adev
)) {
2691 printk("acx111-specific function called "
2692 "with non-acx111 chip, aborting\n");
2696 /* get Acx111 Memory Configuration */
2697 memset(&memconf
, 0, sizeof(memconf
));
2698 /* BTW, fails with 12 (Write only) error code.
2699 ** Retained for easy testing of issue_cmd error handling :) */
2700 acx_s_interrogate(adev
, &memconf
, ACX1xx_IE_QUEUE_CONFIG
);
2702 /* get Acx111 Queue Configuration */
2703 memset(&queueconf
, 0, sizeof(queueconf
));
2704 acx_s_interrogate(adev
, &queueconf
, ACX1xx_IE_MEMORY_CONFIG_OPTIONS
);
2706 /* get Acx111 Memory Map */
2707 memset(memmap
, 0, sizeof(memmap
));
2708 acx_s_interrogate(adev
, &memmap
, ACX1xx_IE_MEMORY_MAP
);
2710 /* get Acx111 Rx Config */
2711 memset(rxconfig
, 0, sizeof(rxconfig
));
2712 acx_s_interrogate(adev
, &rxconfig
, ACX1xx_IE_RXCONFIG
);
2714 /* get Acx111 fcs error count */
2715 memset(fcserror
, 0, sizeof(fcserror
));
2716 acx_s_interrogate(adev
, &fcserror
, ACX1xx_IE_FCS_ERROR_COUNT
);
2718 /* get Acx111 rate fallback */
2719 memset(ratefallback
, 0, sizeof(ratefallback
));
2720 acx_s_interrogate(adev
, &ratefallback
, ACX1xx_IE_RATE_FALLBACK
);
2722 /* force occurrence of a beacon interrupt */
2723 /* TODO: comment why is this necessary */
2724 write_reg16(adev
, IO_ACX_HINT_TRIG
, HOST_INT_BEACON
);
2726 /* dump Acx111 Mem Configuration */
2727 printk("dump mem config:\n"
2728 "data read: %d, struct size: %d\n"
2729 "Number of stations: %1X\n"
2730 "Memory block size: %1X\n"
2731 "tx/rx memory block allocation: %1X\n"
2732 "count rx: %X / tx: %X queues\n"
2734 "fragmentation %1X\n"
2735 "Rx Queue 1 Count Descriptors: %X\n"
2736 "Rx Queue 1 Host Memory Start: %X\n"
2737 "Tx Queue 1 Count Descriptors: %X\n"
2738 "Tx Queue 1 Attributes: %X\n",
2739 memconf
.len
, (int)sizeof(memconf
),
2740 memconf
.no_of_stations
,
2741 memconf
.memory_block_size
,
2742 memconf
.tx_rx_memory_block_allocation
,
2743 memconf
.count_rx_queues
, memconf
.count_tx_queues
,
2745 memconf
.fragmentation
,
2746 memconf
.rx_queue1_count_descs
,
2747 acx2cpu(memconf
.rx_queue1_host_rx_start
),
2748 memconf
.tx_queue1_count_descs
, memconf
.tx_queue1_attributes
);
2750 /* dump Acx111 Queue Configuration */
2751 printk("dump queue head:\n"
2752 "data read: %d, struct size: %d\n"
2753 "tx_memory_block_address (from card): %X\n"
2754 "rx_memory_block_address (from card): %X\n"
2755 "rx1_queue address (from card): %X\n"
2756 "tx1_queue address (from card): %X\n"
2757 "tx1_queue attributes (from card): %X\n",
2758 queueconf
.len
, (int)sizeof(queueconf
),
2759 queueconf
.tx_memory_block_address
,
2760 queueconf
.rx_memory_block_address
,
2761 queueconf
.rx1_queue_address
,
2762 queueconf
.tx1_queue_address
, queueconf
.tx1_attributes
);
2764 /* dump Acx111 Mem Map */
2765 printk("dump mem map:\n"
2766 "data read: %d, struct size: %d\n"
2769 "WEP default key start: %X\n"
2770 "WEP default key end: %X\n"
2771 "STA table start: %X\n"
2772 "STA table end: %X\n"
2773 "Packet template start: %X\n"
2774 "Packet template end: %X\n"
2775 "Queue memory start: %X\n"
2776 "Queue memory end: %X\n"
2777 "Packet memory pool start: %X\n"
2778 "Packet memory pool end: %X\n"
2781 *((u16
*) & memmap
[0x02]), (int)sizeof(memmap
),
2782 *((u32
*) & memmap
[0x04]),
2783 *((u32
*) & memmap
[0x08]),
2784 *((u32
*) & memmap
[0x0C]),
2785 *((u32
*) & memmap
[0x10]),
2786 *((u32
*) & memmap
[0x14]),
2787 *((u32
*) & memmap
[0x18]),
2788 *((u32
*) & memmap
[0x1C]),
2789 *((u32
*) & memmap
[0x20]),
2790 *((u32
*) & memmap
[0x24]),
2791 *((u32
*) & memmap
[0x28]),
2792 *((u32
*) & memmap
[0x2C]),
2793 *((u32
*) & memmap
[0x30]), adev
->iobase
, adev
->iobase2
);
2795 /* dump Acx111 Rx Config */
2796 printk("dump rx config:\n"
2797 "data read: %d, struct size: %d\n"
2799 "rx filter config: %X\n",
2800 *((u16
*) & rxconfig
[0x02]), (int)sizeof(rxconfig
),
2801 *((u16
*) & rxconfig
[0x04]), *((u16
*) & rxconfig
[0x06]));
2803 /* dump Acx111 fcs error */
2804 printk("dump fcserror:\n"
2805 "data read: %d, struct size: %d\n"
2807 *((u16
*) & fcserror
[0x02]), (int)sizeof(fcserror
),
2808 *((u32
*) & fcserror
[0x04]));
2810 /* dump Acx111 rate fallback */
2811 printk("dump rate fallback:\n"
2812 "data read: %d, struct size: %d\n"
2813 "ratefallback: %X\n",
2814 *((u16
*) & ratefallback
[0x02]), (int)sizeof(ratefallback
),
2815 *((u8
*) & ratefallback
[0x04]));
2817 /* protect against IRQ */
2818 acx_lock(adev
, flags
);
2820 /* dump acx111 internal rx descriptor ring buffer */
2821 rxdesc
= adev
->rxdesc_start
;
2823 /* loop over complete receive pool */
2825 for (i
= 0; i
< RX_CNT
; i
++) {
2826 printk("\ndump internal rxdesc %d:\n"
2829 "acx mem pointer (dynamic) 0x%X\n"
2830 "CTL (dynamic) 0x%X\n"
2831 "Rate (dynamic) 0x%X\n"
2832 "RxStatus (dynamic) 0x%X\n"
2833 "Mod/Pre (dynamic) 0x%X\n",
2836 acx2cpu(rxdesc
->pNextDesc
),
2837 acx2cpu(rxdesc
->ACXMemPtr
),
2839 rxdesc
->rate
, rxdesc
->error
, rxdesc
->SNR
);
2843 /* dump host rx descriptor ring buffer */
2845 rxhostdesc
= adev
->rxhostdesc_start
;
2847 /* loop over complete receive pool */
2849 for (i
= 0; i
< RX_CNT
; i
++) {
2850 printk("\ndump host rxdesc %d:\n"
2852 "buffer mem pos 0x%X\n"
2853 "buffer mem offset 0x%X\n"
2860 acx2cpu(rxhostdesc
->data_phy
),
2861 rxhostdesc
->data_offset
,
2862 le16_to_cpu(rxhostdesc
->Ctl_16
),
2863 le16_to_cpu(rxhostdesc
->length
),
2864 acx2cpu(rxhostdesc
->desc_phy_next
),
2865 rxhostdesc
->Status
);
2869 /* dump acx111 internal tx descriptor ring buffer */
2870 txdesc
= adev
->txdesc_start
;
2872 /* loop over complete transmit pool */
2874 for (i
= 0; i
< TX_CNT
; i
++) {
2875 printk("\ndump internal txdesc %d:\n"
2879 "acx mem pointer (dynamic) 0x%X\n"
2880 "host mem pointer (dynamic) 0x%X\n"
2881 "length (dynamic) 0x%X\n"
2882 "CTL (dynamic) 0x%X\n"
2883 "CTL2 (dynamic) 0x%X\n"
2884 "Status (dynamic) 0x%X\n"
2885 "Rate (dynamic) 0x%X\n",
2887 (int)sizeof(struct txdesc
),
2889 acx2cpu(txdesc
->pNextDesc
),
2890 acx2cpu(txdesc
->AcxMemPtr
),
2891 acx2cpu(txdesc
->HostMemPtr
),
2892 le16_to_cpu(txdesc
->total_length
),
2894 txdesc
->Ctl2_8
, txdesc
->error
,
2896 txdesc
= advance_txdesc(adev
, txdesc
, 1);
2899 /* dump host tx descriptor ring buffer */
2901 txhostdesc
= adev
->txhostdesc_start
;
2903 /* loop over complete host send pool */
2905 for (i
= 0; i
< TX_CNT
* 2; i
++) {
2906 printk("\ndump host txdesc %d:\n"
2908 "buffer mem pos 0x%X\n"
2909 "buffer mem offset 0x%X\n"
2916 acx2cpu(txhostdesc
->data_phy
),
2917 txhostdesc
->data_offset
,
2918 le16_to_cpu(txhostdesc
->Ctl_16
),
2919 le16_to_cpu(txhostdesc
->length
),
2920 acx2cpu(txhostdesc
->desc_phy_next
),
2921 le32_to_cpu(txhostdesc
->Status
));
2925 /* write_reg16(adev, 0xb4, 0x4); */
2927 acx_unlock(adev
, flags
);
2930 acx_sem_unlock(adev
);
2931 #endif /* ACX_DEBUG */
2936 /***********************************************************************
2939 acx100pci_ioctl_set_phy_amp_bias(struct net_device
*ndev
,
2940 struct iw_request_info
*info
,
2941 struct iw_param
*vwrq
, char *extra
)
2943 acx_device_t
*adev
= ndev2adev(ndev
);
2944 unsigned long flags
;
2947 if (!IS_ACX100(adev
)) {
2949 * Removing this check *might* damage
2950 * hardware, since we're tweaking GPIOs here after all!!!
2951 * You've been warned...
2953 printk("acx: sorry, setting bias level for non-acx100 "
2954 "is not supported yet\n");
2959 printk("acx: invalid bias parameter, range is 0-7\n");
2965 /* Need to lock accesses to [IO_ACX_GPIO_OUT]:
2966 * IRQ handler uses it to update LED */
2967 acx_lock(adev
, flags
);
2968 gpio_old
= read_reg16(adev
, IO_ACX_GPIO_OUT
);
2969 write_reg16(adev
, IO_ACX_GPIO_OUT
,
2970 (gpio_old
& 0xf8ff) | ((u16
) * extra
<< 8));
2971 acx_unlock(adev
, flags
);
2973 log(L_DEBUG
, "gpio_old: 0x%04X\n", gpio_old
);
2974 printk("%s: PHY power amplifier bias: old:%d, new:%d\n",
2975 ndev
->name
, (gpio_old
& 0x0700) >> 8, (unsigned char)*extra
);
2977 acx_sem_unlock(adev
);
2983 /***************************************************************
2984 ** acxpci_l_alloc_tx
2985 ** Actually returns a txdesc_t* ptr
2987 ** FIXME: in case of fragments, should allocate multiple descrs
2988 ** after figuring out how many we need and whether we still have
2989 ** sufficiently many.
2991 tx_t
*acxpci_l_alloc_tx(acx_device_t
* adev
)
2993 struct txdesc
*txdesc
;
2999 if (unlikely(!adev
->tx_free
)) {
3000 printk("acx: BUG: no free txdesc left\n");
3005 head
= adev
->tx_head
;
3006 txdesc
= get_txdesc(adev
, head
);
3007 ctl8
= txdesc
->Ctl_8
;
3009 /* 2005-10-11: there were several bug reports on this happening
3010 ** but now cause seems to be understood & fixed */
3011 if (unlikely(DESC_CTL_HOSTOWN
!= (ctl8
& DESC_CTL_ACXDONE_HOSTOWN
))) {
3012 /* whoops, descr at current index is not free, so probably
3013 * ring buffer already full */
3014 printk("acx: BUG: tx_head:%d Ctl8:0x%02X - failed to find "
3015 "free txdesc\n", head
, ctl8
);
3020 /* Needed in case txdesc won't be eventually submitted for tx */
3021 txdesc
->Ctl_8
= DESC_CTL_ACXDONE_HOSTOWN
;
3024 log(L_BUFT
, "tx: got desc %u, %u remain\n", head
, adev
->tx_free
);
3025 /* Keep a few free descs between head and tail of tx ring.
3026 ** It is not absolutely needed, just feels safer */
3027 if (adev
->tx_free
< TX_STOP_QUEUE
) {
3028 log(L_BUF
, "stop queue (%u tx desc left)\n", adev
->tx_free
);
3029 acx_stop_queue(adev
->ieee
, NULL
);
3032 /* returning current descriptor, so advance to next free one */
3033 adev
->tx_head
= (head
+ 1) % TX_CNT
;
3037 return (tx_t
*) txdesc
;
3041 /***********************************************************************
3043 void *acxpci_l_get_txbuf(acx_device_t
* adev
, tx_t
* tx_opaque
)
3045 return get_txhostdesc(adev
, (txdesc_t
*) tx_opaque
)->data
;
3049 /***********************************************************************
3052 ** Can be called from IRQ (rx -> (AP bridging or mgmt response) -> tx).
3053 ** Can be called from acx_i_start_xmit (data frames from net core).
3055 ** FIXME: in case of fragments, should loop over the number of
3056 ** pre-allocated tx descrs, properly setting up transfer data and
3057 ** CTL_xxx flags according to fragment number.
3060 acxpci_l_tx_data(acx_device_t
* adev
, tx_t
* tx_opaque
, int len
,
3061 struct ieee80211_tx_control
*ieeectl
,struct sk_buff
* skb
)
3063 txdesc_t
*txdesc
= (txdesc_t
*) tx_opaque
;
3064 struct ieee80211_hdr
*wireless_header
;
3065 txhostdesc_t
*hostdesc1
, *hostdesc2
;
3072 /* fw doesn't tx such packets anyhow */
3073 /* if (unlikely(len < WLAN_HDR_A3_LEN))
3076 hostdesc1
= get_txhostdesc(adev
, txdesc
);
3077 wireless_header
= (struct ieee80211_hdr
*)hostdesc1
->data
;
3078 /* modify flag status in separate variable to be able to write it back
3079 * in one big swoop later (also in order to have less device memory
3081 Ctl_8
= txdesc
->Ctl_8
;
3082 Ctl2_8
= 0; /* really need to init it to 0, not txdesc->Ctl2_8, it seems */
3084 hostdesc2
= hostdesc1
+ 1;
3086 /* DON'T simply set Ctl field to 0 here globally,
3087 * it needs to maintain a consistent flag status (those are state flags!!),
3088 * otherwise it may lead to severe disruption. Only set or reset particular
3089 * flags at the exact moment this is needed... */
3091 /* let chip do RTS/CTS handshaking before sending
3092 * in case packet size exceeds threshold */
3093 if (ieeectl
->flags
& IEEE80211_TXCTL_USE_RTS_CTS
)
3094 SET_BIT(Ctl2_8
, DESC_CTL2_RTS
);
3096 CLEAR_BIT(Ctl2_8
, DESC_CTL2_RTS
);
3098 rate_cur
= ieeectl
->tx_rate
;
3099 if (unlikely(!rate_cur
)) {
3100 printk("acx: driver bug! bad ratemask\n");
3104 /* used in tx cleanup routine for auto rate and accounting: */
3105 /* put_txcr(adev, txdesc, clt, rate_cur); deprecated by mac80211 */
3107 txdesc
->total_length
= cpu_to_le16(len
);
3108 wlhdr_len
= ieee80211_get_hdrlen(le16_to_cpu(wireless_header
->frame_control
));
3109 hostdesc2
->length
= cpu_to_le16(len
- wlhdr_len
);
3111 if (!ieeectl->do_not_encrypt && ieeectl->key_idx>= 0)
3113 u16 key_idx = (u16)(ieeectl->key_idx);
3114 struct acx_key* key = &(adev->key[key_idx]);
3118 memcpy(ieeehdr->wep_iv, ((u8*)wireless_header) + wlhdr_len, 4);
3122 if (IS_ACX111(adev
)) {
3123 /* note that if !txdesc->do_auto, txrate->cur
3124 ** has only one nonzero bit */
3125 txdesc
->u
.r2
.rate111
= cpu_to_le16(rate_cur
3126 /* WARNING: I was never able to make it work with prism54 AP.
3127 ** It was falling down to 1Mbit where shortpre is not applicable,
3128 ** and not working at all at "5,11 basic rates only" setting.
3129 ** I even didn't see tx packets in radio packet capture.
3130 ** Disabled for now --vda */
3131 /*| ((clt->shortpre && clt->cur!=RATE111_1) ? RATE111_SHORTPRE : 0) */
3133 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3134 /* should add this to rate111 above as necessary */
3135 |(clt
->pbcc511
? RATE111_PBCC511
: 0)
3137 hostdesc1
->length
= cpu_to_le16(len
);
3138 } else { /* ACX100 */
3139 u8 rate_100
= ieeectl
->tx_rate
;
3140 txdesc
->u
.r1
.rate
= rate_100
;
3141 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3143 if (n
== RATE100_5
|| n
== RATE100_11
)
3144 n
|= RATE100_PBCC511
;
3147 if (clt
->shortpre
&& (clt
->cur
!= RATE111_1
))
3148 SET_BIT(Ctl_8
, DESC_CTL_SHORT_PREAMBLE
); /* set Short Preamble */
3150 /* set autodma and reclaim and 1st mpdu */
3152 DESC_CTL_AUTODMA
| DESC_CTL_RECLAIM
|
3153 DESC_CTL_FIRSTFRAG
);
3154 #if ACX_FRAGMENTATION
3155 /* SET_BIT(Ctl2_8, DESC_CTL2_MORE_FRAG); cannot set it unconditionally, needs to be set for all non-last fragments */
3157 hostdesc1
->length
= cpu_to_le16(wlhdr_len
);
3159 /* don't need to clean ack/rts statistics here, already
3160 * done on descr cleanup */
3162 /* clears HOSTOWN and ACXDONE bits, thus telling that the descriptors
3163 * are now owned by the acx100; do this as LAST operation */
3164 CLEAR_BIT(Ctl_8
, DESC_CTL_ACXDONE_HOSTOWN
);
3165 /* flush writes before we release hostdesc to the adapter here */
3167 CLEAR_BIT(hostdesc1
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
3168 CLEAR_BIT(hostdesc2
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
3170 /* write back modified flags */
3171 CLEAR_BIT(Ctl2_8
, DESC_CTL2_WEP
);
3172 txdesc
->Ctl2_8
= Ctl2_8
;
3173 txdesc
->Ctl_8
= Ctl_8
;
3174 /* unused: txdesc->tx_time = cpu_to_le32(jiffies); */
3176 /* flush writes before we tell the adapter that it's its turn now */
3177 write_reg16(adev
, IO_ACX_INT_TRIG
, INT_TRIG_TXPRC
);
3179 /* log the packet content AFTER sending it,
3180 * in order to not delay sending any further than absolutely needed
3181 * Do separate logs for acx100/111 to have human-readable rates */
3182 memcpy(&(hostdesc1
->txstatus
.control
),ieeectl
,sizeof(struct ieee80211_tx_control
));
3183 hostdesc1
->skb
= skb
;
3189 /***********************************************************************
3190 ** acxpci_l_clean_txdesc
3192 ** This function resets the txdescs' status when the ACX100
3193 ** signals the TX done IRQ (txdescs have been processed), starting with
3194 ** the pool index of the descriptor which we would use next,
3195 ** in order to make sure that we can be as fast as possible
3196 ** in filling new txdescs.
3197 ** Everytime we get called we know where the next packet to be cleaned is.
3201 static inline void log_txbuffer(const acx_device_t
* adev
)
3205 static void log_txbuffer(acx_device_t
* adev
)
3210 /* no FN_ENTER here, we don't want that */
3211 /* no locks here, since it's entirely non-critical code */
3212 txdesc
= adev
->txdesc_start
;
3213 if (unlikely(!txdesc
))
3215 printk("tx: desc->Ctl8's:");
3216 for (i
= 0; i
< TX_CNT
; i
++) {
3217 printk(" %02X", txdesc
->Ctl_8
);
3218 txdesc
= advance_txdesc(adev
, txdesc
, 1);
3225 static void handle_tx_error(acx_device_t
* adev
, u8 error
, unsigned int finger
,
3226 struct ieee80211_tx_status
*status
)
3228 const char *err
= "unknown error";
3230 /* hmm, should we handle this as a mask
3231 * of *several* bits?
3232 * For now I think only caring about
3233 * individual bits is ok... */
3236 err
= "no Tx due to error in other fragment";
3237 /* adev->wstats.discard.fragment++; */
3241 adev
->stats
.tx_aborted_errors
++;
3244 err
= "Tx desc wrong parameters";
3245 /* adev->wstats.discard.misc++; */
3248 err
= "WEP key not found";
3249 /* adev->wstats.discard.misc++; */
3252 err
= "MSDU lifetime timeout? - try changing "
3253 "'iwconfig retry lifetime XXX'";
3254 /* adev->wstats.discard.misc++; */
3257 err
= "excessive Tx retries due to either distance "
3258 "too high or unable to Tx or Tx frame error - "
3259 "try changing 'iwconfig txpower XXX' or "
3260 "'sens'itivity or 'retry'";
3261 /* adev->wstats.discard.retries++; */
3262 /* Tx error 0x20 also seems to occur on
3263 * overheating, so I'm not sure whether we
3264 * actually want to do aggressive radio recalibration,
3265 * since people maybe won't notice then that their hardware
3266 * is slowly getting cooked...
3267 * Or is it still a safe long distance from utter
3268 * radio non-functionality despite many radio recalibs
3269 * to final destructive overheating of the hardware?
3270 * In this case we really should do recalib here...
3271 * I guess the only way to find out is to do a
3272 * potentially fatal self-experiment :-\
3273 * Or maybe only recalib in case we're using Tx
3274 * rate auto (on errors switching to lower speed
3275 * --> less heat?) or 802.11 power save mode?
3277 * ok, just do it. */
3278 if (++adev
->retry_errors_msg_ratelimit
% 4 == 0) {
3279 if (adev
->retry_errors_msg_ratelimit
<= 20) {
3280 printk("%s: several excessive Tx "
3281 "retry errors occurred, attempting "
3282 "to recalibrate radio. Radio "
3283 "drift might be caused by increasing "
3284 "card temperature, please check the card "
3285 "before it's too late!\n",
3286 wiphy_name(adev
->ieee
->wiphy
));
3287 if (adev
->retry_errors_msg_ratelimit
== 20)
3288 printk("disabling above message\n");
3291 acx_schedule_task(adev
,
3292 ACX_AFTER_IRQ_CMD_RADIO_RECALIB
);
3294 status
->excessive_retries
++;
3297 err
= "Tx buffer overflow";
3298 adev
->stats
.tx_fifo_errors
++;
3301 /* possibly ACPI C-state powersaving related!!!
3302 * (DMA timeout due to excessively high wakeup
3303 * latency after C-state activation!?)
3304 * Disable C-State powersaving and try again,
3305 * then PLEASE REPORT, I'm VERY interested in
3306 * whether my theory is correct that this is
3307 * actually the problem here.
3308 * In that case, use new Linux idle wakeup latency
3309 * requirements kernel API to prevent this issue. */
3311 /* adev->wstats.discard.misc++; */
3314 adev
->stats
.tx_errors
++;
3315 if (adev
->stats
.tx_errors
<= 20)
3316 printk("%s: tx error 0x%02X, buf %02u! (%s)\n",
3317 wiphy_name(adev
->ieee
->wiphy
), error
, finger
, err
);
3319 printk("%s: tx error 0x%02X, buf %02u!\n",
3320 wiphy_name(adev
->ieee
->wiphy
), error
, finger
);
3324 unsigned int acxpci_l_clean_txdesc(acx_device_t
* adev
)
3327 txhostdesc_t
*hostdesc
;
3331 u8 error
, ack_failures
, rts_failures
, rts_ok
, r100
;
3335 if (unlikely(acx_debug
& L_DEBUG
))
3338 log(L_BUFT
, "tx: cleaning up bufs from %u\n", adev
->tx_tail
);
3340 /* We know first descr which is not free yet. We advance it as far
3341 ** as we see correct bits set in following descs (if next desc
3342 ** is NOT free, we shouldn't advance at all). We know that in
3343 ** front of tx_tail may be "holes" with isolated free descs.
3344 ** We will catch up when all intermediate descs will be freed also */
3346 finger
= adev
->tx_tail
;
3348 while (likely(finger
!= adev
->tx_head
)) {
3349 txdesc
= get_txdesc(adev
, finger
);
3351 /* If we allocated txdesc on tx path but then decided
3352 ** to NOT use it, then it will be left as a free "bubble"
3353 ** in the "allocated for tx" part of the ring.
3354 ** We may meet it on the next ring pass here. */
3356 /* stop if not marked as "tx finished" and "host owned" */
3357 if ((txdesc
->Ctl_8
& DESC_CTL_ACXDONE_HOSTOWN
)
3358 != DESC_CTL_ACXDONE_HOSTOWN
) {
3359 if (unlikely(!num_cleaned
)) { /* maybe remove completely */
3360 log(L_BUFT
, "clean_txdesc: tail isn't free. "
3361 "tail:%d head:%d\n",
3362 adev
->tx_tail
, adev
->tx_head
);
3367 /* remember desc values... */
3368 error
= txdesc
->error
;
3369 ack_failures
= txdesc
->ack_failures
;
3370 rts_failures
= txdesc
->rts_failures
;
3371 rts_ok
= txdesc
->rts_ok
;
3372 r100
= txdesc
->u
.r1
.rate
;
3373 r111
= le16_to_cpu(txdesc
->u
.r2
.rate111
);
3375 /* need to check for certain error conditions before we
3376 * clean the descriptor: we still need valid descr data here */
3377 hostdesc
= get_txhostdesc(adev
, txdesc
);
3379 hostdesc
->txstatus
.flags
|= IEEE80211_TX_STATUS_ACK
;
3380 if (unlikely(0x30 & error
)) {
3381 /* only send IWEVTXDROP in case of retry or lifetime exceeded;
3382 * all other errors mean we screwed up locally */
3383 /* union iwreq_data wrqu;
3384 struct ieee80211_hdr_3addr *hdr;
3385 hdr = (struct ieee80211_hdr_3addr *) hostdesc->data;
3386 MAC_COPY(wrqu.addr.sa_data, hdr->addr1);
3388 hostdesc
->txstatus
.flags
&= ~IEEE80211_TX_STATUS_ACK
;
3391 /* ...and free the desc */
3393 txdesc
->ack_failures
= 0;
3394 txdesc
->rts_failures
= 0;
3396 /* signal host owning it LAST, since ACX already knows that this
3397 ** descriptor is finished since it set Ctl_8 accordingly. */
3398 txdesc
->Ctl_8
= DESC_CTL_HOSTOWN
;
3403 if ((adev
->tx_free
>= TX_START_QUEUE
)
3404 /* && (adev->status == ACX_STATUS_4_ASSOCIATED) */
3405 /*&& (acx_queue_stopped(adev->ieee))*/
3407 log(L_BUF
, "tx: wake queue (avail. Tx desc %u)\n",
3409 acx_wake_queue(adev
->ieee
, NULL
);
3412 /* do error checking, rate handling and logging
3413 * AFTER having done the work, it's faster */
3415 /* Rate handling is done in mac80211 */
3416 /* if (adev->rate_auto) {
3417 struct client *clt = get_txc(adev, txdesc);
3419 u16 cur = get_txr(adev, txdesc);
3420 if (clt->rate_cur == cur) {
3421 acx_l_handle_txrate_auto(adev, clt, cur,*/ /* intended rate */
3422 /*r100, r111,*/ /* actually used rate */
3423 /*(error & 0x30),*/ /* was there an error? */
3432 if (unlikely(error
))
3433 handle_tx_error(adev
, error
, finger
, &hostdesc
->txstatus
);
3435 if (IS_ACX111(adev
))
3437 "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u r111=%04X tx_free=%u\n",
3438 finger
, ack_failures
, rts_failures
, rts_ok
, r111
, adev
->tx_free
);
3441 "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u rate=%u\n",
3442 finger
, ack_failures
, rts_failures
, rts_ok
, r100
);
3444 /* And finally report upstream */
3447 hostdesc
->txstatus
.excessive_retries
= rts_failures
;
3448 hostdesc
->txstatus
.retry_count
= ack_failures
;
3449 ieee80211_tx_status(adev
->ieee
,hostdesc
->skb
,&hostdesc
->txstatus
);
3450 memset(&hostdesc
->txstatus
, 0, sizeof(struct ieee80211_tx_status
));
3452 /* update pointer for descr to be cleaned next */
3453 finger
= (finger
+ 1) % TX_CNT
;
3455 /* remember last position */
3456 adev
->tx_tail
= finger
;
3458 FN_EXIT1(num_cleaned
);
3462 /* clean *all* Tx descriptors, and regardless of their previous state.
3463 * Used for brute-force reset handling. */
3464 void acxpci_l_clean_txdesc_emergency(acx_device_t
* adev
)
3471 for (i
= 0; i
< TX_CNT
; i
++) {
3472 txdesc
= get_txdesc(adev
, i
);
3475 txdesc
->ack_failures
= 0;
3476 txdesc
->rts_failures
= 0;
3479 txdesc
->Ctl_8
= DESC_CTL_HOSTOWN
;
3482 adev
->tx_free
= TX_CNT
;
3488 /***********************************************************************
3489 ** acxpci_s_create_tx_host_desc_queue
3492 static void *allocate(acx_device_t
* adev
, size_t size
, dma_addr_t
* phy
,
3497 ptr
= dma_alloc_coherent(adev
->bus_dev
, size
, phy
, GFP_KERNEL
);
3500 log(L_DEBUG
, "%s sz=%d adr=0x%p phy=0x%08llx\n",
3501 msg
, (int)size
, ptr
, (unsigned long long)*phy
);
3502 memset(ptr
, 0, size
);
3505 printk(KERN_ERR
"acx: %s allocation FAILED (%d bytes)\n",
3511 static int acxpci_s_create_tx_host_desc_queue(acx_device_t
* adev
)
3513 txhostdesc_t
*hostdesc
;
3515 dma_addr_t hostdesc_phy
;
3516 dma_addr_t txbuf_phy
;
3521 /* allocate TX buffer */
3522 adev
->txbuf_area_size
= TX_CNT
* /*WLAN_A4FR_MAXLEN_WEP_FCS*/ (30 + 2312 + 4);
3523 adev
->txbuf_start
= allocate(adev
, adev
->txbuf_area_size
,
3524 &adev
->txbuf_startphy
, "txbuf_start");
3525 if (!adev
->txbuf_start
)
3528 /* allocate the TX host descriptor queue pool */
3529 adev
->txhostdesc_area_size
= TX_CNT
* 2 * sizeof(*hostdesc
);
3530 adev
->txhostdesc_start
= allocate(adev
, adev
->txhostdesc_area_size
,
3531 &adev
->txhostdesc_startphy
,
3532 "txhostdesc_start");
3533 if (!adev
->txhostdesc_start
)
3535 /* check for proper alignment of TX host descriptor pool */
3536 if ((long)adev
->txhostdesc_start
& 3) {
3538 ("acx: driver bug: dma alloc returns unaligned address\n");
3542 hostdesc
= adev
->txhostdesc_start
;
3543 hostdesc_phy
= adev
->txhostdesc_startphy
;
3544 txbuf
= adev
->txbuf_start
;
3545 txbuf_phy
= adev
->txbuf_startphy
;
3548 /* Each tx buffer is accessed by hardware via
3549 ** txdesc -> txhostdesc(s) -> txbuffer(s).
3550 ** We use only one txhostdesc per txdesc, but it looks like
3551 ** acx111 is buggy: it accesses second txhostdesc
3552 ** (via hostdesc.desc_phy_next field) even if
3553 ** txdesc->length == hostdesc->length and thus
3554 ** entire packet was placed into first txhostdesc.
3555 ** Due to this bug acx111 hangs unless second txhostdesc
3556 ** has le16_to_cpu(hostdesc.length) = 3 (or larger)
3557 ** Storing NULL into hostdesc.desc_phy_next
3558 ** doesn't seem to help.
3560 ** Update: although it worked on Xterasys XN-2522g
3561 ** with len=3 trick, WG311v2 is even more bogus, doesn't work.
3562 ** Keeping this code (#ifdef'ed out) for documentational purposes.
3564 for (i
= 0; i
< TX_CNT
* 2; i
++) {
3565 hostdesc_phy
+= sizeof(*hostdesc
);
3567 hostdesc
->data_phy
= cpu2acx(txbuf_phy
);
3568 /* hostdesc->data_offset = ... */
3569 /* hostdesc->reserved = ... */
3570 hostdesc
->Ctl_16
= cpu_to_le16(DESC_CTL_HOSTOWN
);
3571 /* hostdesc->length = ... */
3572 hostdesc
->desc_phy_next
= cpu2acx(hostdesc_phy
);
3573 hostdesc
->pNext
= ptr2acx(NULL
);
3574 /* hostdesc->Status = ... */
3575 /* below: non-hardware fields */
3576 hostdesc
->data
= txbuf
;
3578 txbuf
+= WLAN_A4FR_MAXLEN_WEP_FCS
;
3579 txbuf_phy
+= WLAN_A4FR_MAXLEN_WEP_FCS
;
3581 /* hostdesc->data_phy = ... */
3582 /* hostdesc->data_offset = ... */
3583 /* hostdesc->reserved = ... */
3584 /* hostdesc->Ctl_16 = ... */
3585 hostdesc
->length
= cpu_to_le16(3); /* bug workaround */
3586 /* hostdesc->desc_phy_next = ... */
3587 /* hostdesc->pNext = ... */
3588 /* hostdesc->Status = ... */
3589 /* below: non-hardware fields */
3590 /* hostdesc->data = ... */
3595 /* We initialize two hostdescs so that they point to adjacent
3596 ** memory areas. Thus txbuf is really just a contiguous memory area */
3597 for (i
= 0; i
< TX_CNT
* 2; i
++) {
3598 hostdesc_phy
+= sizeof(*hostdesc
);
3600 hostdesc
->data_phy
= cpu2acx(txbuf_phy
);
3601 /* done by memset(0): hostdesc->data_offset = 0; */
3602 /* hostdesc->reserved = ... */
3603 hostdesc
->Ctl_16
= cpu_to_le16(DESC_CTL_HOSTOWN
);
3604 /* hostdesc->length = ... */
3605 hostdesc
->desc_phy_next
= cpu2acx(hostdesc_phy
);
3606 /* done by memset(0): hostdesc->pNext = ptr2acx(NULL); */
3607 /* hostdesc->Status = ... */
3608 /* ->data is a non-hardware field: */
3609 hostdesc
->data
= txbuf
;
3612 txbuf
+= 24 /*WLAN_HDR_A3_LEN*/;
3613 txbuf_phy
+= 24 /*WLAN_HDR_A3_LEN*/;
3615 txbuf
+= 30 + 2132 + 4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3616 txbuf_phy
+= 30 + 2132 +4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3621 hostdesc
->desc_phy_next
= cpu2acx(adev
->txhostdesc_startphy
);
3626 printk("acx: create_tx_host_desc_queue FAILED\n");
3627 /* dealloc will be done by free function on error case */
3633 /***************************************************************
3634 ** acxpci_s_create_rx_host_desc_queue
3636 /* the whole size of a data buffer (header plus data body)
3637 * plus 32 bytes safety offset at the end */
3638 #define RX_BUFFER_SIZE (sizeof(rxbuffer_t) + 32)
3640 static int acxpci_s_create_rx_host_desc_queue(acx_device_t
* adev
)
3642 rxhostdesc_t
*hostdesc
;
3644 dma_addr_t hostdesc_phy
;
3645 dma_addr_t rxbuf_phy
;
3650 /* allocate the RX host descriptor queue pool */
3651 adev
->rxhostdesc_area_size
= RX_CNT
* sizeof(*hostdesc
);
3652 adev
->rxhostdesc_start
= allocate(adev
, adev
->rxhostdesc_area_size
,
3653 &adev
->rxhostdesc_startphy
,
3654 "rxhostdesc_start");
3655 if (!adev
->rxhostdesc_start
)
3657 /* check for proper alignment of RX host descriptor pool */
3658 if ((long)adev
->rxhostdesc_start
& 3) {
3660 ("acx: driver bug: dma alloc returns unaligned address\n");
3664 /* allocate Rx buffer pool which will be used by the acx
3665 * to store the whole content of the received frames in it */
3666 adev
->rxbuf_area_size
= RX_CNT
* RX_BUFFER_SIZE
;
3667 adev
->rxbuf_start
= allocate(adev
, adev
->rxbuf_area_size
,
3668 &adev
->rxbuf_startphy
, "rxbuf_start");
3669 if (!adev
->rxbuf_start
)
3672 rxbuf
= adev
->rxbuf_start
;
3673 rxbuf_phy
= adev
->rxbuf_startphy
;
3674 hostdesc
= adev
->rxhostdesc_start
;
3675 hostdesc_phy
= adev
->rxhostdesc_startphy
;
3677 /* don't make any popular C programming pointer arithmetic mistakes
3678 * here, otherwise I'll kill you...
3679 * (and don't dare asking me why I'm warning you about that...) */
3680 for (i
= 0; i
< RX_CNT
; i
++) {
3681 hostdesc
->data
= rxbuf
;
3682 hostdesc
->data_phy
= cpu2acx(rxbuf_phy
);
3683 hostdesc
->length
= cpu_to_le16(RX_BUFFER_SIZE
);
3684 CLEAR_BIT(hostdesc
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
3686 rxbuf_phy
+= sizeof(*rxbuf
);
3687 hostdesc_phy
+= sizeof(*hostdesc
);
3688 hostdesc
->desc_phy_next
= cpu2acx(hostdesc_phy
);
3692 hostdesc
->desc_phy_next
= cpu2acx(adev
->rxhostdesc_startphy
);
3696 printk("acx: create_rx_host_desc_queue FAILED\n");
3697 /* dealloc will be done by free function on error case */
3703 /***************************************************************
3704 ** acxpci_s_create_hostdesc_queues
3706 int acxpci_s_create_hostdesc_queues(acx_device_t
* adev
)
3709 result
= acxpci_s_create_tx_host_desc_queue(adev
);
3712 result
= acxpci_s_create_rx_host_desc_queue(adev
);
3717 /***************************************************************
3718 ** acxpci_create_tx_desc_queue
3720 static void acxpci_create_tx_desc_queue(acx_device_t
* adev
, u32 tx_queue_start
)
3723 txhostdesc_t
*hostdesc
;
3724 dma_addr_t hostmemptr
;
3730 if (IS_ACX100(adev
))
3731 adev
->txdesc_size
= sizeof(*txdesc
);
3733 /* the acx111 txdesc is 4 bytes larger */
3734 adev
->txdesc_size
= sizeof(*txdesc
) + 4;
3736 adev
->txdesc_start
= (txdesc_t
*) (adev
->iobase2
+ tx_queue_start
);
3738 log(L_DEBUG
, "adev->iobase2=%p\n"
3739 "tx_queue_start=%08X\n"
3740 "adev->txdesc_start=%p\n",
3741 adev
->iobase2
, tx_queue_start
, adev
->txdesc_start
);
3743 adev
->tx_free
= TX_CNT
;
3744 /* done by memset: adev->tx_head = 0; */
3745 /* done by memset: adev->tx_tail = 0; */
3746 txdesc
= adev
->txdesc_start
;
3747 mem_offs
= tx_queue_start
;
3748 hostmemptr
= adev
->txhostdesc_startphy
;
3749 hostdesc
= adev
->txhostdesc_start
;
3751 if (IS_ACX111(adev
)) {
3752 /* ACX111 has a preinitialized Tx buffer! */
3753 /* loop over whole send pool */
3754 /* FIXME: do we have to do the hostmemptr stuff here?? */
3755 for (i
= 0; i
< TX_CNT
; i
++) {
3756 txdesc
->HostMemPtr
= ptr2acx(hostmemptr
);
3757 txdesc
->Ctl_8
= DESC_CTL_HOSTOWN
;
3758 /* reserve two (hdr desc and payload desc) */
3760 hostmemptr
+= 2 * sizeof(*hostdesc
);
3761 txdesc
= advance_txdesc(adev
, txdesc
, 1);
3764 /* ACX100 Tx buffer needs to be initialized by us */
3765 /* clear whole send pool. sizeof is safe here (we are acx100) */
3766 memset(adev
->txdesc_start
, 0, TX_CNT
* sizeof(*txdesc
));
3768 /* loop over whole send pool */
3769 for (i
= 0; i
< TX_CNT
; i
++) {
3770 log(L_DEBUG
, "configure card tx descriptor: 0x%p, "
3771 "size: 0x%X\n", txdesc
, adev
->txdesc_size
);
3773 /* pointer to hostdesc memory */
3774 txdesc
->HostMemPtr
= ptr2acx(hostmemptr
);
3775 /* initialise ctl */
3776 txdesc
->Ctl_8
= (DESC_CTL_HOSTOWN
| DESC_CTL_RECLAIM
3777 | DESC_CTL_AUTODMA
|
3778 DESC_CTL_FIRSTFRAG
);
3779 /* done by memset(0): txdesc->Ctl2_8 = 0; */
3780 /* point to next txdesc */
3782 cpu2acx(mem_offs
+ adev
->txdesc_size
);
3783 /* reserve two (hdr desc and payload desc) */
3785 hostmemptr
+= 2 * sizeof(*hostdesc
);
3786 /* go to the next one */
3787 mem_offs
+= adev
->txdesc_size
;
3788 /* ++ is safe here (we are acx100) */
3791 /* go back to the last one */
3793 /* and point to the first making it a ring buffer */
3794 txdesc
->pNextDesc
= cpu2acx(tx_queue_start
);
3800 /***************************************************************
3801 ** acxpci_create_rx_desc_queue
3803 static void acxpci_create_rx_desc_queue(acx_device_t
* adev
, u32 rx_queue_start
)
3811 /* done by memset: adev->rx_tail = 0; */
3813 /* ACX111 doesn't need any further config: preconfigures itself.
3814 * Simply print ring buffer for debugging */
3815 if (IS_ACX111(adev
)) {
3816 /* rxdesc_start already set here */
3818 adev
->rxdesc_start
=
3819 (rxdesc_t
*) ((u8
*) adev
->iobase2
+ rx_queue_start
);
3821 rxdesc
= adev
->rxdesc_start
;
3822 for (i
= 0; i
< RX_CNT
; i
++) {
3823 log(L_DEBUG
, "rx descriptor %d @ 0x%p\n", i
, rxdesc
);
3824 rxdesc
= adev
->rxdesc_start
= (rxdesc_t
*)
3825 (adev
->iobase2
+ acx2cpu(rxdesc
->pNextDesc
));
3828 /* we didn't pre-calculate rxdesc_start in case of ACX100 */
3829 /* rxdesc_start should be right AFTER Tx pool */
3830 adev
->rxdesc_start
= (rxdesc_t
*)
3831 ((u8
*) adev
->txdesc_start
+ (TX_CNT
* sizeof(txdesc_t
)));
3832 /* NB: sizeof(txdesc_t) above is valid because we know
3833 ** we are in if (acx100) block. Beware of cut-n-pasting elsewhere!
3834 ** acx111's txdesc is larger! */
3836 memset(adev
->rxdesc_start
, 0, RX_CNT
* sizeof(*rxdesc
));
3838 /* loop over whole receive pool */
3839 rxdesc
= adev
->rxdesc_start
;
3840 mem_offs
= rx_queue_start
;
3841 for (i
= 0; i
< RX_CNT
; i
++) {
3842 log(L_DEBUG
, "rx descriptor @ 0x%p\n", rxdesc
);
3843 rxdesc
->Ctl_8
= DESC_CTL_RECLAIM
| DESC_CTL_AUTODMA
;
3844 /* point to next rxdesc */
3845 rxdesc
->pNextDesc
= cpu2acx(mem_offs
+ sizeof(*rxdesc
));
3846 /* go to the next one */
3847 mem_offs
+= sizeof(*rxdesc
);
3850 /* go to the last one */
3853 /* and point to the first making it a ring buffer */
3854 rxdesc
->pNextDesc
= cpu2acx(rx_queue_start
);
3860 /***************************************************************
3861 ** acxpci_create_desc_queues
3864 acxpci_create_desc_queues(acx_device_t
* adev
, u32 tx_queue_start
,
3867 acxpci_create_tx_desc_queue(adev
, tx_queue_start
);
3868 acxpci_create_rx_desc_queue(adev
, rx_queue_start
);
3872 /***************************************************************
3873 ** acxpci_s_proc_diag_output
3875 char *acxpci_s_proc_diag_output(char *p
, acx_device_t
* adev
)
3877 const char *rtl
, *thd
, *ttl
;
3878 rxhostdesc_t
*rxhostdesc
;
3884 p
+= sprintf(p
, "** Rx buf **\n");
3885 rxhostdesc
= adev
->rxhostdesc_start
;
3887 for (i
= 0; i
< RX_CNT
; i
++) {
3888 rtl
= (i
== adev
->rx_tail
) ? " [tail]" : "";
3889 if ((rxhostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
3891 Status
& cpu_to_le32(DESC_STATUS_FULL
)))
3892 p
+= sprintf(p
, "%02u FULL%s\n", i
, rtl
);
3894 p
+= sprintf(p
, "%02u empty%s\n", i
, rtl
);
3897 /* p += sprintf(p, "** Tx buf (free %d, Linux netqueue %s) **\n",
3899 acx_queue_stopped(adev->ieee) ? "STOPPED" : "running");*/
3900 txdesc
= adev
->txdesc_start
;
3902 for (i
= 0; i
< TX_CNT
; i
++) {
3903 thd
= (i
== adev
->tx_head
) ? " [head]" : "";
3904 ttl
= (i
== adev
->tx_tail
) ? " [tail]" : "";
3905 if (txdesc
->Ctl_8
& DESC_CTL_ACXDONE
)
3906 p
+= sprintf(p
, "%02u free (%02X)%s%s\n", i
,
3907 txdesc
->Ctl_8
, thd
, ttl
);
3909 p
+= sprintf(p
, "%02u tx (%02X)%s%s\n", i
,
3910 txdesc
->Ctl_8
, thd
, ttl
);
3911 txdesc
= advance_txdesc(adev
, txdesc
, 1);
3916 "txbuf_start %p, txbuf_area_size %u, txbuf_startphy %08llx\n"
3917 "txdesc_size %u, txdesc_start %p\n"
3918 "txhostdesc_start %p, txhostdesc_area_size %u, txhostdesc_startphy %08llx\n"
3920 "rxhostdesc_start %p, rxhostdesc_area_size %u, rxhostdesc_startphy %08llx\n"
3921 "rxbuf_start %p, rxbuf_area_size %u, rxbuf_startphy %08llx\n",
3922 adev
->txbuf_start
, adev
->txbuf_area_size
,
3923 (unsigned long long)adev
->txbuf_startphy
,
3924 adev
->txdesc_size
, adev
->txdesc_start
,
3925 adev
->txhostdesc_start
, adev
->txhostdesc_area_size
,
3926 (unsigned long long)adev
->txhostdesc_startphy
,
3928 adev
->rxhostdesc_start
, adev
->rxhostdesc_area_size
,
3929 (unsigned long long)adev
->rxhostdesc_startphy
,
3930 adev
->rxbuf_start
, adev
->rxbuf_area_size
,
3931 (unsigned long long)adev
->rxbuf_startphy
);
3938 /***********************************************************************
3940 int acxpci_proc_eeprom_output(char *buf
, acx_device_t
* adev
)
3947 for (i
= 0; i
< 0x400; i
++) {
3948 acxpci_read_eeprom_byte(adev
, i
, p
++);
3956 /***********************************************************************
3959 void acxpci_set_interrupt_mask(acx_device_t
* adev
)
3961 if (IS_ACX111(adev
)) {
3962 adev
->irq_mask
= (u16
) ~ (0
3963 /* | HOST_INT_RX_DATA */
3964 | HOST_INT_TX_COMPLETE
3965 /* | HOST_INT_TX_XFER */
3966 | HOST_INT_RX_COMPLETE
3967 /* | HOST_INT_DTIM */
3968 /* | HOST_INT_BEACON */
3969 /* | HOST_INT_TIMER */
3970 /* | HOST_INT_KEY_NOT_FOUND */
3971 | HOST_INT_IV_ICV_FAILURE
3972 | HOST_INT_CMD_COMPLETE
3974 /* | HOST_INT_OVERFLOW */
3975 /* | HOST_INT_PROCESS_ERROR */
3976 | HOST_INT_SCAN_COMPLETE
3977 | HOST_INT_FCS_THRESHOLD
3978 /* | HOST_INT_UNKNOWN */
3980 /* Or else acx100 won't signal cmd completion, right? */
3981 adev
->irq_mask_off
= (u16
) ~ (HOST_INT_CMD_COMPLETE
); /* 0xfdff */
3983 adev
->irq_mask
= (u16
) ~ (0
3984 /* | HOST_INT_RX_DATA */
3985 | HOST_INT_TX_COMPLETE
3986 /* | HOST_INT_TX_XFER */
3987 | HOST_INT_RX_COMPLETE
3988 /* | HOST_INT_DTIM */
3989 /* | HOST_INT_BEACON */
3990 /* | HOST_INT_TIMER */
3991 /* | HOST_INT_KEY_NOT_FOUND */
3992 /* | HOST_INT_IV_ICV_FAILURE */
3993 | HOST_INT_CMD_COMPLETE
3995 /* | HOST_INT_OVERFLOW */
3996 /* | HOST_INT_PROCESS_ERROR */
3997 | HOST_INT_SCAN_COMPLETE
3998 /* | HOST_INT_FCS_THRESHOLD */
3999 /* | HOST_INT_UNKNOWN */
4001 adev
->irq_mask_off
= (u16
) ~ (HOST_INT_UNKNOWN
); /* 0x7fff */
4006 /***********************************************************************
4008 int acx100pci_s_set_tx_level(acx_device_t
* adev
, u8 level_dbm
)
4010 /* since it can be assumed that at least the Maxim radio has a
4011 * maximum power output of 20dBm and since it also can be
4012 * assumed that these values drive the DAC responsible for
4013 * setting the linear Tx level, I'd guess that these values
4014 * should be the corresponding linear values for a dBm value,
4015 * in other words: calculate the values from that formula:
4016 * Y [dBm] = 10 * log (X [mW])
4017 * then scale the 0..63 value range onto the 1..100mW range (0..20 dBm)
4018 * and you're done...
4019 * Hopefully that's ok, but you never know if we're actually
4020 * right... (especially since Windows XP doesn't seem to show
4021 * actual Tx dBm values :-P) */
4023 /* NOTE: on Maxim, value 30 IS 30mW, and value 10 IS 10mW - so the
4024 * values are EXACTLY mW!!! Not sure about RFMD and others,
4026 static const u8 dbm2val_maxim
[21] = {
4034 static const u8 dbm2val_rfmd
[21] = {
4044 switch (adev
->radio_type
) {
4045 case RADIO_MAXIM_0D
:
4046 table
= &dbm2val_maxim
[0];
4049 case RADIO_RALINK_15
:
4050 table
= &dbm2val_rfmd
[0];
4053 printk("%s: unknown/unsupported radio type, "
4054 "cannot modify tx power level yet!\n", wiphy_name(adev
->ieee
->wiphy
));
4057 printk("%s: changing radio power level to %u dBm (%u)\n",
4058 wiphy_name(adev
->ieee
->wiphy
), level_dbm
, table
[level_dbm
]);
4059 acxpci_s_write_phy_reg(adev
, 0x11, table
[level_dbm
]);
4064 struct vlynq_reg_config
{
4069 struct vlynq_known
{
4072 struct vlynq_mapping rx_mapping
[4];
4076 struct vlynq_reg_config regs
[10];
4079 #define CHIP_TNETW1130 0x00000009
4080 #define CHIP_TNETW1350 0x00000029
4082 static struct vlynq_known known_devices
[] = {
4084 .chip_id
= CHIP_TNETW1130
, .name
= "TI TNETW1130",
4086 { .size
= 0x22000, .offset
= 0xf0000000 },
4087 { .size
= 0x40000, .offset
= 0xc0000000 },
4088 { .size
= 0x0, .offset
= 0x0 },
4089 { .size
= 0x0, .offset
= 0x0 },
4092 .irq_type
= IRQ_TYPE_EDGE_RISING
,
4097 .value
= (0xd0000000 - PHYS_OFFSET
)
4101 .value
= (0xd0000000 - PHYS_OFFSET
)
4103 { .offset
= 0x740, .value
= 0 },
4104 { .offset
= 0x744, .value
= 0x00010000 },
4105 { .offset
= 0x764, .value
= 0x00010000 },
4109 .chip_id
= CHIP_TNETW1350
, .name
= "TI TNETW1350",
4111 { .size
= 0x100000, .offset
= 0x00300000 },
4112 { .size
= 0x80000, .offset
= 0x00000000 },
4113 { .size
= 0x0, .offset
= 0x0 },
4114 { .size
= 0x0, .offset
= 0x0 },
4117 .irq_type
= IRQ_TYPE_EDGE_RISING
,
4122 .value
= (0x60000000 - PHYS_OFFSET
)
4126 .value
= (0x60000000 - PHYS_OFFSET
)
4128 { .offset
= 0x740, .value
= 0 },
4129 { .offset
= 0x744, .value
= 0x00010000 },
4130 { .offset
= 0x764, .value
= 0x00010000 },
4135 static struct vlynq_device_id acx_vlynq_id
[] = {
4136 { CHIP_TNETW1130
, vlynq_div_auto
, 0 },
4137 { CHIP_TNETW1350
, vlynq_div_auto
, 1 },
4141 static __devinit
int vlynq_probe(struct vlynq_device
*vdev
,
4142 struct vlynq_device_id
*id
)
4144 int result
= -EIO
, i
;
4146 struct ieee80211_hw
*ieee
;
4147 acx_device_t
*adev
= NULL
;
4148 acx111_ie_configoption_t co
;
4149 struct vlynq_mapping mapping
[4] = { { 0, }, };
4150 struct vlynq_known
*match
= NULL
;
4153 result
= vlynq_enable_device(vdev
);
4157 match
= &known_devices
[id
->driver_data
];
4164 mapping
[0].offset
= ARCH_PFN_OFFSET
<< PAGE_SHIFT
;
4165 mapping
[0].size
= 0x02000000;
4166 vlynq_set_local_mapping(vdev
, vdev
->mem_start
, mapping
);
4167 vlynq_set_remote_mapping(vdev
, 0, match
->rx_mapping
);
4169 set_irq_type(vlynq_virq_to_irq(vdev
, match
->irq
), match
->irq_type
);
4171 addr
= (u32
)ioremap(vdev
->mem_start
, 0x1000);
4173 printk(KERN_ERR
"%s: failed to remap io memory\n",
4179 for (i
= 0; i
< match
->num_regs
; i
++)
4180 iowrite32(match
->regs
[i
].value
,
4181 (u32
*)(addr
+ match
->regs
[i
].offset
));
4183 iounmap((void *)addr
);
4185 ieee
= ieee80211_alloc_hw(sizeof(struct acx_device
), &acxpci_hw_ops
);
4187 printk("acx: could not allocate ieee80211 structure %s\n",
4189 goto fail_alloc_netdev
;
4191 ieee
->flags
&= ~IEEE80211_HW_RX_INCLUDES_FCS
;
4194 adev
= ieee2adev(ieee
);
4196 memset(adev
, 0, sizeof(*adev
));
4197 /** Set up our private interface **/
4198 spin_lock_init(&adev
->spinlock
); /* initial state: unlocked */
4199 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
4200 mutex_init(&adev
->mutex
);
4201 /* since nobody can see new netdev yet, we can as well
4202 ** just _presume_ that we're under sem (instead of actually taking it): */
4203 /* acx_sem_lock(adev); */
4206 adev
->bus_dev
= &vdev
->dev
;
4207 adev
->dev_type
= DEVTYPE_PCI
;
4209 /** Finished with private interface **/
4211 vlynq_set_drvdata(vdev
, ieee
);
4212 if (!request_mem_region(vdev
->mem_start
, vdev
->mem_end
- vdev
->mem_start
, "acx")) {
4213 printk("acx: cannot reserve VLYNQ memory region\n");
4214 goto fail_request_mem_region
;
4216 adev
->iobase
= ioremap(vdev
->mem_start
, vdev
->mem_end
- vdev
->mem_start
);
4217 if (!adev
->iobase
) {
4218 printk("acx: ioremap() FAILED\n");
4221 adev
->iobase2
= adev
->iobase
+ match
->rx_mapping
[0].size
;
4222 adev
->chip_type
= CHIPTYPE_ACX111
;
4223 adev
->chip_name
= match
->name
;
4224 adev
->io
= IO_ACX111
;
4225 adev
->irq
= vlynq_virq_to_irq(vdev
, match
->irq
);
4227 printk("acx: found %s-based wireless network card at %s, irq:%d, "
4228 "phymem:0x%x, mem:0x%p\n",
4229 match
->name
, vdev
->dev
.bus_id
, adev
->irq
,
4230 vdev
->mem_start
, adev
->iobase
);
4231 log(L_ANY
, "initial debug setting is 0x%04X\n", acx_debug
);
4233 if (0 == adev
->irq
) {
4234 printk("acx: can't use IRQ 0\n");
4237 SET_IEEE80211_DEV(ieee
, &vdev
->dev
);
4240 /* to find crashes due to weird driver access
4241 * to unconfigured interface (ifup) */
4242 adev
->mgmt_timer
.function
= (void (*)(unsigned long))0x0000dead;
4245 /* ok, pci setup is finished, now start initializing the card */
4247 /* NB: read_reg() reads may return bogus data before reset_dev(),
4248 * since the firmware which directly controls large parts of the I/O
4249 * registers isn't initialized yet.
4250 * acx100 seems to be more affected than acx111 */
4251 if (OK
!= acxpci_s_reset_dev(adev
))
4254 if (OK
!= acx_s_init_mac(adev
))
4257 acx_s_interrogate(adev
, &co
, ACX111_IE_CONFIG_OPTIONS
);
4258 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
4259 if (OK
!= acxpci_read_eeprom_byte(adev
, 0x05, &adev
->eeprom_version
))
4260 goto fail_read_eeprom_version
;
4262 acx_s_parse_configoption(adev
, &co
);
4263 acx_s_set_defaults(adev
);
4264 acx_s_get_firmware_version(adev
); /* needs to be after acx_s_init_mac() */
4265 acx_display_hardware_details(adev
);
4267 /* Register the card, AFTER everything else has been set up,
4268 * since otherwise an ioctl could step on our feet due to
4269 * firmware operations happening in parallel or uninitialized data */
4272 acx_proc_register_entries(ieee
);
4274 /* Now we have our device, so make sure the kernel doesn't try
4275 * to send packets even though we're not associated to a network yet */
4277 /* after register_netdev() userspace may start working with dev
4278 * (in particular, on other CPUs), we only need to up the sem */
4279 /* acx_sem_unlock(adev); */
4281 printk("acx " ACX_RELEASE
": net device %s, driver compiled "
4282 "against wireless extensions %d and Linux %s\n",
4283 wiphy_name(adev
->ieee
->wiphy
), WIRELESS_EXT
, UTS_RELEASE
);
4285 MAC_COPY(adev
->ieee
->wiphy
->perm_addr
, adev
->dev_addr
);
4287 log(L_IRQ
| L_INIT
, "using IRQ %d\n", adev
->irq
);
4289 /** done with board specific setup **/
4291 acx_init_task_scheduler(adev
);
4292 result
= ieee80211_register_hw(adev
->ieee
);
4294 printk("acx: ieee80211_register_hw() FAILED: %d\n", result
);
4295 goto fail_register_netdev
;
4298 great_inquisitor(adev
);
4304 /* error paths: undo everything in reverse order... */
4307 acxpci_s_delete_dma_regions(adev
);
4310 fail_read_eeprom_version
:
4316 iounmap(adev
->iobase
);
4319 release_mem_region(vdev
->mem_start
, vdev
->mem_end
- vdev
->mem_start
);
4320 fail_request_mem_region
:
4321 fail_register_netdev
:
4322 ieee80211_free_hw(ieee
);
4324 vlynq_disable_device(vdev
);
4330 static void vlynq_remove(struct vlynq_device
*vdev
)
4332 struct ieee80211_hw
*hw
= vlynq_get_drvdata(vdev
);
4333 acx_device_t
*adev
= ieee2adev(hw
);
4334 unsigned long flags
;
4338 log(L_DEBUG
, "%s: card is unused. Skipping any release code\n",
4344 acx_lock(adev
, flags
);
4345 acx_unlock(adev
, flags
);
4346 adev
->initialized
= 0;
4348 /* If device wasn't hot unplugged... */
4349 if (adev_present(adev
)) {
4353 /* disable both Tx and Rx to shut radio down properly */
4354 if (adev
->initialized
) {
4355 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_TX
, NULL
, 0);
4356 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_RX
, NULL
, 0);
4358 acx_lock(adev
, flags
);
4359 /* disable power LED to save power :-) */
4360 log(L_INIT
, "switching off power LED to save power\n");
4361 acxpci_l_power_led(adev
, 0);
4363 acx_unlock(adev
, flags
);
4365 acx_sem_unlock(adev
);
4368 /* unregister the device to not let the kernel
4369 * (e.g. ioctls) access a half-deconfigured device
4370 * NB: this will cause acxpci_e_close() to be called,
4371 * thus we shouldn't call it under sem!
4372 * Well, netdev did, but ieee80211 stack does not, so we
4373 * have to do so manually...
4376 log(L_INIT
, "removing device %s\n", wiphy_name(adev
->ieee
->wiphy
));
4377 ieee80211_unregister_hw(adev
->ieee
);
4379 /* unregister_netdev ensures that no references to us left.
4380 * For paranoid reasons we continue to follow the rules */
4383 if (adev
->dev_state_mask
& ACX_STATE_IFACE_UP
) {
4385 CLEAR_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
4388 acx_proc_unregister_entries(adev
->ieee
);
4390 /* finally, clean up PCI bus state */
4391 acxpci_s_delete_dma_regions(adev
);
4393 iounmap(adev
->iobase
);
4395 iounmap(adev
->iobase2
);
4396 release_mem_region(vdev
->mem_start
, vdev
->mem_end
- vdev
->mem_start
);
4398 /* remove dev registration */
4400 acx_sem_unlock(adev
);
4401 vlynq_disable_device(vdev
);
4403 /* Free netdev (quite late,
4404 * since otherwise we might get caught off-guard
4405 * by a netdev timeout handler execution
4406 * expecting to see a working dev...) */
4407 ieee80211_free_hw(adev
->ieee
);
4413 static struct vlynq_driver vlynq_acx
= {
4414 .name
= "acx_vlynq",
4415 .id_table
= acx_vlynq_id
,
4416 .probe
= vlynq_probe
,
4417 .remove
= __devexit_p(vlynq_remove
),
4419 #endif /* CONFIG_VLYNQ */
4422 /***********************************************************************
4423 ** Data for init_module/cleanup_module
4426 static const struct pci_device_id acxpci_id_tbl
[] __devinitdata
= {
4428 .vendor
= PCI_VENDOR_ID_TI
,
4429 .device
= PCI_DEVICE_ID_TI_TNETW1100A
,
4430 .subvendor
= PCI_ANY_ID
,
4431 .subdevice
= PCI_ANY_ID
,
4432 .driver_data
= CHIPTYPE_ACX100
,
4435 .vendor
= PCI_VENDOR_ID_TI
,
4436 .device
= PCI_DEVICE_ID_TI_TNETW1100B
,
4437 .subvendor
= PCI_ANY_ID
,
4438 .subdevice
= PCI_ANY_ID
,
4439 .driver_data
= CHIPTYPE_ACX100
,
4442 .vendor
= PCI_VENDOR_ID_TI
,
4443 .device
= PCI_DEVICE_ID_TI_TNETW1130
,
4444 .subvendor
= PCI_ANY_ID
,
4445 .subdevice
= PCI_ANY_ID
,
4446 .driver_data
= CHIPTYPE_ACX111
,
4457 MODULE_DEVICE_TABLE(pci
, acxpci_id_tbl
);
4459 static struct pci_driver
4462 .id_table
= acxpci_id_tbl
,
4463 .probe
= acxpci_e_probe
,
4464 .remove
= __devexit_p(acxpci_e_remove
),
4466 .suspend
= acxpci_e_suspend
,
4467 .resume
= acxpci_e_resume
4468 #endif /* CONFIG_PM */
4470 #endif /* CONFIG_PCI */
4472 /***********************************************************************
4473 ** acxpci_e_init_module
4475 ** Module initialization routine, called once at module load time
4477 int __init
acxpci_e_init_module(void)
4483 #if (ACX_IO_WIDTH==32)
4484 printk("acx: compiled to use 32bit I/O access. "
4485 "I/O timing issues might occur, such as "
4486 "non-working firmware upload. Report them\n");
4488 printk("acx: compiled to use 16bit I/O access only "
4489 "(compatibility mode)\n");
4492 #ifdef __LITTLE_ENDIAN
4493 #define ENDIANNESS_STRING "running on a little-endian CPU\n"
4495 #define ENDIANNESS_STRING "running on a BIG-ENDIAN CPU\n"
4498 "acx: " ENDIANNESS_STRING
4499 "acx: PCI/VLYNQ module " ACX_RELEASE
" initialized, "
4500 "waiting for cards to probe...\n");
4503 res
= pci_register_driver(&acxpci_drv_id
);
4505 res
= vlynq_register_driver(&vlynq_acx
);
4512 /***********************************************************************
4513 ** acxpci_e_cleanup_module
4515 ** Called at module unload time. This is our last chance to
4516 ** clean up after ourselves.
4518 void __exit
acxpci_e_cleanup_module(void)
4523 pci_unregister_driver(&acxpci_drv_id
);
4525 vlynq_unregister_driver(&vlynq_acx
);
4528 "acx: PCI module " ACX_RELEASE
" unloaded\n");