Reverted refactoring of 'interrogate' cmds to 'query'
[acx-mac80211.git] / pci.c
blobdd6b005ebf8428820654e483700196db5e3dc832
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"
38 #include "acx_struct_pci.h"
39 #include "acx_log.h"
40 #include "acx_irq.h"
41 #include "acx_util.h"
43 /***********************************************************************
45 #ifdef CONFIG_PCI
46 #define PCI_TYPE (PCI_USES_MEM | PCI_ADDR0 | PCI_NO_ACPI_WAKE)
47 #define PCI_ACX100_REGION1 0x01
48 #define PCI_ACX100_REGION1_SIZE 0x1000 /* Memory size - 4K bytes */
49 #define PCI_ACX100_REGION2 0x02
50 #define PCI_ACX100_REGION2_SIZE 0x10000 /* Memory size - 64K bytes */
52 #define PCI_ACX111_REGION1 0x00
53 #define PCI_ACX111_REGION1_SIZE 0x2000 /* Memory size - 8K bytes */
54 #define PCI_ACX111_REGION2 0x01
55 #define PCI_ACX111_REGION2_SIZE 0x20000 /* Memory size - 128K bytes */
57 /* Texas Instruments Vendor ID */
58 #define PCI_VENDOR_ID_TI 0x104c
60 /* ACX100 22Mb/s WLAN controller */
61 #define PCI_DEVICE_ID_TI_TNETW1100A 0x8400
62 #define PCI_DEVICE_ID_TI_TNETW1100B 0x8401
64 /* ACX111 54Mb/s WLAN controller */
65 #define PCI_DEVICE_ID_TI_TNETW1130 0x9066
67 /* PCI Class & Sub-Class code, Network-'Other controller' */
68 #define PCI_CLASS_NETWORK_OTHERS 0x0280
70 #define CARD_EEPROM_ID_SIZE 6
72 #ifndef PCI_D0
73 /* From include/linux/pci.h */
74 #define PCI_D0 0
75 #define PCI_D1 1
76 #define PCI_D2 2
77 #define PCI_D3hot 3
78 #define PCI_D3cold 4
79 #define PCI_UNKNOWN 5
80 #define PCI_POWER_ERROR -1
81 #endif
82 #endif /* CONFIG_PCI */
84 /***********************************************************************
87 static irqreturn_t acxpci_i_interrupt(int irq, void *dev_id);
89 static void disable_acx_irq(acx_device_t * adev);
91 static int acxpci_e_open(struct ieee80211_hw *hw);
92 static void acxpci_e_close(struct ieee80211_hw *hw);
93 static void acxpci_s_up(struct ieee80211_hw *hw);
94 static void acxpci_s_down(struct ieee80211_hw *hw);
96 /* Handle PCI posting properly:
97 * Make sure that writes reach the adapter in case they require to be executed
98 * *before* the next write, by reading a random (and safely accessible) register.
99 * This call has to be made if there is no read following (which would flush the data
100 * to the adapter), yet the written data has to reach the adapter immediately. */
101 static inline void write_flush(acx_device_t * adev)
103 /* readb(adev->iobase + adev->io[ACX_IO_INFO_MAILBOX_OFFS]); */
104 /* faster version (accesses the first register, ACX_IO_SOFT_RESET,
105 * which should also be safe): */
106 readb(adev->iobase);
109 static inline int adev_present(acx_device_t * adev)
111 /* fast version (accesses the first register, ACX_IO_SOFT_RESET,
112 * which should be safe): */
113 return acx_readl(adev->iobase) != 0xffffffff;
117 /***********************************************************************
119 static inline txdesc_t *get_txdesc(acx_device_t * adev, int index)
121 return (txdesc_t *) (((u8 *) adev->txdesc_start) +
122 index * adev->txdesc_size);
125 static inline txdesc_t *advance_txdesc(acx_device_t * adev, txdesc_t * txdesc,
126 int inc)
128 return (txdesc_t *) (((u8 *) txdesc) + inc * adev->txdesc_size);
131 static txhostdesc_t *get_txhostdesc(acx_device_t * adev, txdesc_t * txdesc)
133 int index = (u8 *) txdesc - (u8 *) adev->txdesc_start;
135 FN_ENTER;
137 if (unlikely(ACX_DEBUG && (index % adev->txdesc_size))) {
138 acx_log(LOG_WARNING, L_ANY, "bad txdesc ptr %p\n", txdesc);
139 return NULL;
141 index /= adev->txdesc_size;
142 if (unlikely(ACX_DEBUG && (index >= TX_CNT))) {
143 acx_log(LOG_WARNING, L_ANY, "bad txdesc ptr %p\n", txdesc);
144 return NULL;
147 FN_EXIT0;
149 return &adev->txhostdesc_start[index * 2];
156 /***********************************************************************
157 ** EEPROM and PHY read/write helpers
159 /***********************************************************************
160 ** acxpci_read_eeprom_byte
162 ** Function called to read an octet in the EEPROM.
164 ** This function is used by acxpci_e_probe to check if the
165 ** connected card is a legal one or not.
167 ** Arguments:
168 ** adev ptr to acx_device structure
169 ** addr address to read in the EEPROM
170 ** charbuf ptr to a char. This is where the read octet
171 ** will be stored
174 int acxpci_read_eeprom_byte(acx_device_t * adev, u32 addr, u8 * charbuf)
176 int result;
177 int count;
179 FN_ENTER;
181 write_reg32(adev, ACX_IO_EEPROM_CFG, 0);
182 write_reg32(adev, ACX_IO_EEPROM_ADDR, addr);
183 write_flush(adev);
184 write_reg32(adev, ACX_IO_EEPROM_CTL, 2);
186 count = 0xffff;
187 while (read_reg16(adev, ACX_IO_EEPROM_CTL)) {
188 /* scheduling away instead of CPU burning loop
189 * doesn't seem to work here at all:
190 * awful delay, sometimes also failure.
191 * Doesn't matter anyway (only small delay). */
192 if (unlikely(!--count)) {
193 acx_log(LOG_WARNING, L_ANY,
194 "%s: timeout waiting for EEPROM read\n",
195 wiphy_name(adev->ieee->wiphy));
196 result = NOT_OK;
197 goto fail;
199 cpu_relax();
202 *charbuf = read_reg8(adev, ACX_IO_EEPROM_DATA);
203 acx_log(LOG_DEBUG, L_REALLYVERBOSE, "EEPROM at 0x%04X = 0x%02X\n",
204 addr, *charbuf);
205 result = OK;
207 fail:
208 FN_EXIT1(result);
209 return result;
213 /***********************************************************************
214 ** We don't lock hw accesses here since we never r/w eeprom in IRQ
215 ** Note: this function sleeps only because of GFP_KERNEL alloc
217 #ifdef UNUSED
219 acxpci_s_write_eeprom(acx_device_t * adev, u32 addr, u32 len,
220 const u8 * charbuf)
222 u8 *data_verify = NULL;
223 unsigned long flags;
224 int count, i;
225 int result = NOT_OK;
226 u16 gpio_orig;
228 acx_log(LOG_WARNING, L_ANY, "WARNING! I would write to EEPROM now. "
229 "Since I really DON'T want to unless you know "
230 "what you're doing (THIS CODE WILL PROBABLY "
231 "NOT WORK YET!), I will abort that now. And "
232 "definitely make sure to make a "
233 "/proc/driver/acx_wlan0_eeprom backup copy first!!! "
234 "(the EEPROM content includes the PCI config header!! "
235 "If you kill important stuff, then you WILL "
236 "get in trouble and people DID get in trouble already)\n");
237 return OK;
239 FN_ENTER;
241 data_verify = kmalloc(len, GFP_KERNEL);
242 if (!data_verify) {
243 goto end;
246 /* first we need to enable the OE (EEPROM Output Enable) GPIO line
247 * to be able to write to the EEPROM.
248 * NOTE: an EEPROM writing success has been reported,
249 * but you probably have to modify GPIO_OUT, too,
250 * and you probably need to activate a different GPIO
251 * line instead! */
252 gpio_orig = read_reg16(adev, ACX_IO_GPIO_OE);
253 write_reg16(adev, ACX_IO_GPIO_OE, gpio_orig & ~1);
254 write_flush(adev);
256 /* ok, now start writing the data out */
257 for (i = 0; i < len; i++) {
258 write_reg32(adev, ACX_IO_EEPROM_CFG, 0);
259 write_reg32(adev, ACX_IO_EEPROM_ADDR, addr + i);
260 write_reg32(adev, ACX_IO_EEPROM_DATA, *(charbuf + i));
261 write_flush(adev);
262 write_reg32(adev, ACX_IO_EEPROM_CTL, 1);
264 count = 0xffff;
265 while (read_reg16(adev, ACX_IO_EEPROM_CTL)) {
266 if (unlikely(!--count)) {
267 acx_log(LOG_WARNING, L_ANY, "WARNING, DANGER!!! "
268 "Timeout waiting for EEPROM write\n");
269 goto end;
271 cpu_relax();
275 /* disable EEPROM writing */
276 write_reg16(adev, ACX_IO_GPIO_OE, gpio_orig);
277 write_flush(adev);
279 /* now start a verification run */
280 for (i = 0; i < len; i++) {
281 write_reg32(adev, ACX_IO_EEPROM_CFG, 0);
282 write_reg32(adev, ACX_IO_EEPROM_ADDR, addr + i);
283 write_flush(adev);
284 write_reg32(adev, ACX_IO_EEPROM_CTL, 2);
286 count = 0xffff;
287 while (read_reg16(adev, ACX_IO_EEPROM_CTL)) {
288 if (unlikely(!--count)) {
289 acx_log(LOG_WARNING, L_ANY,
290 "timeout waiting for EEPROM read\n");
291 goto end;
293 cpu_relax();
296 data_verify[i] = read_reg16(adev, ACX_IO_EEPROM_DATA);
299 if (0 == memcmp(charbuf, data_verify, len))
300 result = OK; /* read data matches, success */
302 end:
303 kfree(data_verify);
304 FN_EXIT1(result);
305 return result;
307 #endif /* UNUSED */
310 /***********************************************************************
311 ** acxpci_s_read_phy_reg
313 ** Messing with rx/tx disabling and enabling here
314 ** (write_reg32(adev, ACX_IO_ENABLE, 0b000000xx)) kills traffic
316 int acxpci_s_read_phy_reg(acx_device_t * adev, u32 reg, u8 * charbuf)
318 int result = NOT_OK;
319 int count;
321 FN_ENTER;
323 write_reg32(adev, ACX_IO_PHY_ADDR, reg);
324 write_flush(adev);
325 write_reg32(adev, ACX_IO_PHY_CTL, 2);
327 count = 0xffff;
328 while (read_reg32(adev, ACX_IO_PHY_CTL)) {
329 /* scheduling away instead of CPU burning loop
330 * doesn't seem to work here at all:
331 * awful delay, sometimes also failure.
332 * Doesn't matter anyway (only small delay). */
333 if (unlikely(!--count)) {
334 acx_log(LOG_WARNING, L_ANY,
335 "%s: timeout waiting for phy read\n",
336 wiphy_name(adev->ieee->wiphy));
337 *charbuf = 0;
338 goto fail;
340 cpu_relax();
343 acx_log(LOG_DEBUG, L_REALLYVERBOSE, "count was %u\n", count);
344 *charbuf = read_reg8(adev, ACX_IO_PHY_DATA);
346 acx_log(LOG_DEBUG, L_REALLYVERBOSE, "radio PHY at 0x%04X = 0x%02X\n",
347 *charbuf, reg);
348 result = OK;
349 goto fail; /* silence compiler warning */
350 fail:
351 FN_EXIT1(result);
352 return result;
356 /***********************************************************************
358 int acxpci_s_write_phy_reg(acx_device_t * adev, u32 reg, u8 value)
360 FN_ENTER;
362 /* mprusko said that 32bit accesses result in distorted sensitivity
363 * on his card. Unconfirmed, looks like it's not true (most likely since we
364 * now properly flush writes). */
365 write_reg32(adev, ACX_IO_PHY_DATA, value);
366 write_reg32(adev, ACX_IO_PHY_ADDR, reg);
367 write_flush(adev);
368 write_reg32(adev, ACX_IO_PHY_CTL, 1);
369 write_flush(adev);
370 acx_log(LOG_DEBUG, L_REALLYVERBOSE,
371 "radio PHY write 0x%02X at 0x%04X\n",
372 value, reg);
374 FN_EXIT0;
375 return OK;
379 #define NO_AUTO_INCREMENT 1
381 /***********************************************************************
382 ** acxpci_s_write_fw
384 ** Write the firmware image into the card.
386 ** Arguments:
387 ** adev wlan device structure
388 ** fw_image firmware image.
390 ** Returns:
391 ** 1 firmware image corrupted
392 ** 0 success
394 ** Standard csum implementation + write to IO
396 static int
397 acxpci_s_write_fw(acx_device_t * adev, const firmware_image_t *fw_image,
398 u32 offset)
400 int len, size;
401 u32 sum, v32;
402 /* we skip the first four bytes which contain the control sum */
404 const u8 *p = (u8 *) fw_image + 4;
406 FN_ENTER;
408 /* start the image checksum by adding the image size value */
409 sum = p[0] + p[1] + p[2] + p[3];
410 p += 4;
412 write_reg32(adev, ACX_IO_SLV_END_CTL, 0);
414 #if NO_AUTO_INCREMENT
415 write_reg32(adev, ACX_IO_SLV_MEM_CTL, 0); /* use basic mode */
416 #else
417 write_reg32(adev, ACX_IO_SLV_MEM_CTL, 1); /* use autoincrement mode */
418 write_reg32(adev, ACX_IO_SLV_MEM_ADDR, offset); /* configure start address */
419 write_flush(adev);
420 #endif
422 len = 0;
423 size = le32_to_cpu(fw_image->size) & (~3);
425 while (likely(len < size)) {
426 v32 = be32_to_cpu(*(u32 *) p);
427 sum += p[0] + p[1] + p[2] + p[3];
428 p += 4;
429 len += 4;
431 #if NO_AUTO_INCREMENT
432 write_reg32(adev, ACX_IO_SLV_MEM_ADDR, offset + len - 4);
433 write_flush(adev);
434 #endif
435 write_reg32(adev, ACX_IO_SLV_MEM_DATA, v32);
438 acx_log(LOG_DEBUG, L_REALLYVERBOSE,
439 "firmware written, size:%d sum1:%x sum2:%x\n",
440 size, sum, le32_to_cpu(fw_image->chksum));
442 /* compare our checksum with the stored image checksum */
443 FN_EXIT1(sum != le32_to_cpu(fw_image->chksum));
444 return (sum != le32_to_cpu(fw_image->chksum));
448 /***********************************************************************
449 ** acxpci_s_validate_fw
451 ** Compare the firmware image given with
452 ** the firmware image written into the card.
454 ** Arguments:
455 ** adev wlan device structure
456 ** fw_image firmware image.
458 ** Returns:
459 ** NOT_OK firmware image corrupted or not correctly written
460 ** OK success
462 ** Origin: Standard csum + Read IO
464 static int
465 acxpci_s_validate_fw(acx_device_t * adev, const firmware_image_t *fw_image,
466 u32 offset)
468 u32 sum, v32, w32;
469 int len, size;
470 int result = OK;
471 /* we skip the first four bytes which contain the control sum */
472 const u8 *p = (u8 *) fw_image + 4;
474 FN_ENTER;
476 /* start the image checksum by adding the image size value */
477 sum = p[0] + p[1] + p[2] + p[3];
478 p += 4;
480 write_reg32(adev, ACX_IO_SLV_END_CTL, 0);
482 #if NO_AUTO_INCREMENT
483 write_reg32(adev, ACX_IO_SLV_MEM_CTL, 0); /* use basic mode */
484 #else
485 write_reg32(adev, ACX_IO_SLV_MEM_CTL, 1); /* use autoincrement mode */
486 write_reg32(adev, ACX_IO_SLV_MEM_ADDR, offset); /* configure start address */
487 #endif
489 len = 0;
490 size = le32_to_cpu(fw_image->size) & (~3);
492 while (likely(len < size)) {
493 v32 = be32_to_cpu(*(u32 *) p);
494 p += 4;
495 len += 4;
497 #if NO_AUTO_INCREMENT
498 write_reg32(adev, ACX_IO_SLV_MEM_ADDR, offset + len - 4);
499 #endif
500 w32 = read_reg32(adev, ACX_IO_SLV_MEM_DATA);
502 if (unlikely(w32 != v32)) {
503 acx_log(LOG_WARNING, L_ANY,"FATAL: firmware upload: "
504 "data parts at offset %d don't match "
505 "(0x%08X vs. 0x%08X)! I/O timing issues "
506 "or defective memory, with DWL-xx0+? "
507 "ACX_IO_WIDTH=16 may help. Please report\n",
508 len, v32, w32);
509 result = NOT_OK;
510 break;
513 sum +=
514 (u8) w32 + (u8) (w32 >> 8) + (u8) (w32 >> 16) +
515 (u8) (w32 >> 24);
518 /* sum control verification */
519 if (result != NOT_OK) {
520 if (sum != le32_to_cpu(fw_image->chksum)) {
521 acx_log(LOG_WARNING, L_ANY, "FATAL: firmware upload: "
522 "checksums don't match!\n");
523 result = NOT_OK;
527 FN_EXIT1(result);
528 return result;
532 /***********************************************************************
533 ** acxpci_s_upload_fw
535 ** Called from acx_reset_dev
537 ** Origin: Derived from FW dissection
539 static int acxpci_s_upload_fw(acx_device_t * adev)
541 firmware_image_t *fw_image = NULL;
542 int res = NOT_OK;
543 int try;
544 u32 file_size;
545 char filename[sizeof("tiacx1NNcNN")];
547 FN_ENTER;
549 /* print exact chipset and radio ID to make sure people
550 * really get a clue on which files exactly they need to provide.
551 * Firmware loading is a frequent end-user PITA with these chipsets.
553 acx_log(LOG_INFO, L_ANY,
554 "need firmware for acx1%02d chipset "
555 "with radio ID %02X\n",
556 IS_ACX111(adev)*11, adev->radio_type);
557 acx_log(LOG_INFO, L_ANY, "Please provide via firmware hotplug:\n");
558 acx_log(LOG_INFO, L_ANY, "either combined firmware "
559 "(single file named 'tiacx1%02dc%02X')\n"
560 "or two files (base firmware file 'tiacx1%02d' "
561 "+ radio fw 'tiacx1%02dr%02X')\n",
562 IS_ACX111(adev)*11, adev->radio_type,
563 IS_ACX111(adev)*11,
564 IS_ACX111(adev)*11, adev->radio_type
567 /* print exact chipset and radio ID to make sure people really get a
568 * clue on which files exactly they are supposed to provide, since
569 * firmware loading is the biggest enduser PITA with these chipsets.
570 * Not printing radio ID in 0xHEX in order to not confuse them into
571 * wrong file naming
572 * COMMENTED OUT: this was already printed above
574 // printk( "acx: need to load firmware for acx1%02d chipset with radio ID %02x, please provide via firmware hotplug:\n"
575 // "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",
576 // IS_ACX111(adev)*11, adev->radio_type);
578 /* Try combined, then main image */
579 adev->need_radio_fw = 0;
580 snprintf(filename, sizeof(filename), "tiacx1%02dc%02X",
581 IS_ACX111(adev) * 11, adev->radio_type);
583 fw_image = acx_s_read_fw(adev->bus_dev, filename, &file_size);
584 if (!fw_image) {
585 adev->need_radio_fw = 1;
586 filename[sizeof("tiacx1NN") - 1] = '\0';
587 fw_image =
588 acx_s_read_fw(adev->bus_dev, filename, &file_size);
589 if (!fw_image) {
590 FN_EXIT1(NOT_OK);
591 return NOT_OK;
595 for (try = 1; try <= 5; try++) {
596 res = acxpci_s_write_fw(adev, fw_image, 0);
597 acx_log(LOG_DEBUG, L_INIT | L_REALLYVERBOSE,
598 "acx_write_fw (main/combined): %d\n", res);
599 if (OK == res) {
600 res = acxpci_s_validate_fw(adev, fw_image, 0);
601 acx_log(LOG_DEBUG, L_INIT | L_REALLYVERBOSE,
602 "acx_validate_fw (main/combined): %d\n", res);
605 if (OK == res) {
606 SET_BIT(adev->dev_state_mask, ACX_STATE_FW_LOADED);
607 break;
609 acx_log(LOG_WARNING, L_ANY,
610 "firmware upload attempt #%d FAILED, "
611 "retrying...\n", try);
612 acx_s_mwait(1000); /* better wait for a while... */
615 vfree(fw_image);
617 FN_EXIT1(res);
618 return res;
622 /***********************************************************************
623 ** acxpci_s_upload_radio
625 ** Uploads the appropriate radio module firmware into the card.
627 ** Origin: Standard Read/Write to IO
629 int acxpci_s_upload_radio(acx_device_t * adev)
631 acx_ie_memmap_t mm;
632 firmware_image_t *radio_image;
633 acx_cmd_radioinit_t radioinit;
634 int res = NOT_OK;
635 int try;
636 u32 offset;
637 u32 size;
638 char filename[sizeof("tiacx1NNrNN")];
640 if (!adev->need_radio_fw)
641 return OK;
643 FN_ENTER;
645 acx_s_interrogate(adev, &mm, ACX1xx_REG_MEMORY_MAP);
646 offset = le32_to_cpu(mm.CodeEnd);
648 snprintf(filename, sizeof(filename), "tiacx1%02dr%02X",
649 IS_ACX111(adev) * 11, adev->radio_type);
650 radio_image = acx_s_read_fw(adev->bus_dev, filename, &size);
651 if (!radio_image) {
652 acx_log(LOG_WARNING, L_ANY, "can't load radio module '%s'\n",
653 filename);
654 goto fail;
657 acx_s_issue_cmd(adev, ACX1xx_CMD_SLEEP, NULL, 0);
659 for (try = 1; try <= 5; try++) {
660 res = acxpci_s_write_fw(adev, radio_image, offset);
661 acx_log(LOG_DEBUG, L_INIT | L_REALLYVERBOSE,
662 "acx_write_fw (radio): %d\n", res);
663 if (OK == res) {
664 res = acxpci_s_validate_fw(adev, radio_image, offset);
665 acx_log(LOG_DEBUG, L_INIT | L_REALLYVERBOSE,
666 "acx_validate_fw (radio): %d\n", res);
669 if (OK == res)
670 break;
671 acx_log(LOG_WARNING, L_ANY,
672 "radio firmware upload attempt #%d FAILED, "
673 "retrying...\n", try);
674 acx_s_mwait(1000); /* better wait for a while... */
677 acx_s_issue_cmd(adev, ACX1xx_CMD_WAKE, NULL, 0);
678 radioinit.offset = cpu_to_le32(offset);
679 /* no endian conversion needed, remains in card CPU area: */
680 radioinit.len = radio_image->size;
682 vfree(radio_image);
684 if (OK != res)
685 goto fail;
687 /* will take a moment so let's have a big timeout */
688 acx_s_issue_cmd_timeo(adev, ACX1xx_CMD_RADIOINIT,
689 &radioinit, sizeof(radioinit),
690 CMD_TIMEOUT_MS(1000));
692 res = acx_s_interrogate(adev, &mm, ACX1xx_REG_MEMORY_MAP);
693 fail:
694 FN_EXIT1(res);
695 return res;
699 /***********************************************************************
700 ** acxpci_l_reset_mac
702 ** MAC will be reset
703 ** Call context: reset_dev
705 ** Origin: Standard Read/Write to IO
707 static void acxpci_l_reset_mac(acx_device_t * adev)
709 u16 temp;
711 FN_ENTER;
713 /* halt eCPU */
714 temp = read_reg16(adev, ACX_IO_ECPU_CTRL) | 0x1;
715 write_reg16(adev, ACX_IO_ECPU_CTRL, temp);
717 /* now do soft reset of eCPU, set bit */
718 temp = read_reg16(adev, ACX_IO_SOFT_RESET) | 0x1;
719 acx_log(LOG_DEBUG, L_REALLYVERBOSE, "enable soft reset\n");
720 write_reg16(adev, ACX_IO_SOFT_RESET, temp);
721 write_flush(adev);
723 /* now clear bit again: deassert eCPU reset */
724 acx_log(LOG_DEBUG, L_REALLYVERBOSE,
725 "disable soft reset and go to init mode\n");
726 write_reg16(adev, ACX_IO_SOFT_RESET, temp & ~0x1);
728 /* now start a burst read from initial EEPROM */
729 temp = read_reg16(adev, ACX_IO_EE_START) | 0x1;
730 write_reg16(adev, ACX_IO_EE_START, temp);
731 write_flush(adev);
733 FN_EXIT0;
737 /***********************************************************************
738 ** acxpci_s_verify_init
740 static int acxpci_s_verify_init(acx_device_t * adev)
742 int result = NOT_OK;
743 unsigned long timeout;
745 FN_ENTER;
747 timeout = jiffies + 2 * HZ;
748 for (;;) {
749 u16 irqstat = read_reg16(adev, ACX_IO_IRQ_STATUS_NON_DES);
750 if (irqstat & ACX_IRQ_FCS_THRESHOLD) {
751 result = OK;
752 write_reg16(adev, ACX_IO_IRQ_ACK,
753 ACX_IRQ_FCS_THRESHOLD);
754 break;
756 if (time_after(jiffies, timeout))
757 break;
758 /* Init may take up to ~0.5 sec total */
759 acx_s_mwait(50);
762 FN_EXIT1(result);
763 return result;
767 /***********************************************************************
768 ** A few low-level helpers
770 ** Note: these functions are not protected by lock
771 ** and thus are never allowed to be called from IRQ.
772 ** Also they must not race with fw upload which uses same hw regs
775 /***********************************************************************
776 ** acxpci_write_cmd_type_status
778 ** Origin: Common linux implementation
781 static inline void
782 acxpci_write_cmd_type_status(acx_device_t * adev, u16 type, u16 status)
784 FN_ENTER;
785 acx_writel(type | (status << 16), adev->cmd_area);
786 write_flush(adev);
787 FN_EXIT0;
791 /***********************************************************************
792 ** acxpci_read_cmd_type_status
794 ** Origin: Common linux implementation
796 static u32 acxpci_read_cmd_type_status(acx_device_t * adev)
798 u32 cmd_type, cmd_status;
800 FN_ENTER;
802 cmd_type = acx_readl(adev->cmd_area);
803 cmd_status = (cmd_type >> 16);
804 cmd_type = (u16) cmd_type;
806 acx_log(LOG_DEBUG, L_CTL, "cmd_type:%04X cmd_status:%04X [%s]\n",
807 cmd_type, cmd_status, acx_cmd_status_str(cmd_status));
809 FN_EXIT1(cmd_status);
810 return cmd_status;
814 /***********************************************************************
815 ** acxpci_s_reset_dev
817 ** Arguments:
818 ** netdevice that contains the adev variable
819 ** Returns:
820 ** NOT_OK on fail
821 ** OK on success
822 ** Side effects:
823 ** device is hard reset
824 ** Call context:
825 ** acxpci_e_probe
826 ** Comment:
827 ** This resets the device using low level hardware calls
828 ** as well as uploads and verifies the firmware to the card
831 static inline void init_mboxes(acx_device_t * adev)
833 u32 cmd_offs, info_offs;
835 FN_ENTER;
837 cmd_offs = read_reg32(adev, ACX_IO_CMD_MAILBOX_OFFS);
838 info_offs = read_reg32(adev, ACX_IO_INFO_MAILBOX_OFFS);
839 adev->cmd_area = (u8 *) adev->iobase2 + cmd_offs;
840 adev->info_area = (u8 *) adev->iobase2 + info_offs;
841 acx_log(LOG_DEBUG, L_REALLYVERBOSE, "iobase2=%p\n", adev->iobase2);
842 acx_log(LOG_DEBUG, L_REALLYVERBOSE, "cmd_mbox_offset=%X cmd_area=%p\n",
843 cmd_offs, adev->cmd_area);
844 acx_log(LOG_DEBUG, L_REALLYVERBOSE,
845 "info_mbox_offset=%X info_area=%p\n",
846 info_offs, adev->info_area);
847 FN_EXIT0;
851 static inline void read_eeprom_area(acx_device_t * adev)
853 #if ACX_DEBUG > 1
854 int offs;
855 u8 tmp;
857 FN_ENTER;
859 for (offs = 0x8c; offs < 0xb9; offs++)
860 acxpci_read_eeprom_byte(adev, offs, &tmp);
862 FN_EXIT0;
863 #endif
867 int acxpci_s_reset_dev(acx_device_t * adev)
869 const char *msg = "";
870 unsigned long flags;
871 int result = NOT_OK;
872 u16 hardware_info;
873 u16 ecpu_ctrl;
874 int count;
876 FN_ENTER;
878 /* reset the device to make sure the eCPU is stopped
879 * to upload the firmware correctly */
881 acx_lock(adev, flags);
883 #ifdef CONFIG_PCI
884 acxpci_l_reset_mac(adev);
885 #endif
887 ecpu_ctrl = read_reg16(adev, ACX_IO_ECPU_CTRL) & 1;
888 if (!ecpu_ctrl) {
889 msg = "eCPU is already running. ";
890 goto end_unlock;
892 #if 0
893 if (read_reg16(adev, ACX_IO_SOR_CFG) & 2) {
894 /* eCPU most likely means "embedded CPU" */
895 msg = "eCPU did not start after boot from flash. ";
896 goto end_unlock;
899 /* check sense on reset flags */
900 if (read_reg16(adev, ACX_IO_SOR_CFG) & 0x10) {
901 printk("%s: eCPU did not start after boot (SOR), "
902 "is this fatal?\n", wiphy_name(adev->ieee->wiphy));
904 #endif
905 /* scan, if any, is stopped now, setting corresponding IRQ bit */
906 SET_BIT(adev->irq_status, ACX_IRQ_SCAN_COMPLETE);
908 acx_unlock(adev, flags);
910 /* need to know radio type before fw load */
911 /* Need to wait for arrival of this information in a loop,
912 * most probably since eCPU runs some init code from EEPROM
913 * (started burst read in reset_mac()) which also
914 * sets the radio type ID */
916 count = 0xffff;
917 do {
918 hardware_info = read_reg16(adev, ACX_IO_EEPROM_INFORMATION);
919 if (!--count) {
920 msg = "eCPU didn't indicate radio type";
921 goto end_fail;
923 cpu_relax();
924 } while (!(hardware_info & 0xff00)); /* radio type still zero? */
926 /* printk("DEBUG: count %d\n", count); */
927 adev->form_factor = hardware_info & 0xff;
928 adev->radio_type = hardware_info >> 8;
930 /* load the firmware */
931 if (OK != acxpci_s_upload_fw(adev))
932 goto end_fail;
934 /* acx_s_mwait(10); this one really shouldn't be required */
936 /* now start eCPU by clearing bit */
937 write_reg16(adev, ACX_IO_ECPU_CTRL, ecpu_ctrl & ~0x1);
938 acx_log(LOG_DEBUG, L_REALLYVERBOSE,
939 "booted eCPU up and waiting for completion...\n");
941 /* wait for eCPU bootup */
942 if (OK != acxpci_s_verify_init(adev)) {
943 msg = "timeout waiting for eCPU. ";
944 goto end_fail;
946 acx_log(LOG_DEBUG, L_REALLYVERBOSE,
947 "eCPU has woken up, card is ready to be configured\n");
949 init_mboxes(adev);
950 acxpci_write_cmd_type_status(adev, 0, 0);
952 /* test that EEPROM is readable */
953 read_eeprom_area(adev);
955 result = OK;
956 goto end;
958 /* Finish error message. Indicate which function failed */
959 end_unlock:
960 acx_unlock(adev, flags);
961 end_fail:
962 acx_log(LOG_WARNING, L_ANY, "%sreset_dev() FAILED\n", msg);
963 end:
964 FN_EXIT1(result);
965 return result;
969 /***********************************************************************
970 ** acxpci_s_issue_cmd_timeo
972 ** Sends command to fw, extract result
974 ** NB: we do _not_ take lock inside, so be sure to not touch anything
975 ** which may interfere with IRQ handler operation
977 ** TODO: busy wait is a bit silly, so:
978 ** 1) stop doing many iters - go to sleep after first
979 ** 2) go to waitqueue based approach: wait, not poll!
981 #undef FUNC
982 #define FUNC "issue_cmd"
984 #if !ACX_DEBUG
986 acxpci_s_issue_cmd_timeo(acx_device_t * adev,
987 unsigned int cmd,
988 void *buffer, unsigned buflen, unsigned cmd_timeout)
990 #else
992 acxpci_s_issue_cmd_timeo_debug(acx_device_t * adev,
993 unsigned cmd,
994 void *buffer,
995 unsigned buflen,
996 unsigned cmd_timeout, const char *cmdstr)
998 unsigned long start = jiffies;
999 #endif
1000 const char *devname;
1001 unsigned counter;
1002 u16 irqtype;
1003 u16 cmd_status;
1004 unsigned long timeout;
1006 FN_ENTER;
1008 devname = wiphy_name(adev->ieee->wiphy);
1009 if (!devname || !devname[0] || devname[4] == '%')
1010 devname = "acx";
1012 acx_log(LOG_DEBUG, L_CTL,
1013 FUNC "(cmd:%s,buflen:%u,timeout:%ums,type:0x%04X)\n",
1014 cmdstr, buflen, cmd_timeout,
1015 buffer ? le16_to_cpu(((acx_ie_generic_t *) buffer)->type) : -1);
1017 if (!(adev->dev_state_mask & ACX_STATE_FW_LOADED)) {
1018 acx_log(LOG_WARNING, L_ANY,
1019 "%s: " FUNC "(): firmware is not loaded yet, "
1020 "cannot execute commands!\n", devname);
1021 goto bad;
1024 if (cmd != ACX1xx_CMD_INTERROGATE)
1025 acx_log_dump(LOG_DEBUG, L_REALLYVERBOSE, buffer, buflen,
1026 "input buffer:\n");
1028 /* wait for firmware to become idle for our command submission */
1029 timeout = HZ / 5;
1030 counter = (timeout * 1000 / HZ) - 1; /* in ms */
1031 timeout += jiffies;
1032 do {
1033 cmd_status = acxpci_read_cmd_type_status(adev);
1034 /* Test for IDLE state */
1035 if (!cmd_status)
1036 break;
1037 if (counter % 8 == 0) {
1038 if (time_after(jiffies, timeout)) {
1039 counter = 0;
1040 break;
1042 /* we waited 8 iterations, no luck. Sleep 8 ms */
1043 acx_s_mwait(8);
1045 } while (likely(--counter));
1047 if (!counter) {
1048 /* the card doesn't get idle, we're in trouble */
1049 acx_log(LOG_WARNING, L_ANY,
1050 "%s: " FUNC "(): cmd_status is not IDLE: 0x%04X!=0\n",
1051 devname, cmd_status);
1052 goto bad;
1053 } else if (counter < 190) { /* if waited >10ms... */
1054 acx_log(LOG_DEBUG, L_CTL | L_REALLYVERBOSE,
1055 FUNC "(): waited for IDLE %dms. "
1056 "Please report\n", 199 - counter);
1059 /* now write the parameters of the command if needed */
1060 if (buffer && buflen) {
1061 /* if it's an INTERROGATE command, just pass the length
1062 * of parameters to read, as data */
1063 #if CMD_DISCOVERY
1064 if (cmd == ACX1xx_CMD_INTERROGATE)
1065 memset_io(adev->cmd_area + 4, 0xAA, buflen);
1066 #endif
1067 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1068 memcpy_toio(adev->cmd_area + 4, buffer,
1069 (cmd == ACX1xx_CMD_INTERROGATE) ? 4 : buflen);
1071 /* now write the actual command type */
1072 acxpci_write_cmd_type_status(adev, cmd, 0);
1073 /* execute command */
1074 write_reg16(adev, ACX_IO_INT_TRIG, INT_TRIG_CMD);
1075 write_flush(adev);
1077 /* wait for firmware to process command */
1079 /* Ensure nonzero and not too large timeout.
1080 ** Also converts e.g. 100->99, 200->199
1081 ** which is nice but not essential */
1082 cmd_timeout = (cmd_timeout - 1) | 1;
1083 if (unlikely(cmd_timeout > 1199))
1084 cmd_timeout = 1199;
1085 /* clear CMD_COMPLETE bit. can be set only by IRQ handler: */
1086 CLEAR_BIT(adev->irq_status, ACX_IRQ_CMD_COMPLETE);
1087 /* we schedule away sometimes (timeout can be large) */
1088 counter = cmd_timeout;
1089 timeout = jiffies + HZ;
1090 do {
1091 if (!adev->irqs_active) { /* IRQ disabled: poll */
1092 irqtype = read_reg16(adev, ACX_IO_IRQ_STATUS_NON_DES);
1093 if (irqtype & ACX_IRQ_CMD_COMPLETE) {
1094 write_reg16(adev, ACX_IO_IRQ_ACK,
1095 ACX_IRQ_CMD_COMPLETE);
1096 break;
1098 } else { /* Wait when IRQ will set the bit */
1099 irqtype = adev->irq_status;
1100 if (irqtype & ACX_IRQ_CMD_COMPLETE)
1101 break;
1104 if (counter % 8 == 0) {
1105 if (time_after(jiffies, timeout)) {
1106 counter = 0;
1107 break;
1109 /* we waited 8 iterations, no luck. Sleep 8 ms */
1110 acx_s_mwait(8);
1112 } while (likely(--counter));
1114 /* save state for debugging */
1115 cmd_status = acxpci_read_cmd_type_status(adev);
1117 /* put the card in IDLE state */
1118 acxpci_write_cmd_type_status(adev, 0, 0);
1120 if ((cmd_timeout - counter) == 0) { /* timed out! */
1121 acx_log(LOG_WARNING, L_ANY,
1122 "%s: " FUNC "(): timed out %s for CMD_COMPLETE. "
1123 "irq bits:0x%04X irq_status:0x%04X timeout:%dms "
1124 "cmd_status:%d (%s)\n",
1125 devname, (adev->irqs_active) ? "waiting" : "polling",
1126 irqtype, adev->irq_status, cmd_timeout,
1127 cmd_status, acx_cmd_status_str(cmd_status));
1128 acx_log(LOG_WARNING, L_ANY, "hack: don't do: 'goto bad;' "
1129 "counter: %d, cmd_timeout: %d, "
1130 "cmd_timeout-counter: %d\n",
1131 counter, cmd_timeout, cmd_timeout - counter);
1132 } else if (counter == 0) { /* maybe timed out! */
1133 acx_log(LOG_DEBUG, L_CTL | L_REALLYVERBOSE,
1134 FUNC "(): %s for CMD_COMPLETE %dms. "
1135 "count:%d. Please report\n",
1136 (adev->irqs_active) ? "waited" : "polled",
1137 cmd_timeout - counter, counter);
1138 } else if ((cmd_timeout - counter) > 30) { /* if waited >30ms... */
1139 acx_log(LOG_DEBUG, L_CTL | L_REALLYVERBOSE,
1140 FUNC "(): %s for CMD_COMPLETE %dms. "
1141 "count:%d. Please report\n",
1142 (adev->irqs_active) ? "waited" : "polled",
1143 cmd_timeout - counter, counter);
1146 if (1 != cmd_status) { /* it is not a 'Success' */
1147 acx_log(LOG_WARNING, L_ANY,
1148 "%s: " FUNC "(): cmd_status is not SUCCESS: %d (%s). "
1149 "Took %dms of %d\n",
1150 devname, cmd_status, acx_cmd_status_str(cmd_status),
1151 cmd_timeout - counter, cmd_timeout);
1152 /* zero out result buffer
1153 * WARNING: this will trash stack in case of illegally large input
1154 * length! */
1155 if (buffer && buflen)
1156 memset(buffer, 0, buflen);
1157 goto bad;
1160 /* read in result parameters if needed */
1161 if (buffer && buflen && (cmd == ACX1xx_CMD_INTERROGATE)) {
1162 /* adev->cmd_area points to PCI device's memory, not to RAM! */
1163 memcpy_fromio(buffer, adev->cmd_area + 4, buflen);
1164 acx_log_dump(LOG_DEBUG, L_REALLYVERBOSE, buffer, buflen,
1165 "output buffer:\n");
1167 /* ok: */
1168 acx_log(LOG_DEBUG, L_CTL, FUNC "(%s): took %ld jiffies to complete\n",
1169 cmdstr, jiffies - start);
1170 FN_EXIT1(OK);
1171 return OK;
1173 bad:
1174 /* Give enough info so that callers can avoid
1175 ** printing their own diagnostic messages */
1176 #if ACX_DEBUG
1177 acx_log(LOG_WARNING, L_ANY,
1178 "%s: " FUNC "(cmd:%s) FAILED\n", devname, cmdstr);
1179 #else
1180 acx_log(LOG_WARNING, L_ANY,
1181 "%s: " FUNC "(cmd:0x%04X) FAILED\n", devname, cmd);
1182 #endif
1183 dump_stack();
1184 FN_EXIT1(NOT_OK);
1185 return NOT_OK;
1189 /***********************************************************************
1191 #ifdef NONESSENTIAL_FEATURES
1192 typedef struct device_id {
1193 unsigned char id[6];
1194 char *descr;
1195 char *type;
1196 } device_id_t;
1198 static const device_id_t device_ids[] = {
1200 {'G', 'l', 'o', 'b', 'a', 'l'},
1201 NULL,
1202 NULL,
1205 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
1206 "uninitialized",
1207 "SpeedStream SS1021 or Gigafast WF721-AEX"},
1209 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85},
1210 "non-standard",
1211 "DrayTek Vigor 520"},
1213 {'?', '?', '?', '?', '?', '?'},
1214 "non-standard",
1215 "Level One WPC-0200"},
1217 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1218 "empty",
1219 "DWL-650+ variant"}
1222 static void acx_show_card_eeprom_id(acx_device_t * adev)
1224 unsigned char buffer[CARD_EEPROM_ID_SIZE];
1225 int i;
1227 FN_ENTER;
1229 memset(&buffer, 0, CARD_EEPROM_ID_SIZE);
1230 /* use direct EEPROM access */
1231 for (i = 0; i < CARD_EEPROM_ID_SIZE; i++) {
1232 if (OK != acxpci_read_eeprom_byte(adev,
1233 ACX100_EEPROM_ID_OFFSET + i,
1234 &buffer[i])) {
1235 acx_log(LOG_DEBUG, L_ANY, "reading EEPROM FAILED\n");
1236 break;
1240 for (i = 0; i < ARRAY_SIZE(device_ids); i++) {
1241 if (memcmp(&buffer, device_ids[i].id, CARD_EEPROM_ID_SIZE))
1242 continue;
1243 if (device_ids[i].descr) {
1244 acx_log(LOG_INFO, L_ANY,
1245 "EEPROM card ID string check "
1246 "found %s card ID: is this %s?\n",
1247 device_ids[i].descr,
1248 device_ids[i].type);
1250 break;
1252 if (i == ARRAY_SIZE(device_ids)) {
1253 acx_log(LOG_WARNING, L_ANY,
1254 "EEPROM card ID string check found "
1255 "unknown card: expected 'Global', got '%.*s\'. "
1256 "Please report\n", CARD_EEPROM_ID_SIZE, buffer);
1258 FN_EXIT0;
1260 #endif /* NONESSENTIAL_FEATURES */
1263 /***********************************************************************
1264 ** acxpci_free_desc_queues
1266 ** Releases the queues that have been allocated, the
1267 ** others have been initialised to NULL so this
1268 ** function can be used if only part of the queues were allocated.
1271 static inline void
1272 free_coherent(struct pci_dev *hwdev, size_t size,
1273 void *vaddr, dma_addr_t dma_handle)
1275 dma_free_coherent(hwdev == NULL ? NULL : &hwdev->dev,
1276 size, vaddr, dma_handle);
1280 void acxpci_free_desc_queues(acx_device_t * adev)
1282 unsigned long flags;
1284 #define ACX_FREE_QUEUE(size, ptr, phyaddr) \
1285 if (ptr) { \
1286 free_coherent(NULL, size, ptr, phyaddr); \
1287 ptr = NULL; \
1288 size = 0; \
1291 FN_ENTER;
1293 ACX_FREE_QUEUE(adev->txhostdesc_area_size, adev->txhostdesc_start,
1294 adev->txhostdesc_startphy);
1295 ACX_FREE_QUEUE(adev->txbuf_area_size, adev->txbuf_start,
1296 adev->txbuf_startphy);
1298 acx_lock(adev, flags);
1299 adev->txdesc_start = NULL;
1300 acx_unlock(adev, flags);
1302 ACX_FREE_QUEUE(adev->rxhostdesc_area_size, adev->rxhostdesc_start,
1303 adev->rxhostdesc_startphy);
1304 ACX_FREE_QUEUE(adev->rxbuf_area_size, adev->rxbuf_start,
1305 adev->rxbuf_startphy);
1307 acx_lock(adev, flags);
1308 adev->rxdesc_start = NULL;
1309 acx_unlock(adev, flags);
1311 FN_EXIT0;
1315 /***********************************************************************
1316 ** acxpci_s_delete_dma_regions
1318 static void acxpci_s_delete_dma_regions(acx_device_t * adev)
1320 FN_ENTER;
1321 /* disable radio Tx/Rx. Shouldn't we use the firmware commands
1322 * here instead? Or are we that much down the road that it's no
1323 * longer possible here? */
1324 write_reg16(adev, ACX_IO_ENABLE, 0);
1326 acx_s_mwait(100);
1328 /* NO locking for all parts of acxpci_free_desc_queues because:
1329 * while calling dma_free_coherent() interrupts need to be 'free'
1330 * but if you spinlock the whole function (acxpci_free_desc_queues)
1331 * you'll get an error */
1332 acxpci_free_desc_queues(adev);
1334 FN_EXIT0;
1338 /***********************************************************************
1339 ** acxpci_e_probe
1341 ** Probe routine called when a PCI device w/ matching ID is found.
1342 ** Here's the sequence:
1343 ** - Allocate the PCI resources.
1344 ** - Read the PCMCIA attribute memory to make sure we have a WLAN card
1345 ** - Reset the MAC
1346 ** - Initialize the dev and wlan data
1347 ** - Initialize the MAC
1349 ** pdev - ptr to pci device structure containing info about pci configuration
1350 ** id - ptr to the device id entry that matched this device
1352 static const u16 IO_ACX100[] = {
1353 0x0000, /* ACX_IO_SOFT_RESET */
1355 0x0014, /* ACX_IO_SLV_MEM_ADDR */
1356 0x0018, /* ACX_IO_SLV_MEM_DATA */
1357 0x001c, /* ACX_IO_SLV_MEM_CTL */
1358 0x0020, /* ACX_IO_SLV_END_CTL */
1360 0x0034, /* ACX_IO_FEMR */
1362 0x007c, /* ACX_IO_INT_TRIG */
1363 0x0098, /* ACX_IO_IRQ_MASK */
1364 0x00a4, /* ACX_IO_IRQ_STATUS_NON_DES */
1365 0x00a8, /* ACX_IO_IRQ_REASON */
1366 0x00ac, /* ACX_IO_IRQ_ACK */
1367 0x00b0, /* ACX_IO_HINT_TRIG */
1369 0x0104, /* ACX_IO_ENABLE */
1371 0x0250, /* ACX_IO_EEPROM_CTL */
1372 0x0254, /* ACX_IO_EEPROM_ADDR */
1373 0x0258, /* ACX_IO_EEPROM_DATA */
1374 0x025c, /* ACX_IO_EEPROM_CFG */
1376 0x0268, /* ACX_IO_PHY_ADDR */
1377 0x026c, /* ACX_IO_PHY_DATA */
1378 0x0270, /* ACX_IO_PHY_CTL */
1380 0x0290, /* ACX_IO_GPIO_OE */
1382 0x0298, /* ACX_IO_GPIO_OUT */
1384 0x02a4, /* ACX_IO_CMD_MAILBOX_OFFS */
1385 0x02a8, /* ACX_IO_INFO_MAILBOX_OFFS */
1386 0x02ac, /* ACX_IO_EEPROM_INFORMATION */
1388 0x02d0, /* ACX_IO_EE_START */
1389 0x02d4, /* ACX_IO_SOR_CFG */
1390 0x02d8 /* ACX_IO_ECPU_CTRL */
1393 static const u16 IO_ACX111[] = {
1394 0x0000, /* ACX_IO_SOFT_RESET */
1396 0x0014, /* ACX_IO_SLV_MEM_ADDR */
1397 0x0018, /* ACX_IO_SLV_MEM_DATA */
1398 0x001c, /* ACX_IO_SLV_MEM_CTL */
1399 0x0020, /* ACX_IO_SLV_END_CTL */
1401 0x0034, /* ACX_IO_FEMR */
1403 0x00b4, /* ACX_IO_INT_TRIG */
1404 0x00d4, /* ACX_IO_IRQ_MASK */
1405 /* we do mean NON_DES (0xf0), not NON_DES_MASK which is at 0xe0: */
1406 0x00f0, /* ACX_IO_IRQ_STATUS_NON_DES */
1407 0x00e4, /* ACX_IO_IRQ_REASON */
1408 0x00e8, /* ACX_IO_IRQ_ACK */
1409 0x00ec, /* ACX_IO_HINT_TRIG */
1411 0x01d0, /* ACX_IO_ENABLE */
1413 0x0338, /* ACX_IO_EEPROM_CTL */
1414 0x033c, /* ACX_IO_EEPROM_ADDR */
1415 0x0340, /* ACX_IO_EEPROM_DATA */
1416 0x0344, /* ACX_IO_EEPROM_CFG */
1418 0x0350, /* ACX_IO_PHY_ADDR */
1419 0x0354, /* ACX_IO_PHY_DATA */
1420 0x0358, /* ACX_IO_PHY_CTL */
1422 0x0374, /* ACX_IO_GPIO_OE */
1424 0x037c, /* ACX_IO_GPIO_OUT */
1426 0x0388, /* ACX_IO_CMD_MAILBOX_OFFS */
1427 0x038c, /* ACX_IO_INFO_MAILBOX_OFFS */
1428 0x0390, /* ACX_IO_EEPROM_INFORMATION */
1430 0x0100, /* ACX_IO_EE_START */
1431 0x0104, /* ACX_IO_SOR_CFG */
1432 0x0108, /* ACX_IO_ECPU_CTRL */
1435 static const struct ieee80211_ops acxpci_hw_ops = {
1436 .tx = acx_i_start_xmit,
1437 .conf_tx = acx_net_conf_tx,
1438 .add_interface = acx_add_interface,
1439 .remove_interface = acx_remove_interface,
1440 .start = acxpci_e_open,
1441 .configure_filter = acx_i_set_multicast_list,
1442 .stop = acxpci_e_close,
1443 .config = acx_net_config,
1444 .config_interface = acx_config_interface,
1445 .set_key = acx_net_set_key,
1446 .get_stats = acx_e_get_stats,
1447 .get_tx_stats = acx_net_get_tx_stats,
1451 #ifdef CONFIG_PCI
1452 static int __devinit
1453 acxpci_e_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1455 acx111_ie_configoption_t co;
1456 unsigned long mem_region1 = 0;
1457 unsigned long mem_region2 = 0;
1458 unsigned long mem_region1_size;
1459 unsigned long mem_region2_size;
1460 unsigned long phymem1;
1461 unsigned long phymem2;
1462 void *mem1 = NULL;
1463 void *mem2 = NULL;
1464 acx_device_t *adev = NULL;
1465 const char *chip_name;
1466 int result = -EIO;
1467 int err;
1468 u8 chip_type;
1469 struct ieee80211_hw *ieee;
1471 FN_ENTER;
1473 ieee = ieee80211_alloc_hw(sizeof(struct acx_device), &acxpci_hw_ops);
1474 if (!ieee) {
1475 acx_log(LOG_WARNING, L_ANY,
1476 "could not allocate ieee80211 structure %s\n",
1477 pci_name(pdev));
1478 goto fail_alloc_netdev;
1480 ieee->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
1481 /* TODO: mainline doesn't support the following flags yet */
1483 ~IEEE80211_HW_MONITOR_DURING_OPER &
1484 ~IEEE80211_HW_WEP_INCLUDE_IV;
1486 ieee->queues = 1;
1488 /* TODO: although in the original driver the maximum value was 100,
1489 * the OpenBSD driver assigns maximum values depending on the type of
1490 * radio transceiver (i.e. Radia, Maxim, etc.). This value is always a
1491 * positive integer which most probably indicates the gain of the AGC
1492 * in the rx path of the chip, in dB steps (0.625 dB, for example?).
1493 * The mapping of this rssi value to dBm is still unknown, but it can
1494 * nevertheless be used as a measure of relative signal strength. The
1495 * other two values, i.e. max_signal and max_noise, do not seem to be
1496 * supported on my acx111 card (they are always 0), although iwconfig
1497 * reports them (in dBm) when using ndiswrapper with the Windows XP
1498 * driver. The GPL-licensed part of the AVM FRITZ!WLAN USB Stick
1499 * driver sources (for the TNETW1450, though) seems to also indicate
1500 * that only the RSSI is supported. In conclusion, the max_signal and
1501 * max_noise values will not be initialised by now, as they do not
1502 * seem to be supported or how to acquire them is still unknown. */
1503 ieee->max_rssi = 100;
1505 adev = ieee2adev(ieee);
1507 memset(adev, 0, sizeof(*adev));
1508 /** Set up our private interface **/
1509 spin_lock_init(&adev->spinlock);
1510 spin_lock_init(&adev->irqlock);
1511 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
1512 acx_log(LOG_INFO, L_ANY,
1513 "mutex_init(&adev->mutex); // adev = 0x%px\n", adev);
1514 mutex_init(&adev->mutex);
1515 /* since nobody can see new netdev yet, we can as well
1516 ** just _presume_ that we're under sem (instead of actually taking it): */
1517 /* acx_sem_lock(adev); */
1518 adev->ieee = ieee;
1519 adev->pdev = pdev;
1520 adev->bus_dev = &pdev->dev;
1522 /** Finished with private interface **/
1524 /** begin board specific inits **/
1525 pci_set_drvdata(pdev, ieee);
1527 /* Enable the PCI device */
1528 if (pci_enable_device(pdev)) {
1529 acx_log(LOG_WARNING, L_ANY, "pci_enable_device() FAILED\n");
1530 result = -ENODEV;
1531 goto fail_pci_enable_device;
1534 /* enable busmastering (required for CardBus) */
1535 pci_set_master(pdev);
1538 /* chiptype is u8 but id->driver_data is ulong
1539 ** Works for now (possible values are 1 and 2) */
1540 chip_type = (u8) id->driver_data;
1541 /* acx100 and acx111 have different PCI memory regions */
1542 if (chip_type == CHIPTYPE_ACX100) {
1543 chip_name = "ACX100";
1544 mem_region1 = PCI_ACX100_REGION1;
1545 mem_region1_size = PCI_ACX100_REGION1_SIZE;
1547 mem_region2 = PCI_ACX100_REGION2;
1548 mem_region2_size = PCI_ACX100_REGION2_SIZE;
1549 } else if (chip_type == CHIPTYPE_ACX111) {
1550 chip_name = "ACX111";
1551 mem_region1 = PCI_ACX111_REGION1;
1552 mem_region1_size = PCI_ACX111_REGION1_SIZE;
1554 mem_region2 = PCI_ACX111_REGION2;
1555 mem_region2_size = PCI_ACX111_REGION2_SIZE;
1556 } else {
1557 acx_log(LOG_WARNING, L_ANY,
1558 "unknown chip type 0x%04X\n", chip_type);
1559 goto fail_unknown_chiptype;
1562 /* Figure out our resources
1564 * Request our PCI IO regions
1566 err = pci_request_region(pdev, mem_region1, "acx_1");
1567 if (err) {
1568 acx_log(LOG_WARNING, L_ANY, "pci_request_region (1/2) FAILED!"
1569 "No cardbus support in kernel?\n");
1570 goto fail_request_mem_region1;
1573 phymem1 = pci_resource_start(pdev, mem_region1);
1575 err = pci_request_region(pdev, mem_region2, "acx_2");
1576 if (err) {
1577 acx_log(LOG_WARNING, L_ANY, "pci_request_region (2/2) FAILED!\n");
1578 goto fail_request_mem_region2;
1581 phymem2 = pci_resource_start(pdev, mem_region2);
1584 * We got them? Map them!
1586 * We pass 0 as the third argument to pci_iomap(): it will map the full
1587 * region in this case, which is what we want.
1590 mem1 = pci_iomap(pdev, mem_region1, 0);
1591 if (!mem1) {
1592 acx_log(LOG_WARNING, L_ANY, "ioremap() FAILED\n");
1593 goto fail_ioremap1;
1596 mem2 = pci_iomap(pdev, mem_region2, 0);
1597 if (!mem2) {
1598 acx_log(LOG_WARNING, L_ANY, "ioremap() #2 FAILED\n");
1599 goto fail_ioremap2;
1602 acx_log(LOG_INFO, L_ANY, "found %s-based wireless network card at %s, "
1603 "irq:%d, phymem1:0x%lX, phymem2:0x%lX, mem1:0x%p, "
1604 "mem1_size:%ld, mem2:0x%p, mem2_size:%ld\n",
1605 chip_name, pci_name(pdev), pdev->irq, phymem1, phymem2,
1606 mem1, mem_region1_size, mem2, mem_region2_size);
1607 //log(L_ANY, "initial debug setting is 0x%04X\n", acx_debug);
1608 adev->chip_type = chip_type;
1609 adev->chip_name = chip_name;
1610 adev->io = (CHIPTYPE_ACX100 == chip_type) ? IO_ACX100 : IO_ACX111;
1611 adev->membase = phymem1;
1612 adev->iobase = mem1;
1613 adev->membase2 = phymem2;
1614 adev->iobase2 = mem2;
1615 adev->irq = pdev->irq;
1618 if (0 == pdev->irq) {
1619 acx_log(LOG_WARNING, L_ANY, "can't use IRQ 0\n");
1620 goto fail_irq;
1622 SET_IEEE80211_DEV(ieee, &pdev->dev);
1624 /* request shared IRQ handler */
1625 if (request_irq
1626 (adev->irq, acxpci_i_interrupt, IRQF_SHARED, KBUILD_MODNAME, adev)) {
1627 acx_log(LOG_WARNING, L_ANY, "%s: request_irq FAILED\n",
1628 wiphy_name(adev->ieee->wiphy));
1629 result = -EAGAIN;
1630 goto done;
1632 acx_log(LOG_DEBUG, L_IRQ | L_REALLYVERBOSE,
1633 "request_irq %d successful\n", adev->irq);
1635 /* to find crashes due to weird driver access
1636 * to unconfigured interface (ifup) */
1637 adev->mgmt_timer.function = (void (*)(unsigned long))0x0000dead;
1640 #ifdef NONESSENTIAL_FEATURES
1641 acx_show_card_eeprom_id(adev);
1642 #endif /* NONESSENTIAL_FEATURES */
1645 /* ok, pci setup is finished, now start initializing the card */
1647 /* NB: read_reg() reads may return bogus data before reset_dev(),
1648 * since the firmware which directly controls large parts of the I/O
1649 * registers isn't initialized yet.
1650 * acx100 seems to be more affected than acx111 */
1651 if (OK != acxpci_s_reset_dev(adev))
1652 goto fail_reset;
1654 if (IS_ACX100(adev)) {
1655 /* ACX100: configopt struct in cmd mailbox - directly after reset */
1656 memcpy_fromio(&co, adev->cmd_area, sizeof(co));
1659 if (OK != acx_s_init_mac(adev))
1660 goto fail_init_mac;
1662 if (IS_ACX111(adev)) {
1663 /* ACX111: configopt struct needs to be queried after full init */
1664 acx_s_interrogate(adev, &co, ACX111_REG_CONFIG_OPTIONS);
1666 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
1667 if (OK != acxpci_read_eeprom_byte(adev, 0x05, &adev->eeprom_version))
1668 goto fail_read_eeprom_version;
1670 acx_s_parse_configoption(adev, &co);
1671 acx_s_set_defaults(adev);
1672 acx_s_get_firmware_version(adev); /* needs to be after acx_s_init_mac() */
1673 acx_display_hardware_details(adev);
1675 /* Register the card, AFTER everything else has been set up,
1676 * since otherwise an ioctl could step on our feet due to
1677 * firmware operations happening in parallel or uninitialized data */
1680 acx_proc_register_entries(ieee);
1682 /* Now we have our device, so make sure the kernel doesn't try
1683 * to send packets even though we're not associated to a network yet */
1685 /* after register_netdev() userspace may start working with dev
1686 * (in particular, on other CPUs), we only need to up the sem */
1687 /* acx_sem_unlock(adev); */
1689 acx_log(LOG_INFO, L_ANY, "driver version " ACX_RELEASE
1690 ": net device %s, driver compiled "
1691 "against wireless extensions %d and Linux %s\n",
1692 wiphy_name(adev->ieee->wiphy), WIRELESS_EXT, UTS_RELEASE);
1694 MAC_COPY(adev->ieee->wiphy->perm_addr, adev->dev_addr);
1696 acx_log(LOG_INFO, L_IRQ | L_INIT, "using IRQ %d\n", pdev->irq);
1698 /** done with board specific setup **/
1700 /* need to be able to restore PCI state after a suspend */
1701 #ifdef CONFIG_PM
1702 pci_save_state(pdev);
1703 #endif
1705 err = acx_setup_modes(adev);
1706 if (err) {
1707 acx_log(LOG_WARNING, L_ANY, "can't register hwmode\n");
1708 goto fail_register_netdev;
1711 acx_init_task_scheduler(adev);
1712 err = ieee80211_register_hw(ieee);
1713 if (OK != err) {
1714 acx_log(LOG_WARNING, L_ANY,
1715 "ieee80211_register_hw() FAILED: %d\n", err);
1716 goto fail_register_netdev;
1718 #if CMD_DISCOVERY
1719 great_inquisitor(adev);
1720 #endif
1722 result = OK;
1723 goto done;
1725 /* error paths: undo everything in reverse order... */
1728 acxpci_s_delete_dma_regions(adev);
1729 pci_set_drvdata(pdev, NULL);
1731 fail_init_mac:
1732 fail_read_eeprom_version:
1733 fail_reset:
1735 fail_alloc_netdev:
1736 fail_irq:
1737 pci_iounmap(pdev, mem2);
1739 fail_ioremap2:
1740 pci_iounmap(pdev, mem1);
1742 fail_ioremap1:
1743 pci_release_region(pdev, mem_region2);
1745 fail_request_mem_region2:
1746 pci_release_region(pdev, mem_region1);
1748 fail_request_mem_region1:
1749 fail_unknown_chiptype:
1750 pci_disable_device(pdev);
1752 fail_pci_enable_device:
1753 #ifdef CONFIG_PM
1754 pci_set_power_state(pdev, PCI_D3hot);
1755 #endif
1757 fail_register_netdev:
1758 ieee80211_free_hw(ieee);
1759 done:
1760 FN_EXIT1(result);
1761 return result;
1765 /***********************************************************************
1766 ** acxpci_e_remove
1768 ** Shut device down (if not hot unplugged)
1769 ** and deallocate PCI resources for the acx chip.
1771 ** pdev - ptr to PCI device structure containing info about pci configuration
1773 static void __devexit acxpci_e_remove(struct pci_dev *pdev)
1775 struct ieee80211_hw *hw = (struct ieee80211_hw *)pci_get_drvdata(pdev);
1776 acx_device_t *adev = ieee2adev(hw);
1777 unsigned long mem_region1, mem_region2;
1778 unsigned long flags;
1779 FN_ENTER;
1781 if (!hw) {
1782 acx_log(LOG_DEBUG, L_REALLYVERBOSE,
1783 "%s: card is unused. Skipping any release code\n",
1784 __func__);
1785 goto end;
1788 /* If device wasn't hot unplugged... */
1789 if (adev_present(adev)) {
1791 /* disable both Tx and Rx to shut radio down properly */
1792 if (adev->initialized) {
1793 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_TX, NULL, 0);
1794 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_RX, NULL, 0);
1795 adev->initialized = 0;
1797 #ifdef REDUNDANT
1798 /* put the eCPU to sleep to save power
1799 * Halting is not possible currently,
1800 * since not supported by all firmware versions */
1801 acx_s_issue_cmd(adev, ACX100_CMD_SLEEP, NULL, 0);
1802 #endif
1803 acx_lock(adev, flags);
1804 /* disable power LED to save power :-) */
1805 acx_log(LOG_INFO, L_INIT,
1806 "switching off power LED to save power\n");
1807 acxpci_l_power_led(adev, 0);
1808 /* stop our eCPU */
1809 if (IS_ACX111(adev)) {
1810 /* FIXME: does this actually keep halting the eCPU?
1811 * I don't think so...
1813 acxpci_l_reset_mac(adev);
1814 } else {
1815 u16 temp;
1816 /* halt eCPU */
1817 temp = read_reg16(adev, ACX_IO_ECPU_CTRL) | 0x1;
1818 write_reg16(adev, ACX_IO_ECPU_CTRL, temp);
1819 write_flush(adev);
1821 acx_unlock(adev, flags);
1825 /* unregister the device to not let the kernel
1826 * (e.g. ioctls) access a half-deconfigured device
1827 * NB: this will cause acxpci_e_close() to be called,
1828 * thus we shouldn't call it under sem!
1830 acx_log(LOG_INFO, L_INIT,
1831 "removing device %s\n", wiphy_name(adev->ieee->wiphy));
1832 ieee80211_unregister_hw(adev->ieee);
1834 /* unregister_netdev ensures that no references to us left.
1835 * For paranoid reasons we continue to follow the rules */
1836 acx_sem_lock(adev);
1838 if (adev->dev_state_mask & ACX_STATE_IFACE_UP) {
1839 acxpci_s_down(hw);
1840 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
1843 acx_proc_unregister_entries(adev->ieee);
1845 if (IS_ACX100(adev)) {
1846 mem_region1 = PCI_ACX100_REGION1;
1847 mem_region2 = PCI_ACX100_REGION2;
1848 } else {
1849 mem_region1 = PCI_ACX111_REGION1;
1850 mem_region2 = PCI_ACX111_REGION2;
1853 /* finally, clean up PCI bus state */
1854 acxpci_s_delete_dma_regions(adev);
1855 if (adev->iobase)
1856 iounmap(adev->iobase);
1857 if (adev->iobase2)
1858 iounmap(adev->iobase2);
1859 release_mem_region(pci_resource_start(pdev, mem_region1),
1860 pci_resource_len(pdev, mem_region1));
1861 release_mem_region(pci_resource_start(pdev, mem_region2),
1862 pci_resource_len(pdev, mem_region2));
1863 pci_disable_device(pdev);
1865 /* remove dev registration */
1866 pci_set_drvdata(pdev, NULL);
1868 acx_sem_unlock(adev);
1870 /* Free netdev (quite late,
1871 * since otherwise we might get caught off-guard
1872 * by a netdev timeout handler execution
1873 * expecting to see a working dev...) */
1874 ieee80211_free_hw(adev->ieee);
1876 /* put device into ACPI D3 mode (shutdown) */
1877 #ifdef CONFIG_PM
1878 pci_set_power_state(pdev, PCI_D3hot);
1879 #endif
1880 end:
1881 FN_EXIT0;
1885 /***********************************************************************
1886 ** TODO: PM code needs to be fixed / debugged / tested.
1888 #ifdef CONFIG_PM
1889 static int
1890 acxpci_e_suspend(struct pci_dev *pdev, pm_message_t state)
1892 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1893 acx_device_t *adev;
1895 FN_ENTER;
1896 acx_log(LOG_WARNING, L_ANY, "suspend handler is experimental!\n");
1897 acx_log(LOG_INFO, L_ANY, "suspend: dev %p\n", hw);
1899 /* if (!netif_running(ndev))
1900 goto end;
1902 adev = ieee2adev(hw);
1903 acx_log(LOG_INFO, L_ANY, "suspend: adev %p\n", adev);
1905 acx_sem_lock(adev);
1907 ieee80211_unregister_hw(hw); /* this one cannot sleep */
1908 acxpci_s_down(hw);
1909 /* down() does not set it to ACX_IRQ_ALL, but here we really want that */
1910 write_reg16(adev, ACX_IO_IRQ_MASK, ACX_IRQ_ALL);
1911 write_reg16(adev, ACX_IO_FEMR, 0x0);
1912 acxpci_s_delete_dma_regions(adev);
1913 pci_save_state(pdev);
1914 pci_set_power_state(pdev, PCI_D3hot);
1916 acx_sem_unlock(adev);
1917 FN_EXIT0;
1918 return OK;
1922 static int acxpci_e_resume(struct pci_dev *pdev)
1924 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1925 acx_device_t *adev;
1927 FN_ENTER;
1929 acx_log(LOG_WARNING, L_ANY, "resume handler is experimental!\n");
1930 acx_log(LOG_INFO, L_ANY, "resume: got dev %p\n", hw);
1933 adev = ieee2adev(hw);
1934 acx_log(LOG_INFO, L_ANY, "resume: got adev %p\n", adev);
1936 acx_sem_lock(adev);
1938 pci_set_power_state(pdev, PCI_D0);
1939 acx_log(LOG_INFO, L_ANY, "resume: power state PCI_D0 set\n");
1940 pci_restore_state(pdev);
1941 acx_log(LOG_INFO, L_ANY, "resume: PCI state restored\n");
1943 if (OK != acxpci_s_reset_dev(adev))
1944 goto end_unlock;
1945 acx_log(LOG_INFO, L_ANY, "resume: device reset done\n");
1946 if (OK != acx_s_init_mac(adev))
1947 goto end_unlock;
1948 acx_log(LOG_INFO, L_ANY, "resume: init MAC done\n");
1950 acxpci_s_up(hw);
1951 acx_log(LOG_INFO, L_ANY, "resume: acx up done\n");
1953 /* now even reload all card parameters as they were before suspend,
1954 * and possibly be back in the network again already :-) */
1955 if (ACX_STATE_IFACE_UP & adev->dev_state_mask) {
1956 adev->set_mask = GETSET_ALL;
1957 acx_s_update_card_settings(adev);
1958 acx_log(LOG_INFO, L_ANY, "resume: settings updated\n");
1960 ieee80211_register_hw(hw);
1961 acx_log(LOG_INFO, L_ANY, "resume: device attached\n");
1963 end_unlock:
1964 acx_sem_unlock(adev);
1965 /* we need to return OK here anyway, right? */
1966 FN_EXIT0;
1967 return OK;
1969 #endif /* CONFIG_PM */
1970 #endif /* CONFIG_PCI */
1972 /***********************************************************************
1973 ** acxpci_s_up
1975 ** This function is called by acxpci_e_open (when ifconfig sets the device as up)
1977 ** Side effects:
1978 ** - Enables on-card interrupt requests
1979 ** - calls acx_s_start
1982 static void enable_acx_irq(acx_device_t * adev)
1984 FN_ENTER;
1985 write_reg16(adev, ACX_IO_IRQ_MASK, adev->irq_mask);
1986 write_reg16(adev, ACX_IO_FEMR, 0x8000);
1987 adev->irqs_active = 1;
1988 FN_EXIT0;
1991 static void acxpci_s_up(struct ieee80211_hw *hw)
1993 acx_device_t *adev = ieee2adev(hw);
1994 unsigned long flags;
1996 FN_ENTER;
1998 acx_lock(adev, flags);
1999 enable_acx_irq(adev);
2000 acx_unlock(adev, flags);
2002 /* acx fw < 1.9.3.e has a hardware timer, and older drivers
2003 ** used to use it. But we don't do that anymore, our OS
2004 ** has reliable software timers */
2005 init_timer(&adev->mgmt_timer);
2006 adev->mgmt_timer.function = acx_i_timer;
2007 adev->mgmt_timer.data = (unsigned long)adev;
2009 /* Need to set ACX_STATE_IFACE_UP first, or else
2010 ** timer won't be started by acx_set_status() */
2011 SET_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
2013 acx_s_start(adev);
2015 FN_EXIT0;
2019 /***********************************************************************
2020 ** acxpci_s_down
2022 ** NB: device may be already hot unplugged if called from acxpci_e_remove()
2024 ** Disables on-card interrupt request, stops softirq and timer, stops queue,
2025 ** sets status == STOPPED
2028 static void disable_acx_irq(acx_device_t * adev)
2030 u16 disable_irq_mask = (IS_ACX111(adev)) ?
2031 ACX111_DISABLE_ALL_IRQS :
2032 ACX100_DISABLE_ALL_IRQS;
2034 FN_ENTER;
2036 /* I guess mask is not ACX_IRQ_ALL because acx100 won't signal
2037 ** cmd completion then (needed for ifup).
2038 ** I can't ifconfig up after ifconfig down'ing on my acx100 */
2039 write_reg16(adev, ACX_IO_IRQ_MASK, disable_irq_mask);
2040 write_reg16(adev, ACX_IO_FEMR, 0x0);
2041 adev->irqs_active = 0;
2043 FN_EXIT0;
2046 static void acxpci_s_down(struct ieee80211_hw *hw)
2048 acx_device_t *adev = ieee2adev(hw);
2050 FN_ENTER;
2052 /* Disable IRQs first, so that IRQs cannot race with us */
2053 /* then wait until interrupts have finished executing on other CPUs */
2054 disable_acx_irq(adev); /* NO sem-locking here? */
2055 synchronize_irq(adev->irq);
2057 /* we really don't want to have an asynchronous tasklet disturb us
2058 ** after something vital for its job has been shut down, so
2059 ** end all remaining work now.
2061 ** NB: carrier_off (done by set_status below) would lead to
2062 ** not yet fully understood deadlock in flush_scheduled_work().
2063 ** That's why we do FLUSH first.
2065 ** NB2: we have a bad locking bug here: flush_scheduled_work()
2066 ** waits for acx_e_after_interrupt_task to complete if it is running
2067 ** on another CPU, but acx_e_after_interrupt_task
2068 ** will sleep on sem forever, because it is taken by us!
2069 ** Work around that by temporary sem unlock.
2070 ** This will fail miserably if we'll be hit by concurrent
2071 ** iwconfig or something in between. TODO! */
2072 acx_sem_unlock(adev);
2073 flush_scheduled_work();
2074 acx_sem_lock(adev);
2076 /* This is possible:
2077 ** flush_scheduled_work -> acx_e_after_interrupt_task ->
2078 ** -> set_status(ASSOCIATED) -> wake_queue()
2079 ** That's why we stop queue _after_ flush_scheduled_work
2080 ** lock/unlock is just paranoia, maybe not needed */
2082 /* kernel/timer.c says it's illegal to del_timer_sync()
2083 ** a timer which restarts itself. We guarantee this cannot
2084 ** ever happen because acx_i_timer() never does this if
2085 ** status is ACX_STATUS_0_STOPPED */
2086 del_timer_sync(&adev->mgmt_timer);
2088 FN_EXIT0;
2091 #ifdef CONFIG_NET_POLL_CONTROLLER
2092 void acxpci_net_poll_controller(struct net_device *net_dev)
2094 acx_device_t *adev = ndev2adev(net_dev);
2095 unsigned long flags;
2097 local_irq_save(flags);
2098 acxpci_i_interrupt(adev->irq, adev);
2099 local_irq_restore(flags);
2101 #endif*/ /* CONFIG_NET_POLL_CONTROLLER */
2103 /***********************************************************************
2104 ** acxpci_e_open
2106 ** Called as a result of SIOCSIFFLAGS ioctl changing the flags bit IFF_UP
2107 ** from clear to set. In other words: ifconfig up.
2109 ** Returns:
2110 ** 0 success
2111 ** >0 f/w reported error
2112 ** <0 driver reported error
2114 static int acxpci_e_open(struct ieee80211_hw *hw)
2116 acx_device_t *adev = ieee2adev(hw);
2117 int result = OK;
2119 FN_ENTER;
2121 acx_sem_lock(adev);
2123 adev->initialized = 0;
2125 /* TODO: pci_set_power_state(pdev, PCI_D0); ? */
2127 /* ifup device */
2128 acxpci_s_up(hw);
2130 /* We don't currently have to do anything else.
2131 * The setup of the MAC should be subsequently completed via
2132 * the mlme commands.
2133 * Higher layers know we're ready from dev->start==1 and
2134 * dev->tbusy==0. Our rx path knows to pass up received/
2135 * frames because of dev->flags&IFF_UP is true.
2137 ieee80211_start_queues(adev->ieee);
2139 adev->initialized = 1;
2140 acx_sem_unlock(adev);
2142 FN_EXIT1(result);
2143 return result;
2147 /***********************************************************************
2148 ** acxpci_e_close
2150 ** This function stops the network functionality of the interface (invoked
2151 ** when the user calls ifconfig <wlan> down). The tx queue is halted and
2152 ** the device is marked as down.
2154 ** Called as a result of SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
2155 ** from set to clear. I.e. called by "ifconfig DEV down"
2157 ** Returns:
2158 ** 0 success
2159 ** >0 f/w reported error
2160 ** <0 driver reported error
2162 static void acxpci_e_close(struct ieee80211_hw *hw)
2164 acx_device_t *adev = ieee2adev(hw);
2166 FN_ENTER;
2168 acx_sem_lock(adev);
2170 /* ifdown device */
2171 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
2172 if (adev->initialized) {
2173 acxpci_s_down(hw);
2176 if (adev->modes)
2177 acx_free_modes(adev);
2178 /* disable all IRQs, release shared IRQ handler */
2179 write_reg16(adev, ACX_IO_IRQ_MASK, ACX_IRQ_ALL);
2180 write_reg16(adev, ACX_IO_FEMR, 0x0);
2181 free_irq(adev->irq, adev);
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 acx_log(LOG_INFO, 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 acx_log(LOG_WARNING, L_ANY, "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 acx_log(LOG_DEBUG, L_BUFR,
2260 "rx: tail=%u Ctl_16=%04X Status=%08X\n",
2261 tail, hostdesc->Ctl_16, hostdesc->Status);
2263 acx_l_process_rxbuf(adev, hostdesc->data);
2264 hostdesc->Status = 0;
2265 /* flush all writes before adapter sees CTL_HOSTOWN change */
2266 wmb();
2267 /* Host no longer owns this, needs to be LAST */
2268 CLEAR_BIT(hostdesc->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
2270 /* ok, descriptor is handled, now check the next descriptor */
2271 hostdesc = &adev->rxhostdesc_start[tail];
2273 /* if next descriptor is empty, then bail out */
2274 if (!(hostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2275 || !(hostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2276 break;
2278 tail = (tail + 1) % RX_CNT;
2280 end:
2281 adev->rx_tail = tail;
2282 FN_EXIT0;
2287 /***********************************************************************
2288 ** acxpci_i_interrupt
2290 ** IRQ handler (atomic context, must not sleep, blah, blah)
2293 /* scan is complete. all frames now on the receive queue are valid */
2294 #define INFO_SCAN_COMPLETE 0x0001
2295 #define INFO_WEP_KEY_NOT_FOUND 0x0002
2296 /* hw has been reset as the result of a watchdog timer timeout */
2297 #define INFO_WATCH_DOG_RESET 0x0003
2298 /* failed to send out NULL frame from PS mode notification to AP */
2299 /* recommended action: try entering 802.11 PS mode again */
2300 #define INFO_PS_FAIL 0x0004
2301 /* encryption/decryption process on a packet failed */
2302 #define INFO_IV_ICV_FAILURE 0x0005
2304 /* Info mailbox format:
2305 2 bytes: type
2306 2 bytes: status
2307 more bytes may follow
2308 rumors say about status:
2309 0x0000 info available (set by hw)
2310 0x0001 information received (must be set by host)
2311 0x1000 info available, mailbox overflowed (messages lost) (set by hw)
2312 but in practice we've seen:
2313 0x9000 when we did not set status to 0x0001 on prev message
2314 0x1001 when we did set it
2315 0x0000 was never seen
2316 conclusion: this is really a bitfield:
2317 0x1000 is 'info available' bit
2318 'mailbox overflowed' bit is 0x8000, not 0x1000
2319 value of 0x0000 probably means that there are no messages at all
2320 P.S. I dunno how in hell hw is supposed to notice that messages are lost -
2321 it does NOT clear bit 0x0001, and this bit will probably stay forever set
2322 after we set it once. Let's hope this will be fixed in firmware someday
2325 static void handle_info_irq(acx_device_t * adev)
2327 #if ACX_DEBUG
2328 static const char *const info_type_msg[] = {
2329 "(unknown)",
2330 "scan complete",
2331 "WEP key not found",
2332 "internal watchdog reset was done",
2333 "failed to send powersave (NULL frame) notification to AP",
2334 "encrypt/decrypt on a packet has failed",
2335 "TKIP tx keys disabled",
2336 "TKIP rx keys disabled",
2337 "TKIP rx: key ID not found",
2338 "???",
2339 "???",
2340 "???",
2341 "???",
2342 "???",
2343 "???",
2344 "???",
2345 "TKIP IV value exceeds thresh"
2347 #endif
2348 u32 info_type, info_status;
2350 info_type = acx_readl(adev->info_area);
2351 info_status = (info_type >> 16);
2352 info_type = (u16) info_type;
2354 /* inform fw that we have read this info message */
2355 acx_writel(info_type | 0x00010000, adev->info_area);
2356 write_reg16(adev, ACX_IO_INT_TRIG, INT_TRIG_INFOACK);
2357 write_flush(adev);
2359 acx_log(LOG_DEBUG, L_CTL,
2360 "info_type:%04X info_status:%04X\n", info_type, info_status);
2362 acx_log(LOG_DEBUG, L_IRQ, "got Info IRQ: status %04X type %04X: %s\n",
2363 info_status, info_type,
2364 info_type_msg[(info_type >= ARRAY_SIZE(info_type_msg)) ?
2365 0 : info_type]
2370 static void log_unusual_irq(u16 irqtype)
2373 if (!printk_ratelimit())
2374 return;
2377 printk("acx: got");
2378 if (irqtype & ACX_IRQ_RX_DATA) {
2379 printk(" Rx_Data");
2381 /* ACX_IRQ_TX_COMPLETE */
2382 if (irqtype & ACX_IRQ_TX_XFER) {
2383 printk(" Tx_Xfer");
2385 /* ACX_IRQ_RX_COMPLETE */
2386 if (irqtype & ACX_IRQ_DTIM) {
2387 printk(" DTIM");
2389 if (irqtype & ACX_IRQ_BEACON) {
2390 printk(" Beacon");
2392 if (irqtype & ACX_IRQ_TIMER) {
2393 printk(" Timer");
2395 if (irqtype & ACX_IRQ_KEY_NOT_FOUND) {
2396 printk(" Key_Not_Found");
2398 if (irqtype & ACX_IRQ_IV_ICV_FAILURE) {
2399 printk(" IV_ICV_Failure (crypto)");
2401 /* ACX_IRQ_CMD_COMPLETE */
2402 /* ACX_IRQ_INFO */
2403 if (irqtype & ACX_IRQ_OVERFLOW) {
2404 printk(" Overflow");
2406 if (irqtype & ACX_IRQ_PROCESS_ERROR) {
2407 printk(" Process_Error");
2409 /* ACX_IRQ_SCAN_COMPLETE */
2410 if (irqtype & ACX_IRQ_FCS_THRESHOLD) {
2411 printk(" FCS_Threshold");
2413 if (irqtype & ACX_IRQ_UNKNOWN) {
2414 printk(" Unknown");
2416 printk(" IRQ(s)\n");
2419 /* FIXME: update_link_quality_led was a stub - let's comment it and avoid
2420 * compiler warnings */
2422 static void update_link_quality_led(acx_device_t * adev)
2424 int qual;
2426 qual =
2427 acx_signal_determine_quality(adev->wstats.qual.level,
2428 adev->wstats.qual.noise);
2429 if (qual > adev->brange_max_quality)
2430 qual = adev->brange_max_quality;
2432 if (time_after(jiffies, adev->brange_time_last_state_change +
2433 (HZ / 2 -
2434 HZ / 2 * (unsigned long)qual /
2435 adev->brange_max_quality))) {
2436 acxpci_l_power_led(adev, (adev->brange_last_state == 0));
2437 adev->brange_last_state ^= 1; // toggle
2438 adev->brange_time_last_state_change = jiffies;
2443 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* a la orinoco.c */
2445 /* Interrupt handler bottom-half */
2446 void acx_interrupt_tasklet(struct work_struct *work)
2449 #ifdef CONFIG_ACX_MAC80211_DEBUG
2450 u32 _handled = 0x00000000;
2451 # define acxirq_handled(irq) do { _handled |= (irq); } while (0)
2452 #else
2453 # define acxirq_handled(irq) do { /* nothing */ } while (0)
2454 #endif /* CONFIG_ACX_MAC80211_DEBUG */
2455 acx_device_t *adev = container_of(work,struct acx_device, after_interrupt_task);
2456 // unsigned int irqcount = MAX_IRQLOOPS_PER_JIFFY;
2457 int irqtype;
2459 #define IRQ_ITERATE 0
2460 #if IRQ_ITERATE
2461 unsigned int irqcount = MAX_IRQLOOPS_PER_JIFFY;
2462 u16 unmasked;
2463 #endif
2465 FN_ENTER;
2467 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2468 * I am paranoid */
2469 acx_sem_lock(adev);
2471 irqtype = adev->irq_reason;
2472 adev->irq_reason = 0;
2474 #if IRQ_ITERATE
2475 if (jiffies != adev->irq_last_jiffies) {
2476 adev->irq_loops_this_jiffy = 0;
2477 adev->irq_last_jiffies = jiffies;
2480 /* safety condition; we'll normally abort loop below
2481 * in case no IRQ type occurred */
2482 while (likely(--irqcount)) {
2483 #endif
2484 /* ACK all IRQs ASAP */
2486 /* Handle most important IRQ types first */
2487 if (irqtype & ACX_IRQ_RX_COMPLETE) {
2488 acx_log(LOG_DEBUG, L_IRQ, "got Rx_Complete IRQ\n");
2489 acxpci_l_process_rxdesc(adev);
2491 if (irqtype & ACX_IRQ_TX_COMPLETE) {
2492 acx_log(LOG_DEBUG, L_IRQ, "got Tx_Complete IRQ\n");
2493 /* don't clean up on each Tx complete, wait a bit
2494 * unless we're going towards full, in which case
2495 * we do it immediately, too (otherwise we might lockup
2496 * with a full Tx buffer if we go into
2497 * acxpci_l_clean_txdesc() at a time when we won't wakeup
2498 * the net queue in there for some reason...) */
2499 // if (adev->tx_free <= TX_START_CLEAN) {
2500 acxpci_l_clean_txdesc(adev);
2501 // }
2504 /* Less frequent ones */
2505 if (irqtype & (0
2506 | ACX_IRQ_CMD_COMPLETE
2507 | ACX_IRQ_INFO | ACX_IRQ_SCAN_COMPLETE)) {
2508 if (irqtype & ACX_IRQ_INFO) {
2509 handle_info_irq(adev);
2511 if (irqtype & ACX_IRQ_SCAN_COMPLETE) {
2512 acx_log(LOG_DEBUG, L_IRQ,
2513 "got Scan_Complete IRQ\n");
2514 /* need to do that in process context */
2515 /* remember that fw is not scanning anymore */
2516 SET_BIT(adev->irq_status,
2517 ACX_IRQ_SCAN_COMPLETE);
2521 /* These we just log, but either they happen rarely
2522 * or we keep them masked out */
2523 if (irqtype & (0 | ACX_IRQ_RX_DATA
2524 /* | ACX_IRQ_TX_COMPLETE */
2525 | ACX_IRQ_TX_XFER
2526 /* | ACX_IRQ_RX_COMPLETE */
2527 | ACX_IRQ_DTIM
2528 | ACX_IRQ_BEACON
2529 | ACX_IRQ_TIMER
2530 | ACX_IRQ_KEY_NOT_FOUND
2531 | ACX_IRQ_IV_ICV_FAILURE
2532 /* | ACX_IRQ_CMD_COMPLETE */
2533 /* | ACX_IRQ_INFO */
2534 | ACX_IRQ_OVERFLOW
2535 | ACX_IRQ_PROCESS_ERROR
2536 /* | ACX_IRQ_SCAN_COMPLETE */
2537 | ACX_IRQ_FCS_THRESHOLD
2538 | ACX_IRQ_UNKNOWN)) {
2539 log_unusual_irq(irqtype);
2541 #if IRQ_ITERATE
2542 unmasked = read_reg16(adev, ACX_IO_IRQ_REASON);
2543 irqtype = unmasked & ~adev->irq_mask;
2544 /* Bail out if no new IRQ bits or if all are masked out */
2545 if (!irqtype)
2546 break;
2548 if (unlikely
2549 (++adev->irq_loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY)) {
2550 acx_log(LOG_WARNING, L_ANY,
2551 "too many interrupts per jiffy!\n");
2552 /* Looks like card floods us with IRQs! Try to stop that */
2553 write_reg16(adev, ACX_IO_IRQ_MASK, ACX_IRQ_ALL);
2554 /* This will short-circuit all future attempts to handle IRQ.
2555 * We cant do much more... */
2556 adev->irq_mask = 0;
2557 break;
2560 #endif
2561 /* Routine to perform blink with range
2562 * FIXME: update_link_quality_led is a stub - add proper code and enable this again:
2563 if (unlikely(adev->led_power == 2))
2564 update_link_quality_led(adev);
2567 /* write_flush(adev); - not needed, last op was read anyway */
2568 acx_sem_unlock(adev);
2570 /* handled: */
2571 if (adev->after_interrupt_jobs)
2572 acx_e_after_interrupt_task(&adev->after_interrupt_task);
2574 FN_EXIT0;
2575 return;
2580 static irqreturn_t acxpci_i_interrupt(int irq, void *dev_id)
2582 acx_device_t *adev = dev_id;
2583 unsigned long flags;
2584 register u16 irqtype;
2585 u16 unmasked;
2587 FN_ENTER;
2589 if (!adev)
2590 return IRQ_NONE;
2592 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2593 * I am paranoid */
2595 acx_lock(adev, flags);
2597 unmasked = read_reg16(adev, ACX_IO_IRQ_REASON);
2598 if (unlikely(unmasked == ACX_IRQ_ALL)) {
2599 /* ACX_IRQ_ALL value hints at missing hardware,
2600 * so don't do anything.
2601 * Not very clean, but other drivers do the same... */
2602 acx_log(LOG_WARNING, L_IRQ,
2603 "IRQ type:FFFF (ALL) - device removed? IRQ_NONE\n");
2604 goto none;
2607 /* We will check only "interesting" IRQ types */
2608 irqtype = unmasked & ~adev->irq_mask;
2609 if (!irqtype) {
2610 /* We are on a shared IRQ line and it wasn't our IRQ */
2611 acx_log(LOG_DEBUG, L_IRQ,
2612 "IRQ type:%04X, mask:%04X - all are masked, IRQ_NONE\n",
2613 unmasked, adev->irq_mask);
2614 goto none;
2617 /* Go ahead and ACK our interrupt */
2618 write_reg16(adev, ACX_IO_IRQ_ACK, ACX_IRQ_ALL);
2619 if (irqtype & ACX_IRQ_CMD_COMPLETE) {
2620 acx_log(LOG_DEBUG, L_IRQ, "got Command_Complete IRQ\n");
2621 /* save the state for the running issue_cmd() */
2622 SET_BIT(adev->irq_status, ACX_IRQ_CMD_COMPLETE);
2625 /* Only accept IRQs, if we are initialized properly.
2626 * This avoids an RX race while initializing.
2627 * We should probably not enable IRQs before we are initialized
2628 * completely, but some careful work is needed to fix this. I think it
2629 * is best to stay with this cheap workaround for now... .
2631 if (likely(adev->initialized)) {
2632 /* disable all IRQs. They are enabled again in the bottom half. */
2633 /* save the reason code and call our bottom half. */
2634 adev->irq_reason = irqtype;
2636 if ((irqtype & ACX_IRQ_RX_COMPLETE) || (irqtype & ACX_IRQ_TX_COMPLETE))
2637 acx_schedule_task(adev, 0);
2640 acx_unlock(adev, flags);
2641 FN_EXIT0;
2642 return IRQ_HANDLED;
2643 none:
2644 acx_unlock(adev, flags);
2645 FN_EXIT0;
2646 return IRQ_NONE;
2651 /***********************************************************************
2652 ** acxpci_l_power_led
2654 void acxpci_l_power_led(acx_device_t * adev, int enable)
2656 u16 gpio_pled = IS_ACX111(adev) ? 0x0040 : 0x0800;
2658 /* A hack. Not moving message rate limiting to adev->xxx
2659 * (it's only a debug message after all) */
2660 static int rate_limit = 0;
2662 if (rate_limit++ < 3)
2663 acx_log(LOG_INFO, L_IOCTL,
2664 "Please report in case toggling the power LED "
2665 "doesn't work for your card!\n");
2666 if (enable)
2667 write_reg16(adev, ACX_IO_GPIO_OUT,
2668 read_reg16(adev, ACX_IO_GPIO_OUT) & ~gpio_pled);
2669 else
2670 write_reg16(adev, ACX_IO_GPIO_OUT,
2671 read_reg16(adev, ACX_IO_GPIO_OUT) | gpio_pled);
2675 /***********************************************************************
2676 ** Ioctls
2679 /***********************************************************************
2681 #if 0
2683 acx111pci_ioctl_info(struct net_device *ndev,
2684 struct iw_request_info *info,
2685 struct iw_param *vwrq, char *extra)
2687 #if ACX_DEBUG > 1
2688 acx_device_t *adev = ndev2adev(ndev);
2689 rxdesc_t *rxdesc;
2690 txdesc_t *txdesc;
2691 rxhostdesc_t *rxhostdesc;
2692 txhostdesc_t *txhostdesc;
2693 struct acx111_ie_memoryconfig memconf;
2694 struct acx111_ie_queueconfig queueconf;
2695 unsigned long flags;
2696 int i;
2697 char memmap[0x34];
2698 char rxconfig[0x8];
2699 char fcserror[0x8];
2700 char ratefallback[0x5];
2702 if (!(acx_debug & (L_IOCTL | L_DEBUG)))
2703 return OK;
2704 /* using printk() since we checked debug flag already */
2706 acx_sem_lock(adev);
2708 if (!IS_ACX111(adev)) {
2709 printk("acx111-specific function called "
2710 "with non-acx111 chip, aborting\n");
2711 goto end_ok;
2714 /* get Acx111 Memory Configuration */
2715 memset(&memconf, 0, sizeof(memconf));
2716 /* BTW, fails with 12 (Write only) error code.
2717 ** Retained for easy testing of issue_cmd error handling :) */
2718 acx_s_interrogate(adev, &memconf, ACX1xx_REG_QUEUE_CONFIG);
2720 /* get Acx111 Queue Configuration */
2721 memset(&queueconf, 0, sizeof(queueconf));
2722 acx_s_interrogate(adev, &queueconf, ACX1xx_REG_MEMORY_CONFIG_OPTIONS);
2724 /* get Acx111 Memory Map */
2725 memset(memmap, 0, sizeof(memmap));
2726 acx_s_interrogate(adev, &memmap, ACX1xx_REG_MEMORY_MAP);
2728 /* get Acx111 Rx Config */
2729 memset(rxconfig, 0, sizeof(rxconfig));
2730 acx_s_interrogate(adev, &rxconfig, ACX1xx_REG_RXCONFIG);
2732 /* get Acx111 fcs error count */
2733 memset(fcserror, 0, sizeof(fcserror));
2734 acx_s_interrogate(adev, &fcserror, ACX1xx_REG_FCS_ERROR_COUNT);
2736 /* get Acx111 rate fallback */
2737 memset(ratefallback, 0, sizeof(ratefallback));
2738 acx_s_interrogate(adev, &ratefallback, ACX1xx_REG_RATE_FALLBACK);
2740 /* force occurrence of a beacon interrupt */
2741 /* TODO: comment why is this necessary */
2742 write_reg16(adev, ACX_IO_HINT_TRIG, ACX_IRQ_BEACON);
2744 /* dump Acx111 Mem Configuration */
2745 printk("dump mem config:\n"
2746 "data read: %d, struct size: %d\n"
2747 "Number of stations: %1X\n"
2748 "Memory block size: %1X\n"
2749 "tx/rx memory block allocation: %1X\n"
2750 "count rx: %X / tx: %X queues\n"
2751 "options %1X\n"
2752 "fragmentation %1X\n"
2753 "Rx Queue 1 Count Descriptors: %X\n"
2754 "Rx Queue 1 Host Memory Start: %X\n"
2755 "Tx Queue 1 Count Descriptors: %X\n"
2756 "Tx Queue 1 Attributes: %X\n",
2757 memconf.len, (int)sizeof(memconf),
2758 memconf.no_of_stations,
2759 memconf.memory_block_size,
2760 memconf.tx_rx_memory_block_allocation,
2761 memconf.count_rx_queues, memconf.count_tx_queues,
2762 memconf.options,
2763 memconf.fragmentation,
2764 memconf.rx_queue1_count_descs,
2765 acx2cpu(memconf.rx_queue1_host_rx_start),
2766 memconf.tx_queue1_count_descs, memconf.tx_queue1_attributes);
2768 /* dump Acx111 Queue Configuration */
2769 printk("dump queue head:\n"
2770 "data read: %d, struct size: %d\n"
2771 "tx_memory_block_address (from card): %X\n"
2772 "rx_memory_block_address (from card): %X\n"
2773 "rx1_queue address (from card): %X\n"
2774 "tx1_queue address (from card): %X\n"
2775 "tx1_queue attributes (from card): %X\n",
2776 queueconf.len, (int)sizeof(queueconf),
2777 queueconf.tx_memory_block_address,
2778 queueconf.rx_memory_block_address,
2779 queueconf.rx1_queue_address,
2780 queueconf.tx1_queue_address, queueconf.tx1_attributes);
2782 /* dump Acx111 Mem Map */
2783 printk("dump mem map:\n"
2784 "data read: %d, struct size: %d\n"
2785 "Code start: %X\n"
2786 "Code end: %X\n"
2787 "WEP default key start: %X\n"
2788 "WEP default key end: %X\n"
2789 "STA table start: %X\n"
2790 "STA table end: %X\n"
2791 "Packet template start: %X\n"
2792 "Packet template end: %X\n"
2793 "Queue memory start: %X\n"
2794 "Queue memory end: %X\n"
2795 "Packet memory pool start: %X\n"
2796 "Packet memory pool end: %X\n"
2797 "iobase: %p\n"
2798 "iobase2: %p\n",
2799 *((u16 *) & memmap[0x02]), (int)sizeof(memmap),
2800 *((u32 *) & memmap[0x04]),
2801 *((u32 *) & memmap[0x08]),
2802 *((u32 *) & memmap[0x0C]),
2803 *((u32 *) & memmap[0x10]),
2804 *((u32 *) & memmap[0x14]),
2805 *((u32 *) & memmap[0x18]),
2806 *((u32 *) & memmap[0x1C]),
2807 *((u32 *) & memmap[0x20]),
2808 *((u32 *) & memmap[0x24]),
2809 *((u32 *) & memmap[0x28]),
2810 *((u32 *) & memmap[0x2C]),
2811 *((u32 *) & memmap[0x30]), adev->iobase, adev->iobase2);
2813 /* dump Acx111 Rx Config */
2814 printk("dump rx config:\n"
2815 "data read: %d, struct size: %d\n"
2816 "rx config: %X\n"
2817 "rx filter config: %X\n",
2818 *((u16 *) & rxconfig[0x02]), (int)sizeof(rxconfig),
2819 *((u16 *) & rxconfig[0x04]), *((u16 *) & rxconfig[0x06]));
2821 /* dump Acx111 fcs error */
2822 printk("dump fcserror:\n"
2823 "data read: %d, struct size: %d\n"
2824 "fcserrors: %X\n",
2825 *((u16 *) & fcserror[0x02]), (int)sizeof(fcserror),
2826 *((u32 *) & fcserror[0x04]));
2828 /* dump Acx111 rate fallback */
2829 printk("dump rate fallback:\n"
2830 "data read: %d, struct size: %d\n"
2831 "ratefallback: %X\n",
2832 *((u16 *) & ratefallback[0x02]), (int)sizeof(ratefallback),
2833 *((u8 *) & ratefallback[0x04]));
2835 /* protect against IRQ */
2836 acx_lock(adev, flags);
2838 /* dump acx111 internal rx descriptor ring buffer */
2839 rxdesc = adev->rxdesc_start;
2841 /* loop over complete receive pool */
2842 if (rxdesc)
2843 for (i = 0; i < RX_CNT; i++) {
2844 printk("\ndump internal rxdesc %d:\n"
2845 "mem pos %p\n"
2846 "next 0x%X\n"
2847 "acx mem pointer (dynamic) 0x%X\n"
2848 "CTL (dynamic) 0x%X\n"
2849 "Rate (dynamic) 0x%X\n"
2850 "RxStatus (dynamic) 0x%X\n"
2851 "Mod/Pre (dynamic) 0x%X\n",
2853 rxdesc,
2854 acx2cpu(rxdesc->pNextDesc),
2855 acx2cpu(rxdesc->ACXMemPtr),
2856 rxdesc->Ctl_8,
2857 rxdesc->rate, rxdesc->error, rxdesc->SNR);
2858 rxdesc++;
2861 /* dump host rx descriptor ring buffer */
2863 rxhostdesc = adev->rxhostdesc_start;
2865 /* loop over complete receive pool */
2866 if (rxhostdesc)
2867 for (i = 0; i < RX_CNT; i++) {
2868 printk("\ndump host rxdesc %d:\n"
2869 "mem pos %p\n"
2870 "buffer mem pos 0x%X\n"
2871 "buffer mem offset 0x%X\n"
2872 "CTL 0x%X\n"
2873 "Length 0x%X\n"
2874 "next 0x%X\n"
2875 "Status 0x%X\n",
2877 rxhostdesc,
2878 acx2cpu(rxhostdesc->data_phy),
2879 rxhostdesc->data_offset,
2880 le16_to_cpu(rxhostdesc->Ctl_16),
2881 le16_to_cpu(rxhostdesc->length),
2882 acx2cpu(rxhostdesc->desc_phy_next),
2883 rxhostdesc->Status);
2884 rxhostdesc++;
2887 /* dump acx111 internal tx descriptor ring buffer */
2888 txdesc = adev->txdesc_start;
2890 /* loop over complete transmit pool */
2891 if (txdesc)
2892 for (i = 0; i < TX_CNT; i++) {
2893 printk("\ndump internal txdesc %d:\n"
2894 "size 0x%X\n"
2895 "mem pos %p\n"
2896 "next 0x%X\n"
2897 "acx mem pointer (dynamic) 0x%X\n"
2898 "host mem pointer (dynamic) 0x%X\n"
2899 "length (dynamic) 0x%X\n"
2900 "CTL (dynamic) 0x%X\n"
2901 "CTL2 (dynamic) 0x%X\n"
2902 "Status (dynamic) 0x%X\n"
2903 "Rate (dynamic) 0x%X\n",
2905 (int)sizeof(struct txdesc),
2906 txdesc,
2907 acx2cpu(txdesc->pNextDesc),
2908 acx2cpu(txdesc->AcxMemPtr),
2909 acx2cpu(txdesc->HostMemPtr),
2910 le16_to_cpu(txdesc->total_length),
2911 txdesc->Ctl_8,
2912 txdesc->Ctl2_8, txdesc->error,
2913 txdesc->u.r1.rate);
2914 txdesc = advance_txdesc(adev, txdesc, 1);
2917 /* dump host tx descriptor ring buffer */
2919 txhostdesc = adev->txhostdesc_start;
2921 /* loop over complete host send pool */
2922 if (txhostdesc)
2923 for (i = 0; i < TX_CNT * 2; i++) {
2924 printk("\ndump host txdesc %d:\n"
2925 "mem pos %p\n"
2926 "buffer mem pos 0x%X\n"
2927 "buffer mem offset 0x%X\n"
2928 "CTL 0x%X\n"
2929 "Length 0x%X\n"
2930 "next 0x%X\n"
2931 "Status 0x%X\n",
2933 txhostdesc,
2934 acx2cpu(txhostdesc->data_phy),
2935 txhostdesc->data_offset,
2936 le16_to_cpu(txhostdesc->Ctl_16),
2937 le16_to_cpu(txhostdesc->length),
2938 acx2cpu(txhostdesc->desc_phy_next),
2939 le32_to_cpu(txhostdesc->Status));
2940 txhostdesc++;
2943 /* write_reg16(adev, 0xb4, 0x4); */
2945 acx_unlock(adev, flags);
2946 end_ok:
2948 acx_sem_unlock(adev);
2949 #endif /* ACX_DEBUG */
2950 return OK;
2954 /***********************************************************************
2957 acx100pci_ioctl_set_phy_amp_bias(struct net_device *ndev,
2958 struct iw_request_info *info,
2959 struct iw_param *vwrq, char *extra)
2961 acx_device_t *adev = ndev2adev(ndev);
2962 unsigned long flags;
2963 u16 gpio_old;
2965 if (!IS_ACX100(adev)) {
2966 /* WARNING!!!
2967 * Removing this check *might* damage
2968 * hardware, since we're tweaking GPIOs here after all!!!
2969 * You've been warned...
2970 * WARNING!!! */
2971 acx_log(LOG_INFO, L_ANY,
2972 "sorry, setting bias level for non-acx100 "
2973 "is not supported yet\n");
2974 return OK;
2977 if (*extra > 7) {
2978 acx_log(LOG_INFO, L_ANY,
2979 "invalid bias parameter, range is 0-7\n");
2980 return -EINVAL;
2983 acx_sem_lock(adev);
2985 /* Need to lock accesses to [ACX_IO_GPIO_OUT]:
2986 * IRQ handler uses it to update LED */
2987 acx_lock(adev, flags);
2988 gpio_old = read_reg16(adev, ACX_IO_GPIO_OUT);
2989 write_reg16(adev, ACX_IO_GPIO_OUT,
2990 (gpio_old & 0xf8ff) | ((u16) * extra << 8));
2991 acx_unlock(adev, flags);
2993 acx_log(LOG_DEBUG, L_REALLYVERBOSE, "gpio_old: 0x%04X\n", gpio_old);
2994 acx_log(LOG_INFO, L_ANY,
2995 "%s: PHY power amplifier bias: old:%d, new:%d\n",
2996 ndev->name, (gpio_old & 0x0700) >> 8, (unsigned char)*extra);
2998 acx_sem_unlock(adev);
3000 return OK;
3002 #endif
3004 /***************************************************************
3005 ** acxpci_l_alloc_tx
3006 ** Actually returns a txdesc_t* ptr
3008 ** FIXME: in case of fragments, should allocate multiple descrs
3009 ** after figuring out how many we need and whether we still have
3010 ** sufficiently many.
3012 tx_t *acxpci_l_alloc_tx(acx_device_t * adev)
3014 struct txdesc *txdesc;
3015 unsigned head;
3016 u8 ctl8;
3018 FN_ENTER;
3020 if (unlikely(!adev->tx_free)) {
3021 acx_log(LOG_WARNING, L_ANY, "BUG: no free txdesc left\n");
3022 txdesc = NULL;
3023 goto end;
3026 head = adev->tx_head;
3027 txdesc = get_txdesc(adev, head);
3028 ctl8 = txdesc->Ctl_8;
3030 /* 2005-10-11: there were several bug reports on this happening
3031 ** but now cause seems to be understood & fixed */
3032 if (unlikely(DESC_CTL_HOSTOWN != (ctl8 & DESC_CTL_ACXDONE_HOSTOWN))) {
3033 /* whoops, descr at current index is not free, so probably
3034 * ring buffer already full */
3035 acx_log(LOG_WARNING, L_ANY, "BUG: tx_head:%d Ctl8:0x%02X - "
3036 "failed to find free txdesc\n", head, ctl8);
3037 txdesc = NULL;
3038 goto end;
3041 /* Needed in case txdesc won't be eventually submitted for tx */
3042 txdesc->Ctl_8 = DESC_CTL_ACXDONE_HOSTOWN;
3044 adev->tx_free--;
3045 acx_log(LOG_DEBUG, L_BUFT, "tx: got desc %u, %u remain\n",
3046 head, adev->tx_free);
3047 /* Keep a few free descs between head and tail of tx ring.
3048 ** It is not absolutely needed, just feels safer */
3049 if (adev->tx_free < TX_STOP_QUEUE) {
3050 acx_log(LOG_DEBUG, L_BUF, "stop queue (%u tx desc left)\n",
3051 adev->tx_free);
3052 acx_stop_queue(adev->ieee, NULL);
3055 /* returning current descriptor, so advance to next free one */
3056 adev->tx_head = (head + 1) % TX_CNT;
3057 end:
3058 FN_EXIT0;
3060 return (tx_t *) txdesc;
3064 /***********************************************************************
3066 void *acxpci_l_get_txbuf(acx_device_t * adev, tx_t * tx_opaque)
3068 return get_txhostdesc(adev, (txdesc_t *) tx_opaque)->data;
3072 /***********************************************************************
3073 ** acxpci_l_tx_data
3075 ** Can be called from IRQ (rx -> (AP bridging or mgmt response) -> tx).
3076 ** Can be called from acx_i_start_xmit (data frames from net core).
3078 ** FIXME: in case of fragments, should loop over the number of
3079 ** pre-allocated tx descrs, properly setting up transfer data and
3080 ** CTL_xxx flags according to fragment number.
3082 void
3083 acxpci_l_tx_data(acx_device_t * adev, tx_t * tx_opaque, int len,
3084 struct ieee80211_tx_control *ieeectl,struct sk_buff* skb)
3086 txdesc_t *txdesc = (txdesc_t *) tx_opaque;
3087 struct ieee80211_hdr *wireless_header;
3088 txhostdesc_t *hostdesc1, *hostdesc2;
3089 int rate_cur;
3090 u8 Ctl_8, Ctl2_8;
3091 int wlhdr_len;
3093 FN_ENTER;
3095 /* fw doesn't tx such packets anyhow */
3096 /* if (unlikely(len < WLAN_HDR_A3_LEN))
3097 goto end;
3099 hostdesc1 = get_txhostdesc(adev, txdesc);
3100 wireless_header = (struct ieee80211_hdr *)hostdesc1->data;
3101 /* modify flag status in separate variable to be able to write it back
3102 * in one big swoop later (also in order to have less device memory
3103 * accesses) */
3104 Ctl_8 = txdesc->Ctl_8;
3105 Ctl2_8 = 0; /* really need to init it to 0, not txdesc->Ctl2_8, it seems */
3107 hostdesc2 = hostdesc1 + 1;
3109 /* DON'T simply set Ctl field to 0 here globally,
3110 * it needs to maintain a consistent flag status (those are state flags!!),
3111 * otherwise it may lead to severe disruption. Only set or reset particular
3112 * flags at the exact moment this is needed... */
3114 /* let chip do RTS/CTS handshaking before sending
3115 * in case packet size exceeds threshold */
3116 if (ieeectl->flags & IEEE80211_TXCTL_USE_RTS_CTS)
3117 SET_BIT(Ctl2_8, DESC_CTL2_RTS);
3118 else
3119 CLEAR_BIT(Ctl2_8, DESC_CTL2_RTS);
3121 rate_cur = ieeectl->tx_rate;
3122 if (unlikely(!rate_cur)) {
3123 acx_log(LOG_WARNING, L_ANY, "driver bug! bad ratemask\n");
3124 goto end;
3127 /* used in tx cleanup routine for auto rate and accounting: */
3128 /* put_txcr(adev, txdesc, clt, rate_cur); deprecated by mac80211 */
3130 txdesc->total_length = cpu_to_le16(len);
3131 wlhdr_len = ieee80211_get_hdrlen(le16_to_cpu(wireless_header->frame_control));
3132 hostdesc2->length = cpu_to_le16(len - wlhdr_len);
3134 if (!ieeectl->do_not_encrypt && ieeectl->key_idx>= 0)
3136 u16 key_idx = (u16)(ieeectl->key_idx);
3137 struct acx_key* key = &(adev->key[key_idx]);
3138 int wlhdr_len;
3139 if (key->enabled)
3141 memcpy(ieeehdr->wep_iv, ((u8*)wireless_header) + wlhdr_len, 4);
3145 if (IS_ACX111(adev)) {
3146 /* note that if !txdesc->do_auto, txrate->cur
3147 ** has only one nonzero bit */
3148 txdesc->u.r2.rate111 = cpu_to_le16(rate_cur
3149 /* WARNING: I was never able to make it work with prism54 AP.
3150 ** It was falling down to 1Mbit where shortpre is not applicable,
3151 ** and not working at all at "5,11 basic rates only" setting.
3152 ** I even didn't see tx packets in radio packet capture.
3153 ** Disabled for now --vda */
3154 /*| ((clt->shortpre && clt->cur!=RATE111_1) ? RATE111_SHORTPRE : 0) */
3156 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3157 /* should add this to rate111 above as necessary */
3158 |(clt->pbcc511 ? RATE111_PBCC511 : 0)
3159 #endif
3160 hostdesc1->length = cpu_to_le16(len);
3161 } else { /* ACX100 */
3162 u8 rate_100 = ieeectl->tx_rate;
3163 txdesc->u.r1.rate = rate_100;
3164 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3165 if (clt->pbcc511) {
3166 if (n == RATE100_5 || n == RATE100_11)
3167 n |= RATE100_PBCC511;
3170 if (clt->shortpre && (clt->cur != RATE111_1))
3171 SET_BIT(Ctl_8, DESC_CTL_SHORT_PREAMBLE); /* set Short Preamble */
3172 #endif
3173 /* set autodma and reclaim and 1st mpdu */
3174 SET_BIT(Ctl_8,
3175 DESC_CTL_AUTODMA | DESC_CTL_RECLAIM |
3176 DESC_CTL_FIRSTFRAG);
3177 #if ACX_FRAGMENTATION
3178 /* SET_BIT(Ctl2_8, DESC_CTL2_MORE_FRAG); cannot set it unconditionally, needs to be set for all non-last fragments */
3179 #endif
3180 hostdesc1->length = cpu_to_le16(wlhdr_len);
3182 /* don't need to clean ack/rts statistics here, already
3183 * done on descr cleanup */
3185 /* clears HOSTOWN and ACXDONE bits, thus telling that the descriptors
3186 * are now owned by the acx100; do this as LAST operation */
3187 CLEAR_BIT(Ctl_8, DESC_CTL_ACXDONE_HOSTOWN);
3188 /* flush writes before we release hostdesc to the adapter here */
3189 wmb();
3190 CLEAR_BIT(hostdesc1->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3191 CLEAR_BIT(hostdesc2->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3193 /* write back modified flags */
3194 CLEAR_BIT(Ctl2_8, DESC_CTL2_WEP);
3195 txdesc->Ctl2_8 = Ctl2_8;
3196 txdesc->Ctl_8 = Ctl_8;
3197 /* unused: txdesc->tx_time = cpu_to_le32(jiffies); */
3199 /* flush writes before we tell the adapter that it's its turn now */
3200 write_reg16(adev, ACX_IO_INT_TRIG, INT_TRIG_TXPRC);
3201 write_flush(adev);
3202 /* log the packet content AFTER sending it,
3203 * in order to not delay sending any further than absolutely needed
3204 * Do separate logs for acx100/111 to have human-readable rates */
3205 memcpy(&(hostdesc1->txstatus.control),ieeectl,sizeof(struct ieee80211_tx_control));
3206 hostdesc1->skb = skb;
3207 end:
3208 FN_EXIT0;
3212 /***********************************************************************
3213 ** acxpci_l_clean_txdesc
3215 ** This function resets the txdescs' status when the ACX100
3216 ** signals the TX done IRQ (txdescs have been processed), starting with
3217 ** the pool index of the descriptor which we would use next,
3218 ** in order to make sure that we can be as fast as possible
3219 ** in filling new txdescs.
3220 ** Everytime we get called we know where the next packet to be cleaned is.
3223 #if !ACX_DEBUG
3224 static inline void log_txbuffer(const acx_device_t * adev)
3227 #else
3228 static void log_txbuffer(acx_device_t * adev)
3230 txdesc_t *txdesc;
3231 int i;
3233 /* no FN_ENTER here, we don't want that */
3234 /* no locks here, since it's entirely non-critical code */
3235 txdesc = adev->txdesc_start;
3236 if (unlikely(!txdesc))
3237 return;
3238 acx_log(LOG_DEBUG, L_REALLYVERBOSE, "tx: desc->Ctl8's:");
3239 for (i = 0; i < TX_CNT; i++) {
3240 printk(" %02X", txdesc->Ctl_8);
3241 txdesc = advance_txdesc(adev, txdesc, 1);
3243 printk("\n");
3245 #endif
3248 static void handle_tx_error(acx_device_t * adev, u8 error, unsigned int finger,
3249 struct ieee80211_tx_status *status)
3251 const char *err = "unknown error";
3253 /* hmm, should we handle this as a mask
3254 * of *several* bits?
3255 * For now I think only caring about
3256 * individual bits is ok... */
3257 switch (error) {
3258 case 0x01:
3259 err = "no Tx due to error in other fragment";
3260 /* adev->wstats.discard.fragment++; */
3261 break;
3262 case 0x02:
3263 err = "Tx aborted";
3264 adev->stats.tx_aborted_errors++;
3265 break;
3266 case 0x04:
3267 err = "Tx desc wrong parameters";
3268 /* adev->wstats.discard.misc++; */
3269 break;
3270 case 0x08:
3271 err = "WEP key not found";
3272 /* adev->wstats.discard.misc++; */
3273 break;
3274 case 0x10:
3275 err = "MSDU lifetime timeout? - try changing "
3276 "'iwconfig retry lifetime XXX'";
3277 /* adev->wstats.discard.misc++; */
3278 break;
3279 case 0x20:
3280 err = "excessive Tx retries due to either distance "
3281 "too high or unable to Tx or Tx frame error - "
3282 "try changing 'iwconfig txpower XXX' or "
3283 "'sens'itivity or 'retry'";
3284 /* adev->wstats.discard.retries++; */
3285 /* Tx error 0x20 also seems to occur on
3286 * overheating, so I'm not sure whether we
3287 * actually want to do aggressive radio recalibration,
3288 * since people maybe won't notice then that their hardware
3289 * is slowly getting cooked...
3290 * Or is it still a safe long distance from utter
3291 * radio non-functionality despite many radio recalibs
3292 * to final destructive overheating of the hardware?
3293 * In this case we really should do recalib here...
3294 * I guess the only way to find out is to do a
3295 * potentially fatal self-experiment :-\
3296 * Or maybe only recalib in case we're using Tx
3297 * rate auto (on errors switching to lower speed
3298 * --> less heat?) or 802.11 power save mode?
3300 * ok, just do it. */
3301 if (++adev->retry_errors_msg_ratelimit % 4 == 0) {
3302 if (adev->retry_errors_msg_ratelimit <= 20) {
3303 acx_log(LOG_WARNING, L_ANY,
3304 "%s: several excessive Tx "
3305 "retry errors occurred, attempting "
3306 "to recalibrate radio\n",
3307 wiphy_name(adev->ieee->wiphy));
3308 acx_log(LOG_WARNING, L_ANY,
3309 "Radio drift might be caused by "
3310 "increasing card temperature, please "
3311 "check the card before it's too late!\n");
3312 if (adev->retry_errors_msg_ratelimit == 20)
3313 acx_log(LOG_WARNING, L_ANY,
3314 "disabling above message\n");
3317 acx_schedule_task(adev,
3318 ACX_TASKLET_CMD_RADIO_RECALIB);
3320 status->excessive_retries++;
3321 break;
3322 case 0x40:
3323 err = "Tx buffer overflow";
3324 adev->stats.tx_fifo_errors++;
3325 break;
3326 case 0x80:
3327 /* possibly ACPI C-state powersaving related!!!
3328 * (DMA timeout due to excessively high wakeup
3329 * latency after C-state activation!?)
3330 * Disable C-State powersaving and try again,
3331 * then PLEASE REPORT, I'm VERY interested in
3332 * whether my theory is correct that this is
3333 * actually the problem here.
3334 * In that case, use new Linux idle wakeup latency
3335 * requirements kernel API to prevent this issue. */
3336 err = "DMA error";
3337 /* adev->wstats.discard.misc++; */
3338 break;
3340 adev->stats.tx_errors++;
3341 if (adev->stats.tx_errors <= 20)
3342 acx_log(LOG_WARNING, L_ANY,
3343 "%s: tx error 0x%02X, buf %02u! (%s)\n",
3344 wiphy_name(adev->ieee->wiphy), error, finger, err);
3345 else
3346 acx_log(LOG_WARNING, L_ANY,
3347 "%s: tx error 0x%02X, buf %02u!\n",
3348 wiphy_name(adev->ieee->wiphy), error, finger);
3352 unsigned int acxpci_l_clean_txdesc(acx_device_t * adev)
3354 txdesc_t *txdesc;
3355 txhostdesc_t *hostdesc;
3356 unsigned finger;
3357 int num_cleaned;
3358 u16 r111;
3359 u8 error, ack_failures, rts_failures, rts_ok, r100;
3361 FN_ENTER;
3363 if (unlikely(acx_debug & L_REALLYVERBOSE))
3364 log_txbuffer(adev);
3366 acx_log(LOG_DEBUG, L_BUFT, "tx: cleaning up bufs from %u\n",
3367 adev->tx_tail);
3369 /* We know first descr which is not free yet. We advance it as far
3370 ** as we see correct bits set in following descs (if next desc
3371 ** is NOT free, we shouldn't advance at all). We know that in
3372 ** front of tx_tail may be "holes" with isolated free descs.
3373 ** We will catch up when all intermediate descs will be freed also */
3375 finger = adev->tx_tail;
3376 num_cleaned = 0;
3377 while (likely(finger != adev->tx_head)) {
3378 txdesc = get_txdesc(adev, finger);
3380 /* If we allocated txdesc on tx path but then decided
3381 ** to NOT use it, then it will be left as a free "bubble"
3382 ** in the "allocated for tx" part of the ring.
3383 ** We may meet it on the next ring pass here. */
3385 /* stop if not marked as "tx finished" and "host owned" */
3386 if ((txdesc->Ctl_8 & DESC_CTL_ACXDONE_HOSTOWN)
3387 != DESC_CTL_ACXDONE_HOSTOWN) {
3388 if (unlikely(!num_cleaned)) { /* maybe remove completely */
3389 acx_log(LOG_DEBUG, L_BUFT,
3390 "clean_txdesc: tail isn't free. "
3391 "tail:%d head:%d\n",
3392 adev->tx_tail, adev->tx_head);
3394 break;
3397 /* remember desc values... */
3398 error = txdesc->error;
3399 ack_failures = txdesc->ack_failures;
3400 rts_failures = txdesc->rts_failures;
3401 rts_ok = txdesc->rts_ok;
3402 r100 = txdesc->u.r1.rate;
3403 r111 = le16_to_cpu(txdesc->u.r2.rate111);
3405 /* need to check for certain error conditions before we
3406 * clean the descriptor: we still need valid descr data here */
3407 hostdesc = get_txhostdesc(adev, txdesc);
3409 hostdesc->txstatus.flags |= IEEE80211_TX_STATUS_ACK;
3410 if (unlikely(0x30 & error)) {
3411 /* only send IWEVTXDROP in case of retry or lifetime exceeded;
3412 * all other errors mean we screwed up locally */
3413 /* union iwreq_data wrqu;
3414 struct ieee80211_hdr_3addr *hdr;
3415 hdr = (struct ieee80211_hdr_3addr *) hostdesc->data;
3416 MAC_COPY(wrqu.addr.sa_data, hdr->addr1);
3418 hostdesc->txstatus.flags &= ~IEEE80211_TX_STATUS_ACK;
3421 /* ...and free the desc */
3422 txdesc->error = 0;
3423 txdesc->ack_failures = 0;
3424 txdesc->rts_failures = 0;
3425 txdesc->rts_ok = 0;
3426 /* signal host owning it LAST, since ACX already knows that this
3427 ** descriptor is finished since it set Ctl_8 accordingly. */
3428 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3430 adev->tx_free++;
3431 num_cleaned++;
3433 if ((adev->tx_free >= TX_START_QUEUE)
3434 /* && (adev->status == ACX_STATUS_4_ASSOCIATED) */
3435 /*&& (acx_queue_stopped(adev->ieee))*/
3437 acx_log(LOG_DEBUG, L_BUF,
3438 "tx: wake queue (avail. Tx desc %u)\n",
3439 adev->tx_free);
3440 acx_wake_queue(adev->ieee, NULL);
3443 /* do error checking, rate handling and logging
3444 * AFTER having done the work, it's faster */
3446 /* Rate handling is done in mac80211 */
3447 /* if (adev->rate_auto) {
3448 struct client *clt = get_txc(adev, txdesc);
3449 if (clt) {
3450 u16 cur = get_txr(adev, txdesc);
3451 if (clt->rate_cur == cur) {
3452 acx_l_handle_txrate_auto(adev, clt, cur,*/ /* intended rate */
3453 /*r100, r111,*/ /* actually used rate */
3454 /*(error & 0x30),*/ /* was there an error? */
3455 /* TX_CNT +
3456 TX_CLEAN_BACKLOG
3458 adev->tx_free);
3463 if (unlikely(error))
3464 handle_tx_error(adev, error, finger, &hostdesc->txstatus);
3466 if (IS_ACX111(adev))
3467 acx_log(LOG_DEBUG, L_BUFT, "tx: cleaned %u: !ACK=%u "
3468 "!RTS=%u RTS=%u r111=%04X tx_free=%u\n",
3469 finger, ack_failures,
3470 rts_failures, rts_ok, r111, adev->tx_free);
3471 else
3472 acx_log(LOG_DEBUG, L_BUFT, "tx: cleaned %u: !ACK=%u "
3473 "!RTS=%u RTS=%u rate=%u\n",
3474 finger, ack_failures,
3475 rts_failures, rts_ok, r100);
3477 /* And finally report upstream */
3478 if (hostdesc)
3480 hostdesc->txstatus.excessive_retries = rts_failures ;
3481 hostdesc->txstatus.retry_count = ack_failures;
3482 ieee80211_tx_status(adev->ieee,hostdesc->skb,&hostdesc->txstatus);
3483 memset(&hostdesc->txstatus, 0, sizeof(struct ieee80211_tx_status));
3485 /* update pointer for descr to be cleaned next */
3486 finger = (finger + 1) % TX_CNT;
3488 /* remember last position */
3489 adev->tx_tail = finger;
3490 /* end: */
3491 FN_EXIT1(num_cleaned);
3492 return num_cleaned;
3495 /* clean *all* Tx descriptors, and regardless of their previous state.
3496 * Used for brute-force reset handling. */
3497 void acxpci_l_clean_txdesc_emergency(acx_device_t * adev)
3499 txdesc_t *txdesc;
3500 int i;
3502 FN_ENTER;
3504 for (i = 0; i < TX_CNT; i++) {
3505 txdesc = get_txdesc(adev, i);
3507 /* free it */
3508 txdesc->ack_failures = 0;
3509 txdesc->rts_failures = 0;
3510 txdesc->rts_ok = 0;
3511 txdesc->error = 0;
3512 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3515 adev->tx_free = TX_CNT;
3517 FN_EXIT0;
3521 /***********************************************************************
3522 ** acxpci_s_create_tx_host_desc_queue
3525 static void *allocate(acx_device_t * adev, size_t size, dma_addr_t * phy,
3526 const char *msg)
3528 void *ptr;
3530 ptr = dma_alloc_coherent(adev->bus_dev, size, phy, GFP_KERNEL);
3532 if (ptr) {
3533 acx_log(LOG_DEBUG, L_REALLYVERBOSE,
3534 "%s sz=%d adr=0x%p phy=0x%08llx\n",
3535 msg, (int)size, ptr, (unsigned long long)*phy);
3536 memset(ptr, 0, size);
3537 return ptr;
3539 acx_log(LOG_WARNING, L_ANY, "%s allocation FAILED (%d bytes)\n",
3540 msg, (int)size);
3541 return NULL;
3545 static int acxpci_s_create_tx_host_desc_queue(acx_device_t * adev)
3547 txhostdesc_t *hostdesc;
3548 u8 *txbuf;
3549 dma_addr_t hostdesc_phy;
3550 dma_addr_t txbuf_phy;
3551 int i;
3553 FN_ENTER;
3555 /* allocate TX buffer */
3556 adev->txbuf_area_size = TX_CNT * /*WLAN_A4FR_MAXLEN_WEP_FCS*/ (30 + 2312 + 4);
3557 adev->txbuf_start = allocate(adev, adev->txbuf_area_size,
3558 &adev->txbuf_startphy, "txbuf_start");
3559 if (!adev->txbuf_start)
3560 goto fail;
3562 /* allocate the TX host descriptor queue pool */
3563 adev->txhostdesc_area_size = TX_CNT * 2 * sizeof(*hostdesc);
3564 adev->txhostdesc_start = allocate(adev, adev->txhostdesc_area_size,
3565 &adev->txhostdesc_startphy,
3566 "txhostdesc_start");
3567 if (!adev->txhostdesc_start)
3568 goto fail;
3569 /* check for proper alignment of TX host descriptor pool */
3570 if ((long)adev->txhostdesc_start & 3) {
3571 acx_log(LOG_WARNING, L_ANY,
3572 "driver bug: dma alloc returns unaligned address\n");
3573 goto fail;
3576 hostdesc = adev->txhostdesc_start;
3577 hostdesc_phy = adev->txhostdesc_startphy;
3578 txbuf = adev->txbuf_start;
3579 txbuf_phy = adev->txbuf_startphy;
3581 #if 0
3582 /* Each tx buffer is accessed by hardware via
3583 ** txdesc -> txhostdesc(s) -> txbuffer(s).
3584 ** We use only one txhostdesc per txdesc, but it looks like
3585 ** acx111 is buggy: it accesses second txhostdesc
3586 ** (via hostdesc.desc_phy_next field) even if
3587 ** txdesc->length == hostdesc->length and thus
3588 ** entire packet was placed into first txhostdesc.
3589 ** Due to this bug acx111 hangs unless second txhostdesc
3590 ** has le16_to_cpu(hostdesc.length) = 3 (or larger)
3591 ** Storing NULL into hostdesc.desc_phy_next
3592 ** doesn't seem to help.
3594 ** Update: although it worked on Xterasys XN-2522g
3595 ** with len=3 trick, WG311v2 is even more bogus, doesn't work.
3596 ** Keeping this code (#ifdef'ed out) for documentational purposes.
3598 for (i = 0; i < TX_CNT * 2; i++) {
3599 hostdesc_phy += sizeof(*hostdesc);
3600 if (!(i & 1)) {
3601 hostdesc->data_phy = cpu2acx(txbuf_phy);
3602 /* hostdesc->data_offset = ... */
3603 /* hostdesc->reserved = ... */
3604 hostdesc->Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
3605 /* hostdesc->length = ... */
3606 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3607 hostdesc->pNext = ptr2acx(NULL);
3608 /* hostdesc->Status = ... */
3609 /* below: non-hardware fields */
3610 hostdesc->data = txbuf;
3612 txbuf += WLAN_A4FR_MAXLEN_WEP_FCS;
3613 txbuf_phy += WLAN_A4FR_MAXLEN_WEP_FCS;
3614 } else {
3615 /* hostdesc->data_phy = ... */
3616 /* hostdesc->data_offset = ... */
3617 /* hostdesc->reserved = ... */
3618 /* hostdesc->Ctl_16 = ... */
3619 hostdesc->length = cpu_to_le16(3); /* bug workaround */
3620 /* hostdesc->desc_phy_next = ... */
3621 /* hostdesc->pNext = ... */
3622 /* hostdesc->Status = ... */
3623 /* below: non-hardware fields */
3624 /* hostdesc->data = ... */
3626 hostdesc++;
3628 #endif
3629 /* We initialize two hostdescs so that they point to adjacent
3630 ** memory areas. Thus txbuf is really just a contiguous memory area */
3631 for (i = 0; i < TX_CNT * 2; i++) {
3632 hostdesc_phy += sizeof(*hostdesc);
3634 hostdesc->data_phy = cpu2acx(txbuf_phy);
3635 /* done by memset(0): hostdesc->data_offset = 0; */
3636 /* hostdesc->reserved = ... */
3637 hostdesc->Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
3638 /* hostdesc->length = ... */
3639 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3640 /* done by memset(0): hostdesc->pNext = ptr2acx(NULL); */
3641 /* hostdesc->Status = ... */
3642 /* ->data is a non-hardware field: */
3643 hostdesc->data = txbuf;
3645 if (!(i & 1)) {
3646 txbuf += 24 /*WLAN_HDR_A3_LEN*/;
3647 txbuf_phy += 24 /*WLAN_HDR_A3_LEN*/;
3648 } else {
3649 txbuf += 30 + 2132 + 4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3650 txbuf_phy += 30 + 2132 +4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3652 hostdesc++;
3654 hostdesc--;
3655 hostdesc->desc_phy_next = cpu2acx(adev->txhostdesc_startphy);
3657 FN_EXIT1(OK);
3658 return OK;
3659 fail:
3660 acx_log(LOG_WARNING, L_ANY, "create_tx_host_desc_queue FAILED\n");
3661 /* dealloc will be done by free function on error case */
3662 FN_EXIT1(NOT_OK);
3663 return NOT_OK;
3667 /***************************************************************
3668 ** acxpci_s_create_rx_host_desc_queue
3670 /* the whole size of a data buffer (header plus data body)
3671 * plus 32 bytes safety offset at the end */
3672 #define RX_BUFFER_SIZE (sizeof(rxbuffer_t) + 32)
3674 static int acxpci_s_create_rx_host_desc_queue(acx_device_t * adev)
3676 rxhostdesc_t *hostdesc;
3677 rxbuffer_t *rxbuf;
3678 dma_addr_t hostdesc_phy;
3679 dma_addr_t rxbuf_phy;
3680 int i;
3682 FN_ENTER;
3684 /* allocate the RX host descriptor queue pool */
3685 adev->rxhostdesc_area_size = RX_CNT * sizeof(*hostdesc);
3686 adev->rxhostdesc_start = allocate(adev, adev->rxhostdesc_area_size,
3687 &adev->rxhostdesc_startphy,
3688 "rxhostdesc_start");
3689 if (!adev->rxhostdesc_start)
3690 goto fail;
3691 /* check for proper alignment of RX host descriptor pool */
3692 if ((long)adev->rxhostdesc_start & 3) {
3693 acx_log(LOG_WARNING, L_ANY,
3694 "driver bug: dma alloc returns unaligned address\n");
3695 goto fail;
3698 /* allocate Rx buffer pool which will be used by the acx
3699 * to store the whole content of the received frames in it */
3700 adev->rxbuf_area_size = RX_CNT * RX_BUFFER_SIZE;
3701 adev->rxbuf_start = allocate(adev, adev->rxbuf_area_size,
3702 &adev->rxbuf_startphy, "rxbuf_start");
3703 if (!adev->rxbuf_start)
3704 goto fail;
3706 rxbuf = adev->rxbuf_start;
3707 rxbuf_phy = adev->rxbuf_startphy;
3708 hostdesc = adev->rxhostdesc_start;
3709 hostdesc_phy = adev->rxhostdesc_startphy;
3711 /* don't make any popular C programming pointer arithmetic mistakes
3712 * here, otherwise I'll kill you...
3713 * (and don't dare asking me why I'm warning you about that...) */
3714 for (i = 0; i < RX_CNT; i++) {
3715 hostdesc->data = rxbuf;
3716 hostdesc->data_phy = cpu2acx(rxbuf_phy);
3717 hostdesc->length = cpu_to_le16(RX_BUFFER_SIZE);
3718 CLEAR_BIT(hostdesc->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3719 rxbuf++;
3720 rxbuf_phy += sizeof(*rxbuf);
3721 hostdesc_phy += sizeof(*hostdesc);
3722 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3723 hostdesc++;
3725 hostdesc--;
3726 hostdesc->desc_phy_next = cpu2acx(adev->rxhostdesc_startphy);
3727 FN_EXIT1(OK);
3728 return OK;
3729 fail:
3730 acx_log(LOG_WARNING, L_ANY, "create_rx_host_desc_queue FAILED\n");
3731 /* dealloc will be done by free function on error case */
3732 FN_EXIT1(NOT_OK);
3733 return NOT_OK;
3737 /***************************************************************
3738 ** acxpci_s_create_hostdesc_queues
3740 int acxpci_s_create_hostdesc_queues(acx_device_t * adev)
3742 int result;
3743 result = acxpci_s_create_tx_host_desc_queue(adev);
3744 if (OK != result)
3745 return result;
3746 result = acxpci_s_create_rx_host_desc_queue(adev);
3747 return result;
3751 /***************************************************************
3752 ** acxpci_create_tx_desc_queue
3754 static void acxpci_create_tx_desc_queue(acx_device_t * adev, u32 tx_queue_start)
3756 txdesc_t *txdesc;
3757 txhostdesc_t *hostdesc;
3758 dma_addr_t hostmemptr;
3759 u32 mem_offs;
3760 int i;
3762 FN_ENTER;
3764 if (IS_ACX100(adev))
3765 adev->txdesc_size = sizeof(*txdesc);
3766 else
3767 /* the acx111 txdesc is 4 bytes larger */
3768 adev->txdesc_size = sizeof(*txdesc) + 4;
3770 adev->txdesc_start = (txdesc_t *) (adev->iobase2 + tx_queue_start);
3772 acx_log(LOG_DEBUG, L_REALLYVERBOSE, "adev->iobase2=%p\n"
3773 "tx_queue_start=%08X\n adev->txdesc_start=%p\n",
3774 adev->iobase2, tx_queue_start, adev->txdesc_start);
3776 adev->tx_free = TX_CNT;
3777 /* done by memset: adev->tx_head = 0; */
3778 /* done by memset: adev->tx_tail = 0; */
3779 txdesc = adev->txdesc_start;
3780 mem_offs = tx_queue_start;
3781 hostmemptr = adev->txhostdesc_startphy;
3782 hostdesc = adev->txhostdesc_start;
3784 if (IS_ACX111(adev)) {
3785 /* ACX111 has a preinitialized Tx buffer! */
3786 /* loop over whole send pool */
3787 /* FIXME: do we have to do the hostmemptr stuff here?? */
3788 for (i = 0; i < TX_CNT; i++) {
3789 txdesc->HostMemPtr = ptr2acx(hostmemptr);
3790 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3791 /* reserve two (hdr desc and payload desc) */
3792 hostdesc += 2;
3793 hostmemptr += 2 * sizeof(*hostdesc);
3794 txdesc = advance_txdesc(adev, txdesc, 1);
3796 } else {
3797 /* ACX100 Tx buffer needs to be initialized by us */
3798 /* clear whole send pool. sizeof is safe here (we are acx100) */
3799 memset(adev->txdesc_start, 0, TX_CNT * sizeof(*txdesc));
3801 /* loop over whole send pool */
3802 for (i = 0; i < TX_CNT; i++) {
3803 acx_log(LOG_DEBUG, L_REALLYVERBOSE,
3804 "configure card tx descriptor: 0x%p, "
3805 "size: 0x%X\n", txdesc, adev->txdesc_size);
3807 /* pointer to hostdesc memory */
3808 txdesc->HostMemPtr = ptr2acx(hostmemptr);
3809 /* initialise ctl */
3810 txdesc->Ctl_8 = (DESC_CTL_HOSTOWN | DESC_CTL_RECLAIM
3811 | DESC_CTL_AUTODMA |
3812 DESC_CTL_FIRSTFRAG);
3813 /* done by memset(0): txdesc->Ctl2_8 = 0; */
3814 /* point to next txdesc */
3815 txdesc->pNextDesc =
3816 cpu2acx(mem_offs + adev->txdesc_size);
3817 /* reserve two (hdr desc and payload desc) */
3818 hostdesc += 2;
3819 hostmemptr += 2 * sizeof(*hostdesc);
3820 /* go to the next one */
3821 mem_offs += adev->txdesc_size;
3822 /* ++ is safe here (we are acx100) */
3823 txdesc++;
3825 /* go back to the last one */
3826 txdesc--;
3827 /* and point to the first making it a ring buffer */
3828 txdesc->pNextDesc = cpu2acx(tx_queue_start);
3830 FN_EXIT0;
3834 /***************************************************************
3835 ** acxpci_create_rx_desc_queue
3837 static void acxpci_create_rx_desc_queue(acx_device_t * adev, u32 rx_queue_start)
3839 rxdesc_t *rxdesc;
3840 u32 mem_offs;
3841 int i;
3843 FN_ENTER;
3845 /* done by memset: adev->rx_tail = 0; */
3847 /* ACX111 doesn't need any further config: preconfigures itself.
3848 * Simply print ring buffer for debugging */
3849 if (IS_ACX111(adev)) {
3850 /* rxdesc_start already set here */
3852 adev->rxdesc_start =
3853 (rxdesc_t *) ((u8 *) adev->iobase2 + rx_queue_start);
3855 rxdesc = adev->rxdesc_start;
3856 for (i = 0; i < RX_CNT; i++) {
3857 acx_log(LOG_DEBUG, L_REALLYVERBOSE,
3858 "rx descriptor %d @ 0x%p\n", i, rxdesc);
3859 rxdesc = adev->rxdesc_start = (rxdesc_t *)
3860 (adev->iobase2 + acx2cpu(rxdesc->pNextDesc));
3862 } else {
3863 /* we didn't pre-calculate rxdesc_start in case of ACX100 */
3864 /* rxdesc_start should be right AFTER Tx pool */
3865 adev->rxdesc_start = (rxdesc_t *)
3866 ((u8 *) adev->txdesc_start + (TX_CNT * sizeof(txdesc_t)));
3867 /* NB: sizeof(txdesc_t) above is valid because we know
3868 ** we are in if (acx100) block. Beware of cut-n-pasting elsewhere!
3869 ** acx111's txdesc is larger! */
3871 memset(adev->rxdesc_start, 0, RX_CNT * sizeof(*rxdesc));
3873 /* loop over whole receive pool */
3874 rxdesc = adev->rxdesc_start;
3875 mem_offs = rx_queue_start;
3876 for (i = 0; i < RX_CNT; i++) {
3877 acx_log(LOG_DEBUG, L_REALLYVERBOSE,
3878 "rx descriptor @ 0x%p\n", rxdesc);
3879 rxdesc->Ctl_8 = DESC_CTL_RECLAIM | DESC_CTL_AUTODMA;
3880 /* point to next rxdesc */
3881 rxdesc->pNextDesc = cpu2acx(mem_offs + sizeof(*rxdesc));
3882 /* go to the next one */
3883 mem_offs += sizeof(*rxdesc);
3884 rxdesc++;
3886 /* go to the last one */
3887 rxdesc--;
3889 /* and point to the first making it a ring buffer */
3890 rxdesc->pNextDesc = cpu2acx(rx_queue_start);
3892 FN_EXIT0;
3896 /***************************************************************
3897 ** acxpci_create_desc_queues
3899 void
3900 acxpci_create_desc_queues(acx_device_t * adev, u32 tx_queue_start,
3901 u32 rx_queue_start)
3903 acxpci_create_tx_desc_queue(adev, tx_queue_start);
3904 acxpci_create_rx_desc_queue(adev, rx_queue_start);
3908 /***************************************************************
3909 ** acxpci_s_proc_diag_output
3911 char *acxpci_s_proc_diag_output(char *p, acx_device_t * adev)
3913 const char *rtl, *thd, *ttl;
3914 rxhostdesc_t *rxhostdesc;
3915 txdesc_t *txdesc;
3916 int i;
3918 FN_ENTER;
3920 p += sprintf(p, "** Rx buf **\n");
3921 rxhostdesc = adev->rxhostdesc_start;
3922 if (rxhostdesc)
3923 for (i = 0; i < RX_CNT; i++) {
3924 rtl = (i == adev->rx_tail) ? " [tail]" : "";
3925 if ((rxhostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
3926 && (rxhostdesc->
3927 Status & cpu_to_le32(DESC_STATUS_FULL)))
3928 p += sprintf(p, "%02u FULL%s\n", i, rtl);
3929 else
3930 p += sprintf(p, "%02u empty%s\n", i, rtl);
3931 rxhostdesc++;
3933 /* p += sprintf(p, "** Tx buf (free %d, Linux netqueue %s) **\n",
3934 adev->tx_free,
3935 acx_queue_stopped(adev->ieee) ? "STOPPED" : "running");*/
3936 txdesc = adev->txdesc_start;
3937 if (txdesc)
3938 for (i = 0; i < TX_CNT; i++) {
3939 thd = (i == adev->tx_head) ? " [head]" : "";
3940 ttl = (i == adev->tx_tail) ? " [tail]" : "";
3941 if (txdesc->Ctl_8 & DESC_CTL_ACXDONE)
3942 p += sprintf(p, "%02u free (%02X)%s%s\n", i,
3943 txdesc->Ctl_8, thd, ttl);
3944 else
3945 p += sprintf(p, "%02u tx (%02X)%s%s\n", i,
3946 txdesc->Ctl_8, thd, ttl);
3947 txdesc = advance_txdesc(adev, txdesc, 1);
3949 p += sprintf(p,
3950 "\n"
3951 "** PCI data **\n"
3952 "txbuf_start %p, txbuf_area_size %u, txbuf_startphy %08llx\n"
3953 "txdesc_size %u, txdesc_start %p\n"
3954 "txhostdesc_start %p, txhostdesc_area_size %u, txhostdesc_startphy %08llx\n"
3955 "rxdesc_start %p\n"
3956 "rxhostdesc_start %p, rxhostdesc_area_size %u, rxhostdesc_startphy %08llx\n"
3957 "rxbuf_start %p, rxbuf_area_size %u, rxbuf_startphy %08llx\n",
3958 adev->txbuf_start, adev->txbuf_area_size,
3959 (unsigned long long)adev->txbuf_startphy,
3960 adev->txdesc_size, adev->txdesc_start,
3961 adev->txhostdesc_start, adev->txhostdesc_area_size,
3962 (unsigned long long)adev->txhostdesc_startphy,
3963 adev->rxdesc_start,
3964 adev->rxhostdesc_start, adev->rxhostdesc_area_size,
3965 (unsigned long long)adev->rxhostdesc_startphy,
3966 adev->rxbuf_start, adev->rxbuf_area_size,
3967 (unsigned long long)adev->rxbuf_startphy);
3969 FN_EXIT0;
3970 return p;
3974 /***********************************************************************
3976 int acxpci_proc_eeprom_output(char *buf, acx_device_t * adev)
3978 char *p = buf;
3979 int i;
3981 FN_ENTER;
3983 for (i = 0; i < 0x400; i++) {
3984 acxpci_read_eeprom_byte(adev, i, p++);
3987 FN_EXIT1(p - buf);
3988 return p - buf;
3992 /***********************************************************************
3994 int acx100pci_s_set_tx_level(acx_device_t * adev, u8 level_dbm)
3996 /* since it can be assumed that at least the Maxim radio has a
3997 * maximum power output of 20dBm and since it also can be
3998 * assumed that these values drive the DAC responsible for
3999 * setting the linear Tx level, I'd guess that these values
4000 * should be the corresponding linear values for a dBm value,
4001 * in other words: calculate the values from that formula:
4002 * Y [dBm] = 10 * log (X [mW])
4003 * then scale the 0..63 value range onto the 1..100mW range (0..20 dBm)
4004 * and you're done...
4005 * Hopefully that's ok, but you never know if we're actually
4006 * right... (especially since Windows XP doesn't seem to show
4007 * actual Tx dBm values :-P) */
4009 /* NOTE: on Maxim, value 30 IS 30mW, and value 10 IS 10mW - so the
4010 * values are EXACTLY mW!!! Not sure about RFMD and others,
4011 * though... */
4012 static const u8 dbm2val_maxim[21] = {
4013 63, 63, 63, 62,
4014 61, 61, 60, 60,
4015 59, 58, 57, 55,
4016 53, 50, 47, 43,
4017 38, 31, 23, 13,
4020 static const u8 dbm2val_rfmd[21] = {
4021 0, 0, 0, 1,
4022 2, 2, 3, 3,
4023 4, 5, 6, 8,
4024 10, 13, 16, 20,
4025 25, 32, 41, 50,
4028 const u8 *table;
4030 switch (adev->radio_type) {
4031 case RADIO_MAXIM_0D:
4032 table = &dbm2val_maxim[0];
4033 break;
4034 case RADIO_RFMD_11:
4035 case RADIO_RALINK_15:
4036 table = &dbm2val_rfmd[0];
4037 break;
4038 default:
4039 acx_log(LOG_WARNING, L_ANY, "%s: unknown/unsupported radio type, "
4040 "cannot modify tx power level yet!\n",
4041 wiphy_name(adev->ieee->wiphy));
4042 return NOT_OK;
4044 acx_log(LOG_INFO, L_ANY,
4045 "%s: changing radio power level to %u dBm (%u)\n",
4046 wiphy_name(adev->ieee->wiphy), level_dbm, table[level_dbm]);
4047 acxpci_s_write_phy_reg(adev, 0x11, table[level_dbm]);
4048 return OK;
4051 #ifdef CONFIG_VLYNQ
4052 struct vlynq_reg_config {
4053 u32 offset;
4054 u32 value;
4057 struct vlynq_known {
4058 u32 chip_id;
4059 char name[32];
4060 struct vlynq_mapping rx_mapping[4];
4061 int irq;
4062 int irq_type;
4063 int num_regs;
4064 struct vlynq_reg_config regs[10];
4067 #define CHIP_TNETW1130 0x00000009
4068 #define CHIP_TNETW1350 0x00000029
4070 static struct vlynq_known known_devices[] = {
4072 .chip_id = CHIP_TNETW1130, .name = "TI TNETW1130",
4073 .rx_mapping = {
4074 { .size = 0x22000, .offset = 0xf0000000 },
4075 { .size = 0x40000, .offset = 0xc0000000 },
4076 { .size = 0x0, .offset = 0x0 },
4077 { .size = 0x0, .offset = 0x0 },
4079 .irq = 0,
4080 .irq_type = IRQ_TYPE_EDGE_RISING,
4081 .num_regs = 5,
4082 .regs = {
4084 .offset = 0x790,
4085 .value = (0xd0000000 - PHYS_OFFSET)
4088 .offset = 0x794,
4089 .value = (0xd0000000 - PHYS_OFFSET)
4091 { .offset = 0x740, .value = 0 },
4092 { .offset = 0x744, .value = 0x00010000 },
4093 { .offset = 0x764, .value = 0x00010000 },
4097 .chip_id = CHIP_TNETW1350, .name = "TI TNETW1350",
4098 .rx_mapping = {
4099 { .size = 0x100000, .offset = 0x00300000 },
4100 { .size = 0x80000, .offset = 0x00000000 },
4101 { .size = 0x0, .offset = 0x0 },
4102 { .size = 0x0, .offset = 0x0 },
4104 .irq = 0,
4105 .irq_type = IRQ_TYPE_EDGE_RISING,
4106 .num_regs = 5,
4107 .regs = {
4109 .offset = 0x790,
4110 .value = (0x60000000 - PHYS_OFFSET)
4113 .offset = 0x794,
4114 .value = (0x60000000 - PHYS_OFFSET)
4116 { .offset = 0x740, .value = 0 },
4117 { .offset = 0x744, .value = 0x00010000 },
4118 { .offset = 0x764, .value = 0x00010000 },
4123 static struct vlynq_device_id acx_vlynq_id[] = {
4124 { CHIP_TNETW1130, vlynq_div_auto, 0 },
4125 { CHIP_TNETW1350, vlynq_div_auto, 1 },
4126 { 0, 0, 0 },
4129 static __devinit int vlynq_probe(struct vlynq_device *vdev,
4130 struct vlynq_device_id *id)
4132 int result = -EIO, i;
4133 u32 addr;
4134 struct ieee80211_hw *ieee;
4135 acx_device_t *adev = NULL;
4136 acx111_ie_configoption_t co;
4137 struct vlynq_mapping mapping[4] = { { 0, }, };
4138 struct vlynq_known *match = NULL;
4140 FN_ENTER;
4141 result = vlynq_enable_device(vdev);
4142 if (result)
4143 return result;
4145 match = &known_devices[id->driver_data];
4147 if (!match) {
4148 result = -ENODEV;
4149 goto fail;
4152 mapping[0].offset = ARCH_PFN_OFFSET << PAGE_SHIFT;
4153 mapping[0].size = 0x02000000;
4154 vlynq_set_local_mapping(vdev, vdev->mem_start, mapping);
4155 vlynq_set_remote_mapping(vdev, 0, match->rx_mapping);
4157 set_irq_type(vlynq_virq_to_irq(vdev, match->irq), match->irq_type);
4159 addr = (u32)ioremap(vdev->mem_start, 0x1000);
4160 if (!addr) {
4161 acx_log(LOG_WARNING, L_ANY, "%s: failed to remap io memory\n",
4162 vdev->dev.bus_id);
4163 result = -ENXIO;
4164 goto fail;
4167 for (i = 0; i < match->num_regs; i++)
4168 iowrite32(match->regs[i].value,
4169 (u32 *)(addr + match->regs[i].offset));
4171 iounmap((void *)addr);
4173 ieee = ieee80211_alloc_hw(sizeof(struct acx_device), &acxpci_hw_ops);
4174 if (!ieee) {
4175 acx_log(LOG_WARNING, L_ANY,
4176 "could not allocate ieee80211 structure %s\n",
4177 vdev->dev.bus_id);
4178 goto fail_alloc_netdev;
4180 ieee->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
4181 ieee->queues = 1;
4183 adev = ieee2adev(ieee);
4185 memset(adev, 0, sizeof(*adev));
4186 /** Set up our private interface **/
4187 spin_lock_init(&adev->spinlock); /* initial state: unlocked */
4188 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
4189 mutex_init(&adev->mutex);
4190 /* since nobody can see new netdev yet, we can as well
4191 ** just _presume_ that we're under sem (instead of actually taking it): */
4192 /* acx_sem_lock(adev); */
4193 adev->ieee = ieee;
4194 adev->vdev = vdev;
4195 adev->bus_dev = &vdev->dev;
4197 /** Finished with private interface **/
4199 vlynq_set_drvdata(vdev, ieee);
4200 if (!request_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start, "acx")) {
4201 acx_log(LOG_WARNING, L_ANY, "cannot reserve VLYNQ memory region\n");
4202 goto fail_request_mem_region;
4205 adev->iobase = ioremap(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4206 if (!adev->iobase) {
4207 acx_log(LOG_WARNING, L_ANY, "ioremap() FAILED\n");
4208 goto fail_ioremap;
4210 adev->iobase2 = adev->iobase + match->rx_mapping[0].size;
4211 adev->chip_type = CHIPTYPE_ACX111;
4212 adev->chip_name = match->name;
4213 adev->io = IO_ACX111;
4214 adev->irq = vlynq_virq_to_irq(vdev, match->irq);
4216 acx_log(LOG_INFO, L_ANY, "found %s-based wireless network card at %s, "
4217 "irq:%d, phymem:0x%x, mem:0x%p\n",
4218 match->name, vdev->dev.bus_id, adev->irq,
4219 vdev->mem_start, adev->iobase);
4220 // acx_log(LOG_INFO, L_ANY,
4221 // "initial debug setting is 0x%04X\n", acx_debug);
4223 if (0 == adev->irq) {
4224 acx_log(LOG_WARNING, L_ANY, "can't use IRQ 0\n");
4225 goto fail_irq;
4227 SET_IEEE80211_DEV(ieee, &vdev->dev);
4229 /* request shared IRQ handler */
4230 if (request_irq
4231 (adev->irq, acxpci_i_interrupt, IRQF_SHARED, KBUILD_MODNAME, adev)) {
4232 acx_log(LOG_WARNING, L_ANY, "%s: request_irq FAILED\n",
4233 wiphy_name(adev->ieee->wiphy));
4234 result = -EAGAIN;
4235 goto done;
4237 acx_log(LOG_DEBUG, L_IRQ | L_REALLYVERBOSE,
4238 "request_irq %d successful\n", adev->irq);
4240 /* to find crashes due to weird driver access
4241 * to unconfigured interface (ifup) */
4242 adev->mgmt_timer.function = (void (*)(unsigned long))0x0000dead;
4245 /* ok, pci setup is finished, now start initializing the card */
4247 /* NB: read_reg() reads may return bogus data before reset_dev(),
4248 * since the firmware which directly controls large parts of the I/O
4249 * registers isn't initialized yet.
4250 * acx100 seems to be more affected than acx111 */
4251 if (OK != acxpci_s_reset_dev(adev))
4252 goto fail_reset;
4254 if (OK != acx_s_init_mac(adev))
4255 goto fail_init_mac;
4257 acx_s_interrogate(adev, &co, ACX111_REG_CONFIG_OPTIONS);
4258 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
4259 if (OK != acxpci_read_eeprom_byte(adev, 0x05, &adev->eeprom_version))
4260 goto fail_read_eeprom_version;
4262 acx_s_parse_configoption(adev, &co);
4263 acx_s_set_defaults(adev);
4264 acx_s_get_firmware_version(adev); /* needs to be after acx_s_init_mac() */
4265 acx_display_hardware_details(adev);
4267 /* Register the card, AFTER everything else has been set up,
4268 * since otherwise an ioctl could step on our feet due to
4269 * firmware operations happening in parallel or uninitialized data */
4272 acx_proc_register_entries(ieee);
4274 /* Now we have our device, so make sure the kernel doesn't try
4275 * to send packets even though we're not associated to a network yet */
4277 /* after register_netdev() userspace may start working with dev
4278 * (in particular, on other CPUs), we only need to up the sem */
4279 /* acx_sem_unlock(adev); */
4281 acx_log(LOG_INFO, L_ANY, "driver " ACX_RELEASE ", net device %s, "
4282 "driver compiled against wireless extensions %d and Linux %s\n",
4283 wiphy_name(adev->ieee->wiphy), WIRELESS_EXT, UTS_RELEASE);
4285 MAC_COPY(adev->ieee->wiphy->perm_addr, adev->dev_addr);
4287 acx_log(LOG_DEBUG, L_IRQ | L_INIT, "using IRQ %d\n", adev->irq);
4289 /** done with board specific setup **/
4291 result = acx_setup_modes(adev);
4292 if (result) {
4293 acx_log(LOG_WARNING, L_ANY, "can't register hwmode\n");
4294 goto fail_register_netdev;
4297 acx_init_task_scheduler(adev);
4298 result = ieee80211_register_hw(adev->ieee);
4299 if (OK != result) {
4300 acx_log(LOG_WARNING, L_ANY,
4301 "acx: ieee80211_register_hw() FAILED: %d\n", result);
4302 goto fail_register_netdev;
4304 #if CMD_DISCOVERY
4305 great_inquisitor(adev);
4306 #endif
4308 result = OK;
4309 goto done;
4311 /* error paths: undo everything in reverse order... */
4314 acxpci_s_delete_dma_regions(adev);
4316 fail_init_mac:
4317 fail_read_eeprom_version:
4318 fail_reset:
4320 fail_alloc_netdev:
4321 fail_irq:
4323 iounmap(adev->iobase);
4324 fail_ioremap:
4326 release_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4327 fail_request_mem_region:
4328 fail_register_netdev:
4329 ieee80211_free_hw(ieee);
4330 fail:
4331 vlynq_disable_device(vdev);
4332 done:
4333 FN_EXIT1(result);
4334 return result;
4337 static void vlynq_remove(struct vlynq_device *vdev)
4339 struct ieee80211_hw *hw = vlynq_get_drvdata(vdev);
4340 acx_device_t *adev = ieee2adev(hw);
4341 unsigned long flags;
4342 FN_ENTER;
4344 if (!hw) {
4345 acx_log(LOG_DEBUG, L_REALLYVERBOSE,
4346 "%s: card is unused. Skipping any release code\n",
4347 __func__);
4348 goto end;
4352 acx_lock(adev, flags);
4353 acx_unlock(adev, flags);
4354 adev->initialized = 0;
4356 /* If device wasn't hot unplugged... */
4357 if (adev_present(adev)) {
4359 acx_sem_lock(adev);
4361 /* disable both Tx and Rx to shut radio down properly */
4362 if (adev->initialized) {
4363 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_TX, NULL, 0);
4364 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_RX, NULL, 0);
4366 acx_lock(adev, flags);
4367 /* disable power LED to save power :-) */
4368 acx_log(LOG_INFO, L_INIT,
4369 "switching off power LED to save power\n");
4370 acxpci_l_power_led(adev, 0);
4371 /* stop our eCPU */
4372 acx_unlock(adev, flags);
4374 acx_sem_unlock(adev);
4377 /* unregister the device to not let the kernel
4378 * (e.g. ioctls) access a half-deconfigured device
4379 * NB: this will cause acxpci_e_close() to be called,
4380 * thus we shouldn't call it under sem!
4382 acx_log(LOG_INFO, L_INIT, "removing device %s\n",
4383 wiphy_name(adev->ieee->wiphy));
4384 ieee80211_unregister_hw(adev->ieee);
4386 /* unregister_netdev ensures that no references to us left.
4387 * For paranoid reasons we continue to follow the rules */
4388 acx_sem_lock(adev);
4390 if (adev->dev_state_mask & ACX_STATE_IFACE_UP) {
4391 acxpci_s_down(hw);
4392 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
4395 acx_proc_unregister_entries(adev->ieee);
4397 /* finally, clean up PCI bus state */
4398 acxpci_s_delete_dma_regions(adev);
4399 if (adev->iobase)
4400 iounmap(adev->iobase);
4401 if (adev->iobase2)
4402 iounmap(adev->iobase2);
4403 release_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4405 /* remove dev registration */
4407 acx_sem_unlock(adev);
4408 vlynq_disable_device(vdev);
4410 /* Free netdev (quite late,
4411 * since otherwise we might get caught off-guard
4412 * by a netdev timeout handler execution
4413 * expecting to see a working dev...) */
4414 ieee80211_free_hw(adev->ieee);
4416 end:
4417 FN_EXIT0;
4420 static struct vlynq_driver vlynq_acx = {
4421 .name = "acx_vlynq",
4422 .id_table = acx_vlynq_id,
4423 .probe = vlynq_probe,
4424 .remove = __devexit_p(vlynq_remove),
4426 #endif /* CONFIG_VLYNQ */
4429 /***********************************************************************
4430 ** Data for init_module/cleanup_module
4432 #ifdef CONFIG_PCI
4433 static const struct pci_device_id acxpci_id_tbl[] __devinitdata = {
4435 .vendor = PCI_VENDOR_ID_TI,
4436 .device = PCI_DEVICE_ID_TI_TNETW1100A,
4437 .subvendor = PCI_ANY_ID,
4438 .subdevice = PCI_ANY_ID,
4439 .driver_data = CHIPTYPE_ACX100,
4442 .vendor = PCI_VENDOR_ID_TI,
4443 .device = PCI_DEVICE_ID_TI_TNETW1100B,
4444 .subvendor = PCI_ANY_ID,
4445 .subdevice = PCI_ANY_ID,
4446 .driver_data = CHIPTYPE_ACX100,
4449 .vendor = PCI_VENDOR_ID_TI,
4450 .device = PCI_DEVICE_ID_TI_TNETW1130,
4451 .subvendor = PCI_ANY_ID,
4452 .subdevice = PCI_ANY_ID,
4453 .driver_data = CHIPTYPE_ACX111,
4456 .vendor = 0,
4457 .device = 0,
4458 .subvendor = 0,
4459 .subdevice = 0,
4460 .driver_data = 0,
4464 MODULE_DEVICE_TABLE(pci, acxpci_id_tbl);
4466 static struct pci_driver
4467 acxpci_drv_id = {
4468 .name = "acx_pci",
4469 .id_table = acxpci_id_tbl,
4470 .probe = acxpci_e_probe,
4471 .remove = __devexit_p(acxpci_e_remove),
4472 #ifdef CONFIG_PM
4473 .suspend = acxpci_e_suspend,
4474 .resume = acxpci_e_resume
4475 #endif /* CONFIG_PM */
4477 #endif /* CONFIG_PCI */
4479 /***********************************************************************
4480 ** acxpci_e_init_module
4482 ** Module initialization routine, called once at module load time
4484 int __init acxpci_e_init_module(void)
4486 int res;
4488 FN_ENTER;
4490 #if (ACX_IO_WIDTH==32)
4491 acx_log(LOG_INFO, L_ANY, "compiled to use 32bit I/O access. "
4492 "I/O timing issues might occur, such as "
4493 "non-working firmware upload. Report them\n");
4494 #else
4495 acx_log(LOG_INFO, L_ANY, "compiled to use 16bit I/O access only "
4496 "(compatibility mode)\n");
4497 #endif
4499 #ifdef __LITTLE_ENDIAN
4500 #define ENDIANNESS_STRING "running on a little-endian CPU\n"
4501 #else
4502 #define ENDIANNESS_STRING "running on a BIG-ENDIAN CPU\n"
4503 #endif
4504 acx_log(LOG_INFO, L_INIT, ENDIANNESS_STRING);
4505 acx_log(LOG_INFO, L_INIT, "PCI/VLYNQ module " ACX_RELEASE
4506 " initialized, waiting for cards to probe...\n");
4508 #ifdef CONFIG_PCI
4509 res = pci_register_driver(&acxpci_drv_id);
4510 #elif CONFIG_VLYNQ
4511 res = vlynq_register_driver(&vlynq_acx);
4512 #endif
4514 if (res) {
4515 printk(KERN_ERR "acx_pci: can't register pci/vlynq driver\n");
4518 FN_EXIT1(res);
4519 return res;
4523 /***********************************************************************
4524 ** acxpci_e_cleanup_module
4526 ** Called at module unload time. This is our last chance to
4527 ** clean up after ourselves.
4529 void __exit acxpci_e_cleanup_module(void)
4531 FN_ENTER;
4533 #ifdef CONFIG_PCI
4534 pci_unregister_driver(&acxpci_drv_id);
4535 #elif CONFIG_VLYNQ
4536 vlynq_unregister_driver(&vlynq_acx);
4537 #endif
4538 acx_log(LOG_INFO, L_INIT,
4539 "PCI module " ACX_RELEASE " unloaded\n");
4540 FN_EXIT0;