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>
42 /***********************************************************************
45 #define PCI_TYPE (PCI_USES_MEM | PCI_ADDR0 | PCI_NO_ACPI_WAKE)
46 #define PCI_ACX100_REGION1 0x01
47 #define PCI_ACX100_REGION1_SIZE 0x1000 /* Memory size - 4K bytes */
48 #define PCI_ACX100_REGION2 0x02
49 #define PCI_ACX100_REGION2_SIZE 0x10000 /* Memory size - 64K bytes */
51 #define PCI_ACX111_REGION1 0x00
52 #define PCI_ACX111_REGION1_SIZE 0x2000 /* Memory size - 8K bytes */
53 #define PCI_ACX111_REGION2 0x01
54 #define PCI_ACX111_REGION2_SIZE 0x20000 /* Memory size - 128K bytes */
56 /* Texas Instruments Vendor ID */
57 #define PCI_VENDOR_ID_TI 0x104c
59 /* ACX100 22Mb/s WLAN controller */
60 #define PCI_DEVICE_ID_TI_TNETW1100A 0x8400
61 #define PCI_DEVICE_ID_TI_TNETW1100B 0x8401
63 /* ACX111 54Mb/s WLAN controller */
64 #define PCI_DEVICE_ID_TI_TNETW1130 0x9066
66 /* PCI Class & Sub-Class code, Network-'Other controller' */
67 #define PCI_CLASS_NETWORK_OTHERS 0x0280
69 #define CARD_EEPROM_ID_SIZE 6
72 /* From include/linux/pci.h */
79 #define PCI_POWER_ERROR -1
81 #endif /* CONFIG_PCI */
83 /***********************************************************************
86 static irqreturn_t
acxpci_i_interrupt(int irq
, void *dev_id
);
88 static void disable_acx_irq(acx_device_t
* adev
);
90 static int acxpci_e_open(struct ieee80211_hw
*hw
);
91 static void acxpci_e_close(struct ieee80211_hw
*hw
);
92 static void acxpci_s_up(struct ieee80211_hw
*hw
);
93 static void acxpci_s_down(struct ieee80211_hw
*hw
);
95 /* Handle PCI posting properly:
96 * Make sure that writes reach the adapter in case they require to be executed
97 * *before* the next write, by reading a random (and safely accessible) register.
98 * This call has to be made if there is no read following (which would flush the data
99 * to the adapter), yet the written data has to reach the adapter immediately. */
100 static inline void write_flush(acx_device_t
* adev
)
102 /* readb(adev->iobase + adev->io[ACX_IO_INFO_MAILBOX_OFFS]); */
103 /* faster version (accesses the first register, ACX_IO_SOFT_RESET,
104 * which should also be safe): */
105 //readb(adev->iobase);
109 static inline int adev_present(acx_device_t
* adev
)
111 /* fast version (accesses the first register, ACX_IO_SOFT_RESET,
112 * which should be safe): */
113 return acx_readl(adev
->iobase
) != 0xffffffff;
117 /***********************************************************************
119 static inline txdesc_t
*get_txdesc(acx_device_t
* adev
, int index
)
121 return (txdesc_t
*) (((u8
*) adev
->txdesc_start
) +
122 index
* adev
->txdesc_size
);
125 static inline txdesc_t
*advance_txdesc(acx_device_t
* adev
, txdesc_t
* txdesc
,
128 return (txdesc_t
*) (((u8
*) txdesc
) + inc
* adev
->txdesc_size
);
131 static txhostdesc_t
*get_txhostdesc(acx_device_t
* adev
, txdesc_t
* txdesc
)
133 int index
= (u8
*) txdesc
- (u8
*) adev
->txdesc_start
;
137 if (unlikely(ACX_DEBUG
&& (index
% adev
->txdesc_size
))) {
138 acx_log(LOG_WARNING
, L_ANY
, "bad txdesc ptr %p\n", txdesc
);
141 index
/= adev
->txdesc_size
;
142 if (unlikely(ACX_DEBUG
&& (index
>= TX_CNT
))) {
143 acx_log(LOG_WARNING
, L_ANY
, "bad txdesc ptr %p\n", txdesc
);
149 return &adev
->txhostdesc_start
[index
* 2];
156 /***********************************************************************
157 ** EEPROM and PHY read/write helpers
159 /***********************************************************************
160 ** acxpci_read_eeprom_byte
162 ** Function called to read an octet in the EEPROM.
164 ** This function is used by acxpci_e_probe to check if the
165 ** connected card is a legal one or not.
168 ** adev ptr to acx_device structure
169 ** addr address to read in the EEPROM
170 ** charbuf ptr to a char. This is where the read octet
174 int acxpci_read_eeprom_byte(acx_device_t
* adev
, u32 addr
, u8
* charbuf
)
181 write_reg32(adev
, ACX_IO_EEPROM_CFG
, 0);
182 write_reg32(adev
, ACX_IO_EEPROM_ADDR
, addr
);
184 write_reg32(adev
, ACX_IO_EEPROM_CTL
, 2);
187 while (read_reg16(adev
, ACX_IO_EEPROM_CTL
)) {
188 /* scheduling away instead of CPU burning loop
189 * doesn't seem to work here at all:
190 * awful delay, sometimes also failure.
191 * Doesn't matter anyway (only small delay). */
192 if (unlikely(!--count
)) {
193 acx_log(LOG_WARNING
, L_ANY
,
194 "%s: timeout waiting for EEPROM read\n",
195 wiphy_name(adev
->ieee
->wiphy
));
202 *charbuf
= read_reg8(adev
, ACX_IO_EEPROM_DATA
);
203 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "EEPROM at 0x%04X = 0x%02X\n",
213 /***********************************************************************
214 ** We don't lock hw accesses here since we never r/w eeprom in IRQ
215 ** Note: this function sleeps only because of GFP_KERNEL alloc
219 acxpci_s_write_eeprom(acx_device_t
* adev
, u32 addr
, u32 len
,
222 u8
*data_verify
= NULL
;
228 acx_log(LOG_WARNING
, L_ANY
, "WARNING! I would write to EEPROM now. "
229 "Since I really DON'T want to unless you know "
230 "what you're doing (THIS CODE WILL PROBABLY "
231 "NOT WORK YET!), I will abort that now. And "
232 "definitely make sure to make a "
233 "/proc/driver/acx_wlan0_eeprom backup copy first!!! "
234 "(the EEPROM content includes the PCI config header!! "
235 "If you kill important stuff, then you WILL "
236 "get in trouble and people DID get in trouble already)\n");
241 data_verify
= kmalloc(len
, GFP_KERNEL
);
246 /* first we need to enable the OE (EEPROM Output Enable) GPIO line
247 * to be able to write to the EEPROM.
248 * NOTE: an EEPROM writing success has been reported,
249 * but you probably have to modify GPIO_OUT, too,
250 * and you probably need to activate a different GPIO
252 gpio_orig
= read_reg16(adev
, ACX_IO_GPIO_OE
);
253 write_reg16(adev
, ACX_IO_GPIO_OE
, gpio_orig
& ~1);
256 /* ok, now start writing the data out */
257 for (i
= 0; i
< len
; i
++) {
258 write_reg32(adev
, ACX_IO_EEPROM_CFG
, 0);
259 write_reg32(adev
, ACX_IO_EEPROM_ADDR
, addr
+ i
);
260 write_reg32(adev
, ACX_IO_EEPROM_DATA
, *(charbuf
+ i
));
262 write_reg32(adev
, ACX_IO_EEPROM_CTL
, 1);
265 while (read_reg16(adev
, ACX_IO_EEPROM_CTL
)) {
266 if (unlikely(!--count
)) {
267 acx_log(LOG_WARNING
, L_ANY
, "WARNING, DANGER!!! "
268 "Timeout waiting for EEPROM write\n");
275 /* disable EEPROM writing */
276 write_reg16(adev
, ACX_IO_GPIO_OE
, gpio_orig
);
279 /* now start a verification run */
280 for (i
= 0; i
< len
; i
++) {
281 write_reg32(adev
, ACX_IO_EEPROM_CFG
, 0);
282 write_reg32(adev
, ACX_IO_EEPROM_ADDR
, addr
+ i
);
284 write_reg32(adev
, ACX_IO_EEPROM_CTL
, 2);
287 while (read_reg16(adev
, ACX_IO_EEPROM_CTL
)) {
288 if (unlikely(!--count
)) {
289 acx_log(LOG_WARNING
, L_ANY
,
290 "timeout waiting for EEPROM read\n");
296 data_verify
[i
] = read_reg16(adev
, ACX_IO_EEPROM_DATA
);
299 if (0 == memcmp(charbuf
, data_verify
, len
))
300 result
= OK
; /* read data matches, success */
310 /***********************************************************************
311 ** acxpci_s_read_phy_reg
313 ** Messing with rx/tx disabling and enabling here
314 ** (write_reg32(adev, ACX_IO_ENABLE, 0b000000xx)) kills traffic
316 int acxpci_s_read_phy_reg(acx_device_t
* adev
, u32 reg
, u8
* charbuf
)
323 write_reg32(adev
, ACX_IO_PHY_ADDR
, reg
);
325 write_reg32(adev
, ACX_IO_PHY_CTL
, 2);
328 while (read_reg32(adev
, ACX_IO_PHY_CTL
)) {
329 /* scheduling away instead of CPU burning loop
330 * doesn't seem to work here at all:
331 * awful delay, sometimes also failure.
332 * Doesn't matter anyway (only small delay). */
333 if (unlikely(!--count
)) {
334 acx_log(LOG_WARNING
, L_ANY
,
335 "%s: timeout waiting for phy read\n",
336 wiphy_name(adev
->ieee
->wiphy
));
343 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "count was %u\n", count
);
344 *charbuf
= read_reg8(adev
, ACX_IO_PHY_DATA
);
346 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "radio PHY at 0x%04X = 0x%02X\n",
349 goto fail
; /* silence compiler warning */
356 /***********************************************************************
358 int acxpci_s_write_phy_reg(acx_device_t
* adev
, u32 reg
, u8 value
)
362 /* mprusko said that 32bit accesses result in distorted sensitivity
363 * on his card. Unconfirmed, looks like it's not true (most likely since we
364 * now properly flush writes). */
365 write_reg32(adev
, ACX_IO_PHY_DATA
, value
);
366 write_reg32(adev
, ACX_IO_PHY_ADDR
, reg
);
368 write_reg32(adev
, ACX_IO_PHY_CTL
, 1);
370 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
371 "radio PHY write 0x%02X at 0x%04X\n",
379 #define NO_AUTO_INCREMENT 1
381 /***********************************************************************
384 ** Write the firmware image into the card.
387 ** adev wlan device structure
388 ** fw_image firmware image.
391 ** 1 firmware image corrupted
394 ** Standard csum implementation + write to IO
397 acxpci_s_write_fw(acx_device_t
* adev
, const firmware_image_t
*fw_image
,
402 /* we skip the first four bytes which contain the control sum */
404 const u8
*p
= (u8
*) fw_image
+ 4;
408 /* start the image checksum by adding the image size value */
409 sum
= p
[0] + p
[1] + p
[2] + p
[3];
412 write_reg32(adev
, ACX_IO_SLV_END_CTL
, 0);
414 #if NO_AUTO_INCREMENT
415 write_reg32(adev
, ACX_IO_SLV_MEM_CTL
, 0); /* use basic mode */
417 write_reg32(adev
, ACX_IO_SLV_MEM_CTL
, 1); /* use autoincrement mode */
418 write_reg32(adev
, ACX_IO_SLV_MEM_ADDR
, offset
); /* configure start address */
423 size
= le32_to_cpu(fw_image
->size
) & (~3);
425 while (likely(len
< size
)) {
426 v32
= be32_to_cpu(*(u32
*) p
);
427 sum
+= p
[0] + p
[1] + p
[2] + p
[3];
431 #if NO_AUTO_INCREMENT
432 write_reg32(adev
, ACX_IO_SLV_MEM_ADDR
, offset
+ len
- 4);
435 write_reg32(adev
, ACX_IO_SLV_MEM_DATA
, v32
);
438 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
439 "firmware written, size:%d sum1:%x sum2:%x\n",
440 size
, sum
, le32_to_cpu(fw_image
->chksum
));
442 /* compare our checksum with the stored image checksum */
443 FN_EXIT1(sum
!= le32_to_cpu(fw_image
->chksum
));
444 return (sum
!= le32_to_cpu(fw_image
->chksum
));
448 /***********************************************************************
449 ** acxpci_s_validate_fw
451 ** Compare the firmware image given with
452 ** the firmware image written into the card.
455 ** adev wlan device structure
456 ** fw_image firmware image.
459 ** NOT_OK firmware image corrupted or not correctly written
462 ** Origin: Standard csum + Read IO
465 acxpci_s_validate_fw(acx_device_t
* adev
, const firmware_image_t
*fw_image
,
471 /* we skip the first four bytes which contain the control sum */
472 const u8
*p
= (u8
*) fw_image
+ 4;
476 /* start the image checksum by adding the image size value */
477 sum
= p
[0] + p
[1] + p
[2] + p
[3];
480 write_reg32(adev
, ACX_IO_SLV_END_CTL
, 0);
482 #if NO_AUTO_INCREMENT
483 write_reg32(adev
, ACX_IO_SLV_MEM_CTL
, 0); /* use basic mode */
485 write_reg32(adev
, ACX_IO_SLV_MEM_CTL
, 1); /* use autoincrement mode */
486 write_reg32(adev
, ACX_IO_SLV_MEM_ADDR
, offset
); /* configure start address */
490 size
= le32_to_cpu(fw_image
->size
) & (~3);
492 while (likely(len
< size
)) {
493 v32
= be32_to_cpu(*(u32
*) p
);
497 #if NO_AUTO_INCREMENT
498 write_reg32(adev
, ACX_IO_SLV_MEM_ADDR
, offset
+ len
- 4);
500 w32
= read_reg32(adev
, ACX_IO_SLV_MEM_DATA
);
502 if (unlikely(w32
!= v32
)) {
503 acx_log(LOG_WARNING
, L_ANY
,"FATAL: firmware upload: "
504 "data parts at offset %d don't match "
505 "(0x%08X vs. 0x%08X)! I/O timing issues "
506 "or defective memory, with DWL-xx0+? "
507 "ACX_IO_WIDTH=16 may help. Please report\n",
514 (u8
) w32
+ (u8
) (w32
>> 8) + (u8
) (w32
>> 16) +
518 /* sum control verification */
519 if (result
!= NOT_OK
) {
520 if (sum
!= le32_to_cpu(fw_image
->chksum
)) {
521 acx_log(LOG_WARNING
, L_ANY
, "FATAL: firmware upload: "
522 "checksums don't match!\n");
532 /***********************************************************************
533 ** acxpci_s_upload_fw
535 ** Called from acx_reset_dev
537 ** Origin: Derived from FW dissection
539 static int acxpci_s_upload_fw(acx_device_t
* adev
)
541 firmware_image_t
*fw_image
= NULL
;
545 char filename
[sizeof("tiacx1NNcNN")];
549 /* print exact chipset and radio ID to make sure people
550 * really get a clue on which files exactly they need to provide.
551 * Firmware loading is a frequent end-user PITA with these chipsets.
553 acx_log(LOG_INFO
, L_ANY
,
554 "need firmware for acx1%02d chipset "
555 "with radio ID %02X\n",
556 IS_ACX111(adev
)*11, adev
->radio_type
);
557 acx_log(LOG_INFO
, L_ANY
, "Please provide via firmware hotplug:\n");
558 acx_log(LOG_INFO
, L_ANY
, "either combined firmware "
559 "(single file named 'tiacx1%02dc%02X')\n"
560 "or two files (base firmware file 'tiacx1%02d' "
561 "+ radio fw 'tiacx1%02dr%02X')\n",
562 IS_ACX111(adev
)*11, adev
->radio_type
,
564 IS_ACX111(adev
)*11, adev
->radio_type
567 /* print exact chipset and radio ID to make sure people really get a
568 * clue on which files exactly they are supposed to provide, since
569 * firmware loading is the biggest enduser PITA with these chipsets.
570 * Not printing radio ID in 0xHEX in order to not confuse them into
572 * COMMENTED OUT: this was already printed above
574 // printk( "acx: need to load firmware for acx1%02d chipset with radio ID %02x, please provide via firmware hotplug:\n"
575 // "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",
576 // IS_ACX111(adev)*11, adev->radio_type);
578 /* Try combined, then main image */
579 adev
->need_radio_fw
= 0;
580 snprintf(filename
, sizeof(filename
), "tiacx1%02dc%02X",
581 IS_ACX111(adev
) * 11, adev
->radio_type
);
583 fw_image
= acx_s_read_fw(adev
->bus_dev
, filename
, &file_size
);
585 adev
->need_radio_fw
= 1;
586 filename
[sizeof("tiacx1NN") - 1] = '\0';
588 acx_s_read_fw(adev
->bus_dev
, filename
, &file_size
);
595 for (try = 1; try <= 5; try++) {
596 res
= acxpci_s_write_fw(adev
, fw_image
, 0);
597 acx_log(LOG_DEBUG
, L_INIT
| L_REALLYVERBOSE
,
598 "acx_write_fw (main/combined): %d\n", res
);
600 res
= acxpci_s_validate_fw(adev
, fw_image
, 0);
601 acx_log(LOG_DEBUG
, L_INIT
| L_REALLYVERBOSE
,
602 "acx_validate_fw (main/combined): %d\n", res
);
606 SET_BIT(adev
->dev_state_mask
, ACX_STATE_FW_LOADED
);
609 acx_log(LOG_WARNING
, L_ANY
,
610 "firmware upload attempt #%d FAILED, "
611 "retrying...\n", try);
612 acx_s_mwait(1000); /* better wait for a while... */
622 /***********************************************************************
623 ** acxpci_s_upload_radio
625 ** Uploads the appropriate radio module firmware into the card.
627 ** Origin: Standard Read/Write to IO
629 int acxpci_s_upload_radio(acx_device_t
* adev
)
632 firmware_image_t
*radio_image
;
633 acx_cmd_radioinit_t radioinit
;
638 char filename
[sizeof("tiacx1NNrNN")];
640 if (!adev
->need_radio_fw
)
645 acx_s_interrogate(adev
, &mm
, ACX1xx_IE_MEMORY_MAP
);
646 offset
= le32_to_cpu(mm
.CodeEnd
);
648 snprintf(filename
, sizeof(filename
), "tiacx1%02dr%02X",
649 IS_ACX111(adev
) * 11, adev
->radio_type
);
650 radio_image
= acx_s_read_fw(adev
->bus_dev
, filename
, &size
);
652 acx_log(LOG_WARNING
, L_ANY
, "can't load radio module '%s'\n",
657 acx_s_issue_cmd(adev
, ACX1xx_CMD_SLEEP
, NULL
, 0);
659 for (try = 1; try <= 5; try++) {
660 res
= acxpci_s_write_fw(adev
, radio_image
, offset
);
661 acx_log(LOG_DEBUG
, L_INIT
| L_REALLYVERBOSE
,
662 "acx_write_fw (radio): %d\n", res
);
664 res
= acxpci_s_validate_fw(adev
, radio_image
, offset
);
665 acx_log(LOG_DEBUG
, L_INIT
| L_REALLYVERBOSE
,
666 "acx_validate_fw (radio): %d\n", res
);
671 acx_log(LOG_WARNING
, L_ANY
,
672 "radio firmware upload attempt #%d FAILED, "
673 "retrying...\n", try);
674 acx_s_mwait(1000); /* better wait for a while... */
677 acx_s_issue_cmd(adev
, ACX1xx_CMD_WAKE
, NULL
, 0);
678 radioinit
.offset
= cpu_to_le32(offset
);
679 /* no endian conversion needed, remains in card CPU area: */
680 radioinit
.len
= radio_image
->size
;
687 /* will take a moment so let's have a big timeout */
688 acx_s_issue_cmd_timeo(adev
, ACX1xx_CMD_RADIOINIT
,
689 &radioinit
, sizeof(radioinit
),
690 CMD_TIMEOUT_MS(1000));
692 res
= acx_s_interrogate(adev
, &mm
, ACX1xx_IE_MEMORY_MAP
);
699 /***********************************************************************
700 ** acxpci_l_reset_mac
703 ** Call context: reset_dev
705 ** Origin: Standard Read/Write to IO
707 static void acxpci_l_reset_mac(acx_device_t
* adev
)
714 temp
= read_reg16(adev
, ACX_IO_ECPU_CTRL
) | 0x1;
715 write_reg16(adev
, ACX_IO_ECPU_CTRL
, temp
);
717 /* now do soft reset of eCPU, set bit */
718 temp
= read_reg16(adev
, ACX_IO_SOFT_RESET
) | 0x1;
719 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "enable soft reset\n");
720 write_reg16(adev
, ACX_IO_SOFT_RESET
, temp
);
723 /* now clear bit again: deassert eCPU reset */
724 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
725 "disable soft reset and go to init mode\n");
726 write_reg16(adev
, ACX_IO_SOFT_RESET
, temp
& ~0x1);
728 /* now start a burst read from initial EEPROM */
729 temp
= read_reg16(adev
, ACX_IO_EE_START
) | 0x1;
730 write_reg16(adev
, ACX_IO_EE_START
, temp
);
737 /***********************************************************************
738 ** acxpci_s_verify_init
740 static int acxpci_s_verify_init(acx_device_t
* adev
)
743 unsigned long timeout
;
747 timeout
= jiffies
+ 2 * HZ
;
749 u16 irqstat
= read_reg16(adev
, ACX_IO_IRQ_STATUS_NON_DES
);
750 if (irqstat
& ACX_IRQ_FCS_THRESHOLD
) {
752 write_reg16(adev
, ACX_IO_IRQ_ACK
,
753 ACX_IRQ_FCS_THRESHOLD
);
756 if (time_after(jiffies
, timeout
))
758 /* Init may take up to ~0.5 sec total */
767 /***********************************************************************
768 ** A few low-level helpers
770 ** Note: these functions are not protected by lock
771 ** and thus are never allowed to be called from IRQ.
772 ** Also they must not race with fw upload which uses same hw regs
775 /***********************************************************************
776 ** acxpci_write_cmd_type_status
778 ** Origin: Common linux implementation
782 acxpci_write_cmd_type_status(acx_device_t
* adev
, u16 type
, u16 status
)
785 acx_writel(type
| (status
<< 16), adev
->cmd_area
);
791 /***********************************************************************
792 ** acxpci_read_cmd_type_status
794 ** Origin: Common linux implementation
796 static u32
acxpci_read_cmd_type_status(acx_device_t
* adev
)
798 u32 cmd_type
, cmd_status
;
802 cmd_type
= acx_readl(adev
->cmd_area
);
803 cmd_status
= (cmd_type
>> 16);
804 cmd_type
= (u16
) cmd_type
;
806 acx_log(LOG_DEBUG
, L_CTL
, "cmd_type:%04X cmd_status:%04X [%s]\n",
807 cmd_type
, cmd_status
, acx_cmd_status_str(cmd_status
));
809 FN_EXIT1(cmd_status
);
814 /***********************************************************************
815 ** acxpci_s_reset_dev
818 ** netdevice that contains the adev variable
823 ** device is hard reset
827 ** This resets the device using low level hardware calls
828 ** as well as uploads and verifies the firmware to the card
831 static inline void init_mboxes(acx_device_t
* adev
)
833 u32 cmd_offs
, info_offs
;
837 cmd_offs
= read_reg32(adev
, ACX_IO_CMD_MAILBOX_OFFS
);
838 info_offs
= read_reg32(adev
, ACX_IO_INFO_MAILBOX_OFFS
);
839 adev
->cmd_area
= (u8
*) adev
->iobase2
+ cmd_offs
;
840 adev
->info_area
= (u8
*) adev
->iobase2
+ info_offs
;
841 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "iobase2=%p\n", adev
->iobase2
);
842 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "cmd_mbox_offset=%X cmd_area=%p\n",
843 cmd_offs
, adev
->cmd_area
);
844 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
845 "info_mbox_offset=%X info_area=%p\n",
846 info_offs
, adev
->info_area
);
851 static inline void read_eeprom_area(acx_device_t
* adev
)
859 for (offs
= 0x8c; offs
< 0xb9; offs
++)
860 acxpci_read_eeprom_byte(adev
, offs
, &tmp
);
867 int acxpci_s_reset_dev(acx_device_t
* adev
)
869 const char *msg
= "";
878 /* reset the device to make sure the eCPU is stopped
879 * to upload the firmware correctly */
881 acx_lock(adev
, flags
);
884 acxpci_l_reset_mac(adev
);
887 ecpu_ctrl
= read_reg16(adev
, ACX_IO_ECPU_CTRL
) & 1;
889 msg
= "eCPU is already running. ";
893 if (read_reg16(adev
, ACX_IO_SOR_CFG
) & 2) {
894 /* eCPU most likely means "embedded CPU" */
895 msg
= "eCPU did not start after boot from flash. ";
899 /* check sense on reset flags */
900 if (read_reg16(adev
, ACX_IO_SOR_CFG
) & 0x10) {
901 printk("%s: eCPU did not start after boot (SOR), "
902 "is this fatal?\n", wiphy_name(adev
->ieee
->wiphy
));
905 /* scan, if any, is stopped now, setting corresponding IRQ bit */
906 SET_BIT(adev
->irq_status
, ACX_IRQ_SCAN_COMPLETE
);
908 acx_unlock(adev
, flags
);
910 /* need to know radio type before fw load */
911 /* Need to wait for arrival of this information in a loop,
912 * most probably since eCPU runs some init code from EEPROM
913 * (started burst read in reset_mac()) which also
914 * sets the radio type ID */
918 hardware_info
= read_reg16(adev
, ACX_IO_EEPROM_INFORMATION
);
920 msg
= "eCPU didn't indicate radio type";
924 } while (!(hardware_info
& 0xff00)); /* radio type still zero? */
926 /* printk("DEBUG: count %d\n", count); */
927 adev
->form_factor
= hardware_info
& 0xff;
928 adev
->radio_type
= hardware_info
>> 8;
930 /* load the firmware */
931 if (OK
!= acxpci_s_upload_fw(adev
))
934 /* acx_s_mwait(10); this one really shouldn't be required */
936 /* now start eCPU by clearing bit */
937 write_reg16(adev
, ACX_IO_ECPU_CTRL
, ecpu_ctrl
& ~0x1);
938 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
939 "booted eCPU up and waiting for completion...\n");
941 /* wait for eCPU bootup */
942 if (OK
!= acxpci_s_verify_init(adev
)) {
943 msg
= "timeout waiting for eCPU. ";
946 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
947 "eCPU has woken up, card is ready to be configured\n");
950 acxpci_write_cmd_type_status(adev
, 0, 0);
952 /* test that EEPROM is readable */
953 read_eeprom_area(adev
);
958 /* Finish error message. Indicate which function failed */
960 acx_unlock(adev
, flags
);
962 acx_log(LOG_WARNING
, L_ANY
, "%sreset_dev() FAILED\n", msg
);
969 /***********************************************************************
970 ** acxpci_s_issue_cmd_timeo
972 ** Sends command to fw, extract result
974 ** NB: we do _not_ take lock inside, so be sure to not touch anything
975 ** which may interfere with IRQ handler operation
977 ** TODO: busy wait is a bit silly, so:
978 ** 1) stop doing many iters - go to sleep after first
979 ** 2) go to waitqueue based approach: wait, not poll!
982 #define FUNC "issue_cmd"
986 acxpci_s_issue_cmd_timeo(acx_device_t
* adev
,
988 void *buffer
, unsigned buflen
, unsigned cmd_timeout
)
992 acxpci_s_issue_cmd_timeo_debug(acx_device_t
* adev
,
996 unsigned cmd_timeout
, const char *cmdstr
)
998 unsigned long start
= jiffies
;
1000 const char *devname
;
1004 unsigned long timeout
;
1008 devname
= wiphy_name(adev
->ieee
->wiphy
);
1009 if (!devname
|| !devname
[0] || devname
[4] == '%')
1012 acx_log(LOG_DEBUG
, L_CTL
,
1013 FUNC
"(cmd:%s,buflen:%u,timeout:%ums,type:0x%04X)\n",
1014 cmdstr
, buflen
, cmd_timeout
,
1015 buffer
? le16_to_cpu(((acx_ie_generic_t
*) buffer
)->type
) : -1);
1017 if (!(adev
->dev_state_mask
& ACX_STATE_FW_LOADED
)) {
1018 acx_log(LOG_WARNING
, L_ANY
,
1019 "%s: " FUNC
"(): firmware is not loaded yet, "
1020 "cannot execute commands!\n", devname
);
1024 if (cmd
!= ACX1xx_CMD_INTERROGATE
)
1025 acx_log_dump(LOG_DEBUG
, L_REALLYVERBOSE
, buffer
, buflen
,
1028 /* wait for firmware to become idle for our command submission */
1030 counter
= (timeout
* 1000 / HZ
) - 1; /* in ms */
1033 cmd_status
= acxpci_read_cmd_type_status(adev
);
1034 /* Test for IDLE state */
1037 if (counter
% 8 == 0) {
1038 if (time_after(jiffies
, timeout
)) {
1042 /* we waited 8 iterations, no luck. Sleep 8 ms */
1045 } while (likely(--counter
));
1048 /* the card doesn't get idle, we're in trouble */
1049 acx_log(LOG_WARNING
, L_ANY
,
1050 "%s: " FUNC
"(): cmd_status is not IDLE: 0x%04X!=0\n",
1051 devname
, cmd_status
);
1053 } else if (counter
< 190) { /* if waited >10ms... */
1054 acx_log(LOG_DEBUG
, L_CTL
| L_REALLYVERBOSE
,
1055 FUNC
"(): waited for IDLE %dms. "
1056 "Please report\n", 199 - counter
);
1059 /* now write the parameters of the command if needed */
1060 if (buffer
&& buflen
) {
1061 /* if it's an INTERROGATE command, just pass the length
1062 * of parameters to read, as data */
1064 if (cmd
== ACX1xx_CMD_INTERROGATE
)
1065 memset_io(adev
->cmd_area
+ 4, 0xAA, buflen
);
1067 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1068 memcpy_toio(adev
->cmd_area
+ 4, buffer
,
1069 (cmd
== ACX1xx_CMD_INTERROGATE
) ? 4 : buflen
);
1071 /* now write the actual command type */
1072 acxpci_write_cmd_type_status(adev
, cmd
, 0);
1073 /* execute command */
1074 write_reg16(adev
, ACX_IO_INT_TRIG
, INT_TRIG_CMD
);
1077 /* wait for firmware to process command */
1079 /* Ensure nonzero and not too large timeout.
1080 ** Also converts e.g. 100->99, 200->199
1081 ** which is nice but not essential */
1082 cmd_timeout
= (cmd_timeout
- 1) | 1;
1083 if (unlikely(cmd_timeout
> 1199))
1085 /* clear CMD_COMPLETE bit. can be set only by IRQ handler: */
1086 CLEAR_BIT(adev
->irq_status
, ACX_IRQ_CMD_COMPLETE
);
1087 /* we schedule away sometimes (timeout can be large) */
1088 counter
= cmd_timeout
;
1089 timeout
= jiffies
+ HZ
;
1091 if (!adev
->irqs_active
) { /* IRQ disabled: poll */
1092 irqtype
= read_reg16(adev
, ACX_IO_IRQ_STATUS_NON_DES
);
1093 if (irqtype
& ACX_IRQ_CMD_COMPLETE
) {
1094 write_reg16(adev
, ACX_IO_IRQ_ACK
,
1095 ACX_IRQ_CMD_COMPLETE
);
1098 } else { /* Wait when IRQ will set the bit */
1099 irqtype
= adev
->irq_status
;
1100 if (irqtype
& ACX_IRQ_CMD_COMPLETE
)
1104 if (counter
% 8 == 0) {
1105 if (time_after(jiffies
, timeout
)) {
1109 /* we waited 8 iterations, no luck. Sleep 8 ms */
1112 } while (likely(--counter
));
1114 /* save state for debugging */
1115 cmd_status
= acxpci_read_cmd_type_status(adev
);
1117 /* put the card in IDLE state */
1118 acxpci_write_cmd_type_status(adev
, 0, 0);
1120 if ((cmd_timeout
- counter
) == 0) { /* timed out! */
1121 acx_log(LOG_WARNING
, L_ANY
,
1122 "%s: " FUNC
"(): timed out %s for CMD_COMPLETE. "
1123 "irq bits:0x%04X irq_status:0x%04X timeout:%dms "
1124 "cmd_status:%d (%s)\n",
1125 devname
, (adev
->irqs_active
) ? "waiting" : "polling",
1126 irqtype
, adev
->irq_status
, cmd_timeout
,
1127 cmd_status
, acx_cmd_status_str(cmd_status
));
1128 acx_log(LOG_WARNING
, L_ANY
, "hack: don't do: 'goto bad;' "
1129 "counter: %d, cmd_timeout: %d, "
1130 "cmd_timeout-counter: %d\n",
1131 counter
, cmd_timeout
, cmd_timeout
- counter
);
1132 } else if (counter
== 0) { /* maybe timed out! */
1133 acx_log(LOG_DEBUG
, L_CTL
| L_REALLYVERBOSE
,
1134 FUNC
"(): %s for CMD_COMPLETE %dms. "
1135 "count:%d. Please report\n",
1136 (adev
->irqs_active
) ? "waited" : "polled",
1137 cmd_timeout
- counter
, counter
);
1138 } else if ((cmd_timeout
- counter
) > 30) { /* if waited >30ms... */
1139 acx_log(LOG_DEBUG
, L_CTL
| L_REALLYVERBOSE
,
1140 FUNC
"(): %s for CMD_COMPLETE %dms. "
1141 "count:%d. Please report\n",
1142 (adev
->irqs_active
) ? "waited" : "polled",
1143 cmd_timeout
- counter
, counter
);
1146 if (1 != cmd_status
) { /* it is not a 'Success' */
1147 acx_log(LOG_WARNING
, L_ANY
,
1148 "%s: " FUNC
"(): cmd_status is not SUCCESS: %d (%s). "
1149 "Took %dms of %d\n",
1150 devname
, cmd_status
, acx_cmd_status_str(cmd_status
),
1151 cmd_timeout
- counter
, cmd_timeout
);
1152 /* zero out result buffer
1153 * WARNING: this will trash stack in case of illegally large input
1155 if (buffer
&& buflen
)
1156 memset(buffer
, 0, buflen
);
1160 /* read in result parameters if needed */
1161 if (buffer
&& buflen
&& (cmd
== ACX1xx_CMD_INTERROGATE
)) {
1162 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1163 memcpy_fromio(buffer
, adev
->cmd_area
+ 4, buflen
);
1164 acx_log_dump(LOG_DEBUG
, L_REALLYVERBOSE
, buffer
, buflen
,
1165 "output buffer:\n");
1168 acx_log(LOG_DEBUG
, L_CTL
, FUNC
"(%s): took %ld jiffies to complete\n",
1169 cmdstr
, jiffies
- start
);
1174 /* Give enough info so that callers can avoid
1175 ** printing their own diagnostic messages */
1177 acx_log(LOG_WARNING
, L_ANY
,
1178 "%s: " FUNC
"(cmd:%s) FAILED\n", devname
, cmdstr
);
1180 acx_log(LOG_WARNING
, L_ANY
,
1181 "%s: " FUNC
"(cmd:0x%04X) FAILED\n", devname
, cmd
);
1189 /***********************************************************************
1191 #ifdef NONESSENTIAL_FEATURES
1192 typedef struct device_id
{
1193 unsigned char id
[6];
1198 static const device_id_t device_ids
[] = {
1200 {'G', 'l', 'o', 'b', 'a', 'l'},
1205 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
1207 "SpeedStream SS1021 or Gigafast WF721-AEX"},
1209 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85},
1211 "DrayTek Vigor 520"},
1213 {'?', '?', '?', '?', '?', '?'},
1215 "Level One WPC-0200"},
1217 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1222 static void acx_show_card_eeprom_id(acx_device_t
* adev
)
1224 unsigned char buffer
[CARD_EEPROM_ID_SIZE
];
1229 memset(&buffer
, 0, CARD_EEPROM_ID_SIZE
);
1230 /* use direct EEPROM access */
1231 for (i
= 0; i
< CARD_EEPROM_ID_SIZE
; i
++) {
1232 if (OK
!= acxpci_read_eeprom_byte(adev
,
1233 ACX100_EEPROM_ID_OFFSET
+ i
,
1235 acx_log(LOG_DEBUG
, L_ANY
, "reading EEPROM FAILED\n");
1240 for (i
= 0; i
< ARRAY_SIZE(device_ids
); i
++) {
1241 if (memcmp(&buffer
, device_ids
[i
].id
, CARD_EEPROM_ID_SIZE
))
1243 if (device_ids
[i
].descr
) {
1244 acx_log(LOG_INFO
, L_ANY
,
1245 "EEPROM card ID string check "
1246 "found %s card ID: is this %s?\n",
1247 device_ids
[i
].descr
,
1248 device_ids
[i
].type
);
1252 if (i
== ARRAY_SIZE(device_ids
)) {
1253 acx_log(LOG_WARNING
, L_ANY
,
1254 "EEPROM card ID string check found "
1255 "unknown card: expected 'Global', got '%.*s\'. "
1256 "Please report\n", CARD_EEPROM_ID_SIZE
, buffer
);
1260 #endif /* NONESSENTIAL_FEATURES */
1263 /***********************************************************************
1264 ** acxpci_free_desc_queues
1266 ** Releases the queues that have been allocated, the
1267 ** others have been initialised to NULL so this
1268 ** function can be used if only part of the queues were allocated.
1272 free_coherent(struct pci_dev
*hwdev
, size_t size
,
1273 void *vaddr
, dma_addr_t dma_handle
)
1275 dma_free_coherent(hwdev
== NULL
? NULL
: &hwdev
->dev
,
1276 size
, vaddr
, dma_handle
);
1280 void acxpci_free_desc_queues(acx_device_t
* adev
)
1282 unsigned long flags
;
1284 #define ACX_FREE_QUEUE(size, ptr, phyaddr) \
1286 free_coherent(NULL, size, ptr, phyaddr); \
1293 ACX_FREE_QUEUE(adev
->txhostdesc_area_size
, adev
->txhostdesc_start
,
1294 adev
->txhostdesc_startphy
);
1295 ACX_FREE_QUEUE(adev
->txbuf_area_size
, adev
->txbuf_start
,
1296 adev
->txbuf_startphy
);
1298 acx_lock(adev
, flags
);
1299 adev
->txdesc_start
= NULL
;
1300 acx_unlock(adev
, flags
);
1302 ACX_FREE_QUEUE(adev
->rxhostdesc_area_size
, adev
->rxhostdesc_start
,
1303 adev
->rxhostdesc_startphy
);
1304 ACX_FREE_QUEUE(adev
->rxbuf_area_size
, adev
->rxbuf_start
,
1305 adev
->rxbuf_startphy
);
1307 acx_lock(adev
, flags
);
1308 adev
->rxdesc_start
= NULL
;
1309 acx_unlock(adev
, flags
);
1315 /***********************************************************************
1316 ** acxpci_s_delete_dma_regions
1318 static void acxpci_s_delete_dma_regions(acx_device_t
* adev
)
1321 /* disable radio Tx/Rx. Shouldn't we use the firmware commands
1322 * here instead? Or are we that much down the road that it's no
1323 * longer possible here? */
1324 write_reg16(adev
, ACX_IO_ENABLE
, 0);
1328 /* NO locking for all parts of acxpci_free_desc_queues because:
1329 * while calling dma_free_coherent() interrupts need to be 'free'
1330 * but if you spinlock the whole function (acxpci_free_desc_queues)
1331 * you'll get an error */
1332 acxpci_free_desc_queues(adev
);
1338 /***********************************************************************
1341 ** Probe routine called when a PCI device w/ matching ID is found.
1342 ** Here's the sequence:
1343 ** - Allocate the PCI resources.
1344 ** - Read the PCMCIA attribute memory to make sure we have a WLAN card
1346 ** - Initialize the dev and wlan data
1347 ** - Initialize the MAC
1349 ** pdev - ptr to pci device structure containing info about pci configuration
1350 ** id - ptr to the device id entry that matched this device
1352 static const u16 IO_ACX100
[] = {
1353 0x0000, /* ACX_IO_SOFT_RESET */
1355 0x0014, /* ACX_IO_SLV_MEM_ADDR */
1356 0x0018, /* ACX_IO_SLV_MEM_DATA */
1357 0x001c, /* ACX_IO_SLV_MEM_CTL */
1358 0x0020, /* ACX_IO_SLV_END_CTL */
1360 0x0034, /* ACX_IO_FEMR */
1362 0x007c, /* ACX_IO_INT_TRIG */
1363 0x0098, /* ACX_IO_IRQ_MASK */
1364 0x00a4, /* ACX_IO_IRQ_STATUS_NON_DES */
1365 0x00a8, /* ACX_IO_IRQ_REASON */
1366 0x00ac, /* ACX_IO_IRQ_ACK */
1367 0x00b0, /* ACX_IO_HINT_TRIG */
1369 0x0104, /* ACX_IO_ENABLE */
1371 0x0250, /* ACX_IO_EEPROM_CTL */
1372 0x0254, /* ACX_IO_EEPROM_ADDR */
1373 0x0258, /* ACX_IO_EEPROM_DATA */
1374 0x025c, /* ACX_IO_EEPROM_CFG */
1376 0x0268, /* ACX_IO_PHY_ADDR */
1377 0x026c, /* ACX_IO_PHY_DATA */
1378 0x0270, /* ACX_IO_PHY_CTL */
1380 0x0290, /* ACX_IO_GPIO_OE */
1382 0x0298, /* ACX_IO_GPIO_OUT */
1384 0x02a4, /* ACX_IO_CMD_MAILBOX_OFFS */
1385 0x02a8, /* ACX_IO_INFO_MAILBOX_OFFS */
1386 0x02ac, /* ACX_IO_EEPROM_INFORMATION */
1388 0x02d0, /* ACX_IO_EE_START */
1389 0x02d4, /* ACX_IO_SOR_CFG */
1390 0x02d8 /* ACX_IO_ECPU_CTRL */
1393 static const u16 IO_ACX111
[] = {
1394 0x0000, /* ACX_IO_SOFT_RESET */
1396 0x0014, /* ACX_IO_SLV_MEM_ADDR */
1397 0x0018, /* ACX_IO_SLV_MEM_DATA */
1398 0x001c, /* ACX_IO_SLV_MEM_CTL */
1399 0x0020, /* ACX_IO_SLV_END_CTL */
1401 0x0034, /* ACX_IO_FEMR */
1403 0x00b4, /* ACX_IO_INT_TRIG */
1404 0x00d4, /* ACX_IO_IRQ_MASK */
1405 /* we do mean NON_DES (0xf0), not NON_DES_MASK which is at 0xe0: */
1406 0x00f0, /* ACX_IO_IRQ_STATUS_NON_DES */
1407 0x00e4, /* ACX_IO_IRQ_REASON */
1408 0x00e8, /* ACX_IO_IRQ_ACK */
1409 0x00ec, /* ACX_IO_HINT_TRIG */
1411 0x01d0, /* ACX_IO_ENABLE */
1413 0x0338, /* ACX_IO_EEPROM_CTL */
1414 0x033c, /* ACX_IO_EEPROM_ADDR */
1415 0x0340, /* ACX_IO_EEPROM_DATA */
1416 0x0344, /* ACX_IO_EEPROM_CFG */
1418 0x0350, /* ACX_IO_PHY_ADDR */
1419 0x0354, /* ACX_IO_PHY_DATA */
1420 0x0358, /* ACX_IO_PHY_CTL */
1422 0x0374, /* ACX_IO_GPIO_OE */
1424 0x037c, /* ACX_IO_GPIO_OUT */
1426 0x0388, /* ACX_IO_CMD_MAILBOX_OFFS */
1427 0x038c, /* ACX_IO_INFO_MAILBOX_OFFS */
1428 0x0390, /* ACX_IO_EEPROM_INFORMATION */
1430 0x0100, /* ACX_IO_EE_START */
1431 0x0104, /* ACX_IO_SOR_CFG */
1432 0x0108, /* ACX_IO_ECPU_CTRL */
1435 static const struct ieee80211_ops acxpci_hw_ops
= {
1436 .tx
= acx_i_start_xmit
,
1437 .conf_tx
= acx_net_conf_tx
,
1438 .add_interface
= acx_add_interface
,
1439 .remove_interface
= acx_remove_interface
,
1440 .start
= acxpci_e_open
,
1441 .configure_filter
= acx_i_set_multicast_list
,
1442 .stop
= acxpci_e_close
,
1443 .config
= acx_net_config
,
1444 .config_interface
= acx_config_interface
,
1445 .set_key
= acx_net_set_key
,
1446 .get_stats
= acx_e_get_stats
,
1447 .get_tx_stats
= acx_net_get_tx_stats
,
1452 static int __devinit
1453 acxpci_e_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1455 acx111_ie_configoption_t co
;
1456 unsigned long mem_region1
= 0;
1457 unsigned long mem_region2
= 0;
1458 unsigned long mem_region1_size
;
1459 unsigned long mem_region2_size
;
1460 unsigned long phymem1
;
1461 unsigned long phymem2
;
1464 acx_device_t
*adev
= NULL
;
1465 const char *chip_name
;
1469 struct ieee80211_hw
*ieee
;
1473 ieee
= ieee80211_alloc_hw(sizeof(struct acx_device
), &acxpci_hw_ops
);
1475 acx_log(LOG_WARNING
, L_ANY
,
1476 "could not allocate ieee80211 structure %s\n",
1478 goto fail_alloc_netdev
;
1480 ieee
->flags
&= ~IEEE80211_HW_RX_INCLUDES_FCS
;
1481 /* TODO: mainline doesn't support the following flags yet */
1483 ~IEEE80211_HW_MONITOR_DURING_OPER &
1484 ~IEEE80211_HW_WEP_INCLUDE_IV;
1488 adev
= ieee2adev(ieee
);
1490 memset(adev
, 0, sizeof(*adev
));
1491 /** Set up our private interface **/
1492 spin_lock_init(&adev
->spinlock
);
1493 spin_lock_init(&adev
->irqlock
);
1494 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
1495 acx_log(LOG_INFO
, L_ANY
,
1496 "mutex_init(&adev->mutex); // adev = 0x%px\n", adev
);
1497 mutex_init(&adev
->mutex
);
1498 /* since nobody can see new netdev yet, we can as well
1499 ** just _presume_ that we're under sem (instead of actually taking it): */
1500 /* acx_sem_lock(adev); */
1503 adev
->bus_dev
= &pdev
->dev
;
1504 adev
->dev_type
= DEVTYPE_PCI
;
1506 /** Finished with private interface **/
1508 /** begin board specific inits **/
1509 pci_set_drvdata(pdev
, ieee
);
1511 /* Enable the PCI device */
1512 if (pci_enable_device(pdev
)) {
1513 acx_log(LOG_WARNING
, L_ANY
, "pci_enable_device() FAILED\n");
1515 goto fail_pci_enable_device
;
1518 /* enable busmastering (required for CardBus) */
1519 pci_set_master(pdev
);
1522 /* chiptype is u8 but id->driver_data is ulong
1523 ** Works for now (possible values are 1 and 2) */
1524 chip_type
= (u8
) id
->driver_data
;
1525 /* acx100 and acx111 have different PCI memory regions */
1526 if (chip_type
== CHIPTYPE_ACX100
) {
1527 chip_name
= "ACX100";
1528 mem_region1
= PCI_ACX100_REGION1
;
1529 mem_region1_size
= PCI_ACX100_REGION1_SIZE
;
1531 mem_region2
= PCI_ACX100_REGION2
;
1532 mem_region2_size
= PCI_ACX100_REGION2_SIZE
;
1533 } else if (chip_type
== CHIPTYPE_ACX111
) {
1534 chip_name
= "ACX111";
1535 mem_region1
= PCI_ACX111_REGION1
;
1536 mem_region1_size
= PCI_ACX111_REGION1_SIZE
;
1538 mem_region2
= PCI_ACX111_REGION2
;
1539 mem_region2_size
= PCI_ACX111_REGION2_SIZE
;
1541 acx_log(LOG_WARNING
, L_ANY
,
1542 "unknown chip type 0x%04X\n", chip_type
);
1543 goto fail_unknown_chiptype
;
1546 /* Figure out our resources
1548 * Request our PCI IO regions
1550 err
= pci_request_region(pdev
, mem_region1
, "acx_1");
1552 acx_log(LOG_WARNING
, L_ANY
, "pci_request_region (1/2) FAILED!"
1553 "No cardbus support in kernel?\n");
1554 goto fail_request_mem_region1
;
1557 phymem1
= pci_resource_start(pdev
, mem_region1
);
1559 err
= pci_request_region(pdev
, mem_region2
, "acx_2");
1561 acx_log(LOG_WARNING
, L_ANY
, "pci_request_region (2/2) FAILED!\n");
1562 goto fail_request_mem_region2
;
1565 phymem2
= pci_resource_start(pdev
, mem_region2
);
1568 * We got them? Map them!
1570 * We pass 0 as the third argument to pci_iomap(): it will map the full
1571 * region in this case, which is what we want.
1574 mem1
= pci_iomap(pdev
, mem_region1
, 0);
1576 acx_log(LOG_WARNING
, L_ANY
, "ioremap() FAILED\n");
1580 mem2
= pci_iomap(pdev
, mem_region2
, 0);
1582 acx_log(LOG_WARNING
, L_ANY
, "ioremap() #2 FAILED\n");
1586 acx_log(LOG_INFO
, L_ANY
, "found %s-based wireless network card at %s, "
1587 "irq:%d, phymem1:0x%lX, phymem2:0x%lX, mem1:0x%p, "
1588 "mem1_size:%ld, mem2:0x%p, mem2_size:%ld\n",
1589 chip_name
, pci_name(pdev
), pdev
->irq
, phymem1
, phymem2
,
1590 mem1
, mem_region1_size
, mem2
, mem_region2_size
);
1591 //log(L_ANY, "initial debug setting is 0x%04X\n", acx_debug);
1592 adev
->chip_type
= chip_type
;
1593 adev
->chip_name
= chip_name
;
1594 adev
->io
= (CHIPTYPE_ACX100
== chip_type
) ? IO_ACX100
: IO_ACX111
;
1595 adev
->membase
= phymem1
;
1596 adev
->iobase
= mem1
;
1597 adev
->membase2
= phymem2
;
1598 adev
->iobase2
= mem2
;
1599 adev
->irq
= pdev
->irq
;
1602 if (0 == pdev
->irq
) {
1603 acx_log(LOG_WARNING
, L_ANY
, "can't use IRQ 0\n");
1606 SET_IEEE80211_DEV(ieee
, &pdev
->dev
);
1608 /* request shared IRQ handler */
1610 (adev
->irq
, acxpci_i_interrupt
, IRQF_SHARED
, KBUILD_MODNAME
, adev
)) {
1611 acx_log(LOG_WARNING
, L_ANY
, "%s: request_irq FAILED\n",
1612 wiphy_name(adev
->ieee
->wiphy
));
1616 acx_log(LOG_DEBUG
, L_IRQ
| L_REALLYVERBOSE
,
1617 "request_irq %d successful\n", adev
->irq
);
1619 /* to find crashes due to weird driver access
1620 * to unconfigured interface (ifup) */
1621 adev
->mgmt_timer
.function
= (void (*)(unsigned long))0x0000dead;
1624 #ifdef NONESSENTIAL_FEATURES
1625 acx_show_card_eeprom_id(adev
);
1626 #endif /* NONESSENTIAL_FEATURES */
1629 /* ok, pci setup is finished, now start initializing the card */
1631 /* NB: read_reg() reads may return bogus data before reset_dev(),
1632 * since the firmware which directly controls large parts of the I/O
1633 * registers isn't initialized yet.
1634 * acx100 seems to be more affected than acx111 */
1635 if (OK
!= acxpci_s_reset_dev(adev
))
1638 if (IS_ACX100(adev
)) {
1639 /* ACX100: configopt struct in cmd mailbox - directly after reset */
1640 memcpy_fromio(&co
, adev
->cmd_area
, sizeof(co
));
1643 if (OK
!= acx_s_init_mac(adev
))
1646 if (IS_ACX111(adev
)) {
1647 /* ACX111: configopt struct needs to be queried after full init */
1648 acx_s_interrogate(adev
, &co
, ACX111_IE_CONFIG_OPTIONS
);
1650 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
1651 if (OK
!= acxpci_read_eeprom_byte(adev
, 0x05, &adev
->eeprom_version
))
1652 goto fail_read_eeprom_version
;
1654 acx_s_parse_configoption(adev
, &co
);
1655 acx_s_set_defaults(adev
);
1656 acx_s_get_firmware_version(adev
); /* needs to be after acx_s_init_mac() */
1657 acx_display_hardware_details(adev
);
1659 /* Register the card, AFTER everything else has been set up,
1660 * since otherwise an ioctl could step on our feet due to
1661 * firmware operations happening in parallel or uninitialized data */
1664 acx_proc_register_entries(ieee
);
1666 /* Now we have our device, so make sure the kernel doesn't try
1667 * to send packets even though we're not associated to a network yet */
1669 /* after register_netdev() userspace may start working with dev
1670 * (in particular, on other CPUs), we only need to up the sem */
1671 /* acx_sem_unlock(adev); */
1673 acx_log(LOG_INFO
, L_ANY
, "driver version " ACX_RELEASE
1674 ": net device %s, driver compiled "
1675 "against wireless extensions %d and Linux %s\n",
1676 wiphy_name(adev
->ieee
->wiphy
), WIRELESS_EXT
, UTS_RELEASE
);
1678 MAC_COPY(adev
->ieee
->wiphy
->perm_addr
, adev
->dev_addr
);
1680 acx_log(LOG_INFO
, L_IRQ
| L_INIT
, "using IRQ %d\n", pdev
->irq
);
1682 /** done with board specific setup **/
1684 /* need to be able to restore PCI state after a suspend */
1686 pci_save_state(pdev
);
1689 err
= acx_setup_modes(adev
);
1691 acx_log(LOG_WARNING
, L_ANY
, "can't register hwmode\n");
1692 goto fail_register_netdev
;
1695 acx_init_task_scheduler(adev
);
1696 err
= ieee80211_register_hw(ieee
);
1698 acx_log(LOG_WARNING
, L_ANY
,
1699 "ieee80211_register_hw() FAILED: %d\n", err
);
1700 goto fail_register_netdev
;
1703 great_inquisitor(adev
);
1709 /* error paths: undo everything in reverse order... */
1712 acxpci_s_delete_dma_regions(adev
);
1713 pci_set_drvdata(pdev
, NULL
);
1716 fail_read_eeprom_version
:
1721 pci_iounmap(pdev
, mem2
);
1724 pci_iounmap(pdev
, mem1
);
1727 pci_release_region(pdev
, mem_region2
);
1729 fail_request_mem_region2
:
1730 pci_release_region(pdev
, mem_region1
);
1732 fail_request_mem_region1
:
1733 fail_unknown_chiptype
:
1734 pci_disable_device(pdev
);
1736 fail_pci_enable_device
:
1738 pci_set_power_state(pdev
, PCI_D3hot
);
1741 fail_register_netdev
:
1742 ieee80211_free_hw(ieee
);
1749 /***********************************************************************
1752 ** Shut device down (if not hot unplugged)
1753 ** and deallocate PCI resources for the acx chip.
1755 ** pdev - ptr to PCI device structure containing info about pci configuration
1757 static void __devexit
acxpci_e_remove(struct pci_dev
*pdev
)
1759 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*)pci_get_drvdata(pdev
);
1760 acx_device_t
*adev
= ieee2adev(hw
);
1761 unsigned long mem_region1
, mem_region2
;
1762 unsigned long flags
;
1766 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
1767 "%s: card is unused. Skipping any release code\n",
1772 /* If device wasn't hot unplugged... */
1773 if (adev_present(adev
)) {
1775 /* disable both Tx and Rx to shut radio down properly */
1776 if (adev
->initialized
) {
1777 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_TX
, NULL
, 0);
1778 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_RX
, NULL
, 0);
1779 adev
->initialized
= 0;
1782 /* put the eCPU to sleep to save power
1783 * Halting is not possible currently,
1784 * since not supported by all firmware versions */
1785 acx_s_issue_cmd(adev
, ACX100_CMD_SLEEP
, NULL
, 0);
1787 acx_lock(adev
, flags
);
1788 /* disable power LED to save power :-) */
1789 acx_log(LOG_INFO
, L_INIT
,
1790 "switching off power LED to save power\n");
1791 acxpci_l_power_led(adev
, 0);
1793 if (IS_ACX111(adev
)) {
1794 /* FIXME: does this actually keep halting the eCPU?
1795 * I don't think so...
1797 acxpci_l_reset_mac(adev
);
1801 temp
= read_reg16(adev
, ACX_IO_ECPU_CTRL
) | 0x1;
1802 write_reg16(adev
, ACX_IO_ECPU_CTRL
, temp
);
1805 acx_unlock(adev
, flags
);
1809 /* unregister the device to not let the kernel
1810 * (e.g. ioctls) access a half-deconfigured device
1811 * NB: this will cause acxpci_e_close() to be called,
1812 * thus we shouldn't call it under sem!
1813 * Well, netdev did, but ieee80211 stack does not, so we
1814 * have to do so manually...
1817 acx_log(LOG_INFO
, L_INIT
,
1818 "removing device %s\n", wiphy_name(adev
->ieee
->wiphy
));
1819 ieee80211_unregister_hw(adev
->ieee
);
1821 /* unregister_netdev ensures that no references to us left.
1822 * For paranoid reasons we continue to follow the rules */
1825 if (adev
->dev_state_mask
& ACX_STATE_IFACE_UP
) {
1827 CLEAR_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
1830 acx_proc_unregister_entries(adev
->ieee
);
1832 if (IS_ACX100(adev
)) {
1833 mem_region1
= PCI_ACX100_REGION1
;
1834 mem_region2
= PCI_ACX100_REGION2
;
1836 mem_region1
= PCI_ACX111_REGION1
;
1837 mem_region2
= PCI_ACX111_REGION2
;
1840 /* finally, clean up PCI bus state */
1841 acxpci_s_delete_dma_regions(adev
);
1843 iounmap(adev
->iobase
);
1845 iounmap(adev
->iobase2
);
1846 release_mem_region(pci_resource_start(pdev
, mem_region1
),
1847 pci_resource_len(pdev
, mem_region1
));
1848 release_mem_region(pci_resource_start(pdev
, mem_region2
),
1849 pci_resource_len(pdev
, mem_region2
));
1850 pci_disable_device(pdev
);
1852 /* remove dev registration */
1853 pci_set_drvdata(pdev
, NULL
);
1855 acx_sem_unlock(adev
);
1857 /* Free netdev (quite late,
1858 * since otherwise we might get caught off-guard
1859 * by a netdev timeout handler execution
1860 * expecting to see a working dev...) */
1861 ieee80211_free_hw(adev
->ieee
);
1863 /* put device into ACPI D3 mode (shutdown) */
1865 pci_set_power_state(pdev
, PCI_D3hot
);
1872 /***********************************************************************
1873 ** TODO: PM code needs to be fixed / debugged / tested.
1877 acxpci_e_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1879 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
1883 acx_log(LOG_WARNING
, L_ANY
, "suspend handler is experimental!\n");
1884 acx_log(LOG_INFO
, L_ANY
, "suspend: dev %p\n", hw
);
1886 /* if (!netif_running(ndev))
1889 adev
= ieee2adev(hw
);
1890 acx_log(LOG_INFO
, L_ANY
, "suspend: adev %p\n", adev
);
1894 ieee80211_unregister_hw(hw
); /* this one cannot sleep */
1896 /* down() does not set it to ACX_IRQ_ALL, but here we really want that */
1897 write_reg16(adev
, ACX_IO_IRQ_MASK
, ACX_IRQ_ALL
);
1898 write_reg16(adev
, ACX_IO_FEMR
, 0x0);
1899 acxpci_s_delete_dma_regions(adev
);
1900 pci_save_state(pdev
);
1901 pci_set_power_state(pdev
, PCI_D3hot
);
1903 acx_sem_unlock(adev
);
1909 static int acxpci_e_resume(struct pci_dev
*pdev
)
1911 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
1916 acx_log(LOG_WARNING
, L_ANY
, "resume handler is experimental!\n");
1917 acx_log(LOG_INFO
, L_ANY
, "resume: got dev %p\n", hw
);
1920 adev
= ieee2adev(hw
);
1921 acx_log(LOG_INFO
, L_ANY
, "resume: got adev %p\n", adev
);
1925 pci_set_power_state(pdev
, PCI_D0
);
1926 acx_log(LOG_INFO
, L_ANY
, "resume: power state PCI_D0 set\n");
1927 pci_restore_state(pdev
);
1928 acx_log(LOG_INFO
, L_ANY
, "resume: PCI state restored\n");
1930 if (OK
!= acxpci_s_reset_dev(adev
))
1932 acx_log(LOG_INFO
, L_ANY
, "resume: device reset done\n");
1933 if (OK
!= acx_s_init_mac(adev
))
1935 acx_log(LOG_INFO
, L_ANY
, "resume: init MAC done\n");
1938 acx_log(LOG_INFO
, L_ANY
, "resume: acx up done\n");
1940 /* now even reload all card parameters as they were before suspend,
1941 * and possibly be back in the network again already :-) */
1942 if (ACX_STATE_IFACE_UP
& adev
->dev_state_mask
) {
1943 adev
->set_mask
= GETSET_ALL
;
1944 acx_s_update_card_settings(adev
);
1945 acx_log(LOG_INFO
, L_ANY
, "resume: settings updated\n");
1947 ieee80211_register_hw(hw
);
1948 acx_log(LOG_INFO
, L_ANY
, "resume: device attached\n");
1951 acx_sem_unlock(adev
);
1952 /* we need to return OK here anyway, right? */
1956 #endif /* CONFIG_PM */
1957 #endif /* CONFIG_PCI */
1959 /***********************************************************************
1962 ** This function is called by acxpci_e_open (when ifconfig sets the device as up)
1965 ** - Enables on-card interrupt requests
1966 ** - calls acx_s_start
1969 static void enable_acx_irq(acx_device_t
* adev
)
1972 write_reg16(adev
, ACX_IO_IRQ_MASK
, adev
->irq_mask
);
1973 write_reg16(adev
, ACX_IO_FEMR
, 0x8000);
1974 adev
->irqs_active
= 1;
1978 static void acxpci_s_up(struct ieee80211_hw
*hw
)
1980 acx_device_t
*adev
= ieee2adev(hw
);
1981 unsigned long flags
;
1985 acx_lock(adev
, flags
);
1986 enable_acx_irq(adev
);
1987 acx_unlock(adev
, flags
);
1989 /* acx fw < 1.9.3.e has a hardware timer, and older drivers
1990 ** used to use it. But we don't do that anymore, our OS
1991 ** has reliable software timers */
1992 init_timer(&adev
->mgmt_timer
);
1993 adev
->mgmt_timer
.function
= acx_i_timer
;
1994 adev
->mgmt_timer
.data
= (unsigned long)adev
;
1996 /* Need to set ACX_STATE_IFACE_UP first, or else
1997 ** timer won't be started by acx_set_status() */
1998 SET_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
2006 /***********************************************************************
2009 ** NB: device may be already hot unplugged if called from acxpci_e_remove()
2011 ** Disables on-card interrupt request, stops softirq and timer, stops queue,
2012 ** sets status == STOPPED
2015 static void disable_acx_irq(acx_device_t
* adev
)
2017 u16 disable_irq_mask
= (IS_ACX111(adev
)) ?
2018 ACX111_DISABLE_ALL_IRQS
:
2019 ACX100_DISABLE_ALL_IRQS
;
2023 /* I guess mask is not ACX_IRQ_ALL because acx100 won't signal
2024 ** cmd completion then (needed for ifup).
2025 ** I can't ifconfig up after ifconfig down'ing on my acx100 */
2026 write_reg16(adev
, ACX_IO_IRQ_MASK
, disable_irq_mask
);
2027 write_reg16(adev
, ACX_IO_FEMR
, 0x0);
2028 adev
->irqs_active
= 0;
2033 static void acxpci_s_down(struct ieee80211_hw
*hw
)
2035 acx_device_t
*adev
= ieee2adev(hw
);
2039 /* Disable IRQs first, so that IRQs cannot race with us */
2040 /* then wait until interrupts have finished executing on other CPUs */
2041 disable_acx_irq(adev
); /* NO sem-locking here? */
2042 synchronize_irq(adev
->irq
);
2044 /* we really don't want to have an asynchronous tasklet disturb us
2045 ** after something vital for its job has been shut down, so
2046 ** end all remaining work now.
2048 ** NB: carrier_off (done by set_status below) would lead to
2049 ** not yet fully understood deadlock in flush_scheduled_work().
2050 ** That's why we do FLUSH first.
2052 ** NB2: we have a bad locking bug here: flush_scheduled_work()
2053 ** waits for acx_e_after_interrupt_task to complete if it is running
2054 ** on another CPU, but acx_e_after_interrupt_task
2055 ** will sleep on sem forever, because it is taken by us!
2056 ** Work around that by temporary sem unlock.
2057 ** This will fail miserably if we'll be hit by concurrent
2058 ** iwconfig or something in between. TODO! */
2059 acx_sem_unlock(adev
);
2060 flush_scheduled_work();
2063 /* This is possible:
2064 ** flush_scheduled_work -> acx_e_after_interrupt_task ->
2065 ** -> set_status(ASSOCIATED) -> wake_queue()
2066 ** That's why we stop queue _after_ flush_scheduled_work
2067 ** lock/unlock is just paranoia, maybe not needed */
2069 /* kernel/timer.c says it's illegal to del_timer_sync()
2070 ** a timer which restarts itself. We guarantee this cannot
2071 ** ever happen because acx_i_timer() never does this if
2072 ** status is ACX_STATUS_0_STOPPED */
2073 del_timer_sync(&adev
->mgmt_timer
);
2078 #ifdef CONFIG_NET_POLL_CONTROLLER
2079 void acxpci_net_poll_controller(struct net_device *net_dev)
2081 acx_device_t *adev = ndev2adev(net_dev);
2082 unsigned long flags;
2084 local_irq_save(flags);
2085 acxpci_i_interrupt(adev->irq, adev);
2086 local_irq_restore(flags);
2088 #endif*/ /* CONFIG_NET_POLL_CONTROLLER */
2090 /***********************************************************************
2093 ** Called as a result of SIOCSIFFLAGS ioctl changing the flags bit IFF_UP
2094 ** from clear to set. In other words: ifconfig up.
2098 ** >0 f/w reported error
2099 ** <0 driver reported error
2101 static int acxpci_e_open(struct ieee80211_hw
*hw
)
2103 acx_device_t
*adev
= ieee2adev(hw
);
2110 adev
->initialized
= 0;
2112 /* TODO: pci_set_power_state(pdev, PCI_D0); ? */
2117 /* We don't currently have to do anything else.
2118 * The setup of the MAC should be subsequently completed via
2119 * the mlme commands.
2120 * Higher layers know we're ready from dev->start==1 and
2121 * dev->tbusy==0. Our rx path knows to pass up received/
2122 * frames because of dev->flags&IFF_UP is true.
2124 ieee80211_start_queues(adev
->ieee
);
2126 adev
->initialized
= 1;
2127 acx_sem_unlock(adev
);
2134 /***********************************************************************
2137 ** This function stops the network functionality of the interface (invoked
2138 ** when the user calls ifconfig <wlan> down). The tx queue is halted and
2139 ** the device is marked as down.
2141 ** Called as a result of SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
2142 ** from set to clear. I.e. called by "ifconfig DEV down"
2146 ** >0 f/w reported error
2147 ** <0 driver reported error
2149 static void acxpci_e_close(struct ieee80211_hw
*hw
)
2151 acx_device_t
*adev
= ieee2adev(hw
);
2158 CLEAR_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
2159 if (adev
->initialized
) {
2164 acx_free_modes(adev
);
2165 /* disable all IRQs, release shared IRQ handler */
2166 write_reg16(adev
, ACX_IO_IRQ_MASK
, ACX_IRQ_ALL
);
2167 write_reg16(adev
, ACX_IO_FEMR
, 0x0);
2168 free_irq(adev
->irq
, adev
);
2170 /* TODO: pci_set_power_state(pdev, PCI_D3hot); ? */
2172 /* We currently don't have to do anything else.
2173 * Higher layers know we're not ready from dev->start==0 and
2174 * dev->tbusy==1. Our rx path knows to not pass up received
2175 * frames because of dev->flags&IFF_UP is false.
2177 acx_sem_unlock(adev
);
2179 acx_log(LOG_INFO
, L_INIT
, "closed device\n");
2186 /***************************************************************
2187 ** acxpci_l_process_rxdesc
2189 ** Called directly and only from the IRQ handler
2193 static inline void log_rxbuffer(const acx_device_t
* adev
)
2197 static void log_rxbuffer(const acx_device_t
* adev
)
2199 register const struct rxhostdesc
*rxhostdesc
;
2202 /* no FN_ENTER here, we don't want that */
2204 rxhostdesc
= adev
->rxhostdesc_start
;
2205 if (unlikely(!rxhostdesc
))
2207 for (i
= 0; i
< RX_CNT
; i
++) {
2208 if ((rxhostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
2209 && (rxhostdesc
->Status
& cpu_to_le32(DESC_STATUS_FULL
)))
2210 acx_log(LOG_WARNING
, L_ANY
, "rx: buf %d full\n", i
);
2216 static void acxpci_l_process_rxdesc(acx_device_t
* adev
)
2218 register rxhostdesc_t
*hostdesc
;
2219 unsigned count
, tail
;
2223 if (unlikely(acx_debug
& L_BUFR
))
2226 /* First, have a loop to determine the first descriptor that's
2227 * full, just in case there's a mismatch between our current
2228 * rx_tail and the full descriptor we're supposed to handle. */
2229 tail
= adev
->rx_tail
;
2232 hostdesc
= &adev
->rxhostdesc_start
[tail
];
2233 /* advance tail regardless of outcome of the below test */
2234 tail
= (tail
+ 1) % RX_CNT
;
2236 if ((hostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
2237 && (hostdesc
->Status
& cpu_to_le32(DESC_STATUS_FULL
)))
2238 break; /* found it! */
2240 if (unlikely(!--count
)) /* hmm, no luck: all descs empty, bail out */
2244 /* now process descriptors, starting with the first we figured out */
2246 acx_log(LOG_DEBUG
, L_BUFR
,
2247 "rx: tail=%u Ctl_16=%04X Status=%08X\n",
2248 tail
, hostdesc
->Ctl_16
, hostdesc
->Status
);
2250 acx_l_process_rxbuf(adev
, hostdesc
->data
);
2251 hostdesc
->Status
= 0;
2252 /* flush all writes before adapter sees CTL_HOSTOWN change */
2254 /* Host no longer owns this, needs to be LAST */
2255 CLEAR_BIT(hostdesc
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
2257 /* ok, descriptor is handled, now check the next descriptor */
2258 hostdesc
= &adev
->rxhostdesc_start
[tail
];
2260 /* if next descriptor is empty, then bail out */
2261 if (!(hostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
2262 || !(hostdesc
->Status
& cpu_to_le32(DESC_STATUS_FULL
)))
2265 tail
= (tail
+ 1) % RX_CNT
;
2268 adev
->rx_tail
= tail
;
2274 /***********************************************************************
2275 ** acxpci_i_interrupt
2277 ** IRQ handler (atomic context, must not sleep, blah, blah)
2280 /* scan is complete. all frames now on the receive queue are valid */
2281 #define INFO_SCAN_COMPLETE 0x0001
2282 #define INFO_WEP_KEY_NOT_FOUND 0x0002
2283 /* hw has been reset as the result of a watchdog timer timeout */
2284 #define INFO_WATCH_DOG_RESET 0x0003
2285 /* failed to send out NULL frame from PS mode notification to AP */
2286 /* recommended action: try entering 802.11 PS mode again */
2287 #define INFO_PS_FAIL 0x0004
2288 /* encryption/decryption process on a packet failed */
2289 #define INFO_IV_ICV_FAILURE 0x0005
2291 /* Info mailbox format:
2294 more bytes may follow
2295 rumors say about status:
2296 0x0000 info available (set by hw)
2297 0x0001 information received (must be set by host)
2298 0x1000 info available, mailbox overflowed (messages lost) (set by hw)
2299 but in practice we've seen:
2300 0x9000 when we did not set status to 0x0001 on prev message
2301 0x1001 when we did set it
2302 0x0000 was never seen
2303 conclusion: this is really a bitfield:
2304 0x1000 is 'info available' bit
2305 'mailbox overflowed' bit is 0x8000, not 0x1000
2306 value of 0x0000 probably means that there are no messages at all
2307 P.S. I dunno how in hell hw is supposed to notice that messages are lost -
2308 it does NOT clear bit 0x0001, and this bit will probably stay forever set
2309 after we set it once. Let's hope this will be fixed in firmware someday
2312 static void handle_info_irq(acx_device_t
* adev
)
2315 static const char *const info_type_msg
[] = {
2318 "WEP key not found",
2319 "internal watchdog reset was done",
2320 "failed to send powersave (NULL frame) notification to AP",
2321 "encrypt/decrypt on a packet has failed",
2322 "TKIP tx keys disabled",
2323 "TKIP rx keys disabled",
2324 "TKIP rx: key ID not found",
2332 "TKIP IV value exceeds thresh"
2335 u32 info_type
, info_status
;
2337 info_type
= acx_readl(adev
->info_area
);
2338 info_status
= (info_type
>> 16);
2339 info_type
= (u16
) info_type
;
2341 /* inform fw that we have read this info message */
2342 acx_writel(info_type
| 0x00010000, adev
->info_area
);
2343 write_reg16(adev
, ACX_IO_INT_TRIG
, INT_TRIG_INFOACK
);
2346 acx_log(LOG_DEBUG
, L_CTL
,
2347 "info_type:%04X info_status:%04X\n", info_type
, info_status
);
2349 acx_log(LOG_DEBUG
, L_IRQ
, "got Info IRQ: status %04X type %04X: %s\n",
2350 info_status
, info_type
,
2351 info_type_msg
[(info_type
>= ARRAY_SIZE(info_type_msg
)) ?
2357 static void log_unusual_irq(u16 irqtype
)
2360 if (!printk_ratelimit())
2365 if (irqtype
& ACX_IRQ_RX_DATA
) {
2368 /* ACX_IRQ_TX_COMPLETE */
2369 if (irqtype
& ACX_IRQ_TX_XFER
) {
2372 /* ACX_IRQ_RX_COMPLETE */
2373 if (irqtype
& ACX_IRQ_DTIM
) {
2376 if (irqtype
& ACX_IRQ_BEACON
) {
2379 if (irqtype
& ACX_IRQ_TIMER
) {
2382 if (irqtype
& ACX_IRQ_KEY_NOT_FOUND
) {
2383 printk(" Key_Not_Found");
2385 if (irqtype
& ACX_IRQ_IV_ICV_FAILURE
) {
2386 printk(" IV_ICV_Failure (crypto)");
2388 /* ACX_IRQ_CMD_COMPLETE */
2390 if (irqtype
& ACX_IRQ_OVERFLOW
) {
2391 printk(" Overflow");
2393 if (irqtype
& ACX_IRQ_PROCESS_ERROR
) {
2394 printk(" Process_Error");
2396 /* ACX_IRQ_SCAN_COMPLETE */
2397 if (irqtype
& ACX_IRQ_FCS_THRESHOLD
) {
2398 printk(" FCS_Threshold");
2400 if (irqtype
& ACX_IRQ_UNKNOWN
) {
2403 printk(" IRQ(s)\n");
2406 /* FIXME: update_link_quality_led was a stub - let's comment it and avoid
2407 * compiler warnings */
2409 static void update_link_quality_led(acx_device_t * adev)
2414 acx_signal_determine_quality(adev->wstats.qual.level,
2415 adev->wstats.qual.noise);
2416 if (qual > adev->brange_max_quality)
2417 qual = adev->brange_max_quality;
2419 if (time_after(jiffies, adev->brange_time_last_state_change +
2421 HZ / 2 * (unsigned long)qual /
2422 adev->brange_max_quality))) {
2423 acxpci_l_power_led(adev, (adev->brange_last_state == 0));
2424 adev->brange_last_state ^= 1; // toggle
2425 adev->brange_time_last_state_change = jiffies;
2430 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* a la orinoco.c */
2432 /* Interrupt handler bottom-half */
2433 void acx_interrupt_tasklet(struct work_struct
*work
)
2436 #ifdef CONFIG_ACX_MAC80211_DEBUG
2437 u32 _handled
= 0x00000000;
2438 # define acxirq_handled(irq) do { _handled |= (irq); } while (0)
2440 # define acxirq_handled(irq) do { /* nothing */ } while (0)
2441 #endif /* CONFIG_ACX_MAC80211_DEBUG */
2442 acx_device_t
*adev
= container_of(work
,struct acx_device
, after_interrupt_task
);
2443 // unsigned int irqcount = MAX_IRQLOOPS_PER_JIFFY;
2446 #define IRQ_ITERATE 0
2448 unsigned int irqcount
= MAX_IRQLOOPS_PER_JIFFY
;
2454 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2458 irqtype
= adev
->irq_reason
;
2459 adev
->irq_reason
= 0;
2462 if (jiffies
!= adev
->irq_last_jiffies
) {
2463 adev
->irq_loops_this_jiffy
= 0;
2464 adev
->irq_last_jiffies
= jiffies
;
2467 /* safety condition; we'll normally abort loop below
2468 * in case no IRQ type occurred */
2469 while (likely(--irqcount
)) {
2471 /* ACK all IRQs ASAP */
2473 /* Handle most important IRQ types first */
2474 if (irqtype
& ACX_IRQ_RX_COMPLETE
) {
2475 acx_log(LOG_DEBUG
, L_IRQ
, "got Rx_Complete IRQ\n");
2476 acxpci_l_process_rxdesc(adev
);
2478 if (irqtype
& ACX_IRQ_TX_COMPLETE
) {
2479 acx_log(LOG_DEBUG
, L_IRQ
, "got Tx_Complete IRQ\n");
2480 /* don't clean up on each Tx complete, wait a bit
2481 * unless we're going towards full, in which case
2482 * we do it immediately, too (otherwise we might lockup
2483 * with a full Tx buffer if we go into
2484 * acxpci_l_clean_txdesc() at a time when we won't wakeup
2485 * the net queue in there for some reason...) */
2486 // if (adev->tx_free <= TX_START_CLEAN) {
2487 acxpci_l_clean_txdesc(adev
);
2491 /* Less frequent ones */
2493 | ACX_IRQ_CMD_COMPLETE
2494 | ACX_IRQ_INFO
| ACX_IRQ_SCAN_COMPLETE
)) {
2495 if (irqtype
& ACX_IRQ_INFO
) {
2496 handle_info_irq(adev
);
2498 if (irqtype
& ACX_IRQ_SCAN_COMPLETE
) {
2499 acx_log(LOG_DEBUG
, L_IRQ
,
2500 "got Scan_Complete IRQ\n");
2501 /* need to do that in process context */
2502 /* remember that fw is not scanning anymore */
2503 SET_BIT(adev
->irq_status
,
2504 ACX_IRQ_SCAN_COMPLETE
);
2508 /* These we just log, but either they happen rarely
2509 * or we keep them masked out */
2510 if (irqtype
& (0 | ACX_IRQ_RX_DATA
2511 /* | ACX_IRQ_TX_COMPLETE */
2513 /* | ACX_IRQ_RX_COMPLETE */
2517 | ACX_IRQ_KEY_NOT_FOUND
2518 | ACX_IRQ_IV_ICV_FAILURE
2519 /* | ACX_IRQ_CMD_COMPLETE */
2520 /* | ACX_IRQ_INFO */
2522 | ACX_IRQ_PROCESS_ERROR
2523 /* | ACX_IRQ_SCAN_COMPLETE */
2524 | ACX_IRQ_FCS_THRESHOLD
2525 | ACX_IRQ_UNKNOWN
)) {
2526 log_unusual_irq(irqtype
);
2529 unmasked
= read_reg16(adev
, ACX_IO_IRQ_REASON
);
2530 irqtype
= unmasked
& ~adev
->irq_mask
;
2531 /* Bail out if no new IRQ bits or if all are masked out */
2536 (++adev
->irq_loops_this_jiffy
> MAX_IRQLOOPS_PER_JIFFY
)) {
2537 acx_log(LOG_WARNING
, L_ANY
,
2538 "too many interrupts per jiffy!\n");
2539 /* Looks like card floods us with IRQs! Try to stop that */
2540 write_reg16(adev
, ACX_IO_IRQ_MASK
, ACX_IRQ_ALL
);
2541 /* This will short-circuit all future attempts to handle IRQ.
2542 * We cant do much more... */
2548 /* Routine to perform blink with range
2549 * FIXME: update_link_quality_led is a stub - add proper code and enable this again:
2550 if (unlikely(adev->led_power == 2))
2551 update_link_quality_led(adev);
2554 /* write_flush(adev); - not needed, last op was read anyway */
2555 acx_sem_unlock(adev
);
2558 if (adev
->after_interrupt_jobs
)
2559 acx_e_after_interrupt_task(&adev
->after_interrupt_task
);
2567 static irqreturn_t
acxpci_i_interrupt(int irq
, void *dev_id
)
2569 acx_device_t
*adev
= dev_id
;
2570 unsigned long flags
;
2571 register u16 irqtype
;
2579 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2582 acx_lock(adev
, flags
);
2584 unmasked
= read_reg16(adev
, ACX_IO_IRQ_REASON
);
2585 if (unlikely(unmasked
== ACX_IRQ_ALL
)) {
2586 /* ACX_IRQ_ALL value hints at missing hardware,
2587 * so don't do anything.
2588 * Not very clean, but other drivers do the same... */
2589 acx_log(LOG_WARNING
, L_IRQ
,
2590 "IRQ type:FFFF (ALL) - device removed? IRQ_NONE\n");
2594 /* We will check only "interesting" IRQ types */
2595 irqtype
= unmasked
& ~adev
->irq_mask
;
2597 /* We are on a shared IRQ line and it wasn't our IRQ */
2598 acx_log(LOG_DEBUG
, L_IRQ
,
2599 "IRQ type:%04X, mask:%04X - all are masked, IRQ_NONE\n",
2600 unmasked
, adev
->irq_mask
);
2604 /* Go ahead and ACK our interrupt */
2605 write_reg16(adev
, ACX_IO_IRQ_ACK
, ACX_IRQ_ALL
);
2606 if (irqtype
& ACX_IRQ_CMD_COMPLETE
) {
2607 acx_log(LOG_DEBUG
, L_IRQ
, "got Command_Complete IRQ\n");
2608 /* save the state for the running issue_cmd() */
2609 SET_BIT(adev
->irq_status
, ACX_IRQ_CMD_COMPLETE
);
2612 /* Only accept IRQs, if we are initialized properly.
2613 * This avoids an RX race while initializing.
2614 * We should probably not enable IRQs before we are initialized
2615 * completely, but some careful work is needed to fix this. I think it
2616 * is best to stay with this cheap workaround for now... .
2618 if (likely(adev
->initialized
)) {
2619 /* disable all IRQs. They are enabled again in the bottom half. */
2620 /* save the reason code and call our bottom half. */
2621 adev
->irq_reason
= irqtype
;
2623 if ((irqtype
& ACX_IRQ_RX_COMPLETE
) || (irqtype
& ACX_IRQ_TX_COMPLETE
))
2624 acx_schedule_task(adev
, 0);
2627 acx_unlock(adev
, flags
);
2631 acx_unlock(adev
, flags
);
2638 /***********************************************************************
2639 ** acxpci_l_power_led
2641 void acxpci_l_power_led(acx_device_t
* adev
, int enable
)
2643 u16 gpio_pled
= IS_ACX111(adev
) ? 0x0040 : 0x0800;
2645 /* A hack. Not moving message rate limiting to adev->xxx
2646 * (it's only a debug message after all) */
2647 static int rate_limit
= 0;
2649 if (rate_limit
++ < 3)
2650 acx_log(LOG_INFO
, L_IOCTL
,
2651 "Please report in case toggling the power LED "
2652 "doesn't work for your card!\n");
2654 write_reg16(adev
, ACX_IO_GPIO_OUT
,
2655 read_reg16(adev
, ACX_IO_GPIO_OUT
) & ~gpio_pled
);
2657 write_reg16(adev
, ACX_IO_GPIO_OUT
,
2658 read_reg16(adev
, ACX_IO_GPIO_OUT
) | gpio_pled
);
2662 /***********************************************************************
2666 /***********************************************************************
2670 acx111pci_ioctl_info(struct net_device
*ndev
,
2671 struct iw_request_info
*info
,
2672 struct iw_param
*vwrq
, char *extra
)
2675 acx_device_t
*adev
= ndev2adev(ndev
);
2678 rxhostdesc_t
*rxhostdesc
;
2679 txhostdesc_t
*txhostdesc
;
2680 struct acx111_ie_memoryconfig memconf
;
2681 struct acx111_ie_queueconfig queueconf
;
2682 unsigned long flags
;
2687 char ratefallback
[0x5];
2689 if (!(acx_debug
& (L_IOCTL
| L_DEBUG
)))
2691 /* using printk() since we checked debug flag already */
2695 if (!IS_ACX111(adev
)) {
2696 printk("acx111-specific function called "
2697 "with non-acx111 chip, aborting\n");
2701 /* get Acx111 Memory Configuration */
2702 memset(&memconf
, 0, sizeof(memconf
));
2703 /* BTW, fails with 12 (Write only) error code.
2704 ** Retained for easy testing of issue_cmd error handling :) */
2705 acx_s_interrogate(adev
, &memconf
, ACX1xx_IE_QUEUE_CONFIG
);
2707 /* get Acx111 Queue Configuration */
2708 memset(&queueconf
, 0, sizeof(queueconf
));
2709 acx_s_interrogate(adev
, &queueconf
, ACX1xx_IE_MEMORY_CONFIG_OPTIONS
);
2711 /* get Acx111 Memory Map */
2712 memset(memmap
, 0, sizeof(memmap
));
2713 acx_s_interrogate(adev
, &memmap
, ACX1xx_IE_MEMORY_MAP
);
2715 /* get Acx111 Rx Config */
2716 memset(rxconfig
, 0, sizeof(rxconfig
));
2717 acx_s_interrogate(adev
, &rxconfig
, ACX1xx_IE_RXCONFIG
);
2719 /* get Acx111 fcs error count */
2720 memset(fcserror
, 0, sizeof(fcserror
));
2721 acx_s_interrogate(adev
, &fcserror
, ACX1xx_IE_FCS_ERROR_COUNT
);
2723 /* get Acx111 rate fallback */
2724 memset(ratefallback
, 0, sizeof(ratefallback
));
2725 acx_s_interrogate(adev
, &ratefallback
, ACX1xx_IE_RATE_FALLBACK
);
2727 /* force occurrence of a beacon interrupt */
2728 /* TODO: comment why is this necessary */
2729 write_reg16(adev
, ACX_IO_HINT_TRIG
, ACX_IRQ_BEACON
);
2731 /* dump Acx111 Mem Configuration */
2732 printk("dump mem config:\n"
2733 "data read: %d, struct size: %d\n"
2734 "Number of stations: %1X\n"
2735 "Memory block size: %1X\n"
2736 "tx/rx memory block allocation: %1X\n"
2737 "count rx: %X / tx: %X queues\n"
2739 "fragmentation %1X\n"
2740 "Rx Queue 1 Count Descriptors: %X\n"
2741 "Rx Queue 1 Host Memory Start: %X\n"
2742 "Tx Queue 1 Count Descriptors: %X\n"
2743 "Tx Queue 1 Attributes: %X\n",
2744 memconf
.len
, (int)sizeof(memconf
),
2745 memconf
.no_of_stations
,
2746 memconf
.memory_block_size
,
2747 memconf
.tx_rx_memory_block_allocation
,
2748 memconf
.count_rx_queues
, memconf
.count_tx_queues
,
2750 memconf
.fragmentation
,
2751 memconf
.rx_queue1_count_descs
,
2752 acx2cpu(memconf
.rx_queue1_host_rx_start
),
2753 memconf
.tx_queue1_count_descs
, memconf
.tx_queue1_attributes
);
2755 /* dump Acx111 Queue Configuration */
2756 printk("dump queue head:\n"
2757 "data read: %d, struct size: %d\n"
2758 "tx_memory_block_address (from card): %X\n"
2759 "rx_memory_block_address (from card): %X\n"
2760 "rx1_queue address (from card): %X\n"
2761 "tx1_queue address (from card): %X\n"
2762 "tx1_queue attributes (from card): %X\n",
2763 queueconf
.len
, (int)sizeof(queueconf
),
2764 queueconf
.tx_memory_block_address
,
2765 queueconf
.rx_memory_block_address
,
2766 queueconf
.rx1_queue_address
,
2767 queueconf
.tx1_queue_address
, queueconf
.tx1_attributes
);
2769 /* dump Acx111 Mem Map */
2770 printk("dump mem map:\n"
2771 "data read: %d, struct size: %d\n"
2774 "WEP default key start: %X\n"
2775 "WEP default key end: %X\n"
2776 "STA table start: %X\n"
2777 "STA table end: %X\n"
2778 "Packet template start: %X\n"
2779 "Packet template end: %X\n"
2780 "Queue memory start: %X\n"
2781 "Queue memory end: %X\n"
2782 "Packet memory pool start: %X\n"
2783 "Packet memory pool end: %X\n"
2786 *((u16
*) & memmap
[0x02]), (int)sizeof(memmap
),
2787 *((u32
*) & memmap
[0x04]),
2788 *((u32
*) & memmap
[0x08]),
2789 *((u32
*) & memmap
[0x0C]),
2790 *((u32
*) & memmap
[0x10]),
2791 *((u32
*) & memmap
[0x14]),
2792 *((u32
*) & memmap
[0x18]),
2793 *((u32
*) & memmap
[0x1C]),
2794 *((u32
*) & memmap
[0x20]),
2795 *((u32
*) & memmap
[0x24]),
2796 *((u32
*) & memmap
[0x28]),
2797 *((u32
*) & memmap
[0x2C]),
2798 *((u32
*) & memmap
[0x30]), adev
->iobase
, adev
->iobase2
);
2800 /* dump Acx111 Rx Config */
2801 printk("dump rx config:\n"
2802 "data read: %d, struct size: %d\n"
2804 "rx filter config: %X\n",
2805 *((u16
*) & rxconfig
[0x02]), (int)sizeof(rxconfig
),
2806 *((u16
*) & rxconfig
[0x04]), *((u16
*) & rxconfig
[0x06]));
2808 /* dump Acx111 fcs error */
2809 printk("dump fcserror:\n"
2810 "data read: %d, struct size: %d\n"
2812 *((u16
*) & fcserror
[0x02]), (int)sizeof(fcserror
),
2813 *((u32
*) & fcserror
[0x04]));
2815 /* dump Acx111 rate fallback */
2816 printk("dump rate fallback:\n"
2817 "data read: %d, struct size: %d\n"
2818 "ratefallback: %X\n",
2819 *((u16
*) & ratefallback
[0x02]), (int)sizeof(ratefallback
),
2820 *((u8
*) & ratefallback
[0x04]));
2822 /* protect against IRQ */
2823 acx_lock(adev
, flags
);
2825 /* dump acx111 internal rx descriptor ring buffer */
2826 rxdesc
= adev
->rxdesc_start
;
2828 /* loop over complete receive pool */
2830 for (i
= 0; i
< RX_CNT
; i
++) {
2831 printk("\ndump internal rxdesc %d:\n"
2834 "acx mem pointer (dynamic) 0x%X\n"
2835 "CTL (dynamic) 0x%X\n"
2836 "Rate (dynamic) 0x%X\n"
2837 "RxStatus (dynamic) 0x%X\n"
2838 "Mod/Pre (dynamic) 0x%X\n",
2841 acx2cpu(rxdesc
->pNextDesc
),
2842 acx2cpu(rxdesc
->ACXMemPtr
),
2844 rxdesc
->rate
, rxdesc
->error
, rxdesc
->SNR
);
2848 /* dump host rx descriptor ring buffer */
2850 rxhostdesc
= adev
->rxhostdesc_start
;
2852 /* loop over complete receive pool */
2854 for (i
= 0; i
< RX_CNT
; i
++) {
2855 printk("\ndump host rxdesc %d:\n"
2857 "buffer mem pos 0x%X\n"
2858 "buffer mem offset 0x%X\n"
2865 acx2cpu(rxhostdesc
->data_phy
),
2866 rxhostdesc
->data_offset
,
2867 le16_to_cpu(rxhostdesc
->Ctl_16
),
2868 le16_to_cpu(rxhostdesc
->length
),
2869 acx2cpu(rxhostdesc
->desc_phy_next
),
2870 rxhostdesc
->Status
);
2874 /* dump acx111 internal tx descriptor ring buffer */
2875 txdesc
= adev
->txdesc_start
;
2877 /* loop over complete transmit pool */
2879 for (i
= 0; i
< TX_CNT
; i
++) {
2880 printk("\ndump internal txdesc %d:\n"
2884 "acx mem pointer (dynamic) 0x%X\n"
2885 "host mem pointer (dynamic) 0x%X\n"
2886 "length (dynamic) 0x%X\n"
2887 "CTL (dynamic) 0x%X\n"
2888 "CTL2 (dynamic) 0x%X\n"
2889 "Status (dynamic) 0x%X\n"
2890 "Rate (dynamic) 0x%X\n",
2892 (int)sizeof(struct txdesc
),
2894 acx2cpu(txdesc
->pNextDesc
),
2895 acx2cpu(txdesc
->AcxMemPtr
),
2896 acx2cpu(txdesc
->HostMemPtr
),
2897 le16_to_cpu(txdesc
->total_length
),
2899 txdesc
->Ctl2_8
, txdesc
->error
,
2901 txdesc
= advance_txdesc(adev
, txdesc
, 1);
2904 /* dump host tx descriptor ring buffer */
2906 txhostdesc
= adev
->txhostdesc_start
;
2908 /* loop over complete host send pool */
2910 for (i
= 0; i
< TX_CNT
* 2; i
++) {
2911 printk("\ndump host txdesc %d:\n"
2913 "buffer mem pos 0x%X\n"
2914 "buffer mem offset 0x%X\n"
2921 acx2cpu(txhostdesc
->data_phy
),
2922 txhostdesc
->data_offset
,
2923 le16_to_cpu(txhostdesc
->Ctl_16
),
2924 le16_to_cpu(txhostdesc
->length
),
2925 acx2cpu(txhostdesc
->desc_phy_next
),
2926 le32_to_cpu(txhostdesc
->Status
));
2930 /* write_reg16(adev, 0xb4, 0x4); */
2932 acx_unlock(adev
, flags
);
2935 acx_sem_unlock(adev
);
2936 #endif /* ACX_DEBUG */
2941 /***********************************************************************
2944 acx100pci_ioctl_set_phy_amp_bias(struct net_device
*ndev
,
2945 struct iw_request_info
*info
,
2946 struct iw_param
*vwrq
, char *extra
)
2948 acx_device_t
*adev
= ndev2adev(ndev
);
2949 unsigned long flags
;
2952 if (!IS_ACX100(adev
)) {
2954 * Removing this check *might* damage
2955 * hardware, since we're tweaking GPIOs here after all!!!
2956 * You've been warned...
2958 acx_log(LOG_INFO
, L_ANY
,
2959 "sorry, setting bias level for non-acx100 "
2960 "is not supported yet\n");
2965 acx_log(LOG_INFO
, L_ANY
,
2966 "invalid bias parameter, range is 0-7\n");
2972 /* Need to lock accesses to [ACX_IO_GPIO_OUT]:
2973 * IRQ handler uses it to update LED */
2974 acx_lock(adev
, flags
);
2975 gpio_old
= read_reg16(adev
, ACX_IO_GPIO_OUT
);
2976 write_reg16(adev
, ACX_IO_GPIO_OUT
,
2977 (gpio_old
& 0xf8ff) | ((u16
) * extra
<< 8));
2978 acx_unlock(adev
, flags
);
2980 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "gpio_old: 0x%04X\n", gpio_old
);
2981 acx_log(LOG_INFO
, L_ANY
,
2982 "%s: PHY power amplifier bias: old:%d, new:%d\n",
2983 ndev
->name
, (gpio_old
& 0x0700) >> 8, (unsigned char)*extra
);
2985 acx_sem_unlock(adev
);
2991 /***************************************************************
2992 ** acxpci_l_alloc_tx
2993 ** Actually returns a txdesc_t* ptr
2995 ** FIXME: in case of fragments, should allocate multiple descrs
2996 ** after figuring out how many we need and whether we still have
2997 ** sufficiently many.
2999 tx_t
*acxpci_l_alloc_tx(acx_device_t
* adev
)
3001 struct txdesc
*txdesc
;
3007 if (unlikely(!adev
->tx_free
)) {
3008 acx_log(LOG_WARNING
, L_ANY
, "BUG: no free txdesc left\n");
3013 head
= adev
->tx_head
;
3014 txdesc
= get_txdesc(adev
, head
);
3015 ctl8
= txdesc
->Ctl_8
;
3017 /* 2005-10-11: there were several bug reports on this happening
3018 ** but now cause seems to be understood & fixed */
3019 if (unlikely(DESC_CTL_HOSTOWN
!= (ctl8
& DESC_CTL_ACXDONE_HOSTOWN
))) {
3020 /* whoops, descr at current index is not free, so probably
3021 * ring buffer already full */
3022 acx_log(LOG_WARNING
, L_ANY
, "BUG: tx_head:%d Ctl8:0x%02X - "
3023 "failed to find free txdesc\n", head
, ctl8
);
3028 /* Needed in case txdesc won't be eventually submitted for tx */
3029 txdesc
->Ctl_8
= DESC_CTL_ACXDONE_HOSTOWN
;
3032 acx_log(LOG_DEBUG
, L_BUFT
, "tx: got desc %u, %u remain\n",
3033 head
, adev
->tx_free
);
3034 /* Keep a few free descs between head and tail of tx ring.
3035 ** It is not absolutely needed, just feels safer */
3036 if (adev
->tx_free
< TX_STOP_QUEUE
) {
3037 acx_log(LOG_DEBUG
, L_BUF
, "stop queue (%u tx desc left)\n",
3039 acx_stop_queue(adev
->ieee
, NULL
);
3042 /* returning current descriptor, so advance to next free one */
3043 adev
->tx_head
= (head
+ 1) % TX_CNT
;
3047 return (tx_t
*) txdesc
;
3051 /***********************************************************************
3053 void *acxpci_l_get_txbuf(acx_device_t
* adev
, tx_t
* tx_opaque
)
3055 return get_txhostdesc(adev
, (txdesc_t
*) tx_opaque
)->data
;
3059 /***********************************************************************
3062 ** Can be called from IRQ (rx -> (AP bridging or mgmt response) -> tx).
3063 ** Can be called from acx_i_start_xmit (data frames from net core).
3065 ** FIXME: in case of fragments, should loop over the number of
3066 ** pre-allocated tx descrs, properly setting up transfer data and
3067 ** CTL_xxx flags according to fragment number.
3070 acxpci_l_tx_data(acx_device_t
* adev
, tx_t
* tx_opaque
, int len
,
3071 struct ieee80211_tx_control
*ieeectl
,struct sk_buff
* skb
)
3073 txdesc_t
*txdesc
= (txdesc_t
*) tx_opaque
;
3074 struct ieee80211_hdr
*wireless_header
;
3075 txhostdesc_t
*hostdesc1
, *hostdesc2
;
3082 /* fw doesn't tx such packets anyhow */
3083 /* if (unlikely(len < WLAN_HDR_A3_LEN))
3086 hostdesc1
= get_txhostdesc(adev
, txdesc
);
3087 wireless_header
= (struct ieee80211_hdr
*)hostdesc1
->data
;
3088 /* modify flag status in separate variable to be able to write it back
3089 * in one big swoop later (also in order to have less device memory
3091 Ctl_8
= txdesc
->Ctl_8
;
3092 Ctl2_8
= 0; /* really need to init it to 0, not txdesc->Ctl2_8, it seems */
3094 hostdesc2
= hostdesc1
+ 1;
3096 /* DON'T simply set Ctl field to 0 here globally,
3097 * it needs to maintain a consistent flag status (those are state flags!!),
3098 * otherwise it may lead to severe disruption. Only set or reset particular
3099 * flags at the exact moment this is needed... */
3101 /* let chip do RTS/CTS handshaking before sending
3102 * in case packet size exceeds threshold */
3103 if (ieeectl
->flags
& IEEE80211_TXCTL_USE_RTS_CTS
)
3104 SET_BIT(Ctl2_8
, DESC_CTL2_RTS
);
3106 CLEAR_BIT(Ctl2_8
, DESC_CTL2_RTS
);
3108 rate_cur
= ieeectl
->tx_rate
;
3109 if (unlikely(!rate_cur
)) {
3110 acx_log(LOG_WARNING
, L_ANY
, "driver bug! bad ratemask\n");
3114 /* used in tx cleanup routine for auto rate and accounting: */
3115 /* put_txcr(adev, txdesc, clt, rate_cur); deprecated by mac80211 */
3117 txdesc
->total_length
= cpu_to_le16(len
);
3118 wlhdr_len
= ieee80211_get_hdrlen(le16_to_cpu(wireless_header
->frame_control
));
3119 hostdesc2
->length
= cpu_to_le16(len
- wlhdr_len
);
3121 if (!ieeectl->do_not_encrypt && ieeectl->key_idx>= 0)
3123 u16 key_idx = (u16)(ieeectl->key_idx);
3124 struct acx_key* key = &(adev->key[key_idx]);
3128 memcpy(ieeehdr->wep_iv, ((u8*)wireless_header) + wlhdr_len, 4);
3132 if (IS_ACX111(adev
)) {
3133 /* note that if !txdesc->do_auto, txrate->cur
3134 ** has only one nonzero bit */
3135 txdesc
->u
.r2
.rate111
= cpu_to_le16(rate_cur
3136 /* WARNING: I was never able to make it work with prism54 AP.
3137 ** It was falling down to 1Mbit where shortpre is not applicable,
3138 ** and not working at all at "5,11 basic rates only" setting.
3139 ** I even didn't see tx packets in radio packet capture.
3140 ** Disabled for now --vda */
3141 /*| ((clt->shortpre && clt->cur!=RATE111_1) ? RATE111_SHORTPRE : 0) */
3143 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3144 /* should add this to rate111 above as necessary */
3145 |(clt
->pbcc511
? RATE111_PBCC511
: 0)
3147 hostdesc1
->length
= cpu_to_le16(len
);
3148 } else { /* ACX100 */
3149 u8 rate_100
= ieeectl
->tx_rate
;
3150 txdesc
->u
.r1
.rate
= rate_100
;
3151 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3153 if (n
== RATE100_5
|| n
== RATE100_11
)
3154 n
|= RATE100_PBCC511
;
3157 if (clt
->shortpre
&& (clt
->cur
!= RATE111_1
))
3158 SET_BIT(Ctl_8
, DESC_CTL_SHORT_PREAMBLE
); /* set Short Preamble */
3160 /* set autodma and reclaim and 1st mpdu */
3162 DESC_CTL_AUTODMA
| DESC_CTL_RECLAIM
|
3163 DESC_CTL_FIRSTFRAG
);
3164 #if ACX_FRAGMENTATION
3165 /* SET_BIT(Ctl2_8, DESC_CTL2_MORE_FRAG); cannot set it unconditionally, needs to be set for all non-last fragments */
3167 hostdesc1
->length
= cpu_to_le16(wlhdr_len
);
3169 /* don't need to clean ack/rts statistics here, already
3170 * done on descr cleanup */
3172 /* clears HOSTOWN and ACXDONE bits, thus telling that the descriptors
3173 * are now owned by the acx100; do this as LAST operation */
3174 CLEAR_BIT(Ctl_8
, DESC_CTL_ACXDONE_HOSTOWN
);
3175 /* flush writes before we release hostdesc to the adapter here */
3177 CLEAR_BIT(hostdesc1
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
3178 CLEAR_BIT(hostdesc2
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
3180 /* write back modified flags */
3181 CLEAR_BIT(Ctl2_8
, DESC_CTL2_WEP
);
3182 txdesc
->Ctl2_8
= Ctl2_8
;
3183 txdesc
->Ctl_8
= Ctl_8
;
3184 /* unused: txdesc->tx_time = cpu_to_le32(jiffies); */
3186 /* flush writes before we tell the adapter that it's its turn now */
3187 write_reg16(adev
, ACX_IO_INT_TRIG
, INT_TRIG_TXPRC
);
3189 /* log the packet content AFTER sending it,
3190 * in order to not delay sending any further than absolutely needed
3191 * Do separate logs for acx100/111 to have human-readable rates */
3192 memcpy(&(hostdesc1
->txstatus
.control
),ieeectl
,sizeof(struct ieee80211_tx_control
));
3193 hostdesc1
->skb
= skb
;
3199 /***********************************************************************
3200 ** acxpci_l_clean_txdesc
3202 ** This function resets the txdescs' status when the ACX100
3203 ** signals the TX done IRQ (txdescs have been processed), starting with
3204 ** the pool index of the descriptor which we would use next,
3205 ** in order to make sure that we can be as fast as possible
3206 ** in filling new txdescs.
3207 ** Everytime we get called we know where the next packet to be cleaned is.
3211 static inline void log_txbuffer(const acx_device_t
* adev
)
3215 static void log_txbuffer(acx_device_t
* adev
)
3220 /* no FN_ENTER here, we don't want that */
3221 /* no locks here, since it's entirely non-critical code */
3222 txdesc
= adev
->txdesc_start
;
3223 if (unlikely(!txdesc
))
3225 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "tx: desc->Ctl8's:");
3226 for (i
= 0; i
< TX_CNT
; i
++) {
3227 printk(" %02X", txdesc
->Ctl_8
);
3228 txdesc
= advance_txdesc(adev
, txdesc
, 1);
3235 static void handle_tx_error(acx_device_t
* adev
, u8 error
, unsigned int finger
,
3236 struct ieee80211_tx_status
*status
)
3238 const char *err
= "unknown error";
3240 /* hmm, should we handle this as a mask
3241 * of *several* bits?
3242 * For now I think only caring about
3243 * individual bits is ok... */
3246 err
= "no Tx due to error in other fragment";
3247 /* adev->wstats.discard.fragment++; */
3251 adev
->stats
.tx_aborted_errors
++;
3254 err
= "Tx desc wrong parameters";
3255 /* adev->wstats.discard.misc++; */
3258 err
= "WEP key not found";
3259 /* adev->wstats.discard.misc++; */
3262 err
= "MSDU lifetime timeout? - try changing "
3263 "'iwconfig retry lifetime XXX'";
3264 /* adev->wstats.discard.misc++; */
3267 err
= "excessive Tx retries due to either distance "
3268 "too high or unable to Tx or Tx frame error - "
3269 "try changing 'iwconfig txpower XXX' or "
3270 "'sens'itivity or 'retry'";
3271 /* adev->wstats.discard.retries++; */
3272 /* Tx error 0x20 also seems to occur on
3273 * overheating, so I'm not sure whether we
3274 * actually want to do aggressive radio recalibration,
3275 * since people maybe won't notice then that their hardware
3276 * is slowly getting cooked...
3277 * Or is it still a safe long distance from utter
3278 * radio non-functionality despite many radio recalibs
3279 * to final destructive overheating of the hardware?
3280 * In this case we really should do recalib here...
3281 * I guess the only way to find out is to do a
3282 * potentially fatal self-experiment :-\
3283 * Or maybe only recalib in case we're using Tx
3284 * rate auto (on errors switching to lower speed
3285 * --> less heat?) or 802.11 power save mode?
3287 * ok, just do it. */
3288 if (++adev
->retry_errors_msg_ratelimit
% 4 == 0) {
3289 if (adev
->retry_errors_msg_ratelimit
<= 20) {
3290 acx_log(LOG_WARNING
, L_ANY
,
3291 "%s: several excessive Tx "
3292 "retry errors occurred, attempting "
3293 "to recalibrate radio\n",
3294 wiphy_name(adev
->ieee
->wiphy
));
3295 acx_log(LOG_WARNING
, L_ANY
,
3296 "Radio drift might be caused by "
3297 "increasing card temperature, please "
3298 "check the card before it's too late!\n");
3299 if (adev
->retry_errors_msg_ratelimit
== 20)
3300 acx_log(LOG_WARNING
, L_ANY
,
3301 "disabling above message\n");
3304 acx_schedule_task(adev
,
3305 ACX_TASKLET_CMD_RADIO_RECALIB
);
3307 status
->excessive_retries
++;
3310 err
= "Tx buffer overflow";
3311 adev
->stats
.tx_fifo_errors
++;
3314 /* possibly ACPI C-state powersaving related!!!
3315 * (DMA timeout due to excessively high wakeup
3316 * latency after C-state activation!?)
3317 * Disable C-State powersaving and try again,
3318 * then PLEASE REPORT, I'm VERY interested in
3319 * whether my theory is correct that this is
3320 * actually the problem here.
3321 * In that case, use new Linux idle wakeup latency
3322 * requirements kernel API to prevent this issue. */
3324 /* adev->wstats.discard.misc++; */
3327 adev
->stats
.tx_errors
++;
3328 if (adev
->stats
.tx_errors
<= 20)
3329 acx_log(LOG_WARNING
, L_ANY
,
3330 "%s: tx error 0x%02X, buf %02u! (%s)\n",
3331 wiphy_name(adev
->ieee
->wiphy
), error
, finger
, err
);
3333 acx_log(LOG_WARNING
, L_ANY
,
3334 "%s: tx error 0x%02X, buf %02u!\n",
3335 wiphy_name(adev
->ieee
->wiphy
), error
, finger
);
3339 unsigned int acxpci_l_clean_txdesc(acx_device_t
* adev
)
3342 txhostdesc_t
*hostdesc
;
3346 u8 error
, ack_failures
, rts_failures
, rts_ok
, r100
;
3350 if (unlikely(acx_debug
& L_REALLYVERBOSE
))
3353 acx_log(LOG_DEBUG
, L_BUFT
, "tx: cleaning up bufs from %u\n",
3356 /* We know first descr which is not free yet. We advance it as far
3357 ** as we see correct bits set in following descs (if next desc
3358 ** is NOT free, we shouldn't advance at all). We know that in
3359 ** front of tx_tail may be "holes" with isolated free descs.
3360 ** We will catch up when all intermediate descs will be freed also */
3362 finger
= adev
->tx_tail
;
3364 while (likely(finger
!= adev
->tx_head
)) {
3365 txdesc
= get_txdesc(adev
, finger
);
3367 /* If we allocated txdesc on tx path but then decided
3368 ** to NOT use it, then it will be left as a free "bubble"
3369 ** in the "allocated for tx" part of the ring.
3370 ** We may meet it on the next ring pass here. */
3372 /* stop if not marked as "tx finished" and "host owned" */
3373 if ((txdesc
->Ctl_8
& DESC_CTL_ACXDONE_HOSTOWN
)
3374 != DESC_CTL_ACXDONE_HOSTOWN
) {
3375 if (unlikely(!num_cleaned
)) { /* maybe remove completely */
3376 acx_log(LOG_DEBUG
, L_BUFT
,
3377 "clean_txdesc: tail isn't free. "
3378 "tail:%d head:%d\n",
3379 adev
->tx_tail
, adev
->tx_head
);
3384 /* remember desc values... */
3385 error
= txdesc
->error
;
3386 ack_failures
= txdesc
->ack_failures
;
3387 rts_failures
= txdesc
->rts_failures
;
3388 rts_ok
= txdesc
->rts_ok
;
3389 r100
= txdesc
->u
.r1
.rate
;
3390 r111
= le16_to_cpu(txdesc
->u
.r2
.rate111
);
3392 /* need to check for certain error conditions before we
3393 * clean the descriptor: we still need valid descr data here */
3394 hostdesc
= get_txhostdesc(adev
, txdesc
);
3396 hostdesc
->txstatus
.flags
|= IEEE80211_TX_STATUS_ACK
;
3397 if (unlikely(0x30 & error
)) {
3398 /* only send IWEVTXDROP in case of retry or lifetime exceeded;
3399 * all other errors mean we screwed up locally */
3400 /* union iwreq_data wrqu;
3401 struct ieee80211_hdr_3addr *hdr;
3402 hdr = (struct ieee80211_hdr_3addr *) hostdesc->data;
3403 MAC_COPY(wrqu.addr.sa_data, hdr->addr1);
3405 hostdesc
->txstatus
.flags
&= ~IEEE80211_TX_STATUS_ACK
;
3408 /* ...and free the desc */
3410 txdesc
->ack_failures
= 0;
3411 txdesc
->rts_failures
= 0;
3413 /* signal host owning it LAST, since ACX already knows that this
3414 ** descriptor is finished since it set Ctl_8 accordingly. */
3415 txdesc
->Ctl_8
= DESC_CTL_HOSTOWN
;
3420 if ((adev
->tx_free
>= TX_START_QUEUE
)
3421 /* && (adev->status == ACX_STATUS_4_ASSOCIATED) */
3422 /*&& (acx_queue_stopped(adev->ieee))*/
3424 acx_log(LOG_DEBUG
, L_BUF
,
3425 "tx: wake queue (avail. Tx desc %u)\n",
3427 acx_wake_queue(adev
->ieee
, NULL
);
3430 /* do error checking, rate handling and logging
3431 * AFTER having done the work, it's faster */
3433 /* Rate handling is done in mac80211 */
3434 /* if (adev->rate_auto) {
3435 struct client *clt = get_txc(adev, txdesc);
3437 u16 cur = get_txr(adev, txdesc);
3438 if (clt->rate_cur == cur) {
3439 acx_l_handle_txrate_auto(adev, clt, cur,*/ /* intended rate */
3440 /*r100, r111,*/ /* actually used rate */
3441 /*(error & 0x30),*/ /* was there an error? */
3450 if (unlikely(error
))
3451 handle_tx_error(adev
, error
, finger
, &hostdesc
->txstatus
);
3453 if (IS_ACX111(adev
))
3454 acx_log(LOG_DEBUG
, L_BUFT
, "tx: cleaned %u: !ACK=%u "
3455 "!RTS=%u RTS=%u r111=%04X tx_free=%u\n",
3456 finger
, ack_failures
,
3457 rts_failures
, rts_ok
, r111
, adev
->tx_free
);
3459 acx_log(LOG_DEBUG
, L_BUFT
, "tx: cleaned %u: !ACK=%u "
3460 "!RTS=%u RTS=%u rate=%u\n",
3461 finger
, ack_failures
,
3462 rts_failures
, rts_ok
, r100
);
3464 /* And finally report upstream */
3467 hostdesc
->txstatus
.excessive_retries
= rts_failures
;
3468 hostdesc
->txstatus
.retry_count
= ack_failures
;
3469 ieee80211_tx_status(adev
->ieee
,hostdesc
->skb
,&hostdesc
->txstatus
);
3470 memset(&hostdesc
->txstatus
, 0, sizeof(struct ieee80211_tx_status
));
3472 /* update pointer for descr to be cleaned next */
3473 finger
= (finger
+ 1) % TX_CNT
;
3475 /* remember last position */
3476 adev
->tx_tail
= finger
;
3478 FN_EXIT1(num_cleaned
);
3482 /* clean *all* Tx descriptors, and regardless of their previous state.
3483 * Used for brute-force reset handling. */
3484 void acxpci_l_clean_txdesc_emergency(acx_device_t
* adev
)
3491 for (i
= 0; i
< TX_CNT
; i
++) {
3492 txdesc
= get_txdesc(adev
, i
);
3495 txdesc
->ack_failures
= 0;
3496 txdesc
->rts_failures
= 0;
3499 txdesc
->Ctl_8
= DESC_CTL_HOSTOWN
;
3502 adev
->tx_free
= TX_CNT
;
3508 /***********************************************************************
3509 ** acxpci_s_create_tx_host_desc_queue
3512 static void *allocate(acx_device_t
* adev
, size_t size
, dma_addr_t
* phy
,
3517 ptr
= dma_alloc_coherent(adev
->bus_dev
, size
, phy
, GFP_KERNEL
);
3520 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
3521 "%s sz=%d adr=0x%p phy=0x%08llx\n",
3522 msg
, (int)size
, ptr
, (unsigned long long)*phy
);
3523 memset(ptr
, 0, size
);
3526 acx_log(LOG_WARNING
, L_ANY
, "%s allocation FAILED (%d bytes)\n",
3532 static int acxpci_s_create_tx_host_desc_queue(acx_device_t
* adev
)
3534 txhostdesc_t
*hostdesc
;
3536 dma_addr_t hostdesc_phy
;
3537 dma_addr_t txbuf_phy
;
3542 /* allocate TX buffer */
3543 adev
->txbuf_area_size
= TX_CNT
* /*WLAN_A4FR_MAXLEN_WEP_FCS*/ (30 + 2312 + 4);
3544 adev
->txbuf_start
= allocate(adev
, adev
->txbuf_area_size
,
3545 &adev
->txbuf_startphy
, "txbuf_start");
3546 if (!adev
->txbuf_start
)
3549 /* allocate the TX host descriptor queue pool */
3550 adev
->txhostdesc_area_size
= TX_CNT
* 2 * sizeof(*hostdesc
);
3551 adev
->txhostdesc_start
= allocate(adev
, adev
->txhostdesc_area_size
,
3552 &adev
->txhostdesc_startphy
,
3553 "txhostdesc_start");
3554 if (!adev
->txhostdesc_start
)
3556 /* check for proper alignment of TX host descriptor pool */
3557 if ((long)adev
->txhostdesc_start
& 3) {
3558 acx_log(LOG_WARNING
, L_ANY
,
3559 "driver bug: dma alloc returns unaligned address\n");
3563 hostdesc
= adev
->txhostdesc_start
;
3564 hostdesc_phy
= adev
->txhostdesc_startphy
;
3565 txbuf
= adev
->txbuf_start
;
3566 txbuf_phy
= adev
->txbuf_startphy
;
3569 /* Each tx buffer is accessed by hardware via
3570 ** txdesc -> txhostdesc(s) -> txbuffer(s).
3571 ** We use only one txhostdesc per txdesc, but it looks like
3572 ** acx111 is buggy: it accesses second txhostdesc
3573 ** (via hostdesc.desc_phy_next field) even if
3574 ** txdesc->length == hostdesc->length and thus
3575 ** entire packet was placed into first txhostdesc.
3576 ** Due to this bug acx111 hangs unless second txhostdesc
3577 ** has le16_to_cpu(hostdesc.length) = 3 (or larger)
3578 ** Storing NULL into hostdesc.desc_phy_next
3579 ** doesn't seem to help.
3581 ** Update: although it worked on Xterasys XN-2522g
3582 ** with len=3 trick, WG311v2 is even more bogus, doesn't work.
3583 ** Keeping this code (#ifdef'ed out) for documentational purposes.
3585 for (i
= 0; i
< TX_CNT
* 2; i
++) {
3586 hostdesc_phy
+= sizeof(*hostdesc
);
3588 hostdesc
->data_phy
= cpu2acx(txbuf_phy
);
3589 /* hostdesc->data_offset = ... */
3590 /* hostdesc->reserved = ... */
3591 hostdesc
->Ctl_16
= cpu_to_le16(DESC_CTL_HOSTOWN
);
3592 /* hostdesc->length = ... */
3593 hostdesc
->desc_phy_next
= cpu2acx(hostdesc_phy
);
3594 hostdesc
->pNext
= ptr2acx(NULL
);
3595 /* hostdesc->Status = ... */
3596 /* below: non-hardware fields */
3597 hostdesc
->data
= txbuf
;
3599 txbuf
+= WLAN_A4FR_MAXLEN_WEP_FCS
;
3600 txbuf_phy
+= WLAN_A4FR_MAXLEN_WEP_FCS
;
3602 /* hostdesc->data_phy = ... */
3603 /* hostdesc->data_offset = ... */
3604 /* hostdesc->reserved = ... */
3605 /* hostdesc->Ctl_16 = ... */
3606 hostdesc
->length
= cpu_to_le16(3); /* bug workaround */
3607 /* hostdesc->desc_phy_next = ... */
3608 /* hostdesc->pNext = ... */
3609 /* hostdesc->Status = ... */
3610 /* below: non-hardware fields */
3611 /* hostdesc->data = ... */
3616 /* We initialize two hostdescs so that they point to adjacent
3617 ** memory areas. Thus txbuf is really just a contiguous memory area */
3618 for (i
= 0; i
< TX_CNT
* 2; i
++) {
3619 hostdesc_phy
+= sizeof(*hostdesc
);
3621 hostdesc
->data_phy
= cpu2acx(txbuf_phy
);
3622 /* done by memset(0): hostdesc->data_offset = 0; */
3623 /* hostdesc->reserved = ... */
3624 hostdesc
->Ctl_16
= cpu_to_le16(DESC_CTL_HOSTOWN
);
3625 /* hostdesc->length = ... */
3626 hostdesc
->desc_phy_next
= cpu2acx(hostdesc_phy
);
3627 /* done by memset(0): hostdesc->pNext = ptr2acx(NULL); */
3628 /* hostdesc->Status = ... */
3629 /* ->data is a non-hardware field: */
3630 hostdesc
->data
= txbuf
;
3633 txbuf
+= 24 /*WLAN_HDR_A3_LEN*/;
3634 txbuf_phy
+= 24 /*WLAN_HDR_A3_LEN*/;
3636 txbuf
+= 30 + 2132 + 4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3637 txbuf_phy
+= 30 + 2132 +4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3642 hostdesc
->desc_phy_next
= cpu2acx(adev
->txhostdesc_startphy
);
3647 acx_log(LOG_WARNING
, L_ANY
, "create_tx_host_desc_queue FAILED\n");
3648 /* dealloc will be done by free function on error case */
3654 /***************************************************************
3655 ** acxpci_s_create_rx_host_desc_queue
3657 /* the whole size of a data buffer (header plus data body)
3658 * plus 32 bytes safety offset at the end */
3659 #define RX_BUFFER_SIZE (sizeof(rxbuffer_t) + 32)
3661 static int acxpci_s_create_rx_host_desc_queue(acx_device_t
* adev
)
3663 rxhostdesc_t
*hostdesc
;
3665 dma_addr_t hostdesc_phy
;
3666 dma_addr_t rxbuf_phy
;
3671 /* allocate the RX host descriptor queue pool */
3672 adev
->rxhostdesc_area_size
= RX_CNT
* sizeof(*hostdesc
);
3673 adev
->rxhostdesc_start
= allocate(adev
, adev
->rxhostdesc_area_size
,
3674 &adev
->rxhostdesc_startphy
,
3675 "rxhostdesc_start");
3676 if (!adev
->rxhostdesc_start
)
3678 /* check for proper alignment of RX host descriptor pool */
3679 if ((long)adev
->rxhostdesc_start
& 3) {
3680 acx_log(LOG_WARNING
, L_ANY
,
3681 "driver bug: dma alloc returns unaligned address\n");
3685 /* allocate Rx buffer pool which will be used by the acx
3686 * to store the whole content of the received frames in it */
3687 adev
->rxbuf_area_size
= RX_CNT
* RX_BUFFER_SIZE
;
3688 adev
->rxbuf_start
= allocate(adev
, adev
->rxbuf_area_size
,
3689 &adev
->rxbuf_startphy
, "rxbuf_start");
3690 if (!adev
->rxbuf_start
)
3693 rxbuf
= adev
->rxbuf_start
;
3694 rxbuf_phy
= adev
->rxbuf_startphy
;
3695 hostdesc
= adev
->rxhostdesc_start
;
3696 hostdesc_phy
= adev
->rxhostdesc_startphy
;
3698 /* don't make any popular C programming pointer arithmetic mistakes
3699 * here, otherwise I'll kill you...
3700 * (and don't dare asking me why I'm warning you about that...) */
3701 for (i
= 0; i
< RX_CNT
; i
++) {
3702 hostdesc
->data
= rxbuf
;
3703 hostdesc
->data_phy
= cpu2acx(rxbuf_phy
);
3704 hostdesc
->length
= cpu_to_le16(RX_BUFFER_SIZE
);
3705 CLEAR_BIT(hostdesc
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
3707 rxbuf_phy
+= sizeof(*rxbuf
);
3708 hostdesc_phy
+= sizeof(*hostdesc
);
3709 hostdesc
->desc_phy_next
= cpu2acx(hostdesc_phy
);
3713 hostdesc
->desc_phy_next
= cpu2acx(adev
->rxhostdesc_startphy
);
3717 acx_log(LOG_WARNING
, L_ANY
, "create_rx_host_desc_queue FAILED\n");
3718 /* dealloc will be done by free function on error case */
3724 /***************************************************************
3725 ** acxpci_s_create_hostdesc_queues
3727 int acxpci_s_create_hostdesc_queues(acx_device_t
* adev
)
3730 result
= acxpci_s_create_tx_host_desc_queue(adev
);
3733 result
= acxpci_s_create_rx_host_desc_queue(adev
);
3738 /***************************************************************
3739 ** acxpci_create_tx_desc_queue
3741 static void acxpci_create_tx_desc_queue(acx_device_t
* adev
, u32 tx_queue_start
)
3744 txhostdesc_t
*hostdesc
;
3745 dma_addr_t hostmemptr
;
3751 if (IS_ACX100(adev
))
3752 adev
->txdesc_size
= sizeof(*txdesc
);
3754 /* the acx111 txdesc is 4 bytes larger */
3755 adev
->txdesc_size
= sizeof(*txdesc
) + 4;
3757 adev
->txdesc_start
= (txdesc_t
*) (adev
->iobase2
+ tx_queue_start
);
3759 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "adev->iobase2=%p\n"
3760 "tx_queue_start=%08X\n adev->txdesc_start=%p\n",
3761 adev
->iobase2
, tx_queue_start
, adev
->txdesc_start
);
3763 adev
->tx_free
= TX_CNT
;
3764 /* done by memset: adev->tx_head = 0; */
3765 /* done by memset: adev->tx_tail = 0; */
3766 txdesc
= adev
->txdesc_start
;
3767 mem_offs
= tx_queue_start
;
3768 hostmemptr
= adev
->txhostdesc_startphy
;
3769 hostdesc
= adev
->txhostdesc_start
;
3771 if (IS_ACX111(adev
)) {
3772 /* ACX111 has a preinitialized Tx buffer! */
3773 /* loop over whole send pool */
3774 /* FIXME: do we have to do the hostmemptr stuff here?? */
3775 for (i
= 0; i
< TX_CNT
; i
++) {
3776 txdesc
->HostMemPtr
= ptr2acx(hostmemptr
);
3777 txdesc
->Ctl_8
= DESC_CTL_HOSTOWN
;
3778 /* reserve two (hdr desc and payload desc) */
3780 hostmemptr
+= 2 * sizeof(*hostdesc
);
3781 txdesc
= advance_txdesc(adev
, txdesc
, 1);
3784 /* ACX100 Tx buffer needs to be initialized by us */
3785 /* clear whole send pool. sizeof is safe here (we are acx100) */
3786 memset(adev
->txdesc_start
, 0, TX_CNT
* sizeof(*txdesc
));
3788 /* loop over whole send pool */
3789 for (i
= 0; i
< TX_CNT
; i
++) {
3790 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
3791 "configure card tx descriptor: 0x%p, "
3792 "size: 0x%X\n", txdesc
, adev
->txdesc_size
);
3794 /* pointer to hostdesc memory */
3795 txdesc
->HostMemPtr
= ptr2acx(hostmemptr
);
3796 /* initialise ctl */
3797 txdesc
->Ctl_8
= (DESC_CTL_HOSTOWN
| DESC_CTL_RECLAIM
3798 | DESC_CTL_AUTODMA
|
3799 DESC_CTL_FIRSTFRAG
);
3800 /* done by memset(0): txdesc->Ctl2_8 = 0; */
3801 /* point to next txdesc */
3803 cpu2acx(mem_offs
+ adev
->txdesc_size
);
3804 /* reserve two (hdr desc and payload desc) */
3806 hostmemptr
+= 2 * sizeof(*hostdesc
);
3807 /* go to the next one */
3808 mem_offs
+= adev
->txdesc_size
;
3809 /* ++ is safe here (we are acx100) */
3812 /* go back to the last one */
3814 /* and point to the first making it a ring buffer */
3815 txdesc
->pNextDesc
= cpu2acx(tx_queue_start
);
3821 /***************************************************************
3822 ** acxpci_create_rx_desc_queue
3824 static void acxpci_create_rx_desc_queue(acx_device_t
* adev
, u32 rx_queue_start
)
3832 /* done by memset: adev->rx_tail = 0; */
3834 /* ACX111 doesn't need any further config: preconfigures itself.
3835 * Simply print ring buffer for debugging */
3836 if (IS_ACX111(adev
)) {
3837 /* rxdesc_start already set here */
3839 adev
->rxdesc_start
=
3840 (rxdesc_t
*) ((u8
*) adev
->iobase2
+ rx_queue_start
);
3842 rxdesc
= adev
->rxdesc_start
;
3843 for (i
= 0; i
< RX_CNT
; i
++) {
3844 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
3845 "rx descriptor %d @ 0x%p\n", i
, rxdesc
);
3846 rxdesc
= adev
->rxdesc_start
= (rxdesc_t
*)
3847 (adev
->iobase2
+ acx2cpu(rxdesc
->pNextDesc
));
3850 /* we didn't pre-calculate rxdesc_start in case of ACX100 */
3851 /* rxdesc_start should be right AFTER Tx pool */
3852 adev
->rxdesc_start
= (rxdesc_t
*)
3853 ((u8
*) adev
->txdesc_start
+ (TX_CNT
* sizeof(txdesc_t
)));
3854 /* NB: sizeof(txdesc_t) above is valid because we know
3855 ** we are in if (acx100) block. Beware of cut-n-pasting elsewhere!
3856 ** acx111's txdesc is larger! */
3858 memset(adev
->rxdesc_start
, 0, RX_CNT
* sizeof(*rxdesc
));
3860 /* loop over whole receive pool */
3861 rxdesc
= adev
->rxdesc_start
;
3862 mem_offs
= rx_queue_start
;
3863 for (i
= 0; i
< RX_CNT
; i
++) {
3864 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
3865 "rx descriptor @ 0x%p\n", rxdesc
);
3866 rxdesc
->Ctl_8
= DESC_CTL_RECLAIM
| DESC_CTL_AUTODMA
;
3867 /* point to next rxdesc */
3868 rxdesc
->pNextDesc
= cpu2acx(mem_offs
+ sizeof(*rxdesc
));
3869 /* go to the next one */
3870 mem_offs
+= sizeof(*rxdesc
);
3873 /* go to the last one */
3876 /* and point to the first making it a ring buffer */
3877 rxdesc
->pNextDesc
= cpu2acx(rx_queue_start
);
3883 /***************************************************************
3884 ** acxpci_create_desc_queues
3887 acxpci_create_desc_queues(acx_device_t
* adev
, u32 tx_queue_start
,
3890 acxpci_create_tx_desc_queue(adev
, tx_queue_start
);
3891 acxpci_create_rx_desc_queue(adev
, rx_queue_start
);
3895 /***************************************************************
3896 ** acxpci_s_proc_diag_output
3898 char *acxpci_s_proc_diag_output(char *p
, acx_device_t
* adev
)
3900 const char *rtl
, *thd
, *ttl
;
3901 rxhostdesc_t
*rxhostdesc
;
3907 p
+= sprintf(p
, "** Rx buf **\n");
3908 rxhostdesc
= adev
->rxhostdesc_start
;
3910 for (i
= 0; i
< RX_CNT
; i
++) {
3911 rtl
= (i
== adev
->rx_tail
) ? " [tail]" : "";
3912 if ((rxhostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
3914 Status
& cpu_to_le32(DESC_STATUS_FULL
)))
3915 p
+= sprintf(p
, "%02u FULL%s\n", i
, rtl
);
3917 p
+= sprintf(p
, "%02u empty%s\n", i
, rtl
);
3920 /* p += sprintf(p, "** Tx buf (free %d, Linux netqueue %s) **\n",
3922 acx_queue_stopped(adev->ieee) ? "STOPPED" : "running");*/
3923 txdesc
= adev
->txdesc_start
;
3925 for (i
= 0; i
< TX_CNT
; i
++) {
3926 thd
= (i
== adev
->tx_head
) ? " [head]" : "";
3927 ttl
= (i
== adev
->tx_tail
) ? " [tail]" : "";
3928 if (txdesc
->Ctl_8
& DESC_CTL_ACXDONE
)
3929 p
+= sprintf(p
, "%02u free (%02X)%s%s\n", i
,
3930 txdesc
->Ctl_8
, thd
, ttl
);
3932 p
+= sprintf(p
, "%02u tx (%02X)%s%s\n", i
,
3933 txdesc
->Ctl_8
, thd
, ttl
);
3934 txdesc
= advance_txdesc(adev
, txdesc
, 1);
3939 "txbuf_start %p, txbuf_area_size %u, txbuf_startphy %08llx\n"
3940 "txdesc_size %u, txdesc_start %p\n"
3941 "txhostdesc_start %p, txhostdesc_area_size %u, txhostdesc_startphy %08llx\n"
3943 "rxhostdesc_start %p, rxhostdesc_area_size %u, rxhostdesc_startphy %08llx\n"
3944 "rxbuf_start %p, rxbuf_area_size %u, rxbuf_startphy %08llx\n",
3945 adev
->txbuf_start
, adev
->txbuf_area_size
,
3946 (unsigned long long)adev
->txbuf_startphy
,
3947 adev
->txdesc_size
, adev
->txdesc_start
,
3948 adev
->txhostdesc_start
, adev
->txhostdesc_area_size
,
3949 (unsigned long long)adev
->txhostdesc_startphy
,
3951 adev
->rxhostdesc_start
, adev
->rxhostdesc_area_size
,
3952 (unsigned long long)adev
->rxhostdesc_startphy
,
3953 adev
->rxbuf_start
, adev
->rxbuf_area_size
,
3954 (unsigned long long)adev
->rxbuf_startphy
);
3961 /***********************************************************************
3963 int acxpci_proc_eeprom_output(char *buf
, acx_device_t
* adev
)
3970 for (i
= 0; i
< 0x400; i
++) {
3971 acxpci_read_eeprom_byte(adev
, i
, p
++);
3979 /***********************************************************************
3981 int acx100pci_s_set_tx_level(acx_device_t
* adev
, u8 level_dbm
)
3983 /* since it can be assumed that at least the Maxim radio has a
3984 * maximum power output of 20dBm and since it also can be
3985 * assumed that these values drive the DAC responsible for
3986 * setting the linear Tx level, I'd guess that these values
3987 * should be the corresponding linear values for a dBm value,
3988 * in other words: calculate the values from that formula:
3989 * Y [dBm] = 10 * log (X [mW])
3990 * then scale the 0..63 value range onto the 1..100mW range (0..20 dBm)
3991 * and you're done...
3992 * Hopefully that's ok, but you never know if we're actually
3993 * right... (especially since Windows XP doesn't seem to show
3994 * actual Tx dBm values :-P) */
3996 /* NOTE: on Maxim, value 30 IS 30mW, and value 10 IS 10mW - so the
3997 * values are EXACTLY mW!!! Not sure about RFMD and others,
3999 static const u8 dbm2val_maxim
[21] = {
4007 static const u8 dbm2val_rfmd
[21] = {
4017 switch (adev
->radio_type
) {
4018 case RADIO_MAXIM_0D
:
4019 table
= &dbm2val_maxim
[0];
4022 case RADIO_RALINK_15
:
4023 table
= &dbm2val_rfmd
[0];
4026 acx_log(LOG_WARNING
, L_ANY
, "%s: unknown/unsupported radio type, "
4027 "cannot modify tx power level yet!\n",
4028 wiphy_name(adev
->ieee
->wiphy
));
4031 acx_log(LOG_INFO
, L_ANY
,
4032 "%s: changing radio power level to %u dBm (%u)\n",
4033 wiphy_name(adev
->ieee
->wiphy
), level_dbm
, table
[level_dbm
]);
4034 acxpci_s_write_phy_reg(adev
, 0x11, table
[level_dbm
]);
4039 struct vlynq_reg_config
{
4044 struct vlynq_known
{
4047 struct vlynq_mapping rx_mapping
[4];
4051 struct vlynq_reg_config regs
[10];
4054 #define CHIP_TNETW1130 0x00000009
4055 #define CHIP_TNETW1350 0x00000029
4057 static struct vlynq_known known_devices
[] = {
4059 .chip_id
= CHIP_TNETW1130
, .name
= "TI TNETW1130",
4061 { .size
= 0x22000, .offset
= 0xf0000000 },
4062 { .size
= 0x40000, .offset
= 0xc0000000 },
4063 { .size
= 0x0, .offset
= 0x0 },
4064 { .size
= 0x0, .offset
= 0x0 },
4067 .irq_type
= IRQ_TYPE_EDGE_RISING
,
4072 .value
= (0xd0000000 - PHYS_OFFSET
)
4076 .value
= (0xd0000000 - PHYS_OFFSET
)
4078 { .offset
= 0x740, .value
= 0 },
4079 { .offset
= 0x744, .value
= 0x00010000 },
4080 { .offset
= 0x764, .value
= 0x00010000 },
4084 .chip_id
= CHIP_TNETW1350
, .name
= "TI TNETW1350",
4086 { .size
= 0x100000, .offset
= 0x00300000 },
4087 { .size
= 0x80000, .offset
= 0x00000000 },
4088 { .size
= 0x0, .offset
= 0x0 },
4089 { .size
= 0x0, .offset
= 0x0 },
4092 .irq_type
= IRQ_TYPE_EDGE_RISING
,
4097 .value
= (0x60000000 - PHYS_OFFSET
)
4101 .value
= (0x60000000 - PHYS_OFFSET
)
4103 { .offset
= 0x740, .value
= 0 },
4104 { .offset
= 0x744, .value
= 0x00010000 },
4105 { .offset
= 0x764, .value
= 0x00010000 },
4110 static struct vlynq_device_id acx_vlynq_id
[] = {
4111 { CHIP_TNETW1130
, vlynq_div_auto
, 0 },
4112 { CHIP_TNETW1350
, vlynq_div_auto
, 1 },
4116 static __devinit
int vlynq_probe(struct vlynq_device
*vdev
,
4117 struct vlynq_device_id
*id
)
4119 int result
= -EIO
, i
;
4121 struct ieee80211_hw
*ieee
;
4122 acx_device_t
*adev
= NULL
;
4123 acx111_ie_configoption_t co
;
4124 struct vlynq_mapping mapping
[4] = { { 0, }, };
4125 struct vlynq_known
*match
= NULL
;
4128 result
= vlynq_enable_device(vdev
);
4132 match
= &known_devices
[id
->driver_data
];
4139 mapping
[0].offset
= ARCH_PFN_OFFSET
<< PAGE_SHIFT
;
4140 mapping
[0].size
= 0x02000000;
4141 vlynq_set_local_mapping(vdev
, vdev
->mem_start
, mapping
);
4142 vlynq_set_remote_mapping(vdev
, 0, match
->rx_mapping
);
4144 set_irq_type(vlynq_virq_to_irq(vdev
, match
->irq
), match
->irq_type
);
4146 addr
= (u32
)ioremap(vdev
->mem_start
, 0x1000);
4148 acx_log(LOG_WARNING
, L_ANY
, "%s: failed to remap io memory\n",
4154 for (i
= 0; i
< match
->num_regs
; i
++)
4155 iowrite32(match
->regs
[i
].value
,
4156 (u32
*)(addr
+ match
->regs
[i
].offset
));
4158 iounmap((void *)addr
);
4160 ieee
= ieee80211_alloc_hw(sizeof(struct acx_device
), &acxpci_hw_ops
);
4162 acx_log(LOG_WARNING
, L_ANY
,
4163 "could not allocate ieee80211 structure %s\n",
4165 goto fail_alloc_netdev
;
4167 ieee
->flags
&= ~IEEE80211_HW_RX_INCLUDES_FCS
;
4170 adev
= ieee2adev(ieee
);
4172 memset(adev
, 0, sizeof(*adev
));
4173 /** Set up our private interface **/
4174 spin_lock_init(&adev
->spinlock
); /* initial state: unlocked */
4175 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
4176 mutex_init(&adev
->mutex
);
4177 /* since nobody can see new netdev yet, we can as well
4178 ** just _presume_ that we're under sem (instead of actually taking it): */
4179 /* acx_sem_lock(adev); */
4182 adev
->bus_dev
= &vdev
->dev
;
4183 adev
->dev_type
= DEVTYPE_PCI
;
4185 /** Finished with private interface **/
4187 vlynq_set_drvdata(vdev
, ieee
);
4188 if (!request_mem_region(vdev
->mem_start
, vdev
->mem_end
- vdev
->mem_start
, "acx")) {
4189 acx_log(LOG_WARNING
, L_ANY
, "cannot reserve VLYNQ memory region\n");
4190 goto fail_request_mem_region
;
4193 adev
->iobase
= ioremap(vdev
->mem_start
, vdev
->mem_end
- vdev
->mem_start
);
4194 if (!adev
->iobase
) {
4195 acx_log(LOG_WARNING
, L_ANY
, "ioremap() FAILED\n");
4198 adev
->iobase2
= adev
->iobase
+ match
->rx_mapping
[0].size
;
4199 adev
->chip_type
= CHIPTYPE_ACX111
;
4200 adev
->chip_name
= match
->name
;
4201 adev
->io
= IO_ACX111
;
4202 adev
->irq
= vlynq_virq_to_irq(vdev
, match
->irq
);
4204 acx_log(LOG_INFO
, L_ANY
, "found %s-based wireless network card at %s, "
4205 "irq:%d, phymem:0x%x, mem:0x%p\n",
4206 match
->name
, vdev
->dev
.bus_id
, adev
->irq
,
4207 vdev
->mem_start
, adev
->iobase
);
4208 // acx_log(LOG_INFO, L_ANY,
4209 // "initial debug setting is 0x%04X\n", acx_debug);
4211 if (0 == adev
->irq
) {
4212 acx_log(LOG_WARNING
, L_ANY
, "can't use IRQ 0\n");
4215 SET_IEEE80211_DEV(ieee
, &vdev
->dev
);
4217 /* request shared IRQ handler */
4219 (adev
->irq
, acxpci_i_interrupt
, IRQF_SHARED
, KBUILD_MODNAME
, adev
)) {
4220 acx_log(LOG_WARNING
, L_ANY
, "%s: request_irq FAILED\n",
4221 wiphy_name(adev
->ieee
->wiphy
));
4225 acx_log(LOG_DEBUG
, L_IRQ
| L_REALLYVERBOSE
,
4226 "request_irq %d successful\n", adev
->irq
);
4228 /* to find crashes due to weird driver access
4229 * to unconfigured interface (ifup) */
4230 adev
->mgmt_timer
.function
= (void (*)(unsigned long))0x0000dead;
4233 /* ok, pci setup is finished, now start initializing the card */
4235 /* NB: read_reg() reads may return bogus data before reset_dev(),
4236 * since the firmware which directly controls large parts of the I/O
4237 * registers isn't initialized yet.
4238 * acx100 seems to be more affected than acx111 */
4239 if (OK
!= acxpci_s_reset_dev(adev
))
4242 if (OK
!= acx_s_init_mac(adev
))
4245 acx_s_interrogate(adev
, &co
, ACX111_IE_CONFIG_OPTIONS
);
4246 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
4247 if (OK
!= acxpci_read_eeprom_byte(adev
, 0x05, &adev
->eeprom_version
))
4248 goto fail_read_eeprom_version
;
4250 acx_s_parse_configoption(adev
, &co
);
4251 acx_s_set_defaults(adev
);
4252 acx_s_get_firmware_version(adev
); /* needs to be after acx_s_init_mac() */
4253 acx_display_hardware_details(adev
);
4255 /* Register the card, AFTER everything else has been set up,
4256 * since otherwise an ioctl could step on our feet due to
4257 * firmware operations happening in parallel or uninitialized data */
4260 acx_proc_register_entries(ieee
);
4262 /* Now we have our device, so make sure the kernel doesn't try
4263 * to send packets even though we're not associated to a network yet */
4265 /* after register_netdev() userspace may start working with dev
4266 * (in particular, on other CPUs), we only need to up the sem */
4267 /* acx_sem_unlock(adev); */
4269 acx_log(LOG_INFO
, L_ANY
, "driver " ACX_RELEASE
", net device %s, "
4270 "driver compiled against wireless extensions %d and Linux %s\n",
4271 wiphy_name(adev
->ieee
->wiphy
), WIRELESS_EXT
, UTS_RELEASE
);
4273 MAC_COPY(adev
->ieee
->wiphy
->perm_addr
, adev
->dev_addr
);
4275 acx_log(LOG_DEBUG
, L_IRQ
| L_INIT
, "using IRQ %d\n", adev
->irq
);
4277 /** done with board specific setup **/
4279 result
= acx_setup_modes(adev
);
4281 acx_log(LOG_WARNING
, L_ANY
, "can't register hwmode\n");
4282 goto fail_register_netdev
;
4285 acx_init_task_scheduler(adev
);
4286 result
= ieee80211_register_hw(adev
->ieee
);
4288 acx_log(LOG_WARNING
, L_ANY
,
4289 "acx: ieee80211_register_hw() FAILED: %d\n", result
);
4290 goto fail_register_netdev
;
4293 great_inquisitor(adev
);
4299 /* error paths: undo everything in reverse order... */
4302 acxpci_s_delete_dma_regions(adev
);
4305 fail_read_eeprom_version
:
4311 iounmap(adev
->iobase
);
4314 release_mem_region(vdev
->mem_start
, vdev
->mem_end
- vdev
->mem_start
);
4315 fail_request_mem_region
:
4316 fail_register_netdev
:
4317 ieee80211_free_hw(ieee
);
4319 vlynq_disable_device(vdev
);
4325 static void vlynq_remove(struct vlynq_device
*vdev
)
4327 struct ieee80211_hw
*hw
= vlynq_get_drvdata(vdev
);
4328 acx_device_t
*adev
= ieee2adev(hw
);
4329 unsigned long flags
;
4333 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
4334 "%s: card is unused. Skipping any release code\n",
4340 acx_lock(adev
, flags
);
4341 acx_unlock(adev
, flags
);
4342 adev
->initialized
= 0;
4344 /* If device wasn't hot unplugged... */
4345 if (adev_present(adev
)) {
4349 /* disable both Tx and Rx to shut radio down properly */
4350 if (adev
->initialized
) {
4351 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_TX
, NULL
, 0);
4352 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_RX
, NULL
, 0);
4354 acx_lock(adev
, flags
);
4355 /* disable power LED to save power :-) */
4356 acx_log(LOG_INFO
, L_INIT
,
4357 "switching off power LED to save power\n");
4358 acxpci_l_power_led(adev
, 0);
4360 acx_unlock(adev
, flags
);
4362 acx_sem_unlock(adev
);
4365 /* unregister the device to not let the kernel
4366 * (e.g. ioctls) access a half-deconfigured device
4367 * NB: this will cause acxpci_e_close() to be called,
4368 * thus we shouldn't call it under sem!
4369 * Well, netdev did, but ieee80211 stack does not, so we
4370 * have to do so manually...
4373 acx_log(LOG_INFO
, L_INIT
, "removing device %s\n",
4374 wiphy_name(adev
->ieee
->wiphy
));
4375 ieee80211_unregister_hw(adev
->ieee
);
4377 /* unregister_netdev ensures that no references to us left.
4378 * For paranoid reasons we continue to follow the rules */
4381 if (adev
->dev_state_mask
& ACX_STATE_IFACE_UP
) {
4383 CLEAR_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
4386 acx_proc_unregister_entries(adev
->ieee
);
4388 /* finally, clean up PCI bus state */
4389 acxpci_s_delete_dma_regions(adev
);
4391 iounmap(adev
->iobase
);
4393 iounmap(adev
->iobase2
);
4394 release_mem_region(vdev
->mem_start
, vdev
->mem_end
- vdev
->mem_start
);
4396 /* remove dev registration */
4398 acx_sem_unlock(adev
);
4399 vlynq_disable_device(vdev
);
4401 /* Free netdev (quite late,
4402 * since otherwise we might get caught off-guard
4403 * by a netdev timeout handler execution
4404 * expecting to see a working dev...) */
4405 ieee80211_free_hw(adev
->ieee
);
4411 static struct vlynq_driver vlynq_acx
= {
4412 .name
= "acx_vlynq",
4413 .id_table
= acx_vlynq_id
,
4414 .probe
= vlynq_probe
,
4415 .remove
= __devexit_p(vlynq_remove
),
4417 #endif /* CONFIG_VLYNQ */
4420 /***********************************************************************
4421 ** Data for init_module/cleanup_module
4424 static const struct pci_device_id acxpci_id_tbl
[] __devinitdata
= {
4426 .vendor
= PCI_VENDOR_ID_TI
,
4427 .device
= PCI_DEVICE_ID_TI_TNETW1100A
,
4428 .subvendor
= PCI_ANY_ID
,
4429 .subdevice
= PCI_ANY_ID
,
4430 .driver_data
= CHIPTYPE_ACX100
,
4433 .vendor
= PCI_VENDOR_ID_TI
,
4434 .device
= PCI_DEVICE_ID_TI_TNETW1100B
,
4435 .subvendor
= PCI_ANY_ID
,
4436 .subdevice
= PCI_ANY_ID
,
4437 .driver_data
= CHIPTYPE_ACX100
,
4440 .vendor
= PCI_VENDOR_ID_TI
,
4441 .device
= PCI_DEVICE_ID_TI_TNETW1130
,
4442 .subvendor
= PCI_ANY_ID
,
4443 .subdevice
= PCI_ANY_ID
,
4444 .driver_data
= CHIPTYPE_ACX111
,
4455 MODULE_DEVICE_TABLE(pci
, acxpci_id_tbl
);
4457 static struct pci_driver
4460 .id_table
= acxpci_id_tbl
,
4461 .probe
= acxpci_e_probe
,
4462 .remove
= __devexit_p(acxpci_e_remove
),
4464 .suspend
= acxpci_e_suspend
,
4465 .resume
= acxpci_e_resume
4466 #endif /* CONFIG_PM */
4468 #endif /* CONFIG_PCI */
4470 /***********************************************************************
4471 ** acxpci_e_init_module
4473 ** Module initialization routine, called once at module load time
4475 int __init
acxpci_e_init_module(void)
4481 #if (ACX_IO_WIDTH==32)
4482 acx_log(LOG_INFO
, L_ANY
, "compiled to use 32bit I/O access. "
4483 "I/O timing issues might occur, such as "
4484 "non-working firmware upload. Report them\n");
4486 acx_log(LOG_INFO
, L_ANY
, "compiled to use 16bit I/O access only "
4487 "(compatibility mode)\n");
4490 #ifdef __LITTLE_ENDIAN
4491 #define ENDIANNESS_STRING "running on a little-endian CPU\n"
4493 #define ENDIANNESS_STRING "running on a BIG-ENDIAN CPU\n"
4495 acx_log(LOG_INFO
, L_INIT
, ENDIANNESS_STRING
);
4496 acx_log(LOG_INFO
, L_INIT
, "PCI/VLYNQ module " ACX_RELEASE
4497 " initialized, waiting for cards to probe...\n");
4500 res
= pci_register_driver(&acxpci_drv_id
);
4502 res
= vlynq_register_driver(&vlynq_acx
);
4509 /***********************************************************************
4510 ** acxpci_e_cleanup_module
4512 ** Called at module unload time. This is our last chance to
4513 ** clean up after ourselves.
4515 void __exit
acxpci_e_cleanup_module(void)
4520 pci_unregister_driver(&acxpci_drv_id
);
4522 vlynq_unregister_driver(&vlynq_acx
);
4524 acx_log(LOG_INFO
, L_INIT
,
4525 "PCI module " ACX_RELEASE
" unloaded\n");