merged matteo's (rootkit85) code to support the vlynq bus (mostly used in PDA's and...
[acx-mac80211.git] / pci.c
blob9ab698fd5acd3a35a1e90ac92543f9440b16a7b2
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)
102 strncpy(info->bus_info,pci_name(adev->pdev), ETHTOOL_BUSINFO_LEN);
105 /***********************************************************************
106 ** Register access
111 /* OS I/O routines *always* be endianness-clean but having them doesn't hurt */
112 #define acx_readl(v) le32_to_cpu(readl((v)))
113 #define acx_readw(v) le16_to_cpu(readw((v)))
114 #define acx_writew(v,r) writew(le16_to_cpu((v)), r)
115 #define acx_writel(v,r) writel(le32_to_cpu((v)), r)
117 /* Pick one */
118 /* #define INLINE_IO static */
119 #define INLINE_IO static inline
121 INLINE_IO u32 read_reg32(acx_device_t * adev, unsigned int offset)
123 #if ACX_IO_WIDTH == 32
124 return acx_readl((u8 *) adev->iobase + adev->io[offset]);
125 #else
126 return acx_readw((u8 *) adev->iobase + adev->io[offset])
127 + (acx_readw((u8 *) adev->iobase + adev->io[offset] + 2) << 16);
128 #endif
131 INLINE_IO u16 read_reg16(acx_device_t * adev, unsigned int offset)
133 return acx_readw((u8 *) adev->iobase + adev->io[offset]);
136 INLINE_IO u8 read_reg8(acx_device_t * adev, unsigned int offset)
138 return readb((u8 *) adev->iobase + adev->io[offset]);
141 INLINE_IO void write_reg32(acx_device_t * adev, unsigned int offset, u32 val)
143 #if ACX_IO_WIDTH == 32
144 acx_writel(val, (u8 *) adev->iobase + adev->io[offset]);
145 #else
146 acx_writew(val & 0xffff, (u8 *) adev->iobase + adev->io[offset]);
147 acx_writew(val >> 16, (u8 *) adev->iobase + adev->io[offset] + 2);
148 #endif
151 INLINE_IO void write_reg16(acx_device_t * adev, unsigned int offset, u16 val)
153 acx_writew(val, (u8 *) adev->iobase + adev->io[offset]);
156 INLINE_IO void write_reg8(acx_device_t * adev, unsigned int offset, u8 val)
158 writeb(val, (u8 *) adev->iobase + adev->io[offset]);
161 /* Handle PCI posting properly:
162 * Make sure that writes reach the adapter in case they require to be executed
163 * *before* the next write, by reading a random (and safely accessible) register.
164 * This call has to be made if there is no read following (which would flush the data
165 * to the adapter), yet the written data has to reach the adapter immediately. */
166 INLINE_IO void write_flush(acx_device_t * adev)
168 /* readb(adev->iobase + adev->io[IO_ACX_INFO_MAILBOX_OFFS]); */
169 /* faster version (accesses the first register, IO_ACX_SOFT_RESET,
170 * which should also be safe): */
171 readb(adev->iobase);
174 INLINE_IO int adev_present(acx_device_t * adev)
176 /* fast version (accesses the first register, IO_ACX_SOFT_RESET,
177 * which should be safe): */
178 return acx_readl(adev->iobase) != 0xffffffff;
182 /***********************************************************************
184 static inline txdesc_t *get_txdesc(acx_device_t * adev, int index)
186 return (txdesc_t *) (((u8 *) adev->txdesc_start) +
187 index * adev->txdesc_size);
190 static inline txdesc_t *advance_txdesc(acx_device_t * adev, txdesc_t * txdesc,
191 int inc)
193 return (txdesc_t *) (((u8 *) txdesc) + inc * adev->txdesc_size);
196 static txhostdesc_t *get_txhostdesc(acx_device_t * adev, txdesc_t * txdesc)
198 int index = (u8 *) txdesc - (u8 *) adev->txdesc_start;
199 if (unlikely(ACX_DEBUG && (index % adev->txdesc_size))) {
200 printk("bad txdesc ptr %p\n", txdesc);
201 return NULL;
203 index /= adev->txdesc_size;
204 if (unlikely(ACX_DEBUG && (index >= TX_CNT))) {
205 printk("bad txdesc ptr %p\n", txdesc);
206 return NULL;
208 return &adev->txhostdesc_start[index * 2];
215 /***********************************************************************
216 ** EEPROM and PHY read/write helpers
218 /***********************************************************************
219 ** acxpci_read_eeprom_byte
221 ** Function called to read an octet in the EEPROM.
223 ** This function is used by acxpci_e_probe to check if the
224 ** connected card is a legal one or not.
226 ** Arguments:
227 ** adev ptr to acx_device structure
228 ** addr address to read in the EEPROM
229 ** charbuf ptr to a char. This is where the read octet
230 ** will be stored
233 int acxpci_read_eeprom_byte(acx_device_t * adev, u32 addr, u8 * charbuf)
235 int result;
236 int count;
238 FN_ENTER;
240 write_reg32(adev, IO_ACX_EEPROM_CFG, 0);
241 write_reg32(adev, IO_ACX_EEPROM_ADDR, addr);
242 write_flush(adev);
243 write_reg32(adev, IO_ACX_EEPROM_CTL, 2);
245 count = 0xffff;
246 while (read_reg16(adev, IO_ACX_EEPROM_CTL)) {
247 /* scheduling away instead of CPU burning loop
248 * doesn't seem to work here at all:
249 * awful delay, sometimes also failure.
250 * Doesn't matter anyway (only small delay). */
251 if (unlikely(!--count)) {
252 printk("%s: timeout waiting for EEPROM read\n",
253 wiphy_name(adev->ieee->wiphy));
254 result = NOT_OK;
255 goto fail;
257 cpu_relax();
260 *charbuf = read_reg8(adev, IO_ACX_EEPROM_DATA);
261 log(L_DEBUG, "EEPROM at 0x%04X = 0x%02X\n", addr, *charbuf);
262 result = OK;
264 fail:
265 FN_EXIT1(result);
266 return result;
270 /***********************************************************************
271 ** We don't lock hw accesses here since we never r/w eeprom in IRQ
272 ** Note: this function sleeps only because of GFP_KERNEL alloc
274 #ifdef UNUSED
276 acxpci_s_write_eeprom(acx_device_t * adev, u32 addr, u32 len,
277 const u8 * charbuf)
279 u8 *data_verify = NULL;
280 unsigned long flags;
281 int count, i;
282 int result = NOT_OK;
283 u16 gpio_orig;
285 printk("acx: WARNING! I would write to EEPROM now. "
286 "Since I really DON'T want to unless you know "
287 "what you're doing (THIS CODE WILL PROBABLY "
288 "NOT WORK YET!), I will abort that now. And "
289 "definitely make sure to make a "
290 "/proc/driver/acx_wlan0_eeprom backup copy first!!! "
291 "(the EEPROM content includes the PCI config header!! "
292 "If you kill important stuff, then you WILL "
293 "get in trouble and people DID get in trouble already)\n");
294 return OK;
296 FN_ENTER;
298 data_verify = kmalloc(len, GFP_KERNEL);
299 if (!data_verify) {
300 goto end;
303 /* first we need to enable the OE (EEPROM Output Enable) GPIO line
304 * to be able to write to the EEPROM.
305 * NOTE: an EEPROM writing success has been reported,
306 * but you probably have to modify GPIO_OUT, too,
307 * and you probably need to activate a different GPIO
308 * line instead! */
309 gpio_orig = read_reg16(adev, IO_ACX_GPIO_OE);
310 write_reg16(adev, IO_ACX_GPIO_OE, gpio_orig & ~1);
311 write_flush(adev);
313 /* ok, now start writing the data out */
314 for (i = 0; i < len; i++) {
315 write_reg32(adev, IO_ACX_EEPROM_CFG, 0);
316 write_reg32(adev, IO_ACX_EEPROM_ADDR, addr + i);
317 write_reg32(adev, IO_ACX_EEPROM_DATA, *(charbuf + i));
318 write_flush(adev);
319 write_reg32(adev, IO_ACX_EEPROM_CTL, 1);
321 count = 0xffff;
322 while (read_reg16(adev, IO_ACX_EEPROM_CTL)) {
323 if (unlikely(!--count)) {
324 printk("WARNING, DANGER!!! "
325 "Timeout waiting for EEPROM write\n");
326 goto end;
328 cpu_relax();
332 /* disable EEPROM writing */
333 write_reg16(adev, IO_ACX_GPIO_OE, gpio_orig);
334 write_flush(adev);
336 /* now start a verification run */
337 for (i = 0; i < len; i++) {
338 write_reg32(adev, IO_ACX_EEPROM_CFG, 0);
339 write_reg32(adev, IO_ACX_EEPROM_ADDR, addr + i);
340 write_flush(adev);
341 write_reg32(adev, IO_ACX_EEPROM_CTL, 2);
343 count = 0xffff;
344 while (read_reg16(adev, IO_ACX_EEPROM_CTL)) {
345 if (unlikely(!--count)) {
346 printk("timeout waiting for EEPROM read\n");
347 goto end;
349 cpu_relax();
352 data_verify[i] = read_reg16(adev, IO_ACX_EEPROM_DATA);
355 if (0 == memcmp(charbuf, data_verify, len))
356 result = OK; /* read data matches, success */
358 end:
359 kfree(data_verify);
360 FN_EXIT1(result);
361 return result;
363 #endif /* UNUSED */
366 /***********************************************************************
367 ** acxpci_s_read_phy_reg
369 ** Messing with rx/tx disabling and enabling here
370 ** (write_reg32(adev, IO_ACX_ENABLE, 0b000000xx)) kills traffic
372 int acxpci_s_read_phy_reg(acx_device_t * adev, u32 reg, u8 * charbuf)
374 int result = NOT_OK;
375 int count;
377 FN_ENTER;
379 write_reg32(adev, IO_ACX_PHY_ADDR, reg);
380 write_flush(adev);
381 write_reg32(adev, IO_ACX_PHY_CTL, 2);
383 count = 0xffff;
384 while (read_reg32(adev, IO_ACX_PHY_CTL)) {
385 /* scheduling away instead of CPU burning loop
386 * doesn't seem to work here at all:
387 * awful delay, sometimes also failure.
388 * Doesn't matter anyway (only small delay). */
389 if (unlikely(!--count)) {
390 printk("%s: timeout waiting for phy read\n",
391 wiphy_name(adev->ieee->wiphy));
392 *charbuf = 0;
393 goto fail;
395 cpu_relax();
398 log(L_DEBUG, "count was %u\n", count);
399 *charbuf = read_reg8(adev, IO_ACX_PHY_DATA);
401 log(L_DEBUG, "radio PHY at 0x%04X = 0x%02X\n", *charbuf, reg);
402 result = OK;
403 goto fail; /* silence compiler warning */
404 fail:
405 FN_EXIT1(result);
406 return result;
410 /***********************************************************************
412 int acxpci_s_write_phy_reg(acx_device_t * adev, u32 reg, u8 value)
414 FN_ENTER;
416 /* mprusko said that 32bit accesses result in distorted sensitivity
417 * on his card. Unconfirmed, looks like it's not true (most likely since we
418 * now properly flush writes). */
419 write_reg32(adev, IO_ACX_PHY_DATA, value);
420 write_reg32(adev, IO_ACX_PHY_ADDR, reg);
421 write_flush(adev);
422 write_reg32(adev, IO_ACX_PHY_CTL, 1);
423 write_flush(adev);
424 log(L_DEBUG, "radio PHY write 0x%02X at 0x%04X\n", value, reg);
426 FN_EXIT0;
427 return OK;
431 #define NO_AUTO_INCREMENT 1
433 /***********************************************************************
434 ** acxpci_s_write_fw
436 ** Write the firmware image into the card.
438 ** Arguments:
439 ** adev wlan device structure
440 ** fw_image firmware image.
442 ** Returns:
443 ** 1 firmware image corrupted
444 ** 0 success
446 ** Standard csum implementation + write to IO
448 static int
449 acxpci_s_write_fw(acx_device_t * adev, const firmware_image_t *fw_image,
450 u32 offset)
452 int len, size;
453 u32 sum, v32;
454 /* we skip the first four bytes which contain the control sum */
456 const u8 *p = (u8 *) fw_image + 4;
458 FN_ENTER;
460 /* start the image checksum by adding the image size value */
461 sum = p[0] + p[1] + p[2] + p[3];
462 p += 4;
464 write_reg32(adev, IO_ACX_SLV_END_CTL, 0);
466 #if NO_AUTO_INCREMENT
467 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 0); /* use basic mode */
468 #else
469 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 1); /* use autoincrement mode */
470 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset); /* configure start address */
471 write_flush(adev);
472 #endif
474 len = 0;
475 size = le32_to_cpu(fw_image->size) & (~3);
477 while (likely(len < size)) {
478 v32 = be32_to_cpu(*(u32 *) p);
479 sum += p[0] + p[1] + p[2] + p[3];
480 p += 4;
481 len += 4;
483 #if NO_AUTO_INCREMENT
484 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset + len - 4);
485 write_flush(adev);
486 #endif
487 write_reg32(adev, IO_ACX_SLV_MEM_DATA, v32);
490 log(L_DEBUG, "firmware written, size:%d sum1:%x sum2:%x\n",
491 size, sum, le32_to_cpu(fw_image->chksum));
493 /* compare our checksum with the stored image checksum */
494 FN_EXIT1(sum != le32_to_cpu(fw_image->chksum));
495 return (sum != le32_to_cpu(fw_image->chksum));
499 /***********************************************************************
500 ** acxpci_s_validate_fw
502 ** Compare the firmware image given with
503 ** the firmware image written into the card.
505 ** Arguments:
506 ** adev wlan device structure
507 ** fw_image firmware image.
509 ** Returns:
510 ** NOT_OK firmware image corrupted or not correctly written
511 ** OK success
513 ** Origin: Standard csum + Read IO
515 static int
516 acxpci_s_validate_fw(acx_device_t * adev, const firmware_image_t *fw_image,
517 u32 offset)
519 u32 sum, v32, w32;
520 int len, size;
521 int result = OK;
522 /* we skip the first four bytes which contain the control sum */
523 const u8 *p = (u8 *) fw_image + 4;
525 FN_ENTER;
527 /* start the image checksum by adding the image size value */
528 sum = p[0] + p[1] + p[2] + p[3];
529 p += 4;
531 write_reg32(adev, IO_ACX_SLV_END_CTL, 0);
533 #if NO_AUTO_INCREMENT
534 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 0); /* use basic mode */
535 #else
536 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 1); /* use autoincrement mode */
537 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset); /* configure start address */
538 #endif
540 len = 0;
541 size = le32_to_cpu(fw_image->size) & (~3);
543 while (likely(len < size)) {
544 v32 = be32_to_cpu(*(u32 *) p);
545 p += 4;
546 len += 4;
548 #if NO_AUTO_INCREMENT
549 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset + len - 4);
550 #endif
551 w32 = read_reg32(adev, IO_ACX_SLV_MEM_DATA);
553 if (unlikely(w32 != v32)) {
554 printk("acx: FATAL: firmware upload: "
555 "data parts at offset %d don't match (0x%08X vs. 0x%08X)! "
556 "I/O timing issues or defective memory, with DWL-xx0+? "
557 "ACX_IO_WIDTH=16 may help. Please report\n",
558 len, v32, w32);
559 result = NOT_OK;
560 break;
563 sum +=
564 (u8) w32 + (u8) (w32 >> 8) + (u8) (w32 >> 16) +
565 (u8) (w32 >> 24);
568 /* sum control verification */
569 if (result != NOT_OK) {
570 if (sum != le32_to_cpu(fw_image->chksum)) {
571 printk("acx: FATAL: firmware upload: "
572 "checksums don't match!\n");
573 result = NOT_OK;
577 FN_EXIT1(result);
578 return result;
582 /***********************************************************************
583 ** acxpci_s_upload_fw
585 ** Called from acx_reset_dev
587 ** Origin: Derived from FW dissection
589 static int acxpci_s_upload_fw(acx_device_t * adev)
591 firmware_image_t *fw_image = NULL;
592 int res = NOT_OK;
593 int try;
594 u32 file_size;
595 char filename[sizeof("tiacx1NNcNN")];
597 FN_ENTER;
599 /* print exact chipset and radio ID to make sure people
600 * really get a clue on which files exactly they need to provide.
601 * Firmware loading is a frequent end-user PITA with these chipsets.
603 printk( "acx: need firmware for acx1%02d chipset with radio ID %02X\n"
604 "Please provide via firmware hotplug:\n"
605 "either combined firmware (single file named 'tiacx1%02dc%02X')\n"
606 "or two files (base firmware file 'tiacx1%02d' "
607 "+ radio fw 'tiacx1%02dr%02X')\n",
608 IS_ACX111(adev)*11, adev->radio_type,
609 IS_ACX111(adev)*11, adev->radio_type,
610 IS_ACX111(adev)*11,
611 IS_ACX111(adev)*11, adev->radio_type
614 /* print exact chipset and radio ID to make sure people really get a clue on which files exactly they are supposed to provide,
615 * since firmware loading is the biggest enduser PITA with these chipsets.
616 * Not printing radio ID in 0xHEX in order to not confuse them into wrong file naming */
617 printk( "acx: need to load firmware for acx1%02d chipset with radio ID %02x, please provide via firmware hotplug:\n"
618 "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",
619 IS_ACX111(adev)*11, adev->radio_type);
621 /* Try combined, then main image */
622 adev->need_radio_fw = 0;
623 snprintf(filename, sizeof(filename), "tiacx1%02dc%02X",
624 IS_ACX111(adev) * 11, adev->radio_type);
626 fw_image = acx_s_read_fw(adev->bus_dev, filename, &file_size);
627 if (!fw_image) {
628 adev->need_radio_fw = 1;
629 filename[sizeof("tiacx1NN") - 1] = '\0';
630 fw_image =
631 acx_s_read_fw(adev->bus_dev, filename, &file_size);
632 if (!fw_image) {
633 FN_EXIT1(NOT_OK);
634 return NOT_OK;
638 for (try = 1; try <= 5; try++) {
639 res = acxpci_s_write_fw(adev, fw_image, 0);
640 log(L_DEBUG | L_INIT, "acx_write_fw (main/combined): %d\n", res);
641 if (OK == res) {
642 res = acxpci_s_validate_fw(adev, fw_image, 0);
643 log(L_DEBUG | L_INIT, "acx_validate_fw "
644 "(main/combined): %d\n", res);
647 if (OK == res) {
648 SET_BIT(adev->dev_state_mask, ACX_STATE_FW_LOADED);
649 break;
651 printk("acx: firmware upload attempt #%d FAILED, "
652 "retrying...\n", try);
653 acx_s_mdelay(1000); /* better wait for a while... */
656 vfree(fw_image);
658 FN_EXIT1(res);
659 return res;
663 /***********************************************************************
664 ** acxpci_s_upload_radio
666 ** Uploads the appropriate radio module firmware into the card.
668 ** Origin: Standard Read/Write to IO
670 int acxpci_s_upload_radio(acx_device_t * adev)
672 acx_ie_memmap_t mm;
673 firmware_image_t *radio_image;
674 acx_cmd_radioinit_t radioinit;
675 int res = NOT_OK;
676 int try;
677 u32 offset;
678 u32 size;
679 char filename[sizeof("tiacx1NNrNN")];
681 if (!adev->need_radio_fw)
682 return OK;
684 FN_ENTER;
686 acx_s_interrogate(adev, &mm, ACX1xx_IE_MEMORY_MAP);
687 offset = le32_to_cpu(mm.CodeEnd);
689 snprintf(filename, sizeof(filename), "tiacx1%02dr%02X",
690 IS_ACX111(adev) * 11, adev->radio_type);
691 radio_image = acx_s_read_fw(adev->bus_dev, filename, &size);
692 if (!radio_image) {
693 printk("acx: can't load radio module '%s'\n", filename);
694 goto fail;
697 acx_s_issue_cmd(adev, ACX1xx_CMD_SLEEP, NULL, 0);
699 for (try = 1; try <= 5; try++) {
700 res = acxpci_s_write_fw(adev, radio_image, offset);
701 log(L_DEBUG | L_INIT, "acx_write_fw (radio): %d\n", res);
702 if (OK == res) {
703 res = acxpci_s_validate_fw(adev, radio_image, offset);
704 log(L_DEBUG | L_INIT, "acx_validate_fw (radio): %d\n",
705 res);
708 if (OK == res)
709 break;
710 printk("acx: radio firmware upload attempt #%d FAILED, "
711 "retrying...\n", try);
712 acx_s_mdelay(1000); /* better wait for a while... */
715 acx_s_issue_cmd(adev, ACX1xx_CMD_WAKE, NULL, 0);
716 radioinit.offset = cpu_to_le32(offset);
717 /* no endian conversion needed, remains in card CPU area: */
718 radioinit.len = radio_image->size;
720 vfree(radio_image);
722 if (OK != res)
723 goto fail;
725 /* will take a moment so let's have a big timeout */
726 acx_s_issue_cmd_timeo(adev, ACX1xx_CMD_RADIOINIT,
727 &radioinit, sizeof(radioinit),
728 CMD_TIMEOUT_MS(1000));
730 res = acx_s_interrogate(adev, &mm, ACX1xx_IE_MEMORY_MAP);
731 fail:
732 FN_EXIT1(res);
733 return res;
737 /***********************************************************************
738 ** acxpci_l_reset_mac
740 ** MAC will be reset
741 ** Call context: reset_dev
743 ** Origin: Standard Read/Write to IO
745 static void acxpci_l_reset_mac(acx_device_t * adev)
747 u16 temp;
749 FN_ENTER;
751 /* halt eCPU */
752 temp = read_reg16(adev, IO_ACX_ECPU_CTRL) | 0x1;
753 write_reg16(adev, IO_ACX_ECPU_CTRL, temp);
755 /* now do soft reset of eCPU, set bit */
756 temp = read_reg16(adev, IO_ACX_SOFT_RESET) | 0x1;
757 log(L_DEBUG, "enable soft reset\n");
758 write_reg16(adev, IO_ACX_SOFT_RESET, temp);
759 write_flush(adev);
761 /* now clear bit again: deassert eCPU reset */
762 log(L_DEBUG, "disable soft reset and go to init mode");
763 write_reg16(adev, IO_ACX_SOFT_RESET, temp & ~0x1);
765 /* now start a burst read from initial EEPROM */
766 temp = read_reg16(adev, IO_ACX_EE_START) | 0x1;
767 write_reg16(adev, IO_ACX_EE_START, temp);
768 write_flush(adev);
770 FN_EXIT0;
774 /***********************************************************************
775 ** acxpci_s_verify_init
777 static int acxpci_s_verify_init(acx_device_t * adev)
779 int result = NOT_OK;
780 unsigned long timeout;
782 FN_ENTER;
784 timeout = jiffies + 2 * HZ;
785 for (;;) {
786 u16 irqstat = read_reg16(adev, IO_ACX_IRQ_STATUS_NON_DES);
787 if (irqstat & HOST_INT_FCS_THRESHOLD) {
788 result = OK;
789 write_reg16(adev, IO_ACX_IRQ_ACK,
790 HOST_INT_FCS_THRESHOLD);
791 break;
793 if (time_after(jiffies, timeout))
794 break;
795 /* Init may take up to ~0.5 sec total */
796 acx_s_mdelay(50);
799 FN_EXIT1(result);
800 return result;
804 /***********************************************************************
805 ** A few low-level helpers
807 ** Note: these functions are not protected by lock
808 ** and thus are never allowed to be called from IRQ.
809 ** Also they must not race with fw upload which uses same hw regs
812 /***********************************************************************
813 ** acxpci_write_cmd_type_status
815 ** Origin: Common linux implementation
818 static inline void
819 acxpci_write_cmd_type_status(acx_device_t * adev, u16 type, u16 status)
821 FN_ENTER;
822 acx_writel(type | (status << 16), adev->cmd_area);
823 write_flush(adev);
824 FN_EXIT0;
828 /***********************************************************************
829 ** acxpci_read_cmd_type_status
831 ** Origin: Common linux implementation
833 static u32 acxpci_read_cmd_type_status(acx_device_t * adev)
835 u32 cmd_type, cmd_status;
837 FN_ENTER;
839 cmd_type = acx_readl(adev->cmd_area);
840 cmd_status = (cmd_type >> 16);
841 cmd_type = (u16) cmd_type;
843 log(L_CTL, "cmd_type:%04X cmd_status:%04X [%s]\n",
844 cmd_type, cmd_status, acx_cmd_status_str(cmd_status));
846 FN_EXIT1(cmd_status);
847 return cmd_status;
851 /***********************************************************************
852 ** acxpci_s_reset_dev
854 ** Arguments:
855 ** netdevice that contains the adev variable
856 ** Returns:
857 ** NOT_OK on fail
858 ** OK on success
859 ** Side effects:
860 ** device is hard reset
861 ** Call context:
862 ** acxpci_e_probe
863 ** Comment:
864 ** This resets the device using low level hardware calls
865 ** as well as uploads and verifies the firmware to the card
868 static inline void init_mboxes(acx_device_t * adev)
870 u32 cmd_offs, info_offs;
872 FN_ENTER;
874 cmd_offs = read_reg32(adev, IO_ACX_CMD_MAILBOX_OFFS);
875 info_offs = read_reg32(adev, IO_ACX_INFO_MAILBOX_OFFS);
876 adev->cmd_area = (u8 *) adev->iobase2 + cmd_offs;
877 adev->info_area = (u8 *) adev->iobase2 + info_offs;
878 log(L_DEBUG, "iobase2=%p\n"
879 "cmd_mbox_offset=%X cmd_area=%p\n"
880 "info_mbox_offset=%X info_area=%p\n",
881 adev->iobase2,
882 cmd_offs, adev->cmd_area, info_offs, adev->info_area);
883 FN_EXIT0;
887 static inline void read_eeprom_area(acx_device_t * adev)
889 #if ACX_DEBUG > 1
890 int offs;
891 u8 tmp;
893 FN_ENTER;
895 for (offs = 0x8c; offs < 0xb9; offs++)
896 acxpci_read_eeprom_byte(adev, offs, &tmp);
898 FN_EXIT0;
899 #endif
903 int acxpci_s_reset_dev(acx_device_t * adev)
905 const char *msg = "";
906 unsigned long flags;
907 int result = NOT_OK;
908 u16 hardware_info;
909 u16 ecpu_ctrl;
910 int count;
912 FN_ENTER;
914 /* reset the device to make sure the eCPU is stopped
915 * to upload the firmware correctly */
917 acx_lock(adev, flags);
919 #ifdef CONFIG_PCI
920 acxpci_l_reset_mac(adev);
921 #endif
923 ecpu_ctrl = read_reg16(adev, IO_ACX_ECPU_CTRL) & 1;
924 if (!ecpu_ctrl) {
925 msg = "eCPU is already running. ";
926 goto end_unlock;
928 #if 0
929 if (read_reg16(adev, IO_ACX_SOR_CFG) & 2) {
930 /* eCPU most likely means "embedded CPU" */
931 msg = "eCPU did not start after boot from flash. ";
932 goto end_unlock;
935 /* check sense on reset flags */
936 if (read_reg16(adev, IO_ACX_SOR_CFG) & 0x10) {
937 printk("%s: eCPU did not start after boot (SOR), "
938 "is this fatal?\n", wiphy_name(adev->ieee->wiphy));
940 #endif
941 /* scan, if any, is stopped now, setting corresponding IRQ bit */
942 adev->irq_status |= HOST_INT_SCAN_COMPLETE;
944 acx_unlock(adev, flags);
946 /* need to know radio type before fw load */
947 /* Need to wait for arrival of this information in a loop,
948 * most probably since eCPU runs some init code from EEPROM
949 * (started burst read in reset_mac()) which also
950 * sets the radio type ID */
952 count = 0xffff;
953 do {
954 hardware_info = read_reg16(adev, IO_ACX_EEPROM_INFORMATION);
955 if (!--count) {
956 msg = "eCPU didn't indicate radio type";
957 goto end_fail;
959 cpu_relax();
960 } while (!(hardware_info & 0xff00)); /* radio type still zero? */
962 /* printk("DEBUG: count %d\n", count); */
963 adev->form_factor = hardware_info & 0xff;
964 adev->radio_type = hardware_info >> 8;
966 /* load the firmware */
967 if (OK != acxpci_s_upload_fw(adev))
968 goto end_fail;
970 /* acx_s_mdelay(10); this one really shouldn't be required */
972 /* now start eCPU by clearing bit */
973 write_reg16(adev, IO_ACX_ECPU_CTRL, ecpu_ctrl & ~0x1);
974 log(L_DEBUG, "booted eCPU up and waiting for completion...\n");
976 /* wait for eCPU bootup */
977 if (OK != acxpci_s_verify_init(adev)) {
978 msg = "timeout waiting for eCPU. ";
979 goto end_fail;
981 log(L_DEBUG, "eCPU has woken up, card is ready to be configured\n");
983 init_mboxes(adev);
984 acxpci_write_cmd_type_status(adev, 0, 0);
986 /* test that EEPROM is readable */
987 read_eeprom_area(adev);
989 result = OK;
990 goto end;
992 /* Finish error message. Indicate which function failed */
993 end_unlock:
994 acx_unlock(adev, flags);
995 end_fail:
996 printk("acx: %sreset_dev() FAILED\n", msg);
997 end:
998 FN_EXIT1(result);
999 return result;
1003 /***********************************************************************
1004 ** acxpci_s_issue_cmd_timeo
1006 ** Sends command to fw, extract result
1008 ** NB: we do _not_ take lock inside, so be sure to not touch anything
1009 ** which may interfere with IRQ handler operation
1011 ** TODO: busy wait is a bit silly, so:
1012 ** 1) stop doing many iters - go to sleep after first
1013 ** 2) go to waitqueue based approach: wait, not poll!
1015 #undef FUNC
1016 #define FUNC "issue_cmd"
1018 #if !ACX_DEBUG
1020 acxpci_s_issue_cmd_timeo(acx_device_t * adev,
1021 unsigned int cmd,
1022 void *buffer, unsigned buflen, unsigned int cmd_timeout)
1024 #else
1026 acxpci_s_issue_cmd_timeo_debug(acx_device_t * adev,
1027 unsigned cmd,
1028 void *buffer,
1029 unsigned buflen,
1030 unsigned int cmd_timeout, const char *cmdstr)
1032 unsigned long start = jiffies;
1033 #endif
1034 const char *devname;
1035 unsigned counter;
1036 u16 irqtype;
1037 u16 cmd_status;
1038 unsigned long timeout;
1040 FN_ENTER;
1043 devname = wiphy_name(adev->ieee->wiphy);
1044 if (!devname || !devname[0] || devname[4] == '%')
1045 devname = "acx";
1047 log(L_CTL, FUNC "(cmd:%s,buflen:%u,timeout:%ums,type:0x%04X)\n",
1048 cmdstr, buflen, cmd_timeout,
1049 buffer ? le16_to_cpu(((acx_ie_generic_t *) buffer)->type) : -1);
1051 if (!(adev->dev_state_mask & ACX_STATE_FW_LOADED)) {
1052 printk("%s: " FUNC "(): firmware is not loaded yet, "
1053 "cannot execute commands!\n", devname);
1054 goto bad;
1057 if ((acx_debug & L_DEBUG) && (cmd != ACX1xx_CMD_INTERROGATE)) {
1058 printk("input buffer (len=%u):\n", buflen);
1059 acx_dump_bytes(buffer, buflen);
1062 /* wait for firmware to become idle for our command submission */
1063 timeout = HZ / 5;
1064 counter = (timeout * 1000 / HZ) - 1; /* in ms */
1065 timeout += jiffies;
1066 do {
1067 cmd_status = acxpci_read_cmd_type_status(adev);
1068 /* Test for IDLE state */
1069 if (!cmd_status)
1070 break;
1071 if (counter % 8 == 0) {
1072 if (time_after(jiffies, timeout)) {
1073 counter = 0;
1074 break;
1076 /* we waited 8 iterations, no luck. Sleep 8 ms */
1077 acx_s_mdelay(8);
1079 } while (likely(--counter));
1081 if (!counter) {
1082 /* the card doesn't get idle, we're in trouble */
1083 printk("%s: " FUNC "(): cmd_status is not IDLE: 0x%04X!=0\n",
1084 devname, cmd_status);
1085 goto bad;
1086 } else if (counter < 190) { /* if waited >10ms... */
1087 log(L_CTL | L_DEBUG, FUNC "(): waited for IDLE %dms. "
1088 "Please report\n", 199 - counter);
1091 /* now write the parameters of the command if needed */
1092 if (buffer && buflen) {
1093 /* if it's an INTERROGATE command, just pass the length
1094 * of parameters to read, as data */
1095 #if CMD_DISCOVERY
1096 if (cmd == ACX1xx_CMD_INTERROGATE)
1097 memset_io(adev->cmd_area + 4, 0xAA, buflen);
1098 #endif
1099 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1100 memcpy_toio(adev->cmd_area + 4, buffer,
1101 (cmd == ACX1xx_CMD_INTERROGATE) ? 4 : buflen);
1103 /* now write the actual command type */
1104 acxpci_write_cmd_type_status(adev, cmd, 0);
1105 /* execute command */
1106 write_reg16(adev, IO_ACX_INT_TRIG, INT_TRIG_CMD);
1107 write_flush(adev);
1109 /* wait for firmware to process command */
1111 /* Ensure nonzero and not too large timeout.
1112 ** Also converts e.g. 100->99, 200->199
1113 ** which is nice but not essential */
1114 cmd_timeout = (cmd_timeout - 1) | 1;
1115 if (unlikely(cmd_timeout > 1199))
1116 cmd_timeout = 1199;
1117 /* clear CMD_COMPLETE bit. can be set only by IRQ handler: */
1118 adev->irq_status &= ~HOST_INT_CMD_COMPLETE;
1120 /* we schedule away sometimes (timeout can be large) */
1121 counter = cmd_timeout;
1122 timeout = jiffies + cmd_timeout * HZ / 1000;
1123 do {
1124 if (!adev->irqs_active) { /* IRQ disabled: poll */
1125 irqtype = read_reg16(adev, IO_ACX_IRQ_STATUS_NON_DES);
1126 if (irqtype & HOST_INT_CMD_COMPLETE) {
1127 write_reg16(adev, IO_ACX_IRQ_ACK,
1128 HOST_INT_CMD_COMPLETE);
1129 break;
1131 } else { /* Wait when IRQ will set the bit */
1132 irqtype = adev->irq_status;
1133 if (irqtype & HOST_INT_CMD_COMPLETE)
1134 break;
1137 if (counter % 8 == 0) {
1138 if (time_after(jiffies, timeout)) {
1139 counter = 0;
1140 break;
1142 /* we waited 8 iterations, no luck. Sleep 8 ms */
1143 acx_s_mdelay(8);
1145 } while (likely(--counter));
1147 /* save state for debugging */
1148 cmd_status = acxpci_read_cmd_type_status(adev);
1150 /* put the card in IDLE state */
1151 acxpci_write_cmd_type_status(adev, 0, 0);
1153 if ((cmd_timeout - counter) == 0) { /* timed out! */
1154 printk("%s: " FUNC "(): timed out %s for CMD_COMPLETE. "
1155 "irq bits:0x%04X irq_status:0x%04X timeout:%dms "
1156 "cmd_status:%d (%s)\n",
1157 devname, (adev->irqs_active) ? "waiting" : "polling",
1158 irqtype, adev->irq_status, cmd_timeout,
1159 cmd_status, acx_cmd_status_str(cmd_status));
1160 printk("hack: don't do: 'goto bad;'\ncounter: %d cmd_timeout: %d cmd_timeout-counter: %d\n",counter, cmd_timeout, cmd_timeout - counter);
1161 } else if (counter == 0) { /* maybe timed out! */
1162 log(L_CTL | L_DEBUG, FUNC "(): %s for CMD_COMPLETE %dms. "
1163 "count:%d. Please report\n",
1164 (adev->irqs_active) ? "waited" : "polled",
1165 cmd_timeout - counter, counter);
1166 } else if ((cmd_timeout - counter) > 30) { /* if waited >30ms... */
1167 log(L_CTL | L_DEBUG, FUNC "(): %s for CMD_COMPLETE %dms. "
1168 "count:%d. Please report\n",
1169 (adev->irqs_active) ? "waited" : "polled",
1170 cmd_timeout - counter, counter);
1173 if (1 != cmd_status) { /* it is not a 'Success' */
1174 printk("%s: " FUNC "(): cmd_status is not SUCCESS: %d (%s). "
1175 "Took %dms of %d\n",
1176 devname, cmd_status, acx_cmd_status_str(cmd_status),
1177 cmd_timeout - counter, cmd_timeout);
1178 /* zero out result buffer
1179 * WARNING: this will trash stack in case of illegally large input
1180 * length! */
1181 if (buffer && buflen)
1182 memset(buffer, 0, buflen);
1183 goto bad;
1186 /* read in result parameters if needed */
1187 if (buffer && buflen && (cmd == ACX1xx_CMD_INTERROGATE)) {
1188 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1189 memcpy_fromio(buffer, adev->cmd_area + 4, buflen);
1190 if (acx_debug & L_DEBUG) {
1191 printk("output buffer (len=%u): ", buflen);
1192 acx_dump_bytes(buffer, buflen);
1195 /* ok: */
1196 log(L_CTL, FUNC "(%s): took %ld jiffies to complete\n",
1197 cmdstr, jiffies - start);
1198 FN_EXIT1(OK);
1199 return OK;
1201 bad:
1202 /* Give enough info so that callers can avoid
1203 ** printing their own diagnostic messages */
1204 #if ACX_DEBUG
1205 printk("%s: " FUNC "(cmd:%s) FAILED\n", devname, cmdstr);
1206 #else
1207 printk("%s: " FUNC "(cmd:0x%04X) FAILED\n", devname, cmd);
1208 #endif
1209 dump_stack();
1210 FN_EXIT1(NOT_OK);
1211 return NOT_OK;
1215 /***********************************************************************
1217 #ifdef NONESSENTIAL_FEATURES
1218 typedef struct device_id {
1219 unsigned char id[6];
1220 char *descr;
1221 char *type;
1222 } device_id_t;
1224 static const device_id_t device_ids[] = {
1226 {'G', 'l', 'o', 'b', 'a', 'l'},
1227 NULL,
1228 NULL,
1231 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
1232 "uninitialized",
1233 "SpeedStream SS1021 or Gigafast WF721-AEX"},
1235 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85},
1236 "non-standard",
1237 "DrayTek Vigor 520"},
1239 {'?', '?', '?', '?', '?', '?'},
1240 "non-standard",
1241 "Level One WPC-0200"},
1243 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1244 "empty",
1245 "DWL-650+ variant"}
1248 static void acx_show_card_eeprom_id(acx_device_t * adev)
1250 unsigned char buffer[CARD_EEPROM_ID_SIZE];
1251 int i;
1253 FN_ENTER;
1255 memset(&buffer, 0, CARD_EEPROM_ID_SIZE);
1256 /* use direct EEPROM access */
1257 for (i = 0; i < CARD_EEPROM_ID_SIZE; i++) {
1258 if (OK != acxpci_read_eeprom_byte(adev,
1259 ACX100_EEPROM_ID_OFFSET + i,
1260 &buffer[i])) {
1261 printk("acx: reading EEPROM FAILED\n");
1262 break;
1266 for (i = 0; i < ARRAY_SIZE(device_ids); i++) {
1267 if (!memcmp(&buffer, device_ids[i].id, CARD_EEPROM_ID_SIZE)) {
1268 if (device_ids[i].descr) {
1269 printk("acx: EEPROM card ID string check "
1270 "found %s card ID: is this %s?\n",
1271 device_ids[i].descr, device_ids[i].type);
1273 break;
1276 if (i == ARRAY_SIZE(device_ids)) {
1277 printk("acx: EEPROM card ID string check found "
1278 "unknown card: expected 'Global', got '%.*s\'. "
1279 "Please report\n", CARD_EEPROM_ID_SIZE, buffer);
1281 FN_EXIT0;
1283 #endif /* NONESSENTIAL_FEATURES */
1286 /***********************************************************************
1287 ** acxpci_free_desc_queues
1289 ** Releases the queues that have been allocated, the
1290 ** others have been initialised to NULL so this
1291 ** function can be used if only part of the queues were allocated.
1294 static inline void
1295 free_coherent(struct pci_dev *hwdev, size_t size,
1296 void *vaddr, dma_addr_t dma_handle)
1298 dma_free_coherent(hwdev == NULL ? NULL : &hwdev->dev,
1299 size, vaddr, dma_handle);
1303 void acxpci_free_desc_queues(acx_device_t * adev)
1305 #define ACX_FREE_QUEUE(size, ptr, phyaddr) \
1306 if (ptr) { \
1307 free_coherent(NULL, size, ptr, phyaddr); \
1308 ptr = NULL; \
1309 size = 0; \
1312 FN_ENTER;
1314 ACX_FREE_QUEUE(adev->txhostdesc_area_size, adev->txhostdesc_start,
1315 adev->txhostdesc_startphy);
1316 ACX_FREE_QUEUE(adev->txbuf_area_size, adev->txbuf_start,
1317 adev->txbuf_startphy);
1319 adev->txdesc_start = NULL;
1321 ACX_FREE_QUEUE(adev->rxhostdesc_area_size, adev->rxhostdesc_start,
1322 adev->rxhostdesc_startphy);
1323 ACX_FREE_QUEUE(adev->rxbuf_area_size, adev->rxbuf_start,
1324 adev->rxbuf_startphy);
1326 adev->rxdesc_start = NULL;
1328 FN_EXIT0;
1332 /***********************************************************************
1333 ** acxpci_s_delete_dma_regions
1335 static void acxpci_s_delete_dma_regions(acx_device_t * adev)
1337 unsigned long flags;
1339 FN_ENTER;
1340 /* disable radio Tx/Rx. Shouldn't we use the firmware commands
1341 * here instead? Or are we that much down the road that it's no
1342 * longer possible here? */
1343 write_reg16(adev, IO_ACX_ENABLE, 0);
1345 acx_s_mdelay(100);
1347 acx_lock(adev, flags);
1348 acxpci_free_desc_queues(adev);
1349 acx_unlock(adev, flags);
1351 FN_EXIT0;
1355 /***********************************************************************
1356 ** acxpci_e_probe
1358 ** Probe routine called when a PCI device w/ matching ID is found.
1359 ** Here's the sequence:
1360 ** - Allocate the PCI resources.
1361 ** - Read the PCMCIA attribute memory to make sure we have a WLAN card
1362 ** - Reset the MAC
1363 ** - Initialize the dev and wlan data
1364 ** - Initialize the MAC
1366 ** pdev - ptr to pci device structure containing info about pci configuration
1367 ** id - ptr to the device id entry that matched this device
1369 static const u16 IO_ACX100[] = {
1370 0x0000, /* IO_ACX_SOFT_RESET */
1372 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1373 0x0018, /* IO_ACX_SLV_MEM_DATA */
1374 0x001c, /* IO_ACX_SLV_MEM_CTL */
1375 0x0020, /* IO_ACX_SLV_END_CTL */
1377 0x0034, /* IO_ACX_FEMR */
1379 0x007c, /* IO_ACX_INT_TRIG */
1380 0x0098, /* IO_ACX_IRQ_MASK */
1381 0x00a4, /* IO_ACX_IRQ_STATUS_NON_DES */
1382 0x00a8, /* IO_ACX_IRQ_STATUS_CLEAR */
1383 0x00ac, /* IO_ACX_IRQ_ACK */
1384 0x00b0, /* IO_ACX_HINT_TRIG */
1386 0x0104, /* IO_ACX_ENABLE */
1388 0x0250, /* IO_ACX_EEPROM_CTL */
1389 0x0254, /* IO_ACX_EEPROM_ADDR */
1390 0x0258, /* IO_ACX_EEPROM_DATA */
1391 0x025c, /* IO_ACX_EEPROM_CFG */
1393 0x0268, /* IO_ACX_PHY_ADDR */
1394 0x026c, /* IO_ACX_PHY_DATA */
1395 0x0270, /* IO_ACX_PHY_CTL */
1397 0x0290, /* IO_ACX_GPIO_OE */
1399 0x0298, /* IO_ACX_GPIO_OUT */
1401 0x02a4, /* IO_ACX_CMD_MAILBOX_OFFS */
1402 0x02a8, /* IO_ACX_INFO_MAILBOX_OFFS */
1403 0x02ac, /* IO_ACX_EEPROM_INFORMATION */
1405 0x02d0, /* IO_ACX_EE_START */
1406 0x02d4, /* IO_ACX_SOR_CFG */
1407 0x02d8 /* IO_ACX_ECPU_CTRL */
1410 static const u16 IO_ACX111[] = {
1411 0x0000, /* IO_ACX_SOFT_RESET */
1413 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1414 0x0018, /* IO_ACX_SLV_MEM_DATA */
1415 0x001c, /* IO_ACX_SLV_MEM_CTL */
1416 0x0020, /* IO_ACX_SLV_END_CTL */
1418 0x0034, /* IO_ACX_FEMR */
1420 0x00b4, /* IO_ACX_INT_TRIG */
1421 0x00d4, /* IO_ACX_IRQ_MASK */
1422 /* we do mean NON_DES (0xf0), not NON_DES_MASK which is at 0xe0: */
1423 0x00f0, /* IO_ACX_IRQ_STATUS_NON_DES */
1424 0x00e4, /* IO_ACX_IRQ_STATUS_CLEAR */
1425 0x00e8, /* IO_ACX_IRQ_ACK */
1426 0x00ec, /* IO_ACX_HINT_TRIG */
1428 0x01d0, /* IO_ACX_ENABLE */
1430 0x0338, /* IO_ACX_EEPROM_CTL */
1431 0x033c, /* IO_ACX_EEPROM_ADDR */
1432 0x0340, /* IO_ACX_EEPROM_DATA */
1433 0x0344, /* IO_ACX_EEPROM_CFG */
1435 0x0350, /* IO_ACX_PHY_ADDR */
1436 0x0354, /* IO_ACX_PHY_DATA */
1437 0x0358, /* IO_ACX_PHY_CTL */
1439 0x0374, /* IO_ACX_GPIO_OE */
1441 0x037c, /* IO_ACX_GPIO_OUT */
1443 0x0388, /* IO_ACX_CMD_MAILBOX_OFFS */
1444 0x038c, /* IO_ACX_INFO_MAILBOX_OFFS */
1445 0x0390, /* IO_ACX_EEPROM_INFORMATION */
1447 0x0100, /* IO_ACX_EE_START */
1448 0x0104, /* IO_ACX_SOR_CFG */
1449 0x0108, /* IO_ACX_ECPU_CTRL */
1452 static const struct ieee80211_ops acxpci_hw_ops = {
1453 .tx = acx_i_start_xmit,
1454 .conf_tx = acx_net_conf_tx,
1455 .add_interface = acx_add_interface,
1456 .remove_interface = acx_remove_interface,
1457 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
1458 .open = acxpci_e_open,
1459 .reset = acx_net_reset,
1460 .set_multicast_list = acx_i_set_multicast_list,
1461 #else
1462 .start = acxpci_e_open,
1463 .configure_filter = acx_i_set_multicast_list,
1464 #endif
1465 .stop = acxpci_e_close,
1466 .config = acx_net_config,
1467 .config_interface = acx_config_interface,
1468 .set_key = acx_net_set_key,
1469 .get_stats = acx_e_get_stats,
1470 .get_tx_stats = acx_net_get_tx_stats,
1474 #ifdef CONFIG_PCI
1475 static int __devinit
1476 acxpci_e_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1478 acx111_ie_configoption_t co;
1479 unsigned long mem_region1 = 0;
1480 unsigned long mem_region2 = 0;
1481 unsigned long mem_region1_size;
1482 unsigned long mem_region2_size;
1483 unsigned long phymem1;
1484 unsigned long phymem2;
1485 void *mem1 = NULL;
1486 void *mem2 = NULL;
1487 acx_device_t *adev = NULL;
1488 const char *chip_name;
1489 int result = -EIO;
1490 int err;
1491 u8 chip_type;
1492 struct ieee80211_hw *ieee;
1494 FN_ENTER;
1496 ieee = ieee80211_alloc_hw(sizeof(struct acx_device), &acxpci_hw_ops);
1497 if (!ieee) {
1498 printk("acx: could not allocate ieee80211 structure %s\n",
1499 pci_name(pdev));
1500 goto fail_alloc_netdev;
1502 ieee->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
1503 ieee->queues = 1;
1505 /* (NB: memsets to 0 entire area) */
1506 if (!ieee) {
1507 printk("acx: could not allocate ieee structure %s\n",
1508 pci_name(pdev));
1509 goto fail_alloc_netdev;
1512 adev = ieee2adev(ieee);
1514 memset(adev, 0, sizeof(*adev));
1515 /** Set up our private interface **/
1516 spin_lock_init(&adev->lock); /* initial state: unlocked */
1517 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
1518 printk("mutex_init(&adev->mutex); // adev = 0x%px\n", adev);
1519 mutex_init(&adev->mutex);
1520 /* since nobody can see new netdev yet, we can as well
1521 ** just _presume_ that we're under sem (instead of actually taking it): */
1522 /* acx_sem_lock(adev); */
1523 adev->ieee = ieee;
1524 adev->pdev = pdev;
1525 adev->bus_dev = &pdev->dev;
1526 adev->dev_type = DEVTYPE_PCI;
1528 /** Finished with private interface **/
1530 /** begin board specific inits **/
1531 pci_set_drvdata(pdev, ieee);
1533 /* Enable the PCI device */
1534 if (pci_enable_device(pdev)) {
1535 printk("acx: pci_enable_device() FAILED\n");
1536 result = -ENODEV;
1537 goto fail_pci_enable_device;
1540 /* enable busmastering (required for CardBus) */
1541 pci_set_master(pdev);
1544 /* chiptype is u8 but id->driver_data is ulong
1545 ** Works for now (possible values are 1 and 2) */
1546 chip_type = (u8) id->driver_data;
1547 /* acx100 and acx111 have different PCI memory regions */
1548 if (chip_type == CHIPTYPE_ACX100) {
1549 chip_name = "ACX100";
1550 mem_region1 = PCI_ACX100_REGION1;
1551 mem_region1_size = PCI_ACX100_REGION1_SIZE;
1553 mem_region2 = PCI_ACX100_REGION2;
1554 mem_region2_size = PCI_ACX100_REGION2_SIZE;
1555 } else if (chip_type == CHIPTYPE_ACX111) {
1556 chip_name = "ACX111";
1557 mem_region1 = PCI_ACX111_REGION1;
1558 mem_region1_size = PCI_ACX111_REGION1_SIZE;
1560 mem_region2 = PCI_ACX111_REGION2;
1561 mem_region2_size = PCI_ACX111_REGION2_SIZE;
1562 } else {
1563 printk("acx: unknown chip type 0x%04X\n", chip_type);
1564 goto fail_unknown_chiptype;
1567 /* Figure out our resources */
1568 phymem1 = pci_resource_start(pdev, mem_region1);
1569 phymem2 = pci_resource_start(pdev, mem_region2);
1570 if (!request_mem_region
1571 (phymem1, pci_resource_len(pdev, mem_region1), "acx_1")) {
1572 printk("acx: cannot reserve PCI memory region 1 (are you sure "
1573 "you have CardBus support in kernel?)\n");
1574 goto fail_request_mem_region1;
1576 if (!request_mem_region
1577 (phymem2, pci_resource_len(pdev, mem_region2), "acx_2")) {
1578 printk("acx: cannot reserve PCI memory region 2\n");
1579 goto fail_request_mem_region2;
1581 /* this used to be ioremap(), but ioremap_nocache()
1582 * is much less risky, right? (and slower?)
1583 * FIXME: we may want to go back to cached variant if it's
1584 * certain that our code really properly handles
1585 * cached operation (memory barriers, volatile?, ...)
1586 * (but always keep this comment here regardless!)
1587 * Possibly make this a driver config setting?
1590 mem1 = ioremap_nocache(phymem1, mem_region1_size);
1591 if (!mem1) {
1592 printk("acx: ioremap() FAILED\n");
1593 goto fail_ioremap1;
1595 mem2 = ioremap_nocache(phymem2, mem_region2_size);
1596 if (!mem2) {
1597 printk("acx: ioremap() #2 FAILED\n");
1598 goto fail_ioremap2;
1601 printk("acx: found %s-based wireless network card at %s, irq:%d, "
1602 "phymem1:0x%lX, phymem2:0x%lX, mem1:0x%p, mem1_size:%ld, "
1603 "mem2:0x%p, mem2_size:%ld\n",
1604 chip_name, pci_name(pdev), pdev->irq, phymem1, phymem2,
1605 mem1, mem_region1_size, mem2, mem_region2_size);
1606 log(L_ANY, "initial debug setting is 0x%04X\n", acx_debug);
1607 adev->chip_type = chip_type;
1608 adev->chip_name = chip_name;
1609 adev->io = (CHIPTYPE_ACX100 == chip_type) ? IO_ACX100 : IO_ACX111;
1610 adev->membase = phymem1;
1611 adev->iobase = mem1;
1612 adev->membase2 = phymem2;
1613 adev->iobase2 = mem2;
1614 adev->irq = pdev->irq;
1617 if (0 == pdev->irq) {
1618 printk("acx: can't use IRQ 0\n");
1619 goto fail_irq;
1621 SET_IEEE80211_DEV(ieee, &pdev->dev);
1624 /* to find crashes due to weird driver access
1625 * to unconfigured interface (ifup) */
1626 adev->mgmt_timer.function = (void (*)(unsigned long))0x0000dead;
1629 #ifdef NONESSENTIAL_FEATURES
1630 acx_show_card_eeprom_id(adev);
1631 #endif /* NONESSENTIAL_FEATURES */
1634 /* ok, pci setup is finished, now start initializing the card */
1636 /* NB: read_reg() reads may return bogus data before reset_dev(),
1637 * since the firmware which directly controls large parts of the I/O
1638 * registers isn't initialized yet.
1639 * acx100 seems to be more affected than acx111 */
1640 if (OK != acxpci_s_reset_dev(adev))
1641 goto fail_reset;
1643 if (IS_ACX100(adev)) {
1644 /* ACX100: configopt struct in cmd mailbox - directly after reset */
1645 memcpy_fromio(&co, adev->cmd_area, sizeof(co));
1648 if (OK != acx_s_init_mac(adev))
1649 goto fail_init_mac;
1651 if (IS_ACX111(adev)) {
1652 /* ACX111: configopt struct needs to be queried after full init */
1653 acx_s_interrogate(adev, &co, ACX111_IE_CONFIG_OPTIONS);
1655 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
1656 if (OK != acxpci_read_eeprom_byte(adev, 0x05, &adev->eeprom_version))
1657 goto fail_read_eeprom_version;
1659 acx_s_parse_configoption(adev, &co);
1660 acx_s_set_defaults(adev);
1661 acx_s_get_firmware_version(adev); /* needs to be after acx_s_init_mac() */
1662 acx_display_hardware_details(adev);
1664 /* Register the card, AFTER everything else has been set up,
1665 * since otherwise an ioctl could step on our feet due to
1666 * firmware operations happening in parallel or uninitialized data */
1669 acx_proc_register_entries(ieee);
1671 /* Now we have our device, so make sure the kernel doesn't try
1672 * to send packets even though we're not associated to a network yet */
1674 /* after register_netdev() userspace may start working with dev
1675 * (in particular, on other CPUs), we only need to up the sem */
1676 /* acx_sem_unlock(adev); */
1678 printk("acx " ACX_RELEASE ": net device %s, driver compiled "
1679 "against wireless extensions %d and Linux %s\n",
1680 wiphy_name(adev->ieee->wiphy), WIRELESS_EXT, UTS_RELEASE);
1682 MAC_COPY(adev->ieee->wiphy->perm_addr, adev->dev_addr);
1684 log(L_IRQ | L_INIT, "using IRQ %d\n", pdev->irq);
1686 /** done with board specific setup **/
1688 /* need to be able to restore PCI state after a suspend */
1689 #ifdef CONFIG_PM
1690 pci_save_state(pdev);
1691 #endif
1694 acx_init_task_scheduler(adev);
1695 err = ieee80211_register_hw(adev->ieee);
1696 if (OK != err) {
1697 printk("acx: ieee80211_register_hw() FAILED: %d\n", err);
1698 goto fail_register_netdev;
1700 #if CMD_DISCOVERY
1701 great_inquisitor(adev);
1702 #endif
1704 result = OK;
1705 goto done;
1707 /* error paths: undo everything in reverse order... */
1710 acxpci_s_delete_dma_regions(adev);
1711 pci_set_drvdata(pdev, NULL);
1713 fail_init_mac:
1714 fail_read_eeprom_version:
1715 fail_reset:
1717 fail_alloc_netdev:
1718 fail_irq:
1720 iounmap(mem2);
1721 fail_ioremap2:
1723 iounmap(mem1);
1724 fail_ioremap1:
1726 release_mem_region(pci_resource_start(pdev, mem_region2),
1727 pci_resource_len(pdev, mem_region2));
1728 fail_request_mem_region2:
1730 release_mem_region(pci_resource_start(pdev, mem_region1),
1731 pci_resource_len(pdev, mem_region1));
1732 fail_request_mem_region1:
1733 fail_unknown_chiptype:
1735 pci_disable_device(pdev);
1736 fail_pci_enable_device:
1738 #ifdef CONFIG_PM
1739 pci_set_power_state(pdev, PCI_D3hot);
1740 #endif
1741 fail_register_netdev:
1742 ieee80211_free_hw(ieee);
1743 done:
1744 FN_EXIT1(result);
1745 return result;
1749 /***********************************************************************
1750 ** acxpci_e_remove
1752 ** Shut device down (if not hot unplugged)
1753 ** and deallocate PCI resources for the acx chip.
1755 ** pdev - ptr to PCI device structure containing info about pci configuration
1757 static void __devexit acxpci_e_remove(struct pci_dev *pdev)
1759 struct ieee80211_hw *hw = (struct ieee80211_hw *)pci_get_drvdata(pdev);
1760 acx_device_t *adev = ieee2adev(hw);
1761 unsigned long mem_region1, mem_region2;
1762 unsigned long flags;
1763 FN_ENTER;
1765 if (!hw) {
1766 log(L_DEBUG, "%s: card is unused. Skipping any release code\n",
1767 __func__);
1768 goto end;
1772 acx_lock(adev, flags);
1773 acx_unlock(adev, flags);
1774 adev->initialized = 0;
1776 /* If device wasn't hot unplugged... */
1777 if (adev_present(adev)) {
1779 acx_sem_lock(adev);
1781 /* disable both Tx and Rx to shut radio down properly */
1782 if (adev->initialized) {
1783 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_TX, NULL, 0);
1784 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_RX, NULL, 0);
1786 #ifdef REDUNDANT
1787 /* put the eCPU to sleep to save power
1788 * Halting is not possible currently,
1789 * since not supported by all firmware versions */
1790 acx_s_issue_cmd(adev, ACX100_CMD_SLEEP, NULL, 0);
1791 #endif
1792 acx_lock(adev, flags);
1793 /* disable power LED to save power :-) */
1794 log(L_INIT, "switching off power LED to save power\n");
1795 acxpci_l_power_led(adev, 0);
1796 /* stop our eCPU */
1797 if (IS_ACX111(adev)) {
1798 /* FIXME: does this actually keep halting the eCPU?
1799 * I don't think so...
1801 acxpci_l_reset_mac(adev);
1802 } else {
1803 u16 temp;
1804 /* halt eCPU */
1805 temp = read_reg16(adev, IO_ACX_ECPU_CTRL) | 0x1;
1806 write_reg16(adev, IO_ACX_ECPU_CTRL, temp);
1807 write_flush(adev);
1809 acx_unlock(adev, flags);
1811 acx_sem_unlock(adev);
1814 /* unregister the device to not let the kernel
1815 * (e.g. ioctls) access a half-deconfigured device
1816 * NB: this will cause acxpci_e_close() to be called,
1817 * thus we shouldn't call it under sem!
1818 * Well, netdev did, but ieee80211 stack does not, so we
1819 * have to do so manually...
1821 acxpci_e_close(hw);
1822 log(L_INIT, "removing device %s\n", wiphy_name(adev->ieee->wiphy));
1823 ieee80211_unregister_hw(adev->ieee);
1825 /* unregister_netdev ensures that no references to us left.
1826 * For paranoid reasons we continue to follow the rules */
1827 acx_sem_lock(adev);
1829 if (adev->dev_state_mask & ACX_STATE_IFACE_UP) {
1830 acxpci_s_down(hw);
1831 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
1834 acx_proc_unregister_entries(adev->ieee);
1836 if (IS_ACX100(adev)) {
1837 mem_region1 = PCI_ACX100_REGION1;
1838 mem_region2 = PCI_ACX100_REGION2;
1839 } else {
1840 mem_region1 = PCI_ACX111_REGION1;
1841 mem_region2 = PCI_ACX111_REGION2;
1844 /* finally, clean up PCI bus state */
1845 acxpci_s_delete_dma_regions(adev);
1846 if (adev->iobase)
1847 iounmap(adev->iobase);
1848 if (adev->iobase2)
1849 iounmap(adev->iobase2);
1850 release_mem_region(pci_resource_start(pdev, mem_region1),
1851 pci_resource_len(pdev, mem_region1));
1852 release_mem_region(pci_resource_start(pdev, mem_region2),
1853 pci_resource_len(pdev, mem_region2));
1854 pci_disable_device(pdev);
1856 /* remove dev registration */
1858 free_irq(adev->irq, adev);
1859 acx_sem_unlock(adev);
1861 /* Free netdev (quite late,
1862 * since otherwise we might get caught off-guard
1863 * by a netdev timeout handler execution
1864 * expecting to see a working dev...) */
1865 ieee80211_free_hw(adev->ieee);
1867 /* put device into ACPI D3 mode (shutdown) */
1868 #ifdef CONFIG_PM
1869 pci_set_power_state(pdev, PCI_D3hot);
1870 #endif
1871 end:
1872 FN_EXIT0;
1876 /***********************************************************************
1877 ** TODO: PM code needs to be fixed / debugged / tested.
1879 #ifdef CONFIG_PM
1880 static int
1881 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
1882 acxpci_e_suspend(struct pci_dev *pdev, pm_message_t state)
1883 #else
1884 acxpci_e_suspend(struct pci_dev *pdev, u32 state)
1885 #endif
1887 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1888 acx_device_t *adev;
1890 FN_ENTER;
1891 printk("acx: suspend handler is experimental!\n");
1892 printk("sus: dev %p\n", hw);
1894 /* if (!netif_running(ndev))
1895 goto end;
1897 adev = ieee2adev(hw);
1898 printk("sus: adev %p\n", adev);
1900 acx_sem_lock(adev);
1902 ieee80211_unregister_hw(hw); /* this one cannot sleep */
1903 acxpci_s_down(hw);
1904 /* down() does not set it to 0xffff, but here we really want that */
1905 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
1906 write_reg16(adev, IO_ACX_FEMR, 0x0);
1907 acxpci_s_delete_dma_regions(adev);
1908 pci_save_state(pdev);
1909 pci_set_power_state(pdev, PCI_D3hot);
1911 acx_sem_unlock(adev);
1912 FN_EXIT0;
1913 return OK;
1917 static int acxpci_e_resume(struct pci_dev *pdev)
1919 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1920 acx_device_t *adev;
1922 FN_ENTER;
1924 printk("acx: resume handler is experimental!\n");
1925 printk("rsm: got dev %p\n", hw);
1928 adev = ieee2adev(hw);
1929 printk("rsm: got adev %p\n", adev);
1931 acx_sem_lock(adev);
1933 pci_set_power_state(pdev, PCI_D0);
1934 printk("rsm: power state PCI_D0 set\n");
1935 pci_restore_state(pdev);
1936 printk("rsm: PCI state restored\n");
1938 if (OK != acxpci_s_reset_dev(adev))
1939 goto end_unlock;
1940 printk("rsm: device reset done\n");
1941 if (OK != acx_s_init_mac(adev))
1942 goto end_unlock;
1943 printk("rsm: init MAC done\n");
1945 acxpci_s_up(hw);
1946 printk("rsm: acx up done\n");
1948 /* now even reload all card parameters as they were before suspend,
1949 * and possibly be back in the network again already :-) */
1950 if (ACX_STATE_IFACE_UP & adev->dev_state_mask) {
1951 adev->set_mask = GETSET_ALL;
1952 acx_s_update_card_settings(adev);
1953 printk("rsm: settings updated\n");
1955 ieee80211_register_hw(hw);
1956 printk("rsm: device attached\n");
1958 end_unlock:
1959 acx_sem_unlock(adev);
1960 /* we need to return OK here anyway, right? */
1961 FN_EXIT0;
1962 return OK;
1964 #endif /* CONFIG_PM */
1965 #endif /* CONFIG_PCI */
1967 /***********************************************************************
1968 ** acxpci_s_up
1970 ** This function is called by acxpci_e_open (when ifconfig sets the device as up)
1972 ** Side effects:
1973 ** - Enables on-card interrupt requests
1974 ** - calls acx_s_start
1977 static void enable_acx_irq(acx_device_t * adev)
1979 FN_ENTER;
1980 write_reg16(adev, IO_ACX_IRQ_MASK, adev->irq_mask);
1981 write_reg16(adev, IO_ACX_FEMR, 0x8000);
1982 adev->irqs_active = 1;
1983 FN_EXIT0;
1986 static void acxpci_s_up(struct ieee80211_hw *hw)
1988 acx_device_t *adev = ieee2adev(hw);
1989 unsigned long flags;
1991 FN_ENTER;
1993 acx_lock(adev, flags);
1994 enable_acx_irq(adev);
1995 acx_unlock(adev, flags);
1997 /* acx fw < 1.9.3.e has a hardware timer, and older drivers
1998 ** used to use it. But we don't do that anymore, our OS
1999 ** has reliable software timers */
2000 init_timer(&adev->mgmt_timer);
2001 adev->mgmt_timer.function = acx_i_timer;
2002 adev->mgmt_timer.data = (unsigned long)adev;
2004 /* Need to set ACX_STATE_IFACE_UP first, or else
2005 ** timer won't be started by acx_set_status() */
2006 SET_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
2008 acx_s_start(adev);
2010 FN_EXIT0;
2014 /***********************************************************************
2015 ** acxpci_s_down
2017 ** NB: device may be already hot unplugged if called from acxpci_e_remove()
2019 ** Disables on-card interrupt request, stops softirq and timer, stops queue,
2020 ** sets status == STOPPED
2023 static void disable_acx_irq(acx_device_t * adev)
2025 FN_ENTER;
2027 /* I guess mask is not 0xffff because acx100 won't signal
2028 ** cmd completion then (needed for ifup).
2029 ** Someone with acx100 please confirm */
2030 write_reg16(adev, IO_ACX_IRQ_MASK, adev->irq_mask_off);
2031 write_reg16(adev, IO_ACX_FEMR, 0x0);
2032 adev->irqs_active = 0;
2033 FN_EXIT0;
2036 static void acxpci_s_down(struct ieee80211_hw *hw)
2038 acx_device_t *adev = ieee2adev(hw);
2039 unsigned long flags;
2041 FN_ENTER;
2043 /* Disable IRQs first, so that IRQs cannot race with us */
2044 /* then wait until interrupts have finished executing on other CPUs */
2045 printk("acxpci_s_down: acx_lock()\n");
2046 acx_s_mdelay(1000);
2047 acx_lock(adev, flags);
2048 disable_acx_irq(adev);
2049 synchronize_irq(adev->irq);
2050 printk("acxpci_s_down: acx_unlock()\n");
2051 acx_s_mdelay(1000);
2052 acx_unlock(adev, flags);
2054 /* we really don't want to have an asynchronous tasklet disturb us
2055 ** after something vital for its job has been shut down, so
2056 ** end all remaining work now.
2058 ** NB: carrier_off (done by set_status below) would lead to
2059 ** not yet fully understood deadlock in flush_scheduled_work().
2060 ** That's why we do FLUSH first.
2062 ** NB2: we have a bad locking bug here: flush_scheduled_work()
2063 ** waits for acx_e_after_interrupt_task to complete if it is running
2064 ** on another CPU, but acx_e_after_interrupt_task
2065 ** will sleep on sem forever, because it is taken by us!
2066 ** Work around that by temporary sem unlock.
2067 ** This will fail miserably if we'll be hit by concurrent
2068 ** iwconfig or something in between. TODO! */
2069 printk("acxpci_s_down: flush_scheduled_work()\n");
2070 acx_s_mdelay(1000);
2071 flush_scheduled_work();
2073 /* This is possible:
2074 ** flush_scheduled_work -> acx_e_after_interrupt_task ->
2075 ** -> set_status(ASSOCIATED) -> wake_queue()
2076 ** That's why we stop queue _after_ flush_scheduled_work
2077 ** lock/unlock is just paranoia, maybe not needed */
2079 /* kernel/timer.c says it's illegal to del_timer_sync()
2080 ** a timer which restarts itself. We guarantee this cannot
2081 ** ever happen because acx_i_timer() never does this if
2082 ** status is ACX_STATUS_0_STOPPED */
2083 printk("acxpci_s_down: del_timer_sync()\n");
2084 acx_s_mdelay(1000);
2085 del_timer_sync(&adev->mgmt_timer);
2087 FN_EXIT0;
2090 #ifdef CONFIG_NET_POLL_CONTROLLER
2091 void acxpci_net_poll_controller(struct net_device *net_dev)
2093 acx_device_t *adev = ndev2adev(net_dev);
2094 unsigned long flags;
2096 local_irq_save(flags);
2097 acxpci_i_interrupt(adev->irq, adev);
2098 local_irq_restore(flags);
2100 #endif*/ /* CONFIG_NET_POLL_CONTROLLER */
2102 /***********************************************************************
2103 ** acxpci_e_open
2105 ** Called as a result of SIOCSIFFLAGS ioctl changing the flags bit IFF_UP
2106 ** from clear to set. In other words: ifconfig up.
2108 ** Returns:
2109 ** 0 success
2110 ** >0 f/w reported error
2111 ** <0 driver reported error
2113 static int acxpci_e_open(struct ieee80211_hw *hw)
2115 acx_device_t *adev = ieee2adev(hw);
2116 int result = OK;
2118 FN_ENTER;
2120 acx_sem_lock(adev);
2122 adev->initialized = 0;
2124 /* TODO: pci_set_power_state(pdev, PCI_D0); ? */
2126 /* request shared IRQ handler */
2127 if (request_irq
2128 (adev->irq, acxpci_i_interrupt, IRQF_SHARED, KBUILD_MODNAME, adev)) {
2129 printk("%s: request_irq FAILED\n", wiphy_name(adev->ieee->wiphy));
2130 result = -EAGAIN;
2131 goto done;
2133 log(L_DEBUG | L_IRQ, "request_irq %d successful\n", adev->irq);
2135 /* ifup device */
2136 acxpci_s_up(hw);
2138 /* We don't currently have to do anything else.
2139 * The setup of the MAC should be subsequently completed via
2140 * the mlme commands.
2141 * Higher layers know we're ready from dev->start==1 and
2142 * dev->tbusy==0. Our rx path knows to pass up received/
2143 * frames because of dev->flags&IFF_UP is true.
2145 acx_setup_modes(adev);
2146 ieee80211_start_queues(adev->ieee);
2148 adev->initialized = 1;
2149 done:
2150 acx_sem_unlock(adev);
2152 FN_EXIT1(result);
2153 return result;
2157 /***********************************************************************
2158 ** acxpci_e_close
2160 ** This function stops the network functionality of the interface (invoked
2161 ** when the user calls ifconfig <wlan> down). The tx queue is halted and
2162 ** the device is marked as down.
2164 ** Called as a result of SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
2165 ** from set to clear. I.e. called by "ifconfig DEV down"
2167 ** Returns:
2168 ** 0 success
2169 ** >0 f/w reported error
2170 ** <0 driver reported error
2172 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
2173 static int acxpci_e_close(struct ieee80211_hw *hw)
2174 #else
2175 static void acxpci_e_close(struct ieee80211_hw *hw)
2176 #endif
2178 acx_device_t *adev = ieee2adev(hw);
2179 unsigned long flags;
2180 FN_ENTER;
2181 printk("putting interface DOWN - this is filled with printk's and will take 8-10 seconds!\n");
2182 printk("acxpci_e_close: acx_lock()\n");
2183 acx_s_mdelay(1000);
2184 acx_lock(adev,flags);
2185 /* ifdown device */
2186 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
2187 if (adev->initialized) {
2188 printk("acxpci_e_close: acxpci_s_down()\n");
2189 acx_s_mdelay(1000);
2190 acxpci_s_down(hw);
2193 if (adev->modes)
2194 acx_free_modes(adev);
2195 /* disable all IRQs, release shared IRQ handler */
2196 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
2197 write_reg16(adev, IO_ACX_FEMR, 0x0);
2199 /* TODO: pci_set_power_state(pdev, PCI_D3hot); ? */
2201 /* We currently don't have to do anything else.
2202 * Higher layers know we're not ready from dev->start==0 and
2203 * dev->tbusy==1. Our rx path knows to not pass up received
2204 * frames because of dev->flags&IFF_UP is false.
2206 printk("acxpci_e_close: acx_unlock()\n");
2207 acx_s_mdelay(1000);
2208 acx_unlock(adev,flags);
2210 log(L_INIT, "closed device\n");
2211 FN_EXIT0;
2212 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
2213 return OK;
2214 #else
2215 #endif
2221 /***************************************************************
2222 ** acxpci_l_process_rxdesc
2224 ** Called directly and only from the IRQ handler
2227 #if !ACX_DEBUG
2228 static inline void log_rxbuffer(const acx_device_t * adev)
2231 #else
2232 static void log_rxbuffer(const acx_device_t * adev)
2234 register const struct rxhostdesc *rxhostdesc;
2235 int i;
2237 /* no FN_ENTER here, we don't want that */
2239 rxhostdesc = adev->rxhostdesc_start;
2240 if (unlikely(!rxhostdesc))
2241 return;
2242 for (i = 0; i < RX_CNT; i++) {
2243 if ((rxhostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2244 && (rxhostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2245 printk("rx: buf %d full\n", i);
2246 rxhostdesc++;
2249 #endif
2251 static void acxpci_l_process_rxdesc(acx_device_t * adev)
2253 register rxhostdesc_t *hostdesc;
2254 unsigned count, tail;
2256 FN_ENTER;
2258 if (unlikely(acx_debug & L_BUFR))
2259 log_rxbuffer(adev);
2261 /* First, have a loop to determine the first descriptor that's
2262 * full, just in case there's a mismatch between our current
2263 * rx_tail and the full descriptor we're supposed to handle. */
2264 tail = adev->rx_tail;
2265 count = RX_CNT;
2266 while (1) {
2267 hostdesc = &adev->rxhostdesc_start[tail];
2268 /* advance tail regardless of outcome of the below test */
2269 tail = (tail + 1) % RX_CNT;
2271 if ((hostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2272 && (hostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2273 break; /* found it! */
2275 if (unlikely(!--count)) /* hmm, no luck: all descs empty, bail out */
2276 goto end;
2279 /* now process descriptors, starting with the first we figured out */
2280 while (1) {
2281 log(L_BUFR, "rx: tail=%u Ctl_16=%04X Status=%08X\n",
2282 tail, hostdesc->Ctl_16, hostdesc->Status);
2284 acx_l_process_rxbuf(adev, hostdesc->data);
2285 hostdesc->Status = 0;
2286 /* flush all writes before adapter sees CTL_HOSTOWN change */
2287 wmb();
2288 /* Host no longer owns this, needs to be LAST */
2289 CLEAR_BIT(hostdesc->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
2291 /* ok, descriptor is handled, now check the next descriptor */
2292 hostdesc = &adev->rxhostdesc_start[tail];
2294 /* if next descriptor is empty, then bail out */
2295 if (!(hostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2296 || !(hostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2297 break;
2299 tail = (tail + 1) % RX_CNT;
2301 end:
2302 adev->rx_tail = tail;
2303 FN_EXIT0;
2308 /***********************************************************************
2309 ** acxpci_i_interrupt
2311 ** IRQ handler (atomic context, must not sleep, blah, blah)
2314 /* scan is complete. all frames now on the receive queue are valid */
2315 #define INFO_SCAN_COMPLETE 0x0001
2316 #define INFO_WEP_KEY_NOT_FOUND 0x0002
2317 /* hw has been reset as the result of a watchdog timer timeout */
2318 #define INFO_WATCH_DOG_RESET 0x0003
2319 /* failed to send out NULL frame from PS mode notification to AP */
2320 /* recommended action: try entering 802.11 PS mode again */
2321 #define INFO_PS_FAIL 0x0004
2322 /* encryption/decryption process on a packet failed */
2323 #define INFO_IV_ICV_FAILURE 0x0005
2325 /* Info mailbox format:
2326 2 bytes: type
2327 2 bytes: status
2328 more bytes may follow
2329 rumors say about status:
2330 0x0000 info available (set by hw)
2331 0x0001 information received (must be set by host)
2332 0x1000 info available, mailbox overflowed (messages lost) (set by hw)
2333 but in practice we've seen:
2334 0x9000 when we did not set status to 0x0001 on prev message
2335 0x1001 when we did set it
2336 0x0000 was never seen
2337 conclusion: this is really a bitfield:
2338 0x1000 is 'info available' bit
2339 'mailbox overflowed' bit is 0x8000, not 0x1000
2340 value of 0x0000 probably means that there are no messages at all
2341 P.S. I dunno how in hell hw is supposed to notice that messages are lost -
2342 it does NOT clear bit 0x0001, and this bit will probably stay forever set
2343 after we set it once. Let's hope this will be fixed in firmware someday
2346 static void handle_info_irq(acx_device_t * adev)
2348 #if ACX_DEBUG
2349 static const char *const info_type_msg[] = {
2350 "(unknown)",
2351 "scan complete",
2352 "WEP key not found",
2353 "internal watchdog reset was done",
2354 "failed to send powersave (NULL frame) notification to AP",
2355 "encrypt/decrypt on a packet has failed",
2356 "TKIP tx keys disabled",
2357 "TKIP rx keys disabled",
2358 "TKIP rx: key ID not found",
2359 "???",
2360 "???",
2361 "???",
2362 "???",
2363 "???",
2364 "???",
2365 "???",
2366 "TKIP IV value exceeds thresh"
2368 #endif
2369 u32 info_type, info_status;
2371 info_type = acx_readl(adev->info_area);
2372 info_status = (info_type >> 16);
2373 info_type = (u16) info_type;
2375 /* inform fw that we have read this info message */
2376 acx_writel(info_type | 0x00010000, adev->info_area);
2377 write_reg16(adev, IO_ACX_INT_TRIG, INT_TRIG_INFOACK);
2378 write_flush(adev);
2380 log(L_CTL, "info_type:%04X info_status:%04X\n", info_type, info_status);
2382 log(L_IRQ, "got Info IRQ: status %04X type %04X: %s\n",
2383 info_status, info_type,
2384 info_type_msg[(info_type >= ARRAY_SIZE(info_type_msg)) ?
2385 0 : info_type]
2390 static void log_unusual_irq(u16 irqtype)
2393 if (!printk_ratelimit())
2394 return;
2397 printk("acx: got");
2398 if (irqtype & HOST_INT_RX_DATA) {
2399 printk(" Rx_Data");
2401 /* HOST_INT_TX_COMPLETE */
2402 if (irqtype & HOST_INT_TX_XFER) {
2403 printk(" Tx_Xfer");
2405 /* HOST_INT_RX_COMPLETE */
2406 if (irqtype & HOST_INT_DTIM) {
2407 printk(" DTIM");
2409 if (irqtype & HOST_INT_BEACON) {
2410 printk(" Beacon");
2412 if (irqtype & HOST_INT_TIMER) {
2413 log(L_IRQ, " Timer");
2415 if (irqtype & HOST_INT_KEY_NOT_FOUND) {
2416 printk(" Key_Not_Found");
2418 if (irqtype & HOST_INT_IV_ICV_FAILURE) {
2419 printk(" IV_ICV_Failure (crypto)");
2421 /* HOST_INT_CMD_COMPLETE */
2422 /* HOST_INT_INFO */
2423 if (irqtype & HOST_INT_OVERFLOW) {
2424 printk(" Overflow");
2426 if (irqtype & HOST_INT_PROCESS_ERROR) {
2427 printk(" Process_Error");
2429 /* HOST_INT_SCAN_COMPLETE */
2430 if (irqtype & HOST_INT_FCS_THRESHOLD) {
2431 printk(" FCS_Threshold");
2433 if (irqtype & HOST_INT_UNKNOWN) {
2434 printk(" Unknown");
2436 printk(" IRQ(s)\n");
2440 static void update_link_quality_led(acx_device_t * adev)
2442 /* int qual; */
2444 /* qual =
2445 acx_signal_determine_quality(adev->wstats.qual.level,
2446 adev->wstats.qual.noise);
2447 if (qual > adev->brange_max_quality)
2448 qual = adev->brange_max_quality;
2451 /* if (time_after(jiffies, adev->brange_time_last_state_change +
2452 (HZ / 2 -
2453 HZ / 2 * (unsigned long)qual /
2454 adev->brange_max_quality))) {
2455 acxpci_l_power_led(adev, (adev->brange_last_state == 0));
2456 adev->brange_last_state ^= 1; *//* toggle */
2457 /* adev->brange_time_last_state_change = jiffies;
2462 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* a la orinoco.c */
2464 /* Interrupt handler bottom-half */
2465 void acx_interrupt_tasklet(struct work_struct *work)
2468 #ifdef CONFIG_ACX_MAC80211_DEBUG
2469 u32 _handled = 0x00000000;
2470 # define acxirq_handled(irq) do { _handled |= (irq); } while (0)
2471 #else
2472 # define acxirq_handled(irq) do { /* nothing */ } while (0)
2473 #endif /* CONFIG_ACX_MAC80211_DEBUG */
2474 acx_device_t *adev = container_of(work,struct acx_device, after_interrupt_task);
2475 // unsigned int irqcount = MAX_IRQLOOPS_PER_JIFFY;
2476 int irqtype;
2478 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2479 * I am paranoid */
2480 acx_sem_lock(adev);
2483 FN_ENTER;
2484 irqtype = adev->irq_reason;
2485 adev->irq_reason = 0;
2487 #define IRQ_ITERATE 0
2488 #if IRQ_ITERATE
2489 if (jiffies != adev->irq_last_jiffies) {
2490 adev->irq_loops_this_jiffy = 0;
2491 adev->irq_last_jiffies = jiffies;
2494 /* safety condition; we'll normally abort loop below
2495 * in case no IRQ type occurred */
2496 while (likely(--irqcount)) {
2497 #endif
2498 /* ACK all IRQs ASAP */
2501 /* Handle most important IRQ types first */
2502 if (irqtype & HOST_INT_RX_COMPLETE) {
2503 log(L_IRQ, "got Rx_Complete IRQ\n");
2504 acxpci_l_process_rxdesc(adev);
2506 if (irqtype & HOST_INT_TX_COMPLETE) {
2507 log(L_IRQ, "got Tx_Complete IRQ\n");
2508 /* don't clean up on each Tx complete, wait a bit
2509 * unless we're going towards full, in which case
2510 * we do it immediately, too (otherwise we might lockup
2511 * with a full Tx buffer if we go into
2512 * acxpci_l_clean_txdesc() at a time when we won't wakeup
2513 * the net queue in there for some reason...) */
2514 // if (adev->tx_free <= TX_START_CLEAN) {
2515 acxpci_l_clean_txdesc(adev);
2516 // }
2519 /* Less frequent ones */
2520 if (irqtype & (0
2521 | HOST_INT_CMD_COMPLETE
2522 | HOST_INT_INFO | HOST_INT_SCAN_COMPLETE)) {
2523 if (irqtype & HOST_INT_INFO) {
2524 handle_info_irq(adev);
2526 if (irqtype & HOST_INT_SCAN_COMPLETE) {
2527 log(L_IRQ, "got Scan_Complete IRQ\n");
2528 /* need to do that in process context */
2529 /* remember that fw is not scanning anymore */
2530 SET_BIT(adev->irq_status,
2531 HOST_INT_SCAN_COMPLETE);
2535 /* These we just log, but either they happen rarely
2536 * or we keep them masked out */
2537 if (irqtype & (0 | HOST_INT_RX_DATA
2538 /* | HOST_INT_TX_COMPLETE */
2539 | HOST_INT_TX_XFER
2540 /* | HOST_INT_RX_COMPLETE */
2541 | HOST_INT_DTIM
2542 | HOST_INT_BEACON
2543 | HOST_INT_TIMER
2544 | HOST_INT_KEY_NOT_FOUND
2545 | HOST_INT_IV_ICV_FAILURE
2546 /* | HOST_INT_CMD_COMPLETE */
2547 /* | HOST_INT_INFO */
2548 | HOST_INT_OVERFLOW | HOST_INT_PROCESS_ERROR
2549 /* | HOST_INT_SCAN_COMPLETE */
2550 | HOST_INT_FCS_THRESHOLD | HOST_INT_UNKNOWN)) {
2551 log_unusual_irq(irqtype);
2553 #if IRQ_ITERATE
2554 unmasked = read_reg16(adev, IO_ACX_IRQ_STATUS_CLEAR);
2555 irqtype = unmasked & ~adev->irq_mask;
2556 /* Bail out if no new IRQ bits or if all are masked out */
2557 if (!irqtype)
2558 break;
2560 if (unlikely
2561 (++adev->irq_loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY)) {
2562 printk(KERN_ERR
2563 "acx: too many interrupts per jiffy!\n");
2564 /* Looks like card floods us with IRQs! Try to stop that */
2565 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
2566 /* This will short-circuit all future attempts to handle IRQ.
2567 * We cant do much more... */
2568 adev->irq_mask = 0;
2569 break;
2572 #endif
2573 /* Routine to perform blink with range */
2574 if (unlikely(adev->led_power == 2))
2575 update_link_quality_led(adev);
2577 /* handled: */
2578 if (adev->after_interrupt_jobs)
2579 acx_e_after_interrupt_task(&adev->after_interrupt_task);
2581 /* write_flush(adev); - not needed, last op was read anyway */
2582 acx_sem_unlock(adev);
2583 FN_EXIT0;
2584 return;
2589 static irqreturn_t
2590 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
2591 acxpci_i_interrupt(int irq, void *dev_id)
2592 #else
2593 acxpci_i_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2594 #endif
2597 acx_device_t *adev = dev_id;
2598 unsigned long flags;
2599 register u16 irqtype;
2600 u16 unmasked;
2602 if (!adev)
2603 return IRQ_NONE;
2604 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2605 * I am paranoid */
2607 acx_lock(adev, flags);
2609 unmasked = read_reg16(adev, IO_ACX_IRQ_STATUS_CLEAR);
2611 if (unlikely(0xffff == unmasked)) {
2612 /* 0xffff value hints at missing hardware,
2613 * so don't do anything.
2614 * Not very clean, but other drivers do the same... */
2615 log(L_IRQ, "IRQ type:FFFF - device removed? IRQ_NONE\n");
2616 goto none;
2619 /* We will check only "interesting" IRQ types */
2620 irqtype = unmasked & ~adev->irq_mask;
2621 if (!irqtype) {
2622 /* We are on a shared IRQ line and it wasn't our IRQ */
2623 log(L_IRQ,
2624 "IRQ type:%04X, mask:%04X - all are masked, IRQ_NONE\n",
2625 unmasked, adev->irq_mask);
2626 goto none;
2629 /* Go ahead and ACK our interrupt */
2630 write_reg16(adev, IO_ACX_IRQ_ACK, 0xffff);
2631 if (irqtype & HOST_INT_CMD_COMPLETE) {
2632 log(L_IRQ, "got Command_Complete IRQ\n");
2633 /* save the state for the running issue_cmd() */
2634 SET_BIT(adev->irq_status, HOST_INT_CMD_COMPLETE);
2637 /* Only accept IRQs, if we are initialized properly.
2638 * This avoids an RX race while initializing.
2639 * We should probably not enable IRQs before we are initialized
2640 * completely, but some careful work is needed to fix this. I think it
2641 * is best to stay with this cheap workaround for now... .
2643 if (likely(adev->initialized)) {
2644 /* disable all IRQs. They are enabled again in the bottom half. */
2645 /* save the reason code and call our bottom half. */
2646 adev->irq_reason = irqtype;
2648 if ((irqtype & HOST_INT_RX_COMPLETE) || (irqtype & HOST_INT_TX_COMPLETE))
2649 acx_schedule_task(adev, 0);
2651 acx_unlock(adev, flags);
2652 return IRQ_HANDLED;
2653 none:
2654 acx_unlock(adev, flags);
2655 return IRQ_NONE;
2660 /***********************************************************************
2661 ** acxpci_l_power_led
2663 void acxpci_l_power_led(acx_device_t * adev, int enable)
2665 u16 gpio_pled = IS_ACX111(adev) ? 0x0040 : 0x0800;
2667 /* A hack. Not moving message rate limiting to adev->xxx
2668 * (it's only a debug message after all) */
2669 static int rate_limit = 0;
2671 if (rate_limit++ < 3)
2672 log(L_IOCTL, "Please report in case toggling the power "
2673 "LED doesn't work for your card!\n");
2674 if (enable)
2675 write_reg16(adev, IO_ACX_GPIO_OUT,
2676 read_reg16(adev, IO_ACX_GPIO_OUT) & ~gpio_pled);
2677 else
2678 write_reg16(adev, IO_ACX_GPIO_OUT,
2679 read_reg16(adev, IO_ACX_GPIO_OUT) | gpio_pled);
2683 /***********************************************************************
2684 ** Ioctls
2687 /***********************************************************************
2689 #if 0
2691 acx111pci_ioctl_info(struct net_device *ndev,
2692 struct iw_request_info *info,
2693 struct iw_param *vwrq, char *extra)
2695 #if ACX_DEBUG > 1
2696 acx_device_t *adev = ndev2adev(ndev);
2697 rxdesc_t *rxdesc;
2698 txdesc_t *txdesc;
2699 rxhostdesc_t *rxhostdesc;
2700 txhostdesc_t *txhostdesc;
2701 struct acx111_ie_memoryconfig memconf;
2702 struct acx111_ie_queueconfig queueconf;
2703 unsigned long flags;
2704 int i;
2705 char memmap[0x34];
2706 char rxconfig[0x8];
2707 char fcserror[0x8];
2708 char ratefallback[0x5];
2710 if (!(acx_debug & (L_IOCTL | L_DEBUG)))
2711 return OK;
2712 /* using printk() since we checked debug flag already */
2714 acx_sem_lock(adev);
2716 if (!IS_ACX111(adev)) {
2717 printk("acx111-specific function called "
2718 "with non-acx111 chip, aborting\n");
2719 goto end_ok;
2722 /* get Acx111 Memory Configuration */
2723 memset(&memconf, 0, sizeof(memconf));
2724 /* BTW, fails with 12 (Write only) error code.
2725 ** Retained for easy testing of issue_cmd error handling :) */
2726 acx_s_interrogate(adev, &memconf, ACX1xx_IE_QUEUE_CONFIG);
2728 /* get Acx111 Queue Configuration */
2729 memset(&queueconf, 0, sizeof(queueconf));
2730 acx_s_interrogate(adev, &queueconf, ACX1xx_IE_MEMORY_CONFIG_OPTIONS);
2732 /* get Acx111 Memory Map */
2733 memset(memmap, 0, sizeof(memmap));
2734 acx_s_interrogate(adev, &memmap, ACX1xx_IE_MEMORY_MAP);
2736 /* get Acx111 Rx Config */
2737 memset(rxconfig, 0, sizeof(rxconfig));
2738 acx_s_interrogate(adev, &rxconfig, ACX1xx_IE_RXCONFIG);
2740 /* get Acx111 fcs error count */
2741 memset(fcserror, 0, sizeof(fcserror));
2742 acx_s_interrogate(adev, &fcserror, ACX1xx_IE_FCS_ERROR_COUNT);
2744 /* get Acx111 rate fallback */
2745 memset(ratefallback, 0, sizeof(ratefallback));
2746 acx_s_interrogate(adev, &ratefallback, ACX1xx_IE_RATE_FALLBACK);
2748 /* force occurrence of a beacon interrupt */
2749 /* TODO: comment why is this necessary */
2750 write_reg16(adev, IO_ACX_HINT_TRIG, HOST_INT_BEACON);
2752 /* dump Acx111 Mem Configuration */
2753 printk("dump mem config:\n"
2754 "data read: %d, struct size: %d\n"
2755 "Number of stations: %1X\n"
2756 "Memory block size: %1X\n"
2757 "tx/rx memory block allocation: %1X\n"
2758 "count rx: %X / tx: %X queues\n"
2759 "options %1X\n"
2760 "fragmentation %1X\n"
2761 "Rx Queue 1 Count Descriptors: %X\n"
2762 "Rx Queue 1 Host Memory Start: %X\n"
2763 "Tx Queue 1 Count Descriptors: %X\n"
2764 "Tx Queue 1 Attributes: %X\n",
2765 memconf.len, (int)sizeof(memconf),
2766 memconf.no_of_stations,
2767 memconf.memory_block_size,
2768 memconf.tx_rx_memory_block_allocation,
2769 memconf.count_rx_queues, memconf.count_tx_queues,
2770 memconf.options,
2771 memconf.fragmentation,
2772 memconf.rx_queue1_count_descs,
2773 acx2cpu(memconf.rx_queue1_host_rx_start),
2774 memconf.tx_queue1_count_descs, memconf.tx_queue1_attributes);
2776 /* dump Acx111 Queue Configuration */
2777 printk("dump queue head:\n"
2778 "data read: %d, struct size: %d\n"
2779 "tx_memory_block_address (from card): %X\n"
2780 "rx_memory_block_address (from card): %X\n"
2781 "rx1_queue address (from card): %X\n"
2782 "tx1_queue address (from card): %X\n"
2783 "tx1_queue attributes (from card): %X\n",
2784 queueconf.len, (int)sizeof(queueconf),
2785 queueconf.tx_memory_block_address,
2786 queueconf.rx_memory_block_address,
2787 queueconf.rx1_queue_address,
2788 queueconf.tx1_queue_address, queueconf.tx1_attributes);
2790 /* dump Acx111 Mem Map */
2791 printk("dump mem map:\n"
2792 "data read: %d, struct size: %d\n"
2793 "Code start: %X\n"
2794 "Code end: %X\n"
2795 "WEP default key start: %X\n"
2796 "WEP default key end: %X\n"
2797 "STA table start: %X\n"
2798 "STA table end: %X\n"
2799 "Packet template start: %X\n"
2800 "Packet template end: %X\n"
2801 "Queue memory start: %X\n"
2802 "Queue memory end: %X\n"
2803 "Packet memory pool start: %X\n"
2804 "Packet memory pool end: %X\n"
2805 "iobase: %p\n"
2806 "iobase2: %p\n",
2807 *((u16 *) & memmap[0x02]), (int)sizeof(memmap),
2808 *((u32 *) & memmap[0x04]),
2809 *((u32 *) & memmap[0x08]),
2810 *((u32 *) & memmap[0x0C]),
2811 *((u32 *) & memmap[0x10]),
2812 *((u32 *) & memmap[0x14]),
2813 *((u32 *) & memmap[0x18]),
2814 *((u32 *) & memmap[0x1C]),
2815 *((u32 *) & memmap[0x20]),
2816 *((u32 *) & memmap[0x24]),
2817 *((u32 *) & memmap[0x28]),
2818 *((u32 *) & memmap[0x2C]),
2819 *((u32 *) & memmap[0x30]), adev->iobase, adev->iobase2);
2821 /* dump Acx111 Rx Config */
2822 printk("dump rx config:\n"
2823 "data read: %d, struct size: %d\n"
2824 "rx config: %X\n"
2825 "rx filter config: %X\n",
2826 *((u16 *) & rxconfig[0x02]), (int)sizeof(rxconfig),
2827 *((u16 *) & rxconfig[0x04]), *((u16 *) & rxconfig[0x06]));
2829 /* dump Acx111 fcs error */
2830 printk("dump fcserror:\n"
2831 "data read: %d, struct size: %d\n"
2832 "fcserrors: %X\n",
2833 *((u16 *) & fcserror[0x02]), (int)sizeof(fcserror),
2834 *((u32 *) & fcserror[0x04]));
2836 /* dump Acx111 rate fallback */
2837 printk("dump rate fallback:\n"
2838 "data read: %d, struct size: %d\n"
2839 "ratefallback: %X\n",
2840 *((u16 *) & ratefallback[0x02]), (int)sizeof(ratefallback),
2841 *((u8 *) & ratefallback[0x04]));
2843 /* protect against IRQ */
2844 acx_lock(adev, flags);
2846 /* dump acx111 internal rx descriptor ring buffer */
2847 rxdesc = adev->rxdesc_start;
2849 /* loop over complete receive pool */
2850 if (rxdesc)
2851 for (i = 0; i < RX_CNT; i++) {
2852 printk("\ndump internal rxdesc %d:\n"
2853 "mem pos %p\n"
2854 "next 0x%X\n"
2855 "acx mem pointer (dynamic) 0x%X\n"
2856 "CTL (dynamic) 0x%X\n"
2857 "Rate (dynamic) 0x%X\n"
2858 "RxStatus (dynamic) 0x%X\n"
2859 "Mod/Pre (dynamic) 0x%X\n",
2861 rxdesc,
2862 acx2cpu(rxdesc->pNextDesc),
2863 acx2cpu(rxdesc->ACXMemPtr),
2864 rxdesc->Ctl_8,
2865 rxdesc->rate, rxdesc->error, rxdesc->SNR);
2866 rxdesc++;
2869 /* dump host rx descriptor ring buffer */
2871 rxhostdesc = adev->rxhostdesc_start;
2873 /* loop over complete receive pool */
2874 if (rxhostdesc)
2875 for (i = 0; i < RX_CNT; i++) {
2876 printk("\ndump host rxdesc %d:\n"
2877 "mem pos %p\n"
2878 "buffer mem pos 0x%X\n"
2879 "buffer mem offset 0x%X\n"
2880 "CTL 0x%X\n"
2881 "Length 0x%X\n"
2882 "next 0x%X\n"
2883 "Status 0x%X\n",
2885 rxhostdesc,
2886 acx2cpu(rxhostdesc->data_phy),
2887 rxhostdesc->data_offset,
2888 le16_to_cpu(rxhostdesc->Ctl_16),
2889 le16_to_cpu(rxhostdesc->length),
2890 acx2cpu(rxhostdesc->desc_phy_next),
2891 rxhostdesc->Status);
2892 rxhostdesc++;
2895 /* dump acx111 internal tx descriptor ring buffer */
2896 txdesc = adev->txdesc_start;
2898 /* loop over complete transmit pool */
2899 if (txdesc)
2900 for (i = 0; i < TX_CNT; i++) {
2901 printk("\ndump internal txdesc %d:\n"
2902 "size 0x%X\n"
2903 "mem pos %p\n"
2904 "next 0x%X\n"
2905 "acx mem pointer (dynamic) 0x%X\n"
2906 "host mem pointer (dynamic) 0x%X\n"
2907 "length (dynamic) 0x%X\n"
2908 "CTL (dynamic) 0x%X\n"
2909 "CTL2 (dynamic) 0x%X\n"
2910 "Status (dynamic) 0x%X\n"
2911 "Rate (dynamic) 0x%X\n",
2913 (int)sizeof(struct txdesc),
2914 txdesc,
2915 acx2cpu(txdesc->pNextDesc),
2916 acx2cpu(txdesc->AcxMemPtr),
2917 acx2cpu(txdesc->HostMemPtr),
2918 le16_to_cpu(txdesc->total_length),
2919 txdesc->Ctl_8,
2920 txdesc->Ctl2_8, txdesc->error,
2921 txdesc->u.r1.rate);
2922 txdesc = advance_txdesc(adev, txdesc, 1);
2925 /* dump host tx descriptor ring buffer */
2927 txhostdesc = adev->txhostdesc_start;
2929 /* loop over complete host send pool */
2930 if (txhostdesc)
2931 for (i = 0; i < TX_CNT * 2; i++) {
2932 printk("\ndump host txdesc %d:\n"
2933 "mem pos %p\n"
2934 "buffer mem pos 0x%X\n"
2935 "buffer mem offset 0x%X\n"
2936 "CTL 0x%X\n"
2937 "Length 0x%X\n"
2938 "next 0x%X\n"
2939 "Status 0x%X\n",
2941 txhostdesc,
2942 acx2cpu(txhostdesc->data_phy),
2943 txhostdesc->data_offset,
2944 le16_to_cpu(txhostdesc->Ctl_16),
2945 le16_to_cpu(txhostdesc->length),
2946 acx2cpu(txhostdesc->desc_phy_next),
2947 le32_to_cpu(txhostdesc->Status));
2948 txhostdesc++;
2951 /* write_reg16(adev, 0xb4, 0x4); */
2953 acx_unlock(adev, flags);
2954 end_ok:
2956 acx_sem_unlock(adev);
2957 #endif /* ACX_DEBUG */
2958 return OK;
2962 /***********************************************************************
2965 acx100pci_ioctl_set_phy_amp_bias(struct net_device *ndev,
2966 struct iw_request_info *info,
2967 struct iw_param *vwrq, char *extra)
2969 acx_device_t *adev = ndev2adev(ndev);
2970 unsigned long flags;
2971 u16 gpio_old;
2973 if (!IS_ACX100(adev)) {
2974 /* WARNING!!!
2975 * Removing this check *might* damage
2976 * hardware, since we're tweaking GPIOs here after all!!!
2977 * You've been warned...
2978 * WARNING!!! */
2979 printk("acx: sorry, setting bias level for non-acx100 "
2980 "is not supported yet\n");
2981 return OK;
2984 if (*extra > 7) {
2985 printk("acx: invalid bias parameter, range is 0-7\n");
2986 return -EINVAL;
2989 acx_sem_lock(adev);
2991 /* Need to lock accesses to [IO_ACX_GPIO_OUT]:
2992 * IRQ handler uses it to update LED */
2993 acx_lock(adev, flags);
2994 gpio_old = read_reg16(adev, IO_ACX_GPIO_OUT);
2995 write_reg16(adev, IO_ACX_GPIO_OUT,
2996 (gpio_old & 0xf8ff) | ((u16) * extra << 8));
2997 acx_unlock(adev, flags);
2999 log(L_DEBUG, "gpio_old: 0x%04X\n", gpio_old);
3000 printk("%s: PHY power amplifier bias: old:%d, new:%d\n",
3001 ndev->name, (gpio_old & 0x0700) >> 8, (unsigned char)*extra);
3003 acx_sem_unlock(adev);
3005 return OK;
3007 #endif
3009 /***************************************************************
3010 ** acxpci_l_alloc_tx
3011 ** Actually returns a txdesc_t* ptr
3013 ** FIXME: in case of fragments, should allocate multiple descrs
3014 ** after figuring out how many we need and whether we still have
3015 ** sufficiently many.
3017 tx_t *acxpci_l_alloc_tx(acx_device_t * adev)
3019 struct txdesc *txdesc;
3020 unsigned head;
3021 u8 ctl8;
3023 FN_ENTER;
3025 if (unlikely(!adev->tx_free)) {
3026 printk("acx: BUG: no free txdesc left\n");
3027 txdesc = NULL;
3028 goto end;
3031 head = adev->tx_head;
3032 txdesc = get_txdesc(adev, head);
3033 ctl8 = txdesc->Ctl_8;
3035 /* 2005-10-11: there were several bug reports on this happening
3036 ** but now cause seems to be understood & fixed */
3037 if (unlikely(DESC_CTL_HOSTOWN != (ctl8 & DESC_CTL_ACXDONE_HOSTOWN))) {
3038 /* whoops, descr at current index is not free, so probably
3039 * ring buffer already full */
3040 printk("acx: BUG: tx_head:%d Ctl8:0x%02X - failed to find "
3041 "free txdesc\n", head, ctl8);
3042 txdesc = NULL;
3043 goto end;
3046 /* Needed in case txdesc won't be eventually submitted for tx */
3047 txdesc->Ctl_8 = DESC_CTL_ACXDONE_HOSTOWN;
3049 adev->tx_free--;
3050 log(L_BUFT, "tx: got desc %u, %u remain\n", head, adev->tx_free);
3051 /* Keep a few free descs between head and tail of tx ring.
3052 ** It is not absolutely needed, just feels safer */
3053 if (adev->tx_free < TX_STOP_QUEUE) {
3054 log(L_BUF, "stop queue (%u tx desc left)\n", adev->tx_free);
3055 acx_stop_queue(adev->ieee, NULL);
3058 /* returning current descriptor, so advance to next free one */
3059 adev->tx_head = (head + 1) % TX_CNT;
3060 end:
3061 FN_EXIT0;
3063 return (tx_t *) txdesc;
3067 /***********************************************************************
3069 void *acxpci_l_get_txbuf(acx_device_t * adev, tx_t * tx_opaque)
3071 return get_txhostdesc(adev, (txdesc_t *) tx_opaque)->data;
3075 /***********************************************************************
3076 ** acxpci_l_tx_data
3078 ** Can be called from IRQ (rx -> (AP bridging or mgmt response) -> tx).
3079 ** Can be called from acx_i_start_xmit (data frames from net core).
3081 ** FIXME: in case of fragments, should loop over the number of
3082 ** pre-allocated tx descrs, properly setting up transfer data and
3083 ** CTL_xxx flags according to fragment number.
3085 void
3086 acxpci_l_tx_data(acx_device_t * adev, tx_t * tx_opaque, int len,
3087 struct ieee80211_tx_control *ieeectl,struct sk_buff* skb)
3089 txdesc_t *txdesc = (txdesc_t *) tx_opaque;
3090 struct ieee80211_hdr *wireless_header;
3091 txhostdesc_t *hostdesc1, *hostdesc2;
3092 int rate_cur;
3093 u8 Ctl_8, Ctl2_8;
3094 int wlhdr_len;
3096 FN_ENTER;
3098 /* fw doesn't tx such packets anyhow */
3099 /* if (unlikely(len < WLAN_HDR_A3_LEN))
3100 goto end;
3102 hostdesc1 = get_txhostdesc(adev, txdesc);
3103 wireless_header = (struct ieee80211_hdr *)hostdesc1->data;
3104 /* modify flag status in separate variable to be able to write it back
3105 * in one big swoop later (also in order to have less device memory
3106 * accesses) */
3107 Ctl_8 = txdesc->Ctl_8;
3108 Ctl2_8 = 0; /* really need to init it to 0, not txdesc->Ctl2_8, it seems */
3110 hostdesc2 = hostdesc1 + 1;
3112 /* DON'T simply set Ctl field to 0 here globally,
3113 * it needs to maintain a consistent flag status (those are state flags!!),
3114 * otherwise it may lead to severe disruption. Only set or reset particular
3115 * flags at the exact moment this is needed... */
3117 /* let chip do RTS/CTS handshaking before sending
3118 * in case packet size exceeds threshold */
3119 if (ieeectl->flags & IEEE80211_TXCTL_USE_RTS_CTS)
3120 SET_BIT(Ctl2_8, DESC_CTL2_RTS);
3121 else
3122 CLEAR_BIT(Ctl2_8, DESC_CTL2_RTS);
3124 rate_cur = ieeectl->tx_rate;
3125 if (unlikely(!rate_cur)) {
3126 printk("acx: driver bug! bad ratemask\n");
3127 goto end;
3130 /* used in tx cleanup routine for auto rate and accounting: */
3131 /* put_txcr(adev, txdesc, clt, rate_cur); deprecated by mac80211 */
3133 txdesc->total_length = cpu_to_le16(len);
3134 wlhdr_len = ieee80211_get_hdrlen(le16_to_cpu(wireless_header->frame_control));
3135 hostdesc2->length = cpu_to_le16(len - wlhdr_len);
3137 if (!ieeectl->do_not_encrypt && ieeectl->key_idx>= 0)
3139 u16 key_idx = (u16)(ieeectl->key_idx);
3140 struct acx_key* key = &(adev->key[key_idx]);
3141 int wlhdr_len;
3142 if (key->enabled)
3144 memcpy(ieeehdr->wep_iv, ((u8*)wireless_header) + wlhdr_len, 4);
3148 if (IS_ACX111(adev)) {
3149 /* note that if !txdesc->do_auto, txrate->cur
3150 ** has only one nonzero bit */
3151 txdesc->u.r2.rate111 = cpu_to_le16(rate_cur
3152 /* WARNING: I was never able to make it work with prism54 AP.
3153 ** It was falling down to 1Mbit where shortpre is not applicable,
3154 ** and not working at all at "5,11 basic rates only" setting.
3155 ** I even didn't see tx packets in radio packet capture.
3156 ** Disabled for now --vda */
3157 /*| ((clt->shortpre && clt->cur!=RATE111_1) ? RATE111_SHORTPRE : 0) */
3159 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3160 /* should add this to rate111 above as necessary */
3161 |(clt->pbcc511 ? RATE111_PBCC511 : 0)
3162 #endif
3163 hostdesc1->length = cpu_to_le16(len);
3164 } else { /* ACX100 */
3165 u8 rate_100 = ieeectl->tx_rate;
3166 txdesc->u.r1.rate = rate_100;
3167 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3168 if (clt->pbcc511) {
3169 if (n == RATE100_5 || n == RATE100_11)
3170 n |= RATE100_PBCC511;
3173 if (clt->shortpre && (clt->cur != RATE111_1))
3174 SET_BIT(Ctl_8, DESC_CTL_SHORT_PREAMBLE); /* set Short Preamble */
3175 #endif
3176 /* set autodma and reclaim and 1st mpdu */
3177 SET_BIT(Ctl_8,
3178 DESC_CTL_AUTODMA | DESC_CTL_RECLAIM |
3179 DESC_CTL_FIRSTFRAG);
3180 #if ACX_FRAGMENTATION
3181 /* SET_BIT(Ctl2_8, DESC_CTL2_MORE_FRAG); cannot set it unconditionally, needs to be set for all non-last fragments */
3182 #endif
3183 hostdesc1->length = cpu_to_le16(wlhdr_len);
3185 /* don't need to clean ack/rts statistics here, already
3186 * done on descr cleanup */
3188 /* clears HOSTOWN and ACXDONE bits, thus telling that the descriptors
3189 * are now owned by the acx100; do this as LAST operation */
3190 CLEAR_BIT(Ctl_8, DESC_CTL_ACXDONE_HOSTOWN);
3191 /* flush writes before we release hostdesc to the adapter here */
3192 wmb();
3193 CLEAR_BIT(hostdesc1->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3194 CLEAR_BIT(hostdesc2->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3196 /* write back modified flags */
3197 CLEAR_BIT(Ctl2_8, DESC_CTL2_WEP);
3198 txdesc->Ctl2_8 = Ctl2_8;
3199 txdesc->Ctl_8 = Ctl_8;
3200 /* unused: txdesc->tx_time = cpu_to_le32(jiffies); */
3202 /* flush writes before we tell the adapter that it's its turn now */
3203 mmiowb();
3204 write_reg16(adev, IO_ACX_INT_TRIG, INT_TRIG_TXPRC);
3205 write_flush(adev);
3206 /* log the packet content AFTER sending it,
3207 * in order to not delay sending any further than absolutely needed
3208 * Do separate logs for acx100/111 to have human-readable rates */
3209 memcpy(&(hostdesc1->txstatus.control),ieeectl,sizeof(struct ieee80211_tx_control));
3210 hostdesc1->skb = skb;
3211 end:
3212 FN_EXIT0;
3216 /***********************************************************************
3217 ** acxpci_l_clean_txdesc
3219 ** This function resets the txdescs' status when the ACX100
3220 ** signals the TX done IRQ (txdescs have been processed), starting with
3221 ** the pool index of the descriptor which we would use next,
3222 ** in order to make sure that we can be as fast as possible
3223 ** in filling new txdescs.
3224 ** Everytime we get called we know where the next packet to be cleaned is.
3227 #if !ACX_DEBUG
3228 static inline void log_txbuffer(const acx_device_t * adev)
3231 #else
3232 static void log_txbuffer(acx_device_t * adev)
3234 txdesc_t *txdesc;
3235 int i;
3237 /* no FN_ENTER here, we don't want that */
3238 /* no locks here, since it's entirely non-critical code */
3239 txdesc = adev->txdesc_start;
3240 if (unlikely(!txdesc))
3241 return;
3242 printk("tx: desc->Ctl8's:");
3243 for (i = 0; i < TX_CNT; i++) {
3244 printk(" %02X", txdesc->Ctl_8);
3245 txdesc = advance_txdesc(adev, txdesc, 1);
3247 printk("\n");
3249 #endif
3252 static void handle_tx_error(acx_device_t * adev, u8 error, unsigned int finger,
3253 struct ieee80211_tx_status *status)
3255 const char *err = "unknown error";
3257 /* hmm, should we handle this as a mask
3258 * of *several* bits?
3259 * For now I think only caring about
3260 * individual bits is ok... */
3261 switch (error) {
3262 case 0x01:
3263 err = "no Tx due to error in other fragment";
3264 /* adev->wstats.discard.fragment++; */
3265 break;
3266 case 0x02:
3267 err = "Tx aborted";
3268 adev->stats.tx_aborted_errors++;
3269 break;
3270 case 0x04:
3271 err = "Tx desc wrong parameters";
3272 /* adev->wstats.discard.misc++; */
3273 break;
3274 case 0x08:
3275 err = "WEP key not found";
3276 /* adev->wstats.discard.misc++; */
3277 break;
3278 case 0x10:
3279 err = "MSDU lifetime timeout? - try changing "
3280 "'iwconfig retry lifetime XXX'";
3281 /* adev->wstats.discard.misc++; */
3282 break;
3283 case 0x20:
3284 err = "excessive Tx retries due to either distance "
3285 "too high or unable to Tx or Tx frame error - "
3286 "try changing 'iwconfig txpower XXX' or "
3287 "'sens'itivity or 'retry'";
3288 /* adev->wstats.discard.retries++; */
3289 /* Tx error 0x20 also seems to occur on
3290 * overheating, so I'm not sure whether we
3291 * actually want to do aggressive radio recalibration,
3292 * since people maybe won't notice then that their hardware
3293 * is slowly getting cooked...
3294 * Or is it still a safe long distance from utter
3295 * radio non-functionality despite many radio recalibs
3296 * to final destructive overheating of the hardware?
3297 * In this case we really should do recalib here...
3298 * I guess the only way to find out is to do a
3299 * potentially fatal self-experiment :-\
3300 * Or maybe only recalib in case we're using Tx
3301 * rate auto (on errors switching to lower speed
3302 * --> less heat?) or 802.11 power save mode?
3304 * ok, just do it. */
3305 if (++adev->retry_errors_msg_ratelimit % 4 == 0) {
3306 if (adev->retry_errors_msg_ratelimit <= 20) {
3307 printk("%s: several excessive Tx "
3308 "retry errors occurred, attempting "
3309 "to recalibrate radio. Radio "
3310 "drift might be caused by increasing "
3311 "card temperature, please check the card "
3312 "before it's too late!\n",
3313 wiphy_name(adev->ieee->wiphy));
3314 if (adev->retry_errors_msg_ratelimit == 20)
3315 printk("disabling above message\n");
3318 acx_schedule_task(adev,
3319 ACX_AFTER_IRQ_CMD_RADIO_RECALIB);
3321 status->excessive_retries++;
3322 break;
3323 case 0x40:
3324 err = "Tx buffer overflow";
3325 adev->stats.tx_fifo_errors++;
3326 break;
3327 case 0x80:
3328 /* possibly ACPI C-state powersaving related!!!
3329 * (DMA timeout due to excessively high wakeup
3330 * latency after C-state activation!?)
3331 * Disable C-State powersaving and try again,
3332 * then PLEASE REPORT, I'm VERY interested in
3333 * whether my theory is correct that this is
3334 * actually the problem here.
3335 * In that case, use new Linux idle wakeup latency
3336 * requirements kernel API to prevent this issue. */
3337 err = "DMA error";
3338 /* adev->wstats.discard.misc++; */
3339 break;
3341 adev->stats.tx_errors++;
3342 if (adev->stats.tx_errors <= 20)
3343 printk("%s: tx error 0x%02X, buf %02u! (%s)\n",
3344 wiphy_name(adev->ieee->wiphy), error, finger, err);
3345 else
3346 printk("%s: tx error 0x%02X, buf %02u!\n",
3347 wiphy_name(adev->ieee->wiphy), error, finger);
3351 unsigned int acxpci_l_clean_txdesc(acx_device_t * adev)
3353 txdesc_t *txdesc;
3354 txhostdesc_t *hostdesc;
3355 unsigned finger;
3356 int num_cleaned;
3357 u16 r111;
3358 u8 error, ack_failures, rts_failures, rts_ok, r100;
3360 FN_ENTER;
3362 if (unlikely(acx_debug & L_DEBUG))
3363 log_txbuffer(adev);
3365 log(L_BUFT, "tx: cleaning up bufs from %u\n", adev->tx_tail);
3367 /* We know first descr which is not free yet. We advance it as far
3368 ** as we see correct bits set in following descs (if next desc
3369 ** is NOT free, we shouldn't advance at all). We know that in
3370 ** front of tx_tail may be "holes" with isolated free descs.
3371 ** We will catch up when all intermediate descs will be freed also */
3373 finger = adev->tx_tail;
3374 num_cleaned = 0;
3375 while (likely(finger != adev->tx_head)) {
3376 txdesc = get_txdesc(adev, finger);
3378 /* If we allocated txdesc on tx path but then decided
3379 ** to NOT use it, then it will be left as a free "bubble"
3380 ** in the "allocated for tx" part of the ring.
3381 ** We may meet it on the next ring pass here. */
3383 /* stop if not marked as "tx finished" and "host owned" */
3384 if ((txdesc->Ctl_8 & DESC_CTL_ACXDONE_HOSTOWN)
3385 != DESC_CTL_ACXDONE_HOSTOWN) {
3386 if (unlikely(!num_cleaned)) { /* maybe remove completely */
3387 log(L_BUFT, "clean_txdesc: tail isn't free. "
3388 "tail:%d head:%d\n",
3389 adev->tx_tail, adev->tx_head);
3391 break;
3394 /* remember desc values... */
3395 error = txdesc->error;
3396 ack_failures = txdesc->ack_failures;
3397 rts_failures = txdesc->rts_failures;
3398 rts_ok = txdesc->rts_ok;
3399 r100 = txdesc->u.r1.rate;
3400 r111 = le16_to_cpu(txdesc->u.r2.rate111);
3402 /* need to check for certain error conditions before we
3403 * clean the descriptor: we still need valid descr data here */
3404 hostdesc = get_txhostdesc(adev, txdesc);
3406 hostdesc->txstatus.flags |= IEEE80211_TX_STATUS_ACK;
3407 if (unlikely(0x30 & error)) {
3408 /* only send IWEVTXDROP in case of retry or lifetime exceeded;
3409 * all other errors mean we screwed up locally */
3410 /* union iwreq_data wrqu;
3411 struct ieee80211_hdr_3addr *hdr;
3412 hdr = (struct ieee80211_hdr_3addr *) hostdesc->data;
3413 MAC_COPY(wrqu.addr.sa_data, hdr->addr1);
3415 hostdesc->txstatus.flags &= ~IEEE80211_TX_STATUS_ACK;
3418 /* ...and free the desc */
3419 txdesc->error = 0;
3420 txdesc->ack_failures = 0;
3421 txdesc->rts_failures = 0;
3422 txdesc->rts_ok = 0;
3423 /* signal host owning it LAST, since ACX already knows that this
3424 ** descriptor is finished since it set Ctl_8 accordingly. */
3425 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3427 adev->tx_free++;
3428 num_cleaned++;
3430 if ((adev->tx_free >= TX_START_QUEUE)
3431 /* && (adev->status == ACX_STATUS_4_ASSOCIATED) */
3432 /*&& (acx_queue_stopped(adev->ieee))*/
3434 log(L_BUF, "tx: wake queue (avail. Tx desc %u)\n",
3435 adev->tx_free);
3436 acx_wake_queue(adev->ieee, NULL);
3439 /* do error checking, rate handling and logging
3440 * AFTER having done the work, it's faster */
3442 /* Rate handling is done in mac80211 */
3443 /* if (adev->rate_auto) {
3444 struct client *clt = get_txc(adev, txdesc);
3445 if (clt) {
3446 u16 cur = get_txr(adev, txdesc);
3447 if (clt->rate_cur == cur) {
3448 acx_l_handle_txrate_auto(adev, clt, cur,*/ /* intended rate */
3449 /*r100, r111,*/ /* actually used rate */
3450 /*(error & 0x30),*/ /* was there an error? */
3451 /* TX_CNT +
3452 TX_CLEAN_BACKLOG
3454 adev->tx_free);
3459 if (unlikely(error))
3460 handle_tx_error(adev, error, finger, &hostdesc->txstatus);
3462 if (IS_ACX111(adev))
3463 log(L_BUFT,
3464 "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u r111=%04X tx_free=%u\n",
3465 finger, ack_failures, rts_failures, rts_ok, r111, adev->tx_free);
3466 else
3467 log(L_BUFT,
3468 "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u rate=%u\n",
3469 finger, ack_failures, rts_failures, rts_ok, r100);
3471 /* And finally report upstream */
3472 if (hostdesc)
3474 hostdesc->txstatus.excessive_retries = rts_failures ;
3475 hostdesc->txstatus.retry_count = ack_failures;
3476 ieee80211_tx_status(adev->ieee,hostdesc->skb,&hostdesc->txstatus);
3477 memset(&hostdesc->txstatus, 0, sizeof(struct ieee80211_tx_status));
3479 /* update pointer for descr to be cleaned next */
3480 finger = (finger + 1) % TX_CNT;
3482 /* remember last position */
3483 adev->tx_tail = finger;
3484 /* end: */
3485 FN_EXIT1(num_cleaned);
3486 return num_cleaned;
3489 /* clean *all* Tx descriptors, and regardless of their previous state.
3490 * Used for brute-force reset handling. */
3491 void acxpci_l_clean_txdesc_emergency(acx_device_t * adev)
3493 txdesc_t *txdesc;
3494 int i;
3496 FN_ENTER;
3498 for (i = 0; i < TX_CNT; i++) {
3499 txdesc = get_txdesc(adev, i);
3501 /* free it */
3502 txdesc->ack_failures = 0;
3503 txdesc->rts_failures = 0;
3504 txdesc->rts_ok = 0;
3505 txdesc->error = 0;
3506 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3509 adev->tx_free = TX_CNT;
3511 FN_EXIT0;
3515 /***********************************************************************
3516 ** acxpci_s_create_tx_host_desc_queue
3519 static void *allocate(acx_device_t * adev, size_t size, dma_addr_t * phy,
3520 const char *msg)
3522 void *ptr;
3524 ptr = dma_alloc_coherent(adev->bus_dev, size, phy, GFP_KERNEL);
3526 if (ptr) {
3527 log(L_DEBUG, "%s sz=%d adr=0x%p phy=0x%08llx\n",
3528 msg, (int)size, ptr, (unsigned long long)*phy);
3529 memset(ptr, 0, size);
3530 return ptr;
3532 printk(KERN_ERR "acx: %s allocation FAILED (%d bytes)\n",
3533 msg, (int)size);
3534 return NULL;
3538 static int acxpci_s_create_tx_host_desc_queue(acx_device_t * adev)
3540 txhostdesc_t *hostdesc;
3541 u8 *txbuf;
3542 dma_addr_t hostdesc_phy;
3543 dma_addr_t txbuf_phy;
3544 int i;
3546 FN_ENTER;
3548 /* allocate TX buffer */
3549 adev->txbuf_area_size = TX_CNT * /*WLAN_A4FR_MAXLEN_WEP_FCS*/ (30 + 2312 + 4);
3550 adev->txbuf_start = allocate(adev, adev->txbuf_area_size,
3551 &adev->txbuf_startphy, "txbuf_start");
3552 if (!adev->txbuf_start)
3553 goto fail;
3555 /* allocate the TX host descriptor queue pool */
3556 adev->txhostdesc_area_size = TX_CNT * 2 * sizeof(*hostdesc);
3557 adev->txhostdesc_start = allocate(adev, adev->txhostdesc_area_size,
3558 &adev->txhostdesc_startphy,
3559 "txhostdesc_start");
3560 if (!adev->txhostdesc_start)
3561 goto fail;
3562 /* check for proper alignment of TX host descriptor pool */
3563 if ((long)adev->txhostdesc_start & 3) {
3564 printk
3565 ("acx: driver bug: dma alloc returns unaligned address\n");
3566 goto fail;
3569 hostdesc = adev->txhostdesc_start;
3570 hostdesc_phy = adev->txhostdesc_startphy;
3571 txbuf = adev->txbuf_start;
3572 txbuf_phy = adev->txbuf_startphy;
3574 #if 0
3575 /* Each tx buffer is accessed by hardware via
3576 ** txdesc -> txhostdesc(s) -> txbuffer(s).
3577 ** We use only one txhostdesc per txdesc, but it looks like
3578 ** acx111 is buggy: it accesses second txhostdesc
3579 ** (via hostdesc.desc_phy_next field) even if
3580 ** txdesc->length == hostdesc->length and thus
3581 ** entire packet was placed into first txhostdesc.
3582 ** Due to this bug acx111 hangs unless second txhostdesc
3583 ** has le16_to_cpu(hostdesc.length) = 3 (or larger)
3584 ** Storing NULL into hostdesc.desc_phy_next
3585 ** doesn't seem to help.
3587 ** Update: although it worked on Xterasys XN-2522g
3588 ** with len=3 trick, WG311v2 is even more bogus, doesn't work.
3589 ** Keeping this code (#ifdef'ed out) for documentational purposes.
3591 for (i = 0; i < TX_CNT * 2; i++) {
3592 hostdesc_phy += sizeof(*hostdesc);
3593 if (!(i & 1)) {
3594 hostdesc->data_phy = cpu2acx(txbuf_phy);
3595 /* hostdesc->data_offset = ... */
3596 /* hostdesc->reserved = ... */
3597 hostdesc->Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
3598 /* hostdesc->length = ... */
3599 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3600 hostdesc->pNext = ptr2acx(NULL);
3601 /* hostdesc->Status = ... */
3602 /* below: non-hardware fields */
3603 hostdesc->data = txbuf;
3605 txbuf += WLAN_A4FR_MAXLEN_WEP_FCS;
3606 txbuf_phy += WLAN_A4FR_MAXLEN_WEP_FCS;
3607 } else {
3608 /* hostdesc->data_phy = ... */
3609 /* hostdesc->data_offset = ... */
3610 /* hostdesc->reserved = ... */
3611 /* hostdesc->Ctl_16 = ... */
3612 hostdesc->length = cpu_to_le16(3); /* bug workaround */
3613 /* hostdesc->desc_phy_next = ... */
3614 /* hostdesc->pNext = ... */
3615 /* hostdesc->Status = ... */
3616 /* below: non-hardware fields */
3617 /* hostdesc->data = ... */
3619 hostdesc++;
3621 #endif
3622 /* We initialize two hostdescs so that they point to adjacent
3623 ** memory areas. Thus txbuf is really just a contiguous memory area */
3624 for (i = 0; i < TX_CNT * 2; i++) {
3625 hostdesc_phy += sizeof(*hostdesc);
3627 hostdesc->data_phy = cpu2acx(txbuf_phy);
3628 /* done by memset(0): hostdesc->data_offset = 0; */
3629 /* hostdesc->reserved = ... */
3630 hostdesc->Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
3631 /* hostdesc->length = ... */
3632 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3633 /* done by memset(0): hostdesc->pNext = ptr2acx(NULL); */
3634 /* hostdesc->Status = ... */
3635 /* ->data is a non-hardware field: */
3636 hostdesc->data = txbuf;
3638 if (!(i & 1)) {
3639 txbuf += 24 /*WLAN_HDR_A3_LEN*/;
3640 txbuf_phy += 24 /*WLAN_HDR_A3_LEN*/;
3641 } else {
3642 txbuf += 30 + 2132 + 4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3643 txbuf_phy += 30 + 2132 +4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3645 hostdesc++;
3647 hostdesc--;
3648 hostdesc->desc_phy_next = cpu2acx(adev->txhostdesc_startphy);
3650 FN_EXIT1(OK);
3651 return OK;
3652 fail:
3653 printk("acx: create_tx_host_desc_queue FAILED\n");
3654 /* dealloc will be done by free function on error case */
3655 FN_EXIT1(NOT_OK);
3656 return NOT_OK;
3660 /***************************************************************
3661 ** acxpci_s_create_rx_host_desc_queue
3663 /* the whole size of a data buffer (header plus data body)
3664 * plus 32 bytes safety offset at the end */
3665 #define RX_BUFFER_SIZE (sizeof(rxbuffer_t) + 32)
3667 static int acxpci_s_create_rx_host_desc_queue(acx_device_t * adev)
3669 rxhostdesc_t *hostdesc;
3670 rxbuffer_t *rxbuf;
3671 dma_addr_t hostdesc_phy;
3672 dma_addr_t rxbuf_phy;
3673 int i;
3675 FN_ENTER;
3677 /* allocate the RX host descriptor queue pool */
3678 adev->rxhostdesc_area_size = RX_CNT * sizeof(*hostdesc);
3679 adev->rxhostdesc_start = allocate(adev, adev->rxhostdesc_area_size,
3680 &adev->rxhostdesc_startphy,
3681 "rxhostdesc_start");
3682 if (!adev->rxhostdesc_start)
3683 goto fail;
3684 /* check for proper alignment of RX host descriptor pool */
3685 if ((long)adev->rxhostdesc_start & 3) {
3686 printk
3687 ("acx: driver bug: dma alloc returns unaligned address\n");
3688 goto fail;
3691 /* allocate Rx buffer pool which will be used by the acx
3692 * to store the whole content of the received frames in it */
3693 adev->rxbuf_area_size = RX_CNT * RX_BUFFER_SIZE;
3694 adev->rxbuf_start = allocate(adev, adev->rxbuf_area_size,
3695 &adev->rxbuf_startphy, "rxbuf_start");
3696 if (!adev->rxbuf_start)
3697 goto fail;
3699 rxbuf = adev->rxbuf_start;
3700 rxbuf_phy = adev->rxbuf_startphy;
3701 hostdesc = adev->rxhostdesc_start;
3702 hostdesc_phy = adev->rxhostdesc_startphy;
3704 /* don't make any popular C programming pointer arithmetic mistakes
3705 * here, otherwise I'll kill you...
3706 * (and don't dare asking me why I'm warning you about that...) */
3707 for (i = 0; i < RX_CNT; i++) {
3708 hostdesc->data = rxbuf;
3709 hostdesc->data_phy = cpu2acx(rxbuf_phy);
3710 hostdesc->length = cpu_to_le16(RX_BUFFER_SIZE);
3711 CLEAR_BIT(hostdesc->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3712 rxbuf++;
3713 rxbuf_phy += sizeof(*rxbuf);
3714 hostdesc_phy += sizeof(*hostdesc);
3715 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3716 hostdesc++;
3718 hostdesc--;
3719 hostdesc->desc_phy_next = cpu2acx(adev->rxhostdesc_startphy);
3720 FN_EXIT1(OK);
3721 return OK;
3722 fail:
3723 printk("acx: create_rx_host_desc_queue FAILED\n");
3724 /* dealloc will be done by free function on error case */
3725 FN_EXIT1(NOT_OK);
3726 return NOT_OK;
3730 /***************************************************************
3731 ** acxpci_s_create_hostdesc_queues
3733 int acxpci_s_create_hostdesc_queues(acx_device_t * adev)
3735 int result;
3736 result = acxpci_s_create_tx_host_desc_queue(adev);
3737 if (OK != result)
3738 return result;
3739 result = acxpci_s_create_rx_host_desc_queue(adev);
3740 return result;
3744 /***************************************************************
3745 ** acxpci_create_tx_desc_queue
3747 static void acxpci_create_tx_desc_queue(acx_device_t * adev, u32 tx_queue_start)
3749 txdesc_t *txdesc;
3750 txhostdesc_t *hostdesc;
3751 dma_addr_t hostmemptr;
3752 u32 mem_offs;
3753 int i;
3755 FN_ENTER;
3757 if (IS_ACX100(adev))
3758 adev->txdesc_size = sizeof(*txdesc);
3759 else
3760 /* the acx111 txdesc is 4 bytes larger */
3761 adev->txdesc_size = sizeof(*txdesc) + 4;
3763 adev->txdesc_start = (txdesc_t *) (adev->iobase2 + tx_queue_start);
3765 log(L_DEBUG, "adev->iobase2=%p\n"
3766 "tx_queue_start=%08X\n"
3767 "adev->txdesc_start=%p\n",
3768 adev->iobase2, tx_queue_start, adev->txdesc_start);
3770 adev->tx_free = TX_CNT;
3771 /* done by memset: adev->tx_head = 0; */
3772 /* done by memset: adev->tx_tail = 0; */
3773 txdesc = adev->txdesc_start;
3774 mem_offs = tx_queue_start;
3775 hostmemptr = adev->txhostdesc_startphy;
3776 hostdesc = adev->txhostdesc_start;
3778 if (IS_ACX111(adev)) {
3779 /* ACX111 has a preinitialized Tx buffer! */
3780 /* loop over whole send pool */
3781 /* FIXME: do we have to do the hostmemptr stuff here?? */
3782 for (i = 0; i < TX_CNT; i++) {
3783 txdesc->HostMemPtr = ptr2acx(hostmemptr);
3784 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3785 /* reserve two (hdr desc and payload desc) */
3786 hostdesc += 2;
3787 hostmemptr += 2 * sizeof(*hostdesc);
3788 txdesc = advance_txdesc(adev, txdesc, 1);
3790 } else {
3791 /* ACX100 Tx buffer needs to be initialized by us */
3792 /* clear whole send pool. sizeof is safe here (we are acx100) */
3793 memset(adev->txdesc_start, 0, TX_CNT * sizeof(*txdesc));
3795 /* loop over whole send pool */
3796 for (i = 0; i < TX_CNT; i++) {
3797 log(L_DEBUG, "configure card tx descriptor: 0x%p, "
3798 "size: 0x%X\n", txdesc, adev->txdesc_size);
3800 /* pointer to hostdesc memory */
3801 txdesc->HostMemPtr = ptr2acx(hostmemptr);
3802 /* initialise ctl */
3803 txdesc->Ctl_8 = (DESC_CTL_HOSTOWN | DESC_CTL_RECLAIM
3804 | DESC_CTL_AUTODMA |
3805 DESC_CTL_FIRSTFRAG);
3806 /* done by memset(0): txdesc->Ctl2_8 = 0; */
3807 /* point to next txdesc */
3808 txdesc->pNextDesc =
3809 cpu2acx(mem_offs + adev->txdesc_size);
3810 /* reserve two (hdr desc and payload desc) */
3811 hostdesc += 2;
3812 hostmemptr += 2 * sizeof(*hostdesc);
3813 /* go to the next one */
3814 mem_offs += adev->txdesc_size;
3815 /* ++ is safe here (we are acx100) */
3816 txdesc++;
3818 /* go back to the last one */
3819 txdesc--;
3820 /* and point to the first making it a ring buffer */
3821 txdesc->pNextDesc = cpu2acx(tx_queue_start);
3823 FN_EXIT0;
3827 /***************************************************************
3828 ** acxpci_create_rx_desc_queue
3830 static void acxpci_create_rx_desc_queue(acx_device_t * adev, u32 rx_queue_start)
3832 rxdesc_t *rxdesc;
3833 u32 mem_offs;
3834 int i;
3836 FN_ENTER;
3838 /* done by memset: adev->rx_tail = 0; */
3840 /* ACX111 doesn't need any further config: preconfigures itself.
3841 * Simply print ring buffer for debugging */
3842 if (IS_ACX111(adev)) {
3843 /* rxdesc_start already set here */
3845 adev->rxdesc_start =
3846 (rxdesc_t *) ((u8 *) adev->iobase2 + rx_queue_start);
3848 rxdesc = adev->rxdesc_start;
3849 for (i = 0; i < RX_CNT; i++) {
3850 log(L_DEBUG, "rx descriptor %d @ 0x%p\n", i, rxdesc);
3851 rxdesc = adev->rxdesc_start = (rxdesc_t *)
3852 (adev->iobase2 + acx2cpu(rxdesc->pNextDesc));
3854 } else {
3855 /* we didn't pre-calculate rxdesc_start in case of ACX100 */
3856 /* rxdesc_start should be right AFTER Tx pool */
3857 adev->rxdesc_start = (rxdesc_t *)
3858 ((u8 *) adev->txdesc_start + (TX_CNT * sizeof(txdesc_t)));
3859 /* NB: sizeof(txdesc_t) above is valid because we know
3860 ** we are in if (acx100) block. Beware of cut-n-pasting elsewhere!
3861 ** acx111's txdesc is larger! */
3863 memset(adev->rxdesc_start, 0, RX_CNT * sizeof(*rxdesc));
3865 /* loop over whole receive pool */
3866 rxdesc = adev->rxdesc_start;
3867 mem_offs = rx_queue_start;
3868 for (i = 0; i < RX_CNT; i++) {
3869 log(L_DEBUG, "rx descriptor @ 0x%p\n", rxdesc);
3870 rxdesc->Ctl_8 = DESC_CTL_RECLAIM | DESC_CTL_AUTODMA;
3871 /* point to next rxdesc */
3872 rxdesc->pNextDesc = cpu2acx(mem_offs + sizeof(*rxdesc));
3873 /* go to the next one */
3874 mem_offs += sizeof(*rxdesc);
3875 rxdesc++;
3877 /* go to the last one */
3878 rxdesc--;
3880 /* and point to the first making it a ring buffer */
3881 rxdesc->pNextDesc = cpu2acx(rx_queue_start);
3883 FN_EXIT0;
3887 /***************************************************************
3888 ** acxpci_create_desc_queues
3890 void
3891 acxpci_create_desc_queues(acx_device_t * adev, u32 tx_queue_start,
3892 u32 rx_queue_start)
3894 acxpci_create_tx_desc_queue(adev, tx_queue_start);
3895 acxpci_create_rx_desc_queue(adev, rx_queue_start);
3899 /***************************************************************
3900 ** acxpci_s_proc_diag_output
3902 char *acxpci_s_proc_diag_output(char *p, acx_device_t * adev)
3904 const char *rtl, *thd, *ttl;
3905 rxhostdesc_t *rxhostdesc;
3906 txdesc_t *txdesc;
3907 int i;
3909 FN_ENTER;
3911 p += sprintf(p, "** Rx buf **\n");
3912 rxhostdesc = adev->rxhostdesc_start;
3913 if (rxhostdesc)
3914 for (i = 0; i < RX_CNT; i++) {
3915 rtl = (i == adev->rx_tail) ? " [tail]" : "";
3916 if ((rxhostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
3917 && (rxhostdesc->
3918 Status & cpu_to_le32(DESC_STATUS_FULL)))
3919 p += sprintf(p, "%02u FULL%s\n", i, rtl);
3920 else
3921 p += sprintf(p, "%02u empty%s\n", i, rtl);
3922 rxhostdesc++;
3924 /* p += sprintf(p, "** Tx buf (free %d, Linux netqueue %s) **\n",
3925 adev->tx_free,
3926 acx_queue_stopped(adev->ieee) ? "STOPPED" : "running");*/
3927 txdesc = adev->txdesc_start;
3928 if (txdesc)
3929 for (i = 0; i < TX_CNT; i++) {
3930 thd = (i == adev->tx_head) ? " [head]" : "";
3931 ttl = (i == adev->tx_tail) ? " [tail]" : "";
3932 if (txdesc->Ctl_8 & DESC_CTL_ACXDONE)
3933 p += sprintf(p, "%02u free (%02X)%s%s\n", i,
3934 txdesc->Ctl_8, thd, ttl);
3935 else
3936 p += sprintf(p, "%02u tx (%02X)%s%s\n", i,
3937 txdesc->Ctl_8, thd, ttl);
3938 txdesc = advance_txdesc(adev, txdesc, 1);
3940 p += sprintf(p,
3941 "\n"
3942 "** PCI data **\n"
3943 "txbuf_start %p, txbuf_area_size %u, txbuf_startphy %08llx\n"
3944 "txdesc_size %u, txdesc_start %p\n"
3945 "txhostdesc_start %p, txhostdesc_area_size %u, txhostdesc_startphy %08llx\n"
3946 "rxdesc_start %p\n"
3947 "rxhostdesc_start %p, rxhostdesc_area_size %u, rxhostdesc_startphy %08llx\n"
3948 "rxbuf_start %p, rxbuf_area_size %u, rxbuf_startphy %08llx\n",
3949 adev->txbuf_start, adev->txbuf_area_size,
3950 (unsigned long long)adev->txbuf_startphy,
3951 adev->txdesc_size, adev->txdesc_start,
3952 adev->txhostdesc_start, adev->txhostdesc_area_size,
3953 (unsigned long long)adev->txhostdesc_startphy,
3954 adev->rxdesc_start,
3955 adev->rxhostdesc_start, adev->rxhostdesc_area_size,
3956 (unsigned long long)adev->rxhostdesc_startphy,
3957 adev->rxbuf_start, adev->rxbuf_area_size,
3958 (unsigned long long)adev->rxbuf_startphy);
3960 FN_EXIT0;
3961 return p;
3965 /***********************************************************************
3967 int acxpci_proc_eeprom_output(char *buf, acx_device_t * adev)
3969 char *p = buf;
3970 int i;
3972 FN_ENTER;
3974 for (i = 0; i < 0x400; i++) {
3975 acxpci_read_eeprom_byte(adev, i, p++);
3978 FN_EXIT1(p - buf);
3979 return p - buf;
3983 /***********************************************************************
3984 ** Obvious
3986 void acxpci_set_interrupt_mask(acx_device_t * adev)
3988 if (IS_ACX111(adev)) {
3989 adev->irq_mask = (u16) ~ (0
3990 /* | HOST_INT_RX_DATA */
3991 | HOST_INT_TX_COMPLETE
3992 /* | HOST_INT_TX_XFER */
3993 | HOST_INT_RX_COMPLETE
3994 /* | HOST_INT_DTIM */
3995 /* | HOST_INT_BEACON */
3996 /* | HOST_INT_TIMER */
3997 /* | HOST_INT_KEY_NOT_FOUND */
3998 | HOST_INT_IV_ICV_FAILURE
3999 | HOST_INT_CMD_COMPLETE
4000 | HOST_INT_INFO
4001 /* | HOST_INT_OVERFLOW */
4002 /* | HOST_INT_PROCESS_ERROR */
4003 | HOST_INT_SCAN_COMPLETE
4004 | HOST_INT_FCS_THRESHOLD
4005 /* | HOST_INT_UNKNOWN */
4007 /* Or else acx100 won't signal cmd completion, right? */
4008 adev->irq_mask_off = (u16) ~ (HOST_INT_CMD_COMPLETE); /* 0xfdff */
4009 } else {
4010 adev->irq_mask = (u16) ~ (0
4011 /* | HOST_INT_RX_DATA */
4012 | HOST_INT_TX_COMPLETE
4013 /* | HOST_INT_TX_XFER */
4014 | HOST_INT_RX_COMPLETE
4015 /* | HOST_INT_DTIM */
4016 /* | HOST_INT_BEACON */
4017 /* | HOST_INT_TIMER */
4018 /* | HOST_INT_KEY_NOT_FOUND */
4019 /* | HOST_INT_IV_ICV_FAILURE */
4020 | HOST_INT_CMD_COMPLETE
4021 | HOST_INT_INFO
4022 /* | HOST_INT_OVERFLOW */
4023 /* | HOST_INT_PROCESS_ERROR */
4024 | HOST_INT_SCAN_COMPLETE
4025 /* | HOST_INT_FCS_THRESHOLD */
4026 /* | HOST_INT_UNKNOWN */
4028 adev->irq_mask_off = (u16) ~ (HOST_INT_UNKNOWN); /* 0x7fff */
4033 /***********************************************************************
4035 int acx100pci_s_set_tx_level(acx_device_t * adev, u8 level_dbm)
4037 /* since it can be assumed that at least the Maxim radio has a
4038 * maximum power output of 20dBm and since it also can be
4039 * assumed that these values drive the DAC responsible for
4040 * setting the linear Tx level, I'd guess that these values
4041 * should be the corresponding linear values for a dBm value,
4042 * in other words: calculate the values from that formula:
4043 * Y [dBm] = 10 * log (X [mW])
4044 * then scale the 0..63 value range onto the 1..100mW range (0..20 dBm)
4045 * and you're done...
4046 * Hopefully that's ok, but you never know if we're actually
4047 * right... (especially since Windows XP doesn't seem to show
4048 * actual Tx dBm values :-P) */
4050 /* NOTE: on Maxim, value 30 IS 30mW, and value 10 IS 10mW - so the
4051 * values are EXACTLY mW!!! Not sure about RFMD and others,
4052 * though... */
4053 static const u8 dbm2val_maxim[21] = {
4054 63, 63, 63, 62,
4055 61, 61, 60, 60,
4056 59, 58, 57, 55,
4057 53, 50, 47, 43,
4058 38, 31, 23, 13,
4061 static const u8 dbm2val_rfmd[21] = {
4062 0, 0, 0, 1,
4063 2, 2, 3, 3,
4064 4, 5, 6, 8,
4065 10, 13, 16, 20,
4066 25, 32, 41, 50,
4069 const u8 *table;
4071 switch (adev->radio_type) {
4072 case RADIO_MAXIM_0D:
4073 table = &dbm2val_maxim[0];
4074 break;
4075 case RADIO_RFMD_11:
4076 case RADIO_RALINK_15:
4077 table = &dbm2val_rfmd[0];
4078 break;
4079 default:
4080 printk("%s: unknown/unsupported radio type, "
4081 "cannot modify tx power level yet!\n", wiphy_name(adev->ieee->wiphy));
4082 return NOT_OK;
4084 printk("%s: changing radio power level to %u dBm (%u)\n",
4085 wiphy_name(adev->ieee->wiphy), level_dbm, table[level_dbm]);
4086 acxpci_s_write_phy_reg(adev, 0x11, table[level_dbm]);
4087 return OK;
4090 #ifdef CONFIG_VLYNQ
4091 struct vlynq_reg_config {
4092 u32 offset;
4093 u32 value;
4096 struct vlynq_known {
4097 u32 chip_id;
4098 char name[32];
4099 struct vlynq_mapping rx_mapping[4];
4100 int irq;
4101 int irq_type;
4102 int num_regs;
4103 struct vlynq_reg_config regs[10];
4106 #define CHIP_TNETW1130 0x00000009
4107 #define CHIP_TNETW1350 0x00000029
4109 static struct vlynq_known known_devices[] = {
4111 .chip_id = CHIP_TNETW1130, .name = "TI TNETW1130",
4112 .rx_mapping = {
4113 { .size = 0x22000, .offset = 0xf0000000 },
4114 { .size = 0x40000, .offset = 0xc0000000 },
4115 { .size = 0x0, .offset = 0x0 },
4116 { .size = 0x0, .offset = 0x0 },
4118 .irq = 0,
4119 .irq_type = IRQ_TYPE_EDGE_RISING,
4120 .num_regs = 5,
4121 .regs = {
4123 .offset = 0x790,
4124 .value = (0xd0000000 - PHYS_OFFSET)
4127 .offset = 0x794,
4128 .value = (0xd0000000 - PHYS_OFFSET)
4130 { .offset = 0x740, .value = 0 },
4131 { .offset = 0x744, .value = 0x00010000 },
4132 { .offset = 0x764, .value = 0x00010000 },
4136 .chip_id = CHIP_TNETW1350, .name = "TI TNETW1350",
4137 .rx_mapping = {
4138 { .size = 0x100000, .offset = 0x00300000 },
4139 { .size = 0x80000, .offset = 0x00000000 },
4140 { .size = 0x0, .offset = 0x0 },
4141 { .size = 0x0, .offset = 0x0 },
4143 .irq = 0,
4144 .irq_type = IRQ_TYPE_EDGE_RISING,
4145 .num_regs = 5,
4146 .regs = {
4148 .offset = 0x790,
4149 .value = (0x60000000 - PHYS_OFFSET)
4152 .offset = 0x794,
4153 .value = (0x60000000 - PHYS_OFFSET)
4155 { .offset = 0x740, .value = 0 },
4156 { .offset = 0x744, .value = 0x00010000 },
4157 { .offset = 0x764, .value = 0x00010000 },
4162 static struct vlynq_device_id acx_vlynq_id[] = {
4163 { CHIP_TNETW1130, vlynq_div_auto, 0 },
4164 { CHIP_TNETW1350, vlynq_div_auto, 1 },
4165 { 0, 0, 0 },
4168 static __devinit int vlynq_probe(struct vlynq_device *vdev,
4169 struct vlynq_device_id *id)
4171 int result = -EIO, i;
4172 u32 addr;
4173 struct ieee80211_hw *ieee;
4174 acx_device_t *adev = NULL;
4175 acx111_ie_configoption_t co;
4176 struct vlynq_mapping mapping[4] = { { 0, }, };
4177 struct vlynq_known *match = NULL;
4179 FN_ENTER;
4180 result = vlynq_enable_device(vdev);
4181 if (result)
4182 return result;
4184 match = &known_devices[id->driver_data];
4186 if (!match) {
4187 result = -ENODEV;
4188 goto fail;
4191 mapping[0].offset = ARCH_PFN_OFFSET << PAGE_SHIFT;
4192 mapping[0].size = 0x02000000;
4193 vlynq_set_local_mapping(vdev, vdev->mem_start, mapping);
4194 vlynq_set_remote_mapping(vdev, 0, match->rx_mapping);
4196 set_irq_type(vlynq_virq_to_irq(vdev, match->irq), match->irq_type);
4198 addr = (u32)ioremap(vdev->mem_start, 0x1000);
4199 if (!addr) {
4200 printk(KERN_ERR "%s: failed to remap io memory\n",
4201 vdev->dev.bus_id);
4202 result = -ENXIO;
4203 goto fail;
4206 for (i = 0; i < match->num_regs; i++)
4207 iowrite32(match->regs[i].value,
4208 (u32 *)(addr + match->regs[i].offset));
4210 iounmap((void *)addr);
4212 ieee = ieee80211_alloc_hw(sizeof(struct acx_device), &acxpci_hw_ops);
4213 if (!ieee) {
4214 printk("acx: could not allocate ieee80211 structure %s\n",
4215 vdev->dev.bus_id);
4216 goto fail_alloc_netdev;
4218 ieee->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
4219 ieee->queues = 1;
4221 adev = ieee2adev(ieee);
4223 memset(adev, 0, sizeof(*adev));
4224 /** Set up our private interface **/
4225 spin_lock_init(&adev->lock); /* initial state: unlocked */
4226 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
4227 mutex_init(&adev->mutex);
4228 /* since nobody can see new netdev yet, we can as well
4229 ** just _presume_ that we're under sem (instead of actually taking it): */
4230 /* acx_sem_lock(adev); */
4231 adev->ieee = ieee;
4232 adev->vdev = vdev;
4233 adev->bus_dev = &vdev->dev;
4234 adev->dev_type = DEVTYPE_PCI;
4236 /** Finished with private interface **/
4238 vlynq_set_drvdata(vdev, ieee);
4239 if (!request_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start, "acx")) {
4240 printk("acx: cannot reserve VLYNQ memory region\n");
4241 goto fail_request_mem_region;
4243 adev->iobase = ioremap(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4244 if (!adev->iobase) {
4245 printk("acx: ioremap() FAILED\n");
4246 goto fail_ioremap;
4248 adev->iobase2 = adev->iobase + match->rx_mapping[0].size;
4249 adev->chip_type = CHIPTYPE_ACX111;
4250 adev->chip_name = match->name;
4251 adev->io = IO_ACX111;
4252 adev->irq = vlynq_virq_to_irq(vdev, match->irq);
4254 printk("acx: found %s-based wireless network card at %s, irq:%d, "
4255 "phymem:0x%x, mem:0x%p\n",
4256 match->name, vdev->dev.bus_id, adev->irq,
4257 vdev->mem_start, adev->iobase);
4258 log(L_ANY, "initial debug setting is 0x%04X\n", acx_debug);
4260 if (0 == adev->irq) {
4261 printk("acx: can't use IRQ 0\n");
4262 goto fail_irq;
4264 SET_IEEE80211_DEV(ieee, &vdev->dev);
4267 /* to find crashes due to weird driver access
4268 * to unconfigured interface (ifup) */
4269 adev->mgmt_timer.function = (void (*)(unsigned long))0x0000dead;
4272 /* ok, pci setup is finished, now start initializing the card */
4274 /* NB: read_reg() reads may return bogus data before reset_dev(),
4275 * since the firmware which directly controls large parts of the I/O
4276 * registers isn't initialized yet.
4277 * acx100 seems to be more affected than acx111 */
4278 if (OK != acxpci_s_reset_dev(adev))
4279 goto fail_reset;
4281 if (OK != acx_s_init_mac(adev))
4282 goto fail_init_mac;
4284 acx_s_interrogate(adev, &co, ACX111_IE_CONFIG_OPTIONS);
4285 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
4286 if (OK != acxpci_read_eeprom_byte(adev, 0x05, &adev->eeprom_version))
4287 goto fail_read_eeprom_version;
4289 acx_s_parse_configoption(adev, &co);
4290 acx_s_set_defaults(adev);
4291 acx_s_get_firmware_version(adev); /* needs to be after acx_s_init_mac() */
4292 acx_display_hardware_details(adev);
4294 /* Register the card, AFTER everything else has been set up,
4295 * since otherwise an ioctl could step on our feet due to
4296 * firmware operations happening in parallel or uninitialized data */
4299 acx_proc_register_entries(ieee);
4301 /* Now we have our device, so make sure the kernel doesn't try
4302 * to send packets even though we're not associated to a network yet */
4304 /* after register_netdev() userspace may start working with dev
4305 * (in particular, on other CPUs), we only need to up the sem */
4306 /* acx_sem_unlock(adev); */
4308 printk("acx " ACX_RELEASE ": net device %s, driver compiled "
4309 "against wireless extensions %d and Linux %s\n",
4310 wiphy_name(adev->ieee->wiphy), WIRELESS_EXT, UTS_RELEASE);
4312 MAC_COPY(adev->ieee->wiphy->perm_addr, adev->dev_addr);
4314 log(L_IRQ | L_INIT, "using IRQ %d\n", adev->irq);
4316 /** done with board specific setup **/
4318 acx_init_task_scheduler(adev);
4319 result = ieee80211_register_hw(adev->ieee);
4320 if (OK != result) {
4321 printk("acx: ieee80211_register_hw() FAILED: %d\n", result);
4322 goto fail_register_netdev;
4324 #if CMD_DISCOVERY
4325 great_inquisitor(adev);
4326 #endif
4328 result = OK;
4329 goto done;
4331 /* error paths: undo everything in reverse order... */
4334 acxpci_s_delete_dma_regions(adev);
4336 fail_init_mac:
4337 fail_read_eeprom_version:
4338 fail_reset:
4340 fail_alloc_netdev:
4341 fail_irq:
4343 iounmap(adev->iobase);
4344 fail_ioremap:
4346 release_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4347 fail_request_mem_region:
4348 fail_register_netdev:
4349 ieee80211_free_hw(ieee);
4350 fail:
4351 vlynq_disable_device(vdev);
4352 done:
4353 FN_EXIT1(result);
4354 return result;
4357 static void vlynq_remove(struct vlynq_device *vdev)
4359 struct ieee80211_hw *hw = vlynq_get_drvdata(vdev);
4360 acx_device_t *adev = ieee2adev(hw);
4361 unsigned long flags;
4362 FN_ENTER;
4364 if (!hw) {
4365 log(L_DEBUG, "%s: card is unused. Skipping any release code\n",
4366 __func__);
4367 goto end;
4371 acx_lock(adev, flags);
4372 acx_unlock(adev, flags);
4373 adev->initialized = 0;
4375 /* If device wasn't hot unplugged... */
4376 if (adev_present(adev)) {
4378 acx_sem_lock(adev);
4380 /* disable both Tx and Rx to shut radio down properly */
4381 if (adev->initialized) {
4382 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_TX, NULL, 0);
4383 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_RX, NULL, 0);
4385 acx_lock(adev, flags);
4386 /* disable power LED to save power :-) */
4387 log(L_INIT, "switching off power LED to save power\n");
4388 acxpci_l_power_led(adev, 0);
4389 /* stop our eCPU */
4390 acx_unlock(adev, flags);
4392 acx_sem_unlock(adev);
4395 /* unregister the device to not let the kernel
4396 * (e.g. ioctls) access a half-deconfigured device
4397 * NB: this will cause acxpci_e_close() to be called,
4398 * thus we shouldn't call it under sem!
4399 * Well, netdev did, but ieee80211 stack does not, so we
4400 * have to do so manually...
4402 acxpci_e_close(hw);
4403 log(L_INIT, "removing device %s\n", wiphy_name(adev->ieee->wiphy));
4404 ieee80211_unregister_hw(adev->ieee);
4406 /* unregister_netdev ensures that no references to us left.
4407 * For paranoid reasons we continue to follow the rules */
4408 acx_sem_lock(adev);
4410 if (adev->dev_state_mask & ACX_STATE_IFACE_UP) {
4411 acxpci_s_down(hw);
4412 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
4415 acx_proc_unregister_entries(adev->ieee);
4417 /* finally, clean up PCI bus state */
4418 acxpci_s_delete_dma_regions(adev);
4419 if (adev->iobase)
4420 iounmap(adev->iobase);
4421 if (adev->iobase2)
4422 iounmap(adev->iobase2);
4423 release_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4425 /* remove dev registration */
4427 acx_sem_unlock(adev);
4428 vlynq_disable_device(vdev);
4430 /* Free netdev (quite late,
4431 * since otherwise we might get caught off-guard
4432 * by a netdev timeout handler execution
4433 * expecting to see a working dev...) */
4434 ieee80211_free_hw(adev->ieee);
4436 end:
4437 FN_EXIT0;
4440 static struct vlynq_driver vlynq_acx = {
4441 .name = "acx_vlynq",
4442 .id_table = acx_vlynq_id,
4443 .probe = vlynq_probe,
4444 .remove = __devexit_p(vlynq_remove),
4446 #endif /* CONFIG_VLYNQ */
4449 /***********************************************************************
4450 ** Data for init_module/cleanup_module
4452 #ifdef CONFIG_PCI
4453 static const struct pci_device_id acxpci_id_tbl[] __devinitdata = {
4455 .vendor = PCI_VENDOR_ID_TI,
4456 .device = PCI_DEVICE_ID_TI_TNETW1100A,
4457 .subvendor = PCI_ANY_ID,
4458 .subdevice = PCI_ANY_ID,
4459 .driver_data = CHIPTYPE_ACX100,
4462 .vendor = PCI_VENDOR_ID_TI,
4463 .device = PCI_DEVICE_ID_TI_TNETW1100B,
4464 .subvendor = PCI_ANY_ID,
4465 .subdevice = PCI_ANY_ID,
4466 .driver_data = CHIPTYPE_ACX100,
4469 .vendor = PCI_VENDOR_ID_TI,
4470 .device = PCI_DEVICE_ID_TI_TNETW1130,
4471 .subvendor = PCI_ANY_ID,
4472 .subdevice = PCI_ANY_ID,
4473 .driver_data = CHIPTYPE_ACX111,
4476 .vendor = 0,
4477 .device = 0,
4478 .subvendor = 0,
4479 .subdevice = 0,
4480 .driver_data = 0,
4484 MODULE_DEVICE_TABLE(pci, acxpci_id_tbl);
4486 /* FIXME: checks should be removed once driver is included in the kernel */
4487 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 11)
4488 /* pci_name() got introduced at start of 2.6.x,
4489 * got mandatory (slot_name member removed) in 2.6.11-bk1 */
4490 #define pci_name(x) x->slot_name
4491 #endif
4493 static struct pci_driver
4494 acxpci_drv_id = {
4495 .name = "acx_pci",
4496 .id_table = acxpci_id_tbl,
4497 .probe = acxpci_e_probe,
4498 .remove = __devexit_p(acxpci_e_remove),
4499 #ifdef CONFIG_PM
4500 .suspend = acxpci_e_suspend,
4501 .resume = acxpci_e_resume
4502 #endif /* CONFIG_PM */
4504 #endif /* CONFIG_PCI */
4506 /***********************************************************************
4507 ** acxpci_e_init_module
4509 ** Module initialization routine, called once at module load time
4511 int __init acxpci_e_init_module(void)
4513 int res;
4515 FN_ENTER;
4517 #if (ACX_IO_WIDTH==32)
4518 printk("acx: compiled to use 32bit I/O access. "
4519 "I/O timing issues might occur, such as "
4520 "non-working firmware upload. Report them\n");
4521 #else
4522 printk("acx: compiled to use 16bit I/O access only "
4523 "(compatibility mode)\n");
4524 #endif
4526 #ifdef __LITTLE_ENDIAN
4527 #define ENDIANNESS_STRING "running on a little-endian CPU\n"
4528 #else
4529 #define ENDIANNESS_STRING "running on a BIG-ENDIAN CPU\n"
4530 #endif
4531 log(L_INIT,
4532 "acx: " ENDIANNESS_STRING
4533 "acx: PCI/VLYNQ module " ACX_RELEASE " initialized, "
4534 "waiting for cards to probe...\n");
4536 #ifdef CONFIG_PCI
4537 res = pci_register_driver(&acxpci_drv_id);
4538 #endif
4539 #ifdef CONFIG_VLYNQ
4540 res = vlynq_register_driver(&vlynq_acx);
4541 #endif
4542 FN_EXIT1(res);
4543 return res;
4547 /***********************************************************************
4548 ** acxpci_e_cleanup_module
4550 ** Called at module unload time. This is our last chance to
4551 ** clean up after ourselves.
4553 void __exit acxpci_e_cleanup_module(void)
4555 FN_ENTER;
4557 #ifdef CONFIG_PCI
4558 pci_unregister_driver(&acxpci_drv_id);
4559 #endif
4560 #ifdef CONFIG_VLYNQ
4561 vlynq_unregister_driver(&vlynq_acx);
4562 #endif
4563 log(L_INIT,
4564 "acx: PCI module " ACX_RELEASE " unloaded\n");
4565 FN_EXIT0;