UNSTABLE/very experimental!
[acx-mac80211.git] / pci.c
blobfe2459b230b0c3b01d922e4692511ef15f76874c
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");
2434 static void update_link_quality_led(acx_device_t * adev)
2436 /* int qual; */
2438 /* qual =
2439 acx_signal_determine_quality(adev->wstats.qual.level,
2440 adev->wstats.qual.noise);
2441 if (qual > adev->brange_max_quality)
2442 qual = adev->brange_max_quality;
2445 /* if (time_after(jiffies, adev->brange_time_last_state_change +
2446 (HZ / 2 -
2447 HZ / 2 * (unsigned long)qual /
2448 adev->brange_max_quality))) {
2449 acxpci_l_power_led(adev, (adev->brange_last_state == 0));
2450 adev->brange_last_state ^= 1; *//* toggle */
2451 /* adev->brange_time_last_state_change = jiffies;
2456 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* a la orinoco.c */
2458 /* Interrupt handler bottom-half */
2459 void acx_interrupt_tasklet(struct work_struct *work)
2462 #ifdef CONFIG_ACX_MAC80211_DEBUG
2463 u32 _handled = 0x00000000;
2464 # define acxirq_handled(irq) do { _handled |= (irq); } while (0)
2465 #else
2466 # define acxirq_handled(irq) do { /* nothing */ } while (0)
2467 #endif /* CONFIG_ACX_MAC80211_DEBUG */
2468 acx_device_t *adev = container_of(work,struct acx_device, after_interrupt_task);
2469 // unsigned int irqcount = MAX_IRQLOOPS_PER_JIFFY;
2470 int irqtype;
2472 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2473 * I am paranoid */
2474 acx_sem_lock(adev);
2477 FN_ENTER;
2478 irqtype = adev->irq_reason;
2479 adev->irq_reason = 0;
2481 #define IRQ_ITERATE 0
2482 #if IRQ_ITERATE
2483 if (jiffies != adev->irq_last_jiffies) {
2484 adev->irq_loops_this_jiffy = 0;
2485 adev->irq_last_jiffies = jiffies;
2488 /* safety condition; we'll normally abort loop below
2489 * in case no IRQ type occurred */
2490 while (likely(--irqcount)) {
2491 #endif
2492 /* ACK all IRQs ASAP */
2495 /* Handle most important IRQ types first */
2496 if (irqtype & HOST_INT_RX_COMPLETE) {
2497 log(L_IRQ, "got Rx_Complete IRQ\n");
2498 acxpci_l_process_rxdesc(adev);
2500 if (irqtype & HOST_INT_TX_COMPLETE) {
2501 log(L_IRQ, "got Tx_Complete IRQ\n");
2502 /* don't clean up on each Tx complete, wait a bit
2503 * unless we're going towards full, in which case
2504 * we do it immediately, too (otherwise we might lockup
2505 * with a full Tx buffer if we go into
2506 * acxpci_l_clean_txdesc() at a time when we won't wakeup
2507 * the net queue in there for some reason...) */
2508 // if (adev->tx_free <= TX_START_CLEAN) {
2509 acxpci_l_clean_txdesc(adev);
2510 // }
2513 /* Less frequent ones */
2514 if (irqtype & (0
2515 | HOST_INT_CMD_COMPLETE
2516 | HOST_INT_INFO | HOST_INT_SCAN_COMPLETE)) {
2517 if (irqtype & HOST_INT_INFO) {
2518 handle_info_irq(adev);
2520 if (irqtype & HOST_INT_SCAN_COMPLETE) {
2521 log(L_IRQ, "got Scan_Complete IRQ\n");
2522 /* need to do that in process context */
2523 /* remember that fw is not scanning anymore */
2524 SET_BIT(adev->irq_status,
2525 HOST_INT_SCAN_COMPLETE);
2529 /* These we just log, but either they happen rarely
2530 * or we keep them masked out */
2531 if (irqtype & (0 | HOST_INT_RX_DATA
2532 /* | HOST_INT_TX_COMPLETE */
2533 | HOST_INT_TX_XFER
2534 /* | HOST_INT_RX_COMPLETE */
2535 | HOST_INT_DTIM
2536 | HOST_INT_BEACON
2537 | HOST_INT_TIMER
2538 | HOST_INT_KEY_NOT_FOUND
2539 | HOST_INT_IV_ICV_FAILURE
2540 /* | HOST_INT_CMD_COMPLETE */
2541 /* | HOST_INT_INFO */
2542 | HOST_INT_OVERFLOW | HOST_INT_PROCESS_ERROR
2543 /* | HOST_INT_SCAN_COMPLETE */
2544 | HOST_INT_FCS_THRESHOLD | HOST_INT_UNKNOWN)) {
2545 log_unusual_irq(irqtype);
2547 #if IRQ_ITERATE
2548 unmasked = read_reg16(adev, IO_ACX_IRQ_STATUS_CLEAR);
2549 irqtype = unmasked & ~adev->irq_mask;
2550 /* Bail out if no new IRQ bits or if all are masked out */
2551 if (!irqtype)
2552 break;
2554 if (unlikely
2555 (++adev->irq_loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY)) {
2556 printk(KERN_ERR
2557 "acx: too many interrupts per jiffy!\n");
2558 /* Looks like card floods us with IRQs! Try to stop that */
2559 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
2560 /* This will short-circuit all future attempts to handle IRQ.
2561 * We cant do much more... */
2562 adev->irq_mask = 0;
2563 break;
2566 #endif
2567 /* Routine to perform blink with range */
2568 if (unlikely(adev->led_power == 2))
2569 update_link_quality_led(adev);
2571 /* handled: */
2572 if (adev->after_interrupt_jobs)
2573 acx_e_after_interrupt_task(&adev->after_interrupt_task);
2575 /* write_flush(adev); - not needed, last op was read anyway */
2576 acx_sem_unlock(adev);
2577 FN_EXIT0;
2578 return;
2583 static irqreturn_t
2584 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
2585 acxpci_i_interrupt(int irq, void *dev_id)
2586 #else
2587 acxpci_i_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2588 #endif
2590 acx_device_t *adev = dev_id;
2591 unsigned long flags;
2592 register u16 irqtype;
2593 u16 unmasked;
2595 FN_ENTER;
2597 if (!adev)
2598 return IRQ_NONE;
2600 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2601 * I am paranoid */
2603 acx_lock(adev, flags);
2605 unmasked = read_reg16(adev, IO_ACX_IRQ_STATUS_CLEAR);
2606 if (unlikely(0xffff == unmasked)) {
2607 /* 0xffff value hints at missing hardware,
2608 * so don't do anything.
2609 * Not very clean, but other drivers do the same... */
2610 log(L_IRQ, "IRQ type:FFFF - device removed? IRQ_NONE\n");
2611 goto none;
2614 /* We will check only "interesting" IRQ types */
2615 irqtype = unmasked & ~adev->irq_mask;
2616 if (!irqtype) {
2617 /* We are on a shared IRQ line and it wasn't our IRQ */
2618 log(L_IRQ,
2619 "IRQ type:%04X, mask:%04X - all are masked, IRQ_NONE\n",
2620 unmasked, adev->irq_mask);
2621 goto none;
2624 /* Go ahead and ACK our interrupt */
2625 write_reg16(adev, IO_ACX_IRQ_ACK, 0xffff);
2626 if (irqtype & HOST_INT_CMD_COMPLETE) {
2627 log(L_IRQ, "got Command_Complete IRQ\n");
2628 /* save the state for the running issue_cmd() */
2629 SET_BIT(adev->irq_status, HOST_INT_CMD_COMPLETE);
2632 /* Only accept IRQs, if we are initialized properly.
2633 * This avoids an RX race while initializing.
2634 * We should probably not enable IRQs before we are initialized
2635 * completely, but some careful work is needed to fix this. I think it
2636 * is best to stay with this cheap workaround for now... .
2638 if (likely(adev->initialized)) {
2639 /* disable all IRQs. They are enabled again in the bottom half. */
2640 /* save the reason code and call our bottom half. */
2641 adev->irq_reason = irqtype;
2643 if ((irqtype & HOST_INT_RX_COMPLETE) || (irqtype & HOST_INT_TX_COMPLETE))
2644 acx_schedule_task(adev, 0);
2647 acx_unlock(adev, flags);
2648 FN_EXIT0;
2649 return IRQ_HANDLED;
2650 none:
2651 acx_unlock(adev, flags);
2652 FN_EXIT0;
2653 return IRQ_NONE;
2658 /***********************************************************************
2659 ** acxpci_l_power_led
2661 void acxpci_l_power_led(acx_device_t * adev, int enable)
2663 u16 gpio_pled = IS_ACX111(adev) ? 0x0040 : 0x0800;
2665 /* A hack. Not moving message rate limiting to adev->xxx
2666 * (it's only a debug message after all) */
2667 static int rate_limit = 0;
2669 if (rate_limit++ < 3)
2670 log(L_IOCTL, "Please report in case toggling the power "
2671 "LED doesn't work for your card!\n");
2672 if (enable)
2673 write_reg16(adev, IO_ACX_GPIO_OUT,
2674 read_reg16(adev, IO_ACX_GPIO_OUT) & ~gpio_pled);
2675 else
2676 write_reg16(adev, IO_ACX_GPIO_OUT,
2677 read_reg16(adev, IO_ACX_GPIO_OUT) | gpio_pled);
2681 /***********************************************************************
2682 ** Ioctls
2685 /***********************************************************************
2687 #if 0
2689 acx111pci_ioctl_info(struct net_device *ndev,
2690 struct iw_request_info *info,
2691 struct iw_param *vwrq, char *extra)
2693 #if ACX_DEBUG > 1
2694 acx_device_t *adev = ndev2adev(ndev);
2695 rxdesc_t *rxdesc;
2696 txdesc_t *txdesc;
2697 rxhostdesc_t *rxhostdesc;
2698 txhostdesc_t *txhostdesc;
2699 struct acx111_ie_memoryconfig memconf;
2700 struct acx111_ie_queueconfig queueconf;
2701 unsigned long flags;
2702 int i;
2703 char memmap[0x34];
2704 char rxconfig[0x8];
2705 char fcserror[0x8];
2706 char ratefallback[0x5];
2708 if (!(acx_debug & (L_IOCTL | L_DEBUG)))
2709 return OK;
2710 /* using printk() since we checked debug flag already */
2712 acx_sem_lock(adev);
2714 if (!IS_ACX111(adev)) {
2715 printk("acx111-specific function called "
2716 "with non-acx111 chip, aborting\n");
2717 goto end_ok;
2720 /* get Acx111 Memory Configuration */
2721 memset(&memconf, 0, sizeof(memconf));
2722 /* BTW, fails with 12 (Write only) error code.
2723 ** Retained for easy testing of issue_cmd error handling :) */
2724 acx_s_interrogate(adev, &memconf, ACX1xx_IE_QUEUE_CONFIG);
2726 /* get Acx111 Queue Configuration */
2727 memset(&queueconf, 0, sizeof(queueconf));
2728 acx_s_interrogate(adev, &queueconf, ACX1xx_IE_MEMORY_CONFIG_OPTIONS);
2730 /* get Acx111 Memory Map */
2731 memset(memmap, 0, sizeof(memmap));
2732 acx_s_interrogate(adev, &memmap, ACX1xx_IE_MEMORY_MAP);
2734 /* get Acx111 Rx Config */
2735 memset(rxconfig, 0, sizeof(rxconfig));
2736 acx_s_interrogate(adev, &rxconfig, ACX1xx_IE_RXCONFIG);
2738 /* get Acx111 fcs error count */
2739 memset(fcserror, 0, sizeof(fcserror));
2740 acx_s_interrogate(adev, &fcserror, ACX1xx_IE_FCS_ERROR_COUNT);
2742 /* get Acx111 rate fallback */
2743 memset(ratefallback, 0, sizeof(ratefallback));
2744 acx_s_interrogate(adev, &ratefallback, ACX1xx_IE_RATE_FALLBACK);
2746 /* force occurrence of a beacon interrupt */
2747 /* TODO: comment why is this necessary */
2748 write_reg16(adev, IO_ACX_HINT_TRIG, HOST_INT_BEACON);
2750 /* dump Acx111 Mem Configuration */
2751 printk("dump mem config:\n"
2752 "data read: %d, struct size: %d\n"
2753 "Number of stations: %1X\n"
2754 "Memory block size: %1X\n"
2755 "tx/rx memory block allocation: %1X\n"
2756 "count rx: %X / tx: %X queues\n"
2757 "options %1X\n"
2758 "fragmentation %1X\n"
2759 "Rx Queue 1 Count Descriptors: %X\n"
2760 "Rx Queue 1 Host Memory Start: %X\n"
2761 "Tx Queue 1 Count Descriptors: %X\n"
2762 "Tx Queue 1 Attributes: %X\n",
2763 memconf.len, (int)sizeof(memconf),
2764 memconf.no_of_stations,
2765 memconf.memory_block_size,
2766 memconf.tx_rx_memory_block_allocation,
2767 memconf.count_rx_queues, memconf.count_tx_queues,
2768 memconf.options,
2769 memconf.fragmentation,
2770 memconf.rx_queue1_count_descs,
2771 acx2cpu(memconf.rx_queue1_host_rx_start),
2772 memconf.tx_queue1_count_descs, memconf.tx_queue1_attributes);
2774 /* dump Acx111 Queue Configuration */
2775 printk("dump queue head:\n"
2776 "data read: %d, struct size: %d\n"
2777 "tx_memory_block_address (from card): %X\n"
2778 "rx_memory_block_address (from card): %X\n"
2779 "rx1_queue address (from card): %X\n"
2780 "tx1_queue address (from card): %X\n"
2781 "tx1_queue attributes (from card): %X\n",
2782 queueconf.len, (int)sizeof(queueconf),
2783 queueconf.tx_memory_block_address,
2784 queueconf.rx_memory_block_address,
2785 queueconf.rx1_queue_address,
2786 queueconf.tx1_queue_address, queueconf.tx1_attributes);
2788 /* dump Acx111 Mem Map */
2789 printk("dump mem map:\n"
2790 "data read: %d, struct size: %d\n"
2791 "Code start: %X\n"
2792 "Code end: %X\n"
2793 "WEP default key start: %X\n"
2794 "WEP default key end: %X\n"
2795 "STA table start: %X\n"
2796 "STA table end: %X\n"
2797 "Packet template start: %X\n"
2798 "Packet template end: %X\n"
2799 "Queue memory start: %X\n"
2800 "Queue memory end: %X\n"
2801 "Packet memory pool start: %X\n"
2802 "Packet memory pool end: %X\n"
2803 "iobase: %p\n"
2804 "iobase2: %p\n",
2805 *((u16 *) & memmap[0x02]), (int)sizeof(memmap),
2806 *((u32 *) & memmap[0x04]),
2807 *((u32 *) & memmap[0x08]),
2808 *((u32 *) & memmap[0x0C]),
2809 *((u32 *) & memmap[0x10]),
2810 *((u32 *) & memmap[0x14]),
2811 *((u32 *) & memmap[0x18]),
2812 *((u32 *) & memmap[0x1C]),
2813 *((u32 *) & memmap[0x20]),
2814 *((u32 *) & memmap[0x24]),
2815 *((u32 *) & memmap[0x28]),
2816 *((u32 *) & memmap[0x2C]),
2817 *((u32 *) & memmap[0x30]), adev->iobase, adev->iobase2);
2819 /* dump Acx111 Rx Config */
2820 printk("dump rx config:\n"
2821 "data read: %d, struct size: %d\n"
2822 "rx config: %X\n"
2823 "rx filter config: %X\n",
2824 *((u16 *) & rxconfig[0x02]), (int)sizeof(rxconfig),
2825 *((u16 *) & rxconfig[0x04]), *((u16 *) & rxconfig[0x06]));
2827 /* dump Acx111 fcs error */
2828 printk("dump fcserror:\n"
2829 "data read: %d, struct size: %d\n"
2830 "fcserrors: %X\n",
2831 *((u16 *) & fcserror[0x02]), (int)sizeof(fcserror),
2832 *((u32 *) & fcserror[0x04]));
2834 /* dump Acx111 rate fallback */
2835 printk("dump rate fallback:\n"
2836 "data read: %d, struct size: %d\n"
2837 "ratefallback: %X\n",
2838 *((u16 *) & ratefallback[0x02]), (int)sizeof(ratefallback),
2839 *((u8 *) & ratefallback[0x04]));
2841 /* protect against IRQ */
2842 acx_lock(adev, flags);
2844 /* dump acx111 internal rx descriptor ring buffer */
2845 rxdesc = adev->rxdesc_start;
2847 /* loop over complete receive pool */
2848 if (rxdesc)
2849 for (i = 0; i < RX_CNT; i++) {
2850 printk("\ndump internal rxdesc %d:\n"
2851 "mem pos %p\n"
2852 "next 0x%X\n"
2853 "acx mem pointer (dynamic) 0x%X\n"
2854 "CTL (dynamic) 0x%X\n"
2855 "Rate (dynamic) 0x%X\n"
2856 "RxStatus (dynamic) 0x%X\n"
2857 "Mod/Pre (dynamic) 0x%X\n",
2859 rxdesc,
2860 acx2cpu(rxdesc->pNextDesc),
2861 acx2cpu(rxdesc->ACXMemPtr),
2862 rxdesc->Ctl_8,
2863 rxdesc->rate, rxdesc->error, rxdesc->SNR);
2864 rxdesc++;
2867 /* dump host rx descriptor ring buffer */
2869 rxhostdesc = adev->rxhostdesc_start;
2871 /* loop over complete receive pool */
2872 if (rxhostdesc)
2873 for (i = 0; i < RX_CNT; i++) {
2874 printk("\ndump host rxdesc %d:\n"
2875 "mem pos %p\n"
2876 "buffer mem pos 0x%X\n"
2877 "buffer mem offset 0x%X\n"
2878 "CTL 0x%X\n"
2879 "Length 0x%X\n"
2880 "next 0x%X\n"
2881 "Status 0x%X\n",
2883 rxhostdesc,
2884 acx2cpu(rxhostdesc->data_phy),
2885 rxhostdesc->data_offset,
2886 le16_to_cpu(rxhostdesc->Ctl_16),
2887 le16_to_cpu(rxhostdesc->length),
2888 acx2cpu(rxhostdesc->desc_phy_next),
2889 rxhostdesc->Status);
2890 rxhostdesc++;
2893 /* dump acx111 internal tx descriptor ring buffer */
2894 txdesc = adev->txdesc_start;
2896 /* loop over complete transmit pool */
2897 if (txdesc)
2898 for (i = 0; i < TX_CNT; i++) {
2899 printk("\ndump internal txdesc %d:\n"
2900 "size 0x%X\n"
2901 "mem pos %p\n"
2902 "next 0x%X\n"
2903 "acx mem pointer (dynamic) 0x%X\n"
2904 "host mem pointer (dynamic) 0x%X\n"
2905 "length (dynamic) 0x%X\n"
2906 "CTL (dynamic) 0x%X\n"
2907 "CTL2 (dynamic) 0x%X\n"
2908 "Status (dynamic) 0x%X\n"
2909 "Rate (dynamic) 0x%X\n",
2911 (int)sizeof(struct txdesc),
2912 txdesc,
2913 acx2cpu(txdesc->pNextDesc),
2914 acx2cpu(txdesc->AcxMemPtr),
2915 acx2cpu(txdesc->HostMemPtr),
2916 le16_to_cpu(txdesc->total_length),
2917 txdesc->Ctl_8,
2918 txdesc->Ctl2_8, txdesc->error,
2919 txdesc->u.r1.rate);
2920 txdesc = advance_txdesc(adev, txdesc, 1);
2923 /* dump host tx descriptor ring buffer */
2925 txhostdesc = adev->txhostdesc_start;
2927 /* loop over complete host send pool */
2928 if (txhostdesc)
2929 for (i = 0; i < TX_CNT * 2; i++) {
2930 printk("\ndump host txdesc %d:\n"
2931 "mem pos %p\n"
2932 "buffer mem pos 0x%X\n"
2933 "buffer mem offset 0x%X\n"
2934 "CTL 0x%X\n"
2935 "Length 0x%X\n"
2936 "next 0x%X\n"
2937 "Status 0x%X\n",
2939 txhostdesc,
2940 acx2cpu(txhostdesc->data_phy),
2941 txhostdesc->data_offset,
2942 le16_to_cpu(txhostdesc->Ctl_16),
2943 le16_to_cpu(txhostdesc->length),
2944 acx2cpu(txhostdesc->desc_phy_next),
2945 le32_to_cpu(txhostdesc->Status));
2946 txhostdesc++;
2949 /* write_reg16(adev, 0xb4, 0x4); */
2951 acx_unlock(adev, flags);
2952 end_ok:
2954 acx_sem_unlock(adev);
2955 #endif /* ACX_DEBUG */
2956 return OK;
2960 /***********************************************************************
2963 acx100pci_ioctl_set_phy_amp_bias(struct net_device *ndev,
2964 struct iw_request_info *info,
2965 struct iw_param *vwrq, char *extra)
2967 acx_device_t *adev = ndev2adev(ndev);
2968 unsigned long flags;
2969 u16 gpio_old;
2971 if (!IS_ACX100(adev)) {
2972 /* WARNING!!!
2973 * Removing this check *might* damage
2974 * hardware, since we're tweaking GPIOs here after all!!!
2975 * You've been warned...
2976 * WARNING!!! */
2977 printk("acx: sorry, setting bias level for non-acx100 "
2978 "is not supported yet\n");
2979 return OK;
2982 if (*extra > 7) {
2983 printk("acx: invalid bias parameter, range is 0-7\n");
2984 return -EINVAL;
2987 acx_sem_lock(adev);
2989 /* Need to lock accesses to [IO_ACX_GPIO_OUT]:
2990 * IRQ handler uses it to update LED */
2991 acx_lock(adev, flags);
2992 gpio_old = read_reg16(adev, IO_ACX_GPIO_OUT);
2993 write_reg16(adev, IO_ACX_GPIO_OUT,
2994 (gpio_old & 0xf8ff) | ((u16) * extra << 8));
2995 acx_unlock(adev, flags);
2997 log(L_DEBUG, "gpio_old: 0x%04X\n", gpio_old);
2998 printk("%s: PHY power amplifier bias: old:%d, new:%d\n",
2999 ndev->name, (gpio_old & 0x0700) >> 8, (unsigned char)*extra);
3001 acx_sem_unlock(adev);
3003 return OK;
3005 #endif
3007 /***************************************************************
3008 ** acxpci_l_alloc_tx
3009 ** Actually returns a txdesc_t* ptr
3011 ** FIXME: in case of fragments, should allocate multiple descrs
3012 ** after figuring out how many we need and whether we still have
3013 ** sufficiently many.
3015 tx_t *acxpci_l_alloc_tx(acx_device_t * adev)
3017 struct txdesc *txdesc;
3018 unsigned head;
3019 u8 ctl8;
3021 FN_ENTER;
3023 if (unlikely(!adev->tx_free)) {
3024 printk("acx: BUG: no free txdesc left\n");
3025 txdesc = NULL;
3026 goto end;
3029 head = adev->tx_head;
3030 txdesc = get_txdesc(adev, head);
3031 ctl8 = txdesc->Ctl_8;
3033 /* 2005-10-11: there were several bug reports on this happening
3034 ** but now cause seems to be understood & fixed */
3035 if (unlikely(DESC_CTL_HOSTOWN != (ctl8 & DESC_CTL_ACXDONE_HOSTOWN))) {
3036 /* whoops, descr at current index is not free, so probably
3037 * ring buffer already full */
3038 printk("acx: BUG: tx_head:%d Ctl8:0x%02X - failed to find "
3039 "free txdesc\n", head, ctl8);
3040 txdesc = NULL;
3041 goto end;
3044 /* Needed in case txdesc won't be eventually submitted for tx */
3045 txdesc->Ctl_8 = DESC_CTL_ACXDONE_HOSTOWN;
3047 adev->tx_free--;
3048 log(L_BUFT, "tx: got desc %u, %u remain\n", head, adev->tx_free);
3049 /* Keep a few free descs between head and tail of tx ring.
3050 ** It is not absolutely needed, just feels safer */
3051 if (adev->tx_free < TX_STOP_QUEUE) {
3052 log(L_BUF, "stop queue (%u tx desc left)\n", adev->tx_free);
3053 acx_stop_queue(adev->ieee, NULL);
3056 /* returning current descriptor, so advance to next free one */
3057 adev->tx_head = (head + 1) % TX_CNT;
3058 end:
3059 FN_EXIT0;
3061 return (tx_t *) txdesc;
3065 /***********************************************************************
3067 void *acxpci_l_get_txbuf(acx_device_t * adev, tx_t * tx_opaque)
3069 return get_txhostdesc(adev, (txdesc_t *) tx_opaque)->data;
3073 /***********************************************************************
3074 ** acxpci_l_tx_data
3076 ** Can be called from IRQ (rx -> (AP bridging or mgmt response) -> tx).
3077 ** Can be called from acx_i_start_xmit (data frames from net core).
3079 ** FIXME: in case of fragments, should loop over the number of
3080 ** pre-allocated tx descrs, properly setting up transfer data and
3081 ** CTL_xxx flags according to fragment number.
3083 void
3084 acxpci_l_tx_data(acx_device_t * adev, tx_t * tx_opaque, int len,
3085 struct ieee80211_tx_control *ieeectl,struct sk_buff* skb)
3087 txdesc_t *txdesc = (txdesc_t *) tx_opaque;
3088 struct ieee80211_hdr *wireless_header;
3089 txhostdesc_t *hostdesc1, *hostdesc2;
3090 int rate_cur;
3091 u8 Ctl_8, Ctl2_8;
3092 int wlhdr_len;
3094 FN_ENTER;
3096 /* fw doesn't tx such packets anyhow */
3097 /* if (unlikely(len < WLAN_HDR_A3_LEN))
3098 goto end;
3100 hostdesc1 = get_txhostdesc(adev, txdesc);
3101 wireless_header = (struct ieee80211_hdr *)hostdesc1->data;
3102 /* modify flag status in separate variable to be able to write it back
3103 * in one big swoop later (also in order to have less device memory
3104 * accesses) */
3105 Ctl_8 = txdesc->Ctl_8;
3106 Ctl2_8 = 0; /* really need to init it to 0, not txdesc->Ctl2_8, it seems */
3108 hostdesc2 = hostdesc1 + 1;
3110 /* DON'T simply set Ctl field to 0 here globally,
3111 * it needs to maintain a consistent flag status (those are state flags!!),
3112 * otherwise it may lead to severe disruption. Only set or reset particular
3113 * flags at the exact moment this is needed... */
3115 /* let chip do RTS/CTS handshaking before sending
3116 * in case packet size exceeds threshold */
3117 if (ieeectl->flags & IEEE80211_TXCTL_USE_RTS_CTS)
3118 SET_BIT(Ctl2_8, DESC_CTL2_RTS);
3119 else
3120 CLEAR_BIT(Ctl2_8, DESC_CTL2_RTS);
3122 rate_cur = ieeectl->tx_rate;
3123 if (unlikely(!rate_cur)) {
3124 printk("acx: driver bug! bad ratemask\n");
3125 goto end;
3128 /* used in tx cleanup routine for auto rate and accounting: */
3129 /* put_txcr(adev, txdesc, clt, rate_cur); deprecated by mac80211 */
3131 txdesc->total_length = cpu_to_le16(len);
3132 wlhdr_len = ieee80211_get_hdrlen(le16_to_cpu(wireless_header->frame_control));
3133 hostdesc2->length = cpu_to_le16(len - wlhdr_len);
3135 if (!ieeectl->do_not_encrypt && ieeectl->key_idx>= 0)
3137 u16 key_idx = (u16)(ieeectl->key_idx);
3138 struct acx_key* key = &(adev->key[key_idx]);
3139 int wlhdr_len;
3140 if (key->enabled)
3142 memcpy(ieeehdr->wep_iv, ((u8*)wireless_header) + wlhdr_len, 4);
3146 if (IS_ACX111(adev)) {
3147 /* note that if !txdesc->do_auto, txrate->cur
3148 ** has only one nonzero bit */
3149 txdesc->u.r2.rate111 = cpu_to_le16(rate_cur
3150 /* WARNING: I was never able to make it work with prism54 AP.
3151 ** It was falling down to 1Mbit where shortpre is not applicable,
3152 ** and not working at all at "5,11 basic rates only" setting.
3153 ** I even didn't see tx packets in radio packet capture.
3154 ** Disabled for now --vda */
3155 /*| ((clt->shortpre && clt->cur!=RATE111_1) ? RATE111_SHORTPRE : 0) */
3157 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3158 /* should add this to rate111 above as necessary */
3159 |(clt->pbcc511 ? RATE111_PBCC511 : 0)
3160 #endif
3161 hostdesc1->length = cpu_to_le16(len);
3162 } else { /* ACX100 */
3163 u8 rate_100 = ieeectl->tx_rate;
3164 txdesc->u.r1.rate = rate_100;
3165 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3166 if (clt->pbcc511) {
3167 if (n == RATE100_5 || n == RATE100_11)
3168 n |= RATE100_PBCC511;
3171 if (clt->shortpre && (clt->cur != RATE111_1))
3172 SET_BIT(Ctl_8, DESC_CTL_SHORT_PREAMBLE); /* set Short Preamble */
3173 #endif
3174 /* set autodma and reclaim and 1st mpdu */
3175 SET_BIT(Ctl_8,
3176 DESC_CTL_AUTODMA | DESC_CTL_RECLAIM |
3177 DESC_CTL_FIRSTFRAG);
3178 #if ACX_FRAGMENTATION
3179 /* SET_BIT(Ctl2_8, DESC_CTL2_MORE_FRAG); cannot set it unconditionally, needs to be set for all non-last fragments */
3180 #endif
3181 hostdesc1->length = cpu_to_le16(wlhdr_len);
3183 /* don't need to clean ack/rts statistics here, already
3184 * done on descr cleanup */
3186 /* clears HOSTOWN and ACXDONE bits, thus telling that the descriptors
3187 * are now owned by the acx100; do this as LAST operation */
3188 CLEAR_BIT(Ctl_8, DESC_CTL_ACXDONE_HOSTOWN);
3189 /* flush writes before we release hostdesc to the adapter here */
3190 wmb();
3191 CLEAR_BIT(hostdesc1->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3192 CLEAR_BIT(hostdesc2->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3194 /* write back modified flags */
3195 CLEAR_BIT(Ctl2_8, DESC_CTL2_WEP);
3196 txdesc->Ctl2_8 = Ctl2_8;
3197 txdesc->Ctl_8 = Ctl_8;
3198 /* unused: txdesc->tx_time = cpu_to_le32(jiffies); */
3200 /* flush writes before we tell the adapter that it's its turn now */
3201 write_reg16(adev, IO_ACX_INT_TRIG, INT_TRIG_TXPRC);
3202 write_flush(adev);
3203 /* log the packet content AFTER sending it,
3204 * in order to not delay sending any further than absolutely needed
3205 * Do separate logs for acx100/111 to have human-readable rates */
3206 memcpy(&(hostdesc1->txstatus.control),ieeectl,sizeof(struct ieee80211_tx_control));
3207 hostdesc1->skb = skb;
3208 end:
3209 FN_EXIT0;
3213 /***********************************************************************
3214 ** acxpci_l_clean_txdesc
3216 ** This function resets the txdescs' status when the ACX100
3217 ** signals the TX done IRQ (txdescs have been processed), starting with
3218 ** the pool index of the descriptor which we would use next,
3219 ** in order to make sure that we can be as fast as possible
3220 ** in filling new txdescs.
3221 ** Everytime we get called we know where the next packet to be cleaned is.
3224 #if !ACX_DEBUG
3225 static inline void log_txbuffer(const acx_device_t * adev)
3228 #else
3229 static void log_txbuffer(acx_device_t * adev)
3231 txdesc_t *txdesc;
3232 int i;
3234 /* no FN_ENTER here, we don't want that */
3235 /* no locks here, since it's entirely non-critical code */
3236 txdesc = adev->txdesc_start;
3237 if (unlikely(!txdesc))
3238 return;
3239 printk("tx: desc->Ctl8's:");
3240 for (i = 0; i < TX_CNT; i++) {
3241 printk(" %02X", txdesc->Ctl_8);
3242 txdesc = advance_txdesc(adev, txdesc, 1);
3244 printk("\n");
3246 #endif
3249 static void handle_tx_error(acx_device_t * adev, u8 error, unsigned int finger,
3250 struct ieee80211_tx_status *status)
3252 const char *err = "unknown error";
3254 /* hmm, should we handle this as a mask
3255 * of *several* bits?
3256 * For now I think only caring about
3257 * individual bits is ok... */
3258 switch (error) {
3259 case 0x01:
3260 err = "no Tx due to error in other fragment";
3261 /* adev->wstats.discard.fragment++; */
3262 break;
3263 case 0x02:
3264 err = "Tx aborted";
3265 adev->stats.tx_aborted_errors++;
3266 break;
3267 case 0x04:
3268 err = "Tx desc wrong parameters";
3269 /* adev->wstats.discard.misc++; */
3270 break;
3271 case 0x08:
3272 err = "WEP key not found";
3273 /* adev->wstats.discard.misc++; */
3274 break;
3275 case 0x10:
3276 err = "MSDU lifetime timeout? - try changing "
3277 "'iwconfig retry lifetime XXX'";
3278 /* adev->wstats.discard.misc++; */
3279 break;
3280 case 0x20:
3281 err = "excessive Tx retries due to either distance "
3282 "too high or unable to Tx or Tx frame error - "
3283 "try changing 'iwconfig txpower XXX' or "
3284 "'sens'itivity or 'retry'";
3285 /* adev->wstats.discard.retries++; */
3286 /* Tx error 0x20 also seems to occur on
3287 * overheating, so I'm not sure whether we
3288 * actually want to do aggressive radio recalibration,
3289 * since people maybe won't notice then that their hardware
3290 * is slowly getting cooked...
3291 * Or is it still a safe long distance from utter
3292 * radio non-functionality despite many radio recalibs
3293 * to final destructive overheating of the hardware?
3294 * In this case we really should do recalib here...
3295 * I guess the only way to find out is to do a
3296 * potentially fatal self-experiment :-\
3297 * Or maybe only recalib in case we're using Tx
3298 * rate auto (on errors switching to lower speed
3299 * --> less heat?) or 802.11 power save mode?
3301 * ok, just do it. */
3302 if (++adev->retry_errors_msg_ratelimit % 4 == 0) {
3303 if (adev->retry_errors_msg_ratelimit <= 20) {
3304 printk("%s: several excessive Tx "
3305 "retry errors occurred, attempting "
3306 "to recalibrate radio. Radio "
3307 "drift might be caused by increasing "
3308 "card temperature, please check the card "
3309 "before it's too late!\n",
3310 wiphy_name(adev->ieee->wiphy));
3311 if (adev->retry_errors_msg_ratelimit == 20)
3312 printk("disabling above message\n");
3315 acx_schedule_task(adev,
3316 ACX_AFTER_IRQ_CMD_RADIO_RECALIB);
3318 status->excessive_retries++;
3319 break;
3320 case 0x40:
3321 err = "Tx buffer overflow";
3322 adev->stats.tx_fifo_errors++;
3323 break;
3324 case 0x80:
3325 /* possibly ACPI C-state powersaving related!!!
3326 * (DMA timeout due to excessively high wakeup
3327 * latency after C-state activation!?)
3328 * Disable C-State powersaving and try again,
3329 * then PLEASE REPORT, I'm VERY interested in
3330 * whether my theory is correct that this is
3331 * actually the problem here.
3332 * In that case, use new Linux idle wakeup latency
3333 * requirements kernel API to prevent this issue. */
3334 err = "DMA error";
3335 /* adev->wstats.discard.misc++; */
3336 break;
3338 adev->stats.tx_errors++;
3339 if (adev->stats.tx_errors <= 20)
3340 printk("%s: tx error 0x%02X, buf %02u! (%s)\n",
3341 wiphy_name(adev->ieee->wiphy), error, finger, err);
3342 else
3343 printk("%s: tx error 0x%02X, buf %02u!\n",
3344 wiphy_name(adev->ieee->wiphy), error, finger);
3348 unsigned int acxpci_l_clean_txdesc(acx_device_t * adev)
3350 txdesc_t *txdesc;
3351 txhostdesc_t *hostdesc;
3352 unsigned finger;
3353 int num_cleaned;
3354 u16 r111;
3355 u8 error, ack_failures, rts_failures, rts_ok, r100;
3357 FN_ENTER;
3359 if (unlikely(acx_debug & L_DEBUG))
3360 log_txbuffer(adev);
3362 log(L_BUFT, "tx: cleaning up bufs from %u\n", adev->tx_tail);
3364 /* We know first descr which is not free yet. We advance it as far
3365 ** as we see correct bits set in following descs (if next desc
3366 ** is NOT free, we shouldn't advance at all). We know that in
3367 ** front of tx_tail may be "holes" with isolated free descs.
3368 ** We will catch up when all intermediate descs will be freed also */
3370 finger = adev->tx_tail;
3371 num_cleaned = 0;
3372 while (likely(finger != adev->tx_head)) {
3373 txdesc = get_txdesc(adev, finger);
3375 /* If we allocated txdesc on tx path but then decided
3376 ** to NOT use it, then it will be left as a free "bubble"
3377 ** in the "allocated for tx" part of the ring.
3378 ** We may meet it on the next ring pass here. */
3380 /* stop if not marked as "tx finished" and "host owned" */
3381 if ((txdesc->Ctl_8 & DESC_CTL_ACXDONE_HOSTOWN)
3382 != DESC_CTL_ACXDONE_HOSTOWN) {
3383 if (unlikely(!num_cleaned)) { /* maybe remove completely */
3384 log(L_BUFT, "clean_txdesc: tail isn't free. "
3385 "tail:%d head:%d\n",
3386 adev->tx_tail, adev->tx_head);
3388 break;
3391 /* remember desc values... */
3392 error = txdesc->error;
3393 ack_failures = txdesc->ack_failures;
3394 rts_failures = txdesc->rts_failures;
3395 rts_ok = txdesc->rts_ok;
3396 r100 = txdesc->u.r1.rate;
3397 r111 = le16_to_cpu(txdesc->u.r2.rate111);
3399 /* need to check for certain error conditions before we
3400 * clean the descriptor: we still need valid descr data here */
3401 hostdesc = get_txhostdesc(adev, txdesc);
3403 hostdesc->txstatus.flags |= IEEE80211_TX_STATUS_ACK;
3404 if (unlikely(0x30 & error)) {
3405 /* only send IWEVTXDROP in case of retry or lifetime exceeded;
3406 * all other errors mean we screwed up locally */
3407 /* union iwreq_data wrqu;
3408 struct ieee80211_hdr_3addr *hdr;
3409 hdr = (struct ieee80211_hdr_3addr *) hostdesc->data;
3410 MAC_COPY(wrqu.addr.sa_data, hdr->addr1);
3412 hostdesc->txstatus.flags &= ~IEEE80211_TX_STATUS_ACK;
3415 /* ...and free the desc */
3416 txdesc->error = 0;
3417 txdesc->ack_failures = 0;
3418 txdesc->rts_failures = 0;
3419 txdesc->rts_ok = 0;
3420 /* signal host owning it LAST, since ACX already knows that this
3421 ** descriptor is finished since it set Ctl_8 accordingly. */
3422 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3424 adev->tx_free++;
3425 num_cleaned++;
3427 if ((adev->tx_free >= TX_START_QUEUE)
3428 /* && (adev->status == ACX_STATUS_4_ASSOCIATED) */
3429 /*&& (acx_queue_stopped(adev->ieee))*/
3431 log(L_BUF, "tx: wake queue (avail. Tx desc %u)\n",
3432 adev->tx_free);
3433 acx_wake_queue(adev->ieee, NULL);
3436 /* do error checking, rate handling and logging
3437 * AFTER having done the work, it's faster */
3439 /* Rate handling is done in mac80211 */
3440 /* if (adev->rate_auto) {
3441 struct client *clt = get_txc(adev, txdesc);
3442 if (clt) {
3443 u16 cur = get_txr(adev, txdesc);
3444 if (clt->rate_cur == cur) {
3445 acx_l_handle_txrate_auto(adev, clt, cur,*/ /* intended rate */
3446 /*r100, r111,*/ /* actually used rate */
3447 /*(error & 0x30),*/ /* was there an error? */
3448 /* TX_CNT +
3449 TX_CLEAN_BACKLOG
3451 adev->tx_free);
3456 if (unlikely(error))
3457 handle_tx_error(adev, error, finger, &hostdesc->txstatus);
3459 if (IS_ACX111(adev))
3460 log(L_BUFT,
3461 "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u r111=%04X tx_free=%u\n",
3462 finger, ack_failures, rts_failures, rts_ok, r111, adev->tx_free);
3463 else
3464 log(L_BUFT,
3465 "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u rate=%u\n",
3466 finger, ack_failures, rts_failures, rts_ok, r100);
3468 /* And finally report upstream */
3469 if (hostdesc)
3471 hostdesc->txstatus.excessive_retries = rts_failures ;
3472 hostdesc->txstatus.retry_count = ack_failures;
3473 ieee80211_tx_status(adev->ieee,hostdesc->skb,&hostdesc->txstatus);
3474 memset(&hostdesc->txstatus, 0, sizeof(struct ieee80211_tx_status));
3476 /* update pointer for descr to be cleaned next */
3477 finger = (finger + 1) % TX_CNT;
3479 /* remember last position */
3480 adev->tx_tail = finger;
3481 /* end: */
3482 FN_EXIT1(num_cleaned);
3483 return num_cleaned;
3486 /* clean *all* Tx descriptors, and regardless of their previous state.
3487 * Used for brute-force reset handling. */
3488 void acxpci_l_clean_txdesc_emergency(acx_device_t * adev)
3490 txdesc_t *txdesc;
3491 int i;
3493 FN_ENTER;
3495 for (i = 0; i < TX_CNT; i++) {
3496 txdesc = get_txdesc(adev, i);
3498 /* free it */
3499 txdesc->ack_failures = 0;
3500 txdesc->rts_failures = 0;
3501 txdesc->rts_ok = 0;
3502 txdesc->error = 0;
3503 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3506 adev->tx_free = TX_CNT;
3508 FN_EXIT0;
3512 /***********************************************************************
3513 ** acxpci_s_create_tx_host_desc_queue
3516 static void *allocate(acx_device_t * adev, size_t size, dma_addr_t * phy,
3517 const char *msg)
3519 void *ptr;
3521 ptr = dma_alloc_coherent(adev->bus_dev, size, phy, GFP_KERNEL);
3523 if (ptr) {
3524 log(L_DEBUG, "%s sz=%d adr=0x%p phy=0x%08llx\n",
3525 msg, (int)size, ptr, (unsigned long long)*phy);
3526 memset(ptr, 0, size);
3527 return ptr;
3529 printk(KERN_ERR "acx: %s allocation FAILED (%d bytes)\n",
3530 msg, (int)size);
3531 return NULL;
3535 static int acxpci_s_create_tx_host_desc_queue(acx_device_t * adev)
3537 txhostdesc_t *hostdesc;
3538 u8 *txbuf;
3539 dma_addr_t hostdesc_phy;
3540 dma_addr_t txbuf_phy;
3541 int i;
3543 FN_ENTER;
3545 /* allocate TX buffer */
3546 adev->txbuf_area_size = TX_CNT * /*WLAN_A4FR_MAXLEN_WEP_FCS*/ (30 + 2312 + 4);
3547 adev->txbuf_start = allocate(adev, adev->txbuf_area_size,
3548 &adev->txbuf_startphy, "txbuf_start");
3549 if (!adev->txbuf_start)
3550 goto fail;
3552 /* allocate the TX host descriptor queue pool */
3553 adev->txhostdesc_area_size = TX_CNT * 2 * sizeof(*hostdesc);
3554 adev->txhostdesc_start = allocate(adev, adev->txhostdesc_area_size,
3555 &adev->txhostdesc_startphy,
3556 "txhostdesc_start");
3557 if (!adev->txhostdesc_start)
3558 goto fail;
3559 /* check for proper alignment of TX host descriptor pool */
3560 if ((long)adev->txhostdesc_start & 3) {
3561 printk
3562 ("acx: driver bug: dma alloc returns unaligned address\n");
3563 goto fail;
3566 hostdesc = adev->txhostdesc_start;
3567 hostdesc_phy = adev->txhostdesc_startphy;
3568 txbuf = adev->txbuf_start;
3569 txbuf_phy = adev->txbuf_startphy;
3571 #if 0
3572 /* Each tx buffer is accessed by hardware via
3573 ** txdesc -> txhostdesc(s) -> txbuffer(s).
3574 ** We use only one txhostdesc per txdesc, but it looks like
3575 ** acx111 is buggy: it accesses second txhostdesc
3576 ** (via hostdesc.desc_phy_next field) even if
3577 ** txdesc->length == hostdesc->length and thus
3578 ** entire packet was placed into first txhostdesc.
3579 ** Due to this bug acx111 hangs unless second txhostdesc
3580 ** has le16_to_cpu(hostdesc.length) = 3 (or larger)
3581 ** Storing NULL into hostdesc.desc_phy_next
3582 ** doesn't seem to help.
3584 ** Update: although it worked on Xterasys XN-2522g
3585 ** with len=3 trick, WG311v2 is even more bogus, doesn't work.
3586 ** Keeping this code (#ifdef'ed out) for documentational purposes.
3588 for (i = 0; i < TX_CNT * 2; i++) {
3589 hostdesc_phy += sizeof(*hostdesc);
3590 if (!(i & 1)) {
3591 hostdesc->data_phy = cpu2acx(txbuf_phy);
3592 /* hostdesc->data_offset = ... */
3593 /* hostdesc->reserved = ... */
3594 hostdesc->Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
3595 /* hostdesc->length = ... */
3596 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3597 hostdesc->pNext = ptr2acx(NULL);
3598 /* hostdesc->Status = ... */
3599 /* below: non-hardware fields */
3600 hostdesc->data = txbuf;
3602 txbuf += WLAN_A4FR_MAXLEN_WEP_FCS;
3603 txbuf_phy += WLAN_A4FR_MAXLEN_WEP_FCS;
3604 } else {
3605 /* hostdesc->data_phy = ... */
3606 /* hostdesc->data_offset = ... */
3607 /* hostdesc->reserved = ... */
3608 /* hostdesc->Ctl_16 = ... */
3609 hostdesc->length = cpu_to_le16(3); /* bug workaround */
3610 /* hostdesc->desc_phy_next = ... */
3611 /* hostdesc->pNext = ... */
3612 /* hostdesc->Status = ... */
3613 /* below: non-hardware fields */
3614 /* hostdesc->data = ... */
3616 hostdesc++;
3618 #endif
3619 /* We initialize two hostdescs so that they point to adjacent
3620 ** memory areas. Thus txbuf is really just a contiguous memory area */
3621 for (i = 0; i < TX_CNT * 2; i++) {
3622 hostdesc_phy += sizeof(*hostdesc);
3624 hostdesc->data_phy = cpu2acx(txbuf_phy);
3625 /* done by memset(0): hostdesc->data_offset = 0; */
3626 /* hostdesc->reserved = ... */
3627 hostdesc->Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
3628 /* hostdesc->length = ... */
3629 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3630 /* done by memset(0): hostdesc->pNext = ptr2acx(NULL); */
3631 /* hostdesc->Status = ... */
3632 /* ->data is a non-hardware field: */
3633 hostdesc->data = txbuf;
3635 if (!(i & 1)) {
3636 txbuf += 24 /*WLAN_HDR_A3_LEN*/;
3637 txbuf_phy += 24 /*WLAN_HDR_A3_LEN*/;
3638 } else {
3639 txbuf += 30 + 2132 + 4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3640 txbuf_phy += 30 + 2132 +4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3642 hostdesc++;
3644 hostdesc--;
3645 hostdesc->desc_phy_next = cpu2acx(adev->txhostdesc_startphy);
3647 FN_EXIT1(OK);
3648 return OK;
3649 fail:
3650 printk("acx: create_tx_host_desc_queue FAILED\n");
3651 /* dealloc will be done by free function on error case */
3652 FN_EXIT1(NOT_OK);
3653 return NOT_OK;
3657 /***************************************************************
3658 ** acxpci_s_create_rx_host_desc_queue
3660 /* the whole size of a data buffer (header plus data body)
3661 * plus 32 bytes safety offset at the end */
3662 #define RX_BUFFER_SIZE (sizeof(rxbuffer_t) + 32)
3664 static int acxpci_s_create_rx_host_desc_queue(acx_device_t * adev)
3666 rxhostdesc_t *hostdesc;
3667 rxbuffer_t *rxbuf;
3668 dma_addr_t hostdesc_phy;
3669 dma_addr_t rxbuf_phy;
3670 int i;
3672 FN_ENTER;
3674 /* allocate the RX host descriptor queue pool */
3675 adev->rxhostdesc_area_size = RX_CNT * sizeof(*hostdesc);
3676 adev->rxhostdesc_start = allocate(adev, adev->rxhostdesc_area_size,
3677 &adev->rxhostdesc_startphy,
3678 "rxhostdesc_start");
3679 if (!adev->rxhostdesc_start)
3680 goto fail;
3681 /* check for proper alignment of RX host descriptor pool */
3682 if ((long)adev->rxhostdesc_start & 3) {
3683 printk
3684 ("acx: driver bug: dma alloc returns unaligned address\n");
3685 goto fail;
3688 /* allocate Rx buffer pool which will be used by the acx
3689 * to store the whole content of the received frames in it */
3690 adev->rxbuf_area_size = RX_CNT * RX_BUFFER_SIZE;
3691 adev->rxbuf_start = allocate(adev, adev->rxbuf_area_size,
3692 &adev->rxbuf_startphy, "rxbuf_start");
3693 if (!adev->rxbuf_start)
3694 goto fail;
3696 rxbuf = adev->rxbuf_start;
3697 rxbuf_phy = adev->rxbuf_startphy;
3698 hostdesc = adev->rxhostdesc_start;
3699 hostdesc_phy = adev->rxhostdesc_startphy;
3701 /* don't make any popular C programming pointer arithmetic mistakes
3702 * here, otherwise I'll kill you...
3703 * (and don't dare asking me why I'm warning you about that...) */
3704 for (i = 0; i < RX_CNT; i++) {
3705 hostdesc->data = rxbuf;
3706 hostdesc->data_phy = cpu2acx(rxbuf_phy);
3707 hostdesc->length = cpu_to_le16(RX_BUFFER_SIZE);
3708 CLEAR_BIT(hostdesc->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3709 rxbuf++;
3710 rxbuf_phy += sizeof(*rxbuf);
3711 hostdesc_phy += sizeof(*hostdesc);
3712 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3713 hostdesc++;
3715 hostdesc--;
3716 hostdesc->desc_phy_next = cpu2acx(adev->rxhostdesc_startphy);
3717 FN_EXIT1(OK);
3718 return OK;
3719 fail:
3720 printk("acx: create_rx_host_desc_queue FAILED\n");
3721 /* dealloc will be done by free function on error case */
3722 FN_EXIT1(NOT_OK);
3723 return NOT_OK;
3727 /***************************************************************
3728 ** acxpci_s_create_hostdesc_queues
3730 int acxpci_s_create_hostdesc_queues(acx_device_t * adev)
3732 int result;
3733 result = acxpci_s_create_tx_host_desc_queue(adev);
3734 if (OK != result)
3735 return result;
3736 result = acxpci_s_create_rx_host_desc_queue(adev);
3737 return result;
3741 /***************************************************************
3742 ** acxpci_create_tx_desc_queue
3744 static void acxpci_create_tx_desc_queue(acx_device_t * adev, u32 tx_queue_start)
3746 txdesc_t *txdesc;
3747 txhostdesc_t *hostdesc;
3748 dma_addr_t hostmemptr;
3749 u32 mem_offs;
3750 int i;
3752 FN_ENTER;
3754 if (IS_ACX100(adev))
3755 adev->txdesc_size = sizeof(*txdesc);
3756 else
3757 /* the acx111 txdesc is 4 bytes larger */
3758 adev->txdesc_size = sizeof(*txdesc) + 4;
3760 adev->txdesc_start = (txdesc_t *) (adev->iobase2 + tx_queue_start);
3762 log(L_DEBUG, "adev->iobase2=%p\n"
3763 "tx_queue_start=%08X\n"
3764 "adev->txdesc_start=%p\n",
3765 adev->iobase2, tx_queue_start, adev->txdesc_start);
3767 adev->tx_free = TX_CNT;
3768 /* done by memset: adev->tx_head = 0; */
3769 /* done by memset: adev->tx_tail = 0; */
3770 txdesc = adev->txdesc_start;
3771 mem_offs = tx_queue_start;
3772 hostmemptr = adev->txhostdesc_startphy;
3773 hostdesc = adev->txhostdesc_start;
3775 if (IS_ACX111(adev)) {
3776 /* ACX111 has a preinitialized Tx buffer! */
3777 /* loop over whole send pool */
3778 /* FIXME: do we have to do the hostmemptr stuff here?? */
3779 for (i = 0; i < TX_CNT; i++) {
3780 txdesc->HostMemPtr = ptr2acx(hostmemptr);
3781 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3782 /* reserve two (hdr desc and payload desc) */
3783 hostdesc += 2;
3784 hostmemptr += 2 * sizeof(*hostdesc);
3785 txdesc = advance_txdesc(adev, txdesc, 1);
3787 } else {
3788 /* ACX100 Tx buffer needs to be initialized by us */
3789 /* clear whole send pool. sizeof is safe here (we are acx100) */
3790 memset(adev->txdesc_start, 0, TX_CNT * sizeof(*txdesc));
3792 /* loop over whole send pool */
3793 for (i = 0; i < TX_CNT; i++) {
3794 log(L_DEBUG, "configure card tx descriptor: 0x%p, "
3795 "size: 0x%X\n", txdesc, adev->txdesc_size);
3797 /* pointer to hostdesc memory */
3798 txdesc->HostMemPtr = ptr2acx(hostmemptr);
3799 /* initialise ctl */
3800 txdesc->Ctl_8 = (DESC_CTL_HOSTOWN | DESC_CTL_RECLAIM
3801 | DESC_CTL_AUTODMA |
3802 DESC_CTL_FIRSTFRAG);
3803 /* done by memset(0): txdesc->Ctl2_8 = 0; */
3804 /* point to next txdesc */
3805 txdesc->pNextDesc =
3806 cpu2acx(mem_offs + adev->txdesc_size);
3807 /* reserve two (hdr desc and payload desc) */
3808 hostdesc += 2;
3809 hostmemptr += 2 * sizeof(*hostdesc);
3810 /* go to the next one */
3811 mem_offs += adev->txdesc_size;
3812 /* ++ is safe here (we are acx100) */
3813 txdesc++;
3815 /* go back to the last one */
3816 txdesc--;
3817 /* and point to the first making it a ring buffer */
3818 txdesc->pNextDesc = cpu2acx(tx_queue_start);
3820 FN_EXIT0;
3824 /***************************************************************
3825 ** acxpci_create_rx_desc_queue
3827 static void acxpci_create_rx_desc_queue(acx_device_t * adev, u32 rx_queue_start)
3829 rxdesc_t *rxdesc;
3830 u32 mem_offs;
3831 int i;
3833 FN_ENTER;
3835 /* done by memset: adev->rx_tail = 0; */
3837 /* ACX111 doesn't need any further config: preconfigures itself.
3838 * Simply print ring buffer for debugging */
3839 if (IS_ACX111(adev)) {
3840 /* rxdesc_start already set here */
3842 adev->rxdesc_start =
3843 (rxdesc_t *) ((u8 *) adev->iobase2 + rx_queue_start);
3845 rxdesc = adev->rxdesc_start;
3846 for (i = 0; i < RX_CNT; i++) {
3847 log(L_DEBUG, "rx descriptor %d @ 0x%p\n", i, rxdesc);
3848 rxdesc = adev->rxdesc_start = (rxdesc_t *)
3849 (adev->iobase2 + acx2cpu(rxdesc->pNextDesc));
3851 } else {
3852 /* we didn't pre-calculate rxdesc_start in case of ACX100 */
3853 /* rxdesc_start should be right AFTER Tx pool */
3854 adev->rxdesc_start = (rxdesc_t *)
3855 ((u8 *) adev->txdesc_start + (TX_CNT * sizeof(txdesc_t)));
3856 /* NB: sizeof(txdesc_t) above is valid because we know
3857 ** we are in if (acx100) block. Beware of cut-n-pasting elsewhere!
3858 ** acx111's txdesc is larger! */
3860 memset(adev->rxdesc_start, 0, RX_CNT * sizeof(*rxdesc));
3862 /* loop over whole receive pool */
3863 rxdesc = adev->rxdesc_start;
3864 mem_offs = rx_queue_start;
3865 for (i = 0; i < RX_CNT; i++) {
3866 log(L_DEBUG, "rx descriptor @ 0x%p\n", rxdesc);
3867 rxdesc->Ctl_8 = DESC_CTL_RECLAIM | DESC_CTL_AUTODMA;
3868 /* point to next rxdesc */
3869 rxdesc->pNextDesc = cpu2acx(mem_offs + sizeof(*rxdesc));
3870 /* go to the next one */
3871 mem_offs += sizeof(*rxdesc);
3872 rxdesc++;
3874 /* go to the last one */
3875 rxdesc--;
3877 /* and point to the first making it a ring buffer */
3878 rxdesc->pNextDesc = cpu2acx(rx_queue_start);
3880 FN_EXIT0;
3884 /***************************************************************
3885 ** acxpci_create_desc_queues
3887 void
3888 acxpci_create_desc_queues(acx_device_t * adev, u32 tx_queue_start,
3889 u32 rx_queue_start)
3891 acxpci_create_tx_desc_queue(adev, tx_queue_start);
3892 acxpci_create_rx_desc_queue(adev, rx_queue_start);
3896 /***************************************************************
3897 ** acxpci_s_proc_diag_output
3899 char *acxpci_s_proc_diag_output(char *p, acx_device_t * adev)
3901 const char *rtl, *thd, *ttl;
3902 rxhostdesc_t *rxhostdesc;
3903 txdesc_t *txdesc;
3904 int i;
3906 FN_ENTER;
3908 p += sprintf(p, "** Rx buf **\n");
3909 rxhostdesc = adev->rxhostdesc_start;
3910 if (rxhostdesc)
3911 for (i = 0; i < RX_CNT; i++) {
3912 rtl = (i == adev->rx_tail) ? " [tail]" : "";
3913 if ((rxhostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
3914 && (rxhostdesc->
3915 Status & cpu_to_le32(DESC_STATUS_FULL)))
3916 p += sprintf(p, "%02u FULL%s\n", i, rtl);
3917 else
3918 p += sprintf(p, "%02u empty%s\n", i, rtl);
3919 rxhostdesc++;
3921 /* p += sprintf(p, "** Tx buf (free %d, Linux netqueue %s) **\n",
3922 adev->tx_free,
3923 acx_queue_stopped(adev->ieee) ? "STOPPED" : "running");*/
3924 txdesc = adev->txdesc_start;
3925 if (txdesc)
3926 for (i = 0; i < TX_CNT; i++) {
3927 thd = (i == adev->tx_head) ? " [head]" : "";
3928 ttl = (i == adev->tx_tail) ? " [tail]" : "";
3929 if (txdesc->Ctl_8 & DESC_CTL_ACXDONE)
3930 p += sprintf(p, "%02u free (%02X)%s%s\n", i,
3931 txdesc->Ctl_8, thd, ttl);
3932 else
3933 p += sprintf(p, "%02u tx (%02X)%s%s\n", i,
3934 txdesc->Ctl_8, thd, ttl);
3935 txdesc = advance_txdesc(adev, txdesc, 1);
3937 p += sprintf(p,
3938 "\n"
3939 "** PCI data **\n"
3940 "txbuf_start %p, txbuf_area_size %u, txbuf_startphy %08llx\n"
3941 "txdesc_size %u, txdesc_start %p\n"
3942 "txhostdesc_start %p, txhostdesc_area_size %u, txhostdesc_startphy %08llx\n"
3943 "rxdesc_start %p\n"
3944 "rxhostdesc_start %p, rxhostdesc_area_size %u, rxhostdesc_startphy %08llx\n"
3945 "rxbuf_start %p, rxbuf_area_size %u, rxbuf_startphy %08llx\n",
3946 adev->txbuf_start, adev->txbuf_area_size,
3947 (unsigned long long)adev->txbuf_startphy,
3948 adev->txdesc_size, adev->txdesc_start,
3949 adev->txhostdesc_start, adev->txhostdesc_area_size,
3950 (unsigned long long)adev->txhostdesc_startphy,
3951 adev->rxdesc_start,
3952 adev->rxhostdesc_start, adev->rxhostdesc_area_size,
3953 (unsigned long long)adev->rxhostdesc_startphy,
3954 adev->rxbuf_start, adev->rxbuf_area_size,
3955 (unsigned long long)adev->rxbuf_startphy);
3957 FN_EXIT0;
3958 return p;
3962 /***********************************************************************
3964 int acxpci_proc_eeprom_output(char *buf, acx_device_t * adev)
3966 char *p = buf;
3967 int i;
3969 FN_ENTER;
3971 for (i = 0; i < 0x400; i++) {
3972 acxpci_read_eeprom_byte(adev, i, p++);
3975 FN_EXIT1(p - buf);
3976 return p - buf;
3980 /***********************************************************************
3981 ** Obvious
3983 void acxpci_set_interrupt_mask(acx_device_t * adev)
3985 if (IS_ACX111(adev)) {
3986 adev->irq_mask = (u16) ~ (0
3987 /* | HOST_INT_RX_DATA */
3988 | HOST_INT_TX_COMPLETE
3989 /* | HOST_INT_TX_XFER */
3990 | HOST_INT_RX_COMPLETE
3991 /* | HOST_INT_DTIM */
3992 /* | HOST_INT_BEACON */
3993 /* | HOST_INT_TIMER */
3994 /* | HOST_INT_KEY_NOT_FOUND */
3995 | HOST_INT_IV_ICV_FAILURE
3996 | HOST_INT_CMD_COMPLETE
3997 | HOST_INT_INFO
3998 /* | HOST_INT_OVERFLOW */
3999 /* | HOST_INT_PROCESS_ERROR */
4000 | HOST_INT_SCAN_COMPLETE
4001 | HOST_INT_FCS_THRESHOLD
4002 /* | HOST_INT_UNKNOWN */
4004 /* Or else acx100 won't signal cmd completion, right? */
4005 adev->irq_mask_off = (u16) ~ (HOST_INT_CMD_COMPLETE); /* 0xfdff */
4006 } else {
4007 adev->irq_mask = (u16) ~ (0
4008 /* | HOST_INT_RX_DATA */
4009 | HOST_INT_TX_COMPLETE
4010 /* | HOST_INT_TX_XFER */
4011 | HOST_INT_RX_COMPLETE
4012 /* | HOST_INT_DTIM */
4013 /* | HOST_INT_BEACON */
4014 /* | HOST_INT_TIMER */
4015 /* | HOST_INT_KEY_NOT_FOUND */
4016 /* | HOST_INT_IV_ICV_FAILURE */
4017 | HOST_INT_CMD_COMPLETE
4018 | HOST_INT_INFO
4019 /* | HOST_INT_OVERFLOW */
4020 /* | HOST_INT_PROCESS_ERROR */
4021 | HOST_INT_SCAN_COMPLETE
4022 /* | HOST_INT_FCS_THRESHOLD */
4023 /* | HOST_INT_UNKNOWN */
4025 adev->irq_mask_off = (u16) ~ (HOST_INT_UNKNOWN); /* 0x7fff */
4030 /***********************************************************************
4032 int acx100pci_s_set_tx_level(acx_device_t * adev, u8 level_dbm)
4034 /* since it can be assumed that at least the Maxim radio has a
4035 * maximum power output of 20dBm and since it also can be
4036 * assumed that these values drive the DAC responsible for
4037 * setting the linear Tx level, I'd guess that these values
4038 * should be the corresponding linear values for a dBm value,
4039 * in other words: calculate the values from that formula:
4040 * Y [dBm] = 10 * log (X [mW])
4041 * then scale the 0..63 value range onto the 1..100mW range (0..20 dBm)
4042 * and you're done...
4043 * Hopefully that's ok, but you never know if we're actually
4044 * right... (especially since Windows XP doesn't seem to show
4045 * actual Tx dBm values :-P) */
4047 /* NOTE: on Maxim, value 30 IS 30mW, and value 10 IS 10mW - so the
4048 * values are EXACTLY mW!!! Not sure about RFMD and others,
4049 * though... */
4050 static const u8 dbm2val_maxim[21] = {
4051 63, 63, 63, 62,
4052 61, 61, 60, 60,
4053 59, 58, 57, 55,
4054 53, 50, 47, 43,
4055 38, 31, 23, 13,
4058 static const u8 dbm2val_rfmd[21] = {
4059 0, 0, 0, 1,
4060 2, 2, 3, 3,
4061 4, 5, 6, 8,
4062 10, 13, 16, 20,
4063 25, 32, 41, 50,
4066 const u8 *table;
4068 switch (adev->radio_type) {
4069 case RADIO_MAXIM_0D:
4070 table = &dbm2val_maxim[0];
4071 break;
4072 case RADIO_RFMD_11:
4073 case RADIO_RALINK_15:
4074 table = &dbm2val_rfmd[0];
4075 break;
4076 default:
4077 printk("%s: unknown/unsupported radio type, "
4078 "cannot modify tx power level yet!\n", wiphy_name(adev->ieee->wiphy));
4079 return NOT_OK;
4081 printk("%s: changing radio power level to %u dBm (%u)\n",
4082 wiphy_name(adev->ieee->wiphy), level_dbm, table[level_dbm]);
4083 acxpci_s_write_phy_reg(adev, 0x11, table[level_dbm]);
4084 return OK;
4087 #ifdef CONFIG_VLYNQ
4088 struct vlynq_reg_config {
4089 u32 offset;
4090 u32 value;
4093 struct vlynq_known {
4094 u32 chip_id;
4095 char name[32];
4096 struct vlynq_mapping rx_mapping[4];
4097 int irq;
4098 int irq_type;
4099 int num_regs;
4100 struct vlynq_reg_config regs[10];
4103 #define CHIP_TNETW1130 0x00000009
4104 #define CHIP_TNETW1350 0x00000029
4106 static struct vlynq_known known_devices[] = {
4108 .chip_id = CHIP_TNETW1130, .name = "TI TNETW1130",
4109 .rx_mapping = {
4110 { .size = 0x22000, .offset = 0xf0000000 },
4111 { .size = 0x40000, .offset = 0xc0000000 },
4112 { .size = 0x0, .offset = 0x0 },
4113 { .size = 0x0, .offset = 0x0 },
4115 .irq = 0,
4116 .irq_type = IRQ_TYPE_EDGE_RISING,
4117 .num_regs = 5,
4118 .regs = {
4120 .offset = 0x790,
4121 .value = (0xd0000000 - PHYS_OFFSET)
4124 .offset = 0x794,
4125 .value = (0xd0000000 - PHYS_OFFSET)
4127 { .offset = 0x740, .value = 0 },
4128 { .offset = 0x744, .value = 0x00010000 },
4129 { .offset = 0x764, .value = 0x00010000 },
4133 .chip_id = CHIP_TNETW1350, .name = "TI TNETW1350",
4134 .rx_mapping = {
4135 { .size = 0x100000, .offset = 0x00300000 },
4136 { .size = 0x80000, .offset = 0x00000000 },
4137 { .size = 0x0, .offset = 0x0 },
4138 { .size = 0x0, .offset = 0x0 },
4140 .irq = 0,
4141 .irq_type = IRQ_TYPE_EDGE_RISING,
4142 .num_regs = 5,
4143 .regs = {
4145 .offset = 0x790,
4146 .value = (0x60000000 - PHYS_OFFSET)
4149 .offset = 0x794,
4150 .value = (0x60000000 - PHYS_OFFSET)
4152 { .offset = 0x740, .value = 0 },
4153 { .offset = 0x744, .value = 0x00010000 },
4154 { .offset = 0x764, .value = 0x00010000 },
4159 static struct vlynq_device_id acx_vlynq_id[] = {
4160 { CHIP_TNETW1130, vlynq_div_auto, 0 },
4161 { CHIP_TNETW1350, vlynq_div_auto, 1 },
4162 { 0, 0, 0 },
4165 static __devinit int vlynq_probe(struct vlynq_device *vdev,
4166 struct vlynq_device_id *id)
4168 int result = -EIO, i;
4169 u32 addr;
4170 struct ieee80211_hw *ieee;
4171 acx_device_t *adev = NULL;
4172 acx111_ie_configoption_t co;
4173 struct vlynq_mapping mapping[4] = { { 0, }, };
4174 struct vlynq_known *match = NULL;
4176 FN_ENTER;
4177 result = vlynq_enable_device(vdev);
4178 if (result)
4179 return result;
4181 match = &known_devices[id->driver_data];
4183 if (!match) {
4184 result = -ENODEV;
4185 goto fail;
4188 mapping[0].offset = ARCH_PFN_OFFSET << PAGE_SHIFT;
4189 mapping[0].size = 0x02000000;
4190 vlynq_set_local_mapping(vdev, vdev->mem_start, mapping);
4191 vlynq_set_remote_mapping(vdev, 0, match->rx_mapping);
4193 set_irq_type(vlynq_virq_to_irq(vdev, match->irq), match->irq_type);
4195 addr = (u32)ioremap(vdev->mem_start, 0x1000);
4196 if (!addr) {
4197 printk(KERN_ERR "%s: failed to remap io memory\n",
4198 vdev->dev.bus_id);
4199 result = -ENXIO;
4200 goto fail;
4203 for (i = 0; i < match->num_regs; i++)
4204 iowrite32(match->regs[i].value,
4205 (u32 *)(addr + match->regs[i].offset));
4207 iounmap((void *)addr);
4209 ieee = ieee80211_alloc_hw(sizeof(struct acx_device), &acxpci_hw_ops);
4210 if (!ieee) {
4211 printk("acx: could not allocate ieee80211 structure %s\n",
4212 vdev->dev.bus_id);
4213 goto fail_alloc_netdev;
4215 ieee->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
4216 ieee->queues = 1;
4218 adev = ieee2adev(ieee);
4220 memset(adev, 0, sizeof(*adev));
4221 /** Set up our private interface **/
4222 spin_lock_init(&adev->lock); /* initial state: unlocked */
4223 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
4224 mutex_init(&adev->mutex);
4225 /* since nobody can see new netdev yet, we can as well
4226 ** just _presume_ that we're under sem (instead of actually taking it): */
4227 /* acx_sem_lock(adev); */
4228 adev->ieee = ieee;
4229 adev->vdev = vdev;
4230 adev->bus_dev = &vdev->dev;
4231 adev->dev_type = DEVTYPE_PCI;
4233 /** Finished with private interface **/
4235 vlynq_set_drvdata(vdev, ieee);
4236 if (!request_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start, "acx")) {
4237 printk("acx: cannot reserve VLYNQ memory region\n");
4238 goto fail_request_mem_region;
4240 adev->iobase = ioremap(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4241 if (!adev->iobase) {
4242 printk("acx: ioremap() FAILED\n");
4243 goto fail_ioremap;
4245 adev->iobase2 = adev->iobase + match->rx_mapping[0].size;
4246 adev->chip_type = CHIPTYPE_ACX111;
4247 adev->chip_name = match->name;
4248 adev->io = IO_ACX111;
4249 adev->irq = vlynq_virq_to_irq(vdev, match->irq);
4251 printk("acx: found %s-based wireless network card at %s, irq:%d, "
4252 "phymem:0x%x, mem:0x%p\n",
4253 match->name, vdev->dev.bus_id, adev->irq,
4254 vdev->mem_start, adev->iobase);
4255 log(L_ANY, "initial debug setting is 0x%04X\n", acx_debug);
4257 if (0 == adev->irq) {
4258 printk("acx: can't use IRQ 0\n");
4259 goto fail_irq;
4261 SET_IEEE80211_DEV(ieee, &vdev->dev);
4264 /* to find crashes due to weird driver access
4265 * to unconfigured interface (ifup) */
4266 adev->mgmt_timer.function = (void (*)(unsigned long))0x0000dead;
4269 /* ok, pci setup is finished, now start initializing the card */
4271 /* NB: read_reg() reads may return bogus data before reset_dev(),
4272 * since the firmware which directly controls large parts of the I/O
4273 * registers isn't initialized yet.
4274 * acx100 seems to be more affected than acx111 */
4275 if (OK != acxpci_s_reset_dev(adev))
4276 goto fail_reset;
4278 if (OK != acx_s_init_mac(adev))
4279 goto fail_init_mac;
4281 acx_s_interrogate(adev, &co, ACX111_IE_CONFIG_OPTIONS);
4282 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
4283 if (OK != acxpci_read_eeprom_byte(adev, 0x05, &adev->eeprom_version))
4284 goto fail_read_eeprom_version;
4286 acx_s_parse_configoption(adev, &co);
4287 acx_s_set_defaults(adev);
4288 acx_s_get_firmware_version(adev); /* needs to be after acx_s_init_mac() */
4289 acx_display_hardware_details(adev);
4291 /* Register the card, AFTER everything else has been set up,
4292 * since otherwise an ioctl could step on our feet due to
4293 * firmware operations happening in parallel or uninitialized data */
4296 acx_proc_register_entries(ieee);
4298 /* Now we have our device, so make sure the kernel doesn't try
4299 * to send packets even though we're not associated to a network yet */
4301 /* after register_netdev() userspace may start working with dev
4302 * (in particular, on other CPUs), we only need to up the sem */
4303 /* acx_sem_unlock(adev); */
4305 printk("acx " ACX_RELEASE ": net device %s, driver compiled "
4306 "against wireless extensions %d and Linux %s\n",
4307 wiphy_name(adev->ieee->wiphy), WIRELESS_EXT, UTS_RELEASE);
4309 MAC_COPY(adev->ieee->wiphy->perm_addr, adev->dev_addr);
4311 log(L_IRQ | L_INIT, "using IRQ %d\n", adev->irq);
4313 /** done with board specific setup **/
4315 acx_init_task_scheduler(adev);
4316 result = ieee80211_register_hw(adev->ieee);
4317 if (OK != result) {
4318 printk("acx: ieee80211_register_hw() FAILED: %d\n", result);
4319 goto fail_register_netdev;
4321 #if CMD_DISCOVERY
4322 great_inquisitor(adev);
4323 #endif
4325 result = OK;
4326 goto done;
4328 /* error paths: undo everything in reverse order... */
4331 acxpci_s_delete_dma_regions(adev);
4333 fail_init_mac:
4334 fail_read_eeprom_version:
4335 fail_reset:
4337 fail_alloc_netdev:
4338 fail_irq:
4340 iounmap(adev->iobase);
4341 fail_ioremap:
4343 release_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4344 fail_request_mem_region:
4345 fail_register_netdev:
4346 ieee80211_free_hw(ieee);
4347 fail:
4348 vlynq_disable_device(vdev);
4349 done:
4350 FN_EXIT1(result);
4351 return result;
4354 static void vlynq_remove(struct vlynq_device *vdev)
4356 struct ieee80211_hw *hw = vlynq_get_drvdata(vdev);
4357 acx_device_t *adev = ieee2adev(hw);
4358 unsigned long flags;
4359 FN_ENTER;
4361 if (!hw) {
4362 log(L_DEBUG, "%s: card is unused. Skipping any release code\n",
4363 __func__);
4364 goto end;
4368 acx_lock(adev, flags);
4369 acx_unlock(adev, flags);
4370 adev->initialized = 0;
4372 /* If device wasn't hot unplugged... */
4373 if (adev_present(adev)) {
4375 acx_sem_lock(adev);
4377 /* disable both Tx and Rx to shut radio down properly */
4378 if (adev->initialized) {
4379 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_TX, NULL, 0);
4380 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_RX, NULL, 0);
4382 acx_lock(adev, flags);
4383 /* disable power LED to save power :-) */
4384 log(L_INIT, "switching off power LED to save power\n");
4385 acxpci_l_power_led(adev, 0);
4386 /* stop our eCPU */
4387 acx_unlock(adev, flags);
4389 acx_sem_unlock(adev);
4392 /* unregister the device to not let the kernel
4393 * (e.g. ioctls) access a half-deconfigured device
4394 * NB: this will cause acxpci_e_close() to be called,
4395 * thus we shouldn't call it under sem!
4396 * Well, netdev did, but ieee80211 stack does not, so we
4397 * have to do so manually...
4399 acxpci_e_close(hw);
4400 log(L_INIT, "removing device %s\n", wiphy_name(adev->ieee->wiphy));
4401 ieee80211_unregister_hw(adev->ieee);
4403 /* unregister_netdev ensures that no references to us left.
4404 * For paranoid reasons we continue to follow the rules */
4405 acx_sem_lock(adev);
4407 if (adev->dev_state_mask & ACX_STATE_IFACE_UP) {
4408 acxpci_s_down(hw);
4409 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
4412 acx_proc_unregister_entries(adev->ieee);
4414 /* finally, clean up PCI bus state */
4415 acxpci_s_delete_dma_regions(adev);
4416 if (adev->iobase)
4417 iounmap(adev->iobase);
4418 if (adev->iobase2)
4419 iounmap(adev->iobase2);
4420 release_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4422 /* remove dev registration */
4424 acx_sem_unlock(adev);
4425 vlynq_disable_device(vdev);
4427 /* Free netdev (quite late,
4428 * since otherwise we might get caught off-guard
4429 * by a netdev timeout handler execution
4430 * expecting to see a working dev...) */
4431 ieee80211_free_hw(adev->ieee);
4433 end:
4434 FN_EXIT0;
4437 static struct vlynq_driver vlynq_acx = {
4438 .name = "acx_vlynq",
4439 .id_table = acx_vlynq_id,
4440 .probe = vlynq_probe,
4441 .remove = __devexit_p(vlynq_remove),
4443 #endif /* CONFIG_VLYNQ */
4446 /***********************************************************************
4447 ** Data for init_module/cleanup_module
4449 #ifdef CONFIG_PCI
4450 static const struct pci_device_id acxpci_id_tbl[] __devinitdata = {
4452 .vendor = PCI_VENDOR_ID_TI,
4453 .device = PCI_DEVICE_ID_TI_TNETW1100A,
4454 .subvendor = PCI_ANY_ID,
4455 .subdevice = PCI_ANY_ID,
4456 .driver_data = CHIPTYPE_ACX100,
4459 .vendor = PCI_VENDOR_ID_TI,
4460 .device = PCI_DEVICE_ID_TI_TNETW1100B,
4461 .subvendor = PCI_ANY_ID,
4462 .subdevice = PCI_ANY_ID,
4463 .driver_data = CHIPTYPE_ACX100,
4466 .vendor = PCI_VENDOR_ID_TI,
4467 .device = PCI_DEVICE_ID_TI_TNETW1130,
4468 .subvendor = PCI_ANY_ID,
4469 .subdevice = PCI_ANY_ID,
4470 .driver_data = CHIPTYPE_ACX111,
4473 .vendor = 0,
4474 .device = 0,
4475 .subvendor = 0,
4476 .subdevice = 0,
4477 .driver_data = 0,
4481 MODULE_DEVICE_TABLE(pci, acxpci_id_tbl);
4483 /* FIXME: checks should be removed once driver is included in the kernel */
4484 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 11)
4485 /* pci_name() got introduced at start of 2.6.x,
4486 * got mandatory (slot_name member removed) in 2.6.11-bk1 */
4487 #define pci_name(x) x->slot_name
4488 #endif
4490 static struct pci_driver
4491 acxpci_drv_id = {
4492 .name = "acx_pci",
4493 .id_table = acxpci_id_tbl,
4494 .probe = acxpci_e_probe,
4495 .remove = __devexit_p(acxpci_e_remove),
4496 #ifdef CONFIG_PM
4497 .suspend = acxpci_e_suspend,
4498 .resume = acxpci_e_resume
4499 #endif /* CONFIG_PM */
4501 #endif /* CONFIG_PCI */
4503 /***********************************************************************
4504 ** acxpci_e_init_module
4506 ** Module initialization routine, called once at module load time
4508 int __init acxpci_e_init_module(void)
4510 int res;
4512 FN_ENTER;
4514 #if (ACX_IO_WIDTH==32)
4515 printk("acx: compiled to use 32bit I/O access. "
4516 "I/O timing issues might occur, such as "
4517 "non-working firmware upload. Report them\n");
4518 #else
4519 printk("acx: compiled to use 16bit I/O access only "
4520 "(compatibility mode)\n");
4521 #endif
4523 #ifdef __LITTLE_ENDIAN
4524 #define ENDIANNESS_STRING "running on a little-endian CPU\n"
4525 #else
4526 #define ENDIANNESS_STRING "running on a BIG-ENDIAN CPU\n"
4527 #endif
4528 log(L_INIT,
4529 "acx: " ENDIANNESS_STRING
4530 "acx: PCI/VLYNQ module " ACX_RELEASE " initialized, "
4531 "waiting for cards to probe...\n");
4533 #ifdef CONFIG_PCI
4534 res = pci_register_driver(&acxpci_drv_id);
4535 #endif
4536 #ifdef CONFIG_VLYNQ
4537 res = vlynq_register_driver(&vlynq_acx);
4538 #endif
4539 FN_EXIT1(res);
4540 return res;
4544 /***********************************************************************
4545 ** acxpci_e_cleanup_module
4547 ** Called at module unload time. This is our last chance to
4548 ** clean up after ourselves.
4550 void __exit acxpci_e_cleanup_module(void)
4552 FN_ENTER;
4554 #ifdef CONFIG_PCI
4555 pci_unregister_driver(&acxpci_drv_id);
4556 #endif
4557 #ifdef CONFIG_VLYNQ
4558 vlynq_unregister_driver(&vlynq_acx);
4559 #endif
4560 log(L_INIT,
4561 "acx: PCI module " ACX_RELEASE " unloaded\n");
4562 FN_EXIT0;