2 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
3 * The ACX100 Open Source Project <acx100-devel@lists.sourceforge.net>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #define ACX_MAC80211_PCI 1
20 #include <linux/version.h>
22 /* Linux 2.6.18+ uses <linux/utsrelease.h> */
24 #include <linux/utsrelease.h>
27 #include <linux/compiler.h> /* required for Lx 2.6.8 ?? */
28 #include <linux/kernel.h>
29 #include <linux/module.h>
30 #include <linux/moduleparam.h>
31 #include <linux/sched.h>
32 #include <linux/types.h>
33 #include <linux/skbuff.h>
34 #include <linux/slab.h>
35 #include <linux/if_arp.h>
36 #include <linux/rtnetlink.h>
37 #include <linux/wireless.h>
38 #include <net/iw_handler.h>
39 #include <linux/netdevice.h>
40 #include <linux/ioport.h>
41 #include <linux/pci.h>
43 #include <linux/vmalloc.h>
44 #include <linux/ethtool.h>
45 #include <linux/dma-mapping.h>
46 #include <linux/workqueue.h>
48 #include <linux/vlynq.h>
53 /***********************************************************************
56 #define PCI_TYPE (PCI_USES_MEM | PCI_ADDR0 | PCI_NO_ACPI_WAKE)
57 #define PCI_ACX100_REGION1 0x01
58 #define PCI_ACX100_REGION1_SIZE 0x1000 /* Memory size - 4K bytes */
59 #define PCI_ACX100_REGION2 0x02
60 #define PCI_ACX100_REGION2_SIZE 0x10000 /* Memory size - 64K bytes */
62 #define PCI_ACX111_REGION1 0x00
63 #define PCI_ACX111_REGION1_SIZE 0x2000 /* Memory size - 8K bytes */
64 #define PCI_ACX111_REGION2 0x01
65 #define PCI_ACX111_REGION2_SIZE 0x20000 /* Memory size - 128K bytes */
67 /* Texas Instruments Vendor ID */
68 #define PCI_VENDOR_ID_TI 0x104c
70 /* ACX100 22Mb/s WLAN controller */
71 #define PCI_DEVICE_ID_TI_TNETW1100A 0x8400
72 #define PCI_DEVICE_ID_TI_TNETW1100B 0x8401
74 /* ACX111 54Mb/s WLAN controller */
75 #define PCI_DEVICE_ID_TI_TNETW1130 0x9066
77 /* PCI Class & Sub-Class code, Network-'Other controller' */
78 #define PCI_CLASS_NETWORK_OTHERS 0x0280
80 #define CARD_EEPROM_ID_SIZE 6
83 /* From include/linux/pci.h */
90 #define PCI_POWER_ERROR -1
92 #endif /* CONFIG_PCI */
94 /***********************************************************************
97 static irqreturn_t
acxpci_i_interrupt(int irq
, void *dev_id
);
99 static void disable_acx_irq(acx_device_t
* adev
);
101 static int acxpci_e_open(struct ieee80211_hw
*hw
);
102 static void acxpci_e_close(struct ieee80211_hw
*hw
);
103 static void acxpci_s_up(struct ieee80211_hw
*hw
);
104 static void acxpci_s_down(struct ieee80211_hw
*hw
);
106 /***********************************************************************
112 /* OS I/O routines *always* be endianness-clean but having them doesn't hurt */
113 #define acx_readl(v) le32_to_cpu(readl((v)))
114 #define acx_readw(v) le16_to_cpu(readw((v)))
115 #define acx_writew(v,r) writew(le16_to_cpu((v)), r)
116 #define acx_writel(v,r) writel(le32_to_cpu((v)), r)
119 /* #define INLINE_IO static */
120 #define INLINE_IO static inline
122 INLINE_IO u32
read_reg32(acx_device_t
* adev
, unsigned int offset
)
124 #if ACX_IO_WIDTH == 32
125 return acx_readl((u8
*) adev
->iobase
+ adev
->io
[offset
]);
127 return acx_readw((u8
*) adev
->iobase
+ adev
->io
[offset
])
128 + (acx_readw((u8
*) adev
->iobase
+ adev
->io
[offset
] + 2) << 16);
132 INLINE_IO u16
read_reg16(acx_device_t
* adev
, unsigned int offset
)
134 return acx_readw((u8
*) adev
->iobase
+ adev
->io
[offset
]);
137 INLINE_IO u8
read_reg8(acx_device_t
* adev
, unsigned int offset
)
139 return readb((u8
*) adev
->iobase
+ adev
->io
[offset
]);
142 INLINE_IO
void write_reg32(acx_device_t
* adev
, unsigned int offset
, u32 val
)
144 #if ACX_IO_WIDTH == 32
145 acx_writel(val
, (u8
*) adev
->iobase
+ adev
->io
[offset
]);
147 acx_writew(val
& 0xffff, (u8
*) adev
->iobase
+ adev
->io
[offset
]);
148 acx_writew(val
>> 16, (u8
*) adev
->iobase
+ adev
->io
[offset
] + 2);
152 INLINE_IO
void write_reg16(acx_device_t
* adev
, unsigned int offset
, u16 val
)
154 acx_writew(val
, (u8
*) adev
->iobase
+ adev
->io
[offset
]);
157 INLINE_IO
void write_reg8(acx_device_t
* adev
, unsigned int offset
, u8 val
)
159 writeb(val
, (u8
*) adev
->iobase
+ adev
->io
[offset
]);
162 /* Handle PCI posting properly:
163 * Make sure that writes reach the adapter in case they require to be executed
164 * *before* the next write, by reading a random (and safely accessible) register.
165 * This call has to be made if there is no read following (which would flush the data
166 * to the adapter), yet the written data has to reach the adapter immediately. */
167 INLINE_IO
void write_flush(acx_device_t
* adev
)
169 /* readb(adev->iobase + adev->io[IO_ACX_INFO_MAILBOX_OFFS]); */
170 /* faster version (accesses the first register, IO_ACX_SOFT_RESET,
171 * which should also be safe): */
175 INLINE_IO
int adev_present(acx_device_t
* adev
)
177 /* fast version (accesses the first register, IO_ACX_SOFT_RESET,
178 * which should be safe): */
179 return acx_readl(adev
->iobase
) != 0xffffffff;
183 /***********************************************************************
185 static inline txdesc_t
*get_txdesc(acx_device_t
* adev
, int index
)
187 return (txdesc_t
*) (((u8
*) adev
->txdesc_start
) +
188 index
* adev
->txdesc_size
);
191 static inline txdesc_t
*advance_txdesc(acx_device_t
* adev
, txdesc_t
* txdesc
,
194 return (txdesc_t
*) (((u8
*) txdesc
) + inc
* adev
->txdesc_size
);
197 static txhostdesc_t
*get_txhostdesc(acx_device_t
* adev
, txdesc_t
* txdesc
)
199 int index
= (u8
*) txdesc
- (u8
*) adev
->txdesc_start
;
203 if (unlikely(ACX_DEBUG
&& (index
% adev
->txdesc_size
))) {
204 printk("acx: bad txdesc ptr %p\n", txdesc
);
207 index
/= adev
->txdesc_size
;
208 if (unlikely(ACX_DEBUG
&& (index
>= TX_CNT
))) {
209 printk("acx: bad txdesc ptr %p\n", txdesc
);
215 return &adev
->txhostdesc_start
[index
* 2];
222 /***********************************************************************
223 ** EEPROM and PHY read/write helpers
225 /***********************************************************************
226 ** acxpci_read_eeprom_byte
228 ** Function called to read an octet in the EEPROM.
230 ** This function is used by acxpci_e_probe to check if the
231 ** connected card is a legal one or not.
234 ** adev ptr to acx_device structure
235 ** addr address to read in the EEPROM
236 ** charbuf ptr to a char. This is where the read octet
240 int acxpci_read_eeprom_byte(acx_device_t
* adev
, u32 addr
, u8
* charbuf
)
247 write_reg32(adev
, IO_ACX_EEPROM_CFG
, 0);
248 write_reg32(adev
, IO_ACX_EEPROM_ADDR
, addr
);
250 write_reg32(adev
, IO_ACX_EEPROM_CTL
, 2);
253 while (read_reg16(adev
, IO_ACX_EEPROM_CTL
)) {
254 /* scheduling away instead of CPU burning loop
255 * doesn't seem to work here at all:
256 * awful delay, sometimes also failure.
257 * Doesn't matter anyway (only small delay). */
258 if (unlikely(!--count
)) {
259 printk("acx: %s: timeout waiting for EEPROM read\n",
260 wiphy_name(adev
->ieee
->wiphy
));
267 *charbuf
= read_reg8(adev
, IO_ACX_EEPROM_DATA
);
268 log(L_DEBUG
, "acx: EEPROM at 0x%04X = 0x%02X\n", addr
, *charbuf
);
277 /***********************************************************************
278 ** We don't lock hw accesses here since we never r/w eeprom in IRQ
279 ** Note: this function sleeps only because of GFP_KERNEL alloc
283 acxpci_s_write_eeprom(acx_device_t
* adev
, u32 addr
, u32 len
,
286 u8
*data_verify
= NULL
;
292 printk("acx: WARNING! I would write to EEPROM now. "
293 "Since I really DON'T want to unless you know "
294 "what you're doing (THIS CODE WILL PROBABLY "
295 "NOT WORK YET!), I will abort that now. And "
296 "definitely make sure to make a "
297 "/proc/driver/acx_wlan0_eeprom backup copy first!!! "
298 "(the EEPROM content includes the PCI config header!! "
299 "If you kill important stuff, then you WILL "
300 "get in trouble and people DID get in trouble already)\n");
305 data_verify
= kmalloc(len
, GFP_KERNEL
);
310 /* first we need to enable the OE (EEPROM Output Enable) GPIO line
311 * to be able to write to the EEPROM.
312 * NOTE: an EEPROM writing success has been reported,
313 * but you probably have to modify GPIO_OUT, too,
314 * and you probably need to activate a different GPIO
316 gpio_orig
= read_reg16(adev
, IO_ACX_GPIO_OE
);
317 write_reg16(adev
, IO_ACX_GPIO_OE
, gpio_orig
& ~1);
320 /* ok, now start writing the data out */
321 for (i
= 0; i
< len
; i
++) {
322 write_reg32(adev
, IO_ACX_EEPROM_CFG
, 0);
323 write_reg32(adev
, IO_ACX_EEPROM_ADDR
, addr
+ i
);
324 write_reg32(adev
, IO_ACX_EEPROM_DATA
, *(charbuf
+ i
));
326 write_reg32(adev
, IO_ACX_EEPROM_CTL
, 1);
329 while (read_reg16(adev
, IO_ACX_EEPROM_CTL
)) {
330 if (unlikely(!--count
)) {
331 printk("acx: WARNING, DANGER!!! "
332 "Timeout waiting for EEPROM write\n");
339 /* disable EEPROM writing */
340 write_reg16(adev
, IO_ACX_GPIO_OE
, gpio_orig
);
343 /* now start a verification run */
344 for (i
= 0; i
< len
; i
++) {
345 write_reg32(adev
, IO_ACX_EEPROM_CFG
, 0);
346 write_reg32(adev
, IO_ACX_EEPROM_ADDR
, addr
+ i
);
348 write_reg32(adev
, IO_ACX_EEPROM_CTL
, 2);
351 while (read_reg16(adev
, IO_ACX_EEPROM_CTL
)) {
352 if (unlikely(!--count
)) {
353 printk("acx: timeout waiting for EEPROM read\n");
359 data_verify
[i
] = read_reg16(adev
, IO_ACX_EEPROM_DATA
);
362 if (0 == memcmp(charbuf
, data_verify
, len
))
363 result
= OK
; /* read data matches, success */
373 /***********************************************************************
374 ** acxpci_s_read_phy_reg
376 ** Messing with rx/tx disabling and enabling here
377 ** (write_reg32(adev, IO_ACX_ENABLE, 0b000000xx)) kills traffic
379 int acxpci_s_read_phy_reg(acx_device_t
* adev
, u32 reg
, u8
* charbuf
)
386 write_reg32(adev
, IO_ACX_PHY_ADDR
, reg
);
388 write_reg32(adev
, IO_ACX_PHY_CTL
, 2);
391 while (read_reg32(adev
, IO_ACX_PHY_CTL
)) {
392 /* scheduling away instead of CPU burning loop
393 * doesn't seem to work here at all:
394 * awful delay, sometimes also failure.
395 * Doesn't matter anyway (only small delay). */
396 if (unlikely(!--count
)) {
397 printk("acx: %s: timeout waiting for phy read\n",
398 wiphy_name(adev
->ieee
->wiphy
));
405 log(L_DEBUG
, "acx: the count was %u\n", count
);
406 *charbuf
= read_reg8(adev
, IO_ACX_PHY_DATA
);
408 log(L_DEBUG
, "acx: radio PHY at 0x%04X = 0x%02X\n", *charbuf
, reg
);
410 goto fail
; /* silence compiler warning */
417 /***********************************************************************
419 int acxpci_s_write_phy_reg(acx_device_t
* adev
, u32 reg
, u8 value
)
423 /* mprusko said that 32bit accesses result in distorted sensitivity
424 * on his card. Unconfirmed, looks like it's not true (most likely since we
425 * now properly flush writes). */
426 write_reg32(adev
, IO_ACX_PHY_DATA
, value
);
427 write_reg32(adev
, IO_ACX_PHY_ADDR
, reg
);
429 write_reg32(adev
, IO_ACX_PHY_CTL
, 1);
431 log(L_DEBUG
, "acx: radio PHY write 0x%02X at 0x%04X\n", value
, reg
);
438 #define NO_AUTO_INCREMENT 1
440 /***********************************************************************
443 ** Write the firmware image into the card.
446 ** adev wlan device structure
447 ** fw_image firmware image.
450 ** 1 firmware image corrupted
453 ** Standard csum implementation + write to IO
456 acxpci_s_write_fw(acx_device_t
* adev
, const firmware_image_t
*fw_image
,
461 /* we skip the first four bytes which contain the control sum */
463 const u8
*p
= (u8
*) fw_image
+ 4;
467 /* start the image checksum by adding the image size value */
468 sum
= p
[0] + p
[1] + p
[2] + p
[3];
471 write_reg32(adev
, IO_ACX_SLV_END_CTL
, 0);
473 #if NO_AUTO_INCREMENT
474 write_reg32(adev
, IO_ACX_SLV_MEM_CTL
, 0); /* use basic mode */
476 write_reg32(adev
, IO_ACX_SLV_MEM_CTL
, 1); /* use autoincrement mode */
477 write_reg32(adev
, IO_ACX_SLV_MEM_ADDR
, offset
); /* configure start address */
482 size
= le32_to_cpu(fw_image
->size
) & (~3);
484 while (likely(len
< size
)) {
485 v32
= be32_to_cpu(*(u32
*) p
);
486 sum
+= p
[0] + p
[1] + p
[2] + p
[3];
490 #if NO_AUTO_INCREMENT
491 write_reg32(adev
, IO_ACX_SLV_MEM_ADDR
, offset
+ len
- 4);
494 write_reg32(adev
, IO_ACX_SLV_MEM_DATA
, v32
);
497 log(L_DEBUG
, "acx: firmware written, size:%d sum1:%x sum2:%x\n",
498 size
, sum
, le32_to_cpu(fw_image
->chksum
));
500 /* compare our checksum with the stored image checksum */
501 FN_EXIT1(sum
!= le32_to_cpu(fw_image
->chksum
));
502 return (sum
!= le32_to_cpu(fw_image
->chksum
));
506 /***********************************************************************
507 ** acxpci_s_validate_fw
509 ** Compare the firmware image given with
510 ** the firmware image written into the card.
513 ** adev wlan device structure
514 ** fw_image firmware image.
517 ** NOT_OK firmware image corrupted or not correctly written
520 ** Origin: Standard csum + Read IO
523 acxpci_s_validate_fw(acx_device_t
* adev
, const firmware_image_t
*fw_image
,
529 /* we skip the first four bytes which contain the control sum */
530 const u8
*p
= (u8
*) fw_image
+ 4;
534 /* start the image checksum by adding the image size value */
535 sum
= p
[0] + p
[1] + p
[2] + p
[3];
538 write_reg32(adev
, IO_ACX_SLV_END_CTL
, 0);
540 #if NO_AUTO_INCREMENT
541 write_reg32(adev
, IO_ACX_SLV_MEM_CTL
, 0); /* use basic mode */
543 write_reg32(adev
, IO_ACX_SLV_MEM_CTL
, 1); /* use autoincrement mode */
544 write_reg32(adev
, IO_ACX_SLV_MEM_ADDR
, offset
); /* configure start address */
548 size
= le32_to_cpu(fw_image
->size
) & (~3);
550 while (likely(len
< size
)) {
551 v32
= be32_to_cpu(*(u32
*) p
);
555 #if NO_AUTO_INCREMENT
556 write_reg32(adev
, IO_ACX_SLV_MEM_ADDR
, offset
+ len
- 4);
558 w32
= read_reg32(adev
, IO_ACX_SLV_MEM_DATA
);
560 if (unlikely(w32
!= v32
)) {
561 printk("acx: FATAL: firmware upload: "
562 "data parts at offset %d don't match (0x%08X vs. 0x%08X)! "
563 "I/O timing issues or defective memory, with DWL-xx0+? "
564 "ACX_IO_WIDTH=16 may help. Please report\n",
571 (u8
) w32
+ (u8
) (w32
>> 8) + (u8
) (w32
>> 16) +
575 /* sum control verification */
576 if (result
!= NOT_OK
) {
577 if (sum
!= le32_to_cpu(fw_image
->chksum
)) {
578 printk("acx: FATAL: firmware upload: "
579 "checksums don't match!\n");
589 /***********************************************************************
590 ** acxpci_s_upload_fw
592 ** Called from acx_reset_dev
594 ** Origin: Derived from FW dissection
596 static int acxpci_s_upload_fw(acx_device_t
* adev
)
598 firmware_image_t
*fw_image
= NULL
;
602 char filename
[sizeof("tiacx1NNcNN")];
606 /* print exact chipset and radio ID to make sure people
607 * really get a clue on which files exactly they need to provide.
608 * Firmware loading is a frequent end-user PITA with these chipsets.
610 printk( "acx: need firmware for acx1%02d chipset with radio ID %02X\n"
611 "Please provide via firmware hotplug:\n"
612 "either combined firmware (single file named 'tiacx1%02dc%02X')\n"
613 "or two files (base firmware file 'tiacx1%02d' "
614 "+ radio fw 'tiacx1%02dr%02X')\n",
615 IS_ACX111(adev
)*11, adev
->radio_type
,
616 IS_ACX111(adev
)*11, adev
->radio_type
,
618 IS_ACX111(adev
)*11, adev
->radio_type
621 /* print exact chipset and radio ID to make sure people really get a clue on which files exactly they are supposed to provide,
622 * since firmware loading is the biggest enduser PITA with these chipsets.
623 * Not printing radio ID in 0xHEX in order to not confuse them into wrong file naming */
624 printk( "acx: need to load firmware for acx1%02d chipset with radio ID %02x, please provide via firmware hotplug:\n"
625 "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",
626 IS_ACX111(adev
)*11, adev
->radio_type
);
628 /* Try combined, then main image */
629 adev
->need_radio_fw
= 0;
630 snprintf(filename
, sizeof(filename
), "tiacx1%02dc%02X",
631 IS_ACX111(adev
) * 11, adev
->radio_type
);
633 fw_image
= acx_s_read_fw(adev
->bus_dev
, filename
, &file_size
);
635 adev
->need_radio_fw
= 1;
636 filename
[sizeof("tiacx1NN") - 1] = '\0';
638 acx_s_read_fw(adev
->bus_dev
, filename
, &file_size
);
645 for (try = 1; try <= 5; try++) {
646 res
= acxpci_s_write_fw(adev
, fw_image
, 0);
647 log(L_DEBUG
| L_INIT
, "acx: acx_write_fw (main/combined): %d\n", res
);
649 res
= acxpci_s_validate_fw(adev
, fw_image
, 0);
650 log(L_DEBUG
| L_INIT
, "acx: acx_validate_fw "
651 "(main/combined): %d\n", res
);
655 SET_BIT(adev
->dev_state_mask
, ACX_STATE_FW_LOADED
);
658 printk("acx: firmware upload attempt #%d FAILED, "
659 "retrying...\n", try);
660 acx_s_mwait(1000); /* better wait for a while... */
670 /***********************************************************************
671 ** acxpci_s_upload_radio
673 ** Uploads the appropriate radio module firmware into the card.
675 ** Origin: Standard Read/Write to IO
677 int acxpci_s_upload_radio(acx_device_t
* adev
)
680 firmware_image_t
*radio_image
;
681 acx_cmd_radioinit_t radioinit
;
686 char filename
[sizeof("tiacx1NNrNN")];
688 if (!adev
->need_radio_fw
)
693 acx_s_interrogate(adev
, &mm
, ACX1xx_IE_MEMORY_MAP
);
694 offset
= le32_to_cpu(mm
.CodeEnd
);
696 snprintf(filename
, sizeof(filename
), "tiacx1%02dr%02X",
697 IS_ACX111(adev
) * 11, adev
->radio_type
);
698 radio_image
= acx_s_read_fw(adev
->bus_dev
, filename
, &size
);
700 printk("acx: can't load radio module '%s'\n", filename
);
704 acx_s_issue_cmd(adev
, ACX1xx_CMD_SLEEP
, NULL
, 0);
706 for (try = 1; try <= 5; try++) {
707 res
= acxpci_s_write_fw(adev
, radio_image
, offset
);
708 log(L_DEBUG
| L_INIT
, "acx: acx_write_fw (radio): %d\n", res
);
710 res
= acxpci_s_validate_fw(adev
, radio_image
, offset
);
711 log(L_DEBUG
| L_INIT
, "acx: acx_validate_fw (radio): %d\n",
717 printk("acx: radio firmware upload attempt #%d FAILED, "
718 "retrying...\n", try);
719 acx_s_mwait(1000); /* better wait for a while... */
722 acx_s_issue_cmd(adev
, ACX1xx_CMD_WAKE
, NULL
, 0);
723 radioinit
.offset
= cpu_to_le32(offset
);
724 /* no endian conversion needed, remains in card CPU area: */
725 radioinit
.len
= radio_image
->size
;
732 /* will take a moment so let's have a big timeout */
733 acx_s_issue_cmd_timeo(adev
, ACX1xx_CMD_RADIOINIT
,
734 &radioinit
, sizeof(radioinit
),
735 CMD_TIMEOUT_MS(1000));
737 res
= acx_s_interrogate(adev
, &mm
, ACX1xx_IE_MEMORY_MAP
);
744 /***********************************************************************
745 ** acxpci_l_reset_mac
748 ** Call context: reset_dev
750 ** Origin: Standard Read/Write to IO
752 static void acxpci_l_reset_mac(acx_device_t
* adev
)
759 temp
= read_reg16(adev
, IO_ACX_ECPU_CTRL
) | 0x1;
760 write_reg16(adev
, IO_ACX_ECPU_CTRL
, temp
);
762 /* now do soft reset of eCPU, set bit */
763 temp
= read_reg16(adev
, IO_ACX_SOFT_RESET
) | 0x1;
764 log(L_DEBUG
, "acx: enable soft reset\n");
765 write_reg16(adev
, IO_ACX_SOFT_RESET
, temp
);
768 /* now clear bit again: deassert eCPU reset */
769 log(L_DEBUG
, "acx: disable soft reset and go to init mode\n");
770 write_reg16(adev
, IO_ACX_SOFT_RESET
, temp
& ~0x1);
772 /* now start a burst read from initial EEPROM */
773 temp
= read_reg16(adev
, IO_ACX_EE_START
) | 0x1;
774 write_reg16(adev
, IO_ACX_EE_START
, temp
);
781 /***********************************************************************
782 ** acxpci_s_verify_init
784 static int acxpci_s_verify_init(acx_device_t
* adev
)
787 unsigned long timeout
;
791 timeout
= jiffies
+ 2 * HZ
;
793 u16 irqstat
= read_reg16(adev
, IO_ACX_IRQ_STATUS_NON_DES
);
794 if (irqstat
& HOST_INT_FCS_THRESHOLD
) {
796 write_reg16(adev
, IO_ACX_IRQ_ACK
,
797 HOST_INT_FCS_THRESHOLD
);
800 if (time_after(jiffies
, timeout
))
802 /* Init may take up to ~0.5 sec total */
811 /***********************************************************************
812 ** A few low-level helpers
814 ** Note: these functions are not protected by lock
815 ** and thus are never allowed to be called from IRQ.
816 ** Also they must not race with fw upload which uses same hw regs
819 /***********************************************************************
820 ** acxpci_write_cmd_type_status
822 ** Origin: Common linux implementation
826 acxpci_write_cmd_type_status(acx_device_t
* adev
, u16 type
, u16 status
)
829 acx_writel(type
| (status
<< 16), adev
->cmd_area
);
835 /***********************************************************************
836 ** acxpci_read_cmd_type_status
838 ** Origin: Common linux implementation
840 static u32
acxpci_read_cmd_type_status(acx_device_t
* adev
)
842 u32 cmd_type
, cmd_status
;
846 cmd_type
= acx_readl(adev
->cmd_area
);
847 cmd_status
= (cmd_type
>> 16);
848 cmd_type
= (u16
) cmd_type
;
850 log(L_CTL
, "acx: cmd_type:%04X cmd_status:%04X [%s]\n",
851 cmd_type
, cmd_status
, acx_cmd_status_str(cmd_status
));
853 FN_EXIT1(cmd_status
);
858 /***********************************************************************
859 ** acxpci_s_reset_dev
862 ** netdevice that contains the adev variable
867 ** device is hard reset
871 ** This resets the device using low level hardware calls
872 ** as well as uploads and verifies the firmware to the card
875 static inline void init_mboxes(acx_device_t
* adev
)
877 u32 cmd_offs
, info_offs
;
881 cmd_offs
= read_reg32(adev
, IO_ACX_CMD_MAILBOX_OFFS
);
882 info_offs
= read_reg32(adev
, IO_ACX_INFO_MAILBOX_OFFS
);
883 adev
->cmd_area
= (u8
*) adev
->iobase2
+ cmd_offs
;
884 adev
->info_area
= (u8
*) adev
->iobase2
+ info_offs
;
885 log(L_DEBUG
, "acx: iobase2=%p\n"
886 "acx: cmd_mbox_offset=%X cmd_area=%p\n"
887 "acx: info_mbox_offset=%X info_area=%p\n",
889 cmd_offs
, adev
->cmd_area
, info_offs
, adev
->info_area
);
894 static inline void read_eeprom_area(acx_device_t
* adev
)
902 for (offs
= 0x8c; offs
< 0xb9; offs
++)
903 acxpci_read_eeprom_byte(adev
, offs
, &tmp
);
910 int acxpci_s_reset_dev(acx_device_t
* adev
)
912 const char *msg
= "";
921 /* reset the device to make sure the eCPU is stopped
922 * to upload the firmware correctly */
924 acx_lock(adev
, flags
);
927 acxpci_l_reset_mac(adev
);
930 ecpu_ctrl
= read_reg16(adev
, IO_ACX_ECPU_CTRL
) & 1;
932 msg
= "acx: eCPU is already running. ";
936 if (read_reg16(adev
, IO_ACX_SOR_CFG
) & 2) {
937 /* eCPU most likely means "embedded CPU" */
938 msg
= "acx: eCPU did not start after boot from flash. ";
942 /* check sense on reset flags */
943 if (read_reg16(adev
, IO_ACX_SOR_CFG
) & 0x10) {
944 printk("acx: %s: eCPU did not start after boot (SOR), "
945 "is this fatal?\n", wiphy_name(adev
->ieee
->wiphy
));
948 /* scan, if any, is stopped now, setting corresponding IRQ bit */
949 SET_BIT(adev
->irq_status
, HOST_INT_SCAN_COMPLETE
);
951 acx_unlock(adev
, flags
);
953 /* need to know radio type before fw load */
954 /* Need to wait for arrival of this information in a loop,
955 * most probably since eCPU runs some init code from EEPROM
956 * (started burst read in reset_mac()) which also
957 * sets the radio type ID */
961 hardware_info
= read_reg16(adev
, IO_ACX_EEPROM_INFORMATION
);
963 msg
= "acx: eCPU didn't indicate radio type";
967 } while (!(hardware_info
& 0xff00)); /* radio type still zero? */
969 /* printk("acx: DEBUG: count %d\n", count); */
970 adev
->form_factor
= hardware_info
& 0xff;
971 adev
->radio_type
= hardware_info
>> 8;
973 /* load the firmware */
974 if (OK
!= acxpci_s_upload_fw(adev
))
977 /* acx_s_mwait(10); this one really shouldn't be required */
979 /* now start eCPU by clearing bit */
980 write_reg16(adev
, IO_ACX_ECPU_CTRL
, ecpu_ctrl
& ~0x1);
981 log(L_DEBUG
, "acx: booted eCPU up and waiting for completion...\n");
983 /* wait for eCPU bootup */
984 if (OK
!= acxpci_s_verify_init(adev
)) {
985 msg
= "acx: timeout waiting for eCPU. ";
988 log(L_DEBUG
, "acx: eCPU has woken up, card is ready to be configured\n");
991 acxpci_write_cmd_type_status(adev
, 0, 0);
993 /* test that EEPROM is readable */
994 read_eeprom_area(adev
);
999 /* Finish error message. Indicate which function failed */
1001 acx_unlock(adev
, flags
);
1003 printk("acx: %sreset_dev() FAILED\n", msg
);
1010 /***********************************************************************
1011 ** acxpci_s_issue_cmd_timeo
1013 ** Sends command to fw, extract result
1015 ** NB: we do _not_ take lock inside, so be sure to not touch anything
1016 ** which may interfere with IRQ handler operation
1018 ** TODO: busy wait is a bit silly, so:
1019 ** 1) stop doing many iters - go to sleep after first
1020 ** 2) go to waitqueue based approach: wait, not poll!
1023 #define FUNC "issue_cmd"
1027 acxpci_s_issue_cmd_timeo(acx_device_t
* adev
,
1029 void *buffer
, unsigned buflen
, unsigned cmd_timeout
)
1033 acxpci_s_issue_cmd_timeo_debug(acx_device_t
* adev
,
1037 unsigned cmd_timeout
, const char *cmdstr
)
1039 unsigned long start
= jiffies
;
1041 const char *devname
;
1045 unsigned long timeout
;
1049 devname
= wiphy_name(adev
->ieee
->wiphy
);
1050 if (!devname
|| !devname
[0] || devname
[4] == '%')
1053 log(L_CTL
, FUNC
"acx: (cmd:%s,buflen:%u,timeout:%ums,type:0x%04X)\n",
1054 cmdstr
, buflen
, cmd_timeout
,
1055 buffer
? le16_to_cpu(((acx_ie_generic_t
*) buffer
)->type
) : -1);
1057 if (!(adev
->dev_state_mask
& ACX_STATE_FW_LOADED
)) {
1058 printk("acx: %s: " FUNC
"(): firmware is not loaded yet, "
1059 "cannot execute commands!\n", devname
);
1063 if ((acx_debug
& L_DEBUG
) && (cmd
!= ACX1xx_CMD_INTERROGATE
)) {
1064 printk("acx: input buffer (len=%u):\n", buflen
);
1065 acx_dump_bytes(buffer
, buflen
);
1068 /* wait for firmware to become idle for our command submission */
1070 counter
= (timeout
* 1000 / HZ
) - 1; /* in ms */
1073 cmd_status
= acxpci_read_cmd_type_status(adev
);
1074 /* Test for IDLE state */
1077 if (counter
% 8 == 0) {
1078 if (time_after(jiffies
, timeout
)) {
1082 /* we waited 8 iterations, no luck. Sleep 8 ms */
1085 } while (likely(--counter
));
1088 /* the card doesn't get idle, we're in trouble */
1089 printk("acx: %s: " FUNC
"(): cmd_status is not IDLE: 0x%04X!=0\n",
1090 devname
, cmd_status
);
1092 } else if (counter
< 190) { /* if waited >10ms... */
1093 log(L_CTL
| L_DEBUG
, "acx: " FUNC
"(): waited for IDLE %dms. "
1094 "Please report\n", 199 - counter
);
1097 /* now write the parameters of the command if needed */
1098 if (buffer
&& buflen
) {
1099 /* if it's an INTERROGATE command, just pass the length
1100 * of parameters to read, as data */
1102 if (cmd
== ACX1xx_CMD_INTERROGATE
)
1103 memset_io(adev
->cmd_area
+ 4, 0xAA, buflen
);
1105 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1106 memcpy_toio(adev
->cmd_area
+ 4, buffer
,
1107 (cmd
== ACX1xx_CMD_INTERROGATE
) ? 4 : buflen
);
1109 /* now write the actual command type */
1110 acxpci_write_cmd_type_status(adev
, cmd
, 0);
1111 /* execute command */
1112 write_reg16(adev
, IO_ACX_INT_TRIG
, INT_TRIG_CMD
);
1115 /* wait for firmware to process command */
1117 /* Ensure nonzero and not too large timeout.
1118 ** Also converts e.g. 100->99, 200->199
1119 ** which is nice but not essential */
1120 cmd_timeout
= (cmd_timeout
- 1) | 1;
1121 if (unlikely(cmd_timeout
> 1199))
1123 /* clear CMD_COMPLETE bit. can be set only by IRQ handler: */
1124 CLEAR_BIT(adev
->irq_status
, HOST_INT_CMD_COMPLETE
);
1125 /* we schedule away sometimes (timeout can be large) */
1126 counter
= cmd_timeout
;
1127 timeout
= jiffies
+ HZ
;
1129 if (!adev
->irqs_active
) { /* IRQ disabled: poll */
1130 irqtype
= read_reg16(adev
, IO_ACX_IRQ_STATUS_NON_DES
);
1131 if (irqtype
& HOST_INT_CMD_COMPLETE
) {
1132 write_reg16(adev
, IO_ACX_IRQ_ACK
,
1133 HOST_INT_CMD_COMPLETE
);
1136 } else { /* Wait when IRQ will set the bit */
1137 irqtype
= adev
->irq_status
;
1138 if (irqtype
& HOST_INT_CMD_COMPLETE
)
1142 if (counter
% 8 == 0) {
1143 if (time_after(jiffies
, timeout
)) {
1147 /* we waited 8 iterations, no luck. Sleep 8 ms */
1150 } while (likely(--counter
));
1152 /* save state for debugging */
1153 cmd_status
= acxpci_read_cmd_type_status(adev
);
1155 /* put the card in IDLE state */
1156 acxpci_write_cmd_type_status(adev
, 0, 0);
1158 if ((cmd_timeout
- counter
) == 0) { /* timed out! */
1159 printk("acx: %s: " FUNC
"(): timed out %s for CMD_COMPLETE. "
1160 "irq bits:0x%04X irq_status:0x%04X timeout:%dms "
1161 "cmd_status:%d (%s)\n",
1162 devname
, (adev
->irqs_active
) ? "waiting" : "polling",
1163 irqtype
, adev
->irq_status
, cmd_timeout
,
1164 cmd_status
, acx_cmd_status_str(cmd_status
));
1165 printk("acx: hack: don't do: 'goto bad;'\ncounter: %d cmd_timeout: %d cmd_timeout-counter: %d\n",counter
, cmd_timeout
, cmd_timeout
- counter
);
1166 } else if (counter
== 0) { /* maybe timed out! */
1167 log(L_CTL
| L_DEBUG
, "acx: " FUNC
"(): %s for CMD_COMPLETE %dms. "
1168 "count:%d. Please report\n",
1169 (adev
->irqs_active
) ? "waited" : "polled",
1170 cmd_timeout
- counter
, counter
);
1171 } else if ((cmd_timeout
- counter
) > 30) { /* if waited >30ms... */
1172 log(L_CTL
| L_DEBUG
, "acx: " FUNC
"(): %s for CMD_COMPLETE %dms. "
1173 "count:%d. Please report\n",
1174 (adev
->irqs_active
) ? "waited" : "polled",
1175 cmd_timeout
- counter
, counter
);
1178 if (1 != cmd_status
) { /* it is not a 'Success' */
1179 printk("acx: %s: " FUNC
"(): cmd_status is not SUCCESS: %d (%s). "
1180 "Took %dms of %d\n",
1181 devname
, cmd_status
, acx_cmd_status_str(cmd_status
),
1182 cmd_timeout
- counter
, cmd_timeout
);
1183 /* zero out result buffer
1184 * WARNING: this will trash stack in case of illegally large input
1186 if (buffer
&& buflen
)
1187 memset(buffer
, 0, buflen
);
1191 /* read in result parameters if needed */
1192 if (buffer
&& buflen
&& (cmd
== ACX1xx_CMD_INTERROGATE
)) {
1193 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1194 memcpy_fromio(buffer
, adev
->cmd_area
+ 4, buflen
);
1195 if (acx_debug
& L_DEBUG
) {
1196 printk("acx: output buffer (len=%u): ", buflen
);
1197 acx_dump_bytes(buffer
, buflen
);
1201 log(L_CTL
, "acx: " FUNC
"(%s): took %ld jiffies to complete\n",
1202 cmdstr
, jiffies
- start
);
1207 /* Give enough info so that callers can avoid
1208 ** printing their own diagnostic messages */
1210 printk("acx: %s: " FUNC
"(cmd:%s) FAILED\n", devname
, cmdstr
);
1212 printk("acx: %s: " FUNC
"(cmd:0x%04X) FAILED\n", devname
, cmd
);
1220 /***********************************************************************
1222 #ifdef NONESSENTIAL_FEATURES
1223 typedef struct device_id
{
1224 unsigned char id
[6];
1229 static const device_id_t device_ids
[] = {
1231 {'G', 'l', 'o', 'b', 'a', 'l'},
1236 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
1238 "SpeedStream SS1021 or Gigafast WF721-AEX"},
1240 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85},
1242 "DrayTek Vigor 520"},
1244 {'?', '?', '?', '?', '?', '?'},
1246 "Level One WPC-0200"},
1248 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1253 static void acx_show_card_eeprom_id(acx_device_t
* adev
)
1255 unsigned char buffer
[CARD_EEPROM_ID_SIZE
];
1260 memset(&buffer
, 0, CARD_EEPROM_ID_SIZE
);
1261 /* use direct EEPROM access */
1262 for (i
= 0; i
< CARD_EEPROM_ID_SIZE
; i
++) {
1263 if (OK
!= acxpci_read_eeprom_byte(adev
,
1264 ACX100_EEPROM_ID_OFFSET
+ i
,
1266 printk("acx: reading EEPROM FAILED\n");
1271 for (i
= 0; i
< ARRAY_SIZE(device_ids
); i
++) {
1272 if (!memcmp(&buffer
, device_ids
[i
].id
, CARD_EEPROM_ID_SIZE
)) {
1273 if (device_ids
[i
].descr
) {
1274 printk("acx: EEPROM card ID string check "
1275 "found %s card ID: is this %s?\n",
1276 device_ids
[i
].descr
, device_ids
[i
].type
);
1281 if (i
== ARRAY_SIZE(device_ids
)) {
1282 printk("acx: EEPROM card ID string check found "
1283 "unknown card: expected 'Global', got '%.*s\'. "
1284 "Please report\n", CARD_EEPROM_ID_SIZE
, buffer
);
1288 #endif /* NONESSENTIAL_FEATURES */
1291 /***********************************************************************
1292 ** acxpci_free_desc_queues
1294 ** Releases the queues that have been allocated, the
1295 ** others have been initialised to NULL so this
1296 ** function can be used if only part of the queues were allocated.
1300 free_coherent(struct pci_dev
*hwdev
, size_t size
,
1301 void *vaddr
, dma_addr_t dma_handle
)
1303 dma_free_coherent(hwdev
== NULL
? NULL
: &hwdev
->dev
,
1304 size
, vaddr
, dma_handle
);
1308 void acxpci_free_desc_queues(acx_device_t
* adev
)
1310 unsigned long flags
;
1312 #define ACX_FREE_QUEUE(size, ptr, phyaddr) \
1314 free_coherent(NULL, size, ptr, phyaddr); \
1321 ACX_FREE_QUEUE(adev
->txhostdesc_area_size
, adev
->txhostdesc_start
,
1322 adev
->txhostdesc_startphy
);
1323 ACX_FREE_QUEUE(adev
->txbuf_area_size
, adev
->txbuf_start
,
1324 adev
->txbuf_startphy
);
1326 acx_lock(adev
, flags
);
1327 adev
->txdesc_start
= NULL
;
1328 acx_unlock(adev
, flags
);
1330 ACX_FREE_QUEUE(adev
->rxhostdesc_area_size
, adev
->rxhostdesc_start
,
1331 adev
->rxhostdesc_startphy
);
1332 ACX_FREE_QUEUE(adev
->rxbuf_area_size
, adev
->rxbuf_start
,
1333 adev
->rxbuf_startphy
);
1335 acx_lock(adev
, flags
);
1336 adev
->rxdesc_start
= NULL
;
1337 acx_unlock(adev
, flags
);
1343 /***********************************************************************
1344 ** acxpci_s_delete_dma_regions
1346 static void acxpci_s_delete_dma_regions(acx_device_t
* adev
)
1349 /* disable radio Tx/Rx. Shouldn't we use the firmware commands
1350 * here instead? Or are we that much down the road that it's no
1351 * longer possible here? */
1352 write_reg16(adev
, IO_ACX_ENABLE
, 0);
1356 /* NO locking for all parts of acxpci_free_desc_queues because:
1357 * while calling dma_free_coherent() interrupts need to be 'free'
1358 * but if you spinlock the whole function (acxpci_free_desc_queues)
1359 * you'll get an error */
1360 acxpci_free_desc_queues(adev
);
1366 /***********************************************************************
1369 ** Probe routine called when a PCI device w/ matching ID is found.
1370 ** Here's the sequence:
1371 ** - Allocate the PCI resources.
1372 ** - Read the PCMCIA attribute memory to make sure we have a WLAN card
1374 ** - Initialize the dev and wlan data
1375 ** - Initialize the MAC
1377 ** pdev - ptr to pci device structure containing info about pci configuration
1378 ** id - ptr to the device id entry that matched this device
1380 static const u16 IO_ACX100
[] = {
1381 0x0000, /* IO_ACX_SOFT_RESET */
1383 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1384 0x0018, /* IO_ACX_SLV_MEM_DATA */
1385 0x001c, /* IO_ACX_SLV_MEM_CTL */
1386 0x0020, /* IO_ACX_SLV_END_CTL */
1388 0x0034, /* IO_ACX_FEMR */
1390 0x007c, /* IO_ACX_INT_TRIG */
1391 0x0098, /* IO_ACX_IRQ_MASK */
1392 0x00a4, /* IO_ACX_IRQ_STATUS_NON_DES */
1393 0x00a8, /* IO_ACX_IRQ_REASON */
1394 0x00ac, /* IO_ACX_IRQ_ACK */
1395 0x00b0, /* IO_ACX_HINT_TRIG */
1397 0x0104, /* IO_ACX_ENABLE */
1399 0x0250, /* IO_ACX_EEPROM_CTL */
1400 0x0254, /* IO_ACX_EEPROM_ADDR */
1401 0x0258, /* IO_ACX_EEPROM_DATA */
1402 0x025c, /* IO_ACX_EEPROM_CFG */
1404 0x0268, /* IO_ACX_PHY_ADDR */
1405 0x026c, /* IO_ACX_PHY_DATA */
1406 0x0270, /* IO_ACX_PHY_CTL */
1408 0x0290, /* IO_ACX_GPIO_OE */
1410 0x0298, /* IO_ACX_GPIO_OUT */
1412 0x02a4, /* IO_ACX_CMD_MAILBOX_OFFS */
1413 0x02a8, /* IO_ACX_INFO_MAILBOX_OFFS */
1414 0x02ac, /* IO_ACX_EEPROM_INFORMATION */
1416 0x02d0, /* IO_ACX_EE_START */
1417 0x02d4, /* IO_ACX_SOR_CFG */
1418 0x02d8 /* IO_ACX_ECPU_CTRL */
1421 static const u16 IO_ACX111
[] = {
1422 0x0000, /* IO_ACX_SOFT_RESET */
1424 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1425 0x0018, /* IO_ACX_SLV_MEM_DATA */
1426 0x001c, /* IO_ACX_SLV_MEM_CTL */
1427 0x0020, /* IO_ACX_SLV_END_CTL */
1429 0x0034, /* IO_ACX_FEMR */
1431 0x00b4, /* IO_ACX_INT_TRIG */
1432 0x00d4, /* IO_ACX_IRQ_MASK */
1433 /* we do mean NON_DES (0xf0), not NON_DES_MASK which is at 0xe0: */
1434 0x00f0, /* IO_ACX_IRQ_STATUS_NON_DES */
1435 0x00e4, /* IO_ACX_IRQ_REASON */
1436 0x00e8, /* IO_ACX_IRQ_ACK */
1437 0x00ec, /* IO_ACX_HINT_TRIG */
1439 0x01d0, /* IO_ACX_ENABLE */
1441 0x0338, /* IO_ACX_EEPROM_CTL */
1442 0x033c, /* IO_ACX_EEPROM_ADDR */
1443 0x0340, /* IO_ACX_EEPROM_DATA */
1444 0x0344, /* IO_ACX_EEPROM_CFG */
1446 0x0350, /* IO_ACX_PHY_ADDR */
1447 0x0354, /* IO_ACX_PHY_DATA */
1448 0x0358, /* IO_ACX_PHY_CTL */
1450 0x0374, /* IO_ACX_GPIO_OE */
1452 0x037c, /* IO_ACX_GPIO_OUT */
1454 0x0388, /* IO_ACX_CMD_MAILBOX_OFFS */
1455 0x038c, /* IO_ACX_INFO_MAILBOX_OFFS */
1456 0x0390, /* IO_ACX_EEPROM_INFORMATION */
1458 0x0100, /* IO_ACX_EE_START */
1459 0x0104, /* IO_ACX_SOR_CFG */
1460 0x0108, /* IO_ACX_ECPU_CTRL */
1463 static const struct ieee80211_ops acxpci_hw_ops
= {
1464 .tx
= acx_i_start_xmit
,
1465 .conf_tx
= acx_net_conf_tx
,
1466 .add_interface
= acx_add_interface
,
1467 .remove_interface
= acx_remove_interface
,
1468 .start
= acxpci_e_open
,
1469 .configure_filter
= acx_i_set_multicast_list
,
1470 .stop
= acxpci_e_close
,
1471 .config
= acx_net_config
,
1472 .config_interface
= acx_config_interface
,
1473 .set_key
= acx_net_set_key
,
1474 .get_stats
= acx_e_get_stats
,
1475 .get_tx_stats
= acx_net_get_tx_stats
,
1480 static int __devinit
1481 acxpci_e_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1483 acx111_ie_configoption_t co
;
1484 unsigned long mem_region1
= 0;
1485 unsigned long mem_region2
= 0;
1486 unsigned long mem_region1_size
;
1487 unsigned long mem_region2_size
;
1488 unsigned long phymem1
;
1489 unsigned long phymem2
;
1492 acx_device_t
*adev
= NULL
;
1493 const char *chip_name
;
1497 struct ieee80211_hw
*ieee
;
1501 ieee
= ieee80211_alloc_hw(sizeof(struct acx_device
), &acxpci_hw_ops
);
1503 printk("acx: could not allocate ieee80211 structure %s\n",
1505 goto fail_alloc_netdev
;
1507 ieee
->flags
&= ~IEEE80211_HW_RX_INCLUDES_FCS
;
1508 /* TODO: mainline doesn't support the following flags yet */
1510 ~IEEE80211_HW_MONITOR_DURING_OPER &
1511 ~IEEE80211_HW_WEP_INCLUDE_IV;
1515 /* TODO: although in the original driver the maximum value was 100,
1516 * the OpenBSD driver assigns maximum values depending on the type of
1517 * radio transceiver (i.e. Radia, Maxim, etc.). This value is always a
1518 * positive integer which most probably indicates the gain of the AGC
1519 * in the rx path of the chip, in dB steps (0.625 dB, for example?).
1520 * The mapping of this rssi value to dBm is still unknown, but it can
1521 * nevertheless be used as a measure of relative signal strength. The
1522 * other two values, i.e. max_signal and max_noise, do not seem to be
1523 * supported on my acx111 card (they are always 0), although iwconfig
1524 * reports them (in dBm) when using ndiswrapper with the Windows XP
1525 * driver. The GPL-licensed part of the AVM FRITZ!WLAN USB Stick
1526 * driver sources (for the TNETW1450, though) seems to also indicate
1527 * that only the RSSI is supported. In conclusion, the max_signal and
1528 * max_noise values will not be initialised by now, as they do not
1529 * seem to be supported or how to acquire them is still unknown. */
1530 ieee
->max_rssi
= 100;
1532 adev
= ieee2adev(ieee
);
1534 memset(adev
, 0, sizeof(*adev
));
1535 /** Set up our private interface **/
1536 spin_lock_init(&adev
->spinlock
); /* initial state: unlocked */
1537 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
1538 printk("acx: mutex_init(&adev->mutex); // adev = 0x%px\n", adev
);
1539 mutex_init(&adev
->mutex
);
1540 /* since nobody can see new netdev yet, we can as well
1541 ** just _presume_ that we're under sem (instead of actually taking it): */
1542 /* acx_sem_lock(adev); */
1545 adev
->bus_dev
= &pdev
->dev
;
1546 adev
->dev_type
= DEVTYPE_PCI
;
1548 /** Finished with private interface **/
1550 /** begin board specific inits **/
1551 pci_set_drvdata(pdev
, ieee
);
1553 /* Enable the PCI device */
1554 if (pci_enable_device(pdev
)) {
1555 printk("acx: pci_enable_device() FAILED\n");
1557 goto fail_pci_enable_device
;
1560 /* enable busmastering (required for CardBus) */
1561 pci_set_master(pdev
);
1564 /* chiptype is u8 but id->driver_data is ulong
1565 ** Works for now (possible values are 1 and 2) */
1566 chip_type
= (u8
) id
->driver_data
;
1567 /* acx100 and acx111 have different PCI memory regions */
1568 if (chip_type
== CHIPTYPE_ACX100
) {
1569 chip_name
= "ACX100";
1570 mem_region1
= PCI_ACX100_REGION1
;
1571 mem_region1_size
= PCI_ACX100_REGION1_SIZE
;
1573 mem_region2
= PCI_ACX100_REGION2
;
1574 mem_region2_size
= PCI_ACX100_REGION2_SIZE
;
1575 } else if (chip_type
== CHIPTYPE_ACX111
) {
1576 chip_name
= "ACX111";
1577 mem_region1
= PCI_ACX111_REGION1
;
1578 mem_region1_size
= PCI_ACX111_REGION1_SIZE
;
1580 mem_region2
= PCI_ACX111_REGION2
;
1581 mem_region2_size
= PCI_ACX111_REGION2_SIZE
;
1583 printk("acx: unknown chip type 0x%04X\n", chip_type
);
1584 goto fail_unknown_chiptype
;
1587 /* Figure out our resources
1589 * Request our PCI IO regions
1591 err
= pci_request_region(pdev
, mem_region1
, "acx_1");
1593 printk(KERN_WARNING
"acx: pci_request_region (1/2) FAILED!"
1594 "No cardbus support in kernel?\n");
1595 goto fail_request_mem_region1
;
1598 phymem1
= pci_resource_start(pdev
, mem_region1
);
1600 err
= pci_request_region(pdev
, mem_region2
, "acx_2");
1602 printk(KERN_WARNING
"acx: pci_request_region (2/2) FAILED!\n");
1603 goto fail_request_mem_region2
;
1606 phymem2
= pci_resource_start(pdev
, mem_region2
);
1609 * We got them? Map them!
1611 * We pass 0 as the third argument to pci_iomap(): it will map the full
1612 * region in this case, which is what we want.
1615 mem1
= pci_iomap(pdev
, mem_region1
, 0);
1617 printk(KERN_WARNING
"acx: ioremap() FAILED\n");
1621 mem2
= pci_iomap(pdev
, mem_region2
, 0);
1623 printk(KERN_WARNING
"acx: ioremap() #2 FAILED\n");
1627 printk("acx: found an %s-based wireless network card at %s, irq:%d, "
1628 "phymem1:0x%lX, phymem2:0x%lX, mem1:0x%p, mem1_size:%ld, "
1629 "mem2:0x%p, mem2_size:%ld\n",
1630 chip_name
, pci_name(pdev
), pdev
->irq
, phymem1
, phymem2
,
1631 mem1
, mem_region1_size
, mem2
, mem_region2_size
);
1632 log(L_ANY
, "acx: the initial debug setting is 0x%04X\n", acx_debug
);
1633 adev
->chip_type
= chip_type
;
1634 adev
->chip_name
= chip_name
;
1635 adev
->io
= (CHIPTYPE_ACX100
== chip_type
) ? IO_ACX100
: IO_ACX111
;
1636 adev
->membase
= phymem1
;
1637 adev
->iobase
= mem1
;
1638 adev
->membase2
= phymem2
;
1639 adev
->iobase2
= mem2
;
1640 adev
->irq
= pdev
->irq
;
1643 if (0 == pdev
->irq
) {
1644 printk("acx: can't use IRQ 0\n");
1647 SET_IEEE80211_DEV(ieee
, &pdev
->dev
);
1649 /* request shared IRQ handler */
1651 (adev
->irq
, acxpci_i_interrupt
, IRQF_SHARED
, KBUILD_MODNAME
, adev
)) {
1652 printk("acx: %s: request_irq FAILED\n", wiphy_name(adev
->ieee
->wiphy
));
1656 log(L_DEBUG
| L_IRQ
, "acx: request_irq %d successful\n", adev
->irq
);
1658 /* to find crashes due to weird driver access
1659 * to unconfigured interface (ifup) */
1660 adev
->mgmt_timer
.function
= (void (*)(unsigned long))0x0000dead;
1663 #ifdef NONESSENTIAL_FEATURES
1664 acx_show_card_eeprom_id(adev
);
1665 #endif /* NONESSENTIAL_FEATURES */
1668 /* ok, pci setup is finished, now start initializing the card */
1670 /* NB: read_reg() reads may return bogus data before reset_dev(),
1671 * since the firmware which directly controls large parts of the I/O
1672 * registers isn't initialized yet.
1673 * acx100 seems to be more affected than acx111 */
1674 if (OK
!= acxpci_s_reset_dev(adev
))
1677 if (IS_ACX100(adev
)) {
1678 /* ACX100: configopt struct in cmd mailbox - directly after reset */
1679 memcpy_fromio(&co
, adev
->cmd_area
, sizeof(co
));
1682 if (OK
!= acx_s_init_mac(adev
))
1685 if (IS_ACX111(adev
)) {
1686 /* ACX111: configopt struct needs to be queried after full init */
1687 acx_s_interrogate(adev
, &co
, ACX111_IE_CONFIG_OPTIONS
);
1689 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
1690 if (OK
!= acxpci_read_eeprom_byte(adev
, 0x05, &adev
->eeprom_version
))
1691 goto fail_read_eeprom_version
;
1693 acx_s_parse_configoption(adev
, &co
);
1694 acx_s_set_defaults(adev
);
1695 acx_s_get_firmware_version(adev
); /* needs to be after acx_s_init_mac() */
1696 acx_display_hardware_details(adev
);
1698 /* Register the card, AFTER everything else has been set up,
1699 * since otherwise an ioctl could step on our feet due to
1700 * firmware operations happening in parallel or uninitialized data */
1703 acx_proc_register_entries(ieee
);
1705 /* Now we have our device, so make sure the kernel doesn't try
1706 * to send packets even though we're not associated to a network yet */
1708 /* after register_netdev() userspace may start working with dev
1709 * (in particular, on other CPUs), we only need to up the sem */
1710 /* acx_sem_unlock(adev); */
1712 printk("acx: acx " ACX_RELEASE
": net device %s, driver compiled "
1713 "against wireless extensions %d and Linux %s\n",
1714 wiphy_name(adev
->ieee
->wiphy
), WIRELESS_EXT
, UTS_RELEASE
);
1716 MAC_COPY(adev
->ieee
->wiphy
->perm_addr
, adev
->dev_addr
);
1718 log(L_IRQ
| L_INIT
, "acx: using IRQ %d\n", pdev
->irq
);
1720 /** done with board specific setup **/
1722 /* need to be able to restore PCI state after a suspend */
1724 pci_save_state(pdev
);
1727 err
= acx_setup_modes(adev
);
1729 printk("acx: can't register hwmode\n");
1730 goto fail_register_netdev
;
1733 acx_init_task_scheduler(adev
);
1734 err
= ieee80211_register_hw(ieee
);
1736 printk("acx: ieee80211_register_hw() FAILED: %d\n", err
);
1737 goto fail_register_netdev
;
1740 great_inquisitor(adev
);
1746 /* error paths: undo everything in reverse order... */
1749 acxpci_s_delete_dma_regions(adev
);
1750 pci_set_drvdata(pdev
, NULL
);
1753 fail_read_eeprom_version
:
1758 pci_iounmap(pdev
, mem2
);
1761 pci_iounmap(pdev
, mem1
);
1764 pci_release_region(pdev
, mem_region2
);
1766 fail_request_mem_region2
:
1767 pci_release_region(pdev
, mem_region1
);
1769 fail_request_mem_region1
:
1770 fail_unknown_chiptype
:
1771 pci_disable_device(pdev
);
1773 fail_pci_enable_device
:
1775 pci_set_power_state(pdev
, PCI_D3hot
);
1778 fail_register_netdev
:
1779 ieee80211_free_hw(ieee
);
1786 /***********************************************************************
1789 ** Shut device down (if not hot unplugged)
1790 ** and deallocate PCI resources for the acx chip.
1792 ** pdev - ptr to PCI device structure containing info about pci configuration
1794 static void __devexit
acxpci_e_remove(struct pci_dev
*pdev
)
1796 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*)pci_get_drvdata(pdev
);
1797 acx_device_t
*adev
= ieee2adev(hw
);
1798 unsigned long mem_region1
, mem_region2
;
1799 unsigned long flags
;
1803 log(L_DEBUG
, "acx: %s: card is unused. Skipping any release code\n",
1808 /* If device wasn't hot unplugged... */
1809 if (adev_present(adev
)) {
1811 /* disable both Tx and Rx to shut radio down properly */
1812 if (adev
->initialized
) {
1813 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_TX
, NULL
, 0);
1814 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_RX
, NULL
, 0);
1815 adev
->initialized
= 0;
1818 /* put the eCPU to sleep to save power
1819 * Halting is not possible currently,
1820 * since not supported by all firmware versions */
1821 acx_s_issue_cmd(adev
, ACX100_CMD_SLEEP
, NULL
, 0);
1823 acx_lock(adev
, flags
);
1824 /* disable power LED to save power :-) */
1825 log(L_INIT
, "acx: switching off power LED to save power\n");
1826 acxpci_l_power_led(adev
, 0);
1828 if (IS_ACX111(adev
)) {
1829 /* FIXME: does this actually keep halting the eCPU?
1830 * I don't think so...
1832 acxpci_l_reset_mac(adev
);
1836 temp
= read_reg16(adev
, IO_ACX_ECPU_CTRL
) | 0x1;
1837 write_reg16(adev
, IO_ACX_ECPU_CTRL
, temp
);
1840 acx_unlock(adev
, flags
);
1844 /* unregister the device to not let the kernel
1845 * (e.g. ioctls) access a half-deconfigured device
1846 * NB: this will cause acxpci_e_close() to be called,
1847 * thus we shouldn't call it under sem!
1849 // acxpci_e_close(hw);
1850 log(L_INIT
, "acx: removing device %s\n", wiphy_name(adev
->ieee
->wiphy
));
1851 ieee80211_unregister_hw(adev
->ieee
);
1853 /* unregister_netdev ensures that no references to us left.
1854 * For paranoid reasons we continue to follow the rules */
1857 if (adev
->dev_state_mask
& ACX_STATE_IFACE_UP
) {
1859 CLEAR_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
1862 acx_proc_unregister_entries(adev
->ieee
);
1864 if (IS_ACX100(adev
)) {
1865 mem_region1
= PCI_ACX100_REGION1
;
1866 mem_region2
= PCI_ACX100_REGION2
;
1868 mem_region1
= PCI_ACX111_REGION1
;
1869 mem_region2
= PCI_ACX111_REGION2
;
1872 /* finally, clean up PCI bus state */
1873 acxpci_s_delete_dma_regions(adev
);
1875 iounmap(adev
->iobase
);
1877 iounmap(adev
->iobase2
);
1878 release_mem_region(pci_resource_start(pdev
, mem_region1
),
1879 pci_resource_len(pdev
, mem_region1
));
1880 release_mem_region(pci_resource_start(pdev
, mem_region2
),
1881 pci_resource_len(pdev
, mem_region2
));
1882 pci_disable_device(pdev
);
1884 /* remove dev registration */
1885 pci_set_drvdata(pdev
, NULL
);
1887 acx_sem_unlock(adev
);
1889 /* Free netdev (quite late,
1890 * since otherwise we might get caught off-guard
1891 * by a netdev timeout handler execution
1892 * expecting to see a working dev...) */
1893 ieee80211_free_hw(adev
->ieee
);
1895 /* put device into ACPI D3 mode (shutdown) */
1897 pci_set_power_state(pdev
, PCI_D3hot
);
1904 /***********************************************************************
1905 ** TODO: PM code needs to be fixed / debugged / tested.
1909 acxpci_e_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1911 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
1915 printk("acx: suspend handler is experimental!\n");
1916 printk("acx: sus: dev %p\n", hw
);
1918 /* if (!netif_running(ndev))
1921 adev
= ieee2adev(hw
);
1922 printk("acx: sus: adev %p\n", adev
);
1926 ieee80211_unregister_hw(hw
); /* this one cannot sleep */
1928 /* down() does not set it to 0xffff, but here we really want that */
1929 write_reg16(adev
, IO_ACX_IRQ_MASK
, 0xffff);
1930 write_reg16(adev
, IO_ACX_FEMR
, 0x0);
1931 acxpci_s_delete_dma_regions(adev
);
1932 pci_save_state(pdev
);
1933 pci_set_power_state(pdev
, PCI_D3hot
);
1935 acx_sem_unlock(adev
);
1941 static int acxpci_e_resume(struct pci_dev
*pdev
)
1943 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
1948 printk("acx: resume handler is experimental!\n");
1949 printk("acx: rsm: got dev %p\n", hw
);
1952 adev
= ieee2adev(hw
);
1953 printk("acx: rsm: got adev %p\n", adev
);
1957 pci_set_power_state(pdev
, PCI_D0
);
1958 printk("acx: rsm: power state PCI_D0 set\n");
1959 pci_restore_state(pdev
);
1960 printk("acx: rsm: PCI state restored\n");
1962 if (OK
!= acxpci_s_reset_dev(adev
))
1964 printk("acx: rsm: device reset done\n");
1965 if (OK
!= acx_s_init_mac(adev
))
1967 printk("acx: rsm: init MAC done\n");
1970 printk("acx: rsm: acx up done\n");
1972 /* now even reload all card parameters as they were before suspend,
1973 * and possibly be back in the network again already :-) */
1974 if (ACX_STATE_IFACE_UP
& adev
->dev_state_mask
) {
1975 adev
->set_mask
= GETSET_ALL
;
1976 acx_s_update_card_settings(adev
);
1977 printk("acx: rsm: settings updated\n");
1979 ieee80211_register_hw(hw
);
1980 printk("acx: rsm: device attached\n");
1983 acx_sem_unlock(adev
);
1984 /* we need to return OK here anyway, right? */
1988 #endif /* CONFIG_PM */
1989 #endif /* CONFIG_PCI */
1991 /***********************************************************************
1994 ** This function is called by acxpci_e_open (when ifconfig sets the device as up)
1997 ** - Enables on-card interrupt requests
1998 ** - calls acx_s_start
2001 static void enable_acx_irq(acx_device_t
* adev
)
2004 write_reg16(adev
, IO_ACX_IRQ_MASK
, adev
->irq_mask
);
2005 write_reg16(adev
, IO_ACX_FEMR
, 0x8000);
2006 adev
->irqs_active
= 1;
2010 static void acxpci_s_up(struct ieee80211_hw
*hw
)
2012 acx_device_t
*adev
= ieee2adev(hw
);
2013 unsigned long flags
;
2017 acx_lock(adev
, flags
);
2018 enable_acx_irq(adev
);
2019 acx_unlock(adev
, flags
);
2021 /* acx fw < 1.9.3.e has a hardware timer, and older drivers
2022 ** used to use it. But we don't do that anymore, our OS
2023 ** has reliable software timers */
2024 init_timer(&adev
->mgmt_timer
);
2025 adev
->mgmt_timer
.function
= acx_i_timer
;
2026 adev
->mgmt_timer
.data
= (unsigned long)adev
;
2028 /* Need to set ACX_STATE_IFACE_UP first, or else
2029 ** timer won't be started by acx_set_status() */
2030 SET_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
2038 /***********************************************************************
2041 ** NB: device may be already hot unplugged if called from acxpci_e_remove()
2043 ** Disables on-card interrupt request, stops softirq and timer, stops queue,
2044 ** sets status == STOPPED
2047 static void disable_acx_irq(acx_device_t
* adev
)
2051 /* I guess mask is not 0xffff because acx100 won't signal
2052 ** cmd completion then (needed for ifup).
2053 ** I can't ifconfig up after ifconfig down'ing on my acx100 */
2054 write_reg16(adev
, IO_ACX_IRQ_MASK
, adev
->irq_mask_off
);
2055 write_reg16(adev
, IO_ACX_FEMR
, 0x0);
2056 adev
->irqs_active
= 0;
2061 static void acxpci_s_down(struct ieee80211_hw
*hw
)
2063 acx_device_t
*adev
= ieee2adev(hw
);
2067 /* Disable IRQs first, so that IRQs cannot race with us */
2068 /* then wait until interrupts have finished executing on other CPUs */
2069 disable_acx_irq(adev
); /* NO sem-locking here? */
2070 synchronize_irq(adev
->irq
);
2072 /* we really don't want to have an asynchronous tasklet disturb us
2073 ** after something vital for its job has been shut down, so
2074 ** end all remaining work now.
2076 ** NB: carrier_off (done by set_status below) would lead to
2077 ** not yet fully understood deadlock in flush_scheduled_work().
2078 ** That's why we do FLUSH first.
2080 ** NB2: we have a bad locking bug here: flush_scheduled_work()
2081 ** waits for acx_e_after_interrupt_task to complete if it is running
2082 ** on another CPU, but acx_e_after_interrupt_task
2083 ** will sleep on sem forever, because it is taken by us!
2084 ** Work around that by temporary sem unlock.
2085 ** This will fail miserably if we'll be hit by concurrent
2086 ** iwconfig or something in between. TODO! */
2087 acx_sem_unlock(adev
);
2088 flush_scheduled_work();
2091 /* This is possible:
2092 ** flush_scheduled_work -> acx_e_after_interrupt_task ->
2093 ** -> set_status(ASSOCIATED) -> wake_queue()
2094 ** That's why we stop queue _after_ flush_scheduled_work
2095 ** lock/unlock is just paranoia, maybe not needed */
2097 /* kernel/timer.c says it's illegal to del_timer_sync()
2098 ** a timer which restarts itself. We guarantee this cannot
2099 ** ever happen because acx_i_timer() never does this if
2100 ** status is ACX_STATUS_0_STOPPED */
2101 del_timer_sync(&adev
->mgmt_timer
);
2106 #ifdef CONFIG_NET_POLL_CONTROLLER
2107 void acxpci_net_poll_controller(struct net_device *net_dev)
2109 acx_device_t *adev = ndev2adev(net_dev);
2110 unsigned long flags;
2112 local_irq_save(flags);
2113 acxpci_i_interrupt(adev->irq, adev);
2114 local_irq_restore(flags);
2116 #endif*/ /* CONFIG_NET_POLL_CONTROLLER */
2118 /***********************************************************************
2121 ** Called as a result of SIOCSIFFLAGS ioctl changing the flags bit IFF_UP
2122 ** from clear to set. In other words: ifconfig up.
2126 ** >0 f/w reported error
2127 ** <0 driver reported error
2129 static int acxpci_e_open(struct ieee80211_hw
*hw
)
2131 acx_device_t
*adev
= ieee2adev(hw
);
2138 adev
->initialized
= 0;
2140 /* TODO: pci_set_power_state(pdev, PCI_D0); ? */
2145 /* We don't currently have to do anything else.
2146 * The setup of the MAC should be subsequently completed via
2147 * the mlme commands.
2148 * Higher layers know we're ready from dev->start==1 and
2149 * dev->tbusy==0. Our rx path knows to pass up received/
2150 * frames because of dev->flags&IFF_UP is true.
2152 ieee80211_start_queues(adev
->ieee
);
2154 adev
->initialized
= 1;
2155 acx_sem_unlock(adev
);
2162 /***********************************************************************
2165 ** This function stops the network functionality of the interface (invoked
2166 ** when the user calls ifconfig <wlan> down). The tx queue is halted and
2167 ** the device is marked as down.
2169 ** Called as a result of SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
2170 ** from set to clear. I.e. called by "ifconfig DEV down"
2174 ** >0 f/w reported error
2175 ** <0 driver reported error
2177 static void acxpci_e_close(struct ieee80211_hw
*hw
)
2179 acx_device_t
*adev
= ieee2adev(hw
);
2186 CLEAR_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
2187 if (adev
->initialized
) {
2191 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,24)
2193 acx_free_modes(adev
);
2195 /* disable all IRQs, release shared IRQ handler */
2196 write_reg16(adev
, IO_ACX_IRQ_MASK
, 0xffff);
2197 write_reg16(adev
, IO_ACX_FEMR
, 0x0);
2199 /* TODO: pci_set_power_state(pdev, PCI_D3hot); ? */
2201 /* We currently don't have to do anything else.
2202 * Higher layers know we're not ready from dev->start==0 and
2203 * dev->tbusy==1. Our rx path knows to not pass up received
2204 * frames because of dev->flags&IFF_UP is false.
2206 acx_sem_unlock(adev
);
2208 log(L_INIT
, "acx: closed device\n");
2215 /***************************************************************
2216 ** acxpci_l_process_rxdesc
2218 ** Called directly and only from the IRQ handler
2222 static inline void log_rxbuffer(const acx_device_t
* adev
)
2226 static void log_rxbuffer(const acx_device_t
* adev
)
2228 register const struct rxhostdesc
*rxhostdesc
;
2231 /* no FN_ENTER here, we don't want that */
2233 rxhostdesc
= adev
->rxhostdesc_start
;
2234 if (unlikely(!rxhostdesc
))
2236 for (i
= 0; i
< RX_CNT
; i
++) {
2237 if ((rxhostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
2238 && (rxhostdesc
->Status
& cpu_to_le32(DESC_STATUS_FULL
)))
2239 printk("acx: rx: buf %d full\n", i
);
2245 static void acxpci_l_process_rxdesc(acx_device_t
* adev
)
2247 register rxhostdesc_t
*hostdesc
;
2248 unsigned count
, tail
;
2252 if (unlikely(acx_debug
& L_BUFR
))
2255 /* First, have a loop to determine the first descriptor that's
2256 * full, just in case there's a mismatch between our current
2257 * rx_tail and the full descriptor we're supposed to handle. */
2258 tail
= adev
->rx_tail
;
2261 hostdesc
= &adev
->rxhostdesc_start
[tail
];
2262 /* advance tail regardless of outcome of the below test */
2263 tail
= (tail
+ 1) % RX_CNT
;
2265 if ((hostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
2266 && (hostdesc
->Status
& cpu_to_le32(DESC_STATUS_FULL
)))
2267 break; /* found it! */
2269 if (unlikely(!--count
)) /* hmm, no luck: all descs empty, bail out */
2273 /* now process descriptors, starting with the first we figured out */
2275 log(L_BUFR
, "acx: rx: tail=%u Ctl_16=%04X Status=%08X\n",
2276 tail
, hostdesc
->Ctl_16
, hostdesc
->Status
);
2278 acx_l_process_rxbuf(adev
, hostdesc
->data
);
2279 hostdesc
->Status
= 0;
2280 /* flush all writes before adapter sees CTL_HOSTOWN change */
2282 /* Host no longer owns this, needs to be LAST */
2283 CLEAR_BIT(hostdesc
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
2285 /* ok, descriptor is handled, now check the next descriptor */
2286 hostdesc
= &adev
->rxhostdesc_start
[tail
];
2288 /* if next descriptor is empty, then bail out */
2289 if (!(hostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
2290 || !(hostdesc
->Status
& cpu_to_le32(DESC_STATUS_FULL
)))
2293 tail
= (tail
+ 1) % RX_CNT
;
2296 adev
->rx_tail
= tail
;
2302 /***********************************************************************
2303 ** acxpci_i_interrupt
2305 ** IRQ handler (atomic context, must not sleep, blah, blah)
2308 /* scan is complete. all frames now on the receive queue are valid */
2309 #define INFO_SCAN_COMPLETE 0x0001
2310 #define INFO_WEP_KEY_NOT_FOUND 0x0002
2311 /* hw has been reset as the result of a watchdog timer timeout */
2312 #define INFO_WATCH_DOG_RESET 0x0003
2313 /* failed to send out NULL frame from PS mode notification to AP */
2314 /* recommended action: try entering 802.11 PS mode again */
2315 #define INFO_PS_FAIL 0x0004
2316 /* encryption/decryption process on a packet failed */
2317 #define INFO_IV_ICV_FAILURE 0x0005
2319 /* Info mailbox format:
2322 more bytes may follow
2323 rumors say about status:
2324 0x0000 info available (set by hw)
2325 0x0001 information received (must be set by host)
2326 0x1000 info available, mailbox overflowed (messages lost) (set by hw)
2327 but in practice we've seen:
2328 0x9000 when we did not set status to 0x0001 on prev message
2329 0x1001 when we did set it
2330 0x0000 was never seen
2331 conclusion: this is really a bitfield:
2332 0x1000 is 'info available' bit
2333 'mailbox overflowed' bit is 0x8000, not 0x1000
2334 value of 0x0000 probably means that there are no messages at all
2335 P.S. I dunno how in hell hw is supposed to notice that messages are lost -
2336 it does NOT clear bit 0x0001, and this bit will probably stay forever set
2337 after we set it once. Let's hope this will be fixed in firmware someday
2340 static void handle_info_irq(acx_device_t
* adev
)
2343 static const char *const info_type_msg
[] = {
2346 "WEP key not found",
2347 "internal watchdog reset was done",
2348 "failed to send powersave (NULL frame) notification to AP",
2349 "encrypt/decrypt on a packet has failed",
2350 "TKIP tx keys disabled",
2351 "TKIP rx keys disabled",
2352 "TKIP rx: key ID not found",
2360 "TKIP IV value exceeds thresh"
2363 u32 info_type
, info_status
;
2365 info_type
= acx_readl(adev
->info_area
);
2366 info_status
= (info_type
>> 16);
2367 info_type
= (u16
) info_type
;
2369 /* inform fw that we have read this info message */
2370 acx_writel(info_type
| 0x00010000, adev
->info_area
);
2371 write_reg16(adev
, IO_ACX_INT_TRIG
, INT_TRIG_INFOACK
);
2374 log(L_CTL
, "acx: info_type:%04X info_status:%04X\n", info_type
, info_status
);
2376 log(L_IRQ
, "acx: got Info IRQ: status %04X type %04X: %s\n",
2377 info_status
, info_type
,
2378 info_type_msg
[(info_type
>= ARRAY_SIZE(info_type_msg
)) ?
2384 static void log_unusual_irq(u16 irqtype
)
2387 if (!printk_ratelimit())
2392 if (irqtype
& HOST_INT_RX_DATA
) {
2393 printk("acx: Rx_Data");
2395 /* HOST_INT_TX_COMPLETE */
2396 if (irqtype
& HOST_INT_TX_XFER
) {
2397 printk("acx: Tx_Xfer");
2399 /* HOST_INT_RX_COMPLETE */
2400 if (irqtype
& HOST_INT_DTIM
) {
2401 printk("acx: DTIM");
2403 if (irqtype
& HOST_INT_BEACON
) {
2404 printk("acx: Beacon");
2406 if (irqtype
& HOST_INT_TIMER
) {
2407 log(L_IRQ
, "acx: Timer");
2409 if (irqtype
& HOST_INT_KEY_NOT_FOUND
) {
2410 printk("acx: Key_Not_Found");
2412 if (irqtype
& HOST_INT_IV_ICV_FAILURE
) {
2413 printk("acx: IV_ICV_Failure (crypto)");
2415 /* HOST_INT_CMD_COMPLETE */
2417 if (irqtype
& HOST_INT_OVERFLOW
) {
2418 printk("acx: Overflow");
2420 if (irqtype
& HOST_INT_PROCESS_ERROR
) {
2421 printk("acx: Process_Error");
2423 /* HOST_INT_SCAN_COMPLETE */
2424 if (irqtype
& HOST_INT_FCS_THRESHOLD
) {
2425 printk("acx: FCS_Threshold");
2427 if (irqtype
& HOST_INT_UNKNOWN
) {
2428 printk("acx: Unknown");
2430 printk("acx: IRQ(s)\n");
2433 /* FIXME: update_link_quality_led was a stub - let's comment it and avoid
2434 * compiler warnings */
2436 static void update_link_quality_led(acx_device_t * adev)
2441 acx_signal_determine_quality(adev->wstats.qual.level,
2442 adev->wstats.qual.noise);
2443 if (qual > adev->brange_max_quality)
2444 qual = adev->brange_max_quality;
2446 if (time_after(jiffies, adev->brange_time_last_state_change +
2448 HZ / 2 * (unsigned long)qual /
2449 adev->brange_max_quality))) {
2450 acxpci_l_power_led(adev, (adev->brange_last_state == 0));
2451 adev->brange_last_state ^= 1; // toggle
2452 adev->brange_time_last_state_change = jiffies;
2457 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* a la orinoco.c */
2459 /* Interrupt handler bottom-half */
2460 void acx_interrupt_tasklet(struct work_struct
*work
)
2463 #ifdef CONFIG_ACX_MAC80211_DEBUG
2464 u32 _handled
= 0x00000000;
2465 # define acxirq_handled(irq) do { _handled |= (irq); } while (0)
2467 # define acxirq_handled(irq) do { /* nothing */ } while (0)
2468 #endif /* CONFIG_ACX_MAC80211_DEBUG */
2469 acx_device_t
*adev
= container_of(work
,struct acx_device
, after_interrupt_task
);
2470 // unsigned int irqcount = MAX_IRQLOOPS_PER_JIFFY;
2473 #define IRQ_ITERATE 0
2475 unsigned int irqcount
= MAX_IRQLOOPS_PER_JIFFY
;
2481 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2485 irqtype
= adev
->irq_reason
;
2486 adev
->irq_reason
= 0;
2489 if (jiffies
!= adev
->irq_last_jiffies
) {
2490 adev
->irq_loops_this_jiffy
= 0;
2491 adev
->irq_last_jiffies
= jiffies
;
2494 /* safety condition; we'll normally abort loop below
2495 * in case no IRQ type occurred */
2496 while (likely(--irqcount
)) {
2498 /* ACK all IRQs ASAP */
2500 /* Handle most important IRQ types first */
2501 if (irqtype
& HOST_INT_RX_COMPLETE
) {
2502 log(L_IRQ
, "acx: got Rx_Complete IRQ\n");
2503 acxpci_l_process_rxdesc(adev
);
2505 if (irqtype
& HOST_INT_TX_COMPLETE
) {
2506 log(L_IRQ
, "acx: got Tx_Complete IRQ\n");
2507 /* don't clean up on each Tx complete, wait a bit
2508 * unless we're going towards full, in which case
2509 * we do it immediately, too (otherwise we might lockup
2510 * with a full Tx buffer if we go into
2511 * acxpci_l_clean_txdesc() at a time when we won't wakeup
2512 * the net queue in there for some reason...) */
2513 // if (adev->tx_free <= TX_START_CLEAN) {
2514 acxpci_l_clean_txdesc(adev
);
2518 /* Less frequent ones */
2520 | HOST_INT_CMD_COMPLETE
2521 | HOST_INT_INFO
| HOST_INT_SCAN_COMPLETE
)) {
2522 if (irqtype
& HOST_INT_INFO
) {
2523 handle_info_irq(adev
);
2525 if (irqtype
& HOST_INT_SCAN_COMPLETE
) {
2526 log(L_IRQ
, "acx: got Scan_Complete IRQ\n");
2527 /* need to do that in process context */
2528 /* remember that fw is not scanning anymore */
2529 SET_BIT(adev
->irq_status
,
2530 HOST_INT_SCAN_COMPLETE
);
2534 /* These we just log, but either they happen rarely
2535 * or we keep them masked out */
2536 if (irqtype
& (0 | HOST_INT_RX_DATA
2537 /* | HOST_INT_TX_COMPLETE */
2539 /* | HOST_INT_RX_COMPLETE */
2543 | HOST_INT_KEY_NOT_FOUND
2544 | HOST_INT_IV_ICV_FAILURE
2545 /* | HOST_INT_CMD_COMPLETE */
2546 /* | HOST_INT_INFO */
2548 | HOST_INT_PROCESS_ERROR
2549 /* | HOST_INT_SCAN_COMPLETE */
2550 | HOST_INT_FCS_THRESHOLD
2551 | HOST_INT_UNKNOWN
)) {
2552 log_unusual_irq(irqtype
);
2555 unmasked
= read_reg16(adev
, IO_ACX_IRQ_REASON
);
2556 irqtype
= unmasked
& ~adev
->irq_mask
;
2557 /* Bail out if no new IRQ bits or if all are masked out */
2562 (++adev
->irq_loops_this_jiffy
> MAX_IRQLOOPS_PER_JIFFY
)) {
2564 "acx: too many interrupts per jiffy!\n");
2565 /* Looks like card floods us with IRQs! Try to stop that */
2566 write_reg16(adev
, IO_ACX_IRQ_MASK
, 0xffff);
2567 /* This will short-circuit all future attempts to handle IRQ.
2568 * We cant do much more... */
2574 /* Routine to perform blink with range
2575 * FIXME: update_link_quality_led is a stub - add proper code and enable this again:
2576 if (unlikely(adev->led_power == 2))
2577 update_link_quality_led(adev);
2580 /* write_flush(adev); - not needed, last op was read anyway */
2581 acx_sem_unlock(adev
);
2584 if (adev
->after_interrupt_jobs
)
2585 acx_e_after_interrupt_task(&adev
->after_interrupt_task
);
2593 static irqreturn_t
acxpci_i_interrupt(int irq
, void *dev_id
)
2595 acx_device_t
*adev
= dev_id
;
2596 unsigned long flags
;
2597 register u16 irqtype
;
2605 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2608 acx_lock(adev
, flags
);
2611 unmasked
= read_reg16(adev
, IO_ACX_IRQ_REASON
);
2612 if (unlikely(0xffff == unmasked
)) {
2613 /* 0xffff value hints at missing hardware,
2614 * so don't do anything.
2615 * Not very clean, but other drivers do the same... */
2616 log(L_IRQ
, "acx: IRQ type:FFFF - device removed? IRQ_NONE\n");
2620 /* We will check only "interesting" IRQ types */
2621 irqtype
= unmasked
& ~adev
->irq_mask
;
2623 /* We are on a shared IRQ line and it wasn't our IRQ */
2625 "acx: IRQ type:%04X, mask:%04X - all are masked, IRQ_NONE\n",
2626 unmasked
, adev
->irq_mask
);
2630 /* Go ahead and ACK our interrupt */
2631 write_reg16(adev
, IO_ACX_IRQ_ACK
, 0xffff);
2632 if (irqtype
& HOST_INT_CMD_COMPLETE
) {
2633 log(L_IRQ
, "acx: got Command_Complete IRQ\n");
2634 /* save the state for the running issue_cmd() */
2635 SET_BIT(adev
->irq_status
, HOST_INT_CMD_COMPLETE
);
2638 /* Only accept IRQs, if we are initialized properly.
2639 * This avoids an RX race while initializing.
2640 * We should probably not enable IRQs before we are initialized
2641 * completely, but some careful work is needed to fix this. I think it
2642 * is best to stay with this cheap workaround for now... .
2644 if (likely(adev
->initialized
)) {
2645 /* disable all IRQs. They are enabled again in the bottom half. */
2646 /* save the reason code and call our bottom half. */
2647 adev
->irq_reason
= irqtype
;
2649 if ((irqtype
& HOST_INT_RX_COMPLETE
) || (irqtype
& HOST_INT_TX_COMPLETE
))
2650 acx_schedule_task(adev
, 0);
2653 acx_unlock(adev
, flags
);
2657 acx_unlock(adev
, flags
);
2664 /***********************************************************************
2665 ** acxpci_l_power_led
2667 void acxpci_l_power_led(acx_device_t
* adev
, int enable
)
2669 u16 gpio_pled
= IS_ACX111(adev
) ? 0x0040 : 0x0800;
2671 /* A hack. Not moving message rate limiting to adev->xxx
2672 * (it's only a debug message after all) */
2673 static int rate_limit
= 0;
2675 if (rate_limit
++ < 3)
2676 log(L_IOCTL
, "acx: Please report in case toggling the power "
2677 "LED doesn't work for your card\n");
2679 write_reg16(adev
, IO_ACX_GPIO_OUT
,
2680 read_reg16(adev
, IO_ACX_GPIO_OUT
) & ~gpio_pled
);
2682 write_reg16(adev
, IO_ACX_GPIO_OUT
,
2683 read_reg16(adev
, IO_ACX_GPIO_OUT
) | gpio_pled
);
2687 /***********************************************************************
2691 /***********************************************************************
2695 acx111pci_ioctl_info(struct net_device
*ndev
,
2696 struct iw_request_info
*info
,
2697 struct iw_param
*vwrq
, char *extra
)
2700 acx_device_t
*adev
= ndev2adev(ndev
);
2703 rxhostdesc_t
*rxhostdesc
;
2704 txhostdesc_t
*txhostdesc
;
2705 struct acx111_ie_memoryconfig memconf
;
2706 struct acx111_ie_queueconfig queueconf
;
2707 unsigned long flags
;
2712 char ratefallback
[0x5];
2714 if (!(acx_debug
& (L_IOCTL
| L_DEBUG
)))
2716 /* using printk() since we checked debug flag already */
2720 if (!IS_ACX111(adev
)) {
2721 printk("acx: acx111-specific function called "
2722 "with non-acx111 chip, aborting\n");
2726 /* get Acx111 Memory Configuration */
2727 memset(&memconf
, 0, sizeof(memconf
));
2728 /* BTW, fails with 12 (Write only) error code.
2729 ** Retained for easy testing of issue_cmd error handling :) */
2730 acx_s_interrogate(adev
, &memconf
, ACX1xx_IE_QUEUE_CONFIG
);
2732 /* get Acx111 Queue Configuration */
2733 memset(&queueconf
, 0, sizeof(queueconf
));
2734 acx_s_interrogate(adev
, &queueconf
, ACX1xx_IE_MEMORY_CONFIG_OPTIONS
);
2736 /* get Acx111 Memory Map */
2737 memset(memmap
, 0, sizeof(memmap
));
2738 acx_s_interrogate(adev
, &memmap
, ACX1xx_IE_MEMORY_MAP
);
2740 /* get Acx111 Rx Config */
2741 memset(rxconfig
, 0, sizeof(rxconfig
));
2742 acx_s_interrogate(adev
, &rxconfig
, ACX1xx_IE_RXCONFIG
);
2744 /* get Acx111 fcs error count */
2745 memset(fcserror
, 0, sizeof(fcserror
));
2746 acx_s_interrogate(adev
, &fcserror
, ACX1xx_IE_FCS_ERROR_COUNT
);
2748 /* get Acx111 rate fallback */
2749 memset(ratefallback
, 0, sizeof(ratefallback
));
2750 acx_s_interrogate(adev
, &ratefallback
, ACX1xx_IE_RATE_FALLBACK
);
2752 /* force occurrence of a beacon interrupt */
2753 /* TODO: comment why is this necessary */
2754 write_reg16(adev
, IO_ACX_HINT_TRIG
, HOST_INT_BEACON
);
2756 /* dump Acx111 Mem Configuration */
2757 printk("acx: dump mem config:\n"
2758 "data read: %d, struct size: %d\n"
2759 "Number of stations: %1X\n"
2760 "Memory block size: %1X\n"
2761 "tx/rx memory block allocation: %1X\n"
2762 "count rx: %X / tx: %X queues\n"
2764 "fragmentation %1X\n"
2765 "Rx Queue 1 Count Descriptors: %X\n"
2766 "Rx Queue 1 Host Memory Start: %X\n"
2767 "Tx Queue 1 Count Descriptors: %X\n"
2768 "Tx Queue 1 Attributes: %X\n",
2769 memconf
.len
, (int)sizeof(memconf
),
2770 memconf
.no_of_stations
,
2771 memconf
.memory_block_size
,
2772 memconf
.tx_rx_memory_block_allocation
,
2773 memconf
.count_rx_queues
, memconf
.count_tx_queues
,
2775 memconf
.fragmentation
,
2776 memconf
.rx_queue1_count_descs
,
2777 acx2cpu(memconf
.rx_queue1_host_rx_start
),
2778 memconf
.tx_queue1_count_descs
, memconf
.tx_queue1_attributes
);
2780 /* dump Acx111 Queue Configuration */
2781 printk("acx: dump queue head:\n"
2782 "data read: %d, struct size: %d\n"
2783 "tx_memory_block_address (from card): %X\n"
2784 "rx_memory_block_address (from card): %X\n"
2785 "rx1_queue address (from card): %X\n"
2786 "tx1_queue address (from card): %X\n"
2787 "tx1_queue attributes (from card): %X\n",
2788 queueconf
.len
, (int)sizeof(queueconf
),
2789 queueconf
.tx_memory_block_address
,
2790 queueconf
.rx_memory_block_address
,
2791 queueconf
.rx1_queue_address
,
2792 queueconf
.tx1_queue_address
, queueconf
.tx1_attributes
);
2794 /* dump Acx111 Mem Map */
2795 printk("acx: dump mem map:\n"
2796 "data read: %d, struct size: %d\n"
2799 "WEP default key start: %X\n"
2800 "WEP default key end: %X\n"
2801 "STA table start: %X\n"
2802 "STA table end: %X\n"
2803 "Packet template start: %X\n"
2804 "Packet template end: %X\n"
2805 "Queue memory start: %X\n"
2806 "Queue memory end: %X\n"
2807 "Packet memory pool start: %X\n"
2808 "Packet memory pool end: %X\n"
2811 *((u16
*) & memmap
[0x02]), (int)sizeof(memmap
),
2812 *((u32
*) & memmap
[0x04]),
2813 *((u32
*) & memmap
[0x08]),
2814 *((u32
*) & memmap
[0x0C]),
2815 *((u32
*) & memmap
[0x10]),
2816 *((u32
*) & memmap
[0x14]),
2817 *((u32
*) & memmap
[0x18]),
2818 *((u32
*) & memmap
[0x1C]),
2819 *((u32
*) & memmap
[0x20]),
2820 *((u32
*) & memmap
[0x24]),
2821 *((u32
*) & memmap
[0x28]),
2822 *((u32
*) & memmap
[0x2C]),
2823 *((u32
*) & memmap
[0x30]), adev
->iobase
, adev
->iobase2
);
2825 /* dump Acx111 Rx Config */
2826 printk("acx: dump rx config:\n"
2827 "data read: %d, struct size: %d\n"
2829 "rx filter config: %X\n",
2830 *((u16
*) & rxconfig
[0x02]), (int)sizeof(rxconfig
),
2831 *((u16
*) & rxconfig
[0x04]), *((u16
*) & rxconfig
[0x06]));
2833 /* dump Acx111 fcs error */
2834 printk("acx: dump fcserror:\n"
2835 "data read: %d, struct size: %d\n"
2837 *((u16
*) & fcserror
[0x02]), (int)sizeof(fcserror
),
2838 *((u32
*) & fcserror
[0x04]));
2840 /* dump Acx111 rate fallback */
2841 printk("acx: dump rate fallback:\n"
2842 "data read: %d, struct size: %d\n"
2843 "ratefallback: %X\n",
2844 *((u16
*) & ratefallback
[0x02]), (int)sizeof(ratefallback
),
2845 *((u8
*) & ratefallback
[0x04]));
2847 /* protect against IRQ */
2848 acx_lock(adev
, flags
);
2850 /* dump acx111 internal rx descriptor ring buffer */
2851 rxdesc
= adev
->rxdesc_start
;
2853 /* loop over complete receive pool */
2855 for (i
= 0; i
< RX_CNT
; i
++) {
2856 printk("acx: \ndump internal rxdesc %d:\n"
2859 "acx mem pointer (dynamic) 0x%X\n"
2860 "CTL (dynamic) 0x%X\n"
2861 "Rate (dynamic) 0x%X\n"
2862 "RxStatus (dynamic) 0x%X\n"
2863 "Mod/Pre (dynamic) 0x%X\n",
2866 acx2cpu(rxdesc
->pNextDesc
),
2867 acx2cpu(rxdesc
->ACXMemPtr
),
2869 rxdesc
->rate
, rxdesc
->error
, rxdesc
->SNR
);
2873 /* dump host rx descriptor ring buffer */
2875 rxhostdesc
= adev
->rxhostdesc_start
;
2877 /* loop over complete receive pool */
2879 for (i
= 0; i
< RX_CNT
; i
++) {
2880 printk("acx: \ndump host rxdesc %d:\n"
2882 "buffer mem pos 0x%X\n"
2883 "buffer mem offset 0x%X\n"
2890 acx2cpu(rxhostdesc
->data_phy
),
2891 rxhostdesc
->data_offset
,
2892 le16_to_cpu(rxhostdesc
->Ctl_16
),
2893 le16_to_cpu(rxhostdesc
->length
),
2894 acx2cpu(rxhostdesc
->desc_phy_next
),
2895 rxhostdesc
->Status
);
2899 /* dump acx111 internal tx descriptor ring buffer */
2900 txdesc
= adev
->txdesc_start
;
2902 /* loop over complete transmit pool */
2904 for (i
= 0; i
< TX_CNT
; i
++) {
2905 printk("acx: \ndump internal txdesc %d:\n"
2909 "acx mem pointer (dynamic) 0x%X\n"
2910 "host mem pointer (dynamic) 0x%X\n"
2911 "length (dynamic) 0x%X\n"
2912 "CTL (dynamic) 0x%X\n"
2913 "CTL2 (dynamic) 0x%X\n"
2914 "Status (dynamic) 0x%X\n"
2915 "Rate (dynamic) 0x%X\n",
2917 (int)sizeof(struct txdesc
),
2919 acx2cpu(txdesc
->pNextDesc
),
2920 acx2cpu(txdesc
->AcxMemPtr
),
2921 acx2cpu(txdesc
->HostMemPtr
),
2922 le16_to_cpu(txdesc
->total_length
),
2924 txdesc
->Ctl2_8
, txdesc
->error
,
2926 txdesc
= advance_txdesc(adev
, txdesc
, 1);
2929 /* dump host tx descriptor ring buffer */
2931 txhostdesc
= adev
->txhostdesc_start
;
2933 /* loop over complete host send pool */
2935 for (i
= 0; i
< TX_CNT
* 2; i
++) {
2936 printk("acx: \ndump host txdesc %d:\n"
2938 "buffer mem pos 0x%X\n"
2939 "buffer mem offset 0x%X\n"
2946 acx2cpu(txhostdesc
->data_phy
),
2947 txhostdesc
->data_offset
,
2948 le16_to_cpu(txhostdesc
->Ctl_16
),
2949 le16_to_cpu(txhostdesc
->length
),
2950 acx2cpu(txhostdesc
->desc_phy_next
),
2951 le32_to_cpu(txhostdesc
->Status
));
2955 /* write_reg16(adev, 0xb4, 0x4); */
2957 acx_unlock(adev
, flags
);
2960 acx_sem_unlock(adev
);
2961 #endif /* ACX_DEBUG */
2966 /***********************************************************************
2969 acx100pci_ioctl_set_phy_amp_bias(struct net_device
*ndev
,
2970 struct iw_request_info
*info
,
2971 struct iw_param
*vwrq
, char *extra
)
2973 acx_device_t
*adev
= ndev2adev(ndev
);
2974 unsigned long flags
;
2977 if (!IS_ACX100(adev
)) {
2979 * Removing this check *might* damage
2980 * hardware, since we're tweaking GPIOs here after all!!!
2981 * You've been warned...
2983 printk("acx: sorry, setting bias level for non-acx100 "
2984 "is not supported yet\n");
2989 printk("acx: invalid bias parameter, range is 0-7\n");
2995 /* Need to lock accesses to [IO_ACX_GPIO_OUT]:
2996 * IRQ handler uses it to update LED */
2997 acx_lock(adev
, flags
);
2998 gpio_old
= read_reg16(adev
, IO_ACX_GPIO_OUT
);
2999 write_reg16(adev
, IO_ACX_GPIO_OUT
,
3000 (gpio_old
& 0xf8ff) | ((u16
) * extra
<< 8));
3001 acx_unlock(adev
, flags
);
3003 log(L_DEBUG
, "acx: gpio_old: 0x%04X\n", gpio_old
);
3004 printk("acx: %s: PHY power amplifier bias: old:%d, new:%d\n",
3005 ndev
->name
, (gpio_old
& 0x0700) >> 8, (unsigned char)*extra
);
3007 acx_sem_unlock(adev
);
3013 /***************************************************************
3014 ** acxpci_l_alloc_tx
3015 ** Actually returns a txdesc_t* ptr
3017 ** FIXME: in case of fragments, should allocate multiple descrs
3018 ** after figuring out how many we need and whether we still have
3019 ** sufficiently many.
3021 tx_t
*acxpci_l_alloc_tx(acx_device_t
* adev
)
3023 struct txdesc
*txdesc
;
3029 if (unlikely(!adev
->tx_free
)) {
3030 printk("acx: BUG: no free txdesc left\n");
3035 head
= adev
->tx_head
;
3036 txdesc
= get_txdesc(adev
, head
);
3037 ctl8
= txdesc
->Ctl_8
;
3039 /* 2005-10-11: there were several bug reports on this happening
3040 ** but now cause seems to be understood & fixed */
3041 if (unlikely(DESC_CTL_HOSTOWN
!= (ctl8
& DESC_CTL_ACXDONE_HOSTOWN
))) {
3042 /* whoops, descr at current index is not free, so probably
3043 * ring buffer already full */
3044 printk("acx: BUG: tx_head:%d Ctl8:0x%02X - failed to find "
3045 "free txdesc\n", head
, ctl8
);
3050 /* Needed in case txdesc won't be eventually submitted for tx */
3051 txdesc
->Ctl_8
= DESC_CTL_ACXDONE_HOSTOWN
;
3054 log(L_BUFT
, "acx: tx: got desc %u, %u remain\n", head
, adev
->tx_free
);
3055 /* Keep a few free descs between head and tail of tx ring.
3056 ** It is not absolutely needed, just feels safer */
3057 if (adev
->tx_free
< TX_STOP_QUEUE
) {
3058 log(L_BUF
, "acx: stop queue (%u tx desc left)\n", adev
->tx_free
);
3059 acx_stop_queue(adev
->ieee
, NULL
);
3062 /* returning current descriptor, so advance to next free one */
3063 adev
->tx_head
= (head
+ 1) % TX_CNT
;
3067 return (tx_t
*) txdesc
;
3071 /***********************************************************************
3073 void *acxpci_l_get_txbuf(acx_device_t
* adev
, tx_t
* tx_opaque
)
3075 return get_txhostdesc(adev
, (txdesc_t
*) tx_opaque
)->data
;
3079 /***********************************************************************
3082 ** Can be called from IRQ (rx -> (AP bridging or mgmt response) -> tx).
3083 ** Can be called from acx_i_start_xmit (data frames from net core).
3085 ** FIXME: in case of fragments, should loop over the number of
3086 ** pre-allocated tx descrs, properly setting up transfer data and
3087 ** CTL_xxx flags according to fragment number.
3090 acxpci_l_tx_data(acx_device_t
* adev
, tx_t
* tx_opaque
, int len
,
3091 struct ieee80211_tx_control
*ieeectl
,struct sk_buff
* skb
)
3093 txdesc_t
*txdesc
= (txdesc_t
*) tx_opaque
;
3094 struct ieee80211_hdr
*wireless_header
;
3095 txhostdesc_t
*hostdesc1
, *hostdesc2
;
3102 /* fw doesn't tx such packets anyhow */
3103 /* if (unlikely(len < WLAN_HDR_A3_LEN))
3106 hostdesc1
= get_txhostdesc(adev
, txdesc
);
3107 wireless_header
= (struct ieee80211_hdr
*)hostdesc1
->data
;
3108 /* modify flag status in separate variable to be able to write it back
3109 * in one big swoop later (also in order to have less device memory
3111 Ctl_8
= txdesc
->Ctl_8
;
3112 Ctl2_8
= 0; /* really need to init it to 0, not txdesc->Ctl2_8, it seems */
3114 hostdesc2
= hostdesc1
+ 1;
3116 /* DON'T simply set Ctl field to 0 here globally,
3117 * it needs to maintain a consistent flag status (those are state flags!!),
3118 * otherwise it may lead to severe disruption. Only set or reset particular
3119 * flags at the exact moment this is needed... */
3121 /* let chip do RTS/CTS handshaking before sending
3122 * in case packet size exceeds threshold */
3123 if (ieeectl
->flags
& IEEE80211_TXCTL_USE_RTS_CTS
)
3124 SET_BIT(Ctl2_8
, DESC_CTL2_RTS
);
3126 CLEAR_BIT(Ctl2_8
, DESC_CTL2_RTS
);
3128 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,25)
3129 rate_cur
= ieeectl
->tx_rate
;
3131 rate_cur
= ieeectl
->tx_rate
->bitrate
;
3133 if (unlikely(!rate_cur
)) {
3134 printk("acx: driver bug! bad ratemask\n");
3138 /* used in tx cleanup routine for auto rate and accounting: */
3139 /* put_txcr(adev, txdesc, clt, rate_cur); deprecated by mac80211 */
3141 txdesc
->total_length
= cpu_to_le16(len
);
3142 wlhdr_len
= ieee80211_get_hdrlen(le16_to_cpu(wireless_header
->frame_control
));
3143 hostdesc2
->length
= cpu_to_le16(len
- wlhdr_len
);
3145 if (!ieeectl->do_not_encrypt && ieeectl->key_idx>= 0)
3147 u16 key_idx = (u16)(ieeectl->key_idx);
3148 struct acx_key* key = &(adev->key[key_idx]);
3152 memcpy(ieeehdr->wep_iv, ((u8*)wireless_header) + wlhdr_len, 4);
3156 if (IS_ACX111(adev
)) {
3157 /* note that if !txdesc->do_auto, txrate->cur
3158 ** has only one nonzero bit */
3159 txdesc
->u
.r2
.rate111
= cpu_to_le16(rate_cur
3160 /* WARNING: I was never able to make it work with prism54 AP.
3161 ** It was falling down to 1Mbit where shortpre is not applicable,
3162 ** and not working at all at "5,11 basic rates only" setting.
3163 ** I even didn't see tx packets in radio packet capture.
3164 ** Disabled for now --vda */
3165 /*| ((clt->shortpre && clt->cur!=RATE111_1) ? RATE111_SHORTPRE : 0) */
3167 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3168 /* should add this to rate111 above as necessary */
3169 |(clt
->pbcc511
? RATE111_PBCC511
: 0)
3171 hostdesc1
->length
= cpu_to_le16(len
);
3172 } else { /* ACX100 */
3173 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,25)
3174 u8 rate_100
= ieeectl
->tx_rate
;
3176 u8 rate_100
= ieeectl
->tx_rate
->bitrate
;
3178 txdesc
->u
.r1
.rate
= rate_100
;
3179 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3181 if (n
== RATE100_5
|| n
== RATE100_11
)
3182 n
|= RATE100_PBCC511
;
3185 if (clt
->shortpre
&& (clt
->cur
!= RATE111_1
))
3186 SET_BIT(Ctl_8
, DESC_CTL_SHORT_PREAMBLE
); /* set Short Preamble */
3188 /* set autodma and reclaim and 1st mpdu */
3190 DESC_CTL_AUTODMA
| DESC_CTL_RECLAIM
|
3191 DESC_CTL_FIRSTFRAG
);
3192 #if ACX_FRAGMENTATION
3193 /* SET_BIT(Ctl2_8, DESC_CTL2_MORE_FRAG); cannot set it unconditionally, needs to be set for all non-last fragments */
3195 hostdesc1
->length
= cpu_to_le16(wlhdr_len
);
3197 /* don't need to clean ack/rts statistics here, already
3198 * done on descr cleanup */
3200 /* clears HOSTOWN and ACXDONE bits, thus telling that the descriptors
3201 * are now owned by the acx100; do this as LAST operation */
3202 CLEAR_BIT(Ctl_8
, DESC_CTL_ACXDONE_HOSTOWN
);
3203 /* flush writes before we release hostdesc to the adapter here */
3205 CLEAR_BIT(hostdesc1
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
3206 CLEAR_BIT(hostdesc2
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
3208 /* write back modified flags */
3209 CLEAR_BIT(Ctl2_8
, DESC_CTL2_WEP
);
3210 txdesc
->Ctl2_8
= Ctl2_8
;
3211 txdesc
->Ctl_8
= Ctl_8
;
3212 /* unused: txdesc->tx_time = cpu_to_le32(jiffies); */
3214 /* flush writes before we tell the adapter that it's its turn now */
3215 write_reg16(adev
, IO_ACX_INT_TRIG
, INT_TRIG_TXPRC
);
3217 /* log the packet content AFTER sending it,
3218 * in order to not delay sending any further than absolutely needed
3219 * Do separate logs for acx100/111 to have human-readable rates */
3220 memcpy(&(hostdesc1
->txstatus
.control
),ieeectl
,sizeof(struct ieee80211_tx_control
));
3221 hostdesc1
->skb
= skb
;
3227 /***********************************************************************
3228 ** acxpci_l_clean_txdesc
3230 ** This function resets the txdescs' status when the ACX100
3231 ** signals the TX done IRQ (txdescs have been processed), starting with
3232 ** the pool index of the descriptor which we would use next,
3233 ** in order to make sure that we can be as fast as possible
3234 ** in filling new txdescs.
3235 ** Everytime we get called we know where the next packet to be cleaned is.
3239 static inline void log_txbuffer(const acx_device_t
* adev
)
3243 static void log_txbuffer(acx_device_t
* adev
)
3248 /* no FN_ENTER here, we don't want that */
3249 /* no locks here, since it's entirely non-critical code */
3250 txdesc
= adev
->txdesc_start
;
3251 if (unlikely(!txdesc
))
3253 printk("acx: tx: desc->Ctl8's:");
3254 for (i
= 0; i
< TX_CNT
; i
++) {
3255 printk("acx: %02X", txdesc
->Ctl_8
);
3256 txdesc
= advance_txdesc(adev
, txdesc
, 1);
3263 static void handle_tx_error(acx_device_t
* adev
, u8 error
, unsigned int finger
,
3264 struct ieee80211_tx_status
*status
)
3266 const char *err
= "unknown error";
3268 /* hmm, should we handle this as a mask
3269 * of *several* bits?
3270 * For now I think only caring about
3271 * individual bits is ok... */
3274 err
= "no Tx due to error in other fragment";
3275 /* adev->wstats.discard.fragment++; */
3279 adev
->stats
.tx_aborted_errors
++;
3282 err
= "Tx desc wrong parameters";
3283 /* adev->wstats.discard.misc++; */
3286 err
= "WEP key not found";
3287 /* adev->wstats.discard.misc++; */
3290 err
= "MSDU lifetime timeout? - try changing "
3291 "'iwconfig retry lifetime XXX'";
3292 /* adev->wstats.discard.misc++; */
3295 err
= "excessive Tx retries due to either distance "
3296 "too high or unable to Tx or Tx frame error - "
3297 "try changing 'iwconfig txpower XXX' or "
3298 "'sens'itivity or 'retry'";
3299 /* adev->wstats.discard.retries++; */
3300 /* Tx error 0x20 also seems to occur on
3301 * overheating, so I'm not sure whether we
3302 * actually want to do aggressive radio recalibration,
3303 * since people maybe won't notice then that their hardware
3304 * is slowly getting cooked...
3305 * Or is it still a safe long distance from utter
3306 * radio non-functionality despite many radio recalibs
3307 * to final destructive overheating of the hardware?
3308 * In this case we really should do recalib here...
3309 * I guess the only way to find out is to do a
3310 * potentially fatal self-experiment :-\
3311 * Or maybe only recalib in case we're using Tx
3312 * rate auto (on errors switching to lower speed
3313 * --> less heat?) or 802.11 power save mode?
3315 * ok, just do it. */
3316 if (++adev
->retry_errors_msg_ratelimit
% 4 == 0) {
3317 if (adev
->retry_errors_msg_ratelimit
<= 20) {
3318 printk("acx: %s: several excessive Tx "
3319 "retry errors occurred, attempting "
3320 "to recalibrate radio. Radio "
3321 "drift might be caused by increasing "
3322 "card temperature, please check the card "
3323 "before it's too late!\n",
3324 wiphy_name(adev
->ieee
->wiphy
));
3325 if (adev
->retry_errors_msg_ratelimit
== 20)
3326 printk("acx: disabling above message\n");
3329 acx_schedule_task(adev
,
3330 ACX_AFTER_IRQ_CMD_RADIO_RECALIB
);
3332 status
->excessive_retries
++;
3335 err
= "Tx buffer overflow";
3336 adev
->stats
.tx_fifo_errors
++;
3339 /* possibly ACPI C-state powersaving related!!!
3340 * (DMA timeout due to excessively high wakeup
3341 * latency after C-state activation!?)
3342 * Disable C-State powersaving and try again,
3343 * then PLEASE REPORT, I'm VERY interested in
3344 * whether my theory is correct that this is
3345 * actually the problem here.
3346 * In that case, use new Linux idle wakeup latency
3347 * requirements kernel API to prevent this issue. */
3349 /* adev->wstats.discard.misc++; */
3352 adev
->stats
.tx_errors
++;
3353 if (adev
->stats
.tx_errors
<= 20)
3354 printk("acx: %s: tx error 0x%02X, buf %02u! (%s)\n",
3355 wiphy_name(adev
->ieee
->wiphy
), error
, finger
, err
);
3357 printk("acx: %s: tx error 0x%02X, buf %02u!\n",
3358 wiphy_name(adev
->ieee
->wiphy
), error
, finger
);
3362 unsigned int acxpci_l_clean_txdesc(acx_device_t
* adev
)
3365 txhostdesc_t
*hostdesc
;
3369 u8 error
, ack_failures
, rts_failures
, rts_ok
, r100
;
3373 if (unlikely(acx_debug
& L_DEBUG
))
3376 log(L_BUFT
, "acx: tx: cleaning up bufs from %u\n", adev
->tx_tail
);
3378 /* We know first descr which is not free yet. We advance it as far
3379 ** as we see correct bits set in following descs (if next desc
3380 ** is NOT free, we shouldn't advance at all). We know that in
3381 ** front of tx_tail may be "holes" with isolated free descs.
3382 ** We will catch up when all intermediate descs will be freed also */
3384 finger
= adev
->tx_tail
;
3386 while (likely(finger
!= adev
->tx_head
)) {
3387 txdesc
= get_txdesc(adev
, finger
);
3389 /* If we allocated txdesc on tx path but then decided
3390 ** to NOT use it, then it will be left as a free "bubble"
3391 ** in the "allocated for tx" part of the ring.
3392 ** We may meet it on the next ring pass here. */
3394 /* stop if not marked as "tx finished" and "host owned" */
3395 if ((txdesc
->Ctl_8
& DESC_CTL_ACXDONE_HOSTOWN
)
3396 != DESC_CTL_ACXDONE_HOSTOWN
) {
3397 if (unlikely(!num_cleaned
)) { /* maybe remove completely */
3398 log(L_BUFT
, "acx: clean_txdesc: tail isn't free. "
3399 "tail:%d head:%d\n",
3400 adev
->tx_tail
, adev
->tx_head
);
3405 /* remember desc values... */
3406 error
= txdesc
->error
;
3407 ack_failures
= txdesc
->ack_failures
;
3408 rts_failures
= txdesc
->rts_failures
;
3409 rts_ok
= txdesc
->rts_ok
;
3410 r100
= txdesc
->u
.r1
.rate
;
3411 r111
= le16_to_cpu(txdesc
->u
.r2
.rate111
);
3413 /* need to check for certain error conditions before we
3414 * clean the descriptor: we still need valid descr data here */
3415 hostdesc
= get_txhostdesc(adev
, txdesc
);
3417 hostdesc
->txstatus
.flags
|= IEEE80211_TX_STATUS_ACK
;
3418 if (unlikely(0x30 & error
)) {
3419 /* only send IWEVTXDROP in case of retry or lifetime exceeded;
3420 * all other errors mean we screwed up locally */
3421 /* union iwreq_data wrqu;
3422 struct ieee80211_hdr_3addr *hdr;
3423 hdr = (struct ieee80211_hdr_3addr *) hostdesc->data;
3424 MAC_COPY(wrqu.addr.sa_data, hdr->addr1);
3426 hostdesc
->txstatus
.flags
&= ~IEEE80211_TX_STATUS_ACK
;
3429 /* ...and free the desc */
3431 txdesc
->ack_failures
= 0;
3432 txdesc
->rts_failures
= 0;
3434 /* signal host owning it LAST, since ACX already knows that this
3435 ** descriptor is finished since it set Ctl_8 accordingly. */
3436 txdesc
->Ctl_8
= DESC_CTL_HOSTOWN
;
3441 if ((adev
->tx_free
>= TX_START_QUEUE
)
3442 /* && (adev->status == ACX_STATUS_4_ASSOCIATED) */
3443 /*&& (acx_queue_stopped(adev->ieee))*/
3445 log(L_BUF
, "acx: tx: wake queue (avail. Tx desc %u)\n",
3447 acx_wake_queue(adev
->ieee
, NULL
);
3450 /* do error checking, rate handling and logging
3451 * AFTER having done the work, it's faster */
3453 /* Rate handling is done in mac80211 */
3454 /* if (adev->rate_auto) {
3455 struct client *clt = get_txc(adev, txdesc);
3457 u16 cur = get_txr(adev, txdesc);
3458 if (clt->rate_cur == cur) {
3459 acx_l_handle_txrate_auto(adev, clt, cur,*/ /* intended rate */
3460 /*r100, r111,*/ /* actually used rate */
3461 /*(error & 0x30),*/ /* was there an error? */
3470 if (unlikely(error
))
3471 handle_tx_error(adev
, error
, finger
, &hostdesc
->txstatus
);
3473 if (IS_ACX111(adev
))
3475 "acx: tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u r111=%04X tx_free=%u\n",
3476 finger
, ack_failures
, rts_failures
, rts_ok
, r111
, adev
->tx_free
);
3479 "acx: tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u rate=%u\n",
3480 finger
, ack_failures
, rts_failures
, rts_ok
, r100
);
3482 /* And finally report upstream */
3485 hostdesc
->txstatus
.excessive_retries
= rts_failures
;
3486 hostdesc
->txstatus
.retry_count
= ack_failures
;
3487 ieee80211_tx_status(adev
->ieee
,hostdesc
->skb
,&hostdesc
->txstatus
);
3488 memset(&hostdesc
->txstatus
, 0, sizeof(struct ieee80211_tx_status
));
3490 /* update pointer for descr to be cleaned next */
3491 finger
= (finger
+ 1) % TX_CNT
;
3493 /* remember last position */
3494 adev
->tx_tail
= finger
;
3496 FN_EXIT1(num_cleaned
);
3500 /* clean *all* Tx descriptors, and regardless of their previous state.
3501 * Used for brute-force reset handling. */
3502 void acxpci_l_clean_txdesc_emergency(acx_device_t
* adev
)
3509 for (i
= 0; i
< TX_CNT
; i
++) {
3510 txdesc
= get_txdesc(adev
, i
);
3513 txdesc
->ack_failures
= 0;
3514 txdesc
->rts_failures
= 0;
3517 txdesc
->Ctl_8
= DESC_CTL_HOSTOWN
;
3520 adev
->tx_free
= TX_CNT
;
3526 /***********************************************************************
3527 ** acxpci_s_create_tx_host_desc_queue
3530 static void *allocate(acx_device_t
* adev
, size_t size
, dma_addr_t
* phy
,
3535 ptr
= dma_alloc_coherent(adev
->bus_dev
, size
, phy
, GFP_KERNEL
);
3538 log(L_DEBUG
, "acx: %s sz=%d adr=0x%p phy=0x%08llx\n",
3539 msg
, (int)size
, ptr
, (unsigned long long)*phy
);
3540 memset(ptr
, 0, size
);
3543 printk(KERN_ERR
"acx: %s allocation FAILED (%d bytes)\n",
3549 static int acxpci_s_create_tx_host_desc_queue(acx_device_t
* adev
)
3551 txhostdesc_t
*hostdesc
;
3553 dma_addr_t hostdesc_phy
;
3554 dma_addr_t txbuf_phy
;
3559 /* allocate TX buffer */
3560 adev
->txbuf_area_size
= TX_CNT
* /*WLAN_A4FR_MAXLEN_WEP_FCS*/ (30 + 2312 + 4);
3561 adev
->txbuf_start
= allocate(adev
, adev
->txbuf_area_size
,
3562 &adev
->txbuf_startphy
, "txbuf_start");
3563 if (!adev
->txbuf_start
)
3566 /* allocate the TX host descriptor queue pool */
3567 adev
->txhostdesc_area_size
= TX_CNT
* 2 * sizeof(*hostdesc
);
3568 adev
->txhostdesc_start
= allocate(adev
, adev
->txhostdesc_area_size
,
3569 &adev
->txhostdesc_startphy
,
3570 "txhostdesc_start");
3571 if (!adev
->txhostdesc_start
)
3573 /* check for proper alignment of TX host descriptor pool */
3574 if ((long)adev
->txhostdesc_start
& 3) {
3576 ("acx: driver bug: dma alloc returns unaligned address\n");
3580 hostdesc
= adev
->txhostdesc_start
;
3581 hostdesc_phy
= adev
->txhostdesc_startphy
;
3582 txbuf
= adev
->txbuf_start
;
3583 txbuf_phy
= adev
->txbuf_startphy
;
3586 /* Each tx buffer is accessed by hardware via
3587 ** txdesc -> txhostdesc(s) -> txbuffer(s).
3588 ** We use only one txhostdesc per txdesc, but it looks like
3589 ** acx111 is buggy: it accesses second txhostdesc
3590 ** (via hostdesc.desc_phy_next field) even if
3591 ** txdesc->length == hostdesc->length and thus
3592 ** entire packet was placed into first txhostdesc.
3593 ** Due to this bug acx111 hangs unless second txhostdesc
3594 ** has le16_to_cpu(hostdesc.length) = 3 (or larger)
3595 ** Storing NULL into hostdesc.desc_phy_next
3596 ** doesn't seem to help.
3598 ** Update: although it worked on Xterasys XN-2522g
3599 ** with len=3 trick, WG311v2 is even more bogus, doesn't work.
3600 ** Keeping this code (#ifdef'ed out) for documentational purposes.
3602 for (i
= 0; i
< TX_CNT
* 2; i
++) {
3603 hostdesc_phy
+= sizeof(*hostdesc
);
3605 hostdesc
->data_phy
= cpu2acx(txbuf_phy
);
3606 /* hostdesc->data_offset = ... */
3607 /* hostdesc->reserved = ... */
3608 hostdesc
->Ctl_16
= cpu_to_le16(DESC_CTL_HOSTOWN
);
3609 /* hostdesc->length = ... */
3610 hostdesc
->desc_phy_next
= cpu2acx(hostdesc_phy
);
3611 hostdesc
->pNext
= ptr2acx(NULL
);
3612 /* hostdesc->Status = ... */
3613 /* below: non-hardware fields */
3614 hostdesc
->data
= txbuf
;
3616 txbuf
+= WLAN_A4FR_MAXLEN_WEP_FCS
;
3617 txbuf_phy
+= WLAN_A4FR_MAXLEN_WEP_FCS
;
3619 /* hostdesc->data_phy = ... */
3620 /* hostdesc->data_offset = ... */
3621 /* hostdesc->reserved = ... */
3622 /* hostdesc->Ctl_16 = ... */
3623 hostdesc
->length
= cpu_to_le16(3); /* bug workaround */
3624 /* hostdesc->desc_phy_next = ... */
3625 /* hostdesc->pNext = ... */
3626 /* hostdesc->Status = ... */
3627 /* below: non-hardware fields */
3628 /* hostdesc->data = ... */
3633 /* We initialize two hostdescs so that they point to adjacent
3634 ** memory areas. Thus txbuf is really just a contiguous memory area */
3635 for (i
= 0; i
< TX_CNT
* 2; i
++) {
3636 hostdesc_phy
+= sizeof(*hostdesc
);
3638 hostdesc
->data_phy
= cpu2acx(txbuf_phy
);
3639 /* done by memset(0): hostdesc->data_offset = 0; */
3640 /* hostdesc->reserved = ... */
3641 hostdesc
->Ctl_16
= cpu_to_le16(DESC_CTL_HOSTOWN
);
3642 /* hostdesc->length = ... */
3643 hostdesc
->desc_phy_next
= cpu2acx(hostdesc_phy
);
3644 /* done by memset(0): hostdesc->pNext = ptr2acx(NULL); */
3645 /* hostdesc->Status = ... */
3646 /* ->data is a non-hardware field: */
3647 hostdesc
->data
= txbuf
;
3650 txbuf
+= 24 /*WLAN_HDR_A3_LEN*/;
3651 txbuf_phy
+= 24 /*WLAN_HDR_A3_LEN*/;
3653 txbuf
+= 30 + 2132 + 4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3654 txbuf_phy
+= 30 + 2132 +4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3659 hostdesc
->desc_phy_next
= cpu2acx(adev
->txhostdesc_startphy
);
3664 printk("acx: create_tx_host_desc_queue FAILED\n");
3665 /* dealloc will be done by free function on error case */
3671 /***************************************************************
3672 ** acxpci_s_create_rx_host_desc_queue
3674 /* the whole size of a data buffer (header plus data body)
3675 * plus 32 bytes safety offset at the end */
3676 #define RX_BUFFER_SIZE (sizeof(rxbuffer_t) + 32)
3678 static int acxpci_s_create_rx_host_desc_queue(acx_device_t
* adev
)
3680 rxhostdesc_t
*hostdesc
;
3682 dma_addr_t hostdesc_phy
;
3683 dma_addr_t rxbuf_phy
;
3688 /* allocate the RX host descriptor queue pool */
3689 adev
->rxhostdesc_area_size
= RX_CNT
* sizeof(*hostdesc
);
3690 adev
->rxhostdesc_start
= allocate(adev
, adev
->rxhostdesc_area_size
,
3691 &adev
->rxhostdesc_startphy
,
3692 "rxhostdesc_start");
3693 if (!adev
->rxhostdesc_start
)
3695 /* check for proper alignment of RX host descriptor pool */
3696 if ((long)adev
->rxhostdesc_start
& 3) {
3698 ("acx: driver bug: dma alloc returns unaligned address\n");
3702 /* allocate Rx buffer pool which will be used by the acx
3703 * to store the whole content of the received frames in it */
3704 adev
->rxbuf_area_size
= RX_CNT
* RX_BUFFER_SIZE
;
3705 adev
->rxbuf_start
= allocate(adev
, adev
->rxbuf_area_size
,
3706 &adev
->rxbuf_startphy
, "rxbuf_start");
3707 if (!adev
->rxbuf_start
)
3710 rxbuf
= adev
->rxbuf_start
;
3711 rxbuf_phy
= adev
->rxbuf_startphy
;
3712 hostdesc
= adev
->rxhostdesc_start
;
3713 hostdesc_phy
= adev
->rxhostdesc_startphy
;
3715 /* don't make any popular C programming pointer arithmetic mistakes
3716 * here, otherwise I'll kill you...
3717 * (and don't dare asking me why I'm warning you about that...) */
3718 for (i
= 0; i
< RX_CNT
; i
++) {
3719 hostdesc
->data
= rxbuf
;
3720 hostdesc
->data_phy
= cpu2acx(rxbuf_phy
);
3721 hostdesc
->length
= cpu_to_le16(RX_BUFFER_SIZE
);
3722 CLEAR_BIT(hostdesc
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
3724 rxbuf_phy
+= sizeof(*rxbuf
);
3725 hostdesc_phy
+= sizeof(*hostdesc
);
3726 hostdesc
->desc_phy_next
= cpu2acx(hostdesc_phy
);
3730 hostdesc
->desc_phy_next
= cpu2acx(adev
->rxhostdesc_startphy
);
3734 printk("acx: create_rx_host_desc_queue FAILED\n");
3735 /* dealloc will be done by free function on error case */
3741 /***************************************************************
3742 ** acxpci_s_create_hostdesc_queues
3744 int acxpci_s_create_hostdesc_queues(acx_device_t
* adev
)
3747 result
= acxpci_s_create_tx_host_desc_queue(adev
);
3750 result
= acxpci_s_create_rx_host_desc_queue(adev
);
3755 /***************************************************************
3756 ** acxpci_create_tx_desc_queue
3758 static void acxpci_create_tx_desc_queue(acx_device_t
* adev
, u32 tx_queue_start
)
3761 txhostdesc_t
*hostdesc
;
3762 dma_addr_t hostmemptr
;
3768 if (IS_ACX100(adev
))
3769 adev
->txdesc_size
= sizeof(*txdesc
);
3771 /* the acx111 txdesc is 4 bytes larger */
3772 adev
->txdesc_size
= sizeof(*txdesc
) + 4;
3774 adev
->txdesc_start
= (txdesc_t
*) (adev
->iobase2
+ tx_queue_start
);
3776 log(L_DEBUG
, "acx: adev->iobase2=%p\n"
3777 "acx: tx_queue_start=%08X\n"
3778 "acx: adev->txdesc_start=%p\n",
3779 adev
->iobase2
, tx_queue_start
, adev
->txdesc_start
);
3781 adev
->tx_free
= TX_CNT
;
3782 /* done by memset: adev->tx_head = 0; */
3783 /* done by memset: adev->tx_tail = 0; */
3784 txdesc
= adev
->txdesc_start
;
3785 mem_offs
= tx_queue_start
;
3786 hostmemptr
= adev
->txhostdesc_startphy
;
3787 hostdesc
= adev
->txhostdesc_start
;
3789 if (IS_ACX111(adev
)) {
3790 /* ACX111 has a preinitialized Tx buffer! */
3791 /* loop over whole send pool */
3792 /* FIXME: do we have to do the hostmemptr stuff here?? */
3793 for (i
= 0; i
< TX_CNT
; i
++) {
3794 txdesc
->HostMemPtr
= ptr2acx(hostmemptr
);
3795 txdesc
->Ctl_8
= DESC_CTL_HOSTOWN
;
3796 /* reserve two (hdr desc and payload desc) */
3798 hostmemptr
+= 2 * sizeof(*hostdesc
);
3799 txdesc
= advance_txdesc(adev
, txdesc
, 1);
3802 /* ACX100 Tx buffer needs to be initialized by us */
3803 /* clear whole send pool. sizeof is safe here (we are acx100) */
3804 memset(adev
->txdesc_start
, 0, TX_CNT
* sizeof(*txdesc
));
3806 /* loop over whole send pool */
3807 for (i
= 0; i
< TX_CNT
; i
++) {
3808 log(L_DEBUG
, "acx: configure card tx descriptor: 0x%p, "
3809 "size: 0x%X\n", txdesc
, adev
->txdesc_size
);
3811 /* pointer to hostdesc memory */
3812 txdesc
->HostMemPtr
= ptr2acx(hostmemptr
);
3813 /* initialise ctl */
3814 txdesc
->Ctl_8
= (DESC_CTL_HOSTOWN
| DESC_CTL_RECLAIM
3815 | DESC_CTL_AUTODMA
|
3816 DESC_CTL_FIRSTFRAG
);
3817 /* done by memset(0): txdesc->Ctl2_8 = 0; */
3818 /* point to next txdesc */
3820 cpu2acx(mem_offs
+ adev
->txdesc_size
);
3821 /* reserve two (hdr desc and payload desc) */
3823 hostmemptr
+= 2 * sizeof(*hostdesc
);
3824 /* go to the next one */
3825 mem_offs
+= adev
->txdesc_size
;
3826 /* ++ is safe here (we are acx100) */
3829 /* go back to the last one */
3831 /* and point to the first making it a ring buffer */
3832 txdesc
->pNextDesc
= cpu2acx(tx_queue_start
);
3838 /***************************************************************
3839 ** acxpci_create_rx_desc_queue
3841 static void acxpci_create_rx_desc_queue(acx_device_t
* adev
, u32 rx_queue_start
)
3849 /* done by memset: adev->rx_tail = 0; */
3851 /* ACX111 doesn't need any further config: preconfigures itself.
3852 * Simply print ring buffer for debugging */
3853 if (IS_ACX111(adev
)) {
3854 /* rxdesc_start already set here */
3856 adev
->rxdesc_start
=
3857 (rxdesc_t
*) ((u8
*) adev
->iobase2
+ rx_queue_start
);
3859 rxdesc
= adev
->rxdesc_start
;
3860 for (i
= 0; i
< RX_CNT
; i
++) {
3861 log(L_DEBUG
, "acx: rx descriptor %d @ 0x%p\n", i
, rxdesc
);
3862 rxdesc
= adev
->rxdesc_start
= (rxdesc_t
*)
3863 (adev
->iobase2
+ acx2cpu(rxdesc
->pNextDesc
));
3866 /* we didn't pre-calculate rxdesc_start in case of ACX100 */
3867 /* rxdesc_start should be right AFTER Tx pool */
3868 adev
->rxdesc_start
= (rxdesc_t
*)
3869 ((u8
*) adev
->txdesc_start
+ (TX_CNT
* sizeof(txdesc_t
)));
3870 /* NB: sizeof(txdesc_t) above is valid because we know
3871 ** we are in if (acx100) block. Beware of cut-n-pasting elsewhere!
3872 ** acx111's txdesc is larger! */
3874 memset(adev
->rxdesc_start
, 0, RX_CNT
* sizeof(*rxdesc
));
3876 /* loop over whole receive pool */
3877 rxdesc
= adev
->rxdesc_start
;
3878 mem_offs
= rx_queue_start
;
3879 for (i
= 0; i
< RX_CNT
; i
++) {
3880 log(L_DEBUG
, "acx: rx descriptor @ 0x%p\n", rxdesc
);
3881 rxdesc
->Ctl_8
= DESC_CTL_RECLAIM
| DESC_CTL_AUTODMA
;
3882 /* point to next rxdesc */
3883 rxdesc
->pNextDesc
= cpu2acx(mem_offs
+ sizeof(*rxdesc
));
3884 /* go to the next one */
3885 mem_offs
+= sizeof(*rxdesc
);
3888 /* go to the last one */
3891 /* and point to the first making it a ring buffer */
3892 rxdesc
->pNextDesc
= cpu2acx(rx_queue_start
);
3898 /***************************************************************
3899 ** acxpci_create_desc_queues
3902 acxpci_create_desc_queues(acx_device_t
* adev
, u32 tx_queue_start
,
3905 acxpci_create_tx_desc_queue(adev
, tx_queue_start
);
3906 acxpci_create_rx_desc_queue(adev
, rx_queue_start
);
3910 /***************************************************************
3911 ** acxpci_s_proc_diag_output
3913 char *acxpci_s_proc_diag_output(char *p
, acx_device_t
* adev
)
3915 const char *rtl
, *thd
, *ttl
;
3916 rxhostdesc_t
*rxhostdesc
;
3922 p
+= sprintf(p
, "** Rx buf **\n");
3923 rxhostdesc
= adev
->rxhostdesc_start
;
3925 for (i
= 0; i
< RX_CNT
; i
++) {
3926 rtl
= (i
== adev
->rx_tail
) ? " [tail]" : "";
3927 if ((rxhostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
3929 Status
& cpu_to_le32(DESC_STATUS_FULL
)))
3930 p
+= sprintf(p
, "%02u FULL%s\n", i
, rtl
);
3932 p
+= sprintf(p
, "%02u empty%s\n", i
, rtl
);
3935 /* p += sprintf(p, "** Tx buf (free %d, Linux netqueue %s) **\n",
3937 acx_queue_stopped(adev->ieee) ? "STOPPED" : "running");*/
3938 txdesc
= adev
->txdesc_start
;
3940 for (i
= 0; i
< TX_CNT
; i
++) {
3941 thd
= (i
== adev
->tx_head
) ? " [head]" : "";
3942 ttl
= (i
== adev
->tx_tail
) ? " [tail]" : "";
3943 if (txdesc
->Ctl_8
& DESC_CTL_ACXDONE
)
3944 p
+= sprintf(p
, "%02u free (%02X)%s%s\n", i
,
3945 txdesc
->Ctl_8
, thd
, ttl
);
3947 p
+= sprintf(p
, "%02u tx (%02X)%s%s\n", i
,
3948 txdesc
->Ctl_8
, thd
, ttl
);
3949 txdesc
= advance_txdesc(adev
, txdesc
, 1);
3954 "txbuf_start %p, txbuf_area_size %u, txbuf_startphy %08llx\n"
3955 "txdesc_size %u, txdesc_start %p\n"
3956 "txhostdesc_start %p, txhostdesc_area_size %u, txhostdesc_startphy %08llx\n"
3958 "rxhostdesc_start %p, rxhostdesc_area_size %u, rxhostdesc_startphy %08llx\n"
3959 "rxbuf_start %p, rxbuf_area_size %u, rxbuf_startphy %08llx\n",
3960 adev
->txbuf_start
, adev
->txbuf_area_size
,
3961 (unsigned long long)adev
->txbuf_startphy
,
3962 adev
->txdesc_size
, adev
->txdesc_start
,
3963 adev
->txhostdesc_start
, adev
->txhostdesc_area_size
,
3964 (unsigned long long)adev
->txhostdesc_startphy
,
3966 adev
->rxhostdesc_start
, adev
->rxhostdesc_area_size
,
3967 (unsigned long long)adev
->rxhostdesc_startphy
,
3968 adev
->rxbuf_start
, adev
->rxbuf_area_size
,
3969 (unsigned long long)adev
->rxbuf_startphy
);
3976 /***********************************************************************
3978 int acxpci_proc_eeprom_output(char *buf
, acx_device_t
* adev
)
3985 for (i
= 0; i
< 0x400; i
++) {
3986 acxpci_read_eeprom_byte(adev
, i
, p
++);
3994 /***********************************************************************
3997 void acxpci_set_interrupt_mask(acx_device_t
* adev
)
3999 if (IS_ACX111(adev
)) {
4000 adev
->irq_mask
= (u16
) ~ (0
4001 /* | HOST_INT_RX_DATA */
4002 | HOST_INT_TX_COMPLETE
4003 /* | HOST_INT_TX_XFER */
4004 | HOST_INT_RX_COMPLETE
4005 /* | HOST_INT_DTIM */
4006 /* | HOST_INT_BEACON */
4007 /* | HOST_INT_TIMER */
4008 /* | HOST_INT_KEY_NOT_FOUND */
4009 | HOST_INT_IV_ICV_FAILURE
4010 | HOST_INT_CMD_COMPLETE
4012 /* | HOST_INT_OVERFLOW */
4013 /* | HOST_INT_PROCESS_ERROR */
4014 | HOST_INT_SCAN_COMPLETE
4015 | HOST_INT_FCS_THRESHOLD
4016 /* | HOST_INT_UNKNOWN */
4018 /* Or else acx100 won't signal cmd completion, right? */
4019 adev
->irq_mask_off
= (u16
) ~ (HOST_INT_CMD_COMPLETE
); /* 0xfdff */
4021 adev
->irq_mask
= (u16
) ~ (0
4022 /* | HOST_INT_RX_DATA */
4023 | HOST_INT_TX_COMPLETE
4024 /* | HOST_INT_TX_XFER */
4025 | HOST_INT_RX_COMPLETE
4026 /* | HOST_INT_DTIM */
4027 /* | HOST_INT_BEACON */
4028 /* | HOST_INT_TIMER */
4029 /* | HOST_INT_KEY_NOT_FOUND */
4030 /* | HOST_INT_IV_ICV_FAILURE */
4031 | HOST_INT_CMD_COMPLETE
4033 /* | HOST_INT_OVERFLOW */
4034 /* | HOST_INT_PROCESS_ERROR */
4035 | HOST_INT_SCAN_COMPLETE
4036 /* | HOST_INT_FCS_THRESHOLD */
4037 /* | HOST_INT_UNKNOWN */
4039 adev
->irq_mask_off
= (u16
) ~ (HOST_INT_UNKNOWN
); /* 0x7fff */
4044 /***********************************************************************
4046 int acx100pci_s_set_tx_level(acx_device_t
* adev
, u8 level_dbm
)
4048 /* since it can be assumed that at least the Maxim radio has a
4049 * maximum power output of 20dBm and since it also can be
4050 * assumed that these values drive the DAC responsible for
4051 * setting the linear Tx level, I'd guess that these values
4052 * should be the corresponding linear values for a dBm value,
4053 * in other words: calculate the values from that formula:
4054 * Y [dBm] = 10 * log (X [mW])
4055 * then scale the 0..63 value range onto the 1..100mW range (0..20 dBm)
4056 * and you're done...
4057 * Hopefully that's ok, but you never know if we're actually
4058 * right... (especially since Windows XP doesn't seem to show
4059 * actual Tx dBm values :-P) */
4061 /* NOTE: on Maxim, value 30 IS 30mW, and value 10 IS 10mW - so the
4062 * values are EXACTLY mW!!! Not sure about RFMD and others,
4064 static const u8 dbm2val_maxim
[21] = {
4072 static const u8 dbm2val_rfmd
[21] = {
4082 switch (adev
->radio_type
) {
4083 case RADIO_MAXIM_0D
:
4084 table
= &dbm2val_maxim
[0];
4087 case RADIO_RALINK_15
:
4088 table
= &dbm2val_rfmd
[0];
4091 printk("acx: %s: unknown/unsupported radio type, "
4092 "cannot modify tx power level yet!\n", wiphy_name(adev
->ieee
->wiphy
));
4095 printk("acx: %s: changing radio power level to %u dBm (%u)\n",
4096 wiphy_name(adev
->ieee
->wiphy
), level_dbm
, table
[level_dbm
]);
4097 acxpci_s_write_phy_reg(adev
, 0x11, table
[level_dbm
]);
4102 struct vlynq_reg_config
{
4107 struct vlynq_known
{
4110 struct vlynq_mapping rx_mapping
[4];
4114 struct vlynq_reg_config regs
[10];
4117 #define CHIP_TNETW1130 0x00000009
4118 #define CHIP_TNETW1350 0x00000029
4120 static struct vlynq_known known_devices
[] = {
4122 .chip_id
= CHIP_TNETW1130
, .name
= "TI TNETW1130",
4124 { .size
= 0x22000, .offset
= 0xf0000000 },
4125 { .size
= 0x40000, .offset
= 0xc0000000 },
4126 { .size
= 0x0, .offset
= 0x0 },
4127 { .size
= 0x0, .offset
= 0x0 },
4130 .irq_type
= IRQ_TYPE_EDGE_RISING
,
4135 .value
= (0xd0000000 - PHYS_OFFSET
)
4139 .value
= (0xd0000000 - PHYS_OFFSET
)
4141 { .offset
= 0x740, .value
= 0 },
4142 { .offset
= 0x744, .value
= 0x00010000 },
4143 { .offset
= 0x764, .value
= 0x00010000 },
4147 .chip_id
= CHIP_TNETW1350
, .name
= "TI TNETW1350",
4149 { .size
= 0x100000, .offset
= 0x00300000 },
4150 { .size
= 0x80000, .offset
= 0x00000000 },
4151 { .size
= 0x0, .offset
= 0x0 },
4152 { .size
= 0x0, .offset
= 0x0 },
4155 .irq_type
= IRQ_TYPE_EDGE_RISING
,
4160 .value
= (0x60000000 - PHYS_OFFSET
)
4164 .value
= (0x60000000 - PHYS_OFFSET
)
4166 { .offset
= 0x740, .value
= 0 },
4167 { .offset
= 0x744, .value
= 0x00010000 },
4168 { .offset
= 0x764, .value
= 0x00010000 },
4173 static struct vlynq_device_id acx_vlynq_id
[] = {
4174 { CHIP_TNETW1130
, vlynq_div_auto
, 0 },
4175 { CHIP_TNETW1350
, vlynq_div_auto
, 1 },
4179 static __devinit
int vlynq_probe(struct vlynq_device
*vdev
,
4180 struct vlynq_device_id
*id
)
4182 int result
= -EIO
, i
;
4184 struct ieee80211_hw
*ieee
;
4185 acx_device_t
*adev
= NULL
;
4186 acx111_ie_configoption_t co
;
4187 struct vlynq_mapping mapping
[4] = { { 0, }, };
4188 struct vlynq_known
*match
= NULL
;
4191 result
= vlynq_enable_device(vdev
);
4195 match
= &known_devices
[id
->driver_data
];
4202 mapping
[0].offset
= ARCH_PFN_OFFSET
<< PAGE_SHIFT
;
4203 mapping
[0].size
= 0x02000000;
4204 vlynq_set_local_mapping(vdev
, vdev
->mem_start
, mapping
);
4205 vlynq_set_remote_mapping(vdev
, 0, match
->rx_mapping
);
4207 set_irq_type(vlynq_virq_to_irq(vdev
, match
->irq
), match
->irq_type
);
4209 addr
= (u32
)ioremap(vdev
->mem_start
, 0x1000);
4211 printk(KERN_ERR
"acx: %s: failed to remap io memory\n",
4217 for (i
= 0; i
< match
->num_regs
; i
++)
4218 iowrite32(match
->regs
[i
].value
,
4219 (u32
*)(addr
+ match
->regs
[i
].offset
));
4221 iounmap((void *)addr
);
4223 ieee
= ieee80211_alloc_hw(sizeof(struct acx_device
), &acxpci_hw_ops
);
4225 printk("acx: could not allocate ieee80211 structure %s\n",
4227 goto fail_alloc_netdev
;
4229 ieee
->flags
&= ~IEEE80211_HW_RX_INCLUDES_FCS
;
4232 adev
= ieee2adev(ieee
);
4234 memset(adev
, 0, sizeof(*adev
));
4235 /** Set up our private interface **/
4236 spin_lock_init(&adev
->spinlock
); /* initial state: unlocked */
4237 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
4238 mutex_init(&adev
->mutex
);
4239 /* since nobody can see new netdev yet, we can as well
4240 ** just _presume_ that we're under sem (instead of actually taking it): */
4241 /* acx_sem_lock(adev); */
4244 adev
->bus_dev
= &vdev
->dev
;
4245 adev
->dev_type
= DEVTYPE_PCI
;
4247 /** Finished with private interface **/
4249 vlynq_set_drvdata(vdev
, ieee
);
4250 if (!request_mem_region(vdev
->mem_start
, vdev
->mem_end
- vdev
->mem_start
, "acx")) {
4251 printk("acx: cannot reserve VLYNQ memory region\n");
4252 goto fail_request_mem_region
;
4255 adev
->iobase
= ioremap(vdev
->mem_start
, vdev
->mem_end
- vdev
->mem_start
);
4256 if (!adev
->iobase
) {
4257 printk("acx: ioremap() FAILED\n");
4260 adev
->iobase2
= adev
->iobase
+ match
->rx_mapping
[0].size
;
4261 adev
->chip_type
= CHIPTYPE_ACX111
;
4262 adev
->chip_name
= match
->name
;
4263 adev
->io
= IO_ACX111
;
4264 adev
->irq
= vlynq_virq_to_irq(vdev
, match
->irq
);
4266 printk("acx: found %s-based wireless network card at %s, irq:%d, "
4267 "phymem:0x%x, mem:0x%p\n",
4268 match
->name
, vdev
->dev
.bus_id
, adev
->irq
,
4269 vdev
->mem_start
, adev
->iobase
);
4270 log(L_ANY
, "acx: the initial debug setting is 0x%04X\n", acx_debug
);
4272 if (0 == adev
->irq
) {
4273 printk("acx: can't use IRQ 0\n");
4276 SET_IEEE80211_DEV(ieee
, &vdev
->dev
);
4278 /* request shared IRQ handler */
4280 (adev
->irq
, acxpci_i_interrupt
, IRQF_SHARED
, KBUILD_MODNAME
, adev
)) {
4281 printk("acx: %s: request_irq FAILED\n", wiphy_name(adev
->ieee
->wiphy
));
4285 log(L_DEBUG
| L_IRQ
, "acx: request_irq %d successful\n", adev
->irq
);
4287 /* to find crashes due to weird driver access
4288 * to unconfigured interface (ifup) */
4289 adev
->mgmt_timer
.function
= (void (*)(unsigned long))0x0000dead;
4292 /* ok, pci setup is finished, now start initializing the card */
4294 /* NB: read_reg() reads may return bogus data before reset_dev(),
4295 * since the firmware which directly controls large parts of the I/O
4296 * registers isn't initialized yet.
4297 * acx100 seems to be more affected than acx111 */
4298 if (OK
!= acxpci_s_reset_dev(adev
))
4301 if (OK
!= acx_s_init_mac(adev
))
4304 acx_s_interrogate(adev
, &co
, ACX111_IE_CONFIG_OPTIONS
);
4305 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
4306 if (OK
!= acxpci_read_eeprom_byte(adev
, 0x05, &adev
->eeprom_version
))
4307 goto fail_read_eeprom_version
;
4309 acx_s_parse_configoption(adev
, &co
);
4310 acx_s_set_defaults(adev
);
4311 acx_s_get_firmware_version(adev
); /* needs to be after acx_s_init_mac() */
4312 acx_display_hardware_details(adev
);
4314 /* Register the card, AFTER everything else has been set up,
4315 * since otherwise an ioctl could step on our feet due to
4316 * firmware operations happening in parallel or uninitialized data */
4319 acx_proc_register_entries(ieee
);
4321 /* Now we have our device, so make sure the kernel doesn't try
4322 * to send packets even though we're not associated to a network yet */
4324 /* after register_netdev() userspace may start working with dev
4325 * (in particular, on other CPUs), we only need to up the sem */
4326 /* acx_sem_unlock(adev); */
4328 printk("acx: acx " ACX_RELEASE
": net device %s, driver compiled "
4329 "against wireless extensions %d and Linux %s\n",
4330 wiphy_name(adev
->ieee
->wiphy
), WIRELESS_EXT
, UTS_RELEASE
);
4332 MAC_COPY(adev
->ieee
->wiphy
->perm_addr
, adev
->dev_addr
);
4334 log(L_IRQ
| L_INIT
, "acx: using IRQ %d\n", adev
->irq
);
4336 /** done with board specific setup **/
4338 result
= acx_setup_modes(adev
);
4340 printk("acx: can't register hwmode\n");
4341 goto fail_register_netdev
;
4344 acx_init_task_scheduler(adev
);
4345 result
= ieee80211_register_hw(adev
->ieee
);
4347 printk("acx: ieee80211_register_hw() FAILED: %d\n", result
);
4348 goto fail_register_netdev
;
4351 great_inquisitor(adev
);
4357 /* error paths: undo everything in reverse order... */
4360 acxpci_s_delete_dma_regions(adev
);
4363 fail_read_eeprom_version
:
4369 iounmap(adev
->iobase
);
4372 release_mem_region(vdev
->mem_start
, vdev
->mem_end
- vdev
->mem_start
);
4373 fail_request_mem_region
:
4374 fail_register_netdev
:
4375 ieee80211_free_hw(ieee
);
4377 vlynq_disable_device(vdev
);
4383 static void vlynq_remove(struct vlynq_device
*vdev
)
4385 struct ieee80211_hw
*hw
= vlynq_get_drvdata(vdev
);
4386 acx_device_t
*adev
= ieee2adev(hw
);
4387 unsigned long flags
;
4391 log(L_DEBUG
, "acx: %s: card is unused. Skipping any release code\n",
4397 acx_lock(adev
, flags
);
4398 acx_unlock(adev
, flags
);
4399 adev
->initialized
= 0;
4401 /* If device wasn't hot unplugged... */
4402 if (adev_present(adev
)) {
4406 /* disable both Tx and Rx to shut radio down properly */
4407 if (adev
->initialized
) {
4408 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_TX
, NULL
, 0);
4409 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_RX
, NULL
, 0);
4411 acx_lock(adev
, flags
);
4412 /* disable power LED to save power :-) */
4413 log(L_INIT
, "acx: switching off power LED to save power\n");
4414 acxpci_l_power_led(adev
, 0);
4416 acx_unlock(adev
, flags
);
4418 acx_sem_unlock(adev
);
4421 /* unregister the device to not let the kernel
4422 * (e.g. ioctls) access a half-deconfigured device
4423 * NB: this will cause acxpci_e_close() to be called,
4424 * thus we shouldn't call it under sem!
4427 log(L_INIT
, "acx: removing device %s\n", wiphy_name(adev
->ieee
->wiphy
));
4428 ieee80211_unregister_hw(adev
->ieee
);
4430 /* unregister_netdev ensures that no references to us left.
4431 * For paranoid reasons we continue to follow the rules */
4434 if (adev
->dev_state_mask
& ACX_STATE_IFACE_UP
) {
4436 CLEAR_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
4439 acx_proc_unregister_entries(adev
->ieee
);
4441 /* finally, clean up PCI bus state */
4442 acxpci_s_delete_dma_regions(adev
);
4444 iounmap(adev
->iobase
);
4446 iounmap(adev
->iobase2
);
4447 release_mem_region(vdev
->mem_start
, vdev
->mem_end
- vdev
->mem_start
);
4449 /* remove dev registration */
4451 acx_sem_unlock(adev
);
4452 vlynq_disable_device(vdev
);
4454 /* Free netdev (quite late,
4455 * since otherwise we might get caught off-guard
4456 * by a netdev timeout handler execution
4457 * expecting to see a working dev...) */
4458 ieee80211_free_hw(adev
->ieee
);
4464 static struct vlynq_driver vlynq_acx
= {
4465 .name
= "acx_vlynq",
4466 .id_table
= acx_vlynq_id
,
4467 .probe
= vlynq_probe
,
4468 .remove
= __devexit_p(vlynq_remove
),
4470 #endif /* CONFIG_VLYNQ */
4473 /***********************************************************************
4474 ** Data for init_module/cleanup_module
4477 static const struct pci_device_id acxpci_id_tbl
[] __devinitdata
= {
4479 .vendor
= PCI_VENDOR_ID_TI
,
4480 .device
= PCI_DEVICE_ID_TI_TNETW1100A
,
4481 .subvendor
= PCI_ANY_ID
,
4482 .subdevice
= PCI_ANY_ID
,
4483 .driver_data
= CHIPTYPE_ACX100
,
4486 .vendor
= PCI_VENDOR_ID_TI
,
4487 .device
= PCI_DEVICE_ID_TI_TNETW1100B
,
4488 .subvendor
= PCI_ANY_ID
,
4489 .subdevice
= PCI_ANY_ID
,
4490 .driver_data
= CHIPTYPE_ACX100
,
4493 .vendor
= PCI_VENDOR_ID_TI
,
4494 .device
= PCI_DEVICE_ID_TI_TNETW1130
,
4495 .subvendor
= PCI_ANY_ID
,
4496 .subdevice
= PCI_ANY_ID
,
4497 .driver_data
= CHIPTYPE_ACX111
,
4508 MODULE_DEVICE_TABLE(pci
, acxpci_id_tbl
);
4510 static struct pci_driver
4513 .id_table
= acxpci_id_tbl
,
4514 .probe
= acxpci_e_probe
,
4515 .remove
= __devexit_p(acxpci_e_remove
),
4517 .suspend
= acxpci_e_suspend
,
4518 .resume
= acxpci_e_resume
4519 #endif /* CONFIG_PM */
4521 #endif /* CONFIG_PCI */
4523 /***********************************************************************
4524 ** acxpci_e_init_module
4526 ** Module initialization routine, called once at module load time
4528 int __init
acxpci_e_init_module(void)
4536 #if (ACX_IO_WIDTH==32)
4537 log(L_INIT
, "acx: compiled to use 32bit I/O access. "
4538 "I/O timing issues might occur, such as "
4539 "non-working firmware upload. Report them\n");
4541 log(L_INIT
, "acx: compiled to use 16bit I/O access only "
4542 "(compatibility mode)\n");
4545 #ifdef __LITTLE_ENDIAN
4546 #define ENDIANNESS_STRING "running on a little-endian CPU\n"
4548 #define ENDIANNESS_STRING "running on a BIG-ENDIAN CPU\n"
4551 "acx: " ENDIANNESS_STRING
4552 " PCI/VLYNQ module " ACX_RELEASE
" initialized, "
4553 "waiting for cards to probe...\n");
4556 res
= pci_register_driver(&acxpci_drv_id
);
4558 res
= vlynq_register_driver(&vlynq_acx
);
4562 printk(KERN_ERR
"acx_pci: can't register pci/vlynq driver\n");
4570 /***********************************************************************
4571 ** acxpci_e_cleanup_module
4573 ** Called at module unload time. This is our last chance to
4574 ** clean up after ourselves.
4576 void __exit
acxpci_e_cleanup_module(void)
4581 pci_unregister_driver(&acxpci_drv_id
);
4583 vlynq_unregister_driver(&vlynq_acx
);
4586 "acx: PCI module " ACX_RELEASE
" unloaded\n");