1 /**** (legal) claimer in README
2 ** Copyright (C) 2003 ACX100 Open Source Project
4 #define ACX_MAC80211_PCI 1
6 #include <linux/version.h>
8 /* Linux 2.6.18+ uses <linux/utsrelease.h> */
10 #include <linux/utsrelease.h>
13 #include <linux/compiler.h> /* required for Lx 2.6.8 ?? */
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/moduleparam.h>
17 #include <linux/sched.h>
18 #include <linux/types.h>
19 #include <linux/skbuff.h>
20 #include <linux/slab.h>
21 #include <linux/if_arp.h>
22 #include <linux/rtnetlink.h>
23 #include <linux/wireless.h>
24 #include <net/iw_handler.h>
25 #include <linux/netdevice.h>
26 #include <linux/ioport.h>
27 #include <linux/pci.h>
29 #include <linux/vmalloc.h>
30 #include <linux/ethtool.h>
31 #include <linux/dma-mapping.h>
32 #include <linux/workqueue.h>
34 #include <linux/vlynq.h>
41 /***********************************************************************
44 #define PCI_TYPE (PCI_USES_MEM | PCI_ADDR0 | PCI_NO_ACPI_WAKE)
45 #define PCI_ACX100_REGION1 0x01
46 #define PCI_ACX100_REGION1_SIZE 0x1000 /* Memory size - 4K bytes */
47 #define PCI_ACX100_REGION2 0x02
48 #define PCI_ACX100_REGION2_SIZE 0x10000 /* Memory size - 64K bytes */
50 #define PCI_ACX111_REGION1 0x00
51 #define PCI_ACX111_REGION1_SIZE 0x2000 /* Memory size - 8K bytes */
52 #define PCI_ACX111_REGION2 0x01
53 #define PCI_ACX111_REGION2_SIZE 0x20000 /* Memory size - 128K bytes */
55 /* Texas Instruments Vendor ID */
56 #define PCI_VENDOR_ID_TI 0x104c
58 /* ACX100 22Mb/s WLAN controller */
59 #define PCI_DEVICE_ID_TI_TNETW1100A 0x8400
60 #define PCI_DEVICE_ID_TI_TNETW1100B 0x8401
62 /* ACX111 54Mb/s WLAN controller */
63 #define PCI_DEVICE_ID_TI_TNETW1130 0x9066
65 /* PCI Class & Sub-Class code, Network-'Other controller' */
66 #define PCI_CLASS_NETWORK_OTHERS 0x0280
68 #define CARD_EEPROM_ID_SIZE 6
71 /* From include/linux/pci.h */
78 #define PCI_POWER_ERROR -1
80 #endif /* CONFIG_PCI */
82 /***********************************************************************
85 static irqreturn_t
acxpci_i_interrupt(int irq
, void *dev_id
);
87 static void disable_acx_irq(acx_device_t
* adev
);
89 static int acxpci_e_open(struct ieee80211_hw
*hw
);
90 static void acxpci_e_close(struct ieee80211_hw
*hw
);
91 static void acxpci_s_up(struct ieee80211_hw
*hw
);
92 static void acxpci_s_down(struct ieee80211_hw
*hw
);
94 /***********************************************************************
100 /* OS I/O routines *always* be endianness-clean but having them doesn't hurt */
101 #define acx_readl(v) le32_to_cpu(readl((v)))
102 #define acx_readw(v) le16_to_cpu(readw((v)))
103 #define acx_writew(v,r) writew(le16_to_cpu((v)), r)
104 #define acx_writel(v,r) writel(le32_to_cpu((v)), r)
107 /* #define INLINE_IO static */
108 #define INLINE_IO static inline
110 INLINE_IO u32
read_reg32(acx_device_t
* adev
, unsigned int offset
)
112 #if ACX_IO_WIDTH == 32
113 return acx_readl((u8
*) adev
->iobase
+ adev
->io
[offset
]);
115 return acx_readw((u8
*) adev
->iobase
+ adev
->io
[offset
])
116 + (acx_readw((u8
*) adev
->iobase
+ adev
->io
[offset
] + 2) << 16);
120 INLINE_IO u16
read_reg16(acx_device_t
* adev
, unsigned int offset
)
122 return acx_readw((u8
*) adev
->iobase
+ adev
->io
[offset
]);
125 INLINE_IO u8
read_reg8(acx_device_t
* adev
, unsigned int offset
)
127 return readb((u8
*) adev
->iobase
+ adev
->io
[offset
]);
130 INLINE_IO
void write_reg32(acx_device_t
* adev
, unsigned int offset
, u32 val
)
132 #if ACX_IO_WIDTH == 32
133 acx_writel(val
, (u8
*) adev
->iobase
+ adev
->io
[offset
]);
135 acx_writew(val
& 0xffff, (u8
*) adev
->iobase
+ adev
->io
[offset
]);
136 acx_writew(val
>> 16, (u8
*) adev
->iobase
+ adev
->io
[offset
] + 2);
140 INLINE_IO
void write_reg16(acx_device_t
* adev
, unsigned int offset
, u16 val
)
142 acx_writew(val
, (u8
*) adev
->iobase
+ adev
->io
[offset
]);
145 INLINE_IO
void write_reg8(acx_device_t
* adev
, unsigned int offset
, u8 val
)
147 writeb(val
, (u8
*) adev
->iobase
+ adev
->io
[offset
]);
150 /* Handle PCI posting properly:
151 * Make sure that writes reach the adapter in case they require to be executed
152 * *before* the next write, by reading a random (and safely accessible) register.
153 * This call has to be made if there is no read following (which would flush the data
154 * to the adapter), yet the written data has to reach the adapter immediately. */
155 INLINE_IO
void write_flush(acx_device_t
* adev
)
157 /* readb(adev->iobase + adev->io[IO_ACX_INFO_MAILBOX_OFFS]); */
158 /* faster version (accesses the first register, IO_ACX_SOFT_RESET,
159 * which should also be safe): */
163 INLINE_IO
int adev_present(acx_device_t
* adev
)
165 /* fast version (accesses the first register, IO_ACX_SOFT_RESET,
166 * which should be safe): */
167 return acx_readl(adev
->iobase
) != 0xffffffff;
171 /***********************************************************************
173 static inline txdesc_t
*get_txdesc(acx_device_t
* adev
, int index
)
175 return (txdesc_t
*) (((u8
*) adev
->txdesc_start
) +
176 index
* adev
->txdesc_size
);
179 static inline txdesc_t
*advance_txdesc(acx_device_t
* adev
, txdesc_t
* txdesc
,
182 return (txdesc_t
*) (((u8
*) txdesc
) + inc
* adev
->txdesc_size
);
185 static txhostdesc_t
*get_txhostdesc(acx_device_t
* adev
, txdesc_t
* txdesc
)
187 int index
= (u8
*) txdesc
- (u8
*) adev
->txdesc_start
;
191 if (unlikely(ACX_DEBUG
&& (index
% adev
->txdesc_size
))) {
192 acx_log(LOG_WARNING
, L_ANY
, "bad txdesc ptr %p\n", txdesc
);
195 index
/= adev
->txdesc_size
;
196 if (unlikely(ACX_DEBUG
&& (index
>= TX_CNT
))) {
197 acx_log(LOG_WARNING
, L_ANY
, "bad txdesc ptr %p\n", txdesc
);
203 return &adev
->txhostdesc_start
[index
* 2];
210 /***********************************************************************
211 ** EEPROM and PHY read/write helpers
213 /***********************************************************************
214 ** acxpci_read_eeprom_byte
216 ** Function called to read an octet in the EEPROM.
218 ** This function is used by acxpci_e_probe to check if the
219 ** connected card is a legal one or not.
222 ** adev ptr to acx_device structure
223 ** addr address to read in the EEPROM
224 ** charbuf ptr to a char. This is where the read octet
228 int acxpci_read_eeprom_byte(acx_device_t
* adev
, u32 addr
, u8
* charbuf
)
235 write_reg32(adev
, IO_ACX_EEPROM_CFG
, 0);
236 write_reg32(adev
, IO_ACX_EEPROM_ADDR
, addr
);
238 write_reg32(adev
, IO_ACX_EEPROM_CTL
, 2);
241 while (read_reg16(adev
, IO_ACX_EEPROM_CTL
)) {
242 /* scheduling away instead of CPU burning loop
243 * doesn't seem to work here at all:
244 * awful delay, sometimes also failure.
245 * Doesn't matter anyway (only small delay). */
246 if (unlikely(!--count
)) {
247 acx_log(LOG_WARNING
, L_ANY
,
248 "%s: timeout waiting for EEPROM read\n",
249 wiphy_name(adev
->ieee
->wiphy
));
256 *charbuf
= read_reg8(adev
, IO_ACX_EEPROM_DATA
);
257 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "EEPROM at 0x%04X = 0x%02X\n",
267 /***********************************************************************
268 ** We don't lock hw accesses here since we never r/w eeprom in IRQ
269 ** Note: this function sleeps only because of GFP_KERNEL alloc
273 acxpci_s_write_eeprom(acx_device_t
* adev
, u32 addr
, u32 len
,
276 u8
*data_verify
= NULL
;
282 acx_log(LOG_WARNING
, L_ANY
, "WARNING! I would write to EEPROM now. "
283 "Since I really DON'T want to unless you know "
284 "what you're doing (THIS CODE WILL PROBABLY "
285 "NOT WORK YET!), I will abort that now. And "
286 "definitely make sure to make a "
287 "/proc/driver/acx_wlan0_eeprom backup copy first!!! "
288 "(the EEPROM content includes the PCI config header!! "
289 "If you kill important stuff, then you WILL "
290 "get in trouble and people DID get in trouble already)\n");
295 data_verify
= kmalloc(len
, GFP_KERNEL
);
300 /* first we need to enable the OE (EEPROM Output Enable) GPIO line
301 * to be able to write to the EEPROM.
302 * NOTE: an EEPROM writing success has been reported,
303 * but you probably have to modify GPIO_OUT, too,
304 * and you probably need to activate a different GPIO
306 gpio_orig
= read_reg16(adev
, IO_ACX_GPIO_OE
);
307 write_reg16(adev
, IO_ACX_GPIO_OE
, gpio_orig
& ~1);
310 /* ok, now start writing the data out */
311 for (i
= 0; i
< len
; i
++) {
312 write_reg32(adev
, IO_ACX_EEPROM_CFG
, 0);
313 write_reg32(adev
, IO_ACX_EEPROM_ADDR
, addr
+ i
);
314 write_reg32(adev
, IO_ACX_EEPROM_DATA
, *(charbuf
+ i
));
316 write_reg32(adev
, IO_ACX_EEPROM_CTL
, 1);
319 while (read_reg16(adev
, IO_ACX_EEPROM_CTL
)) {
320 if (unlikely(!--count
)) {
321 acx_log(LOG_WARNING
, L_ANY
, "WARNING, DANGER!!! "
322 "Timeout waiting for EEPROM write\n");
329 /* disable EEPROM writing */
330 write_reg16(adev
, IO_ACX_GPIO_OE
, gpio_orig
);
333 /* now start a verification run */
334 for (i
= 0; i
< len
; i
++) {
335 write_reg32(adev
, IO_ACX_EEPROM_CFG
, 0);
336 write_reg32(adev
, IO_ACX_EEPROM_ADDR
, addr
+ i
);
338 write_reg32(adev
, IO_ACX_EEPROM_CTL
, 2);
341 while (read_reg16(adev
, IO_ACX_EEPROM_CTL
)) {
342 if (unlikely(!--count
)) {
343 acx_log(LOG_WARNING
, L_ANY
,
344 "timeout waiting for EEPROM read\n");
350 data_verify
[i
] = read_reg16(adev
, IO_ACX_EEPROM_DATA
);
353 if (0 == memcmp(charbuf
, data_verify
, len
))
354 result
= OK
; /* read data matches, success */
364 /***********************************************************************
365 ** acxpci_s_read_phy_reg
367 ** Messing with rx/tx disabling and enabling here
368 ** (write_reg32(adev, IO_ACX_ENABLE, 0b000000xx)) kills traffic
370 int acxpci_s_read_phy_reg(acx_device_t
* adev
, u32 reg
, u8
* charbuf
)
377 write_reg32(adev
, IO_ACX_PHY_ADDR
, reg
);
379 write_reg32(adev
, IO_ACX_PHY_CTL
, 2);
382 while (read_reg32(adev
, IO_ACX_PHY_CTL
)) {
383 /* scheduling away instead of CPU burning loop
384 * doesn't seem to work here at all:
385 * awful delay, sometimes also failure.
386 * Doesn't matter anyway (only small delay). */
387 if (unlikely(!--count
)) {
388 acx_log(LOG_WARNING
, L_ANY
,
389 "%s: timeout waiting for phy read\n",
390 wiphy_name(adev
->ieee
->wiphy
));
397 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "count was %u\n", count
);
398 *charbuf
= read_reg8(adev
, IO_ACX_PHY_DATA
);
400 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "radio PHY at 0x%04X = 0x%02X\n",
403 goto fail
; /* silence compiler warning */
410 /***********************************************************************
412 int acxpci_s_write_phy_reg(acx_device_t
* adev
, u32 reg
, u8 value
)
416 /* mprusko said that 32bit accesses result in distorted sensitivity
417 * on his card. Unconfirmed, looks like it's not true (most likely since we
418 * now properly flush writes). */
419 write_reg32(adev
, IO_ACX_PHY_DATA
, value
);
420 write_reg32(adev
, IO_ACX_PHY_ADDR
, reg
);
422 write_reg32(adev
, IO_ACX_PHY_CTL
, 1);
424 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
425 "radio PHY write 0x%02X at 0x%04X\n",
433 #define NO_AUTO_INCREMENT 1
435 /***********************************************************************
438 ** Write the firmware image into the card.
441 ** adev wlan device structure
442 ** fw_image firmware image.
445 ** 1 firmware image corrupted
448 ** Standard csum implementation + write to IO
451 acxpci_s_write_fw(acx_device_t
* adev
, const firmware_image_t
*fw_image
,
456 /* we skip the first four bytes which contain the control sum */
458 const u8
*p
= (u8
*) fw_image
+ 4;
462 /* start the image checksum by adding the image size value */
463 sum
= p
[0] + p
[1] + p
[2] + p
[3];
466 write_reg32(adev
, IO_ACX_SLV_END_CTL
, 0);
468 #if NO_AUTO_INCREMENT
469 write_reg32(adev
, IO_ACX_SLV_MEM_CTL
, 0); /* use basic mode */
471 write_reg32(adev
, IO_ACX_SLV_MEM_CTL
, 1); /* use autoincrement mode */
472 write_reg32(adev
, IO_ACX_SLV_MEM_ADDR
, offset
); /* configure start address */
477 size
= le32_to_cpu(fw_image
->size
) & (~3);
479 while (likely(len
< size
)) {
480 v32
= be32_to_cpu(*(u32
*) p
);
481 sum
+= p
[0] + p
[1] + p
[2] + p
[3];
485 #if NO_AUTO_INCREMENT
486 write_reg32(adev
, IO_ACX_SLV_MEM_ADDR
, offset
+ len
- 4);
489 write_reg32(adev
, IO_ACX_SLV_MEM_DATA
, v32
);
492 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
493 "firmware written, size:%d sum1:%x sum2:%x\n",
494 size
, sum
, le32_to_cpu(fw_image
->chksum
));
496 /* compare our checksum with the stored image checksum */
497 FN_EXIT1(sum
!= le32_to_cpu(fw_image
->chksum
));
498 return (sum
!= le32_to_cpu(fw_image
->chksum
));
502 /***********************************************************************
503 ** acxpci_s_validate_fw
505 ** Compare the firmware image given with
506 ** the firmware image written into the card.
509 ** adev wlan device structure
510 ** fw_image firmware image.
513 ** NOT_OK firmware image corrupted or not correctly written
516 ** Origin: Standard csum + Read IO
519 acxpci_s_validate_fw(acx_device_t
* adev
, const firmware_image_t
*fw_image
,
525 /* we skip the first four bytes which contain the control sum */
526 const u8
*p
= (u8
*) fw_image
+ 4;
530 /* start the image checksum by adding the image size value */
531 sum
= p
[0] + p
[1] + p
[2] + p
[3];
534 write_reg32(adev
, IO_ACX_SLV_END_CTL
, 0);
536 #if NO_AUTO_INCREMENT
537 write_reg32(adev
, IO_ACX_SLV_MEM_CTL
, 0); /* use basic mode */
539 write_reg32(adev
, IO_ACX_SLV_MEM_CTL
, 1); /* use autoincrement mode */
540 write_reg32(adev
, IO_ACX_SLV_MEM_ADDR
, offset
); /* configure start address */
544 size
= le32_to_cpu(fw_image
->size
) & (~3);
546 while (likely(len
< size
)) {
547 v32
= be32_to_cpu(*(u32
*) p
);
551 #if NO_AUTO_INCREMENT
552 write_reg32(adev
, IO_ACX_SLV_MEM_ADDR
, offset
+ len
- 4);
554 w32
= read_reg32(adev
, IO_ACX_SLV_MEM_DATA
);
556 if (unlikely(w32
!= v32
)) {
557 acx_log(LOG_WARNING
, L_ANY
,"FATAL: firmware upload: "
558 "data parts at offset %d don't match "
559 "(0x%08X vs. 0x%08X)! I/O timing issues "
560 "or defective memory, with DWL-xx0+? "
561 "ACX_IO_WIDTH=16 may help. Please report\n",
568 (u8
) w32
+ (u8
) (w32
>> 8) + (u8
) (w32
>> 16) +
572 /* sum control verification */
573 if (result
!= NOT_OK
) {
574 if (sum
!= le32_to_cpu(fw_image
->chksum
)) {
575 acx_log(LOG_WARNING
, L_ANY
, "FATAL: firmware upload: "
576 "checksums don't match!\n");
586 /***********************************************************************
587 ** acxpci_s_upload_fw
589 ** Called from acx_reset_dev
591 ** Origin: Derived from FW dissection
593 static int acxpci_s_upload_fw(acx_device_t
* adev
)
595 firmware_image_t
*fw_image
= NULL
;
599 char filename
[sizeof("tiacx1NNcNN")];
603 /* print exact chipset and radio ID to make sure people
604 * really get a clue on which files exactly they need to provide.
605 * Firmware loading is a frequent end-user PITA with these chipsets.
607 acx_log(LOG_INFO
, L_ANY
,
608 "need firmware for acx1%02d chipset "
609 "with radio ID %02X\n",
610 IS_ACX111(adev
)*11, adev
->radio_type
);
611 acx_log(LOG_INFO
, L_ANY
, "Please provide via firmware hotplug:\n");
612 acx_log(LOG_INFO
, L_ANY
, "either combined firmware "
613 "(single file named 'tiacx1%02dc%02X')\n"
614 "or two files (base firmware file 'tiacx1%02d' "
615 "+ radio fw 'tiacx1%02dr%02X')\n",
616 IS_ACX111(adev
)*11, adev
->radio_type
,
618 IS_ACX111(adev
)*11, adev
->radio_type
621 /* print exact chipset and radio ID to make sure people really get a
622 * clue on which files exactly they are supposed to provide, since
623 * firmware loading is the biggest enduser PITA with these chipsets.
624 * Not printing radio ID in 0xHEX in order to not confuse them into
626 * COMMENTED OUT: this was already printed above
628 // printk( "acx: need to load firmware for acx1%02d chipset with radio ID %02x, please provide via firmware hotplug:\n"
629 // "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",
630 // IS_ACX111(adev)*11, adev->radio_type);
632 /* Try combined, then main image */
633 adev
->need_radio_fw
= 0;
634 snprintf(filename
, sizeof(filename
), "tiacx1%02dc%02X",
635 IS_ACX111(adev
) * 11, adev
->radio_type
);
637 fw_image
= acx_s_read_fw(adev
->bus_dev
, filename
, &file_size
);
639 adev
->need_radio_fw
= 1;
640 filename
[sizeof("tiacx1NN") - 1] = '\0';
642 acx_s_read_fw(adev
->bus_dev
, filename
, &file_size
);
649 for (try = 1; try <= 5; try++) {
650 res
= acxpci_s_write_fw(adev
, fw_image
, 0);
651 acx_log(LOG_DEBUG
, L_INIT
| L_REALLYVERBOSE
,
652 "acx_write_fw (main/combined): %d\n", res
);
654 res
= acxpci_s_validate_fw(adev
, fw_image
, 0);
655 acx_log(LOG_DEBUG
, L_INIT
| L_REALLYVERBOSE
,
656 "acx_validate_fw (main/combined): %d\n", res
);
660 SET_BIT(adev
->dev_state_mask
, ACX_STATE_FW_LOADED
);
663 acx_log(LOG_WARNING
, L_ANY
,
664 "firmware upload attempt #%d FAILED, "
665 "retrying...\n", try);
666 acx_s_mwait(1000); /* better wait for a while... */
676 /***********************************************************************
677 ** acxpci_s_upload_radio
679 ** Uploads the appropriate radio module firmware into the card.
681 ** Origin: Standard Read/Write to IO
683 int acxpci_s_upload_radio(acx_device_t
* adev
)
686 firmware_image_t
*radio_image
;
687 acx_cmd_radioinit_t radioinit
;
692 char filename
[sizeof("tiacx1NNrNN")];
694 if (!adev
->need_radio_fw
)
699 acx_s_interrogate(adev
, &mm
, ACX1xx_IE_MEMORY_MAP
);
700 offset
= le32_to_cpu(mm
.CodeEnd
);
702 snprintf(filename
, sizeof(filename
), "tiacx1%02dr%02X",
703 IS_ACX111(adev
) * 11, adev
->radio_type
);
704 radio_image
= acx_s_read_fw(adev
->bus_dev
, filename
, &size
);
706 acx_log(LOG_WARNING
, L_ANY
, "can't load radio module '%s'\n",
711 acx_s_issue_cmd(adev
, ACX1xx_CMD_SLEEP
, NULL
, 0);
713 for (try = 1; try <= 5; try++) {
714 res
= acxpci_s_write_fw(adev
, radio_image
, offset
);
715 acx_log(LOG_DEBUG
, L_INIT
| L_REALLYVERBOSE
,
716 "acx_write_fw (radio): %d\n", res
);
718 res
= acxpci_s_validate_fw(adev
, radio_image
, offset
);
719 acx_log(LOG_DEBUG
, L_INIT
| L_REALLYVERBOSE
,
720 "acx_validate_fw (radio): %d\n", res
);
725 acx_log(LOG_WARNING
, L_ANY
,
726 "radio firmware upload attempt #%d FAILED, "
727 "retrying...\n", try);
728 acx_s_mwait(1000); /* better wait for a while... */
731 acx_s_issue_cmd(adev
, ACX1xx_CMD_WAKE
, NULL
, 0);
732 radioinit
.offset
= cpu_to_le32(offset
);
733 /* no endian conversion needed, remains in card CPU area: */
734 radioinit
.len
= radio_image
->size
;
741 /* will take a moment so let's have a big timeout */
742 acx_s_issue_cmd_timeo(adev
, ACX1xx_CMD_RADIOINIT
,
743 &radioinit
, sizeof(radioinit
),
744 CMD_TIMEOUT_MS(1000));
746 res
= acx_s_interrogate(adev
, &mm
, ACX1xx_IE_MEMORY_MAP
);
753 /***********************************************************************
754 ** acxpci_l_reset_mac
757 ** Call context: reset_dev
759 ** Origin: Standard Read/Write to IO
761 static void acxpci_l_reset_mac(acx_device_t
* adev
)
768 temp
= read_reg16(adev
, IO_ACX_ECPU_CTRL
) | 0x1;
769 write_reg16(adev
, IO_ACX_ECPU_CTRL
, temp
);
771 /* now do soft reset of eCPU, set bit */
772 temp
= read_reg16(adev
, IO_ACX_SOFT_RESET
) | 0x1;
773 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "enable soft reset\n");
774 write_reg16(adev
, IO_ACX_SOFT_RESET
, temp
);
777 /* now clear bit again: deassert eCPU reset */
778 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
779 "disable soft reset and go to init mode\n");
780 write_reg16(adev
, IO_ACX_SOFT_RESET
, temp
& ~0x1);
782 /* now start a burst read from initial EEPROM */
783 temp
= read_reg16(adev
, IO_ACX_EE_START
) | 0x1;
784 write_reg16(adev
, IO_ACX_EE_START
, temp
);
791 /***********************************************************************
792 ** acxpci_s_verify_init
794 static int acxpci_s_verify_init(acx_device_t
* adev
)
797 unsigned long timeout
;
801 timeout
= jiffies
+ 2 * HZ
;
803 u16 irqstat
= read_reg16(adev
, IO_ACX_IRQ_STATUS_NON_DES
);
804 if (irqstat
& ACX_IRQ_FCS_THRESHOLD
) {
806 write_reg16(adev
, IO_ACX_IRQ_ACK
,
807 ACX_IRQ_FCS_THRESHOLD
);
810 if (time_after(jiffies
, timeout
))
812 /* Init may take up to ~0.5 sec total */
821 /***********************************************************************
822 ** A few low-level helpers
824 ** Note: these functions are not protected by lock
825 ** and thus are never allowed to be called from IRQ.
826 ** Also they must not race with fw upload which uses same hw regs
829 /***********************************************************************
830 ** acxpci_write_cmd_type_status
832 ** Origin: Common linux implementation
836 acxpci_write_cmd_type_status(acx_device_t
* adev
, u16 type
, u16 status
)
839 acx_writel(type
| (status
<< 16), adev
->cmd_area
);
845 /***********************************************************************
846 ** acxpci_read_cmd_type_status
848 ** Origin: Common linux implementation
850 static u32
acxpci_read_cmd_type_status(acx_device_t
* adev
)
852 u32 cmd_type
, cmd_status
;
856 cmd_type
= acx_readl(adev
->cmd_area
);
857 cmd_status
= (cmd_type
>> 16);
858 cmd_type
= (u16
) cmd_type
;
860 acx_log(LOG_DEBUG
, L_CTL
, "cmd_type:%04X cmd_status:%04X [%s]\n",
861 cmd_type
, cmd_status
, acx_cmd_status_str(cmd_status
));
863 FN_EXIT1(cmd_status
);
868 /***********************************************************************
869 ** acxpci_s_reset_dev
872 ** netdevice that contains the adev variable
877 ** device is hard reset
881 ** This resets the device using low level hardware calls
882 ** as well as uploads and verifies the firmware to the card
885 static inline void init_mboxes(acx_device_t
* adev
)
887 u32 cmd_offs
, info_offs
;
891 cmd_offs
= read_reg32(adev
, IO_ACX_CMD_MAILBOX_OFFS
);
892 info_offs
= read_reg32(adev
, IO_ACX_INFO_MAILBOX_OFFS
);
893 adev
->cmd_area
= (u8
*) adev
->iobase2
+ cmd_offs
;
894 adev
->info_area
= (u8
*) adev
->iobase2
+ info_offs
;
895 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "iobase2=%p\n", adev
->iobase2
);
896 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "cmd_mbox_offset=%X cmd_area=%p\n",
897 cmd_offs
, adev
->cmd_area
);
898 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
899 "info_mbox_offset=%X info_area=%p\n",
900 info_offs
, adev
->info_area
);
905 static inline void read_eeprom_area(acx_device_t
* adev
)
913 for (offs
= 0x8c; offs
< 0xb9; offs
++)
914 acxpci_read_eeprom_byte(adev
, offs
, &tmp
);
921 int acxpci_s_reset_dev(acx_device_t
* adev
)
923 const char *msg
= "";
932 /* reset the device to make sure the eCPU is stopped
933 * to upload the firmware correctly */
935 acx_lock(adev
, flags
);
938 acxpci_l_reset_mac(adev
);
941 ecpu_ctrl
= read_reg16(adev
, IO_ACX_ECPU_CTRL
) & 1;
943 msg
= "eCPU is already running. ";
947 if (read_reg16(adev
, IO_ACX_SOR_CFG
) & 2) {
948 /* eCPU most likely means "embedded CPU" */
949 msg
= "eCPU did not start after boot from flash. ";
953 /* check sense on reset flags */
954 if (read_reg16(adev
, IO_ACX_SOR_CFG
) & 0x10) {
955 printk("%s: eCPU did not start after boot (SOR), "
956 "is this fatal?\n", wiphy_name(adev
->ieee
->wiphy
));
959 /* scan, if any, is stopped now, setting corresponding IRQ bit */
960 SET_BIT(adev
->irq_status
, ACX_IRQ_SCAN_COMPLETE
);
962 acx_unlock(adev
, flags
);
964 /* need to know radio type before fw load */
965 /* Need to wait for arrival of this information in a loop,
966 * most probably since eCPU runs some init code from EEPROM
967 * (started burst read in reset_mac()) which also
968 * sets the radio type ID */
972 hardware_info
= read_reg16(adev
, IO_ACX_EEPROM_INFORMATION
);
974 msg
= "eCPU didn't indicate radio type";
978 } while (!(hardware_info
& 0xff00)); /* radio type still zero? */
980 /* printk("DEBUG: count %d\n", count); */
981 adev
->form_factor
= hardware_info
& 0xff;
982 adev
->radio_type
= hardware_info
>> 8;
984 /* load the firmware */
985 if (OK
!= acxpci_s_upload_fw(adev
))
988 /* acx_s_mwait(10); this one really shouldn't be required */
990 /* now start eCPU by clearing bit */
991 write_reg16(adev
, IO_ACX_ECPU_CTRL
, ecpu_ctrl
& ~0x1);
992 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
993 "booted eCPU up and waiting for completion...\n");
995 /* wait for eCPU bootup */
996 if (OK
!= acxpci_s_verify_init(adev
)) {
997 msg
= "timeout waiting for eCPU. ";
1000 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
1001 "eCPU has woken up, card is ready to be configured\n");
1004 acxpci_write_cmd_type_status(adev
, 0, 0);
1006 /* test that EEPROM is readable */
1007 read_eeprom_area(adev
);
1012 /* Finish error message. Indicate which function failed */
1014 acx_unlock(adev
, flags
);
1016 acx_log(LOG_WARNING
, L_ANY
, "%sreset_dev() FAILED\n", msg
);
1023 /***********************************************************************
1024 ** acxpci_s_issue_cmd_timeo
1026 ** Sends command to fw, extract result
1028 ** NB: we do _not_ take lock inside, so be sure to not touch anything
1029 ** which may interfere with IRQ handler operation
1031 ** TODO: busy wait is a bit silly, so:
1032 ** 1) stop doing many iters - go to sleep after first
1033 ** 2) go to waitqueue based approach: wait, not poll!
1036 #define FUNC "issue_cmd"
1040 acxpci_s_issue_cmd_timeo(acx_device_t
* adev
,
1042 void *buffer
, unsigned buflen
, unsigned cmd_timeout
)
1046 acxpci_s_issue_cmd_timeo_debug(acx_device_t
* adev
,
1050 unsigned cmd_timeout
, const char *cmdstr
)
1052 unsigned long start
= jiffies
;
1054 const char *devname
;
1058 unsigned long timeout
;
1062 devname
= wiphy_name(adev
->ieee
->wiphy
);
1063 if (!devname
|| !devname
[0] || devname
[4] == '%')
1066 acx_log(LOG_DEBUG
, L_CTL
,
1067 FUNC
"(cmd:%s,buflen:%u,timeout:%ums,type:0x%04X)\n",
1068 cmdstr
, buflen
, cmd_timeout
,
1069 buffer
? le16_to_cpu(((acx_ie_generic_t
*) buffer
)->type
) : -1);
1071 if (!(adev
->dev_state_mask
& ACX_STATE_FW_LOADED
)) {
1072 acx_log(LOG_WARNING
, L_ANY
,
1073 "%s: " FUNC
"(): firmware is not loaded yet, "
1074 "cannot execute commands!\n", devname
);
1078 if (cmd
!= ACX1xx_CMD_INTERROGATE
)
1079 acx_log_dump(LOG_DEBUG
, L_REALLYVERBOSE
, buffer
, buflen
,
1082 /* wait for firmware to become idle for our command submission */
1084 counter
= (timeout
* 1000 / HZ
) - 1; /* in ms */
1087 cmd_status
= acxpci_read_cmd_type_status(adev
);
1088 /* Test for IDLE state */
1091 if (counter
% 8 == 0) {
1092 if (time_after(jiffies
, timeout
)) {
1096 /* we waited 8 iterations, no luck. Sleep 8 ms */
1099 } while (likely(--counter
));
1102 /* the card doesn't get idle, we're in trouble */
1103 acx_log(LOG_WARNING
, L_ANY
,
1104 "%s: " FUNC
"(): cmd_status is not IDLE: 0x%04X!=0\n",
1105 devname
, cmd_status
);
1107 } else if (counter
< 190) { /* if waited >10ms... */
1108 acx_log(LOG_DEBUG
, L_CTL
| L_REALLYVERBOSE
,
1109 FUNC
"(): waited for IDLE %dms. "
1110 "Please report\n", 199 - counter
);
1113 /* now write the parameters of the command if needed */
1114 if (buffer
&& buflen
) {
1115 /* if it's an INTERROGATE command, just pass the length
1116 * of parameters to read, as data */
1118 if (cmd
== ACX1xx_CMD_INTERROGATE
)
1119 memset_io(adev
->cmd_area
+ 4, 0xAA, buflen
);
1121 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1122 memcpy_toio(adev
->cmd_area
+ 4, buffer
,
1123 (cmd
== ACX1xx_CMD_INTERROGATE
) ? 4 : buflen
);
1125 /* now write the actual command type */
1126 acxpci_write_cmd_type_status(adev
, cmd
, 0);
1127 /* execute command */
1128 write_reg16(adev
, IO_ACX_INT_TRIG
, INT_TRIG_CMD
);
1131 /* wait for firmware to process command */
1133 /* Ensure nonzero and not too large timeout.
1134 ** Also converts e.g. 100->99, 200->199
1135 ** which is nice but not essential */
1136 cmd_timeout
= (cmd_timeout
- 1) | 1;
1137 if (unlikely(cmd_timeout
> 1199))
1139 /* clear CMD_COMPLETE bit. can be set only by IRQ handler: */
1140 CLEAR_BIT(adev
->irq_status
, ACX_IRQ_CMD_COMPLETE
);
1141 /* we schedule away sometimes (timeout can be large) */
1142 counter
= cmd_timeout
;
1143 timeout
= jiffies
+ HZ
;
1145 if (!adev
->irqs_active
) { /* IRQ disabled: poll */
1146 irqtype
= read_reg16(adev
, IO_ACX_IRQ_STATUS_NON_DES
);
1147 if (irqtype
& ACX_IRQ_CMD_COMPLETE
) {
1148 write_reg16(adev
, IO_ACX_IRQ_ACK
,
1149 ACX_IRQ_CMD_COMPLETE
);
1152 } else { /* Wait when IRQ will set the bit */
1153 irqtype
= adev
->irq_status
;
1154 if (irqtype
& ACX_IRQ_CMD_COMPLETE
)
1158 if (counter
% 8 == 0) {
1159 if (time_after(jiffies
, timeout
)) {
1163 /* we waited 8 iterations, no luck. Sleep 8 ms */
1166 } while (likely(--counter
));
1168 /* save state for debugging */
1169 cmd_status
= acxpci_read_cmd_type_status(adev
);
1171 /* put the card in IDLE state */
1172 acxpci_write_cmd_type_status(adev
, 0, 0);
1174 if ((cmd_timeout
- counter
) == 0) { /* timed out! */
1175 acx_log(LOG_WARNING
, L_ANY
,
1176 "%s: " FUNC
"(): timed out %s for CMD_COMPLETE. "
1177 "irq bits:0x%04X irq_status:0x%04X timeout:%dms "
1178 "cmd_status:%d (%s)\n",
1179 devname
, (adev
->irqs_active
) ? "waiting" : "polling",
1180 irqtype
, adev
->irq_status
, cmd_timeout
,
1181 cmd_status
, acx_cmd_status_str(cmd_status
));
1182 acx_log(LOG_WARNING
, L_ANY
, "hack: don't do: 'goto bad;' "
1183 "counter: %d, cmd_timeout: %d, "
1184 "cmd_timeout-counter: %d\n",
1185 counter
, cmd_timeout
, cmd_timeout
- counter
);
1186 } else if (counter
== 0) { /* maybe timed out! */
1187 acx_log(LOG_DEBUG
, L_CTL
| L_REALLYVERBOSE
,
1188 FUNC
"(): %s for CMD_COMPLETE %dms. "
1189 "count:%d. Please report\n",
1190 (adev
->irqs_active
) ? "waited" : "polled",
1191 cmd_timeout
- counter
, counter
);
1192 } else if ((cmd_timeout
- counter
) > 30) { /* if waited >30ms... */
1193 acx_log(LOG_DEBUG
, L_CTL
| L_REALLYVERBOSE
,
1194 FUNC
"(): %s for CMD_COMPLETE %dms. "
1195 "count:%d. Please report\n",
1196 (adev
->irqs_active
) ? "waited" : "polled",
1197 cmd_timeout
- counter
, counter
);
1200 if (1 != cmd_status
) { /* it is not a 'Success' */
1201 acx_log(LOG_WARNING
, L_ANY
,
1202 "%s: " FUNC
"(): cmd_status is not SUCCESS: %d (%s). "
1203 "Took %dms of %d\n",
1204 devname
, cmd_status
, acx_cmd_status_str(cmd_status
),
1205 cmd_timeout
- counter
, cmd_timeout
);
1206 /* zero out result buffer
1207 * WARNING: this will trash stack in case of illegally large input
1209 if (buffer
&& buflen
)
1210 memset(buffer
, 0, buflen
);
1214 /* read in result parameters if needed */
1215 if (buffer
&& buflen
&& (cmd
== ACX1xx_CMD_INTERROGATE
)) {
1216 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1217 memcpy_fromio(buffer
, adev
->cmd_area
+ 4, buflen
);
1218 acx_log_dump(LOG_DEBUG
, L_REALLYVERBOSE
, buffer
, buflen
,
1219 "output buffer:\n");
1222 acx_log(LOG_DEBUG
, L_CTL
, FUNC
"(%s): took %ld jiffies to complete\n",
1223 cmdstr
, jiffies
- start
);
1228 /* Give enough info so that callers can avoid
1229 ** printing their own diagnostic messages */
1231 acx_log(LOG_WARNING
, L_ANY
,
1232 "%s: " FUNC
"(cmd:%s) FAILED\n", devname
, cmdstr
);
1234 acx_log(LOG_WARNING
, L_ANY
,
1235 "%s: " FUNC
"(cmd:0x%04X) FAILED\n", devname
, cmd
);
1243 /***********************************************************************
1245 #ifdef NONESSENTIAL_FEATURES
1246 typedef struct device_id
{
1247 unsigned char id
[6];
1252 static const device_id_t device_ids
[] = {
1254 {'G', 'l', 'o', 'b', 'a', 'l'},
1259 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
1261 "SpeedStream SS1021 or Gigafast WF721-AEX"},
1263 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85},
1265 "DrayTek Vigor 520"},
1267 {'?', '?', '?', '?', '?', '?'},
1269 "Level One WPC-0200"},
1271 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1276 static void acx_show_card_eeprom_id(acx_device_t
* adev
)
1278 unsigned char buffer
[CARD_EEPROM_ID_SIZE
];
1283 memset(&buffer
, 0, CARD_EEPROM_ID_SIZE
);
1284 /* use direct EEPROM access */
1285 for (i
= 0; i
< CARD_EEPROM_ID_SIZE
; i
++) {
1286 if (OK
!= acxpci_read_eeprom_byte(adev
,
1287 ACX100_EEPROM_ID_OFFSET
+ i
,
1289 acx_log(LOG_DEBUG
, L_ANY
, "reading EEPROM FAILED\n");
1294 for (i
= 0; i
< ARRAY_SIZE(device_ids
); i
++) {
1295 if (memcmp(&buffer
, device_ids
[i
].id
, CARD_EEPROM_ID_SIZE
))
1297 if (device_ids
[i
].descr
) {
1298 acx_log(LOG_INFO
, L_ANY
,
1299 "EEPROM card ID string check "
1300 "found %s card ID: is this %s?\n",
1301 device_ids
[i
].descr
,
1302 device_ids
[i
].type
);
1306 if (i
== ARRAY_SIZE(device_ids
)) {
1307 acx_log(LOG_WARNING
, L_ANY
,
1308 "EEPROM card ID string check found "
1309 "unknown card: expected 'Global', got '%.*s\'. "
1310 "Please report\n", CARD_EEPROM_ID_SIZE
, buffer
);
1314 #endif /* NONESSENTIAL_FEATURES */
1317 /***********************************************************************
1318 ** acxpci_free_desc_queues
1320 ** Releases the queues that have been allocated, the
1321 ** others have been initialised to NULL so this
1322 ** function can be used if only part of the queues were allocated.
1326 free_coherent(struct pci_dev
*hwdev
, size_t size
,
1327 void *vaddr
, dma_addr_t dma_handle
)
1329 dma_free_coherent(hwdev
== NULL
? NULL
: &hwdev
->dev
,
1330 size
, vaddr
, dma_handle
);
1334 void acxpci_free_desc_queues(acx_device_t
* adev
)
1336 unsigned long flags
;
1338 #define ACX_FREE_QUEUE(size, ptr, phyaddr) \
1340 free_coherent(NULL, size, ptr, phyaddr); \
1347 ACX_FREE_QUEUE(adev
->txhostdesc_area_size
, adev
->txhostdesc_start
,
1348 adev
->txhostdesc_startphy
);
1349 ACX_FREE_QUEUE(adev
->txbuf_area_size
, adev
->txbuf_start
,
1350 adev
->txbuf_startphy
);
1352 acx_lock(adev
, flags
);
1353 adev
->txdesc_start
= NULL
;
1354 acx_unlock(adev
, flags
);
1356 ACX_FREE_QUEUE(adev
->rxhostdesc_area_size
, adev
->rxhostdesc_start
,
1357 adev
->rxhostdesc_startphy
);
1358 ACX_FREE_QUEUE(adev
->rxbuf_area_size
, adev
->rxbuf_start
,
1359 adev
->rxbuf_startphy
);
1361 acx_lock(adev
, flags
);
1362 adev
->rxdesc_start
= NULL
;
1363 acx_unlock(adev
, flags
);
1369 /***********************************************************************
1370 ** acxpci_s_delete_dma_regions
1372 static void acxpci_s_delete_dma_regions(acx_device_t
* adev
)
1375 /* disable radio Tx/Rx. Shouldn't we use the firmware commands
1376 * here instead? Or are we that much down the road that it's no
1377 * longer possible here? */
1378 write_reg16(adev
, IO_ACX_ENABLE
, 0);
1382 /* NO locking for all parts of acxpci_free_desc_queues because:
1383 * while calling dma_free_coherent() interrupts need to be 'free'
1384 * but if you spinlock the whole function (acxpci_free_desc_queues)
1385 * you'll get an error */
1386 acxpci_free_desc_queues(adev
);
1392 /***********************************************************************
1395 ** Probe routine called when a PCI device w/ matching ID is found.
1396 ** Here's the sequence:
1397 ** - Allocate the PCI resources.
1398 ** - Read the PCMCIA attribute memory to make sure we have a WLAN card
1400 ** - Initialize the dev and wlan data
1401 ** - Initialize the MAC
1403 ** pdev - ptr to pci device structure containing info about pci configuration
1404 ** id - ptr to the device id entry that matched this device
1406 static const u16 IO_ACX100
[] = {
1407 0x0000, /* IO_ACX_SOFT_RESET */
1409 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1410 0x0018, /* IO_ACX_SLV_MEM_DATA */
1411 0x001c, /* IO_ACX_SLV_MEM_CTL */
1412 0x0020, /* IO_ACX_SLV_END_CTL */
1414 0x0034, /* IO_ACX_FEMR */
1416 0x007c, /* IO_ACX_INT_TRIG */
1417 0x0098, /* IO_ACX_IRQ_MASK */
1418 0x00a4, /* IO_ACX_IRQ_STATUS_NON_DES */
1419 0x00a8, /* IO_ACX_IRQ_STATUS_CLEAR */
1420 0x00ac, /* IO_ACX_IRQ_ACK */
1421 0x00b0, /* IO_ACX_HINT_TRIG */
1423 0x0104, /* IO_ACX_ENABLE */
1425 0x0250, /* IO_ACX_EEPROM_CTL */
1426 0x0254, /* IO_ACX_EEPROM_ADDR */
1427 0x0258, /* IO_ACX_EEPROM_DATA */
1428 0x025c, /* IO_ACX_EEPROM_CFG */
1430 0x0268, /* IO_ACX_PHY_ADDR */
1431 0x026c, /* IO_ACX_PHY_DATA */
1432 0x0270, /* IO_ACX_PHY_CTL */
1434 0x0290, /* IO_ACX_GPIO_OE */
1436 0x0298, /* IO_ACX_GPIO_OUT */
1438 0x02a4, /* IO_ACX_CMD_MAILBOX_OFFS */
1439 0x02a8, /* IO_ACX_INFO_MAILBOX_OFFS */
1440 0x02ac, /* IO_ACX_EEPROM_INFORMATION */
1442 0x02d0, /* IO_ACX_EE_START */
1443 0x02d4, /* IO_ACX_SOR_CFG */
1444 0x02d8 /* IO_ACX_ECPU_CTRL */
1447 static const u16 IO_ACX111
[] = {
1448 0x0000, /* IO_ACX_SOFT_RESET */
1450 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1451 0x0018, /* IO_ACX_SLV_MEM_DATA */
1452 0x001c, /* IO_ACX_SLV_MEM_CTL */
1453 0x0020, /* IO_ACX_SLV_END_CTL */
1455 0x0034, /* IO_ACX_FEMR */
1457 0x00b4, /* IO_ACX_INT_TRIG */
1458 0x00d4, /* IO_ACX_IRQ_MASK */
1459 /* we do mean NON_DES (0xf0), not NON_DES_MASK which is at 0xe0: */
1460 0x00f0, /* IO_ACX_IRQ_STATUS_NON_DES */
1461 0x00e4, /* IO_ACX_IRQ_STATUS_CLEAR */
1462 0x00e8, /* IO_ACX_IRQ_ACK */
1463 0x00ec, /* IO_ACX_HINT_TRIG */
1465 0x01d0, /* IO_ACX_ENABLE */
1467 0x0338, /* IO_ACX_EEPROM_CTL */
1468 0x033c, /* IO_ACX_EEPROM_ADDR */
1469 0x0340, /* IO_ACX_EEPROM_DATA */
1470 0x0344, /* IO_ACX_EEPROM_CFG */
1472 0x0350, /* IO_ACX_PHY_ADDR */
1473 0x0354, /* IO_ACX_PHY_DATA */
1474 0x0358, /* IO_ACX_PHY_CTL */
1476 0x0374, /* IO_ACX_GPIO_OE */
1478 0x037c, /* IO_ACX_GPIO_OUT */
1480 0x0388, /* IO_ACX_CMD_MAILBOX_OFFS */
1481 0x038c, /* IO_ACX_INFO_MAILBOX_OFFS */
1482 0x0390, /* IO_ACX_EEPROM_INFORMATION */
1484 0x0100, /* IO_ACX_EE_START */
1485 0x0104, /* IO_ACX_SOR_CFG */
1486 0x0108, /* IO_ACX_ECPU_CTRL */
1489 static const struct ieee80211_ops acxpci_hw_ops
= {
1490 .tx
= acx_i_start_xmit
,
1491 .conf_tx
= acx_net_conf_tx
,
1492 .add_interface
= acx_add_interface
,
1493 .remove_interface
= acx_remove_interface
,
1494 .start
= acxpci_e_open
,
1495 .configure_filter
= acx_i_set_multicast_list
,
1496 .stop
= acxpci_e_close
,
1497 .config
= acx_net_config
,
1498 .config_interface
= acx_config_interface
,
1499 .set_key
= acx_net_set_key
,
1500 .get_stats
= acx_e_get_stats
,
1501 .get_tx_stats
= acx_net_get_tx_stats
,
1506 static int __devinit
1507 acxpci_e_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1509 acx111_ie_configoption_t co
;
1510 unsigned long mem_region1
= 0;
1511 unsigned long mem_region2
= 0;
1512 unsigned long mem_region1_size
;
1513 unsigned long mem_region2_size
;
1514 unsigned long phymem1
;
1515 unsigned long phymem2
;
1518 acx_device_t
*adev
= NULL
;
1519 const char *chip_name
;
1523 struct ieee80211_hw
*ieee
;
1527 ieee
= ieee80211_alloc_hw(sizeof(struct acx_device
), &acxpci_hw_ops
);
1529 acx_log(LOG_WARNING
, L_ANY
,
1530 "could not allocate ieee80211 structure %s\n",
1532 goto fail_alloc_netdev
;
1534 ieee
->flags
&= ~IEEE80211_HW_RX_INCLUDES_FCS
;
1535 /* TODO: mainline doesn't support the following flags yet */
1537 ~IEEE80211_HW_MONITOR_DURING_OPER &
1538 ~IEEE80211_HW_WEP_INCLUDE_IV;
1542 adev
= ieee2adev(ieee
);
1544 memset(adev
, 0, sizeof(*adev
));
1545 /** Set up our private interface **/
1546 spin_lock_init(&adev
->spinlock
); /* initial state: unlocked */
1547 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
1548 acx_log(LOG_INFO
, L_ANY
,
1549 "mutex_init(&adev->mutex); // adev = 0x%px\n", adev
);
1550 mutex_init(&adev
->mutex
);
1551 /* since nobody can see new netdev yet, we can as well
1552 ** just _presume_ that we're under sem (instead of actually taking it): */
1553 /* acx_sem_lock(adev); */
1556 adev
->bus_dev
= &pdev
->dev
;
1557 adev
->dev_type
= DEVTYPE_PCI
;
1559 /** Finished with private interface **/
1561 /** begin board specific inits **/
1562 pci_set_drvdata(pdev
, ieee
);
1564 /* Enable the PCI device */
1565 if (pci_enable_device(pdev
)) {
1566 acx_log(LOG_WARNING
, L_ANY
, "pci_enable_device() FAILED\n");
1568 goto fail_pci_enable_device
;
1571 /* enable busmastering (required for CardBus) */
1572 pci_set_master(pdev
);
1575 /* chiptype is u8 but id->driver_data is ulong
1576 ** Works for now (possible values are 1 and 2) */
1577 chip_type
= (u8
) id
->driver_data
;
1578 /* acx100 and acx111 have different PCI memory regions */
1579 if (chip_type
== CHIPTYPE_ACX100
) {
1580 chip_name
= "ACX100";
1581 mem_region1
= PCI_ACX100_REGION1
;
1582 mem_region1_size
= PCI_ACX100_REGION1_SIZE
;
1584 mem_region2
= PCI_ACX100_REGION2
;
1585 mem_region2_size
= PCI_ACX100_REGION2_SIZE
;
1586 } else if (chip_type
== CHIPTYPE_ACX111
) {
1587 chip_name
= "ACX111";
1588 mem_region1
= PCI_ACX111_REGION1
;
1589 mem_region1_size
= PCI_ACX111_REGION1_SIZE
;
1591 mem_region2
= PCI_ACX111_REGION2
;
1592 mem_region2_size
= PCI_ACX111_REGION2_SIZE
;
1594 acx_log(LOG_WARNING
, L_ANY
,
1595 "unknown chip type 0x%04X\n", chip_type
);
1596 goto fail_unknown_chiptype
;
1599 /* Figure out our resources
1601 * Request our PCI IO regions
1603 err
= pci_request_region(pdev
, mem_region1
, "acx_1");
1605 acx_log(LOG_WARNING
, L_ANY
, "pci_request_region (1/2) FAILED!"
1606 "No cardbus support in kernel?\n");
1607 goto fail_request_mem_region1
;
1610 phymem1
= pci_resource_start(pdev
, mem_region1
);
1612 err
= pci_request_region(pdev
, mem_region2
, "acx_2");
1614 acx_log(LOG_WARNING
, L_ANY
, "pci_request_region (2/2) FAILED!\n");
1615 goto fail_request_mem_region2
;
1618 phymem2
= pci_resource_start(pdev
, mem_region2
);
1621 * We got them? Map them!
1623 * We pass 0 as the third argument to pci_iomap(): it will map the full
1624 * region in this case, which is what we want.
1627 mem1
= pci_iomap(pdev
, mem_region1
, 0);
1629 acx_log(LOG_WARNING
, L_ANY
, "ioremap() FAILED\n");
1633 mem2
= pci_iomap(pdev
, mem_region2
, 0);
1635 acx_log(LOG_WARNING
, L_ANY
, "ioremap() #2 FAILED\n");
1639 acx_log(LOG_INFO
, L_ANY
, "found %s-based wireless network card at %s, "
1640 "irq:%d, phymem1:0x%lX, phymem2:0x%lX, mem1:0x%p, "
1641 "mem1_size:%ld, mem2:0x%p, mem2_size:%ld\n",
1642 chip_name
, pci_name(pdev
), pdev
->irq
, phymem1
, phymem2
,
1643 mem1
, mem_region1_size
, mem2
, mem_region2_size
);
1644 //log(L_ANY, "initial debug setting is 0x%04X\n", acx_debug);
1645 adev
->chip_type
= chip_type
;
1646 adev
->chip_name
= chip_name
;
1647 adev
->io
= (CHIPTYPE_ACX100
== chip_type
) ? IO_ACX100
: IO_ACX111
;
1648 adev
->membase
= phymem1
;
1649 adev
->iobase
= mem1
;
1650 adev
->membase2
= phymem2
;
1651 adev
->iobase2
= mem2
;
1652 adev
->irq
= pdev
->irq
;
1655 if (0 == pdev
->irq
) {
1656 acx_log(LOG_WARNING
, L_ANY
, "can't use IRQ 0\n");
1659 SET_IEEE80211_DEV(ieee
, &pdev
->dev
);
1661 /* request shared IRQ handler */
1663 (adev
->irq
, acxpci_i_interrupt
, IRQF_SHARED
, KBUILD_MODNAME
, adev
)) {
1664 acx_log(LOG_WARNING
, L_ANY
, "%s: request_irq FAILED\n",
1665 wiphy_name(adev
->ieee
->wiphy
));
1669 acx_log(LOG_DEBUG
, L_IRQ
| L_REALLYVERBOSE
,
1670 "request_irq %d successful\n", adev
->irq
);
1672 /* to find crashes due to weird driver access
1673 * to unconfigured interface (ifup) */
1674 adev
->mgmt_timer
.function
= (void (*)(unsigned long))0x0000dead;
1677 #ifdef NONESSENTIAL_FEATURES
1678 acx_show_card_eeprom_id(adev
);
1679 #endif /* NONESSENTIAL_FEATURES */
1682 /* ok, pci setup is finished, now start initializing the card */
1684 /* NB: read_reg() reads may return bogus data before reset_dev(),
1685 * since the firmware which directly controls large parts of the I/O
1686 * registers isn't initialized yet.
1687 * acx100 seems to be more affected than acx111 */
1688 if (OK
!= acxpci_s_reset_dev(adev
))
1691 if (IS_ACX100(adev
)) {
1692 /* ACX100: configopt struct in cmd mailbox - directly after reset */
1693 memcpy_fromio(&co
, adev
->cmd_area
, sizeof(co
));
1696 if (OK
!= acx_s_init_mac(adev
))
1699 if (IS_ACX111(adev
)) {
1700 /* ACX111: configopt struct needs to be queried after full init */
1701 acx_s_interrogate(adev
, &co
, ACX111_IE_CONFIG_OPTIONS
);
1703 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
1704 if (OK
!= acxpci_read_eeprom_byte(adev
, 0x05, &adev
->eeprom_version
))
1705 goto fail_read_eeprom_version
;
1707 acx_s_parse_configoption(adev
, &co
);
1708 acx_s_set_defaults(adev
);
1709 acx_s_get_firmware_version(adev
); /* needs to be after acx_s_init_mac() */
1710 acx_display_hardware_details(adev
);
1712 /* Register the card, AFTER everything else has been set up,
1713 * since otherwise an ioctl could step on our feet due to
1714 * firmware operations happening in parallel or uninitialized data */
1717 acx_proc_register_entries(ieee
);
1719 /* Now we have our device, so make sure the kernel doesn't try
1720 * to send packets even though we're not associated to a network yet */
1722 /* after register_netdev() userspace may start working with dev
1723 * (in particular, on other CPUs), we only need to up the sem */
1724 /* acx_sem_unlock(adev); */
1726 acx_log(LOG_INFO
, L_ANY
, "driver version " ACX_RELEASE
1727 ": net device %s, driver compiled "
1728 "against wireless extensions %d and Linux %s\n",
1729 wiphy_name(adev
->ieee
->wiphy
), WIRELESS_EXT
, UTS_RELEASE
);
1731 MAC_COPY(adev
->ieee
->wiphy
->perm_addr
, adev
->dev_addr
);
1733 acx_log(LOG_INFO
, L_IRQ
| L_INIT
, "using IRQ %d\n", pdev
->irq
);
1735 /** done with board specific setup **/
1737 /* need to be able to restore PCI state after a suspend */
1739 pci_save_state(pdev
);
1742 err
= acx_setup_modes(adev
);
1744 acx_log(LOG_WARNING
, L_ANY
, "can't register hwmode\n");
1745 goto fail_register_netdev
;
1748 acx_init_task_scheduler(adev
);
1749 err
= ieee80211_register_hw(ieee
);
1751 acx_log(LOG_WARNING
, L_ANY
,
1752 "ieee80211_register_hw() FAILED: %d\n", err
);
1753 goto fail_register_netdev
;
1756 great_inquisitor(adev
);
1762 /* error paths: undo everything in reverse order... */
1765 acxpci_s_delete_dma_regions(adev
);
1766 pci_set_drvdata(pdev
, NULL
);
1769 fail_read_eeprom_version
:
1774 pci_iounmap(pdev
, mem2
);
1777 pci_iounmap(pdev
, mem1
);
1780 pci_release_region(pdev
, mem_region2
);
1782 fail_request_mem_region2
:
1783 pci_release_region(pdev
, mem_region1
);
1785 fail_request_mem_region1
:
1786 fail_unknown_chiptype
:
1787 pci_disable_device(pdev
);
1789 fail_pci_enable_device
:
1791 pci_set_power_state(pdev
, PCI_D3hot
);
1794 fail_register_netdev
:
1795 ieee80211_free_hw(ieee
);
1802 /***********************************************************************
1805 ** Shut device down (if not hot unplugged)
1806 ** and deallocate PCI resources for the acx chip.
1808 ** pdev - ptr to PCI device structure containing info about pci configuration
1810 static void __devexit
acxpci_e_remove(struct pci_dev
*pdev
)
1812 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*)pci_get_drvdata(pdev
);
1813 acx_device_t
*adev
= ieee2adev(hw
);
1814 unsigned long mem_region1
, mem_region2
;
1815 unsigned long flags
;
1819 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
1820 "%s: card is unused. Skipping any release code\n",
1825 /* If device wasn't hot unplugged... */
1826 if (adev_present(adev
)) {
1828 /* disable both Tx and Rx to shut radio down properly */
1829 if (adev
->initialized
) {
1830 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_TX
, NULL
, 0);
1831 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_RX
, NULL
, 0);
1832 adev
->initialized
= 0;
1835 /* put the eCPU to sleep to save power
1836 * Halting is not possible currently,
1837 * since not supported by all firmware versions */
1838 acx_s_issue_cmd(adev
, ACX100_CMD_SLEEP
, NULL
, 0);
1840 acx_lock(adev
, flags
);
1841 /* disable power LED to save power :-) */
1842 acx_log(LOG_INFO
, L_INIT
,
1843 "switching off power LED to save power\n");
1844 acxpci_l_power_led(adev
, 0);
1846 if (IS_ACX111(adev
)) {
1847 /* FIXME: does this actually keep halting the eCPU?
1848 * I don't think so...
1850 acxpci_l_reset_mac(adev
);
1854 temp
= read_reg16(adev
, IO_ACX_ECPU_CTRL
) | 0x1;
1855 write_reg16(adev
, IO_ACX_ECPU_CTRL
, temp
);
1858 acx_unlock(adev
, flags
);
1862 /* unregister the device to not let the kernel
1863 * (e.g. ioctls) access a half-deconfigured device
1864 * NB: this will cause acxpci_e_close() to be called,
1865 * thus we shouldn't call it under sem!
1866 * Well, netdev did, but ieee80211 stack does not, so we
1867 * have to do so manually...
1870 acx_log(LOG_INFO
, L_INIT
,
1871 "removing device %s\n", wiphy_name(adev
->ieee
->wiphy
));
1872 ieee80211_unregister_hw(adev
->ieee
);
1874 /* unregister_netdev ensures that no references to us left.
1875 * For paranoid reasons we continue to follow the rules */
1878 if (adev
->dev_state_mask
& ACX_STATE_IFACE_UP
) {
1880 CLEAR_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
1883 acx_proc_unregister_entries(adev
->ieee
);
1885 if (IS_ACX100(adev
)) {
1886 mem_region1
= PCI_ACX100_REGION1
;
1887 mem_region2
= PCI_ACX100_REGION2
;
1889 mem_region1
= PCI_ACX111_REGION1
;
1890 mem_region2
= PCI_ACX111_REGION2
;
1893 /* finally, clean up PCI bus state */
1894 acxpci_s_delete_dma_regions(adev
);
1896 iounmap(adev
->iobase
);
1898 iounmap(adev
->iobase2
);
1899 release_mem_region(pci_resource_start(pdev
, mem_region1
),
1900 pci_resource_len(pdev
, mem_region1
));
1901 release_mem_region(pci_resource_start(pdev
, mem_region2
),
1902 pci_resource_len(pdev
, mem_region2
));
1903 pci_disable_device(pdev
);
1905 /* remove dev registration */
1906 pci_set_drvdata(pdev
, NULL
);
1908 acx_sem_unlock(adev
);
1910 /* Free netdev (quite late,
1911 * since otherwise we might get caught off-guard
1912 * by a netdev timeout handler execution
1913 * expecting to see a working dev...) */
1914 ieee80211_free_hw(adev
->ieee
);
1916 /* put device into ACPI D3 mode (shutdown) */
1918 pci_set_power_state(pdev
, PCI_D3hot
);
1925 /***********************************************************************
1926 ** TODO: PM code needs to be fixed / debugged / tested.
1930 acxpci_e_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1932 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
1936 acx_log(LOG_WARNING
, L_ANY
, "suspend handler is experimental!\n");
1937 acx_log(LOG_INFO
, L_ANY
, "suspend: dev %p\n", hw
);
1939 /* if (!netif_running(ndev))
1942 adev
= ieee2adev(hw
);
1943 acx_log(LOG_INFO
, L_ANY
, "suspend: adev %p\n", adev
);
1947 ieee80211_unregister_hw(hw
); /* this one cannot sleep */
1949 /* down() does not set it to 0xffff, but here we really want that */
1950 write_reg16(adev
, IO_ACX_IRQ_MASK
, 0xffff);
1951 write_reg16(adev
, IO_ACX_FEMR
, 0x0);
1952 acxpci_s_delete_dma_regions(adev
);
1953 pci_save_state(pdev
);
1954 pci_set_power_state(pdev
, PCI_D3hot
);
1956 acx_sem_unlock(adev
);
1962 static int acxpci_e_resume(struct pci_dev
*pdev
)
1964 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
1969 acx_log(LOG_WARNING
, L_ANY
, "resume handler is experimental!\n");
1970 acx_log(LOG_INFO
, L_ANY
, "resume: got dev %p\n", hw
);
1973 adev
= ieee2adev(hw
);
1974 acx_log(LOG_INFO
, L_ANY
, "resume: got adev %p\n", adev
);
1978 pci_set_power_state(pdev
, PCI_D0
);
1979 acx_log(LOG_INFO
, L_ANY
, "resume: power state PCI_D0 set\n");
1980 pci_restore_state(pdev
);
1981 acx_log(LOG_INFO
, L_ANY
, "resume: PCI state restored\n");
1983 if (OK
!= acxpci_s_reset_dev(adev
))
1985 acx_log(LOG_INFO
, L_ANY
, "resume: device reset done\n");
1986 if (OK
!= acx_s_init_mac(adev
))
1988 acx_log(LOG_INFO
, L_ANY
, "resume: init MAC done\n");
1991 acx_log(LOG_INFO
, L_ANY
, "resume: acx up done\n");
1993 /* now even reload all card parameters as they were before suspend,
1994 * and possibly be back in the network again already :-) */
1995 if (ACX_STATE_IFACE_UP
& adev
->dev_state_mask
) {
1996 adev
->set_mask
= GETSET_ALL
;
1997 acx_s_update_card_settings(adev
);
1998 acx_log(LOG_INFO
, L_ANY
, "resume: settings updated\n");
2000 ieee80211_register_hw(hw
);
2001 acx_log(LOG_INFO
, L_ANY
, "resume: device attached\n");
2004 acx_sem_unlock(adev
);
2005 /* we need to return OK here anyway, right? */
2009 #endif /* CONFIG_PM */
2010 #endif /* CONFIG_PCI */
2012 /***********************************************************************
2015 ** This function is called by acxpci_e_open (when ifconfig sets the device as up)
2018 ** - Enables on-card interrupt requests
2019 ** - calls acx_s_start
2022 static void enable_acx_irq(acx_device_t
* adev
)
2025 write_reg16(adev
, IO_ACX_IRQ_MASK
, adev
->irq_mask
);
2026 write_reg16(adev
, IO_ACX_FEMR
, 0x8000);
2027 adev
->irqs_active
= 1;
2031 static void acxpci_s_up(struct ieee80211_hw
*hw
)
2033 acx_device_t
*adev
= ieee2adev(hw
);
2034 unsigned long flags
;
2038 acx_lock(adev
, flags
);
2039 enable_acx_irq(adev
);
2040 acx_unlock(adev
, flags
);
2042 /* acx fw < 1.9.3.e has a hardware timer, and older drivers
2043 ** used to use it. But we don't do that anymore, our OS
2044 ** has reliable software timers */
2045 init_timer(&adev
->mgmt_timer
);
2046 adev
->mgmt_timer
.function
= acx_i_timer
;
2047 adev
->mgmt_timer
.data
= (unsigned long)adev
;
2049 /* Need to set ACX_STATE_IFACE_UP first, or else
2050 ** timer won't be started by acx_set_status() */
2051 SET_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
2059 /***********************************************************************
2062 ** NB: device may be already hot unplugged if called from acxpci_e_remove()
2064 ** Disables on-card interrupt request, stops softirq and timer, stops queue,
2065 ** sets status == STOPPED
2068 static void disable_acx_irq(acx_device_t
* adev
)
2072 /* I guess mask is not 0xffff because acx100 won't signal
2073 ** cmd completion then (needed for ifup).
2074 ** I can't ifconfig up after ifconfig down'ing on my acx100 */
2075 write_reg16(adev
, IO_ACX_IRQ_MASK
, adev
->irq_mask_off
);
2076 write_reg16(adev
, IO_ACX_FEMR
, 0x0);
2077 adev
->irqs_active
= 0;
2082 static void acxpci_s_down(struct ieee80211_hw
*hw
)
2084 acx_device_t
*adev
= ieee2adev(hw
);
2088 /* Disable IRQs first, so that IRQs cannot race with us */
2089 /* then wait until interrupts have finished executing on other CPUs */
2090 disable_acx_irq(adev
); /* NO sem-locking here? */
2091 synchronize_irq(adev
->irq
);
2093 /* we really don't want to have an asynchronous tasklet disturb us
2094 ** after something vital for its job has been shut down, so
2095 ** end all remaining work now.
2097 ** NB: carrier_off (done by set_status below) would lead to
2098 ** not yet fully understood deadlock in flush_scheduled_work().
2099 ** That's why we do FLUSH first.
2101 ** NB2: we have a bad locking bug here: flush_scheduled_work()
2102 ** waits for acx_e_after_interrupt_task to complete if it is running
2103 ** on another CPU, but acx_e_after_interrupt_task
2104 ** will sleep on sem forever, because it is taken by us!
2105 ** Work around that by temporary sem unlock.
2106 ** This will fail miserably if we'll be hit by concurrent
2107 ** iwconfig or something in between. TODO! */
2108 acx_sem_unlock(adev
);
2109 flush_scheduled_work();
2112 /* This is possible:
2113 ** flush_scheduled_work -> acx_e_after_interrupt_task ->
2114 ** -> set_status(ASSOCIATED) -> wake_queue()
2115 ** That's why we stop queue _after_ flush_scheduled_work
2116 ** lock/unlock is just paranoia, maybe not needed */
2118 /* kernel/timer.c says it's illegal to del_timer_sync()
2119 ** a timer which restarts itself. We guarantee this cannot
2120 ** ever happen because acx_i_timer() never does this if
2121 ** status is ACX_STATUS_0_STOPPED */
2122 del_timer_sync(&adev
->mgmt_timer
);
2127 #ifdef CONFIG_NET_POLL_CONTROLLER
2128 void acxpci_net_poll_controller(struct net_device *net_dev)
2130 acx_device_t *adev = ndev2adev(net_dev);
2131 unsigned long flags;
2133 local_irq_save(flags);
2134 acxpci_i_interrupt(adev->irq, adev);
2135 local_irq_restore(flags);
2137 #endif*/ /* CONFIG_NET_POLL_CONTROLLER */
2139 /***********************************************************************
2142 ** Called as a result of SIOCSIFFLAGS ioctl changing the flags bit IFF_UP
2143 ** from clear to set. In other words: ifconfig up.
2147 ** >0 f/w reported error
2148 ** <0 driver reported error
2150 static int acxpci_e_open(struct ieee80211_hw
*hw
)
2152 acx_device_t
*adev
= ieee2adev(hw
);
2159 adev
->initialized
= 0;
2161 /* TODO: pci_set_power_state(pdev, PCI_D0); ? */
2166 /* We don't currently have to do anything else.
2167 * The setup of the MAC should be subsequently completed via
2168 * the mlme commands.
2169 * Higher layers know we're ready from dev->start==1 and
2170 * dev->tbusy==0. Our rx path knows to pass up received/
2171 * frames because of dev->flags&IFF_UP is true.
2173 ieee80211_start_queues(adev
->ieee
);
2175 adev
->initialized
= 1;
2176 acx_sem_unlock(adev
);
2183 /***********************************************************************
2186 ** This function stops the network functionality of the interface (invoked
2187 ** when the user calls ifconfig <wlan> down). The tx queue is halted and
2188 ** the device is marked as down.
2190 ** Called as a result of SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
2191 ** from set to clear. I.e. called by "ifconfig DEV down"
2195 ** >0 f/w reported error
2196 ** <0 driver reported error
2198 static void acxpci_e_close(struct ieee80211_hw
*hw
)
2200 acx_device_t
*adev
= ieee2adev(hw
);
2207 CLEAR_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
2208 if (adev
->initialized
) {
2213 acx_free_modes(adev
);
2214 /* disable all IRQs, release shared IRQ handler */
2215 write_reg16(adev
, IO_ACX_IRQ_MASK
, 0xffff);
2216 write_reg16(adev
, IO_ACX_FEMR
, 0x0);
2217 free_irq(adev
->irq
, adev
);
2219 /* TODO: pci_set_power_state(pdev, PCI_D3hot); ? */
2221 /* We currently don't have to do anything else.
2222 * Higher layers know we're not ready from dev->start==0 and
2223 * dev->tbusy==1. Our rx path knows to not pass up received
2224 * frames because of dev->flags&IFF_UP is false.
2226 acx_sem_unlock(adev
);
2228 acx_log(LOG_INFO
, L_INIT
, "closed device\n");
2235 /***************************************************************
2236 ** acxpci_l_process_rxdesc
2238 ** Called directly and only from the IRQ handler
2242 static inline void log_rxbuffer(const acx_device_t
* adev
)
2246 static void log_rxbuffer(const acx_device_t
* adev
)
2248 register const struct rxhostdesc
*rxhostdesc
;
2251 /* no FN_ENTER here, we don't want that */
2253 rxhostdesc
= adev
->rxhostdesc_start
;
2254 if (unlikely(!rxhostdesc
))
2256 for (i
= 0; i
< RX_CNT
; i
++) {
2257 if ((rxhostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
2258 && (rxhostdesc
->Status
& cpu_to_le32(DESC_STATUS_FULL
)))
2259 acx_log(LOG_WARNING
, L_ANY
, "rx: buf %d full\n", i
);
2265 static void acxpci_l_process_rxdesc(acx_device_t
* adev
)
2267 register rxhostdesc_t
*hostdesc
;
2268 unsigned count
, tail
;
2272 if (unlikely(acx_debug
& L_BUFR
))
2275 /* First, have a loop to determine the first descriptor that's
2276 * full, just in case there's a mismatch between our current
2277 * rx_tail and the full descriptor we're supposed to handle. */
2278 tail
= adev
->rx_tail
;
2281 hostdesc
= &adev
->rxhostdesc_start
[tail
];
2282 /* advance tail regardless of outcome of the below test */
2283 tail
= (tail
+ 1) % RX_CNT
;
2285 if ((hostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
2286 && (hostdesc
->Status
& cpu_to_le32(DESC_STATUS_FULL
)))
2287 break; /* found it! */
2289 if (unlikely(!--count
)) /* hmm, no luck: all descs empty, bail out */
2293 /* now process descriptors, starting with the first we figured out */
2295 acx_log(LOG_DEBUG
, L_BUFR
,
2296 "rx: tail=%u Ctl_16=%04X Status=%08X\n",
2297 tail
, hostdesc
->Ctl_16
, hostdesc
->Status
);
2299 acx_l_process_rxbuf(adev
, hostdesc
->data
);
2300 hostdesc
->Status
= 0;
2301 /* flush all writes before adapter sees CTL_HOSTOWN change */
2303 /* Host no longer owns this, needs to be LAST */
2304 CLEAR_BIT(hostdesc
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
2306 /* ok, descriptor is handled, now check the next descriptor */
2307 hostdesc
= &adev
->rxhostdesc_start
[tail
];
2309 /* if next descriptor is empty, then bail out */
2310 if (!(hostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
2311 || !(hostdesc
->Status
& cpu_to_le32(DESC_STATUS_FULL
)))
2314 tail
= (tail
+ 1) % RX_CNT
;
2317 adev
->rx_tail
= tail
;
2323 /***********************************************************************
2324 ** acxpci_i_interrupt
2326 ** IRQ handler (atomic context, must not sleep, blah, blah)
2329 /* scan is complete. all frames now on the receive queue are valid */
2330 #define INFO_SCAN_COMPLETE 0x0001
2331 #define INFO_WEP_KEY_NOT_FOUND 0x0002
2332 /* hw has been reset as the result of a watchdog timer timeout */
2333 #define INFO_WATCH_DOG_RESET 0x0003
2334 /* failed to send out NULL frame from PS mode notification to AP */
2335 /* recommended action: try entering 802.11 PS mode again */
2336 #define INFO_PS_FAIL 0x0004
2337 /* encryption/decryption process on a packet failed */
2338 #define INFO_IV_ICV_FAILURE 0x0005
2340 /* Info mailbox format:
2343 more bytes may follow
2344 rumors say about status:
2345 0x0000 info available (set by hw)
2346 0x0001 information received (must be set by host)
2347 0x1000 info available, mailbox overflowed (messages lost) (set by hw)
2348 but in practice we've seen:
2349 0x9000 when we did not set status to 0x0001 on prev message
2350 0x1001 when we did set it
2351 0x0000 was never seen
2352 conclusion: this is really a bitfield:
2353 0x1000 is 'info available' bit
2354 'mailbox overflowed' bit is 0x8000, not 0x1000
2355 value of 0x0000 probably means that there are no messages at all
2356 P.S. I dunno how in hell hw is supposed to notice that messages are lost -
2357 it does NOT clear bit 0x0001, and this bit will probably stay forever set
2358 after we set it once. Let's hope this will be fixed in firmware someday
2361 static void handle_info_irq(acx_device_t
* adev
)
2364 static const char *const info_type_msg
[] = {
2367 "WEP key not found",
2368 "internal watchdog reset was done",
2369 "failed to send powersave (NULL frame) notification to AP",
2370 "encrypt/decrypt on a packet has failed",
2371 "TKIP tx keys disabled",
2372 "TKIP rx keys disabled",
2373 "TKIP rx: key ID not found",
2381 "TKIP IV value exceeds thresh"
2384 u32 info_type
, info_status
;
2386 info_type
= acx_readl(adev
->info_area
);
2387 info_status
= (info_type
>> 16);
2388 info_type
= (u16
) info_type
;
2390 /* inform fw that we have read this info message */
2391 acx_writel(info_type
| 0x00010000, adev
->info_area
);
2392 write_reg16(adev
, IO_ACX_INT_TRIG
, INT_TRIG_INFOACK
);
2395 acx_log(LOG_DEBUG
, L_CTL
,
2396 "info_type:%04X info_status:%04X\n", info_type
, info_status
);
2398 acx_log(LOG_DEBUG
, L_IRQ
, "got Info IRQ: status %04X type %04X: %s\n",
2399 info_status
, info_type
,
2400 info_type_msg
[(info_type
>= ARRAY_SIZE(info_type_msg
)) ?
2406 static void log_unusual_irq(u16 irqtype
)
2409 if (!printk_ratelimit())
2414 if (irqtype
& ACX_IRQ_RX_DATA
) {
2417 /* ACX_IRQ_TX_COMPLETE */
2418 if (irqtype
& ACX_IRQ_TX_XFER
) {
2421 /* ACX_IRQ_RX_COMPLETE */
2422 if (irqtype
& ACX_IRQ_DTIM
) {
2425 if (irqtype
& ACX_IRQ_BEACON
) {
2428 if (irqtype
& ACX_IRQ_TIMER
) {
2431 if (irqtype
& ACX_IRQ_KEY_NOT_FOUND
) {
2432 printk(" Key_Not_Found");
2434 if (irqtype
& ACX_IRQ_IV_ICV_FAILURE
) {
2435 printk(" IV_ICV_Failure (crypto)");
2437 /* ACX_IRQ_CMD_COMPLETE */
2439 if (irqtype
& ACX_IRQ_OVERFLOW
) {
2440 printk(" Overflow");
2442 if (irqtype
& ACX_IRQ_PROCESS_ERROR
) {
2443 printk(" Process_Error");
2445 /* ACX_IRQ_SCAN_COMPLETE */
2446 if (irqtype
& ACX_IRQ_FCS_THRESHOLD
) {
2447 printk(" FCS_Threshold");
2449 if (irqtype
& ACX_IRQ_UNKNOWN
) {
2452 printk(" IRQ(s)\n");
2455 /* FIXME: update_link_quality_led was a stub - let's comment it and avoid
2456 * compiler warnings */
2458 static void update_link_quality_led(acx_device_t * adev)
2463 acx_signal_determine_quality(adev->wstats.qual.level,
2464 adev->wstats.qual.noise);
2465 if (qual > adev->brange_max_quality)
2466 qual = adev->brange_max_quality;
2468 if (time_after(jiffies, adev->brange_time_last_state_change +
2470 HZ / 2 * (unsigned long)qual /
2471 adev->brange_max_quality))) {
2472 acxpci_l_power_led(adev, (adev->brange_last_state == 0));
2473 adev->brange_last_state ^= 1; // toggle
2474 adev->brange_time_last_state_change = jiffies;
2479 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* a la orinoco.c */
2481 /* Interrupt handler bottom-half */
2482 void acx_interrupt_tasklet(struct work_struct
*work
)
2485 #ifdef CONFIG_ACX_MAC80211_DEBUG
2486 u32 _handled
= 0x00000000;
2487 # define acxirq_handled(irq) do { _handled |= (irq); } while (0)
2489 # define acxirq_handled(irq) do { /* nothing */ } while (0)
2490 #endif /* CONFIG_ACX_MAC80211_DEBUG */
2491 acx_device_t
*adev
= container_of(work
,struct acx_device
, after_interrupt_task
);
2492 // unsigned int irqcount = MAX_IRQLOOPS_PER_JIFFY;
2495 #define IRQ_ITERATE 0
2497 unsigned int irqcount
= MAX_IRQLOOPS_PER_JIFFY
;
2503 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2507 irqtype
= adev
->irq_reason
;
2508 adev
->irq_reason
= 0;
2511 if (jiffies
!= adev
->irq_last_jiffies
) {
2512 adev
->irq_loops_this_jiffy
= 0;
2513 adev
->irq_last_jiffies
= jiffies
;
2516 /* safety condition; we'll normally abort loop below
2517 * in case no IRQ type occurred */
2518 while (likely(--irqcount
)) {
2520 /* ACK all IRQs ASAP */
2522 /* Handle most important IRQ types first */
2523 if (irqtype
& ACX_IRQ_RX_COMPLETE
) {
2524 acx_log(LOG_DEBUG
, L_IRQ
, "got Rx_Complete IRQ\n");
2525 acxpci_l_process_rxdesc(adev
);
2527 if (irqtype
& ACX_IRQ_TX_COMPLETE
) {
2528 acx_log(LOG_DEBUG
, L_IRQ
, "got Tx_Complete IRQ\n");
2529 /* don't clean up on each Tx complete, wait a bit
2530 * unless we're going towards full, in which case
2531 * we do it immediately, too (otherwise we might lockup
2532 * with a full Tx buffer if we go into
2533 * acxpci_l_clean_txdesc() at a time when we won't wakeup
2534 * the net queue in there for some reason...) */
2535 // if (adev->tx_free <= TX_START_CLEAN) {
2536 acxpci_l_clean_txdesc(adev
);
2540 /* Less frequent ones */
2542 | ACX_IRQ_CMD_COMPLETE
2543 | ACX_IRQ_INFO
| ACX_IRQ_SCAN_COMPLETE
)) {
2544 if (irqtype
& ACX_IRQ_INFO
) {
2545 handle_info_irq(adev
);
2547 if (irqtype
& ACX_IRQ_SCAN_COMPLETE
) {
2548 acx_log(LOG_DEBUG
, L_IRQ
,
2549 "got Scan_Complete IRQ\n");
2550 /* need to do that in process context */
2551 /* remember that fw is not scanning anymore */
2552 SET_BIT(adev
->irq_status
,
2553 ACX_IRQ_SCAN_COMPLETE
);
2557 /* These we just log, but either they happen rarely
2558 * or we keep them masked out */
2559 if (irqtype
& (0 | ACX_IRQ_RX_DATA
2560 /* | ACX_IRQ_TX_COMPLETE */
2562 /* | ACX_IRQ_RX_COMPLETE */
2566 | ACX_IRQ_KEY_NOT_FOUND
2567 | ACX_IRQ_IV_ICV_FAILURE
2568 /* | ACX_IRQ_CMD_COMPLETE */
2569 /* | ACX_IRQ_INFO */
2571 | ACX_IRQ_PROCESS_ERROR
2572 /* | ACX_IRQ_SCAN_COMPLETE */
2573 | ACX_IRQ_FCS_THRESHOLD
2574 | ACX_IRQ_UNKNOWN
)) {
2575 log_unusual_irq(irqtype
);
2578 unmasked
= read_reg16(adev
, IO_ACX_IRQ_STATUS_CLEAR
);
2579 irqtype
= unmasked
& ~adev
->irq_mask
;
2580 /* Bail out if no new IRQ bits or if all are masked out */
2585 (++adev
->irq_loops_this_jiffy
> MAX_IRQLOOPS_PER_JIFFY
)) {
2586 acx_log(LOG_WARNING
, L_ANY
,
2587 "too many interrupts per jiffy!\n");
2588 /* Looks like card floods us with IRQs! Try to stop that */
2589 write_reg16(adev
, IO_ACX_IRQ_MASK
, 0xffff);
2590 /* This will short-circuit all future attempts to handle IRQ.
2591 * We cant do much more... */
2597 /* Routine to perform blink with range
2598 * FIXME: update_link_quality_led is a stub - add proper code and enable this again:
2599 if (unlikely(adev->led_power == 2))
2600 update_link_quality_led(adev);
2603 /* write_flush(adev); - not needed, last op was read anyway */
2604 acx_sem_unlock(adev
);
2607 if (adev
->after_interrupt_jobs
)
2608 acx_e_after_interrupt_task(&adev
->after_interrupt_task
);
2616 static irqreturn_t
acxpci_i_interrupt(int irq
, void *dev_id
)
2618 acx_device_t
*adev
= dev_id
;
2619 unsigned long flags
;
2620 register u16 irqtype
;
2628 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2631 acx_lock(adev
, flags
);
2633 unmasked
= read_reg16(adev
, IO_ACX_IRQ_STATUS_CLEAR
);
2634 if (unlikely(0xffff == unmasked
)) {
2635 /* 0xffff value hints at missing hardware,
2636 * so don't do anything.
2637 * Not very clean, but other drivers do the same... */
2638 acx_log(LOG_WARNING
, L_IRQ
,
2639 "IRQ type:FFFF - device removed? IRQ_NONE\n");
2643 /* We will check only "interesting" IRQ types */
2644 irqtype
= unmasked
& ~adev
->irq_mask
;
2646 /* We are on a shared IRQ line and it wasn't our IRQ */
2647 acx_log(LOG_DEBUG
, L_IRQ
,
2648 "IRQ type:%04X, mask:%04X - all are masked, IRQ_NONE\n",
2649 unmasked
, adev
->irq_mask
);
2653 /* Go ahead and ACK our interrupt */
2654 write_reg16(adev
, IO_ACX_IRQ_ACK
, 0xffff);
2655 if (irqtype
& ACX_IRQ_CMD_COMPLETE
) {
2656 acx_log(LOG_DEBUG
, L_IRQ
, "got Command_Complete IRQ\n");
2657 /* save the state for the running issue_cmd() */
2658 SET_BIT(adev
->irq_status
, ACX_IRQ_CMD_COMPLETE
);
2661 /* Only accept IRQs, if we are initialized properly.
2662 * This avoids an RX race while initializing.
2663 * We should probably not enable IRQs before we are initialized
2664 * completely, but some careful work is needed to fix this. I think it
2665 * is best to stay with this cheap workaround for now... .
2667 if (likely(adev
->initialized
)) {
2668 /* disable all IRQs. They are enabled again in the bottom half. */
2669 /* save the reason code and call our bottom half. */
2670 adev
->irq_reason
= irqtype
;
2672 if ((irqtype
& ACX_IRQ_RX_COMPLETE
) || (irqtype
& ACX_IRQ_TX_COMPLETE
))
2673 acx_schedule_task(adev
, 0);
2676 acx_unlock(adev
, flags
);
2680 acx_unlock(adev
, flags
);
2687 /***********************************************************************
2688 ** acxpci_l_power_led
2690 void acxpci_l_power_led(acx_device_t
* adev
, int enable
)
2692 u16 gpio_pled
= IS_ACX111(adev
) ? 0x0040 : 0x0800;
2694 /* A hack. Not moving message rate limiting to adev->xxx
2695 * (it's only a debug message after all) */
2696 static int rate_limit
= 0;
2698 if (rate_limit
++ < 3)
2699 acx_log(LOG_INFO
, L_IOCTL
,
2700 "Please report in case toggling the power LED "
2701 "doesn't work for your card!\n");
2703 write_reg16(adev
, IO_ACX_GPIO_OUT
,
2704 read_reg16(adev
, IO_ACX_GPIO_OUT
) & ~gpio_pled
);
2706 write_reg16(adev
, IO_ACX_GPIO_OUT
,
2707 read_reg16(adev
, IO_ACX_GPIO_OUT
) | gpio_pled
);
2711 /***********************************************************************
2715 /***********************************************************************
2719 acx111pci_ioctl_info(struct net_device
*ndev
,
2720 struct iw_request_info
*info
,
2721 struct iw_param
*vwrq
, char *extra
)
2724 acx_device_t
*adev
= ndev2adev(ndev
);
2727 rxhostdesc_t
*rxhostdesc
;
2728 txhostdesc_t
*txhostdesc
;
2729 struct acx111_ie_memoryconfig memconf
;
2730 struct acx111_ie_queueconfig queueconf
;
2731 unsigned long flags
;
2736 char ratefallback
[0x5];
2738 if (!(acx_debug
& (L_IOCTL
| L_DEBUG
)))
2740 /* using printk() since we checked debug flag already */
2744 if (!IS_ACX111(adev
)) {
2745 printk("acx111-specific function called "
2746 "with non-acx111 chip, aborting\n");
2750 /* get Acx111 Memory Configuration */
2751 memset(&memconf
, 0, sizeof(memconf
));
2752 /* BTW, fails with 12 (Write only) error code.
2753 ** Retained for easy testing of issue_cmd error handling :) */
2754 acx_s_interrogate(adev
, &memconf
, ACX1xx_IE_QUEUE_CONFIG
);
2756 /* get Acx111 Queue Configuration */
2757 memset(&queueconf
, 0, sizeof(queueconf
));
2758 acx_s_interrogate(adev
, &queueconf
, ACX1xx_IE_MEMORY_CONFIG_OPTIONS
);
2760 /* get Acx111 Memory Map */
2761 memset(memmap
, 0, sizeof(memmap
));
2762 acx_s_interrogate(adev
, &memmap
, ACX1xx_IE_MEMORY_MAP
);
2764 /* get Acx111 Rx Config */
2765 memset(rxconfig
, 0, sizeof(rxconfig
));
2766 acx_s_interrogate(adev
, &rxconfig
, ACX1xx_IE_RXCONFIG
);
2768 /* get Acx111 fcs error count */
2769 memset(fcserror
, 0, sizeof(fcserror
));
2770 acx_s_interrogate(adev
, &fcserror
, ACX1xx_IE_FCS_ERROR_COUNT
);
2772 /* get Acx111 rate fallback */
2773 memset(ratefallback
, 0, sizeof(ratefallback
));
2774 acx_s_interrogate(adev
, &ratefallback
, ACX1xx_IE_RATE_FALLBACK
);
2776 /* force occurrence of a beacon interrupt */
2777 /* TODO: comment why is this necessary */
2778 write_reg16(adev
, IO_ACX_HINT_TRIG
, ACX_IRQ_BEACON
);
2780 /* dump Acx111 Mem Configuration */
2781 printk("dump mem config:\n"
2782 "data read: %d, struct size: %d\n"
2783 "Number of stations: %1X\n"
2784 "Memory block size: %1X\n"
2785 "tx/rx memory block allocation: %1X\n"
2786 "count rx: %X / tx: %X queues\n"
2788 "fragmentation %1X\n"
2789 "Rx Queue 1 Count Descriptors: %X\n"
2790 "Rx Queue 1 Host Memory Start: %X\n"
2791 "Tx Queue 1 Count Descriptors: %X\n"
2792 "Tx Queue 1 Attributes: %X\n",
2793 memconf
.len
, (int)sizeof(memconf
),
2794 memconf
.no_of_stations
,
2795 memconf
.memory_block_size
,
2796 memconf
.tx_rx_memory_block_allocation
,
2797 memconf
.count_rx_queues
, memconf
.count_tx_queues
,
2799 memconf
.fragmentation
,
2800 memconf
.rx_queue1_count_descs
,
2801 acx2cpu(memconf
.rx_queue1_host_rx_start
),
2802 memconf
.tx_queue1_count_descs
, memconf
.tx_queue1_attributes
);
2804 /* dump Acx111 Queue Configuration */
2805 printk("dump queue head:\n"
2806 "data read: %d, struct size: %d\n"
2807 "tx_memory_block_address (from card): %X\n"
2808 "rx_memory_block_address (from card): %X\n"
2809 "rx1_queue address (from card): %X\n"
2810 "tx1_queue address (from card): %X\n"
2811 "tx1_queue attributes (from card): %X\n",
2812 queueconf
.len
, (int)sizeof(queueconf
),
2813 queueconf
.tx_memory_block_address
,
2814 queueconf
.rx_memory_block_address
,
2815 queueconf
.rx1_queue_address
,
2816 queueconf
.tx1_queue_address
, queueconf
.tx1_attributes
);
2818 /* dump Acx111 Mem Map */
2819 printk("dump mem map:\n"
2820 "data read: %d, struct size: %d\n"
2823 "WEP default key start: %X\n"
2824 "WEP default key end: %X\n"
2825 "STA table start: %X\n"
2826 "STA table end: %X\n"
2827 "Packet template start: %X\n"
2828 "Packet template end: %X\n"
2829 "Queue memory start: %X\n"
2830 "Queue memory end: %X\n"
2831 "Packet memory pool start: %X\n"
2832 "Packet memory pool end: %X\n"
2835 *((u16
*) & memmap
[0x02]), (int)sizeof(memmap
),
2836 *((u32
*) & memmap
[0x04]),
2837 *((u32
*) & memmap
[0x08]),
2838 *((u32
*) & memmap
[0x0C]),
2839 *((u32
*) & memmap
[0x10]),
2840 *((u32
*) & memmap
[0x14]),
2841 *((u32
*) & memmap
[0x18]),
2842 *((u32
*) & memmap
[0x1C]),
2843 *((u32
*) & memmap
[0x20]),
2844 *((u32
*) & memmap
[0x24]),
2845 *((u32
*) & memmap
[0x28]),
2846 *((u32
*) & memmap
[0x2C]),
2847 *((u32
*) & memmap
[0x30]), adev
->iobase
, adev
->iobase2
);
2849 /* dump Acx111 Rx Config */
2850 printk("dump rx config:\n"
2851 "data read: %d, struct size: %d\n"
2853 "rx filter config: %X\n",
2854 *((u16
*) & rxconfig
[0x02]), (int)sizeof(rxconfig
),
2855 *((u16
*) & rxconfig
[0x04]), *((u16
*) & rxconfig
[0x06]));
2857 /* dump Acx111 fcs error */
2858 printk("dump fcserror:\n"
2859 "data read: %d, struct size: %d\n"
2861 *((u16
*) & fcserror
[0x02]), (int)sizeof(fcserror
),
2862 *((u32
*) & fcserror
[0x04]));
2864 /* dump Acx111 rate fallback */
2865 printk("dump rate fallback:\n"
2866 "data read: %d, struct size: %d\n"
2867 "ratefallback: %X\n",
2868 *((u16
*) & ratefallback
[0x02]), (int)sizeof(ratefallback
),
2869 *((u8
*) & ratefallback
[0x04]));
2871 /* protect against IRQ */
2872 acx_lock(adev
, flags
);
2874 /* dump acx111 internal rx descriptor ring buffer */
2875 rxdesc
= adev
->rxdesc_start
;
2877 /* loop over complete receive pool */
2879 for (i
= 0; i
< RX_CNT
; i
++) {
2880 printk("\ndump internal rxdesc %d:\n"
2883 "acx mem pointer (dynamic) 0x%X\n"
2884 "CTL (dynamic) 0x%X\n"
2885 "Rate (dynamic) 0x%X\n"
2886 "RxStatus (dynamic) 0x%X\n"
2887 "Mod/Pre (dynamic) 0x%X\n",
2890 acx2cpu(rxdesc
->pNextDesc
),
2891 acx2cpu(rxdesc
->ACXMemPtr
),
2893 rxdesc
->rate
, rxdesc
->error
, rxdesc
->SNR
);
2897 /* dump host rx descriptor ring buffer */
2899 rxhostdesc
= adev
->rxhostdesc_start
;
2901 /* loop over complete receive pool */
2903 for (i
= 0; i
< RX_CNT
; i
++) {
2904 printk("\ndump host rxdesc %d:\n"
2906 "buffer mem pos 0x%X\n"
2907 "buffer mem offset 0x%X\n"
2914 acx2cpu(rxhostdesc
->data_phy
),
2915 rxhostdesc
->data_offset
,
2916 le16_to_cpu(rxhostdesc
->Ctl_16
),
2917 le16_to_cpu(rxhostdesc
->length
),
2918 acx2cpu(rxhostdesc
->desc_phy_next
),
2919 rxhostdesc
->Status
);
2923 /* dump acx111 internal tx descriptor ring buffer */
2924 txdesc
= adev
->txdesc_start
;
2926 /* loop over complete transmit pool */
2928 for (i
= 0; i
< TX_CNT
; i
++) {
2929 printk("\ndump internal txdesc %d:\n"
2933 "acx mem pointer (dynamic) 0x%X\n"
2934 "host mem pointer (dynamic) 0x%X\n"
2935 "length (dynamic) 0x%X\n"
2936 "CTL (dynamic) 0x%X\n"
2937 "CTL2 (dynamic) 0x%X\n"
2938 "Status (dynamic) 0x%X\n"
2939 "Rate (dynamic) 0x%X\n",
2941 (int)sizeof(struct txdesc
),
2943 acx2cpu(txdesc
->pNextDesc
),
2944 acx2cpu(txdesc
->AcxMemPtr
),
2945 acx2cpu(txdesc
->HostMemPtr
),
2946 le16_to_cpu(txdesc
->total_length
),
2948 txdesc
->Ctl2_8
, txdesc
->error
,
2950 txdesc
= advance_txdesc(adev
, txdesc
, 1);
2953 /* dump host tx descriptor ring buffer */
2955 txhostdesc
= adev
->txhostdesc_start
;
2957 /* loop over complete host send pool */
2959 for (i
= 0; i
< TX_CNT
* 2; i
++) {
2960 printk("\ndump host txdesc %d:\n"
2962 "buffer mem pos 0x%X\n"
2963 "buffer mem offset 0x%X\n"
2970 acx2cpu(txhostdesc
->data_phy
),
2971 txhostdesc
->data_offset
,
2972 le16_to_cpu(txhostdesc
->Ctl_16
),
2973 le16_to_cpu(txhostdesc
->length
),
2974 acx2cpu(txhostdesc
->desc_phy_next
),
2975 le32_to_cpu(txhostdesc
->Status
));
2979 /* write_reg16(adev, 0xb4, 0x4); */
2981 acx_unlock(adev
, flags
);
2984 acx_sem_unlock(adev
);
2985 #endif /* ACX_DEBUG */
2990 /***********************************************************************
2993 acx100pci_ioctl_set_phy_amp_bias(struct net_device
*ndev
,
2994 struct iw_request_info
*info
,
2995 struct iw_param
*vwrq
, char *extra
)
2997 acx_device_t
*adev
= ndev2adev(ndev
);
2998 unsigned long flags
;
3001 if (!IS_ACX100(adev
)) {
3003 * Removing this check *might* damage
3004 * hardware, since we're tweaking GPIOs here after all!!!
3005 * You've been warned...
3007 acx_log(LOG_INFO
, L_ANY
,
3008 "sorry, setting bias level for non-acx100 "
3009 "is not supported yet\n");
3014 acx_log(LOG_INFO
, L_ANY
,
3015 "invalid bias parameter, range is 0-7\n");
3021 /* Need to lock accesses to [IO_ACX_GPIO_OUT]:
3022 * IRQ handler uses it to update LED */
3023 acx_lock(adev
, flags
);
3024 gpio_old
= read_reg16(adev
, IO_ACX_GPIO_OUT
);
3025 write_reg16(adev
, IO_ACX_GPIO_OUT
,
3026 (gpio_old
& 0xf8ff) | ((u16
) * extra
<< 8));
3027 acx_unlock(adev
, flags
);
3029 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "gpio_old: 0x%04X\n", gpio_old
);
3030 acx_log(LOG_INFO
, L_ANY
,
3031 "%s: PHY power amplifier bias: old:%d, new:%d\n",
3032 ndev
->name
, (gpio_old
& 0x0700) >> 8, (unsigned char)*extra
);
3034 acx_sem_unlock(adev
);
3040 /***************************************************************
3041 ** acxpci_l_alloc_tx
3042 ** Actually returns a txdesc_t* ptr
3044 ** FIXME: in case of fragments, should allocate multiple descrs
3045 ** after figuring out how many we need and whether we still have
3046 ** sufficiently many.
3048 tx_t
*acxpci_l_alloc_tx(acx_device_t
* adev
)
3050 struct txdesc
*txdesc
;
3056 if (unlikely(!adev
->tx_free
)) {
3057 acx_log(LOG_WARNING
, L_ANY
, "BUG: no free txdesc left\n");
3062 head
= adev
->tx_head
;
3063 txdesc
= get_txdesc(adev
, head
);
3064 ctl8
= txdesc
->Ctl_8
;
3066 /* 2005-10-11: there were several bug reports on this happening
3067 ** but now cause seems to be understood & fixed */
3068 if (unlikely(DESC_CTL_HOSTOWN
!= (ctl8
& DESC_CTL_ACXDONE_HOSTOWN
))) {
3069 /* whoops, descr at current index is not free, so probably
3070 * ring buffer already full */
3071 acx_log(LOG_WARNING
, L_ANY
, "BUG: tx_head:%d Ctl8:0x%02X - "
3072 "failed to find free txdesc\n", head
, ctl8
);
3077 /* Needed in case txdesc won't be eventually submitted for tx */
3078 txdesc
->Ctl_8
= DESC_CTL_ACXDONE_HOSTOWN
;
3081 acx_log(LOG_DEBUG
, L_BUFT
, "tx: got desc %u, %u remain\n",
3082 head
, adev
->tx_free
);
3083 /* Keep a few free descs between head and tail of tx ring.
3084 ** It is not absolutely needed, just feels safer */
3085 if (adev
->tx_free
< TX_STOP_QUEUE
) {
3086 acx_log(LOG_DEBUG
, L_BUF
, "stop queue (%u tx desc left)\n",
3088 acx_stop_queue(adev
->ieee
, NULL
);
3091 /* returning current descriptor, so advance to next free one */
3092 adev
->tx_head
= (head
+ 1) % TX_CNT
;
3096 return (tx_t
*) txdesc
;
3100 /***********************************************************************
3102 void *acxpci_l_get_txbuf(acx_device_t
* adev
, tx_t
* tx_opaque
)
3104 return get_txhostdesc(adev
, (txdesc_t
*) tx_opaque
)->data
;
3108 /***********************************************************************
3111 ** Can be called from IRQ (rx -> (AP bridging or mgmt response) -> tx).
3112 ** Can be called from acx_i_start_xmit (data frames from net core).
3114 ** FIXME: in case of fragments, should loop over the number of
3115 ** pre-allocated tx descrs, properly setting up transfer data and
3116 ** CTL_xxx flags according to fragment number.
3119 acxpci_l_tx_data(acx_device_t
* adev
, tx_t
* tx_opaque
, int len
,
3120 struct ieee80211_tx_control
*ieeectl
,struct sk_buff
* skb
)
3122 txdesc_t
*txdesc
= (txdesc_t
*) tx_opaque
;
3123 struct ieee80211_hdr
*wireless_header
;
3124 txhostdesc_t
*hostdesc1
, *hostdesc2
;
3131 /* fw doesn't tx such packets anyhow */
3132 /* if (unlikely(len < WLAN_HDR_A3_LEN))
3135 hostdesc1
= get_txhostdesc(adev
, txdesc
);
3136 wireless_header
= (struct ieee80211_hdr
*)hostdesc1
->data
;
3137 /* modify flag status in separate variable to be able to write it back
3138 * in one big swoop later (also in order to have less device memory
3140 Ctl_8
= txdesc
->Ctl_8
;
3141 Ctl2_8
= 0; /* really need to init it to 0, not txdesc->Ctl2_8, it seems */
3143 hostdesc2
= hostdesc1
+ 1;
3145 /* DON'T simply set Ctl field to 0 here globally,
3146 * it needs to maintain a consistent flag status (those are state flags!!),
3147 * otherwise it may lead to severe disruption. Only set or reset particular
3148 * flags at the exact moment this is needed... */
3150 /* let chip do RTS/CTS handshaking before sending
3151 * in case packet size exceeds threshold */
3152 if (ieeectl
->flags
& IEEE80211_TXCTL_USE_RTS_CTS
)
3153 SET_BIT(Ctl2_8
, DESC_CTL2_RTS
);
3155 CLEAR_BIT(Ctl2_8
, DESC_CTL2_RTS
);
3157 rate_cur
= ieeectl
->tx_rate
;
3158 if (unlikely(!rate_cur
)) {
3159 acx_log(LOG_WARNING
, L_ANY
, "driver bug! bad ratemask\n");
3163 /* used in tx cleanup routine for auto rate and accounting: */
3164 /* put_txcr(adev, txdesc, clt, rate_cur); deprecated by mac80211 */
3166 txdesc
->total_length
= cpu_to_le16(len
);
3167 wlhdr_len
= ieee80211_get_hdrlen(le16_to_cpu(wireless_header
->frame_control
));
3168 hostdesc2
->length
= cpu_to_le16(len
- wlhdr_len
);
3170 if (!ieeectl->do_not_encrypt && ieeectl->key_idx>= 0)
3172 u16 key_idx = (u16)(ieeectl->key_idx);
3173 struct acx_key* key = &(adev->key[key_idx]);
3177 memcpy(ieeehdr->wep_iv, ((u8*)wireless_header) + wlhdr_len, 4);
3181 if (IS_ACX111(adev
)) {
3182 /* note that if !txdesc->do_auto, txrate->cur
3183 ** has only one nonzero bit */
3184 txdesc
->u
.r2
.rate111
= cpu_to_le16(rate_cur
3185 /* WARNING: I was never able to make it work with prism54 AP.
3186 ** It was falling down to 1Mbit where shortpre is not applicable,
3187 ** and not working at all at "5,11 basic rates only" setting.
3188 ** I even didn't see tx packets in radio packet capture.
3189 ** Disabled for now --vda */
3190 /*| ((clt->shortpre && clt->cur!=RATE111_1) ? RATE111_SHORTPRE : 0) */
3192 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3193 /* should add this to rate111 above as necessary */
3194 |(clt
->pbcc511
? RATE111_PBCC511
: 0)
3196 hostdesc1
->length
= cpu_to_le16(len
);
3197 } else { /* ACX100 */
3198 u8 rate_100
= ieeectl
->tx_rate
;
3199 txdesc
->u
.r1
.rate
= rate_100
;
3200 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3202 if (n
== RATE100_5
|| n
== RATE100_11
)
3203 n
|= RATE100_PBCC511
;
3206 if (clt
->shortpre
&& (clt
->cur
!= RATE111_1
))
3207 SET_BIT(Ctl_8
, DESC_CTL_SHORT_PREAMBLE
); /* set Short Preamble */
3209 /* set autodma and reclaim and 1st mpdu */
3211 DESC_CTL_AUTODMA
| DESC_CTL_RECLAIM
|
3212 DESC_CTL_FIRSTFRAG
);
3213 #if ACX_FRAGMENTATION
3214 /* SET_BIT(Ctl2_8, DESC_CTL2_MORE_FRAG); cannot set it unconditionally, needs to be set for all non-last fragments */
3216 hostdesc1
->length
= cpu_to_le16(wlhdr_len
);
3218 /* don't need to clean ack/rts statistics here, already
3219 * done on descr cleanup */
3221 /* clears HOSTOWN and ACXDONE bits, thus telling that the descriptors
3222 * are now owned by the acx100; do this as LAST operation */
3223 CLEAR_BIT(Ctl_8
, DESC_CTL_ACXDONE_HOSTOWN
);
3224 /* flush writes before we release hostdesc to the adapter here */
3226 CLEAR_BIT(hostdesc1
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
3227 CLEAR_BIT(hostdesc2
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
3229 /* write back modified flags */
3230 CLEAR_BIT(Ctl2_8
, DESC_CTL2_WEP
);
3231 txdesc
->Ctl2_8
= Ctl2_8
;
3232 txdesc
->Ctl_8
= Ctl_8
;
3233 /* unused: txdesc->tx_time = cpu_to_le32(jiffies); */
3235 /* flush writes before we tell the adapter that it's its turn now */
3236 write_reg16(adev
, IO_ACX_INT_TRIG
, INT_TRIG_TXPRC
);
3238 /* log the packet content AFTER sending it,
3239 * in order to not delay sending any further than absolutely needed
3240 * Do separate logs for acx100/111 to have human-readable rates */
3241 memcpy(&(hostdesc1
->txstatus
.control
),ieeectl
,sizeof(struct ieee80211_tx_control
));
3242 hostdesc1
->skb
= skb
;
3248 /***********************************************************************
3249 ** acxpci_l_clean_txdesc
3251 ** This function resets the txdescs' status when the ACX100
3252 ** signals the TX done IRQ (txdescs have been processed), starting with
3253 ** the pool index of the descriptor which we would use next,
3254 ** in order to make sure that we can be as fast as possible
3255 ** in filling new txdescs.
3256 ** Everytime we get called we know where the next packet to be cleaned is.
3260 static inline void log_txbuffer(const acx_device_t
* adev
)
3264 static void log_txbuffer(acx_device_t
* adev
)
3269 /* no FN_ENTER here, we don't want that */
3270 /* no locks here, since it's entirely non-critical code */
3271 txdesc
= adev
->txdesc_start
;
3272 if (unlikely(!txdesc
))
3274 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "tx: desc->Ctl8's:");
3275 for (i
= 0; i
< TX_CNT
; i
++) {
3276 printk(" %02X", txdesc
->Ctl_8
);
3277 txdesc
= advance_txdesc(adev
, txdesc
, 1);
3284 static void handle_tx_error(acx_device_t
* adev
, u8 error
, unsigned int finger
,
3285 struct ieee80211_tx_status
*status
)
3287 const char *err
= "unknown error";
3289 /* hmm, should we handle this as a mask
3290 * of *several* bits?
3291 * For now I think only caring about
3292 * individual bits is ok... */
3295 err
= "no Tx due to error in other fragment";
3296 /* adev->wstats.discard.fragment++; */
3300 adev
->stats
.tx_aborted_errors
++;
3303 err
= "Tx desc wrong parameters";
3304 /* adev->wstats.discard.misc++; */
3307 err
= "WEP key not found";
3308 /* adev->wstats.discard.misc++; */
3311 err
= "MSDU lifetime timeout? - try changing "
3312 "'iwconfig retry lifetime XXX'";
3313 /* adev->wstats.discard.misc++; */
3316 err
= "excessive Tx retries due to either distance "
3317 "too high or unable to Tx or Tx frame error - "
3318 "try changing 'iwconfig txpower XXX' or "
3319 "'sens'itivity or 'retry'";
3320 /* adev->wstats.discard.retries++; */
3321 /* Tx error 0x20 also seems to occur on
3322 * overheating, so I'm not sure whether we
3323 * actually want to do aggressive radio recalibration,
3324 * since people maybe won't notice then that their hardware
3325 * is slowly getting cooked...
3326 * Or is it still a safe long distance from utter
3327 * radio non-functionality despite many radio recalibs
3328 * to final destructive overheating of the hardware?
3329 * In this case we really should do recalib here...
3330 * I guess the only way to find out is to do a
3331 * potentially fatal self-experiment :-\
3332 * Or maybe only recalib in case we're using Tx
3333 * rate auto (on errors switching to lower speed
3334 * --> less heat?) or 802.11 power save mode?
3336 * ok, just do it. */
3337 if (++adev
->retry_errors_msg_ratelimit
% 4 == 0) {
3338 if (adev
->retry_errors_msg_ratelimit
<= 20) {
3339 acx_log(LOG_WARNING
, L_ANY
,
3340 "%s: several excessive Tx "
3341 "retry errors occurred, attempting "
3342 "to recalibrate radio\n",
3343 wiphy_name(adev
->ieee
->wiphy
));
3344 acx_log(LOG_WARNING
, L_ANY
,
3345 "Radio drift might be caused by "
3346 "increasing card temperature, please "
3347 "check the card before it's too late!\n");
3348 if (adev
->retry_errors_msg_ratelimit
== 20)
3349 acx_log(LOG_WARNING
, L_ANY
,
3350 "disabling above message\n");
3353 acx_schedule_task(adev
,
3354 ACX_TASKLET_CMD_RADIO_RECALIB
);
3356 status
->excessive_retries
++;
3359 err
= "Tx buffer overflow";
3360 adev
->stats
.tx_fifo_errors
++;
3363 /* possibly ACPI C-state powersaving related!!!
3364 * (DMA timeout due to excessively high wakeup
3365 * latency after C-state activation!?)
3366 * Disable C-State powersaving and try again,
3367 * then PLEASE REPORT, I'm VERY interested in
3368 * whether my theory is correct that this is
3369 * actually the problem here.
3370 * In that case, use new Linux idle wakeup latency
3371 * requirements kernel API to prevent this issue. */
3373 /* adev->wstats.discard.misc++; */
3376 adev
->stats
.tx_errors
++;
3377 if (adev
->stats
.tx_errors
<= 20)
3378 acx_log(LOG_WARNING
, L_ANY
,
3379 "%s: tx error 0x%02X, buf %02u! (%s)\n",
3380 wiphy_name(adev
->ieee
->wiphy
), error
, finger
, err
);
3382 acx_log(LOG_WARNING
, L_ANY
,
3383 "%s: tx error 0x%02X, buf %02u!\n",
3384 wiphy_name(adev
->ieee
->wiphy
), error
, finger
);
3388 unsigned int acxpci_l_clean_txdesc(acx_device_t
* adev
)
3391 txhostdesc_t
*hostdesc
;
3395 u8 error
, ack_failures
, rts_failures
, rts_ok
, r100
;
3399 if (unlikely(acx_debug
& L_REALLYVERBOSE
))
3402 acx_log(LOG_DEBUG
, L_BUFT
, "tx: cleaning up bufs from %u\n",
3405 /* We know first descr which is not free yet. We advance it as far
3406 ** as we see correct bits set in following descs (if next desc
3407 ** is NOT free, we shouldn't advance at all). We know that in
3408 ** front of tx_tail may be "holes" with isolated free descs.
3409 ** We will catch up when all intermediate descs will be freed also */
3411 finger
= adev
->tx_tail
;
3413 while (likely(finger
!= adev
->tx_head
)) {
3414 txdesc
= get_txdesc(adev
, finger
);
3416 /* If we allocated txdesc on tx path but then decided
3417 ** to NOT use it, then it will be left as a free "bubble"
3418 ** in the "allocated for tx" part of the ring.
3419 ** We may meet it on the next ring pass here. */
3421 /* stop if not marked as "tx finished" and "host owned" */
3422 if ((txdesc
->Ctl_8
& DESC_CTL_ACXDONE_HOSTOWN
)
3423 != DESC_CTL_ACXDONE_HOSTOWN
) {
3424 if (unlikely(!num_cleaned
)) { /* maybe remove completely */
3425 acx_log(LOG_DEBUG
, L_BUFT
,
3426 "clean_txdesc: tail isn't free. "
3427 "tail:%d head:%d\n",
3428 adev
->tx_tail
, adev
->tx_head
);
3433 /* remember desc values... */
3434 error
= txdesc
->error
;
3435 ack_failures
= txdesc
->ack_failures
;
3436 rts_failures
= txdesc
->rts_failures
;
3437 rts_ok
= txdesc
->rts_ok
;
3438 r100
= txdesc
->u
.r1
.rate
;
3439 r111
= le16_to_cpu(txdesc
->u
.r2
.rate111
);
3441 /* need to check for certain error conditions before we
3442 * clean the descriptor: we still need valid descr data here */
3443 hostdesc
= get_txhostdesc(adev
, txdesc
);
3445 hostdesc
->txstatus
.flags
|= IEEE80211_TX_STATUS_ACK
;
3446 if (unlikely(0x30 & error
)) {
3447 /* only send IWEVTXDROP in case of retry or lifetime exceeded;
3448 * all other errors mean we screwed up locally */
3449 /* union iwreq_data wrqu;
3450 struct ieee80211_hdr_3addr *hdr;
3451 hdr = (struct ieee80211_hdr_3addr *) hostdesc->data;
3452 MAC_COPY(wrqu.addr.sa_data, hdr->addr1);
3454 hostdesc
->txstatus
.flags
&= ~IEEE80211_TX_STATUS_ACK
;
3457 /* ...and free the desc */
3459 txdesc
->ack_failures
= 0;
3460 txdesc
->rts_failures
= 0;
3462 /* signal host owning it LAST, since ACX already knows that this
3463 ** descriptor is finished since it set Ctl_8 accordingly. */
3464 txdesc
->Ctl_8
= DESC_CTL_HOSTOWN
;
3469 if ((adev
->tx_free
>= TX_START_QUEUE
)
3470 /* && (adev->status == ACX_STATUS_4_ASSOCIATED) */
3471 /*&& (acx_queue_stopped(adev->ieee))*/
3473 acx_log(LOG_DEBUG
, L_BUF
,
3474 "tx: wake queue (avail. Tx desc %u)\n",
3476 acx_wake_queue(adev
->ieee
, NULL
);
3479 /* do error checking, rate handling and logging
3480 * AFTER having done the work, it's faster */
3482 /* Rate handling is done in mac80211 */
3483 /* if (adev->rate_auto) {
3484 struct client *clt = get_txc(adev, txdesc);
3486 u16 cur = get_txr(adev, txdesc);
3487 if (clt->rate_cur == cur) {
3488 acx_l_handle_txrate_auto(adev, clt, cur,*/ /* intended rate */
3489 /*r100, r111,*/ /* actually used rate */
3490 /*(error & 0x30),*/ /* was there an error? */
3499 if (unlikely(error
))
3500 handle_tx_error(adev
, error
, finger
, &hostdesc
->txstatus
);
3502 if (IS_ACX111(adev
))
3503 acx_log(LOG_DEBUG
, L_BUFT
, "tx: cleaned %u: !ACK=%u "
3504 "!RTS=%u RTS=%u r111=%04X tx_free=%u\n",
3505 finger
, ack_failures
,
3506 rts_failures
, rts_ok
, r111
, adev
->tx_free
);
3508 acx_log(LOG_DEBUG
, L_BUFT
, "tx: cleaned %u: !ACK=%u "
3509 "!RTS=%u RTS=%u rate=%u\n",
3510 finger
, ack_failures
,
3511 rts_failures
, rts_ok
, r100
);
3513 /* And finally report upstream */
3516 hostdesc
->txstatus
.excessive_retries
= rts_failures
;
3517 hostdesc
->txstatus
.retry_count
= ack_failures
;
3518 ieee80211_tx_status(adev
->ieee
,hostdesc
->skb
,&hostdesc
->txstatus
);
3519 memset(&hostdesc
->txstatus
, 0, sizeof(struct ieee80211_tx_status
));
3521 /* update pointer for descr to be cleaned next */
3522 finger
= (finger
+ 1) % TX_CNT
;
3524 /* remember last position */
3525 adev
->tx_tail
= finger
;
3527 FN_EXIT1(num_cleaned
);
3531 /* clean *all* Tx descriptors, and regardless of their previous state.
3532 * Used for brute-force reset handling. */
3533 void acxpci_l_clean_txdesc_emergency(acx_device_t
* adev
)
3540 for (i
= 0; i
< TX_CNT
; i
++) {
3541 txdesc
= get_txdesc(adev
, i
);
3544 txdesc
->ack_failures
= 0;
3545 txdesc
->rts_failures
= 0;
3548 txdesc
->Ctl_8
= DESC_CTL_HOSTOWN
;
3551 adev
->tx_free
= TX_CNT
;
3557 /***********************************************************************
3558 ** acxpci_s_create_tx_host_desc_queue
3561 static void *allocate(acx_device_t
* adev
, size_t size
, dma_addr_t
* phy
,
3566 ptr
= dma_alloc_coherent(adev
->bus_dev
, size
, phy
, GFP_KERNEL
);
3569 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
3570 "%s sz=%d adr=0x%p phy=0x%08llx\n",
3571 msg
, (int)size
, ptr
, (unsigned long long)*phy
);
3572 memset(ptr
, 0, size
);
3575 acx_log(LOG_WARNING
, L_ANY
, "%s allocation FAILED (%d bytes)\n",
3581 static int acxpci_s_create_tx_host_desc_queue(acx_device_t
* adev
)
3583 txhostdesc_t
*hostdesc
;
3585 dma_addr_t hostdesc_phy
;
3586 dma_addr_t txbuf_phy
;
3591 /* allocate TX buffer */
3592 adev
->txbuf_area_size
= TX_CNT
* /*WLAN_A4FR_MAXLEN_WEP_FCS*/ (30 + 2312 + 4);
3593 adev
->txbuf_start
= allocate(adev
, adev
->txbuf_area_size
,
3594 &adev
->txbuf_startphy
, "txbuf_start");
3595 if (!adev
->txbuf_start
)
3598 /* allocate the TX host descriptor queue pool */
3599 adev
->txhostdesc_area_size
= TX_CNT
* 2 * sizeof(*hostdesc
);
3600 adev
->txhostdesc_start
= allocate(adev
, adev
->txhostdesc_area_size
,
3601 &adev
->txhostdesc_startphy
,
3602 "txhostdesc_start");
3603 if (!adev
->txhostdesc_start
)
3605 /* check for proper alignment of TX host descriptor pool */
3606 if ((long)adev
->txhostdesc_start
& 3) {
3607 acx_log(LOG_WARNING
, L_ANY
,
3608 "driver bug: dma alloc returns unaligned address\n");
3612 hostdesc
= adev
->txhostdesc_start
;
3613 hostdesc_phy
= adev
->txhostdesc_startphy
;
3614 txbuf
= adev
->txbuf_start
;
3615 txbuf_phy
= adev
->txbuf_startphy
;
3618 /* Each tx buffer is accessed by hardware via
3619 ** txdesc -> txhostdesc(s) -> txbuffer(s).
3620 ** We use only one txhostdesc per txdesc, but it looks like
3621 ** acx111 is buggy: it accesses second txhostdesc
3622 ** (via hostdesc.desc_phy_next field) even if
3623 ** txdesc->length == hostdesc->length and thus
3624 ** entire packet was placed into first txhostdesc.
3625 ** Due to this bug acx111 hangs unless second txhostdesc
3626 ** has le16_to_cpu(hostdesc.length) = 3 (or larger)
3627 ** Storing NULL into hostdesc.desc_phy_next
3628 ** doesn't seem to help.
3630 ** Update: although it worked on Xterasys XN-2522g
3631 ** with len=3 trick, WG311v2 is even more bogus, doesn't work.
3632 ** Keeping this code (#ifdef'ed out) for documentational purposes.
3634 for (i
= 0; i
< TX_CNT
* 2; i
++) {
3635 hostdesc_phy
+= sizeof(*hostdesc
);
3637 hostdesc
->data_phy
= cpu2acx(txbuf_phy
);
3638 /* hostdesc->data_offset = ... */
3639 /* hostdesc->reserved = ... */
3640 hostdesc
->Ctl_16
= cpu_to_le16(DESC_CTL_HOSTOWN
);
3641 /* hostdesc->length = ... */
3642 hostdesc
->desc_phy_next
= cpu2acx(hostdesc_phy
);
3643 hostdesc
->pNext
= ptr2acx(NULL
);
3644 /* hostdesc->Status = ... */
3645 /* below: non-hardware fields */
3646 hostdesc
->data
= txbuf
;
3648 txbuf
+= WLAN_A4FR_MAXLEN_WEP_FCS
;
3649 txbuf_phy
+= WLAN_A4FR_MAXLEN_WEP_FCS
;
3651 /* hostdesc->data_phy = ... */
3652 /* hostdesc->data_offset = ... */
3653 /* hostdesc->reserved = ... */
3654 /* hostdesc->Ctl_16 = ... */
3655 hostdesc
->length
= cpu_to_le16(3); /* bug workaround */
3656 /* hostdesc->desc_phy_next = ... */
3657 /* hostdesc->pNext = ... */
3658 /* hostdesc->Status = ... */
3659 /* below: non-hardware fields */
3660 /* hostdesc->data = ... */
3665 /* We initialize two hostdescs so that they point to adjacent
3666 ** memory areas. Thus txbuf is really just a contiguous memory area */
3667 for (i
= 0; i
< TX_CNT
* 2; i
++) {
3668 hostdesc_phy
+= sizeof(*hostdesc
);
3670 hostdesc
->data_phy
= cpu2acx(txbuf_phy
);
3671 /* done by memset(0): hostdesc->data_offset = 0; */
3672 /* hostdesc->reserved = ... */
3673 hostdesc
->Ctl_16
= cpu_to_le16(DESC_CTL_HOSTOWN
);
3674 /* hostdesc->length = ... */
3675 hostdesc
->desc_phy_next
= cpu2acx(hostdesc_phy
);
3676 /* done by memset(0): hostdesc->pNext = ptr2acx(NULL); */
3677 /* hostdesc->Status = ... */
3678 /* ->data is a non-hardware field: */
3679 hostdesc
->data
= txbuf
;
3682 txbuf
+= 24 /*WLAN_HDR_A3_LEN*/;
3683 txbuf_phy
+= 24 /*WLAN_HDR_A3_LEN*/;
3685 txbuf
+= 30 + 2132 + 4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3686 txbuf_phy
+= 30 + 2132 +4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3691 hostdesc
->desc_phy_next
= cpu2acx(adev
->txhostdesc_startphy
);
3696 acx_log(LOG_WARNING
, L_ANY
, "create_tx_host_desc_queue FAILED\n");
3697 /* dealloc will be done by free function on error case */
3703 /***************************************************************
3704 ** acxpci_s_create_rx_host_desc_queue
3706 /* the whole size of a data buffer (header plus data body)
3707 * plus 32 bytes safety offset at the end */
3708 #define RX_BUFFER_SIZE (sizeof(rxbuffer_t) + 32)
3710 static int acxpci_s_create_rx_host_desc_queue(acx_device_t
* adev
)
3712 rxhostdesc_t
*hostdesc
;
3714 dma_addr_t hostdesc_phy
;
3715 dma_addr_t rxbuf_phy
;
3720 /* allocate the RX host descriptor queue pool */
3721 adev
->rxhostdesc_area_size
= RX_CNT
* sizeof(*hostdesc
);
3722 adev
->rxhostdesc_start
= allocate(adev
, adev
->rxhostdesc_area_size
,
3723 &adev
->rxhostdesc_startphy
,
3724 "rxhostdesc_start");
3725 if (!adev
->rxhostdesc_start
)
3727 /* check for proper alignment of RX host descriptor pool */
3728 if ((long)adev
->rxhostdesc_start
& 3) {
3729 acx_log(LOG_WARNING
, L_ANY
,
3730 "driver bug: dma alloc returns unaligned address\n");
3734 /* allocate Rx buffer pool which will be used by the acx
3735 * to store the whole content of the received frames in it */
3736 adev
->rxbuf_area_size
= RX_CNT
* RX_BUFFER_SIZE
;
3737 adev
->rxbuf_start
= allocate(adev
, adev
->rxbuf_area_size
,
3738 &adev
->rxbuf_startphy
, "rxbuf_start");
3739 if (!adev
->rxbuf_start
)
3742 rxbuf
= adev
->rxbuf_start
;
3743 rxbuf_phy
= adev
->rxbuf_startphy
;
3744 hostdesc
= adev
->rxhostdesc_start
;
3745 hostdesc_phy
= adev
->rxhostdesc_startphy
;
3747 /* don't make any popular C programming pointer arithmetic mistakes
3748 * here, otherwise I'll kill you...
3749 * (and don't dare asking me why I'm warning you about that...) */
3750 for (i
= 0; i
< RX_CNT
; i
++) {
3751 hostdesc
->data
= rxbuf
;
3752 hostdesc
->data_phy
= cpu2acx(rxbuf_phy
);
3753 hostdesc
->length
= cpu_to_le16(RX_BUFFER_SIZE
);
3754 CLEAR_BIT(hostdesc
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
3756 rxbuf_phy
+= sizeof(*rxbuf
);
3757 hostdesc_phy
+= sizeof(*hostdesc
);
3758 hostdesc
->desc_phy_next
= cpu2acx(hostdesc_phy
);
3762 hostdesc
->desc_phy_next
= cpu2acx(adev
->rxhostdesc_startphy
);
3766 acx_log(LOG_WARNING
, L_ANY
, "create_rx_host_desc_queue FAILED\n");
3767 /* dealloc will be done by free function on error case */
3773 /***************************************************************
3774 ** acxpci_s_create_hostdesc_queues
3776 int acxpci_s_create_hostdesc_queues(acx_device_t
* adev
)
3779 result
= acxpci_s_create_tx_host_desc_queue(adev
);
3782 result
= acxpci_s_create_rx_host_desc_queue(adev
);
3787 /***************************************************************
3788 ** acxpci_create_tx_desc_queue
3790 static void acxpci_create_tx_desc_queue(acx_device_t
* adev
, u32 tx_queue_start
)
3793 txhostdesc_t
*hostdesc
;
3794 dma_addr_t hostmemptr
;
3800 if (IS_ACX100(adev
))
3801 adev
->txdesc_size
= sizeof(*txdesc
);
3803 /* the acx111 txdesc is 4 bytes larger */
3804 adev
->txdesc_size
= sizeof(*txdesc
) + 4;
3806 adev
->txdesc_start
= (txdesc_t
*) (adev
->iobase2
+ tx_queue_start
);
3808 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "adev->iobase2=%p\n"
3809 "tx_queue_start=%08X\n adev->txdesc_start=%p\n",
3810 adev
->iobase2
, tx_queue_start
, adev
->txdesc_start
);
3812 adev
->tx_free
= TX_CNT
;
3813 /* done by memset: adev->tx_head = 0; */
3814 /* done by memset: adev->tx_tail = 0; */
3815 txdesc
= adev
->txdesc_start
;
3816 mem_offs
= tx_queue_start
;
3817 hostmemptr
= adev
->txhostdesc_startphy
;
3818 hostdesc
= adev
->txhostdesc_start
;
3820 if (IS_ACX111(adev
)) {
3821 /* ACX111 has a preinitialized Tx buffer! */
3822 /* loop over whole send pool */
3823 /* FIXME: do we have to do the hostmemptr stuff here?? */
3824 for (i
= 0; i
< TX_CNT
; i
++) {
3825 txdesc
->HostMemPtr
= ptr2acx(hostmemptr
);
3826 txdesc
->Ctl_8
= DESC_CTL_HOSTOWN
;
3827 /* reserve two (hdr desc and payload desc) */
3829 hostmemptr
+= 2 * sizeof(*hostdesc
);
3830 txdesc
= advance_txdesc(adev
, txdesc
, 1);
3833 /* ACX100 Tx buffer needs to be initialized by us */
3834 /* clear whole send pool. sizeof is safe here (we are acx100) */
3835 memset(adev
->txdesc_start
, 0, TX_CNT
* sizeof(*txdesc
));
3837 /* loop over whole send pool */
3838 for (i
= 0; i
< TX_CNT
; i
++) {
3839 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
3840 "configure card tx descriptor: 0x%p, "
3841 "size: 0x%X\n", txdesc
, adev
->txdesc_size
);
3843 /* pointer to hostdesc memory */
3844 txdesc
->HostMemPtr
= ptr2acx(hostmemptr
);
3845 /* initialise ctl */
3846 txdesc
->Ctl_8
= (DESC_CTL_HOSTOWN
| DESC_CTL_RECLAIM
3847 | DESC_CTL_AUTODMA
|
3848 DESC_CTL_FIRSTFRAG
);
3849 /* done by memset(0): txdesc->Ctl2_8 = 0; */
3850 /* point to next txdesc */
3852 cpu2acx(mem_offs
+ adev
->txdesc_size
);
3853 /* reserve two (hdr desc and payload desc) */
3855 hostmemptr
+= 2 * sizeof(*hostdesc
);
3856 /* go to the next one */
3857 mem_offs
+= adev
->txdesc_size
;
3858 /* ++ is safe here (we are acx100) */
3861 /* go back to the last one */
3863 /* and point to the first making it a ring buffer */
3864 txdesc
->pNextDesc
= cpu2acx(tx_queue_start
);
3870 /***************************************************************
3871 ** acxpci_create_rx_desc_queue
3873 static void acxpci_create_rx_desc_queue(acx_device_t
* adev
, u32 rx_queue_start
)
3881 /* done by memset: adev->rx_tail = 0; */
3883 /* ACX111 doesn't need any further config: preconfigures itself.
3884 * Simply print ring buffer for debugging */
3885 if (IS_ACX111(adev
)) {
3886 /* rxdesc_start already set here */
3888 adev
->rxdesc_start
=
3889 (rxdesc_t
*) ((u8
*) adev
->iobase2
+ rx_queue_start
);
3891 rxdesc
= adev
->rxdesc_start
;
3892 for (i
= 0; i
< RX_CNT
; i
++) {
3893 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
3894 "rx descriptor %d @ 0x%p\n", i
, rxdesc
);
3895 rxdesc
= adev
->rxdesc_start
= (rxdesc_t
*)
3896 (adev
->iobase2
+ acx2cpu(rxdesc
->pNextDesc
));
3899 /* we didn't pre-calculate rxdesc_start in case of ACX100 */
3900 /* rxdesc_start should be right AFTER Tx pool */
3901 adev
->rxdesc_start
= (rxdesc_t
*)
3902 ((u8
*) adev
->txdesc_start
+ (TX_CNT
* sizeof(txdesc_t
)));
3903 /* NB: sizeof(txdesc_t) above is valid because we know
3904 ** we are in if (acx100) block. Beware of cut-n-pasting elsewhere!
3905 ** acx111's txdesc is larger! */
3907 memset(adev
->rxdesc_start
, 0, RX_CNT
* sizeof(*rxdesc
));
3909 /* loop over whole receive pool */
3910 rxdesc
= adev
->rxdesc_start
;
3911 mem_offs
= rx_queue_start
;
3912 for (i
= 0; i
< RX_CNT
; i
++) {
3913 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
3914 "rx descriptor @ 0x%p\n", rxdesc
);
3915 rxdesc
->Ctl_8
= DESC_CTL_RECLAIM
| DESC_CTL_AUTODMA
;
3916 /* point to next rxdesc */
3917 rxdesc
->pNextDesc
= cpu2acx(mem_offs
+ sizeof(*rxdesc
));
3918 /* go to the next one */
3919 mem_offs
+= sizeof(*rxdesc
);
3922 /* go to the last one */
3925 /* and point to the first making it a ring buffer */
3926 rxdesc
->pNextDesc
= cpu2acx(rx_queue_start
);
3932 /***************************************************************
3933 ** acxpci_create_desc_queues
3936 acxpci_create_desc_queues(acx_device_t
* adev
, u32 tx_queue_start
,
3939 acxpci_create_tx_desc_queue(adev
, tx_queue_start
);
3940 acxpci_create_rx_desc_queue(adev
, rx_queue_start
);
3944 /***************************************************************
3945 ** acxpci_s_proc_diag_output
3947 char *acxpci_s_proc_diag_output(char *p
, acx_device_t
* adev
)
3949 const char *rtl
, *thd
, *ttl
;
3950 rxhostdesc_t
*rxhostdesc
;
3956 p
+= sprintf(p
, "** Rx buf **\n");
3957 rxhostdesc
= adev
->rxhostdesc_start
;
3959 for (i
= 0; i
< RX_CNT
; i
++) {
3960 rtl
= (i
== adev
->rx_tail
) ? " [tail]" : "";
3961 if ((rxhostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
3963 Status
& cpu_to_le32(DESC_STATUS_FULL
)))
3964 p
+= sprintf(p
, "%02u FULL%s\n", i
, rtl
);
3966 p
+= sprintf(p
, "%02u empty%s\n", i
, rtl
);
3969 /* p += sprintf(p, "** Tx buf (free %d, Linux netqueue %s) **\n",
3971 acx_queue_stopped(adev->ieee) ? "STOPPED" : "running");*/
3972 txdesc
= adev
->txdesc_start
;
3974 for (i
= 0; i
< TX_CNT
; i
++) {
3975 thd
= (i
== adev
->tx_head
) ? " [head]" : "";
3976 ttl
= (i
== adev
->tx_tail
) ? " [tail]" : "";
3977 if (txdesc
->Ctl_8
& DESC_CTL_ACXDONE
)
3978 p
+= sprintf(p
, "%02u free (%02X)%s%s\n", i
,
3979 txdesc
->Ctl_8
, thd
, ttl
);
3981 p
+= sprintf(p
, "%02u tx (%02X)%s%s\n", i
,
3982 txdesc
->Ctl_8
, thd
, ttl
);
3983 txdesc
= advance_txdesc(adev
, txdesc
, 1);
3988 "txbuf_start %p, txbuf_area_size %u, txbuf_startphy %08llx\n"
3989 "txdesc_size %u, txdesc_start %p\n"
3990 "txhostdesc_start %p, txhostdesc_area_size %u, txhostdesc_startphy %08llx\n"
3992 "rxhostdesc_start %p, rxhostdesc_area_size %u, rxhostdesc_startphy %08llx\n"
3993 "rxbuf_start %p, rxbuf_area_size %u, rxbuf_startphy %08llx\n",
3994 adev
->txbuf_start
, adev
->txbuf_area_size
,
3995 (unsigned long long)adev
->txbuf_startphy
,
3996 adev
->txdesc_size
, adev
->txdesc_start
,
3997 adev
->txhostdesc_start
, adev
->txhostdesc_area_size
,
3998 (unsigned long long)adev
->txhostdesc_startphy
,
4000 adev
->rxhostdesc_start
, adev
->rxhostdesc_area_size
,
4001 (unsigned long long)adev
->rxhostdesc_startphy
,
4002 adev
->rxbuf_start
, adev
->rxbuf_area_size
,
4003 (unsigned long long)adev
->rxbuf_startphy
);
4010 /***********************************************************************
4012 int acxpci_proc_eeprom_output(char *buf
, acx_device_t
* adev
)
4019 for (i
= 0; i
< 0x400; i
++) {
4020 acxpci_read_eeprom_byte(adev
, i
, p
++);
4028 /***********************************************************************
4031 void acxpci_set_interrupt_mask(acx_device_t
* adev
)
4033 if (IS_ACX111(adev
)) {
4034 adev
->irq_mask
= (u16
) ~ (0
4035 /* | ACX_IRQ_RX_DATA */
4036 | ACX_IRQ_TX_COMPLETE
4037 /* | ACX_IRQ_TX_XFER */
4038 | ACX_IRQ_RX_COMPLETE
4039 /* | ACX_IRQ_DTIM */
4040 /* | ACX_IRQ_BEACON */
4041 /* | ACX_IRQ_TIMER */
4042 /* | ACX_IRQ_KEY_NOT_FOUND */
4043 | ACX_IRQ_IV_ICV_FAILURE
4044 | ACX_IRQ_CMD_COMPLETE
4046 /* | ACX_IRQ_OVERFLOW */
4047 /* | ACX_IRQ_PROCESS_ERROR */
4048 | ACX_IRQ_SCAN_COMPLETE
4049 | ACX_IRQ_FCS_THRESHOLD
4050 /* | ACX_IRQ_UNKNOWN */
4052 /* Or else acx100 won't signal cmd completion, right? */
4053 adev
->irq_mask_off
= (u16
) ~ (ACX_IRQ_CMD_COMPLETE
); /* 0xfdff */
4055 adev
->irq_mask
= (u16
) ~ (0
4056 /* | ACX_IRQ_RX_DATA */
4057 | ACX_IRQ_TX_COMPLETE
4058 /* | ACX_IRQ_TX_XFER */
4059 | ACX_IRQ_RX_COMPLETE
4060 /* | ACX_IRQ_DTIM */
4061 /* | ACX_IRQ_BEACON */
4062 /* | ACX_IRQ_TIMER */
4063 /* | ACX_IRQ_KEY_NOT_FOUND */
4064 /* | ACX_IRQ_IV_ICV_FAILURE */
4065 | ACX_IRQ_CMD_COMPLETE
4067 /* | ACX_IRQ_OVERFLOW */
4068 /* | ACX_IRQ_PROCESS_ERROR */
4069 | ACX_IRQ_SCAN_COMPLETE
4070 /* | ACX_IRQ_FCS_THRESHOLD */
4071 /* | ACX_IRQ_UNKNOWN */
4073 adev
->irq_mask_off
= (u16
) ~ (ACX_IRQ_UNKNOWN
); /* 0x7fff */
4078 /***********************************************************************
4080 int acx100pci_s_set_tx_level(acx_device_t
* adev
, u8 level_dbm
)
4082 /* since it can be assumed that at least the Maxim radio has a
4083 * maximum power output of 20dBm and since it also can be
4084 * assumed that these values drive the DAC responsible for
4085 * setting the linear Tx level, I'd guess that these values
4086 * should be the corresponding linear values for a dBm value,
4087 * in other words: calculate the values from that formula:
4088 * Y [dBm] = 10 * log (X [mW])
4089 * then scale the 0..63 value range onto the 1..100mW range (0..20 dBm)
4090 * and you're done...
4091 * Hopefully that's ok, but you never know if we're actually
4092 * right... (especially since Windows XP doesn't seem to show
4093 * actual Tx dBm values :-P) */
4095 /* NOTE: on Maxim, value 30 IS 30mW, and value 10 IS 10mW - so the
4096 * values are EXACTLY mW!!! Not sure about RFMD and others,
4098 static const u8 dbm2val_maxim
[21] = {
4106 static const u8 dbm2val_rfmd
[21] = {
4116 switch (adev
->radio_type
) {
4117 case RADIO_MAXIM_0D
:
4118 table
= &dbm2val_maxim
[0];
4121 case RADIO_RALINK_15
:
4122 table
= &dbm2val_rfmd
[0];
4125 acx_log(LOG_WARNING
, L_ANY
, "%s: unknown/unsupported radio type, "
4126 "cannot modify tx power level yet!\n",
4127 wiphy_name(adev
->ieee
->wiphy
));
4130 acx_log(LOG_INFO
, L_ANY
,
4131 "%s: changing radio power level to %u dBm (%u)\n",
4132 wiphy_name(adev
->ieee
->wiphy
), level_dbm
, table
[level_dbm
]);
4133 acxpci_s_write_phy_reg(adev
, 0x11, table
[level_dbm
]);
4138 struct vlynq_reg_config
{
4143 struct vlynq_known
{
4146 struct vlynq_mapping rx_mapping
[4];
4150 struct vlynq_reg_config regs
[10];
4153 #define CHIP_TNETW1130 0x00000009
4154 #define CHIP_TNETW1350 0x00000029
4156 static struct vlynq_known known_devices
[] = {
4158 .chip_id
= CHIP_TNETW1130
, .name
= "TI TNETW1130",
4160 { .size
= 0x22000, .offset
= 0xf0000000 },
4161 { .size
= 0x40000, .offset
= 0xc0000000 },
4162 { .size
= 0x0, .offset
= 0x0 },
4163 { .size
= 0x0, .offset
= 0x0 },
4166 .irq_type
= IRQ_TYPE_EDGE_RISING
,
4171 .value
= (0xd0000000 - PHYS_OFFSET
)
4175 .value
= (0xd0000000 - PHYS_OFFSET
)
4177 { .offset
= 0x740, .value
= 0 },
4178 { .offset
= 0x744, .value
= 0x00010000 },
4179 { .offset
= 0x764, .value
= 0x00010000 },
4183 .chip_id
= CHIP_TNETW1350
, .name
= "TI TNETW1350",
4185 { .size
= 0x100000, .offset
= 0x00300000 },
4186 { .size
= 0x80000, .offset
= 0x00000000 },
4187 { .size
= 0x0, .offset
= 0x0 },
4188 { .size
= 0x0, .offset
= 0x0 },
4191 .irq_type
= IRQ_TYPE_EDGE_RISING
,
4196 .value
= (0x60000000 - PHYS_OFFSET
)
4200 .value
= (0x60000000 - PHYS_OFFSET
)
4202 { .offset
= 0x740, .value
= 0 },
4203 { .offset
= 0x744, .value
= 0x00010000 },
4204 { .offset
= 0x764, .value
= 0x00010000 },
4209 static struct vlynq_device_id acx_vlynq_id
[] = {
4210 { CHIP_TNETW1130
, vlynq_div_auto
, 0 },
4211 { CHIP_TNETW1350
, vlynq_div_auto
, 1 },
4215 static __devinit
int vlynq_probe(struct vlynq_device
*vdev
,
4216 struct vlynq_device_id
*id
)
4218 int result
= -EIO
, i
;
4220 struct ieee80211_hw
*ieee
;
4221 acx_device_t
*adev
= NULL
;
4222 acx111_ie_configoption_t co
;
4223 struct vlynq_mapping mapping
[4] = { { 0, }, };
4224 struct vlynq_known
*match
= NULL
;
4227 result
= vlynq_enable_device(vdev
);
4231 match
= &known_devices
[id
->driver_data
];
4238 mapping
[0].offset
= ARCH_PFN_OFFSET
<< PAGE_SHIFT
;
4239 mapping
[0].size
= 0x02000000;
4240 vlynq_set_local_mapping(vdev
, vdev
->mem_start
, mapping
);
4241 vlynq_set_remote_mapping(vdev
, 0, match
->rx_mapping
);
4243 set_irq_type(vlynq_virq_to_irq(vdev
, match
->irq
), match
->irq_type
);
4245 addr
= (u32
)ioremap(vdev
->mem_start
, 0x1000);
4247 acx_log(LOG_WARNING
, L_ANY
, "%s: failed to remap io memory\n",
4253 for (i
= 0; i
< match
->num_regs
; i
++)
4254 iowrite32(match
->regs
[i
].value
,
4255 (u32
*)(addr
+ match
->regs
[i
].offset
));
4257 iounmap((void *)addr
);
4259 ieee
= ieee80211_alloc_hw(sizeof(struct acx_device
), &acxpci_hw_ops
);
4261 acx_log(LOG_WARNING
, L_ANY
,
4262 "could not allocate ieee80211 structure %s\n",
4264 goto fail_alloc_netdev
;
4266 ieee
->flags
&= ~IEEE80211_HW_RX_INCLUDES_FCS
;
4269 adev
= ieee2adev(ieee
);
4271 memset(adev
, 0, sizeof(*adev
));
4272 /** Set up our private interface **/
4273 spin_lock_init(&adev
->spinlock
); /* initial state: unlocked */
4274 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
4275 mutex_init(&adev
->mutex
);
4276 /* since nobody can see new netdev yet, we can as well
4277 ** just _presume_ that we're under sem (instead of actually taking it): */
4278 /* acx_sem_lock(adev); */
4281 adev
->bus_dev
= &vdev
->dev
;
4282 adev
->dev_type
= DEVTYPE_PCI
;
4284 /** Finished with private interface **/
4286 vlynq_set_drvdata(vdev
, ieee
);
4287 if (!request_mem_region(vdev
->mem_start
, vdev
->mem_end
- vdev
->mem_start
, "acx")) {
4288 acx_log(LOG_WARNING
, L_ANY
, "cannot reserve VLYNQ memory region\n");
4289 goto fail_request_mem_region
;
4292 adev
->iobase
= ioremap(vdev
->mem_start
, vdev
->mem_end
- vdev
->mem_start
);
4293 if (!adev
->iobase
) {
4294 acx_log(LOG_WARNING
, L_ANY
, "ioremap() FAILED\n");
4297 adev
->iobase2
= adev
->iobase
+ match
->rx_mapping
[0].size
;
4298 adev
->chip_type
= CHIPTYPE_ACX111
;
4299 adev
->chip_name
= match
->name
;
4300 adev
->io
= IO_ACX111
;
4301 adev
->irq
= vlynq_virq_to_irq(vdev
, match
->irq
);
4303 acx_log(LOG_INFO
, L_ANY
, "found %s-based wireless network card at %s, "
4304 "irq:%d, phymem:0x%x, mem:0x%p\n",
4305 match
->name
, vdev
->dev
.bus_id
, adev
->irq
,
4306 vdev
->mem_start
, adev
->iobase
);
4307 // acx_log(LOG_INFO, L_ANY,
4308 // "initial debug setting is 0x%04X\n", acx_debug);
4310 if (0 == adev
->irq
) {
4311 acx_log(LOG_WARNING
, L_ANY
, "can't use IRQ 0\n");
4314 SET_IEEE80211_DEV(ieee
, &vdev
->dev
);
4316 /* request shared IRQ handler */
4318 (adev
->irq
, acxpci_i_interrupt
, IRQF_SHARED
, KBUILD_MODNAME
, adev
)) {
4319 acx_log(LOG_WARNING
, L_ANY
, "%s: request_irq FAILED\n",
4320 wiphy_name(adev
->ieee
->wiphy
));
4324 acx_log(LOG_DEBUG
, L_IRQ
| L_REALLYVERBOSE
,
4325 "request_irq %d successful\n", adev
->irq
);
4327 /* to find crashes due to weird driver access
4328 * to unconfigured interface (ifup) */
4329 adev
->mgmt_timer
.function
= (void (*)(unsigned long))0x0000dead;
4332 /* ok, pci setup is finished, now start initializing the card */
4334 /* NB: read_reg() reads may return bogus data before reset_dev(),
4335 * since the firmware which directly controls large parts of the I/O
4336 * registers isn't initialized yet.
4337 * acx100 seems to be more affected than acx111 */
4338 if (OK
!= acxpci_s_reset_dev(adev
))
4341 if (OK
!= acx_s_init_mac(adev
))
4344 acx_s_interrogate(adev
, &co
, ACX111_IE_CONFIG_OPTIONS
);
4345 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
4346 if (OK
!= acxpci_read_eeprom_byte(adev
, 0x05, &adev
->eeprom_version
))
4347 goto fail_read_eeprom_version
;
4349 acx_s_parse_configoption(adev
, &co
);
4350 acx_s_set_defaults(adev
);
4351 acx_s_get_firmware_version(adev
); /* needs to be after acx_s_init_mac() */
4352 acx_display_hardware_details(adev
);
4354 /* Register the card, AFTER everything else has been set up,
4355 * since otherwise an ioctl could step on our feet due to
4356 * firmware operations happening in parallel or uninitialized data */
4359 acx_proc_register_entries(ieee
);
4361 /* Now we have our device, so make sure the kernel doesn't try
4362 * to send packets even though we're not associated to a network yet */
4364 /* after register_netdev() userspace may start working with dev
4365 * (in particular, on other CPUs), we only need to up the sem */
4366 /* acx_sem_unlock(adev); */
4368 acx_log(LOG_INFO
, L_ANY
, "driver " ACX_RELEASE
", net device %s, "
4369 "driver compiled against wireless extensions %d and Linux %s\n",
4370 wiphy_name(adev
->ieee
->wiphy
), WIRELESS_EXT
, UTS_RELEASE
);
4372 MAC_COPY(adev
->ieee
->wiphy
->perm_addr
, adev
->dev_addr
);
4374 acx_log(LOG_DEBUG
, L_IRQ
| L_INIT
, "using IRQ %d\n", adev
->irq
);
4376 /** done with board specific setup **/
4378 result
= acx_setup_modes(adev
);
4380 acx_log(LOG_WARNING
, L_ANY
, "can't register hwmode\n");
4381 goto fail_register_netdev
;
4384 acx_init_task_scheduler(adev
);
4385 result
= ieee80211_register_hw(adev
->ieee
);
4387 acx_log(LOG_WARNING
, L_ANY
,
4388 "acx: ieee80211_register_hw() FAILED: %d\n", result
);
4389 goto fail_register_netdev
;
4392 great_inquisitor(adev
);
4398 /* error paths: undo everything in reverse order... */
4401 acxpci_s_delete_dma_regions(adev
);
4404 fail_read_eeprom_version
:
4410 iounmap(adev
->iobase
);
4413 release_mem_region(vdev
->mem_start
, vdev
->mem_end
- vdev
->mem_start
);
4414 fail_request_mem_region
:
4415 fail_register_netdev
:
4416 ieee80211_free_hw(ieee
);
4418 vlynq_disable_device(vdev
);
4424 static void vlynq_remove(struct vlynq_device
*vdev
)
4426 struct ieee80211_hw
*hw
= vlynq_get_drvdata(vdev
);
4427 acx_device_t
*adev
= ieee2adev(hw
);
4428 unsigned long flags
;
4432 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
4433 "%s: card is unused. Skipping any release code\n",
4439 acx_lock(adev
, flags
);
4440 acx_unlock(adev
, flags
);
4441 adev
->initialized
= 0;
4443 /* If device wasn't hot unplugged... */
4444 if (adev_present(adev
)) {
4448 /* disable both Tx and Rx to shut radio down properly */
4449 if (adev
->initialized
) {
4450 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_TX
, NULL
, 0);
4451 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_RX
, NULL
, 0);
4453 acx_lock(adev
, flags
);
4454 /* disable power LED to save power :-) */
4455 acx_log(LOG_INFO
, L_INIT
,
4456 "switching off power LED to save power\n");
4457 acxpci_l_power_led(adev
, 0);
4459 acx_unlock(adev
, flags
);
4461 acx_sem_unlock(adev
);
4464 /* unregister the device to not let the kernel
4465 * (e.g. ioctls) access a half-deconfigured device
4466 * NB: this will cause acxpci_e_close() to be called,
4467 * thus we shouldn't call it under sem!
4468 * Well, netdev did, but ieee80211 stack does not, so we
4469 * have to do so manually...
4472 acx_log(LOG_INFO
, L_INIT
, "removing device %s\n",
4473 wiphy_name(adev
->ieee
->wiphy
));
4474 ieee80211_unregister_hw(adev
->ieee
);
4476 /* unregister_netdev ensures that no references to us left.
4477 * For paranoid reasons we continue to follow the rules */
4480 if (adev
->dev_state_mask
& ACX_STATE_IFACE_UP
) {
4482 CLEAR_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
4485 acx_proc_unregister_entries(adev
->ieee
);
4487 /* finally, clean up PCI bus state */
4488 acxpci_s_delete_dma_regions(adev
);
4490 iounmap(adev
->iobase
);
4492 iounmap(adev
->iobase2
);
4493 release_mem_region(vdev
->mem_start
, vdev
->mem_end
- vdev
->mem_start
);
4495 /* remove dev registration */
4497 acx_sem_unlock(adev
);
4498 vlynq_disable_device(vdev
);
4500 /* Free netdev (quite late,
4501 * since otherwise we might get caught off-guard
4502 * by a netdev timeout handler execution
4503 * expecting to see a working dev...) */
4504 ieee80211_free_hw(adev
->ieee
);
4510 static struct vlynq_driver vlynq_acx
= {
4511 .name
= "acx_vlynq",
4512 .id_table
= acx_vlynq_id
,
4513 .probe
= vlynq_probe
,
4514 .remove
= __devexit_p(vlynq_remove
),
4516 #endif /* CONFIG_VLYNQ */
4519 /***********************************************************************
4520 ** Data for init_module/cleanup_module
4523 static const struct pci_device_id acxpci_id_tbl
[] __devinitdata
= {
4525 .vendor
= PCI_VENDOR_ID_TI
,
4526 .device
= PCI_DEVICE_ID_TI_TNETW1100A
,
4527 .subvendor
= PCI_ANY_ID
,
4528 .subdevice
= PCI_ANY_ID
,
4529 .driver_data
= CHIPTYPE_ACX100
,
4532 .vendor
= PCI_VENDOR_ID_TI
,
4533 .device
= PCI_DEVICE_ID_TI_TNETW1100B
,
4534 .subvendor
= PCI_ANY_ID
,
4535 .subdevice
= PCI_ANY_ID
,
4536 .driver_data
= CHIPTYPE_ACX100
,
4539 .vendor
= PCI_VENDOR_ID_TI
,
4540 .device
= PCI_DEVICE_ID_TI_TNETW1130
,
4541 .subvendor
= PCI_ANY_ID
,
4542 .subdevice
= PCI_ANY_ID
,
4543 .driver_data
= CHIPTYPE_ACX111
,
4554 MODULE_DEVICE_TABLE(pci
, acxpci_id_tbl
);
4556 static struct pci_driver
4559 .id_table
= acxpci_id_tbl
,
4560 .probe
= acxpci_e_probe
,
4561 .remove
= __devexit_p(acxpci_e_remove
),
4563 .suspend
= acxpci_e_suspend
,
4564 .resume
= acxpci_e_resume
4565 #endif /* CONFIG_PM */
4567 #endif /* CONFIG_PCI */
4569 /***********************************************************************
4570 ** acxpci_e_init_module
4572 ** Module initialization routine, called once at module load time
4574 int __init
acxpci_e_init_module(void)
4580 #if (ACX_IO_WIDTH==32)
4581 acx_log(LOG_INFO
, L_ANY
, "compiled to use 32bit I/O access. "
4582 "I/O timing issues might occur, such as "
4583 "non-working firmware upload. Report them\n");
4585 acx_log(LOG_INFO
, L_ANY
, "compiled to use 16bit I/O access only "
4586 "(compatibility mode)\n");
4589 #ifdef __LITTLE_ENDIAN
4590 #define ENDIANNESS_STRING "running on a little-endian CPU\n"
4592 #define ENDIANNESS_STRING "running on a BIG-ENDIAN CPU\n"
4594 acx_log(LOG_INFO
, L_INIT
, ENDIANNESS_STRING
);
4595 acx_log(LOG_INFO
, L_INIT
, "PCI/VLYNQ module " ACX_RELEASE
4596 " initialized, waiting for cards to probe...\n");
4599 res
= pci_register_driver(&acxpci_drv_id
);
4601 res
= vlynq_register_driver(&vlynq_acx
);
4608 /***********************************************************************
4609 ** acxpci_e_cleanup_module
4611 ** Called at module unload time. This is our last chance to
4612 ** clean up after ourselves.
4614 void __exit
acxpci_e_cleanup_module(void)
4619 pci_unregister_driver(&acxpci_drv_id
);
4621 vlynq_unregister_driver(&vlynq_acx
);
4623 acx_log(LOG_INFO
, L_INIT
,
4624 "PCI module " ACX_RELEASE
" unloaded\n");