added little comment and one more printk
[acx-mac80211.git] / pci.c
blobd4d8f21f5aa84cfb3646be1689d3b8b9f2ebba97
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>
37 #include "acx.h"
39 /***********************************************************************
41 #define PCI_TYPE (PCI_USES_MEM | PCI_ADDR0 | PCI_NO_ACPI_WAKE)
42 #define PCI_ACX100_REGION1 0x01
43 #define PCI_ACX100_REGION1_SIZE 0x1000 /* Memory size - 4K bytes */
44 #define PCI_ACX100_REGION2 0x02
45 #define PCI_ACX100_REGION2_SIZE 0x10000 /* Memory size - 64K bytes */
47 #define PCI_ACX111_REGION1 0x00
48 #define PCI_ACX111_REGION1_SIZE 0x2000 /* Memory size - 8K bytes */
49 #define PCI_ACX111_REGION2 0x01
50 #define PCI_ACX111_REGION2_SIZE 0x20000 /* Memory size - 128K bytes */
52 /* Texas Instruments Vendor ID */
53 #define PCI_VENDOR_ID_TI 0x104c
55 /* ACX100 22Mb/s WLAN controller */
56 #define PCI_DEVICE_ID_TI_TNETW1100A 0x8400
57 #define PCI_DEVICE_ID_TI_TNETW1100B 0x8401
59 /* ACX111 54Mb/s WLAN controller */
60 #define PCI_DEVICE_ID_TI_TNETW1130 0x9066
62 /* PCI Class & Sub-Class code, Network-'Other controller' */
63 #define PCI_CLASS_NETWORK_OTHERS 0x0280
65 #define CARD_EEPROM_ID_SIZE 6
67 #ifndef PCI_D0
68 /* From include/linux/pci.h */
69 #define PCI_D0 0
70 #define PCI_D1 1
71 #define PCI_D2 2
72 #define PCI_D3hot 3
73 #define PCI_D3cold 4
74 #define PCI_UNKNOWN 5
75 #define PCI_POWER_ERROR -1
76 #endif
78 /***********************************************************************
81 static irqreturn_t acxpci_i_interrupt(int irq, void *dev_id);
83 static void disable_acx_irq(acx_device_t * adev);
85 static int acxpci_e_open(struct ieee80211_hw *hw);
86 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
87 static int acxpci_e_close(struct ieee80211_hw *hw);
88 #else
89 static void acxpci_e_close(struct ieee80211_hw *hw);
90 #endif
91 static void acxpci_s_up(struct ieee80211_hw *hw);
92 static void acxpci_s_down(struct ieee80211_hw *hw);
94 void acxpci_put_devname(acx_device_t *adev, struct ethtool_drvinfo *info)
97 strncpy(info->bus_info,pci_name(adev->pdev), ETHTOOL_BUSINFO_LEN);
100 /***********************************************************************
101 ** Register access
106 /* OS I/O routines *always* be endianness-clean but having them doesn't hurt */
107 #define acx_readl(v) le32_to_cpu(readl((v)))
108 #define acx_readw(v) le16_to_cpu(readw((v)))
109 #define acx_writew(v,r) writew(le16_to_cpu((v)), r)
110 #define acx_writel(v,r) writel(le32_to_cpu((v)), r)
112 /* Pick one */
113 /* #define INLINE_IO static */
114 #define INLINE_IO static inline
116 INLINE_IO u32 read_reg32(acx_device_t * adev, unsigned int offset)
118 #if ACX_IO_WIDTH == 32
119 return acx_readl((u8 *) adev->iobase + adev->io[offset]);
120 #else
121 return acx_readw((u8 *) adev->iobase + adev->io[offset])
122 + (acx_readw((u8 *) adev->iobase + adev->io[offset] + 2) << 16);
123 #endif
126 INLINE_IO u16 read_reg16(acx_device_t * adev, unsigned int offset)
128 return acx_readw((u8 *) adev->iobase + adev->io[offset]);
131 INLINE_IO u8 read_reg8(acx_device_t * adev, unsigned int offset)
133 return readb((u8 *) adev->iobase + adev->io[offset]);
136 INLINE_IO void write_reg32(acx_device_t * adev, unsigned int offset, u32 val)
138 #if ACX_IO_WIDTH == 32
139 acx_writel(val, (u8 *) adev->iobase + adev->io[offset]);
140 #else
141 acx_writew(val & 0xffff, (u8 *) adev->iobase + adev->io[offset]);
142 acx_writew(val >> 16, (u8 *) adev->iobase + adev->io[offset] + 2);
143 #endif
146 INLINE_IO void write_reg16(acx_device_t * adev, unsigned int offset, u16 val)
148 acx_writew(val, (u8 *) adev->iobase + adev->io[offset]);
151 INLINE_IO void write_reg8(acx_device_t * adev, unsigned int offset, u8 val)
153 writeb(val, (u8 *) adev->iobase + adev->io[offset]);
156 /* Handle PCI posting properly:
157 * Make sure that writes reach the adapter in case they require to be executed
158 * *before* the next write, by reading a random (and safely accessible) register.
159 * This call has to be made if there is no read following (which would flush the data
160 * to the adapter), yet the written data has to reach the adapter immediately. */
161 INLINE_IO void write_flush(acx_device_t * adev)
163 /* readb(adev->iobase + adev->io[IO_ACX_INFO_MAILBOX_OFFS]); */
164 /* faster version (accesses the first register, IO_ACX_SOFT_RESET,
165 * which should also be safe): */
166 readb(adev->iobase);
169 INLINE_IO int adev_present(acx_device_t * adev)
171 /* fast version (accesses the first register, IO_ACX_SOFT_RESET,
172 * which should be safe): */
173 return acx_readl(adev->iobase) != 0xffffffff;
177 /***********************************************************************
179 static inline txdesc_t *get_txdesc(acx_device_t * adev, int index)
181 return (txdesc_t *) (((u8 *) adev->txdesc_start) +
182 index * adev->txdesc_size);
185 static inline txdesc_t *advance_txdesc(acx_device_t * adev, txdesc_t * txdesc,
186 int inc)
188 return (txdesc_t *) (((u8 *) txdesc) + inc * adev->txdesc_size);
191 static txhostdesc_t *get_txhostdesc(acx_device_t * adev, txdesc_t * txdesc)
193 int index = (u8 *) txdesc - (u8 *) adev->txdesc_start;
194 if (unlikely(ACX_DEBUG && (index % adev->txdesc_size))) {
195 printk("bad txdesc ptr %p\n", txdesc);
196 return NULL;
198 index /= adev->txdesc_size;
199 if (unlikely(ACX_DEBUG && (index >= TX_CNT))) {
200 printk("bad txdesc ptr %p\n", txdesc);
201 return NULL;
203 return &adev->txhostdesc_start[index * 2];
210 /***********************************************************************
211 ** EEPROM and PHY read/write helpers
213 /***********************************************************************
214 ** acxpci_read_eeprom_byte
216 ** Function called to read an octet in the EEPROM.
218 ** This function is used by acxpci_e_probe to check if the
219 ** connected card is a legal one or not.
221 ** Arguments:
222 ** adev ptr to acx_device structure
223 ** addr address to read in the EEPROM
224 ** charbuf ptr to a char. This is where the read octet
225 ** will be stored
228 int acxpci_read_eeprom_byte(acx_device_t * adev, u32 addr, u8 * charbuf)
230 int result;
231 int count;
233 FN_ENTER;
235 write_reg32(adev, IO_ACX_EEPROM_CFG, 0);
236 write_reg32(adev, IO_ACX_EEPROM_ADDR, addr);
237 write_flush(adev);
238 write_reg32(adev, IO_ACX_EEPROM_CTL, 2);
240 count = 0xffff;
241 while (read_reg16(adev, IO_ACX_EEPROM_CTL)) {
242 /* scheduling away instead of CPU burning loop
243 * doesn't seem to work here at all:
244 * awful delay, sometimes also failure.
245 * Doesn't matter anyway (only small delay). */
246 if (unlikely(!--count)) {
247 printk("%s: timeout waiting for EEPROM read\n",
248 wiphy_name(adev->ieee->wiphy));
249 result = NOT_OK;
250 goto fail;
252 cpu_relax();
255 *charbuf = read_reg8(adev, IO_ACX_EEPROM_DATA);
256 log(L_DEBUG, "EEPROM at 0x%04X = 0x%02X\n", addr, *charbuf);
257 result = OK;
259 fail:
260 FN_EXIT1(result);
261 return result;
265 /***********************************************************************
266 ** We don't lock hw accesses here since we never r/w eeprom in IRQ
267 ** Note: this function sleeps only because of GFP_KERNEL alloc
269 #ifdef UNUSED
271 acxpci_s_write_eeprom(acx_device_t * adev, u32 addr, u32 len,
272 const u8 * charbuf)
274 u8 *data_verify = NULL;
275 unsigned long flags;
276 int count, i;
277 int result = NOT_OK;
278 u16 gpio_orig;
280 printk("acx: WARNING! I would write to EEPROM now. "
281 "Since I really DON'T want to unless you know "
282 "what you're doing (THIS CODE WILL PROBABLY "
283 "NOT WORK YET!), I will abort that now. And "
284 "definitely make sure to make a "
285 "/proc/driver/acx_wlan0_eeprom backup copy first!!! "
286 "(the EEPROM content includes the PCI config header!! "
287 "If you kill important stuff, then you WILL "
288 "get in trouble and people DID get in trouble already)\n");
289 return OK;
291 FN_ENTER;
293 data_verify = kmalloc(len, GFP_KERNEL);
294 if (!data_verify) {
295 goto end;
298 /* first we need to enable the OE (EEPROM Output Enable) GPIO line
299 * to be able to write to the EEPROM.
300 * NOTE: an EEPROM writing success has been reported,
301 * but you probably have to modify GPIO_OUT, too,
302 * and you probably need to activate a different GPIO
303 * line instead! */
304 gpio_orig = read_reg16(adev, IO_ACX_GPIO_OE);
305 write_reg16(adev, IO_ACX_GPIO_OE, gpio_orig & ~1);
306 write_flush(adev);
308 /* ok, now start writing the data out */
309 for (i = 0; i < len; i++) {
310 write_reg32(adev, IO_ACX_EEPROM_CFG, 0);
311 write_reg32(adev, IO_ACX_EEPROM_ADDR, addr + i);
312 write_reg32(adev, IO_ACX_EEPROM_DATA, *(charbuf + i));
313 write_flush(adev);
314 write_reg32(adev, IO_ACX_EEPROM_CTL, 1);
316 count = 0xffff;
317 while (read_reg16(adev, IO_ACX_EEPROM_CTL)) {
318 if (unlikely(!--count)) {
319 printk("WARNING, DANGER!!! "
320 "Timeout waiting for EEPROM write\n");
321 goto end;
323 cpu_relax();
327 /* disable EEPROM writing */
328 write_reg16(adev, IO_ACX_GPIO_OE, gpio_orig);
329 write_flush(adev);
331 /* now start a verification run */
332 for (i = 0; i < len; i++) {
333 write_reg32(adev, IO_ACX_EEPROM_CFG, 0);
334 write_reg32(adev, IO_ACX_EEPROM_ADDR, addr + i);
335 write_flush(adev);
336 write_reg32(adev, IO_ACX_EEPROM_CTL, 2);
338 count = 0xffff;
339 while (read_reg16(adev, IO_ACX_EEPROM_CTL)) {
340 if (unlikely(!--count)) {
341 printk("timeout waiting for EEPROM read\n");
342 goto end;
344 cpu_relax();
347 data_verify[i] = read_reg16(adev, IO_ACX_EEPROM_DATA);
350 if (0 == memcmp(charbuf, data_verify, len))
351 result = OK; /* read data matches, success */
353 end:
354 kfree(data_verify);
355 FN_EXIT1(result);
356 return result;
358 #endif /* UNUSED */
361 /***********************************************************************
362 ** acxpci_s_read_phy_reg
364 ** Messing with rx/tx disabling and enabling here
365 ** (write_reg32(adev, IO_ACX_ENABLE, 0b000000xx)) kills traffic
367 int acxpci_s_read_phy_reg(acx_device_t * adev, u32 reg, u8 * charbuf)
369 int result = NOT_OK;
370 int count;
372 FN_ENTER;
374 write_reg32(adev, IO_ACX_PHY_ADDR, reg);
375 write_flush(adev);
376 write_reg32(adev, IO_ACX_PHY_CTL, 2);
378 count = 0xffff;
379 while (read_reg32(adev, IO_ACX_PHY_CTL)) {
380 /* scheduling away instead of CPU burning loop
381 * doesn't seem to work here at all:
382 * awful delay, sometimes also failure.
383 * Doesn't matter anyway (only small delay). */
384 if (unlikely(!--count)) {
385 printk("%s: timeout waiting for phy read\n",
386 wiphy_name(adev->ieee->wiphy));
387 *charbuf = 0;
388 goto fail;
390 cpu_relax();
393 log(L_DEBUG, "count was %u\n", count);
394 *charbuf = read_reg8(adev, IO_ACX_PHY_DATA);
396 log(L_DEBUG, "radio PHY at 0x%04X = 0x%02X\n", *charbuf, reg);
397 result = OK;
398 goto fail; /* silence compiler warning */
399 fail:
400 FN_EXIT1(result);
401 return result;
405 /***********************************************************************
407 int acxpci_s_write_phy_reg(acx_device_t * adev, u32 reg, u8 value)
409 FN_ENTER;
411 /* mprusko said that 32bit accesses result in distorted sensitivity
412 * on his card. Unconfirmed, looks like it's not true (most likely since we
413 * now properly flush writes). */
414 write_reg32(adev, IO_ACX_PHY_DATA, value);
415 write_reg32(adev, IO_ACX_PHY_ADDR, reg);
416 write_flush(adev);
417 write_reg32(adev, IO_ACX_PHY_CTL, 1);
418 write_flush(adev);
419 log(L_DEBUG, "radio PHY write 0x%02X at 0x%04X\n", value, reg);
421 FN_EXIT0;
422 return OK;
426 #define NO_AUTO_INCREMENT 1
428 /***********************************************************************
429 ** acxpci_s_write_fw
431 ** Write the firmware image into the card.
433 ** Arguments:
434 ** adev wlan device structure
435 ** fw_image firmware image.
437 ** Returns:
438 ** 1 firmware image corrupted
439 ** 0 success
441 ** Standard csum implementation + write to IO
443 static int
444 acxpci_s_write_fw(acx_device_t * adev, const firmware_image_t *fw_image,
445 u32 offset)
447 int len, size;
448 u32 sum, v32;
449 /* we skip the first four bytes which contain the control sum */
451 const u8 *p = (u8 *) fw_image + 4;
453 FN_ENTER;
455 /* start the image checksum by adding the image size value */
456 sum = p[0] + p[1] + p[2] + p[3];
457 p += 4;
459 write_reg32(adev, IO_ACX_SLV_END_CTL, 0);
461 #if NO_AUTO_INCREMENT
462 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 0); /* use basic mode */
463 #else
464 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 1); /* use autoincrement mode */
465 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset); /* configure start address */
466 write_flush(adev);
467 #endif
469 len = 0;
470 size = le32_to_cpu(fw_image->size) & (~3);
472 while (likely(len < size)) {
473 v32 = be32_to_cpu(*(u32 *) p);
474 sum += p[0] + p[1] + p[2] + p[3];
475 p += 4;
476 len += 4;
478 #if NO_AUTO_INCREMENT
479 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset + len - 4);
480 write_flush(adev);
481 #endif
482 write_reg32(adev, IO_ACX_SLV_MEM_DATA, v32);
485 log(L_DEBUG, "firmware written, size:%d sum1:%x sum2:%x\n",
486 size, sum, le32_to_cpu(fw_image->chksum));
488 /* compare our checksum with the stored image checksum */
489 FN_EXIT1(sum != le32_to_cpu(fw_image->chksum));
490 return (sum != le32_to_cpu(fw_image->chksum));
494 /***********************************************************************
495 ** acxpci_s_validate_fw
497 ** Compare the firmware image given with
498 ** the firmware image written into the card.
500 ** Arguments:
501 ** adev wlan device structure
502 ** fw_image firmware image.
504 ** Returns:
505 ** NOT_OK firmware image corrupted or not correctly written
506 ** OK success
508 ** Origin: Standard csum + Read IO
510 static int
511 acxpci_s_validate_fw(acx_device_t * adev, const firmware_image_t *fw_image,
512 u32 offset)
514 u32 sum, v32, w32;
515 int len, size;
516 int result = OK;
517 /* we skip the first four bytes which contain the control sum */
518 const u8 *p = (u8 *) fw_image + 4;
520 FN_ENTER;
522 /* start the image checksum by adding the image size value */
523 sum = p[0] + p[1] + p[2] + p[3];
524 p += 4;
526 write_reg32(adev, IO_ACX_SLV_END_CTL, 0);
528 #if NO_AUTO_INCREMENT
529 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 0); /* use basic mode */
530 #else
531 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 1); /* use autoincrement mode */
532 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset); /* configure start address */
533 #endif
535 len = 0;
536 size = le32_to_cpu(fw_image->size) & (~3);
538 while (likely(len < size)) {
539 v32 = be32_to_cpu(*(u32 *) p);
540 p += 4;
541 len += 4;
543 #if NO_AUTO_INCREMENT
544 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset + len - 4);
545 #endif
546 w32 = read_reg32(adev, IO_ACX_SLV_MEM_DATA);
548 if (unlikely(w32 != v32)) {
549 printk("acx: FATAL: firmware upload: "
550 "data parts at offset %d don't match (0x%08X vs. 0x%08X)! "
551 "I/O timing issues or defective memory, with DWL-xx0+? "
552 "ACX_IO_WIDTH=16 may help. Please report\n",
553 len, v32, w32);
554 result = NOT_OK;
555 break;
558 sum +=
559 (u8) w32 + (u8) (w32 >> 8) + (u8) (w32 >> 16) +
560 (u8) (w32 >> 24);
563 /* sum control verification */
564 if (result != NOT_OK) {
565 if (sum != le32_to_cpu(fw_image->chksum)) {
566 printk("acx: FATAL: firmware upload: "
567 "checksums don't match!\n");
568 result = NOT_OK;
572 FN_EXIT1(result);
573 return result;
577 /***********************************************************************
578 ** acxpci_s_upload_fw
580 ** Called from acx_reset_dev
582 ** Origin: Derived from FW dissection
584 static int acxpci_s_upload_fw(acx_device_t * adev)
586 firmware_image_t *fw_image = NULL;
587 int res = NOT_OK;
588 int try;
589 u32 file_size;
590 char filename[sizeof("tiacx1NNcNN")];
592 FN_ENTER;
594 /* print exact chipset and radio ID to make sure people
595 * really get a clue on which files exactly they need to provide.
596 * Firmware loading is a frequent end-user PITA with these chipsets.
598 printk( "acx: need firmware for acx1%02d chipset with radio ID %02X\n"
599 "Please provide via firmware hotplug:\n"
600 "either combined firmware (single file named 'tiacx1%02dc%02X')\n"
601 "or two files (base firmware file 'tiacx1%02d' "
602 "+ radio fw 'tiacx1%02dr%02X')\n",
603 IS_ACX111(adev)*11, adev->radio_type,
604 IS_ACX111(adev)*11, adev->radio_type,
605 IS_ACX111(adev)*11,
606 IS_ACX111(adev)*11, adev->radio_type
609 /* print exact chipset and radio ID to make sure people really get a clue on which files exactly they are supposed to provide,
610 * since firmware loading is the biggest enduser PITA with these chipsets.
611 * Not printing radio ID in 0xHEX in order to not confuse them into wrong file naming */
612 printk( "acx: need to load firmware for acx1%02d chipset with radio ID %02x, please provide via firmware hotplug:\n"
613 "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",
614 IS_ACX111(adev)*11, adev->radio_type);
616 /* Try combined, then main image */
617 adev->need_radio_fw = 0;
618 snprintf(filename, sizeof(filename), "tiacx1%02dc%02X",
619 IS_ACX111(adev) * 11, adev->radio_type);
621 fw_image = acx_s_read_fw(&adev->pdev->dev, filename, &file_size);
622 if (!fw_image) {
623 adev->need_radio_fw = 1;
624 filename[sizeof("tiacx1NN") - 1] = '\0';
625 fw_image =
626 acx_s_read_fw(&adev->pdev->dev, filename, &file_size);
627 if (!fw_image) {
628 FN_EXIT1(NOT_OK);
629 return NOT_OK;
633 for (try = 1; try <= 5; try++) {
634 res = acxpci_s_write_fw(adev, fw_image, 0);
635 log(L_DEBUG | L_INIT, "acx_write_fw (main/combined): %d\n", res);
636 if (OK == res) {
637 res = acxpci_s_validate_fw(adev, fw_image, 0);
638 log(L_DEBUG | L_INIT, "acx_validate_fw "
639 "(main/combined): %d\n", res);
642 if (OK == res) {
643 SET_BIT(adev->dev_state_mask, ACX_STATE_FW_LOADED);
644 break;
646 printk("acx: firmware upload attempt #%d FAILED, "
647 "retrying...\n", try);
648 acx_s_mdelay(1000); /* better wait for a while... */
651 vfree(fw_image);
653 FN_EXIT1(res);
654 return res;
658 /***********************************************************************
659 ** acxpci_s_upload_radio
661 ** Uploads the appropriate radio module firmware into the card.
663 ** Origin: Standard Read/Write to IO
665 int acxpci_s_upload_radio(acx_device_t * adev)
667 acx_ie_memmap_t mm;
668 firmware_image_t *radio_image;
669 acx_cmd_radioinit_t radioinit;
670 int res = NOT_OK;
671 int try;
672 u32 offset;
673 u32 size;
674 char filename[sizeof("tiacx1NNrNN")];
676 if (!adev->need_radio_fw)
677 return OK;
679 FN_ENTER;
681 acx_s_interrogate(adev, &mm, ACX1xx_IE_MEMORY_MAP);
682 offset = le32_to_cpu(mm.CodeEnd);
684 snprintf(filename, sizeof(filename), "tiacx1%02dr%02X",
685 IS_ACX111(adev) * 11, adev->radio_type);
686 radio_image = acx_s_read_fw(&adev->pdev->dev, filename, &size);
687 if (!radio_image) {
688 printk("acx: can't load radio module '%s'\n", filename);
689 goto fail;
692 acx_s_issue_cmd(adev, ACX1xx_CMD_SLEEP, NULL, 0);
694 for (try = 1; try <= 5; try++) {
695 res = acxpci_s_write_fw(adev, radio_image, offset);
696 log(L_DEBUG | L_INIT, "acx_write_fw (radio): %d\n", res);
697 if (OK == res) {
698 res = acxpci_s_validate_fw(adev, radio_image, offset);
699 log(L_DEBUG | L_INIT, "acx_validate_fw (radio): %d\n",
700 res);
703 if (OK == res)
704 break;
705 printk("acx: radio firmware upload attempt #%d FAILED, "
706 "retrying...\n", try);
707 acx_s_mdelay(1000); /* better wait for a while... */
710 acx_s_issue_cmd(adev, ACX1xx_CMD_WAKE, NULL, 0);
711 radioinit.offset = cpu_to_le32(offset);
712 /* no endian conversion needed, remains in card CPU area: */
713 radioinit.len = radio_image->size;
715 vfree(radio_image);
717 if (OK != res)
718 goto fail;
720 /* will take a moment so let's have a big timeout */
721 acx_s_issue_cmd_timeo(adev, ACX1xx_CMD_RADIOINIT,
722 &radioinit, sizeof(radioinit),
723 CMD_TIMEOUT_MS(1000));
725 res = acx_s_interrogate(adev, &mm, ACX1xx_IE_MEMORY_MAP);
726 fail:
727 FN_EXIT1(res);
728 return res;
732 /***********************************************************************
733 ** acxpci_l_reset_mac
735 ** MAC will be reset
736 ** Call context: reset_dev
738 ** Origin: Standard Read/Write to IO
740 static void acxpci_l_reset_mac(acx_device_t * adev)
742 u16 temp;
744 FN_ENTER;
746 /* halt eCPU */
747 temp = read_reg16(adev, IO_ACX_ECPU_CTRL) | 0x1;
748 write_reg16(adev, IO_ACX_ECPU_CTRL, temp);
750 /* now do soft reset of eCPU, set bit */
751 temp = read_reg16(adev, IO_ACX_SOFT_RESET) | 0x1;
752 log(L_DEBUG, "enable soft reset\n");
753 write_reg16(adev, IO_ACX_SOFT_RESET, temp);
754 write_flush(adev);
756 /* now clear bit again: deassert eCPU reset */
757 log(L_DEBUG, "disable soft reset and go to init mode");
758 write_reg16(adev, IO_ACX_SOFT_RESET, temp & ~0x1);
760 /* now start a burst read from initial EEPROM */
761 temp = read_reg16(adev, IO_ACX_EE_START) | 0x1;
762 write_reg16(adev, IO_ACX_EE_START, temp);
763 write_flush(adev);
765 FN_EXIT0;
769 /***********************************************************************
770 ** acxpci_s_verify_init
772 static int acxpci_s_verify_init(acx_device_t * adev)
774 int result = NOT_OK;
775 unsigned long timeout;
777 FN_ENTER;
779 timeout = jiffies + 2 * HZ;
780 for (;;) {
781 u16 irqstat = read_reg16(adev, IO_ACX_IRQ_STATUS_NON_DES);
782 if (irqstat & HOST_INT_FCS_THRESHOLD) {
783 result = OK;
784 write_reg16(adev, IO_ACX_IRQ_ACK,
785 HOST_INT_FCS_THRESHOLD);
786 break;
788 if (time_after(jiffies, timeout))
789 break;
790 /* Init may take up to ~0.5 sec total */
791 acx_s_mdelay(50);
794 FN_EXIT1(result);
795 return result;
799 /***********************************************************************
800 ** A few low-level helpers
802 ** Note: these functions are not protected by lock
803 ** and thus are never allowed to be called from IRQ.
804 ** Also they must not race with fw upload which uses same hw regs
807 /***********************************************************************
808 ** acxpci_write_cmd_type_status
810 ** Origin: Common linux implementation
813 static inline void
814 acxpci_write_cmd_type_status(acx_device_t * adev, u16 type, u16 status)
816 FN_ENTER;
817 acx_writel(type | (status << 16), adev->cmd_area);
818 write_flush(adev);
819 FN_EXIT0;
823 /***********************************************************************
824 ** acxpci_read_cmd_type_status
826 ** Origin: Common linux implementation
828 static u32 acxpci_read_cmd_type_status(acx_device_t * adev)
830 u32 cmd_type, cmd_status;
832 FN_ENTER;
834 cmd_type = acx_readl(adev->cmd_area);
835 cmd_status = (cmd_type >> 16);
836 cmd_type = (u16) cmd_type;
838 log(L_CTL, "cmd_type:%04X cmd_status:%04X [%s]\n",
839 cmd_type, cmd_status, acx_cmd_status_str(cmd_status));
841 FN_EXIT1(cmd_status);
842 return cmd_status;
846 /***********************************************************************
847 ** acxpci_s_reset_dev
849 ** Arguments:
850 ** netdevice that contains the adev variable
851 ** Returns:
852 ** NOT_OK on fail
853 ** OK on success
854 ** Side effects:
855 ** device is hard reset
856 ** Call context:
857 ** acxpci_e_probe
858 ** Comment:
859 ** This resets the device using low level hardware calls
860 ** as well as uploads and verifies the firmware to the card
863 static inline void init_mboxes(acx_device_t * adev)
865 u32 cmd_offs, info_offs;
867 FN_ENTER;
869 cmd_offs = read_reg32(adev, IO_ACX_CMD_MAILBOX_OFFS);
870 info_offs = read_reg32(adev, IO_ACX_INFO_MAILBOX_OFFS);
871 adev->cmd_area = (u8 *) adev->iobase2 + cmd_offs;
872 adev->info_area = (u8 *) adev->iobase2 + info_offs;
873 log(L_DEBUG, "iobase2=%p\n"
874 "cmd_mbox_offset=%X cmd_area=%p\n"
875 "info_mbox_offset=%X info_area=%p\n",
876 adev->iobase2,
877 cmd_offs, adev->cmd_area, info_offs, adev->info_area);
878 FN_EXIT0;
882 static inline void read_eeprom_area(acx_device_t * adev)
884 #if ACX_DEBUG > 1
885 int offs;
886 u8 tmp;
888 FN_ENTER;
890 for (offs = 0x8c; offs < 0xb9; offs++)
891 acxpci_read_eeprom_byte(adev, offs, &tmp);
893 FN_EXIT0;
894 #endif
898 int acxpci_s_reset_dev(acx_device_t * adev)
900 const char *msg = "";
901 unsigned long flags;
902 int result = NOT_OK;
903 u16 hardware_info;
904 u16 ecpu_ctrl;
905 int count;
907 FN_ENTER;
909 /* reset the device to make sure the eCPU is stopped
910 * to upload the firmware correctly */
912 acx_lock(adev, flags);
914 acxpci_l_reset_mac(adev);
916 ecpu_ctrl = read_reg16(adev, IO_ACX_ECPU_CTRL) & 1;
917 if (!ecpu_ctrl) {
918 msg = "eCPU is already running. ";
919 goto end_unlock;
921 #ifdef WE_DONT_NEED_THAT_DO_WE
922 if (read_reg16(adev, IO_ACX_SOR_CFG) & 2) {
923 /* eCPU most likely means "embedded CPU" */
924 msg = "eCPU did not start after boot from flash. ";
925 goto end_unlock;
928 /* check sense on reset flags */
929 if (read_reg16(adev, IO_ACX_SOR_CFG) & 0x10) {
930 printk("%s: eCPU did not start after boot (SOR), "
931 "is this fatal?\n", wiphy_name(adev->ieee->wiphy));
933 #endif
934 /* scan, if any, is stopped now, setting corresponding IRQ bit */
935 adev->irq_status |= HOST_INT_SCAN_COMPLETE;
937 acx_unlock(adev, flags);
939 /* need to know radio type before fw load */
940 /* Need to wait for arrival of this information in a loop,
941 * most probably since eCPU runs some init code from EEPROM
942 * (started burst read in reset_mac()) which also
943 * sets the radio type ID */
945 count = 0xffff;
946 do {
947 hardware_info = read_reg16(adev, IO_ACX_EEPROM_INFORMATION);
948 if (!--count) {
949 msg = "eCPU didn't indicate radio type";
950 goto end_fail;
952 cpu_relax();
953 } while (!(hardware_info & 0xff00)); /* radio type still zero? */
955 /* printk("DEBUG: count %d\n", count); */
956 adev->form_factor = hardware_info & 0xff;
957 adev->radio_type = hardware_info >> 8;
959 /* load the firmware */
960 if (OK != acxpci_s_upload_fw(adev))
961 goto end_fail;
963 /* acx_s_mdelay(10); this one really shouldn't be required */
965 /* now start eCPU by clearing bit */
966 write_reg16(adev, IO_ACX_ECPU_CTRL, ecpu_ctrl & ~0x1);
967 log(L_DEBUG, "booted eCPU up and waiting for completion...\n");
969 /* wait for eCPU bootup */
970 if (OK != acxpci_s_verify_init(adev)) {
971 msg = "timeout waiting for eCPU. ";
972 goto end_fail;
974 log(L_DEBUG, "eCPU has woken up, card is ready to be configured\n");
976 init_mboxes(adev);
977 acxpci_write_cmd_type_status(adev, 0, 0);
979 /* test that EEPROM is readable */
980 read_eeprom_area(adev);
982 result = OK;
983 goto end;
985 /* Finish error message. Indicate which function failed */
986 end_unlock:
987 acx_unlock(adev, flags);
988 end_fail:
989 printk("acx: %sreset_dev() FAILED\n", msg);
990 end:
991 FN_EXIT1(result);
992 return result;
996 /***********************************************************************
997 ** acxpci_s_issue_cmd_timeo
999 ** Sends command to fw, extract result
1001 ** NB: we do _not_ take lock inside, so be sure to not touch anything
1002 ** which may interfere with IRQ handler operation
1004 ** TODO: busy wait is a bit silly, so:
1005 ** 1) stop doing many iters - go to sleep after first
1006 ** 2) go to waitqueue based approach: wait, not poll!
1008 #undef FUNC
1009 #define FUNC "issue_cmd"
1011 #if !ACX_DEBUG
1013 acxpci_s_issue_cmd_timeo(acx_device_t * adev,
1014 unsigned int cmd,
1015 void *buffer, unsigned buflen, unsigned int cmd_timeout)
1017 #else
1019 acxpci_s_issue_cmd_timeo_debug(acx_device_t * adev,
1020 unsigned cmd,
1021 void *buffer,
1022 unsigned buflen,
1023 unsigned int cmd_timeout, const char *cmdstr)
1025 unsigned long start = jiffies;
1026 #endif
1027 const char *devname;
1028 unsigned counter;
1029 u16 irqtype;
1030 u16 cmd_status;
1031 unsigned long timeout;
1033 FN_ENTER;
1036 devname = wiphy_name(adev->ieee->wiphy);
1037 if (!devname || !devname[0] || devname[4] == '%')
1038 devname = "acx";
1040 log(L_CTL, FUNC "(cmd:%s,buflen:%u,timeout:%ums,type:0x%04X)\n",
1041 cmdstr, buflen, cmd_timeout,
1042 buffer ? le16_to_cpu(((acx_ie_generic_t *) buffer)->type) : -1);
1044 if (!(adev->dev_state_mask & ACX_STATE_FW_LOADED)) {
1045 printk("%s: " FUNC "(): firmware is not loaded yet, "
1046 "cannot execute commands!\n", devname);
1047 goto bad;
1050 if ((acx_debug & L_DEBUG) && (cmd != ACX1xx_CMD_INTERROGATE)) {
1051 printk("input buffer (len=%u):\n", buflen);
1052 acx_dump_bytes(buffer, buflen);
1055 /* wait for firmware to become idle for our command submission */
1056 timeout = HZ / 5;
1057 counter = (timeout * 1000 / HZ) - 1; /* in ms */
1058 timeout += jiffies;
1059 do {
1060 cmd_status = acxpci_read_cmd_type_status(adev);
1061 /* Test for IDLE state */
1062 if (!cmd_status)
1063 break;
1064 if (counter % 8 == 0) {
1065 if (time_after(jiffies, timeout)) {
1066 counter = 0;
1067 break;
1069 /* we waited 8 iterations, no luck. Sleep 8 ms */
1070 acx_s_mdelay(8);
1072 } while (likely(--counter));
1074 if (!counter) {
1075 /* the card doesn't get idle, we're in trouble */
1076 printk("%s: " FUNC "(): cmd_status is not IDLE: 0x%04X!=0\n",
1077 devname, cmd_status);
1078 goto bad;
1079 } else if (counter < 190) { /* if waited >10ms... */
1080 log(L_CTL | L_DEBUG, FUNC "(): waited for IDLE %dms. "
1081 "Please report\n", 199 - counter);
1084 /* now write the parameters of the command if needed */
1085 if (buffer && buflen) {
1086 /* if it's an INTERROGATE command, just pass the length
1087 * of parameters to read, as data */
1088 #if CMD_DISCOVERY
1089 if (cmd == ACX1xx_CMD_INTERROGATE)
1090 memset_io(adev->cmd_area + 4, 0xAA, buflen);
1091 #endif
1092 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1093 memcpy_toio(adev->cmd_area + 4, buffer,
1094 (cmd == ACX1xx_CMD_INTERROGATE) ? 4 : buflen);
1096 /* now write the actual command type */
1097 acxpci_write_cmd_type_status(adev, cmd, 0);
1098 /* execute command */
1099 write_reg16(adev, IO_ACX_INT_TRIG, INT_TRIG_CMD);
1100 write_flush(adev);
1102 /* wait for firmware to process command */
1104 /* Ensure nonzero and not too large timeout.
1105 ** Also converts e.g. 100->99, 200->199
1106 ** which is nice but not essential */
1107 cmd_timeout = (cmd_timeout - 1) | 1;
1108 if (unlikely(cmd_timeout > 1199))
1109 cmd_timeout = 1199;
1110 /* clear CMD_COMPLETE bit. can be set only by IRQ handler: */
1111 adev->irq_status &= ~HOST_INT_CMD_COMPLETE;
1113 /* we schedule away sometimes (timeout can be large) */
1114 counter = cmd_timeout;
1115 timeout = jiffies + cmd_timeout * HZ / 1000;
1116 do {
1117 if (!adev->irqs_active) { /* IRQ disabled: poll */
1118 irqtype = read_reg16(adev, IO_ACX_IRQ_STATUS_NON_DES);
1119 if (irqtype & HOST_INT_CMD_COMPLETE) {
1120 write_reg16(adev, IO_ACX_IRQ_ACK,
1121 HOST_INT_CMD_COMPLETE);
1122 break;
1124 } else { /* Wait when IRQ will set the bit */
1125 irqtype = adev->irq_status;
1126 if (irqtype & HOST_INT_CMD_COMPLETE)
1127 break;
1130 if (counter % 8 == 0) {
1131 if (time_after(jiffies, timeout)) {
1132 counter = 0;
1133 break;
1135 /* we waited 8 iterations, no luck. Sleep 8 ms */
1136 acx_s_mdelay(8);
1138 } while (likely(--counter));
1140 /* save state for debugging */
1141 cmd_status = acxpci_read_cmd_type_status(adev);
1143 /* put the card in IDLE state */
1144 acxpci_write_cmd_type_status(adev, 0, 0);
1146 if ((cmd_timeout - counter) == 0) { /* timed out! */
1147 printk("%s: " FUNC "(): timed out %s for CMD_COMPLETE. "
1148 "irq bits:0x%04X irq_status:0x%04X timeout:%dms "
1149 "cmd_status:%d (%s)\n",
1150 devname, (adev->irqs_active) ? "waiting" : "polling",
1151 irqtype, adev->irq_status, cmd_timeout,
1152 cmd_status, acx_cmd_status_str(cmd_status));
1153 printk("hack: don't do: 'goto bad;'\ncounter: %d cmd_timeout: %d cmd_timeout-counter: %d\n",counter, cmd_timeout, cmd_timeout - counter);
1154 } else if (counter == 0) { /* maybe timed out! */
1155 log(L_CTL | L_DEBUG, FUNC "(): %s for CMD_COMPLETE %dms. "
1156 "count:%d. Please report\n",
1157 (adev->irqs_active) ? "waited" : "polled",
1158 cmd_timeout - counter, counter);
1159 } else if ((cmd_timeout - counter) > 30) { /* if waited >30ms... */
1160 log(L_CTL | L_DEBUG, FUNC "(): %s for CMD_COMPLETE %dms. "
1161 "count:%d. Please report\n",
1162 (adev->irqs_active) ? "waited" : "polled",
1163 cmd_timeout - counter, counter);
1166 if (1 != cmd_status) { /* it is not a 'Success' */
1167 printk("%s: " FUNC "(): cmd_status is not SUCCESS: %d (%s). "
1168 "Took %dms of %d\n",
1169 devname, cmd_status, acx_cmd_status_str(cmd_status),
1170 cmd_timeout - counter, cmd_timeout);
1171 /* zero out result buffer
1172 * WARNING: this will trash stack in case of illegally large input
1173 * length! */
1174 if (buffer && buflen)
1175 memset(buffer, 0, buflen);
1176 goto bad;
1179 /* read in result parameters if needed */
1180 if (buffer && buflen && (cmd == ACX1xx_CMD_INTERROGATE)) {
1181 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1182 memcpy_fromio(buffer, adev->cmd_area + 4, buflen);
1183 if (acx_debug & L_DEBUG) {
1184 printk("output buffer (len=%u): ", buflen);
1185 acx_dump_bytes(buffer, buflen);
1188 /* ok: */
1189 log(L_CTL, FUNC "(%s): took %ld jiffies to complete\n",
1190 cmdstr, jiffies - start);
1191 FN_EXIT1(OK);
1192 return OK;
1194 bad:
1195 /* Give enough info so that callers can avoid
1196 ** printing their own diagnostic messages */
1197 #if ACX_DEBUG
1198 printk("%s: " FUNC "(cmd:%s) FAILED\n", devname, cmdstr);
1199 #else
1200 printk("%s: " FUNC "(cmd:0x%04X) FAILED\n", devname, cmd);
1201 #endif
1202 dump_stack();
1203 FN_EXIT1(NOT_OK);
1204 return NOT_OK;
1208 /***********************************************************************
1210 #ifdef NONESSENTIAL_FEATURES
1211 typedef struct device_id {
1212 unsigned char id[6];
1213 char *descr;
1214 char *type;
1215 } device_id_t;
1217 static const device_id_t device_ids[] = {
1219 {'G', 'l', 'o', 'b', 'a', 'l'},
1220 NULL,
1221 NULL,
1224 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
1225 "uninitialized",
1226 "SpeedStream SS1021 or Gigafast WF721-AEX"},
1228 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85},
1229 "non-standard",
1230 "DrayTek Vigor 520"},
1232 {'?', '?', '?', '?', '?', '?'},
1233 "non-standard",
1234 "Level One WPC-0200"},
1236 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1237 "empty",
1238 "DWL-650+ variant"}
1241 static void acx_show_card_eeprom_id(acx_device_t * adev)
1243 unsigned char buffer[CARD_EEPROM_ID_SIZE];
1244 int i;
1246 FN_ENTER;
1248 memset(&buffer, 0, CARD_EEPROM_ID_SIZE);
1249 /* use direct EEPROM access */
1250 for (i = 0; i < CARD_EEPROM_ID_SIZE; i++) {
1251 if (OK != acxpci_read_eeprom_byte(adev,
1252 ACX100_EEPROM_ID_OFFSET + i,
1253 &buffer[i])) {
1254 printk("acx: reading EEPROM FAILED\n");
1255 break;
1259 for (i = 0; i < ARRAY_SIZE(device_ids); i++) {
1260 if (!memcmp(&buffer, device_ids[i].id, CARD_EEPROM_ID_SIZE)) {
1261 if (device_ids[i].descr) {
1262 printk("acx: EEPROM card ID string check "
1263 "found %s card ID: is this %s?\n",
1264 device_ids[i].descr, device_ids[i].type);
1266 break;
1269 if (i == ARRAY_SIZE(device_ids)) {
1270 printk("acx: EEPROM card ID string check found "
1271 "unknown card: expected 'Global', got '%.*s\'. "
1272 "Please report\n", CARD_EEPROM_ID_SIZE, buffer);
1274 FN_EXIT0;
1276 #endif /* NONESSENTIAL_FEATURES */
1279 /***********************************************************************
1280 ** acxpci_free_desc_queues
1282 ** Releases the queues that have been allocated, the
1283 ** others have been initialised to NULL so this
1284 ** function can be used if only part of the queues were allocated.
1287 static inline void
1288 free_coherent(struct pci_dev *hwdev, size_t size,
1289 void *vaddr, dma_addr_t dma_handle)
1291 dma_free_coherent(hwdev == NULL ? NULL : &hwdev->dev,
1292 size, vaddr, dma_handle);
1296 void acxpci_free_desc_queues(acx_device_t * adev)
1298 #define ACX_FREE_QUEUE(size, ptr, phyaddr) \
1299 if (ptr) { \
1300 free_coherent(NULL, size, ptr, phyaddr); \
1301 ptr = NULL; \
1302 size = 0; \
1305 FN_ENTER;
1307 ACX_FREE_QUEUE(adev->txhostdesc_area_size, adev->txhostdesc_start,
1308 adev->txhostdesc_startphy);
1309 ACX_FREE_QUEUE(adev->txbuf_area_size, adev->txbuf_start,
1310 adev->txbuf_startphy);
1312 adev->txdesc_start = NULL;
1314 ACX_FREE_QUEUE(adev->rxhostdesc_area_size, adev->rxhostdesc_start,
1315 adev->rxhostdesc_startphy);
1316 ACX_FREE_QUEUE(adev->rxbuf_area_size, adev->rxbuf_start,
1317 adev->rxbuf_startphy);
1319 adev->rxdesc_start = NULL;
1321 FN_EXIT0;
1325 /***********************************************************************
1326 ** acxpci_s_delete_dma_regions
1328 static void acxpci_s_delete_dma_regions(acx_device_t * adev)
1330 unsigned long flags;
1332 FN_ENTER;
1333 /* disable radio Tx/Rx. Shouldn't we use the firmware commands
1334 * here instead? Or are we that much down the road that it's no
1335 * longer possible here? */
1336 write_reg16(adev, IO_ACX_ENABLE, 0);
1338 acx_s_mdelay(100);
1340 acx_lock(adev, flags);
1341 acxpci_free_desc_queues(adev);
1342 acx_unlock(adev, flags);
1344 FN_EXIT0;
1348 /***********************************************************************
1349 ** acxpci_e_probe
1351 ** Probe routine called when a PCI device w/ matching ID is found.
1352 ** Here's the sequence:
1353 ** - Allocate the PCI resources.
1354 ** - Read the PCMCIA attribute memory to make sure we have a WLAN card
1355 ** - Reset the MAC
1356 ** - Initialize the dev and wlan data
1357 ** - Initialize the MAC
1359 ** pdev - ptr to pci device structure containing info about pci configuration
1360 ** id - ptr to the device id entry that matched this device
1362 static const u16 IO_ACX100[] = {
1363 0x0000, /* IO_ACX_SOFT_RESET */
1365 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1366 0x0018, /* IO_ACX_SLV_MEM_DATA */
1367 0x001c, /* IO_ACX_SLV_MEM_CTL */
1368 0x0020, /* IO_ACX_SLV_END_CTL */
1370 0x0034, /* IO_ACX_FEMR */
1372 0x007c, /* IO_ACX_INT_TRIG */
1373 0x0098, /* IO_ACX_IRQ_MASK */
1374 0x00a4, /* IO_ACX_IRQ_STATUS_NON_DES */
1375 0x00a8, /* IO_ACX_IRQ_STATUS_CLEAR */
1376 0x00ac, /* IO_ACX_IRQ_ACK */
1377 0x00b0, /* IO_ACX_HINT_TRIG */
1379 0x0104, /* IO_ACX_ENABLE */
1381 0x0250, /* IO_ACX_EEPROM_CTL */
1382 0x0254, /* IO_ACX_EEPROM_ADDR */
1383 0x0258, /* IO_ACX_EEPROM_DATA */
1384 0x025c, /* IO_ACX_EEPROM_CFG */
1386 0x0268, /* IO_ACX_PHY_ADDR */
1387 0x026c, /* IO_ACX_PHY_DATA */
1388 0x0270, /* IO_ACX_PHY_CTL */
1390 0x0290, /* IO_ACX_GPIO_OE */
1392 0x0298, /* IO_ACX_GPIO_OUT */
1394 0x02a4, /* IO_ACX_CMD_MAILBOX_OFFS */
1395 0x02a8, /* IO_ACX_INFO_MAILBOX_OFFS */
1396 0x02ac, /* IO_ACX_EEPROM_INFORMATION */
1398 0x02d0, /* IO_ACX_EE_START */
1399 0x02d4, /* IO_ACX_SOR_CFG */
1400 0x02d8 /* IO_ACX_ECPU_CTRL */
1403 static const u16 IO_ACX111[] = {
1404 0x0000, /* IO_ACX_SOFT_RESET */
1406 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1407 0x0018, /* IO_ACX_SLV_MEM_DATA */
1408 0x001c, /* IO_ACX_SLV_MEM_CTL */
1409 0x0020, /* IO_ACX_SLV_END_CTL */
1411 0x0034, /* IO_ACX_FEMR */
1413 0x00b4, /* IO_ACX_INT_TRIG */
1414 0x00d4, /* IO_ACX_IRQ_MASK */
1415 /* we do mean NON_DES (0xf0), not NON_DES_MASK which is at 0xe0: */
1416 0x00f0, /* IO_ACX_IRQ_STATUS_NON_DES */
1417 0x00e4, /* IO_ACX_IRQ_STATUS_CLEAR */
1418 0x00e8, /* IO_ACX_IRQ_ACK */
1419 0x00ec, /* IO_ACX_HINT_TRIG */
1421 0x01d0, /* IO_ACX_ENABLE */
1423 0x0338, /* IO_ACX_EEPROM_CTL */
1424 0x033c, /* IO_ACX_EEPROM_ADDR */
1425 0x0340, /* IO_ACX_EEPROM_DATA */
1426 0x0344, /* IO_ACX_EEPROM_CFG */
1428 0x0350, /* IO_ACX_PHY_ADDR */
1429 0x0354, /* IO_ACX_PHY_DATA */
1430 0x0358, /* IO_ACX_PHY_CTL */
1432 0x0374, /* IO_ACX_GPIO_OE */
1434 0x037c, /* IO_ACX_GPIO_OUT */
1436 0x0388, /* IO_ACX_CMD_MAILBOX_OFFS */
1437 0x038c, /* IO_ACX_INFO_MAILBOX_OFFS */
1438 0x0390, /* IO_ACX_EEPROM_INFORMATION */
1440 0x0100, /* IO_ACX_EE_START */
1441 0x0104, /* IO_ACX_SOR_CFG */
1442 0x0108, /* IO_ACX_ECPU_CTRL */
1445 static const struct ieee80211_ops acxpci_hw_ops = {
1446 .tx = acx_i_start_xmit,
1447 .conf_tx = acx_net_conf_tx,
1448 .add_interface = acx_add_interface,
1449 .remove_interface = acx_remove_interface,
1450 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
1451 .open = acxpci_e_open,
1452 #else
1453 .start = acxpci_e_open,
1454 #endif
1455 .stop = acxpci_e_close,
1456 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
1457 .reset = acx_net_reset,
1458 #endif
1459 .config = acx_net_config,
1460 .config_interface = acx_config_interface,
1461 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
1462 .set_multicast_list = acx_i_set_multicast_list,
1463 #else
1464 .configure_filter = acx_i_set_multicast_list,
1465 #endif
1466 .set_key = acx_net_set_key,
1467 .get_stats = acx_e_get_stats,
1468 .get_tx_stats = acx_net_get_tx_stats,
1472 static int __devinit
1473 acxpci_e_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1475 acx111_ie_configoption_t co;
1476 unsigned long mem_region1 = 0;
1477 unsigned long mem_region2 = 0;
1478 unsigned long mem_region1_size;
1479 unsigned long mem_region2_size;
1480 unsigned long phymem1;
1481 unsigned long phymem2;
1482 void *mem1 = NULL;
1483 void *mem2 = NULL;
1484 acx_device_t *adev = NULL;
1485 const char *chip_name;
1486 int result = -EIO;
1487 int err;
1488 u8 chip_type;
1489 struct ieee80211_hw *ieee;
1491 FN_ENTER;
1493 ieee = ieee80211_alloc_hw(sizeof(struct acx_device), &acxpci_hw_ops);
1494 if (!ieee) {
1495 printk("acx: could not allocate ieee80211 structure %s\n",
1496 pci_name(pdev));
1497 goto fail_alloc_netdev;
1499 ieee->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
1500 ieee->queues = 1;
1502 /* (NB: memsets to 0 entire area) */
1503 if (!ieee) {
1504 printk("acx: could not allocate ieee structure %s\n",
1505 pci_name(pdev));
1506 goto fail_alloc_netdev;
1509 adev = ieee2adev(ieee);
1511 memset(adev, 0, sizeof(*adev));
1512 /** Set up our private interface **/
1513 spin_lock_init(&adev->lock); /* initial state: unlocked */
1514 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
1515 printk("mutex_init(&adev->mutex); // adev = 0x%px\n", adev);
1516 mutex_init(&adev->mutex);
1517 /* since nobody can see new netdev yet, we can as well
1518 ** just _presume_ that we're under sem (instead of actually taking it): */
1519 /* acx_sem_lock(adev); */
1520 adev->ieee = ieee;
1521 adev->pdev = pdev;
1522 adev->dev_type = DEVTYPE_PCI;
1524 /** Finished with private interface **/
1526 /** begin board specific inits **/
1527 pci_set_drvdata(pdev, ieee);
1529 /* Enable the PCI device */
1530 if (pci_enable_device(pdev)) {
1531 printk("acx: pci_enable_device() FAILED\n");
1532 result = -ENODEV;
1533 goto fail_pci_enable_device;
1536 /* enable busmastering (required for CardBus) */
1537 pci_set_master(pdev);
1540 /* chiptype is u8 but id->driver_data is ulong
1541 ** Works for now (possible values are 1 and 2) */
1542 chip_type = (u8) id->driver_data;
1543 /* acx100 and acx111 have different PCI memory regions */
1544 if (chip_type == CHIPTYPE_ACX100) {
1545 chip_name = "ACX100";
1546 mem_region1 = PCI_ACX100_REGION1;
1547 mem_region1_size = PCI_ACX100_REGION1_SIZE;
1549 mem_region2 = PCI_ACX100_REGION2;
1550 mem_region2_size = PCI_ACX100_REGION2_SIZE;
1551 } else if (chip_type == CHIPTYPE_ACX111) {
1552 chip_name = "ACX111";
1553 mem_region1 = PCI_ACX111_REGION1;
1554 mem_region1_size = PCI_ACX111_REGION1_SIZE;
1556 mem_region2 = PCI_ACX111_REGION2;
1557 mem_region2_size = PCI_ACX111_REGION2_SIZE;
1558 } else {
1559 printk("acx: unknown chip type 0x%04X\n", chip_type);
1560 goto fail_unknown_chiptype;
1563 /* Figure out our resources */
1564 phymem1 = pci_resource_start(pdev, mem_region1);
1565 phymem2 = pci_resource_start(pdev, mem_region2);
1566 if (!request_mem_region
1567 (phymem1, pci_resource_len(pdev, mem_region1), "acx_1")) {
1568 printk("acx: cannot reserve PCI memory region 1 (are you sure "
1569 "you have CardBus support in kernel?)\n");
1570 goto fail_request_mem_region1;
1572 if (!request_mem_region
1573 (phymem2, pci_resource_len(pdev, mem_region2), "acx_2")) {
1574 printk("acx: cannot reserve PCI memory region 2\n");
1575 goto fail_request_mem_region2;
1577 /* this used to be ioremap(), but ioremap_nocache()
1578 * is much less risky, right? (and slower?)
1579 * FIXME: we may want to go back to cached variant if it's
1580 * certain that our code really properly handles
1581 * cached operation (memory barriers, volatile?, ...)
1582 * (but always keep this comment here regardless!)
1583 * Possibly make this a driver config setting?
1586 mem1 = ioremap_nocache(phymem1, mem_region1_size);
1587 if (!mem1) {
1588 printk("acx: ioremap() FAILED\n");
1589 goto fail_ioremap1;
1591 mem2 = ioremap_nocache(phymem2, mem_region2_size);
1592 if (!mem2) {
1593 printk("acx: ioremap() #2 FAILED\n");
1594 goto fail_ioremap2;
1597 printk("acx: found %s-based wireless network card at %s, irq:%d, "
1598 "phymem1:0x%lX, phymem2:0x%lX, mem1:0x%p, mem1_size:%ld, "
1599 "mem2:0x%p, mem2_size:%ld\n",
1600 chip_name, pci_name(pdev), pdev->irq, phymem1, phymem2,
1601 mem1, mem_region1_size, mem2, mem_region2_size);
1602 log(L_ANY, "initial debug setting is 0x%04X\n", acx_debug);
1603 adev->chip_type = chip_type;
1604 adev->chip_name = chip_name;
1605 adev->io = (CHIPTYPE_ACX100 == chip_type) ? IO_ACX100 : IO_ACX111;
1606 adev->membase = phymem1;
1607 adev->iobase = mem1;
1608 adev->membase2 = phymem2;
1609 adev->iobase2 = mem2;
1610 adev->irq = pdev->irq;
1613 if (0 == pdev->irq) {
1614 printk("acx: can't use IRQ 0\n");
1615 goto fail_irq;
1617 SET_IEEE80211_DEV(ieee, &pdev->dev);
1620 /* to find crashes due to weird driver access
1621 * to unconfigured interface (ifup) */
1622 adev->mgmt_timer.function = (void (*)(unsigned long))0x0000dead;
1625 #ifdef NONESSENTIAL_FEATURES
1626 acx_show_card_eeprom_id(adev);
1627 #endif /* NONESSENTIAL_FEATURES */
1630 /* ok, pci setup is finished, now start initializing the card */
1632 /* NB: read_reg() reads may return bogus data before reset_dev(),
1633 * since the firmware which directly controls large parts of the I/O
1634 * registers isn't initialized yet.
1635 * acx100 seems to be more affected than acx111 */
1636 if (OK != acxpci_s_reset_dev(adev))
1637 goto fail_reset;
1639 if (IS_ACX100(adev)) {
1640 /* ACX100: configopt struct in cmd mailbox - directly after reset */
1641 memcpy_fromio(&co, adev->cmd_area, sizeof(co));
1644 if (OK != acx_s_init_mac(adev))
1645 goto fail_init_mac;
1647 if (IS_ACX111(adev)) {
1648 /* ACX111: configopt struct needs to be queried after full init */
1649 acx_s_interrogate(adev, &co, ACX111_IE_CONFIG_OPTIONS);
1651 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
1652 if (OK != acxpci_read_eeprom_byte(adev, 0x05, &adev->eeprom_version))
1653 goto fail_read_eeprom_version;
1655 acx_s_parse_configoption(adev, &co);
1656 acx_s_set_defaults(adev);
1657 acx_s_get_firmware_version(adev); /* needs to be after acx_s_init_mac() */
1658 acx_display_hardware_details(adev);
1660 /* Register the card, AFTER everything else has been set up,
1661 * since otherwise an ioctl could step on our feet due to
1662 * firmware operations happening in parallel or uninitialized data */
1665 acx_proc_register_entries(ieee);
1667 /* Now we have our device, so make sure the kernel doesn't try
1668 * to send packets even though we're not associated to a network yet */
1670 /* after register_netdev() userspace may start working with dev
1671 * (in particular, on other CPUs), we only need to up the sem */
1672 /* acx_sem_unlock(adev); */
1674 printk("acx " ACX_RELEASE ": net device %s, driver compiled "
1675 "against wireless extensions %d and Linux %s\n",
1676 wiphy_name(adev->ieee->wiphy), WIRELESS_EXT, UTS_RELEASE);
1678 MAC_COPY(adev->ieee->wiphy->perm_addr, adev->dev_addr);
1680 log(L_IRQ | L_INIT, "using IRQ %d\n", pdev->irq);
1682 /** done with board specific setup **/
1684 /* need to be able to restore PCI state after a suspend */
1685 #ifdef CONFIG_PM
1686 pci_save_state(pdev);
1687 #endif
1690 acx_init_task_scheduler(adev);
1691 err = ieee80211_register_hw(adev->ieee);
1692 if (OK != err) {
1693 printk("acx: ieee80211_register_hw() FAILED: %d\n", err);
1694 goto fail_register_netdev;
1696 #if CMD_DISCOVERY
1697 great_inquisitor(adev);
1698 #endif
1700 result = OK;
1701 goto done;
1703 /* error paths: undo everything in reverse order... */
1706 acxpci_s_delete_dma_regions(adev);
1707 pci_set_drvdata(pdev, NULL);
1709 fail_init_mac:
1710 fail_read_eeprom_version:
1711 fail_reset:
1713 fail_alloc_netdev:
1714 fail_irq:
1716 iounmap(mem2);
1717 fail_ioremap2:
1719 iounmap(mem1);
1720 fail_ioremap1:
1722 release_mem_region(pci_resource_start(pdev, mem_region2),
1723 pci_resource_len(pdev, mem_region2));
1724 fail_request_mem_region2:
1726 release_mem_region(pci_resource_start(pdev, mem_region1),
1727 pci_resource_len(pdev, mem_region1));
1728 fail_request_mem_region1:
1729 fail_unknown_chiptype:
1731 pci_disable_device(pdev);
1732 fail_pci_enable_device:
1734 #ifdef CONFIG_PM
1735 pci_set_power_state(pdev, PCI_D3hot);
1736 #endif
1737 fail_register_netdev:
1738 ieee80211_free_hw(ieee);
1739 done:
1740 FN_EXIT1(result);
1741 return result;
1745 /***********************************************************************
1746 ** acxpci_e_remove
1748 ** Shut device down (if not hot unplugged)
1749 ** and deallocate PCI resources for the acx chip.
1751 ** pdev - ptr to PCI device structure containing info about pci configuration
1753 static void __devexit acxpci_e_remove(struct pci_dev *pdev)
1755 struct ieee80211_hw *hw = (struct ieee80211_hw *)pci_get_drvdata(pdev);
1756 acx_device_t *adev = ieee2adev(hw);
1757 unsigned long mem_region1, mem_region2;
1758 unsigned long flags;
1759 FN_ENTER;
1761 if (!hw) {
1762 log(L_DEBUG, "%s: card is unused. Skipping any release code\n",
1763 __func__);
1764 goto end;
1768 acx_lock(adev, flags);
1769 acx_unlock(adev, flags);
1770 adev->initialized = 0;
1772 /* If device wasn't hot unplugged... */
1773 if (adev_present(adev)) {
1775 acx_sem_lock(adev);
1777 /* disable both Tx and Rx to shut radio down properly */
1778 if (adev->initialized) {
1779 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_TX, NULL, 0);
1780 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_RX, NULL, 0);
1782 #ifdef REDUNDANT
1783 /* put the eCPU to sleep to save power
1784 * Halting is not possible currently,
1785 * since not supported by all firmware versions */
1786 acx_s_issue_cmd(adev, ACX100_CMD_SLEEP, NULL, 0);
1787 #endif
1788 acx_lock(adev, flags);
1789 /* disable power LED to save power :-) */
1790 log(L_INIT, "switching off power LED to save power\n");
1791 acxpci_l_power_led(adev, 0);
1792 /* stop our eCPU */
1793 if (IS_ACX111(adev)) {
1794 /* FIXME: does this actually keep halting the eCPU?
1795 * I don't think so...
1797 acxpci_l_reset_mac(adev);
1798 } else {
1799 u16 temp;
1800 /* halt eCPU */
1801 temp = read_reg16(adev, IO_ACX_ECPU_CTRL) | 0x1;
1802 write_reg16(adev, IO_ACX_ECPU_CTRL, temp);
1803 write_flush(adev);
1805 acx_unlock(adev, flags);
1807 acx_sem_unlock(adev);
1810 /* unregister the device to not let the kernel
1811 * (e.g. ioctls) access a half-deconfigured device
1812 * NB: this will cause acxpci_e_close() to be called,
1813 * thus we shouldn't call it under sem!
1814 * Well, netdev did, but ieee80211 stack does not, so we
1815 * have to do so manually...
1817 acxpci_e_close(hw);
1818 log(L_INIT, "removing device %s\n", wiphy_name(adev->ieee->wiphy));
1819 ieee80211_unregister_hw(adev->ieee);
1821 /* unregister_netdev ensures that no references to us left.
1822 * For paranoid reasons we continue to follow the rules */
1823 acx_sem_lock(adev);
1825 if (adev->dev_state_mask & ACX_STATE_IFACE_UP) {
1826 acxpci_s_down(hw);
1827 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
1830 acx_proc_unregister_entries(adev->ieee);
1832 if (IS_ACX100(adev)) {
1833 mem_region1 = PCI_ACX100_REGION1;
1834 mem_region2 = PCI_ACX100_REGION2;
1835 } else {
1836 mem_region1 = PCI_ACX111_REGION1;
1837 mem_region2 = PCI_ACX111_REGION2;
1840 /* finally, clean up PCI bus state */
1841 acxpci_s_delete_dma_regions(adev);
1842 if (adev->iobase)
1843 iounmap(adev->iobase);
1844 if (adev->iobase2)
1845 iounmap(adev->iobase2);
1846 release_mem_region(pci_resource_start(pdev, mem_region1),
1847 pci_resource_len(pdev, mem_region1));
1848 release_mem_region(pci_resource_start(pdev, mem_region2),
1849 pci_resource_len(pdev, mem_region2));
1850 pci_disable_device(pdev);
1852 /* remove dev registration */
1854 free_irq(adev->irq, adev);
1855 acx_sem_unlock(adev);
1857 /* Free netdev (quite late,
1858 * since otherwise we might get caught off-guard
1859 * by a netdev timeout handler execution
1860 * expecting to see a working dev...) */
1861 ieee80211_free_hw(adev->ieee);
1863 /* put device into ACPI D3 mode (shutdown) */
1864 #ifdef CONFIG_PM
1865 pci_set_power_state(pdev, PCI_D3hot);
1866 #endif
1867 end:
1868 FN_EXIT0;
1872 /***********************************************************************
1873 ** TODO: PM code needs to be fixed / debugged / tested.
1875 #ifdef CONFIG_PM
1876 static int
1877 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
1878 acxpci_e_suspend(struct pci_dev *pdev, pm_message_t state)
1879 #else
1880 acxpci_e_suspend(struct pci_dev *pdev, u32 state)
1881 #endif
1883 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1884 acx_device_t *adev;
1886 FN_ENTER;
1887 printk("acx: suspend handler is experimental!\n");
1888 printk("sus: dev %p\n", hw);
1890 /* if (!netif_running(ndev))
1891 goto end;
1893 adev = ieee2adev(hw);
1894 printk("sus: adev %p\n", adev);
1896 acx_sem_lock(adev);
1898 ieee80211_unregister_hw(hw); /* this one cannot sleep */
1899 acxpci_s_down(hw);
1900 /* down() does not set it to 0xffff, but here we really want that */
1901 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
1902 write_reg16(adev, IO_ACX_FEMR, 0x0);
1903 acxpci_s_delete_dma_regions(adev);
1904 pci_save_state(pdev);
1905 pci_set_power_state(pdev, PCI_D3hot);
1907 acx_sem_unlock(adev);
1908 FN_EXIT0;
1909 return OK;
1913 static int acxpci_e_resume(struct pci_dev *pdev)
1915 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1916 acx_device_t *adev;
1918 FN_ENTER;
1920 printk("acx: resume handler is experimental!\n");
1921 printk("rsm: got dev %p\n", hw);
1924 adev = ieee2adev(hw);
1925 printk("rsm: got adev %p\n", adev);
1927 acx_sem_lock(adev);
1929 pci_set_power_state(pdev, PCI_D0);
1930 printk("rsm: power state PCI_D0 set\n");
1931 pci_restore_state(pdev);
1932 printk("rsm: PCI state restored\n");
1934 if (OK != acxpci_s_reset_dev(adev))
1935 goto end_unlock;
1936 printk("rsm: device reset done\n");
1937 if (OK != acx_s_init_mac(adev))
1938 goto end_unlock;
1939 printk("rsm: init MAC done\n");
1941 acxpci_s_up(hw);
1942 printk("rsm: acx up done\n");
1944 /* now even reload all card parameters as they were before suspend,
1945 * and possibly be back in the network again already :-) */
1946 if (ACX_STATE_IFACE_UP & adev->dev_state_mask) {
1947 adev->set_mask = GETSET_ALL;
1948 acx_s_update_card_settings(adev);
1949 printk("rsm: settings updated\n");
1951 ieee80211_register_hw(hw);
1952 printk("rsm: device attached\n");
1954 end_unlock:
1955 acx_sem_unlock(adev);
1956 /* we need to return OK here anyway, right? */
1957 FN_EXIT0;
1958 return OK;
1960 #endif /* CONFIG_PM */
1963 /***********************************************************************
1964 ** acxpci_s_up
1966 ** This function is called by acxpci_e_open (when ifconfig sets the device as up)
1968 ** Side effects:
1969 ** - Enables on-card interrupt requests
1970 ** - calls acx_s_start
1973 static void enable_acx_irq(acx_device_t * adev)
1975 FN_ENTER;
1976 write_reg16(adev, IO_ACX_IRQ_MASK, adev->irq_mask);
1977 write_reg16(adev, IO_ACX_FEMR, 0x8000);
1978 adev->irqs_active = 1;
1979 FN_EXIT0;
1982 static void acxpci_s_up(struct ieee80211_hw *hw)
1984 acx_device_t *adev = ieee2adev(hw);
1985 unsigned long flags;
1987 FN_ENTER;
1989 acx_lock(adev, flags);
1990 enable_acx_irq(adev);
1991 acx_unlock(adev, flags);
1993 /* acx fw < 1.9.3.e has a hardware timer, and older drivers
1994 ** used to use it. But we don't do that anymore, our OS
1995 ** has reliable software timers */
1996 init_timer(&adev->mgmt_timer);
1997 adev->mgmt_timer.function = acx_i_timer;
1998 adev->mgmt_timer.data = (unsigned long)adev;
2000 /* Need to set ACX_STATE_IFACE_UP first, or else
2001 ** timer won't be started by acx_set_status() */
2002 SET_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
2004 acx_s_start(adev);
2006 FN_EXIT0;
2010 /***********************************************************************
2011 ** acxpci_s_down
2013 ** NB: device may be already hot unplugged if called from acxpci_e_remove()
2015 ** Disables on-card interrupt request, stops softirq and timer, stops queue,
2016 ** sets status == STOPPED
2019 static void disable_acx_irq(acx_device_t * adev)
2021 FN_ENTER;
2023 /* I guess mask is not 0xffff because acx100 won't signal
2024 ** cmd completion then (needed for ifup).
2025 ** Someone with acx100 please confirm */
2026 write_reg16(adev, IO_ACX_IRQ_MASK, adev->irq_mask_off);
2027 write_reg16(adev, IO_ACX_FEMR, 0x0);
2028 adev->irqs_active = 0;
2029 FN_EXIT0;
2032 static void acxpci_s_down(struct ieee80211_hw *hw)
2034 acx_device_t *adev = ieee2adev(hw);
2035 unsigned long flags;
2037 FN_ENTER;
2039 /* Disable IRQs first, so that IRQs cannot race with us */
2040 /* then wait until interrupts have finished executing on other CPUs */
2041 printk("acxpci_s_down: acx_lock()\n");
2042 acx_s_mdelay(1000);
2043 acx_lock(adev, flags);
2044 disable_acx_irq(adev);
2045 synchronize_irq(adev->pdev->irq);
2046 printk("acxpci_s_down: acx_unlock()\n");
2047 acx_s_mdelay(1000);
2048 acx_unlock(adev, flags);
2050 /* we really don't want to have an asynchronous tasklet disturb us
2051 ** after something vital for its job has been shut down, so
2052 ** end all remaining work now.
2054 ** NB: carrier_off (done by set_status below) would lead to
2055 ** not yet fully understood deadlock in flush_scheduled_work().
2056 ** That's why we do FLUSH first.
2058 ** NB2: we have a bad locking bug here: flush_scheduled_work()
2059 ** waits for acx_e_after_interrupt_task to complete if it is running
2060 ** on another CPU, but acx_e_after_interrupt_task
2061 ** will sleep on sem forever, because it is taken by us!
2062 ** Work around that by temporary sem unlock.
2063 ** This will fail miserably if we'll be hit by concurrent
2064 ** iwconfig or something in between. TODO! */
2065 printk("acxpci_s_down: flush_scheduled_work()\n");
2066 acx_s_mdelay(1000);
2067 flush_scheduled_work();
2069 /* This is possible:
2070 ** flush_scheduled_work -> acx_e_after_interrupt_task ->
2071 ** -> set_status(ASSOCIATED) -> wake_queue()
2072 ** That's why we stop queue _after_ flush_scheduled_work
2073 ** lock/unlock is just paranoia, maybe not needed */
2075 /* kernel/timer.c says it's illegal to del_timer_sync()
2076 ** a timer which restarts itself. We guarantee this cannot
2077 ** ever happen because acx_i_timer() never does this if
2078 ** status is ACX_STATUS_0_STOPPED */
2079 printk("acxpci_s_down: del_timer_sync()\n");
2080 acx_s_mdelay(1000);
2081 del_timer_sync(&adev->mgmt_timer);
2083 FN_EXIT0;
2086 #ifdef CONFIG_NET_POLL_CONTROLLER
2087 void acxpci_net_poll_controller(struct net_device *net_dev)
2089 acx_device_t *adev = ndev2adev(net_dev);
2090 unsigned long flags;
2092 local_irq_save(flags);
2093 acxpci_i_interrupt(adev->irq, adev);
2094 local_irq_restore(flags);
2096 #endif*/ /* CONFIG_NET_POLL_CONTROLLER */
2098 /***********************************************************************
2099 ** acxpci_e_open
2101 ** Called as a result of SIOCSIFFLAGS ioctl changing the flags bit IFF_UP
2102 ** from clear to set. In other words: ifconfig up.
2104 ** Returns:
2105 ** 0 success
2106 ** >0 f/w reported error
2107 ** <0 driver reported error
2109 static int acxpci_e_open(struct ieee80211_hw *hw)
2111 acx_device_t *adev = ieee2adev(hw);
2112 int result = OK;
2114 FN_ENTER;
2116 acx_sem_lock(adev);
2118 adev->initialized = 0;
2120 /* TODO: pci_set_power_state(pdev, PCI_D0); ? */
2122 /* request shared IRQ handler */
2123 if (request_irq
2124 (adev->irq, acxpci_i_interrupt, IRQF_SHARED, KBUILD_MODNAME, adev)) {
2125 printk("%s: request_irq FAILED\n", wiphy_name(adev->ieee->wiphy));
2126 result = -EAGAIN;
2127 goto done;
2129 log(L_DEBUG | L_IRQ, "request_irq %d successful\n", adev->irq);
2131 /* ifup device */
2132 acxpci_s_up(hw);
2134 /* We don't currently have to do anything else.
2135 * The setup of the MAC should be subsequently completed via
2136 * the mlme commands.
2137 * Higher layers know we're ready from dev->start==1 and
2138 * dev->tbusy==0. Our rx path knows to pass up received/
2139 * frames because of dev->flags&IFF_UP is true.
2141 acx_setup_modes(adev);
2142 ieee80211_start_queues(adev->ieee);
2144 adev->initialized = 1;
2145 done:
2146 acx_sem_unlock(adev);
2148 FN_EXIT1(result);
2149 return result;
2153 /***********************************************************************
2154 ** acxpci_e_close
2156 ** This function stops the network functionality of the interface (invoked
2157 ** when the user calls ifconfig <wlan> down). The tx queue is halted and
2158 ** the device is marked as down.
2160 ** Called as a result of SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
2161 ** from set to clear. I.e. called by "ifconfig DEV down"
2163 ** Returns:
2164 ** 0 success
2165 ** >0 f/w reported error
2166 ** <0 driver reported error
2168 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
2169 static int acxpci_e_close(struct ieee80211_hw *hw)
2170 #else
2171 static void acxpci_e_close(struct ieee80211_hw *hw)
2172 #endif
2174 acx_device_t *adev = ieee2adev(hw);
2175 unsigned long flags;
2176 FN_ENTER;
2177 printk("putting interface DOWN - this is filled with printk's and will take 8-10 seconds!\n");
2178 printk("acxpci_e_close: acx_lock()\n");
2179 acx_s_mdelay(1000);
2180 acx_lock(adev,flags);
2181 /* ifdown device */
2182 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
2183 if (adev->initialized) {
2184 printk("acxpci_e_close: acxpci_s_down()\n");
2185 acx_s_mdelay(1000);
2186 acxpci_s_down(hw);
2189 if (adev->modes)
2190 acx_free_modes(adev);
2191 /* disable all IRQs, release shared IRQ handler */
2192 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
2193 write_reg16(adev, IO_ACX_FEMR, 0x0);
2195 /* TODO: pci_set_power_state(pdev, PCI_D3hot); ? */
2197 /* We currently don't have to do anything else.
2198 * Higher layers know we're not ready from dev->start==0 and
2199 * dev->tbusy==1. Our rx path knows to not pass up received
2200 * frames because of dev->flags&IFF_UP is false.
2202 printk("acxpci_e_close: acx_unlock()\n");
2203 acx_s_mdelay(1000);
2204 acx_unlock(adev,flags);
2206 log(L_INIT, "closed device\n");
2207 FN_EXIT0;
2208 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
2209 return OK;
2210 #else
2211 #endif
2217 /***************************************************************
2218 ** acxpci_l_process_rxdesc
2220 ** Called directly and only from the IRQ handler
2223 #if !ACX_DEBUG
2224 static inline void log_rxbuffer(const acx_device_t * adev)
2227 #else
2228 static void log_rxbuffer(const acx_device_t * adev)
2230 register const struct rxhostdesc *rxhostdesc;
2231 int i;
2233 /* no FN_ENTER here, we don't want that */
2235 rxhostdesc = adev->rxhostdesc_start;
2236 if (unlikely(!rxhostdesc))
2237 return;
2238 for (i = 0; i < RX_CNT; i++) {
2239 if ((rxhostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2240 && (rxhostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2241 printk("rx: buf %d full\n", i);
2242 rxhostdesc++;
2245 #endif
2247 static void acxpci_l_process_rxdesc(acx_device_t * adev)
2249 register rxhostdesc_t *hostdesc;
2250 unsigned count, tail;
2252 FN_ENTER;
2254 if (unlikely(acx_debug & L_BUFR))
2255 log_rxbuffer(adev);
2257 /* First, have a loop to determine the first descriptor that's
2258 * full, just in case there's a mismatch between our current
2259 * rx_tail and the full descriptor we're supposed to handle. */
2260 tail = adev->rx_tail;
2261 count = RX_CNT;
2262 while (1) {
2263 hostdesc = &adev->rxhostdesc_start[tail];
2264 /* advance tail regardless of outcome of the below test */
2265 tail = (tail + 1) % RX_CNT;
2267 if ((hostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2268 && (hostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2269 break; /* found it! */
2271 if (unlikely(!--count)) /* hmm, no luck: all descs empty, bail out */
2272 goto end;
2275 /* now process descriptors, starting with the first we figured out */
2276 while (1) {
2277 log(L_BUFR, "rx: tail=%u Ctl_16=%04X Status=%08X\n",
2278 tail, hostdesc->Ctl_16, hostdesc->Status);
2280 acx_l_process_rxbuf(adev, hostdesc->data);
2281 hostdesc->Status = 0;
2282 /* flush all writes before adapter sees CTL_HOSTOWN change */
2283 wmb();
2284 /* Host no longer owns this, needs to be LAST */
2285 CLEAR_BIT(hostdesc->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
2287 /* ok, descriptor is handled, now check the next descriptor */
2288 hostdesc = &adev->rxhostdesc_start[tail];
2290 /* if next descriptor is empty, then bail out */
2291 if (!(hostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2292 || !(hostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2293 break;
2295 tail = (tail + 1) % RX_CNT;
2297 end:
2298 adev->rx_tail = tail;
2299 FN_EXIT0;
2304 /***********************************************************************
2305 ** acxpci_i_interrupt
2307 ** IRQ handler (atomic context, must not sleep, blah, blah)
2310 /* scan is complete. all frames now on the receive queue are valid */
2311 #define INFO_SCAN_COMPLETE 0x0001
2312 #define INFO_WEP_KEY_NOT_FOUND 0x0002
2313 /* hw has been reset as the result of a watchdog timer timeout */
2314 #define INFO_WATCH_DOG_RESET 0x0003
2315 /* failed to send out NULL frame from PS mode notification to AP */
2316 /* recommended action: try entering 802.11 PS mode again */
2317 #define INFO_PS_FAIL 0x0004
2318 /* encryption/decryption process on a packet failed */
2319 #define INFO_IV_ICV_FAILURE 0x0005
2321 /* Info mailbox format:
2322 2 bytes: type
2323 2 bytes: status
2324 more bytes may follow
2325 rumors say about status:
2326 0x0000 info available (set by hw)
2327 0x0001 information received (must be set by host)
2328 0x1000 info available, mailbox overflowed (messages lost) (set by hw)
2329 but in practice we've seen:
2330 0x9000 when we did not set status to 0x0001 on prev message
2331 0x1001 when we did set it
2332 0x0000 was never seen
2333 conclusion: this is really a bitfield:
2334 0x1000 is 'info available' bit
2335 'mailbox overflowed' bit is 0x8000, not 0x1000
2336 value of 0x0000 probably means that there are no messages at all
2337 P.S. I dunno how in hell hw is supposed to notice that messages are lost -
2338 it does NOT clear bit 0x0001, and this bit will probably stay forever set
2339 after we set it once. Let's hope this will be fixed in firmware someday
2342 static void handle_info_irq(acx_device_t * adev)
2344 #if ACX_DEBUG
2345 static const char *const info_type_msg[] = {
2346 "(unknown)",
2347 "scan complete",
2348 "WEP key not found",
2349 "internal watchdog reset was done",
2350 "failed to send powersave (NULL frame) notification to AP",
2351 "encrypt/decrypt on a packet has failed",
2352 "TKIP tx keys disabled",
2353 "TKIP rx keys disabled",
2354 "TKIP rx: key ID not found",
2355 "???",
2356 "???",
2357 "???",
2358 "???",
2359 "???",
2360 "???",
2361 "???",
2362 "TKIP IV value exceeds thresh"
2364 #endif
2365 u32 info_type, info_status;
2367 info_type = acx_readl(adev->info_area);
2368 info_status = (info_type >> 16);
2369 info_type = (u16) info_type;
2371 /* inform fw that we have read this info message */
2372 acx_writel(info_type | 0x00010000, adev->info_area);
2373 write_reg16(adev, IO_ACX_INT_TRIG, INT_TRIG_INFOACK);
2374 write_flush(adev);
2376 log(L_CTL, "info_type:%04X info_status:%04X\n", info_type, info_status);
2378 log(L_IRQ, "got Info IRQ: status %04X type %04X: %s\n",
2379 info_status, info_type,
2380 info_type_msg[(info_type >= ARRAY_SIZE(info_type_msg)) ?
2381 0 : info_type]
2386 static void log_unusual_irq(u16 irqtype)
2389 if (!printk_ratelimit())
2390 return;
2393 printk("acx: got");
2394 if (irqtype & HOST_INT_RX_DATA) {
2395 printk(" Rx_Data");
2397 /* HOST_INT_TX_COMPLETE */
2398 if (irqtype & HOST_INT_TX_XFER) {
2399 printk(" Tx_Xfer");
2401 /* HOST_INT_RX_COMPLETE */
2402 if (irqtype & HOST_INT_DTIM) {
2403 printk(" DTIM");
2405 if (irqtype & HOST_INT_BEACON) {
2406 printk(" Beacon");
2408 if (irqtype & HOST_INT_TIMER) {
2409 log(L_IRQ, " Timer");
2411 if (irqtype & HOST_INT_KEY_NOT_FOUND) {
2412 printk(" Key_Not_Found");
2414 if (irqtype & HOST_INT_IV_ICV_FAILURE) {
2415 printk(" IV_ICV_Failure (crypto)");
2417 /* HOST_INT_CMD_COMPLETE */
2418 /* HOST_INT_INFO */
2419 if (irqtype & HOST_INT_OVERFLOW) {
2420 printk(" Overflow");
2422 if (irqtype & HOST_INT_PROCESS_ERROR) {
2423 printk(" Process_Error");
2425 /* HOST_INT_SCAN_COMPLETE */
2426 if (irqtype & HOST_INT_FCS_THRESHOLD) {
2427 printk(" FCS_Threshold");
2429 if (irqtype & HOST_INT_UNKNOWN) {
2430 printk(" Unknown");
2432 printk(" IRQ(s)\n");
2436 static void update_link_quality_led(acx_device_t * adev)
2438 /* int qual; */
2440 /* qual =
2441 acx_signal_determine_quality(adev->wstats.qual.level,
2442 adev->wstats.qual.noise);
2443 if (qual > adev->brange_max_quality)
2444 qual = adev->brange_max_quality;
2447 /* if (time_after(jiffies, adev->brange_time_last_state_change +
2448 (HZ / 2 -
2449 HZ / 2 * (unsigned long)qual /
2450 adev->brange_max_quality))) {
2451 acxpci_l_power_led(adev, (adev->brange_last_state == 0));
2452 adev->brange_last_state ^= 1; *//* toggle */
2453 /* adev->brange_time_last_state_change = jiffies;
2458 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* a la orinoco.c */
2460 /* Interrupt handler bottom-half */
2461 void acx_interrupt_tasklet(struct work_struct *work)
2464 #ifdef CONFIG_ACX_MAC80211_DEBUG
2465 u32 _handled = 0x00000000;
2466 # define acxirq_handled(irq) do { _handled |= (irq); } while (0)
2467 #else
2468 # define acxirq_handled(irq) do { /* nothing */ } while (0)
2469 #endif /* CONFIG_ACX_MAC80211_DEBUG */
2470 acx_device_t *adev = container_of(work,struct acx_device, after_interrupt_task);
2471 // unsigned int irqcount = MAX_IRQLOOPS_PER_JIFFY;
2472 int irqtype;
2474 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2475 * I am paranoid */
2476 acx_sem_lock(adev);
2479 FN_ENTER;
2480 irqtype = adev->irq_reason;
2481 adev->irq_reason = 0;
2483 #define IRQ_ITERATE 0
2484 #if IRQ_ITERATE
2485 if (jiffies != adev->irq_last_jiffies) {
2486 adev->irq_loops_this_jiffy = 0;
2487 adev->irq_last_jiffies = jiffies;
2490 /* safety condition; we'll normally abort loop below
2491 * in case no IRQ type occurred */
2492 while (likely(--irqcount)) {
2493 #endif
2494 /* ACK all IRQs ASAP */
2497 /* Handle most important IRQ types first */
2498 if (irqtype & HOST_INT_RX_COMPLETE) {
2499 log(L_IRQ, "got Rx_Complete IRQ\n");
2500 acxpci_l_process_rxdesc(adev);
2502 if (irqtype & HOST_INT_TX_COMPLETE) {
2503 log(L_IRQ, "got Tx_Complete IRQ\n");
2504 /* don't clean up on each Tx complete, wait a bit
2505 * unless we're going towards full, in which case
2506 * we do it immediately, too (otherwise we might lockup
2507 * with a full Tx buffer if we go into
2508 * acxpci_l_clean_txdesc() at a time when we won't wakeup
2509 * the net queue in there for some reason...) */
2510 // if (adev->tx_free <= TX_START_CLEAN) {
2511 acxpci_l_clean_txdesc(adev);
2512 // }
2515 /* Less frequent ones */
2516 if (irqtype & (0
2517 | HOST_INT_CMD_COMPLETE
2518 | HOST_INT_INFO | HOST_INT_SCAN_COMPLETE)) {
2519 if (irqtype & HOST_INT_INFO) {
2520 handle_info_irq(adev);
2522 if (irqtype & HOST_INT_SCAN_COMPLETE) {
2523 log(L_IRQ, "got Scan_Complete IRQ\n");
2524 /* need to do that in process context */
2525 /* remember that fw is not scanning anymore */
2526 SET_BIT(adev->irq_status,
2527 HOST_INT_SCAN_COMPLETE);
2531 /* These we just log, but either they happen rarely
2532 * or we keep them masked out */
2533 if (irqtype & (0 | HOST_INT_RX_DATA
2534 /* | HOST_INT_TX_COMPLETE */
2535 | HOST_INT_TX_XFER
2536 /* | HOST_INT_RX_COMPLETE */
2537 | HOST_INT_DTIM
2538 | HOST_INT_BEACON
2539 | HOST_INT_TIMER
2540 | HOST_INT_KEY_NOT_FOUND
2541 | HOST_INT_IV_ICV_FAILURE
2542 /* | HOST_INT_CMD_COMPLETE */
2543 /* | HOST_INT_INFO */
2544 | HOST_INT_OVERFLOW | HOST_INT_PROCESS_ERROR
2545 /* | HOST_INT_SCAN_COMPLETE */
2546 | HOST_INT_FCS_THRESHOLD | HOST_INT_UNKNOWN)) {
2547 log_unusual_irq(irqtype);
2549 #if IRQ_ITERATE
2550 unmasked = read_reg16(adev, IO_ACX_IRQ_STATUS_CLEAR);
2551 irqtype = unmasked & ~adev->irq_mask;
2552 /* Bail out if no new IRQ bits or if all are masked out */
2553 if (!irqtype)
2554 break;
2556 if (unlikely
2557 (++adev->irq_loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY)) {
2558 printk(KERN_ERR
2559 "acx: too many interrupts per jiffy!\n");
2560 /* Looks like card floods us with IRQs! Try to stop that */
2561 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
2562 /* This will short-circuit all future attempts to handle IRQ.
2563 * We cant do much more... */
2564 adev->irq_mask = 0;
2565 break;
2568 #endif
2569 /* Routine to perform blink with range */
2570 if (unlikely(adev->led_power == 2))
2571 update_link_quality_led(adev);
2573 /* handled: */
2574 if (adev->after_interrupt_jobs)
2575 acx_e_after_interrupt_task(&adev->after_interrupt_task);
2577 /* write_flush(adev); - not needed, last op was read anyway */
2578 acx_sem_unlock(adev);
2579 FN_EXIT0;
2580 return;
2585 static irqreturn_t
2586 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
2587 acxpci_i_interrupt(int irq, void *dev_id)
2588 #else
2589 acxpci_i_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2590 #endif
2593 acx_device_t *adev = dev_id;
2594 unsigned long flags;
2595 register u16 irqtype;
2596 u16 unmasked;
2598 if (!adev)
2599 return IRQ_NONE;
2600 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2601 * I am paranoid */
2603 acx_lock(adev, flags);
2605 unmasked = read_reg16(adev, IO_ACX_IRQ_STATUS_CLEAR);
2607 if (unlikely(0xffff == unmasked)) {
2608 /* 0xffff value hints at missing hardware,
2609 * so don't do anything.
2610 * Not very clean, but other drivers do the same... */
2611 log(L_IRQ, "IRQ type:FFFF - device removed? IRQ_NONE\n");
2612 goto none;
2615 /* We will check only "interesting" IRQ types */
2616 irqtype = unmasked & ~adev->irq_mask;
2617 if (!irqtype) {
2618 /* We are on a shared IRQ line and it wasn't our IRQ */
2619 log(L_IRQ,
2620 "IRQ type:%04X, mask:%04X - all are masked, IRQ_NONE\n",
2621 unmasked, adev->irq_mask);
2622 goto none;
2625 /* Go ahead and ACK our interrupt */
2626 write_reg16(adev, IO_ACX_IRQ_ACK, 0xffff);
2627 if (irqtype & HOST_INT_CMD_COMPLETE) {
2628 log(L_IRQ, "got Command_Complete IRQ\n");
2629 /* save the state for the running issue_cmd() */
2630 SET_BIT(adev->irq_status, HOST_INT_CMD_COMPLETE);
2633 /* Only accept IRQs, if we are initialized properly.
2634 * This avoids an RX race while initializing.
2635 * We should probably not enable IRQs before we are initialized
2636 * completely, but some careful work is needed to fix this. I think it
2637 * is best to stay with this cheap workaround for now... .
2639 if (likely(adev->initialized)) {
2640 /* disable all IRQs. They are enabled again in the bottom half. */
2641 /* save the reason code and call our bottom half. */
2642 adev->irq_reason = irqtype;
2644 if ((irqtype & HOST_INT_RX_COMPLETE) || (irqtype & HOST_INT_TX_COMPLETE))
2645 acx_schedule_task(adev, 0);
2647 acx_unlock(adev, flags);
2648 return IRQ_HANDLED;
2649 none:
2650 acx_unlock(adev, flags);
2651 return IRQ_NONE;
2656 /***********************************************************************
2657 ** acxpci_l_power_led
2659 void acxpci_l_power_led(acx_device_t * adev, int enable)
2661 u16 gpio_pled = IS_ACX111(adev) ? 0x0040 : 0x0800;
2663 /* A hack. Not moving message rate limiting to adev->xxx
2664 * (it's only a debug message after all) */
2665 static int rate_limit = 0;
2667 if (rate_limit++ < 3)
2668 log(L_IOCTL, "Please report in case toggling the power "
2669 "LED doesn't work for your card!\n");
2670 if (enable)
2671 write_reg16(adev, IO_ACX_GPIO_OUT,
2672 read_reg16(adev, IO_ACX_GPIO_OUT) & ~gpio_pled);
2673 else
2674 write_reg16(adev, IO_ACX_GPIO_OUT,
2675 read_reg16(adev, IO_ACX_GPIO_OUT) | gpio_pled);
2679 /***********************************************************************
2680 ** Ioctls
2683 /***********************************************************************
2685 #if 0
2687 acx111pci_ioctl_info(struct net_device *ndev,
2688 struct iw_request_info *info,
2689 struct iw_param *vwrq, char *extra)
2691 #if ACX_DEBUG > 1
2692 acx_device_t *adev = ndev2adev(ndev);
2693 rxdesc_t *rxdesc;
2694 txdesc_t *txdesc;
2695 rxhostdesc_t *rxhostdesc;
2696 txhostdesc_t *txhostdesc;
2697 struct acx111_ie_memoryconfig memconf;
2698 struct acx111_ie_queueconfig queueconf;
2699 unsigned long flags;
2700 int i;
2701 char memmap[0x34];
2702 char rxconfig[0x8];
2703 char fcserror[0x8];
2704 char ratefallback[0x5];
2706 if (!(acx_debug & (L_IOCTL | L_DEBUG)))
2707 return OK;
2708 /* using printk() since we checked debug flag already */
2710 acx_sem_lock(adev);
2712 if (!IS_ACX111(adev)) {
2713 printk("acx111-specific function called "
2714 "with non-acx111 chip, aborting\n");
2715 goto end_ok;
2718 /* get Acx111 Memory Configuration */
2719 memset(&memconf, 0, sizeof(memconf));
2720 /* BTW, fails with 12 (Write only) error code.
2721 ** Retained for easy testing of issue_cmd error handling :) */
2722 acx_s_interrogate(adev, &memconf, ACX1xx_IE_QUEUE_CONFIG);
2724 /* get Acx111 Queue Configuration */
2725 memset(&queueconf, 0, sizeof(queueconf));
2726 acx_s_interrogate(adev, &queueconf, ACX1xx_IE_MEMORY_CONFIG_OPTIONS);
2728 /* get Acx111 Memory Map */
2729 memset(memmap, 0, sizeof(memmap));
2730 acx_s_interrogate(adev, &memmap, ACX1xx_IE_MEMORY_MAP);
2732 /* get Acx111 Rx Config */
2733 memset(rxconfig, 0, sizeof(rxconfig));
2734 acx_s_interrogate(adev, &rxconfig, ACX1xx_IE_RXCONFIG);
2736 /* get Acx111 fcs error count */
2737 memset(fcserror, 0, sizeof(fcserror));
2738 acx_s_interrogate(adev, &fcserror, ACX1xx_IE_FCS_ERROR_COUNT);
2740 /* get Acx111 rate fallback */
2741 memset(ratefallback, 0, sizeof(ratefallback));
2742 acx_s_interrogate(adev, &ratefallback, ACX1xx_IE_RATE_FALLBACK);
2744 /* force occurrence of a beacon interrupt */
2745 /* TODO: comment why is this necessary */
2746 write_reg16(adev, IO_ACX_HINT_TRIG, HOST_INT_BEACON);
2748 /* dump Acx111 Mem Configuration */
2749 printk("dump mem config:\n"
2750 "data read: %d, struct size: %d\n"
2751 "Number of stations: %1X\n"
2752 "Memory block size: %1X\n"
2753 "tx/rx memory block allocation: %1X\n"
2754 "count rx: %X / tx: %X queues\n"
2755 "options %1X\n"
2756 "fragmentation %1X\n"
2757 "Rx Queue 1 Count Descriptors: %X\n"
2758 "Rx Queue 1 Host Memory Start: %X\n"
2759 "Tx Queue 1 Count Descriptors: %X\n"
2760 "Tx Queue 1 Attributes: %X\n",
2761 memconf.len, (int)sizeof(memconf),
2762 memconf.no_of_stations,
2763 memconf.memory_block_size,
2764 memconf.tx_rx_memory_block_allocation,
2765 memconf.count_rx_queues, memconf.count_tx_queues,
2766 memconf.options,
2767 memconf.fragmentation,
2768 memconf.rx_queue1_count_descs,
2769 acx2cpu(memconf.rx_queue1_host_rx_start),
2770 memconf.tx_queue1_count_descs, memconf.tx_queue1_attributes);
2772 /* dump Acx111 Queue Configuration */
2773 printk("dump queue head:\n"
2774 "data read: %d, struct size: %d\n"
2775 "tx_memory_block_address (from card): %X\n"
2776 "rx_memory_block_address (from card): %X\n"
2777 "rx1_queue address (from card): %X\n"
2778 "tx1_queue address (from card): %X\n"
2779 "tx1_queue attributes (from card): %X\n",
2780 queueconf.len, (int)sizeof(queueconf),
2781 queueconf.tx_memory_block_address,
2782 queueconf.rx_memory_block_address,
2783 queueconf.rx1_queue_address,
2784 queueconf.tx1_queue_address, queueconf.tx1_attributes);
2786 /* dump Acx111 Mem Map */
2787 printk("dump mem map:\n"
2788 "data read: %d, struct size: %d\n"
2789 "Code start: %X\n"
2790 "Code end: %X\n"
2791 "WEP default key start: %X\n"
2792 "WEP default key end: %X\n"
2793 "STA table start: %X\n"
2794 "STA table end: %X\n"
2795 "Packet template start: %X\n"
2796 "Packet template end: %X\n"
2797 "Queue memory start: %X\n"
2798 "Queue memory end: %X\n"
2799 "Packet memory pool start: %X\n"
2800 "Packet memory pool end: %X\n"
2801 "iobase: %p\n"
2802 "iobase2: %p\n",
2803 *((u16 *) & memmap[0x02]), (int)sizeof(memmap),
2804 *((u32 *) & memmap[0x04]),
2805 *((u32 *) & memmap[0x08]),
2806 *((u32 *) & memmap[0x0C]),
2807 *((u32 *) & memmap[0x10]),
2808 *((u32 *) & memmap[0x14]),
2809 *((u32 *) & memmap[0x18]),
2810 *((u32 *) & memmap[0x1C]),
2811 *((u32 *) & memmap[0x20]),
2812 *((u32 *) & memmap[0x24]),
2813 *((u32 *) & memmap[0x28]),
2814 *((u32 *) & memmap[0x2C]),
2815 *((u32 *) & memmap[0x30]), adev->iobase, adev->iobase2);
2817 /* dump Acx111 Rx Config */
2818 printk("dump rx config:\n"
2819 "data read: %d, struct size: %d\n"
2820 "rx config: %X\n"
2821 "rx filter config: %X\n",
2822 *((u16 *) & rxconfig[0x02]), (int)sizeof(rxconfig),
2823 *((u16 *) & rxconfig[0x04]), *((u16 *) & rxconfig[0x06]));
2825 /* dump Acx111 fcs error */
2826 printk("dump fcserror:\n"
2827 "data read: %d, struct size: %d\n"
2828 "fcserrors: %X\n",
2829 *((u16 *) & fcserror[0x02]), (int)sizeof(fcserror),
2830 *((u32 *) & fcserror[0x04]));
2832 /* dump Acx111 rate fallback */
2833 printk("dump rate fallback:\n"
2834 "data read: %d, struct size: %d\n"
2835 "ratefallback: %X\n",
2836 *((u16 *) & ratefallback[0x02]), (int)sizeof(ratefallback),
2837 *((u8 *) & ratefallback[0x04]));
2839 /* protect against IRQ */
2840 acx_lock(adev, flags);
2842 /* dump acx111 internal rx descriptor ring buffer */
2843 rxdesc = adev->rxdesc_start;
2845 /* loop over complete receive pool */
2846 if (rxdesc)
2847 for (i = 0; i < RX_CNT; i++) {
2848 printk("\ndump internal rxdesc %d:\n"
2849 "mem pos %p\n"
2850 "next 0x%X\n"
2851 "acx mem pointer (dynamic) 0x%X\n"
2852 "CTL (dynamic) 0x%X\n"
2853 "Rate (dynamic) 0x%X\n"
2854 "RxStatus (dynamic) 0x%X\n"
2855 "Mod/Pre (dynamic) 0x%X\n",
2857 rxdesc,
2858 acx2cpu(rxdesc->pNextDesc),
2859 acx2cpu(rxdesc->ACXMemPtr),
2860 rxdesc->Ctl_8,
2861 rxdesc->rate, rxdesc->error, rxdesc->SNR);
2862 rxdesc++;
2865 /* dump host rx descriptor ring buffer */
2867 rxhostdesc = adev->rxhostdesc_start;
2869 /* loop over complete receive pool */
2870 if (rxhostdesc)
2871 for (i = 0; i < RX_CNT; i++) {
2872 printk("\ndump host rxdesc %d:\n"
2873 "mem pos %p\n"
2874 "buffer mem pos 0x%X\n"
2875 "buffer mem offset 0x%X\n"
2876 "CTL 0x%X\n"
2877 "Length 0x%X\n"
2878 "next 0x%X\n"
2879 "Status 0x%X\n",
2881 rxhostdesc,
2882 acx2cpu(rxhostdesc->data_phy),
2883 rxhostdesc->data_offset,
2884 le16_to_cpu(rxhostdesc->Ctl_16),
2885 le16_to_cpu(rxhostdesc->length),
2886 acx2cpu(rxhostdesc->desc_phy_next),
2887 rxhostdesc->Status);
2888 rxhostdesc++;
2891 /* dump acx111 internal tx descriptor ring buffer */
2892 txdesc = adev->txdesc_start;
2894 /* loop over complete transmit pool */
2895 if (txdesc)
2896 for (i = 0; i < TX_CNT; i++) {
2897 printk("\ndump internal txdesc %d:\n"
2898 "size 0x%X\n"
2899 "mem pos %p\n"
2900 "next 0x%X\n"
2901 "acx mem pointer (dynamic) 0x%X\n"
2902 "host mem pointer (dynamic) 0x%X\n"
2903 "length (dynamic) 0x%X\n"
2904 "CTL (dynamic) 0x%X\n"
2905 "CTL2 (dynamic) 0x%X\n"
2906 "Status (dynamic) 0x%X\n"
2907 "Rate (dynamic) 0x%X\n",
2909 (int)sizeof(struct txdesc),
2910 txdesc,
2911 acx2cpu(txdesc->pNextDesc),
2912 acx2cpu(txdesc->AcxMemPtr),
2913 acx2cpu(txdesc->HostMemPtr),
2914 le16_to_cpu(txdesc->total_length),
2915 txdesc->Ctl_8,
2916 txdesc->Ctl2_8, txdesc->error,
2917 txdesc->u.r1.rate);
2918 txdesc = advance_txdesc(adev, txdesc, 1);
2921 /* dump host tx descriptor ring buffer */
2923 txhostdesc = adev->txhostdesc_start;
2925 /* loop over complete host send pool */
2926 if (txhostdesc)
2927 for (i = 0; i < TX_CNT * 2; i++) {
2928 printk("\ndump host txdesc %d:\n"
2929 "mem pos %p\n"
2930 "buffer mem pos 0x%X\n"
2931 "buffer mem offset 0x%X\n"
2932 "CTL 0x%X\n"
2933 "Length 0x%X\n"
2934 "next 0x%X\n"
2935 "Status 0x%X\n",
2937 txhostdesc,
2938 acx2cpu(txhostdesc->data_phy),
2939 txhostdesc->data_offset,
2940 le16_to_cpu(txhostdesc->Ctl_16),
2941 le16_to_cpu(txhostdesc->length),
2942 acx2cpu(txhostdesc->desc_phy_next),
2943 le32_to_cpu(txhostdesc->Status));
2944 txhostdesc++;
2947 /* write_reg16(adev, 0xb4, 0x4); */
2949 acx_unlock(adev, flags);
2950 end_ok:
2952 acx_sem_unlock(adev);
2953 #endif /* ACX_DEBUG */
2954 return OK;
2958 /***********************************************************************
2961 acx100pci_ioctl_set_phy_amp_bias(struct net_device *ndev,
2962 struct iw_request_info *info,
2963 struct iw_param *vwrq, char *extra)
2965 acx_device_t *adev = ndev2adev(ndev);
2966 unsigned long flags;
2967 u16 gpio_old;
2969 if (!IS_ACX100(adev)) {
2970 /* WARNING!!!
2971 * Removing this check *might* damage
2972 * hardware, since we're tweaking GPIOs here after all!!!
2973 * You've been warned...
2974 * WARNING!!! */
2975 printk("acx: sorry, setting bias level for non-acx100 "
2976 "is not supported yet\n");
2977 return OK;
2980 if (*extra > 7) {
2981 printk("acx: invalid bias parameter, range is 0-7\n");
2982 return -EINVAL;
2985 acx_sem_lock(adev);
2987 /* Need to lock accesses to [IO_ACX_GPIO_OUT]:
2988 * IRQ handler uses it to update LED */
2989 acx_lock(adev, flags);
2990 gpio_old = read_reg16(adev, IO_ACX_GPIO_OUT);
2991 write_reg16(adev, IO_ACX_GPIO_OUT,
2992 (gpio_old & 0xf8ff) | ((u16) * extra << 8));
2993 acx_unlock(adev, flags);
2995 log(L_DEBUG, "gpio_old: 0x%04X\n", gpio_old);
2996 printk("%s: PHY power amplifier bias: old:%d, new:%d\n",
2997 ndev->name, (gpio_old & 0x0700) >> 8, (unsigned char)*extra);
2999 acx_sem_unlock(adev);
3001 return OK;
3003 #endif
3005 /***************************************************************
3006 ** acxpci_l_alloc_tx
3007 ** Actually returns a txdesc_t* ptr
3009 ** FIXME: in case of fragments, should allocate multiple descrs
3010 ** after figuring out how many we need and whether we still have
3011 ** sufficiently many.
3013 tx_t *acxpci_l_alloc_tx(acx_device_t * adev)
3015 struct txdesc *txdesc;
3016 unsigned head;
3017 u8 ctl8;
3019 FN_ENTER;
3021 if (unlikely(!adev->tx_free)) {
3022 printk("acx: BUG: no free txdesc left\n");
3023 txdesc = NULL;
3024 goto end;
3027 head = adev->tx_head;
3028 txdesc = get_txdesc(adev, head);
3029 ctl8 = txdesc->Ctl_8;
3031 /* 2005-10-11: there were several bug reports on this happening
3032 ** but now cause seems to be understood & fixed */
3033 if (unlikely(DESC_CTL_HOSTOWN != (ctl8 & DESC_CTL_ACXDONE_HOSTOWN))) {
3034 /* whoops, descr at current index is not free, so probably
3035 * ring buffer already full */
3036 printk("acx: BUG: tx_head:%d Ctl8:0x%02X - failed to find "
3037 "free txdesc\n", head, ctl8);
3038 txdesc = NULL;
3039 goto end;
3042 /* Needed in case txdesc won't be eventually submitted for tx */
3043 txdesc->Ctl_8 = DESC_CTL_ACXDONE_HOSTOWN;
3045 adev->tx_free--;
3046 log(L_BUFT, "tx: got desc %u, %u remain\n", head, adev->tx_free);
3047 /* Keep a few free descs between head and tail of tx ring.
3048 ** It is not absolutely needed, just feels safer */
3049 if (adev->tx_free < TX_STOP_QUEUE) {
3050 log(L_BUF, "stop queue (%u tx desc left)\n", adev->tx_free);
3051 acx_stop_queue(adev->ieee, NULL);
3054 /* returning current descriptor, so advance to next free one */
3055 adev->tx_head = (head + 1) % TX_CNT;
3056 end:
3057 FN_EXIT0;
3059 return (tx_t *) txdesc;
3063 /***********************************************************************
3065 void *acxpci_l_get_txbuf(acx_device_t * adev, tx_t * tx_opaque)
3067 return get_txhostdesc(adev, (txdesc_t *) tx_opaque)->data;
3071 /***********************************************************************
3072 ** acxpci_l_tx_data
3074 ** Can be called from IRQ (rx -> (AP bridging or mgmt response) -> tx).
3075 ** Can be called from acx_i_start_xmit (data frames from net core).
3077 ** FIXME: in case of fragments, should loop over the number of
3078 ** pre-allocated tx descrs, properly setting up transfer data and
3079 ** CTL_xxx flags according to fragment number.
3081 void
3082 acxpci_l_tx_data(acx_device_t * adev, tx_t * tx_opaque, int len,
3083 struct ieee80211_tx_control *ieeectl,struct sk_buff* skb)
3085 txdesc_t *txdesc = (txdesc_t *) tx_opaque;
3086 struct ieee80211_hdr *wireless_header;
3087 txhostdesc_t *hostdesc1, *hostdesc2;
3088 int rate_cur;
3089 u8 Ctl_8, Ctl2_8;
3090 int wlhdr_len;
3092 FN_ENTER;
3094 /* fw doesn't tx such packets anyhow */
3095 /* if (unlikely(len < WLAN_HDR_A3_LEN))
3096 goto end;
3098 hostdesc1 = get_txhostdesc(adev, txdesc);
3099 wireless_header = (struct ieee80211_hdr *)hostdesc1->data;
3100 /* modify flag status in separate variable to be able to write it back
3101 * in one big swoop later (also in order to have less device memory
3102 * accesses) */
3103 Ctl_8 = txdesc->Ctl_8;
3104 Ctl2_8 = 0; /* really need to init it to 0, not txdesc->Ctl2_8, it seems */
3106 hostdesc2 = hostdesc1 + 1;
3108 /* DON'T simply set Ctl field to 0 here globally,
3109 * it needs to maintain a consistent flag status (those are state flags!!),
3110 * otherwise it may lead to severe disruption. Only set or reset particular
3111 * flags at the exact moment this is needed... */
3113 /* let chip do RTS/CTS handshaking before sending
3114 * in case packet size exceeds threshold */
3115 if (ieeectl->flags & IEEE80211_TXCTL_USE_RTS_CTS)
3116 SET_BIT(Ctl2_8, DESC_CTL2_RTS);
3117 else
3118 CLEAR_BIT(Ctl2_8, DESC_CTL2_RTS);
3120 rate_cur = ieeectl->tx_rate;
3121 if (unlikely(!rate_cur)) {
3122 printk("acx: driver bug! bad ratemask\n");
3123 goto end;
3126 /* used in tx cleanup routine for auto rate and accounting: */
3127 /* put_txcr(adev, txdesc, clt, rate_cur); deprecated by mac80211 */
3129 txdesc->total_length = cpu_to_le16(len);
3130 wlhdr_len = ieee80211_get_hdrlen(le16_to_cpu(wireless_header->frame_control));
3131 hostdesc2->length = cpu_to_le16(len - wlhdr_len);
3133 if (!ieeectl->do_not_encrypt && ieeectl->key_idx>= 0)
3135 u16 key_idx = (u16)(ieeectl->key_idx);
3136 struct acx_key* key = &(adev->key[key_idx]);
3137 int wlhdr_len;
3138 if (key->enabled)
3140 memcpy(ieeehdr->wep_iv, ((u8*)wireless_header) + wlhdr_len, 4);
3144 if (IS_ACX111(adev)) {
3145 /* note that if !txdesc->do_auto, txrate->cur
3146 ** has only one nonzero bit */
3147 txdesc->u.r2.rate111 = cpu_to_le16(rate_cur
3148 /* WARNING: I was never able to make it work with prism54 AP.
3149 ** It was falling down to 1Mbit where shortpre is not applicable,
3150 ** and not working at all at "5,11 basic rates only" setting.
3151 ** I even didn't see tx packets in radio packet capture.
3152 ** Disabled for now --vda */
3153 /*| ((clt->shortpre && clt->cur!=RATE111_1) ? RATE111_SHORTPRE : 0) */
3155 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3156 /* should add this to rate111 above as necessary */
3157 |(clt->pbcc511 ? RATE111_PBCC511 : 0)
3158 #endif
3159 hostdesc1->length = cpu_to_le16(len);
3160 } else { /* ACX100 */
3161 u8 rate_100 = ieeectl->tx_rate;
3162 txdesc->u.r1.rate = rate_100;
3163 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3164 if (clt->pbcc511) {
3165 if (n == RATE100_5 || n == RATE100_11)
3166 n |= RATE100_PBCC511;
3169 if (clt->shortpre && (clt->cur != RATE111_1))
3170 SET_BIT(Ctl_8, DESC_CTL_SHORT_PREAMBLE); /* set Short Preamble */
3171 #endif
3172 /* set autodma and reclaim and 1st mpdu */
3173 SET_BIT(Ctl_8,
3174 DESC_CTL_AUTODMA | DESC_CTL_RECLAIM |
3175 DESC_CTL_FIRSTFRAG);
3176 #if ACX_FRAGMENTATION
3177 /* SET_BIT(Ctl2_8, DESC_CTL2_MORE_FRAG); cannot set it unconditionally, needs to be set for all non-last fragments */
3178 #endif
3179 hostdesc1->length = cpu_to_le16(wlhdr_len);
3181 /* don't need to clean ack/rts statistics here, already
3182 * done on descr cleanup */
3184 /* clears HOSTOWN and ACXDONE bits, thus telling that the descriptors
3185 * are now owned by the acx100; do this as LAST operation */
3186 CLEAR_BIT(Ctl_8, DESC_CTL_ACXDONE_HOSTOWN);
3187 /* flush writes before we release hostdesc to the adapter here */
3188 wmb();
3189 CLEAR_BIT(hostdesc1->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3190 CLEAR_BIT(hostdesc2->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3192 /* write back modified flags */
3193 CLEAR_BIT(Ctl2_8, DESC_CTL2_WEP);
3194 txdesc->Ctl2_8 = Ctl2_8;
3195 txdesc->Ctl_8 = Ctl_8;
3196 /* unused: txdesc->tx_time = cpu_to_le32(jiffies); */
3198 /* flush writes before we tell the adapter that it's its turn now */
3199 mmiowb();
3200 write_reg16(adev, IO_ACX_INT_TRIG, INT_TRIG_TXPRC);
3201 write_flush(adev);
3202 /* log the packet content AFTER sending it,
3203 * in order to not delay sending any further than absolutely needed
3204 * Do separate logs for acx100/111 to have human-readable rates */
3205 memcpy(&(hostdesc1->txstatus.control),ieeectl,sizeof(struct ieee80211_tx_control));
3206 hostdesc1->skb = skb;
3207 end:
3208 FN_EXIT0;
3212 /***********************************************************************
3213 ** acxpci_l_clean_txdesc
3215 ** This function resets the txdescs' status when the ACX100
3216 ** signals the TX done IRQ (txdescs have been processed), starting with
3217 ** the pool index of the descriptor which we would use next,
3218 ** in order to make sure that we can be as fast as possible
3219 ** in filling new txdescs.
3220 ** Everytime we get called we know where the next packet to be cleaned is.
3223 #if !ACX_DEBUG
3224 static inline void log_txbuffer(const acx_device_t * adev)
3227 #else
3228 static void log_txbuffer(acx_device_t * adev)
3230 txdesc_t *txdesc;
3231 int i;
3233 /* no FN_ENTER here, we don't want that */
3234 /* no locks here, since it's entirely non-critical code */
3235 txdesc = adev->txdesc_start;
3236 if (unlikely(!txdesc))
3237 return;
3238 printk("tx: desc->Ctl8's:");
3239 for (i = 0; i < TX_CNT; i++) {
3240 printk(" %02X", txdesc->Ctl_8);
3241 txdesc = advance_txdesc(adev, txdesc, 1);
3243 printk("\n");
3245 #endif
3248 static void handle_tx_error(acx_device_t * adev, u8 error, unsigned int finger,
3249 struct ieee80211_tx_status *status)
3251 const char *err = "unknown error";
3253 /* hmm, should we handle this as a mask
3254 * of *several* bits?
3255 * For now I think only caring about
3256 * individual bits is ok... */
3257 switch (error) {
3258 case 0x01:
3259 err = "no Tx due to error in other fragment";
3260 /* adev->wstats.discard.fragment++; */
3261 break;
3262 case 0x02:
3263 err = "Tx aborted";
3264 adev->stats.tx_aborted_errors++;
3265 break;
3266 case 0x04:
3267 err = "Tx desc wrong parameters";
3268 /* adev->wstats.discard.misc++; */
3269 break;
3270 case 0x08:
3271 err = "WEP key not found";
3272 /* adev->wstats.discard.misc++; */
3273 break;
3274 case 0x10:
3275 err = "MSDU lifetime timeout? - try changing "
3276 "'iwconfig retry lifetime XXX'";
3277 /* adev->wstats.discard.misc++; */
3278 break;
3279 case 0x20:
3280 err = "excessive Tx retries due to either distance "
3281 "too high or unable to Tx or Tx frame error - "
3282 "try changing 'iwconfig txpower XXX' or "
3283 "'sens'itivity or 'retry'";
3284 /* adev->wstats.discard.retries++; */
3285 /* Tx error 0x20 also seems to occur on
3286 * overheating, so I'm not sure whether we
3287 * actually want to do aggressive radio recalibration,
3288 * since people maybe won't notice then that their hardware
3289 * is slowly getting cooked...
3290 * Or is it still a safe long distance from utter
3291 * radio non-functionality despite many radio recalibs
3292 * to final destructive overheating of the hardware?
3293 * In this case we really should do recalib here...
3294 * I guess the only way to find out is to do a
3295 * potentially fatal self-experiment :-\
3296 * Or maybe only recalib in case we're using Tx
3297 * rate auto (on errors switching to lower speed
3298 * --> less heat?) or 802.11 power save mode?
3300 * ok, just do it. */
3301 if (++adev->retry_errors_msg_ratelimit % 4 == 0) {
3302 if (adev->retry_errors_msg_ratelimit <= 20) {
3303 printk("%s: several excessive Tx "
3304 "retry errors occurred, attempting "
3305 "to recalibrate radio. Radio "
3306 "drift might be caused by increasing "
3307 "card temperature, please check the card "
3308 "before it's too late!\n",
3309 wiphy_name(adev->ieee->wiphy));
3310 if (adev->retry_errors_msg_ratelimit == 20)
3311 printk("disabling above message\n");
3314 acx_schedule_task(adev,
3315 ACX_AFTER_IRQ_CMD_RADIO_RECALIB);
3317 status->excessive_retries++;
3318 break;
3319 case 0x40:
3320 err = "Tx buffer overflow";
3321 adev->stats.tx_fifo_errors++;
3322 break;
3323 case 0x80:
3324 /* possibly ACPI C-state powersaving related!!!
3325 * (DMA timeout due to excessively high wakeup
3326 * latency after C-state activation!?)
3327 * Disable C-State powersaving and try again,
3328 * then PLEASE REPORT, I'm VERY interested in
3329 * whether my theory is correct that this is
3330 * actually the problem here.
3331 * In that case, use new Linux idle wakeup latency
3332 * requirements kernel API to prevent this issue. */
3333 err = "DMA error";
3334 /* adev->wstats.discard.misc++; */
3335 break;
3337 adev->stats.tx_errors++;
3338 if (adev->stats.tx_errors <= 20)
3339 printk("%s: tx error 0x%02X, buf %02u! (%s)\n",
3340 wiphy_name(adev->ieee->wiphy), error, finger, err);
3341 else
3342 printk("%s: tx error 0x%02X, buf %02u!\n",
3343 wiphy_name(adev->ieee->wiphy), error, finger);
3347 unsigned int acxpci_l_clean_txdesc(acx_device_t * adev)
3349 txdesc_t *txdesc;
3350 txhostdesc_t *hostdesc;
3351 unsigned finger;
3352 int num_cleaned;
3353 u16 r111;
3354 u8 error, ack_failures, rts_failures, rts_ok, r100;
3356 FN_ENTER;
3358 if (unlikely(acx_debug & L_DEBUG))
3359 log_txbuffer(adev);
3361 log(L_BUFT, "tx: cleaning up bufs from %u\n", adev->tx_tail);
3363 /* We know first descr which is not free yet. We advance it as far
3364 ** as we see correct bits set in following descs (if next desc
3365 ** is NOT free, we shouldn't advance at all). We know that in
3366 ** front of tx_tail may be "holes" with isolated free descs.
3367 ** We will catch up when all intermediate descs will be freed also */
3369 finger = adev->tx_tail;
3370 num_cleaned = 0;
3371 while (likely(finger != adev->tx_head)) {
3372 txdesc = get_txdesc(adev, finger);
3374 /* If we allocated txdesc on tx path but then decided
3375 ** to NOT use it, then it will be left as a free "bubble"
3376 ** in the "allocated for tx" part of the ring.
3377 ** We may meet it on the next ring pass here. */
3379 /* stop if not marked as "tx finished" and "host owned" */
3380 if ((txdesc->Ctl_8 & DESC_CTL_ACXDONE_HOSTOWN)
3381 != DESC_CTL_ACXDONE_HOSTOWN) {
3382 if (unlikely(!num_cleaned)) { /* maybe remove completely */
3383 log(L_BUFT, "clean_txdesc: tail isn't free. "
3384 "tail:%d head:%d\n",
3385 adev->tx_tail, adev->tx_head);
3387 break;
3390 /* remember desc values... */
3391 error = txdesc->error;
3392 ack_failures = txdesc->ack_failures;
3393 rts_failures = txdesc->rts_failures;
3394 rts_ok = txdesc->rts_ok;
3395 r100 = txdesc->u.r1.rate;
3396 r111 = le16_to_cpu(txdesc->u.r2.rate111);
3398 /* need to check for certain error conditions before we
3399 * clean the descriptor: we still need valid descr data here */
3400 hostdesc = get_txhostdesc(adev, txdesc);
3402 hostdesc->txstatus.flags |= IEEE80211_TX_STATUS_ACK;
3403 if (unlikely(0x30 & error)) {
3404 /* only send IWEVTXDROP in case of retry or lifetime exceeded;
3405 * all other errors mean we screwed up locally */
3406 /* union iwreq_data wrqu;
3407 struct ieee80211_hdr_3addr *hdr;
3408 hdr = (struct ieee80211_hdr_3addr *) hostdesc->data;
3409 MAC_COPY(wrqu.addr.sa_data, hdr->addr1);
3411 hostdesc->txstatus.flags &= ~IEEE80211_TX_STATUS_ACK;
3414 /* ...and free the desc */
3415 txdesc->error = 0;
3416 txdesc->ack_failures = 0;
3417 txdesc->rts_failures = 0;
3418 txdesc->rts_ok = 0;
3419 /* signal host owning it LAST, since ACX already knows that this
3420 ** descriptor is finished since it set Ctl_8 accordingly. */
3421 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3423 adev->tx_free++;
3424 num_cleaned++;
3426 if ((adev->tx_free >= TX_START_QUEUE)
3427 /* && (adev->status == ACX_STATUS_4_ASSOCIATED) */
3428 /*&& (acx_queue_stopped(adev->ieee))*/
3430 log(L_BUF, "tx: wake queue (avail. Tx desc %u)\n",
3431 adev->tx_free);
3432 acx_wake_queue(adev->ieee, NULL);
3435 /* do error checking, rate handling and logging
3436 * AFTER having done the work, it's faster */
3438 /* Rate handling is done in mac80211 */
3439 /* if (adev->rate_auto) {
3440 struct client *clt = get_txc(adev, txdesc);
3441 if (clt) {
3442 u16 cur = get_txr(adev, txdesc);
3443 if (clt->rate_cur == cur) {
3444 acx_l_handle_txrate_auto(adev, clt, cur,*/ /* intended rate */
3445 /*r100, r111,*/ /* actually used rate */
3446 /*(error & 0x30),*/ /* was there an error? */
3447 /* TX_CNT +
3448 TX_CLEAN_BACKLOG
3450 adev->tx_free);
3455 if (unlikely(error))
3456 handle_tx_error(adev, error, finger, &hostdesc->txstatus);
3458 if (IS_ACX111(adev))
3459 log(L_BUFT,
3460 "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u r111=%04X tx_free=%u\n",
3461 finger, ack_failures, rts_failures, rts_ok, r111, adev->tx_free);
3462 else
3463 log(L_BUFT,
3464 "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u rate=%u\n",
3465 finger, ack_failures, rts_failures, rts_ok, r100);
3467 /* And finally report upstream */
3468 if (hostdesc)
3470 hostdesc->txstatus.excessive_retries = rts_failures ;
3471 hostdesc->txstatus.retry_count = ack_failures;
3472 ieee80211_tx_status(adev->ieee,hostdesc->skb,&hostdesc->txstatus);
3473 memset(&hostdesc->txstatus, 0, sizeof(struct ieee80211_tx_status));
3475 /* update pointer for descr to be cleaned next */
3476 finger = (finger + 1) % TX_CNT;
3478 /* remember last position */
3479 adev->tx_tail = finger;
3480 /* end: */
3481 FN_EXIT1(num_cleaned);
3482 return num_cleaned;
3485 /* clean *all* Tx descriptors, and regardless of their previous state.
3486 * Used for brute-force reset handling. */
3487 void acxpci_l_clean_txdesc_emergency(acx_device_t * adev)
3489 txdesc_t *txdesc;
3490 int i;
3492 FN_ENTER;
3494 for (i = 0; i < TX_CNT; i++) {
3495 txdesc = get_txdesc(adev, i);
3497 /* free it */
3498 txdesc->ack_failures = 0;
3499 txdesc->rts_failures = 0;
3500 txdesc->rts_ok = 0;
3501 txdesc->error = 0;
3502 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3505 adev->tx_free = TX_CNT;
3507 FN_EXIT0;
3511 /***********************************************************************
3512 ** acxpci_s_create_tx_host_desc_queue
3515 static void *allocate(acx_device_t * adev, size_t size, dma_addr_t * phy,
3516 const char *msg)
3518 void *ptr;
3520 ptr = dma_alloc_coherent(adev->pdev ? &adev->pdev->dev : NULL,
3521 size, phy, GFP_KERNEL);
3523 if (ptr) {
3524 log(L_DEBUG, "%s sz=%d adr=0x%p phy=0x%08llx\n",
3525 msg, (int)size, ptr, (unsigned long long)*phy);
3526 memset(ptr, 0, size);
3527 return ptr;
3529 printk(KERN_ERR "acx: %s allocation FAILED (%d bytes)\n",
3530 msg, (int)size);
3531 return NULL;
3535 static int acxpci_s_create_tx_host_desc_queue(acx_device_t * adev)
3537 txhostdesc_t *hostdesc;
3538 u8 *txbuf;
3539 dma_addr_t hostdesc_phy;
3540 dma_addr_t txbuf_phy;
3541 int i;
3543 FN_ENTER;
3545 /* allocate TX buffer */
3546 adev->txbuf_area_size = TX_CNT * /*WLAN_A4FR_MAXLEN_WEP_FCS*/ (30 + 2312 + 4);
3547 adev->txbuf_start = allocate(adev, adev->txbuf_area_size,
3548 &adev->txbuf_startphy, "txbuf_start");
3549 if (!adev->txbuf_start)
3550 goto fail;
3552 /* allocate the TX host descriptor queue pool */
3553 adev->txhostdesc_area_size = TX_CNT * 2 * sizeof(*hostdesc);
3554 adev->txhostdesc_start = allocate(adev, adev->txhostdesc_area_size,
3555 &adev->txhostdesc_startphy,
3556 "txhostdesc_start");
3557 if (!adev->txhostdesc_start)
3558 goto fail;
3559 /* check for proper alignment of TX host descriptor pool */
3560 if ((long)adev->txhostdesc_start & 3) {
3561 printk
3562 ("acx: driver bug: dma alloc returns unaligned address\n");
3563 goto fail;
3566 hostdesc = adev->txhostdesc_start;
3567 hostdesc_phy = adev->txhostdesc_startphy;
3568 txbuf = adev->txbuf_start;
3569 txbuf_phy = adev->txbuf_startphy;
3571 #if 0
3572 /* Each tx buffer is accessed by hardware via
3573 ** txdesc -> txhostdesc(s) -> txbuffer(s).
3574 ** We use only one txhostdesc per txdesc, but it looks like
3575 ** acx111 is buggy: it accesses second txhostdesc
3576 ** (via hostdesc.desc_phy_next field) even if
3577 ** txdesc->length == hostdesc->length and thus
3578 ** entire packet was placed into first txhostdesc.
3579 ** Due to this bug acx111 hangs unless second txhostdesc
3580 ** has le16_to_cpu(hostdesc.length) = 3 (or larger)
3581 ** Storing NULL into hostdesc.desc_phy_next
3582 ** doesn't seem to help.
3584 ** Update: although it worked on Xterasys XN-2522g
3585 ** with len=3 trick, WG311v2 is even more bogus, doesn't work.
3586 ** Keeping this code (#ifdef'ed out) for documentational purposes.
3588 for (i = 0; i < TX_CNT * 2; i++) {
3589 hostdesc_phy += sizeof(*hostdesc);
3590 if (!(i & 1)) {
3591 hostdesc->data_phy = cpu2acx(txbuf_phy);
3592 /* hostdesc->data_offset = ... */
3593 /* hostdesc->reserved = ... */
3594 hostdesc->Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
3595 /* hostdesc->length = ... */
3596 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3597 hostdesc->pNext = ptr2acx(NULL);
3598 /* hostdesc->Status = ... */
3599 /* below: non-hardware fields */
3600 hostdesc->data = txbuf;
3602 txbuf += WLAN_A4FR_MAXLEN_WEP_FCS;
3603 txbuf_phy += WLAN_A4FR_MAXLEN_WEP_FCS;
3604 } else {
3605 /* hostdesc->data_phy = ... */
3606 /* hostdesc->data_offset = ... */
3607 /* hostdesc->reserved = ... */
3608 /* hostdesc->Ctl_16 = ... */
3609 hostdesc->length = cpu_to_le16(3); /* bug workaround */
3610 /* hostdesc->desc_phy_next = ... */
3611 /* hostdesc->pNext = ... */
3612 /* hostdesc->Status = ... */
3613 /* below: non-hardware fields */
3614 /* hostdesc->data = ... */
3616 hostdesc++;
3618 #endif
3619 /* We initialize two hostdescs so that they point to adjacent
3620 ** memory areas. Thus txbuf is really just a contiguous memory area */
3621 for (i = 0; i < TX_CNT * 2; i++) {
3622 hostdesc_phy += sizeof(*hostdesc);
3624 hostdesc->data_phy = cpu2acx(txbuf_phy);
3625 /* done by memset(0): hostdesc->data_offset = 0; */
3626 /* hostdesc->reserved = ... */
3627 hostdesc->Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
3628 /* hostdesc->length = ... */
3629 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3630 /* done by memset(0): hostdesc->pNext = ptr2acx(NULL); */
3631 /* hostdesc->Status = ... */
3632 /* ->data is a non-hardware field: */
3633 hostdesc->data = txbuf;
3635 if (!(i & 1)) {
3636 txbuf += 24 /*WLAN_HDR_A3_LEN*/;
3637 txbuf_phy += 24 /*WLAN_HDR_A3_LEN*/;
3638 } else {
3639 txbuf += 30 + 2132 + 4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3640 txbuf_phy += 30 + 2132 +4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3642 hostdesc++;
3644 hostdesc--;
3645 hostdesc->desc_phy_next = cpu2acx(adev->txhostdesc_startphy);
3647 FN_EXIT1(OK);
3648 return OK;
3649 fail:
3650 printk("acx: create_tx_host_desc_queue FAILED\n");
3651 /* dealloc will be done by free function on error case */
3652 FN_EXIT1(NOT_OK);
3653 return NOT_OK;
3657 /***************************************************************
3658 ** acxpci_s_create_rx_host_desc_queue
3660 /* the whole size of a data buffer (header plus data body)
3661 * plus 32 bytes safety offset at the end */
3662 #define RX_BUFFER_SIZE (sizeof(rxbuffer_t) + 32)
3664 static int acxpci_s_create_rx_host_desc_queue(acx_device_t * adev)
3666 rxhostdesc_t *hostdesc;
3667 rxbuffer_t *rxbuf;
3668 dma_addr_t hostdesc_phy;
3669 dma_addr_t rxbuf_phy;
3670 int i;
3672 FN_ENTER;
3674 /* allocate the RX host descriptor queue pool */
3675 adev->rxhostdesc_area_size = RX_CNT * sizeof(*hostdesc);
3676 adev->rxhostdesc_start = allocate(adev, adev->rxhostdesc_area_size,
3677 &adev->rxhostdesc_startphy,
3678 "rxhostdesc_start");
3679 if (!adev->rxhostdesc_start)
3680 goto fail;
3681 /* check for proper alignment of RX host descriptor pool */
3682 if ((long)adev->rxhostdesc_start & 3) {
3683 printk
3684 ("acx: driver bug: dma alloc returns unaligned address\n");
3685 goto fail;
3688 /* allocate Rx buffer pool which will be used by the acx
3689 * to store the whole content of the received frames in it */
3690 adev->rxbuf_area_size = RX_CNT * RX_BUFFER_SIZE;
3691 adev->rxbuf_start = allocate(adev, adev->rxbuf_area_size,
3692 &adev->rxbuf_startphy, "rxbuf_start");
3693 if (!adev->rxbuf_start)
3694 goto fail;
3696 rxbuf = adev->rxbuf_start;
3697 rxbuf_phy = adev->rxbuf_startphy;
3698 hostdesc = adev->rxhostdesc_start;
3699 hostdesc_phy = adev->rxhostdesc_startphy;
3701 /* don't make any popular C programming pointer arithmetic mistakes
3702 * here, otherwise I'll kill you...
3703 * (and don't dare asking me why I'm warning you about that...) */
3704 for (i = 0; i < RX_CNT; i++) {
3705 hostdesc->data = rxbuf;
3706 hostdesc->data_phy = cpu2acx(rxbuf_phy);
3707 hostdesc->length = cpu_to_le16(RX_BUFFER_SIZE);
3708 CLEAR_BIT(hostdesc->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3709 rxbuf++;
3710 rxbuf_phy += sizeof(*rxbuf);
3711 hostdesc_phy += sizeof(*hostdesc);
3712 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3713 hostdesc++;
3715 hostdesc--;
3716 hostdesc->desc_phy_next = cpu2acx(adev->rxhostdesc_startphy);
3717 FN_EXIT1(OK);
3718 return OK;
3719 fail:
3720 printk("acx: create_rx_host_desc_queue FAILED\n");
3721 /* dealloc will be done by free function on error case */
3722 FN_EXIT1(NOT_OK);
3723 return NOT_OK;
3727 /***************************************************************
3728 ** acxpci_s_create_hostdesc_queues
3730 int acxpci_s_create_hostdesc_queues(acx_device_t * adev)
3732 int result;
3733 result = acxpci_s_create_tx_host_desc_queue(adev);
3734 if (OK != result)
3735 return result;
3736 result = acxpci_s_create_rx_host_desc_queue(adev);
3737 return result;
3741 /***************************************************************
3742 ** acxpci_create_tx_desc_queue
3744 static void acxpci_create_tx_desc_queue(acx_device_t * adev, u32 tx_queue_start)
3746 txdesc_t *txdesc;
3747 txhostdesc_t *hostdesc;
3748 dma_addr_t hostmemptr;
3749 u32 mem_offs;
3750 int i;
3752 FN_ENTER;
3754 if (IS_ACX100(adev))
3755 adev->txdesc_size = sizeof(*txdesc);
3756 else
3757 /* the acx111 txdesc is 4 bytes larger */
3758 adev->txdesc_size = sizeof(*txdesc) + 4;
3760 adev->txdesc_start = (txdesc_t *) (adev->iobase2 + tx_queue_start);
3762 log(L_DEBUG, "adev->iobase2=%p\n"
3763 "tx_queue_start=%08X\n"
3764 "adev->txdesc_start=%p\n",
3765 adev->iobase2, tx_queue_start, adev->txdesc_start);
3767 adev->tx_free = TX_CNT;
3768 /* done by memset: adev->tx_head = 0; */
3769 /* done by memset: adev->tx_tail = 0; */
3770 txdesc = adev->txdesc_start;
3771 mem_offs = tx_queue_start;
3772 hostmemptr = adev->txhostdesc_startphy;
3773 hostdesc = adev->txhostdesc_start;
3775 if (IS_ACX111(adev)) {
3776 /* ACX111 has a preinitialized Tx buffer! */
3777 /* loop over whole send pool */
3778 /* FIXME: do we have to do the hostmemptr stuff here?? */
3779 for (i = 0; i < TX_CNT; i++) {
3780 txdesc->HostMemPtr = ptr2acx(hostmemptr);
3781 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3782 /* reserve two (hdr desc and payload desc) */
3783 hostdesc += 2;
3784 hostmemptr += 2 * sizeof(*hostdesc);
3785 txdesc = advance_txdesc(adev, txdesc, 1);
3787 } else {
3788 /* ACX100 Tx buffer needs to be initialized by us */
3789 /* clear whole send pool. sizeof is safe here (we are acx100) */
3790 memset(adev->txdesc_start, 0, TX_CNT * sizeof(*txdesc));
3792 /* loop over whole send pool */
3793 for (i = 0; i < TX_CNT; i++) {
3794 log(L_DEBUG, "configure card tx descriptor: 0x%p, "
3795 "size: 0x%X\n", txdesc, adev->txdesc_size);
3797 /* pointer to hostdesc memory */
3798 txdesc->HostMemPtr = ptr2acx(hostmemptr);
3799 /* initialise ctl */
3800 txdesc->Ctl_8 = (DESC_CTL_HOSTOWN | DESC_CTL_RECLAIM
3801 | DESC_CTL_AUTODMA |
3802 DESC_CTL_FIRSTFRAG);
3803 /* done by memset(0): txdesc->Ctl2_8 = 0; */
3804 /* point to next txdesc */
3805 txdesc->pNextDesc =
3806 cpu2acx(mem_offs + adev->txdesc_size);
3807 /* reserve two (hdr desc and payload desc) */
3808 hostdesc += 2;
3809 hostmemptr += 2 * sizeof(*hostdesc);
3810 /* go to the next one */
3811 mem_offs += adev->txdesc_size;
3812 /* ++ is safe here (we are acx100) */
3813 txdesc++;
3815 /* go back to the last one */
3816 txdesc--;
3817 /* and point to the first making it a ring buffer */
3818 txdesc->pNextDesc = cpu2acx(tx_queue_start);
3820 FN_EXIT0;
3824 /***************************************************************
3825 ** acxpci_create_rx_desc_queue
3827 static void acxpci_create_rx_desc_queue(acx_device_t * adev, u32 rx_queue_start)
3829 rxdesc_t *rxdesc;
3830 u32 mem_offs;
3831 int i;
3833 FN_ENTER;
3835 /* done by memset: adev->rx_tail = 0; */
3837 /* ACX111 doesn't need any further config: preconfigures itself.
3838 * Simply print ring buffer for debugging */
3839 if (IS_ACX111(adev)) {
3840 /* rxdesc_start already set here */
3842 adev->rxdesc_start =
3843 (rxdesc_t *) ((u8 *) adev->iobase2 + rx_queue_start);
3845 rxdesc = adev->rxdesc_start;
3846 for (i = 0; i < RX_CNT; i++) {
3847 log(L_DEBUG, "rx descriptor %d @ 0x%p\n", i, rxdesc);
3848 rxdesc = adev->rxdesc_start = (rxdesc_t *)
3849 (adev->iobase2 + acx2cpu(rxdesc->pNextDesc));
3851 } else {
3852 /* we didn't pre-calculate rxdesc_start in case of ACX100 */
3853 /* rxdesc_start should be right AFTER Tx pool */
3854 adev->rxdesc_start = (rxdesc_t *)
3855 ((u8 *) adev->txdesc_start + (TX_CNT * sizeof(txdesc_t)));
3856 /* NB: sizeof(txdesc_t) above is valid because we know
3857 ** we are in if (acx100) block. Beware of cut-n-pasting elsewhere!
3858 ** acx111's txdesc is larger! */
3860 memset(adev->rxdesc_start, 0, RX_CNT * sizeof(*rxdesc));
3862 /* loop over whole receive pool */
3863 rxdesc = adev->rxdesc_start;
3864 mem_offs = rx_queue_start;
3865 for (i = 0; i < RX_CNT; i++) {
3866 log(L_DEBUG, "rx descriptor @ 0x%p\n", rxdesc);
3867 rxdesc->Ctl_8 = DESC_CTL_RECLAIM | DESC_CTL_AUTODMA;
3868 /* point to next rxdesc */
3869 rxdesc->pNextDesc = cpu2acx(mem_offs + sizeof(*rxdesc));
3870 /* go to the next one */
3871 mem_offs += sizeof(*rxdesc);
3872 rxdesc++;
3874 /* go to the last one */
3875 rxdesc--;
3877 /* and point to the first making it a ring buffer */
3878 rxdesc->pNextDesc = cpu2acx(rx_queue_start);
3880 FN_EXIT0;
3884 /***************************************************************
3885 ** acxpci_create_desc_queues
3887 void
3888 acxpci_create_desc_queues(acx_device_t * adev, u32 tx_queue_start,
3889 u32 rx_queue_start)
3891 acxpci_create_tx_desc_queue(adev, tx_queue_start);
3892 acxpci_create_rx_desc_queue(adev, rx_queue_start);
3896 /***************************************************************
3897 ** acxpci_s_proc_diag_output
3899 char *acxpci_s_proc_diag_output(char *p, acx_device_t * adev)
3901 const char *rtl, *thd, *ttl;
3902 rxhostdesc_t *rxhostdesc;
3903 txdesc_t *txdesc;
3904 int i;
3906 FN_ENTER;
3908 p += sprintf(p, "** Rx buf **\n");
3909 rxhostdesc = adev->rxhostdesc_start;
3910 if (rxhostdesc)
3911 for (i = 0; i < RX_CNT; i++) {
3912 rtl = (i == adev->rx_tail) ? " [tail]" : "";
3913 if ((rxhostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
3914 && (rxhostdesc->
3915 Status & cpu_to_le32(DESC_STATUS_FULL)))
3916 p += sprintf(p, "%02u FULL%s\n", i, rtl);
3917 else
3918 p += sprintf(p, "%02u empty%s\n", i, rtl);
3919 rxhostdesc++;
3921 /* p += sprintf(p, "** Tx buf (free %d, Linux netqueue %s) **\n",
3922 adev->tx_free,
3923 acx_queue_stopped(adev->ieee) ? "STOPPED" : "running");*/
3924 txdesc = adev->txdesc_start;
3925 if (txdesc)
3926 for (i = 0; i < TX_CNT; i++) {
3927 thd = (i == adev->tx_head) ? " [head]" : "";
3928 ttl = (i == adev->tx_tail) ? " [tail]" : "";
3929 if (txdesc->Ctl_8 & DESC_CTL_ACXDONE)
3930 p += sprintf(p, "%02u free (%02X)%s%s\n", i,
3931 txdesc->Ctl_8, thd, ttl);
3932 else
3933 p += sprintf(p, "%02u tx (%02X)%s%s\n", i,
3934 txdesc->Ctl_8, thd, ttl);
3935 txdesc = advance_txdesc(adev, txdesc, 1);
3937 p += sprintf(p,
3938 "\n"
3939 "** PCI data **\n"
3940 "txbuf_start %p, txbuf_area_size %u, txbuf_startphy %08llx\n"
3941 "txdesc_size %u, txdesc_start %p\n"
3942 "txhostdesc_start %p, txhostdesc_area_size %u, txhostdesc_startphy %08llx\n"
3943 "rxdesc_start %p\n"
3944 "rxhostdesc_start %p, rxhostdesc_area_size %u, rxhostdesc_startphy %08llx\n"
3945 "rxbuf_start %p, rxbuf_area_size %u, rxbuf_startphy %08llx\n",
3946 adev->txbuf_start, adev->txbuf_area_size,
3947 (unsigned long long)adev->txbuf_startphy,
3948 adev->txdesc_size, adev->txdesc_start,
3949 adev->txhostdesc_start, adev->txhostdesc_area_size,
3950 (unsigned long long)adev->txhostdesc_startphy,
3951 adev->rxdesc_start,
3952 adev->rxhostdesc_start, adev->rxhostdesc_area_size,
3953 (unsigned long long)adev->rxhostdesc_startphy,
3954 adev->rxbuf_start, adev->rxbuf_area_size,
3955 (unsigned long long)adev->rxbuf_startphy);
3957 FN_EXIT0;
3958 return p;
3962 /***********************************************************************
3964 int acxpci_proc_eeprom_output(char *buf, acx_device_t * adev)
3966 char *p = buf;
3967 int i;
3969 FN_ENTER;
3971 for (i = 0; i < 0x400; i++) {
3972 acxpci_read_eeprom_byte(adev, i, p++);
3975 FN_EXIT1(p - buf);
3976 return p - buf;
3980 /***********************************************************************
3981 ** Obvious
3983 void acxpci_set_interrupt_mask(acx_device_t * adev)
3985 if (IS_ACX111(adev)) {
3986 adev->irq_mask = (u16) ~ (0
3987 /* | HOST_INT_RX_DATA */
3988 | HOST_INT_TX_COMPLETE
3989 /* | HOST_INT_TX_XFER */
3990 | HOST_INT_RX_COMPLETE
3991 /* | HOST_INT_DTIM */
3992 /* | HOST_INT_BEACON */
3993 /* | HOST_INT_TIMER */
3994 /* | HOST_INT_KEY_NOT_FOUND */
3995 | HOST_INT_IV_ICV_FAILURE
3996 | HOST_INT_CMD_COMPLETE
3997 | HOST_INT_INFO
3998 /* | HOST_INT_OVERFLOW */
3999 /* | HOST_INT_PROCESS_ERROR */
4000 | HOST_INT_SCAN_COMPLETE
4001 | HOST_INT_FCS_THRESHOLD
4002 /* | HOST_INT_UNKNOWN */
4004 /* Or else acx100 won't signal cmd completion, right? */
4005 adev->irq_mask_off = (u16) ~ (HOST_INT_CMD_COMPLETE); /* 0xfdff */
4006 } else {
4007 adev->irq_mask = (u16) ~ (0
4008 /* | HOST_INT_RX_DATA */
4009 | HOST_INT_TX_COMPLETE
4010 /* | HOST_INT_TX_XFER */
4011 | HOST_INT_RX_COMPLETE
4012 /* | HOST_INT_DTIM */
4013 /* | HOST_INT_BEACON */
4014 /* | HOST_INT_TIMER */
4015 /* | HOST_INT_KEY_NOT_FOUND */
4016 /* | HOST_INT_IV_ICV_FAILURE */
4017 | HOST_INT_CMD_COMPLETE
4018 | HOST_INT_INFO
4019 /* | HOST_INT_OVERFLOW */
4020 /* | HOST_INT_PROCESS_ERROR */
4021 | HOST_INT_SCAN_COMPLETE
4022 /* | HOST_INT_FCS_THRESHOLD */
4023 /* | HOST_INT_UNKNOWN */
4025 adev->irq_mask_off = (u16) ~ (HOST_INT_UNKNOWN); /* 0x7fff */
4030 /***********************************************************************
4032 int acx100pci_s_set_tx_level(acx_device_t * adev, u8 level_dbm)
4034 /* since it can be assumed that at least the Maxim radio has a
4035 * maximum power output of 20dBm and since it also can be
4036 * assumed that these values drive the DAC responsible for
4037 * setting the linear Tx level, I'd guess that these values
4038 * should be the corresponding linear values for a dBm value,
4039 * in other words: calculate the values from that formula:
4040 * Y [dBm] = 10 * log (X [mW])
4041 * then scale the 0..63 value range onto the 1..100mW range (0..20 dBm)
4042 * and you're done...
4043 * Hopefully that's ok, but you never know if we're actually
4044 * right... (especially since Windows XP doesn't seem to show
4045 * actual Tx dBm values :-P) */
4047 /* NOTE: on Maxim, value 30 IS 30mW, and value 10 IS 10mW - so the
4048 * values are EXACTLY mW!!! Not sure about RFMD and others,
4049 * though... */
4050 static const u8 dbm2val_maxim[21] = {
4051 63, 63, 63, 62,
4052 61, 61, 60, 60,
4053 59, 58, 57, 55,
4054 53, 50, 47, 43,
4055 38, 31, 23, 13,
4058 static const u8 dbm2val_rfmd[21] = {
4059 0, 0, 0, 1,
4060 2, 2, 3, 3,
4061 4, 5, 6, 8,
4062 10, 13, 16, 20,
4063 25, 32, 41, 50,
4066 const u8 *table;
4068 switch (adev->radio_type) {
4069 case RADIO_MAXIM_0D:
4070 table = &dbm2val_maxim[0];
4071 break;
4072 case RADIO_RFMD_11:
4073 case RADIO_RALINK_15:
4074 table = &dbm2val_rfmd[0];
4075 break;
4076 default:
4077 printk("%s: unknown/unsupported radio type, "
4078 "cannot modify tx power level yet!\n", wiphy_name(adev->ieee->wiphy));
4079 return NOT_OK;
4081 printk("%s: changing radio power level to %u dBm (%u)\n",
4082 wiphy_name(adev->ieee->wiphy), level_dbm, table[level_dbm]);
4083 acxpci_s_write_phy_reg(adev, 0x11, table[level_dbm]);
4084 return OK;
4088 /***********************************************************************
4089 ** Data for init_module/cleanup_module
4091 static const struct pci_device_id acxpci_id_tbl[] __devinitdata = {
4093 .vendor = PCI_VENDOR_ID_TI,
4094 .device = PCI_DEVICE_ID_TI_TNETW1100A,
4095 .subvendor = PCI_ANY_ID,
4096 .subdevice = PCI_ANY_ID,
4097 .driver_data = CHIPTYPE_ACX100,
4100 .vendor = PCI_VENDOR_ID_TI,
4101 .device = PCI_DEVICE_ID_TI_TNETW1100B,
4102 .subvendor = PCI_ANY_ID,
4103 .subdevice = PCI_ANY_ID,
4104 .driver_data = CHIPTYPE_ACX100,
4107 .vendor = PCI_VENDOR_ID_TI,
4108 .device = PCI_DEVICE_ID_TI_TNETW1130,
4109 .subvendor = PCI_ANY_ID,
4110 .subdevice = PCI_ANY_ID,
4111 .driver_data = CHIPTYPE_ACX111,
4114 .vendor = 0,
4115 .device = 0,
4116 .subvendor = 0,
4117 .subdevice = 0,
4118 .driver_data = 0,
4122 MODULE_DEVICE_TABLE(pci, acxpci_id_tbl);
4124 /* FIXME: checks should be removed once driver is included in the kernel */
4125 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 11)
4126 /* pci_name() got introduced at start of 2.6.x,
4127 * got mandatory (slot_name member removed) in 2.6.11-bk1 */
4128 #define pci_name(x) x->slot_name
4129 #endif
4131 static struct pci_driver
4132 acxpci_drv_id = {
4133 .name = "acx_pci",
4134 .id_table = acxpci_id_tbl,
4135 .probe = acxpci_e_probe,
4136 .remove = __devexit_p(acxpci_e_remove),
4137 #ifdef CONFIG_PM
4138 .suspend = acxpci_e_suspend,
4139 .resume = acxpci_e_resume
4140 #endif /* CONFIG_PM */
4144 /***********************************************************************
4145 ** acxpci_e_init_module
4147 ** Module initialization routine, called once at module load time
4149 int __init acxpci_e_init_module(void)
4151 int res;
4153 FN_ENTER;
4155 #if (ACX_IO_WIDTH==32)
4156 printk("acx: compiled to use 32bit I/O access. "
4157 "I/O timing issues might occur, such as "
4158 "non-working firmware upload. Report them\n");
4159 #else
4160 printk("acx: compiled to use 16bit I/O access only "
4161 "(compatibility mode)\n");
4162 #endif
4164 #ifdef __LITTLE_ENDIAN
4165 #define ENDIANNESS_STRING "running on a little-endian CPU\n"
4166 #else
4167 #define ENDIANNESS_STRING "running on a BIG-ENDIAN CPU\n"
4168 #endif
4169 log(L_INIT,
4170 "acx: " ENDIANNESS_STRING
4171 "acx: PCI module " ACX_RELEASE " initialized, "
4172 "waiting for cards to probe...\n");
4174 res = pci_register_driver(&acxpci_drv_id);
4175 FN_EXIT1(res);
4176 return res;
4180 /***********************************************************************
4181 ** acxpci_e_cleanup_module
4183 ** Called at module unload time. This is our last chance to
4184 ** clean up after ourselves.
4186 void __exit acxpci_e_cleanup_module(void)
4188 FN_ENTER;
4190 pci_unregister_driver(&acxpci_drv_id);
4191 log(L_INIT,
4192 "acx: PCI module " ACX_RELEASE " unloaded\n");
4193 FN_EXIT0;