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>
40 /***********************************************************************
43 #define PCI_TYPE (PCI_USES_MEM | PCI_ADDR0 | PCI_NO_ACPI_WAKE)
44 #define PCI_ACX100_REGION1 0x01
45 #define PCI_ACX100_REGION1_SIZE 0x1000 /* Memory size - 4K bytes */
46 #define PCI_ACX100_REGION2 0x02
47 #define PCI_ACX100_REGION2_SIZE 0x10000 /* Memory size - 64K bytes */
49 #define PCI_ACX111_REGION1 0x00
50 #define PCI_ACX111_REGION1_SIZE 0x2000 /* Memory size - 8K bytes */
51 #define PCI_ACX111_REGION2 0x01
52 #define PCI_ACX111_REGION2_SIZE 0x20000 /* Memory size - 128K bytes */
54 /* Texas Instruments Vendor ID */
55 #define PCI_VENDOR_ID_TI 0x104c
57 /* ACX100 22Mb/s WLAN controller */
58 #define PCI_DEVICE_ID_TI_TNETW1100A 0x8400
59 #define PCI_DEVICE_ID_TI_TNETW1100B 0x8401
61 /* ACX111 54Mb/s WLAN controller */
62 #define PCI_DEVICE_ID_TI_TNETW1130 0x9066
64 /* PCI Class & Sub-Class code, Network-'Other controller' */
65 #define PCI_CLASS_NETWORK_OTHERS 0x0280
67 #define CARD_EEPROM_ID_SIZE 6
70 /* From include/linux/pci.h */
77 #define PCI_POWER_ERROR -1
79 #endif /* CONFIG_PCI */
81 /***********************************************************************
84 static irqreturn_t
acxpci_i_interrupt(int irq
, void *dev_id
);
86 static void disable_acx_irq(acx_device_t
* adev
);
88 static int acxpci_e_open(struct ieee80211_hw
*hw
);
89 static void acxpci_e_close(struct ieee80211_hw
*hw
);
90 static void acxpci_s_up(struct ieee80211_hw
*hw
);
91 static void acxpci_s_down(struct ieee80211_hw
*hw
);
93 /***********************************************************************
99 /* OS I/O routines *always* be endianness-clean but having them doesn't hurt */
100 #define acx_readl(v) le32_to_cpu(readl((v)))
101 #define acx_readw(v) le16_to_cpu(readw((v)))
102 #define acx_writew(v,r) writew(le16_to_cpu((v)), r)
103 #define acx_writel(v,r) writel(le32_to_cpu((v)), r)
106 /* #define INLINE_IO static */
107 #define INLINE_IO static inline
109 INLINE_IO u32
read_reg32(acx_device_t
* adev
, unsigned int offset
)
111 #if ACX_IO_WIDTH == 32
112 return acx_readl((u8
*) adev
->iobase
+ adev
->io
[offset
]);
114 return acx_readw((u8
*) adev
->iobase
+ adev
->io
[offset
])
115 + (acx_readw((u8
*) adev
->iobase
+ adev
->io
[offset
] + 2) << 16);
119 INLINE_IO u16
read_reg16(acx_device_t
* adev
, unsigned int offset
)
121 return acx_readw((u8
*) adev
->iobase
+ adev
->io
[offset
]);
124 INLINE_IO u8
read_reg8(acx_device_t
* adev
, unsigned int offset
)
126 return readb((u8
*) adev
->iobase
+ adev
->io
[offset
]);
129 INLINE_IO
void write_reg32(acx_device_t
* adev
, unsigned int offset
, u32 val
)
131 #if ACX_IO_WIDTH == 32
132 acx_writel(val
, (u8
*) adev
->iobase
+ adev
->io
[offset
]);
134 acx_writew(val
& 0xffff, (u8
*) adev
->iobase
+ adev
->io
[offset
]);
135 acx_writew(val
>> 16, (u8
*) adev
->iobase
+ adev
->io
[offset
] + 2);
139 INLINE_IO
void write_reg16(acx_device_t
* adev
, unsigned int offset
, u16 val
)
141 acx_writew(val
, (u8
*) adev
->iobase
+ adev
->io
[offset
]);
144 INLINE_IO
void write_reg8(acx_device_t
* adev
, unsigned int offset
, u8 val
)
146 writeb(val
, (u8
*) adev
->iobase
+ adev
->io
[offset
]);
149 /* Handle PCI posting properly:
150 * Make sure that writes reach the adapter in case they require to be executed
151 * *before* the next write, by reading a random (and safely accessible) register.
152 * This call has to be made if there is no read following (which would flush the data
153 * to the adapter), yet the written data has to reach the adapter immediately. */
154 INLINE_IO
void write_flush(acx_device_t
* adev
)
156 /* readb(adev->iobase + adev->io[IO_ACX_INFO_MAILBOX_OFFS]); */
157 /* faster version (accesses the first register, IO_ACX_SOFT_RESET,
158 * which should also be safe): */
162 INLINE_IO
int adev_present(acx_device_t
* adev
)
164 /* fast version (accesses the first register, IO_ACX_SOFT_RESET,
165 * which should be safe): */
166 return acx_readl(adev
->iobase
) != 0xffffffff;
170 /***********************************************************************
172 static inline txdesc_t
*get_txdesc(acx_device_t
* adev
, int index
)
174 return (txdesc_t
*) (((u8
*) adev
->txdesc_start
) +
175 index
* adev
->txdesc_size
);
178 static inline txdesc_t
*advance_txdesc(acx_device_t
* adev
, txdesc_t
* txdesc
,
181 return (txdesc_t
*) (((u8
*) txdesc
) + inc
* adev
->txdesc_size
);
184 static txhostdesc_t
*get_txhostdesc(acx_device_t
* adev
, txdesc_t
* txdesc
)
186 int index
= (u8
*) txdesc
- (u8
*) adev
->txdesc_start
;
190 if (unlikely(ACX_DEBUG
&& (index
% adev
->txdesc_size
))) {
191 acx_log(LOG_WARNING
, L_ANY
, "bad txdesc ptr %p\n", txdesc
);
194 index
/= adev
->txdesc_size
;
195 if (unlikely(ACX_DEBUG
&& (index
>= TX_CNT
))) {
196 acx_log(LOG_WARNING
, L_ANY
, "bad txdesc ptr %p\n", txdesc
);
202 return &adev
->txhostdesc_start
[index
* 2];
209 /***********************************************************************
210 ** EEPROM and PHY read/write helpers
212 /***********************************************************************
213 ** acxpci_read_eeprom_byte
215 ** Function called to read an octet in the EEPROM.
217 ** This function is used by acxpci_e_probe to check if the
218 ** connected card is a legal one or not.
221 ** adev ptr to acx_device structure
222 ** addr address to read in the EEPROM
223 ** charbuf ptr to a char. This is where the read octet
227 int acxpci_read_eeprom_byte(acx_device_t
* adev
, u32 addr
, u8
* charbuf
)
234 write_reg32(adev
, IO_ACX_EEPROM_CFG
, 0);
235 write_reg32(adev
, IO_ACX_EEPROM_ADDR
, addr
);
237 write_reg32(adev
, IO_ACX_EEPROM_CTL
, 2);
240 while (read_reg16(adev
, IO_ACX_EEPROM_CTL
)) {
241 /* scheduling away instead of CPU burning loop
242 * doesn't seem to work here at all:
243 * awful delay, sometimes also failure.
244 * Doesn't matter anyway (only small delay). */
245 if (unlikely(!--count
)) {
246 acx_log(LOG_WARNING
, L_ANY
,
247 "%s: timeout waiting for EEPROM read\n",
248 wiphy_name(adev
->ieee
->wiphy
));
255 *charbuf
= read_reg8(adev
, IO_ACX_EEPROM_DATA
);
256 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "EEPROM at 0x%04X = 0x%02X\n",
266 /***********************************************************************
267 ** We don't lock hw accesses here since we never r/w eeprom in IRQ
268 ** Note: this function sleeps only because of GFP_KERNEL alloc
272 acxpci_s_write_eeprom(acx_device_t
* adev
, u32 addr
, u32 len
,
275 u8
*data_verify
= NULL
;
281 acx_log(LOG_WARNING
, L_ANY
, "WARNING! I would write to EEPROM now. "
282 "Since I really DON'T want to unless you know "
283 "what you're doing (THIS CODE WILL PROBABLY "
284 "NOT WORK YET!), I will abort that now. And "
285 "definitely make sure to make a "
286 "/proc/driver/acx_wlan0_eeprom backup copy first!!! "
287 "(the EEPROM content includes the PCI config header!! "
288 "If you kill important stuff, then you WILL "
289 "get in trouble and people DID get in trouble already)\n");
294 data_verify
= kmalloc(len
, GFP_KERNEL
);
299 /* first we need to enable the OE (EEPROM Output Enable) GPIO line
300 * to be able to write to the EEPROM.
301 * NOTE: an EEPROM writing success has been reported,
302 * but you probably have to modify GPIO_OUT, too,
303 * and you probably need to activate a different GPIO
305 gpio_orig
= read_reg16(adev
, IO_ACX_GPIO_OE
);
306 write_reg16(adev
, IO_ACX_GPIO_OE
, gpio_orig
& ~1);
309 /* ok, now start writing the data out */
310 for (i
= 0; i
< len
; i
++) {
311 write_reg32(adev
, IO_ACX_EEPROM_CFG
, 0);
312 write_reg32(adev
, IO_ACX_EEPROM_ADDR
, addr
+ i
);
313 write_reg32(adev
, IO_ACX_EEPROM_DATA
, *(charbuf
+ i
));
315 write_reg32(adev
, IO_ACX_EEPROM_CTL
, 1);
318 while (read_reg16(adev
, IO_ACX_EEPROM_CTL
)) {
319 if (unlikely(!--count
)) {
320 acx_log(LOG_WARNING
, L_ANY
, "WARNING, DANGER!!! "
321 "Timeout waiting for EEPROM write\n");
328 /* disable EEPROM writing */
329 write_reg16(adev
, IO_ACX_GPIO_OE
, gpio_orig
);
332 /* now start a verification run */
333 for (i
= 0; i
< len
; i
++) {
334 write_reg32(adev
, IO_ACX_EEPROM_CFG
, 0);
335 write_reg32(adev
, IO_ACX_EEPROM_ADDR
, addr
+ i
);
337 write_reg32(adev
, IO_ACX_EEPROM_CTL
, 2);
340 while (read_reg16(adev
, IO_ACX_EEPROM_CTL
)) {
341 if (unlikely(!--count
)) {
342 acx_log(LOG_WARNING
, L_ANY
,
343 "timeout waiting for EEPROM read\n");
349 data_verify
[i
] = read_reg16(adev
, IO_ACX_EEPROM_DATA
);
352 if (0 == memcmp(charbuf
, data_verify
, len
))
353 result
= OK
; /* read data matches, success */
363 /***********************************************************************
364 ** acxpci_s_read_phy_reg
366 ** Messing with rx/tx disabling and enabling here
367 ** (write_reg32(adev, IO_ACX_ENABLE, 0b000000xx)) kills traffic
369 int acxpci_s_read_phy_reg(acx_device_t
* adev
, u32 reg
, u8
* charbuf
)
376 write_reg32(adev
, IO_ACX_PHY_ADDR
, reg
);
378 write_reg32(adev
, IO_ACX_PHY_CTL
, 2);
381 while (read_reg32(adev
, IO_ACX_PHY_CTL
)) {
382 /* scheduling away instead of CPU burning loop
383 * doesn't seem to work here at all:
384 * awful delay, sometimes also failure.
385 * Doesn't matter anyway (only small delay). */
386 if (unlikely(!--count
)) {
387 acx_log(LOG_WARNING
, L_ANY
,
388 "%s: timeout waiting for phy read\n",
389 wiphy_name(adev
->ieee
->wiphy
));
396 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "count was %u\n", count
);
397 *charbuf
= read_reg8(adev
, IO_ACX_PHY_DATA
);
399 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "radio PHY at 0x%04X = 0x%02X\n",
402 goto fail
; /* silence compiler warning */
409 /***********************************************************************
411 int acxpci_s_write_phy_reg(acx_device_t
* adev
, u32 reg
, u8 value
)
415 /* mprusko said that 32bit accesses result in distorted sensitivity
416 * on his card. Unconfirmed, looks like it's not true (most likely since we
417 * now properly flush writes). */
418 write_reg32(adev
, IO_ACX_PHY_DATA
, value
);
419 write_reg32(adev
, IO_ACX_PHY_ADDR
, reg
);
421 write_reg32(adev
, IO_ACX_PHY_CTL
, 1);
423 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
424 "radio PHY write 0x%02X at 0x%04X\n",
432 #define NO_AUTO_INCREMENT 1
434 /***********************************************************************
437 ** Write the firmware image into the card.
440 ** adev wlan device structure
441 ** fw_image firmware image.
444 ** 1 firmware image corrupted
447 ** Standard csum implementation + write to IO
450 acxpci_s_write_fw(acx_device_t
* adev
, const firmware_image_t
*fw_image
,
455 /* we skip the first four bytes which contain the control sum */
457 const u8
*p
= (u8
*) fw_image
+ 4;
461 /* start the image checksum by adding the image size value */
462 sum
= p
[0] + p
[1] + p
[2] + p
[3];
465 write_reg32(adev
, IO_ACX_SLV_END_CTL
, 0);
467 #if NO_AUTO_INCREMENT
468 write_reg32(adev
, IO_ACX_SLV_MEM_CTL
, 0); /* use basic mode */
470 write_reg32(adev
, IO_ACX_SLV_MEM_CTL
, 1); /* use autoincrement mode */
471 write_reg32(adev
, IO_ACX_SLV_MEM_ADDR
, offset
); /* configure start address */
476 size
= le32_to_cpu(fw_image
->size
) & (~3);
478 while (likely(len
< size
)) {
479 v32
= be32_to_cpu(*(u32
*) p
);
480 sum
+= p
[0] + p
[1] + p
[2] + p
[3];
484 #if NO_AUTO_INCREMENT
485 write_reg32(adev
, IO_ACX_SLV_MEM_ADDR
, offset
+ len
- 4);
488 write_reg32(adev
, IO_ACX_SLV_MEM_DATA
, v32
);
491 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
492 "firmware written, size:%d sum1:%x sum2:%x\n",
493 size
, sum
, le32_to_cpu(fw_image
->chksum
));
495 /* compare our checksum with the stored image checksum */
496 FN_EXIT1(sum
!= le32_to_cpu(fw_image
->chksum
));
497 return (sum
!= le32_to_cpu(fw_image
->chksum
));
501 /***********************************************************************
502 ** acxpci_s_validate_fw
504 ** Compare the firmware image given with
505 ** the firmware image written into the card.
508 ** adev wlan device structure
509 ** fw_image firmware image.
512 ** NOT_OK firmware image corrupted or not correctly written
515 ** Origin: Standard csum + Read IO
518 acxpci_s_validate_fw(acx_device_t
* adev
, const firmware_image_t
*fw_image
,
524 /* we skip the first four bytes which contain the control sum */
525 const u8
*p
= (u8
*) fw_image
+ 4;
529 /* start the image checksum by adding the image size value */
530 sum
= p
[0] + p
[1] + p
[2] + p
[3];
533 write_reg32(adev
, IO_ACX_SLV_END_CTL
, 0);
535 #if NO_AUTO_INCREMENT
536 write_reg32(adev
, IO_ACX_SLV_MEM_CTL
, 0); /* use basic mode */
538 write_reg32(adev
, IO_ACX_SLV_MEM_CTL
, 1); /* use autoincrement mode */
539 write_reg32(adev
, IO_ACX_SLV_MEM_ADDR
, offset
); /* configure start address */
543 size
= le32_to_cpu(fw_image
->size
) & (~3);
545 while (likely(len
< size
)) {
546 v32
= be32_to_cpu(*(u32
*) p
);
550 #if NO_AUTO_INCREMENT
551 write_reg32(adev
, IO_ACX_SLV_MEM_ADDR
, offset
+ len
- 4);
553 w32
= read_reg32(adev
, IO_ACX_SLV_MEM_DATA
);
555 if (unlikely(w32
!= v32
)) {
556 acx_log(LOG_WARNING
, L_ANY
,"FATAL: firmware upload: "
557 "data parts at offset %d don't match "
558 "(0x%08X vs. 0x%08X)! I/O timing issues "
559 "or defective memory, with DWL-xx0+? "
560 "ACX_IO_WIDTH=16 may help. Please report\n",
567 (u8
) w32
+ (u8
) (w32
>> 8) + (u8
) (w32
>> 16) +
571 /* sum control verification */
572 if (result
!= NOT_OK
) {
573 if (sum
!= le32_to_cpu(fw_image
->chksum
)) {
574 acx_log(LOG_WARNING
, L_ANY
, "FATAL: firmware upload: "
575 "checksums don't match!\n");
585 /***********************************************************************
586 ** acxpci_s_upload_fw
588 ** Called from acx_reset_dev
590 ** Origin: Derived from FW dissection
592 static int acxpci_s_upload_fw(acx_device_t
* adev
)
594 firmware_image_t
*fw_image
= NULL
;
598 char filename
[sizeof("tiacx1NNcNN")];
602 /* print exact chipset and radio ID to make sure people
603 * really get a clue on which files exactly they need to provide.
604 * Firmware loading is a frequent end-user PITA with these chipsets.
606 acx_log(LOG_INFO
, L_ANY
,
607 "need firmware for acx1%02d chipset "
608 "with radio ID %02X\n",
609 IS_ACX111(adev
)*11, adev
->radio_type
);
610 acx_log(LOG_INFO
, L_ANY
, "Please provide via firmware hotplug:\n");
611 acx_log(LOG_INFO
, L_ANY
, "either combined firmware "
612 "(single file named 'tiacx1%02dc%02X')\n"
613 "or two files (base firmware file 'tiacx1%02d' "
614 "+ radio fw 'tiacx1%02dr%02X')\n",
615 IS_ACX111(adev
)*11, adev
->radio_type
,
617 IS_ACX111(adev
)*11, adev
->radio_type
620 /* print exact chipset and radio ID to make sure people really get a
621 * clue on which files exactly they are supposed to provide, since
622 * firmware loading is the biggest enduser PITA with these chipsets.
623 * Not printing radio ID in 0xHEX in order to not confuse them into
625 * COMMENTED OUT: this was already printed above
627 // printk( "acx: need to load firmware for acx1%02d chipset with radio ID %02x, please provide via firmware hotplug:\n"
628 // "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",
629 // IS_ACX111(adev)*11, adev->radio_type);
631 /* Try combined, then main image */
632 adev
->need_radio_fw
= 0;
633 snprintf(filename
, sizeof(filename
), "tiacx1%02dc%02X",
634 IS_ACX111(adev
) * 11, adev
->radio_type
);
636 fw_image
= acx_s_read_fw(adev
->bus_dev
, filename
, &file_size
);
638 adev
->need_radio_fw
= 1;
639 filename
[sizeof("tiacx1NN") - 1] = '\0';
641 acx_s_read_fw(adev
->bus_dev
, filename
, &file_size
);
648 for (try = 1; try <= 5; try++) {
649 res
= acxpci_s_write_fw(adev
, fw_image
, 0);
650 acx_log(LOG_DEBUG
, L_INIT
| L_REALLYVERBOSE
,
651 "acx_write_fw (main/combined): %d\n", res
);
653 res
= acxpci_s_validate_fw(adev
, fw_image
, 0);
654 acx_log(LOG_DEBUG
, L_INIT
| L_REALLYVERBOSE
,
655 "acx_validate_fw (main/combined): %d\n", res
);
659 SET_BIT(adev
->dev_state_mask
, ACX_STATE_FW_LOADED
);
662 acx_log(LOG_WARNING
, L_ANY
,
663 "firmware upload attempt #%d FAILED, "
664 "retrying...\n", try);
665 acx_s_mwait(1000); /* better wait for a while... */
675 /***********************************************************************
676 ** acxpci_s_upload_radio
678 ** Uploads the appropriate radio module firmware into the card.
680 ** Origin: Standard Read/Write to IO
682 int acxpci_s_upload_radio(acx_device_t
* adev
)
685 firmware_image_t
*radio_image
;
686 acx_cmd_radioinit_t radioinit
;
691 char filename
[sizeof("tiacx1NNrNN")];
693 if (!adev
->need_radio_fw
)
698 acx_s_interrogate(adev
, &mm
, ACX1xx_IE_MEMORY_MAP
);
699 offset
= le32_to_cpu(mm
.CodeEnd
);
701 snprintf(filename
, sizeof(filename
), "tiacx1%02dr%02X",
702 IS_ACX111(adev
) * 11, adev
->radio_type
);
703 radio_image
= acx_s_read_fw(adev
->bus_dev
, filename
, &size
);
705 acx_log(LOG_WARNING
, L_ANY
, "can't load radio module '%s'\n",
710 acx_s_issue_cmd(adev
, ACX1xx_CMD_SLEEP
, NULL
, 0);
712 for (try = 1; try <= 5; try++) {
713 res
= acxpci_s_write_fw(adev
, radio_image
, offset
);
714 acx_log(LOG_DEBUG
, L_INIT
| L_REALLYVERBOSE
,
715 "acx_write_fw (radio): %d\n", res
);
717 res
= acxpci_s_validate_fw(adev
, radio_image
, offset
);
718 acx_log(LOG_DEBUG
, L_INIT
| L_REALLYVERBOSE
,
719 "acx_validate_fw (radio): %d\n", res
);
724 acx_log(LOG_WARNING
, L_ANY
,
725 "radio firmware upload attempt #%d FAILED, "
726 "retrying...\n", try);
727 acx_s_mwait(1000); /* better wait for a while... */
730 acx_s_issue_cmd(adev
, ACX1xx_CMD_WAKE
, NULL
, 0);
731 radioinit
.offset
= cpu_to_le32(offset
);
732 /* no endian conversion needed, remains in card CPU area: */
733 radioinit
.len
= radio_image
->size
;
740 /* will take a moment so let's have a big timeout */
741 acx_s_issue_cmd_timeo(adev
, ACX1xx_CMD_RADIOINIT
,
742 &radioinit
, sizeof(radioinit
),
743 CMD_TIMEOUT_MS(1000));
745 res
= acx_s_interrogate(adev
, &mm
, ACX1xx_IE_MEMORY_MAP
);
752 /***********************************************************************
753 ** acxpci_l_reset_mac
756 ** Call context: reset_dev
758 ** Origin: Standard Read/Write to IO
760 static void acxpci_l_reset_mac(acx_device_t
* adev
)
767 temp
= read_reg16(adev
, IO_ACX_ECPU_CTRL
) | 0x1;
768 write_reg16(adev
, IO_ACX_ECPU_CTRL
, temp
);
770 /* now do soft reset of eCPU, set bit */
771 temp
= read_reg16(adev
, IO_ACX_SOFT_RESET
) | 0x1;
772 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "enable soft reset\n");
773 write_reg16(adev
, IO_ACX_SOFT_RESET
, temp
);
776 /* now clear bit again: deassert eCPU reset */
777 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
778 "disable soft reset and go to init mode\n");
779 write_reg16(adev
, IO_ACX_SOFT_RESET
, temp
& ~0x1);
781 /* now start a burst read from initial EEPROM */
782 temp
= read_reg16(adev
, IO_ACX_EE_START
) | 0x1;
783 write_reg16(adev
, IO_ACX_EE_START
, temp
);
790 /***********************************************************************
791 ** acxpci_s_verify_init
793 static int acxpci_s_verify_init(acx_device_t
* adev
)
796 unsigned long timeout
;
800 timeout
= jiffies
+ 2 * HZ
;
802 u16 irqstat
= read_reg16(adev
, IO_ACX_IRQ_STATUS_NON_DES
);
803 if (irqstat
& HOST_INT_FCS_THRESHOLD
) {
805 write_reg16(adev
, IO_ACX_IRQ_ACK
,
806 HOST_INT_FCS_THRESHOLD
);
809 if (time_after(jiffies
, timeout
))
811 /* Init may take up to ~0.5 sec total */
820 /***********************************************************************
821 ** A few low-level helpers
823 ** Note: these functions are not protected by lock
824 ** and thus are never allowed to be called from IRQ.
825 ** Also they must not race with fw upload which uses same hw regs
828 /***********************************************************************
829 ** acxpci_write_cmd_type_status
831 ** Origin: Common linux implementation
835 acxpci_write_cmd_type_status(acx_device_t
* adev
, u16 type
, u16 status
)
838 acx_writel(type
| (status
<< 16), adev
->cmd_area
);
844 /***********************************************************************
845 ** acxpci_read_cmd_type_status
847 ** Origin: Common linux implementation
849 static u32
acxpci_read_cmd_type_status(acx_device_t
* adev
)
851 u32 cmd_type
, cmd_status
;
855 cmd_type
= acx_readl(adev
->cmd_area
);
856 cmd_status
= (cmd_type
>> 16);
857 cmd_type
= (u16
) cmd_type
;
859 acx_log(LOG_DEBUG
, L_CTL
, "cmd_type:%04X cmd_status:%04X [%s]\n",
860 cmd_type
, cmd_status
, acx_cmd_status_str(cmd_status
));
862 FN_EXIT1(cmd_status
);
867 /***********************************************************************
868 ** acxpci_s_reset_dev
871 ** netdevice that contains the adev variable
876 ** device is hard reset
880 ** This resets the device using low level hardware calls
881 ** as well as uploads and verifies the firmware to the card
884 static inline void init_mboxes(acx_device_t
* adev
)
886 u32 cmd_offs
, info_offs
;
890 cmd_offs
= read_reg32(adev
, IO_ACX_CMD_MAILBOX_OFFS
);
891 info_offs
= read_reg32(adev
, IO_ACX_INFO_MAILBOX_OFFS
);
892 adev
->cmd_area
= (u8
*) adev
->iobase2
+ cmd_offs
;
893 adev
->info_area
= (u8
*) adev
->iobase2
+ info_offs
;
894 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "iobase2=%p\n", adev
->iobase2
);
895 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "cmd_mbox_offset=%X cmd_area=%p\n",
896 cmd_offs
, adev
->cmd_area
);
897 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
898 "info_mbox_offset=%X info_area=%p\n",
899 info_offs
, adev
->info_area
);
904 static inline void read_eeprom_area(acx_device_t
* adev
)
912 for (offs
= 0x8c; offs
< 0xb9; offs
++)
913 acxpci_read_eeprom_byte(adev
, offs
, &tmp
);
920 int acxpci_s_reset_dev(acx_device_t
* adev
)
922 const char *msg
= "";
931 /* reset the device to make sure the eCPU is stopped
932 * to upload the firmware correctly */
934 acx_lock(adev
, flags
);
937 acxpci_l_reset_mac(adev
);
940 ecpu_ctrl
= read_reg16(adev
, IO_ACX_ECPU_CTRL
) & 1;
942 msg
= "eCPU is already running. ";
946 if (read_reg16(adev
, IO_ACX_SOR_CFG
) & 2) {
947 /* eCPU most likely means "embedded CPU" */
948 msg
= "eCPU did not start after boot from flash. ";
952 /* check sense on reset flags */
953 if (read_reg16(adev
, IO_ACX_SOR_CFG
) & 0x10) {
954 printk("%s: eCPU did not start after boot (SOR), "
955 "is this fatal?\n", wiphy_name(adev
->ieee
->wiphy
));
958 /* scan, if any, is stopped now, setting corresponding IRQ bit */
959 SET_BIT(adev
->irq_status
, HOST_INT_SCAN_COMPLETE
);
961 acx_unlock(adev
, flags
);
963 /* need to know radio type before fw load */
964 /* Need to wait for arrival of this information in a loop,
965 * most probably since eCPU runs some init code from EEPROM
966 * (started burst read in reset_mac()) which also
967 * sets the radio type ID */
971 hardware_info
= read_reg16(adev
, IO_ACX_EEPROM_INFORMATION
);
973 msg
= "eCPU didn't indicate radio type";
977 } while (!(hardware_info
& 0xff00)); /* radio type still zero? */
979 /* printk("DEBUG: count %d\n", count); */
980 adev
->form_factor
= hardware_info
& 0xff;
981 adev
->radio_type
= hardware_info
>> 8;
983 /* load the firmware */
984 if (OK
!= acxpci_s_upload_fw(adev
))
987 /* acx_s_mwait(10); this one really shouldn't be required */
989 /* now start eCPU by clearing bit */
990 write_reg16(adev
, IO_ACX_ECPU_CTRL
, ecpu_ctrl
& ~0x1);
991 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
992 "booted eCPU up and waiting for completion...\n");
994 /* wait for eCPU bootup */
995 if (OK
!= acxpci_s_verify_init(adev
)) {
996 msg
= "timeout waiting for eCPU. ";
999 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
1000 "eCPU has woken up, card is ready to be configured\n");
1003 acxpci_write_cmd_type_status(adev
, 0, 0);
1005 /* test that EEPROM is readable */
1006 read_eeprom_area(adev
);
1011 /* Finish error message. Indicate which function failed */
1013 acx_unlock(adev
, flags
);
1015 acx_log(LOG_WARNING
, L_ANY
, "%sreset_dev() FAILED\n", msg
);
1022 /***********************************************************************
1023 ** acxpci_s_issue_cmd_timeo
1025 ** Sends command to fw, extract result
1027 ** NB: we do _not_ take lock inside, so be sure to not touch anything
1028 ** which may interfere with IRQ handler operation
1030 ** TODO: busy wait is a bit silly, so:
1031 ** 1) stop doing many iters - go to sleep after first
1032 ** 2) go to waitqueue based approach: wait, not poll!
1035 #define FUNC "issue_cmd"
1039 acxpci_s_issue_cmd_timeo(acx_device_t
* adev
,
1041 void *buffer
, unsigned buflen
, unsigned cmd_timeout
)
1045 acxpci_s_issue_cmd_timeo_debug(acx_device_t
* adev
,
1049 unsigned cmd_timeout
, const char *cmdstr
)
1051 unsigned long start
= jiffies
;
1053 const char *devname
;
1057 unsigned long timeout
;
1061 devname
= wiphy_name(adev
->ieee
->wiphy
);
1062 if (!devname
|| !devname
[0] || devname
[4] == '%')
1065 acx_log(LOG_DEBUG
, L_CTL
,
1066 FUNC
"(cmd:%s,buflen:%u,timeout:%ums,type:0x%04X)\n",
1067 cmdstr
, buflen
, cmd_timeout
,
1068 buffer
? le16_to_cpu(((acx_ie_generic_t
*) buffer
)->type
) : -1);
1070 if (!(adev
->dev_state_mask
& ACX_STATE_FW_LOADED
)) {
1071 acx_log(LOG_WARNING
, L_ANY
,
1072 "%s: " FUNC
"(): firmware is not loaded yet, "
1073 "cannot execute commands!\n", devname
);
1077 if (cmd
!= ACX1xx_CMD_INTERROGATE
)
1078 acx_log_dump(LOG_DEBUG
, L_REALLYVERBOSE
, buffer
, buflen
,
1081 /* wait for firmware to become idle for our command submission */
1083 counter
= (timeout
* 1000 / HZ
) - 1; /* in ms */
1086 cmd_status
= acxpci_read_cmd_type_status(adev
);
1087 /* Test for IDLE state */
1090 if (counter
% 8 == 0) {
1091 if (time_after(jiffies
, timeout
)) {
1095 /* we waited 8 iterations, no luck. Sleep 8 ms */
1098 } while (likely(--counter
));
1101 /* the card doesn't get idle, we're in trouble */
1102 acx_log(LOG_WARNING
, L_ANY
,
1103 "%s: " FUNC
"(): cmd_status is not IDLE: 0x%04X!=0\n",
1104 devname
, cmd_status
);
1106 } else if (counter
< 190) { /* if waited >10ms... */
1107 acx_log(LOG_DEBUG
, L_CTL
| L_REALLYVERBOSE
,
1108 FUNC
"(): waited for IDLE %dms. "
1109 "Please report\n", 199 - counter
);
1112 /* now write the parameters of the command if needed */
1113 if (buffer
&& buflen
) {
1114 /* if it's an INTERROGATE command, just pass the length
1115 * of parameters to read, as data */
1117 if (cmd
== ACX1xx_CMD_INTERROGATE
)
1118 memset_io(adev
->cmd_area
+ 4, 0xAA, buflen
);
1120 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1121 memcpy_toio(adev
->cmd_area
+ 4, buffer
,
1122 (cmd
== ACX1xx_CMD_INTERROGATE
) ? 4 : buflen
);
1124 /* now write the actual command type */
1125 acxpci_write_cmd_type_status(adev
, cmd
, 0);
1126 /* execute command */
1127 write_reg16(adev
, IO_ACX_INT_TRIG
, INT_TRIG_CMD
);
1130 /* wait for firmware to process command */
1132 /* Ensure nonzero and not too large timeout.
1133 ** Also converts e.g. 100->99, 200->199
1134 ** which is nice but not essential */
1135 cmd_timeout
= (cmd_timeout
- 1) | 1;
1136 if (unlikely(cmd_timeout
> 1199))
1138 /* clear CMD_COMPLETE bit. can be set only by IRQ handler: */
1139 CLEAR_BIT(adev
->irq_status
, HOST_INT_CMD_COMPLETE
);
1140 /* we schedule away sometimes (timeout can be large) */
1141 counter
= cmd_timeout
;
1142 timeout
= jiffies
+ HZ
;
1144 if (!adev
->irqs_active
) { /* IRQ disabled: poll */
1145 irqtype
= read_reg16(adev
, IO_ACX_IRQ_STATUS_NON_DES
);
1146 if (irqtype
& HOST_INT_CMD_COMPLETE
) {
1147 write_reg16(adev
, IO_ACX_IRQ_ACK
,
1148 HOST_INT_CMD_COMPLETE
);
1151 } else { /* Wait when IRQ will set the bit */
1152 irqtype
= adev
->irq_status
;
1153 if (irqtype
& HOST_INT_CMD_COMPLETE
)
1157 if (counter
% 8 == 0) {
1158 if (time_after(jiffies
, timeout
)) {
1162 /* we waited 8 iterations, no luck. Sleep 8 ms */
1165 } while (likely(--counter
));
1167 /* save state for debugging */
1168 cmd_status
= acxpci_read_cmd_type_status(adev
);
1170 /* put the card in IDLE state */
1171 acxpci_write_cmd_type_status(adev
, 0, 0);
1173 if ((cmd_timeout
- counter
) == 0) { /* timed out! */
1174 acx_log(LOG_WARNING
, L_ANY
,
1175 "%s: " FUNC
"(): timed out %s for CMD_COMPLETE. "
1176 "irq bits:0x%04X irq_status:0x%04X timeout:%dms "
1177 "cmd_status:%d (%s)\n",
1178 devname
, (adev
->irqs_active
) ? "waiting" : "polling",
1179 irqtype
, adev
->irq_status
, cmd_timeout
,
1180 cmd_status
, acx_cmd_status_str(cmd_status
));
1181 acx_log(LOG_WARNING
, L_ANY
, "hack: don't do: 'goto bad;' "
1182 "counter: %d, cmd_timeout: %d, "
1183 "cmd_timeout-counter: %d\n",
1184 counter
, cmd_timeout
, cmd_timeout
- counter
);
1185 } else if (counter
== 0) { /* maybe timed out! */
1186 acx_log(LOG_DEBUG
, L_CTL
| L_REALLYVERBOSE
,
1187 FUNC
"(): %s for CMD_COMPLETE %dms. "
1188 "count:%d. Please report\n",
1189 (adev
->irqs_active
) ? "waited" : "polled",
1190 cmd_timeout
- counter
, counter
);
1191 } else if ((cmd_timeout
- counter
) > 30) { /* if waited >30ms... */
1192 acx_log(LOG_DEBUG
, L_CTL
| L_REALLYVERBOSE
,
1193 FUNC
"(): %s for CMD_COMPLETE %dms. "
1194 "count:%d. Please report\n",
1195 (adev
->irqs_active
) ? "waited" : "polled",
1196 cmd_timeout
- counter
, counter
);
1199 if (1 != cmd_status
) { /* it is not a 'Success' */
1200 acx_log(LOG_WARNING
, L_ANY
,
1201 "%s: " FUNC
"(): cmd_status is not SUCCESS: %d (%s). "
1202 "Took %dms of %d\n",
1203 devname
, cmd_status
, acx_cmd_status_str(cmd_status
),
1204 cmd_timeout
- counter
, cmd_timeout
);
1205 /* zero out result buffer
1206 * WARNING: this will trash stack in case of illegally large input
1208 if (buffer
&& buflen
)
1209 memset(buffer
, 0, buflen
);
1213 /* read in result parameters if needed */
1214 if (buffer
&& buflen
&& (cmd
== ACX1xx_CMD_INTERROGATE
)) {
1215 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1216 memcpy_fromio(buffer
, adev
->cmd_area
+ 4, buflen
);
1217 acx_log_dump(LOG_DEBUG
, L_REALLYVERBOSE
, buffer
, buflen
,
1218 "output buffer:\n");
1221 acx_log(LOG_DEBUG
, L_CTL
, FUNC
"(%s): took %ld jiffies to complete\n",
1222 cmdstr
, jiffies
- start
);
1227 /* Give enough info so that callers can avoid
1228 ** printing their own diagnostic messages */
1230 acx_log(LOG_WARNING
, L_ANY
,
1231 "%s: " FUNC
"(cmd:%s) FAILED\n", devname
, cmdstr
);
1233 acx_log(LOG_WARNING
, L_ANY
,
1234 "%s: " FUNC
"(cmd:0x%04X) FAILED\n", devname
, cmd
);
1242 /***********************************************************************
1244 #ifdef NONESSENTIAL_FEATURES
1245 typedef struct device_id
{
1246 unsigned char id
[6];
1251 static const device_id_t device_ids
[] = {
1253 {'G', 'l', 'o', 'b', 'a', 'l'},
1258 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
1260 "SpeedStream SS1021 or Gigafast WF721-AEX"},
1262 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85},
1264 "DrayTek Vigor 520"},
1266 {'?', '?', '?', '?', '?', '?'},
1268 "Level One WPC-0200"},
1270 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1275 static void acx_show_card_eeprom_id(acx_device_t
* adev
)
1277 unsigned char buffer
[CARD_EEPROM_ID_SIZE
];
1282 memset(&buffer
, 0, CARD_EEPROM_ID_SIZE
);
1283 /* use direct EEPROM access */
1284 for (i
= 0; i
< CARD_EEPROM_ID_SIZE
; i
++) {
1285 if (OK
!= acxpci_read_eeprom_byte(adev
,
1286 ACX100_EEPROM_ID_OFFSET
+ i
,
1288 acx_log(LOG_DEBUG
, L_ANY
, "reading EEPROM FAILED\n");
1293 for (i
= 0; i
< ARRAY_SIZE(device_ids
); i
++) {
1294 if (memcmp(&buffer
, device_ids
[i
].id
, CARD_EEPROM_ID_SIZE
))
1296 if (device_ids
[i
].descr
) {
1297 acx_log(LOG_INFO
, L_ANY
,
1298 "EEPROM card ID string check "
1299 "found %s card ID: is this %s?\n",
1300 device_ids
[i
].descr
,
1301 device_ids
[i
].type
);
1305 if (i
== ARRAY_SIZE(device_ids
)) {
1306 acx_log(LOG_WARNING
, L_ANY
,
1307 "EEPROM card ID string check found "
1308 "unknown card: expected 'Global', got '%.*s\'. "
1309 "Please report\n", CARD_EEPROM_ID_SIZE
, buffer
);
1313 #endif /* NONESSENTIAL_FEATURES */
1316 /***********************************************************************
1317 ** acxpci_free_desc_queues
1319 ** Releases the queues that have been allocated, the
1320 ** others have been initialised to NULL so this
1321 ** function can be used if only part of the queues were allocated.
1325 free_coherent(struct pci_dev
*hwdev
, size_t size
,
1326 void *vaddr
, dma_addr_t dma_handle
)
1328 dma_free_coherent(hwdev
== NULL
? NULL
: &hwdev
->dev
,
1329 size
, vaddr
, dma_handle
);
1333 void acxpci_free_desc_queues(acx_device_t
* adev
)
1335 unsigned long flags
;
1337 #define ACX_FREE_QUEUE(size, ptr, phyaddr) \
1339 free_coherent(NULL, size, ptr, phyaddr); \
1346 ACX_FREE_QUEUE(adev
->txhostdesc_area_size
, adev
->txhostdesc_start
,
1347 adev
->txhostdesc_startphy
);
1348 ACX_FREE_QUEUE(adev
->txbuf_area_size
, adev
->txbuf_start
,
1349 adev
->txbuf_startphy
);
1351 acx_lock(adev
, flags
);
1352 adev
->txdesc_start
= NULL
;
1353 acx_unlock(adev
, flags
);
1355 ACX_FREE_QUEUE(adev
->rxhostdesc_area_size
, adev
->rxhostdesc_start
,
1356 adev
->rxhostdesc_startphy
);
1357 ACX_FREE_QUEUE(adev
->rxbuf_area_size
, adev
->rxbuf_start
,
1358 adev
->rxbuf_startphy
);
1360 acx_lock(adev
, flags
);
1361 adev
->rxdesc_start
= NULL
;
1362 acx_unlock(adev
, flags
);
1368 /***********************************************************************
1369 ** acxpci_s_delete_dma_regions
1371 static void acxpci_s_delete_dma_regions(acx_device_t
* adev
)
1374 /* disable radio Tx/Rx. Shouldn't we use the firmware commands
1375 * here instead? Or are we that much down the road that it's no
1376 * longer possible here? */
1377 write_reg16(adev
, IO_ACX_ENABLE
, 0);
1381 /* NO locking for all parts of acxpci_free_desc_queues because:
1382 * while calling dma_free_coherent() interrupts need to be 'free'
1383 * but if you spinlock the whole function (acxpci_free_desc_queues)
1384 * you'll get an error */
1385 acxpci_free_desc_queues(adev
);
1391 /***********************************************************************
1394 ** Probe routine called when a PCI device w/ matching ID is found.
1395 ** Here's the sequence:
1396 ** - Allocate the PCI resources.
1397 ** - Read the PCMCIA attribute memory to make sure we have a WLAN card
1399 ** - Initialize the dev and wlan data
1400 ** - Initialize the MAC
1402 ** pdev - ptr to pci device structure containing info about pci configuration
1403 ** id - ptr to the device id entry that matched this device
1405 static const u16 IO_ACX100
[] = {
1406 0x0000, /* IO_ACX_SOFT_RESET */
1408 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1409 0x0018, /* IO_ACX_SLV_MEM_DATA */
1410 0x001c, /* IO_ACX_SLV_MEM_CTL */
1411 0x0020, /* IO_ACX_SLV_END_CTL */
1413 0x0034, /* IO_ACX_FEMR */
1415 0x007c, /* IO_ACX_INT_TRIG */
1416 0x0098, /* IO_ACX_IRQ_MASK */
1417 0x00a4, /* IO_ACX_IRQ_STATUS_NON_DES */
1418 0x00a8, /* IO_ACX_IRQ_STATUS_CLEAR */
1419 0x00ac, /* IO_ACX_IRQ_ACK */
1420 0x00b0, /* IO_ACX_HINT_TRIG */
1422 0x0104, /* IO_ACX_ENABLE */
1424 0x0250, /* IO_ACX_EEPROM_CTL */
1425 0x0254, /* IO_ACX_EEPROM_ADDR */
1426 0x0258, /* IO_ACX_EEPROM_DATA */
1427 0x025c, /* IO_ACX_EEPROM_CFG */
1429 0x0268, /* IO_ACX_PHY_ADDR */
1430 0x026c, /* IO_ACX_PHY_DATA */
1431 0x0270, /* IO_ACX_PHY_CTL */
1433 0x0290, /* IO_ACX_GPIO_OE */
1435 0x0298, /* IO_ACX_GPIO_OUT */
1437 0x02a4, /* IO_ACX_CMD_MAILBOX_OFFS */
1438 0x02a8, /* IO_ACX_INFO_MAILBOX_OFFS */
1439 0x02ac, /* IO_ACX_EEPROM_INFORMATION */
1441 0x02d0, /* IO_ACX_EE_START */
1442 0x02d4, /* IO_ACX_SOR_CFG */
1443 0x02d8 /* IO_ACX_ECPU_CTRL */
1446 static const u16 IO_ACX111
[] = {
1447 0x0000, /* IO_ACX_SOFT_RESET */
1449 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1450 0x0018, /* IO_ACX_SLV_MEM_DATA */
1451 0x001c, /* IO_ACX_SLV_MEM_CTL */
1452 0x0020, /* IO_ACX_SLV_END_CTL */
1454 0x0034, /* IO_ACX_FEMR */
1456 0x00b4, /* IO_ACX_INT_TRIG */
1457 0x00d4, /* IO_ACX_IRQ_MASK */
1458 /* we do mean NON_DES (0xf0), not NON_DES_MASK which is at 0xe0: */
1459 0x00f0, /* IO_ACX_IRQ_STATUS_NON_DES */
1460 0x00e4, /* IO_ACX_IRQ_STATUS_CLEAR */
1461 0x00e8, /* IO_ACX_IRQ_ACK */
1462 0x00ec, /* IO_ACX_HINT_TRIG */
1464 0x01d0, /* IO_ACX_ENABLE */
1466 0x0338, /* IO_ACX_EEPROM_CTL */
1467 0x033c, /* IO_ACX_EEPROM_ADDR */
1468 0x0340, /* IO_ACX_EEPROM_DATA */
1469 0x0344, /* IO_ACX_EEPROM_CFG */
1471 0x0350, /* IO_ACX_PHY_ADDR */
1472 0x0354, /* IO_ACX_PHY_DATA */
1473 0x0358, /* IO_ACX_PHY_CTL */
1475 0x0374, /* IO_ACX_GPIO_OE */
1477 0x037c, /* IO_ACX_GPIO_OUT */
1479 0x0388, /* IO_ACX_CMD_MAILBOX_OFFS */
1480 0x038c, /* IO_ACX_INFO_MAILBOX_OFFS */
1481 0x0390, /* IO_ACX_EEPROM_INFORMATION */
1483 0x0100, /* IO_ACX_EE_START */
1484 0x0104, /* IO_ACX_SOR_CFG */
1485 0x0108, /* IO_ACX_ECPU_CTRL */
1488 static const struct ieee80211_ops acxpci_hw_ops
= {
1489 .tx
= acx_i_start_xmit
,
1490 .conf_tx
= acx_net_conf_tx
,
1491 .add_interface
= acx_add_interface
,
1492 .remove_interface
= acx_remove_interface
,
1493 .start
= acxpci_e_open
,
1494 .configure_filter
= acx_i_set_multicast_list
,
1495 .stop
= acxpci_e_close
,
1496 .config
= acx_net_config
,
1497 .config_interface
= acx_config_interface
,
1498 .set_key
= acx_net_set_key
,
1499 .get_stats
= acx_e_get_stats
,
1500 .get_tx_stats
= acx_net_get_tx_stats
,
1505 static int __devinit
1506 acxpci_e_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1508 acx111_ie_configoption_t co
;
1509 unsigned long mem_region1
= 0;
1510 unsigned long mem_region2
= 0;
1511 unsigned long mem_region1_size
;
1512 unsigned long mem_region2_size
;
1513 unsigned long phymem1
;
1514 unsigned long phymem2
;
1517 acx_device_t
*adev
= NULL
;
1518 const char *chip_name
;
1522 struct ieee80211_hw
*ieee
;
1526 ieee
= ieee80211_alloc_hw(sizeof(struct acx_device
), &acxpci_hw_ops
);
1528 acx_log(LOG_WARNING
, L_ANY
,
1529 "could not allocate ieee80211 structure %s\n",
1531 goto fail_alloc_netdev
;
1533 ieee
->flags
&= ~IEEE80211_HW_RX_INCLUDES_FCS
;
1534 /* TODO: mainline doesn't support the following flags yet */
1536 ~IEEE80211_HW_MONITOR_DURING_OPER &
1537 ~IEEE80211_HW_WEP_INCLUDE_IV;
1541 adev
= ieee2adev(ieee
);
1543 memset(adev
, 0, sizeof(*adev
));
1544 /** Set up our private interface **/
1545 spin_lock_init(&adev
->spinlock
); /* initial state: unlocked */
1546 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
1547 acx_log(LOG_INFO
, L_ANY
,
1548 "mutex_init(&adev->mutex); // adev = 0x%px\n", adev
);
1549 mutex_init(&adev
->mutex
);
1550 /* since nobody can see new netdev yet, we can as well
1551 ** just _presume_ that we're under sem (instead of actually taking it): */
1552 /* acx_sem_lock(adev); */
1555 adev
->bus_dev
= &pdev
->dev
;
1556 adev
->dev_type
= DEVTYPE_PCI
;
1558 /** Finished with private interface **/
1560 /** begin board specific inits **/
1561 pci_set_drvdata(pdev
, ieee
);
1563 /* Enable the PCI device */
1564 if (pci_enable_device(pdev
)) {
1565 acx_log(LOG_WARNING
, L_ANY
, "pci_enable_device() FAILED\n");
1567 goto fail_pci_enable_device
;
1570 /* enable busmastering (required for CardBus) */
1571 pci_set_master(pdev
);
1574 /* chiptype is u8 but id->driver_data is ulong
1575 ** Works for now (possible values are 1 and 2) */
1576 chip_type
= (u8
) id
->driver_data
;
1577 /* acx100 and acx111 have different PCI memory regions */
1578 if (chip_type
== CHIPTYPE_ACX100
) {
1579 chip_name
= "ACX100";
1580 mem_region1
= PCI_ACX100_REGION1
;
1581 mem_region1_size
= PCI_ACX100_REGION1_SIZE
;
1583 mem_region2
= PCI_ACX100_REGION2
;
1584 mem_region2_size
= PCI_ACX100_REGION2_SIZE
;
1585 } else if (chip_type
== CHIPTYPE_ACX111
) {
1586 chip_name
= "ACX111";
1587 mem_region1
= PCI_ACX111_REGION1
;
1588 mem_region1_size
= PCI_ACX111_REGION1_SIZE
;
1590 mem_region2
= PCI_ACX111_REGION2
;
1591 mem_region2_size
= PCI_ACX111_REGION2_SIZE
;
1593 acx_log(LOG_WARNING
, L_ANY
,
1594 "unknown chip type 0x%04X\n", chip_type
);
1595 goto fail_unknown_chiptype
;
1598 /* Figure out our resources
1600 * Request our PCI IO regions
1602 err
= pci_request_region(pdev
, mem_region1
, "acx_1");
1604 acx_log(LOG_WARNING
, L_ANY
, "pci_request_region (1/2) FAILED!"
1605 "No cardbus support in kernel?\n");
1606 goto fail_request_mem_region1
;
1609 phymem1
= pci_resource_start(pdev
, mem_region1
);
1611 err
= pci_request_region(pdev
, mem_region2
, "acx_2");
1613 acx_log(LOG_WARNING
, L_ANY
, "pci_request_region (2/2) FAILED!\n");
1614 goto fail_request_mem_region2
;
1617 phymem2
= pci_resource_start(pdev
, mem_region2
);
1620 * We got them? Map them!
1622 * We pass 0 as the third argument to pci_iomap(): it will map the full
1623 * region in this case, which is what we want.
1626 mem1
= pci_iomap(pdev
, mem_region1
, 0);
1628 acx_log(LOG_WARNING
, L_ANY
, "ioremap() FAILED\n");
1632 mem2
= pci_iomap(pdev
, mem_region2
, 0);
1634 acx_log(LOG_WARNING
, L_ANY
, "ioremap() #2 FAILED\n");
1638 acx_log(LOG_INFO
, L_ANY
, "found %s-based wireless network card at %s, "
1639 "irq:%d, phymem1:0x%lX, phymem2:0x%lX, mem1:0x%p, "
1640 "mem1_size:%ld, mem2:0x%p, mem2_size:%ld\n",
1641 chip_name
, pci_name(pdev
), pdev
->irq
, phymem1
, phymem2
,
1642 mem1
, mem_region1_size
, mem2
, mem_region2_size
);
1643 //log(L_ANY, "initial debug setting is 0x%04X\n", acx_debug);
1644 adev
->chip_type
= chip_type
;
1645 adev
->chip_name
= chip_name
;
1646 adev
->io
= (CHIPTYPE_ACX100
== chip_type
) ? IO_ACX100
: IO_ACX111
;
1647 adev
->membase
= phymem1
;
1648 adev
->iobase
= mem1
;
1649 adev
->membase2
= phymem2
;
1650 adev
->iobase2
= mem2
;
1651 adev
->irq
= pdev
->irq
;
1654 if (0 == pdev
->irq
) {
1655 acx_log(LOG_WARNING
, L_ANY
, "can't use IRQ 0\n");
1658 SET_IEEE80211_DEV(ieee
, &pdev
->dev
);
1660 /* request shared IRQ handler */
1662 (adev
->irq
, acxpci_i_interrupt
, IRQF_SHARED
, KBUILD_MODNAME
, adev
)) {
1663 acx_log(LOG_WARNING
, L_ANY
, "%s: request_irq FAILED\n",
1664 wiphy_name(adev
->ieee
->wiphy
));
1668 acx_log(LOG_DEBUG
, L_IRQ
| L_REALLYVERBOSE
,
1669 "request_irq %d successful\n", adev
->irq
);
1671 /* to find crashes due to weird driver access
1672 * to unconfigured interface (ifup) */
1673 adev
->mgmt_timer
.function
= (void (*)(unsigned long))0x0000dead;
1676 #ifdef NONESSENTIAL_FEATURES
1677 acx_show_card_eeprom_id(adev
);
1678 #endif /* NONESSENTIAL_FEATURES */
1681 /* ok, pci setup is finished, now start initializing the card */
1683 /* NB: read_reg() reads may return bogus data before reset_dev(),
1684 * since the firmware which directly controls large parts of the I/O
1685 * registers isn't initialized yet.
1686 * acx100 seems to be more affected than acx111 */
1687 if (OK
!= acxpci_s_reset_dev(adev
))
1690 if (IS_ACX100(adev
)) {
1691 /* ACX100: configopt struct in cmd mailbox - directly after reset */
1692 memcpy_fromio(&co
, adev
->cmd_area
, sizeof(co
));
1695 if (OK
!= acx_s_init_mac(adev
))
1698 if (IS_ACX111(adev
)) {
1699 /* ACX111: configopt struct needs to be queried after full init */
1700 acx_s_interrogate(adev
, &co
, ACX111_IE_CONFIG_OPTIONS
);
1702 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
1703 if (OK
!= acxpci_read_eeprom_byte(adev
, 0x05, &adev
->eeprom_version
))
1704 goto fail_read_eeprom_version
;
1706 acx_s_parse_configoption(adev
, &co
);
1707 acx_s_set_defaults(adev
);
1708 acx_s_get_firmware_version(adev
); /* needs to be after acx_s_init_mac() */
1709 acx_display_hardware_details(adev
);
1711 /* Register the card, AFTER everything else has been set up,
1712 * since otherwise an ioctl could step on our feet due to
1713 * firmware operations happening in parallel or uninitialized data */
1716 acx_proc_register_entries(ieee
);
1718 /* Now we have our device, so make sure the kernel doesn't try
1719 * to send packets even though we're not associated to a network yet */
1721 /* after register_netdev() userspace may start working with dev
1722 * (in particular, on other CPUs), we only need to up the sem */
1723 /* acx_sem_unlock(adev); */
1725 acx_log(LOG_INFO
, L_ANY
, "driver version " ACX_RELEASE
1726 ": net device %s, driver compiled "
1727 "against wireless extensions %d and Linux %s\n",
1728 wiphy_name(adev
->ieee
->wiphy
), WIRELESS_EXT
, UTS_RELEASE
);
1730 MAC_COPY(adev
->ieee
->wiphy
->perm_addr
, adev
->dev_addr
);
1732 acx_log(LOG_INFO
, L_IRQ
| L_INIT
, "using IRQ %d\n", pdev
->irq
);
1734 /** done with board specific setup **/
1736 /* need to be able to restore PCI state after a suspend */
1738 pci_save_state(pdev
);
1741 err
= acx_setup_modes(adev
);
1743 acx_log(LOG_WARNING
, L_ANY
, "can't register hwmode\n");
1744 goto fail_register_netdev
;
1747 acx_init_task_scheduler(adev
);
1748 err
= ieee80211_register_hw(ieee
);
1750 acx_log(LOG_WARNING
, L_ANY
,
1751 "ieee80211_register_hw() FAILED: %d\n", err
);
1752 goto fail_register_netdev
;
1755 great_inquisitor(adev
);
1761 /* error paths: undo everything in reverse order... */
1764 acxpci_s_delete_dma_regions(adev
);
1765 pci_set_drvdata(pdev
, NULL
);
1768 fail_read_eeprom_version
:
1773 pci_iounmap(pdev
, mem2
);
1776 pci_iounmap(pdev
, mem1
);
1779 pci_release_region(pdev
, mem_region2
);
1781 fail_request_mem_region2
:
1782 pci_release_region(pdev
, mem_region1
);
1784 fail_request_mem_region1
:
1785 fail_unknown_chiptype
:
1786 pci_disable_device(pdev
);
1788 fail_pci_enable_device
:
1790 pci_set_power_state(pdev
, PCI_D3hot
);
1793 fail_register_netdev
:
1794 ieee80211_free_hw(ieee
);
1801 /***********************************************************************
1804 ** Shut device down (if not hot unplugged)
1805 ** and deallocate PCI resources for the acx chip.
1807 ** pdev - ptr to PCI device structure containing info about pci configuration
1809 static void __devexit
acxpci_e_remove(struct pci_dev
*pdev
)
1811 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*)pci_get_drvdata(pdev
);
1812 acx_device_t
*adev
= ieee2adev(hw
);
1813 unsigned long mem_region1
, mem_region2
;
1814 unsigned long flags
;
1818 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
1819 "%s: card is unused. Skipping any release code\n",
1824 /* If device wasn't hot unplugged... */
1825 if (adev_present(adev
)) {
1827 /* disable both Tx and Rx to shut radio down properly */
1828 if (adev
->initialized
) {
1829 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_TX
, NULL
, 0);
1830 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_RX
, NULL
, 0);
1831 adev
->initialized
= 0;
1834 /* put the eCPU to sleep to save power
1835 * Halting is not possible currently,
1836 * since not supported by all firmware versions */
1837 acx_s_issue_cmd(adev
, ACX100_CMD_SLEEP
, NULL
, 0);
1839 acx_lock(adev
, flags
);
1840 /* disable power LED to save power :-) */
1841 acx_log(LOG_INFO
, L_INIT
,
1842 "switching off power LED to save power\n");
1843 acxpci_l_power_led(adev
, 0);
1845 if (IS_ACX111(adev
)) {
1846 /* FIXME: does this actually keep halting the eCPU?
1847 * I don't think so...
1849 acxpci_l_reset_mac(adev
);
1853 temp
= read_reg16(adev
, IO_ACX_ECPU_CTRL
) | 0x1;
1854 write_reg16(adev
, IO_ACX_ECPU_CTRL
, temp
);
1857 acx_unlock(adev
, flags
);
1861 /* unregister the device to not let the kernel
1862 * (e.g. ioctls) access a half-deconfigured device
1863 * NB: this will cause acxpci_e_close() to be called,
1864 * thus we shouldn't call it under sem!
1865 * Well, netdev did, but ieee80211 stack does not, so we
1866 * have to do so manually...
1869 acx_log(LOG_INFO
, L_INIT
,
1870 "removing device %s\n", wiphy_name(adev
->ieee
->wiphy
));
1871 ieee80211_unregister_hw(adev
->ieee
);
1873 /* unregister_netdev ensures that no references to us left.
1874 * For paranoid reasons we continue to follow the rules */
1877 if (adev
->dev_state_mask
& ACX_STATE_IFACE_UP
) {
1879 CLEAR_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
1882 acx_proc_unregister_entries(adev
->ieee
);
1884 if (IS_ACX100(adev
)) {
1885 mem_region1
= PCI_ACX100_REGION1
;
1886 mem_region2
= PCI_ACX100_REGION2
;
1888 mem_region1
= PCI_ACX111_REGION1
;
1889 mem_region2
= PCI_ACX111_REGION2
;
1892 /* finally, clean up PCI bus state */
1893 acxpci_s_delete_dma_regions(adev
);
1895 iounmap(adev
->iobase
);
1897 iounmap(adev
->iobase2
);
1898 release_mem_region(pci_resource_start(pdev
, mem_region1
),
1899 pci_resource_len(pdev
, mem_region1
));
1900 release_mem_region(pci_resource_start(pdev
, mem_region2
),
1901 pci_resource_len(pdev
, mem_region2
));
1902 pci_disable_device(pdev
);
1904 /* remove dev registration */
1905 pci_set_drvdata(pdev
, NULL
);
1907 acx_sem_unlock(adev
);
1909 /* Free netdev (quite late,
1910 * since otherwise we might get caught off-guard
1911 * by a netdev timeout handler execution
1912 * expecting to see a working dev...) */
1913 ieee80211_free_hw(adev
->ieee
);
1915 /* put device into ACPI D3 mode (shutdown) */
1917 pci_set_power_state(pdev
, PCI_D3hot
);
1924 /***********************************************************************
1925 ** TODO: PM code needs to be fixed / debugged / tested.
1929 acxpci_e_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1931 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
1935 acx_log(LOG_WARNING
, L_ANY
, "suspend handler is experimental!\n");
1936 acx_log(LOG_INFO
, L_ANY
, "suspend: dev %p\n", hw
);
1938 /* if (!netif_running(ndev))
1941 adev
= ieee2adev(hw
);
1942 acx_log(LOG_INFO
, L_ANY
, "suspend: adev %p\n", adev
);
1946 ieee80211_unregister_hw(hw
); /* this one cannot sleep */
1948 /* down() does not set it to 0xffff, but here we really want that */
1949 write_reg16(adev
, IO_ACX_IRQ_MASK
, 0xffff);
1950 write_reg16(adev
, IO_ACX_FEMR
, 0x0);
1951 acxpci_s_delete_dma_regions(adev
);
1952 pci_save_state(pdev
);
1953 pci_set_power_state(pdev
, PCI_D3hot
);
1955 acx_sem_unlock(adev
);
1961 static int acxpci_e_resume(struct pci_dev
*pdev
)
1963 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
1968 acx_log(LOG_WARNING
, L_ANY
, "resume handler is experimental!\n");
1969 acx_log(LOG_INFO
, L_ANY
, "resume: got dev %p\n", hw
);
1972 adev
= ieee2adev(hw
);
1973 acx_log(LOG_INFO
, L_ANY
, "resume: got adev %p\n", adev
);
1977 pci_set_power_state(pdev
, PCI_D0
);
1978 acx_log(LOG_INFO
, L_ANY
, "resume: power state PCI_D0 set\n");
1979 pci_restore_state(pdev
);
1980 acx_log(LOG_INFO
, L_ANY
, "resume: PCI state restored\n");
1982 if (OK
!= acxpci_s_reset_dev(adev
))
1984 acx_log(LOG_INFO
, L_ANY
, "resume: device reset done\n");
1985 if (OK
!= acx_s_init_mac(adev
))
1987 acx_log(LOG_INFO
, L_ANY
, "resume: init MAC done\n");
1990 acx_log(LOG_INFO
, L_ANY
, "resume: acx up done\n");
1992 /* now even reload all card parameters as they were before suspend,
1993 * and possibly be back in the network again already :-) */
1994 if (ACX_STATE_IFACE_UP
& adev
->dev_state_mask
) {
1995 adev
->set_mask
= GETSET_ALL
;
1996 acx_s_update_card_settings(adev
);
1997 acx_log(LOG_INFO
, L_ANY
, "resume: settings updated\n");
1999 ieee80211_register_hw(hw
);
2000 acx_log(LOG_INFO
, L_ANY
, "resume: device attached\n");
2003 acx_sem_unlock(adev
);
2004 /* we need to return OK here anyway, right? */
2008 #endif /* CONFIG_PM */
2009 #endif /* CONFIG_PCI */
2011 /***********************************************************************
2014 ** This function is called by acxpci_e_open (when ifconfig sets the device as up)
2017 ** - Enables on-card interrupt requests
2018 ** - calls acx_s_start
2021 static void enable_acx_irq(acx_device_t
* adev
)
2024 write_reg16(adev
, IO_ACX_IRQ_MASK
, adev
->irq_mask
);
2025 write_reg16(adev
, IO_ACX_FEMR
, 0x8000);
2026 adev
->irqs_active
= 1;
2030 static void acxpci_s_up(struct ieee80211_hw
*hw
)
2032 acx_device_t
*adev
= ieee2adev(hw
);
2033 unsigned long flags
;
2037 acx_lock(adev
, flags
);
2038 enable_acx_irq(adev
);
2039 acx_unlock(adev
, flags
);
2041 /* acx fw < 1.9.3.e has a hardware timer, and older drivers
2042 ** used to use it. But we don't do that anymore, our OS
2043 ** has reliable software timers */
2044 init_timer(&adev
->mgmt_timer
);
2045 adev
->mgmt_timer
.function
= acx_i_timer
;
2046 adev
->mgmt_timer
.data
= (unsigned long)adev
;
2048 /* Need to set ACX_STATE_IFACE_UP first, or else
2049 ** timer won't be started by acx_set_status() */
2050 SET_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
2058 /***********************************************************************
2061 ** NB: device may be already hot unplugged if called from acxpci_e_remove()
2063 ** Disables on-card interrupt request, stops softirq and timer, stops queue,
2064 ** sets status == STOPPED
2067 static void disable_acx_irq(acx_device_t
* adev
)
2071 /* I guess mask is not 0xffff because acx100 won't signal
2072 ** cmd completion then (needed for ifup).
2073 ** I can't ifconfig up after ifconfig down'ing on my acx100 */
2074 write_reg16(adev
, IO_ACX_IRQ_MASK
, adev
->irq_mask_off
);
2075 write_reg16(adev
, IO_ACX_FEMR
, 0x0);
2076 adev
->irqs_active
= 0;
2081 static void acxpci_s_down(struct ieee80211_hw
*hw
)
2083 acx_device_t
*adev
= ieee2adev(hw
);
2087 /* Disable IRQs first, so that IRQs cannot race with us */
2088 /* then wait until interrupts have finished executing on other CPUs */
2089 disable_acx_irq(adev
); /* NO sem-locking here? */
2090 synchronize_irq(adev
->irq
);
2092 /* we really don't want to have an asynchronous tasklet disturb us
2093 ** after something vital for its job has been shut down, so
2094 ** end all remaining work now.
2096 ** NB: carrier_off (done by set_status below) would lead to
2097 ** not yet fully understood deadlock in flush_scheduled_work().
2098 ** That's why we do FLUSH first.
2100 ** NB2: we have a bad locking bug here: flush_scheduled_work()
2101 ** waits for acx_e_after_interrupt_task to complete if it is running
2102 ** on another CPU, but acx_e_after_interrupt_task
2103 ** will sleep on sem forever, because it is taken by us!
2104 ** Work around that by temporary sem unlock.
2105 ** This will fail miserably if we'll be hit by concurrent
2106 ** iwconfig or something in between. TODO! */
2107 acx_sem_unlock(adev
);
2108 flush_scheduled_work();
2111 /* This is possible:
2112 ** flush_scheduled_work -> acx_e_after_interrupt_task ->
2113 ** -> set_status(ASSOCIATED) -> wake_queue()
2114 ** That's why we stop queue _after_ flush_scheduled_work
2115 ** lock/unlock is just paranoia, maybe not needed */
2117 /* kernel/timer.c says it's illegal to del_timer_sync()
2118 ** a timer which restarts itself. We guarantee this cannot
2119 ** ever happen because acx_i_timer() never does this if
2120 ** status is ACX_STATUS_0_STOPPED */
2121 del_timer_sync(&adev
->mgmt_timer
);
2126 #ifdef CONFIG_NET_POLL_CONTROLLER
2127 void acxpci_net_poll_controller(struct net_device *net_dev)
2129 acx_device_t *adev = ndev2adev(net_dev);
2130 unsigned long flags;
2132 local_irq_save(flags);
2133 acxpci_i_interrupt(adev->irq, adev);
2134 local_irq_restore(flags);
2136 #endif*/ /* CONFIG_NET_POLL_CONTROLLER */
2138 /***********************************************************************
2141 ** Called as a result of SIOCSIFFLAGS ioctl changing the flags bit IFF_UP
2142 ** from clear to set. In other words: ifconfig up.
2146 ** >0 f/w reported error
2147 ** <0 driver reported error
2149 static int acxpci_e_open(struct ieee80211_hw
*hw
)
2151 acx_device_t
*adev
= ieee2adev(hw
);
2158 adev
->initialized
= 0;
2160 /* TODO: pci_set_power_state(pdev, PCI_D0); ? */
2165 /* We don't currently have to do anything else.
2166 * The setup of the MAC should be subsequently completed via
2167 * the mlme commands.
2168 * Higher layers know we're ready from dev->start==1 and
2169 * dev->tbusy==0. Our rx path knows to pass up received/
2170 * frames because of dev->flags&IFF_UP is true.
2172 ieee80211_start_queues(adev
->ieee
);
2174 adev
->initialized
= 1;
2175 acx_sem_unlock(adev
);
2182 /***********************************************************************
2185 ** This function stops the network functionality of the interface (invoked
2186 ** when the user calls ifconfig <wlan> down). The tx queue is halted and
2187 ** the device is marked as down.
2189 ** Called as a result of SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
2190 ** from set to clear. I.e. called by "ifconfig DEV down"
2194 ** >0 f/w reported error
2195 ** <0 driver reported error
2197 static void acxpci_e_close(struct ieee80211_hw
*hw
)
2199 acx_device_t
*adev
= ieee2adev(hw
);
2206 CLEAR_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
2207 if (adev
->initialized
) {
2212 acx_free_modes(adev
);
2213 /* disable all IRQs, release shared IRQ handler */
2214 write_reg16(adev
, IO_ACX_IRQ_MASK
, 0xffff);
2215 write_reg16(adev
, IO_ACX_FEMR
, 0x0);
2216 free_irq(adev
->irq
, adev
);
2218 /* TODO: pci_set_power_state(pdev, PCI_D3hot); ? */
2220 /* We currently don't have to do anything else.
2221 * Higher layers know we're not ready from dev->start==0 and
2222 * dev->tbusy==1. Our rx path knows to not pass up received
2223 * frames because of dev->flags&IFF_UP is false.
2225 acx_sem_unlock(adev
);
2227 acx_log(LOG_INFO
, L_INIT
, "closed device\n");
2234 /***************************************************************
2235 ** acxpci_l_process_rxdesc
2237 ** Called directly and only from the IRQ handler
2241 static inline void log_rxbuffer(const acx_device_t
* adev
)
2245 static void log_rxbuffer(const acx_device_t
* adev
)
2247 register const struct rxhostdesc
*rxhostdesc
;
2250 /* no FN_ENTER here, we don't want that */
2252 rxhostdesc
= adev
->rxhostdesc_start
;
2253 if (unlikely(!rxhostdesc
))
2255 for (i
= 0; i
< RX_CNT
; i
++) {
2256 if ((rxhostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
2257 && (rxhostdesc
->Status
& cpu_to_le32(DESC_STATUS_FULL
)))
2258 acx_log(LOG_WARNING
, L_ANY
, "rx: buf %d full\n", i
);
2264 static void acxpci_l_process_rxdesc(acx_device_t
* adev
)
2266 register rxhostdesc_t
*hostdesc
;
2267 unsigned count
, tail
;
2271 if (unlikely(acx_debug
& L_BUFR
))
2274 /* First, have a loop to determine the first descriptor that's
2275 * full, just in case there's a mismatch between our current
2276 * rx_tail and the full descriptor we're supposed to handle. */
2277 tail
= adev
->rx_tail
;
2280 hostdesc
= &adev
->rxhostdesc_start
[tail
];
2281 /* advance tail regardless of outcome of the below test */
2282 tail
= (tail
+ 1) % RX_CNT
;
2284 if ((hostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
2285 && (hostdesc
->Status
& cpu_to_le32(DESC_STATUS_FULL
)))
2286 break; /* found it! */
2288 if (unlikely(!--count
)) /* hmm, no luck: all descs empty, bail out */
2292 /* now process descriptors, starting with the first we figured out */
2294 acx_log(LOG_DEBUG
, L_BUFR
,
2295 "rx: tail=%u Ctl_16=%04X Status=%08X\n",
2296 tail
, hostdesc
->Ctl_16
, hostdesc
->Status
);
2298 acx_l_process_rxbuf(adev
, hostdesc
->data
);
2299 hostdesc
->Status
= 0;
2300 /* flush all writes before adapter sees CTL_HOSTOWN change */
2302 /* Host no longer owns this, needs to be LAST */
2303 CLEAR_BIT(hostdesc
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
2305 /* ok, descriptor is handled, now check the next descriptor */
2306 hostdesc
= &adev
->rxhostdesc_start
[tail
];
2308 /* if next descriptor is empty, then bail out */
2309 if (!(hostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
2310 || !(hostdesc
->Status
& cpu_to_le32(DESC_STATUS_FULL
)))
2313 tail
= (tail
+ 1) % RX_CNT
;
2316 adev
->rx_tail
= tail
;
2322 /***********************************************************************
2323 ** acxpci_i_interrupt
2325 ** IRQ handler (atomic context, must not sleep, blah, blah)
2328 /* scan is complete. all frames now on the receive queue are valid */
2329 #define INFO_SCAN_COMPLETE 0x0001
2330 #define INFO_WEP_KEY_NOT_FOUND 0x0002
2331 /* hw has been reset as the result of a watchdog timer timeout */
2332 #define INFO_WATCH_DOG_RESET 0x0003
2333 /* failed to send out NULL frame from PS mode notification to AP */
2334 /* recommended action: try entering 802.11 PS mode again */
2335 #define INFO_PS_FAIL 0x0004
2336 /* encryption/decryption process on a packet failed */
2337 #define INFO_IV_ICV_FAILURE 0x0005
2339 /* Info mailbox format:
2342 more bytes may follow
2343 rumors say about status:
2344 0x0000 info available (set by hw)
2345 0x0001 information received (must be set by host)
2346 0x1000 info available, mailbox overflowed (messages lost) (set by hw)
2347 but in practice we've seen:
2348 0x9000 when we did not set status to 0x0001 on prev message
2349 0x1001 when we did set it
2350 0x0000 was never seen
2351 conclusion: this is really a bitfield:
2352 0x1000 is 'info available' bit
2353 'mailbox overflowed' bit is 0x8000, not 0x1000
2354 value of 0x0000 probably means that there are no messages at all
2355 P.S. I dunno how in hell hw is supposed to notice that messages are lost -
2356 it does NOT clear bit 0x0001, and this bit will probably stay forever set
2357 after we set it once. Let's hope this will be fixed in firmware someday
2360 static void handle_info_irq(acx_device_t
* adev
)
2363 static const char *const info_type_msg
[] = {
2366 "WEP key not found",
2367 "internal watchdog reset was done",
2368 "failed to send powersave (NULL frame) notification to AP",
2369 "encrypt/decrypt on a packet has failed",
2370 "TKIP tx keys disabled",
2371 "TKIP rx keys disabled",
2372 "TKIP rx: key ID not found",
2380 "TKIP IV value exceeds thresh"
2383 u32 info_type
, info_status
;
2385 info_type
= acx_readl(adev
->info_area
);
2386 info_status
= (info_type
>> 16);
2387 info_type
= (u16
) info_type
;
2389 /* inform fw that we have read this info message */
2390 acx_writel(info_type
| 0x00010000, adev
->info_area
);
2391 write_reg16(adev
, IO_ACX_INT_TRIG
, INT_TRIG_INFOACK
);
2394 acx_log(LOG_DEBUG
, L_CTL
,
2395 "info_type:%04X info_status:%04X\n", info_type
, info_status
);
2397 acx_log(LOG_DEBUG
, L_IRQ
, "got Info IRQ: status %04X type %04X: %s\n",
2398 info_status
, info_type
,
2399 info_type_msg
[(info_type
>= ARRAY_SIZE(info_type_msg
)) ?
2405 static void log_unusual_irq(u16 irqtype
)
2408 if (!printk_ratelimit())
2413 if (irqtype
& HOST_INT_RX_DATA
) {
2416 /* HOST_INT_TX_COMPLETE */
2417 if (irqtype
& HOST_INT_TX_XFER
) {
2420 /* HOST_INT_RX_COMPLETE */
2421 if (irqtype
& HOST_INT_DTIM
) {
2424 if (irqtype
& HOST_INT_BEACON
) {
2427 if (irqtype
& HOST_INT_TIMER
) {
2430 if (irqtype
& HOST_INT_KEY_NOT_FOUND
) {
2431 printk(" Key_Not_Found");
2433 if (irqtype
& HOST_INT_IV_ICV_FAILURE
) {
2434 printk(" IV_ICV_Failure (crypto)");
2436 /* HOST_INT_CMD_COMPLETE */
2438 if (irqtype
& HOST_INT_OVERFLOW
) {
2439 printk(" Overflow");
2441 if (irqtype
& HOST_INT_PROCESS_ERROR
) {
2442 printk(" Process_Error");
2444 /* HOST_INT_SCAN_COMPLETE */
2445 if (irqtype
& HOST_INT_FCS_THRESHOLD
) {
2446 printk(" FCS_Threshold");
2448 if (irqtype
& HOST_INT_UNKNOWN
) {
2451 printk(" IRQ(s)\n");
2454 /* FIXME: update_link_quality_led was a stub - let's comment it and avoid
2455 * compiler warnings */
2457 static void update_link_quality_led(acx_device_t * adev)
2462 acx_signal_determine_quality(adev->wstats.qual.level,
2463 adev->wstats.qual.noise);
2464 if (qual > adev->brange_max_quality)
2465 qual = adev->brange_max_quality;
2467 if (time_after(jiffies, adev->brange_time_last_state_change +
2469 HZ / 2 * (unsigned long)qual /
2470 adev->brange_max_quality))) {
2471 acxpci_l_power_led(adev, (adev->brange_last_state == 0));
2472 adev->brange_last_state ^= 1; // toggle
2473 adev->brange_time_last_state_change = jiffies;
2478 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* a la orinoco.c */
2480 /* Interrupt handler bottom-half */
2481 void acx_interrupt_tasklet(struct work_struct
*work
)
2484 #ifdef CONFIG_ACX_MAC80211_DEBUG
2485 u32 _handled
= 0x00000000;
2486 # define acxirq_handled(irq) do { _handled |= (irq); } while (0)
2488 # define acxirq_handled(irq) do { /* nothing */ } while (0)
2489 #endif /* CONFIG_ACX_MAC80211_DEBUG */
2490 acx_device_t
*adev
= container_of(work
,struct acx_device
, after_interrupt_task
);
2491 // unsigned int irqcount = MAX_IRQLOOPS_PER_JIFFY;
2494 #define IRQ_ITERATE 0
2496 unsigned int irqcount
= MAX_IRQLOOPS_PER_JIFFY
;
2502 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2506 irqtype
= adev
->irq_reason
;
2507 adev
->irq_reason
= 0;
2510 if (jiffies
!= adev
->irq_last_jiffies
) {
2511 adev
->irq_loops_this_jiffy
= 0;
2512 adev
->irq_last_jiffies
= jiffies
;
2515 /* safety condition; we'll normally abort loop below
2516 * in case no IRQ type occurred */
2517 while (likely(--irqcount
)) {
2519 /* ACK all IRQs ASAP */
2521 /* Handle most important IRQ types first */
2522 if (irqtype
& HOST_INT_RX_COMPLETE
) {
2523 acx_log(LOG_DEBUG
, L_IRQ
, "got Rx_Complete IRQ\n");
2524 acxpci_l_process_rxdesc(adev
);
2526 if (irqtype
& HOST_INT_TX_COMPLETE
) {
2527 acx_log(LOG_DEBUG
, L_IRQ
, "got Tx_Complete IRQ\n");
2528 /* don't clean up on each Tx complete, wait a bit
2529 * unless we're going towards full, in which case
2530 * we do it immediately, too (otherwise we might lockup
2531 * with a full Tx buffer if we go into
2532 * acxpci_l_clean_txdesc() at a time when we won't wakeup
2533 * the net queue in there for some reason...) */
2534 // if (adev->tx_free <= TX_START_CLEAN) {
2535 acxpci_l_clean_txdesc(adev
);
2539 /* Less frequent ones */
2541 | HOST_INT_CMD_COMPLETE
2542 | HOST_INT_INFO
| HOST_INT_SCAN_COMPLETE
)) {
2543 if (irqtype
& HOST_INT_INFO
) {
2544 handle_info_irq(adev
);
2546 if (irqtype
& HOST_INT_SCAN_COMPLETE
) {
2547 acx_log(LOG_DEBUG
, L_IRQ
,
2548 "got Scan_Complete IRQ\n");
2549 /* need to do that in process context */
2550 /* remember that fw is not scanning anymore */
2551 SET_BIT(adev
->irq_status
,
2552 HOST_INT_SCAN_COMPLETE
);
2556 /* These we just log, but either they happen rarely
2557 * or we keep them masked out */
2558 if (irqtype
& (0 | HOST_INT_RX_DATA
2559 /* | HOST_INT_TX_COMPLETE */
2561 /* | HOST_INT_RX_COMPLETE */
2565 | HOST_INT_KEY_NOT_FOUND
2566 | HOST_INT_IV_ICV_FAILURE
2567 /* | HOST_INT_CMD_COMPLETE */
2568 /* | HOST_INT_INFO */
2570 | HOST_INT_PROCESS_ERROR
2571 /* | HOST_INT_SCAN_COMPLETE */
2572 | HOST_INT_FCS_THRESHOLD
2573 | HOST_INT_UNKNOWN
)) {
2574 log_unusual_irq(irqtype
);
2577 unmasked
= read_reg16(adev
, IO_ACX_IRQ_STATUS_CLEAR
);
2578 irqtype
= unmasked
& ~adev
->irq_mask
;
2579 /* Bail out if no new IRQ bits or if all are masked out */
2584 (++adev
->irq_loops_this_jiffy
> MAX_IRQLOOPS_PER_JIFFY
)) {
2585 acx_log(LOG_WARNING
, L_ANY
,
2586 "too many interrupts per jiffy!\n");
2587 /* Looks like card floods us with IRQs! Try to stop that */
2588 write_reg16(adev
, IO_ACX_IRQ_MASK
, 0xffff);
2589 /* This will short-circuit all future attempts to handle IRQ.
2590 * We cant do much more... */
2596 /* Routine to perform blink with range
2597 * FIXME: update_link_quality_led is a stub - add proper code and enable this again:
2598 if (unlikely(adev->led_power == 2))
2599 update_link_quality_led(adev);
2602 /* write_flush(adev); - not needed, last op was read anyway */
2603 acx_sem_unlock(adev
);
2606 if (adev
->after_interrupt_jobs
)
2607 acx_e_after_interrupt_task(&adev
->after_interrupt_task
);
2615 static irqreturn_t
acxpci_i_interrupt(int irq
, void *dev_id
)
2617 acx_device_t
*adev
= dev_id
;
2618 unsigned long flags
;
2619 register u16 irqtype
;
2627 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2630 acx_lock(adev
, flags
);
2632 unmasked
= read_reg16(adev
, IO_ACX_IRQ_STATUS_CLEAR
);
2633 if (unlikely(0xffff == unmasked
)) {
2634 /* 0xffff value hints at missing hardware,
2635 * so don't do anything.
2636 * Not very clean, but other drivers do the same... */
2637 acx_log(LOG_WARNING
, L_IRQ
,
2638 "IRQ type:FFFF - device removed? IRQ_NONE\n");
2642 /* We will check only "interesting" IRQ types */
2643 irqtype
= unmasked
& ~adev
->irq_mask
;
2645 /* We are on a shared IRQ line and it wasn't our IRQ */
2646 acx_log(LOG_DEBUG
, L_IRQ
,
2647 "IRQ type:%04X, mask:%04X - all are masked, IRQ_NONE\n",
2648 unmasked
, adev
->irq_mask
);
2652 /* Go ahead and ACK our interrupt */
2653 write_reg16(adev
, IO_ACX_IRQ_ACK
, 0xffff);
2654 if (irqtype
& HOST_INT_CMD_COMPLETE
) {
2655 acx_log(LOG_DEBUG
, L_IRQ
, "got Command_Complete IRQ\n");
2656 /* save the state for the running issue_cmd() */
2657 SET_BIT(adev
->irq_status
, HOST_INT_CMD_COMPLETE
);
2660 /* Only accept IRQs, if we are initialized properly.
2661 * This avoids an RX race while initializing.
2662 * We should probably not enable IRQs before we are initialized
2663 * completely, but some careful work is needed to fix this. I think it
2664 * is best to stay with this cheap workaround for now... .
2666 if (likely(adev
->initialized
)) {
2667 /* disable all IRQs. They are enabled again in the bottom half. */
2668 /* save the reason code and call our bottom half. */
2669 adev
->irq_reason
= irqtype
;
2671 if ((irqtype
& HOST_INT_RX_COMPLETE
) || (irqtype
& HOST_INT_TX_COMPLETE
))
2672 acx_schedule_task(adev
, 0);
2675 acx_unlock(adev
, flags
);
2679 acx_unlock(adev
, flags
);
2686 /***********************************************************************
2687 ** acxpci_l_power_led
2689 void acxpci_l_power_led(acx_device_t
* adev
, int enable
)
2691 u16 gpio_pled
= IS_ACX111(adev
) ? 0x0040 : 0x0800;
2693 /* A hack. Not moving message rate limiting to adev->xxx
2694 * (it's only a debug message after all) */
2695 static int rate_limit
= 0;
2697 if (rate_limit
++ < 3)
2698 acx_log(LOG_INFO
, L_IOCTL
,
2699 "Please report in case toggling the power LED "
2700 "doesn't work for your card!\n");
2702 write_reg16(adev
, IO_ACX_GPIO_OUT
,
2703 read_reg16(adev
, IO_ACX_GPIO_OUT
) & ~gpio_pled
);
2705 write_reg16(adev
, IO_ACX_GPIO_OUT
,
2706 read_reg16(adev
, IO_ACX_GPIO_OUT
) | gpio_pled
);
2710 /***********************************************************************
2714 /***********************************************************************
2718 acx111pci_ioctl_info(struct net_device
*ndev
,
2719 struct iw_request_info
*info
,
2720 struct iw_param
*vwrq
, char *extra
)
2723 acx_device_t
*adev
= ndev2adev(ndev
);
2726 rxhostdesc_t
*rxhostdesc
;
2727 txhostdesc_t
*txhostdesc
;
2728 struct acx111_ie_memoryconfig memconf
;
2729 struct acx111_ie_queueconfig queueconf
;
2730 unsigned long flags
;
2735 char ratefallback
[0x5];
2737 if (!(acx_debug
& (L_IOCTL
| L_DEBUG
)))
2739 /* using printk() since we checked debug flag already */
2743 if (!IS_ACX111(adev
)) {
2744 printk("acx111-specific function called "
2745 "with non-acx111 chip, aborting\n");
2749 /* get Acx111 Memory Configuration */
2750 memset(&memconf
, 0, sizeof(memconf
));
2751 /* BTW, fails with 12 (Write only) error code.
2752 ** Retained for easy testing of issue_cmd error handling :) */
2753 acx_s_interrogate(adev
, &memconf
, ACX1xx_IE_QUEUE_CONFIG
);
2755 /* get Acx111 Queue Configuration */
2756 memset(&queueconf
, 0, sizeof(queueconf
));
2757 acx_s_interrogate(adev
, &queueconf
, ACX1xx_IE_MEMORY_CONFIG_OPTIONS
);
2759 /* get Acx111 Memory Map */
2760 memset(memmap
, 0, sizeof(memmap
));
2761 acx_s_interrogate(adev
, &memmap
, ACX1xx_IE_MEMORY_MAP
);
2763 /* get Acx111 Rx Config */
2764 memset(rxconfig
, 0, sizeof(rxconfig
));
2765 acx_s_interrogate(adev
, &rxconfig
, ACX1xx_IE_RXCONFIG
);
2767 /* get Acx111 fcs error count */
2768 memset(fcserror
, 0, sizeof(fcserror
));
2769 acx_s_interrogate(adev
, &fcserror
, ACX1xx_IE_FCS_ERROR_COUNT
);
2771 /* get Acx111 rate fallback */
2772 memset(ratefallback
, 0, sizeof(ratefallback
));
2773 acx_s_interrogate(adev
, &ratefallback
, ACX1xx_IE_RATE_FALLBACK
);
2775 /* force occurrence of a beacon interrupt */
2776 /* TODO: comment why is this necessary */
2777 write_reg16(adev
, IO_ACX_HINT_TRIG
, HOST_INT_BEACON
);
2779 /* dump Acx111 Mem Configuration */
2780 printk("dump mem config:\n"
2781 "data read: %d, struct size: %d\n"
2782 "Number of stations: %1X\n"
2783 "Memory block size: %1X\n"
2784 "tx/rx memory block allocation: %1X\n"
2785 "count rx: %X / tx: %X queues\n"
2787 "fragmentation %1X\n"
2788 "Rx Queue 1 Count Descriptors: %X\n"
2789 "Rx Queue 1 Host Memory Start: %X\n"
2790 "Tx Queue 1 Count Descriptors: %X\n"
2791 "Tx Queue 1 Attributes: %X\n",
2792 memconf
.len
, (int)sizeof(memconf
),
2793 memconf
.no_of_stations
,
2794 memconf
.memory_block_size
,
2795 memconf
.tx_rx_memory_block_allocation
,
2796 memconf
.count_rx_queues
, memconf
.count_tx_queues
,
2798 memconf
.fragmentation
,
2799 memconf
.rx_queue1_count_descs
,
2800 acx2cpu(memconf
.rx_queue1_host_rx_start
),
2801 memconf
.tx_queue1_count_descs
, memconf
.tx_queue1_attributes
);
2803 /* dump Acx111 Queue Configuration */
2804 printk("dump queue head:\n"
2805 "data read: %d, struct size: %d\n"
2806 "tx_memory_block_address (from card): %X\n"
2807 "rx_memory_block_address (from card): %X\n"
2808 "rx1_queue address (from card): %X\n"
2809 "tx1_queue address (from card): %X\n"
2810 "tx1_queue attributes (from card): %X\n",
2811 queueconf
.len
, (int)sizeof(queueconf
),
2812 queueconf
.tx_memory_block_address
,
2813 queueconf
.rx_memory_block_address
,
2814 queueconf
.rx1_queue_address
,
2815 queueconf
.tx1_queue_address
, queueconf
.tx1_attributes
);
2817 /* dump Acx111 Mem Map */
2818 printk("dump mem map:\n"
2819 "data read: %d, struct size: %d\n"
2822 "WEP default key start: %X\n"
2823 "WEP default key end: %X\n"
2824 "STA table start: %X\n"
2825 "STA table end: %X\n"
2826 "Packet template start: %X\n"
2827 "Packet template end: %X\n"
2828 "Queue memory start: %X\n"
2829 "Queue memory end: %X\n"
2830 "Packet memory pool start: %X\n"
2831 "Packet memory pool end: %X\n"
2834 *((u16
*) & memmap
[0x02]), (int)sizeof(memmap
),
2835 *((u32
*) & memmap
[0x04]),
2836 *((u32
*) & memmap
[0x08]),
2837 *((u32
*) & memmap
[0x0C]),
2838 *((u32
*) & memmap
[0x10]),
2839 *((u32
*) & memmap
[0x14]),
2840 *((u32
*) & memmap
[0x18]),
2841 *((u32
*) & memmap
[0x1C]),
2842 *((u32
*) & memmap
[0x20]),
2843 *((u32
*) & memmap
[0x24]),
2844 *((u32
*) & memmap
[0x28]),
2845 *((u32
*) & memmap
[0x2C]),
2846 *((u32
*) & memmap
[0x30]), adev
->iobase
, adev
->iobase2
);
2848 /* dump Acx111 Rx Config */
2849 printk("dump rx config:\n"
2850 "data read: %d, struct size: %d\n"
2852 "rx filter config: %X\n",
2853 *((u16
*) & rxconfig
[0x02]), (int)sizeof(rxconfig
),
2854 *((u16
*) & rxconfig
[0x04]), *((u16
*) & rxconfig
[0x06]));
2856 /* dump Acx111 fcs error */
2857 printk("dump fcserror:\n"
2858 "data read: %d, struct size: %d\n"
2860 *((u16
*) & fcserror
[0x02]), (int)sizeof(fcserror
),
2861 *((u32
*) & fcserror
[0x04]));
2863 /* dump Acx111 rate fallback */
2864 printk("dump rate fallback:\n"
2865 "data read: %d, struct size: %d\n"
2866 "ratefallback: %X\n",
2867 *((u16
*) & ratefallback
[0x02]), (int)sizeof(ratefallback
),
2868 *((u8
*) & ratefallback
[0x04]));
2870 /* protect against IRQ */
2871 acx_lock(adev
, flags
);
2873 /* dump acx111 internal rx descriptor ring buffer */
2874 rxdesc
= adev
->rxdesc_start
;
2876 /* loop over complete receive pool */
2878 for (i
= 0; i
< RX_CNT
; i
++) {
2879 printk("\ndump internal rxdesc %d:\n"
2882 "acx mem pointer (dynamic) 0x%X\n"
2883 "CTL (dynamic) 0x%X\n"
2884 "Rate (dynamic) 0x%X\n"
2885 "RxStatus (dynamic) 0x%X\n"
2886 "Mod/Pre (dynamic) 0x%X\n",
2889 acx2cpu(rxdesc
->pNextDesc
),
2890 acx2cpu(rxdesc
->ACXMemPtr
),
2892 rxdesc
->rate
, rxdesc
->error
, rxdesc
->SNR
);
2896 /* dump host rx descriptor ring buffer */
2898 rxhostdesc
= adev
->rxhostdesc_start
;
2900 /* loop over complete receive pool */
2902 for (i
= 0; i
< RX_CNT
; i
++) {
2903 printk("\ndump host rxdesc %d:\n"
2905 "buffer mem pos 0x%X\n"
2906 "buffer mem offset 0x%X\n"
2913 acx2cpu(rxhostdesc
->data_phy
),
2914 rxhostdesc
->data_offset
,
2915 le16_to_cpu(rxhostdesc
->Ctl_16
),
2916 le16_to_cpu(rxhostdesc
->length
),
2917 acx2cpu(rxhostdesc
->desc_phy_next
),
2918 rxhostdesc
->Status
);
2922 /* dump acx111 internal tx descriptor ring buffer */
2923 txdesc
= adev
->txdesc_start
;
2925 /* loop over complete transmit pool */
2927 for (i
= 0; i
< TX_CNT
; i
++) {
2928 printk("\ndump internal txdesc %d:\n"
2932 "acx mem pointer (dynamic) 0x%X\n"
2933 "host mem pointer (dynamic) 0x%X\n"
2934 "length (dynamic) 0x%X\n"
2935 "CTL (dynamic) 0x%X\n"
2936 "CTL2 (dynamic) 0x%X\n"
2937 "Status (dynamic) 0x%X\n"
2938 "Rate (dynamic) 0x%X\n",
2940 (int)sizeof(struct txdesc
),
2942 acx2cpu(txdesc
->pNextDesc
),
2943 acx2cpu(txdesc
->AcxMemPtr
),
2944 acx2cpu(txdesc
->HostMemPtr
),
2945 le16_to_cpu(txdesc
->total_length
),
2947 txdesc
->Ctl2_8
, txdesc
->error
,
2949 txdesc
= advance_txdesc(adev
, txdesc
, 1);
2952 /* dump host tx descriptor ring buffer */
2954 txhostdesc
= adev
->txhostdesc_start
;
2956 /* loop over complete host send pool */
2958 for (i
= 0; i
< TX_CNT
* 2; i
++) {
2959 printk("\ndump host txdesc %d:\n"
2961 "buffer mem pos 0x%X\n"
2962 "buffer mem offset 0x%X\n"
2969 acx2cpu(txhostdesc
->data_phy
),
2970 txhostdesc
->data_offset
,
2971 le16_to_cpu(txhostdesc
->Ctl_16
),
2972 le16_to_cpu(txhostdesc
->length
),
2973 acx2cpu(txhostdesc
->desc_phy_next
),
2974 le32_to_cpu(txhostdesc
->Status
));
2978 /* write_reg16(adev, 0xb4, 0x4); */
2980 acx_unlock(adev
, flags
);
2983 acx_sem_unlock(adev
);
2984 #endif /* ACX_DEBUG */
2989 /***********************************************************************
2992 acx100pci_ioctl_set_phy_amp_bias(struct net_device
*ndev
,
2993 struct iw_request_info
*info
,
2994 struct iw_param
*vwrq
, char *extra
)
2996 acx_device_t
*adev
= ndev2adev(ndev
);
2997 unsigned long flags
;
3000 if (!IS_ACX100(adev
)) {
3002 * Removing this check *might* damage
3003 * hardware, since we're tweaking GPIOs here after all!!!
3004 * You've been warned...
3006 acx_log(LOG_INFO
, L_ANY
,
3007 "sorry, setting bias level for non-acx100 "
3008 "is not supported yet\n");
3013 acx_log(LOG_INFO
, L_ANY
,
3014 "invalid bias parameter, range is 0-7\n");
3020 /* Need to lock accesses to [IO_ACX_GPIO_OUT]:
3021 * IRQ handler uses it to update LED */
3022 acx_lock(adev
, flags
);
3023 gpio_old
= read_reg16(adev
, IO_ACX_GPIO_OUT
);
3024 write_reg16(adev
, IO_ACX_GPIO_OUT
,
3025 (gpio_old
& 0xf8ff) | ((u16
) * extra
<< 8));
3026 acx_unlock(adev
, flags
);
3028 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "gpio_old: 0x%04X\n", gpio_old
);
3029 acx_log(LOG_INFO
, L_ANY
,
3030 "%s: PHY power amplifier bias: old:%d, new:%d\n",
3031 ndev
->name
, (gpio_old
& 0x0700) >> 8, (unsigned char)*extra
);
3033 acx_sem_unlock(adev
);
3039 /***************************************************************
3040 ** acxpci_l_alloc_tx
3041 ** Actually returns a txdesc_t* ptr
3043 ** FIXME: in case of fragments, should allocate multiple descrs
3044 ** after figuring out how many we need and whether we still have
3045 ** sufficiently many.
3047 tx_t
*acxpci_l_alloc_tx(acx_device_t
* adev
)
3049 struct txdesc
*txdesc
;
3055 if (unlikely(!adev
->tx_free
)) {
3056 acx_log(LOG_WARNING
, L_ANY
, "BUG: no free txdesc left\n");
3061 head
= adev
->tx_head
;
3062 txdesc
= get_txdesc(adev
, head
);
3063 ctl8
= txdesc
->Ctl_8
;
3065 /* 2005-10-11: there were several bug reports on this happening
3066 ** but now cause seems to be understood & fixed */
3067 if (unlikely(DESC_CTL_HOSTOWN
!= (ctl8
& DESC_CTL_ACXDONE_HOSTOWN
))) {
3068 /* whoops, descr at current index is not free, so probably
3069 * ring buffer already full */
3070 acx_log(LOG_WARNING
, L_ANY
, "BUG: tx_head:%d Ctl8:0x%02X - "
3071 "failed to find free txdesc\n", head
, ctl8
);
3076 /* Needed in case txdesc won't be eventually submitted for tx */
3077 txdesc
->Ctl_8
= DESC_CTL_ACXDONE_HOSTOWN
;
3080 acx_log(LOG_DEBUG
, L_BUFT
, "tx: got desc %u, %u remain\n",
3081 head
, adev
->tx_free
);
3082 /* Keep a few free descs between head and tail of tx ring.
3083 ** It is not absolutely needed, just feels safer */
3084 if (adev
->tx_free
< TX_STOP_QUEUE
) {
3085 acx_log(LOG_DEBUG
, L_BUF
, "stop queue (%u tx desc left)\n",
3087 acx_stop_queue(adev
->ieee
, NULL
);
3090 /* returning current descriptor, so advance to next free one */
3091 adev
->tx_head
= (head
+ 1) % TX_CNT
;
3095 return (tx_t
*) txdesc
;
3099 /***********************************************************************
3101 void *acxpci_l_get_txbuf(acx_device_t
* adev
, tx_t
* tx_opaque
)
3103 return get_txhostdesc(adev
, (txdesc_t
*) tx_opaque
)->data
;
3107 /***********************************************************************
3110 ** Can be called from IRQ (rx -> (AP bridging or mgmt response) -> tx).
3111 ** Can be called from acx_i_start_xmit (data frames from net core).
3113 ** FIXME: in case of fragments, should loop over the number of
3114 ** pre-allocated tx descrs, properly setting up transfer data and
3115 ** CTL_xxx flags according to fragment number.
3118 acxpci_l_tx_data(acx_device_t
* adev
, tx_t
* tx_opaque
, int len
,
3119 struct ieee80211_tx_control
*ieeectl
,struct sk_buff
* skb
)
3121 txdesc_t
*txdesc
= (txdesc_t
*) tx_opaque
;
3122 struct ieee80211_hdr
*wireless_header
;
3123 txhostdesc_t
*hostdesc1
, *hostdesc2
;
3130 /* fw doesn't tx such packets anyhow */
3131 /* if (unlikely(len < WLAN_HDR_A3_LEN))
3134 hostdesc1
= get_txhostdesc(adev
, txdesc
);
3135 wireless_header
= (struct ieee80211_hdr
*)hostdesc1
->data
;
3136 /* modify flag status in separate variable to be able to write it back
3137 * in one big swoop later (also in order to have less device memory
3139 Ctl_8
= txdesc
->Ctl_8
;
3140 Ctl2_8
= 0; /* really need to init it to 0, not txdesc->Ctl2_8, it seems */
3142 hostdesc2
= hostdesc1
+ 1;
3144 /* DON'T simply set Ctl field to 0 here globally,
3145 * it needs to maintain a consistent flag status (those are state flags!!),
3146 * otherwise it may lead to severe disruption. Only set or reset particular
3147 * flags at the exact moment this is needed... */
3149 /* let chip do RTS/CTS handshaking before sending
3150 * in case packet size exceeds threshold */
3151 if (ieeectl
->flags
& IEEE80211_TXCTL_USE_RTS_CTS
)
3152 SET_BIT(Ctl2_8
, DESC_CTL2_RTS
);
3154 CLEAR_BIT(Ctl2_8
, DESC_CTL2_RTS
);
3156 rate_cur
= ieeectl
->tx_rate
;
3157 if (unlikely(!rate_cur
)) {
3158 acx_log(LOG_WARNING
, L_ANY
, "driver bug! bad ratemask\n");
3162 /* used in tx cleanup routine for auto rate and accounting: */
3163 /* put_txcr(adev, txdesc, clt, rate_cur); deprecated by mac80211 */
3165 txdesc
->total_length
= cpu_to_le16(len
);
3166 wlhdr_len
= ieee80211_get_hdrlen(le16_to_cpu(wireless_header
->frame_control
));
3167 hostdesc2
->length
= cpu_to_le16(len
- wlhdr_len
);
3169 if (!ieeectl->do_not_encrypt && ieeectl->key_idx>= 0)
3171 u16 key_idx = (u16)(ieeectl->key_idx);
3172 struct acx_key* key = &(adev->key[key_idx]);
3176 memcpy(ieeehdr->wep_iv, ((u8*)wireless_header) + wlhdr_len, 4);
3180 if (IS_ACX111(adev
)) {
3181 /* note that if !txdesc->do_auto, txrate->cur
3182 ** has only one nonzero bit */
3183 txdesc
->u
.r2
.rate111
= cpu_to_le16(rate_cur
3184 /* WARNING: I was never able to make it work with prism54 AP.
3185 ** It was falling down to 1Mbit where shortpre is not applicable,
3186 ** and not working at all at "5,11 basic rates only" setting.
3187 ** I even didn't see tx packets in radio packet capture.
3188 ** Disabled for now --vda */
3189 /*| ((clt->shortpre && clt->cur!=RATE111_1) ? RATE111_SHORTPRE : 0) */
3191 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3192 /* should add this to rate111 above as necessary */
3193 |(clt
->pbcc511
? RATE111_PBCC511
: 0)
3195 hostdesc1
->length
= cpu_to_le16(len
);
3196 } else { /* ACX100 */
3197 u8 rate_100
= ieeectl
->tx_rate
;
3198 txdesc
->u
.r1
.rate
= rate_100
;
3199 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3201 if (n
== RATE100_5
|| n
== RATE100_11
)
3202 n
|= RATE100_PBCC511
;
3205 if (clt
->shortpre
&& (clt
->cur
!= RATE111_1
))
3206 SET_BIT(Ctl_8
, DESC_CTL_SHORT_PREAMBLE
); /* set Short Preamble */
3208 /* set autodma and reclaim and 1st mpdu */
3210 DESC_CTL_AUTODMA
| DESC_CTL_RECLAIM
|
3211 DESC_CTL_FIRSTFRAG
);
3212 #if ACX_FRAGMENTATION
3213 /* SET_BIT(Ctl2_8, DESC_CTL2_MORE_FRAG); cannot set it unconditionally, needs to be set for all non-last fragments */
3215 hostdesc1
->length
= cpu_to_le16(wlhdr_len
);
3217 /* don't need to clean ack/rts statistics here, already
3218 * done on descr cleanup */
3220 /* clears HOSTOWN and ACXDONE bits, thus telling that the descriptors
3221 * are now owned by the acx100; do this as LAST operation */
3222 CLEAR_BIT(Ctl_8
, DESC_CTL_ACXDONE_HOSTOWN
);
3223 /* flush writes before we release hostdesc to the adapter here */
3225 CLEAR_BIT(hostdesc1
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
3226 CLEAR_BIT(hostdesc2
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
3228 /* write back modified flags */
3229 CLEAR_BIT(Ctl2_8
, DESC_CTL2_WEP
);
3230 txdesc
->Ctl2_8
= Ctl2_8
;
3231 txdesc
->Ctl_8
= Ctl_8
;
3232 /* unused: txdesc->tx_time = cpu_to_le32(jiffies); */
3234 /* flush writes before we tell the adapter that it's its turn now */
3235 write_reg16(adev
, IO_ACX_INT_TRIG
, INT_TRIG_TXPRC
);
3237 /* log the packet content AFTER sending it,
3238 * in order to not delay sending any further than absolutely needed
3239 * Do separate logs for acx100/111 to have human-readable rates */
3240 memcpy(&(hostdesc1
->txstatus
.control
),ieeectl
,sizeof(struct ieee80211_tx_control
));
3241 hostdesc1
->skb
= skb
;
3247 /***********************************************************************
3248 ** acxpci_l_clean_txdesc
3250 ** This function resets the txdescs' status when the ACX100
3251 ** signals the TX done IRQ (txdescs have been processed), starting with
3252 ** the pool index of the descriptor which we would use next,
3253 ** in order to make sure that we can be as fast as possible
3254 ** in filling new txdescs.
3255 ** Everytime we get called we know where the next packet to be cleaned is.
3259 static inline void log_txbuffer(const acx_device_t
* adev
)
3263 static void log_txbuffer(acx_device_t
* adev
)
3268 /* no FN_ENTER here, we don't want that */
3269 /* no locks here, since it's entirely non-critical code */
3270 txdesc
= adev
->txdesc_start
;
3271 if (unlikely(!txdesc
))
3273 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "tx: desc->Ctl8's:");
3274 for (i
= 0; i
< TX_CNT
; i
++) {
3275 printk(" %02X", txdesc
->Ctl_8
);
3276 txdesc
= advance_txdesc(adev
, txdesc
, 1);
3283 static void handle_tx_error(acx_device_t
* adev
, u8 error
, unsigned int finger
,
3284 struct ieee80211_tx_status
*status
)
3286 const char *err
= "unknown error";
3288 /* hmm, should we handle this as a mask
3289 * of *several* bits?
3290 * For now I think only caring about
3291 * individual bits is ok... */
3294 err
= "no Tx due to error in other fragment";
3295 /* adev->wstats.discard.fragment++; */
3299 adev
->stats
.tx_aborted_errors
++;
3302 err
= "Tx desc wrong parameters";
3303 /* adev->wstats.discard.misc++; */
3306 err
= "WEP key not found";
3307 /* adev->wstats.discard.misc++; */
3310 err
= "MSDU lifetime timeout? - try changing "
3311 "'iwconfig retry lifetime XXX'";
3312 /* adev->wstats.discard.misc++; */
3315 err
= "excessive Tx retries due to either distance "
3316 "too high or unable to Tx or Tx frame error - "
3317 "try changing 'iwconfig txpower XXX' or "
3318 "'sens'itivity or 'retry'";
3319 /* adev->wstats.discard.retries++; */
3320 /* Tx error 0x20 also seems to occur on
3321 * overheating, so I'm not sure whether we
3322 * actually want to do aggressive radio recalibration,
3323 * since people maybe won't notice then that their hardware
3324 * is slowly getting cooked...
3325 * Or is it still a safe long distance from utter
3326 * radio non-functionality despite many radio recalibs
3327 * to final destructive overheating of the hardware?
3328 * In this case we really should do recalib here...
3329 * I guess the only way to find out is to do a
3330 * potentially fatal self-experiment :-\
3331 * Or maybe only recalib in case we're using Tx
3332 * rate auto (on errors switching to lower speed
3333 * --> less heat?) or 802.11 power save mode?
3335 * ok, just do it. */
3336 if (++adev
->retry_errors_msg_ratelimit
% 4 == 0) {
3337 if (adev
->retry_errors_msg_ratelimit
<= 20) {
3338 acx_log(LOG_WARNING
, L_ANY
,
3339 "%s: several excessive Tx "
3340 "retry errors occurred, attempting "
3341 "to recalibrate radio\n",
3342 wiphy_name(adev
->ieee
->wiphy
));
3343 acx_log(LOG_WARNING
, L_ANY
,
3344 "Radio drift might be caused by "
3345 "increasing card temperature, please "
3346 "check the card before it's too late!\n");
3347 if (adev
->retry_errors_msg_ratelimit
== 20)
3348 acx_log(LOG_WARNING
, L_ANY
,
3349 "disabling above message\n");
3352 acx_schedule_task(adev
,
3353 ACX_AFTER_IRQ_CMD_RADIO_RECALIB
);
3355 status
->excessive_retries
++;
3358 err
= "Tx buffer overflow";
3359 adev
->stats
.tx_fifo_errors
++;
3362 /* possibly ACPI C-state powersaving related!!!
3363 * (DMA timeout due to excessively high wakeup
3364 * latency after C-state activation!?)
3365 * Disable C-State powersaving and try again,
3366 * then PLEASE REPORT, I'm VERY interested in
3367 * whether my theory is correct that this is
3368 * actually the problem here.
3369 * In that case, use new Linux idle wakeup latency
3370 * requirements kernel API to prevent this issue. */
3372 /* adev->wstats.discard.misc++; */
3375 adev
->stats
.tx_errors
++;
3376 if (adev
->stats
.tx_errors
<= 20)
3377 acx_log(LOG_WARNING
, L_ANY
,
3378 "%s: tx error 0x%02X, buf %02u! (%s)\n",
3379 wiphy_name(adev
->ieee
->wiphy
), error
, finger
, err
);
3381 acx_log(LOG_WARNING
, L_ANY
,
3382 "%s: tx error 0x%02X, buf %02u!\n",
3383 wiphy_name(adev
->ieee
->wiphy
), error
, finger
);
3387 unsigned int acxpci_l_clean_txdesc(acx_device_t
* adev
)
3390 txhostdesc_t
*hostdesc
;
3394 u8 error
, ack_failures
, rts_failures
, rts_ok
, r100
;
3398 if (unlikely(acx_debug
& L_REALLYVERBOSE
))
3401 acx_log(LOG_DEBUG
, L_BUFT
, "tx: cleaning up bufs from %u\n",
3404 /* We know first descr which is not free yet. We advance it as far
3405 ** as we see correct bits set in following descs (if next desc
3406 ** is NOT free, we shouldn't advance at all). We know that in
3407 ** front of tx_tail may be "holes" with isolated free descs.
3408 ** We will catch up when all intermediate descs will be freed also */
3410 finger
= adev
->tx_tail
;
3412 while (likely(finger
!= adev
->tx_head
)) {
3413 txdesc
= get_txdesc(adev
, finger
);
3415 /* If we allocated txdesc on tx path but then decided
3416 ** to NOT use it, then it will be left as a free "bubble"
3417 ** in the "allocated for tx" part of the ring.
3418 ** We may meet it on the next ring pass here. */
3420 /* stop if not marked as "tx finished" and "host owned" */
3421 if ((txdesc
->Ctl_8
& DESC_CTL_ACXDONE_HOSTOWN
)
3422 != DESC_CTL_ACXDONE_HOSTOWN
) {
3423 if (unlikely(!num_cleaned
)) { /* maybe remove completely */
3424 acx_log(LOG_DEBUG
, L_BUFT
,
3425 "clean_txdesc: tail isn't free. "
3426 "tail:%d head:%d\n",
3427 adev
->tx_tail
, adev
->tx_head
);
3432 /* remember desc values... */
3433 error
= txdesc
->error
;
3434 ack_failures
= txdesc
->ack_failures
;
3435 rts_failures
= txdesc
->rts_failures
;
3436 rts_ok
= txdesc
->rts_ok
;
3437 r100
= txdesc
->u
.r1
.rate
;
3438 r111
= le16_to_cpu(txdesc
->u
.r2
.rate111
);
3440 /* need to check for certain error conditions before we
3441 * clean the descriptor: we still need valid descr data here */
3442 hostdesc
= get_txhostdesc(adev
, txdesc
);
3444 hostdesc
->txstatus
.flags
|= IEEE80211_TX_STATUS_ACK
;
3445 if (unlikely(0x30 & error
)) {
3446 /* only send IWEVTXDROP in case of retry or lifetime exceeded;
3447 * all other errors mean we screwed up locally */
3448 /* union iwreq_data wrqu;
3449 struct ieee80211_hdr_3addr *hdr;
3450 hdr = (struct ieee80211_hdr_3addr *) hostdesc->data;
3451 MAC_COPY(wrqu.addr.sa_data, hdr->addr1);
3453 hostdesc
->txstatus
.flags
&= ~IEEE80211_TX_STATUS_ACK
;
3456 /* ...and free the desc */
3458 txdesc
->ack_failures
= 0;
3459 txdesc
->rts_failures
= 0;
3461 /* signal host owning it LAST, since ACX already knows that this
3462 ** descriptor is finished since it set Ctl_8 accordingly. */
3463 txdesc
->Ctl_8
= DESC_CTL_HOSTOWN
;
3468 if ((adev
->tx_free
>= TX_START_QUEUE
)
3469 /* && (adev->status == ACX_STATUS_4_ASSOCIATED) */
3470 /*&& (acx_queue_stopped(adev->ieee))*/
3472 acx_log(LOG_DEBUG
, L_BUF
,
3473 "tx: wake queue (avail. Tx desc %u)\n",
3475 acx_wake_queue(adev
->ieee
, NULL
);
3478 /* do error checking, rate handling and logging
3479 * AFTER having done the work, it's faster */
3481 /* Rate handling is done in mac80211 */
3482 /* if (adev->rate_auto) {
3483 struct client *clt = get_txc(adev, txdesc);
3485 u16 cur = get_txr(adev, txdesc);
3486 if (clt->rate_cur == cur) {
3487 acx_l_handle_txrate_auto(adev, clt, cur,*/ /* intended rate */
3488 /*r100, r111,*/ /* actually used rate */
3489 /*(error & 0x30),*/ /* was there an error? */
3498 if (unlikely(error
))
3499 handle_tx_error(adev
, error
, finger
, &hostdesc
->txstatus
);
3501 if (IS_ACX111(adev
))
3502 acx_log(LOG_DEBUG
, L_BUFT
, "tx: cleaned %u: !ACK=%u "
3503 "!RTS=%u RTS=%u r111=%04X tx_free=%u\n",
3504 finger
, ack_failures
,
3505 rts_failures
, rts_ok
, r111
, adev
->tx_free
);
3507 acx_log(LOG_DEBUG
, L_BUFT
, "tx: cleaned %u: !ACK=%u "
3508 "!RTS=%u RTS=%u rate=%u\n",
3509 finger
, ack_failures
,
3510 rts_failures
, rts_ok
, r100
);
3512 /* And finally report upstream */
3515 hostdesc
->txstatus
.excessive_retries
= rts_failures
;
3516 hostdesc
->txstatus
.retry_count
= ack_failures
;
3517 ieee80211_tx_status(adev
->ieee
,hostdesc
->skb
,&hostdesc
->txstatus
);
3518 memset(&hostdesc
->txstatus
, 0, sizeof(struct ieee80211_tx_status
));
3520 /* update pointer for descr to be cleaned next */
3521 finger
= (finger
+ 1) % TX_CNT
;
3523 /* remember last position */
3524 adev
->tx_tail
= finger
;
3526 FN_EXIT1(num_cleaned
);
3530 /* clean *all* Tx descriptors, and regardless of their previous state.
3531 * Used for brute-force reset handling. */
3532 void acxpci_l_clean_txdesc_emergency(acx_device_t
* adev
)
3539 for (i
= 0; i
< TX_CNT
; i
++) {
3540 txdesc
= get_txdesc(adev
, i
);
3543 txdesc
->ack_failures
= 0;
3544 txdesc
->rts_failures
= 0;
3547 txdesc
->Ctl_8
= DESC_CTL_HOSTOWN
;
3550 adev
->tx_free
= TX_CNT
;
3556 /***********************************************************************
3557 ** acxpci_s_create_tx_host_desc_queue
3560 static void *allocate(acx_device_t
* adev
, size_t size
, dma_addr_t
* phy
,
3565 ptr
= dma_alloc_coherent(adev
->bus_dev
, size
, phy
, GFP_KERNEL
);
3568 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
3569 "%s sz=%d adr=0x%p phy=0x%08llx\n",
3570 msg
, (int)size
, ptr
, (unsigned long long)*phy
);
3571 memset(ptr
, 0, size
);
3574 acx_log(LOG_WARNING
, L_ANY
, "%s allocation FAILED (%d bytes)\n",
3580 static int acxpci_s_create_tx_host_desc_queue(acx_device_t
* adev
)
3582 txhostdesc_t
*hostdesc
;
3584 dma_addr_t hostdesc_phy
;
3585 dma_addr_t txbuf_phy
;
3590 /* allocate TX buffer */
3591 adev
->txbuf_area_size
= TX_CNT
* /*WLAN_A4FR_MAXLEN_WEP_FCS*/ (30 + 2312 + 4);
3592 adev
->txbuf_start
= allocate(adev
, adev
->txbuf_area_size
,
3593 &adev
->txbuf_startphy
, "txbuf_start");
3594 if (!adev
->txbuf_start
)
3597 /* allocate the TX host descriptor queue pool */
3598 adev
->txhostdesc_area_size
= TX_CNT
* 2 * sizeof(*hostdesc
);
3599 adev
->txhostdesc_start
= allocate(adev
, adev
->txhostdesc_area_size
,
3600 &adev
->txhostdesc_startphy
,
3601 "txhostdesc_start");
3602 if (!adev
->txhostdesc_start
)
3604 /* check for proper alignment of TX host descriptor pool */
3605 if ((long)adev
->txhostdesc_start
& 3) {
3606 acx_log(LOG_WARNING
, L_ANY
,
3607 "driver bug: dma alloc returns unaligned address\n");
3611 hostdesc
= adev
->txhostdesc_start
;
3612 hostdesc_phy
= adev
->txhostdesc_startphy
;
3613 txbuf
= adev
->txbuf_start
;
3614 txbuf_phy
= adev
->txbuf_startphy
;
3617 /* Each tx buffer is accessed by hardware via
3618 ** txdesc -> txhostdesc(s) -> txbuffer(s).
3619 ** We use only one txhostdesc per txdesc, but it looks like
3620 ** acx111 is buggy: it accesses second txhostdesc
3621 ** (via hostdesc.desc_phy_next field) even if
3622 ** txdesc->length == hostdesc->length and thus
3623 ** entire packet was placed into first txhostdesc.
3624 ** Due to this bug acx111 hangs unless second txhostdesc
3625 ** has le16_to_cpu(hostdesc.length) = 3 (or larger)
3626 ** Storing NULL into hostdesc.desc_phy_next
3627 ** doesn't seem to help.
3629 ** Update: although it worked on Xterasys XN-2522g
3630 ** with len=3 trick, WG311v2 is even more bogus, doesn't work.
3631 ** Keeping this code (#ifdef'ed out) for documentational purposes.
3633 for (i
= 0; i
< TX_CNT
* 2; i
++) {
3634 hostdesc_phy
+= sizeof(*hostdesc
);
3636 hostdesc
->data_phy
= cpu2acx(txbuf_phy
);
3637 /* hostdesc->data_offset = ... */
3638 /* hostdesc->reserved = ... */
3639 hostdesc
->Ctl_16
= cpu_to_le16(DESC_CTL_HOSTOWN
);
3640 /* hostdesc->length = ... */
3641 hostdesc
->desc_phy_next
= cpu2acx(hostdesc_phy
);
3642 hostdesc
->pNext
= ptr2acx(NULL
);
3643 /* hostdesc->Status = ... */
3644 /* below: non-hardware fields */
3645 hostdesc
->data
= txbuf
;
3647 txbuf
+= WLAN_A4FR_MAXLEN_WEP_FCS
;
3648 txbuf_phy
+= WLAN_A4FR_MAXLEN_WEP_FCS
;
3650 /* hostdesc->data_phy = ... */
3651 /* hostdesc->data_offset = ... */
3652 /* hostdesc->reserved = ... */
3653 /* hostdesc->Ctl_16 = ... */
3654 hostdesc
->length
= cpu_to_le16(3); /* bug workaround */
3655 /* hostdesc->desc_phy_next = ... */
3656 /* hostdesc->pNext = ... */
3657 /* hostdesc->Status = ... */
3658 /* below: non-hardware fields */
3659 /* hostdesc->data = ... */
3664 /* We initialize two hostdescs so that they point to adjacent
3665 ** memory areas. Thus txbuf is really just a contiguous memory area */
3666 for (i
= 0; i
< TX_CNT
* 2; i
++) {
3667 hostdesc_phy
+= sizeof(*hostdesc
);
3669 hostdesc
->data_phy
= cpu2acx(txbuf_phy
);
3670 /* done by memset(0): hostdesc->data_offset = 0; */
3671 /* hostdesc->reserved = ... */
3672 hostdesc
->Ctl_16
= cpu_to_le16(DESC_CTL_HOSTOWN
);
3673 /* hostdesc->length = ... */
3674 hostdesc
->desc_phy_next
= cpu2acx(hostdesc_phy
);
3675 /* done by memset(0): hostdesc->pNext = ptr2acx(NULL); */
3676 /* hostdesc->Status = ... */
3677 /* ->data is a non-hardware field: */
3678 hostdesc
->data
= txbuf
;
3681 txbuf
+= 24 /*WLAN_HDR_A3_LEN*/;
3682 txbuf_phy
+= 24 /*WLAN_HDR_A3_LEN*/;
3684 txbuf
+= 30 + 2132 + 4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3685 txbuf_phy
+= 30 + 2132 +4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3690 hostdesc
->desc_phy_next
= cpu2acx(adev
->txhostdesc_startphy
);
3695 acx_log(LOG_WARNING
, L_ANY
, "create_tx_host_desc_queue FAILED\n");
3696 /* dealloc will be done by free function on error case */
3702 /***************************************************************
3703 ** acxpci_s_create_rx_host_desc_queue
3705 /* the whole size of a data buffer (header plus data body)
3706 * plus 32 bytes safety offset at the end */
3707 #define RX_BUFFER_SIZE (sizeof(rxbuffer_t) + 32)
3709 static int acxpci_s_create_rx_host_desc_queue(acx_device_t
* adev
)
3711 rxhostdesc_t
*hostdesc
;
3713 dma_addr_t hostdesc_phy
;
3714 dma_addr_t rxbuf_phy
;
3719 /* allocate the RX host descriptor queue pool */
3720 adev
->rxhostdesc_area_size
= RX_CNT
* sizeof(*hostdesc
);
3721 adev
->rxhostdesc_start
= allocate(adev
, adev
->rxhostdesc_area_size
,
3722 &adev
->rxhostdesc_startphy
,
3723 "rxhostdesc_start");
3724 if (!adev
->rxhostdesc_start
)
3726 /* check for proper alignment of RX host descriptor pool */
3727 if ((long)adev
->rxhostdesc_start
& 3) {
3728 acx_log(LOG_WARNING
, L_ANY
,
3729 "driver bug: dma alloc returns unaligned address\n");
3733 /* allocate Rx buffer pool which will be used by the acx
3734 * to store the whole content of the received frames in it */
3735 adev
->rxbuf_area_size
= RX_CNT
* RX_BUFFER_SIZE
;
3736 adev
->rxbuf_start
= allocate(adev
, adev
->rxbuf_area_size
,
3737 &adev
->rxbuf_startphy
, "rxbuf_start");
3738 if (!adev
->rxbuf_start
)
3741 rxbuf
= adev
->rxbuf_start
;
3742 rxbuf_phy
= adev
->rxbuf_startphy
;
3743 hostdesc
= adev
->rxhostdesc_start
;
3744 hostdesc_phy
= adev
->rxhostdesc_startphy
;
3746 /* don't make any popular C programming pointer arithmetic mistakes
3747 * here, otherwise I'll kill you...
3748 * (and don't dare asking me why I'm warning you about that...) */
3749 for (i
= 0; i
< RX_CNT
; i
++) {
3750 hostdesc
->data
= rxbuf
;
3751 hostdesc
->data_phy
= cpu2acx(rxbuf_phy
);
3752 hostdesc
->length
= cpu_to_le16(RX_BUFFER_SIZE
);
3753 CLEAR_BIT(hostdesc
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
3755 rxbuf_phy
+= sizeof(*rxbuf
);
3756 hostdesc_phy
+= sizeof(*hostdesc
);
3757 hostdesc
->desc_phy_next
= cpu2acx(hostdesc_phy
);
3761 hostdesc
->desc_phy_next
= cpu2acx(adev
->rxhostdesc_startphy
);
3765 acx_log(LOG_WARNING
, L_ANY
, "create_rx_host_desc_queue FAILED\n");
3766 /* dealloc will be done by free function on error case */
3772 /***************************************************************
3773 ** acxpci_s_create_hostdesc_queues
3775 int acxpci_s_create_hostdesc_queues(acx_device_t
* adev
)
3778 result
= acxpci_s_create_tx_host_desc_queue(adev
);
3781 result
= acxpci_s_create_rx_host_desc_queue(adev
);
3786 /***************************************************************
3787 ** acxpci_create_tx_desc_queue
3789 static void acxpci_create_tx_desc_queue(acx_device_t
* adev
, u32 tx_queue_start
)
3792 txhostdesc_t
*hostdesc
;
3793 dma_addr_t hostmemptr
;
3799 if (IS_ACX100(adev
))
3800 adev
->txdesc_size
= sizeof(*txdesc
);
3802 /* the acx111 txdesc is 4 bytes larger */
3803 adev
->txdesc_size
= sizeof(*txdesc
) + 4;
3805 adev
->txdesc_start
= (txdesc_t
*) (adev
->iobase2
+ tx_queue_start
);
3807 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
, "adev->iobase2=%p\n"
3808 "tx_queue_start=%08X\n adev->txdesc_start=%p\n",
3809 adev
->iobase2
, tx_queue_start
, adev
->txdesc_start
);
3811 adev
->tx_free
= TX_CNT
;
3812 /* done by memset: adev->tx_head = 0; */
3813 /* done by memset: adev->tx_tail = 0; */
3814 txdesc
= adev
->txdesc_start
;
3815 mem_offs
= tx_queue_start
;
3816 hostmemptr
= adev
->txhostdesc_startphy
;
3817 hostdesc
= adev
->txhostdesc_start
;
3819 if (IS_ACX111(adev
)) {
3820 /* ACX111 has a preinitialized Tx buffer! */
3821 /* loop over whole send pool */
3822 /* FIXME: do we have to do the hostmemptr stuff here?? */
3823 for (i
= 0; i
< TX_CNT
; i
++) {
3824 txdesc
->HostMemPtr
= ptr2acx(hostmemptr
);
3825 txdesc
->Ctl_8
= DESC_CTL_HOSTOWN
;
3826 /* reserve two (hdr desc and payload desc) */
3828 hostmemptr
+= 2 * sizeof(*hostdesc
);
3829 txdesc
= advance_txdesc(adev
, txdesc
, 1);
3832 /* ACX100 Tx buffer needs to be initialized by us */
3833 /* clear whole send pool. sizeof is safe here (we are acx100) */
3834 memset(adev
->txdesc_start
, 0, TX_CNT
* sizeof(*txdesc
));
3836 /* loop over whole send pool */
3837 for (i
= 0; i
< TX_CNT
; i
++) {
3838 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
3839 "configure card tx descriptor: 0x%p, "
3840 "size: 0x%X\n", txdesc
, adev
->txdesc_size
);
3842 /* pointer to hostdesc memory */
3843 txdesc
->HostMemPtr
= ptr2acx(hostmemptr
);
3844 /* initialise ctl */
3845 txdesc
->Ctl_8
= (DESC_CTL_HOSTOWN
| DESC_CTL_RECLAIM
3846 | DESC_CTL_AUTODMA
|
3847 DESC_CTL_FIRSTFRAG
);
3848 /* done by memset(0): txdesc->Ctl2_8 = 0; */
3849 /* point to next txdesc */
3851 cpu2acx(mem_offs
+ adev
->txdesc_size
);
3852 /* reserve two (hdr desc and payload desc) */
3854 hostmemptr
+= 2 * sizeof(*hostdesc
);
3855 /* go to the next one */
3856 mem_offs
+= adev
->txdesc_size
;
3857 /* ++ is safe here (we are acx100) */
3860 /* go back to the last one */
3862 /* and point to the first making it a ring buffer */
3863 txdesc
->pNextDesc
= cpu2acx(tx_queue_start
);
3869 /***************************************************************
3870 ** acxpci_create_rx_desc_queue
3872 static void acxpci_create_rx_desc_queue(acx_device_t
* adev
, u32 rx_queue_start
)
3880 /* done by memset: adev->rx_tail = 0; */
3882 /* ACX111 doesn't need any further config: preconfigures itself.
3883 * Simply print ring buffer for debugging */
3884 if (IS_ACX111(adev
)) {
3885 /* rxdesc_start already set here */
3887 adev
->rxdesc_start
=
3888 (rxdesc_t
*) ((u8
*) adev
->iobase2
+ rx_queue_start
);
3890 rxdesc
= adev
->rxdesc_start
;
3891 for (i
= 0; i
< RX_CNT
; i
++) {
3892 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
3893 "rx descriptor %d @ 0x%p\n", i
, rxdesc
);
3894 rxdesc
= adev
->rxdesc_start
= (rxdesc_t
*)
3895 (adev
->iobase2
+ acx2cpu(rxdesc
->pNextDesc
));
3898 /* we didn't pre-calculate rxdesc_start in case of ACX100 */
3899 /* rxdesc_start should be right AFTER Tx pool */
3900 adev
->rxdesc_start
= (rxdesc_t
*)
3901 ((u8
*) adev
->txdesc_start
+ (TX_CNT
* sizeof(txdesc_t
)));
3902 /* NB: sizeof(txdesc_t) above is valid because we know
3903 ** we are in if (acx100) block. Beware of cut-n-pasting elsewhere!
3904 ** acx111's txdesc is larger! */
3906 memset(adev
->rxdesc_start
, 0, RX_CNT
* sizeof(*rxdesc
));
3908 /* loop over whole receive pool */
3909 rxdesc
= adev
->rxdesc_start
;
3910 mem_offs
= rx_queue_start
;
3911 for (i
= 0; i
< RX_CNT
; i
++) {
3912 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
3913 "rx descriptor @ 0x%p\n", rxdesc
);
3914 rxdesc
->Ctl_8
= DESC_CTL_RECLAIM
| DESC_CTL_AUTODMA
;
3915 /* point to next rxdesc */
3916 rxdesc
->pNextDesc
= cpu2acx(mem_offs
+ sizeof(*rxdesc
));
3917 /* go to the next one */
3918 mem_offs
+= sizeof(*rxdesc
);
3921 /* go to the last one */
3924 /* and point to the first making it a ring buffer */
3925 rxdesc
->pNextDesc
= cpu2acx(rx_queue_start
);
3931 /***************************************************************
3932 ** acxpci_create_desc_queues
3935 acxpci_create_desc_queues(acx_device_t
* adev
, u32 tx_queue_start
,
3938 acxpci_create_tx_desc_queue(adev
, tx_queue_start
);
3939 acxpci_create_rx_desc_queue(adev
, rx_queue_start
);
3943 /***************************************************************
3944 ** acxpci_s_proc_diag_output
3946 char *acxpci_s_proc_diag_output(char *p
, acx_device_t
* adev
)
3948 const char *rtl
, *thd
, *ttl
;
3949 rxhostdesc_t
*rxhostdesc
;
3955 p
+= sprintf(p
, "** Rx buf **\n");
3956 rxhostdesc
= adev
->rxhostdesc_start
;
3958 for (i
= 0; i
< RX_CNT
; i
++) {
3959 rtl
= (i
== adev
->rx_tail
) ? " [tail]" : "";
3960 if ((rxhostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
3962 Status
& cpu_to_le32(DESC_STATUS_FULL
)))
3963 p
+= sprintf(p
, "%02u FULL%s\n", i
, rtl
);
3965 p
+= sprintf(p
, "%02u empty%s\n", i
, rtl
);
3968 /* p += sprintf(p, "** Tx buf (free %d, Linux netqueue %s) **\n",
3970 acx_queue_stopped(adev->ieee) ? "STOPPED" : "running");*/
3971 txdesc
= adev
->txdesc_start
;
3973 for (i
= 0; i
< TX_CNT
; i
++) {
3974 thd
= (i
== adev
->tx_head
) ? " [head]" : "";
3975 ttl
= (i
== adev
->tx_tail
) ? " [tail]" : "";
3976 if (txdesc
->Ctl_8
& DESC_CTL_ACXDONE
)
3977 p
+= sprintf(p
, "%02u free (%02X)%s%s\n", i
,
3978 txdesc
->Ctl_8
, thd
, ttl
);
3980 p
+= sprintf(p
, "%02u tx (%02X)%s%s\n", i
,
3981 txdesc
->Ctl_8
, thd
, ttl
);
3982 txdesc
= advance_txdesc(adev
, txdesc
, 1);
3987 "txbuf_start %p, txbuf_area_size %u, txbuf_startphy %08llx\n"
3988 "txdesc_size %u, txdesc_start %p\n"
3989 "txhostdesc_start %p, txhostdesc_area_size %u, txhostdesc_startphy %08llx\n"
3991 "rxhostdesc_start %p, rxhostdesc_area_size %u, rxhostdesc_startphy %08llx\n"
3992 "rxbuf_start %p, rxbuf_area_size %u, rxbuf_startphy %08llx\n",
3993 adev
->txbuf_start
, adev
->txbuf_area_size
,
3994 (unsigned long long)adev
->txbuf_startphy
,
3995 adev
->txdesc_size
, adev
->txdesc_start
,
3996 adev
->txhostdesc_start
, adev
->txhostdesc_area_size
,
3997 (unsigned long long)adev
->txhostdesc_startphy
,
3999 adev
->rxhostdesc_start
, adev
->rxhostdesc_area_size
,
4000 (unsigned long long)adev
->rxhostdesc_startphy
,
4001 adev
->rxbuf_start
, adev
->rxbuf_area_size
,
4002 (unsigned long long)adev
->rxbuf_startphy
);
4009 /***********************************************************************
4011 int acxpci_proc_eeprom_output(char *buf
, acx_device_t
* adev
)
4018 for (i
= 0; i
< 0x400; i
++) {
4019 acxpci_read_eeprom_byte(adev
, i
, p
++);
4027 /***********************************************************************
4030 void acxpci_set_interrupt_mask(acx_device_t
* adev
)
4032 if (IS_ACX111(adev
)) {
4033 adev
->irq_mask
= (u16
) ~ (0
4034 /* | HOST_INT_RX_DATA */
4035 | HOST_INT_TX_COMPLETE
4036 /* | HOST_INT_TX_XFER */
4037 | HOST_INT_RX_COMPLETE
4038 /* | HOST_INT_DTIM */
4039 /* | HOST_INT_BEACON */
4040 /* | HOST_INT_TIMER */
4041 /* | HOST_INT_KEY_NOT_FOUND */
4042 | HOST_INT_IV_ICV_FAILURE
4043 | HOST_INT_CMD_COMPLETE
4045 /* | HOST_INT_OVERFLOW */
4046 /* | HOST_INT_PROCESS_ERROR */
4047 | HOST_INT_SCAN_COMPLETE
4048 | HOST_INT_FCS_THRESHOLD
4049 /* | HOST_INT_UNKNOWN */
4051 /* Or else acx100 won't signal cmd completion, right? */
4052 adev
->irq_mask_off
= (u16
) ~ (HOST_INT_CMD_COMPLETE
); /* 0xfdff */
4054 adev
->irq_mask
= (u16
) ~ (0
4055 /* | HOST_INT_RX_DATA */
4056 | HOST_INT_TX_COMPLETE
4057 /* | HOST_INT_TX_XFER */
4058 | HOST_INT_RX_COMPLETE
4059 /* | HOST_INT_DTIM */
4060 /* | HOST_INT_BEACON */
4061 /* | HOST_INT_TIMER */
4062 /* | HOST_INT_KEY_NOT_FOUND */
4063 /* | HOST_INT_IV_ICV_FAILURE */
4064 | HOST_INT_CMD_COMPLETE
4066 /* | HOST_INT_OVERFLOW */
4067 /* | HOST_INT_PROCESS_ERROR */
4068 | HOST_INT_SCAN_COMPLETE
4069 /* | HOST_INT_FCS_THRESHOLD */
4070 /* | HOST_INT_UNKNOWN */
4072 adev
->irq_mask_off
= (u16
) ~ (HOST_INT_UNKNOWN
); /* 0x7fff */
4077 /***********************************************************************
4079 int acx100pci_s_set_tx_level(acx_device_t
* adev
, u8 level_dbm
)
4081 /* since it can be assumed that at least the Maxim radio has a
4082 * maximum power output of 20dBm and since it also can be
4083 * assumed that these values drive the DAC responsible for
4084 * setting the linear Tx level, I'd guess that these values
4085 * should be the corresponding linear values for a dBm value,
4086 * in other words: calculate the values from that formula:
4087 * Y [dBm] = 10 * log (X [mW])
4088 * then scale the 0..63 value range onto the 1..100mW range (0..20 dBm)
4089 * and you're done...
4090 * Hopefully that's ok, but you never know if we're actually
4091 * right... (especially since Windows XP doesn't seem to show
4092 * actual Tx dBm values :-P) */
4094 /* NOTE: on Maxim, value 30 IS 30mW, and value 10 IS 10mW - so the
4095 * values are EXACTLY mW!!! Not sure about RFMD and others,
4097 static const u8 dbm2val_maxim
[21] = {
4105 static const u8 dbm2val_rfmd
[21] = {
4115 switch (adev
->radio_type
) {
4116 case RADIO_MAXIM_0D
:
4117 table
= &dbm2val_maxim
[0];
4120 case RADIO_RALINK_15
:
4121 table
= &dbm2val_rfmd
[0];
4124 acx_log(LOG_WARNING
, L_ANY
, "%s: unknown/unsupported radio type, "
4125 "cannot modify tx power level yet!\n",
4126 wiphy_name(adev
->ieee
->wiphy
));
4129 acx_log(LOG_INFO
, L_ANY
,
4130 "%s: changing radio power level to %u dBm (%u)\n",
4131 wiphy_name(adev
->ieee
->wiphy
), level_dbm
, table
[level_dbm
]);
4132 acxpci_s_write_phy_reg(adev
, 0x11, table
[level_dbm
]);
4137 struct vlynq_reg_config
{
4142 struct vlynq_known
{
4145 struct vlynq_mapping rx_mapping
[4];
4149 struct vlynq_reg_config regs
[10];
4152 #define CHIP_TNETW1130 0x00000009
4153 #define CHIP_TNETW1350 0x00000029
4155 static struct vlynq_known known_devices
[] = {
4157 .chip_id
= CHIP_TNETW1130
, .name
= "TI TNETW1130",
4159 { .size
= 0x22000, .offset
= 0xf0000000 },
4160 { .size
= 0x40000, .offset
= 0xc0000000 },
4161 { .size
= 0x0, .offset
= 0x0 },
4162 { .size
= 0x0, .offset
= 0x0 },
4165 .irq_type
= IRQ_TYPE_EDGE_RISING
,
4170 .value
= (0xd0000000 - PHYS_OFFSET
)
4174 .value
= (0xd0000000 - PHYS_OFFSET
)
4176 { .offset
= 0x740, .value
= 0 },
4177 { .offset
= 0x744, .value
= 0x00010000 },
4178 { .offset
= 0x764, .value
= 0x00010000 },
4182 .chip_id
= CHIP_TNETW1350
, .name
= "TI TNETW1350",
4184 { .size
= 0x100000, .offset
= 0x00300000 },
4185 { .size
= 0x80000, .offset
= 0x00000000 },
4186 { .size
= 0x0, .offset
= 0x0 },
4187 { .size
= 0x0, .offset
= 0x0 },
4190 .irq_type
= IRQ_TYPE_EDGE_RISING
,
4195 .value
= (0x60000000 - PHYS_OFFSET
)
4199 .value
= (0x60000000 - PHYS_OFFSET
)
4201 { .offset
= 0x740, .value
= 0 },
4202 { .offset
= 0x744, .value
= 0x00010000 },
4203 { .offset
= 0x764, .value
= 0x00010000 },
4208 static struct vlynq_device_id acx_vlynq_id
[] = {
4209 { CHIP_TNETW1130
, vlynq_div_auto
, 0 },
4210 { CHIP_TNETW1350
, vlynq_div_auto
, 1 },
4214 static __devinit
int vlynq_probe(struct vlynq_device
*vdev
,
4215 struct vlynq_device_id
*id
)
4217 int result
= -EIO
, i
;
4219 struct ieee80211_hw
*ieee
;
4220 acx_device_t
*adev
= NULL
;
4221 acx111_ie_configoption_t co
;
4222 struct vlynq_mapping mapping
[4] = { { 0, }, };
4223 struct vlynq_known
*match
= NULL
;
4226 result
= vlynq_enable_device(vdev
);
4230 match
= &known_devices
[id
->driver_data
];
4237 mapping
[0].offset
= ARCH_PFN_OFFSET
<< PAGE_SHIFT
;
4238 mapping
[0].size
= 0x02000000;
4239 vlynq_set_local_mapping(vdev
, vdev
->mem_start
, mapping
);
4240 vlynq_set_remote_mapping(vdev
, 0, match
->rx_mapping
);
4242 set_irq_type(vlynq_virq_to_irq(vdev
, match
->irq
), match
->irq_type
);
4244 addr
= (u32
)ioremap(vdev
->mem_start
, 0x1000);
4246 acx_log(LOG_WARNING
, L_ANY
, "%s: failed to remap io memory\n",
4252 for (i
= 0; i
< match
->num_regs
; i
++)
4253 iowrite32(match
->regs
[i
].value
,
4254 (u32
*)(addr
+ match
->regs
[i
].offset
));
4256 iounmap((void *)addr
);
4258 ieee
= ieee80211_alloc_hw(sizeof(struct acx_device
), &acxpci_hw_ops
);
4260 acx_log(LOG_WARNING
, L_ANY
,
4261 "could not allocate ieee80211 structure %s\n",
4263 goto fail_alloc_netdev
;
4265 ieee
->flags
&= ~IEEE80211_HW_RX_INCLUDES_FCS
;
4268 adev
= ieee2adev(ieee
);
4270 memset(adev
, 0, sizeof(*adev
));
4271 /** Set up our private interface **/
4272 spin_lock_init(&adev
->spinlock
); /* initial state: unlocked */
4273 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
4274 mutex_init(&adev
->mutex
);
4275 /* since nobody can see new netdev yet, we can as well
4276 ** just _presume_ that we're under sem (instead of actually taking it): */
4277 /* acx_sem_lock(adev); */
4280 adev
->bus_dev
= &vdev
->dev
;
4281 adev
->dev_type
= DEVTYPE_PCI
;
4283 /** Finished with private interface **/
4285 vlynq_set_drvdata(vdev
, ieee
);
4286 if (!request_mem_region(vdev
->mem_start
, vdev
->mem_end
- vdev
->mem_start
, "acx")) {
4287 acx_log(LOG_WARNING
, L_ANY
, "cannot reserve VLYNQ memory region\n");
4288 goto fail_request_mem_region
;
4291 adev
->iobase
= ioremap(vdev
->mem_start
, vdev
->mem_end
- vdev
->mem_start
);
4292 if (!adev
->iobase
) {
4293 acx_log(LOG_WARNING
, L_ANY
, "ioremap() FAILED\n");
4296 adev
->iobase2
= adev
->iobase
+ match
->rx_mapping
[0].size
;
4297 adev
->chip_type
= CHIPTYPE_ACX111
;
4298 adev
->chip_name
= match
->name
;
4299 adev
->io
= IO_ACX111
;
4300 adev
->irq
= vlynq_virq_to_irq(vdev
, match
->irq
);
4302 acx_log(LOG_INFO
, L_ANY
, "found %s-based wireless network card at %s, "
4303 "irq:%d, phymem:0x%x, mem:0x%p\n",
4304 match
->name
, vdev
->dev
.bus_id
, adev
->irq
,
4305 vdev
->mem_start
, adev
->iobase
);
4306 // acx_log(LOG_INFO, L_ANY,
4307 // "initial debug setting is 0x%04X\n", acx_debug);
4309 if (0 == adev
->irq
) {
4310 acx_log(LOG_WARNING
, L_ANY
, "can't use IRQ 0\n");
4313 SET_IEEE80211_DEV(ieee
, &vdev
->dev
);
4315 /* request shared IRQ handler */
4317 (adev
->irq
, acxpci_i_interrupt
, IRQF_SHARED
, KBUILD_MODNAME
, adev
)) {
4318 acx_log(LOG_WARNING
, L_ANY
, "%s: request_irq FAILED\n",
4319 wiphy_name(adev
->ieee
->wiphy
));
4323 acx_log(LOG_DEBUG
, L_IRQ
| L_REALLYVERBOSE
,
4324 "request_irq %d successful\n", adev
->irq
);
4326 /* to find crashes due to weird driver access
4327 * to unconfigured interface (ifup) */
4328 adev
->mgmt_timer
.function
= (void (*)(unsigned long))0x0000dead;
4331 /* ok, pci setup is finished, now start initializing the card */
4333 /* NB: read_reg() reads may return bogus data before reset_dev(),
4334 * since the firmware which directly controls large parts of the I/O
4335 * registers isn't initialized yet.
4336 * acx100 seems to be more affected than acx111 */
4337 if (OK
!= acxpci_s_reset_dev(adev
))
4340 if (OK
!= acx_s_init_mac(adev
))
4343 acx_s_interrogate(adev
, &co
, ACX111_IE_CONFIG_OPTIONS
);
4344 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
4345 if (OK
!= acxpci_read_eeprom_byte(adev
, 0x05, &adev
->eeprom_version
))
4346 goto fail_read_eeprom_version
;
4348 acx_s_parse_configoption(adev
, &co
);
4349 acx_s_set_defaults(adev
);
4350 acx_s_get_firmware_version(adev
); /* needs to be after acx_s_init_mac() */
4351 acx_display_hardware_details(adev
);
4353 /* Register the card, AFTER everything else has been set up,
4354 * since otherwise an ioctl could step on our feet due to
4355 * firmware operations happening in parallel or uninitialized data */
4358 acx_proc_register_entries(ieee
);
4360 /* Now we have our device, so make sure the kernel doesn't try
4361 * to send packets even though we're not associated to a network yet */
4363 /* after register_netdev() userspace may start working with dev
4364 * (in particular, on other CPUs), we only need to up the sem */
4365 /* acx_sem_unlock(adev); */
4367 acx_log(LOG_INFO
, L_ANY
, "driver " ACX_RELEASE
", net device %s, "
4368 "driver compiled against wireless extensions %d and Linux %s\n",
4369 wiphy_name(adev
->ieee
->wiphy
), WIRELESS_EXT
, UTS_RELEASE
);
4371 MAC_COPY(adev
->ieee
->wiphy
->perm_addr
, adev
->dev_addr
);
4373 acx_log(LOG_DEBUG
, L_IRQ
| L_INIT
, "using IRQ %d\n", adev
->irq
);
4375 /** done with board specific setup **/
4377 result
= acx_setup_modes(adev
);
4379 acx_log(LOG_WARNING
, L_ANY
, "can't register hwmode\n");
4380 goto fail_register_netdev
;
4383 acx_init_task_scheduler(adev
);
4384 result
= ieee80211_register_hw(adev
->ieee
);
4386 acx_log(LOG_WARNING
, L_ANY
,
4387 "acx: ieee80211_register_hw() FAILED: %d\n", result
);
4388 goto fail_register_netdev
;
4391 great_inquisitor(adev
);
4397 /* error paths: undo everything in reverse order... */
4400 acxpci_s_delete_dma_regions(adev
);
4403 fail_read_eeprom_version
:
4409 iounmap(adev
->iobase
);
4412 release_mem_region(vdev
->mem_start
, vdev
->mem_end
- vdev
->mem_start
);
4413 fail_request_mem_region
:
4414 fail_register_netdev
:
4415 ieee80211_free_hw(ieee
);
4417 vlynq_disable_device(vdev
);
4423 static void vlynq_remove(struct vlynq_device
*vdev
)
4425 struct ieee80211_hw
*hw
= vlynq_get_drvdata(vdev
);
4426 acx_device_t
*adev
= ieee2adev(hw
);
4427 unsigned long flags
;
4431 acx_log(LOG_DEBUG
, L_REALLYVERBOSE
,
4432 "%s: card is unused. Skipping any release code\n",
4438 acx_lock(adev
, flags
);
4439 acx_unlock(adev
, flags
);
4440 adev
->initialized
= 0;
4442 /* If device wasn't hot unplugged... */
4443 if (adev_present(adev
)) {
4447 /* disable both Tx and Rx to shut radio down properly */
4448 if (adev
->initialized
) {
4449 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_TX
, NULL
, 0);
4450 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_RX
, NULL
, 0);
4452 acx_lock(adev
, flags
);
4453 /* disable power LED to save power :-) */
4454 acx_log(L_INFO
, L_INIT
,
4455 "switching off power LED to save power\n");
4456 acxpci_l_power_led(adev
, 0);
4458 acx_unlock(adev
, flags
);
4460 acx_sem_unlock(adev
);
4463 /* unregister the device to not let the kernel
4464 * (e.g. ioctls) access a half-deconfigured device
4465 * NB: this will cause acxpci_e_close() to be called,
4466 * thus we shouldn't call it under sem!
4467 * Well, netdev did, but ieee80211 stack does not, so we
4468 * have to do so manually...
4471 acx_log(LOG_INFO
, L_INIT
, "removing device %s\n",
4472 wiphy_name(adev
->ieee
->wiphy
));
4473 ieee80211_unregister_hw(adev
->ieee
);
4475 /* unregister_netdev ensures that no references to us left.
4476 * For paranoid reasons we continue to follow the rules */
4479 if (adev
->dev_state_mask
& ACX_STATE_IFACE_UP
) {
4481 CLEAR_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
4484 acx_proc_unregister_entries(adev
->ieee
);
4486 /* finally, clean up PCI bus state */
4487 acxpci_s_delete_dma_regions(adev
);
4489 iounmap(adev
->iobase
);
4491 iounmap(adev
->iobase2
);
4492 release_mem_region(vdev
->mem_start
, vdev
->mem_end
- vdev
->mem_start
);
4494 /* remove dev registration */
4496 acx_sem_unlock(adev
);
4497 vlynq_disable_device(vdev
);
4499 /* Free netdev (quite late,
4500 * since otherwise we might get caught off-guard
4501 * by a netdev timeout handler execution
4502 * expecting to see a working dev...) */
4503 ieee80211_free_hw(adev
->ieee
);
4509 static struct vlynq_driver vlynq_acx
= {
4510 .name
= "acx_vlynq",
4511 .id_table
= acx_vlynq_id
,
4512 .probe
= vlynq_probe
,
4513 .remove
= __devexit_p(vlynq_remove
),
4515 #endif /* CONFIG_VLYNQ */
4518 /***********************************************************************
4519 ** Data for init_module/cleanup_module
4522 static const struct pci_device_id acxpci_id_tbl
[] __devinitdata
= {
4524 .vendor
= PCI_VENDOR_ID_TI
,
4525 .device
= PCI_DEVICE_ID_TI_TNETW1100A
,
4526 .subvendor
= PCI_ANY_ID
,
4527 .subdevice
= PCI_ANY_ID
,
4528 .driver_data
= CHIPTYPE_ACX100
,
4531 .vendor
= PCI_VENDOR_ID_TI
,
4532 .device
= PCI_DEVICE_ID_TI_TNETW1100B
,
4533 .subvendor
= PCI_ANY_ID
,
4534 .subdevice
= PCI_ANY_ID
,
4535 .driver_data
= CHIPTYPE_ACX100
,
4538 .vendor
= PCI_VENDOR_ID_TI
,
4539 .device
= PCI_DEVICE_ID_TI_TNETW1130
,
4540 .subvendor
= PCI_ANY_ID
,
4541 .subdevice
= PCI_ANY_ID
,
4542 .driver_data
= CHIPTYPE_ACX111
,
4553 MODULE_DEVICE_TABLE(pci
, acxpci_id_tbl
);
4555 static struct pci_driver
4558 .id_table
= acxpci_id_tbl
,
4559 .probe
= acxpci_e_probe
,
4560 .remove
= __devexit_p(acxpci_e_remove
),
4562 .suspend
= acxpci_e_suspend
,
4563 .resume
= acxpci_e_resume
4564 #endif /* CONFIG_PM */
4566 #endif /* CONFIG_PCI */
4568 /***********************************************************************
4569 ** acxpci_e_init_module
4571 ** Module initialization routine, called once at module load time
4573 int __init
acxpci_e_init_module(void)
4579 #if (ACX_IO_WIDTH==32)
4580 acx_log(LOG_INFO
, L_ANY
, "compiled to use 32bit I/O access. "
4581 "I/O timing issues might occur, such as "
4582 "non-working firmware upload. Report them\n");
4584 acx_log(LOG_INFO
, L_ANY
, "compiled to use 16bit I/O access only "
4585 "(compatibility mode)\n");
4588 #ifdef __LITTLE_ENDIAN
4589 #define ENDIANNESS_STRING "running on a little-endian CPU\n"
4591 #define ENDIANNESS_STRING "running on a BIG-ENDIAN CPU\n"
4593 acx_log(LOG_INFO
, L_INIT
, ENDIANNESS_STRING
);
4594 acx_log(LOG_INFO
, L_INIT
, "PCI/VLYNQ module " ACX_RELEASE
4595 " initialized, waiting for cards to probe...\n");
4598 res
= pci_register_driver(&acxpci_drv_id
);
4600 res
= vlynq_register_driver(&vlynq_acx
);
4607 /***********************************************************************
4608 ** acxpci_e_cleanup_module
4610 ** Called at module unload time. This is our last chance to
4611 ** clean up after ourselves.
4613 void __exit
acxpci_e_cleanup_module(void)
4618 pci_unregister_driver(&acxpci_drv_id
);
4620 vlynq_unregister_driver(&vlynq_acx
);
4622 acx_log(LOG_INFO
, L_INIT
,
4623 "PCI module " ACX_RELEASE
" unloaded\n");