reverted some changes from 9a2483499c2923e493d00b5c9818dad7f88f5ffb
[acx-mac80211.git] / pci.c
blob9713f8a8e0918368964ab63269c496d5148436e2
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 static int acxpci_e_close(struct ieee80211_hw *hw);
87 static void acxpci_s_up(struct ieee80211_hw *hw);
88 static void acxpci_s_down(struct ieee80211_hw *hw);
90 void acxpci_put_devname(acx_device_t *adev, struct ethtool_drvinfo *info)
93 strncpy(info->bus_info,pci_name(adev->pdev), ETHTOOL_BUSINFO_LEN);
96 /***********************************************************************
97 ** Register access
99 **
102 /* OS I/O routines *always* be endianness-clean but having them doesn't hurt */
103 #define acx_readl(v) le32_to_cpu(readl((v)))
104 #define acx_readw(v) le16_to_cpu(readw((v)))
105 #define acx_writew(v,r) writew(le16_to_cpu((v)), r)
106 #define acx_writel(v,r) writel(le32_to_cpu((v)), r)
108 /* Pick one */
109 /* #define INLINE_IO static */
110 #define INLINE_IO static inline
112 INLINE_IO u32 read_reg32(acx_device_t * adev, unsigned int offset)
114 #if ACX_IO_WIDTH == 32
115 return acx_readl((u8 *) adev->iobase + adev->io[offset]);
116 #else
117 return acx_readw((u8 *) adev->iobase + adev->io[offset])
118 + (acx_readw((u8 *) adev->iobase + adev->io[offset] + 2) << 16);
119 #endif
122 INLINE_IO u16 read_reg16(acx_device_t * adev, unsigned int offset)
124 return acx_readw((u8 *) adev->iobase + adev->io[offset]);
127 INLINE_IO u8 read_reg8(acx_device_t * adev, unsigned int offset)
129 return readb((u8 *) adev->iobase + adev->io[offset]);
132 INLINE_IO void write_reg32(acx_device_t * adev, unsigned int offset, u32 val)
134 #if ACX_IO_WIDTH == 32
135 acx_writel(val, (u8 *) adev->iobase + adev->io[offset]);
136 #else
137 acx_writew(val & 0xffff, (u8 *) adev->iobase + adev->io[offset]);
138 acx_writew(val >> 16, (u8 *) adev->iobase + adev->io[offset] + 2);
139 #endif
142 INLINE_IO void write_reg16(acx_device_t * adev, unsigned int offset, u16 val)
144 acx_writew(val, (u8 *) adev->iobase + adev->io[offset]);
147 INLINE_IO void write_reg8(acx_device_t * adev, unsigned int offset, u8 val)
149 writeb(val, (u8 *) adev->iobase + adev->io[offset]);
152 /* Handle PCI posting properly:
153 * Make sure that writes reach the adapter in case they require to be executed
154 * *before* the next write, by reading a random (and safely accessible) register.
155 * This call has to be made if there is no read following (which would flush the data
156 * to the adapter), yet the written data has to reach the adapter immediately. */
157 INLINE_IO void write_flush(acx_device_t * adev)
159 /* readb(adev->iobase + adev->io[IO_ACX_INFO_MAILBOX_OFFS]); */
160 /* faster version (accesses the first register, IO_ACX_SOFT_RESET,
161 * which should also be safe): */
162 readb(adev->iobase);
165 INLINE_IO int adev_present(acx_device_t * adev)
167 /* fast version (accesses the first register, IO_ACX_SOFT_RESET,
168 * which should be safe): */
169 return acx_readl(adev->iobase) != 0xffffffff;
173 /***********************************************************************
175 static inline txdesc_t *get_txdesc(acx_device_t * adev, int index)
177 return (txdesc_t *) (((u8 *) adev->txdesc_start) +
178 index * adev->txdesc_size);
181 static inline txdesc_t *advance_txdesc(acx_device_t * adev, txdesc_t * txdesc,
182 int inc)
184 return (txdesc_t *) (((u8 *) txdesc) + inc * adev->txdesc_size);
187 static txhostdesc_t *get_txhostdesc(acx_device_t * adev, txdesc_t * txdesc)
189 int index = (u8 *) txdesc - (u8 *) adev->txdesc_start;
190 if (unlikely(ACX_DEBUG && (index % adev->txdesc_size))) {
191 printk("bad txdesc ptr %p\n", txdesc);
192 return NULL;
194 index /= adev->txdesc_size;
195 if (unlikely(ACX_DEBUG && (index >= TX_CNT))) {
196 printk("bad txdesc ptr %p\n", txdesc);
197 return NULL;
199 return &adev->txhostdesc_start[index * 2];
206 /***********************************************************************
207 ** EEPROM and PHY read/write helpers
209 /***********************************************************************
210 ** acxpci_read_eeprom_byte
212 ** Function called to read an octet in the EEPROM.
214 ** This function is used by acxpci_e_probe to check if the
215 ** connected card is a legal one or not.
217 ** Arguments:
218 ** adev ptr to acx_device structure
219 ** addr address to read in the EEPROM
220 ** charbuf ptr to a char. This is where the read octet
221 ** will be stored
224 int acxpci_read_eeprom_byte(acx_device_t * adev, u32 addr, u8 * charbuf)
226 int result;
227 int count;
229 FN_ENTER;
231 write_reg32(adev, IO_ACX_EEPROM_CFG, 0);
232 write_reg32(adev, IO_ACX_EEPROM_ADDR, addr);
233 write_flush(adev);
234 write_reg32(adev, IO_ACX_EEPROM_CTL, 2);
236 count = 0xffff;
237 while (read_reg16(adev, IO_ACX_EEPROM_CTL)) {
238 /* scheduling away instead of CPU burning loop
239 * doesn't seem to work here at all:
240 * awful delay, sometimes also failure.
241 * Doesn't matter anyway (only small delay). */
242 if (unlikely(!--count)) {
243 printk("%s: timeout waiting for EEPROM read\n",
244 wiphy_name(adev->ieee->wiphy));
245 result = NOT_OK;
246 goto fail;
248 cpu_relax();
251 *charbuf = read_reg8(adev, IO_ACX_EEPROM_DATA);
252 log(L_DEBUG, "EEPROM at 0x%04X = 0x%02X\n", addr, *charbuf);
253 result = OK;
255 fail:
256 FN_EXIT1(result);
257 return result;
261 /***********************************************************************
262 ** We don't lock hw accesses here since we never r/w eeprom in IRQ
263 ** Note: this function sleeps only because of GFP_KERNEL alloc
265 #ifdef UNUSED
267 acxpci_s_write_eeprom(acx_device_t * adev, u32 addr, u32 len,
268 const u8 * charbuf)
270 u8 *data_verify = NULL;
271 unsigned long flags;
272 int count, i;
273 int result = NOT_OK;
274 u16 gpio_orig;
276 printk("acx: WARNING! I would write to EEPROM now. "
277 "Since I really DON'T want to unless you know "
278 "what you're doing (THIS CODE WILL PROBABLY "
279 "NOT WORK YET!), I will abort that now. And "
280 "definitely make sure to make a "
281 "/proc/driver/acx_wlan0_eeprom backup copy first!!! "
282 "(the EEPROM content includes the PCI config header!! "
283 "If you kill important stuff, then you WILL "
284 "get in trouble and people DID get in trouble already)\n");
285 return OK;
287 FN_ENTER;
289 data_verify = kmalloc(len, GFP_KERNEL);
290 if (!data_verify) {
291 goto end;
294 /* first we need to enable the OE (EEPROM Output Enable) GPIO line
295 * to be able to write to the EEPROM.
296 * NOTE: an EEPROM writing success has been reported,
297 * but you probably have to modify GPIO_OUT, too,
298 * and you probably need to activate a different GPIO
299 * line instead! */
300 gpio_orig = read_reg16(adev, IO_ACX_GPIO_OE);
301 write_reg16(adev, IO_ACX_GPIO_OE, gpio_orig & ~1);
302 write_flush(adev);
304 /* ok, now start writing the data out */
305 for (i = 0; i < len; i++) {
306 write_reg32(adev, IO_ACX_EEPROM_CFG, 0);
307 write_reg32(adev, IO_ACX_EEPROM_ADDR, addr + i);
308 write_reg32(adev, IO_ACX_EEPROM_DATA, *(charbuf + i));
309 write_flush(adev);
310 write_reg32(adev, IO_ACX_EEPROM_CTL, 1);
312 count = 0xffff;
313 while (read_reg16(adev, IO_ACX_EEPROM_CTL)) {
314 if (unlikely(!--count)) {
315 printk("WARNING, DANGER!!! "
316 "Timeout waiting for EEPROM write\n");
317 goto end;
319 cpu_relax();
323 /* disable EEPROM writing */
324 write_reg16(adev, IO_ACX_GPIO_OE, gpio_orig);
325 write_flush(adev);
327 /* now start a verification run */
328 for (i = 0; i < len; i++) {
329 write_reg32(adev, IO_ACX_EEPROM_CFG, 0);
330 write_reg32(adev, IO_ACX_EEPROM_ADDR, addr + i);
331 write_flush(adev);
332 write_reg32(adev, IO_ACX_EEPROM_CTL, 2);
334 count = 0xffff;
335 while (read_reg16(adev, IO_ACX_EEPROM_CTL)) {
336 if (unlikely(!--count)) {
337 printk("timeout waiting for EEPROM read\n");
338 goto end;
340 cpu_relax();
343 data_verify[i] = read_reg16(adev, IO_ACX_EEPROM_DATA);
346 if (0 == memcmp(charbuf, data_verify, len))
347 result = OK; /* read data matches, success */
349 end:
350 kfree(data_verify);
351 FN_EXIT1(result);
352 return result;
354 #endif /* UNUSED */
357 /***********************************************************************
358 ** acxpci_s_read_phy_reg
360 ** Messing with rx/tx disabling and enabling here
361 ** (write_reg32(adev, IO_ACX_ENABLE, 0b000000xx)) kills traffic
363 int acxpci_s_read_phy_reg(acx_device_t * adev, u32 reg, u8 * charbuf)
365 int result = NOT_OK;
366 int count;
368 FN_ENTER;
370 write_reg32(adev, IO_ACX_PHY_ADDR, reg);
371 write_flush(adev);
372 write_reg32(adev, IO_ACX_PHY_CTL, 2);
374 count = 0xffff;
375 while (read_reg32(adev, IO_ACX_PHY_CTL)) {
376 /* scheduling away instead of CPU burning loop
377 * doesn't seem to work here at all:
378 * awful delay, sometimes also failure.
379 * Doesn't matter anyway (only small delay). */
380 if (unlikely(!--count)) {
381 printk("%s: timeout waiting for phy read\n",
382 wiphy_name(adev->ieee->wiphy));
383 *charbuf = 0;
384 goto fail;
386 cpu_relax();
389 log(L_DEBUG, "count was %u\n", count);
390 *charbuf = read_reg8(adev, IO_ACX_PHY_DATA);
392 log(L_DEBUG, "radio PHY at 0x%04X = 0x%02X\n", *charbuf, reg);
393 result = OK;
394 goto fail; /* silence compiler warning */
395 fail:
396 FN_EXIT1(result);
397 return result;
401 /***********************************************************************
403 int acxpci_s_write_phy_reg(acx_device_t * adev, u32 reg, u8 value)
405 FN_ENTER;
407 /* mprusko said that 32bit accesses result in distorted sensitivity
408 * on his card. Unconfirmed, looks like it's not true (most likely since we
409 * now properly flush writes). */
410 write_reg32(adev, IO_ACX_PHY_DATA, value);
411 write_reg32(adev, IO_ACX_PHY_ADDR, reg);
412 write_flush(adev);
413 write_reg32(adev, IO_ACX_PHY_CTL, 1);
414 write_flush(adev);
415 log(L_DEBUG, "radio PHY write 0x%02X at 0x%04X\n", value, reg);
417 FN_EXIT0;
418 return OK;
422 #define NO_AUTO_INCREMENT 1
424 /***********************************************************************
425 ** acxpci_s_write_fw
427 ** Write the firmware image into the card.
429 ** Arguments:
430 ** adev wlan device structure
431 ** fw_image firmware image.
433 ** Returns:
434 ** 1 firmware image corrupted
435 ** 0 success
437 ** Standard csum implementation + write to IO
439 static int
440 acxpci_s_write_fw(acx_device_t * adev, const firmware_image_t *fw_image,
441 u32 offset)
443 int len, size;
444 u32 sum, v32;
445 /* we skip the first four bytes which contain the control sum */
447 const u8 *p = (u8 *) fw_image + 4;
449 FN_ENTER;
451 /* start the image checksum by adding the image size value */
452 sum = p[0] + p[1] + p[2] + p[3];
453 p += 4;
455 write_reg32(adev, IO_ACX_SLV_END_CTL, 0);
457 #if NO_AUTO_INCREMENT
458 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 0); /* use basic mode */
459 #else
460 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 1); /* use autoincrement mode */
461 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset); /* configure start address */
462 write_flush(adev);
463 #endif
465 len = 0;
466 size = le32_to_cpu(fw_image->size) & (~3);
468 while (likely(len < size)) {
469 v32 = be32_to_cpu(*(u32 *) p);
470 sum += p[0] + p[1] + p[2] + p[3];
471 p += 4;
472 len += 4;
474 #if NO_AUTO_INCREMENT
475 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset + len - 4);
476 write_flush(adev);
477 #endif
478 write_reg32(adev, IO_ACX_SLV_MEM_DATA, v32);
481 log(L_DEBUG, "firmware written, size:%d sum1:%x sum2:%x\n",
482 size, sum, le32_to_cpu(fw_image->chksum));
484 /* compare our checksum with the stored image checksum */
485 FN_EXIT1(sum != le32_to_cpu(fw_image->chksum));
486 return (sum != le32_to_cpu(fw_image->chksum));
490 /***********************************************************************
491 ** acxpci_s_validate_fw
493 ** Compare the firmware image given with
494 ** the firmware image written into the card.
496 ** Arguments:
497 ** adev wlan device structure
498 ** fw_image firmware image.
500 ** Returns:
501 ** NOT_OK firmware image corrupted or not correctly written
502 ** OK success
504 ** Origin: Standard csum + Read IO
506 static int
507 acxpci_s_validate_fw(acx_device_t * adev, const firmware_image_t *fw_image,
508 u32 offset)
510 u32 sum, v32, w32;
511 int len, size;
512 int result = OK;
513 /* we skip the first four bytes which contain the control sum */
514 const u8 *p = (u8 *) fw_image + 4;
516 FN_ENTER;
518 /* start the image checksum by adding the image size value */
519 sum = p[0] + p[1] + p[2] + p[3];
520 p += 4;
522 write_reg32(adev, IO_ACX_SLV_END_CTL, 0);
524 #if NO_AUTO_INCREMENT
525 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 0); /* use basic mode */
526 #else
527 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 1); /* use autoincrement mode */
528 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset); /* configure start address */
529 #endif
531 len = 0;
532 size = le32_to_cpu(fw_image->size) & (~3);
534 while (likely(len < size)) {
535 v32 = be32_to_cpu(*(u32 *) p);
536 p += 4;
537 len += 4;
539 #if NO_AUTO_INCREMENT
540 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset + len - 4);
541 #endif
542 w32 = read_reg32(adev, IO_ACX_SLV_MEM_DATA);
544 if (unlikely(w32 != v32)) {
545 printk("acx: FATAL: firmware upload: "
546 "data parts at offset %d don't match (0x%08X vs. 0x%08X)! "
547 "I/O timing issues or defective memory, with DWL-xx0+? "
548 "ACX_IO_WIDTH=16 may help. Please report\n",
549 len, v32, w32);
550 result = NOT_OK;
551 break;
554 sum +=
555 (u8) w32 + (u8) (w32 >> 8) + (u8) (w32 >> 16) +
556 (u8) (w32 >> 24);
559 /* sum control verification */
560 if (result != NOT_OK) {
561 if (sum != le32_to_cpu(fw_image->chksum)) {
562 printk("acx: FATAL: firmware upload: "
563 "checksums don't match!\n");
564 result = NOT_OK;
568 FN_EXIT1(result);
569 return result;
573 /***********************************************************************
574 ** acxpci_s_upload_fw
576 ** Called from acx_reset_dev
578 ** Origin: Derived from FW dissection
580 static int acxpci_s_upload_fw(acx_device_t * adev)
582 firmware_image_t *fw_image = NULL;
583 int res = NOT_OK;
584 int try;
585 u32 file_size;
586 char filename[sizeof("tiacx1NNcNN")];
588 FN_ENTER;
590 /* print exact chipset and radio ID to make sure people
591 * really get a clue on which files exactly they need to provide.
592 * Firmware loading is a frequent end-user PITA with these chipsets.
594 printk( "acx: need firmware for acx1%02d chipset with radio ID %02X\n"
595 "Please provide via firmware hotplug:\n"
596 "either combined firmware (single file named 'tiacx1%02dc%02X')\n"
597 "or two files (base firmware file 'tiacx1%02d' "
598 "+ radio fw 'tiacx1%02dr%02X')\n",
599 IS_ACX111(adev)*11, adev->radio_type,
600 IS_ACX111(adev)*11, adev->radio_type,
601 IS_ACX111(adev)*11,
602 IS_ACX111(adev)*11, adev->radio_type
605 /* print exact chipset and radio ID to make sure people really get a clue on which files exactly they are supposed to provide,
606 * since firmware loading is the biggest enduser PITA with these chipsets.
607 * Not printing radio ID in 0xHEX in order to not confuse them into wrong file naming */
608 printk( "acx: need to load firmware for acx1%02d chipset with radio ID %02x, please provide via firmware hotplug:\n"
609 "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",
610 IS_ACX111(adev)*11, adev->radio_type);
612 /* Try combined, then main image */
613 adev->need_radio_fw = 0;
614 snprintf(filename, sizeof(filename), "tiacx1%02dc%02X",
615 IS_ACX111(adev) * 11, adev->radio_type);
617 fw_image = acx_s_read_fw(&adev->pdev->dev, filename, &file_size);
618 if (!fw_image) {
619 adev->need_radio_fw = 1;
620 filename[sizeof("tiacx1NN") - 1] = '\0';
621 fw_image =
622 acx_s_read_fw(&adev->pdev->dev, filename, &file_size);
623 if (!fw_image) {
624 FN_EXIT1(NOT_OK);
625 return NOT_OK;
629 for (try = 1; try <= 5; try++) {
630 res = acxpci_s_write_fw(adev, fw_image, 0);
631 log(L_DEBUG | L_INIT, "acx_write_fw (main/combined): %d\n", res);
632 if (OK == res) {
633 res = acxpci_s_validate_fw(adev, fw_image, 0);
634 log(L_DEBUG | L_INIT, "acx_validate_fw "
635 "(main/combined): %d\n", res);
638 if (OK == res) {
639 SET_BIT(adev->dev_state_mask, ACX_STATE_FW_LOADED);
640 break;
642 printk("acx: firmware upload attempt #%d FAILED, "
643 "retrying...\n", try);
644 acx_s_msleep(1000); /* better wait for a while... */
647 vfree(fw_image);
649 FN_EXIT1(res);
650 return res;
654 /***********************************************************************
655 ** acxpci_s_upload_radio
657 ** Uploads the appropriate radio module firmware into the card.
659 ** Origin: Standard Read/Write to IO
661 int acxpci_s_upload_radio(acx_device_t * adev)
663 acx_ie_memmap_t mm;
664 firmware_image_t *radio_image;
665 acx_cmd_radioinit_t radioinit;
666 int res = NOT_OK;
667 int try;
668 u32 offset;
669 u32 size;
670 char filename[sizeof("tiacx1NNrNN")];
672 if (!adev->need_radio_fw)
673 return OK;
675 FN_ENTER;
677 acx_s_interrogate(adev, &mm, ACX1xx_IE_MEMORY_MAP);
678 offset = le32_to_cpu(mm.CodeEnd);
680 snprintf(filename, sizeof(filename), "tiacx1%02dr%02X",
681 IS_ACX111(adev) * 11, adev->radio_type);
682 radio_image = acx_s_read_fw(&adev->pdev->dev, filename, &size);
683 if (!radio_image) {
684 printk("acx: can't load radio module '%s'\n", filename);
685 goto fail;
688 acx_s_issue_cmd(adev, ACX1xx_CMD_SLEEP, NULL, 0);
690 for (try = 1; try <= 5; try++) {
691 res = acxpci_s_write_fw(adev, radio_image, offset);
692 log(L_DEBUG | L_INIT, "acx_write_fw (radio): %d\n", res);
693 if (OK == res) {
694 res = acxpci_s_validate_fw(adev, radio_image, offset);
695 log(L_DEBUG | L_INIT, "acx_validate_fw (radio): %d\n",
696 res);
699 if (OK == res)
700 break;
701 printk("acx: radio firmware upload attempt #%d FAILED, "
702 "retrying...\n", try);
703 acx_s_msleep(1000); /* better wait for a while... */
706 acx_s_issue_cmd(adev, ACX1xx_CMD_WAKE, NULL, 0);
707 radioinit.offset = cpu_to_le32(offset);
708 /* no endian conversion needed, remains in card CPU area: */
709 radioinit.len = radio_image->size;
711 vfree(radio_image);
713 if (OK != res)
714 goto fail;
716 /* will take a moment so let's have a big timeout */
717 acx_s_issue_cmd_timeo(adev, ACX1xx_CMD_RADIOINIT,
718 &radioinit, sizeof(radioinit),
719 CMD_TIMEOUT_MS(1000));
721 res = acx_s_interrogate(adev, &mm, ACX1xx_IE_MEMORY_MAP);
722 fail:
723 FN_EXIT1(res);
724 return res;
728 /***********************************************************************
729 ** acxpci_l_reset_mac
731 ** MAC will be reset
732 ** Call context: reset_dev
734 ** Origin: Standard Read/Write to IO
736 static void acxpci_l_reset_mac(acx_device_t * adev)
738 u16 temp;
740 FN_ENTER;
742 /* halt eCPU */
743 temp = read_reg16(adev, IO_ACX_ECPU_CTRL) | 0x1;
744 write_reg16(adev, IO_ACX_ECPU_CTRL, temp);
746 /* now do soft reset of eCPU, set bit */
747 temp = read_reg16(adev, IO_ACX_SOFT_RESET) | 0x1;
748 log(L_DEBUG, "enable soft reset\n");
749 write_reg16(adev, IO_ACX_SOFT_RESET, temp);
750 write_flush(adev);
752 /* now clear bit again: deassert eCPU reset */
753 log(L_DEBUG, "disable soft reset and go to init mode");
754 write_reg16(adev, IO_ACX_SOFT_RESET, temp & ~0x1);
756 /* now start a burst read from initial EEPROM */
757 temp = read_reg16(adev, IO_ACX_EE_START) | 0x1;
758 write_reg16(adev, IO_ACX_EE_START, temp);
759 write_flush(adev);
761 FN_EXIT0;
765 /***********************************************************************
766 ** acxpci_s_verify_init
768 static int acxpci_s_verify_init(acx_device_t * adev)
770 int result = NOT_OK;
771 unsigned long timeout;
773 FN_ENTER;
775 timeout = jiffies + 2 * HZ;
776 for (;;) {
777 u16 irqstat = read_reg16(adev, IO_ACX_IRQ_STATUS_NON_DES);
778 if (irqstat & HOST_INT_FCS_THRESHOLD) {
779 result = OK;
780 write_reg16(adev, IO_ACX_IRQ_ACK,
781 HOST_INT_FCS_THRESHOLD);
782 break;
784 if (time_after(jiffies, timeout))
785 break;
786 /* Init may take up to ~0.5 sec total */
787 acx_s_msleep(50);
790 FN_EXIT1(result);
791 return result;
795 /***********************************************************************
796 ** A few low-level helpers
798 ** Note: these functions are not protected by lock
799 ** and thus are never allowed to be called from IRQ.
800 ** Also they must not race with fw upload which uses same hw regs
803 /***********************************************************************
804 ** acxpci_write_cmd_type_status
806 ** Origin: Common linux implementation
809 static inline void
810 acxpci_write_cmd_type_status(acx_device_t * adev, u16 type, u16 status)
812 FN_ENTER;
813 acx_writel(type | (status << 16), adev->cmd_area);
814 write_flush(adev);
815 FN_EXIT0;
819 /***********************************************************************
820 ** acxpci_read_cmd_type_status
822 ** Origin: Common linux implementation
824 static u32 acxpci_read_cmd_type_status(acx_device_t * adev)
826 u32 cmd_type, cmd_status;
828 FN_ENTER;
830 cmd_type = acx_readl(adev->cmd_area);
831 cmd_status = (cmd_type >> 16);
832 cmd_type = (u16) cmd_type;
834 log(L_CTL, "cmd_type:%04X cmd_status:%04X [%s]\n",
835 cmd_type, cmd_status, acx_cmd_status_str(cmd_status));
837 FN_EXIT1(cmd_status);
838 return cmd_status;
842 /***********************************************************************
843 ** acxpci_s_reset_dev
845 ** Arguments:
846 ** netdevice that contains the adev variable
847 ** Returns:
848 ** NOT_OK on fail
849 ** OK on success
850 ** Side effects:
851 ** device is hard reset
852 ** Call context:
853 ** acxpci_e_probe
854 ** Comment:
855 ** This resets the device using low level hardware calls
856 ** as well as uploads and verifies the firmware to the card
859 static inline void init_mboxes(acx_device_t * adev)
861 u32 cmd_offs, info_offs;
863 FN_ENTER;
865 cmd_offs = read_reg32(adev, IO_ACX_CMD_MAILBOX_OFFS);
866 info_offs = read_reg32(adev, IO_ACX_INFO_MAILBOX_OFFS);
867 adev->cmd_area = (u8 *) adev->iobase2 + cmd_offs;
868 adev->info_area = (u8 *) adev->iobase2 + info_offs;
869 log(L_DEBUG, "iobase2=%p\n"
870 "cmd_mbox_offset=%X cmd_area=%p\n"
871 "info_mbox_offset=%X info_area=%p\n",
872 adev->iobase2,
873 cmd_offs, adev->cmd_area, info_offs, adev->info_area);
874 FN_EXIT0;
878 static inline void read_eeprom_area(acx_device_t * adev)
880 #if ACX_DEBUG > 1
881 int offs;
882 u8 tmp;
884 FN_ENTER;
886 for (offs = 0x8c; offs < 0xb9; offs++)
887 acxpci_read_eeprom_byte(adev, offs, &tmp);
889 FN_EXIT0;
890 #endif
894 int acxpci_s_reset_dev(acx_device_t * adev)
896 const char *msg = "";
897 unsigned long flags;
898 int result = NOT_OK;
899 u16 hardware_info;
900 u16 ecpu_ctrl;
901 int count;
903 FN_ENTER;
905 /* reset the device to make sure the eCPU is stopped
906 * to upload the firmware correctly */
908 acx_lock(adev, flags);
910 acxpci_l_reset_mac(adev);
912 ecpu_ctrl = read_reg16(adev, IO_ACX_ECPU_CTRL) & 1;
913 if (!ecpu_ctrl) {
914 msg = "eCPU is already running. ";
915 goto end_unlock;
917 #ifdef WE_DONT_NEED_THAT_DO_WE
918 if (read_reg16(adev, IO_ACX_SOR_CFG) & 2) {
919 /* eCPU most likely means "embedded CPU" */
920 msg = "eCPU did not start after boot from flash. ";
921 goto end_unlock;
924 /* check sense on reset flags */
925 if (read_reg16(adev, IO_ACX_SOR_CFG) & 0x10) {
926 printk("%s: eCPU did not start after boot (SOR), "
927 "is this fatal?\n", wiphy_name(adev->ieee->wiphy));
929 #endif
930 /* scan, if any, is stopped now, setting corresponding IRQ bit */
931 adev->irq_status |= HOST_INT_SCAN_COMPLETE;
933 acx_unlock(adev, flags);
935 /* need to know radio type before fw load */
936 /* Need to wait for arrival of this information in a loop,
937 * most probably since eCPU runs some init code from EEPROM
938 * (started burst read in reset_mac()) which also
939 * sets the radio type ID */
941 count = 0xffff;
942 do {
943 hardware_info = read_reg16(adev, IO_ACX_EEPROM_INFORMATION);
944 if (!--count) {
945 msg = "eCPU didn't indicate radio type";
946 goto end_fail;
948 cpu_relax();
949 } while (!(hardware_info & 0xff00)); /* radio type still zero? */
951 /* printk("DEBUG: count %d\n", count); */
952 adev->form_factor = hardware_info & 0xff;
953 adev->radio_type = hardware_info >> 8;
955 /* load the firmware */
956 if (OK != acxpci_s_upload_fw(adev))
957 goto end_fail;
959 /* acx_s_msleep(10); this one really shouldn't be required */
961 /* now start eCPU by clearing bit */
962 write_reg16(adev, IO_ACX_ECPU_CTRL, ecpu_ctrl & ~0x1);
963 log(L_DEBUG, "booted eCPU up and waiting for completion...\n");
965 /* wait for eCPU bootup */
966 if (OK != acxpci_s_verify_init(adev)) {
967 msg = "timeout waiting for eCPU. ";
968 goto end_fail;
970 log(L_DEBUG, "eCPU has woken up, card is ready to be configured\n");
972 init_mboxes(adev);
973 acxpci_write_cmd_type_status(adev, 0, 0);
975 /* test that EEPROM is readable */
976 read_eeprom_area(adev);
978 result = OK;
979 goto end;
981 /* Finish error message. Indicate which function failed */
982 end_unlock:
983 acx_unlock(adev, flags);
984 end_fail:
985 printk("acx: %sreset_dev() FAILED\n", msg);
986 end:
987 FN_EXIT1(result);
988 return result;
992 /***********************************************************************
993 ** acxpci_s_issue_cmd_timeo
995 ** Sends command to fw, extract result
997 ** NB: we do _not_ take lock inside, so be sure to not touch anything
998 ** which may interfere with IRQ handler operation
1000 ** TODO: busy wait is a bit silly, so:
1001 ** 1) stop doing many iters - go to sleep after first
1002 ** 2) go to waitqueue based approach: wait, not poll!
1004 #undef FUNC
1005 #define FUNC "issue_cmd"
1007 #if !ACX_DEBUG
1009 acxpci_s_issue_cmd_timeo(acx_device_t * adev,
1010 unsigned int cmd,
1011 void *buffer, unsigned buflen, unsigned cmd_timeout)
1013 #else
1015 acxpci_s_issue_cmd_timeo_debug(acx_device_t * adev,
1016 unsigned cmd,
1017 void *buffer,
1018 unsigned buflen,
1019 unsigned cmd_timeout, const char *cmdstr)
1021 unsigned long start = jiffies;
1022 #endif
1023 const char *devname;
1024 unsigned counter;
1025 u16 irqtype;
1026 u16 cmd_status;
1027 unsigned long timeout;
1029 FN_ENTER;
1032 devname = wiphy_name(adev->ieee->wiphy);
1033 if (!devname || !devname[0] || devname[4] == '%')
1034 devname = "acx";
1036 log(L_CTL, FUNC "(cmd:%s,buflen:%u,timeout:%ums,type:0x%04X)\n",
1037 cmdstr, buflen, cmd_timeout,
1038 buffer ? le16_to_cpu(((acx_ie_generic_t *) buffer)->type) : -1);
1040 if (!(adev->dev_state_mask & ACX_STATE_FW_LOADED)) {
1041 printk("%s: " FUNC "(): firmware is not loaded yet, "
1042 "cannot execute commands!\n", devname);
1043 goto bad;
1046 if ((acx_debug & L_DEBUG) && (cmd != ACX1xx_CMD_INTERROGATE)) {
1047 printk("input buffer (len=%u):\n", buflen);
1048 acx_dump_bytes(buffer, buflen);
1051 /* wait for firmware to become idle for our command submission */
1052 timeout = HZ / 5;
1053 counter = (timeout * 1000 / HZ) - 1; /* in ms */
1054 timeout += jiffies;
1055 do {
1056 cmd_status = acxpci_read_cmd_type_status(adev);
1057 /* Test for IDLE state */
1058 if (!cmd_status)
1059 break;
1060 if (counter % 8 == 0) {
1061 if (time_after(jiffies, timeout)) {
1062 counter = 0;
1063 break;
1065 /* we waited 8 iterations, no luck. Sleep 8 ms */
1066 acx_s_msleep(8);
1068 } while (likely(--counter));
1070 if (!counter) {
1071 /* the card doesn't get idle, we're in trouble */
1072 printk("%s: " FUNC "(): cmd_status is not IDLE: 0x%04X!=0\n",
1073 devname, cmd_status);
1074 goto bad;
1075 } else if (counter < 190) { /* if waited >10ms... */
1076 log(L_CTL | L_DEBUG, FUNC "(): waited for IDLE %dms. "
1077 "Please report\n", 199 - counter);
1080 /* now write the parameters of the command if needed */
1081 if (buffer && buflen) {
1082 /* if it's an INTERROGATE command, just pass the length
1083 * of parameters to read, as data */
1084 #if CMD_DISCOVERY
1085 if (cmd == ACX1xx_CMD_INTERROGATE)
1086 memset_io(adev->cmd_area + 4, 0xAA, buflen);
1087 #endif
1088 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1089 memcpy_toio(adev->cmd_area + 4, buffer,
1090 (cmd == ACX1xx_CMD_INTERROGATE) ? 4 : buflen);
1092 /* now write the actual command type */
1093 acxpci_write_cmd_type_status(adev, cmd, 0);
1094 /* execute command */
1095 write_reg16(adev, IO_ACX_INT_TRIG, INT_TRIG_CMD);
1096 write_flush(adev);
1098 /* wait for firmware to process command */
1100 /* Ensure nonzero and not too large timeout.
1101 ** Also converts e.g. 100->99, 200->199
1102 ** which is nice but not essential */
1103 cmd_timeout = (cmd_timeout - 1) | 1;
1104 if (unlikely(cmd_timeout > 1199))
1105 cmd_timeout = 1199;
1106 /* clear CMD_COMPLETE bit. can be set only by IRQ handler: */
1107 adev->irq_status &= ~HOST_INT_CMD_COMPLETE;
1109 /* we schedule away sometimes (timeout can be large) */
1110 counter = cmd_timeout;
1111 timeout = jiffies + cmd_timeout * HZ / 1000;
1112 do {
1113 if (!adev->irqs_active) { /* IRQ disabled: poll */
1114 irqtype = read_reg16(adev, IO_ACX_IRQ_STATUS_NON_DES);
1115 if (irqtype & HOST_INT_CMD_COMPLETE) {
1116 write_reg16(adev, IO_ACX_IRQ_ACK,
1117 HOST_INT_CMD_COMPLETE);
1118 break;
1120 } else { /* Wait when IRQ will set the bit */
1121 irqtype = adev->irq_status;
1122 if (irqtype & HOST_INT_CMD_COMPLETE)
1123 break;
1126 if (counter % 8 == 0) {
1127 if (time_after(jiffies, timeout)) {
1128 counter = 0;
1129 break;
1131 /* we waited 8 iterations, no luck. Sleep 8 ms */
1132 acx_s_msleep(8);
1134 } while (likely(--counter));
1136 /* save state for debugging */
1137 cmd_status = acxpci_read_cmd_type_status(adev);
1139 /* put the card in IDLE state */
1140 acxpci_write_cmd_type_status(adev, 0, 0);
1142 if (!counter) { /* timed out! */
1143 printk("%s: " FUNC "(): timed out %s for CMD_COMPLETE. "
1144 "irq bits:0x%04X irq_status:0x%04X timeout:%dms "
1145 "cmd_status:%d (%s)\n",
1146 devname, (adev->irqs_active) ? "waiting" : "polling",
1147 irqtype, adev->irq_status, cmd_timeout,
1148 cmd_status, acx_cmd_status_str(cmd_status));
1149 goto bad;
1150 } else if (cmd_timeout - counter > 30) { /* if waited >30ms... */
1151 log(L_CTL | L_DEBUG, FUNC "(): %s for CMD_COMPLETE %dms. "
1152 "count:%d. Please report\n",
1153 (adev->irqs_active) ? "waited" : "polled",
1154 cmd_timeout - counter, counter);
1157 if (1 != cmd_status) { /* it is not a 'Success' */
1158 printk("%s: " FUNC "(): cmd_status is not SUCCESS: %d (%s). "
1159 "Took %dms of %d\n",
1160 devname, cmd_status, acx_cmd_status_str(cmd_status),
1161 cmd_timeout - counter, cmd_timeout);
1162 /* zero out result buffer
1163 * WARNING: this will trash stack in case of illegally large input
1164 * length! */
1165 if (buffer && buflen)
1166 memset(buffer, 0, buflen);
1167 goto bad;
1170 /* read in result parameters if needed */
1171 if (buffer && buflen && (cmd == ACX1xx_CMD_INTERROGATE)) {
1172 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1173 memcpy_fromio(buffer, adev->cmd_area + 4, buflen);
1174 if (acx_debug & L_DEBUG) {
1175 printk("output buffer (len=%u): ", buflen);
1176 acx_dump_bytes(buffer, buflen);
1179 /* ok: */
1180 log(L_CTL, FUNC "(%s): took %ld jiffies to complete\n",
1181 cmdstr, jiffies - start);
1182 FN_EXIT1(OK);
1183 return OK;
1185 bad:
1186 /* Give enough info so that callers can avoid
1187 ** printing their own diagnostic messages */
1188 #if ACX_DEBUG
1189 printk("%s: " FUNC "(cmd:%s) FAILED\n", devname, cmdstr);
1190 #else
1191 printk("%s: " FUNC "(cmd:0x%04X) FAILED\n", devname, cmd);
1192 #endif
1193 dump_stack();
1194 FN_EXIT1(NOT_OK);
1195 return NOT_OK;
1199 /***********************************************************************
1201 #ifdef NONESSENTIAL_FEATURES
1202 typedef struct device_id {
1203 unsigned char id[6];
1204 char *descr;
1205 char *type;
1206 } device_id_t;
1208 static const device_id_t device_ids[] = {
1210 {'G', 'l', 'o', 'b', 'a', 'l'},
1211 NULL,
1212 NULL,
1215 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
1216 "uninitialized",
1217 "SpeedStream SS1021 or Gigafast WF721-AEX"},
1219 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85},
1220 "non-standard",
1221 "DrayTek Vigor 520"},
1223 {'?', '?', '?', '?', '?', '?'},
1224 "non-standard",
1225 "Level One WPC-0200"},
1227 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1228 "empty",
1229 "DWL-650+ variant"}
1232 static void acx_show_card_eeprom_id(acx_device_t * adev)
1234 unsigned char buffer[CARD_EEPROM_ID_SIZE];
1235 int i;
1237 FN_ENTER;
1239 memset(&buffer, 0, CARD_EEPROM_ID_SIZE);
1240 /* use direct EEPROM access */
1241 for (i = 0; i < CARD_EEPROM_ID_SIZE; i++) {
1242 if (OK != acxpci_read_eeprom_byte(adev,
1243 ACX100_EEPROM_ID_OFFSET + i,
1244 &buffer[i])) {
1245 printk("acx: reading EEPROM FAILED\n");
1246 break;
1250 for (i = 0; i < ARRAY_SIZE(device_ids); i++) {
1251 if (!memcmp(&buffer, device_ids[i].id, CARD_EEPROM_ID_SIZE)) {
1252 if (device_ids[i].descr) {
1253 printk("acx: EEPROM card ID string check "
1254 "found %s card ID: is this %s?\n",
1255 device_ids[i].descr, device_ids[i].type);
1257 break;
1260 if (i == ARRAY_SIZE(device_ids)) {
1261 printk("acx: EEPROM card ID string check found "
1262 "unknown card: expected 'Global', got '%.*s\'. "
1263 "Please report\n", CARD_EEPROM_ID_SIZE, buffer);
1265 FN_EXIT0;
1267 #endif /* NONESSENTIAL_FEATURES */
1270 /***********************************************************************
1271 ** acxpci_free_desc_queues
1273 ** Releases the queues that have been allocated, the
1274 ** others have been initialised to NULL so this
1275 ** function can be used if only part of the queues were allocated.
1278 static inline void
1279 free_coherent(struct pci_dev *hwdev, size_t size,
1280 void *vaddr, dma_addr_t dma_handle)
1282 dma_free_coherent(hwdev == NULL ? NULL : &hwdev->dev,
1283 size, vaddr, dma_handle);
1287 void acxpci_free_desc_queues(acx_device_t * adev)
1289 #define ACX_FREE_QUEUE(size, ptr, phyaddr) \
1290 if (ptr) { \
1291 free_coherent(NULL, size, ptr, phyaddr); \
1292 ptr = NULL; \
1293 size = 0; \
1296 FN_ENTER;
1298 ACX_FREE_QUEUE(adev->txhostdesc_area_size, adev->txhostdesc_start,
1299 adev->txhostdesc_startphy);
1300 ACX_FREE_QUEUE(adev->txbuf_area_size, adev->txbuf_start,
1301 adev->txbuf_startphy);
1303 adev->txdesc_start = NULL;
1305 ACX_FREE_QUEUE(adev->rxhostdesc_area_size, adev->rxhostdesc_start,
1306 adev->rxhostdesc_startphy);
1307 ACX_FREE_QUEUE(adev->rxbuf_area_size, adev->rxbuf_start,
1308 adev->rxbuf_startphy);
1310 adev->rxdesc_start = NULL;
1312 FN_EXIT0;
1316 /***********************************************************************
1317 ** acxpci_s_delete_dma_regions
1319 static void acxpci_s_delete_dma_regions(acx_device_t * adev)
1321 unsigned long flags;
1323 FN_ENTER;
1324 /* disable radio Tx/Rx. Shouldn't we use the firmware commands
1325 * here instead? Or are we that much down the road that it's no
1326 * longer possible here? */
1327 write_reg16(adev, IO_ACX_ENABLE, 0);
1329 acx_s_msleep(100);
1331 acx_lock(adev, flags);
1332 acxpci_free_desc_queues(adev);
1333 acx_unlock(adev, flags);
1335 FN_EXIT0;
1339 /***********************************************************************
1340 ** acxpci_e_probe
1342 ** Probe routine called when a PCI device w/ matching ID is found.
1343 ** Here's the sequence:
1344 ** - Allocate the PCI resources.
1345 ** - Read the PCMCIA attribute memory to make sure we have a WLAN card
1346 ** - Reset the MAC
1347 ** - Initialize the dev and wlan data
1348 ** - Initialize the MAC
1350 ** pdev - ptr to pci device structure containing info about pci configuration
1351 ** id - ptr to the device id entry that matched this device
1353 static const u16 IO_ACX100[] = {
1354 0x0000, /* IO_ACX_SOFT_RESET */
1356 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1357 0x0018, /* IO_ACX_SLV_MEM_DATA */
1358 0x001c, /* IO_ACX_SLV_MEM_CTL */
1359 0x0020, /* IO_ACX_SLV_END_CTL */
1361 0x0034, /* IO_ACX_FEMR */
1363 0x007c, /* IO_ACX_INT_TRIG */
1364 0x0098, /* IO_ACX_IRQ_MASK */
1365 0x00a4, /* IO_ACX_IRQ_STATUS_NON_DES */
1366 0x00a8, /* IO_ACX_IRQ_STATUS_CLEAR */
1367 0x00ac, /* IO_ACX_IRQ_ACK */
1368 0x00b0, /* IO_ACX_HINT_TRIG */
1370 0x0104, /* IO_ACX_ENABLE */
1372 0x0250, /* IO_ACX_EEPROM_CTL */
1373 0x0254, /* IO_ACX_EEPROM_ADDR */
1374 0x0258, /* IO_ACX_EEPROM_DATA */
1375 0x025c, /* IO_ACX_EEPROM_CFG */
1377 0x0268, /* IO_ACX_PHY_ADDR */
1378 0x026c, /* IO_ACX_PHY_DATA */
1379 0x0270, /* IO_ACX_PHY_CTL */
1381 0x0290, /* IO_ACX_GPIO_OE */
1383 0x0298, /* IO_ACX_GPIO_OUT */
1385 0x02a4, /* IO_ACX_CMD_MAILBOX_OFFS */
1386 0x02a8, /* IO_ACX_INFO_MAILBOX_OFFS */
1387 0x02ac, /* IO_ACX_EEPROM_INFORMATION */
1389 0x02d0, /* IO_ACX_EE_START */
1390 0x02d4, /* IO_ACX_SOR_CFG */
1391 0x02d8 /* IO_ACX_ECPU_CTRL */
1394 static const u16 IO_ACX111[] = {
1395 0x0000, /* IO_ACX_SOFT_RESET */
1397 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1398 0x0018, /* IO_ACX_SLV_MEM_DATA */
1399 0x001c, /* IO_ACX_SLV_MEM_CTL */
1400 0x0020, /* IO_ACX_SLV_END_CTL */
1402 0x0034, /* IO_ACX_FEMR */
1404 0x00b4, /* IO_ACX_INT_TRIG */
1405 0x00d4, /* IO_ACX_IRQ_MASK */
1406 /* we do mean NON_DES (0xf0), not NON_DES_MASK which is at 0xe0: */
1407 0x00f0, /* IO_ACX_IRQ_STATUS_NON_DES */
1408 0x00e4, /* IO_ACX_IRQ_STATUS_CLEAR */
1409 0x00e8, /* IO_ACX_IRQ_ACK */
1410 0x00ec, /* IO_ACX_HINT_TRIG */
1412 0x01d0, /* IO_ACX_ENABLE */
1414 0x0338, /* IO_ACX_EEPROM_CTL */
1415 0x033c, /* IO_ACX_EEPROM_ADDR */
1416 0x0340, /* IO_ACX_EEPROM_DATA */
1417 0x0344, /* IO_ACX_EEPROM_CFG */
1419 0x0350, /* IO_ACX_PHY_ADDR */
1420 0x0354, /* IO_ACX_PHY_DATA */
1421 0x0358, /* IO_ACX_PHY_CTL */
1423 0x0374, /* IO_ACX_GPIO_OE */
1425 0x037c, /* IO_ACX_GPIO_OUT */
1427 0x0388, /* IO_ACX_CMD_MAILBOX_OFFS */
1428 0x038c, /* IO_ACX_INFO_MAILBOX_OFFS */
1429 0x0390, /* IO_ACX_EEPROM_INFORMATION */
1431 0x0100, /* IO_ACX_EE_START */
1432 0x0104, /* IO_ACX_SOR_CFG */
1433 0x0108, /* IO_ACX_ECPU_CTRL */
1436 static const struct ieee80211_ops acxpci_hw_ops = {
1437 .tx = acx_i_start_xmit,
1438 .conf_tx = acx_net_conf_tx,
1439 .add_interface = acx_add_interface,
1440 .remove_interface = acx_remove_interface,
1441 .open = acxpci_e_open,
1442 .stop = acxpci_e_close,
1443 /* .reset = acx_net_reset,*/
1444 .config = acx_net_config,
1445 .config_interface = acx_config_interface,
1446 .set_multicast_list = acx_i_set_multicast_list,
1447 .set_key = acx_net_set_key,
1448 .get_stats = acx_e_get_stats,
1449 .get_tx_stats = acx_net_get_tx_stats,
1453 static int __devinit
1454 acxpci_e_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1456 acx111_ie_configoption_t co;
1457 unsigned long mem_region1 = 0;
1458 unsigned long mem_region2 = 0;
1459 unsigned long mem_region1_size;
1460 unsigned long mem_region2_size;
1461 unsigned long phymem1;
1462 unsigned long phymem2;
1463 void *mem1 = NULL;
1464 void *mem2 = NULL;
1465 acx_device_t *adev = NULL;
1466 const char *chip_name;
1467 int result = -EIO;
1468 int err;
1469 u8 chip_type;
1470 struct ieee80211_hw *ieee;
1472 FN_ENTER;
1474 ieee = ieee80211_alloc_hw(sizeof(struct acx_device), &acxpci_hw_ops);
1475 if (!ieee) {
1476 printk("acx: could not allocate ieee80211 structure %s\n",
1477 pci_name(pdev));
1478 goto fail_alloc_netdev;
1480 ieee->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
1481 ieee->queues = 1;
1483 /* (NB: memsets to 0 entire area) */
1484 if (!ieee) {
1485 printk("acx: could not allocate ieee structure %s\n",
1486 pci_name(pdev));
1487 goto fail_alloc_netdev;
1490 adev = ieee2adev(ieee);
1492 memset(adev, 0, sizeof(*adev));
1493 /** Set up our private interface **/
1494 spin_lock_init(&adev->lock); /* initial state: unlocked */
1495 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
1496 mutex_init(&adev->mutex);
1497 /* since nobody can see new netdev yet, we can as well
1498 ** just _presume_ that we're under sem (instead of actually taking it): */
1499 /* acx_sem_lock(adev); */
1500 adev->ieee = ieee;
1501 adev->pdev = pdev;
1502 adev->dev_type = DEVTYPE_PCI;
1504 /** Finished with private interface **/
1506 /** begin board specific inits **/
1507 pci_set_drvdata(pdev, ieee);
1509 /* Enable the PCI device */
1510 if (pci_enable_device(pdev)) {
1511 printk("acx: pci_enable_device() FAILED\n");
1512 result = -ENODEV;
1513 goto fail_pci_enable_device;
1516 /* enable busmastering (required for CardBus) */
1517 pci_set_master(pdev);
1520 /* chiptype is u8 but id->driver_data is ulong
1521 ** Works for now (possible values are 1 and 2) */
1522 chip_type = (u8) id->driver_data;
1523 /* acx100 and acx111 have different PCI memory regions */
1524 if (chip_type == CHIPTYPE_ACX100) {
1525 chip_name = "ACX100";
1526 mem_region1 = PCI_ACX100_REGION1;
1527 mem_region1_size = PCI_ACX100_REGION1_SIZE;
1529 mem_region2 = PCI_ACX100_REGION2;
1530 mem_region2_size = PCI_ACX100_REGION2_SIZE;
1531 } else if (chip_type == CHIPTYPE_ACX111) {
1532 chip_name = "ACX111";
1533 mem_region1 = PCI_ACX111_REGION1;
1534 mem_region1_size = PCI_ACX111_REGION1_SIZE;
1536 mem_region2 = PCI_ACX111_REGION2;
1537 mem_region2_size = PCI_ACX111_REGION2_SIZE;
1538 } else {
1539 printk("acx: unknown chip type 0x%04X\n", chip_type);
1540 goto fail_unknown_chiptype;
1543 /* Figure out our resources */
1544 phymem1 = pci_resource_start(pdev, mem_region1);
1545 phymem2 = pci_resource_start(pdev, mem_region2);
1546 if (!request_mem_region
1547 (phymem1, pci_resource_len(pdev, mem_region1), "acx_1")) {
1548 printk("acx: cannot reserve PCI memory region 1 (are you sure "
1549 "you have CardBus support in kernel?)\n");
1550 goto fail_request_mem_region1;
1552 if (!request_mem_region
1553 (phymem2, pci_resource_len(pdev, mem_region2), "acx_2")) {
1554 printk("acx: cannot reserve PCI memory region 2\n");
1555 goto fail_request_mem_region2;
1557 /* this used to be ioremap(), but ioremap_nocache()
1558 * is much less risky, right? (and slower?)
1559 * FIXME: we may want to go back to cached variant if it's
1560 * certain that our code really properly handles
1561 * cached operation (memory barriers, volatile?, ...)
1562 * (but always keep this comment here regardless!)
1563 * Possibly make this a driver config setting?
1566 mem1 = ioremap_nocache(phymem1, mem_region1_size);
1567 if (!mem1) {
1568 printk("acx: ioremap() FAILED\n");
1569 goto fail_ioremap1;
1571 mem2 = ioremap_nocache(phymem2, mem_region2_size);
1572 if (!mem2) {
1573 printk("acx: ioremap() #2 FAILED\n");
1574 goto fail_ioremap2;
1577 printk("acx: found %s-based wireless network card at %s, irq:%d, "
1578 "phymem1:0x%lX, phymem2:0x%lX, mem1:0x%p, mem1_size:%ld, "
1579 "mem2:0x%p, mem2_size:%ld\n",
1580 chip_name, pci_name(pdev), pdev->irq, phymem1, phymem2,
1581 mem1, mem_region1_size, mem2, mem_region2_size);
1582 log(L_ANY, "initial debug setting is 0x%04X\n", acx_debug);
1583 adev->chip_type = chip_type;
1584 adev->chip_name = chip_name;
1585 adev->io = (CHIPTYPE_ACX100 == chip_type) ? IO_ACX100 : IO_ACX111;
1586 adev->membase = phymem1;
1587 adev->iobase = mem1;
1588 adev->membase2 = phymem2;
1589 adev->iobase2 = mem2;
1590 adev->irq = pdev->irq;
1593 if (0 == pdev->irq) {
1594 printk("acx: can't use IRQ 0\n");
1595 goto fail_irq;
1597 SET_IEEE80211_DEV(ieee, &pdev->dev);
1600 /* to find crashes due to weird driver access
1601 * to unconfigured interface (ifup) */
1602 adev->mgmt_timer.function = (void (*)(unsigned long))0x0000dead;
1605 #ifdef NONESSENTIAL_FEATURES
1606 acx_show_card_eeprom_id(adev);
1607 #endif /* NONESSENTIAL_FEATURES */
1610 /* ok, pci setup is finished, now start initializing the card */
1612 /* NB: read_reg() reads may return bogus data before reset_dev(),
1613 * since the firmware which directly controls large parts of the I/O
1614 * registers isn't initialized yet.
1615 * acx100 seems to be more affected than acx111 */
1616 if (OK != acxpci_s_reset_dev(adev))
1617 goto fail_reset;
1619 if (IS_ACX100(adev)) {
1620 /* ACX100: configopt struct in cmd mailbox - directly after reset */
1621 memcpy_fromio(&co, adev->cmd_area, sizeof(co));
1624 if (OK != acx_s_init_mac(adev))
1625 goto fail_init_mac;
1627 if (IS_ACX111(adev)) {
1628 /* ACX111: configopt struct needs to be queried after full init */
1629 acx_s_interrogate(adev, &co, ACX111_IE_CONFIG_OPTIONS);
1631 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
1632 if (OK != acxpci_read_eeprom_byte(adev, 0x05, &adev->eeprom_version))
1633 goto fail_read_eeprom_version;
1635 acx_s_parse_configoption(adev, &co);
1636 acx_s_set_defaults(adev);
1637 acx_s_get_firmware_version(adev); /* needs to be after acx_s_init_mac() */
1638 acx_display_hardware_details(adev);
1640 /* Register the card, AFTER everything else has been set up,
1641 * since otherwise an ioctl could step on our feet due to
1642 * firmware operations happening in parallel or uninitialized data */
1645 acx_proc_register_entries(ieee);
1647 /* Now we have our device, so make sure the kernel doesn't try
1648 * to send packets even though we're not associated to a network yet */
1650 /* after register_netdev() userspace may start working with dev
1651 * (in particular, on other CPUs), we only need to up the sem */
1652 /* acx_sem_unlock(adev); */
1654 printk("acx " ACX_RELEASE ": net device %s, driver compiled "
1655 "against wireless extensions %d and Linux %s\n",
1656 wiphy_name(adev->ieee->wiphy), WIRELESS_EXT, UTS_RELEASE);
1658 MAC_COPY(adev->ieee->wiphy->perm_addr, adev->dev_addr);
1660 log(L_IRQ | L_INIT, "using IRQ %d\n", pdev->irq);
1662 /** done with board specific setup **/
1664 /* need to be able to restore PCI state after a suspend */
1665 #ifdef CONFIG_PM
1666 pci_save_state(pdev);
1667 #endif
1670 acx_init_task_scheduler(adev);
1671 err = ieee80211_register_hw(adev->ieee);
1672 if (OK != err) {
1673 printk("acx: ieee80211_register_hw() FAILED: %d\n", err);
1674 goto fail_register_netdev;
1676 #if CMD_DISCOVERY
1677 great_inquisitor(adev);
1678 #endif
1680 result = OK;
1681 goto done;
1683 /* error paths: undo everything in reverse order... */
1686 acxpci_s_delete_dma_regions(adev);
1687 pci_set_drvdata(pdev, NULL);
1689 fail_init_mac:
1690 fail_read_eeprom_version:
1691 fail_reset:
1693 fail_alloc_netdev:
1694 fail_irq:
1696 iounmap(mem2);
1697 fail_ioremap2:
1699 iounmap(mem1);
1700 fail_ioremap1:
1702 release_mem_region(pci_resource_start(pdev, mem_region2),
1703 pci_resource_len(pdev, mem_region2));
1704 fail_request_mem_region2:
1706 release_mem_region(pci_resource_start(pdev, mem_region1),
1707 pci_resource_len(pdev, mem_region1));
1708 fail_request_mem_region1:
1709 fail_unknown_chiptype:
1711 pci_disable_device(pdev);
1712 fail_pci_enable_device:
1714 #ifdef CONFIG_PM
1715 pci_set_power_state(pdev, PCI_D3hot);
1716 #endif
1717 fail_register_netdev:
1718 ieee80211_free_hw(ieee);
1719 done:
1720 FN_EXIT1(result);
1721 return result;
1725 /***********************************************************************
1726 ** acxpci_e_remove
1728 ** Shut device down (if not hot unplugged)
1729 ** and deallocate PCI resources for the acx chip.
1731 ** pdev - ptr to PCI device structure containing info about pci configuration
1733 static void __devexit acxpci_e_remove(struct pci_dev *pdev)
1735 struct ieee80211_hw *hw = (struct ieee80211_hw *)pci_get_drvdata(pdev);
1736 acx_device_t *adev = ieee2adev(hw);
1737 unsigned long mem_region1, mem_region2;
1738 unsigned long flags;
1739 FN_ENTER;
1741 if (!hw) {
1742 log(L_DEBUG, "%s: card is unused. Skipping any release code\n",
1743 __func__);
1744 goto end;
1748 acx_lock(adev, flags);
1749 acx_unlock(adev, flags);
1750 adev->initialized = 0;
1752 /* If device wasn't hot unplugged... */
1753 if (adev_present(adev)) {
1755 acx_sem_lock(adev);
1757 /* disable both Tx and Rx to shut radio down properly */
1758 if (adev->initialized) {
1759 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_TX, NULL, 0);
1760 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_RX, NULL, 0);
1762 #ifdef REDUNDANT
1763 /* put the eCPU to sleep to save power
1764 * Halting is not possible currently,
1765 * since not supported by all firmware versions */
1766 acx_s_issue_cmd(adev, ACX100_CMD_SLEEP, NULL, 0);
1767 #endif
1768 acx_lock(adev, flags);
1769 /* disable power LED to save power :-) */
1770 log(L_INIT, "switching off power LED to save power\n");
1771 acxpci_l_power_led(adev, 0);
1772 /* stop our eCPU */
1773 if (IS_ACX111(adev)) {
1774 /* FIXME: does this actually keep halting the eCPU?
1775 * I don't think so...
1777 acxpci_l_reset_mac(adev);
1778 } else {
1779 u16 temp;
1780 /* halt eCPU */
1781 temp = read_reg16(adev, IO_ACX_ECPU_CTRL) | 0x1;
1782 write_reg16(adev, IO_ACX_ECPU_CTRL, temp);
1783 write_flush(adev);
1785 acx_unlock(adev, flags);
1787 acx_sem_unlock(adev);
1790 /* unregister the device to not let the kernel
1791 * (e.g. ioctls) access a half-deconfigured device
1792 * NB: this will cause acxpci_e_close() to be called,
1793 * thus we shouldn't call it under sem!
1794 * Well, netdev did, but ieee80211 stack does not, so we
1795 * have to do so manually...
1797 acxpci_e_close(hw);
1798 log(L_INIT, "removing device %s\n", wiphy_name(adev->ieee->wiphy));
1799 ieee80211_unregister_hw(adev->ieee);
1801 /* unregister_netdev ensures that no references to us left.
1802 * For paranoid reasons we continue to follow the rules */
1803 acx_sem_lock(adev);
1805 if (adev->dev_state_mask & ACX_STATE_IFACE_UP) {
1806 acxpci_s_down(hw);
1807 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
1810 acx_proc_unregister_entries(adev->ieee);
1812 if (IS_ACX100(adev)) {
1813 mem_region1 = PCI_ACX100_REGION1;
1814 mem_region2 = PCI_ACX100_REGION2;
1815 } else {
1816 mem_region1 = PCI_ACX111_REGION1;
1817 mem_region2 = PCI_ACX111_REGION2;
1820 /* finally, clean up PCI bus state */
1821 acxpci_s_delete_dma_regions(adev);
1822 if (adev->iobase)
1823 iounmap(adev->iobase);
1824 if (adev->iobase2)
1825 iounmap(adev->iobase2);
1826 release_mem_region(pci_resource_start(pdev, mem_region1),
1827 pci_resource_len(pdev, mem_region1));
1828 release_mem_region(pci_resource_start(pdev, mem_region2),
1829 pci_resource_len(pdev, mem_region2));
1830 pci_disable_device(pdev);
1832 /* remove dev registration */
1834 free_irq(adev->irq, adev);
1835 acx_sem_unlock(adev);
1837 /* Free netdev (quite late,
1838 * since otherwise we might get caught off-guard
1839 * by a netdev timeout handler execution
1840 * expecting to see a working dev...) */
1841 ieee80211_free_hw(adev->ieee);
1843 /* put device into ACPI D3 mode (shutdown) */
1844 #ifdef CONFIG_PM
1845 pci_set_power_state(pdev, PCI_D3hot);
1846 #endif
1847 end:
1848 FN_EXIT0;
1852 /***********************************************************************
1853 ** TODO: PM code needs to be fixed / debugged / tested.
1855 #ifdef CONFIG_PM
1856 static int
1857 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
1858 acxpci_e_suspend(struct pci_dev *pdev, pm_message_t state)
1859 #else
1860 acxpci_e_suspend(struct pci_dev *pdev, u32 state)
1861 #endif
1863 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1864 acx_device_t *adev;
1866 FN_ENTER;
1867 printk("acx: suspend handler is experimental!\n");
1868 printk("sus: dev %p\n", hw);
1870 /* if (!netif_running(ndev))
1871 goto end;
1873 adev = ieee2adev(hw);
1874 printk("sus: adev %p\n", adev);
1876 acx_sem_lock(adev);
1878 ieee80211_unregister_hw(hw); /* this one cannot sleep */
1879 acxpci_s_down(hw);
1880 /* down() does not set it to 0xffff, but here we really want that */
1881 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
1882 write_reg16(adev, IO_ACX_FEMR, 0x0);
1883 acxpci_s_delete_dma_regions(adev);
1884 pci_save_state(pdev);
1885 pci_set_power_state(pdev, PCI_D3hot);
1887 acx_sem_unlock(adev);
1888 FN_EXIT0;
1889 return OK;
1893 static int acxpci_e_resume(struct pci_dev *pdev)
1895 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1896 acx_device_t *adev;
1898 FN_ENTER;
1900 printk("acx: resume handler is experimental!\n");
1901 printk("rsm: got dev %p\n", hw);
1904 adev = ieee2adev(hw);
1905 printk("rsm: got adev %p\n", adev);
1907 acx_sem_lock(adev);
1909 pci_set_power_state(pdev, PCI_D0);
1910 printk("rsm: power state PCI_D0 set\n");
1911 pci_restore_state(pdev);
1912 printk("rsm: PCI state restored\n");
1914 if (OK != acxpci_s_reset_dev(adev))
1915 goto end_unlock;
1916 printk("rsm: device reset done\n");
1917 if (OK != acx_s_init_mac(adev))
1918 goto end_unlock;
1919 printk("rsm: init MAC done\n");
1921 acxpci_s_up(hw);
1922 printk("rsm: acx up done\n");
1924 /* now even reload all card parameters as they were before suspend,
1925 * and possibly be back in the network again already :-) */
1926 if (ACX_STATE_IFACE_UP & adev->dev_state_mask) {
1927 adev->set_mask = GETSET_ALL;
1928 acx_s_update_card_settings(adev);
1929 printk("rsm: settings updated\n");
1931 ieee80211_register_hw(hw);
1932 printk("rsm: device attached\n");
1934 end_unlock:
1935 acx_sem_unlock(adev);
1936 /* we need to return OK here anyway, right? */
1937 FN_EXIT0;
1938 return OK;
1940 #endif /* CONFIG_PM */
1943 /***********************************************************************
1944 ** acxpci_s_up
1946 ** This function is called by acxpci_e_open (when ifconfig sets the device as up)
1948 ** Side effects:
1949 ** - Enables on-card interrupt requests
1950 ** - calls acx_s_start
1953 static void enable_acx_irq(acx_device_t * adev)
1955 FN_ENTER;
1956 write_reg16(adev, IO_ACX_IRQ_MASK, adev->irq_mask);
1957 write_reg16(adev, IO_ACX_FEMR, 0x8000);
1958 adev->irqs_active = 1;
1959 FN_EXIT0;
1962 static void acxpci_s_up(struct ieee80211_hw *hw)
1964 acx_device_t *adev = ieee2adev(hw);
1965 unsigned long flags;
1967 FN_ENTER;
1969 acx_lock(adev, flags);
1970 enable_acx_irq(adev);
1971 acx_unlock(adev, flags);
1973 /* acx fw < 1.9.3.e has a hardware timer, and older drivers
1974 ** used to use it. But we don't do that anymore, our OS
1975 ** has reliable software timers */
1976 init_timer(&adev->mgmt_timer);
1977 adev->mgmt_timer.function = acx_i_timer;
1978 adev->mgmt_timer.data = (unsigned long)adev;
1980 /* Need to set ACX_STATE_IFACE_UP first, or else
1981 ** timer won't be started by acx_set_status() */
1982 SET_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
1984 acx_s_start(adev);
1986 FN_EXIT0;
1990 /***********************************************************************
1991 ** acxpci_s_down
1993 ** NB: device may be already hot unplugged if called from acxpci_e_remove()
1995 ** Disables on-card interrupt request, stops softirq and timer, stops queue,
1996 ** sets status == STOPPED
1999 static void disable_acx_irq(acx_device_t * adev)
2001 FN_ENTER;
2003 /* I guess mask is not 0xffff because acx100 won't signal
2004 ** cmd completion then (needed for ifup).
2005 ** Someone with acx100 please confirm */
2006 write_reg16(adev, IO_ACX_IRQ_MASK, adev->irq_mask_off);
2007 write_reg16(adev, IO_ACX_FEMR, 0x0);
2008 adev->irqs_active = 0;
2009 FN_EXIT0;
2012 static void acxpci_s_down(struct ieee80211_hw *hw)
2014 acx_device_t *adev = ieee2adev(hw);
2015 unsigned long flags;
2017 FN_ENTER;
2019 /* Disable IRQs first, so that IRQs cannot race with us */
2020 /* then wait until interrupts have finished executing on other CPUs */
2021 acx_lock(adev, flags);
2022 disable_acx_irq(adev);
2023 synchronize_irq(adev->pdev->irq);
2024 acx_unlock(adev, flags);
2026 /* we really don't want to have an asynchronous tasklet disturb us
2027 ** after something vital for its job has been shut down, so
2028 ** end all remaining work now.
2030 ** NB: carrier_off (done by set_status below) would lead to
2031 ** not yet fully understood deadlock in flush_scheduled_work().
2032 ** That's why we do FLUSH first.
2034 ** NB2: we have a bad locking bug here: flush_scheduled_work()
2035 ** waits for acx_e_after_interrupt_task to complete if it is running
2036 ** on another CPU, but acx_e_after_interrupt_task
2037 ** will sleep on sem forever, because it is taken by us!
2038 ** Work around that by temporary sem unlock.
2039 ** This will fail miserably if we'll be hit by concurrent
2040 ** iwconfig or something in between. TODO! */
2041 flush_scheduled_work();
2043 /* This is possible:
2044 ** flush_scheduled_work -> acx_e_after_interrupt_task ->
2045 ** -> set_status(ASSOCIATED) -> wake_queue()
2046 ** That's why we stop queue _after_ flush_scheduled_work
2047 ** lock/unlock is just paranoia, maybe not needed */
2049 /* kernel/timer.c says it's illegal to del_timer_sync()
2050 ** a timer which restarts itself. We guarantee this cannot
2051 ** ever happen because acx_i_timer() never does this if
2052 ** status is ACX_STATUS_0_STOPPED */
2053 del_timer_sync(&adev->mgmt_timer);
2055 FN_EXIT0;
2058 #ifdef CONFIG_NET_POLL_CONTROLLER
2059 void acxpci_net_poll_controller(struct net_device *net_dev)
2061 acx_device_t *adev = ndev2adev(net_dev);
2062 unsigned long flags;
2064 local_irq_save(flags);
2065 acxpci_i_interrupt(adev->irq, adev);
2066 local_irq_restore(flags);
2068 #endif*/ /* CONFIG_NET_POLL_CONTROLLER */
2070 /***********************************************************************
2071 ** acxpci_e_open
2073 ** Called as a result of SIOCSIFFLAGS ioctl changing the flags bit IFF_UP
2074 ** from clear to set. In other words: ifconfig up.
2076 ** Returns:
2077 ** 0 success
2078 ** >0 f/w reported error
2079 ** <0 driver reported error
2081 static int acxpci_e_open(struct ieee80211_hw *hw)
2083 acx_device_t *adev = ieee2adev(hw);
2084 int result = OK;
2086 FN_ENTER;
2088 acx_sem_lock(adev);
2090 adev->initialized = 0;
2092 /* TODO: pci_set_power_state(pdev, PCI_D0); ? */
2094 /* request shared IRQ handler */
2095 if (request_irq
2096 (adev->irq, acxpci_i_interrupt, IRQF_SHARED, KBUILD_MODNAME, adev)) {
2097 printk("%s: request_irq FAILED\n", wiphy_name(adev->ieee->wiphy));
2098 result = -EAGAIN;
2099 goto done;
2101 log(L_DEBUG | L_IRQ, "request_irq %d successful\n", adev->irq);
2103 /* ifup device */
2104 acxpci_s_up(hw);
2106 /* We don't currently have to do anything else.
2107 * The setup of the MAC should be subsequently completed via
2108 * the mlme commands.
2109 * Higher layers know we're ready from dev->start==1 and
2110 * dev->tbusy==0. Our rx path knows to pass up received/
2111 * frames because of dev->flags&IFF_UP is true.
2113 acx_setup_modes(adev);
2114 ieee80211_start_queues(adev->ieee);
2116 adev->initialized = 1;
2117 done:
2118 acx_sem_unlock(adev);
2120 FN_EXIT1(result);
2121 return result;
2125 /***********************************************************************
2126 ** acxpci_e_close
2128 ** Called as a result of SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
2129 ** from set to clear. I.e. called by "ifconfig DEV down"
2131 ** Returns:
2132 ** 0 success
2133 ** >0 f/w reported error
2134 ** <0 driver reported error
2136 static int acxpci_e_close(struct ieee80211_hw *hw)
2138 acx_device_t *adev = ieee2adev(hw);
2139 unsigned long flags;
2140 FN_ENTER;
2141 acx_lock(adev,flags);
2142 /* ifdown device */
2143 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
2144 if (adev->initialized) {
2145 acxpci_s_down(hw);
2148 if (adev->modes)
2149 acx_free_modes(adev);
2150 /* disable all IRQs, release shared IRQ handler */
2151 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
2152 write_reg16(adev, IO_ACX_FEMR, 0x0);
2154 /* TODO: pci_set_power_state(pdev, PCI_D3hot); ? */
2156 /* We currently don't have to do anything else.
2157 * Higher layers know we're not ready from dev->start==0 and
2158 * dev->tbusy==1. Our rx path knows to not pass up received
2159 * frames because of dev->flags&IFF_UP is false.
2161 acx_unlock(adev,flags);
2163 log(L_INIT, "closed device\n");
2164 FN_EXIT0;
2165 return OK;
2171 /***************************************************************
2172 ** acxpci_l_process_rxdesc
2174 ** Called directly and only from the IRQ handler
2177 #if !ACX_DEBUG
2178 static inline void log_rxbuffer(const acx_device_t * adev)
2181 #else
2182 static void log_rxbuffer(const acx_device_t * adev)
2184 register const struct rxhostdesc *rxhostdesc;
2185 int i;
2187 /* no FN_ENTER here, we don't want that */
2189 rxhostdesc = adev->rxhostdesc_start;
2190 if (unlikely(!rxhostdesc))
2191 return;
2192 for (i = 0; i < RX_CNT; i++) {
2193 if ((rxhostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2194 && (rxhostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2195 printk("rx: buf %d full\n", i);
2196 rxhostdesc++;
2199 #endif
2201 static void acxpci_l_process_rxdesc(acx_device_t * adev)
2203 register rxhostdesc_t *hostdesc;
2204 unsigned count, tail;
2206 FN_ENTER;
2208 if (unlikely(acx_debug & L_BUFR))
2209 log_rxbuffer(adev);
2211 /* First, have a loop to determine the first descriptor that's
2212 * full, just in case there's a mismatch between our current
2213 * rx_tail and the full descriptor we're supposed to handle. */
2214 tail = adev->rx_tail;
2215 count = RX_CNT;
2216 while (1) {
2217 hostdesc = &adev->rxhostdesc_start[tail];
2218 /* advance tail regardless of outcome of the below test */
2219 tail = (tail + 1) % RX_CNT;
2221 if ((hostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2222 && (hostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2223 break; /* found it! */
2225 if (unlikely(!--count)) /* hmm, no luck: all descs empty, bail out */
2226 goto end;
2229 /* now process descriptors, starting with the first we figured out */
2230 while (1) {
2231 log(L_BUFR, "rx: tail=%u Ctl_16=%04X Status=%08X\n",
2232 tail, hostdesc->Ctl_16, hostdesc->Status);
2234 acx_l_process_rxbuf(adev, hostdesc->data);
2235 hostdesc->Status = 0;
2236 /* flush all writes before adapter sees CTL_HOSTOWN change */
2237 wmb();
2238 /* Host no longer owns this, needs to be LAST */
2239 CLEAR_BIT(hostdesc->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
2241 /* ok, descriptor is handled, now check the next descriptor */
2242 hostdesc = &adev->rxhostdesc_start[tail];
2244 /* if next descriptor is empty, then bail out */
2245 if (!(hostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2246 || !(hostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2247 break;
2249 tail = (tail + 1) % RX_CNT;
2251 end:
2252 adev->rx_tail = tail;
2253 FN_EXIT0;
2258 /***********************************************************************
2259 ** acxpci_i_interrupt
2261 ** IRQ handler (atomic context, must not sleep, blah, blah)
2264 /* scan is complete. all frames now on the receive queue are valid */
2265 #define INFO_SCAN_COMPLETE 0x0001
2266 #define INFO_WEP_KEY_NOT_FOUND 0x0002
2267 /* hw has been reset as the result of a watchdog timer timeout */
2268 #define INFO_WATCH_DOG_RESET 0x0003
2269 /* failed to send out NULL frame from PS mode notification to AP */
2270 /* recommended action: try entering 802.11 PS mode again */
2271 #define INFO_PS_FAIL 0x0004
2272 /* encryption/decryption process on a packet failed */
2273 #define INFO_IV_ICV_FAILURE 0x0005
2275 /* Info mailbox format:
2276 2 bytes: type
2277 2 bytes: status
2278 more bytes may follow
2279 rumors say about status:
2280 0x0000 info available (set by hw)
2281 0x0001 information received (must be set by host)
2282 0x1000 info available, mailbox overflowed (messages lost) (set by hw)
2283 but in practice we've seen:
2284 0x9000 when we did not set status to 0x0001 on prev message
2285 0x1001 when we did set it
2286 0x0000 was never seen
2287 conclusion: this is really a bitfield:
2288 0x1000 is 'info available' bit
2289 'mailbox overflowed' bit is 0x8000, not 0x1000
2290 value of 0x0000 probably means that there are no messages at all
2291 P.S. I dunno how in hell hw is supposed to notice that messages are lost -
2292 it does NOT clear bit 0x0001, and this bit will probably stay forever set
2293 after we set it once. Let's hope this will be fixed in firmware someday
2296 static void handle_info_irq(acx_device_t * adev)
2298 #if ACX_DEBUG
2299 static const char *const info_type_msg[] = {
2300 "(unknown)",
2301 "scan complete",
2302 "WEP key not found",
2303 "internal watchdog reset was done",
2304 "failed to send powersave (NULL frame) notification to AP",
2305 "encrypt/decrypt on a packet has failed",
2306 "TKIP tx keys disabled",
2307 "TKIP rx keys disabled",
2308 "TKIP rx: key ID not found",
2309 "???",
2310 "???",
2311 "???",
2312 "???",
2313 "???",
2314 "???",
2315 "???",
2316 "TKIP IV value exceeds thresh"
2318 #endif
2319 u32 info_type, info_status;
2321 info_type = acx_readl(adev->info_area);
2322 info_status = (info_type >> 16);
2323 info_type = (u16) info_type;
2325 /* inform fw that we have read this info message */
2326 acx_writel(info_type | 0x00010000, adev->info_area);
2327 write_reg16(adev, IO_ACX_INT_TRIG, INT_TRIG_INFOACK);
2328 write_flush(adev);
2330 log(L_CTL, "info_type:%04X info_status:%04X\n", info_type, info_status);
2332 log(L_IRQ, "got Info IRQ: status %04X type %04X: %s\n",
2333 info_status, info_type,
2334 info_type_msg[(info_type >= ARRAY_SIZE(info_type_msg)) ?
2335 0 : info_type]
2340 static void log_unusual_irq(u16 irqtype)
2343 if (!printk_ratelimit())
2344 return;
2347 printk("acx: got");
2348 if (irqtype & HOST_INT_RX_DATA) {
2349 printk(" Rx_Data");
2351 /* HOST_INT_TX_COMPLETE */
2352 if (irqtype & HOST_INT_TX_XFER) {
2353 printk(" Tx_Xfer");
2355 /* HOST_INT_RX_COMPLETE */
2356 if (irqtype & HOST_INT_DTIM) {
2357 printk(" DTIM");
2359 if (irqtype & HOST_INT_BEACON) {
2360 printk(" Beacon");
2362 if (irqtype & HOST_INT_TIMER) {
2363 log(L_IRQ, " Timer");
2365 if (irqtype & HOST_INT_KEY_NOT_FOUND) {
2366 printk(" Key_Not_Found");
2368 if (irqtype & HOST_INT_IV_ICV_FAILURE) {
2369 printk(" IV_ICV_Failure (crypto)");
2371 /* HOST_INT_CMD_COMPLETE */
2372 /* HOST_INT_INFO */
2373 if (irqtype & HOST_INT_OVERFLOW) {
2374 printk(" Overflow");
2376 if (irqtype & HOST_INT_PROCESS_ERROR) {
2377 printk(" Process_Error");
2379 /* HOST_INT_SCAN_COMPLETE */
2380 if (irqtype & HOST_INT_FCS_THRESHOLD) {
2381 printk(" FCS_Threshold");
2383 if (irqtype & HOST_INT_UNKNOWN) {
2384 printk(" Unknown");
2386 printk(" IRQ(s)\n");
2390 static void update_link_quality_led(acx_device_t * adev)
2392 /* int qual; */
2394 /* qual =
2395 acx_signal_determine_quality(adev->wstats.qual.level,
2396 adev->wstats.qual.noise);
2397 if (qual > adev->brange_max_quality)
2398 qual = adev->brange_max_quality;
2401 /* if (time_after(jiffies, adev->brange_time_last_state_change +
2402 (HZ / 2 -
2403 HZ / 2 * (unsigned long)qual /
2404 adev->brange_max_quality))) {
2405 acxpci_l_power_led(adev, (adev->brange_last_state == 0));
2406 adev->brange_last_state ^= 1; *//* toggle */
2407 /* adev->brange_time_last_state_change = jiffies;
2412 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* a la orinoco.c */
2414 /* Interrupt handler bottom-half */
2415 void acx_interrupt_tasklet(struct work_struct *work)
2418 #ifdef CONFIG_ACX_MAC80211_DEBUG
2419 u32 _handled = 0x00000000;
2420 # define acxirq_handled(irq) do { _handled |= (irq); } while (0)
2421 #else
2422 # define acxirq_handled(irq) do { /* nothing */ } while (0)
2423 #endif /* CONFIG_ACX_MAC80211_DEBUG */
2424 acx_device_t *adev = container_of(work,struct acx_device, after_interrupt_task);
2425 // unsigned int irqcount = MAX_IRQLOOPS_PER_JIFFY;
2426 int irqtype;
2428 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2429 * I am paranoid */
2430 acx_sem_lock(adev);
2433 FN_ENTER;
2434 irqtype = adev->irq_reason;
2435 adev->irq_reason = 0;
2437 #define IRQ_ITERATE 0
2438 #if IRQ_ITERATE
2439 if (jiffies != adev->irq_last_jiffies) {
2440 adev->irq_loops_this_jiffy = 0;
2441 adev->irq_last_jiffies = jiffies;
2444 /* safety condition; we'll normally abort loop below
2445 * in case no IRQ type occurred */
2446 while (likely(--irqcount)) {
2447 #endif
2448 /* ACK all IRQs ASAP */
2451 /* Handle most important IRQ types first */
2452 if (irqtype & HOST_INT_RX_COMPLETE) {
2453 log(L_IRQ, "got Rx_Complete IRQ\n");
2454 acxpci_l_process_rxdesc(adev);
2456 if (irqtype & HOST_INT_TX_COMPLETE) {
2457 log(L_IRQ, "got Tx_Complete IRQ\n");
2458 /* don't clean up on each Tx complete, wait a bit
2459 * unless we're going towards full, in which case
2460 * we do it immediately, too (otherwise we might lockup
2461 * with a full Tx buffer if we go into
2462 * acxpci_l_clean_txdesc() at a time when we won't wakeup
2463 * the net queue in there for some reason...) */
2464 // if (adev->tx_free <= TX_START_CLEAN) {
2465 acxpci_l_clean_txdesc(adev);
2466 // }
2469 /* Less frequent ones */
2470 if (irqtype & (0
2471 | HOST_INT_CMD_COMPLETE
2472 | HOST_INT_INFO | HOST_INT_SCAN_COMPLETE)) {
2473 if (irqtype & HOST_INT_INFO) {
2474 handle_info_irq(adev);
2476 if (irqtype & HOST_INT_SCAN_COMPLETE) {
2477 log(L_IRQ, "got Scan_Complete IRQ\n");
2478 /* need to do that in process context */
2479 /* remember that fw is not scanning anymore */
2480 SET_BIT(adev->irq_status,
2481 HOST_INT_SCAN_COMPLETE);
2485 /* These we just log, but either they happen rarely
2486 * or we keep them masked out */
2487 if (irqtype & (0 | HOST_INT_RX_DATA
2488 /* | HOST_INT_TX_COMPLETE */
2489 | HOST_INT_TX_XFER
2490 /* | HOST_INT_RX_COMPLETE */
2491 | HOST_INT_DTIM
2492 | HOST_INT_BEACON
2493 | HOST_INT_TIMER
2494 | HOST_INT_KEY_NOT_FOUND
2495 | HOST_INT_IV_ICV_FAILURE
2496 /* | HOST_INT_CMD_COMPLETE */
2497 /* | HOST_INT_INFO */
2498 | HOST_INT_OVERFLOW | HOST_INT_PROCESS_ERROR
2499 /* | HOST_INT_SCAN_COMPLETE */
2500 | HOST_INT_FCS_THRESHOLD | HOST_INT_UNKNOWN)) {
2501 log_unusual_irq(irqtype);
2503 #if IRQ_ITERATE
2504 unmasked = read_reg16(adev, IO_ACX_IRQ_STATUS_CLEAR);
2505 irqtype = unmasked & ~adev->irq_mask;
2506 /* Bail out if no new IRQ bits or if all are masked out */
2507 if (!irqtype)
2508 break;
2510 if (unlikely
2511 (++adev->irq_loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY)) {
2512 printk(KERN_ERR
2513 "acx: too many interrupts per jiffy!\n");
2514 /* Looks like card floods us with IRQs! Try to stop that */
2515 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
2516 /* This will short-circuit all future attempts to handle IRQ.
2517 * We cant do much more... */
2518 adev->irq_mask = 0;
2519 break;
2522 #endif
2523 /* Routine to perform blink with range */
2524 if (unlikely(adev->led_power == 2))
2525 update_link_quality_led(adev);
2527 /* handled: */
2528 if (adev->after_interrupt_jobs)
2529 acx_e_after_interrupt_task(&adev->after_interrupt_task);
2531 /* write_flush(adev); - not needed, last op was read anyway */
2532 acx_sem_unlock(adev);
2533 FN_EXIT0;
2534 return;
2539 static irqreturn_t
2540 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
2541 acxpci_i_interrupt(int irq, void *dev_id)
2542 #else
2543 acxpci_i_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2544 #endif
2547 acx_device_t *adev = dev_id;
2548 unsigned long flags;
2549 register u16 irqtype;
2550 u16 unmasked;
2552 if (!adev)
2553 return IRQ_NONE;
2554 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2555 * I am paranoid */
2557 acx_lock(adev, flags);
2559 unmasked = read_reg16(adev, IO_ACX_IRQ_STATUS_CLEAR);
2561 if (unlikely(0xffff == unmasked)) {
2562 /* 0xffff value hints at missing hardware,
2563 * so don't do anything.
2564 * Not very clean, but other drivers do the same... */
2565 log(L_IRQ, "IRQ type:FFFF - device removed? IRQ_NONE\n");
2566 goto none;
2569 /* We will check only "interesting" IRQ types */
2570 irqtype = unmasked & ~adev->irq_mask;
2571 if (!irqtype) {
2572 /* We are on a shared IRQ line and it wasn't our IRQ */
2573 log(L_IRQ,
2574 "IRQ type:%04X, mask:%04X - all are masked, IRQ_NONE\n",
2575 unmasked, adev->irq_mask);
2576 goto none;
2579 /* Go ahead and ACK our interrupt */
2580 write_reg16(adev, IO_ACX_IRQ_ACK, 0xffff);
2581 if (irqtype & HOST_INT_CMD_COMPLETE) {
2582 log(L_IRQ, "got Command_Complete IRQ\n");
2583 /* save the state for the running issue_cmd() */
2584 SET_BIT(adev->irq_status, HOST_INT_CMD_COMPLETE);
2587 /* Only accept IRQs, if we are initialized properly.
2588 * This avoids an RX race while initializing.
2589 * We should probably not enable IRQs before we are initialized
2590 * completely, but some careful work is needed to fix this. I think it
2591 * is best to stay with this cheap workaround for now... .
2593 if (likely(adev->initialized)) {
2594 /* disable all IRQs. They are enabled again in the bottom half. */
2595 /* save the reason code and call our bottom half. */
2596 adev->irq_reason = irqtype;
2598 if ((irqtype & HOST_INT_RX_COMPLETE) || (irqtype & HOST_INT_TX_COMPLETE))
2599 acx_schedule_task(adev, 0);
2601 acx_unlock(adev, flags);
2602 return IRQ_HANDLED;
2603 none:
2604 acx_unlock(adev, flags);
2605 return IRQ_NONE;
2610 /***********************************************************************
2611 ** acxpci_l_power_led
2613 void acxpci_l_power_led(acx_device_t * adev, int enable)
2615 u16 gpio_pled = IS_ACX111(adev) ? 0x0040 : 0x0800;
2617 /* A hack. Not moving message rate limiting to adev->xxx
2618 * (it's only a debug message after all) */
2619 static int rate_limit = 0;
2621 if (rate_limit++ < 3)
2622 log(L_IOCTL, "Please report in case toggling the power "
2623 "LED doesn't work for your card!\n");
2624 if (enable)
2625 write_reg16(adev, IO_ACX_GPIO_OUT,
2626 read_reg16(adev, IO_ACX_GPIO_OUT) & ~gpio_pled);
2627 else
2628 write_reg16(adev, IO_ACX_GPIO_OUT,
2629 read_reg16(adev, IO_ACX_GPIO_OUT) | gpio_pled);
2633 /***********************************************************************
2634 ** Ioctls
2637 /***********************************************************************
2639 #if 0
2641 acx111pci_ioctl_info(struct net_device *ndev,
2642 struct iw_request_info *info,
2643 struct iw_param *vwrq, char *extra)
2645 #if ACX_DEBUG > 1
2646 acx_device_t *adev = ndev2adev(ndev);
2647 rxdesc_t *rxdesc;
2648 txdesc_t *txdesc;
2649 rxhostdesc_t *rxhostdesc;
2650 txhostdesc_t *txhostdesc;
2651 struct acx111_ie_memoryconfig memconf;
2652 struct acx111_ie_queueconfig queueconf;
2653 unsigned long flags;
2654 int i;
2655 char memmap[0x34];
2656 char rxconfig[0x8];
2657 char fcserror[0x8];
2658 char ratefallback[0x5];
2660 if (!(acx_debug & (L_IOCTL | L_DEBUG)))
2661 return OK;
2662 /* using printk() since we checked debug flag already */
2664 acx_sem_lock(adev);
2666 if (!IS_ACX111(adev)) {
2667 printk("acx111-specific function called "
2668 "with non-acx111 chip, aborting\n");
2669 goto end_ok;
2672 /* get Acx111 Memory Configuration */
2673 memset(&memconf, 0, sizeof(memconf));
2674 /* BTW, fails with 12 (Write only) error code.
2675 ** Retained for easy testing of issue_cmd error handling :) */
2676 acx_s_interrogate(adev, &memconf, ACX1xx_IE_QUEUE_CONFIG);
2678 /* get Acx111 Queue Configuration */
2679 memset(&queueconf, 0, sizeof(queueconf));
2680 acx_s_interrogate(adev, &queueconf, ACX1xx_IE_MEMORY_CONFIG_OPTIONS);
2682 /* get Acx111 Memory Map */
2683 memset(memmap, 0, sizeof(memmap));
2684 acx_s_interrogate(adev, &memmap, ACX1xx_IE_MEMORY_MAP);
2686 /* get Acx111 Rx Config */
2687 memset(rxconfig, 0, sizeof(rxconfig));
2688 acx_s_interrogate(adev, &rxconfig, ACX1xx_IE_RXCONFIG);
2690 /* get Acx111 fcs error count */
2691 memset(fcserror, 0, sizeof(fcserror));
2692 acx_s_interrogate(adev, &fcserror, ACX1xx_IE_FCS_ERROR_COUNT);
2694 /* get Acx111 rate fallback */
2695 memset(ratefallback, 0, sizeof(ratefallback));
2696 acx_s_interrogate(adev, &ratefallback, ACX1xx_IE_RATE_FALLBACK);
2698 /* force occurrence of a beacon interrupt */
2699 /* TODO: comment why is this necessary */
2700 write_reg16(adev, IO_ACX_HINT_TRIG, HOST_INT_BEACON);
2702 /* dump Acx111 Mem Configuration */
2703 printk("dump mem config:\n"
2704 "data read: %d, struct size: %d\n"
2705 "Number of stations: %1X\n"
2706 "Memory block size: %1X\n"
2707 "tx/rx memory block allocation: %1X\n"
2708 "count rx: %X / tx: %X queues\n"
2709 "options %1X\n"
2710 "fragmentation %1X\n"
2711 "Rx Queue 1 Count Descriptors: %X\n"
2712 "Rx Queue 1 Host Memory Start: %X\n"
2713 "Tx Queue 1 Count Descriptors: %X\n"
2714 "Tx Queue 1 Attributes: %X\n",
2715 memconf.len, (int)sizeof(memconf),
2716 memconf.no_of_stations,
2717 memconf.memory_block_size,
2718 memconf.tx_rx_memory_block_allocation,
2719 memconf.count_rx_queues, memconf.count_tx_queues,
2720 memconf.options,
2721 memconf.fragmentation,
2722 memconf.rx_queue1_count_descs,
2723 acx2cpu(memconf.rx_queue1_host_rx_start),
2724 memconf.tx_queue1_count_descs, memconf.tx_queue1_attributes);
2726 /* dump Acx111 Queue Configuration */
2727 printk("dump queue head:\n"
2728 "data read: %d, struct size: %d\n"
2729 "tx_memory_block_address (from card): %X\n"
2730 "rx_memory_block_address (from card): %X\n"
2731 "rx1_queue address (from card): %X\n"
2732 "tx1_queue address (from card): %X\n"
2733 "tx1_queue attributes (from card): %X\n",
2734 queueconf.len, (int)sizeof(queueconf),
2735 queueconf.tx_memory_block_address,
2736 queueconf.rx_memory_block_address,
2737 queueconf.rx1_queue_address,
2738 queueconf.tx1_queue_address, queueconf.tx1_attributes);
2740 /* dump Acx111 Mem Map */
2741 printk("dump mem map:\n"
2742 "data read: %d, struct size: %d\n"
2743 "Code start: %X\n"
2744 "Code end: %X\n"
2745 "WEP default key start: %X\n"
2746 "WEP default key end: %X\n"
2747 "STA table start: %X\n"
2748 "STA table end: %X\n"
2749 "Packet template start: %X\n"
2750 "Packet template end: %X\n"
2751 "Queue memory start: %X\n"
2752 "Queue memory end: %X\n"
2753 "Packet memory pool start: %X\n"
2754 "Packet memory pool end: %X\n"
2755 "iobase: %p\n"
2756 "iobase2: %p\n",
2757 *((u16 *) & memmap[0x02]), (int)sizeof(memmap),
2758 *((u32 *) & memmap[0x04]),
2759 *((u32 *) & memmap[0x08]),
2760 *((u32 *) & memmap[0x0C]),
2761 *((u32 *) & memmap[0x10]),
2762 *((u32 *) & memmap[0x14]),
2763 *((u32 *) & memmap[0x18]),
2764 *((u32 *) & memmap[0x1C]),
2765 *((u32 *) & memmap[0x20]),
2766 *((u32 *) & memmap[0x24]),
2767 *((u32 *) & memmap[0x28]),
2768 *((u32 *) & memmap[0x2C]),
2769 *((u32 *) & memmap[0x30]), adev->iobase, adev->iobase2);
2771 /* dump Acx111 Rx Config */
2772 printk("dump rx config:\n"
2773 "data read: %d, struct size: %d\n"
2774 "rx config: %X\n"
2775 "rx filter config: %X\n",
2776 *((u16 *) & rxconfig[0x02]), (int)sizeof(rxconfig),
2777 *((u16 *) & rxconfig[0x04]), *((u16 *) & rxconfig[0x06]));
2779 /* dump Acx111 fcs error */
2780 printk("dump fcserror:\n"
2781 "data read: %d, struct size: %d\n"
2782 "fcserrors: %X\n",
2783 *((u16 *) & fcserror[0x02]), (int)sizeof(fcserror),
2784 *((u32 *) & fcserror[0x04]));
2786 /* dump Acx111 rate fallback */
2787 printk("dump rate fallback:\n"
2788 "data read: %d, struct size: %d\n"
2789 "ratefallback: %X\n",
2790 *((u16 *) & ratefallback[0x02]), (int)sizeof(ratefallback),
2791 *((u8 *) & ratefallback[0x04]));
2793 /* protect against IRQ */
2794 acx_lock(adev, flags);
2796 /* dump acx111 internal rx descriptor ring buffer */
2797 rxdesc = adev->rxdesc_start;
2799 /* loop over complete receive pool */
2800 if (rxdesc)
2801 for (i = 0; i < RX_CNT; i++) {
2802 printk("\ndump internal rxdesc %d:\n"
2803 "mem pos %p\n"
2804 "next 0x%X\n"
2805 "acx mem pointer (dynamic) 0x%X\n"
2806 "CTL (dynamic) 0x%X\n"
2807 "Rate (dynamic) 0x%X\n"
2808 "RxStatus (dynamic) 0x%X\n"
2809 "Mod/Pre (dynamic) 0x%X\n",
2811 rxdesc,
2812 acx2cpu(rxdesc->pNextDesc),
2813 acx2cpu(rxdesc->ACXMemPtr),
2814 rxdesc->Ctl_8,
2815 rxdesc->rate, rxdesc->error, rxdesc->SNR);
2816 rxdesc++;
2819 /* dump host rx descriptor ring buffer */
2821 rxhostdesc = adev->rxhostdesc_start;
2823 /* loop over complete receive pool */
2824 if (rxhostdesc)
2825 for (i = 0; i < RX_CNT; i++) {
2826 printk("\ndump host rxdesc %d:\n"
2827 "mem pos %p\n"
2828 "buffer mem pos 0x%X\n"
2829 "buffer mem offset 0x%X\n"
2830 "CTL 0x%X\n"
2831 "Length 0x%X\n"
2832 "next 0x%X\n"
2833 "Status 0x%X\n",
2835 rxhostdesc,
2836 acx2cpu(rxhostdesc->data_phy),
2837 rxhostdesc->data_offset,
2838 le16_to_cpu(rxhostdesc->Ctl_16),
2839 le16_to_cpu(rxhostdesc->length),
2840 acx2cpu(rxhostdesc->desc_phy_next),
2841 rxhostdesc->Status);
2842 rxhostdesc++;
2845 /* dump acx111 internal tx descriptor ring buffer */
2846 txdesc = adev->txdesc_start;
2848 /* loop over complete transmit pool */
2849 if (txdesc)
2850 for (i = 0; i < TX_CNT; i++) {
2851 printk("\ndump internal txdesc %d:\n"
2852 "size 0x%X\n"
2853 "mem pos %p\n"
2854 "next 0x%X\n"
2855 "acx mem pointer (dynamic) 0x%X\n"
2856 "host mem pointer (dynamic) 0x%X\n"
2857 "length (dynamic) 0x%X\n"
2858 "CTL (dynamic) 0x%X\n"
2859 "CTL2 (dynamic) 0x%X\n"
2860 "Status (dynamic) 0x%X\n"
2861 "Rate (dynamic) 0x%X\n",
2863 (int)sizeof(struct txdesc),
2864 txdesc,
2865 acx2cpu(txdesc->pNextDesc),
2866 acx2cpu(txdesc->AcxMemPtr),
2867 acx2cpu(txdesc->HostMemPtr),
2868 le16_to_cpu(txdesc->total_length),
2869 txdesc->Ctl_8,
2870 txdesc->Ctl2_8, txdesc->error,
2871 txdesc->u.r1.rate);
2872 txdesc = advance_txdesc(adev, txdesc, 1);
2875 /* dump host tx descriptor ring buffer */
2877 txhostdesc = adev->txhostdesc_start;
2879 /* loop over complete host send pool */
2880 if (txhostdesc)
2881 for (i = 0; i < TX_CNT * 2; i++) {
2882 printk("\ndump host txdesc %d:\n"
2883 "mem pos %p\n"
2884 "buffer mem pos 0x%X\n"
2885 "buffer mem offset 0x%X\n"
2886 "CTL 0x%X\n"
2887 "Length 0x%X\n"
2888 "next 0x%X\n"
2889 "Status 0x%X\n",
2891 txhostdesc,
2892 acx2cpu(txhostdesc->data_phy),
2893 txhostdesc->data_offset,
2894 le16_to_cpu(txhostdesc->Ctl_16),
2895 le16_to_cpu(txhostdesc->length),
2896 acx2cpu(txhostdesc->desc_phy_next),
2897 le32_to_cpu(txhostdesc->Status));
2898 txhostdesc++;
2901 /* write_reg16(adev, 0xb4, 0x4); */
2903 acx_unlock(adev, flags);
2904 end_ok:
2906 acx_sem_unlock(adev);
2907 #endif /* ACX_DEBUG */
2908 return OK;
2912 /***********************************************************************
2915 acx100pci_ioctl_set_phy_amp_bias(struct net_device *ndev,
2916 struct iw_request_info *info,
2917 struct iw_param *vwrq, char *extra)
2919 acx_device_t *adev = ndev2adev(ndev);
2920 unsigned long flags;
2921 u16 gpio_old;
2923 if (!IS_ACX100(adev)) {
2924 /* WARNING!!!
2925 * Removing this check *might* damage
2926 * hardware, since we're tweaking GPIOs here after all!!!
2927 * You've been warned...
2928 * WARNING!!! */
2929 printk("acx: sorry, setting bias level for non-acx100 "
2930 "is not supported yet\n");
2931 return OK;
2934 if (*extra > 7) {
2935 printk("acx: invalid bias parameter, range is 0-7\n");
2936 return -EINVAL;
2939 acx_sem_lock(adev);
2941 /* Need to lock accesses to [IO_ACX_GPIO_OUT]:
2942 * IRQ handler uses it to update LED */
2943 acx_lock(adev, flags);
2944 gpio_old = read_reg16(adev, IO_ACX_GPIO_OUT);
2945 write_reg16(adev, IO_ACX_GPIO_OUT,
2946 (gpio_old & 0xf8ff) | ((u16) * extra << 8));
2947 acx_unlock(adev, flags);
2949 log(L_DEBUG, "gpio_old: 0x%04X\n", gpio_old);
2950 printk("%s: PHY power amplifier bias: old:%d, new:%d\n",
2951 ndev->name, (gpio_old & 0x0700) >> 8, (unsigned char)*extra);
2953 acx_sem_unlock(adev);
2955 return OK;
2957 #endif
2959 /***************************************************************
2960 ** acxpci_l_alloc_tx
2961 ** Actually returns a txdesc_t* ptr
2963 ** FIXME: in case of fragments, should allocate multiple descrs
2964 ** after figuring out how many we need and whether we still have
2965 ** sufficiently many.
2967 tx_t *acxpci_l_alloc_tx(acx_device_t * adev)
2969 struct txdesc *txdesc;
2970 unsigned head;
2971 u8 ctl8;
2973 FN_ENTER;
2975 if (unlikely(!adev->tx_free)) {
2976 printk("acx: BUG: no free txdesc left\n");
2977 txdesc = NULL;
2978 goto end;
2981 head = adev->tx_head;
2982 txdesc = get_txdesc(adev, head);
2983 ctl8 = txdesc->Ctl_8;
2985 /* 2005-10-11: there were several bug reports on this happening
2986 ** but now cause seems to be understood & fixed */
2987 if (unlikely(DESC_CTL_HOSTOWN != (ctl8 & DESC_CTL_ACXDONE_HOSTOWN))) {
2988 /* whoops, descr at current index is not free, so probably
2989 * ring buffer already full */
2990 printk("acx: BUG: tx_head:%d Ctl8:0x%02X - failed to find "
2991 "free txdesc\n", head, ctl8);
2992 txdesc = NULL;
2993 goto end;
2996 /* Needed in case txdesc won't be eventually submitted for tx */
2997 txdesc->Ctl_8 = DESC_CTL_ACXDONE_HOSTOWN;
2999 adev->tx_free--;
3000 log(L_BUFT, "tx: got desc %u, %u remain\n", head, adev->tx_free);
3001 /* Keep a few free descs between head and tail of tx ring.
3002 ** It is not absolutely needed, just feels safer */
3003 if (adev->tx_free < TX_STOP_QUEUE) {
3004 log(L_BUF, "stop queue (%u tx desc left)\n", adev->tx_free);
3005 acx_stop_queue(adev->ieee, NULL);
3008 /* returning current descriptor, so advance to next free one */
3009 adev->tx_head = (head + 1) % TX_CNT;
3010 end:
3011 FN_EXIT0;
3013 return (tx_t *) txdesc;
3017 /***********************************************************************
3019 void *acxpci_l_get_txbuf(acx_device_t * adev, tx_t * tx_opaque)
3021 return get_txhostdesc(adev, (txdesc_t *) tx_opaque)->data;
3025 /***********************************************************************
3026 ** acxpci_l_tx_data
3028 ** Can be called from IRQ (rx -> (AP bridging or mgmt response) -> tx).
3029 ** Can be called from acx_i_start_xmit (data frames from net core).
3031 ** FIXME: in case of fragments, should loop over the number of
3032 ** pre-allocated tx descrs, properly setting up transfer data and
3033 ** CTL_xxx flags according to fragment number.
3035 void
3036 acxpci_l_tx_data(acx_device_t * adev, tx_t * tx_opaque, int len,
3037 struct ieee80211_tx_control *ieeectl,struct sk_buff* skb)
3039 txdesc_t *txdesc = (txdesc_t *) tx_opaque;
3040 struct ieee80211_hdr *wireless_header;
3041 txhostdesc_t *hostdesc1, *hostdesc2;
3042 int rate_cur;
3043 u8 Ctl_8, Ctl2_8;
3044 int wlhdr_len;
3046 FN_ENTER;
3048 /* fw doesn't tx such packets anyhow */
3049 /* if (unlikely(len < WLAN_HDR_A3_LEN))
3050 goto end;
3052 hostdesc1 = get_txhostdesc(adev, txdesc);
3053 wireless_header = (struct ieee80211_hdr *)hostdesc1->data;
3054 /* modify flag status in separate variable to be able to write it back
3055 * in one big swoop later (also in order to have less device memory
3056 * accesses) */
3057 Ctl_8 = txdesc->Ctl_8;
3058 Ctl2_8 = 0; /* really need to init it to 0, not txdesc->Ctl2_8, it seems */
3060 hostdesc2 = hostdesc1 + 1;
3062 /* DON'T simply set Ctl field to 0 here globally,
3063 * it needs to maintain a consistent flag status (those are state flags!!),
3064 * otherwise it may lead to severe disruption. Only set or reset particular
3065 * flags at the exact moment this is needed... */
3067 /* let chip do RTS/CTS handshaking before sending
3068 * in case packet size exceeds threshold */
3069 if (ieeectl->flags & IEEE80211_TXCTL_USE_RTS_CTS)
3070 SET_BIT(Ctl2_8, DESC_CTL2_RTS);
3071 else
3072 CLEAR_BIT(Ctl2_8, DESC_CTL2_RTS);
3074 rate_cur = ieeectl->tx_rate;
3075 if (unlikely(!rate_cur)) {
3076 printk("acx: driver bug! bad ratemask\n");
3077 goto end;
3080 /* used in tx cleanup routine for auto rate and accounting: */
3081 /* put_txcr(adev, txdesc, clt, rate_cur); deprecated by mac80211 */
3083 txdesc->total_length = cpu_to_le16(len);
3084 wlhdr_len = ieee80211_get_hdrlen(le16_to_cpu(wireless_header->frame_control));
3085 hostdesc2->length = cpu_to_le16(len - wlhdr_len);
3087 if (!ieeectl->do_not_encrypt && ieeectl->key_idx>= 0)
3089 u16 key_idx = (u16)(ieeectl->key_idx);
3090 struct acx_key* key = &(adev->key[key_idx]);
3091 int wlhdr_len;
3092 if (key->enabled)
3094 memcpy(ieeehdr->wep_iv, ((u8*)wireless_header) + wlhdr_len, 4);
3098 if (IS_ACX111(adev)) {
3099 /* note that if !txdesc->do_auto, txrate->cur
3100 ** has only one nonzero bit */
3101 txdesc->u.r2.rate111 = cpu_to_le16(rate_cur
3102 /* WARNING: I was never able to make it work with prism54 AP.
3103 ** It was falling down to 1Mbit where shortpre is not applicable,
3104 ** and not working at all at "5,11 basic rates only" setting.
3105 ** I even didn't see tx packets in radio packet capture.
3106 ** Disabled for now --vda */
3107 /*| ((clt->shortpre && clt->cur!=RATE111_1) ? RATE111_SHORTPRE : 0) */
3109 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3110 /* should add this to rate111 above as necessary */
3111 |(clt->pbcc511 ? RATE111_PBCC511 : 0)
3112 #endif
3113 hostdesc1->length = cpu_to_le16(len);
3114 } else { /* ACX100 */
3115 u8 rate_100 = ieeectl->tx_rate;
3116 txdesc->u.r1.rate = rate_100;
3117 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3118 if (clt->pbcc511) {
3119 if (n == RATE100_5 || n == RATE100_11)
3120 n |= RATE100_PBCC511;
3123 if (clt->shortpre && (clt->cur != RATE111_1))
3124 SET_BIT(Ctl_8, DESC_CTL_SHORT_PREAMBLE); /* set Short Preamble */
3125 #endif
3126 /* set autodma and reclaim and 1st mpdu */
3127 SET_BIT(Ctl_8,
3128 DESC_CTL_AUTODMA | DESC_CTL_RECLAIM |
3129 DESC_CTL_FIRSTFRAG);
3130 #if ACX_FRAGMENTATION
3131 /* SET_BIT(Ctl2_8, DESC_CTL2_MORE_FRAG); cannot set it unconditionally, needs to be set for all non-last fragments */
3132 #endif
3133 hostdesc1->length = cpu_to_le16(wlhdr_len);
3135 /* don't need to clean ack/rts statistics here, already
3136 * done on descr cleanup */
3138 /* clears HOSTOWN and ACXDONE bits, thus telling that the descriptors
3139 * are now owned by the acx100; do this as LAST operation */
3140 CLEAR_BIT(Ctl_8, DESC_CTL_ACXDONE_HOSTOWN);
3141 /* flush writes before we release hostdesc to the adapter here */
3142 wmb();
3143 CLEAR_BIT(hostdesc1->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3144 CLEAR_BIT(hostdesc2->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3146 /* write back modified flags */
3147 CLEAR_BIT(Ctl2_8, DESC_CTL2_WEP);
3148 txdesc->Ctl2_8 = Ctl2_8;
3149 txdesc->Ctl_8 = Ctl_8;
3150 /* unused: txdesc->tx_time = cpu_to_le32(jiffies); */
3152 /* flush writes before we tell the adapter that it's its turn now */
3153 mmiowb();
3154 write_reg16(adev, IO_ACX_INT_TRIG, INT_TRIG_TXPRC);
3155 write_flush(adev);
3156 /* log the packet content AFTER sending it,
3157 * in order to not delay sending any further than absolutely needed
3158 * Do separate logs for acx100/111 to have human-readable rates */
3159 memcpy(&(hostdesc1->txstatus.control),ieeectl,sizeof(struct ieee80211_tx_control));
3160 hostdesc1->skb = skb;
3161 end:
3162 FN_EXIT0;
3166 /***********************************************************************
3167 ** acxpci_l_clean_txdesc
3169 ** This function resets the txdescs' status when the ACX100
3170 ** signals the TX done IRQ (txdescs have been processed), starting with
3171 ** the pool index of the descriptor which we would use next,
3172 ** in order to make sure that we can be as fast as possible
3173 ** in filling new txdescs.
3174 ** Everytime we get called we know where the next packet to be cleaned is.
3177 #if !ACX_DEBUG
3178 static inline void log_txbuffer(const acx_device_t * adev)
3181 #else
3182 static void log_txbuffer(acx_device_t * adev)
3184 txdesc_t *txdesc;
3185 int i;
3187 /* no FN_ENTER here, we don't want that */
3188 /* no locks here, since it's entirely non-critical code */
3189 txdesc = adev->txdesc_start;
3190 if (unlikely(!txdesc))
3191 return;
3192 printk("tx: desc->Ctl8's:");
3193 for (i = 0; i < TX_CNT; i++) {
3194 printk(" %02X", txdesc->Ctl_8);
3195 txdesc = advance_txdesc(adev, txdesc, 1);
3197 printk("\n");
3199 #endif
3202 static void handle_tx_error(acx_device_t * adev, u8 error, unsigned int finger,
3203 struct ieee80211_tx_status *status)
3205 const char *err = "unknown error";
3207 /* hmm, should we handle this as a mask
3208 * of *several* bits?
3209 * For now I think only caring about
3210 * individual bits is ok... */
3211 switch (error) {
3212 case 0x01:
3213 err = "no Tx due to error in other fragment";
3214 /* adev->wstats.discard.fragment++; */
3215 break;
3216 case 0x02:
3217 err = "Tx aborted";
3218 adev->stats.tx_aborted_errors++;
3219 break;
3220 case 0x04:
3221 err = "Tx desc wrong parameters";
3222 /* adev->wstats.discard.misc++; */
3223 break;
3224 case 0x08:
3225 err = "WEP key not found";
3226 /* adev->wstats.discard.misc++; */
3227 break;
3228 case 0x10:
3229 err = "MSDU lifetime timeout? - try changing "
3230 "'iwconfig retry lifetime XXX'";
3231 /* adev->wstats.discard.misc++; */
3232 break;
3233 case 0x20:
3234 err = "excessive Tx retries due to either distance "
3235 "too high or unable to Tx or Tx frame error - "
3236 "try changing 'iwconfig txpower XXX' or "
3237 "'sens'itivity or 'retry'";
3238 /* adev->wstats.discard.retries++; */
3239 /* Tx error 0x20 also seems to occur on
3240 * overheating, so I'm not sure whether we
3241 * actually want to do aggressive radio recalibration,
3242 * since people maybe won't notice then that their hardware
3243 * is slowly getting cooked...
3244 * Or is it still a safe long distance from utter
3245 * radio non-functionality despite many radio recalibs
3246 * to final destructive overheating of the hardware?
3247 * In this case we really should do recalib here...
3248 * I guess the only way to find out is to do a
3249 * potentially fatal self-experiment :-\
3250 * Or maybe only recalib in case we're using Tx
3251 * rate auto (on errors switching to lower speed
3252 * --> less heat?) or 802.11 power save mode?
3254 * ok, just do it. */
3255 if (++adev->retry_errors_msg_ratelimit % 4 == 0) {
3256 if (adev->retry_errors_msg_ratelimit <= 20) {
3257 printk("%s: several excessive Tx "
3258 "retry errors occurred, attempting "
3259 "to recalibrate radio. Radio "
3260 "drift might be caused by increasing "
3261 "card temperature, please check the card "
3262 "before it's too late!\n",
3263 wiphy_name(adev->ieee->wiphy));
3264 if (adev->retry_errors_msg_ratelimit == 20)
3265 printk("disabling above message\n");
3268 acx_schedule_task(adev,
3269 ACX_AFTER_IRQ_CMD_RADIO_RECALIB);
3271 status->excessive_retries++;
3272 break;
3273 case 0x40:
3274 err = "Tx buffer overflow";
3275 adev->stats.tx_fifo_errors++;
3276 break;
3277 case 0x80:
3278 /* possibly ACPI C-state powersaving related!!!
3279 * (DMA timeout due to excessively high wakeup
3280 * latency after C-state activation!?)
3281 * Disable C-State powersaving and try again,
3282 * then PLEASE REPORT, I'm VERY interested in
3283 * whether my theory is correct that this is
3284 * actually the problem here.
3285 * In that case, use new Linux idle wakeup latency
3286 * requirements kernel API to prevent this issue. */
3287 err = "DMA error";
3288 /* adev->wstats.discard.misc++; */
3289 break;
3291 adev->stats.tx_errors++;
3292 if (adev->stats.tx_errors <= 20)
3293 printk("%s: tx error 0x%02X, buf %02u! (%s)\n",
3294 wiphy_name(adev->ieee->wiphy), error, finger, err);
3295 else
3296 printk("%s: tx error 0x%02X, buf %02u!\n",
3297 wiphy_name(adev->ieee->wiphy), error, finger);
3301 unsigned int acxpci_l_clean_txdesc(acx_device_t * adev)
3303 txdesc_t *txdesc;
3304 txhostdesc_t *hostdesc;
3305 unsigned finger;
3306 int num_cleaned;
3307 u16 r111;
3308 u8 error, ack_failures, rts_failures, rts_ok, r100;
3310 FN_ENTER;
3312 if (unlikely(acx_debug & L_DEBUG))
3313 log_txbuffer(adev);
3315 log(L_BUFT, "tx: cleaning up bufs from %u\n", adev->tx_tail);
3317 /* We know first descr which is not free yet. We advance it as far
3318 ** as we see correct bits set in following descs (if next desc
3319 ** is NOT free, we shouldn't advance at all). We know that in
3320 ** front of tx_tail may be "holes" with isolated free descs.
3321 ** We will catch up when all intermediate descs will be freed also */
3323 finger = adev->tx_tail;
3324 num_cleaned = 0;
3325 while (likely(finger != adev->tx_head)) {
3326 txdesc = get_txdesc(adev, finger);
3328 /* If we allocated txdesc on tx path but then decided
3329 ** to NOT use it, then it will be left as a free "bubble"
3330 ** in the "allocated for tx" part of the ring.
3331 ** We may meet it on the next ring pass here. */
3333 /* stop if not marked as "tx finished" and "host owned" */
3334 if ((txdesc->Ctl_8 & DESC_CTL_ACXDONE_HOSTOWN)
3335 != DESC_CTL_ACXDONE_HOSTOWN) {
3336 if (unlikely(!num_cleaned)) { /* maybe remove completely */
3337 log(L_BUFT, "clean_txdesc: tail isn't free. "
3338 "tail:%d head:%d\n",
3339 adev->tx_tail, adev->tx_head);
3341 break;
3344 /* remember desc values... */
3345 error = txdesc->error;
3346 ack_failures = txdesc->ack_failures;
3347 rts_failures = txdesc->rts_failures;
3348 rts_ok = txdesc->rts_ok;
3349 r100 = txdesc->u.r1.rate;
3350 r111 = le16_to_cpu(txdesc->u.r2.rate111);
3352 /* need to check for certain error conditions before we
3353 * clean the descriptor: we still need valid descr data here */
3354 hostdesc = get_txhostdesc(adev, txdesc);
3356 hostdesc->txstatus.flags |= IEEE80211_TX_STATUS_ACK;
3357 if (unlikely(0x30 & error)) {
3358 /* only send IWEVTXDROP in case of retry or lifetime exceeded;
3359 * all other errors mean we screwed up locally */
3360 /* union iwreq_data wrqu;
3361 struct ieee80211_hdr_3addr *hdr;
3362 hdr = (struct ieee80211_hdr_3addr *) hostdesc->data;
3363 MAC_COPY(wrqu.addr.sa_data, hdr->addr1);
3365 hostdesc->txstatus.flags &= ~IEEE80211_TX_STATUS_ACK;
3368 /* ...and free the desc */
3369 txdesc->error = 0;
3370 txdesc->ack_failures = 0;
3371 txdesc->rts_failures = 0;
3372 txdesc->rts_ok = 0;
3373 /* signal host owning it LAST, since ACX already knows that this
3374 ** descriptor is finished since it set Ctl_8 accordingly. */
3375 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3377 adev->tx_free++;
3378 num_cleaned++;
3380 if ((adev->tx_free >= TX_START_QUEUE)
3381 /* && (adev->status == ACX_STATUS_4_ASSOCIATED) */
3382 /*&& (acx_queue_stopped(adev->ieee))*/
3384 log(L_BUF, "tx: wake queue (avail. Tx desc %u)\n",
3385 adev->tx_free);
3386 acx_wake_queue(adev->ieee, NULL);
3389 /* do error checking, rate handling and logging
3390 * AFTER having done the work, it's faster */
3392 /* Rate handling is done in mac80211 */
3393 /* if (adev->rate_auto) {
3394 struct client *clt = get_txc(adev, txdesc);
3395 if (clt) {
3396 u16 cur = get_txr(adev, txdesc);
3397 if (clt->rate_cur == cur) {
3398 acx_l_handle_txrate_auto(adev, clt, cur,*/ /* intended rate */
3399 /*r100, r111,*/ /* actually used rate */
3400 /*(error & 0x30),*/ /* was there an error? */
3401 /* TX_CNT +
3402 TX_CLEAN_BACKLOG
3404 adev->tx_free);
3409 if (unlikely(error))
3410 handle_tx_error(adev, error, finger, &hostdesc->txstatus);
3412 if (IS_ACX111(adev))
3413 log(L_BUFT,
3414 "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u r111=%04X tx_free=%u\n",
3415 finger, ack_failures, rts_failures, rts_ok, r111, adev->tx_free);
3416 else
3417 log(L_BUFT,
3418 "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u rate=%u\n",
3419 finger, ack_failures, rts_failures, rts_ok, r100);
3421 /* And finally report upstream */
3422 if (hostdesc)
3424 hostdesc->txstatus.excessive_retries = rts_failures ;
3425 hostdesc->txstatus.retry_count = ack_failures;
3426 ieee80211_tx_status(adev->ieee,hostdesc->skb,&hostdesc->txstatus);
3427 memset(&hostdesc->txstatus, 0, sizeof(struct ieee80211_tx_status));
3429 /* update pointer for descr to be cleaned next */
3430 finger = (finger + 1) % TX_CNT;
3432 /* remember last position */
3433 adev->tx_tail = finger;
3434 /* end: */
3435 FN_EXIT1(num_cleaned);
3436 return num_cleaned;
3439 /* clean *all* Tx descriptors, and regardless of their previous state.
3440 * Used for brute-force reset handling. */
3441 void acxpci_l_clean_txdesc_emergency(acx_device_t * adev)
3443 txdesc_t *txdesc;
3444 int i;
3446 FN_ENTER;
3448 for (i = 0; i < TX_CNT; i++) {
3449 txdesc = get_txdesc(adev, i);
3451 /* free it */
3452 txdesc->ack_failures = 0;
3453 txdesc->rts_failures = 0;
3454 txdesc->rts_ok = 0;
3455 txdesc->error = 0;
3456 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3459 adev->tx_free = TX_CNT;
3461 FN_EXIT0;
3465 /***********************************************************************
3466 ** acxpci_s_create_tx_host_desc_queue
3469 static void *allocate(acx_device_t * adev, size_t size, dma_addr_t * phy,
3470 const char *msg)
3472 void *ptr;
3474 ptr = dma_alloc_coherent(adev->pdev ? &adev->pdev->dev : NULL,
3475 size, phy, GFP_KERNEL);
3477 if (ptr) {
3478 log(L_DEBUG, "%s sz=%d adr=0x%p phy=0x%08llx\n",
3479 msg, (int)size, ptr, (unsigned long long)*phy);
3480 memset(ptr, 0, size);
3481 return ptr;
3483 printk(KERN_ERR "acx: %s allocation FAILED (%d bytes)\n",
3484 msg, (int)size);
3485 return NULL;
3489 static int acxpci_s_create_tx_host_desc_queue(acx_device_t * adev)
3491 txhostdesc_t *hostdesc;
3492 u8 *txbuf;
3493 dma_addr_t hostdesc_phy;
3494 dma_addr_t txbuf_phy;
3495 int i;
3497 FN_ENTER;
3499 /* allocate TX buffer */
3500 adev->txbuf_area_size = TX_CNT * /*WLAN_A4FR_MAXLEN_WEP_FCS*/ (30 + 2312 + 4);
3501 adev->txbuf_start = allocate(adev, adev->txbuf_area_size,
3502 &adev->txbuf_startphy, "txbuf_start");
3503 if (!adev->txbuf_start)
3504 goto fail;
3506 /* allocate the TX host descriptor queue pool */
3507 adev->txhostdesc_area_size = TX_CNT * 2 * sizeof(*hostdesc);
3508 adev->txhostdesc_start = allocate(adev, adev->txhostdesc_area_size,
3509 &adev->txhostdesc_startphy,
3510 "txhostdesc_start");
3511 if (!adev->txhostdesc_start)
3512 goto fail;
3513 /* check for proper alignment of TX host descriptor pool */
3514 if ((long)adev->txhostdesc_start & 3) {
3515 printk
3516 ("acx: driver bug: dma alloc returns unaligned address\n");
3517 goto fail;
3520 hostdesc = adev->txhostdesc_start;
3521 hostdesc_phy = adev->txhostdesc_startphy;
3522 txbuf = adev->txbuf_start;
3523 txbuf_phy = adev->txbuf_startphy;
3525 #if 0
3526 /* Each tx buffer is accessed by hardware via
3527 ** txdesc -> txhostdesc(s) -> txbuffer(s).
3528 ** We use only one txhostdesc per txdesc, but it looks like
3529 ** acx111 is buggy: it accesses second txhostdesc
3530 ** (via hostdesc.desc_phy_next field) even if
3531 ** txdesc->length == hostdesc->length and thus
3532 ** entire packet was placed into first txhostdesc.
3533 ** Due to this bug acx111 hangs unless second txhostdesc
3534 ** has le16_to_cpu(hostdesc.length) = 3 (or larger)
3535 ** Storing NULL into hostdesc.desc_phy_next
3536 ** doesn't seem to help.
3538 ** Update: although it worked on Xterasys XN-2522g
3539 ** with len=3 trick, WG311v2 is even more bogus, doesn't work.
3540 ** Keeping this code (#ifdef'ed out) for documentational purposes.
3542 for (i = 0; i < TX_CNT * 2; i++) {
3543 hostdesc_phy += sizeof(*hostdesc);
3544 if (!(i & 1)) {
3545 hostdesc->data_phy = cpu2acx(txbuf_phy);
3546 /* hostdesc->data_offset = ... */
3547 /* hostdesc->reserved = ... */
3548 hostdesc->Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
3549 /* hostdesc->length = ... */
3550 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3551 hostdesc->pNext = ptr2acx(NULL);
3552 /* hostdesc->Status = ... */
3553 /* below: non-hardware fields */
3554 hostdesc->data = txbuf;
3556 txbuf += WLAN_A4FR_MAXLEN_WEP_FCS;
3557 txbuf_phy += WLAN_A4FR_MAXLEN_WEP_FCS;
3558 } else {
3559 /* hostdesc->data_phy = ... */
3560 /* hostdesc->data_offset = ... */
3561 /* hostdesc->reserved = ... */
3562 /* hostdesc->Ctl_16 = ... */
3563 hostdesc->length = cpu_to_le16(3); /* bug workaround */
3564 /* hostdesc->desc_phy_next = ... */
3565 /* hostdesc->pNext = ... */
3566 /* hostdesc->Status = ... */
3567 /* below: non-hardware fields */
3568 /* hostdesc->data = ... */
3570 hostdesc++;
3572 #endif
3573 /* We initialize two hostdescs so that they point to adjacent
3574 ** memory areas. Thus txbuf is really just a contiguous memory area */
3575 for (i = 0; i < TX_CNT * 2; i++) {
3576 hostdesc_phy += sizeof(*hostdesc);
3578 hostdesc->data_phy = cpu2acx(txbuf_phy);
3579 /* done by memset(0): hostdesc->data_offset = 0; */
3580 /* hostdesc->reserved = ... */
3581 hostdesc->Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
3582 /* hostdesc->length = ... */
3583 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3584 /* done by memset(0): hostdesc->pNext = ptr2acx(NULL); */
3585 /* hostdesc->Status = ... */
3586 /* ->data is a non-hardware field: */
3587 hostdesc->data = txbuf;
3589 if (!(i & 1)) {
3590 txbuf += 24 /*WLAN_HDR_A3_LEN*/;
3591 txbuf_phy += 24 /*WLAN_HDR_A3_LEN*/;
3592 } else {
3593 txbuf += 30 + 2132 + 4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3594 txbuf_phy += 30 + 2132 +4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3596 hostdesc++;
3598 hostdesc--;
3599 hostdesc->desc_phy_next = cpu2acx(adev->txhostdesc_startphy);
3601 FN_EXIT1(OK);
3602 return OK;
3603 fail:
3604 printk("acx: create_tx_host_desc_queue FAILED\n");
3605 /* dealloc will be done by free function on error case */
3606 FN_EXIT1(NOT_OK);
3607 return NOT_OK;
3611 /***************************************************************
3612 ** acxpci_s_create_rx_host_desc_queue
3614 /* the whole size of a data buffer (header plus data body)
3615 * plus 32 bytes safety offset at the end */
3616 #define RX_BUFFER_SIZE (sizeof(rxbuffer_t) + 32)
3618 static int acxpci_s_create_rx_host_desc_queue(acx_device_t * adev)
3620 rxhostdesc_t *hostdesc;
3621 rxbuffer_t *rxbuf;
3622 dma_addr_t hostdesc_phy;
3623 dma_addr_t rxbuf_phy;
3624 int i;
3626 FN_ENTER;
3628 /* allocate the RX host descriptor queue pool */
3629 adev->rxhostdesc_area_size = RX_CNT * sizeof(*hostdesc);
3630 adev->rxhostdesc_start = allocate(adev, adev->rxhostdesc_area_size,
3631 &adev->rxhostdesc_startphy,
3632 "rxhostdesc_start");
3633 if (!adev->rxhostdesc_start)
3634 goto fail;
3635 /* check for proper alignment of RX host descriptor pool */
3636 if ((long)adev->rxhostdesc_start & 3) {
3637 printk
3638 ("acx: driver bug: dma alloc returns unaligned address\n");
3639 goto fail;
3642 /* allocate Rx buffer pool which will be used by the acx
3643 * to store the whole content of the received frames in it */
3644 adev->rxbuf_area_size = RX_CNT * RX_BUFFER_SIZE;
3645 adev->rxbuf_start = allocate(adev, adev->rxbuf_area_size,
3646 &adev->rxbuf_startphy, "rxbuf_start");
3647 if (!adev->rxbuf_start)
3648 goto fail;
3650 rxbuf = adev->rxbuf_start;
3651 rxbuf_phy = adev->rxbuf_startphy;
3652 hostdesc = adev->rxhostdesc_start;
3653 hostdesc_phy = adev->rxhostdesc_startphy;
3655 /* don't make any popular C programming pointer arithmetic mistakes
3656 * here, otherwise I'll kill you...
3657 * (and don't dare asking me why I'm warning you about that...) */
3658 for (i = 0; i < RX_CNT; i++) {
3659 hostdesc->data = rxbuf;
3660 hostdesc->data_phy = cpu2acx(rxbuf_phy);
3661 hostdesc->length = cpu_to_le16(RX_BUFFER_SIZE);
3662 CLEAR_BIT(hostdesc->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3663 rxbuf++;
3664 rxbuf_phy += sizeof(*rxbuf);
3665 hostdesc_phy += sizeof(*hostdesc);
3666 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3667 hostdesc++;
3669 hostdesc--;
3670 hostdesc->desc_phy_next = cpu2acx(adev->rxhostdesc_startphy);
3671 FN_EXIT1(OK);
3672 return OK;
3673 fail:
3674 printk("acx: create_rx_host_desc_queue FAILED\n");
3675 /* dealloc will be done by free function on error case */
3676 FN_EXIT1(NOT_OK);
3677 return NOT_OK;
3681 /***************************************************************
3682 ** acxpci_s_create_hostdesc_queues
3684 int acxpci_s_create_hostdesc_queues(acx_device_t * adev)
3686 int result;
3687 result = acxpci_s_create_tx_host_desc_queue(adev);
3688 if (OK != result)
3689 return result;
3690 result = acxpci_s_create_rx_host_desc_queue(adev);
3691 return result;
3695 /***************************************************************
3696 ** acxpci_create_tx_desc_queue
3698 static void acxpci_create_tx_desc_queue(acx_device_t * adev, u32 tx_queue_start)
3700 txdesc_t *txdesc;
3701 txhostdesc_t *hostdesc;
3702 dma_addr_t hostmemptr;
3703 u32 mem_offs;
3704 int i;
3706 FN_ENTER;
3708 if (IS_ACX100(adev))
3709 adev->txdesc_size = sizeof(*txdesc);
3710 else
3711 /* the acx111 txdesc is 4 bytes larger */
3712 adev->txdesc_size = sizeof(*txdesc) + 4;
3714 adev->txdesc_start = (txdesc_t *) (adev->iobase2 + tx_queue_start);
3716 log(L_DEBUG, "adev->iobase2=%p\n"
3717 "tx_queue_start=%08X\n"
3718 "adev->txdesc_start=%p\n",
3719 adev->iobase2, tx_queue_start, adev->txdesc_start);
3721 adev->tx_free = TX_CNT;
3722 /* done by memset: adev->tx_head = 0; */
3723 /* done by memset: adev->tx_tail = 0; */
3724 txdesc = adev->txdesc_start;
3725 mem_offs = tx_queue_start;
3726 hostmemptr = adev->txhostdesc_startphy;
3727 hostdesc = adev->txhostdesc_start;
3729 if (IS_ACX111(adev)) {
3730 /* ACX111 has a preinitialized Tx buffer! */
3731 /* loop over whole send pool */
3732 /* FIXME: do we have to do the hostmemptr stuff here?? */
3733 for (i = 0; i < TX_CNT; i++) {
3734 txdesc->HostMemPtr = ptr2acx(hostmemptr);
3735 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3736 /* reserve two (hdr desc and payload desc) */
3737 hostdesc += 2;
3738 hostmemptr += 2 * sizeof(*hostdesc);
3739 txdesc = advance_txdesc(adev, txdesc, 1);
3741 } else {
3742 /* ACX100 Tx buffer needs to be initialized by us */
3743 /* clear whole send pool. sizeof is safe here (we are acx100) */
3744 memset(adev->txdesc_start, 0, TX_CNT * sizeof(*txdesc));
3746 /* loop over whole send pool */
3747 for (i = 0; i < TX_CNT; i++) {
3748 log(L_DEBUG, "configure card tx descriptor: 0x%p, "
3749 "size: 0x%X\n", txdesc, adev->txdesc_size);
3751 /* pointer to hostdesc memory */
3752 txdesc->HostMemPtr = ptr2acx(hostmemptr);
3753 /* initialise ctl */
3754 txdesc->Ctl_8 = (DESC_CTL_HOSTOWN | DESC_CTL_RECLAIM
3755 | DESC_CTL_AUTODMA |
3756 DESC_CTL_FIRSTFRAG);
3757 /* done by memset(0): txdesc->Ctl2_8 = 0; */
3758 /* point to next txdesc */
3759 txdesc->pNextDesc =
3760 cpu2acx(mem_offs + adev->txdesc_size);
3761 /* reserve two (hdr desc and payload desc) */
3762 hostdesc += 2;
3763 hostmemptr += 2 * sizeof(*hostdesc);
3764 /* go to the next one */
3765 mem_offs += adev->txdesc_size;
3766 /* ++ is safe here (we are acx100) */
3767 txdesc++;
3769 /* go back to the last one */
3770 txdesc--;
3771 /* and point to the first making it a ring buffer */
3772 txdesc->pNextDesc = cpu2acx(tx_queue_start);
3774 FN_EXIT0;
3778 /***************************************************************
3779 ** acxpci_create_rx_desc_queue
3781 static void acxpci_create_rx_desc_queue(acx_device_t * adev, u32 rx_queue_start)
3783 rxdesc_t *rxdesc;
3784 u32 mem_offs;
3785 int i;
3787 FN_ENTER;
3789 /* done by memset: adev->rx_tail = 0; */
3791 /* ACX111 doesn't need any further config: preconfigures itself.
3792 * Simply print ring buffer for debugging */
3793 if (IS_ACX111(adev)) {
3794 /* rxdesc_start already set here */
3796 adev->rxdesc_start =
3797 (rxdesc_t *) ((u8 *) adev->iobase2 + rx_queue_start);
3799 rxdesc = adev->rxdesc_start;
3800 for (i = 0; i < RX_CNT; i++) {
3801 log(L_DEBUG, "rx descriptor %d @ 0x%p\n", i, rxdesc);
3802 rxdesc = adev->rxdesc_start = (rxdesc_t *)
3803 (adev->iobase2 + acx2cpu(rxdesc->pNextDesc));
3805 } else {
3806 /* we didn't pre-calculate rxdesc_start in case of ACX100 */
3807 /* rxdesc_start should be right AFTER Tx pool */
3808 adev->rxdesc_start = (rxdesc_t *)
3809 ((u8 *) adev->txdesc_start + (TX_CNT * sizeof(txdesc_t)));
3810 /* NB: sizeof(txdesc_t) above is valid because we know
3811 ** we are in if (acx100) block. Beware of cut-n-pasting elsewhere!
3812 ** acx111's txdesc is larger! */
3814 memset(adev->rxdesc_start, 0, RX_CNT * sizeof(*rxdesc));
3816 /* loop over whole receive pool */
3817 rxdesc = adev->rxdesc_start;
3818 mem_offs = rx_queue_start;
3819 for (i = 0; i < RX_CNT; i++) {
3820 log(L_DEBUG, "rx descriptor @ 0x%p\n", rxdesc);
3821 rxdesc->Ctl_8 = DESC_CTL_RECLAIM | DESC_CTL_AUTODMA;
3822 /* point to next rxdesc */
3823 rxdesc->pNextDesc = cpu2acx(mem_offs + sizeof(*rxdesc));
3824 /* go to the next one */
3825 mem_offs += sizeof(*rxdesc);
3826 rxdesc++;
3828 /* go to the last one */
3829 rxdesc--;
3831 /* and point to the first making it a ring buffer */
3832 rxdesc->pNextDesc = cpu2acx(rx_queue_start);
3834 FN_EXIT0;
3838 /***************************************************************
3839 ** acxpci_create_desc_queues
3841 void
3842 acxpci_create_desc_queues(acx_device_t * adev, u32 tx_queue_start,
3843 u32 rx_queue_start)
3845 acxpci_create_tx_desc_queue(adev, tx_queue_start);
3846 acxpci_create_rx_desc_queue(adev, rx_queue_start);
3850 /***************************************************************
3851 ** acxpci_s_proc_diag_output
3853 char *acxpci_s_proc_diag_output(char *p, acx_device_t * adev)
3855 const char *rtl, *thd, *ttl;
3856 rxhostdesc_t *rxhostdesc;
3857 txdesc_t *txdesc;
3858 int i;
3860 FN_ENTER;
3862 p += sprintf(p, "** Rx buf **\n");
3863 rxhostdesc = adev->rxhostdesc_start;
3864 if (rxhostdesc)
3865 for (i = 0; i < RX_CNT; i++) {
3866 rtl = (i == adev->rx_tail) ? " [tail]" : "";
3867 if ((rxhostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
3868 && (rxhostdesc->
3869 Status & cpu_to_le32(DESC_STATUS_FULL)))
3870 p += sprintf(p, "%02u FULL%s\n", i, rtl);
3871 else
3872 p += sprintf(p, "%02u empty%s\n", i, rtl);
3873 rxhostdesc++;
3875 /* p += sprintf(p, "** Tx buf (free %d, Linux netqueue %s) **\n",
3876 adev->tx_free,
3877 acx_queue_stopped(adev->ieee) ? "STOPPED" : "running");*/
3878 txdesc = adev->txdesc_start;
3879 if (txdesc)
3880 for (i = 0; i < TX_CNT; i++) {
3881 thd = (i == adev->tx_head) ? " [head]" : "";
3882 ttl = (i == adev->tx_tail) ? " [tail]" : "";
3883 if (txdesc->Ctl_8 & DESC_CTL_ACXDONE)
3884 p += sprintf(p, "%02u free (%02X)%s%s\n", i,
3885 txdesc->Ctl_8, thd, ttl);
3886 else
3887 p += sprintf(p, "%02u tx (%02X)%s%s\n", i,
3888 txdesc->Ctl_8, thd, ttl);
3889 txdesc = advance_txdesc(adev, txdesc, 1);
3891 p += sprintf(p,
3892 "\n"
3893 "** PCI data **\n"
3894 "txbuf_start %p, txbuf_area_size %u, txbuf_startphy %08llx\n"
3895 "txdesc_size %u, txdesc_start %p\n"
3896 "txhostdesc_start %p, txhostdesc_area_size %u, txhostdesc_startphy %08llx\n"
3897 "rxdesc_start %p\n"
3898 "rxhostdesc_start %p, rxhostdesc_area_size %u, rxhostdesc_startphy %08llx\n"
3899 "rxbuf_start %p, rxbuf_area_size %u, rxbuf_startphy %08llx\n",
3900 adev->txbuf_start, adev->txbuf_area_size,
3901 (unsigned long long)adev->txbuf_startphy,
3902 adev->txdesc_size, adev->txdesc_start,
3903 adev->txhostdesc_start, adev->txhostdesc_area_size,
3904 (unsigned long long)adev->txhostdesc_startphy,
3905 adev->rxdesc_start,
3906 adev->rxhostdesc_start, adev->rxhostdesc_area_size,
3907 (unsigned long long)adev->rxhostdesc_startphy,
3908 adev->rxbuf_start, adev->rxbuf_area_size,
3909 (unsigned long long)adev->rxbuf_startphy);
3911 FN_EXIT0;
3912 return p;
3916 /***********************************************************************
3918 int acxpci_proc_eeprom_output(char *buf, acx_device_t * adev)
3920 char *p = buf;
3921 int i;
3923 FN_ENTER;
3925 for (i = 0; i < 0x400; i++) {
3926 acxpci_read_eeprom_byte(adev, i, p++);
3929 FN_EXIT1(p - buf);
3930 return p - buf;
3934 /***********************************************************************
3935 ** Obvious
3937 void acxpci_set_interrupt_mask(acx_device_t * adev)
3939 if (IS_ACX111(adev)) {
3940 adev->irq_mask = (u16) ~ (0
3941 /* | HOST_INT_RX_DATA */
3942 | HOST_INT_TX_COMPLETE
3943 /* | HOST_INT_TX_XFER */
3944 | HOST_INT_RX_COMPLETE
3945 /* | HOST_INT_DTIM */
3946 /* | HOST_INT_BEACON */
3947 /* | HOST_INT_TIMER */
3948 /* | HOST_INT_KEY_NOT_FOUND */
3949 | HOST_INT_IV_ICV_FAILURE
3950 | HOST_INT_CMD_COMPLETE
3951 | HOST_INT_INFO
3952 /* | HOST_INT_OVERFLOW */
3953 /* | HOST_INT_PROCESS_ERROR */
3954 | HOST_INT_SCAN_COMPLETE
3955 | HOST_INT_FCS_THRESHOLD
3956 /* | HOST_INT_UNKNOWN */
3958 /* Or else acx100 won't signal cmd completion, right? */
3959 adev->irq_mask_off = (u16) ~ (HOST_INT_CMD_COMPLETE); /* 0xfdff */
3960 } else {
3961 adev->irq_mask = (u16) ~ (0
3962 /* | HOST_INT_RX_DATA */
3963 | HOST_INT_TX_COMPLETE
3964 /* | HOST_INT_TX_XFER */
3965 | HOST_INT_RX_COMPLETE
3966 /* | HOST_INT_DTIM */
3967 /* | HOST_INT_BEACON */
3968 /* | HOST_INT_TIMER */
3969 /* | HOST_INT_KEY_NOT_FOUND */
3970 /* | HOST_INT_IV_ICV_FAILURE */
3971 | HOST_INT_CMD_COMPLETE
3972 | HOST_INT_INFO
3973 /* | HOST_INT_OVERFLOW */
3974 /* | HOST_INT_PROCESS_ERROR */
3975 | HOST_INT_SCAN_COMPLETE
3976 /* | HOST_INT_FCS_THRESHOLD */
3977 /* | HOST_INT_UNKNOWN */
3979 adev->irq_mask_off = (u16) ~ (HOST_INT_UNKNOWN); /* 0x7fff */
3984 /***********************************************************************
3986 int acx100pci_s_set_tx_level(acx_device_t * adev, u8 level_dbm)
3988 /* since it can be assumed that at least the Maxim radio has a
3989 * maximum power output of 20dBm and since it also can be
3990 * assumed that these values drive the DAC responsible for
3991 * setting the linear Tx level, I'd guess that these values
3992 * should be the corresponding linear values for a dBm value,
3993 * in other words: calculate the values from that formula:
3994 * Y [dBm] = 10 * log (X [mW])
3995 * then scale the 0..63 value range onto the 1..100mW range (0..20 dBm)
3996 * and you're done...
3997 * Hopefully that's ok, but you never know if we're actually
3998 * right... (especially since Windows XP doesn't seem to show
3999 * actual Tx dBm values :-P) */
4001 /* NOTE: on Maxim, value 30 IS 30mW, and value 10 IS 10mW - so the
4002 * values are EXACTLY mW!!! Not sure about RFMD and others,
4003 * though... */
4004 static const u8 dbm2val_maxim[21] = {
4005 63, 63, 63, 62,
4006 61, 61, 60, 60,
4007 59, 58, 57, 55,
4008 53, 50, 47, 43,
4009 38, 31, 23, 13,
4012 static const u8 dbm2val_rfmd[21] = {
4013 0, 0, 0, 1,
4014 2, 2, 3, 3,
4015 4, 5, 6, 8,
4016 10, 13, 16, 20,
4017 25, 32, 41, 50,
4020 const u8 *table;
4022 switch (adev->radio_type) {
4023 case RADIO_MAXIM_0D:
4024 table = &dbm2val_maxim[0];
4025 break;
4026 case RADIO_RFMD_11:
4027 case RADIO_RALINK_15:
4028 table = &dbm2val_rfmd[0];
4029 break;
4030 default:
4031 printk("%s: unknown/unsupported radio type, "
4032 "cannot modify tx power level yet!\n", wiphy_name(adev->ieee->wiphy));
4033 return NOT_OK;
4035 printk("%s: changing radio power level to %u dBm (%u)\n",
4036 wiphy_name(adev->ieee->wiphy), level_dbm, table[level_dbm]);
4037 acxpci_s_write_phy_reg(adev, 0x11, table[level_dbm]);
4038 return OK;
4042 /***********************************************************************
4043 ** Data for init_module/cleanup_module
4045 static const struct pci_device_id acxpci_id_tbl[] __devinitdata = {
4047 .vendor = PCI_VENDOR_ID_TI,
4048 .device = PCI_DEVICE_ID_TI_TNETW1100A,
4049 .subvendor = PCI_ANY_ID,
4050 .subdevice = PCI_ANY_ID,
4051 .driver_data = CHIPTYPE_ACX100,
4054 .vendor = PCI_VENDOR_ID_TI,
4055 .device = PCI_DEVICE_ID_TI_TNETW1100B,
4056 .subvendor = PCI_ANY_ID,
4057 .subdevice = PCI_ANY_ID,
4058 .driver_data = CHIPTYPE_ACX100,
4061 .vendor = PCI_VENDOR_ID_TI,
4062 .device = PCI_DEVICE_ID_TI_TNETW1130,
4063 .subvendor = PCI_ANY_ID,
4064 .subdevice = PCI_ANY_ID,
4065 .driver_data = CHIPTYPE_ACX111,
4068 .vendor = 0,
4069 .device = 0,
4070 .subvendor = 0,
4071 .subdevice = 0,
4072 .driver_data = 0,
4076 MODULE_DEVICE_TABLE(pci, acxpci_id_tbl);
4078 /* FIXME: checks should be removed once driver is included in the kernel */
4079 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 11)
4080 /* pci_name() got introduced at start of 2.6.x,
4081 * got mandatory (slot_name member removed) in 2.6.11-bk1 */
4082 #define pci_name(x) x->slot_name
4083 #endif
4085 static struct pci_driver
4086 acxpci_drv_id = {
4087 .name = "acx_pci",
4088 .id_table = acxpci_id_tbl,
4089 .probe = acxpci_e_probe,
4090 .remove = __devexit_p(acxpci_e_remove),
4091 #ifdef CONFIG_PM
4092 .suspend = acxpci_e_suspend,
4093 .resume = acxpci_e_resume
4094 #endif /* CONFIG_PM */
4098 /***********************************************************************
4099 ** acxpci_e_init_module
4101 ** Module initialization routine, called once at module load time
4103 int __init acxpci_e_init_module(void)
4105 int res;
4107 FN_ENTER;
4109 #if (ACX_IO_WIDTH==32)
4110 printk("acx: compiled to use 32bit I/O access. "
4111 "I/O timing issues might occur, such as "
4112 "non-working firmware upload. Report them\n");
4113 #else
4114 printk("acx: compiled to use 16bit I/O access only "
4115 "(compatibility mode)\n");
4116 #endif
4118 #ifdef __LITTLE_ENDIAN
4119 #define ENDIANNESS_STRING "running on a little-endian CPU\n"
4120 #else
4121 #define ENDIANNESS_STRING "running on a BIG-ENDIAN CPU\n"
4122 #endif
4123 log(L_INIT,
4124 "acx: " ENDIANNESS_STRING
4125 "acx: PCI module " ACX_RELEASE " initialized, "
4126 "waiting for cards to probe...\n");
4128 res = pci_register_driver(&acxpci_drv_id);
4129 FN_EXIT1(res);
4130 return res;
4134 /***********************************************************************
4135 ** acxpci_e_cleanup_module
4137 ** Called at module unload time. This is our last chance to
4138 ** clean up after ourselves.
4140 void __exit acxpci_e_cleanup_module(void)
4142 FN_ENTER;
4144 pci_unregister_driver(&acxpci_drv_id);
4146 FN_EXIT0;