more coding style fixes
[acx-mac80211.git] / pci.c
blobba99df7290630d7ba5665c3930e1975cd89b0783
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>
8 /* Linux 2.6.18+ uses <linux/utsrelease.h> */
9 #ifndef UTS_RELEASE
10 #include <linux/utsrelease.h>
11 #endif
13 #include <linux/compiler.h> /* required for Lx 2.6.8 ?? */
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/moduleparam.h>
17 #include <linux/sched.h>
18 #include <linux/types.h>
19 #include <linux/skbuff.h>
20 #include <linux/slab.h>
21 #include <linux/if_arp.h>
22 #include <linux/rtnetlink.h>
23 #include <linux/wireless.h>
24 #include <net/iw_handler.h>
25 #include <linux/netdevice.h>
26 #include <linux/ioport.h>
27 #include <linux/pci.h>
28 #include <linux/pm.h>
29 #include <linux/vmalloc.h>
30 #include <linux/ethtool.h>
31 #include <linux/dma-mapping.h>
32 #include <linux/workqueue.h>
33 #ifdef CONFIG_VLYNQ
34 #include <linux/vlynq.h>
35 #endif
37 #include "acx.h"
39 /***********************************************************************
41 #ifdef CONFIG_PCI
42 #define PCI_TYPE (PCI_USES_MEM | PCI_ADDR0 | PCI_NO_ACPI_WAKE)
43 #define PCI_ACX100_REGION1 0x01
44 #define PCI_ACX100_REGION1_SIZE 0x1000 /* Memory size - 4K bytes */
45 #define PCI_ACX100_REGION2 0x02
46 #define PCI_ACX100_REGION2_SIZE 0x10000 /* Memory size - 64K bytes */
48 #define PCI_ACX111_REGION1 0x00
49 #define PCI_ACX111_REGION1_SIZE 0x2000 /* Memory size - 8K bytes */
50 #define PCI_ACX111_REGION2 0x01
51 #define PCI_ACX111_REGION2_SIZE 0x20000 /* Memory size - 128K bytes */
53 /* Texas Instruments Vendor ID */
54 #define PCI_VENDOR_ID_TI 0x104c
56 /* ACX100 22Mb/s WLAN controller */
57 #define PCI_DEVICE_ID_TI_TNETW1100A 0x8400
58 #define PCI_DEVICE_ID_TI_TNETW1100B 0x8401
60 /* ACX111 54Mb/s WLAN controller */
61 #define PCI_DEVICE_ID_TI_TNETW1130 0x9066
63 /* PCI Class & Sub-Class code, Network-'Other controller' */
64 #define PCI_CLASS_NETWORK_OTHERS 0x0280
66 #define CARD_EEPROM_ID_SIZE 6
68 #ifndef PCI_D0
69 /* From include/linux/pci.h */
70 #define PCI_D0 0
71 #define PCI_D1 1
72 #define PCI_D2 2
73 #define PCI_D3hot 3
74 #define PCI_D3cold 4
75 #define PCI_UNKNOWN 5
76 #define PCI_POWER_ERROR -1
77 #endif
78 #endif /* CONFIG_PCI */
80 /***********************************************************************
83 static irqreturn_t acxpci_i_interrupt(int irq, void *dev_id);
85 static void disable_acx_irq(acx_device_t * adev);
87 static int acxpci_e_open(struct ieee80211_hw *hw);
88 static void acxpci_e_close(struct ieee80211_hw *hw);
89 static void acxpci_s_up(struct ieee80211_hw *hw);
90 static void acxpci_s_down(struct ieee80211_hw *hw);
92 void acxpci_put_devname(acx_device_t *adev, struct ethtool_drvinfo *info)
94 strncpy(info->bus_info,pci_name(adev->pdev), ETHTOOL_BUSINFO_LEN);
97 /***********************************************************************
98 ** Register access
103 /* OS I/O routines *always* be endianness-clean but having them doesn't hurt */
104 #define acx_readl(v) le32_to_cpu(readl((v)))
105 #define acx_readw(v) le16_to_cpu(readw((v)))
106 #define acx_writew(v,r) writew(le16_to_cpu((v)), r)
107 #define acx_writel(v,r) writel(le32_to_cpu((v)), r)
109 /* Pick one */
110 /* #define INLINE_IO static */
111 #define INLINE_IO static inline
113 INLINE_IO u32 read_reg32(acx_device_t * adev, unsigned int offset)
115 #if ACX_IO_WIDTH == 32
116 return acx_readl((u8 *) adev->iobase + adev->io[offset]);
117 #else
118 return acx_readw((u8 *) adev->iobase + adev->io[offset])
119 + (acx_readw((u8 *) adev->iobase + adev->io[offset] + 2) << 16);
120 #endif
123 INLINE_IO u16 read_reg16(acx_device_t * adev, unsigned int offset)
125 return acx_readw((u8 *) adev->iobase + adev->io[offset]);
128 INLINE_IO u8 read_reg8(acx_device_t * adev, unsigned int offset)
130 return readb((u8 *) adev->iobase + adev->io[offset]);
133 INLINE_IO void write_reg32(acx_device_t * adev, unsigned int offset, u32 val)
135 #if ACX_IO_WIDTH == 32
136 acx_writel(val, (u8 *) adev->iobase + adev->io[offset]);
137 #else
138 acx_writew(val & 0xffff, (u8 *) adev->iobase + adev->io[offset]);
139 acx_writew(val >> 16, (u8 *) adev->iobase + adev->io[offset] + 2);
140 #endif
143 INLINE_IO void write_reg16(acx_device_t * adev, unsigned int offset, u16 val)
145 acx_writew(val, (u8 *) adev->iobase + adev->io[offset]);
148 INLINE_IO void write_reg8(acx_device_t * adev, unsigned int offset, u8 val)
150 writeb(val, (u8 *) adev->iobase + adev->io[offset]);
153 /* Handle PCI posting properly:
154 * Make sure that writes reach the adapter in case they require to be executed
155 * *before* the next write, by reading a random (and safely accessible) register.
156 * This call has to be made if there is no read following (which would flush the data
157 * to the adapter), yet the written data has to reach the adapter immediately. */
158 INLINE_IO void write_flush(acx_device_t * adev)
160 /* readb(adev->iobase + adev->io[IO_ACX_INFO_MAILBOX_OFFS]); */
161 /* faster version (accesses the first register, IO_ACX_SOFT_RESET,
162 * which should also be safe): */
163 readb(adev->iobase);
166 INLINE_IO int adev_present(acx_device_t * adev)
168 /* fast version (accesses the first register, IO_ACX_SOFT_RESET,
169 * which should be safe): */
170 return acx_readl(adev->iobase) != 0xffffffff;
174 /***********************************************************************
176 static inline txdesc_t *get_txdesc(acx_device_t * adev, int index)
178 return (txdesc_t *) (((u8 *) adev->txdesc_start) +
179 index * adev->txdesc_size);
182 static inline txdesc_t *advance_txdesc(acx_device_t * adev, txdesc_t * txdesc,
183 int inc)
185 return (txdesc_t *) (((u8 *) txdesc) + inc * adev->txdesc_size);
188 static txhostdesc_t *get_txhostdesc(acx_device_t * adev, txdesc_t * txdesc)
190 int index = (u8 *) txdesc - (u8 *) adev->txdesc_start;
192 FN_ENTER;
194 if (unlikely(ACX_DEBUG && (index % adev->txdesc_size))) {
195 printk("bad txdesc ptr %p\n", txdesc);
196 return NULL;
198 index /= adev->txdesc_size;
199 if (unlikely(ACX_DEBUG && (index >= TX_CNT))) {
200 printk("bad txdesc ptr %p\n", txdesc);
201 return NULL;
204 FN_EXIT0;
206 return &adev->txhostdesc_start[index * 2];
213 /***********************************************************************
214 ** EEPROM and PHY read/write helpers
216 /***********************************************************************
217 ** acxpci_read_eeprom_byte
219 ** Function called to read an octet in the EEPROM.
221 ** This function is used by acxpci_e_probe to check if the
222 ** connected card is a legal one or not.
224 ** Arguments:
225 ** adev ptr to acx_device structure
226 ** addr address to read in the EEPROM
227 ** charbuf ptr to a char. This is where the read octet
228 ** will be stored
231 int acxpci_read_eeprom_byte(acx_device_t * adev, u32 addr, u8 * charbuf)
233 int result;
234 int count;
236 FN_ENTER;
238 write_reg32(adev, IO_ACX_EEPROM_CFG, 0);
239 write_reg32(adev, IO_ACX_EEPROM_ADDR, addr);
240 write_flush(adev);
241 write_reg32(adev, IO_ACX_EEPROM_CTL, 2);
243 count = 0xffff;
244 while (read_reg16(adev, IO_ACX_EEPROM_CTL)) {
245 /* scheduling away instead of CPU burning loop
246 * doesn't seem to work here at all:
247 * awful delay, sometimes also failure.
248 * Doesn't matter anyway (only small delay). */
249 if (unlikely(!--count)) {
250 printk("%s: timeout waiting for EEPROM read\n",
251 wiphy_name(adev->ieee->wiphy));
252 result = NOT_OK;
253 goto fail;
255 cpu_relax();
258 *charbuf = read_reg8(adev, IO_ACX_EEPROM_DATA);
259 log(L_DEBUG, "EEPROM at 0x%04X = 0x%02X\n", addr, *charbuf);
260 result = OK;
262 fail:
263 FN_EXIT1(result);
264 return result;
268 /***********************************************************************
269 ** We don't lock hw accesses here since we never r/w eeprom in IRQ
270 ** Note: this function sleeps only because of GFP_KERNEL alloc
272 #ifdef UNUSED
274 acxpci_s_write_eeprom(acx_device_t * adev, u32 addr, u32 len,
275 const u8 * charbuf)
277 u8 *data_verify = NULL;
278 unsigned long flags;
279 int count, i;
280 int result = NOT_OK;
281 u16 gpio_orig;
283 printk("acx: WARNING! I would write to EEPROM now. "
284 "Since I really DON'T want to unless you know "
285 "what you're doing (THIS CODE WILL PROBABLY "
286 "NOT WORK YET!), I will abort that now. And "
287 "definitely make sure to make a "
288 "/proc/driver/acx_wlan0_eeprom backup copy first!!! "
289 "(the EEPROM content includes the PCI config header!! "
290 "If you kill important stuff, then you WILL "
291 "get in trouble and people DID get in trouble already)\n");
292 return OK;
294 FN_ENTER;
296 data_verify = kmalloc(len, GFP_KERNEL);
297 if (!data_verify) {
298 goto end;
301 /* first we need to enable the OE (EEPROM Output Enable) GPIO line
302 * to be able to write to the EEPROM.
303 * NOTE: an EEPROM writing success has been reported,
304 * but you probably have to modify GPIO_OUT, too,
305 * and you probably need to activate a different GPIO
306 * line instead! */
307 gpio_orig = read_reg16(adev, IO_ACX_GPIO_OE);
308 write_reg16(adev, IO_ACX_GPIO_OE, gpio_orig & ~1);
309 write_flush(adev);
311 /* ok, now start writing the data out */
312 for (i = 0; i < len; i++) {
313 write_reg32(adev, IO_ACX_EEPROM_CFG, 0);
314 write_reg32(adev, IO_ACX_EEPROM_ADDR, addr + i);
315 write_reg32(adev, IO_ACX_EEPROM_DATA, *(charbuf + i));
316 write_flush(adev);
317 write_reg32(adev, IO_ACX_EEPROM_CTL, 1);
319 count = 0xffff;
320 while (read_reg16(adev, IO_ACX_EEPROM_CTL)) {
321 if (unlikely(!--count)) {
322 printk("WARNING, DANGER!!! "
323 "Timeout waiting for EEPROM write\n");
324 goto end;
326 cpu_relax();
330 /* disable EEPROM writing */
331 write_reg16(adev, IO_ACX_GPIO_OE, gpio_orig);
332 write_flush(adev);
334 /* now start a verification run */
335 for (i = 0; i < len; i++) {
336 write_reg32(adev, IO_ACX_EEPROM_CFG, 0);
337 write_reg32(adev, IO_ACX_EEPROM_ADDR, addr + i);
338 write_flush(adev);
339 write_reg32(adev, IO_ACX_EEPROM_CTL, 2);
341 count = 0xffff;
342 while (read_reg16(adev, IO_ACX_EEPROM_CTL)) {
343 if (unlikely(!--count)) {
344 printk("timeout waiting for EEPROM read\n");
345 goto end;
347 cpu_relax();
350 data_verify[i] = read_reg16(adev, IO_ACX_EEPROM_DATA);
353 if (0 == memcmp(charbuf, data_verify, len))
354 result = OK; /* read data matches, success */
356 end:
357 kfree(data_verify);
358 FN_EXIT1(result);
359 return result;
361 #endif /* UNUSED */
364 /***********************************************************************
365 ** acxpci_s_read_phy_reg
367 ** Messing with rx/tx disabling and enabling here
368 ** (write_reg32(adev, IO_ACX_ENABLE, 0b000000xx)) kills traffic
370 int acxpci_s_read_phy_reg(acx_device_t * adev, u32 reg, u8 * charbuf)
372 int result = NOT_OK;
373 int count;
375 FN_ENTER;
377 write_reg32(adev, IO_ACX_PHY_ADDR, reg);
378 write_flush(adev);
379 write_reg32(adev, IO_ACX_PHY_CTL, 2);
381 count = 0xffff;
382 while (read_reg32(adev, IO_ACX_PHY_CTL)) {
383 /* scheduling away instead of CPU burning loop
384 * doesn't seem to work here at all:
385 * awful delay, sometimes also failure.
386 * Doesn't matter anyway (only small delay). */
387 if (unlikely(!--count)) {
388 printk("%s: timeout waiting for phy read\n",
389 wiphy_name(adev->ieee->wiphy));
390 *charbuf = 0;
391 goto fail;
393 cpu_relax();
396 log(L_DEBUG, "count was %u\n", count);
397 *charbuf = read_reg8(adev, IO_ACX_PHY_DATA);
399 log(L_DEBUG, "radio PHY at 0x%04X = 0x%02X\n", *charbuf, reg);
400 result = OK;
401 goto fail; /* silence compiler warning */
402 fail:
403 FN_EXIT1(result);
404 return result;
408 /***********************************************************************
410 int acxpci_s_write_phy_reg(acx_device_t * adev, u32 reg, u8 value)
412 FN_ENTER;
414 /* mprusko said that 32bit accesses result in distorted sensitivity
415 * on his card. Unconfirmed, looks like it's not true (most likely since we
416 * now properly flush writes). */
417 write_reg32(adev, IO_ACX_PHY_DATA, value);
418 write_reg32(adev, IO_ACX_PHY_ADDR, reg);
419 write_flush(adev);
420 write_reg32(adev, IO_ACX_PHY_CTL, 1);
421 write_flush(adev);
422 log(L_DEBUG, "radio PHY write 0x%02X at 0x%04X\n", value, reg);
424 FN_EXIT0;
425 return OK;
429 #define NO_AUTO_INCREMENT 1
431 /***********************************************************************
432 ** acxpci_s_write_fw
434 ** Write the firmware image into the card.
436 ** Arguments:
437 ** adev wlan device structure
438 ** fw_image firmware image.
440 ** Returns:
441 ** 1 firmware image corrupted
442 ** 0 success
444 ** Standard csum implementation + write to IO
446 static int
447 acxpci_s_write_fw(acx_device_t * adev, const firmware_image_t *fw_image,
448 u32 offset)
450 int len, size;
451 u32 sum, v32;
452 /* we skip the first four bytes which contain the control sum */
454 const u8 *p = (u8 *) fw_image + 4;
456 FN_ENTER;
458 /* start the image checksum by adding the image size value */
459 sum = p[0] + p[1] + p[2] + p[3];
460 p += 4;
462 write_reg32(adev, IO_ACX_SLV_END_CTL, 0);
464 #if NO_AUTO_INCREMENT
465 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 0); /* use basic mode */
466 #else
467 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 1); /* use autoincrement mode */
468 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset); /* configure start address */
469 write_flush(adev);
470 #endif
472 len = 0;
473 size = le32_to_cpu(fw_image->size) & (~3);
475 while (likely(len < size)) {
476 v32 = be32_to_cpu(*(u32 *) p);
477 sum += p[0] + p[1] + p[2] + p[3];
478 p += 4;
479 len += 4;
481 #if NO_AUTO_INCREMENT
482 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset + len - 4);
483 write_flush(adev);
484 #endif
485 write_reg32(adev, IO_ACX_SLV_MEM_DATA, v32);
488 log(L_DEBUG, "firmware written, size:%d sum1:%x sum2:%x\n",
489 size, sum, le32_to_cpu(fw_image->chksum));
491 /* compare our checksum with the stored image checksum */
492 FN_EXIT1(sum != le32_to_cpu(fw_image->chksum));
493 return (sum != le32_to_cpu(fw_image->chksum));
497 /***********************************************************************
498 ** acxpci_s_validate_fw
500 ** Compare the firmware image given with
501 ** the firmware image written into the card.
503 ** Arguments:
504 ** adev wlan device structure
505 ** fw_image firmware image.
507 ** Returns:
508 ** NOT_OK firmware image corrupted or not correctly written
509 ** OK success
511 ** Origin: Standard csum + Read IO
513 static int
514 acxpci_s_validate_fw(acx_device_t * adev, const firmware_image_t *fw_image,
515 u32 offset)
517 u32 sum, v32, w32;
518 int len, size;
519 int result = OK;
520 /* we skip the first four bytes which contain the control sum */
521 const u8 *p = (u8 *) fw_image + 4;
523 FN_ENTER;
525 /* start the image checksum by adding the image size value */
526 sum = p[0] + p[1] + p[2] + p[3];
527 p += 4;
529 write_reg32(adev, IO_ACX_SLV_END_CTL, 0);
531 #if NO_AUTO_INCREMENT
532 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 0); /* use basic mode */
533 #else
534 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 1); /* use autoincrement mode */
535 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset); /* configure start address */
536 #endif
538 len = 0;
539 size = le32_to_cpu(fw_image->size) & (~3);
541 while (likely(len < size)) {
542 v32 = be32_to_cpu(*(u32 *) p);
543 p += 4;
544 len += 4;
546 #if NO_AUTO_INCREMENT
547 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset + len - 4);
548 #endif
549 w32 = read_reg32(adev, IO_ACX_SLV_MEM_DATA);
551 if (unlikely(w32 != v32)) {
552 printk("acx: FATAL: firmware upload: "
553 "data parts at offset %d don't match (0x%08X vs. 0x%08X)! "
554 "I/O timing issues or defective memory, with DWL-xx0+? "
555 "ACX_IO_WIDTH=16 may help. Please report\n",
556 len, v32, w32);
557 result = NOT_OK;
558 break;
561 sum +=
562 (u8) w32 + (u8) (w32 >> 8) + (u8) (w32 >> 16) +
563 (u8) (w32 >> 24);
566 /* sum control verification */
567 if (result != NOT_OK) {
568 if (sum != le32_to_cpu(fw_image->chksum)) {
569 printk("acx: FATAL: firmware upload: "
570 "checksums don't match!\n");
571 result = NOT_OK;
575 FN_EXIT1(result);
576 return result;
580 /***********************************************************************
581 ** acxpci_s_upload_fw
583 ** Called from acx_reset_dev
585 ** Origin: Derived from FW dissection
587 static int acxpci_s_upload_fw(acx_device_t * adev)
589 firmware_image_t *fw_image = NULL;
590 int res = NOT_OK;
591 int try;
592 u32 file_size;
593 char filename[sizeof("tiacx1NNcNN")];
595 FN_ENTER;
597 /* print exact chipset and radio ID to make sure people
598 * really get a clue on which files exactly they need to provide.
599 * Firmware loading is a frequent end-user PITA with these chipsets.
601 printk( "acx: need firmware for acx1%02d chipset with radio ID %02X\n"
602 "Please provide via firmware hotplug:\n"
603 "either combined firmware (single file named 'tiacx1%02dc%02X')\n"
604 "or two files (base firmware file 'tiacx1%02d' "
605 "+ radio fw 'tiacx1%02dr%02X')\n",
606 IS_ACX111(adev)*11, adev->radio_type,
607 IS_ACX111(adev)*11, adev->radio_type,
608 IS_ACX111(adev)*11,
609 IS_ACX111(adev)*11, adev->radio_type
612 /* print exact chipset and radio ID to make sure people really get a clue on which files exactly they are supposed to provide,
613 * since firmware loading is the biggest enduser PITA with these chipsets.
614 * Not printing radio ID in 0xHEX in order to not confuse them into wrong file naming */
615 printk( "acx: need to load firmware for acx1%02d chipset with radio ID %02x, please provide via firmware hotplug:\n"
616 "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",
617 IS_ACX111(adev)*11, adev->radio_type);
619 /* Try combined, then main image */
620 adev->need_radio_fw = 0;
621 snprintf(filename, sizeof(filename), "tiacx1%02dc%02X",
622 IS_ACX111(adev) * 11, adev->radio_type);
624 fw_image = acx_s_read_fw(adev->bus_dev, filename, &file_size);
625 if (!fw_image) {
626 adev->need_radio_fw = 1;
627 filename[sizeof("tiacx1NN") - 1] = '\0';
628 fw_image =
629 acx_s_read_fw(adev->bus_dev, filename, &file_size);
630 if (!fw_image) {
631 FN_EXIT1(NOT_OK);
632 return NOT_OK;
636 for (try = 1; try <= 5; try++) {
637 res = acxpci_s_write_fw(adev, fw_image, 0);
638 log(L_DEBUG | L_INIT, "acx_write_fw (main/combined): %d\n", res);
639 if (OK == res) {
640 res = acxpci_s_validate_fw(adev, fw_image, 0);
641 log(L_DEBUG | L_INIT, "acx_validate_fw "
642 "(main/combined): %d\n", res);
645 if (OK == res) {
646 SET_BIT(adev->dev_state_mask, ACX_STATE_FW_LOADED);
647 break;
649 printk("acx: firmware upload attempt #%d FAILED, "
650 "retrying...\n", try);
651 acx_s_mwait(1000); /* better wait for a while... */
654 vfree(fw_image);
656 FN_EXIT1(res);
657 return res;
661 /***********************************************************************
662 ** acxpci_s_upload_radio
664 ** Uploads the appropriate radio module firmware into the card.
666 ** Origin: Standard Read/Write to IO
668 int acxpci_s_upload_radio(acx_device_t * adev)
670 acx_ie_memmap_t mm;
671 firmware_image_t *radio_image;
672 acx_cmd_radioinit_t radioinit;
673 int res = NOT_OK;
674 int try;
675 u32 offset;
676 u32 size;
677 char filename[sizeof("tiacx1NNrNN")];
679 if (!adev->need_radio_fw)
680 return OK;
682 FN_ENTER;
684 acx_s_interrogate(adev, &mm, ACX1xx_IE_MEMORY_MAP);
685 offset = le32_to_cpu(mm.CodeEnd);
687 snprintf(filename, sizeof(filename), "tiacx1%02dr%02X",
688 IS_ACX111(adev) * 11, adev->radio_type);
689 radio_image = acx_s_read_fw(adev->bus_dev, filename, &size);
690 if (!radio_image) {
691 printk("acx: can't load radio module '%s'\n", filename);
692 goto fail;
695 acx_s_issue_cmd(adev, ACX1xx_CMD_SLEEP, NULL, 0);
697 for (try = 1; try <= 5; try++) {
698 res = acxpci_s_write_fw(adev, radio_image, offset);
699 log(L_DEBUG | L_INIT, "acx_write_fw (radio): %d\n", res);
700 if (OK == res) {
701 res = acxpci_s_validate_fw(adev, radio_image, offset);
702 log(L_DEBUG | L_INIT, "acx_validate_fw (radio): %d\n",
703 res);
706 if (OK == res)
707 break;
708 printk("acx: radio firmware upload attempt #%d FAILED, "
709 "retrying...\n", try);
710 acx_s_mwait(1000); /* better wait for a while... */
713 acx_s_issue_cmd(adev, ACX1xx_CMD_WAKE, NULL, 0);
714 radioinit.offset = cpu_to_le32(offset);
715 /* no endian conversion needed, remains in card CPU area: */
716 radioinit.len = radio_image->size;
718 vfree(radio_image);
720 if (OK != res)
721 goto fail;
723 /* will take a moment so let's have a big timeout */
724 acx_s_issue_cmd_timeo(adev, ACX1xx_CMD_RADIOINIT,
725 &radioinit, sizeof(radioinit),
726 CMD_TIMEOUT_MS(1000));
728 res = acx_s_interrogate(adev, &mm, ACX1xx_IE_MEMORY_MAP);
729 fail:
730 FN_EXIT1(res);
731 return res;
735 /***********************************************************************
736 ** acxpci_l_reset_mac
738 ** MAC will be reset
739 ** Call context: reset_dev
741 ** Origin: Standard Read/Write to IO
743 static void acxpci_l_reset_mac(acx_device_t * adev)
745 u16 temp;
747 FN_ENTER;
749 /* halt eCPU */
750 temp = read_reg16(adev, IO_ACX_ECPU_CTRL) | 0x1;
751 write_reg16(adev, IO_ACX_ECPU_CTRL, temp);
753 /* now do soft reset of eCPU, set bit */
754 temp = read_reg16(adev, IO_ACX_SOFT_RESET) | 0x1;
755 log(L_DEBUG, "enable soft reset\n");
756 write_reg16(adev, IO_ACX_SOFT_RESET, temp);
757 write_flush(adev);
759 /* now clear bit again: deassert eCPU reset */
760 log(L_DEBUG, "disable soft reset and go to init mode");
761 write_reg16(adev, IO_ACX_SOFT_RESET, temp & ~0x1);
763 /* now start a burst read from initial EEPROM */
764 temp = read_reg16(adev, IO_ACX_EE_START) | 0x1;
765 write_reg16(adev, IO_ACX_EE_START, temp);
766 write_flush(adev);
768 FN_EXIT0;
772 /***********************************************************************
773 ** acxpci_s_verify_init
775 static int acxpci_s_verify_init(acx_device_t * adev)
777 int result = NOT_OK;
778 unsigned long timeout;
780 FN_ENTER;
782 timeout = jiffies + 2 * HZ;
783 for (;;) {
784 u16 irqstat = read_reg16(adev, IO_ACX_IRQ_STATUS_NON_DES);
785 if (irqstat & HOST_INT_FCS_THRESHOLD) {
786 result = OK;
787 write_reg16(adev, IO_ACX_IRQ_ACK,
788 HOST_INT_FCS_THRESHOLD);
789 break;
791 if (time_after(jiffies, timeout))
792 break;
793 /* Init may take up to ~0.5 sec total */
794 acx_s_mwait(50);
797 FN_EXIT1(result);
798 return result;
802 /***********************************************************************
803 ** A few low-level helpers
805 ** Note: these functions are not protected by lock
806 ** and thus are never allowed to be called from IRQ.
807 ** Also they must not race with fw upload which uses same hw regs
810 /***********************************************************************
811 ** acxpci_write_cmd_type_status
813 ** Origin: Common linux implementation
816 static inline void
817 acxpci_write_cmd_type_status(acx_device_t * adev, u16 type, u16 status)
819 FN_ENTER;
820 acx_writel(type | (status << 16), adev->cmd_area);
821 write_flush(adev);
822 FN_EXIT0;
826 /***********************************************************************
827 ** acxpci_read_cmd_type_status
829 ** Origin: Common linux implementation
831 static u32 acxpci_read_cmd_type_status(acx_device_t * adev)
833 u32 cmd_type, cmd_status;
835 FN_ENTER;
837 cmd_type = acx_readl(adev->cmd_area);
838 cmd_status = (cmd_type >> 16);
839 cmd_type = (u16) cmd_type;
841 log(L_CTL, "cmd_type:%04X cmd_status:%04X [%s]\n",
842 cmd_type, cmd_status, acx_cmd_status_str(cmd_status));
844 FN_EXIT1(cmd_status);
845 return cmd_status;
849 /***********************************************************************
850 ** acxpci_s_reset_dev
852 ** Arguments:
853 ** netdevice that contains the adev variable
854 ** Returns:
855 ** NOT_OK on fail
856 ** OK on success
857 ** Side effects:
858 ** device is hard reset
859 ** Call context:
860 ** acxpci_e_probe
861 ** Comment:
862 ** This resets the device using low level hardware calls
863 ** as well as uploads and verifies the firmware to the card
866 static inline void init_mboxes(acx_device_t * adev)
868 u32 cmd_offs, info_offs;
870 FN_ENTER;
872 cmd_offs = read_reg32(adev, IO_ACX_CMD_MAILBOX_OFFS);
873 info_offs = read_reg32(adev, IO_ACX_INFO_MAILBOX_OFFS);
874 adev->cmd_area = (u8 *) adev->iobase2 + cmd_offs;
875 adev->info_area = (u8 *) adev->iobase2 + info_offs;
876 log(L_DEBUG, "iobase2=%p\n"
877 "cmd_mbox_offset=%X cmd_area=%p\n"
878 "info_mbox_offset=%X info_area=%p\n",
879 adev->iobase2,
880 cmd_offs, adev->cmd_area, info_offs, adev->info_area);
881 FN_EXIT0;
885 static inline void read_eeprom_area(acx_device_t * adev)
887 #if ACX_DEBUG > 1
888 int offs;
889 u8 tmp;
891 FN_ENTER;
893 for (offs = 0x8c; offs < 0xb9; offs++)
894 acxpci_read_eeprom_byte(adev, offs, &tmp);
896 FN_EXIT0;
897 #endif
901 int acxpci_s_reset_dev(acx_device_t * adev)
903 const char *msg = "";
904 unsigned long flags;
905 int result = NOT_OK;
906 u16 hardware_info;
907 u16 ecpu_ctrl;
908 int count;
910 FN_ENTER;
912 /* reset the device to make sure the eCPU is stopped
913 * to upload the firmware correctly */
915 acx_lock(adev, flags);
917 #ifdef CONFIG_PCI
918 acxpci_l_reset_mac(adev);
919 #endif
921 ecpu_ctrl = read_reg16(adev, IO_ACX_ECPU_CTRL) & 1;
922 if (!ecpu_ctrl) {
923 msg = "eCPU is already running. ";
924 goto end_unlock;
926 #if 0
927 if (read_reg16(adev, IO_ACX_SOR_CFG) & 2) {
928 /* eCPU most likely means "embedded CPU" */
929 msg = "eCPU did not start after boot from flash. ";
930 goto end_unlock;
933 /* check sense on reset flags */
934 if (read_reg16(adev, IO_ACX_SOR_CFG) & 0x10) {
935 printk("%s: eCPU did not start after boot (SOR), "
936 "is this fatal?\n", wiphy_name(adev->ieee->wiphy));
938 #endif
939 /* scan, if any, is stopped now, setting corresponding IRQ bit */
940 SET_BIT(adev->irq_status, HOST_INT_SCAN_COMPLETE);
942 acx_unlock(adev, flags);
944 /* need to know radio type before fw load */
945 /* Need to wait for arrival of this information in a loop,
946 * most probably since eCPU runs some init code from EEPROM
947 * (started burst read in reset_mac()) which also
948 * sets the radio type ID */
950 count = 0xffff;
951 do {
952 hardware_info = read_reg16(adev, IO_ACX_EEPROM_INFORMATION);
953 if (!--count) {
954 msg = "eCPU didn't indicate radio type";
955 goto end_fail;
957 cpu_relax();
958 } while (!(hardware_info & 0xff00)); /* radio type still zero? */
960 /* printk("DEBUG: count %d\n", count); */
961 adev->form_factor = hardware_info & 0xff;
962 adev->radio_type = hardware_info >> 8;
964 /* load the firmware */
965 if (OK != acxpci_s_upload_fw(adev))
966 goto end_fail;
968 /* acx_s_mwait(10); this one really shouldn't be required */
970 /* now start eCPU by clearing bit */
971 write_reg16(adev, IO_ACX_ECPU_CTRL, ecpu_ctrl & ~0x1);
972 log(L_DEBUG, "booted eCPU up and waiting for completion...\n");
974 /* wait for eCPU bootup */
975 if (OK != acxpci_s_verify_init(adev)) {
976 msg = "timeout waiting for eCPU. ";
977 goto end_fail;
979 log(L_DEBUG, "eCPU has woken up, card is ready to be configured\n");
981 init_mboxes(adev);
982 acxpci_write_cmd_type_status(adev, 0, 0);
984 /* test that EEPROM is readable */
985 read_eeprom_area(adev);
987 result = OK;
988 goto end;
990 /* Finish error message. Indicate which function failed */
991 end_unlock:
992 acx_unlock(adev, flags);
993 end_fail:
994 printk("acx: %sreset_dev() FAILED\n", msg);
995 end:
996 FN_EXIT1(result);
997 return result;
1001 /***********************************************************************
1002 ** acxpci_s_issue_cmd_timeo
1004 ** Sends command to fw, extract result
1006 ** NB: we do _not_ take lock inside, so be sure to not touch anything
1007 ** which may interfere with IRQ handler operation
1009 ** TODO: busy wait is a bit silly, so:
1010 ** 1) stop doing many iters - go to sleep after first
1011 ** 2) go to waitqueue based approach: wait, not poll!
1013 #undef FUNC
1014 #define FUNC "issue_cmd"
1016 #if !ACX_DEBUG
1018 acxpci_s_issue_cmd_timeo(acx_device_t * adev,
1019 unsigned int cmd,
1020 void *buffer, unsigned buflen, unsigned cmd_timeout)
1022 #else
1024 acxpci_s_issue_cmd_timeo_debug(acx_device_t * adev,
1025 unsigned cmd,
1026 void *buffer,
1027 unsigned buflen,
1028 unsigned cmd_timeout, const char *cmdstr)
1030 unsigned long start = jiffies;
1031 #endif
1032 const char *devname;
1033 unsigned counter;
1034 u16 irqtype;
1035 u16 cmd_status;
1036 unsigned long timeout;
1038 FN_ENTER;
1040 devname = wiphy_name(adev->ieee->wiphy);
1041 if (!devname || !devname[0] || devname[4] == '%')
1042 devname = "acx";
1044 log(L_CTL, FUNC "(cmd:%s,buflen:%u,timeout:%ums,type:0x%04X)\n",
1045 cmdstr, buflen, cmd_timeout,
1046 buffer ? le16_to_cpu(((acx_ie_generic_t *) buffer)->type) : -1);
1048 if (!(adev->dev_state_mask & ACX_STATE_FW_LOADED)) {
1049 printk("%s: " FUNC "(): firmware is not loaded yet, "
1050 "cannot execute commands!\n", devname);
1051 goto bad;
1054 if ((acx_debug & L_DEBUG) && (cmd != ACX1xx_CMD_INTERROGATE)) {
1055 printk("input buffer (len=%u):\n", buflen);
1056 acx_dump_bytes(buffer, buflen);
1059 /* wait for firmware to become idle for our command submission */
1060 timeout = HZ / 5;
1061 counter = (timeout * 1000 / HZ) - 1; /* in ms */
1062 timeout += jiffies;
1063 do {
1064 cmd_status = acxpci_read_cmd_type_status(adev);
1065 /* Test for IDLE state */
1066 if (!cmd_status)
1067 break;
1068 if (counter % 8 == 0) {
1069 if (time_after(jiffies, timeout)) {
1070 counter = 0;
1071 break;
1073 /* we waited 8 iterations, no luck. Sleep 8 ms */
1074 acx_s_mwait(8);
1076 } while (likely(--counter));
1078 if (!counter) {
1079 /* the card doesn't get idle, we're in trouble */
1080 printk("%s: " FUNC "(): cmd_status is not IDLE: 0x%04X!=0\n",
1081 devname, cmd_status);
1082 goto bad;
1083 } else if (counter < 190) { /* if waited >10ms... */
1084 log(L_CTL | L_DEBUG, FUNC "(): waited for IDLE %dms. "
1085 "Please report\n", 199 - counter);
1088 /* now write the parameters of the command if needed */
1089 if (buffer && buflen) {
1090 /* if it's an INTERROGATE command, just pass the length
1091 * of parameters to read, as data */
1092 #if CMD_DISCOVERY
1093 if (cmd == ACX1xx_CMD_INTERROGATE)
1094 memset_io(adev->cmd_area + 4, 0xAA, buflen);
1095 #endif
1096 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1097 memcpy_toio(adev->cmd_area + 4, buffer,
1098 (cmd == ACX1xx_CMD_INTERROGATE) ? 4 : buflen);
1100 /* now write the actual command type */
1101 acxpci_write_cmd_type_status(adev, cmd, 0);
1102 /* execute command */
1103 write_reg16(adev, IO_ACX_INT_TRIG, INT_TRIG_CMD);
1104 write_flush(adev);
1106 /* wait for firmware to process command */
1108 /* Ensure nonzero and not too large timeout.
1109 ** Also converts e.g. 100->99, 200->199
1110 ** which is nice but not essential */
1111 cmd_timeout = (cmd_timeout - 1) | 1;
1112 if (unlikely(cmd_timeout > 1199))
1113 cmd_timeout = 1199;
1114 /* clear CMD_COMPLETE bit. can be set only by IRQ handler: */
1115 CLEAR_BIT(adev->irq_status, HOST_INT_CMD_COMPLETE);
1116 /* we schedule away sometimes (timeout can be large) */
1117 counter = cmd_timeout;
1118 timeout = jiffies + HZ;
1119 do {
1120 if (!adev->irqs_active) { /* IRQ disabled: poll */
1121 irqtype = read_reg16(adev, IO_ACX_IRQ_STATUS_NON_DES);
1122 if (irqtype & HOST_INT_CMD_COMPLETE) {
1123 write_reg16(adev, IO_ACX_IRQ_ACK,
1124 HOST_INT_CMD_COMPLETE);
1125 break;
1127 } else { /* Wait when IRQ will set the bit */
1128 irqtype = adev->irq_status;
1129 if (irqtype & HOST_INT_CMD_COMPLETE)
1130 break;
1133 if (counter % 8 == 0) {
1134 if (time_after(jiffies, timeout)) {
1135 counter = 0;
1136 break;
1138 /* we waited 8 iterations, no luck. Sleep 8 ms */
1139 acx_s_mwait(8);
1141 } while (likely(--counter));
1143 /* save state for debugging */
1144 cmd_status = acxpci_read_cmd_type_status(adev);
1146 /* put the card in IDLE state */
1147 acxpci_write_cmd_type_status(adev, 0, 0);
1149 if ((cmd_timeout - counter) == 0) { /* timed out! */
1150 printk("%s: " FUNC "(): timed out %s for CMD_COMPLETE. "
1151 "irq bits:0x%04X irq_status:0x%04X timeout:%dms "
1152 "cmd_status:%d (%s)\n",
1153 devname, (adev->irqs_active) ? "waiting" : "polling",
1154 irqtype, adev->irq_status, cmd_timeout,
1155 cmd_status, acx_cmd_status_str(cmd_status));
1156 printk("hack: don't do: 'goto bad;'\ncounter: %d cmd_timeout: %d cmd_timeout-counter: %d\n",counter, cmd_timeout, cmd_timeout - counter);
1157 } else if (counter == 0) { /* maybe timed out! */
1158 log(L_CTL | L_DEBUG, FUNC "(): %s for CMD_COMPLETE %dms. "
1159 "count:%d. Please report\n",
1160 (adev->irqs_active) ? "waited" : "polled",
1161 cmd_timeout - counter, counter);
1162 } else if ((cmd_timeout - counter) > 30) { /* if waited >30ms... */
1163 log(L_CTL | L_DEBUG, FUNC "(): %s for CMD_COMPLETE %dms. "
1164 "count:%d. Please report\n",
1165 (adev->irqs_active) ? "waited" : "polled",
1166 cmd_timeout - counter, counter);
1169 if (1 != cmd_status) { /* it is not a 'Success' */
1170 printk("%s: " FUNC "(): cmd_status is not SUCCESS: %d (%s). "
1171 "Took %dms of %d\n",
1172 devname, cmd_status, acx_cmd_status_str(cmd_status),
1173 cmd_timeout - counter, cmd_timeout);
1174 /* zero out result buffer
1175 * WARNING: this will trash stack in case of illegally large input
1176 * length! */
1177 if (buffer && buflen)
1178 memset(buffer, 0, buflen);
1179 goto bad;
1182 /* read in result parameters if needed */
1183 if (buffer && buflen && (cmd == ACX1xx_CMD_INTERROGATE)) {
1184 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1185 memcpy_fromio(buffer, adev->cmd_area + 4, buflen);
1186 if (acx_debug & L_DEBUG) {
1187 printk("output buffer (len=%u): ", buflen);
1188 acx_dump_bytes(buffer, buflen);
1191 /* ok: */
1192 log(L_CTL, FUNC "(%s): took %ld jiffies to complete\n",
1193 cmdstr, jiffies - start);
1194 FN_EXIT1(OK);
1195 return OK;
1197 bad:
1198 /* Give enough info so that callers can avoid
1199 ** printing their own diagnostic messages */
1200 #if ACX_DEBUG
1201 printk("%s: " FUNC "(cmd:%s) FAILED\n", devname, cmdstr);
1202 #else
1203 printk("%s: " FUNC "(cmd:0x%04X) FAILED\n", devname, cmd);
1204 #endif
1205 dump_stack();
1206 FN_EXIT1(NOT_OK);
1207 return NOT_OK;
1211 /***********************************************************************
1213 #ifdef NONESSENTIAL_FEATURES
1214 typedef struct device_id {
1215 unsigned char id[6];
1216 char *descr;
1217 char *type;
1218 } device_id_t;
1220 static const device_id_t device_ids[] = {
1222 {'G', 'l', 'o', 'b', 'a', 'l'},
1223 NULL,
1224 NULL,
1227 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
1228 "uninitialized",
1229 "SpeedStream SS1021 or Gigafast WF721-AEX"},
1231 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85},
1232 "non-standard",
1233 "DrayTek Vigor 520"},
1235 {'?', '?', '?', '?', '?', '?'},
1236 "non-standard",
1237 "Level One WPC-0200"},
1239 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1240 "empty",
1241 "DWL-650+ variant"}
1244 static void acx_show_card_eeprom_id(acx_device_t * adev)
1246 unsigned char buffer[CARD_EEPROM_ID_SIZE];
1247 int i;
1249 FN_ENTER;
1251 memset(&buffer, 0, CARD_EEPROM_ID_SIZE);
1252 /* use direct EEPROM access */
1253 for (i = 0; i < CARD_EEPROM_ID_SIZE; i++) {
1254 if (OK != acxpci_read_eeprom_byte(adev,
1255 ACX100_EEPROM_ID_OFFSET + i,
1256 &buffer[i])) {
1257 printk("acx: reading EEPROM FAILED\n");
1258 break;
1262 for (i = 0; i < ARRAY_SIZE(device_ids); i++) {
1263 if (!memcmp(&buffer, device_ids[i].id, CARD_EEPROM_ID_SIZE)) {
1264 if (device_ids[i].descr) {
1265 printk("acx: EEPROM card ID string check "
1266 "found %s card ID: is this %s?\n",
1267 device_ids[i].descr, device_ids[i].type);
1269 break;
1272 if (i == ARRAY_SIZE(device_ids)) {
1273 printk("acx: EEPROM card ID string check found "
1274 "unknown card: expected 'Global', got '%.*s\'. "
1275 "Please report\n", CARD_EEPROM_ID_SIZE, buffer);
1277 FN_EXIT0;
1279 #endif /* NONESSENTIAL_FEATURES */
1282 /***********************************************************************
1283 ** acxpci_free_desc_queues
1285 ** Releases the queues that have been allocated, the
1286 ** others have been initialised to NULL so this
1287 ** function can be used if only part of the queues were allocated.
1290 static inline void
1291 free_coherent(struct pci_dev *hwdev, size_t size,
1292 void *vaddr, dma_addr_t dma_handle)
1294 dma_free_coherent(hwdev == NULL ? NULL : &hwdev->dev,
1295 size, vaddr, dma_handle);
1299 void acxpci_free_desc_queues(acx_device_t * adev)
1301 unsigned long flags;
1303 #define ACX_FREE_QUEUE(size, ptr, phyaddr) \
1304 if (ptr) { \
1305 free_coherent(NULL, size, ptr, phyaddr); \
1306 ptr = NULL; \
1307 size = 0; \
1310 FN_ENTER;
1312 ACX_FREE_QUEUE(adev->txhostdesc_area_size, adev->txhostdesc_start,
1313 adev->txhostdesc_startphy);
1314 ACX_FREE_QUEUE(adev->txbuf_area_size, adev->txbuf_start,
1315 adev->txbuf_startphy);
1317 acx_lock(adev, flags);
1318 adev->txdesc_start = NULL;
1319 acx_unlock(adev, flags);
1321 ACX_FREE_QUEUE(adev->rxhostdesc_area_size, adev->rxhostdesc_start,
1322 adev->rxhostdesc_startphy);
1323 ACX_FREE_QUEUE(adev->rxbuf_area_size, adev->rxbuf_start,
1324 adev->rxbuf_startphy);
1326 acx_lock(adev, flags);
1327 adev->rxdesc_start = NULL;
1328 acx_unlock(adev, flags);
1330 FN_EXIT0;
1334 /***********************************************************************
1335 ** acxpci_s_delete_dma_regions
1337 static void acxpci_s_delete_dma_regions(acx_device_t * adev)
1339 FN_ENTER;
1340 /* disable radio Tx/Rx. Shouldn't we use the firmware commands
1341 * here instead? Or are we that much down the road that it's no
1342 * longer possible here? */
1343 write_reg16(adev, IO_ACX_ENABLE, 0);
1345 acx_s_mwait(100);
1347 /* NO locking for all parts of acxpci_free_desc_queues because:
1348 * while calling dma_free_coherent() interrupts need to be 'free'
1349 * but if you spinlock the whole function (acxpci_free_desc_queues)
1350 * you'll get an error */
1351 acxpci_free_desc_queues(adev);
1353 FN_EXIT0;
1357 /***********************************************************************
1358 ** acxpci_e_probe
1360 ** Probe routine called when a PCI device w/ matching ID is found.
1361 ** Here's the sequence:
1362 ** - Allocate the PCI resources.
1363 ** - Read the PCMCIA attribute memory to make sure we have a WLAN card
1364 ** - Reset the MAC
1365 ** - Initialize the dev and wlan data
1366 ** - Initialize the MAC
1368 ** pdev - ptr to pci device structure containing info about pci configuration
1369 ** id - ptr to the device id entry that matched this device
1371 static const u16 IO_ACX100[] = {
1372 0x0000, /* IO_ACX_SOFT_RESET */
1374 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1375 0x0018, /* IO_ACX_SLV_MEM_DATA */
1376 0x001c, /* IO_ACX_SLV_MEM_CTL */
1377 0x0020, /* IO_ACX_SLV_END_CTL */
1379 0x0034, /* IO_ACX_FEMR */
1381 0x007c, /* IO_ACX_INT_TRIG */
1382 0x0098, /* IO_ACX_IRQ_MASK */
1383 0x00a4, /* IO_ACX_IRQ_STATUS_NON_DES */
1384 0x00a8, /* IO_ACX_IRQ_STATUS_CLEAR */
1385 0x00ac, /* IO_ACX_IRQ_ACK */
1386 0x00b0, /* IO_ACX_HINT_TRIG */
1388 0x0104, /* IO_ACX_ENABLE */
1390 0x0250, /* IO_ACX_EEPROM_CTL */
1391 0x0254, /* IO_ACX_EEPROM_ADDR */
1392 0x0258, /* IO_ACX_EEPROM_DATA */
1393 0x025c, /* IO_ACX_EEPROM_CFG */
1395 0x0268, /* IO_ACX_PHY_ADDR */
1396 0x026c, /* IO_ACX_PHY_DATA */
1397 0x0270, /* IO_ACX_PHY_CTL */
1399 0x0290, /* IO_ACX_GPIO_OE */
1401 0x0298, /* IO_ACX_GPIO_OUT */
1403 0x02a4, /* IO_ACX_CMD_MAILBOX_OFFS */
1404 0x02a8, /* IO_ACX_INFO_MAILBOX_OFFS */
1405 0x02ac, /* IO_ACX_EEPROM_INFORMATION */
1407 0x02d0, /* IO_ACX_EE_START */
1408 0x02d4, /* IO_ACX_SOR_CFG */
1409 0x02d8 /* IO_ACX_ECPU_CTRL */
1412 static const u16 IO_ACX111[] = {
1413 0x0000, /* IO_ACX_SOFT_RESET */
1415 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1416 0x0018, /* IO_ACX_SLV_MEM_DATA */
1417 0x001c, /* IO_ACX_SLV_MEM_CTL */
1418 0x0020, /* IO_ACX_SLV_END_CTL */
1420 0x0034, /* IO_ACX_FEMR */
1422 0x00b4, /* IO_ACX_INT_TRIG */
1423 0x00d4, /* IO_ACX_IRQ_MASK */
1424 /* we do mean NON_DES (0xf0), not NON_DES_MASK which is at 0xe0: */
1425 0x00f0, /* IO_ACX_IRQ_STATUS_NON_DES */
1426 0x00e4, /* IO_ACX_IRQ_STATUS_CLEAR */
1427 0x00e8, /* IO_ACX_IRQ_ACK */
1428 0x00ec, /* IO_ACX_HINT_TRIG */
1430 0x01d0, /* IO_ACX_ENABLE */
1432 0x0338, /* IO_ACX_EEPROM_CTL */
1433 0x033c, /* IO_ACX_EEPROM_ADDR */
1434 0x0340, /* IO_ACX_EEPROM_DATA */
1435 0x0344, /* IO_ACX_EEPROM_CFG */
1437 0x0350, /* IO_ACX_PHY_ADDR */
1438 0x0354, /* IO_ACX_PHY_DATA */
1439 0x0358, /* IO_ACX_PHY_CTL */
1441 0x0374, /* IO_ACX_GPIO_OE */
1443 0x037c, /* IO_ACX_GPIO_OUT */
1445 0x0388, /* IO_ACX_CMD_MAILBOX_OFFS */
1446 0x038c, /* IO_ACX_INFO_MAILBOX_OFFS */
1447 0x0390, /* IO_ACX_EEPROM_INFORMATION */
1449 0x0100, /* IO_ACX_EE_START */
1450 0x0104, /* IO_ACX_SOR_CFG */
1451 0x0108, /* IO_ACX_ECPU_CTRL */
1454 static const struct ieee80211_ops acxpci_hw_ops = {
1455 .tx = acx_i_start_xmit,
1456 .conf_tx = acx_net_conf_tx,
1457 .add_interface = acx_add_interface,
1458 .remove_interface = acx_remove_interface,
1459 .start = acxpci_e_open,
1460 .configure_filter = acx_i_set_multicast_list,
1461 .stop = acxpci_e_close,
1462 .config = acx_net_config,
1463 .config_interface = acx_config_interface,
1464 .set_key = acx_net_set_key,
1465 .get_stats = acx_e_get_stats,
1466 .get_tx_stats = acx_net_get_tx_stats,
1470 #ifdef CONFIG_PCI
1471 static int __devinit
1472 acxpci_e_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1474 acx111_ie_configoption_t co;
1475 unsigned long mem_region1 = 0;
1476 unsigned long mem_region2 = 0;
1477 unsigned long mem_region1_size;
1478 unsigned long mem_region2_size;
1479 unsigned long phymem1;
1480 unsigned long phymem2;
1481 void *mem1 = NULL;
1482 void *mem2 = NULL;
1483 acx_device_t *adev = NULL;
1484 const char *chip_name;
1485 int result = -EIO;
1486 int err;
1487 u8 chip_type;
1488 struct ieee80211_hw *ieee;
1490 FN_ENTER;
1492 ieee = ieee80211_alloc_hw(sizeof(struct acx_device), &acxpci_hw_ops);
1493 if (!ieee) {
1494 printk("acx: could not allocate ieee80211 structure %s\n",
1495 pci_name(pdev));
1496 goto fail_alloc_netdev;
1498 ieee->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
1499 /* TODO: mainline doesn't support the following flags yet */
1501 ~IEEE80211_HW_MONITOR_DURING_OPER &
1502 ~IEEE80211_HW_WEP_INCLUDE_IV;
1504 ieee->queues = 1;
1506 /* (NB: memsets to 0 entire area) */
1507 if (!ieee) {
1508 printk("acx: could not allocate ieee structure %s\n",
1509 pci_name(pdev));
1510 goto fail_alloc_netdev;
1513 adev = ieee2adev(ieee);
1515 memset(adev, 0, sizeof(*adev));
1516 /** Set up our private interface **/
1517 spin_lock_init(&adev->spinlock); /* initial state: unlocked */
1518 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
1519 printk("mutex_init(&adev->mutex); // adev = 0x%px\n", adev);
1520 mutex_init(&adev->mutex);
1521 /* since nobody can see new netdev yet, we can as well
1522 ** just _presume_ that we're under sem (instead of actually taking it): */
1523 /* acx_sem_lock(adev); */
1524 adev->ieee = ieee;
1525 adev->pdev = pdev;
1526 adev->bus_dev = &pdev->dev;
1527 adev->dev_type = DEVTYPE_PCI;
1529 /** Finished with private interface **/
1531 /** begin board specific inits **/
1532 pci_set_drvdata(pdev, ieee);
1534 /* Enable the PCI device */
1535 if (pci_enable_device(pdev)) {
1536 printk("acx: pci_enable_device() FAILED\n");
1537 result = -ENODEV;
1538 goto fail_pci_enable_device;
1541 /* enable busmastering (required for CardBus) */
1542 pci_set_master(pdev);
1545 /* chiptype is u8 but id->driver_data is ulong
1546 ** Works for now (possible values are 1 and 2) */
1547 chip_type = (u8) id->driver_data;
1548 /* acx100 and acx111 have different PCI memory regions */
1549 if (chip_type == CHIPTYPE_ACX100) {
1550 chip_name = "ACX100";
1551 mem_region1 = PCI_ACX100_REGION1;
1552 mem_region1_size = PCI_ACX100_REGION1_SIZE;
1554 mem_region2 = PCI_ACX100_REGION2;
1555 mem_region2_size = PCI_ACX100_REGION2_SIZE;
1556 } else if (chip_type == CHIPTYPE_ACX111) {
1557 chip_name = "ACX111";
1558 mem_region1 = PCI_ACX111_REGION1;
1559 mem_region1_size = PCI_ACX111_REGION1_SIZE;
1561 mem_region2 = PCI_ACX111_REGION2;
1562 mem_region2_size = PCI_ACX111_REGION2_SIZE;
1563 } else {
1564 printk("acx: unknown chip type 0x%04X\n", chip_type);
1565 goto fail_unknown_chiptype;
1568 /* Figure out our resources */
1569 phymem1 = pci_resource_start(pdev, mem_region1);
1570 phymem2 = pci_resource_start(pdev, mem_region2);
1571 if (!request_mem_region
1572 (phymem1, pci_resource_len(pdev, mem_region1), "acx_1")) {
1573 printk("acx: cannot reserve PCI memory region 1 (are you sure "
1574 "you have CardBus support in kernel?)\n");
1575 goto fail_request_mem_region1;
1577 if (!request_mem_region
1578 (phymem2, pci_resource_len(pdev, mem_region2), "acx_2")) {
1579 printk("acx: cannot reserve PCI memory region 2\n");
1580 goto fail_request_mem_region2;
1582 /* this used to be ioremap(), but ioremap_nocache()
1583 * is much less risky, right? (and slower?)
1584 * FIXME: we may want to go back to cached variant if it's
1585 * certain that our code really properly handles
1586 * cached operation (memory barriers, volatile?, ...)
1587 * (but always keep this comment here regardless!)
1588 * Possibly make this a driver config setting?
1591 mem1 = ioremap_nocache(phymem1, mem_region1_size);
1592 if (!mem1) {
1593 printk("acx: ioremap() FAILED\n");
1594 goto fail_ioremap1;
1596 mem2 = ioremap_nocache(phymem2, mem_region2_size);
1597 if (!mem2) {
1598 printk("acx: ioremap() #2 FAILED\n");
1599 goto fail_ioremap2;
1602 printk("acx: found %s-based wireless network card at %s, irq:%d, "
1603 "phymem1:0x%lX, phymem2:0x%lX, mem1:0x%p, mem1_size:%ld, "
1604 "mem2:0x%p, mem2_size:%ld\n",
1605 chip_name, pci_name(pdev), pdev->irq, phymem1, phymem2,
1606 mem1, mem_region1_size, mem2, mem_region2_size);
1607 log(L_ANY, "initial debug setting is 0x%04X\n", acx_debug);
1608 adev->chip_type = chip_type;
1609 adev->chip_name = chip_name;
1610 adev->io = (CHIPTYPE_ACX100 == chip_type) ? IO_ACX100 : IO_ACX111;
1611 adev->membase = phymem1;
1612 adev->iobase = mem1;
1613 adev->membase2 = phymem2;
1614 adev->iobase2 = mem2;
1615 adev->irq = pdev->irq;
1618 if (0 == pdev->irq) {
1619 printk("acx: can't use IRQ 0\n");
1620 goto fail_irq;
1622 SET_IEEE80211_DEV(ieee, &pdev->dev);
1625 /* to find crashes due to weird driver access
1626 * to unconfigured interface (ifup) */
1627 adev->mgmt_timer.function = (void (*)(unsigned long))0x0000dead;
1630 #ifdef NONESSENTIAL_FEATURES
1631 acx_show_card_eeprom_id(adev);
1632 #endif /* NONESSENTIAL_FEATURES */
1635 /* ok, pci setup is finished, now start initializing the card */
1637 /* NB: read_reg() reads may return bogus data before reset_dev(),
1638 * since the firmware which directly controls large parts of the I/O
1639 * registers isn't initialized yet.
1640 * acx100 seems to be more affected than acx111 */
1641 if (OK != acxpci_s_reset_dev(adev))
1642 goto fail_reset;
1644 if (IS_ACX100(adev)) {
1645 /* ACX100: configopt struct in cmd mailbox - directly after reset */
1646 memcpy_fromio(&co, adev->cmd_area, sizeof(co));
1649 if (OK != acx_s_init_mac(adev))
1650 goto fail_init_mac;
1652 if (IS_ACX111(adev)) {
1653 /* ACX111: configopt struct needs to be queried after full init */
1654 acx_s_interrogate(adev, &co, ACX111_IE_CONFIG_OPTIONS);
1656 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
1657 if (OK != acxpci_read_eeprom_byte(adev, 0x05, &adev->eeprom_version))
1658 goto fail_read_eeprom_version;
1660 acx_s_parse_configoption(adev, &co);
1661 acx_s_set_defaults(adev);
1662 acx_s_get_firmware_version(adev); /* needs to be after acx_s_init_mac() */
1663 acx_display_hardware_details(adev);
1665 /* Register the card, AFTER everything else has been set up,
1666 * since otherwise an ioctl could step on our feet due to
1667 * firmware operations happening in parallel or uninitialized data */
1670 acx_proc_register_entries(ieee);
1672 /* Now we have our device, so make sure the kernel doesn't try
1673 * to send packets even though we're not associated to a network yet */
1675 /* after register_netdev() userspace may start working with dev
1676 * (in particular, on other CPUs), we only need to up the sem */
1677 /* acx_sem_unlock(adev); */
1679 printk("acx " ACX_RELEASE ": net device %s, driver compiled "
1680 "against wireless extensions %d and Linux %s\n",
1681 wiphy_name(adev->ieee->wiphy), WIRELESS_EXT, UTS_RELEASE);
1683 MAC_COPY(adev->ieee->wiphy->perm_addr, adev->dev_addr);
1685 log(L_IRQ | L_INIT, "using IRQ %d\n", pdev->irq);
1687 /** done with board specific setup **/
1689 /* need to be able to restore PCI state after a suspend */
1690 #ifdef CONFIG_PM
1691 pci_save_state(pdev);
1692 #endif
1694 err = acx_setup_modes(adev);
1695 if (err) {
1696 printk("can't register hwmode\n");
1697 goto fail_register_netdev;
1700 acx_init_task_scheduler(adev);
1701 err = ieee80211_register_hw(ieee);
1702 if (OK != err) {
1703 printk("acx: ieee80211_register_hw() FAILED: %d\n", err);
1704 goto fail_register_netdev;
1706 #if CMD_DISCOVERY
1707 great_inquisitor(adev);
1708 #endif
1710 result = OK;
1711 goto done;
1713 /* error paths: undo everything in reverse order... */
1716 acxpci_s_delete_dma_regions(adev);
1717 pci_set_drvdata(pdev, NULL);
1719 fail_init_mac:
1720 fail_read_eeprom_version:
1721 fail_reset:
1723 fail_alloc_netdev:
1724 fail_irq:
1726 iounmap(mem2);
1727 fail_ioremap2:
1729 iounmap(mem1);
1730 fail_ioremap1:
1732 release_mem_region(pci_resource_start(pdev, mem_region2),
1733 pci_resource_len(pdev, mem_region2));
1734 fail_request_mem_region2:
1736 release_mem_region(pci_resource_start(pdev, mem_region1),
1737 pci_resource_len(pdev, mem_region1));
1738 fail_request_mem_region1:
1739 fail_unknown_chiptype:
1741 pci_disable_device(pdev);
1742 fail_pci_enable_device:
1744 #ifdef CONFIG_PM
1745 pci_set_power_state(pdev, PCI_D3hot);
1746 #endif
1747 fail_register_netdev:
1748 ieee80211_free_hw(ieee);
1749 done:
1750 FN_EXIT1(result);
1751 return result;
1755 /***********************************************************************
1756 ** acxpci_e_remove
1758 ** Shut device down (if not hot unplugged)
1759 ** and deallocate PCI resources for the acx chip.
1761 ** pdev - ptr to PCI device structure containing info about pci configuration
1763 static void __devexit acxpci_e_remove(struct pci_dev *pdev)
1765 struct ieee80211_hw *hw = (struct ieee80211_hw *)pci_get_drvdata(pdev);
1766 acx_device_t *adev = ieee2adev(hw);
1767 unsigned long mem_region1, mem_region2;
1768 unsigned long flags;
1769 FN_ENTER;
1771 if (!hw) {
1772 log(L_DEBUG, "%s: card is unused. Skipping any release code\n",
1773 __func__);
1774 goto end;
1778 adev->initialized = 0;
1780 /* If device wasn't hot unplugged... */
1781 if (adev_present(adev)) {
1783 /* disable both Tx and Rx to shut radio down properly */
1784 if (adev->initialized) {
1785 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_TX, NULL, 0);
1786 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_RX, NULL, 0);
1788 #ifdef REDUNDANT
1789 /* put the eCPU to sleep to save power
1790 * Halting is not possible currently,
1791 * since not supported by all firmware versions */
1792 acx_s_issue_cmd(adev, ACX100_CMD_SLEEP, NULL, 0);
1793 #endif
1794 acx_lock(adev, flags);
1795 /* disable power LED to save power :-) */
1796 log(L_INIT, "switching off power LED to save power\n");
1797 acxpci_l_power_led(adev, 0);
1798 /* stop our eCPU */
1799 if (IS_ACX111(adev)) {
1800 /* FIXME: does this actually keep halting the eCPU?
1801 * I don't think so...
1803 acxpci_l_reset_mac(adev);
1804 } else {
1805 u16 temp;
1806 /* halt eCPU */
1807 temp = read_reg16(adev, IO_ACX_ECPU_CTRL) | 0x1;
1808 write_reg16(adev, IO_ACX_ECPU_CTRL, temp);
1809 write_flush(adev);
1811 acx_unlock(adev, flags);
1815 /* unregister the device to not let the kernel
1816 * (e.g. ioctls) access a half-deconfigured device
1817 * NB: this will cause acxpci_e_close() to be called,
1818 * thus we shouldn't call it under sem!
1819 * Well, netdev did, but ieee80211 stack does not, so we
1820 * have to do so manually...
1822 acxpci_e_close(hw);
1823 log(L_INIT, "removing device %s\n", wiphy_name(adev->ieee->wiphy));
1824 ieee80211_unregister_hw(adev->ieee);
1826 /* unregister_netdev ensures that no references to us left.
1827 * For paranoid reasons we continue to follow the rules */
1828 acx_sem_lock(adev);
1830 if (adev->dev_state_mask & ACX_STATE_IFACE_UP) {
1831 acxpci_s_down(hw);
1832 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
1835 acx_proc_unregister_entries(adev->ieee);
1837 if (IS_ACX100(adev)) {
1838 mem_region1 = PCI_ACX100_REGION1;
1839 mem_region2 = PCI_ACX100_REGION2;
1840 } else {
1841 mem_region1 = PCI_ACX111_REGION1;
1842 mem_region2 = PCI_ACX111_REGION2;
1845 /* finally, clean up PCI bus state */
1846 acxpci_s_delete_dma_regions(adev);
1847 if (adev->iobase)
1848 iounmap(adev->iobase);
1849 if (adev->iobase2)
1850 iounmap(adev->iobase2);
1851 release_mem_region(pci_resource_start(pdev, mem_region1),
1852 pci_resource_len(pdev, mem_region1));
1853 release_mem_region(pci_resource_start(pdev, mem_region2),
1854 pci_resource_len(pdev, mem_region2));
1855 pci_disable_device(pdev);
1857 /* remove dev registration */
1859 free_irq(adev->irq, adev);
1860 acx_sem_unlock(adev);
1862 /* Free netdev (quite late,
1863 * since otherwise we might get caught off-guard
1864 * by a netdev timeout handler execution
1865 * expecting to see a working dev...) */
1866 ieee80211_free_hw(adev->ieee);
1868 /* put device into ACPI D3 mode (shutdown) */
1869 #ifdef CONFIG_PM
1870 pci_set_power_state(pdev, PCI_D3hot);
1871 #endif
1872 end:
1873 FN_EXIT0;
1877 /***********************************************************************
1878 ** TODO: PM code needs to be fixed / debugged / tested.
1880 #ifdef CONFIG_PM
1881 static int
1882 acxpci_e_suspend(struct pci_dev *pdev, pm_message_t state)
1884 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1885 acx_device_t *adev;
1887 FN_ENTER;
1888 printk("acx: suspend handler is experimental!\n");
1889 printk("sus: dev %p\n", hw);
1891 /* if (!netif_running(ndev))
1892 goto end;
1894 adev = ieee2adev(hw);
1895 printk("sus: adev %p\n", adev);
1897 acx_sem_lock(adev);
1899 ieee80211_unregister_hw(hw); /* this one cannot sleep */
1900 acxpci_s_down(hw);
1901 /* down() does not set it to 0xffff, but here we really want that */
1902 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
1903 write_reg16(adev, IO_ACX_FEMR, 0x0);
1904 acxpci_s_delete_dma_regions(adev);
1905 pci_save_state(pdev);
1906 pci_set_power_state(pdev, PCI_D3hot);
1908 acx_sem_unlock(adev);
1909 FN_EXIT0;
1910 return OK;
1914 static int acxpci_e_resume(struct pci_dev *pdev)
1916 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1917 acx_device_t *adev;
1919 FN_ENTER;
1921 printk("acx: resume handler is experimental!\n");
1922 printk("rsm: got dev %p\n", hw);
1925 adev = ieee2adev(hw);
1926 printk("rsm: got adev %p\n", adev);
1928 acx_sem_lock(adev);
1930 pci_set_power_state(pdev, PCI_D0);
1931 printk("rsm: power state PCI_D0 set\n");
1932 pci_restore_state(pdev);
1933 printk("rsm: PCI state restored\n");
1935 if (OK != acxpci_s_reset_dev(adev))
1936 goto end_unlock;
1937 printk("rsm: device reset done\n");
1938 if (OK != acx_s_init_mac(adev))
1939 goto end_unlock;
1940 printk("rsm: init MAC done\n");
1942 acxpci_s_up(hw);
1943 printk("rsm: acx up done\n");
1945 /* now even reload all card parameters as they were before suspend,
1946 * and possibly be back in the network again already :-) */
1947 if (ACX_STATE_IFACE_UP & adev->dev_state_mask) {
1948 adev->set_mask = GETSET_ALL;
1949 acx_s_update_card_settings(adev);
1950 printk("rsm: settings updated\n");
1952 ieee80211_register_hw(hw);
1953 printk("rsm: device attached\n");
1955 end_unlock:
1956 acx_sem_unlock(adev);
1957 /* we need to return OK here anyway, right? */
1958 FN_EXIT0;
1959 return OK;
1961 #endif /* CONFIG_PM */
1962 #endif /* CONFIG_PCI */
1964 /***********************************************************************
1965 ** acxpci_s_up
1967 ** This function is called by acxpci_e_open (when ifconfig sets the device as up)
1969 ** Side effects:
1970 ** - Enables on-card interrupt requests
1971 ** - calls acx_s_start
1974 static void enable_acx_irq(acx_device_t * adev)
1976 FN_ENTER;
1977 write_reg16(adev, IO_ACX_IRQ_MASK, adev->irq_mask);
1978 write_reg16(adev, IO_ACX_FEMR, 0x8000);
1979 adev->irqs_active = 1;
1980 FN_EXIT0;
1983 static void acxpci_s_up(struct ieee80211_hw *hw)
1985 acx_device_t *adev = ieee2adev(hw);
1986 unsigned long flags;
1988 FN_ENTER;
1990 acx_lock(adev, flags);
1991 enable_acx_irq(adev);
1992 acx_unlock(adev, flags);
1994 /* acx fw < 1.9.3.e has a hardware timer, and older drivers
1995 ** used to use it. But we don't do that anymore, our OS
1996 ** has reliable software timers */
1997 init_timer(&adev->mgmt_timer);
1998 adev->mgmt_timer.function = acx_i_timer;
1999 adev->mgmt_timer.data = (unsigned long)adev;
2001 /* Need to set ACX_STATE_IFACE_UP first, or else
2002 ** timer won't be started by acx_set_status() */
2003 SET_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
2005 acx_s_start(adev);
2007 FN_EXIT0;
2011 /***********************************************************************
2012 ** acxpci_s_down
2014 ** NB: device may be already hot unplugged if called from acxpci_e_remove()
2016 ** Disables on-card interrupt request, stops softirq and timer, stops queue,
2017 ** sets status == STOPPED
2020 static void disable_acx_irq(acx_device_t * adev)
2022 FN_ENTER;
2024 /* I guess mask is not 0xffff because acx100 won't signal
2025 ** cmd completion then (needed for ifup).
2026 ** I can't ifconfig up after ifconfig down'ing on my acx100 */
2027 write_reg16(adev, IO_ACX_IRQ_MASK, adev->irq_mask_off);
2028 write_reg16(adev, IO_ACX_FEMR, 0x0);
2029 adev->irqs_active = 0;
2031 FN_EXIT0;
2034 static void acxpci_s_down(struct ieee80211_hw *hw)
2036 acx_device_t *adev = ieee2adev(hw);
2038 FN_ENTER;
2040 /* Disable IRQs first, so that IRQs cannot race with us */
2041 /* then wait until interrupts have finished executing on other CPUs */
2042 disable_acx_irq(adev); /* NO sem-locking here? */
2043 synchronize_irq(adev->irq);
2045 /* we really don't want to have an asynchronous tasklet disturb us
2046 ** after something vital for its job has been shut down, so
2047 ** end all remaining work now.
2049 ** NB: carrier_off (done by set_status below) would lead to
2050 ** not yet fully understood deadlock in flush_scheduled_work().
2051 ** That's why we do FLUSH first.
2053 ** NB2: we have a bad locking bug here: flush_scheduled_work()
2054 ** waits for acx_e_after_interrupt_task to complete if it is running
2055 ** on another CPU, but acx_e_after_interrupt_task
2056 ** will sleep on sem forever, because it is taken by us!
2057 ** Work around that by temporary sem unlock.
2058 ** This will fail miserably if we'll be hit by concurrent
2059 ** iwconfig or something in between. TODO! */
2060 acx_sem_unlock(adev);
2061 flush_scheduled_work();
2062 acx_sem_lock(adev);
2064 /* This is possible:
2065 ** flush_scheduled_work -> acx_e_after_interrupt_task ->
2066 ** -> set_status(ASSOCIATED) -> wake_queue()
2067 ** That's why we stop queue _after_ flush_scheduled_work
2068 ** lock/unlock is just paranoia, maybe not needed */
2070 /* kernel/timer.c says it's illegal to del_timer_sync()
2071 ** a timer which restarts itself. We guarantee this cannot
2072 ** ever happen because acx_i_timer() never does this if
2073 ** status is ACX_STATUS_0_STOPPED */
2074 del_timer_sync(&adev->mgmt_timer);
2076 FN_EXIT0;
2079 #ifdef CONFIG_NET_POLL_CONTROLLER
2080 void acxpci_net_poll_controller(struct net_device *net_dev)
2082 acx_device_t *adev = ndev2adev(net_dev);
2083 unsigned long flags;
2085 local_irq_save(flags);
2086 acxpci_i_interrupt(adev->irq, adev);
2087 local_irq_restore(flags);
2089 #endif*/ /* CONFIG_NET_POLL_CONTROLLER */
2091 /***********************************************************************
2092 ** acxpci_e_open
2094 ** Called as a result of SIOCSIFFLAGS ioctl changing the flags bit IFF_UP
2095 ** from clear to set. In other words: ifconfig up.
2097 ** Returns:
2098 ** 0 success
2099 ** >0 f/w reported error
2100 ** <0 driver reported error
2102 static int acxpci_e_open(struct ieee80211_hw *hw)
2104 acx_device_t *adev = ieee2adev(hw);
2105 int result = OK;
2107 FN_ENTER;
2109 acx_sem_lock(adev);
2111 adev->initialized = 0;
2113 /* TODO: pci_set_power_state(pdev, PCI_D0); ? */
2115 /* request shared IRQ handler */
2116 if (request_irq
2117 (adev->irq, acxpci_i_interrupt, IRQF_SHARED, KBUILD_MODNAME, adev)) {
2118 printk("%s: request_irq FAILED\n", wiphy_name(adev->ieee->wiphy));
2119 result = -EAGAIN;
2120 goto done;
2122 log(L_DEBUG | L_IRQ, "request_irq %d successful\n", adev->irq);
2124 /* ifup device */
2125 acxpci_s_up(hw);
2127 /* We don't currently have to do anything else.
2128 * The setup of the MAC should be subsequently completed via
2129 * the mlme commands.
2130 * Higher layers know we're ready from dev->start==1 and
2131 * dev->tbusy==0. Our rx path knows to pass up received/
2132 * frames because of dev->flags&IFF_UP is true.
2134 ieee80211_start_queues(adev->ieee);
2136 adev->initialized = 1;
2137 done:
2138 acx_sem_unlock(adev);
2140 FN_EXIT1(result);
2141 return result;
2145 /***********************************************************************
2146 ** acxpci_e_close
2148 ** This function stops the network functionality of the interface (invoked
2149 ** when the user calls ifconfig <wlan> down). The tx queue is halted and
2150 ** the device is marked as down.
2152 ** Called as a result of SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
2153 ** from set to clear. I.e. called by "ifconfig DEV down"
2155 ** Returns:
2156 ** 0 success
2157 ** >0 f/w reported error
2158 ** <0 driver reported error
2160 static void acxpci_e_close(struct ieee80211_hw *hw)
2162 acx_device_t *adev = ieee2adev(hw);
2164 FN_ENTER;
2166 acx_sem_lock(adev);
2168 /* ifdown device */
2169 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
2170 if (adev->initialized) {
2171 acxpci_s_down(hw);
2174 if (adev->modes)
2175 acx_free_modes(adev);
2176 /* disable all IRQs, release shared IRQ handler */
2177 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
2178 write_reg16(adev, IO_ACX_FEMR, 0x0);
2180 /* TODO: pci_set_power_state(pdev, PCI_D3hot); ? */
2182 /* We currently don't have to do anything else.
2183 * Higher layers know we're not ready from dev->start==0 and
2184 * dev->tbusy==1. Our rx path knows to not pass up received
2185 * frames because of dev->flags&IFF_UP is false.
2187 acx_sem_unlock(adev);
2189 log(L_INIT, "closed device\n");
2190 FN_EXIT0;
2196 /***************************************************************
2197 ** acxpci_l_process_rxdesc
2199 ** Called directly and only from the IRQ handler
2202 #if !ACX_DEBUG
2203 static inline void log_rxbuffer(const acx_device_t * adev)
2206 #else
2207 static void log_rxbuffer(const acx_device_t * adev)
2209 register const struct rxhostdesc *rxhostdesc;
2210 int i;
2212 /* no FN_ENTER here, we don't want that */
2214 rxhostdesc = adev->rxhostdesc_start;
2215 if (unlikely(!rxhostdesc))
2216 return;
2217 for (i = 0; i < RX_CNT; i++) {
2218 if ((rxhostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2219 && (rxhostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2220 printk("rx: buf %d full\n", i);
2221 rxhostdesc++;
2224 #endif
2226 static void acxpci_l_process_rxdesc(acx_device_t * adev)
2228 register rxhostdesc_t *hostdesc;
2229 unsigned count, tail;
2231 FN_ENTER;
2233 if (unlikely(acx_debug & L_BUFR))
2234 log_rxbuffer(adev);
2236 /* First, have a loop to determine the first descriptor that's
2237 * full, just in case there's a mismatch between our current
2238 * rx_tail and the full descriptor we're supposed to handle. */
2239 tail = adev->rx_tail;
2240 count = RX_CNT;
2241 while (1) {
2242 hostdesc = &adev->rxhostdesc_start[tail];
2243 /* advance tail regardless of outcome of the below test */
2244 tail = (tail + 1) % RX_CNT;
2246 if ((hostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2247 && (hostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2248 break; /* found it! */
2250 if (unlikely(!--count)) /* hmm, no luck: all descs empty, bail out */
2251 goto end;
2254 /* now process descriptors, starting with the first we figured out */
2255 while (1) {
2256 log(L_BUFR, "rx: tail=%u Ctl_16=%04X Status=%08X\n",
2257 tail, hostdesc->Ctl_16, hostdesc->Status);
2259 acx_l_process_rxbuf(adev, hostdesc->data);
2260 hostdesc->Status = 0;
2261 /* flush all writes before adapter sees CTL_HOSTOWN change */
2262 wmb();
2263 /* Host no longer owns this, needs to be LAST */
2264 CLEAR_BIT(hostdesc->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
2266 /* ok, descriptor is handled, now check the next descriptor */
2267 hostdesc = &adev->rxhostdesc_start[tail];
2269 /* if next descriptor is empty, then bail out */
2270 if (!(hostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2271 || !(hostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2272 break;
2274 tail = (tail + 1) % RX_CNT;
2276 end:
2277 adev->rx_tail = tail;
2278 FN_EXIT0;
2283 /***********************************************************************
2284 ** acxpci_i_interrupt
2286 ** IRQ handler (atomic context, must not sleep, blah, blah)
2289 /* scan is complete. all frames now on the receive queue are valid */
2290 #define INFO_SCAN_COMPLETE 0x0001
2291 #define INFO_WEP_KEY_NOT_FOUND 0x0002
2292 /* hw has been reset as the result of a watchdog timer timeout */
2293 #define INFO_WATCH_DOG_RESET 0x0003
2294 /* failed to send out NULL frame from PS mode notification to AP */
2295 /* recommended action: try entering 802.11 PS mode again */
2296 #define INFO_PS_FAIL 0x0004
2297 /* encryption/decryption process on a packet failed */
2298 #define INFO_IV_ICV_FAILURE 0x0005
2300 /* Info mailbox format:
2301 2 bytes: type
2302 2 bytes: status
2303 more bytes may follow
2304 rumors say about status:
2305 0x0000 info available (set by hw)
2306 0x0001 information received (must be set by host)
2307 0x1000 info available, mailbox overflowed (messages lost) (set by hw)
2308 but in practice we've seen:
2309 0x9000 when we did not set status to 0x0001 on prev message
2310 0x1001 when we did set it
2311 0x0000 was never seen
2312 conclusion: this is really a bitfield:
2313 0x1000 is 'info available' bit
2314 'mailbox overflowed' bit is 0x8000, not 0x1000
2315 value of 0x0000 probably means that there are no messages at all
2316 P.S. I dunno how in hell hw is supposed to notice that messages are lost -
2317 it does NOT clear bit 0x0001, and this bit will probably stay forever set
2318 after we set it once. Let's hope this will be fixed in firmware someday
2321 static void handle_info_irq(acx_device_t * adev)
2323 #if ACX_DEBUG
2324 static const char *const info_type_msg[] = {
2325 "(unknown)",
2326 "scan complete",
2327 "WEP key not found",
2328 "internal watchdog reset was done",
2329 "failed to send powersave (NULL frame) notification to AP",
2330 "encrypt/decrypt on a packet has failed",
2331 "TKIP tx keys disabled",
2332 "TKIP rx keys disabled",
2333 "TKIP rx: key ID not found",
2334 "???",
2335 "???",
2336 "???",
2337 "???",
2338 "???",
2339 "???",
2340 "???",
2341 "TKIP IV value exceeds thresh"
2343 #endif
2344 u32 info_type, info_status;
2346 info_type = acx_readl(adev->info_area);
2347 info_status = (info_type >> 16);
2348 info_type = (u16) info_type;
2350 /* inform fw that we have read this info message */
2351 acx_writel(info_type | 0x00010000, adev->info_area);
2352 write_reg16(adev, IO_ACX_INT_TRIG, INT_TRIG_INFOACK);
2353 write_flush(adev);
2355 log(L_CTL, "info_type:%04X info_status:%04X\n", info_type, info_status);
2357 log(L_IRQ, "got Info IRQ: status %04X type %04X: %s\n",
2358 info_status, info_type,
2359 info_type_msg[(info_type >= ARRAY_SIZE(info_type_msg)) ?
2360 0 : info_type]
2365 static void log_unusual_irq(u16 irqtype)
2368 if (!printk_ratelimit())
2369 return;
2372 printk("acx: got");
2373 if (irqtype & HOST_INT_RX_DATA) {
2374 printk(" Rx_Data");
2376 /* HOST_INT_TX_COMPLETE */
2377 if (irqtype & HOST_INT_TX_XFER) {
2378 printk(" Tx_Xfer");
2380 /* HOST_INT_RX_COMPLETE */
2381 if (irqtype & HOST_INT_DTIM) {
2382 printk(" DTIM");
2384 if (irqtype & HOST_INT_BEACON) {
2385 printk(" Beacon");
2387 if (irqtype & HOST_INT_TIMER) {
2388 log(L_IRQ, " Timer");
2390 if (irqtype & HOST_INT_KEY_NOT_FOUND) {
2391 printk(" Key_Not_Found");
2393 if (irqtype & HOST_INT_IV_ICV_FAILURE) {
2394 printk(" IV_ICV_Failure (crypto)");
2396 /* HOST_INT_CMD_COMPLETE */
2397 /* HOST_INT_INFO */
2398 if (irqtype & HOST_INT_OVERFLOW) {
2399 printk(" Overflow");
2401 if (irqtype & HOST_INT_PROCESS_ERROR) {
2402 printk(" Process_Error");
2404 /* HOST_INT_SCAN_COMPLETE */
2405 if (irqtype & HOST_INT_FCS_THRESHOLD) {
2406 printk(" FCS_Threshold");
2408 if (irqtype & HOST_INT_UNKNOWN) {
2409 printk(" Unknown");
2411 printk(" IRQ(s)\n");
2414 /* FIXME: update_link_quality_led was a stub - let's comment it and avoid
2415 * compiler warnings */
2417 static void update_link_quality_led(acx_device_t * adev)
2419 int qual;
2421 qual =
2422 acx_signal_determine_quality(adev->wstats.qual.level,
2423 adev->wstats.qual.noise);
2424 if (qual > adev->brange_max_quality)
2425 qual = adev->brange_max_quality;
2427 if (time_after(jiffies, adev->brange_time_last_state_change +
2428 (HZ / 2 -
2429 HZ / 2 * (unsigned long)qual /
2430 adev->brange_max_quality))) {
2431 acxpci_l_power_led(adev, (adev->brange_last_state == 0));
2432 adev->brange_last_state ^= 1; // toggle
2433 adev->brange_time_last_state_change = jiffies;
2438 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* a la orinoco.c */
2440 /* Interrupt handler bottom-half */
2441 void acx_interrupt_tasklet(struct work_struct *work)
2444 #ifdef CONFIG_ACX_MAC80211_DEBUG
2445 u32 _handled = 0x00000000;
2446 # define acxirq_handled(irq) do { _handled |= (irq); } while (0)
2447 #else
2448 # define acxirq_handled(irq) do { /* nothing */ } while (0)
2449 #endif /* CONFIG_ACX_MAC80211_DEBUG */
2450 acx_device_t *adev = container_of(work,struct acx_device, after_interrupt_task);
2451 // unsigned int irqcount = MAX_IRQLOOPS_PER_JIFFY;
2452 int irqtype;
2453 unsigned long flags;
2455 FN_ENTER;
2457 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2458 * I am paranoid */
2459 acx_sem_lock(adev);
2461 irqtype = adev->irq_reason;
2462 adev->irq_reason = 0;
2464 #define IRQ_ITERATE 0
2465 #if IRQ_ITERATE
2466 if (jiffies != adev->irq_last_jiffies) {
2467 adev->irq_loops_this_jiffy = 0;
2468 adev->irq_last_jiffies = jiffies;
2471 /* safety condition; we'll normally abort loop below
2472 * in case no IRQ type occurred */
2473 while (likely(--irqcount)) {
2474 #endif
2475 /* ACK all IRQs ASAP */
2477 acx_lock(adev, flags);
2479 /* Handle most important IRQ types first */
2480 if (irqtype & HOST_INT_RX_COMPLETE) {
2481 log(L_IRQ, "got Rx_Complete IRQ\n");
2482 acxpci_l_process_rxdesc(adev);
2484 if (irqtype & HOST_INT_TX_COMPLETE) {
2485 log(L_IRQ, "got Tx_Complete IRQ\n");
2486 /* don't clean up on each Tx complete, wait a bit
2487 * unless we're going towards full, in which case
2488 * we do it immediately, too (otherwise we might lockup
2489 * with a full Tx buffer if we go into
2490 * acxpci_l_clean_txdesc() at a time when we won't wakeup
2491 * the net queue in there for some reason...) */
2492 // if (adev->tx_free <= TX_START_CLEAN) {
2493 acxpci_l_clean_txdesc(adev);
2494 // }
2497 acx_unlock(adev, flags);
2499 /* Less frequent ones */
2500 if (irqtype & (0
2501 | HOST_INT_CMD_COMPLETE
2502 | HOST_INT_INFO | HOST_INT_SCAN_COMPLETE)) {
2503 if (irqtype & HOST_INT_INFO) {
2504 handle_info_irq(adev);
2506 if (irqtype & HOST_INT_SCAN_COMPLETE) {
2507 log(L_IRQ, "got Scan_Complete IRQ\n");
2508 /* need to do that in process context */
2509 /* remember that fw is not scanning anymore */
2510 SET_BIT(adev->irq_status,
2511 HOST_INT_SCAN_COMPLETE);
2515 /* These we just log, but either they happen rarely
2516 * or we keep them masked out */
2517 if (irqtype & (0 | HOST_INT_RX_DATA
2518 /* | HOST_INT_TX_COMPLETE */
2519 | HOST_INT_TX_XFER
2520 /* | HOST_INT_RX_COMPLETE */
2521 | HOST_INT_DTIM
2522 | HOST_INT_BEACON
2523 | HOST_INT_TIMER
2524 | HOST_INT_KEY_NOT_FOUND
2525 | HOST_INT_IV_ICV_FAILURE
2526 /* | HOST_INT_CMD_COMPLETE */
2527 /* | HOST_INT_INFO */
2528 | HOST_INT_OVERFLOW
2529 | HOST_INT_PROCESS_ERROR
2530 /* | HOST_INT_SCAN_COMPLETE */
2531 | HOST_INT_FCS_THRESHOLD
2532 | HOST_INT_UNKNOWN)) {
2533 log_unusual_irq(irqtype);
2535 #if IRQ_ITERATE
2536 unmasked = read_reg16(adev, IO_ACX_IRQ_STATUS_CLEAR);
2537 irqtype = unmasked & ~adev->irq_mask;
2538 /* Bail out if no new IRQ bits or if all are masked out */
2539 if (!irqtype)
2540 break;
2542 if (unlikely
2543 (++adev->irq_loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY)) {
2544 printk(KERN_ERR
2545 "acx: too many interrupts per jiffy!\n");
2546 /* Looks like card floods us with IRQs! Try to stop that */
2547 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
2548 /* This will short-circuit all future attempts to handle IRQ.
2549 * We cant do much more... */
2550 adev->irq_mask = 0;
2551 break;
2554 #endif
2555 /* Routine to perform blink with range
2556 * FIXME: update_link_quality_led is a stub - add proper code and enable this again:
2557 if (unlikely(adev->led_power == 2))
2558 update_link_quality_led(adev);
2561 /* write_flush(adev); - not needed, last op was read anyway */
2562 acx_sem_unlock(adev);
2564 /* handled: */
2565 if (adev->after_interrupt_jobs)
2566 acx_e_after_interrupt_task(&adev->after_interrupt_task);
2568 FN_EXIT0;
2569 return;
2574 static irqreturn_t acxpci_i_interrupt(int irq, void *dev_id)
2576 acx_device_t *adev = dev_id;
2577 unsigned long flags;
2578 register u16 irqtype;
2579 u16 unmasked;
2581 FN_ENTER;
2583 if (!adev)
2584 return IRQ_NONE;
2586 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2587 * I am paranoid */
2589 acx_lock(adev, flags);
2591 unmasked = read_reg16(adev, IO_ACX_IRQ_STATUS_CLEAR);
2592 if (unlikely(0xffff == unmasked)) {
2593 /* 0xffff value hints at missing hardware,
2594 * so don't do anything.
2595 * Not very clean, but other drivers do the same... */
2596 log(L_IRQ, "IRQ type:FFFF - device removed? IRQ_NONE\n");
2597 goto none;
2600 /* We will check only "interesting" IRQ types */
2601 irqtype = unmasked & ~adev->irq_mask;
2602 if (!irqtype) {
2603 /* We are on a shared IRQ line and it wasn't our IRQ */
2604 log(L_IRQ,
2605 "IRQ type:%04X, mask:%04X - all are masked, IRQ_NONE\n",
2606 unmasked, adev->irq_mask);
2607 goto none;
2610 /* Go ahead and ACK our interrupt */
2611 write_reg16(adev, IO_ACX_IRQ_ACK, 0xffff);
2612 if (irqtype & HOST_INT_CMD_COMPLETE) {
2613 log(L_IRQ, "got Command_Complete IRQ\n");
2614 /* save the state for the running issue_cmd() */
2615 SET_BIT(adev->irq_status, HOST_INT_CMD_COMPLETE);
2618 /* Only accept IRQs, if we are initialized properly.
2619 * This avoids an RX race while initializing.
2620 * We should probably not enable IRQs before we are initialized
2621 * completely, but some careful work is needed to fix this. I think it
2622 * is best to stay with this cheap workaround for now... .
2624 if (likely(adev->initialized)) {
2625 /* disable all IRQs. They are enabled again in the bottom half. */
2626 /* save the reason code and call our bottom half. */
2627 adev->irq_reason = irqtype;
2629 if ((irqtype & HOST_INT_RX_COMPLETE) || (irqtype & HOST_INT_TX_COMPLETE))
2630 acx_schedule_task(adev, 0);
2633 acx_unlock(adev, flags);
2634 FN_EXIT0;
2635 return IRQ_HANDLED;
2636 none:
2637 acx_unlock(adev, flags);
2638 FN_EXIT0;
2639 return IRQ_NONE;
2644 /***********************************************************************
2645 ** acxpci_l_power_led
2647 void acxpci_l_power_led(acx_device_t * adev, int enable)
2649 u16 gpio_pled = IS_ACX111(adev) ? 0x0040 : 0x0800;
2651 /* A hack. Not moving message rate limiting to adev->xxx
2652 * (it's only a debug message after all) */
2653 static int rate_limit = 0;
2655 if (rate_limit++ < 3)
2656 log(L_IOCTL, "Please report in case toggling the power "
2657 "LED doesn't work for your card!\n");
2658 if (enable)
2659 write_reg16(adev, IO_ACX_GPIO_OUT,
2660 read_reg16(adev, IO_ACX_GPIO_OUT) & ~gpio_pled);
2661 else
2662 write_reg16(adev, IO_ACX_GPIO_OUT,
2663 read_reg16(adev, IO_ACX_GPIO_OUT) | gpio_pled);
2667 /***********************************************************************
2668 ** Ioctls
2671 /***********************************************************************
2673 #if 0
2675 acx111pci_ioctl_info(struct net_device *ndev,
2676 struct iw_request_info *info,
2677 struct iw_param *vwrq, char *extra)
2679 #if ACX_DEBUG > 1
2680 acx_device_t *adev = ndev2adev(ndev);
2681 rxdesc_t *rxdesc;
2682 txdesc_t *txdesc;
2683 rxhostdesc_t *rxhostdesc;
2684 txhostdesc_t *txhostdesc;
2685 struct acx111_ie_memoryconfig memconf;
2686 struct acx111_ie_queueconfig queueconf;
2687 unsigned long flags;
2688 int i;
2689 char memmap[0x34];
2690 char rxconfig[0x8];
2691 char fcserror[0x8];
2692 char ratefallback[0x5];
2694 if (!(acx_debug & (L_IOCTL | L_DEBUG)))
2695 return OK;
2696 /* using printk() since we checked debug flag already */
2698 acx_sem_lock(adev);
2700 if (!IS_ACX111(adev)) {
2701 printk("acx111-specific function called "
2702 "with non-acx111 chip, aborting\n");
2703 goto end_ok;
2706 /* get Acx111 Memory Configuration */
2707 memset(&memconf, 0, sizeof(memconf));
2708 /* BTW, fails with 12 (Write only) error code.
2709 ** Retained for easy testing of issue_cmd error handling :) */
2710 acx_s_interrogate(adev, &memconf, ACX1xx_IE_QUEUE_CONFIG);
2712 /* get Acx111 Queue Configuration */
2713 memset(&queueconf, 0, sizeof(queueconf));
2714 acx_s_interrogate(adev, &queueconf, ACX1xx_IE_MEMORY_CONFIG_OPTIONS);
2716 /* get Acx111 Memory Map */
2717 memset(memmap, 0, sizeof(memmap));
2718 acx_s_interrogate(adev, &memmap, ACX1xx_IE_MEMORY_MAP);
2720 /* get Acx111 Rx Config */
2721 memset(rxconfig, 0, sizeof(rxconfig));
2722 acx_s_interrogate(adev, &rxconfig, ACX1xx_IE_RXCONFIG);
2724 /* get Acx111 fcs error count */
2725 memset(fcserror, 0, sizeof(fcserror));
2726 acx_s_interrogate(adev, &fcserror, ACX1xx_IE_FCS_ERROR_COUNT);
2728 /* get Acx111 rate fallback */
2729 memset(ratefallback, 0, sizeof(ratefallback));
2730 acx_s_interrogate(adev, &ratefallback, ACX1xx_IE_RATE_FALLBACK);
2732 /* force occurrence of a beacon interrupt */
2733 /* TODO: comment why is this necessary */
2734 write_reg16(adev, IO_ACX_HINT_TRIG, HOST_INT_BEACON);
2736 /* dump Acx111 Mem Configuration */
2737 printk("dump mem config:\n"
2738 "data read: %d, struct size: %d\n"
2739 "Number of stations: %1X\n"
2740 "Memory block size: %1X\n"
2741 "tx/rx memory block allocation: %1X\n"
2742 "count rx: %X / tx: %X queues\n"
2743 "options %1X\n"
2744 "fragmentation %1X\n"
2745 "Rx Queue 1 Count Descriptors: %X\n"
2746 "Rx Queue 1 Host Memory Start: %X\n"
2747 "Tx Queue 1 Count Descriptors: %X\n"
2748 "Tx Queue 1 Attributes: %X\n",
2749 memconf.len, (int)sizeof(memconf),
2750 memconf.no_of_stations,
2751 memconf.memory_block_size,
2752 memconf.tx_rx_memory_block_allocation,
2753 memconf.count_rx_queues, memconf.count_tx_queues,
2754 memconf.options,
2755 memconf.fragmentation,
2756 memconf.rx_queue1_count_descs,
2757 acx2cpu(memconf.rx_queue1_host_rx_start),
2758 memconf.tx_queue1_count_descs, memconf.tx_queue1_attributes);
2760 /* dump Acx111 Queue Configuration */
2761 printk("dump queue head:\n"
2762 "data read: %d, struct size: %d\n"
2763 "tx_memory_block_address (from card): %X\n"
2764 "rx_memory_block_address (from card): %X\n"
2765 "rx1_queue address (from card): %X\n"
2766 "tx1_queue address (from card): %X\n"
2767 "tx1_queue attributes (from card): %X\n",
2768 queueconf.len, (int)sizeof(queueconf),
2769 queueconf.tx_memory_block_address,
2770 queueconf.rx_memory_block_address,
2771 queueconf.rx1_queue_address,
2772 queueconf.tx1_queue_address, queueconf.tx1_attributes);
2774 /* dump Acx111 Mem Map */
2775 printk("dump mem map:\n"
2776 "data read: %d, struct size: %d\n"
2777 "Code start: %X\n"
2778 "Code end: %X\n"
2779 "WEP default key start: %X\n"
2780 "WEP default key end: %X\n"
2781 "STA table start: %X\n"
2782 "STA table end: %X\n"
2783 "Packet template start: %X\n"
2784 "Packet template end: %X\n"
2785 "Queue memory start: %X\n"
2786 "Queue memory end: %X\n"
2787 "Packet memory pool start: %X\n"
2788 "Packet memory pool end: %X\n"
2789 "iobase: %p\n"
2790 "iobase2: %p\n",
2791 *((u16 *) & memmap[0x02]), (int)sizeof(memmap),
2792 *((u32 *) & memmap[0x04]),
2793 *((u32 *) & memmap[0x08]),
2794 *((u32 *) & memmap[0x0C]),
2795 *((u32 *) & memmap[0x10]),
2796 *((u32 *) & memmap[0x14]),
2797 *((u32 *) & memmap[0x18]),
2798 *((u32 *) & memmap[0x1C]),
2799 *((u32 *) & memmap[0x20]),
2800 *((u32 *) & memmap[0x24]),
2801 *((u32 *) & memmap[0x28]),
2802 *((u32 *) & memmap[0x2C]),
2803 *((u32 *) & memmap[0x30]), adev->iobase, adev->iobase2);
2805 /* dump Acx111 Rx Config */
2806 printk("dump rx config:\n"
2807 "data read: %d, struct size: %d\n"
2808 "rx config: %X\n"
2809 "rx filter config: %X\n",
2810 *((u16 *) & rxconfig[0x02]), (int)sizeof(rxconfig),
2811 *((u16 *) & rxconfig[0x04]), *((u16 *) & rxconfig[0x06]));
2813 /* dump Acx111 fcs error */
2814 printk("dump fcserror:\n"
2815 "data read: %d, struct size: %d\n"
2816 "fcserrors: %X\n",
2817 *((u16 *) & fcserror[0x02]), (int)sizeof(fcserror),
2818 *((u32 *) & fcserror[0x04]));
2820 /* dump Acx111 rate fallback */
2821 printk("dump rate fallback:\n"
2822 "data read: %d, struct size: %d\n"
2823 "ratefallback: %X\n",
2824 *((u16 *) & ratefallback[0x02]), (int)sizeof(ratefallback),
2825 *((u8 *) & ratefallback[0x04]));
2827 /* protect against IRQ */
2828 acx_lock(adev, flags);
2830 /* dump acx111 internal rx descriptor ring buffer */
2831 rxdesc = adev->rxdesc_start;
2833 /* loop over complete receive pool */
2834 if (rxdesc)
2835 for (i = 0; i < RX_CNT; i++) {
2836 printk("\ndump internal rxdesc %d:\n"
2837 "mem pos %p\n"
2838 "next 0x%X\n"
2839 "acx mem pointer (dynamic) 0x%X\n"
2840 "CTL (dynamic) 0x%X\n"
2841 "Rate (dynamic) 0x%X\n"
2842 "RxStatus (dynamic) 0x%X\n"
2843 "Mod/Pre (dynamic) 0x%X\n",
2845 rxdesc,
2846 acx2cpu(rxdesc->pNextDesc),
2847 acx2cpu(rxdesc->ACXMemPtr),
2848 rxdesc->Ctl_8,
2849 rxdesc->rate, rxdesc->error, rxdesc->SNR);
2850 rxdesc++;
2853 /* dump host rx descriptor ring buffer */
2855 rxhostdesc = adev->rxhostdesc_start;
2857 /* loop over complete receive pool */
2858 if (rxhostdesc)
2859 for (i = 0; i < RX_CNT; i++) {
2860 printk("\ndump host rxdesc %d:\n"
2861 "mem pos %p\n"
2862 "buffer mem pos 0x%X\n"
2863 "buffer mem offset 0x%X\n"
2864 "CTL 0x%X\n"
2865 "Length 0x%X\n"
2866 "next 0x%X\n"
2867 "Status 0x%X\n",
2869 rxhostdesc,
2870 acx2cpu(rxhostdesc->data_phy),
2871 rxhostdesc->data_offset,
2872 le16_to_cpu(rxhostdesc->Ctl_16),
2873 le16_to_cpu(rxhostdesc->length),
2874 acx2cpu(rxhostdesc->desc_phy_next),
2875 rxhostdesc->Status);
2876 rxhostdesc++;
2879 /* dump acx111 internal tx descriptor ring buffer */
2880 txdesc = adev->txdesc_start;
2882 /* loop over complete transmit pool */
2883 if (txdesc)
2884 for (i = 0; i < TX_CNT; i++) {
2885 printk("\ndump internal txdesc %d:\n"
2886 "size 0x%X\n"
2887 "mem pos %p\n"
2888 "next 0x%X\n"
2889 "acx mem pointer (dynamic) 0x%X\n"
2890 "host mem pointer (dynamic) 0x%X\n"
2891 "length (dynamic) 0x%X\n"
2892 "CTL (dynamic) 0x%X\n"
2893 "CTL2 (dynamic) 0x%X\n"
2894 "Status (dynamic) 0x%X\n"
2895 "Rate (dynamic) 0x%X\n",
2897 (int)sizeof(struct txdesc),
2898 txdesc,
2899 acx2cpu(txdesc->pNextDesc),
2900 acx2cpu(txdesc->AcxMemPtr),
2901 acx2cpu(txdesc->HostMemPtr),
2902 le16_to_cpu(txdesc->total_length),
2903 txdesc->Ctl_8,
2904 txdesc->Ctl2_8, txdesc->error,
2905 txdesc->u.r1.rate);
2906 txdesc = advance_txdesc(adev, txdesc, 1);
2909 /* dump host tx descriptor ring buffer */
2911 txhostdesc = adev->txhostdesc_start;
2913 /* loop over complete host send pool */
2914 if (txhostdesc)
2915 for (i = 0; i < TX_CNT * 2; i++) {
2916 printk("\ndump host txdesc %d:\n"
2917 "mem pos %p\n"
2918 "buffer mem pos 0x%X\n"
2919 "buffer mem offset 0x%X\n"
2920 "CTL 0x%X\n"
2921 "Length 0x%X\n"
2922 "next 0x%X\n"
2923 "Status 0x%X\n",
2925 txhostdesc,
2926 acx2cpu(txhostdesc->data_phy),
2927 txhostdesc->data_offset,
2928 le16_to_cpu(txhostdesc->Ctl_16),
2929 le16_to_cpu(txhostdesc->length),
2930 acx2cpu(txhostdesc->desc_phy_next),
2931 le32_to_cpu(txhostdesc->Status));
2932 txhostdesc++;
2935 /* write_reg16(adev, 0xb4, 0x4); */
2937 acx_unlock(adev, flags);
2938 end_ok:
2940 acx_sem_unlock(adev);
2941 #endif /* ACX_DEBUG */
2942 return OK;
2946 /***********************************************************************
2949 acx100pci_ioctl_set_phy_amp_bias(struct net_device *ndev,
2950 struct iw_request_info *info,
2951 struct iw_param *vwrq, char *extra)
2953 acx_device_t *adev = ndev2adev(ndev);
2954 unsigned long flags;
2955 u16 gpio_old;
2957 if (!IS_ACX100(adev)) {
2958 /* WARNING!!!
2959 * Removing this check *might* damage
2960 * hardware, since we're tweaking GPIOs here after all!!!
2961 * You've been warned...
2962 * WARNING!!! */
2963 printk("acx: sorry, setting bias level for non-acx100 "
2964 "is not supported yet\n");
2965 return OK;
2968 if (*extra > 7) {
2969 printk("acx: invalid bias parameter, range is 0-7\n");
2970 return -EINVAL;
2973 acx_sem_lock(adev);
2975 /* Need to lock accesses to [IO_ACX_GPIO_OUT]:
2976 * IRQ handler uses it to update LED */
2977 acx_lock(adev, flags);
2978 gpio_old = read_reg16(adev, IO_ACX_GPIO_OUT);
2979 write_reg16(adev, IO_ACX_GPIO_OUT,
2980 (gpio_old & 0xf8ff) | ((u16) * extra << 8));
2981 acx_unlock(adev, flags);
2983 log(L_DEBUG, "gpio_old: 0x%04X\n", gpio_old);
2984 printk("%s: PHY power amplifier bias: old:%d, new:%d\n",
2985 ndev->name, (gpio_old & 0x0700) >> 8, (unsigned char)*extra);
2987 acx_sem_unlock(adev);
2989 return OK;
2991 #endif
2993 /***************************************************************
2994 ** acxpci_l_alloc_tx
2995 ** Actually returns a txdesc_t* ptr
2997 ** FIXME: in case of fragments, should allocate multiple descrs
2998 ** after figuring out how many we need and whether we still have
2999 ** sufficiently many.
3001 tx_t *acxpci_l_alloc_tx(acx_device_t * adev)
3003 struct txdesc *txdesc;
3004 unsigned head;
3005 u8 ctl8;
3007 FN_ENTER;
3009 if (unlikely(!adev->tx_free)) {
3010 printk("acx: BUG: no free txdesc left\n");
3011 txdesc = NULL;
3012 goto end;
3015 head = adev->tx_head;
3016 txdesc = get_txdesc(adev, head);
3017 ctl8 = txdesc->Ctl_8;
3019 /* 2005-10-11: there were several bug reports on this happening
3020 ** but now cause seems to be understood & fixed */
3021 if (unlikely(DESC_CTL_HOSTOWN != (ctl8 & DESC_CTL_ACXDONE_HOSTOWN))) {
3022 /* whoops, descr at current index is not free, so probably
3023 * ring buffer already full */
3024 printk("acx: BUG: tx_head:%d Ctl8:0x%02X - failed to find "
3025 "free txdesc\n", head, ctl8);
3026 txdesc = NULL;
3027 goto end;
3030 /* Needed in case txdesc won't be eventually submitted for tx */
3031 txdesc->Ctl_8 = DESC_CTL_ACXDONE_HOSTOWN;
3033 adev->tx_free--;
3034 log(L_BUFT, "tx: got desc %u, %u remain\n", head, adev->tx_free);
3035 /* Keep a few free descs between head and tail of tx ring.
3036 ** It is not absolutely needed, just feels safer */
3037 if (adev->tx_free < TX_STOP_QUEUE) {
3038 log(L_BUF, "stop queue (%u tx desc left)\n", adev->tx_free);
3039 acx_stop_queue(adev->ieee, NULL);
3042 /* returning current descriptor, so advance to next free one */
3043 adev->tx_head = (head + 1) % TX_CNT;
3044 end:
3045 FN_EXIT0;
3047 return (tx_t *) txdesc;
3051 /***********************************************************************
3053 void *acxpci_l_get_txbuf(acx_device_t * adev, tx_t * tx_opaque)
3055 return get_txhostdesc(adev, (txdesc_t *) tx_opaque)->data;
3059 /***********************************************************************
3060 ** acxpci_l_tx_data
3062 ** Can be called from IRQ (rx -> (AP bridging or mgmt response) -> tx).
3063 ** Can be called from acx_i_start_xmit (data frames from net core).
3065 ** FIXME: in case of fragments, should loop over the number of
3066 ** pre-allocated tx descrs, properly setting up transfer data and
3067 ** CTL_xxx flags according to fragment number.
3069 void
3070 acxpci_l_tx_data(acx_device_t * adev, tx_t * tx_opaque, int len,
3071 struct ieee80211_tx_control *ieeectl,struct sk_buff* skb)
3073 txdesc_t *txdesc = (txdesc_t *) tx_opaque;
3074 struct ieee80211_hdr *wireless_header;
3075 txhostdesc_t *hostdesc1, *hostdesc2;
3076 int rate_cur;
3077 u8 Ctl_8, Ctl2_8;
3078 int wlhdr_len;
3080 FN_ENTER;
3082 /* fw doesn't tx such packets anyhow */
3083 /* if (unlikely(len < WLAN_HDR_A3_LEN))
3084 goto end;
3086 hostdesc1 = get_txhostdesc(adev, txdesc);
3087 wireless_header = (struct ieee80211_hdr *)hostdesc1->data;
3088 /* modify flag status in separate variable to be able to write it back
3089 * in one big swoop later (also in order to have less device memory
3090 * accesses) */
3091 Ctl_8 = txdesc->Ctl_8;
3092 Ctl2_8 = 0; /* really need to init it to 0, not txdesc->Ctl2_8, it seems */
3094 hostdesc2 = hostdesc1 + 1;
3096 /* DON'T simply set Ctl field to 0 here globally,
3097 * it needs to maintain a consistent flag status (those are state flags!!),
3098 * otherwise it may lead to severe disruption. Only set or reset particular
3099 * flags at the exact moment this is needed... */
3101 /* let chip do RTS/CTS handshaking before sending
3102 * in case packet size exceeds threshold */
3103 if (ieeectl->flags & IEEE80211_TXCTL_USE_RTS_CTS)
3104 SET_BIT(Ctl2_8, DESC_CTL2_RTS);
3105 else
3106 CLEAR_BIT(Ctl2_8, DESC_CTL2_RTS);
3108 rate_cur = ieeectl->tx_rate;
3109 if (unlikely(!rate_cur)) {
3110 printk("acx: driver bug! bad ratemask\n");
3111 goto end;
3114 /* used in tx cleanup routine for auto rate and accounting: */
3115 /* put_txcr(adev, txdesc, clt, rate_cur); deprecated by mac80211 */
3117 txdesc->total_length = cpu_to_le16(len);
3118 wlhdr_len = ieee80211_get_hdrlen(le16_to_cpu(wireless_header->frame_control));
3119 hostdesc2->length = cpu_to_le16(len - wlhdr_len);
3121 if (!ieeectl->do_not_encrypt && ieeectl->key_idx>= 0)
3123 u16 key_idx = (u16)(ieeectl->key_idx);
3124 struct acx_key* key = &(adev->key[key_idx]);
3125 int wlhdr_len;
3126 if (key->enabled)
3128 memcpy(ieeehdr->wep_iv, ((u8*)wireless_header) + wlhdr_len, 4);
3132 if (IS_ACX111(adev)) {
3133 /* note that if !txdesc->do_auto, txrate->cur
3134 ** has only one nonzero bit */
3135 txdesc->u.r2.rate111 = cpu_to_le16(rate_cur
3136 /* WARNING: I was never able to make it work with prism54 AP.
3137 ** It was falling down to 1Mbit where shortpre is not applicable,
3138 ** and not working at all at "5,11 basic rates only" setting.
3139 ** I even didn't see tx packets in radio packet capture.
3140 ** Disabled for now --vda */
3141 /*| ((clt->shortpre && clt->cur!=RATE111_1) ? RATE111_SHORTPRE : 0) */
3143 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3144 /* should add this to rate111 above as necessary */
3145 |(clt->pbcc511 ? RATE111_PBCC511 : 0)
3146 #endif
3147 hostdesc1->length = cpu_to_le16(len);
3148 } else { /* ACX100 */
3149 u8 rate_100 = ieeectl->tx_rate;
3150 txdesc->u.r1.rate = rate_100;
3151 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3152 if (clt->pbcc511) {
3153 if (n == RATE100_5 || n == RATE100_11)
3154 n |= RATE100_PBCC511;
3157 if (clt->shortpre && (clt->cur != RATE111_1))
3158 SET_BIT(Ctl_8, DESC_CTL_SHORT_PREAMBLE); /* set Short Preamble */
3159 #endif
3160 /* set autodma and reclaim and 1st mpdu */
3161 SET_BIT(Ctl_8,
3162 DESC_CTL_AUTODMA | DESC_CTL_RECLAIM |
3163 DESC_CTL_FIRSTFRAG);
3164 #if ACX_FRAGMENTATION
3165 /* SET_BIT(Ctl2_8, DESC_CTL2_MORE_FRAG); cannot set it unconditionally, needs to be set for all non-last fragments */
3166 #endif
3167 hostdesc1->length = cpu_to_le16(wlhdr_len);
3169 /* don't need to clean ack/rts statistics here, already
3170 * done on descr cleanup */
3172 /* clears HOSTOWN and ACXDONE bits, thus telling that the descriptors
3173 * are now owned by the acx100; do this as LAST operation */
3174 CLEAR_BIT(Ctl_8, DESC_CTL_ACXDONE_HOSTOWN);
3175 /* flush writes before we release hostdesc to the adapter here */
3176 wmb();
3177 CLEAR_BIT(hostdesc1->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3178 CLEAR_BIT(hostdesc2->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3180 /* write back modified flags */
3181 CLEAR_BIT(Ctl2_8, DESC_CTL2_WEP);
3182 txdesc->Ctl2_8 = Ctl2_8;
3183 txdesc->Ctl_8 = Ctl_8;
3184 /* unused: txdesc->tx_time = cpu_to_le32(jiffies); */
3186 /* flush writes before we tell the adapter that it's its turn now */
3187 write_reg16(adev, IO_ACX_INT_TRIG, INT_TRIG_TXPRC);
3188 write_flush(adev);
3189 /* log the packet content AFTER sending it,
3190 * in order to not delay sending any further than absolutely needed
3191 * Do separate logs for acx100/111 to have human-readable rates */
3192 memcpy(&(hostdesc1->txstatus.control),ieeectl,sizeof(struct ieee80211_tx_control));
3193 hostdesc1->skb = skb;
3194 end:
3195 FN_EXIT0;
3199 /***********************************************************************
3200 ** acxpci_l_clean_txdesc
3202 ** This function resets the txdescs' status when the ACX100
3203 ** signals the TX done IRQ (txdescs have been processed), starting with
3204 ** the pool index of the descriptor which we would use next,
3205 ** in order to make sure that we can be as fast as possible
3206 ** in filling new txdescs.
3207 ** Everytime we get called we know where the next packet to be cleaned is.
3210 #if !ACX_DEBUG
3211 static inline void log_txbuffer(const acx_device_t * adev)
3214 #else
3215 static void log_txbuffer(acx_device_t * adev)
3217 txdesc_t *txdesc;
3218 int i;
3220 /* no FN_ENTER here, we don't want that */
3221 /* no locks here, since it's entirely non-critical code */
3222 txdesc = adev->txdesc_start;
3223 if (unlikely(!txdesc))
3224 return;
3225 printk("tx: desc->Ctl8's:");
3226 for (i = 0; i < TX_CNT; i++) {
3227 printk(" %02X", txdesc->Ctl_8);
3228 txdesc = advance_txdesc(adev, txdesc, 1);
3230 printk("\n");
3232 #endif
3235 static void handle_tx_error(acx_device_t * adev, u8 error, unsigned int finger,
3236 struct ieee80211_tx_status *status)
3238 const char *err = "unknown error";
3240 /* hmm, should we handle this as a mask
3241 * of *several* bits?
3242 * For now I think only caring about
3243 * individual bits is ok... */
3244 switch (error) {
3245 case 0x01:
3246 err = "no Tx due to error in other fragment";
3247 /* adev->wstats.discard.fragment++; */
3248 break;
3249 case 0x02:
3250 err = "Tx aborted";
3251 adev->stats.tx_aborted_errors++;
3252 break;
3253 case 0x04:
3254 err = "Tx desc wrong parameters";
3255 /* adev->wstats.discard.misc++; */
3256 break;
3257 case 0x08:
3258 err = "WEP key not found";
3259 /* adev->wstats.discard.misc++; */
3260 break;
3261 case 0x10:
3262 err = "MSDU lifetime timeout? - try changing "
3263 "'iwconfig retry lifetime XXX'";
3264 /* adev->wstats.discard.misc++; */
3265 break;
3266 case 0x20:
3267 err = "excessive Tx retries due to either distance "
3268 "too high or unable to Tx or Tx frame error - "
3269 "try changing 'iwconfig txpower XXX' or "
3270 "'sens'itivity or 'retry'";
3271 /* adev->wstats.discard.retries++; */
3272 /* Tx error 0x20 also seems to occur on
3273 * overheating, so I'm not sure whether we
3274 * actually want to do aggressive radio recalibration,
3275 * since people maybe won't notice then that their hardware
3276 * is slowly getting cooked...
3277 * Or is it still a safe long distance from utter
3278 * radio non-functionality despite many radio recalibs
3279 * to final destructive overheating of the hardware?
3280 * In this case we really should do recalib here...
3281 * I guess the only way to find out is to do a
3282 * potentially fatal self-experiment :-\
3283 * Or maybe only recalib in case we're using Tx
3284 * rate auto (on errors switching to lower speed
3285 * --> less heat?) or 802.11 power save mode?
3287 * ok, just do it. */
3288 if (++adev->retry_errors_msg_ratelimit % 4 == 0) {
3289 if (adev->retry_errors_msg_ratelimit <= 20) {
3290 printk("%s: several excessive Tx "
3291 "retry errors occurred, attempting "
3292 "to recalibrate radio. Radio "
3293 "drift might be caused by increasing "
3294 "card temperature, please check the card "
3295 "before it's too late!\n",
3296 wiphy_name(adev->ieee->wiphy));
3297 if (adev->retry_errors_msg_ratelimit == 20)
3298 printk("disabling above message\n");
3301 acx_schedule_task(adev,
3302 ACX_AFTER_IRQ_CMD_RADIO_RECALIB);
3304 status->excessive_retries++;
3305 break;
3306 case 0x40:
3307 err = "Tx buffer overflow";
3308 adev->stats.tx_fifo_errors++;
3309 break;
3310 case 0x80:
3311 /* possibly ACPI C-state powersaving related!!!
3312 * (DMA timeout due to excessively high wakeup
3313 * latency after C-state activation!?)
3314 * Disable C-State powersaving and try again,
3315 * then PLEASE REPORT, I'm VERY interested in
3316 * whether my theory is correct that this is
3317 * actually the problem here.
3318 * In that case, use new Linux idle wakeup latency
3319 * requirements kernel API to prevent this issue. */
3320 err = "DMA error";
3321 /* adev->wstats.discard.misc++; */
3322 break;
3324 adev->stats.tx_errors++;
3325 if (adev->stats.tx_errors <= 20)
3326 printk("%s: tx error 0x%02X, buf %02u! (%s)\n",
3327 wiphy_name(adev->ieee->wiphy), error, finger, err);
3328 else
3329 printk("%s: tx error 0x%02X, buf %02u!\n",
3330 wiphy_name(adev->ieee->wiphy), error, finger);
3334 unsigned int acxpci_l_clean_txdesc(acx_device_t * adev)
3336 txdesc_t *txdesc;
3337 txhostdesc_t *hostdesc;
3338 unsigned finger;
3339 int num_cleaned;
3340 u16 r111;
3341 u8 error, ack_failures, rts_failures, rts_ok, r100;
3343 FN_ENTER;
3345 if (unlikely(acx_debug & L_DEBUG))
3346 log_txbuffer(adev);
3348 log(L_BUFT, "tx: cleaning up bufs from %u\n", adev->tx_tail);
3350 /* We know first descr which is not free yet. We advance it as far
3351 ** as we see correct bits set in following descs (if next desc
3352 ** is NOT free, we shouldn't advance at all). We know that in
3353 ** front of tx_tail may be "holes" with isolated free descs.
3354 ** We will catch up when all intermediate descs will be freed also */
3356 finger = adev->tx_tail;
3357 num_cleaned = 0;
3358 while (likely(finger != adev->tx_head)) {
3359 txdesc = get_txdesc(adev, finger);
3361 /* If we allocated txdesc on tx path but then decided
3362 ** to NOT use it, then it will be left as a free "bubble"
3363 ** in the "allocated for tx" part of the ring.
3364 ** We may meet it on the next ring pass here. */
3366 /* stop if not marked as "tx finished" and "host owned" */
3367 if ((txdesc->Ctl_8 & DESC_CTL_ACXDONE_HOSTOWN)
3368 != DESC_CTL_ACXDONE_HOSTOWN) {
3369 if (unlikely(!num_cleaned)) { /* maybe remove completely */
3370 log(L_BUFT, "clean_txdesc: tail isn't free. "
3371 "tail:%d head:%d\n",
3372 adev->tx_tail, adev->tx_head);
3374 break;
3377 /* remember desc values... */
3378 error = txdesc->error;
3379 ack_failures = txdesc->ack_failures;
3380 rts_failures = txdesc->rts_failures;
3381 rts_ok = txdesc->rts_ok;
3382 r100 = txdesc->u.r1.rate;
3383 r111 = le16_to_cpu(txdesc->u.r2.rate111);
3385 /* need to check for certain error conditions before we
3386 * clean the descriptor: we still need valid descr data here */
3387 hostdesc = get_txhostdesc(adev, txdesc);
3389 hostdesc->txstatus.flags |= IEEE80211_TX_STATUS_ACK;
3390 if (unlikely(0x30 & error)) {
3391 /* only send IWEVTXDROP in case of retry or lifetime exceeded;
3392 * all other errors mean we screwed up locally */
3393 /* union iwreq_data wrqu;
3394 struct ieee80211_hdr_3addr *hdr;
3395 hdr = (struct ieee80211_hdr_3addr *) hostdesc->data;
3396 MAC_COPY(wrqu.addr.sa_data, hdr->addr1);
3398 hostdesc->txstatus.flags &= ~IEEE80211_TX_STATUS_ACK;
3401 /* ...and free the desc */
3402 txdesc->error = 0;
3403 txdesc->ack_failures = 0;
3404 txdesc->rts_failures = 0;
3405 txdesc->rts_ok = 0;
3406 /* signal host owning it LAST, since ACX already knows that this
3407 ** descriptor is finished since it set Ctl_8 accordingly. */
3408 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3410 adev->tx_free++;
3411 num_cleaned++;
3413 if ((adev->tx_free >= TX_START_QUEUE)
3414 /* && (adev->status == ACX_STATUS_4_ASSOCIATED) */
3415 /*&& (acx_queue_stopped(adev->ieee))*/
3417 log(L_BUF, "tx: wake queue (avail. Tx desc %u)\n",
3418 adev->tx_free);
3419 acx_wake_queue(adev->ieee, NULL);
3422 /* do error checking, rate handling and logging
3423 * AFTER having done the work, it's faster */
3425 /* Rate handling is done in mac80211 */
3426 /* if (adev->rate_auto) {
3427 struct client *clt = get_txc(adev, txdesc);
3428 if (clt) {
3429 u16 cur = get_txr(adev, txdesc);
3430 if (clt->rate_cur == cur) {
3431 acx_l_handle_txrate_auto(adev, clt, cur,*/ /* intended rate */
3432 /*r100, r111,*/ /* actually used rate */
3433 /*(error & 0x30),*/ /* was there an error? */
3434 /* TX_CNT +
3435 TX_CLEAN_BACKLOG
3437 adev->tx_free);
3442 if (unlikely(error))
3443 handle_tx_error(adev, error, finger, &hostdesc->txstatus);
3445 if (IS_ACX111(adev))
3446 log(L_BUFT,
3447 "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u r111=%04X tx_free=%u\n",
3448 finger, ack_failures, rts_failures, rts_ok, r111, adev->tx_free);
3449 else
3450 log(L_BUFT,
3451 "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u rate=%u\n",
3452 finger, ack_failures, rts_failures, rts_ok, r100);
3454 /* And finally report upstream */
3455 if (hostdesc)
3457 hostdesc->txstatus.excessive_retries = rts_failures ;
3458 hostdesc->txstatus.retry_count = ack_failures;
3459 ieee80211_tx_status(adev->ieee,hostdesc->skb,&hostdesc->txstatus);
3460 memset(&hostdesc->txstatus, 0, sizeof(struct ieee80211_tx_status));
3462 /* update pointer for descr to be cleaned next */
3463 finger = (finger + 1) % TX_CNT;
3465 /* remember last position */
3466 adev->tx_tail = finger;
3467 /* end: */
3468 FN_EXIT1(num_cleaned);
3469 return num_cleaned;
3472 /* clean *all* Tx descriptors, and regardless of their previous state.
3473 * Used for brute-force reset handling. */
3474 void acxpci_l_clean_txdesc_emergency(acx_device_t * adev)
3476 txdesc_t *txdesc;
3477 int i;
3479 FN_ENTER;
3481 for (i = 0; i < TX_CNT; i++) {
3482 txdesc = get_txdesc(adev, i);
3484 /* free it */
3485 txdesc->ack_failures = 0;
3486 txdesc->rts_failures = 0;
3487 txdesc->rts_ok = 0;
3488 txdesc->error = 0;
3489 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3492 adev->tx_free = TX_CNT;
3494 FN_EXIT0;
3498 /***********************************************************************
3499 ** acxpci_s_create_tx_host_desc_queue
3502 static void *allocate(acx_device_t * adev, size_t size, dma_addr_t * phy,
3503 const char *msg)
3505 void *ptr;
3507 ptr = dma_alloc_coherent(adev->bus_dev, size, phy, GFP_KERNEL);
3509 if (ptr) {
3510 log(L_DEBUG, "%s sz=%d adr=0x%p phy=0x%08llx\n",
3511 msg, (int)size, ptr, (unsigned long long)*phy);
3512 memset(ptr, 0, size);
3513 return ptr;
3515 printk(KERN_ERR "acx: %s allocation FAILED (%d bytes)\n",
3516 msg, (int)size);
3517 return NULL;
3521 static int acxpci_s_create_tx_host_desc_queue(acx_device_t * adev)
3523 txhostdesc_t *hostdesc;
3524 u8 *txbuf;
3525 dma_addr_t hostdesc_phy;
3526 dma_addr_t txbuf_phy;
3527 int i;
3529 FN_ENTER;
3531 /* allocate TX buffer */
3532 adev->txbuf_area_size = TX_CNT * /*WLAN_A4FR_MAXLEN_WEP_FCS*/ (30 + 2312 + 4);
3533 adev->txbuf_start = allocate(adev, adev->txbuf_area_size,
3534 &adev->txbuf_startphy, "txbuf_start");
3535 if (!adev->txbuf_start)
3536 goto fail;
3538 /* allocate the TX host descriptor queue pool */
3539 adev->txhostdesc_area_size = TX_CNT * 2 * sizeof(*hostdesc);
3540 adev->txhostdesc_start = allocate(adev, adev->txhostdesc_area_size,
3541 &adev->txhostdesc_startphy,
3542 "txhostdesc_start");
3543 if (!adev->txhostdesc_start)
3544 goto fail;
3545 /* check for proper alignment of TX host descriptor pool */
3546 if ((long)adev->txhostdesc_start & 3) {
3547 printk
3548 ("acx: driver bug: dma alloc returns unaligned address\n");
3549 goto fail;
3552 hostdesc = adev->txhostdesc_start;
3553 hostdesc_phy = adev->txhostdesc_startphy;
3554 txbuf = adev->txbuf_start;
3555 txbuf_phy = adev->txbuf_startphy;
3557 #if 0
3558 /* Each tx buffer is accessed by hardware via
3559 ** txdesc -> txhostdesc(s) -> txbuffer(s).
3560 ** We use only one txhostdesc per txdesc, but it looks like
3561 ** acx111 is buggy: it accesses second txhostdesc
3562 ** (via hostdesc.desc_phy_next field) even if
3563 ** txdesc->length == hostdesc->length and thus
3564 ** entire packet was placed into first txhostdesc.
3565 ** Due to this bug acx111 hangs unless second txhostdesc
3566 ** has le16_to_cpu(hostdesc.length) = 3 (or larger)
3567 ** Storing NULL into hostdesc.desc_phy_next
3568 ** doesn't seem to help.
3570 ** Update: although it worked on Xterasys XN-2522g
3571 ** with len=3 trick, WG311v2 is even more bogus, doesn't work.
3572 ** Keeping this code (#ifdef'ed out) for documentational purposes.
3574 for (i = 0; i < TX_CNT * 2; i++) {
3575 hostdesc_phy += sizeof(*hostdesc);
3576 if (!(i & 1)) {
3577 hostdesc->data_phy = cpu2acx(txbuf_phy);
3578 /* hostdesc->data_offset = ... */
3579 /* hostdesc->reserved = ... */
3580 hostdesc->Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
3581 /* hostdesc->length = ... */
3582 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3583 hostdesc->pNext = ptr2acx(NULL);
3584 /* hostdesc->Status = ... */
3585 /* below: non-hardware fields */
3586 hostdesc->data = txbuf;
3588 txbuf += WLAN_A4FR_MAXLEN_WEP_FCS;
3589 txbuf_phy += WLAN_A4FR_MAXLEN_WEP_FCS;
3590 } else {
3591 /* hostdesc->data_phy = ... */
3592 /* hostdesc->data_offset = ... */
3593 /* hostdesc->reserved = ... */
3594 /* hostdesc->Ctl_16 = ... */
3595 hostdesc->length = cpu_to_le16(3); /* bug workaround */
3596 /* hostdesc->desc_phy_next = ... */
3597 /* hostdesc->pNext = ... */
3598 /* hostdesc->Status = ... */
3599 /* below: non-hardware fields */
3600 /* hostdesc->data = ... */
3602 hostdesc++;
3604 #endif
3605 /* We initialize two hostdescs so that they point to adjacent
3606 ** memory areas. Thus txbuf is really just a contiguous memory area */
3607 for (i = 0; i < TX_CNT * 2; i++) {
3608 hostdesc_phy += sizeof(*hostdesc);
3610 hostdesc->data_phy = cpu2acx(txbuf_phy);
3611 /* done by memset(0): hostdesc->data_offset = 0; */
3612 /* hostdesc->reserved = ... */
3613 hostdesc->Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
3614 /* hostdesc->length = ... */
3615 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3616 /* done by memset(0): hostdesc->pNext = ptr2acx(NULL); */
3617 /* hostdesc->Status = ... */
3618 /* ->data is a non-hardware field: */
3619 hostdesc->data = txbuf;
3621 if (!(i & 1)) {
3622 txbuf += 24 /*WLAN_HDR_A3_LEN*/;
3623 txbuf_phy += 24 /*WLAN_HDR_A3_LEN*/;
3624 } else {
3625 txbuf += 30 + 2132 + 4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3626 txbuf_phy += 30 + 2132 +4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3628 hostdesc++;
3630 hostdesc--;
3631 hostdesc->desc_phy_next = cpu2acx(adev->txhostdesc_startphy);
3633 FN_EXIT1(OK);
3634 return OK;
3635 fail:
3636 printk("acx: create_tx_host_desc_queue FAILED\n");
3637 /* dealloc will be done by free function on error case */
3638 FN_EXIT1(NOT_OK);
3639 return NOT_OK;
3643 /***************************************************************
3644 ** acxpci_s_create_rx_host_desc_queue
3646 /* the whole size of a data buffer (header plus data body)
3647 * plus 32 bytes safety offset at the end */
3648 #define RX_BUFFER_SIZE (sizeof(rxbuffer_t) + 32)
3650 static int acxpci_s_create_rx_host_desc_queue(acx_device_t * adev)
3652 rxhostdesc_t *hostdesc;
3653 rxbuffer_t *rxbuf;
3654 dma_addr_t hostdesc_phy;
3655 dma_addr_t rxbuf_phy;
3656 int i;
3658 FN_ENTER;
3660 /* allocate the RX host descriptor queue pool */
3661 adev->rxhostdesc_area_size = RX_CNT * sizeof(*hostdesc);
3662 adev->rxhostdesc_start = allocate(adev, adev->rxhostdesc_area_size,
3663 &adev->rxhostdesc_startphy,
3664 "rxhostdesc_start");
3665 if (!adev->rxhostdesc_start)
3666 goto fail;
3667 /* check for proper alignment of RX host descriptor pool */
3668 if ((long)adev->rxhostdesc_start & 3) {
3669 printk
3670 ("acx: driver bug: dma alloc returns unaligned address\n");
3671 goto fail;
3674 /* allocate Rx buffer pool which will be used by the acx
3675 * to store the whole content of the received frames in it */
3676 adev->rxbuf_area_size = RX_CNT * RX_BUFFER_SIZE;
3677 adev->rxbuf_start = allocate(adev, adev->rxbuf_area_size,
3678 &adev->rxbuf_startphy, "rxbuf_start");
3679 if (!adev->rxbuf_start)
3680 goto fail;
3682 rxbuf = adev->rxbuf_start;
3683 rxbuf_phy = adev->rxbuf_startphy;
3684 hostdesc = adev->rxhostdesc_start;
3685 hostdesc_phy = adev->rxhostdesc_startphy;
3687 /* don't make any popular C programming pointer arithmetic mistakes
3688 * here, otherwise I'll kill you...
3689 * (and don't dare asking me why I'm warning you about that...) */
3690 for (i = 0; i < RX_CNT; i++) {
3691 hostdesc->data = rxbuf;
3692 hostdesc->data_phy = cpu2acx(rxbuf_phy);
3693 hostdesc->length = cpu_to_le16(RX_BUFFER_SIZE);
3694 CLEAR_BIT(hostdesc->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3695 rxbuf++;
3696 rxbuf_phy += sizeof(*rxbuf);
3697 hostdesc_phy += sizeof(*hostdesc);
3698 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3699 hostdesc++;
3701 hostdesc--;
3702 hostdesc->desc_phy_next = cpu2acx(adev->rxhostdesc_startphy);
3703 FN_EXIT1(OK);
3704 return OK;
3705 fail:
3706 printk("acx: create_rx_host_desc_queue FAILED\n");
3707 /* dealloc will be done by free function on error case */
3708 FN_EXIT1(NOT_OK);
3709 return NOT_OK;
3713 /***************************************************************
3714 ** acxpci_s_create_hostdesc_queues
3716 int acxpci_s_create_hostdesc_queues(acx_device_t * adev)
3718 int result;
3719 result = acxpci_s_create_tx_host_desc_queue(adev);
3720 if (OK != result)
3721 return result;
3722 result = acxpci_s_create_rx_host_desc_queue(adev);
3723 return result;
3727 /***************************************************************
3728 ** acxpci_create_tx_desc_queue
3730 static void acxpci_create_tx_desc_queue(acx_device_t * adev, u32 tx_queue_start)
3732 txdesc_t *txdesc;
3733 txhostdesc_t *hostdesc;
3734 dma_addr_t hostmemptr;
3735 u32 mem_offs;
3736 int i;
3738 FN_ENTER;
3740 if (IS_ACX100(adev))
3741 adev->txdesc_size = sizeof(*txdesc);
3742 else
3743 /* the acx111 txdesc is 4 bytes larger */
3744 adev->txdesc_size = sizeof(*txdesc) + 4;
3746 adev->txdesc_start = (txdesc_t *) (adev->iobase2 + tx_queue_start);
3748 log(L_DEBUG, "adev->iobase2=%p\n"
3749 "tx_queue_start=%08X\n"
3750 "adev->txdesc_start=%p\n",
3751 adev->iobase2, tx_queue_start, adev->txdesc_start);
3753 adev->tx_free = TX_CNT;
3754 /* done by memset: adev->tx_head = 0; */
3755 /* done by memset: adev->tx_tail = 0; */
3756 txdesc = adev->txdesc_start;
3757 mem_offs = tx_queue_start;
3758 hostmemptr = adev->txhostdesc_startphy;
3759 hostdesc = adev->txhostdesc_start;
3761 if (IS_ACX111(adev)) {
3762 /* ACX111 has a preinitialized Tx buffer! */
3763 /* loop over whole send pool */
3764 /* FIXME: do we have to do the hostmemptr stuff here?? */
3765 for (i = 0; i < TX_CNT; i++) {
3766 txdesc->HostMemPtr = ptr2acx(hostmemptr);
3767 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3768 /* reserve two (hdr desc and payload desc) */
3769 hostdesc += 2;
3770 hostmemptr += 2 * sizeof(*hostdesc);
3771 txdesc = advance_txdesc(adev, txdesc, 1);
3773 } else {
3774 /* ACX100 Tx buffer needs to be initialized by us */
3775 /* clear whole send pool. sizeof is safe here (we are acx100) */
3776 memset(adev->txdesc_start, 0, TX_CNT * sizeof(*txdesc));
3778 /* loop over whole send pool */
3779 for (i = 0; i < TX_CNT; i++) {
3780 log(L_DEBUG, "configure card tx descriptor: 0x%p, "
3781 "size: 0x%X\n", txdesc, adev->txdesc_size);
3783 /* pointer to hostdesc memory */
3784 txdesc->HostMemPtr = ptr2acx(hostmemptr);
3785 /* initialise ctl */
3786 txdesc->Ctl_8 = (DESC_CTL_HOSTOWN | DESC_CTL_RECLAIM
3787 | DESC_CTL_AUTODMA |
3788 DESC_CTL_FIRSTFRAG);
3789 /* done by memset(0): txdesc->Ctl2_8 = 0; */
3790 /* point to next txdesc */
3791 txdesc->pNextDesc =
3792 cpu2acx(mem_offs + adev->txdesc_size);
3793 /* reserve two (hdr desc and payload desc) */
3794 hostdesc += 2;
3795 hostmemptr += 2 * sizeof(*hostdesc);
3796 /* go to the next one */
3797 mem_offs += adev->txdesc_size;
3798 /* ++ is safe here (we are acx100) */
3799 txdesc++;
3801 /* go back to the last one */
3802 txdesc--;
3803 /* and point to the first making it a ring buffer */
3804 txdesc->pNextDesc = cpu2acx(tx_queue_start);
3806 FN_EXIT0;
3810 /***************************************************************
3811 ** acxpci_create_rx_desc_queue
3813 static void acxpci_create_rx_desc_queue(acx_device_t * adev, u32 rx_queue_start)
3815 rxdesc_t *rxdesc;
3816 u32 mem_offs;
3817 int i;
3819 FN_ENTER;
3821 /* done by memset: adev->rx_tail = 0; */
3823 /* ACX111 doesn't need any further config: preconfigures itself.
3824 * Simply print ring buffer for debugging */
3825 if (IS_ACX111(adev)) {
3826 /* rxdesc_start already set here */
3828 adev->rxdesc_start =
3829 (rxdesc_t *) ((u8 *) adev->iobase2 + rx_queue_start);
3831 rxdesc = adev->rxdesc_start;
3832 for (i = 0; i < RX_CNT; i++) {
3833 log(L_DEBUG, "rx descriptor %d @ 0x%p\n", i, rxdesc);
3834 rxdesc = adev->rxdesc_start = (rxdesc_t *)
3835 (adev->iobase2 + acx2cpu(rxdesc->pNextDesc));
3837 } else {
3838 /* we didn't pre-calculate rxdesc_start in case of ACX100 */
3839 /* rxdesc_start should be right AFTER Tx pool */
3840 adev->rxdesc_start = (rxdesc_t *)
3841 ((u8 *) adev->txdesc_start + (TX_CNT * sizeof(txdesc_t)));
3842 /* NB: sizeof(txdesc_t) above is valid because we know
3843 ** we are in if (acx100) block. Beware of cut-n-pasting elsewhere!
3844 ** acx111's txdesc is larger! */
3846 memset(adev->rxdesc_start, 0, RX_CNT * sizeof(*rxdesc));
3848 /* loop over whole receive pool */
3849 rxdesc = adev->rxdesc_start;
3850 mem_offs = rx_queue_start;
3851 for (i = 0; i < RX_CNT; i++) {
3852 log(L_DEBUG, "rx descriptor @ 0x%p\n", rxdesc);
3853 rxdesc->Ctl_8 = DESC_CTL_RECLAIM | DESC_CTL_AUTODMA;
3854 /* point to next rxdesc */
3855 rxdesc->pNextDesc = cpu2acx(mem_offs + sizeof(*rxdesc));
3856 /* go to the next one */
3857 mem_offs += sizeof(*rxdesc);
3858 rxdesc++;
3860 /* go to the last one */
3861 rxdesc--;
3863 /* and point to the first making it a ring buffer */
3864 rxdesc->pNextDesc = cpu2acx(rx_queue_start);
3866 FN_EXIT0;
3870 /***************************************************************
3871 ** acxpci_create_desc_queues
3873 void
3874 acxpci_create_desc_queues(acx_device_t * adev, u32 tx_queue_start,
3875 u32 rx_queue_start)
3877 acxpci_create_tx_desc_queue(adev, tx_queue_start);
3878 acxpci_create_rx_desc_queue(adev, rx_queue_start);
3882 /***************************************************************
3883 ** acxpci_s_proc_diag_output
3885 char *acxpci_s_proc_diag_output(char *p, acx_device_t * adev)
3887 const char *rtl, *thd, *ttl;
3888 rxhostdesc_t *rxhostdesc;
3889 txdesc_t *txdesc;
3890 int i;
3892 FN_ENTER;
3894 p += sprintf(p, "** Rx buf **\n");
3895 rxhostdesc = adev->rxhostdesc_start;
3896 if (rxhostdesc)
3897 for (i = 0; i < RX_CNT; i++) {
3898 rtl = (i == adev->rx_tail) ? " [tail]" : "";
3899 if ((rxhostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
3900 && (rxhostdesc->
3901 Status & cpu_to_le32(DESC_STATUS_FULL)))
3902 p += sprintf(p, "%02u FULL%s\n", i, rtl);
3903 else
3904 p += sprintf(p, "%02u empty%s\n", i, rtl);
3905 rxhostdesc++;
3907 /* p += sprintf(p, "** Tx buf (free %d, Linux netqueue %s) **\n",
3908 adev->tx_free,
3909 acx_queue_stopped(adev->ieee) ? "STOPPED" : "running");*/
3910 txdesc = adev->txdesc_start;
3911 if (txdesc)
3912 for (i = 0; i < TX_CNT; i++) {
3913 thd = (i == adev->tx_head) ? " [head]" : "";
3914 ttl = (i == adev->tx_tail) ? " [tail]" : "";
3915 if (txdesc->Ctl_8 & DESC_CTL_ACXDONE)
3916 p += sprintf(p, "%02u free (%02X)%s%s\n", i,
3917 txdesc->Ctl_8, thd, ttl);
3918 else
3919 p += sprintf(p, "%02u tx (%02X)%s%s\n", i,
3920 txdesc->Ctl_8, thd, ttl);
3921 txdesc = advance_txdesc(adev, txdesc, 1);
3923 p += sprintf(p,
3924 "\n"
3925 "** PCI data **\n"
3926 "txbuf_start %p, txbuf_area_size %u, txbuf_startphy %08llx\n"
3927 "txdesc_size %u, txdesc_start %p\n"
3928 "txhostdesc_start %p, txhostdesc_area_size %u, txhostdesc_startphy %08llx\n"
3929 "rxdesc_start %p\n"
3930 "rxhostdesc_start %p, rxhostdesc_area_size %u, rxhostdesc_startphy %08llx\n"
3931 "rxbuf_start %p, rxbuf_area_size %u, rxbuf_startphy %08llx\n",
3932 adev->txbuf_start, adev->txbuf_area_size,
3933 (unsigned long long)adev->txbuf_startphy,
3934 adev->txdesc_size, adev->txdesc_start,
3935 adev->txhostdesc_start, adev->txhostdesc_area_size,
3936 (unsigned long long)adev->txhostdesc_startphy,
3937 adev->rxdesc_start,
3938 adev->rxhostdesc_start, adev->rxhostdesc_area_size,
3939 (unsigned long long)adev->rxhostdesc_startphy,
3940 adev->rxbuf_start, adev->rxbuf_area_size,
3941 (unsigned long long)adev->rxbuf_startphy);
3943 FN_EXIT0;
3944 return p;
3948 /***********************************************************************
3950 int acxpci_proc_eeprom_output(char *buf, acx_device_t * adev)
3952 char *p = buf;
3953 int i;
3955 FN_ENTER;
3957 for (i = 0; i < 0x400; i++) {
3958 acxpci_read_eeprom_byte(adev, i, p++);
3961 FN_EXIT1(p - buf);
3962 return p - buf;
3966 /***********************************************************************
3967 ** Obvious
3969 void acxpci_set_interrupt_mask(acx_device_t * adev)
3971 if (IS_ACX111(adev)) {
3972 adev->irq_mask = (u16) ~ (0
3973 /* | HOST_INT_RX_DATA */
3974 | HOST_INT_TX_COMPLETE
3975 /* | HOST_INT_TX_XFER */
3976 | HOST_INT_RX_COMPLETE
3977 /* | HOST_INT_DTIM */
3978 /* | HOST_INT_BEACON */
3979 /* | HOST_INT_TIMER */
3980 /* | HOST_INT_KEY_NOT_FOUND */
3981 | HOST_INT_IV_ICV_FAILURE
3982 | HOST_INT_CMD_COMPLETE
3983 | HOST_INT_INFO
3984 /* | HOST_INT_OVERFLOW */
3985 /* | HOST_INT_PROCESS_ERROR */
3986 | HOST_INT_SCAN_COMPLETE
3987 | HOST_INT_FCS_THRESHOLD
3988 /* | HOST_INT_UNKNOWN */
3990 /* Or else acx100 won't signal cmd completion, right? */
3991 adev->irq_mask_off = (u16) ~ (HOST_INT_CMD_COMPLETE); /* 0xfdff */
3992 } else {
3993 adev->irq_mask = (u16) ~ (0
3994 /* | HOST_INT_RX_DATA */
3995 | HOST_INT_TX_COMPLETE
3996 /* | HOST_INT_TX_XFER */
3997 | HOST_INT_RX_COMPLETE
3998 /* | HOST_INT_DTIM */
3999 /* | HOST_INT_BEACON */
4000 /* | HOST_INT_TIMER */
4001 /* | HOST_INT_KEY_NOT_FOUND */
4002 /* | HOST_INT_IV_ICV_FAILURE */
4003 | HOST_INT_CMD_COMPLETE
4004 | HOST_INT_INFO
4005 /* | HOST_INT_OVERFLOW */
4006 /* | HOST_INT_PROCESS_ERROR */
4007 | HOST_INT_SCAN_COMPLETE
4008 /* | HOST_INT_FCS_THRESHOLD */
4009 /* | HOST_INT_UNKNOWN */
4011 adev->irq_mask_off = (u16) ~ (HOST_INT_UNKNOWN); /* 0x7fff */
4016 /***********************************************************************
4018 int acx100pci_s_set_tx_level(acx_device_t * adev, u8 level_dbm)
4020 /* since it can be assumed that at least the Maxim radio has a
4021 * maximum power output of 20dBm and since it also can be
4022 * assumed that these values drive the DAC responsible for
4023 * setting the linear Tx level, I'd guess that these values
4024 * should be the corresponding linear values for a dBm value,
4025 * in other words: calculate the values from that formula:
4026 * Y [dBm] = 10 * log (X [mW])
4027 * then scale the 0..63 value range onto the 1..100mW range (0..20 dBm)
4028 * and you're done...
4029 * Hopefully that's ok, but you never know if we're actually
4030 * right... (especially since Windows XP doesn't seem to show
4031 * actual Tx dBm values :-P) */
4033 /* NOTE: on Maxim, value 30 IS 30mW, and value 10 IS 10mW - so the
4034 * values are EXACTLY mW!!! Not sure about RFMD and others,
4035 * though... */
4036 static const u8 dbm2val_maxim[21] = {
4037 63, 63, 63, 62,
4038 61, 61, 60, 60,
4039 59, 58, 57, 55,
4040 53, 50, 47, 43,
4041 38, 31, 23, 13,
4044 static const u8 dbm2val_rfmd[21] = {
4045 0, 0, 0, 1,
4046 2, 2, 3, 3,
4047 4, 5, 6, 8,
4048 10, 13, 16, 20,
4049 25, 32, 41, 50,
4052 const u8 *table;
4054 switch (adev->radio_type) {
4055 case RADIO_MAXIM_0D:
4056 table = &dbm2val_maxim[0];
4057 break;
4058 case RADIO_RFMD_11:
4059 case RADIO_RALINK_15:
4060 table = &dbm2val_rfmd[0];
4061 break;
4062 default:
4063 printk("%s: unknown/unsupported radio type, "
4064 "cannot modify tx power level yet!\n", wiphy_name(adev->ieee->wiphy));
4065 return NOT_OK;
4067 printk("%s: changing radio power level to %u dBm (%u)\n",
4068 wiphy_name(adev->ieee->wiphy), level_dbm, table[level_dbm]);
4069 acxpci_s_write_phy_reg(adev, 0x11, table[level_dbm]);
4070 return OK;
4073 #ifdef CONFIG_VLYNQ
4074 struct vlynq_reg_config {
4075 u32 offset;
4076 u32 value;
4079 struct vlynq_known {
4080 u32 chip_id;
4081 char name[32];
4082 struct vlynq_mapping rx_mapping[4];
4083 int irq;
4084 int irq_type;
4085 int num_regs;
4086 struct vlynq_reg_config regs[10];
4089 #define CHIP_TNETW1130 0x00000009
4090 #define CHIP_TNETW1350 0x00000029
4092 static struct vlynq_known known_devices[] = {
4094 .chip_id = CHIP_TNETW1130, .name = "TI TNETW1130",
4095 .rx_mapping = {
4096 { .size = 0x22000, .offset = 0xf0000000 },
4097 { .size = 0x40000, .offset = 0xc0000000 },
4098 { .size = 0x0, .offset = 0x0 },
4099 { .size = 0x0, .offset = 0x0 },
4101 .irq = 0,
4102 .irq_type = IRQ_TYPE_EDGE_RISING,
4103 .num_regs = 5,
4104 .regs = {
4106 .offset = 0x790,
4107 .value = (0xd0000000 - PHYS_OFFSET)
4110 .offset = 0x794,
4111 .value = (0xd0000000 - PHYS_OFFSET)
4113 { .offset = 0x740, .value = 0 },
4114 { .offset = 0x744, .value = 0x00010000 },
4115 { .offset = 0x764, .value = 0x00010000 },
4119 .chip_id = CHIP_TNETW1350, .name = "TI TNETW1350",
4120 .rx_mapping = {
4121 { .size = 0x100000, .offset = 0x00300000 },
4122 { .size = 0x80000, .offset = 0x00000000 },
4123 { .size = 0x0, .offset = 0x0 },
4124 { .size = 0x0, .offset = 0x0 },
4126 .irq = 0,
4127 .irq_type = IRQ_TYPE_EDGE_RISING,
4128 .num_regs = 5,
4129 .regs = {
4131 .offset = 0x790,
4132 .value = (0x60000000 - PHYS_OFFSET)
4135 .offset = 0x794,
4136 .value = (0x60000000 - PHYS_OFFSET)
4138 { .offset = 0x740, .value = 0 },
4139 { .offset = 0x744, .value = 0x00010000 },
4140 { .offset = 0x764, .value = 0x00010000 },
4145 static struct vlynq_device_id acx_vlynq_id[] = {
4146 { CHIP_TNETW1130, vlynq_div_auto, 0 },
4147 { CHIP_TNETW1350, vlynq_div_auto, 1 },
4148 { 0, 0, 0 },
4151 static __devinit int vlynq_probe(struct vlynq_device *vdev,
4152 struct vlynq_device_id *id)
4154 int result = -EIO, i;
4155 u32 addr;
4156 struct ieee80211_hw *ieee;
4157 acx_device_t *adev = NULL;
4158 acx111_ie_configoption_t co;
4159 struct vlynq_mapping mapping[4] = { { 0, }, };
4160 struct vlynq_known *match = NULL;
4162 FN_ENTER;
4163 result = vlynq_enable_device(vdev);
4164 if (result)
4165 return result;
4167 match = &known_devices[id->driver_data];
4169 if (!match) {
4170 result = -ENODEV;
4171 goto fail;
4174 mapping[0].offset = ARCH_PFN_OFFSET << PAGE_SHIFT;
4175 mapping[0].size = 0x02000000;
4176 vlynq_set_local_mapping(vdev, vdev->mem_start, mapping);
4177 vlynq_set_remote_mapping(vdev, 0, match->rx_mapping);
4179 set_irq_type(vlynq_virq_to_irq(vdev, match->irq), match->irq_type);
4181 addr = (u32)ioremap(vdev->mem_start, 0x1000);
4182 if (!addr) {
4183 printk(KERN_ERR "%s: failed to remap io memory\n",
4184 vdev->dev.bus_id);
4185 result = -ENXIO;
4186 goto fail;
4189 for (i = 0; i < match->num_regs; i++)
4190 iowrite32(match->regs[i].value,
4191 (u32 *)(addr + match->regs[i].offset));
4193 iounmap((void *)addr);
4195 ieee = ieee80211_alloc_hw(sizeof(struct acx_device), &acxpci_hw_ops);
4196 if (!ieee) {
4197 printk("acx: could not allocate ieee80211 structure %s\n",
4198 vdev->dev.bus_id);
4199 goto fail_alloc_netdev;
4201 ieee->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
4202 ieee->queues = 1;
4204 adev = ieee2adev(ieee);
4206 memset(adev, 0, sizeof(*adev));
4207 /** Set up our private interface **/
4208 spin_lock_init(&adev->spinlock); /* initial state: unlocked */
4209 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
4210 mutex_init(&adev->mutex);
4211 /* since nobody can see new netdev yet, we can as well
4212 ** just _presume_ that we're under sem (instead of actually taking it): */
4213 /* acx_sem_lock(adev); */
4214 adev->ieee = ieee;
4215 adev->vdev = vdev;
4216 adev->bus_dev = &vdev->dev;
4217 adev->dev_type = DEVTYPE_PCI;
4219 /** Finished with private interface **/
4221 vlynq_set_drvdata(vdev, ieee);
4222 if (!request_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start, "acx")) {
4223 printk("acx: cannot reserve VLYNQ memory region\n");
4224 goto fail_request_mem_region;
4226 adev->iobase = ioremap(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4227 if (!adev->iobase) {
4228 printk("acx: ioremap() FAILED\n");
4229 goto fail_ioremap;
4231 adev->iobase2 = adev->iobase + match->rx_mapping[0].size;
4232 adev->chip_type = CHIPTYPE_ACX111;
4233 adev->chip_name = match->name;
4234 adev->io = IO_ACX111;
4235 adev->irq = vlynq_virq_to_irq(vdev, match->irq);
4237 printk("acx: found %s-based wireless network card at %s, irq:%d, "
4238 "phymem:0x%x, mem:0x%p\n",
4239 match->name, vdev->dev.bus_id, adev->irq,
4240 vdev->mem_start, adev->iobase);
4241 log(L_ANY, "initial debug setting is 0x%04X\n", acx_debug);
4243 if (0 == adev->irq) {
4244 printk("acx: can't use IRQ 0\n");
4245 goto fail_irq;
4247 SET_IEEE80211_DEV(ieee, &vdev->dev);
4250 /* to find crashes due to weird driver access
4251 * to unconfigured interface (ifup) */
4252 adev->mgmt_timer.function = (void (*)(unsigned long))0x0000dead;
4255 /* ok, pci setup is finished, now start initializing the card */
4257 /* NB: read_reg() reads may return bogus data before reset_dev(),
4258 * since the firmware which directly controls large parts of the I/O
4259 * registers isn't initialized yet.
4260 * acx100 seems to be more affected than acx111 */
4261 if (OK != acxpci_s_reset_dev(adev))
4262 goto fail_reset;
4264 if (OK != acx_s_init_mac(adev))
4265 goto fail_init_mac;
4267 acx_s_interrogate(adev, &co, ACX111_IE_CONFIG_OPTIONS);
4268 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
4269 if (OK != acxpci_read_eeprom_byte(adev, 0x05, &adev->eeprom_version))
4270 goto fail_read_eeprom_version;
4272 acx_s_parse_configoption(adev, &co);
4273 acx_s_set_defaults(adev);
4274 acx_s_get_firmware_version(adev); /* needs to be after acx_s_init_mac() */
4275 acx_display_hardware_details(adev);
4277 /* Register the card, AFTER everything else has been set up,
4278 * since otherwise an ioctl could step on our feet due to
4279 * firmware operations happening in parallel or uninitialized data */
4282 acx_proc_register_entries(ieee);
4284 /* Now we have our device, so make sure the kernel doesn't try
4285 * to send packets even though we're not associated to a network yet */
4287 /* after register_netdev() userspace may start working with dev
4288 * (in particular, on other CPUs), we only need to up the sem */
4289 /* acx_sem_unlock(adev); */
4291 printk("acx " ACX_RELEASE ": net device %s, driver compiled "
4292 "against wireless extensions %d and Linux %s\n",
4293 wiphy_name(adev->ieee->wiphy), WIRELESS_EXT, UTS_RELEASE);
4295 MAC_COPY(adev->ieee->wiphy->perm_addr, adev->dev_addr);
4297 log(L_IRQ | L_INIT, "using IRQ %d\n", adev->irq);
4299 /** done with board specific setup **/
4301 err = acx_setup_modes(adev);
4302 if (err) {
4303 printk("can't register hwmode\n");
4304 goto fail_register_netdev;
4307 acx_init_task_scheduler(adev);
4308 result = ieee80211_register_hw(adev->ieee);
4309 if (OK != result) {
4310 printk("acx: ieee80211_register_hw() FAILED: %d\n", result);
4311 goto fail_register_netdev;
4313 #if CMD_DISCOVERY
4314 great_inquisitor(adev);
4315 #endif
4317 result = OK;
4318 goto done;
4320 /* error paths: undo everything in reverse order... */
4323 acxpci_s_delete_dma_regions(adev);
4325 fail_init_mac:
4326 fail_read_eeprom_version:
4327 fail_reset:
4329 fail_alloc_netdev:
4330 fail_irq:
4332 iounmap(adev->iobase);
4333 fail_ioremap:
4335 release_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4336 fail_request_mem_region:
4337 fail_register_netdev:
4338 ieee80211_free_hw(ieee);
4339 fail:
4340 vlynq_disable_device(vdev);
4341 done:
4342 FN_EXIT1(result);
4343 return result;
4346 static void vlynq_remove(struct vlynq_device *vdev)
4348 struct ieee80211_hw *hw = vlynq_get_drvdata(vdev);
4349 acx_device_t *adev = ieee2adev(hw);
4350 unsigned long flags;
4351 FN_ENTER;
4353 if (!hw) {
4354 log(L_DEBUG, "%s: card is unused. Skipping any release code\n",
4355 __func__);
4356 goto end;
4360 acx_lock(adev, flags);
4361 acx_unlock(adev, flags);
4362 adev->initialized = 0;
4364 /* If device wasn't hot unplugged... */
4365 if (adev_present(adev)) {
4367 acx_sem_lock(adev);
4369 /* disable both Tx and Rx to shut radio down properly */
4370 if (adev->initialized) {
4371 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_TX, NULL, 0);
4372 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_RX, NULL, 0);
4374 acx_lock(adev, flags);
4375 /* disable power LED to save power :-) */
4376 log(L_INIT, "switching off power LED to save power\n");
4377 acxpci_l_power_led(adev, 0);
4378 /* stop our eCPU */
4379 acx_unlock(adev, flags);
4381 acx_sem_unlock(adev);
4384 /* unregister the device to not let the kernel
4385 * (e.g. ioctls) access a half-deconfigured device
4386 * NB: this will cause acxpci_e_close() to be called,
4387 * thus we shouldn't call it under sem!
4388 * Well, netdev did, but ieee80211 stack does not, so we
4389 * have to do so manually...
4391 acxpci_e_close(hw);
4392 log(L_INIT, "removing device %s\n", wiphy_name(adev->ieee->wiphy));
4393 ieee80211_unregister_hw(adev->ieee);
4395 /* unregister_netdev ensures that no references to us left.
4396 * For paranoid reasons we continue to follow the rules */
4397 acx_sem_lock(adev);
4399 if (adev->dev_state_mask & ACX_STATE_IFACE_UP) {
4400 acxpci_s_down(hw);
4401 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
4404 acx_proc_unregister_entries(adev->ieee);
4406 /* finally, clean up PCI bus state */
4407 acxpci_s_delete_dma_regions(adev);
4408 if (adev->iobase)
4409 iounmap(adev->iobase);
4410 if (adev->iobase2)
4411 iounmap(adev->iobase2);
4412 release_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4414 /* remove dev registration */
4416 acx_sem_unlock(adev);
4417 vlynq_disable_device(vdev);
4419 /* Free netdev (quite late,
4420 * since otherwise we might get caught off-guard
4421 * by a netdev timeout handler execution
4422 * expecting to see a working dev...) */
4423 ieee80211_free_hw(adev->ieee);
4425 end:
4426 FN_EXIT0;
4429 static struct vlynq_driver vlynq_acx = {
4430 .name = "acx_vlynq",
4431 .id_table = acx_vlynq_id,
4432 .probe = vlynq_probe,
4433 .remove = __devexit_p(vlynq_remove),
4435 #endif /* CONFIG_VLYNQ */
4438 /***********************************************************************
4439 ** Data for init_module/cleanup_module
4441 #ifdef CONFIG_PCI
4442 static const struct pci_device_id acxpci_id_tbl[] __devinitdata = {
4444 .vendor = PCI_VENDOR_ID_TI,
4445 .device = PCI_DEVICE_ID_TI_TNETW1100A,
4446 .subvendor = PCI_ANY_ID,
4447 .subdevice = PCI_ANY_ID,
4448 .driver_data = CHIPTYPE_ACX100,
4451 .vendor = PCI_VENDOR_ID_TI,
4452 .device = PCI_DEVICE_ID_TI_TNETW1100B,
4453 .subvendor = PCI_ANY_ID,
4454 .subdevice = PCI_ANY_ID,
4455 .driver_data = CHIPTYPE_ACX100,
4458 .vendor = PCI_VENDOR_ID_TI,
4459 .device = PCI_DEVICE_ID_TI_TNETW1130,
4460 .subvendor = PCI_ANY_ID,
4461 .subdevice = PCI_ANY_ID,
4462 .driver_data = CHIPTYPE_ACX111,
4465 .vendor = 0,
4466 .device = 0,
4467 .subvendor = 0,
4468 .subdevice = 0,
4469 .driver_data = 0,
4473 MODULE_DEVICE_TABLE(pci, acxpci_id_tbl);
4475 static struct pci_driver
4476 acxpci_drv_id = {
4477 .name = "acx_pci",
4478 .id_table = acxpci_id_tbl,
4479 .probe = acxpci_e_probe,
4480 .remove = __devexit_p(acxpci_e_remove),
4481 #ifdef CONFIG_PM
4482 .suspend = acxpci_e_suspend,
4483 .resume = acxpci_e_resume
4484 #endif /* CONFIG_PM */
4486 #endif /* CONFIG_PCI */
4488 /***********************************************************************
4489 ** acxpci_e_init_module
4491 ** Module initialization routine, called once at module load time
4493 int __init acxpci_e_init_module(void)
4495 int res;
4497 FN_ENTER;
4499 #if (ACX_IO_WIDTH==32)
4500 printk("acx: compiled to use 32bit I/O access. "
4501 "I/O timing issues might occur, such as "
4502 "non-working firmware upload. Report them\n");
4503 #else
4504 printk("acx: compiled to use 16bit I/O access only "
4505 "(compatibility mode)\n");
4506 #endif
4508 #ifdef __LITTLE_ENDIAN
4509 #define ENDIANNESS_STRING "running on a little-endian CPU\n"
4510 #else
4511 #define ENDIANNESS_STRING "running on a BIG-ENDIAN CPU\n"
4512 #endif
4513 log(L_INIT,
4514 "acx: " ENDIANNESS_STRING
4515 "acx: PCI/VLYNQ module " ACX_RELEASE " initialized, "
4516 "waiting for cards to probe...\n");
4518 #ifdef CONFIG_PCI
4519 res = pci_register_driver(&acxpci_drv_id);
4520 #elif CONFIG_VLYNQ
4521 res = vlynq_register_driver(&vlynq_acx);
4522 #endif
4523 FN_EXIT1(res);
4524 return res;
4528 /***********************************************************************
4529 ** acxpci_e_cleanup_module
4531 ** Called at module unload time. This is our last chance to
4532 ** clean up after ourselves.
4534 void __exit acxpci_e_cleanup_module(void)
4536 FN_ENTER;
4538 #ifdef CONFIG_PCI
4539 pci_unregister_driver(&acxpci_drv_id);
4540 #elif CONFIG_VLYNQ
4541 vlynq_unregister_driver(&vlynq_acx);
4542 #endif
4543 log(L_INIT,
4544 "acx: PCI module " ACX_RELEASE " unloaded\n");
4545 FN_EXIT0;