comment unused function (update_link_quality_led) to avoid compiler warnings
[acx-mac80211.git] / pci.c
blobacbbc740c75b79b73b23703303353029e5f5f8a3
1 /**** (legal) claimer in README
2 ** Copyright (C) 2003 ACX100 Open Source Project
3 */
4 #define ACX_MAC80211_PCI 1
6 #include <linux/version.h>
7 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 18)
8 #include <linux/config.h>
9 #endif
11 /* Linux 2.6.18+ uses <linux/utsrelease.h> */
12 #ifndef UTS_RELEASE
13 #include <linux/utsrelease.h>
14 #endif
16 #include <linux/compiler.h> /* required for Lx 2.6.8 ?? */
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/moduleparam.h>
20 #include <linux/sched.h>
21 #include <linux/types.h>
22 #include <linux/skbuff.h>
23 #include <linux/slab.h>
24 #include <linux/if_arp.h>
25 #include <linux/rtnetlink.h>
26 #include <linux/wireless.h>
27 #include <net/iw_handler.h>
28 #include <linux/netdevice.h>
29 #include <linux/ioport.h>
30 #include <linux/pci.h>
31 #include <linux/pm.h>
32 #include <linux/vmalloc.h>
33 #include <linux/ethtool.h>
34 #include <linux/dma-mapping.h>
35 #include <linux/workqueue.h>
36 #ifdef CONFIG_VLYNQ
37 #include <linux/vlynq.h>
38 #endif
40 #include "acx.h"
42 /***********************************************************************
44 #ifdef CONFIG_PCI
45 #define PCI_TYPE (PCI_USES_MEM | PCI_ADDR0 | PCI_NO_ACPI_WAKE)
46 #define PCI_ACX100_REGION1 0x01
47 #define PCI_ACX100_REGION1_SIZE 0x1000 /* Memory size - 4K bytes */
48 #define PCI_ACX100_REGION2 0x02
49 #define PCI_ACX100_REGION2_SIZE 0x10000 /* Memory size - 64K bytes */
51 #define PCI_ACX111_REGION1 0x00
52 #define PCI_ACX111_REGION1_SIZE 0x2000 /* Memory size - 8K bytes */
53 #define PCI_ACX111_REGION2 0x01
54 #define PCI_ACX111_REGION2_SIZE 0x20000 /* Memory size - 128K bytes */
56 /* Texas Instruments Vendor ID */
57 #define PCI_VENDOR_ID_TI 0x104c
59 /* ACX100 22Mb/s WLAN controller */
60 #define PCI_DEVICE_ID_TI_TNETW1100A 0x8400
61 #define PCI_DEVICE_ID_TI_TNETW1100B 0x8401
63 /* ACX111 54Mb/s WLAN controller */
64 #define PCI_DEVICE_ID_TI_TNETW1130 0x9066
66 /* PCI Class & Sub-Class code, Network-'Other controller' */
67 #define PCI_CLASS_NETWORK_OTHERS 0x0280
69 #define CARD_EEPROM_ID_SIZE 6
71 #ifndef PCI_D0
72 /* From include/linux/pci.h */
73 #define PCI_D0 0
74 #define PCI_D1 1
75 #define PCI_D2 2
76 #define PCI_D3hot 3
77 #define PCI_D3cold 4
78 #define PCI_UNKNOWN 5
79 #define PCI_POWER_ERROR -1
80 #endif
81 #endif /* CONFIG_PCI */
83 /***********************************************************************
86 static irqreturn_t acxpci_i_interrupt(int irq, void *dev_id);
88 static void disable_acx_irq(acx_device_t * adev);
90 static int acxpci_e_open(struct ieee80211_hw *hw);
91 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
92 static int acxpci_e_close(struct ieee80211_hw *hw);
93 #else
94 static void acxpci_e_close(struct ieee80211_hw *hw);
95 #endif
96 static void acxpci_s_up(struct ieee80211_hw *hw);
97 static void acxpci_s_down(struct ieee80211_hw *hw);
99 void acxpci_put_devname(acx_device_t *adev, struct ethtool_drvinfo *info)
101 strncpy(info->bus_info,pci_name(adev->pdev), ETHTOOL_BUSINFO_LEN);
104 /***********************************************************************
105 ** Register access
110 /* OS I/O routines *always* be endianness-clean but having them doesn't hurt */
111 #define acx_readl(v) le32_to_cpu(readl((v)))
112 #define acx_readw(v) le16_to_cpu(readw((v)))
113 #define acx_writew(v,r) writew(le16_to_cpu((v)), r)
114 #define acx_writel(v,r) writel(le32_to_cpu((v)), r)
116 /* Pick one */
117 /* #define INLINE_IO static */
118 #define INLINE_IO static inline
120 INLINE_IO u32 read_reg32(acx_device_t * adev, unsigned int offset)
122 #if ACX_IO_WIDTH == 32
123 return acx_readl((u8 *) adev->iobase + adev->io[offset]);
124 #else
125 return acx_readw((u8 *) adev->iobase + adev->io[offset])
126 + (acx_readw((u8 *) adev->iobase + adev->io[offset] + 2) << 16);
127 #endif
130 INLINE_IO u16 read_reg16(acx_device_t * adev, unsigned int offset)
132 return acx_readw((u8 *) adev->iobase + adev->io[offset]);
135 INLINE_IO u8 read_reg8(acx_device_t * adev, unsigned int offset)
137 return readb((u8 *) adev->iobase + adev->io[offset]);
140 INLINE_IO void write_reg32(acx_device_t * adev, unsigned int offset, u32 val)
142 #if ACX_IO_WIDTH == 32
143 acx_writel(val, (u8 *) adev->iobase + adev->io[offset]);
144 #else
145 acx_writew(val & 0xffff, (u8 *) adev->iobase + adev->io[offset]);
146 acx_writew(val >> 16, (u8 *) adev->iobase + adev->io[offset] + 2);
147 #endif
150 INLINE_IO void write_reg16(acx_device_t * adev, unsigned int offset, u16 val)
152 acx_writew(val, (u8 *) adev->iobase + adev->io[offset]);
155 INLINE_IO void write_reg8(acx_device_t * adev, unsigned int offset, u8 val)
157 writeb(val, (u8 *) adev->iobase + adev->io[offset]);
160 /* Handle PCI posting properly:
161 * Make sure that writes reach the adapter in case they require to be executed
162 * *before* the next write, by reading a random (and safely accessible) register.
163 * This call has to be made if there is no read following (which would flush the data
164 * to the adapter), yet the written data has to reach the adapter immediately. */
165 INLINE_IO void write_flush(acx_device_t * adev)
167 /* readb(adev->iobase + adev->io[IO_ACX_INFO_MAILBOX_OFFS]); */
168 /* faster version (accesses the first register, IO_ACX_SOFT_RESET,
169 * which should also be safe): */
170 readb(adev->iobase);
173 INLINE_IO int adev_present(acx_device_t * adev)
175 /* fast version (accesses the first register, IO_ACX_SOFT_RESET,
176 * which should be safe): */
177 return acx_readl(adev->iobase) != 0xffffffff;
181 /***********************************************************************
183 static inline txdesc_t *get_txdesc(acx_device_t * adev, int index)
185 return (txdesc_t *) (((u8 *) adev->txdesc_start) +
186 index * adev->txdesc_size);
189 static inline txdesc_t *advance_txdesc(acx_device_t * adev, txdesc_t * txdesc,
190 int inc)
192 return (txdesc_t *) (((u8 *) txdesc) + inc * adev->txdesc_size);
195 static txhostdesc_t *get_txhostdesc(acx_device_t * adev, txdesc_t * txdesc)
197 int index = (u8 *) txdesc - (u8 *) adev->txdesc_start;
198 if (unlikely(ACX_DEBUG && (index % adev->txdesc_size))) {
199 printk("bad txdesc ptr %p\n", txdesc);
200 return NULL;
202 index /= adev->txdesc_size;
203 if (unlikely(ACX_DEBUG && (index >= TX_CNT))) {
204 printk("bad txdesc ptr %p\n", txdesc);
205 return NULL;
207 return &adev->txhostdesc_start[index * 2];
214 /***********************************************************************
215 ** EEPROM and PHY read/write helpers
217 /***********************************************************************
218 ** acxpci_read_eeprom_byte
220 ** Function called to read an octet in the EEPROM.
222 ** This function is used by acxpci_e_probe to check if the
223 ** connected card is a legal one or not.
225 ** Arguments:
226 ** adev ptr to acx_device structure
227 ** addr address to read in the EEPROM
228 ** charbuf ptr to a char. This is where the read octet
229 ** will be stored
232 int acxpci_read_eeprom_byte(acx_device_t * adev, u32 addr, u8 * charbuf)
234 int result;
235 int count;
237 FN_ENTER;
239 write_reg32(adev, IO_ACX_EEPROM_CFG, 0);
240 write_reg32(adev, IO_ACX_EEPROM_ADDR, addr);
241 write_flush(adev);
242 write_reg32(adev, IO_ACX_EEPROM_CTL, 2);
244 count = 0xffff;
245 while (read_reg16(adev, IO_ACX_EEPROM_CTL)) {
246 /* scheduling away instead of CPU burning loop
247 * doesn't seem to work here at all:
248 * awful delay, sometimes also failure.
249 * Doesn't matter anyway (only small delay). */
250 if (unlikely(!--count)) {
251 printk("%s: timeout waiting for EEPROM read\n",
252 wiphy_name(adev->ieee->wiphy));
253 result = NOT_OK;
254 goto fail;
256 cpu_relax();
259 *charbuf = read_reg8(adev, IO_ACX_EEPROM_DATA);
260 log(L_DEBUG, "EEPROM at 0x%04X = 0x%02X\n", addr, *charbuf);
261 result = OK;
263 fail:
264 FN_EXIT1(result);
265 return result;
269 /***********************************************************************
270 ** We don't lock hw accesses here since we never r/w eeprom in IRQ
271 ** Note: this function sleeps only because of GFP_KERNEL alloc
273 #ifdef UNUSED
275 acxpci_s_write_eeprom(acx_device_t * adev, u32 addr, u32 len,
276 const u8 * charbuf)
278 u8 *data_verify = NULL;
279 unsigned long flags;
280 int count, i;
281 int result = NOT_OK;
282 u16 gpio_orig;
284 printk("acx: WARNING! I would write to EEPROM now. "
285 "Since I really DON'T want to unless you know "
286 "what you're doing (THIS CODE WILL PROBABLY "
287 "NOT WORK YET!), I will abort that now. And "
288 "definitely make sure to make a "
289 "/proc/driver/acx_wlan0_eeprom backup copy first!!! "
290 "(the EEPROM content includes the PCI config header!! "
291 "If you kill important stuff, then you WILL "
292 "get in trouble and people DID get in trouble already)\n");
293 return OK;
295 FN_ENTER;
297 data_verify = kmalloc(len, GFP_KERNEL);
298 if (!data_verify) {
299 goto end;
302 /* first we need to enable the OE (EEPROM Output Enable) GPIO line
303 * to be able to write to the EEPROM.
304 * NOTE: an EEPROM writing success has been reported,
305 * but you probably have to modify GPIO_OUT, too,
306 * and you probably need to activate a different GPIO
307 * line instead! */
308 gpio_orig = read_reg16(adev, IO_ACX_GPIO_OE);
309 write_reg16(adev, IO_ACX_GPIO_OE, gpio_orig & ~1);
310 write_flush(adev);
312 /* ok, now start writing the data out */
313 for (i = 0; i < len; i++) {
314 write_reg32(adev, IO_ACX_EEPROM_CFG, 0);
315 write_reg32(adev, IO_ACX_EEPROM_ADDR, addr + i);
316 write_reg32(adev, IO_ACX_EEPROM_DATA, *(charbuf + i));
317 write_flush(adev);
318 write_reg32(adev, IO_ACX_EEPROM_CTL, 1);
320 count = 0xffff;
321 while (read_reg16(adev, IO_ACX_EEPROM_CTL)) {
322 if (unlikely(!--count)) {
323 printk("WARNING, DANGER!!! "
324 "Timeout waiting for EEPROM write\n");
325 goto end;
327 cpu_relax();
331 /* disable EEPROM writing */
332 write_reg16(adev, IO_ACX_GPIO_OE, gpio_orig);
333 write_flush(adev);
335 /* now start a verification run */
336 for (i = 0; i < len; i++) {
337 write_reg32(adev, IO_ACX_EEPROM_CFG, 0);
338 write_reg32(adev, IO_ACX_EEPROM_ADDR, addr + i);
339 write_flush(adev);
340 write_reg32(adev, IO_ACX_EEPROM_CTL, 2);
342 count = 0xffff;
343 while (read_reg16(adev, IO_ACX_EEPROM_CTL)) {
344 if (unlikely(!--count)) {
345 printk("timeout waiting for EEPROM read\n");
346 goto end;
348 cpu_relax();
351 data_verify[i] = read_reg16(adev, IO_ACX_EEPROM_DATA);
354 if (0 == memcmp(charbuf, data_verify, len))
355 result = OK; /* read data matches, success */
357 end:
358 kfree(data_verify);
359 FN_EXIT1(result);
360 return result;
362 #endif /* UNUSED */
365 /***********************************************************************
366 ** acxpci_s_read_phy_reg
368 ** Messing with rx/tx disabling and enabling here
369 ** (write_reg32(adev, IO_ACX_ENABLE, 0b000000xx)) kills traffic
371 int acxpci_s_read_phy_reg(acx_device_t * adev, u32 reg, u8 * charbuf)
373 int result = NOT_OK;
374 int count;
376 FN_ENTER;
378 write_reg32(adev, IO_ACX_PHY_ADDR, reg);
379 write_flush(adev);
380 write_reg32(adev, IO_ACX_PHY_CTL, 2);
382 count = 0xffff;
383 while (read_reg32(adev, IO_ACX_PHY_CTL)) {
384 /* scheduling away instead of CPU burning loop
385 * doesn't seem to work here at all:
386 * awful delay, sometimes also failure.
387 * Doesn't matter anyway (only small delay). */
388 if (unlikely(!--count)) {
389 printk("%s: timeout waiting for phy read\n",
390 wiphy_name(adev->ieee->wiphy));
391 *charbuf = 0;
392 goto fail;
394 cpu_relax();
397 log(L_DEBUG, "count was %u\n", count);
398 *charbuf = read_reg8(adev, IO_ACX_PHY_DATA);
400 log(L_DEBUG, "radio PHY at 0x%04X = 0x%02X\n", *charbuf, reg);
401 result = OK;
402 goto fail; /* silence compiler warning */
403 fail:
404 FN_EXIT1(result);
405 return result;
409 /***********************************************************************
411 int acxpci_s_write_phy_reg(acx_device_t * adev, u32 reg, u8 value)
413 FN_ENTER;
415 /* mprusko said that 32bit accesses result in distorted sensitivity
416 * on his card. Unconfirmed, looks like it's not true (most likely since we
417 * now properly flush writes). */
418 write_reg32(adev, IO_ACX_PHY_DATA, value);
419 write_reg32(adev, IO_ACX_PHY_ADDR, reg);
420 write_flush(adev);
421 write_reg32(adev, IO_ACX_PHY_CTL, 1);
422 write_flush(adev);
423 log(L_DEBUG, "radio PHY write 0x%02X at 0x%04X\n", value, reg);
425 FN_EXIT0;
426 return OK;
430 #define NO_AUTO_INCREMENT 1
432 /***********************************************************************
433 ** acxpci_s_write_fw
435 ** Write the firmware image into the card.
437 ** Arguments:
438 ** adev wlan device structure
439 ** fw_image firmware image.
441 ** Returns:
442 ** 1 firmware image corrupted
443 ** 0 success
445 ** Standard csum implementation + write to IO
447 static int
448 acxpci_s_write_fw(acx_device_t * adev, const firmware_image_t *fw_image,
449 u32 offset)
451 int len, size;
452 u32 sum, v32;
453 /* we skip the first four bytes which contain the control sum */
455 const u8 *p = (u8 *) fw_image + 4;
457 FN_ENTER;
459 /* start the image checksum by adding the image size value */
460 sum = p[0] + p[1] + p[2] + p[3];
461 p += 4;
463 write_reg32(adev, IO_ACX_SLV_END_CTL, 0);
465 #if NO_AUTO_INCREMENT
466 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 0); /* use basic mode */
467 #else
468 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 1); /* use autoincrement mode */
469 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset); /* configure start address */
470 write_flush(adev);
471 #endif
473 len = 0;
474 size = le32_to_cpu(fw_image->size) & (~3);
476 while (likely(len < size)) {
477 v32 = be32_to_cpu(*(u32 *) p);
478 sum += p[0] + p[1] + p[2] + p[3];
479 p += 4;
480 len += 4;
482 #if NO_AUTO_INCREMENT
483 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset + len - 4);
484 write_flush(adev);
485 #endif
486 write_reg32(adev, IO_ACX_SLV_MEM_DATA, v32);
489 log(L_DEBUG, "firmware written, size:%d sum1:%x sum2:%x\n",
490 size, sum, le32_to_cpu(fw_image->chksum));
492 /* compare our checksum with the stored image checksum */
493 FN_EXIT1(sum != le32_to_cpu(fw_image->chksum));
494 return (sum != le32_to_cpu(fw_image->chksum));
498 /***********************************************************************
499 ** acxpci_s_validate_fw
501 ** Compare the firmware image given with
502 ** the firmware image written into the card.
504 ** Arguments:
505 ** adev wlan device structure
506 ** fw_image firmware image.
508 ** Returns:
509 ** NOT_OK firmware image corrupted or not correctly written
510 ** OK success
512 ** Origin: Standard csum + Read IO
514 static int
515 acxpci_s_validate_fw(acx_device_t * adev, const firmware_image_t *fw_image,
516 u32 offset)
518 u32 sum, v32, w32;
519 int len, size;
520 int result = OK;
521 /* we skip the first four bytes which contain the control sum */
522 const u8 *p = (u8 *) fw_image + 4;
524 FN_ENTER;
526 /* start the image checksum by adding the image size value */
527 sum = p[0] + p[1] + p[2] + p[3];
528 p += 4;
530 write_reg32(adev, IO_ACX_SLV_END_CTL, 0);
532 #if NO_AUTO_INCREMENT
533 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 0); /* use basic mode */
534 #else
535 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 1); /* use autoincrement mode */
536 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset); /* configure start address */
537 #endif
539 len = 0;
540 size = le32_to_cpu(fw_image->size) & (~3);
542 while (likely(len < size)) {
543 v32 = be32_to_cpu(*(u32 *) p);
544 p += 4;
545 len += 4;
547 #if NO_AUTO_INCREMENT
548 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset + len - 4);
549 #endif
550 w32 = read_reg32(adev, IO_ACX_SLV_MEM_DATA);
552 if (unlikely(w32 != v32)) {
553 printk("acx: FATAL: firmware upload: "
554 "data parts at offset %d don't match (0x%08X vs. 0x%08X)! "
555 "I/O timing issues or defective memory, with DWL-xx0+? "
556 "ACX_IO_WIDTH=16 may help. Please report\n",
557 len, v32, w32);
558 result = NOT_OK;
559 break;
562 sum +=
563 (u8) w32 + (u8) (w32 >> 8) + (u8) (w32 >> 16) +
564 (u8) (w32 >> 24);
567 /* sum control verification */
568 if (result != NOT_OK) {
569 if (sum != le32_to_cpu(fw_image->chksum)) {
570 printk("acx: FATAL: firmware upload: "
571 "checksums don't match!\n");
572 result = NOT_OK;
576 FN_EXIT1(result);
577 return result;
581 /***********************************************************************
582 ** acxpci_s_upload_fw
584 ** Called from acx_reset_dev
586 ** Origin: Derived from FW dissection
588 static int acxpci_s_upload_fw(acx_device_t * adev)
590 firmware_image_t *fw_image = NULL;
591 int res = NOT_OK;
592 int try;
593 u32 file_size;
594 char filename[sizeof("tiacx1NNcNN")];
596 FN_ENTER;
598 /* print exact chipset and radio ID to make sure people
599 * really get a clue on which files exactly they need to provide.
600 * Firmware loading is a frequent end-user PITA with these chipsets.
602 printk( "acx: need firmware for acx1%02d chipset with radio ID %02X\n"
603 "Please provide via firmware hotplug:\n"
604 "either combined firmware (single file named 'tiacx1%02dc%02X')\n"
605 "or two files (base firmware file 'tiacx1%02d' "
606 "+ radio fw 'tiacx1%02dr%02X')\n",
607 IS_ACX111(adev)*11, adev->radio_type,
608 IS_ACX111(adev)*11, adev->radio_type,
609 IS_ACX111(adev)*11,
610 IS_ACX111(adev)*11, adev->radio_type
613 /* print exact chipset and radio ID to make sure people really get a clue on which files exactly they are supposed to provide,
614 * since firmware loading is the biggest enduser PITA with these chipsets.
615 * Not printing radio ID in 0xHEX in order to not confuse them into wrong file naming */
616 printk( "acx: need to load firmware for acx1%02d chipset with radio ID %02x, please provide via firmware hotplug:\n"
617 "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",
618 IS_ACX111(adev)*11, adev->radio_type);
620 /* Try combined, then main image */
621 adev->need_radio_fw = 0;
622 snprintf(filename, sizeof(filename), "tiacx1%02dc%02X",
623 IS_ACX111(adev) * 11, adev->radio_type);
625 fw_image = acx_s_read_fw(adev->bus_dev, filename, &file_size);
626 if (!fw_image) {
627 adev->need_radio_fw = 1;
628 filename[sizeof("tiacx1NN") - 1] = '\0';
629 fw_image =
630 acx_s_read_fw(adev->bus_dev, filename, &file_size);
631 if (!fw_image) {
632 FN_EXIT1(NOT_OK);
633 return NOT_OK;
637 for (try = 1; try <= 5; try++) {
638 res = acxpci_s_write_fw(adev, fw_image, 0);
639 log(L_DEBUG | L_INIT, "acx_write_fw (main/combined): %d\n", res);
640 if (OK == res) {
641 res = acxpci_s_validate_fw(adev, fw_image, 0);
642 log(L_DEBUG | L_INIT, "acx_validate_fw "
643 "(main/combined): %d\n", res);
646 if (OK == res) {
647 SET_BIT(adev->dev_state_mask, ACX_STATE_FW_LOADED);
648 break;
650 printk("acx: firmware upload attempt #%d FAILED, "
651 "retrying...\n", try);
652 acx_s_mwait(1000); /* better wait for a while... */
655 vfree(fw_image);
657 FN_EXIT1(res);
658 return res;
662 /***********************************************************************
663 ** acxpci_s_upload_radio
665 ** Uploads the appropriate radio module firmware into the card.
667 ** Origin: Standard Read/Write to IO
669 int acxpci_s_upload_radio(acx_device_t * adev)
671 acx_ie_memmap_t mm;
672 firmware_image_t *radio_image;
673 acx_cmd_radioinit_t radioinit;
674 int res = NOT_OK;
675 int try;
676 u32 offset;
677 u32 size;
678 char filename[sizeof("tiacx1NNrNN")];
680 if (!adev->need_radio_fw)
681 return OK;
683 FN_ENTER;
685 acx_s_interrogate(adev, &mm, ACX1xx_IE_MEMORY_MAP);
686 offset = le32_to_cpu(mm.CodeEnd);
688 snprintf(filename, sizeof(filename), "tiacx1%02dr%02X",
689 IS_ACX111(adev) * 11, adev->radio_type);
690 radio_image = acx_s_read_fw(adev->bus_dev, filename, &size);
691 if (!radio_image) {
692 printk("acx: can't load radio module '%s'\n", filename);
693 goto fail;
696 acx_s_issue_cmd(adev, ACX1xx_CMD_SLEEP, NULL, 0);
698 for (try = 1; try <= 5; try++) {
699 res = acxpci_s_write_fw(adev, radio_image, offset);
700 log(L_DEBUG | L_INIT, "acx_write_fw (radio): %d\n", res);
701 if (OK == res) {
702 res = acxpci_s_validate_fw(adev, radio_image, offset);
703 log(L_DEBUG | L_INIT, "acx_validate_fw (radio): %d\n",
704 res);
707 if (OK == res)
708 break;
709 printk("acx: radio firmware upload attempt #%d FAILED, "
710 "retrying...\n", try);
711 acx_s_mwait(1000); /* better wait for a while... */
714 acx_s_issue_cmd(adev, ACX1xx_CMD_WAKE, NULL, 0);
715 radioinit.offset = cpu_to_le32(offset);
716 /* no endian conversion needed, remains in card CPU area: */
717 radioinit.len = radio_image->size;
719 vfree(radio_image);
721 if (OK != res)
722 goto fail;
724 /* will take a moment so let's have a big timeout */
725 acx_s_issue_cmd_timeo(adev, ACX1xx_CMD_RADIOINIT,
726 &radioinit, sizeof(radioinit),
727 CMD_TIMEOUT_MS(1000));
729 res = acx_s_interrogate(adev, &mm, ACX1xx_IE_MEMORY_MAP);
730 fail:
731 FN_EXIT1(res);
732 return res;
736 /***********************************************************************
737 ** acxpci_l_reset_mac
739 ** MAC will be reset
740 ** Call context: reset_dev
742 ** Origin: Standard Read/Write to IO
744 static void acxpci_l_reset_mac(acx_device_t * adev)
746 u16 temp;
748 FN_ENTER;
750 /* halt eCPU */
751 temp = read_reg16(adev, IO_ACX_ECPU_CTRL) | 0x1;
752 write_reg16(adev, IO_ACX_ECPU_CTRL, temp);
754 /* now do soft reset of eCPU, set bit */
755 temp = read_reg16(adev, IO_ACX_SOFT_RESET) | 0x1;
756 log(L_DEBUG, "enable soft reset\n");
757 write_reg16(adev, IO_ACX_SOFT_RESET, temp);
758 write_flush(adev);
760 /* now clear bit again: deassert eCPU reset */
761 log(L_DEBUG, "disable soft reset and go to init mode");
762 write_reg16(adev, IO_ACX_SOFT_RESET, temp & ~0x1);
764 /* now start a burst read from initial EEPROM */
765 temp = read_reg16(adev, IO_ACX_EE_START) | 0x1;
766 write_reg16(adev, IO_ACX_EE_START, temp);
767 write_flush(adev);
769 FN_EXIT0;
773 /***********************************************************************
774 ** acxpci_s_verify_init
776 static int acxpci_s_verify_init(acx_device_t * adev)
778 int result = NOT_OK;
779 unsigned long timeout;
781 FN_ENTER;
783 timeout = jiffies + 2 * HZ;
784 for (;;) {
785 u16 irqstat = read_reg16(adev, IO_ACX_IRQ_STATUS_NON_DES);
786 if (irqstat & HOST_INT_FCS_THRESHOLD) {
787 result = OK;
788 write_reg16(adev, IO_ACX_IRQ_ACK,
789 HOST_INT_FCS_THRESHOLD);
790 break;
792 if (time_after(jiffies, timeout))
793 break;
794 /* Init may take up to ~0.5 sec total */
795 acx_s_mwait(50);
798 FN_EXIT1(result);
799 return result;
803 /***********************************************************************
804 ** A few low-level helpers
806 ** Note: these functions are not protected by lock
807 ** and thus are never allowed to be called from IRQ.
808 ** Also they must not race with fw upload which uses same hw regs
811 /***********************************************************************
812 ** acxpci_write_cmd_type_status
814 ** Origin: Common linux implementation
817 static inline void
818 acxpci_write_cmd_type_status(acx_device_t * adev, u16 type, u16 status)
820 FN_ENTER;
821 acx_writel(type | (status << 16), adev->cmd_area);
822 write_flush(adev);
823 FN_EXIT0;
827 /***********************************************************************
828 ** acxpci_read_cmd_type_status
830 ** Origin: Common linux implementation
832 static u32 acxpci_read_cmd_type_status(acx_device_t * adev)
834 u32 cmd_type, cmd_status;
836 FN_ENTER;
838 cmd_type = acx_readl(adev->cmd_area);
839 cmd_status = (cmd_type >> 16);
840 cmd_type = (u16) cmd_type;
842 log(L_CTL, "cmd_type:%04X cmd_status:%04X [%s]\n",
843 cmd_type, cmd_status, acx_cmd_status_str(cmd_status));
845 FN_EXIT1(cmd_status);
846 return cmd_status;
850 /***********************************************************************
851 ** acxpci_s_reset_dev
853 ** Arguments:
854 ** netdevice that contains the adev variable
855 ** Returns:
856 ** NOT_OK on fail
857 ** OK on success
858 ** Side effects:
859 ** device is hard reset
860 ** Call context:
861 ** acxpci_e_probe
862 ** Comment:
863 ** This resets the device using low level hardware calls
864 ** as well as uploads and verifies the firmware to the card
867 static inline void init_mboxes(acx_device_t * adev)
869 u32 cmd_offs, info_offs;
871 FN_ENTER;
873 cmd_offs = read_reg32(adev, IO_ACX_CMD_MAILBOX_OFFS);
874 info_offs = read_reg32(adev, IO_ACX_INFO_MAILBOX_OFFS);
875 adev->cmd_area = (u8 *) adev->iobase2 + cmd_offs;
876 adev->info_area = (u8 *) adev->iobase2 + info_offs;
877 log(L_DEBUG, "iobase2=%p\n"
878 "cmd_mbox_offset=%X cmd_area=%p\n"
879 "info_mbox_offset=%X info_area=%p\n",
880 adev->iobase2,
881 cmd_offs, adev->cmd_area, info_offs, adev->info_area);
882 FN_EXIT0;
886 static inline void read_eeprom_area(acx_device_t * adev)
888 #if ACX_DEBUG > 1
889 int offs;
890 u8 tmp;
892 FN_ENTER;
894 for (offs = 0x8c; offs < 0xb9; offs++)
895 acxpci_read_eeprom_byte(adev, offs, &tmp);
897 FN_EXIT0;
898 #endif
902 int acxpci_s_reset_dev(acx_device_t * adev)
904 const char *msg = "";
905 unsigned long flags;
906 int result = NOT_OK;
907 u16 hardware_info;
908 u16 ecpu_ctrl;
909 int count;
911 FN_ENTER;
913 /* reset the device to make sure the eCPU is stopped
914 * to upload the firmware correctly */
916 acx_lock(adev, flags);
918 #ifdef CONFIG_PCI
919 acxpci_l_reset_mac(adev);
920 #endif
922 ecpu_ctrl = read_reg16(adev, IO_ACX_ECPU_CTRL) & 1;
923 if (!ecpu_ctrl) {
924 msg = "eCPU is already running. ";
925 goto end_unlock;
927 #if 0
928 if (read_reg16(adev, IO_ACX_SOR_CFG) & 2) {
929 /* eCPU most likely means "embedded CPU" */
930 msg = "eCPU did not start after boot from flash. ";
931 goto end_unlock;
934 /* check sense on reset flags */
935 if (read_reg16(adev, IO_ACX_SOR_CFG) & 0x10) {
936 printk("%s: eCPU did not start after boot (SOR), "
937 "is this fatal?\n", wiphy_name(adev->ieee->wiphy));
939 #endif
940 /* scan, if any, is stopped now, setting corresponding IRQ bit */
941 SET_BIT(adev->irq_status, HOST_INT_SCAN_COMPLETE);
943 acx_unlock(adev, flags);
945 /* need to know radio type before fw load */
946 /* Need to wait for arrival of this information in a loop,
947 * most probably since eCPU runs some init code from EEPROM
948 * (started burst read in reset_mac()) which also
949 * sets the radio type ID */
951 count = 0xffff;
952 do {
953 hardware_info = read_reg16(adev, IO_ACX_EEPROM_INFORMATION);
954 if (!--count) {
955 msg = "eCPU didn't indicate radio type";
956 goto end_fail;
958 cpu_relax();
959 } while (!(hardware_info & 0xff00)); /* radio type still zero? */
961 /* printk("DEBUG: count %d\n", count); */
962 adev->form_factor = hardware_info & 0xff;
963 adev->radio_type = hardware_info >> 8;
965 /* load the firmware */
966 if (OK != acxpci_s_upload_fw(adev))
967 goto end_fail;
969 /* acx_s_mwait(10); this one really shouldn't be required */
971 /* now start eCPU by clearing bit */
972 write_reg16(adev, IO_ACX_ECPU_CTRL, ecpu_ctrl & ~0x1);
973 log(L_DEBUG, "booted eCPU up and waiting for completion...\n");
975 /* wait for eCPU bootup */
976 if (OK != acxpci_s_verify_init(adev)) {
977 msg = "timeout waiting for eCPU. ";
978 goto end_fail;
980 log(L_DEBUG, "eCPU has woken up, card is ready to be configured\n");
982 init_mboxes(adev);
983 acxpci_write_cmd_type_status(adev, 0, 0);
985 /* test that EEPROM is readable */
986 read_eeprom_area(adev);
988 result = OK;
989 goto end;
991 /* Finish error message. Indicate which function failed */
992 end_unlock:
993 acx_unlock(adev, flags);
994 end_fail:
995 printk("acx: %sreset_dev() FAILED\n", msg);
996 end:
997 FN_EXIT1(result);
998 return result;
1002 /***********************************************************************
1003 ** acxpci_s_issue_cmd_timeo
1005 ** Sends command to fw, extract result
1007 ** NB: we do _not_ take lock inside, so be sure to not touch anything
1008 ** which may interfere with IRQ handler operation
1010 ** TODO: busy wait is a bit silly, so:
1011 ** 1) stop doing many iters - go to sleep after first
1012 ** 2) go to waitqueue based approach: wait, not poll!
1014 #undef FUNC
1015 #define FUNC "issue_cmd"
1017 #if !ACX_DEBUG
1019 acxpci_s_issue_cmd_timeo(acx_device_t * adev,
1020 unsigned int cmd,
1021 void *buffer, unsigned buflen, unsigned cmd_timeout)
1023 #else
1025 acxpci_s_issue_cmd_timeo_debug(acx_device_t * adev,
1026 unsigned cmd,
1027 void *buffer,
1028 unsigned buflen,
1029 unsigned cmd_timeout, const char *cmdstr)
1031 unsigned long start = jiffies;
1032 #endif
1033 const char *devname;
1034 unsigned counter;
1035 u16 irqtype;
1036 u16 cmd_status;
1037 unsigned long timeout;
1039 FN_ENTER;
1041 devname = wiphy_name(adev->ieee->wiphy);
1042 if (!devname || !devname[0] || devname[4] == '%')
1043 devname = "acx";
1045 log(L_CTL, FUNC "(cmd:%s,buflen:%u,timeout:%ums,type:0x%04X)\n",
1046 cmdstr, buflen, cmd_timeout,
1047 buffer ? le16_to_cpu(((acx_ie_generic_t *) buffer)->type) : -1);
1049 if (!(adev->dev_state_mask & ACX_STATE_FW_LOADED)) {
1050 printk("%s: " FUNC "(): firmware is not loaded yet, "
1051 "cannot execute commands!\n", devname);
1052 goto bad;
1055 if ((acx_debug & L_DEBUG) && (cmd != ACX1xx_CMD_INTERROGATE)) {
1056 printk("input buffer (len=%u):\n", buflen);
1057 acx_dump_bytes(buffer, buflen);
1060 /* wait for firmware to become idle for our command submission */
1061 timeout = HZ / 5;
1062 counter = (timeout * 1000 / HZ) - 1; /* in ms */
1063 timeout += jiffies;
1064 do {
1065 cmd_status = acxpci_read_cmd_type_status(adev);
1066 /* Test for IDLE state */
1067 if (!cmd_status)
1068 break;
1069 if (counter % 8 == 0) {
1070 if (time_after(jiffies, timeout)) {
1071 counter = 0;
1072 break;
1074 /* we waited 8 iterations, no luck. Sleep 8 ms */
1075 acx_s_mwait(8);
1077 } while (likely(--counter));
1079 if (!counter) {
1080 /* the card doesn't get idle, we're in trouble */
1081 printk("%s: " FUNC "(): cmd_status is not IDLE: 0x%04X!=0\n",
1082 devname, cmd_status);
1083 goto bad;
1084 } else if (counter < 190) { /* if waited >10ms... */
1085 log(L_CTL | L_DEBUG, FUNC "(): waited for IDLE %dms. "
1086 "Please report\n", 199 - counter);
1089 /* now write the parameters of the command if needed */
1090 if (buffer && buflen) {
1091 /* if it's an INTERROGATE command, just pass the length
1092 * of parameters to read, as data */
1093 #if CMD_DISCOVERY
1094 if (cmd == ACX1xx_CMD_INTERROGATE)
1095 memset_io(adev->cmd_area + 4, 0xAA, buflen);
1096 #endif
1097 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1098 memcpy_toio(adev->cmd_area + 4, buffer,
1099 (cmd == ACX1xx_CMD_INTERROGATE) ? 4 : buflen);
1101 /* now write the actual command type */
1102 acxpci_write_cmd_type_status(adev, cmd, 0);
1103 /* execute command */
1104 write_reg16(adev, IO_ACX_INT_TRIG, INT_TRIG_CMD);
1105 write_flush(adev);
1107 /* wait for firmware to process command */
1109 /* Ensure nonzero and not too large timeout.
1110 ** Also converts e.g. 100->99, 200->199
1111 ** which is nice but not essential */
1112 cmd_timeout = (cmd_timeout - 1) | 1;
1113 if (unlikely(cmd_timeout > 1199))
1114 cmd_timeout = 1199;
1115 /* clear CMD_COMPLETE bit. can be set only by IRQ handler: */
1116 CLEAR_BIT(adev->irq_status, HOST_INT_CMD_COMPLETE);
1117 /* we schedule away sometimes (timeout can be large) */
1118 counter = cmd_timeout;
1119 timeout = jiffies + HZ;
1120 do {
1121 if (!adev->irqs_active) { /* IRQ disabled: poll */
1122 irqtype = read_reg16(adev, IO_ACX_IRQ_STATUS_NON_DES);
1123 if (irqtype & HOST_INT_CMD_COMPLETE) {
1124 write_reg16(adev, IO_ACX_IRQ_ACK,
1125 HOST_INT_CMD_COMPLETE);
1126 break;
1128 } else { /* Wait when IRQ will set the bit */
1129 irqtype = adev->irq_status;
1130 if (irqtype & HOST_INT_CMD_COMPLETE)
1131 break;
1134 if (counter % 8 == 0) {
1135 if (time_after(jiffies, timeout)) {
1136 counter = 0;
1137 break;
1139 /* we waited 8 iterations, no luck. Sleep 8 ms */
1140 acx_s_mwait(8);
1142 } while (likely(--counter));
1144 /* save state for debugging */
1145 cmd_status = acxpci_read_cmd_type_status(adev);
1147 /* put the card in IDLE state */
1148 acxpci_write_cmd_type_status(adev, 0, 0);
1150 if ((cmd_timeout - counter) == 0) { /* timed out! */
1151 printk("%s: " FUNC "(): timed out %s for CMD_COMPLETE. "
1152 "irq bits:0x%04X irq_status:0x%04X timeout:%dms "
1153 "cmd_status:%d (%s)\n",
1154 devname, (adev->irqs_active) ? "waiting" : "polling",
1155 irqtype, adev->irq_status, cmd_timeout,
1156 cmd_status, acx_cmd_status_str(cmd_status));
1157 printk("hack: don't do: 'goto bad;'\ncounter: %d cmd_timeout: %d cmd_timeout-counter: %d\n",counter, cmd_timeout, cmd_timeout - counter);
1158 } else if (counter == 0) { /* maybe timed out! */
1159 log(L_CTL | L_DEBUG, FUNC "(): %s for CMD_COMPLETE %dms. "
1160 "count:%d. Please report\n",
1161 (adev->irqs_active) ? "waited" : "polled",
1162 cmd_timeout - counter, counter);
1163 } else if ((cmd_timeout - counter) > 30) { /* if waited >30ms... */
1164 log(L_CTL | L_DEBUG, FUNC "(): %s for CMD_COMPLETE %dms. "
1165 "count:%d. Please report\n",
1166 (adev->irqs_active) ? "waited" : "polled",
1167 cmd_timeout - counter, counter);
1170 if (1 != cmd_status) { /* it is not a 'Success' */
1171 printk("%s: " FUNC "(): cmd_status is not SUCCESS: %d (%s). "
1172 "Took %dms of %d\n",
1173 devname, cmd_status, acx_cmd_status_str(cmd_status),
1174 cmd_timeout - counter, cmd_timeout);
1175 /* zero out result buffer
1176 * WARNING: this will trash stack in case of illegally large input
1177 * length! */
1178 if (buffer && buflen)
1179 memset(buffer, 0, buflen);
1180 goto bad;
1183 /* read in result parameters if needed */
1184 if (buffer && buflen && (cmd == ACX1xx_CMD_INTERROGATE)) {
1185 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1186 memcpy_fromio(buffer, adev->cmd_area + 4, buflen);
1187 if (acx_debug & L_DEBUG) {
1188 printk("output buffer (len=%u): ", buflen);
1189 acx_dump_bytes(buffer, buflen);
1192 /* ok: */
1193 log(L_CTL, FUNC "(%s): took %ld jiffies to complete\n",
1194 cmdstr, jiffies - start);
1195 FN_EXIT1(OK);
1196 return OK;
1198 bad:
1199 /* Give enough info so that callers can avoid
1200 ** printing their own diagnostic messages */
1201 #if ACX_DEBUG
1202 printk("%s: " FUNC "(cmd:%s) FAILED\n", devname, cmdstr);
1203 #else
1204 printk("%s: " FUNC "(cmd:0x%04X) FAILED\n", devname, cmd);
1205 #endif
1206 dump_stack();
1207 FN_EXIT1(NOT_OK);
1208 return NOT_OK;
1212 /***********************************************************************
1214 #ifdef NONESSENTIAL_FEATURES
1215 typedef struct device_id {
1216 unsigned char id[6];
1217 char *descr;
1218 char *type;
1219 } device_id_t;
1221 static const device_id_t device_ids[] = {
1223 {'G', 'l', 'o', 'b', 'a', 'l'},
1224 NULL,
1225 NULL,
1228 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
1229 "uninitialized",
1230 "SpeedStream SS1021 or Gigafast WF721-AEX"},
1232 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85},
1233 "non-standard",
1234 "DrayTek Vigor 520"},
1236 {'?', '?', '?', '?', '?', '?'},
1237 "non-standard",
1238 "Level One WPC-0200"},
1240 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1241 "empty",
1242 "DWL-650+ variant"}
1245 static void acx_show_card_eeprom_id(acx_device_t * adev)
1247 unsigned char buffer[CARD_EEPROM_ID_SIZE];
1248 int i;
1250 FN_ENTER;
1252 memset(&buffer, 0, CARD_EEPROM_ID_SIZE);
1253 /* use direct EEPROM access */
1254 for (i = 0; i < CARD_EEPROM_ID_SIZE; i++) {
1255 if (OK != acxpci_read_eeprom_byte(adev,
1256 ACX100_EEPROM_ID_OFFSET + i,
1257 &buffer[i])) {
1258 printk("acx: reading EEPROM FAILED\n");
1259 break;
1263 for (i = 0; i < ARRAY_SIZE(device_ids); i++) {
1264 if (!memcmp(&buffer, device_ids[i].id, CARD_EEPROM_ID_SIZE)) {
1265 if (device_ids[i].descr) {
1266 printk("acx: EEPROM card ID string check "
1267 "found %s card ID: is this %s?\n",
1268 device_ids[i].descr, device_ids[i].type);
1270 break;
1273 if (i == ARRAY_SIZE(device_ids)) {
1274 printk("acx: EEPROM card ID string check found "
1275 "unknown card: expected 'Global', got '%.*s\'. "
1276 "Please report\n", CARD_EEPROM_ID_SIZE, buffer);
1278 FN_EXIT0;
1280 #endif /* NONESSENTIAL_FEATURES */
1283 /***********************************************************************
1284 ** acxpci_free_desc_queues
1286 ** Releases the queues that have been allocated, the
1287 ** others have been initialised to NULL so this
1288 ** function can be used if only part of the queues were allocated.
1291 static inline void
1292 free_coherent(struct pci_dev *hwdev, size_t size,
1293 void *vaddr, dma_addr_t dma_handle)
1295 dma_free_coherent(hwdev == NULL ? NULL : &hwdev->dev,
1296 size, vaddr, dma_handle);
1300 void acxpci_free_desc_queues(acx_device_t * adev)
1302 unsigned long flags;
1304 #define ACX_FREE_QUEUE(size, ptr, phyaddr) \
1305 if (ptr) { \
1306 free_coherent(NULL, size, ptr, phyaddr); \
1307 ptr = NULL; \
1308 size = 0; \
1311 FN_ENTER;
1313 ACX_FREE_QUEUE(adev->txhostdesc_area_size, adev->txhostdesc_start,
1314 adev->txhostdesc_startphy);
1315 ACX_FREE_QUEUE(adev->txbuf_area_size, adev->txbuf_start,
1316 adev->txbuf_startphy);
1318 acx_lock(adev, flags);
1319 adev->txdesc_start = NULL;
1320 acx_unlock(adev, flags);
1322 ACX_FREE_QUEUE(adev->rxhostdesc_area_size, adev->rxhostdesc_start,
1323 adev->rxhostdesc_startphy);
1324 ACX_FREE_QUEUE(adev->rxbuf_area_size, adev->rxbuf_start,
1325 adev->rxbuf_startphy);
1327 acx_lock(adev, flags);
1328 adev->rxdesc_start = NULL;
1329 acx_unlock(adev, flags);
1331 FN_EXIT0;
1335 /***********************************************************************
1336 ** acxpci_s_delete_dma_regions
1338 static void acxpci_s_delete_dma_regions(acx_device_t * adev)
1340 FN_ENTER;
1341 /* disable radio Tx/Rx. Shouldn't we use the firmware commands
1342 * here instead? Or are we that much down the road that it's no
1343 * longer possible here? */
1344 write_reg16(adev, IO_ACX_ENABLE, 0);
1346 acx_s_mwait(100);
1348 /* NO locking for all parts of acxpci_free_desc_queues because:
1349 * while calling dma_free_coherent() interrupts need to be 'free'
1350 * but if you spinlock the whole function (acxpci_free_desc_queues)
1351 * you'll get an error */
1352 acxpci_free_desc_queues(adev);
1354 FN_EXIT0;
1358 /***********************************************************************
1359 ** acxpci_e_probe
1361 ** Probe routine called when a PCI device w/ matching ID is found.
1362 ** Here's the sequence:
1363 ** - Allocate the PCI resources.
1364 ** - Read the PCMCIA attribute memory to make sure we have a WLAN card
1365 ** - Reset the MAC
1366 ** - Initialize the dev and wlan data
1367 ** - Initialize the MAC
1369 ** pdev - ptr to pci device structure containing info about pci configuration
1370 ** id - ptr to the device id entry that matched this device
1372 static const u16 IO_ACX100[] = {
1373 0x0000, /* IO_ACX_SOFT_RESET */
1375 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1376 0x0018, /* IO_ACX_SLV_MEM_DATA */
1377 0x001c, /* IO_ACX_SLV_MEM_CTL */
1378 0x0020, /* IO_ACX_SLV_END_CTL */
1380 0x0034, /* IO_ACX_FEMR */
1382 0x007c, /* IO_ACX_INT_TRIG */
1383 0x0098, /* IO_ACX_IRQ_MASK */
1384 0x00a4, /* IO_ACX_IRQ_STATUS_NON_DES */
1385 0x00a8, /* IO_ACX_IRQ_STATUS_CLEAR */
1386 0x00ac, /* IO_ACX_IRQ_ACK */
1387 0x00b0, /* IO_ACX_HINT_TRIG */
1389 0x0104, /* IO_ACX_ENABLE */
1391 0x0250, /* IO_ACX_EEPROM_CTL */
1392 0x0254, /* IO_ACX_EEPROM_ADDR */
1393 0x0258, /* IO_ACX_EEPROM_DATA */
1394 0x025c, /* IO_ACX_EEPROM_CFG */
1396 0x0268, /* IO_ACX_PHY_ADDR */
1397 0x026c, /* IO_ACX_PHY_DATA */
1398 0x0270, /* IO_ACX_PHY_CTL */
1400 0x0290, /* IO_ACX_GPIO_OE */
1402 0x0298, /* IO_ACX_GPIO_OUT */
1404 0x02a4, /* IO_ACX_CMD_MAILBOX_OFFS */
1405 0x02a8, /* IO_ACX_INFO_MAILBOX_OFFS */
1406 0x02ac, /* IO_ACX_EEPROM_INFORMATION */
1408 0x02d0, /* IO_ACX_EE_START */
1409 0x02d4, /* IO_ACX_SOR_CFG */
1410 0x02d8 /* IO_ACX_ECPU_CTRL */
1413 static const u16 IO_ACX111[] = {
1414 0x0000, /* IO_ACX_SOFT_RESET */
1416 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1417 0x0018, /* IO_ACX_SLV_MEM_DATA */
1418 0x001c, /* IO_ACX_SLV_MEM_CTL */
1419 0x0020, /* IO_ACX_SLV_END_CTL */
1421 0x0034, /* IO_ACX_FEMR */
1423 0x00b4, /* IO_ACX_INT_TRIG */
1424 0x00d4, /* IO_ACX_IRQ_MASK */
1425 /* we do mean NON_DES (0xf0), not NON_DES_MASK which is at 0xe0: */
1426 0x00f0, /* IO_ACX_IRQ_STATUS_NON_DES */
1427 0x00e4, /* IO_ACX_IRQ_STATUS_CLEAR */
1428 0x00e8, /* IO_ACX_IRQ_ACK */
1429 0x00ec, /* IO_ACX_HINT_TRIG */
1431 0x01d0, /* IO_ACX_ENABLE */
1433 0x0338, /* IO_ACX_EEPROM_CTL */
1434 0x033c, /* IO_ACX_EEPROM_ADDR */
1435 0x0340, /* IO_ACX_EEPROM_DATA */
1436 0x0344, /* IO_ACX_EEPROM_CFG */
1438 0x0350, /* IO_ACX_PHY_ADDR */
1439 0x0354, /* IO_ACX_PHY_DATA */
1440 0x0358, /* IO_ACX_PHY_CTL */
1442 0x0374, /* IO_ACX_GPIO_OE */
1444 0x037c, /* IO_ACX_GPIO_OUT */
1446 0x0388, /* IO_ACX_CMD_MAILBOX_OFFS */
1447 0x038c, /* IO_ACX_INFO_MAILBOX_OFFS */
1448 0x0390, /* IO_ACX_EEPROM_INFORMATION */
1450 0x0100, /* IO_ACX_EE_START */
1451 0x0104, /* IO_ACX_SOR_CFG */
1452 0x0108, /* IO_ACX_ECPU_CTRL */
1455 static const struct ieee80211_ops acxpci_hw_ops = {
1456 .tx = acx_i_start_xmit,
1457 .conf_tx = acx_net_conf_tx,
1458 .add_interface = acx_add_interface,
1459 .remove_interface = acx_remove_interface,
1460 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
1461 .open = acxpci_e_open,
1462 .reset = acx_net_reset,
1463 .set_multicast_list = acx_i_set_multicast_list,
1464 #else
1465 .start = acxpci_e_open,
1466 .configure_filter = acx_i_set_multicast_list,
1467 #endif
1468 .stop = acxpci_e_close,
1469 .config = acx_net_config,
1470 .config_interface = acx_config_interface,
1471 .set_key = acx_net_set_key,
1472 .get_stats = acx_e_get_stats,
1473 .get_tx_stats = acx_net_get_tx_stats,
1477 #ifdef CONFIG_PCI
1478 static int __devinit
1479 acxpci_e_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1481 acx111_ie_configoption_t co;
1482 unsigned long mem_region1 = 0;
1483 unsigned long mem_region2 = 0;
1484 unsigned long mem_region1_size;
1485 unsigned long mem_region2_size;
1486 unsigned long phymem1;
1487 unsigned long phymem2;
1488 void *mem1 = NULL;
1489 void *mem2 = NULL;
1490 acx_device_t *adev = NULL;
1491 const char *chip_name;
1492 int result = -EIO;
1493 int err;
1494 u8 chip_type;
1495 struct ieee80211_hw *ieee;
1497 FN_ENTER;
1499 ieee = ieee80211_alloc_hw(sizeof(struct acx_device), &acxpci_hw_ops);
1500 if (!ieee) {
1501 printk("acx: could not allocate ieee80211 structure %s\n",
1502 pci_name(pdev));
1503 goto fail_alloc_netdev;
1505 ieee->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
1506 /* TODO: mainline doesn't support the following flags yet */
1508 ~IEEE80211_HW_MONITOR_DURING_OPER &
1509 ~IEEE80211_HW_WEP_INCLUDE_IV;
1511 ieee->queues = 1;
1513 /* (NB: memsets to 0 entire area) */
1514 if (!ieee) {
1515 printk("acx: could not allocate ieee structure %s\n",
1516 pci_name(pdev));
1517 goto fail_alloc_netdev;
1520 adev = ieee2adev(ieee);
1522 memset(adev, 0, sizeof(*adev));
1523 /** Set up our private interface **/
1524 spin_lock_init(&adev->lock); /* initial state: unlocked */
1525 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
1526 printk("mutex_init(&adev->mutex); // adev = 0x%px\n", adev);
1527 mutex_init(&adev->mutex);
1528 /* since nobody can see new netdev yet, we can as well
1529 ** just _presume_ that we're under sem (instead of actually taking it): */
1530 /* acx_sem_lock(adev); */
1531 adev->ieee = ieee;
1532 adev->pdev = pdev;
1533 adev->bus_dev = &pdev->dev;
1534 adev->dev_type = DEVTYPE_PCI;
1536 /** Finished with private interface **/
1538 /** begin board specific inits **/
1539 pci_set_drvdata(pdev, ieee);
1541 /* Enable the PCI device */
1542 if (pci_enable_device(pdev)) {
1543 printk("acx: pci_enable_device() FAILED\n");
1544 result = -ENODEV;
1545 goto fail_pci_enable_device;
1548 /* enable busmastering (required for CardBus) */
1549 pci_set_master(pdev);
1552 /* chiptype is u8 but id->driver_data is ulong
1553 ** Works for now (possible values are 1 and 2) */
1554 chip_type = (u8) id->driver_data;
1555 /* acx100 and acx111 have different PCI memory regions */
1556 if (chip_type == CHIPTYPE_ACX100) {
1557 chip_name = "ACX100";
1558 mem_region1 = PCI_ACX100_REGION1;
1559 mem_region1_size = PCI_ACX100_REGION1_SIZE;
1561 mem_region2 = PCI_ACX100_REGION2;
1562 mem_region2_size = PCI_ACX100_REGION2_SIZE;
1563 } else if (chip_type == CHIPTYPE_ACX111) {
1564 chip_name = "ACX111";
1565 mem_region1 = PCI_ACX111_REGION1;
1566 mem_region1_size = PCI_ACX111_REGION1_SIZE;
1568 mem_region2 = PCI_ACX111_REGION2;
1569 mem_region2_size = PCI_ACX111_REGION2_SIZE;
1570 } else {
1571 printk("acx: unknown chip type 0x%04X\n", chip_type);
1572 goto fail_unknown_chiptype;
1575 /* Figure out our resources */
1576 phymem1 = pci_resource_start(pdev, mem_region1);
1577 phymem2 = pci_resource_start(pdev, mem_region2);
1578 if (!request_mem_region
1579 (phymem1, pci_resource_len(pdev, mem_region1), "acx_1")) {
1580 printk("acx: cannot reserve PCI memory region 1 (are you sure "
1581 "you have CardBus support in kernel?)\n");
1582 goto fail_request_mem_region1;
1584 if (!request_mem_region
1585 (phymem2, pci_resource_len(pdev, mem_region2), "acx_2")) {
1586 printk("acx: cannot reserve PCI memory region 2\n");
1587 goto fail_request_mem_region2;
1589 /* this used to be ioremap(), but ioremap_nocache()
1590 * is much less risky, right? (and slower?)
1591 * FIXME: we may want to go back to cached variant if it's
1592 * certain that our code really properly handles
1593 * cached operation (memory barriers, volatile?, ...)
1594 * (but always keep this comment here regardless!)
1595 * Possibly make this a driver config setting?
1598 mem1 = ioremap_nocache(phymem1, mem_region1_size);
1599 if (!mem1) {
1600 printk("acx: ioremap() FAILED\n");
1601 goto fail_ioremap1;
1603 mem2 = ioremap_nocache(phymem2, mem_region2_size);
1604 if (!mem2) {
1605 printk("acx: ioremap() #2 FAILED\n");
1606 goto fail_ioremap2;
1609 printk("acx: found %s-based wireless network card at %s, irq:%d, "
1610 "phymem1:0x%lX, phymem2:0x%lX, mem1:0x%p, mem1_size:%ld, "
1611 "mem2:0x%p, mem2_size:%ld\n",
1612 chip_name, pci_name(pdev), pdev->irq, phymem1, phymem2,
1613 mem1, mem_region1_size, mem2, mem_region2_size);
1614 log(L_ANY, "initial debug setting is 0x%04X\n", acx_debug);
1615 adev->chip_type = chip_type;
1616 adev->chip_name = chip_name;
1617 adev->io = (CHIPTYPE_ACX100 == chip_type) ? IO_ACX100 : IO_ACX111;
1618 adev->membase = phymem1;
1619 adev->iobase = mem1;
1620 adev->membase2 = phymem2;
1621 adev->iobase2 = mem2;
1622 adev->irq = pdev->irq;
1625 if (0 == pdev->irq) {
1626 printk("acx: can't use IRQ 0\n");
1627 goto fail_irq;
1629 SET_IEEE80211_DEV(ieee, &pdev->dev);
1632 /* to find crashes due to weird driver access
1633 * to unconfigured interface (ifup) */
1634 adev->mgmt_timer.function = (void (*)(unsigned long))0x0000dead;
1637 #ifdef NONESSENTIAL_FEATURES
1638 acx_show_card_eeprom_id(adev);
1639 #endif /* NONESSENTIAL_FEATURES */
1642 /* ok, pci setup is finished, now start initializing the card */
1644 /* NB: read_reg() reads may return bogus data before reset_dev(),
1645 * since the firmware which directly controls large parts of the I/O
1646 * registers isn't initialized yet.
1647 * acx100 seems to be more affected than acx111 */
1648 if (OK != acxpci_s_reset_dev(adev))
1649 goto fail_reset;
1651 if (IS_ACX100(adev)) {
1652 /* ACX100: configopt struct in cmd mailbox - directly after reset */
1653 memcpy_fromio(&co, adev->cmd_area, sizeof(co));
1656 if (OK != acx_s_init_mac(adev))
1657 goto fail_init_mac;
1659 if (IS_ACX111(adev)) {
1660 /* ACX111: configopt struct needs to be queried after full init */
1661 acx_s_interrogate(adev, &co, ACX111_IE_CONFIG_OPTIONS);
1663 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
1664 if (OK != acxpci_read_eeprom_byte(adev, 0x05, &adev->eeprom_version))
1665 goto fail_read_eeprom_version;
1667 acx_s_parse_configoption(adev, &co);
1668 acx_s_set_defaults(adev);
1669 acx_s_get_firmware_version(adev); /* needs to be after acx_s_init_mac() */
1670 acx_display_hardware_details(adev);
1672 /* Register the card, AFTER everything else has been set up,
1673 * since otherwise an ioctl could step on our feet due to
1674 * firmware operations happening in parallel or uninitialized data */
1677 acx_proc_register_entries(ieee);
1679 /* Now we have our device, so make sure the kernel doesn't try
1680 * to send packets even though we're not associated to a network yet */
1682 /* after register_netdev() userspace may start working with dev
1683 * (in particular, on other CPUs), we only need to up the sem */
1684 /* acx_sem_unlock(adev); */
1686 printk("acx " ACX_RELEASE ": net device %s, driver compiled "
1687 "against wireless extensions %d and Linux %s\n",
1688 wiphy_name(adev->ieee->wiphy), WIRELESS_EXT, UTS_RELEASE);
1690 MAC_COPY(adev->ieee->wiphy->perm_addr, adev->dev_addr);
1692 log(L_IRQ | L_INIT, "using IRQ %d\n", pdev->irq);
1694 /** done with board specific setup **/
1696 /* need to be able to restore PCI state after a suspend */
1697 #ifdef CONFIG_PM
1698 pci_save_state(pdev);
1699 #endif
1702 acx_init_task_scheduler(adev);
1703 err = ieee80211_register_hw(adev->ieee);
1704 if (OK != err) {
1705 printk("acx: ieee80211_register_hw() FAILED: %d\n", err);
1706 goto fail_register_netdev;
1708 #if CMD_DISCOVERY
1709 great_inquisitor(adev);
1710 #endif
1712 result = OK;
1713 goto done;
1715 /* error paths: undo everything in reverse order... */
1718 acxpci_s_delete_dma_regions(adev);
1719 pci_set_drvdata(pdev, NULL);
1721 fail_init_mac:
1722 fail_read_eeprom_version:
1723 fail_reset:
1725 fail_alloc_netdev:
1726 fail_irq:
1728 iounmap(mem2);
1729 fail_ioremap2:
1731 iounmap(mem1);
1732 fail_ioremap1:
1734 release_mem_region(pci_resource_start(pdev, mem_region2),
1735 pci_resource_len(pdev, mem_region2));
1736 fail_request_mem_region2:
1738 release_mem_region(pci_resource_start(pdev, mem_region1),
1739 pci_resource_len(pdev, mem_region1));
1740 fail_request_mem_region1:
1741 fail_unknown_chiptype:
1743 pci_disable_device(pdev);
1744 fail_pci_enable_device:
1746 #ifdef CONFIG_PM
1747 pci_set_power_state(pdev, PCI_D3hot);
1748 #endif
1749 fail_register_netdev:
1750 ieee80211_free_hw(ieee);
1751 done:
1752 FN_EXIT1(result);
1753 return result;
1757 /***********************************************************************
1758 ** acxpci_e_remove
1760 ** Shut device down (if not hot unplugged)
1761 ** and deallocate PCI resources for the acx chip.
1763 ** pdev - ptr to PCI device structure containing info about pci configuration
1765 static void __devexit acxpci_e_remove(struct pci_dev *pdev)
1767 struct ieee80211_hw *hw = (struct ieee80211_hw *)pci_get_drvdata(pdev);
1768 acx_device_t *adev = ieee2adev(hw);
1769 unsigned long mem_region1, mem_region2;
1770 unsigned long flags;
1771 FN_ENTER;
1773 if (!hw) {
1774 log(L_DEBUG, "%s: card is unused. Skipping any release code\n",
1775 __func__);
1776 goto end;
1780 acx_lock(adev, flags);
1781 acx_unlock(adev, flags);
1782 adev->initialized = 0;
1784 /* If device wasn't hot unplugged... */
1785 if (adev_present(adev)) {
1787 acx_sem_lock(adev);
1789 /* disable both Tx and Rx to shut radio down properly */
1790 if (adev->initialized) {
1791 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_TX, NULL, 0);
1792 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_RX, NULL, 0);
1794 #ifdef REDUNDANT
1795 /* put the eCPU to sleep to save power
1796 * Halting is not possible currently,
1797 * since not supported by all firmware versions */
1798 acx_s_issue_cmd(adev, ACX100_CMD_SLEEP, NULL, 0);
1799 #endif
1800 acx_lock(adev, flags);
1801 /* disable power LED to save power :-) */
1802 log(L_INIT, "switching off power LED to save power\n");
1803 acxpci_l_power_led(adev, 0);
1804 /* stop our eCPU */
1805 if (IS_ACX111(adev)) {
1806 /* FIXME: does this actually keep halting the eCPU?
1807 * I don't think so...
1809 acxpci_l_reset_mac(adev);
1810 } else {
1811 u16 temp;
1812 /* halt eCPU */
1813 temp = read_reg16(adev, IO_ACX_ECPU_CTRL) | 0x1;
1814 write_reg16(adev, IO_ACX_ECPU_CTRL, temp);
1815 write_flush(adev);
1817 acx_unlock(adev, flags);
1819 acx_sem_unlock(adev);
1822 /* unregister the device to not let the kernel
1823 * (e.g. ioctls) access a half-deconfigured device
1824 * NB: this will cause acxpci_e_close() to be called,
1825 * thus we shouldn't call it under sem!
1826 * Well, netdev did, but ieee80211 stack does not, so we
1827 * have to do so manually...
1829 acxpci_e_close(hw);
1830 log(L_INIT, "removing device %s\n", wiphy_name(adev->ieee->wiphy));
1831 ieee80211_unregister_hw(adev->ieee);
1833 /* unregister_netdev ensures that no references to us left.
1834 * For paranoid reasons we continue to follow the rules */
1835 acx_sem_lock(adev);
1837 if (adev->dev_state_mask & ACX_STATE_IFACE_UP) {
1838 acxpci_s_down(hw);
1839 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
1842 acx_proc_unregister_entries(adev->ieee);
1844 if (IS_ACX100(adev)) {
1845 mem_region1 = PCI_ACX100_REGION1;
1846 mem_region2 = PCI_ACX100_REGION2;
1847 } else {
1848 mem_region1 = PCI_ACX111_REGION1;
1849 mem_region2 = PCI_ACX111_REGION2;
1852 /* finally, clean up PCI bus state */
1853 acxpci_s_delete_dma_regions(adev);
1854 if (adev->iobase)
1855 iounmap(adev->iobase);
1856 if (adev->iobase2)
1857 iounmap(adev->iobase2);
1858 release_mem_region(pci_resource_start(pdev, mem_region1),
1859 pci_resource_len(pdev, mem_region1));
1860 release_mem_region(pci_resource_start(pdev, mem_region2),
1861 pci_resource_len(pdev, mem_region2));
1862 pci_disable_device(pdev);
1864 /* remove dev registration */
1866 free_irq(adev->irq, adev);
1867 acx_sem_unlock(adev);
1869 /* Free netdev (quite late,
1870 * since otherwise we might get caught off-guard
1871 * by a netdev timeout handler execution
1872 * expecting to see a working dev...) */
1873 ieee80211_free_hw(adev->ieee);
1875 /* put device into ACPI D3 mode (shutdown) */
1876 #ifdef CONFIG_PM
1877 pci_set_power_state(pdev, PCI_D3hot);
1878 #endif
1879 end:
1880 FN_EXIT0;
1884 /***********************************************************************
1885 ** TODO: PM code needs to be fixed / debugged / tested.
1887 #ifdef CONFIG_PM
1888 static int
1889 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
1890 acxpci_e_suspend(struct pci_dev *pdev, pm_message_t state)
1891 #else
1892 acxpci_e_suspend(struct pci_dev *pdev, u32 state)
1893 #endif
1895 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1896 acx_device_t *adev;
1898 FN_ENTER;
1899 printk("acx: suspend handler is experimental!\n");
1900 printk("sus: dev %p\n", hw);
1902 /* if (!netif_running(ndev))
1903 goto end;
1905 adev = ieee2adev(hw);
1906 printk("sus: adev %p\n", adev);
1908 acx_sem_lock(adev);
1910 ieee80211_unregister_hw(hw); /* this one cannot sleep */
1911 acxpci_s_down(hw);
1912 /* down() does not set it to 0xffff, but here we really want that */
1913 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
1914 write_reg16(adev, IO_ACX_FEMR, 0x0);
1915 acxpci_s_delete_dma_regions(adev);
1916 pci_save_state(pdev);
1917 pci_set_power_state(pdev, PCI_D3hot);
1919 acx_sem_unlock(adev);
1920 FN_EXIT0;
1921 return OK;
1925 static int acxpci_e_resume(struct pci_dev *pdev)
1927 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1928 acx_device_t *adev;
1930 FN_ENTER;
1932 printk("acx: resume handler is experimental!\n");
1933 printk("rsm: got dev %p\n", hw);
1936 adev = ieee2adev(hw);
1937 printk("rsm: got adev %p\n", adev);
1939 acx_sem_lock(adev);
1941 pci_set_power_state(pdev, PCI_D0);
1942 printk("rsm: power state PCI_D0 set\n");
1943 pci_restore_state(pdev);
1944 printk("rsm: PCI state restored\n");
1946 if (OK != acxpci_s_reset_dev(adev))
1947 goto end_unlock;
1948 printk("rsm: device reset done\n");
1949 if (OK != acx_s_init_mac(adev))
1950 goto end_unlock;
1951 printk("rsm: init MAC done\n");
1953 acxpci_s_up(hw);
1954 printk("rsm: acx up done\n");
1956 /* now even reload all card parameters as they were before suspend,
1957 * and possibly be back in the network again already :-) */
1958 if (ACX_STATE_IFACE_UP & adev->dev_state_mask) {
1959 adev->set_mask = GETSET_ALL;
1960 acx_s_update_card_settings(adev);
1961 printk("rsm: settings updated\n");
1963 ieee80211_register_hw(hw);
1964 printk("rsm: device attached\n");
1966 end_unlock:
1967 acx_sem_unlock(adev);
1968 /* we need to return OK here anyway, right? */
1969 FN_EXIT0;
1970 return OK;
1972 #endif /* CONFIG_PM */
1973 #endif /* CONFIG_PCI */
1975 /***********************************************************************
1976 ** acxpci_s_up
1978 ** This function is called by acxpci_e_open (when ifconfig sets the device as up)
1980 ** Side effects:
1981 ** - Enables on-card interrupt requests
1982 ** - calls acx_s_start
1985 static void enable_acx_irq(acx_device_t * adev)
1987 FN_ENTER;
1988 write_reg16(adev, IO_ACX_IRQ_MASK, adev->irq_mask);
1989 write_reg16(adev, IO_ACX_FEMR, 0x8000);
1990 adev->irqs_active = 1;
1991 FN_EXIT0;
1994 static void acxpci_s_up(struct ieee80211_hw *hw)
1996 acx_device_t *adev = ieee2adev(hw);
1997 unsigned long flags;
1999 FN_ENTER;
2001 acx_lock(adev, flags);
2002 enable_acx_irq(adev);
2003 acx_unlock(adev, flags);
2005 /* acx fw < 1.9.3.e has a hardware timer, and older drivers
2006 ** used to use it. But we don't do that anymore, our OS
2007 ** has reliable software timers */
2008 init_timer(&adev->mgmt_timer);
2009 adev->mgmt_timer.function = acx_i_timer;
2010 adev->mgmt_timer.data = (unsigned long)adev;
2012 /* Need to set ACX_STATE_IFACE_UP first, or else
2013 ** timer won't be started by acx_set_status() */
2014 SET_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
2016 acx_s_start(adev);
2018 FN_EXIT0;
2022 /***********************************************************************
2023 ** acxpci_s_down
2025 ** NB: device may be already hot unplugged if called from acxpci_e_remove()
2027 ** Disables on-card interrupt request, stops softirq and timer, stops queue,
2028 ** sets status == STOPPED
2031 static void disable_acx_irq(acx_device_t * adev)
2033 FN_ENTER;
2035 /* I guess mask is not 0xffff because acx100 won't signal
2036 ** cmd completion then (needed for ifup).
2037 ** I can't ifconfig up after ifconfig down'ing on my acx100 */
2038 write_reg16(adev, IO_ACX_IRQ_MASK, adev->irq_mask_off);
2039 write_reg16(adev, IO_ACX_FEMR, 0x0);
2040 adev->irqs_active = 0;
2042 FN_EXIT0;
2045 static void acxpci_s_down(struct ieee80211_hw *hw)
2047 acx_device_t *adev = ieee2adev(hw);
2049 FN_ENTER;
2051 /* Disable IRQs first, so that IRQs cannot race with us */
2052 /* then wait until interrupts have finished executing on other CPUs */
2053 disable_acx_irq(adev); /* NO sem-locking here? */
2054 synchronize_irq(adev->irq);
2056 /* we really don't want to have an asynchronous tasklet disturb us
2057 ** after something vital for its job has been shut down, so
2058 ** end all remaining work now.
2060 ** NB: carrier_off (done by set_status below) would lead to
2061 ** not yet fully understood deadlock in flush_scheduled_work().
2062 ** That's why we do FLUSH first.
2064 ** NB2: we have a bad locking bug here: flush_scheduled_work()
2065 ** waits for acx_e_after_interrupt_task to complete if it is running
2066 ** on another CPU, but acx_e_after_interrupt_task
2067 ** will sleep on sem forever, because it is taken by us!
2068 ** Work around that by temporary sem unlock.
2069 ** This will fail miserably if we'll be hit by concurrent
2070 ** iwconfig or something in between. TODO! */
2071 acx_sem_unlock(adev); /* valid? */
2072 flush_scheduled_work();
2073 acx_sem_lock(adev); /* valid? */
2075 /* This is possible:
2076 ** flush_scheduled_work -> acx_e_after_interrupt_task ->
2077 ** -> set_status(ASSOCIATED) -> wake_queue()
2078 ** That's why we stop queue _after_ flush_scheduled_work
2079 ** lock/unlock is just paranoia, maybe not needed */
2081 /* kernel/timer.c says it's illegal to del_timer_sync()
2082 ** a timer which restarts itself. We guarantee this cannot
2083 ** ever happen because acx_i_timer() never does this if
2084 ** status is ACX_STATUS_0_STOPPED */
2085 del_timer_sync(&adev->mgmt_timer);
2087 FN_EXIT0;
2090 #ifdef CONFIG_NET_POLL_CONTROLLER
2091 void acxpci_net_poll_controller(struct net_device *net_dev)
2093 acx_device_t *adev = ndev2adev(net_dev);
2094 unsigned long flags;
2096 local_irq_save(flags);
2097 acxpci_i_interrupt(adev->irq, adev);
2098 local_irq_restore(flags);
2100 #endif*/ /* CONFIG_NET_POLL_CONTROLLER */
2102 /***********************************************************************
2103 ** acxpci_e_open
2105 ** Called as a result of SIOCSIFFLAGS ioctl changing the flags bit IFF_UP
2106 ** from clear to set. In other words: ifconfig up.
2108 ** Returns:
2109 ** 0 success
2110 ** >0 f/w reported error
2111 ** <0 driver reported error
2113 static int acxpci_e_open(struct ieee80211_hw *hw)
2115 acx_device_t *adev = ieee2adev(hw);
2116 int result = OK;
2118 FN_ENTER;
2120 acx_sem_lock(adev);
2122 adev->initialized = 0;
2124 /* TODO: pci_set_power_state(pdev, PCI_D0); ? */
2126 /* request shared IRQ handler */
2127 if (request_irq
2128 (adev->irq, acxpci_i_interrupt, IRQF_SHARED, KBUILD_MODNAME, adev)) {
2129 printk("%s: request_irq FAILED\n", wiphy_name(adev->ieee->wiphy));
2130 result = -EAGAIN;
2131 goto done;
2133 log(L_DEBUG | L_IRQ, "request_irq %d successful\n", adev->irq);
2135 /* ifup device */
2136 acxpci_s_up(hw);
2138 /* We don't currently have to do anything else.
2139 * The setup of the MAC should be subsequently completed via
2140 * the mlme commands.
2141 * Higher layers know we're ready from dev->start==1 and
2142 * dev->tbusy==0. Our rx path knows to pass up received/
2143 * frames because of dev->flags&IFF_UP is true.
2145 acx_setup_modes(adev);
2146 ieee80211_start_queues(adev->ieee);
2148 adev->initialized = 1;
2149 done:
2150 acx_sem_unlock(adev);
2152 FN_EXIT1(result);
2153 return result;
2157 /***********************************************************************
2158 ** acxpci_e_close
2160 ** This function stops the network functionality of the interface (invoked
2161 ** when the user calls ifconfig <wlan> down). The tx queue is halted and
2162 ** the device is marked as down.
2164 ** Called as a result of SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
2165 ** from set to clear. I.e. called by "ifconfig DEV down"
2167 ** Returns:
2168 ** 0 success
2169 ** >0 f/w reported error
2170 ** <0 driver reported error
2172 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
2173 static int acxpci_e_close(struct ieee80211_hw *hw)
2174 #else
2175 static void acxpci_e_close(struct ieee80211_hw *hw)
2176 #endif
2178 acx_device_t *adev = ieee2adev(hw);
2180 FN_ENTER;
2182 acx_sem_lock(adev);
2184 /* ifdown device */
2185 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
2186 if (adev->initialized) {
2187 acxpci_s_down(hw);
2190 if (adev->modes)
2191 acx_free_modes(adev);
2192 /* disable all IRQs, release shared IRQ handler */
2193 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
2194 write_reg16(adev, IO_ACX_FEMR, 0x0);
2196 /* TODO: pci_set_power_state(pdev, PCI_D3hot); ? */
2198 /* We currently don't have to do anything else.
2199 * Higher layers know we're not ready from dev->start==0 and
2200 * dev->tbusy==1. Our rx path knows to not pass up received
2201 * frames because of dev->flags&IFF_UP is false.
2203 acx_sem_unlock(adev);
2205 log(L_INIT, "closed device\n");
2206 FN_EXIT0;
2207 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
2208 return OK;
2209 #endif
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("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, "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, "info_type:%04X info_status:%04X\n", info_type, info_status);
2376 log(L_IRQ, "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(" Rx_Data");
2395 /* HOST_INT_TX_COMPLETE */
2396 if (irqtype & HOST_INT_TX_XFER) {
2397 printk(" Tx_Xfer");
2399 /* HOST_INT_RX_COMPLETE */
2400 if (irqtype & HOST_INT_DTIM) {
2401 printk(" DTIM");
2403 if (irqtype & HOST_INT_BEACON) {
2404 printk(" Beacon");
2406 if (irqtype & HOST_INT_TIMER) {
2407 log(L_IRQ, " Timer");
2409 if (irqtype & HOST_INT_KEY_NOT_FOUND) {
2410 printk(" Key_Not_Found");
2412 if (irqtype & HOST_INT_IV_ICV_FAILURE) {
2413 printk(" IV_ICV_Failure (crypto)");
2415 /* HOST_INT_CMD_COMPLETE */
2416 /* HOST_INT_INFO */
2417 if (irqtype & HOST_INT_OVERFLOW) {
2418 printk(" Overflow");
2420 if (irqtype & HOST_INT_PROCESS_ERROR) {
2421 printk(" Process_Error");
2423 /* HOST_INT_SCAN_COMPLETE */
2424 if (irqtype & HOST_INT_FCS_THRESHOLD) {
2425 printk(" FCS_Threshold");
2427 if (irqtype & HOST_INT_UNKNOWN) {
2428 printk(" Unknown");
2430 printk(" 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 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2474 * I am paranoid */
2475 acx_sem_lock(adev);
2478 FN_ENTER;
2479 irqtype = adev->irq_reason;
2480 adev->irq_reason = 0;
2482 #define IRQ_ITERATE 0
2483 #if IRQ_ITERATE
2484 if (jiffies != adev->irq_last_jiffies) {
2485 adev->irq_loops_this_jiffy = 0;
2486 adev->irq_last_jiffies = jiffies;
2489 /* safety condition; we'll normally abort loop below
2490 * in case no IRQ type occurred */
2491 while (likely(--irqcount)) {
2492 #endif
2493 /* ACK all IRQs ASAP */
2496 /* Handle most important IRQ types first */
2497 if (irqtype & HOST_INT_RX_COMPLETE) {
2498 log(L_IRQ, "got Rx_Complete IRQ\n");
2499 acxpci_l_process_rxdesc(adev);
2501 if (irqtype & HOST_INT_TX_COMPLETE) {
2502 log(L_IRQ, "got Tx_Complete IRQ\n");
2503 /* don't clean up on each Tx complete, wait a bit
2504 * unless we're going towards full, in which case
2505 * we do it immediately, too (otherwise we might lockup
2506 * with a full Tx buffer if we go into
2507 * acxpci_l_clean_txdesc() at a time when we won't wakeup
2508 * the net queue in there for some reason...) */
2509 // if (adev->tx_free <= TX_START_CLEAN) {
2510 acxpci_l_clean_txdesc(adev);
2511 // }
2514 /* Less frequent ones */
2515 if (irqtype & (0
2516 | HOST_INT_CMD_COMPLETE
2517 | HOST_INT_INFO | HOST_INT_SCAN_COMPLETE)) {
2518 if (irqtype & HOST_INT_INFO) {
2519 handle_info_irq(adev);
2521 if (irqtype & HOST_INT_SCAN_COMPLETE) {
2522 log(L_IRQ, "got Scan_Complete IRQ\n");
2523 /* need to do that in process context */
2524 /* remember that fw is not scanning anymore */
2525 SET_BIT(adev->irq_status,
2526 HOST_INT_SCAN_COMPLETE);
2530 /* These we just log, but either they happen rarely
2531 * or we keep them masked out */
2532 if (irqtype & (0 | HOST_INT_RX_DATA
2533 /* | HOST_INT_TX_COMPLETE */
2534 | HOST_INT_TX_XFER
2535 /* | HOST_INT_RX_COMPLETE */
2536 | HOST_INT_DTIM
2537 | HOST_INT_BEACON
2538 | HOST_INT_TIMER
2539 | HOST_INT_KEY_NOT_FOUND
2540 | HOST_INT_IV_ICV_FAILURE
2541 /* | HOST_INT_CMD_COMPLETE */
2542 /* | HOST_INT_INFO */
2543 | HOST_INT_OVERFLOW | HOST_INT_PROCESS_ERROR
2544 /* | HOST_INT_SCAN_COMPLETE */
2545 | HOST_INT_FCS_THRESHOLD | HOST_INT_UNKNOWN)) {
2546 log_unusual_irq(irqtype);
2548 #if IRQ_ITERATE
2549 unmasked = read_reg16(adev, IO_ACX_IRQ_STATUS_CLEAR);
2550 irqtype = unmasked & ~adev->irq_mask;
2551 /* Bail out if no new IRQ bits or if all are masked out */
2552 if (!irqtype)
2553 break;
2555 if (unlikely
2556 (++adev->irq_loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY)) {
2557 printk(KERN_ERR
2558 "acx: too many interrupts per jiffy!\n");
2559 /* Looks like card floods us with IRQs! Try to stop that */
2560 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
2561 /* This will short-circuit all future attempts to handle IRQ.
2562 * We cant do much more... */
2563 adev->irq_mask = 0;
2564 break;
2567 #endif
2568 /* Routine to perform blink with range
2569 * FIXME: update_link_quality_led is a stub - add proper code and enable this again:
2570 if (unlikely(adev->led_power == 2))
2571 update_link_quality_led(adev);
2574 /* handled: */
2575 if (adev->after_interrupt_jobs)
2576 acx_e_after_interrupt_task(&adev->after_interrupt_task);
2578 /* write_flush(adev); - not needed, last op was read anyway */
2579 acx_sem_unlock(adev);
2580 FN_EXIT0;
2581 return;
2586 static irqreturn_t
2587 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
2588 acxpci_i_interrupt(int irq, void *dev_id)
2589 #else
2590 acxpci_i_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2591 #endif
2593 acx_device_t *adev = dev_id;
2594 unsigned long flags;
2595 register u16 irqtype;
2596 u16 unmasked;
2598 FN_ENTER;
2600 if (!adev)
2601 return IRQ_NONE;
2603 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2604 * I am paranoid */
2606 acx_lock(adev, flags);
2608 unmasked = read_reg16(adev, IO_ACX_IRQ_STATUS_CLEAR);
2609 if (unlikely(0xffff == unmasked)) {
2610 /* 0xffff value hints at missing hardware,
2611 * so don't do anything.
2612 * Not very clean, but other drivers do the same... */
2613 log(L_IRQ, "IRQ type:FFFF - device removed? IRQ_NONE\n");
2614 goto none;
2617 /* We will check only "interesting" IRQ types */
2618 irqtype = unmasked & ~adev->irq_mask;
2619 if (!irqtype) {
2620 /* We are on a shared IRQ line and it wasn't our IRQ */
2621 log(L_IRQ,
2622 "IRQ type:%04X, mask:%04X - all are masked, IRQ_NONE\n",
2623 unmasked, adev->irq_mask);
2624 goto none;
2627 /* Go ahead and ACK our interrupt */
2628 write_reg16(adev, IO_ACX_IRQ_ACK, 0xffff);
2629 if (irqtype & HOST_INT_CMD_COMPLETE) {
2630 log(L_IRQ, "got Command_Complete IRQ\n");
2631 /* save the state for the running issue_cmd() */
2632 SET_BIT(adev->irq_status, HOST_INT_CMD_COMPLETE);
2635 /* Only accept IRQs, if we are initialized properly.
2636 * This avoids an RX race while initializing.
2637 * We should probably not enable IRQs before we are initialized
2638 * completely, but some careful work is needed to fix this. I think it
2639 * is best to stay with this cheap workaround for now... .
2641 if (likely(adev->initialized)) {
2642 /* disable all IRQs. They are enabled again in the bottom half. */
2643 /* save the reason code and call our bottom half. */
2644 adev->irq_reason = irqtype;
2646 if ((irqtype & HOST_INT_RX_COMPLETE) || (irqtype & HOST_INT_TX_COMPLETE))
2647 acx_schedule_task(adev, 0);
2650 acx_unlock(adev, flags);
2651 FN_EXIT0;
2652 return IRQ_HANDLED;
2653 none:
2654 acx_unlock(adev, flags);
2655 FN_EXIT0;
2656 return IRQ_NONE;
2661 /***********************************************************************
2662 ** acxpci_l_power_led
2664 void acxpci_l_power_led(acx_device_t * adev, int enable)
2666 u16 gpio_pled = IS_ACX111(adev) ? 0x0040 : 0x0800;
2668 /* A hack. Not moving message rate limiting to adev->xxx
2669 * (it's only a debug message after all) */
2670 static int rate_limit = 0;
2672 if (rate_limit++ < 3)
2673 log(L_IOCTL, "Please report in case toggling the power "
2674 "LED doesn't work for your card!\n");
2675 if (enable)
2676 write_reg16(adev, IO_ACX_GPIO_OUT,
2677 read_reg16(adev, IO_ACX_GPIO_OUT) & ~gpio_pled);
2678 else
2679 write_reg16(adev, IO_ACX_GPIO_OUT,
2680 read_reg16(adev, IO_ACX_GPIO_OUT) | gpio_pled);
2684 /***********************************************************************
2685 ** Ioctls
2688 /***********************************************************************
2690 #if 0
2692 acx111pci_ioctl_info(struct net_device *ndev,
2693 struct iw_request_info *info,
2694 struct iw_param *vwrq, char *extra)
2696 #if ACX_DEBUG > 1
2697 acx_device_t *adev = ndev2adev(ndev);
2698 rxdesc_t *rxdesc;
2699 txdesc_t *txdesc;
2700 rxhostdesc_t *rxhostdesc;
2701 txhostdesc_t *txhostdesc;
2702 struct acx111_ie_memoryconfig memconf;
2703 struct acx111_ie_queueconfig queueconf;
2704 unsigned long flags;
2705 int i;
2706 char memmap[0x34];
2707 char rxconfig[0x8];
2708 char fcserror[0x8];
2709 char ratefallback[0x5];
2711 if (!(acx_debug & (L_IOCTL | L_DEBUG)))
2712 return OK;
2713 /* using printk() since we checked debug flag already */
2715 acx_sem_lock(adev);
2717 if (!IS_ACX111(adev)) {
2718 printk("acx111-specific function called "
2719 "with non-acx111 chip, aborting\n");
2720 goto end_ok;
2723 /* get Acx111 Memory Configuration */
2724 memset(&memconf, 0, sizeof(memconf));
2725 /* BTW, fails with 12 (Write only) error code.
2726 ** Retained for easy testing of issue_cmd error handling :) */
2727 acx_s_interrogate(adev, &memconf, ACX1xx_IE_QUEUE_CONFIG);
2729 /* get Acx111 Queue Configuration */
2730 memset(&queueconf, 0, sizeof(queueconf));
2731 acx_s_interrogate(adev, &queueconf, ACX1xx_IE_MEMORY_CONFIG_OPTIONS);
2733 /* get Acx111 Memory Map */
2734 memset(memmap, 0, sizeof(memmap));
2735 acx_s_interrogate(adev, &memmap, ACX1xx_IE_MEMORY_MAP);
2737 /* get Acx111 Rx Config */
2738 memset(rxconfig, 0, sizeof(rxconfig));
2739 acx_s_interrogate(adev, &rxconfig, ACX1xx_IE_RXCONFIG);
2741 /* get Acx111 fcs error count */
2742 memset(fcserror, 0, sizeof(fcserror));
2743 acx_s_interrogate(adev, &fcserror, ACX1xx_IE_FCS_ERROR_COUNT);
2745 /* get Acx111 rate fallback */
2746 memset(ratefallback, 0, sizeof(ratefallback));
2747 acx_s_interrogate(adev, &ratefallback, ACX1xx_IE_RATE_FALLBACK);
2749 /* force occurrence of a beacon interrupt */
2750 /* TODO: comment why is this necessary */
2751 write_reg16(adev, IO_ACX_HINT_TRIG, HOST_INT_BEACON);
2753 /* dump Acx111 Mem Configuration */
2754 printk("dump mem config:\n"
2755 "data read: %d, struct size: %d\n"
2756 "Number of stations: %1X\n"
2757 "Memory block size: %1X\n"
2758 "tx/rx memory block allocation: %1X\n"
2759 "count rx: %X / tx: %X queues\n"
2760 "options %1X\n"
2761 "fragmentation %1X\n"
2762 "Rx Queue 1 Count Descriptors: %X\n"
2763 "Rx Queue 1 Host Memory Start: %X\n"
2764 "Tx Queue 1 Count Descriptors: %X\n"
2765 "Tx Queue 1 Attributes: %X\n",
2766 memconf.len, (int)sizeof(memconf),
2767 memconf.no_of_stations,
2768 memconf.memory_block_size,
2769 memconf.tx_rx_memory_block_allocation,
2770 memconf.count_rx_queues, memconf.count_tx_queues,
2771 memconf.options,
2772 memconf.fragmentation,
2773 memconf.rx_queue1_count_descs,
2774 acx2cpu(memconf.rx_queue1_host_rx_start),
2775 memconf.tx_queue1_count_descs, memconf.tx_queue1_attributes);
2777 /* dump Acx111 Queue Configuration */
2778 printk("dump queue head:\n"
2779 "data read: %d, struct size: %d\n"
2780 "tx_memory_block_address (from card): %X\n"
2781 "rx_memory_block_address (from card): %X\n"
2782 "rx1_queue address (from card): %X\n"
2783 "tx1_queue address (from card): %X\n"
2784 "tx1_queue attributes (from card): %X\n",
2785 queueconf.len, (int)sizeof(queueconf),
2786 queueconf.tx_memory_block_address,
2787 queueconf.rx_memory_block_address,
2788 queueconf.rx1_queue_address,
2789 queueconf.tx1_queue_address, queueconf.tx1_attributes);
2791 /* dump Acx111 Mem Map */
2792 printk("dump mem map:\n"
2793 "data read: %d, struct size: %d\n"
2794 "Code start: %X\n"
2795 "Code end: %X\n"
2796 "WEP default key start: %X\n"
2797 "WEP default key end: %X\n"
2798 "STA table start: %X\n"
2799 "STA table end: %X\n"
2800 "Packet template start: %X\n"
2801 "Packet template end: %X\n"
2802 "Queue memory start: %X\n"
2803 "Queue memory end: %X\n"
2804 "Packet memory pool start: %X\n"
2805 "Packet memory pool end: %X\n"
2806 "iobase: %p\n"
2807 "iobase2: %p\n",
2808 *((u16 *) & memmap[0x02]), (int)sizeof(memmap),
2809 *((u32 *) & memmap[0x04]),
2810 *((u32 *) & memmap[0x08]),
2811 *((u32 *) & memmap[0x0C]),
2812 *((u32 *) & memmap[0x10]),
2813 *((u32 *) & memmap[0x14]),
2814 *((u32 *) & memmap[0x18]),
2815 *((u32 *) & memmap[0x1C]),
2816 *((u32 *) & memmap[0x20]),
2817 *((u32 *) & memmap[0x24]),
2818 *((u32 *) & memmap[0x28]),
2819 *((u32 *) & memmap[0x2C]),
2820 *((u32 *) & memmap[0x30]), adev->iobase, adev->iobase2);
2822 /* dump Acx111 Rx Config */
2823 printk("dump rx config:\n"
2824 "data read: %d, struct size: %d\n"
2825 "rx config: %X\n"
2826 "rx filter config: %X\n",
2827 *((u16 *) & rxconfig[0x02]), (int)sizeof(rxconfig),
2828 *((u16 *) & rxconfig[0x04]), *((u16 *) & rxconfig[0x06]));
2830 /* dump Acx111 fcs error */
2831 printk("dump fcserror:\n"
2832 "data read: %d, struct size: %d\n"
2833 "fcserrors: %X\n",
2834 *((u16 *) & fcserror[0x02]), (int)sizeof(fcserror),
2835 *((u32 *) & fcserror[0x04]));
2837 /* dump Acx111 rate fallback */
2838 printk("dump rate fallback:\n"
2839 "data read: %d, struct size: %d\n"
2840 "ratefallback: %X\n",
2841 *((u16 *) & ratefallback[0x02]), (int)sizeof(ratefallback),
2842 *((u8 *) & ratefallback[0x04]));
2844 /* protect against IRQ */
2845 acx_lock(adev, flags);
2847 /* dump acx111 internal rx descriptor ring buffer */
2848 rxdesc = adev->rxdesc_start;
2850 /* loop over complete receive pool */
2851 if (rxdesc)
2852 for (i = 0; i < RX_CNT; i++) {
2853 printk("\ndump internal rxdesc %d:\n"
2854 "mem pos %p\n"
2855 "next 0x%X\n"
2856 "acx mem pointer (dynamic) 0x%X\n"
2857 "CTL (dynamic) 0x%X\n"
2858 "Rate (dynamic) 0x%X\n"
2859 "RxStatus (dynamic) 0x%X\n"
2860 "Mod/Pre (dynamic) 0x%X\n",
2862 rxdesc,
2863 acx2cpu(rxdesc->pNextDesc),
2864 acx2cpu(rxdesc->ACXMemPtr),
2865 rxdesc->Ctl_8,
2866 rxdesc->rate, rxdesc->error, rxdesc->SNR);
2867 rxdesc++;
2870 /* dump host rx descriptor ring buffer */
2872 rxhostdesc = adev->rxhostdesc_start;
2874 /* loop over complete receive pool */
2875 if (rxhostdesc)
2876 for (i = 0; i < RX_CNT; i++) {
2877 printk("\ndump host rxdesc %d:\n"
2878 "mem pos %p\n"
2879 "buffer mem pos 0x%X\n"
2880 "buffer mem offset 0x%X\n"
2881 "CTL 0x%X\n"
2882 "Length 0x%X\n"
2883 "next 0x%X\n"
2884 "Status 0x%X\n",
2886 rxhostdesc,
2887 acx2cpu(rxhostdesc->data_phy),
2888 rxhostdesc->data_offset,
2889 le16_to_cpu(rxhostdesc->Ctl_16),
2890 le16_to_cpu(rxhostdesc->length),
2891 acx2cpu(rxhostdesc->desc_phy_next),
2892 rxhostdesc->Status);
2893 rxhostdesc++;
2896 /* dump acx111 internal tx descriptor ring buffer */
2897 txdesc = adev->txdesc_start;
2899 /* loop over complete transmit pool */
2900 if (txdesc)
2901 for (i = 0; i < TX_CNT; i++) {
2902 printk("\ndump internal txdesc %d:\n"
2903 "size 0x%X\n"
2904 "mem pos %p\n"
2905 "next 0x%X\n"
2906 "acx mem pointer (dynamic) 0x%X\n"
2907 "host mem pointer (dynamic) 0x%X\n"
2908 "length (dynamic) 0x%X\n"
2909 "CTL (dynamic) 0x%X\n"
2910 "CTL2 (dynamic) 0x%X\n"
2911 "Status (dynamic) 0x%X\n"
2912 "Rate (dynamic) 0x%X\n",
2914 (int)sizeof(struct txdesc),
2915 txdesc,
2916 acx2cpu(txdesc->pNextDesc),
2917 acx2cpu(txdesc->AcxMemPtr),
2918 acx2cpu(txdesc->HostMemPtr),
2919 le16_to_cpu(txdesc->total_length),
2920 txdesc->Ctl_8,
2921 txdesc->Ctl2_8, txdesc->error,
2922 txdesc->u.r1.rate);
2923 txdesc = advance_txdesc(adev, txdesc, 1);
2926 /* dump host tx descriptor ring buffer */
2928 txhostdesc = adev->txhostdesc_start;
2930 /* loop over complete host send pool */
2931 if (txhostdesc)
2932 for (i = 0; i < TX_CNT * 2; i++) {
2933 printk("\ndump host txdesc %d:\n"
2934 "mem pos %p\n"
2935 "buffer mem pos 0x%X\n"
2936 "buffer mem offset 0x%X\n"
2937 "CTL 0x%X\n"
2938 "Length 0x%X\n"
2939 "next 0x%X\n"
2940 "Status 0x%X\n",
2942 txhostdesc,
2943 acx2cpu(txhostdesc->data_phy),
2944 txhostdesc->data_offset,
2945 le16_to_cpu(txhostdesc->Ctl_16),
2946 le16_to_cpu(txhostdesc->length),
2947 acx2cpu(txhostdesc->desc_phy_next),
2948 le32_to_cpu(txhostdesc->Status));
2949 txhostdesc++;
2952 /* write_reg16(adev, 0xb4, 0x4); */
2954 acx_unlock(adev, flags);
2955 end_ok:
2957 acx_sem_unlock(adev);
2958 #endif /* ACX_DEBUG */
2959 return OK;
2963 /***********************************************************************
2966 acx100pci_ioctl_set_phy_amp_bias(struct net_device *ndev,
2967 struct iw_request_info *info,
2968 struct iw_param *vwrq, char *extra)
2970 acx_device_t *adev = ndev2adev(ndev);
2971 unsigned long flags;
2972 u16 gpio_old;
2974 if (!IS_ACX100(adev)) {
2975 /* WARNING!!!
2976 * Removing this check *might* damage
2977 * hardware, since we're tweaking GPIOs here after all!!!
2978 * You've been warned...
2979 * WARNING!!! */
2980 printk("acx: sorry, setting bias level for non-acx100 "
2981 "is not supported yet\n");
2982 return OK;
2985 if (*extra > 7) {
2986 printk("acx: invalid bias parameter, range is 0-7\n");
2987 return -EINVAL;
2990 acx_sem_lock(adev);
2992 /* Need to lock accesses to [IO_ACX_GPIO_OUT]:
2993 * IRQ handler uses it to update LED */
2994 acx_lock(adev, flags);
2995 gpio_old = read_reg16(adev, IO_ACX_GPIO_OUT);
2996 write_reg16(adev, IO_ACX_GPIO_OUT,
2997 (gpio_old & 0xf8ff) | ((u16) * extra << 8));
2998 acx_unlock(adev, flags);
3000 log(L_DEBUG, "gpio_old: 0x%04X\n", gpio_old);
3001 printk("%s: PHY power amplifier bias: old:%d, new:%d\n",
3002 ndev->name, (gpio_old & 0x0700) >> 8, (unsigned char)*extra);
3004 acx_sem_unlock(adev);
3006 return OK;
3008 #endif
3010 /***************************************************************
3011 ** acxpci_l_alloc_tx
3012 ** Actually returns a txdesc_t* ptr
3014 ** FIXME: in case of fragments, should allocate multiple descrs
3015 ** after figuring out how many we need and whether we still have
3016 ** sufficiently many.
3018 tx_t *acxpci_l_alloc_tx(acx_device_t * adev)
3020 struct txdesc *txdesc;
3021 unsigned head;
3022 u8 ctl8;
3024 FN_ENTER;
3026 if (unlikely(!adev->tx_free)) {
3027 printk("acx: BUG: no free txdesc left\n");
3028 txdesc = NULL;
3029 goto end;
3032 head = adev->tx_head;
3033 txdesc = get_txdesc(adev, head);
3034 ctl8 = txdesc->Ctl_8;
3036 /* 2005-10-11: there were several bug reports on this happening
3037 ** but now cause seems to be understood & fixed */
3038 if (unlikely(DESC_CTL_HOSTOWN != (ctl8 & DESC_CTL_ACXDONE_HOSTOWN))) {
3039 /* whoops, descr at current index is not free, so probably
3040 * ring buffer already full */
3041 printk("acx: BUG: tx_head:%d Ctl8:0x%02X - failed to find "
3042 "free txdesc\n", head, ctl8);
3043 txdesc = NULL;
3044 goto end;
3047 /* Needed in case txdesc won't be eventually submitted for tx */
3048 txdesc->Ctl_8 = DESC_CTL_ACXDONE_HOSTOWN;
3050 adev->tx_free--;
3051 log(L_BUFT, "tx: got desc %u, %u remain\n", head, adev->tx_free);
3052 /* Keep a few free descs between head and tail of tx ring.
3053 ** It is not absolutely needed, just feels safer */
3054 if (adev->tx_free < TX_STOP_QUEUE) {
3055 log(L_BUF, "stop queue (%u tx desc left)\n", adev->tx_free);
3056 acx_stop_queue(adev->ieee, NULL);
3059 /* returning current descriptor, so advance to next free one */
3060 adev->tx_head = (head + 1) % TX_CNT;
3061 end:
3062 FN_EXIT0;
3064 return (tx_t *) txdesc;
3068 /***********************************************************************
3070 void *acxpci_l_get_txbuf(acx_device_t * adev, tx_t * tx_opaque)
3072 return get_txhostdesc(adev, (txdesc_t *) tx_opaque)->data;
3076 /***********************************************************************
3077 ** acxpci_l_tx_data
3079 ** Can be called from IRQ (rx -> (AP bridging or mgmt response) -> tx).
3080 ** Can be called from acx_i_start_xmit (data frames from net core).
3082 ** FIXME: in case of fragments, should loop over the number of
3083 ** pre-allocated tx descrs, properly setting up transfer data and
3084 ** CTL_xxx flags according to fragment number.
3086 void
3087 acxpci_l_tx_data(acx_device_t * adev, tx_t * tx_opaque, int len,
3088 struct ieee80211_tx_control *ieeectl,struct sk_buff* skb)
3090 txdesc_t *txdesc = (txdesc_t *) tx_opaque;
3091 struct ieee80211_hdr *wireless_header;
3092 txhostdesc_t *hostdesc1, *hostdesc2;
3093 int rate_cur;
3094 u8 Ctl_8, Ctl2_8;
3095 int wlhdr_len;
3097 FN_ENTER;
3099 /* fw doesn't tx such packets anyhow */
3100 /* if (unlikely(len < WLAN_HDR_A3_LEN))
3101 goto end;
3103 hostdesc1 = get_txhostdesc(adev, txdesc);
3104 wireless_header = (struct ieee80211_hdr *)hostdesc1->data;
3105 /* modify flag status in separate variable to be able to write it back
3106 * in one big swoop later (also in order to have less device memory
3107 * accesses) */
3108 Ctl_8 = txdesc->Ctl_8;
3109 Ctl2_8 = 0; /* really need to init it to 0, not txdesc->Ctl2_8, it seems */
3111 hostdesc2 = hostdesc1 + 1;
3113 /* DON'T simply set Ctl field to 0 here globally,
3114 * it needs to maintain a consistent flag status (those are state flags!!),
3115 * otherwise it may lead to severe disruption. Only set or reset particular
3116 * flags at the exact moment this is needed... */
3118 /* let chip do RTS/CTS handshaking before sending
3119 * in case packet size exceeds threshold */
3120 if (ieeectl->flags & IEEE80211_TXCTL_USE_RTS_CTS)
3121 SET_BIT(Ctl2_8, DESC_CTL2_RTS);
3122 else
3123 CLEAR_BIT(Ctl2_8, DESC_CTL2_RTS);
3125 rate_cur = ieeectl->tx_rate;
3126 if (unlikely(!rate_cur)) {
3127 printk("acx: driver bug! bad ratemask\n");
3128 goto end;
3131 /* used in tx cleanup routine for auto rate and accounting: */
3132 /* put_txcr(adev, txdesc, clt, rate_cur); deprecated by mac80211 */
3134 txdesc->total_length = cpu_to_le16(len);
3135 wlhdr_len = ieee80211_get_hdrlen(le16_to_cpu(wireless_header->frame_control));
3136 hostdesc2->length = cpu_to_le16(len - wlhdr_len);
3138 if (!ieeectl->do_not_encrypt && ieeectl->key_idx>= 0)
3140 u16 key_idx = (u16)(ieeectl->key_idx);
3141 struct acx_key* key = &(adev->key[key_idx]);
3142 int wlhdr_len;
3143 if (key->enabled)
3145 memcpy(ieeehdr->wep_iv, ((u8*)wireless_header) + wlhdr_len, 4);
3149 if (IS_ACX111(adev)) {
3150 /* note that if !txdesc->do_auto, txrate->cur
3151 ** has only one nonzero bit */
3152 txdesc->u.r2.rate111 = cpu_to_le16(rate_cur
3153 /* WARNING: I was never able to make it work with prism54 AP.
3154 ** It was falling down to 1Mbit where shortpre is not applicable,
3155 ** and not working at all at "5,11 basic rates only" setting.
3156 ** I even didn't see tx packets in radio packet capture.
3157 ** Disabled for now --vda */
3158 /*| ((clt->shortpre && clt->cur!=RATE111_1) ? RATE111_SHORTPRE : 0) */
3160 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3161 /* should add this to rate111 above as necessary */
3162 |(clt->pbcc511 ? RATE111_PBCC511 : 0)
3163 #endif
3164 hostdesc1->length = cpu_to_le16(len);
3165 } else { /* ACX100 */
3166 u8 rate_100 = ieeectl->tx_rate;
3167 txdesc->u.r1.rate = rate_100;
3168 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3169 if (clt->pbcc511) {
3170 if (n == RATE100_5 || n == RATE100_11)
3171 n |= RATE100_PBCC511;
3174 if (clt->shortpre && (clt->cur != RATE111_1))
3175 SET_BIT(Ctl_8, DESC_CTL_SHORT_PREAMBLE); /* set Short Preamble */
3176 #endif
3177 /* set autodma and reclaim and 1st mpdu */
3178 SET_BIT(Ctl_8,
3179 DESC_CTL_AUTODMA | DESC_CTL_RECLAIM |
3180 DESC_CTL_FIRSTFRAG);
3181 #if ACX_FRAGMENTATION
3182 /* SET_BIT(Ctl2_8, DESC_CTL2_MORE_FRAG); cannot set it unconditionally, needs to be set for all non-last fragments */
3183 #endif
3184 hostdesc1->length = cpu_to_le16(wlhdr_len);
3186 /* don't need to clean ack/rts statistics here, already
3187 * done on descr cleanup */
3189 /* clears HOSTOWN and ACXDONE bits, thus telling that the descriptors
3190 * are now owned by the acx100; do this as LAST operation */
3191 CLEAR_BIT(Ctl_8, DESC_CTL_ACXDONE_HOSTOWN);
3192 /* flush writes before we release hostdesc to the adapter here */
3193 wmb();
3194 CLEAR_BIT(hostdesc1->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3195 CLEAR_BIT(hostdesc2->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3197 /* write back modified flags */
3198 CLEAR_BIT(Ctl2_8, DESC_CTL2_WEP);
3199 txdesc->Ctl2_8 = Ctl2_8;
3200 txdesc->Ctl_8 = Ctl_8;
3201 /* unused: txdesc->tx_time = cpu_to_le32(jiffies); */
3203 /* flush writes before we tell the adapter that it's its turn now */
3204 write_reg16(adev, IO_ACX_INT_TRIG, INT_TRIG_TXPRC);
3205 write_flush(adev);
3206 /* log the packet content AFTER sending it,
3207 * in order to not delay sending any further than absolutely needed
3208 * Do separate logs for acx100/111 to have human-readable rates */
3209 memcpy(&(hostdesc1->txstatus.control),ieeectl,sizeof(struct ieee80211_tx_control));
3210 hostdesc1->skb = skb;
3211 end:
3212 FN_EXIT0;
3216 /***********************************************************************
3217 ** acxpci_l_clean_txdesc
3219 ** This function resets the txdescs' status when the ACX100
3220 ** signals the TX done IRQ (txdescs have been processed), starting with
3221 ** the pool index of the descriptor which we would use next,
3222 ** in order to make sure that we can be as fast as possible
3223 ** in filling new txdescs.
3224 ** Everytime we get called we know where the next packet to be cleaned is.
3227 #if !ACX_DEBUG
3228 static inline void log_txbuffer(const acx_device_t * adev)
3231 #else
3232 static void log_txbuffer(acx_device_t * adev)
3234 txdesc_t *txdesc;
3235 int i;
3237 /* no FN_ENTER here, we don't want that */
3238 /* no locks here, since it's entirely non-critical code */
3239 txdesc = adev->txdesc_start;
3240 if (unlikely(!txdesc))
3241 return;
3242 printk("tx: desc->Ctl8's:");
3243 for (i = 0; i < TX_CNT; i++) {
3244 printk(" %02X", txdesc->Ctl_8);
3245 txdesc = advance_txdesc(adev, txdesc, 1);
3247 printk("\n");
3249 #endif
3252 static void handle_tx_error(acx_device_t * adev, u8 error, unsigned int finger,
3253 struct ieee80211_tx_status *status)
3255 const char *err = "unknown error";
3257 /* hmm, should we handle this as a mask
3258 * of *several* bits?
3259 * For now I think only caring about
3260 * individual bits is ok... */
3261 switch (error) {
3262 case 0x01:
3263 err = "no Tx due to error in other fragment";
3264 /* adev->wstats.discard.fragment++; */
3265 break;
3266 case 0x02:
3267 err = "Tx aborted";
3268 adev->stats.tx_aborted_errors++;
3269 break;
3270 case 0x04:
3271 err = "Tx desc wrong parameters";
3272 /* adev->wstats.discard.misc++; */
3273 break;
3274 case 0x08:
3275 err = "WEP key not found";
3276 /* adev->wstats.discard.misc++; */
3277 break;
3278 case 0x10:
3279 err = "MSDU lifetime timeout? - try changing "
3280 "'iwconfig retry lifetime XXX'";
3281 /* adev->wstats.discard.misc++; */
3282 break;
3283 case 0x20:
3284 err = "excessive Tx retries due to either distance "
3285 "too high or unable to Tx or Tx frame error - "
3286 "try changing 'iwconfig txpower XXX' or "
3287 "'sens'itivity or 'retry'";
3288 /* adev->wstats.discard.retries++; */
3289 /* Tx error 0x20 also seems to occur on
3290 * overheating, so I'm not sure whether we
3291 * actually want to do aggressive radio recalibration,
3292 * since people maybe won't notice then that their hardware
3293 * is slowly getting cooked...
3294 * Or is it still a safe long distance from utter
3295 * radio non-functionality despite many radio recalibs
3296 * to final destructive overheating of the hardware?
3297 * In this case we really should do recalib here...
3298 * I guess the only way to find out is to do a
3299 * potentially fatal self-experiment :-\
3300 * Or maybe only recalib in case we're using Tx
3301 * rate auto (on errors switching to lower speed
3302 * --> less heat?) or 802.11 power save mode?
3304 * ok, just do it. */
3305 if (++adev->retry_errors_msg_ratelimit % 4 == 0) {
3306 if (adev->retry_errors_msg_ratelimit <= 20) {
3307 printk("%s: several excessive Tx "
3308 "retry errors occurred, attempting "
3309 "to recalibrate radio. Radio "
3310 "drift might be caused by increasing "
3311 "card temperature, please check the card "
3312 "before it's too late!\n",
3313 wiphy_name(adev->ieee->wiphy));
3314 if (adev->retry_errors_msg_ratelimit == 20)
3315 printk("disabling above message\n");
3318 acx_schedule_task(adev,
3319 ACX_AFTER_IRQ_CMD_RADIO_RECALIB);
3321 status->excessive_retries++;
3322 break;
3323 case 0x40:
3324 err = "Tx buffer overflow";
3325 adev->stats.tx_fifo_errors++;
3326 break;
3327 case 0x80:
3328 /* possibly ACPI C-state powersaving related!!!
3329 * (DMA timeout due to excessively high wakeup
3330 * latency after C-state activation!?)
3331 * Disable C-State powersaving and try again,
3332 * then PLEASE REPORT, I'm VERY interested in
3333 * whether my theory is correct that this is
3334 * actually the problem here.
3335 * In that case, use new Linux idle wakeup latency
3336 * requirements kernel API to prevent this issue. */
3337 err = "DMA error";
3338 /* adev->wstats.discard.misc++; */
3339 break;
3341 adev->stats.tx_errors++;
3342 if (adev->stats.tx_errors <= 20)
3343 printk("%s: tx error 0x%02X, buf %02u! (%s)\n",
3344 wiphy_name(adev->ieee->wiphy), error, finger, err);
3345 else
3346 printk("%s: tx error 0x%02X, buf %02u!\n",
3347 wiphy_name(adev->ieee->wiphy), error, finger);
3351 unsigned int acxpci_l_clean_txdesc(acx_device_t * adev)
3353 txdesc_t *txdesc;
3354 txhostdesc_t *hostdesc;
3355 unsigned finger;
3356 int num_cleaned;
3357 u16 r111;
3358 u8 error, ack_failures, rts_failures, rts_ok, r100;
3360 FN_ENTER;
3362 if (unlikely(acx_debug & L_DEBUG))
3363 log_txbuffer(adev);
3365 log(L_BUFT, "tx: cleaning up bufs from %u\n", adev->tx_tail);
3367 /* We know first descr which is not free yet. We advance it as far
3368 ** as we see correct bits set in following descs (if next desc
3369 ** is NOT free, we shouldn't advance at all). We know that in
3370 ** front of tx_tail may be "holes" with isolated free descs.
3371 ** We will catch up when all intermediate descs will be freed also */
3373 finger = adev->tx_tail;
3374 num_cleaned = 0;
3375 while (likely(finger != adev->tx_head)) {
3376 txdesc = get_txdesc(adev, finger);
3378 /* If we allocated txdesc on tx path but then decided
3379 ** to NOT use it, then it will be left as a free "bubble"
3380 ** in the "allocated for tx" part of the ring.
3381 ** We may meet it on the next ring pass here. */
3383 /* stop if not marked as "tx finished" and "host owned" */
3384 if ((txdesc->Ctl_8 & DESC_CTL_ACXDONE_HOSTOWN)
3385 != DESC_CTL_ACXDONE_HOSTOWN) {
3386 if (unlikely(!num_cleaned)) { /* maybe remove completely */
3387 log(L_BUFT, "clean_txdesc: tail isn't free. "
3388 "tail:%d head:%d\n",
3389 adev->tx_tail, adev->tx_head);
3391 break;
3394 /* remember desc values... */
3395 error = txdesc->error;
3396 ack_failures = txdesc->ack_failures;
3397 rts_failures = txdesc->rts_failures;
3398 rts_ok = txdesc->rts_ok;
3399 r100 = txdesc->u.r1.rate;
3400 r111 = le16_to_cpu(txdesc->u.r2.rate111);
3402 /* need to check for certain error conditions before we
3403 * clean the descriptor: we still need valid descr data here */
3404 hostdesc = get_txhostdesc(adev, txdesc);
3406 hostdesc->txstatus.flags |= IEEE80211_TX_STATUS_ACK;
3407 if (unlikely(0x30 & error)) {
3408 /* only send IWEVTXDROP in case of retry or lifetime exceeded;
3409 * all other errors mean we screwed up locally */
3410 /* union iwreq_data wrqu;
3411 struct ieee80211_hdr_3addr *hdr;
3412 hdr = (struct ieee80211_hdr_3addr *) hostdesc->data;
3413 MAC_COPY(wrqu.addr.sa_data, hdr->addr1);
3415 hostdesc->txstatus.flags &= ~IEEE80211_TX_STATUS_ACK;
3418 /* ...and free the desc */
3419 txdesc->error = 0;
3420 txdesc->ack_failures = 0;
3421 txdesc->rts_failures = 0;
3422 txdesc->rts_ok = 0;
3423 /* signal host owning it LAST, since ACX already knows that this
3424 ** descriptor is finished since it set Ctl_8 accordingly. */
3425 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3427 adev->tx_free++;
3428 num_cleaned++;
3430 if ((adev->tx_free >= TX_START_QUEUE)
3431 /* && (adev->status == ACX_STATUS_4_ASSOCIATED) */
3432 /*&& (acx_queue_stopped(adev->ieee))*/
3434 log(L_BUF, "tx: wake queue (avail. Tx desc %u)\n",
3435 adev->tx_free);
3436 acx_wake_queue(adev->ieee, NULL);
3439 /* do error checking, rate handling and logging
3440 * AFTER having done the work, it's faster */
3442 /* Rate handling is done in mac80211 */
3443 /* if (adev->rate_auto) {
3444 struct client *clt = get_txc(adev, txdesc);
3445 if (clt) {
3446 u16 cur = get_txr(adev, txdesc);
3447 if (clt->rate_cur == cur) {
3448 acx_l_handle_txrate_auto(adev, clt, cur,*/ /* intended rate */
3449 /*r100, r111,*/ /* actually used rate */
3450 /*(error & 0x30),*/ /* was there an error? */
3451 /* TX_CNT +
3452 TX_CLEAN_BACKLOG
3454 adev->tx_free);
3459 if (unlikely(error))
3460 handle_tx_error(adev, error, finger, &hostdesc->txstatus);
3462 if (IS_ACX111(adev))
3463 log(L_BUFT,
3464 "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u r111=%04X tx_free=%u\n",
3465 finger, ack_failures, rts_failures, rts_ok, r111, adev->tx_free);
3466 else
3467 log(L_BUFT,
3468 "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u rate=%u\n",
3469 finger, ack_failures, rts_failures, rts_ok, r100);
3471 /* And finally report upstream */
3472 if (hostdesc)
3474 hostdesc->txstatus.excessive_retries = rts_failures ;
3475 hostdesc->txstatus.retry_count = ack_failures;
3476 ieee80211_tx_status(adev->ieee,hostdesc->skb,&hostdesc->txstatus);
3477 memset(&hostdesc->txstatus, 0, sizeof(struct ieee80211_tx_status));
3479 /* update pointer for descr to be cleaned next */
3480 finger = (finger + 1) % TX_CNT;
3482 /* remember last position */
3483 adev->tx_tail = finger;
3484 /* end: */
3485 FN_EXIT1(num_cleaned);
3486 return num_cleaned;
3489 /* clean *all* Tx descriptors, and regardless of their previous state.
3490 * Used for brute-force reset handling. */
3491 void acxpci_l_clean_txdesc_emergency(acx_device_t * adev)
3493 txdesc_t *txdesc;
3494 int i;
3496 FN_ENTER;
3498 for (i = 0; i < TX_CNT; i++) {
3499 txdesc = get_txdesc(adev, i);
3501 /* free it */
3502 txdesc->ack_failures = 0;
3503 txdesc->rts_failures = 0;
3504 txdesc->rts_ok = 0;
3505 txdesc->error = 0;
3506 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3509 adev->tx_free = TX_CNT;
3511 FN_EXIT0;
3515 /***********************************************************************
3516 ** acxpci_s_create_tx_host_desc_queue
3519 static void *allocate(acx_device_t * adev, size_t size, dma_addr_t * phy,
3520 const char *msg)
3522 void *ptr;
3524 ptr = dma_alloc_coherent(adev->bus_dev, size, phy, GFP_KERNEL);
3526 if (ptr) {
3527 log(L_DEBUG, "%s sz=%d adr=0x%p phy=0x%08llx\n",
3528 msg, (int)size, ptr, (unsigned long long)*phy);
3529 memset(ptr, 0, size);
3530 return ptr;
3532 printk(KERN_ERR "acx: %s allocation FAILED (%d bytes)\n",
3533 msg, (int)size);
3534 return NULL;
3538 static int acxpci_s_create_tx_host_desc_queue(acx_device_t * adev)
3540 txhostdesc_t *hostdesc;
3541 u8 *txbuf;
3542 dma_addr_t hostdesc_phy;
3543 dma_addr_t txbuf_phy;
3544 int i;
3546 FN_ENTER;
3548 /* allocate TX buffer */
3549 adev->txbuf_area_size = TX_CNT * /*WLAN_A4FR_MAXLEN_WEP_FCS*/ (30 + 2312 + 4);
3550 adev->txbuf_start = allocate(adev, adev->txbuf_area_size,
3551 &adev->txbuf_startphy, "txbuf_start");
3552 if (!adev->txbuf_start)
3553 goto fail;
3555 /* allocate the TX host descriptor queue pool */
3556 adev->txhostdesc_area_size = TX_CNT * 2 * sizeof(*hostdesc);
3557 adev->txhostdesc_start = allocate(adev, adev->txhostdesc_area_size,
3558 &adev->txhostdesc_startphy,
3559 "txhostdesc_start");
3560 if (!adev->txhostdesc_start)
3561 goto fail;
3562 /* check for proper alignment of TX host descriptor pool */
3563 if ((long)adev->txhostdesc_start & 3) {
3564 printk
3565 ("acx: driver bug: dma alloc returns unaligned address\n");
3566 goto fail;
3569 hostdesc = adev->txhostdesc_start;
3570 hostdesc_phy = adev->txhostdesc_startphy;
3571 txbuf = adev->txbuf_start;
3572 txbuf_phy = adev->txbuf_startphy;
3574 #if 0
3575 /* Each tx buffer is accessed by hardware via
3576 ** txdesc -> txhostdesc(s) -> txbuffer(s).
3577 ** We use only one txhostdesc per txdesc, but it looks like
3578 ** acx111 is buggy: it accesses second txhostdesc
3579 ** (via hostdesc.desc_phy_next field) even if
3580 ** txdesc->length == hostdesc->length and thus
3581 ** entire packet was placed into first txhostdesc.
3582 ** Due to this bug acx111 hangs unless second txhostdesc
3583 ** has le16_to_cpu(hostdesc.length) = 3 (or larger)
3584 ** Storing NULL into hostdesc.desc_phy_next
3585 ** doesn't seem to help.
3587 ** Update: although it worked on Xterasys XN-2522g
3588 ** with len=3 trick, WG311v2 is even more bogus, doesn't work.
3589 ** Keeping this code (#ifdef'ed out) for documentational purposes.
3591 for (i = 0; i < TX_CNT * 2; i++) {
3592 hostdesc_phy += sizeof(*hostdesc);
3593 if (!(i & 1)) {
3594 hostdesc->data_phy = cpu2acx(txbuf_phy);
3595 /* hostdesc->data_offset = ... */
3596 /* hostdesc->reserved = ... */
3597 hostdesc->Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
3598 /* hostdesc->length = ... */
3599 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3600 hostdesc->pNext = ptr2acx(NULL);
3601 /* hostdesc->Status = ... */
3602 /* below: non-hardware fields */
3603 hostdesc->data = txbuf;
3605 txbuf += WLAN_A4FR_MAXLEN_WEP_FCS;
3606 txbuf_phy += WLAN_A4FR_MAXLEN_WEP_FCS;
3607 } else {
3608 /* hostdesc->data_phy = ... */
3609 /* hostdesc->data_offset = ... */
3610 /* hostdesc->reserved = ... */
3611 /* hostdesc->Ctl_16 = ... */
3612 hostdesc->length = cpu_to_le16(3); /* bug workaround */
3613 /* hostdesc->desc_phy_next = ... */
3614 /* hostdesc->pNext = ... */
3615 /* hostdesc->Status = ... */
3616 /* below: non-hardware fields */
3617 /* hostdesc->data = ... */
3619 hostdesc++;
3621 #endif
3622 /* We initialize two hostdescs so that they point to adjacent
3623 ** memory areas. Thus txbuf is really just a contiguous memory area */
3624 for (i = 0; i < TX_CNT * 2; i++) {
3625 hostdesc_phy += sizeof(*hostdesc);
3627 hostdesc->data_phy = cpu2acx(txbuf_phy);
3628 /* done by memset(0): hostdesc->data_offset = 0; */
3629 /* hostdesc->reserved = ... */
3630 hostdesc->Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
3631 /* hostdesc->length = ... */
3632 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3633 /* done by memset(0): hostdesc->pNext = ptr2acx(NULL); */
3634 /* hostdesc->Status = ... */
3635 /* ->data is a non-hardware field: */
3636 hostdesc->data = txbuf;
3638 if (!(i & 1)) {
3639 txbuf += 24 /*WLAN_HDR_A3_LEN*/;
3640 txbuf_phy += 24 /*WLAN_HDR_A3_LEN*/;
3641 } else {
3642 txbuf += 30 + 2132 + 4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3643 txbuf_phy += 30 + 2132 +4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3645 hostdesc++;
3647 hostdesc--;
3648 hostdesc->desc_phy_next = cpu2acx(adev->txhostdesc_startphy);
3650 FN_EXIT1(OK);
3651 return OK;
3652 fail:
3653 printk("acx: create_tx_host_desc_queue FAILED\n");
3654 /* dealloc will be done by free function on error case */
3655 FN_EXIT1(NOT_OK);
3656 return NOT_OK;
3660 /***************************************************************
3661 ** acxpci_s_create_rx_host_desc_queue
3663 /* the whole size of a data buffer (header plus data body)
3664 * plus 32 bytes safety offset at the end */
3665 #define RX_BUFFER_SIZE (sizeof(rxbuffer_t) + 32)
3667 static int acxpci_s_create_rx_host_desc_queue(acx_device_t * adev)
3669 rxhostdesc_t *hostdesc;
3670 rxbuffer_t *rxbuf;
3671 dma_addr_t hostdesc_phy;
3672 dma_addr_t rxbuf_phy;
3673 int i;
3675 FN_ENTER;
3677 /* allocate the RX host descriptor queue pool */
3678 adev->rxhostdesc_area_size = RX_CNT * sizeof(*hostdesc);
3679 adev->rxhostdesc_start = allocate(adev, adev->rxhostdesc_area_size,
3680 &adev->rxhostdesc_startphy,
3681 "rxhostdesc_start");
3682 if (!adev->rxhostdesc_start)
3683 goto fail;
3684 /* check for proper alignment of RX host descriptor pool */
3685 if ((long)adev->rxhostdesc_start & 3) {
3686 printk
3687 ("acx: driver bug: dma alloc returns unaligned address\n");
3688 goto fail;
3691 /* allocate Rx buffer pool which will be used by the acx
3692 * to store the whole content of the received frames in it */
3693 adev->rxbuf_area_size = RX_CNT * RX_BUFFER_SIZE;
3694 adev->rxbuf_start = allocate(adev, adev->rxbuf_area_size,
3695 &adev->rxbuf_startphy, "rxbuf_start");
3696 if (!adev->rxbuf_start)
3697 goto fail;
3699 rxbuf = adev->rxbuf_start;
3700 rxbuf_phy = adev->rxbuf_startphy;
3701 hostdesc = adev->rxhostdesc_start;
3702 hostdesc_phy = adev->rxhostdesc_startphy;
3704 /* don't make any popular C programming pointer arithmetic mistakes
3705 * here, otherwise I'll kill you...
3706 * (and don't dare asking me why I'm warning you about that...) */
3707 for (i = 0; i < RX_CNT; i++) {
3708 hostdesc->data = rxbuf;
3709 hostdesc->data_phy = cpu2acx(rxbuf_phy);
3710 hostdesc->length = cpu_to_le16(RX_BUFFER_SIZE);
3711 CLEAR_BIT(hostdesc->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3712 rxbuf++;
3713 rxbuf_phy += sizeof(*rxbuf);
3714 hostdesc_phy += sizeof(*hostdesc);
3715 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3716 hostdesc++;
3718 hostdesc--;
3719 hostdesc->desc_phy_next = cpu2acx(adev->rxhostdesc_startphy);
3720 FN_EXIT1(OK);
3721 return OK;
3722 fail:
3723 printk("acx: create_rx_host_desc_queue FAILED\n");
3724 /* dealloc will be done by free function on error case */
3725 FN_EXIT1(NOT_OK);
3726 return NOT_OK;
3730 /***************************************************************
3731 ** acxpci_s_create_hostdesc_queues
3733 int acxpci_s_create_hostdesc_queues(acx_device_t * adev)
3735 int result;
3736 result = acxpci_s_create_tx_host_desc_queue(adev);
3737 if (OK != result)
3738 return result;
3739 result = acxpci_s_create_rx_host_desc_queue(adev);
3740 return result;
3744 /***************************************************************
3745 ** acxpci_create_tx_desc_queue
3747 static void acxpci_create_tx_desc_queue(acx_device_t * adev, u32 tx_queue_start)
3749 txdesc_t *txdesc;
3750 txhostdesc_t *hostdesc;
3751 dma_addr_t hostmemptr;
3752 u32 mem_offs;
3753 int i;
3755 FN_ENTER;
3757 if (IS_ACX100(adev))
3758 adev->txdesc_size = sizeof(*txdesc);
3759 else
3760 /* the acx111 txdesc is 4 bytes larger */
3761 adev->txdesc_size = sizeof(*txdesc) + 4;
3763 adev->txdesc_start = (txdesc_t *) (adev->iobase2 + tx_queue_start);
3765 log(L_DEBUG, "adev->iobase2=%p\n"
3766 "tx_queue_start=%08X\n"
3767 "adev->txdesc_start=%p\n",
3768 adev->iobase2, tx_queue_start, adev->txdesc_start);
3770 adev->tx_free = TX_CNT;
3771 /* done by memset: adev->tx_head = 0; */
3772 /* done by memset: adev->tx_tail = 0; */
3773 txdesc = adev->txdesc_start;
3774 mem_offs = tx_queue_start;
3775 hostmemptr = adev->txhostdesc_startphy;
3776 hostdesc = adev->txhostdesc_start;
3778 if (IS_ACX111(adev)) {
3779 /* ACX111 has a preinitialized Tx buffer! */
3780 /* loop over whole send pool */
3781 /* FIXME: do we have to do the hostmemptr stuff here?? */
3782 for (i = 0; i < TX_CNT; i++) {
3783 txdesc->HostMemPtr = ptr2acx(hostmemptr);
3784 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3785 /* reserve two (hdr desc and payload desc) */
3786 hostdesc += 2;
3787 hostmemptr += 2 * sizeof(*hostdesc);
3788 txdesc = advance_txdesc(adev, txdesc, 1);
3790 } else {
3791 /* ACX100 Tx buffer needs to be initialized by us */
3792 /* clear whole send pool. sizeof is safe here (we are acx100) */
3793 memset(adev->txdesc_start, 0, TX_CNT * sizeof(*txdesc));
3795 /* loop over whole send pool */
3796 for (i = 0; i < TX_CNT; i++) {
3797 log(L_DEBUG, "configure card tx descriptor: 0x%p, "
3798 "size: 0x%X\n", txdesc, adev->txdesc_size);
3800 /* pointer to hostdesc memory */
3801 txdesc->HostMemPtr = ptr2acx(hostmemptr);
3802 /* initialise ctl */
3803 txdesc->Ctl_8 = (DESC_CTL_HOSTOWN | DESC_CTL_RECLAIM
3804 | DESC_CTL_AUTODMA |
3805 DESC_CTL_FIRSTFRAG);
3806 /* done by memset(0): txdesc->Ctl2_8 = 0; */
3807 /* point to next txdesc */
3808 txdesc->pNextDesc =
3809 cpu2acx(mem_offs + adev->txdesc_size);
3810 /* reserve two (hdr desc and payload desc) */
3811 hostdesc += 2;
3812 hostmemptr += 2 * sizeof(*hostdesc);
3813 /* go to the next one */
3814 mem_offs += adev->txdesc_size;
3815 /* ++ is safe here (we are acx100) */
3816 txdesc++;
3818 /* go back to the last one */
3819 txdesc--;
3820 /* and point to the first making it a ring buffer */
3821 txdesc->pNextDesc = cpu2acx(tx_queue_start);
3823 FN_EXIT0;
3827 /***************************************************************
3828 ** acxpci_create_rx_desc_queue
3830 static void acxpci_create_rx_desc_queue(acx_device_t * adev, u32 rx_queue_start)
3832 rxdesc_t *rxdesc;
3833 u32 mem_offs;
3834 int i;
3836 FN_ENTER;
3838 /* done by memset: adev->rx_tail = 0; */
3840 /* ACX111 doesn't need any further config: preconfigures itself.
3841 * Simply print ring buffer for debugging */
3842 if (IS_ACX111(adev)) {
3843 /* rxdesc_start already set here */
3845 adev->rxdesc_start =
3846 (rxdesc_t *) ((u8 *) adev->iobase2 + rx_queue_start);
3848 rxdesc = adev->rxdesc_start;
3849 for (i = 0; i < RX_CNT; i++) {
3850 log(L_DEBUG, "rx descriptor %d @ 0x%p\n", i, rxdesc);
3851 rxdesc = adev->rxdesc_start = (rxdesc_t *)
3852 (adev->iobase2 + acx2cpu(rxdesc->pNextDesc));
3854 } else {
3855 /* we didn't pre-calculate rxdesc_start in case of ACX100 */
3856 /* rxdesc_start should be right AFTER Tx pool */
3857 adev->rxdesc_start = (rxdesc_t *)
3858 ((u8 *) adev->txdesc_start + (TX_CNT * sizeof(txdesc_t)));
3859 /* NB: sizeof(txdesc_t) above is valid because we know
3860 ** we are in if (acx100) block. Beware of cut-n-pasting elsewhere!
3861 ** acx111's txdesc is larger! */
3863 memset(adev->rxdesc_start, 0, RX_CNT * sizeof(*rxdesc));
3865 /* loop over whole receive pool */
3866 rxdesc = adev->rxdesc_start;
3867 mem_offs = rx_queue_start;
3868 for (i = 0; i < RX_CNT; i++) {
3869 log(L_DEBUG, "rx descriptor @ 0x%p\n", rxdesc);
3870 rxdesc->Ctl_8 = DESC_CTL_RECLAIM | DESC_CTL_AUTODMA;
3871 /* point to next rxdesc */
3872 rxdesc->pNextDesc = cpu2acx(mem_offs + sizeof(*rxdesc));
3873 /* go to the next one */
3874 mem_offs += sizeof(*rxdesc);
3875 rxdesc++;
3877 /* go to the last one */
3878 rxdesc--;
3880 /* and point to the first making it a ring buffer */
3881 rxdesc->pNextDesc = cpu2acx(rx_queue_start);
3883 FN_EXIT0;
3887 /***************************************************************
3888 ** acxpci_create_desc_queues
3890 void
3891 acxpci_create_desc_queues(acx_device_t * adev, u32 tx_queue_start,
3892 u32 rx_queue_start)
3894 acxpci_create_tx_desc_queue(adev, tx_queue_start);
3895 acxpci_create_rx_desc_queue(adev, rx_queue_start);
3899 /***************************************************************
3900 ** acxpci_s_proc_diag_output
3902 char *acxpci_s_proc_diag_output(char *p, acx_device_t * adev)
3904 const char *rtl, *thd, *ttl;
3905 rxhostdesc_t *rxhostdesc;
3906 txdesc_t *txdesc;
3907 int i;
3909 FN_ENTER;
3911 p += sprintf(p, "** Rx buf **\n");
3912 rxhostdesc = adev->rxhostdesc_start;
3913 if (rxhostdesc)
3914 for (i = 0; i < RX_CNT; i++) {
3915 rtl = (i == adev->rx_tail) ? " [tail]" : "";
3916 if ((rxhostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
3917 && (rxhostdesc->
3918 Status & cpu_to_le32(DESC_STATUS_FULL)))
3919 p += sprintf(p, "%02u FULL%s\n", i, rtl);
3920 else
3921 p += sprintf(p, "%02u empty%s\n", i, rtl);
3922 rxhostdesc++;
3924 /* p += sprintf(p, "** Tx buf (free %d, Linux netqueue %s) **\n",
3925 adev->tx_free,
3926 acx_queue_stopped(adev->ieee) ? "STOPPED" : "running");*/
3927 txdesc = adev->txdesc_start;
3928 if (txdesc)
3929 for (i = 0; i < TX_CNT; i++) {
3930 thd = (i == adev->tx_head) ? " [head]" : "";
3931 ttl = (i == adev->tx_tail) ? " [tail]" : "";
3932 if (txdesc->Ctl_8 & DESC_CTL_ACXDONE)
3933 p += sprintf(p, "%02u free (%02X)%s%s\n", i,
3934 txdesc->Ctl_8, thd, ttl);
3935 else
3936 p += sprintf(p, "%02u tx (%02X)%s%s\n", i,
3937 txdesc->Ctl_8, thd, ttl);
3938 txdesc = advance_txdesc(adev, txdesc, 1);
3940 p += sprintf(p,
3941 "\n"
3942 "** PCI data **\n"
3943 "txbuf_start %p, txbuf_area_size %u, txbuf_startphy %08llx\n"
3944 "txdesc_size %u, txdesc_start %p\n"
3945 "txhostdesc_start %p, txhostdesc_area_size %u, txhostdesc_startphy %08llx\n"
3946 "rxdesc_start %p\n"
3947 "rxhostdesc_start %p, rxhostdesc_area_size %u, rxhostdesc_startphy %08llx\n"
3948 "rxbuf_start %p, rxbuf_area_size %u, rxbuf_startphy %08llx\n",
3949 adev->txbuf_start, adev->txbuf_area_size,
3950 (unsigned long long)adev->txbuf_startphy,
3951 adev->txdesc_size, adev->txdesc_start,
3952 adev->txhostdesc_start, adev->txhostdesc_area_size,
3953 (unsigned long long)adev->txhostdesc_startphy,
3954 adev->rxdesc_start,
3955 adev->rxhostdesc_start, adev->rxhostdesc_area_size,
3956 (unsigned long long)adev->rxhostdesc_startphy,
3957 adev->rxbuf_start, adev->rxbuf_area_size,
3958 (unsigned long long)adev->rxbuf_startphy);
3960 FN_EXIT0;
3961 return p;
3965 /***********************************************************************
3967 int acxpci_proc_eeprom_output(char *buf, acx_device_t * adev)
3969 char *p = buf;
3970 int i;
3972 FN_ENTER;
3974 for (i = 0; i < 0x400; i++) {
3975 acxpci_read_eeprom_byte(adev, i, p++);
3978 FN_EXIT1(p - buf);
3979 return p - buf;
3983 /***********************************************************************
3984 ** Obvious
3986 void acxpci_set_interrupt_mask(acx_device_t * adev)
3988 if (IS_ACX111(adev)) {
3989 adev->irq_mask = (u16) ~ (0
3990 /* | HOST_INT_RX_DATA */
3991 | HOST_INT_TX_COMPLETE
3992 /* | HOST_INT_TX_XFER */
3993 | HOST_INT_RX_COMPLETE
3994 /* | HOST_INT_DTIM */
3995 /* | HOST_INT_BEACON */
3996 /* | HOST_INT_TIMER */
3997 /* | HOST_INT_KEY_NOT_FOUND */
3998 | HOST_INT_IV_ICV_FAILURE
3999 | HOST_INT_CMD_COMPLETE
4000 | HOST_INT_INFO
4001 /* | HOST_INT_OVERFLOW */
4002 /* | HOST_INT_PROCESS_ERROR */
4003 | HOST_INT_SCAN_COMPLETE
4004 | HOST_INT_FCS_THRESHOLD
4005 /* | HOST_INT_UNKNOWN */
4007 /* Or else acx100 won't signal cmd completion, right? */
4008 adev->irq_mask_off = (u16) ~ (HOST_INT_CMD_COMPLETE); /* 0xfdff */
4009 } else {
4010 adev->irq_mask = (u16) ~ (0
4011 /* | HOST_INT_RX_DATA */
4012 | HOST_INT_TX_COMPLETE
4013 /* | HOST_INT_TX_XFER */
4014 | HOST_INT_RX_COMPLETE
4015 /* | HOST_INT_DTIM */
4016 /* | HOST_INT_BEACON */
4017 /* | HOST_INT_TIMER */
4018 /* | HOST_INT_KEY_NOT_FOUND */
4019 /* | HOST_INT_IV_ICV_FAILURE */
4020 | HOST_INT_CMD_COMPLETE
4021 | HOST_INT_INFO
4022 /* | HOST_INT_OVERFLOW */
4023 /* | HOST_INT_PROCESS_ERROR */
4024 | HOST_INT_SCAN_COMPLETE
4025 /* | HOST_INT_FCS_THRESHOLD */
4026 /* | HOST_INT_UNKNOWN */
4028 adev->irq_mask_off = (u16) ~ (HOST_INT_UNKNOWN); /* 0x7fff */
4033 /***********************************************************************
4035 int acx100pci_s_set_tx_level(acx_device_t * adev, u8 level_dbm)
4037 /* since it can be assumed that at least the Maxim radio has a
4038 * maximum power output of 20dBm and since it also can be
4039 * assumed that these values drive the DAC responsible for
4040 * setting the linear Tx level, I'd guess that these values
4041 * should be the corresponding linear values for a dBm value,
4042 * in other words: calculate the values from that formula:
4043 * Y [dBm] = 10 * log (X [mW])
4044 * then scale the 0..63 value range onto the 1..100mW range (0..20 dBm)
4045 * and you're done...
4046 * Hopefully that's ok, but you never know if we're actually
4047 * right... (especially since Windows XP doesn't seem to show
4048 * actual Tx dBm values :-P) */
4050 /* NOTE: on Maxim, value 30 IS 30mW, and value 10 IS 10mW - so the
4051 * values are EXACTLY mW!!! Not sure about RFMD and others,
4052 * though... */
4053 static const u8 dbm2val_maxim[21] = {
4054 63, 63, 63, 62,
4055 61, 61, 60, 60,
4056 59, 58, 57, 55,
4057 53, 50, 47, 43,
4058 38, 31, 23, 13,
4061 static const u8 dbm2val_rfmd[21] = {
4062 0, 0, 0, 1,
4063 2, 2, 3, 3,
4064 4, 5, 6, 8,
4065 10, 13, 16, 20,
4066 25, 32, 41, 50,
4069 const u8 *table;
4071 switch (adev->radio_type) {
4072 case RADIO_MAXIM_0D:
4073 table = &dbm2val_maxim[0];
4074 break;
4075 case RADIO_RFMD_11:
4076 case RADIO_RALINK_15:
4077 table = &dbm2val_rfmd[0];
4078 break;
4079 default:
4080 printk("%s: unknown/unsupported radio type, "
4081 "cannot modify tx power level yet!\n", wiphy_name(adev->ieee->wiphy));
4082 return NOT_OK;
4084 printk("%s: changing radio power level to %u dBm (%u)\n",
4085 wiphy_name(adev->ieee->wiphy), level_dbm, table[level_dbm]);
4086 acxpci_s_write_phy_reg(adev, 0x11, table[level_dbm]);
4087 return OK;
4090 #ifdef CONFIG_VLYNQ
4091 struct vlynq_reg_config {
4092 u32 offset;
4093 u32 value;
4096 struct vlynq_known {
4097 u32 chip_id;
4098 char name[32];
4099 struct vlynq_mapping rx_mapping[4];
4100 int irq;
4101 int irq_type;
4102 int num_regs;
4103 struct vlynq_reg_config regs[10];
4106 #define CHIP_TNETW1130 0x00000009
4107 #define CHIP_TNETW1350 0x00000029
4109 static struct vlynq_known known_devices[] = {
4111 .chip_id = CHIP_TNETW1130, .name = "TI TNETW1130",
4112 .rx_mapping = {
4113 { .size = 0x22000, .offset = 0xf0000000 },
4114 { .size = 0x40000, .offset = 0xc0000000 },
4115 { .size = 0x0, .offset = 0x0 },
4116 { .size = 0x0, .offset = 0x0 },
4118 .irq = 0,
4119 .irq_type = IRQ_TYPE_EDGE_RISING,
4120 .num_regs = 5,
4121 .regs = {
4123 .offset = 0x790,
4124 .value = (0xd0000000 - PHYS_OFFSET)
4127 .offset = 0x794,
4128 .value = (0xd0000000 - PHYS_OFFSET)
4130 { .offset = 0x740, .value = 0 },
4131 { .offset = 0x744, .value = 0x00010000 },
4132 { .offset = 0x764, .value = 0x00010000 },
4136 .chip_id = CHIP_TNETW1350, .name = "TI TNETW1350",
4137 .rx_mapping = {
4138 { .size = 0x100000, .offset = 0x00300000 },
4139 { .size = 0x80000, .offset = 0x00000000 },
4140 { .size = 0x0, .offset = 0x0 },
4141 { .size = 0x0, .offset = 0x0 },
4143 .irq = 0,
4144 .irq_type = IRQ_TYPE_EDGE_RISING,
4145 .num_regs = 5,
4146 .regs = {
4148 .offset = 0x790,
4149 .value = (0x60000000 - PHYS_OFFSET)
4152 .offset = 0x794,
4153 .value = (0x60000000 - PHYS_OFFSET)
4155 { .offset = 0x740, .value = 0 },
4156 { .offset = 0x744, .value = 0x00010000 },
4157 { .offset = 0x764, .value = 0x00010000 },
4162 static struct vlynq_device_id acx_vlynq_id[] = {
4163 { CHIP_TNETW1130, vlynq_div_auto, 0 },
4164 { CHIP_TNETW1350, vlynq_div_auto, 1 },
4165 { 0, 0, 0 },
4168 static __devinit int vlynq_probe(struct vlynq_device *vdev,
4169 struct vlynq_device_id *id)
4171 int result = -EIO, i;
4172 u32 addr;
4173 struct ieee80211_hw *ieee;
4174 acx_device_t *adev = NULL;
4175 acx111_ie_configoption_t co;
4176 struct vlynq_mapping mapping[4] = { { 0, }, };
4177 struct vlynq_known *match = NULL;
4179 FN_ENTER;
4180 result = vlynq_enable_device(vdev);
4181 if (result)
4182 return result;
4184 match = &known_devices[id->driver_data];
4186 if (!match) {
4187 result = -ENODEV;
4188 goto fail;
4191 mapping[0].offset = ARCH_PFN_OFFSET << PAGE_SHIFT;
4192 mapping[0].size = 0x02000000;
4193 vlynq_set_local_mapping(vdev, vdev->mem_start, mapping);
4194 vlynq_set_remote_mapping(vdev, 0, match->rx_mapping);
4196 set_irq_type(vlynq_virq_to_irq(vdev, match->irq), match->irq_type);
4198 addr = (u32)ioremap(vdev->mem_start, 0x1000);
4199 if (!addr) {
4200 printk(KERN_ERR "%s: failed to remap io memory\n",
4201 vdev->dev.bus_id);
4202 result = -ENXIO;
4203 goto fail;
4206 for (i = 0; i < match->num_regs; i++)
4207 iowrite32(match->regs[i].value,
4208 (u32 *)(addr + match->regs[i].offset));
4210 iounmap((void *)addr);
4212 ieee = ieee80211_alloc_hw(sizeof(struct acx_device), &acxpci_hw_ops);
4213 if (!ieee) {
4214 printk("acx: could not allocate ieee80211 structure %s\n",
4215 vdev->dev.bus_id);
4216 goto fail_alloc_netdev;
4218 ieee->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
4219 ieee->queues = 1;
4221 adev = ieee2adev(ieee);
4223 memset(adev, 0, sizeof(*adev));
4224 /** Set up our private interface **/
4225 spin_lock_init(&adev->lock); /* initial state: unlocked */
4226 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
4227 mutex_init(&adev->mutex);
4228 /* since nobody can see new netdev yet, we can as well
4229 ** just _presume_ that we're under sem (instead of actually taking it): */
4230 /* acx_sem_lock(adev); */
4231 adev->ieee = ieee;
4232 adev->vdev = vdev;
4233 adev->bus_dev = &vdev->dev;
4234 adev->dev_type = DEVTYPE_PCI;
4236 /** Finished with private interface **/
4238 vlynq_set_drvdata(vdev, ieee);
4239 if (!request_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start, "acx")) {
4240 printk("acx: cannot reserve VLYNQ memory region\n");
4241 goto fail_request_mem_region;
4243 adev->iobase = ioremap(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4244 if (!adev->iobase) {
4245 printk("acx: ioremap() FAILED\n");
4246 goto fail_ioremap;
4248 adev->iobase2 = adev->iobase + match->rx_mapping[0].size;
4249 adev->chip_type = CHIPTYPE_ACX111;
4250 adev->chip_name = match->name;
4251 adev->io = IO_ACX111;
4252 adev->irq = vlynq_virq_to_irq(vdev, match->irq);
4254 printk("acx: found %s-based wireless network card at %s, irq:%d, "
4255 "phymem:0x%x, mem:0x%p\n",
4256 match->name, vdev->dev.bus_id, adev->irq,
4257 vdev->mem_start, adev->iobase);
4258 log(L_ANY, "initial debug setting is 0x%04X\n", acx_debug);
4260 if (0 == adev->irq) {
4261 printk("acx: can't use IRQ 0\n");
4262 goto fail_irq;
4264 SET_IEEE80211_DEV(ieee, &vdev->dev);
4267 /* to find crashes due to weird driver access
4268 * to unconfigured interface (ifup) */
4269 adev->mgmt_timer.function = (void (*)(unsigned long))0x0000dead;
4272 /* ok, pci setup is finished, now start initializing the card */
4274 /* NB: read_reg() reads may return bogus data before reset_dev(),
4275 * since the firmware which directly controls large parts of the I/O
4276 * registers isn't initialized yet.
4277 * acx100 seems to be more affected than acx111 */
4278 if (OK != acxpci_s_reset_dev(adev))
4279 goto fail_reset;
4281 if (OK != acx_s_init_mac(adev))
4282 goto fail_init_mac;
4284 acx_s_interrogate(adev, &co, ACX111_IE_CONFIG_OPTIONS);
4285 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
4286 if (OK != acxpci_read_eeprom_byte(adev, 0x05, &adev->eeprom_version))
4287 goto fail_read_eeprom_version;
4289 acx_s_parse_configoption(adev, &co);
4290 acx_s_set_defaults(adev);
4291 acx_s_get_firmware_version(adev); /* needs to be after acx_s_init_mac() */
4292 acx_display_hardware_details(adev);
4294 /* Register the card, AFTER everything else has been set up,
4295 * since otherwise an ioctl could step on our feet due to
4296 * firmware operations happening in parallel or uninitialized data */
4299 acx_proc_register_entries(ieee);
4301 /* Now we have our device, so make sure the kernel doesn't try
4302 * to send packets even though we're not associated to a network yet */
4304 /* after register_netdev() userspace may start working with dev
4305 * (in particular, on other CPUs), we only need to up the sem */
4306 /* acx_sem_unlock(adev); */
4308 printk("acx " ACX_RELEASE ": net device %s, driver compiled "
4309 "against wireless extensions %d and Linux %s\n",
4310 wiphy_name(adev->ieee->wiphy), WIRELESS_EXT, UTS_RELEASE);
4312 MAC_COPY(adev->ieee->wiphy->perm_addr, adev->dev_addr);
4314 log(L_IRQ | L_INIT, "using IRQ %d\n", adev->irq);
4316 /** done with board specific setup **/
4318 acx_init_task_scheduler(adev);
4319 result = ieee80211_register_hw(adev->ieee);
4320 if (OK != result) {
4321 printk("acx: ieee80211_register_hw() FAILED: %d\n", result);
4322 goto fail_register_netdev;
4324 #if CMD_DISCOVERY
4325 great_inquisitor(adev);
4326 #endif
4328 result = OK;
4329 goto done;
4331 /* error paths: undo everything in reverse order... */
4334 acxpci_s_delete_dma_regions(adev);
4336 fail_init_mac:
4337 fail_read_eeprom_version:
4338 fail_reset:
4340 fail_alloc_netdev:
4341 fail_irq:
4343 iounmap(adev->iobase);
4344 fail_ioremap:
4346 release_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4347 fail_request_mem_region:
4348 fail_register_netdev:
4349 ieee80211_free_hw(ieee);
4350 fail:
4351 vlynq_disable_device(vdev);
4352 done:
4353 FN_EXIT1(result);
4354 return result;
4357 static void vlynq_remove(struct vlynq_device *vdev)
4359 struct ieee80211_hw *hw = vlynq_get_drvdata(vdev);
4360 acx_device_t *adev = ieee2adev(hw);
4361 unsigned long flags;
4362 FN_ENTER;
4364 if (!hw) {
4365 log(L_DEBUG, "%s: card is unused. Skipping any release code\n",
4366 __func__);
4367 goto end;
4371 acx_lock(adev, flags);
4372 acx_unlock(adev, flags);
4373 adev->initialized = 0;
4375 /* If device wasn't hot unplugged... */
4376 if (adev_present(adev)) {
4378 acx_sem_lock(adev);
4380 /* disable both Tx and Rx to shut radio down properly */
4381 if (adev->initialized) {
4382 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_TX, NULL, 0);
4383 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_RX, NULL, 0);
4385 acx_lock(adev, flags);
4386 /* disable power LED to save power :-) */
4387 log(L_INIT, "switching off power LED to save power\n");
4388 acxpci_l_power_led(adev, 0);
4389 /* stop our eCPU */
4390 acx_unlock(adev, flags);
4392 acx_sem_unlock(adev);
4395 /* unregister the device to not let the kernel
4396 * (e.g. ioctls) access a half-deconfigured device
4397 * NB: this will cause acxpci_e_close() to be called,
4398 * thus we shouldn't call it under sem!
4399 * Well, netdev did, but ieee80211 stack does not, so we
4400 * have to do so manually...
4402 acxpci_e_close(hw);
4403 log(L_INIT, "removing device %s\n", wiphy_name(adev->ieee->wiphy));
4404 ieee80211_unregister_hw(adev->ieee);
4406 /* unregister_netdev ensures that no references to us left.
4407 * For paranoid reasons we continue to follow the rules */
4408 acx_sem_lock(adev);
4410 if (adev->dev_state_mask & ACX_STATE_IFACE_UP) {
4411 acxpci_s_down(hw);
4412 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
4415 acx_proc_unregister_entries(adev->ieee);
4417 /* finally, clean up PCI bus state */
4418 acxpci_s_delete_dma_regions(adev);
4419 if (adev->iobase)
4420 iounmap(adev->iobase);
4421 if (adev->iobase2)
4422 iounmap(adev->iobase2);
4423 release_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4425 /* remove dev registration */
4427 acx_sem_unlock(adev);
4428 vlynq_disable_device(vdev);
4430 /* Free netdev (quite late,
4431 * since otherwise we might get caught off-guard
4432 * by a netdev timeout handler execution
4433 * expecting to see a working dev...) */
4434 ieee80211_free_hw(adev->ieee);
4436 end:
4437 FN_EXIT0;
4440 static struct vlynq_driver vlynq_acx = {
4441 .name = "acx_vlynq",
4442 .id_table = acx_vlynq_id,
4443 .probe = vlynq_probe,
4444 .remove = __devexit_p(vlynq_remove),
4446 #endif /* CONFIG_VLYNQ */
4449 /***********************************************************************
4450 ** Data for init_module/cleanup_module
4452 #ifdef CONFIG_PCI
4453 static const struct pci_device_id acxpci_id_tbl[] __devinitdata = {
4455 .vendor = PCI_VENDOR_ID_TI,
4456 .device = PCI_DEVICE_ID_TI_TNETW1100A,
4457 .subvendor = PCI_ANY_ID,
4458 .subdevice = PCI_ANY_ID,
4459 .driver_data = CHIPTYPE_ACX100,
4462 .vendor = PCI_VENDOR_ID_TI,
4463 .device = PCI_DEVICE_ID_TI_TNETW1100B,
4464 .subvendor = PCI_ANY_ID,
4465 .subdevice = PCI_ANY_ID,
4466 .driver_data = CHIPTYPE_ACX100,
4469 .vendor = PCI_VENDOR_ID_TI,
4470 .device = PCI_DEVICE_ID_TI_TNETW1130,
4471 .subvendor = PCI_ANY_ID,
4472 .subdevice = PCI_ANY_ID,
4473 .driver_data = CHIPTYPE_ACX111,
4476 .vendor = 0,
4477 .device = 0,
4478 .subvendor = 0,
4479 .subdevice = 0,
4480 .driver_data = 0,
4484 MODULE_DEVICE_TABLE(pci, acxpci_id_tbl);
4486 /* FIXME: checks should be removed once driver is included in the kernel */
4487 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 11)
4488 /* pci_name() got introduced at start of 2.6.x,
4489 * got mandatory (slot_name member removed) in 2.6.11-bk1 */
4490 #define pci_name(x) x->slot_name
4491 #endif
4493 static struct pci_driver
4494 acxpci_drv_id = {
4495 .name = "acx_pci",
4496 .id_table = acxpci_id_tbl,
4497 .probe = acxpci_e_probe,
4498 .remove = __devexit_p(acxpci_e_remove),
4499 #ifdef CONFIG_PM
4500 .suspend = acxpci_e_suspend,
4501 .resume = acxpci_e_resume
4502 #endif /* CONFIG_PM */
4504 #endif /* CONFIG_PCI */
4506 /***********************************************************************
4507 ** acxpci_e_init_module
4509 ** Module initialization routine, called once at module load time
4511 int __init acxpci_e_init_module(void)
4513 int res;
4515 FN_ENTER;
4517 #if (ACX_IO_WIDTH==32)
4518 printk("acx: compiled to use 32bit I/O access. "
4519 "I/O timing issues might occur, such as "
4520 "non-working firmware upload. Report them\n");
4521 #else
4522 printk("acx: compiled to use 16bit I/O access only "
4523 "(compatibility mode)\n");
4524 #endif
4526 #ifdef __LITTLE_ENDIAN
4527 #define ENDIANNESS_STRING "running on a little-endian CPU\n"
4528 #else
4529 #define ENDIANNESS_STRING "running on a BIG-ENDIAN CPU\n"
4530 #endif
4531 log(L_INIT,
4532 "acx: " ENDIANNESS_STRING
4533 "acx: PCI/VLYNQ module " ACX_RELEASE " initialized, "
4534 "waiting for cards to probe...\n");
4536 #ifdef CONFIG_PCI
4537 res = pci_register_driver(&acxpci_drv_id);
4538 #endif
4539 #ifdef CONFIG_VLYNQ
4540 res = vlynq_register_driver(&vlynq_acx);
4541 #endif
4542 FN_EXIT1(res);
4543 return res;
4547 /***********************************************************************
4548 ** acxpci_e_cleanup_module
4550 ** Called at module unload time. This is our last chance to
4551 ** clean up after ourselves.
4553 void __exit acxpci_e_cleanup_module(void)
4555 FN_ENTER;
4557 #ifdef CONFIG_PCI
4558 pci_unregister_driver(&acxpci_drv_id);
4559 #endif
4560 #ifdef CONFIG_VLYNQ
4561 vlynq_unregister_driver(&vlynq_acx);
4562 #endif
4563 log(L_INIT,
4564 "acx: PCI module " ACX_RELEASE " unloaded\n");
4565 FN_EXIT0;