pci.c and usb.c: skip setting the ->dev_type of struct acx_device
[acx-mac80211.git] / pci.c
blob55eedb9774c9bec374d33408ae2d2aafc2aef0ee
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 "acxpci.h"
39 #include "acx_log.h"
40 #include "acx_irq.h"
41 #include "acx_util.h"
43 /***********************************************************************
45 #ifdef CONFIG_PCI
46 #define PCI_TYPE (PCI_USES_MEM | PCI_ADDR0 | PCI_NO_ACPI_WAKE)
47 #define PCI_ACX100_REGION1 0x01
48 #define PCI_ACX100_REGION1_SIZE 0x1000 /* Memory size - 4K bytes */
49 #define PCI_ACX100_REGION2 0x02
50 #define PCI_ACX100_REGION2_SIZE 0x10000 /* Memory size - 64K bytes */
52 #define PCI_ACX111_REGION1 0x00
53 #define PCI_ACX111_REGION1_SIZE 0x2000 /* Memory size - 8K bytes */
54 #define PCI_ACX111_REGION2 0x01
55 #define PCI_ACX111_REGION2_SIZE 0x20000 /* Memory size - 128K bytes */
57 /* Texas Instruments Vendor ID */
58 #define PCI_VENDOR_ID_TI 0x104c
60 /* ACX100 22Mb/s WLAN controller */
61 #define PCI_DEVICE_ID_TI_TNETW1100A 0x8400
62 #define PCI_DEVICE_ID_TI_TNETW1100B 0x8401
64 /* ACX111 54Mb/s WLAN controller */
65 #define PCI_DEVICE_ID_TI_TNETW1130 0x9066
67 /* PCI Class & Sub-Class code, Network-'Other controller' */
68 #define PCI_CLASS_NETWORK_OTHERS 0x0280
70 #define CARD_EEPROM_ID_SIZE 6
72 #ifndef PCI_D0
73 /* From include/linux/pci.h */
74 #define PCI_D0 0
75 #define PCI_D1 1
76 #define PCI_D2 2
77 #define PCI_D3hot 3
78 #define PCI_D3cold 4
79 #define PCI_UNKNOWN 5
80 #define PCI_POWER_ERROR -1
81 #endif
82 #endif /* CONFIG_PCI */
84 /***********************************************************************
87 static irqreturn_t acxpci_i_interrupt(int irq, void *dev_id);
89 static void disable_acx_irq(acx_device_t * adev);
91 static int acxpci_e_open(struct ieee80211_hw *hw);
92 static void acxpci_e_close(struct ieee80211_hw *hw);
93 static void acxpci_s_up(struct ieee80211_hw *hw);
94 static void acxpci_s_down(struct ieee80211_hw *hw);
96 /* Handle PCI posting properly:
97 * Make sure that writes reach the adapter in case they require to be executed
98 * *before* the next write, by reading a random (and safely accessible) register.
99 * This call has to be made if there is no read following (which would flush the data
100 * to the adapter), yet the written data has to reach the adapter immediately. */
101 static inline void write_flush(acx_device_t * adev)
103 /* readb(adev->iobase + adev->io[ACX_IO_INFO_MAILBOX_OFFS]); */
104 /* faster version (accesses the first register, ACX_IO_SOFT_RESET,
105 * which should also be safe): */
106 readb(adev->iobase);
109 static inline int adev_present(acx_device_t * adev)
111 /* fast version (accesses the first register, ACX_IO_SOFT_RESET,
112 * which should be safe): */
113 return acx_readl(adev->iobase) != 0xffffffff;
117 /***********************************************************************
119 static inline txdesc_t *get_txdesc(acx_device_t * adev, int index)
121 return (txdesc_t *) (((u8 *) adev->txdesc_start) +
122 index * adev->txdesc_size);
125 static inline txdesc_t *advance_txdesc(acx_device_t * adev, txdesc_t * txdesc,
126 int inc)
128 return (txdesc_t *) (((u8 *) txdesc) + inc * adev->txdesc_size);
131 static txhostdesc_t *get_txhostdesc(acx_device_t * adev, txdesc_t * txdesc)
133 int index = (u8 *) txdesc - (u8 *) adev->txdesc_start;
135 FN_ENTER;
137 if (unlikely(ACX_DEBUG && (index % adev->txdesc_size))) {
138 acx_log(LOG_WARNING, L_ANY, "bad txdesc ptr %p\n", txdesc);
139 return NULL;
141 index /= adev->txdesc_size;
142 if (unlikely(ACX_DEBUG && (index >= TX_CNT))) {
143 acx_log(LOG_WARNING, L_ANY, "bad txdesc ptr %p\n", txdesc);
144 return NULL;
147 FN_EXIT0;
149 return &adev->txhostdesc_start[index * 2];
156 /***********************************************************************
157 ** EEPROM and PHY read/write helpers
159 /***********************************************************************
160 ** acxpci_read_eeprom_byte
162 ** Function called to read an octet in the EEPROM.
164 ** This function is used by acxpci_e_probe to check if the
165 ** connected card is a legal one or not.
167 ** Arguments:
168 ** adev ptr to acx_device structure
169 ** addr address to read in the EEPROM
170 ** charbuf ptr to a char. This is where the read octet
171 ** will be stored
174 int acxpci_read_eeprom_byte(acx_device_t * adev, u32 addr, u8 * charbuf)
176 int result;
177 int count;
179 FN_ENTER;
181 write_reg32(adev, ACX_IO_EEPROM_CFG, 0);
182 write_reg32(adev, ACX_IO_EEPROM_ADDR, addr);
183 write_flush(adev);
184 write_reg32(adev, ACX_IO_EEPROM_CTL, 2);
186 count = 0xffff;
187 while (read_reg16(adev, ACX_IO_EEPROM_CTL)) {
188 /* scheduling away instead of CPU burning loop
189 * doesn't seem to work here at all:
190 * awful delay, sometimes also failure.
191 * Doesn't matter anyway (only small delay). */
192 if (unlikely(!--count)) {
193 acx_log(LOG_WARNING, L_ANY,
194 "%s: timeout waiting for EEPROM read\n",
195 wiphy_name(adev->ieee->wiphy));
196 result = NOT_OK;
197 goto fail;
199 cpu_relax();
202 *charbuf = read_reg8(adev, ACX_IO_EEPROM_DATA);
203 acx_log(LOG_DEBUG, L_REALLYVERBOSE, "EEPROM at 0x%04X = 0x%02X\n",
204 addr, *charbuf);
205 result = OK;
207 fail:
208 FN_EXIT1(result);
209 return result;
213 /***********************************************************************
214 ** We don't lock hw accesses here since we never r/w eeprom in IRQ
215 ** Note: this function sleeps only because of GFP_KERNEL alloc
217 #ifdef UNUSED
219 acxpci_s_write_eeprom(acx_device_t * adev, u32 addr, u32 len,
220 const u8 * charbuf)
222 u8 *data_verify = NULL;
223 unsigned long flags;
224 int count, i;
225 int result = NOT_OK;
226 u16 gpio_orig;
228 acx_log(LOG_WARNING, L_ANY, "WARNING! I would write to EEPROM now. "
229 "Since I really DON'T want to unless you know "
230 "what you're doing (THIS CODE WILL PROBABLY "
231 "NOT WORK YET!), I will abort that now. And "
232 "definitely make sure to make a "
233 "/proc/driver/acx_wlan0_eeprom backup copy first!!! "
234 "(the EEPROM content includes the PCI config header!! "
235 "If you kill important stuff, then you WILL "
236 "get in trouble and people DID get in trouble already)\n");
237 return OK;
239 FN_ENTER;
241 data_verify = kmalloc(len, GFP_KERNEL);
242 if (!data_verify) {
243 goto end;
246 /* first we need to enable the OE (EEPROM Output Enable) GPIO line
247 * to be able to write to the EEPROM.
248 * NOTE: an EEPROM writing success has been reported,
249 * but you probably have to modify GPIO_OUT, too,
250 * and you probably need to activate a different GPIO
251 * line instead! */
252 gpio_orig = read_reg16(adev, ACX_IO_GPIO_OE);
253 write_reg16(adev, ACX_IO_GPIO_OE, gpio_orig & ~1);
254 write_flush(adev);
256 /* ok, now start writing the data out */
257 for (i = 0; i < len; i++) {
258 write_reg32(adev, ACX_IO_EEPROM_CFG, 0);
259 write_reg32(adev, ACX_IO_EEPROM_ADDR, addr + i);
260 write_reg32(adev, ACX_IO_EEPROM_DATA, *(charbuf + i));
261 write_flush(adev);
262 write_reg32(adev, ACX_IO_EEPROM_CTL, 1);
264 count = 0xffff;
265 while (read_reg16(adev, ACX_IO_EEPROM_CTL)) {
266 if (unlikely(!--count)) {
267 acx_log(LOG_WARNING, L_ANY, "WARNING, DANGER!!! "
268 "Timeout waiting for EEPROM write\n");
269 goto end;
271 cpu_relax();
275 /* disable EEPROM writing */
276 write_reg16(adev, ACX_IO_GPIO_OE, gpio_orig);
277 write_flush(adev);
279 /* now start a verification run */
280 for (i = 0; i < len; i++) {
281 write_reg32(adev, ACX_IO_EEPROM_CFG, 0);
282 write_reg32(adev, ACX_IO_EEPROM_ADDR, addr + i);
283 write_flush(adev);
284 write_reg32(adev, ACX_IO_EEPROM_CTL, 2);
286 count = 0xffff;
287 while (read_reg16(adev, ACX_IO_EEPROM_CTL)) {
288 if (unlikely(!--count)) {
289 acx_log(LOG_WARNING, L_ANY,
290 "timeout waiting for EEPROM read\n");
291 goto end;
293 cpu_relax();
296 data_verify[i] = read_reg16(adev, ACX_IO_EEPROM_DATA);
299 if (0 == memcmp(charbuf, data_verify, len))
300 result = OK; /* read data matches, success */
302 end:
303 kfree(data_verify);
304 FN_EXIT1(result);
305 return result;
307 #endif /* UNUSED */
310 /***********************************************************************
311 ** acxpci_s_read_phy_reg
313 ** Messing with rx/tx disabling and enabling here
314 ** (write_reg32(adev, ACX_IO_ENABLE, 0b000000xx)) kills traffic
316 int acxpci_s_read_phy_reg(acx_device_t * adev, u32 reg, u8 * charbuf)
318 int result = NOT_OK;
319 int count;
321 FN_ENTER;
323 write_reg32(adev, ACX_IO_PHY_ADDR, reg);
324 write_flush(adev);
325 write_reg32(adev, ACX_IO_PHY_CTL, 2);
327 count = 0xffff;
328 while (read_reg32(adev, ACX_IO_PHY_CTL)) {
329 /* scheduling away instead of CPU burning loop
330 * doesn't seem to work here at all:
331 * awful delay, sometimes also failure.
332 * Doesn't matter anyway (only small delay). */
333 if (unlikely(!--count)) {
334 acx_log(LOG_WARNING, L_ANY,
335 "%s: timeout waiting for phy read\n",
336 wiphy_name(adev->ieee->wiphy));
337 *charbuf = 0;
338 goto fail;
340 cpu_relax();
343 acx_log(LOG_DEBUG, L_REALLYVERBOSE, "count was %u\n", count);
344 *charbuf = read_reg8(adev, ACX_IO_PHY_DATA);
346 acx_log(LOG_DEBUG, L_REALLYVERBOSE, "radio PHY at 0x%04X = 0x%02X\n",
347 *charbuf, reg);
348 result = OK;
349 goto fail; /* silence compiler warning */
350 fail:
351 FN_EXIT1(result);
352 return result;
356 /***********************************************************************
358 int acxpci_s_write_phy_reg(acx_device_t * adev, u32 reg, u8 value)
360 FN_ENTER;
362 /* mprusko said that 32bit accesses result in distorted sensitivity
363 * on his card. Unconfirmed, looks like it's not true (most likely since we
364 * now properly flush writes). */
365 write_reg32(adev, ACX_IO_PHY_DATA, value);
366 write_reg32(adev, ACX_IO_PHY_ADDR, reg);
367 write_flush(adev);
368 write_reg32(adev, ACX_IO_PHY_CTL, 1);
369 write_flush(adev);
370 acx_log(LOG_DEBUG, L_REALLYVERBOSE,
371 "radio PHY write 0x%02X at 0x%04X\n",
372 value, reg);
374 FN_EXIT0;
375 return OK;
379 #define NO_AUTO_INCREMENT 1
381 /***********************************************************************
382 ** acxpci_s_write_fw
384 ** Write the firmware image into the card.
386 ** Arguments:
387 ** adev wlan device structure
388 ** fw_image firmware image.
390 ** Returns:
391 ** 1 firmware image corrupted
392 ** 0 success
394 ** Standard csum implementation + write to IO
396 static int
397 acxpci_s_write_fw(acx_device_t * adev, const firmware_image_t *fw_image,
398 u32 offset)
400 int len, size;
401 u32 sum, v32;
402 /* we skip the first four bytes which contain the control sum */
404 const u8 *p = (u8 *) fw_image + 4;
406 FN_ENTER;
408 /* start the image checksum by adding the image size value */
409 sum = p[0] + p[1] + p[2] + p[3];
410 p += 4;
412 write_reg32(adev, ACX_IO_SLV_END_CTL, 0);
414 #if NO_AUTO_INCREMENT
415 write_reg32(adev, ACX_IO_SLV_MEM_CTL, 0); /* use basic mode */
416 #else
417 write_reg32(adev, ACX_IO_SLV_MEM_CTL, 1); /* use autoincrement mode */
418 write_reg32(adev, ACX_IO_SLV_MEM_ADDR, offset); /* configure start address */
419 write_flush(adev);
420 #endif
422 len = 0;
423 size = le32_to_cpu(fw_image->size) & (~3);
425 while (likely(len < size)) {
426 v32 = be32_to_cpu(*(u32 *) p);
427 sum += p[0] + p[1] + p[2] + p[3];
428 p += 4;
429 len += 4;
431 #if NO_AUTO_INCREMENT
432 write_reg32(adev, ACX_IO_SLV_MEM_ADDR, offset + len - 4);
433 write_flush(adev);
434 #endif
435 write_reg32(adev, ACX_IO_SLV_MEM_DATA, v32);
438 acx_log(LOG_DEBUG, L_REALLYVERBOSE,
439 "firmware written, size:%d sum1:%x sum2:%x\n",
440 size, sum, le32_to_cpu(fw_image->chksum));
442 /* compare our checksum with the stored image checksum */
443 FN_EXIT1(sum != le32_to_cpu(fw_image->chksum));
444 return (sum != le32_to_cpu(fw_image->chksum));
448 /***********************************************************************
449 ** acxpci_s_validate_fw
451 ** Compare the firmware image given with
452 ** the firmware image written into the card.
454 ** Arguments:
455 ** adev wlan device structure
456 ** fw_image firmware image.
458 ** Returns:
459 ** NOT_OK firmware image corrupted or not correctly written
460 ** OK success
462 ** Origin: Standard csum + Read IO
464 static int
465 acxpci_s_validate_fw(acx_device_t * adev, const firmware_image_t *fw_image,
466 u32 offset)
468 u32 sum, v32, w32;
469 int len, size;
470 int result = OK;
471 /* we skip the first four bytes which contain the control sum */
472 const u8 *p = (u8 *) fw_image + 4;
474 FN_ENTER;
476 /* start the image checksum by adding the image size value */
477 sum = p[0] + p[1] + p[2] + p[3];
478 p += 4;
480 write_reg32(adev, ACX_IO_SLV_END_CTL, 0);
482 #if NO_AUTO_INCREMENT
483 write_reg32(adev, ACX_IO_SLV_MEM_CTL, 0); /* use basic mode */
484 #else
485 write_reg32(adev, ACX_IO_SLV_MEM_CTL, 1); /* use autoincrement mode */
486 write_reg32(adev, ACX_IO_SLV_MEM_ADDR, offset); /* configure start address */
487 #endif
489 len = 0;
490 size = le32_to_cpu(fw_image->size) & (~3);
492 while (likely(len < size)) {
493 v32 = be32_to_cpu(*(u32 *) p);
494 p += 4;
495 len += 4;
497 #if NO_AUTO_INCREMENT
498 write_reg32(adev, ACX_IO_SLV_MEM_ADDR, offset + len - 4);
499 #endif
500 w32 = read_reg32(adev, ACX_IO_SLV_MEM_DATA);
502 if (unlikely(w32 != v32)) {
503 acx_log(LOG_WARNING, L_ANY,"FATAL: firmware upload: "
504 "data parts at offset %d don't match "
505 "(0x%08X vs. 0x%08X)! I/O timing issues "
506 "or defective memory, with DWL-xx0+? "
507 "ACX_IO_WIDTH=16 may help. Please report\n",
508 len, v32, w32);
509 result = NOT_OK;
510 break;
513 sum +=
514 (u8) w32 + (u8) (w32 >> 8) + (u8) (w32 >> 16) +
515 (u8) (w32 >> 24);
518 /* sum control verification */
519 if (result != NOT_OK) {
520 if (sum != le32_to_cpu(fw_image->chksum)) {
521 acx_log(LOG_WARNING, L_ANY, "FATAL: firmware upload: "
522 "checksums don't match!\n");
523 result = NOT_OK;
527 FN_EXIT1(result);
528 return result;
532 /***********************************************************************
533 ** acxpci_s_upload_fw
535 ** Called from acx_reset_dev
537 ** Origin: Derived from FW dissection
539 static int acxpci_s_upload_fw(acx_device_t * adev)
541 firmware_image_t *fw_image = NULL;
542 int res = NOT_OK;
543 int try;
544 u32 file_size;
545 char filename[sizeof("tiacx1NNcNN")];
547 FN_ENTER;
549 /* print exact chipset and radio ID to make sure people
550 * really get a clue on which files exactly they need to provide.
551 * Firmware loading is a frequent end-user PITA with these chipsets.
553 acx_log(LOG_INFO, L_ANY,
554 "need firmware for acx1%02d chipset "
555 "with radio ID %02X\n",
556 IS_ACX111(adev)*11, adev->radio_type);
557 acx_log(LOG_INFO, L_ANY, "Please provide via firmware hotplug:\n");
558 acx_log(LOG_INFO, L_ANY, "either combined firmware "
559 "(single file named 'tiacx1%02dc%02X')\n"
560 "or two files (base firmware file 'tiacx1%02d' "
561 "+ radio fw 'tiacx1%02dr%02X')\n",
562 IS_ACX111(adev)*11, adev->radio_type,
563 IS_ACX111(adev)*11,
564 IS_ACX111(adev)*11, adev->radio_type
567 /* print exact chipset and radio ID to make sure people really get a
568 * clue on which files exactly they are supposed to provide, since
569 * firmware loading is the biggest enduser PITA with these chipsets.
570 * Not printing radio ID in 0xHEX in order to not confuse them into
571 * wrong file naming
572 * COMMENTED OUT: this was already printed above
574 // printk( "acx: need to load firmware for acx1%02d chipset with radio ID %02x, please provide via firmware hotplug:\n"
575 // "acx: either one file only (<c>ombined firmware image file, radio-specific) or two files (radio-less base image file *plus* separate <r>adio-specific extension file)\n",
576 // IS_ACX111(adev)*11, adev->radio_type);
578 /* Try combined, then main image */
579 adev->need_radio_fw = 0;
580 snprintf(filename, sizeof(filename), "tiacx1%02dc%02X",
581 IS_ACX111(adev) * 11, adev->radio_type);
583 fw_image = acx_s_read_fw(adev->bus_dev, filename, &file_size);
584 if (!fw_image) {
585 adev->need_radio_fw = 1;
586 filename[sizeof("tiacx1NN") - 1] = '\0';
587 fw_image =
588 acx_s_read_fw(adev->bus_dev, filename, &file_size);
589 if (!fw_image) {
590 FN_EXIT1(NOT_OK);
591 return NOT_OK;
595 for (try = 1; try <= 5; try++) {
596 res = acxpci_s_write_fw(adev, fw_image, 0);
597 acx_log(LOG_DEBUG, L_INIT | L_REALLYVERBOSE,
598 "acx_write_fw (main/combined): %d\n", res);
599 if (OK == res) {
600 res = acxpci_s_validate_fw(adev, fw_image, 0);
601 acx_log(LOG_DEBUG, L_INIT | L_REALLYVERBOSE,
602 "acx_validate_fw (main/combined): %d\n", res);
605 if (OK == res) {
606 SET_BIT(adev->dev_state_mask, ACX_STATE_FW_LOADED);
607 break;
609 acx_log(LOG_WARNING, L_ANY,
610 "firmware upload attempt #%d FAILED, "
611 "retrying...\n", try);
612 acx_s_mwait(1000); /* better wait for a while... */
615 vfree(fw_image);
617 FN_EXIT1(res);
618 return res;
622 /***********************************************************************
623 ** acxpci_s_upload_radio
625 ** Uploads the appropriate radio module firmware into the card.
627 ** Origin: Standard Read/Write to IO
629 int acxpci_s_upload_radio(acx_device_t * adev)
631 acx_ie_memmap_t mm;
632 firmware_image_t *radio_image;
633 acx_cmd_radioinit_t radioinit;
634 int res = NOT_OK;
635 int try;
636 u32 offset;
637 u32 size;
638 char filename[sizeof("tiacx1NNrNN")];
640 if (!adev->need_radio_fw)
641 return OK;
643 FN_ENTER;
645 acx_s_interrogate(adev, &mm, ACX1xx_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;
1505 /** Finished with private interface **/
1507 /** begin board specific inits **/
1508 pci_set_drvdata(pdev, ieee);
1510 /* Enable the PCI device */
1511 if (pci_enable_device(pdev)) {
1512 acx_log(LOG_WARNING, L_ANY, "pci_enable_device() FAILED\n");
1513 result = -ENODEV;
1514 goto fail_pci_enable_device;
1517 /* enable busmastering (required for CardBus) */
1518 pci_set_master(pdev);
1521 /* chiptype is u8 but id->driver_data is ulong
1522 ** Works for now (possible values are 1 and 2) */
1523 chip_type = (u8) id->driver_data;
1524 /* acx100 and acx111 have different PCI memory regions */
1525 if (chip_type == CHIPTYPE_ACX100) {
1526 chip_name = "ACX100";
1527 mem_region1 = PCI_ACX100_REGION1;
1528 mem_region1_size = PCI_ACX100_REGION1_SIZE;
1530 mem_region2 = PCI_ACX100_REGION2;
1531 mem_region2_size = PCI_ACX100_REGION2_SIZE;
1532 } else if (chip_type == CHIPTYPE_ACX111) {
1533 chip_name = "ACX111";
1534 mem_region1 = PCI_ACX111_REGION1;
1535 mem_region1_size = PCI_ACX111_REGION1_SIZE;
1537 mem_region2 = PCI_ACX111_REGION2;
1538 mem_region2_size = PCI_ACX111_REGION2_SIZE;
1539 } else {
1540 acx_log(LOG_WARNING, L_ANY,
1541 "unknown chip type 0x%04X\n", chip_type);
1542 goto fail_unknown_chiptype;
1545 /* Figure out our resources
1547 * Request our PCI IO regions
1549 err = pci_request_region(pdev, mem_region1, "acx_1");
1550 if (err) {
1551 acx_log(LOG_WARNING, L_ANY, "pci_request_region (1/2) FAILED!"
1552 "No cardbus support in kernel?\n");
1553 goto fail_request_mem_region1;
1556 phymem1 = pci_resource_start(pdev, mem_region1);
1558 err = pci_request_region(pdev, mem_region2, "acx_2");
1559 if (err) {
1560 acx_log(LOG_WARNING, L_ANY, "pci_request_region (2/2) FAILED!\n");
1561 goto fail_request_mem_region2;
1564 phymem2 = pci_resource_start(pdev, mem_region2);
1567 * We got them? Map them!
1569 * We pass 0 as the third argument to pci_iomap(): it will map the full
1570 * region in this case, which is what we want.
1573 mem1 = pci_iomap(pdev, mem_region1, 0);
1574 if (!mem1) {
1575 acx_log(LOG_WARNING, L_ANY, "ioremap() FAILED\n");
1576 goto fail_ioremap1;
1579 mem2 = pci_iomap(pdev, mem_region2, 0);
1580 if (!mem2) {
1581 acx_log(LOG_WARNING, L_ANY, "ioremap() #2 FAILED\n");
1582 goto fail_ioremap2;
1585 acx_log(LOG_INFO, L_ANY, "found %s-based wireless network card at %s, "
1586 "irq:%d, phymem1:0x%lX, phymem2:0x%lX, mem1:0x%p, "
1587 "mem1_size:%ld, mem2:0x%p, mem2_size:%ld\n",
1588 chip_name, pci_name(pdev), pdev->irq, phymem1, phymem2,
1589 mem1, mem_region1_size, mem2, mem_region2_size);
1590 //log(L_ANY, "initial debug setting is 0x%04X\n", acx_debug);
1591 adev->chip_type = chip_type;
1592 adev->chip_name = chip_name;
1593 adev->io = (CHIPTYPE_ACX100 == chip_type) ? IO_ACX100 : IO_ACX111;
1594 adev->membase = phymem1;
1595 adev->iobase = mem1;
1596 adev->membase2 = phymem2;
1597 adev->iobase2 = mem2;
1598 adev->irq = pdev->irq;
1601 if (0 == pdev->irq) {
1602 acx_log(LOG_WARNING, L_ANY, "can't use IRQ 0\n");
1603 goto fail_irq;
1605 SET_IEEE80211_DEV(ieee, &pdev->dev);
1607 /* request shared IRQ handler */
1608 if (request_irq
1609 (adev->irq, acxpci_i_interrupt, IRQF_SHARED, KBUILD_MODNAME, adev)) {
1610 acx_log(LOG_WARNING, L_ANY, "%s: request_irq FAILED\n",
1611 wiphy_name(adev->ieee->wiphy));
1612 result = -EAGAIN;
1613 goto done;
1615 acx_log(LOG_DEBUG, L_IRQ | L_REALLYVERBOSE,
1616 "request_irq %d successful\n", adev->irq);
1618 /* to find crashes due to weird driver access
1619 * to unconfigured interface (ifup) */
1620 adev->mgmt_timer.function = (void (*)(unsigned long))0x0000dead;
1623 #ifdef NONESSENTIAL_FEATURES
1624 acx_show_card_eeprom_id(adev);
1625 #endif /* NONESSENTIAL_FEATURES */
1628 /* ok, pci setup is finished, now start initializing the card */
1630 /* NB: read_reg() reads may return bogus data before reset_dev(),
1631 * since the firmware which directly controls large parts of the I/O
1632 * registers isn't initialized yet.
1633 * acx100 seems to be more affected than acx111 */
1634 if (OK != acxpci_s_reset_dev(adev))
1635 goto fail_reset;
1637 if (IS_ACX100(adev)) {
1638 /* ACX100: configopt struct in cmd mailbox - directly after reset */
1639 memcpy_fromio(&co, adev->cmd_area, sizeof(co));
1642 if (OK != acx_s_init_mac(adev))
1643 goto fail_init_mac;
1645 if (IS_ACX111(adev)) {
1646 /* ACX111: configopt struct needs to be queried after full init */
1647 acx_s_interrogate(adev, &co, ACX111_IE_CONFIG_OPTIONS);
1649 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
1650 if (OK != acxpci_read_eeprom_byte(adev, 0x05, &adev->eeprom_version))
1651 goto fail_read_eeprom_version;
1653 acx_s_parse_configoption(adev, &co);
1654 acx_s_set_defaults(adev);
1655 acx_s_get_firmware_version(adev); /* needs to be after acx_s_init_mac() */
1656 acx_display_hardware_details(adev);
1658 /* Register the card, AFTER everything else has been set up,
1659 * since otherwise an ioctl could step on our feet due to
1660 * firmware operations happening in parallel or uninitialized data */
1663 acx_proc_register_entries(ieee);
1665 /* Now we have our device, so make sure the kernel doesn't try
1666 * to send packets even though we're not associated to a network yet */
1668 /* after register_netdev() userspace may start working with dev
1669 * (in particular, on other CPUs), we only need to up the sem */
1670 /* acx_sem_unlock(adev); */
1672 acx_log(LOG_INFO, L_ANY, "driver version " ACX_RELEASE
1673 ": net device %s, driver compiled "
1674 "against wireless extensions %d and Linux %s\n",
1675 wiphy_name(adev->ieee->wiphy), WIRELESS_EXT, UTS_RELEASE);
1677 MAC_COPY(adev->ieee->wiphy->perm_addr, adev->dev_addr);
1679 acx_log(LOG_INFO, L_IRQ | L_INIT, "using IRQ %d\n", pdev->irq);
1681 /** done with board specific setup **/
1683 /* need to be able to restore PCI state after a suspend */
1684 #ifdef CONFIG_PM
1685 pci_save_state(pdev);
1686 #endif
1688 err = acx_setup_modes(adev);
1689 if (err) {
1690 acx_log(LOG_WARNING, L_ANY, "can't register hwmode\n");
1691 goto fail_register_netdev;
1694 acx_init_task_scheduler(adev);
1695 err = ieee80211_register_hw(ieee);
1696 if (OK != err) {
1697 acx_log(LOG_WARNING, L_ANY,
1698 "ieee80211_register_hw() FAILED: %d\n", err);
1699 goto fail_register_netdev;
1701 #if CMD_DISCOVERY
1702 great_inquisitor(adev);
1703 #endif
1705 result = OK;
1706 goto done;
1708 /* error paths: undo everything in reverse order... */
1711 acxpci_s_delete_dma_regions(adev);
1712 pci_set_drvdata(pdev, NULL);
1714 fail_init_mac:
1715 fail_read_eeprom_version:
1716 fail_reset:
1718 fail_alloc_netdev:
1719 fail_irq:
1720 pci_iounmap(pdev, mem2);
1722 fail_ioremap2:
1723 pci_iounmap(pdev, mem1);
1725 fail_ioremap1:
1726 pci_release_region(pdev, mem_region2);
1728 fail_request_mem_region2:
1729 pci_release_region(pdev, mem_region1);
1731 fail_request_mem_region1:
1732 fail_unknown_chiptype:
1733 pci_disable_device(pdev);
1735 fail_pci_enable_device:
1736 #ifdef CONFIG_PM
1737 pci_set_power_state(pdev, PCI_D3hot);
1738 #endif
1740 fail_register_netdev:
1741 ieee80211_free_hw(ieee);
1742 done:
1743 FN_EXIT1(result);
1744 return result;
1748 /***********************************************************************
1749 ** acxpci_e_remove
1751 ** Shut device down (if not hot unplugged)
1752 ** and deallocate PCI resources for the acx chip.
1754 ** pdev - ptr to PCI device structure containing info about pci configuration
1756 static void __devexit acxpci_e_remove(struct pci_dev *pdev)
1758 struct ieee80211_hw *hw = (struct ieee80211_hw *)pci_get_drvdata(pdev);
1759 acx_device_t *adev = ieee2adev(hw);
1760 unsigned long mem_region1, mem_region2;
1761 unsigned long flags;
1762 FN_ENTER;
1764 if (!hw) {
1765 acx_log(LOG_DEBUG, L_REALLYVERBOSE,
1766 "%s: card is unused. Skipping any release code\n",
1767 __func__);
1768 goto end;
1771 /* If device wasn't hot unplugged... */
1772 if (adev_present(adev)) {
1774 /* disable both Tx and Rx to shut radio down properly */
1775 if (adev->initialized) {
1776 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_TX, NULL, 0);
1777 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_RX, NULL, 0);
1778 adev->initialized = 0;
1780 #ifdef REDUNDANT
1781 /* put the eCPU to sleep to save power
1782 * Halting is not possible currently,
1783 * since not supported by all firmware versions */
1784 acx_s_issue_cmd(adev, ACX100_CMD_SLEEP, NULL, 0);
1785 #endif
1786 acx_lock(adev, flags);
1787 /* disable power LED to save power :-) */
1788 acx_log(LOG_INFO, L_INIT,
1789 "switching off power LED to save power\n");
1790 acxpci_l_power_led(adev, 0);
1791 /* stop our eCPU */
1792 if (IS_ACX111(adev)) {
1793 /* FIXME: does this actually keep halting the eCPU?
1794 * I don't think so...
1796 acxpci_l_reset_mac(adev);
1797 } else {
1798 u16 temp;
1799 /* halt eCPU */
1800 temp = read_reg16(adev, ACX_IO_ECPU_CTRL) | 0x1;
1801 write_reg16(adev, ACX_IO_ECPU_CTRL, temp);
1802 write_flush(adev);
1804 acx_unlock(adev, flags);
1808 /* unregister the device to not let the kernel
1809 * (e.g. ioctls) access a half-deconfigured device
1810 * NB: this will cause acxpci_e_close() to be called,
1811 * thus we shouldn't call it under sem!
1813 acx_log(LOG_INFO, L_INIT,
1814 "removing device %s\n", wiphy_name(adev->ieee->wiphy));
1815 ieee80211_unregister_hw(adev->ieee);
1817 /* unregister_netdev ensures that no references to us left.
1818 * For paranoid reasons we continue to follow the rules */
1819 acx_sem_lock(adev);
1821 if (adev->dev_state_mask & ACX_STATE_IFACE_UP) {
1822 acxpci_s_down(hw);
1823 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
1826 acx_proc_unregister_entries(adev->ieee);
1828 if (IS_ACX100(adev)) {
1829 mem_region1 = PCI_ACX100_REGION1;
1830 mem_region2 = PCI_ACX100_REGION2;
1831 } else {
1832 mem_region1 = PCI_ACX111_REGION1;
1833 mem_region2 = PCI_ACX111_REGION2;
1836 /* finally, clean up PCI bus state */
1837 acxpci_s_delete_dma_regions(adev);
1838 if (adev->iobase)
1839 iounmap(adev->iobase);
1840 if (adev->iobase2)
1841 iounmap(adev->iobase2);
1842 release_mem_region(pci_resource_start(pdev, mem_region1),
1843 pci_resource_len(pdev, mem_region1));
1844 release_mem_region(pci_resource_start(pdev, mem_region2),
1845 pci_resource_len(pdev, mem_region2));
1846 pci_disable_device(pdev);
1848 /* remove dev registration */
1849 pci_set_drvdata(pdev, NULL);
1851 acx_sem_unlock(adev);
1853 /* Free netdev (quite late,
1854 * since otherwise we might get caught off-guard
1855 * by a netdev timeout handler execution
1856 * expecting to see a working dev...) */
1857 ieee80211_free_hw(adev->ieee);
1859 /* put device into ACPI D3 mode (shutdown) */
1860 #ifdef CONFIG_PM
1861 pci_set_power_state(pdev, PCI_D3hot);
1862 #endif
1863 end:
1864 FN_EXIT0;
1868 /***********************************************************************
1869 ** TODO: PM code needs to be fixed / debugged / tested.
1871 #ifdef CONFIG_PM
1872 static int
1873 acxpci_e_suspend(struct pci_dev *pdev, pm_message_t state)
1875 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1876 acx_device_t *adev;
1878 FN_ENTER;
1879 acx_log(LOG_WARNING, L_ANY, "suspend handler is experimental!\n");
1880 acx_log(LOG_INFO, L_ANY, "suspend: dev %p\n", hw);
1882 /* if (!netif_running(ndev))
1883 goto end;
1885 adev = ieee2adev(hw);
1886 acx_log(LOG_INFO, L_ANY, "suspend: adev %p\n", adev);
1888 acx_sem_lock(adev);
1890 ieee80211_unregister_hw(hw); /* this one cannot sleep */
1891 acxpci_s_down(hw);
1892 /* down() does not set it to ACX_IRQ_ALL, but here we really want that */
1893 write_reg16(adev, ACX_IO_IRQ_MASK, ACX_IRQ_ALL);
1894 write_reg16(adev, ACX_IO_FEMR, 0x0);
1895 acxpci_s_delete_dma_regions(adev);
1896 pci_save_state(pdev);
1897 pci_set_power_state(pdev, PCI_D3hot);
1899 acx_sem_unlock(adev);
1900 FN_EXIT0;
1901 return OK;
1905 static int acxpci_e_resume(struct pci_dev *pdev)
1907 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1908 acx_device_t *adev;
1910 FN_ENTER;
1912 acx_log(LOG_WARNING, L_ANY, "resume handler is experimental!\n");
1913 acx_log(LOG_INFO, L_ANY, "resume: got dev %p\n", hw);
1916 adev = ieee2adev(hw);
1917 acx_log(LOG_INFO, L_ANY, "resume: got adev %p\n", adev);
1919 acx_sem_lock(adev);
1921 pci_set_power_state(pdev, PCI_D0);
1922 acx_log(LOG_INFO, L_ANY, "resume: power state PCI_D0 set\n");
1923 pci_restore_state(pdev);
1924 acx_log(LOG_INFO, L_ANY, "resume: PCI state restored\n");
1926 if (OK != acxpci_s_reset_dev(adev))
1927 goto end_unlock;
1928 acx_log(LOG_INFO, L_ANY, "resume: device reset done\n");
1929 if (OK != acx_s_init_mac(adev))
1930 goto end_unlock;
1931 acx_log(LOG_INFO, L_ANY, "resume: init MAC done\n");
1933 acxpci_s_up(hw);
1934 acx_log(LOG_INFO, L_ANY, "resume: acx up done\n");
1936 /* now even reload all card parameters as they were before suspend,
1937 * and possibly be back in the network again already :-) */
1938 if (ACX_STATE_IFACE_UP & adev->dev_state_mask) {
1939 adev->set_mask = GETSET_ALL;
1940 acx_s_update_card_settings(adev);
1941 acx_log(LOG_INFO, L_ANY, "resume: settings updated\n");
1943 ieee80211_register_hw(hw);
1944 acx_log(LOG_INFO, L_ANY, "resume: device attached\n");
1946 end_unlock:
1947 acx_sem_unlock(adev);
1948 /* we need to return OK here anyway, right? */
1949 FN_EXIT0;
1950 return OK;
1952 #endif /* CONFIG_PM */
1953 #endif /* CONFIG_PCI */
1955 /***********************************************************************
1956 ** acxpci_s_up
1958 ** This function is called by acxpci_e_open (when ifconfig sets the device as up)
1960 ** Side effects:
1961 ** - Enables on-card interrupt requests
1962 ** - calls acx_s_start
1965 static void enable_acx_irq(acx_device_t * adev)
1967 FN_ENTER;
1968 write_reg16(adev, ACX_IO_IRQ_MASK, adev->irq_mask);
1969 write_reg16(adev, ACX_IO_FEMR, 0x8000);
1970 adev->irqs_active = 1;
1971 FN_EXIT0;
1974 static void acxpci_s_up(struct ieee80211_hw *hw)
1976 acx_device_t *adev = ieee2adev(hw);
1977 unsigned long flags;
1979 FN_ENTER;
1981 acx_lock(adev, flags);
1982 enable_acx_irq(adev);
1983 acx_unlock(adev, flags);
1985 /* acx fw < 1.9.3.e has a hardware timer, and older drivers
1986 ** used to use it. But we don't do that anymore, our OS
1987 ** has reliable software timers */
1988 init_timer(&adev->mgmt_timer);
1989 adev->mgmt_timer.function = acx_i_timer;
1990 adev->mgmt_timer.data = (unsigned long)adev;
1992 /* Need to set ACX_STATE_IFACE_UP first, or else
1993 ** timer won't be started by acx_set_status() */
1994 SET_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
1996 acx_s_start(adev);
1998 FN_EXIT0;
2002 /***********************************************************************
2003 ** acxpci_s_down
2005 ** NB: device may be already hot unplugged if called from acxpci_e_remove()
2007 ** Disables on-card interrupt request, stops softirq and timer, stops queue,
2008 ** sets status == STOPPED
2011 static void disable_acx_irq(acx_device_t * adev)
2013 u16 disable_irq_mask = (IS_ACX111(adev)) ?
2014 ACX111_DISABLE_ALL_IRQS :
2015 ACX100_DISABLE_ALL_IRQS;
2017 FN_ENTER;
2019 /* I guess mask is not ACX_IRQ_ALL because acx100 won't signal
2020 ** cmd completion then (needed for ifup).
2021 ** I can't ifconfig up after ifconfig down'ing on my acx100 */
2022 write_reg16(adev, ACX_IO_IRQ_MASK, disable_irq_mask);
2023 write_reg16(adev, ACX_IO_FEMR, 0x0);
2024 adev->irqs_active = 0;
2026 FN_EXIT0;
2029 static void acxpci_s_down(struct ieee80211_hw *hw)
2031 acx_device_t *adev = ieee2adev(hw);
2033 FN_ENTER;
2035 /* Disable IRQs first, so that IRQs cannot race with us */
2036 /* then wait until interrupts have finished executing on other CPUs */
2037 disable_acx_irq(adev); /* NO sem-locking here? */
2038 synchronize_irq(adev->irq);
2040 /* we really don't want to have an asynchronous tasklet disturb us
2041 ** after something vital for its job has been shut down, so
2042 ** end all remaining work now.
2044 ** NB: carrier_off (done by set_status below) would lead to
2045 ** not yet fully understood deadlock in flush_scheduled_work().
2046 ** That's why we do FLUSH first.
2048 ** NB2: we have a bad locking bug here: flush_scheduled_work()
2049 ** waits for acx_e_after_interrupt_task to complete if it is running
2050 ** on another CPU, but acx_e_after_interrupt_task
2051 ** will sleep on sem forever, because it is taken by us!
2052 ** Work around that by temporary sem unlock.
2053 ** This will fail miserably if we'll be hit by concurrent
2054 ** iwconfig or something in between. TODO! */
2055 acx_sem_unlock(adev);
2056 flush_scheduled_work();
2057 acx_sem_lock(adev);
2059 /* This is possible:
2060 ** flush_scheduled_work -> acx_e_after_interrupt_task ->
2061 ** -> set_status(ASSOCIATED) -> wake_queue()
2062 ** That's why we stop queue _after_ flush_scheduled_work
2063 ** lock/unlock is just paranoia, maybe not needed */
2065 /* kernel/timer.c says it's illegal to del_timer_sync()
2066 ** a timer which restarts itself. We guarantee this cannot
2067 ** ever happen because acx_i_timer() never does this if
2068 ** status is ACX_STATUS_0_STOPPED */
2069 del_timer_sync(&adev->mgmt_timer);
2071 FN_EXIT0;
2074 #ifdef CONFIG_NET_POLL_CONTROLLER
2075 void acxpci_net_poll_controller(struct net_device *net_dev)
2077 acx_device_t *adev = ndev2adev(net_dev);
2078 unsigned long flags;
2080 local_irq_save(flags);
2081 acxpci_i_interrupt(adev->irq, adev);
2082 local_irq_restore(flags);
2084 #endif*/ /* CONFIG_NET_POLL_CONTROLLER */
2086 /***********************************************************************
2087 ** acxpci_e_open
2089 ** Called as a result of SIOCSIFFLAGS ioctl changing the flags bit IFF_UP
2090 ** from clear to set. In other words: ifconfig up.
2092 ** Returns:
2093 ** 0 success
2094 ** >0 f/w reported error
2095 ** <0 driver reported error
2097 static int acxpci_e_open(struct ieee80211_hw *hw)
2099 acx_device_t *adev = ieee2adev(hw);
2100 int result = OK;
2102 FN_ENTER;
2104 acx_sem_lock(adev);
2106 adev->initialized = 0;
2108 /* TODO: pci_set_power_state(pdev, PCI_D0); ? */
2110 /* ifup device */
2111 acxpci_s_up(hw);
2113 /* We don't currently have to do anything else.
2114 * The setup of the MAC should be subsequently completed via
2115 * the mlme commands.
2116 * Higher layers know we're ready from dev->start==1 and
2117 * dev->tbusy==0. Our rx path knows to pass up received/
2118 * frames because of dev->flags&IFF_UP is true.
2120 ieee80211_start_queues(adev->ieee);
2122 adev->initialized = 1;
2123 acx_sem_unlock(adev);
2125 FN_EXIT1(result);
2126 return result;
2130 /***********************************************************************
2131 ** acxpci_e_close
2133 ** This function stops the network functionality of the interface (invoked
2134 ** when the user calls ifconfig <wlan> down). The tx queue is halted and
2135 ** the device is marked as down.
2137 ** Called as a result of SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
2138 ** from set to clear. I.e. called by "ifconfig DEV down"
2140 ** Returns:
2141 ** 0 success
2142 ** >0 f/w reported error
2143 ** <0 driver reported error
2145 static void acxpci_e_close(struct ieee80211_hw *hw)
2147 acx_device_t *adev = ieee2adev(hw);
2149 FN_ENTER;
2151 acx_sem_lock(adev);
2153 /* ifdown device */
2154 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
2155 if (adev->initialized) {
2156 acxpci_s_down(hw);
2159 if (adev->modes)
2160 acx_free_modes(adev);
2161 /* disable all IRQs, release shared IRQ handler */
2162 write_reg16(adev, ACX_IO_IRQ_MASK, ACX_IRQ_ALL);
2163 write_reg16(adev, ACX_IO_FEMR, 0x0);
2164 free_irq(adev->irq, adev);
2166 /* TODO: pci_set_power_state(pdev, PCI_D3hot); ? */
2168 /* We currently don't have to do anything else.
2169 * Higher layers know we're not ready from dev->start==0 and
2170 * dev->tbusy==1. Our rx path knows to not pass up received
2171 * frames because of dev->flags&IFF_UP is false.
2173 acx_sem_unlock(adev);
2175 acx_log(LOG_INFO, L_INIT, "closed device\n");
2176 FN_EXIT0;
2182 /***************************************************************
2183 ** acxpci_l_process_rxdesc
2185 ** Called directly and only from the IRQ handler
2188 #if !ACX_DEBUG
2189 static inline void log_rxbuffer(const acx_device_t * adev)
2192 #else
2193 static void log_rxbuffer(const acx_device_t * adev)
2195 register const struct rxhostdesc *rxhostdesc;
2196 int i;
2198 /* no FN_ENTER here, we don't want that */
2200 rxhostdesc = adev->rxhostdesc_start;
2201 if (unlikely(!rxhostdesc))
2202 return;
2203 for (i = 0; i < RX_CNT; i++) {
2204 if ((rxhostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2205 && (rxhostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2206 acx_log(LOG_WARNING, L_ANY, "rx: buf %d full\n", i);
2207 rxhostdesc++;
2210 #endif
2212 static void acxpci_l_process_rxdesc(acx_device_t * adev)
2214 register rxhostdesc_t *hostdesc;
2215 unsigned count, tail;
2217 FN_ENTER;
2219 if (unlikely(acx_debug & L_BUFR))
2220 log_rxbuffer(adev);
2222 /* First, have a loop to determine the first descriptor that's
2223 * full, just in case there's a mismatch between our current
2224 * rx_tail and the full descriptor we're supposed to handle. */
2225 tail = adev->rx_tail;
2226 count = RX_CNT;
2227 while (1) {
2228 hostdesc = &adev->rxhostdesc_start[tail];
2229 /* advance tail regardless of outcome of the below test */
2230 tail = (tail + 1) % RX_CNT;
2232 if ((hostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2233 && (hostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2234 break; /* found it! */
2236 if (unlikely(!--count)) /* hmm, no luck: all descs empty, bail out */
2237 goto end;
2240 /* now process descriptors, starting with the first we figured out */
2241 while (1) {
2242 acx_log(LOG_DEBUG, L_BUFR,
2243 "rx: tail=%u Ctl_16=%04X Status=%08X\n",
2244 tail, hostdesc->Ctl_16, hostdesc->Status);
2246 acx_l_process_rxbuf(adev, hostdesc->data);
2247 hostdesc->Status = 0;
2248 /* flush all writes before adapter sees CTL_HOSTOWN change */
2249 wmb();
2250 /* Host no longer owns this, needs to be LAST */
2251 CLEAR_BIT(hostdesc->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
2253 /* ok, descriptor is handled, now check the next descriptor */
2254 hostdesc = &adev->rxhostdesc_start[tail];
2256 /* if next descriptor is empty, then bail out */
2257 if (!(hostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2258 || !(hostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2259 break;
2261 tail = (tail + 1) % RX_CNT;
2263 end:
2264 adev->rx_tail = tail;
2265 FN_EXIT0;
2270 /***********************************************************************
2271 ** acxpci_i_interrupt
2273 ** IRQ handler (atomic context, must not sleep, blah, blah)
2276 /* scan is complete. all frames now on the receive queue are valid */
2277 #define INFO_SCAN_COMPLETE 0x0001
2278 #define INFO_WEP_KEY_NOT_FOUND 0x0002
2279 /* hw has been reset as the result of a watchdog timer timeout */
2280 #define INFO_WATCH_DOG_RESET 0x0003
2281 /* failed to send out NULL frame from PS mode notification to AP */
2282 /* recommended action: try entering 802.11 PS mode again */
2283 #define INFO_PS_FAIL 0x0004
2284 /* encryption/decryption process on a packet failed */
2285 #define INFO_IV_ICV_FAILURE 0x0005
2287 /* Info mailbox format:
2288 2 bytes: type
2289 2 bytes: status
2290 more bytes may follow
2291 rumors say about status:
2292 0x0000 info available (set by hw)
2293 0x0001 information received (must be set by host)
2294 0x1000 info available, mailbox overflowed (messages lost) (set by hw)
2295 but in practice we've seen:
2296 0x9000 when we did not set status to 0x0001 on prev message
2297 0x1001 when we did set it
2298 0x0000 was never seen
2299 conclusion: this is really a bitfield:
2300 0x1000 is 'info available' bit
2301 'mailbox overflowed' bit is 0x8000, not 0x1000
2302 value of 0x0000 probably means that there are no messages at all
2303 P.S. I dunno how in hell hw is supposed to notice that messages are lost -
2304 it does NOT clear bit 0x0001, and this bit will probably stay forever set
2305 after we set it once. Let's hope this will be fixed in firmware someday
2308 static void handle_info_irq(acx_device_t * adev)
2310 #if ACX_DEBUG
2311 static const char *const info_type_msg[] = {
2312 "(unknown)",
2313 "scan complete",
2314 "WEP key not found",
2315 "internal watchdog reset was done",
2316 "failed to send powersave (NULL frame) notification to AP",
2317 "encrypt/decrypt on a packet has failed",
2318 "TKIP tx keys disabled",
2319 "TKIP rx keys disabled",
2320 "TKIP rx: key ID not found",
2321 "???",
2322 "???",
2323 "???",
2324 "???",
2325 "???",
2326 "???",
2327 "???",
2328 "TKIP IV value exceeds thresh"
2330 #endif
2331 u32 info_type, info_status;
2333 info_type = acx_readl(adev->info_area);
2334 info_status = (info_type >> 16);
2335 info_type = (u16) info_type;
2337 /* inform fw that we have read this info message */
2338 acx_writel(info_type | 0x00010000, adev->info_area);
2339 write_reg16(adev, ACX_IO_INT_TRIG, INT_TRIG_INFOACK);
2340 write_flush(adev);
2342 acx_log(LOG_DEBUG, L_CTL,
2343 "info_type:%04X info_status:%04X\n", info_type, info_status);
2345 acx_log(LOG_DEBUG, L_IRQ, "got Info IRQ: status %04X type %04X: %s\n",
2346 info_status, info_type,
2347 info_type_msg[(info_type >= ARRAY_SIZE(info_type_msg)) ?
2348 0 : info_type]
2353 static void log_unusual_irq(u16 irqtype)
2356 if (!printk_ratelimit())
2357 return;
2360 printk("acx: got");
2361 if (irqtype & ACX_IRQ_RX_DATA) {
2362 printk(" Rx_Data");
2364 /* ACX_IRQ_TX_COMPLETE */
2365 if (irqtype & ACX_IRQ_TX_XFER) {
2366 printk(" Tx_Xfer");
2368 /* ACX_IRQ_RX_COMPLETE */
2369 if (irqtype & ACX_IRQ_DTIM) {
2370 printk(" DTIM");
2372 if (irqtype & ACX_IRQ_BEACON) {
2373 printk(" Beacon");
2375 if (irqtype & ACX_IRQ_TIMER) {
2376 printk(" Timer");
2378 if (irqtype & ACX_IRQ_KEY_NOT_FOUND) {
2379 printk(" Key_Not_Found");
2381 if (irqtype & ACX_IRQ_IV_ICV_FAILURE) {
2382 printk(" IV_ICV_Failure (crypto)");
2384 /* ACX_IRQ_CMD_COMPLETE */
2385 /* ACX_IRQ_INFO */
2386 if (irqtype & ACX_IRQ_OVERFLOW) {
2387 printk(" Overflow");
2389 if (irqtype & ACX_IRQ_PROCESS_ERROR) {
2390 printk(" Process_Error");
2392 /* ACX_IRQ_SCAN_COMPLETE */
2393 if (irqtype & ACX_IRQ_FCS_THRESHOLD) {
2394 printk(" FCS_Threshold");
2396 if (irqtype & ACX_IRQ_UNKNOWN) {
2397 printk(" Unknown");
2399 printk(" IRQ(s)\n");
2402 /* FIXME: update_link_quality_led was a stub - let's comment it and avoid
2403 * compiler warnings */
2405 static void update_link_quality_led(acx_device_t * adev)
2407 int qual;
2409 qual =
2410 acx_signal_determine_quality(adev->wstats.qual.level,
2411 adev->wstats.qual.noise);
2412 if (qual > adev->brange_max_quality)
2413 qual = adev->brange_max_quality;
2415 if (time_after(jiffies, adev->brange_time_last_state_change +
2416 (HZ / 2 -
2417 HZ / 2 * (unsigned long)qual /
2418 adev->brange_max_quality))) {
2419 acxpci_l_power_led(adev, (adev->brange_last_state == 0));
2420 adev->brange_last_state ^= 1; // toggle
2421 adev->brange_time_last_state_change = jiffies;
2426 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* a la orinoco.c */
2428 /* Interrupt handler bottom-half */
2429 void acx_interrupt_tasklet(struct work_struct *work)
2432 #ifdef CONFIG_ACX_MAC80211_DEBUG
2433 u32 _handled = 0x00000000;
2434 # define acxirq_handled(irq) do { _handled |= (irq); } while (0)
2435 #else
2436 # define acxirq_handled(irq) do { /* nothing */ } while (0)
2437 #endif /* CONFIG_ACX_MAC80211_DEBUG */
2438 acx_device_t *adev = container_of(work,struct acx_device, after_interrupt_task);
2439 // unsigned int irqcount = MAX_IRQLOOPS_PER_JIFFY;
2440 int irqtype;
2442 #define IRQ_ITERATE 0
2443 #if IRQ_ITERATE
2444 unsigned int irqcount = MAX_IRQLOOPS_PER_JIFFY;
2445 u16 unmasked;
2446 #endif
2448 FN_ENTER;
2450 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2451 * I am paranoid */
2452 acx_sem_lock(adev);
2454 irqtype = adev->irq_reason;
2455 adev->irq_reason = 0;
2457 #if IRQ_ITERATE
2458 if (jiffies != adev->irq_last_jiffies) {
2459 adev->irq_loops_this_jiffy = 0;
2460 adev->irq_last_jiffies = jiffies;
2463 /* safety condition; we'll normally abort loop below
2464 * in case no IRQ type occurred */
2465 while (likely(--irqcount)) {
2466 #endif
2467 /* ACK all IRQs ASAP */
2469 /* Handle most important IRQ types first */
2470 if (irqtype & ACX_IRQ_RX_COMPLETE) {
2471 acx_log(LOG_DEBUG, L_IRQ, "got Rx_Complete IRQ\n");
2472 acxpci_l_process_rxdesc(adev);
2474 if (irqtype & ACX_IRQ_TX_COMPLETE) {
2475 acx_log(LOG_DEBUG, L_IRQ, "got Tx_Complete IRQ\n");
2476 /* don't clean up on each Tx complete, wait a bit
2477 * unless we're going towards full, in which case
2478 * we do it immediately, too (otherwise we might lockup
2479 * with a full Tx buffer if we go into
2480 * acxpci_l_clean_txdesc() at a time when we won't wakeup
2481 * the net queue in there for some reason...) */
2482 // if (adev->tx_free <= TX_START_CLEAN) {
2483 acxpci_l_clean_txdesc(adev);
2484 // }
2487 /* Less frequent ones */
2488 if (irqtype & (0
2489 | ACX_IRQ_CMD_COMPLETE
2490 | ACX_IRQ_INFO | ACX_IRQ_SCAN_COMPLETE)) {
2491 if (irqtype & ACX_IRQ_INFO) {
2492 handle_info_irq(adev);
2494 if (irqtype & ACX_IRQ_SCAN_COMPLETE) {
2495 acx_log(LOG_DEBUG, L_IRQ,
2496 "got Scan_Complete IRQ\n");
2497 /* need to do that in process context */
2498 /* remember that fw is not scanning anymore */
2499 SET_BIT(adev->irq_status,
2500 ACX_IRQ_SCAN_COMPLETE);
2504 /* These we just log, but either they happen rarely
2505 * or we keep them masked out */
2506 if (irqtype & (0 | ACX_IRQ_RX_DATA
2507 /* | ACX_IRQ_TX_COMPLETE */
2508 | ACX_IRQ_TX_XFER
2509 /* | ACX_IRQ_RX_COMPLETE */
2510 | ACX_IRQ_DTIM
2511 | ACX_IRQ_BEACON
2512 | ACX_IRQ_TIMER
2513 | ACX_IRQ_KEY_NOT_FOUND
2514 | ACX_IRQ_IV_ICV_FAILURE
2515 /* | ACX_IRQ_CMD_COMPLETE */
2516 /* | ACX_IRQ_INFO */
2517 | ACX_IRQ_OVERFLOW
2518 | ACX_IRQ_PROCESS_ERROR
2519 /* | ACX_IRQ_SCAN_COMPLETE */
2520 | ACX_IRQ_FCS_THRESHOLD
2521 | ACX_IRQ_UNKNOWN)) {
2522 log_unusual_irq(irqtype);
2524 #if IRQ_ITERATE
2525 unmasked = read_reg16(adev, ACX_IO_IRQ_REASON);
2526 irqtype = unmasked & ~adev->irq_mask;
2527 /* Bail out if no new IRQ bits or if all are masked out */
2528 if (!irqtype)
2529 break;
2531 if (unlikely
2532 (++adev->irq_loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY)) {
2533 acx_log(LOG_WARNING, L_ANY,
2534 "too many interrupts per jiffy!\n");
2535 /* Looks like card floods us with IRQs! Try to stop that */
2536 write_reg16(adev, ACX_IO_IRQ_MASK, ACX_IRQ_ALL);
2537 /* This will short-circuit all future attempts to handle IRQ.
2538 * We cant do much more... */
2539 adev->irq_mask = 0;
2540 break;
2543 #endif
2544 /* Routine to perform blink with range
2545 * FIXME: update_link_quality_led is a stub - add proper code and enable this again:
2546 if (unlikely(adev->led_power == 2))
2547 update_link_quality_led(adev);
2550 /* write_flush(adev); - not needed, last op was read anyway */
2551 acx_sem_unlock(adev);
2553 /* handled: */
2554 if (adev->after_interrupt_jobs)
2555 acx_e_after_interrupt_task(&adev->after_interrupt_task);
2557 FN_EXIT0;
2558 return;
2563 static irqreturn_t acxpci_i_interrupt(int irq, void *dev_id)
2565 acx_device_t *adev = dev_id;
2566 unsigned long flags;
2567 register u16 irqtype;
2568 u16 unmasked;
2570 FN_ENTER;
2572 if (!adev)
2573 return IRQ_NONE;
2575 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2576 * I am paranoid */
2578 acx_lock(adev, flags);
2580 unmasked = read_reg16(adev, ACX_IO_IRQ_REASON);
2581 if (unlikely(unmasked == ACX_IRQ_ALL)) {
2582 /* ACX_IRQ_ALL value hints at missing hardware,
2583 * so don't do anything.
2584 * Not very clean, but other drivers do the same... */
2585 acx_log(LOG_WARNING, L_IRQ,
2586 "IRQ type:FFFF (ALL) - device removed? IRQ_NONE\n");
2587 goto none;
2590 /* We will check only "interesting" IRQ types */
2591 irqtype = unmasked & ~adev->irq_mask;
2592 if (!irqtype) {
2593 /* We are on a shared IRQ line and it wasn't our IRQ */
2594 acx_log(LOG_DEBUG, L_IRQ,
2595 "IRQ type:%04X, mask:%04X - all are masked, IRQ_NONE\n",
2596 unmasked, adev->irq_mask);
2597 goto none;
2600 /* Go ahead and ACK our interrupt */
2601 write_reg16(adev, ACX_IO_IRQ_ACK, ACX_IRQ_ALL);
2602 if (irqtype & ACX_IRQ_CMD_COMPLETE) {
2603 acx_log(LOG_DEBUG, L_IRQ, "got Command_Complete IRQ\n");
2604 /* save the state for the running issue_cmd() */
2605 SET_BIT(adev->irq_status, ACX_IRQ_CMD_COMPLETE);
2608 /* Only accept IRQs, if we are initialized properly.
2609 * This avoids an RX race while initializing.
2610 * We should probably not enable IRQs before we are initialized
2611 * completely, but some careful work is needed to fix this. I think it
2612 * is best to stay with this cheap workaround for now... .
2614 if (likely(adev->initialized)) {
2615 /* disable all IRQs. They are enabled again in the bottom half. */
2616 /* save the reason code and call our bottom half. */
2617 adev->irq_reason = irqtype;
2619 if ((irqtype & ACX_IRQ_RX_COMPLETE) || (irqtype & ACX_IRQ_TX_COMPLETE))
2620 acx_schedule_task(adev, 0);
2623 acx_unlock(adev, flags);
2624 FN_EXIT0;
2625 return IRQ_HANDLED;
2626 none:
2627 acx_unlock(adev, flags);
2628 FN_EXIT0;
2629 return IRQ_NONE;
2634 /***********************************************************************
2635 ** acxpci_l_power_led
2637 void acxpci_l_power_led(acx_device_t * adev, int enable)
2639 u16 gpio_pled = IS_ACX111(adev) ? 0x0040 : 0x0800;
2641 /* A hack. Not moving message rate limiting to adev->xxx
2642 * (it's only a debug message after all) */
2643 static int rate_limit = 0;
2645 if (rate_limit++ < 3)
2646 acx_log(LOG_INFO, L_IOCTL,
2647 "Please report in case toggling the power LED "
2648 "doesn't work for your card!\n");
2649 if (enable)
2650 write_reg16(adev, ACX_IO_GPIO_OUT,
2651 read_reg16(adev, ACX_IO_GPIO_OUT) & ~gpio_pled);
2652 else
2653 write_reg16(adev, ACX_IO_GPIO_OUT,
2654 read_reg16(adev, ACX_IO_GPIO_OUT) | gpio_pled);
2658 /***********************************************************************
2659 ** Ioctls
2662 /***********************************************************************
2664 #if 0
2666 acx111pci_ioctl_info(struct net_device *ndev,
2667 struct iw_request_info *info,
2668 struct iw_param *vwrq, char *extra)
2670 #if ACX_DEBUG > 1
2671 acx_device_t *adev = ndev2adev(ndev);
2672 rxdesc_t *rxdesc;
2673 txdesc_t *txdesc;
2674 rxhostdesc_t *rxhostdesc;
2675 txhostdesc_t *txhostdesc;
2676 struct acx111_ie_memoryconfig memconf;
2677 struct acx111_ie_queueconfig queueconf;
2678 unsigned long flags;
2679 int i;
2680 char memmap[0x34];
2681 char rxconfig[0x8];
2682 char fcserror[0x8];
2683 char ratefallback[0x5];
2685 if (!(acx_debug & (L_IOCTL | L_DEBUG)))
2686 return OK;
2687 /* using printk() since we checked debug flag already */
2689 acx_sem_lock(adev);
2691 if (!IS_ACX111(adev)) {
2692 printk("acx111-specific function called "
2693 "with non-acx111 chip, aborting\n");
2694 goto end_ok;
2697 /* get Acx111 Memory Configuration */
2698 memset(&memconf, 0, sizeof(memconf));
2699 /* BTW, fails with 12 (Write only) error code.
2700 ** Retained for easy testing of issue_cmd error handling :) */
2701 acx_s_interrogate(adev, &memconf, ACX1xx_IE_QUEUE_CONFIG);
2703 /* get Acx111 Queue Configuration */
2704 memset(&queueconf, 0, sizeof(queueconf));
2705 acx_s_interrogate(adev, &queueconf, ACX1xx_IE_MEMORY_CONFIG_OPTIONS);
2707 /* get Acx111 Memory Map */
2708 memset(memmap, 0, sizeof(memmap));
2709 acx_s_interrogate(adev, &memmap, ACX1xx_IE_MEMORY_MAP);
2711 /* get Acx111 Rx Config */
2712 memset(rxconfig, 0, sizeof(rxconfig));
2713 acx_s_interrogate(adev, &rxconfig, ACX1xx_IE_RXCONFIG);
2715 /* get Acx111 fcs error count */
2716 memset(fcserror, 0, sizeof(fcserror));
2717 acx_s_interrogate(adev, &fcserror, ACX1xx_IE_FCS_ERROR_COUNT);
2719 /* get Acx111 rate fallback */
2720 memset(ratefallback, 0, sizeof(ratefallback));
2721 acx_s_interrogate(adev, &ratefallback, ACX1xx_IE_RATE_FALLBACK);
2723 /* force occurrence of a beacon interrupt */
2724 /* TODO: comment why is this necessary */
2725 write_reg16(adev, ACX_IO_HINT_TRIG, ACX_IRQ_BEACON);
2727 /* dump Acx111 Mem Configuration */
2728 printk("dump mem config:\n"
2729 "data read: %d, struct size: %d\n"
2730 "Number of stations: %1X\n"
2731 "Memory block size: %1X\n"
2732 "tx/rx memory block allocation: %1X\n"
2733 "count rx: %X / tx: %X queues\n"
2734 "options %1X\n"
2735 "fragmentation %1X\n"
2736 "Rx Queue 1 Count Descriptors: %X\n"
2737 "Rx Queue 1 Host Memory Start: %X\n"
2738 "Tx Queue 1 Count Descriptors: %X\n"
2739 "Tx Queue 1 Attributes: %X\n",
2740 memconf.len, (int)sizeof(memconf),
2741 memconf.no_of_stations,
2742 memconf.memory_block_size,
2743 memconf.tx_rx_memory_block_allocation,
2744 memconf.count_rx_queues, memconf.count_tx_queues,
2745 memconf.options,
2746 memconf.fragmentation,
2747 memconf.rx_queue1_count_descs,
2748 acx2cpu(memconf.rx_queue1_host_rx_start),
2749 memconf.tx_queue1_count_descs, memconf.tx_queue1_attributes);
2751 /* dump Acx111 Queue Configuration */
2752 printk("dump queue head:\n"
2753 "data read: %d, struct size: %d\n"
2754 "tx_memory_block_address (from card): %X\n"
2755 "rx_memory_block_address (from card): %X\n"
2756 "rx1_queue address (from card): %X\n"
2757 "tx1_queue address (from card): %X\n"
2758 "tx1_queue attributes (from card): %X\n",
2759 queueconf.len, (int)sizeof(queueconf),
2760 queueconf.tx_memory_block_address,
2761 queueconf.rx_memory_block_address,
2762 queueconf.rx1_queue_address,
2763 queueconf.tx1_queue_address, queueconf.tx1_attributes);
2765 /* dump Acx111 Mem Map */
2766 printk("dump mem map:\n"
2767 "data read: %d, struct size: %d\n"
2768 "Code start: %X\n"
2769 "Code end: %X\n"
2770 "WEP default key start: %X\n"
2771 "WEP default key end: %X\n"
2772 "STA table start: %X\n"
2773 "STA table end: %X\n"
2774 "Packet template start: %X\n"
2775 "Packet template end: %X\n"
2776 "Queue memory start: %X\n"
2777 "Queue memory end: %X\n"
2778 "Packet memory pool start: %X\n"
2779 "Packet memory pool end: %X\n"
2780 "iobase: %p\n"
2781 "iobase2: %p\n",
2782 *((u16 *) & memmap[0x02]), (int)sizeof(memmap),
2783 *((u32 *) & memmap[0x04]),
2784 *((u32 *) & memmap[0x08]),
2785 *((u32 *) & memmap[0x0C]),
2786 *((u32 *) & memmap[0x10]),
2787 *((u32 *) & memmap[0x14]),
2788 *((u32 *) & memmap[0x18]),
2789 *((u32 *) & memmap[0x1C]),
2790 *((u32 *) & memmap[0x20]),
2791 *((u32 *) & memmap[0x24]),
2792 *((u32 *) & memmap[0x28]),
2793 *((u32 *) & memmap[0x2C]),
2794 *((u32 *) & memmap[0x30]), adev->iobase, adev->iobase2);
2796 /* dump Acx111 Rx Config */
2797 printk("dump rx config:\n"
2798 "data read: %d, struct size: %d\n"
2799 "rx config: %X\n"
2800 "rx filter config: %X\n",
2801 *((u16 *) & rxconfig[0x02]), (int)sizeof(rxconfig),
2802 *((u16 *) & rxconfig[0x04]), *((u16 *) & rxconfig[0x06]));
2804 /* dump Acx111 fcs error */
2805 printk("dump fcserror:\n"
2806 "data read: %d, struct size: %d\n"
2807 "fcserrors: %X\n",
2808 *((u16 *) & fcserror[0x02]), (int)sizeof(fcserror),
2809 *((u32 *) & fcserror[0x04]));
2811 /* dump Acx111 rate fallback */
2812 printk("dump rate fallback:\n"
2813 "data read: %d, struct size: %d\n"
2814 "ratefallback: %X\n",
2815 *((u16 *) & ratefallback[0x02]), (int)sizeof(ratefallback),
2816 *((u8 *) & ratefallback[0x04]));
2818 /* protect against IRQ */
2819 acx_lock(adev, flags);
2821 /* dump acx111 internal rx descriptor ring buffer */
2822 rxdesc = adev->rxdesc_start;
2824 /* loop over complete receive pool */
2825 if (rxdesc)
2826 for (i = 0; i < RX_CNT; i++) {
2827 printk("\ndump internal rxdesc %d:\n"
2828 "mem pos %p\n"
2829 "next 0x%X\n"
2830 "acx mem pointer (dynamic) 0x%X\n"
2831 "CTL (dynamic) 0x%X\n"
2832 "Rate (dynamic) 0x%X\n"
2833 "RxStatus (dynamic) 0x%X\n"
2834 "Mod/Pre (dynamic) 0x%X\n",
2836 rxdesc,
2837 acx2cpu(rxdesc->pNextDesc),
2838 acx2cpu(rxdesc->ACXMemPtr),
2839 rxdesc->Ctl_8,
2840 rxdesc->rate, rxdesc->error, rxdesc->SNR);
2841 rxdesc++;
2844 /* dump host rx descriptor ring buffer */
2846 rxhostdesc = adev->rxhostdesc_start;
2848 /* loop over complete receive pool */
2849 if (rxhostdesc)
2850 for (i = 0; i < RX_CNT; i++) {
2851 printk("\ndump host rxdesc %d:\n"
2852 "mem pos %p\n"
2853 "buffer mem pos 0x%X\n"
2854 "buffer mem offset 0x%X\n"
2855 "CTL 0x%X\n"
2856 "Length 0x%X\n"
2857 "next 0x%X\n"
2858 "Status 0x%X\n",
2860 rxhostdesc,
2861 acx2cpu(rxhostdesc->data_phy),
2862 rxhostdesc->data_offset,
2863 le16_to_cpu(rxhostdesc->Ctl_16),
2864 le16_to_cpu(rxhostdesc->length),
2865 acx2cpu(rxhostdesc->desc_phy_next),
2866 rxhostdesc->Status);
2867 rxhostdesc++;
2870 /* dump acx111 internal tx descriptor ring buffer */
2871 txdesc = adev->txdesc_start;
2873 /* loop over complete transmit pool */
2874 if (txdesc)
2875 for (i = 0; i < TX_CNT; i++) {
2876 printk("\ndump internal txdesc %d:\n"
2877 "size 0x%X\n"
2878 "mem pos %p\n"
2879 "next 0x%X\n"
2880 "acx mem pointer (dynamic) 0x%X\n"
2881 "host mem pointer (dynamic) 0x%X\n"
2882 "length (dynamic) 0x%X\n"
2883 "CTL (dynamic) 0x%X\n"
2884 "CTL2 (dynamic) 0x%X\n"
2885 "Status (dynamic) 0x%X\n"
2886 "Rate (dynamic) 0x%X\n",
2888 (int)sizeof(struct txdesc),
2889 txdesc,
2890 acx2cpu(txdesc->pNextDesc),
2891 acx2cpu(txdesc->AcxMemPtr),
2892 acx2cpu(txdesc->HostMemPtr),
2893 le16_to_cpu(txdesc->total_length),
2894 txdesc->Ctl_8,
2895 txdesc->Ctl2_8, txdesc->error,
2896 txdesc->u.r1.rate);
2897 txdesc = advance_txdesc(adev, txdesc, 1);
2900 /* dump host tx descriptor ring buffer */
2902 txhostdesc = adev->txhostdesc_start;
2904 /* loop over complete host send pool */
2905 if (txhostdesc)
2906 for (i = 0; i < TX_CNT * 2; i++) {
2907 printk("\ndump host txdesc %d:\n"
2908 "mem pos %p\n"
2909 "buffer mem pos 0x%X\n"
2910 "buffer mem offset 0x%X\n"
2911 "CTL 0x%X\n"
2912 "Length 0x%X\n"
2913 "next 0x%X\n"
2914 "Status 0x%X\n",
2916 txhostdesc,
2917 acx2cpu(txhostdesc->data_phy),
2918 txhostdesc->data_offset,
2919 le16_to_cpu(txhostdesc->Ctl_16),
2920 le16_to_cpu(txhostdesc->length),
2921 acx2cpu(txhostdesc->desc_phy_next),
2922 le32_to_cpu(txhostdesc->Status));
2923 txhostdesc++;
2926 /* write_reg16(adev, 0xb4, 0x4); */
2928 acx_unlock(adev, flags);
2929 end_ok:
2931 acx_sem_unlock(adev);
2932 #endif /* ACX_DEBUG */
2933 return OK;
2937 /***********************************************************************
2940 acx100pci_ioctl_set_phy_amp_bias(struct net_device *ndev,
2941 struct iw_request_info *info,
2942 struct iw_param *vwrq, char *extra)
2944 acx_device_t *adev = ndev2adev(ndev);
2945 unsigned long flags;
2946 u16 gpio_old;
2948 if (!IS_ACX100(adev)) {
2949 /* WARNING!!!
2950 * Removing this check *might* damage
2951 * hardware, since we're tweaking GPIOs here after all!!!
2952 * You've been warned...
2953 * WARNING!!! */
2954 acx_log(LOG_INFO, L_ANY,
2955 "sorry, setting bias level for non-acx100 "
2956 "is not supported yet\n");
2957 return OK;
2960 if (*extra > 7) {
2961 acx_log(LOG_INFO, L_ANY,
2962 "invalid bias parameter, range is 0-7\n");
2963 return -EINVAL;
2966 acx_sem_lock(adev);
2968 /* Need to lock accesses to [ACX_IO_GPIO_OUT]:
2969 * IRQ handler uses it to update LED */
2970 acx_lock(adev, flags);
2971 gpio_old = read_reg16(adev, ACX_IO_GPIO_OUT);
2972 write_reg16(adev, ACX_IO_GPIO_OUT,
2973 (gpio_old & 0xf8ff) | ((u16) * extra << 8));
2974 acx_unlock(adev, flags);
2976 acx_log(LOG_DEBUG, L_REALLYVERBOSE, "gpio_old: 0x%04X\n", gpio_old);
2977 acx_log(LOG_INFO, L_ANY,
2978 "%s: PHY power amplifier bias: old:%d, new:%d\n",
2979 ndev->name, (gpio_old & 0x0700) >> 8, (unsigned char)*extra);
2981 acx_sem_unlock(adev);
2983 return OK;
2985 #endif
2987 /***************************************************************
2988 ** acxpci_l_alloc_tx
2989 ** Actually returns a txdesc_t* ptr
2991 ** FIXME: in case of fragments, should allocate multiple descrs
2992 ** after figuring out how many we need and whether we still have
2993 ** sufficiently many.
2995 tx_t *acxpci_l_alloc_tx(acx_device_t * adev)
2997 struct txdesc *txdesc;
2998 unsigned head;
2999 u8 ctl8;
3001 FN_ENTER;
3003 if (unlikely(!adev->tx_free)) {
3004 acx_log(LOG_WARNING, L_ANY, "BUG: no free txdesc left\n");
3005 txdesc = NULL;
3006 goto end;
3009 head = adev->tx_head;
3010 txdesc = get_txdesc(adev, head);
3011 ctl8 = txdesc->Ctl_8;
3013 /* 2005-10-11: there were several bug reports on this happening
3014 ** but now cause seems to be understood & fixed */
3015 if (unlikely(DESC_CTL_HOSTOWN != (ctl8 & DESC_CTL_ACXDONE_HOSTOWN))) {
3016 /* whoops, descr at current index is not free, so probably
3017 * ring buffer already full */
3018 acx_log(LOG_WARNING, L_ANY, "BUG: tx_head:%d Ctl8:0x%02X - "
3019 "failed to find free txdesc\n", head, ctl8);
3020 txdesc = NULL;
3021 goto end;
3024 /* Needed in case txdesc won't be eventually submitted for tx */
3025 txdesc->Ctl_8 = DESC_CTL_ACXDONE_HOSTOWN;
3027 adev->tx_free--;
3028 acx_log(LOG_DEBUG, L_BUFT, "tx: got desc %u, %u remain\n",
3029 head, adev->tx_free);
3030 /* Keep a few free descs between head and tail of tx ring.
3031 ** It is not absolutely needed, just feels safer */
3032 if (adev->tx_free < TX_STOP_QUEUE) {
3033 acx_log(LOG_DEBUG, L_BUF, "stop queue (%u tx desc left)\n",
3034 adev->tx_free);
3035 acx_stop_queue(adev->ieee, NULL);
3038 /* returning current descriptor, so advance to next free one */
3039 adev->tx_head = (head + 1) % TX_CNT;
3040 end:
3041 FN_EXIT0;
3043 return (tx_t *) txdesc;
3047 /***********************************************************************
3049 void *acxpci_l_get_txbuf(acx_device_t * adev, tx_t * tx_opaque)
3051 return get_txhostdesc(adev, (txdesc_t *) tx_opaque)->data;
3055 /***********************************************************************
3056 ** acxpci_l_tx_data
3058 ** Can be called from IRQ (rx -> (AP bridging or mgmt response) -> tx).
3059 ** Can be called from acx_i_start_xmit (data frames from net core).
3061 ** FIXME: in case of fragments, should loop over the number of
3062 ** pre-allocated tx descrs, properly setting up transfer data and
3063 ** CTL_xxx flags according to fragment number.
3065 void
3066 acxpci_l_tx_data(acx_device_t * adev, tx_t * tx_opaque, int len,
3067 struct ieee80211_tx_control *ieeectl,struct sk_buff* skb)
3069 txdesc_t *txdesc = (txdesc_t *) tx_opaque;
3070 struct ieee80211_hdr *wireless_header;
3071 txhostdesc_t *hostdesc1, *hostdesc2;
3072 int rate_cur;
3073 u8 Ctl_8, Ctl2_8;
3074 int wlhdr_len;
3076 FN_ENTER;
3078 /* fw doesn't tx such packets anyhow */
3079 /* if (unlikely(len < WLAN_HDR_A3_LEN))
3080 goto end;
3082 hostdesc1 = get_txhostdesc(adev, txdesc);
3083 wireless_header = (struct ieee80211_hdr *)hostdesc1->data;
3084 /* modify flag status in separate variable to be able to write it back
3085 * in one big swoop later (also in order to have less device memory
3086 * accesses) */
3087 Ctl_8 = txdesc->Ctl_8;
3088 Ctl2_8 = 0; /* really need to init it to 0, not txdesc->Ctl2_8, it seems */
3090 hostdesc2 = hostdesc1 + 1;
3092 /* DON'T simply set Ctl field to 0 here globally,
3093 * it needs to maintain a consistent flag status (those are state flags!!),
3094 * otherwise it may lead to severe disruption. Only set or reset particular
3095 * flags at the exact moment this is needed... */
3097 /* let chip do RTS/CTS handshaking before sending
3098 * in case packet size exceeds threshold */
3099 if (ieeectl->flags & IEEE80211_TXCTL_USE_RTS_CTS)
3100 SET_BIT(Ctl2_8, DESC_CTL2_RTS);
3101 else
3102 CLEAR_BIT(Ctl2_8, DESC_CTL2_RTS);
3104 rate_cur = ieeectl->tx_rate;
3105 if (unlikely(!rate_cur)) {
3106 acx_log(LOG_WARNING, L_ANY, "driver bug! bad ratemask\n");
3107 goto end;
3110 /* used in tx cleanup routine for auto rate and accounting: */
3111 /* put_txcr(adev, txdesc, clt, rate_cur); deprecated by mac80211 */
3113 txdesc->total_length = cpu_to_le16(len);
3114 wlhdr_len = ieee80211_get_hdrlen(le16_to_cpu(wireless_header->frame_control));
3115 hostdesc2->length = cpu_to_le16(len - wlhdr_len);
3117 if (!ieeectl->do_not_encrypt && ieeectl->key_idx>= 0)
3119 u16 key_idx = (u16)(ieeectl->key_idx);
3120 struct acx_key* key = &(adev->key[key_idx]);
3121 int wlhdr_len;
3122 if (key->enabled)
3124 memcpy(ieeehdr->wep_iv, ((u8*)wireless_header) + wlhdr_len, 4);
3128 if (IS_ACX111(adev)) {
3129 /* note that if !txdesc->do_auto, txrate->cur
3130 ** has only one nonzero bit */
3131 txdesc->u.r2.rate111 = cpu_to_le16(rate_cur
3132 /* WARNING: I was never able to make it work with prism54 AP.
3133 ** It was falling down to 1Mbit where shortpre is not applicable,
3134 ** and not working at all at "5,11 basic rates only" setting.
3135 ** I even didn't see tx packets in radio packet capture.
3136 ** Disabled for now --vda */
3137 /*| ((clt->shortpre && clt->cur!=RATE111_1) ? RATE111_SHORTPRE : 0) */
3139 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3140 /* should add this to rate111 above as necessary */
3141 |(clt->pbcc511 ? RATE111_PBCC511 : 0)
3142 #endif
3143 hostdesc1->length = cpu_to_le16(len);
3144 } else { /* ACX100 */
3145 u8 rate_100 = ieeectl->tx_rate;
3146 txdesc->u.r1.rate = rate_100;
3147 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3148 if (clt->pbcc511) {
3149 if (n == RATE100_5 || n == RATE100_11)
3150 n |= RATE100_PBCC511;
3153 if (clt->shortpre && (clt->cur != RATE111_1))
3154 SET_BIT(Ctl_8, DESC_CTL_SHORT_PREAMBLE); /* set Short Preamble */
3155 #endif
3156 /* set autodma and reclaim and 1st mpdu */
3157 SET_BIT(Ctl_8,
3158 DESC_CTL_AUTODMA | DESC_CTL_RECLAIM |
3159 DESC_CTL_FIRSTFRAG);
3160 #if ACX_FRAGMENTATION
3161 /* SET_BIT(Ctl2_8, DESC_CTL2_MORE_FRAG); cannot set it unconditionally, needs to be set for all non-last fragments */
3162 #endif
3163 hostdesc1->length = cpu_to_le16(wlhdr_len);
3165 /* don't need to clean ack/rts statistics here, already
3166 * done on descr cleanup */
3168 /* clears HOSTOWN and ACXDONE bits, thus telling that the descriptors
3169 * are now owned by the acx100; do this as LAST operation */
3170 CLEAR_BIT(Ctl_8, DESC_CTL_ACXDONE_HOSTOWN);
3171 /* flush writes before we release hostdesc to the adapter here */
3172 wmb();
3173 CLEAR_BIT(hostdesc1->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3174 CLEAR_BIT(hostdesc2->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3176 /* write back modified flags */
3177 CLEAR_BIT(Ctl2_8, DESC_CTL2_WEP);
3178 txdesc->Ctl2_8 = Ctl2_8;
3179 txdesc->Ctl_8 = Ctl_8;
3180 /* unused: txdesc->tx_time = cpu_to_le32(jiffies); */
3182 /* flush writes before we tell the adapter that it's its turn now */
3183 write_reg16(adev, ACX_IO_INT_TRIG, INT_TRIG_TXPRC);
3184 write_flush(adev);
3185 /* log the packet content AFTER sending it,
3186 * in order to not delay sending any further than absolutely needed
3187 * Do separate logs for acx100/111 to have human-readable rates */
3188 memcpy(&(hostdesc1->txstatus.control),ieeectl,sizeof(struct ieee80211_tx_control));
3189 hostdesc1->skb = skb;
3190 end:
3191 FN_EXIT0;
3195 /***********************************************************************
3196 ** acxpci_l_clean_txdesc
3198 ** This function resets the txdescs' status when the ACX100
3199 ** signals the TX done IRQ (txdescs have been processed), starting with
3200 ** the pool index of the descriptor which we would use next,
3201 ** in order to make sure that we can be as fast as possible
3202 ** in filling new txdescs.
3203 ** Everytime we get called we know where the next packet to be cleaned is.
3206 #if !ACX_DEBUG
3207 static inline void log_txbuffer(const acx_device_t * adev)
3210 #else
3211 static void log_txbuffer(acx_device_t * adev)
3213 txdesc_t *txdesc;
3214 int i;
3216 /* no FN_ENTER here, we don't want that */
3217 /* no locks here, since it's entirely non-critical code */
3218 txdesc = adev->txdesc_start;
3219 if (unlikely(!txdesc))
3220 return;
3221 acx_log(LOG_DEBUG, L_REALLYVERBOSE, "tx: desc->Ctl8's:");
3222 for (i = 0; i < TX_CNT; i++) {
3223 printk(" %02X", txdesc->Ctl_8);
3224 txdesc = advance_txdesc(adev, txdesc, 1);
3226 printk("\n");
3228 #endif
3231 static void handle_tx_error(acx_device_t * adev, u8 error, unsigned int finger,
3232 struct ieee80211_tx_status *status)
3234 const char *err = "unknown error";
3236 /* hmm, should we handle this as a mask
3237 * of *several* bits?
3238 * For now I think only caring about
3239 * individual bits is ok... */
3240 switch (error) {
3241 case 0x01:
3242 err = "no Tx due to error in other fragment";
3243 /* adev->wstats.discard.fragment++; */
3244 break;
3245 case 0x02:
3246 err = "Tx aborted";
3247 adev->stats.tx_aborted_errors++;
3248 break;
3249 case 0x04:
3250 err = "Tx desc wrong parameters";
3251 /* adev->wstats.discard.misc++; */
3252 break;
3253 case 0x08:
3254 err = "WEP key not found";
3255 /* adev->wstats.discard.misc++; */
3256 break;
3257 case 0x10:
3258 err = "MSDU lifetime timeout? - try changing "
3259 "'iwconfig retry lifetime XXX'";
3260 /* adev->wstats.discard.misc++; */
3261 break;
3262 case 0x20:
3263 err = "excessive Tx retries due to either distance "
3264 "too high or unable to Tx or Tx frame error - "
3265 "try changing 'iwconfig txpower XXX' or "
3266 "'sens'itivity or 'retry'";
3267 /* adev->wstats.discard.retries++; */
3268 /* Tx error 0x20 also seems to occur on
3269 * overheating, so I'm not sure whether we
3270 * actually want to do aggressive radio recalibration,
3271 * since people maybe won't notice then that their hardware
3272 * is slowly getting cooked...
3273 * Or is it still a safe long distance from utter
3274 * radio non-functionality despite many radio recalibs
3275 * to final destructive overheating of the hardware?
3276 * In this case we really should do recalib here...
3277 * I guess the only way to find out is to do a
3278 * potentially fatal self-experiment :-\
3279 * Or maybe only recalib in case we're using Tx
3280 * rate auto (on errors switching to lower speed
3281 * --> less heat?) or 802.11 power save mode?
3283 * ok, just do it. */
3284 if (++adev->retry_errors_msg_ratelimit % 4 == 0) {
3285 if (adev->retry_errors_msg_ratelimit <= 20) {
3286 acx_log(LOG_WARNING, L_ANY,
3287 "%s: several excessive Tx "
3288 "retry errors occurred, attempting "
3289 "to recalibrate radio\n",
3290 wiphy_name(adev->ieee->wiphy));
3291 acx_log(LOG_WARNING, L_ANY,
3292 "Radio drift might be caused by "
3293 "increasing card temperature, please "
3294 "check the card before it's too late!\n");
3295 if (adev->retry_errors_msg_ratelimit == 20)
3296 acx_log(LOG_WARNING, L_ANY,
3297 "disabling above message\n");
3300 acx_schedule_task(adev,
3301 ACX_TASKLET_CMD_RADIO_RECALIB);
3303 status->excessive_retries++;
3304 break;
3305 case 0x40:
3306 err = "Tx buffer overflow";
3307 adev->stats.tx_fifo_errors++;
3308 break;
3309 case 0x80:
3310 /* possibly ACPI C-state powersaving related!!!
3311 * (DMA timeout due to excessively high wakeup
3312 * latency after C-state activation!?)
3313 * Disable C-State powersaving and try again,
3314 * then PLEASE REPORT, I'm VERY interested in
3315 * whether my theory is correct that this is
3316 * actually the problem here.
3317 * In that case, use new Linux idle wakeup latency
3318 * requirements kernel API to prevent this issue. */
3319 err = "DMA error";
3320 /* adev->wstats.discard.misc++; */
3321 break;
3323 adev->stats.tx_errors++;
3324 if (adev->stats.tx_errors <= 20)
3325 acx_log(LOG_WARNING, L_ANY,
3326 "%s: tx error 0x%02X, buf %02u! (%s)\n",
3327 wiphy_name(adev->ieee->wiphy), error, finger, err);
3328 else
3329 acx_log(LOG_WARNING, L_ANY,
3330 "%s: tx error 0x%02X, buf %02u!\n",
3331 wiphy_name(adev->ieee->wiphy), error, finger);
3335 unsigned int acxpci_l_clean_txdesc(acx_device_t * adev)
3337 txdesc_t *txdesc;
3338 txhostdesc_t *hostdesc;
3339 unsigned finger;
3340 int num_cleaned;
3341 u16 r111;
3342 u8 error, ack_failures, rts_failures, rts_ok, r100;
3344 FN_ENTER;
3346 if (unlikely(acx_debug & L_REALLYVERBOSE))
3347 log_txbuffer(adev);
3349 acx_log(LOG_DEBUG, L_BUFT, "tx: cleaning up bufs from %u\n",
3350 adev->tx_tail);
3352 /* We know first descr which is not free yet. We advance it as far
3353 ** as we see correct bits set in following descs (if next desc
3354 ** is NOT free, we shouldn't advance at all). We know that in
3355 ** front of tx_tail may be "holes" with isolated free descs.
3356 ** We will catch up when all intermediate descs will be freed also */
3358 finger = adev->tx_tail;
3359 num_cleaned = 0;
3360 while (likely(finger != adev->tx_head)) {
3361 txdesc = get_txdesc(adev, finger);
3363 /* If we allocated txdesc on tx path but then decided
3364 ** to NOT use it, then it will be left as a free "bubble"
3365 ** in the "allocated for tx" part of the ring.
3366 ** We may meet it on the next ring pass here. */
3368 /* stop if not marked as "tx finished" and "host owned" */
3369 if ((txdesc->Ctl_8 & DESC_CTL_ACXDONE_HOSTOWN)
3370 != DESC_CTL_ACXDONE_HOSTOWN) {
3371 if (unlikely(!num_cleaned)) { /* maybe remove completely */
3372 acx_log(LOG_DEBUG, L_BUFT,
3373 "clean_txdesc: tail isn't free. "
3374 "tail:%d head:%d\n",
3375 adev->tx_tail, adev->tx_head);
3377 break;
3380 /* remember desc values... */
3381 error = txdesc->error;
3382 ack_failures = txdesc->ack_failures;
3383 rts_failures = txdesc->rts_failures;
3384 rts_ok = txdesc->rts_ok;
3385 r100 = txdesc->u.r1.rate;
3386 r111 = le16_to_cpu(txdesc->u.r2.rate111);
3388 /* need to check for certain error conditions before we
3389 * clean the descriptor: we still need valid descr data here */
3390 hostdesc = get_txhostdesc(adev, txdesc);
3392 hostdesc->txstatus.flags |= IEEE80211_TX_STATUS_ACK;
3393 if (unlikely(0x30 & error)) {
3394 /* only send IWEVTXDROP in case of retry or lifetime exceeded;
3395 * all other errors mean we screwed up locally */
3396 /* union iwreq_data wrqu;
3397 struct ieee80211_hdr_3addr *hdr;
3398 hdr = (struct ieee80211_hdr_3addr *) hostdesc->data;
3399 MAC_COPY(wrqu.addr.sa_data, hdr->addr1);
3401 hostdesc->txstatus.flags &= ~IEEE80211_TX_STATUS_ACK;
3404 /* ...and free the desc */
3405 txdesc->error = 0;
3406 txdesc->ack_failures = 0;
3407 txdesc->rts_failures = 0;
3408 txdesc->rts_ok = 0;
3409 /* signal host owning it LAST, since ACX already knows that this
3410 ** descriptor is finished since it set Ctl_8 accordingly. */
3411 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3413 adev->tx_free++;
3414 num_cleaned++;
3416 if ((adev->tx_free >= TX_START_QUEUE)
3417 /* && (adev->status == ACX_STATUS_4_ASSOCIATED) */
3418 /*&& (acx_queue_stopped(adev->ieee))*/
3420 acx_log(LOG_DEBUG, L_BUF,
3421 "tx: wake queue (avail. Tx desc %u)\n",
3422 adev->tx_free);
3423 acx_wake_queue(adev->ieee, NULL);
3426 /* do error checking, rate handling and logging
3427 * AFTER having done the work, it's faster */
3429 /* Rate handling is done in mac80211 */
3430 /* if (adev->rate_auto) {
3431 struct client *clt = get_txc(adev, txdesc);
3432 if (clt) {
3433 u16 cur = get_txr(adev, txdesc);
3434 if (clt->rate_cur == cur) {
3435 acx_l_handle_txrate_auto(adev, clt, cur,*/ /* intended rate */
3436 /*r100, r111,*/ /* actually used rate */
3437 /*(error & 0x30),*/ /* was there an error? */
3438 /* TX_CNT +
3439 TX_CLEAN_BACKLOG
3441 adev->tx_free);
3446 if (unlikely(error))
3447 handle_tx_error(adev, error, finger, &hostdesc->txstatus);
3449 if (IS_ACX111(adev))
3450 acx_log(LOG_DEBUG, L_BUFT, "tx: cleaned %u: !ACK=%u "
3451 "!RTS=%u RTS=%u r111=%04X tx_free=%u\n",
3452 finger, ack_failures,
3453 rts_failures, rts_ok, r111, adev->tx_free);
3454 else
3455 acx_log(LOG_DEBUG, L_BUFT, "tx: cleaned %u: !ACK=%u "
3456 "!RTS=%u RTS=%u rate=%u\n",
3457 finger, ack_failures,
3458 rts_failures, rts_ok, r100);
3460 /* And finally report upstream */
3461 if (hostdesc)
3463 hostdesc->txstatus.excessive_retries = rts_failures ;
3464 hostdesc->txstatus.retry_count = ack_failures;
3465 ieee80211_tx_status(adev->ieee,hostdesc->skb,&hostdesc->txstatus);
3466 memset(&hostdesc->txstatus, 0, sizeof(struct ieee80211_tx_status));
3468 /* update pointer for descr to be cleaned next */
3469 finger = (finger + 1) % TX_CNT;
3471 /* remember last position */
3472 adev->tx_tail = finger;
3473 /* end: */
3474 FN_EXIT1(num_cleaned);
3475 return num_cleaned;
3478 /* clean *all* Tx descriptors, and regardless of their previous state.
3479 * Used for brute-force reset handling. */
3480 void acxpci_l_clean_txdesc_emergency(acx_device_t * adev)
3482 txdesc_t *txdesc;
3483 int i;
3485 FN_ENTER;
3487 for (i = 0; i < TX_CNT; i++) {
3488 txdesc = get_txdesc(adev, i);
3490 /* free it */
3491 txdesc->ack_failures = 0;
3492 txdesc->rts_failures = 0;
3493 txdesc->rts_ok = 0;
3494 txdesc->error = 0;
3495 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3498 adev->tx_free = TX_CNT;
3500 FN_EXIT0;
3504 /***********************************************************************
3505 ** acxpci_s_create_tx_host_desc_queue
3508 static void *allocate(acx_device_t * adev, size_t size, dma_addr_t * phy,
3509 const char *msg)
3511 void *ptr;
3513 ptr = dma_alloc_coherent(adev->bus_dev, size, phy, GFP_KERNEL);
3515 if (ptr) {
3516 acx_log(LOG_DEBUG, L_REALLYVERBOSE,
3517 "%s sz=%d adr=0x%p phy=0x%08llx\n",
3518 msg, (int)size, ptr, (unsigned long long)*phy);
3519 memset(ptr, 0, size);
3520 return ptr;
3522 acx_log(LOG_WARNING, L_ANY, "%s allocation FAILED (%d bytes)\n",
3523 msg, (int)size);
3524 return NULL;
3528 static int acxpci_s_create_tx_host_desc_queue(acx_device_t * adev)
3530 txhostdesc_t *hostdesc;
3531 u8 *txbuf;
3532 dma_addr_t hostdesc_phy;
3533 dma_addr_t txbuf_phy;
3534 int i;
3536 FN_ENTER;
3538 /* allocate TX buffer */
3539 adev->txbuf_area_size = TX_CNT * /*WLAN_A4FR_MAXLEN_WEP_FCS*/ (30 + 2312 + 4);
3540 adev->txbuf_start = allocate(adev, adev->txbuf_area_size,
3541 &adev->txbuf_startphy, "txbuf_start");
3542 if (!adev->txbuf_start)
3543 goto fail;
3545 /* allocate the TX host descriptor queue pool */
3546 adev->txhostdesc_area_size = TX_CNT * 2 * sizeof(*hostdesc);
3547 adev->txhostdesc_start = allocate(adev, adev->txhostdesc_area_size,
3548 &adev->txhostdesc_startphy,
3549 "txhostdesc_start");
3550 if (!adev->txhostdesc_start)
3551 goto fail;
3552 /* check for proper alignment of TX host descriptor pool */
3553 if ((long)adev->txhostdesc_start & 3) {
3554 acx_log(LOG_WARNING, L_ANY,
3555 "driver bug: dma alloc returns unaligned address\n");
3556 goto fail;
3559 hostdesc = adev->txhostdesc_start;
3560 hostdesc_phy = adev->txhostdesc_startphy;
3561 txbuf = adev->txbuf_start;
3562 txbuf_phy = adev->txbuf_startphy;
3564 #if 0
3565 /* Each tx buffer is accessed by hardware via
3566 ** txdesc -> txhostdesc(s) -> txbuffer(s).
3567 ** We use only one txhostdesc per txdesc, but it looks like
3568 ** acx111 is buggy: it accesses second txhostdesc
3569 ** (via hostdesc.desc_phy_next field) even if
3570 ** txdesc->length == hostdesc->length and thus
3571 ** entire packet was placed into first txhostdesc.
3572 ** Due to this bug acx111 hangs unless second txhostdesc
3573 ** has le16_to_cpu(hostdesc.length) = 3 (or larger)
3574 ** Storing NULL into hostdesc.desc_phy_next
3575 ** doesn't seem to help.
3577 ** Update: although it worked on Xterasys XN-2522g
3578 ** with len=3 trick, WG311v2 is even more bogus, doesn't work.
3579 ** Keeping this code (#ifdef'ed out) for documentational purposes.
3581 for (i = 0; i < TX_CNT * 2; i++) {
3582 hostdesc_phy += sizeof(*hostdesc);
3583 if (!(i & 1)) {
3584 hostdesc->data_phy = cpu2acx(txbuf_phy);
3585 /* hostdesc->data_offset = ... */
3586 /* hostdesc->reserved = ... */
3587 hostdesc->Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
3588 /* hostdesc->length = ... */
3589 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3590 hostdesc->pNext = ptr2acx(NULL);
3591 /* hostdesc->Status = ... */
3592 /* below: non-hardware fields */
3593 hostdesc->data = txbuf;
3595 txbuf += WLAN_A4FR_MAXLEN_WEP_FCS;
3596 txbuf_phy += WLAN_A4FR_MAXLEN_WEP_FCS;
3597 } else {
3598 /* hostdesc->data_phy = ... */
3599 /* hostdesc->data_offset = ... */
3600 /* hostdesc->reserved = ... */
3601 /* hostdesc->Ctl_16 = ... */
3602 hostdesc->length = cpu_to_le16(3); /* bug workaround */
3603 /* hostdesc->desc_phy_next = ... */
3604 /* hostdesc->pNext = ... */
3605 /* hostdesc->Status = ... */
3606 /* below: non-hardware fields */
3607 /* hostdesc->data = ... */
3609 hostdesc++;
3611 #endif
3612 /* We initialize two hostdescs so that they point to adjacent
3613 ** memory areas. Thus txbuf is really just a contiguous memory area */
3614 for (i = 0; i < TX_CNT * 2; i++) {
3615 hostdesc_phy += sizeof(*hostdesc);
3617 hostdesc->data_phy = cpu2acx(txbuf_phy);
3618 /* done by memset(0): hostdesc->data_offset = 0; */
3619 /* hostdesc->reserved = ... */
3620 hostdesc->Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
3621 /* hostdesc->length = ... */
3622 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3623 /* done by memset(0): hostdesc->pNext = ptr2acx(NULL); */
3624 /* hostdesc->Status = ... */
3625 /* ->data is a non-hardware field: */
3626 hostdesc->data = txbuf;
3628 if (!(i & 1)) {
3629 txbuf += 24 /*WLAN_HDR_A3_LEN*/;
3630 txbuf_phy += 24 /*WLAN_HDR_A3_LEN*/;
3631 } else {
3632 txbuf += 30 + 2132 + 4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3633 txbuf_phy += 30 + 2132 +4 - 24/*WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN*/;
3635 hostdesc++;
3637 hostdesc--;
3638 hostdesc->desc_phy_next = cpu2acx(adev->txhostdesc_startphy);
3640 FN_EXIT1(OK);
3641 return OK;
3642 fail:
3643 acx_log(LOG_WARNING, L_ANY, "create_tx_host_desc_queue FAILED\n");
3644 /* dealloc will be done by free function on error case */
3645 FN_EXIT1(NOT_OK);
3646 return NOT_OK;
3650 /***************************************************************
3651 ** acxpci_s_create_rx_host_desc_queue
3653 /* the whole size of a data buffer (header plus data body)
3654 * plus 32 bytes safety offset at the end */
3655 #define RX_BUFFER_SIZE (sizeof(rxbuffer_t) + 32)
3657 static int acxpci_s_create_rx_host_desc_queue(acx_device_t * adev)
3659 rxhostdesc_t *hostdesc;
3660 rxbuffer_t *rxbuf;
3661 dma_addr_t hostdesc_phy;
3662 dma_addr_t rxbuf_phy;
3663 int i;
3665 FN_ENTER;
3667 /* allocate the RX host descriptor queue pool */
3668 adev->rxhostdesc_area_size = RX_CNT * sizeof(*hostdesc);
3669 adev->rxhostdesc_start = allocate(adev, adev->rxhostdesc_area_size,
3670 &adev->rxhostdesc_startphy,
3671 "rxhostdesc_start");
3672 if (!adev->rxhostdesc_start)
3673 goto fail;
3674 /* check for proper alignment of RX host descriptor pool */
3675 if ((long)adev->rxhostdesc_start & 3) {
3676 acx_log(LOG_WARNING, L_ANY,
3677 "driver bug: dma alloc returns unaligned address\n");
3678 goto fail;
3681 /* allocate Rx buffer pool which will be used by the acx
3682 * to store the whole content of the received frames in it */
3683 adev->rxbuf_area_size = RX_CNT * RX_BUFFER_SIZE;
3684 adev->rxbuf_start = allocate(adev, adev->rxbuf_area_size,
3685 &adev->rxbuf_startphy, "rxbuf_start");
3686 if (!adev->rxbuf_start)
3687 goto fail;
3689 rxbuf = adev->rxbuf_start;
3690 rxbuf_phy = adev->rxbuf_startphy;
3691 hostdesc = adev->rxhostdesc_start;
3692 hostdesc_phy = adev->rxhostdesc_startphy;
3694 /* don't make any popular C programming pointer arithmetic mistakes
3695 * here, otherwise I'll kill you...
3696 * (and don't dare asking me why I'm warning you about that...) */
3697 for (i = 0; i < RX_CNT; i++) {
3698 hostdesc->data = rxbuf;
3699 hostdesc->data_phy = cpu2acx(rxbuf_phy);
3700 hostdesc->length = cpu_to_le16(RX_BUFFER_SIZE);
3701 CLEAR_BIT(hostdesc->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3702 rxbuf++;
3703 rxbuf_phy += sizeof(*rxbuf);
3704 hostdesc_phy += sizeof(*hostdesc);
3705 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
3706 hostdesc++;
3708 hostdesc--;
3709 hostdesc->desc_phy_next = cpu2acx(adev->rxhostdesc_startphy);
3710 FN_EXIT1(OK);
3711 return OK;
3712 fail:
3713 acx_log(LOG_WARNING, L_ANY, "create_rx_host_desc_queue FAILED\n");
3714 /* dealloc will be done by free function on error case */
3715 FN_EXIT1(NOT_OK);
3716 return NOT_OK;
3720 /***************************************************************
3721 ** acxpci_s_create_hostdesc_queues
3723 int acxpci_s_create_hostdesc_queues(acx_device_t * adev)
3725 int result;
3726 result = acxpci_s_create_tx_host_desc_queue(adev);
3727 if (OK != result)
3728 return result;
3729 result = acxpci_s_create_rx_host_desc_queue(adev);
3730 return result;
3734 /***************************************************************
3735 ** acxpci_create_tx_desc_queue
3737 static void acxpci_create_tx_desc_queue(acx_device_t * adev, u32 tx_queue_start)
3739 txdesc_t *txdesc;
3740 txhostdesc_t *hostdesc;
3741 dma_addr_t hostmemptr;
3742 u32 mem_offs;
3743 int i;
3745 FN_ENTER;
3747 if (IS_ACX100(adev))
3748 adev->txdesc_size = sizeof(*txdesc);
3749 else
3750 /* the acx111 txdesc is 4 bytes larger */
3751 adev->txdesc_size = sizeof(*txdesc) + 4;
3753 adev->txdesc_start = (txdesc_t *) (adev->iobase2 + tx_queue_start);
3755 acx_log(LOG_DEBUG, L_REALLYVERBOSE, "adev->iobase2=%p\n"
3756 "tx_queue_start=%08X\n adev->txdesc_start=%p\n",
3757 adev->iobase2, tx_queue_start, adev->txdesc_start);
3759 adev->tx_free = TX_CNT;
3760 /* done by memset: adev->tx_head = 0; */
3761 /* done by memset: adev->tx_tail = 0; */
3762 txdesc = adev->txdesc_start;
3763 mem_offs = tx_queue_start;
3764 hostmemptr = adev->txhostdesc_startphy;
3765 hostdesc = adev->txhostdesc_start;
3767 if (IS_ACX111(adev)) {
3768 /* ACX111 has a preinitialized Tx buffer! */
3769 /* loop over whole send pool */
3770 /* FIXME: do we have to do the hostmemptr stuff here?? */
3771 for (i = 0; i < TX_CNT; i++) {
3772 txdesc->HostMemPtr = ptr2acx(hostmemptr);
3773 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3774 /* reserve two (hdr desc and payload desc) */
3775 hostdesc += 2;
3776 hostmemptr += 2 * sizeof(*hostdesc);
3777 txdesc = advance_txdesc(adev, txdesc, 1);
3779 } else {
3780 /* ACX100 Tx buffer needs to be initialized by us */
3781 /* clear whole send pool. sizeof is safe here (we are acx100) */
3782 memset(adev->txdesc_start, 0, TX_CNT * sizeof(*txdesc));
3784 /* loop over whole send pool */
3785 for (i = 0; i < TX_CNT; i++) {
3786 acx_log(LOG_DEBUG, L_REALLYVERBOSE,
3787 "configure card tx descriptor: 0x%p, "
3788 "size: 0x%X\n", txdesc, adev->txdesc_size);
3790 /* pointer to hostdesc memory */
3791 txdesc->HostMemPtr = ptr2acx(hostmemptr);
3792 /* initialise ctl */
3793 txdesc->Ctl_8 = (DESC_CTL_HOSTOWN | DESC_CTL_RECLAIM
3794 | DESC_CTL_AUTODMA |
3795 DESC_CTL_FIRSTFRAG);
3796 /* done by memset(0): txdesc->Ctl2_8 = 0; */
3797 /* point to next txdesc */
3798 txdesc->pNextDesc =
3799 cpu2acx(mem_offs + adev->txdesc_size);
3800 /* reserve two (hdr desc and payload desc) */
3801 hostdesc += 2;
3802 hostmemptr += 2 * sizeof(*hostdesc);
3803 /* go to the next one */
3804 mem_offs += adev->txdesc_size;
3805 /* ++ is safe here (we are acx100) */
3806 txdesc++;
3808 /* go back to the last one */
3809 txdesc--;
3810 /* and point to the first making it a ring buffer */
3811 txdesc->pNextDesc = cpu2acx(tx_queue_start);
3813 FN_EXIT0;
3817 /***************************************************************
3818 ** acxpci_create_rx_desc_queue
3820 static void acxpci_create_rx_desc_queue(acx_device_t * adev, u32 rx_queue_start)
3822 rxdesc_t *rxdesc;
3823 u32 mem_offs;
3824 int i;
3826 FN_ENTER;
3828 /* done by memset: adev->rx_tail = 0; */
3830 /* ACX111 doesn't need any further config: preconfigures itself.
3831 * Simply print ring buffer for debugging */
3832 if (IS_ACX111(adev)) {
3833 /* rxdesc_start already set here */
3835 adev->rxdesc_start =
3836 (rxdesc_t *) ((u8 *) adev->iobase2 + rx_queue_start);
3838 rxdesc = adev->rxdesc_start;
3839 for (i = 0; i < RX_CNT; i++) {
3840 acx_log(LOG_DEBUG, L_REALLYVERBOSE,
3841 "rx descriptor %d @ 0x%p\n", i, rxdesc);
3842 rxdesc = adev->rxdesc_start = (rxdesc_t *)
3843 (adev->iobase2 + acx2cpu(rxdesc->pNextDesc));
3845 } else {
3846 /* we didn't pre-calculate rxdesc_start in case of ACX100 */
3847 /* rxdesc_start should be right AFTER Tx pool */
3848 adev->rxdesc_start = (rxdesc_t *)
3849 ((u8 *) adev->txdesc_start + (TX_CNT * sizeof(txdesc_t)));
3850 /* NB: sizeof(txdesc_t) above is valid because we know
3851 ** we are in if (acx100) block. Beware of cut-n-pasting elsewhere!
3852 ** acx111's txdesc is larger! */
3854 memset(adev->rxdesc_start, 0, RX_CNT * sizeof(*rxdesc));
3856 /* loop over whole receive pool */
3857 rxdesc = adev->rxdesc_start;
3858 mem_offs = rx_queue_start;
3859 for (i = 0; i < RX_CNT; i++) {
3860 acx_log(LOG_DEBUG, L_REALLYVERBOSE,
3861 "rx descriptor @ 0x%p\n", rxdesc);
3862 rxdesc->Ctl_8 = DESC_CTL_RECLAIM | DESC_CTL_AUTODMA;
3863 /* point to next rxdesc */
3864 rxdesc->pNextDesc = cpu2acx(mem_offs + sizeof(*rxdesc));
3865 /* go to the next one */
3866 mem_offs += sizeof(*rxdesc);
3867 rxdesc++;
3869 /* go to the last one */
3870 rxdesc--;
3872 /* and point to the first making it a ring buffer */
3873 rxdesc->pNextDesc = cpu2acx(rx_queue_start);
3875 FN_EXIT0;
3879 /***************************************************************
3880 ** acxpci_create_desc_queues
3882 void
3883 acxpci_create_desc_queues(acx_device_t * adev, u32 tx_queue_start,
3884 u32 rx_queue_start)
3886 acxpci_create_tx_desc_queue(adev, tx_queue_start);
3887 acxpci_create_rx_desc_queue(adev, rx_queue_start);
3891 /***************************************************************
3892 ** acxpci_s_proc_diag_output
3894 char *acxpci_s_proc_diag_output(char *p, acx_device_t * adev)
3896 const char *rtl, *thd, *ttl;
3897 rxhostdesc_t *rxhostdesc;
3898 txdesc_t *txdesc;
3899 int i;
3901 FN_ENTER;
3903 p += sprintf(p, "** Rx buf **\n");
3904 rxhostdesc = adev->rxhostdesc_start;
3905 if (rxhostdesc)
3906 for (i = 0; i < RX_CNT; i++) {
3907 rtl = (i == adev->rx_tail) ? " [tail]" : "";
3908 if ((rxhostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
3909 && (rxhostdesc->
3910 Status & cpu_to_le32(DESC_STATUS_FULL)))
3911 p += sprintf(p, "%02u FULL%s\n", i, rtl);
3912 else
3913 p += sprintf(p, "%02u empty%s\n", i, rtl);
3914 rxhostdesc++;
3916 /* p += sprintf(p, "** Tx buf (free %d, Linux netqueue %s) **\n",
3917 adev->tx_free,
3918 acx_queue_stopped(adev->ieee) ? "STOPPED" : "running");*/
3919 txdesc = adev->txdesc_start;
3920 if (txdesc)
3921 for (i = 0; i < TX_CNT; i++) {
3922 thd = (i == adev->tx_head) ? " [head]" : "";
3923 ttl = (i == adev->tx_tail) ? " [tail]" : "";
3924 if (txdesc->Ctl_8 & DESC_CTL_ACXDONE)
3925 p += sprintf(p, "%02u free (%02X)%s%s\n", i,
3926 txdesc->Ctl_8, thd, ttl);
3927 else
3928 p += sprintf(p, "%02u tx (%02X)%s%s\n", i,
3929 txdesc->Ctl_8, thd, ttl);
3930 txdesc = advance_txdesc(adev, txdesc, 1);
3932 p += sprintf(p,
3933 "\n"
3934 "** PCI data **\n"
3935 "txbuf_start %p, txbuf_area_size %u, txbuf_startphy %08llx\n"
3936 "txdesc_size %u, txdesc_start %p\n"
3937 "txhostdesc_start %p, txhostdesc_area_size %u, txhostdesc_startphy %08llx\n"
3938 "rxdesc_start %p\n"
3939 "rxhostdesc_start %p, rxhostdesc_area_size %u, rxhostdesc_startphy %08llx\n"
3940 "rxbuf_start %p, rxbuf_area_size %u, rxbuf_startphy %08llx\n",
3941 adev->txbuf_start, adev->txbuf_area_size,
3942 (unsigned long long)adev->txbuf_startphy,
3943 adev->txdesc_size, adev->txdesc_start,
3944 adev->txhostdesc_start, adev->txhostdesc_area_size,
3945 (unsigned long long)adev->txhostdesc_startphy,
3946 adev->rxdesc_start,
3947 adev->rxhostdesc_start, adev->rxhostdesc_area_size,
3948 (unsigned long long)adev->rxhostdesc_startphy,
3949 adev->rxbuf_start, adev->rxbuf_area_size,
3950 (unsigned long long)adev->rxbuf_startphy);
3952 FN_EXIT0;
3953 return p;
3957 /***********************************************************************
3959 int acxpci_proc_eeprom_output(char *buf, acx_device_t * adev)
3961 char *p = buf;
3962 int i;
3964 FN_ENTER;
3966 for (i = 0; i < 0x400; i++) {
3967 acxpci_read_eeprom_byte(adev, i, p++);
3970 FN_EXIT1(p - buf);
3971 return p - buf;
3975 /***********************************************************************
3977 int acx100pci_s_set_tx_level(acx_device_t * adev, u8 level_dbm)
3979 /* since it can be assumed that at least the Maxim radio has a
3980 * maximum power output of 20dBm and since it also can be
3981 * assumed that these values drive the DAC responsible for
3982 * setting the linear Tx level, I'd guess that these values
3983 * should be the corresponding linear values for a dBm value,
3984 * in other words: calculate the values from that formula:
3985 * Y [dBm] = 10 * log (X [mW])
3986 * then scale the 0..63 value range onto the 1..100mW range (0..20 dBm)
3987 * and you're done...
3988 * Hopefully that's ok, but you never know if we're actually
3989 * right... (especially since Windows XP doesn't seem to show
3990 * actual Tx dBm values :-P) */
3992 /* NOTE: on Maxim, value 30 IS 30mW, and value 10 IS 10mW - so the
3993 * values are EXACTLY mW!!! Not sure about RFMD and others,
3994 * though... */
3995 static const u8 dbm2val_maxim[21] = {
3996 63, 63, 63, 62,
3997 61, 61, 60, 60,
3998 59, 58, 57, 55,
3999 53, 50, 47, 43,
4000 38, 31, 23, 13,
4003 static const u8 dbm2val_rfmd[21] = {
4004 0, 0, 0, 1,
4005 2, 2, 3, 3,
4006 4, 5, 6, 8,
4007 10, 13, 16, 20,
4008 25, 32, 41, 50,
4011 const u8 *table;
4013 switch (adev->radio_type) {
4014 case RADIO_MAXIM_0D:
4015 table = &dbm2val_maxim[0];
4016 break;
4017 case RADIO_RFMD_11:
4018 case RADIO_RALINK_15:
4019 table = &dbm2val_rfmd[0];
4020 break;
4021 default:
4022 acx_log(LOG_WARNING, L_ANY, "%s: unknown/unsupported radio type, "
4023 "cannot modify tx power level yet!\n",
4024 wiphy_name(adev->ieee->wiphy));
4025 return NOT_OK;
4027 acx_log(LOG_INFO, L_ANY,
4028 "%s: changing radio power level to %u dBm (%u)\n",
4029 wiphy_name(adev->ieee->wiphy), level_dbm, table[level_dbm]);
4030 acxpci_s_write_phy_reg(adev, 0x11, table[level_dbm]);
4031 return OK;
4034 #ifdef CONFIG_VLYNQ
4035 struct vlynq_reg_config {
4036 u32 offset;
4037 u32 value;
4040 struct vlynq_known {
4041 u32 chip_id;
4042 char name[32];
4043 struct vlynq_mapping rx_mapping[4];
4044 int irq;
4045 int irq_type;
4046 int num_regs;
4047 struct vlynq_reg_config regs[10];
4050 #define CHIP_TNETW1130 0x00000009
4051 #define CHIP_TNETW1350 0x00000029
4053 static struct vlynq_known known_devices[] = {
4055 .chip_id = CHIP_TNETW1130, .name = "TI TNETW1130",
4056 .rx_mapping = {
4057 { .size = 0x22000, .offset = 0xf0000000 },
4058 { .size = 0x40000, .offset = 0xc0000000 },
4059 { .size = 0x0, .offset = 0x0 },
4060 { .size = 0x0, .offset = 0x0 },
4062 .irq = 0,
4063 .irq_type = IRQ_TYPE_EDGE_RISING,
4064 .num_regs = 5,
4065 .regs = {
4067 .offset = 0x790,
4068 .value = (0xd0000000 - PHYS_OFFSET)
4071 .offset = 0x794,
4072 .value = (0xd0000000 - PHYS_OFFSET)
4074 { .offset = 0x740, .value = 0 },
4075 { .offset = 0x744, .value = 0x00010000 },
4076 { .offset = 0x764, .value = 0x00010000 },
4080 .chip_id = CHIP_TNETW1350, .name = "TI TNETW1350",
4081 .rx_mapping = {
4082 { .size = 0x100000, .offset = 0x00300000 },
4083 { .size = 0x80000, .offset = 0x00000000 },
4084 { .size = 0x0, .offset = 0x0 },
4085 { .size = 0x0, .offset = 0x0 },
4087 .irq = 0,
4088 .irq_type = IRQ_TYPE_EDGE_RISING,
4089 .num_regs = 5,
4090 .regs = {
4092 .offset = 0x790,
4093 .value = (0x60000000 - PHYS_OFFSET)
4096 .offset = 0x794,
4097 .value = (0x60000000 - PHYS_OFFSET)
4099 { .offset = 0x740, .value = 0 },
4100 { .offset = 0x744, .value = 0x00010000 },
4101 { .offset = 0x764, .value = 0x00010000 },
4106 static struct vlynq_device_id acx_vlynq_id[] = {
4107 { CHIP_TNETW1130, vlynq_div_auto, 0 },
4108 { CHIP_TNETW1350, vlynq_div_auto, 1 },
4109 { 0, 0, 0 },
4112 static __devinit int vlynq_probe(struct vlynq_device *vdev,
4113 struct vlynq_device_id *id)
4115 int result = -EIO, i;
4116 u32 addr;
4117 struct ieee80211_hw *ieee;
4118 acx_device_t *adev = NULL;
4119 acx111_ie_configoption_t co;
4120 struct vlynq_mapping mapping[4] = { { 0, }, };
4121 struct vlynq_known *match = NULL;
4123 FN_ENTER;
4124 result = vlynq_enable_device(vdev);
4125 if (result)
4126 return result;
4128 match = &known_devices[id->driver_data];
4130 if (!match) {
4131 result = -ENODEV;
4132 goto fail;
4135 mapping[0].offset = ARCH_PFN_OFFSET << PAGE_SHIFT;
4136 mapping[0].size = 0x02000000;
4137 vlynq_set_local_mapping(vdev, vdev->mem_start, mapping);
4138 vlynq_set_remote_mapping(vdev, 0, match->rx_mapping);
4140 set_irq_type(vlynq_virq_to_irq(vdev, match->irq), match->irq_type);
4142 addr = (u32)ioremap(vdev->mem_start, 0x1000);
4143 if (!addr) {
4144 acx_log(LOG_WARNING, L_ANY, "%s: failed to remap io memory\n",
4145 vdev->dev.bus_id);
4146 result = -ENXIO;
4147 goto fail;
4150 for (i = 0; i < match->num_regs; i++)
4151 iowrite32(match->regs[i].value,
4152 (u32 *)(addr + match->regs[i].offset));
4154 iounmap((void *)addr);
4156 ieee = ieee80211_alloc_hw(sizeof(struct acx_device), &acxpci_hw_ops);
4157 if (!ieee) {
4158 acx_log(LOG_WARNING, L_ANY,
4159 "could not allocate ieee80211 structure %s\n",
4160 vdev->dev.bus_id);
4161 goto fail_alloc_netdev;
4163 ieee->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
4164 ieee->queues = 1;
4166 adev = ieee2adev(ieee);
4168 memset(adev, 0, sizeof(*adev));
4169 /** Set up our private interface **/
4170 spin_lock_init(&adev->spinlock); /* initial state: unlocked */
4171 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
4172 mutex_init(&adev->mutex);
4173 /* since nobody can see new netdev yet, we can as well
4174 ** just _presume_ that we're under sem (instead of actually taking it): */
4175 /* acx_sem_lock(adev); */
4176 adev->ieee = ieee;
4177 adev->vdev = vdev;
4178 adev->bus_dev = &vdev->dev;
4180 /** Finished with private interface **/
4182 vlynq_set_drvdata(vdev, ieee);
4183 if (!request_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start, "acx")) {
4184 acx_log(LOG_WARNING, L_ANY, "cannot reserve VLYNQ memory region\n");
4185 goto fail_request_mem_region;
4188 adev->iobase = ioremap(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4189 if (!adev->iobase) {
4190 acx_log(LOG_WARNING, L_ANY, "ioremap() FAILED\n");
4191 goto fail_ioremap;
4193 adev->iobase2 = adev->iobase + match->rx_mapping[0].size;
4194 adev->chip_type = CHIPTYPE_ACX111;
4195 adev->chip_name = match->name;
4196 adev->io = IO_ACX111;
4197 adev->irq = vlynq_virq_to_irq(vdev, match->irq);
4199 acx_log(LOG_INFO, L_ANY, "found %s-based wireless network card at %s, "
4200 "irq:%d, phymem:0x%x, mem:0x%p\n",
4201 match->name, vdev->dev.bus_id, adev->irq,
4202 vdev->mem_start, adev->iobase);
4203 // acx_log(LOG_INFO, L_ANY,
4204 // "initial debug setting is 0x%04X\n", acx_debug);
4206 if (0 == adev->irq) {
4207 acx_log(LOG_WARNING, L_ANY, "can't use IRQ 0\n");
4208 goto fail_irq;
4210 SET_IEEE80211_DEV(ieee, &vdev->dev);
4212 /* request shared IRQ handler */
4213 if (request_irq
4214 (adev->irq, acxpci_i_interrupt, IRQF_SHARED, KBUILD_MODNAME, adev)) {
4215 acx_log(LOG_WARNING, L_ANY, "%s: request_irq FAILED\n",
4216 wiphy_name(adev->ieee->wiphy));
4217 result = -EAGAIN;
4218 goto done;
4220 acx_log(LOG_DEBUG, L_IRQ | L_REALLYVERBOSE,
4221 "request_irq %d successful\n", adev->irq);
4223 /* to find crashes due to weird driver access
4224 * to unconfigured interface (ifup) */
4225 adev->mgmt_timer.function = (void (*)(unsigned long))0x0000dead;
4228 /* ok, pci setup is finished, now start initializing the card */
4230 /* NB: read_reg() reads may return bogus data before reset_dev(),
4231 * since the firmware which directly controls large parts of the I/O
4232 * registers isn't initialized yet.
4233 * acx100 seems to be more affected than acx111 */
4234 if (OK != acxpci_s_reset_dev(adev))
4235 goto fail_reset;
4237 if (OK != acx_s_init_mac(adev))
4238 goto fail_init_mac;
4240 acx_s_interrogate(adev, &co, ACX111_IE_CONFIG_OPTIONS);
4241 /* TODO: merge them into one function, they are called just once and are the same for pci & usb */
4242 if (OK != acxpci_read_eeprom_byte(adev, 0x05, &adev->eeprom_version))
4243 goto fail_read_eeprom_version;
4245 acx_s_parse_configoption(adev, &co);
4246 acx_s_set_defaults(adev);
4247 acx_s_get_firmware_version(adev); /* needs to be after acx_s_init_mac() */
4248 acx_display_hardware_details(adev);
4250 /* Register the card, AFTER everything else has been set up,
4251 * since otherwise an ioctl could step on our feet due to
4252 * firmware operations happening in parallel or uninitialized data */
4255 acx_proc_register_entries(ieee);
4257 /* Now we have our device, so make sure the kernel doesn't try
4258 * to send packets even though we're not associated to a network yet */
4260 /* after register_netdev() userspace may start working with dev
4261 * (in particular, on other CPUs), we only need to up the sem */
4262 /* acx_sem_unlock(adev); */
4264 acx_log(LOG_INFO, L_ANY, "driver " ACX_RELEASE ", net device %s, "
4265 "driver compiled against wireless extensions %d and Linux %s\n",
4266 wiphy_name(adev->ieee->wiphy), WIRELESS_EXT, UTS_RELEASE);
4268 MAC_COPY(adev->ieee->wiphy->perm_addr, adev->dev_addr);
4270 acx_log(LOG_DEBUG, L_IRQ | L_INIT, "using IRQ %d\n", adev->irq);
4272 /** done with board specific setup **/
4274 result = acx_setup_modes(adev);
4275 if (result) {
4276 acx_log(LOG_WARNING, L_ANY, "can't register hwmode\n");
4277 goto fail_register_netdev;
4280 acx_init_task_scheduler(adev);
4281 result = ieee80211_register_hw(adev->ieee);
4282 if (OK != result) {
4283 acx_log(LOG_WARNING, L_ANY,
4284 "acx: ieee80211_register_hw() FAILED: %d\n", result);
4285 goto fail_register_netdev;
4287 #if CMD_DISCOVERY
4288 great_inquisitor(adev);
4289 #endif
4291 result = OK;
4292 goto done;
4294 /* error paths: undo everything in reverse order... */
4297 acxpci_s_delete_dma_regions(adev);
4299 fail_init_mac:
4300 fail_read_eeprom_version:
4301 fail_reset:
4303 fail_alloc_netdev:
4304 fail_irq:
4306 iounmap(adev->iobase);
4307 fail_ioremap:
4309 release_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4310 fail_request_mem_region:
4311 fail_register_netdev:
4312 ieee80211_free_hw(ieee);
4313 fail:
4314 vlynq_disable_device(vdev);
4315 done:
4316 FN_EXIT1(result);
4317 return result;
4320 static void vlynq_remove(struct vlynq_device *vdev)
4322 struct ieee80211_hw *hw = vlynq_get_drvdata(vdev);
4323 acx_device_t *adev = ieee2adev(hw);
4324 unsigned long flags;
4325 FN_ENTER;
4327 if (!hw) {
4328 acx_log(LOG_DEBUG, L_REALLYVERBOSE,
4329 "%s: card is unused. Skipping any release code\n",
4330 __func__);
4331 goto end;
4335 acx_lock(adev, flags);
4336 acx_unlock(adev, flags);
4337 adev->initialized = 0;
4339 /* If device wasn't hot unplugged... */
4340 if (adev_present(adev)) {
4342 acx_sem_lock(adev);
4344 /* disable both Tx and Rx to shut radio down properly */
4345 if (adev->initialized) {
4346 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_TX, NULL, 0);
4347 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_RX, NULL, 0);
4349 acx_lock(adev, flags);
4350 /* disable power LED to save power :-) */
4351 acx_log(LOG_INFO, L_INIT,
4352 "switching off power LED to save power\n");
4353 acxpci_l_power_led(adev, 0);
4354 /* stop our eCPU */
4355 acx_unlock(adev, flags);
4357 acx_sem_unlock(adev);
4360 /* unregister the device to not let the kernel
4361 * (e.g. ioctls) access a half-deconfigured device
4362 * NB: this will cause acxpci_e_close() to be called,
4363 * thus we shouldn't call it under sem!
4365 acx_log(LOG_INFO, L_INIT, "removing device %s\n",
4366 wiphy_name(adev->ieee->wiphy));
4367 ieee80211_unregister_hw(adev->ieee);
4369 /* unregister_netdev ensures that no references to us left.
4370 * For paranoid reasons we continue to follow the rules */
4371 acx_sem_lock(adev);
4373 if (adev->dev_state_mask & ACX_STATE_IFACE_UP) {
4374 acxpci_s_down(hw);
4375 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
4378 acx_proc_unregister_entries(adev->ieee);
4380 /* finally, clean up PCI bus state */
4381 acxpci_s_delete_dma_regions(adev);
4382 if (adev->iobase)
4383 iounmap(adev->iobase);
4384 if (adev->iobase2)
4385 iounmap(adev->iobase2);
4386 release_mem_region(vdev->mem_start, vdev->mem_end - vdev->mem_start);
4388 /* remove dev registration */
4390 acx_sem_unlock(adev);
4391 vlynq_disable_device(vdev);
4393 /* Free netdev (quite late,
4394 * since otherwise we might get caught off-guard
4395 * by a netdev timeout handler execution
4396 * expecting to see a working dev...) */
4397 ieee80211_free_hw(adev->ieee);
4399 end:
4400 FN_EXIT0;
4403 static struct vlynq_driver vlynq_acx = {
4404 .name = "acx_vlynq",
4405 .id_table = acx_vlynq_id,
4406 .probe = vlynq_probe,
4407 .remove = __devexit_p(vlynq_remove),
4409 #endif /* CONFIG_VLYNQ */
4412 /***********************************************************************
4413 ** Data for init_module/cleanup_module
4415 #ifdef CONFIG_PCI
4416 static const struct pci_device_id acxpci_id_tbl[] __devinitdata = {
4418 .vendor = PCI_VENDOR_ID_TI,
4419 .device = PCI_DEVICE_ID_TI_TNETW1100A,
4420 .subvendor = PCI_ANY_ID,
4421 .subdevice = PCI_ANY_ID,
4422 .driver_data = CHIPTYPE_ACX100,
4425 .vendor = PCI_VENDOR_ID_TI,
4426 .device = PCI_DEVICE_ID_TI_TNETW1100B,
4427 .subvendor = PCI_ANY_ID,
4428 .subdevice = PCI_ANY_ID,
4429 .driver_data = CHIPTYPE_ACX100,
4432 .vendor = PCI_VENDOR_ID_TI,
4433 .device = PCI_DEVICE_ID_TI_TNETW1130,
4434 .subvendor = PCI_ANY_ID,
4435 .subdevice = PCI_ANY_ID,
4436 .driver_data = CHIPTYPE_ACX111,
4439 .vendor = 0,
4440 .device = 0,
4441 .subvendor = 0,
4442 .subdevice = 0,
4443 .driver_data = 0,
4447 MODULE_DEVICE_TABLE(pci, acxpci_id_tbl);
4449 static struct pci_driver
4450 acxpci_drv_id = {
4451 .name = "acx_pci",
4452 .id_table = acxpci_id_tbl,
4453 .probe = acxpci_e_probe,
4454 .remove = __devexit_p(acxpci_e_remove),
4455 #ifdef CONFIG_PM
4456 .suspend = acxpci_e_suspend,
4457 .resume = acxpci_e_resume
4458 #endif /* CONFIG_PM */
4460 #endif /* CONFIG_PCI */
4462 /***********************************************************************
4463 ** acxpci_e_init_module
4465 ** Module initialization routine, called once at module load time
4467 int __init acxpci_e_init_module(void)
4469 int res;
4471 FN_ENTER;
4473 #if (ACX_IO_WIDTH==32)
4474 acx_log(LOG_INFO, L_ANY, "compiled to use 32bit I/O access. "
4475 "I/O timing issues might occur, such as "
4476 "non-working firmware upload. Report them\n");
4477 #else
4478 acx_log(LOG_INFO, L_ANY, "compiled to use 16bit I/O access only "
4479 "(compatibility mode)\n");
4480 #endif
4482 #ifdef __LITTLE_ENDIAN
4483 #define ENDIANNESS_STRING "running on a little-endian CPU\n"
4484 #else
4485 #define ENDIANNESS_STRING "running on a BIG-ENDIAN CPU\n"
4486 #endif
4487 acx_log(LOG_INFO, L_INIT, ENDIANNESS_STRING);
4488 acx_log(LOG_INFO, L_INIT, "PCI/VLYNQ module " ACX_RELEASE
4489 " initialized, waiting for cards to probe...\n");
4491 #ifdef CONFIG_PCI
4492 res = pci_register_driver(&acxpci_drv_id);
4493 #elif CONFIG_VLYNQ
4494 res = vlynq_register_driver(&vlynq_acx);
4495 #endif
4496 FN_EXIT1(res);
4497 return res;
4501 /***********************************************************************
4502 ** acxpci_e_cleanup_module
4504 ** Called at module unload time. This is our last chance to
4505 ** clean up after ourselves.
4507 void __exit acxpci_e_cleanup_module(void)
4509 FN_ENTER;
4511 #ifdef CONFIG_PCI
4512 pci_unregister_driver(&acxpci_drv_id);
4513 #elif CONFIG_VLYNQ
4514 vlynq_unregister_driver(&vlynq_acx);
4515 #endif
4516 acx_log(LOG_INFO, L_INIT,
4517 "PCI module " ACX_RELEASE " unloaded\n");
4518 FN_EXIT0;