Original 20051017 tarball
[acx-mac80211.git] / pci.c
blobba61a1f1a8b698df4e5953ce6061ac94a5d6dec7
1 /***********************************************************************
2 ** Copyright (C) 2003 ACX100 Open Source Project
3 **
4 ** The contents of this file are subject to the Mozilla Public
5 ** License Version 1.1 (the "License"); you may not use this file
6 ** except in compliance with the License. You may obtain a copy of
7 ** the License at http://www.mozilla.org/MPL/
8 **
9 ** Software distributed under the License is distributed on an "AS
10 ** IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11 ** implied. See the License for the specific language governing
12 ** rights and limitations under the License.
14 ** Alternatively, the contents of this file may be used under the
15 ** terms of the GNU Public License version 2 (the "GPL"), in which
16 ** case the provisions of the GPL are applicable instead of the
17 ** above. If you wish to allow the use of your version of this file
18 ** only under the terms of the GPL and not to allow others to use
19 ** your version of this file under the MPL, indicate your decision
20 ** by deleting the provisions above and replace them with the notice
21 ** and other provisions required by the GPL. If you do not delete
22 ** the provisions above, a recipient may use your version of this
23 ** file under either the MPL or the GPL.
24 ** ---------------------------------------------------------------------
25 ** Inquiries regarding the ACX100 Open Source Project can be
26 ** made directly to:
28 ** acx100-users@lists.sf.net
29 ** http://acx100.sf.net
30 ** ---------------------------------------------------------------------
32 #define ACX_PCI 1
34 #include <linux/config.h>
35 #include <linux/version.h>
36 #include <linux/kernel.h>
37 #include <linux/module.h>
38 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
39 #include <linux/moduleparam.h>
40 #endif
41 #include <linux/sched.h>
42 #include <linux/types.h>
43 #include <linux/skbuff.h>
44 #include <linux/slab.h>
45 #include <linux/if_arp.h>
46 #include <linux/rtnetlink.h>
47 #include <linux/wireless.h>
48 #if WIRELESS_EXT >= 13
49 #include <net/iw_handler.h>
50 #endif
51 #include <linux/netdevice.h>
52 #include <linux/ioport.h>
53 #include <linux/pci.h>
54 #include <linux/pm.h>
56 #include "acx.h"
59 /***********************************************************************
61 #define PCI_TYPE (PCI_USES_MEM | PCI_ADDR0 | PCI_NO_ACPI_WAKE)
62 #define PCI_ACX100_REGION1 0x01
63 #define PCI_ACX100_REGION1_SIZE 0x1000 /* Memory size - 4K bytes */
64 #define PCI_ACX100_REGION2 0x02
65 #define PCI_ACX100_REGION2_SIZE 0x10000 /* Memory size - 64K bytes */
67 #define PCI_ACX111_REGION1 0x00
68 #define PCI_ACX111_REGION1_SIZE 0x2000 /* Memory size - 8K bytes */
69 #define PCI_ACX111_REGION2 0x01
70 #define PCI_ACX111_REGION2_SIZE 0x20000 /* Memory size - 128K bytes */
72 /* Texas Instruments Vendor ID */
73 #define PCI_VENDOR_ID_TI 0x104c
75 /* ACX100 22Mb/s WLAN controller */
76 #define PCI_DEVICE_ID_TI_TNETW1100A 0x8400
77 #define PCI_DEVICE_ID_TI_TNETW1100B 0x8401
79 /* ACX111 54Mb/s WLAN controller */
80 #define PCI_DEVICE_ID_TI_TNETW1130 0x9066
82 /* PCI Class & Sub-Class code, Network-'Other controller' */
83 #define PCI_CLASS_NETWORK_OTHERS 0x0280
85 #define CARD_EEPROM_ID_SIZE 6
88 /***********************************************************************
90 static void acxpci_i_tx_timeout(netdevice_t *dev);
91 static irqreturn_t acxpci_i_interrupt(int irq, void *dev_id, struct pt_regs *regs);
92 static void acxpci_i_set_multicast_list(netdevice_t *dev);
94 static int acxpci_e_open(netdevice_t *dev);
95 static int acxpci_e_close(netdevice_t *dev);
96 static void acxpci_s_up(netdevice_t *dev);
97 static void acxpci_s_down(netdevice_t *dev);
100 /***********************************************************************
101 ** Register access
104 /* Pick one */
105 /* #define INLINE_IO static */
106 #define INLINE_IO static inline
108 INLINE_IO u32
109 read_reg32(wlandevice_t *priv, unsigned int offset)
111 #if ACX_IO_WIDTH == 32
112 return readl((u8 *)priv->iobase + priv->io[offset]);
113 #else
114 return readw((u8 *)priv->iobase + priv->io[offset])
115 + (readw((u8 *)priv->iobase + priv->io[offset] + 2) << 16);
116 #endif
119 INLINE_IO u16
120 read_reg16(wlandevice_t *priv, unsigned int offset)
122 return readw((u8 *)priv->iobase + priv->io[offset]);
125 INLINE_IO u8
126 read_reg8(wlandevice_t *priv, unsigned int offset)
128 return readb((u8 *)priv->iobase + priv->io[offset]);
131 INLINE_IO void
132 write_reg32(wlandevice_t *priv, unsigned int offset, u32 val)
134 #if ACX_IO_WIDTH == 32
135 writel(val, (u8 *)priv->iobase + priv->io[offset]);
136 #else
137 writew(val & 0xffff, (u8 *)priv->iobase + priv->io[offset]);
138 writew(val >> 16, (u8 *)priv->iobase + priv->io[offset] + 2);
139 #endif
142 INLINE_IO void
143 write_reg16(wlandevice_t *priv, unsigned int offset, u16 val)
145 writew(val, (u8 *)priv->iobase + priv->io[offset]);
148 INLINE_IO void
149 write_reg8(wlandevice_t *priv, unsigned int offset, u8 val)
151 writeb(val, (u8 *)priv->iobase + priv->io[offset]);
154 /* Handle PCI posting properly:
155 * Make sure that writes reach the adapter in case they require to be executed
156 * *before* the next write, by reading a random (and safely accessible) register.
157 * This call has to be made if there is no read following (which would flush the data
158 * to the adapter), yet the written data has to reach the adapter immediately. */
159 INLINE_IO void
160 write_flush(wlandevice_t *priv)
162 /* readb(priv->iobase + priv->io[IO_ACX_INFO_MAILBOX_OFFS]); */
163 /* faster version (accesses the first register, IO_ACX_SOFT_RESET,
164 * which should also be safe): */
165 readb(priv->iobase);
169 /***********************************************************************
171 typedef struct acx_device {
172 netdevice_t *newest;
173 } acx_device_t;
175 /* if this driver was only about PCI devices, then we probably wouldn't
176 * need this linked list.
177 * But if we want to register ALL kinds of devices in one global list,
178 * then we need it and need to maintain it properly. */
179 static struct acx_device root_acx_dev = {
180 .newest = NULL,
182 DECLARE_MUTEX(root_acx_dev_sem);
185 /***********************************************************************
187 static inline txdesc_t*
188 get_txdesc(wlandevice_t* priv, int index)
190 return (txdesc_t*) (((u8*)priv->txdesc_start) + index * priv->txdesc_size);
193 static inline txdesc_t*
194 move_txdesc(wlandevice_t* priv, txdesc_t* txdesc, int inc)
196 return (txdesc_t*) (((u8*)txdesc) + inc * priv->txdesc_size);
199 static txhostdesc_t*
200 get_txhostdesc(wlandevice_t* priv, txdesc_t* txdesc)
202 int index = (u8*)txdesc - (u8*)priv->txdesc_start;
203 if (ACX_DEBUG && (index % priv->txdesc_size)) {
204 printk("bad txdesc ptr %p\n", txdesc);
205 return NULL;
207 index /= priv->txdesc_size;
208 if (ACX_DEBUG && (index >= TX_CNT)) {
209 printk("bad txdesc ptr %p\n", txdesc);
210 return NULL;
212 return &priv->txhostdesc_start[index*2];
215 static client_t*
216 get_txc(wlandevice_t* priv, txdesc_t* txdesc)
218 int index = (u8*)txdesc - (u8*)priv->txdesc_start;
219 if (ACX_DEBUG && (index % priv->txdesc_size)) {
220 printk("bad txdesc ptr %p\n", txdesc);
221 return NULL;
223 index /= priv->txdesc_size;
224 if (ACX_DEBUG && (index >= TX_CNT)) {
225 printk("bad txdesc ptr %p\n", txdesc);
226 return NULL;
228 return priv->txc[index];
231 static void
232 put_txc(wlandevice_t* priv, txdesc_t* txdesc, client_t* c)
234 int index = (u8*)txdesc - (u8*)priv->txdesc_start;
235 if (ACX_DEBUG && (index % priv->txdesc_size)) {
236 printk("bad txdesc ptr %p\n", txdesc);
237 return;
239 index /= priv->txdesc_size;
240 if (ACX_DEBUG && (index >= TX_CNT)) {
241 printk("bad txdesc ptr %p\n", txdesc);
242 return;
244 priv->txc[index] = c;
248 /***********************************************************************
249 ** EEPROM and PHY read/write helpers
251 /***********************************************************************
252 ** acxpci_read_eeprom_byte
254 ** Function called to read an octet in the EEPROM.
256 ** This function is used by acxpci_e_probe to check if the
257 ** connected card is a legal one or not.
259 ** Arguments:
260 ** priv ptr to wlandevice structure
261 ** addr address to read in the EEPROM
262 ** charbuf ptr to a char. This is where the read octet
263 ** will be stored
266 acxpci_read_eeprom_byte(wlandevice_t *priv, u32 addr, u8 *charbuf)
268 int result;
269 int count;
271 write_reg32(priv, IO_ACX_EEPROM_CFG, 0);
272 write_reg32(priv, IO_ACX_EEPROM_ADDR, addr);
273 write_flush(priv);
274 write_reg32(priv, IO_ACX_EEPROM_CTL, 2);
276 count = 0xffff;
277 while (read_reg16(priv, IO_ACX_EEPROM_CTL)) {
278 /* scheduling away instead of CPU burning loop
279 * doesn't seem to work here at all:
280 * awful delay, sometimes also failure.
281 * Doesn't matter anyway (only small delay). */
282 if (unlikely(!--count)) {
283 printk("%s: timeout waiting for EEPROM read\n",
284 priv->netdev->name);
285 result = NOT_OK;
286 goto fail;
290 *charbuf = read_reg8(priv, IO_ACX_EEPROM_DATA);
291 acxlog(L_DEBUG, "EEPROM at 0x%04X = 0x%02X\n", addr, *charbuf);
292 result = OK;
294 fail:
295 return result;
299 /***********************************************************************
300 ** Dummy EEPROM read? why?!
302 static int
303 acxpci_read_eeprom_area(wlandevice_t *priv)
305 int offs;
306 u8 tmp[0x3b];
308 for (offs = 0x8c; offs < 0xb9; offs++) {
309 acxpci_read_eeprom_byte(priv, offs, &tmp[offs - 0x8c]);
311 return OK;
315 /***********************************************************************
316 ** We don't lock hw accesses here since we never r/w eeprom in IRQ
317 ** Note: this function sleeps only because of GFP_KERNEL alloc
319 #ifdef UNUSED
321 acxpci_s_write_eeprom(wlandevice_t *priv, u32 addr, u32 len, const u8 *charbuf)
323 u8 *data_verify = NULL;
324 unsigned long flags;
325 int count, i;
326 int result = NOT_OK;
327 u16 gpio_orig;
329 printk("acx: WARNING! I would write to EEPROM now. "
330 "Since I really DON'T want to unless you know "
331 "what you're doing (THIS CODE WILL PROBABLY "
332 "NOT WORK YET!), I will abort that now. And "
333 "definitely make sure to make a "
334 "/proc/driver/acx_wlan0_eeprom backup copy first!!! "
335 "(the EEPROM content includes the PCI config header!! "
336 "If you kill important stuff, then you WILL "
337 "get in trouble and people DID get in trouble already)\n");
338 return OK;
340 FN_ENTER;
342 data_verify = kmalloc(len, GFP_KERNEL);
343 if (!data_verify) {
344 goto end;
347 /* first we need to enable the OE (EEPROM Output Enable) GPIO line
348 * to be able to write to the EEPROM.
349 * NOTE: an EEPROM writing success has been reported,
350 * but you probably have to modify GPIO_OUT, too,
351 * and you probably need to activate a different GPIO
352 * line instead! */
353 gpio_orig = read_reg16(priv, IO_ACX_GPIO_OE);
354 write_reg16(priv, IO_ACX_GPIO_OE, gpio_orig & ~1);
355 write_flush(priv);
357 /* ok, now start writing the data out */
358 for (i = 0; i < len; i++) {
359 write_reg32(priv, IO_ACX_EEPROM_CFG, 0);
360 write_reg32(priv, IO_ACX_EEPROM_ADDR, addr + i);
361 write_reg32(priv, IO_ACX_EEPROM_DATA, *(charbuf + i));
362 write_flush(priv);
363 write_reg32(priv, IO_ACX_EEPROM_CTL, 1);
365 while (read_reg16(priv, IO_ACX_EEPROM_CTL)) {
366 if (unlikely(++count > 0xffff)) {
367 printk("WARNING, DANGER!!! "
368 "Timeout waiting for EEPROM write\n");
369 goto end;
374 /* disable EEPROM writing */
375 write_reg16(priv, IO_ACX_GPIO_OE, gpio_orig);
376 write_flush(priv);
378 /* now start a verification run */
379 count = 0xffff;
380 for (i = 0; i < len; i++) {
381 write_reg32(priv, IO_ACX_EEPROM_CFG, 0);
382 write_reg32(priv, IO_ACX_EEPROM_ADDR, addr + i);
383 write_flush(priv);
384 write_reg32(priv, IO_ACX_EEPROM_CTL, 2);
386 while (read_reg16(priv, IO_ACX_EEPROM_CTL)) {
387 if (unlikely(!--count)) {
388 printk("timeout waiting for EEPROM read\n");
389 goto end;
393 data_verify[i] = read_reg16(priv, IO_ACX_EEPROM_DATA);
396 if (0 == memcmp(charbuf, data_verify, len))
397 result = OK; /* read data matches, success */
399 end:
400 kfree(data_verify);
401 FN_EXIT1(result);
402 return result;
404 #endif /* UNUSED */
407 /***********************************************************************
408 ** acxpci_s_read_phy_reg
410 ** Messing with rx/tx disabling and enabling here
411 ** (write_reg32(priv, IO_ACX_ENABLE, 0b000000xx)) kills traffic
414 acxpci_s_read_phy_reg(wlandevice_t *priv, u32 reg, u8 *charbuf)
416 int result = NOT_OK;
417 int count;
419 FN_ENTER;
421 write_reg32(priv, IO_ACX_PHY_ADDR, reg);
422 write_flush(priv);
423 write_reg32(priv, IO_ACX_PHY_CTL, 2);
425 count = 0xffff;
426 while (read_reg32(priv, IO_ACX_PHY_CTL)) {
427 /* scheduling away instead of CPU burning loop
428 * doesn't seem to work here at all:
429 * awful delay, sometimes also failure.
430 * Doesn't matter anyway (only small delay). */
431 if (unlikely(!--count)) {
432 printk("%s: timeout waiting for phy read\n",
433 priv->netdev->name);
434 *charbuf = 0;
435 goto fail;
439 acxlog(L_DEBUG, "count was %u\n", count);
440 *charbuf = read_reg8(priv, IO_ACX_PHY_DATA);
442 acxlog(L_DEBUG, "radio PHY at 0x%04X = 0x%02X\n", *charbuf, reg);
443 result = OK;
444 goto fail; /* silence compiler warning */
445 fail:
446 FN_EXIT1(result);
447 return result;
451 /***********************************************************************
454 acxpci_s_write_phy_reg(wlandevice_t *priv, u32 reg, u8 value)
456 FN_ENTER;
458 /* FIXME: we didn't use 32bit access here since mprusko said that
459 * it results in distorted sensitivity on his card (huh!?!?
460 * doesn't happen with my setup...)
461 * But with the access reordering and flushing it
462 * shouldn't happen any more...
463 * FIXME: which radio is in the problematic card? My working one
464 * is 0x11 */
465 write_reg32(priv, IO_ACX_PHY_DATA, value);
466 write_reg32(priv, IO_ACX_PHY_ADDR, reg);
467 write_flush(priv);
468 write_reg32(priv, IO_ACX_PHY_CTL, 1);
469 write_flush(priv);
470 acxlog(L_DEBUG, "radio PHY write 0x%02X at 0x%04X\n", value, reg);
472 FN_EXIT1(OK);
473 return OK;
477 #define NO_AUTO_INCREMENT 1
479 /***********************************************************************
480 ** acxpci_s_write_fw
482 ** Write the firmware image into the card.
484 ** Arguments:
485 ** priv wlan device structure
486 ** apfw_image firmware image.
488 ** Returns:
489 ** 1 firmware image corrupted
490 ** 0 success
492 static int
493 acxpci_s_write_fw(wlandevice_t *priv, const firmware_image_t *apfw_image, u32 offset)
495 int len, size;
496 u32 sum, v32;
497 /* we skip the first four bytes which contain the control sum */
498 const u8 *image = (u8*)apfw_image + 4;
500 /* start the image checksum by adding the image size value */
501 sum = image[0]+image[1]+image[2]+image[3];
502 image += 4;
504 write_reg32(priv, IO_ACX_SLV_END_CTL, 0);
506 #if NO_AUTO_INCREMENT
507 write_reg32(priv, IO_ACX_SLV_MEM_CTL, 0); /* use basic mode */
508 #else
509 write_reg32(priv, IO_ACX_SLV_MEM_CTL, 1); /* use autoincrement mode */
510 write_reg32(priv, IO_ACX_SLV_MEM_ADDR, offset); /* configure start address */
511 write_flush(priv);
512 #endif
514 len = 0;
515 size = le32_to_cpu(apfw_image->size) & (~3);
517 while (likely(len < size)) {
518 v32 = be32_to_cpu(*(u32*)image);
519 sum += image[0]+image[1]+image[2]+image[3];
520 image += 4;
521 len += 4;
523 #if NO_AUTO_INCREMENT
524 write_reg32(priv, IO_ACX_SLV_MEM_ADDR, offset + len - 4);
525 write_flush(priv);
526 #endif
527 write_reg32(priv, IO_ACX_SLV_MEM_DATA, v32);
530 acxlog(L_DEBUG, "firmware written, size:%d sum1:%x sum2:%x\n",
531 size, sum, le32_to_cpu(apfw_image->chksum));
533 /* compare our checksum with the stored image checksum */
534 return (sum != le32_to_cpu(apfw_image->chksum));
538 /***********************************************************************
539 ** acxpci_s_validate_fw
541 ** Compare the firmware image given with
542 ** the firmware image written into the card.
544 ** Arguments:
545 ** priv wlan device structure
546 ** apfw_image firmware image.
548 ** Returns:
549 ** NOT_OK firmware image corrupted or not correctly written
550 ** OK success
552 static int
553 acxpci_s_validate_fw(wlandevice_t *priv, const firmware_image_t *apfw_image,
554 u32 offset)
556 u32 v32, w32, sum;
557 int len, size;
558 int result = OK;
559 /* we skip the first four bytes which contain the control sum */
560 const u8 *image = (u8*)apfw_image + 4;
562 /* start the image checksum by adding the image size value */
563 sum = image[0]+image[1]+image[2]+image[3];
564 image += 4;
566 write_reg32(priv, IO_ACX_SLV_END_CTL, 0);
568 #if NO_AUTO_INCREMENT
569 write_reg32(priv, IO_ACX_SLV_MEM_CTL, 0); /* use basic mode */
570 #else
571 write_reg32(priv, IO_ACX_SLV_MEM_CTL, 1); /* use autoincrement mode */
572 write_reg32(priv, IO_ACX_SLV_MEM_ADDR, offset); /* configure start address */
573 #endif
575 len = 0;
576 size = le32_to_cpu(apfw_image->size) & (~3);
578 while (likely(len < size)) {
579 v32 = be32_to_cpu(*(u32*)image);
580 image += 4;
581 len += 4;
583 #if NO_AUTO_INCREMENT
584 write_reg32(priv, IO_ACX_SLV_MEM_ADDR, offset + len - 4);
585 #endif
586 w32 = read_reg32(priv, IO_ACX_SLV_MEM_DATA);
588 if (unlikely(w32 != v32)) {
589 printk("acx: FATAL: firmware upload: "
590 "data parts at offset %d don't match (0x%08X vs. 0x%08X)! "
591 "I/O timing issues or defective memory, with DWL-xx0+? "
592 "ACX_IO_WIDTH=16 may help. Please report\n",
593 len, v32, w32);
594 result = NOT_OK;
595 break;
598 sum += (u8)w32 + (u8)(w32>>8) + (u8)(w32>>16) + (u8)(w32>>24);
601 /* sum control verification */
602 if (result != NOT_OK) {
603 if (sum != le32_to_cpu(apfw_image->chksum)) {
604 printk("acx: FATAL: firmware upload: "
605 "checksums don't match!\n");
606 result = NOT_OK;
610 return result;
614 /***********************************************************************
615 ** acxpci_s_upload_fw
617 ** Called from acx_reset_dev
619 static int
620 acxpci_s_upload_fw(wlandevice_t *priv)
622 firmware_image_t *apfw_image = NULL;
623 int res = NOT_OK;
624 int try;
625 u32 size;
626 char filename[sizeof("tiacx1NNcNN")];
628 FN_ENTER;
630 /* Try combined, then main image */
631 priv->need_radio_fw = 0;
632 sprintf(filename, "tiacx1%02dc%02X",
633 IS_ACX111(priv)*11, priv->radio_type);
635 apfw_image = acx_s_read_fw(&priv->pdev->dev, filename, &size);
636 if (!apfw_image) {
637 priv->need_radio_fw = 1;
638 filename[sizeof("tiacx1NN")-1] = '\0';
639 apfw_image = acx_s_read_fw(&priv->pdev->dev, filename, &size);
640 if (!apfw_image) {
641 FN_EXIT1(NOT_OK);
642 return NOT_OK;
646 for (try = 1; try <= 5; try++) {
647 res = acxpci_s_write_fw(priv, apfw_image, 0);
648 acxlog(L_DEBUG|L_INIT, "acx_write_fw (main/combined):%d\n", res);
649 if (OK == res) {
650 res = acxpci_s_validate_fw(priv, apfw_image, 0);
651 acxlog(L_DEBUG|L_INIT, "acx_validate_fw "
652 "(main/combined):%d\n", res);
655 if (OK == res) {
656 SET_BIT(priv->dev_state_mask, ACX_STATE_FW_LOADED);
657 break;
659 printk("acx: firmware upload attempt #%d FAILED, "
660 "retrying...\n", try);
661 acx_s_msleep(1000); /* better wait for a while... */
664 vfree(apfw_image);
666 FN_EXIT1(res);
667 return res;
671 /***********************************************************************
672 ** acxpci_s_upload_radio
674 ** Uploads the appropriate radio module firmware into the card.
677 acxpci_s_upload_radio(wlandevice_t *priv)
679 acx_ie_memmap_t mm;
680 firmware_image_t *radio_image = NULL;
681 acx_cmd_radioinit_t radioinit;
682 int res = NOT_OK;
683 int try;
684 u32 offset;
685 u32 size;
686 char filename[sizeof("tiacx1NNrNN")];
688 if (!priv->need_radio_fw) return OK;
690 FN_ENTER;
692 acx_s_interrogate(priv, &mm, ACX1xx_IE_MEMORY_MAP);
693 offset = le32_to_cpu(mm.CodeEnd);
695 sprintf(filename, "tiacx1%02dr%02X",
696 IS_ACX111(priv)*11,
697 priv->radio_type);
698 radio_image = acx_s_read_fw(&priv->pdev->dev, filename, &size);
699 if (!radio_image) {
700 printk("acx: can't load radio module '%s'\n", filename);
701 goto fail;
704 acx_s_issue_cmd(priv, ACX1xx_CMD_SLEEP, NULL, 0);
706 for (try = 1; try <= 5; try++) {
707 res = acxpci_s_write_fw(priv, radio_image, offset);
708 acxlog(L_DEBUG|L_INIT, "acx_write_fw (radio): %d\n", res);
709 if (OK == res) {
710 res = acxpci_s_validate_fw(priv, radio_image, offset);
711 acxlog(L_DEBUG|L_INIT, "acx_validate_fw (radio): %d\n", res);
714 if (OK == res)
715 break;
716 printk("acx: radio firmware upload attempt #%d FAILED, "
717 "retrying...\n", try);
718 acx_s_msleep(1000); /* better wait for a while... */
721 acx_s_issue_cmd(priv, ACX1xx_CMD_WAKE, NULL, 0);
722 radioinit.offset = cpu_to_le32(offset);
723 /* no endian conversion needed, remains in card CPU area: */
724 radioinit.len = radio_image->size;
726 vfree(radio_image);
728 if (OK != res)
729 goto fail;
731 /* will take a moment so let's have a big timeout */
732 acx_s_issue_cmd_timeo(priv, ACX1xx_CMD_RADIOINIT,
733 &radioinit, sizeof(radioinit), CMD_TIMEOUT_MS(1000));
735 res = acx_s_interrogate(priv, &mm, ACX1xx_IE_MEMORY_MAP);
736 fail:
737 FN_EXIT1(res);
738 return res;
742 /***********************************************************************
743 ** acxpci_l_reset_mac
745 ** Arguments:
746 ** wlandevice: private device that contains card device
747 ** Side effects:
748 ** MAC will be reset
749 ** Call context:
750 ** acx_reset_dev
751 ** Comment:
752 ** resets onboard acx MAC
754 static void
755 acxpci_l_reset_mac(wlandevice_t *priv)
757 u16 temp;
759 FN_ENTER;
761 /* halt eCPU */
762 temp = read_reg16(priv, IO_ACX_ECPU_CTRL) | 0x1;
763 write_reg16(priv, IO_ACX_ECPU_CTRL, temp);
765 /* now do soft reset of eCPU */
766 temp = read_reg16(priv, IO_ACX_SOFT_RESET) | 0x1;
767 acxlog(L_DEBUG, "%s: enable soft reset...\n", __func__);
768 write_reg16(priv, IO_ACX_SOFT_RESET, temp);
769 write_flush(priv);
771 /* now reset bit again */
772 acxlog(L_DEBUG, "%s: disable soft reset and go to init mode...\n", __func__);
773 /* deassert eCPU reset */
774 write_reg16(priv, IO_ACX_SOFT_RESET, temp & ~0x1);
776 /* now start a burst read from initial flash EEPROM */
777 temp = read_reg16(priv, IO_ACX_EE_START) | 0x1;
778 write_reg16(priv, IO_ACX_EE_START, temp);
779 write_flush(priv);
781 FN_EXIT0;
785 /***********************************************************************
786 ** acxpci_s_verify_init
788 static int
789 acxpci_s_verify_init(wlandevice_t *priv)
791 int result = NOT_OK;
792 int timer;
794 FN_ENTER;
796 for (timer = 40; timer > 0; timer--) {
797 u16 irqstat = read_reg16(priv, IO_ACX_IRQ_STATUS_NON_DES);
798 if (irqstat & HOST_INT_FCS_THRESHOLD) {
799 result = OK;
800 write_reg16(priv, IO_ACX_IRQ_ACK, HOST_INT_FCS_THRESHOLD);
801 break;
803 /* Init may take up to ~0.5 sec total */
804 acx_s_msleep(50);
807 FN_EXIT1(result);
808 return result;
812 /***********************************************************************
813 ** A few low-level helpers
815 ** Note: these functions are not protected by lock
816 ** and thus are never allowed to be called from IRQ.
817 ** Also they must not race with fw upload which uses same hw regs
820 /***********************************************************************
821 ** acxpci_write_cmd_type_or_status
823 static void
824 acxpci_write_cmd_type_or_status(wlandevice_t *priv, u32 val)
826 write_reg32(priv, IO_ACX_SLV_END_CTL, 0x0);
827 write_reg32(priv, IO_ACX_SLV_MEM_CTL, 0x1); /* FIXME: why auto increment?? */
829 write_reg32(priv, IO_ACX_SLV_MEM_ADDR,
830 read_reg32(priv, IO_ACX_CMD_MAILBOX_OFFS));
832 /* make sure we only write the data once all config registers are written */
833 write_flush(priv);
834 write_reg32(priv, IO_ACX_SLV_MEM_DATA, val);
835 write_flush(priv);
837 static inline void
838 acxpci_write_cmd_type(wlandevice_t *priv, u32 val)
840 acxpci_write_cmd_type_or_status(priv, val);
842 static inline void
843 acxpci_write_cmd_status(wlandevice_t *priv, u32 val)
845 acxpci_write_cmd_type_or_status(priv, val<<16);
849 /***********************************************************************
850 ** acxpci_read_cmd_status
852 static void
853 acxpci_read_cmd_status(wlandevice_t *priv)
855 u32 value;
857 write_reg32(priv, IO_ACX_SLV_END_CTL, 0x0);
858 write_reg32(priv, IO_ACX_SLV_MEM_CTL, 0x1); /* FIXME: why auto increment?? */
860 write_reg32(priv, IO_ACX_SLV_MEM_ADDR,
861 read_reg32(priv, IO_ACX_CMD_MAILBOX_OFFS));
863 /* make sure we only read the data once all config registers are written */
864 write_flush(priv);
865 value = read_reg32(priv, IO_ACX_SLV_MEM_DATA);
867 priv->cmd_type = (u16)value;
868 priv->cmd_status = (value >> 16);
870 acxlog(L_CTL, "cmd_type 0x%04X, cmd_status 0x%04X [%s]\n",
871 priv->cmd_type, priv->cmd_status,
872 acx_cmd_status_str(priv->cmd_status));
876 /***********************************************************************
877 ** acxpci_s_reset_dev
879 ** Arguments:
880 ** netdevice that contains the wlandevice priv variable
881 ** Returns:
882 ** NOT_OK on fail
883 ** OK on success
884 ** Side effects:
885 ** device is hard reset
886 ** Call context:
887 ** acxpci_e_probe
888 ** Comment:
889 ** This resets the device using low level hardware calls
890 ** as well as uploads and verifies the firmware to the card
892 static int
893 acxpci_s_reset_dev(netdevice_t *dev)
895 wlandevice_t *priv = netdev_priv(dev);
896 const char* msg = "";
897 unsigned long flags;
898 int result = NOT_OK;
899 u16 hardware_info;
900 u16 ecpu_ctrl;
902 FN_ENTER;
904 /* we're doing a reset, so hardware is unavailable */
906 /* reset the device to make sure the eCPU is stopped
907 * to upload the firmware correctly */
909 acx_lock(priv, flags);
911 acxpci_l_reset_mac(priv);
913 ecpu_ctrl = read_reg16(priv, IO_ACX_ECPU_CTRL) & 1;
914 if (!ecpu_ctrl) {
915 msg = "eCPU is already running. ";
916 goto fail_unlock;
919 #ifdef WE_DONT_NEED_THAT_DO_WE
920 if (read_reg16(priv, IO_ACX_SOR_CFG) & 2) {
921 /* eCPU most likely means "embedded CPU" */
922 msg = "eCPU did not start after boot from flash. ";
923 goto fail_unlock;
926 /* check sense on reset flags */
927 if (read_reg16(priv, IO_ACX_SOR_CFG) & 0x10) {
928 printk("%s: eCPU did not start after boot (SOR), "
929 "is this fatal?\n", dev->name);
931 #endif
932 /* scan, if any, is stopped now, setting corresponding IRQ bit */
933 priv->irq_status |= HOST_INT_SCAN_COMPLETE;
935 acx_unlock(priv, flags);
937 /* without this delay acx100 may fail to report hardware_info
938 ** (see below). Most probably eCPU runs some init code */
939 acx_s_msleep(10);
941 /* Need to know radio type before fw load */
942 hardware_info = read_reg16(priv, IO_ACX_EEPROM_INFORMATION);
943 priv->form_factor = hardware_info & 0xff;
944 priv->radio_type = hardware_info >> 8;
946 /* load the firmware */
947 if (OK != acxpci_s_upload_fw(priv))
948 goto fail;
950 acx_s_msleep(10);
952 /* now start eCPU by clearing bit */
953 acxlog(L_DEBUG, "booted eCPU up and waiting for completion...\n");
954 write_reg16(priv, IO_ACX_ECPU_CTRL, ecpu_ctrl & ~0x1);
956 /* wait for eCPU bootup */
957 if (OK != acxpci_s_verify_init(priv)) {
958 msg = "timeout waiting for eCPU. ";
959 goto fail;
962 acxlog(L_DEBUG, "eCPU has woken up, card is ready to be configured\n");
964 if (IS_ACX111(priv)) {
965 acxlog(L_DEBUG, "cleaning up cmd mailbox access area\n");
966 acxpci_write_cmd_status(priv, 0);
967 acxpci_read_cmd_status(priv);
968 if (priv->cmd_status) {
969 msg = "error cleaning cmd mailbox area. ";
970 goto fail;
974 /* Test that EEPROM is readable */
975 if ((OK != acxpci_read_eeprom_area(priv)) && IS_ACX100(priv)) {
976 /* does "CIS" mean "Card Information Structure"?
977 * If so, then this would be a PCMCIA message...
979 msg = "CIS error. ";
980 goto fail;
983 result = OK;
984 FN_EXIT1(result);
985 return result;
987 /* Finish error message. Indicate which function failed */
988 fail_unlock:
989 acx_unlock(priv, flags);
990 fail:
991 printk("acx: %sreset_dev() FAILED\n", msg);
992 FN_EXIT1(result);
993 return result;
997 /***********************************************************************
998 ** acxpci_init_mboxes
1000 void
1001 acxpci_init_mboxes(wlandevice_t *priv)
1003 u32 cmd_offs, info_offs;
1005 FN_ENTER;
1007 cmd_offs = read_reg32(priv, IO_ACX_CMD_MAILBOX_OFFS);
1008 info_offs = read_reg32(priv, IO_ACX_INFO_MAILBOX_OFFS);
1009 priv->cmd_area = (u8 *)priv->iobase2 + cmd_offs + 0x4;
1010 priv->info_area = (u8 *)priv->iobase2 + info_offs + 0x4;
1011 acxlog(L_DEBUG, "iobase2=%p\n"
1012 "cmd_mbox_offset=%X cmd_area=%p\n"
1013 "info_mbox_offset=%X info_area=%p\n",
1014 priv->iobase2,
1015 cmd_offs, priv->cmd_area,
1016 info_offs, priv->info_area);
1018 FN_EXIT0;
1022 /***********************************************************************
1023 ** acxpci_s_issue_cmd_timeo
1025 ** Sends command to fw, extract result
1027 ** NB: we do _not_ take lock inside, so be sure to not touch anything
1028 ** which may interfere with IRQ handler operation
1030 ** TODO: busy wait is a bit silly, so:
1031 ** 1) stop doing many iters - go to sleep after first
1032 ** 2) go to waitqueue based approach: wait, not poll!
1034 #undef FUNC
1035 #define FUNC "issue_cmd"
1037 #if !ACX_DEBUG
1039 acxpci_s_issue_cmd_timeo(
1040 wlandevice_t *priv,
1041 unsigned int cmd,
1042 void *buffer,
1043 unsigned buflen,
1044 unsigned timeout)
1046 #else
1048 acxpci_s_issue_cmd_timeo_debug(
1049 wlandevice_t *priv,
1050 unsigned cmd,
1051 void *buffer,
1052 unsigned buflen,
1053 unsigned timeout,
1054 const char* cmdstr)
1056 unsigned long start = jiffies;
1057 #endif
1058 const char *devname;
1059 unsigned counter;
1060 u16 irqtype;
1061 u16 cmd_status;
1063 FN_ENTER;
1065 devname = priv->netdev->name;
1066 if (!devname || !devname[0])
1067 devname = "acx";
1069 acxlog(L_CTL, FUNC"(cmd:%s,buflen:%u,timeout:%ums,type:0x%04X)\n",
1070 cmdstr, buflen, timeout,
1071 buffer ? le16_to_cpu(((acx_ie_generic_t *)buffer)->type) : -1);
1073 if (!(priv->dev_state_mask & ACX_STATE_FW_LOADED)) {
1074 printk("%s: "FUNC"(): firmware is not loaded yet, "
1075 "cannot execute commands!\n", devname);
1076 goto bad;
1079 if ((acx_debug & L_DEBUG) && (cmd != ACX1xx_CMD_INTERROGATE)) {
1080 printk("input pdr (len=%u):\n", buflen);
1081 acx_dump_bytes(buffer, buflen);
1084 /* wait for firmware to become idle for our command submission */
1085 counter = 199; /* in ms */
1086 do {
1087 acxpci_read_cmd_status(priv);
1088 /* Test for IDLE state */
1089 if (!priv->cmd_status)
1090 break;
1091 if (counter % 10 == 0) {
1092 /* we waited 10 iterations, no luck. Sleep 10 ms */
1093 acx_s_msleep(10);
1095 } while (--counter);
1097 if (!counter) {
1098 /* the card doesn't get idle, we're in trouble */
1099 printk("%s: "FUNC"(): cmd_status is not IDLE: 0x%04X!=0\n",
1100 devname, priv->cmd_status);
1101 goto bad;
1102 } else if (counter < 190) { /* if waited >10ms... */
1103 acxlog(L_CTL|L_DEBUG, FUNC"(): waited for IDLE %dms. "
1104 "Please report\n", 199 - counter);
1107 /* now write the parameters of the command if needed */
1108 if (buffer && buflen) {
1109 /* if it's an INTERROGATE command, just pass the length
1110 * of parameters to read, as data */
1111 #if CMD_DISCOVERY
1112 if (cmd == ACX1xx_CMD_INTERROGATE)
1113 memset(priv->cmd_area, 0xAA, buflen);
1114 #endif
1115 memcpy(priv->cmd_area, buffer,
1116 (cmd == ACX1xx_CMD_INTERROGATE) ? 4 : buflen);
1118 /* now write the actual command type */
1119 priv->cmd_type = cmd;
1120 acxpci_write_cmd_type(priv, cmd);
1121 /* execute command */
1122 write_reg16(priv, IO_ACX_INT_TRIG, INT_TRIG_CMD);
1123 write_flush(priv);
1125 /* wait for firmware to process command */
1127 /* Ensure nonzero and not too large timeout.
1128 ** Also converts e.g. 100->99, 200->199
1129 ** which is nice but not essential */
1130 timeout = (timeout-1) | 1;
1131 if (unlikely(timeout > 1199))
1132 timeout = 1199;
1133 /* clear CMD_COMPLETE bit. can be set only by IRQ handler: */
1134 priv->irq_status &= ~HOST_INT_CMD_COMPLETE;
1136 /* we schedule away sometimes (timeout can be large) */
1137 counter = timeout;
1138 do {
1139 if (!priv->irqs_active) { /* IRQ disabled: poll */
1140 irqtype = read_reg16(priv, IO_ACX_IRQ_STATUS_NON_DES);
1141 if (irqtype & HOST_INT_CMD_COMPLETE) {
1142 write_reg16(priv, IO_ACX_IRQ_ACK,
1143 HOST_INT_CMD_COMPLETE);
1144 break;
1146 } else { /* Wait when IRQ will set the bit */
1147 irqtype = priv->irq_status;
1148 if (irqtype & HOST_INT_CMD_COMPLETE)
1149 break;
1152 if (counter % 10 == 0) {
1153 /* we waited 10 iterations, no luck. Sleep 10 ms */
1154 acx_s_msleep(10);
1156 } while (--counter);
1158 /* save state for debugging */
1159 acxpci_read_cmd_status(priv);
1160 cmd_status = priv->cmd_status;
1162 /* put the card in IDLE state */
1163 priv->cmd_status = 0;
1164 acxpci_write_cmd_status(priv, 0);
1166 if (!counter) { /* timed out! */
1167 printk("%s: "FUNC"(): timed out %s for CMD_COMPLETE. "
1168 "irq bits:0x%04X irq_status:0x%04X timeout:%dms "
1169 "cmd_status:%d (%s)\n",
1170 devname, (priv->irqs_active) ? "waiting" : "polling",
1171 irqtype, priv->irq_status, timeout,
1172 cmd_status, acx_cmd_status_str(cmd_status));
1173 goto bad;
1174 } else if (timeout - counter > 30) { /* if waited >30ms... */
1175 acxlog(L_CTL|L_DEBUG, FUNC"(): %s for CMD_COMPLETE %dms. "
1176 "count:%d. Please report\n",
1177 (priv->irqs_active) ? "waited" : "polled",
1178 timeout - counter, counter);
1181 if (1 != cmd_status) { /* it is not a 'Success' */
1182 printk("%s: "FUNC"(): cmd_status is not SUCCESS: %d (%s). "
1183 "Took %dms of %d\n",
1184 devname, cmd_status, acx_cmd_status_str(cmd_status),
1185 timeout - counter, timeout);
1186 /* zero out result buffer */
1187 if (buffer && buflen)
1188 memset(buffer, 0, buflen);
1189 goto bad;
1192 /* read in result parameters if needed */
1193 if (buffer && buflen && (cmd == ACX1xx_CMD_INTERROGATE)) {
1194 memcpy(buffer, priv->cmd_area, buflen);
1195 if (acx_debug & L_DEBUG) {
1196 printk("output buffer (len=%u): ", buflen);
1197 acx_dump_bytes(buffer, buflen);
1200 /* ok: */
1201 acxlog(L_CTL, FUNC"(%s): took %ld jiffies to complete\n",
1202 cmdstr, jiffies - start);
1203 FN_EXIT1(OK);
1204 return OK;
1206 bad:
1207 /* Give enough info so that callers can avoid
1208 ** printing their own diagnostic messages */
1209 #if ACX_DEBUG
1210 printk("%s: "FUNC"(cmd:%s) FAILED\n", devname, cmdstr);
1211 #else
1212 printk("%s: "FUNC"(cmd:0x%04X) FAILED\n", devname, cmd);
1213 #endif
1214 dump_stack();
1215 FN_EXIT1(NOT_OK);
1216 return NOT_OK;
1220 /***********************************************************************
1221 ** acx_s_get_firmware_version
1223 ** TODO: not pci-specific, move to common.c and use from usb.c too
1225 static void
1226 acx_s_get_firmware_version(wlandevice_t *priv)
1228 fw_ver_t fw;
1229 u8 hexarr[4] = { 0, 0, 0, 0 };
1230 int hexidx = 0, val = 0;
1231 const char *num;
1232 char c;
1234 FN_ENTER;
1236 memset(fw.fw_id, 'E', FW_ID_SIZE);
1237 acx_s_interrogate(priv, &fw, ACX1xx_IE_FWREV);
1238 memcpy(priv->firmware_version, fw.fw_id, FW_ID_SIZE);
1239 priv->firmware_version[FW_ID_SIZE] = '\0';
1241 acxlog(L_DEBUG, "fw_ver: fw_id='%s' hw_id=%08X\n",
1242 priv->firmware_version, fw.hw_id);
1244 if (strncmp(fw.fw_id, "Rev ", 4) != 0) {
1245 printk("acx: strange firmware version string "
1246 "'%s', please report\n", priv->firmware_version);
1247 priv->firmware_numver = 0x01090407; /* assume 1.9.4.7 */
1248 } else {
1249 num = &fw.fw_id[4];
1250 while (1) {
1251 c = *num++;
1252 if ((c == '.') || (c == '\0')) {
1253 hexarr[hexidx++] = val;
1254 if ((hexidx > 3) || (c == '\0')) /* end? */
1255 break;
1256 val = 0;
1257 continue;
1259 if ((c >= '0') && (c <= '9'))
1260 c -= '0';
1261 else
1262 c = c - 'a' + (char)10;
1263 val = val*16 + c;
1266 priv->firmware_numver = (u32)(
1267 (hexarr[0] << 24) + (hexarr[1] << 16)
1268 + (hexarr[2] << 8) + hexarr[3]);
1269 acxlog(L_DEBUG, "firmware_numver 0x%08X\n", priv->firmware_numver);
1271 if (IS_ACX111(priv)) {
1272 if (priv->firmware_numver == 0x00010011) {
1273 /* This one does not survive floodpinging */
1274 printk("acx: firmware '%s' is known to be buggy, "
1275 "please upgrade\n", priv->firmware_version);
1277 if (priv->firmware_numver == 0x02030131) {
1278 /* With this one, all rx packets look mangled
1279 ** Most probably we simply do not know how to use it
1280 ** properly */
1281 printk("acx: firmware '%s' does not work well "
1282 "with this driver\n", priv->firmware_version);
1286 priv->firmware_id = le32_to_cpu(fw.hw_id);
1288 /* we're able to find out more detailed chip names now */
1289 switch (priv->firmware_id & 0xffff0000) {
1290 case 0x01010000:
1291 case 0x01020000:
1292 priv->chip_name = "TNETW1100A";
1293 break;
1294 case 0x01030000:
1295 priv->chip_name = "TNETW1100B";
1296 break;
1297 case 0x03000000:
1298 case 0x03010000:
1299 priv->chip_name = "TNETW1130";
1300 break;
1301 default:
1302 printk("acx: unknown chip ID 0x%08X, "
1303 "please report\n", priv->firmware_id);
1304 break;
1307 FN_EXIT0;
1311 /***********************************************************************
1312 ** acx_display_hardware_details
1314 ** Displays hw/fw version, radio type etc...
1316 ** TODO: not pci-specific, move to common.c and use from usb.c too
1318 static void
1319 acx_display_hardware_details(wlandevice_t *priv)
1321 const char *radio_str, *form_str;
1323 FN_ENTER;
1325 switch (priv->radio_type) {
1326 case RADIO_MAXIM_0D:
1327 /* hmm, the DWL-650+ seems to have two variants,
1328 * according to a windows driver changelog comment:
1329 * RFMD and Maxim. */
1330 radio_str = "Maxim";
1331 break;
1332 case RADIO_RFMD_11:
1333 radio_str = "RFMD";
1334 break;
1335 case RADIO_RALINK_15:
1336 radio_str = "Ralink";
1337 break;
1338 case RADIO_RADIA_16:
1339 radio_str = "Radia";
1340 break;
1341 case RADIO_UNKNOWN_17:
1342 /* TI seems to have a radio which is
1343 * additionally 802.11a capable, too */
1344 radio_str = "802.11a/b/g radio?! Please report";
1345 break;
1346 case RADIO_UNKNOWN_19:
1347 radio_str = "A radio used by Safecom cards?! Please report";
1348 break;
1349 default:
1350 radio_str = "UNKNOWN, please report the radio type name!";
1351 break;
1354 switch (priv->form_factor) {
1355 case 0x00:
1356 form_str = "unspecified";
1357 break;
1358 case 0x01:
1359 form_str = "(mini-)PCI / CardBus";
1360 break;
1361 case 0x02:
1362 form_str = "USB";
1363 break;
1364 case 0x03:
1365 form_str = "Compact Flash";
1366 break;
1367 default:
1368 form_str = "UNKNOWN, Please report";
1369 break;
1372 printk("acx: form factor 0x%02X (%s), "
1373 "radio type 0x%02X (%s), EEPROM version 0x%02X, "
1374 "uploaded firmware '%s' (0x%08X)\n",
1375 priv->form_factor, form_str, priv->radio_type, radio_str,
1376 priv->eeprom_version, priv->firmware_version,
1377 priv->firmware_id);
1379 FN_EXIT0;
1382 /***********************************************************************
1384 #ifdef NONESSENTIAL_FEATURES
1385 typedef struct device_id {
1386 unsigned char id[6];
1387 char *descr;
1388 char *type;
1389 } device_id_t;
1391 static const device_id_t
1392 device_ids[] =
1395 {'G', 'l', 'o', 'b', 'a', 'l'},
1396 NULL,
1397 NULL,
1400 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
1401 "uninitialized",
1402 "SpeedStream SS1021 or Gigafast WF721-AEX"
1405 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85},
1406 "non-standard",
1407 "DrayTek Vigor 520"
1410 {'?', '?', '?', '?', '?', '?'},
1411 "non-standard",
1412 "Level One WPC-0200"
1415 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1416 "empty",
1417 "DWL-650+ variant"
1421 static void
1422 acx_show_card_eeprom_id(wlandevice_t *priv)
1424 unsigned char buffer[CARD_EEPROM_ID_SIZE];
1425 int i;
1427 memset(&buffer, 0, CARD_EEPROM_ID_SIZE);
1428 /* use direct EEPROM access */
1429 for (i = 0; i < CARD_EEPROM_ID_SIZE; i++) {
1430 if (OK != acxpci_read_eeprom_byte(priv,
1431 ACX100_EEPROM_ID_OFFSET + i,
1432 &buffer[i]))
1434 printk("acx: reading EEPROM FAILED\n");
1435 break;
1439 for (i = 0; i < VEC_SIZE(device_ids); i++) {
1440 if (!memcmp(&buffer, device_ids[i].id, CARD_EEPROM_ID_SIZE)) {
1441 if (device_ids[i].descr) {
1442 printk("acx: EEPROM card ID string check "
1443 "found %s card ID: is this %s?\n",
1444 device_ids[i].descr, device_ids[i].type);
1446 break;
1449 if (i == VEC_SIZE(device_ids)) {
1450 printk("acx: EEPROM card ID string check found "
1451 "unknown card: expected 'Global', got '%.*s\'. "
1452 "Please report\n", CARD_EEPROM_ID_SIZE, buffer);
1455 #endif /* NONESSENTIAL_FEATURES */
1458 /***********************************************************************
1460 static void
1461 acxpci_s_device_chain_add(struct net_device *dev)
1463 wlandevice_t *priv = netdev_priv(dev);
1465 down(&root_acx_dev_sem);
1466 priv->prev_nd = root_acx_dev.newest;
1467 root_acx_dev.newest = dev;
1468 priv->netdev = dev;
1469 up(&root_acx_dev_sem);
1472 static void
1473 acxpci_s_device_chain_remove(struct net_device *dev)
1475 struct net_device *querydev;
1476 struct net_device *olderdev;
1477 struct net_device *newerdev;
1479 down(&root_acx_dev_sem);
1480 querydev = root_acx_dev.newest;
1481 newerdev = NULL;
1482 while (querydev) {
1483 olderdev = ((wlandevice_t*)netdev_priv(querydev))->prev_nd;
1484 if (0 == strcmp(querydev->name, dev->name)) {
1485 if (!newerdev) {
1486 /* if we were at the beginning of the
1487 * list, then it's the list head that
1488 * we need to update to point at the
1489 * next older device */
1490 root_acx_dev.newest = olderdev;
1491 } else {
1492 /* it's the device that is newer than us
1493 * that we need to update to point at
1494 * the device older than us */
1495 ((wlandevice_t*)netdev_priv(newerdev))->
1496 prev_nd = olderdev;
1498 break;
1500 /* "newerdev" is actually the device of the old iteration,
1501 * but since the list starts (root_acx_dev.newest)
1502 * with the newest devices,
1503 * it's newer than the ones following.
1504 * Oh the joys of iterating from newest to oldest :-\ */
1505 newerdev = querydev;
1507 /* keep checking old devices for matches until we hit the end
1508 * of the list */
1509 querydev = olderdev;
1511 up(&root_acx_dev_sem);
1515 /***********************************************************************
1516 ** acxpci_free_desc_queues
1518 ** Releases the queues that have been allocated, the
1519 ** others have been initialised to NULL so this
1520 ** function can be used if only part of the queues were allocated.
1523 static inline void
1524 free_coherent(struct pci_dev *hwdev, size_t size,
1525 void *vaddr, dma_addr_t dma_handle)
1527 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 53)
1528 dma_free_coherent(hwdev == NULL ? NULL : &hwdev->dev,
1529 size, vaddr, dma_handle);
1530 #else
1531 pci_free_consistent(hwdev, size, vaddr, dma_handle);
1532 #endif
1535 void
1536 acxpci_free_desc_queues(wlandevice_t *priv)
1538 #define ACX_FREE_QUEUE(size, ptr, phyaddr) \
1539 if (ptr) { \
1540 free_coherent(0, size, ptr, phyaddr); \
1541 ptr = NULL; \
1542 size = 0; \
1545 FN_ENTER;
1547 ACX_FREE_QUEUE(priv->txhostdesc_area_size, priv->txhostdesc_start, priv->txhostdesc_startphy);
1548 ACX_FREE_QUEUE(priv->txbuf_area_size, priv->txbuf_start, priv->txbuf_startphy);
1550 priv->txdesc_start = NULL;
1552 ACX_FREE_QUEUE(priv->rxhostdesc_area_size, priv->rxhostdesc_start, priv->rxhostdesc_startphy);
1553 ACX_FREE_QUEUE(priv->rxbuf_area_size, priv->rxbuf_start, priv->rxbuf_startphy);
1555 priv->rxdesc_start = NULL;
1557 FN_EXIT0;
1561 /***********************************************************************
1562 ** acxpci_s_delete_dma_regions
1564 static void
1565 acxpci_s_delete_dma_regions(wlandevice_t *priv)
1567 unsigned long flags;
1569 FN_ENTER;
1570 /* disable radio Tx/Rx. Shouldn't we use the firmware commands
1571 * here instead? Or are we that much down the road that it's no
1572 * longer possible here? */
1573 write_reg16(priv, IO_ACX_ENABLE, 0);
1575 acx_s_msleep(100);
1577 acx_lock(priv, flags);
1578 acxpci_free_desc_queues(priv);
1579 acx_unlock(priv, flags);
1581 FN_EXIT0;
1585 /***********************************************************************
1586 ** acxpci_e_probe
1588 ** Probe routine called when a PCI device w/ matching ID is found.
1589 ** Here's the sequence:
1590 ** - Allocate the PCI resources.
1591 ** - Read the PCMCIA attribute memory to make sure we have a WLAN card
1592 ** - Reset the MAC
1593 ** - Initialize the dev and wlan data
1594 ** - Initialize the MAC
1596 ** pdev - ptr to pci device structure containing info about pci configuration
1597 ** id - ptr to the device id entry that matched this device
1599 static const u16
1600 IO_ACX100[] =
1602 0x0000, /* IO_ACX_SOFT_RESET */
1604 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1605 0x0018, /* IO_ACX_SLV_MEM_DATA */
1606 0x001c, /* IO_ACX_SLV_MEM_CTL */
1607 0x0020, /* IO_ACX_SLV_END_CTL */
1609 0x0034, /* IO_ACX_FEMR */
1611 0x007c, /* IO_ACX_INT_TRIG */
1612 0x0098, /* IO_ACX_IRQ_MASK */
1613 0x00a4, /* IO_ACX_IRQ_STATUS_NON_DES */
1614 0x00a8, /* IO_ACX_IRQ_STATUS_CLEAR */
1615 0x00ac, /* IO_ACX_IRQ_ACK */
1616 0x00b0, /* IO_ACX_HINT_TRIG */
1618 0x0104, /* IO_ACX_ENABLE */
1620 0x0250, /* IO_ACX_EEPROM_CTL */
1621 0x0254, /* IO_ACX_EEPROM_ADDR */
1622 0x0258, /* IO_ACX_EEPROM_DATA */
1623 0x025c, /* IO_ACX_EEPROM_CFG */
1625 0x0268, /* IO_ACX_PHY_ADDR */
1626 0x026c, /* IO_ACX_PHY_DATA */
1627 0x0270, /* IO_ACX_PHY_CTL */
1629 0x0290, /* IO_ACX_GPIO_OE */
1631 0x0298, /* IO_ACX_GPIO_OUT */
1633 0x02a4, /* IO_ACX_CMD_MAILBOX_OFFS */
1634 0x02a8, /* IO_ACX_INFO_MAILBOX_OFFS */
1635 0x02ac, /* IO_ACX_EEPROM_INFORMATION */
1637 0x02d0, /* IO_ACX_EE_START */
1638 0x02d4, /* IO_ACX_SOR_CFG */
1639 0x02d8 /* IO_ACX_ECPU_CTRL */
1642 static const u16
1643 IO_ACX111[] =
1645 0x0000, /* IO_ACX_SOFT_RESET */
1647 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1648 0x0018, /* IO_ACX_SLV_MEM_DATA */
1649 0x001c, /* IO_ACX_SLV_MEM_CTL */
1650 0x0020, /* IO_ACX_SLV_END_CTL */
1652 0x0034, /* IO_ACX_FEMR */
1654 0x00b4, /* IO_ACX_INT_TRIG */
1655 0x00d4, /* IO_ACX_IRQ_MASK */
1656 /* we need NON_DES (0xf0), not NON_DES_MASK which is at 0xe0: */
1657 0x00f0, /* IO_ACX_IRQ_STATUS_NON_DES */
1658 0x00e4, /* IO_ACX_IRQ_STATUS_CLEAR */
1659 0x00e8, /* IO_ACX_IRQ_ACK */
1660 0x00ec, /* IO_ACX_HINT_TRIG */
1662 0x01d0, /* IO_ACX_ENABLE */
1664 0x0338, /* IO_ACX_EEPROM_CTL */
1665 0x033c, /* IO_ACX_EEPROM_ADDR */
1666 0x0340, /* IO_ACX_EEPROM_DATA */
1667 0x0344, /* IO_ACX_EEPROM_CFG */
1669 0x0350, /* IO_ACX_PHY_ADDR */
1670 0x0354, /* IO_ACX_PHY_DATA */
1671 0x0358, /* IO_ACX_PHY_CTL */
1673 0x0374, /* IO_ACX_GPIO_OE */
1675 0x037c, /* IO_ACX_GPIO_OUT */
1677 0x0388, /* IO_ACX_CMD_MAILBOX_OFFS */
1678 0x038c, /* IO_ACX_INFO_MAILBOX_OFFS */
1679 0x0390, /* IO_ACX_EEPROM_INFORMATION */
1681 0x0100, /* IO_ACX_EE_START */
1682 0x0104, /* IO_ACX_SOR_CFG */
1683 0x0108, /* IO_ACX_ECPU_CTRL */
1686 static void
1687 dummy_netdev_init(struct net_device *dev) {}
1689 static int __devinit
1690 acxpci_e_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1692 unsigned long mem_region1 = 0;
1693 unsigned long mem_region2 = 0;
1694 unsigned long mem_region1_size;
1695 unsigned long mem_region2_size;
1696 unsigned long phymem1;
1697 unsigned long phymem2;
1698 void *mem1 = NULL;
1699 void *mem2 = NULL;
1700 wlandevice_t *priv = NULL;
1701 struct net_device *dev = NULL;
1702 const char *chip_name;
1703 int result = -EIO;
1704 int err;
1705 u8 chip_type;
1707 #if SEPARATE_DRIVER_INSTANCES
1708 struct pci_dev *tdev;
1709 unsigned int inited;
1710 static int turn = 0;
1711 #endif /* SEPARATE_DRIVER_INSTANCES */
1713 FN_ENTER;
1715 #if SEPARATE_DRIVER_INSTANCES
1716 if (card) {
1717 turn++;
1718 inited = 0;
1719 pci_for_each_dev(tdev) {
1720 if (tdev->vendor != PCI_VENDOR_ID_TI)
1721 continue;
1723 if (tdev == pdev)
1724 break;
1725 if (pci_get_drvdata(tdev))
1726 inited++;
1728 if (inited + turn != card) {
1729 result = -ENODEV;
1730 goto done;
1733 #endif /* SEPARATE_DRIVER_INSTANCES */
1735 /* Enable the PCI device */
1736 if (pci_enable_device(pdev)) {
1737 printk("acx: pci_enable_device() FAILED\n");
1738 result = -ENODEV;
1739 goto fail_pci_enable_device;
1742 /* enable busmastering (required for CardBus) */
1743 pci_set_master(pdev);
1745 /* chiptype is u8 but id->driver_data is ulong
1746 ** Works for now (possible values are 1 and 2) */
1747 chip_type = (u8)id->driver_data;
1748 /* acx100 and acx111 have different PCI memory regions */
1749 if (chip_type == CHIPTYPE_ACX100) {
1750 chip_name = "ACX100";
1751 mem_region1 = PCI_ACX100_REGION1;
1752 mem_region1_size = PCI_ACX100_REGION1_SIZE;
1754 mem_region2 = PCI_ACX100_REGION2;
1755 mem_region2_size = PCI_ACX100_REGION2_SIZE;
1756 } else if (chip_type == CHIPTYPE_ACX111) {
1757 chip_name = "ACX111";
1758 mem_region1 = PCI_ACX111_REGION1;
1759 mem_region1_size = PCI_ACX111_REGION1_SIZE;
1761 mem_region2 = PCI_ACX111_REGION2;
1762 mem_region2_size = PCI_ACX111_REGION2_SIZE;
1763 } else {
1764 printk("acx: unknown chip type 0x%04X\n", chip_type);
1765 goto fail_unknown_chiptype;
1768 /* Figure out our resources */
1769 phymem1 = pci_resource_start(pdev, mem_region1);
1770 phymem2 = pci_resource_start(pdev, mem_region2);
1772 if (!request_mem_region(phymem1, pci_resource_len(pdev, mem_region1), "ACX1xx_1")) {
1773 printk("acx: cannot reserve PCI memory region 1 (are you sure "
1774 "you have CardBus support in kernel?)\n");
1775 goto fail_request_mem_region1;
1778 if (!request_mem_region(phymem2, pci_resource_len(pdev, mem_region2), "ACX1xx_2")) {
1779 printk("acx: cannot reserve PCI memory region 2\n");
1780 goto fail_request_mem_region2;
1783 mem1 = ioremap(phymem1, mem_region1_size);
1784 if (NULL == mem1) {
1785 printk("acx: ioremap() FAILED\n");
1786 goto fail_ioremap1;
1789 mem2 = ioremap(phymem2, mem_region2_size);
1790 if (NULL == mem2) {
1791 printk("acx: ioremap() #2 FAILED\n");
1792 goto fail_ioremap2;
1795 /* Log the device */
1796 printk("acx: found %s-based wireless network card at %s, irq:%d, "
1797 "phymem1:0x%lX, phymem2:0x%lX, mem1:0x%p, mem1_size:%ld, "
1798 "mem2:0x%p, mem2_size:%ld\n",
1799 chip_name, pci_name(pdev), pdev->irq, phymem1, phymem2,
1800 mem1, mem_region1_size,
1801 mem2, mem_region2_size);
1802 acxlog(L_ANY, "initial debug setting is 0x%04X\n", acx_debug);
1804 if (0 == pdev->irq) {
1805 printk("acx: can't use IRQ 0\n");
1806 goto fail_irq;
1809 dev = alloc_netdev(sizeof(wlandevice_t), "wlan%d", dummy_netdev_init);
1810 /* (NB: memsets to 0 entire area) */
1811 if (!dev) {
1812 printk("acx: no memory for netdevice structure\n");
1813 goto fail_alloc_netdev;
1816 ether_setup(dev);
1817 dev->open = &acxpci_e_open;
1818 dev->stop = &acxpci_e_close;
1819 dev->hard_start_xmit = &acx_i_start_xmit;
1820 dev->get_stats = &acx_e_get_stats;
1821 dev->get_wireless_stats = &acx_e_get_wireless_stats;
1822 #if WIRELESS_EXT >= 13
1823 dev->wireless_handlers = (struct iw_handler_def *)&acx_ioctl_handler_def;
1824 #else
1825 dev->do_ioctl = &acx_e_ioctl_old;
1826 #endif
1827 dev->set_multicast_list = &acxpci_i_set_multicast_list;
1828 dev->tx_timeout = &acxpci_i_tx_timeout;
1829 dev->change_mtu = &acx_e_change_mtu;
1830 dev->watchdog_timeo = 4 * HZ;
1831 dev->irq = pdev->irq;
1832 dev->base_addr = pci_resource_start(pdev, 0);
1834 priv = netdev_priv(dev);
1835 spin_lock_init(&priv->lock); /* initial state: unlocked */
1836 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
1837 sema_init(&priv->sem, 1); /* initial state: 1 (upped) */
1838 /* since nobody can see new netdev yet, we can as well
1839 ** just _presume_ that we're under sem (instead of actually taking it): */
1840 /* acx_sem_lock(priv); */
1841 priv->pdev = pdev;
1842 priv->dev_type = DEVTYPE_PCI;
1843 priv->chip_type = chip_type;
1844 priv->chip_name = chip_name;
1845 priv->io = (CHIPTYPE_ACX100 == chip_type) ? IO_ACX100 : IO_ACX111;
1846 priv->membase = phymem1;
1847 priv->iobase = mem1;
1848 priv->membase2 = phymem2;
1849 priv->iobase2 = mem2;
1850 /* to find crashes due to weird driver access
1851 * to unconfigured interface (ifup) */
1852 priv->mgmt_timer.function = (void (*)(unsigned long))0x0000dead;
1854 #ifdef NONESSENTIAL_FEATURES
1855 acx_show_card_eeprom_id(priv);
1856 #endif /* NONESSENTIAL_FEATURES */
1858 /* now we have our device, so make sure the kernel doesn't try
1859 * to send packets even though we're not associated to a network yet */
1860 acx_stop_queue(dev, "after setup");
1862 #ifdef SET_MODULE_OWNER
1863 SET_MODULE_OWNER(dev);
1864 #endif
1865 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 70)
1866 /* this define and its netdev member exist since 2.5.70 */
1867 SET_NETDEV_DEV(dev, &pdev->dev);
1868 #endif
1870 /* register new dev in linked list */
1871 acxpci_s_device_chain_add(dev);
1873 acxlog(L_IRQ|L_INIT, "using IRQ %d\n", pdev->irq);
1875 /* need to be able to restore PCI state after a suspend */
1876 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
1877 /* 2.6.9-rc3-mm2 (2.6.9-bk4, too) introduced this shorter version,
1878 then it made its way into 2.6.10 */
1879 pci_save_state(pdev);
1880 #else
1881 pci_save_state(pdev, priv->pci_state);
1882 #endif
1884 /* NB: read_reg() reads may return bogus data before reset_dev().
1885 ** acx100 seems to be more affected than acx111 */
1886 if (OK != acxpci_s_reset_dev(dev)) {
1887 goto fail_reset;
1890 /* ok, basic setup is finished, now start initialising the card */
1892 if (OK != acxpci_read_eeprom_byte(priv, 0x05, &priv->eeprom_version)) {
1893 goto fail_read_eeprom_version;
1896 if (OK != acx_s_init_mac(dev)) {
1897 printk("acx: init_mac() FAILED\n");
1898 goto fail_init_mac;
1900 if (OK != acx_s_set_defaults(priv)) {
1901 printk("acx: set_defaults() FAILED\n");
1902 goto fail_set_defaults;
1905 /* needs to be after acx_s_init_mac() due to necessary init stuff */
1906 acx_s_get_firmware_version(priv);
1908 acx_display_hardware_details(priv);
1910 pci_set_drvdata(pdev, dev);
1912 /* ...and register the card, AFTER everything else has been set up,
1913 * since otherwise an ioctl could step on our feet due to
1914 * firmware operations happening in parallel or uninitialized data */
1915 err = register_netdev(dev);
1916 if (OK != err) {
1917 printk("acx: register_netdev() FAILED: %d\n", err);
1918 goto fail_register_netdev;
1921 acx_carrier_off(dev, "on probe");
1923 if (OK != acx_proc_register_entries(dev)) {
1924 goto fail_proc_register_entries;
1927 /* after register_netdev() userspace may start working with dev
1928 * (in particular, on other CPUs), we only need to up the sem */
1929 /* acx_sem_unlock(priv); */
1931 printk("acx "WLAN_RELEASE": net device %s, driver compiled "
1932 "against wireless extensions %d and Linux %s\n",
1933 dev->name, WIRELESS_EXT, UTS_RELEASE);
1935 #if CMD_DISCOVERY
1936 great_inquisitor(priv);
1937 #endif
1939 result = OK;
1940 goto done;
1942 /* error paths: undo everything in reverse order... */
1944 #ifdef CONFIG_PROC_FS
1945 fail_proc_register_entries:
1947 if (priv->dev_state_mask & ACX_STATE_IFACE_UP)
1948 acxpci_s_down(dev);
1950 unregister_netdev(dev);
1952 /* after unregister_netdev() userspace is guaranteed to finish
1953 * working with it. netdev does not exist anymore.
1954 * For paranoid reasons I am taking sem anyway */
1955 acx_sem_lock(priv);
1956 #endif
1958 fail_register_netdev:
1960 acxpci_s_delete_dma_regions(priv);
1961 pci_set_drvdata(pdev, NULL);
1963 fail_set_defaults:
1964 fail_init_mac:
1965 fail_read_eeprom_version:
1966 fail_reset:
1968 acxpci_s_device_chain_remove(dev);
1969 free_netdev(dev);
1970 fail_alloc_netdev:
1971 fail_irq:
1973 iounmap(mem2);
1974 fail_ioremap2:
1976 iounmap(mem1);
1977 fail_ioremap1:
1979 release_mem_region(pci_resource_start(pdev, mem_region2),
1980 pci_resource_len(pdev, mem_region2));
1981 fail_request_mem_region2:
1983 release_mem_region(pci_resource_start(pdev, mem_region1),
1984 pci_resource_len(pdev, mem_region1));
1985 fail_request_mem_region1:
1986 fail_unknown_chiptype:
1988 pci_disable_device(pdev);
1989 fail_pci_enable_device:
1991 pci_set_power_state(pdev, 3);
1993 done:
1994 FN_EXIT1(result);
1995 return result;
1999 /***********************************************************************
2000 ** acxpci_e_remove
2002 ** Deallocate PCI resources for the acx chip.
2004 ** This should NOT execute any other hardware operations on the card,
2005 ** since the card might already be ejected. Instead, that should be done
2006 ** in cleanup_module, since the card is most likely still available there.
2008 ** pdev - ptr to PCI device structure containing info about pci configuration
2010 static void __devexit
2011 acxpci_e_remove(struct pci_dev *pdev)
2013 struct net_device *dev;
2014 wlandevice_t *priv;
2015 unsigned long mem_region1, mem_region2;
2017 FN_ENTER;
2019 dev = (struct net_device *) pci_get_drvdata(pdev);
2020 if (!dev) {
2021 acxlog(L_DEBUG, "%s: card is unused. Skipping any release code\n",
2022 __func__);
2023 goto end;
2026 priv = netdev_priv(dev);
2028 /* unregister the device to not let the kernel
2029 * (e.g. ioctls) access a half-deconfigured device
2030 * NB: this will cause acxpci_e_close() to be called,
2031 * thus we shouldn't call it under sem! */
2032 acxlog(L_INIT, "removing device %s\n", dev->name);
2033 unregister_netdev(dev);
2035 /* unregister_netdev ensures that no references to us left.
2036 * For paranoid reasons we continue to follow the rules */
2037 acx_sem_lock(priv);
2039 if (IS_ACX100(priv)) {
2040 mem_region1 = PCI_ACX100_REGION1;
2041 mem_region2 = PCI_ACX100_REGION2;
2042 } else {
2043 mem_region1 = PCI_ACX111_REGION1;
2044 mem_region2 = PCI_ACX111_REGION2;
2047 acx_proc_unregister_entries(dev);
2049 /* find our PCI device in the global acx list and remove it */
2050 acxpci_s_device_chain_remove(dev);
2052 if (priv->dev_state_mask & ACX_STATE_IFACE_UP)
2053 acxpci_s_down(dev);
2055 CLEAR_BIT(priv->dev_state_mask, ACX_STATE_IFACE_UP);
2057 acxpci_s_delete_dma_regions(priv);
2059 /* finally, clean up PCI bus state */
2060 if (priv->iobase) iounmap(priv->iobase);
2061 if (priv->iobase2) iounmap(priv->iobase2);
2063 release_mem_region(pci_resource_start(pdev, mem_region1),
2064 pci_resource_len(pdev, mem_region1));
2066 release_mem_region(pci_resource_start(pdev, mem_region2),
2067 pci_resource_len(pdev, mem_region2));
2069 pci_disable_device(pdev);
2071 /* remove dev registration */
2072 pci_set_drvdata(pdev, NULL);
2074 /* Free netdev (quite late,
2075 * since otherwise we might get caught off-guard
2076 * by a netdev timeout handler execution
2077 * expecting to see a working dev...) */
2078 free_netdev(dev);
2080 /* put device into ACPI D3 mode (shutdown) */
2081 pci_set_power_state(pdev, 3);
2083 end:
2084 FN_EXIT0;
2088 /***********************************************************************
2089 ** TODO: PM code needs to be fixed / debugged / tested.
2091 #ifdef CONFIG_PM
2092 static int if_was_up = 0; /* FIXME: HACK, do it correctly sometime instead */
2093 static int
2094 acxpci_e_suspend(struct pci_dev *pdev, pm_message_t state)
2096 struct net_device *dev = pci_get_drvdata(pdev);
2097 wlandevice_t *priv = netdev_priv(dev);
2099 FN_ENTER;
2101 acx_sem_lock(priv);
2103 printk("acx: experimental suspend handler called for %p\n", priv);
2104 if (netif_device_present(dev)) {
2105 if_was_up = 1;
2106 acxpci_s_down(dev);
2108 else
2109 if_was_up = 0;
2111 netif_device_detach(dev); /* This one cannot sleep */
2112 acxpci_s_delete_dma_regions(priv);
2114 acx_sem_unlock(priv);
2116 FN_EXIT0;
2117 return OK;
2120 static int
2121 acxpci_e_resume(struct pci_dev *pdev)
2123 struct net_device *dev;
2124 wlandevice_t *priv;
2126 printk(KERN_WARNING "rsm: resume\n");
2127 dev = pci_get_drvdata(pdev);
2128 printk(KERN_WARNING "rsm: got dev\n");
2130 if (!netif_running(dev))
2131 return 0;
2133 priv = netdev_priv(dev);
2135 acx_sem_lock(priv);
2137 printk(KERN_WARNING "rsm: got priv\n");
2138 FN_ENTER;
2139 printk("acx: experimental resume handler called for %p!\n", priv);
2140 pci_set_power_state(pdev, 0);
2141 acxlog(L_DEBUG, "rsm: power state set\n");
2142 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
2143 /* 2.6.9-rc3-mm2 (2.6.9-bk4, too) introduced this shorter version,
2144 then it made its way into 2.6.10 */
2145 pci_restore_state(pdev);
2146 #else
2147 pci_restore_state(pdev, priv->pci_state);
2148 #endif
2149 acxlog(L_DEBUG, "rsm: PCI state restored\n");
2150 acxpci_s_reset_dev(dev);
2151 acxlog(L_DEBUG, "rsm: device reset done\n");
2153 if (OK != acx_s_init_mac(dev)) {
2154 printk("rsm: init_mac FAILED\n");
2155 goto fail;
2157 acxlog(L_DEBUG, "rsm: init MAC done\n");
2159 if (1 == if_was_up)
2160 acxpci_s_up(dev);
2161 acxlog(L_DEBUG, "rsm: acx up\n");
2163 /* now even reload all card parameters as they were before suspend,
2164 * and possibly be back in the network again already :-)
2165 * FIXME: should this be done in that scheduled task instead?? */
2166 if (ACX_STATE_IFACE_UP & priv->dev_state_mask)
2167 acx_s_update_card_settings(priv, 0, 1);
2168 acxlog(L_DEBUG, "rsm: settings updated\n");
2169 netif_device_attach(dev);
2170 acxlog(L_DEBUG, "rsm: device attached\n");
2171 fail: /* we need to return OK here anyway, right? */
2172 acx_sem_unlock(priv);
2173 FN_EXIT0;
2174 return OK;
2176 #endif /* CONFIG_PM */
2179 /***********************************************************************
2180 ** acxpci_s_up
2182 ** This function is called by acxpci_e_open (when ifconfig sets the device as up)
2184 ** Side effects:
2185 ** - Enables on-card interrupt requests
2186 ** - calls acx_s_start
2189 static void
2190 enable_acx_irq(wlandevice_t *priv)
2192 FN_ENTER;
2193 write_reg16(priv, IO_ACX_IRQ_MASK, priv->irq_mask);
2194 write_reg16(priv, IO_ACX_FEMR, 0x8000);
2195 priv->irqs_active = 1;
2196 FN_EXIT0;
2199 static void
2200 acxpci_s_up(netdevice_t *dev)
2202 wlandevice_t *priv = netdev_priv(dev);
2203 unsigned long flags;
2205 FN_ENTER;
2207 acx_lock(priv, flags);
2208 enable_acx_irq(priv);
2209 acx_unlock(priv, flags);
2211 /* acx fw < 1.9.3.e has a hardware timer, and older drivers
2212 ** used to use it. But we don't do that anymore, our OS
2213 ** has reliable software timers */
2214 init_timer(&priv->mgmt_timer);
2215 priv->mgmt_timer.function = acx_i_timer;
2216 priv->mgmt_timer.data = (unsigned long)priv;
2218 /* Need to set ACX_STATE_IFACE_UP first, or else
2219 ** timer won't be started by acx_set_status() */
2220 SET_BIT(priv->dev_state_mask, ACX_STATE_IFACE_UP);
2221 switch (priv->mode) {
2222 case ACX_MODE_0_ADHOC:
2223 case ACX_MODE_2_STA:
2224 /* actual scan cmd will happen in start() */
2225 acx_set_status(priv, ACX_STATUS_1_SCANNING); break;
2226 case ACX_MODE_3_AP:
2227 case ACX_MODE_MONITOR:
2228 acx_set_status(priv, ACX_STATUS_4_ASSOCIATED); break;
2231 acx_s_start(priv);
2233 FN_EXIT0;
2237 /***********************************************************************
2238 ** acxpci_s_down
2240 ** This disables the netdevice
2242 ** Side effects:
2243 ** - disables on-card interrupt request
2246 static void
2247 disable_acx_irq(wlandevice_t *priv)
2249 FN_ENTER;
2250 write_reg16(priv, IO_ACX_IRQ_MASK, priv->irq_mask_off);
2251 write_reg16(priv, IO_ACX_FEMR, 0x0);
2252 priv->irqs_active = 0;
2253 FN_EXIT0;
2256 static void
2257 acxpci_s_down(netdevice_t *dev)
2259 wlandevice_t *priv = netdev_priv(dev);
2260 unsigned long flags;
2262 FN_ENTER;
2264 /* Disable IRQs first, so that IRQs cannot race with us */
2265 acx_lock(priv, flags);
2266 disable_acx_irq(priv);
2267 acx_unlock(priv, flags);
2269 /* we really don't want to have an asynchronous tasklet disturb us
2270 ** after something vital for its job has been shut down, so
2271 ** end all remaining work now.
2273 ** NB: carrier_off (done by set_status below) would lead to
2274 ** not yet fully understood deadlock in FLUSH_SCHEDULED_WORK().
2275 ** That's why we do FLUSH first.
2277 ** NB2: we have a bad locking bug here: FLUSH_SCHEDULED_WORK()
2278 ** waits for acx_e_after_interrupt_task to complete if it is running
2279 ** on another CPU, but acx_e_after_interrupt_task
2280 ** will sleep on sem forever, because it is taken by us!
2281 ** Work around that by temporary sem unlock.
2282 ** This will fail miserably if we'll be hit by concurrent
2283 ** iwconfig or something in between. TODO! */
2284 acx_sem_unlock(priv);
2285 FLUSH_SCHEDULED_WORK();
2286 acx_sem_lock(priv);
2288 /* This is possible:
2289 ** FLUSH_SCHEDULED_WORK -> acx_e_after_interrupt_task ->
2290 ** -> set_status(ASSOCIATED) -> wake_queue()
2291 ** That's why we stop queue _after_ FLUSH_SCHEDULED_WORK
2292 ** lock/unlock is just paranoia, maybe not needed */
2293 acx_lock(priv, flags);
2294 acx_stop_queue(dev, "during close");
2295 acx_set_status(priv, ACX_STATUS_0_STOPPED);
2296 acx_unlock(priv, flags);
2298 /* kernel/timer.c says it's illegal to del_timer_sync()
2299 ** a timer which restarts itself. We guarantee this cannot
2300 ** ever happen because acx_i_timer() never does this if
2301 ** status is ACX_STATUS_0_STOPPED */
2302 del_timer_sync(&priv->mgmt_timer);
2304 FN_EXIT0;
2308 /***********************************************************************
2309 ** acxpci_e_open
2311 ** Called as a result of SIOCSIFFLAGS ioctl changing the flags bit IFF_UP
2312 ** from clear to set. In other words: ifconfig up.
2314 ** Returns:
2315 ** 0 success
2316 ** >0 f/w reported error
2317 ** <0 driver reported error
2319 static int
2320 acxpci_e_open(netdevice_t *dev)
2322 wlandevice_t *priv = netdev_priv(dev);
2323 int result = OK;
2325 FN_ENTER;
2327 acxlog(L_INIT, "module count++\n");
2328 WLAN_MOD_INC_USE_COUNT;
2330 acx_sem_lock(priv);
2332 acx_init_task_scheduler(priv);
2334 /* request shared IRQ handler */
2335 if (request_irq(dev->irq, acxpci_i_interrupt, SA_SHIRQ, dev->name, dev)) {
2336 printk("%s: request_irq FAILED\n", dev->name);
2337 result = -EAGAIN;
2338 goto done;
2340 acxlog(L_DEBUG|L_IRQ, "request_irq %d successful\n", dev->irq);
2342 /* ifup device */
2343 acxpci_s_up(dev);
2345 /* We don't currently have to do anything else.
2346 * The setup of the MAC should be subsequently completed via
2347 * the mlme commands.
2348 * Higher layers know we're ready from dev->start==1 and
2349 * dev->tbusy==0. Our rx path knows to pass up received/
2350 * frames because of dev->flags&IFF_UP is true.
2352 done:
2353 acx_sem_unlock(priv);
2355 FN_EXIT1(result);
2356 return result;
2360 /***********************************************************************
2361 ** acxpci_e_close
2363 ** Called as a result of SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
2364 ** from set to clear. I.e. called by "ifconfig DEV down"
2366 ** Returns:
2367 ** 0 success
2368 ** >0 f/w reported error
2369 ** <0 driver reported error
2371 static int
2372 acxpci_e_close(netdevice_t *dev)
2374 wlandevice_t *priv = netdev_priv(dev);
2376 FN_ENTER;
2378 acx_sem_lock(priv);
2380 /* ifdown device */
2381 CLEAR_BIT(priv->dev_state_mask, ACX_STATE_IFACE_UP);
2382 if (netif_device_present(dev)) {
2383 acxpci_s_down(dev);
2386 /* disable all IRQs, release shared IRQ handler */
2387 write_reg16(priv, IO_ACX_IRQ_MASK, 0xffff);
2388 write_reg16(priv, IO_ACX_FEMR, 0x0);
2389 free_irq(dev->irq, dev);
2391 /* We currently don't have to do anything else.
2392 * Higher layers know we're not ready from dev->start==0 and
2393 * dev->tbusy==1. Our rx path knows to not pass up received
2394 * frames because of dev->flags&IFF_UP is false.
2396 acxlog(L_INIT, "module count--\n");
2397 WLAN_MOD_DEC_USE_COUNT;
2399 acx_sem_unlock(priv);
2401 acxlog(L_INIT, "closed device\n");
2402 FN_EXIT0;
2403 return OK;
2407 /***********************************************************************
2408 ** acxpci_i_tx_timeout
2410 ** Called from network core. Must not sleep!
2412 static void
2413 acxpci_i_tx_timeout(netdevice_t *dev)
2415 wlandevice_t *priv = netdev_priv(dev);
2416 unsigned long flags;
2417 unsigned int tx_num_cleaned;
2419 FN_ENTER;
2421 acx_lock(priv, flags);
2423 /* clean processed tx descs, they may have been completely full */
2424 tx_num_cleaned = acxpci_l_clean_txdesc(priv);
2426 /* nothing cleaned, yet (almost) no free buffers available?
2427 * --> clean all tx descs, no matter which status!!
2428 * Note that I strongly suspect that doing emergency cleaning
2429 * may confuse the firmware. This is a last ditch effort to get
2430 * ANYTHING to work again...
2432 * TODO: it's best to simply reset & reinit hw from scratch...
2434 if ((priv->tx_free <= TX_EMERG_CLEAN) && (tx_num_cleaned == 0)) {
2435 printk("%s: FAILED to free any of the many full tx buffers. "
2436 "Switching to emergency freeing. "
2437 "Please report!\n", dev->name);
2438 acxpci_l_clean_txdesc_emergency(priv);
2441 if (acx_queue_stopped(dev) && (ACX_STATUS_4_ASSOCIATED == priv->status))
2442 acx_wake_queue(dev, "after tx timeout");
2444 /* stall may have happened due to radio drift, so recalib radio */
2445 acx_schedule_task(priv, ACX_AFTER_IRQ_CMD_RADIO_RECALIB);
2447 /* do unimportant work last */
2448 printk("%s: tx timeout!\n", dev->name);
2449 priv->stats.tx_errors++;
2451 acx_unlock(priv, flags);
2453 FN_EXIT0;
2457 /***********************************************************************
2458 ** acxpci_i_set_multicast_list
2459 ** FIXME: most likely needs refinement
2461 static void
2462 acxpci_i_set_multicast_list(netdevice_t *dev)
2464 wlandevice_t *priv = netdev_priv(dev);
2465 unsigned long flags;
2467 FN_ENTER;
2469 acx_lock(priv, flags);
2471 /* firmwares don't have allmulti capability,
2472 * so just use promiscuous mode instead in this case. */
2473 if (dev->flags & (IFF_PROMISC|IFF_ALLMULTI)) {
2474 SET_BIT(priv->rx_config_1, RX_CFG1_RCV_PROMISCUOUS);
2475 CLEAR_BIT(priv->rx_config_1, RX_CFG1_FILTER_ALL_MULTI);
2476 SET_BIT(priv->set_mask, SET_RXCONFIG);
2477 /* let kernel know in case *we* needed to set promiscuous */
2478 dev->flags |= (IFF_PROMISC|IFF_ALLMULTI);
2479 } else {
2480 CLEAR_BIT(priv->rx_config_1, RX_CFG1_RCV_PROMISCUOUS);
2481 SET_BIT(priv->rx_config_1, RX_CFG1_FILTER_ALL_MULTI);
2482 SET_BIT(priv->set_mask, SET_RXCONFIG);
2483 dev->flags &= ~(IFF_PROMISC|IFF_ALLMULTI);
2486 /* cannot update card settings directly here, atomic context */
2487 acx_schedule_task(priv, ACX_AFTER_IRQ_UPDATE_CARD_CFG);
2489 acx_unlock(priv, flags);
2491 FN_EXIT0;
2495 /***************************************************************
2496 ** acxpci_l_process_rxdesc
2498 ** Called directly and only from the IRQ handler
2501 #if !ACX_DEBUG
2502 static inline void log_rxbuffer(const wlandevice_t *priv) {}
2503 #else
2504 static void
2505 log_rxbuffer(const wlandevice_t *priv)
2507 const struct rxhostdesc *rxhostdesc;
2508 int i;
2510 /* no FN_ENTER here, we don't want that */
2512 rxhostdesc = priv->rxhostdesc_start;
2513 if (!rxhostdesc) return;
2514 for (i = 0; i < RX_CNT; i++) {
2515 if ((rxhostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2516 && (rxhostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2517 printk("rx: buf %d full\n", i);
2518 rxhostdesc++;
2521 #endif
2523 static void
2524 acxpci_l_process_rxdesc(wlandevice_t *priv)
2526 rxhostdesc_t *hostdesc;
2527 int count, tail;
2529 FN_ENTER;
2531 if (unlikely(acx_debug & L_BUFR))
2532 log_rxbuffer(priv);
2534 /* First, have a loop to determine the first descriptor that's
2535 * full, just in case there's a mismatch between our current
2536 * rx_tail and the full descriptor we're supposed to handle. */
2537 count = RX_CNT;
2538 tail = priv->rx_tail;
2539 while (1) {
2540 hostdesc = &priv->rxhostdesc_start[tail];
2541 /* advance tail regardless of outcome of the below test */
2542 tail = (tail + 1) % RX_CNT;
2544 if ((hostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2545 && (hostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2546 break; /* found it! */
2548 if (--count) /* hmm, no luck: all descs empty, bail out */
2549 goto end;
2552 /* now process descriptors, starting with the first we figured out */
2553 while (1) {
2554 acxlog(L_BUFR, "rx: tail=%u Ctl_16=%04X Status=%08X\n",
2555 tail, hostdesc->Ctl_16, hostdesc->Status);
2557 acx_l_process_rxbuf(priv, hostdesc->data);
2559 hostdesc->Status = 0;
2560 /* flush all writes before adapter sees CTL_HOSTOWN change */
2561 wmb();
2562 /* Host no longer owns this, needs to be LAST */
2563 CLEAR_BIT(hostdesc->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
2565 /* ok, descriptor is handled, now check the next descriptor */
2566 hostdesc = &priv->rxhostdesc_start[tail];
2568 /* if next descriptor is empty, then bail out */
2569 if (!(hostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2570 || !(hostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2571 break;
2573 tail = (tail + 1) % RX_CNT;
2575 end:
2576 priv->rx_tail = tail;
2577 FN_EXIT0;
2581 /***********************************************************************
2582 ** acxpci_i_interrupt
2584 ** IRQ handler (atomic context, must not sleep, blah, blah)
2587 /* scan is complete. all frames now on the receive queue are valid */
2588 #define INFO_SCAN_COMPLETE 0x0001
2589 #define INFO_WEP_KEY_NOT_FOUND 0x0002
2590 /* hw has been reset as the result of a watchdog timer timeout */
2591 #define INFO_WATCH_DOG_RESET 0x0003
2592 /* failed to send out NULL frame from PS mode notification to AP */
2593 /* recommended action: try entering 802.11 PS mode again */
2594 #define INFO_PS_FAIL 0x0004
2595 /* encryption/decryption process on a packet failed */
2596 #define INFO_IV_ICV_FAILURE 0x0005
2598 /* Info mailbox format:
2599 2 bytes: type
2600 2 bytes: status
2601 more bytes may follow
2602 rumors say about status:
2603 0x0000 info available (set by hw)
2604 0x0001 information received (must be set by host)
2605 0x1000 info available, mailbox overflowed (messages lost) (set by hw)
2606 but in practice we've seen:
2607 0x9000 when we did not set status to 0x0001 on prev message
2608 0x1001 when we did set it
2609 0x0000 was never seen
2610 conclusion: this is really a bitfield:
2611 0x1000 is 'info available' bit
2612 'mailbox overflowed' bit is 0x8000, not 0x1000
2613 value of 0x0000 probably means that there are no messages at all
2614 P.S. I dunno how in hell hw is supposed to notice that messages are lost -
2615 it does NOT clear bit 0x0001, and this bit will probably stay forever set
2616 after we set it once. Let's hope this will be fixed in firmware someday
2618 static void
2619 read_info_status(wlandevice_t *priv)
2621 u32 value;
2623 write_reg32(priv, IO_ACX_SLV_END_CTL, 0x0);
2624 write_reg32(priv, IO_ACX_SLV_MEM_CTL, 0x1);
2626 write_reg32(priv, IO_ACX_SLV_MEM_ADDR,
2627 read_reg32(priv, IO_ACX_INFO_MAILBOX_OFFS));
2629 /* make sure we only read the data once all cfg registers are written: */
2630 write_flush(priv);
2631 value = read_reg32(priv, IO_ACX_SLV_MEM_DATA);
2633 priv->info_type = (u16)value;
2634 priv->info_status = (value >> 16);
2636 /* inform hw that we have read this info message */
2637 write_reg32(priv, IO_ACX_SLV_MEM_DATA, priv->info_type | 0x00010000);
2638 write_flush(priv);
2639 /* now bother hw to notice it: */
2640 write_reg16(priv, IO_ACX_INT_TRIG, INT_TRIG_INFOACK);
2641 write_flush(priv);
2643 acxlog(L_CTL, "info_type 0x%04X, info_status 0x%04X\n",
2644 priv->info_type, priv->info_status);
2648 static void
2649 handle_info_irq(wlandevice_t *priv)
2651 #if ACX_DEBUG
2652 static const char * const info_type_msg[] = {
2653 "(unknown)",
2654 "scan complete",
2655 "WEP key not found",
2656 "internal watchdog reset was done",
2657 "failed to send powersave (NULL frame) notification to AP",
2658 "encrypt/decrypt on a packet has failed",
2659 "TKIP tx keys disabled",
2660 "TKIP rx keys disabled",
2661 "TKIP rx: key ID not found",
2662 "???",
2663 "???",
2664 "???",
2665 "???",
2666 "???",
2667 "???",
2668 "???",
2669 "TKIP IV value exceeds thresh"
2671 #endif
2672 read_info_status(priv);
2673 acxlog(L_IRQ, "got Info IRQ: status 0x%04X type 0x%04X: %s\n",
2674 priv->info_status, priv->info_type,
2675 info_type_msg[(priv->info_type >= VEC_SIZE(info_type_msg)) ?
2676 0 : priv->info_type]
2681 static void
2682 log_unusual_irq(u16 irqtype) {
2684 if (!printk_ratelimit())
2685 return;
2688 printk("acx: got");
2689 if (irqtype & HOST_INT_RX_DATA) {
2690 printk(" Rx_Data");
2692 /* HOST_INT_TX_COMPLETE */
2693 if (irqtype & HOST_INT_TX_XFER) {
2694 printk(" Tx_Xfer");
2696 /* HOST_INT_RX_COMPLETE */
2697 if (irqtype & HOST_INT_DTIM) {
2698 printk(" DTIM");
2700 if (irqtype & HOST_INT_BEACON) {
2701 printk(" Beacon");
2703 if (irqtype & HOST_INT_TIMER) {
2704 acxlog(L_IRQ, " Timer");
2706 if (irqtype & HOST_INT_KEY_NOT_FOUND) {
2707 printk(" Key_Not_Found");
2709 if (irqtype & HOST_INT_IV_ICV_FAILURE) {
2710 printk(" IV_ICV_Failure");
2712 /* HOST_INT_CMD_COMPLETE */
2713 /* HOST_INT_INFO */
2714 if (irqtype & HOST_INT_OVERFLOW) {
2715 printk(" Overflow");
2717 if (irqtype & HOST_INT_PROCESS_ERROR) {
2718 printk(" Process_Error");
2720 /* HOST_INT_SCAN_COMPLETE */
2721 if (irqtype & HOST_INT_FCS_THRESHOLD) {
2722 printk(" FCS_Threshold");
2724 if (irqtype & HOST_INT_UNKNOWN) {
2725 printk(" Unknown");
2727 printk(" IRQ(s)\n");
2731 static void
2732 update_link_quality_led(wlandevice_t *priv)
2734 int qual;
2736 qual = acx_signal_determine_quality(priv->wstats.qual.level, priv->wstats.qual.noise);
2737 if (qual > priv->brange_max_quality)
2738 qual = priv->brange_max_quality;
2740 if (time_after(jiffies, priv->brange_time_last_state_change +
2741 (HZ/2 - HZ/2 * (unsigned long)qual / priv->brange_max_quality ) )) {
2742 acxpci_l_power_led(priv, (priv->brange_last_state == 0));
2743 priv->brange_last_state ^= 1; /* toggle */
2744 priv->brange_time_last_state_change = jiffies;
2749 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* a la orinoco.c */
2751 static irqreturn_t
2752 acxpci_i_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2754 wlandevice_t *priv;
2755 unsigned long flags;
2756 unsigned int irqcount = MAX_IRQLOOPS_PER_JIFFY;
2757 u16 irqtype, unmasked;
2759 priv = (wlandevice_t *) (((netdevice_t *) dev_id)->priv);
2761 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2762 * I am paranoid */
2763 acx_lock(priv, flags);
2765 unmasked = read_reg16(priv, IO_ACX_IRQ_STATUS_CLEAR);
2766 if (unlikely(0xffff == unmasked)) {
2767 /* 0xffff value hints at missing hardware,
2768 * so don't do anything.
2769 * FIXME: that's not very clean - maybe we are able to
2770 * establish a flag which definitely tells us that some
2771 * hardware is absent and which we could check here?
2772 * Hmm, but other drivers do the very same thing... */
2773 acxlog(L_IRQ, "IRQ type:FFFF - device removed? IRQ_NONE\n");
2774 goto none;
2777 /* We will check only "interesting" IRQ types */
2778 irqtype = unmasked & ~priv->irq_mask;
2779 if (!irqtype) {
2780 /* We are on a shared IRQ line and it wasn't our IRQ */
2781 acxlog(L_IRQ, "IRQ type:%04X, mask:%04X - all are masked, IRQ_NONE\n",
2782 unmasked, priv->irq_mask);
2783 goto none;
2786 /* Done here because IRQ_NONEs taking three lines of log
2787 ** drive me crazy */
2788 FN_ENTER;
2790 #define IRQ_ITERATE 1
2791 #if IRQ_ITERATE
2792 if (jiffies != priv->irq_last_jiffies) {
2793 priv->irq_loops_this_jiffy = 0;
2794 priv->irq_last_jiffies = jiffies;
2797 /* safety condition; we'll normally abort loop below
2798 * in case no IRQ type occurred */
2799 while (--irqcount) {
2800 #endif
2801 /* ACK all IRQs asap */
2802 write_reg16(priv, IO_ACX_IRQ_ACK, 0xffff);
2804 acxlog(L_IRQ, "IRQ type:%04X, mask:%04X, type & ~mask:%04X\n",
2805 unmasked, priv->irq_mask, irqtype);
2807 /* Handle most important IRQ types first */
2808 if (irqtype & HOST_INT_RX_COMPLETE) {
2809 acxlog(L_IRQ, "got Rx_Complete IRQ\n");
2810 acxpci_l_process_rxdesc(priv);
2812 if (irqtype & HOST_INT_TX_COMPLETE) {
2813 acxlog(L_IRQ, "got Tx_Complete IRQ\n");
2814 /* don't clean up on each Tx complete, wait a bit
2815 * unless we're going towards full, in which case
2816 * we do it immediately, too (otherwise we might lockup
2817 * with a full Tx buffer if we go into
2818 * acxpci_l_clean_txdesc() at a time when we won't wakeup
2819 * the net queue in there for some reason...) */
2820 if (priv->tx_free <= TX_START_CLEAN) {
2821 #if TX_CLEANUP_IN_SOFTIRQ
2822 acx_schedule_task(priv, ACX_AFTER_IRQ_TX_CLEANUP);
2823 #else
2824 acxpci_l_clean_txdesc(priv);
2825 #endif
2829 /* Less frequent ones */
2830 if (irqtype & (0
2831 | HOST_INT_CMD_COMPLETE
2832 | HOST_INT_INFO
2833 | HOST_INT_SCAN_COMPLETE
2834 )) {
2835 if (irqtype & HOST_INT_CMD_COMPLETE) {
2836 acxlog(L_IRQ, "got Command_Complete IRQ\n");
2837 /* save the state for the running issue_cmd() */
2838 SET_BIT(priv->irq_status, HOST_INT_CMD_COMPLETE);
2840 if (irqtype & HOST_INT_INFO) {
2841 handle_info_irq(priv);
2843 if (irqtype & HOST_INT_SCAN_COMPLETE) {
2844 acxlog(L_IRQ, "got Scan_Complete IRQ\n");
2845 /* need to do that in process context */
2846 acx_schedule_task(priv, ACX_AFTER_IRQ_COMPLETE_SCAN);
2847 /* remember that fw is not scanning anymore */
2848 SET_BIT(priv->irq_status, HOST_INT_SCAN_COMPLETE);
2852 /* These we just log, but either they happen rarely
2853 * or we keep them masked out */
2854 if (irqtype & (0
2855 | HOST_INT_RX_DATA
2856 /* | HOST_INT_TX_COMPLETE */
2857 | HOST_INT_TX_XFER
2858 /* | HOST_INT_RX_COMPLETE */
2859 | HOST_INT_DTIM
2860 | HOST_INT_BEACON
2861 | HOST_INT_TIMER
2862 | HOST_INT_KEY_NOT_FOUND
2863 | HOST_INT_IV_ICV_FAILURE
2864 /* | HOST_INT_CMD_COMPLETE */
2865 /* | HOST_INT_INFO */
2866 | HOST_INT_OVERFLOW
2867 | HOST_INT_PROCESS_ERROR
2868 /* | HOST_INT_SCAN_COMPLETE */
2869 | HOST_INT_FCS_THRESHOLD
2870 | HOST_INT_UNKNOWN
2871 )) {
2872 log_unusual_irq(irqtype);
2875 #if IRQ_ITERATE
2876 unmasked = read_reg16(priv, IO_ACX_IRQ_STATUS_CLEAR);
2877 irqtype = unmasked & ~priv->irq_mask;
2878 /* Bail out if no new IRQ bits or if all are masked out */
2879 if (!irqtype)
2880 break;
2882 if (unlikely(++priv->irq_loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY)) {
2883 printk(KERN_ERR "acx: too many interrupts per jiffy!\n");
2884 /* Looks like card floods us with IRQs! Try to stop that */
2885 write_reg16(priv, IO_ACX_IRQ_MASK, 0xffff);
2886 /* This will short-circuit all future attempts to handle IRQ.
2887 * We cant do much more... */
2888 priv->irq_mask = 0;
2889 break;
2892 #endif
2893 /* Routine to perform blink with range */
2894 if (unlikely(priv->led_power == 2))
2895 update_link_quality_led(priv);
2897 /* handled: */
2898 /* write_flush(priv); - not needed, last op was read anyway */
2899 acx_unlock(priv, flags);
2900 FN_EXIT0;
2901 return IRQ_HANDLED;
2903 none:
2904 acx_unlock(priv, flags);
2905 return IRQ_NONE;
2909 /***********************************************************************
2910 ** acxpci_l_power_led
2912 void
2913 acxpci_l_power_led(wlandevice_t *priv, int enable)
2915 u16 gpio_pled = IS_ACX111(priv) ? 0x0040 : 0x0800;
2917 /* A hack. Not moving message rate limiting to priv->xxx
2918 * (it's only a debug message after all) */
2919 static int rate_limit = 0;
2921 if (rate_limit++ < 3)
2922 acxlog(L_IOCTL, "Please report in case toggling the power "
2923 "LED doesn't work for your card!\n");
2924 if (enable)
2925 write_reg16(priv, IO_ACX_GPIO_OUT,
2926 read_reg16(priv, IO_ACX_GPIO_OUT) & ~gpio_pled);
2927 else
2928 write_reg16(priv, IO_ACX_GPIO_OUT,
2929 read_reg16(priv, IO_ACX_GPIO_OUT) | gpio_pled);
2933 /***********************************************************************
2934 ** Ioctls
2937 /***********************************************************************
2940 acx111pci_ioctl_info(
2941 struct net_device *dev,
2942 struct iw_request_info *info,
2943 struct iw_param *vwrq,
2944 char *extra)
2946 #if ACX_DEBUG > 1
2947 wlandevice_t *priv = netdev_priv(dev);
2948 rxdesc_t *rxdesc;
2949 txdesc_t *txdesc;
2950 rxhostdesc_t *rxhostdesc;
2951 txhostdesc_t *txhostdesc;
2952 struct acx111_ie_memoryconfig memconf;
2953 struct acx111_ie_queueconfig queueconf;
2954 unsigned long flags;
2955 int i;
2956 char memmap[0x34];
2957 char rxconfig[0x8];
2958 char fcserror[0x8];
2959 char ratefallback[0x5];
2961 if ( !(acx_debug & (L_IOCTL|L_DEBUG)) )
2962 return OK;
2963 /* using printk() since we checked debug flag already */
2965 acx_sem_lock(priv);
2967 if (!IS_ACX111(priv)) {
2968 printk("acx111-specific function called "
2969 "with non-acx111 chip, aborting\n");
2970 goto end_ok;
2973 /* get Acx111 Memory Configuration */
2974 memset(&memconf, 0, sizeof(memconf));
2975 /* BTW, fails with 12 (Write only) error code.
2976 ** Retained for easy testing of issue_cmd error handling :) */
2977 acx_s_interrogate(priv, &memconf, ACX1xx_IE_QUEUE_CONFIG);
2979 /* get Acx111 Queue Configuration */
2980 memset(&queueconf, 0, sizeof(queueconf));
2981 acx_s_interrogate(priv, &queueconf, ACX1xx_IE_MEMORY_CONFIG_OPTIONS);
2983 /* get Acx111 Memory Map */
2984 memset(memmap, 0, sizeof(memmap));
2985 acx_s_interrogate(priv, &memmap, ACX1xx_IE_MEMORY_MAP);
2987 /* get Acx111 Rx Config */
2988 memset(rxconfig, 0, sizeof(rxconfig));
2989 acx_s_interrogate(priv, &rxconfig, ACX1xx_IE_RXCONFIG);
2991 /* get Acx111 fcs error count */
2992 memset(fcserror, 0, sizeof(fcserror));
2993 acx_s_interrogate(priv, &fcserror, ACX1xx_IE_FCS_ERROR_COUNT);
2995 /* get Acx111 rate fallback */
2996 memset(ratefallback, 0, sizeof(ratefallback));
2997 acx_s_interrogate(priv, &ratefallback, ACX1xx_IE_RATE_FALLBACK);
2999 /* force occurrence of a beacon interrupt */
3000 /* TODO: comment why is this necessary */
3001 write_reg16(priv, IO_ACX_HINT_TRIG, HOST_INT_BEACON);
3003 /* dump Acx111 Mem Configuration */
3004 printk("dump mem config:\n"
3005 "data read: %d, struct size: %d\n"
3006 "Number of stations: %1X\n"
3007 "Memory block size: %1X\n"
3008 "tx/rx memory block allocation: %1X\n"
3009 "count rx: %X / tx: %X queues\n"
3010 "options %1X\n"
3011 "fragmentation %1X\n"
3012 "Rx Queue 1 Count Descriptors: %X\n"
3013 "Rx Queue 1 Host Memory Start: %X\n"
3014 "Tx Queue 1 Count Descriptors: %X\n"
3015 "Tx Queue 1 Attributes: %X\n",
3016 memconf.len, (int) sizeof(memconf),
3017 memconf.no_of_stations,
3018 memconf.memory_block_size,
3019 memconf.tx_rx_memory_block_allocation,
3020 memconf.count_rx_queues, memconf.count_tx_queues,
3021 memconf.options,
3022 memconf.fragmentation,
3023 memconf.rx_queue1_count_descs,
3024 acx2cpu(memconf.rx_queue1_host_rx_start),
3025 memconf.tx_queue1_count_descs,
3026 memconf.tx_queue1_attributes);
3028 /* dump Acx111 Queue Configuration */
3029 printk("dump queue head:\n"
3030 "data read: %d, struct size: %d\n"
3031 "tx_memory_block_address (from card): %X\n"
3032 "rx_memory_block_address (from card): %X\n"
3033 "rx1_queue address (from card): %X\n"
3034 "tx1_queue address (from card): %X\n"
3035 "tx1_queue attributes (from card): %X\n",
3036 queueconf.len, (int) sizeof(queueconf),
3037 queueconf.tx_memory_block_address,
3038 queueconf.rx_memory_block_address,
3039 queueconf.rx1_queue_address,
3040 queueconf.tx1_queue_address,
3041 queueconf.tx1_attributes);
3043 /* dump Acx111 Mem Map */
3044 printk("dump mem map:\n"
3045 "data read: %d, struct size: %d\n"
3046 "Code start: %X\n"
3047 "Code end: %X\n"
3048 "WEP default key start: %X\n"
3049 "WEP default key end: %X\n"
3050 "STA table start: %X\n"
3051 "STA table end: %X\n"
3052 "Packet template start: %X\n"
3053 "Packet template end: %X\n"
3054 "Queue memory start: %X\n"
3055 "Queue memory end: %X\n"
3056 "Packet memory pool start: %X\n"
3057 "Packet memory pool end: %X\n"
3058 "iobase: %p\n"
3059 "iobase2: %p\n",
3060 *((u16 *)&memmap[0x02]), (int) sizeof(memmap),
3061 *((u32 *)&memmap[0x04]),
3062 *((u32 *)&memmap[0x08]),
3063 *((u32 *)&memmap[0x0C]),
3064 *((u32 *)&memmap[0x10]),
3065 *((u32 *)&memmap[0x14]),
3066 *((u32 *)&memmap[0x18]),
3067 *((u32 *)&memmap[0x1C]),
3068 *((u32 *)&memmap[0x20]),
3069 *((u32 *)&memmap[0x24]),
3070 *((u32 *)&memmap[0x28]),
3071 *((u32 *)&memmap[0x2C]),
3072 *((u32 *)&memmap[0x30]),
3073 priv->iobase,
3074 priv->iobase2);
3076 /* dump Acx111 Rx Config */
3077 printk("dump rx config:\n"
3078 "data read: %d, struct size: %d\n"
3079 "rx config: %X\n"
3080 "rx filter config: %X\n",
3081 *((u16 *)&rxconfig[0x02]), (int) sizeof(rxconfig),
3082 *((u16 *)&rxconfig[0x04]),
3083 *((u16 *)&rxconfig[0x06]));
3085 /* dump Acx111 fcs error */
3086 printk("dump fcserror:\n"
3087 "data read: %d, struct size: %d\n"
3088 "fcserrors: %X\n",
3089 *((u16 *)&fcserror[0x02]), (int) sizeof(fcserror),
3090 *((u32 *)&fcserror[0x04]));
3092 /* dump Acx111 rate fallback */
3093 printk("dump rate fallback:\n"
3094 "data read: %d, struct size: %d\n"
3095 "ratefallback: %X\n",
3096 *((u16 *)&ratefallback[0x02]), (int) sizeof(ratefallback),
3097 *((u8 *)&ratefallback[0x04]));
3099 /* protect against IRQ */
3100 acx_lock(priv, flags);
3102 /* dump acx111 internal rx descriptor ring buffer */
3103 rxdesc = priv->rxdesc_start;
3105 /* loop over complete receive pool */
3106 if (rxdesc) for (i = 0; i < RX_CNT; i++) {
3107 printk("\ndump internal rxdesc %d:\n"
3108 "mem pos %p\n"
3109 "next 0x%X\n"
3110 "acx mem pointer (dynamic) 0x%X\n"
3111 "CTL (dynamic) 0x%X\n"
3112 "Rate (dynamic) 0x%X\n"
3113 "RxStatus (dynamic) 0x%X\n"
3114 "Mod/Pre (dynamic) 0x%X\n",
3116 rxdesc,
3117 acx2cpu(rxdesc->pNextDesc),
3118 acx2cpu(rxdesc->ACXMemPtr),
3119 rxdesc->Ctl_8,
3120 rxdesc->rate,
3121 rxdesc->error,
3122 rxdesc->SNR);
3123 rxdesc++;
3126 /* dump host rx descriptor ring buffer */
3128 rxhostdesc = priv->rxhostdesc_start;
3130 /* loop over complete receive pool */
3131 if (rxhostdesc) for (i = 0; i < RX_CNT; i++) {
3132 printk("\ndump host rxdesc %d:\n"
3133 "mem pos %p\n"
3134 "buffer mem pos 0x%X\n"
3135 "buffer mem offset 0x%X\n"
3136 "CTL 0x%X\n"
3137 "Length 0x%X\n"
3138 "next 0x%X\n"
3139 "Status 0x%X\n",
3141 rxhostdesc,
3142 acx2cpu(rxhostdesc->data_phy),
3143 rxhostdesc->data_offset,
3144 le16_to_cpu(rxhostdesc->Ctl_16),
3145 le16_to_cpu(rxhostdesc->length),
3146 acx2cpu(rxhostdesc->desc_phy_next),
3147 rxhostdesc->Status);
3148 rxhostdesc++;
3151 /* dump acx111 internal tx descriptor ring buffer */
3152 txdesc = priv->txdesc_start;
3154 /* loop over complete transmit pool */
3155 if (txdesc) for (i = 0; i < TX_CNT; i++) {
3156 printk("\ndump internal txdesc %d:\n"
3157 "size 0x%X\n"
3158 "mem pos %p\n"
3159 "next 0x%X\n"
3160 "acx mem pointer (dynamic) 0x%X\n"
3161 "host mem pointer (dynamic) 0x%X\n"
3162 "length (dynamic) 0x%X\n"
3163 "CTL (dynamic) 0x%X\n"
3164 "CTL2 (dynamic) 0x%X\n"
3165 "Status (dynamic) 0x%X\n"
3166 "Rate (dynamic) 0x%X\n",
3168 (int) sizeof(struct txdesc),
3169 txdesc,
3170 acx2cpu(txdesc->pNextDesc),
3171 acx2cpu(txdesc->AcxMemPtr),
3172 acx2cpu(txdesc->HostMemPtr),
3173 le16_to_cpu(txdesc->total_length),
3174 txdesc->Ctl_8,
3175 txdesc->Ctl2_8, txdesc->error,
3176 txdesc->u.r1.rate);
3177 txdesc = move_txdesc(priv, txdesc, 1);
3180 /* dump host tx descriptor ring buffer */
3182 txhostdesc = priv->txhostdesc_start;
3184 /* loop over complete host send pool */
3185 if (txhostdesc) for (i = 0; i < TX_CNT * 2; i++) {
3186 printk("\ndump host txdesc %d:\n"
3187 "mem pos %p\n"
3188 "buffer mem pos 0x%X\n"
3189 "buffer mem offset 0x%X\n"
3190 "CTL 0x%X\n"
3191 "Length 0x%X\n"
3192 "next 0x%X\n"
3193 "Status 0x%X\n",
3195 txhostdesc,
3196 acx2cpu(txhostdesc->data_phy),
3197 txhostdesc->data_offset,
3198 le16_to_cpu(txhostdesc->Ctl_16),
3199 le16_to_cpu(txhostdesc->length),
3200 acx2cpu(txhostdesc->desc_phy_next),
3201 le32_to_cpu(txhostdesc->Status));
3202 txhostdesc++;
3205 /* write_reg16(priv, 0xb4, 0x4); */
3207 acx_unlock(priv, flags);
3208 end_ok:
3210 acx_sem_unlock(priv);
3211 #endif /* ACX_DEBUG */
3212 return OK;
3216 /***********************************************************************
3219 acx100pci_ioctl_set_phy_amp_bias(
3220 struct net_device *dev,
3221 struct iw_request_info *info,
3222 struct iw_param *vwrq,
3223 char *extra)
3225 wlandevice_t *priv = netdev_priv(dev);
3226 unsigned long flags;
3227 u16 gpio_old;
3229 if (!IS_ACX100(priv)) {
3230 /* WARNING!!!
3231 * Removing this check *might* damage
3232 * hardware, since we're tweaking GPIOs here after all!!!
3233 * You've been warned...
3234 * WARNING!!! */
3235 printk("acx: sorry, setting bias level for non-acx100 "
3236 "is not supported yet\n");
3237 return OK;
3240 if (*extra > 7) {
3241 printk("acx: invalid bias parameter, range is 0-7\n");
3242 return -EINVAL;
3245 acx_sem_lock(priv);
3247 /* Need to lock accesses to [IO_ACX_GPIO_OUT]:
3248 * IRQ handler uses it to update LED */
3249 acx_lock(priv, flags);
3250 gpio_old = read_reg16(priv, IO_ACX_GPIO_OUT);
3251 write_reg16(priv, IO_ACX_GPIO_OUT, (gpio_old & 0xf8ff) | ((u16)*extra << 8));
3252 acx_unlock(priv, flags);
3254 acxlog(L_DEBUG, "gpio_old: 0x%04X\n", gpio_old);
3255 printk("%s: PHY power amplifier bias: old:%d, new:%d\n",
3256 dev->name,
3257 (gpio_old & 0x0700) >> 8, (unsigned char)*extra);
3259 acx_sem_unlock(priv);
3261 return OK;
3265 /***************************************************************
3266 ** acxpci_l_alloc_tx
3267 ** Actually returns a txdesc_t* ptr
3269 tx_t*
3270 acxpci_l_alloc_tx(wlandevice_t* priv)
3272 struct txdesc *txdesc;
3273 int head;
3274 u8 ctl8;
3276 FN_ENTER;
3278 if(!priv->tx_free) {
3279 printk("acx: BUG: no free txdesc left\n");
3280 txdesc = NULL;
3281 goto end;
3284 head = priv->tx_head;
3285 txdesc = get_txdesc(priv, head);
3286 ctl8 = txdesc->Ctl_8;
3288 /* 2005-10-11: there were several bug reports on this happening
3289 ** but now cause seems to be understood & fixed */
3290 if (unlikely(DESC_CTL_HOSTOWN != (ctl8 & DESC_CTL_ACXDONE_HOSTOWN))) {
3291 /* whoops, descr at current index is not free, so probably
3292 * ring buffer already full */
3293 printk("acx: BUG: tx_head:%d Ctl8:0x%02X - failed to find "
3294 "free txdesc\n", head, ctl8);
3295 txdesc = NULL;
3296 goto end;
3299 /* Needed in case txdesc won't be eventually submitted for tx */
3300 txdesc->Ctl_8 = DESC_CTL_ACXDONE_HOSTOWN;
3302 priv->tx_free--;
3303 acxlog(L_BUFT, "tx: got desc %u, %u remain\n",
3304 head, priv->tx_free);
3306 /* Keep a few free descs between head and tail of tx ring.
3307 ** It is not absolutely needed, just feels safer */
3308 if (priv->tx_free < TX_STOP_QUEUE) {
3309 acxlog(L_BUF, "stop queue (%u tx desc left)\n",
3310 priv->tx_free);
3311 acx_stop_queue(priv->netdev, NULL);
3314 /* returning current descriptor, so advance to next free one */
3315 priv->tx_head = (head + 1) % TX_CNT;
3316 end:
3317 FN_EXIT0;
3319 return (tx_t*)txdesc;
3323 /***********************************************************************
3325 void*
3326 acxpci_l_get_txbuf(wlandevice_t *priv, tx_t* tx_opaque)
3328 return get_txhostdesc(priv, (txdesc_t*)tx_opaque)->data;
3332 /***********************************************************************
3333 ** acxpci_l_tx_data
3335 ** Can be called from IRQ (rx -> (AP bridging or mgmt response) -> tx).
3336 ** Can be called from acx_i_start_xmit (data frames from net core).
3338 void
3339 acxpci_l_tx_data(wlandevice_t *priv, tx_t* tx_opaque, int len)
3341 txdesc_t *txdesc = (txdesc_t*)tx_opaque;
3342 txhostdesc_t *hostdesc1, *hostdesc2;
3343 client_t *clt;
3344 u8 Ctl_8, Ctl2_8;
3346 FN_ENTER;
3348 /* fw doesn't tx such packets anyhow */
3349 if (len < WLAN_HDR_A3_LEN)
3350 goto end;
3352 hostdesc1 = get_txhostdesc(priv, txdesc);
3353 hostdesc2 = hostdesc1 + 1;
3355 /* modify flag status in separate variable to be able to write it back
3356 * in one big swoop later (also in order to have less device memory
3357 * accesses) */
3358 Ctl_8 = txdesc->Ctl_8;
3359 Ctl2_8 = txdesc->Ctl2_8;
3361 /* DON'T simply set Ctl field to 0 here globally,
3362 * it needs to maintain a consistent flag status (those are state flags!!),
3363 * otherwise it may lead to severe disruption. Only set or reset particular
3364 * flags at the exact moment this is needed...
3365 * FIXME: what about Ctl2? Equally problematic? */
3367 /* let chip do RTS/CTS handshaking before sending
3368 * in case packet size exceeds threshold */
3369 if (len > priv->rts_threshold)
3370 SET_BIT(Ctl2_8, DESC_CTL2_RTS);
3371 else
3372 CLEAR_BIT(Ctl2_8, DESC_CTL2_RTS);
3374 #ifdef DEBUG_WEP
3375 if (priv->wep_enabled)
3376 SET_BIT(Ctl2_8, DESC_CTL2_WEP);
3377 else
3378 CLEAR_BIT(Ctl2_8, DESC_CTL2_WEP);
3379 #endif
3381 switch (priv->mode) {
3382 case ACX_MODE_0_ADHOC:
3383 case ACX_MODE_3_AP:
3384 clt = acx_l_sta_list_get(priv, ((wlan_hdr_t*)hostdesc1->data)->a1);
3385 break;
3386 case ACX_MODE_2_STA:
3387 clt = priv->ap_client;
3388 break;
3389 #if 0
3390 /* testing was done on acx111: */
3391 case ACX_MODE_MONITOR:
3392 SET_BIT(Ctl2_8, 0
3393 /* sends CTS to self before packet */
3394 + DESC_CTL2_SEQ /* don't increase sequence field */
3395 /* not working (looks like good fcs is still added) */
3396 + DESC_CTL2_FCS /* don't add the FCS */
3397 /* not tested */
3398 + DESC_CTL2_MORE_FRAG
3399 /* not tested */
3400 + DESC_CTL2_RETRY /* don't increase retry field */
3401 /* not tested */
3402 + DESC_CTL2_POWER /* don't increase power mgmt. field */
3403 /* no effect */
3404 + DESC_CTL2_WEP /* encrypt this frame */
3405 /* not tested */
3406 + DESC_CTL2_DUR /* don't increase duration field */
3408 /* fallthrough */
3409 #endif
3410 default: /* ACX_MODE_OFF, ACX_MODE_MONITOR */
3411 clt = NULL;
3412 break;
3415 if (unlikely(clt && !clt->rate_cur)) {
3416 printk("acx: driver bug! bad ratemask\n");
3417 goto end;
3420 /* used in tx cleanup routine for auto rate and accounting: */
3421 put_txc(priv, txdesc, clt);
3423 txdesc->total_length = cpu_to_le16(len);
3424 hostdesc2->length = cpu_to_le16(len - WLAN_HDR_A3_LEN);
3425 if (IS_ACX111(priv)) {
3426 u16 rate_cur = clt ? clt->rate_cur : priv->rate_bcast;
3427 /* note that if !txdesc->do_auto, txrate->cur
3428 ** has only one nonzero bit */
3429 txdesc->u.r2.rate111 = cpu_to_le16(
3430 rate_cur
3431 /* WARNING: I was never able to make it work with prism54 AP.
3432 ** It was falling down to 1Mbit where shortpre is not applicable,
3433 ** and not working at all at "5,11 basic rates only" setting.
3434 ** I even didn't see tx packets in radio packet capture.
3435 ** Disabled for now --vda */
3436 /*| ((clt->shortpre && clt->cur!=RATE111_1) ? RATE111_SHORTPRE : 0) */
3438 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3439 /* should add this to rate111 above as necessary */
3440 | (clt->pbcc511 ? RATE111_PBCC511 : 0)
3441 #endif
3442 hostdesc1->length = cpu_to_le16(len);
3443 } else { /* ACX100 */
3444 u8 rate_100 = clt ? clt->rate_100 : priv->rate_bcast100;
3445 txdesc->u.r1.rate = rate_100;
3446 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3447 if (clt->pbcc511) {
3448 if (n == RATE100_5 || n == RATE100_11)
3449 n |= RATE100_PBCC511;
3452 if (clt->shortpre && (clt->cur != RATE111_1))
3453 SET_BIT(Ctl_8, DESC_CTL_SHORT_PREAMBLE); /* set Short Preamble */
3454 #endif
3455 /* set autodma and reclaim and 1st mpdu */
3456 SET_BIT(Ctl_8, DESC_CTL_AUTODMA | DESC_CTL_RECLAIM | DESC_CTL_FIRSTFRAG);
3457 hostdesc1->length = cpu_to_le16(WLAN_HDR_A3_LEN);
3459 /* don't need to clean ack/rts statistics here, already
3460 * done on descr cleanup */
3462 /* clears HOSTOWN and ACXDONE bits, thus telling that the descriptors
3463 * are now owned by the acx100; do this as LAST operation */
3464 CLEAR_BIT(Ctl_8, DESC_CTL_ACXDONE_HOSTOWN);
3465 /* flush writes before we release hostdesc to the adapter here */
3466 wmb();
3467 CLEAR_BIT(hostdesc1->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3468 CLEAR_BIT(hostdesc2->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
3470 /* write back modified flags */
3471 txdesc->Ctl2_8 = Ctl2_8;
3472 txdesc->Ctl_8 = Ctl_8;
3474 /* unused: txdesc->tx_time = cpu_to_le32(jiffies); */
3475 //TODO: should it be a mmiowb() instead? we are protecting against race with write[bwl]()
3476 /* flush writes before we tell the adapter that it's its turn now */
3477 wmb();
3478 write_reg16(priv, IO_ACX_INT_TRIG, INT_TRIG_TXPRC);
3479 write_flush(priv);
3481 /* log the packet content AFTER sending it,
3482 * in order to not delay sending any further than absolutely needed
3483 * Do separate logs for acx100/111 to have human-readable rates */
3484 if (unlikely(acx_debug & (L_XFER|L_DATA))) {
3485 u16 fc = ((wlan_hdr_t*)hostdesc1->data)->fc;
3486 if (IS_ACX111(priv))
3487 printk("tx: pkt (%s): len %d "
3488 "rate %04X%s status %u\n",
3489 acx_get_packet_type_string(le16_to_cpu(fc)), len,
3490 le16_to_cpu(txdesc->u.r2.rate111),
3491 (le16_to_cpu(txdesc->u.r2.rate111) & RATE111_SHORTPRE) ? "(SPr)" : "",
3492 priv->status);
3493 else
3494 printk("tx: pkt (%s): len %d rate %03u%s status %u\n",
3495 acx_get_packet_type_string(fc), len,
3496 txdesc->u.r1.rate,
3497 (Ctl_8 & DESC_CTL_SHORT_PREAMBLE) ? "(SPr)" : "",
3498 priv->status);
3500 if (acx_debug & L_DATA) {
3501 printk("tx: 802.11 [%d]: ", len);
3502 acx_dump_bytes(hostdesc1->data, len);
3505 end:
3506 FN_EXIT0;
3510 /***********************************************************************
3511 ** acxpci_l_clean_txdesc
3513 ** This function resets the txdescs' status when the ACX100
3514 ** signals the TX done IRQ (txdescs have been processed), starting with
3515 ** the pool index of the descriptor which we would use next,
3516 ** in order to make sure that we can be as fast as possible
3517 ** in filling new txdescs.
3518 ** Everytime we get called we know where the next packet to be cleaned is.
3521 #if !ACX_DEBUG
3522 static inline void log_txbuffer(const wlandevice_t *priv) {}
3523 #else
3524 static void
3525 log_txbuffer(wlandevice_t *priv)
3527 txdesc_t *txdesc;
3528 int i;
3530 /* no FN_ENTER here, we don't want that */
3531 /* no locks here, since it's entirely non-critical code */
3532 txdesc = priv->txdesc_start;
3533 if (!txdesc) return;
3534 printk("tx: desc->Ctl8's:");
3535 for (i = 0; i < TX_CNT; i++) {
3536 printk(" %02X", txdesc->Ctl_8);
3537 txdesc = move_txdesc(priv, txdesc, 1);
3539 printk("\n");
3541 #endif
3544 static void
3545 handle_tx_error(wlandevice_t *priv, u8 error, unsigned int finger)
3547 const char *err = "unknown error";
3549 /* hmm, should we handle this as a mask
3550 * of *several* bits?
3551 * For now I think only caring about
3552 * individual bits is ok... */
3553 switch (error) {
3554 case 0x01:
3555 err = "no Tx due to error in other fragment";
3556 priv->wstats.discard.fragment++;
3557 break;
3558 case 0x02:
3559 err = "Tx aborted";
3560 priv->stats.tx_aborted_errors++;
3561 break;
3562 case 0x04:
3563 err = "Tx desc wrong parameters";
3564 priv->wstats.discard.misc++;
3565 break;
3566 case 0x08:
3567 err = "WEP key not found";
3568 priv->wstats.discard.misc++;
3569 break;
3570 case 0x10:
3571 err = "MSDU lifetime timeout? - try changing "
3572 "'iwconfig retry lifetime XXX'";
3573 priv->wstats.discard.misc++;
3574 break;
3575 case 0x20:
3576 err = "excessive Tx retries due to either distance "
3577 "too high or unable to Tx or Tx frame error - "
3578 "try changing 'iwconfig txpower XXX' or "
3579 "'sens'itivity or 'retry'";
3580 priv->wstats.discard.retries++;
3581 /* FIXME: set (GETSET_TX|GETSET_RX) here
3582 * (this seems to recalib radio on ACX100)
3583 * after some more jiffies passed??
3584 * But OTOH Tx error 0x20 also seems to occur on
3585 * overheating, so I'm not sure whether we
3586 * actually want that, since people maybe won't notice
3587 * then that their hardware is slowly getting
3588 * cooked...
3589 * Or is it still a safe long distance from utter
3590 * radio non-functionality despite many radio
3591 * recalibs
3592 * to final destructive overheating of the hardware?
3593 * In this case we really should do recalib here...
3594 * I guess the only way to find out is to do a
3595 * potentially fatal self-experiment :-\
3596 * Or maybe only recalib in case we're using Tx
3597 * rate auto (on errors switching to lower speed
3598 * --> less heat?) or 802.11 power save mode? */
3600 /* ok, just do it.
3601 * ENABLE_TX|ENABLE_RX helps, so even do
3602 * DISABLE_TX and DISABLE_RX in order to perhaps
3603 * have more impact. */
3604 if (++priv->retry_errors_msg_ratelimit % 4 == 0) {
3605 if (priv->retry_errors_msg_ratelimit <= 20)
3606 printk("%s: several excessive Tx "
3607 "retry errors occurred, attempting "
3608 "to recalibrate radio. Radio "
3609 "drift might be caused by increasing "
3610 "card temperature, please check the card "
3611 "before it's too late!\n",
3612 priv->netdev->name);
3613 if (priv->retry_errors_msg_ratelimit == 20)
3614 printk("disabling above message\n");
3616 acx_schedule_task(priv, ACX_AFTER_IRQ_CMD_RADIO_RECALIB);
3618 break;
3619 case 0x40:
3620 err = "Tx buffer overflow";
3621 priv->stats.tx_fifo_errors++;
3622 break;
3623 case 0x80:
3624 err = "DMA error";
3625 priv->wstats.discard.misc++;
3626 break;
3628 priv->stats.tx_errors++;
3629 if (priv->stats.tx_errors <= 20)
3630 printk("%s: tx error 0x%02X, buf %02u! (%s)\n",
3631 priv->netdev->name, error, finger, err);
3632 else
3633 printk("%s: tx error 0x%02X, buf %02u!\n",
3634 priv->netdev->name, error, finger);
3638 /* maps acx100 tx descr rate field to acx111 one */
3639 static u16
3640 rate100to111(u8 r)
3642 switch (r) {
3643 case RATE100_1: return RATE111_1;
3644 case RATE100_2: return RATE111_2;
3645 case RATE100_5:
3646 case (RATE100_5 | RATE100_PBCC511): return RATE111_5;
3647 case RATE100_11:
3648 case (RATE100_11 | RATE100_PBCC511): return RATE111_11;
3649 case RATE100_22: return RATE111_22;
3650 default:
3651 printk("acx: unexpected acx100 txrate: %u! "
3652 "Please report\n", r);
3653 return RATE111_2;
3658 /* Theory of operation:
3659 ** client->rate_cap is a bitmask of rates client is capable of.
3660 ** client->rate_cfg is a bitmask of allowed (configured) rates.
3661 ** It is set as a result of iwconfig rate N [auto]
3662 ** or iwpriv set_rates "N,N,N N,N,N" commands.
3663 ** It can be fixed (e.g. 0x0080 == 18Mbit only),
3664 ** auto (0x00ff == 18Mbit or any lower value),
3665 ** and code handles any bitmask (0x1081 == try 54Mbit,18Mbit,1Mbit _only_).
3667 ** client->rate_cur is a value for rate111 field in tx descriptor.
3668 ** It is always set to txrate_cfg sans zero or more most significant
3669 ** bits. This routine handles selection of new rate_cur value depending on
3670 ** outcome of last tx event.
3672 ** client->rate_100 is a precalculated rate value for acx100
3673 ** (we can do without it, but will need to calculate it on each tx).
3675 ** You cannot configure mixed usage of 5.5 and/or 11Mbit rate
3676 ** with PBCC and CCK modulation. Either both at CCK or both at PBCC.
3677 ** In theory you can implement it, but so far it is considered not worth doing.
3679 ** 22Mbit, of course, is PBCC always. */
3681 static void
3682 handle_txrate_auto(wlandevice_t *priv, struct client *txc,
3683 unsigned int idx, u8 rate100, u16 rate111, u8 error)
3685 u16 sent_rate;
3686 u16 cur = txc->rate_cur;
3687 int slower_rate_was_used;
3689 /* FIXME: need to implement some kind of rate success memory
3690 * which stores the success percentage per rate, to be taken
3691 * into account when considering allowing a new rate, since it
3692 * doesn't really help to stupidly count fallback/stepup,
3693 * since one invalid rate will spoil the party anyway
3694 * (such as 22M in case of 11M-only peers) */
3696 /* vda: hmm. current code will do this:
3697 ** 1. send packets at 11 Mbit, stepup++
3698 ** 2. will try to send at 22Mbit. hardware will see no ACK,
3699 ** retries at 11Mbit, success. code notes that used rate
3700 ** is lower. stepup = 0, fallback++
3701 ** 3. repeat step 2 fallback_count times. Fall back to
3702 ** 11Mbit. go to step 1.
3703 ** If stepup_count is large (say, 16) and fallback_count
3704 ** is small (3), this wouldn't be too bad wrt throughput */
3706 /* do some preparations, i.e. calculate the one rate that was
3707 * used to send this packet */
3708 if (IS_ACX111(priv)) {
3709 sent_rate = 1 << highest_bit(rate111 & RATE111_ALL);
3710 } else {
3711 sent_rate = rate100to111(rate100);
3713 /* sent_rate has only one bit set now, corresponding to tx rate
3714 * which was used by hardware to tx this particular packet */
3716 /* now do the actual auto rate management */
3717 acxlog(L_DEBUG, "tx: %sclient=%p/"MACSTR" used=%04X cur=%04X cfg=%04X "
3718 "__=%u/%u ^^=%u/%u\n",
3719 (txc->ignore_count > 0) ? "[IGN] " : "",
3720 txc, MAC(txc->address), sent_rate, cur, txc->rate_cfg,
3721 txc->fallback_count, priv->fallback_threshold,
3722 txc->stepup_count, priv->stepup_threshold
3725 /* we need to ignore old packets already in the tx queue since
3726 * they use older rate bytes configured before our last rate change,
3727 * otherwise our mechanism will get confused by interpreting old data.
3728 * Do it here only, in order to have the logging above */
3729 if (txc->ignore_count) {
3730 txc->ignore_count--;
3731 return;
3734 /* true only if the only nonzero bit in sent_rate is
3735 ** less significant than highest nonzero bit in cur */
3736 slower_rate_was_used = ( cur > ((sent_rate<<1)-1) );
3738 if (slower_rate_was_used || (error & 0x30)) {
3739 txc->stepup_count = 0;
3740 if (++txc->fallback_count <= priv->fallback_threshold)
3741 return;
3742 txc->fallback_count = 0;
3744 /* clear highest 1 bit in cur */
3745 sent_rate = RATE111_54;
3746 while (!(cur & sent_rate)) sent_rate >>= 1;
3747 CLEAR_BIT(cur, sent_rate);
3749 if (cur) { /* we can't disable all rates! */
3750 acxlog(L_XFER, "tx: falling back to ratemask %04X\n", cur);
3751 txc->rate_cur = cur;
3752 txc->ignore_count = TX_CNT - priv->tx_free;
3754 } else if (!slower_rate_was_used) {
3755 txc->fallback_count = 0;
3756 if (++txc->stepup_count <= priv->stepup_threshold)
3757 return;
3758 txc->stepup_count = 0;
3760 /* sanitize. Sort of not needed, but I dont trust hw that much...
3761 ** what if it can report bogus tx rates sometimes? */
3762 while (!(cur & sent_rate)) sent_rate >>= 1;
3763 /* try to find a higher sent_rate that isn't yet in our
3764 * current set, but is an allowed cfg */
3765 while (1) {
3766 sent_rate <<= 1;
3767 if (sent_rate > txc->rate_cfg)
3768 /* no higher rates allowed by config */
3769 return;
3770 if (!(cur & sent_rate) && (txc->rate_cfg & sent_rate))
3771 /* found */
3772 break;
3773 /* not found, try higher one */
3775 SET_BIT(cur, sent_rate);
3776 acxlog(L_XFER, "tx: stepping up to ratemask %04X\n", cur);
3777 txc->rate_cur = cur;
3778 /* FIXME: totally bogus - we could be sending to many peers at once... */
3779 txc->ignore_count = TX_CNT - priv->tx_free;
3782 /* calculate acx100 style rate byte if needed */
3783 if (IS_ACX100(priv)) {
3784 txc->rate_100 = bitpos2rate100[highest_bit(cur)];
3789 unsigned int
3790 acxpci_l_clean_txdesc(wlandevice_t *priv)
3792 txdesc_t *txdesc;
3793 struct client *txc;
3794 int finger;
3795 int num_cleaned;
3796 u16 r111;
3797 u8 error, ack_failures, rts_failures, rts_ok, r100;
3799 FN_ENTER;
3801 if (unlikely(acx_debug & L_DEBUG))
3802 log_txbuffer(priv);
3804 acxlog(L_BUFT, "tx: cleaning up bufs from %u\n", priv->tx_tail);
3806 /* We know first descr which is not free yet. We advance it as far
3807 ** as we see correct bits set in following descs (if next desc
3808 ** is NOT free, we shouldn't advance at all). We know that in
3809 ** front of tx_tail may be "holes" with isolated free descs.
3810 ** We will catch up when all intermediate descs will be freed also */
3812 finger = priv->tx_tail;
3813 num_cleaned = 0;
3814 while (finger != priv->tx_head) {
3815 txdesc = get_txdesc(priv, finger);
3817 /* If we allocated txdesc on tx path but then decided
3818 ** to NOT use it, then it will be left as a free "bubble"
3819 ** in the "allocated for tx" part of the ring.
3820 ** We may meet it on the next ring pass here. */
3822 /* stop if not marked as "tx finished" and "host owned" */
3823 if ((txdesc->Ctl_8 & DESC_CTL_ACXDONE_HOSTOWN) != DESC_CTL_ACXDONE_HOSTOWN) {
3824 /* Moan a lot if none was cleaned */
3825 if (!num_cleaned) {
3826 if (!(acx_debug & L_DEBUG))
3827 log_txbuffer(priv);
3828 printk("%s: clean_tx_desc: tail is not free. "
3829 "tail:%d head:%d. Please report\n",
3830 priv->netdev->name,
3831 priv->tx_tail, priv->tx_head);
3833 break;
3836 /* remember desc values... */
3837 error = txdesc->error;
3838 ack_failures = txdesc->ack_failures;
3839 rts_failures = txdesc->rts_failures;
3840 rts_ok = txdesc->rts_ok;
3841 r100 = txdesc->u.r1.rate;
3842 r111 = txdesc->u.r2.rate111;
3844 #if WIRELESS_EXT > 13 /* wireless_send_event() and IWEVTXDROP are WE13 */
3845 /* need to check for certain error conditions before we
3846 * clean the descriptor: we still need valid descr data here */
3847 if (unlikely(0x30 & error)) {
3848 /* only send IWEVTXDROP in case of retry or lifetime exceeded;
3849 * all other errors mean we screwed up locally */
3850 union iwreq_data wrqu;
3851 wlan_hdr_t *hdr;
3852 txhostdesc_t *hostdesc;
3854 hostdesc = get_txhostdesc(priv, txdesc);
3855 hdr = (wlan_hdr_t *)hostdesc->data;
3856 MAC_COPY(wrqu.addr.sa_data, hdr->a1);
3857 wireless_send_event(priv->netdev, IWEVTXDROP, &wrqu, NULL);
3859 #endif
3860 /* ...and free the desc */
3861 txdesc->error = 0;
3862 txdesc->ack_failures = 0;
3863 txdesc->rts_failures = 0;
3864 txdesc->rts_ok = 0;
3865 /* signal host owning it LAST, since ACX already knows that this
3866 ** descriptor is finished since it set Ctl_8 accordingly. */
3867 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3869 priv->tx_free++;
3870 num_cleaned++;
3872 if ((priv->tx_free >= TX_START_QUEUE)
3873 && (priv->status == ACX_STATUS_4_ASSOCIATED)
3874 && (acx_queue_stopped(priv->netdev))
3876 acxlog(L_BUF, "tx: wake queue (avail. Tx desc %u)\n",
3877 priv->tx_free);
3878 acx_wake_queue(priv->netdev, NULL);
3881 /* do error checking, rate handling and logging
3882 * AFTER having done the work, it's faster */
3884 /* do rate handling */
3885 txc = get_txc(priv, txdesc);
3886 if (txc && priv->rate_auto) {
3887 handle_txrate_auto(priv, txc, finger, r100, r111, error);
3890 if (unlikely(error))
3891 handle_tx_error(priv, error, finger);
3893 if (IS_ACX111(priv))
3894 acxlog(L_BUFT, "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u r111=%04X\n",
3895 finger, ack_failures, rts_failures, rts_ok, r111);
3896 else
3897 acxlog(L_BUFT, "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u rate=%u\n",
3898 finger, ack_failures, rts_failures, rts_ok, r100);
3900 /* update pointer for descr to be cleaned next */
3901 finger = (finger + 1) % TX_CNT;
3904 /* remember last position */
3905 priv->tx_tail = finger;
3906 /* end: */
3907 FN_EXIT1(num_cleaned);
3908 return num_cleaned;
3911 /* clean *all* Tx descriptors, and regardless of their previous state.
3912 * Used for brute-force reset handling. */
3913 void
3914 acxpci_l_clean_txdesc_emergency(wlandevice_t *priv)
3916 txdesc_t *txdesc;
3917 int i;
3919 FN_ENTER;
3921 for (i = 0; i < TX_CNT; i++) {
3922 txdesc = get_txdesc(priv, i);
3924 /* free it */
3925 txdesc->ack_failures = 0;
3926 txdesc->rts_failures = 0;
3927 txdesc->rts_ok = 0;
3928 txdesc->error = 0;
3929 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
3932 priv->tx_free = TX_CNT;
3934 FN_EXIT0;
3938 /***********************************************************************
3939 ** acxpci_s_create_tx_host_desc_queue
3942 static void*
3943 allocate(wlandevice_t *priv, size_t size, dma_addr_t *phy, const char *msg)
3945 void *ptr;
3947 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 53)
3948 ptr = dma_alloc_coherent(priv->pdev ? &priv->pdev->dev : NULL,
3949 size, phy, GFP_KERNEL);
3950 #else
3951 #warning Using old PCI-specific DMA allocation, may fail with out-of-mem!
3952 #warning Upgrade kernel if it does...
3953 ptr = pci_alloc_consistent(priv->pdev, size, phy);
3954 #endif
3956 if (ptr) {
3957 acxlog(L_DEBUG, "%s sz=%d adr=0x%p phy=0x%08llx\n",
3958 msg, (int)size, ptr, (unsigned long long)*phy);
3959 memset(ptr, 0, size);
3960 return ptr;
3962 printk(KERN_ERR "acx: %s allocation FAILED (%d bytes)\n",
3963 msg, (int)size);
3964 return NULL;
3968 static int
3969 acxpci_s_create_tx_host_desc_queue(wlandevice_t *priv)
3971 txhostdesc_t *hostdesc;
3972 u8 *txbuf;
3973 dma_addr_t hostdesc_phy;
3974 dma_addr_t txbuf_phy;
3975 int i;
3977 FN_ENTER;
3979 /* allocate TX buffer */
3980 priv->txbuf_area_size = TX_CNT * WLAN_A4FR_MAXLEN_WEP_FCS;
3981 priv->txbuf_start = allocate(priv, priv->txbuf_area_size,
3982 &priv->txbuf_startphy, "txbuf_start");
3983 if (!priv->txbuf_start)
3984 goto fail;
3986 /* allocate the TX host descriptor queue pool */
3987 priv->txhostdesc_area_size = TX_CNT * 2*sizeof(txhostdesc_t);
3988 priv->txhostdesc_start = allocate(priv, priv->txhostdesc_area_size,
3989 &priv->txhostdesc_startphy, "txhostdesc_start");
3990 if (!priv->txhostdesc_start)
3991 goto fail;
3992 /* check for proper alignment of TX host descriptor pool */
3993 if ((long) priv->txhostdesc_start & 3) {
3994 printk("acx: driver bug: dma alloc returns unaligned address\n");
3995 goto fail;
3998 /* Each tx frame buffer is accessed by hardware via
3999 ** txdesc -> txhostdesc(s) -> framebuffer(s)
4000 ** We use only one txhostdesc per txdesc, but it looks like
4001 ** acx111 is buggy: it accesses second txhostdesc
4002 ** (via hostdesc.desc_phy_next field) even if
4003 ** txdesc->length == hostdesc->length and thus
4004 ** entire packet was placed into first txhostdesc.
4005 ** Due to this bug acx111 hangs unless second txhostdesc
4006 ** has hostdesc.length = 3 (or larger)
4007 ** Storing NULL into hostdesc.desc_phy_next
4008 ** doesn't seem to help.
4010 ** It is not known whether we need to have 'extra' second
4011 ** txhostdescs for acx100. Maybe it is acx111-only bug.
4013 ** Update: acx111 WG311v2 is even more bogus than this.
4014 ** We will initialize two hostdesc so that they point
4015 ** to adjacent memory areas.
4017 hostdesc = priv->txhostdesc_start;
4018 hostdesc_phy = priv->txhostdesc_startphy;
4019 txbuf = priv->txbuf_start;
4020 txbuf_phy = priv->txbuf_startphy;
4022 #if 0
4023 /* Works for xterasys xn2522g, does not for WG311v2 !!? */
4024 for (i = 0; i < TX_CNT*2; i++) {
4025 hostdesc_phy += sizeof(txhostdesc_t);
4026 if (!(i & 1)) {
4027 hostdesc->data_phy = cpu2acx(txbuf_phy);
4028 /* hostdesc->data_offset = ... */
4029 /* hostdesc->reserved = ... */
4030 hostdesc->Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
4031 /* hostdesc->length = ... */
4032 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
4033 hostdesc->pNext = ptr2acx(NULL);
4034 /* hostdesc->Status = ... */
4035 /* below: non-hardware fields */
4036 hostdesc->data = txbuf;
4038 txbuf += WLAN_A4FR_MAXLEN_WEP_FCS;
4039 txbuf_phy += WLAN_A4FR_MAXLEN_WEP_FCS;
4040 } else {
4041 /* hostdesc->data_phy = ... */
4042 /* hostdesc->data_offset = ... */
4043 /* hostdesc->reserved = ... */
4044 /* hostdesc->Ctl_16 = ... */
4045 hostdesc->length = 3; /* bug workaround */
4046 /* hostdesc->desc_phy_next = ... */
4047 /* hostdesc->pNext = ... */
4048 /* hostdesc->Status = ... */
4049 /* below: non-hardware fields */
4050 /* hostdesc->data = ... */
4052 hostdesc++;
4054 #endif
4055 for (i = 0; i < TX_CNT*2; i++) {
4056 hostdesc_phy += sizeof(txhostdesc_t);
4058 hostdesc->data_phy = cpu2acx(txbuf_phy);
4059 /* done by memset(0): hostdesc->data_offset = 0; */
4060 /* hostdesc->reserved = ... */
4061 hostdesc->Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
4062 /* hostdesc->length = ... */
4063 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
4064 /* done by memset(0): hostdesc->pNext = ptr2acx(NULL); */
4065 /* hostdesc->Status = ... */
4066 /* ->data is a non-hardware field: */
4067 hostdesc->data = txbuf;
4069 if (!(i & 1)) {
4070 txbuf += WLAN_HDR_A3_LEN;
4071 txbuf_phy += WLAN_HDR_A3_LEN;
4072 } else {
4073 txbuf += WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN;
4074 txbuf_phy += WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN;
4076 hostdesc++;
4078 hostdesc--;
4079 hostdesc->desc_phy_next = cpu2acx(priv->txhostdesc_startphy);
4081 FN_EXIT1(OK);
4082 return OK;
4083 fail:
4084 printk("acx: create_tx_host_desc_queue FAILED\n");
4085 /* dealloc will be done by free function on error case */
4086 FN_EXIT1(NOT_OK);
4087 return NOT_OK;
4091 /***************************************************************
4092 ** acxpci_s_create_rx_host_desc_queue
4094 /* the whole size of a data buffer (header plus data body)
4095 * plus 32 bytes safety offset at the end */
4096 #define RX_BUFFER_SIZE (sizeof(rxbuffer_t) + 32)
4098 static int
4099 acxpci_s_create_rx_host_desc_queue(wlandevice_t *priv)
4101 rxhostdesc_t *hostdesc;
4102 rxbuffer_t *rxbuf;
4103 dma_addr_t hostdesc_phy;
4104 dma_addr_t rxbuf_phy;
4105 int i;
4107 FN_ENTER;
4109 /* allocate the RX host descriptor queue pool */
4110 priv->rxhostdesc_area_size = RX_CNT * sizeof(rxhostdesc_t);
4111 priv->rxhostdesc_start = allocate(priv, priv->rxhostdesc_area_size,
4112 &priv->rxhostdesc_startphy, "rxhostdesc_start");
4113 if (!priv->rxhostdesc_start)
4114 goto fail;
4115 /* check for proper alignment of RX host descriptor pool */
4116 if ((long) priv->rxhostdesc_start & 3) {
4117 printk("acx: driver bug: dma alloc returns unaligned address\n");
4118 goto fail;
4121 /* allocate Rx buffer pool which will be used by the acx
4122 * to store the whole content of the received frames in it */
4123 priv->rxbuf_area_size = RX_CNT * RX_BUFFER_SIZE;
4124 priv->rxbuf_start = allocate(priv, priv->rxbuf_area_size,
4125 &priv->rxbuf_startphy, "rxbuf_start");
4126 if (!priv->rxbuf_start)
4127 goto fail;
4129 rxbuf = priv->rxbuf_start;
4130 rxbuf_phy = priv->rxbuf_startphy;
4131 hostdesc = priv->rxhostdesc_start;
4132 hostdesc_phy = priv->rxhostdesc_startphy;
4134 /* don't make any popular C programming pointer arithmetic mistakes
4135 * here, otherwise I'll kill you...
4136 * (and don't dare asking me why I'm warning you about that...) */
4137 for (i = 0; i < RX_CNT; i++) {
4138 hostdesc->data = rxbuf;
4139 hostdesc->data_phy = cpu2acx(rxbuf_phy);
4140 hostdesc->length = cpu_to_le16(RX_BUFFER_SIZE);
4141 CLEAR_BIT(hostdesc->Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
4142 rxbuf++;
4143 rxbuf_phy += sizeof(rxbuffer_t);
4144 hostdesc_phy += sizeof(rxhostdesc_t);
4145 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
4146 hostdesc++;
4148 hostdesc--;
4149 hostdesc->desc_phy_next = cpu2acx(priv->rxhostdesc_startphy);
4150 FN_EXIT1(OK);
4151 return OK;
4152 fail:
4153 printk("acx: create_rx_host_desc_queue FAILED\n");
4154 /* dealloc will be done by free function on error case */
4155 FN_EXIT1(NOT_OK);
4156 return NOT_OK;
4160 /***************************************************************
4161 ** acxpci_s_create_hostdesc_queues
4164 acxpci_s_create_hostdesc_queues(wlandevice_t *priv)
4166 int result;
4167 result = acxpci_s_create_tx_host_desc_queue(priv);
4168 if (OK != result) return result;
4169 result = acxpci_s_create_rx_host_desc_queue(priv);
4170 return result;
4174 /***************************************************************
4175 ** acxpci_create_tx_desc_queue
4177 static void
4178 acxpci_create_tx_desc_queue(wlandevice_t *priv, u32 tx_queue_start)
4180 txdesc_t *txdesc;
4181 txhostdesc_t *hostdesc;
4182 dma_addr_t hostmemptr;
4183 u32 mem_offs;
4184 int i;
4186 FN_ENTER;
4188 priv->txdesc_size = sizeof(txdesc_t);
4190 if (IS_ACX111(priv)) {
4191 /* the acx111 txdesc is 4 bytes larger */
4192 priv->txdesc_size = sizeof(txdesc_t) + 4;
4195 priv->txdesc_start = (txdesc_t *) (priv->iobase2 + tx_queue_start);
4197 acxlog(L_DEBUG, "priv->iobase2=%p\n"
4198 "tx_queue_start=%08X\n"
4199 "priv->txdesc_start=%p\n",
4200 priv->iobase2,
4201 tx_queue_start,
4202 priv->txdesc_start);
4204 priv->tx_free = TX_CNT;
4205 /* done by memset: priv->tx_head = 0; */
4206 /* done by memset: priv->tx_tail = 0; */
4207 txdesc = priv->txdesc_start;
4208 mem_offs = tx_queue_start;
4209 hostmemptr = priv->txhostdesc_startphy;
4210 hostdesc = priv->txhostdesc_start;
4212 if (IS_ACX111(priv)) {
4213 /* ACX111 has a preinitialized Tx buffer! */
4214 /* loop over whole send pool */
4215 /* FIXME: do we have to do the hostmemptr stuff here?? */
4216 for (i = 0; i < TX_CNT; i++) {
4217 txdesc->HostMemPtr = ptr2acx(hostmemptr);
4218 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
4219 /* reserve two (hdr desc and payload desc) */
4220 hostdesc += 2;
4221 hostmemptr += 2 * sizeof(txhostdesc_t);
4222 txdesc = move_txdesc(priv, txdesc, 1);
4224 } else {
4225 /* ACX100 Tx buffer needs to be initialized by us */
4226 /* clear whole send pool. sizeof is safe here (we are acx100) */
4227 memset(priv->txdesc_start, 0, TX_CNT * sizeof(txdesc_t));
4229 /* loop over whole send pool */
4230 for (i = 0; i < TX_CNT; i++) {
4231 acxlog(L_DEBUG, "configure card tx descriptor: 0x%p, "
4232 "size: 0x%X\n", txdesc, priv->txdesc_size);
4234 /* pointer to hostdesc memory */
4235 /* FIXME: type-incorrect assignment, might cause trouble
4236 * in some cases */
4237 txdesc->HostMemPtr = ptr2acx(hostmemptr);
4238 /* initialise ctl */
4239 txdesc->Ctl_8 = DESC_CTL_INIT;
4240 txdesc->Ctl2_8 = 0;
4241 /* point to next txdesc */
4242 txdesc->pNextDesc = cpu2acx(mem_offs + priv->txdesc_size);
4243 /* reserve two (hdr desc and payload desc) */
4244 hostdesc += 2;
4245 hostmemptr += 2 * sizeof(txhostdesc_t);
4246 /* go to the next one */
4247 mem_offs += priv->txdesc_size;
4248 /* ++ is safe here (we are acx100) */
4249 txdesc++;
4251 /* go back to the last one */
4252 txdesc--;
4253 /* and point to the first making it a ring buffer */
4254 txdesc->pNextDesc = cpu2acx(tx_queue_start);
4256 FN_EXIT0;
4260 /***************************************************************
4261 ** acxpci_create_rx_desc_queue
4263 static void
4264 acxpci_create_rx_desc_queue(wlandevice_t *priv, u32 rx_queue_start)
4266 rxdesc_t *rxdesc;
4267 u32 mem_offs;
4268 int i;
4270 FN_ENTER;
4272 /* done by memset: priv->rx_tail = 0; */
4274 /* ACX111 doesn't need any further config: preconfigures itself.
4275 * Simply print ring buffer for debugging */
4276 if (IS_ACX111(priv)) {
4277 /* rxdesc_start already set here */
4279 priv->rxdesc_start = (rxdesc_t *) ((u8 *)priv->iobase2 + rx_queue_start);
4281 rxdesc = priv->rxdesc_start;
4282 for (i = 0; i < RX_CNT; i++) {
4283 acxlog(L_DEBUG, "rx descriptor %d @ 0x%p\n", i, rxdesc);
4284 rxdesc = priv->rxdesc_start = (rxdesc_t *)
4285 (priv->iobase2 + acx2cpu(rxdesc->pNextDesc));
4287 } else {
4288 /* we didn't pre-calculate rxdesc_start in case of ACX100 */
4289 /* rxdesc_start should be right AFTER Tx pool */
4290 priv->rxdesc_start = (rxdesc_t *)
4291 ((u8 *) priv->txdesc_start + (TX_CNT * sizeof(txdesc_t)));
4292 /* NB: sizeof(txdesc_t) above is valid because we know
4293 ** we are in if(acx100) block. Beware of cut-n-pasting elsewhere!
4294 ** acx111's txdesc is larger! */
4296 memset(priv->rxdesc_start, 0, RX_CNT * sizeof(rxdesc_t));
4298 /* loop over whole receive pool */
4299 rxdesc = priv->rxdesc_start;
4300 mem_offs = rx_queue_start;
4301 for (i = 0; i < RX_CNT; i++) {
4302 acxlog(L_DEBUG, "rx descriptor @ 0x%p\n", rxdesc);
4303 rxdesc->Ctl_8 = DESC_CTL_RECLAIM | DESC_CTL_AUTODMA;
4304 /* point to next rxdesc */
4305 rxdesc->pNextDesc = cpu2acx(mem_offs + sizeof(rxdesc_t));
4306 /* go to the next one */
4307 mem_offs += sizeof(rxdesc_t);
4308 rxdesc++;
4310 /* go to the last one */
4311 rxdesc--;
4313 /* and point to the first making it a ring buffer */
4314 rxdesc->pNextDesc = cpu2acx(rx_queue_start);
4316 FN_EXIT0;
4320 /***************************************************************
4321 ** acxpci_create_desc_queues
4323 void
4324 acxpci_create_desc_queues(wlandevice_t *priv, u32 tx_queue_start, u32 rx_queue_start)
4326 acxpci_create_tx_desc_queue(priv, tx_queue_start);
4327 acxpci_create_rx_desc_queue(priv, rx_queue_start);
4331 /***************************************************************
4332 ** acxpci_s_proc_diag_output
4334 char*
4335 acxpci_s_proc_diag_output(char *p, wlandevice_t *priv)
4337 const char *rtl, *thd, *ttl;
4338 rxhostdesc_t *rxhostdesc;
4339 txdesc_t *txdesc;
4340 int i;
4342 FN_ENTER;
4344 p += sprintf(p, "** Rx buf **\n");
4345 rxhostdesc = priv->rxhostdesc_start;
4346 if (rxhostdesc) for (i = 0; i < RX_CNT; i++) {
4347 rtl = (i == priv->rx_tail) ? " [tail]" : "";
4348 if ((rxhostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
4349 && (rxhostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)) )
4350 p += sprintf(p, "%02u FULL%s\n", i, rtl);
4351 else
4352 p += sprintf(p, "%02u empty%s\n", i, rtl);
4353 rxhostdesc++;
4355 p += sprintf(p, "** Tx buf (free %d, Linux netqueue %s) **\n", priv->tx_free,
4356 acx_queue_stopped(priv->netdev) ? "STOPPED" : "running");
4357 txdesc = priv->txdesc_start;
4358 if (txdesc) for (i = 0; i < TX_CNT; i++) {
4359 thd = (i == priv->tx_head) ? " [head]" : "";
4360 ttl = (i == priv->tx_tail) ? " [tail]" : "";
4361 if (txdesc->Ctl_8 & DESC_CTL_ACXDONE)
4362 p += sprintf(p, "%02u free (%02X)%s%s\n", i, txdesc->Ctl_8, thd, ttl);
4363 else
4364 p += sprintf(p, "%02u tx (%02X)%s%s\n", i, txdesc->Ctl_8, thd, ttl);
4365 txdesc = move_txdesc(priv, txdesc, 1);
4367 p += sprintf(p,
4368 "\n"
4369 "** PCI data **\n"
4370 "txbuf_start %p, txbuf_area_size %u, txbuf_startphy %08llx\n"
4371 "txdesc_size %u, txdesc_start %p\n"
4372 "txhostdesc_start %p, txhostdesc_area_size %u, txhostdesc_startphy %08llx\n"
4373 "rxdesc_start %p\n"
4374 "rxhostdesc_start %p, rxhostdesc_area_size %u, rxhostdesc_startphy %08llx\n"
4375 "rxbuf_start %p, rxbuf_area_size %u, rxbuf_startphy %08llx\n",
4376 priv->txbuf_start, priv->txbuf_area_size, (u64)priv->txbuf_startphy,
4377 priv->txdesc_size, priv->txdesc_start,
4378 priv->txhostdesc_start, priv->txhostdesc_area_size, (u64)priv->txhostdesc_startphy,
4379 priv->rxdesc_start,
4380 priv->rxhostdesc_start, priv->rxhostdesc_area_size, (u64)priv->rxhostdesc_startphy,
4381 priv->rxbuf_start, priv->rxbuf_area_size, (u64)priv->rxbuf_startphy);
4383 FN_EXIT0;
4384 return p;
4388 /***********************************************************************
4391 acxpci_proc_eeprom_output(char *buf, wlandevice_t *priv)
4393 char *p = buf;
4394 int i;
4396 FN_ENTER;
4398 for (i = 0; i < 0x400; i++) {
4399 acxpci_read_eeprom_byte(priv, i, p++);
4402 FN_EXIT1(p - buf);
4403 return p - buf;
4407 /***********************************************************************
4409 void
4410 acxpci_set_interrupt_mask(wlandevice_t *priv)
4412 if (IS_ACX111(priv)) {
4413 priv->irq_mask = (u16) ~(0
4414 /* | HOST_INT_RX_DATA */
4415 | HOST_INT_TX_COMPLETE
4416 /* | HOST_INT_TX_XFER */
4417 | HOST_INT_RX_COMPLETE
4418 /* | HOST_INT_DTIM */
4419 /* | HOST_INT_BEACON */
4420 /* | HOST_INT_TIMER */
4421 /* | HOST_INT_KEY_NOT_FOUND */
4422 | HOST_INT_IV_ICV_FAILURE
4423 | HOST_INT_CMD_COMPLETE
4424 | HOST_INT_INFO
4425 /* | HOST_INT_OVERFLOW */
4426 /* | HOST_INT_PROCESS_ERROR */
4427 | HOST_INT_SCAN_COMPLETE
4428 | HOST_INT_FCS_THRESHOLD
4429 /* | HOST_INT_UNKNOWN */
4431 priv->irq_mask_off = (u16)~( HOST_INT_CMD_COMPLETE ); /* 0xfdff */
4432 } else {
4433 priv->irq_mask = (u16) ~(0
4434 /* | HOST_INT_RX_DATA */
4435 | HOST_INT_TX_COMPLETE
4436 /* | HOST_INT_TX_XFER */
4437 | HOST_INT_RX_COMPLETE
4438 /* | HOST_INT_DTIM */
4439 /* | HOST_INT_BEACON */
4440 /* | HOST_INT_TIMER */
4441 /* | HOST_INT_KEY_NOT_FOUND */
4442 /* | HOST_INT_IV_ICV_FAILURE */
4443 | HOST_INT_CMD_COMPLETE
4444 | HOST_INT_INFO
4445 /* | HOST_INT_OVERFLOW */
4446 /* | HOST_INT_PROCESS_ERROR */
4447 | HOST_INT_SCAN_COMPLETE
4448 /* | HOST_INT_FCS_THRESHOLD */
4449 /* | HOST_INT_UNKNOWN */
4451 priv->irq_mask_off = (u16)~( HOST_INT_UNKNOWN ); /* 0x7fff */
4456 /***********************************************************************
4459 acx100pci_s_set_tx_level(wlandevice_t *priv, u8 level_dbm)
4461 /* since it can be assumed that at least the Maxim radio has a
4462 * maximum power output of 20dBm and since it also can be
4463 * assumed that these values drive the DAC responsible for
4464 * setting the linear Tx level, I'd guess that these values
4465 * should be the corresponding linear values for a dBm value,
4466 * in other words: calculate the values from that formula:
4467 * Y [dBm] = 10 * log (X [mW])
4468 * then scale the 0..63 value range onto the 1..100mW range (0..20 dBm)
4469 * and you're done...
4470 * Hopefully that's ok, but you never know if we're actually
4471 * right... (especially since Windows XP doesn't seem to show
4472 * actual Tx dBm values :-P) */
4474 /* NOTE: on Maxim, value 30 IS 30mW, and value 10 IS 10mW - so the
4475 * values are EXACTLY mW!!! Not sure about RFMD and others,
4476 * though... */
4477 static const u8 dbm2val_maxim[21] = {
4478 63, 63, 63, 62,
4479 61, 61, 60, 60,
4480 59, 58, 57, 55,
4481 53, 50, 47, 43,
4482 38, 31, 23, 13,
4485 static const u8 dbm2val_rfmd[21] = {
4486 0, 0, 0, 1,
4487 2, 2, 3, 3,
4488 4, 5, 6, 8,
4489 10, 13, 16, 20,
4490 25, 32, 41, 50,
4493 const u8 *table;
4495 switch (priv->radio_type) {
4496 case RADIO_MAXIM_0D:
4497 table = &dbm2val_maxim[0];
4498 break;
4499 case RADIO_RFMD_11:
4500 case RADIO_RALINK_15:
4501 table = &dbm2val_rfmd[0];
4502 break;
4503 default:
4504 printk("%s: unknown/unsupported radio type, "
4505 "cannot modify tx power level yet!\n",
4506 priv->netdev->name);
4507 return NOT_OK;
4509 printk("%s: changing radio power level to %u dBm (%u)\n",
4510 priv->netdev->name, level_dbm, table[level_dbm]);
4511 acxpci_s_write_phy_reg(priv, 0x11, table[level_dbm]);
4512 return OK;
4516 /***********************************************************************
4517 ** Data for init_module/cleanup_module
4519 static const struct pci_device_id
4520 acxpci_id_tbl[] __devinitdata = {
4522 .vendor = PCI_VENDOR_ID_TI,
4523 .device = PCI_DEVICE_ID_TI_TNETW1100A,
4524 .subvendor = PCI_ANY_ID,
4525 .subdevice = PCI_ANY_ID,
4526 .driver_data = CHIPTYPE_ACX100,
4529 .vendor = PCI_VENDOR_ID_TI,
4530 .device = PCI_DEVICE_ID_TI_TNETW1100B,
4531 .subvendor = PCI_ANY_ID,
4532 .subdevice = PCI_ANY_ID,
4533 .driver_data = CHIPTYPE_ACX100,
4536 .vendor = PCI_VENDOR_ID_TI,
4537 .device = PCI_DEVICE_ID_TI_TNETW1130,
4538 .subvendor = PCI_ANY_ID,
4539 .subdevice = PCI_ANY_ID,
4540 .driver_data = CHIPTYPE_ACX111,
4543 .vendor = 0,
4544 .device = 0,
4545 .subvendor = 0,
4546 .subdevice = 0,
4547 .driver_data = 0,
4551 MODULE_DEVICE_TABLE(pci, acxpci_id_tbl);
4553 /* FIXME: checks should be removed once driver is included in the kernel */
4554 #ifndef __devexit_p
4555 #warning *** your kernel is EXTREMELY old since it does not even know about
4556 #warning __devexit_p - this driver could easily FAIL to work, so better
4557 #warning upgrade your kernel! ***
4558 #define __devexit_p(x) x
4559 #endif
4561 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 11)
4562 /* pci_name() got introduced at start of 2.6.x,
4563 * got mandatory (slot_name member removed) in 2.6.11-bk1 */
4564 #define pci_name(x) x->slot_name
4565 #endif
4567 static struct pci_driver
4568 acxpci_drv_id = {
4569 .name = "acx_pci",
4570 .id_table = acxpci_id_tbl,
4571 .probe = acxpci_e_probe,
4572 .remove = __devexit_p(acxpci_e_remove),
4573 #ifdef CONFIG_PM
4574 .suspend = acxpci_e_suspend,
4575 .resume = acxpci_e_resume
4576 #endif /* CONFIG_PM */
4580 /***********************************************************************
4581 ** acxpci_e_init_module
4583 ** Module initialization routine, called once at module load time
4585 int __init
4586 acxpci_e_init_module(void)
4588 int res;
4590 FN_ENTER;
4592 #if (ACX_IO_WIDTH==32)
4593 printk("acx: compiled to use 32bit I/O access. "
4594 "I/O timing issues might occur, such as "
4595 "non-working firmware upload. Report them\n");
4596 #else
4597 printk("acx: compiled to use 16bit I/O access only "
4598 "(compatibility mode)\n");
4599 #endif
4601 #ifdef __LITTLE_ENDIAN
4602 acxlog(L_INIT, "running on a little-endian CPU\n");
4603 #else
4604 acxlog(L_INIT, "running on a BIG-ENDIAN CPU\n");
4605 #endif
4606 acxlog(L_INIT, "PCI module " WLAN_RELEASE " initialized, "
4607 "waiting for cards to probe...\n");
4609 res = pci_module_init(&acxpci_drv_id);
4610 FN_EXIT1(res);
4611 return res;
4615 /***********************************************************************
4616 ** acxpci_e_cleanup_module
4618 ** Called at module unload time. This is our last chance to
4619 ** clean up after ourselves.
4621 void __exit
4622 acxpci_e_cleanup_module(void)
4624 struct net_device *dev;
4625 unsigned long flags;
4627 FN_ENTER;
4629 /* Since the whole module is about to be unloaded,
4630 * we recursively shutdown all cards we handled instead
4631 * of doing it in acxpci_e_remove() (which will be activated by us
4632 * via pci_unregister_driver at the end).
4633 * acxpci_e_remove() might just get called after a card eject,
4634 * that's why hardware operations have to be done here instead
4635 * when the hardware is available. */
4637 down(&root_acx_dev_sem);
4639 dev = root_acx_dev.newest;
4640 while (dev != NULL) {
4641 /* doh, netdev_priv() doesn't have const! */
4642 wlandevice_t *priv = netdev_priv(dev);
4644 acx_sem_lock(priv);
4646 /* disable both Tx and Rx to shut radio down properly */
4647 acx_s_issue_cmd(priv, ACX1xx_CMD_DISABLE_TX, NULL, 0);
4648 acx_s_issue_cmd(priv, ACX1xx_CMD_DISABLE_RX, NULL, 0);
4650 #ifdef REDUNDANT
4651 /* put the eCPU to sleep to save power
4652 * Halting is not possible currently,
4653 * since not supported by all firmware versions */
4654 acx_s_issue_cmd(priv, ACX100_CMD_SLEEP, NULL, 0);
4655 #endif
4656 acx_lock(priv, flags);
4658 /* disable power LED to save power :-) */
4659 acxlog(L_INIT, "switching off power LED to save power :-)\n");
4660 acxpci_l_power_led(priv, 0);
4662 /* stop our eCPU */
4663 if (IS_ACX111(priv)) {
4664 /* FIXME: does this actually keep halting the eCPU?
4665 * I don't think so...
4667 acxpci_l_reset_mac(priv);
4668 } else {
4669 u16 temp;
4671 /* halt eCPU */
4672 temp = read_reg16(priv, IO_ACX_ECPU_CTRL) | 0x1;
4673 write_reg16(priv, IO_ACX_ECPU_CTRL, temp);
4674 write_flush(priv);
4677 acx_unlock(priv, flags);
4679 acx_sem_unlock(priv);
4681 dev = priv->prev_nd;
4684 up(&root_acx_dev_sem);
4686 /* now let the PCI layer recursively remove
4687 * all PCI related things (acxpci_e_remove()) */
4688 pci_unregister_driver(&acxpci_drv_id);
4690 FN_EXIT0;