Rename IO_ACX_* to ACX_IO_* to keep in sync with naming conventions
[acx-mac80211.git] / pci.c
blobaccb541a5ea79f37d876089843c15b9d69b67643
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_log.h"
39 #include "acx_irq.h"
40 #include "acx_util.h"
42 /***********************************************************************
44 #ifdef CONFIG_PCI
45 #define PCI_TYPE (PCI_USES_MEM | PCI_ADDR0 | PCI_NO_ACPI_WAKE)
46 #define PCI_ACX100_REGION1 0x01
47 #define PCI_ACX100_REGION1_SIZE 0x1000 /* Memory size - 4K bytes */
48 #define PCI_ACX100_REGION2 0x02
49 #define PCI_ACX100_REGION2_SIZE 0x10000 /* Memory size - 64K bytes */
51 #define PCI_ACX111_REGION1 0x00
52 #define PCI_ACX111_REGION1_SIZE 0x2000 /* Memory size - 8K bytes */
53 #define PCI_ACX111_REGION2 0x01
54 #define PCI_ACX111_REGION2_SIZE 0x20000 /* Memory size - 128K bytes */
56 /* Texas Instruments Vendor ID */
57 #define PCI_VENDOR_ID_TI 0x104c
59 /* ACX100 22Mb/s WLAN controller */
60 #define PCI_DEVICE_ID_TI_TNETW1100A 0x8400
61 #define PCI_DEVICE_ID_TI_TNETW1100B 0x8401
63 /* ACX111 54Mb/s WLAN controller */
64 #define PCI_DEVICE_ID_TI_TNETW1130 0x9066
66 /* PCI Class & Sub-Class code, Network-'Other controller' */
67 #define PCI_CLASS_NETWORK_OTHERS 0x0280
69 #define CARD_EEPROM_ID_SIZE 6
71 #ifndef PCI_D0
72 /* From include/linux/pci.h */
73 #define PCI_D0 0
74 #define PCI_D1 1
75 #define PCI_D2 2
76 #define PCI_D3hot 3
77 #define PCI_D3cold 4
78 #define PCI_UNKNOWN 5
79 #define PCI_POWER_ERROR -1
80 #endif
81 #endif /* CONFIG_PCI */
83 /***********************************************************************
86 static irqreturn_t acxpci_i_interrupt(int irq, void *dev_id);
88 static void disable_acx_irq(acx_device_t * adev);
90 static int acxpci_e_open(struct ieee80211_hw *hw);
91 static void acxpci_e_close(struct ieee80211_hw *hw);
92 static void acxpci_s_up(struct ieee80211_hw *hw);
93 static void acxpci_s_down(struct ieee80211_hw *hw);
95 /* Handle PCI posting properly:
96 * Make sure that writes reach the adapter in case they require to be executed
97 * *before* the next write, by reading a random (and safely accessible) register.
98 * This call has to be made if there is no read following (which would flush the data
99 * to the adapter), yet the written data has to reach the adapter immediately. */
100 static inline void write_flush(acx_device_t * adev)
102 /* readb(adev->iobase + adev->io[ACX_IO_INFO_MAILBOX_OFFS]); */
103 /* faster version (accesses the first register, ACX_IO_SOFT_RESET,
104 * which should also be safe): */
105 //readb(adev->iobase);
106 smp_wmb();
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_IE_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_IE_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: ");
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 adev = ieee2adev(ieee);
1490 memset(adev, 0, sizeof(*adev));
1491 /** Set up our private interface **/
1492 spin_lock_init(&adev->spinlock);
1493 spin_lock_init(&adev->irqlock);
1494 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
1495 acx_log(LOG_INFO, L_ANY,
1496 "mutex_init(&adev->mutex); // adev = 0x%px\n", adev);
1497 mutex_init(&adev->mutex);
1498 /* since nobody can see new netdev yet, we can as well
1499 ** just _presume_ that we're under sem (instead of actually taking it): */
1500 /* acx_sem_lock(adev); */
1501 adev->ieee = ieee;
1502 adev->pdev = pdev;
1503 adev->bus_dev = &pdev->dev;
1504 adev->dev_type = DEVTYPE_PCI;
1506 /** Finished with private interface **/
1508 /** begin board specific inits **/
1509 pci_set_drvdata(pdev, ieee);
1511 /* Enable the PCI device */
1512 if (pci_enable_device(pdev)) {
1513 acx_log(LOG_WARNING, L_ANY, "pci_enable_device() FAILED\n");
1514 result = -ENODEV;
1515 goto fail_pci_enable_device;
1518 /* enable busmastering (required for CardBus) */
1519 pci_set_master(pdev);
1522 /* chiptype is u8 but id->driver_data is ulong
1523 ** Works for now (possible values are 1 and 2) */
1524 chip_type = (u8) id->driver_data;
1525 /* acx100 and acx111 have different PCI memory regions */
1526 if (chip_type == CHIPTYPE_ACX100) {
1527 chip_name = "ACX100";
1528 mem_region1 = PCI_ACX100_REGION1;
1529 mem_region1_size = PCI_ACX100_REGION1_SIZE;
1531 mem_region2 = PCI_ACX100_REGION2;
1532 mem_region2_size = PCI_ACX100_REGION2_SIZE;
1533 } else if (chip_type == CHIPTYPE_ACX111) {
1534 chip_name = "ACX111";
1535 mem_region1 = PCI_ACX111_REGION1;
1536 mem_region1_size = PCI_ACX111_REGION1_SIZE;
1538 mem_region2 = PCI_ACX111_REGION2;
1539 mem_region2_size = PCI_ACX111_REGION2_SIZE;
1540 } else {
1541 acx_log(LOG_WARNING, L_ANY,
1542 "unknown chip type 0x%04X\n", chip_type);
1543 goto fail_unknown_chiptype;
1546 /* Figure out our resources
1548 * Request our PCI IO regions
1550 err = pci_request_region(pdev, mem_region1, "acx_1");
1551 if (err) {
1552 acx_log(LOG_WARNING, L_ANY, "pci_request_region (1/2) FAILED!"
1553 "No cardbus support in kernel?\n");
1554 goto fail_request_mem_region1;
1557 phymem1 = pci_resource_start(pdev, mem_region1);
1559 err = pci_request_region(pdev, mem_region2, "acx_2");
1560 if (err) {
1561 acx_log(LOG_WARNING, L_ANY, "pci_request_region (2/2) FAILED!\n");
1562 goto fail_request_mem_region2;
1565 phymem2 = pci_resource_start(pdev, mem_region2);
1568 * We got them? Map them!
1570 * We pass 0 as the third argument to pci_iomap(): it will map the full
1571 * region in this case, which is what we want.
1574 mem1 = pci_iomap(pdev, mem_region1, 0);
1575 if (!mem1) {
1576 acx_log(LOG_WARNING, L_ANY, "ioremap() FAILED\n");
1577 goto fail_ioremap1;
1580 mem2 = pci_iomap(pdev, mem_region2, 0);
1581 if (!mem2) {
1582 acx_log(LOG_WARNING, L_ANY, "ioremap() #2 FAILED\n");
1583 goto fail_ioremap2;
1586 acx_log(LOG_INFO, L_ANY, "found %s-based wireless network card at %s, "
1587 "irq:%d, phymem1:0x%lX, phymem2:0x%lX, mem1:0x%p, "
1588 "mem1_size:%ld, mem2:0x%p, mem2_size:%ld\n",
1589 chip_name, pci_name(pdev), pdev->irq, phymem1, phymem2,
1590 mem1, mem_region1_size, mem2, mem_region2_size);
1591 //log(L_ANY, "initial debug setting is 0x%04X\n", acx_debug);
1592 adev->chip_type = chip_type;
1593 adev->chip_name = chip_name;
1594 adev->io = (CHIPTYPE_ACX100 == chip_type) ? IO_ACX100 : IO_ACX111;
1595 adev->membase = phymem1;
1596 adev->iobase = mem1;
1597 adev->membase2 = phymem2;
1598 adev->iobase2 = mem2;
1599 adev->irq = pdev->irq;
1602 if (0 == pdev->irq) {
1603 acx_log(LOG_WARNING, L_ANY, "can't use IRQ 0\n");
1604 goto fail_irq;
1606 SET_IEEE80211_DEV(ieee, &pdev->dev);
1608 /* request shared IRQ handler */
1609 if (request_irq
1610 (adev->irq, acxpci_i_interrupt, IRQF_SHARED, KBUILD_MODNAME, adev)) {
1611 acx_log(LOG_WARNING, L_ANY, "%s: request_irq FAILED\n",
1612 wiphy_name(adev->ieee->wiphy));
1613 result = -EAGAIN;
1614 goto done;
1616 acx_log(LOG_DEBUG, L_IRQ | L_REALLYVERBOSE,
1617 "request_irq %d successful\n", adev->irq);
1619 /* to find crashes due to weird driver access
1620 * to unconfigured interface (ifup) */
1621 adev->mgmt_timer.function = (void (*)(unsigned long))0x0000dead;
1624 #ifdef NONESSENTIAL_FEATURES
1625 acx_show_card_eeprom_id(adev);
1626 #endif /* NONESSENTIAL_FEATURES */
1629 /* ok, pci setup is finished, now start initializing the card */
1631 /* NB: read_reg() reads may return bogus data before reset_dev(),
1632 * since the firmware which directly controls large parts of the I/O
1633 * registers isn't initialized yet.
1634 * acx100 seems to be more affected than acx111 */
1635 if (OK != acxpci_s_reset_dev(adev))
1636 goto fail_reset;
1638 if (IS_ACX100(adev)) {
1639 /* ACX100: configopt struct in cmd mailbox - directly after reset */
1640 memcpy_fromio(&co, adev->cmd_area, sizeof(co));
1643 if (OK != acx_s_init_mac(adev))
1644 goto fail_init_mac;
1646 if (IS_ACX111(adev)) {
1647 /* ACX111: configopt struct needs to be queried after full init */
1648 acx_s_interrogate(adev, &co, ACX111_IE_CONFIG_OPTIONS);
1650 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
1651 if (OK != acxpci_read_eeprom_byte(adev, 0x05, &adev->eeprom_version))
1652 goto fail_read_eeprom_version;
1654 acx_s_parse_configoption(adev, &co);
1655 acx_s_set_defaults(adev);
1656 acx_s_get_firmware_version(adev); /* needs to be after acx_s_init_mac() */
1657 acx_display_hardware_details(adev);
1659 /* Register the card, AFTER everything else has been set up,
1660 * since otherwise an ioctl could step on our feet due to
1661 * firmware operations happening in parallel or uninitialized data */
1664 acx_proc_register_entries(ieee);
1666 /* Now we have our device, so make sure the kernel doesn't try
1667 * to send packets even though we're not associated to a network yet */
1669 /* after register_netdev() userspace may start working with dev
1670 * (in particular, on other CPUs), we only need to up the sem */
1671 /* acx_sem_unlock(adev); */
1673 acx_log(LOG_INFO, L_ANY, "driver version " ACX_RELEASE
1674 ": net device %s, driver compiled "
1675 "against wireless extensions %d and Linux %s\n",
1676 wiphy_name(adev->ieee->wiphy), WIRELESS_EXT, UTS_RELEASE);
1678 MAC_COPY(adev->ieee->wiphy->perm_addr, adev->dev_addr);
1680 acx_log(LOG_INFO, L_IRQ | L_INIT, "using IRQ %d\n", pdev->irq);
1682 /** done with board specific setup **/
1684 /* need to be able to restore PCI state after a suspend */
1685 #ifdef CONFIG_PM
1686 pci_save_state(pdev);
1687 #endif
1689 err = acx_setup_modes(adev);
1690 if (err) {
1691 acx_log(LOG_WARNING, L_ANY, "can't register hwmode\n");
1692 goto fail_register_netdev;
1695 acx_init_task_scheduler(adev);
1696 err = ieee80211_register_hw(ieee);
1697 if (OK != err) {
1698 acx_log(LOG_WARNING, L_ANY,
1699 "ieee80211_register_hw() FAILED: %d\n", err);
1700 goto fail_register_netdev;
1702 #if CMD_DISCOVERY
1703 great_inquisitor(adev);
1704 #endif
1706 result = OK;
1707 goto done;
1709 /* error paths: undo everything in reverse order... */
1712 acxpci_s_delete_dma_regions(adev);
1713 pci_set_drvdata(pdev, NULL);
1715 fail_init_mac:
1716 fail_read_eeprom_version:
1717 fail_reset:
1719 fail_alloc_netdev:
1720 fail_irq:
1721 pci_iounmap(pdev, mem2);
1723 fail_ioremap2:
1724 pci_iounmap(pdev, mem1);
1726 fail_ioremap1:
1727 pci_release_region(pdev, mem_region2);
1729 fail_request_mem_region2:
1730 pci_release_region(pdev, mem_region1);
1732 fail_request_mem_region1:
1733 fail_unknown_chiptype:
1734 pci_disable_device(pdev);
1736 fail_pci_enable_device:
1737 #ifdef CONFIG_PM
1738 pci_set_power_state(pdev, PCI_D3hot);
1739 #endif
1741 fail_register_netdev:
1742 ieee80211_free_hw(ieee);
1743 done:
1744 FN_EXIT1(result);
1745 return result;
1749 /***********************************************************************
1750 ** acxpci_e_remove
1752 ** Shut device down (if not hot unplugged)
1753 ** and deallocate PCI resources for the acx chip.
1755 ** pdev - ptr to PCI device structure containing info about pci configuration
1757 static void __devexit acxpci_e_remove(struct pci_dev *pdev)
1759 struct ieee80211_hw *hw = (struct ieee80211_hw *)pci_get_drvdata(pdev);
1760 acx_device_t *adev = ieee2adev(hw);
1761 unsigned long mem_region1, mem_region2;
1762 unsigned long flags;
1763 FN_ENTER;
1765 if (!hw) {
1766 acx_log(LOG_DEBUG, L_REALLYVERBOSE,
1767 "%s: card is unused. Skipping any release code\n",
1768 __func__);
1769 goto end;
1772 /* If device wasn't hot unplugged... */
1773 if (adev_present(adev)) {
1775 /* disable both Tx and Rx to shut radio down properly */
1776 if (adev->initialized) {
1777 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_TX, NULL, 0);
1778 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_RX, NULL, 0);
1779 adev->initialized = 0;
1781 #ifdef REDUNDANT
1782 /* put the eCPU to sleep to save power
1783 * Halting is not possible currently,
1784 * since not supported by all firmware versions */
1785 acx_s_issue_cmd(adev, ACX100_CMD_SLEEP, NULL, 0);
1786 #endif
1787 acx_lock(adev, flags);
1788 /* disable power LED to save power :-) */
1789 acx_log(LOG_INFO, L_INIT,
1790 "switching off power LED to save power\n");
1791 acxpci_l_power_led(adev, 0);
1792 /* stop our eCPU */
1793 if (IS_ACX111(adev)) {
1794 /* FIXME: does this actually keep halting the eCPU?
1795 * I don't think so...
1797 acxpci_l_reset_mac(adev);
1798 } else {
1799 u16 temp;
1800 /* halt eCPU */
1801 temp = read_reg16(adev, ACX_IO_ECPU_CTRL) | 0x1;
1802 write_reg16(adev, ACX_IO_ECPU_CTRL, temp);
1803 write_flush(adev);
1805 acx_unlock(adev, flags);
1809 /* unregister the device to not let the kernel
1810 * (e.g. ioctls) access a half-deconfigured device
1811 * NB: this will cause acxpci_e_close() to be called,
1812 * thus we shouldn't call it under sem!
1813 * Well, netdev did, but ieee80211 stack does not, so we
1814 * have to do so manually...
1816 acxpci_e_close(hw);
1817 acx_log(LOG_INFO, L_INIT,
1818 "removing device %s\n", wiphy_name(adev->ieee->wiphy));
1819 ieee80211_unregister_hw(adev->ieee);
1821 /* unregister_netdev ensures that no references to us left.
1822 * For paranoid reasons we continue to follow the rules */
1823 acx_sem_lock(adev);
1825 if (adev->dev_state_mask & ACX_STATE_IFACE_UP) {
1826 acxpci_s_down(hw);
1827 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
1830 acx_proc_unregister_entries(adev->ieee);
1832 if (IS_ACX100(adev)) {
1833 mem_region1 = PCI_ACX100_REGION1;
1834 mem_region2 = PCI_ACX100_REGION2;
1835 } else {
1836 mem_region1 = PCI_ACX111_REGION1;
1837 mem_region2 = PCI_ACX111_REGION2;
1840 /* finally, clean up PCI bus state */
1841 acxpci_s_delete_dma_regions(adev);
1842 if (adev->iobase)
1843 iounmap(adev->iobase);
1844 if (adev->iobase2)
1845 iounmap(adev->iobase2);
1846 release_mem_region(pci_resource_start(pdev, mem_region1),
1847 pci_resource_len(pdev, mem_region1));
1848 release_mem_region(pci_resource_start(pdev, mem_region2),
1849 pci_resource_len(pdev, mem_region2));
1850 pci_disable_device(pdev);
1852 /* remove dev registration */
1853 pci_set_drvdata(pdev, NULL);
1855 acx_sem_unlock(adev);
1857 /* Free netdev (quite late,
1858 * since otherwise we might get caught off-guard
1859 * by a netdev timeout handler execution
1860 * expecting to see a working dev...) */
1861 ieee80211_free_hw(adev->ieee);
1863 /* put device into ACPI D3 mode (shutdown) */
1864 #ifdef CONFIG_PM
1865 pci_set_power_state(pdev, PCI_D3hot);
1866 #endif
1867 end:
1868 FN_EXIT0;
1872 /***********************************************************************
1873 ** TODO: PM code needs to be fixed / debugged / tested.
1875 #ifdef CONFIG_PM
1876 static int
1877 acxpci_e_suspend(struct pci_dev *pdev, pm_message_t state)
1879 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1880 acx_device_t *adev;
1882 FN_ENTER;
1883 acx_log(LOG_WARNING, L_ANY, "suspend handler is experimental!\n");
1884 acx_log(LOG_INFO, L_ANY, "suspend: dev %p\n", hw);
1886 /* if (!netif_running(ndev))
1887 goto end;
1889 adev = ieee2adev(hw);
1890 acx_log(LOG_INFO, L_ANY, "suspend: adev %p\n", adev);
1892 acx_sem_lock(adev);
1894 ieee80211_unregister_hw(hw); /* this one cannot sleep */
1895 acxpci_s_down(hw);
1896 /* down() does not set it to ACX_IRQ_ALL, but here we really want that */
1897 write_reg16(adev, ACX_IO_IRQ_MASK, ACX_IRQ_ALL);
1898 write_reg16(adev, ACX_IO_FEMR, 0x0);
1899 acxpci_s_delete_dma_regions(adev);
1900 pci_save_state(pdev);
1901 pci_set_power_state(pdev, PCI_D3hot);
1903 acx_sem_unlock(adev);
1904 FN_EXIT0;
1905 return OK;
1909 static int acxpci_e_resume(struct pci_dev *pdev)
1911 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1912 acx_device_t *adev;
1914 FN_ENTER;
1916 acx_log(LOG_WARNING, L_ANY, "resume handler is experimental!\n");
1917 acx_log(LOG_INFO, L_ANY, "resume: got dev %p\n", hw);
1920 adev = ieee2adev(hw);
1921 acx_log(LOG_INFO, L_ANY, "resume: got adev %p\n", adev);
1923 acx_sem_lock(adev);
1925 pci_set_power_state(pdev, PCI_D0);
1926 acx_log(LOG_INFO, L_ANY, "resume: power state PCI_D0 set\n");
1927 pci_restore_state(pdev);
1928 acx_log(LOG_INFO, L_ANY, "resume: PCI state restored\n");
1930 if (OK != acxpci_s_reset_dev(adev))
1931 goto end_unlock;
1932 acx_log(LOG_INFO, L_ANY, "resume: device reset done\n");
1933 if (OK != acx_s_init_mac(adev))
1934 goto end_unlock;
1935 acx_log(LOG_INFO, L_ANY, "resume: init MAC done\n");
1937 acxpci_s_up(hw);
1938 acx_log(LOG_INFO, L_ANY, "resume: acx up done\n");
1940 /* now even reload all card parameters as they were before suspend,
1941 * and possibly be back in the network again already :-) */
1942 if (ACX_STATE_IFACE_UP & adev->dev_state_mask) {
1943 adev->set_mask = GETSET_ALL;
1944 acx_s_update_card_settings(adev);
1945 acx_log(LOG_INFO, L_ANY, "resume: settings updated\n");
1947 ieee80211_register_hw(hw);
1948 acx_log(LOG_INFO, L_ANY, "resume: device attached\n");
1950 end_unlock:
1951 acx_sem_unlock(adev);
1952 /* we need to return OK here anyway, right? */
1953 FN_EXIT0;
1954 return OK;
1956 #endif /* CONFIG_PM */
1957 #endif /* CONFIG_PCI */
1959 /***********************************************************************
1960 ** acxpci_s_up
1962 ** This function is called by acxpci_e_open (when ifconfig sets the device as up)
1964 ** Side effects:
1965 ** - Enables on-card interrupt requests
1966 ** - calls acx_s_start
1969 static void enable_acx_irq(acx_device_t * adev)
1971 FN_ENTER;
1972 write_reg16(adev, ACX_IO_IRQ_MASK, adev->irq_mask);
1973 write_reg16(adev, ACX_IO_FEMR, 0x8000);
1974 adev->irqs_active = 1;
1975 FN_EXIT0;
1978 static void acxpci_s_up(struct ieee80211_hw *hw)
1980 acx_device_t *adev = ieee2adev(hw);
1981 unsigned long flags;
1983 FN_ENTER;
1985 acx_lock(adev, flags);
1986 enable_acx_irq(adev);
1987 acx_unlock(adev, flags);
1989 /* acx fw < 1.9.3.e has a hardware timer, and older drivers
1990 ** used to use it. But we don't do that anymore, our OS
1991 ** has reliable software timers */
1992 init_timer(&adev->mgmt_timer);
1993 adev->mgmt_timer.function = acx_i_timer;
1994 adev->mgmt_timer.data = (unsigned long)adev;
1996 /* Need to set ACX_STATE_IFACE_UP first, or else
1997 ** timer won't be started by acx_set_status() */
1998 SET_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
2000 acx_s_start(adev);
2002 FN_EXIT0;
2006 /***********************************************************************
2007 ** acxpci_s_down
2009 ** NB: device may be already hot unplugged if called from acxpci_e_remove()
2011 ** Disables on-card interrupt request, stops softirq and timer, stops queue,
2012 ** sets status == STOPPED
2015 static void disable_acx_irq(acx_device_t * adev)
2017 u16 disable_irq_mask = (IS_ACX111(adev)) ?
2018 ACX111_DISABLE_ALL_IRQS :
2019 ACX100_DISABLE_ALL_IRQS;
2021 FN_ENTER;
2023 /* I guess mask is not ACX_IRQ_ALL because acx100 won't signal
2024 ** cmd completion then (needed for ifup).
2025 ** I can't ifconfig up after ifconfig down'ing on my acx100 */
2026 write_reg16(adev, ACX_IO_IRQ_MASK, disable_irq_mask);
2027 write_reg16(adev, ACX_IO_FEMR, 0x0);
2028 adev->irqs_active = 0;
2030 FN_EXIT0;
2033 static void acxpci_s_down(struct ieee80211_hw *hw)
2035 acx_device_t *adev = ieee2adev(hw);
2037 FN_ENTER;
2039 /* Disable IRQs first, so that IRQs cannot race with us */
2040 /* then wait until interrupts have finished executing on other CPUs */
2041 disable_acx_irq(adev); /* NO sem-locking here? */
2042 synchronize_irq(adev->irq);
2044 /* we really don't want to have an asynchronous tasklet disturb us
2045 ** after something vital for its job has been shut down, so
2046 ** end all remaining work now.
2048 ** NB: carrier_off (done by set_status below) would lead to
2049 ** not yet fully understood deadlock in flush_scheduled_work().
2050 ** That's why we do FLUSH first.
2052 ** NB2: we have a bad locking bug here: flush_scheduled_work()
2053 ** waits for acx_e_after_interrupt_task to complete if it is running
2054 ** on another CPU, but acx_e_after_interrupt_task
2055 ** will sleep on sem forever, because it is taken by us!
2056 ** Work around that by temporary sem unlock.
2057 ** This will fail miserably if we'll be hit by concurrent
2058 ** iwconfig or something in between. TODO! */
2059 acx_sem_unlock(adev);
2060 flush_scheduled_work();
2061 acx_sem_lock(adev);
2063 /* This is possible:
2064 ** flush_scheduled_work -> acx_e_after_interrupt_task ->
2065 ** -> set_status(ASSOCIATED) -> wake_queue()
2066 ** That's why we stop queue _after_ flush_scheduled_work
2067 ** lock/unlock is just paranoia, maybe not needed */
2069 /* kernel/timer.c says it's illegal to del_timer_sync()
2070 ** a timer which restarts itself. We guarantee this cannot
2071 ** ever happen because acx_i_timer() never does this if
2072 ** status is ACX_STATUS_0_STOPPED */
2073 del_timer_sync(&adev->mgmt_timer);
2075 FN_EXIT0;
2078 #ifdef CONFIG_NET_POLL_CONTROLLER
2079 void acxpci_net_poll_controller(struct net_device *net_dev)
2081 acx_device_t *adev = ndev2adev(net_dev);
2082 unsigned long flags;
2084 local_irq_save(flags);
2085 acxpci_i_interrupt(adev->irq, adev);
2086 local_irq_restore(flags);
2088 #endif*/ /* CONFIG_NET_POLL_CONTROLLER */
2090 /***********************************************************************
2091 ** acxpci_e_open
2093 ** Called as a result of SIOCSIFFLAGS ioctl changing the flags bit IFF_UP
2094 ** from clear to set. In other words: ifconfig up.
2096 ** Returns:
2097 ** 0 success
2098 ** >0 f/w reported error
2099 ** <0 driver reported error
2101 static int acxpci_e_open(struct ieee80211_hw *hw)
2103 acx_device_t *adev = ieee2adev(hw);
2104 int result = OK;
2106 FN_ENTER;
2108 acx_sem_lock(adev);
2110 adev->initialized = 0;
2112 /* TODO: pci_set_power_state(pdev, PCI_D0); ? */
2114 /* ifup device */
2115 acxpci_s_up(hw);
2117 /* We don't currently have to do anything else.
2118 * The setup of the MAC should be subsequently completed via
2119 * the mlme commands.
2120 * Higher layers know we're ready from dev->start==1 and
2121 * dev->tbusy==0. Our rx path knows to pass up received/
2122 * frames because of dev->flags&IFF_UP is true.
2124 ieee80211_start_queues(adev->ieee);
2126 adev->initialized = 1;
2127 acx_sem_unlock(adev);
2129 FN_EXIT1(result);
2130 return result;
2134 /***********************************************************************
2135 ** acxpci_e_close
2137 ** This function stops the network functionality of the interface (invoked
2138 ** when the user calls ifconfig <wlan> down). The tx queue is halted and
2139 ** the device is marked as down.
2141 ** Called as a result of SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
2142 ** from set to clear. I.e. called by "ifconfig DEV down"
2144 ** Returns:
2145 ** 0 success
2146 ** >0 f/w reported error
2147 ** <0 driver reported error
2149 static void acxpci_e_close(struct ieee80211_hw *hw)
2151 acx_device_t *adev = ieee2adev(hw);
2153 FN_ENTER;
2155 acx_sem_lock(adev);
2157 /* ifdown device */
2158 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
2159 if (adev->initialized) {
2160 acxpci_s_down(hw);
2163 if (adev->modes)
2164 acx_free_modes(adev);
2165 /* disable all IRQs, release shared IRQ handler */
2166 write_reg16(adev, ACX_IO_IRQ_MASK, ACX_IRQ_ALL);
2167 write_reg16(adev, ACX_IO_FEMR, 0x0);
2168 free_irq(adev->irq, adev);
2170 /* TODO: pci_set_power_state(pdev, PCI_D3hot); ? */
2172 /* We currently don't have to do anything else.
2173 * Higher layers know we're not ready from dev->start==0 and
2174 * dev->tbusy==1. Our rx path knows to not pass up received
2175 * frames because of dev->flags&IFF_UP is false.
2177 acx_sem_unlock(adev);
2179 acx_log(LOG_INFO, L_INIT, "closed device\n");
2180 FN_EXIT0;
2186 /***************************************************************
2187 ** acxpci_l_process_rxdesc
2189 ** Called directly and only from the IRQ handler
2192 #if !ACX_DEBUG
2193 static inline void log_rxbuffer(const acx_device_t * adev)
2196 #else
2197 static void log_rxbuffer(const acx_device_t * adev)
2199 register const struct rxhostdesc *rxhostdesc;
2200 int i;
2202 /* no FN_ENTER here, we don't want that */
2204 rxhostdesc = adev->rxhostdesc_start;
2205 if (unlikely(!rxhostdesc))
2206 return;
2207 for (i = 0; i < RX_CNT; i++) {
2208 if ((rxhostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2209 && (rxhostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2210 acx_log(LOG_WARNING, L_ANY, "rx: buf %d full\n", i);
2211 rxhostdesc++;
2214 #endif
2216 static void acxpci_l_process_rxdesc(acx_device_t * adev)
2218 register rxhostdesc_t *hostdesc;
2219 unsigned count, tail;
2221 FN_ENTER;
2223 if (unlikely(acx_debug & L_BUFR))
2224 log_rxbuffer(adev);
2226 /* First, have a loop to determine the first descriptor that's
2227 * full, just in case there's a mismatch between our current
2228 * rx_tail and the full descriptor we're supposed to handle. */
2229 tail = adev->rx_tail;
2230 count = RX_CNT;
2231 while (1) {
2232 hostdesc = &adev->rxhostdesc_start[tail];
2233 /* advance tail regardless of outcome of the below test */
2234 tail = (tail + 1) % RX_CNT;
2236 if ((hostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2237 && (hostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2238 break; /* found it! */
2240 if (unlikely(!--count)) /* hmm, no luck: all descs empty, bail out */
2241 goto end;
2244 /* now process descriptors, starting with the first we figured out */
2245 while (1) {
2246 acx_log(LOG_DEBUG, L_BUFR,
2247 "rx: tail=%u Ctl_16=%04X Status=%08X\n",
2248 tail, hostdesc->Ctl_16, hostdesc->Status);
2250 acx_l_process_rxbuf(adev, hostdesc->data);
2251 hostdesc->Status = 0;
2252 /* flush all writes before adapter sees CTL_HOSTOWN change */
2253 wmb();
2254 /* Host no longer owns this, needs to be LAST */
2255 CLEAR_BIT(hostdesc->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
2257 /* ok, descriptor is handled, now check the next descriptor */
2258 hostdesc = &adev->rxhostdesc_start[tail];
2260 /* if next descriptor is empty, then bail out */
2261 if (!(hostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2262 || !(hostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2263 break;
2265 tail = (tail + 1) % RX_CNT;
2267 end:
2268 adev->rx_tail = tail;
2269 FN_EXIT0;
2274 /***********************************************************************
2275 ** acxpci_i_interrupt
2277 ** IRQ handler (atomic context, must not sleep, blah, blah)
2280 /* scan is complete. all frames now on the receive queue are valid */
2281 #define INFO_SCAN_COMPLETE 0x0001
2282 #define INFO_WEP_KEY_NOT_FOUND 0x0002
2283 /* hw has been reset as the result of a watchdog timer timeout */
2284 #define INFO_WATCH_DOG_RESET 0x0003
2285 /* failed to send out NULL frame from PS mode notification to AP */
2286 /* recommended action: try entering 802.11 PS mode again */
2287 #define INFO_PS_FAIL 0x0004
2288 /* encryption/decryption process on a packet failed */
2289 #define INFO_IV_ICV_FAILURE 0x0005
2291 /* Info mailbox format:
2292 2 bytes: type
2293 2 bytes: status
2294 more bytes may follow
2295 rumors say about status:
2296 0x0000 info available (set by hw)
2297 0x0001 information received (must be set by host)
2298 0x1000 info available, mailbox overflowed (messages lost) (set by hw)
2299 but in practice we've seen:
2300 0x9000 when we did not set status to 0x0001 on prev message
2301 0x1001 when we did set it
2302 0x0000 was never seen
2303 conclusion: this is really a bitfield:
2304 0x1000 is 'info available' bit
2305 'mailbox overflowed' bit is 0x8000, not 0x1000
2306 value of 0x0000 probably means that there are no messages at all
2307 P.S. I dunno how in hell hw is supposed to notice that messages are lost -
2308 it does NOT clear bit 0x0001, and this bit will probably stay forever set
2309 after we set it once. Let's hope this will be fixed in firmware someday
2312 static void handle_info_irq(acx_device_t * adev)
2314 #if ACX_DEBUG
2315 static const char *const info_type_msg[] = {
2316 "(unknown)",
2317 "scan complete",
2318 "WEP key not found",
2319 "internal watchdog reset was done",
2320 "failed to send powersave (NULL frame) notification to AP",
2321 "encrypt/decrypt on a packet has failed",
2322 "TKIP tx keys disabled",
2323 "TKIP rx keys disabled",
2324 "TKIP rx: key ID not found",
2325 "???",
2326 "???",
2327 "???",
2328 "???",
2329 "???",
2330 "???",
2331 "???",
2332 "TKIP IV value exceeds thresh"
2334 #endif
2335 u32 info_type, info_status;
2337 info_type = acx_readl(adev->info_area);
2338 info_status = (info_type >> 16);
2339 info_type = (u16) info_type;
2341 /* inform fw that we have read this info message */
2342 acx_writel(info_type | 0x00010000, adev->info_area);
2343 write_reg16(adev, ACX_IO_INT_TRIG, INT_TRIG_INFOACK);
2344 write_flush(adev);
2346 acx_log(LOG_DEBUG, L_CTL,
2347 "info_type:%04X info_status:%04X\n", info_type, info_status);
2349 acx_log(LOG_DEBUG, L_IRQ, "got Info IRQ: status %04X type %04X: %s\n",
2350 info_status, info_type,
2351 info_type_msg[(info_type >= ARRAY_SIZE(info_type_msg)) ?
2352 0 : info_type]
2357 static void log_unusual_irq(u16 irqtype)
2360 if (!printk_ratelimit())
2361 return;
2364 printk("acx: got");
2365 if (irqtype & ACX_IRQ_RX_DATA) {
2366 printk(" Rx_Data");
2368 /* ACX_IRQ_TX_COMPLETE */
2369 if (irqtype & ACX_IRQ_TX_XFER) {
2370 printk(" Tx_Xfer");
2372 /* ACX_IRQ_RX_COMPLETE */
2373 if (irqtype & ACX_IRQ_DTIM) {
2374 printk(" DTIM");
2376 if (irqtype & ACX_IRQ_BEACON) {
2377 printk(" Beacon");
2379 if (irqtype & ACX_IRQ_TIMER) {
2380 printk(" Timer");
2382 if (irqtype & ACX_IRQ_KEY_NOT_FOUND) {
2383 printk(" Key_Not_Found");
2385 if (irqtype & ACX_IRQ_IV_ICV_FAILURE) {
2386 printk(" IV_ICV_Failure (crypto)");
2388 /* ACX_IRQ_CMD_COMPLETE */
2389 /* ACX_IRQ_INFO */
2390 if (irqtype & ACX_IRQ_OVERFLOW) {
2391 printk(" Overflow");
2393 if (irqtype & ACX_IRQ_PROCESS_ERROR) {
2394 printk(" Process_Error");
2396 /* ACX_IRQ_SCAN_COMPLETE */
2397 if (irqtype & ACX_IRQ_FCS_THRESHOLD) {
2398 printk(" FCS_Threshold");
2400 if (irqtype & ACX_IRQ_UNKNOWN) {
2401 printk(" Unknown");
2403 printk(" IRQ(s)\n");
2406 /* FIXME: update_link_quality_led was a stub - let's comment it and avoid
2407 * compiler warnings */
2409 static void update_link_quality_led(acx_device_t * adev)
2411 int qual;
2413 qual =
2414 acx_signal_determine_quality(adev->wstats.qual.level,
2415 adev->wstats.qual.noise);
2416 if (qual > adev->brange_max_quality)
2417 qual = adev->brange_max_quality;
2419 if (time_after(jiffies, adev->brange_time_last_state_change +
2420 (HZ / 2 -
2421 HZ / 2 * (unsigned long)qual /
2422 adev->brange_max_quality))) {
2423 acxpci_l_power_led(adev, (adev->brange_last_state == 0));
2424 adev->brange_last_state ^= 1; // toggle
2425 adev->brange_time_last_state_change = jiffies;
2430 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* a la orinoco.c */
2432 /* Interrupt handler bottom-half */
2433 void acx_interrupt_tasklet(struct work_struct *work)
2436 #ifdef CONFIG_ACX_MAC80211_DEBUG
2437 u32 _handled = 0x00000000;
2438 # define acxirq_handled(irq) do { _handled |= (irq); } while (0)
2439 #else
2440 # define acxirq_handled(irq) do { /* nothing */ } while (0)
2441 #endif /* CONFIG_ACX_MAC80211_DEBUG */
2442 acx_device_t *adev = container_of(work,struct acx_device, after_interrupt_task);
2443 // unsigned int irqcount = MAX_IRQLOOPS_PER_JIFFY;
2444 int irqtype;
2446 #define IRQ_ITERATE 0
2447 #if IRQ_ITERATE
2448 unsigned int irqcount = MAX_IRQLOOPS_PER_JIFFY;
2449 u16 unmasked;
2450 #endif
2452 FN_ENTER;
2454 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2455 * I am paranoid */
2456 acx_sem_lock(adev);
2458 irqtype = adev->irq_reason;
2459 adev->irq_reason = 0;
2461 #if IRQ_ITERATE
2462 if (jiffies != adev->irq_last_jiffies) {
2463 adev->irq_loops_this_jiffy = 0;
2464 adev->irq_last_jiffies = jiffies;
2467 /* safety condition; we'll normally abort loop below
2468 * in case no IRQ type occurred */
2469 while (likely(--irqcount)) {
2470 #endif
2471 /* ACK all IRQs ASAP */
2473 /* Handle most important IRQ types first */
2474 if (irqtype & ACX_IRQ_RX_COMPLETE) {
2475 acx_log(LOG_DEBUG, L_IRQ, "got Rx_Complete IRQ\n");
2476 acxpci_l_process_rxdesc(adev);
2478 if (irqtype & ACX_IRQ_TX_COMPLETE) {
2479 acx_log(LOG_DEBUG, L_IRQ, "got Tx_Complete IRQ\n");
2480 /* don't clean up on each Tx complete, wait a bit
2481 * unless we're going towards full, in which case
2482 * we do it immediately, too (otherwise we might lockup
2483 * with a full Tx buffer if we go into
2484 * acxpci_l_clean_txdesc() at a time when we won't wakeup
2485 * the net queue in there for some reason...) */
2486 // if (adev->tx_free <= TX_START_CLEAN) {
2487 acxpci_l_clean_txdesc(adev);
2488 // }
2491 /* Less frequent ones */
2492 if (irqtype & (0
2493 | ACX_IRQ_CMD_COMPLETE
2494 | ACX_IRQ_INFO | ACX_IRQ_SCAN_COMPLETE)) {
2495 if (irqtype & ACX_IRQ_INFO) {
2496 handle_info_irq(adev);
2498 if (irqtype & ACX_IRQ_SCAN_COMPLETE) {
2499 acx_log(LOG_DEBUG, L_IRQ,
2500 "got Scan_Complete IRQ\n");
2501 /* need to do that in process context */
2502 /* remember that fw is not scanning anymore */
2503 SET_BIT(adev->irq_status,
2504 ACX_IRQ_SCAN_COMPLETE);
2508 /* These we just log, but either they happen rarely
2509 * or we keep them masked out */
2510 if (irqtype & (0 | ACX_IRQ_RX_DATA
2511 /* | ACX_IRQ_TX_COMPLETE */
2512 | ACX_IRQ_TX_XFER
2513 /* | ACX_IRQ_RX_COMPLETE */
2514 | ACX_IRQ_DTIM
2515 | ACX_IRQ_BEACON
2516 | ACX_IRQ_TIMER
2517 | ACX_IRQ_KEY_NOT_FOUND
2518 | ACX_IRQ_IV_ICV_FAILURE
2519 /* | ACX_IRQ_CMD_COMPLETE */
2520 /* | ACX_IRQ_INFO */
2521 | ACX_IRQ_OVERFLOW
2522 | ACX_IRQ_PROCESS_ERROR
2523 /* | ACX_IRQ_SCAN_COMPLETE */
2524 | ACX_IRQ_FCS_THRESHOLD
2525 | ACX_IRQ_UNKNOWN)) {
2526 log_unusual_irq(irqtype);
2528 #if IRQ_ITERATE
2529 unmasked = read_reg16(adev, ACX_IO_IRQ_REASON);
2530 irqtype = unmasked & ~adev->irq_mask;
2531 /* Bail out if no new IRQ bits or if all are masked out */
2532 if (!irqtype)
2533 break;
2535 if (unlikely
2536 (++adev->irq_loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY)) {
2537 acx_log(LOG_WARNING, L_ANY,
2538 "too many interrupts per jiffy!\n");
2539 /* Looks like card floods us with IRQs! Try to stop that */
2540 write_reg16(adev, ACX_IO_IRQ_MASK, ACX_IRQ_ALL);
2541 /* This will short-circuit all future attempts to handle IRQ.
2542 * We cant do much more... */
2543 adev->irq_mask = 0;
2544 break;
2547 #endif
2548 /* Routine to perform blink with range
2549 * FIXME: update_link_quality_led is a stub - add proper code and enable this again:
2550 if (unlikely(adev->led_power == 2))
2551 update_link_quality_led(adev);
2554 /* write_flush(adev); - not needed, last op was read anyway */
2555 acx_sem_unlock(adev);
2557 /* handled: */
2558 if (adev->after_interrupt_jobs)
2559 acx_e_after_interrupt_task(&adev->after_interrupt_task);
2561 FN_EXIT0;
2562 return;
2567 static irqreturn_t acxpci_i_interrupt(int irq, void *dev_id)
2569 acx_device_t *adev = dev_id;
2570 unsigned long flags;
2571 register u16 irqtype;
2572 u16 unmasked;
2574 FN_ENTER;
2576 if (!adev)
2577 return IRQ_NONE;
2579 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2580 * I am paranoid */
2582 acx_lock(adev, flags);
2584 unmasked = read_reg16(adev, ACX_IO_IRQ_REASON);
2585 if (unlikely(unmasked == ACX_IRQ_ALL)) {
2586 /* ACX_IRQ_ALL value hints at missing hardware,
2587 * so don't do anything.
2588 * Not very clean, but other drivers do the same... */
2589 acx_log(LOG_WARNING, L_IRQ,
2590 "IRQ type:FFFF (ALL) - device removed? IRQ_NONE\n");
2591 goto none;
2594 /* We will check only "interesting" IRQ types */
2595 irqtype = unmasked & ~adev->irq_mask;
2596 if (!irqtype) {
2597 /* We are on a shared IRQ line and it wasn't our IRQ */
2598 acx_log(LOG_DEBUG, L_IRQ,
2599 "IRQ type:%04X, mask:%04X - all are masked, IRQ_NONE\n",
2600 unmasked, adev->irq_mask);
2601 goto none;
2604 /* Go ahead and ACK our interrupt */
2605 write_reg16(adev, ACX_IO_IRQ_ACK, ACX_IRQ_ALL);
2606 if (irqtype & ACX_IRQ_CMD_COMPLETE) {
2607 acx_log(LOG_DEBUG, L_IRQ, "got Command_Complete IRQ\n");
2608 /* save the state for the running issue_cmd() */
2609 SET_BIT(adev->irq_status, ACX_IRQ_CMD_COMPLETE);
2612 /* Only accept IRQs, if we are initialized properly.
2613 * This avoids an RX race while initializing.
2614 * We should probably not enable IRQs before we are initialized
2615 * completely, but some careful work is needed to fix this. I think it
2616 * is best to stay with this cheap workaround for now... .
2618 if (likely(adev->initialized)) {
2619 /* disable all IRQs. They are enabled again in the bottom half. */
2620 /* save the reason code and call our bottom half. */
2621 adev->irq_reason = irqtype;
2623 if ((irqtype & ACX_IRQ_RX_COMPLETE) || (irqtype & ACX_IRQ_TX_COMPLETE))
2624 acx_schedule_task(adev, 0);
2627 acx_unlock(adev, flags);
2628 FN_EXIT0;
2629 return IRQ_HANDLED;
2630 none:
2631 acx_unlock(adev, flags);
2632 FN_EXIT0;
2633 return IRQ_NONE;
2638 /***********************************************************************
2639 ** acxpci_l_power_led
2641 void acxpci_l_power_led(acx_device_t * adev, int enable)
2643 u16 gpio_pled = IS_ACX111(adev) ? 0x0040 : 0x0800;
2645 /* A hack. Not moving message rate limiting to adev->xxx
2646 * (it's only a debug message after all) */
2647 static int rate_limit = 0;
2649 if (rate_limit++ < 3)
2650 acx_log(LOG_INFO, L_IOCTL,
2651 "Please report in case toggling the power LED "
2652 "doesn't work for your card!\n");
2653 if (enable)
2654 write_reg16(adev, ACX_IO_GPIO_OUT,
2655 read_reg16(adev, ACX_IO_GPIO_OUT) & ~gpio_pled);
2656 else
2657 write_reg16(adev, ACX_IO_GPIO_OUT,
2658 read_reg16(adev, ACX_IO_GPIO_OUT) | gpio_pled);
2662 /***********************************************************************
2663 ** Ioctls
2666 /***********************************************************************
2668 #if 0
2670 acx111pci_ioctl_info(struct net_device *ndev,
2671 struct iw_request_info *info,
2672 struct iw_param *vwrq, char *extra)
2674 #if ACX_DEBUG > 1
2675 acx_device_t *adev = ndev2adev(ndev);
2676 rxdesc_t *rxdesc;
2677 txdesc_t *txdesc;
2678 rxhostdesc_t *rxhostdesc;
2679 txhostdesc_t *txhostdesc;
2680 struct acx111_ie_memoryconfig memconf;
2681 struct acx111_ie_queueconfig queueconf;
2682 unsigned long flags;
2683 int i;
2684 char memmap[0x34];
2685 char rxconfig[0x8];
2686 char fcserror[0x8];
2687 char ratefallback[0x5];
2689 if (!(acx_debug & (L_IOCTL | L_DEBUG)))
2690 return OK;
2691 /* using printk() since we checked debug flag already */
2693 acx_sem_lock(adev);
2695 if (!IS_ACX111(adev)) {
2696 printk("acx111-specific function called "
2697 "with non-acx111 chip, aborting\n");
2698 goto end_ok;
2701 /* get Acx111 Memory Configuration */
2702 memset(&memconf, 0, sizeof(memconf));
2703 /* BTW, fails with 12 (Write only) error code.
2704 ** Retained for easy testing of issue_cmd error handling :) */
2705 acx_s_interrogate(adev, &memconf, ACX1xx_IE_QUEUE_CONFIG);
2707 /* get Acx111 Queue Configuration */
2708 memset(&queueconf, 0, sizeof(queueconf));
2709 acx_s_interrogate(adev, &queueconf, ACX1xx_IE_MEMORY_CONFIG_OPTIONS);
2711 /* get Acx111 Memory Map */
2712 memset(memmap, 0, sizeof(memmap));
2713 acx_s_interrogate(adev, &memmap, ACX1xx_IE_MEMORY_MAP);
2715 /* get Acx111 Rx Config */
2716 memset(rxconfig, 0, sizeof(rxconfig));
2717 acx_s_interrogate(adev, &rxconfig, ACX1xx_IE_RXCONFIG);
2719 /* get Acx111 fcs error count */
2720 memset(fcserror, 0, sizeof(fcserror));
2721 acx_s_interrogate(adev, &fcserror, ACX1xx_IE_FCS_ERROR_COUNT);
2723 /* get Acx111 rate fallback */
2724 memset(ratefallback, 0, sizeof(ratefallback));
2725 acx_s_interrogate(adev, &ratefallback, ACX1xx_IE_RATE_FALLBACK);
2727 /* force occurrence of a beacon interrupt */
2728 /* TODO: comment why is this necessary */
2729 write_reg16(adev, ACX_IO_HINT_TRIG, ACX_IRQ_BEACON);
2731 /* dump Acx111 Mem Configuration */
2732 printk("dump mem config:\n"
2733 "data read: %d, struct size: %d\n"
2734 "Number of stations: %1X\n"
2735 "Memory block size: %1X\n"
2736 "tx/rx memory block allocation: %1X\n"
2737 "count rx: %X / tx: %X queues\n"
2738 "options %1X\n"
2739 "fragmentation %1X\n"
2740 "Rx Queue 1 Count Descriptors: %X\n"
2741 "Rx Queue 1 Host Memory Start: %X\n"
2742 "Tx Queue 1 Count Descriptors: %X\n"
2743 "Tx Queue 1 Attributes: %X\n",
2744 memconf.len, (int)sizeof(memconf),
2745 memconf.no_of_stations,
2746 memconf.memory_block_size,
2747 memconf.tx_rx_memory_block_allocation,
2748 memconf.count_rx_queues, memconf.count_tx_queues,
2749 memconf.options,
2750 memconf.fragmentation,
2751 memconf.rx_queue1_count_descs,
2752 acx2cpu(memconf.rx_queue1_host_rx_start),
2753 memconf.tx_queue1_count_descs, memconf.tx_queue1_attributes);
2755 /* dump Acx111 Queue Configuration */
2756 printk("dump queue head:\n"
2757 "data read: %d, struct size: %d\n"
2758 "tx_memory_block_address (from card): %X\n"
2759 "rx_memory_block_address (from card): %X\n"
2760 "rx1_queue address (from card): %X\n"
2761 "tx1_queue address (from card): %X\n"
2762 "tx1_queue attributes (from card): %X\n",
2763 queueconf.len, (int)sizeof(queueconf),
2764 queueconf.tx_memory_block_address,
2765 queueconf.rx_memory_block_address,
2766 queueconf.rx1_queue_address,
2767 queueconf.tx1_queue_address, queueconf.tx1_attributes);
2769 /* dump Acx111 Mem Map */
2770 printk("dump mem map:\n"
2771 "data read: %d, struct size: %d\n"
2772 "Code start: %X\n"
2773 "Code end: %X\n"
2774 "WEP default key start: %X\n"
2775 "WEP default key end: %X\n"
2776 "STA table start: %X\n"
2777 "STA table end: %X\n"
2778 "Packet template start: %X\n"
2779 "Packet template end: %X\n"
2780 "Queue memory start: %X\n"
2781 "Queue memory end: %X\n"
2782 "Packet memory pool start: %X\n"
2783 "Packet memory pool end: %X\n"
2784 "iobase: %p\n"
2785 "iobase2: %p\n",
2786 *((u16 *) & memmap[0x02]), (int)sizeof(memmap),
2787 *((u32 *) & memmap[0x04]),
2788 *((u32 *) & memmap[0x08]),
2789 *((u32 *) & memmap[0x0C]),
2790 *((u32 *) & memmap[0x10]),
2791 *((u32 *) & memmap[0x14]),
2792 *((u32 *) & memmap[0x18]),
2793 *((u32 *) & memmap[0x1C]),
2794 *((u32 *) & memmap[0x20]),
2795 *((u32 *) & memmap[0x24]),
2796 *((u32 *) & memmap[0x28]),
2797 *((u32 *) & memmap[0x2C]),
2798 *((u32 *) & memmap[0x30]), adev->iobase, adev->iobase2);
2800 /* dump Acx111 Rx Config */
2801 printk("dump rx config:\n"
2802 "data read: %d, struct size: %d\n"
2803 "rx config: %X\n"
2804 "rx filter config: %X\n",
2805 *((u16 *) & rxconfig[0x02]), (int)sizeof(rxconfig),
2806 *((u16 *) & rxconfig[0x04]), *((u16 *) & rxconfig[0x06]));
2808 /* dump Acx111 fcs error */
2809 printk("dump fcserror:\n"
2810 "data read: %d, struct size: %d\n"
2811 "fcserrors: %X\n",
2812 *((u16 *) & fcserror[0x02]), (int)sizeof(fcserror),
2813 *((u32 *) & fcserror[0x04]));
2815 /* dump Acx111 rate fallback */
2816 printk("dump rate fallback:\n"
2817 "data read: %d, struct size: %d\n"
2818 "ratefallback: %X\n",
2819 *((u16 *) & ratefallback[0x02]), (int)sizeof(ratefallback),
2820 *((u8 *) & ratefallback[0x04]));
2822 /* protect against IRQ */
2823 acx_lock(adev, flags);
2825 /* dump acx111 internal rx descriptor ring buffer */
2826 rxdesc = adev->rxdesc_start;
2828 /* loop over complete receive pool */
2829 if (rxdesc)
2830 for (i = 0; i < RX_CNT; i++) {
2831 printk("\ndump internal rxdesc %d:\n"
2832 "mem pos %p\n"
2833 "next 0x%X\n"
2834 "acx mem pointer (dynamic) 0x%X\n"
2835 "CTL (dynamic) 0x%X\n"
2836 "Rate (dynamic) 0x%X\n"
2837 "RxStatus (dynamic) 0x%X\n"
2838 "Mod/Pre (dynamic) 0x%X\n",
2840 rxdesc,
2841 acx2cpu(rxdesc->pNextDesc),
2842 acx2cpu(rxdesc->ACXMemPtr),
2843 rxdesc->Ctl_8,
2844 rxdesc->rate, rxdesc->error, rxdesc->SNR);
2845 rxdesc++;
2848 /* dump host rx descriptor ring buffer */
2850 rxhostdesc = adev->rxhostdesc_start;
2852 /* loop over complete receive pool */
2853 if (rxhostdesc)
2854 for (i = 0; i < RX_CNT; i++) {
2855 printk("\ndump host rxdesc %d:\n"
2856 "mem pos %p\n"
2857 "buffer mem pos 0x%X\n"
2858 "buffer mem offset 0x%X\n"
2859 "CTL 0x%X\n"
2860 "Length 0x%X\n"
2861 "next 0x%X\n"
2862 "Status 0x%X\n",
2864 rxhostdesc,
2865 acx2cpu(rxhostdesc->data_phy),
2866 rxhostdesc->data_offset,
2867 le16_to_cpu(rxhostdesc->Ctl_16),
2868 le16_to_cpu(rxhostdesc->length),
2869 acx2cpu(rxhostdesc->desc_phy_next),
2870 rxhostdesc->Status);
2871 rxhostdesc++;
2874 /* dump acx111 internal tx descriptor ring buffer */
2875 txdesc = adev->txdesc_start;
2877 /* loop over complete transmit pool */
2878 if (txdesc)
2879 for (i = 0; i < TX_CNT; i++) {
2880 printk("\ndump internal txdesc %d:\n"
2881 "size 0x%X\n"
2882 "mem pos %p\n"
2883 "next 0x%X\n"
2884 "acx mem pointer (dynamic) 0x%X\n"
2885 "host mem pointer (dynamic) 0x%X\n"
2886 "length (dynamic) 0x%X\n"
2887 "CTL (dynamic) 0x%X\n"
2888 "CTL2 (dynamic) 0x%X\n"
2889 "Status (dynamic) 0x%X\n"
2890 "Rate (dynamic) 0x%X\n",
2892 (int)sizeof(struct txdesc),
2893 txdesc,
2894 acx2cpu(txdesc->pNextDesc),
2895 acx2cpu(txdesc->AcxMemPtr),
2896 acx2cpu(txdesc->HostMemPtr),
2897 le16_to_cpu(txdesc->total_length),
2898 txdesc->Ctl_8,
2899 txdesc->Ctl2_8, txdesc->error,
2900 txdesc->u.r1.rate);
2901 txdesc = advance_txdesc(adev, txdesc, 1);
2904 /* dump host tx descriptor ring buffer */
2906 txhostdesc = adev->txhostdesc_start;
2908 /* loop over complete host send pool */
2909 if (txhostdesc)
2910 for (i = 0; i < TX_CNT * 2; i++) {
2911 printk("\ndump host txdesc %d:\n"
2912 "mem pos %p\n"
2913 "buffer mem pos 0x%X\n"
2914 "buffer mem offset 0x%X\n"
2915 "CTL 0x%X\n"
2916 "Length 0x%X\n"
2917 "next 0x%X\n"
2918 "Status 0x%X\n",
2920 txhostdesc,
2921 acx2cpu(txhostdesc->data_phy),
2922 txhostdesc->data_offset,
2923 le16_to_cpu(txhostdesc->Ctl_16),
2924 le16_to_cpu(txhostdesc->length),
2925 acx2cpu(txhostdesc->desc_phy_next),
2926 le32_to_cpu(txhostdesc->Status));
2927 txhostdesc++;
2930 /* write_reg16(adev, 0xb4, 0x4); */
2932 acx_unlock(adev, flags);
2933 end_ok:
2935 acx_sem_unlock(adev);
2936 #endif /* ACX_DEBUG */
2937 return OK;
2941 /***********************************************************************
2944 acx100pci_ioctl_set_phy_amp_bias(struct net_device *ndev,
2945 struct iw_request_info *info,
2946 struct iw_param *vwrq, char *extra)
2948 acx_device_t *adev = ndev2adev(ndev);
2949 unsigned long flags;
2950 u16 gpio_old;
2952 if (!IS_ACX100(adev)) {
2953 /* WARNING!!!
2954 * Removing this check *might* damage
2955 * hardware, since we're tweaking GPIOs here after all!!!
2956 * You've been warned...
2957 * WARNING!!! */
2958 acx_log(LOG_INFO, L_ANY,
2959 "sorry, setting bias level for non-acx100 "
2960 "is not supported yet\n");
2961 return OK;
2964 if (*extra > 7) {
2965 acx_log(LOG_INFO, L_ANY,
2966 "invalid bias parameter, range is 0-7\n");
2967 return -EINVAL;
2970 acx_sem_lock(adev);
2972 /* Need to lock accesses to [ACX_IO_GPIO_OUT]:
2973 * IRQ handler uses it to update LED */
2974 acx_lock(adev, flags);
2975 gpio_old = read_reg16(adev, ACX_IO_GPIO_OUT);
2976 write_reg16(adev, ACX_IO_GPIO_OUT,
2977 (gpio_old & 0xf8ff) | ((u16) * extra << 8));
2978 acx_unlock(adev, flags);
2980 acx_log(LOG_DEBUG, L_REALLYVERBOSE, "gpio_old: 0x%04X\n", gpio_old);
2981 acx_log(LOG_INFO, L_ANY,
2982 "%s: PHY power amplifier bias: old:%d, new:%d\n",
2983 ndev->name, (gpio_old & 0x0700) >> 8, (unsigned char)*extra);
2985 acx_sem_unlock(adev);
2987 return OK;
2989 #endif
2991 /***************************************************************
2992 ** acxpci_l_alloc_tx
2993 ** Actually returns a txdesc_t* ptr
2995 ** FIXME: in case of fragments, should allocate multiple descrs
2996 ** after figuring out how many we need and whether we still have
2997 ** sufficiently many.
2999 tx_t *acxpci_l_alloc_tx(acx_device_t * adev)
3001 struct txdesc *txdesc;
3002 unsigned head;
3003 u8 ctl8;
3005 FN_ENTER;
3007 if (unlikely(!adev->tx_free)) {
3008 acx_log(LOG_WARNING, L_ANY, "BUG: no free txdesc left\n");
3009 txdesc = NULL;
3010 goto end;
3013 head = adev->tx_head;
3014 txdesc = get_txdesc(adev, head);
3015 ctl8 = txdesc->Ctl_8;
3017 /* 2005-10-11: there were several bug reports on this happening
3018 ** but now cause seems to be understood & fixed */
3019 if (unlikely(DESC_CTL_HOSTOWN != (ctl8 & DESC_CTL_ACXDONE_HOSTOWN))) {
3020 /* whoops, descr at current index is not free, so probably
3021 * ring buffer already full */
3022 acx_log(LOG_WARNING, L_ANY, "BUG: tx_head:%d Ctl8:0x%02X - "
3023 "failed to find free txdesc\n", head, ctl8);
3024 txdesc = NULL;
3025 goto end;
3028 /* Needed in case txdesc won't be eventually submitted for tx */
3029 txdesc->Ctl_8 = DESC_CTL_ACXDONE_HOSTOWN;
3031 adev->tx_free--;
3032 acx_log(LOG_DEBUG, L_BUFT, "tx: got desc %u, %u remain\n",
3033 head, adev->tx_free);
3034 /* Keep a few free descs between head and tail of tx ring.
3035 ** It is not absolutely needed, just feels safer */
3036 if (adev->tx_free < TX_STOP_QUEUE) {
3037 acx_log(LOG_DEBUG, L_BUF, "stop queue (%u tx desc left)\n",
3038 adev->tx_free);
3039 acx_stop_queue(adev->ieee, NULL);
3042 /* returning current descriptor, so advance to next free one */
3043 adev->tx_head = (head + 1) % TX_CNT;
3044 end:
3045 FN_EXIT0;
3047 return (tx_t *) txdesc;
3051 /***********************************************************************
3053 void *acxpci_l_get_txbuf(acx_device_t * adev, tx_t * tx_opaque)
3055 return get_txhostdesc(adev, (txdesc_t *) tx_opaque)->data;
3059 /***********************************************************************
3060 ** acxpci_l_tx_data
3062 ** Can be called from IRQ (rx -> (AP bridging or mgmt response) -> tx).
3063 ** Can be called from acx_i_start_xmit (data frames from net core).
3065 ** FIXME: in case of fragments, should loop over the number of
3066 ** pre-allocated tx descrs, properly setting up transfer data and
3067 ** CTL_xxx flags according to fragment number.
3069 void
3070 acxpci_l_tx_data(acx_device_t * adev, tx_t * tx_opaque, int len,
3071 struct ieee80211_tx_control *ieeectl,struct sk_buff* skb)
3073 txdesc_t *txdesc = (txdesc_t *) tx_opaque;
3074 struct ieee80211_hdr *wireless_header;
3075 txhostdesc_t *hostdesc1, *hostdesc2;
3076 int rate_cur;
3077 u8 Ctl_8, Ctl2_8;
3078 int wlhdr_len;
3080 FN_ENTER;
3082 /* fw doesn't tx such packets anyhow */
3083 /* if (unlikely(len < WLAN_HDR_A3_LEN))
3084 goto end;
3086 hostdesc1 = get_txhostdesc(adev, txdesc);
3087 wireless_header = (struct ieee80211_hdr *)hostdesc1->data;
3088 /* modify flag status in separate variable to be able to write it back
3089 * in one big swoop later (also in order to have less device memory
3090 * accesses) */
3091 Ctl_8 = txdesc->Ctl_8;
3092 Ctl2_8 = 0; /* really need to init it to 0, not txdesc->Ctl2_8, it seems */
3094 hostdesc2 = hostdesc1 + 1;
3096 /* DON'T simply set Ctl field to 0 here globally,
3097 * it needs to maintain a consistent flag status (those are state flags!!),
3098 * otherwise it may lead to severe disruption. Only set or reset particular
3099 * flags at the exact moment this is needed... */
3101 /* let chip do RTS/CTS handshaking before sending
3102 * in case packet size exceeds threshold */
3103 if (ieeectl->flags & IEEE80211_TXCTL_USE_RTS_CTS)
3104 SET_BIT(Ctl2_8, DESC_CTL2_RTS);
3105 else
3106 CLEAR_BIT(Ctl2_8, DESC_CTL2_RTS);
3108 rate_cur = ieeectl->tx_rate;
3109 if (unlikely(!rate_cur)) {
3110 acx_log(LOG_WARNING, L_ANY, "driver bug! bad ratemask\n");
3111 goto end;
3114 /* used in tx cleanup routine for auto rate and accounting: */
3115 /* put_txcr(adev, txdesc, clt, rate_cur); deprecated by mac80211 */
3117 txdesc->total_length = cpu_to_le16(len);
3118 wlhdr_len = ieee80211_get_hdrlen(le16_to_cpu(wireless_header->frame_control));
3119 hostdesc2->length = cpu_to_le16(len - wlhdr_len);
3121 if (!ieeectl->do_not_encrypt && ieeectl->key_idx>= 0)
3123 u16 key_idx = (u16)(ieeectl->key_idx);
3124 struct acx_key* key = &(adev->key[key_idx]);
3125 int wlhdr_len;
3126 if (key->enabled)
3128 memcpy(ieeehdr->wep_iv, ((u8*)wireless_header) + wlhdr_len, 4);
3132 if (IS_ACX111(adev)) {
3133 /* note that if !txdesc->do_auto, txrate->cur
3134 ** has only one nonzero bit */
3135 txdesc->u.r2.rate111 = cpu_to_le16(rate_cur
3136 /* WARNING: I was never able to make it work with prism54 AP.
3137 ** It was falling down to 1Mbit where shortpre is not applicable,
3138 ** and not working at all at "5,11 basic rates only" setting.
3139 ** I even didn't see tx packets in radio packet capture.
3140 ** Disabled for now --vda */
3141 /*| ((clt->shortpre && clt->cur!=RATE111_1) ? RATE111_SHORTPRE : 0) */
3143 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3144 /* should add this to rate111 above as necessary */
3145 |(clt->pbcc511 ? RATE111_PBCC511 : 0)
3146 #endif
3147 hostdesc1->length = cpu_to_le16(len);
3148 } else { /* ACX100 */
3149 u8 rate_100 = ieeectl->tx_rate;
3150 txdesc->u.r1.rate = rate_100;
3151 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3152 if (clt->pbcc511) {
3153 if (n == RATE100_5 || n == RATE100_11)
3154 n |= RATE100_PBCC511;
3157 if (clt->shortpre && (clt->cur != RATE111_1))
3158 SET_BIT(Ctl_8, DESC_CTL_SHORT_PREAMBLE); /* set Short Preamble */
3159 #endif
3160 /* set autodma and reclaim and 1st mpdu */
3161 SET_BIT(Ctl_8,
3162 DESC_CTL_AUTODMA | DESC_CTL_RECLAIM |
3163 DESC_CTL_FIRSTFRAG);
3164 #if ACX_FRAGMENTATION
3165 /* SET_BIT(Ctl2_8, DESC_CTL2_MORE_FRAG); cannot set it unconditionally, needs to be set for all non-last fragments */
3166 #endif
3167 hostdesc1->length = cpu_to_le16(wlhdr_len);
3169 /* don't need to clean ack/rts statistics here, already
3170 * done on descr cleanup */
3172 /* clears HOSTOWN and ACXDONE bits, thus telling that the descriptors
3173 * are now owned by the acx100; do this as LAST operation */
3174 CLEAR_BIT(Ctl_8, DESC_CTL_ACXDONE_HOSTOWN);
3175 /* flush writes before we release hostdesc to the adapter here */
3176 wmb();
3177 CLEAR_BIT(hostdesc1->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3178 CLEAR_BIT(hostdesc2->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3180 /* write back modified flags */
3181 CLEAR_BIT(Ctl2_8, DESC_CTL2_WEP);
3182 txdesc->Ctl2_8 = Ctl2_8;
3183 txdesc->Ctl_8 = Ctl_8;
3184 /* unused: txdesc->tx_time = cpu_to_le32(jiffies); */
3186 /* flush writes before we tell the adapter that it's its turn now */
3187 write_reg16(adev, ACX_IO_INT_TRIG, INT_TRIG_TXPRC);
3188 write_flush(adev);
3189 /* log the packet content AFTER sending it,
3190 * in order to not delay sending any further than absolutely needed
3191 * Do separate logs for acx100/111 to have human-readable rates */
3192 memcpy(&(hostdesc1->txstatus.control),ieeectl,sizeof(struct ieee80211_tx_control));
3193 hostdesc1->skb = skb;
3194 end:
3195 FN_EXIT0;
3199 /***********************************************************************
3200 ** acxpci_l_clean_txdesc
3202 ** This function resets the txdescs' status when the ACX100
3203 ** signals the TX done IRQ (txdescs have been processed), starting with
3204 ** the pool index of the descriptor which we would use next,
3205 ** in order to make sure that we can be as fast as possible
3206 ** in filling new txdescs.
3207 ** Everytime we get called we know where the next packet to be cleaned is.
3210 #if !ACX_DEBUG
3211 static inline void log_txbuffer(const acx_device_t * adev)
3214 #else
3215 static void log_txbuffer(acx_device_t * adev)
3217 txdesc_t *txdesc;
3218 int i;
3220 /* no FN_ENTER here, we don't want that */
3221 /* no locks here, since it's entirely non-critical code */
3222 txdesc = adev->txdesc_start;
3223 if (unlikely(!txdesc))
3224 return;
3225 acx_log(LOG_DEBUG, L_REALLYVERBOSE, "tx: desc->Ctl8's:");
3226 for (i = 0; i < TX_CNT; i++) {
3227 printk(" %02X", txdesc->Ctl_8);
3228 txdesc = advance_txdesc(adev, txdesc, 1);
3230 printk("\n");
3232 #endif
3235 static void handle_tx_error(acx_device_t * adev, u8 error, unsigned int finger,
3236 struct ieee80211_tx_status *status)
3238 const char *err = "unknown error";
3240 /* hmm, should we handle this as a mask
3241 * of *several* bits?
3242 * For now I think only caring about
3243 * individual bits is ok... */
3244 switch (error) {
3245 case 0x01:
3246 err = "no Tx due to error in other fragment";
3247 /* adev->wstats.discard.fragment++; */
3248 break;
3249 case 0x02:
3250 err = "Tx aborted";
3251 adev->stats.tx_aborted_errors++;
3252 break;
3253 case 0x04:
3254 err = "Tx desc wrong parameters";
3255 /* adev->wstats.discard.misc++; */
3256 break;
3257 case 0x08:
3258 err = "WEP key not found";
3259 /* adev->wstats.discard.misc++; */
3260 break;
3261 case 0x10:
3262 err = "MSDU lifetime timeout? - try changing "
3263 "'iwconfig retry lifetime XXX'";
3264 /* adev->wstats.discard.misc++; */
3265 break;
3266 case 0x20:
3267 err = "excessive Tx retries due to either distance "
3268 "too high or unable to Tx or Tx frame error - "
3269 "try changing 'iwconfig txpower XXX' or "
3270 "'sens'itivity or 'retry'";
3271 /* adev->wstats.discard.retries++; */
3272 /* Tx error 0x20 also seems to occur on
3273 * overheating, so I'm not sure whether we
3274 * actually want to do aggressive radio recalibration,
3275 * since people maybe won't notice then that their hardware
3276 * is slowly getting cooked...
3277 * Or is it still a safe long distance from utter
3278 * radio non-functionality despite many radio recalibs
3279 * to final destructive overheating of the hardware?
3280 * In this case we really should do recalib here...
3281 * I guess the only way to find out is to do a
3282 * potentially fatal self-experiment :-\
3283 * Or maybe only recalib in case we're using Tx
3284 * rate auto (on errors switching to lower speed
3285 * --> less heat?) or 802.11 power save mode?
3287 * ok, just do it. */
3288 if (++adev->retry_errors_msg_ratelimit % 4 == 0) {
3289 if (adev->retry_errors_msg_ratelimit <= 20) {
3290 acx_log(LOG_WARNING, L_ANY,
3291 "%s: several excessive Tx "
3292 "retry errors occurred, attempting "
3293 "to recalibrate radio\n",
3294 wiphy_name(adev->ieee->wiphy));
3295 acx_log(LOG_WARNING, L_ANY,
3296 "Radio drift might be caused by "
3297 "increasing card temperature, please "
3298 "check the card before it's too late!\n");
3299 if (adev->retry_errors_msg_ratelimit == 20)
3300 acx_log(LOG_WARNING, L_ANY,
3301 "disabling above message\n");
3304 acx_schedule_task(adev,
3305 ACX_TASKLET_CMD_RADIO_RECALIB);
3307 status->excessive_retries++;
3308 break;
3309 case 0x40:
3310 err = "Tx buffer overflow";
3311 adev->stats.tx_fifo_errors++;
3312 break;
3313 case 0x80:
3314 /* possibly ACPI C-state powersaving related!!!
3315 * (DMA timeout due to excessively high wakeup
3316 * latency after C-state activation!?)
3317 * Disable C-State powersaving and try again,
3318 * then PLEASE REPORT, I'm VERY interested in
3319 * whether my theory is correct that this is
3320 * actually the problem here.
3321 * In that case, use new Linux idle wakeup latency
3322 * requirements kernel API to prevent this issue. */
3323 err = "DMA error";
3324 /* adev->wstats.discard.misc++; */
3325 break;
3327 adev->stats.tx_errors++;
3328 if (adev->stats.tx_errors <= 20)
3329 acx_log(LOG_WARNING, L_ANY,
3330 "%s: tx error 0x%02X, buf %02u! (%s)\n",
3331 wiphy_name(adev->ieee->wiphy), error, finger, err);
3332 else
3333 acx_log(LOG_WARNING, L_ANY,
3334 "%s: tx error 0x%02X, buf %02u!\n",
3335 wiphy_name(adev->ieee->wiphy), error, finger);
3339 unsigned int acxpci_l_clean_txdesc(acx_device_t * adev)
3341 txdesc_t *txdesc;
3342 txhostdesc_t *hostdesc;
3343 unsigned finger;
3344 int num_cleaned;
3345 u16 r111;
3346 u8 error, ack_failures, rts_failures, rts_ok, r100;
3348 FN_ENTER;
3350 if (unlikely(acx_debug & L_REALLYVERBOSE))
3351 log_txbuffer(adev);
3353 acx_log(LOG_DEBUG, L_BUFT, "tx: cleaning up bufs from %u\n",
3354 adev->tx_tail);
3356 /* We know first descr which is not free yet. We advance it as far
3357 ** as we see correct bits set in following descs (if next desc
3358 ** is NOT free, we shouldn't advance at all). We know that in
3359 ** front of tx_tail may be "holes" with isolated free descs.
3360 ** We will catch up when all intermediate descs will be freed also */
3362 finger = adev->tx_tail;
3363 num_cleaned = 0;
3364 while (likely(finger != adev->tx_head)) {
3365 txdesc = get_txdesc(adev, finger);
3367 /* If we allocated txdesc on tx path but then decided
3368 ** to NOT use it, then it will be left as a free "bubble"
3369 ** in the "allocated for tx" part of the ring.
3370 ** We may meet it on the next ring pass here. */
3372 /* stop if not marked as "tx finished" and "host owned" */
3373 if ((txdesc->Ctl_8 & DESC_CTL_ACXDONE_HOSTOWN)
3374 != DESC_CTL_ACXDONE_HOSTOWN) {
3375 if (unlikely(!num_cleaned)) { /* maybe remove completely */
3376 acx_log(LOG_DEBUG, L_BUFT,
3377 "clean_txdesc: tail isn't free. "
3378 "tail:%d head:%d\n",
3379 adev->tx_tail, adev->tx_head);
3381 break;
3384 /* remember desc values... */
3385 error = txdesc->error;
3386 ack_failures = txdesc->ack_failures;
3387 rts_failures = txdesc->rts_failures;
3388 rts_ok = txdesc->rts_ok;
3389 r100 = txdesc->u.r1.rate;
3390 r111 = le16_to_cpu(txdesc->u.r2.rate111);
3392 /* need to check for certain error conditions before we
3393 * clean the descriptor: we still need valid descr data here */
3394 hostdesc = get_txhostdesc(adev, txdesc);
3396 hostdesc->txstatus.flags |= IEEE80211_TX_STATUS_ACK;
3397 if (unlikely(0x30 & error)) {
3398 /* only send IWEVTXDROP in case of retry or lifetime exceeded;
3399 * all other errors mean we screwed up locally */
3400 /* union iwreq_data wrqu;
3401 struct ieee80211_hdr_3addr *hdr;
3402 hdr = (struct ieee80211_hdr_3addr *) hostdesc->data;
3403 MAC_COPY(wrqu.addr.sa_data, hdr->addr1);
3405 hostdesc->txstatus.flags &= ~IEEE80211_TX_STATUS_ACK;
3408 /* ...and free the desc */
3409 txdesc->error = 0;
3410 txdesc->ack_failures = 0;
3411 txdesc->rts_failures = 0;
3412 txdesc->rts_ok = 0;
3413 /* signal host owning it LAST, since ACX already knows that this
3414 ** descriptor is finished since it set Ctl_8 accordingly. */
3415 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3417 adev->tx_free++;
3418 num_cleaned++;
3420 if ((adev->tx_free >= TX_START_QUEUE)
3421 /* && (adev->status == ACX_STATUS_4_ASSOCIATED) */
3422 /*&& (acx_queue_stopped(adev->ieee))*/
3424 acx_log(LOG_DEBUG, L_BUF,
3425 "tx: wake queue (avail. Tx desc %u)\n",
3426 adev->tx_free);
3427 acx_wake_queue(adev->ieee, NULL);
3430 /* do error checking, rate handling and logging
3431 * AFTER having done the work, it's faster */
3433 /* Rate handling is done in mac80211 */
3434 /* if (adev->rate_auto) {
3435 struct client *clt = get_txc(adev, txdesc);
3436 if (clt) {
3437 u16 cur = get_txr(adev, txdesc);
3438 if (clt->rate_cur == cur) {
3439 acx_l_handle_txrate_auto(adev, clt, cur,*/ /* intended rate */
3440 /*r100, r111,*/ /* actually used rate */
3441 /*(error & 0x30),*/ /* was there an error? */
3442 /* TX_CNT +
3443 TX_CLEAN_BACKLOG
3445 adev->tx_free);
3450 if (unlikely(error))
3451 handle_tx_error(adev, error, finger, &hostdesc->txstatus);
3453 if (IS_ACX111(adev))
3454 acx_log(LOG_DEBUG, L_BUFT, "tx: cleaned %u: !ACK=%u "
3455 "!RTS=%u RTS=%u r111=%04X tx_free=%u\n",
3456 finger, ack_failures,
3457 rts_failures, rts_ok, r111, adev->tx_free);
3458 else
3459 acx_log(LOG_DEBUG, L_BUFT, "tx: cleaned %u: !ACK=%u "
3460 "!RTS=%u RTS=%u rate=%u\n",
3461 finger, ack_failures,
3462 rts_failures, rts_ok, r100);
3464 /* And finally report upstream */
3465 if (hostdesc)
3467 hostdesc->txstatus.excessive_retries = rts_failures ;
3468 hostdesc->txstatus.retry_count = ack_failures;
3469 ieee80211_tx_status(adev->ieee,hostdesc->skb,&hostdesc->txstatus);
3470 memset(&hostdesc->txstatus, 0, sizeof(struct ieee80211_tx_status));
3472 /* update pointer for descr to be cleaned next */
3473 finger = (finger + 1) % TX_CNT;
3475 /* remember last position */
3476 adev->tx_tail = finger;
3477 /* end: */
3478 FN_EXIT1(num_cleaned);
3479 return num_cleaned;
3482 /* clean *all* Tx descriptors, and regardless of their previous state.
3483 * Used for brute-force reset handling. */
3484 void acxpci_l_clean_txdesc_emergency(acx_device_t * adev)
3486 txdesc_t *txdesc;
3487 int i;
3489 FN_ENTER;
3491 for (i = 0; i < TX_CNT; i++) {
3492 txdesc = get_txdesc(adev, i);
3494 /* free it */
3495 txdesc->ack_failures = 0;
3496 txdesc->rts_failures = 0;
3497 txdesc->rts_ok = 0;
3498 txdesc->error = 0;
3499 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3502 adev->tx_free = TX_CNT;
3504 FN_EXIT0;
3508 /***********************************************************************
3509 ** acxpci_s_create_tx_host_desc_queue
3512 static void *allocate(acx_device_t * adev, size_t size, dma_addr_t * phy,
3513 const char *msg)
3515 void *ptr;
3517 ptr = dma_alloc_coherent(adev->bus_dev, size, phy, GFP_KERNEL);
3519 if (ptr) {
3520 acx_log(LOG_DEBUG, L_REALLYVERBOSE,
3521 "%s sz=%d adr=0x%p phy=0x%08llx\n",
3522 msg, (int)size, ptr, (unsigned long long)*phy);
3523 memset(ptr, 0, size);
3524 return ptr;
3526 acx_log(LOG_WARNING, L_ANY, "%s allocation FAILED (%d bytes)\n",
3527 msg, (int)size);
3528 return NULL;
3532 static int acxpci_s_create_tx_host_desc_queue(acx_device_t * adev)
3534 txhostdesc_t *hostdesc;
3535 u8 *txbuf;
3536 dma_addr_t hostdesc_phy;
3537 dma_addr_t txbuf_phy;
3538 int i;
3540 FN_ENTER;
3542 /* allocate TX buffer */
3543 adev->txbuf_area_size = TX_CNT * /*WLAN_A4FR_MAXLEN_WEP_FCS*/ (30 + 2312 + 4);
3544 adev->txbuf_start = allocate(adev, adev->txbuf_area_size,
3545 &adev->txbuf_startphy, "txbuf_start");
3546 if (!adev->txbuf_start)
3547 goto fail;
3549 /* allocate the TX host descriptor queue pool */
3550 adev->txhostdesc_area_size = TX_CNT * 2 * sizeof(*hostdesc);
3551 adev->txhostdesc_start = allocate(adev, adev->txhostdesc_area_size,
3552 &adev->txhostdesc_startphy,
3553 "txhostdesc_start");
3554 if (!adev->txhostdesc_start)
3555 goto fail;
3556 /* check for proper alignment of TX host descriptor pool */
3557 if ((long)adev->txhostdesc_start & 3) {
3558 acx_log(LOG_WARNING, L_ANY,
3559 "driver bug: dma alloc returns unaligned address\n");
3560 goto fail;
3563 hostdesc = adev->txhostdesc_start;
3564 hostdesc_phy = adev->txhostdesc_startphy;
3565 txbuf = adev->txbuf_start;
3566 txbuf_phy = adev->txbuf_startphy;
3568 #if 0
3569 /* Each tx buffer is accessed by hardware via
3570 ** txdesc -> txhostdesc(s) -> txbuffer(s).
3571 ** We use only one txhostdesc per txdesc, but it looks like
3572 ** acx111 is buggy: it accesses second txhostdesc
3573 ** (via hostdesc.desc_phy_next field) even if
3574 ** txdesc->length == hostdesc->length and thus
3575 ** entire packet was placed into first txhostdesc.
3576 ** Due to this bug acx111 hangs unless second txhostdesc
3577 ** has le16_to_cpu(hostdesc.length) = 3 (or larger)
3578 ** Storing NULL into hostdesc.desc_phy_next
3579 ** doesn't seem to help.
3581 ** Update: although it worked on Xterasys XN-2522g
3582 ** with len=3 trick, WG311v2 is even more bogus, doesn't work.
3583 ** Keeping this code (#ifdef'ed out) for documentational purposes.
3585 for (i = 0; i < TX_CNT * 2; i++) {
3586 hostdesc_phy += sizeof(*hostdesc);
3587 if (!(i & 1)) {
3588 hostdesc->data_phy = cpu2acx(txbuf_phy);
3589 /* hostdesc->data_offset = ... */
3590 /* hostdesc->reserved = ... */
3591 hostdesc->Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
3592 /* hostdesc->length = ... */
3593 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3594 hostdesc->pNext = ptr2acx(NULL);
3595 /* hostdesc->Status = ... */
3596 /* below: non-hardware fields */
3597 hostdesc->data = txbuf;
3599 txbuf += WLAN_A4FR_MAXLEN_WEP_FCS;
3600 txbuf_phy += WLAN_A4FR_MAXLEN_WEP_FCS;
3601 } else {
3602 /* hostdesc->data_phy = ... */
3603 /* hostdesc->data_offset = ... */
3604 /* hostdesc->reserved = ... */
3605 /* hostdesc->Ctl_16 = ... */
3606 hostdesc->length = cpu_to_le16(3); /* bug workaround */
3607 /* hostdesc->desc_phy_next = ... */
3608 /* hostdesc->pNext = ... */
3609 /* hostdesc->Status = ... */
3610 /* below: non-hardware fields */
3611 /* hostdesc->data = ... */
3613 hostdesc++;
3615 #endif
3616 /* We initialize two hostdescs so that they point to adjacent
3617 ** memory areas. Thus txbuf is really just a contiguous memory area */
3618 for (i = 0; i < TX_CNT * 2; i++) {
3619 hostdesc_phy += sizeof(*hostdesc);
3621 hostdesc->data_phy = cpu2acx(txbuf_phy);
3622 /* done by memset(0): hostdesc->data_offset = 0; */
3623 /* hostdesc->reserved = ... */
3624 hostdesc->Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
3625 /* hostdesc->length = ... */
3626 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3627 /* done by memset(0): hostdesc->pNext = ptr2acx(NULL); */
3628 /* hostdesc->Status = ... */
3629 /* ->data is a non-hardware field: */
3630 hostdesc->data = txbuf;
3632 if (!(i & 1)) {
3633 txbuf += 24 /*WLAN_HDR_A3_LEN*/;
3634 txbuf_phy += 24 /*WLAN_HDR_A3_LEN*/;
3635 } else {
3636 txbuf += 30 + 2132 + 4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3637 txbuf_phy += 30 + 2132 +4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3639 hostdesc++;
3641 hostdesc--;
3642 hostdesc->desc_phy_next = cpu2acx(adev->txhostdesc_startphy);
3644 FN_EXIT1(OK);
3645 return OK;
3646 fail:
3647 acx_log(LOG_WARNING, L_ANY, "create_tx_host_desc_queue FAILED\n");
3648 /* dealloc will be done by free function on error case */
3649 FN_EXIT1(NOT_OK);
3650 return NOT_OK;
3654 /***************************************************************
3655 ** acxpci_s_create_rx_host_desc_queue
3657 /* the whole size of a data buffer (header plus data body)
3658 * plus 32 bytes safety offset at the end */
3659 #define RX_BUFFER_SIZE (sizeof(rxbuffer_t) + 32)
3661 static int acxpci_s_create_rx_host_desc_queue(acx_device_t * adev)
3663 rxhostdesc_t *hostdesc;
3664 rxbuffer_t *rxbuf;
3665 dma_addr_t hostdesc_phy;
3666 dma_addr_t rxbuf_phy;
3667 int i;
3669 FN_ENTER;
3671 /* allocate the RX host descriptor queue pool */
3672 adev->rxhostdesc_area_size = RX_CNT * sizeof(*hostdesc);
3673 adev->rxhostdesc_start = allocate(adev, adev->rxhostdesc_area_size,
3674 &adev->rxhostdesc_startphy,
3675 "rxhostdesc_start");
3676 if (!adev->rxhostdesc_start)
3677 goto fail;
3678 /* check for proper alignment of RX host descriptor pool */
3679 if ((long)adev->rxhostdesc_start & 3) {
3680 acx_log(LOG_WARNING, L_ANY,
3681 "driver bug: dma alloc returns unaligned address\n");
3682 goto fail;
3685 /* allocate Rx buffer pool which will be used by the acx
3686 * to store the whole content of the received frames in it */
3687 adev->rxbuf_area_size = RX_CNT * RX_BUFFER_SIZE;
3688 adev->rxbuf_start = allocate(adev, adev->rxbuf_area_size,
3689 &adev->rxbuf_startphy, "rxbuf_start");
3690 if (!adev->rxbuf_start)
3691 goto fail;
3693 rxbuf = adev->rxbuf_start;
3694 rxbuf_phy = adev->rxbuf_startphy;
3695 hostdesc = adev->rxhostdesc_start;
3696 hostdesc_phy = adev->rxhostdesc_startphy;
3698 /* don't make any popular C programming pointer arithmetic mistakes
3699 * here, otherwise I'll kill you...
3700 * (and don't dare asking me why I'm warning you about that...) */
3701 for (i = 0; i < RX_CNT; i++) {
3702 hostdesc->data = rxbuf;
3703 hostdesc->data_phy = cpu2acx(rxbuf_phy);
3704 hostdesc->length = cpu_to_le16(RX_BUFFER_SIZE);
3705 CLEAR_BIT(hostdesc->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3706 rxbuf++;
3707 rxbuf_phy += sizeof(*rxbuf);
3708 hostdesc_phy += sizeof(*hostdesc);
3709 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3710 hostdesc++;
3712 hostdesc--;
3713 hostdesc->desc_phy_next = cpu2acx(adev->rxhostdesc_startphy);
3714 FN_EXIT1(OK);
3715 return OK;
3716 fail:
3717 acx_log(LOG_WARNING, L_ANY, "create_rx_host_desc_queue FAILED\n");
3718 /* dealloc will be done by free function on error case */
3719 FN_EXIT1(NOT_OK);
3720 return NOT_OK;
3724 /***************************************************************
3725 ** acxpci_s_create_hostdesc_queues
3727 int acxpci_s_create_hostdesc_queues(acx_device_t * adev)
3729 int result;
3730 result = acxpci_s_create_tx_host_desc_queue(adev);
3731 if (OK != result)
3732 return result;
3733 result = acxpci_s_create_rx_host_desc_queue(adev);
3734 return result;
3738 /***************************************************************
3739 ** acxpci_create_tx_desc_queue
3741 static void acxpci_create_tx_desc_queue(acx_device_t * adev, u32 tx_queue_start)
3743 txdesc_t *txdesc;
3744 txhostdesc_t *hostdesc;
3745 dma_addr_t hostmemptr;
3746 u32 mem_offs;
3747 int i;
3749 FN_ENTER;
3751 if (IS_ACX100(adev))
3752 adev->txdesc_size = sizeof(*txdesc);
3753 else
3754 /* the acx111 txdesc is 4 bytes larger */
3755 adev->txdesc_size = sizeof(*txdesc) + 4;
3757 adev->txdesc_start = (txdesc_t *) (adev->iobase2 + tx_queue_start);
3759 acx_log(LOG_DEBUG, L_REALLYVERBOSE, "adev->iobase2=%p\n"
3760 "tx_queue_start=%08X\n adev->txdesc_start=%p\n",
3761 adev->iobase2, tx_queue_start, adev->txdesc_start);
3763 adev->tx_free = TX_CNT;
3764 /* done by memset: adev->tx_head = 0; */
3765 /* done by memset: adev->tx_tail = 0; */
3766 txdesc = adev->txdesc_start;
3767 mem_offs = tx_queue_start;
3768 hostmemptr = adev->txhostdesc_startphy;
3769 hostdesc = adev->txhostdesc_start;
3771 if (IS_ACX111(adev)) {
3772 /* ACX111 has a preinitialized Tx buffer! */
3773 /* loop over whole send pool */
3774 /* FIXME: do we have to do the hostmemptr stuff here?? */
3775 for (i = 0; i < TX_CNT; i++) {
3776 txdesc->HostMemPtr = ptr2acx(hostmemptr);
3777 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3778 /* reserve two (hdr desc and payload desc) */
3779 hostdesc += 2;
3780 hostmemptr += 2 * sizeof(*hostdesc);
3781 txdesc = advance_txdesc(adev, txdesc, 1);
3783 } else {
3784 /* ACX100 Tx buffer needs to be initialized by us */
3785 /* clear whole send pool. sizeof is safe here (we are acx100) */
3786 memset(adev->txdesc_start, 0, TX_CNT * sizeof(*txdesc));
3788 /* loop over whole send pool */
3789 for (i = 0; i < TX_CNT; i++) {
3790 acx_log(LOG_DEBUG, L_REALLYVERBOSE,
3791 "configure card tx descriptor: 0x%p, "
3792 "size: 0x%X\n", txdesc, adev->txdesc_size);
3794 /* pointer to hostdesc memory */
3795 txdesc->HostMemPtr = ptr2acx(hostmemptr);
3796 /* initialise ctl */
3797 txdesc->Ctl_8 = (DESC_CTL_HOSTOWN | DESC_CTL_RECLAIM
3798 | DESC_CTL_AUTODMA |
3799 DESC_CTL_FIRSTFRAG);
3800 /* done by memset(0): txdesc->Ctl2_8 = 0; */
3801 /* point to next txdesc */
3802 txdesc->pNextDesc =
3803 cpu2acx(mem_offs + adev->txdesc_size);
3804 /* reserve two (hdr desc and payload desc) */
3805 hostdesc += 2;
3806 hostmemptr += 2 * sizeof(*hostdesc);
3807 /* go to the next one */
3808 mem_offs += adev->txdesc_size;
3809 /* ++ is safe here (we are acx100) */
3810 txdesc++;
3812 /* go back to the last one */
3813 txdesc--;
3814 /* and point to the first making it a ring buffer */
3815 txdesc->pNextDesc = cpu2acx(tx_queue_start);
3817 FN_EXIT0;
3821 /***************************************************************
3822 ** acxpci_create_rx_desc_queue
3824 static void acxpci_create_rx_desc_queue(acx_device_t * adev, u32 rx_queue_start)
3826 rxdesc_t *rxdesc;
3827 u32 mem_offs;
3828 int i;
3830 FN_ENTER;
3832 /* done by memset: adev->rx_tail = 0; */
3834 /* ACX111 doesn't need any further config: preconfigures itself.
3835 * Simply print ring buffer for debugging */
3836 if (IS_ACX111(adev)) {
3837 /* rxdesc_start already set here */
3839 adev->rxdesc_start =
3840 (rxdesc_t *) ((u8 *) adev->iobase2 + rx_queue_start);
3842 rxdesc = adev->rxdesc_start;
3843 for (i = 0; i < RX_CNT; i++) {
3844 acx_log(LOG_DEBUG, L_REALLYVERBOSE,
3845 "rx descriptor %d @ 0x%p\n", i, rxdesc);
3846 rxdesc = adev->rxdesc_start = (rxdesc_t *)
3847 (adev->iobase2 + acx2cpu(rxdesc->pNextDesc));
3849 } else {
3850 /* we didn't pre-calculate rxdesc_start in case of ACX100 */
3851 /* rxdesc_start should be right AFTER Tx pool */
3852 adev->rxdesc_start = (rxdesc_t *)
3853 ((u8 *) adev->txdesc_start + (TX_CNT * sizeof(txdesc_t)));
3854 /* NB: sizeof(txdesc_t) above is valid because we know
3855 ** we are in if (acx100) block. Beware of cut-n-pasting elsewhere!
3856 ** acx111's txdesc is larger! */
3858 memset(adev->rxdesc_start, 0, RX_CNT * sizeof(*rxdesc));
3860 /* loop over whole receive pool */
3861 rxdesc = adev->rxdesc_start;
3862 mem_offs = rx_queue_start;
3863 for (i = 0; i < RX_CNT; i++) {
3864 acx_log(LOG_DEBUG, L_REALLYVERBOSE,
3865 "rx descriptor @ 0x%p\n", rxdesc);
3866 rxdesc->Ctl_8 = DESC_CTL_RECLAIM | DESC_CTL_AUTODMA;
3867 /* point to next rxdesc */
3868 rxdesc->pNextDesc = cpu2acx(mem_offs + sizeof(*rxdesc));
3869 /* go to the next one */
3870 mem_offs += sizeof(*rxdesc);
3871 rxdesc++;
3873 /* go to the last one */
3874 rxdesc--;
3876 /* and point to the first making it a ring buffer */
3877 rxdesc->pNextDesc = cpu2acx(rx_queue_start);
3879 FN_EXIT0;
3883 /***************************************************************
3884 ** acxpci_create_desc_queues
3886 void
3887 acxpci_create_desc_queues(acx_device_t * adev, u32 tx_queue_start,
3888 u32 rx_queue_start)
3890 acxpci_create_tx_desc_queue(adev, tx_queue_start);
3891 acxpci_create_rx_desc_queue(adev, rx_queue_start);
3895 /***************************************************************
3896 ** acxpci_s_proc_diag_output
3898 char *acxpci_s_proc_diag_output(char *p, acx_device_t * adev)
3900 const char *rtl, *thd, *ttl;
3901 rxhostdesc_t *rxhostdesc;
3902 txdesc_t *txdesc;
3903 int i;
3905 FN_ENTER;
3907 p += sprintf(p, "** Rx buf **\n");
3908 rxhostdesc = adev->rxhostdesc_start;
3909 if (rxhostdesc)
3910 for (i = 0; i < RX_CNT; i++) {
3911 rtl = (i == adev->rx_tail) ? " [tail]" : "";
3912 if ((rxhostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
3913 && (rxhostdesc->
3914 Status & cpu_to_le32(DESC_STATUS_FULL)))
3915 p += sprintf(p, "%02u FULL%s\n", i, rtl);
3916 else
3917 p += sprintf(p, "%02u empty%s\n", i, rtl);
3918 rxhostdesc++;
3920 /* p += sprintf(p, "** Tx buf (free %d, Linux netqueue %s) **\n",
3921 adev->tx_free,
3922 acx_queue_stopped(adev->ieee) ? "STOPPED" : "running");*/
3923 txdesc = adev->txdesc_start;
3924 if (txdesc)
3925 for (i = 0; i < TX_CNT; i++) {
3926 thd = (i == adev->tx_head) ? " [head]" : "";
3927 ttl = (i == adev->tx_tail) ? " [tail]" : "";
3928 if (txdesc->Ctl_8 & DESC_CTL_ACXDONE)
3929 p += sprintf(p, "%02u free (%02X)%s%s\n", i,
3930 txdesc->Ctl_8, thd, ttl);
3931 else
3932 p += sprintf(p, "%02u tx (%02X)%s%s\n", i,
3933 txdesc->Ctl_8, thd, ttl);
3934 txdesc = advance_txdesc(adev, txdesc, 1);
3936 p += sprintf(p,
3937 "\n"
3938 "** PCI data **\n"
3939 "txbuf_start %p, txbuf_area_size %u, txbuf_startphy %08llx\n"
3940 "txdesc_size %u, txdesc_start %p\n"
3941 "txhostdesc_start %p, txhostdesc_area_size %u, txhostdesc_startphy %08llx\n"
3942 "rxdesc_start %p\n"
3943 "rxhostdesc_start %p, rxhostdesc_area_size %u, rxhostdesc_startphy %08llx\n"
3944 "rxbuf_start %p, rxbuf_area_size %u, rxbuf_startphy %08llx\n",
3945 adev->txbuf_start, adev->txbuf_area_size,
3946 (unsigned long long)adev->txbuf_startphy,
3947 adev->txdesc_size, adev->txdesc_start,
3948 adev->txhostdesc_start, adev->txhostdesc_area_size,
3949 (unsigned long long)adev->txhostdesc_startphy,
3950 adev->rxdesc_start,
3951 adev->rxhostdesc_start, adev->rxhostdesc_area_size,
3952 (unsigned long long)adev->rxhostdesc_startphy,
3953 adev->rxbuf_start, adev->rxbuf_area_size,
3954 (unsigned long long)adev->rxbuf_startphy);
3956 FN_EXIT0;
3957 return p;
3961 /***********************************************************************
3963 int acxpci_proc_eeprom_output(char *buf, acx_device_t * adev)
3965 char *p = buf;
3966 int i;
3968 FN_ENTER;
3970 for (i = 0; i < 0x400; i++) {
3971 acxpci_read_eeprom_byte(adev, i, p++);
3974 FN_EXIT1(p - buf);
3975 return p - buf;
3979 /***********************************************************************
3981 int acx100pci_s_set_tx_level(acx_device_t * adev, u8 level_dbm)
3983 /* since it can be assumed that at least the Maxim radio has a
3984 * maximum power output of 20dBm and since it also can be
3985 * assumed that these values drive the DAC responsible for
3986 * setting the linear Tx level, I'd guess that these values
3987 * should be the corresponding linear values for a dBm value,
3988 * in other words: calculate the values from that formula:
3989 * Y [dBm] = 10 * log (X [mW])
3990 * then scale the 0..63 value range onto the 1..100mW range (0..20 dBm)
3991 * and you're done...
3992 * Hopefully that's ok, but you never know if we're actually
3993 * right... (especially since Windows XP doesn't seem to show
3994 * actual Tx dBm values :-P) */
3996 /* NOTE: on Maxim, value 30 IS 30mW, and value 10 IS 10mW - so the
3997 * values are EXACTLY mW!!! Not sure about RFMD and others,
3998 * though... */
3999 static const u8 dbm2val_maxim[21] = {
4000 63, 63, 63, 62,
4001 61, 61, 60, 60,
4002 59, 58, 57, 55,
4003 53, 50, 47, 43,
4004 38, 31, 23, 13,
4007 static const u8 dbm2val_rfmd[21] = {
4008 0, 0, 0, 1,
4009 2, 2, 3, 3,
4010 4, 5, 6, 8,
4011 10, 13, 16, 20,
4012 25, 32, 41, 50,
4015 const u8 *table;
4017 switch (adev->radio_type) {
4018 case RADIO_MAXIM_0D:
4019 table = &dbm2val_maxim[0];
4020 break;
4021 case RADIO_RFMD_11:
4022 case RADIO_RALINK_15:
4023 table = &dbm2val_rfmd[0];
4024 break;
4025 default:
4026 acx_log(LOG_WARNING, L_ANY, "%s: unknown/unsupported radio type, "
4027 "cannot modify tx power level yet!\n",
4028 wiphy_name(adev->ieee->wiphy));
4029 return NOT_OK;
4031 acx_log(LOG_INFO, L_ANY,
4032 "%s: changing radio power level to %u dBm (%u)\n",
4033 wiphy_name(adev->ieee->wiphy), level_dbm, table[level_dbm]);
4034 acxpci_s_write_phy_reg(adev, 0x11, table[level_dbm]);
4035 return OK;
4038 #ifdef CONFIG_VLYNQ
4039 struct vlynq_reg_config {
4040 u32 offset;
4041 u32 value;
4044 struct vlynq_known {
4045 u32 chip_id;
4046 char name[32];
4047 struct vlynq_mapping rx_mapping[4];
4048 int irq;
4049 int irq_type;
4050 int num_regs;
4051 struct vlynq_reg_config regs[10];
4054 #define CHIP_TNETW1130 0x00000009
4055 #define CHIP_TNETW1350 0x00000029
4057 static struct vlynq_known known_devices[] = {
4059 .chip_id = CHIP_TNETW1130, .name = "TI TNETW1130",
4060 .rx_mapping = {
4061 { .size = 0x22000, .offset = 0xf0000000 },
4062 { .size = 0x40000, .offset = 0xc0000000 },
4063 { .size = 0x0, .offset = 0x0 },
4064 { .size = 0x0, .offset = 0x0 },
4066 .irq = 0,
4067 .irq_type = IRQ_TYPE_EDGE_RISING,
4068 .num_regs = 5,
4069 .regs = {
4071 .offset = 0x790,
4072 .value = (0xd0000000 - PHYS_OFFSET)
4075 .offset = 0x794,
4076 .value = (0xd0000000 - PHYS_OFFSET)
4078 { .offset = 0x740, .value = 0 },
4079 { .offset = 0x744, .value = 0x00010000 },
4080 { .offset = 0x764, .value = 0x00010000 },
4084 .chip_id = CHIP_TNETW1350, .name = "TI TNETW1350",
4085 .rx_mapping = {
4086 { .size = 0x100000, .offset = 0x00300000 },
4087 { .size = 0x80000, .offset = 0x00000000 },
4088 { .size = 0x0, .offset = 0x0 },
4089 { .size = 0x0, .offset = 0x0 },
4091 .irq = 0,
4092 .irq_type = IRQ_TYPE_EDGE_RISING,
4093 .num_regs = 5,
4094 .regs = {
4096 .offset = 0x790,
4097 .value = (0x60000000 - PHYS_OFFSET)
4100 .offset = 0x794,
4101 .value = (0x60000000 - PHYS_OFFSET)
4103 { .offset = 0x740, .value = 0 },
4104 { .offset = 0x744, .value = 0x00010000 },
4105 { .offset = 0x764, .value = 0x00010000 },
4110 static struct vlynq_device_id acx_vlynq_id[] = {
4111 { CHIP_TNETW1130, vlynq_div_auto, 0 },
4112 { CHIP_TNETW1350, vlynq_div_auto, 1 },
4113 { 0, 0, 0 },
4116 static __devinit int vlynq_probe(struct vlynq_device *vdev,
4117 struct vlynq_device_id *id)
4119 int result = -EIO, i;
4120 u32 addr;
4121 struct ieee80211_hw *ieee;
4122 acx_device_t *adev = NULL;
4123 acx111_ie_configoption_t co;
4124 struct vlynq_mapping mapping[4] = { { 0, }, };
4125 struct vlynq_known *match = NULL;
4127 FN_ENTER;
4128 result = vlynq_enable_device(vdev);
4129 if (result)
4130 return result;
4132 match = &known_devices[id->driver_data];
4134 if (!match) {
4135 result = -ENODEV;
4136 goto fail;
4139 mapping[0].offset = ARCH_PFN_OFFSET << PAGE_SHIFT;
4140 mapping[0].size = 0x02000000;
4141 vlynq_set_local_mapping(vdev, vdev->mem_start, mapping);
4142 vlynq_set_remote_mapping(vdev, 0, match->rx_mapping);
4144 set_irq_type(vlynq_virq_to_irq(vdev, match->irq), match->irq_type);
4146 addr = (u32)ioremap(vdev->mem_start, 0x1000);
4147 if (!addr) {
4148 acx_log(LOG_WARNING, L_ANY, "%s: failed to remap io memory\n",
4149 vdev->dev.bus_id);
4150 result = -ENXIO;
4151 goto fail;
4154 for (i = 0; i < match->num_regs; i++)
4155 iowrite32(match->regs[i].value,
4156 (u32 *)(addr + match->regs[i].offset));
4158 iounmap((void *)addr);
4160 ieee = ieee80211_alloc_hw(sizeof(struct acx_device), &acxpci_hw_ops);
4161 if (!ieee) {
4162 acx_log(LOG_WARNING, L_ANY,
4163 "could not allocate ieee80211 structure %s\n",
4164 vdev->dev.bus_id);
4165 goto fail_alloc_netdev;
4167 ieee->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
4168 ieee->queues = 1;
4170 adev = ieee2adev(ieee);
4172 memset(adev, 0, sizeof(*adev));
4173 /** Set up our private interface **/
4174 spin_lock_init(&adev->spinlock); /* initial state: unlocked */
4175 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
4176 mutex_init(&adev->mutex);
4177 /* since nobody can see new netdev yet, we can as well
4178 ** just _presume_ that we're under sem (instead of actually taking it): */
4179 /* acx_sem_lock(adev); */
4180 adev->ieee = ieee;
4181 adev->vdev = vdev;
4182 adev->bus_dev = &vdev->dev;
4183 adev->dev_type = DEVTYPE_PCI;
4185 /** Finished with private interface **/
4187 vlynq_set_drvdata(vdev, ieee);
4188 if (!request_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start, "acx")) {
4189 acx_log(LOG_WARNING, L_ANY, "cannot reserve VLYNQ memory region\n");
4190 goto fail_request_mem_region;
4193 adev->iobase = ioremap(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4194 if (!adev->iobase) {
4195 acx_log(LOG_WARNING, L_ANY, "ioremap() FAILED\n");
4196 goto fail_ioremap;
4198 adev->iobase2 = adev->iobase + match->rx_mapping[0].size;
4199 adev->chip_type = CHIPTYPE_ACX111;
4200 adev->chip_name = match->name;
4201 adev->io = IO_ACX111;
4202 adev->irq = vlynq_virq_to_irq(vdev, match->irq);
4204 acx_log(LOG_INFO, L_ANY, "found %s-based wireless network card at %s, "
4205 "irq:%d, phymem:0x%x, mem:0x%p\n",
4206 match->name, vdev->dev.bus_id, adev->irq,
4207 vdev->mem_start, adev->iobase);
4208 // acx_log(LOG_INFO, L_ANY,
4209 // "initial debug setting is 0x%04X\n", acx_debug);
4211 if (0 == adev->irq) {
4212 acx_log(LOG_WARNING, L_ANY, "can't use IRQ 0\n");
4213 goto fail_irq;
4215 SET_IEEE80211_DEV(ieee, &vdev->dev);
4217 /* request shared IRQ handler */
4218 if (request_irq
4219 (adev->irq, acxpci_i_interrupt, IRQF_SHARED, KBUILD_MODNAME, adev)) {
4220 acx_log(LOG_WARNING, L_ANY, "%s: request_irq FAILED\n",
4221 wiphy_name(adev->ieee->wiphy));
4222 result = -EAGAIN;
4223 goto done;
4225 acx_log(LOG_DEBUG, L_IRQ | L_REALLYVERBOSE,
4226 "request_irq %d successful\n", adev->irq);
4228 /* to find crashes due to weird driver access
4229 * to unconfigured interface (ifup) */
4230 adev->mgmt_timer.function = (void (*)(unsigned long))0x0000dead;
4233 /* ok, pci setup is finished, now start initializing the card */
4235 /* NB: read_reg() reads may return bogus data before reset_dev(),
4236 * since the firmware which directly controls large parts of the I/O
4237 * registers isn't initialized yet.
4238 * acx100 seems to be more affected than acx111 */
4239 if (OK != acxpci_s_reset_dev(adev))
4240 goto fail_reset;
4242 if (OK != acx_s_init_mac(adev))
4243 goto fail_init_mac;
4245 acx_s_interrogate(adev, &co, ACX111_IE_CONFIG_OPTIONS);
4246 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
4247 if (OK != acxpci_read_eeprom_byte(adev, 0x05, &adev->eeprom_version))
4248 goto fail_read_eeprom_version;
4250 acx_s_parse_configoption(adev, &co);
4251 acx_s_set_defaults(adev);
4252 acx_s_get_firmware_version(adev); /* needs to be after acx_s_init_mac() */
4253 acx_display_hardware_details(adev);
4255 /* Register the card, AFTER everything else has been set up,
4256 * since otherwise an ioctl could step on our feet due to
4257 * firmware operations happening in parallel or uninitialized data */
4260 acx_proc_register_entries(ieee);
4262 /* Now we have our device, so make sure the kernel doesn't try
4263 * to send packets even though we're not associated to a network yet */
4265 /* after register_netdev() userspace may start working with dev
4266 * (in particular, on other CPUs), we only need to up the sem */
4267 /* acx_sem_unlock(adev); */
4269 acx_log(LOG_INFO, L_ANY, "driver " ACX_RELEASE ", net device %s, "
4270 "driver compiled against wireless extensions %d and Linux %s\n",
4271 wiphy_name(adev->ieee->wiphy), WIRELESS_EXT, UTS_RELEASE);
4273 MAC_COPY(adev->ieee->wiphy->perm_addr, adev->dev_addr);
4275 acx_log(LOG_DEBUG, L_IRQ | L_INIT, "using IRQ %d\n", adev->irq);
4277 /** done with board specific setup **/
4279 result = acx_setup_modes(adev);
4280 if (result) {
4281 acx_log(LOG_WARNING, L_ANY, "can't register hwmode\n");
4282 goto fail_register_netdev;
4285 acx_init_task_scheduler(adev);
4286 result = ieee80211_register_hw(adev->ieee);
4287 if (OK != result) {
4288 acx_log(LOG_WARNING, L_ANY,
4289 "acx: ieee80211_register_hw() FAILED: %d\n", result);
4290 goto fail_register_netdev;
4292 #if CMD_DISCOVERY
4293 great_inquisitor(adev);
4294 #endif
4296 result = OK;
4297 goto done;
4299 /* error paths: undo everything in reverse order... */
4302 acxpci_s_delete_dma_regions(adev);
4304 fail_init_mac:
4305 fail_read_eeprom_version:
4306 fail_reset:
4308 fail_alloc_netdev:
4309 fail_irq:
4311 iounmap(adev->iobase);
4312 fail_ioremap:
4314 release_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4315 fail_request_mem_region:
4316 fail_register_netdev:
4317 ieee80211_free_hw(ieee);
4318 fail:
4319 vlynq_disable_device(vdev);
4320 done:
4321 FN_EXIT1(result);
4322 return result;
4325 static void vlynq_remove(struct vlynq_device *vdev)
4327 struct ieee80211_hw *hw = vlynq_get_drvdata(vdev);
4328 acx_device_t *adev = ieee2adev(hw);
4329 unsigned long flags;
4330 FN_ENTER;
4332 if (!hw) {
4333 acx_log(LOG_DEBUG, L_REALLYVERBOSE,
4334 "%s: card is unused. Skipping any release code\n",
4335 __func__);
4336 goto end;
4340 acx_lock(adev, flags);
4341 acx_unlock(adev, flags);
4342 adev->initialized = 0;
4344 /* If device wasn't hot unplugged... */
4345 if (adev_present(adev)) {
4347 acx_sem_lock(adev);
4349 /* disable both Tx and Rx to shut radio down properly */
4350 if (adev->initialized) {
4351 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_TX, NULL, 0);
4352 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_RX, NULL, 0);
4354 acx_lock(adev, flags);
4355 /* disable power LED to save power :-) */
4356 acx_log(LOG_INFO, L_INIT,
4357 "switching off power LED to save power\n");
4358 acxpci_l_power_led(adev, 0);
4359 /* stop our eCPU */
4360 acx_unlock(adev, flags);
4362 acx_sem_unlock(adev);
4365 /* unregister the device to not let the kernel
4366 * (e.g. ioctls) access a half-deconfigured device
4367 * NB: this will cause acxpci_e_close() to be called,
4368 * thus we shouldn't call it under sem!
4369 * Well, netdev did, but ieee80211 stack does not, so we
4370 * have to do so manually...
4372 acxpci_e_close(hw);
4373 acx_log(LOG_INFO, L_INIT, "removing device %s\n",
4374 wiphy_name(adev->ieee->wiphy));
4375 ieee80211_unregister_hw(adev->ieee);
4377 /* unregister_netdev ensures that no references to us left.
4378 * For paranoid reasons we continue to follow the rules */
4379 acx_sem_lock(adev);
4381 if (adev->dev_state_mask & ACX_STATE_IFACE_UP) {
4382 acxpci_s_down(hw);
4383 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
4386 acx_proc_unregister_entries(adev->ieee);
4388 /* finally, clean up PCI bus state */
4389 acxpci_s_delete_dma_regions(adev);
4390 if (adev->iobase)
4391 iounmap(adev->iobase);
4392 if (adev->iobase2)
4393 iounmap(adev->iobase2);
4394 release_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4396 /* remove dev registration */
4398 acx_sem_unlock(adev);
4399 vlynq_disable_device(vdev);
4401 /* Free netdev (quite late,
4402 * since otherwise we might get caught off-guard
4403 * by a netdev timeout handler execution
4404 * expecting to see a working dev...) */
4405 ieee80211_free_hw(adev->ieee);
4407 end:
4408 FN_EXIT0;
4411 static struct vlynq_driver vlynq_acx = {
4412 .name = "acx_vlynq",
4413 .id_table = acx_vlynq_id,
4414 .probe = vlynq_probe,
4415 .remove = __devexit_p(vlynq_remove),
4417 #endif /* CONFIG_VLYNQ */
4420 /***********************************************************************
4421 ** Data for init_module/cleanup_module
4423 #ifdef CONFIG_PCI
4424 static const struct pci_device_id acxpci_id_tbl[] __devinitdata = {
4426 .vendor = PCI_VENDOR_ID_TI,
4427 .device = PCI_DEVICE_ID_TI_TNETW1100A,
4428 .subvendor = PCI_ANY_ID,
4429 .subdevice = PCI_ANY_ID,
4430 .driver_data = CHIPTYPE_ACX100,
4433 .vendor = PCI_VENDOR_ID_TI,
4434 .device = PCI_DEVICE_ID_TI_TNETW1100B,
4435 .subvendor = PCI_ANY_ID,
4436 .subdevice = PCI_ANY_ID,
4437 .driver_data = CHIPTYPE_ACX100,
4440 .vendor = PCI_VENDOR_ID_TI,
4441 .device = PCI_DEVICE_ID_TI_TNETW1130,
4442 .subvendor = PCI_ANY_ID,
4443 .subdevice = PCI_ANY_ID,
4444 .driver_data = CHIPTYPE_ACX111,
4447 .vendor = 0,
4448 .device = 0,
4449 .subvendor = 0,
4450 .subdevice = 0,
4451 .driver_data = 0,
4455 MODULE_DEVICE_TABLE(pci, acxpci_id_tbl);
4457 static struct pci_driver
4458 acxpci_drv_id = {
4459 .name = "acx_pci",
4460 .id_table = acxpci_id_tbl,
4461 .probe = acxpci_e_probe,
4462 .remove = __devexit_p(acxpci_e_remove),
4463 #ifdef CONFIG_PM
4464 .suspend = acxpci_e_suspend,
4465 .resume = acxpci_e_resume
4466 #endif /* CONFIG_PM */
4468 #endif /* CONFIG_PCI */
4470 /***********************************************************************
4471 ** acxpci_e_init_module
4473 ** Module initialization routine, called once at module load time
4475 int __init acxpci_e_init_module(void)
4477 int res;
4479 FN_ENTER;
4481 #if (ACX_IO_WIDTH==32)
4482 acx_log(LOG_INFO, L_ANY, "compiled to use 32bit I/O access. "
4483 "I/O timing issues might occur, such as "
4484 "non-working firmware upload. Report them\n");
4485 #else
4486 acx_log(LOG_INFO, L_ANY, "compiled to use 16bit I/O access only "
4487 "(compatibility mode)\n");
4488 #endif
4490 #ifdef __LITTLE_ENDIAN
4491 #define ENDIANNESS_STRING "running on a little-endian CPU\n"
4492 #else
4493 #define ENDIANNESS_STRING "running on a BIG-ENDIAN CPU\n"
4494 #endif
4495 acx_log(LOG_INFO, L_INIT, ENDIANNESS_STRING);
4496 acx_log(LOG_INFO, L_INIT, "PCI/VLYNQ module " ACX_RELEASE
4497 " initialized, waiting for cards to probe...\n");
4499 #ifdef CONFIG_PCI
4500 res = pci_register_driver(&acxpci_drv_id);
4501 #elif CONFIG_VLYNQ
4502 res = vlynq_register_driver(&vlynq_acx);
4503 #endif
4504 FN_EXIT1(res);
4505 return res;
4509 /***********************************************************************
4510 ** acxpci_e_cleanup_module
4512 ** Called at module unload time. This is our last chance to
4513 ** clean up after ourselves.
4515 void __exit acxpci_e_cleanup_module(void)
4517 FN_ENTER;
4519 #ifdef CONFIG_PCI
4520 pci_unregister_driver(&acxpci_drv_id);
4521 #elif CONFIG_VLYNQ
4522 vlynq_unregister_driver(&vlynq_acx);
4523 #endif
4524 acx_log(LOG_INFO, L_INIT,
4525 "PCI module " ACX_RELEASE " unloaded\n");
4526 FN_EXIT0;