1 /**** (legal) claimer in README
2 ** Copyright (C) 2003 ACX100 Open Source Project
4 #define ACX_MAC80211_PCI 1
6 #include <linux/version.h>
7 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 18)
8 #include <linux/config.h>
11 /* Linux 2.6.18+ uses <linux/utsrelease.h> */
13 #include <linux/utsrelease.h>
16 #include <linux/compiler.h> /* required for Lx 2.6.8 ?? */
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/moduleparam.h>
20 #include <linux/sched.h>
21 #include <linux/types.h>
22 #include <linux/skbuff.h>
23 #include <linux/slab.h>
24 #include <linux/if_arp.h>
25 #include <linux/rtnetlink.h>
26 #include <linux/wireless.h>
27 #include <net/iw_handler.h>
28 #include <linux/netdevice.h>
29 #include <linux/ioport.h>
30 #include <linux/pci.h>
32 #include <linux/vmalloc.h>
33 #include <linux/ethtool.h>
34 #include <linux/dma-mapping.h>
35 #include <linux/workqueue.h>
37 #include <linux/vlynq.h>
42 /***********************************************************************
45 #define PCI_TYPE (PCI_USES_MEM | PCI_ADDR0 | PCI_NO_ACPI_WAKE)
46 #define PCI_ACX100_REGION1 0x01
47 #define PCI_ACX100_REGION1_SIZE 0x1000 /* Memory size - 4K bytes */
48 #define PCI_ACX100_REGION2 0x02
49 #define PCI_ACX100_REGION2_SIZE 0x10000 /* Memory size - 64K bytes */
51 #define PCI_ACX111_REGION1 0x00
52 #define PCI_ACX111_REGION1_SIZE 0x2000 /* Memory size - 8K bytes */
53 #define PCI_ACX111_REGION2 0x01
54 #define PCI_ACX111_REGION2_SIZE 0x20000 /* Memory size - 128K bytes */
56 /* Texas Instruments Vendor ID */
57 #define PCI_VENDOR_ID_TI 0x104c
59 /* ACX100 22Mb/s WLAN controller */
60 #define PCI_DEVICE_ID_TI_TNETW1100A 0x8400
61 #define PCI_DEVICE_ID_TI_TNETW1100B 0x8401
63 /* ACX111 54Mb/s WLAN controller */
64 #define PCI_DEVICE_ID_TI_TNETW1130 0x9066
66 /* PCI Class & Sub-Class code, Network-'Other controller' */
67 #define PCI_CLASS_NETWORK_OTHERS 0x0280
69 #define CARD_EEPROM_ID_SIZE 6
72 /* From include/linux/pci.h */
79 #define PCI_POWER_ERROR -1
81 #endif /* CONFIG_PCI */
83 /***********************************************************************
86 static irqreturn_t
acxpci_i_interrupt(int irq
, void *dev_id
);
88 static void disable_acx_irq(acx_device_t
* adev
);
90 static int acxpci_e_open(struct ieee80211_hw
*hw
);
91 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
92 static int acxpci_e_close(struct ieee80211_hw
*hw
);
94 static void acxpci_e_close(struct ieee80211_hw
*hw
);
96 static void acxpci_s_up(struct ieee80211_hw
*hw
);
97 static void acxpci_s_down(struct ieee80211_hw
*hw
);
99 void acxpci_put_devname(acx_device_t
*adev
, struct ethtool_drvinfo
*info
)
101 strncpy(info
->bus_info
,pci_name(adev
->pdev
), ETHTOOL_BUSINFO_LEN
);
104 /***********************************************************************
110 /* OS I/O routines *always* be endianness-clean but having them doesn't hurt */
111 #define acx_readl(v) le32_to_cpu(readl((v)))
112 #define acx_readw(v) le16_to_cpu(readw((v)))
113 #define acx_writew(v,r) writew(le16_to_cpu((v)), r)
114 #define acx_writel(v,r) writel(le32_to_cpu((v)), r)
117 /* #define INLINE_IO static */
118 #define INLINE_IO static inline
120 INLINE_IO u32
read_reg32(acx_device_t
* adev
, unsigned int offset
)
122 #if ACX_IO_WIDTH == 32
123 return acx_readl((u8
*) adev
->iobase
+ adev
->io
[offset
]);
125 return acx_readw((u8
*) adev
->iobase
+ adev
->io
[offset
])
126 + (acx_readw((u8
*) adev
->iobase
+ adev
->io
[offset
] + 2) << 16);
130 INLINE_IO u16
read_reg16(acx_device_t
* adev
, unsigned int offset
)
132 return acx_readw((u8
*) adev
->iobase
+ adev
->io
[offset
]);
135 INLINE_IO u8
read_reg8(acx_device_t
* adev
, unsigned int offset
)
137 return readb((u8
*) adev
->iobase
+ adev
->io
[offset
]);
140 INLINE_IO
void write_reg32(acx_device_t
* adev
, unsigned int offset
, u32 val
)
142 #if ACX_IO_WIDTH == 32
143 acx_writel(val
, (u8
*) adev
->iobase
+ adev
->io
[offset
]);
145 acx_writew(val
& 0xffff, (u8
*) adev
->iobase
+ adev
->io
[offset
]);
146 acx_writew(val
>> 16, (u8
*) adev
->iobase
+ adev
->io
[offset
] + 2);
150 INLINE_IO
void write_reg16(acx_device_t
* adev
, unsigned int offset
, u16 val
)
152 acx_writew(val
, (u8
*) adev
->iobase
+ adev
->io
[offset
]);
155 INLINE_IO
void write_reg8(acx_device_t
* adev
, unsigned int offset
, u8 val
)
157 writeb(val
, (u8
*) adev
->iobase
+ adev
->io
[offset
]);
160 /* Handle PCI posting properly:
161 * Make sure that writes reach the adapter in case they require to be executed
162 * *before* the next write, by reading a random (and safely accessible) register.
163 * This call has to be made if there is no read following (which would flush the data
164 * to the adapter), yet the written data has to reach the adapter immediately. */
165 INLINE_IO
void write_flush(acx_device_t
* adev
)
167 /* readb(adev->iobase + adev->io[IO_ACX_INFO_MAILBOX_OFFS]); */
168 /* faster version (accesses the first register, IO_ACX_SOFT_RESET,
169 * which should also be safe): */
173 INLINE_IO
int adev_present(acx_device_t
* adev
)
175 /* fast version (accesses the first register, IO_ACX_SOFT_RESET,
176 * which should be safe): */
177 return acx_readl(adev
->iobase
) != 0xffffffff;
181 /***********************************************************************
183 static inline txdesc_t
*get_txdesc(acx_device_t
* adev
, int index
)
185 return (txdesc_t
*) (((u8
*) adev
->txdesc_start
) +
186 index
* adev
->txdesc_size
);
189 static inline txdesc_t
*advance_txdesc(acx_device_t
* adev
, txdesc_t
* txdesc
,
192 return (txdesc_t
*) (((u8
*) txdesc
) + inc
* adev
->txdesc_size
);
195 static txhostdesc_t
*get_txhostdesc(acx_device_t
* adev
, txdesc_t
* txdesc
)
197 int index
= (u8
*) txdesc
- (u8
*) adev
->txdesc_start
;
198 if (unlikely(ACX_DEBUG
&& (index
% adev
->txdesc_size
))) {
199 printk("bad txdesc ptr %p\n", txdesc
);
202 index
/= adev
->txdesc_size
;
203 if (unlikely(ACX_DEBUG
&& (index
>= TX_CNT
))) {
204 printk("bad txdesc ptr %p\n", txdesc
);
207 return &adev
->txhostdesc_start
[index
* 2];
214 /***********************************************************************
215 ** EEPROM and PHY read/write helpers
217 /***********************************************************************
218 ** acxpci_read_eeprom_byte
220 ** Function called to read an octet in the EEPROM.
222 ** This function is used by acxpci_e_probe to check if the
223 ** connected card is a legal one or not.
226 ** adev ptr to acx_device structure
227 ** addr address to read in the EEPROM
228 ** charbuf ptr to a char. This is where the read octet
232 int acxpci_read_eeprom_byte(acx_device_t
* adev
, u32 addr
, u8
* charbuf
)
239 write_reg32(adev
, IO_ACX_EEPROM_CFG
, 0);
240 write_reg32(adev
, IO_ACX_EEPROM_ADDR
, addr
);
242 write_reg32(adev
, IO_ACX_EEPROM_CTL
, 2);
245 while (read_reg16(adev
, IO_ACX_EEPROM_CTL
)) {
246 /* scheduling away instead of CPU burning loop
247 * doesn't seem to work here at all:
248 * awful delay, sometimes also failure.
249 * Doesn't matter anyway (only small delay). */
250 if (unlikely(!--count
)) {
251 printk("%s: timeout waiting for EEPROM read\n",
252 wiphy_name(adev
->ieee
->wiphy
));
259 *charbuf
= read_reg8(adev
, IO_ACX_EEPROM_DATA
);
260 log(L_DEBUG
, "EEPROM at 0x%04X = 0x%02X\n", addr
, *charbuf
);
269 /***********************************************************************
270 ** We don't lock hw accesses here since we never r/w eeprom in IRQ
271 ** Note: this function sleeps only because of GFP_KERNEL alloc
275 acxpci_s_write_eeprom(acx_device_t
* adev
, u32 addr
, u32 len
,
278 u8
*data_verify
= NULL
;
284 printk("acx: WARNING! I would write to EEPROM now. "
285 "Since I really DON'T want to unless you know "
286 "what you're doing (THIS CODE WILL PROBABLY "
287 "NOT WORK YET!), I will abort that now. And "
288 "definitely make sure to make a "
289 "/proc/driver/acx_wlan0_eeprom backup copy first!!! "
290 "(the EEPROM content includes the PCI config header!! "
291 "If you kill important stuff, then you WILL "
292 "get in trouble and people DID get in trouble already)\n");
297 data_verify
= kmalloc(len
, GFP_KERNEL
);
302 /* first we need to enable the OE (EEPROM Output Enable) GPIO line
303 * to be able to write to the EEPROM.
304 * NOTE: an EEPROM writing success has been reported,
305 * but you probably have to modify GPIO_OUT, too,
306 * and you probably need to activate a different GPIO
308 gpio_orig
= read_reg16(adev
, IO_ACX_GPIO_OE
);
309 write_reg16(adev
, IO_ACX_GPIO_OE
, gpio_orig
& ~1);
312 /* ok, now start writing the data out */
313 for (i
= 0; i
< len
; i
++) {
314 write_reg32(adev
, IO_ACX_EEPROM_CFG
, 0);
315 write_reg32(adev
, IO_ACX_EEPROM_ADDR
, addr
+ i
);
316 write_reg32(adev
, IO_ACX_EEPROM_DATA
, *(charbuf
+ i
));
318 write_reg32(adev
, IO_ACX_EEPROM_CTL
, 1);
321 while (read_reg16(adev
, IO_ACX_EEPROM_CTL
)) {
322 if (unlikely(!--count
)) {
323 printk("WARNING, DANGER!!! "
324 "Timeout waiting for EEPROM write\n");
331 /* disable EEPROM writing */
332 write_reg16(adev
, IO_ACX_GPIO_OE
, gpio_orig
);
335 /* now start a verification run */
336 for (i
= 0; i
< len
; i
++) {
337 write_reg32(adev
, IO_ACX_EEPROM_CFG
, 0);
338 write_reg32(adev
, IO_ACX_EEPROM_ADDR
, addr
+ i
);
340 write_reg32(adev
, IO_ACX_EEPROM_CTL
, 2);
343 while (read_reg16(adev
, IO_ACX_EEPROM_CTL
)) {
344 if (unlikely(!--count
)) {
345 printk("timeout waiting for EEPROM read\n");
351 data_verify
[i
] = read_reg16(adev
, IO_ACX_EEPROM_DATA
);
354 if (0 == memcmp(charbuf
, data_verify
, len
))
355 result
= OK
; /* read data matches, success */
365 /***********************************************************************
366 ** acxpci_s_read_phy_reg
368 ** Messing with rx/tx disabling and enabling here
369 ** (write_reg32(adev, IO_ACX_ENABLE, 0b000000xx)) kills traffic
371 int acxpci_s_read_phy_reg(acx_device_t
* adev
, u32 reg
, u8
* charbuf
)
378 write_reg32(adev
, IO_ACX_PHY_ADDR
, reg
);
380 write_reg32(adev
, IO_ACX_PHY_CTL
, 2);
383 while (read_reg32(adev
, IO_ACX_PHY_CTL
)) {
384 /* scheduling away instead of CPU burning loop
385 * doesn't seem to work here at all:
386 * awful delay, sometimes also failure.
387 * Doesn't matter anyway (only small delay). */
388 if (unlikely(!--count
)) {
389 printk("%s: timeout waiting for phy read\n",
390 wiphy_name(adev
->ieee
->wiphy
));
397 log(L_DEBUG
, "count was %u\n", count
);
398 *charbuf
= read_reg8(adev
, IO_ACX_PHY_DATA
);
400 log(L_DEBUG
, "radio PHY at 0x%04X = 0x%02X\n", *charbuf
, reg
);
402 goto fail
; /* silence compiler warning */
409 /***********************************************************************
411 int acxpci_s_write_phy_reg(acx_device_t
* adev
, u32 reg
, u8 value
)
415 /* mprusko said that 32bit accesses result in distorted sensitivity
416 * on his card. Unconfirmed, looks like it's not true (most likely since we
417 * now properly flush writes). */
418 write_reg32(adev
, IO_ACX_PHY_DATA
, value
);
419 write_reg32(adev
, IO_ACX_PHY_ADDR
, reg
);
421 write_reg32(adev
, IO_ACX_PHY_CTL
, 1);
423 log(L_DEBUG
, "radio PHY write 0x%02X at 0x%04X\n", value
, reg
);
430 #define NO_AUTO_INCREMENT 1
432 /***********************************************************************
435 ** Write the firmware image into the card.
438 ** adev wlan device structure
439 ** fw_image firmware image.
442 ** 1 firmware image corrupted
445 ** Standard csum implementation + write to IO
448 acxpci_s_write_fw(acx_device_t
* adev
, const firmware_image_t
*fw_image
,
453 /* we skip the first four bytes which contain the control sum */
455 const u8
*p
= (u8
*) fw_image
+ 4;
459 /* start the image checksum by adding the image size value */
460 sum
= p
[0] + p
[1] + p
[2] + p
[3];
463 write_reg32(adev
, IO_ACX_SLV_END_CTL
, 0);
465 #if NO_AUTO_INCREMENT
466 write_reg32(adev
, IO_ACX_SLV_MEM_CTL
, 0); /* use basic mode */
468 write_reg32(adev
, IO_ACX_SLV_MEM_CTL
, 1); /* use autoincrement mode */
469 write_reg32(adev
, IO_ACX_SLV_MEM_ADDR
, offset
); /* configure start address */
474 size
= le32_to_cpu(fw_image
->size
) & (~3);
476 while (likely(len
< size
)) {
477 v32
= be32_to_cpu(*(u32
*) p
);
478 sum
+= p
[0] + p
[1] + p
[2] + p
[3];
482 #if NO_AUTO_INCREMENT
483 write_reg32(adev
, IO_ACX_SLV_MEM_ADDR
, offset
+ len
- 4);
486 write_reg32(adev
, IO_ACX_SLV_MEM_DATA
, v32
);
489 log(L_DEBUG
, "firmware written, size:%d sum1:%x sum2:%x\n",
490 size
, sum
, le32_to_cpu(fw_image
->chksum
));
492 /* compare our checksum with the stored image checksum */
493 FN_EXIT1(sum
!= le32_to_cpu(fw_image
->chksum
));
494 return (sum
!= le32_to_cpu(fw_image
->chksum
));
498 /***********************************************************************
499 ** acxpci_s_validate_fw
501 ** Compare the firmware image given with
502 ** the firmware image written into the card.
505 ** adev wlan device structure
506 ** fw_image firmware image.
509 ** NOT_OK firmware image corrupted or not correctly written
512 ** Origin: Standard csum + Read IO
515 acxpci_s_validate_fw(acx_device_t
* adev
, const firmware_image_t
*fw_image
,
521 /* we skip the first four bytes which contain the control sum */
522 const u8
*p
= (u8
*) fw_image
+ 4;
526 /* start the image checksum by adding the image size value */
527 sum
= p
[0] + p
[1] + p
[2] + p
[3];
530 write_reg32(adev
, IO_ACX_SLV_END_CTL
, 0);
532 #if NO_AUTO_INCREMENT
533 write_reg32(adev
, IO_ACX_SLV_MEM_CTL
, 0); /* use basic mode */
535 write_reg32(adev
, IO_ACX_SLV_MEM_CTL
, 1); /* use autoincrement mode */
536 write_reg32(adev
, IO_ACX_SLV_MEM_ADDR
, offset
); /* configure start address */
540 size
= le32_to_cpu(fw_image
->size
) & (~3);
542 while (likely(len
< size
)) {
543 v32
= be32_to_cpu(*(u32
*) p
);
547 #if NO_AUTO_INCREMENT
548 write_reg32(adev
, IO_ACX_SLV_MEM_ADDR
, offset
+ len
- 4);
550 w32
= read_reg32(adev
, IO_ACX_SLV_MEM_DATA
);
552 if (unlikely(w32
!= v32
)) {
553 printk("acx: FATAL: firmware upload: "
554 "data parts at offset %d don't match (0x%08X vs. 0x%08X)! "
555 "I/O timing issues or defective memory, with DWL-xx0+? "
556 "ACX_IO_WIDTH=16 may help. Please report\n",
563 (u8
) w32
+ (u8
) (w32
>> 8) + (u8
) (w32
>> 16) +
567 /* sum control verification */
568 if (result
!= NOT_OK
) {
569 if (sum
!= le32_to_cpu(fw_image
->chksum
)) {
570 printk("acx: FATAL: firmware upload: "
571 "checksums don't match!\n");
581 /***********************************************************************
582 ** acxpci_s_upload_fw
584 ** Called from acx_reset_dev
586 ** Origin: Derived from FW dissection
588 static int acxpci_s_upload_fw(acx_device_t
* adev
)
590 firmware_image_t
*fw_image
= NULL
;
594 char filename
[sizeof("tiacx1NNcNN")];
598 /* print exact chipset and radio ID to make sure people
599 * really get a clue on which files exactly they need to provide.
600 * Firmware loading is a frequent end-user PITA with these chipsets.
602 printk( "acx: need firmware for acx1%02d chipset with radio ID %02X\n"
603 "Please provide via firmware hotplug:\n"
604 "either combined firmware (single file named 'tiacx1%02dc%02X')\n"
605 "or two files (base firmware file 'tiacx1%02d' "
606 "+ radio fw 'tiacx1%02dr%02X')\n",
607 IS_ACX111(adev
)*11, adev
->radio_type
,
608 IS_ACX111(adev
)*11, adev
->radio_type
,
610 IS_ACX111(adev
)*11, adev
->radio_type
613 /* print exact chipset and radio ID to make sure people really get a clue on which files exactly they are supposed to provide,
614 * since firmware loading is the biggest enduser PITA with these chipsets.
615 * Not printing radio ID in 0xHEX in order to not confuse them into wrong file naming */
616 printk( "acx: need to load firmware for acx1%02d chipset with radio ID %02x, please provide via firmware hotplug:\n"
617 "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",
618 IS_ACX111(adev
)*11, adev
->radio_type
);
620 /* Try combined, then main image */
621 adev
->need_radio_fw
= 0;
622 snprintf(filename
, sizeof(filename
), "tiacx1%02dc%02X",
623 IS_ACX111(adev
) * 11, adev
->radio_type
);
625 fw_image
= acx_s_read_fw(adev
->bus_dev
, filename
, &file_size
);
627 adev
->need_radio_fw
= 1;
628 filename
[sizeof("tiacx1NN") - 1] = '\0';
630 acx_s_read_fw(adev
->bus_dev
, filename
, &file_size
);
637 for (try = 1; try <= 5; try++) {
638 res
= acxpci_s_write_fw(adev
, fw_image
, 0);
639 log(L_DEBUG
| L_INIT
, "acx_write_fw (main/combined): %d\n", res
);
641 res
= acxpci_s_validate_fw(adev
, fw_image
, 0);
642 log(L_DEBUG
| L_INIT
, "acx_validate_fw "
643 "(main/combined): %d\n", res
);
647 SET_BIT(adev
->dev_state_mask
, ACX_STATE_FW_LOADED
);
650 printk("acx: firmware upload attempt #%d FAILED, "
651 "retrying...\n", try);
652 acx_s_mwait(1000); /* better wait for a while... */
662 /***********************************************************************
663 ** acxpci_s_upload_radio
665 ** Uploads the appropriate radio module firmware into the card.
667 ** Origin: Standard Read/Write to IO
669 int acxpci_s_upload_radio(acx_device_t
* adev
)
672 firmware_image_t
*radio_image
;
673 acx_cmd_radioinit_t radioinit
;
678 char filename
[sizeof("tiacx1NNrNN")];
680 if (!adev
->need_radio_fw
)
685 acx_s_interrogate(adev
, &mm
, ACX1xx_IE_MEMORY_MAP
);
686 offset
= le32_to_cpu(mm
.CodeEnd
);
688 snprintf(filename
, sizeof(filename
), "tiacx1%02dr%02X",
689 IS_ACX111(adev
) * 11, adev
->radio_type
);
690 radio_image
= acx_s_read_fw(adev
->bus_dev
, filename
, &size
);
692 printk("acx: can't load radio module '%s'\n", filename
);
696 acx_s_issue_cmd(adev
, ACX1xx_CMD_SLEEP
, NULL
, 0);
698 for (try = 1; try <= 5; try++) {
699 res
= acxpci_s_write_fw(adev
, radio_image
, offset
);
700 log(L_DEBUG
| L_INIT
, "acx_write_fw (radio): %d\n", res
);
702 res
= acxpci_s_validate_fw(adev
, radio_image
, offset
);
703 log(L_DEBUG
| L_INIT
, "acx_validate_fw (radio): %d\n",
709 printk("acx: radio firmware upload attempt #%d FAILED, "
710 "retrying...\n", try);
711 acx_s_mwait(1000); /* better wait for a while... */
714 acx_s_issue_cmd(adev
, ACX1xx_CMD_WAKE
, NULL
, 0);
715 radioinit
.offset
= cpu_to_le32(offset
);
716 /* no endian conversion needed, remains in card CPU area: */
717 radioinit
.len
= radio_image
->size
;
724 /* will take a moment so let's have a big timeout */
725 acx_s_issue_cmd_timeo(adev
, ACX1xx_CMD_RADIOINIT
,
726 &radioinit
, sizeof(radioinit
),
727 CMD_TIMEOUT_MS(1000));
729 res
= acx_s_interrogate(adev
, &mm
, ACX1xx_IE_MEMORY_MAP
);
736 /***********************************************************************
737 ** acxpci_l_reset_mac
740 ** Call context: reset_dev
742 ** Origin: Standard Read/Write to IO
744 static void acxpci_l_reset_mac(acx_device_t
* adev
)
751 temp
= read_reg16(adev
, IO_ACX_ECPU_CTRL
) | 0x1;
752 write_reg16(adev
, IO_ACX_ECPU_CTRL
, temp
);
754 /* now do soft reset of eCPU, set bit */
755 temp
= read_reg16(adev
, IO_ACX_SOFT_RESET
) | 0x1;
756 log(L_DEBUG
, "enable soft reset\n");
757 write_reg16(adev
, IO_ACX_SOFT_RESET
, temp
);
760 /* now clear bit again: deassert eCPU reset */
761 log(L_DEBUG
, "disable soft reset and go to init mode");
762 write_reg16(adev
, IO_ACX_SOFT_RESET
, temp
& ~0x1);
764 /* now start a burst read from initial EEPROM */
765 temp
= read_reg16(adev
, IO_ACX_EE_START
) | 0x1;
766 write_reg16(adev
, IO_ACX_EE_START
, temp
);
773 /***********************************************************************
774 ** acxpci_s_verify_init
776 static int acxpci_s_verify_init(acx_device_t
* adev
)
779 unsigned long timeout
;
783 timeout
= jiffies
+ 2 * HZ
;
785 u16 irqstat
= read_reg16(adev
, IO_ACX_IRQ_STATUS_NON_DES
);
786 if (irqstat
& HOST_INT_FCS_THRESHOLD
) {
788 write_reg16(adev
, IO_ACX_IRQ_ACK
,
789 HOST_INT_FCS_THRESHOLD
);
792 if (time_after(jiffies
, timeout
))
794 /* Init may take up to ~0.5 sec total */
803 /***********************************************************************
804 ** A few low-level helpers
806 ** Note: these functions are not protected by lock
807 ** and thus are never allowed to be called from IRQ.
808 ** Also they must not race with fw upload which uses same hw regs
811 /***********************************************************************
812 ** acxpci_write_cmd_type_status
814 ** Origin: Common linux implementation
818 acxpci_write_cmd_type_status(acx_device_t
* adev
, u16 type
, u16 status
)
821 acx_writel(type
| (status
<< 16), adev
->cmd_area
);
827 /***********************************************************************
828 ** acxpci_read_cmd_type_status
830 ** Origin: Common linux implementation
832 static u32
acxpci_read_cmd_type_status(acx_device_t
* adev
)
834 u32 cmd_type
, cmd_status
;
838 cmd_type
= acx_readl(adev
->cmd_area
);
839 cmd_status
= (cmd_type
>> 16);
840 cmd_type
= (u16
) cmd_type
;
842 log(L_CTL
, "cmd_type:%04X cmd_status:%04X [%s]\n",
843 cmd_type
, cmd_status
, acx_cmd_status_str(cmd_status
));
845 FN_EXIT1(cmd_status
);
850 /***********************************************************************
851 ** acxpci_s_reset_dev
854 ** netdevice that contains the adev variable
859 ** device is hard reset
863 ** This resets the device using low level hardware calls
864 ** as well as uploads and verifies the firmware to the card
867 static inline void init_mboxes(acx_device_t
* adev
)
869 u32 cmd_offs
, info_offs
;
873 cmd_offs
= read_reg32(adev
, IO_ACX_CMD_MAILBOX_OFFS
);
874 info_offs
= read_reg32(adev
, IO_ACX_INFO_MAILBOX_OFFS
);
875 adev
->cmd_area
= (u8
*) adev
->iobase2
+ cmd_offs
;
876 adev
->info_area
= (u8
*) adev
->iobase2
+ info_offs
;
877 log(L_DEBUG
, "iobase2=%p\n"
878 "cmd_mbox_offset=%X cmd_area=%p\n"
879 "info_mbox_offset=%X info_area=%p\n",
881 cmd_offs
, adev
->cmd_area
, info_offs
, adev
->info_area
);
886 static inline void read_eeprom_area(acx_device_t
* adev
)
894 for (offs
= 0x8c; offs
< 0xb9; offs
++)
895 acxpci_read_eeprom_byte(adev
, offs
, &tmp
);
902 int acxpci_s_reset_dev(acx_device_t
* adev
)
904 const char *msg
= "";
913 /* reset the device to make sure the eCPU is stopped
914 * to upload the firmware correctly */
916 acx_lock(adev
, flags
);
919 acxpci_l_reset_mac(adev
);
922 ecpu_ctrl
= read_reg16(adev
, IO_ACX_ECPU_CTRL
) & 1;
924 msg
= "eCPU is already running. ";
928 if (read_reg16(adev
, IO_ACX_SOR_CFG
) & 2) {
929 /* eCPU most likely means "embedded CPU" */
930 msg
= "eCPU did not start after boot from flash. ";
934 /* check sense on reset flags */
935 if (read_reg16(adev
, IO_ACX_SOR_CFG
) & 0x10) {
936 printk("%s: eCPU did not start after boot (SOR), "
937 "is this fatal?\n", wiphy_name(adev
->ieee
->wiphy
));
940 /* scan, if any, is stopped now, setting corresponding IRQ bit */
941 SET_BIT(adev
->irq_status
, HOST_INT_SCAN_COMPLETE
);
943 acx_unlock(adev
, flags
);
945 /* need to know radio type before fw load */
946 /* Need to wait for arrival of this information in a loop,
947 * most probably since eCPU runs some init code from EEPROM
948 * (started burst read in reset_mac()) which also
949 * sets the radio type ID */
953 hardware_info
= read_reg16(adev
, IO_ACX_EEPROM_INFORMATION
);
955 msg
= "eCPU didn't indicate radio type";
959 } while (!(hardware_info
& 0xff00)); /* radio type still zero? */
961 /* printk("DEBUG: count %d\n", count); */
962 adev
->form_factor
= hardware_info
& 0xff;
963 adev
->radio_type
= hardware_info
>> 8;
965 /* load the firmware */
966 if (OK
!= acxpci_s_upload_fw(adev
))
969 /* acx_s_mwait(10); this one really shouldn't be required */
971 /* now start eCPU by clearing bit */
972 write_reg16(adev
, IO_ACX_ECPU_CTRL
, ecpu_ctrl
& ~0x1);
973 log(L_DEBUG
, "booted eCPU up and waiting for completion...\n");
975 /* wait for eCPU bootup */
976 if (OK
!= acxpci_s_verify_init(adev
)) {
977 msg
= "timeout waiting for eCPU. ";
980 log(L_DEBUG
, "eCPU has woken up, card is ready to be configured\n");
983 acxpci_write_cmd_type_status(adev
, 0, 0);
985 /* test that EEPROM is readable */
986 read_eeprom_area(adev
);
991 /* Finish error message. Indicate which function failed */
993 acx_unlock(adev
, flags
);
995 printk("acx: %sreset_dev() FAILED\n", msg
);
1002 /***********************************************************************
1003 ** acxpci_s_issue_cmd_timeo
1005 ** Sends command to fw, extract result
1007 ** NB: we do _not_ take lock inside, so be sure to not touch anything
1008 ** which may interfere with IRQ handler operation
1010 ** TODO: busy wait is a bit silly, so:
1011 ** 1) stop doing many iters - go to sleep after first
1012 ** 2) go to waitqueue based approach: wait, not poll!
1015 #define FUNC "issue_cmd"
1019 acxpci_s_issue_cmd_timeo(acx_device_t
* adev
,
1021 void *buffer
, unsigned buflen
, unsigned cmd_timeout
)
1025 acxpci_s_issue_cmd_timeo_debug(acx_device_t
* adev
,
1029 unsigned cmd_timeout
, const char *cmdstr
)
1031 unsigned long start
= jiffies
;
1033 const char *devname
;
1037 unsigned long timeout
;
1041 devname
= wiphy_name(adev
->ieee
->wiphy
);
1042 if (!devname
|| !devname
[0] || devname
[4] == '%')
1045 log(L_CTL
, FUNC
"(cmd:%s,buflen:%u,timeout:%ums,type:0x%04X)\n",
1046 cmdstr
, buflen
, cmd_timeout
,
1047 buffer
? le16_to_cpu(((acx_ie_generic_t
*) buffer
)->type
) : -1);
1049 if (!(adev
->dev_state_mask
& ACX_STATE_FW_LOADED
)) {
1050 printk("%s: " FUNC
"(): firmware is not loaded yet, "
1051 "cannot execute commands!\n", devname
);
1055 if ((acx_debug
& L_DEBUG
) && (cmd
!= ACX1xx_CMD_INTERROGATE
)) {
1056 printk("input buffer (len=%u):\n", buflen
);
1057 acx_dump_bytes(buffer
, buflen
);
1060 /* wait for firmware to become idle for our command submission */
1062 counter
= (timeout
* 1000 / HZ
) - 1; /* in ms */
1065 cmd_status
= acxpci_read_cmd_type_status(adev
);
1066 /* Test for IDLE state */
1069 if (counter
% 8 == 0) {
1070 if (time_after(jiffies
, timeout
)) {
1074 /* we waited 8 iterations, no luck. Sleep 8 ms */
1077 } while (likely(--counter
));
1080 /* the card doesn't get idle, we're in trouble */
1081 printk("%s: " FUNC
"(): cmd_status is not IDLE: 0x%04X!=0\n",
1082 devname
, cmd_status
);
1084 } else if (counter
< 190) { /* if waited >10ms... */
1085 log(L_CTL
| L_DEBUG
, FUNC
"(): waited for IDLE %dms. "
1086 "Please report\n", 199 - counter
);
1089 /* now write the parameters of the command if needed */
1090 if (buffer
&& buflen
) {
1091 /* if it's an INTERROGATE command, just pass the length
1092 * of parameters to read, as data */
1094 if (cmd
== ACX1xx_CMD_INTERROGATE
)
1095 memset_io(adev
->cmd_area
+ 4, 0xAA, buflen
);
1097 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1098 memcpy_toio(adev
->cmd_area
+ 4, buffer
,
1099 (cmd
== ACX1xx_CMD_INTERROGATE
) ? 4 : buflen
);
1101 /* now write the actual command type */
1102 acxpci_write_cmd_type_status(adev
, cmd
, 0);
1103 /* execute command */
1104 write_reg16(adev
, IO_ACX_INT_TRIG
, INT_TRIG_CMD
);
1107 /* wait for firmware to process command */
1109 /* Ensure nonzero and not too large timeout.
1110 ** Also converts e.g. 100->99, 200->199
1111 ** which is nice but not essential */
1112 cmd_timeout
= (cmd_timeout
- 1) | 1;
1113 if (unlikely(cmd_timeout
> 1199))
1115 /* clear CMD_COMPLETE bit. can be set only by IRQ handler: */
1116 CLEAR_BIT(adev
->irq_status
, HOST_INT_CMD_COMPLETE
);
1117 /* we schedule away sometimes (timeout can be large) */
1118 counter
= cmd_timeout
;
1119 timeout
= jiffies
+ HZ
;
1121 if (!adev
->irqs_active
) { /* IRQ disabled: poll */
1122 irqtype
= read_reg16(adev
, IO_ACX_IRQ_STATUS_NON_DES
);
1123 if (irqtype
& HOST_INT_CMD_COMPLETE
) {
1124 write_reg16(adev
, IO_ACX_IRQ_ACK
,
1125 HOST_INT_CMD_COMPLETE
);
1128 } else { /* Wait when IRQ will set the bit */
1129 irqtype
= adev
->irq_status
;
1130 if (irqtype
& HOST_INT_CMD_COMPLETE
)
1134 if (counter
% 8 == 0) {
1135 if (time_after(jiffies
, timeout
)) {
1139 /* we waited 8 iterations, no luck. Sleep 8 ms */
1142 } while (likely(--counter
));
1144 /* save state for debugging */
1145 cmd_status
= acxpci_read_cmd_type_status(adev
);
1147 /* put the card in IDLE state */
1148 acxpci_write_cmd_type_status(adev
, 0, 0);
1150 if ((cmd_timeout
- counter
) == 0) { /* timed out! */
1151 printk("%s: " FUNC
"(): timed out %s for CMD_COMPLETE. "
1152 "irq bits:0x%04X irq_status:0x%04X timeout:%dms "
1153 "cmd_status:%d (%s)\n",
1154 devname
, (adev
->irqs_active
) ? "waiting" : "polling",
1155 irqtype
, adev
->irq_status
, cmd_timeout
,
1156 cmd_status
, acx_cmd_status_str(cmd_status
));
1157 printk("hack: don't do: 'goto bad;'\ncounter: %d cmd_timeout: %d cmd_timeout-counter: %d\n",counter
, cmd_timeout
, cmd_timeout
- counter
);
1158 } else if (counter
== 0) { /* maybe timed out! */
1159 log(L_CTL
| L_DEBUG
, FUNC
"(): %s for CMD_COMPLETE %dms. "
1160 "count:%d. Please report\n",
1161 (adev
->irqs_active
) ? "waited" : "polled",
1162 cmd_timeout
- counter
, counter
);
1163 } else if ((cmd_timeout
- counter
) > 30) { /* if waited >30ms... */
1164 log(L_CTL
| L_DEBUG
, FUNC
"(): %s for CMD_COMPLETE %dms. "
1165 "count:%d. Please report\n",
1166 (adev
->irqs_active
) ? "waited" : "polled",
1167 cmd_timeout
- counter
, counter
);
1170 if (1 != cmd_status
) { /* it is not a 'Success' */
1171 printk("%s: " FUNC
"(): cmd_status is not SUCCESS: %d (%s). "
1172 "Took %dms of %d\n",
1173 devname
, cmd_status
, acx_cmd_status_str(cmd_status
),
1174 cmd_timeout
- counter
, cmd_timeout
);
1175 /* zero out result buffer
1176 * WARNING: this will trash stack in case of illegally large input
1178 if (buffer
&& buflen
)
1179 memset(buffer
, 0, buflen
);
1183 /* read in result parameters if needed */
1184 if (buffer
&& buflen
&& (cmd
== ACX1xx_CMD_INTERROGATE
)) {
1185 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1186 memcpy_fromio(buffer
, adev
->cmd_area
+ 4, buflen
);
1187 if (acx_debug
& L_DEBUG
) {
1188 printk("output buffer (len=%u): ", buflen
);
1189 acx_dump_bytes(buffer
, buflen
);
1193 log(L_CTL
, FUNC
"(%s): took %ld jiffies to complete\n",
1194 cmdstr
, jiffies
- start
);
1199 /* Give enough info so that callers can avoid
1200 ** printing their own diagnostic messages */
1202 printk("%s: " FUNC
"(cmd:%s) FAILED\n", devname
, cmdstr
);
1204 printk("%s: " FUNC
"(cmd:0x%04X) FAILED\n", devname
, cmd
);
1212 /***********************************************************************
1214 #ifdef NONESSENTIAL_FEATURES
1215 typedef struct device_id
{
1216 unsigned char id
[6];
1221 static const device_id_t device_ids
[] = {
1223 {'G', 'l', 'o', 'b', 'a', 'l'},
1228 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
1230 "SpeedStream SS1021 or Gigafast WF721-AEX"},
1232 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85},
1234 "DrayTek Vigor 520"},
1236 {'?', '?', '?', '?', '?', '?'},
1238 "Level One WPC-0200"},
1240 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1245 static void acx_show_card_eeprom_id(acx_device_t
* adev
)
1247 unsigned char buffer
[CARD_EEPROM_ID_SIZE
];
1252 memset(&buffer
, 0, CARD_EEPROM_ID_SIZE
);
1253 /* use direct EEPROM access */
1254 for (i
= 0; i
< CARD_EEPROM_ID_SIZE
; i
++) {
1255 if (OK
!= acxpci_read_eeprom_byte(adev
,
1256 ACX100_EEPROM_ID_OFFSET
+ i
,
1258 printk("acx: reading EEPROM FAILED\n");
1263 for (i
= 0; i
< ARRAY_SIZE(device_ids
); i
++) {
1264 if (!memcmp(&buffer
, device_ids
[i
].id
, CARD_EEPROM_ID_SIZE
)) {
1265 if (device_ids
[i
].descr
) {
1266 printk("acx: EEPROM card ID string check "
1267 "found %s card ID: is this %s?\n",
1268 device_ids
[i
].descr
, device_ids
[i
].type
);
1273 if (i
== ARRAY_SIZE(device_ids
)) {
1274 printk("acx: EEPROM card ID string check found "
1275 "unknown card: expected 'Global', got '%.*s\'. "
1276 "Please report\n", CARD_EEPROM_ID_SIZE
, buffer
);
1280 #endif /* NONESSENTIAL_FEATURES */
1283 /***********************************************************************
1284 ** acxpci_free_desc_queues
1286 ** Releases the queues that have been allocated, the
1287 ** others have been initialised to NULL so this
1288 ** function can be used if only part of the queues were allocated.
1292 free_coherent(struct pci_dev
*hwdev
, size_t size
,
1293 void *vaddr
, dma_addr_t dma_handle
)
1295 dma_free_coherent(hwdev
== NULL
? NULL
: &hwdev
->dev
,
1296 size
, vaddr
, dma_handle
);
1300 void acxpci_free_desc_queues(acx_device_t
* adev
)
1302 unsigned long flags
;
1304 #define ACX_FREE_QUEUE(size, ptr, phyaddr) \
1306 free_coherent(NULL, size, ptr, phyaddr); \
1313 ACX_FREE_QUEUE(adev
->txhostdesc_area_size
, adev
->txhostdesc_start
,
1314 adev
->txhostdesc_startphy
);
1315 ACX_FREE_QUEUE(adev
->txbuf_area_size
, adev
->txbuf_start
,
1316 adev
->txbuf_startphy
);
1318 acx_lock(adev
, flags
);
1319 adev
->txdesc_start
= NULL
;
1320 acx_unlock(adev
, flags
);
1322 ACX_FREE_QUEUE(adev
->rxhostdesc_area_size
, adev
->rxhostdesc_start
,
1323 adev
->rxhostdesc_startphy
);
1324 ACX_FREE_QUEUE(adev
->rxbuf_area_size
, adev
->rxbuf_start
,
1325 adev
->rxbuf_startphy
);
1327 acx_lock(adev
, flags
);
1328 adev
->rxdesc_start
= NULL
;
1329 acx_unlock(adev
, flags
);
1335 /***********************************************************************
1336 ** acxpci_s_delete_dma_regions
1338 static void acxpci_s_delete_dma_regions(acx_device_t
* adev
)
1341 /* disable radio Tx/Rx. Shouldn't we use the firmware commands
1342 * here instead? Or are we that much down the road that it's no
1343 * longer possible here? */
1344 write_reg16(adev
, IO_ACX_ENABLE
, 0);
1348 /* NO locking for all parts of acxpci_free_desc_queues because:
1349 * while calling dma_free_coherent() interrupts need to be 'free'
1350 * but if you spinlock the whole function (acxpci_free_desc_queues)
1351 * you'll get an error */
1352 acxpci_free_desc_queues(adev
);
1358 /***********************************************************************
1361 ** Probe routine called when a PCI device w/ matching ID is found.
1362 ** Here's the sequence:
1363 ** - Allocate the PCI resources.
1364 ** - Read the PCMCIA attribute memory to make sure we have a WLAN card
1366 ** - Initialize the dev and wlan data
1367 ** - Initialize the MAC
1369 ** pdev - ptr to pci device structure containing info about pci configuration
1370 ** id - ptr to the device id entry that matched this device
1372 static const u16 IO_ACX100
[] = {
1373 0x0000, /* IO_ACX_SOFT_RESET */
1375 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1376 0x0018, /* IO_ACX_SLV_MEM_DATA */
1377 0x001c, /* IO_ACX_SLV_MEM_CTL */
1378 0x0020, /* IO_ACX_SLV_END_CTL */
1380 0x0034, /* IO_ACX_FEMR */
1382 0x007c, /* IO_ACX_INT_TRIG */
1383 0x0098, /* IO_ACX_IRQ_MASK */
1384 0x00a4, /* IO_ACX_IRQ_STATUS_NON_DES */
1385 0x00a8, /* IO_ACX_IRQ_STATUS_CLEAR */
1386 0x00ac, /* IO_ACX_IRQ_ACK */
1387 0x00b0, /* IO_ACX_HINT_TRIG */
1389 0x0104, /* IO_ACX_ENABLE */
1391 0x0250, /* IO_ACX_EEPROM_CTL */
1392 0x0254, /* IO_ACX_EEPROM_ADDR */
1393 0x0258, /* IO_ACX_EEPROM_DATA */
1394 0x025c, /* IO_ACX_EEPROM_CFG */
1396 0x0268, /* IO_ACX_PHY_ADDR */
1397 0x026c, /* IO_ACX_PHY_DATA */
1398 0x0270, /* IO_ACX_PHY_CTL */
1400 0x0290, /* IO_ACX_GPIO_OE */
1402 0x0298, /* IO_ACX_GPIO_OUT */
1404 0x02a4, /* IO_ACX_CMD_MAILBOX_OFFS */
1405 0x02a8, /* IO_ACX_INFO_MAILBOX_OFFS */
1406 0x02ac, /* IO_ACX_EEPROM_INFORMATION */
1408 0x02d0, /* IO_ACX_EE_START */
1409 0x02d4, /* IO_ACX_SOR_CFG */
1410 0x02d8 /* IO_ACX_ECPU_CTRL */
1413 static const u16 IO_ACX111
[] = {
1414 0x0000, /* IO_ACX_SOFT_RESET */
1416 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1417 0x0018, /* IO_ACX_SLV_MEM_DATA */
1418 0x001c, /* IO_ACX_SLV_MEM_CTL */
1419 0x0020, /* IO_ACX_SLV_END_CTL */
1421 0x0034, /* IO_ACX_FEMR */
1423 0x00b4, /* IO_ACX_INT_TRIG */
1424 0x00d4, /* IO_ACX_IRQ_MASK */
1425 /* we do mean NON_DES (0xf0), not NON_DES_MASK which is at 0xe0: */
1426 0x00f0, /* IO_ACX_IRQ_STATUS_NON_DES */
1427 0x00e4, /* IO_ACX_IRQ_STATUS_CLEAR */
1428 0x00e8, /* IO_ACX_IRQ_ACK */
1429 0x00ec, /* IO_ACX_HINT_TRIG */
1431 0x01d0, /* IO_ACX_ENABLE */
1433 0x0338, /* IO_ACX_EEPROM_CTL */
1434 0x033c, /* IO_ACX_EEPROM_ADDR */
1435 0x0340, /* IO_ACX_EEPROM_DATA */
1436 0x0344, /* IO_ACX_EEPROM_CFG */
1438 0x0350, /* IO_ACX_PHY_ADDR */
1439 0x0354, /* IO_ACX_PHY_DATA */
1440 0x0358, /* IO_ACX_PHY_CTL */
1442 0x0374, /* IO_ACX_GPIO_OE */
1444 0x037c, /* IO_ACX_GPIO_OUT */
1446 0x0388, /* IO_ACX_CMD_MAILBOX_OFFS */
1447 0x038c, /* IO_ACX_INFO_MAILBOX_OFFS */
1448 0x0390, /* IO_ACX_EEPROM_INFORMATION */
1450 0x0100, /* IO_ACX_EE_START */
1451 0x0104, /* IO_ACX_SOR_CFG */
1452 0x0108, /* IO_ACX_ECPU_CTRL */
1455 static const struct ieee80211_ops acxpci_hw_ops
= {
1456 .tx
= acx_i_start_xmit
,
1457 .conf_tx
= acx_net_conf_tx
,
1458 .add_interface
= acx_add_interface
,
1459 .remove_interface
= acx_remove_interface
,
1460 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
1461 .open
= acxpci_e_open
,
1462 .reset
= acx_net_reset
,
1463 .set_multicast_list
= acx_i_set_multicast_list
,
1465 .start
= acxpci_e_open
,
1466 .configure_filter
= acx_i_set_multicast_list
,
1468 .stop
= acxpci_e_close
,
1469 .config
= acx_net_config
,
1470 .config_interface
= acx_config_interface
,
1471 .set_key
= acx_net_set_key
,
1472 .get_stats
= acx_e_get_stats
,
1473 .get_tx_stats
= acx_net_get_tx_stats
,
1478 static int __devinit
1479 acxpci_e_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1481 acx111_ie_configoption_t co
;
1482 unsigned long mem_region1
= 0;
1483 unsigned long mem_region2
= 0;
1484 unsigned long mem_region1_size
;
1485 unsigned long mem_region2_size
;
1486 unsigned long phymem1
;
1487 unsigned long phymem2
;
1490 acx_device_t
*adev
= NULL
;
1491 const char *chip_name
;
1495 struct ieee80211_hw
*ieee
;
1499 ieee
= ieee80211_alloc_hw(sizeof(struct acx_device
), &acxpci_hw_ops
);
1501 printk("acx: could not allocate ieee80211 structure %s\n",
1503 goto fail_alloc_netdev
;
1505 ieee
->flags
&= ~IEEE80211_HW_RX_INCLUDES_FCS
;
1506 /* TODO: mainline doesn't support the following flags yet */
1508 ~IEEE80211_HW_MONITOR_DURING_OPER &
1509 ~IEEE80211_HW_WEP_INCLUDE_IV;
1513 /* (NB: memsets to 0 entire area) */
1515 printk("acx: could not allocate ieee structure %s\n",
1517 goto fail_alloc_netdev
;
1520 adev
= ieee2adev(ieee
);
1522 memset(adev
, 0, sizeof(*adev
));
1523 /** Set up our private interface **/
1524 spin_lock_init(&adev
->lock
); /* initial state: unlocked */
1525 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
1526 printk("mutex_init(&adev->mutex); // adev = 0x%px\n", adev
);
1527 mutex_init(&adev
->mutex
);
1528 /* since nobody can see new netdev yet, we can as well
1529 ** just _presume_ that we're under sem (instead of actually taking it): */
1530 /* acx_sem_lock(adev); */
1533 adev
->bus_dev
= &pdev
->dev
;
1534 adev
->dev_type
= DEVTYPE_PCI
;
1536 /** Finished with private interface **/
1538 /** begin board specific inits **/
1539 pci_set_drvdata(pdev
, ieee
);
1541 /* Enable the PCI device */
1542 if (pci_enable_device(pdev
)) {
1543 printk("acx: pci_enable_device() FAILED\n");
1545 goto fail_pci_enable_device
;
1548 /* enable busmastering (required for CardBus) */
1549 pci_set_master(pdev
);
1552 /* chiptype is u8 but id->driver_data is ulong
1553 ** Works for now (possible values are 1 and 2) */
1554 chip_type
= (u8
) id
->driver_data
;
1555 /* acx100 and acx111 have different PCI memory regions */
1556 if (chip_type
== CHIPTYPE_ACX100
) {
1557 chip_name
= "ACX100";
1558 mem_region1
= PCI_ACX100_REGION1
;
1559 mem_region1_size
= PCI_ACX100_REGION1_SIZE
;
1561 mem_region2
= PCI_ACX100_REGION2
;
1562 mem_region2_size
= PCI_ACX100_REGION2_SIZE
;
1563 } else if (chip_type
== CHIPTYPE_ACX111
) {
1564 chip_name
= "ACX111";
1565 mem_region1
= PCI_ACX111_REGION1
;
1566 mem_region1_size
= PCI_ACX111_REGION1_SIZE
;
1568 mem_region2
= PCI_ACX111_REGION2
;
1569 mem_region2_size
= PCI_ACX111_REGION2_SIZE
;
1571 printk("acx: unknown chip type 0x%04X\n", chip_type
);
1572 goto fail_unknown_chiptype
;
1575 /* Figure out our resources */
1576 phymem1
= pci_resource_start(pdev
, mem_region1
);
1577 phymem2
= pci_resource_start(pdev
, mem_region2
);
1578 if (!request_mem_region
1579 (phymem1
, pci_resource_len(pdev
, mem_region1
), "acx_1")) {
1580 printk("acx: cannot reserve PCI memory region 1 (are you sure "
1581 "you have CardBus support in kernel?)\n");
1582 goto fail_request_mem_region1
;
1584 if (!request_mem_region
1585 (phymem2
, pci_resource_len(pdev
, mem_region2
), "acx_2")) {
1586 printk("acx: cannot reserve PCI memory region 2\n");
1587 goto fail_request_mem_region2
;
1589 /* this used to be ioremap(), but ioremap_nocache()
1590 * is much less risky, right? (and slower?)
1591 * FIXME: we may want to go back to cached variant if it's
1592 * certain that our code really properly handles
1593 * cached operation (memory barriers, volatile?, ...)
1594 * (but always keep this comment here regardless!)
1595 * Possibly make this a driver config setting?
1598 mem1
= ioremap_nocache(phymem1
, mem_region1_size
);
1600 printk("acx: ioremap() FAILED\n");
1603 mem2
= ioremap_nocache(phymem2
, mem_region2_size
);
1605 printk("acx: ioremap() #2 FAILED\n");
1609 printk("acx: found %s-based wireless network card at %s, irq:%d, "
1610 "phymem1:0x%lX, phymem2:0x%lX, mem1:0x%p, mem1_size:%ld, "
1611 "mem2:0x%p, mem2_size:%ld\n",
1612 chip_name
, pci_name(pdev
), pdev
->irq
, phymem1
, phymem2
,
1613 mem1
, mem_region1_size
, mem2
, mem_region2_size
);
1614 log(L_ANY
, "initial debug setting is 0x%04X\n", acx_debug
);
1615 adev
->chip_type
= chip_type
;
1616 adev
->chip_name
= chip_name
;
1617 adev
->io
= (CHIPTYPE_ACX100
== chip_type
) ? IO_ACX100
: IO_ACX111
;
1618 adev
->membase
= phymem1
;
1619 adev
->iobase
= mem1
;
1620 adev
->membase2
= phymem2
;
1621 adev
->iobase2
= mem2
;
1622 adev
->irq
= pdev
->irq
;
1625 if (0 == pdev
->irq
) {
1626 printk("acx: can't use IRQ 0\n");
1629 SET_IEEE80211_DEV(ieee
, &pdev
->dev
);
1632 /* to find crashes due to weird driver access
1633 * to unconfigured interface (ifup) */
1634 adev
->mgmt_timer
.function
= (void (*)(unsigned long))0x0000dead;
1637 #ifdef NONESSENTIAL_FEATURES
1638 acx_show_card_eeprom_id(adev
);
1639 #endif /* NONESSENTIAL_FEATURES */
1642 /* ok, pci setup is finished, now start initializing the card */
1644 /* NB: read_reg() reads may return bogus data before reset_dev(),
1645 * since the firmware which directly controls large parts of the I/O
1646 * registers isn't initialized yet.
1647 * acx100 seems to be more affected than acx111 */
1648 if (OK
!= acxpci_s_reset_dev(adev
))
1651 if (IS_ACX100(adev
)) {
1652 /* ACX100: configopt struct in cmd mailbox - directly after reset */
1653 memcpy_fromio(&co
, adev
->cmd_area
, sizeof(co
));
1656 if (OK
!= acx_s_init_mac(adev
))
1659 if (IS_ACX111(adev
)) {
1660 /* ACX111: configopt struct needs to be queried after full init */
1661 acx_s_interrogate(adev
, &co
, ACX111_IE_CONFIG_OPTIONS
);
1663 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
1664 if (OK
!= acxpci_read_eeprom_byte(adev
, 0x05, &adev
->eeprom_version
))
1665 goto fail_read_eeprom_version
;
1667 acx_s_parse_configoption(adev
, &co
);
1668 acx_s_set_defaults(adev
);
1669 acx_s_get_firmware_version(adev
); /* needs to be after acx_s_init_mac() */
1670 acx_display_hardware_details(adev
);
1672 /* Register the card, AFTER everything else has been set up,
1673 * since otherwise an ioctl could step on our feet due to
1674 * firmware operations happening in parallel or uninitialized data */
1677 acx_proc_register_entries(ieee
);
1679 /* Now we have our device, so make sure the kernel doesn't try
1680 * to send packets even though we're not associated to a network yet */
1682 /* after register_netdev() userspace may start working with dev
1683 * (in particular, on other CPUs), we only need to up the sem */
1684 /* acx_sem_unlock(adev); */
1686 printk("acx " ACX_RELEASE
": net device %s, driver compiled "
1687 "against wireless extensions %d and Linux %s\n",
1688 wiphy_name(adev
->ieee
->wiphy
), WIRELESS_EXT
, UTS_RELEASE
);
1690 MAC_COPY(adev
->ieee
->wiphy
->perm_addr
, adev
->dev_addr
);
1692 log(L_IRQ
| L_INIT
, "using IRQ %d\n", pdev
->irq
);
1694 /** done with board specific setup **/
1696 /* need to be able to restore PCI state after a suspend */
1698 pci_save_state(pdev
);
1702 acx_init_task_scheduler(adev
);
1703 err
= ieee80211_register_hw(adev
->ieee
);
1705 printk("acx: ieee80211_register_hw() FAILED: %d\n", err
);
1706 goto fail_register_netdev
;
1709 great_inquisitor(adev
);
1715 /* error paths: undo everything in reverse order... */
1718 acxpci_s_delete_dma_regions(adev
);
1719 pci_set_drvdata(pdev
, NULL
);
1722 fail_read_eeprom_version
:
1734 release_mem_region(pci_resource_start(pdev
, mem_region2
),
1735 pci_resource_len(pdev
, mem_region2
));
1736 fail_request_mem_region2
:
1738 release_mem_region(pci_resource_start(pdev
, mem_region1
),
1739 pci_resource_len(pdev
, mem_region1
));
1740 fail_request_mem_region1
:
1741 fail_unknown_chiptype
:
1743 pci_disable_device(pdev
);
1744 fail_pci_enable_device
:
1747 pci_set_power_state(pdev
, PCI_D3hot
);
1749 fail_register_netdev
:
1750 ieee80211_free_hw(ieee
);
1757 /***********************************************************************
1760 ** Shut device down (if not hot unplugged)
1761 ** and deallocate PCI resources for the acx chip.
1763 ** pdev - ptr to PCI device structure containing info about pci configuration
1765 static void __devexit
acxpci_e_remove(struct pci_dev
*pdev
)
1767 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*)pci_get_drvdata(pdev
);
1768 acx_device_t
*adev
= ieee2adev(hw
);
1769 unsigned long mem_region1
, mem_region2
;
1770 unsigned long flags
;
1774 log(L_DEBUG
, "%s: card is unused. Skipping any release code\n",
1780 acx_lock(adev
, flags
);
1781 acx_unlock(adev
, flags
);
1782 adev
->initialized
= 0;
1784 /* If device wasn't hot unplugged... */
1785 if (adev_present(adev
)) {
1789 /* disable both Tx and Rx to shut radio down properly */
1790 if (adev
->initialized
) {
1791 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_TX
, NULL
, 0);
1792 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_RX
, NULL
, 0);
1795 /* put the eCPU to sleep to save power
1796 * Halting is not possible currently,
1797 * since not supported by all firmware versions */
1798 acx_s_issue_cmd(adev
, ACX100_CMD_SLEEP
, NULL
, 0);
1800 acx_lock(adev
, flags
);
1801 /* disable power LED to save power :-) */
1802 log(L_INIT
, "switching off power LED to save power\n");
1803 acxpci_l_power_led(adev
, 0);
1805 if (IS_ACX111(adev
)) {
1806 /* FIXME: does this actually keep halting the eCPU?
1807 * I don't think so...
1809 acxpci_l_reset_mac(adev
);
1813 temp
= read_reg16(adev
, IO_ACX_ECPU_CTRL
) | 0x1;
1814 write_reg16(adev
, IO_ACX_ECPU_CTRL
, temp
);
1817 acx_unlock(adev
, flags
);
1819 acx_sem_unlock(adev
);
1822 /* unregister the device to not let the kernel
1823 * (e.g. ioctls) access a half-deconfigured device
1824 * NB: this will cause acxpci_e_close() to be called,
1825 * thus we shouldn't call it under sem!
1826 * Well, netdev did, but ieee80211 stack does not, so we
1827 * have to do so manually...
1830 log(L_INIT
, "removing device %s\n", wiphy_name(adev
->ieee
->wiphy
));
1831 ieee80211_unregister_hw(adev
->ieee
);
1833 /* unregister_netdev ensures that no references to us left.
1834 * For paranoid reasons we continue to follow the rules */
1837 if (adev
->dev_state_mask
& ACX_STATE_IFACE_UP
) {
1839 CLEAR_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
1842 acx_proc_unregister_entries(adev
->ieee
);
1844 if (IS_ACX100(adev
)) {
1845 mem_region1
= PCI_ACX100_REGION1
;
1846 mem_region2
= PCI_ACX100_REGION2
;
1848 mem_region1
= PCI_ACX111_REGION1
;
1849 mem_region2
= PCI_ACX111_REGION2
;
1852 /* finally, clean up PCI bus state */
1853 acxpci_s_delete_dma_regions(adev
);
1855 iounmap(adev
->iobase
);
1857 iounmap(adev
->iobase2
);
1858 release_mem_region(pci_resource_start(pdev
, mem_region1
),
1859 pci_resource_len(pdev
, mem_region1
));
1860 release_mem_region(pci_resource_start(pdev
, mem_region2
),
1861 pci_resource_len(pdev
, mem_region2
));
1862 pci_disable_device(pdev
);
1864 /* remove dev registration */
1866 free_irq(adev
->irq
, adev
);
1867 acx_sem_unlock(adev
);
1869 /* Free netdev (quite late,
1870 * since otherwise we might get caught off-guard
1871 * by a netdev timeout handler execution
1872 * expecting to see a working dev...) */
1873 ieee80211_free_hw(adev
->ieee
);
1875 /* put device into ACPI D3 mode (shutdown) */
1877 pci_set_power_state(pdev
, PCI_D3hot
);
1884 /***********************************************************************
1885 ** TODO: PM code needs to be fixed / debugged / tested.
1889 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
1890 acxpci_e_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1892 acxpci_e_suspend(struct pci_dev
*pdev
, u32 state
)
1895 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
1899 printk("acx: suspend handler is experimental!\n");
1900 printk("sus: dev %p\n", hw
);
1902 /* if (!netif_running(ndev))
1905 adev
= ieee2adev(hw
);
1906 printk("sus: adev %p\n", adev
);
1910 ieee80211_unregister_hw(hw
); /* this one cannot sleep */
1912 /* down() does not set it to 0xffff, but here we really want that */
1913 write_reg16(adev
, IO_ACX_IRQ_MASK
, 0xffff);
1914 write_reg16(adev
, IO_ACX_FEMR
, 0x0);
1915 acxpci_s_delete_dma_regions(adev
);
1916 pci_save_state(pdev
);
1917 pci_set_power_state(pdev
, PCI_D3hot
);
1919 acx_sem_unlock(adev
);
1925 static int acxpci_e_resume(struct pci_dev
*pdev
)
1927 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
1932 printk("acx: resume handler is experimental!\n");
1933 printk("rsm: got dev %p\n", hw
);
1936 adev
= ieee2adev(hw
);
1937 printk("rsm: got adev %p\n", adev
);
1941 pci_set_power_state(pdev
, PCI_D0
);
1942 printk("rsm: power state PCI_D0 set\n");
1943 pci_restore_state(pdev
);
1944 printk("rsm: PCI state restored\n");
1946 if (OK
!= acxpci_s_reset_dev(adev
))
1948 printk("rsm: device reset done\n");
1949 if (OK
!= acx_s_init_mac(adev
))
1951 printk("rsm: init MAC done\n");
1954 printk("rsm: acx up done\n");
1956 /* now even reload all card parameters as they were before suspend,
1957 * and possibly be back in the network again already :-) */
1958 if (ACX_STATE_IFACE_UP
& adev
->dev_state_mask
) {
1959 adev
->set_mask
= GETSET_ALL
;
1960 acx_s_update_card_settings(adev
);
1961 printk("rsm: settings updated\n");
1963 ieee80211_register_hw(hw
);
1964 printk("rsm: device attached\n");
1967 acx_sem_unlock(adev
);
1968 /* we need to return OK here anyway, right? */
1972 #endif /* CONFIG_PM */
1973 #endif /* CONFIG_PCI */
1975 /***********************************************************************
1978 ** This function is called by acxpci_e_open (when ifconfig sets the device as up)
1981 ** - Enables on-card interrupt requests
1982 ** - calls acx_s_start
1985 static void enable_acx_irq(acx_device_t
* adev
)
1988 write_reg16(adev
, IO_ACX_IRQ_MASK
, adev
->irq_mask
);
1989 write_reg16(adev
, IO_ACX_FEMR
, 0x8000);
1990 adev
->irqs_active
= 1;
1994 static void acxpci_s_up(struct ieee80211_hw
*hw
)
1996 acx_device_t
*adev
= ieee2adev(hw
);
1997 unsigned long flags
;
2001 acx_lock(adev
, flags
);
2002 enable_acx_irq(adev
);
2003 acx_unlock(adev
, flags
);
2005 /* acx fw < 1.9.3.e has a hardware timer, and older drivers
2006 ** used to use it. But we don't do that anymore, our OS
2007 ** has reliable software timers */
2008 init_timer(&adev
->mgmt_timer
);
2009 adev
->mgmt_timer
.function
= acx_i_timer
;
2010 adev
->mgmt_timer
.data
= (unsigned long)adev
;
2012 /* Need to set ACX_STATE_IFACE_UP first, or else
2013 ** timer won't be started by acx_set_status() */
2014 SET_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
2022 /***********************************************************************
2025 ** NB: device may be already hot unplugged if called from acxpci_e_remove()
2027 ** Disables on-card interrupt request, stops softirq and timer, stops queue,
2028 ** sets status == STOPPED
2031 static void disable_acx_irq(acx_device_t
* adev
)
2035 /* I guess mask is not 0xffff because acx100 won't signal
2036 ** cmd completion then (needed for ifup).
2037 ** I can't ifconfig up after ifconfig down'ing on my acx100 */
2038 write_reg16(adev
, IO_ACX_IRQ_MASK
, adev
->irq_mask_off
);
2039 write_reg16(adev
, IO_ACX_FEMR
, 0x0);
2040 adev
->irqs_active
= 0;
2045 static void acxpci_s_down(struct ieee80211_hw
*hw
)
2047 acx_device_t
*adev
= ieee2adev(hw
);
2051 /* Disable IRQs first, so that IRQs cannot race with us */
2052 /* then wait until interrupts have finished executing on other CPUs */
2053 disable_acx_irq(adev
); /* NO sem-locking here? */
2054 synchronize_irq(adev
->irq
);
2056 /* we really don't want to have an asynchronous tasklet disturb us
2057 ** after something vital for its job has been shut down, so
2058 ** end all remaining work now.
2060 ** NB: carrier_off (done by set_status below) would lead to
2061 ** not yet fully understood deadlock in flush_scheduled_work().
2062 ** That's why we do FLUSH first.
2064 ** NB2: we have a bad locking bug here: flush_scheduled_work()
2065 ** waits for acx_e_after_interrupt_task to complete if it is running
2066 ** on another CPU, but acx_e_after_interrupt_task
2067 ** will sleep on sem forever, because it is taken by us!
2068 ** Work around that by temporary sem unlock.
2069 ** This will fail miserably if we'll be hit by concurrent
2070 ** iwconfig or something in between. TODO! */
2071 acx_sem_unlock(adev
); /* valid? */
2072 flush_scheduled_work();
2073 acx_sem_lock(adev
); /* valid? */
2075 /* This is possible:
2076 ** flush_scheduled_work -> acx_e_after_interrupt_task ->
2077 ** -> set_status(ASSOCIATED) -> wake_queue()
2078 ** That's why we stop queue _after_ flush_scheduled_work
2079 ** lock/unlock is just paranoia, maybe not needed */
2081 /* kernel/timer.c says it's illegal to del_timer_sync()
2082 ** a timer which restarts itself. We guarantee this cannot
2083 ** ever happen because acx_i_timer() never does this if
2084 ** status is ACX_STATUS_0_STOPPED */
2085 del_timer_sync(&adev
->mgmt_timer
);
2090 #ifdef CONFIG_NET_POLL_CONTROLLER
2091 void acxpci_net_poll_controller(struct net_device *net_dev)
2093 acx_device_t *adev = ndev2adev(net_dev);
2094 unsigned long flags;
2096 local_irq_save(flags);
2097 acxpci_i_interrupt(adev->irq, adev);
2098 local_irq_restore(flags);
2100 #endif*/ /* CONFIG_NET_POLL_CONTROLLER */
2102 /***********************************************************************
2105 ** Called as a result of SIOCSIFFLAGS ioctl changing the flags bit IFF_UP
2106 ** from clear to set. In other words: ifconfig up.
2110 ** >0 f/w reported error
2111 ** <0 driver reported error
2113 static int acxpci_e_open(struct ieee80211_hw
*hw
)
2115 acx_device_t
*adev
= ieee2adev(hw
);
2122 adev
->initialized
= 0;
2124 /* TODO: pci_set_power_state(pdev, PCI_D0); ? */
2126 /* request shared IRQ handler */
2128 (adev
->irq
, acxpci_i_interrupt
, IRQF_SHARED
, KBUILD_MODNAME
, adev
)) {
2129 printk("%s: request_irq FAILED\n", wiphy_name(adev
->ieee
->wiphy
));
2133 log(L_DEBUG
| L_IRQ
, "request_irq %d successful\n", adev
->irq
);
2138 /* We don't currently have to do anything else.
2139 * The setup of the MAC should be subsequently completed via
2140 * the mlme commands.
2141 * Higher layers know we're ready from dev->start==1 and
2142 * dev->tbusy==0. Our rx path knows to pass up received/
2143 * frames because of dev->flags&IFF_UP is true.
2145 acx_setup_modes(adev
);
2146 ieee80211_start_queues(adev
->ieee
);
2148 adev
->initialized
= 1;
2150 acx_sem_unlock(adev
);
2157 /***********************************************************************
2160 ** This function stops the network functionality of the interface (invoked
2161 ** when the user calls ifconfig <wlan> down). The tx queue is halted and
2162 ** the device is marked as down.
2164 ** Called as a result of SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
2165 ** from set to clear. I.e. called by "ifconfig DEV down"
2169 ** >0 f/w reported error
2170 ** <0 driver reported error
2172 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
2173 static int acxpci_e_close(struct ieee80211_hw
*hw
)
2175 static void acxpci_e_close(struct ieee80211_hw
*hw
)
2178 acx_device_t
*adev
= ieee2adev(hw
);
2185 CLEAR_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
2186 if (adev
->initialized
) {
2191 acx_free_modes(adev
);
2192 /* disable all IRQs, release shared IRQ handler */
2193 write_reg16(adev
, IO_ACX_IRQ_MASK
, 0xffff);
2194 write_reg16(adev
, IO_ACX_FEMR
, 0x0);
2196 /* TODO: pci_set_power_state(pdev, PCI_D3hot); ? */
2198 /* We currently don't have to do anything else.
2199 * Higher layers know we're not ready from dev->start==0 and
2200 * dev->tbusy==1. Our rx path knows to not pass up received
2201 * frames because of dev->flags&IFF_UP is false.
2203 acx_sem_unlock(adev
);
2205 log(L_INIT
, "closed device\n");
2207 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
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("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
, "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
, "info_type:%04X info_status:%04X\n", info_type
, info_status
);
2376 log(L_IRQ
, "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
) {
2395 /* HOST_INT_TX_COMPLETE */
2396 if (irqtype
& HOST_INT_TX_XFER
) {
2399 /* HOST_INT_RX_COMPLETE */
2400 if (irqtype
& HOST_INT_DTIM
) {
2403 if (irqtype
& HOST_INT_BEACON
) {
2406 if (irqtype
& HOST_INT_TIMER
) {
2407 log(L_IRQ
, " Timer");
2409 if (irqtype
& HOST_INT_KEY_NOT_FOUND
) {
2410 printk(" Key_Not_Found");
2412 if (irqtype
& HOST_INT_IV_ICV_FAILURE
) {
2413 printk(" IV_ICV_Failure (crypto)");
2415 /* HOST_INT_CMD_COMPLETE */
2417 if (irqtype
& HOST_INT_OVERFLOW
) {
2418 printk(" Overflow");
2420 if (irqtype
& HOST_INT_PROCESS_ERROR
) {
2421 printk(" Process_Error");
2423 /* HOST_INT_SCAN_COMPLETE */
2424 if (irqtype
& HOST_INT_FCS_THRESHOLD
) {
2425 printk(" FCS_Threshold");
2427 if (irqtype
& HOST_INT_UNKNOWN
) {
2430 printk(" IRQ(s)\n");
2434 static void update_link_quality_led(acx_device_t
* adev
)
2439 acx_signal_determine_quality(adev->wstats.qual.level,
2440 adev->wstats.qual.noise);
2441 if (qual > adev->brange_max_quality)
2442 qual = adev->brange_max_quality;
2445 /* if (time_after(jiffies, adev->brange_time_last_state_change +
2447 HZ / 2 * (unsigned long)qual /
2448 adev->brange_max_quality))) {
2449 acxpci_l_power_led(adev, (adev->brange_last_state == 0));
2450 adev->brange_last_state ^= 1; *//* toggle */
2451 /* adev->brange_time_last_state_change = jiffies;
2456 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* a la orinoco.c */
2458 /* Interrupt handler bottom-half */
2459 void acx_interrupt_tasklet(struct work_struct
*work
)
2462 #ifdef CONFIG_ACX_MAC80211_DEBUG
2463 u32 _handled
= 0x00000000;
2464 # define acxirq_handled(irq) do { _handled |= (irq); } while (0)
2466 # define acxirq_handled(irq) do { /* nothing */ } while (0)
2467 #endif /* CONFIG_ACX_MAC80211_DEBUG */
2468 acx_device_t
*adev
= container_of(work
,struct acx_device
, after_interrupt_task
);
2469 // unsigned int irqcount = MAX_IRQLOOPS_PER_JIFFY;
2472 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2478 irqtype
= adev
->irq_reason
;
2479 adev
->irq_reason
= 0;
2481 #define IRQ_ITERATE 0
2483 if (jiffies
!= adev
->irq_last_jiffies
) {
2484 adev
->irq_loops_this_jiffy
= 0;
2485 adev
->irq_last_jiffies
= jiffies
;
2488 /* safety condition; we'll normally abort loop below
2489 * in case no IRQ type occurred */
2490 while (likely(--irqcount
)) {
2492 /* ACK all IRQs ASAP */
2495 /* Handle most important IRQ types first */
2496 if (irqtype
& HOST_INT_RX_COMPLETE
) {
2497 log(L_IRQ
, "got Rx_Complete IRQ\n");
2498 acxpci_l_process_rxdesc(adev
);
2500 if (irqtype
& HOST_INT_TX_COMPLETE
) {
2501 log(L_IRQ
, "got Tx_Complete IRQ\n");
2502 /* don't clean up on each Tx complete, wait a bit
2503 * unless we're going towards full, in which case
2504 * we do it immediately, too (otherwise we might lockup
2505 * with a full Tx buffer if we go into
2506 * acxpci_l_clean_txdesc() at a time when we won't wakeup
2507 * the net queue in there for some reason...) */
2508 // if (adev->tx_free <= TX_START_CLEAN) {
2509 acxpci_l_clean_txdesc(adev
);
2513 /* Less frequent ones */
2515 | HOST_INT_CMD_COMPLETE
2516 | HOST_INT_INFO
| HOST_INT_SCAN_COMPLETE
)) {
2517 if (irqtype
& HOST_INT_INFO
) {
2518 handle_info_irq(adev
);
2520 if (irqtype
& HOST_INT_SCAN_COMPLETE
) {
2521 log(L_IRQ
, "got Scan_Complete IRQ\n");
2522 /* need to do that in process context */
2523 /* remember that fw is not scanning anymore */
2524 SET_BIT(adev
->irq_status
,
2525 HOST_INT_SCAN_COMPLETE
);
2529 /* These we just log, but either they happen rarely
2530 * or we keep them masked out */
2531 if (irqtype
& (0 | HOST_INT_RX_DATA
2532 /* | HOST_INT_TX_COMPLETE */
2534 /* | HOST_INT_RX_COMPLETE */
2538 | HOST_INT_KEY_NOT_FOUND
2539 | HOST_INT_IV_ICV_FAILURE
2540 /* | HOST_INT_CMD_COMPLETE */
2541 /* | HOST_INT_INFO */
2542 | HOST_INT_OVERFLOW
| HOST_INT_PROCESS_ERROR
2543 /* | HOST_INT_SCAN_COMPLETE */
2544 | HOST_INT_FCS_THRESHOLD
| HOST_INT_UNKNOWN
)) {
2545 log_unusual_irq(irqtype
);
2548 unmasked
= read_reg16(adev
, IO_ACX_IRQ_STATUS_CLEAR
);
2549 irqtype
= unmasked
& ~adev
->irq_mask
;
2550 /* Bail out if no new IRQ bits or if all are masked out */
2555 (++adev
->irq_loops_this_jiffy
> MAX_IRQLOOPS_PER_JIFFY
)) {
2557 "acx: too many interrupts per jiffy!\n");
2558 /* Looks like card floods us with IRQs! Try to stop that */
2559 write_reg16(adev
, IO_ACX_IRQ_MASK
, 0xffff);
2560 /* This will short-circuit all future attempts to handle IRQ.
2561 * We cant do much more... */
2567 /* Routine to perform blink with range */
2568 if (unlikely(adev
->led_power
== 2))
2569 update_link_quality_led(adev
);
2572 if (adev
->after_interrupt_jobs
)
2573 acx_e_after_interrupt_task(&adev
->after_interrupt_task
);
2575 /* write_flush(adev); - not needed, last op was read anyway */
2576 acx_sem_unlock(adev
);
2584 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
2585 acxpci_i_interrupt(int irq
, void *dev_id
)
2587 acxpci_i_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
2590 acx_device_t
*adev
= dev_id
;
2591 unsigned long flags
;
2592 register u16 irqtype
;
2600 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2603 acx_lock(adev
, flags
);
2605 unmasked
= read_reg16(adev
, IO_ACX_IRQ_STATUS_CLEAR
);
2606 if (unlikely(0xffff == unmasked
)) {
2607 /* 0xffff value hints at missing hardware,
2608 * so don't do anything.
2609 * Not very clean, but other drivers do the same... */
2610 log(L_IRQ
, "IRQ type:FFFF - device removed? IRQ_NONE\n");
2614 /* We will check only "interesting" IRQ types */
2615 irqtype
= unmasked
& ~adev
->irq_mask
;
2617 /* We are on a shared IRQ line and it wasn't our IRQ */
2619 "IRQ type:%04X, mask:%04X - all are masked, IRQ_NONE\n",
2620 unmasked
, adev
->irq_mask
);
2624 /* Go ahead and ACK our interrupt */
2625 write_reg16(adev
, IO_ACX_IRQ_ACK
, 0xffff);
2626 if (irqtype
& HOST_INT_CMD_COMPLETE
) {
2627 log(L_IRQ
, "got Command_Complete IRQ\n");
2628 /* save the state for the running issue_cmd() */
2629 SET_BIT(adev
->irq_status
, HOST_INT_CMD_COMPLETE
);
2632 /* Only accept IRQs, if we are initialized properly.
2633 * This avoids an RX race while initializing.
2634 * We should probably not enable IRQs before we are initialized
2635 * completely, but some careful work is needed to fix this. I think it
2636 * is best to stay with this cheap workaround for now... .
2638 if (likely(adev
->initialized
)) {
2639 /* disable all IRQs. They are enabled again in the bottom half. */
2640 /* save the reason code and call our bottom half. */
2641 adev
->irq_reason
= irqtype
;
2643 if ((irqtype
& HOST_INT_RX_COMPLETE
) || (irqtype
& HOST_INT_TX_COMPLETE
))
2644 acx_schedule_task(adev
, 0);
2647 acx_unlock(adev
, flags
);
2651 acx_unlock(adev
, flags
);
2658 /***********************************************************************
2659 ** acxpci_l_power_led
2661 void acxpci_l_power_led(acx_device_t
* adev
, int enable
)
2663 u16 gpio_pled
= IS_ACX111(adev
) ? 0x0040 : 0x0800;
2665 /* A hack. Not moving message rate limiting to adev->xxx
2666 * (it's only a debug message after all) */
2667 static int rate_limit
= 0;
2669 if (rate_limit
++ < 3)
2670 log(L_IOCTL
, "Please report in case toggling the power "
2671 "LED doesn't work for your card!\n");
2673 write_reg16(adev
, IO_ACX_GPIO_OUT
,
2674 read_reg16(adev
, IO_ACX_GPIO_OUT
) & ~gpio_pled
);
2676 write_reg16(adev
, IO_ACX_GPIO_OUT
,
2677 read_reg16(adev
, IO_ACX_GPIO_OUT
) | gpio_pled
);
2681 /***********************************************************************
2685 /***********************************************************************
2689 acx111pci_ioctl_info(struct net_device
*ndev
,
2690 struct iw_request_info
*info
,
2691 struct iw_param
*vwrq
, char *extra
)
2694 acx_device_t
*adev
= ndev2adev(ndev
);
2697 rxhostdesc_t
*rxhostdesc
;
2698 txhostdesc_t
*txhostdesc
;
2699 struct acx111_ie_memoryconfig memconf
;
2700 struct acx111_ie_queueconfig queueconf
;
2701 unsigned long flags
;
2706 char ratefallback
[0x5];
2708 if (!(acx_debug
& (L_IOCTL
| L_DEBUG
)))
2710 /* using printk() since we checked debug flag already */
2714 if (!IS_ACX111(adev
)) {
2715 printk("acx111-specific function called "
2716 "with non-acx111 chip, aborting\n");
2720 /* get Acx111 Memory Configuration */
2721 memset(&memconf
, 0, sizeof(memconf
));
2722 /* BTW, fails with 12 (Write only) error code.
2723 ** Retained for easy testing of issue_cmd error handling :) */
2724 acx_s_interrogate(adev
, &memconf
, ACX1xx_IE_QUEUE_CONFIG
);
2726 /* get Acx111 Queue Configuration */
2727 memset(&queueconf
, 0, sizeof(queueconf
));
2728 acx_s_interrogate(adev
, &queueconf
, ACX1xx_IE_MEMORY_CONFIG_OPTIONS
);
2730 /* get Acx111 Memory Map */
2731 memset(memmap
, 0, sizeof(memmap
));
2732 acx_s_interrogate(adev
, &memmap
, ACX1xx_IE_MEMORY_MAP
);
2734 /* get Acx111 Rx Config */
2735 memset(rxconfig
, 0, sizeof(rxconfig
));
2736 acx_s_interrogate(adev
, &rxconfig
, ACX1xx_IE_RXCONFIG
);
2738 /* get Acx111 fcs error count */
2739 memset(fcserror
, 0, sizeof(fcserror
));
2740 acx_s_interrogate(adev
, &fcserror
, ACX1xx_IE_FCS_ERROR_COUNT
);
2742 /* get Acx111 rate fallback */
2743 memset(ratefallback
, 0, sizeof(ratefallback
));
2744 acx_s_interrogate(adev
, &ratefallback
, ACX1xx_IE_RATE_FALLBACK
);
2746 /* force occurrence of a beacon interrupt */
2747 /* TODO: comment why is this necessary */
2748 write_reg16(adev
, IO_ACX_HINT_TRIG
, HOST_INT_BEACON
);
2750 /* dump Acx111 Mem Configuration */
2751 printk("dump mem config:\n"
2752 "data read: %d, struct size: %d\n"
2753 "Number of stations: %1X\n"
2754 "Memory block size: %1X\n"
2755 "tx/rx memory block allocation: %1X\n"
2756 "count rx: %X / tx: %X queues\n"
2758 "fragmentation %1X\n"
2759 "Rx Queue 1 Count Descriptors: %X\n"
2760 "Rx Queue 1 Host Memory Start: %X\n"
2761 "Tx Queue 1 Count Descriptors: %X\n"
2762 "Tx Queue 1 Attributes: %X\n",
2763 memconf
.len
, (int)sizeof(memconf
),
2764 memconf
.no_of_stations
,
2765 memconf
.memory_block_size
,
2766 memconf
.tx_rx_memory_block_allocation
,
2767 memconf
.count_rx_queues
, memconf
.count_tx_queues
,
2769 memconf
.fragmentation
,
2770 memconf
.rx_queue1_count_descs
,
2771 acx2cpu(memconf
.rx_queue1_host_rx_start
),
2772 memconf
.tx_queue1_count_descs
, memconf
.tx_queue1_attributes
);
2774 /* dump Acx111 Queue Configuration */
2775 printk("dump queue head:\n"
2776 "data read: %d, struct size: %d\n"
2777 "tx_memory_block_address (from card): %X\n"
2778 "rx_memory_block_address (from card): %X\n"
2779 "rx1_queue address (from card): %X\n"
2780 "tx1_queue address (from card): %X\n"
2781 "tx1_queue attributes (from card): %X\n",
2782 queueconf
.len
, (int)sizeof(queueconf
),
2783 queueconf
.tx_memory_block_address
,
2784 queueconf
.rx_memory_block_address
,
2785 queueconf
.rx1_queue_address
,
2786 queueconf
.tx1_queue_address
, queueconf
.tx1_attributes
);
2788 /* dump Acx111 Mem Map */
2789 printk("dump mem map:\n"
2790 "data read: %d, struct size: %d\n"
2793 "WEP default key start: %X\n"
2794 "WEP default key end: %X\n"
2795 "STA table start: %X\n"
2796 "STA table end: %X\n"
2797 "Packet template start: %X\n"
2798 "Packet template end: %X\n"
2799 "Queue memory start: %X\n"
2800 "Queue memory end: %X\n"
2801 "Packet memory pool start: %X\n"
2802 "Packet memory pool end: %X\n"
2805 *((u16
*) & memmap
[0x02]), (int)sizeof(memmap
),
2806 *((u32
*) & memmap
[0x04]),
2807 *((u32
*) & memmap
[0x08]),
2808 *((u32
*) & memmap
[0x0C]),
2809 *((u32
*) & memmap
[0x10]),
2810 *((u32
*) & memmap
[0x14]),
2811 *((u32
*) & memmap
[0x18]),
2812 *((u32
*) & memmap
[0x1C]),
2813 *((u32
*) & memmap
[0x20]),
2814 *((u32
*) & memmap
[0x24]),
2815 *((u32
*) & memmap
[0x28]),
2816 *((u32
*) & memmap
[0x2C]),
2817 *((u32
*) & memmap
[0x30]), adev
->iobase
, adev
->iobase2
);
2819 /* dump Acx111 Rx Config */
2820 printk("dump rx config:\n"
2821 "data read: %d, struct size: %d\n"
2823 "rx filter config: %X\n",
2824 *((u16
*) & rxconfig
[0x02]), (int)sizeof(rxconfig
),
2825 *((u16
*) & rxconfig
[0x04]), *((u16
*) & rxconfig
[0x06]));
2827 /* dump Acx111 fcs error */
2828 printk("dump fcserror:\n"
2829 "data read: %d, struct size: %d\n"
2831 *((u16
*) & fcserror
[0x02]), (int)sizeof(fcserror
),
2832 *((u32
*) & fcserror
[0x04]));
2834 /* dump Acx111 rate fallback */
2835 printk("dump rate fallback:\n"
2836 "data read: %d, struct size: %d\n"
2837 "ratefallback: %X\n",
2838 *((u16
*) & ratefallback
[0x02]), (int)sizeof(ratefallback
),
2839 *((u8
*) & ratefallback
[0x04]));
2841 /* protect against IRQ */
2842 acx_lock(adev
, flags
);
2844 /* dump acx111 internal rx descriptor ring buffer */
2845 rxdesc
= adev
->rxdesc_start
;
2847 /* loop over complete receive pool */
2849 for (i
= 0; i
< RX_CNT
; i
++) {
2850 printk("\ndump internal rxdesc %d:\n"
2853 "acx mem pointer (dynamic) 0x%X\n"
2854 "CTL (dynamic) 0x%X\n"
2855 "Rate (dynamic) 0x%X\n"
2856 "RxStatus (dynamic) 0x%X\n"
2857 "Mod/Pre (dynamic) 0x%X\n",
2860 acx2cpu(rxdesc
->pNextDesc
),
2861 acx2cpu(rxdesc
->ACXMemPtr
),
2863 rxdesc
->rate
, rxdesc
->error
, rxdesc
->SNR
);
2867 /* dump host rx descriptor ring buffer */
2869 rxhostdesc
= adev
->rxhostdesc_start
;
2871 /* loop over complete receive pool */
2873 for (i
= 0; i
< RX_CNT
; i
++) {
2874 printk("\ndump host rxdesc %d:\n"
2876 "buffer mem pos 0x%X\n"
2877 "buffer mem offset 0x%X\n"
2884 acx2cpu(rxhostdesc
->data_phy
),
2885 rxhostdesc
->data_offset
,
2886 le16_to_cpu(rxhostdesc
->Ctl_16
),
2887 le16_to_cpu(rxhostdesc
->length
),
2888 acx2cpu(rxhostdesc
->desc_phy_next
),
2889 rxhostdesc
->Status
);
2893 /* dump acx111 internal tx descriptor ring buffer */
2894 txdesc
= adev
->txdesc_start
;
2896 /* loop over complete transmit pool */
2898 for (i
= 0; i
< TX_CNT
; i
++) {
2899 printk("\ndump internal txdesc %d:\n"
2903 "acx mem pointer (dynamic) 0x%X\n"
2904 "host mem pointer (dynamic) 0x%X\n"
2905 "length (dynamic) 0x%X\n"
2906 "CTL (dynamic) 0x%X\n"
2907 "CTL2 (dynamic) 0x%X\n"
2908 "Status (dynamic) 0x%X\n"
2909 "Rate (dynamic) 0x%X\n",
2911 (int)sizeof(struct txdesc
),
2913 acx2cpu(txdesc
->pNextDesc
),
2914 acx2cpu(txdesc
->AcxMemPtr
),
2915 acx2cpu(txdesc
->HostMemPtr
),
2916 le16_to_cpu(txdesc
->total_length
),
2918 txdesc
->Ctl2_8
, txdesc
->error
,
2920 txdesc
= advance_txdesc(adev
, txdesc
, 1);
2923 /* dump host tx descriptor ring buffer */
2925 txhostdesc
= adev
->txhostdesc_start
;
2927 /* loop over complete host send pool */
2929 for (i
= 0; i
< TX_CNT
* 2; i
++) {
2930 printk("\ndump host txdesc %d:\n"
2932 "buffer mem pos 0x%X\n"
2933 "buffer mem offset 0x%X\n"
2940 acx2cpu(txhostdesc
->data_phy
),
2941 txhostdesc
->data_offset
,
2942 le16_to_cpu(txhostdesc
->Ctl_16
),
2943 le16_to_cpu(txhostdesc
->length
),
2944 acx2cpu(txhostdesc
->desc_phy_next
),
2945 le32_to_cpu(txhostdesc
->Status
));
2949 /* write_reg16(adev, 0xb4, 0x4); */
2951 acx_unlock(adev
, flags
);
2954 acx_sem_unlock(adev
);
2955 #endif /* ACX_DEBUG */
2960 /***********************************************************************
2963 acx100pci_ioctl_set_phy_amp_bias(struct net_device
*ndev
,
2964 struct iw_request_info
*info
,
2965 struct iw_param
*vwrq
, char *extra
)
2967 acx_device_t
*adev
= ndev2adev(ndev
);
2968 unsigned long flags
;
2971 if (!IS_ACX100(adev
)) {
2973 * Removing this check *might* damage
2974 * hardware, since we're tweaking GPIOs here after all!!!
2975 * You've been warned...
2977 printk("acx: sorry, setting bias level for non-acx100 "
2978 "is not supported yet\n");
2983 printk("acx: invalid bias parameter, range is 0-7\n");
2989 /* Need to lock accesses to [IO_ACX_GPIO_OUT]:
2990 * IRQ handler uses it to update LED */
2991 acx_lock(adev
, flags
);
2992 gpio_old
= read_reg16(adev
, IO_ACX_GPIO_OUT
);
2993 write_reg16(adev
, IO_ACX_GPIO_OUT
,
2994 (gpio_old
& 0xf8ff) | ((u16
) * extra
<< 8));
2995 acx_unlock(adev
, flags
);
2997 log(L_DEBUG
, "gpio_old: 0x%04X\n", gpio_old
);
2998 printk("%s: PHY power amplifier bias: old:%d, new:%d\n",
2999 ndev
->name
, (gpio_old
& 0x0700) >> 8, (unsigned char)*extra
);
3001 acx_sem_unlock(adev
);
3007 /***************************************************************
3008 ** acxpci_l_alloc_tx
3009 ** Actually returns a txdesc_t* ptr
3011 ** FIXME: in case of fragments, should allocate multiple descrs
3012 ** after figuring out how many we need and whether we still have
3013 ** sufficiently many.
3015 tx_t
*acxpci_l_alloc_tx(acx_device_t
* adev
)
3017 struct txdesc
*txdesc
;
3023 if (unlikely(!adev
->tx_free
)) {
3024 printk("acx: BUG: no free txdesc left\n");
3029 head
= adev
->tx_head
;
3030 txdesc
= get_txdesc(adev
, head
);
3031 ctl8
= txdesc
->Ctl_8
;
3033 /* 2005-10-11: there were several bug reports on this happening
3034 ** but now cause seems to be understood & fixed */
3035 if (unlikely(DESC_CTL_HOSTOWN
!= (ctl8
& DESC_CTL_ACXDONE_HOSTOWN
))) {
3036 /* whoops, descr at current index is not free, so probably
3037 * ring buffer already full */
3038 printk("acx: BUG: tx_head:%d Ctl8:0x%02X - failed to find "
3039 "free txdesc\n", head
, ctl8
);
3044 /* Needed in case txdesc won't be eventually submitted for tx */
3045 txdesc
->Ctl_8
= DESC_CTL_ACXDONE_HOSTOWN
;
3048 log(L_BUFT
, "tx: got desc %u, %u remain\n", head
, adev
->tx_free
);
3049 /* Keep a few free descs between head and tail of tx ring.
3050 ** It is not absolutely needed, just feels safer */
3051 if (adev
->tx_free
< TX_STOP_QUEUE
) {
3052 log(L_BUF
, "stop queue (%u tx desc left)\n", adev
->tx_free
);
3053 acx_stop_queue(adev
->ieee
, NULL
);
3056 /* returning current descriptor, so advance to next free one */
3057 adev
->tx_head
= (head
+ 1) % TX_CNT
;
3061 return (tx_t
*) txdesc
;
3065 /***********************************************************************
3067 void *acxpci_l_get_txbuf(acx_device_t
* adev
, tx_t
* tx_opaque
)
3069 return get_txhostdesc(adev
, (txdesc_t
*) tx_opaque
)->data
;
3073 /***********************************************************************
3076 ** Can be called from IRQ (rx -> (AP bridging or mgmt response) -> tx).
3077 ** Can be called from acx_i_start_xmit (data frames from net core).
3079 ** FIXME: in case of fragments, should loop over the number of
3080 ** pre-allocated tx descrs, properly setting up transfer data and
3081 ** CTL_xxx flags according to fragment number.
3084 acxpci_l_tx_data(acx_device_t
* adev
, tx_t
* tx_opaque
, int len
,
3085 struct ieee80211_tx_control
*ieeectl
,struct sk_buff
* skb
)
3087 txdesc_t
*txdesc
= (txdesc_t
*) tx_opaque
;
3088 struct ieee80211_hdr
*wireless_header
;
3089 txhostdesc_t
*hostdesc1
, *hostdesc2
;
3096 /* fw doesn't tx such packets anyhow */
3097 /* if (unlikely(len < WLAN_HDR_A3_LEN))
3100 hostdesc1
= get_txhostdesc(adev
, txdesc
);
3101 wireless_header
= (struct ieee80211_hdr
*)hostdesc1
->data
;
3102 /* modify flag status in separate variable to be able to write it back
3103 * in one big swoop later (also in order to have less device memory
3105 Ctl_8
= txdesc
->Ctl_8
;
3106 Ctl2_8
= 0; /* really need to init it to 0, not txdesc->Ctl2_8, it seems */
3108 hostdesc2
= hostdesc1
+ 1;
3110 /* DON'T simply set Ctl field to 0 here globally,
3111 * it needs to maintain a consistent flag status (those are state flags!!),
3112 * otherwise it may lead to severe disruption. Only set or reset particular
3113 * flags at the exact moment this is needed... */
3115 /* let chip do RTS/CTS handshaking before sending
3116 * in case packet size exceeds threshold */
3117 if (ieeectl
->flags
& IEEE80211_TXCTL_USE_RTS_CTS
)
3118 SET_BIT(Ctl2_8
, DESC_CTL2_RTS
);
3120 CLEAR_BIT(Ctl2_8
, DESC_CTL2_RTS
);
3122 rate_cur
= ieeectl
->tx_rate
;
3123 if (unlikely(!rate_cur
)) {
3124 printk("acx: driver bug! bad ratemask\n");
3128 /* used in tx cleanup routine for auto rate and accounting: */
3129 /* put_txcr(adev, txdesc, clt, rate_cur); deprecated by mac80211 */
3131 txdesc
->total_length
= cpu_to_le16(len
);
3132 wlhdr_len
= ieee80211_get_hdrlen(le16_to_cpu(wireless_header
->frame_control
));
3133 hostdesc2
->length
= cpu_to_le16(len
- wlhdr_len
);
3135 if (!ieeectl->do_not_encrypt && ieeectl->key_idx>= 0)
3137 u16 key_idx = (u16)(ieeectl->key_idx);
3138 struct acx_key* key = &(adev->key[key_idx]);
3142 memcpy(ieeehdr->wep_iv, ((u8*)wireless_header) + wlhdr_len, 4);
3146 if (IS_ACX111(adev
)) {
3147 /* note that if !txdesc->do_auto, txrate->cur
3148 ** has only one nonzero bit */
3149 txdesc
->u
.r2
.rate111
= cpu_to_le16(rate_cur
3150 /* WARNING: I was never able to make it work with prism54 AP.
3151 ** It was falling down to 1Mbit where shortpre is not applicable,
3152 ** and not working at all at "5,11 basic rates only" setting.
3153 ** I even didn't see tx packets in radio packet capture.
3154 ** Disabled for now --vda */
3155 /*| ((clt->shortpre && clt->cur!=RATE111_1) ? RATE111_SHORTPRE : 0) */
3157 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3158 /* should add this to rate111 above as necessary */
3159 |(clt
->pbcc511
? RATE111_PBCC511
: 0)
3161 hostdesc1
->length
= cpu_to_le16(len
);
3162 } else { /* ACX100 */
3163 u8 rate_100
= ieeectl
->tx_rate
;
3164 txdesc
->u
.r1
.rate
= rate_100
;
3165 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3167 if (n
== RATE100_5
|| n
== RATE100_11
)
3168 n
|= RATE100_PBCC511
;
3171 if (clt
->shortpre
&& (clt
->cur
!= RATE111_1
))
3172 SET_BIT(Ctl_8
, DESC_CTL_SHORT_PREAMBLE
); /* set Short Preamble */
3174 /* set autodma and reclaim and 1st mpdu */
3176 DESC_CTL_AUTODMA
| DESC_CTL_RECLAIM
|
3177 DESC_CTL_FIRSTFRAG
);
3178 #if ACX_FRAGMENTATION
3179 /* SET_BIT(Ctl2_8, DESC_CTL2_MORE_FRAG); cannot set it unconditionally, needs to be set for all non-last fragments */
3181 hostdesc1
->length
= cpu_to_le16(wlhdr_len
);
3183 /* don't need to clean ack/rts statistics here, already
3184 * done on descr cleanup */
3186 /* clears HOSTOWN and ACXDONE bits, thus telling that the descriptors
3187 * are now owned by the acx100; do this as LAST operation */
3188 CLEAR_BIT(Ctl_8
, DESC_CTL_ACXDONE_HOSTOWN
);
3189 /* flush writes before we release hostdesc to the adapter here */
3191 CLEAR_BIT(hostdesc1
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
3192 CLEAR_BIT(hostdesc2
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
3194 /* write back modified flags */
3195 CLEAR_BIT(Ctl2_8
, DESC_CTL2_WEP
);
3196 txdesc
->Ctl2_8
= Ctl2_8
;
3197 txdesc
->Ctl_8
= Ctl_8
;
3198 /* unused: txdesc->tx_time = cpu_to_le32(jiffies); */
3200 /* flush writes before we tell the adapter that it's its turn now */
3201 write_reg16(adev
, IO_ACX_INT_TRIG
, INT_TRIG_TXPRC
);
3203 /* log the packet content AFTER sending it,
3204 * in order to not delay sending any further than absolutely needed
3205 * Do separate logs for acx100/111 to have human-readable rates */
3206 memcpy(&(hostdesc1
->txstatus
.control
),ieeectl
,sizeof(struct ieee80211_tx_control
));
3207 hostdesc1
->skb
= skb
;
3213 /***********************************************************************
3214 ** acxpci_l_clean_txdesc
3216 ** This function resets the txdescs' status when the ACX100
3217 ** signals the TX done IRQ (txdescs have been processed), starting with
3218 ** the pool index of the descriptor which we would use next,
3219 ** in order to make sure that we can be as fast as possible
3220 ** in filling new txdescs.
3221 ** Everytime we get called we know where the next packet to be cleaned is.
3225 static inline void log_txbuffer(const acx_device_t
* adev
)
3229 static void log_txbuffer(acx_device_t
* adev
)
3234 /* no FN_ENTER here, we don't want that */
3235 /* no locks here, since it's entirely non-critical code */
3236 txdesc
= adev
->txdesc_start
;
3237 if (unlikely(!txdesc
))
3239 printk("tx: desc->Ctl8's:");
3240 for (i
= 0; i
< TX_CNT
; i
++) {
3241 printk(" %02X", txdesc
->Ctl_8
);
3242 txdesc
= advance_txdesc(adev
, txdesc
, 1);
3249 static void handle_tx_error(acx_device_t
* adev
, u8 error
, unsigned int finger
,
3250 struct ieee80211_tx_status
*status
)
3252 const char *err
= "unknown error";
3254 /* hmm, should we handle this as a mask
3255 * of *several* bits?
3256 * For now I think only caring about
3257 * individual bits is ok... */
3260 err
= "no Tx due to error in other fragment";
3261 /* adev->wstats.discard.fragment++; */
3265 adev
->stats
.tx_aborted_errors
++;
3268 err
= "Tx desc wrong parameters";
3269 /* adev->wstats.discard.misc++; */
3272 err
= "WEP key not found";
3273 /* adev->wstats.discard.misc++; */
3276 err
= "MSDU lifetime timeout? - try changing "
3277 "'iwconfig retry lifetime XXX'";
3278 /* adev->wstats.discard.misc++; */
3281 err
= "excessive Tx retries due to either distance "
3282 "too high or unable to Tx or Tx frame error - "
3283 "try changing 'iwconfig txpower XXX' or "
3284 "'sens'itivity or 'retry'";
3285 /* adev->wstats.discard.retries++; */
3286 /* Tx error 0x20 also seems to occur on
3287 * overheating, so I'm not sure whether we
3288 * actually want to do aggressive radio recalibration,
3289 * since people maybe won't notice then that their hardware
3290 * is slowly getting cooked...
3291 * Or is it still a safe long distance from utter
3292 * radio non-functionality despite many radio recalibs
3293 * to final destructive overheating of the hardware?
3294 * In this case we really should do recalib here...
3295 * I guess the only way to find out is to do a
3296 * potentially fatal self-experiment :-\
3297 * Or maybe only recalib in case we're using Tx
3298 * rate auto (on errors switching to lower speed
3299 * --> less heat?) or 802.11 power save mode?
3301 * ok, just do it. */
3302 if (++adev
->retry_errors_msg_ratelimit
% 4 == 0) {
3303 if (adev
->retry_errors_msg_ratelimit
<= 20) {
3304 printk("%s: several excessive Tx "
3305 "retry errors occurred, attempting "
3306 "to recalibrate radio. Radio "
3307 "drift might be caused by increasing "
3308 "card temperature, please check the card "
3309 "before it's too late!\n",
3310 wiphy_name(adev
->ieee
->wiphy
));
3311 if (adev
->retry_errors_msg_ratelimit
== 20)
3312 printk("disabling above message\n");
3315 acx_schedule_task(adev
,
3316 ACX_AFTER_IRQ_CMD_RADIO_RECALIB
);
3318 status
->excessive_retries
++;
3321 err
= "Tx buffer overflow";
3322 adev
->stats
.tx_fifo_errors
++;
3325 /* possibly ACPI C-state powersaving related!!!
3326 * (DMA timeout due to excessively high wakeup
3327 * latency after C-state activation!?)
3328 * Disable C-State powersaving and try again,
3329 * then PLEASE REPORT, I'm VERY interested in
3330 * whether my theory is correct that this is
3331 * actually the problem here.
3332 * In that case, use new Linux idle wakeup latency
3333 * requirements kernel API to prevent this issue. */
3335 /* adev->wstats.discard.misc++; */
3338 adev
->stats
.tx_errors
++;
3339 if (adev
->stats
.tx_errors
<= 20)
3340 printk("%s: tx error 0x%02X, buf %02u! (%s)\n",
3341 wiphy_name(adev
->ieee
->wiphy
), error
, finger
, err
);
3343 printk("%s: tx error 0x%02X, buf %02u!\n",
3344 wiphy_name(adev
->ieee
->wiphy
), error
, finger
);
3348 unsigned int acxpci_l_clean_txdesc(acx_device_t
* adev
)
3351 txhostdesc_t
*hostdesc
;
3355 u8 error
, ack_failures
, rts_failures
, rts_ok
, r100
;
3359 if (unlikely(acx_debug
& L_DEBUG
))
3362 log(L_BUFT
, "tx: cleaning up bufs from %u\n", adev
->tx_tail
);
3364 /* We know first descr which is not free yet. We advance it as far
3365 ** as we see correct bits set in following descs (if next desc
3366 ** is NOT free, we shouldn't advance at all). We know that in
3367 ** front of tx_tail may be "holes" with isolated free descs.
3368 ** We will catch up when all intermediate descs will be freed also */
3370 finger
= adev
->tx_tail
;
3372 while (likely(finger
!= adev
->tx_head
)) {
3373 txdesc
= get_txdesc(adev
, finger
);
3375 /* If we allocated txdesc on tx path but then decided
3376 ** to NOT use it, then it will be left as a free "bubble"
3377 ** in the "allocated for tx" part of the ring.
3378 ** We may meet it on the next ring pass here. */
3380 /* stop if not marked as "tx finished" and "host owned" */
3381 if ((txdesc
->Ctl_8
& DESC_CTL_ACXDONE_HOSTOWN
)
3382 != DESC_CTL_ACXDONE_HOSTOWN
) {
3383 if (unlikely(!num_cleaned
)) { /* maybe remove completely */
3384 log(L_BUFT
, "clean_txdesc: tail isn't free. "
3385 "tail:%d head:%d\n",
3386 adev
->tx_tail
, adev
->tx_head
);
3391 /* remember desc values... */
3392 error
= txdesc
->error
;
3393 ack_failures
= txdesc
->ack_failures
;
3394 rts_failures
= txdesc
->rts_failures
;
3395 rts_ok
= txdesc
->rts_ok
;
3396 r100
= txdesc
->u
.r1
.rate
;
3397 r111
= le16_to_cpu(txdesc
->u
.r2
.rate111
);
3399 /* need to check for certain error conditions before we
3400 * clean the descriptor: we still need valid descr data here */
3401 hostdesc
= get_txhostdesc(adev
, txdesc
);
3403 hostdesc
->txstatus
.flags
|= IEEE80211_TX_STATUS_ACK
;
3404 if (unlikely(0x30 & error
)) {
3405 /* only send IWEVTXDROP in case of retry or lifetime exceeded;
3406 * all other errors mean we screwed up locally */
3407 /* union iwreq_data wrqu;
3408 struct ieee80211_hdr_3addr *hdr;
3409 hdr = (struct ieee80211_hdr_3addr *) hostdesc->data;
3410 MAC_COPY(wrqu.addr.sa_data, hdr->addr1);
3412 hostdesc
->txstatus
.flags
&= ~IEEE80211_TX_STATUS_ACK
;
3415 /* ...and free the desc */
3417 txdesc
->ack_failures
= 0;
3418 txdesc
->rts_failures
= 0;
3420 /* signal host owning it LAST, since ACX already knows that this
3421 ** descriptor is finished since it set Ctl_8 accordingly. */
3422 txdesc
->Ctl_8
= DESC_CTL_HOSTOWN
;
3427 if ((adev
->tx_free
>= TX_START_QUEUE
)
3428 /* && (adev->status == ACX_STATUS_4_ASSOCIATED) */
3429 /*&& (acx_queue_stopped(adev->ieee))*/
3431 log(L_BUF
, "tx: wake queue (avail. Tx desc %u)\n",
3433 acx_wake_queue(adev
->ieee
, NULL
);
3436 /* do error checking, rate handling and logging
3437 * AFTER having done the work, it's faster */
3439 /* Rate handling is done in mac80211 */
3440 /* if (adev->rate_auto) {
3441 struct client *clt = get_txc(adev, txdesc);
3443 u16 cur = get_txr(adev, txdesc);
3444 if (clt->rate_cur == cur) {
3445 acx_l_handle_txrate_auto(adev, clt, cur,*/ /* intended rate */
3446 /*r100, r111,*/ /* actually used rate */
3447 /*(error & 0x30),*/ /* was there an error? */
3456 if (unlikely(error
))
3457 handle_tx_error(adev
, error
, finger
, &hostdesc
->txstatus
);
3459 if (IS_ACX111(adev
))
3461 "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u r111=%04X tx_free=%u\n",
3462 finger
, ack_failures
, rts_failures
, rts_ok
, r111
, adev
->tx_free
);
3465 "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u rate=%u\n",
3466 finger
, ack_failures
, rts_failures
, rts_ok
, r100
);
3468 /* And finally report upstream */
3471 hostdesc
->txstatus
.excessive_retries
= rts_failures
;
3472 hostdesc
->txstatus
.retry_count
= ack_failures
;
3473 ieee80211_tx_status(adev
->ieee
,hostdesc
->skb
,&hostdesc
->txstatus
);
3474 memset(&hostdesc
->txstatus
, 0, sizeof(struct ieee80211_tx_status
));
3476 /* update pointer for descr to be cleaned next */
3477 finger
= (finger
+ 1) % TX_CNT
;
3479 /* remember last position */
3480 adev
->tx_tail
= finger
;
3482 FN_EXIT1(num_cleaned
);
3486 /* clean *all* Tx descriptors, and regardless of their previous state.
3487 * Used for brute-force reset handling. */
3488 void acxpci_l_clean_txdesc_emergency(acx_device_t
* adev
)
3495 for (i
= 0; i
< TX_CNT
; i
++) {
3496 txdesc
= get_txdesc(adev
, i
);
3499 txdesc
->ack_failures
= 0;
3500 txdesc
->rts_failures
= 0;
3503 txdesc
->Ctl_8
= DESC_CTL_HOSTOWN
;
3506 adev
->tx_free
= TX_CNT
;
3512 /***********************************************************************
3513 ** acxpci_s_create_tx_host_desc_queue
3516 static void *allocate(acx_device_t
* adev
, size_t size
, dma_addr_t
* phy
,
3521 ptr
= dma_alloc_coherent(adev
->bus_dev
, size
, phy
, GFP_KERNEL
);
3524 log(L_DEBUG
, "%s sz=%d adr=0x%p phy=0x%08llx\n",
3525 msg
, (int)size
, ptr
, (unsigned long long)*phy
);
3526 memset(ptr
, 0, size
);
3529 printk(KERN_ERR
"acx: %s allocation FAILED (%d bytes)\n",
3535 static int acxpci_s_create_tx_host_desc_queue(acx_device_t
* adev
)
3537 txhostdesc_t
*hostdesc
;
3539 dma_addr_t hostdesc_phy
;
3540 dma_addr_t txbuf_phy
;
3545 /* allocate TX buffer */
3546 adev
->txbuf_area_size
= TX_CNT
* /*WLAN_A4FR_MAXLEN_WEP_FCS*/ (30 + 2312 + 4);
3547 adev
->txbuf_start
= allocate(adev
, adev
->txbuf_area_size
,
3548 &adev
->txbuf_startphy
, "txbuf_start");
3549 if (!adev
->txbuf_start
)
3552 /* allocate the TX host descriptor queue pool */
3553 adev
->txhostdesc_area_size
= TX_CNT
* 2 * sizeof(*hostdesc
);
3554 adev
->txhostdesc_start
= allocate(adev
, adev
->txhostdesc_area_size
,
3555 &adev
->txhostdesc_startphy
,
3556 "txhostdesc_start");
3557 if (!adev
->txhostdesc_start
)
3559 /* check for proper alignment of TX host descriptor pool */
3560 if ((long)adev
->txhostdesc_start
& 3) {
3562 ("acx: driver bug: dma alloc returns unaligned address\n");
3566 hostdesc
= adev
->txhostdesc_start
;
3567 hostdesc_phy
= adev
->txhostdesc_startphy
;
3568 txbuf
= adev
->txbuf_start
;
3569 txbuf_phy
= adev
->txbuf_startphy
;
3572 /* Each tx buffer is accessed by hardware via
3573 ** txdesc -> txhostdesc(s) -> txbuffer(s).
3574 ** We use only one txhostdesc per txdesc, but it looks like
3575 ** acx111 is buggy: it accesses second txhostdesc
3576 ** (via hostdesc.desc_phy_next field) even if
3577 ** txdesc->length == hostdesc->length and thus
3578 ** entire packet was placed into first txhostdesc.
3579 ** Due to this bug acx111 hangs unless second txhostdesc
3580 ** has le16_to_cpu(hostdesc.length) = 3 (or larger)
3581 ** Storing NULL into hostdesc.desc_phy_next
3582 ** doesn't seem to help.
3584 ** Update: although it worked on Xterasys XN-2522g
3585 ** with len=3 trick, WG311v2 is even more bogus, doesn't work.
3586 ** Keeping this code (#ifdef'ed out) for documentational purposes.
3588 for (i
= 0; i
< TX_CNT
* 2; i
++) {
3589 hostdesc_phy
+= sizeof(*hostdesc
);
3591 hostdesc
->data_phy
= cpu2acx(txbuf_phy
);
3592 /* hostdesc->data_offset = ... */
3593 /* hostdesc->reserved = ... */
3594 hostdesc
->Ctl_16
= cpu_to_le16(DESC_CTL_HOSTOWN
);
3595 /* hostdesc->length = ... */
3596 hostdesc
->desc_phy_next
= cpu2acx(hostdesc_phy
);
3597 hostdesc
->pNext
= ptr2acx(NULL
);
3598 /* hostdesc->Status = ... */
3599 /* below: non-hardware fields */
3600 hostdesc
->data
= txbuf
;
3602 txbuf
+= WLAN_A4FR_MAXLEN_WEP_FCS
;
3603 txbuf_phy
+= WLAN_A4FR_MAXLEN_WEP_FCS
;
3605 /* hostdesc->data_phy = ... */
3606 /* hostdesc->data_offset = ... */
3607 /* hostdesc->reserved = ... */
3608 /* hostdesc->Ctl_16 = ... */
3609 hostdesc
->length
= cpu_to_le16(3); /* bug workaround */
3610 /* hostdesc->desc_phy_next = ... */
3611 /* hostdesc->pNext = ... */
3612 /* hostdesc->Status = ... */
3613 /* below: non-hardware fields */
3614 /* hostdesc->data = ... */
3619 /* We initialize two hostdescs so that they point to adjacent
3620 ** memory areas. Thus txbuf is really just a contiguous memory area */
3621 for (i
= 0; i
< TX_CNT
* 2; i
++) {
3622 hostdesc_phy
+= sizeof(*hostdesc
);
3624 hostdesc
->data_phy
= cpu2acx(txbuf_phy
);
3625 /* done by memset(0): hostdesc->data_offset = 0; */
3626 /* hostdesc->reserved = ... */
3627 hostdesc
->Ctl_16
= cpu_to_le16(DESC_CTL_HOSTOWN
);
3628 /* hostdesc->length = ... */
3629 hostdesc
->desc_phy_next
= cpu2acx(hostdesc_phy
);
3630 /* done by memset(0): hostdesc->pNext = ptr2acx(NULL); */
3631 /* hostdesc->Status = ... */
3632 /* ->data is a non-hardware field: */
3633 hostdesc
->data
= txbuf
;
3636 txbuf
+= 24 /*WLAN_HDR_A3_LEN*/;
3637 txbuf_phy
+= 24 /*WLAN_HDR_A3_LEN*/;
3639 txbuf
+= 30 + 2132 + 4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3640 txbuf_phy
+= 30 + 2132 +4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3645 hostdesc
->desc_phy_next
= cpu2acx(adev
->txhostdesc_startphy
);
3650 printk("acx: create_tx_host_desc_queue FAILED\n");
3651 /* dealloc will be done by free function on error case */
3657 /***************************************************************
3658 ** acxpci_s_create_rx_host_desc_queue
3660 /* the whole size of a data buffer (header plus data body)
3661 * plus 32 bytes safety offset at the end */
3662 #define RX_BUFFER_SIZE (sizeof(rxbuffer_t) + 32)
3664 static int acxpci_s_create_rx_host_desc_queue(acx_device_t
* adev
)
3666 rxhostdesc_t
*hostdesc
;
3668 dma_addr_t hostdesc_phy
;
3669 dma_addr_t rxbuf_phy
;
3674 /* allocate the RX host descriptor queue pool */
3675 adev
->rxhostdesc_area_size
= RX_CNT
* sizeof(*hostdesc
);
3676 adev
->rxhostdesc_start
= allocate(adev
, adev
->rxhostdesc_area_size
,
3677 &adev
->rxhostdesc_startphy
,
3678 "rxhostdesc_start");
3679 if (!adev
->rxhostdesc_start
)
3681 /* check for proper alignment of RX host descriptor pool */
3682 if ((long)adev
->rxhostdesc_start
& 3) {
3684 ("acx: driver bug: dma alloc returns unaligned address\n");
3688 /* allocate Rx buffer pool which will be used by the acx
3689 * to store the whole content of the received frames in it */
3690 adev
->rxbuf_area_size
= RX_CNT
* RX_BUFFER_SIZE
;
3691 adev
->rxbuf_start
= allocate(adev
, adev
->rxbuf_area_size
,
3692 &adev
->rxbuf_startphy
, "rxbuf_start");
3693 if (!adev
->rxbuf_start
)
3696 rxbuf
= adev
->rxbuf_start
;
3697 rxbuf_phy
= adev
->rxbuf_startphy
;
3698 hostdesc
= adev
->rxhostdesc_start
;
3699 hostdesc_phy
= adev
->rxhostdesc_startphy
;
3701 /* don't make any popular C programming pointer arithmetic mistakes
3702 * here, otherwise I'll kill you...
3703 * (and don't dare asking me why I'm warning you about that...) */
3704 for (i
= 0; i
< RX_CNT
; i
++) {
3705 hostdesc
->data
= rxbuf
;
3706 hostdesc
->data_phy
= cpu2acx(rxbuf_phy
);
3707 hostdesc
->length
= cpu_to_le16(RX_BUFFER_SIZE
);
3708 CLEAR_BIT(hostdesc
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
3710 rxbuf_phy
+= sizeof(*rxbuf
);
3711 hostdesc_phy
+= sizeof(*hostdesc
);
3712 hostdesc
->desc_phy_next
= cpu2acx(hostdesc_phy
);
3716 hostdesc
->desc_phy_next
= cpu2acx(adev
->rxhostdesc_startphy
);
3720 printk("acx: create_rx_host_desc_queue FAILED\n");
3721 /* dealloc will be done by free function on error case */
3727 /***************************************************************
3728 ** acxpci_s_create_hostdesc_queues
3730 int acxpci_s_create_hostdesc_queues(acx_device_t
* adev
)
3733 result
= acxpci_s_create_tx_host_desc_queue(adev
);
3736 result
= acxpci_s_create_rx_host_desc_queue(adev
);
3741 /***************************************************************
3742 ** acxpci_create_tx_desc_queue
3744 static void acxpci_create_tx_desc_queue(acx_device_t
* adev
, u32 tx_queue_start
)
3747 txhostdesc_t
*hostdesc
;
3748 dma_addr_t hostmemptr
;
3754 if (IS_ACX100(adev
))
3755 adev
->txdesc_size
= sizeof(*txdesc
);
3757 /* the acx111 txdesc is 4 bytes larger */
3758 adev
->txdesc_size
= sizeof(*txdesc
) + 4;
3760 adev
->txdesc_start
= (txdesc_t
*) (adev
->iobase2
+ tx_queue_start
);
3762 log(L_DEBUG
, "adev->iobase2=%p\n"
3763 "tx_queue_start=%08X\n"
3764 "adev->txdesc_start=%p\n",
3765 adev
->iobase2
, tx_queue_start
, adev
->txdesc_start
);
3767 adev
->tx_free
= TX_CNT
;
3768 /* done by memset: adev->tx_head = 0; */
3769 /* done by memset: adev->tx_tail = 0; */
3770 txdesc
= adev
->txdesc_start
;
3771 mem_offs
= tx_queue_start
;
3772 hostmemptr
= adev
->txhostdesc_startphy
;
3773 hostdesc
= adev
->txhostdesc_start
;
3775 if (IS_ACX111(adev
)) {
3776 /* ACX111 has a preinitialized Tx buffer! */
3777 /* loop over whole send pool */
3778 /* FIXME: do we have to do the hostmemptr stuff here?? */
3779 for (i
= 0; i
< TX_CNT
; i
++) {
3780 txdesc
->HostMemPtr
= ptr2acx(hostmemptr
);
3781 txdesc
->Ctl_8
= DESC_CTL_HOSTOWN
;
3782 /* reserve two (hdr desc and payload desc) */
3784 hostmemptr
+= 2 * sizeof(*hostdesc
);
3785 txdesc
= advance_txdesc(adev
, txdesc
, 1);
3788 /* ACX100 Tx buffer needs to be initialized by us */
3789 /* clear whole send pool. sizeof is safe here (we are acx100) */
3790 memset(adev
->txdesc_start
, 0, TX_CNT
* sizeof(*txdesc
));
3792 /* loop over whole send pool */
3793 for (i
= 0; i
< TX_CNT
; i
++) {
3794 log(L_DEBUG
, "configure card tx descriptor: 0x%p, "
3795 "size: 0x%X\n", txdesc
, adev
->txdesc_size
);
3797 /* pointer to hostdesc memory */
3798 txdesc
->HostMemPtr
= ptr2acx(hostmemptr
);
3799 /* initialise ctl */
3800 txdesc
->Ctl_8
= (DESC_CTL_HOSTOWN
| DESC_CTL_RECLAIM
3801 | DESC_CTL_AUTODMA
|
3802 DESC_CTL_FIRSTFRAG
);
3803 /* done by memset(0): txdesc->Ctl2_8 = 0; */
3804 /* point to next txdesc */
3806 cpu2acx(mem_offs
+ adev
->txdesc_size
);
3807 /* reserve two (hdr desc and payload desc) */
3809 hostmemptr
+= 2 * sizeof(*hostdesc
);
3810 /* go to the next one */
3811 mem_offs
+= adev
->txdesc_size
;
3812 /* ++ is safe here (we are acx100) */
3815 /* go back to the last one */
3817 /* and point to the first making it a ring buffer */
3818 txdesc
->pNextDesc
= cpu2acx(tx_queue_start
);
3824 /***************************************************************
3825 ** acxpci_create_rx_desc_queue
3827 static void acxpci_create_rx_desc_queue(acx_device_t
* adev
, u32 rx_queue_start
)
3835 /* done by memset: adev->rx_tail = 0; */
3837 /* ACX111 doesn't need any further config: preconfigures itself.
3838 * Simply print ring buffer for debugging */
3839 if (IS_ACX111(adev
)) {
3840 /* rxdesc_start already set here */
3842 adev
->rxdesc_start
=
3843 (rxdesc_t
*) ((u8
*) adev
->iobase2
+ rx_queue_start
);
3845 rxdesc
= adev
->rxdesc_start
;
3846 for (i
= 0; i
< RX_CNT
; i
++) {
3847 log(L_DEBUG
, "rx descriptor %d @ 0x%p\n", i
, rxdesc
);
3848 rxdesc
= adev
->rxdesc_start
= (rxdesc_t
*)
3849 (adev
->iobase2
+ acx2cpu(rxdesc
->pNextDesc
));
3852 /* we didn't pre-calculate rxdesc_start in case of ACX100 */
3853 /* rxdesc_start should be right AFTER Tx pool */
3854 adev
->rxdesc_start
= (rxdesc_t
*)
3855 ((u8
*) adev
->txdesc_start
+ (TX_CNT
* sizeof(txdesc_t
)));
3856 /* NB: sizeof(txdesc_t) above is valid because we know
3857 ** we are in if (acx100) block. Beware of cut-n-pasting elsewhere!
3858 ** acx111's txdesc is larger! */
3860 memset(adev
->rxdesc_start
, 0, RX_CNT
* sizeof(*rxdesc
));
3862 /* loop over whole receive pool */
3863 rxdesc
= adev
->rxdesc_start
;
3864 mem_offs
= rx_queue_start
;
3865 for (i
= 0; i
< RX_CNT
; i
++) {
3866 log(L_DEBUG
, "rx descriptor @ 0x%p\n", rxdesc
);
3867 rxdesc
->Ctl_8
= DESC_CTL_RECLAIM
| DESC_CTL_AUTODMA
;
3868 /* point to next rxdesc */
3869 rxdesc
->pNextDesc
= cpu2acx(mem_offs
+ sizeof(*rxdesc
));
3870 /* go to the next one */
3871 mem_offs
+= sizeof(*rxdesc
);
3874 /* go to the last one */
3877 /* and point to the first making it a ring buffer */
3878 rxdesc
->pNextDesc
= cpu2acx(rx_queue_start
);
3884 /***************************************************************
3885 ** acxpci_create_desc_queues
3888 acxpci_create_desc_queues(acx_device_t
* adev
, u32 tx_queue_start
,
3891 acxpci_create_tx_desc_queue(adev
, tx_queue_start
);
3892 acxpci_create_rx_desc_queue(adev
, rx_queue_start
);
3896 /***************************************************************
3897 ** acxpci_s_proc_diag_output
3899 char *acxpci_s_proc_diag_output(char *p
, acx_device_t
* adev
)
3901 const char *rtl
, *thd
, *ttl
;
3902 rxhostdesc_t
*rxhostdesc
;
3908 p
+= sprintf(p
, "** Rx buf **\n");
3909 rxhostdesc
= adev
->rxhostdesc_start
;
3911 for (i
= 0; i
< RX_CNT
; i
++) {
3912 rtl
= (i
== adev
->rx_tail
) ? " [tail]" : "";
3913 if ((rxhostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
3915 Status
& cpu_to_le32(DESC_STATUS_FULL
)))
3916 p
+= sprintf(p
, "%02u FULL%s\n", i
, rtl
);
3918 p
+= sprintf(p
, "%02u empty%s\n", i
, rtl
);
3921 /* p += sprintf(p, "** Tx buf (free %d, Linux netqueue %s) **\n",
3923 acx_queue_stopped(adev->ieee) ? "STOPPED" : "running");*/
3924 txdesc
= adev
->txdesc_start
;
3926 for (i
= 0; i
< TX_CNT
; i
++) {
3927 thd
= (i
== adev
->tx_head
) ? " [head]" : "";
3928 ttl
= (i
== adev
->tx_tail
) ? " [tail]" : "";
3929 if (txdesc
->Ctl_8
& DESC_CTL_ACXDONE
)
3930 p
+= sprintf(p
, "%02u free (%02X)%s%s\n", i
,
3931 txdesc
->Ctl_8
, thd
, ttl
);
3933 p
+= sprintf(p
, "%02u tx (%02X)%s%s\n", i
,
3934 txdesc
->Ctl_8
, thd
, ttl
);
3935 txdesc
= advance_txdesc(adev
, txdesc
, 1);
3940 "txbuf_start %p, txbuf_area_size %u, txbuf_startphy %08llx\n"
3941 "txdesc_size %u, txdesc_start %p\n"
3942 "txhostdesc_start %p, txhostdesc_area_size %u, txhostdesc_startphy %08llx\n"
3944 "rxhostdesc_start %p, rxhostdesc_area_size %u, rxhostdesc_startphy %08llx\n"
3945 "rxbuf_start %p, rxbuf_area_size %u, rxbuf_startphy %08llx\n",
3946 adev
->txbuf_start
, adev
->txbuf_area_size
,
3947 (unsigned long long)adev
->txbuf_startphy
,
3948 adev
->txdesc_size
, adev
->txdesc_start
,
3949 adev
->txhostdesc_start
, adev
->txhostdesc_area_size
,
3950 (unsigned long long)adev
->txhostdesc_startphy
,
3952 adev
->rxhostdesc_start
, adev
->rxhostdesc_area_size
,
3953 (unsigned long long)adev
->rxhostdesc_startphy
,
3954 adev
->rxbuf_start
, adev
->rxbuf_area_size
,
3955 (unsigned long long)adev
->rxbuf_startphy
);
3962 /***********************************************************************
3964 int acxpci_proc_eeprom_output(char *buf
, acx_device_t
* adev
)
3971 for (i
= 0; i
< 0x400; i
++) {
3972 acxpci_read_eeprom_byte(adev
, i
, p
++);
3980 /***********************************************************************
3983 void acxpci_set_interrupt_mask(acx_device_t
* adev
)
3985 if (IS_ACX111(adev
)) {
3986 adev
->irq_mask
= (u16
) ~ (0
3987 /* | HOST_INT_RX_DATA */
3988 | HOST_INT_TX_COMPLETE
3989 /* | HOST_INT_TX_XFER */
3990 | HOST_INT_RX_COMPLETE
3991 /* | HOST_INT_DTIM */
3992 /* | HOST_INT_BEACON */
3993 /* | HOST_INT_TIMER */
3994 /* | HOST_INT_KEY_NOT_FOUND */
3995 | HOST_INT_IV_ICV_FAILURE
3996 | HOST_INT_CMD_COMPLETE
3998 /* | HOST_INT_OVERFLOW */
3999 /* | HOST_INT_PROCESS_ERROR */
4000 | HOST_INT_SCAN_COMPLETE
4001 | HOST_INT_FCS_THRESHOLD
4002 /* | HOST_INT_UNKNOWN */
4004 /* Or else acx100 won't signal cmd completion, right? */
4005 adev
->irq_mask_off
= (u16
) ~ (HOST_INT_CMD_COMPLETE
); /* 0xfdff */
4007 adev
->irq_mask
= (u16
) ~ (0
4008 /* | HOST_INT_RX_DATA */
4009 | HOST_INT_TX_COMPLETE
4010 /* | HOST_INT_TX_XFER */
4011 | HOST_INT_RX_COMPLETE
4012 /* | HOST_INT_DTIM */
4013 /* | HOST_INT_BEACON */
4014 /* | HOST_INT_TIMER */
4015 /* | HOST_INT_KEY_NOT_FOUND */
4016 /* | HOST_INT_IV_ICV_FAILURE */
4017 | HOST_INT_CMD_COMPLETE
4019 /* | HOST_INT_OVERFLOW */
4020 /* | HOST_INT_PROCESS_ERROR */
4021 | HOST_INT_SCAN_COMPLETE
4022 /* | HOST_INT_FCS_THRESHOLD */
4023 /* | HOST_INT_UNKNOWN */
4025 adev
->irq_mask_off
= (u16
) ~ (HOST_INT_UNKNOWN
); /* 0x7fff */
4030 /***********************************************************************
4032 int acx100pci_s_set_tx_level(acx_device_t
* adev
, u8 level_dbm
)
4034 /* since it can be assumed that at least the Maxim radio has a
4035 * maximum power output of 20dBm and since it also can be
4036 * assumed that these values drive the DAC responsible for
4037 * setting the linear Tx level, I'd guess that these values
4038 * should be the corresponding linear values for a dBm value,
4039 * in other words: calculate the values from that formula:
4040 * Y [dBm] = 10 * log (X [mW])
4041 * then scale the 0..63 value range onto the 1..100mW range (0..20 dBm)
4042 * and you're done...
4043 * Hopefully that's ok, but you never know if we're actually
4044 * right... (especially since Windows XP doesn't seem to show
4045 * actual Tx dBm values :-P) */
4047 /* NOTE: on Maxim, value 30 IS 30mW, and value 10 IS 10mW - so the
4048 * values are EXACTLY mW!!! Not sure about RFMD and others,
4050 static const u8 dbm2val_maxim
[21] = {
4058 static const u8 dbm2val_rfmd
[21] = {
4068 switch (adev
->radio_type
) {
4069 case RADIO_MAXIM_0D
:
4070 table
= &dbm2val_maxim
[0];
4073 case RADIO_RALINK_15
:
4074 table
= &dbm2val_rfmd
[0];
4077 printk("%s: unknown/unsupported radio type, "
4078 "cannot modify tx power level yet!\n", wiphy_name(adev
->ieee
->wiphy
));
4081 printk("%s: changing radio power level to %u dBm (%u)\n",
4082 wiphy_name(adev
->ieee
->wiphy
), level_dbm
, table
[level_dbm
]);
4083 acxpci_s_write_phy_reg(adev
, 0x11, table
[level_dbm
]);
4088 struct vlynq_reg_config
{
4093 struct vlynq_known
{
4096 struct vlynq_mapping rx_mapping
[4];
4100 struct vlynq_reg_config regs
[10];
4103 #define CHIP_TNETW1130 0x00000009
4104 #define CHIP_TNETW1350 0x00000029
4106 static struct vlynq_known known_devices
[] = {
4108 .chip_id
= CHIP_TNETW1130
, .name
= "TI TNETW1130",
4110 { .size
= 0x22000, .offset
= 0xf0000000 },
4111 { .size
= 0x40000, .offset
= 0xc0000000 },
4112 { .size
= 0x0, .offset
= 0x0 },
4113 { .size
= 0x0, .offset
= 0x0 },
4116 .irq_type
= IRQ_TYPE_EDGE_RISING
,
4121 .value
= (0xd0000000 - PHYS_OFFSET
)
4125 .value
= (0xd0000000 - PHYS_OFFSET
)
4127 { .offset
= 0x740, .value
= 0 },
4128 { .offset
= 0x744, .value
= 0x00010000 },
4129 { .offset
= 0x764, .value
= 0x00010000 },
4133 .chip_id
= CHIP_TNETW1350
, .name
= "TI TNETW1350",
4135 { .size
= 0x100000, .offset
= 0x00300000 },
4136 { .size
= 0x80000, .offset
= 0x00000000 },
4137 { .size
= 0x0, .offset
= 0x0 },
4138 { .size
= 0x0, .offset
= 0x0 },
4141 .irq_type
= IRQ_TYPE_EDGE_RISING
,
4146 .value
= (0x60000000 - PHYS_OFFSET
)
4150 .value
= (0x60000000 - PHYS_OFFSET
)
4152 { .offset
= 0x740, .value
= 0 },
4153 { .offset
= 0x744, .value
= 0x00010000 },
4154 { .offset
= 0x764, .value
= 0x00010000 },
4159 static struct vlynq_device_id acx_vlynq_id
[] = {
4160 { CHIP_TNETW1130
, vlynq_div_auto
, 0 },
4161 { CHIP_TNETW1350
, vlynq_div_auto
, 1 },
4165 static __devinit
int vlynq_probe(struct vlynq_device
*vdev
,
4166 struct vlynq_device_id
*id
)
4168 int result
= -EIO
, i
;
4170 struct ieee80211_hw
*ieee
;
4171 acx_device_t
*adev
= NULL
;
4172 acx111_ie_configoption_t co
;
4173 struct vlynq_mapping mapping
[4] = { { 0, }, };
4174 struct vlynq_known
*match
= NULL
;
4177 result
= vlynq_enable_device(vdev
);
4181 match
= &known_devices
[id
->driver_data
];
4188 mapping
[0].offset
= ARCH_PFN_OFFSET
<< PAGE_SHIFT
;
4189 mapping
[0].size
= 0x02000000;
4190 vlynq_set_local_mapping(vdev
, vdev
->mem_start
, mapping
);
4191 vlynq_set_remote_mapping(vdev
, 0, match
->rx_mapping
);
4193 set_irq_type(vlynq_virq_to_irq(vdev
, match
->irq
), match
->irq_type
);
4195 addr
= (u32
)ioremap(vdev
->mem_start
, 0x1000);
4197 printk(KERN_ERR
"%s: failed to remap io memory\n",
4203 for (i
= 0; i
< match
->num_regs
; i
++)
4204 iowrite32(match
->regs
[i
].value
,
4205 (u32
*)(addr
+ match
->regs
[i
].offset
));
4207 iounmap((void *)addr
);
4209 ieee
= ieee80211_alloc_hw(sizeof(struct acx_device
), &acxpci_hw_ops
);
4211 printk("acx: could not allocate ieee80211 structure %s\n",
4213 goto fail_alloc_netdev
;
4215 ieee
->flags
&= ~IEEE80211_HW_RX_INCLUDES_FCS
;
4218 adev
= ieee2adev(ieee
);
4220 memset(adev
, 0, sizeof(*adev
));
4221 /** Set up our private interface **/
4222 spin_lock_init(&adev
->lock
); /* initial state: unlocked */
4223 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
4224 mutex_init(&adev
->mutex
);
4225 /* since nobody can see new netdev yet, we can as well
4226 ** just _presume_ that we're under sem (instead of actually taking it): */
4227 /* acx_sem_lock(adev); */
4230 adev
->bus_dev
= &vdev
->dev
;
4231 adev
->dev_type
= DEVTYPE_PCI
;
4233 /** Finished with private interface **/
4235 vlynq_set_drvdata(vdev
, ieee
);
4236 if (!request_mem_region(vdev
->mem_start
, vdev
->mem_end
- vdev
->mem_start
, "acx")) {
4237 printk("acx: cannot reserve VLYNQ memory region\n");
4238 goto fail_request_mem_region
;
4240 adev
->iobase
= ioremap(vdev
->mem_start
, vdev
->mem_end
- vdev
->mem_start
);
4241 if (!adev
->iobase
) {
4242 printk("acx: ioremap() FAILED\n");
4245 adev
->iobase2
= adev
->iobase
+ match
->rx_mapping
[0].size
;
4246 adev
->chip_type
= CHIPTYPE_ACX111
;
4247 adev
->chip_name
= match
->name
;
4248 adev
->io
= IO_ACX111
;
4249 adev
->irq
= vlynq_virq_to_irq(vdev
, match
->irq
);
4251 printk("acx: found %s-based wireless network card at %s, irq:%d, "
4252 "phymem:0x%x, mem:0x%p\n",
4253 match
->name
, vdev
->dev
.bus_id
, adev
->irq
,
4254 vdev
->mem_start
, adev
->iobase
);
4255 log(L_ANY
, "initial debug setting is 0x%04X\n", acx_debug
);
4257 if (0 == adev
->irq
) {
4258 printk("acx: can't use IRQ 0\n");
4261 SET_IEEE80211_DEV(ieee
, &vdev
->dev
);
4264 /* to find crashes due to weird driver access
4265 * to unconfigured interface (ifup) */
4266 adev
->mgmt_timer
.function
= (void (*)(unsigned long))0x0000dead;
4269 /* ok, pci setup is finished, now start initializing the card */
4271 /* NB: read_reg() reads may return bogus data before reset_dev(),
4272 * since the firmware which directly controls large parts of the I/O
4273 * registers isn't initialized yet.
4274 * acx100 seems to be more affected than acx111 */
4275 if (OK
!= acxpci_s_reset_dev(adev
))
4278 if (OK
!= acx_s_init_mac(adev
))
4281 acx_s_interrogate(adev
, &co
, ACX111_IE_CONFIG_OPTIONS
);
4282 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
4283 if (OK
!= acxpci_read_eeprom_byte(adev
, 0x05, &adev
->eeprom_version
))
4284 goto fail_read_eeprom_version
;
4286 acx_s_parse_configoption(adev
, &co
);
4287 acx_s_set_defaults(adev
);
4288 acx_s_get_firmware_version(adev
); /* needs to be after acx_s_init_mac() */
4289 acx_display_hardware_details(adev
);
4291 /* Register the card, AFTER everything else has been set up,
4292 * since otherwise an ioctl could step on our feet due to
4293 * firmware operations happening in parallel or uninitialized data */
4296 acx_proc_register_entries(ieee
);
4298 /* Now we have our device, so make sure the kernel doesn't try
4299 * to send packets even though we're not associated to a network yet */
4301 /* after register_netdev() userspace may start working with dev
4302 * (in particular, on other CPUs), we only need to up the sem */
4303 /* acx_sem_unlock(adev); */
4305 printk("acx " ACX_RELEASE
": net device %s, driver compiled "
4306 "against wireless extensions %d and Linux %s\n",
4307 wiphy_name(adev
->ieee
->wiphy
), WIRELESS_EXT
, UTS_RELEASE
);
4309 MAC_COPY(adev
->ieee
->wiphy
->perm_addr
, adev
->dev_addr
);
4311 log(L_IRQ
| L_INIT
, "using IRQ %d\n", adev
->irq
);
4313 /** done with board specific setup **/
4315 acx_init_task_scheduler(adev
);
4316 result
= ieee80211_register_hw(adev
->ieee
);
4318 printk("acx: ieee80211_register_hw() FAILED: %d\n", result
);
4319 goto fail_register_netdev
;
4322 great_inquisitor(adev
);
4328 /* error paths: undo everything in reverse order... */
4331 acxpci_s_delete_dma_regions(adev
);
4334 fail_read_eeprom_version
:
4340 iounmap(adev
->iobase
);
4343 release_mem_region(vdev
->mem_start
, vdev
->mem_end
- vdev
->mem_start
);
4344 fail_request_mem_region
:
4345 fail_register_netdev
:
4346 ieee80211_free_hw(ieee
);
4348 vlynq_disable_device(vdev
);
4354 static void vlynq_remove(struct vlynq_device
*vdev
)
4356 struct ieee80211_hw
*hw
= vlynq_get_drvdata(vdev
);
4357 acx_device_t
*adev
= ieee2adev(hw
);
4358 unsigned long flags
;
4362 log(L_DEBUG
, "%s: card is unused. Skipping any release code\n",
4368 acx_lock(adev
, flags
);
4369 acx_unlock(adev
, flags
);
4370 adev
->initialized
= 0;
4372 /* If device wasn't hot unplugged... */
4373 if (adev_present(adev
)) {
4377 /* disable both Tx and Rx to shut radio down properly */
4378 if (adev
->initialized
) {
4379 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_TX
, NULL
, 0);
4380 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_RX
, NULL
, 0);
4382 acx_lock(adev
, flags
);
4383 /* disable power LED to save power :-) */
4384 log(L_INIT
, "switching off power LED to save power\n");
4385 acxpci_l_power_led(adev
, 0);
4387 acx_unlock(adev
, flags
);
4389 acx_sem_unlock(adev
);
4392 /* unregister the device to not let the kernel
4393 * (e.g. ioctls) access a half-deconfigured device
4394 * NB: this will cause acxpci_e_close() to be called,
4395 * thus we shouldn't call it under sem!
4396 * Well, netdev did, but ieee80211 stack does not, so we
4397 * have to do so manually...
4400 log(L_INIT
, "removing device %s\n", wiphy_name(adev
->ieee
->wiphy
));
4401 ieee80211_unregister_hw(adev
->ieee
);
4403 /* unregister_netdev ensures that no references to us left.
4404 * For paranoid reasons we continue to follow the rules */
4407 if (adev
->dev_state_mask
& ACX_STATE_IFACE_UP
) {
4409 CLEAR_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
4412 acx_proc_unregister_entries(adev
->ieee
);
4414 /* finally, clean up PCI bus state */
4415 acxpci_s_delete_dma_regions(adev
);
4417 iounmap(adev
->iobase
);
4419 iounmap(adev
->iobase2
);
4420 release_mem_region(vdev
->mem_start
, vdev
->mem_end
- vdev
->mem_start
);
4422 /* remove dev registration */
4424 acx_sem_unlock(adev
);
4425 vlynq_disable_device(vdev
);
4427 /* Free netdev (quite late,
4428 * since otherwise we might get caught off-guard
4429 * by a netdev timeout handler execution
4430 * expecting to see a working dev...) */
4431 ieee80211_free_hw(adev
->ieee
);
4437 static struct vlynq_driver vlynq_acx
= {
4438 .name
= "acx_vlynq",
4439 .id_table
= acx_vlynq_id
,
4440 .probe
= vlynq_probe
,
4441 .remove
= __devexit_p(vlynq_remove
),
4443 #endif /* CONFIG_VLYNQ */
4446 /***********************************************************************
4447 ** Data for init_module/cleanup_module
4450 static const struct pci_device_id acxpci_id_tbl
[] __devinitdata
= {
4452 .vendor
= PCI_VENDOR_ID_TI
,
4453 .device
= PCI_DEVICE_ID_TI_TNETW1100A
,
4454 .subvendor
= PCI_ANY_ID
,
4455 .subdevice
= PCI_ANY_ID
,
4456 .driver_data
= CHIPTYPE_ACX100
,
4459 .vendor
= PCI_VENDOR_ID_TI
,
4460 .device
= PCI_DEVICE_ID_TI_TNETW1100B
,
4461 .subvendor
= PCI_ANY_ID
,
4462 .subdevice
= PCI_ANY_ID
,
4463 .driver_data
= CHIPTYPE_ACX100
,
4466 .vendor
= PCI_VENDOR_ID_TI
,
4467 .device
= PCI_DEVICE_ID_TI_TNETW1130
,
4468 .subvendor
= PCI_ANY_ID
,
4469 .subdevice
= PCI_ANY_ID
,
4470 .driver_data
= CHIPTYPE_ACX111
,
4481 MODULE_DEVICE_TABLE(pci
, acxpci_id_tbl
);
4483 /* FIXME: checks should be removed once driver is included in the kernel */
4484 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 11)
4485 /* pci_name() got introduced at start of 2.6.x,
4486 * got mandatory (slot_name member removed) in 2.6.11-bk1 */
4487 #define pci_name(x) x->slot_name
4490 static struct pci_driver
4493 .id_table
= acxpci_id_tbl
,
4494 .probe
= acxpci_e_probe
,
4495 .remove
= __devexit_p(acxpci_e_remove
),
4497 .suspend
= acxpci_e_suspend
,
4498 .resume
= acxpci_e_resume
4499 #endif /* CONFIG_PM */
4501 #endif /* CONFIG_PCI */
4503 /***********************************************************************
4504 ** acxpci_e_init_module
4506 ** Module initialization routine, called once at module load time
4508 int __init
acxpci_e_init_module(void)
4514 #if (ACX_IO_WIDTH==32)
4515 printk("acx: compiled to use 32bit I/O access. "
4516 "I/O timing issues might occur, such as "
4517 "non-working firmware upload. Report them\n");
4519 printk("acx: compiled to use 16bit I/O access only "
4520 "(compatibility mode)\n");
4523 #ifdef __LITTLE_ENDIAN
4524 #define ENDIANNESS_STRING "running on a little-endian CPU\n"
4526 #define ENDIANNESS_STRING "running on a BIG-ENDIAN CPU\n"
4529 "acx: " ENDIANNESS_STRING
4530 "acx: PCI/VLYNQ module " ACX_RELEASE
" initialized, "
4531 "waiting for cards to probe...\n");
4534 res
= pci_register_driver(&acxpci_drv_id
);
4537 res
= vlynq_register_driver(&vlynq_acx
);
4544 /***********************************************************************
4545 ** acxpci_e_cleanup_module
4547 ** Called at module unload time. This is our last chance to
4548 ** clean up after ourselves.
4550 void __exit
acxpci_e_cleanup_module(void)
4555 pci_unregister_driver(&acxpci_drv_id
);
4558 vlynq_unregister_driver(&vlynq_acx
);
4561 "acx: PCI module " ACX_RELEASE
" unloaded\n");