again some little changes (diff between my and matteo's code)
[acx-mac80211.git] / pci.c
blob7824146065ef905494801bab3cb5f70784e7bea4
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->pdev->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->pdev->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->pdev->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 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;
1042 devname = wiphy_name(adev->ieee->wiphy);
1043 if (!devname || !devname[0] || devname[4] == '%')
1044 devname = "acx";
1046 log(L_CTL, FUNC "(cmd:%s,buflen:%u,timeout:%ums,type:0x%04X)\n",
1047 cmdstr, buflen, cmd_timeout,
1048 buffer ? le16_to_cpu(((acx_ie_generic_t *) buffer)->type) : -1);
1050 if (!(adev->dev_state_mask & ACX_STATE_FW_LOADED)) {
1051 printk("%s: " FUNC "(): firmware is not loaded yet, "
1052 "cannot execute commands!\n", devname);
1053 goto bad;
1056 if ((acx_debug & L_DEBUG) && (cmd != ACX1xx_CMD_INTERROGATE)) {
1057 printk("input buffer (len=%u):\n", buflen);
1058 acx_dump_bytes(buffer, buflen);
1061 /* wait for firmware to become idle for our command submission */
1062 timeout = HZ / 5;
1063 counter = (timeout * 1000 / HZ) - 1; /* in ms */
1064 timeout += jiffies;
1065 do {
1066 cmd_status = acxpci_read_cmd_type_status(adev);
1067 /* Test for IDLE state */
1068 if (!cmd_status)
1069 break;
1070 if (counter % 8 == 0) {
1071 if (time_after(jiffies, timeout)) {
1072 counter = 0;
1073 break;
1075 /* we waited 8 iterations, no luck. Sleep 8 ms */
1076 acx_s_mwait(8);
1078 } while (likely(--counter));
1080 if (!counter) {
1081 /* the card doesn't get idle, we're in trouble */
1082 printk("%s: " FUNC "(): cmd_status is not IDLE: 0x%04X!=0\n",
1083 devname, cmd_status);
1084 goto bad;
1085 } else if (counter < 190) { /* if waited >10ms... */
1086 log(L_CTL | L_DEBUG, FUNC "(): waited for IDLE %dms. "
1087 "Please report\n", 199 - counter);
1090 /* now write the parameters of the command if needed */
1091 if (buffer && buflen) {
1092 /* if it's an INTERROGATE command, just pass the length
1093 * of parameters to read, as data */
1094 #if CMD_DISCOVERY
1095 if (cmd == ACX1xx_CMD_INTERROGATE)
1096 memset_io(adev->cmd_area + 4, 0xAA, buflen);
1097 #endif
1098 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1099 memcpy_toio(adev->cmd_area + 4, buffer,
1100 (cmd == ACX1xx_CMD_INTERROGATE) ? 4 : buflen);
1102 /* now write the actual command type */
1103 acxpci_write_cmd_type_status(adev, cmd, 0);
1104 /* execute command */
1105 write_reg16(adev, IO_ACX_INT_TRIG, INT_TRIG_CMD);
1106 write_flush(adev);
1108 /* wait for firmware to process command */
1110 /* Ensure nonzero and not too large timeout.
1111 ** Also converts e.g. 100->99, 200->199
1112 ** which is nice but not essential */
1113 cmd_timeout = (cmd_timeout - 1) | 1;
1114 if (unlikely(cmd_timeout > 1199))
1115 cmd_timeout = 1199;
1116 /* clear CMD_COMPLETE bit. can be set only by IRQ handler: */
1117 adev->irq_status &= ~HOST_INT_CMD_COMPLETE;
1119 /* we schedule away sometimes (timeout can be large) */
1120 counter = cmd_timeout;
1121 timeout = jiffies + cmd_timeout * HZ / 1000;
1122 do {
1123 if (!adev->irqs_active) { /* IRQ disabled: poll */
1124 irqtype = read_reg16(adev, IO_ACX_IRQ_STATUS_NON_DES);
1125 if (irqtype & HOST_INT_CMD_COMPLETE) {
1126 write_reg16(adev, IO_ACX_IRQ_ACK,
1127 HOST_INT_CMD_COMPLETE);
1128 break;
1130 } else { /* Wait when IRQ will set the bit */
1131 irqtype = adev->irq_status;
1132 if (irqtype & HOST_INT_CMD_COMPLETE)
1133 break;
1136 if (counter % 8 == 0) {
1137 if (time_after(jiffies, timeout)) {
1138 counter = 0;
1139 break;
1141 /* we waited 8 iterations, no luck. Sleep 8 ms */
1142 acx_s_mwait(8);
1144 } while (likely(--counter));
1146 /* save state for debugging */
1147 cmd_status = acxpci_read_cmd_type_status(adev);
1149 /* put the card in IDLE state */
1150 acxpci_write_cmd_type_status(adev, 0, 0);
1152 if ((cmd_timeout - counter) == 0) { /* timed out! */
1153 printk("%s: " FUNC "(): timed out %s for CMD_COMPLETE. "
1154 "irq bits:0x%04X irq_status:0x%04X timeout:%dms "
1155 "cmd_status:%d (%s)\n",
1156 devname, (adev->irqs_active) ? "waiting" : "polling",
1157 irqtype, adev->irq_status, cmd_timeout,
1158 cmd_status, acx_cmd_status_str(cmd_status));
1159 printk("hack: don't do: 'goto bad;'\ncounter: %d cmd_timeout: %d cmd_timeout-counter: %d\n",counter, cmd_timeout, cmd_timeout - counter);
1160 } else if (counter == 0) { /* maybe timed out! */
1161 log(L_CTL | L_DEBUG, FUNC "(): %s for CMD_COMPLETE %dms. "
1162 "count:%d. Please report\n",
1163 (adev->irqs_active) ? "waited" : "polled",
1164 cmd_timeout - counter, counter);
1165 } else if ((cmd_timeout - counter) > 30) { /* if waited >30ms... */
1166 log(L_CTL | L_DEBUG, FUNC "(): %s for CMD_COMPLETE %dms. "
1167 "count:%d. Please report\n",
1168 (adev->irqs_active) ? "waited" : "polled",
1169 cmd_timeout - counter, counter);
1172 if (1 != cmd_status) { /* it is not a 'Success' */
1173 printk("%s: " FUNC "(): cmd_status is not SUCCESS: %d (%s). "
1174 "Took %dms of %d\n",
1175 devname, cmd_status, acx_cmd_status_str(cmd_status),
1176 cmd_timeout - counter, cmd_timeout);
1177 /* zero out result buffer
1178 * WARNING: this will trash stack in case of illegally large input
1179 * length! */
1180 if (buffer && buflen)
1181 memset(buffer, 0, buflen);
1182 goto bad;
1185 /* read in result parameters if needed */
1186 if (buffer && buflen && (cmd == ACX1xx_CMD_INTERROGATE)) {
1187 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1188 memcpy_fromio(buffer, adev->cmd_area + 4, buflen);
1189 if (acx_debug & L_DEBUG) {
1190 printk("output buffer (len=%u): ", buflen);
1191 acx_dump_bytes(buffer, buflen);
1194 /* ok: */
1195 log(L_CTL, FUNC "(%s): took %ld jiffies to complete\n",
1196 cmdstr, jiffies - start);
1197 FN_EXIT1(OK);
1198 return OK;
1200 bad:
1201 /* Give enough info so that callers can avoid
1202 ** printing their own diagnostic messages */
1203 #if ACX_DEBUG
1204 printk("%s: " FUNC "(cmd:%s) FAILED\n", devname, cmdstr);
1205 #else
1206 printk("%s: " FUNC "(cmd:0x%04X) FAILED\n", devname, cmd);
1207 #endif
1208 dump_stack();
1209 FN_EXIT1(NOT_OK);
1210 return NOT_OK;
1214 /***********************************************************************
1216 #ifdef NONESSENTIAL_FEATURES
1217 typedef struct device_id {
1218 unsigned char id[6];
1219 char *descr;
1220 char *type;
1221 } device_id_t;
1223 static const device_id_t device_ids[] = {
1225 {'G', 'l', 'o', 'b', 'a', 'l'},
1226 NULL,
1227 NULL,
1230 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
1231 "uninitialized",
1232 "SpeedStream SS1021 or Gigafast WF721-AEX"},
1234 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85},
1235 "non-standard",
1236 "DrayTek Vigor 520"},
1238 {'?', '?', '?', '?', '?', '?'},
1239 "non-standard",
1240 "Level One WPC-0200"},
1242 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1243 "empty",
1244 "DWL-650+ variant"}
1247 static void acx_show_card_eeprom_id(acx_device_t * adev)
1249 unsigned char buffer[CARD_EEPROM_ID_SIZE];
1250 int i;
1252 FN_ENTER;
1254 memset(&buffer, 0, CARD_EEPROM_ID_SIZE);
1255 /* use direct EEPROM access */
1256 for (i = 0; i < CARD_EEPROM_ID_SIZE; i++) {
1257 if (OK != acxpci_read_eeprom_byte(adev,
1258 ACX100_EEPROM_ID_OFFSET + i,
1259 &buffer[i])) {
1260 printk("acx: reading EEPROM FAILED\n");
1261 break;
1265 for (i = 0; i < ARRAY_SIZE(device_ids); i++) {
1266 if (!memcmp(&buffer, device_ids[i].id, CARD_EEPROM_ID_SIZE)) {
1267 if (device_ids[i].descr) {
1268 printk("acx: EEPROM card ID string check "
1269 "found %s card ID: is this %s?\n",
1270 device_ids[i].descr, device_ids[i].type);
1272 break;
1275 if (i == ARRAY_SIZE(device_ids)) {
1276 printk("acx: EEPROM card ID string check found "
1277 "unknown card: expected 'Global', got '%.*s\'. "
1278 "Please report\n", CARD_EEPROM_ID_SIZE, buffer);
1280 FN_EXIT0;
1282 #endif /* NONESSENTIAL_FEATURES */
1285 /***********************************************************************
1286 ** acxpci_free_desc_queues
1288 ** Releases the queues that have been allocated, the
1289 ** others have been initialised to NULL so this
1290 ** function can be used if only part of the queues were allocated.
1293 static inline void
1294 free_coherent(struct pci_dev *hwdev, size_t size,
1295 void *vaddr, dma_addr_t dma_handle)
1297 dma_free_coherent(hwdev == NULL ? NULL : &hwdev->dev,
1298 size, vaddr, dma_handle);
1302 void acxpci_free_desc_queues(acx_device_t * adev)
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 adev->txdesc_start = NULL;
1320 ACX_FREE_QUEUE(adev->rxhostdesc_area_size, adev->rxhostdesc_start,
1321 adev->rxhostdesc_startphy);
1322 ACX_FREE_QUEUE(adev->rxbuf_area_size, adev->rxbuf_start,
1323 adev->rxbuf_startphy);
1325 adev->rxdesc_start = NULL;
1327 FN_EXIT0;
1331 /***********************************************************************
1332 ** acxpci_s_delete_dma_regions
1334 static void acxpci_s_delete_dma_regions(acx_device_t * adev)
1336 unsigned long flags;
1338 FN_ENTER;
1339 /* disable radio Tx/Rx. Shouldn't we use the firmware commands
1340 * here instead? Or are we that much down the road that it's no
1341 * longer possible here? */
1342 write_reg16(adev, IO_ACX_ENABLE, 0);
1344 acx_s_mwait(100);
1346 acx_lock(adev, flags);
1347 acxpci_free_desc_queues(adev);
1348 acx_unlock(adev, flags);
1350 FN_EXIT0;
1354 /***********************************************************************
1355 ** acxpci_e_probe
1357 ** Probe routine called when a PCI device w/ matching ID is found.
1358 ** Here's the sequence:
1359 ** - Allocate the PCI resources.
1360 ** - Read the PCMCIA attribute memory to make sure we have a WLAN card
1361 ** - Reset the MAC
1362 ** - Initialize the dev and wlan data
1363 ** - Initialize the MAC
1365 ** pdev - ptr to pci device structure containing info about pci configuration
1366 ** id - ptr to the device id entry that matched this device
1368 static const u16 IO_ACX100[] = {
1369 0x0000, /* IO_ACX_SOFT_RESET */
1371 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1372 0x0018, /* IO_ACX_SLV_MEM_DATA */
1373 0x001c, /* IO_ACX_SLV_MEM_CTL */
1374 0x0020, /* IO_ACX_SLV_END_CTL */
1376 0x0034, /* IO_ACX_FEMR */
1378 0x007c, /* IO_ACX_INT_TRIG */
1379 0x0098, /* IO_ACX_IRQ_MASK */
1380 0x00a4, /* IO_ACX_IRQ_STATUS_NON_DES */
1381 0x00a8, /* IO_ACX_IRQ_STATUS_CLEAR */
1382 0x00ac, /* IO_ACX_IRQ_ACK */
1383 0x00b0, /* IO_ACX_HINT_TRIG */
1385 0x0104, /* IO_ACX_ENABLE */
1387 0x0250, /* IO_ACX_EEPROM_CTL */
1388 0x0254, /* IO_ACX_EEPROM_ADDR */
1389 0x0258, /* IO_ACX_EEPROM_DATA */
1390 0x025c, /* IO_ACX_EEPROM_CFG */
1392 0x0268, /* IO_ACX_PHY_ADDR */
1393 0x026c, /* IO_ACX_PHY_DATA */
1394 0x0270, /* IO_ACX_PHY_CTL */
1396 0x0290, /* IO_ACX_GPIO_OE */
1398 0x0298, /* IO_ACX_GPIO_OUT */
1400 0x02a4, /* IO_ACX_CMD_MAILBOX_OFFS */
1401 0x02a8, /* IO_ACX_INFO_MAILBOX_OFFS */
1402 0x02ac, /* IO_ACX_EEPROM_INFORMATION */
1404 0x02d0, /* IO_ACX_EE_START */
1405 0x02d4, /* IO_ACX_SOR_CFG */
1406 0x02d8 /* IO_ACX_ECPU_CTRL */
1409 static const u16 IO_ACX111[] = {
1410 0x0000, /* IO_ACX_SOFT_RESET */
1412 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1413 0x0018, /* IO_ACX_SLV_MEM_DATA */
1414 0x001c, /* IO_ACX_SLV_MEM_CTL */
1415 0x0020, /* IO_ACX_SLV_END_CTL */
1417 0x0034, /* IO_ACX_FEMR */
1419 0x00b4, /* IO_ACX_INT_TRIG */
1420 0x00d4, /* IO_ACX_IRQ_MASK */
1421 /* we do mean NON_DES (0xf0), not NON_DES_MASK which is at 0xe0: */
1422 0x00f0, /* IO_ACX_IRQ_STATUS_NON_DES */
1423 0x00e4, /* IO_ACX_IRQ_STATUS_CLEAR */
1424 0x00e8, /* IO_ACX_IRQ_ACK */
1425 0x00ec, /* IO_ACX_HINT_TRIG */
1427 0x01d0, /* IO_ACX_ENABLE */
1429 0x0338, /* IO_ACX_EEPROM_CTL */
1430 0x033c, /* IO_ACX_EEPROM_ADDR */
1431 0x0340, /* IO_ACX_EEPROM_DATA */
1432 0x0344, /* IO_ACX_EEPROM_CFG */
1434 0x0350, /* IO_ACX_PHY_ADDR */
1435 0x0354, /* IO_ACX_PHY_DATA */
1436 0x0358, /* IO_ACX_PHY_CTL */
1438 0x0374, /* IO_ACX_GPIO_OE */
1440 0x037c, /* IO_ACX_GPIO_OUT */
1442 0x0388, /* IO_ACX_CMD_MAILBOX_OFFS */
1443 0x038c, /* IO_ACX_INFO_MAILBOX_OFFS */
1444 0x0390, /* IO_ACX_EEPROM_INFORMATION */
1446 0x0100, /* IO_ACX_EE_START */
1447 0x0104, /* IO_ACX_SOR_CFG */
1448 0x0108, /* IO_ACX_ECPU_CTRL */
1451 static const struct ieee80211_ops acxpci_hw_ops = {
1452 .tx = acx_i_start_xmit,
1453 .conf_tx = acx_net_conf_tx,
1454 .add_interface = acx_add_interface,
1455 .remove_interface = acx_remove_interface,
1456 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
1457 .open = acxpci_e_open,
1458 .reset = acx_net_reset,
1459 .set_multicast_list = acx_i_set_multicast_list,
1460 #else
1461 .start = acxpci_e_open,
1462 .configure_filter = acx_i_set_multicast_list,
1463 #endif
1464 .stop = acxpci_e_close,
1465 .config = acx_net_config,
1466 .config_interface = acx_config_interface,
1467 .set_key = acx_net_set_key,
1468 .get_stats = acx_e_get_stats,
1469 .get_tx_stats = acx_net_get_tx_stats,
1473 #ifdef CONFIG_PCI
1474 static int __devinit
1475 acxpci_e_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1477 acx111_ie_configoption_t co;
1478 unsigned long mem_region1 = 0;
1479 unsigned long mem_region2 = 0;
1480 unsigned long mem_region1_size;
1481 unsigned long mem_region2_size;
1482 unsigned long phymem1;
1483 unsigned long phymem2;
1484 void *mem1 = NULL;
1485 void *mem2 = NULL;
1486 acx_device_t *adev = NULL;
1487 const char *chip_name;
1488 int result = -EIO;
1489 int err;
1490 u8 chip_type;
1491 struct ieee80211_hw *ieee;
1493 FN_ENTER;
1495 ieee = ieee80211_alloc_hw(sizeof(struct acx_device), &acxpci_hw_ops);
1496 if (!ieee) {
1497 printk("acx: could not allocate ieee80211 structure %s\n",
1498 pci_name(pdev));
1499 goto fail_alloc_netdev;
1501 ieee->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
1502 /* TODO: mainline doesn't support the following flags yet */
1504 ~IEEE80211_HW_MONITOR_DURING_OPER &
1505 ~IEEE80211_HW_WEP_INCLUDE_IV;
1507 ieee->queues = 1;
1509 /* (NB: memsets to 0 entire area) */
1510 if (!ieee) {
1511 printk("acx: could not allocate ieee structure %s\n",
1512 pci_name(pdev));
1513 goto fail_alloc_netdev;
1516 adev = ieee2adev(ieee);
1518 memset(adev, 0, sizeof(*adev));
1519 /** Set up our private interface **/
1520 spin_lock_init(&adev->lock); /* initial state: unlocked */
1521 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
1522 printk("mutex_init(&adev->mutex); // adev = 0x%px\n", adev);
1523 mutex_init(&adev->mutex);
1524 /* since nobody can see new netdev yet, we can as well
1525 ** just _presume_ that we're under sem (instead of actually taking it): */
1526 /* acx_sem_lock(adev); */
1527 adev->ieee = ieee;
1528 adev->pdev = pdev;
1529 adev->bus_dev = &pdev->dev;
1530 adev->dev_type = DEVTYPE_PCI;
1532 /** Finished with private interface **/
1534 /** begin board specific inits **/
1535 pci_set_drvdata(pdev, ieee);
1537 /* Enable the PCI device */
1538 if (pci_enable_device(pdev)) {
1539 printk("acx: pci_enable_device() FAILED\n");
1540 result = -ENODEV;
1541 goto fail_pci_enable_device;
1544 /* enable busmastering (required for CardBus) */
1545 pci_set_master(pdev);
1548 /* chiptype is u8 but id->driver_data is ulong
1549 ** Works for now (possible values are 1 and 2) */
1550 chip_type = (u8) id->driver_data;
1551 /* acx100 and acx111 have different PCI memory regions */
1552 if (chip_type == CHIPTYPE_ACX100) {
1553 chip_name = "ACX100";
1554 mem_region1 = PCI_ACX100_REGION1;
1555 mem_region1_size = PCI_ACX100_REGION1_SIZE;
1557 mem_region2 = PCI_ACX100_REGION2;
1558 mem_region2_size = PCI_ACX100_REGION2_SIZE;
1559 } else if (chip_type == CHIPTYPE_ACX111) {
1560 chip_name = "ACX111";
1561 mem_region1 = PCI_ACX111_REGION1;
1562 mem_region1_size = PCI_ACX111_REGION1_SIZE;
1564 mem_region2 = PCI_ACX111_REGION2;
1565 mem_region2_size = PCI_ACX111_REGION2_SIZE;
1566 } else {
1567 printk("acx: unknown chip type 0x%04X\n", chip_type);
1568 goto fail_unknown_chiptype;
1571 /* Figure out our resources */
1572 phymem1 = pci_resource_start(pdev, mem_region1);
1573 phymem2 = pci_resource_start(pdev, mem_region2);
1574 if (!request_mem_region
1575 (phymem1, pci_resource_len(pdev, mem_region1), "acx_1")) {
1576 printk("acx: cannot reserve PCI memory region 1 (are you sure "
1577 "you have CardBus support in kernel?)\n");
1578 goto fail_request_mem_region1;
1580 if (!request_mem_region
1581 (phymem2, pci_resource_len(pdev, mem_region2), "acx_2")) {
1582 printk("acx: cannot reserve PCI memory region 2\n");
1583 goto fail_request_mem_region2;
1585 /* this used to be ioremap(), but ioremap_nocache()
1586 * is much less risky, right? (and slower?)
1587 * FIXME: we may want to go back to cached variant if it's
1588 * certain that our code really properly handles
1589 * cached operation (memory barriers, volatile?, ...)
1590 * (but always keep this comment here regardless!)
1591 * Possibly make this a driver config setting?
1594 mem1 = ioremap_nocache(phymem1, mem_region1_size);
1595 if (!mem1) {
1596 printk("acx: ioremap() FAILED\n");
1597 goto fail_ioremap1;
1599 mem2 = ioremap_nocache(phymem2, mem_region2_size);
1600 if (!mem2) {
1601 printk("acx: ioremap() #2 FAILED\n");
1602 goto fail_ioremap2;
1605 printk("acx: found %s-based wireless network card at %s, irq:%d, "
1606 "phymem1:0x%lX, phymem2:0x%lX, mem1:0x%p, mem1_size:%ld, "
1607 "mem2:0x%p, mem2_size:%ld\n",
1608 chip_name, pci_name(pdev), pdev->irq, phymem1, phymem2,
1609 mem1, mem_region1_size, mem2, mem_region2_size);
1610 log(L_ANY, "initial debug setting is 0x%04X\n", acx_debug);
1611 adev->chip_type = chip_type;
1612 adev->chip_name = chip_name;
1613 adev->io = (CHIPTYPE_ACX100 == chip_type) ? IO_ACX100 : IO_ACX111;
1614 adev->membase = phymem1;
1615 adev->iobase = mem1;
1616 adev->membase2 = phymem2;
1617 adev->iobase2 = mem2;
1618 adev->irq = pdev->irq;
1621 if (0 == pdev->irq) {
1622 printk("acx: can't use IRQ 0\n");
1623 goto fail_irq;
1625 SET_IEEE80211_DEV(ieee, &pdev->dev);
1628 /* to find crashes due to weird driver access
1629 * to unconfigured interface (ifup) */
1630 adev->mgmt_timer.function = (void (*)(unsigned long))0x0000dead;
1633 #ifdef NONESSENTIAL_FEATURES
1634 acx_show_card_eeprom_id(adev);
1635 #endif /* NONESSENTIAL_FEATURES */
1638 /* ok, pci setup is finished, now start initializing the card */
1640 /* NB: read_reg() reads may return bogus data before reset_dev(),
1641 * since the firmware which directly controls large parts of the I/O
1642 * registers isn't initialized yet.
1643 * acx100 seems to be more affected than acx111 */
1644 if (OK != acxpci_s_reset_dev(adev))
1645 goto fail_reset;
1647 if (IS_ACX100(adev)) {
1648 /* ACX100: configopt struct in cmd mailbox - directly after reset */
1649 memcpy_fromio(&co, adev->cmd_area, sizeof(co));
1652 if (OK != acx_s_init_mac(adev))
1653 goto fail_init_mac;
1655 if (IS_ACX111(adev)) {
1656 /* ACX111: configopt struct needs to be queried after full init */
1657 acx_s_interrogate(adev, &co, ACX111_IE_CONFIG_OPTIONS);
1659 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
1660 if (OK != acxpci_read_eeprom_byte(adev, 0x05, &adev->eeprom_version))
1661 goto fail_read_eeprom_version;
1663 acx_s_parse_configoption(adev, &co);
1664 acx_s_set_defaults(adev);
1665 acx_s_get_firmware_version(adev); /* needs to be after acx_s_init_mac() */
1666 acx_display_hardware_details(adev);
1668 /* Register the card, AFTER everything else has been set up,
1669 * since otherwise an ioctl could step on our feet due to
1670 * firmware operations happening in parallel or uninitialized data */
1673 acx_proc_register_entries(ieee);
1675 /* Now we have our device, so make sure the kernel doesn't try
1676 * to send packets even though we're not associated to a network yet */
1678 /* after register_netdev() userspace may start working with dev
1679 * (in particular, on other CPUs), we only need to up the sem */
1680 /* acx_sem_unlock(adev); */
1682 printk("acx " ACX_RELEASE ": net device %s, driver compiled "
1683 "against wireless extensions %d and Linux %s\n",
1684 wiphy_name(adev->ieee->wiphy), WIRELESS_EXT, UTS_RELEASE);
1686 MAC_COPY(adev->ieee->wiphy->perm_addr, adev->dev_addr);
1688 log(L_IRQ | L_INIT, "using IRQ %d\n", pdev->irq);
1690 /** done with board specific setup **/
1692 /* need to be able to restore PCI state after a suspend */
1693 #ifdef CONFIG_PM
1694 pci_save_state(pdev);
1695 #endif
1698 acx_init_task_scheduler(adev);
1699 err = ieee80211_register_hw(adev->ieee);
1700 if (OK != err) {
1701 printk("acx: ieee80211_register_hw() FAILED: %d\n", err);
1702 goto fail_register_netdev;
1704 #if CMD_DISCOVERY
1705 great_inquisitor(adev);
1706 #endif
1708 result = OK;
1709 goto done;
1711 /* error paths: undo everything in reverse order... */
1714 acxpci_s_delete_dma_regions(adev);
1715 pci_set_drvdata(pdev, NULL);
1717 fail_init_mac:
1718 fail_read_eeprom_version:
1719 fail_reset:
1721 fail_alloc_netdev:
1722 fail_irq:
1724 iounmap(mem2);
1725 fail_ioremap2:
1727 iounmap(mem1);
1728 fail_ioremap1:
1730 release_mem_region(pci_resource_start(pdev, mem_region2),
1731 pci_resource_len(pdev, mem_region2));
1732 fail_request_mem_region2:
1734 release_mem_region(pci_resource_start(pdev, mem_region1),
1735 pci_resource_len(pdev, mem_region1));
1736 fail_request_mem_region1:
1737 fail_unknown_chiptype:
1739 pci_disable_device(pdev);
1740 fail_pci_enable_device:
1742 #ifdef CONFIG_PM
1743 pci_set_power_state(pdev, PCI_D3hot);
1744 #endif
1745 fail_register_netdev:
1746 ieee80211_free_hw(ieee);
1747 done:
1748 FN_EXIT1(result);
1749 return result;
1753 /***********************************************************************
1754 ** acxpci_e_remove
1756 ** Shut device down (if not hot unplugged)
1757 ** and deallocate PCI resources for the acx chip.
1759 ** pdev - ptr to PCI device structure containing info about pci configuration
1761 static void __devexit acxpci_e_remove(struct pci_dev *pdev)
1763 struct ieee80211_hw *hw = (struct ieee80211_hw *)pci_get_drvdata(pdev);
1764 acx_device_t *adev = ieee2adev(hw);
1765 unsigned long mem_region1, mem_region2;
1766 unsigned long flags;
1767 FN_ENTER;
1769 if (!hw) {
1770 log(L_DEBUG, "%s: card is unused. Skipping any release code\n",
1771 __func__);
1772 goto end;
1776 acx_lock(adev, flags);
1777 acx_unlock(adev, flags);
1778 adev->initialized = 0;
1780 /* If device wasn't hot unplugged... */
1781 if (adev_present(adev)) {
1783 acx_sem_lock(adev);
1785 /* disable both Tx and Rx to shut radio down properly */
1786 if (adev->initialized) {
1787 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_TX, NULL, 0);
1788 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_RX, NULL, 0);
1790 #ifdef REDUNDANT
1791 /* put the eCPU to sleep to save power
1792 * Halting is not possible currently,
1793 * since not supported by all firmware versions */
1794 acx_s_issue_cmd(adev, ACX100_CMD_SLEEP, NULL, 0);
1795 #endif
1796 acx_lock(adev, flags);
1797 /* disable power LED to save power :-) */
1798 log(L_INIT, "switching off power LED to save power\n");
1799 acxpci_l_power_led(adev, 0);
1800 /* stop our eCPU */
1801 if (IS_ACX111(adev)) {
1802 /* FIXME: does this actually keep halting the eCPU?
1803 * I don't think so...
1805 acxpci_l_reset_mac(adev);
1806 } else {
1807 u16 temp;
1808 /* halt eCPU */
1809 temp = read_reg16(adev, IO_ACX_ECPU_CTRL) | 0x1;
1810 write_reg16(adev, IO_ACX_ECPU_CTRL, temp);
1811 write_flush(adev);
1813 acx_unlock(adev, flags);
1815 acx_sem_unlock(adev);
1818 /* unregister the device to not let the kernel
1819 * (e.g. ioctls) access a half-deconfigured device
1820 * NB: this will cause acxpci_e_close() to be called,
1821 * thus we shouldn't call it under sem!
1822 * Well, netdev did, but ieee80211 stack does not, so we
1823 * have to do so manually...
1825 acxpci_e_close(hw);
1826 log(L_INIT, "removing device %s\n", wiphy_name(adev->ieee->wiphy));
1827 ieee80211_unregister_hw(adev->ieee);
1829 /* unregister_netdev ensures that no references to us left.
1830 * For paranoid reasons we continue to follow the rules */
1831 acx_sem_lock(adev);
1833 if (adev->dev_state_mask & ACX_STATE_IFACE_UP) {
1834 acxpci_s_down(hw);
1835 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
1838 acx_proc_unregister_entries(adev->ieee);
1840 if (IS_ACX100(adev)) {
1841 mem_region1 = PCI_ACX100_REGION1;
1842 mem_region2 = PCI_ACX100_REGION2;
1843 } else {
1844 mem_region1 = PCI_ACX111_REGION1;
1845 mem_region2 = PCI_ACX111_REGION2;
1848 /* finally, clean up PCI bus state */
1849 acxpci_s_delete_dma_regions(adev);
1850 if (adev->iobase)
1851 iounmap(adev->iobase);
1852 if (adev->iobase2)
1853 iounmap(adev->iobase2);
1854 release_mem_region(pci_resource_start(pdev, mem_region1),
1855 pci_resource_len(pdev, mem_region1));
1856 release_mem_region(pci_resource_start(pdev, mem_region2),
1857 pci_resource_len(pdev, mem_region2));
1858 pci_disable_device(pdev);
1860 /* remove dev registration */
1862 free_irq(adev->irq, adev);
1863 acx_sem_unlock(adev);
1865 /* Free netdev (quite late,
1866 * since otherwise we might get caught off-guard
1867 * by a netdev timeout handler execution
1868 * expecting to see a working dev...) */
1869 ieee80211_free_hw(adev->ieee);
1871 /* put device into ACPI D3 mode (shutdown) */
1872 #ifdef CONFIG_PM
1873 pci_set_power_state(pdev, PCI_D3hot);
1874 #endif
1875 end:
1876 FN_EXIT0;
1880 /***********************************************************************
1881 ** TODO: PM code needs to be fixed / debugged / tested.
1883 #ifdef CONFIG_PM
1884 static int
1885 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
1886 acxpci_e_suspend(struct pci_dev *pdev, pm_message_t state)
1887 #else
1888 acxpci_e_suspend(struct pci_dev *pdev, u32 state)
1889 #endif
1891 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1892 acx_device_t *adev;
1894 FN_ENTER;
1895 printk("acx: suspend handler is experimental!\n");
1896 printk("sus: dev %p\n", hw);
1898 /* if (!netif_running(ndev))
1899 goto end;
1901 adev = ieee2adev(hw);
1902 printk("sus: adev %p\n", adev);
1904 acx_sem_lock(adev);
1906 ieee80211_unregister_hw(hw); /* this one cannot sleep */
1907 acxpci_s_down(hw);
1908 /* down() does not set it to 0xffff, but here we really want that */
1909 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
1910 write_reg16(adev, IO_ACX_FEMR, 0x0);
1911 acxpci_s_delete_dma_regions(adev);
1912 pci_save_state(pdev);
1913 pci_set_power_state(pdev, PCI_D3hot);
1915 acx_sem_unlock(adev);
1916 FN_EXIT0;
1917 return OK;
1921 static int acxpci_e_resume(struct pci_dev *pdev)
1923 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1924 acx_device_t *adev;
1926 FN_ENTER;
1928 printk("acx: resume handler is experimental!\n");
1929 printk("rsm: got dev %p\n", hw);
1932 adev = ieee2adev(hw);
1933 printk("rsm: got adev %p\n", adev);
1935 acx_sem_lock(adev);
1937 pci_set_power_state(pdev, PCI_D0);
1938 printk("rsm: power state PCI_D0 set\n");
1939 pci_restore_state(pdev);
1940 printk("rsm: PCI state restored\n");
1942 if (OK != acxpci_s_reset_dev(adev))
1943 goto end_unlock;
1944 printk("rsm: device reset done\n");
1945 if (OK != acx_s_init_mac(adev))
1946 goto end_unlock;
1947 printk("rsm: init MAC done\n");
1949 acxpci_s_up(hw);
1950 printk("rsm: acx up done\n");
1952 /* now even reload all card parameters as they were before suspend,
1953 * and possibly be back in the network again already :-) */
1954 if (ACX_STATE_IFACE_UP & adev->dev_state_mask) {
1955 adev->set_mask = GETSET_ALL;
1956 acx_s_update_card_settings(adev);
1957 printk("rsm: settings updated\n");
1959 ieee80211_register_hw(hw);
1960 printk("rsm: device attached\n");
1962 end_unlock:
1963 acx_sem_unlock(adev);
1964 /* we need to return OK here anyway, right? */
1965 FN_EXIT0;
1966 return OK;
1968 #endif /* CONFIG_PM */
1969 #endif /* CONFIG_PCI */
1971 /***********************************************************************
1972 ** acxpci_s_up
1974 ** This function is called by acxpci_e_open (when ifconfig sets the device as up)
1976 ** Side effects:
1977 ** - Enables on-card interrupt requests
1978 ** - calls acx_s_start
1981 static void enable_acx_irq(acx_device_t * adev)
1983 FN_ENTER;
1984 write_reg16(adev, IO_ACX_IRQ_MASK, adev->irq_mask);
1985 write_reg16(adev, IO_ACX_FEMR, 0x8000);
1986 adev->irqs_active = 1;
1987 FN_EXIT0;
1990 static void acxpci_s_up(struct ieee80211_hw *hw)
1992 acx_device_t *adev = ieee2adev(hw);
1993 unsigned long flags;
1995 FN_ENTER;
1997 acx_lock(adev, flags);
1998 enable_acx_irq(adev);
1999 acx_unlock(adev, flags);
2001 /* acx fw < 1.9.3.e has a hardware timer, and older drivers
2002 ** used to use it. But we don't do that anymore, our OS
2003 ** has reliable software timers */
2004 init_timer(&adev->mgmt_timer);
2005 adev->mgmt_timer.function = acx_i_timer;
2006 adev->mgmt_timer.data = (unsigned long)adev;
2008 /* Need to set ACX_STATE_IFACE_UP first, or else
2009 ** timer won't be started by acx_set_status() */
2010 SET_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
2012 acx_s_start(adev);
2014 FN_EXIT0;
2018 /***********************************************************************
2019 ** acxpci_s_down
2021 ** NB: device may be already hot unplugged if called from acxpci_e_remove()
2023 ** Disables on-card interrupt request, stops softirq and timer, stops queue,
2024 ** sets status == STOPPED
2027 static void disable_acx_irq(acx_device_t * adev)
2029 FN_ENTER;
2031 /* I guess mask is not 0xffff because acx100 won't signal
2032 ** cmd completion then (needed for ifup).
2033 ** Someone with acx100 please confirm */
2034 write_reg16(adev, IO_ACX_IRQ_MASK, adev->irq_mask_off);
2035 write_reg16(adev, IO_ACX_FEMR, 0x0);
2036 adev->irqs_active = 0;
2037 FN_EXIT0;
2040 static void acxpci_s_down(struct ieee80211_hw *hw)
2042 acx_device_t *adev = ieee2adev(hw);
2043 unsigned long flags;
2045 FN_ENTER;
2047 /* Disable IRQs first, so that IRQs cannot race with us */
2048 /* then wait until interrupts have finished executing on other CPUs */
2049 printk("acxpci_s_down: acx_lock()\n");
2050 acx_s_mwait(1000);
2051 acx_lock(adev, flags);
2052 disable_acx_irq(adev);
2053 synchronize_irq(adev->pdev->irq);
2054 printk("acxpci_s_down: acx_unlock()\n");
2055 acx_s_mwait(1000);
2056 acx_unlock(adev, flags);
2058 /* we really don't want to have an asynchronous tasklet disturb us
2059 ** after something vital for its job has been shut down, so
2060 ** end all remaining work now.
2062 ** NB: carrier_off (done by set_status below) would lead to
2063 ** not yet fully understood deadlock in flush_scheduled_work().
2064 ** That's why we do FLUSH first.
2066 ** NB2: we have a bad locking bug here: flush_scheduled_work()
2067 ** waits for acx_e_after_interrupt_task to complete if it is running
2068 ** on another CPU, but acx_e_after_interrupt_task
2069 ** will sleep on sem forever, because it is taken by us!
2070 ** Work around that by temporary sem unlock.
2071 ** This will fail miserably if we'll be hit by concurrent
2072 ** iwconfig or something in between. TODO! */
2073 printk("acxpci_s_down: flush_scheduled_work()\n");
2074 acx_s_mwait(1000);
2075 flush_scheduled_work();
2077 /* This is possible:
2078 ** flush_scheduled_work -> acx_e_after_interrupt_task ->
2079 ** -> set_status(ASSOCIATED) -> wake_queue()
2080 ** That's why we stop queue _after_ flush_scheduled_work
2081 ** lock/unlock is just paranoia, maybe not needed */
2083 /* kernel/timer.c says it's illegal to del_timer_sync()
2084 ** a timer which restarts itself. We guarantee this cannot
2085 ** ever happen because acx_i_timer() never does this if
2086 ** status is ACX_STATUS_0_STOPPED */
2087 printk("acxpci_s_down: del_timer_sync()\n");
2088 acx_s_mwait(1000);
2089 del_timer_sync(&adev->mgmt_timer);
2091 FN_EXIT0;
2094 #ifdef CONFIG_NET_POLL_CONTROLLER
2095 void acxpci_net_poll_controller(struct net_device *net_dev)
2097 acx_device_t *adev = ndev2adev(net_dev);
2098 unsigned long flags;
2100 local_irq_save(flags);
2101 acxpci_i_interrupt(adev->irq, adev);
2102 local_irq_restore(flags);
2104 #endif*/ /* CONFIG_NET_POLL_CONTROLLER */
2106 /***********************************************************************
2107 ** acxpci_e_open
2109 ** Called as a result of SIOCSIFFLAGS ioctl changing the flags bit IFF_UP
2110 ** from clear to set. In other words: ifconfig up.
2112 ** Returns:
2113 ** 0 success
2114 ** >0 f/w reported error
2115 ** <0 driver reported error
2117 static int acxpci_e_open(struct ieee80211_hw *hw)
2119 acx_device_t *adev = ieee2adev(hw);
2120 int result = OK;
2122 FN_ENTER;
2124 acx_sem_lock(adev);
2126 adev->initialized = 0;
2128 /* TODO: pci_set_power_state(pdev, PCI_D0); ? */
2130 /* request shared IRQ handler */
2131 if (request_irq
2132 (adev->irq, acxpci_i_interrupt, IRQF_SHARED, KBUILD_MODNAME, adev)) {
2133 printk("%s: request_irq FAILED\n", wiphy_name(adev->ieee->wiphy));
2134 result = -EAGAIN;
2135 goto done;
2137 log(L_DEBUG | L_IRQ, "request_irq %d successful\n", adev->irq);
2139 /* ifup device */
2140 acxpci_s_up(hw);
2142 /* We don't currently have to do anything else.
2143 * The setup of the MAC should be subsequently completed via
2144 * the mlme commands.
2145 * Higher layers know we're ready from dev->start==1 and
2146 * dev->tbusy==0. Our rx path knows to pass up received/
2147 * frames because of dev->flags&IFF_UP is true.
2149 acx_setup_modes(adev);
2150 ieee80211_start_queues(adev->ieee);
2152 adev->initialized = 1;
2153 done:
2154 acx_sem_unlock(adev);
2156 FN_EXIT1(result);
2157 return result;
2161 /***********************************************************************
2162 ** acxpci_e_close
2164 ** This function stops the network functionality of the interface (invoked
2165 ** when the user calls ifconfig <wlan> down). The tx queue is halted and
2166 ** the device is marked as down.
2168 ** Called as a result of SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
2169 ** from set to clear. I.e. called by "ifconfig DEV down"
2171 ** Returns:
2172 ** 0 success
2173 ** >0 f/w reported error
2174 ** <0 driver reported error
2176 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
2177 static int acxpci_e_close(struct ieee80211_hw *hw)
2178 #else
2179 static void acxpci_e_close(struct ieee80211_hw *hw)
2180 #endif
2182 acx_device_t *adev = ieee2adev(hw);
2183 unsigned long flags;
2184 FN_ENTER;
2185 printk("putting interface DOWN - this is filled with printk's and will take 8-10 seconds!\n");
2186 printk("acxpci_e_close: acx_lock()\n");
2187 acx_s_mwait(1000);
2188 acx_lock(adev,flags);
2189 /* ifdown device */
2190 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
2191 if (adev->initialized) {
2192 printk("acxpci_e_close: acxpci_s_down()\n");
2193 acx_s_mwait(1000);
2194 acxpci_s_down(hw);
2197 if (adev->modes)
2198 acx_free_modes(adev);
2199 /* disable all IRQs, release shared IRQ handler */
2200 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
2201 write_reg16(adev, IO_ACX_FEMR, 0x0);
2203 /* TODO: pci_set_power_state(pdev, PCI_D3hot); ? */
2205 /* We currently don't have to do anything else.
2206 * Higher layers know we're not ready from dev->start==0 and
2207 * dev->tbusy==1. Our rx path knows to not pass up received
2208 * frames because of dev->flags&IFF_UP is false.
2210 printk("acxpci_e_close: acx_unlock()\n");
2211 acx_s_mwait(1000);
2212 acx_unlock(adev,flags);
2214 log(L_INIT, "closed device\n");
2215 FN_EXIT0;
2216 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
2217 return OK;
2218 #endif
2224 /***************************************************************
2225 ** acxpci_l_process_rxdesc
2227 ** Called directly and only from the IRQ handler
2230 #if !ACX_DEBUG
2231 static inline void log_rxbuffer(const acx_device_t * adev)
2234 #else
2235 static void log_rxbuffer(const acx_device_t * adev)
2237 register const struct rxhostdesc *rxhostdesc;
2238 int i;
2240 /* no FN_ENTER here, we don't want that */
2242 rxhostdesc = adev->rxhostdesc_start;
2243 if (unlikely(!rxhostdesc))
2244 return;
2245 for (i = 0; i < RX_CNT; i++) {
2246 if ((rxhostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2247 && (rxhostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2248 printk("rx: buf %d full\n", i);
2249 rxhostdesc++;
2252 #endif
2254 static void acxpci_l_process_rxdesc(acx_device_t * adev)
2256 register rxhostdesc_t *hostdesc;
2257 unsigned count, tail;
2259 FN_ENTER;
2261 if (unlikely(acx_debug & L_BUFR))
2262 log_rxbuffer(adev);
2264 /* First, have a loop to determine the first descriptor that's
2265 * full, just in case there's a mismatch between our current
2266 * rx_tail and the full descriptor we're supposed to handle. */
2267 tail = adev->rx_tail;
2268 count = RX_CNT;
2269 while (1) {
2270 hostdesc = &adev->rxhostdesc_start[tail];
2271 /* advance tail regardless of outcome of the below test */
2272 tail = (tail + 1) % RX_CNT;
2274 if ((hostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2275 && (hostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2276 break; /* found it! */
2278 if (unlikely(!--count)) /* hmm, no luck: all descs empty, bail out */
2279 goto end;
2282 /* now process descriptors, starting with the first we figured out */
2283 while (1) {
2284 log(L_BUFR, "rx: tail=%u Ctl_16=%04X Status=%08X\n",
2285 tail, hostdesc->Ctl_16, hostdesc->Status);
2287 acx_l_process_rxbuf(adev, hostdesc->data);
2288 hostdesc->Status = 0;
2289 /* flush all writes before adapter sees CTL_HOSTOWN change */
2290 wmb();
2291 /* Host no longer owns this, needs to be LAST */
2292 CLEAR_BIT(hostdesc->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
2294 /* ok, descriptor is handled, now check the next descriptor */
2295 hostdesc = &adev->rxhostdesc_start[tail];
2297 /* if next descriptor is empty, then bail out */
2298 if (!(hostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2299 || !(hostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2300 break;
2302 tail = (tail + 1) % RX_CNT;
2304 end:
2305 adev->rx_tail = tail;
2306 FN_EXIT0;
2311 /***********************************************************************
2312 ** acxpci_i_interrupt
2314 ** IRQ handler (atomic context, must not sleep, blah, blah)
2317 /* scan is complete. all frames now on the receive queue are valid */
2318 #define INFO_SCAN_COMPLETE 0x0001
2319 #define INFO_WEP_KEY_NOT_FOUND 0x0002
2320 /* hw has been reset as the result of a watchdog timer timeout */
2321 #define INFO_WATCH_DOG_RESET 0x0003
2322 /* failed to send out NULL frame from PS mode notification to AP */
2323 /* recommended action: try entering 802.11 PS mode again */
2324 #define INFO_PS_FAIL 0x0004
2325 /* encryption/decryption process on a packet failed */
2326 #define INFO_IV_ICV_FAILURE 0x0005
2328 /* Info mailbox format:
2329 2 bytes: type
2330 2 bytes: status
2331 more bytes may follow
2332 rumors say about status:
2333 0x0000 info available (set by hw)
2334 0x0001 information received (must be set by host)
2335 0x1000 info available, mailbox overflowed (messages lost) (set by hw)
2336 but in practice we've seen:
2337 0x9000 when we did not set status to 0x0001 on prev message
2338 0x1001 when we did set it
2339 0x0000 was never seen
2340 conclusion: this is really a bitfield:
2341 0x1000 is 'info available' bit
2342 'mailbox overflowed' bit is 0x8000, not 0x1000
2343 value of 0x0000 probably means that there are no messages at all
2344 P.S. I dunno how in hell hw is supposed to notice that messages are lost -
2345 it does NOT clear bit 0x0001, and this bit will probably stay forever set
2346 after we set it once. Let's hope this will be fixed in firmware someday
2349 static void handle_info_irq(acx_device_t * adev)
2351 #if ACX_DEBUG
2352 static const char *const info_type_msg[] = {
2353 "(unknown)",
2354 "scan complete",
2355 "WEP key not found",
2356 "internal watchdog reset was done",
2357 "failed to send powersave (NULL frame) notification to AP",
2358 "encrypt/decrypt on a packet has failed",
2359 "TKIP tx keys disabled",
2360 "TKIP rx keys disabled",
2361 "TKIP rx: key ID not found",
2362 "???",
2363 "???",
2364 "???",
2365 "???",
2366 "???",
2367 "???",
2368 "???",
2369 "TKIP IV value exceeds thresh"
2371 #endif
2372 u32 info_type, info_status;
2374 info_type = acx_readl(adev->info_area);
2375 info_status = (info_type >> 16);
2376 info_type = (u16) info_type;
2378 /* inform fw that we have read this info message */
2379 acx_writel(info_type | 0x00010000, adev->info_area);
2380 write_reg16(adev, IO_ACX_INT_TRIG, INT_TRIG_INFOACK);
2381 write_flush(adev);
2383 log(L_CTL, "info_type:%04X info_status:%04X\n", info_type, info_status);
2385 log(L_IRQ, "got Info IRQ: status %04X type %04X: %s\n",
2386 info_status, info_type,
2387 info_type_msg[(info_type >= ARRAY_SIZE(info_type_msg)) ?
2388 0 : info_type]
2393 static void log_unusual_irq(u16 irqtype)
2396 if (!printk_ratelimit())
2397 return;
2400 printk("acx: got");
2401 if (irqtype & HOST_INT_RX_DATA) {
2402 printk(" Rx_Data");
2404 /* HOST_INT_TX_COMPLETE */
2405 if (irqtype & HOST_INT_TX_XFER) {
2406 printk(" Tx_Xfer");
2408 /* HOST_INT_RX_COMPLETE */
2409 if (irqtype & HOST_INT_DTIM) {
2410 printk(" DTIM");
2412 if (irqtype & HOST_INT_BEACON) {
2413 printk(" Beacon");
2415 if (irqtype & HOST_INT_TIMER) {
2416 log(L_IRQ, " Timer");
2418 if (irqtype & HOST_INT_KEY_NOT_FOUND) {
2419 printk(" Key_Not_Found");
2421 if (irqtype & HOST_INT_IV_ICV_FAILURE) {
2422 printk(" IV_ICV_Failure (crypto)");
2424 /* HOST_INT_CMD_COMPLETE */
2425 /* HOST_INT_INFO */
2426 if (irqtype & HOST_INT_OVERFLOW) {
2427 printk(" Overflow");
2429 if (irqtype & HOST_INT_PROCESS_ERROR) {
2430 printk(" Process_Error");
2432 /* HOST_INT_SCAN_COMPLETE */
2433 if (irqtype & HOST_INT_FCS_THRESHOLD) {
2434 printk(" FCS_Threshold");
2436 if (irqtype & HOST_INT_UNKNOWN) {
2437 printk(" Unknown");
2439 printk(" IRQ(s)\n");
2443 static void update_link_quality_led(acx_device_t * adev)
2445 /* int qual; */
2447 /* qual =
2448 acx_signal_determine_quality(adev->wstats.qual.level,
2449 adev->wstats.qual.noise);
2450 if (qual > adev->brange_max_quality)
2451 qual = adev->brange_max_quality;
2454 /* if (time_after(jiffies, adev->brange_time_last_state_change +
2455 (HZ / 2 -
2456 HZ / 2 * (unsigned long)qual /
2457 adev->brange_max_quality))) {
2458 acxpci_l_power_led(adev, (adev->brange_last_state == 0));
2459 adev->brange_last_state ^= 1; *//* toggle */
2460 /* adev->brange_time_last_state_change = jiffies;
2465 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* a la orinoco.c */
2467 /* Interrupt handler bottom-half */
2468 void acx_interrupt_tasklet(struct work_struct *work)
2471 #ifdef CONFIG_ACX_MAC80211_DEBUG
2472 u32 _handled = 0x00000000;
2473 # define acxirq_handled(irq) do { _handled |= (irq); } while (0)
2474 #else
2475 # define acxirq_handled(irq) do { /* nothing */ } while (0)
2476 #endif /* CONFIG_ACX_MAC80211_DEBUG */
2477 acx_device_t *adev = container_of(work,struct acx_device, after_interrupt_task);
2478 // unsigned int irqcount = MAX_IRQLOOPS_PER_JIFFY;
2479 int irqtype;
2481 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2482 * I am paranoid */
2483 acx_sem_lock(adev);
2486 FN_ENTER;
2487 irqtype = adev->irq_reason;
2488 adev->irq_reason = 0;
2490 #define IRQ_ITERATE 0
2491 #if IRQ_ITERATE
2492 if (jiffies != adev->irq_last_jiffies) {
2493 adev->irq_loops_this_jiffy = 0;
2494 adev->irq_last_jiffies = jiffies;
2497 /* safety condition; we'll normally abort loop below
2498 * in case no IRQ type occurred */
2499 while (likely(--irqcount)) {
2500 #endif
2501 /* ACK all IRQs ASAP */
2504 /* Handle most important IRQ types first */
2505 if (irqtype & HOST_INT_RX_COMPLETE) {
2506 log(L_IRQ, "got Rx_Complete IRQ\n");
2507 acxpci_l_process_rxdesc(adev);
2509 if (irqtype & HOST_INT_TX_COMPLETE) {
2510 log(L_IRQ, "got Tx_Complete IRQ\n");
2511 /* don't clean up on each Tx complete, wait a bit
2512 * unless we're going towards full, in which case
2513 * we do it immediately, too (otherwise we might lockup
2514 * with a full Tx buffer if we go into
2515 * acxpci_l_clean_txdesc() at a time when we won't wakeup
2516 * the net queue in there for some reason...) */
2517 // if (adev->tx_free <= TX_START_CLEAN) {
2518 acxpci_l_clean_txdesc(adev);
2519 // }
2522 /* Less frequent ones */
2523 if (irqtype & (0
2524 | HOST_INT_CMD_COMPLETE
2525 | HOST_INT_INFO | HOST_INT_SCAN_COMPLETE)) {
2526 if (irqtype & HOST_INT_INFO) {
2527 handle_info_irq(adev);
2529 if (irqtype & HOST_INT_SCAN_COMPLETE) {
2530 log(L_IRQ, "got Scan_Complete IRQ\n");
2531 /* need to do that in process context */
2532 /* remember that fw is not scanning anymore */
2533 SET_BIT(adev->irq_status,
2534 HOST_INT_SCAN_COMPLETE);
2538 /* These we just log, but either they happen rarely
2539 * or we keep them masked out */
2540 if (irqtype & (0 | HOST_INT_RX_DATA
2541 /* | HOST_INT_TX_COMPLETE */
2542 | HOST_INT_TX_XFER
2543 /* | HOST_INT_RX_COMPLETE */
2544 | HOST_INT_DTIM
2545 | HOST_INT_BEACON
2546 | HOST_INT_TIMER
2547 | HOST_INT_KEY_NOT_FOUND
2548 | HOST_INT_IV_ICV_FAILURE
2549 /* | HOST_INT_CMD_COMPLETE */
2550 /* | HOST_INT_INFO */
2551 | HOST_INT_OVERFLOW | HOST_INT_PROCESS_ERROR
2552 /* | HOST_INT_SCAN_COMPLETE */
2553 | HOST_INT_FCS_THRESHOLD | HOST_INT_UNKNOWN)) {
2554 log_unusual_irq(irqtype);
2556 #if IRQ_ITERATE
2557 unmasked = read_reg16(adev, IO_ACX_IRQ_STATUS_CLEAR);
2558 irqtype = unmasked & ~adev->irq_mask;
2559 /* Bail out if no new IRQ bits or if all are masked out */
2560 if (!irqtype)
2561 break;
2563 if (unlikely
2564 (++adev->irq_loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY)) {
2565 printk(KERN_ERR
2566 "acx: too many interrupts per jiffy!\n");
2567 /* Looks like card floods us with IRQs! Try to stop that */
2568 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
2569 /* This will short-circuit all future attempts to handle IRQ.
2570 * We cant do much more... */
2571 adev->irq_mask = 0;
2572 break;
2575 #endif
2576 /* Routine to perform blink with range */
2577 if (unlikely(adev->led_power == 2))
2578 update_link_quality_led(adev);
2580 /* handled: */
2581 if (adev->after_interrupt_jobs)
2582 acx_e_after_interrupt_task(&adev->after_interrupt_task);
2584 /* write_flush(adev); - not needed, last op was read anyway */
2585 acx_sem_unlock(adev);
2586 FN_EXIT0;
2587 return;
2592 static irqreturn_t
2593 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
2594 acxpci_i_interrupt(int irq, void *dev_id)
2595 #else
2596 acxpci_i_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2597 #endif
2600 acx_device_t *adev = dev_id;
2601 unsigned long flags;
2602 register u16 irqtype;
2603 u16 unmasked;
2605 if (!adev)
2606 return IRQ_NONE;
2607 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2608 * I am paranoid */
2610 acx_lock(adev, flags);
2612 unmasked = read_reg16(adev, IO_ACX_IRQ_STATUS_CLEAR);
2614 if (unlikely(0xffff == unmasked)) {
2615 /* 0xffff value hints at missing hardware,
2616 * so don't do anything.
2617 * Not very clean, but other drivers do the same... */
2618 log(L_IRQ, "IRQ type:FFFF - device removed? IRQ_NONE\n");
2619 goto none;
2622 /* We will check only "interesting" IRQ types */
2623 irqtype = unmasked & ~adev->irq_mask;
2624 if (!irqtype) {
2625 /* We are on a shared IRQ line and it wasn't our IRQ */
2626 log(L_IRQ,
2627 "IRQ type:%04X, mask:%04X - all are masked, IRQ_NONE\n",
2628 unmasked, adev->irq_mask);
2629 goto none;
2632 /* Go ahead and ACK our interrupt */
2633 write_reg16(adev, IO_ACX_IRQ_ACK, 0xffff);
2634 if (irqtype & HOST_INT_CMD_COMPLETE) {
2635 log(L_IRQ, "got Command_Complete IRQ\n");
2636 /* save the state for the running issue_cmd() */
2637 SET_BIT(adev->irq_status, HOST_INT_CMD_COMPLETE);
2640 /* Only accept IRQs, if we are initialized properly.
2641 * This avoids an RX race while initializing.
2642 * We should probably not enable IRQs before we are initialized
2643 * completely, but some careful work is needed to fix this. I think it
2644 * is best to stay with this cheap workaround for now... .
2646 if (likely(adev->initialized)) {
2647 /* disable all IRQs. They are enabled again in the bottom half. */
2648 /* save the reason code and call our bottom half. */
2649 adev->irq_reason = irqtype;
2651 if ((irqtype & HOST_INT_RX_COMPLETE) || (irqtype & HOST_INT_TX_COMPLETE))
2652 acx_schedule_task(adev, 0);
2654 acx_unlock(adev, flags);
2655 return IRQ_HANDLED;
2656 none:
2657 acx_unlock(adev, flags);
2658 return IRQ_NONE;
2663 /***********************************************************************
2664 ** acxpci_l_power_led
2666 void acxpci_l_power_led(acx_device_t * adev, int enable)
2668 u16 gpio_pled = IS_ACX111(adev) ? 0x0040 : 0x0800;
2670 /* A hack. Not moving message rate limiting to adev->xxx
2671 * (it's only a debug message after all) */
2672 static int rate_limit = 0;
2674 if (rate_limit++ < 3)
2675 log(L_IOCTL, "Please report in case toggling the power "
2676 "LED doesn't work for your card!\n");
2677 if (enable)
2678 write_reg16(adev, IO_ACX_GPIO_OUT,
2679 read_reg16(adev, IO_ACX_GPIO_OUT) & ~gpio_pled);
2680 else
2681 write_reg16(adev, IO_ACX_GPIO_OUT,
2682 read_reg16(adev, IO_ACX_GPIO_OUT) | gpio_pled);
2686 /***********************************************************************
2687 ** Ioctls
2690 /***********************************************************************
2692 #if 0
2694 acx111pci_ioctl_info(struct net_device *ndev,
2695 struct iw_request_info *info,
2696 struct iw_param *vwrq, char *extra)
2698 #if ACX_DEBUG > 1
2699 acx_device_t *adev = ndev2adev(ndev);
2700 rxdesc_t *rxdesc;
2701 txdesc_t *txdesc;
2702 rxhostdesc_t *rxhostdesc;
2703 txhostdesc_t *txhostdesc;
2704 struct acx111_ie_memoryconfig memconf;
2705 struct acx111_ie_queueconfig queueconf;
2706 unsigned long flags;
2707 int i;
2708 char memmap[0x34];
2709 char rxconfig[0x8];
2710 char fcserror[0x8];
2711 char ratefallback[0x5];
2713 if (!(acx_debug & (L_IOCTL | L_DEBUG)))
2714 return OK;
2715 /* using printk() since we checked debug flag already */
2717 acx_sem_lock(adev);
2719 if (!IS_ACX111(adev)) {
2720 printk("acx111-specific function called "
2721 "with non-acx111 chip, aborting\n");
2722 goto end_ok;
2725 /* get Acx111 Memory Configuration */
2726 memset(&memconf, 0, sizeof(memconf));
2727 /* BTW, fails with 12 (Write only) error code.
2728 ** Retained for easy testing of issue_cmd error handling :) */
2729 acx_s_interrogate(adev, &memconf, ACX1xx_IE_QUEUE_CONFIG);
2731 /* get Acx111 Queue Configuration */
2732 memset(&queueconf, 0, sizeof(queueconf));
2733 acx_s_interrogate(adev, &queueconf, ACX1xx_IE_MEMORY_CONFIG_OPTIONS);
2735 /* get Acx111 Memory Map */
2736 memset(memmap, 0, sizeof(memmap));
2737 acx_s_interrogate(adev, &memmap, ACX1xx_IE_MEMORY_MAP);
2739 /* get Acx111 Rx Config */
2740 memset(rxconfig, 0, sizeof(rxconfig));
2741 acx_s_interrogate(adev, &rxconfig, ACX1xx_IE_RXCONFIG);
2743 /* get Acx111 fcs error count */
2744 memset(fcserror, 0, sizeof(fcserror));
2745 acx_s_interrogate(adev, &fcserror, ACX1xx_IE_FCS_ERROR_COUNT);
2747 /* get Acx111 rate fallback */
2748 memset(ratefallback, 0, sizeof(ratefallback));
2749 acx_s_interrogate(adev, &ratefallback, ACX1xx_IE_RATE_FALLBACK);
2751 /* force occurrence of a beacon interrupt */
2752 /* TODO: comment why is this necessary */
2753 write_reg16(adev, IO_ACX_HINT_TRIG, HOST_INT_BEACON);
2755 /* dump Acx111 Mem Configuration */
2756 printk("dump mem config:\n"
2757 "data read: %d, struct size: %d\n"
2758 "Number of stations: %1X\n"
2759 "Memory block size: %1X\n"
2760 "tx/rx memory block allocation: %1X\n"
2761 "count rx: %X / tx: %X queues\n"
2762 "options %1X\n"
2763 "fragmentation %1X\n"
2764 "Rx Queue 1 Count Descriptors: %X\n"
2765 "Rx Queue 1 Host Memory Start: %X\n"
2766 "Tx Queue 1 Count Descriptors: %X\n"
2767 "Tx Queue 1 Attributes: %X\n",
2768 memconf.len, (int)sizeof(memconf),
2769 memconf.no_of_stations,
2770 memconf.memory_block_size,
2771 memconf.tx_rx_memory_block_allocation,
2772 memconf.count_rx_queues, memconf.count_tx_queues,
2773 memconf.options,
2774 memconf.fragmentation,
2775 memconf.rx_queue1_count_descs,
2776 acx2cpu(memconf.rx_queue1_host_rx_start),
2777 memconf.tx_queue1_count_descs, memconf.tx_queue1_attributes);
2779 /* dump Acx111 Queue Configuration */
2780 printk("dump queue head:\n"
2781 "data read: %d, struct size: %d\n"
2782 "tx_memory_block_address (from card): %X\n"
2783 "rx_memory_block_address (from card): %X\n"
2784 "rx1_queue address (from card): %X\n"
2785 "tx1_queue address (from card): %X\n"
2786 "tx1_queue attributes (from card): %X\n",
2787 queueconf.len, (int)sizeof(queueconf),
2788 queueconf.tx_memory_block_address,
2789 queueconf.rx_memory_block_address,
2790 queueconf.rx1_queue_address,
2791 queueconf.tx1_queue_address, queueconf.tx1_attributes);
2793 /* dump Acx111 Mem Map */
2794 printk("dump mem map:\n"
2795 "data read: %d, struct size: %d\n"
2796 "Code start: %X\n"
2797 "Code end: %X\n"
2798 "WEP default key start: %X\n"
2799 "WEP default key end: %X\n"
2800 "STA table start: %X\n"
2801 "STA table end: %X\n"
2802 "Packet template start: %X\n"
2803 "Packet template end: %X\n"
2804 "Queue memory start: %X\n"
2805 "Queue memory end: %X\n"
2806 "Packet memory pool start: %X\n"
2807 "Packet memory pool end: %X\n"
2808 "iobase: %p\n"
2809 "iobase2: %p\n",
2810 *((u16 *) & memmap[0x02]), (int)sizeof(memmap),
2811 *((u32 *) & memmap[0x04]),
2812 *((u32 *) & memmap[0x08]),
2813 *((u32 *) & memmap[0x0C]),
2814 *((u32 *) & memmap[0x10]),
2815 *((u32 *) & memmap[0x14]),
2816 *((u32 *) & memmap[0x18]),
2817 *((u32 *) & memmap[0x1C]),
2818 *((u32 *) & memmap[0x20]),
2819 *((u32 *) & memmap[0x24]),
2820 *((u32 *) & memmap[0x28]),
2821 *((u32 *) & memmap[0x2C]),
2822 *((u32 *) & memmap[0x30]), adev->iobase, adev->iobase2);
2824 /* dump Acx111 Rx Config */
2825 printk("dump rx config:\n"
2826 "data read: %d, struct size: %d\n"
2827 "rx config: %X\n"
2828 "rx filter config: %X\n",
2829 *((u16 *) & rxconfig[0x02]), (int)sizeof(rxconfig),
2830 *((u16 *) & rxconfig[0x04]), *((u16 *) & rxconfig[0x06]));
2832 /* dump Acx111 fcs error */
2833 printk("dump fcserror:\n"
2834 "data read: %d, struct size: %d\n"
2835 "fcserrors: %X\n",
2836 *((u16 *) & fcserror[0x02]), (int)sizeof(fcserror),
2837 *((u32 *) & fcserror[0x04]));
2839 /* dump Acx111 rate fallback */
2840 printk("dump rate fallback:\n"
2841 "data read: %d, struct size: %d\n"
2842 "ratefallback: %X\n",
2843 *((u16 *) & ratefallback[0x02]), (int)sizeof(ratefallback),
2844 *((u8 *) & ratefallback[0x04]));
2846 /* protect against IRQ */
2847 acx_lock(adev, flags);
2849 /* dump acx111 internal rx descriptor ring buffer */
2850 rxdesc = adev->rxdesc_start;
2852 /* loop over complete receive pool */
2853 if (rxdesc)
2854 for (i = 0; i < RX_CNT; i++) {
2855 printk("\ndump internal rxdesc %d:\n"
2856 "mem pos %p\n"
2857 "next 0x%X\n"
2858 "acx mem pointer (dynamic) 0x%X\n"
2859 "CTL (dynamic) 0x%X\n"
2860 "Rate (dynamic) 0x%X\n"
2861 "RxStatus (dynamic) 0x%X\n"
2862 "Mod/Pre (dynamic) 0x%X\n",
2864 rxdesc,
2865 acx2cpu(rxdesc->pNextDesc),
2866 acx2cpu(rxdesc->ACXMemPtr),
2867 rxdesc->Ctl_8,
2868 rxdesc->rate, rxdesc->error, rxdesc->SNR);
2869 rxdesc++;
2872 /* dump host rx descriptor ring buffer */
2874 rxhostdesc = adev->rxhostdesc_start;
2876 /* loop over complete receive pool */
2877 if (rxhostdesc)
2878 for (i = 0; i < RX_CNT; i++) {
2879 printk("\ndump host rxdesc %d:\n"
2880 "mem pos %p\n"
2881 "buffer mem pos 0x%X\n"
2882 "buffer mem offset 0x%X\n"
2883 "CTL 0x%X\n"
2884 "Length 0x%X\n"
2885 "next 0x%X\n"
2886 "Status 0x%X\n",
2888 rxhostdesc,
2889 acx2cpu(rxhostdesc->data_phy),
2890 rxhostdesc->data_offset,
2891 le16_to_cpu(rxhostdesc->Ctl_16),
2892 le16_to_cpu(rxhostdesc->length),
2893 acx2cpu(rxhostdesc->desc_phy_next),
2894 rxhostdesc->Status);
2895 rxhostdesc++;
2898 /* dump acx111 internal tx descriptor ring buffer */
2899 txdesc = adev->txdesc_start;
2901 /* loop over complete transmit pool */
2902 if (txdesc)
2903 for (i = 0; i < TX_CNT; i++) {
2904 printk("\ndump internal txdesc %d:\n"
2905 "size 0x%X\n"
2906 "mem pos %p\n"
2907 "next 0x%X\n"
2908 "acx mem pointer (dynamic) 0x%X\n"
2909 "host mem pointer (dynamic) 0x%X\n"
2910 "length (dynamic) 0x%X\n"
2911 "CTL (dynamic) 0x%X\n"
2912 "CTL2 (dynamic) 0x%X\n"
2913 "Status (dynamic) 0x%X\n"
2914 "Rate (dynamic) 0x%X\n",
2916 (int)sizeof(struct txdesc),
2917 txdesc,
2918 acx2cpu(txdesc->pNextDesc),
2919 acx2cpu(txdesc->AcxMemPtr),
2920 acx2cpu(txdesc->HostMemPtr),
2921 le16_to_cpu(txdesc->total_length),
2922 txdesc->Ctl_8,
2923 txdesc->Ctl2_8, txdesc->error,
2924 txdesc->u.r1.rate);
2925 txdesc = advance_txdesc(adev, txdesc, 1);
2928 /* dump host tx descriptor ring buffer */
2930 txhostdesc = adev->txhostdesc_start;
2932 /* loop over complete host send pool */
2933 if (txhostdesc)
2934 for (i = 0; i < TX_CNT * 2; i++) {
2935 printk("\ndump host txdesc %d:\n"
2936 "mem pos %p\n"
2937 "buffer mem pos 0x%X\n"
2938 "buffer mem offset 0x%X\n"
2939 "CTL 0x%X\n"
2940 "Length 0x%X\n"
2941 "next 0x%X\n"
2942 "Status 0x%X\n",
2944 txhostdesc,
2945 acx2cpu(txhostdesc->data_phy),
2946 txhostdesc->data_offset,
2947 le16_to_cpu(txhostdesc->Ctl_16),
2948 le16_to_cpu(txhostdesc->length),
2949 acx2cpu(txhostdesc->desc_phy_next),
2950 le32_to_cpu(txhostdesc->Status));
2951 txhostdesc++;
2954 /* write_reg16(adev, 0xb4, 0x4); */
2956 acx_unlock(adev, flags);
2957 end_ok:
2959 acx_sem_unlock(adev);
2960 #endif /* ACX_DEBUG */
2961 return OK;
2965 /***********************************************************************
2968 acx100pci_ioctl_set_phy_amp_bias(struct net_device *ndev,
2969 struct iw_request_info *info,
2970 struct iw_param *vwrq, char *extra)
2972 acx_device_t *adev = ndev2adev(ndev);
2973 unsigned long flags;
2974 u16 gpio_old;
2976 if (!IS_ACX100(adev)) {
2977 /* WARNING!!!
2978 * Removing this check *might* damage
2979 * hardware, since we're tweaking GPIOs here after all!!!
2980 * You've been warned...
2981 * WARNING!!! */
2982 printk("acx: sorry, setting bias level for non-acx100 "
2983 "is not supported yet\n");
2984 return OK;
2987 if (*extra > 7) {
2988 printk("acx: invalid bias parameter, range is 0-7\n");
2989 return -EINVAL;
2992 acx_sem_lock(adev);
2994 /* Need to lock accesses to [IO_ACX_GPIO_OUT]:
2995 * IRQ handler uses it to update LED */
2996 acx_lock(adev, flags);
2997 gpio_old = read_reg16(adev, IO_ACX_GPIO_OUT);
2998 write_reg16(adev, IO_ACX_GPIO_OUT,
2999 (gpio_old & 0xf8ff) | ((u16) * extra << 8));
3000 acx_unlock(adev, flags);
3002 log(L_DEBUG, "gpio_old: 0x%04X\n", gpio_old);
3003 printk("%s: PHY power amplifier bias: old:%d, new:%d\n",
3004 ndev->name, (gpio_old & 0x0700) >> 8, (unsigned char)*extra);
3006 acx_sem_unlock(adev);
3008 return OK;
3010 #endif
3012 /***************************************************************
3013 ** acxpci_l_alloc_tx
3014 ** Actually returns a txdesc_t* ptr
3016 ** FIXME: in case of fragments, should allocate multiple descrs
3017 ** after figuring out how many we need and whether we still have
3018 ** sufficiently many.
3020 tx_t *acxpci_l_alloc_tx(acx_device_t * adev)
3022 struct txdesc *txdesc;
3023 unsigned head;
3024 u8 ctl8;
3026 FN_ENTER;
3028 if (unlikely(!adev->tx_free)) {
3029 printk("acx: BUG: no free txdesc left\n");
3030 txdesc = NULL;
3031 goto end;
3034 head = adev->tx_head;
3035 txdesc = get_txdesc(adev, head);
3036 ctl8 = txdesc->Ctl_8;
3038 /* 2005-10-11: there were several bug reports on this happening
3039 ** but now cause seems to be understood & fixed */
3040 if (unlikely(DESC_CTL_HOSTOWN != (ctl8 & DESC_CTL_ACXDONE_HOSTOWN))) {
3041 /* whoops, descr at current index is not free, so probably
3042 * ring buffer already full */
3043 printk("acx: BUG: tx_head:%d Ctl8:0x%02X - failed to find "
3044 "free txdesc\n", head, ctl8);
3045 txdesc = NULL;
3046 goto end;
3049 /* Needed in case txdesc won't be eventually submitted for tx */
3050 txdesc->Ctl_8 = DESC_CTL_ACXDONE_HOSTOWN;
3052 adev->tx_free--;
3053 log(L_BUFT, "tx: got desc %u, %u remain\n", head, adev->tx_free);
3054 /* Keep a few free descs between head and tail of tx ring.
3055 ** It is not absolutely needed, just feels safer */
3056 if (adev->tx_free < TX_STOP_QUEUE) {
3057 log(L_BUF, "stop queue (%u tx desc left)\n", adev->tx_free);
3058 acx_stop_queue(adev->ieee, NULL);
3061 /* returning current descriptor, so advance to next free one */
3062 adev->tx_head = (head + 1) % TX_CNT;
3063 end:
3064 FN_EXIT0;
3066 return (tx_t *) txdesc;
3070 /***********************************************************************
3072 void *acxpci_l_get_txbuf(acx_device_t * adev, tx_t * tx_opaque)
3074 return get_txhostdesc(adev, (txdesc_t *) tx_opaque)->data;
3078 /***********************************************************************
3079 ** acxpci_l_tx_data
3081 ** Can be called from IRQ (rx -> (AP bridging or mgmt response) -> tx).
3082 ** Can be called from acx_i_start_xmit (data frames from net core).
3084 ** FIXME: in case of fragments, should loop over the number of
3085 ** pre-allocated tx descrs, properly setting up transfer data and
3086 ** CTL_xxx flags according to fragment number.
3088 void
3089 acxpci_l_tx_data(acx_device_t * adev, tx_t * tx_opaque, int len,
3090 struct ieee80211_tx_control *ieeectl,struct sk_buff* skb)
3092 txdesc_t *txdesc = (txdesc_t *) tx_opaque;
3093 struct ieee80211_hdr *wireless_header;
3094 txhostdesc_t *hostdesc1, *hostdesc2;
3095 int rate_cur;
3096 u8 Ctl_8, Ctl2_8;
3097 int wlhdr_len;
3099 FN_ENTER;
3101 /* fw doesn't tx such packets anyhow */
3102 /* if (unlikely(len < WLAN_HDR_A3_LEN))
3103 goto end;
3105 hostdesc1 = get_txhostdesc(adev, txdesc);
3106 wireless_header = (struct ieee80211_hdr *)hostdesc1->data;
3107 /* modify flag status in separate variable to be able to write it back
3108 * in one big swoop later (also in order to have less device memory
3109 * accesses) */
3110 Ctl_8 = txdesc->Ctl_8;
3111 Ctl2_8 = 0; /* really need to init it to 0, not txdesc->Ctl2_8, it seems */
3113 hostdesc2 = hostdesc1 + 1;
3115 /* DON'T simply set Ctl field to 0 here globally,
3116 * it needs to maintain a consistent flag status (those are state flags!!),
3117 * otherwise it may lead to severe disruption. Only set or reset particular
3118 * flags at the exact moment this is needed... */
3120 /* let chip do RTS/CTS handshaking before sending
3121 * in case packet size exceeds threshold */
3122 if (ieeectl->flags & IEEE80211_TXCTL_USE_RTS_CTS)
3123 SET_BIT(Ctl2_8, DESC_CTL2_RTS);
3124 else
3125 CLEAR_BIT(Ctl2_8, DESC_CTL2_RTS);
3127 rate_cur = ieeectl->tx_rate;
3128 if (unlikely(!rate_cur)) {
3129 printk("acx: driver bug! bad ratemask\n");
3130 goto end;
3133 /* used in tx cleanup routine for auto rate and accounting: */
3134 /* put_txcr(adev, txdesc, clt, rate_cur); deprecated by mac80211 */
3136 txdesc->total_length = cpu_to_le16(len);
3137 wlhdr_len = ieee80211_get_hdrlen(le16_to_cpu(wireless_header->frame_control));
3138 hostdesc2->length = cpu_to_le16(len - wlhdr_len);
3140 if (!ieeectl->do_not_encrypt && ieeectl->key_idx>= 0)
3142 u16 key_idx = (u16)(ieeectl->key_idx);
3143 struct acx_key* key = &(adev->key[key_idx]);
3144 int wlhdr_len;
3145 if (key->enabled)
3147 memcpy(ieeehdr->wep_iv, ((u8*)wireless_header) + wlhdr_len, 4);
3151 if (IS_ACX111(adev)) {
3152 /* note that if !txdesc->do_auto, txrate->cur
3153 ** has only one nonzero bit */
3154 txdesc->u.r2.rate111 = cpu_to_le16(rate_cur
3155 /* WARNING: I was never able to make it work with prism54 AP.
3156 ** It was falling down to 1Mbit where shortpre is not applicable,
3157 ** and not working at all at "5,11 basic rates only" setting.
3158 ** I even didn't see tx packets in radio packet capture.
3159 ** Disabled for now --vda */
3160 /*| ((clt->shortpre && clt->cur!=RATE111_1) ? RATE111_SHORTPRE : 0) */
3162 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3163 /* should add this to rate111 above as necessary */
3164 |(clt->pbcc511 ? RATE111_PBCC511 : 0)
3165 #endif
3166 hostdesc1->length = cpu_to_le16(len);
3167 } else { /* ACX100 */
3168 u8 rate_100 = ieeectl->tx_rate;
3169 txdesc->u.r1.rate = rate_100;
3170 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3171 if (clt->pbcc511) {
3172 if (n == RATE100_5 || n == RATE100_11)
3173 n |= RATE100_PBCC511;
3176 if (clt->shortpre && (clt->cur != RATE111_1))
3177 SET_BIT(Ctl_8, DESC_CTL_SHORT_PREAMBLE); /* set Short Preamble */
3178 #endif
3179 /* set autodma and reclaim and 1st mpdu */
3180 SET_BIT(Ctl_8,
3181 DESC_CTL_AUTODMA | DESC_CTL_RECLAIM |
3182 DESC_CTL_FIRSTFRAG);
3183 #if ACX_FRAGMENTATION
3184 /* SET_BIT(Ctl2_8, DESC_CTL2_MORE_FRAG); cannot set it unconditionally, needs to be set for all non-last fragments */
3185 #endif
3186 hostdesc1->length = cpu_to_le16(wlhdr_len);
3188 /* don't need to clean ack/rts statistics here, already
3189 * done on descr cleanup */
3191 /* clears HOSTOWN and ACXDONE bits, thus telling that the descriptors
3192 * are now owned by the acx100; do this as LAST operation */
3193 CLEAR_BIT(Ctl_8, DESC_CTL_ACXDONE_HOSTOWN);
3194 /* flush writes before we release hostdesc to the adapter here */
3195 wmb();
3196 CLEAR_BIT(hostdesc1->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3197 CLEAR_BIT(hostdesc2->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3199 /* write back modified flags */
3200 CLEAR_BIT(Ctl2_8, DESC_CTL2_WEP);
3201 txdesc->Ctl2_8 = Ctl2_8;
3202 txdesc->Ctl_8 = Ctl_8;
3203 /* unused: txdesc->tx_time = cpu_to_le32(jiffies); */
3205 /* flush writes before we tell the adapter that it's its turn now */
3206 mmiowb();
3207 write_reg16(adev, IO_ACX_INT_TRIG, INT_TRIG_TXPRC);
3208 write_flush(adev);
3209 /* log the packet content AFTER sending it,
3210 * in order to not delay sending any further than absolutely needed
3211 * Do separate logs for acx100/111 to have human-readable rates */
3212 memcpy(&(hostdesc1->txstatus.control),ieeectl,sizeof(struct ieee80211_tx_control));
3213 hostdesc1->skb = skb;
3214 end:
3215 FN_EXIT0;
3219 /***********************************************************************
3220 ** acxpci_l_clean_txdesc
3222 ** This function resets the txdescs' status when the ACX100
3223 ** signals the TX done IRQ (txdescs have been processed), starting with
3224 ** the pool index of the descriptor which we would use next,
3225 ** in order to make sure that we can be as fast as possible
3226 ** in filling new txdescs.
3227 ** Everytime we get called we know where the next packet to be cleaned is.
3230 #if !ACX_DEBUG
3231 static inline void log_txbuffer(const acx_device_t * adev)
3234 #else
3235 static void log_txbuffer(acx_device_t * adev)
3237 txdesc_t *txdesc;
3238 int i;
3240 /* no FN_ENTER here, we don't want that */
3241 /* no locks here, since it's entirely non-critical code */
3242 txdesc = adev->txdesc_start;
3243 if (unlikely(!txdesc))
3244 return;
3245 printk("tx: desc->Ctl8's:");
3246 for (i = 0; i < TX_CNT; i++) {
3247 printk(" %02X", txdesc->Ctl_8);
3248 txdesc = advance_txdesc(adev, txdesc, 1);
3250 printk("\n");
3252 #endif
3255 static void handle_tx_error(acx_device_t * adev, u8 error, unsigned int finger,
3256 struct ieee80211_tx_status *status)
3258 const char *err = "unknown error";
3260 /* hmm, should we handle this as a mask
3261 * of *several* bits?
3262 * For now I think only caring about
3263 * individual bits is ok... */
3264 switch (error) {
3265 case 0x01:
3266 err = "no Tx due to error in other fragment";
3267 /* adev->wstats.discard.fragment++; */
3268 break;
3269 case 0x02:
3270 err = "Tx aborted";
3271 adev->stats.tx_aborted_errors++;
3272 break;
3273 case 0x04:
3274 err = "Tx desc wrong parameters";
3275 /* adev->wstats.discard.misc++; */
3276 break;
3277 case 0x08:
3278 err = "WEP key not found";
3279 /* adev->wstats.discard.misc++; */
3280 break;
3281 case 0x10:
3282 err = "MSDU lifetime timeout? - try changing "
3283 "'iwconfig retry lifetime XXX'";
3284 /* adev->wstats.discard.misc++; */
3285 break;
3286 case 0x20:
3287 err = "excessive Tx retries due to either distance "
3288 "too high or unable to Tx or Tx frame error - "
3289 "try changing 'iwconfig txpower XXX' or "
3290 "'sens'itivity or 'retry'";
3291 /* adev->wstats.discard.retries++; */
3292 /* Tx error 0x20 also seems to occur on
3293 * overheating, so I'm not sure whether we
3294 * actually want to do aggressive radio recalibration,
3295 * since people maybe won't notice then that their hardware
3296 * is slowly getting cooked...
3297 * Or is it still a safe long distance from utter
3298 * radio non-functionality despite many radio recalibs
3299 * to final destructive overheating of the hardware?
3300 * In this case we really should do recalib here...
3301 * I guess the only way to find out is to do a
3302 * potentially fatal self-experiment :-\
3303 * Or maybe only recalib in case we're using Tx
3304 * rate auto (on errors switching to lower speed
3305 * --> less heat?) or 802.11 power save mode?
3307 * ok, just do it. */
3308 if (++adev->retry_errors_msg_ratelimit % 4 == 0) {
3309 if (adev->retry_errors_msg_ratelimit <= 20) {
3310 printk("%s: several excessive Tx "
3311 "retry errors occurred, attempting "
3312 "to recalibrate radio. Radio "
3313 "drift might be caused by increasing "
3314 "card temperature, please check the card "
3315 "before it's too late!\n",
3316 wiphy_name(adev->ieee->wiphy));
3317 if (adev->retry_errors_msg_ratelimit == 20)
3318 printk("disabling above message\n");
3321 acx_schedule_task(adev,
3322 ACX_AFTER_IRQ_CMD_RADIO_RECALIB);
3324 status->excessive_retries++;
3325 break;
3326 case 0x40:
3327 err = "Tx buffer overflow";
3328 adev->stats.tx_fifo_errors++;
3329 break;
3330 case 0x80:
3331 /* possibly ACPI C-state powersaving related!!!
3332 * (DMA timeout due to excessively high wakeup
3333 * latency after C-state activation!?)
3334 * Disable C-State powersaving and try again,
3335 * then PLEASE REPORT, I'm VERY interested in
3336 * whether my theory is correct that this is
3337 * actually the problem here.
3338 * In that case, use new Linux idle wakeup latency
3339 * requirements kernel API to prevent this issue. */
3340 err = "DMA error";
3341 /* adev->wstats.discard.misc++; */
3342 break;
3344 adev->stats.tx_errors++;
3345 if (adev->stats.tx_errors <= 20)
3346 printk("%s: tx error 0x%02X, buf %02u! (%s)\n",
3347 wiphy_name(adev->ieee->wiphy), error, finger, err);
3348 else
3349 printk("%s: tx error 0x%02X, buf %02u!\n",
3350 wiphy_name(adev->ieee->wiphy), error, finger);
3354 unsigned int acxpci_l_clean_txdesc(acx_device_t * adev)
3356 txdesc_t *txdesc;
3357 txhostdesc_t *hostdesc;
3358 unsigned finger;
3359 int num_cleaned;
3360 u16 r111;
3361 u8 error, ack_failures, rts_failures, rts_ok, r100;
3363 FN_ENTER;
3365 if (unlikely(acx_debug & L_DEBUG))
3366 log_txbuffer(adev);
3368 log(L_BUFT, "tx: cleaning up bufs from %u\n", adev->tx_tail);
3370 /* We know first descr which is not free yet. We advance it as far
3371 ** as we see correct bits set in following descs (if next desc
3372 ** is NOT free, we shouldn't advance at all). We know that in
3373 ** front of tx_tail may be "holes" with isolated free descs.
3374 ** We will catch up when all intermediate descs will be freed also */
3376 finger = adev->tx_tail;
3377 num_cleaned = 0;
3378 while (likely(finger != adev->tx_head)) {
3379 txdesc = get_txdesc(adev, finger);
3381 /* If we allocated txdesc on tx path but then decided
3382 ** to NOT use it, then it will be left as a free "bubble"
3383 ** in the "allocated for tx" part of the ring.
3384 ** We may meet it on the next ring pass here. */
3386 /* stop if not marked as "tx finished" and "host owned" */
3387 if ((txdesc->Ctl_8 & DESC_CTL_ACXDONE_HOSTOWN)
3388 != DESC_CTL_ACXDONE_HOSTOWN) {
3389 if (unlikely(!num_cleaned)) { /* maybe remove completely */
3390 log(L_BUFT, "clean_txdesc: tail isn't free. "
3391 "tail:%d head:%d\n",
3392 adev->tx_tail, adev->tx_head);
3394 break;
3397 /* remember desc values... */
3398 error = txdesc->error;
3399 ack_failures = txdesc->ack_failures;
3400 rts_failures = txdesc->rts_failures;
3401 rts_ok = txdesc->rts_ok;
3402 r100 = txdesc->u.r1.rate;
3403 r111 = le16_to_cpu(txdesc->u.r2.rate111);
3405 /* need to check for certain error conditions before we
3406 * clean the descriptor: we still need valid descr data here */
3407 hostdesc = get_txhostdesc(adev, txdesc);
3409 hostdesc->txstatus.flags |= IEEE80211_TX_STATUS_ACK;
3410 if (unlikely(0x30 & error)) {
3411 /* only send IWEVTXDROP in case of retry or lifetime exceeded;
3412 * all other errors mean we screwed up locally */
3413 /* union iwreq_data wrqu;
3414 struct ieee80211_hdr_3addr *hdr;
3415 hdr = (struct ieee80211_hdr_3addr *) hostdesc->data;
3416 MAC_COPY(wrqu.addr.sa_data, hdr->addr1);
3418 hostdesc->txstatus.flags &= ~IEEE80211_TX_STATUS_ACK;
3421 /* ...and free the desc */
3422 txdesc->error = 0;
3423 txdesc->ack_failures = 0;
3424 txdesc->rts_failures = 0;
3425 txdesc->rts_ok = 0;
3426 /* signal host owning it LAST, since ACX already knows that this
3427 ** descriptor is finished since it set Ctl_8 accordingly. */
3428 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3430 adev->tx_free++;
3431 num_cleaned++;
3433 if ((adev->tx_free >= TX_START_QUEUE)
3434 /* && (adev->status == ACX_STATUS_4_ASSOCIATED) */
3435 /*&& (acx_queue_stopped(adev->ieee))*/
3437 log(L_BUF, "tx: wake queue (avail. Tx desc %u)\n",
3438 adev->tx_free);
3439 acx_wake_queue(adev->ieee, NULL);
3442 /* do error checking, rate handling and logging
3443 * AFTER having done the work, it's faster */
3445 /* Rate handling is done in mac80211 */
3446 /* if (adev->rate_auto) {
3447 struct client *clt = get_txc(adev, txdesc);
3448 if (clt) {
3449 u16 cur = get_txr(adev, txdesc);
3450 if (clt->rate_cur == cur) {
3451 acx_l_handle_txrate_auto(adev, clt, cur,*/ /* intended rate */
3452 /*r100, r111,*/ /* actually used rate */
3453 /*(error & 0x30),*/ /* was there an error? */
3454 /* TX_CNT +
3455 TX_CLEAN_BACKLOG
3457 adev->tx_free);
3462 if (unlikely(error))
3463 handle_tx_error(adev, error, finger, &hostdesc->txstatus);
3465 if (IS_ACX111(adev))
3466 log(L_BUFT,
3467 "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u r111=%04X tx_free=%u\n",
3468 finger, ack_failures, rts_failures, rts_ok, r111, adev->tx_free);
3469 else
3470 log(L_BUFT,
3471 "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u rate=%u\n",
3472 finger, ack_failures, rts_failures, rts_ok, r100);
3474 /* And finally report upstream */
3475 if (hostdesc)
3477 hostdesc->txstatus.excessive_retries = rts_failures ;
3478 hostdesc->txstatus.retry_count = ack_failures;
3479 ieee80211_tx_status(adev->ieee,hostdesc->skb,&hostdesc->txstatus);
3480 memset(&hostdesc->txstatus, 0, sizeof(struct ieee80211_tx_status));
3482 /* update pointer for descr to be cleaned next */
3483 finger = (finger + 1) % TX_CNT;
3485 /* remember last position */
3486 adev->tx_tail = finger;
3487 /* end: */
3488 FN_EXIT1(num_cleaned);
3489 return num_cleaned;
3492 /* clean *all* Tx descriptors, and regardless of their previous state.
3493 * Used for brute-force reset handling. */
3494 void acxpci_l_clean_txdesc_emergency(acx_device_t * adev)
3496 txdesc_t *txdesc;
3497 int i;
3499 FN_ENTER;
3501 for (i = 0; i < TX_CNT; i++) {
3502 txdesc = get_txdesc(adev, i);
3504 /* free it */
3505 txdesc->ack_failures = 0;
3506 txdesc->rts_failures = 0;
3507 txdesc->rts_ok = 0;
3508 txdesc->error = 0;
3509 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3512 adev->tx_free = TX_CNT;
3514 FN_EXIT0;
3518 /***********************************************************************
3519 ** acxpci_s_create_tx_host_desc_queue
3522 static void *allocate(acx_device_t * adev, size_t size, dma_addr_t * phy,
3523 const char *msg)
3525 void *ptr;
3527 ptr = dma_alloc_coherent(adev->pdev ? &adev->pdev->dev : NULL,
3528 size, phy, GFP_KERNEL);
3530 if (ptr) {
3531 log(L_DEBUG, "%s sz=%d adr=0x%p phy=0x%08llx\n",
3532 msg, (int)size, ptr, (unsigned long long)*phy);
3533 memset(ptr, 0, size);
3534 return ptr;
3536 printk(KERN_ERR "acx: %s allocation FAILED (%d bytes)\n",
3537 msg, (int)size);
3538 return NULL;
3542 static int acxpci_s_create_tx_host_desc_queue(acx_device_t * adev)
3544 txhostdesc_t *hostdesc;
3545 u8 *txbuf;
3546 dma_addr_t hostdesc_phy;
3547 dma_addr_t txbuf_phy;
3548 int i;
3550 FN_ENTER;
3552 /* allocate TX buffer */
3553 adev->txbuf_area_size = TX_CNT * /*WLAN_A4FR_MAXLEN_WEP_FCS*/ (30 + 2312 + 4);
3554 adev->txbuf_start = allocate(adev, adev->txbuf_area_size,
3555 &adev->txbuf_startphy, "txbuf_start");
3556 if (!adev->txbuf_start)
3557 goto fail;
3559 /* allocate the TX host descriptor queue pool */
3560 adev->txhostdesc_area_size = TX_CNT * 2 * sizeof(*hostdesc);
3561 adev->txhostdesc_start = allocate(adev, adev->txhostdesc_area_size,
3562 &adev->txhostdesc_startphy,
3563 "txhostdesc_start");
3564 if (!adev->txhostdesc_start)
3565 goto fail;
3566 /* check for proper alignment of TX host descriptor pool */
3567 if ((long)adev->txhostdesc_start & 3) {
3568 printk
3569 ("acx: driver bug: dma alloc returns unaligned address\n");
3570 goto fail;
3573 hostdesc = adev->txhostdesc_start;
3574 hostdesc_phy = adev->txhostdesc_startphy;
3575 txbuf = adev->txbuf_start;
3576 txbuf_phy = adev->txbuf_startphy;
3578 #if 0
3579 /* Each tx buffer is accessed by hardware via
3580 ** txdesc -> txhostdesc(s) -> txbuffer(s).
3581 ** We use only one txhostdesc per txdesc, but it looks like
3582 ** acx111 is buggy: it accesses second txhostdesc
3583 ** (via hostdesc.desc_phy_next field) even if
3584 ** txdesc->length == hostdesc->length and thus
3585 ** entire packet was placed into first txhostdesc.
3586 ** Due to this bug acx111 hangs unless second txhostdesc
3587 ** has le16_to_cpu(hostdesc.length) = 3 (or larger)
3588 ** Storing NULL into hostdesc.desc_phy_next
3589 ** doesn't seem to help.
3591 ** Update: although it worked on Xterasys XN-2522g
3592 ** with len=3 trick, WG311v2 is even more bogus, doesn't work.
3593 ** Keeping this code (#ifdef'ed out) for documentational purposes.
3595 for (i = 0; i < TX_CNT * 2; i++) {
3596 hostdesc_phy += sizeof(*hostdesc);
3597 if (!(i & 1)) {
3598 hostdesc->data_phy = cpu2acx(txbuf_phy);
3599 /* hostdesc->data_offset = ... */
3600 /* hostdesc->reserved = ... */
3601 hostdesc->Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
3602 /* hostdesc->length = ... */
3603 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3604 hostdesc->pNext = ptr2acx(NULL);
3605 /* hostdesc->Status = ... */
3606 /* below: non-hardware fields */
3607 hostdesc->data = txbuf;
3609 txbuf += WLAN_A4FR_MAXLEN_WEP_FCS;
3610 txbuf_phy += WLAN_A4FR_MAXLEN_WEP_FCS;
3611 } else {
3612 /* hostdesc->data_phy = ... */
3613 /* hostdesc->data_offset = ... */
3614 /* hostdesc->reserved = ... */
3615 /* hostdesc->Ctl_16 = ... */
3616 hostdesc->length = cpu_to_le16(3); /* bug workaround */
3617 /* hostdesc->desc_phy_next = ... */
3618 /* hostdesc->pNext = ... */
3619 /* hostdesc->Status = ... */
3620 /* below: non-hardware fields */
3621 /* hostdesc->data = ... */
3623 hostdesc++;
3625 #endif
3626 /* We initialize two hostdescs so that they point to adjacent
3627 ** memory areas. Thus txbuf is really just a contiguous memory area */
3628 for (i = 0; i < TX_CNT * 2; i++) {
3629 hostdesc_phy += sizeof(*hostdesc);
3631 hostdesc->data_phy = cpu2acx(txbuf_phy);
3632 /* done by memset(0): hostdesc->data_offset = 0; */
3633 /* hostdesc->reserved = ... */
3634 hostdesc->Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
3635 /* hostdesc->length = ... */
3636 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3637 /* done by memset(0): hostdesc->pNext = ptr2acx(NULL); */
3638 /* hostdesc->Status = ... */
3639 /* ->data is a non-hardware field: */
3640 hostdesc->data = txbuf;
3642 if (!(i & 1)) {
3643 txbuf += 24 /*WLAN_HDR_A3_LEN*/;
3644 txbuf_phy += 24 /*WLAN_HDR_A3_LEN*/;
3645 } else {
3646 txbuf += 30 + 2132 + 4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3647 txbuf_phy += 30 + 2132 +4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3649 hostdesc++;
3651 hostdesc--;
3652 hostdesc->desc_phy_next = cpu2acx(adev->txhostdesc_startphy);
3654 FN_EXIT1(OK);
3655 return OK;
3656 fail:
3657 printk("acx: create_tx_host_desc_queue FAILED\n");
3658 /* dealloc will be done by free function on error case */
3659 FN_EXIT1(NOT_OK);
3660 return NOT_OK;
3664 /***************************************************************
3665 ** acxpci_s_create_rx_host_desc_queue
3667 /* the whole size of a data buffer (header plus data body)
3668 * plus 32 bytes safety offset at the end */
3669 #define RX_BUFFER_SIZE (sizeof(rxbuffer_t) + 32)
3671 static int acxpci_s_create_rx_host_desc_queue(acx_device_t * adev)
3673 rxhostdesc_t *hostdesc;
3674 rxbuffer_t *rxbuf;
3675 dma_addr_t hostdesc_phy;
3676 dma_addr_t rxbuf_phy;
3677 int i;
3679 FN_ENTER;
3681 /* allocate the RX host descriptor queue pool */
3682 adev->rxhostdesc_area_size = RX_CNT * sizeof(*hostdesc);
3683 adev->rxhostdesc_start = allocate(adev, adev->rxhostdesc_area_size,
3684 &adev->rxhostdesc_startphy,
3685 "rxhostdesc_start");
3686 if (!adev->rxhostdesc_start)
3687 goto fail;
3688 /* check for proper alignment of RX host descriptor pool */
3689 if ((long)adev->rxhostdesc_start & 3) {
3690 printk
3691 ("acx: driver bug: dma alloc returns unaligned address\n");
3692 goto fail;
3695 /* allocate Rx buffer pool which will be used by the acx
3696 * to store the whole content of the received frames in it */
3697 adev->rxbuf_area_size = RX_CNT * RX_BUFFER_SIZE;
3698 adev->rxbuf_start = allocate(adev, adev->rxbuf_area_size,
3699 &adev->rxbuf_startphy, "rxbuf_start");
3700 if (!adev->rxbuf_start)
3701 goto fail;
3703 rxbuf = adev->rxbuf_start;
3704 rxbuf_phy = adev->rxbuf_startphy;
3705 hostdesc = adev->rxhostdesc_start;
3706 hostdesc_phy = adev->rxhostdesc_startphy;
3708 /* don't make any popular C programming pointer arithmetic mistakes
3709 * here, otherwise I'll kill you...
3710 * (and don't dare asking me why I'm warning you about that...) */
3711 for (i = 0; i < RX_CNT; i++) {
3712 hostdesc->data = rxbuf;
3713 hostdesc->data_phy = cpu2acx(rxbuf_phy);
3714 hostdesc->length = cpu_to_le16(RX_BUFFER_SIZE);
3715 CLEAR_BIT(hostdesc->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3716 rxbuf++;
3717 rxbuf_phy += sizeof(*rxbuf);
3718 hostdesc_phy += sizeof(*hostdesc);
3719 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3720 hostdesc++;
3722 hostdesc--;
3723 hostdesc->desc_phy_next = cpu2acx(adev->rxhostdesc_startphy);
3724 FN_EXIT1(OK);
3725 return OK;
3726 fail:
3727 printk("acx: create_rx_host_desc_queue FAILED\n");
3728 /* dealloc will be done by free function on error case */
3729 FN_EXIT1(NOT_OK);
3730 return NOT_OK;
3734 /***************************************************************
3735 ** acxpci_s_create_hostdesc_queues
3737 int acxpci_s_create_hostdesc_queues(acx_device_t * adev)
3739 int result;
3740 result = acxpci_s_create_tx_host_desc_queue(adev);
3741 if (OK != result)
3742 return result;
3743 result = acxpci_s_create_rx_host_desc_queue(adev);
3744 return result;
3748 /***************************************************************
3749 ** acxpci_create_tx_desc_queue
3751 static void acxpci_create_tx_desc_queue(acx_device_t * adev, u32 tx_queue_start)
3753 txdesc_t *txdesc;
3754 txhostdesc_t *hostdesc;
3755 dma_addr_t hostmemptr;
3756 u32 mem_offs;
3757 int i;
3759 FN_ENTER;
3761 if (IS_ACX100(adev))
3762 adev->txdesc_size = sizeof(*txdesc);
3763 else
3764 /* the acx111 txdesc is 4 bytes larger */
3765 adev->txdesc_size = sizeof(*txdesc) + 4;
3767 adev->txdesc_start = (txdesc_t *) (adev->iobase2 + tx_queue_start);
3769 log(L_DEBUG, "adev->iobase2=%p\n"
3770 "tx_queue_start=%08X\n"
3771 "adev->txdesc_start=%p\n",
3772 adev->iobase2, tx_queue_start, adev->txdesc_start);
3774 adev->tx_free = TX_CNT;
3775 /* done by memset: adev->tx_head = 0; */
3776 /* done by memset: adev->tx_tail = 0; */
3777 txdesc = adev->txdesc_start;
3778 mem_offs = tx_queue_start;
3779 hostmemptr = adev->txhostdesc_startphy;
3780 hostdesc = adev->txhostdesc_start;
3782 if (IS_ACX111(adev)) {
3783 /* ACX111 has a preinitialized Tx buffer! */
3784 /* loop over whole send pool */
3785 /* FIXME: do we have to do the hostmemptr stuff here?? */
3786 for (i = 0; i < TX_CNT; i++) {
3787 txdesc->HostMemPtr = ptr2acx(hostmemptr);
3788 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3789 /* reserve two (hdr desc and payload desc) */
3790 hostdesc += 2;
3791 hostmemptr += 2 * sizeof(*hostdesc);
3792 txdesc = advance_txdesc(adev, txdesc, 1);
3794 } else {
3795 /* ACX100 Tx buffer needs to be initialized by us */
3796 /* clear whole send pool. sizeof is safe here (we are acx100) */
3797 memset(adev->txdesc_start, 0, TX_CNT * sizeof(*txdesc));
3799 /* loop over whole send pool */
3800 for (i = 0; i < TX_CNT; i++) {
3801 log(L_DEBUG, "configure card tx descriptor: 0x%p, "
3802 "size: 0x%X\n", txdesc, adev->txdesc_size);
3804 /* pointer to hostdesc memory */
3805 txdesc->HostMemPtr = ptr2acx(hostmemptr);
3806 /* initialise ctl */
3807 txdesc->Ctl_8 = (DESC_CTL_HOSTOWN | DESC_CTL_RECLAIM
3808 | DESC_CTL_AUTODMA |
3809 DESC_CTL_FIRSTFRAG);
3810 /* done by memset(0): txdesc->Ctl2_8 = 0; */
3811 /* point to next txdesc */
3812 txdesc->pNextDesc =
3813 cpu2acx(mem_offs + adev->txdesc_size);
3814 /* reserve two (hdr desc and payload desc) */
3815 hostdesc += 2;
3816 hostmemptr += 2 * sizeof(*hostdesc);
3817 /* go to the next one */
3818 mem_offs += adev->txdesc_size;
3819 /* ++ is safe here (we are acx100) */
3820 txdesc++;
3822 /* go back to the last one */
3823 txdesc--;
3824 /* and point to the first making it a ring buffer */
3825 txdesc->pNextDesc = cpu2acx(tx_queue_start);
3827 FN_EXIT0;
3831 /***************************************************************
3832 ** acxpci_create_rx_desc_queue
3834 static void acxpci_create_rx_desc_queue(acx_device_t * adev, u32 rx_queue_start)
3836 rxdesc_t *rxdesc;
3837 u32 mem_offs;
3838 int i;
3840 FN_ENTER;
3842 /* done by memset: adev->rx_tail = 0; */
3844 /* ACX111 doesn't need any further config: preconfigures itself.
3845 * Simply print ring buffer for debugging */
3846 if (IS_ACX111(adev)) {
3847 /* rxdesc_start already set here */
3849 adev->rxdesc_start =
3850 (rxdesc_t *) ((u8 *) adev->iobase2 + rx_queue_start);
3852 rxdesc = adev->rxdesc_start;
3853 for (i = 0; i < RX_CNT; i++) {
3854 log(L_DEBUG, "rx descriptor %d @ 0x%p\n", i, rxdesc);
3855 rxdesc = adev->rxdesc_start = (rxdesc_t *)
3856 (adev->iobase2 + acx2cpu(rxdesc->pNextDesc));
3858 } else {
3859 /* we didn't pre-calculate rxdesc_start in case of ACX100 */
3860 /* rxdesc_start should be right AFTER Tx pool */
3861 adev->rxdesc_start = (rxdesc_t *)
3862 ((u8 *) adev->txdesc_start + (TX_CNT * sizeof(txdesc_t)));
3863 /* NB: sizeof(txdesc_t) above is valid because we know
3864 ** we are in if (acx100) block. Beware of cut-n-pasting elsewhere!
3865 ** acx111's txdesc is larger! */
3867 memset(adev->rxdesc_start, 0, RX_CNT * sizeof(*rxdesc));
3869 /* loop over whole receive pool */
3870 rxdesc = adev->rxdesc_start;
3871 mem_offs = rx_queue_start;
3872 for (i = 0; i < RX_CNT; i++) {
3873 log(L_DEBUG, "rx descriptor @ 0x%p\n", rxdesc);
3874 rxdesc->Ctl_8 = DESC_CTL_RECLAIM | DESC_CTL_AUTODMA;
3875 /* point to next rxdesc */
3876 rxdesc->pNextDesc = cpu2acx(mem_offs + sizeof(*rxdesc));
3877 /* go to the next one */
3878 mem_offs += sizeof(*rxdesc);
3879 rxdesc++;
3881 /* go to the last one */
3882 rxdesc--;
3884 /* and point to the first making it a ring buffer */
3885 rxdesc->pNextDesc = cpu2acx(rx_queue_start);
3887 FN_EXIT0;
3891 /***************************************************************
3892 ** acxpci_create_desc_queues
3894 void
3895 acxpci_create_desc_queues(acx_device_t * adev, u32 tx_queue_start,
3896 u32 rx_queue_start)
3898 acxpci_create_tx_desc_queue(adev, tx_queue_start);
3899 acxpci_create_rx_desc_queue(adev, rx_queue_start);
3903 /***************************************************************
3904 ** acxpci_s_proc_diag_output
3906 char *acxpci_s_proc_diag_output(char *p, acx_device_t * adev)
3908 const char *rtl, *thd, *ttl;
3909 rxhostdesc_t *rxhostdesc;
3910 txdesc_t *txdesc;
3911 int i;
3913 FN_ENTER;
3915 p += sprintf(p, "** Rx buf **\n");
3916 rxhostdesc = adev->rxhostdesc_start;
3917 if (rxhostdesc)
3918 for (i = 0; i < RX_CNT; i++) {
3919 rtl = (i == adev->rx_tail) ? " [tail]" : "";
3920 if ((rxhostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
3921 && (rxhostdesc->
3922 Status & cpu_to_le32(DESC_STATUS_FULL)))
3923 p += sprintf(p, "%02u FULL%s\n", i, rtl);
3924 else
3925 p += sprintf(p, "%02u empty%s\n", i, rtl);
3926 rxhostdesc++;
3928 /* p += sprintf(p, "** Tx buf (free %d, Linux netqueue %s) **\n",
3929 adev->tx_free,
3930 acx_queue_stopped(adev->ieee) ? "STOPPED" : "running");*/
3931 txdesc = adev->txdesc_start;
3932 if (txdesc)
3933 for (i = 0; i < TX_CNT; i++) {
3934 thd = (i == adev->tx_head) ? " [head]" : "";
3935 ttl = (i == adev->tx_tail) ? " [tail]" : "";
3936 if (txdesc->Ctl_8 & DESC_CTL_ACXDONE)
3937 p += sprintf(p, "%02u free (%02X)%s%s\n", i,
3938 txdesc->Ctl_8, thd, ttl);
3939 else
3940 p += sprintf(p, "%02u tx (%02X)%s%s\n", i,
3941 txdesc->Ctl_8, thd, ttl);
3942 txdesc = advance_txdesc(adev, txdesc, 1);
3944 p += sprintf(p,
3945 "\n"
3946 "** PCI data **\n"
3947 "txbuf_start %p, txbuf_area_size %u, txbuf_startphy %08llx\n"
3948 "txdesc_size %u, txdesc_start %p\n"
3949 "txhostdesc_start %p, txhostdesc_area_size %u, txhostdesc_startphy %08llx\n"
3950 "rxdesc_start %p\n"
3951 "rxhostdesc_start %p, rxhostdesc_area_size %u, rxhostdesc_startphy %08llx\n"
3952 "rxbuf_start %p, rxbuf_area_size %u, rxbuf_startphy %08llx\n",
3953 adev->txbuf_start, adev->txbuf_area_size,
3954 (unsigned long long)adev->txbuf_startphy,
3955 adev->txdesc_size, adev->txdesc_start,
3956 adev->txhostdesc_start, adev->txhostdesc_area_size,
3957 (unsigned long long)adev->txhostdesc_startphy,
3958 adev->rxdesc_start,
3959 adev->rxhostdesc_start, adev->rxhostdesc_area_size,
3960 (unsigned long long)adev->rxhostdesc_startphy,
3961 adev->rxbuf_start, adev->rxbuf_area_size,
3962 (unsigned long long)adev->rxbuf_startphy);
3964 FN_EXIT0;
3965 return p;
3969 /***********************************************************************
3971 int acxpci_proc_eeprom_output(char *buf, acx_device_t * adev)
3973 char *p = buf;
3974 int i;
3976 FN_ENTER;
3978 for (i = 0; i < 0x400; i++) {
3979 acxpci_read_eeprom_byte(adev, i, p++);
3982 FN_EXIT1(p - buf);
3983 return p - buf;
3987 /***********************************************************************
3988 ** Obvious
3990 void acxpci_set_interrupt_mask(acx_device_t * adev)
3992 if (IS_ACX111(adev)) {
3993 adev->irq_mask = (u16) ~ (0
3994 /* | HOST_INT_RX_DATA */
3995 | HOST_INT_TX_COMPLETE
3996 /* | HOST_INT_TX_XFER */
3997 | HOST_INT_RX_COMPLETE
3998 /* | HOST_INT_DTIM */
3999 /* | HOST_INT_BEACON */
4000 /* | HOST_INT_TIMER */
4001 /* | HOST_INT_KEY_NOT_FOUND */
4002 | HOST_INT_IV_ICV_FAILURE
4003 | HOST_INT_CMD_COMPLETE
4004 | HOST_INT_INFO
4005 /* | HOST_INT_OVERFLOW */
4006 /* | HOST_INT_PROCESS_ERROR */
4007 | HOST_INT_SCAN_COMPLETE
4008 | HOST_INT_FCS_THRESHOLD
4009 /* | HOST_INT_UNKNOWN */
4011 /* Or else acx100 won't signal cmd completion, right? */
4012 adev->irq_mask_off = (u16) ~ (HOST_INT_CMD_COMPLETE); /* 0xfdff */
4013 } else {
4014 adev->irq_mask = (u16) ~ (0
4015 /* | HOST_INT_RX_DATA */
4016 | HOST_INT_TX_COMPLETE
4017 /* | HOST_INT_TX_XFER */
4018 | HOST_INT_RX_COMPLETE
4019 /* | HOST_INT_DTIM */
4020 /* | HOST_INT_BEACON */
4021 /* | HOST_INT_TIMER */
4022 /* | HOST_INT_KEY_NOT_FOUND */
4023 /* | HOST_INT_IV_ICV_FAILURE */
4024 | HOST_INT_CMD_COMPLETE
4025 | HOST_INT_INFO
4026 /* | HOST_INT_OVERFLOW */
4027 /* | HOST_INT_PROCESS_ERROR */
4028 | HOST_INT_SCAN_COMPLETE
4029 /* | HOST_INT_FCS_THRESHOLD */
4030 /* | HOST_INT_UNKNOWN */
4032 adev->irq_mask_off = (u16) ~ (HOST_INT_UNKNOWN); /* 0x7fff */
4037 /***********************************************************************
4039 int acx100pci_s_set_tx_level(acx_device_t * adev, u8 level_dbm)
4041 /* since it can be assumed that at least the Maxim radio has a
4042 * maximum power output of 20dBm and since it also can be
4043 * assumed that these values drive the DAC responsible for
4044 * setting the linear Tx level, I'd guess that these values
4045 * should be the corresponding linear values for a dBm value,
4046 * in other words: calculate the values from that formula:
4047 * Y [dBm] = 10 * log (X [mW])
4048 * then scale the 0..63 value range onto the 1..100mW range (0..20 dBm)
4049 * and you're done...
4050 * Hopefully that's ok, but you never know if we're actually
4051 * right... (especially since Windows XP doesn't seem to show
4052 * actual Tx dBm values :-P) */
4054 /* NOTE: on Maxim, value 30 IS 30mW, and value 10 IS 10mW - so the
4055 * values are EXACTLY mW!!! Not sure about RFMD and others,
4056 * though... */
4057 static const u8 dbm2val_maxim[21] = {
4058 63, 63, 63, 62,
4059 61, 61, 60, 60,
4060 59, 58, 57, 55,
4061 53, 50, 47, 43,
4062 38, 31, 23, 13,
4065 static const u8 dbm2val_rfmd[21] = {
4066 0, 0, 0, 1,
4067 2, 2, 3, 3,
4068 4, 5, 6, 8,
4069 10, 13, 16, 20,
4070 25, 32, 41, 50,
4073 const u8 *table;
4075 switch (adev->radio_type) {
4076 case RADIO_MAXIM_0D:
4077 table = &dbm2val_maxim[0];
4078 break;
4079 case RADIO_RFMD_11:
4080 case RADIO_RALINK_15:
4081 table = &dbm2val_rfmd[0];
4082 break;
4083 default:
4084 printk("%s: unknown/unsupported radio type, "
4085 "cannot modify tx power level yet!\n", wiphy_name(adev->ieee->wiphy));
4086 return NOT_OK;
4088 printk("%s: changing radio power level to %u dBm (%u)\n",
4089 wiphy_name(adev->ieee->wiphy), level_dbm, table[level_dbm]);
4090 acxpci_s_write_phy_reg(adev, 0x11, table[level_dbm]);
4091 return OK;
4094 #ifdef CONFIG_VLYNQ
4095 struct vlynq_reg_config {
4096 u32 offset;
4097 u32 value;
4100 struct vlynq_known {
4101 u32 chip_id;
4102 char name[32];
4103 struct vlynq_mapping rx_mapping[4];
4104 int irq;
4105 int irq_type;
4106 int num_regs;
4107 struct vlynq_reg_config regs[10];
4110 #define CHIP_TNETW1130 0x00000009
4111 #define CHIP_TNETW1350 0x00000029
4113 static struct vlynq_known known_devices[] = {
4115 .chip_id = CHIP_TNETW1130, .name = "TI TNETW1130",
4116 .rx_mapping = {
4117 { .size = 0x22000, .offset = 0xf0000000 },
4118 { .size = 0x40000, .offset = 0xc0000000 },
4119 { .size = 0x0, .offset = 0x0 },
4120 { .size = 0x0, .offset = 0x0 },
4122 .irq = 0,
4123 .irq_type = IRQ_TYPE_EDGE_RISING,
4124 .num_regs = 5,
4125 .regs = {
4127 .offset = 0x790,
4128 .value = (0xd0000000 - PHYS_OFFSET)
4131 .offset = 0x794,
4132 .value = (0xd0000000 - PHYS_OFFSET)
4134 { .offset = 0x740, .value = 0 },
4135 { .offset = 0x744, .value = 0x00010000 },
4136 { .offset = 0x764, .value = 0x00010000 },
4140 .chip_id = CHIP_TNETW1350, .name = "TI TNETW1350",
4141 .rx_mapping = {
4142 { .size = 0x100000, .offset = 0x00300000 },
4143 { .size = 0x80000, .offset = 0x00000000 },
4144 { .size = 0x0, .offset = 0x0 },
4145 { .size = 0x0, .offset = 0x0 },
4147 .irq = 0,
4148 .irq_type = IRQ_TYPE_EDGE_RISING,
4149 .num_regs = 5,
4150 .regs = {
4152 .offset = 0x790,
4153 .value = (0x60000000 - PHYS_OFFSET)
4156 .offset = 0x794,
4157 .value = (0x60000000 - PHYS_OFFSET)
4159 { .offset = 0x740, .value = 0 },
4160 { .offset = 0x744, .value = 0x00010000 },
4161 { .offset = 0x764, .value = 0x00010000 },
4166 static struct vlynq_device_id acx_vlynq_id[] = {
4167 { CHIP_TNETW1130, vlynq_div_auto, 0 },
4168 { CHIP_TNETW1350, vlynq_div_auto, 1 },
4169 { 0, 0, 0 },
4172 static __devinit int vlynq_probe(struct vlynq_device *vdev,
4173 struct vlynq_device_id *id)
4175 int result = -EIO, i;
4176 u32 addr;
4177 struct ieee80211_hw *ieee;
4178 acx_device_t *adev = NULL;
4179 acx111_ie_configoption_t co;
4180 struct vlynq_mapping mapping[4] = { { 0, }, };
4181 struct vlynq_known *match = NULL;
4183 FN_ENTER;
4184 result = vlynq_enable_device(vdev);
4185 if (result)
4186 return result;
4188 match = &known_devices[id->driver_data];
4190 if (!match) {
4191 result = -ENODEV;
4192 goto fail;
4195 mapping[0].offset = ARCH_PFN_OFFSET << PAGE_SHIFT;
4196 mapping[0].size = 0x02000000;
4197 vlynq_set_local_mapping(vdev, vdev->mem_start, mapping);
4198 vlynq_set_remote_mapping(vdev, 0, match->rx_mapping);
4200 set_irq_type(vlynq_virq_to_irq(vdev, match->irq), match->irq_type);
4202 addr = (u32)ioremap(vdev->mem_start, 0x1000);
4203 if (!addr) {
4204 printk(KERN_ERR "%s: failed to remap io memory\n",
4205 vdev->dev.bus_id);
4206 result = -ENXIO;
4207 goto fail;
4210 for (i = 0; i < match->num_regs; i++)
4211 iowrite32(match->regs[i].value,
4212 (u32 *)(addr + match->regs[i].offset));
4214 iounmap((void *)addr);
4216 ieee = ieee80211_alloc_hw(sizeof(struct acx_device), &acxpci_hw_ops);
4217 if (!ieee) {
4218 printk("acx: could not allocate ieee80211 structure %s\n",
4219 vdev->dev.bus_id);
4220 goto fail_alloc_netdev;
4222 ieee->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
4223 ieee->queues = 1;
4225 adev = ieee2adev(ieee);
4227 memset(adev, 0, sizeof(*adev));
4228 /** Set up our private interface **/
4229 spin_lock_init(&adev->lock); /* initial state: unlocked */
4230 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
4231 mutex_init(&adev->mutex);
4232 /* since nobody can see new netdev yet, we can as well
4233 ** just _presume_ that we're under sem (instead of actually taking it): */
4234 /* acx_sem_lock(adev); */
4235 adev->ieee = ieee;
4236 adev->vdev = vdev;
4237 adev->bus_dev = &vdev->dev;
4238 adev->dev_type = DEVTYPE_PCI;
4240 /** Finished with private interface **/
4242 vlynq_set_drvdata(vdev, ieee);
4243 if (!request_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start, "acx")) {
4244 printk("acx: cannot reserve VLYNQ memory region\n");
4245 goto fail_request_mem_region;
4247 adev->iobase = ioremap(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4248 if (!adev->iobase) {
4249 printk("acx: ioremap() FAILED\n");
4250 goto fail_ioremap;
4252 adev->iobase2 = adev->iobase + match->rx_mapping[0].size;
4253 adev->chip_type = CHIPTYPE_ACX111;
4254 adev->chip_name = match->name;
4255 adev->io = IO_ACX111;
4256 adev->irq = vlynq_virq_to_irq(vdev, match->irq);
4258 printk("acx: found %s-based wireless network card at %s, irq:%d, "
4259 "phymem:0x%x, mem:0x%p\n",
4260 match->name, vdev->dev.bus_id, adev->irq,
4261 vdev->mem_start, adev->iobase);
4262 log(L_ANY, "initial debug setting is 0x%04X\n", acx_debug);
4264 if (0 == adev->irq) {
4265 printk("acx: can't use IRQ 0\n");
4266 goto fail_irq;
4268 SET_IEEE80211_DEV(ieee, &vdev->dev);
4271 /* to find crashes due to weird driver access
4272 * to unconfigured interface (ifup) */
4273 adev->mgmt_timer.function = (void (*)(unsigned long))0x0000dead;
4276 /* ok, pci setup is finished, now start initializing the card */
4278 /* NB: read_reg() reads may return bogus data before reset_dev(),
4279 * since the firmware which directly controls large parts of the I/O
4280 * registers isn't initialized yet.
4281 * acx100 seems to be more affected than acx111 */
4282 if (OK != acxpci_s_reset_dev(adev))
4283 goto fail_reset;
4285 if (OK != acx_s_init_mac(adev))
4286 goto fail_init_mac;
4288 acx_s_interrogate(adev, &co, ACX111_IE_CONFIG_OPTIONS);
4289 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
4290 if (OK != acxpci_read_eeprom_byte(adev, 0x05, &adev->eeprom_version))
4291 goto fail_read_eeprom_version;
4293 acx_s_parse_configoption(adev, &co);
4294 acx_s_set_defaults(adev);
4295 acx_s_get_firmware_version(adev); /* needs to be after acx_s_init_mac() */
4296 acx_display_hardware_details(adev);
4298 /* Register the card, AFTER everything else has been set up,
4299 * since otherwise an ioctl could step on our feet due to
4300 * firmware operations happening in parallel or uninitialized data */
4303 acx_proc_register_entries(ieee);
4305 /* Now we have our device, so make sure the kernel doesn't try
4306 * to send packets even though we're not associated to a network yet */
4308 /* after register_netdev() userspace may start working with dev
4309 * (in particular, on other CPUs), we only need to up the sem */
4310 /* acx_sem_unlock(adev); */
4312 printk("acx " ACX_RELEASE ": net device %s, driver compiled "
4313 "against wireless extensions %d and Linux %s\n",
4314 wiphy_name(adev->ieee->wiphy), WIRELESS_EXT, UTS_RELEASE);
4316 MAC_COPY(adev->ieee->wiphy->perm_addr, adev->dev_addr);
4318 log(L_IRQ | L_INIT, "using IRQ %d\n", adev->irq);
4320 /** done with board specific setup **/
4322 acx_init_task_scheduler(adev);
4323 result = ieee80211_register_hw(adev->ieee);
4324 if (OK != result) {
4325 printk("acx: ieee80211_register_hw() FAILED: %d\n", result);
4326 goto fail_register_netdev;
4328 #if CMD_DISCOVERY
4329 great_inquisitor(adev);
4330 #endif
4332 result = OK;
4333 goto done;
4335 /* error paths: undo everything in reverse order... */
4338 acxpci_s_delete_dma_regions(adev);
4340 fail_init_mac:
4341 fail_read_eeprom_version:
4342 fail_reset:
4344 fail_alloc_netdev:
4345 fail_irq:
4347 iounmap(adev->iobase);
4348 fail_ioremap:
4350 release_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4351 fail_request_mem_region:
4352 fail_register_netdev:
4353 ieee80211_free_hw(ieee);
4354 fail:
4355 vlynq_disable_device(vdev);
4356 done:
4357 FN_EXIT1(result);
4358 return result;
4361 static void vlynq_remove(struct vlynq_device *vdev)
4363 struct ieee80211_hw *hw = vlynq_get_drvdata(vdev);
4364 acx_device_t *adev = ieee2adev(hw);
4365 unsigned long flags;
4366 FN_ENTER;
4368 if (!hw) {
4369 log(L_DEBUG, "%s: card is unused. Skipping any release code\n",
4370 __func__);
4371 goto end;
4375 acx_lock(adev, flags);
4376 acx_unlock(adev, flags);
4377 adev->initialized = 0;
4379 /* If device wasn't hot unplugged... */
4380 if (adev_present(adev)) {
4382 acx_sem_lock(adev);
4384 /* disable both Tx and Rx to shut radio down properly */
4385 if (adev->initialized) {
4386 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_TX, NULL, 0);
4387 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_RX, NULL, 0);
4389 acx_lock(adev, flags);
4390 /* disable power LED to save power :-) */
4391 log(L_INIT, "switching off power LED to save power\n");
4392 acxpci_l_power_led(adev, 0);
4393 /* stop our eCPU */
4394 acx_unlock(adev, flags);
4396 acx_sem_unlock(adev);
4399 /* unregister the device to not let the kernel
4400 * (e.g. ioctls) access a half-deconfigured device
4401 * NB: this will cause acxpci_e_close() to be called,
4402 * thus we shouldn't call it under sem!
4403 * Well, netdev did, but ieee80211 stack does not, so we
4404 * have to do so manually...
4406 acxpci_e_close(hw);
4407 log(L_INIT, "removing device %s\n", wiphy_name(adev->ieee->wiphy));
4408 ieee80211_unregister_hw(adev->ieee);
4410 /* unregister_netdev ensures that no references to us left.
4411 * For paranoid reasons we continue to follow the rules */
4412 acx_sem_lock(adev);
4414 if (adev->dev_state_mask & ACX_STATE_IFACE_UP) {
4415 acxpci_s_down(hw);
4416 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
4419 acx_proc_unregister_entries(adev->ieee);
4421 /* finally, clean up PCI bus state */
4422 acxpci_s_delete_dma_regions(adev);
4423 if (adev->iobase)
4424 iounmap(adev->iobase);
4425 if (adev->iobase2)
4426 iounmap(adev->iobase2);
4427 release_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4429 /* remove dev registration */
4431 acx_sem_unlock(adev);
4432 vlynq_disable_device(vdev);
4434 /* Free netdev (quite late,
4435 * since otherwise we might get caught off-guard
4436 * by a netdev timeout handler execution
4437 * expecting to see a working dev...) */
4438 ieee80211_free_hw(adev->ieee);
4440 end:
4441 FN_EXIT0;
4444 static struct vlynq_driver vlynq_acx = {
4445 .name = "acx_vlynq",
4446 .id_table = acx_vlynq_id,
4447 .probe = vlynq_probe,
4448 .remove = __devexit_p(vlynq_remove),
4450 #endif /* CONFIG_VLYNQ */
4453 /***********************************************************************
4454 ** Data for init_module/cleanup_module
4456 #ifdef CONFIG_PCI
4457 static const struct pci_device_id acxpci_id_tbl[] __devinitdata = {
4459 .vendor = PCI_VENDOR_ID_TI,
4460 .device = PCI_DEVICE_ID_TI_TNETW1100A,
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_TNETW1100B,
4468 .subvendor = PCI_ANY_ID,
4469 .subdevice = PCI_ANY_ID,
4470 .driver_data = CHIPTYPE_ACX100,
4473 .vendor = PCI_VENDOR_ID_TI,
4474 .device = PCI_DEVICE_ID_TI_TNETW1130,
4475 .subvendor = PCI_ANY_ID,
4476 .subdevice = PCI_ANY_ID,
4477 .driver_data = CHIPTYPE_ACX111,
4480 .vendor = 0,
4481 .device = 0,
4482 .subvendor = 0,
4483 .subdevice = 0,
4484 .driver_data = 0,
4488 MODULE_DEVICE_TABLE(pci, acxpci_id_tbl);
4490 /* FIXME: checks should be removed once driver is included in the kernel */
4491 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 11)
4492 /* pci_name() got introduced at start of 2.6.x,
4493 * got mandatory (slot_name member removed) in 2.6.11-bk1 */
4494 #define pci_name(x) x->slot_name
4495 #endif
4497 static struct pci_driver
4498 acxpci_drv_id = {
4499 .name = "acx_pci",
4500 .id_table = acxpci_id_tbl,
4501 .probe = acxpci_e_probe,
4502 .remove = __devexit_p(acxpci_e_remove),
4503 #ifdef CONFIG_PM
4504 .suspend = acxpci_e_suspend,
4505 .resume = acxpci_e_resume
4506 #endif /* CONFIG_PM */
4508 #endif /* CONFIG_PCI */
4510 /***********************************************************************
4511 ** acxpci_e_init_module
4513 ** Module initialization routine, called once at module load time
4515 int __init acxpci_e_init_module(void)
4517 int res;
4519 FN_ENTER;
4521 #if (ACX_IO_WIDTH==32)
4522 printk("acx: compiled to use 32bit I/O access. "
4523 "I/O timing issues might occur, such as "
4524 "non-working firmware upload. Report them\n");
4525 #else
4526 printk("acx: compiled to use 16bit I/O access only "
4527 "(compatibility mode)\n");
4528 #endif
4530 #ifdef __LITTLE_ENDIAN
4531 #define ENDIANNESS_STRING "running on a little-endian CPU\n"
4532 #else
4533 #define ENDIANNESS_STRING "running on a BIG-ENDIAN CPU\n"
4534 #endif
4535 log(L_INIT,
4536 "acx: " ENDIANNESS_STRING
4537 "acx: PCI/VLYNQ module " ACX_RELEASE " initialized, "
4538 "waiting for cards to probe...\n");
4540 #ifdef CONFIG_PCI
4541 res = pci_register_driver(&acxpci_drv_id);
4542 #endif
4543 #ifdef CONFIG_VLYNQ
4544 res = vlynq_register_driver(&vlynq_acx);
4545 #endif
4546 FN_EXIT1(res);
4547 return res;
4551 /***********************************************************************
4552 ** acxpci_e_cleanup_module
4554 ** Called at module unload time. This is our last chance to
4555 ** clean up after ourselves.
4557 void __exit acxpci_e_cleanup_module(void)
4559 FN_ENTER;
4561 #ifdef CONFIG_PCI
4562 pci_unregister_driver(&acxpci_drv_id);
4563 #endif
4564 #ifdef CONFIG_VLYNQ
4565 vlynq_unregister_driver(&vlynq_acx);
4566 #endif
4567 log(L_INIT,
4568 "acx: PCI module " ACX_RELEASE " unloaded\n");
4569 FN_EXIT0;