Merge branch 'master' of http://xazz.no-ip.info/projects/acx-mac80211
[acx-mac80211.git] / pci.c
blobb2191a848758c102c2111fd394b79d701b967d40
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 /***********************************************************************
93 ** Register access
95 **
98 /* OS I/O routines *always* be endianness-clean but having them doesn't hurt */
99 #define acx_readl(v) le32_to_cpu(readl((v)))
100 #define acx_readw(v) le16_to_cpu(readw((v)))
101 #define acx_writew(v,r) writew(le16_to_cpu((v)), r)
102 #define acx_writel(v,r) writel(le32_to_cpu((v)), r)
104 /* Pick one */
105 /* #define INLINE_IO static */
106 #define INLINE_IO static inline
108 INLINE_IO u32 read_reg32(acx_device_t * adev, unsigned int offset)
110 #if ACX_IO_WIDTH == 32
111 return acx_readl((u8 *) adev->iobase + adev->io[offset]);
112 #else
113 return acx_readw((u8 *) adev->iobase + adev->io[offset])
114 + (acx_readw((u8 *) adev->iobase + adev->io[offset] + 2) << 16);
115 #endif
118 INLINE_IO u16 read_reg16(acx_device_t * adev, unsigned int offset)
120 return acx_readw((u8 *) adev->iobase + adev->io[offset]);
123 INLINE_IO u8 read_reg8(acx_device_t * adev, unsigned int offset)
125 return readb((u8 *) adev->iobase + adev->io[offset]);
128 INLINE_IO void write_reg32(acx_device_t * adev, unsigned int offset, u32 val)
130 #if ACX_IO_WIDTH == 32
131 acx_writel(val, (u8 *) adev->iobase + adev->io[offset]);
132 #else
133 acx_writew(val & 0xffff, (u8 *) adev->iobase + adev->io[offset]);
134 acx_writew(val >> 16, (u8 *) adev->iobase + adev->io[offset] + 2);
135 #endif
138 INLINE_IO void write_reg16(acx_device_t * adev, unsigned int offset, u16 val)
140 acx_writew(val, (u8 *) adev->iobase + adev->io[offset]);
143 INLINE_IO void write_reg8(acx_device_t * adev, unsigned int offset, u8 val)
145 writeb(val, (u8 *) adev->iobase + adev->io[offset]);
148 /* Handle PCI posting properly:
149 * Make sure that writes reach the adapter in case they require to be executed
150 * *before* the next write, by reading a random (and safely accessible) register.
151 * This call has to be made if there is no read following (which would flush the data
152 * to the adapter), yet the written data has to reach the adapter immediately. */
153 INLINE_IO void write_flush(acx_device_t * adev)
155 /* readb(adev->iobase + adev->io[IO_ACX_INFO_MAILBOX_OFFS]); */
156 /* faster version (accesses the first register, IO_ACX_SOFT_RESET,
157 * which should also be safe): */
158 readb(adev->iobase);
161 INLINE_IO int adev_present(acx_device_t * adev)
163 /* fast version (accesses the first register, IO_ACX_SOFT_RESET,
164 * which should be safe): */
165 return acx_readl(adev->iobase) != 0xffffffff;
169 /***********************************************************************
171 static inline txdesc_t *get_txdesc(acx_device_t * adev, int index)
173 return (txdesc_t *) (((u8 *) adev->txdesc_start) +
174 index * adev->txdesc_size);
177 static inline txdesc_t *advance_txdesc(acx_device_t * adev, txdesc_t * txdesc,
178 int inc)
180 return (txdesc_t *) (((u8 *) txdesc) + inc * adev->txdesc_size);
183 static txhostdesc_t *get_txhostdesc(acx_device_t * adev, txdesc_t * txdesc)
185 int index = (u8 *) txdesc - (u8 *) adev->txdesc_start;
187 FN_ENTER;
189 if (unlikely(ACX_DEBUG && (index % adev->txdesc_size))) {
190 printk("bad txdesc ptr %p\n", txdesc);
191 return NULL;
193 index /= adev->txdesc_size;
194 if (unlikely(ACX_DEBUG && (index >= TX_CNT))) {
195 printk("bad txdesc ptr %p\n", txdesc);
196 return NULL;
199 FN_EXIT0;
201 return &adev->txhostdesc_start[index * 2];
208 /***********************************************************************
209 ** EEPROM and PHY read/write helpers
211 /***********************************************************************
212 ** acxpci_read_eeprom_byte
214 ** Function called to read an octet in the EEPROM.
216 ** This function is used by acxpci_e_probe to check if the
217 ** connected card is a legal one or not.
219 ** Arguments:
220 ** adev ptr to acx_device structure
221 ** addr address to read in the EEPROM
222 ** charbuf ptr to a char. This is where the read octet
223 ** will be stored
226 int acxpci_read_eeprom_byte(acx_device_t * adev, u32 addr, u8 * charbuf)
228 int result;
229 int count;
231 FN_ENTER;
233 write_reg32(adev, IO_ACX_EEPROM_CFG, 0);
234 write_reg32(adev, IO_ACX_EEPROM_ADDR, addr);
235 write_flush(adev);
236 write_reg32(adev, IO_ACX_EEPROM_CTL, 2);
238 count = 0xffff;
239 while (read_reg16(adev, IO_ACX_EEPROM_CTL)) {
240 /* scheduling away instead of CPU burning loop
241 * doesn't seem to work here at all:
242 * awful delay, sometimes also failure.
243 * Doesn't matter anyway (only small delay). */
244 if (unlikely(!--count)) {
245 printk("%s: timeout waiting for EEPROM read\n",
246 wiphy_name(adev->ieee->wiphy));
247 result = NOT_OK;
248 goto fail;
250 cpu_relax();
253 *charbuf = read_reg8(adev, IO_ACX_EEPROM_DATA);
254 log(L_DEBUG, "EEPROM at 0x%04X = 0x%02X\n", addr, *charbuf);
255 result = OK;
257 fail:
258 FN_EXIT1(result);
259 return result;
263 /***********************************************************************
264 ** We don't lock hw accesses here since we never r/w eeprom in IRQ
265 ** Note: this function sleeps only because of GFP_KERNEL alloc
267 #ifdef UNUSED
269 acxpci_s_write_eeprom(acx_device_t * adev, u32 addr, u32 len,
270 const u8 * charbuf)
272 u8 *data_verify = NULL;
273 unsigned long flags;
274 int count, i;
275 int result = NOT_OK;
276 u16 gpio_orig;
278 printk("acx: WARNING! I would write to EEPROM now. "
279 "Since I really DON'T want to unless you know "
280 "what you're doing (THIS CODE WILL PROBABLY "
281 "NOT WORK YET!), I will abort that now. And "
282 "definitely make sure to make a "
283 "/proc/driver/acx_wlan0_eeprom backup copy first!!! "
284 "(the EEPROM content includes the PCI config header!! "
285 "If you kill important stuff, then you WILL "
286 "get in trouble and people DID get in trouble already)\n");
287 return OK;
289 FN_ENTER;
291 data_verify = kmalloc(len, GFP_KERNEL);
292 if (!data_verify) {
293 goto end;
296 /* first we need to enable the OE (EEPROM Output Enable) GPIO line
297 * to be able to write to the EEPROM.
298 * NOTE: an EEPROM writing success has been reported,
299 * but you probably have to modify GPIO_OUT, too,
300 * and you probably need to activate a different GPIO
301 * line instead! */
302 gpio_orig = read_reg16(adev, IO_ACX_GPIO_OE);
303 write_reg16(adev, IO_ACX_GPIO_OE, gpio_orig & ~1);
304 write_flush(adev);
306 /* ok, now start writing the data out */
307 for (i = 0; i < len; i++) {
308 write_reg32(adev, IO_ACX_EEPROM_CFG, 0);
309 write_reg32(adev, IO_ACX_EEPROM_ADDR, addr + i);
310 write_reg32(adev, IO_ACX_EEPROM_DATA, *(charbuf + i));
311 write_flush(adev);
312 write_reg32(adev, IO_ACX_EEPROM_CTL, 1);
314 count = 0xffff;
315 while (read_reg16(adev, IO_ACX_EEPROM_CTL)) {
316 if (unlikely(!--count)) {
317 printk("WARNING, DANGER!!! "
318 "Timeout waiting for EEPROM write\n");
319 goto end;
321 cpu_relax();
325 /* disable EEPROM writing */
326 write_reg16(adev, IO_ACX_GPIO_OE, gpio_orig);
327 write_flush(adev);
329 /* now start a verification run */
330 for (i = 0; i < len; i++) {
331 write_reg32(adev, IO_ACX_EEPROM_CFG, 0);
332 write_reg32(adev, IO_ACX_EEPROM_ADDR, addr + i);
333 write_flush(adev);
334 write_reg32(adev, IO_ACX_EEPROM_CTL, 2);
336 count = 0xffff;
337 while (read_reg16(adev, IO_ACX_EEPROM_CTL)) {
338 if (unlikely(!--count)) {
339 printk("timeout waiting for EEPROM read\n");
340 goto end;
342 cpu_relax();
345 data_verify[i] = read_reg16(adev, IO_ACX_EEPROM_DATA);
348 if (0 == memcmp(charbuf, data_verify, len))
349 result = OK; /* read data matches, success */
351 end:
352 kfree(data_verify);
353 FN_EXIT1(result);
354 return result;
356 #endif /* UNUSED */
359 /***********************************************************************
360 ** acxpci_s_read_phy_reg
362 ** Messing with rx/tx disabling and enabling here
363 ** (write_reg32(adev, IO_ACX_ENABLE, 0b000000xx)) kills traffic
365 int acxpci_s_read_phy_reg(acx_device_t * adev, u32 reg, u8 * charbuf)
367 int result = NOT_OK;
368 int count;
370 FN_ENTER;
372 write_reg32(adev, IO_ACX_PHY_ADDR, reg);
373 write_flush(adev);
374 write_reg32(adev, IO_ACX_PHY_CTL, 2);
376 count = 0xffff;
377 while (read_reg32(adev, IO_ACX_PHY_CTL)) {
378 /* scheduling away instead of CPU burning loop
379 * doesn't seem to work here at all:
380 * awful delay, sometimes also failure.
381 * Doesn't matter anyway (only small delay). */
382 if (unlikely(!--count)) {
383 printk("%s: timeout waiting for phy read\n",
384 wiphy_name(adev->ieee->wiphy));
385 *charbuf = 0;
386 goto fail;
388 cpu_relax();
391 log(L_DEBUG, "count was %u\n", count);
392 *charbuf = read_reg8(adev, IO_ACX_PHY_DATA);
394 log(L_DEBUG, "radio PHY at 0x%04X = 0x%02X\n", *charbuf, reg);
395 result = OK;
396 goto fail; /* silence compiler warning */
397 fail:
398 FN_EXIT1(result);
399 return result;
403 /***********************************************************************
405 int acxpci_s_write_phy_reg(acx_device_t * adev, u32 reg, u8 value)
407 FN_ENTER;
409 /* mprusko said that 32bit accesses result in distorted sensitivity
410 * on his card. Unconfirmed, looks like it's not true (most likely since we
411 * now properly flush writes). */
412 write_reg32(adev, IO_ACX_PHY_DATA, value);
413 write_reg32(adev, IO_ACX_PHY_ADDR, reg);
414 write_flush(adev);
415 write_reg32(adev, IO_ACX_PHY_CTL, 1);
416 write_flush(adev);
417 log(L_DEBUG, "radio PHY write 0x%02X at 0x%04X\n", value, reg);
419 FN_EXIT0;
420 return OK;
424 #define NO_AUTO_INCREMENT 1
426 /***********************************************************************
427 ** acxpci_s_write_fw
429 ** Write the firmware image into the card.
431 ** Arguments:
432 ** adev wlan device structure
433 ** fw_image firmware image.
435 ** Returns:
436 ** 1 firmware image corrupted
437 ** 0 success
439 ** Standard csum implementation + write to IO
441 static int
442 acxpci_s_write_fw(acx_device_t * adev, const firmware_image_t *fw_image,
443 u32 offset)
445 int len, size;
446 u32 sum, v32;
447 /* we skip the first four bytes which contain the control sum */
449 const u8 *p = (u8 *) fw_image + 4;
451 FN_ENTER;
453 /* start the image checksum by adding the image size value */
454 sum = p[0] + p[1] + p[2] + p[3];
455 p += 4;
457 write_reg32(adev, IO_ACX_SLV_END_CTL, 0);
459 #if NO_AUTO_INCREMENT
460 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 0); /* use basic mode */
461 #else
462 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 1); /* use autoincrement mode */
463 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset); /* configure start address */
464 write_flush(adev);
465 #endif
467 len = 0;
468 size = le32_to_cpu(fw_image->size) & (~3);
470 while (likely(len < size)) {
471 v32 = be32_to_cpu(*(u32 *) p);
472 sum += p[0] + p[1] + p[2] + p[3];
473 p += 4;
474 len += 4;
476 #if NO_AUTO_INCREMENT
477 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset + len - 4);
478 write_flush(adev);
479 #endif
480 write_reg32(adev, IO_ACX_SLV_MEM_DATA, v32);
483 log(L_DEBUG, "firmware written, size:%d sum1:%x sum2:%x\n",
484 size, sum, le32_to_cpu(fw_image->chksum));
486 /* compare our checksum with the stored image checksum */
487 FN_EXIT1(sum != le32_to_cpu(fw_image->chksum));
488 return (sum != le32_to_cpu(fw_image->chksum));
492 /***********************************************************************
493 ** acxpci_s_validate_fw
495 ** Compare the firmware image given with
496 ** the firmware image written into the card.
498 ** Arguments:
499 ** adev wlan device structure
500 ** fw_image firmware image.
502 ** Returns:
503 ** NOT_OK firmware image corrupted or not correctly written
504 ** OK success
506 ** Origin: Standard csum + Read IO
508 static int
509 acxpci_s_validate_fw(acx_device_t * adev, const firmware_image_t *fw_image,
510 u32 offset)
512 u32 sum, v32, w32;
513 int len, size;
514 int result = OK;
515 /* we skip the first four bytes which contain the control sum */
516 const u8 *p = (u8 *) fw_image + 4;
518 FN_ENTER;
520 /* start the image checksum by adding the image size value */
521 sum = p[0] + p[1] + p[2] + p[3];
522 p += 4;
524 write_reg32(adev, IO_ACX_SLV_END_CTL, 0);
526 #if NO_AUTO_INCREMENT
527 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 0); /* use basic mode */
528 #else
529 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 1); /* use autoincrement mode */
530 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset); /* configure start address */
531 #endif
533 len = 0;
534 size = le32_to_cpu(fw_image->size) & (~3);
536 while (likely(len < size)) {
537 v32 = be32_to_cpu(*(u32 *) p);
538 p += 4;
539 len += 4;
541 #if NO_AUTO_INCREMENT
542 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset + len - 4);
543 #endif
544 w32 = read_reg32(adev, IO_ACX_SLV_MEM_DATA);
546 if (unlikely(w32 != v32)) {
547 printk("acx: FATAL: firmware upload: "
548 "data parts at offset %d don't match (0x%08X vs. 0x%08X)! "
549 "I/O timing issues or defective memory, with DWL-xx0+? "
550 "ACX_IO_WIDTH=16 may help. Please report\n",
551 len, v32, w32);
552 result = NOT_OK;
553 break;
556 sum +=
557 (u8) w32 + (u8) (w32 >> 8) + (u8) (w32 >> 16) +
558 (u8) (w32 >> 24);
561 /* sum control verification */
562 if (result != NOT_OK) {
563 if (sum != le32_to_cpu(fw_image->chksum)) {
564 printk("acx: FATAL: firmware upload: "
565 "checksums don't match!\n");
566 result = NOT_OK;
570 FN_EXIT1(result);
571 return result;
575 /***********************************************************************
576 ** acxpci_s_upload_fw
578 ** Called from acx_reset_dev
580 ** Origin: Derived from FW dissection
582 static int acxpci_s_upload_fw(acx_device_t * adev)
584 firmware_image_t *fw_image = NULL;
585 int res = NOT_OK;
586 int try;
587 u32 file_size;
588 char filename[sizeof("tiacx1NNcNN")];
590 FN_ENTER;
592 /* print exact chipset and radio ID to make sure people
593 * really get a clue on which files exactly they need to provide.
594 * Firmware loading is a frequent end-user PITA with these chipsets.
596 printk( "acx: need firmware for acx1%02d chipset with radio ID %02X\n"
597 "Please provide via firmware hotplug:\n"
598 "either combined firmware (single file named 'tiacx1%02dc%02X')\n"
599 "or two files (base firmware file 'tiacx1%02d' "
600 "+ radio fw 'tiacx1%02dr%02X')\n",
601 IS_ACX111(adev)*11, adev->radio_type,
602 IS_ACX111(adev)*11, adev->radio_type,
603 IS_ACX111(adev)*11,
604 IS_ACX111(adev)*11, adev->radio_type
607 /* print exact chipset and radio ID to make sure people really get a clue on which files exactly they are supposed to provide,
608 * since firmware loading is the biggest enduser PITA with these chipsets.
609 * Not printing radio ID in 0xHEX in order to not confuse them into wrong file naming */
610 printk( "acx: need to load firmware for acx1%02d chipset with radio ID %02x, please provide via firmware hotplug:\n"
611 "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",
612 IS_ACX111(adev)*11, adev->radio_type);
614 /* Try combined, then main image */
615 adev->need_radio_fw = 0;
616 snprintf(filename, sizeof(filename), "tiacx1%02dc%02X",
617 IS_ACX111(adev) * 11, adev->radio_type);
619 fw_image = acx_s_read_fw(adev->bus_dev, filename, &file_size);
620 if (!fw_image) {
621 adev->need_radio_fw = 1;
622 filename[sizeof("tiacx1NN") - 1] = '\0';
623 fw_image =
624 acx_s_read_fw(adev->bus_dev, filename, &file_size);
625 if (!fw_image) {
626 FN_EXIT1(NOT_OK);
627 return NOT_OK;
631 for (try = 1; try <= 5; try++) {
632 res = acxpci_s_write_fw(adev, fw_image, 0);
633 log(L_DEBUG | L_INIT, "acx_write_fw (main/combined): %d\n", res);
634 if (OK == res) {
635 res = acxpci_s_validate_fw(adev, fw_image, 0);
636 log(L_DEBUG | L_INIT, "acx_validate_fw "
637 "(main/combined): %d\n", res);
640 if (OK == res) {
641 SET_BIT(adev->dev_state_mask, ACX_STATE_FW_LOADED);
642 break;
644 printk("acx: firmware upload attempt #%d FAILED, "
645 "retrying...\n", try);
646 acx_s_mwait(1000); /* better wait for a while... */
649 vfree(fw_image);
651 FN_EXIT1(res);
652 return res;
656 /***********************************************************************
657 ** acxpci_s_upload_radio
659 ** Uploads the appropriate radio module firmware into the card.
661 ** Origin: Standard Read/Write to IO
663 int acxpci_s_upload_radio(acx_device_t * adev)
665 acx_ie_memmap_t mm;
666 firmware_image_t *radio_image;
667 acx_cmd_radioinit_t radioinit;
668 int res = NOT_OK;
669 int try;
670 u32 offset;
671 u32 size;
672 char filename[sizeof("tiacx1NNrNN")];
674 if (!adev->need_radio_fw)
675 return OK;
677 FN_ENTER;
679 acx_s_interrogate(adev, &mm, ACX1xx_IE_MEMORY_MAP);
680 offset = le32_to_cpu(mm.CodeEnd);
682 snprintf(filename, sizeof(filename), "tiacx1%02dr%02X",
683 IS_ACX111(adev) * 11, adev->radio_type);
684 radio_image = acx_s_read_fw(adev->bus_dev, filename, &size);
685 if (!radio_image) {
686 printk("acx: can't load radio module '%s'\n", filename);
687 goto fail;
690 acx_s_issue_cmd(adev, ACX1xx_CMD_SLEEP, NULL, 0);
692 for (try = 1; try <= 5; try++) {
693 res = acxpci_s_write_fw(adev, radio_image, offset);
694 log(L_DEBUG | L_INIT, "acx_write_fw (radio): %d\n", res);
695 if (OK == res) {
696 res = acxpci_s_validate_fw(adev, radio_image, offset);
697 log(L_DEBUG | L_INIT, "acx_validate_fw (radio): %d\n",
698 res);
701 if (OK == res)
702 break;
703 printk("acx: radio firmware upload attempt #%d FAILED, "
704 "retrying...\n", try);
705 acx_s_mwait(1000); /* better wait for a while... */
708 acx_s_issue_cmd(adev, ACX1xx_CMD_WAKE, NULL, 0);
709 radioinit.offset = cpu_to_le32(offset);
710 /* no endian conversion needed, remains in card CPU area: */
711 radioinit.len = radio_image->size;
713 vfree(radio_image);
715 if (OK != res)
716 goto fail;
718 /* will take a moment so let's have a big timeout */
719 acx_s_issue_cmd_timeo(adev, ACX1xx_CMD_RADIOINIT,
720 &radioinit, sizeof(radioinit),
721 CMD_TIMEOUT_MS(1000));
723 res = acx_s_interrogate(adev, &mm, ACX1xx_IE_MEMORY_MAP);
724 fail:
725 FN_EXIT1(res);
726 return res;
730 /***********************************************************************
731 ** acxpci_l_reset_mac
733 ** MAC will be reset
734 ** Call context: reset_dev
736 ** Origin: Standard Read/Write to IO
738 static void acxpci_l_reset_mac(acx_device_t * adev)
740 u16 temp;
742 FN_ENTER;
744 /* halt eCPU */
745 temp = read_reg16(adev, IO_ACX_ECPU_CTRL) | 0x1;
746 write_reg16(adev, IO_ACX_ECPU_CTRL, temp);
748 /* now do soft reset of eCPU, set bit */
749 temp = read_reg16(adev, IO_ACX_SOFT_RESET) | 0x1;
750 log(L_DEBUG, "enable soft reset\n");
751 write_reg16(adev, IO_ACX_SOFT_RESET, temp);
752 write_flush(adev);
754 /* now clear bit again: deassert eCPU reset */
755 log(L_DEBUG, "disable soft reset and go to init mode\n");
756 write_reg16(adev, IO_ACX_SOFT_RESET, temp & ~0x1);
758 /* now start a burst read from initial EEPROM */
759 temp = read_reg16(adev, IO_ACX_EE_START) | 0x1;
760 write_reg16(adev, IO_ACX_EE_START, temp);
761 write_flush(adev);
763 FN_EXIT0;
767 /***********************************************************************
768 ** acxpci_s_verify_init
770 static int acxpci_s_verify_init(acx_device_t * adev)
772 int result = NOT_OK;
773 unsigned long timeout;
775 FN_ENTER;
777 timeout = jiffies + 2 * HZ;
778 for (;;) {
779 u16 irqstat = read_reg16(adev, IO_ACX_IRQ_STATUS_NON_DES);
780 if (irqstat & HOST_INT_FCS_THRESHOLD) {
781 result = OK;
782 write_reg16(adev, IO_ACX_IRQ_ACK,
783 HOST_INT_FCS_THRESHOLD);
784 break;
786 if (time_after(jiffies, timeout))
787 break;
788 /* Init may take up to ~0.5 sec total */
789 acx_s_mwait(50);
792 FN_EXIT1(result);
793 return result;
797 /***********************************************************************
798 ** A few low-level helpers
800 ** Note: these functions are not protected by lock
801 ** and thus are never allowed to be called from IRQ.
802 ** Also they must not race with fw upload which uses same hw regs
805 /***********************************************************************
806 ** acxpci_write_cmd_type_status
808 ** Origin: Common linux implementation
811 static inline void
812 acxpci_write_cmd_type_status(acx_device_t * adev, u16 type, u16 status)
814 FN_ENTER;
815 acx_writel(type | (status << 16), adev->cmd_area);
816 write_flush(adev);
817 FN_EXIT0;
821 /***********************************************************************
822 ** acxpci_read_cmd_type_status
824 ** Origin: Common linux implementation
826 static u32 acxpci_read_cmd_type_status(acx_device_t * adev)
828 u32 cmd_type, cmd_status;
830 FN_ENTER;
832 cmd_type = acx_readl(adev->cmd_area);
833 cmd_status = (cmd_type >> 16);
834 cmd_type = (u16) cmd_type;
836 log(L_CTL, "cmd_type:%04X cmd_status:%04X [%s]\n",
837 cmd_type, cmd_status, acx_cmd_status_str(cmd_status));
839 FN_EXIT1(cmd_status);
840 return cmd_status;
844 /***********************************************************************
845 ** acxpci_s_reset_dev
847 ** Arguments:
848 ** netdevice that contains the adev variable
849 ** Returns:
850 ** NOT_OK on fail
851 ** OK on success
852 ** Side effects:
853 ** device is hard reset
854 ** Call context:
855 ** acxpci_e_probe
856 ** Comment:
857 ** This resets the device using low level hardware calls
858 ** as well as uploads and verifies the firmware to the card
861 static inline void init_mboxes(acx_device_t * adev)
863 u32 cmd_offs, info_offs;
865 FN_ENTER;
867 cmd_offs = read_reg32(adev, IO_ACX_CMD_MAILBOX_OFFS);
868 info_offs = read_reg32(adev, IO_ACX_INFO_MAILBOX_OFFS);
869 adev->cmd_area = (u8 *) adev->iobase2 + cmd_offs;
870 adev->info_area = (u8 *) adev->iobase2 + info_offs;
871 log(L_DEBUG, "iobase2=%p\n"
872 "cmd_mbox_offset=%X cmd_area=%p\n"
873 "info_mbox_offset=%X info_area=%p\n",
874 adev->iobase2,
875 cmd_offs, adev->cmd_area, info_offs, adev->info_area);
876 FN_EXIT0;
880 static inline void read_eeprom_area(acx_device_t * adev)
882 #if ACX_DEBUG > 1
883 int offs;
884 u8 tmp;
886 FN_ENTER;
888 for (offs = 0x8c; offs < 0xb9; offs++)
889 acxpci_read_eeprom_byte(adev, offs, &tmp);
891 FN_EXIT0;
892 #endif
896 int acxpci_s_reset_dev(acx_device_t * adev)
898 const char *msg = "";
899 unsigned long flags;
900 int result = NOT_OK;
901 u16 hardware_info;
902 u16 ecpu_ctrl;
903 int count;
905 FN_ENTER;
907 /* reset the device to make sure the eCPU is stopped
908 * to upload the firmware correctly */
910 acx_lock(adev, flags);
912 #ifdef CONFIG_PCI
913 acxpci_l_reset_mac(adev);
914 #endif
916 ecpu_ctrl = read_reg16(adev, IO_ACX_ECPU_CTRL) & 1;
917 if (!ecpu_ctrl) {
918 msg = "eCPU is already running. ";
919 goto end_unlock;
921 #if 0
922 if (read_reg16(adev, IO_ACX_SOR_CFG) & 2) {
923 /* eCPU most likely means "embedded CPU" */
924 msg = "eCPU did not start after boot from flash. ";
925 goto end_unlock;
928 /* check sense on reset flags */
929 if (read_reg16(adev, IO_ACX_SOR_CFG) & 0x10) {
930 printk("%s: eCPU did not start after boot (SOR), "
931 "is this fatal?\n", wiphy_name(adev->ieee->wiphy));
933 #endif
934 /* scan, if any, is stopped now, setting corresponding IRQ bit */
935 SET_BIT(adev->irq_status, HOST_INT_SCAN_COMPLETE);
937 acx_unlock(adev, flags);
939 /* need to know radio type before fw load */
940 /* Need to wait for arrival of this information in a loop,
941 * most probably since eCPU runs some init code from EEPROM
942 * (started burst read in reset_mac()) which also
943 * sets the radio type ID */
945 count = 0xffff;
946 do {
947 hardware_info = read_reg16(adev, IO_ACX_EEPROM_INFORMATION);
948 if (!--count) {
949 msg = "eCPU didn't indicate radio type";
950 goto end_fail;
952 cpu_relax();
953 } while (!(hardware_info & 0xff00)); /* radio type still zero? */
955 /* printk("DEBUG: count %d\n", count); */
956 adev->form_factor = hardware_info & 0xff;
957 adev->radio_type = hardware_info >> 8;
959 /* load the firmware */
960 if (OK != acxpci_s_upload_fw(adev))
961 goto end_fail;
963 /* acx_s_mwait(10); this one really shouldn't be required */
965 /* now start eCPU by clearing bit */
966 write_reg16(adev, IO_ACX_ECPU_CTRL, ecpu_ctrl & ~0x1);
967 log(L_DEBUG, "booted eCPU up and waiting for completion...\n");
969 /* wait for eCPU bootup */
970 if (OK != acxpci_s_verify_init(adev)) {
971 msg = "timeout waiting for eCPU. ";
972 goto end_fail;
974 log(L_DEBUG, "eCPU has woken up, card is ready to be configured\n");
976 init_mboxes(adev);
977 acxpci_write_cmd_type_status(adev, 0, 0);
979 /* test that EEPROM is readable */
980 read_eeprom_area(adev);
982 result = OK;
983 goto end;
985 /* Finish error message. Indicate which function failed */
986 end_unlock:
987 acx_unlock(adev, flags);
988 end_fail:
989 printk("acx: %sreset_dev() FAILED\n", msg);
990 end:
991 FN_EXIT1(result);
992 return result;
996 /***********************************************************************
997 ** acxpci_s_issue_cmd_timeo
999 ** Sends command to fw, extract result
1001 ** NB: we do _not_ take lock inside, so be sure to not touch anything
1002 ** which may interfere with IRQ handler operation
1004 ** TODO: busy wait is a bit silly, so:
1005 ** 1) stop doing many iters - go to sleep after first
1006 ** 2) go to waitqueue based approach: wait, not poll!
1008 #undef FUNC
1009 #define FUNC "issue_cmd"
1011 #if !ACX_DEBUG
1013 acxpci_s_issue_cmd_timeo(acx_device_t * adev,
1014 unsigned int cmd,
1015 void *buffer, unsigned buflen, unsigned cmd_timeout)
1017 #else
1019 acxpci_s_issue_cmd_timeo_debug(acx_device_t * adev,
1020 unsigned cmd,
1021 void *buffer,
1022 unsigned buflen,
1023 unsigned cmd_timeout, const char *cmdstr)
1025 unsigned long start = jiffies;
1026 #endif
1027 const char *devname;
1028 unsigned counter;
1029 u16 irqtype;
1030 u16 cmd_status;
1031 unsigned long timeout;
1033 FN_ENTER;
1035 devname = wiphy_name(adev->ieee->wiphy);
1036 if (!devname || !devname[0] || devname[4] == '%')
1037 devname = "acx";
1039 log(L_CTL, FUNC "(cmd:%s,buflen:%u,timeout:%ums,type:0x%04X)\n",
1040 cmdstr, buflen, cmd_timeout,
1041 buffer ? le16_to_cpu(((acx_ie_generic_t *) buffer)->type) : -1);
1043 if (!(adev->dev_state_mask & ACX_STATE_FW_LOADED)) {
1044 printk("%s: " FUNC "(): firmware is not loaded yet, "
1045 "cannot execute commands!\n", devname);
1046 goto bad;
1049 if ((acx_debug & L_DEBUG) && (cmd != ACX1xx_CMD_QUERY)) {
1050 printk("input buffer (len=%u):\n", buflen);
1051 acx_dump_bytes(buffer, buflen);
1054 /* wait for firmware to become idle for our command submission */
1055 timeout = HZ / 5;
1056 counter = (timeout * 1000 / HZ) - 1; /* in ms */
1057 timeout += jiffies;
1058 do {
1059 cmd_status = acxpci_read_cmd_type_status(adev);
1060 /* Test for IDLE state */
1061 if (!cmd_status)
1062 break;
1063 if (counter % 8 == 0) {
1064 if (time_after(jiffies, timeout)) {
1065 counter = 0;
1066 break;
1068 /* we waited 8 iterations, no luck. Sleep 8 ms */
1069 acx_s_mwait(8);
1071 } while (likely(--counter));
1073 if (!counter) {
1074 /* the card doesn't get idle, we're in trouble */
1075 printk("%s: " FUNC "(): cmd_status is not IDLE: 0x%04X!=0\n",
1076 devname, cmd_status);
1077 goto bad;
1078 } else if (counter < 190) { /* if waited >10ms... */
1079 log(L_CTL | L_DEBUG, FUNC "(): waited for IDLE %dms. "
1080 "Please report\n", 199 - counter);
1083 /* now write the parameters of the command if needed */
1084 if (buffer && buflen) {
1085 /* if it's an INTERROGATE command, just pass the length
1086 * of parameters to read, as data */
1087 #if CMD_DISCOVERY
1088 if (cmd == ACX1xx_CMD_INTERROGATE)
1089 memset_io(adev->cmd_area + 4, 0xAA, buflen);
1090 #endif
1091 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1092 memcpy_toio(adev->cmd_area + 4, buffer,
1093 (cmd == ACX1xx_CMD_INTERROGATE) ? 4 : buflen);
1095 /* now write the actual command type */
1096 acxpci_write_cmd_type_status(adev, cmd, 0);
1097 /* execute command */
1098 write_reg16(adev, IO_ACX_INT_TRIG, INT_TRIG_CMD);
1099 write_flush(adev);
1101 /* wait for firmware to process command */
1103 /* Ensure nonzero and not too large timeout.
1104 ** Also converts e.g. 100->99, 200->199
1105 ** which is nice but not essential */
1106 cmd_timeout = (cmd_timeout - 1) | 1;
1107 if (unlikely(cmd_timeout > 1199))
1108 cmd_timeout = 1199;
1109 /* clear CMD_COMPLETE bit. can be set only by IRQ handler: */
1110 CLEAR_BIT(adev->irq_status, HOST_INT_CMD_COMPLETE);
1111 /* we schedule away sometimes (timeout can be large) */
1112 counter = cmd_timeout;
1113 timeout = jiffies + HZ;
1114 do {
1115 if (!adev->irqs_active) { /* IRQ disabled: poll */
1116 irqtype = read_reg16(adev, IO_ACX_IRQ_STATUS_NON_DES);
1117 if (irqtype & HOST_INT_CMD_COMPLETE) {
1118 write_reg16(adev, IO_ACX_IRQ_ACK,
1119 HOST_INT_CMD_COMPLETE);
1120 break;
1122 } else { /* Wait when IRQ will set the bit */
1123 irqtype = adev->irq_status;
1124 if (irqtype & HOST_INT_CMD_COMPLETE)
1125 break;
1128 if (counter % 8 == 0) {
1129 if (time_after(jiffies, timeout)) {
1130 counter = 0;
1131 break;
1133 /* we waited 8 iterations, no luck. Sleep 8 ms */
1134 acx_s_mwait(8);
1136 } while (likely(--counter));
1138 /* save state for debugging */
1139 cmd_status = acxpci_read_cmd_type_status(adev);
1141 /* put the card in IDLE state */
1142 acxpci_write_cmd_type_status(adev, 0, 0);
1144 if ((cmd_timeout - counter) == 0) { /* timed out! */
1145 printk("%s: " FUNC "(): timed out %s for CMD_COMPLETE. "
1146 "irq bits:0x%04X irq_status:0x%04X timeout:%dms "
1147 "cmd_status:%d (%s)\n",
1148 devname, (adev->irqs_active) ? "waiting" : "polling",
1149 irqtype, adev->irq_status, cmd_timeout,
1150 cmd_status, acx_cmd_status_str(cmd_status));
1151 printk("hack: don't do: 'goto bad;'\ncounter: %d cmd_timeout: %d cmd_timeout-counter: %d\n",counter, cmd_timeout, cmd_timeout - counter);
1152 } else if (counter == 0) { /* maybe timed out! */
1153 log(L_CTL | L_DEBUG, FUNC "(): %s for CMD_COMPLETE %dms. "
1154 "count:%d. Please report\n",
1155 (adev->irqs_active) ? "waited" : "polled",
1156 cmd_timeout - counter, counter);
1157 } else if ((cmd_timeout - counter) > 30) { /* if waited >30ms... */
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);
1164 if (1 != cmd_status) { /* it is not a 'Success' */
1165 printk("%s: " FUNC "(): cmd_status is not SUCCESS: %d (%s). "
1166 "Took %dms of %d\n",
1167 devname, cmd_status, acx_cmd_status_str(cmd_status),
1168 cmd_timeout - counter, cmd_timeout);
1169 /* zero out result buffer
1170 * WARNING: this will trash stack in case of illegally large input
1171 * length! */
1172 if (buffer && buflen)
1173 memset(buffer, 0, buflen);
1174 goto bad;
1177 /* read in result parameters if needed */
1178 if (buffer && buflen && (cmd == ACX1xx_CMD_INTERROGATE)) {
1179 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1180 memcpy_fromio(buffer, adev->cmd_area + 4, buflen);
1181 if (acx_debug & L_DEBUG) {
1182 printk("output buffer (len=%u): ", buflen);
1183 acx_dump_bytes(buffer, buflen);
1186 /* ok: */
1187 log(L_CTL, FUNC "(%s): took %ld jiffies to complete\n",
1188 cmdstr, jiffies - start);
1189 FN_EXIT1(OK);
1190 return OK;
1192 bad:
1193 /* Give enough info so that callers can avoid
1194 ** printing their own diagnostic messages */
1195 #if ACX_DEBUG
1196 printk("%s: " FUNC "(cmd:%s) FAILED\n", devname, cmdstr);
1197 #else
1198 printk("%s: " FUNC "(cmd:0x%04X) FAILED\n", devname, cmd);
1199 #endif
1200 dump_stack();
1201 FN_EXIT1(NOT_OK);
1202 return NOT_OK;
1206 /***********************************************************************
1208 #ifdef NONESSENTIAL_FEATURES
1209 typedef struct device_id {
1210 unsigned char id[6];
1211 char *descr;
1212 char *type;
1213 } device_id_t;
1215 static const device_id_t device_ids[] = {
1217 {'G', 'l', 'o', 'b', 'a', 'l'},
1218 NULL,
1219 NULL,
1222 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
1223 "uninitialized",
1224 "SpeedStream SS1021 or Gigafast WF721-AEX"},
1226 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85},
1227 "non-standard",
1228 "DrayTek Vigor 520"},
1230 {'?', '?', '?', '?', '?', '?'},
1231 "non-standard",
1232 "Level One WPC-0200"},
1234 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1235 "empty",
1236 "DWL-650+ variant"}
1239 static void acx_show_card_eeprom_id(acx_device_t * adev)
1241 unsigned char buffer[CARD_EEPROM_ID_SIZE];
1242 int i;
1244 FN_ENTER;
1246 memset(&buffer, 0, CARD_EEPROM_ID_SIZE);
1247 /* use direct EEPROM access */
1248 for (i = 0; i < CARD_EEPROM_ID_SIZE; i++) {
1249 if (OK != acxpci_read_eeprom_byte(adev,
1250 ACX100_EEPROM_ID_OFFSET + i,
1251 &buffer[i])) {
1252 printk("acx: reading EEPROM FAILED\n");
1253 break;
1257 for (i = 0; i < ARRAY_SIZE(device_ids); i++) {
1258 if (!memcmp(&buffer, device_ids[i].id, CARD_EEPROM_ID_SIZE)) {
1259 if (device_ids[i].descr) {
1260 printk("acx: EEPROM card ID string check "
1261 "found %s card ID: is this %s?\n",
1262 device_ids[i].descr, device_ids[i].type);
1264 break;
1267 if (i == ARRAY_SIZE(device_ids)) {
1268 printk("acx: EEPROM card ID string check found "
1269 "unknown card: expected 'Global', got '%.*s\'. "
1270 "Please report\n", CARD_EEPROM_ID_SIZE, buffer);
1272 FN_EXIT0;
1274 #endif /* NONESSENTIAL_FEATURES */
1277 /***********************************************************************
1278 ** acxpci_free_desc_queues
1280 ** Releases the queues that have been allocated, the
1281 ** others have been initialised to NULL so this
1282 ** function can be used if only part of the queues were allocated.
1285 static inline void
1286 free_coherent(struct pci_dev *hwdev, size_t size,
1287 void *vaddr, dma_addr_t dma_handle)
1289 dma_free_coherent(hwdev == NULL ? NULL : &hwdev->dev,
1290 size, vaddr, dma_handle);
1294 void acxpci_free_desc_queues(acx_device_t * adev)
1296 unsigned long flags;
1298 #define ACX_FREE_QUEUE(size, ptr, phyaddr) \
1299 if (ptr) { \
1300 free_coherent(NULL, size, ptr, phyaddr); \
1301 ptr = NULL; \
1302 size = 0; \
1305 FN_ENTER;
1307 ACX_FREE_QUEUE(adev->txhostdesc_area_size, adev->txhostdesc_start,
1308 adev->txhostdesc_startphy);
1309 ACX_FREE_QUEUE(adev->txbuf_area_size, adev->txbuf_start,
1310 adev->txbuf_startphy);
1312 acx_lock(adev, flags);
1313 adev->txdesc_start = NULL;
1314 acx_unlock(adev, flags);
1316 ACX_FREE_QUEUE(adev->rxhostdesc_area_size, adev->rxhostdesc_start,
1317 adev->rxhostdesc_startphy);
1318 ACX_FREE_QUEUE(adev->rxbuf_area_size, adev->rxbuf_start,
1319 adev->rxbuf_startphy);
1321 acx_lock(adev, flags);
1322 adev->rxdesc_start = NULL;
1323 acx_unlock(adev, flags);
1325 FN_EXIT0;
1329 /***********************************************************************
1330 ** acxpci_s_delete_dma_regions
1332 static void acxpci_s_delete_dma_regions(acx_device_t * adev)
1334 FN_ENTER;
1335 /* disable radio Tx/Rx. Shouldn't we use the firmware commands
1336 * here instead? Or are we that much down the road that it's no
1337 * longer possible here? */
1338 write_reg16(adev, IO_ACX_ENABLE, 0);
1340 acx_s_mwait(100);
1342 /* NO locking for all parts of acxpci_free_desc_queues because:
1343 * while calling dma_free_coherent() interrupts need to be 'free'
1344 * but if you spinlock the whole function (acxpci_free_desc_queues)
1345 * you'll get an error */
1346 acxpci_free_desc_queues(adev);
1348 FN_EXIT0;
1352 /***********************************************************************
1353 ** acxpci_e_probe
1355 ** Probe routine called when a PCI device w/ matching ID is found.
1356 ** Here's the sequence:
1357 ** - Allocate the PCI resources.
1358 ** - Read the PCMCIA attribute memory to make sure we have a WLAN card
1359 ** - Reset the MAC
1360 ** - Initialize the dev and wlan data
1361 ** - Initialize the MAC
1363 ** pdev - ptr to pci device structure containing info about pci configuration
1364 ** id - ptr to the device id entry that matched this device
1366 static const u16 IO_ACX100[] = {
1367 0x0000, /* IO_ACX_SOFT_RESET */
1369 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1370 0x0018, /* IO_ACX_SLV_MEM_DATA */
1371 0x001c, /* IO_ACX_SLV_MEM_CTL */
1372 0x0020, /* IO_ACX_SLV_END_CTL */
1374 0x0034, /* IO_ACX_FEMR */
1376 0x007c, /* IO_ACX_INT_TRIG */
1377 0x0098, /* IO_ACX_IRQ_MASK */
1378 0x00a4, /* IO_ACX_IRQ_STATUS_NON_DES */
1379 0x00a8, /* IO_ACX_IRQ_REASON */
1380 0x00ac, /* IO_ACX_IRQ_ACK */
1381 0x00b0, /* IO_ACX_HINT_TRIG */
1383 0x0104, /* IO_ACX_ENABLE */
1385 0x0250, /* IO_ACX_EEPROM_CTL */
1386 0x0254, /* IO_ACX_EEPROM_ADDR */
1387 0x0258, /* IO_ACX_EEPROM_DATA */
1388 0x025c, /* IO_ACX_EEPROM_CFG */
1390 0x0268, /* IO_ACX_PHY_ADDR */
1391 0x026c, /* IO_ACX_PHY_DATA */
1392 0x0270, /* IO_ACX_PHY_CTL */
1394 0x0290, /* IO_ACX_GPIO_OE */
1396 0x0298, /* IO_ACX_GPIO_OUT */
1398 0x02a4, /* IO_ACX_CMD_MAILBOX_OFFS */
1399 0x02a8, /* IO_ACX_INFO_MAILBOX_OFFS */
1400 0x02ac, /* IO_ACX_EEPROM_INFORMATION */
1402 0x02d0, /* IO_ACX_EE_START */
1403 0x02d4, /* IO_ACX_SOR_CFG */
1404 0x02d8 /* IO_ACX_ECPU_CTRL */
1407 static const u16 IO_ACX111[] = {
1408 0x0000, /* IO_ACX_SOFT_RESET */
1410 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1411 0x0018, /* IO_ACX_SLV_MEM_DATA */
1412 0x001c, /* IO_ACX_SLV_MEM_CTL */
1413 0x0020, /* IO_ACX_SLV_END_CTL */
1415 0x0034, /* IO_ACX_FEMR */
1417 0x00b4, /* IO_ACX_INT_TRIG */
1418 0x00d4, /* IO_ACX_IRQ_MASK */
1419 /* we do mean NON_DES (0xf0), not NON_DES_MASK which is at 0xe0: */
1420 0x00f0, /* IO_ACX_IRQ_STATUS_NON_DES */
1421 0x00e4, /* IO_ACX_IRQ_REASON */
1422 0x00e8, /* IO_ACX_IRQ_ACK */
1423 0x00ec, /* IO_ACX_HINT_TRIG */
1425 0x01d0, /* IO_ACX_ENABLE */
1427 0x0338, /* IO_ACX_EEPROM_CTL */
1428 0x033c, /* IO_ACX_EEPROM_ADDR */
1429 0x0340, /* IO_ACX_EEPROM_DATA */
1430 0x0344, /* IO_ACX_EEPROM_CFG */
1432 0x0350, /* IO_ACX_PHY_ADDR */
1433 0x0354, /* IO_ACX_PHY_DATA */
1434 0x0358, /* IO_ACX_PHY_CTL */
1436 0x0374, /* IO_ACX_GPIO_OE */
1438 0x037c, /* IO_ACX_GPIO_OUT */
1440 0x0388, /* IO_ACX_CMD_MAILBOX_OFFS */
1441 0x038c, /* IO_ACX_INFO_MAILBOX_OFFS */
1442 0x0390, /* IO_ACX_EEPROM_INFORMATION */
1444 0x0100, /* IO_ACX_EE_START */
1445 0x0104, /* IO_ACX_SOR_CFG */
1446 0x0108, /* IO_ACX_ECPU_CTRL */
1449 static const struct ieee80211_ops acxpci_hw_ops = {
1450 .tx = acx_i_start_xmit,
1451 .conf_tx = acx_net_conf_tx,
1452 .add_interface = acx_add_interface,
1453 .remove_interface = acx_remove_interface,
1454 .start = acxpci_e_open,
1455 .configure_filter = acx_i_set_multicast_list,
1456 .stop = acxpci_e_close,
1457 .config = acx_net_config,
1458 .config_interface = acx_config_interface,
1459 .set_key = acx_net_set_key,
1460 .get_stats = acx_e_get_stats,
1461 .get_tx_stats = acx_net_get_tx_stats,
1465 #ifdef CONFIG_PCI
1466 static int __devinit
1467 acxpci_e_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1469 acx111_ie_configoption_t co;
1470 unsigned long mem_region1 = 0;
1471 unsigned long mem_region2 = 0;
1472 unsigned long mem_region1_size;
1473 unsigned long mem_region2_size;
1474 unsigned long phymem1;
1475 unsigned long phymem2;
1476 void *mem1 = NULL;
1477 void *mem2 = NULL;
1478 acx_device_t *adev = NULL;
1479 const char *chip_name;
1480 int result = -EIO;
1481 int err;
1482 u8 chip_type;
1483 struct ieee80211_hw *ieee;
1485 FN_ENTER;
1487 ieee = ieee80211_alloc_hw(sizeof(struct acx_device), &acxpci_hw_ops);
1488 if (!ieee) {
1489 printk("acx: could not allocate ieee80211 structure %s\n",
1490 pci_name(pdev));
1491 goto fail_alloc_netdev;
1493 ieee->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
1494 /* TODO: mainline doesn't support the following flags yet */
1496 ~IEEE80211_HW_MONITOR_DURING_OPER &
1497 ~IEEE80211_HW_WEP_INCLUDE_IV;
1499 ieee->queues = 1;
1501 /* TODO: although in the original driver the maximum value was 100,
1502 * the OpenBSD driver assigns maximum values depending on the type of
1503 * radio transceiver (i.e. Radia, Maxim, etc.). This value is always a
1504 * positive integer which most probably indicates the gain of the AGC
1505 * in the rx path of the chip, in dB steps (0.625 dB, for example?).
1506 * The mapping of this rssi value to dBm is still unknown, but it can
1507 * nevertheless be used as a measure of relative signal strength. The
1508 * other two values, i.e. max_signal and max_noise, do not seem to be
1509 * supported on my acx111 card (they are always 0), although iwconfig
1510 * reports them (in dBm) when using ndiswrapper with the Windows XP
1511 * driver. The GPL-licensed part of the AVM FRITZ!WLAN USB Stick
1512 * driver sources (for the TNETW1450, though) seems to also indicate
1513 * that only the RSSI is supported. In conclusion, the max_signal and
1514 * max_noise values will not be initialised by now, as they do not
1515 * seem to be supported or how to acquire them is still unknown. */
1516 ieee->max_rssi = 100;
1518 adev = ieee2adev(ieee);
1520 memset(adev, 0, sizeof(*adev));
1521 /** Set up our private interface **/
1522 spin_lock_init(&adev->spinlock); /* initial state: unlocked */
1523 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
1524 printk("mutex_init(&adev->mutex); // adev = 0x%px\n", adev);
1525 mutex_init(&adev->mutex);
1526 /* since nobody can see new netdev yet, we can as well
1527 ** just _presume_ that we're under sem (instead of actually taking it): */
1528 /* acx_sem_lock(adev); */
1529 adev->ieee = ieee;
1530 adev->pdev = pdev;
1531 adev->bus_dev = &pdev->dev;
1532 adev->dev_type = DEVTYPE_PCI;
1534 /** Finished with private interface **/
1536 /** begin board specific inits **/
1537 pci_set_drvdata(pdev, ieee);
1539 /* Enable the PCI device */
1540 if (pci_enable_device(pdev)) {
1541 printk("acx: pci_enable_device() FAILED\n");
1542 result = -ENODEV;
1543 goto fail_pci_enable_device;
1546 /* enable busmastering (required for CardBus) */
1547 pci_set_master(pdev);
1550 /* chiptype is u8 but id->driver_data is ulong
1551 ** Works for now (possible values are 1 and 2) */
1552 chip_type = (u8) id->driver_data;
1553 /* acx100 and acx111 have different PCI memory regions */
1554 if (chip_type == CHIPTYPE_ACX100) {
1555 chip_name = "ACX100";
1556 mem_region1 = PCI_ACX100_REGION1;
1557 mem_region1_size = PCI_ACX100_REGION1_SIZE;
1559 mem_region2 = PCI_ACX100_REGION2;
1560 mem_region2_size = PCI_ACX100_REGION2_SIZE;
1561 } else if (chip_type == CHIPTYPE_ACX111) {
1562 chip_name = "ACX111";
1563 mem_region1 = PCI_ACX111_REGION1;
1564 mem_region1_size = PCI_ACX111_REGION1_SIZE;
1566 mem_region2 = PCI_ACX111_REGION2;
1567 mem_region2_size = PCI_ACX111_REGION2_SIZE;
1568 } else {
1569 printk("acx: unknown chip type 0x%04X\n", chip_type);
1570 goto fail_unknown_chiptype;
1573 /* Figure out our resources
1575 * Request our PCI IO regions
1577 err = pci_request_region(pdev, mem_region1, "acx_1");
1578 if (err) {
1579 printk(KERN_WARNING "acx: pci_request_region (1/2) FAILED!"
1580 "No cardbus support in kernel?\n");
1581 goto fail_request_mem_region1;
1584 phymem1 = pci_resource_start(pdev, mem_region1);
1586 err = pci_request_region(pdev, mem_region2, "acx_2");
1587 if (err) {
1588 printk(KERN_WARNING "acx: pci_request_region (2/2) FAILED!\n");
1589 goto fail_request_mem_region2;
1592 phymem2 = pci_resource_start(pdev, mem_region2);
1595 * We got them? Map them!
1597 * We pass 0 as the third argument to pci_iomap(): it will map the full
1598 * region in this case, which is what we want.
1601 mem1 = pci_iomap(pdev, mem_region1, 0);
1602 if (!mem1) {
1603 printk(KERN_WARNING "acx: ioremap() FAILED\n");
1604 goto fail_ioremap1;
1607 mem2 = pci_iomap(pdev, mem_region2, 0);
1608 if (!mem2) {
1609 printk(KERN_WARNING "acx: ioremap() #2 FAILED\n");
1610 goto fail_ioremap2;
1613 printk("acx: found %s-based wireless network card at %s, irq:%d, "
1614 "phymem1:0x%lX, phymem2:0x%lX, mem1:0x%p, mem1_size:%ld, "
1615 "mem2:0x%p, mem2_size:%ld\n",
1616 chip_name, pci_name(pdev), pdev->irq, phymem1, phymem2,
1617 mem1, mem_region1_size, mem2, mem_region2_size);
1618 log(L_ANY, "initial debug setting is 0x%04X\n", acx_debug);
1619 adev->chip_type = chip_type;
1620 adev->chip_name = chip_name;
1621 adev->io = (CHIPTYPE_ACX100 == chip_type) ? IO_ACX100 : IO_ACX111;
1622 adev->membase = phymem1;
1623 adev->iobase = mem1;
1624 adev->membase2 = phymem2;
1625 adev->iobase2 = mem2;
1626 adev->irq = pdev->irq;
1629 if (0 == pdev->irq) {
1630 printk("acx: can't use IRQ 0\n");
1631 goto fail_irq;
1633 SET_IEEE80211_DEV(ieee, &pdev->dev);
1635 /* request shared IRQ handler */
1636 if (request_irq
1637 (adev->irq, acxpci_i_interrupt, IRQF_SHARED, KBUILD_MODNAME, adev)) {
1638 printk("%s: request_irq FAILED\n", wiphy_name(adev->ieee->wiphy));
1639 result = -EAGAIN;
1640 goto done;
1642 log(L_DEBUG | L_IRQ, "request_irq %d successful\n", adev->irq);
1644 /* to find crashes due to weird driver access
1645 * to unconfigured interface (ifup) */
1646 adev->mgmt_timer.function = (void (*)(unsigned long))0x0000dead;
1649 #ifdef NONESSENTIAL_FEATURES
1650 acx_show_card_eeprom_id(adev);
1651 #endif /* NONESSENTIAL_FEATURES */
1654 /* ok, pci setup is finished, now start initializing the card */
1656 /* NB: read_reg() reads may return bogus data before reset_dev(),
1657 * since the firmware which directly controls large parts of the I/O
1658 * registers isn't initialized yet.
1659 * acx100 seems to be more affected than acx111 */
1660 if (OK != acxpci_s_reset_dev(adev))
1661 goto fail_reset;
1663 if (IS_ACX100(adev)) {
1664 /* ACX100: configopt struct in cmd mailbox - directly after reset */
1665 memcpy_fromio(&co, adev->cmd_area, sizeof(co));
1668 if (OK != acx_s_init_mac(adev))
1669 goto fail_init_mac;
1671 if (IS_ACX111(adev)) {
1672 /* ACX111: configopt struct needs to be queried after full init */
1673 acx_s_interrogate(adev, &co, ACX111_IE_CONFIG_OPTIONS);
1675 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
1676 if (OK != acxpci_read_eeprom_byte(adev, 0x05, &adev->eeprom_version))
1677 goto fail_read_eeprom_version;
1679 acx_s_parse_configoption(adev, &co);
1680 acx_s_set_defaults(adev);
1681 acx_s_get_firmware_version(adev); /* needs to be after acx_s_init_mac() */
1682 acx_display_hardware_details(adev);
1684 /* Register the card, AFTER everything else has been set up,
1685 * since otherwise an ioctl could step on our feet due to
1686 * firmware operations happening in parallel or uninitialized data */
1689 acx_proc_register_entries(ieee);
1691 /* Now we have our device, so make sure the kernel doesn't try
1692 * to send packets even though we're not associated to a network yet */
1694 /* after register_netdev() userspace may start working with dev
1695 * (in particular, on other CPUs), we only need to up the sem */
1696 /* acx_sem_unlock(adev); */
1698 printk("acx " ACX_RELEASE ": net device %s, driver compiled "
1699 "against wireless extensions %d and Linux %s\n",
1700 wiphy_name(adev->ieee->wiphy), WIRELESS_EXT, UTS_RELEASE);
1702 MAC_COPY(adev->ieee->wiphy->perm_addr, adev->dev_addr);
1704 log(L_IRQ | L_INIT, "using IRQ %d\n", pdev->irq);
1706 /** done with board specific setup **/
1708 /* need to be able to restore PCI state after a suspend */
1709 #ifdef CONFIG_PM
1710 pci_save_state(pdev);
1711 #endif
1713 err = acx_setup_modes(adev);
1714 if (err) {
1715 printk("can't register hwmode\n");
1716 goto fail_register_netdev;
1719 acx_init_task_scheduler(adev);
1720 err = ieee80211_register_hw(ieee);
1721 if (OK != err) {
1722 printk("acx: ieee80211_register_hw() FAILED: %d\n", err);
1723 goto fail_register_netdev;
1725 #if CMD_DISCOVERY
1726 great_inquisitor(adev);
1727 #endif
1729 result = OK;
1730 goto done;
1732 /* error paths: undo everything in reverse order... */
1735 acxpci_s_delete_dma_regions(adev);
1736 pci_set_drvdata(pdev, NULL);
1738 fail_init_mac:
1739 fail_read_eeprom_version:
1740 fail_reset:
1742 fail_alloc_netdev:
1743 fail_irq:
1744 pci_iounmap(pdev, mem2);
1746 fail_ioremap2:
1747 pci_iounmap(pdev, mem1);
1749 fail_ioremap1:
1750 pci_release_region(pdev, mem_region2);
1752 fail_request_mem_region2:
1753 pci_release_region(pdev, mem_region1);
1755 fail_request_mem_region1:
1756 fail_unknown_chiptype:
1757 pci_disable_device(pdev);
1759 fail_pci_enable_device:
1760 #ifdef CONFIG_PM
1761 pci_set_power_state(pdev, PCI_D3hot);
1762 #endif
1764 fail_register_netdev:
1765 ieee80211_free_hw(ieee);
1766 done:
1767 FN_EXIT1(result);
1768 return result;
1772 /***********************************************************************
1773 ** acxpci_e_remove
1775 ** Shut device down (if not hot unplugged)
1776 ** and deallocate PCI resources for the acx chip.
1778 ** pdev - ptr to PCI device structure containing info about pci configuration
1780 static void __devexit acxpci_e_remove(struct pci_dev *pdev)
1782 struct ieee80211_hw *hw = (struct ieee80211_hw *)pci_get_drvdata(pdev);
1783 acx_device_t *adev = ieee2adev(hw);
1784 unsigned long mem_region1, mem_region2;
1785 unsigned long flags;
1786 FN_ENTER;
1788 if (!hw) {
1789 log(L_DEBUG, "%s: card is unused. Skipping any release code\n",
1790 __func__);
1791 goto end;
1794 /* If device wasn't hot unplugged... */
1795 if (adev_present(adev)) {
1797 /* disable both Tx and Rx to shut radio down properly */
1798 if (adev->initialized) {
1799 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_TX, NULL, 0);
1800 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_RX, NULL, 0);
1801 adev->initialized = 0;
1803 #ifdef REDUNDANT
1804 /* put the eCPU to sleep to save power
1805 * Halting is not possible currently,
1806 * since not supported by all firmware versions */
1807 acx_s_issue_cmd(adev, ACX100_CMD_SLEEP, NULL, 0);
1808 #endif
1809 acx_lock(adev, flags);
1810 /* disable power LED to save power :-) */
1811 log(L_INIT, "switching off power LED to save power\n");
1812 acxpci_l_power_led(adev, 0);
1813 /* stop our eCPU */
1814 if (IS_ACX111(adev)) {
1815 /* FIXME: does this actually keep halting the eCPU?
1816 * I don't think so...
1818 acxpci_l_reset_mac(adev);
1819 } else {
1820 u16 temp;
1821 /* halt eCPU */
1822 temp = read_reg16(adev, IO_ACX_ECPU_CTRL) | 0x1;
1823 write_reg16(adev, IO_ACX_ECPU_CTRL, temp);
1824 write_flush(adev);
1826 acx_unlock(adev, flags);
1830 /* unregister the device to not let the kernel
1831 * (e.g. ioctls) access a half-deconfigured device
1832 * NB: this will cause acxpci_e_close() to be called,
1833 * thus we shouldn't call it under sem!
1835 // acxpci_e_close(hw);
1836 log(L_INIT, "removing device %s\n", wiphy_name(adev->ieee->wiphy));
1837 ieee80211_unregister_hw(adev->ieee);
1839 /* unregister_netdev ensures that no references to us left.
1840 * For paranoid reasons we continue to follow the rules */
1841 acx_sem_lock(adev);
1843 if (adev->dev_state_mask & ACX_STATE_IFACE_UP) {
1844 acxpci_s_down(hw);
1845 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
1848 acx_proc_unregister_entries(adev->ieee);
1850 if (IS_ACX100(adev)) {
1851 mem_region1 = PCI_ACX100_REGION1;
1852 mem_region2 = PCI_ACX100_REGION2;
1853 } else {
1854 mem_region1 = PCI_ACX111_REGION1;
1855 mem_region2 = PCI_ACX111_REGION2;
1858 /* finally, clean up PCI bus state */
1859 acxpci_s_delete_dma_regions(adev);
1860 if (adev->iobase)
1861 iounmap(adev->iobase);
1862 if (adev->iobase2)
1863 iounmap(adev->iobase2);
1864 release_mem_region(pci_resource_start(pdev, mem_region1),
1865 pci_resource_len(pdev, mem_region1));
1866 release_mem_region(pci_resource_start(pdev, mem_region2),
1867 pci_resource_len(pdev, mem_region2));
1868 pci_disable_device(pdev);
1870 /* remove dev registration */
1871 pci_set_drvdata(pdev, NULL);
1873 acx_sem_unlock(adev);
1875 /* Free netdev (quite late,
1876 * since otherwise we might get caught off-guard
1877 * by a netdev timeout handler execution
1878 * expecting to see a working dev...) */
1879 ieee80211_free_hw(adev->ieee);
1881 /* put device into ACPI D3 mode (shutdown) */
1882 #ifdef CONFIG_PM
1883 pci_set_power_state(pdev, PCI_D3hot);
1884 #endif
1885 end:
1886 FN_EXIT0;
1890 /***********************************************************************
1891 ** TODO: PM code needs to be fixed / debugged / tested.
1893 #ifdef CONFIG_PM
1894 static int
1895 acxpci_e_suspend(struct pci_dev *pdev, pm_message_t state)
1897 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1898 acx_device_t *adev;
1900 FN_ENTER;
1901 printk("acx: suspend handler is experimental!\n");
1902 printk("sus: dev %p\n", hw);
1904 /* if (!netif_running(ndev))
1905 goto end;
1907 adev = ieee2adev(hw);
1908 printk("sus: adev %p\n", adev);
1910 acx_sem_lock(adev);
1912 ieee80211_unregister_hw(hw); /* this one cannot sleep */
1913 acxpci_s_down(hw);
1914 /* down() does not set it to 0xffff, but here we really want that */
1915 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
1916 write_reg16(adev, IO_ACX_FEMR, 0x0);
1917 acxpci_s_delete_dma_regions(adev);
1918 pci_save_state(pdev);
1919 pci_set_power_state(pdev, PCI_D3hot);
1921 acx_sem_unlock(adev);
1922 FN_EXIT0;
1923 return OK;
1927 static int acxpci_e_resume(struct pci_dev *pdev)
1929 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1930 acx_device_t *adev;
1932 FN_ENTER;
1934 printk("acx: resume handler is experimental!\n");
1935 printk("rsm: got dev %p\n", hw);
1938 adev = ieee2adev(hw);
1939 printk("rsm: got adev %p\n", adev);
1941 acx_sem_lock(adev);
1943 pci_set_power_state(pdev, PCI_D0);
1944 printk("rsm: power state PCI_D0 set\n");
1945 pci_restore_state(pdev);
1946 printk("rsm: PCI state restored\n");
1948 if (OK != acxpci_s_reset_dev(adev))
1949 goto end_unlock;
1950 printk("rsm: device reset done\n");
1951 if (OK != acx_s_init_mac(adev))
1952 goto end_unlock;
1953 printk("rsm: init MAC done\n");
1955 acxpci_s_up(hw);
1956 printk("rsm: acx up done\n");
1958 /* now even reload all card parameters as they were before suspend,
1959 * and possibly be back in the network again already :-) */
1960 if (ACX_STATE_IFACE_UP & adev->dev_state_mask) {
1961 adev->set_mask = GETSET_ALL;
1962 acx_s_update_card_settings(adev);
1963 printk("rsm: settings updated\n");
1965 ieee80211_register_hw(hw);
1966 printk("rsm: device attached\n");
1968 end_unlock:
1969 acx_sem_unlock(adev);
1970 /* we need to return OK here anyway, right? */
1971 FN_EXIT0;
1972 return OK;
1974 #endif /* CONFIG_PM */
1975 #endif /* CONFIG_PCI */
1977 /***********************************************************************
1978 ** acxpci_s_up
1980 ** This function is called by acxpci_e_open (when ifconfig sets the device as up)
1982 ** Side effects:
1983 ** - Enables on-card interrupt requests
1984 ** - calls acx_s_start
1987 static void enable_acx_irq(acx_device_t * adev)
1989 FN_ENTER;
1990 write_reg16(adev, IO_ACX_IRQ_MASK, adev->irq_mask);
1991 write_reg16(adev, IO_ACX_FEMR, 0x8000);
1992 adev->irqs_active = 1;
1993 FN_EXIT0;
1996 static void acxpci_s_up(struct ieee80211_hw *hw)
1998 acx_device_t *adev = ieee2adev(hw);
1999 unsigned long flags;
2001 FN_ENTER;
2003 acx_lock(adev, flags);
2004 enable_acx_irq(adev);
2005 acx_unlock(adev, flags);
2007 /* acx fw < 1.9.3.e has a hardware timer, and older drivers
2008 ** used to use it. But we don't do that anymore, our OS
2009 ** has reliable software timers */
2010 init_timer(&adev->mgmt_timer);
2011 adev->mgmt_timer.function = acx_i_timer;
2012 adev->mgmt_timer.data = (unsigned long)adev;
2014 /* Need to set ACX_STATE_IFACE_UP first, or else
2015 ** timer won't be started by acx_set_status() */
2016 SET_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
2018 acx_s_start(adev);
2020 FN_EXIT0;
2024 /***********************************************************************
2025 ** acxpci_s_down
2027 ** NB: device may be already hot unplugged if called from acxpci_e_remove()
2029 ** Disables on-card interrupt request, stops softirq and timer, stops queue,
2030 ** sets status == STOPPED
2033 static void disable_acx_irq(acx_device_t * adev)
2035 FN_ENTER;
2037 /* I guess mask is not 0xffff because acx100 won't signal
2038 ** cmd completion then (needed for ifup).
2039 ** I can't ifconfig up after ifconfig down'ing on my acx100 */
2040 write_reg16(adev, IO_ACX_IRQ_MASK, adev->irq_mask_off);
2041 write_reg16(adev, IO_ACX_FEMR, 0x0);
2042 adev->irqs_active = 0;
2044 FN_EXIT0;
2047 static void acxpci_s_down(struct ieee80211_hw *hw)
2049 acx_device_t *adev = ieee2adev(hw);
2051 FN_ENTER;
2053 /* Disable IRQs first, so that IRQs cannot race with us */
2054 /* then wait until interrupts have finished executing on other CPUs */
2055 disable_acx_irq(adev); /* NO sem-locking here? */
2056 synchronize_irq(adev->irq);
2058 /* we really don't want to have an asynchronous tasklet disturb us
2059 ** after something vital for its job has been shut down, so
2060 ** end all remaining work now.
2062 ** NB: carrier_off (done by set_status below) would lead to
2063 ** not yet fully understood deadlock in flush_scheduled_work().
2064 ** That's why we do FLUSH first.
2066 ** NB2: we have a bad locking bug here: flush_scheduled_work()
2067 ** waits for acx_e_after_interrupt_task to complete if it is running
2068 ** on another CPU, but acx_e_after_interrupt_task
2069 ** will sleep on sem forever, because it is taken by us!
2070 ** Work around that by temporary sem unlock.
2071 ** This will fail miserably if we'll be hit by concurrent
2072 ** iwconfig or something in between. TODO! */
2073 acx_sem_unlock(adev);
2074 flush_scheduled_work();
2075 acx_sem_lock(adev);
2077 /* This is possible:
2078 ** flush_scheduled_work -> acx_e_after_interrupt_task ->
2079 ** -> set_status(ASSOCIATED) -> wake_queue()
2080 ** That's why we stop queue _after_ flush_scheduled_work
2081 ** lock/unlock is just paranoia, maybe not needed */
2083 /* kernel/timer.c says it's illegal to del_timer_sync()
2084 ** a timer which restarts itself. We guarantee this cannot
2085 ** ever happen because acx_i_timer() never does this if
2086 ** status is ACX_STATUS_0_STOPPED */
2087 del_timer_sync(&adev->mgmt_timer);
2089 FN_EXIT0;
2092 #ifdef CONFIG_NET_POLL_CONTROLLER
2093 void acxpci_net_poll_controller(struct net_device *net_dev)
2095 acx_device_t *adev = ndev2adev(net_dev);
2096 unsigned long flags;
2098 local_irq_save(flags);
2099 acxpci_i_interrupt(adev->irq, adev);
2100 local_irq_restore(flags);
2102 #endif*/ /* CONFIG_NET_POLL_CONTROLLER */
2104 /***********************************************************************
2105 ** acxpci_e_open
2107 ** Called as a result of SIOCSIFFLAGS ioctl changing the flags bit IFF_UP
2108 ** from clear to set. In other words: ifconfig up.
2110 ** Returns:
2111 ** 0 success
2112 ** >0 f/w reported error
2113 ** <0 driver reported error
2115 static int acxpci_e_open(struct ieee80211_hw *hw)
2117 acx_device_t *adev = ieee2adev(hw);
2118 int result = OK;
2120 FN_ENTER;
2122 acx_sem_lock(adev);
2124 adev->initialized = 0;
2126 /* TODO: pci_set_power_state(pdev, PCI_D0); ? */
2128 /* ifup device */
2129 acxpci_s_up(hw);
2131 /* We don't currently have to do anything else.
2132 * The setup of the MAC should be subsequently completed via
2133 * the mlme commands.
2134 * Higher layers know we're ready from dev->start==1 and
2135 * dev->tbusy==0. Our rx path knows to pass up received/
2136 * frames because of dev->flags&IFF_UP is true.
2138 ieee80211_start_queues(adev->ieee);
2140 adev->initialized = 1;
2141 acx_sem_unlock(adev);
2143 FN_EXIT1(result);
2144 return result;
2148 /***********************************************************************
2149 ** acxpci_e_close
2151 ** This function stops the network functionality of the interface (invoked
2152 ** when the user calls ifconfig <wlan> down). The tx queue is halted and
2153 ** the device is marked as down.
2155 ** Called as a result of SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
2156 ** from set to clear. I.e. called by "ifconfig DEV down"
2158 ** Returns:
2159 ** 0 success
2160 ** >0 f/w reported error
2161 ** <0 driver reported error
2163 static void acxpci_e_close(struct ieee80211_hw *hw)
2165 acx_device_t *adev = ieee2adev(hw);
2167 FN_ENTER;
2169 acx_sem_lock(adev);
2171 /* ifdown device */
2172 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
2173 if (adev->initialized) {
2174 acxpci_s_down(hw);
2177 if (adev->modes)
2178 acx_free_modes(adev);
2179 /* disable all IRQs, release shared IRQ handler */
2180 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
2181 write_reg16(adev, IO_ACX_FEMR, 0x0);
2183 /* TODO: pci_set_power_state(pdev, PCI_D3hot); ? */
2185 /* We currently don't have to do anything else.
2186 * Higher layers know we're not ready from dev->start==0 and
2187 * dev->tbusy==1. Our rx path knows to not pass up received
2188 * frames because of dev->flags&IFF_UP is false.
2190 acx_sem_unlock(adev);
2192 log(L_INIT, "closed device\n");
2193 FN_EXIT0;
2199 /***************************************************************
2200 ** acxpci_l_process_rxdesc
2202 ** Called directly and only from the IRQ handler
2205 #if !ACX_DEBUG
2206 static inline void log_rxbuffer(const acx_device_t * adev)
2209 #else
2210 static void log_rxbuffer(const acx_device_t * adev)
2212 register const struct rxhostdesc *rxhostdesc;
2213 int i;
2215 /* no FN_ENTER here, we don't want that */
2217 rxhostdesc = adev->rxhostdesc_start;
2218 if (unlikely(!rxhostdesc))
2219 return;
2220 for (i = 0; i < RX_CNT; i++) {
2221 if ((rxhostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2222 && (rxhostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2223 printk("rx: buf %d full\n", i);
2224 rxhostdesc++;
2227 #endif
2229 static void acxpci_l_process_rxdesc(acx_device_t * adev)
2231 register rxhostdesc_t *hostdesc;
2232 unsigned count, tail;
2234 FN_ENTER;
2236 if (unlikely(acx_debug & L_BUFR))
2237 log_rxbuffer(adev);
2239 /* First, have a loop to determine the first descriptor that's
2240 * full, just in case there's a mismatch between our current
2241 * rx_tail and the full descriptor we're supposed to handle. */
2242 tail = adev->rx_tail;
2243 count = RX_CNT;
2244 while (1) {
2245 hostdesc = &adev->rxhostdesc_start[tail];
2246 /* advance tail regardless of outcome of the below test */
2247 tail = (tail + 1) % RX_CNT;
2249 if ((hostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2250 && (hostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2251 break; /* found it! */
2253 if (unlikely(!--count)) /* hmm, no luck: all descs empty, bail out */
2254 goto end;
2257 /* now process descriptors, starting with the first we figured out */
2258 while (1) {
2259 log(L_BUFR, "rx: tail=%u Ctl_16=%04X Status=%08X\n",
2260 tail, hostdesc->Ctl_16, hostdesc->Status);
2262 acx_l_process_rxbuf(adev, hostdesc->data);
2263 hostdesc->Status = 0;
2264 /* flush all writes before adapter sees CTL_HOSTOWN change */
2265 wmb();
2266 /* Host no longer owns this, needs to be LAST */
2267 CLEAR_BIT(hostdesc->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
2269 /* ok, descriptor is handled, now check the next descriptor */
2270 hostdesc = &adev->rxhostdesc_start[tail];
2272 /* if next descriptor is empty, then bail out */
2273 if (!(hostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2274 || !(hostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2275 break;
2277 tail = (tail + 1) % RX_CNT;
2279 end:
2280 adev->rx_tail = tail;
2281 FN_EXIT0;
2286 /***********************************************************************
2287 ** acxpci_i_interrupt
2289 ** IRQ handler (atomic context, must not sleep, blah, blah)
2292 /* scan is complete. all frames now on the receive queue are valid */
2293 #define INFO_SCAN_COMPLETE 0x0001
2294 #define INFO_WEP_KEY_NOT_FOUND 0x0002
2295 /* hw has been reset as the result of a watchdog timer timeout */
2296 #define INFO_WATCH_DOG_RESET 0x0003
2297 /* failed to send out NULL frame from PS mode notification to AP */
2298 /* recommended action: try entering 802.11 PS mode again */
2299 #define INFO_PS_FAIL 0x0004
2300 /* encryption/decryption process on a packet failed */
2301 #define INFO_IV_ICV_FAILURE 0x0005
2303 /* Info mailbox format:
2304 2 bytes: type
2305 2 bytes: status
2306 more bytes may follow
2307 rumors say about status:
2308 0x0000 info available (set by hw)
2309 0x0001 information received (must be set by host)
2310 0x1000 info available, mailbox overflowed (messages lost) (set by hw)
2311 but in practice we've seen:
2312 0x9000 when we did not set status to 0x0001 on prev message
2313 0x1001 when we did set it
2314 0x0000 was never seen
2315 conclusion: this is really a bitfield:
2316 0x1000 is 'info available' bit
2317 'mailbox overflowed' bit is 0x8000, not 0x1000
2318 value of 0x0000 probably means that there are no messages at all
2319 P.S. I dunno how in hell hw is supposed to notice that messages are lost -
2320 it does NOT clear bit 0x0001, and this bit will probably stay forever set
2321 after we set it once. Let's hope this will be fixed in firmware someday
2324 static void handle_info_irq(acx_device_t * adev)
2326 #if ACX_DEBUG
2327 static const char *const info_type_msg[] = {
2328 "(unknown)",
2329 "scan complete",
2330 "WEP key not found",
2331 "internal watchdog reset was done",
2332 "failed to send powersave (NULL frame) notification to AP",
2333 "encrypt/decrypt on a packet has failed",
2334 "TKIP tx keys disabled",
2335 "TKIP rx keys disabled",
2336 "TKIP rx: key ID not found",
2337 "???",
2338 "???",
2339 "???",
2340 "???",
2341 "???",
2342 "???",
2343 "???",
2344 "TKIP IV value exceeds thresh"
2346 #endif
2347 u32 info_type, info_status;
2349 info_type = acx_readl(adev->info_area);
2350 info_status = (info_type >> 16);
2351 info_type = (u16) info_type;
2353 /* inform fw that we have read this info message */
2354 acx_writel(info_type | 0x00010000, adev->info_area);
2355 write_reg16(adev, IO_ACX_INT_TRIG, INT_TRIG_INFOACK);
2356 write_flush(adev);
2358 log(L_CTL, "info_type:%04X info_status:%04X\n", info_type, info_status);
2360 log(L_IRQ, "got Info IRQ: status %04X type %04X: %s\n",
2361 info_status, info_type,
2362 info_type_msg[(info_type >= ARRAY_SIZE(info_type_msg)) ?
2363 0 : info_type]
2368 static void log_unusual_irq(u16 irqtype)
2371 if (!printk_ratelimit())
2372 return;
2375 printk("acx: got");
2376 if (irqtype & HOST_INT_RX_DATA) {
2377 printk(" Rx_Data");
2379 /* HOST_INT_TX_COMPLETE */
2380 if (irqtype & HOST_INT_TX_XFER) {
2381 printk(" Tx_Xfer");
2383 /* HOST_INT_RX_COMPLETE */
2384 if (irqtype & HOST_INT_DTIM) {
2385 printk(" DTIM");
2387 if (irqtype & HOST_INT_BEACON) {
2388 printk(" Beacon");
2390 if (irqtype & HOST_INT_TIMER) {
2391 log(L_IRQ, " Timer");
2393 if (irqtype & HOST_INT_KEY_NOT_FOUND) {
2394 printk(" Key_Not_Found");
2396 if (irqtype & HOST_INT_IV_ICV_FAILURE) {
2397 printk(" IV_ICV_Failure (crypto)");
2399 /* HOST_INT_CMD_COMPLETE */
2400 /* HOST_INT_INFO */
2401 if (irqtype & HOST_INT_OVERFLOW) {
2402 printk(" Overflow");
2404 if (irqtype & HOST_INT_PROCESS_ERROR) {
2405 printk(" Process_Error");
2407 /* HOST_INT_SCAN_COMPLETE */
2408 if (irqtype & HOST_INT_FCS_THRESHOLD) {
2409 printk(" FCS_Threshold");
2411 if (irqtype & HOST_INT_UNKNOWN) {
2412 printk(" Unknown");
2414 printk(" IRQ(s)\n");
2417 /* FIXME: update_link_quality_led was a stub - let's comment it and avoid
2418 * compiler warnings */
2420 static void update_link_quality_led(acx_device_t * adev)
2422 int qual;
2424 qual =
2425 acx_signal_determine_quality(adev->wstats.qual.level,
2426 adev->wstats.qual.noise);
2427 if (qual > adev->brange_max_quality)
2428 qual = adev->brange_max_quality;
2430 if (time_after(jiffies, adev->brange_time_last_state_change +
2431 (HZ / 2 -
2432 HZ / 2 * (unsigned long)qual /
2433 adev->brange_max_quality))) {
2434 acxpci_l_power_led(adev, (adev->brange_last_state == 0));
2435 adev->brange_last_state ^= 1; // toggle
2436 adev->brange_time_last_state_change = jiffies;
2441 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* a la orinoco.c */
2443 /* Interrupt handler bottom-half */
2444 void acx_interrupt_tasklet(struct work_struct *work)
2447 #ifdef CONFIG_ACX_MAC80211_DEBUG
2448 u32 _handled = 0x00000000;
2449 # define acxirq_handled(irq) do { _handled |= (irq); } while (0)
2450 #else
2451 # define acxirq_handled(irq) do { /* nothing */ } while (0)
2452 #endif /* CONFIG_ACX_MAC80211_DEBUG */
2453 acx_device_t *adev = container_of(work,struct acx_device, after_interrupt_task);
2454 // unsigned int irqcount = MAX_IRQLOOPS_PER_JIFFY;
2455 int irqtype;
2457 #define IRQ_ITERATE 0
2458 #if IRQ_ITERATE
2459 unsigned int irqcount = MAX_IRQLOOPS_PER_JIFFY;
2460 u16 unmasked;
2461 #endif
2463 FN_ENTER;
2465 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2466 * I am paranoid */
2467 acx_sem_lock(adev);
2469 irqtype = adev->irq_reason;
2470 adev->irq_reason = 0;
2472 #if IRQ_ITERATE
2473 if (jiffies != adev->irq_last_jiffies) {
2474 adev->irq_loops_this_jiffy = 0;
2475 adev->irq_last_jiffies = jiffies;
2478 /* safety condition; we'll normally abort loop below
2479 * in case no IRQ type occurred */
2480 while (likely(--irqcount)) {
2481 #endif
2482 /* ACK all IRQs ASAP */
2484 /* Handle most important IRQ types first */
2485 if (irqtype & HOST_INT_RX_COMPLETE) {
2486 log(L_IRQ, "got Rx_Complete IRQ\n");
2487 acxpci_l_process_rxdesc(adev);
2489 if (irqtype & HOST_INT_TX_COMPLETE) {
2490 log(L_IRQ, "got Tx_Complete IRQ\n");
2491 /* don't clean up on each Tx complete, wait a bit
2492 * unless we're going towards full, in which case
2493 * we do it immediately, too (otherwise we might lockup
2494 * with a full Tx buffer if we go into
2495 * acxpci_l_clean_txdesc() at a time when we won't wakeup
2496 * the net queue in there for some reason...) */
2497 // if (adev->tx_free <= TX_START_CLEAN) {
2498 acxpci_l_clean_txdesc(adev);
2499 // }
2502 /* Less frequent ones */
2503 if (irqtype & (0
2504 | HOST_INT_CMD_COMPLETE
2505 | HOST_INT_INFO | HOST_INT_SCAN_COMPLETE)) {
2506 if (irqtype & HOST_INT_INFO) {
2507 handle_info_irq(adev);
2509 if (irqtype & HOST_INT_SCAN_COMPLETE) {
2510 log(L_IRQ, "got Scan_Complete IRQ\n");
2511 /* need to do that in process context */
2512 /* remember that fw is not scanning anymore */
2513 SET_BIT(adev->irq_status,
2514 HOST_INT_SCAN_COMPLETE);
2518 /* These we just log, but either they happen rarely
2519 * or we keep them masked out */
2520 if (irqtype & (0 | HOST_INT_RX_DATA
2521 /* | HOST_INT_TX_COMPLETE */
2522 | HOST_INT_TX_XFER
2523 /* | HOST_INT_RX_COMPLETE */
2524 | HOST_INT_DTIM
2525 | HOST_INT_BEACON
2526 | HOST_INT_TIMER
2527 | HOST_INT_KEY_NOT_FOUND
2528 | HOST_INT_IV_ICV_FAILURE
2529 /* | HOST_INT_CMD_COMPLETE */
2530 /* | HOST_INT_INFO */
2531 | HOST_INT_OVERFLOW
2532 | HOST_INT_PROCESS_ERROR
2533 /* | HOST_INT_SCAN_COMPLETE */
2534 | HOST_INT_FCS_THRESHOLD
2535 | HOST_INT_UNKNOWN)) {
2536 log_unusual_irq(irqtype);
2538 #if IRQ_ITERATE
2539 unmasked = read_reg16(adev, IO_ACX_IRQ_REASON);
2540 irqtype = unmasked & ~adev->irq_mask;
2541 /* Bail out if no new IRQ bits or if all are masked out */
2542 if (!irqtype)
2543 break;
2545 if (unlikely
2546 (++adev->irq_loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY)) {
2547 printk(KERN_ERR
2548 "acx: too many interrupts per jiffy!\n");
2549 /* Looks like card floods us with IRQs! Try to stop that */
2550 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
2551 /* This will short-circuit all future attempts to handle IRQ.
2552 * We cant do much more... */
2553 adev->irq_mask = 0;
2554 break;
2557 #endif
2558 /* Routine to perform blink with range
2559 * FIXME: update_link_quality_led is a stub - add proper code and enable this again:
2560 if (unlikely(adev->led_power == 2))
2561 update_link_quality_led(adev);
2564 /* write_flush(adev); - not needed, last op was read anyway */
2565 acx_sem_unlock(adev);
2567 /* handled: */
2568 if (adev->after_interrupt_jobs)
2569 acx_e_after_interrupt_task(&adev->after_interrupt_task);
2571 FN_EXIT0;
2572 return;
2577 static irqreturn_t acxpci_i_interrupt(int irq, void *dev_id)
2579 acx_device_t *adev = dev_id;
2580 unsigned long flags;
2581 register u16 irqtype;
2582 u16 unmasked;
2584 FN_ENTER;
2586 if (!adev)
2587 return IRQ_NONE;
2589 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2590 * I am paranoid */
2592 acx_lock(adev, flags);
2595 unmasked = read_reg16(adev, IO_ACX_IRQ_REASON);
2596 if (unlikely(0xffff == unmasked)) {
2597 /* 0xffff value hints at missing hardware,
2598 * so don't do anything.
2599 * Not very clean, but other drivers do the same... */
2600 log(L_IRQ, "IRQ type:FFFF - device removed? IRQ_NONE\n");
2601 goto none;
2604 /* We will check only "interesting" IRQ types */
2605 irqtype = unmasked & ~adev->irq_mask;
2606 if (!irqtype) {
2607 /* We are on a shared IRQ line and it wasn't our IRQ */
2608 log(L_IRQ,
2609 "IRQ type:%04X, mask:%04X - all are masked, IRQ_NONE\n",
2610 unmasked, adev->irq_mask);
2611 goto none;
2614 /* Go ahead and ACK our interrupt */
2615 write_reg16(adev, IO_ACX_IRQ_ACK, 0xffff);
2616 if (irqtype & HOST_INT_CMD_COMPLETE) {
2617 log(L_IRQ, "got Command_Complete IRQ\n");
2618 /* save the state for the running issue_cmd() */
2619 SET_BIT(adev->irq_status, HOST_INT_CMD_COMPLETE);
2622 /* Only accept IRQs, if we are initialized properly.
2623 * This avoids an RX race while initializing.
2624 * We should probably not enable IRQs before we are initialized
2625 * completely, but some careful work is needed to fix this. I think it
2626 * is best to stay with this cheap workaround for now... .
2628 if (likely(adev->initialized)) {
2629 /* disable all IRQs. They are enabled again in the bottom half. */
2630 /* save the reason code and call our bottom half. */
2631 adev->irq_reason = irqtype;
2633 if ((irqtype & HOST_INT_RX_COMPLETE) || (irqtype & HOST_INT_TX_COMPLETE))
2634 acx_schedule_task(adev, 0);
2637 acx_unlock(adev, flags);
2638 FN_EXIT0;
2639 return IRQ_HANDLED;
2640 none:
2641 acx_unlock(adev, flags);
2642 FN_EXIT0;
2643 return IRQ_NONE;
2648 /***********************************************************************
2649 ** acxpci_l_power_led
2651 void acxpci_l_power_led(acx_device_t * adev, int enable)
2653 u16 gpio_pled = IS_ACX111(adev) ? 0x0040 : 0x0800;
2655 /* A hack. Not moving message rate limiting to adev->xxx
2656 * (it's only a debug message after all) */
2657 static int rate_limit = 0;
2659 if (rate_limit++ < 3)
2660 log(L_IOCTL, "Please report in case toggling the power "
2661 "LED doesn't work for your card!\n");
2662 if (enable)
2663 write_reg16(adev, IO_ACX_GPIO_OUT,
2664 read_reg16(adev, IO_ACX_GPIO_OUT) & ~gpio_pled);
2665 else
2666 write_reg16(adev, IO_ACX_GPIO_OUT,
2667 read_reg16(adev, IO_ACX_GPIO_OUT) | gpio_pled);
2671 /***********************************************************************
2672 ** Ioctls
2675 /***********************************************************************
2677 #if 0
2679 acx111pci_ioctl_info(struct net_device *ndev,
2680 struct iw_request_info *info,
2681 struct iw_param *vwrq, char *extra)
2683 #if ACX_DEBUG > 1
2684 acx_device_t *adev = ndev2adev(ndev);
2685 rxdesc_t *rxdesc;
2686 txdesc_t *txdesc;
2687 rxhostdesc_t *rxhostdesc;
2688 txhostdesc_t *txhostdesc;
2689 struct acx111_ie_memoryconfig memconf;
2690 struct acx111_ie_queueconfig queueconf;
2691 unsigned long flags;
2692 int i;
2693 char memmap[0x34];
2694 char rxconfig[0x8];
2695 char fcserror[0x8];
2696 char ratefallback[0x5];
2698 if (!(acx_debug & (L_IOCTL | L_DEBUG)))
2699 return OK;
2700 /* using printk() since we checked debug flag already */
2702 acx_sem_lock(adev);
2704 if (!IS_ACX111(adev)) {
2705 printk("acx111-specific function called "
2706 "with non-acx111 chip, aborting\n");
2707 goto end_ok;
2710 /* get Acx111 Memory Configuration */
2711 memset(&memconf, 0, sizeof(memconf));
2712 /* BTW, fails with 12 (Write only) error code.
2713 ** Retained for easy testing of issue_cmd error handling :) */
2714 acx_s_interrogate(adev, &memconf, ACX1xx_IE_QUEUE_CONFIG);
2716 /* get Acx111 Queue Configuration */
2717 memset(&queueconf, 0, sizeof(queueconf));
2718 acx_s_interrogate(adev, &queueconf, ACX1xx_IE_MEMORY_CONFIG_OPTIONS);
2720 /* get Acx111 Memory Map */
2721 memset(memmap, 0, sizeof(memmap));
2722 acx_s_interrogate(adev, &memmap, ACX1xx_IE_MEMORY_MAP);
2724 /* get Acx111 Rx Config */
2725 memset(rxconfig, 0, sizeof(rxconfig));
2726 acx_s_interrogate(adev, &rxconfig, ACX1xx_IE_RXCONFIG);
2728 /* get Acx111 fcs error count */
2729 memset(fcserror, 0, sizeof(fcserror));
2730 acx_s_interrogate(adev, &fcserror, ACX1xx_IE_FCS_ERROR_COUNT);
2732 /* get Acx111 rate fallback */
2733 memset(ratefallback, 0, sizeof(ratefallback));
2734 acx_s_interrogate(adev, &ratefallback, ACX1xx_IE_RATE_FALLBACK);
2736 /* force occurrence of a beacon interrupt */
2737 /* TODO: comment why is this necessary */
2738 write_reg16(adev, IO_ACX_HINT_TRIG, HOST_INT_BEACON);
2740 /* dump Acx111 Mem Configuration */
2741 printk("dump mem config:\n"
2742 "data read: %d, struct size: %d\n"
2743 "Number of stations: %1X\n"
2744 "Memory block size: %1X\n"
2745 "tx/rx memory block allocation: %1X\n"
2746 "count rx: %X / tx: %X queues\n"
2747 "options %1X\n"
2748 "fragmentation %1X\n"
2749 "Rx Queue 1 Count Descriptors: %X\n"
2750 "Rx Queue 1 Host Memory Start: %X\n"
2751 "Tx Queue 1 Count Descriptors: %X\n"
2752 "Tx Queue 1 Attributes: %X\n",
2753 memconf.len, (int)sizeof(memconf),
2754 memconf.no_of_stations,
2755 memconf.memory_block_size,
2756 memconf.tx_rx_memory_block_allocation,
2757 memconf.count_rx_queues, memconf.count_tx_queues,
2758 memconf.options,
2759 memconf.fragmentation,
2760 memconf.rx_queue1_count_descs,
2761 acx2cpu(memconf.rx_queue1_host_rx_start),
2762 memconf.tx_queue1_count_descs, memconf.tx_queue1_attributes);
2764 /* dump Acx111 Queue Configuration */
2765 printk("dump queue head:\n"
2766 "data read: %d, struct size: %d\n"
2767 "tx_memory_block_address (from card): %X\n"
2768 "rx_memory_block_address (from card): %X\n"
2769 "rx1_queue address (from card): %X\n"
2770 "tx1_queue address (from card): %X\n"
2771 "tx1_queue attributes (from card): %X\n",
2772 queueconf.len, (int)sizeof(queueconf),
2773 queueconf.tx_memory_block_address,
2774 queueconf.rx_memory_block_address,
2775 queueconf.rx1_queue_address,
2776 queueconf.tx1_queue_address, queueconf.tx1_attributes);
2778 /* dump Acx111 Mem Map */
2779 printk("dump mem map:\n"
2780 "data read: %d, struct size: %d\n"
2781 "Code start: %X\n"
2782 "Code end: %X\n"
2783 "WEP default key start: %X\n"
2784 "WEP default key end: %X\n"
2785 "STA table start: %X\n"
2786 "STA table end: %X\n"
2787 "Packet template start: %X\n"
2788 "Packet template end: %X\n"
2789 "Queue memory start: %X\n"
2790 "Queue memory end: %X\n"
2791 "Packet memory pool start: %X\n"
2792 "Packet memory pool end: %X\n"
2793 "iobase: %p\n"
2794 "iobase2: %p\n",
2795 *((u16 *) & memmap[0x02]), (int)sizeof(memmap),
2796 *((u32 *) & memmap[0x04]),
2797 *((u32 *) & memmap[0x08]),
2798 *((u32 *) & memmap[0x0C]),
2799 *((u32 *) & memmap[0x10]),
2800 *((u32 *) & memmap[0x14]),
2801 *((u32 *) & memmap[0x18]),
2802 *((u32 *) & memmap[0x1C]),
2803 *((u32 *) & memmap[0x20]),
2804 *((u32 *) & memmap[0x24]),
2805 *((u32 *) & memmap[0x28]),
2806 *((u32 *) & memmap[0x2C]),
2807 *((u32 *) & memmap[0x30]), adev->iobase, adev->iobase2);
2809 /* dump Acx111 Rx Config */
2810 printk("dump rx config:\n"
2811 "data read: %d, struct size: %d\n"
2812 "rx config: %X\n"
2813 "rx filter config: %X\n",
2814 *((u16 *) & rxconfig[0x02]), (int)sizeof(rxconfig),
2815 *((u16 *) & rxconfig[0x04]), *((u16 *) & rxconfig[0x06]));
2817 /* dump Acx111 fcs error */
2818 printk("dump fcserror:\n"
2819 "data read: %d, struct size: %d\n"
2820 "fcserrors: %X\n",
2821 *((u16 *) & fcserror[0x02]), (int)sizeof(fcserror),
2822 *((u32 *) & fcserror[0x04]));
2824 /* dump Acx111 rate fallback */
2825 printk("dump rate fallback:\n"
2826 "data read: %d, struct size: %d\n"
2827 "ratefallback: %X\n",
2828 *((u16 *) & ratefallback[0x02]), (int)sizeof(ratefallback),
2829 *((u8 *) & ratefallback[0x04]));
2831 /* protect against IRQ */
2832 acx_lock(adev, flags);
2834 /* dump acx111 internal rx descriptor ring buffer */
2835 rxdesc = adev->rxdesc_start;
2837 /* loop over complete receive pool */
2838 if (rxdesc)
2839 for (i = 0; i < RX_CNT; i++) {
2840 printk("\ndump internal rxdesc %d:\n"
2841 "mem pos %p\n"
2842 "next 0x%X\n"
2843 "acx mem pointer (dynamic) 0x%X\n"
2844 "CTL (dynamic) 0x%X\n"
2845 "Rate (dynamic) 0x%X\n"
2846 "RxStatus (dynamic) 0x%X\n"
2847 "Mod/Pre (dynamic) 0x%X\n",
2849 rxdesc,
2850 acx2cpu(rxdesc->pNextDesc),
2851 acx2cpu(rxdesc->ACXMemPtr),
2852 rxdesc->Ctl_8,
2853 rxdesc->rate, rxdesc->error, rxdesc->SNR);
2854 rxdesc++;
2857 /* dump host rx descriptor ring buffer */
2859 rxhostdesc = adev->rxhostdesc_start;
2861 /* loop over complete receive pool */
2862 if (rxhostdesc)
2863 for (i = 0; i < RX_CNT; i++) {
2864 printk("\ndump host rxdesc %d:\n"
2865 "mem pos %p\n"
2866 "buffer mem pos 0x%X\n"
2867 "buffer mem offset 0x%X\n"
2868 "CTL 0x%X\n"
2869 "Length 0x%X\n"
2870 "next 0x%X\n"
2871 "Status 0x%X\n",
2873 rxhostdesc,
2874 acx2cpu(rxhostdesc->data_phy),
2875 rxhostdesc->data_offset,
2876 le16_to_cpu(rxhostdesc->Ctl_16),
2877 le16_to_cpu(rxhostdesc->length),
2878 acx2cpu(rxhostdesc->desc_phy_next),
2879 rxhostdesc->Status);
2880 rxhostdesc++;
2883 /* dump acx111 internal tx descriptor ring buffer */
2884 txdesc = adev->txdesc_start;
2886 /* loop over complete transmit pool */
2887 if (txdesc)
2888 for (i = 0; i < TX_CNT; i++) {
2889 printk("\ndump internal txdesc %d:\n"
2890 "size 0x%X\n"
2891 "mem pos %p\n"
2892 "next 0x%X\n"
2893 "acx mem pointer (dynamic) 0x%X\n"
2894 "host mem pointer (dynamic) 0x%X\n"
2895 "length (dynamic) 0x%X\n"
2896 "CTL (dynamic) 0x%X\n"
2897 "CTL2 (dynamic) 0x%X\n"
2898 "Status (dynamic) 0x%X\n"
2899 "Rate (dynamic) 0x%X\n",
2901 (int)sizeof(struct txdesc),
2902 txdesc,
2903 acx2cpu(txdesc->pNextDesc),
2904 acx2cpu(txdesc->AcxMemPtr),
2905 acx2cpu(txdesc->HostMemPtr),
2906 le16_to_cpu(txdesc->total_length),
2907 txdesc->Ctl_8,
2908 txdesc->Ctl2_8, txdesc->error,
2909 txdesc->u.r1.rate);
2910 txdesc = advance_txdesc(adev, txdesc, 1);
2913 /* dump host tx descriptor ring buffer */
2915 txhostdesc = adev->txhostdesc_start;
2917 /* loop over complete host send pool */
2918 if (txhostdesc)
2919 for (i = 0; i < TX_CNT * 2; i++) {
2920 printk("\ndump host txdesc %d:\n"
2921 "mem pos %p\n"
2922 "buffer mem pos 0x%X\n"
2923 "buffer mem offset 0x%X\n"
2924 "CTL 0x%X\n"
2925 "Length 0x%X\n"
2926 "next 0x%X\n"
2927 "Status 0x%X\n",
2929 txhostdesc,
2930 acx2cpu(txhostdesc->data_phy),
2931 txhostdesc->data_offset,
2932 le16_to_cpu(txhostdesc->Ctl_16),
2933 le16_to_cpu(txhostdesc->length),
2934 acx2cpu(txhostdesc->desc_phy_next),
2935 le32_to_cpu(txhostdesc->Status));
2936 txhostdesc++;
2939 /* write_reg16(adev, 0xb4, 0x4); */
2941 acx_unlock(adev, flags);
2942 end_ok:
2944 acx_sem_unlock(adev);
2945 #endif /* ACX_DEBUG */
2946 return OK;
2950 /***********************************************************************
2953 acx100pci_ioctl_set_phy_amp_bias(struct net_device *ndev,
2954 struct iw_request_info *info,
2955 struct iw_param *vwrq, char *extra)
2957 acx_device_t *adev = ndev2adev(ndev);
2958 unsigned long flags;
2959 u16 gpio_old;
2961 if (!IS_ACX100(adev)) {
2962 /* WARNING!!!
2963 * Removing this check *might* damage
2964 * hardware, since we're tweaking GPIOs here after all!!!
2965 * You've been warned...
2966 * WARNING!!! */
2967 printk("acx: sorry, setting bias level for non-acx100 "
2968 "is not supported yet\n");
2969 return OK;
2972 if (*extra > 7) {
2973 printk("acx: invalid bias parameter, range is 0-7\n");
2974 return -EINVAL;
2977 acx_sem_lock(adev);
2979 /* Need to lock accesses to [IO_ACX_GPIO_OUT]:
2980 * IRQ handler uses it to update LED */
2981 acx_lock(adev, flags);
2982 gpio_old = read_reg16(adev, IO_ACX_GPIO_OUT);
2983 write_reg16(adev, IO_ACX_GPIO_OUT,
2984 (gpio_old & 0xf8ff) | ((u16) * extra << 8));
2985 acx_unlock(adev, flags);
2987 log(L_DEBUG, "gpio_old: 0x%04X\n", gpio_old);
2988 printk("%s: PHY power amplifier bias: old:%d, new:%d\n",
2989 ndev->name, (gpio_old & 0x0700) >> 8, (unsigned char)*extra);
2991 acx_sem_unlock(adev);
2993 return OK;
2995 #endif
2997 /***************************************************************
2998 ** acxpci_l_alloc_tx
2999 ** Actually returns a txdesc_t* ptr
3001 ** FIXME: in case of fragments, should allocate multiple descrs
3002 ** after figuring out how many we need and whether we still have
3003 ** sufficiently many.
3005 tx_t *acxpci_l_alloc_tx(acx_device_t * adev)
3007 struct txdesc *txdesc;
3008 unsigned head;
3009 u8 ctl8;
3011 FN_ENTER;
3013 if (unlikely(!adev->tx_free)) {
3014 printk("acx: BUG: no free txdesc left\n");
3015 txdesc = NULL;
3016 goto end;
3019 head = adev->tx_head;
3020 txdesc = get_txdesc(adev, head);
3021 ctl8 = txdesc->Ctl_8;
3023 /* 2005-10-11: there were several bug reports on this happening
3024 ** but now cause seems to be understood & fixed */
3025 if (unlikely(DESC_CTL_HOSTOWN != (ctl8 & DESC_CTL_ACXDONE_HOSTOWN))) {
3026 /* whoops, descr at current index is not free, so probably
3027 * ring buffer already full */
3028 printk("acx: BUG: tx_head:%d Ctl8:0x%02X - failed to find "
3029 "free txdesc\n", head, ctl8);
3030 txdesc = NULL;
3031 goto end;
3034 /* Needed in case txdesc won't be eventually submitted for tx */
3035 txdesc->Ctl_8 = DESC_CTL_ACXDONE_HOSTOWN;
3037 adev->tx_free--;
3038 log(L_BUFT, "tx: got desc %u, %u remain\n", head, adev->tx_free);
3039 /* Keep a few free descs between head and tail of tx ring.
3040 ** It is not absolutely needed, just feels safer */
3041 if (adev->tx_free < TX_STOP_QUEUE) {
3042 log(L_BUF, "stop queue (%u tx desc left)\n", adev->tx_free);
3043 acx_stop_queue(adev->ieee, NULL);
3046 /* returning current descriptor, so advance to next free one */
3047 adev->tx_head = (head + 1) % TX_CNT;
3048 end:
3049 FN_EXIT0;
3051 return (tx_t *) txdesc;
3055 /***********************************************************************
3057 void *acxpci_l_get_txbuf(acx_device_t * adev, tx_t * tx_opaque)
3059 return get_txhostdesc(adev, (txdesc_t *) tx_opaque)->data;
3063 /***********************************************************************
3064 ** acxpci_l_tx_data
3066 ** Can be called from IRQ (rx -> (AP bridging or mgmt response) -> tx).
3067 ** Can be called from acx_i_start_xmit (data frames from net core).
3069 ** FIXME: in case of fragments, should loop over the number of
3070 ** pre-allocated tx descrs, properly setting up transfer data and
3071 ** CTL_xxx flags according to fragment number.
3073 void
3074 acxpci_l_tx_data(acx_device_t * adev, tx_t * tx_opaque, int len,
3075 struct ieee80211_tx_control *ieeectl,struct sk_buff* skb)
3077 txdesc_t *txdesc = (txdesc_t *) tx_opaque;
3078 struct ieee80211_hdr *wireless_header;
3079 txhostdesc_t *hostdesc1, *hostdesc2;
3080 int rate_cur;
3081 u8 Ctl_8, Ctl2_8;
3082 int wlhdr_len;
3084 FN_ENTER;
3086 /* fw doesn't tx such packets anyhow */
3087 /* if (unlikely(len < WLAN_HDR_A3_LEN))
3088 goto end;
3090 hostdesc1 = get_txhostdesc(adev, txdesc);
3091 wireless_header = (struct ieee80211_hdr *)hostdesc1->data;
3092 /* modify flag status in separate variable to be able to write it back
3093 * in one big swoop later (also in order to have less device memory
3094 * accesses) */
3095 Ctl_8 = txdesc->Ctl_8;
3096 Ctl2_8 = 0; /* really need to init it to 0, not txdesc->Ctl2_8, it seems */
3098 hostdesc2 = hostdesc1 + 1;
3100 /* DON'T simply set Ctl field to 0 here globally,
3101 * it needs to maintain a consistent flag status (those are state flags!!),
3102 * otherwise it may lead to severe disruption. Only set or reset particular
3103 * flags at the exact moment this is needed... */
3105 /* let chip do RTS/CTS handshaking before sending
3106 * in case packet size exceeds threshold */
3107 if (ieeectl->flags & IEEE80211_TXCTL_USE_RTS_CTS)
3108 SET_BIT(Ctl2_8, DESC_CTL2_RTS);
3109 else
3110 CLEAR_BIT(Ctl2_8, DESC_CTL2_RTS);
3112 rate_cur = ieeectl->tx_rate;
3113 if (unlikely(!rate_cur)) {
3114 printk("acx: driver bug! bad ratemask\n");
3115 goto end;
3118 /* used in tx cleanup routine for auto rate and accounting: */
3119 /* put_txcr(adev, txdesc, clt, rate_cur); deprecated by mac80211 */
3121 txdesc->total_length = cpu_to_le16(len);
3122 wlhdr_len = ieee80211_get_hdrlen(le16_to_cpu(wireless_header->frame_control));
3123 hostdesc2->length = cpu_to_le16(len - wlhdr_len);
3125 if (!ieeectl->do_not_encrypt && ieeectl->key_idx>= 0)
3127 u16 key_idx = (u16)(ieeectl->key_idx);
3128 struct acx_key* key = &(adev->key[key_idx]);
3129 int wlhdr_len;
3130 if (key->enabled)
3132 memcpy(ieeehdr->wep_iv, ((u8*)wireless_header) + wlhdr_len, 4);
3136 if (IS_ACX111(adev)) {
3137 /* note that if !txdesc->do_auto, txrate->cur
3138 ** has only one nonzero bit */
3139 txdesc->u.r2.rate111 = cpu_to_le16(rate_cur
3140 /* WARNING: I was never able to make it work with prism54 AP.
3141 ** It was falling down to 1Mbit where shortpre is not applicable,
3142 ** and not working at all at "5,11 basic rates only" setting.
3143 ** I even didn't see tx packets in radio packet capture.
3144 ** Disabled for now --vda */
3145 /*| ((clt->shortpre && clt->cur!=RATE111_1) ? RATE111_SHORTPRE : 0) */
3147 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3148 /* should add this to rate111 above as necessary */
3149 |(clt->pbcc511 ? RATE111_PBCC511 : 0)
3150 #endif
3151 hostdesc1->length = cpu_to_le16(len);
3152 } else { /* ACX100 */
3153 u8 rate_100 = ieeectl->tx_rate;
3154 txdesc->u.r1.rate = rate_100;
3155 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3156 if (clt->pbcc511) {
3157 if (n == RATE100_5 || n == RATE100_11)
3158 n |= RATE100_PBCC511;
3161 if (clt->shortpre && (clt->cur != RATE111_1))
3162 SET_BIT(Ctl_8, DESC_CTL_SHORT_PREAMBLE); /* set Short Preamble */
3163 #endif
3164 /* set autodma and reclaim and 1st mpdu */
3165 SET_BIT(Ctl_8,
3166 DESC_CTL_AUTODMA | DESC_CTL_RECLAIM |
3167 DESC_CTL_FIRSTFRAG);
3168 #if ACX_FRAGMENTATION
3169 /* SET_BIT(Ctl2_8, DESC_CTL2_MORE_FRAG); cannot set it unconditionally, needs to be set for all non-last fragments */
3170 #endif
3171 hostdesc1->length = cpu_to_le16(wlhdr_len);
3173 /* don't need to clean ack/rts statistics here, already
3174 * done on descr cleanup */
3176 /* clears HOSTOWN and ACXDONE bits, thus telling that the descriptors
3177 * are now owned by the acx100; do this as LAST operation */
3178 CLEAR_BIT(Ctl_8, DESC_CTL_ACXDONE_HOSTOWN);
3179 /* flush writes before we release hostdesc to the adapter here */
3180 wmb();
3181 CLEAR_BIT(hostdesc1->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3182 CLEAR_BIT(hostdesc2->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3184 /* write back modified flags */
3185 CLEAR_BIT(Ctl2_8, DESC_CTL2_WEP);
3186 txdesc->Ctl2_8 = Ctl2_8;
3187 txdesc->Ctl_8 = Ctl_8;
3188 /* unused: txdesc->tx_time = cpu_to_le32(jiffies); */
3190 /* flush writes before we tell the adapter that it's its turn now */
3191 write_reg16(adev, IO_ACX_INT_TRIG, INT_TRIG_TXPRC);
3192 write_flush(adev);
3193 /* log the packet content AFTER sending it,
3194 * in order to not delay sending any further than absolutely needed
3195 * Do separate logs for acx100/111 to have human-readable rates */
3196 memcpy(&(hostdesc1->txstatus.control),ieeectl,sizeof(struct ieee80211_tx_control));
3197 hostdesc1->skb = skb;
3198 end:
3199 FN_EXIT0;
3203 /***********************************************************************
3204 ** acxpci_l_clean_txdesc
3206 ** This function resets the txdescs' status when the ACX100
3207 ** signals the TX done IRQ (txdescs have been processed), starting with
3208 ** the pool index of the descriptor which we would use next,
3209 ** in order to make sure that we can be as fast as possible
3210 ** in filling new txdescs.
3211 ** Everytime we get called we know where the next packet to be cleaned is.
3214 #if !ACX_DEBUG
3215 static inline void log_txbuffer(const acx_device_t * adev)
3218 #else
3219 static void log_txbuffer(acx_device_t * adev)
3221 txdesc_t *txdesc;
3222 int i;
3224 /* no FN_ENTER here, we don't want that */
3225 /* no locks here, since it's entirely non-critical code */
3226 txdesc = adev->txdesc_start;
3227 if (unlikely(!txdesc))
3228 return;
3229 printk("tx: desc->Ctl8's:");
3230 for (i = 0; i < TX_CNT; i++) {
3231 printk(" %02X", txdesc->Ctl_8);
3232 txdesc = advance_txdesc(adev, txdesc, 1);
3234 printk("\n");
3236 #endif
3239 static void handle_tx_error(acx_device_t * adev, u8 error, unsigned int finger,
3240 struct ieee80211_tx_status *status)
3242 const char *err = "unknown error";
3244 /* hmm, should we handle this as a mask
3245 * of *several* bits?
3246 * For now I think only caring about
3247 * individual bits is ok... */
3248 switch (error) {
3249 case 0x01:
3250 err = "no Tx due to error in other fragment";
3251 /* adev->wstats.discard.fragment++; */
3252 break;
3253 case 0x02:
3254 err = "Tx aborted";
3255 adev->stats.tx_aborted_errors++;
3256 break;
3257 case 0x04:
3258 err = "Tx desc wrong parameters";
3259 /* adev->wstats.discard.misc++; */
3260 break;
3261 case 0x08:
3262 err = "WEP key not found";
3263 /* adev->wstats.discard.misc++; */
3264 break;
3265 case 0x10:
3266 err = "MSDU lifetime timeout? - try changing "
3267 "'iwconfig retry lifetime XXX'";
3268 /* adev->wstats.discard.misc++; */
3269 break;
3270 case 0x20:
3271 err = "excessive Tx retries due to either distance "
3272 "too high or unable to Tx or Tx frame error - "
3273 "try changing 'iwconfig txpower XXX' or "
3274 "'sens'itivity or 'retry'";
3275 /* adev->wstats.discard.retries++; */
3276 /* Tx error 0x20 also seems to occur on
3277 * overheating, so I'm not sure whether we
3278 * actually want to do aggressive radio recalibration,
3279 * since people maybe won't notice then that their hardware
3280 * is slowly getting cooked...
3281 * Or is it still a safe long distance from utter
3282 * radio non-functionality despite many radio recalibs
3283 * to final destructive overheating of the hardware?
3284 * In this case we really should do recalib here...
3285 * I guess the only way to find out is to do a
3286 * potentially fatal self-experiment :-\
3287 * Or maybe only recalib in case we're using Tx
3288 * rate auto (on errors switching to lower speed
3289 * --> less heat?) or 802.11 power save mode?
3291 * ok, just do it. */
3292 if (++adev->retry_errors_msg_ratelimit % 4 == 0) {
3293 if (adev->retry_errors_msg_ratelimit <= 20) {
3294 printk("%s: several excessive Tx "
3295 "retry errors occurred, attempting "
3296 "to recalibrate radio. Radio "
3297 "drift might be caused by increasing "
3298 "card temperature, please check the card "
3299 "before it's too late!\n",
3300 wiphy_name(adev->ieee->wiphy));
3301 if (adev->retry_errors_msg_ratelimit == 20)
3302 printk("disabling above message\n");
3305 acx_schedule_task(adev,
3306 ACX_AFTER_IRQ_CMD_RADIO_RECALIB);
3308 status->excessive_retries++;
3309 break;
3310 case 0x40:
3311 err = "Tx buffer overflow";
3312 adev->stats.tx_fifo_errors++;
3313 break;
3314 case 0x80:
3315 /* possibly ACPI C-state powersaving related!!!
3316 * (DMA timeout due to excessively high wakeup
3317 * latency after C-state activation!?)
3318 * Disable C-State powersaving and try again,
3319 * then PLEASE REPORT, I'm VERY interested in
3320 * whether my theory is correct that this is
3321 * actually the problem here.
3322 * In that case, use new Linux idle wakeup latency
3323 * requirements kernel API to prevent this issue. */
3324 err = "DMA error";
3325 /* adev->wstats.discard.misc++; */
3326 break;
3328 adev->stats.tx_errors++;
3329 if (adev->stats.tx_errors <= 20)
3330 printk("%s: tx error 0x%02X, buf %02u! (%s)\n",
3331 wiphy_name(adev->ieee->wiphy), error, finger, err);
3332 else
3333 printk("%s: tx error 0x%02X, buf %02u!\n",
3334 wiphy_name(adev->ieee->wiphy), error, finger);
3338 unsigned int acxpci_l_clean_txdesc(acx_device_t * adev)
3340 txdesc_t *txdesc;
3341 txhostdesc_t *hostdesc;
3342 unsigned finger;
3343 int num_cleaned;
3344 u16 r111;
3345 u8 error, ack_failures, rts_failures, rts_ok, r100;
3347 FN_ENTER;
3349 if (unlikely(acx_debug & L_DEBUG))
3350 log_txbuffer(adev);
3352 log(L_BUFT, "tx: cleaning up bufs from %u\n", adev->tx_tail);
3354 /* We know first descr which is not free yet. We advance it as far
3355 ** as we see correct bits set in following descs (if next desc
3356 ** is NOT free, we shouldn't advance at all). We know that in
3357 ** front of tx_tail may be "holes" with isolated free descs.
3358 ** We will catch up when all intermediate descs will be freed also */
3360 finger = adev->tx_tail;
3361 num_cleaned = 0;
3362 while (likely(finger != adev->tx_head)) {
3363 txdesc = get_txdesc(adev, finger);
3365 /* If we allocated txdesc on tx path but then decided
3366 ** to NOT use it, then it will be left as a free "bubble"
3367 ** in the "allocated for tx" part of the ring.
3368 ** We may meet it on the next ring pass here. */
3370 /* stop if not marked as "tx finished" and "host owned" */
3371 if ((txdesc->Ctl_8 & DESC_CTL_ACXDONE_HOSTOWN)
3372 != DESC_CTL_ACXDONE_HOSTOWN) {
3373 if (unlikely(!num_cleaned)) { /* maybe remove completely */
3374 log(L_BUFT, "clean_txdesc: tail isn't free. "
3375 "tail:%d head:%d\n",
3376 adev->tx_tail, adev->tx_head);
3378 break;
3381 /* remember desc values... */
3382 error = txdesc->error;
3383 ack_failures = txdesc->ack_failures;
3384 rts_failures = txdesc->rts_failures;
3385 rts_ok = txdesc->rts_ok;
3386 r100 = txdesc->u.r1.rate;
3387 r111 = le16_to_cpu(txdesc->u.r2.rate111);
3389 /* need to check for certain error conditions before we
3390 * clean the descriptor: we still need valid descr data here */
3391 hostdesc = get_txhostdesc(adev, txdesc);
3393 hostdesc->txstatus.flags |= IEEE80211_TX_STATUS_ACK;
3394 if (unlikely(0x30 & error)) {
3395 /* only send IWEVTXDROP in case of retry or lifetime exceeded;
3396 * all other errors mean we screwed up locally */
3397 /* union iwreq_data wrqu;
3398 struct ieee80211_hdr_3addr *hdr;
3399 hdr = (struct ieee80211_hdr_3addr *) hostdesc->data;
3400 MAC_COPY(wrqu.addr.sa_data, hdr->addr1);
3402 hostdesc->txstatus.flags &= ~IEEE80211_TX_STATUS_ACK;
3405 /* ...and free the desc */
3406 txdesc->error = 0;
3407 txdesc->ack_failures = 0;
3408 txdesc->rts_failures = 0;
3409 txdesc->rts_ok = 0;
3410 /* signal host owning it LAST, since ACX already knows that this
3411 ** descriptor is finished since it set Ctl_8 accordingly. */
3412 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3414 adev->tx_free++;
3415 num_cleaned++;
3417 if ((adev->tx_free >= TX_START_QUEUE)
3418 /* && (adev->status == ACX_STATUS_4_ASSOCIATED) */
3419 /*&& (acx_queue_stopped(adev->ieee))*/
3421 log(L_BUF, "tx: wake queue (avail. Tx desc %u)\n",
3422 adev->tx_free);
3423 acx_wake_queue(adev->ieee, NULL);
3426 /* do error checking, rate handling and logging
3427 * AFTER having done the work, it's faster */
3429 /* Rate handling is done in mac80211 */
3430 /* if (adev->rate_auto) {
3431 struct client *clt = get_txc(adev, txdesc);
3432 if (clt) {
3433 u16 cur = get_txr(adev, txdesc);
3434 if (clt->rate_cur == cur) {
3435 acx_l_handle_txrate_auto(adev, clt, cur,*/ /* intended rate */
3436 /*r100, r111,*/ /* actually used rate */
3437 /*(error & 0x30),*/ /* was there an error? */
3438 /* TX_CNT +
3439 TX_CLEAN_BACKLOG
3441 adev->tx_free);
3446 if (unlikely(error))
3447 handle_tx_error(adev, error, finger, &hostdesc->txstatus);
3449 if (IS_ACX111(adev))
3450 log(L_BUFT,
3451 "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u r111=%04X tx_free=%u\n",
3452 finger, ack_failures, rts_failures, rts_ok, r111, adev->tx_free);
3453 else
3454 log(L_BUFT,
3455 "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u rate=%u\n",
3456 finger, ack_failures, rts_failures, rts_ok, r100);
3458 /* And finally report upstream */
3459 if (hostdesc)
3461 hostdesc->txstatus.excessive_retries = rts_failures ;
3462 hostdesc->txstatus.retry_count = ack_failures;
3463 ieee80211_tx_status(adev->ieee,hostdesc->skb,&hostdesc->txstatus);
3464 memset(&hostdesc->txstatus, 0, sizeof(struct ieee80211_tx_status));
3466 /* update pointer for descr to be cleaned next */
3467 finger = (finger + 1) % TX_CNT;
3469 /* remember last position */
3470 adev->tx_tail = finger;
3471 /* end: */
3472 FN_EXIT1(num_cleaned);
3473 return num_cleaned;
3476 /* clean *all* Tx descriptors, and regardless of their previous state.
3477 * Used for brute-force reset handling. */
3478 void acxpci_l_clean_txdesc_emergency(acx_device_t * adev)
3480 txdesc_t *txdesc;
3481 int i;
3483 FN_ENTER;
3485 for (i = 0; i < TX_CNT; i++) {
3486 txdesc = get_txdesc(adev, i);
3488 /* free it */
3489 txdesc->ack_failures = 0;
3490 txdesc->rts_failures = 0;
3491 txdesc->rts_ok = 0;
3492 txdesc->error = 0;
3493 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3496 adev->tx_free = TX_CNT;
3498 FN_EXIT0;
3502 /***********************************************************************
3503 ** acxpci_s_create_tx_host_desc_queue
3506 static void *allocate(acx_device_t * adev, size_t size, dma_addr_t * phy,
3507 const char *msg)
3509 void *ptr;
3511 ptr = dma_alloc_coherent(adev->bus_dev, size, phy, GFP_KERNEL);
3513 if (ptr) {
3514 log(L_DEBUG, "%s sz=%d adr=0x%p phy=0x%08llx\n",
3515 msg, (int)size, ptr, (unsigned long long)*phy);
3516 memset(ptr, 0, size);
3517 return ptr;
3519 printk(KERN_ERR "acx: %s allocation FAILED (%d bytes)\n",
3520 msg, (int)size);
3521 return NULL;
3525 static int acxpci_s_create_tx_host_desc_queue(acx_device_t * adev)
3527 txhostdesc_t *hostdesc;
3528 u8 *txbuf;
3529 dma_addr_t hostdesc_phy;
3530 dma_addr_t txbuf_phy;
3531 int i;
3533 FN_ENTER;
3535 /* allocate TX buffer */
3536 adev->txbuf_area_size = TX_CNT * /*WLAN_A4FR_MAXLEN_WEP_FCS*/ (30 + 2312 + 4);
3537 adev->txbuf_start = allocate(adev, adev->txbuf_area_size,
3538 &adev->txbuf_startphy, "txbuf_start");
3539 if (!adev->txbuf_start)
3540 goto fail;
3542 /* allocate the TX host descriptor queue pool */
3543 adev->txhostdesc_area_size = TX_CNT * 2 * sizeof(*hostdesc);
3544 adev->txhostdesc_start = allocate(adev, adev->txhostdesc_area_size,
3545 &adev->txhostdesc_startphy,
3546 "txhostdesc_start");
3547 if (!adev->txhostdesc_start)
3548 goto fail;
3549 /* check for proper alignment of TX host descriptor pool */
3550 if ((long)adev->txhostdesc_start & 3) {
3551 printk
3552 ("acx: driver bug: dma alloc returns unaligned address\n");
3553 goto fail;
3556 hostdesc = adev->txhostdesc_start;
3557 hostdesc_phy = adev->txhostdesc_startphy;
3558 txbuf = adev->txbuf_start;
3559 txbuf_phy = adev->txbuf_startphy;
3561 #if 0
3562 /* Each tx buffer is accessed by hardware via
3563 ** txdesc -> txhostdesc(s) -> txbuffer(s).
3564 ** We use only one txhostdesc per txdesc, but it looks like
3565 ** acx111 is buggy: it accesses second txhostdesc
3566 ** (via hostdesc.desc_phy_next field) even if
3567 ** txdesc->length == hostdesc->length and thus
3568 ** entire packet was placed into first txhostdesc.
3569 ** Due to this bug acx111 hangs unless second txhostdesc
3570 ** has le16_to_cpu(hostdesc.length) = 3 (or larger)
3571 ** Storing NULL into hostdesc.desc_phy_next
3572 ** doesn't seem to help.
3574 ** Update: although it worked on Xterasys XN-2522g
3575 ** with len=3 trick, WG311v2 is even more bogus, doesn't work.
3576 ** Keeping this code (#ifdef'ed out) for documentational purposes.
3578 for (i = 0; i < TX_CNT * 2; i++) {
3579 hostdesc_phy += sizeof(*hostdesc);
3580 if (!(i & 1)) {
3581 hostdesc->data_phy = cpu2acx(txbuf_phy);
3582 /* hostdesc->data_offset = ... */
3583 /* hostdesc->reserved = ... */
3584 hostdesc->Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
3585 /* hostdesc->length = ... */
3586 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3587 hostdesc->pNext = ptr2acx(NULL);
3588 /* hostdesc->Status = ... */
3589 /* below: non-hardware fields */
3590 hostdesc->data = txbuf;
3592 txbuf += WLAN_A4FR_MAXLEN_WEP_FCS;
3593 txbuf_phy += WLAN_A4FR_MAXLEN_WEP_FCS;
3594 } else {
3595 /* hostdesc->data_phy = ... */
3596 /* hostdesc->data_offset = ... */
3597 /* hostdesc->reserved = ... */
3598 /* hostdesc->Ctl_16 = ... */
3599 hostdesc->length = cpu_to_le16(3); /* bug workaround */
3600 /* hostdesc->desc_phy_next = ... */
3601 /* hostdesc->pNext = ... */
3602 /* hostdesc->Status = ... */
3603 /* below: non-hardware fields */
3604 /* hostdesc->data = ... */
3606 hostdesc++;
3608 #endif
3609 /* We initialize two hostdescs so that they point to adjacent
3610 ** memory areas. Thus txbuf is really just a contiguous memory area */
3611 for (i = 0; i < TX_CNT * 2; i++) {
3612 hostdesc_phy += sizeof(*hostdesc);
3614 hostdesc->data_phy = cpu2acx(txbuf_phy);
3615 /* done by memset(0): hostdesc->data_offset = 0; */
3616 /* hostdesc->reserved = ... */
3617 hostdesc->Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
3618 /* hostdesc->length = ... */
3619 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3620 /* done by memset(0): hostdesc->pNext = ptr2acx(NULL); */
3621 /* hostdesc->Status = ... */
3622 /* ->data is a non-hardware field: */
3623 hostdesc->data = txbuf;
3625 if (!(i & 1)) {
3626 txbuf += 24 /*WLAN_HDR_A3_LEN*/;
3627 txbuf_phy += 24 /*WLAN_HDR_A3_LEN*/;
3628 } else {
3629 txbuf += 30 + 2132 + 4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3630 txbuf_phy += 30 + 2132 +4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3632 hostdesc++;
3634 hostdesc--;
3635 hostdesc->desc_phy_next = cpu2acx(adev->txhostdesc_startphy);
3637 FN_EXIT1(OK);
3638 return OK;
3639 fail:
3640 printk("acx: create_tx_host_desc_queue FAILED\n");
3641 /* dealloc will be done by free function on error case */
3642 FN_EXIT1(NOT_OK);
3643 return NOT_OK;
3647 /***************************************************************
3648 ** acxpci_s_create_rx_host_desc_queue
3650 /* the whole size of a data buffer (header plus data body)
3651 * plus 32 bytes safety offset at the end */
3652 #define RX_BUFFER_SIZE (sizeof(rxbuffer_t) + 32)
3654 static int acxpci_s_create_rx_host_desc_queue(acx_device_t * adev)
3656 rxhostdesc_t *hostdesc;
3657 rxbuffer_t *rxbuf;
3658 dma_addr_t hostdesc_phy;
3659 dma_addr_t rxbuf_phy;
3660 int i;
3662 FN_ENTER;
3664 /* allocate the RX host descriptor queue pool */
3665 adev->rxhostdesc_area_size = RX_CNT * sizeof(*hostdesc);
3666 adev->rxhostdesc_start = allocate(adev, adev->rxhostdesc_area_size,
3667 &adev->rxhostdesc_startphy,
3668 "rxhostdesc_start");
3669 if (!adev->rxhostdesc_start)
3670 goto fail;
3671 /* check for proper alignment of RX host descriptor pool */
3672 if ((long)adev->rxhostdesc_start & 3) {
3673 printk
3674 ("acx: driver bug: dma alloc returns unaligned address\n");
3675 goto fail;
3678 /* allocate Rx buffer pool which will be used by the acx
3679 * to store the whole content of the received frames in it */
3680 adev->rxbuf_area_size = RX_CNT * RX_BUFFER_SIZE;
3681 adev->rxbuf_start = allocate(adev, adev->rxbuf_area_size,
3682 &adev->rxbuf_startphy, "rxbuf_start");
3683 if (!adev->rxbuf_start)
3684 goto fail;
3686 rxbuf = adev->rxbuf_start;
3687 rxbuf_phy = adev->rxbuf_startphy;
3688 hostdesc = adev->rxhostdesc_start;
3689 hostdesc_phy = adev->rxhostdesc_startphy;
3691 /* don't make any popular C programming pointer arithmetic mistakes
3692 * here, otherwise I'll kill you...
3693 * (and don't dare asking me why I'm warning you about that...) */
3694 for (i = 0; i < RX_CNT; i++) {
3695 hostdesc->data = rxbuf;
3696 hostdesc->data_phy = cpu2acx(rxbuf_phy);
3697 hostdesc->length = cpu_to_le16(RX_BUFFER_SIZE);
3698 CLEAR_BIT(hostdesc->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3699 rxbuf++;
3700 rxbuf_phy += sizeof(*rxbuf);
3701 hostdesc_phy += sizeof(*hostdesc);
3702 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3703 hostdesc++;
3705 hostdesc--;
3706 hostdesc->desc_phy_next = cpu2acx(adev->rxhostdesc_startphy);
3707 FN_EXIT1(OK);
3708 return OK;
3709 fail:
3710 printk("acx: create_rx_host_desc_queue FAILED\n");
3711 /* dealloc will be done by free function on error case */
3712 FN_EXIT1(NOT_OK);
3713 return NOT_OK;
3717 /***************************************************************
3718 ** acxpci_s_create_hostdesc_queues
3720 int acxpci_s_create_hostdesc_queues(acx_device_t * adev)
3722 int result;
3723 result = acxpci_s_create_tx_host_desc_queue(adev);
3724 if (OK != result)
3725 return result;
3726 result = acxpci_s_create_rx_host_desc_queue(adev);
3727 return result;
3731 /***************************************************************
3732 ** acxpci_create_tx_desc_queue
3734 static void acxpci_create_tx_desc_queue(acx_device_t * adev, u32 tx_queue_start)
3736 txdesc_t *txdesc;
3737 txhostdesc_t *hostdesc;
3738 dma_addr_t hostmemptr;
3739 u32 mem_offs;
3740 int i;
3742 FN_ENTER;
3744 if (IS_ACX100(adev))
3745 adev->txdesc_size = sizeof(*txdesc);
3746 else
3747 /* the acx111 txdesc is 4 bytes larger */
3748 adev->txdesc_size = sizeof(*txdesc) + 4;
3750 adev->txdesc_start = (txdesc_t *) (adev->iobase2 + tx_queue_start);
3752 log(L_DEBUG, "adev->iobase2=%p\n"
3753 "tx_queue_start=%08X\n"
3754 "adev->txdesc_start=%p\n",
3755 adev->iobase2, tx_queue_start, adev->txdesc_start);
3757 adev->tx_free = TX_CNT;
3758 /* done by memset: adev->tx_head = 0; */
3759 /* done by memset: adev->tx_tail = 0; */
3760 txdesc = adev->txdesc_start;
3761 mem_offs = tx_queue_start;
3762 hostmemptr = adev->txhostdesc_startphy;
3763 hostdesc = adev->txhostdesc_start;
3765 if (IS_ACX111(adev)) {
3766 /* ACX111 has a preinitialized Tx buffer! */
3767 /* loop over whole send pool */
3768 /* FIXME: do we have to do the hostmemptr stuff here?? */
3769 for (i = 0; i < TX_CNT; i++) {
3770 txdesc->HostMemPtr = ptr2acx(hostmemptr);
3771 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3772 /* reserve two (hdr desc and payload desc) */
3773 hostdesc += 2;
3774 hostmemptr += 2 * sizeof(*hostdesc);
3775 txdesc = advance_txdesc(adev, txdesc, 1);
3777 } else {
3778 /* ACX100 Tx buffer needs to be initialized by us */
3779 /* clear whole send pool. sizeof is safe here (we are acx100) */
3780 memset(adev->txdesc_start, 0, TX_CNT * sizeof(*txdesc));
3782 /* loop over whole send pool */
3783 for (i = 0; i < TX_CNT; i++) {
3784 log(L_DEBUG, "configure card tx descriptor: 0x%p, "
3785 "size: 0x%X\n", txdesc, adev->txdesc_size);
3787 /* pointer to hostdesc memory */
3788 txdesc->HostMemPtr = ptr2acx(hostmemptr);
3789 /* initialise ctl */
3790 txdesc->Ctl_8 = (DESC_CTL_HOSTOWN | DESC_CTL_RECLAIM
3791 | DESC_CTL_AUTODMA |
3792 DESC_CTL_FIRSTFRAG);
3793 /* done by memset(0): txdesc->Ctl2_8 = 0; */
3794 /* point to next txdesc */
3795 txdesc->pNextDesc =
3796 cpu2acx(mem_offs + adev->txdesc_size);
3797 /* reserve two (hdr desc and payload desc) */
3798 hostdesc += 2;
3799 hostmemptr += 2 * sizeof(*hostdesc);
3800 /* go to the next one */
3801 mem_offs += adev->txdesc_size;
3802 /* ++ is safe here (we are acx100) */
3803 txdesc++;
3805 /* go back to the last one */
3806 txdesc--;
3807 /* and point to the first making it a ring buffer */
3808 txdesc->pNextDesc = cpu2acx(tx_queue_start);
3810 FN_EXIT0;
3814 /***************************************************************
3815 ** acxpci_create_rx_desc_queue
3817 static void acxpci_create_rx_desc_queue(acx_device_t * adev, u32 rx_queue_start)
3819 rxdesc_t *rxdesc;
3820 u32 mem_offs;
3821 int i;
3823 FN_ENTER;
3825 /* done by memset: adev->rx_tail = 0; */
3827 /* ACX111 doesn't need any further config: preconfigures itself.
3828 * Simply print ring buffer for debugging */
3829 if (IS_ACX111(adev)) {
3830 /* rxdesc_start already set here */
3832 adev->rxdesc_start =
3833 (rxdesc_t *) ((u8 *) adev->iobase2 + rx_queue_start);
3835 rxdesc = adev->rxdesc_start;
3836 for (i = 0; i < RX_CNT; i++) {
3837 log(L_DEBUG, "rx descriptor %d @ 0x%p\n", i, rxdesc);
3838 rxdesc = adev->rxdesc_start = (rxdesc_t *)
3839 (adev->iobase2 + acx2cpu(rxdesc->pNextDesc));
3841 } else {
3842 /* we didn't pre-calculate rxdesc_start in case of ACX100 */
3843 /* rxdesc_start should be right AFTER Tx pool */
3844 adev->rxdesc_start = (rxdesc_t *)
3845 ((u8 *) adev->txdesc_start + (TX_CNT * sizeof(txdesc_t)));
3846 /* NB: sizeof(txdesc_t) above is valid because we know
3847 ** we are in if (acx100) block. Beware of cut-n-pasting elsewhere!
3848 ** acx111's txdesc is larger! */
3850 memset(adev->rxdesc_start, 0, RX_CNT * sizeof(*rxdesc));
3852 /* loop over whole receive pool */
3853 rxdesc = adev->rxdesc_start;
3854 mem_offs = rx_queue_start;
3855 for (i = 0; i < RX_CNT; i++) {
3856 log(L_DEBUG, "rx descriptor @ 0x%p\n", rxdesc);
3857 rxdesc->Ctl_8 = DESC_CTL_RECLAIM | DESC_CTL_AUTODMA;
3858 /* point to next rxdesc */
3859 rxdesc->pNextDesc = cpu2acx(mem_offs + sizeof(*rxdesc));
3860 /* go to the next one */
3861 mem_offs += sizeof(*rxdesc);
3862 rxdesc++;
3864 /* go to the last one */
3865 rxdesc--;
3867 /* and point to the first making it a ring buffer */
3868 rxdesc->pNextDesc = cpu2acx(rx_queue_start);
3870 FN_EXIT0;
3874 /***************************************************************
3875 ** acxpci_create_desc_queues
3877 void
3878 acxpci_create_desc_queues(acx_device_t * adev, u32 tx_queue_start,
3879 u32 rx_queue_start)
3881 acxpci_create_tx_desc_queue(adev, tx_queue_start);
3882 acxpci_create_rx_desc_queue(adev, rx_queue_start);
3886 /***************************************************************
3887 ** acxpci_s_proc_diag_output
3889 char *acxpci_s_proc_diag_output(char *p, acx_device_t * adev)
3891 const char *rtl, *thd, *ttl;
3892 rxhostdesc_t *rxhostdesc;
3893 txdesc_t *txdesc;
3894 int i;
3896 FN_ENTER;
3898 p += sprintf(p, "** Rx buf **\n");
3899 rxhostdesc = adev->rxhostdesc_start;
3900 if (rxhostdesc)
3901 for (i = 0; i < RX_CNT; i++) {
3902 rtl = (i == adev->rx_tail) ? " [tail]" : "";
3903 if ((rxhostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
3904 && (rxhostdesc->
3905 Status & cpu_to_le32(DESC_STATUS_FULL)))
3906 p += sprintf(p, "%02u FULL%s\n", i, rtl);
3907 else
3908 p += sprintf(p, "%02u empty%s\n", i, rtl);
3909 rxhostdesc++;
3911 /* p += sprintf(p, "** Tx buf (free %d, Linux netqueue %s) **\n",
3912 adev->tx_free,
3913 acx_queue_stopped(adev->ieee) ? "STOPPED" : "running");*/
3914 txdesc = adev->txdesc_start;
3915 if (txdesc)
3916 for (i = 0; i < TX_CNT; i++) {
3917 thd = (i == adev->tx_head) ? " [head]" : "";
3918 ttl = (i == adev->tx_tail) ? " [tail]" : "";
3919 if (txdesc->Ctl_8 & DESC_CTL_ACXDONE)
3920 p += sprintf(p, "%02u free (%02X)%s%s\n", i,
3921 txdesc->Ctl_8, thd, ttl);
3922 else
3923 p += sprintf(p, "%02u tx (%02X)%s%s\n", i,
3924 txdesc->Ctl_8, thd, ttl);
3925 txdesc = advance_txdesc(adev, txdesc, 1);
3927 p += sprintf(p,
3928 "\n"
3929 "** PCI data **\n"
3930 "txbuf_start %p, txbuf_area_size %u, txbuf_startphy %08llx\n"
3931 "txdesc_size %u, txdesc_start %p\n"
3932 "txhostdesc_start %p, txhostdesc_area_size %u, txhostdesc_startphy %08llx\n"
3933 "rxdesc_start %p\n"
3934 "rxhostdesc_start %p, rxhostdesc_area_size %u, rxhostdesc_startphy %08llx\n"
3935 "rxbuf_start %p, rxbuf_area_size %u, rxbuf_startphy %08llx\n",
3936 adev->txbuf_start, adev->txbuf_area_size,
3937 (unsigned long long)adev->txbuf_startphy,
3938 adev->txdesc_size, adev->txdesc_start,
3939 adev->txhostdesc_start, adev->txhostdesc_area_size,
3940 (unsigned long long)adev->txhostdesc_startphy,
3941 adev->rxdesc_start,
3942 adev->rxhostdesc_start, adev->rxhostdesc_area_size,
3943 (unsigned long long)adev->rxhostdesc_startphy,
3944 adev->rxbuf_start, adev->rxbuf_area_size,
3945 (unsigned long long)adev->rxbuf_startphy);
3947 FN_EXIT0;
3948 return p;
3952 /***********************************************************************
3954 int acxpci_proc_eeprom_output(char *buf, acx_device_t * adev)
3956 char *p = buf;
3957 int i;
3959 FN_ENTER;
3961 for (i = 0; i < 0x400; i++) {
3962 acxpci_read_eeprom_byte(adev, i, p++);
3965 FN_EXIT1(p - buf);
3966 return p - buf;
3970 /***********************************************************************
3971 ** Obvious
3973 void acxpci_set_interrupt_mask(acx_device_t * adev)
3975 if (IS_ACX111(adev)) {
3976 adev->irq_mask = (u16) ~ (0
3977 /* | HOST_INT_RX_DATA */
3978 | HOST_INT_TX_COMPLETE
3979 /* | HOST_INT_TX_XFER */
3980 | HOST_INT_RX_COMPLETE
3981 /* | HOST_INT_DTIM */
3982 /* | HOST_INT_BEACON */
3983 /* | HOST_INT_TIMER */
3984 /* | HOST_INT_KEY_NOT_FOUND */
3985 | HOST_INT_IV_ICV_FAILURE
3986 | HOST_INT_CMD_COMPLETE
3987 | HOST_INT_INFO
3988 /* | HOST_INT_OVERFLOW */
3989 /* | HOST_INT_PROCESS_ERROR */
3990 | HOST_INT_SCAN_COMPLETE
3991 | HOST_INT_FCS_THRESHOLD
3992 /* | HOST_INT_UNKNOWN */
3994 /* Or else acx100 won't signal cmd completion, right? */
3995 adev->irq_mask_off = (u16) ~ (HOST_INT_CMD_COMPLETE); /* 0xfdff */
3996 } else {
3997 adev->irq_mask = (u16) ~ (0
3998 /* | HOST_INT_RX_DATA */
3999 | HOST_INT_TX_COMPLETE
4000 /* | HOST_INT_TX_XFER */
4001 | HOST_INT_RX_COMPLETE
4002 /* | HOST_INT_DTIM */
4003 /* | HOST_INT_BEACON */
4004 /* | HOST_INT_TIMER */
4005 /* | HOST_INT_KEY_NOT_FOUND */
4006 /* | HOST_INT_IV_ICV_FAILURE */
4007 | HOST_INT_CMD_COMPLETE
4008 | HOST_INT_INFO
4009 /* | HOST_INT_OVERFLOW */
4010 /* | HOST_INT_PROCESS_ERROR */
4011 | HOST_INT_SCAN_COMPLETE
4012 /* | HOST_INT_FCS_THRESHOLD */
4013 /* | HOST_INT_UNKNOWN */
4015 adev->irq_mask_off = (u16) ~ (HOST_INT_UNKNOWN); /* 0x7fff */
4020 /***********************************************************************
4022 int acx100pci_s_set_tx_level(acx_device_t * adev, u8 level_dbm)
4024 /* since it can be assumed that at least the Maxim radio has a
4025 * maximum power output of 20dBm and since it also can be
4026 * assumed that these values drive the DAC responsible for
4027 * setting the linear Tx level, I'd guess that these values
4028 * should be the corresponding linear values for a dBm value,
4029 * in other words: calculate the values from that formula:
4030 * Y [dBm] = 10 * log (X [mW])
4031 * then scale the 0..63 value range onto the 1..100mW range (0..20 dBm)
4032 * and you're done...
4033 * Hopefully that's ok, but you never know if we're actually
4034 * right... (especially since Windows XP doesn't seem to show
4035 * actual Tx dBm values :-P) */
4037 /* NOTE: on Maxim, value 30 IS 30mW, and value 10 IS 10mW - so the
4038 * values are EXACTLY mW!!! Not sure about RFMD and others,
4039 * though... */
4040 static const u8 dbm2val_maxim[21] = {
4041 63, 63, 63, 62,
4042 61, 61, 60, 60,
4043 59, 58, 57, 55,
4044 53, 50, 47, 43,
4045 38, 31, 23, 13,
4048 static const u8 dbm2val_rfmd[21] = {
4049 0, 0, 0, 1,
4050 2, 2, 3, 3,
4051 4, 5, 6, 8,
4052 10, 13, 16, 20,
4053 25, 32, 41, 50,
4056 const u8 *table;
4058 switch (adev->radio_type) {
4059 case RADIO_MAXIM_0D:
4060 table = &dbm2val_maxim[0];
4061 break;
4062 case RADIO_RFMD_11:
4063 case RADIO_RALINK_15:
4064 table = &dbm2val_rfmd[0];
4065 break;
4066 default:
4067 printk("%s: unknown/unsupported radio type, "
4068 "cannot modify tx power level yet!\n", wiphy_name(adev->ieee->wiphy));
4069 return NOT_OK;
4071 printk("%s: changing radio power level to %u dBm (%u)\n",
4072 wiphy_name(adev->ieee->wiphy), level_dbm, table[level_dbm]);
4073 acxpci_s_write_phy_reg(adev, 0x11, table[level_dbm]);
4074 return OK;
4077 #ifdef CONFIG_VLYNQ
4078 struct vlynq_reg_config {
4079 u32 offset;
4080 u32 value;
4083 struct vlynq_known {
4084 u32 chip_id;
4085 char name[32];
4086 struct vlynq_mapping rx_mapping[4];
4087 int irq;
4088 int irq_type;
4089 int num_regs;
4090 struct vlynq_reg_config regs[10];
4093 #define CHIP_TNETW1130 0x00000009
4094 #define CHIP_TNETW1350 0x00000029
4096 static struct vlynq_known known_devices[] = {
4098 .chip_id = CHIP_TNETW1130, .name = "TI TNETW1130",
4099 .rx_mapping = {
4100 { .size = 0x22000, .offset = 0xf0000000 },
4101 { .size = 0x40000, .offset = 0xc0000000 },
4102 { .size = 0x0, .offset = 0x0 },
4103 { .size = 0x0, .offset = 0x0 },
4105 .irq = 0,
4106 .irq_type = IRQ_TYPE_EDGE_RISING,
4107 .num_regs = 5,
4108 .regs = {
4110 .offset = 0x790,
4111 .value = (0xd0000000 - PHYS_OFFSET)
4114 .offset = 0x794,
4115 .value = (0xd0000000 - PHYS_OFFSET)
4117 { .offset = 0x740, .value = 0 },
4118 { .offset = 0x744, .value = 0x00010000 },
4119 { .offset = 0x764, .value = 0x00010000 },
4123 .chip_id = CHIP_TNETW1350, .name = "TI TNETW1350",
4124 .rx_mapping = {
4125 { .size = 0x100000, .offset = 0x00300000 },
4126 { .size = 0x80000, .offset = 0x00000000 },
4127 { .size = 0x0, .offset = 0x0 },
4128 { .size = 0x0, .offset = 0x0 },
4130 .irq = 0,
4131 .irq_type = IRQ_TYPE_EDGE_RISING,
4132 .num_regs = 5,
4133 .regs = {
4135 .offset = 0x790,
4136 .value = (0x60000000 - PHYS_OFFSET)
4139 .offset = 0x794,
4140 .value = (0x60000000 - PHYS_OFFSET)
4142 { .offset = 0x740, .value = 0 },
4143 { .offset = 0x744, .value = 0x00010000 },
4144 { .offset = 0x764, .value = 0x00010000 },
4149 static struct vlynq_device_id acx_vlynq_id[] = {
4150 { CHIP_TNETW1130, vlynq_div_auto, 0 },
4151 { CHIP_TNETW1350, vlynq_div_auto, 1 },
4152 { 0, 0, 0 },
4155 static __devinit int vlynq_probe(struct vlynq_device *vdev,
4156 struct vlynq_device_id *id)
4158 int result = -EIO, i;
4159 u32 addr;
4160 struct ieee80211_hw *ieee;
4161 acx_device_t *adev = NULL;
4162 acx111_ie_configoption_t co;
4163 struct vlynq_mapping mapping[4] = { { 0, }, };
4164 struct vlynq_known *match = NULL;
4166 FN_ENTER;
4167 result = vlynq_enable_device(vdev);
4168 if (result)
4169 return result;
4171 match = &known_devices[id->driver_data];
4173 if (!match) {
4174 result = -ENODEV;
4175 goto fail;
4178 mapping[0].offset = ARCH_PFN_OFFSET << PAGE_SHIFT;
4179 mapping[0].size = 0x02000000;
4180 vlynq_set_local_mapping(vdev, vdev->mem_start, mapping);
4181 vlynq_set_remote_mapping(vdev, 0, match->rx_mapping);
4183 set_irq_type(vlynq_virq_to_irq(vdev, match->irq), match->irq_type);
4185 addr = (u32)ioremap(vdev->mem_start, 0x1000);
4186 if (!addr) {
4187 printk(KERN_ERR "%s: failed to remap io memory\n",
4188 vdev->dev.bus_id);
4189 result = -ENXIO;
4190 goto fail;
4193 for (i = 0; i < match->num_regs; i++)
4194 iowrite32(match->regs[i].value,
4195 (u32 *)(addr + match->regs[i].offset));
4197 iounmap((void *)addr);
4199 ieee = ieee80211_alloc_hw(sizeof(struct acx_device), &acxpci_hw_ops);
4200 if (!ieee) {
4201 printk("acx: could not allocate ieee80211 structure %s\n",
4202 vdev->dev.bus_id);
4203 goto fail_alloc_netdev;
4205 ieee->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
4206 ieee->queues = 1;
4208 adev = ieee2adev(ieee);
4210 memset(adev, 0, sizeof(*adev));
4211 /** Set up our private interface **/
4212 spin_lock_init(&adev->spinlock); /* initial state: unlocked */
4213 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
4214 mutex_init(&adev->mutex);
4215 /* since nobody can see new netdev yet, we can as well
4216 ** just _presume_ that we're under sem (instead of actually taking it): */
4217 /* acx_sem_lock(adev); */
4218 adev->ieee = ieee;
4219 adev->vdev = vdev;
4220 adev->bus_dev = &vdev->dev;
4221 adev->dev_type = DEVTYPE_PCI;
4223 /** Finished with private interface **/
4225 vlynq_set_drvdata(vdev, ieee);
4226 if (!request_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start, "acx")) {
4227 printk("acx: cannot reserve VLYNQ memory region\n");
4228 goto fail_request_mem_region;
4231 adev->iobase = ioremap(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4232 if (!adev->iobase) {
4233 printk("acx: ioremap() FAILED\n");
4234 goto fail_ioremap;
4236 adev->iobase2 = adev->iobase + match->rx_mapping[0].size;
4237 adev->chip_type = CHIPTYPE_ACX111;
4238 adev->chip_name = match->name;
4239 adev->io = IO_ACX111;
4240 adev->irq = vlynq_virq_to_irq(vdev, match->irq);
4242 printk("acx: found %s-based wireless network card at %s, irq:%d, "
4243 "phymem:0x%x, mem:0x%p\n",
4244 match->name, vdev->dev.bus_id, adev->irq,
4245 vdev->mem_start, adev->iobase);
4246 log(L_ANY, "initial debug setting is 0x%04X\n", acx_debug);
4248 if (0 == adev->irq) {
4249 printk("acx: can't use IRQ 0\n");
4250 goto fail_irq;
4252 SET_IEEE80211_DEV(ieee, &vdev->dev);
4254 /* request shared IRQ handler */
4255 if (request_irq
4256 (adev->irq, acxpci_i_interrupt, IRQF_SHARED, KBUILD_MODNAME, adev)) {
4257 printk("%s: request_irq FAILED\n", wiphy_name(adev->ieee->wiphy));
4258 result = -EAGAIN;
4259 goto done;
4261 log(L_DEBUG | L_IRQ, "request_irq %d successful\n", adev->irq);
4263 /* to find crashes due to weird driver access
4264 * to unconfigured interface (ifup) */
4265 adev->mgmt_timer.function = (void (*)(unsigned long))0x0000dead;
4268 /* ok, pci setup is finished, now start initializing the card */
4270 /* NB: read_reg() reads may return bogus data before reset_dev(),
4271 * since the firmware which directly controls large parts of the I/O
4272 * registers isn't initialized yet.
4273 * acx100 seems to be more affected than acx111 */
4274 if (OK != acxpci_s_reset_dev(adev))
4275 goto fail_reset;
4277 if (OK != acx_s_init_mac(adev))
4278 goto fail_init_mac;
4280 acx_s_interrogate(adev, &co, ACX111_IE_CONFIG_OPTIONS);
4281 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
4282 if (OK != acxpci_read_eeprom_byte(adev, 0x05, &adev->eeprom_version))
4283 goto fail_read_eeprom_version;
4285 acx_s_parse_configoption(adev, &co);
4286 acx_s_set_defaults(adev);
4287 acx_s_get_firmware_version(adev); /* needs to be after acx_s_init_mac() */
4288 acx_display_hardware_details(adev);
4290 /* Register the card, AFTER everything else has been set up,
4291 * since otherwise an ioctl could step on our feet due to
4292 * firmware operations happening in parallel or uninitialized data */
4295 acx_proc_register_entries(ieee);
4297 /* Now we have our device, so make sure the kernel doesn't try
4298 * to send packets even though we're not associated to a network yet */
4300 /* after register_netdev() userspace may start working with dev
4301 * (in particular, on other CPUs), we only need to up the sem */
4302 /* acx_sem_unlock(adev); */
4304 printk("acx " ACX_RELEASE ": net device %s, driver compiled "
4305 "against wireless extensions %d and Linux %s\n",
4306 wiphy_name(adev->ieee->wiphy), WIRELESS_EXT, UTS_RELEASE);
4308 MAC_COPY(adev->ieee->wiphy->perm_addr, adev->dev_addr);
4310 log(L_IRQ | L_INIT, "using IRQ %d\n", adev->irq);
4312 /** done with board specific setup **/
4314 result = acx_setup_modes(adev);
4315 if (result) {
4316 printk("can't register hwmode\n");
4317 goto fail_register_netdev;
4320 acx_init_task_scheduler(adev);
4321 result = ieee80211_register_hw(adev->ieee);
4322 if (OK != result) {
4323 printk("acx: ieee80211_register_hw() FAILED: %d\n", result);
4324 goto fail_register_netdev;
4326 #if CMD_DISCOVERY
4327 great_inquisitor(adev);
4328 #endif
4330 result = OK;
4331 goto done;
4333 /* error paths: undo everything in reverse order... */
4336 acxpci_s_delete_dma_regions(adev);
4338 fail_init_mac:
4339 fail_read_eeprom_version:
4340 fail_reset:
4342 fail_alloc_netdev:
4343 fail_irq:
4345 iounmap(adev->iobase);
4346 fail_ioremap:
4348 release_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4349 fail_request_mem_region:
4350 fail_register_netdev:
4351 ieee80211_free_hw(ieee);
4352 fail:
4353 vlynq_disable_device(vdev);
4354 done:
4355 FN_EXIT1(result);
4356 return result;
4359 static void vlynq_remove(struct vlynq_device *vdev)
4361 struct ieee80211_hw *hw = vlynq_get_drvdata(vdev);
4362 acx_device_t *adev = ieee2adev(hw);
4363 unsigned long flags;
4364 FN_ENTER;
4366 if (!hw) {
4367 log(L_DEBUG, "%s: card is unused. Skipping any release code\n",
4368 __func__);
4369 goto end;
4373 acx_lock(adev, flags);
4374 acx_unlock(adev, flags);
4375 adev->initialized = 0;
4377 /* If device wasn't hot unplugged... */
4378 if (adev_present(adev)) {
4380 acx_sem_lock(adev);
4382 /* disable both Tx and Rx to shut radio down properly */
4383 if (adev->initialized) {
4384 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_TX, NULL, 0);
4385 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_RX, NULL, 0);
4387 acx_lock(adev, flags);
4388 /* disable power LED to save power :-) */
4389 log(L_INIT, "switching off power LED to save power\n");
4390 acxpci_l_power_led(adev, 0);
4391 /* stop our eCPU */
4392 acx_unlock(adev, flags);
4394 acx_sem_unlock(adev);
4397 /* unregister the device to not let the kernel
4398 * (e.g. ioctls) access a half-deconfigured device
4399 * NB: this will cause acxpci_e_close() to be called,
4400 * thus we shouldn't call it under sem!
4402 acxpci_e_close(hw);
4403 log(L_INIT, "removing device %s\n", wiphy_name(adev->ieee->wiphy));
4404 ieee80211_unregister_hw(adev->ieee);
4406 /* unregister_netdev ensures that no references to us left.
4407 * For paranoid reasons we continue to follow the rules */
4408 acx_sem_lock(adev);
4410 if (adev->dev_state_mask & ACX_STATE_IFACE_UP) {
4411 acxpci_s_down(hw);
4412 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
4415 acx_proc_unregister_entries(adev->ieee);
4417 /* finally, clean up PCI bus state */
4418 acxpci_s_delete_dma_regions(adev);
4419 if (adev->iobase)
4420 iounmap(adev->iobase);
4421 if (adev->iobase2)
4422 iounmap(adev->iobase2);
4423 release_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4425 /* remove dev registration */
4427 acx_sem_unlock(adev);
4428 vlynq_disable_device(vdev);
4430 /* Free netdev (quite late,
4431 * since otherwise we might get caught off-guard
4432 * by a netdev timeout handler execution
4433 * expecting to see a working dev...) */
4434 ieee80211_free_hw(adev->ieee);
4436 end:
4437 FN_EXIT0;
4440 static struct vlynq_driver vlynq_acx = {
4441 .name = "acx_vlynq",
4442 .id_table = acx_vlynq_id,
4443 .probe = vlynq_probe,
4444 .remove = __devexit_p(vlynq_remove),
4446 #endif /* CONFIG_VLYNQ */
4449 /***********************************************************************
4450 ** Data for init_module/cleanup_module
4452 #ifdef CONFIG_PCI
4453 static const struct pci_device_id acxpci_id_tbl[] __devinitdata = {
4455 .vendor = PCI_VENDOR_ID_TI,
4456 .device = PCI_DEVICE_ID_TI_TNETW1100A,
4457 .subvendor = PCI_ANY_ID,
4458 .subdevice = PCI_ANY_ID,
4459 .driver_data = CHIPTYPE_ACX100,
4462 .vendor = PCI_VENDOR_ID_TI,
4463 .device = PCI_DEVICE_ID_TI_TNETW1100B,
4464 .subvendor = PCI_ANY_ID,
4465 .subdevice = PCI_ANY_ID,
4466 .driver_data = CHIPTYPE_ACX100,
4469 .vendor = PCI_VENDOR_ID_TI,
4470 .device = PCI_DEVICE_ID_TI_TNETW1130,
4471 .subvendor = PCI_ANY_ID,
4472 .subdevice = PCI_ANY_ID,
4473 .driver_data = CHIPTYPE_ACX111,
4476 .vendor = 0,
4477 .device = 0,
4478 .subvendor = 0,
4479 .subdevice = 0,
4480 .driver_data = 0,
4484 MODULE_DEVICE_TABLE(pci, acxpci_id_tbl);
4486 static struct pci_driver
4487 acxpci_drv_id = {
4488 .name = "acx_pci",
4489 .id_table = acxpci_id_tbl,
4490 .probe = acxpci_e_probe,
4491 .remove = __devexit_p(acxpci_e_remove),
4492 #ifdef CONFIG_PM
4493 .suspend = acxpci_e_suspend,
4494 .resume = acxpci_e_resume
4495 #endif /* CONFIG_PM */
4497 #endif /* CONFIG_PCI */
4499 /***********************************************************************
4500 ** acxpci_e_init_module
4502 ** Module initialization routine, called once at module load time
4504 int __init acxpci_e_init_module(void)
4506 int res;
4508 FN_ENTER;
4510 printk(KERN_EMERG);
4512 #if (ACX_IO_WIDTH==32)
4513 log(L_INIT, "acx: compiled to use 32bit I/O access. "
4514 "I/O timing issues might occur, such as "
4515 "non-working firmware upload. Report them\n");
4516 #else
4517 log(L_INIT, "acx: compiled to use 16bit I/O access only "
4518 "(compatibility mode)\n");
4519 #endif
4521 #ifdef __LITTLE_ENDIAN
4522 #define ENDIANNESS_STRING "running on a little-endian CPU\n"
4523 #else
4524 #define ENDIANNESS_STRING "running on a BIG-ENDIAN CPU\n"
4525 #endif
4526 log(L_INIT,
4527 "acx: " ENDIANNESS_STRING
4528 "acx: PCI/VLYNQ module " ACX_RELEASE " initialized, "
4529 "waiting for cards to probe...\n");
4531 #ifdef CONFIG_PCI
4532 res = pci_register_driver(&acxpci_drv_id);
4533 #elif CONFIG_VLYNQ
4534 res = vlynq_register_driver(&vlynq_acx);
4535 #endif
4537 if (res) {
4538 printk(KERN_ERR "acx_pci: can't register pci/vlynq driver\n");
4541 FN_EXIT1(res);
4542 return res;
4546 /***********************************************************************
4547 ** acxpci_e_cleanup_module
4549 ** Called at module unload time. This is our last chance to
4550 ** clean up after ourselves.
4552 void __exit acxpci_e_cleanup_module(void)
4554 FN_ENTER;
4556 #ifdef CONFIG_PCI
4557 pci_unregister_driver(&acxpci_drv_id);
4558 #elif CONFIG_VLYNQ
4559 vlynq_unregister_driver(&vlynq_acx);
4560 #endif
4561 log(L_INIT,
4562 "acx: PCI module " ACX_RELEASE " unloaded\n");
4563 FN_EXIT0;