Use the rdtscl call only on x86 achitectures
[acx-mac80211.git] / pci.c
blobabf25ad7b2053c64ad987cfe050746cd3417a6e6
1 /*
2 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
3 * The ACX100 Open Source Project <acx100-devel@lists.sourceforge.net>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #define ACX_MAC80211_PCI 1
20 #include <linux/version.h>
22 /* Linux 2.6.18+ uses <linux/utsrelease.h> */
23 #ifndef UTS_RELEASE
24 #include <linux/utsrelease.h>
25 #endif
27 #include <linux/compiler.h> /* required for Lx 2.6.8 ?? */
28 #include <linux/kernel.h>
29 #include <linux/module.h>
30 #include <linux/moduleparam.h>
31 #include <linux/sched.h>
32 #include <linux/types.h>
33 #include <linux/skbuff.h>
34 #include <linux/slab.h>
35 #include <linux/if_arp.h>
36 #include <linux/rtnetlink.h>
37 #include <linux/wireless.h>
38 #include <net/iw_handler.h>
39 #include <linux/netdevice.h>
40 #include <linux/ioport.h>
41 #include <linux/pci.h>
42 #include <linux/pm.h>
43 #include <linux/vmalloc.h>
44 #include <linux/ethtool.h>
45 #include <linux/dma-mapping.h>
46 #include <linux/workqueue.h>
47 #ifdef CONFIG_VLYNQ
48 #include <linux/vlynq.h>
49 #endif
51 #include "acx.h"
53 /***********************************************************************
55 #ifdef CONFIG_PCI
56 #define PCI_TYPE (PCI_USES_MEM | PCI_ADDR0 | PCI_NO_ACPI_WAKE)
57 #define PCI_ACX100_REGION1 0x01
58 #define PCI_ACX100_REGION1_SIZE 0x1000 /* Memory size - 4K bytes */
59 #define PCI_ACX100_REGION2 0x02
60 #define PCI_ACX100_REGION2_SIZE 0x10000 /* Memory size - 64K bytes */
62 #define PCI_ACX111_REGION1 0x00
63 #define PCI_ACX111_REGION1_SIZE 0x2000 /* Memory size - 8K bytes */
64 #define PCI_ACX111_REGION2 0x01
65 #define PCI_ACX111_REGION2_SIZE 0x20000 /* Memory size - 128K bytes */
67 /* Texas Instruments Vendor ID */
68 #define PCI_VENDOR_ID_TI 0x104c
70 /* ACX100 22Mb/s WLAN controller */
71 #define PCI_DEVICE_ID_TI_TNETW1100A 0x8400
72 #define PCI_DEVICE_ID_TI_TNETW1100B 0x8401
74 /* ACX111 54Mb/s WLAN controller */
75 #define PCI_DEVICE_ID_TI_TNETW1130 0x9066
77 /* PCI Class & Sub-Class code, Network-'Other controller' */
78 #define PCI_CLASS_NETWORK_OTHERS 0x0280
80 #define CARD_EEPROM_ID_SIZE 6
82 #ifndef PCI_D0
83 /* From include/linux/pci.h */
84 #define PCI_D0 0
85 #define PCI_D1 1
86 #define PCI_D2 2
87 #define PCI_D3hot 3
88 #define PCI_D3cold 4
89 #define PCI_UNKNOWN 5
90 #define PCI_POWER_ERROR -1
91 #endif
92 #endif /* CONFIG_PCI */
94 /***********************************************************************
97 static irqreturn_t acxpci_i_interrupt(int irq, void *dev_id);
99 static void disable_acx_irq(acx_device_t * adev);
101 static int acxpci_e_open(struct ieee80211_hw *hw);
102 static void acxpci_e_close(struct ieee80211_hw *hw);
103 static void acxpci_s_up(struct ieee80211_hw *hw);
104 static void acxpci_s_down(struct ieee80211_hw *hw);
106 /***********************************************************************
107 ** Register access
112 /* OS I/O routines *always* be endianness-clean but having them doesn't hurt */
113 #define acx_readl(v) le32_to_cpu(readl((v)))
114 #define acx_readw(v) le16_to_cpu(readw((v)))
115 #define acx_writew(v,r) writew(le16_to_cpu((v)), r)
116 #define acx_writel(v,r) writel(le32_to_cpu((v)), r)
118 /* Pick one */
119 /* #define INLINE_IO static */
120 #define INLINE_IO static inline
122 INLINE_IO u32 read_reg32(acx_device_t * adev, unsigned int offset)
124 #if ACX_IO_WIDTH == 32
125 return acx_readl((u8 *) adev->iobase + adev->io[offset]);
126 #else
127 return acx_readw((u8 *) adev->iobase + adev->io[offset])
128 + (acx_readw((u8 *) adev->iobase + adev->io[offset] + 2) << 16);
129 #endif
132 INLINE_IO u16 read_reg16(acx_device_t * adev, unsigned int offset)
134 return acx_readw((u8 *) adev->iobase + adev->io[offset]);
137 INLINE_IO u8 read_reg8(acx_device_t * adev, unsigned int offset)
139 return readb((u8 *) adev->iobase + adev->io[offset]);
142 INLINE_IO void write_reg32(acx_device_t * adev, unsigned int offset, u32 val)
144 #if ACX_IO_WIDTH == 32
145 acx_writel(val, (u8 *) adev->iobase + adev->io[offset]);
146 #else
147 acx_writew(val & 0xffff, (u8 *) adev->iobase + adev->io[offset]);
148 acx_writew(val >> 16, (u8 *) adev->iobase + adev->io[offset] + 2);
149 #endif
152 INLINE_IO void write_reg16(acx_device_t * adev, unsigned int offset, u16 val)
154 acx_writew(val, (u8 *) adev->iobase + adev->io[offset]);
157 INLINE_IO void write_reg8(acx_device_t * adev, unsigned int offset, u8 val)
159 writeb(val, (u8 *) adev->iobase + adev->io[offset]);
162 /* Handle PCI posting properly:
163 * Make sure that writes reach the adapter in case they require to be executed
164 * *before* the next write, by reading a random (and safely accessible) register.
165 * This call has to be made if there is no read following (which would flush the data
166 * to the adapter), yet the written data has to reach the adapter immediately. */
167 INLINE_IO void write_flush(acx_device_t * adev)
169 /* readb(adev->iobase + adev->io[IO_ACX_INFO_MAILBOX_OFFS]); */
170 /* faster version (accesses the first register, IO_ACX_SOFT_RESET,
171 * which should also be safe): */
172 readb(adev->iobase);
175 INLINE_IO int adev_present(acx_device_t * adev)
177 /* fast version (accesses the first register, IO_ACX_SOFT_RESET,
178 * which should be safe): */
179 return acx_readl(adev->iobase) != 0xffffffff;
183 /***********************************************************************
185 static inline txdesc_t *get_txdesc(acx_device_t * adev, int index)
187 return (txdesc_t *) (((u8 *) adev->txdesc_start) +
188 index * adev->txdesc_size);
191 static inline txdesc_t *advance_txdesc(acx_device_t * adev, txdesc_t * txdesc,
192 int inc)
194 return (txdesc_t *) (((u8 *) txdesc) + inc * adev->txdesc_size);
197 static txhostdesc_t *get_txhostdesc(acx_device_t * adev, txdesc_t * txdesc)
199 int index = (u8 *) txdesc - (u8 *) adev->txdesc_start;
201 FN_ENTER;
203 if (unlikely(ACX_DEBUG && (index % adev->txdesc_size))) {
204 printk("acx: bad txdesc ptr %p\n", txdesc);
205 return NULL;
207 index /= adev->txdesc_size;
208 if (unlikely(ACX_DEBUG && (index >= TX_CNT))) {
209 printk("acx: bad txdesc ptr %p\n", txdesc);
210 return NULL;
213 FN_EXIT0;
215 return &adev->txhostdesc_start[index * 2];
222 /***********************************************************************
223 ** EEPROM and PHY read/write helpers
225 /***********************************************************************
226 ** acxpci_read_eeprom_byte
228 ** Function called to read an octet in the EEPROM.
230 ** This function is used by acxpci_e_probe to check if the
231 ** connected card is a legal one or not.
233 ** Arguments:
234 ** adev ptr to acx_device structure
235 ** addr address to read in the EEPROM
236 ** charbuf ptr to a char. This is where the read octet
237 ** will be stored
240 int acxpci_read_eeprom_byte(acx_device_t * adev, u32 addr, u8 * charbuf)
242 int result;
243 int count;
245 FN_ENTER;
247 write_reg32(adev, IO_ACX_EEPROM_CFG, 0);
248 write_reg32(adev, IO_ACX_EEPROM_ADDR, addr);
249 write_flush(adev);
250 write_reg32(adev, IO_ACX_EEPROM_CTL, 2);
252 count = 0xffff;
253 while (read_reg16(adev, IO_ACX_EEPROM_CTL)) {
254 /* scheduling away instead of CPU burning loop
255 * doesn't seem to work here at all:
256 * awful delay, sometimes also failure.
257 * Doesn't matter anyway (only small delay). */
258 if (unlikely(!--count)) {
259 printk("acx: %s: timeout waiting for EEPROM read\n",
260 wiphy_name(adev->ieee->wiphy));
261 result = NOT_OK;
262 goto fail;
264 cpu_relax();
267 *charbuf = read_reg8(adev, IO_ACX_EEPROM_DATA);
268 log(L_DEBUG, "acx: EEPROM at 0x%04X = 0x%02X\n", addr, *charbuf);
269 result = OK;
271 fail:
272 FN_EXIT1(result);
273 return result;
277 /***********************************************************************
278 ** We don't lock hw accesses here since we never r/w eeprom in IRQ
279 ** Note: this function sleeps only because of GFP_KERNEL alloc
281 #ifdef UNUSED
283 acxpci_s_write_eeprom(acx_device_t * adev, u32 addr, u32 len,
284 const u8 * charbuf)
286 u8 *data_verify = NULL;
287 unsigned long flags;
288 int count, i;
289 int result = NOT_OK;
290 u16 gpio_orig;
292 printk("acx: WARNING! I would write to EEPROM now. "
293 "Since I really DON'T want to unless you know "
294 "what you're doing (THIS CODE WILL PROBABLY "
295 "NOT WORK YET!), I will abort that now. And "
296 "definitely make sure to make a "
297 "/proc/driver/acx_wlan0_eeprom backup copy first!!! "
298 "(the EEPROM content includes the PCI config header!! "
299 "If you kill important stuff, then you WILL "
300 "get in trouble and people DID get in trouble already)\n");
301 return OK;
303 FN_ENTER;
305 data_verify = kmalloc(len, GFP_KERNEL);
306 if (!data_verify) {
307 goto end;
310 /* first we need to enable the OE (EEPROM Output Enable) GPIO line
311 * to be able to write to the EEPROM.
312 * NOTE: an EEPROM writing success has been reported,
313 * but you probably have to modify GPIO_OUT, too,
314 * and you probably need to activate a different GPIO
315 * line instead! */
316 gpio_orig = read_reg16(adev, IO_ACX_GPIO_OE);
317 write_reg16(adev, IO_ACX_GPIO_OE, gpio_orig & ~1);
318 write_flush(adev);
320 /* ok, now start writing the data out */
321 for (i = 0; i < len; i++) {
322 write_reg32(adev, IO_ACX_EEPROM_CFG, 0);
323 write_reg32(adev, IO_ACX_EEPROM_ADDR, addr + i);
324 write_reg32(adev, IO_ACX_EEPROM_DATA, *(charbuf + i));
325 write_flush(adev);
326 write_reg32(adev, IO_ACX_EEPROM_CTL, 1);
328 count = 0xffff;
329 while (read_reg16(adev, IO_ACX_EEPROM_CTL)) {
330 if (unlikely(!--count)) {
331 printk("acx: WARNING, DANGER!!! "
332 "Timeout waiting for EEPROM write\n");
333 goto end;
335 cpu_relax();
339 /* disable EEPROM writing */
340 write_reg16(adev, IO_ACX_GPIO_OE, gpio_orig);
341 write_flush(adev);
343 /* now start a verification run */
344 for (i = 0; i < len; i++) {
345 write_reg32(adev, IO_ACX_EEPROM_CFG, 0);
346 write_reg32(adev, IO_ACX_EEPROM_ADDR, addr + i);
347 write_flush(adev);
348 write_reg32(adev, IO_ACX_EEPROM_CTL, 2);
350 count = 0xffff;
351 while (read_reg16(adev, IO_ACX_EEPROM_CTL)) {
352 if (unlikely(!--count)) {
353 printk("acx: timeout waiting for EEPROM read\n");
354 goto end;
356 cpu_relax();
359 data_verify[i] = read_reg16(adev, IO_ACX_EEPROM_DATA);
362 if (0 == memcmp(charbuf, data_verify, len))
363 result = OK; /* read data matches, success */
365 end:
366 kfree(data_verify);
367 FN_EXIT1(result);
368 return result;
370 #endif /* UNUSED */
373 /***********************************************************************
374 ** acxpci_s_read_phy_reg
376 ** Messing with rx/tx disabling and enabling here
377 ** (write_reg32(adev, IO_ACX_ENABLE, 0b000000xx)) kills traffic
379 int acxpci_s_read_phy_reg(acx_device_t * adev, u32 reg, u8 * charbuf)
381 int result = NOT_OK;
382 int count;
384 FN_ENTER;
386 write_reg32(adev, IO_ACX_PHY_ADDR, reg);
387 write_flush(adev);
388 write_reg32(adev, IO_ACX_PHY_CTL, 2);
390 count = 0xffff;
391 while (read_reg32(adev, IO_ACX_PHY_CTL)) {
392 /* scheduling away instead of CPU burning loop
393 * doesn't seem to work here at all:
394 * awful delay, sometimes also failure.
395 * Doesn't matter anyway (only small delay). */
396 if (unlikely(!--count)) {
397 printk("acx: %s: timeout waiting for phy read\n",
398 wiphy_name(adev->ieee->wiphy));
399 *charbuf = 0;
400 goto fail;
402 cpu_relax();
405 log(L_DEBUG, "acx: the count was %u\n", count);
406 *charbuf = read_reg8(adev, IO_ACX_PHY_DATA);
408 log(L_DEBUG, "acx: radio PHY at 0x%04X = 0x%02X\n", *charbuf, reg);
409 result = OK;
410 goto fail; /* silence compiler warning */
411 fail:
412 FN_EXIT1(result);
413 return result;
417 /***********************************************************************
419 int acxpci_s_write_phy_reg(acx_device_t * adev, u32 reg, u8 value)
421 FN_ENTER;
423 /* mprusko said that 32bit accesses result in distorted sensitivity
424 * on his card. Unconfirmed, looks like it's not true (most likely since we
425 * now properly flush writes). */
426 write_reg32(adev, IO_ACX_PHY_DATA, value);
427 write_reg32(adev, IO_ACX_PHY_ADDR, reg);
428 write_flush(adev);
429 write_reg32(adev, IO_ACX_PHY_CTL, 1);
430 write_flush(adev);
431 log(L_DEBUG, "acx: radio PHY write 0x%02X at 0x%04X\n", value, reg);
433 FN_EXIT0;
434 return OK;
438 #define NO_AUTO_INCREMENT 1
440 /***********************************************************************
441 ** acxpci_s_write_fw
443 ** Write the firmware image into the card.
445 ** Arguments:
446 ** adev wlan device structure
447 ** fw_image firmware image.
449 ** Returns:
450 ** 1 firmware image corrupted
451 ** 0 success
453 ** Standard csum implementation + write to IO
455 static int
456 acxpci_s_write_fw(acx_device_t * adev, const firmware_image_t *fw_image,
457 u32 offset)
459 int len, size;
460 u32 sum, v32;
461 /* we skip the first four bytes which contain the control sum */
463 const u8 *p = (u8 *) fw_image + 4;
465 FN_ENTER;
467 /* start the image checksum by adding the image size value */
468 sum = p[0] + p[1] + p[2] + p[3];
469 p += 4;
471 write_reg32(adev, IO_ACX_SLV_END_CTL, 0);
473 #if NO_AUTO_INCREMENT
474 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 0); /* use basic mode */
475 #else
476 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 1); /* use autoincrement mode */
477 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset); /* configure start address */
478 write_flush(adev);
479 #endif
481 len = 0;
482 size = le32_to_cpu(fw_image->size) & (~3);
484 while (likely(len < size)) {
485 v32 = be32_to_cpu(*(u32 *) p);
486 sum += p[0] + p[1] + p[2] + p[3];
487 p += 4;
488 len += 4;
490 #if NO_AUTO_INCREMENT
491 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset + len - 4);
492 write_flush(adev);
493 #endif
494 write_reg32(adev, IO_ACX_SLV_MEM_DATA, v32);
497 log(L_DEBUG, "acx: firmware written, size:%d sum1:%x sum2:%x\n",
498 size, sum, le32_to_cpu(fw_image->chksum));
500 /* compare our checksum with the stored image checksum */
501 FN_EXIT1(sum != le32_to_cpu(fw_image->chksum));
502 return (sum != le32_to_cpu(fw_image->chksum));
506 /***********************************************************************
507 ** acxpci_s_validate_fw
509 ** Compare the firmware image given with
510 ** the firmware image written into the card.
512 ** Arguments:
513 ** adev wlan device structure
514 ** fw_image firmware image.
516 ** Returns:
517 ** NOT_OK firmware image corrupted or not correctly written
518 ** OK success
520 ** Origin: Standard csum + Read IO
522 static int
523 acxpci_s_validate_fw(acx_device_t * adev, const firmware_image_t *fw_image,
524 u32 offset)
526 u32 sum, v32, w32;
527 int len, size;
528 int result = OK;
529 /* we skip the first four bytes which contain the control sum */
530 const u8 *p = (u8 *) fw_image + 4;
532 FN_ENTER;
534 /* start the image checksum by adding the image size value */
535 sum = p[0] + p[1] + p[2] + p[3];
536 p += 4;
538 write_reg32(adev, IO_ACX_SLV_END_CTL, 0);
540 #if NO_AUTO_INCREMENT
541 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 0); /* use basic mode */
542 #else
543 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 1); /* use autoincrement mode */
544 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset); /* configure start address */
545 #endif
547 len = 0;
548 size = le32_to_cpu(fw_image->size) & (~3);
550 while (likely(len < size)) {
551 v32 = be32_to_cpu(*(u32 *) p);
552 p += 4;
553 len += 4;
555 #if NO_AUTO_INCREMENT
556 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset + len - 4);
557 #endif
558 w32 = read_reg32(adev, IO_ACX_SLV_MEM_DATA);
560 if (unlikely(w32 != v32)) {
561 printk("acx: FATAL: firmware upload: "
562 "data parts at offset %d don't match (0x%08X vs. 0x%08X)! "
563 "I/O timing issues or defective memory, with DWL-xx0+? "
564 "ACX_IO_WIDTH=16 may help. Please report\n",
565 len, v32, w32);
566 result = NOT_OK;
567 break;
570 sum +=
571 (u8) w32 + (u8) (w32 >> 8) + (u8) (w32 >> 16) +
572 (u8) (w32 >> 24);
575 /* sum control verification */
576 if (result != NOT_OK) {
577 if (sum != le32_to_cpu(fw_image->chksum)) {
578 printk("acx: FATAL: firmware upload: "
579 "checksums don't match!\n");
580 result = NOT_OK;
584 FN_EXIT1(result);
585 return result;
589 /***********************************************************************
590 ** acxpci_s_upload_fw
592 ** Called from acx_reset_dev
594 ** Origin: Derived from FW dissection
596 static int acxpci_s_upload_fw(acx_device_t * adev)
598 firmware_image_t *fw_image = NULL;
599 int res = NOT_OK;
600 int try;
601 u32 file_size;
602 char filename[sizeof("tiacx1NNcNN")];
604 FN_ENTER;
606 /* print exact chipset and radio ID to make sure people
607 * really get a clue on which files exactly they need to provide.
608 * Firmware loading is a frequent end-user PITA with these chipsets.
610 printk( "acx: need firmware for acx1%02d chipset with radio ID %02X\n"
611 "Please provide via firmware hotplug:\n"
612 "either combined firmware (single file named 'tiacx1%02dc%02X')\n"
613 "or two files (base firmware file 'tiacx1%02d' "
614 "+ radio fw 'tiacx1%02dr%02X')\n",
615 IS_ACX111(adev)*11, adev->radio_type,
616 IS_ACX111(adev)*11, adev->radio_type,
617 IS_ACX111(adev)*11,
618 IS_ACX111(adev)*11, adev->radio_type
621 /* print exact chipset and radio ID to make sure people really get a clue on which files exactly they are supposed to provide,
622 * since firmware loading is the biggest enduser PITA with these chipsets.
623 * Not printing radio ID in 0xHEX in order to not confuse them into wrong file naming */
624 printk( "acx: need to load firmware for acx1%02d chipset with radio ID %02x, please provide via firmware hotplug:\n"
625 "acx: either one file only (<c>ombined firmware image file, radio-specific) or two files (radio-less base image file *plus* separate <r>adio-specific extension file)\n",
626 IS_ACX111(adev)*11, adev->radio_type);
628 /* Try combined, then main image */
629 adev->need_radio_fw = 0;
630 snprintf(filename, sizeof(filename), "tiacx1%02dc%02X",
631 IS_ACX111(adev) * 11, adev->radio_type);
633 fw_image = acx_s_read_fw(adev->bus_dev, filename, &file_size);
634 if (!fw_image) {
635 adev->need_radio_fw = 1;
636 filename[sizeof("tiacx1NN") - 1] = '\0';
637 fw_image =
638 acx_s_read_fw(adev->bus_dev, filename, &file_size);
639 if (!fw_image) {
640 FN_EXIT1(NOT_OK);
641 return NOT_OK;
645 for (try = 1; try <= 5; try++) {
646 res = acxpci_s_write_fw(adev, fw_image, 0);
647 log(L_DEBUG | L_INIT, "acx: acx_write_fw (main/combined): %d\n", res);
648 if (OK == res) {
649 res = acxpci_s_validate_fw(adev, fw_image, 0);
650 log(L_DEBUG | L_INIT, "acx: acx_validate_fw "
651 "(main/combined): %d\n", res);
654 if (OK == res) {
655 SET_BIT(adev->dev_state_mask, ACX_STATE_FW_LOADED);
656 break;
658 printk("acx: firmware upload attempt #%d FAILED, "
659 "retrying...\n", try);
660 acx_s_mwait(1000); /* better wait for a while... */
663 vfree(fw_image);
665 FN_EXIT1(res);
666 return res;
670 /***********************************************************************
671 ** acxpci_s_upload_radio
673 ** Uploads the appropriate radio module firmware into the card.
675 ** Origin: Standard Read/Write to IO
677 int acxpci_s_upload_radio(acx_device_t * adev)
679 acx_ie_memmap_t mm;
680 firmware_image_t *radio_image;
681 acx_cmd_radioinit_t radioinit;
682 int res = NOT_OK;
683 int try;
684 u32 offset;
685 u32 size;
686 char filename[sizeof("tiacx1NNrNN")];
688 if (!adev->need_radio_fw)
689 return OK;
691 FN_ENTER;
693 acx_s_interrogate(adev, &mm, ACX1xx_IE_MEMORY_MAP);
694 offset = le32_to_cpu(mm.CodeEnd);
696 snprintf(filename, sizeof(filename), "tiacx1%02dr%02X",
697 IS_ACX111(adev) * 11, adev->radio_type);
698 radio_image = acx_s_read_fw(adev->bus_dev, filename, &size);
699 if (!radio_image) {
700 printk("acx: can't load radio module '%s'\n", filename);
701 goto fail;
704 acx_s_issue_cmd(adev, ACX1xx_CMD_SLEEP, NULL, 0);
706 for (try = 1; try <= 5; try++) {
707 res = acxpci_s_write_fw(adev, radio_image, offset);
708 log(L_DEBUG | L_INIT, "acx: acx_write_fw (radio): %d\n", res);
709 if (OK == res) {
710 res = acxpci_s_validate_fw(adev, radio_image, offset);
711 log(L_DEBUG | L_INIT, "acx: acx_validate_fw (radio): %d\n",
712 res);
715 if (OK == res)
716 break;
717 printk("acx: radio firmware upload attempt #%d FAILED, "
718 "retrying...\n", try);
719 acx_s_mwait(1000); /* better wait for a while... */
722 acx_s_issue_cmd(adev, ACX1xx_CMD_WAKE, NULL, 0);
723 radioinit.offset = cpu_to_le32(offset);
724 /* no endian conversion needed, remains in card CPU area: */
725 radioinit.len = radio_image->size;
727 vfree(radio_image);
729 if (OK != res)
730 goto fail;
732 /* will take a moment so let's have a big timeout */
733 acx_s_issue_cmd_timeo(adev, ACX1xx_CMD_RADIOINIT,
734 &radioinit, sizeof(radioinit),
735 CMD_TIMEOUT_MS(1000));
737 res = acx_s_interrogate(adev, &mm, ACX1xx_IE_MEMORY_MAP);
738 fail:
739 FN_EXIT1(res);
740 return res;
744 /***********************************************************************
745 ** acxpci_l_reset_mac
747 ** MAC will be reset
748 ** Call context: reset_dev
750 ** Origin: Standard Read/Write to IO
752 static void acxpci_l_reset_mac(acx_device_t * adev)
754 u16 temp;
756 FN_ENTER;
758 /* halt eCPU */
759 temp = read_reg16(adev, IO_ACX_ECPU_CTRL) | 0x1;
760 write_reg16(adev, IO_ACX_ECPU_CTRL, temp);
762 /* now do soft reset of eCPU, set bit */
763 temp = read_reg16(adev, IO_ACX_SOFT_RESET) | 0x1;
764 log(L_DEBUG, "acx: enable soft reset\n");
765 write_reg16(adev, IO_ACX_SOFT_RESET, temp);
766 write_flush(adev);
768 /* now clear bit again: deassert eCPU reset */
769 log(L_DEBUG, "acx: disable soft reset and go to init mode\n");
770 write_reg16(adev, IO_ACX_SOFT_RESET, temp & ~0x1);
772 /* now start a burst read from initial EEPROM */
773 temp = read_reg16(adev, IO_ACX_EE_START) | 0x1;
774 write_reg16(adev, IO_ACX_EE_START, temp);
775 write_flush(adev);
777 FN_EXIT0;
781 /***********************************************************************
782 ** acxpci_s_verify_init
784 static int acxpci_s_verify_init(acx_device_t * adev)
786 int result = NOT_OK;
787 unsigned long timeout;
789 FN_ENTER;
791 timeout = jiffies + 2 * HZ;
792 for (;;) {
793 u16 irqstat = read_reg16(adev, IO_ACX_IRQ_STATUS_NON_DES);
794 if (irqstat & HOST_INT_FCS_THRESHOLD) {
795 result = OK;
796 write_reg16(adev, IO_ACX_IRQ_ACK,
797 HOST_INT_FCS_THRESHOLD);
798 break;
800 if (time_after(jiffies, timeout))
801 break;
802 /* Init may take up to ~0.5 sec total */
803 acx_s_mwait(50);
806 FN_EXIT1(result);
807 return result;
811 /***********************************************************************
812 ** A few low-level helpers
814 ** Note: these functions are not protected by lock
815 ** and thus are never allowed to be called from IRQ.
816 ** Also they must not race with fw upload which uses same hw regs
819 /***********************************************************************
820 ** acxpci_write_cmd_type_status
822 ** Origin: Common linux implementation
825 static inline void
826 acxpci_write_cmd_type_status(acx_device_t * adev, u16 type, u16 status)
828 FN_ENTER;
829 acx_writel(type | (status << 16), adev->cmd_area);
830 write_flush(adev);
831 FN_EXIT0;
835 /***********************************************************************
836 ** acxpci_read_cmd_type_status
838 ** Origin: Common linux implementation
840 static u32 acxpci_read_cmd_type_status(acx_device_t * adev)
842 u32 cmd_type, cmd_status;
844 FN_ENTER;
846 cmd_type = acx_readl(adev->cmd_area);
847 cmd_status = (cmd_type >> 16);
848 cmd_type = (u16) cmd_type;
850 log(L_CTL, "acx: cmd_type:%04X cmd_status:%04X [%s]\n",
851 cmd_type, cmd_status, acx_cmd_status_str(cmd_status));
853 FN_EXIT1(cmd_status);
854 return cmd_status;
858 /***********************************************************************
859 ** acxpci_s_reset_dev
861 ** Arguments:
862 ** netdevice that contains the adev variable
863 ** Returns:
864 ** NOT_OK on fail
865 ** OK on success
866 ** Side effects:
867 ** device is hard reset
868 ** Call context:
869 ** acxpci_e_probe
870 ** Comment:
871 ** This resets the device using low level hardware calls
872 ** as well as uploads and verifies the firmware to the card
875 static inline void init_mboxes(acx_device_t * adev)
877 u32 cmd_offs, info_offs;
879 FN_ENTER;
881 cmd_offs = read_reg32(adev, IO_ACX_CMD_MAILBOX_OFFS);
882 info_offs = read_reg32(adev, IO_ACX_INFO_MAILBOX_OFFS);
883 adev->cmd_area = (u8 *) adev->iobase2 + cmd_offs;
884 adev->info_area = (u8 *) adev->iobase2 + info_offs;
885 log(L_DEBUG, "acx: iobase2=%p\n"
886 "acx: cmd_mbox_offset=%X cmd_area=%p\n"
887 "acx: info_mbox_offset=%X info_area=%p\n",
888 adev->iobase2,
889 cmd_offs, adev->cmd_area, info_offs, adev->info_area);
890 FN_EXIT0;
894 static inline void read_eeprom_area(acx_device_t * adev)
896 #if ACX_DEBUG > 1
897 int offs;
898 u8 tmp;
900 FN_ENTER;
902 for (offs = 0x8c; offs < 0xb9; offs++)
903 acxpci_read_eeprom_byte(adev, offs, &tmp);
905 FN_EXIT0;
906 #endif
910 int acxpci_s_reset_dev(acx_device_t * adev)
912 const char *msg = "";
913 unsigned long flags;
914 int result = NOT_OK;
915 u16 hardware_info;
916 u16 ecpu_ctrl;
917 int count;
919 FN_ENTER;
921 /* reset the device to make sure the eCPU is stopped
922 * to upload the firmware correctly */
924 acx_lock(adev, flags);
926 #ifdef CONFIG_PCI
927 acxpci_l_reset_mac(adev);
928 #endif
930 ecpu_ctrl = read_reg16(adev, IO_ACX_ECPU_CTRL) & 1;
931 if (!ecpu_ctrl) {
932 msg = "acx: eCPU is already running. ";
933 goto end_unlock;
935 #if 0
936 if (read_reg16(adev, IO_ACX_SOR_CFG) & 2) {
937 /* eCPU most likely means "embedded CPU" */
938 msg = "acx: eCPU did not start after boot from flash. ";
939 goto end_unlock;
942 /* check sense on reset flags */
943 if (read_reg16(adev, IO_ACX_SOR_CFG) & 0x10) {
944 printk("acx: %s: eCPU did not start after boot (SOR), "
945 "is this fatal?\n", wiphy_name(adev->ieee->wiphy));
947 #endif
948 /* scan, if any, is stopped now, setting corresponding IRQ bit */
949 SET_BIT(adev->irq_status, HOST_INT_SCAN_COMPLETE);
951 acx_unlock(adev, flags);
953 /* need to know radio type before fw load */
954 /* Need to wait for arrival of this information in a loop,
955 * most probably since eCPU runs some init code from EEPROM
956 * (started burst read in reset_mac()) which also
957 * sets the radio type ID */
959 count = 0xffff;
960 do {
961 hardware_info = read_reg16(adev, IO_ACX_EEPROM_INFORMATION);
962 if (!--count) {
963 msg = "acx: eCPU didn't indicate radio type";
964 goto end_fail;
966 cpu_relax();
967 } while (!(hardware_info & 0xff00)); /* radio type still zero? */
969 /* printk("acx: DEBUG: count %d\n", count); */
970 adev->form_factor = hardware_info & 0xff;
971 adev->radio_type = hardware_info >> 8;
973 /* load the firmware */
974 if (OK != acxpci_s_upload_fw(adev))
975 goto end_fail;
977 /* acx_s_mwait(10); this one really shouldn't be required */
979 /* now start eCPU by clearing bit */
980 write_reg16(adev, IO_ACX_ECPU_CTRL, ecpu_ctrl & ~0x1);
981 log(L_DEBUG, "acx: booted eCPU up and waiting for completion...\n");
983 /* wait for eCPU bootup */
984 if (OK != acxpci_s_verify_init(adev)) {
985 msg = "acx: timeout waiting for eCPU. ";
986 goto end_fail;
988 log(L_DEBUG, "acx: eCPU has woken up, card is ready to be configured\n");
990 init_mboxes(adev);
991 acxpci_write_cmd_type_status(adev, 0, 0);
993 /* test that EEPROM is readable */
994 read_eeprom_area(adev);
996 result = OK;
997 goto end;
999 /* Finish error message. Indicate which function failed */
1000 end_unlock:
1001 acx_unlock(adev, flags);
1002 end_fail:
1003 printk("acx: %sreset_dev() FAILED\n", msg);
1004 end:
1005 FN_EXIT1(result);
1006 return result;
1010 /***********************************************************************
1011 ** acxpci_s_issue_cmd_timeo
1013 ** Sends command to fw, extract result
1015 ** NB: we do _not_ take lock inside, so be sure to not touch anything
1016 ** which may interfere with IRQ handler operation
1018 ** TODO: busy wait is a bit silly, so:
1019 ** 1) stop doing many iters - go to sleep after first
1020 ** 2) go to waitqueue based approach: wait, not poll!
1022 #undef FUNC
1023 #define FUNC "issue_cmd"
1025 #if !ACX_DEBUG
1027 acxpci_s_issue_cmd_timeo(acx_device_t * adev,
1028 unsigned int cmd,
1029 void *buffer, unsigned buflen, unsigned cmd_timeout)
1031 #else
1033 acxpci_s_issue_cmd_timeo_debug(acx_device_t * adev,
1034 unsigned cmd,
1035 void *buffer,
1036 unsigned buflen,
1037 unsigned cmd_timeout, const char *cmdstr)
1039 unsigned long start = jiffies;
1040 #endif
1041 const char *devname;
1042 unsigned counter;
1043 u16 irqtype;
1044 u16 cmd_status;
1045 unsigned long timeout;
1047 FN_ENTER;
1049 devname = wiphy_name(adev->ieee->wiphy);
1050 if (!devname || !devname[0] || devname[4] == '%')
1051 devname = "acx";
1053 log(L_CTL, FUNC "acx: (cmd:%s,buflen:%u,timeout:%ums,type:0x%04X)\n",
1054 cmdstr, buflen, cmd_timeout,
1055 buffer ? le16_to_cpu(((acx_ie_generic_t *) buffer)->type) : -1);
1057 if (!(adev->dev_state_mask & ACX_STATE_FW_LOADED)) {
1058 printk("acx: %s: " FUNC "(): firmware is not loaded yet, "
1059 "cannot execute commands!\n", devname);
1060 goto bad;
1063 if ((acx_debug & L_DEBUG) && (cmd != ACX1xx_CMD_INTERROGATE)) {
1064 printk("acx: input buffer (len=%u):\n", buflen);
1065 acx_dump_bytes(buffer, buflen);
1068 /* wait for firmware to become idle for our command submission */
1069 timeout = HZ / 5;
1070 counter = (timeout * 1000 / HZ) - 1; /* in ms */
1071 timeout += jiffies;
1072 do {
1073 cmd_status = acxpci_read_cmd_type_status(adev);
1074 /* Test for IDLE state */
1075 if (!cmd_status)
1076 break;
1077 if (counter % 8 == 0) {
1078 if (time_after(jiffies, timeout)) {
1079 counter = 0;
1080 break;
1082 /* we waited 8 iterations, no luck. Sleep 8 ms */
1083 acx_s_mwait(8);
1085 } while (likely(--counter));
1087 if (!counter) {
1088 /* the card doesn't get idle, we're in trouble */
1089 printk("acx: %s: " FUNC "(): cmd_status is not IDLE: 0x%04X!=0\n",
1090 devname, cmd_status);
1091 goto bad;
1092 } else if (counter < 190) { /* if waited >10ms... */
1093 log(L_CTL | L_DEBUG, "acx: " FUNC "(): waited for IDLE %dms. "
1094 "Please report\n", 199 - counter);
1097 /* now write the parameters of the command if needed */
1098 if (buffer && buflen) {
1099 /* if it's an INTERROGATE command, just pass the length
1100 * of parameters to read, as data */
1101 #if CMD_DISCOVERY
1102 if (cmd == ACX1xx_CMD_INTERROGATE)
1103 memset_io(adev->cmd_area + 4, 0xAA, buflen);
1104 #endif
1105 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1106 memcpy_toio(adev->cmd_area + 4, buffer,
1107 (cmd == ACX1xx_CMD_INTERROGATE) ? 4 : buflen);
1109 /* now write the actual command type */
1110 acxpci_write_cmd_type_status(adev, cmd, 0);
1111 /* execute command */
1112 write_reg16(adev, IO_ACX_INT_TRIG, INT_TRIG_CMD);
1113 write_flush(adev);
1115 /* wait for firmware to process command */
1117 /* Ensure nonzero and not too large timeout.
1118 ** Also converts e.g. 100->99, 200->199
1119 ** which is nice but not essential */
1120 cmd_timeout = (cmd_timeout - 1) | 1;
1121 if (unlikely(cmd_timeout > 1199))
1122 cmd_timeout = 1199;
1123 /* clear CMD_COMPLETE bit. can be set only by IRQ handler: */
1124 CLEAR_BIT(adev->irq_status, HOST_INT_CMD_COMPLETE);
1125 /* we schedule away sometimes (timeout can be large) */
1126 counter = cmd_timeout;
1127 timeout = jiffies + HZ;
1128 do {
1129 if (!adev->irqs_active) { /* IRQ disabled: poll */
1130 irqtype = read_reg16(adev, IO_ACX_IRQ_STATUS_NON_DES);
1131 if (irqtype & HOST_INT_CMD_COMPLETE) {
1132 write_reg16(adev, IO_ACX_IRQ_ACK,
1133 HOST_INT_CMD_COMPLETE);
1134 break;
1136 } else { /* Wait when IRQ will set the bit */
1137 irqtype = adev->irq_status;
1138 if (irqtype & HOST_INT_CMD_COMPLETE)
1139 break;
1142 if (counter % 8 == 0) {
1143 if (time_after(jiffies, timeout)) {
1144 counter = 0;
1145 break;
1147 /* we waited 8 iterations, no luck. Sleep 8 ms */
1148 acx_s_mwait(8);
1150 } while (likely(--counter));
1152 /* save state for debugging */
1153 cmd_status = acxpci_read_cmd_type_status(adev);
1155 /* put the card in IDLE state */
1156 acxpci_write_cmd_type_status(adev, 0, 0);
1158 if ((cmd_timeout - counter) == 0) { /* timed out! */
1159 printk("acx: %s: " FUNC "(): timed out %s for CMD_COMPLETE. "
1160 "irq bits:0x%04X irq_status:0x%04X timeout:%dms "
1161 "cmd_status:%d (%s)\n",
1162 devname, (adev->irqs_active) ? "waiting" : "polling",
1163 irqtype, adev->irq_status, cmd_timeout,
1164 cmd_status, acx_cmd_status_str(cmd_status));
1165 printk("acx: hack: don't do: 'goto bad;'\ncounter: %d cmd_timeout: %d cmd_timeout-counter: %d\n",counter, cmd_timeout, cmd_timeout - counter);
1166 } else if (counter == 0) { /* maybe timed out! */
1167 log(L_CTL | L_DEBUG, "acx: " FUNC "(): %s for CMD_COMPLETE %dms. "
1168 "count:%d. Please report\n",
1169 (adev->irqs_active) ? "waited" : "polled",
1170 cmd_timeout - counter, counter);
1171 } else if ((cmd_timeout - counter) > 30) { /* if waited >30ms... */
1172 log(L_CTL | L_DEBUG, "acx: " FUNC "(): %s for CMD_COMPLETE %dms. "
1173 "count:%d. Please report\n",
1174 (adev->irqs_active) ? "waited" : "polled",
1175 cmd_timeout - counter, counter);
1178 if (1 != cmd_status) { /* it is not a 'Success' */
1179 printk("acx: %s: " FUNC "(): cmd_status is not SUCCESS: %d (%s). "
1180 "Took %dms of %d\n",
1181 devname, cmd_status, acx_cmd_status_str(cmd_status),
1182 cmd_timeout - counter, cmd_timeout);
1183 /* zero out result buffer
1184 * WARNING: this will trash stack in case of illegally large input
1185 * length! */
1186 if (buffer && buflen)
1187 memset(buffer, 0, buflen);
1188 goto bad;
1191 /* read in result parameters if needed */
1192 if (buffer && buflen && (cmd == ACX1xx_CMD_INTERROGATE)) {
1193 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1194 memcpy_fromio(buffer, adev->cmd_area + 4, buflen);
1195 if (acx_debug & L_DEBUG) {
1196 printk("acx: output buffer (len=%u): ", buflen);
1197 acx_dump_bytes(buffer, buflen);
1200 /* ok: */
1201 log(L_CTL, "acx: " FUNC "(%s): took %ld jiffies to complete\n",
1202 cmdstr, jiffies - start);
1203 FN_EXIT1(OK);
1204 return OK;
1206 bad:
1207 /* Give enough info so that callers can avoid
1208 ** printing their own diagnostic messages */
1209 #if ACX_DEBUG
1210 printk("acx: %s: " FUNC "(cmd:%s) FAILED\n", devname, cmdstr);
1211 #else
1212 printk("acx: %s: " FUNC "(cmd:0x%04X) FAILED\n", devname, cmd);
1213 #endif
1214 dump_stack();
1215 FN_EXIT1(NOT_OK);
1216 return NOT_OK;
1220 /***********************************************************************
1222 #ifdef NONESSENTIAL_FEATURES
1223 typedef struct device_id {
1224 unsigned char id[6];
1225 char *descr;
1226 char *type;
1227 } device_id_t;
1229 static const device_id_t device_ids[] = {
1231 {'G', 'l', 'o', 'b', 'a', 'l'},
1232 NULL,
1233 NULL,
1236 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
1237 "uninitialized",
1238 "SpeedStream SS1021 or Gigafast WF721-AEX"},
1240 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85},
1241 "non-standard",
1242 "DrayTek Vigor 520"},
1244 {'?', '?', '?', '?', '?', '?'},
1245 "non-standard",
1246 "Level One WPC-0200"},
1248 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1249 "empty",
1250 "DWL-650+ variant"}
1253 static void acx_show_card_eeprom_id(acx_device_t * adev)
1255 unsigned char buffer[CARD_EEPROM_ID_SIZE];
1256 int i;
1258 FN_ENTER;
1260 memset(&buffer, 0, CARD_EEPROM_ID_SIZE);
1261 /* use direct EEPROM access */
1262 for (i = 0; i < CARD_EEPROM_ID_SIZE; i++) {
1263 if (OK != acxpci_read_eeprom_byte(adev,
1264 ACX100_EEPROM_ID_OFFSET + i,
1265 &buffer[i])) {
1266 printk("acx: reading EEPROM FAILED\n");
1267 break;
1271 for (i = 0; i < ARRAY_SIZE(device_ids); i++) {
1272 if (!memcmp(&buffer, device_ids[i].id, CARD_EEPROM_ID_SIZE)) {
1273 if (device_ids[i].descr) {
1274 printk("acx: EEPROM card ID string check "
1275 "found %s card ID: is this %s?\n",
1276 device_ids[i].descr, device_ids[i].type);
1278 break;
1281 if (i == ARRAY_SIZE(device_ids)) {
1282 printk("acx: EEPROM card ID string check found "
1283 "unknown card: expected 'Global', got '%.*s\'. "
1284 "Please report\n", CARD_EEPROM_ID_SIZE, buffer);
1286 FN_EXIT0;
1288 #endif /* NONESSENTIAL_FEATURES */
1291 /***********************************************************************
1292 ** acxpci_free_desc_queues
1294 ** Releases the queues that have been allocated, the
1295 ** others have been initialised to NULL so this
1296 ** function can be used if only part of the queues were allocated.
1299 static inline void
1300 free_coherent(struct pci_dev *hwdev, size_t size,
1301 void *vaddr, dma_addr_t dma_handle)
1303 dma_free_coherent(hwdev == NULL ? NULL : &hwdev->dev,
1304 size, vaddr, dma_handle);
1308 void acxpci_free_desc_queues(acx_device_t * adev)
1310 unsigned long flags;
1312 #define ACX_FREE_QUEUE(size, ptr, phyaddr) \
1313 if (ptr) { \
1314 free_coherent(NULL, size, ptr, phyaddr); \
1315 ptr = NULL; \
1316 size = 0; \
1319 FN_ENTER;
1321 ACX_FREE_QUEUE(adev->txhostdesc_area_size, adev->txhostdesc_start,
1322 adev->txhostdesc_startphy);
1323 ACX_FREE_QUEUE(adev->txbuf_area_size, adev->txbuf_start,
1324 adev->txbuf_startphy);
1326 acx_lock(adev, flags);
1327 adev->txdesc_start = NULL;
1328 acx_unlock(adev, flags);
1330 ACX_FREE_QUEUE(adev->rxhostdesc_area_size, adev->rxhostdesc_start,
1331 adev->rxhostdesc_startphy);
1332 ACX_FREE_QUEUE(adev->rxbuf_area_size, adev->rxbuf_start,
1333 adev->rxbuf_startphy);
1335 acx_lock(adev, flags);
1336 adev->rxdesc_start = NULL;
1337 acx_unlock(adev, flags);
1339 FN_EXIT0;
1343 /***********************************************************************
1344 ** acxpci_s_delete_dma_regions
1346 static void acxpci_s_delete_dma_regions(acx_device_t * adev)
1348 FN_ENTER;
1349 /* disable radio Tx/Rx. Shouldn't we use the firmware commands
1350 * here instead? Or are we that much down the road that it's no
1351 * longer possible here? */
1352 write_reg16(adev, IO_ACX_ENABLE, 0);
1354 acx_s_mwait(100);
1356 /* NO locking for all parts of acxpci_free_desc_queues because:
1357 * while calling dma_free_coherent() interrupts need to be 'free'
1358 * but if you spinlock the whole function (acxpci_free_desc_queues)
1359 * you'll get an error */
1360 acxpci_free_desc_queues(adev);
1362 FN_EXIT0;
1366 /***********************************************************************
1367 ** acxpci_e_probe
1369 ** Probe routine called when a PCI device w/ matching ID is found.
1370 ** Here's the sequence:
1371 ** - Allocate the PCI resources.
1372 ** - Read the PCMCIA attribute memory to make sure we have a WLAN card
1373 ** - Reset the MAC
1374 ** - Initialize the dev and wlan data
1375 ** - Initialize the MAC
1377 ** pdev - ptr to pci device structure containing info about pci configuration
1378 ** id - ptr to the device id entry that matched this device
1380 static const u16 IO_ACX100[] = {
1381 0x0000, /* IO_ACX_SOFT_RESET */
1383 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1384 0x0018, /* IO_ACX_SLV_MEM_DATA */
1385 0x001c, /* IO_ACX_SLV_MEM_CTL */
1386 0x0020, /* IO_ACX_SLV_END_CTL */
1388 0x0034, /* IO_ACX_FEMR */
1390 0x007c, /* IO_ACX_INT_TRIG */
1391 0x0098, /* IO_ACX_IRQ_MASK */
1392 0x00a4, /* IO_ACX_IRQ_STATUS_NON_DES */
1393 0x00a8, /* IO_ACX_IRQ_REASON */
1394 0x00ac, /* IO_ACX_IRQ_ACK */
1395 0x00b0, /* IO_ACX_HINT_TRIG */
1397 0x0104, /* IO_ACX_ENABLE */
1399 0x0250, /* IO_ACX_EEPROM_CTL */
1400 0x0254, /* IO_ACX_EEPROM_ADDR */
1401 0x0258, /* IO_ACX_EEPROM_DATA */
1402 0x025c, /* IO_ACX_EEPROM_CFG */
1404 0x0268, /* IO_ACX_PHY_ADDR */
1405 0x026c, /* IO_ACX_PHY_DATA */
1406 0x0270, /* IO_ACX_PHY_CTL */
1408 0x0290, /* IO_ACX_GPIO_OE */
1410 0x0298, /* IO_ACX_GPIO_OUT */
1412 0x02a4, /* IO_ACX_CMD_MAILBOX_OFFS */
1413 0x02a8, /* IO_ACX_INFO_MAILBOX_OFFS */
1414 0x02ac, /* IO_ACX_EEPROM_INFORMATION */
1416 0x02d0, /* IO_ACX_EE_START */
1417 0x02d4, /* IO_ACX_SOR_CFG */
1418 0x02d8 /* IO_ACX_ECPU_CTRL */
1421 static const u16 IO_ACX111[] = {
1422 0x0000, /* IO_ACX_SOFT_RESET */
1424 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1425 0x0018, /* IO_ACX_SLV_MEM_DATA */
1426 0x001c, /* IO_ACX_SLV_MEM_CTL */
1427 0x0020, /* IO_ACX_SLV_END_CTL */
1429 0x0034, /* IO_ACX_FEMR */
1431 0x00b4, /* IO_ACX_INT_TRIG */
1432 0x00d4, /* IO_ACX_IRQ_MASK */
1433 /* we do mean NON_DES (0xf0), not NON_DES_MASK which is at 0xe0: */
1434 0x00f0, /* IO_ACX_IRQ_STATUS_NON_DES */
1435 0x00e4, /* IO_ACX_IRQ_REASON */
1436 0x00e8, /* IO_ACX_IRQ_ACK */
1437 0x00ec, /* IO_ACX_HINT_TRIG */
1439 0x01d0, /* IO_ACX_ENABLE */
1441 0x0338, /* IO_ACX_EEPROM_CTL */
1442 0x033c, /* IO_ACX_EEPROM_ADDR */
1443 0x0340, /* IO_ACX_EEPROM_DATA */
1444 0x0344, /* IO_ACX_EEPROM_CFG */
1446 0x0350, /* IO_ACX_PHY_ADDR */
1447 0x0354, /* IO_ACX_PHY_DATA */
1448 0x0358, /* IO_ACX_PHY_CTL */
1450 0x0374, /* IO_ACX_GPIO_OE */
1452 0x037c, /* IO_ACX_GPIO_OUT */
1454 0x0388, /* IO_ACX_CMD_MAILBOX_OFFS */
1455 0x038c, /* IO_ACX_INFO_MAILBOX_OFFS */
1456 0x0390, /* IO_ACX_EEPROM_INFORMATION */
1458 0x0100, /* IO_ACX_EE_START */
1459 0x0104, /* IO_ACX_SOR_CFG */
1460 0x0108, /* IO_ACX_ECPU_CTRL */
1463 static const struct ieee80211_ops acxpci_hw_ops = {
1464 .tx = acx_i_start_xmit,
1465 .conf_tx = acx_net_conf_tx,
1466 .add_interface = acx_add_interface,
1467 .remove_interface = acx_remove_interface,
1468 .start = acxpci_e_open,
1469 .configure_filter = acx_i_set_multicast_list,
1470 .stop = acxpci_e_close,
1471 .config = acx_net_config,
1472 .config_interface = acx_config_interface,
1473 .set_key = acx_net_set_key,
1474 .get_stats = acx_e_get_stats,
1475 .get_tx_stats = acx_net_get_tx_stats,
1479 #ifdef CONFIG_PCI
1480 static int __devinit
1481 acxpci_e_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1483 acx111_ie_configoption_t co;
1484 unsigned long mem_region1 = 0;
1485 unsigned long mem_region2 = 0;
1486 unsigned long mem_region1_size;
1487 unsigned long mem_region2_size;
1488 unsigned long phymem1;
1489 unsigned long phymem2;
1490 void *mem1 = NULL;
1491 void *mem2 = NULL;
1492 acx_device_t *adev = NULL;
1493 const char *chip_name;
1494 int result = -EIO;
1495 int err;
1496 u8 chip_type;
1497 struct ieee80211_hw *ieee;
1499 FN_ENTER;
1501 ieee = ieee80211_alloc_hw(sizeof(struct acx_device), &acxpci_hw_ops);
1502 if (!ieee) {
1503 printk("acx: could not allocate ieee80211 structure %s\n",
1504 pci_name(pdev));
1505 goto fail_alloc_netdev;
1507 ieee->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
1508 /* TODO: mainline doesn't support the following flags yet */
1510 ~IEEE80211_HW_MONITOR_DURING_OPER &
1511 ~IEEE80211_HW_WEP_INCLUDE_IV;
1513 ieee->queues = 1;
1515 /* TODO: although in the original driver the maximum value was 100,
1516 * the OpenBSD driver assigns maximum values depending on the type of
1517 * radio transceiver (i.e. Radia, Maxim, etc.). This value is always a
1518 * positive integer which most probably indicates the gain of the AGC
1519 * in the rx path of the chip, in dB steps (0.625 dB, for example?).
1520 * The mapping of this rssi value to dBm is still unknown, but it can
1521 * nevertheless be used as a measure of relative signal strength. The
1522 * other two values, i.e. max_signal and max_noise, do not seem to be
1523 * supported on my acx111 card (they are always 0), although iwconfig
1524 * reports them (in dBm) when using ndiswrapper with the Windows XP
1525 * driver. The GPL-licensed part of the AVM FRITZ!WLAN USB Stick
1526 * driver sources (for the TNETW1450, though) seems to also indicate
1527 * that only the RSSI is supported. In conclusion, the max_signal and
1528 * max_noise values will not be initialised by now, as they do not
1529 * seem to be supported or how to acquire them is still unknown. */
1530 ieee->max_rssi = 100;
1532 adev = ieee2adev(ieee);
1534 memset(adev, 0, sizeof(*adev));
1535 /** Set up our private interface **/
1536 spin_lock_init(&adev->spinlock); /* initial state: unlocked */
1537 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
1538 printk("acx: mutex_init(&adev->mutex); // adev = 0x%px\n", adev);
1539 mutex_init(&adev->mutex);
1540 /* since nobody can see new netdev yet, we can as well
1541 ** just _presume_ that we're under sem (instead of actually taking it): */
1542 /* acx_sem_lock(adev); */
1543 adev->ieee = ieee;
1544 adev->pdev = pdev;
1545 adev->bus_dev = &pdev->dev;
1546 adev->dev_type = DEVTYPE_PCI;
1548 /** Finished with private interface **/
1550 /** begin board specific inits **/
1551 pci_set_drvdata(pdev, ieee);
1553 /* Enable the PCI device */
1554 if (pci_enable_device(pdev)) {
1555 printk("acx: pci_enable_device() FAILED\n");
1556 result = -ENODEV;
1557 goto fail_pci_enable_device;
1560 /* enable busmastering (required for CardBus) */
1561 pci_set_master(pdev);
1564 /* chiptype is u8 but id->driver_data is ulong
1565 ** Works for now (possible values are 1 and 2) */
1566 chip_type = (u8) id->driver_data;
1567 /* acx100 and acx111 have different PCI memory regions */
1568 if (chip_type == CHIPTYPE_ACX100) {
1569 chip_name = "ACX100";
1570 mem_region1 = PCI_ACX100_REGION1;
1571 mem_region1_size = PCI_ACX100_REGION1_SIZE;
1573 mem_region2 = PCI_ACX100_REGION2;
1574 mem_region2_size = PCI_ACX100_REGION2_SIZE;
1575 } else if (chip_type == CHIPTYPE_ACX111) {
1576 chip_name = "ACX111";
1577 mem_region1 = PCI_ACX111_REGION1;
1578 mem_region1_size = PCI_ACX111_REGION1_SIZE;
1580 mem_region2 = PCI_ACX111_REGION2;
1581 mem_region2_size = PCI_ACX111_REGION2_SIZE;
1582 } else {
1583 printk("acx: unknown chip type 0x%04X\n", chip_type);
1584 goto fail_unknown_chiptype;
1587 /* Figure out our resources
1589 * Request our PCI IO regions
1591 err = pci_request_region(pdev, mem_region1, "acx_1");
1592 if (err) {
1593 printk(KERN_WARNING "acx: pci_request_region (1/2) FAILED!"
1594 "No cardbus support in kernel?\n");
1595 goto fail_request_mem_region1;
1598 phymem1 = pci_resource_start(pdev, mem_region1);
1600 err = pci_request_region(pdev, mem_region2, "acx_2");
1601 if (err) {
1602 printk(KERN_WARNING "acx: pci_request_region (2/2) FAILED!\n");
1603 goto fail_request_mem_region2;
1606 phymem2 = pci_resource_start(pdev, mem_region2);
1609 * We got them? Map them!
1611 * We pass 0 as the third argument to pci_iomap(): it will map the full
1612 * region in this case, which is what we want.
1615 mem1 = pci_iomap(pdev, mem_region1, 0);
1616 if (!mem1) {
1617 printk(KERN_WARNING "acx: ioremap() FAILED\n");
1618 goto fail_ioremap1;
1621 mem2 = pci_iomap(pdev, mem_region2, 0);
1622 if (!mem2) {
1623 printk(KERN_WARNING "acx: ioremap() #2 FAILED\n");
1624 goto fail_ioremap2;
1627 printk("acx: found an %s-based wireless network card at %s, irq:%d, "
1628 "phymem1:0x%lX, phymem2:0x%lX, mem1:0x%p, mem1_size:%ld, "
1629 "mem2:0x%p, mem2_size:%ld\n",
1630 chip_name, pci_name(pdev), pdev->irq, phymem1, phymem2,
1631 mem1, mem_region1_size, mem2, mem_region2_size);
1632 log(L_ANY, "acx: the initial debug setting is 0x%04X\n", acx_debug);
1633 adev->chip_type = chip_type;
1634 adev->chip_name = chip_name;
1635 adev->io = (CHIPTYPE_ACX100 == chip_type) ? IO_ACX100 : IO_ACX111;
1636 adev->membase = phymem1;
1637 adev->iobase = mem1;
1638 adev->membase2 = phymem2;
1639 adev->iobase2 = mem2;
1640 adev->irq = pdev->irq;
1643 if (0 == pdev->irq) {
1644 printk("acx: can't use IRQ 0\n");
1645 goto fail_irq;
1647 SET_IEEE80211_DEV(ieee, &pdev->dev);
1649 /* request shared IRQ handler */
1650 if (request_irq
1651 (adev->irq, acxpci_i_interrupt, IRQF_SHARED, KBUILD_MODNAME, adev)) {
1652 printk("acx: %s: request_irq FAILED\n", wiphy_name(adev->ieee->wiphy));
1653 result = -EAGAIN;
1654 goto done;
1656 log(L_DEBUG | L_IRQ, "acx: request_irq %d successful\n", adev->irq);
1658 /* to find crashes due to weird driver access
1659 * to unconfigured interface (ifup) */
1660 adev->mgmt_timer.function = (void (*)(unsigned long))0x0000dead;
1663 #ifdef NONESSENTIAL_FEATURES
1664 acx_show_card_eeprom_id(adev);
1665 #endif /* NONESSENTIAL_FEATURES */
1668 /* ok, pci setup is finished, now start initializing the card */
1670 /* NB: read_reg() reads may return bogus data before reset_dev(),
1671 * since the firmware which directly controls large parts of the I/O
1672 * registers isn't initialized yet.
1673 * acx100 seems to be more affected than acx111 */
1674 if (OK != acxpci_s_reset_dev(adev))
1675 goto fail_reset;
1677 if (IS_ACX100(adev)) {
1678 /* ACX100: configopt struct in cmd mailbox - directly after reset */
1679 memcpy_fromio(&co, adev->cmd_area, sizeof(co));
1682 if (OK != acx_s_init_mac(adev))
1683 goto fail_init_mac;
1685 if (IS_ACX111(adev)) {
1686 /* ACX111: configopt struct needs to be queried after full init */
1687 acx_s_interrogate(adev, &co, ACX111_IE_CONFIG_OPTIONS);
1689 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
1690 if (OK != acxpci_read_eeprom_byte(adev, 0x05, &adev->eeprom_version))
1691 goto fail_read_eeprom_version;
1693 acx_s_parse_configoption(adev, &co);
1694 acx_s_set_defaults(adev);
1695 acx_s_get_firmware_version(adev); /* needs to be after acx_s_init_mac() */
1696 acx_display_hardware_details(adev);
1698 /* Register the card, AFTER everything else has been set up,
1699 * since otherwise an ioctl could step on our feet due to
1700 * firmware operations happening in parallel or uninitialized data */
1703 acx_proc_register_entries(ieee);
1705 /* Now we have our device, so make sure the kernel doesn't try
1706 * to send packets even though we're not associated to a network yet */
1708 /* after register_netdev() userspace may start working with dev
1709 * (in particular, on other CPUs), we only need to up the sem */
1710 /* acx_sem_unlock(adev); */
1712 printk("acx: acx " ACX_RELEASE ": net device %s, driver compiled "
1713 "against wireless extensions %d and Linux %s\n",
1714 wiphy_name(adev->ieee->wiphy), WIRELESS_EXT, UTS_RELEASE);
1716 MAC_COPY(adev->ieee->wiphy->perm_addr, adev->dev_addr);
1718 log(L_IRQ | L_INIT, "acx: using IRQ %d\n", pdev->irq);
1720 /** done with board specific setup **/
1722 /* need to be able to restore PCI state after a suspend */
1723 #ifdef CONFIG_PM
1724 pci_save_state(pdev);
1725 #endif
1727 err = acx_setup_modes(adev);
1728 if (err) {
1729 printk("acx: can't register hwmode\n");
1730 goto fail_register_netdev;
1733 acx_init_task_scheduler(adev);
1734 err = ieee80211_register_hw(ieee);
1735 if (OK != err) {
1736 printk("acx: ieee80211_register_hw() FAILED: %d\n", err);
1737 goto fail_register_netdev;
1739 #if CMD_DISCOVERY
1740 great_inquisitor(adev);
1741 #endif
1743 result = OK;
1744 goto done;
1746 /* error paths: undo everything in reverse order... */
1749 acxpci_s_delete_dma_regions(adev);
1750 pci_set_drvdata(pdev, NULL);
1752 fail_init_mac:
1753 fail_read_eeprom_version:
1754 fail_reset:
1756 fail_alloc_netdev:
1757 fail_irq:
1758 pci_iounmap(pdev, mem2);
1760 fail_ioremap2:
1761 pci_iounmap(pdev, mem1);
1763 fail_ioremap1:
1764 pci_release_region(pdev, mem_region2);
1766 fail_request_mem_region2:
1767 pci_release_region(pdev, mem_region1);
1769 fail_request_mem_region1:
1770 fail_unknown_chiptype:
1771 pci_disable_device(pdev);
1773 fail_pci_enable_device:
1774 #ifdef CONFIG_PM
1775 pci_set_power_state(pdev, PCI_D3hot);
1776 #endif
1778 fail_register_netdev:
1779 ieee80211_free_hw(ieee);
1780 done:
1781 FN_EXIT1(result);
1782 return result;
1786 /***********************************************************************
1787 ** acxpci_e_remove
1789 ** Shut device down (if not hot unplugged)
1790 ** and deallocate PCI resources for the acx chip.
1792 ** pdev - ptr to PCI device structure containing info about pci configuration
1794 static void __devexit acxpci_e_remove(struct pci_dev *pdev)
1796 struct ieee80211_hw *hw = (struct ieee80211_hw *)pci_get_drvdata(pdev);
1797 acx_device_t *adev = ieee2adev(hw);
1798 unsigned long mem_region1, mem_region2;
1799 unsigned long flags;
1800 FN_ENTER;
1802 if (!hw) {
1803 log(L_DEBUG, "acx: %s: card is unused. Skipping any release code\n",
1804 __func__);
1805 goto end;
1808 /* If device wasn't hot unplugged... */
1809 if (adev_present(adev)) {
1811 /* disable both Tx and Rx to shut radio down properly */
1812 if (adev->initialized) {
1813 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_TX, NULL, 0);
1814 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_RX, NULL, 0);
1815 adev->initialized = 0;
1817 #ifdef REDUNDANT
1818 /* put the eCPU to sleep to save power
1819 * Halting is not possible currently,
1820 * since not supported by all firmware versions */
1821 acx_s_issue_cmd(adev, ACX100_CMD_SLEEP, NULL, 0);
1822 #endif
1823 acx_lock(adev, flags);
1824 /* disable power LED to save power :-) */
1825 log(L_INIT, "acx: switching off power LED to save power\n");
1826 acxpci_l_power_led(adev, 0);
1827 /* stop our eCPU */
1828 if (IS_ACX111(adev)) {
1829 /* FIXME: does this actually keep halting the eCPU?
1830 * I don't think so...
1832 acxpci_l_reset_mac(adev);
1833 } else {
1834 u16 temp;
1835 /* halt eCPU */
1836 temp = read_reg16(adev, IO_ACX_ECPU_CTRL) | 0x1;
1837 write_reg16(adev, IO_ACX_ECPU_CTRL, temp);
1838 write_flush(adev);
1840 acx_unlock(adev, flags);
1844 /* unregister the device to not let the kernel
1845 * (e.g. ioctls) access a half-deconfigured device
1846 * NB: this will cause acxpci_e_close() to be called,
1847 * thus we shouldn't call it under sem!
1849 // acxpci_e_close(hw);
1850 log(L_INIT, "acx: removing device %s\n", wiphy_name(adev->ieee->wiphy));
1851 ieee80211_unregister_hw(adev->ieee);
1853 /* unregister_netdev ensures that no references to us left.
1854 * For paranoid reasons we continue to follow the rules */
1855 acx_sem_lock(adev);
1857 if (adev->dev_state_mask & ACX_STATE_IFACE_UP) {
1858 acxpci_s_down(hw);
1859 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
1862 acx_proc_unregister_entries(adev->ieee);
1864 if (IS_ACX100(adev)) {
1865 mem_region1 = PCI_ACX100_REGION1;
1866 mem_region2 = PCI_ACX100_REGION2;
1867 } else {
1868 mem_region1 = PCI_ACX111_REGION1;
1869 mem_region2 = PCI_ACX111_REGION2;
1872 /* finally, clean up PCI bus state */
1873 acxpci_s_delete_dma_regions(adev);
1874 if (adev->iobase)
1875 iounmap(adev->iobase);
1876 if (adev->iobase2)
1877 iounmap(adev->iobase2);
1878 release_mem_region(pci_resource_start(pdev, mem_region1),
1879 pci_resource_len(pdev, mem_region1));
1880 release_mem_region(pci_resource_start(pdev, mem_region2),
1881 pci_resource_len(pdev, mem_region2));
1882 pci_disable_device(pdev);
1884 /* remove dev registration */
1885 pci_set_drvdata(pdev, NULL);
1887 acx_sem_unlock(adev);
1889 /* Free netdev (quite late,
1890 * since otherwise we might get caught off-guard
1891 * by a netdev timeout handler execution
1892 * expecting to see a working dev...) */
1893 ieee80211_free_hw(adev->ieee);
1895 /* put device into ACPI D3 mode (shutdown) */
1896 #ifdef CONFIG_PM
1897 pci_set_power_state(pdev, PCI_D3hot);
1898 #endif
1899 end:
1900 FN_EXIT0;
1904 /***********************************************************************
1905 ** TODO: PM code needs to be fixed / debugged / tested.
1907 #ifdef CONFIG_PM
1908 static int
1909 acxpci_e_suspend(struct pci_dev *pdev, pm_message_t state)
1911 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1912 acx_device_t *adev;
1914 FN_ENTER;
1915 printk("acx: suspend handler is experimental!\n");
1916 printk("acx: sus: dev %p\n", hw);
1918 /* if (!netif_running(ndev))
1919 goto end;
1921 adev = ieee2adev(hw);
1922 printk("acx: sus: adev %p\n", adev);
1924 acx_sem_lock(adev);
1926 ieee80211_unregister_hw(hw); /* this one cannot sleep */
1927 acxpci_s_down(hw);
1928 /* down() does not set it to 0xffff, but here we really want that */
1929 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
1930 write_reg16(adev, IO_ACX_FEMR, 0x0);
1931 acxpci_s_delete_dma_regions(adev);
1932 pci_save_state(pdev);
1933 pci_set_power_state(pdev, PCI_D3hot);
1935 acx_sem_unlock(adev);
1936 FN_EXIT0;
1937 return OK;
1941 static int acxpci_e_resume(struct pci_dev *pdev)
1943 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1944 acx_device_t *adev;
1946 FN_ENTER;
1948 printk("acx: resume handler is experimental!\n");
1949 printk("acx: rsm: got dev %p\n", hw);
1952 adev = ieee2adev(hw);
1953 printk("acx: rsm: got adev %p\n", adev);
1955 acx_sem_lock(adev);
1957 pci_set_power_state(pdev, PCI_D0);
1958 printk("acx: rsm: power state PCI_D0 set\n");
1959 pci_restore_state(pdev);
1960 printk("acx: rsm: PCI state restored\n");
1962 if (OK != acxpci_s_reset_dev(adev))
1963 goto end_unlock;
1964 printk("acx: rsm: device reset done\n");
1965 if (OK != acx_s_init_mac(adev))
1966 goto end_unlock;
1967 printk("acx: rsm: init MAC done\n");
1969 acxpci_s_up(hw);
1970 printk("acx: rsm: acx up done\n");
1972 /* now even reload all card parameters as they were before suspend,
1973 * and possibly be back in the network again already :-) */
1974 if (ACX_STATE_IFACE_UP & adev->dev_state_mask) {
1975 adev->set_mask = GETSET_ALL;
1976 acx_s_update_card_settings(adev);
1977 printk("acx: rsm: settings updated\n");
1979 ieee80211_register_hw(hw);
1980 printk("acx: rsm: device attached\n");
1982 end_unlock:
1983 acx_sem_unlock(adev);
1984 /* we need to return OK here anyway, right? */
1985 FN_EXIT0;
1986 return OK;
1988 #endif /* CONFIG_PM */
1989 #endif /* CONFIG_PCI */
1991 /***********************************************************************
1992 ** acxpci_s_up
1994 ** This function is called by acxpci_e_open (when ifconfig sets the device as up)
1996 ** Side effects:
1997 ** - Enables on-card interrupt requests
1998 ** - calls acx_s_start
2001 static void enable_acx_irq(acx_device_t * adev)
2003 FN_ENTER;
2004 write_reg16(adev, IO_ACX_IRQ_MASK, adev->irq_mask);
2005 write_reg16(adev, IO_ACX_FEMR, 0x8000);
2006 adev->irqs_active = 1;
2007 FN_EXIT0;
2010 static void acxpci_s_up(struct ieee80211_hw *hw)
2012 acx_device_t *adev = ieee2adev(hw);
2013 unsigned long flags;
2015 FN_ENTER;
2017 acx_lock(adev, flags);
2018 enable_acx_irq(adev);
2019 acx_unlock(adev, flags);
2021 /* acx fw < 1.9.3.e has a hardware timer, and older drivers
2022 ** used to use it. But we don't do that anymore, our OS
2023 ** has reliable software timers */
2024 init_timer(&adev->mgmt_timer);
2025 adev->mgmt_timer.function = acx_i_timer;
2026 adev->mgmt_timer.data = (unsigned long)adev;
2028 /* Need to set ACX_STATE_IFACE_UP first, or else
2029 ** timer won't be started by acx_set_status() */
2030 SET_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
2032 acx_s_start(adev);
2034 FN_EXIT0;
2038 /***********************************************************************
2039 ** acxpci_s_down
2041 ** NB: device may be already hot unplugged if called from acxpci_e_remove()
2043 ** Disables on-card interrupt request, stops softirq and timer, stops queue,
2044 ** sets status == STOPPED
2047 static void disable_acx_irq(acx_device_t * adev)
2049 FN_ENTER;
2051 /* I guess mask is not 0xffff because acx100 won't signal
2052 ** cmd completion then (needed for ifup).
2053 ** I can't ifconfig up after ifconfig down'ing on my acx100 */
2054 write_reg16(adev, IO_ACX_IRQ_MASK, adev->irq_mask_off);
2055 write_reg16(adev, IO_ACX_FEMR, 0x0);
2056 adev->irqs_active = 0;
2058 FN_EXIT0;
2061 static void acxpci_s_down(struct ieee80211_hw *hw)
2063 acx_device_t *adev = ieee2adev(hw);
2065 FN_ENTER;
2067 /* Disable IRQs first, so that IRQs cannot race with us */
2068 /* then wait until interrupts have finished executing on other CPUs */
2069 disable_acx_irq(adev); /* NO sem-locking here? */
2070 synchronize_irq(adev->irq);
2072 /* we really don't want to have an asynchronous tasklet disturb us
2073 ** after something vital for its job has been shut down, so
2074 ** end all remaining work now.
2076 ** NB: carrier_off (done by set_status below) would lead to
2077 ** not yet fully understood deadlock in flush_scheduled_work().
2078 ** That's why we do FLUSH first.
2080 ** NB2: we have a bad locking bug here: flush_scheduled_work()
2081 ** waits for acx_e_after_interrupt_task to complete if it is running
2082 ** on another CPU, but acx_e_after_interrupt_task
2083 ** will sleep on sem forever, because it is taken by us!
2084 ** Work around that by temporary sem unlock.
2085 ** This will fail miserably if we'll be hit by concurrent
2086 ** iwconfig or something in between. TODO! */
2087 acx_sem_unlock(adev);
2088 flush_scheduled_work();
2089 acx_sem_lock(adev);
2091 /* This is possible:
2092 ** flush_scheduled_work -> acx_e_after_interrupt_task ->
2093 ** -> set_status(ASSOCIATED) -> wake_queue()
2094 ** That's why we stop queue _after_ flush_scheduled_work
2095 ** lock/unlock is just paranoia, maybe not needed */
2097 /* kernel/timer.c says it's illegal to del_timer_sync()
2098 ** a timer which restarts itself. We guarantee this cannot
2099 ** ever happen because acx_i_timer() never does this if
2100 ** status is ACX_STATUS_0_STOPPED */
2101 del_timer_sync(&adev->mgmt_timer);
2103 FN_EXIT0;
2106 #ifdef CONFIG_NET_POLL_CONTROLLER
2107 void acxpci_net_poll_controller(struct net_device *net_dev)
2109 acx_device_t *adev = ndev2adev(net_dev);
2110 unsigned long flags;
2112 local_irq_save(flags);
2113 acxpci_i_interrupt(adev->irq, adev);
2114 local_irq_restore(flags);
2116 #endif*/ /* CONFIG_NET_POLL_CONTROLLER */
2118 /***********************************************************************
2119 ** acxpci_e_open
2121 ** Called as a result of SIOCSIFFLAGS ioctl changing the flags bit IFF_UP
2122 ** from clear to set. In other words: ifconfig up.
2124 ** Returns:
2125 ** 0 success
2126 ** >0 f/w reported error
2127 ** <0 driver reported error
2129 static int acxpci_e_open(struct ieee80211_hw *hw)
2131 acx_device_t *adev = ieee2adev(hw);
2132 int result = OK;
2134 FN_ENTER;
2136 acx_sem_lock(adev);
2138 adev->initialized = 0;
2140 /* TODO: pci_set_power_state(pdev, PCI_D0); ? */
2142 /* ifup device */
2143 acxpci_s_up(hw);
2145 /* We don't currently have to do anything else.
2146 * The setup of the MAC should be subsequently completed via
2147 * the mlme commands.
2148 * Higher layers know we're ready from dev->start==1 and
2149 * dev->tbusy==0. Our rx path knows to pass up received/
2150 * frames because of dev->flags&IFF_UP is true.
2152 ieee80211_start_queues(adev->ieee);
2154 adev->initialized = 1;
2155 acx_sem_unlock(adev);
2157 FN_EXIT1(result);
2158 return result;
2162 /***********************************************************************
2163 ** acxpci_e_close
2165 ** This function stops the network functionality of the interface (invoked
2166 ** when the user calls ifconfig <wlan> down). The tx queue is halted and
2167 ** the device is marked as down.
2169 ** Called as a result of SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
2170 ** from set to clear. I.e. called by "ifconfig DEV down"
2172 ** Returns:
2173 ** 0 success
2174 ** >0 f/w reported error
2175 ** <0 driver reported error
2177 static void acxpci_e_close(struct ieee80211_hw *hw)
2179 acx_device_t *adev = ieee2adev(hw);
2181 FN_ENTER;
2183 acx_sem_lock(adev);
2185 /* ifdown device */
2186 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
2187 if (adev->initialized) {
2188 acxpci_s_down(hw);
2191 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,24)
2192 if (adev->modes)
2193 acx_free_modes(adev);
2194 #endif
2195 /* disable all IRQs, release shared IRQ handler */
2196 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
2197 write_reg16(adev, IO_ACX_FEMR, 0x0);
2199 /* TODO: pci_set_power_state(pdev, PCI_D3hot); ? */
2201 /* We currently don't have to do anything else.
2202 * Higher layers know we're not ready from dev->start==0 and
2203 * dev->tbusy==1. Our rx path knows to not pass up received
2204 * frames because of dev->flags&IFF_UP is false.
2206 acx_sem_unlock(adev);
2208 log(L_INIT, "acx: closed device\n");
2209 FN_EXIT0;
2215 /***************************************************************
2216 ** acxpci_l_process_rxdesc
2218 ** Called directly and only from the IRQ handler
2221 #if !ACX_DEBUG
2222 static inline void log_rxbuffer(const acx_device_t * adev)
2225 #else
2226 static void log_rxbuffer(const acx_device_t * adev)
2228 register const struct rxhostdesc *rxhostdesc;
2229 int i;
2231 /* no FN_ENTER here, we don't want that */
2233 rxhostdesc = adev->rxhostdesc_start;
2234 if (unlikely(!rxhostdesc))
2235 return;
2236 for (i = 0; i < RX_CNT; i++) {
2237 if ((rxhostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2238 && (rxhostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2239 printk("acx: rx: buf %d full\n", i);
2240 rxhostdesc++;
2243 #endif
2245 static void acxpci_l_process_rxdesc(acx_device_t * adev)
2247 register rxhostdesc_t *hostdesc;
2248 unsigned count, tail;
2250 FN_ENTER;
2252 if (unlikely(acx_debug & L_BUFR))
2253 log_rxbuffer(adev);
2255 /* First, have a loop to determine the first descriptor that's
2256 * full, just in case there's a mismatch between our current
2257 * rx_tail and the full descriptor we're supposed to handle. */
2258 tail = adev->rx_tail;
2259 count = RX_CNT;
2260 while (1) {
2261 hostdesc = &adev->rxhostdesc_start[tail];
2262 /* advance tail regardless of outcome of the below test */
2263 tail = (tail + 1) % RX_CNT;
2265 if ((hostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2266 && (hostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2267 break; /* found it! */
2269 if (unlikely(!--count)) /* hmm, no luck: all descs empty, bail out */
2270 goto end;
2273 /* now process descriptors, starting with the first we figured out */
2274 while (1) {
2275 log(L_BUFR, "acx: rx: tail=%u Ctl_16=%04X Status=%08X\n",
2276 tail, hostdesc->Ctl_16, hostdesc->Status);
2278 acx_l_process_rxbuf(adev, hostdesc->data);
2279 hostdesc->Status = 0;
2280 /* flush all writes before adapter sees CTL_HOSTOWN change */
2281 wmb();
2282 /* Host no longer owns this, needs to be LAST */
2283 CLEAR_BIT(hostdesc->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
2285 /* ok, descriptor is handled, now check the next descriptor */
2286 hostdesc = &adev->rxhostdesc_start[tail];
2288 /* if next descriptor is empty, then bail out */
2289 if (!(hostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2290 || !(hostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2291 break;
2293 tail = (tail + 1) % RX_CNT;
2295 end:
2296 adev->rx_tail = tail;
2297 FN_EXIT0;
2302 /***********************************************************************
2303 ** acxpci_i_interrupt
2305 ** IRQ handler (atomic context, must not sleep, blah, blah)
2308 /* scan is complete. all frames now on the receive queue are valid */
2309 #define INFO_SCAN_COMPLETE 0x0001
2310 #define INFO_WEP_KEY_NOT_FOUND 0x0002
2311 /* hw has been reset as the result of a watchdog timer timeout */
2312 #define INFO_WATCH_DOG_RESET 0x0003
2313 /* failed to send out NULL frame from PS mode notification to AP */
2314 /* recommended action: try entering 802.11 PS mode again */
2315 #define INFO_PS_FAIL 0x0004
2316 /* encryption/decryption process on a packet failed */
2317 #define INFO_IV_ICV_FAILURE 0x0005
2319 /* Info mailbox format:
2320 2 bytes: type
2321 2 bytes: status
2322 more bytes may follow
2323 rumors say about status:
2324 0x0000 info available (set by hw)
2325 0x0001 information received (must be set by host)
2326 0x1000 info available, mailbox overflowed (messages lost) (set by hw)
2327 but in practice we've seen:
2328 0x9000 when we did not set status to 0x0001 on prev message
2329 0x1001 when we did set it
2330 0x0000 was never seen
2331 conclusion: this is really a bitfield:
2332 0x1000 is 'info available' bit
2333 'mailbox overflowed' bit is 0x8000, not 0x1000
2334 value of 0x0000 probably means that there are no messages at all
2335 P.S. I dunno how in hell hw is supposed to notice that messages are lost -
2336 it does NOT clear bit 0x0001, and this bit will probably stay forever set
2337 after we set it once. Let's hope this will be fixed in firmware someday
2340 static void handle_info_irq(acx_device_t * adev)
2342 #if ACX_DEBUG
2343 static const char *const info_type_msg[] = {
2344 "(unknown)",
2345 "scan complete",
2346 "WEP key not found",
2347 "internal watchdog reset was done",
2348 "failed to send powersave (NULL frame) notification to AP",
2349 "encrypt/decrypt on a packet has failed",
2350 "TKIP tx keys disabled",
2351 "TKIP rx keys disabled",
2352 "TKIP rx: key ID not found",
2353 "???",
2354 "???",
2355 "???",
2356 "???",
2357 "???",
2358 "???",
2359 "???",
2360 "TKIP IV value exceeds thresh"
2362 #endif
2363 u32 info_type, info_status;
2365 info_type = acx_readl(adev->info_area);
2366 info_status = (info_type >> 16);
2367 info_type = (u16) info_type;
2369 /* inform fw that we have read this info message */
2370 acx_writel(info_type | 0x00010000, adev->info_area);
2371 write_reg16(adev, IO_ACX_INT_TRIG, INT_TRIG_INFOACK);
2372 write_flush(adev);
2374 log(L_CTL, "acx: info_type:%04X info_status:%04X\n", info_type, info_status);
2376 log(L_IRQ, "acx: got Info IRQ: status %04X type %04X: %s\n",
2377 info_status, info_type,
2378 info_type_msg[(info_type >= ARRAY_SIZE(info_type_msg)) ?
2379 0 : info_type]
2384 static void log_unusual_irq(u16 irqtype)
2387 if (!printk_ratelimit())
2388 return;
2391 printk("acx: got");
2392 if (irqtype & HOST_INT_RX_DATA) {
2393 printk("acx: Rx_Data");
2395 /* HOST_INT_TX_COMPLETE */
2396 if (irqtype & HOST_INT_TX_XFER) {
2397 printk("acx: Tx_Xfer");
2399 /* HOST_INT_RX_COMPLETE */
2400 if (irqtype & HOST_INT_DTIM) {
2401 printk("acx: DTIM");
2403 if (irqtype & HOST_INT_BEACON) {
2404 printk("acx: Beacon");
2406 if (irqtype & HOST_INT_TIMER) {
2407 log(L_IRQ, "acx: Timer");
2409 if (irqtype & HOST_INT_KEY_NOT_FOUND) {
2410 printk("acx: Key_Not_Found");
2412 if (irqtype & HOST_INT_IV_ICV_FAILURE) {
2413 printk("acx: IV_ICV_Failure (crypto)");
2415 /* HOST_INT_CMD_COMPLETE */
2416 /* HOST_INT_INFO */
2417 if (irqtype & HOST_INT_OVERFLOW) {
2418 printk("acx: Overflow");
2420 if (irqtype & HOST_INT_PROCESS_ERROR) {
2421 printk("acx: Process_Error");
2423 /* HOST_INT_SCAN_COMPLETE */
2424 if (irqtype & HOST_INT_FCS_THRESHOLD) {
2425 printk("acx: FCS_Threshold");
2427 if (irqtype & HOST_INT_UNKNOWN) {
2428 printk("acx: Unknown");
2430 printk("acx: IRQ(s)\n");
2433 /* FIXME: update_link_quality_led was a stub - let's comment it and avoid
2434 * compiler warnings */
2436 static void update_link_quality_led(acx_device_t * adev)
2438 int qual;
2440 qual =
2441 acx_signal_determine_quality(adev->wstats.qual.level,
2442 adev->wstats.qual.noise);
2443 if (qual > adev->brange_max_quality)
2444 qual = adev->brange_max_quality;
2446 if (time_after(jiffies, adev->brange_time_last_state_change +
2447 (HZ / 2 -
2448 HZ / 2 * (unsigned long)qual /
2449 adev->brange_max_quality))) {
2450 acxpci_l_power_led(adev, (adev->brange_last_state == 0));
2451 adev->brange_last_state ^= 1; // toggle
2452 adev->brange_time_last_state_change = jiffies;
2457 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* a la orinoco.c */
2459 /* Interrupt handler bottom-half */
2460 void acx_interrupt_tasklet(struct work_struct *work)
2463 #ifdef CONFIG_ACX_MAC80211_DEBUG
2464 u32 _handled = 0x00000000;
2465 # define acxirq_handled(irq) do { _handled |= (irq); } while (0)
2466 #else
2467 # define acxirq_handled(irq) do { /* nothing */ } while (0)
2468 #endif /* CONFIG_ACX_MAC80211_DEBUG */
2469 acx_device_t *adev = container_of(work,struct acx_device, after_interrupt_task);
2470 // unsigned int irqcount = MAX_IRQLOOPS_PER_JIFFY;
2471 int irqtype;
2473 #define IRQ_ITERATE 0
2474 #if IRQ_ITERATE
2475 unsigned int irqcount = MAX_IRQLOOPS_PER_JIFFY;
2476 u16 unmasked;
2477 #endif
2479 FN_ENTER;
2481 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2482 * I am paranoid */
2483 acx_sem_lock(adev);
2485 irqtype = adev->irq_reason;
2486 adev->irq_reason = 0;
2488 #if IRQ_ITERATE
2489 if (jiffies != adev->irq_last_jiffies) {
2490 adev->irq_loops_this_jiffy = 0;
2491 adev->irq_last_jiffies = jiffies;
2494 /* safety condition; we'll normally abort loop below
2495 * in case no IRQ type occurred */
2496 while (likely(--irqcount)) {
2497 #endif
2498 /* ACK all IRQs ASAP */
2500 /* Handle most important IRQ types first */
2501 if (irqtype & HOST_INT_RX_COMPLETE) {
2502 log(L_IRQ, "acx: got Rx_Complete IRQ\n");
2503 acxpci_l_process_rxdesc(adev);
2505 if (irqtype & HOST_INT_TX_COMPLETE) {
2506 log(L_IRQ, "acx: got Tx_Complete IRQ\n");
2507 /* don't clean up on each Tx complete, wait a bit
2508 * unless we're going towards full, in which case
2509 * we do it immediately, too (otherwise we might lockup
2510 * with a full Tx buffer if we go into
2511 * acxpci_l_clean_txdesc() at a time when we won't wakeup
2512 * the net queue in there for some reason...) */
2513 // if (adev->tx_free <= TX_START_CLEAN) {
2514 acxpci_l_clean_txdesc(adev);
2515 // }
2518 /* Less frequent ones */
2519 if (irqtype & (0
2520 | HOST_INT_CMD_COMPLETE
2521 | HOST_INT_INFO | HOST_INT_SCAN_COMPLETE)) {
2522 if (irqtype & HOST_INT_INFO) {
2523 handle_info_irq(adev);
2525 if (irqtype & HOST_INT_SCAN_COMPLETE) {
2526 log(L_IRQ, "acx: got Scan_Complete IRQ\n");
2527 /* need to do that in process context */
2528 /* remember that fw is not scanning anymore */
2529 SET_BIT(adev->irq_status,
2530 HOST_INT_SCAN_COMPLETE);
2534 /* These we just log, but either they happen rarely
2535 * or we keep them masked out */
2536 if (irqtype & (0 | HOST_INT_RX_DATA
2537 /* | HOST_INT_TX_COMPLETE */
2538 | HOST_INT_TX_XFER
2539 /* | HOST_INT_RX_COMPLETE */
2540 | HOST_INT_DTIM
2541 | HOST_INT_BEACON
2542 | HOST_INT_TIMER
2543 | HOST_INT_KEY_NOT_FOUND
2544 | HOST_INT_IV_ICV_FAILURE
2545 /* | HOST_INT_CMD_COMPLETE */
2546 /* | HOST_INT_INFO */
2547 | HOST_INT_OVERFLOW
2548 | HOST_INT_PROCESS_ERROR
2549 /* | HOST_INT_SCAN_COMPLETE */
2550 | HOST_INT_FCS_THRESHOLD
2551 | HOST_INT_UNKNOWN)) {
2552 log_unusual_irq(irqtype);
2554 #if IRQ_ITERATE
2555 unmasked = read_reg16(adev, IO_ACX_IRQ_REASON);
2556 irqtype = unmasked & ~adev->irq_mask;
2557 /* Bail out if no new IRQ bits or if all are masked out */
2558 if (!irqtype)
2559 break;
2561 if (unlikely
2562 (++adev->irq_loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY)) {
2563 printk(KERN_ERR
2564 "acx: too many interrupts per jiffy!\n");
2565 /* Looks like card floods us with IRQs! Try to stop that */
2566 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
2567 /* This will short-circuit all future attempts to handle IRQ.
2568 * We cant do much more... */
2569 adev->irq_mask = 0;
2570 break;
2573 #endif
2574 /* Routine to perform blink with range
2575 * FIXME: update_link_quality_led is a stub - add proper code and enable this again:
2576 if (unlikely(adev->led_power == 2))
2577 update_link_quality_led(adev);
2580 /* write_flush(adev); - not needed, last op was read anyway */
2581 acx_sem_unlock(adev);
2583 /* handled: */
2584 if (adev->after_interrupt_jobs)
2585 acx_e_after_interrupt_task(&adev->after_interrupt_task);
2587 FN_EXIT0;
2588 return;
2593 static irqreturn_t acxpci_i_interrupt(int irq, void *dev_id)
2595 acx_device_t *adev = dev_id;
2596 unsigned long flags;
2597 register u16 irqtype;
2598 u16 unmasked;
2600 FN_ENTER;
2602 if (!adev)
2603 return IRQ_NONE;
2605 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2606 * I am paranoid */
2608 acx_lock(adev, flags);
2611 unmasked = read_reg16(adev, IO_ACX_IRQ_REASON);
2612 if (unlikely(0xffff == unmasked)) {
2613 /* 0xffff value hints at missing hardware,
2614 * so don't do anything.
2615 * Not very clean, but other drivers do the same... */
2616 log(L_IRQ, "acx: IRQ type:FFFF - device removed? IRQ_NONE\n");
2617 goto none;
2620 /* We will check only "interesting" IRQ types */
2621 irqtype = unmasked & ~adev->irq_mask;
2622 if (!irqtype) {
2623 /* We are on a shared IRQ line and it wasn't our IRQ */
2624 log(L_IRQ,
2625 "acx: IRQ type:%04X, mask:%04X - all are masked, IRQ_NONE\n",
2626 unmasked, adev->irq_mask);
2627 goto none;
2630 /* Go ahead and ACK our interrupt */
2631 write_reg16(adev, IO_ACX_IRQ_ACK, 0xffff);
2632 if (irqtype & HOST_INT_CMD_COMPLETE) {
2633 log(L_IRQ, "acx: got Command_Complete IRQ\n");
2634 /* save the state for the running issue_cmd() */
2635 SET_BIT(adev->irq_status, HOST_INT_CMD_COMPLETE);
2638 /* Only accept IRQs, if we are initialized properly.
2639 * This avoids an RX race while initializing.
2640 * We should probably not enable IRQs before we are initialized
2641 * completely, but some careful work is needed to fix this. I think it
2642 * is best to stay with this cheap workaround for now... .
2644 if (likely(adev->initialized)) {
2645 /* disable all IRQs. They are enabled again in the bottom half. */
2646 /* save the reason code and call our bottom half. */
2647 adev->irq_reason = irqtype;
2649 if ((irqtype & HOST_INT_RX_COMPLETE) || (irqtype & HOST_INT_TX_COMPLETE))
2650 acx_schedule_task(adev, 0);
2653 acx_unlock(adev, flags);
2654 FN_EXIT0;
2655 return IRQ_HANDLED;
2656 none:
2657 acx_unlock(adev, flags);
2658 FN_EXIT0;
2659 return IRQ_NONE;
2664 /***********************************************************************
2665 ** acxpci_l_power_led
2667 void acxpci_l_power_led(acx_device_t * adev, int enable)
2669 u16 gpio_pled = IS_ACX111(adev) ? 0x0040 : 0x0800;
2671 /* A hack. Not moving message rate limiting to adev->xxx
2672 * (it's only a debug message after all) */
2673 static int rate_limit = 0;
2675 if (rate_limit++ < 3)
2676 log(L_IOCTL, "acx: Please report in case toggling the power "
2677 "LED doesn't work for your card\n");
2678 if (enable)
2679 write_reg16(adev, IO_ACX_GPIO_OUT,
2680 read_reg16(adev, IO_ACX_GPIO_OUT) & ~gpio_pled);
2681 else
2682 write_reg16(adev, IO_ACX_GPIO_OUT,
2683 read_reg16(adev, IO_ACX_GPIO_OUT) | gpio_pled);
2687 /***********************************************************************
2688 ** Ioctls
2691 /***********************************************************************
2693 #if 0
2695 acx111pci_ioctl_info(struct net_device *ndev,
2696 struct iw_request_info *info,
2697 struct iw_param *vwrq, char *extra)
2699 #if ACX_DEBUG > 1
2700 acx_device_t *adev = ndev2adev(ndev);
2701 rxdesc_t *rxdesc;
2702 txdesc_t *txdesc;
2703 rxhostdesc_t *rxhostdesc;
2704 txhostdesc_t *txhostdesc;
2705 struct acx111_ie_memoryconfig memconf;
2706 struct acx111_ie_queueconfig queueconf;
2707 unsigned long flags;
2708 int i;
2709 char memmap[0x34];
2710 char rxconfig[0x8];
2711 char fcserror[0x8];
2712 char ratefallback[0x5];
2714 if (!(acx_debug & (L_IOCTL | L_DEBUG)))
2715 return OK;
2716 /* using printk() since we checked debug flag already */
2718 acx_sem_lock(adev);
2720 if (!IS_ACX111(adev)) {
2721 printk("acx: acx111-specific function called "
2722 "with non-acx111 chip, aborting\n");
2723 goto end_ok;
2726 /* get Acx111 Memory Configuration */
2727 memset(&memconf, 0, sizeof(memconf));
2728 /* BTW, fails with 12 (Write only) error code.
2729 ** Retained for easy testing of issue_cmd error handling :) */
2730 acx_s_interrogate(adev, &memconf, ACX1xx_IE_QUEUE_CONFIG);
2732 /* get Acx111 Queue Configuration */
2733 memset(&queueconf, 0, sizeof(queueconf));
2734 acx_s_interrogate(adev, &queueconf, ACX1xx_IE_MEMORY_CONFIG_OPTIONS);
2736 /* get Acx111 Memory Map */
2737 memset(memmap, 0, sizeof(memmap));
2738 acx_s_interrogate(adev, &memmap, ACX1xx_IE_MEMORY_MAP);
2740 /* get Acx111 Rx Config */
2741 memset(rxconfig, 0, sizeof(rxconfig));
2742 acx_s_interrogate(adev, &rxconfig, ACX1xx_IE_RXCONFIG);
2744 /* get Acx111 fcs error count */
2745 memset(fcserror, 0, sizeof(fcserror));
2746 acx_s_interrogate(adev, &fcserror, ACX1xx_IE_FCS_ERROR_COUNT);
2748 /* get Acx111 rate fallback */
2749 memset(ratefallback, 0, sizeof(ratefallback));
2750 acx_s_interrogate(adev, &ratefallback, ACX1xx_IE_RATE_FALLBACK);
2752 /* force occurrence of a beacon interrupt */
2753 /* TODO: comment why is this necessary */
2754 write_reg16(adev, IO_ACX_HINT_TRIG, HOST_INT_BEACON);
2756 /* dump Acx111 Mem Configuration */
2757 printk("acx: dump mem config:\n"
2758 "data read: %d, struct size: %d\n"
2759 "Number of stations: %1X\n"
2760 "Memory block size: %1X\n"
2761 "tx/rx memory block allocation: %1X\n"
2762 "count rx: %X / tx: %X queues\n"
2763 "options %1X\n"
2764 "fragmentation %1X\n"
2765 "Rx Queue 1 Count Descriptors: %X\n"
2766 "Rx Queue 1 Host Memory Start: %X\n"
2767 "Tx Queue 1 Count Descriptors: %X\n"
2768 "Tx Queue 1 Attributes: %X\n",
2769 memconf.len, (int)sizeof(memconf),
2770 memconf.no_of_stations,
2771 memconf.memory_block_size,
2772 memconf.tx_rx_memory_block_allocation,
2773 memconf.count_rx_queues, memconf.count_tx_queues,
2774 memconf.options,
2775 memconf.fragmentation,
2776 memconf.rx_queue1_count_descs,
2777 acx2cpu(memconf.rx_queue1_host_rx_start),
2778 memconf.tx_queue1_count_descs, memconf.tx_queue1_attributes);
2780 /* dump Acx111 Queue Configuration */
2781 printk("acx: dump queue head:\n"
2782 "data read: %d, struct size: %d\n"
2783 "tx_memory_block_address (from card): %X\n"
2784 "rx_memory_block_address (from card): %X\n"
2785 "rx1_queue address (from card): %X\n"
2786 "tx1_queue address (from card): %X\n"
2787 "tx1_queue attributes (from card): %X\n",
2788 queueconf.len, (int)sizeof(queueconf),
2789 queueconf.tx_memory_block_address,
2790 queueconf.rx_memory_block_address,
2791 queueconf.rx1_queue_address,
2792 queueconf.tx1_queue_address, queueconf.tx1_attributes);
2794 /* dump Acx111 Mem Map */
2795 printk("acx: dump mem map:\n"
2796 "data read: %d, struct size: %d\n"
2797 "Code start: %X\n"
2798 "Code end: %X\n"
2799 "WEP default key start: %X\n"
2800 "WEP default key end: %X\n"
2801 "STA table start: %X\n"
2802 "STA table end: %X\n"
2803 "Packet template start: %X\n"
2804 "Packet template end: %X\n"
2805 "Queue memory start: %X\n"
2806 "Queue memory end: %X\n"
2807 "Packet memory pool start: %X\n"
2808 "Packet memory pool end: %X\n"
2809 "iobase: %p\n"
2810 "iobase2: %p\n",
2811 *((u16 *) & memmap[0x02]), (int)sizeof(memmap),
2812 *((u32 *) & memmap[0x04]),
2813 *((u32 *) & memmap[0x08]),
2814 *((u32 *) & memmap[0x0C]),
2815 *((u32 *) & memmap[0x10]),
2816 *((u32 *) & memmap[0x14]),
2817 *((u32 *) & memmap[0x18]),
2818 *((u32 *) & memmap[0x1C]),
2819 *((u32 *) & memmap[0x20]),
2820 *((u32 *) & memmap[0x24]),
2821 *((u32 *) & memmap[0x28]),
2822 *((u32 *) & memmap[0x2C]),
2823 *((u32 *) & memmap[0x30]), adev->iobase, adev->iobase2);
2825 /* dump Acx111 Rx Config */
2826 printk("acx: dump rx config:\n"
2827 "data read: %d, struct size: %d\n"
2828 "rx config: %X\n"
2829 "rx filter config: %X\n",
2830 *((u16 *) & rxconfig[0x02]), (int)sizeof(rxconfig),
2831 *((u16 *) & rxconfig[0x04]), *((u16 *) & rxconfig[0x06]));
2833 /* dump Acx111 fcs error */
2834 printk("acx: dump fcserror:\n"
2835 "data read: %d, struct size: %d\n"
2836 "fcserrors: %X\n",
2837 *((u16 *) & fcserror[0x02]), (int)sizeof(fcserror),
2838 *((u32 *) & fcserror[0x04]));
2840 /* dump Acx111 rate fallback */
2841 printk("acx: dump rate fallback:\n"
2842 "data read: %d, struct size: %d\n"
2843 "ratefallback: %X\n",
2844 *((u16 *) & ratefallback[0x02]), (int)sizeof(ratefallback),
2845 *((u8 *) & ratefallback[0x04]));
2847 /* protect against IRQ */
2848 acx_lock(adev, flags);
2850 /* dump acx111 internal rx descriptor ring buffer */
2851 rxdesc = adev->rxdesc_start;
2853 /* loop over complete receive pool */
2854 if (rxdesc)
2855 for (i = 0; i < RX_CNT; i++) {
2856 printk("acx: \ndump internal rxdesc %d:\n"
2857 "mem pos %p\n"
2858 "next 0x%X\n"
2859 "acx mem pointer (dynamic) 0x%X\n"
2860 "CTL (dynamic) 0x%X\n"
2861 "Rate (dynamic) 0x%X\n"
2862 "RxStatus (dynamic) 0x%X\n"
2863 "Mod/Pre (dynamic) 0x%X\n",
2865 rxdesc,
2866 acx2cpu(rxdesc->pNextDesc),
2867 acx2cpu(rxdesc->ACXMemPtr),
2868 rxdesc->Ctl_8,
2869 rxdesc->rate, rxdesc->error, rxdesc->SNR);
2870 rxdesc++;
2873 /* dump host rx descriptor ring buffer */
2875 rxhostdesc = adev->rxhostdesc_start;
2877 /* loop over complete receive pool */
2878 if (rxhostdesc)
2879 for (i = 0; i < RX_CNT; i++) {
2880 printk("acx: \ndump host rxdesc %d:\n"
2881 "mem pos %p\n"
2882 "buffer mem pos 0x%X\n"
2883 "buffer mem offset 0x%X\n"
2884 "CTL 0x%X\n"
2885 "Length 0x%X\n"
2886 "next 0x%X\n"
2887 "Status 0x%X\n",
2889 rxhostdesc,
2890 acx2cpu(rxhostdesc->data_phy),
2891 rxhostdesc->data_offset,
2892 le16_to_cpu(rxhostdesc->Ctl_16),
2893 le16_to_cpu(rxhostdesc->length),
2894 acx2cpu(rxhostdesc->desc_phy_next),
2895 rxhostdesc->Status);
2896 rxhostdesc++;
2899 /* dump acx111 internal tx descriptor ring buffer */
2900 txdesc = adev->txdesc_start;
2902 /* loop over complete transmit pool */
2903 if (txdesc)
2904 for (i = 0; i < TX_CNT; i++) {
2905 printk("acx: \ndump internal txdesc %d:\n"
2906 "size 0x%X\n"
2907 "mem pos %p\n"
2908 "next 0x%X\n"
2909 "acx mem pointer (dynamic) 0x%X\n"
2910 "host mem pointer (dynamic) 0x%X\n"
2911 "length (dynamic) 0x%X\n"
2912 "CTL (dynamic) 0x%X\n"
2913 "CTL2 (dynamic) 0x%X\n"
2914 "Status (dynamic) 0x%X\n"
2915 "Rate (dynamic) 0x%X\n",
2917 (int)sizeof(struct txdesc),
2918 txdesc,
2919 acx2cpu(txdesc->pNextDesc),
2920 acx2cpu(txdesc->AcxMemPtr),
2921 acx2cpu(txdesc->HostMemPtr),
2922 le16_to_cpu(txdesc->total_length),
2923 txdesc->Ctl_8,
2924 txdesc->Ctl2_8, txdesc->error,
2925 txdesc->u.r1.rate);
2926 txdesc = advance_txdesc(adev, txdesc, 1);
2929 /* dump host tx descriptor ring buffer */
2931 txhostdesc = adev->txhostdesc_start;
2933 /* loop over complete host send pool */
2934 if (txhostdesc)
2935 for (i = 0; i < TX_CNT * 2; i++) {
2936 printk("acx: \ndump host txdesc %d:\n"
2937 "mem pos %p\n"
2938 "buffer mem pos 0x%X\n"
2939 "buffer mem offset 0x%X\n"
2940 "CTL 0x%X\n"
2941 "Length 0x%X\n"
2942 "next 0x%X\n"
2943 "Status 0x%X\n",
2945 txhostdesc,
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));
2952 txhostdesc++;
2955 /* write_reg16(adev, 0xb4, 0x4); */
2957 acx_unlock(adev, flags);
2958 end_ok:
2960 acx_sem_unlock(adev);
2961 #endif /* ACX_DEBUG */
2962 return OK;
2966 /***********************************************************************
2969 acx100pci_ioctl_set_phy_amp_bias(struct net_device *ndev,
2970 struct iw_request_info *info,
2971 struct iw_param *vwrq, char *extra)
2973 acx_device_t *adev = ndev2adev(ndev);
2974 unsigned long flags;
2975 u16 gpio_old;
2977 if (!IS_ACX100(adev)) {
2978 /* WARNING!!!
2979 * Removing this check *might* damage
2980 * hardware, since we're tweaking GPIOs here after all!!!
2981 * You've been warned...
2982 * WARNING!!! */
2983 printk("acx: sorry, setting bias level for non-acx100 "
2984 "is not supported yet\n");
2985 return OK;
2988 if (*extra > 7) {
2989 printk("acx: invalid bias parameter, range is 0-7\n");
2990 return -EINVAL;
2993 acx_sem_lock(adev);
2995 /* Need to lock accesses to [IO_ACX_GPIO_OUT]:
2996 * IRQ handler uses it to update LED */
2997 acx_lock(adev, flags);
2998 gpio_old = read_reg16(adev, IO_ACX_GPIO_OUT);
2999 write_reg16(adev, IO_ACX_GPIO_OUT,
3000 (gpio_old & 0xf8ff) | ((u16) * extra << 8));
3001 acx_unlock(adev, flags);
3003 log(L_DEBUG, "acx: gpio_old: 0x%04X\n", gpio_old);
3004 printk("acx: %s: PHY power amplifier bias: old:%d, new:%d\n",
3005 ndev->name, (gpio_old & 0x0700) >> 8, (unsigned char)*extra);
3007 acx_sem_unlock(adev);
3009 return OK;
3011 #endif /* 0 */
3013 /***************************************************************
3014 ** acxpci_l_alloc_tx
3015 ** Actually returns a txdesc_t* ptr
3017 ** FIXME: in case of fragments, should allocate multiple descrs
3018 ** after figuring out how many we need and whether we still have
3019 ** sufficiently many.
3021 tx_t *acxpci_l_alloc_tx(acx_device_t * adev)
3023 struct txdesc *txdesc;
3024 unsigned head;
3025 u8 ctl8;
3027 FN_ENTER;
3029 if (unlikely(!adev->tx_free)) {
3030 printk("acx: BUG: no free txdesc left\n");
3031 txdesc = NULL;
3032 goto end;
3035 head = adev->tx_head;
3036 txdesc = get_txdesc(adev, head);
3037 ctl8 = txdesc->Ctl_8;
3039 /* 2005-10-11: there were several bug reports on this happening
3040 ** but now cause seems to be understood & fixed */
3041 if (unlikely(DESC_CTL_HOSTOWN != (ctl8 & DESC_CTL_ACXDONE_HOSTOWN))) {
3042 /* whoops, descr at current index is not free, so probably
3043 * ring buffer already full */
3044 printk("acx: BUG: tx_head:%d Ctl8:0x%02X - failed to find "
3045 "free txdesc\n", head, ctl8);
3046 txdesc = NULL;
3047 goto end;
3050 /* Needed in case txdesc won't be eventually submitted for tx */
3051 txdesc->Ctl_8 = DESC_CTL_ACXDONE_HOSTOWN;
3053 adev->tx_free--;
3054 log(L_BUFT, "acx: tx: got desc %u, %u remain\n", head, adev->tx_free);
3055 /* Keep a few free descs between head and tail of tx ring.
3056 ** It is not absolutely needed, just feels safer */
3057 if (adev->tx_free < TX_STOP_QUEUE) {
3058 log(L_BUF, "acx: stop queue (%u tx desc left)\n", adev->tx_free);
3059 acx_stop_queue(adev->ieee, NULL);
3062 /* returning current descriptor, so advance to next free one */
3063 adev->tx_head = (head + 1) % TX_CNT;
3064 end:
3065 FN_EXIT0;
3067 return (tx_t *) txdesc;
3071 /***********************************************************************
3073 void *acxpci_l_get_txbuf(acx_device_t * adev, tx_t * tx_opaque)
3075 return get_txhostdesc(adev, (txdesc_t *) tx_opaque)->data;
3079 /***********************************************************************
3080 ** acxpci_l_tx_data
3082 ** Can be called from IRQ (rx -> (AP bridging or mgmt response) -> tx).
3083 ** Can be called from acx_i_start_xmit (data frames from net core).
3085 ** FIXME: in case of fragments, should loop over the number of
3086 ** pre-allocated tx descrs, properly setting up transfer data and
3087 ** CTL_xxx flags according to fragment number.
3089 void
3090 acxpci_l_tx_data(acx_device_t * adev, tx_t * tx_opaque, int len,
3091 struct ieee80211_tx_control *ieeectl,struct sk_buff* skb)
3093 txdesc_t *txdesc = (txdesc_t *) tx_opaque;
3094 struct ieee80211_hdr *wireless_header;
3095 txhostdesc_t *hostdesc1, *hostdesc2;
3096 int rate_cur;
3097 u8 Ctl_8, Ctl2_8;
3098 int wlhdr_len;
3100 FN_ENTER;
3102 /* fw doesn't tx such packets anyhow */
3103 /* if (unlikely(len < WLAN_HDR_A3_LEN))
3104 goto end;
3106 hostdesc1 = get_txhostdesc(adev, txdesc);
3107 wireless_header = (struct ieee80211_hdr *)hostdesc1->data;
3108 /* modify flag status in separate variable to be able to write it back
3109 * in one big swoop later (also in order to have less device memory
3110 * accesses) */
3111 Ctl_8 = txdesc->Ctl_8;
3112 Ctl2_8 = 0; /* really need to init it to 0, not txdesc->Ctl2_8, it seems */
3114 hostdesc2 = hostdesc1 + 1;
3116 /* DON'T simply set Ctl field to 0 here globally,
3117 * it needs to maintain a consistent flag status (those are state flags!!),
3118 * otherwise it may lead to severe disruption. Only set or reset particular
3119 * flags at the exact moment this is needed... */
3121 /* let chip do RTS/CTS handshaking before sending
3122 * in case packet size exceeds threshold */
3123 if (ieeectl->flags & IEEE80211_TXCTL_USE_RTS_CTS)
3124 SET_BIT(Ctl2_8, DESC_CTL2_RTS);
3125 else
3126 CLEAR_BIT(Ctl2_8, DESC_CTL2_RTS);
3128 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,25)
3129 rate_cur = ieeectl->tx_rate;
3130 #else
3131 rate_cur = ieeectl->tx_rate->bitrate;
3132 #endif
3133 if (unlikely(!rate_cur)) {
3134 printk("acx: driver bug! bad ratemask\n");
3135 goto end;
3138 /* used in tx cleanup routine for auto rate and accounting: */
3139 /* put_txcr(adev, txdesc, clt, rate_cur); deprecated by mac80211 */
3141 txdesc->total_length = cpu_to_le16(len);
3142 wlhdr_len = ieee80211_get_hdrlen(le16_to_cpu(wireless_header->frame_control));
3143 hostdesc2->length = cpu_to_le16(len - wlhdr_len);
3145 if (!ieeectl->do_not_encrypt && ieeectl->key_idx>= 0)
3147 u16 key_idx = (u16)(ieeectl->key_idx);
3148 struct acx_key* key = &(adev->key[key_idx]);
3149 int wlhdr_len;
3150 if (key->enabled)
3152 memcpy(ieeehdr->wep_iv, ((u8*)wireless_header) + wlhdr_len, 4);
3156 if (IS_ACX111(adev)) {
3157 /* note that if !txdesc->do_auto, txrate->cur
3158 ** has only one nonzero bit */
3159 txdesc->u.r2.rate111 = cpu_to_le16(rate_cur
3160 /* WARNING: I was never able to make it work with prism54 AP.
3161 ** It was falling down to 1Mbit where shortpre is not applicable,
3162 ** and not working at all at "5,11 basic rates only" setting.
3163 ** I even didn't see tx packets in radio packet capture.
3164 ** Disabled for now --vda */
3165 /*| ((clt->shortpre && clt->cur!=RATE111_1) ? RATE111_SHORTPRE : 0) */
3167 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3168 /* should add this to rate111 above as necessary */
3169 |(clt->pbcc511 ? RATE111_PBCC511 : 0)
3170 #endif
3171 hostdesc1->length = cpu_to_le16(len);
3172 } else { /* ACX100 */
3173 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,25)
3174 u8 rate_100 = ieeectl->tx_rate;
3175 #else
3176 u8 rate_100 = ieeectl->tx_rate->bitrate;
3177 #endif
3178 txdesc->u.r1.rate = rate_100;
3179 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3180 if (clt->pbcc511) {
3181 if (n == RATE100_5 || n == RATE100_11)
3182 n |= RATE100_PBCC511;
3185 if (clt->shortpre && (clt->cur != RATE111_1))
3186 SET_BIT(Ctl_8, DESC_CTL_SHORT_PREAMBLE); /* set Short Preamble */
3187 #endif
3188 /* set autodma and reclaim and 1st mpdu */
3189 SET_BIT(Ctl_8,
3190 DESC_CTL_AUTODMA | DESC_CTL_RECLAIM |
3191 DESC_CTL_FIRSTFRAG);
3192 #if ACX_FRAGMENTATION
3193 /* SET_BIT(Ctl2_8, DESC_CTL2_MORE_FRAG); cannot set it unconditionally, needs to be set for all non-last fragments */
3194 #endif
3195 hostdesc1->length = cpu_to_le16(wlhdr_len);
3197 /* don't need to clean ack/rts statistics here, already
3198 * done on descr cleanup */
3200 /* clears HOSTOWN and ACXDONE bits, thus telling that the descriptors
3201 * are now owned by the acx100; do this as LAST operation */
3202 CLEAR_BIT(Ctl_8, DESC_CTL_ACXDONE_HOSTOWN);
3203 /* flush writes before we release hostdesc to the adapter here */
3204 wmb();
3205 CLEAR_BIT(hostdesc1->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3206 CLEAR_BIT(hostdesc2->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3208 /* write back modified flags */
3209 CLEAR_BIT(Ctl2_8, DESC_CTL2_WEP);
3210 txdesc->Ctl2_8 = Ctl2_8;
3211 txdesc->Ctl_8 = Ctl_8;
3212 /* unused: txdesc->tx_time = cpu_to_le32(jiffies); */
3214 /* flush writes before we tell the adapter that it's its turn now */
3215 write_reg16(adev, IO_ACX_INT_TRIG, INT_TRIG_TXPRC);
3216 write_flush(adev);
3217 /* log the packet content AFTER sending it,
3218 * in order to not delay sending any further than absolutely needed
3219 * Do separate logs for acx100/111 to have human-readable rates */
3220 memcpy(&(hostdesc1->txstatus.control),ieeectl,sizeof(struct ieee80211_tx_control));
3221 hostdesc1->skb = skb;
3222 end:
3223 FN_EXIT0;
3227 /***********************************************************************
3228 ** acxpci_l_clean_txdesc
3230 ** This function resets the txdescs' status when the ACX100
3231 ** signals the TX done IRQ (txdescs have been processed), starting with
3232 ** the pool index of the descriptor which we would use next,
3233 ** in order to make sure that we can be as fast as possible
3234 ** in filling new txdescs.
3235 ** Everytime we get called we know where the next packet to be cleaned is.
3238 #if !ACX_DEBUG
3239 static inline void log_txbuffer(const acx_device_t * adev)
3242 #else
3243 static void log_txbuffer(acx_device_t * adev)
3245 txdesc_t *txdesc;
3246 int i;
3248 /* no FN_ENTER here, we don't want that */
3249 /* no locks here, since it's entirely non-critical code */
3250 txdesc = adev->txdesc_start;
3251 if (unlikely(!txdesc))
3252 return;
3253 printk("acx: tx: desc->Ctl8's:");
3254 for (i = 0; i < TX_CNT; i++) {
3255 printk("acx: %02X", txdesc->Ctl_8);
3256 txdesc = advance_txdesc(adev, txdesc, 1);
3258 printk("acx: \n");
3260 #endif
3263 static void handle_tx_error(acx_device_t * adev, u8 error, unsigned int finger,
3264 struct ieee80211_tx_status *status)
3266 const char *err = "unknown error";
3268 /* hmm, should we handle this as a mask
3269 * of *several* bits?
3270 * For now I think only caring about
3271 * individual bits is ok... */
3272 switch (error) {
3273 case 0x01:
3274 err = "no Tx due to error in other fragment";
3275 /* adev->wstats.discard.fragment++; */
3276 break;
3277 case 0x02:
3278 err = "Tx aborted";
3279 adev->stats.tx_aborted_errors++;
3280 break;
3281 case 0x04:
3282 err = "Tx desc wrong parameters";
3283 /* adev->wstats.discard.misc++; */
3284 break;
3285 case 0x08:
3286 err = "WEP key not found";
3287 /* adev->wstats.discard.misc++; */
3288 break;
3289 case 0x10:
3290 err = "MSDU lifetime timeout? - try changing "
3291 "'iwconfig retry lifetime XXX'";
3292 /* adev->wstats.discard.misc++; */
3293 break;
3294 case 0x20:
3295 err = "excessive Tx retries due to either distance "
3296 "too high or unable to Tx or Tx frame error - "
3297 "try changing 'iwconfig txpower XXX' or "
3298 "'sens'itivity or 'retry'";
3299 /* adev->wstats.discard.retries++; */
3300 /* Tx error 0x20 also seems to occur on
3301 * overheating, so I'm not sure whether we
3302 * actually want to do aggressive radio recalibration,
3303 * since people maybe won't notice then that their hardware
3304 * is slowly getting cooked...
3305 * Or is it still a safe long distance from utter
3306 * radio non-functionality despite many radio recalibs
3307 * to final destructive overheating of the hardware?
3308 * In this case we really should do recalib here...
3309 * I guess the only way to find out is to do a
3310 * potentially fatal self-experiment :-\
3311 * Or maybe only recalib in case we're using Tx
3312 * rate auto (on errors switching to lower speed
3313 * --> less heat?) or 802.11 power save mode?
3315 * ok, just do it. */
3316 if (++adev->retry_errors_msg_ratelimit % 4 == 0) {
3317 if (adev->retry_errors_msg_ratelimit <= 20) {
3318 printk("acx: %s: several excessive Tx "
3319 "retry errors occurred, attempting "
3320 "to recalibrate radio. Radio "
3321 "drift might be caused by increasing "
3322 "card temperature, please check the card "
3323 "before it's too late!\n",
3324 wiphy_name(adev->ieee->wiphy));
3325 if (adev->retry_errors_msg_ratelimit == 20)
3326 printk("acx: disabling above message\n");
3329 acx_schedule_task(adev,
3330 ACX_AFTER_IRQ_CMD_RADIO_RECALIB);
3332 status->excessive_retries++;
3333 break;
3334 case 0x40:
3335 err = "Tx buffer overflow";
3336 adev->stats.tx_fifo_errors++;
3337 break;
3338 case 0x80:
3339 /* possibly ACPI C-state powersaving related!!!
3340 * (DMA timeout due to excessively high wakeup
3341 * latency after C-state activation!?)
3342 * Disable C-State powersaving and try again,
3343 * then PLEASE REPORT, I'm VERY interested in
3344 * whether my theory is correct that this is
3345 * actually the problem here.
3346 * In that case, use new Linux idle wakeup latency
3347 * requirements kernel API to prevent this issue. */
3348 err = "DMA error";
3349 /* adev->wstats.discard.misc++; */
3350 break;
3352 adev->stats.tx_errors++;
3353 if (adev->stats.tx_errors <= 20)
3354 printk("acx: %s: tx error 0x%02X, buf %02u! (%s)\n",
3355 wiphy_name(adev->ieee->wiphy), error, finger, err);
3356 else
3357 printk("acx: %s: tx error 0x%02X, buf %02u!\n",
3358 wiphy_name(adev->ieee->wiphy), error, finger);
3362 unsigned int acxpci_l_clean_txdesc(acx_device_t * adev)
3364 txdesc_t *txdesc;
3365 txhostdesc_t *hostdesc;
3366 unsigned finger;
3367 int num_cleaned;
3368 u16 r111;
3369 u8 error, ack_failures, rts_failures, rts_ok, r100;
3371 FN_ENTER;
3373 if (unlikely(acx_debug & L_DEBUG))
3374 log_txbuffer(adev);
3376 log(L_BUFT, "acx: tx: cleaning up bufs from %u\n", adev->tx_tail);
3378 /* We know first descr which is not free yet. We advance it as far
3379 ** as we see correct bits set in following descs (if next desc
3380 ** is NOT free, we shouldn't advance at all). We know that in
3381 ** front of tx_tail may be "holes" with isolated free descs.
3382 ** We will catch up when all intermediate descs will be freed also */
3384 finger = adev->tx_tail;
3385 num_cleaned = 0;
3386 while (likely(finger != adev->tx_head)) {
3387 txdesc = get_txdesc(adev, finger);
3389 /* If we allocated txdesc on tx path but then decided
3390 ** to NOT use it, then it will be left as a free "bubble"
3391 ** in the "allocated for tx" part of the ring.
3392 ** We may meet it on the next ring pass here. */
3394 /* stop if not marked as "tx finished" and "host owned" */
3395 if ((txdesc->Ctl_8 & DESC_CTL_ACXDONE_HOSTOWN)
3396 != DESC_CTL_ACXDONE_HOSTOWN) {
3397 if (unlikely(!num_cleaned)) { /* maybe remove completely */
3398 log(L_BUFT, "acx: clean_txdesc: tail isn't free. "
3399 "tail:%d head:%d\n",
3400 adev->tx_tail, adev->tx_head);
3402 break;
3405 /* remember desc values... */
3406 error = txdesc->error;
3407 ack_failures = txdesc->ack_failures;
3408 rts_failures = txdesc->rts_failures;
3409 rts_ok = txdesc->rts_ok;
3410 r100 = txdesc->u.r1.rate;
3411 r111 = le16_to_cpu(txdesc->u.r2.rate111);
3413 /* need to check for certain error conditions before we
3414 * clean the descriptor: we still need valid descr data here */
3415 hostdesc = get_txhostdesc(adev, txdesc);
3417 hostdesc->txstatus.flags |= IEEE80211_TX_STATUS_ACK;
3418 if (unlikely(0x30 & error)) {
3419 /* only send IWEVTXDROP in case of retry or lifetime exceeded;
3420 * all other errors mean we screwed up locally */
3421 /* union iwreq_data wrqu;
3422 struct ieee80211_hdr_3addr *hdr;
3423 hdr = (struct ieee80211_hdr_3addr *) hostdesc->data;
3424 MAC_COPY(wrqu.addr.sa_data, hdr->addr1);
3426 hostdesc->txstatus.flags &= ~IEEE80211_TX_STATUS_ACK;
3429 /* ...and free the desc */
3430 txdesc->error = 0;
3431 txdesc->ack_failures = 0;
3432 txdesc->rts_failures = 0;
3433 txdesc->rts_ok = 0;
3434 /* signal host owning it LAST, since ACX already knows that this
3435 ** descriptor is finished since it set Ctl_8 accordingly. */
3436 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3438 adev->tx_free++;
3439 num_cleaned++;
3441 if ((adev->tx_free >= TX_START_QUEUE)
3442 /* && (adev->status == ACX_STATUS_4_ASSOCIATED) */
3443 /*&& (acx_queue_stopped(adev->ieee))*/
3445 log(L_BUF, "acx: tx: wake queue (avail. Tx desc %u)\n",
3446 adev->tx_free);
3447 acx_wake_queue(adev->ieee, NULL);
3450 /* do error checking, rate handling and logging
3451 * AFTER having done the work, it's faster */
3453 /* Rate handling is done in mac80211 */
3454 /* if (adev->rate_auto) {
3455 struct client *clt = get_txc(adev, txdesc);
3456 if (clt) {
3457 u16 cur = get_txr(adev, txdesc);
3458 if (clt->rate_cur == cur) {
3459 acx_l_handle_txrate_auto(adev, clt, cur,*/ /* intended rate */
3460 /*r100, r111,*/ /* actually used rate */
3461 /*(error & 0x30),*/ /* was there an error? */
3462 /* TX_CNT +
3463 TX_CLEAN_BACKLOG
3465 adev->tx_free);
3470 if (unlikely(error))
3471 handle_tx_error(adev, error, finger, &hostdesc->txstatus);
3473 if (IS_ACX111(adev))
3474 log(L_BUFT,
3475 "acx: tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u r111=%04X tx_free=%u\n",
3476 finger, ack_failures, rts_failures, rts_ok, r111, adev->tx_free);
3477 else
3478 log(L_BUFT,
3479 "acx: tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u rate=%u\n",
3480 finger, ack_failures, rts_failures, rts_ok, r100);
3482 /* And finally report upstream */
3483 if (hostdesc)
3485 hostdesc->txstatus.excessive_retries = rts_failures ;
3486 hostdesc->txstatus.retry_count = ack_failures;
3487 ieee80211_tx_status(adev->ieee,hostdesc->skb,&hostdesc->txstatus);
3488 memset(&hostdesc->txstatus, 0, sizeof(struct ieee80211_tx_status));
3490 /* update pointer for descr to be cleaned next */
3491 finger = (finger + 1) % TX_CNT;
3493 /* remember last position */
3494 adev->tx_tail = finger;
3495 /* end: */
3496 FN_EXIT1(num_cleaned);
3497 return num_cleaned;
3500 /* clean *all* Tx descriptors, and regardless of their previous state.
3501 * Used for brute-force reset handling. */
3502 void acxpci_l_clean_txdesc_emergency(acx_device_t * adev)
3504 txdesc_t *txdesc;
3505 int i;
3507 FN_ENTER;
3509 for (i = 0; i < TX_CNT; i++) {
3510 txdesc = get_txdesc(adev, i);
3512 /* free it */
3513 txdesc->ack_failures = 0;
3514 txdesc->rts_failures = 0;
3515 txdesc->rts_ok = 0;
3516 txdesc->error = 0;
3517 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3520 adev->tx_free = TX_CNT;
3522 FN_EXIT0;
3526 /***********************************************************************
3527 ** acxpci_s_create_tx_host_desc_queue
3530 static void *allocate(acx_device_t * adev, size_t size, dma_addr_t * phy,
3531 const char *msg)
3533 void *ptr;
3535 ptr = dma_alloc_coherent(adev->bus_dev, size, phy, GFP_KERNEL);
3537 if (ptr) {
3538 log(L_DEBUG, "acx: %s sz=%d adr=0x%p phy=0x%08llx\n",
3539 msg, (int)size, ptr, (unsigned long long)*phy);
3540 memset(ptr, 0, size);
3541 return ptr;
3543 printk(KERN_ERR "acx: %s allocation FAILED (%d bytes)\n",
3544 msg, (int)size);
3545 return NULL;
3549 static int acxpci_s_create_tx_host_desc_queue(acx_device_t * adev)
3551 txhostdesc_t *hostdesc;
3552 u8 *txbuf;
3553 dma_addr_t hostdesc_phy;
3554 dma_addr_t txbuf_phy;
3555 int i;
3557 FN_ENTER;
3559 /* allocate TX buffer */
3560 adev->txbuf_area_size = TX_CNT * /*WLAN_A4FR_MAXLEN_WEP_FCS*/ (30 + 2312 + 4);
3561 adev->txbuf_start = allocate(adev, adev->txbuf_area_size,
3562 &adev->txbuf_startphy, "txbuf_start");
3563 if (!adev->txbuf_start)
3564 goto fail;
3566 /* allocate the TX host descriptor queue pool */
3567 adev->txhostdesc_area_size = TX_CNT * 2 * sizeof(*hostdesc);
3568 adev->txhostdesc_start = allocate(adev, adev->txhostdesc_area_size,
3569 &adev->txhostdesc_startphy,
3570 "txhostdesc_start");
3571 if (!adev->txhostdesc_start)
3572 goto fail;
3573 /* check for proper alignment of TX host descriptor pool */
3574 if ((long)adev->txhostdesc_start & 3) {
3575 printk
3576 ("acx: driver bug: dma alloc returns unaligned address\n");
3577 goto fail;
3580 hostdesc = adev->txhostdesc_start;
3581 hostdesc_phy = adev->txhostdesc_startphy;
3582 txbuf = adev->txbuf_start;
3583 txbuf_phy = adev->txbuf_startphy;
3585 #if 0
3586 /* Each tx buffer is accessed by hardware via
3587 ** txdesc -> txhostdesc(s) -> txbuffer(s).
3588 ** We use only one txhostdesc per txdesc, but it looks like
3589 ** acx111 is buggy: it accesses second txhostdesc
3590 ** (via hostdesc.desc_phy_next field) even if
3591 ** txdesc->length == hostdesc->length and thus
3592 ** entire packet was placed into first txhostdesc.
3593 ** Due to this bug acx111 hangs unless second txhostdesc
3594 ** has le16_to_cpu(hostdesc.length) = 3 (or larger)
3595 ** Storing NULL into hostdesc.desc_phy_next
3596 ** doesn't seem to help.
3598 ** Update: although it worked on Xterasys XN-2522g
3599 ** with len=3 trick, WG311v2 is even more bogus, doesn't work.
3600 ** Keeping this code (#ifdef'ed out) for documentational purposes.
3602 for (i = 0; i < TX_CNT * 2; i++) {
3603 hostdesc_phy += sizeof(*hostdesc);
3604 if (!(i & 1)) {
3605 hostdesc->data_phy = cpu2acx(txbuf_phy);
3606 /* hostdesc->data_offset = ... */
3607 /* hostdesc->reserved = ... */
3608 hostdesc->Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
3609 /* hostdesc->length = ... */
3610 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3611 hostdesc->pNext = ptr2acx(NULL);
3612 /* hostdesc->Status = ... */
3613 /* below: non-hardware fields */
3614 hostdesc->data = txbuf;
3616 txbuf += WLAN_A4FR_MAXLEN_WEP_FCS;
3617 txbuf_phy += WLAN_A4FR_MAXLEN_WEP_FCS;
3618 } else {
3619 /* hostdesc->data_phy = ... */
3620 /* hostdesc->data_offset = ... */
3621 /* hostdesc->reserved = ... */
3622 /* hostdesc->Ctl_16 = ... */
3623 hostdesc->length = cpu_to_le16(3); /* bug workaround */
3624 /* hostdesc->desc_phy_next = ... */
3625 /* hostdesc->pNext = ... */
3626 /* hostdesc->Status = ... */
3627 /* below: non-hardware fields */
3628 /* hostdesc->data = ... */
3630 hostdesc++;
3632 #endif
3633 /* We initialize two hostdescs so that they point to adjacent
3634 ** memory areas. Thus txbuf is really just a contiguous memory area */
3635 for (i = 0; i < TX_CNT * 2; i++) {
3636 hostdesc_phy += sizeof(*hostdesc);
3638 hostdesc->data_phy = cpu2acx(txbuf_phy);
3639 /* done by memset(0): hostdesc->data_offset = 0; */
3640 /* hostdesc->reserved = ... */
3641 hostdesc->Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
3642 /* hostdesc->length = ... */
3643 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3644 /* done by memset(0): hostdesc->pNext = ptr2acx(NULL); */
3645 /* hostdesc->Status = ... */
3646 /* ->data is a non-hardware field: */
3647 hostdesc->data = txbuf;
3649 if (!(i & 1)) {
3650 txbuf += 24 /*WLAN_HDR_A3_LEN*/;
3651 txbuf_phy += 24 /*WLAN_HDR_A3_LEN*/;
3652 } else {
3653 txbuf += 30 + 2132 + 4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3654 txbuf_phy += 30 + 2132 +4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3656 hostdesc++;
3658 hostdesc--;
3659 hostdesc->desc_phy_next = cpu2acx(adev->txhostdesc_startphy);
3661 FN_EXIT1(OK);
3662 return OK;
3663 fail:
3664 printk("acx: create_tx_host_desc_queue FAILED\n");
3665 /* dealloc will be done by free function on error case */
3666 FN_EXIT1(NOT_OK);
3667 return NOT_OK;
3671 /***************************************************************
3672 ** acxpci_s_create_rx_host_desc_queue
3674 /* the whole size of a data buffer (header plus data body)
3675 * plus 32 bytes safety offset at the end */
3676 #define RX_BUFFER_SIZE (sizeof(rxbuffer_t) + 32)
3678 static int acxpci_s_create_rx_host_desc_queue(acx_device_t * adev)
3680 rxhostdesc_t *hostdesc;
3681 rxbuffer_t *rxbuf;
3682 dma_addr_t hostdesc_phy;
3683 dma_addr_t rxbuf_phy;
3684 int i;
3686 FN_ENTER;
3688 /* allocate the RX host descriptor queue pool */
3689 adev->rxhostdesc_area_size = RX_CNT * sizeof(*hostdesc);
3690 adev->rxhostdesc_start = allocate(adev, adev->rxhostdesc_area_size,
3691 &adev->rxhostdesc_startphy,
3692 "rxhostdesc_start");
3693 if (!adev->rxhostdesc_start)
3694 goto fail;
3695 /* check for proper alignment of RX host descriptor pool */
3696 if ((long)adev->rxhostdesc_start & 3) {
3697 printk
3698 ("acx: driver bug: dma alloc returns unaligned address\n");
3699 goto fail;
3702 /* allocate Rx buffer pool which will be used by the acx
3703 * to store the whole content of the received frames in it */
3704 adev->rxbuf_area_size = RX_CNT * RX_BUFFER_SIZE;
3705 adev->rxbuf_start = allocate(adev, adev->rxbuf_area_size,
3706 &adev->rxbuf_startphy, "rxbuf_start");
3707 if (!adev->rxbuf_start)
3708 goto fail;
3710 rxbuf = adev->rxbuf_start;
3711 rxbuf_phy = adev->rxbuf_startphy;
3712 hostdesc = adev->rxhostdesc_start;
3713 hostdesc_phy = adev->rxhostdesc_startphy;
3715 /* don't make any popular C programming pointer arithmetic mistakes
3716 * here, otherwise I'll kill you...
3717 * (and don't dare asking me why I'm warning you about that...) */
3718 for (i = 0; i < RX_CNT; i++) {
3719 hostdesc->data = rxbuf;
3720 hostdesc->data_phy = cpu2acx(rxbuf_phy);
3721 hostdesc->length = cpu_to_le16(RX_BUFFER_SIZE);
3722 CLEAR_BIT(hostdesc->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3723 rxbuf++;
3724 rxbuf_phy += sizeof(*rxbuf);
3725 hostdesc_phy += sizeof(*hostdesc);
3726 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3727 hostdesc++;
3729 hostdesc--;
3730 hostdesc->desc_phy_next = cpu2acx(adev->rxhostdesc_startphy);
3731 FN_EXIT1(OK);
3732 return OK;
3733 fail:
3734 printk("acx: create_rx_host_desc_queue FAILED\n");
3735 /* dealloc will be done by free function on error case */
3736 FN_EXIT1(NOT_OK);
3737 return NOT_OK;
3741 /***************************************************************
3742 ** acxpci_s_create_hostdesc_queues
3744 int acxpci_s_create_hostdesc_queues(acx_device_t * adev)
3746 int result;
3747 result = acxpci_s_create_tx_host_desc_queue(adev);
3748 if (OK != result)
3749 return result;
3750 result = acxpci_s_create_rx_host_desc_queue(adev);
3751 return result;
3755 /***************************************************************
3756 ** acxpci_create_tx_desc_queue
3758 static void acxpci_create_tx_desc_queue(acx_device_t * adev, u32 tx_queue_start)
3760 txdesc_t *txdesc;
3761 txhostdesc_t *hostdesc;
3762 dma_addr_t hostmemptr;
3763 u32 mem_offs;
3764 int i;
3766 FN_ENTER;
3768 if (IS_ACX100(adev))
3769 adev->txdesc_size = sizeof(*txdesc);
3770 else
3771 /* the acx111 txdesc is 4 bytes larger */
3772 adev->txdesc_size = sizeof(*txdesc) + 4;
3774 adev->txdesc_start = (txdesc_t *) (adev->iobase2 + tx_queue_start);
3776 log(L_DEBUG, "acx: adev->iobase2=%p\n"
3777 "acx: tx_queue_start=%08X\n"
3778 "acx: adev->txdesc_start=%p\n",
3779 adev->iobase2, tx_queue_start, adev->txdesc_start);
3781 adev->tx_free = TX_CNT;
3782 /* done by memset: adev->tx_head = 0; */
3783 /* done by memset: adev->tx_tail = 0; */
3784 txdesc = adev->txdesc_start;
3785 mem_offs = tx_queue_start;
3786 hostmemptr = adev->txhostdesc_startphy;
3787 hostdesc = adev->txhostdesc_start;
3789 if (IS_ACX111(adev)) {
3790 /* ACX111 has a preinitialized Tx buffer! */
3791 /* loop over whole send pool */
3792 /* FIXME: do we have to do the hostmemptr stuff here?? */
3793 for (i = 0; i < TX_CNT; i++) {
3794 txdesc->HostMemPtr = ptr2acx(hostmemptr);
3795 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3796 /* reserve two (hdr desc and payload desc) */
3797 hostdesc += 2;
3798 hostmemptr += 2 * sizeof(*hostdesc);
3799 txdesc = advance_txdesc(adev, txdesc, 1);
3801 } else {
3802 /* ACX100 Tx buffer needs to be initialized by us */
3803 /* clear whole send pool. sizeof is safe here (we are acx100) */
3804 memset(adev->txdesc_start, 0, TX_CNT * sizeof(*txdesc));
3806 /* loop over whole send pool */
3807 for (i = 0; i < TX_CNT; i++) {
3808 log(L_DEBUG, "acx: configure card tx descriptor: 0x%p, "
3809 "size: 0x%X\n", txdesc, adev->txdesc_size);
3811 /* pointer to hostdesc memory */
3812 txdesc->HostMemPtr = ptr2acx(hostmemptr);
3813 /* initialise ctl */
3814 txdesc->Ctl_8 = (DESC_CTL_HOSTOWN | DESC_CTL_RECLAIM
3815 | DESC_CTL_AUTODMA |
3816 DESC_CTL_FIRSTFRAG);
3817 /* done by memset(0): txdesc->Ctl2_8 = 0; */
3818 /* point to next txdesc */
3819 txdesc->pNextDesc =
3820 cpu2acx(mem_offs + adev->txdesc_size);
3821 /* reserve two (hdr desc and payload desc) */
3822 hostdesc += 2;
3823 hostmemptr += 2 * sizeof(*hostdesc);
3824 /* go to the next one */
3825 mem_offs += adev->txdesc_size;
3826 /* ++ is safe here (we are acx100) */
3827 txdesc++;
3829 /* go back to the last one */
3830 txdesc--;
3831 /* and point to the first making it a ring buffer */
3832 txdesc->pNextDesc = cpu2acx(tx_queue_start);
3834 FN_EXIT0;
3838 /***************************************************************
3839 ** acxpci_create_rx_desc_queue
3841 static void acxpci_create_rx_desc_queue(acx_device_t * adev, u32 rx_queue_start)
3843 rxdesc_t *rxdesc;
3844 u32 mem_offs;
3845 int i;
3847 FN_ENTER;
3849 /* done by memset: adev->rx_tail = 0; */
3851 /* ACX111 doesn't need any further config: preconfigures itself.
3852 * Simply print ring buffer for debugging */
3853 if (IS_ACX111(adev)) {
3854 /* rxdesc_start already set here */
3856 adev->rxdesc_start =
3857 (rxdesc_t *) ((u8 *) adev->iobase2 + rx_queue_start);
3859 rxdesc = adev->rxdesc_start;
3860 for (i = 0; i < RX_CNT; i++) {
3861 log(L_DEBUG, "acx: rx descriptor %d @ 0x%p\n", i, rxdesc);
3862 rxdesc = adev->rxdesc_start = (rxdesc_t *)
3863 (adev->iobase2 + acx2cpu(rxdesc->pNextDesc));
3865 } else {
3866 /* we didn't pre-calculate rxdesc_start in case of ACX100 */
3867 /* rxdesc_start should be right AFTER Tx pool */
3868 adev->rxdesc_start = (rxdesc_t *)
3869 ((u8 *) adev->txdesc_start + (TX_CNT * sizeof(txdesc_t)));
3870 /* NB: sizeof(txdesc_t) above is valid because we know
3871 ** we are in if (acx100) block. Beware of cut-n-pasting elsewhere!
3872 ** acx111's txdesc is larger! */
3874 memset(adev->rxdesc_start, 0, RX_CNT * sizeof(*rxdesc));
3876 /* loop over whole receive pool */
3877 rxdesc = adev->rxdesc_start;
3878 mem_offs = rx_queue_start;
3879 for (i = 0; i < RX_CNT; i++) {
3880 log(L_DEBUG, "acx: rx descriptor @ 0x%p\n", rxdesc);
3881 rxdesc->Ctl_8 = DESC_CTL_RECLAIM | DESC_CTL_AUTODMA;
3882 /* point to next rxdesc */
3883 rxdesc->pNextDesc = cpu2acx(mem_offs + sizeof(*rxdesc));
3884 /* go to the next one */
3885 mem_offs += sizeof(*rxdesc);
3886 rxdesc++;
3888 /* go to the last one */
3889 rxdesc--;
3891 /* and point to the first making it a ring buffer */
3892 rxdesc->pNextDesc = cpu2acx(rx_queue_start);
3894 FN_EXIT0;
3898 /***************************************************************
3899 ** acxpci_create_desc_queues
3901 void
3902 acxpci_create_desc_queues(acx_device_t * adev, u32 tx_queue_start,
3903 u32 rx_queue_start)
3905 acxpci_create_tx_desc_queue(adev, tx_queue_start);
3906 acxpci_create_rx_desc_queue(adev, rx_queue_start);
3910 /***************************************************************
3911 ** acxpci_s_proc_diag_output
3913 char *acxpci_s_proc_diag_output(char *p, acx_device_t * adev)
3915 const char *rtl, *thd, *ttl;
3916 rxhostdesc_t *rxhostdesc;
3917 txdesc_t *txdesc;
3918 int i;
3920 FN_ENTER;
3922 p += sprintf(p, "** Rx buf **\n");
3923 rxhostdesc = adev->rxhostdesc_start;
3924 if (rxhostdesc)
3925 for (i = 0; i < RX_CNT; i++) {
3926 rtl = (i == adev->rx_tail) ? " [tail]" : "";
3927 if ((rxhostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
3928 && (rxhostdesc->
3929 Status & cpu_to_le32(DESC_STATUS_FULL)))
3930 p += sprintf(p, "%02u FULL%s\n", i, rtl);
3931 else
3932 p += sprintf(p, "%02u empty%s\n", i, rtl);
3933 rxhostdesc++;
3935 /* p += sprintf(p, "** Tx buf (free %d, Linux netqueue %s) **\n",
3936 adev->tx_free,
3937 acx_queue_stopped(adev->ieee) ? "STOPPED" : "running");*/
3938 txdesc = adev->txdesc_start;
3939 if (txdesc)
3940 for (i = 0; i < TX_CNT; i++) {
3941 thd = (i == adev->tx_head) ? " [head]" : "";
3942 ttl = (i == adev->tx_tail) ? " [tail]" : "";
3943 if (txdesc->Ctl_8 & DESC_CTL_ACXDONE)
3944 p += sprintf(p, "%02u free (%02X)%s%s\n", i,
3945 txdesc->Ctl_8, thd, ttl);
3946 else
3947 p += sprintf(p, "%02u tx (%02X)%s%s\n", i,
3948 txdesc->Ctl_8, thd, ttl);
3949 txdesc = advance_txdesc(adev, txdesc, 1);
3951 p += sprintf(p,
3952 "\n"
3953 "** PCI data **\n"
3954 "txbuf_start %p, txbuf_area_size %u, txbuf_startphy %08llx\n"
3955 "txdesc_size %u, txdesc_start %p\n"
3956 "txhostdesc_start %p, txhostdesc_area_size %u, txhostdesc_startphy %08llx\n"
3957 "rxdesc_start %p\n"
3958 "rxhostdesc_start %p, rxhostdesc_area_size %u, rxhostdesc_startphy %08llx\n"
3959 "rxbuf_start %p, rxbuf_area_size %u, rxbuf_startphy %08llx\n",
3960 adev->txbuf_start, adev->txbuf_area_size,
3961 (unsigned long long)adev->txbuf_startphy,
3962 adev->txdesc_size, adev->txdesc_start,
3963 adev->txhostdesc_start, adev->txhostdesc_area_size,
3964 (unsigned long long)adev->txhostdesc_startphy,
3965 adev->rxdesc_start,
3966 adev->rxhostdesc_start, adev->rxhostdesc_area_size,
3967 (unsigned long long)adev->rxhostdesc_startphy,
3968 adev->rxbuf_start, adev->rxbuf_area_size,
3969 (unsigned long long)adev->rxbuf_startphy);
3971 FN_EXIT0;
3972 return p;
3976 /***********************************************************************
3978 int acxpci_proc_eeprom_output(char *buf, acx_device_t * adev)
3980 char *p = buf;
3981 int i;
3983 FN_ENTER;
3985 for (i = 0; i < 0x400; i++) {
3986 acxpci_read_eeprom_byte(adev, i, p++);
3989 FN_EXIT1(p - buf);
3990 return p - buf;
3994 /***********************************************************************
3995 ** Obvious
3997 void acxpci_set_interrupt_mask(acx_device_t * adev)
3999 if (IS_ACX111(adev)) {
4000 adev->irq_mask = (u16) ~ (0
4001 /* | HOST_INT_RX_DATA */
4002 | HOST_INT_TX_COMPLETE
4003 /* | HOST_INT_TX_XFER */
4004 | HOST_INT_RX_COMPLETE
4005 /* | HOST_INT_DTIM */
4006 /* | HOST_INT_BEACON */
4007 /* | HOST_INT_TIMER */
4008 /* | HOST_INT_KEY_NOT_FOUND */
4009 | HOST_INT_IV_ICV_FAILURE
4010 | HOST_INT_CMD_COMPLETE
4011 | HOST_INT_INFO
4012 /* | HOST_INT_OVERFLOW */
4013 /* | HOST_INT_PROCESS_ERROR */
4014 | HOST_INT_SCAN_COMPLETE
4015 | HOST_INT_FCS_THRESHOLD
4016 /* | HOST_INT_UNKNOWN */
4018 /* Or else acx100 won't signal cmd completion, right? */
4019 adev->irq_mask_off = (u16) ~ (HOST_INT_CMD_COMPLETE); /* 0xfdff */
4020 } else {
4021 adev->irq_mask = (u16) ~ (0
4022 /* | HOST_INT_RX_DATA */
4023 | HOST_INT_TX_COMPLETE
4024 /* | HOST_INT_TX_XFER */
4025 | HOST_INT_RX_COMPLETE
4026 /* | HOST_INT_DTIM */
4027 /* | HOST_INT_BEACON */
4028 /* | HOST_INT_TIMER */
4029 /* | HOST_INT_KEY_NOT_FOUND */
4030 /* | HOST_INT_IV_ICV_FAILURE */
4031 | HOST_INT_CMD_COMPLETE
4032 | HOST_INT_INFO
4033 /* | HOST_INT_OVERFLOW */
4034 /* | HOST_INT_PROCESS_ERROR */
4035 | HOST_INT_SCAN_COMPLETE
4036 /* | HOST_INT_FCS_THRESHOLD */
4037 /* | HOST_INT_UNKNOWN */
4039 adev->irq_mask_off = (u16) ~ (HOST_INT_UNKNOWN); /* 0x7fff */
4044 /***********************************************************************
4046 int acx100pci_s_set_tx_level(acx_device_t * adev, u8 level_dbm)
4048 /* since it can be assumed that at least the Maxim radio has a
4049 * maximum power output of 20dBm and since it also can be
4050 * assumed that these values drive the DAC responsible for
4051 * setting the linear Tx level, I'd guess that these values
4052 * should be the corresponding linear values for a dBm value,
4053 * in other words: calculate the values from that formula:
4054 * Y [dBm] = 10 * log (X [mW])
4055 * then scale the 0..63 value range onto the 1..100mW range (0..20 dBm)
4056 * and you're done...
4057 * Hopefully that's ok, but you never know if we're actually
4058 * right... (especially since Windows XP doesn't seem to show
4059 * actual Tx dBm values :-P) */
4061 /* NOTE: on Maxim, value 30 IS 30mW, and value 10 IS 10mW - so the
4062 * values are EXACTLY mW!!! Not sure about RFMD and others,
4063 * though... */
4064 static const u8 dbm2val_maxim[21] = {
4065 63, 63, 63, 62,
4066 61, 61, 60, 60,
4067 59, 58, 57, 55,
4068 53, 50, 47, 43,
4069 38, 31, 23, 13,
4072 static const u8 dbm2val_rfmd[21] = {
4073 0, 0, 0, 1,
4074 2, 2, 3, 3,
4075 4, 5, 6, 8,
4076 10, 13, 16, 20,
4077 25, 32, 41, 50,
4080 const u8 *table;
4082 switch (adev->radio_type) {
4083 case RADIO_MAXIM_0D:
4084 table = &dbm2val_maxim[0];
4085 break;
4086 case RADIO_RFMD_11:
4087 case RADIO_RALINK_15:
4088 table = &dbm2val_rfmd[0];
4089 break;
4090 default:
4091 printk("acx: %s: unknown/unsupported radio type, "
4092 "cannot modify tx power level yet!\n", wiphy_name(adev->ieee->wiphy));
4093 return NOT_OK;
4095 printk("acx: %s: changing radio power level to %u dBm (%u)\n",
4096 wiphy_name(adev->ieee->wiphy), level_dbm, table[level_dbm]);
4097 acxpci_s_write_phy_reg(adev, 0x11, table[level_dbm]);
4098 return OK;
4101 #ifdef CONFIG_VLYNQ
4102 struct vlynq_reg_config {
4103 u32 offset;
4104 u32 value;
4107 struct vlynq_known {
4108 u32 chip_id;
4109 char name[32];
4110 struct vlynq_mapping rx_mapping[4];
4111 int irq;
4112 int irq_type;
4113 int num_regs;
4114 struct vlynq_reg_config regs[10];
4117 #define CHIP_TNETW1130 0x00000009
4118 #define CHIP_TNETW1350 0x00000029
4120 static struct vlynq_known known_devices[] = {
4122 .chip_id = CHIP_TNETW1130, .name = "TI TNETW1130",
4123 .rx_mapping = {
4124 { .size = 0x22000, .offset = 0xf0000000 },
4125 { .size = 0x40000, .offset = 0xc0000000 },
4126 { .size = 0x0, .offset = 0x0 },
4127 { .size = 0x0, .offset = 0x0 },
4129 .irq = 0,
4130 .irq_type = IRQ_TYPE_EDGE_RISING,
4131 .num_regs = 5,
4132 .regs = {
4134 .offset = 0x790,
4135 .value = (0xd0000000 - PHYS_OFFSET)
4138 .offset = 0x794,
4139 .value = (0xd0000000 - PHYS_OFFSET)
4141 { .offset = 0x740, .value = 0 },
4142 { .offset = 0x744, .value = 0x00010000 },
4143 { .offset = 0x764, .value = 0x00010000 },
4147 .chip_id = CHIP_TNETW1350, .name = "TI TNETW1350",
4148 .rx_mapping = {
4149 { .size = 0x100000, .offset = 0x00300000 },
4150 { .size = 0x80000, .offset = 0x00000000 },
4151 { .size = 0x0, .offset = 0x0 },
4152 { .size = 0x0, .offset = 0x0 },
4154 .irq = 0,
4155 .irq_type = IRQ_TYPE_EDGE_RISING,
4156 .num_regs = 5,
4157 .regs = {
4159 .offset = 0x790,
4160 .value = (0x60000000 - PHYS_OFFSET)
4163 .offset = 0x794,
4164 .value = (0x60000000 - PHYS_OFFSET)
4166 { .offset = 0x740, .value = 0 },
4167 { .offset = 0x744, .value = 0x00010000 },
4168 { .offset = 0x764, .value = 0x00010000 },
4173 static struct vlynq_device_id acx_vlynq_id[] = {
4174 { CHIP_TNETW1130, vlynq_div_auto, 0 },
4175 { CHIP_TNETW1350, vlynq_div_auto, 1 },
4176 { 0, 0, 0 },
4179 static __devinit int vlynq_probe(struct vlynq_device *vdev,
4180 struct vlynq_device_id *id)
4182 int result = -EIO, i;
4183 u32 addr;
4184 struct ieee80211_hw *ieee;
4185 acx_device_t *adev = NULL;
4186 acx111_ie_configoption_t co;
4187 struct vlynq_mapping mapping[4] = { { 0, }, };
4188 struct vlynq_known *match = NULL;
4190 FN_ENTER;
4191 result = vlynq_enable_device(vdev);
4192 if (result)
4193 return result;
4195 match = &known_devices[id->driver_data];
4197 if (!match) {
4198 result = -ENODEV;
4199 goto fail;
4202 mapping[0].offset = ARCH_PFN_OFFSET << PAGE_SHIFT;
4203 mapping[0].size = 0x02000000;
4204 vlynq_set_local_mapping(vdev, vdev->mem_start, mapping);
4205 vlynq_set_remote_mapping(vdev, 0, match->rx_mapping);
4207 set_irq_type(vlynq_virq_to_irq(vdev, match->irq), match->irq_type);
4209 addr = (u32)ioremap(vdev->mem_start, 0x1000);
4210 if (!addr) {
4211 printk(KERN_ERR "acx: %s: failed to remap io memory\n",
4212 vdev->dev.bus_id);
4213 result = -ENXIO;
4214 goto fail;
4217 for (i = 0; i < match->num_regs; i++)
4218 iowrite32(match->regs[i].value,
4219 (u32 *)(addr + match->regs[i].offset));
4221 iounmap((void *)addr);
4223 ieee = ieee80211_alloc_hw(sizeof(struct acx_device), &acxpci_hw_ops);
4224 if (!ieee) {
4225 printk("acx: could not allocate ieee80211 structure %s\n",
4226 vdev->dev.bus_id);
4227 goto fail_alloc_netdev;
4229 ieee->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
4230 ieee->queues = 1;
4232 adev = ieee2adev(ieee);
4234 memset(adev, 0, sizeof(*adev));
4235 /** Set up our private interface **/
4236 spin_lock_init(&adev->spinlock); /* initial state: unlocked */
4237 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
4238 mutex_init(&adev->mutex);
4239 /* since nobody can see new netdev yet, we can as well
4240 ** just _presume_ that we're under sem (instead of actually taking it): */
4241 /* acx_sem_lock(adev); */
4242 adev->ieee = ieee;
4243 adev->vdev = vdev;
4244 adev->bus_dev = &vdev->dev;
4245 adev->dev_type = DEVTYPE_PCI;
4247 /** Finished with private interface **/
4249 vlynq_set_drvdata(vdev, ieee);
4250 if (!request_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start, "acx")) {
4251 printk("acx: cannot reserve VLYNQ memory region\n");
4252 goto fail_request_mem_region;
4255 adev->iobase = ioremap(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4256 if (!adev->iobase) {
4257 printk("acx: ioremap() FAILED\n");
4258 goto fail_ioremap;
4260 adev->iobase2 = adev->iobase + match->rx_mapping[0].size;
4261 adev->chip_type = CHIPTYPE_ACX111;
4262 adev->chip_name = match->name;
4263 adev->io = IO_ACX111;
4264 adev->irq = vlynq_virq_to_irq(vdev, match->irq);
4266 printk("acx: found %s-based wireless network card at %s, irq:%d, "
4267 "phymem:0x%x, mem:0x%p\n",
4268 match->name, vdev->dev.bus_id, adev->irq,
4269 vdev->mem_start, adev->iobase);
4270 log(L_ANY, "acx: the initial debug setting is 0x%04X\n", acx_debug);
4272 if (0 == adev->irq) {
4273 printk("acx: can't use IRQ 0\n");
4274 goto fail_irq;
4276 SET_IEEE80211_DEV(ieee, &vdev->dev);
4278 /* request shared IRQ handler */
4279 if (request_irq
4280 (adev->irq, acxpci_i_interrupt, IRQF_SHARED, KBUILD_MODNAME, adev)) {
4281 printk("acx: %s: request_irq FAILED\n", wiphy_name(adev->ieee->wiphy));
4282 result = -EAGAIN;
4283 goto done;
4285 log(L_DEBUG | L_IRQ, "acx: request_irq %d successful\n", adev->irq);
4287 /* to find crashes due to weird driver access
4288 * to unconfigured interface (ifup) */
4289 adev->mgmt_timer.function = (void (*)(unsigned long))0x0000dead;
4292 /* ok, pci setup is finished, now start initializing the card */
4294 /* NB: read_reg() reads may return bogus data before reset_dev(),
4295 * since the firmware which directly controls large parts of the I/O
4296 * registers isn't initialized yet.
4297 * acx100 seems to be more affected than acx111 */
4298 if (OK != acxpci_s_reset_dev(adev))
4299 goto fail_reset;
4301 if (OK != acx_s_init_mac(adev))
4302 goto fail_init_mac;
4304 acx_s_interrogate(adev, &co, ACX111_IE_CONFIG_OPTIONS);
4305 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
4306 if (OK != acxpci_read_eeprom_byte(adev, 0x05, &adev->eeprom_version))
4307 goto fail_read_eeprom_version;
4309 acx_s_parse_configoption(adev, &co);
4310 acx_s_set_defaults(adev);
4311 acx_s_get_firmware_version(adev); /* needs to be after acx_s_init_mac() */
4312 acx_display_hardware_details(adev);
4314 /* Register the card, AFTER everything else has been set up,
4315 * since otherwise an ioctl could step on our feet due to
4316 * firmware operations happening in parallel or uninitialized data */
4319 acx_proc_register_entries(ieee);
4321 /* Now we have our device, so make sure the kernel doesn't try
4322 * to send packets even though we're not associated to a network yet */
4324 /* after register_netdev() userspace may start working with dev
4325 * (in particular, on other CPUs), we only need to up the sem */
4326 /* acx_sem_unlock(adev); */
4328 printk("acx: acx " ACX_RELEASE ": net device %s, driver compiled "
4329 "against wireless extensions %d and Linux %s\n",
4330 wiphy_name(adev->ieee->wiphy), WIRELESS_EXT, UTS_RELEASE);
4332 MAC_COPY(adev->ieee->wiphy->perm_addr, adev->dev_addr);
4334 log(L_IRQ | L_INIT, "acx: using IRQ %d\n", adev->irq);
4336 /** done with board specific setup **/
4338 result = acx_setup_modes(adev);
4339 if (result) {
4340 printk("acx: can't register hwmode\n");
4341 goto fail_register_netdev;
4344 acx_init_task_scheduler(adev);
4345 result = ieee80211_register_hw(adev->ieee);
4346 if (OK != result) {
4347 printk("acx: ieee80211_register_hw() FAILED: %d\n", result);
4348 goto fail_register_netdev;
4350 #if CMD_DISCOVERY
4351 great_inquisitor(adev);
4352 #endif
4354 result = OK;
4355 goto done;
4357 /* error paths: undo everything in reverse order... */
4360 acxpci_s_delete_dma_regions(adev);
4362 fail_init_mac:
4363 fail_read_eeprom_version:
4364 fail_reset:
4366 fail_alloc_netdev:
4367 fail_irq:
4369 iounmap(adev->iobase);
4370 fail_ioremap:
4372 release_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4373 fail_request_mem_region:
4374 fail_register_netdev:
4375 ieee80211_free_hw(ieee);
4376 fail:
4377 vlynq_disable_device(vdev);
4378 done:
4379 FN_EXIT1(result);
4380 return result;
4383 static void vlynq_remove(struct vlynq_device *vdev)
4385 struct ieee80211_hw *hw = vlynq_get_drvdata(vdev);
4386 acx_device_t *adev = ieee2adev(hw);
4387 unsigned long flags;
4388 FN_ENTER;
4390 if (!hw) {
4391 log(L_DEBUG, "acx: %s: card is unused. Skipping any release code\n",
4392 __func__);
4393 goto end;
4397 acx_lock(adev, flags);
4398 acx_unlock(adev, flags);
4399 adev->initialized = 0;
4401 /* If device wasn't hot unplugged... */
4402 if (adev_present(adev)) {
4404 acx_sem_lock(adev);
4406 /* disable both Tx and Rx to shut radio down properly */
4407 if (adev->initialized) {
4408 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_TX, NULL, 0);
4409 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_RX, NULL, 0);
4411 acx_lock(adev, flags);
4412 /* disable power LED to save power :-) */
4413 log(L_INIT, "acx: switching off power LED to save power\n");
4414 acxpci_l_power_led(adev, 0);
4415 /* stop our eCPU */
4416 acx_unlock(adev, flags);
4418 acx_sem_unlock(adev);
4421 /* unregister the device to not let the kernel
4422 * (e.g. ioctls) access a half-deconfigured device
4423 * NB: this will cause acxpci_e_close() to be called,
4424 * thus we shouldn't call it under sem!
4426 acxpci_e_close(hw);
4427 log(L_INIT, "acx: removing device %s\n", wiphy_name(adev->ieee->wiphy));
4428 ieee80211_unregister_hw(adev->ieee);
4430 /* unregister_netdev ensures that no references to us left.
4431 * For paranoid reasons we continue to follow the rules */
4432 acx_sem_lock(adev);
4434 if (adev->dev_state_mask & ACX_STATE_IFACE_UP) {
4435 acxpci_s_down(hw);
4436 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
4439 acx_proc_unregister_entries(adev->ieee);
4441 /* finally, clean up PCI bus state */
4442 acxpci_s_delete_dma_regions(adev);
4443 if (adev->iobase)
4444 iounmap(adev->iobase);
4445 if (adev->iobase2)
4446 iounmap(adev->iobase2);
4447 release_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4449 /* remove dev registration */
4451 acx_sem_unlock(adev);
4452 vlynq_disable_device(vdev);
4454 /* Free netdev (quite late,
4455 * since otherwise we might get caught off-guard
4456 * by a netdev timeout handler execution
4457 * expecting to see a working dev...) */
4458 ieee80211_free_hw(adev->ieee);
4460 end:
4461 FN_EXIT0;
4464 static struct vlynq_driver vlynq_acx = {
4465 .name = "acx_vlynq",
4466 .id_table = acx_vlynq_id,
4467 .probe = vlynq_probe,
4468 .remove = __devexit_p(vlynq_remove),
4470 #endif /* CONFIG_VLYNQ */
4473 /***********************************************************************
4474 ** Data for init_module/cleanup_module
4476 #ifdef CONFIG_PCI
4477 static const struct pci_device_id acxpci_id_tbl[] __devinitdata = {
4479 .vendor = PCI_VENDOR_ID_TI,
4480 .device = PCI_DEVICE_ID_TI_TNETW1100A,
4481 .subvendor = PCI_ANY_ID,
4482 .subdevice = PCI_ANY_ID,
4483 .driver_data = CHIPTYPE_ACX100,
4486 .vendor = PCI_VENDOR_ID_TI,
4487 .device = PCI_DEVICE_ID_TI_TNETW1100B,
4488 .subvendor = PCI_ANY_ID,
4489 .subdevice = PCI_ANY_ID,
4490 .driver_data = CHIPTYPE_ACX100,
4493 .vendor = PCI_VENDOR_ID_TI,
4494 .device = PCI_DEVICE_ID_TI_TNETW1130,
4495 .subvendor = PCI_ANY_ID,
4496 .subdevice = PCI_ANY_ID,
4497 .driver_data = CHIPTYPE_ACX111,
4500 .vendor = 0,
4501 .device = 0,
4502 .subvendor = 0,
4503 .subdevice = 0,
4504 .driver_data = 0,
4508 MODULE_DEVICE_TABLE(pci, acxpci_id_tbl);
4510 static struct pci_driver
4511 acxpci_drv_id = {
4512 .name = "acx_pci",
4513 .id_table = acxpci_id_tbl,
4514 .probe = acxpci_e_probe,
4515 .remove = __devexit_p(acxpci_e_remove),
4516 #ifdef CONFIG_PM
4517 .suspend = acxpci_e_suspend,
4518 .resume = acxpci_e_resume
4519 #endif /* CONFIG_PM */
4521 #endif /* CONFIG_PCI */
4523 /***********************************************************************
4524 ** acxpci_e_init_module
4526 ** Module initialization routine, called once at module load time
4528 int __init acxpci_e_init_module(void)
4530 int res;
4532 FN_ENTER;
4534 printk(KERN_EMERG);
4536 #if (ACX_IO_WIDTH==32)
4537 log(L_INIT, "acx: compiled to use 32bit I/O access. "
4538 "I/O timing issues might occur, such as "
4539 "non-working firmware upload. Report them\n");
4540 #else
4541 log(L_INIT, "acx: compiled to use 16bit I/O access only "
4542 "(compatibility mode)\n");
4543 #endif
4545 #ifdef __LITTLE_ENDIAN
4546 #define ENDIANNESS_STRING "running on a little-endian CPU\n"
4547 #else
4548 #define ENDIANNESS_STRING "running on a BIG-ENDIAN CPU\n"
4549 #endif
4550 log(L_INIT,
4551 "acx: " ENDIANNESS_STRING
4552 " PCI/VLYNQ module " ACX_RELEASE " initialized, "
4553 "waiting for cards to probe...\n");
4555 #ifdef CONFIG_PCI
4556 res = pci_register_driver(&acxpci_drv_id);
4557 #elif CONFIG_VLYNQ
4558 res = vlynq_register_driver(&vlynq_acx);
4559 #endif
4561 if (res) {
4562 printk(KERN_ERR "acx_pci: can't register pci/vlynq driver\n");
4565 FN_EXIT1(res);
4566 return res;
4570 /***********************************************************************
4571 ** acxpci_e_cleanup_module
4573 ** Called at module unload time. This is our last chance to
4574 ** clean up after ourselves.
4576 void __exit acxpci_e_cleanup_module(void)
4578 FN_ENTER;
4580 #ifdef CONFIG_PCI
4581 pci_unregister_driver(&acxpci_drv_id);
4582 #elif CONFIG_VLYNQ
4583 vlynq_unregister_driver(&vlynq_acx);
4584 #endif
4585 log(L_INIT,
4586 "acx: PCI module " ACX_RELEASE " unloaded\n");
4587 FN_EXIT0;