1 /***********************************************************************
2 ** Copyright (C) 2003 ACX100 Open Source Project
4 ** The contents of this file are subject to the Mozilla Public
5 ** License Version 1.1 (the "License"); you may not use this file
6 ** except in compliance with the License. You may obtain a copy of
7 ** the License at http://www.mozilla.org/MPL/
9 ** Software distributed under the License is distributed on an "AS
10 ** IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11 ** implied. See the License for the specific language governing
12 ** rights and limitations under the License.
14 ** Alternatively, the contents of this file may be used under the
15 ** terms of the GNU Public License version 2 (the "GPL"), in which
16 ** case the provisions of the GPL are applicable instead of the
17 ** above. If you wish to allow the use of your version of this file
18 ** only under the terms of the GPL and not to allow others to use
19 ** your version of this file under the MPL, indicate your decision
20 ** by deleting the provisions above and replace them with the notice
21 ** and other provisions required by the GPL. If you do not delete
22 ** the provisions above, a recipient may use your version of this
23 ** file under either the MPL or the GPL.
24 ** ---------------------------------------------------------------------
25 ** Inquiries regarding the ACX100 Open Source Project can be
28 ** acx100-users@lists.sf.net
29 ** http://acx100.sf.net
30 ** ---------------------------------------------------------------------
34 #include <linux/config.h>
35 #include <linux/version.h>
36 #include <linux/compiler.h> /* required for Lx 2.6.8 ?? */
37 #include <linux/kernel.h>
38 #include <linux/module.h>
39 #include <linux/moduleparam.h>
40 #include <linux/sched.h>
41 #include <linux/types.h>
42 #include <linux/skbuff.h>
43 #include <linux/slab.h>
44 #include <linux/if_arp.h>
45 #include <linux/rtnetlink.h>
46 #include <linux/wireless.h>
47 #include <net/iw_handler.h>
48 #include <linux/netdevice.h>
49 #include <linux/ioport.h>
50 #include <linux/pci.h>
52 #include <linux/vmalloc.h>
57 /***********************************************************************
59 #define PCI_TYPE (PCI_USES_MEM | PCI_ADDR0 | PCI_NO_ACPI_WAKE)
60 #define PCI_ACX100_REGION1 0x01
61 #define PCI_ACX100_REGION1_SIZE 0x1000 /* Memory size - 4K bytes */
62 #define PCI_ACX100_REGION2 0x02
63 #define PCI_ACX100_REGION2_SIZE 0x10000 /* Memory size - 64K bytes */
65 #define PCI_ACX111_REGION1 0x00
66 #define PCI_ACX111_REGION1_SIZE 0x2000 /* Memory size - 8K bytes */
67 #define PCI_ACX111_REGION2 0x01
68 #define PCI_ACX111_REGION2_SIZE 0x20000 /* Memory size - 128K bytes */
70 /* Texas Instruments Vendor ID */
71 #define PCI_VENDOR_ID_TI 0x104c
73 /* ACX100 22Mb/s WLAN controller */
74 #define PCI_DEVICE_ID_TI_TNETW1100A 0x8400
75 #define PCI_DEVICE_ID_TI_TNETW1100B 0x8401
77 /* ACX111 54Mb/s WLAN controller */
78 #define PCI_DEVICE_ID_TI_TNETW1130 0x9066
80 /* PCI Class & Sub-Class code, Network-'Other controller' */
81 #define PCI_CLASS_NETWORK_OTHERS 0x0280
83 #define CARD_EEPROM_ID_SIZE 6
86 /* From include/linux/pci.h */
93 #define PCI_POWER_ERROR -1
97 /***********************************************************************
99 static void acxpci_i_tx_timeout(struct net_device
*ndev
);
100 static irqreturn_t
acxpci_i_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
101 static void acxpci_i_set_multicast_list(struct net_device
*ndev
);
103 static int acxpci_e_open(struct net_device
*ndev
);
104 static int acxpci_e_close(struct net_device
*ndev
);
105 static void acxpci_s_up(struct net_device
*ndev
);
106 static void acxpci_s_down(struct net_device
*ndev
);
109 /***********************************************************************
114 /* #define INLINE_IO static */
115 #define INLINE_IO static inline
118 read_reg32(acx_device_t
*adev
, unsigned int offset
)
120 #if ACX_IO_WIDTH == 32
121 return readl((u8
*)adev
->iobase
+ adev
->io
[offset
]);
123 return readw((u8
*)adev
->iobase
+ adev
->io
[offset
])
124 + (readw((u8
*)adev
->iobase
+ adev
->io
[offset
] + 2) << 16);
129 read_reg16(acx_device_t
*adev
, unsigned int offset
)
131 return readw((u8
*)adev
->iobase
+ adev
->io
[offset
]);
135 read_reg8(acx_device_t
*adev
, unsigned int offset
)
137 return readb((u8
*)adev
->iobase
+ adev
->io
[offset
]);
141 write_reg32(acx_device_t
*adev
, unsigned int offset
, u32 val
)
143 #if ACX_IO_WIDTH == 32
144 writel(val
, (u8
*)adev
->iobase
+ adev
->io
[offset
]);
146 writew(val
& 0xffff, (u8
*)adev
->iobase
+ adev
->io
[offset
]);
147 writew(val
>> 16, (u8
*)adev
->iobase
+ adev
->io
[offset
] + 2);
152 write_reg16(acx_device_t
*adev
, unsigned int offset
, u16 val
)
154 writew(val
, (u8
*)adev
->iobase
+ adev
->io
[offset
]);
158 write_reg8(acx_device_t
*adev
, unsigned int offset
, u8 val
)
160 writeb(val
, (u8
*)adev
->iobase
+ adev
->io
[offset
]);
163 /* Handle PCI posting properly:
164 * Make sure that writes reach the adapter in case they require to be executed
165 * *before* the next write, by reading a random (and safely accessible) register.
166 * This call has to be made if there is no read following (which would flush the data
167 * to the adapter), yet the written data has to reach the adapter immediately. */
169 write_flush(acx_device_t
*adev
)
171 /* readb(adev->iobase + adev->io[IO_ACX_INFO_MAILBOX_OFFS]); */
172 /* faster version (accesses the first register, IO_ACX_SOFT_RESET,
173 * which should also be safe): */
178 /***********************************************************************
180 static struct net_device
*root_adev_newest
= NULL
;
181 DECLARE_MUTEX(root_adev_sem
);
184 /***********************************************************************
186 static inline txdesc_t
*
187 get_txdesc(acx_device_t
*adev
, int index
)
189 return (txdesc_t
*) (((u8
*)adev
->txdesc_start
) + index
* adev
->txdesc_size
);
192 static inline txdesc_t
*
193 advance_txdesc(acx_device_t
*adev
, txdesc_t
* txdesc
, int inc
)
195 return (txdesc_t
*) (((u8
*)txdesc
) + inc
* adev
->txdesc_size
);
199 get_txhostdesc(acx_device_t
*adev
, txdesc_t
* txdesc
)
201 int index
= (u8
*)txdesc
- (u8
*)adev
->txdesc_start
;
202 if (unlikely(ACX_DEBUG
&& (index
% adev
->txdesc_size
))) {
203 printk("bad txdesc ptr %p\n", txdesc
);
206 index
/= adev
->txdesc_size
;
207 if (unlikely(ACX_DEBUG
&& (index
>= TX_CNT
))) {
208 printk("bad txdesc ptr %p\n", txdesc
);
211 return &adev
->txhostdesc_start
[index
*2];
214 static inline client_t
*
215 get_txc(acx_device_t
*adev
, txdesc_t
* txdesc
)
217 int index
= (u8
*)txdesc
- (u8
*)adev
->txdesc_start
;
218 if (unlikely(ACX_DEBUG
&& (index
% adev
->txdesc_size
))) {
219 printk("bad txdesc ptr %p\n", txdesc
);
222 index
/= adev
->txdesc_size
;
223 if (unlikely(ACX_DEBUG
&& (index
>= TX_CNT
))) {
224 printk("bad txdesc ptr %p\n", txdesc
);
227 return adev
->txc
[index
];
231 get_txr(acx_device_t
*adev
, txdesc_t
* txdesc
)
233 int index
= (u8
*)txdesc
- (u8
*)adev
->txdesc_start
;
234 index
/= adev
->txdesc_size
;
235 return adev
->txr
[index
];
239 put_txcr(acx_device_t
*adev
, txdesc_t
* txdesc
, client_t
* c
, u16 r111
)
241 int index
= (u8
*)txdesc
- (u8
*)adev
->txdesc_start
;
242 if (unlikely(ACX_DEBUG
&& (index
% adev
->txdesc_size
))) {
243 printk("bad txdesc ptr %p\n", txdesc
);
246 index
/= adev
->txdesc_size
;
247 if (unlikely(ACX_DEBUG
&& (index
>= TX_CNT
))) {
248 printk("bad txdesc ptr %p\n", txdesc
);
251 adev
->txc
[index
] = c
;
252 adev
->txr
[index
] = r111
;
256 /***********************************************************************
257 ** EEPROM and PHY read/write helpers
259 /***********************************************************************
260 ** acxpci_read_eeprom_byte
262 ** Function called to read an octet in the EEPROM.
264 ** This function is used by acxpci_e_probe to check if the
265 ** connected card is a legal one or not.
268 ** adev ptr to acx_device structure
269 ** addr address to read in the EEPROM
270 ** charbuf ptr to a char. This is where the read octet
274 acxpci_read_eeprom_byte(acx_device_t
*adev
, u32 addr
, u8
*charbuf
)
279 write_reg32(adev
, IO_ACX_EEPROM_CFG
, 0);
280 write_reg32(adev
, IO_ACX_EEPROM_ADDR
, addr
);
282 write_reg32(adev
, IO_ACX_EEPROM_CTL
, 2);
285 while (read_reg16(adev
, IO_ACX_EEPROM_CTL
)) {
286 /* scheduling away instead of CPU burning loop
287 * doesn't seem to work here at all:
288 * awful delay, sometimes also failure.
289 * Doesn't matter anyway (only small delay). */
290 if (unlikely(!--count
)) {
291 printk("%s: timeout waiting for EEPROM read\n",
299 *charbuf
= read_reg8(adev
, IO_ACX_EEPROM_DATA
);
300 log(L_DEBUG
, "EEPROM at 0x%04X = 0x%02X\n", addr
, *charbuf
);
308 /***********************************************************************
309 ** We don't lock hw accesses here since we never r/w eeprom in IRQ
310 ** Note: this function sleeps only because of GFP_KERNEL alloc
314 acxpci_s_write_eeprom(acx_device_t
*adev
, u32 addr
, u32 len
, const u8
*charbuf
)
316 u8
*data_verify
= NULL
;
322 printk("acx: WARNING! I would write to EEPROM now. "
323 "Since I really DON'T want to unless you know "
324 "what you're doing (THIS CODE WILL PROBABLY "
325 "NOT WORK YET!), I will abort that now. And "
326 "definitely make sure to make a "
327 "/proc/driver/acx_wlan0_eeprom backup copy first!!! "
328 "(the EEPROM content includes the PCI config header!! "
329 "If you kill important stuff, then you WILL "
330 "get in trouble and people DID get in trouble already)\n");
335 data_verify
= kmalloc(len
, GFP_KERNEL
);
340 /* first we need to enable the OE (EEPROM Output Enable) GPIO line
341 * to be able to write to the EEPROM.
342 * NOTE: an EEPROM writing success has been reported,
343 * but you probably have to modify GPIO_OUT, too,
344 * and you probably need to activate a different GPIO
346 gpio_orig
= read_reg16(adev
, IO_ACX_GPIO_OE
);
347 write_reg16(adev
, IO_ACX_GPIO_OE
, gpio_orig
& ~1);
350 /* ok, now start writing the data out */
351 for (i
= 0; i
< len
; i
++) {
352 write_reg32(adev
, IO_ACX_EEPROM_CFG
, 0);
353 write_reg32(adev
, IO_ACX_EEPROM_ADDR
, addr
+ i
);
354 write_reg32(adev
, IO_ACX_EEPROM_DATA
, *(charbuf
+ i
));
356 write_reg32(adev
, IO_ACX_EEPROM_CTL
, 1);
359 while (read_reg16(adev
, IO_ACX_EEPROM_CTL
)) {
360 if (unlikely(!--count
)) {
361 printk("WARNING, DANGER!!! "
362 "Timeout waiting for EEPROM write\n");
369 /* disable EEPROM writing */
370 write_reg16(adev
, IO_ACX_GPIO_OE
, gpio_orig
);
373 /* now start a verification run */
374 for (i
= 0; i
< len
; i
++) {
375 write_reg32(adev
, IO_ACX_EEPROM_CFG
, 0);
376 write_reg32(adev
, IO_ACX_EEPROM_ADDR
, addr
+ i
);
378 write_reg32(adev
, IO_ACX_EEPROM_CTL
, 2);
381 while (read_reg16(adev
, IO_ACX_EEPROM_CTL
)) {
382 if (unlikely(!--count
)) {
383 printk("timeout waiting for EEPROM read\n");
389 data_verify
[i
] = read_reg16(adev
, IO_ACX_EEPROM_DATA
);
392 if (0 == memcmp(charbuf
, data_verify
, len
))
393 result
= OK
; /* read data matches, success */
403 /***********************************************************************
404 ** acxpci_s_read_phy_reg
406 ** Messing with rx/tx disabling and enabling here
407 ** (write_reg32(adev, IO_ACX_ENABLE, 0b000000xx)) kills traffic
410 acxpci_s_read_phy_reg(acx_device_t
*adev
, u32 reg
, u8
*charbuf
)
417 write_reg32(adev
, IO_ACX_PHY_ADDR
, reg
);
419 write_reg32(adev
, IO_ACX_PHY_CTL
, 2);
422 while (read_reg32(adev
, IO_ACX_PHY_CTL
)) {
423 /* scheduling away instead of CPU burning loop
424 * doesn't seem to work here at all:
425 * awful delay, sometimes also failure.
426 * Doesn't matter anyway (only small delay). */
427 if (unlikely(!--count
)) {
428 printk("%s: timeout waiting for phy read\n",
436 log(L_DEBUG
, "count was %u\n", count
);
437 *charbuf
= read_reg8(adev
, IO_ACX_PHY_DATA
);
439 log(L_DEBUG
, "radio PHY at 0x%04X = 0x%02X\n", *charbuf
, reg
);
441 goto fail
; /* silence compiler warning */
448 /***********************************************************************
451 acxpci_s_write_phy_reg(acx_device_t
*adev
, u32 reg
, u8 value
)
455 /* mprusko said that 32bit accesses result in distorted sensitivity
456 * on his card. Unconfirmed, looks like it's not true (most likely since we
457 * now properly flush writes). */
458 write_reg32(adev
, IO_ACX_PHY_DATA
, value
);
459 write_reg32(adev
, IO_ACX_PHY_ADDR
, reg
);
461 write_reg32(adev
, IO_ACX_PHY_CTL
, 1);
463 log(L_DEBUG
, "radio PHY write 0x%02X at 0x%04X\n", value
, reg
);
470 #define NO_AUTO_INCREMENT 1
472 /***********************************************************************
475 ** Write the firmware image into the card.
478 ** adev wlan device structure
479 ** apfw_image firmware image.
482 ** 1 firmware image corrupted
486 acxpci_s_write_fw(acx_device_t
*adev
, const firmware_image_t
*apfw_image
, u32 offset
)
490 /* we skip the first four bytes which contain the control sum */
491 const u8
*image
= (u8
*)apfw_image
+ 4;
493 /* start the image checksum by adding the image size value */
494 sum
= image
[0]+image
[1]+image
[2]+image
[3];
497 write_reg32(adev
, IO_ACX_SLV_END_CTL
, 0);
499 #if NO_AUTO_INCREMENT
500 write_reg32(adev
, IO_ACX_SLV_MEM_CTL
, 0); /* use basic mode */
502 write_reg32(adev
, IO_ACX_SLV_MEM_CTL
, 1); /* use autoincrement mode */
503 write_reg32(adev
, IO_ACX_SLV_MEM_ADDR
, offset
); /* configure start address */
508 size
= le32_to_cpu(apfw_image
->size
) & (~3);
510 while (likely(len
< size
)) {
511 v32
= be32_to_cpu(*(u32
*)image
);
512 sum
+= image
[0]+image
[1]+image
[2]+image
[3];
516 #if NO_AUTO_INCREMENT
517 write_reg32(adev
, IO_ACX_SLV_MEM_ADDR
, offset
+ len
- 4);
520 write_reg32(adev
, IO_ACX_SLV_MEM_DATA
, v32
);
523 log(L_DEBUG
, "firmware written, size:%d sum1:%x sum2:%x\n",
524 size
, sum
, le32_to_cpu(apfw_image
->chksum
));
526 /* compare our checksum with the stored image checksum */
527 return (sum
!= le32_to_cpu(apfw_image
->chksum
));
531 /***********************************************************************
532 ** acxpci_s_validate_fw
534 ** Compare the firmware image given with
535 ** the firmware image written into the card.
538 ** adev wlan device structure
539 ** apfw_image firmware image.
542 ** NOT_OK firmware image corrupted or not correctly written
546 acxpci_s_validate_fw(acx_device_t
*adev
, const firmware_image_t
*apfw_image
,
552 /* we skip the first four bytes which contain the control sum */
553 const u8
*image
= (u8
*)apfw_image
+ 4;
555 /* start the image checksum by adding the image size value */
556 sum
= image
[0]+image
[1]+image
[2]+image
[3];
559 write_reg32(adev
, IO_ACX_SLV_END_CTL
, 0);
561 #if NO_AUTO_INCREMENT
562 write_reg32(adev
, IO_ACX_SLV_MEM_CTL
, 0); /* use basic mode */
564 write_reg32(adev
, IO_ACX_SLV_MEM_CTL
, 1); /* use autoincrement mode */
565 write_reg32(adev
, IO_ACX_SLV_MEM_ADDR
, offset
); /* configure start address */
569 size
= le32_to_cpu(apfw_image
->size
) & (~3);
571 while (likely(len
< size
)) {
572 v32
= be32_to_cpu(*(u32
*)image
);
576 #if NO_AUTO_INCREMENT
577 write_reg32(adev
, IO_ACX_SLV_MEM_ADDR
, offset
+ len
- 4);
579 w32
= read_reg32(adev
, IO_ACX_SLV_MEM_DATA
);
581 if (unlikely(w32
!= v32
)) {
582 printk("acx: FATAL: firmware upload: "
583 "data parts at offset %d don't match (0x%08X vs. 0x%08X)! "
584 "I/O timing issues or defective memory, with DWL-xx0+? "
585 "ACX_IO_WIDTH=16 may help. Please report\n",
591 sum
+= (u8
)w32
+ (u8
)(w32
>>8) + (u8
)(w32
>>16) + (u8
)(w32
>>24);
594 /* sum control verification */
595 if (result
!= NOT_OK
) {
596 if (sum
!= le32_to_cpu(apfw_image
->chksum
)) {
597 printk("acx: FATAL: firmware upload: "
598 "checksums don't match!\n");
607 /***********************************************************************
608 ** acxpci_s_upload_fw
610 ** Called from acx_reset_dev
613 acxpci_s_upload_fw(acx_device_t
*adev
)
615 firmware_image_t
*apfw_image
= NULL
;
619 char filename
[sizeof("tiacx1NNcNN")];
623 /* Try combined, then main image */
624 adev
->need_radio_fw
= 0;
625 snprintf(filename
, sizeof(filename
), "tiacx1%02dc%02X",
626 IS_ACX111(adev
)*11, adev
->radio_type
);
628 apfw_image
= acx_s_read_fw(&adev
->pdev
->dev
, filename
, &size
);
630 adev
->need_radio_fw
= 1;
631 filename
[sizeof("tiacx1NN")-1] = '\0';
632 apfw_image
= acx_s_read_fw(&adev
->pdev
->dev
, filename
, &size
);
639 for (try = 1; try <= 5; try++) {
640 res
= acxpci_s_write_fw(adev
, apfw_image
, 0);
641 log(L_DEBUG
|L_INIT
, "acx_write_fw (main/combined):%d\n", res
);
643 res
= acxpci_s_validate_fw(adev
, apfw_image
, 0);
644 log(L_DEBUG
|L_INIT
, "acx_validate_fw "
645 "(main/combined):%d\n", res
);
649 SET_BIT(adev
->dev_state_mask
, ACX_STATE_FW_LOADED
);
652 printk("acx: firmware upload attempt #%d FAILED, "
653 "retrying...\n", try);
654 acx_s_msleep(1000); /* better wait for a while... */
664 /***********************************************************************
665 ** acxpci_s_upload_radio
667 ** Uploads the appropriate radio module firmware into the card.
670 acxpci_s_upload_radio(acx_device_t
*adev
)
673 firmware_image_t
*radio_image
;
674 acx_cmd_radioinit_t radioinit
;
679 char filename
[sizeof("tiacx1NNrNN")];
681 if (!adev
->need_radio_fw
) return OK
;
685 acx_s_interrogate(adev
, &mm
, ACX1xx_IE_MEMORY_MAP
);
686 offset
= le32_to_cpu(mm
.CodeEnd
);
688 snprintf(filename
, sizeof(filename
), "tiacx1%02dr%02X",
691 radio_image
= acx_s_read_fw(&adev
->pdev
->dev
, filename
, &size
);
693 printk("acx: can't load radio module '%s'\n", filename
);
697 acx_s_issue_cmd(adev
, ACX1xx_CMD_SLEEP
, NULL
, 0);
699 for (try = 1; try <= 5; try++) {
700 res
= acxpci_s_write_fw(adev
, radio_image
, offset
);
701 log(L_DEBUG
|L_INIT
, "acx_write_fw (radio): %d\n", res
);
703 res
= acxpci_s_validate_fw(adev
, radio_image
, offset
);
704 log(L_DEBUG
|L_INIT
, "acx_validate_fw (radio): %d\n", res
);
709 printk("acx: radio firmware upload attempt #%d FAILED, "
710 "retrying...\n", try);
711 acx_s_msleep(1000); /* better wait for a while... */
714 acx_s_issue_cmd(adev
, ACX1xx_CMD_WAKE
, NULL
, 0);
715 radioinit
.offset
= cpu_to_le32(offset
);
716 /* no endian conversion needed, remains in card CPU area: */
717 radioinit
.len
= radio_image
->size
;
724 /* will take a moment so let's have a big timeout */
725 acx_s_issue_cmd_timeo(adev
, ACX1xx_CMD_RADIOINIT
,
726 &radioinit
, sizeof(radioinit
), CMD_TIMEOUT_MS(1000));
728 res
= acx_s_interrogate(adev
, &mm
, ACX1xx_IE_MEMORY_MAP
);
735 /***********************************************************************
736 ** acxpci_l_reset_mac
739 ** Call context: reset_dev
742 acxpci_l_reset_mac(acx_device_t
*adev
)
749 temp
= read_reg16(adev
, IO_ACX_ECPU_CTRL
) | 0x1;
750 write_reg16(adev
, IO_ACX_ECPU_CTRL
, temp
);
752 /* now do soft reset of eCPU, set bit */
753 temp
= read_reg16(adev
, IO_ACX_SOFT_RESET
) | 0x1;
754 log(L_DEBUG
, "%s: enable soft reset...\n", __func__
);
755 write_reg16(adev
, IO_ACX_SOFT_RESET
, temp
);
758 /* now clear bit again: deassert eCPU reset */
759 log(L_DEBUG
, "%s: disable soft reset and go to init mode...\n", __func__
);
760 write_reg16(adev
, IO_ACX_SOFT_RESET
, temp
& ~0x1);
762 /* now start a burst read from initial EEPROM */
763 temp
= read_reg16(adev
, IO_ACX_EE_START
) | 0x1;
764 write_reg16(adev
, IO_ACX_EE_START
, temp
);
771 /***********************************************************************
772 ** acxpci_s_verify_init
775 acxpci_s_verify_init(acx_device_t
*adev
)
778 unsigned long timeout
;
782 timeout
= jiffies
+ 2*HZ
;
784 u16 irqstat
= read_reg16(adev
, IO_ACX_IRQ_STATUS_NON_DES
);
785 if (irqstat
& HOST_INT_FCS_THRESHOLD
) {
787 write_reg16(adev
, IO_ACX_IRQ_ACK
, HOST_INT_FCS_THRESHOLD
);
790 if (time_after(jiffies
, timeout
))
792 /* Init may take up to ~0.5 sec total */
801 /***********************************************************************
802 ** A few low-level helpers
804 ** Note: these functions are not protected by lock
805 ** and thus are never allowed to be called from IRQ.
806 ** Also they must not race with fw upload which uses same hw regs
809 /***********************************************************************
810 ** acxpci_write_cmd_type_status
814 acxpci_write_cmd_type_status(acx_device_t
*adev
, u16 type
, u16 status
)
816 writel(type
| (status
<< 16), adev
->cmd_area
);
821 /***********************************************************************
822 ** acxpci_read_cmd_type_status
825 acxpci_read_cmd_type_status(acx_device_t
*adev
)
827 u32 cmd_type
, cmd_status
;
829 cmd_type
= readl(adev
->cmd_area
);
830 cmd_status
= (cmd_type
>> 16);
831 cmd_type
= (u16
)cmd_type
;
833 log(L_CTL
, "cmd_type:%04X cmd_status:%04X [%s]\n",
834 cmd_type
, cmd_status
,
835 acx_cmd_status_str(cmd_status
));
841 /***********************************************************************
842 ** acxpci_s_reset_dev
845 ** netdevice that contains the adev variable
850 ** device is hard reset
854 ** This resets the device using low level hardware calls
855 ** as well as uploads and verifies the firmware to the card
859 init_mboxes(acx_device_t
*adev
)
861 u32 cmd_offs
, info_offs
;
863 cmd_offs
= read_reg32(adev
, IO_ACX_CMD_MAILBOX_OFFS
);
864 info_offs
= read_reg32(adev
, IO_ACX_INFO_MAILBOX_OFFS
);
865 adev
->cmd_area
= (u8
*)adev
->iobase2
+ cmd_offs
;
866 adev
->info_area
= (u8
*)adev
->iobase2
+ info_offs
;
867 log(L_DEBUG
, "iobase2=%p\n"
868 "cmd_mbox_offset=%X cmd_area=%p\n"
869 "info_mbox_offset=%X info_area=%p\n",
871 cmd_offs
, adev
->cmd_area
,
872 info_offs
, adev
->info_area
);
877 read_eeprom_area(acx_device_t
*adev
)
883 for (offs
= 0x8c; offs
< 0xb9; offs
++)
884 acxpci_read_eeprom_byte(adev
, offs
, &tmp
);
890 acxpci_s_reset_dev(acx_device_t
*adev
)
892 const char* msg
= "";
901 /* reset the device to make sure the eCPU is stopped
902 * to upload the firmware correctly */
904 acx_lock(adev
, flags
);
906 acxpci_l_reset_mac(adev
);
908 ecpu_ctrl
= read_reg16(adev
, IO_ACX_ECPU_CTRL
) & 1;
910 msg
= "eCPU is already running. ";
914 #ifdef WE_DONT_NEED_THAT_DO_WE
915 if (read_reg16(adev
, IO_ACX_SOR_CFG
) & 2) {
916 /* eCPU most likely means "embedded CPU" */
917 msg
= "eCPU did not start after boot from flash. ";
921 /* check sense on reset flags */
922 if (read_reg16(adev
, IO_ACX_SOR_CFG
) & 0x10) {
923 printk("%s: eCPU did not start after boot (SOR), "
924 "is this fatal?\n", adev
->ndev
->name
);
927 /* scan, if any, is stopped now, setting corresponding IRQ bit */
928 adev
->irq_status
|= HOST_INT_SCAN_COMPLETE
;
930 acx_unlock(adev
, flags
);
932 /* need to know radio type before fw load */
933 /* Need to wait for arrival of this information in a loop,
934 * most probably since eCPU runs some init code from EEPROM
935 * (started burst read in reset_mac()) which also
936 * sets the radio type ID */
940 hardware_info
= read_reg16(adev
, IO_ACX_EEPROM_INFORMATION
);
942 msg
= "eCPU didn't indicate radio type";
946 } while (!(hardware_info
& 0xff00)); /* radio type still zero? */
948 /* printk("DEBUG: count %d\n", count); */
949 adev
->form_factor
= hardware_info
& 0xff;
950 adev
->radio_type
= hardware_info
>> 8;
952 /* load the firmware */
953 if (OK
!= acxpci_s_upload_fw(adev
))
956 /* acx_s_msleep(10); this one really shouldn't be required */
958 /* now start eCPU by clearing bit */
959 write_reg16(adev
, IO_ACX_ECPU_CTRL
, ecpu_ctrl
& ~0x1);
960 log(L_DEBUG
, "booted eCPU up and waiting for completion...\n");
962 /* wait for eCPU bootup */
963 if (OK
!= acxpci_s_verify_init(adev
)) {
964 msg
= "timeout waiting for eCPU. ";
967 log(L_DEBUG
, "eCPU has woken up, card is ready to be configured\n");
970 acxpci_write_cmd_type_status(adev
, 0, 0);
972 /* test that EEPROM is readable */
973 read_eeprom_area(adev
);
978 /* Finish error message. Indicate which function failed */
980 acx_unlock(adev
, flags
);
982 printk("acx: %sreset_dev() FAILED\n", msg
);
989 /***********************************************************************
990 ** acxpci_s_issue_cmd_timeo
992 ** Sends command to fw, extract result
994 ** NB: we do _not_ take lock inside, so be sure to not touch anything
995 ** which may interfere with IRQ handler operation
997 ** TODO: busy wait is a bit silly, so:
998 ** 1) stop doing many iters - go to sleep after first
999 ** 2) go to waitqueue based approach: wait, not poll!
1002 #define FUNC "issue_cmd"
1006 acxpci_s_issue_cmd_timeo(
1011 unsigned cmd_timeout
)
1015 acxpci_s_issue_cmd_timeo_debug(
1020 unsigned cmd_timeout
,
1023 unsigned long start
= jiffies
;
1025 const char *devname
;
1029 unsigned long timeout
;
1033 devname
= adev
->ndev
->name
;
1034 if (!devname
|| !devname
[0] || devname
[4]=='%')
1037 log(L_CTL
, FUNC
"(cmd:%s,buflen:%u,timeout:%ums,type:0x%04X)\n",
1038 cmdstr
, buflen
, cmd_timeout
,
1039 buffer
? le16_to_cpu(((acx_ie_generic_t
*)buffer
)->type
) : -1);
1041 if (!(adev
->dev_state_mask
& ACX_STATE_FW_LOADED
)) {
1042 printk("%s: "FUNC
"(): firmware is not loaded yet, "
1043 "cannot execute commands!\n", devname
);
1047 if ((acx_debug
& L_DEBUG
) && (cmd
!= ACX1xx_CMD_INTERROGATE
)) {
1048 printk("input buffer (len=%u):\n", buflen
);
1049 acx_dump_bytes(buffer
, buflen
);
1052 /* wait for firmware to become idle for our command submission */
1054 counter
= (timeout
* 1000 / HZ
) - 1; /* in ms */
1057 cmd_status
= acxpci_read_cmd_type_status(adev
);
1058 /* Test for IDLE state */
1061 if (counter
% 5 == 0) {
1062 if (time_after(jiffies
, timeout
)) {
1066 /* we waited 5 iterations, no luck. Sleep 5 ms */
1069 } while (likely(--counter
));
1072 /* the card doesn't get idle, we're in trouble */
1073 printk("%s: "FUNC
"(): cmd_status is not IDLE: 0x%04X!=0\n",
1074 devname
, cmd_status
);
1076 } else if (counter
< 190) { /* if waited >10ms... */
1077 log(L_CTL
|L_DEBUG
, FUNC
"(): waited for IDLE %dms. "
1078 "Please report\n", 199 - counter
);
1081 /* now write the parameters of the command if needed */
1082 if (buffer
&& buflen
) {
1083 /* if it's an INTERROGATE command, just pass the length
1084 * of parameters to read, as data */
1086 if (cmd
== ACX1xx_CMD_INTERROGATE
)
1087 memset_io(adev
->cmd_area
+ 4, 0xAA, buflen
);
1089 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1090 memcpy_toio(adev
->cmd_area
+ 4, buffer
,
1091 (cmd
== ACX1xx_CMD_INTERROGATE
) ? 4 : buflen
);
1093 /* now write the actual command type */
1094 acxpci_write_cmd_type_status(adev
, cmd
, 0);
1095 /* execute command */
1096 write_reg16(adev
, IO_ACX_INT_TRIG
, INT_TRIG_CMD
);
1099 /* wait for firmware to process command */
1101 /* Ensure nonzero and not too large timeout.
1102 ** Also converts e.g. 100->99, 200->199
1103 ** which is nice but not essential */
1104 cmd_timeout
= (cmd_timeout
-1) | 1;
1105 if (unlikely(cmd_timeout
> 1199))
1107 /* clear CMD_COMPLETE bit. can be set only by IRQ handler: */
1108 adev
->irq_status
&= ~HOST_INT_CMD_COMPLETE
;
1110 /* we schedule away sometimes (timeout can be large) */
1111 counter
= cmd_timeout
;
1112 timeout
= jiffies
+ cmd_timeout
* HZ
/ 1000;
1114 if (!adev
->irqs_active
) { /* IRQ disabled: poll */
1115 irqtype
= read_reg16(adev
, IO_ACX_IRQ_STATUS_NON_DES
);
1116 if (irqtype
& HOST_INT_CMD_COMPLETE
) {
1117 write_reg16(adev
, IO_ACX_IRQ_ACK
,
1118 HOST_INT_CMD_COMPLETE
);
1121 } else { /* Wait when IRQ will set the bit */
1122 irqtype
= adev
->irq_status
;
1123 if (irqtype
& HOST_INT_CMD_COMPLETE
)
1127 if (counter
% 5 == 0) {
1128 if (time_after(jiffies
, timeout
)) {
1132 /* we waited 5 iterations, no luck. Sleep 5 ms */
1135 } while (likely(--counter
));
1137 /* save state for debugging */
1138 cmd_status
= acxpci_read_cmd_type_status(adev
);
1140 /* put the card in IDLE state */
1141 acxpci_write_cmd_type_status(adev
, 0, 0);
1143 if (!counter
) { /* timed out! */
1144 printk("%s: "FUNC
"(): timed out %s for CMD_COMPLETE. "
1145 "irq bits:0x%04X irq_status:0x%04X timeout:%dms "
1146 "cmd_status:%d (%s)\n",
1147 devname
, (adev
->irqs_active
) ? "waiting" : "polling",
1148 irqtype
, adev
->irq_status
, cmd_timeout
,
1149 cmd_status
, acx_cmd_status_str(cmd_status
));
1151 } else if (cmd_timeout
- counter
> 30) { /* if waited >30ms... */
1152 log(L_CTL
|L_DEBUG
, FUNC
"(): %s for CMD_COMPLETE %dms. "
1153 "count:%d. Please report\n",
1154 (adev
->irqs_active
) ? "waited" : "polled",
1155 cmd_timeout
- counter
, counter
);
1158 if (1 != cmd_status
) { /* it is not a 'Success' */
1159 printk("%s: "FUNC
"(): cmd_status is not SUCCESS: %d (%s). "
1160 "Took %dms of %d\n",
1161 devname
, cmd_status
, acx_cmd_status_str(cmd_status
),
1162 cmd_timeout
- counter
, cmd_timeout
);
1163 /* zero out result buffer
1164 * WARNING: this will trash stack in case of illegally large input
1166 if (buffer
&& buflen
)
1167 memset(buffer
, 0, buflen
);
1171 /* read in result parameters if needed */
1172 if (buffer
&& buflen
&& (cmd
== ACX1xx_CMD_INTERROGATE
)) {
1173 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1174 memcpy_fromio(buffer
, adev
->cmd_area
+ 4, buflen
);
1175 if (acx_debug
& L_DEBUG
) {
1176 printk("output buffer (len=%u): ", buflen
);
1177 acx_dump_bytes(buffer
, buflen
);
1181 log(L_CTL
, FUNC
"(%s): took %ld jiffies to complete\n",
1182 cmdstr
, jiffies
- start
);
1187 /* Give enough info so that callers can avoid
1188 ** printing their own diagnostic messages */
1190 printk("%s: "FUNC
"(cmd:%s) FAILED\n", devname
, cmdstr
);
1192 printk("%s: "FUNC
"(cmd:0x%04X) FAILED\n", devname
, cmd
);
1200 /***********************************************************************
1202 #ifdef NONESSENTIAL_FEATURES
1203 typedef struct device_id
{
1204 unsigned char id
[6];
1209 static const device_id_t
1213 {'G', 'l', 'o', 'b', 'a', 'l'},
1218 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
1220 "SpeedStream SS1021 or Gigafast WF721-AEX"
1223 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85},
1228 {'?', '?', '?', '?', '?', '?'},
1230 "Level One WPC-0200"
1233 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1240 acx_show_card_eeprom_id(acx_device_t
*adev
)
1242 unsigned char buffer
[CARD_EEPROM_ID_SIZE
];
1245 memset(&buffer
, 0, CARD_EEPROM_ID_SIZE
);
1246 /* use direct EEPROM access */
1247 for (i
= 0; i
< CARD_EEPROM_ID_SIZE
; i
++) {
1248 if (OK
!= acxpci_read_eeprom_byte(adev
,
1249 ACX100_EEPROM_ID_OFFSET
+ i
,
1251 printk("acx: reading EEPROM FAILED\n");
1256 for (i
= 0; i
< VEC_SIZE(device_ids
); i
++) {
1257 if (!memcmp(&buffer
, device_ids
[i
].id
, CARD_EEPROM_ID_SIZE
)) {
1258 if (device_ids
[i
].descr
) {
1259 printk("acx: EEPROM card ID string check "
1260 "found %s card ID: is this %s?\n",
1261 device_ids
[i
].descr
, device_ids
[i
].type
);
1266 if (i
== VEC_SIZE(device_ids
)) {
1267 printk("acx: EEPROM card ID string check found "
1268 "unknown card: expected 'Global', got '%.*s\'. "
1269 "Please report\n", CARD_EEPROM_ID_SIZE
, buffer
);
1272 #endif /* NONESSENTIAL_FEATURES */
1275 /***********************************************************************
1278 acxpci_s_device_chain_add(struct net_device
*ndev
)
1280 acx_device_t
*adev
= ndev2adev(ndev
);
1282 down(&root_adev_sem
);
1283 adev
->prev_nd
= root_adev_newest
;
1284 root_adev_newest
= ndev
;
1290 acxpci_s_device_chain_remove(struct net_device
*ndev
)
1292 struct net_device
*querydev
;
1293 struct net_device
*olderdev
;
1294 struct net_device
*newerdev
;
1296 down(&root_adev_sem
);
1297 querydev
= root_adev_newest
;
1300 olderdev
= ndev2adev(querydev
)->prev_nd
;
1301 if (0 == strcmp(querydev
->name
, ndev
->name
)) {
1303 /* if we were at the beginning of the
1304 * list, then it's the list head that
1305 * we need to update to point at the
1306 * next older device */
1307 root_adev_newest
= olderdev
;
1309 /* it's the device that is newer than us
1310 * that we need to update to point at
1311 * the device older than us */
1312 ndev2adev(newerdev
)->prev_nd
= olderdev
;
1316 /* "newerdev" is actually the device of the old iteration,
1317 * but since the list starts (root_adev_newest)
1318 * with the newest devices,
1319 * it's newer than the ones following.
1320 * Oh the joys of iterating from newest to oldest :-\ */
1321 newerdev
= querydev
;
1323 /* keep checking old devices for matches until we hit the end
1325 querydev
= olderdev
;
1331 /***********************************************************************
1332 ** acxpci_free_desc_queues
1334 ** Releases the queues that have been allocated, the
1335 ** others have been initialised to NULL so this
1336 ** function can be used if only part of the queues were allocated.
1340 free_coherent(struct pci_dev
*hwdev
, size_t size
,
1341 void *vaddr
, dma_addr_t dma_handle
)
1343 dma_free_coherent(hwdev
== NULL
? NULL
: &hwdev
->dev
,
1344 size
, vaddr
, dma_handle
);
1348 acxpci_free_desc_queues(acx_device_t
*adev
)
1350 #define ACX_FREE_QUEUE(size, ptr, phyaddr) \
1352 free_coherent(0, size, ptr, phyaddr); \
1359 ACX_FREE_QUEUE(adev
->txhostdesc_area_size
, adev
->txhostdesc_start
, adev
->txhostdesc_startphy
);
1360 ACX_FREE_QUEUE(adev
->txbuf_area_size
, adev
->txbuf_start
, adev
->txbuf_startphy
);
1362 adev
->txdesc_start
= NULL
;
1364 ACX_FREE_QUEUE(adev
->rxhostdesc_area_size
, adev
->rxhostdesc_start
, adev
->rxhostdesc_startphy
);
1365 ACX_FREE_QUEUE(adev
->rxbuf_area_size
, adev
->rxbuf_start
, adev
->rxbuf_startphy
);
1367 adev
->rxdesc_start
= NULL
;
1373 /***********************************************************************
1374 ** acxpci_s_delete_dma_regions
1377 acxpci_s_delete_dma_regions(acx_device_t
*adev
)
1379 unsigned long flags
;
1382 /* disable radio Tx/Rx. Shouldn't we use the firmware commands
1383 * here instead? Or are we that much down the road that it's no
1384 * longer possible here? */
1385 write_reg16(adev
, IO_ACX_ENABLE
, 0);
1389 acx_lock(adev
, flags
);
1390 acxpci_free_desc_queues(adev
);
1391 acx_unlock(adev
, flags
);
1397 /***********************************************************************
1400 ** Probe routine called when a PCI device w/ matching ID is found.
1401 ** Here's the sequence:
1402 ** - Allocate the PCI resources.
1403 ** - Read the PCMCIA attribute memory to make sure we have a WLAN card
1405 ** - Initialize the dev and wlan data
1406 ** - Initialize the MAC
1408 ** pdev - ptr to pci device structure containing info about pci configuration
1409 ** id - ptr to the device id entry that matched this device
1414 0x0000, /* IO_ACX_SOFT_RESET */
1416 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1417 0x0018, /* IO_ACX_SLV_MEM_DATA */
1418 0x001c, /* IO_ACX_SLV_MEM_CTL */
1419 0x0020, /* IO_ACX_SLV_END_CTL */
1421 0x0034, /* IO_ACX_FEMR */
1423 0x007c, /* IO_ACX_INT_TRIG */
1424 0x0098, /* IO_ACX_IRQ_MASK */
1425 0x00a4, /* IO_ACX_IRQ_STATUS_NON_DES */
1426 0x00a8, /* IO_ACX_IRQ_STATUS_CLEAR */
1427 0x00ac, /* IO_ACX_IRQ_ACK */
1428 0x00b0, /* IO_ACX_HINT_TRIG */
1430 0x0104, /* IO_ACX_ENABLE */
1432 0x0250, /* IO_ACX_EEPROM_CTL */
1433 0x0254, /* IO_ACX_EEPROM_ADDR */
1434 0x0258, /* IO_ACX_EEPROM_DATA */
1435 0x025c, /* IO_ACX_EEPROM_CFG */
1437 0x0268, /* IO_ACX_PHY_ADDR */
1438 0x026c, /* IO_ACX_PHY_DATA */
1439 0x0270, /* IO_ACX_PHY_CTL */
1441 0x0290, /* IO_ACX_GPIO_OE */
1443 0x0298, /* IO_ACX_GPIO_OUT */
1445 0x02a4, /* IO_ACX_CMD_MAILBOX_OFFS */
1446 0x02a8, /* IO_ACX_INFO_MAILBOX_OFFS */
1447 0x02ac, /* IO_ACX_EEPROM_INFORMATION */
1449 0x02d0, /* IO_ACX_EE_START */
1450 0x02d4, /* IO_ACX_SOR_CFG */
1451 0x02d8 /* IO_ACX_ECPU_CTRL */
1457 0x0000, /* IO_ACX_SOFT_RESET */
1459 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1460 0x0018, /* IO_ACX_SLV_MEM_DATA */
1461 0x001c, /* IO_ACX_SLV_MEM_CTL */
1462 0x0020, /* IO_ACX_SLV_END_CTL */
1464 0x0034, /* IO_ACX_FEMR */
1466 0x00b4, /* IO_ACX_INT_TRIG */
1467 0x00d4, /* IO_ACX_IRQ_MASK */
1468 /* we do mean NON_DES (0xf0), not NON_DES_MASK which is at 0xe0: */
1469 0x00f0, /* IO_ACX_IRQ_STATUS_NON_DES */
1470 0x00e4, /* IO_ACX_IRQ_STATUS_CLEAR */
1471 0x00e8, /* IO_ACX_IRQ_ACK */
1472 0x00ec, /* IO_ACX_HINT_TRIG */
1474 0x01d0, /* IO_ACX_ENABLE */
1476 0x0338, /* IO_ACX_EEPROM_CTL */
1477 0x033c, /* IO_ACX_EEPROM_ADDR */
1478 0x0340, /* IO_ACX_EEPROM_DATA */
1479 0x0344, /* IO_ACX_EEPROM_CFG */
1481 0x0350, /* IO_ACX_PHY_ADDR */
1482 0x0354, /* IO_ACX_PHY_DATA */
1483 0x0358, /* IO_ACX_PHY_CTL */
1485 0x0374, /* IO_ACX_GPIO_OE */
1487 0x037c, /* IO_ACX_GPIO_OUT */
1489 0x0388, /* IO_ACX_CMD_MAILBOX_OFFS */
1490 0x038c, /* IO_ACX_INFO_MAILBOX_OFFS */
1491 0x0390, /* IO_ACX_EEPROM_INFORMATION */
1493 0x0100, /* IO_ACX_EE_START */
1494 0x0104, /* IO_ACX_SOR_CFG */
1495 0x0108, /* IO_ACX_ECPU_CTRL */
1499 dummy_netdev_init(struct net_device
*ndev
) {}
1501 static int __devinit
1502 acxpci_e_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1504 acx111_ie_configoption_t co
;
1505 unsigned long mem_region1
= 0;
1506 unsigned long mem_region2
= 0;
1507 unsigned long mem_region1_size
;
1508 unsigned long mem_region2_size
;
1509 unsigned long phymem1
;
1510 unsigned long phymem2
;
1513 acx_device_t
*adev
= NULL
;
1514 struct net_device
*ndev
= NULL
;
1515 const char *chip_name
;
1522 /* Enable the PCI device */
1523 if (pci_enable_device(pdev
)) {
1524 printk("acx: pci_enable_device() FAILED\n");
1526 goto fail_pci_enable_device
;
1529 /* enable busmastering (required for CardBus) */
1530 pci_set_master(pdev
);
1532 /* FIXME: prism54 calls pci_set_mwi() here,
1533 * should we do/support the same? */
1535 /* chiptype is u8 but id->driver_data is ulong
1536 ** Works for now (possible values are 1 and 2) */
1537 chip_type
= (u8
)id
->driver_data
;
1538 /* acx100 and acx111 have different PCI memory regions */
1539 if (chip_type
== CHIPTYPE_ACX100
) {
1540 chip_name
= "ACX100";
1541 mem_region1
= PCI_ACX100_REGION1
;
1542 mem_region1_size
= PCI_ACX100_REGION1_SIZE
;
1544 mem_region2
= PCI_ACX100_REGION2
;
1545 mem_region2_size
= PCI_ACX100_REGION2_SIZE
;
1546 } else if (chip_type
== CHIPTYPE_ACX111
) {
1547 chip_name
= "ACX111";
1548 mem_region1
= PCI_ACX111_REGION1
;
1549 mem_region1_size
= PCI_ACX111_REGION1_SIZE
;
1551 mem_region2
= PCI_ACX111_REGION2
;
1552 mem_region2_size
= PCI_ACX111_REGION2_SIZE
;
1554 printk("acx: unknown chip type 0x%04X\n", chip_type
);
1555 goto fail_unknown_chiptype
;
1558 /* Figure out our resources */
1559 phymem1
= pci_resource_start(pdev
, mem_region1
);
1560 phymem2
= pci_resource_start(pdev
, mem_region2
);
1561 if (!request_mem_region(phymem1
, pci_resource_len(pdev
, mem_region1
), "acx_1")) {
1562 printk("acx: cannot reserve PCI memory region 1 (are you sure "
1563 "you have CardBus support in kernel?)\n");
1564 goto fail_request_mem_region1
;
1566 if (!request_mem_region(phymem2
, pci_resource_len(pdev
, mem_region2
), "acx_2")) {
1567 printk("acx: cannot reserve PCI memory region 2\n");
1568 goto fail_request_mem_region2
;
1570 mem1
= ioremap(phymem1
, mem_region1_size
);
1572 printk("acx: ioremap() FAILED\n");
1575 mem2
= ioremap(phymem2
, mem_region2_size
);
1577 printk("acx: ioremap() #2 FAILED\n");
1581 printk("acx: found %s-based wireless network card at %s, irq:%d, "
1582 "phymem1:0x%lX, phymem2:0x%lX, mem1:0x%p, mem1_size:%ld, "
1583 "mem2:0x%p, mem2_size:%ld\n",
1584 chip_name
, pci_name(pdev
), pdev
->irq
, phymem1
, phymem2
,
1585 mem1
, mem_region1_size
,
1586 mem2
, mem_region2_size
);
1587 log(L_ANY
, "initial debug setting is 0x%04X\n", acx_debug
);
1589 if (0 == pdev
->irq
) {
1590 printk("acx: can't use IRQ 0\n");
1594 ndev
= alloc_netdev(sizeof(*adev
), "wlan%d", dummy_netdev_init
);
1595 /* (NB: memsets to 0 entire area) */
1597 printk("acx: no memory for netdevice structure\n");
1598 goto fail_alloc_netdev
;
1602 ndev
->open
= &acxpci_e_open
;
1603 ndev
->stop
= &acxpci_e_close
;
1604 ndev
->hard_start_xmit
= &acx_i_start_xmit
;
1605 ndev
->get_stats
= &acx_e_get_stats
;
1606 #if IW_HANDLER_VERSION <= 5
1607 ndev
->get_wireless_stats
= &acx_e_get_wireless_stats
;
1609 ndev
->wireless_handlers
= (struct iw_handler_def
*)&acx_ioctl_handler_def
;
1610 ndev
->set_multicast_list
= &acxpci_i_set_multicast_list
;
1611 ndev
->tx_timeout
= &acxpci_i_tx_timeout
;
1612 ndev
->change_mtu
= &acx_e_change_mtu
;
1613 ndev
->watchdog_timeo
= 4 * HZ
;
1614 ndev
->irq
= pdev
->irq
;
1615 ndev
->base_addr
= pci_resource_start(pdev
, 0);
1617 adev
= ndev2adev(ndev
);
1618 spin_lock_init(&adev
->lock
); /* initial state: unlocked */
1619 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
1620 sema_init(&adev
->sem
, 1); /* initial state: 1 (upped) */
1621 /* since nobody can see new netdev yet, we can as well
1622 ** just _presume_ that we're under sem (instead of actually taking it): */
1623 /* acx_sem_lock(adev); */
1625 adev
->dev_type
= DEVTYPE_PCI
;
1626 adev
->chip_type
= chip_type
;
1627 adev
->chip_name
= chip_name
;
1628 adev
->io
= (CHIPTYPE_ACX100
== chip_type
) ? IO_ACX100
: IO_ACX111
;
1629 adev
->membase
= phymem1
;
1630 adev
->iobase
= mem1
;
1631 adev
->membase2
= phymem2
;
1632 adev
->iobase2
= mem2
;
1633 /* to find crashes due to weird driver access
1634 * to unconfigured interface (ifup) */
1635 adev
->mgmt_timer
.function
= (void (*)(unsigned long))0x0000dead;
1637 #ifdef NONESSENTIAL_FEATURES
1638 acx_show_card_eeprom_id(adev
);
1639 #endif /* NONESSENTIAL_FEATURES */
1641 #ifdef SET_MODULE_OWNER
1642 SET_MODULE_OWNER(ndev
);
1644 SET_NETDEV_DEV(ndev
, &pdev
->dev
);
1646 /* register new dev in linked list */
1647 acxpci_s_device_chain_add(ndev
);
1649 log(L_IRQ
|L_INIT
, "using IRQ %d\n", pdev
->irq
);
1651 /* need to be able to restore PCI state after a suspend */
1652 pci_save_state(pdev
);
1653 pci_set_drvdata(pdev
, ndev
);
1655 /* ok, pci setup is finished, now start initializing the card */
1657 /* NB: read_reg() reads may return bogus data before reset_dev(),
1658 * since the firmware which directly controls large parts of the I/O
1659 * registers isn't initialized yet.
1660 * acx100 seems to be more affected than acx111 */
1661 if (OK
!= acxpci_s_reset_dev(adev
))
1664 if (OK
!= acxpci_read_eeprom_byte(adev
, 0x05, &adev
->eeprom_version
))
1665 goto fail_read_eeprom_version
;
1667 if (IS_ACX100(adev
)) {
1668 /* ACX100: configopt struct in cmd mailbox - directly after reset */
1669 memcpy_fromio(&co
, adev
->cmd_area
, sizeof(co
));
1672 if (OK
!= acx_s_init_mac(adev
))
1675 if (IS_ACX111(adev
)) {
1676 /* ACX111: configopt struct needs to be queried after full init */
1677 acx_s_interrogate(adev
, &co
, ACX111_IE_CONFIG_OPTIONS
);
1680 //TODO: merge them into one function, they are called just once and are the same for pci & usb
1681 acx_s_parse_configoption(adev
, &co
);
1682 acx_s_set_defaults(adev
);
1683 acx_s_get_firmware_version(adev
); /* needs to be after acx_s_init_mac() */
1684 acx_display_hardware_details(adev
);
1686 /* Register the card, AFTER everything else has been set up,
1687 * since otherwise an ioctl could step on our feet due to
1688 * firmware operations happening in parallel or uninitialized data */
1689 err
= register_netdev(ndev
);
1691 printk("acx: register_netdev() FAILED: %d\n", err
);
1692 goto fail_register_netdev
;
1695 acx_proc_register_entries(ndev
);
1697 /* Now we have our device, so make sure the kernel doesn't try
1698 * to send packets even though we're not associated to a network yet */
1699 acx_stop_queue(ndev
, "on probe");
1700 acx_carrier_off(ndev
, "on probe");
1702 /* after register_netdev() userspace may start working with dev
1703 * (in particular, on other CPUs), we only need to up the sem */
1704 /* acx_sem_unlock(adev); */
1706 printk("acx "ACX_RELEASE
": net device %s, driver compiled "
1707 "against wireless extensions %d and Linux %s\n",
1708 ndev
->name
, WIRELESS_EXT
, UTS_RELEASE
);
1711 great_inquisitor(adev
);
1717 /* error paths: undo everything in reverse order... */
1719 fail_register_netdev
:
1721 acxpci_s_delete_dma_regions(adev
);
1722 pci_set_drvdata(pdev
, NULL
);
1725 fail_read_eeprom_version
:
1728 acxpci_s_device_chain_remove(ndev
);
1739 release_mem_region(pci_resource_start(pdev
, mem_region2
),
1740 pci_resource_len(pdev
, mem_region2
));
1741 fail_request_mem_region2
:
1743 release_mem_region(pci_resource_start(pdev
, mem_region1
),
1744 pci_resource_len(pdev
, mem_region1
));
1745 fail_request_mem_region1
:
1746 fail_unknown_chiptype
:
1748 pci_disable_device(pdev
);
1749 fail_pci_enable_device
:
1751 pci_set_power_state(pdev
, PCI_D3hot
);
1759 /***********************************************************************
1762 ** Deallocate PCI resources for the acx chip.
1764 ** This should NOT execute any other hardware operations on the card,
1765 ** since the card might already be ejected. Instead, that should be done
1766 ** in cleanup_module, since the card is most likely still available there.
1768 ** pdev - ptr to PCI device structure containing info about pci configuration
1770 static void __devexit
1771 acxpci_e_remove(struct pci_dev
*pdev
)
1773 struct net_device
*ndev
;
1775 unsigned long mem_region1
, mem_region2
;
1779 ndev
= (struct net_device
*) pci_get_drvdata(pdev
);
1781 log(L_DEBUG
, "%s: card is unused. Skipping any release code\n",
1786 adev
= ndev2adev(ndev
);
1788 /* unregister the device to not let the kernel
1789 * (e.g. ioctls) access a half-deconfigured device
1790 * NB: this will cause acxpci_e_close() to be called,
1791 * thus we shouldn't call it under sem! */
1792 log(L_INIT
, "removing device %s\n", ndev
->name
);
1793 unregister_netdev(ndev
);
1795 /* unregister_netdev ensures that no references to us left.
1796 * For paranoid reasons we continue to follow the rules */
1799 if (IS_ACX100(adev
)) {
1800 mem_region1
= PCI_ACX100_REGION1
;
1801 mem_region2
= PCI_ACX100_REGION2
;
1803 mem_region1
= PCI_ACX111_REGION1
;
1804 mem_region2
= PCI_ACX111_REGION2
;
1807 acx_proc_unregister_entries(ndev
);
1809 /* find our PCI device in the global acx list and remove it */
1810 acxpci_s_device_chain_remove(ndev
);
1812 if (adev
->dev_state_mask
& ACX_STATE_IFACE_UP
)
1813 acxpci_s_down(ndev
);
1815 CLEAR_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
1817 acxpci_s_delete_dma_regions(adev
);
1819 /* finally, clean up PCI bus state */
1820 if (adev
->iobase
) iounmap(adev
->iobase
);
1821 if (adev
->iobase2
) iounmap(adev
->iobase2
);
1823 release_mem_region(pci_resource_start(pdev
, mem_region1
),
1824 pci_resource_len(pdev
, mem_region1
));
1826 release_mem_region(pci_resource_start(pdev
, mem_region2
),
1827 pci_resource_len(pdev
, mem_region2
));
1829 pci_disable_device(pdev
);
1831 /* remove dev registration */
1832 pci_set_drvdata(pdev
, NULL
);
1834 /* Free netdev (quite late,
1835 * since otherwise we might get caught off-guard
1836 * by a netdev timeout handler execution
1837 * expecting to see a working dev...) */
1840 /* put device into ACPI D3 mode (shutdown) */
1841 pci_set_power_state(pdev
, PCI_D3hot
);
1848 /***********************************************************************
1849 ** TODO: PM code needs to be fixed / debugged / tested.
1853 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
1854 acxpci_e_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1856 acxpci_e_suspend(struct pci_dev
*pdev
, u32 state
)
1859 struct net_device
*ndev
= pci_get_drvdata(pdev
);
1863 printk("acx: suspend handler is experimental!\n");
1864 printk("sus: dev %p\n", ndev
);
1866 if (!netif_running(ndev
))
1869 adev
= ndev2adev(ndev
);
1870 printk("sus: adev %p\n", adev
);
1874 netif_device_detach(ndev
); /* this one cannot sleep */
1875 acxpci_s_down(ndev
);
1876 /* down() does not set it to 0xffff, but here we really want that */
1877 write_reg16(adev
, IO_ACX_IRQ_MASK
, 0xffff);
1878 write_reg16(adev
, IO_ACX_FEMR
, 0x0);
1879 acxpci_s_delete_dma_regions(adev
);
1880 pci_save_state(pdev
);
1881 pci_set_power_state(pdev
, PCI_D3hot
);
1883 acx_sem_unlock(adev
);
1891 acxpci_e_resume(struct pci_dev
*pdev
)
1893 struct net_device
*ndev
= pci_get_drvdata(pdev
);
1898 printk("acx: resume handler is experimental!\n");
1899 printk("rsm: got dev %p\n", ndev
);
1901 if (!netif_running(ndev
))
1904 adev
= ndev2adev(ndev
);
1905 printk("rsm: got adev %p\n", adev
);
1909 pci_set_power_state(pdev
, PCI_D0
);
1910 printk("rsm: power state PCI_D0 set\n");
1911 pci_restore_state(pdev
);
1912 printk("rsm: PCI state restored\n");
1914 if (OK
!= acxpci_s_reset_dev(adev
))
1916 printk("rsm: device reset done\n");
1917 if (OK
!= acx_s_init_mac(adev
))
1919 printk("rsm: init MAC done\n");
1922 printk("rsm: acx up done\n");
1924 /* now even reload all card parameters as they were before suspend,
1925 * and possibly be back in the network again already :-) */
1926 if (ACX_STATE_IFACE_UP
& adev
->dev_state_mask
) {
1927 adev
->set_mask
= GETSET_ALL
;
1928 acx_s_update_card_settings(adev
);
1929 printk("rsm: settings updated\n");
1931 netif_device_attach(ndev
);
1932 printk("rsm: device attached\n");
1935 acx_sem_unlock(adev
);
1937 /* we need to return OK here anyway, right? */
1941 #endif /* CONFIG_PM */
1944 /***********************************************************************
1947 ** This function is called by acxpci_e_open (when ifconfig sets the device as up)
1950 ** - Enables on-card interrupt requests
1951 ** - calls acx_s_start
1955 enable_acx_irq(acx_device_t
*adev
)
1958 write_reg16(adev
, IO_ACX_IRQ_MASK
, adev
->irq_mask
);
1959 write_reg16(adev
, IO_ACX_FEMR
, 0x8000);
1960 adev
->irqs_active
= 1;
1965 acxpci_s_up(struct net_device
*ndev
)
1967 acx_device_t
*adev
= ndev2adev(ndev
);
1968 unsigned long flags
;
1972 acx_lock(adev
, flags
);
1973 enable_acx_irq(adev
);
1974 acx_unlock(adev
, flags
);
1976 /* acx fw < 1.9.3.e has a hardware timer, and older drivers
1977 ** used to use it. But we don't do that anymore, our OS
1978 ** has reliable software timers */
1979 init_timer(&adev
->mgmt_timer
);
1980 adev
->mgmt_timer
.function
= acx_i_timer
;
1981 adev
->mgmt_timer
.data
= (unsigned long)adev
;
1983 /* Need to set ACX_STATE_IFACE_UP first, or else
1984 ** timer won't be started by acx_set_status() */
1985 SET_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
1986 switch (adev
->mode
) {
1987 case ACX_MODE_0_ADHOC
:
1988 case ACX_MODE_2_STA
:
1989 /* actual scan cmd will happen in start() */
1990 acx_set_status(adev
, ACX_STATUS_1_SCANNING
); break;
1992 case ACX_MODE_MONITOR
:
1993 acx_set_status(adev
, ACX_STATUS_4_ASSOCIATED
); break;
2002 /***********************************************************************
2005 ** This disables the netdevice
2008 ** - disables on-card interrupt request
2012 disable_acx_irq(acx_device_t
*adev
)
2016 /* I guess mask is not 0xffff because acx100 won't signal
2017 ** cmd completion then (needed for ifup).
2018 ** Someone with acx100 please confirm */
2019 write_reg16(adev
, IO_ACX_IRQ_MASK
, adev
->irq_mask_off
);
2020 write_reg16(adev
, IO_ACX_FEMR
, 0x0);
2021 adev
->irqs_active
= 0;
2026 acxpci_s_down(struct net_device
*ndev
)
2028 acx_device_t
*adev
= ndev2adev(ndev
);
2029 unsigned long flags
;
2033 /* Disable IRQs first, so that IRQs cannot race with us */
2034 /* then wait until interrupts have finished executing on other CPUs */
2035 acx_lock(adev
, flags
);
2036 disable_acx_irq(adev
);
2037 synchronize_irq(adev
->pdev
->irq
);
2038 acx_unlock(adev
, flags
);
2040 /* we really don't want to have an asynchronous tasklet disturb us
2041 ** after something vital for its job has been shut down, so
2042 ** end all remaining work now.
2044 ** NB: carrier_off (done by set_status below) would lead to
2045 ** not yet fully understood deadlock in FLUSH_SCHEDULED_WORK().
2046 ** That's why we do FLUSH first.
2048 ** NB2: we have a bad locking bug here: FLUSH_SCHEDULED_WORK()
2049 ** waits for acx_e_after_interrupt_task to complete if it is running
2050 ** on another CPU, but acx_e_after_interrupt_task
2051 ** will sleep on sem forever, because it is taken by us!
2052 ** Work around that by temporary sem unlock.
2053 ** This will fail miserably if we'll be hit by concurrent
2054 ** iwconfig or something in between. TODO! */
2055 acx_sem_unlock(adev
);
2056 FLUSH_SCHEDULED_WORK();
2059 /* This is possible:
2060 ** FLUSH_SCHEDULED_WORK -> acx_e_after_interrupt_task ->
2061 ** -> set_status(ASSOCIATED) -> wake_queue()
2062 ** That's why we stop queue _after_ FLUSH_SCHEDULED_WORK
2063 ** lock/unlock is just paranoia, maybe not needed */
2064 acx_lock(adev
, flags
);
2065 acx_stop_queue(ndev
, "on ifdown");
2066 acx_set_status(adev
, ACX_STATUS_0_STOPPED
);
2067 acx_unlock(adev
, flags
);
2069 /* kernel/timer.c says it's illegal to del_timer_sync()
2070 ** a timer which restarts itself. We guarantee this cannot
2071 ** ever happen because acx_i_timer() never does this if
2072 ** status is ACX_STATUS_0_STOPPED */
2073 del_timer_sync(&adev
->mgmt_timer
);
2079 /***********************************************************************
2082 ** Called as a result of SIOCSIFFLAGS ioctl changing the flags bit IFF_UP
2083 ** from clear to set. In other words: ifconfig up.
2087 ** >0 f/w reported error
2088 ** <0 driver reported error
2091 acxpci_e_open(struct net_device
*ndev
)
2093 acx_device_t
*adev
= ndev2adev(ndev
);
2100 acx_init_task_scheduler(adev
);
2102 //TODO: pci_set_power_state(pdev, PCI_D0); ?
2104 /* request shared IRQ handler */
2105 if (request_irq(ndev
->irq
, acxpci_i_interrupt
, SA_SHIRQ
, ndev
->name
, ndev
)) {
2106 printk("%s: request_irq FAILED\n", ndev
->name
);
2110 log(L_DEBUG
|L_IRQ
, "request_irq %d successful\n", ndev
->irq
);
2115 /* We don't currently have to do anything else.
2116 * The setup of the MAC should be subsequently completed via
2117 * the mlme commands.
2118 * Higher layers know we're ready from dev->start==1 and
2119 * dev->tbusy==0. Our rx path knows to pass up received/
2120 * frames because of dev->flags&IFF_UP is true.
2123 acx_sem_unlock(adev
);
2130 /***********************************************************************
2133 ** Called as a result of SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
2134 ** from set to clear. I.e. called by "ifconfig DEV down"
2138 ** >0 f/w reported error
2139 ** <0 driver reported error
2142 acxpci_e_close(struct net_device
*ndev
)
2144 acx_device_t
*adev
= ndev2adev(ndev
);
2151 CLEAR_BIT(adev
->dev_state_mask
, ACX_STATE_IFACE_UP
);
2152 if (netif_device_present(ndev
)) {
2153 acxpci_s_down(ndev
);
2156 /* disable all IRQs, release shared IRQ handler */
2157 write_reg16(adev
, IO_ACX_IRQ_MASK
, 0xffff);
2158 write_reg16(adev
, IO_ACX_FEMR
, 0x0);
2159 free_irq(ndev
->irq
, ndev
);
2161 //TODO: pci_set_power_state(pdev, PCI_D3hot); ?
2163 /* We currently don't have to do anything else.
2164 * Higher layers know we're not ready from dev->start==0 and
2165 * dev->tbusy==1. Our rx path knows to not pass up received
2166 * frames because of dev->flags&IFF_UP is false.
2168 acx_sem_unlock(adev
);
2170 log(L_INIT
, "closed device\n");
2176 /***********************************************************************
2177 ** acxpci_i_tx_timeout
2179 ** Called from network core. Must not sleep!
2182 acxpci_i_tx_timeout(struct net_device
*ndev
)
2184 acx_device_t
*adev
= ndev2adev(ndev
);
2185 unsigned long flags
;
2186 unsigned int tx_num_cleaned
;
2190 acx_lock(adev
, flags
);
2192 /* clean processed tx descs, they may have been completely full */
2193 tx_num_cleaned
= acxpci_l_clean_txdesc(adev
);
2195 /* nothing cleaned, yet (almost) no free buffers available?
2196 * --> clean all tx descs, no matter which status!!
2197 * Note that I strongly suspect that doing emergency cleaning
2198 * may confuse the firmware. This is a last ditch effort to get
2199 * ANYTHING to work again...
2201 * TODO: it's best to simply reset & reinit hw from scratch...
2203 if ((adev
->tx_free
<= TX_EMERG_CLEAN
) && (tx_num_cleaned
== 0)) {
2204 printk("%s: FAILED to free any of the many full tx buffers. "
2205 "Switching to emergency freeing. "
2206 "Please report!\n", ndev
->name
);
2207 acxpci_l_clean_txdesc_emergency(adev
);
2210 if (acx_queue_stopped(ndev
) && (ACX_STATUS_4_ASSOCIATED
== adev
->status
))
2211 acx_wake_queue(ndev
, "after tx timeout");
2213 /* stall may have happened due to radio drift, so recalib radio */
2214 acx_schedule_task(adev
, ACX_AFTER_IRQ_CMD_RADIO_RECALIB
);
2216 /* do unimportant work last */
2217 printk("%s: tx timeout!\n", ndev
->name
);
2218 adev
->stats
.tx_errors
++;
2220 acx_unlock(adev
, flags
);
2226 /***********************************************************************
2227 ** acxpci_i_set_multicast_list
2228 ** FIXME: most likely needs refinement
2231 acxpci_i_set_multicast_list(struct net_device
*ndev
)
2233 acx_device_t
*adev
= ndev2adev(ndev
);
2234 unsigned long flags
;
2238 acx_lock(adev
, flags
);
2240 /* firmwares don't have allmulti capability,
2241 * so just use promiscuous mode instead in this case. */
2242 if (ndev
->flags
& (IFF_PROMISC
|IFF_ALLMULTI
)) {
2243 SET_BIT(adev
->rx_config_1
, RX_CFG1_RCV_PROMISCUOUS
);
2244 CLEAR_BIT(adev
->rx_config_1
, RX_CFG1_FILTER_ALL_MULTI
);
2245 SET_BIT(adev
->set_mask
, SET_RXCONFIG
);
2246 /* let kernel know in case *we* needed to set promiscuous */
2247 ndev
->flags
|= (IFF_PROMISC
|IFF_ALLMULTI
);
2249 CLEAR_BIT(adev
->rx_config_1
, RX_CFG1_RCV_PROMISCUOUS
);
2250 SET_BIT(adev
->rx_config_1
, RX_CFG1_FILTER_ALL_MULTI
);
2251 SET_BIT(adev
->set_mask
, SET_RXCONFIG
);
2252 ndev
->flags
&= ~(IFF_PROMISC
|IFF_ALLMULTI
);
2255 /* cannot update card settings directly here, atomic context */
2256 acx_schedule_task(adev
, ACX_AFTER_IRQ_UPDATE_CARD_CFG
);
2258 acx_unlock(adev
, flags
);
2264 /***************************************************************
2265 ** acxpci_l_process_rxdesc
2267 ** Called directly and only from the IRQ handler
2271 static inline void log_rxbuffer(const acx_device_t
*adev
) {}
2274 log_rxbuffer(const acx_device_t
*adev
)
2276 register const struct rxhostdesc
*rxhostdesc
;
2278 /* no FN_ENTER here, we don't want that */
2280 rxhostdesc
= adev
->rxhostdesc_start
;
2281 if (unlikely(!rxhostdesc
)) return;
2282 for (i
= 0; i
< RX_CNT
; i
++) {
2283 if ((rxhostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
2284 && (rxhostdesc
->Status
& cpu_to_le32(DESC_STATUS_FULL
)))
2285 printk("rx: buf %d full\n", i
);
2292 acxpci_l_process_rxdesc(acx_device_t
*adev
)
2294 register rxhostdesc_t
*hostdesc
;
2299 if (unlikely(acx_debug
& L_BUFR
))
2302 /* First, have a loop to determine the first descriptor that's
2303 * full, just in case there's a mismatch between our current
2304 * rx_tail and the full descriptor we're supposed to handle. */
2305 tail
= adev
->rx_tail
;
2308 hostdesc
= &adev
->rxhostdesc_start
[tail
];
2309 /* advance tail regardless of outcome of the below test */
2310 tail
= (tail
+ 1) % RX_CNT
;
2312 if ((hostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
2313 && (hostdesc
->Status
& cpu_to_le32(DESC_STATUS_FULL
)))
2314 break; /* found it! */
2316 if (unlikely(!--count
)) /* hmm, no luck: all descs empty, bail out */
2320 /* now process descriptors, starting with the first we figured out */
2322 log(L_BUFR
, "rx: tail=%u Ctl_16=%04X Status=%08X\n",
2323 tail
, hostdesc
->Ctl_16
, hostdesc
->Status
);
2325 acx_l_process_rxbuf(adev
, hostdesc
->data
);
2327 hostdesc
->Status
= 0;
2328 /* flush all writes before adapter sees CTL_HOSTOWN change */
2330 /* Host no longer owns this, needs to be LAST */
2331 CLEAR_BIT(hostdesc
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
2333 /* ok, descriptor is handled, now check the next descriptor */
2334 hostdesc
= &adev
->rxhostdesc_start
[tail
];
2336 /* if next descriptor is empty, then bail out */
2337 if (!(hostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
2338 || !(hostdesc
->Status
& cpu_to_le32(DESC_STATUS_FULL
)))
2341 tail
= (tail
+ 1) % RX_CNT
;
2344 adev
->rx_tail
= tail
;
2349 /***********************************************************************
2350 ** acxpci_i_interrupt
2352 ** IRQ handler (atomic context, must not sleep, blah, blah)
2355 /* scan is complete. all frames now on the receive queue are valid */
2356 #define INFO_SCAN_COMPLETE 0x0001
2357 #define INFO_WEP_KEY_NOT_FOUND 0x0002
2358 /* hw has been reset as the result of a watchdog timer timeout */
2359 #define INFO_WATCH_DOG_RESET 0x0003
2360 /* failed to send out NULL frame from PS mode notification to AP */
2361 /* recommended action: try entering 802.11 PS mode again */
2362 #define INFO_PS_FAIL 0x0004
2363 /* encryption/decryption process on a packet failed */
2364 #define INFO_IV_ICV_FAILURE 0x0005
2366 /* Info mailbox format:
2369 more bytes may follow
2370 rumors say about status:
2371 0x0000 info available (set by hw)
2372 0x0001 information received (must be set by host)
2373 0x1000 info available, mailbox overflowed (messages lost) (set by hw)
2374 but in practice we've seen:
2375 0x9000 when we did not set status to 0x0001 on prev message
2376 0x1001 when we did set it
2377 0x0000 was never seen
2378 conclusion: this is really a bitfield:
2379 0x1000 is 'info available' bit
2380 'mailbox overflowed' bit is 0x8000, not 0x1000
2381 value of 0x0000 probably means that there are no messages at all
2382 P.S. I dunno how in hell hw is supposed to notice that messages are lost -
2383 it does NOT clear bit 0x0001, and this bit will probably stay forever set
2384 after we set it once. Let's hope this will be fixed in firmware someday
2388 handle_info_irq(acx_device_t
*adev
)
2391 static const char * const info_type_msg
[] = {
2394 "WEP key not found",
2395 "internal watchdog reset was done",
2396 "failed to send powersave (NULL frame) notification to AP",
2397 "encrypt/decrypt on a packet has failed",
2398 "TKIP tx keys disabled",
2399 "TKIP rx keys disabled",
2400 "TKIP rx: key ID not found",
2408 "TKIP IV value exceeds thresh"
2411 u32 info_type
, info_status
;
2413 info_type
= readl(adev
->info_area
);
2414 info_status
= (info_type
>> 16);
2415 info_type
= (u16
)info_type
;
2417 /* inform fw that we have read this info message */
2418 writel(info_type
| 0x00010000, adev
->info_area
);
2419 write_reg16(adev
, IO_ACX_INT_TRIG
, INT_TRIG_INFOACK
);
2422 log(L_CTL
, "info_type:%04X info_status:%04X\n",
2423 info_type
, info_status
);
2425 log(L_IRQ
, "got Info IRQ: status %04X type %04X: %s\n",
2426 info_status
, info_type
,
2427 info_type_msg
[(info_type
>= VEC_SIZE(info_type_msg
)) ?
2434 log_unusual_irq(u16 irqtype
) {
2436 if (!printk_ratelimit())
2441 if (irqtype
& HOST_INT_RX_DATA
) {
2444 /* HOST_INT_TX_COMPLETE */
2445 if (irqtype
& HOST_INT_TX_XFER
) {
2448 /* HOST_INT_RX_COMPLETE */
2449 if (irqtype
& HOST_INT_DTIM
) {
2452 if (irqtype
& HOST_INT_BEACON
) {
2455 if (irqtype
& HOST_INT_TIMER
) {
2456 log(L_IRQ
, " Timer");
2458 if (irqtype
& HOST_INT_KEY_NOT_FOUND
) {
2459 printk(" Key_Not_Found");
2461 if (irqtype
& HOST_INT_IV_ICV_FAILURE
) {
2462 printk(" IV_ICV_Failure");
2464 /* HOST_INT_CMD_COMPLETE */
2466 if (irqtype
& HOST_INT_OVERFLOW
) {
2467 printk(" Overflow");
2469 if (irqtype
& HOST_INT_PROCESS_ERROR
) {
2470 printk(" Process_Error");
2472 /* HOST_INT_SCAN_COMPLETE */
2473 if (irqtype
& HOST_INT_FCS_THRESHOLD
) {
2474 printk(" FCS_Threshold");
2476 if (irqtype
& HOST_INT_UNKNOWN
) {
2479 printk(" IRQ(s)\n");
2484 update_link_quality_led(acx_device_t
*adev
)
2488 qual
= acx_signal_determine_quality(adev
->wstats
.qual
.level
, adev
->wstats
.qual
.noise
);
2489 if (qual
> adev
->brange_max_quality
)
2490 qual
= adev
->brange_max_quality
;
2492 if (time_after(jiffies
, adev
->brange_time_last_state_change
+
2493 (HZ
/2 - HZ
/2 * (unsigned long)qual
/ adev
->brange_max_quality
) )) {
2494 acxpci_l_power_led(adev
, (adev
->brange_last_state
== 0));
2495 adev
->brange_last_state
^= 1; /* toggle */
2496 adev
->brange_time_last_state_change
= jiffies
;
2501 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* a la orinoco.c */
2504 acxpci_i_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
2507 unsigned long flags
;
2508 unsigned int irqcount
= MAX_IRQLOOPS_PER_JIFFY
;
2509 register u16 irqtype
;
2512 adev
= ndev2adev((struct net_device
*)dev_id
);
2514 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2516 acx_lock(adev
, flags
);
2518 unmasked
= read_reg16(adev
, IO_ACX_IRQ_STATUS_CLEAR
);
2519 if (unlikely(0xffff == unmasked
)) {
2520 /* 0xffff value hints at missing hardware,
2521 * so don't do anything.
2522 * Not very clean, but other drivers do the same... */
2523 log(L_IRQ
, "IRQ type:FFFF - device removed? IRQ_NONE\n");
2527 /* We will check only "interesting" IRQ types */
2528 irqtype
= unmasked
& ~adev
->irq_mask
;
2530 /* We are on a shared IRQ line and it wasn't our IRQ */
2531 log(L_IRQ
, "IRQ type:%04X, mask:%04X - all are masked, IRQ_NONE\n",
2532 unmasked
, adev
->irq_mask
);
2536 /* Done here because IRQ_NONEs taking three lines of log
2537 ** drive me crazy */
2540 #define IRQ_ITERATE 1
2542 if (jiffies
!= adev
->irq_last_jiffies
) {
2543 adev
->irq_loops_this_jiffy
= 0;
2544 adev
->irq_last_jiffies
= jiffies
;
2547 /* safety condition; we'll normally abort loop below
2548 * in case no IRQ type occurred */
2549 while (likely(--irqcount
)) {
2551 /* ACK all IRQs ASAP */
2552 write_reg16(adev
, IO_ACX_IRQ_ACK
, 0xffff);
2554 log(L_IRQ
, "IRQ type:%04X, mask:%04X, type & ~mask:%04X\n",
2555 unmasked
, adev
->irq_mask
, irqtype
);
2557 /* Handle most important IRQ types first */
2558 if (irqtype
& HOST_INT_RX_COMPLETE
) {
2559 log(L_IRQ
, "got Rx_Complete IRQ\n");
2560 acxpci_l_process_rxdesc(adev
);
2562 if (irqtype
& HOST_INT_TX_COMPLETE
) {
2563 log(L_IRQ
, "got Tx_Complete IRQ\n");
2564 /* don't clean up on each Tx complete, wait a bit
2565 * unless we're going towards full, in which case
2566 * we do it immediately, too (otherwise we might lockup
2567 * with a full Tx buffer if we go into
2568 * acxpci_l_clean_txdesc() at a time when we won't wakeup
2569 * the net queue in there for some reason...) */
2570 if (adev
->tx_free
<= TX_START_CLEAN
) {
2571 #if TX_CLEANUP_IN_SOFTIRQ
2572 acx_schedule_task(adev
, ACX_AFTER_IRQ_TX_CLEANUP
);
2574 acxpci_l_clean_txdesc(adev
);
2579 /* Less frequent ones */
2581 | HOST_INT_CMD_COMPLETE
2583 | HOST_INT_SCAN_COMPLETE
2585 if (irqtype
& HOST_INT_CMD_COMPLETE
) {
2586 log(L_IRQ
, "got Command_Complete IRQ\n");
2587 /* save the state for the running issue_cmd() */
2588 SET_BIT(adev
->irq_status
, HOST_INT_CMD_COMPLETE
);
2590 if (irqtype
& HOST_INT_INFO
) {
2591 handle_info_irq(adev
);
2593 if (irqtype
& HOST_INT_SCAN_COMPLETE
) {
2594 log(L_IRQ
, "got Scan_Complete IRQ\n");
2595 /* need to do that in process context */
2596 acx_schedule_task(adev
, ACX_AFTER_IRQ_COMPLETE_SCAN
);
2597 /* remember that fw is not scanning anymore */
2598 SET_BIT(adev
->irq_status
, HOST_INT_SCAN_COMPLETE
);
2602 /* These we just log, but either they happen rarely
2603 * or we keep them masked out */
2606 /* | HOST_INT_TX_COMPLETE */
2608 /* | HOST_INT_RX_COMPLETE */
2612 | HOST_INT_KEY_NOT_FOUND
2613 | HOST_INT_IV_ICV_FAILURE
2614 /* | HOST_INT_CMD_COMPLETE */
2615 /* | HOST_INT_INFO */
2617 | HOST_INT_PROCESS_ERROR
2618 /* | HOST_INT_SCAN_COMPLETE */
2619 | HOST_INT_FCS_THRESHOLD
2622 log_unusual_irq(irqtype
);
2626 unmasked
= read_reg16(adev
, IO_ACX_IRQ_STATUS_CLEAR
);
2627 irqtype
= unmasked
& ~adev
->irq_mask
;
2628 /* Bail out if no new IRQ bits or if all are masked out */
2632 if (unlikely(++adev
->irq_loops_this_jiffy
> MAX_IRQLOOPS_PER_JIFFY
)) {
2633 printk(KERN_ERR
"acx: too many interrupts per jiffy!\n");
2634 /* Looks like card floods us with IRQs! Try to stop that */
2635 write_reg16(adev
, IO_ACX_IRQ_MASK
, 0xffff);
2636 /* This will short-circuit all future attempts to handle IRQ.
2637 * We cant do much more... */
2643 /* Routine to perform blink with range */
2644 if (unlikely(adev
->led_power
== 2))
2645 update_link_quality_led(adev
);
2648 /* write_flush(adev); - not needed, last op was read anyway */
2649 acx_unlock(adev
, flags
);
2654 acx_unlock(adev
, flags
);
2659 /***********************************************************************
2660 ** acxpci_l_power_led
2663 acxpci_l_power_led(acx_device_t
*adev
, int enable
)
2665 u16 gpio_pled
= IS_ACX111(adev
) ? 0x0040 : 0x0800;
2667 /* A hack. Not moving message rate limiting to adev->xxx
2668 * (it's only a debug message after all) */
2669 static int rate_limit
= 0;
2671 if (rate_limit
++ < 3)
2672 log(L_IOCTL
, "Please report in case toggling the power "
2673 "LED doesn't work for your card!\n");
2675 write_reg16(adev
, IO_ACX_GPIO_OUT
,
2676 read_reg16(adev
, IO_ACX_GPIO_OUT
) & ~gpio_pled
);
2678 write_reg16(adev
, IO_ACX_GPIO_OUT
,
2679 read_reg16(adev
, IO_ACX_GPIO_OUT
) | gpio_pled
);
2683 /***********************************************************************
2687 /***********************************************************************
2690 acx111pci_ioctl_info(
2691 struct net_device
*ndev
,
2692 struct iw_request_info
*info
,
2693 struct iw_param
*vwrq
,
2697 acx_device_t
*adev
= ndev2adev(ndev
);
2700 rxhostdesc_t
*rxhostdesc
;
2701 txhostdesc_t
*txhostdesc
;
2702 struct acx111_ie_memoryconfig memconf
;
2703 struct acx111_ie_queueconfig queueconf
;
2704 unsigned long flags
;
2709 char ratefallback
[0x5];
2711 if ( !(acx_debug
& (L_IOCTL
|L_DEBUG
)) )
2713 /* using printk() since we checked debug flag already */
2717 if (!IS_ACX111(adev
)) {
2718 printk("acx111-specific function called "
2719 "with non-acx111 chip, aborting\n");
2723 /* get Acx111 Memory Configuration */
2724 memset(&memconf
, 0, sizeof(memconf
));
2725 /* BTW, fails with 12 (Write only) error code.
2726 ** Retained for easy testing of issue_cmd error handling :) */
2727 acx_s_interrogate(adev
, &memconf
, ACX1xx_IE_QUEUE_CONFIG
);
2729 /* get Acx111 Queue Configuration */
2730 memset(&queueconf
, 0, sizeof(queueconf
));
2731 acx_s_interrogate(adev
, &queueconf
, ACX1xx_IE_MEMORY_CONFIG_OPTIONS
);
2733 /* get Acx111 Memory Map */
2734 memset(memmap
, 0, sizeof(memmap
));
2735 acx_s_interrogate(adev
, &memmap
, ACX1xx_IE_MEMORY_MAP
);
2737 /* get Acx111 Rx Config */
2738 memset(rxconfig
, 0, sizeof(rxconfig
));
2739 acx_s_interrogate(adev
, &rxconfig
, ACX1xx_IE_RXCONFIG
);
2741 /* get Acx111 fcs error count */
2742 memset(fcserror
, 0, sizeof(fcserror
));
2743 acx_s_interrogate(adev
, &fcserror
, ACX1xx_IE_FCS_ERROR_COUNT
);
2745 /* get Acx111 rate fallback */
2746 memset(ratefallback
, 0, sizeof(ratefallback
));
2747 acx_s_interrogate(adev
, &ratefallback
, ACX1xx_IE_RATE_FALLBACK
);
2749 /* force occurrence of a beacon interrupt */
2750 /* TODO: comment why is this necessary */
2751 write_reg16(adev
, IO_ACX_HINT_TRIG
, HOST_INT_BEACON
);
2753 /* dump Acx111 Mem Configuration */
2754 printk("dump mem config:\n"
2755 "data read: %d, struct size: %d\n"
2756 "Number of stations: %1X\n"
2757 "Memory block size: %1X\n"
2758 "tx/rx memory block allocation: %1X\n"
2759 "count rx: %X / tx: %X queues\n"
2761 "fragmentation %1X\n"
2762 "Rx Queue 1 Count Descriptors: %X\n"
2763 "Rx Queue 1 Host Memory Start: %X\n"
2764 "Tx Queue 1 Count Descriptors: %X\n"
2765 "Tx Queue 1 Attributes: %X\n",
2766 memconf
.len
, (int) sizeof(memconf
),
2767 memconf
.no_of_stations
,
2768 memconf
.memory_block_size
,
2769 memconf
.tx_rx_memory_block_allocation
,
2770 memconf
.count_rx_queues
, memconf
.count_tx_queues
,
2772 memconf
.fragmentation
,
2773 memconf
.rx_queue1_count_descs
,
2774 acx2cpu(memconf
.rx_queue1_host_rx_start
),
2775 memconf
.tx_queue1_count_descs
,
2776 memconf
.tx_queue1_attributes
);
2778 /* dump Acx111 Queue Configuration */
2779 printk("dump queue head:\n"
2780 "data read: %d, struct size: %d\n"
2781 "tx_memory_block_address (from card): %X\n"
2782 "rx_memory_block_address (from card): %X\n"
2783 "rx1_queue address (from card): %X\n"
2784 "tx1_queue address (from card): %X\n"
2785 "tx1_queue attributes (from card): %X\n",
2786 queueconf
.len
, (int) sizeof(queueconf
),
2787 queueconf
.tx_memory_block_address
,
2788 queueconf
.rx_memory_block_address
,
2789 queueconf
.rx1_queue_address
,
2790 queueconf
.tx1_queue_address
,
2791 queueconf
.tx1_attributes
);
2793 /* dump Acx111 Mem Map */
2794 printk("dump mem map:\n"
2795 "data read: %d, struct size: %d\n"
2798 "WEP default key start: %X\n"
2799 "WEP default key end: %X\n"
2800 "STA table start: %X\n"
2801 "STA table end: %X\n"
2802 "Packet template start: %X\n"
2803 "Packet template end: %X\n"
2804 "Queue memory start: %X\n"
2805 "Queue memory end: %X\n"
2806 "Packet memory pool start: %X\n"
2807 "Packet memory pool end: %X\n"
2810 *((u16
*)&memmap
[0x02]), (int) sizeof(memmap
),
2811 *((u32
*)&memmap
[0x04]),
2812 *((u32
*)&memmap
[0x08]),
2813 *((u32
*)&memmap
[0x0C]),
2814 *((u32
*)&memmap
[0x10]),
2815 *((u32
*)&memmap
[0x14]),
2816 *((u32
*)&memmap
[0x18]),
2817 *((u32
*)&memmap
[0x1C]),
2818 *((u32
*)&memmap
[0x20]),
2819 *((u32
*)&memmap
[0x24]),
2820 *((u32
*)&memmap
[0x28]),
2821 *((u32
*)&memmap
[0x2C]),
2822 *((u32
*)&memmap
[0x30]),
2826 /* dump Acx111 Rx Config */
2827 printk("dump rx config:\n"
2828 "data read: %d, struct size: %d\n"
2830 "rx filter config: %X\n",
2831 *((u16
*)&rxconfig
[0x02]), (int) sizeof(rxconfig
),
2832 *((u16
*)&rxconfig
[0x04]),
2833 *((u16
*)&rxconfig
[0x06]));
2835 /* dump Acx111 fcs error */
2836 printk("dump fcserror:\n"
2837 "data read: %d, struct size: %d\n"
2839 *((u16
*)&fcserror
[0x02]), (int) sizeof(fcserror
),
2840 *((u32
*)&fcserror
[0x04]));
2842 /* dump Acx111 rate fallback */
2843 printk("dump rate fallback:\n"
2844 "data read: %d, struct size: %d\n"
2845 "ratefallback: %X\n",
2846 *((u16
*)&ratefallback
[0x02]), (int) sizeof(ratefallback
),
2847 *((u8
*)&ratefallback
[0x04]));
2849 /* protect against IRQ */
2850 acx_lock(adev
, flags
);
2852 /* dump acx111 internal rx descriptor ring buffer */
2853 rxdesc
= adev
->rxdesc_start
;
2855 /* loop over complete receive pool */
2856 if (rxdesc
) for (i
= 0; i
< RX_CNT
; i
++) {
2857 printk("\ndump internal rxdesc %d:\n"
2860 "acx mem pointer (dynamic) 0x%X\n"
2861 "CTL (dynamic) 0x%X\n"
2862 "Rate (dynamic) 0x%X\n"
2863 "RxStatus (dynamic) 0x%X\n"
2864 "Mod/Pre (dynamic) 0x%X\n",
2867 acx2cpu(rxdesc
->pNextDesc
),
2868 acx2cpu(rxdesc
->ACXMemPtr
),
2876 /* dump host rx descriptor ring buffer */
2878 rxhostdesc
= adev
->rxhostdesc_start
;
2880 /* loop over complete receive pool */
2881 if (rxhostdesc
) for (i
= 0; i
< RX_CNT
; i
++) {
2882 printk("\ndump host rxdesc %d:\n"
2884 "buffer mem pos 0x%X\n"
2885 "buffer mem offset 0x%X\n"
2892 acx2cpu(rxhostdesc
->data_phy
),
2893 rxhostdesc
->data_offset
,
2894 le16_to_cpu(rxhostdesc
->Ctl_16
),
2895 le16_to_cpu(rxhostdesc
->length
),
2896 acx2cpu(rxhostdesc
->desc_phy_next
),
2897 rxhostdesc
->Status
);
2901 /* dump acx111 internal tx descriptor ring buffer */
2902 txdesc
= adev
->txdesc_start
;
2904 /* loop over complete transmit pool */
2905 if (txdesc
) for (i
= 0; i
< TX_CNT
; i
++) {
2906 printk("\ndump internal txdesc %d:\n"
2910 "acx mem pointer (dynamic) 0x%X\n"
2911 "host mem pointer (dynamic) 0x%X\n"
2912 "length (dynamic) 0x%X\n"
2913 "CTL (dynamic) 0x%X\n"
2914 "CTL2 (dynamic) 0x%X\n"
2915 "Status (dynamic) 0x%X\n"
2916 "Rate (dynamic) 0x%X\n",
2918 (int) sizeof(struct txdesc
),
2920 acx2cpu(txdesc
->pNextDesc
),
2921 acx2cpu(txdesc
->AcxMemPtr
),
2922 acx2cpu(txdesc
->HostMemPtr
),
2923 le16_to_cpu(txdesc
->total_length
),
2925 txdesc
->Ctl2_8
, txdesc
->error
,
2927 txdesc
= advance_txdesc(adev
, txdesc
, 1);
2930 /* dump host tx descriptor ring buffer */
2932 txhostdesc
= adev
->txhostdesc_start
;
2934 /* loop over complete host send pool */
2935 if (txhostdesc
) for (i
= 0; i
< TX_CNT
* 2; i
++) {
2936 printk("\ndump host txdesc %d:\n"
2938 "buffer mem pos 0x%X\n"
2939 "buffer mem offset 0x%X\n"
2946 acx2cpu(txhostdesc
->data_phy
),
2947 txhostdesc
->data_offset
,
2948 le16_to_cpu(txhostdesc
->Ctl_16
),
2949 le16_to_cpu(txhostdesc
->length
),
2950 acx2cpu(txhostdesc
->desc_phy_next
),
2951 le32_to_cpu(txhostdesc
->Status
));
2955 /* write_reg16(adev, 0xb4, 0x4); */
2957 acx_unlock(adev
, flags
);
2960 acx_sem_unlock(adev
);
2961 #endif /* ACX_DEBUG */
2966 /***********************************************************************
2969 acx100pci_ioctl_set_phy_amp_bias(
2970 struct net_device
*ndev
,
2971 struct iw_request_info
*info
,
2972 struct iw_param
*vwrq
,
2975 acx_device_t
*adev
= ndev2adev(ndev
);
2976 unsigned long flags
;
2979 if (!IS_ACX100(adev
)) {
2981 * Removing this check *might* damage
2982 * hardware, since we're tweaking GPIOs here after all!!!
2983 * You've been warned...
2985 printk("acx: sorry, setting bias level for non-acx100 "
2986 "is not supported yet\n");
2991 printk("acx: invalid bias parameter, range is 0-7\n");
2997 /* Need to lock accesses to [IO_ACX_GPIO_OUT]:
2998 * IRQ handler uses it to update LED */
2999 acx_lock(adev
, flags
);
3000 gpio_old
= read_reg16(adev
, IO_ACX_GPIO_OUT
);
3001 write_reg16(adev
, IO_ACX_GPIO_OUT
, (gpio_old
& 0xf8ff) | ((u16
)*extra
<< 8));
3002 acx_unlock(adev
, flags
);
3004 log(L_DEBUG
, "gpio_old: 0x%04X\n", gpio_old
);
3005 printk("%s: PHY power amplifier bias: old:%d, new:%d\n",
3007 (gpio_old
& 0x0700) >> 8, (unsigned char)*extra
);
3009 acx_sem_unlock(adev
);
3015 /***************************************************************
3016 ** acxpci_l_alloc_tx
3017 ** Actually returns a txdesc_t* ptr
3019 ** FIXME: in case of fragments, should allocate multiple descrs
3020 ** after figuring out how many we need and whether we still have
3021 ** sufficiently many.
3024 acxpci_l_alloc_tx(acx_device_t
*adev
)
3026 struct txdesc
*txdesc
;
3032 if (unlikely(!adev
->tx_free
)) {
3033 printk("acx: BUG: no free txdesc left\n");
3038 head
= adev
->tx_head
;
3039 txdesc
= get_txdesc(adev
, head
);
3040 ctl8
= txdesc
->Ctl_8
;
3042 /* 2005-10-11: there were several bug reports on this happening
3043 ** but now cause seems to be understood & fixed */
3044 if (unlikely(DESC_CTL_HOSTOWN
!= (ctl8
& DESC_CTL_ACXDONE_HOSTOWN
))) {
3045 /* whoops, descr at current index is not free, so probably
3046 * ring buffer already full */
3047 printk("acx: BUG: tx_head:%d Ctl8:0x%02X - failed to find "
3048 "free txdesc\n", head
, ctl8
);
3053 /* Needed in case txdesc won't be eventually submitted for tx */
3054 txdesc
->Ctl_8
= DESC_CTL_ACXDONE_HOSTOWN
;
3057 log(L_BUFT
, "tx: got desc %u, %u remain\n",
3058 head
, adev
->tx_free
);
3059 /* Keep a few free descs between head and tail of tx ring.
3060 ** It is not absolutely needed, just feels safer */
3061 if (adev
->tx_free
< TX_STOP_QUEUE
) {
3062 log(L_BUF
, "stop queue (%u tx desc left)\n",
3064 acx_stop_queue(adev
->ndev
, NULL
);
3067 /* returning current descriptor, so advance to next free one */
3068 adev
->tx_head
= (head
+ 1) % TX_CNT
;
3072 return (tx_t
*)txdesc
;
3076 /***********************************************************************
3079 acxpci_l_get_txbuf(acx_device_t
*adev
, tx_t
* tx_opaque
)
3081 return get_txhostdesc(adev
, (txdesc_t
*)tx_opaque
)->data
;
3085 /***********************************************************************
3088 ** Can be called from IRQ (rx -> (AP bridging or mgmt response) -> tx).
3089 ** Can be called from acx_i_start_xmit (data frames from net core).
3091 ** FIXME: in case of fragments, should loop over the number of
3092 ** pre-allocated tx descrs, properly setting up transfer data and
3093 ** CTL_xxx flags according to fragment number.
3096 acxpci_l_tx_data(acx_device_t
*adev
, tx_t
* tx_opaque
, int len
)
3098 txdesc_t
*txdesc
= (txdesc_t
*)tx_opaque
;
3099 txhostdesc_t
*hostdesc1
, *hostdesc2
;
3106 /* fw doesn't tx such packets anyhow */
3107 if (unlikely(len
< WLAN_HDR_A3_LEN
))
3110 hostdesc1
= get_txhostdesc(adev
, txdesc
);
3111 /* modify flag status in separate variable to be able to write it back
3112 * in one big swoop later (also in order to have less device memory
3114 Ctl_8
= txdesc
->Ctl_8
;
3115 Ctl2_8
= 0; /* really need to init it to 0, not txdesc->Ctl2_8, it seems */
3117 hostdesc2
= hostdesc1
+ 1;
3119 /* DON'T simply set Ctl field to 0 here globally,
3120 * it needs to maintain a consistent flag status (those are state flags!!),
3121 * otherwise it may lead to severe disruption. Only set or reset particular
3122 * flags at the exact moment this is needed... */
3124 /* let chip do RTS/CTS handshaking before sending
3125 * in case packet size exceeds threshold */
3126 if (len
> adev
->rts_threshold
)
3127 SET_BIT(Ctl2_8
, DESC_CTL2_RTS
);
3129 CLEAR_BIT(Ctl2_8
, DESC_CTL2_RTS
);
3131 switch (adev
->mode
) {
3132 case ACX_MODE_0_ADHOC
:
3134 clt
= acx_l_sta_list_get(adev
, ((wlan_hdr_t
*)hostdesc1
->data
)->a1
);
3136 case ACX_MODE_2_STA
:
3137 clt
= adev
->ap_client
;
3140 /* testing was done on acx111: */
3141 case ACX_MODE_MONITOR
:
3143 /* sends CTS to self before packet */
3144 + DESC_CTL2_SEQ
/* don't increase sequence field */
3145 /* not working (looks like good fcs is still added) */
3146 + DESC_CTL2_FCS
/* don't add the FCS */
3148 + DESC_CTL2_MORE_FRAG
3150 + DESC_CTL2_RETRY
/* don't increase retry field */
3152 + DESC_CTL2_POWER
/* don't increase power mgmt. field */
3154 + DESC_CTL2_WEP
/* encrypt this frame */
3156 + DESC_CTL2_DUR
/* don't increase duration field */
3160 default: /* ACX_MODE_OFF, ACX_MODE_MONITOR */
3165 rate_cur
= clt
? clt
->rate_cur
: adev
->rate_bcast
;
3166 if (unlikely(!rate_cur
)) {
3167 printk("acx: driver bug! bad ratemask\n");
3171 /* used in tx cleanup routine for auto rate and accounting: */
3172 put_txcr(adev
, txdesc
, clt
, rate_cur
);
3174 txdesc
->total_length
= cpu_to_le16(len
);
3175 hostdesc2
->length
= cpu_to_le16(len
- WLAN_HDR_A3_LEN
);
3176 if (IS_ACX111(adev
)) {
3177 /* note that if !txdesc->do_auto, txrate->cur
3178 ** has only one nonzero bit */
3179 txdesc
->u
.r2
.rate111
= cpu_to_le16(
3181 /* WARNING: I was never able to make it work with prism54 AP.
3182 ** It was falling down to 1Mbit where shortpre is not applicable,
3183 ** and not working at all at "5,11 basic rates only" setting.
3184 ** I even didn't see tx packets in radio packet capture.
3185 ** Disabled for now --vda */
3186 /*| ((clt->shortpre && clt->cur!=RATE111_1) ? RATE111_SHORTPRE : 0) */
3188 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3189 /* should add this to rate111 above as necessary */
3190 | (clt
->pbcc511
? RATE111_PBCC511
: 0)
3192 hostdesc1
->length
= cpu_to_le16(len
);
3193 } else { /* ACX100 */
3194 u8 rate_100
= clt
? clt
->rate_100
: adev
->rate_bcast100
;
3195 txdesc
->u
.r1
.rate
= rate_100
;
3196 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3198 if (n
== RATE100_5
|| n
== RATE100_11
)
3199 n
|= RATE100_PBCC511
;
3202 if (clt
->shortpre
&& (clt
->cur
!= RATE111_1
))
3203 SET_BIT(Ctl_8
, DESC_CTL_SHORT_PREAMBLE
); /* set Short Preamble */
3205 /* set autodma and reclaim and 1st mpdu */
3206 SET_BIT(Ctl_8
, DESC_CTL_AUTODMA
| DESC_CTL_RECLAIM
| DESC_CTL_FIRSTFRAG
);
3207 #if ACX_FRAGMENTATION
3208 /* SET_BIT(Ctl2_8, DESC_CTL2_MORE_FRAG); cannot set it unconditionally, needs to be set for all non-last fragments */
3210 hostdesc1
->length
= cpu_to_le16(WLAN_HDR_A3_LEN
);
3212 /* don't need to clean ack/rts statistics here, already
3213 * done on descr cleanup */
3215 /* clears HOSTOWN and ACXDONE bits, thus telling that the descriptors
3216 * are now owned by the acx100; do this as LAST operation */
3217 CLEAR_BIT(Ctl_8
, DESC_CTL_ACXDONE_HOSTOWN
);
3218 /* flush writes before we release hostdesc to the adapter here */
3220 CLEAR_BIT(hostdesc1
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
3221 CLEAR_BIT(hostdesc2
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
3223 /* write back modified flags */
3224 txdesc
->Ctl2_8
= Ctl2_8
;
3225 txdesc
->Ctl_8
= Ctl_8
;
3226 /* unused: txdesc->tx_time = cpu_to_le32(jiffies); */
3228 /* flush writes before we tell the adapter that it's its turn now */
3230 write_reg16(adev
, IO_ACX_INT_TRIG
, INT_TRIG_TXPRC
);
3233 /* log the packet content AFTER sending it,
3234 * in order to not delay sending any further than absolutely needed
3235 * Do separate logs for acx100/111 to have human-readable rates */
3236 if (unlikely(acx_debug
& (L_XFER
|L_DATA
))) {
3237 u16 fc
= ((wlan_hdr_t
*)hostdesc1
->data
)->fc
;
3238 if (IS_ACX111(adev
))
3239 printk("tx: pkt (%s): len %d "
3240 "rate %04X%s status %u\n",
3241 acx_get_packet_type_string(le16_to_cpu(fc
)), len
,
3242 le16_to_cpu(txdesc
->u
.r2
.rate111
),
3243 (le16_to_cpu(txdesc
->u
.r2
.rate111
) & RATE111_SHORTPRE
) ? "(SPr)" : "",
3246 printk("tx: pkt (%s): len %d rate %03u%s status %u\n",
3247 acx_get_packet_type_string(fc
), len
,
3249 (Ctl_8
& DESC_CTL_SHORT_PREAMBLE
) ? "(SPr)" : "",
3252 if (acx_debug
& L_DATA
) {
3253 printk("tx: 802.11 [%d]: ", len
);
3254 acx_dump_bytes(hostdesc1
->data
, len
);
3262 /***********************************************************************
3263 ** acxpci_l_clean_txdesc
3265 ** This function resets the txdescs' status when the ACX100
3266 ** signals the TX done IRQ (txdescs have been processed), starting with
3267 ** the pool index of the descriptor which we would use next,
3268 ** in order to make sure that we can be as fast as possible
3269 ** in filling new txdescs.
3270 ** Everytime we get called we know where the next packet to be cleaned is.
3274 static inline void log_txbuffer(const acx_device_t
*adev
) {}
3277 log_txbuffer(acx_device_t
*adev
)
3282 /* no FN_ENTER here, we don't want that */
3283 /* no locks here, since it's entirely non-critical code */
3284 txdesc
= adev
->txdesc_start
;
3285 if (unlikely(!txdesc
)) return;
3286 printk("tx: desc->Ctl8's:");
3287 for (i
= 0; i
< TX_CNT
; i
++) {
3288 printk(" %02X", txdesc
->Ctl_8
);
3289 txdesc
= advance_txdesc(adev
, txdesc
, 1);
3297 handle_tx_error(acx_device_t
*adev
, u8 error
, unsigned int finger
)
3299 const char *err
= "unknown error";
3301 /* hmm, should we handle this as a mask
3302 * of *several* bits?
3303 * For now I think only caring about
3304 * individual bits is ok... */
3307 err
= "no Tx due to error in other fragment";
3308 adev
->wstats
.discard
.fragment
++;
3312 adev
->stats
.tx_aborted_errors
++;
3315 err
= "Tx desc wrong parameters";
3316 adev
->wstats
.discard
.misc
++;
3319 err
= "WEP key not found";
3320 adev
->wstats
.discard
.misc
++;
3323 err
= "MSDU lifetime timeout? - try changing "
3324 "'iwconfig retry lifetime XXX'";
3325 adev
->wstats
.discard
.misc
++;
3328 err
= "excessive Tx retries due to either distance "
3329 "too high or unable to Tx or Tx frame error - "
3330 "try changing 'iwconfig txpower XXX' or "
3331 "'sens'itivity or 'retry'";
3332 adev
->wstats
.discard
.retries
++;
3333 /* Tx error 0x20 also seems to occur on
3334 * overheating, so I'm not sure whether we
3335 * actually want to do aggressive radio recalibration,
3336 * since people maybe won't notice then that their hardware
3337 * is slowly getting cooked...
3338 * Or is it still a safe long distance from utter
3339 * radio non-functionality despite many radio recalibs
3340 * to final destructive overheating of the hardware?
3341 * In this case we really should do recalib here...
3342 * I guess the only way to find out is to do a
3343 * potentially fatal self-experiment :-\
3344 * Or maybe only recalib in case we're using Tx
3345 * rate auto (on errors switching to lower speed
3346 * --> less heat?) or 802.11 power save mode?
3348 * ok, just do it. */
3349 if (++adev
->retry_errors_msg_ratelimit
% 4 == 0) {
3350 if (adev
->retry_errors_msg_ratelimit
<= 20) {
3351 printk("%s: several excessive Tx "
3352 "retry errors occurred, attempting "
3353 "to recalibrate radio. Radio "
3354 "drift might be caused by increasing "
3355 "card temperature, please check the card "
3356 "before it's too late!\n",
3358 if (adev
->retry_errors_msg_ratelimit
== 20)
3359 printk("disabling above message\n");
3362 acx_schedule_task(adev
, ACX_AFTER_IRQ_CMD_RADIO_RECALIB
);
3366 err
= "Tx buffer overflow";
3367 adev
->stats
.tx_fifo_errors
++;
3371 adev
->wstats
.discard
.misc
++;
3374 adev
->stats
.tx_errors
++;
3375 if (adev
->stats
.tx_errors
<= 20)
3376 printk("%s: tx error 0x%02X, buf %02u! (%s)\n",
3377 adev
->ndev
->name
, error
, finger
, err
);
3379 printk("%s: tx error 0x%02X, buf %02u!\n",
3380 adev
->ndev
->name
, error
, finger
);
3385 acxpci_l_clean_txdesc(acx_device_t
*adev
)
3391 u8 error
, ack_failures
, rts_failures
, rts_ok
, r100
;
3395 if (unlikely(acx_debug
& L_DEBUG
))
3398 log(L_BUFT
, "tx: cleaning up bufs from %u\n", adev
->tx_tail
);
3400 /* We know first descr which is not free yet. We advance it as far
3401 ** as we see correct bits set in following descs (if next desc
3402 ** is NOT free, we shouldn't advance at all). We know that in
3403 ** front of tx_tail may be "holes" with isolated free descs.
3404 ** We will catch up when all intermediate descs will be freed also */
3406 finger
= adev
->tx_tail
;
3408 while (likely(finger
!= adev
->tx_head
)) {
3409 txdesc
= get_txdesc(adev
, finger
);
3411 /* If we allocated txdesc on tx path but then decided
3412 ** to NOT use it, then it will be left as a free "bubble"
3413 ** in the "allocated for tx" part of the ring.
3414 ** We may meet it on the next ring pass here. */
3416 /* stop if not marked as "tx finished" and "host owned" */
3417 if ((txdesc
->Ctl_8
& DESC_CTL_ACXDONE_HOSTOWN
)
3418 != DESC_CTL_ACXDONE_HOSTOWN
) {
3419 if (unlikely(!num_cleaned
)) { /* maybe remove completely */
3420 log(L_BUFT
, "clean_txdesc: tail isn't free. "
3421 "tail:%d head:%d\n",
3422 adev
->tx_tail
, adev
->tx_head
);
3427 /* remember desc values... */
3428 error
= txdesc
->error
;
3429 ack_failures
= txdesc
->ack_failures
;
3430 rts_failures
= txdesc
->rts_failures
;
3431 rts_ok
= txdesc
->rts_ok
;
3432 r100
= txdesc
->u
.r1
.rate
;
3433 r111
= le16_to_cpu(txdesc
->u
.r2
.rate111
);
3435 /* need to check for certain error conditions before we
3436 * clean the descriptor: we still need valid descr data here */
3437 if (unlikely(0x30 & error
)) {
3438 /* only send IWEVTXDROP in case of retry or lifetime exceeded;
3439 * all other errors mean we screwed up locally */
3440 union iwreq_data wrqu
;
3442 txhostdesc_t
*hostdesc
;
3444 hostdesc
= get_txhostdesc(adev
, txdesc
);
3445 hdr
= (wlan_hdr_t
*)hostdesc
->data
;
3446 MAC_COPY(wrqu
.addr
.sa_data
, hdr
->a1
);
3447 wireless_send_event(adev
->ndev
, IWEVTXDROP
, &wrqu
, NULL
);
3450 /* ...and free the desc */
3452 txdesc
->ack_failures
= 0;
3453 txdesc
->rts_failures
= 0;
3455 /* signal host owning it LAST, since ACX already knows that this
3456 ** descriptor is finished since it set Ctl_8 accordingly. */
3457 txdesc
->Ctl_8
= DESC_CTL_HOSTOWN
;
3462 if ((adev
->tx_free
>= TX_START_QUEUE
)
3463 && (adev
->status
== ACX_STATUS_4_ASSOCIATED
)
3464 && (acx_queue_stopped(adev
->ndev
))
3466 log(L_BUF
, "tx: wake queue (avail. Tx desc %u)\n",
3468 acx_wake_queue(adev
->ndev
, NULL
);
3471 /* do error checking, rate handling and logging
3472 * AFTER having done the work, it's faster */
3474 /* do rate handling */
3475 if (adev
->rate_auto
) {
3476 struct client
*clt
= get_txc(adev
, txdesc
);
3478 u16 cur
= get_txr(adev
, txdesc
);
3479 if (clt
->rate_cur
== cur
) {
3480 acx_l_handle_txrate_auto(adev
, clt
,
3481 cur
, /* intended rate */
3482 r100
, r111
, /* actually used rate */
3483 (error
& 0x30), /* was there an error? */
3484 TX_CNT
+ TX_CLEAN_BACKLOG
- adev
->tx_free
);
3489 if (unlikely(error
))
3490 handle_tx_error(adev
, error
, finger
);
3492 if (IS_ACX111(adev
))
3493 log(L_BUFT
, "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u r111=%04X\n",
3494 finger
, ack_failures
, rts_failures
, rts_ok
, r111
);
3496 log(L_BUFT
, "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u rate=%u\n",
3497 finger
, ack_failures
, rts_failures
, rts_ok
, r100
);
3499 /* update pointer for descr to be cleaned next */
3500 finger
= (finger
+ 1) % TX_CNT
;
3503 /* remember last position */
3504 adev
->tx_tail
= finger
;
3506 FN_EXIT1(num_cleaned
);
3510 /* clean *all* Tx descriptors, and regardless of their previous state.
3511 * Used for brute-force reset handling. */
3513 acxpci_l_clean_txdesc_emergency(acx_device_t
*adev
)
3520 for (i
= 0; i
< TX_CNT
; i
++) {
3521 txdesc
= get_txdesc(adev
, i
);
3524 txdesc
->ack_failures
= 0;
3525 txdesc
->rts_failures
= 0;
3528 txdesc
->Ctl_8
= DESC_CTL_HOSTOWN
;
3531 adev
->tx_free
= TX_CNT
;
3537 /***********************************************************************
3538 ** acxpci_s_create_tx_host_desc_queue
3542 allocate(acx_device_t
*adev
, size_t size
, dma_addr_t
*phy
, const char *msg
)
3546 ptr
= dma_alloc_coherent(adev
->pdev
? &adev
->pdev
->dev
: NULL
,
3547 size
, phy
, GFP_KERNEL
);
3550 log(L_DEBUG
, "%s sz=%d adr=0x%p phy=0x%08llx\n",
3551 msg
, (int)size
, ptr
, (unsigned long long)*phy
);
3552 memset(ptr
, 0, size
);
3555 printk(KERN_ERR
"acx: %s allocation FAILED (%d bytes)\n",
3562 acxpci_s_create_tx_host_desc_queue(acx_device_t
*adev
)
3564 txhostdesc_t
*hostdesc
;
3566 dma_addr_t hostdesc_phy
;
3567 dma_addr_t txbuf_phy
;
3572 /* allocate TX buffer */
3573 adev
->txbuf_area_size
= TX_CNT
* WLAN_A4FR_MAXLEN_WEP_FCS
;
3574 adev
->txbuf_start
= allocate(adev
, adev
->txbuf_area_size
,
3575 &adev
->txbuf_startphy
, "txbuf_start");
3576 if (!adev
->txbuf_start
)
3579 /* allocate the TX host descriptor queue pool */
3580 adev
->txhostdesc_area_size
= TX_CNT
* 2*sizeof(*hostdesc
);
3581 adev
->txhostdesc_start
= allocate(adev
, adev
->txhostdesc_area_size
,
3582 &adev
->txhostdesc_startphy
, "txhostdesc_start");
3583 if (!adev
->txhostdesc_start
)
3585 /* check for proper alignment of TX host descriptor pool */
3586 if ((long) adev
->txhostdesc_start
& 3) {
3587 printk("acx: driver bug: dma alloc returns unaligned address\n");
3591 hostdesc
= adev
->txhostdesc_start
;
3592 hostdesc_phy
= adev
->txhostdesc_startphy
;
3593 txbuf
= adev
->txbuf_start
;
3594 txbuf_phy
= adev
->txbuf_startphy
;
3597 /* Each tx buffer is accessed by hardware via
3598 ** txdesc -> txhostdesc(s) -> txbuffer(s).
3599 ** We use only one txhostdesc per txdesc, but it looks like
3600 ** acx111 is buggy: it accesses second txhostdesc
3601 ** (via hostdesc.desc_phy_next field) even if
3602 ** txdesc->length == hostdesc->length and thus
3603 ** entire packet was placed into first txhostdesc.
3604 ** Due to this bug acx111 hangs unless second txhostdesc
3605 ** has le16_to_cpu(hostdesc.length) = 3 (or larger)
3606 ** Storing NULL into hostdesc.desc_phy_next
3607 ** doesn't seem to help.
3609 ** Update: although it worked on Xterasys XN-2522g
3610 ** with len=3 trick, WG311v2 is even more bogus, doesn't work.
3611 ** Keeping this code (#ifdef'ed out) for documentational purposes.
3613 for (i
= 0; i
< TX_CNT
*2; i
++) {
3614 hostdesc_phy
+= sizeof(*hostdesc
);
3616 hostdesc
->data_phy
= cpu2acx(txbuf_phy
);
3617 /* hostdesc->data_offset = ... */
3618 /* hostdesc->reserved = ... */
3619 hostdesc
->Ctl_16
= cpu_to_le16(DESC_CTL_HOSTOWN
);
3620 /* hostdesc->length = ... */
3621 hostdesc
->desc_phy_next
= cpu2acx(hostdesc_phy
);
3622 hostdesc
->pNext
= ptr2acx(NULL
);
3623 /* hostdesc->Status = ... */
3624 /* below: non-hardware fields */
3625 hostdesc
->data
= txbuf
;
3627 txbuf
+= WLAN_A4FR_MAXLEN_WEP_FCS
;
3628 txbuf_phy
+= WLAN_A4FR_MAXLEN_WEP_FCS
;
3630 /* hostdesc->data_phy = ... */
3631 /* hostdesc->data_offset = ... */
3632 /* hostdesc->reserved = ... */
3633 /* hostdesc->Ctl_16 = ... */
3634 hostdesc
->length
= cpu_to_le16(3); /* bug workaround */
3635 /* hostdesc->desc_phy_next = ... */
3636 /* hostdesc->pNext = ... */
3637 /* hostdesc->Status = ... */
3638 /* below: non-hardware fields */
3639 /* hostdesc->data = ... */
3644 /* We initialize two hostdescs so that they point to adjacent
3645 ** memory areas. Thus txbuf is really just a contiguous memory area */
3646 for (i
= 0; i
< TX_CNT
*2; i
++) {
3647 hostdesc_phy
+= sizeof(*hostdesc
);
3649 hostdesc
->data_phy
= cpu2acx(txbuf_phy
);
3650 /* done by memset(0): hostdesc->data_offset = 0; */
3651 /* hostdesc->reserved = ... */
3652 hostdesc
->Ctl_16
= cpu_to_le16(DESC_CTL_HOSTOWN
);
3653 /* hostdesc->length = ... */
3654 hostdesc
->desc_phy_next
= cpu2acx(hostdesc_phy
);
3655 /* done by memset(0): hostdesc->pNext = ptr2acx(NULL); */
3656 /* hostdesc->Status = ... */
3657 /* ->data is a non-hardware field: */
3658 hostdesc
->data
= txbuf
;
3661 txbuf
+= WLAN_HDR_A3_LEN
;
3662 txbuf_phy
+= WLAN_HDR_A3_LEN
;
3664 txbuf
+= WLAN_A4FR_MAXLEN_WEP_FCS
- WLAN_HDR_A3_LEN
;
3665 txbuf_phy
+= WLAN_A4FR_MAXLEN_WEP_FCS
- WLAN_HDR_A3_LEN
;
3670 hostdesc
->desc_phy_next
= cpu2acx(adev
->txhostdesc_startphy
);
3675 printk("acx: create_tx_host_desc_queue FAILED\n");
3676 /* dealloc will be done by free function on error case */
3682 /***************************************************************
3683 ** acxpci_s_create_rx_host_desc_queue
3685 /* the whole size of a data buffer (header plus data body)
3686 * plus 32 bytes safety offset at the end */
3687 #define RX_BUFFER_SIZE (sizeof(rxbuffer_t) + 32)
3690 acxpci_s_create_rx_host_desc_queue(acx_device_t
*adev
)
3692 rxhostdesc_t
*hostdesc
;
3694 dma_addr_t hostdesc_phy
;
3695 dma_addr_t rxbuf_phy
;
3700 /* allocate the RX host descriptor queue pool */
3701 adev
->rxhostdesc_area_size
= RX_CNT
* sizeof(*hostdesc
);
3702 adev
->rxhostdesc_start
= allocate(adev
, adev
->rxhostdesc_area_size
,
3703 &adev
->rxhostdesc_startphy
, "rxhostdesc_start");
3704 if (!adev
->rxhostdesc_start
)
3706 /* check for proper alignment of RX host descriptor pool */
3707 if ((long) adev
->rxhostdesc_start
& 3) {
3708 printk("acx: driver bug: dma alloc returns unaligned address\n");
3712 /* allocate Rx buffer pool which will be used by the acx
3713 * to store the whole content of the received frames in it */
3714 adev
->rxbuf_area_size
= RX_CNT
* RX_BUFFER_SIZE
;
3715 adev
->rxbuf_start
= allocate(adev
, adev
->rxbuf_area_size
,
3716 &adev
->rxbuf_startphy
, "rxbuf_start");
3717 if (!adev
->rxbuf_start
)
3720 rxbuf
= adev
->rxbuf_start
;
3721 rxbuf_phy
= adev
->rxbuf_startphy
;
3722 hostdesc
= adev
->rxhostdesc_start
;
3723 hostdesc_phy
= adev
->rxhostdesc_startphy
;
3725 /* don't make any popular C programming pointer arithmetic mistakes
3726 * here, otherwise I'll kill you...
3727 * (and don't dare asking me why I'm warning you about that...) */
3728 for (i
= 0; i
< RX_CNT
; i
++) {
3729 hostdesc
->data
= rxbuf
;
3730 hostdesc
->data_phy
= cpu2acx(rxbuf_phy
);
3731 hostdesc
->length
= cpu_to_le16(RX_BUFFER_SIZE
);
3732 CLEAR_BIT(hostdesc
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
3734 rxbuf_phy
+= sizeof(*rxbuf
);
3735 hostdesc_phy
+= sizeof(*hostdesc
);
3736 hostdesc
->desc_phy_next
= cpu2acx(hostdesc_phy
);
3740 hostdesc
->desc_phy_next
= cpu2acx(adev
->rxhostdesc_startphy
);
3744 printk("acx: create_rx_host_desc_queue FAILED\n");
3745 /* dealloc will be done by free function on error case */
3751 /***************************************************************
3752 ** acxpci_s_create_hostdesc_queues
3755 acxpci_s_create_hostdesc_queues(acx_device_t
*adev
)
3758 result
= acxpci_s_create_tx_host_desc_queue(adev
);
3759 if (OK
!= result
) return result
;
3760 result
= acxpci_s_create_rx_host_desc_queue(adev
);
3765 /***************************************************************
3766 ** acxpci_create_tx_desc_queue
3769 acxpci_create_tx_desc_queue(acx_device_t
*adev
, u32 tx_queue_start
)
3772 txhostdesc_t
*hostdesc
;
3773 dma_addr_t hostmemptr
;
3779 if (IS_ACX100(adev
))
3780 adev
->txdesc_size
= sizeof(*txdesc
);
3782 /* the acx111 txdesc is 4 bytes larger */
3783 adev
->txdesc_size
= sizeof(*txdesc
) + 4;
3785 adev
->txdesc_start
= (txdesc_t
*) (adev
->iobase2
+ tx_queue_start
);
3787 log(L_DEBUG
, "adev->iobase2=%p\n"
3788 "tx_queue_start=%08X\n"
3789 "adev->txdesc_start=%p\n",
3792 adev
->txdesc_start
);
3794 adev
->tx_free
= TX_CNT
;
3795 /* done by memset: adev->tx_head = 0; */
3796 /* done by memset: adev->tx_tail = 0; */
3797 txdesc
= adev
->txdesc_start
;
3798 mem_offs
= tx_queue_start
;
3799 hostmemptr
= adev
->txhostdesc_startphy
;
3800 hostdesc
= adev
->txhostdesc_start
;
3802 if (IS_ACX111(adev
)) {
3803 /* ACX111 has a preinitialized Tx buffer! */
3804 /* loop over whole send pool */
3805 /* FIXME: do we have to do the hostmemptr stuff here?? */
3806 for (i
= 0; i
< TX_CNT
; i
++) {
3807 txdesc
->HostMemPtr
= ptr2acx(hostmemptr
);
3808 txdesc
->Ctl_8
= DESC_CTL_HOSTOWN
;
3809 /* reserve two (hdr desc and payload desc) */
3811 hostmemptr
+= 2 * sizeof(*hostdesc
);
3812 txdesc
= advance_txdesc(adev
, txdesc
, 1);
3815 /* ACX100 Tx buffer needs to be initialized by us */
3816 /* clear whole send pool. sizeof is safe here (we are acx100) */
3817 memset(adev
->txdesc_start
, 0, TX_CNT
* sizeof(*txdesc
));
3819 /* loop over whole send pool */
3820 for (i
= 0; i
< TX_CNT
; i
++) {
3821 log(L_DEBUG
, "configure card tx descriptor: 0x%p, "
3822 "size: 0x%X\n", txdesc
, adev
->txdesc_size
);
3824 /* pointer to hostdesc memory */
3825 txdesc
->HostMemPtr
= ptr2acx(hostmemptr
);
3826 /* initialise ctl */
3827 txdesc
->Ctl_8
= ( DESC_CTL_HOSTOWN
| DESC_CTL_RECLAIM
3828 | DESC_CTL_AUTODMA
| DESC_CTL_FIRSTFRAG
);
3829 /* done by memset(0): txdesc->Ctl2_8 = 0; */
3830 /* point to next txdesc */
3831 txdesc
->pNextDesc
= cpu2acx(mem_offs
+ adev
->txdesc_size
);
3832 /* reserve two (hdr desc and payload desc) */
3834 hostmemptr
+= 2 * sizeof(*hostdesc
);
3835 /* go to the next one */
3836 mem_offs
+= adev
->txdesc_size
;
3837 /* ++ is safe here (we are acx100) */
3840 /* go back to the last one */
3842 /* and point to the first making it a ring buffer */
3843 txdesc
->pNextDesc
= cpu2acx(tx_queue_start
);
3849 /***************************************************************
3850 ** acxpci_create_rx_desc_queue
3853 acxpci_create_rx_desc_queue(acx_device_t
*adev
, u32 rx_queue_start
)
3861 /* done by memset: adev->rx_tail = 0; */
3863 /* ACX111 doesn't need any further config: preconfigures itself.
3864 * Simply print ring buffer for debugging */
3865 if (IS_ACX111(adev
)) {
3866 /* rxdesc_start already set here */
3868 adev
->rxdesc_start
= (rxdesc_t
*) ((u8
*)adev
->iobase2
+ rx_queue_start
);
3870 rxdesc
= adev
->rxdesc_start
;
3871 for (i
= 0; i
< RX_CNT
; i
++) {
3872 log(L_DEBUG
, "rx descriptor %d @ 0x%p\n", i
, rxdesc
);
3873 rxdesc
= adev
->rxdesc_start
= (rxdesc_t
*)
3874 (adev
->iobase2
+ acx2cpu(rxdesc
->pNextDesc
));
3877 /* we didn't pre-calculate rxdesc_start in case of ACX100 */
3878 /* rxdesc_start should be right AFTER Tx pool */
3879 adev
->rxdesc_start
= (rxdesc_t
*)
3880 ((u8
*) adev
->txdesc_start
+ (TX_CNT
* sizeof(txdesc_t
)));
3881 /* NB: sizeof(txdesc_t) above is valid because we know
3882 ** we are in if (acx100) block. Beware of cut-n-pasting elsewhere!
3883 ** acx111's txdesc is larger! */
3885 memset(adev
->rxdesc_start
, 0, RX_CNT
* sizeof(*rxdesc
));
3887 /* loop over whole receive pool */
3888 rxdesc
= adev
->rxdesc_start
;
3889 mem_offs
= rx_queue_start
;
3890 for (i
= 0; i
< RX_CNT
; i
++) {
3891 log(L_DEBUG
, "rx descriptor @ 0x%p\n", rxdesc
);
3892 rxdesc
->Ctl_8
= DESC_CTL_RECLAIM
| DESC_CTL_AUTODMA
;
3893 /* point to next rxdesc */
3894 rxdesc
->pNextDesc
= cpu2acx(mem_offs
+ sizeof(*rxdesc
));
3895 /* go to the next one */
3896 mem_offs
+= sizeof(*rxdesc
);
3899 /* go to the last one */
3902 /* and point to the first making it a ring buffer */
3903 rxdesc
->pNextDesc
= cpu2acx(rx_queue_start
);
3909 /***************************************************************
3910 ** acxpci_create_desc_queues
3913 acxpci_create_desc_queues(acx_device_t
*adev
, u32 tx_queue_start
, u32 rx_queue_start
)
3915 acxpci_create_tx_desc_queue(adev
, tx_queue_start
);
3916 acxpci_create_rx_desc_queue(adev
, rx_queue_start
);
3920 /***************************************************************
3921 ** acxpci_s_proc_diag_output
3924 acxpci_s_proc_diag_output(char *p
, acx_device_t
*adev
)
3926 const char *rtl
, *thd
, *ttl
;
3927 rxhostdesc_t
*rxhostdesc
;
3933 p
+= sprintf(p
, "** Rx buf **\n");
3934 rxhostdesc
= adev
->rxhostdesc_start
;
3935 if (rxhostdesc
) for (i
= 0; i
< RX_CNT
; i
++) {
3936 rtl
= (i
== adev
->rx_tail
) ? " [tail]" : "";
3937 if ((rxhostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
3938 && (rxhostdesc
->Status
& cpu_to_le32(DESC_STATUS_FULL
)) )
3939 p
+= sprintf(p
, "%02u FULL%s\n", i
, rtl
);
3941 p
+= sprintf(p
, "%02u empty%s\n", i
, rtl
);
3944 p
+= sprintf(p
, "** Tx buf (free %d, Linux netqueue %s) **\n", adev
->tx_free
,
3945 acx_queue_stopped(adev
->ndev
) ? "STOPPED" : "running");
3946 txdesc
= adev
->txdesc_start
;
3947 if (txdesc
) for (i
= 0; i
< TX_CNT
; i
++) {
3948 thd
= (i
== adev
->tx_head
) ? " [head]" : "";
3949 ttl
= (i
== adev
->tx_tail
) ? " [tail]" : "";
3950 if (txdesc
->Ctl_8
& DESC_CTL_ACXDONE
)
3951 p
+= sprintf(p
, "%02u free (%02X)%s%s\n", i
, txdesc
->Ctl_8
, thd
, ttl
);
3953 p
+= sprintf(p
, "%02u tx (%02X)%s%s\n", i
, txdesc
->Ctl_8
, thd
, ttl
);
3954 txdesc
= advance_txdesc(adev
, txdesc
, 1);
3959 "txbuf_start %p, txbuf_area_size %u, txbuf_startphy %08llx\n"
3960 "txdesc_size %u, txdesc_start %p\n"
3961 "txhostdesc_start %p, txhostdesc_area_size %u, txhostdesc_startphy %08llx\n"
3963 "rxhostdesc_start %p, rxhostdesc_area_size %u, rxhostdesc_startphy %08llx\n"
3964 "rxbuf_start %p, rxbuf_area_size %u, rxbuf_startphy %08llx\n",
3965 adev
->txbuf_start
, adev
->txbuf_area_size
, (u64
)adev
->txbuf_startphy
,
3966 adev
->txdesc_size
, adev
->txdesc_start
,
3967 adev
->txhostdesc_start
, adev
->txhostdesc_area_size
, (u64
)adev
->txhostdesc_startphy
,
3969 adev
->rxhostdesc_start
, adev
->rxhostdesc_area_size
, (u64
)adev
->rxhostdesc_startphy
,
3970 adev
->rxbuf_start
, adev
->rxbuf_area_size
, (u64
)adev
->rxbuf_startphy
);
3977 /***********************************************************************
3980 acxpci_proc_eeprom_output(char *buf
, acx_device_t
*adev
)
3987 for (i
= 0; i
< 0x400; i
++) {
3988 acxpci_read_eeprom_byte(adev
, i
, p
++);
3996 /***********************************************************************
3999 acxpci_set_interrupt_mask(acx_device_t
*adev
)
4001 if (IS_ACX111(adev
)) {
4002 adev
->irq_mask
= (u16
) ~(0
4003 /* | HOST_INT_RX_DATA */
4004 | HOST_INT_TX_COMPLETE
4005 /* | HOST_INT_TX_XFER */
4006 | HOST_INT_RX_COMPLETE
4007 /* | HOST_INT_DTIM */
4008 /* | HOST_INT_BEACON */
4009 /* | HOST_INT_TIMER */
4010 /* | HOST_INT_KEY_NOT_FOUND */
4011 | HOST_INT_IV_ICV_FAILURE
4012 | HOST_INT_CMD_COMPLETE
4014 /* | HOST_INT_OVERFLOW */
4015 /* | HOST_INT_PROCESS_ERROR */
4016 | HOST_INT_SCAN_COMPLETE
4017 | HOST_INT_FCS_THRESHOLD
4018 /* | HOST_INT_UNKNOWN */
4020 /* Or else acx100 won't signal cmd completion, right? */
4021 adev
->irq_mask_off
= (u16
)~( HOST_INT_CMD_COMPLETE
); /* 0xfdff */
4023 adev
->irq_mask
= (u16
) ~(0
4024 /* | HOST_INT_RX_DATA */
4025 | HOST_INT_TX_COMPLETE
4026 /* | HOST_INT_TX_XFER */
4027 | HOST_INT_RX_COMPLETE
4028 /* | HOST_INT_DTIM */
4029 /* | HOST_INT_BEACON */
4030 /* | HOST_INT_TIMER */
4031 /* | HOST_INT_KEY_NOT_FOUND */
4032 /* | HOST_INT_IV_ICV_FAILURE */
4033 | HOST_INT_CMD_COMPLETE
4035 /* | HOST_INT_OVERFLOW */
4036 /* | HOST_INT_PROCESS_ERROR */
4037 | HOST_INT_SCAN_COMPLETE
4038 /* | HOST_INT_FCS_THRESHOLD */
4039 /* | HOST_INT_UNKNOWN */
4041 adev
->irq_mask_off
= (u16
)~( HOST_INT_UNKNOWN
); /* 0x7fff */
4046 /***********************************************************************
4049 acx100pci_s_set_tx_level(acx_device_t
*adev
, u8 level_dbm
)
4051 /* since it can be assumed that at least the Maxim radio has a
4052 * maximum power output of 20dBm and since it also can be
4053 * assumed that these values drive the DAC responsible for
4054 * setting the linear Tx level, I'd guess that these values
4055 * should be the corresponding linear values for a dBm value,
4056 * in other words: calculate the values from that formula:
4057 * Y [dBm] = 10 * log (X [mW])
4058 * then scale the 0..63 value range onto the 1..100mW range (0..20 dBm)
4059 * and you're done...
4060 * Hopefully that's ok, but you never know if we're actually
4061 * right... (especially since Windows XP doesn't seem to show
4062 * actual Tx dBm values :-P) */
4064 /* NOTE: on Maxim, value 30 IS 30mW, and value 10 IS 10mW - so the
4065 * values are EXACTLY mW!!! Not sure about RFMD and others,
4067 static const u8 dbm2val_maxim
[21] = {
4075 static const u8 dbm2val_rfmd
[21] = {
4085 switch (adev
->radio_type
) {
4086 case RADIO_MAXIM_0D
:
4087 table
= &dbm2val_maxim
[0];
4090 case RADIO_RALINK_15
:
4091 table
= &dbm2val_rfmd
[0];
4094 printk("%s: unknown/unsupported radio type, "
4095 "cannot modify tx power level yet!\n",
4099 printk("%s: changing radio power level to %u dBm (%u)\n",
4100 adev
->ndev
->name
, level_dbm
, table
[level_dbm
]);
4101 acxpci_s_write_phy_reg(adev
, 0x11, table
[level_dbm
]);
4106 /***********************************************************************
4107 ** Data for init_module/cleanup_module
4109 static const struct pci_device_id
4110 acxpci_id_tbl
[] __devinitdata
= {
4112 .vendor
= PCI_VENDOR_ID_TI
,
4113 .device
= PCI_DEVICE_ID_TI_TNETW1100A
,
4114 .subvendor
= PCI_ANY_ID
,
4115 .subdevice
= PCI_ANY_ID
,
4116 .driver_data
= CHIPTYPE_ACX100
,
4119 .vendor
= PCI_VENDOR_ID_TI
,
4120 .device
= PCI_DEVICE_ID_TI_TNETW1100B
,
4121 .subvendor
= PCI_ANY_ID
,
4122 .subdevice
= PCI_ANY_ID
,
4123 .driver_data
= CHIPTYPE_ACX100
,
4126 .vendor
= PCI_VENDOR_ID_TI
,
4127 .device
= PCI_DEVICE_ID_TI_TNETW1130
,
4128 .subvendor
= PCI_ANY_ID
,
4129 .subdevice
= PCI_ANY_ID
,
4130 .driver_data
= CHIPTYPE_ACX111
,
4141 MODULE_DEVICE_TABLE(pci
, acxpci_id_tbl
);
4143 /* FIXME: checks should be removed once driver is included in the kernel */
4144 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 11)
4145 /* pci_name() got introduced at start of 2.6.x,
4146 * got mandatory (slot_name member removed) in 2.6.11-bk1 */
4147 #define pci_name(x) x->slot_name
4150 static struct pci_driver
4153 .id_table
= acxpci_id_tbl
,
4154 .probe
= acxpci_e_probe
,
4155 .remove
= __devexit_p(acxpci_e_remove
),
4157 .suspend
= acxpci_e_suspend
,
4158 .resume
= acxpci_e_resume
4159 #endif /* CONFIG_PM */
4163 /***********************************************************************
4164 ** acxpci_e_init_module
4166 ** Module initialization routine, called once at module load time
4169 acxpci_e_init_module(void)
4175 #if (ACX_IO_WIDTH==32)
4176 printk("acx: compiled to use 32bit I/O access. "
4177 "I/O timing issues might occur, such as "
4178 "non-working firmware upload. Report them\n");
4180 printk("acx: compiled to use 16bit I/O access only "
4181 "(compatibility mode)\n");
4184 #ifdef __LITTLE_ENDIAN
4185 #define ENDIANNESS_STRING "running on a little-endian CPU\n"
4187 #define ENDIANNESS_STRING "running on a BIG-ENDIAN CPU\n"
4191 "PCI module " ACX_RELEASE
" initialized, "
4192 "waiting for cards to probe...\n"
4195 res
= pci_register_driver(&acxpci_drv_id
);
4201 /***********************************************************************
4202 ** acxpci_e_cleanup_module
4204 ** Called at module unload time. This is our last chance to
4205 ** clean up after ourselves.
4208 acxpci_e_cleanup_module(void)
4210 struct net_device
*ndev
;
4211 unsigned long flags
;
4215 /* Since the whole module is about to be unloaded,
4216 * we recursively shutdown all cards we handled instead
4217 * of doing it in acxpci_e_remove() (which will be activated by us
4218 * via pci_unregister_driver at the end).
4219 * acxpci_e_remove() might just get called after a card eject,
4220 * that's why hardware operations have to be done here instead
4221 * when the hardware is available. */
4223 down(&root_adev_sem
);
4225 ndev
= root_adev_newest
;
4227 acx_device_t
*adev
= ndev2adev(ndev
);
4231 /* disable both Tx and Rx to shut radio down properly */
4232 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_TX
, NULL
, 0);
4233 acx_s_issue_cmd(adev
, ACX1xx_CMD_DISABLE_RX
, NULL
, 0);
4236 /* put the eCPU to sleep to save power
4237 * Halting is not possible currently,
4238 * since not supported by all firmware versions */
4239 acx_s_issue_cmd(adev
, ACX100_CMD_SLEEP
, NULL
, 0);
4241 acx_lock(adev
, flags
);
4243 /* disable power LED to save power :-) */
4244 log(L_INIT
, "switching off power LED to save power\n");
4245 acxpci_l_power_led(adev
, 0);
4248 if (IS_ACX111(adev
)) {
4249 /* FIXME: does this actually keep halting the eCPU?
4250 * I don't think so...
4252 acxpci_l_reset_mac(adev
);
4257 temp
= read_reg16(adev
, IO_ACX_ECPU_CTRL
) | 0x1;
4258 write_reg16(adev
, IO_ACX_ECPU_CTRL
, temp
);
4262 acx_unlock(adev
, flags
);
4264 acx_sem_unlock(adev
);
4266 ndev
= adev
->prev_nd
;
4271 /* now let the PCI layer recursively remove
4272 * all PCI related things (acxpci_e_remove()) */
4273 pci_unregister_driver(&acxpci_drv_id
);