1 /***********************************************************************
2 ** Copyright (C) 2003 ACX100 Open Source Project
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/
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
28 ** acx100-users@lists.sf.net
29 ** http://acx100.sf.net
30 ** ---------------------------------------------------------------------
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>
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>
51 #include <linux/netdevice.h>
52 #include <linux/ioport.h>
53 #include <linux/pci.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 0x280
85 #define CARD_EEPROM_ID_SIZE 6
86 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* a la orinoco.c */
89 /***********************************************************************
91 static void acx_l_disable_irq(wlandevice_t
*priv
);
92 static void acx_l_enable_irq(wlandevice_t
*priv
);
93 static int acx_e_probe_pci(struct pci_dev
*pdev
,
94 const struct pci_device_id
*id
);
95 static void acx_e_remove_pci(struct pci_dev
*pdev
);
98 static int acx_e_suspend(struct pci_dev
*pdev
, pm_message_t state
);
99 static int acx_e_resume(struct pci_dev
*pdev
);
102 static void acx_i_tx_timeout(netdevice_t
*dev
);
103 static struct net_device_stats
*acx_e_get_stats(netdevice_t
*dev
);
104 static struct iw_statistics
*acx_e_get_wireless_stats(netdevice_t
*dev
);
106 static irqreturn_t
acx_i_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
107 static void acx_i_set_multicast_list(netdevice_t
*dev
);
109 static int acx_e_open(netdevice_t
*dev
);
110 static int acx_e_close(netdevice_t
*dev
);
111 static void acx_s_up(netdevice_t
*dev
);
112 static void acx_s_down(netdevice_t
*dev
);
115 /***********************************************************************
120 /* #define INLINE_IO static */
121 #define INLINE_IO static inline
124 acx_read_reg32(wlandevice_t
*priv
, unsigned int offset
)
126 #if ACX_IO_WIDTH == 32
127 return readl((u8
*)priv
->iobase
+ priv
->io
[offset
]);
129 return readw((u8
*)priv
->iobase
+ priv
->io
[offset
])
130 + (readw((u8
*)priv
->iobase
+ priv
->io
[offset
] + 2) << 16);
135 acx_read_reg16(wlandevice_t
*priv
, unsigned int offset
)
137 return readw((u8
*)priv
->iobase
+ priv
->io
[offset
]);
141 acx_read_reg8(wlandevice_t
*priv
, unsigned int offset
)
143 return readb((u8
*)priv
->iobase
+ priv
->io
[offset
]);
147 acx_write_reg32(wlandevice_t
*priv
, unsigned int offset
, u32 val
)
149 #if ACX_IO_WIDTH == 32
150 writel(val
, (u8
*)priv
->iobase
+ priv
->io
[offset
]);
152 writew(val
& 0xffff, (u8
*)priv
->iobase
+ priv
->io
[offset
]);
153 writew(val
>> 16, (u8
*)priv
->iobase
+ priv
->io
[offset
] + 2);
158 acx_write_reg16(wlandevice_t
*priv
, unsigned int offset
, u16 val
)
160 writew(val
, (u8
*)priv
->iobase
+ priv
->io
[offset
]);
164 acx_write_reg8(wlandevice_t
*priv
, unsigned int offset
, u8 val
)
166 writeb(val
, (u8
*)priv
->iobase
+ priv
->io
[offset
]);
169 /* Handle PCI posting properly:
170 * Make sure that writes reach the adapter in case they require to be executed
171 * *before* the next write, by reading a random (and safely accessible) register.
172 * This call has to be made if there is no read following (which would flush the data
173 * to the adapter), yet the written data has to reach the adapter immediately. */
175 acx_write_flush(wlandevice_t
*priv
)
177 /* readb(priv->iobase + priv->io[IO_ACX_INFO_MAILBOX_OFFS]); */
178 /* faster version (accesses the first register, IO_ACX_SOFT_RESET,
179 * which should also be safe): */
184 /***********************************************************************
186 static const char name_acx100
[] = "ACX100";
187 static const char name_tnetw1100a
[] = "TNETW1100A";
188 static const char name_tnetw1100b
[] = "TNETW1100B";
190 static const char name_acx111
[] = "ACX111";
191 static const char name_tnetw1130
[] = "TNETW1130";
193 static const struct pci_device_id
194 acx_pci_id_tbl
[] __devinitdata
= {
196 .vendor
= PCI_VENDOR_ID_TI
,
197 .device
= PCI_DEVICE_ID_TI_TNETW1100A
,
198 .subvendor
= PCI_ANY_ID
,
199 .subdevice
= PCI_ANY_ID
,
200 .driver_data
= CHIPTYPE_ACX100
,
203 .vendor
= PCI_VENDOR_ID_TI
,
204 .device
= PCI_DEVICE_ID_TI_TNETW1100B
,
205 .subvendor
= PCI_ANY_ID
,
206 .subdevice
= PCI_ANY_ID
,
207 .driver_data
= CHIPTYPE_ACX100
,
210 .vendor
= PCI_VENDOR_ID_TI
,
211 .device
= PCI_DEVICE_ID_TI_TNETW1130
,
212 .subvendor
= PCI_ANY_ID
,
213 .subdevice
= PCI_ANY_ID
,
214 .driver_data
= CHIPTYPE_ACX111
,
225 MODULE_DEVICE_TABLE(pci
, acx_pci_id_tbl
);
227 /* FIXME: checks should be removed once driver is included in the kernel */
229 #warning *** your kernel is EXTREMELY old since it does not even know about
230 #warning __devexit_p - this driver could easily FAIL to work, so better
231 #warning upgrade your kernel! ***
232 #define __devexit_p(x) x
235 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 11)
236 /* pci_name() got introduced at start of 2.6.x,
237 * got mandatory (slot_name member removed) in 2.6.11-bk1 */
238 #define pci_name(x) x->slot_name
241 static struct pci_driver acx_pci_drv_id
= {
243 .id_table
= acx_pci_id_tbl
,
244 .probe
= acx_e_probe_pci
,
245 .remove
= __devexit_p(acx_e_remove_pci
),
247 .suspend
= acx_e_suspend
,
248 .resume
= acx_e_resume
249 #endif /* CONFIG_PM */
252 typedef struct acx_device
{
256 /* if this driver was only about PCI devices, then we probably wouldn't
257 * need this linked list.
258 * But if we want to register ALL kinds of devices in one global list,
259 * then we need it and need to maintain it properly. */
260 static struct acx_device root_acx_dev
= {
263 DECLARE_MUTEX(root_acx_dev_sem
);
266 /***********************************************************************
268 static inline txdesc_t
*
269 get_txdesc(wlandevice_t
* priv
, int index
)
271 return (txdesc_t
*) (((u8
*)priv
->txdesc_start
) + index
* priv
->txdesc_size
);
274 static inline txdesc_t
*
275 move_txdesc(wlandevice_t
* priv
, txdesc_t
* txdesc
, int inc
)
277 return (txdesc_t
*) (((u8
*)txdesc
) + inc
* priv
->txdesc_size
);
281 acx_get_txhostdesc(wlandevice_t
* priv
, txdesc_t
* txdesc
)
283 int index
= (u8
*)txdesc
- (u8
*)priv
->txdesc_start
;
284 if (ACX_DEBUG
&& (index
% priv
->txdesc_size
)) {
285 printk("bad txdesc ptr %p\n", txdesc
);
288 index
/= priv
->txdesc_size
;
289 if (ACX_DEBUG
&& (index
>= TX_CNT
)) {
290 printk("bad txdesc ptr %p\n", txdesc
);
293 return &priv
->txhostdesc_start
[index
*2];
297 acx_get_txc(wlandevice_t
* priv
, txdesc_t
* txdesc
)
299 int index
= (u8
*)txdesc
- (u8
*)priv
->txdesc_start
;
300 if (ACX_DEBUG
&& (index
% priv
->txdesc_size
)) {
301 printk("bad txdesc ptr %p\n", txdesc
);
304 index
/= priv
->txdesc_size
;
305 if (ACX_DEBUG
&& (index
>= TX_CNT
)) {
306 printk("bad txdesc ptr %p\n", txdesc
);
309 return priv
->txc
[index
];
313 acx_put_txc(wlandevice_t
* priv
, txdesc_t
* txdesc
, client_t
* c
)
315 int index
= (u8
*)txdesc
- (u8
*)priv
->txdesc_start
;
316 if (ACX_DEBUG
&& (index
% priv
->txdesc_size
)) {
317 printk("bad txdesc ptr %p\n", txdesc
);
320 index
/= priv
->txdesc_size
;
321 if (ACX_DEBUG
&& (index
>= TX_CNT
)) {
322 printk("bad txdesc ptr %p\n", txdesc
);
325 priv
->txc
[index
] = c
;
328 /***********************************************************************
329 ** EEPROM and PHY read/write helpers
331 /***********************************************************************
332 ** acx_read_eeprom_offset
334 ** Function called to read an octet in the EEPROM.
336 ** This function is used by acx_probe_pci to check if the
337 ** connected card is a legal one or not.
340 ** priv ptr to wlandevice structure
341 ** addr address to read in the EEPROM
342 ** charbuf ptr to a char. This is where the read octet
349 ** NOT ADAPTED FOR ACX111!!
352 acx_read_eeprom_offset(wlandevice_t
*priv
, u32 addr
, u8
*charbuf
)
357 acx_write_reg32(priv
, IO_ACX_EEPROM_CFG
, 0);
358 acx_write_reg32(priv
, IO_ACX_EEPROM_ADDR
, addr
);
359 acx_write_flush(priv
);
360 acx_write_reg32(priv
, IO_ACX_EEPROM_CTL
, 2);
363 while (acx_read_reg16(priv
, IO_ACX_EEPROM_CTL
)) {
364 /* scheduling away instead of CPU burning loop
365 * doesn't seem to work here at all:
366 * awful delay, sometimes also failure.
367 * Doesn't matter anyway (only small delay). */
368 if (unlikely(!--count
)) {
369 printk("%s: timeout waiting for EEPROM read\n",
375 *charbuf
= acx_read_reg8(priv
, IO_ACX_EEPROM_DATA
);
376 acxlog(L_DEBUG
, "EEPROM at 0x%04X = 0x%02X\n", addr
, *charbuf
);
384 /***********************************************************************
385 ** Dummy EEPROM read? why?!
388 acx_read_eeprom_area(wlandevice_t
*priv
)
393 for (offs
= 0x8c; offs
< 0xb9; offs
++) {
394 acx_read_eeprom_offset(priv
, offs
, &tmp
[offs
- 0x8c]);
400 /***********************************************************************
401 ** We don't lock hw accesses here since we never r/w eeprom in IRQ
402 ** Note: this function sleeps only because of GFP_KERNEL alloc
406 acx_s_write_eeprom_offset(wlandevice_t
*priv
, u32 addr
, u32 len
, const u8
*charbuf
)
408 u8
*data_verify
= NULL
;
414 printk("acx: WARNING! I would write to EEPROM now. "
415 "Since I really DON'T want to unless you know "
416 "what you're doing (THIS CODE WILL PROBABLY "
417 "NOT WORK YET!), I will abort that now. And "
418 "definitely make sure to make a "
419 "/proc/driver/acx_wlan0_eeprom backup copy first!!! "
420 "(the EEPROM content includes the PCI config header!! "
421 "If you kill important stuff, then you WILL "
422 "get in trouble and people DID get in trouble already)\n");
427 data_verify
= kmalloc(len
, GFP_KERNEL
);
432 /* first we need to enable the OE (EEPROM Output Enable) GPIO line
433 * to be able to write to the EEPROM.
434 * NOTE: an EEPROM writing success has been reported,
435 * but you probably have to modify GPIO_OUT, too,
436 * and you probably need to activate a different GPIO
438 gpio_orig
= acx_read_reg16(priv
, IO_ACX_GPIO_OE
);
439 acx_write_reg16(priv
, IO_ACX_GPIO_OE
, gpio_orig
& ~1);
440 acx_write_flush(priv
);
442 /* ok, now start writing the data out */
443 for (i
= 0; i
< len
; i
++) {
444 acx_write_reg32(priv
, IO_ACX_EEPROM_CFG
, 0);
445 acx_write_reg32(priv
, IO_ACX_EEPROM_ADDR
, addr
+ i
);
446 acx_write_reg32(priv
, IO_ACX_EEPROM_DATA
, *(charbuf
+ i
));
447 acx_write_flush(priv
);
448 acx_write_reg32(priv
, IO_ACX_EEPROM_CTL
, 1);
450 while (acx_read_reg16(priv
, IO_ACX_EEPROM_CTL
)) {
451 if (unlikely(++count
> 0xffff)) {
452 printk("WARNING, DANGER!!! "
453 "Timeout waiting for EEPROM write\n");
459 /* disable EEPROM writing */
460 acx_write_reg16(priv
, IO_ACX_GPIO_OE
, gpio_orig
);
461 acx_write_flush(priv
);
463 /* now start a verification run */
465 for (i
= 0; i
< len
; i
++) {
466 acx_write_reg32(priv
, IO_ACX_EEPROM_CFG
, 0);
467 acx_write_reg32(priv
, IO_ACX_EEPROM_ADDR
, addr
+ i
);
468 acx_write_flush(priv
);
469 acx_write_reg32(priv
, IO_ACX_EEPROM_CTL
, 2);
471 while (acx_read_reg16(priv
, IO_ACX_EEPROM_CTL
)) {
472 if (unlikely(!--count
)) {
473 printk("timeout waiting for EEPROM read\n");
478 data_verify
[i
] = acx_read_reg16(priv
, IO_ACX_EEPROM_DATA
);
481 if (0 == memcmp(charbuf
, data_verify
, len
))
482 result
= OK
; /* read data matches, success */
492 /***********************************************************************
493 ** acxpci_s_read_phy_reg
495 ** Messing with rx/tx disabling and enabling here
496 ** (acx_write_reg32(priv, IO_ACX_ENABLE, 0b000000xx)) kills traffic
499 acxpci_s_read_phy_reg(wlandevice_t
*priv
, u32 reg
, u8
*charbuf
)
506 acx_write_reg32(priv
, IO_ACX_PHY_ADDR
, reg
);
507 acx_write_flush(priv
);
508 acx_write_reg32(priv
, IO_ACX_PHY_CTL
, 2);
511 while (acx_read_reg32(priv
, IO_ACX_PHY_CTL
)) {
512 /* scheduling away instead of CPU burning loop
513 * doesn't seem to work here at all:
514 * awful delay, sometimes also failure.
515 * Doesn't matter anyway (only small delay). */
516 if (unlikely(!--count
)) {
517 printk("%s: timeout waiting for phy read\n",
524 acxlog(L_DEBUG
, "count was %u\n", count
);
525 *charbuf
= acx_read_reg8(priv
, IO_ACX_PHY_DATA
);
527 acxlog(L_DEBUG
, "radio PHY at 0x%04X = 0x%02X\n", *charbuf
, reg
);
529 goto fail
; /* silence compiler warning */
536 /***********************************************************************
539 acxpci_s_write_phy_reg(wlandevice_t
*priv
, u32 reg
, u8 value
)
543 /* FIXME: we didn't use 32bit access here since mprusko said that
544 * it results in distorted sensitivity on his card (huh!?!?
545 * doesn't happen with my setup...)
546 * But with the access reordering and flushing it
547 * shouldn't happen any more...
548 * FIXME: which radio is in the problematic card? My working one
550 acx_write_reg32(priv
, IO_ACX_PHY_DATA
, value
);
551 acx_write_reg32(priv
, IO_ACX_PHY_ADDR
, reg
);
552 acx_write_flush(priv
);
553 acx_write_reg32(priv
, IO_ACX_PHY_CTL
, 1);
554 acx_write_flush(priv
);
555 acxlog(L_DEBUG
, "radio PHY write 0x%02X at 0x%04X\n", value
, reg
);
562 #define NO_AUTO_INCREMENT 1
564 /***********************************************************************
567 ** Write the firmware image into the card.
570 ** priv wlan device structure
571 ** apfw_image firmware image.
574 ** 1 firmware image corrupted
578 acx_s_write_fw(wlandevice_t
*priv
, const firmware_image_t
*apfw_image
, u32 offset
)
582 /* we skip the first four bytes which contain the control sum */
583 const u8
*image
= (u8
*)apfw_image
+ 4;
585 /* start the image checksum by adding the image size value */
586 sum
= image
[0]+image
[1]+image
[2]+image
[3];
589 acx_write_reg32(priv
, IO_ACX_SLV_END_CTL
, 0);
591 #if NO_AUTO_INCREMENT
592 acxlog(L_INIT
, "not using auto increment for firmware loading\n");
593 acx_write_reg32(priv
, IO_ACX_SLV_MEM_CTL
, 0); /* use basic mode */
595 acx_write_reg32(priv
, IO_ACX_SLV_MEM_CTL
, 1); /* use autoincrement mode */
596 acx_write_reg32(priv
, IO_ACX_SLV_MEM_ADDR
, offset
); /* configure start address */
597 acx_write_flush(priv
);
601 size
= le32_to_cpu(apfw_image
->size
) & (~3);
603 while (likely(len
< size
)) {
604 v32
= be32_to_cpu(*(u32
*)image
);
605 sum
+= image
[0]+image
[1]+image
[2]+image
[3];
609 #if NO_AUTO_INCREMENT
610 acx_write_reg32(priv
, IO_ACX_SLV_MEM_ADDR
, offset
+ len
- 4);
611 acx_write_flush(priv
);
613 acx_write_reg32(priv
, IO_ACX_SLV_MEM_DATA
, v32
);
616 acxlog(L_DEBUG
, "firmware written, size:%d sum1:%x sum2:%x\n",
617 size
, sum
, le32_to_cpu(apfw_image
->chksum
));
619 /* compare our checksum with the stored image checksum */
620 return (sum
!= le32_to_cpu(apfw_image
->chksum
));
624 /***********************************************************************
627 ** Compare the firmware image given with
628 ** the firmware image written into the card.
631 ** priv wlan device structure
632 ** apfw_image firmware image.
635 ** NOT_OK firmware image corrupted or not correctly written
639 acx_s_validate_fw(wlandevice_t
*priv
, const firmware_image_t
*apfw_image
,
645 /* we skip the first four bytes which contain the control sum */
646 const u8
*image
= (u8
*)apfw_image
+ 4;
648 /* start the image checksum by adding the image size value */
649 sum
= image
[0]+image
[1]+image
[2]+image
[3];
652 acx_write_reg32(priv
, IO_ACX_SLV_END_CTL
, 0);
654 #if NO_AUTO_INCREMENT
655 acx_write_reg32(priv
, IO_ACX_SLV_MEM_CTL
, 0); /* use basic mode */
657 acx_write_reg32(priv
, IO_ACX_SLV_MEM_CTL
, 1); /* use autoincrement mode */
658 acx_write_reg32(priv
, IO_ACX_SLV_MEM_ADDR
, offset
); /* configure start address */
662 size
= le32_to_cpu(apfw_image
->size
) & (~3);
664 while (likely(len
< size
)) {
665 v32
= be32_to_cpu(*(u32
*)image
);
669 #if NO_AUTO_INCREMENT
670 acx_write_reg32(priv
, IO_ACX_SLV_MEM_ADDR
, offset
+ len
- 4);
672 w32
= acx_read_reg32(priv
, IO_ACX_SLV_MEM_DATA
);
674 if (unlikely(w32
!= v32
)) {
675 printk("acx: FATAL: firmware upload: "
676 "data parts at offset %d don't match (0x%08X vs. 0x%08X)! "
677 "I/O timing issues or defective memory, with DWL-xx0+? "
678 "ACX_IO_WIDTH=16 may help. Please report\n",
684 sum
+= (u8
)w32
+ (u8
)(w32
>>8) + (u8
)(w32
>>16) + (u8
)(w32
>>24);
687 /* sum control verification */
688 if (result
!= NOT_OK
) {
689 if (sum
!= le32_to_cpu(apfw_image
->chksum
)) {
690 printk("acx: FATAL: firmware upload: "
691 "checksums don't match!\n");
700 /***********************************************************************
704 ** wlandevice: private device that contains card device
712 acx_s_upload_fw(wlandevice_t
*priv
)
714 firmware_image_t
*apfw_image
= NULL
;
718 char filename
[sizeof("tiacx1NNcNN")];
722 /* Try combined, then main image */
723 priv
->need_radio_fw
= 0;
724 sprintf(filename
, "tiacx1%02dc%02X",
725 IS_ACX111(priv
)*11, priv
->radio_type
);
727 apfw_image
= acx_s_read_fw(&priv
->pdev
->dev
, filename
, &size
);
729 priv
->need_radio_fw
= 1;
730 filename
[sizeof("tiacx1NN")-1] = '\0';
731 apfw_image
= acx_s_read_fw(&priv
->pdev
->dev
, filename
, &size
);
738 for (try = 1; try <= 5; try++) {
739 res
= acx_s_write_fw(priv
, apfw_image
, 0);
740 acxlog(L_DEBUG
|L_INIT
, "acx_write_fw (main/combined):%d\n", res
);
742 res
= acx_s_validate_fw(priv
, apfw_image
, 0);
743 acxlog(L_DEBUG
|L_INIT
, "acx_validate_fw "
744 "(main/combined):%d\n", res
);
748 SET_BIT(priv
->dev_state_mask
, ACX_STATE_FW_LOADED
);
751 printk("acx: firmware upload attempt #%d FAILED, "
752 "retrying...\n", try);
753 acx_s_msleep(1000); /* better wait for a while... */
763 /***********************************************************************
764 ** acx_s_upload_radio
766 ** Uploads the appropriate radio module firmware
770 acx_s_upload_radio(wlandevice_t
*priv
)
773 firmware_image_t
*radio_image
= NULL
;
774 acx_cmd_radioinit_t radioinit
;
779 char filename
[sizeof("tiacx1NNrNN")];
781 if (!priv
->need_radio_fw
) return OK
;
785 acx_s_interrogate(priv
, &mm
, ACX1xx_IE_MEMORY_MAP
);
786 offset
= le32_to_cpu(mm
.CodeEnd
);
788 sprintf(filename
, "tiacx1%02dr%02X",
791 radio_image
= acx_s_read_fw(&priv
->pdev
->dev
, filename
, &size
);
793 printk("acx: can't load radio module '%s'\n", filename
);
797 acx_s_issue_cmd(priv
, ACX1xx_CMD_SLEEP
, NULL
, 0);
799 for (try = 1; try <= 5; try++) {
800 res
= acx_s_write_fw(priv
, radio_image
, offset
);
801 acxlog(L_DEBUG
|L_INIT
, "acx_write_fw (radio): %d\n", res
);
803 res
= acx_s_validate_fw(priv
, radio_image
, offset
);
804 acxlog(L_DEBUG
|L_INIT
, "acx_validate_fw (radio): %d\n", res
);
809 printk("acx: radio firmware upload attempt #%d FAILED, "
810 "retrying...\n", try);
811 acx_s_msleep(1000); /* better wait for a while... */
814 acx_s_issue_cmd(priv
, ACX1xx_CMD_WAKE
, NULL
, 0);
815 radioinit
.offset
= cpu_to_le32(offset
);
816 /* no endian conversion needed, remains in card CPU area: */
817 radioinit
.len
= radio_image
->size
;
824 /* will take a moment so let's have a big timeout */
825 acx_s_issue_cmd_timeo(priv
, ACX1xx_CMD_RADIOINIT
,
826 &radioinit
, sizeof(radioinit
), CMD_TIMEOUT_MS(1000));
828 res
= acx_s_interrogate(priv
, &mm
, ACX1xx_IE_MEMORY_MAP
);
835 /***********************************************************************
839 ** wlandevice: private device that contains card device
845 ** resets onboard acx100 MAC
847 ** Requires lock to be taken
850 acx_l_reset_mac(wlandevice_t
*priv
)
857 temp
= acx_read_reg16(priv
, IO_ACX_ECPU_CTRL
) | 0x1;
858 acx_write_reg16(priv
, IO_ACX_ECPU_CTRL
, temp
);
860 /* now do soft reset of eCPU */
861 temp
= acx_read_reg16(priv
, IO_ACX_SOFT_RESET
) | 0x1;
862 acxlog(L_DEBUG
, "%s: enable soft reset...\n", __func__
);
863 acx_write_reg16(priv
, IO_ACX_SOFT_RESET
, temp
);
864 acx_write_flush(priv
);
866 /* now reset bit again */
867 acxlog(L_DEBUG
, "%s: disable soft reset and go to init mode...\n", __func__
);
868 /* deassert eCPU reset */
869 acx_write_reg16(priv
, IO_ACX_SOFT_RESET
, temp
& ~0x1);
871 /* now start a burst read from initial flash EEPROM */
872 temp
= acx_read_reg16(priv
, IO_ACX_EE_START
) | 0x1;
873 acx_write_reg16(priv
, IO_ACX_EE_START
, temp
);
874 acx_write_flush(priv
);
880 /***********************************************************************
884 acx_s_verify_init(wlandevice_t
*priv
)
891 for (timer
= 40; timer
> 0; timer
--) {
892 u16 irqstat
= acx_read_reg16(priv
, IO_ACX_IRQ_STATUS_NON_DES
);
893 if (irqstat
& HOST_INT_FCS_THRESHOLD
) {
895 acx_write_reg16(priv
, IO_ACX_IRQ_ACK
, HOST_INT_FCS_THRESHOLD
);
898 /* HZ / 50 resulted in 24 schedules for ACX100 on my machine,
899 * so better schedule away longer for greater efficiency,
900 * decrease loop count */
909 /***********************************************************************
910 ** A few low-level helpers
912 ** Note: these functions are not protected by lock
913 ** and thus are never allowed to be called from IRQ.
914 ** Also they must not race with fw upload which uses same hw regs
917 /***********************************************************************
918 ** acx_read_info_status
920 /* Info mailbox format:
923 more bytes may follow
924 docs say about status:
925 0x0000 info available (set by hw)
926 0x0001 information received (must be set by host)
927 0x1000 info available, mailbox overflowed (messages lost) (set by hw)
928 but in practice we've seen:
929 0x9000 when we did not set status to 0x0001 on prev message
930 0x1001 when we did set it
931 0x0000 was never seen
932 conclusion: this is really a bitfield:
933 0x1000 is 'info available' bit
934 'mailbox overflowed' bit is 0x8000, not 0x1000
935 value of 0x0000 probably means that there is no message at all
936 P.S. I dunno how in hell hw is supposed to notice that messages are lost -
937 it does NOT clear bit 0x0001, and this bit will probably stay forever set
938 after we set it once. Let's hope this will be fixed in firmware someday
941 acx_read_info_status(wlandevice_t
*priv
)
945 acx_write_reg32(priv
, IO_ACX_SLV_END_CTL
, 0x0);
946 acx_write_reg32(priv
, IO_ACX_SLV_MEM_CTL
, 0x1);
948 acx_write_reg32(priv
, IO_ACX_SLV_MEM_ADDR
,
949 acx_read_reg32(priv
, IO_ACX_INFO_MAILBOX_OFFS
));
951 /* make sure we only read the data once all cfg registers are written: */
952 acx_write_flush(priv
);
953 value
= acx_read_reg32(priv
, IO_ACX_SLV_MEM_DATA
);
955 priv
->info_type
= (u16
)value
;
956 priv
->info_status
= (value
>> 16);
958 /* inform hw that we have read this info message */
959 acx_write_reg32(priv
, IO_ACX_SLV_MEM_DATA
, priv
->info_type
| 0x00010000);
960 acx_write_flush(priv
);
961 /* now bother hw to notice it: */
962 acx_write_reg16(priv
, IO_ACX_INT_TRIG
, INT_TRIG_INFOACK
);
963 acx_write_flush(priv
);
965 acxlog(L_CTL
, "info_type 0x%04X, info_status 0x%04X\n",
966 priv
->info_type
, priv
->info_status
);
970 /***********************************************************************
971 ** acx_write_cmd_type_or_status
974 acx_write_cmd_type_or_status(wlandevice_t
*priv
, u32 val
)
976 acx_write_reg32(priv
, IO_ACX_SLV_END_CTL
, 0x0);
977 acx_write_reg32(priv
, IO_ACX_SLV_MEM_CTL
, 0x1); /* FIXME: why auto increment?? */
979 acx_write_reg32(priv
, IO_ACX_SLV_MEM_ADDR
,
980 acx_read_reg32(priv
, IO_ACX_CMD_MAILBOX_OFFS
));
982 /* make sure we only write the data once all config registers are written */
983 acx_write_flush(priv
);
984 acx_write_reg32(priv
, IO_ACX_SLV_MEM_DATA
, val
);
985 acx_write_flush(priv
);
988 acx_write_cmd_type(wlandevice_t
*priv
, u32 val
)
990 acx_write_cmd_type_or_status(priv
, val
);
993 acx_write_cmd_status(wlandevice_t
*priv
, u32 val
)
995 acx_write_cmd_type_or_status(priv
, val
<<16);
999 /***********************************************************************
1000 ** acx_read_cmd_status
1003 acx_read_cmd_status(wlandevice_t
*priv
)
1007 acx_write_reg32(priv
, IO_ACX_SLV_END_CTL
, 0x0);
1008 acx_write_reg32(priv
, IO_ACX_SLV_MEM_CTL
, 0x1); /* FIXME: why auto increment?? */
1010 acx_write_reg32(priv
, IO_ACX_SLV_MEM_ADDR
,
1011 acx_read_reg32(priv
, IO_ACX_CMD_MAILBOX_OFFS
));
1013 /* make sure we only read the data once all config registers are written */
1014 acx_write_flush(priv
);
1015 value
= acx_read_reg32(priv
, IO_ACX_SLV_MEM_DATA
);
1017 priv
->cmd_type
= (u16
)value
;
1018 priv
->cmd_status
= (value
>> 16);
1020 acxlog(L_CTL
, "cmd_type 0x%04X, cmd_status 0x%04X [%s]\n",
1021 priv
->cmd_type
, priv
->cmd_status
,
1022 acx_cmd_status_str(priv
->cmd_status
));
1026 /***********************************************************************
1030 ** netdevice that contains the wlandevice priv variable
1035 ** device is hard reset
1039 ** This resets the acx100 device using low level hardware calls
1040 ** as well as uploads and verifies the firmware to the card
1043 acx_s_reset_dev(netdevice_t
*dev
)
1045 wlandevice_t
*priv
= netdev_priv(dev
);
1046 const char* msg
= "";
1047 unsigned long flags
;
1048 int result
= NOT_OK
;
1054 /* we're doing a reset, so hardware is unavailable */
1056 /* reset the device to make sure the eCPU is stopped
1057 * to upload the firmware correctly */
1059 acx_lock(priv
, flags
);
1061 acx_l_reset_mac(priv
);
1063 ecpu_ctrl
= acx_read_reg16(priv
, IO_ACX_ECPU_CTRL
) & 1;
1065 msg
= "eCPU is already running. ";
1069 #ifdef WE_DONT_NEED_THAT_DO_WE
1070 if (acx_read_reg16(priv
, IO_ACX_SOR_CFG
) & 2) {
1071 /* eCPU most likely means "embedded CPU" */
1072 msg
= "eCPU did not start after boot from flash. ";
1076 /* check sense on reset flags */
1077 if (acx_read_reg16(priv
, IO_ACX_SOR_CFG
) & 0x10) {
1078 printk("%s: eCPU did not start after boot (SOR), "
1079 "is this fatal?\n", dev
->name
);
1082 /* scan, if any, is stopped now, setting corresponding IRQ bit */
1083 priv
->irq_status
|= HOST_INT_SCAN_COMPLETE
;
1085 acx_unlock(priv
, flags
);
1087 /* without this delay acx100 may fail to report hardware_info
1088 ** (see below). Most probably eCPU runs some init code */
1091 /* Need to know radio type before fw load */
1092 hardware_info
= acx_read_reg16(priv
, IO_ACX_EEPROM_INFORMATION
);
1093 priv
->form_factor
= hardware_info
& 0xff;
1094 priv
->radio_type
= hardware_info
>> 8;
1096 /* load the firmware */
1097 if (OK
!= acx_s_upload_fw(priv
))
1102 /* now start eCPU by clearing bit */
1103 acxlog(L_DEBUG
, "booted eCPU up and waiting for completion...\n");
1104 acx_write_reg16(priv
, IO_ACX_ECPU_CTRL
, ecpu_ctrl
& ~0x1);
1106 /* wait for eCPU bootup */
1107 if (OK
!= acx_s_verify_init(priv
)) {
1108 msg
= "timeout waiting for eCPU. ";
1112 acxlog(L_DEBUG
, "eCPU has woken up, card is ready to be configured\n");
1114 if (IS_ACX111(priv
)) {
1115 acxlog(L_DEBUG
, "cleaning up cmd mailbox access area\n");
1116 acx_write_cmd_status(priv
, 0);
1117 acx_read_cmd_status(priv
);
1118 if (priv
->cmd_status
) {
1119 msg
= "error cleaning cmd mailbox area. ";
1124 /* TODO what is this one doing ?? adapt for acx111 */
1125 if ((OK
!= acx_read_eeprom_area(priv
)) && IS_ACX100(priv
)) {
1126 /* does "CIS" mean "Card Information Structure"?
1127 * If so, then this would be a PCMCIA message...
1129 msg
= "CIS error. ";
1137 /* Finish error message. Indicate which function failed */
1139 acx_unlock(priv
, flags
);
1141 printk("acx: %sreset_dev() FAILED\n", msg
);
1147 /***********************************************************************
1151 acx_init_mboxes(wlandevice_t
*priv
)
1153 u32 cmd_offs
, info_offs
;
1157 cmd_offs
= acx_read_reg32(priv
, IO_ACX_CMD_MAILBOX_OFFS
);
1158 info_offs
= acx_read_reg32(priv
, IO_ACX_INFO_MAILBOX_OFFS
);
1159 priv
->cmd_area
= (u8
*)priv
->iobase2
+ cmd_offs
+ 0x4;
1160 priv
->info_area
= (u8
*)priv
->iobase2
+ info_offs
+ 0x4;
1161 acxlog(L_DEBUG
, "iobase2=%p\n"
1162 "cmd_mbox_offset=%X cmd_area=%p\n"
1163 "info_mbox_offset=%X info_area=%p\n",
1165 cmd_offs
, priv
->cmd_area
,
1166 info_offs
, priv
->info_area
);
1172 /***********************************************************************
1173 ** acx_s_issue_cmd_timeo
1175 ** Sends command to fw, extract result
1177 ** NB: we do _not_ take lock inside, so be sure to not touch anything
1178 ** which may interfere with IRQ handler operation
1180 ** TODO: busy wait is a bit silly, so:
1181 ** 1) stop doing many iters - go to sleep after first
1182 ** 2) go to waitqueue based approach: wait, not poll!
1185 #define FUNC "issue_cmd"
1189 acxpci_s_issue_cmd_timeo(
1198 acxpci_s_issue_cmd_timeo_debug(
1206 unsigned long start
= jiffies
;
1208 const char *devname
;
1215 devname
= priv
->netdev
->name
;
1216 if (!devname
|| !devname
[0])
1219 acxlog(L_CTL
, FUNC
"(cmd:%s,buflen:%u,timeout:%ums,type:0x%04X)\n",
1220 cmdstr
, buflen
, timeout
,
1221 buffer
? le16_to_cpu(((acx_ie_generic_t
*)buffer
)->type
) : -1);
1223 if (!(priv
->dev_state_mask
& ACX_STATE_FW_LOADED
)) {
1224 printk("%s: "FUNC
"(): firmware is not loaded yet, "
1225 "cannot execute commands!\n", devname
);
1229 if ((acx_debug
& L_DEBUG
) && (cmd
!= ACX1xx_CMD_INTERROGATE
)) {
1230 printk("input pdr (len=%u):\n", buflen
);
1231 acx_dump_bytes(buffer
, buflen
);
1234 /* wait for firmware to become idle for our command submission */
1235 counter
= 199; /* in ms */
1237 acx_read_cmd_status(priv
);
1238 /* Test for IDLE state */
1239 if (!priv
->cmd_status
)
1241 if (counter
% 10 == 0) {
1242 /* we waited 10 iterations, no luck. Sleep 10 ms */
1245 } while (--counter
);
1248 /* the card doesn't get idle, we're in trouble */
1249 printk("%s: "FUNC
"(): cmd_status is not IDLE: 0x%04X!=0\n",
1250 devname
, priv
->cmd_status
);
1252 } else if (counter
< 190) { /* if waited >10ms... */
1253 acxlog(L_CTL
|L_DEBUG
, FUNC
"(): waited for IDLE %dms. "
1254 "Please report\n", 199 - counter
);
1257 /* now write the parameters of the command if needed */
1258 if (buffer
&& buflen
) {
1259 /* if it's an INTERROGATE command, just pass the length
1260 * of parameters to read, as data */
1262 if (cmd
== ACX1xx_CMD_INTERROGATE
)
1263 memset(priv
->cmd_area
, 0xAA, buflen
);
1265 memcpy(priv
->cmd_area
, buffer
,
1266 (cmd
== ACX1xx_CMD_INTERROGATE
) ? 4 : buflen
);
1268 /* now write the actual command type */
1269 priv
->cmd_type
= cmd
;
1270 acx_write_cmd_type(priv
, cmd
);
1271 /* execute command */
1272 acx_write_reg16(priv
, IO_ACX_INT_TRIG
, INT_TRIG_CMD
);
1273 acx_write_flush(priv
);
1275 /* wait for firmware to process command */
1277 /* Ensure nonzero and not too large timeout.
1278 ** Also converts e.g. 100->99, 200->199
1279 ** which is nice but not essential */
1280 timeout
= (timeout
-1) | 1;
1281 if (unlikely(timeout
> 1199))
1283 /* clear CMD_COMPLETE bit. can be set only by IRQ handler: */
1284 priv
->irq_status
&= ~HOST_INT_CMD_COMPLETE
;
1286 /* we schedule away sometimes (timeout can be large) */
1289 if (!priv
->irqs_active
) { /* IRQ disabled: poll */
1290 irqtype
= acx_read_reg16(priv
, IO_ACX_IRQ_STATUS_NON_DES
);
1291 if (irqtype
& HOST_INT_CMD_COMPLETE
) {
1292 acx_write_reg16(priv
, IO_ACX_IRQ_ACK
,
1293 HOST_INT_CMD_COMPLETE
);
1296 } else { /* Wait when IRQ will set the bit */
1297 irqtype
= priv
->irq_status
;
1298 if (irqtype
& HOST_INT_CMD_COMPLETE
)
1302 if (counter
% 10 == 0) {
1303 /* we waited 10 iterations, no luck. Sleep 10 ms */
1306 } while (--counter
);
1308 /* save state for debugging */
1309 acx_read_cmd_status(priv
);
1310 cmd_status
= priv
->cmd_status
;
1312 /* put the card in IDLE state */
1313 priv
->cmd_status
= 0;
1314 acx_write_cmd_status(priv
, 0);
1316 if (!counter
) { /* timed out! */
1317 printk("%s: "FUNC
"(): timed out %s for CMD_COMPLETE. "
1318 "irq bits:0x%04X irq_status:0x%04X timeout:%dms "
1319 "cmd_status:%d (%s)\n",
1320 devname
, (priv
->irqs_active
) ? "waiting" : "polling",
1321 irqtype
, priv
->irq_status
, timeout
,
1322 cmd_status
, acx_cmd_status_str(cmd_status
));
1324 } else if (timeout
- counter
> 30) { /* if waited >30ms... */
1325 acxlog(L_CTL
|L_DEBUG
, FUNC
"(): %s for CMD_COMPLETE %dms. "
1326 "count:%d. Please report\n",
1327 (priv
->irqs_active
) ? "waited" : "polled",
1328 timeout
- counter
, counter
);
1331 if (1 != cmd_status
) { /* it is not a 'Success' */
1332 printk("%s: "FUNC
"(): cmd_status is not SUCCESS: %d (%s). "
1333 "Took %dms of %d\n",
1334 devname
, cmd_status
, acx_cmd_status_str(cmd_status
),
1335 timeout
- counter
, timeout
);
1336 /* zero out result buffer */
1337 if (buffer
&& buflen
)
1338 memset(buffer
, 0, buflen
);
1342 /* read in result parameters if needed */
1343 if (buffer
&& buflen
&& (cmd
== ACX1xx_CMD_INTERROGATE
)) {
1344 memcpy(buffer
, priv
->cmd_area
, buflen
);
1345 if (acx_debug
& L_DEBUG
) {
1346 printk("output buffer (len=%u): ", buflen
);
1347 acx_dump_bytes(buffer
, buflen
);
1351 acxlog(L_CTL
, FUNC
"(%s): took %ld jiffies to complete\n",
1352 cmdstr
, jiffies
- start
);
1357 /* Give enough info so that callers can avoid
1358 ** printing their own diagnostic messages */
1360 printk("%s: "FUNC
"(cmd:%s) FAILED\n", devname
, cmdstr
);
1362 printk("%s: "FUNC
"(cmd:0x%04X) FAILED\n", devname
, cmd
);
1370 /***********************************************************************
1371 ** acx_s_get_firmware_version
1374 acx_s_get_firmware_version(wlandevice_t
*priv
)
1377 u8 hexarr
[4] = { 0, 0, 0, 0 };
1378 int hexidx
= 0, val
= 0;
1384 acx_s_interrogate(priv
, &fw
, ACX1xx_IE_FWREV
);
1385 memcpy(priv
->firmware_version
, fw
.fw_id
, FW_ID_SIZE
);
1386 priv
->firmware_version
[FW_ID_SIZE
] = '\0';
1387 acxlog(L_DEBUG
, "fw_ver: fw_id='%s' hw_id=%08X\n",
1388 priv
->firmware_version
, fw
.hw_id
);
1390 if (strncmp(fw
.fw_id
, "Rev ", 4) != 0) {
1391 printk("acx: strange firmware version string "
1392 "'%s', please report\n", priv
->firmware_version
);
1393 priv
->firmware_numver
= 0x01090407; /* assume 1.9.4.7 */
1398 if ((c
== '.') || (c
== '\0')) {
1399 hexarr
[hexidx
++] = val
;
1400 if ((hexidx
> 3) || (c
== '\0')) /* end? */
1405 if ((c
>= '0') && (c
<= '9'))
1408 c
= c
- 'a' + (char)10;
1412 priv
->firmware_numver
= (u32
)(
1413 (hexarr
[0] << 24) + (hexarr
[1] << 16)
1414 + (hexarr
[2] << 8) + hexarr
[3]);
1415 acxlog(L_DEBUG
, "firmware_numver 0x%08X\n", priv
->firmware_numver
);
1417 if (IS_ACX111(priv
)) {
1418 if (priv
->firmware_numver
== 0x00010011) {
1419 /* This one does not survive floodpinging */
1420 printk("acx: firmware '%s' is known to be buggy, "
1421 "please upgrade\n", priv
->firmware_version
);
1423 if (priv
->firmware_numver
== 0x02030131) {
1424 /* With this one, all rx packets look mangled
1425 ** Most probably we simply do not know how to use it
1427 printk("acx: firmware '%s' does not work well "
1428 "with this driver\n", priv
->firmware_version
);
1432 priv
->firmware_id
= le32_to_cpu(fw
.hw_id
);
1434 /* we're able to find out more detailed chip names now */
1435 switch (priv
->firmware_id
& 0xffff0000) {
1438 priv
->chip_name
= name_tnetw1100a
;
1441 priv
->chip_name
= name_tnetw1100b
;
1445 priv
->chip_name
= name_tnetw1130
;
1448 printk("acx: unknown chip ID 0x%08X, "
1449 "please report\n", priv
->firmware_id
);
1457 /***********************************************************************
1458 ** acx_display_hardware_details
1460 ** Displays hw/fw version, radio type etc...
1463 acx_display_hardware_details(wlandevice_t
*priv
)
1465 const char *radio_str
, *form_str
;
1469 switch (priv
->radio_type
) {
1470 case RADIO_MAXIM_0D
:
1471 /* hmm, the DWL-650+ seems to have two variants,
1472 * according to a windows driver changelog comment:
1473 * RFMD and Maxim. */
1474 radio_str
= "Maxim";
1479 case RADIO_RALINK_15
:
1480 radio_str
= "Ralink";
1482 case RADIO_RADIA_16
:
1483 radio_str
= "Radia";
1485 case RADIO_UNKNOWN_17
:
1486 /* TI seems to have a radio which is
1487 * additionally 802.11a capable, too */
1488 radio_str
= "802.11a/b/g radio?! Please report";
1490 case RADIO_UNKNOWN_19
:
1491 radio_str
= "A radio used by Safecom cards?! Please report";
1494 radio_str
= "UNKNOWN, please report the radio type name!";
1498 switch (priv
->form_factor
) {
1500 form_str
= "unspecified";
1503 form_str
= "(mini-)PCI / CardBus";
1509 form_str
= "Compact Flash";
1512 form_str
= "UNKNOWN, Please report";
1516 printk("acx: form factor 0x%02X (%s), "
1517 "radio type 0x%02X (%s), EEPROM version 0x%02X, "
1518 "uploaded firmware '%s' (0x%08X)\n",
1519 priv
->form_factor
, form_str
, priv
->radio_type
, radio_str
,
1520 priv
->eeprom_version
, priv
->firmware_version
,
1526 /***********************************************************************
1528 #ifdef NONESSENTIAL_FEATURES
1529 typedef struct device_id
{
1530 unsigned char id
[6];
1535 static const device_id_t
1539 {'G', 'l', 'o', 'b', 'a', 'l'},
1544 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
1546 "SpeedStream SS1021 or Gigafast WF721-AEX"
1549 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85},
1554 {'?', '?', '?', '?', '?', '?'},
1556 "Level One WPC-0200"
1559 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1566 acx_show_card_eeprom_id(wlandevice_t
*priv
)
1568 unsigned char buffer
[CARD_EEPROM_ID_SIZE
];
1571 memset(&buffer
, 0, CARD_EEPROM_ID_SIZE
);
1572 /* use direct EEPROM access */
1573 for (i
= 0; i
< CARD_EEPROM_ID_SIZE
; i
++) {
1574 if (OK
!= acx_read_eeprom_offset(priv
,
1575 ACX100_EEPROM_ID_OFFSET
+ i
,
1578 printk("acx: reading EEPROM FAILED\n");
1583 for (i
= 0; i
< VEC_SIZE(device_ids
); i
++) {
1584 if (!memcmp(&buffer
, device_ids
[i
].id
, CARD_EEPROM_ID_SIZE
)) {
1585 if (device_ids
[i
].descr
) {
1586 printk("acx: EEPROM card ID string check "
1587 "found %s card ID: is this %s?\n",
1588 device_ids
[i
].descr
, device_ids
[i
].type
);
1593 if (i
== VEC_SIZE(device_ids
)) {
1594 printk("acx: EEPROM card ID string check found "
1595 "unknown card: expected 'Global', got '%.*s\'. "
1596 "Please report\n", CARD_EEPROM_ID_SIZE
, buffer
);
1599 #endif /* NONESSENTIAL_FEATURES */
1602 /***********************************************************************
1605 acx_s_device_chain_add(struct net_device
*dev
)
1607 wlandevice_t
*priv
= netdev_priv(dev
);
1609 down(&root_acx_dev_sem
);
1610 priv
->prev_nd
= root_acx_dev
.newest
;
1611 root_acx_dev
.newest
= dev
;
1613 up(&root_acx_dev_sem
);
1617 acx_s_device_chain_remove(struct net_device
*dev
)
1619 struct net_device
*querydev
;
1620 struct net_device
*olderdev
;
1621 struct net_device
*newerdev
;
1623 down(&root_acx_dev_sem
);
1624 querydev
= root_acx_dev
.newest
;
1627 olderdev
= ((wlandevice_t
*)netdev_priv(querydev
))->prev_nd
;
1628 if (0 == strcmp(querydev
->name
, dev
->name
)) {
1630 /* if we were at the beginning of the
1631 * list, then it's the list head that
1632 * we need to update to point at the
1633 * next older device */
1634 root_acx_dev
.newest
= olderdev
;
1636 /* it's the device that is newer than us
1637 * that we need to update to point at
1638 * the device older than us */
1639 ((wlandevice_t
*)netdev_priv(newerdev
))->
1644 /* "newerdev" is actually the device of the old iteration,
1645 * but since the list starts (root_acx_dev.newest)
1646 * with the newest devices,
1647 * it's newer than the ones following.
1648 * Oh the joys of iterating from newest to oldest :-\ */
1649 newerdev
= querydev
;
1651 /* keep checking old devices for matches until we hit the end
1653 querydev
= olderdev
;
1655 up(&root_acx_dev_sem
);
1659 /***********************************************************************
1660 ** acx_free_desc_queues
1662 ** Releases the queues that have been allocated, the
1663 ** others have been initialised to NULL so this
1664 ** function can be used if only part of the queues were allocated.
1667 acx_free_coherent(struct pci_dev
*hwdev
, size_t size
,
1668 void *vaddr
, dma_addr_t dma_handle
)
1670 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 53)
1671 dma_free_coherent(hwdev
== NULL
? NULL
: &hwdev
->dev
,
1672 size
, vaddr
, dma_handle
);
1674 pci_free_consistent(hwdev
, size
, vaddr
, dma_handle
);
1679 acx_free_desc_queues(wlandevice_t
*priv
)
1681 #define ACX_FREE_QUEUE(size, ptr, phyaddr) \
1683 acx_free_coherent(0, size, ptr, phyaddr); \
1690 ACX_FREE_QUEUE(priv
->txhostdesc_area_size
, priv
->txhostdesc_start
, priv
->txhostdesc_startphy
);
1691 ACX_FREE_QUEUE(priv
->txbuf_area_size
, priv
->txbuf_start
, priv
->txbuf_startphy
);
1693 priv
->txdesc_start
= NULL
;
1695 ACX_FREE_QUEUE(priv
->rxhostdesc_area_size
, priv
->rxhostdesc_start
, priv
->rxhostdesc_startphy
);
1696 ACX_FREE_QUEUE(priv
->rxbuf_area_size
, priv
->rxbuf_start
, priv
->rxbuf_startphy
);
1698 priv
->rxdesc_start
= NULL
;
1704 /***********************************************************************
1705 ** acx_s_delete_dma_regions
1708 acx_s_delete_dma_regions(wlandevice_t
*priv
)
1710 unsigned long flags
;
1713 /* disable radio Tx/Rx. Shouldn't we use the firmware commands
1714 * here instead? Or are we that much down the road that it's no
1715 * longer possible here? */
1716 acx_write_reg16(priv
, IO_ACX_ENABLE
, 0);
1720 acx_lock(priv
, flags
);
1721 acx_free_desc_queues(priv
);
1722 acx_unlock(priv
, flags
);
1728 /***********************************************************************
1731 ** Probe routine called when a PCI device w/ matching ID is found.
1732 ** Here's the sequence:
1733 ** - Allocate the PCI resources.
1734 ** - Read the PCMCIA attribute memory to make sure we have a WLAN card
1736 ** - Initialize the dev and wlan data
1737 ** - Initialize the MAC
1739 ** pdev - ptr to pci device structure containing info about pci configuration
1740 ** id - ptr to the device id entry that matched this device
1745 0x0000, /* IO_ACX_SOFT_RESET */
1747 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1748 0x0018, /* IO_ACX_SLV_MEM_DATA */
1749 0x001c, /* IO_ACX_SLV_MEM_CTL */
1750 0x0020, /* IO_ACX_SLV_END_CTL */
1752 0x0034, /* IO_ACX_FEMR */
1754 0x007c, /* IO_ACX_INT_TRIG */
1755 0x0098, /* IO_ACX_IRQ_MASK */
1756 0x00a4, /* IO_ACX_IRQ_STATUS_NON_DES */
1757 0x00a8, /* IO_ACX_IRQ_STATUS_CLEAR */
1758 0x00ac, /* IO_ACX_IRQ_ACK */
1759 0x00b0, /* IO_ACX_HINT_TRIG */
1761 0x0104, /* IO_ACX_ENABLE */
1763 0x0250, /* IO_ACX_EEPROM_CTL */
1764 0x0254, /* IO_ACX_EEPROM_ADDR */
1765 0x0258, /* IO_ACX_EEPROM_DATA */
1766 0x025c, /* IO_ACX_EEPROM_CFG */
1768 0x0268, /* IO_ACX_PHY_ADDR */
1769 0x026c, /* IO_ACX_PHY_DATA */
1770 0x0270, /* IO_ACX_PHY_CTL */
1772 0x0290, /* IO_ACX_GPIO_OE */
1774 0x0298, /* IO_ACX_GPIO_OUT */
1776 0x02a4, /* IO_ACX_CMD_MAILBOX_OFFS */
1777 0x02a8, /* IO_ACX_INFO_MAILBOX_OFFS */
1778 0x02ac, /* IO_ACX_EEPROM_INFORMATION */
1780 0x02d0, /* IO_ACX_EE_START */
1781 0x02d4, /* IO_ACX_SOR_CFG */
1782 0x02d8 /* IO_ACX_ECPU_CTRL */
1788 0x0000, /* IO_ACX_SOFT_RESET */
1790 0x0014, /* IO_ACX_SLV_MEM_ADDR */
1791 0x0018, /* IO_ACX_SLV_MEM_DATA */
1792 0x001c, /* IO_ACX_SLV_MEM_CTL */
1793 0x0020, /* IO_ACX_SLV_END_CTL */
1795 0x0034, /* IO_ACX_FEMR */
1797 0x00b4, /* IO_ACX_INT_TRIG */
1798 0x00d4, /* IO_ACX_IRQ_MASK */
1799 /* we need NON_DES (0xf0), not NON_DES_MASK which is at 0xe0: */
1800 0x00f0, /* IO_ACX_IRQ_STATUS_NON_DES */
1801 0x00e4, /* IO_ACX_IRQ_STATUS_CLEAR */
1802 0x00e8, /* IO_ACX_IRQ_ACK */
1803 0x00ec, /* IO_ACX_HINT_TRIG */
1805 0x01d0, /* IO_ACX_ENABLE */
1807 0x0338, /* IO_ACX_EEPROM_CTL */
1808 0x033c, /* IO_ACX_EEPROM_ADDR */
1809 0x0340, /* IO_ACX_EEPROM_DATA */
1810 0x0344, /* IO_ACX_EEPROM_CFG */
1812 0x0350, /* IO_ACX_PHY_ADDR */
1813 0x0354, /* IO_ACX_PHY_DATA */
1814 0x0358, /* IO_ACX_PHY_CTL */
1816 0x0374, /* IO_ACX_GPIO_OE */
1818 0x037c, /* IO_ACX_GPIO_OUT */
1820 0x0388, /* IO_ACX_CMD_MAILBOX_OFFS */
1821 0x038c, /* IO_ACX_INFO_MAILBOX_OFFS */
1822 0x0390, /* IO_ACX_EEPROM_INFORMATION */
1824 0x0100, /* IO_ACX_EE_START */
1825 0x0104, /* IO_ACX_SOR_CFG */
1826 0x0108, /* IO_ACX_ECPU_CTRL */
1830 acx_netdev_init(struct net_device
*dev
) {}
1832 //FIXME: do the same for USB
1834 acx_change_mtu(struct net_device
*dev
, int mtu
)
1838 MAX_MTU
= WLAN_DATA_MAXLEN
- (ETH_HLEN
)
1841 if (mtu
< MIN_MTU
|| mtu
> MAX_MTU
)
1848 static int __devinit
1849 acx_e_probe_pci(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1851 unsigned long mem_region1
= 0;
1852 unsigned long mem_region2
= 0;
1853 unsigned long mem_region1_size
;
1854 unsigned long mem_region2_size
;
1855 unsigned long phymem1
;
1856 unsigned long phymem2
;
1859 wlandevice_t
*priv
= NULL
;
1860 struct net_device
*dev
= NULL
;
1861 const char *chip_name
;
1866 #if SEPARATE_DRIVER_INSTANCES
1867 struct pci_dev
*tdev
;
1868 unsigned int inited
;
1869 static int turn
= 0;
1870 #endif /* SEPARATE_DRIVER_INSTANCES */
1874 #if SEPARATE_DRIVER_INSTANCES
1878 pci_for_each_dev(tdev
) {
1879 if (tdev
->vendor
!= PCI_VENDOR_ID_TI
)
1884 if (pci_get_drvdata(tdev
))
1887 if (inited
+ turn
!= card
) {
1892 #endif /* SEPARATE_DRIVER_INSTANCES */
1894 /* Enable the PCI device */
1895 if (pci_enable_device(pdev
)) {
1896 printk("acx: pci_enable_device() FAILED\n");
1898 goto fail_pci_enable_device
;
1901 /* enable busmastering (required for CardBus) */
1902 pci_set_master(pdev
);
1904 /* chiptype is u8 but id->driver_data is ulong
1905 ** Works for now (possible values are 1 and 2) */
1906 chip_type
= (u8
)id
->driver_data
;
1907 /* acx100 and acx111 have different PCI memory regions */
1908 if (chip_type
== CHIPTYPE_ACX100
) {
1909 chip_name
= name_acx100
;
1910 mem_region1
= PCI_ACX100_REGION1
;
1911 mem_region1_size
= PCI_ACX100_REGION1_SIZE
;
1913 mem_region2
= PCI_ACX100_REGION2
;
1914 mem_region2_size
= PCI_ACX100_REGION2_SIZE
;
1915 } else if (chip_type
== CHIPTYPE_ACX111
) {
1916 chip_name
= name_acx111
;
1917 mem_region1
= PCI_ACX111_REGION1
;
1918 mem_region1_size
= PCI_ACX111_REGION1_SIZE
;
1920 mem_region2
= PCI_ACX111_REGION2
;
1921 mem_region2_size
= PCI_ACX111_REGION2_SIZE
;
1923 printk("acx: unknown chip type 0x%04X\n", chip_type
);
1924 goto fail_unknown_chiptype
;
1927 /* Figure out our resources */
1928 phymem1
= pci_resource_start(pdev
, mem_region1
);
1929 phymem2
= pci_resource_start(pdev
, mem_region2
);
1931 if (!request_mem_region(phymem1
, pci_resource_len(pdev
, mem_region1
), "ACX1xx_1")) {
1932 printk("acx: cannot reserve PCI memory region 1 (are you sure "
1933 "you have CardBus support in kernel?)\n");
1934 goto fail_request_mem_region1
;
1937 if (!request_mem_region(phymem2
, pci_resource_len(pdev
, mem_region2
), "ACX1xx_2")) {
1938 printk("acx: cannot reserve PCI memory region 2\n");
1939 goto fail_request_mem_region2
;
1942 mem1
= ioremap(phymem1
, mem_region1_size
);
1944 printk("acx: ioremap() FAILED\n");
1948 mem2
= ioremap(phymem2
, mem_region2_size
);
1950 printk("acx: ioremap() #2 FAILED\n");
1954 /* Log the device */
1955 printk("acx: found %s-based wireless network card at %s, irq:%d, "
1956 "phymem1:0x%lX, phymem2:0x%lX, mem1:0x%p, mem1_size:%ld, "
1957 "mem2:0x%p, mem2_size:%ld\n",
1958 chip_name
, pci_name(pdev
), pdev
->irq
, phymem1
, phymem2
,
1959 mem1
, mem_region1_size
,
1960 mem2
, mem_region2_size
);
1961 acxlog(L_ANY
, "initial debug setting is 0x%04X\n", acx_debug
);
1963 if (0 == pdev
->irq
) {
1964 printk("acx: can't use IRQ 0\n");
1968 dev
= alloc_netdev(sizeof(wlandevice_t
), "wlan%d", acx_netdev_init
);
1969 /* (NB: memsets to 0 entire area) */
1971 printk("acx: no memory for netdevice structure\n");
1972 goto fail_alloc_netdev
;
1976 dev
->open
= &acx_e_open
;
1977 dev
->stop
= &acx_e_close
;
1978 dev
->hard_start_xmit
= &acx_i_start_xmit
;
1979 dev
->get_stats
= &acx_e_get_stats
;
1980 dev
->get_wireless_stats
= &acx_e_get_wireless_stats
;
1981 #if WIRELESS_EXT >= 13
1982 dev
->wireless_handlers
= (struct iw_handler_def
*)&acx_ioctl_handler_def
;
1984 dev
->do_ioctl
= &acx_e_ioctl_old
;
1986 dev
->set_multicast_list
= &acx_i_set_multicast_list
;
1987 dev
->tx_timeout
= &acx_i_tx_timeout
;
1988 dev
->change_mtu
= &acx_change_mtu
;
1989 dev
->watchdog_timeo
= 4 * HZ
;
1990 dev
->irq
= pdev
->irq
;
1991 dev
->base_addr
= pci_resource_start(pdev
, 0);
1993 priv
= netdev_priv(dev
);
1994 spin_lock_init(&priv
->lock
); /* initial state: unlocked */
1995 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
1996 sema_init(&priv
->sem
, 1); /* initial state: 1 (upped) */
1997 /* since nobody can see new netdev yet, we can as well
1998 ** just _presume_ that we're under sem (instead of actually taking it): */
1999 /* acx_sem_lock(priv); */
2001 priv
->dev_type
= DEVTYPE_PCI
;
2002 priv
->chip_type
= chip_type
;
2003 priv
->chip_name
= chip_name
;
2004 priv
->io
= (CHIPTYPE_ACX100
== chip_type
) ? IO_ACX100
: IO_ACX111
;
2005 priv
->membase
= phymem1
;
2006 priv
->iobase
= mem1
;
2007 priv
->membase2
= phymem2
;
2008 priv
->iobase2
= mem2
;
2009 /* to find crashes due to weird driver access
2010 * to unconfigured interface (ifup) */
2011 priv
->mgmt_timer
.function
= (void (*)(unsigned long))0x0000dead;
2013 #ifdef NONESSENTIAL_FEATURES
2014 acx_show_card_eeprom_id(priv
);
2015 #endif /* NONESSENTIAL_FEATURES */
2017 /* now we have our device, so make sure the kernel doesn't try
2018 * to send packets even though we're not associated to a network yet */
2019 acx_stop_queue(dev
, "after setup");
2021 #ifdef SET_MODULE_OWNER
2022 SET_MODULE_OWNER(dev
);
2024 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 70)
2025 /* this define and its netdev member exist since 2.5.70 */
2026 SET_NETDEV_DEV(dev
, &pdev
->dev
);
2029 /* register new dev in linked list */
2030 acx_s_device_chain_add(dev
);
2032 acxlog(L_IRQ
|L_INIT
, "using IRQ %d\n", pdev
->irq
);
2034 /* need to be able to restore PCI state after a suspend */
2035 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
2036 /* 2.6.9-rc3-mm2 (2.6.9-bk4, too) introduced this shorter version,
2037 then it made its way into 2.6.10 */
2038 pci_save_state(pdev
);
2040 pci_save_state(pdev
, priv
->pci_state
);
2043 /* NB: acx_read_reg() reads may return bogus data before reset_dev().
2044 ** acx100 seems to be more affected than acx111 */
2045 if (OK
!= acx_s_reset_dev(dev
)) {
2049 /* ok, basic setup is finished, now start initialising the card */
2051 if (OK
!= acx_read_eeprom_offset(priv
, 0x05, &priv
->eeprom_version
)) {
2052 goto fail_read_eeprom_version
;
2055 if (OK
!= acx_s_init_mac(dev
)) {
2056 printk("acx: init_mac() FAILED\n");
2059 if (OK
!= acx_s_set_defaults(priv
)) {
2060 printk("acx: set_defaults() FAILED\n");
2061 goto fail_set_defaults
;
2064 /* needs to be after acx_s_init_mac() due to necessary init stuff */
2065 acx_s_get_firmware_version(priv
);
2067 acx_display_hardware_details(priv
);
2069 pci_set_drvdata(pdev
, dev
);
2071 /* ...and register the card, AFTER everything else has been set up,
2072 * since otherwise an ioctl could step on our feet due to
2073 * firmware operations happening in parallel or uninitialized data */
2074 err
= register_netdev(dev
);
2076 printk("acx: register_netdev() FAILED: %d\n", err
);
2077 goto fail_register_netdev
;
2080 acx_carrier_off(dev
, "on probe");
2082 if (OK
!= acx_proc_register_entries(dev
)) {
2083 goto fail_proc_register_entries
;
2086 /* after register_netdev() userspace may start working with dev
2087 * (in particular, on other CPUs), we only need to up the sem */
2088 /* acx_sem_unlock(priv); */
2090 printk("acx "WLAN_RELEASE
": net device %s, driver compiled "
2091 "against wireless extensions %d and Linux %s\n",
2092 dev
->name
, WIRELESS_EXT
, UTS_RELEASE
);
2095 great_inquisitor(priv
);
2101 /* error paths: undo everything in reverse order... */
2103 #ifdef CONFIG_PROC_FS
2104 fail_proc_register_entries
:
2106 if (priv
->dev_state_mask
& ACX_STATE_IFACE_UP
)
2109 unregister_netdev(dev
);
2111 /* after unregister_netdev() userspace is guaranteed to finish
2112 * working with it. netdev does not exist anymore.
2113 * For paranoid reasons I am taking sem anyway */
2117 fail_register_netdev
:
2119 acx_s_delete_dma_regions(priv
);
2120 pci_set_drvdata(pdev
, NULL
);
2124 fail_read_eeprom_version
:
2127 acx_s_device_chain_remove(dev
);
2138 release_mem_region(pci_resource_start(pdev
, mem_region2
),
2139 pci_resource_len(pdev
, mem_region2
));
2140 fail_request_mem_region2
:
2142 release_mem_region(pci_resource_start(pdev
, mem_region1
),
2143 pci_resource_len(pdev
, mem_region1
));
2144 fail_request_mem_region1
:
2145 fail_unknown_chiptype
:
2147 pci_disable_device(pdev
);
2148 fail_pci_enable_device
:
2150 pci_set_power_state(pdev
, 3);
2158 /***********************************************************************
2161 ** Deallocate PCI resources for the acx chip.
2163 ** This should NOT execute any other hardware operations on the card,
2164 ** since the card might already be ejected. Instead, that should be done
2165 ** in cleanup_module, since the card is most likely still available there.
2167 ** pdev - ptr to PCI device structure containing info about pci configuration
2169 static void __devexit
2170 acx_e_remove_pci(struct pci_dev
*pdev
)
2172 struct net_device
*dev
;
2174 unsigned long mem_region1
, mem_region2
;
2178 dev
= (struct net_device
*) pci_get_drvdata(pdev
);
2180 acxlog(L_DEBUG
, "%s: card is unused. Skipping any release code\n",
2185 priv
= netdev_priv(dev
);
2187 /* unregister the device to not let the kernel
2188 * (e.g. ioctls) access a half-deconfigured device
2189 * NB: this will cause acx_e_close() to be called,
2190 * thus we shouldn't call it under sem! */
2191 acxlog(L_INIT
, "removing device %s\n", dev
->name
);
2192 unregister_netdev(dev
);
2194 /* unregister_netdev ensures that no references to us left.
2195 * For paranoid reasons we continue to follow the rules */
2198 if (IS_ACX100(priv
)) {
2199 mem_region1
= PCI_ACX100_REGION1
;
2200 mem_region2
= PCI_ACX100_REGION2
;
2202 mem_region1
= PCI_ACX111_REGION1
;
2203 mem_region2
= PCI_ACX111_REGION2
;
2206 acx_proc_unregister_entries(dev
);
2208 /* find our PCI device in the global acx list and remove it */
2209 acx_s_device_chain_remove(dev
);
2211 if (priv
->dev_state_mask
& ACX_STATE_IFACE_UP
)
2214 CLEAR_BIT(priv
->dev_state_mask
, ACX_STATE_IFACE_UP
);
2216 acx_s_delete_dma_regions(priv
);
2218 /* finally, clean up PCI bus state */
2219 if (priv
->iobase
) iounmap(priv
->iobase
);
2220 if (priv
->iobase2
) iounmap(priv
->iobase2
);
2222 release_mem_region(pci_resource_start(pdev
, mem_region1
),
2223 pci_resource_len(pdev
, mem_region1
));
2225 release_mem_region(pci_resource_start(pdev
, mem_region2
),
2226 pci_resource_len(pdev
, mem_region2
));
2228 pci_disable_device(pdev
);
2230 /* remove dev registration */
2231 pci_set_drvdata(pdev
, NULL
);
2233 /* Free netdev (quite late,
2234 * since otherwise we might get caught off-guard
2235 * by a netdev timeout handler execution
2236 * expecting to see a working dev...) */
2239 /* put device into ACPI D3 mode (shutdown) */
2240 pci_set_power_state(pdev
, 3);
2247 /***********************************************************************
2250 static int if_was_up
= 0; /* FIXME: HACK, do it correctly sometime instead */
2252 acx_e_suspend(struct pci_dev
*pdev
, pm_message_t state
)
2254 struct net_device
*dev
= pci_get_drvdata(pdev
);
2255 wlandevice_t
*priv
= netdev_priv(dev
);
2261 printk("acx: experimental suspend handler called for %p\n", priv
);
2262 if (netif_device_present(dev
)) {
2269 netif_device_detach(dev
); /* This one cannot sleep */
2270 acx_s_delete_dma_regions(priv
);
2272 acx_sem_unlock(priv
);
2279 acx_e_resume(struct pci_dev
*pdev
)
2281 struct net_device
*dev
;
2284 printk(KERN_WARNING
"rsm: resume\n");
2285 dev
= pci_get_drvdata(pdev
);
2286 printk(KERN_WARNING
"rsm: got dev\n");
2288 if (!netif_running(dev
))
2291 priv
= netdev_priv(dev
);
2295 printk(KERN_WARNING
"rsm: got priv\n");
2297 printk("acx: experimental resume handler called for %p!\n", priv
);
2298 pci_set_power_state(pdev
, 0);
2299 acxlog(L_DEBUG
, "rsm: power state set\n");
2300 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
2301 /* 2.6.9-rc3-mm2 (2.6.9-bk4, too) introduced this shorter version,
2302 then it made its way into 2.6.10 */
2303 pci_restore_state(pdev
);
2305 pci_restore_state(pdev
, priv
->pci_state
);
2307 acxlog(L_DEBUG
, "rsm: PCI state restored\n");
2308 acx_s_reset_dev(dev
);
2309 acxlog(L_DEBUG
, "rsm: device reset done\n");
2311 if (OK
!= acx_s_init_mac(dev
)) {
2312 printk("rsm: init_mac FAILED\n");
2315 acxlog(L_DEBUG
, "rsm: init MAC done\n");
2319 acxlog(L_DEBUG
, "rsm: acx up\n");
2321 /* now even reload all card parameters as they were before suspend,
2322 * and possibly be back in the network again already :-)
2323 * FIXME: should this be done in that scheduled task instead?? */
2324 if (ACX_STATE_IFACE_UP
& priv
->dev_state_mask
)
2325 acx_s_update_card_settings(priv
, 0, 1);
2326 acxlog(L_DEBUG
, "rsm: settings updated\n");
2327 netif_device_attach(dev
);
2328 acxlog(L_DEBUG
, "rsm: device attached\n");
2329 fail
: /* we need to return OK here anyway, right? */
2330 acx_sem_unlock(priv
);
2334 #endif /* CONFIG_PM */
2337 /***********************************************************************
2340 ** This function is called by acx_e_open (when ifconfig sets the device as up)
2343 ** - Enables on-card interrupt requests
2344 ** - calls acx_start
2347 acx_s_up(netdevice_t
*dev
)
2349 wlandevice_t
*priv
= netdev_priv(dev
);
2350 unsigned long flags
;
2354 acx_lock(priv
, flags
);
2355 acx_l_enable_irq(priv
);
2356 acx_unlock(priv
, flags
);
2358 /* acx fw < 1.9.3.e has a hardware timer, and older drivers
2359 ** used to use it. But we don't do that anymore, our OS
2360 ** has reliable software timers */
2361 init_timer(&priv
->mgmt_timer
);
2362 priv
->mgmt_timer
.function
= acx_i_timer
;
2363 priv
->mgmt_timer
.data
= (unsigned long)priv
;
2365 /* Need to set ACX_STATE_IFACE_UP first, or else
2366 ** timer won't be started by acx_set_status() */
2367 SET_BIT(priv
->dev_state_mask
, ACX_STATE_IFACE_UP
);
2368 switch (priv
->mode
) {
2369 case ACX_MODE_0_ADHOC
:
2370 case ACX_MODE_2_STA
:
2371 /* actual scan cmd will happen in start() */
2372 acx_set_status(priv
, ACX_STATUS_1_SCANNING
); break;
2374 case ACX_MODE_MONITOR
:
2375 acx_set_status(priv
, ACX_STATUS_4_ASSOCIATED
); break;
2384 /***********************************************************************
2387 ** This disables the netdevice
2390 ** - disables on-card interrupt request
2393 acx_s_down(netdevice_t
*dev
)
2395 wlandevice_t
*priv
= netdev_priv(dev
);
2396 unsigned long flags
;
2400 /* Disable IRQs first, so that IRQs cannot race with us */
2401 acx_lock(priv
, flags
);
2402 acx_l_disable_irq(priv
);
2403 acx_unlock(priv
, flags
);
2405 /* we really don't want to have an asynchronous tasklet disturb us
2406 ** after something vital for its job has been shut down, so
2407 ** end all remaining work now.
2409 ** NB: carrier_off (done by set_status below) would lead to
2410 ** not yet fully understood deadlock in FLUSH_SCHEDULED_WORK().
2411 ** That's why we do FLUSH first.
2413 ** NB2: we have a bad locking bug here: FLUSH_SCHEDULED_WORK()
2414 ** waits for acx_e_after_interrupt_task to complete if it is running
2415 ** on another CPU, but acx_e_after_interrupt_task
2416 ** will sleep on sem forever, because it is taken by us!
2417 ** Work around that by temporary sem unlock.
2418 ** This will fail miserably if we'll be hit by concurrent
2419 ** iwconfig or something in between. TODO! */
2420 acx_sem_unlock(priv
);
2421 FLUSH_SCHEDULED_WORK();
2424 /* This is possible:
2425 ** FLUSH_SCHEDULED_WORK -> acx_e_after_interrupt_task ->
2426 ** -> set_status(ASSOCIATED) -> wake_queue()
2427 ** That's why we stop queue _after_ FLUSH_SCHEDULED_WORK
2428 ** lock/unlock is just paranoia, maybe not needed */
2429 acx_lock(priv
, flags
);
2430 acx_stop_queue(dev
, "during close");
2431 acx_set_status(priv
, ACX_STATUS_0_STOPPED
);
2432 acx_unlock(priv
, flags
);
2434 /* kernel/timer.c says it's illegal to del_timer_sync()
2435 ** a timer which restarts itself. We guarantee this cannot
2436 ** ever happen because acx_i_timer() never does this if
2437 ** status is ACX_STATUS_0_STOPPED */
2438 del_timer_sync(&priv
->mgmt_timer
);
2444 /***********************************************************************
2447 ** Called as a result of SIOCSIFFLAGS ioctl changing the flags bit IFF_UP
2448 ** from clear to set. In other words: ifconfig up.
2452 ** >0 f/w reported error
2453 ** <0 driver reported error
2456 acx_e_open(netdevice_t
*dev
)
2458 wlandevice_t
*priv
= netdev_priv(dev
);
2463 acxlog(L_INIT
, "module count++\n");
2464 WLAN_MOD_INC_USE_COUNT
;
2468 acx_init_task_scheduler(priv
);
2470 /* request shared IRQ handler */
2471 if (request_irq(dev
->irq
, acx_i_interrupt
, SA_SHIRQ
, dev
->name
, dev
)) {
2472 printk("%s: request_irq FAILED\n", dev
->name
);
2476 acxlog(L_DEBUG
|L_IRQ
, "request_irq %d successful\n", dev
->irq
);
2481 /* We don't currently have to do anything else.
2482 * The setup of the MAC should be subsequently completed via
2483 * the mlme commands.
2484 * Higher layers know we're ready from dev->start==1 and
2485 * dev->tbusy==0. Our rx path knows to pass up received/
2486 * frames because of dev->flags&IFF_UP is true.
2489 acx_sem_unlock(priv
);
2496 /***********************************************************************
2499 ** Called as a result of SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
2500 ** from set to clear. I.e. called by "ifconfig DEV down"
2504 ** >0 f/w reported error
2505 ** <0 driver reported error
2508 acx_e_close(netdevice_t
*dev
)
2510 wlandevice_t
*priv
= netdev_priv(dev
);
2517 CLEAR_BIT(priv
->dev_state_mask
, ACX_STATE_IFACE_UP
);
2518 if (netif_device_present(dev
)) {
2522 /* disable all IRQs, release shared IRQ handler */
2523 acx_write_reg16(priv
, IO_ACX_IRQ_MASK
, 0xffff);
2524 acx_write_reg16(priv
, IO_ACX_FEMR
, 0x0);
2525 free_irq(dev
->irq
, dev
);
2527 /* We currently don't have to do anything else.
2528 * Higher layers know we're not ready from dev->start==0 and
2529 * dev->tbusy==1. Our rx path knows to not pass up received
2530 * frames because of dev->flags&IFF_UP is false.
2532 acxlog(L_INIT
, "module count--\n");
2533 WLAN_MOD_DEC_USE_COUNT
;
2535 acx_sem_unlock(priv
);
2537 acxlog(L_INIT
, "closed device\n");
2543 /***********************************************************************
2546 ** Called from network core. Must not sleep!
2549 acx_i_tx_timeout(netdevice_t
*dev
)
2551 wlandevice_t
*priv
= netdev_priv(dev
);
2552 unsigned long flags
;
2553 unsigned int tx_num_cleaned
;
2557 acx_lock(priv
, flags
);
2559 /* clean processed tx descs, they may have been completely full */
2560 tx_num_cleaned
= acx_l_clean_tx_desc(priv
);
2562 /* nothing cleaned, yet (almost) no free buffers available?
2563 * --> clean all tx descs, no matter which status!!
2564 * Note that I strongly suspect that doing emergency cleaning
2565 * may confuse the firmware. This is a last ditch effort to get
2566 * ANYTHING to work again...
2568 * TODO: it's best to simply reset & reinit hw from scratch...
2570 if ((priv
->tx_free
<= TX_EMERG_CLEAN
) && (tx_num_cleaned
== 0)) {
2571 printk("%s: FAILED to free any of the many full tx buffers. "
2572 "Switching to emergency freeing. "
2573 "Please report!\n", dev
->name
);
2574 acx_l_clean_tx_desc_emergency(priv
);
2577 if (acx_queue_stopped(dev
) && (ACX_STATUS_4_ASSOCIATED
== priv
->status
))
2578 acx_wake_queue(dev
, "after tx timeout");
2580 /* stall may have happened due to radio drift, so recalib radio */
2581 acx_schedule_task(priv
, ACX_AFTER_IRQ_CMD_RADIO_RECALIB
);
2583 /* do unimportant work last */
2584 printk("%s: tx timeout!\n", dev
->name
);
2585 priv
->stats
.tx_errors
++;
2587 acx_unlock(priv
, flags
);
2593 /***********************************************************************
2596 static struct net_device_stats
*
2597 acx_e_get_stats(netdevice_t
*dev
)
2599 wlandevice_t
*priv
= netdev_priv(dev
);
2600 return &priv
->stats
;
2604 /***********************************************************************
2605 ** acx_e_get_wireless_stats
2607 static struct iw_statistics
*
2608 acx_e_get_wireless_stats(netdevice_t
*dev
)
2610 wlandevice_t
*priv
= netdev_priv(dev
);
2611 return &priv
->wstats
;
2615 /***********************************************************************
2616 ** acx_i_set_multicast_list
2617 ** FIXME: most likely needs refinement
2620 acx_i_set_multicast_list(netdevice_t
*dev
)
2622 wlandevice_t
*priv
= netdev_priv(dev
);
2623 unsigned long flags
;
2627 acx_lock(priv
, flags
);
2629 /* firmwares don't have allmulti capability,
2630 * so just use promiscuous mode instead in this case. */
2631 if (dev
->flags
& (IFF_PROMISC
|IFF_ALLMULTI
)) {
2632 SET_BIT(priv
->rx_config_1
, RX_CFG1_RCV_PROMISCUOUS
);
2633 CLEAR_BIT(priv
->rx_config_1
, RX_CFG1_FILTER_ALL_MULTI
);
2634 SET_BIT(priv
->set_mask
, SET_RXCONFIG
);
2635 /* let kernel know in case *we* needed to set promiscuous */
2636 dev
->flags
|= (IFF_PROMISC
|IFF_ALLMULTI
);
2638 CLEAR_BIT(priv
->rx_config_1
, RX_CFG1_RCV_PROMISCUOUS
);
2639 SET_BIT(priv
->rx_config_1
, RX_CFG1_FILTER_ALL_MULTI
);
2640 SET_BIT(priv
->set_mask
, SET_RXCONFIG
);
2641 dev
->flags
&= ~(IFF_PROMISC
|IFF_ALLMULTI
);
2644 /* cannot update card settings directly here, atomic context */
2645 acx_schedule_task(priv
, ACX_AFTER_IRQ_UPDATE_CARD_CFG
);
2647 acx_unlock(priv
, flags
);
2653 acx_l_update_link_quality_led(wlandevice_t
*priv
)
2657 qual
= acx_signal_determine_quality(priv
->wstats
.qual
.level
, priv
->wstats
.qual
.noise
);
2658 if (qual
> priv
->brange_max_quality
)
2659 qual
= priv
->brange_max_quality
;
2661 if (time_after(jiffies
, priv
->brange_time_last_state_change
+
2662 (HZ
/2 - HZ
/2 * (unsigned long) qual
/priv
->brange_max_quality
) )) {
2663 acx_l_power_led(priv
, (priv
->brange_last_state
== 0));
2664 priv
->brange_last_state
^= 1; /* toggle */
2665 priv
->brange_time_last_state_change
= jiffies
;
2670 /***********************************************************************
2674 acx_l_enable_irq(wlandevice_t
*priv
)
2677 acx_write_reg16(priv
, IO_ACX_IRQ_MASK
, priv
->irq_mask
);
2678 acx_write_reg16(priv
, IO_ACX_FEMR
, 0x8000);
2679 priv
->irqs_active
= 1;
2684 /***********************************************************************
2685 ** acx_l_disable_irq
2688 acx_l_disable_irq(wlandevice_t
*priv
)
2691 acx_write_reg16(priv
, IO_ACX_IRQ_MASK
, priv
->irq_mask_off
);
2692 acx_write_reg16(priv
, IO_ACX_FEMR
, 0x0);
2693 priv
->irqs_active
= 0;
2697 /* scan is complete. all frames now on the receive queue are valid */
2698 #define INFO_SCAN_COMPLETE 0x0001
2699 #define INFO_WEP_KEY_NOT_FOUND 0x0002
2700 /* hw has been reset as the result of a watchdog timer timeout */
2701 #define INFO_WATCH_DOG_RESET 0x0003
2702 /* failed to send out NULL frame from PS mode notification to AP */
2703 /* recommended action: try entering 802.11 PS mode again */
2704 #define INFO_PS_FAIL 0x0004
2705 /* encryption/decryption process on a packet failed */
2706 #define INFO_IV_ICV_FAILURE 0x0005
2709 acx_l_handle_info_irq(wlandevice_t
*priv
)
2712 static const char * const info_type_msg
[] = {
2715 "WEP key not found",
2716 "internal watchdog reset was done",
2717 "failed to send powersave (NULL frame) notification to AP",
2718 "encrypt/decrypt on a packet has failed",
2719 "TKIP tx keys disabled",
2720 "TKIP rx keys disabled",
2721 "TKIP rx: key ID not found",
2729 "TKIP IV value exceeds thresh"
2732 acx_read_info_status(priv
);
2733 acxlog(L_IRQ
, "got Info IRQ: status 0x%04X type 0x%04X: %s\n",
2734 priv
->info_status
, priv
->info_type
,
2735 info_type_msg
[(priv
->info_type
>= VEC_SIZE(info_type_msg
)) ?
2736 0 : priv
->info_type
]
2741 /***********************************************************************
2744 ** IRQ handler (atomic context, must not sleep, blah, blah)
2747 acx_log_unusual_irq(u16 irqtype
) {
2749 if (!printk_ratelimit())
2754 if (irqtype
& HOST_INT_RX_DATA
) {
2757 /* HOST_INT_TX_COMPLETE */
2758 if (irqtype
& HOST_INT_TX_XFER
) {
2761 /* HOST_INT_RX_COMPLETE */
2762 if (irqtype
& HOST_INT_DTIM
) {
2765 if (irqtype
& HOST_INT_BEACON
) {
2768 if (irqtype
& HOST_INT_TIMER
) {
2769 acxlog(L_IRQ
, " Timer");
2771 if (irqtype
& HOST_INT_KEY_NOT_FOUND
) {
2772 printk(" Key_Not_Found");
2774 if (irqtype
& HOST_INT_IV_ICV_FAILURE
) {
2775 printk(" IV_ICV_Failure");
2777 /* HOST_INT_CMD_COMPLETE */
2779 if (irqtype
& HOST_INT_OVERFLOW
) {
2780 printk(" Overflow");
2782 if (irqtype
& HOST_INT_PROCESS_ERROR
) {
2783 printk(" Process_Error");
2785 /* HOST_INT_SCAN_COMPLETE */
2786 if (irqtype
& HOST_INT_FCS_THRESHOLD
) {
2787 printk(" FCS_Threshold");
2789 if (irqtype
& HOST_INT_UNKNOWN
) {
2792 printk(" IRQ(s)\n");
2796 acx_i_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
2799 unsigned long flags
;
2800 unsigned int irqcount
= MAX_IRQLOOPS_PER_JIFFY
;
2801 u16 irqtype
, unmasked
;
2803 priv
= (wlandevice_t
*) (((netdevice_t
*) dev_id
)->priv
);
2805 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
2807 acx_lock(priv
, flags
);
2809 unmasked
= acx_read_reg16(priv
, IO_ACX_IRQ_STATUS_CLEAR
);
2810 if (unlikely(0xffff == unmasked
)) {
2811 /* 0xffff value hints at missing hardware,
2812 * so don't do anything.
2813 * FIXME: that's not very clean - maybe we are able to
2814 * establish a flag which definitely tells us that some
2815 * hardware is absent and which we could check here?
2816 * Hmm, but other drivers do the very same thing... */
2817 acxlog(L_IRQ
, "IRQ type:FFFF - device removed? IRQ_NONE\n");
2821 /* We will check only "interesting" IRQ types */
2822 irqtype
= unmasked
& ~priv
->irq_mask
;
2824 /* We are on a shared IRQ line and it wasn't our IRQ */
2825 acxlog(L_IRQ
, "IRQ type:%04X, mask:%04X - all are masked, IRQ_NONE\n",
2826 unmasked
, priv
->irq_mask
);
2830 /* Done here because IRQ_NONEs taking three lines of log
2831 ** drive me crazy */
2834 #define IRQ_ITERATE 1
2836 if (jiffies
!= priv
->irq_last_jiffies
) {
2837 priv
->irq_loops_this_jiffy
= 0;
2838 priv
->irq_last_jiffies
= jiffies
;
2841 /* safety condition; we'll normally abort loop below
2842 * in case no IRQ type occurred */
2843 while (--irqcount
) {
2845 /* ACK all IRQs asap */
2846 acx_write_reg16(priv
, IO_ACX_IRQ_ACK
, 0xffff);
2848 acxlog(L_IRQ
, "IRQ type:%04X, mask:%04X, type & ~mask:%04X\n",
2849 unmasked
, priv
->irq_mask
, irqtype
);
2851 /* Handle most important IRQ types first */
2852 if (irqtype
& HOST_INT_RX_COMPLETE
) {
2853 acxlog(L_IRQ
, "got Rx_Complete IRQ\n");
2854 acx_l_process_rx_desc(priv
);
2856 if (irqtype
& HOST_INT_TX_COMPLETE
) {
2857 acxlog(L_IRQ
, "got Tx_Complete IRQ\n");
2858 /* don't clean up on each Tx complete, wait a bit
2859 * unless we're going towards full, in which case
2860 * we do it immediately, too (otherwise we might lockup
2861 * with a full Tx buffer if we go into
2862 * acx_l_clean_tx_desc() at a time when we won't wakeup
2863 * the net queue in there for some reason...) */
2864 if (priv
->tx_free
<= TX_START_CLEAN
) {
2865 #if TX_CLEANUP_IN_SOFTIRQ
2866 acx_schedule_task(priv
, ACX_AFTER_IRQ_TX_CLEANUP
);
2868 acx_l_clean_tx_desc(priv
);
2873 /* Less frequent ones */
2875 | HOST_INT_CMD_COMPLETE
2877 | HOST_INT_SCAN_COMPLETE
2879 if (irqtype
& HOST_INT_CMD_COMPLETE
) {
2880 acxlog(L_IRQ
, "got Command_Complete IRQ\n");
2881 /* save the state for the running issue_cmd() */
2882 SET_BIT(priv
->irq_status
, HOST_INT_CMD_COMPLETE
);
2884 if (irqtype
& HOST_INT_INFO
) {
2885 acx_l_handle_info_irq(priv
);
2887 if (irqtype
& HOST_INT_SCAN_COMPLETE
) {
2888 acxlog(L_IRQ
, "got Scan_Complete IRQ\n");
2889 /* need to do that in process context */
2890 acx_schedule_task(priv
, ACX_AFTER_IRQ_COMPLETE_SCAN
);
2891 /* remember that fw is not scanning anymore */
2892 SET_BIT(priv
->irq_status
, HOST_INT_SCAN_COMPLETE
);
2896 /* These we just log, but either they happen rarely
2897 * or we keep them masked out */
2900 /* | HOST_INT_TX_COMPLETE */
2902 /* | HOST_INT_RX_COMPLETE */
2906 | HOST_INT_KEY_NOT_FOUND
2907 | HOST_INT_IV_ICV_FAILURE
2908 /* | HOST_INT_CMD_COMPLETE */
2909 /* | HOST_INT_INFO */
2911 | HOST_INT_PROCESS_ERROR
2912 /* | HOST_INT_SCAN_COMPLETE */
2913 | HOST_INT_FCS_THRESHOLD
2916 acx_log_unusual_irq(irqtype
);
2920 unmasked
= acx_read_reg16(priv
, IO_ACX_IRQ_STATUS_CLEAR
);
2921 irqtype
= unmasked
& ~priv
->irq_mask
;
2922 /* Bail out if no new IRQ bits or if all are masked out */
2926 if (unlikely(++priv
->irq_loops_this_jiffy
> MAX_IRQLOOPS_PER_JIFFY
)) {
2927 printk(KERN_ERR
"acx: too many interrupts per jiffy!\n");
2928 /* Looks like card floods us with IRQs! Try to stop that */
2929 acx_write_reg16(priv
, IO_ACX_IRQ_MASK
, 0xffff);
2930 /* This will short-circuit all future attempts to handle IRQ.
2931 * We cant do much more... */
2937 /* Routine to perform blink with range */
2938 if (unlikely(priv
->led_power
== 2))
2939 acx_l_update_link_quality_led(priv
);
2942 /* acx_write_flush(priv); - not needed, last op was read anyway */
2943 acx_unlock(priv
, flags
);
2948 acx_unlock(priv
, flags
);
2953 /***********************************************************************
2957 acx_l_power_led(wlandevice_t
*priv
, int enable
)
2959 u16 gpio_pled
= IS_ACX111(priv
) ? 0x0040 : 0x0800;
2961 /* A hack. Not moving message rate limiting to priv->xxx
2962 * (it's only a debug message after all) */
2963 static int rate_limit
= 0;
2965 if (rate_limit
++ < 3)
2966 acxlog(L_IOCTL
, "Please report in case toggling the power "
2967 "LED doesn't work for your card!\n");
2969 acx_write_reg16(priv
, IO_ACX_GPIO_OUT
,
2970 acx_read_reg16(priv
, IO_ACX_GPIO_OUT
) & ~gpio_pled
);
2972 acx_write_reg16(priv
, IO_ACX_GPIO_OUT
,
2973 acx_read_reg16(priv
, IO_ACX_GPIO_OUT
) | gpio_pled
);
2977 /***********************************************************************
2981 /***********************************************************************
2984 acx111pci_ioctl_info(
2985 struct net_device
*dev
,
2986 struct iw_request_info
*info
,
2987 struct iw_param
*vwrq
,
2991 wlandevice_t
*priv
= netdev_priv(dev
);
2994 rxhostdesc_t
*rxhostdesc
;
2995 txhostdesc_t
*txhostdesc
;
2996 struct acx111_ie_memoryconfig memconf
;
2997 struct acx111_ie_queueconfig queueconf
;
2998 unsigned long flags
;
3003 char ratefallback
[0x5];
3005 if ( !(acx_debug
& (L_IOCTL
|L_DEBUG
)) )
3007 /* using printk() since we checked debug flag already */
3011 if (!IS_ACX111(priv
)) {
3012 printk("acx111-specific function called "
3013 "with non-acx111 chip, aborting\n");
3017 /* get Acx111 Memory Configuration */
3018 memset(&memconf
, 0, sizeof(memconf
));
3019 /* BTW, fails with 12 (Write only) error code.
3020 ** Retained for easy testing of issue_cmd error handling :) */
3021 acx_s_interrogate(priv
, &memconf
, ACX1xx_IE_QUEUE_CONFIG
);
3023 /* get Acx111 Queue Configuration */
3024 memset(&queueconf
, 0, sizeof(queueconf
));
3025 acx_s_interrogate(priv
, &queueconf
, ACX1xx_IE_MEMORY_CONFIG_OPTIONS
);
3027 /* get Acx111 Memory Map */
3028 memset(memmap
, 0, sizeof(memmap
));
3029 acx_s_interrogate(priv
, &memmap
, ACX1xx_IE_MEMORY_MAP
);
3031 /* get Acx111 Rx Config */
3032 memset(rxconfig
, 0, sizeof(rxconfig
));
3033 acx_s_interrogate(priv
, &rxconfig
, ACX1xx_IE_RXCONFIG
);
3035 /* get Acx111 fcs error count */
3036 memset(fcserror
, 0, sizeof(fcserror
));
3037 acx_s_interrogate(priv
, &fcserror
, ACX1xx_IE_FCS_ERROR_COUNT
);
3039 /* get Acx111 rate fallback */
3040 memset(ratefallback
, 0, sizeof(ratefallback
));
3041 acx_s_interrogate(priv
, &ratefallback
, ACX1xx_IE_RATE_FALLBACK
);
3043 /* force occurrence of a beacon interrupt */
3044 /* TODO: comment why is this necessary */
3045 acx_write_reg16(priv
, IO_ACX_HINT_TRIG
, HOST_INT_BEACON
);
3047 /* dump Acx111 Mem Configuration */
3048 printk("dump mem config:\n"
3049 "data read: %d, struct size: %d\n"
3050 "Number of stations: %1X\n"
3051 "Memory block size: %1X\n"
3052 "tx/rx memory block allocation: %1X\n"
3053 "count rx: %X / tx: %X queues\n"
3055 "fragmentation %1X\n"
3056 "Rx Queue 1 Count Descriptors: %X\n"
3057 "Rx Queue 1 Host Memory Start: %X\n"
3058 "Tx Queue 1 Count Descriptors: %X\n"
3059 "Tx Queue 1 Attributes: %X\n",
3060 memconf
.len
, (int) sizeof(memconf
),
3061 memconf
.no_of_stations
,
3062 memconf
.memory_block_size
,
3063 memconf
.tx_rx_memory_block_allocation
,
3064 memconf
.count_rx_queues
, memconf
.count_tx_queues
,
3066 memconf
.fragmentation
,
3067 memconf
.rx_queue1_count_descs
,
3068 acx2cpu(memconf
.rx_queue1_host_rx_start
),
3069 memconf
.tx_queue1_count_descs
,
3070 memconf
.tx_queue1_attributes
);
3072 /* dump Acx111 Queue Configuration */
3073 printk("dump queue head:\n"
3074 "data read: %d, struct size: %d\n"
3075 "tx_memory_block_address (from card): %X\n"
3076 "rx_memory_block_address (from card): %X\n"
3077 "rx1_queue address (from card): %X\n"
3078 "tx1_queue address (from card): %X\n"
3079 "tx1_queue attributes (from card): %X\n",
3080 queueconf
.len
, (int) sizeof(queueconf
),
3081 queueconf
.tx_memory_block_address
,
3082 queueconf
.rx_memory_block_address
,
3083 queueconf
.rx1_queue_address
,
3084 queueconf
.tx1_queue_address
,
3085 queueconf
.tx1_attributes
);
3087 /* dump Acx111 Mem Map */
3088 printk("dump mem map:\n"
3089 "data read: %d, struct size: %d\n"
3092 "WEP default key start: %X\n"
3093 "WEP default key end: %X\n"
3094 "STA table start: %X\n"
3095 "STA table end: %X\n"
3096 "Packet template start: %X\n"
3097 "Packet template end: %X\n"
3098 "Queue memory start: %X\n"
3099 "Queue memory end: %X\n"
3100 "Packet memory pool start: %X\n"
3101 "Packet memory pool end: %X\n"
3104 *((u16
*)&memmap
[0x02]), (int) sizeof(memmap
),
3105 *((u32
*)&memmap
[0x04]),
3106 *((u32
*)&memmap
[0x08]),
3107 *((u32
*)&memmap
[0x0C]),
3108 *((u32
*)&memmap
[0x10]),
3109 *((u32
*)&memmap
[0x14]),
3110 *((u32
*)&memmap
[0x18]),
3111 *((u32
*)&memmap
[0x1C]),
3112 *((u32
*)&memmap
[0x20]),
3113 *((u32
*)&memmap
[0x24]),
3114 *((u32
*)&memmap
[0x28]),
3115 *((u32
*)&memmap
[0x2C]),
3116 *((u32
*)&memmap
[0x30]),
3120 /* dump Acx111 Rx Config */
3121 printk("dump rx config:\n"
3122 "data read: %d, struct size: %d\n"
3124 "rx filter config: %X\n",
3125 *((u16
*)&rxconfig
[0x02]), (int) sizeof(rxconfig
),
3126 *((u16
*)&rxconfig
[0x04]),
3127 *((u16
*)&rxconfig
[0x06]));
3129 /* dump Acx111 fcs error */
3130 printk("dump fcserror:\n"
3131 "data read: %d, struct size: %d\n"
3133 *((u16
*)&fcserror
[0x02]), (int) sizeof(fcserror
),
3134 *((u32
*)&fcserror
[0x04]));
3136 /* dump Acx111 rate fallback */
3137 printk("dump rate fallback:\n"
3138 "data read: %d, struct size: %d\n"
3139 "ratefallback: %X\n",
3140 *((u16
*)&ratefallback
[0x02]), (int) sizeof(ratefallback
),
3141 *((u8
*)&ratefallback
[0x04]));
3143 /* protect against IRQ */
3144 acx_lock(priv
, flags
);
3146 /* dump acx111 internal rx descriptor ring buffer */
3147 rxdesc
= priv
->rxdesc_start
;
3149 /* loop over complete receive pool */
3150 if (rxdesc
) for (i
= 0; i
< RX_CNT
; i
++) {
3151 printk("\ndump internal rxdesc %d:\n"
3154 "acx mem pointer (dynamic) 0x%X\n"
3155 "CTL (dynamic) 0x%X\n"
3156 "Rate (dynamic) 0x%X\n"
3157 "RxStatus (dynamic) 0x%X\n"
3158 "Mod/Pre (dynamic) 0x%X\n",
3161 acx2cpu(rxdesc
->pNextDesc
),
3162 acx2cpu(rxdesc
->ACXMemPtr
),
3170 /* dump host rx descriptor ring buffer */
3172 rxhostdesc
= priv
->rxhostdesc_start
;
3174 /* loop over complete receive pool */
3175 if (rxhostdesc
) for (i
= 0; i
< RX_CNT
; i
++) {
3176 printk("\ndump host rxdesc %d:\n"
3178 "buffer mem pos 0x%X\n"
3179 "buffer mem offset 0x%X\n"
3186 acx2cpu(rxhostdesc
->data_phy
),
3187 rxhostdesc
->data_offset
,
3188 le16_to_cpu(rxhostdesc
->Ctl_16
),
3189 le16_to_cpu(rxhostdesc
->length
),
3190 acx2cpu(rxhostdesc
->desc_phy_next
),
3191 rxhostdesc
->Status
);
3195 /* dump acx111 internal tx descriptor ring buffer */
3196 txdesc
= priv
->txdesc_start
;
3198 /* loop over complete transmit pool */
3199 if (txdesc
) for (i
= 0; i
< TX_CNT
; i
++) {
3200 printk("\ndump internal txdesc %d:\n"
3204 "acx mem pointer (dynamic) 0x%X\n"
3205 "host mem pointer (dynamic) 0x%X\n"
3206 "length (dynamic) 0x%X\n"
3207 "CTL (dynamic) 0x%X\n"
3208 "CTL2 (dynamic) 0x%X\n"
3209 "Status (dynamic) 0x%X\n"
3210 "Rate (dynamic) 0x%X\n",
3212 (int) sizeof(struct txdesc
),
3214 acx2cpu(txdesc
->pNextDesc
),
3215 acx2cpu(txdesc
->AcxMemPtr
),
3216 acx2cpu(txdesc
->HostMemPtr
),
3217 le16_to_cpu(txdesc
->total_length
),
3219 txdesc
->Ctl2_8
, txdesc
->error
,
3221 txdesc
= move_txdesc(priv
, txdesc
, 1);
3224 /* dump host tx descriptor ring buffer */
3226 txhostdesc
= priv
->txhostdesc_start
;
3228 /* loop over complete host send pool */
3229 if (txhostdesc
) for (i
= 0; i
< TX_CNT
* 2; i
++) {
3230 printk("\ndump host txdesc %d:\n"
3232 "buffer mem pos 0x%X\n"
3233 "buffer mem offset 0x%X\n"
3240 acx2cpu(txhostdesc
->data_phy
),
3241 txhostdesc
->data_offset
,
3242 le16_to_cpu(txhostdesc
->Ctl_16
),
3243 le16_to_cpu(txhostdesc
->length
),
3244 acx2cpu(txhostdesc
->desc_phy_next
),
3245 le32_to_cpu(txhostdesc
->Status
));
3249 /* acx_write_reg16(priv, 0xb4, 0x4); */
3251 acx_unlock(priv
, flags
);
3254 acx_sem_unlock(priv
);
3255 #endif /* ACX_DEBUG */
3260 /***********************************************************************
3263 acx100pci_ioctl_set_phy_amp_bias(
3264 struct net_device
*dev
,
3265 struct iw_request_info
*info
,
3266 struct iw_param
*vwrq
,
3269 wlandevice_t
*priv
= netdev_priv(dev
);
3270 unsigned long flags
;
3273 if (!IS_ACX100(priv
)) {
3275 * Removing this check *might* damage
3276 * hardware, since we're tweaking GPIOs here after all!!!
3277 * You've been warned...
3279 printk("acx: sorry, setting bias level for non-acx100 "
3280 "is not supported yet\n");
3285 printk("acx: invalid bias parameter, range is 0-7\n");
3291 /* Need to lock accesses to [IO_ACX_GPIO_OUT]:
3292 * IRQ handler uses it to update LED */
3293 acx_lock(priv
, flags
);
3294 gpio_old
= acx_read_reg16(priv
, IO_ACX_GPIO_OUT
);
3295 acx_write_reg16(priv
, IO_ACX_GPIO_OUT
, (gpio_old
& 0xf8ff) | ((u16
)*extra
<< 8));
3296 acx_unlock(priv
, flags
);
3298 acxlog(L_DEBUG
, "gpio_old: 0x%04X\n", gpio_old
);
3299 printk("%s: PHY power amplifier bias: old:%d, new:%d\n",
3301 (gpio_old
& 0x0700) >> 8, (unsigned char)*extra
);
3303 acx_sem_unlock(priv
);
3309 /***************************************************************
3310 ** acxpci_l_alloc_tx
3311 ** Actually returns a txdesc_t* ptr
3314 acxpci_l_alloc_tx(wlandevice_t
* priv
)
3316 struct txdesc
*txdesc
;
3322 head
= priv
->tx_head
;
3323 txdesc
= get_txdesc(priv
, head
);
3324 ctl8
= txdesc
->Ctl_8
;
3326 /* 2005-10-11: there were several bug reports on this happening
3327 ** but now cause seems to be understood & fixed */
3328 if (unlikely(DESC_CTL_DONE
!= ctl8
)) {
3329 /* whoops, descr at current index is not free, so
3330 * ring buffer completely full??! */
3331 printk("acx: BUG: tx_head:%d Ctl8:0x%02X (expected "
3332 "0x"DESC_CTL_DONE_STR
"): failed to find "
3333 "free tx descr\n", head
, ctl8
);
3339 acxlog(L_BUFT
, "tx: got desc %u, %u remain\n",
3340 head
, priv
->tx_free
);
3342 /* Keep a few free descs between head and tail of tx ring.
3343 ** It is not absolutely needed, just feels safer */
3344 if (priv
->tx_free
< TX_STOP_QUEUE
) {
3345 acxlog(L_BUF
, "stop queue (%u tx desc left)\n",
3347 acx_stop_queue(priv
->netdev
, NULL
);
3350 /* returning current descriptor, so advance to next free one */
3351 priv
->tx_head
= (head
+ 1) % TX_CNT
;
3355 return (tx_t
*)txdesc
;
3359 /***********************************************************************
3362 acxpci_l_get_txbuf(wlandevice_t
*priv
, tx_t
* tx_opaque
)
3364 return acx_get_txhostdesc(priv
, (txdesc_t
*)tx_opaque
)->data
;
3368 /***********************************************************************
3371 ** Can be called from IRQ (rx -> (AP bridging or mgmt response) -> tx).
3372 ** Can be called from acx_i_start_xmit (data frames from net core).
3375 acxpci_l_tx_data(wlandevice_t
*priv
, tx_t
* tx_opaque
, int len
)
3377 txdesc_t
*txdesc
= (txdesc_t
*)tx_opaque
;
3378 txhostdesc_t
*hostdesc1
, *hostdesc2
;
3384 /* fw doesn't tx such packets anyhow */
3385 if (len
< WLAN_HDR_A3_LEN
)
3388 hostdesc1
= acx_get_txhostdesc(priv
, txdesc
);
3389 hostdesc2
= hostdesc1
+ 1;
3391 /* modify flag status in separate variable to be able to write it back
3392 * in one big swoop later (also in order to have less device memory
3394 Ctl_8
= txdesc
->Ctl_8
;
3395 Ctl2_8
= txdesc
->Ctl2_8
;
3397 /* DON'T simply set Ctl field to 0 here globally,
3398 * it needs to maintain a consistent flag status (those are state flags!!),
3399 * otherwise it may lead to severe disruption. Only set or reset particular
3400 * flags at the exact moment this is needed...
3401 * FIXME: what about Ctl2? Equally problematic? */
3403 /* let chip do RTS/CTS handshaking before sending
3404 * in case packet size exceeds threshold */
3405 if (len
> priv
->rts_threshold
)
3406 SET_BIT(Ctl2_8
, DESC_CTL2_RTS
);
3408 CLEAR_BIT(Ctl2_8
, DESC_CTL2_RTS
);
3411 if (priv
->wep_enabled
)
3412 SET_BIT(Ctl2_8
, DESC_CTL2_WEP
);
3414 CLEAR_BIT(Ctl2_8
, DESC_CTL2_WEP
);
3417 switch (priv
->mode
) {
3418 case ACX_MODE_0_ADHOC
:
3420 clt
= acx_l_sta_list_get(priv
, ((wlan_hdr_t
*)hostdesc1
->data
)->a1
);
3422 case ACX_MODE_2_STA
:
3423 clt
= priv
->ap_client
;
3426 /* testing was done on acx111: */
3427 case ACX_MODE_MONITOR
:
3429 /* sends CTS to self before packet */
3430 + DESC_CTL2_SEQ
/* don't increase sequence field */
3431 /* not working (looks like good fcs is still added) */
3432 + DESC_CTL2_FCS
/* don't add the FCS */
3434 + DESC_CTL2_MORE_FRAG
3436 + DESC_CTL2_RETRY
/* don't increase retry field */
3438 + DESC_CTL2_POWER
/* don't increase power mgmt. field */
3440 + DESC_CTL2_WEP
/* encrypt this frame */
3442 + DESC_CTL2_DUR
/* don't increase duration field */
3446 default: /* ACX_MODE_OFF, ACX_MODE_MONITOR */
3451 if (unlikely(clt
&& !clt
->rate_cur
)) {
3452 printk("acx: driver bug! bad ratemask\n");
3456 /* used in tx cleanup routine for auto rate and accounting: */
3457 acx_put_txc(priv
, txdesc
, clt
);
3459 txdesc
->total_length
= cpu_to_le16(len
);
3460 hostdesc2
->length
= cpu_to_le16(len
- WLAN_HDR_A3_LEN
);
3461 if (IS_ACX111(priv
)) {
3462 u16 rate_cur
= clt
? clt
->rate_cur
: priv
->rate_bcast
;
3463 /* note that if !txdesc->do_auto, txrate->cur
3464 ** has only one nonzero bit */
3465 txdesc
->u
.r2
.rate111
= cpu_to_le16(
3467 /* WARNING: I was never able to make it work with prism54 AP.
3468 ** It was falling down to 1Mbit where shortpre is not applicable,
3469 ** and not working at all at "5,11 basic rates only" setting.
3470 ** I even didn't see tx packets in radio packet capture.
3471 ** Disabled for now --vda */
3472 /*| ((clt->shortpre && clt->cur!=RATE111_1) ? RATE111_SHORTPRE : 0) */
3474 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3475 /* should add this to rate111 above as necessary */
3476 | (clt
->pbcc511
? RATE111_PBCC511
: 0)
3478 hostdesc1
->length
= cpu_to_le16(len
);
3479 } else { /* ACX100 */
3480 u8 rate_100
= clt
? clt
->rate_100
: priv
->rate_bcast100
;
3481 txdesc
->u
.r1
.rate
= rate_100
;
3482 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
3484 if (n
== RATE100_5
|| n
== RATE100_11
)
3485 n
|= RATE100_PBCC511
;
3488 if (clt
->shortpre
&& (clt
->cur
!= RATE111_1
))
3489 SET_BIT(Ctl_8
, DESC_CTL_SHORT_PREAMBLE
); /* set Short Preamble */
3491 /* set autodma and reclaim and 1st mpdu */
3492 SET_BIT(Ctl_8
, DESC_CTL_AUTODMA
| DESC_CTL_RECLAIM
| DESC_CTL_FIRSTFRAG
);
3493 hostdesc1
->length
= cpu_to_le16(WLAN_HDR_A3_LEN
);
3495 /* don't need to clean ack/rts statistics here, already
3496 * done on descr cleanup */
3498 /* clears Ctl DESC_CTL_DONE bits, thus telling that the descriptors
3499 * are now owned by the acx; do this as LAST operation */
3500 CLEAR_BIT(Ctl_8
, DESC_CTL_DONE
);
3501 /* flush writes before we release hostdesc to the adapter here */
3503 CLEAR_BIT(hostdesc1
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
3504 CLEAR_BIT(hostdesc2
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
3506 /* write back modified flags */
3507 txdesc
->Ctl2_8
= Ctl2_8
;
3508 txdesc
->Ctl_8
= Ctl_8
;
3510 /* unused: txdesc->tx_time = cpu_to_le32(jiffies); */
3511 //TODO: should it be a mmiowb() instead? we are protecting against race with write[bwl]()
3512 /* flush writes before we tell the adapter that it's its turn now */
3514 acx_write_reg16(priv
, IO_ACX_INT_TRIG
, INT_TRIG_TXPRC
);
3515 acx_write_flush(priv
);
3517 /* log the packet content AFTER sending it,
3518 * in order to not delay sending any further than absolutely needed
3519 * Do separate logs for acx100/111 to have human-readable rates */
3520 if (unlikely(acx_debug
& (L_XFER
|L_DATA
))) {
3521 u16 fc
= ((wlan_hdr_t
*)hostdesc1
->data
)->fc
;
3522 if (IS_ACX111(priv
))
3523 printk("tx: pkt (%s): len %d "
3524 "rate %04X%s status %u\n",
3525 acx_get_packet_type_string(le16_to_cpu(fc
)), len
,
3526 le16_to_cpu(txdesc
->u
.r2
.rate111
),
3527 (le16_to_cpu(txdesc
->u
.r2
.rate111
) & RATE111_SHORTPRE
) ? "(SPr)" : "",
3530 printk("tx: pkt (%s): len %d rate %03u%s status %u\n",
3531 acx_get_packet_type_string(fc
), len
,
3533 (Ctl_8
& DESC_CTL_SHORT_PREAMBLE
) ? "(SPr)" : "",
3536 if (acx_debug
& L_DATA
) {
3537 printk("tx: 802.11 [%d]: ", len
);
3538 acx_dump_bytes(hostdesc1
->data
, len
);
3546 /***********************************************************************
3549 acx_l_handle_tx_error(wlandevice_t
*priv
, u8 error
, unsigned int finger
)
3551 const char *err
= "unknown error";
3553 /* hmm, should we handle this as a mask
3554 * of *several* bits?
3555 * For now I think only caring about
3556 * individual bits is ok... */
3559 err
= "no Tx due to error in other fragment";
3560 priv
->wstats
.discard
.fragment
++;
3564 priv
->stats
.tx_aborted_errors
++;
3567 err
= "Tx desc wrong parameters";
3568 priv
->wstats
.discard
.misc
++;
3571 err
= "WEP key not found";
3572 priv
->wstats
.discard
.misc
++;
3575 err
= "MSDU lifetime timeout? - try changing "
3576 "'iwconfig retry lifetime XXX'";
3577 priv
->wstats
.discard
.misc
++;
3580 err
= "excessive Tx retries due to either distance "
3581 "too high or unable to Tx or Tx frame error - "
3582 "try changing 'iwconfig txpower XXX' or "
3583 "'sens'itivity or 'retry'";
3584 priv
->wstats
.discard
.retries
++;
3585 /* FIXME: set (GETSET_TX|GETSET_RX) here
3586 * (this seems to recalib radio on ACX100)
3587 * after some more jiffies passed??
3588 * But OTOH Tx error 0x20 also seems to occur on
3589 * overheating, so I'm not sure whether we
3590 * actually want that, since people maybe won't notice
3591 * then that their hardware is slowly getting
3593 * Or is it still a safe long distance from utter
3594 * radio non-functionality despite many radio
3596 * to final destructive overheating of the hardware?
3597 * In this case we really should do recalib here...
3598 * I guess the only way to find out is to do a
3599 * potentially fatal self-experiment :-\
3600 * Or maybe only recalib in case we're using Tx
3601 * rate auto (on errors switching to lower speed
3602 * --> less heat?) or 802.11 power save mode? */
3605 * ENABLE_TX|ENABLE_RX helps, so even do
3606 * DISABLE_TX and DISABLE_RX in order to perhaps
3607 * have more impact. */
3608 if (++priv
->retry_errors_msg_ratelimit
% 4 == 0) {
3609 if (priv
->retry_errors_msg_ratelimit
<= 20)
3610 printk("%s: several excessive Tx "
3611 "retry errors occurred, attempting "
3612 "to recalibrate radio. Radio "
3613 "drift might be caused by increasing "
3614 "card temperature, please check the card "
3615 "before it's too late!\n",
3616 priv
->netdev
->name
);
3617 if (priv
->retry_errors_msg_ratelimit
== 20)
3618 printk("disabling above message\n");
3620 acx_schedule_task(priv
, ACX_AFTER_IRQ_CMD_RADIO_RECALIB
);
3624 err
= "Tx buffer overflow";
3625 priv
->stats
.tx_fifo_errors
++;
3629 priv
->wstats
.discard
.misc
++;
3632 priv
->stats
.tx_errors
++;
3633 if (priv
->stats
.tx_errors
<= 20)
3634 printk("%s: tx error 0x%02X, buf %02u! (%s)\n",
3635 priv
->netdev
->name
, error
, finger
, err
);
3637 printk("%s: tx error 0x%02X, buf %02u!\n",
3638 priv
->netdev
->name
, error
, finger
);
3642 /***********************************************************************
3644 /* Theory of operation:
3645 ** client->rate_cap is a bitmask of rates client is capable of.
3646 ** client->rate_cfg is a bitmask of allowed (configured) rates.
3647 ** It is set as a result of iwconfig rate N [auto]
3648 ** or iwpriv set_rates "N,N,N N,N,N" commands.
3649 ** It can be fixed (e.g. 0x0080 == 18Mbit only),
3650 ** auto (0x00ff == 18Mbit or any lower value),
3651 ** and code handles any bitmask (0x1081 == try 54Mbit,18Mbit,1Mbit _only_).
3653 ** client->rate_cur is a value for rate111 field in tx descriptor.
3654 ** It is always set to txrate_cfg sans zero or more most significant
3655 ** bits. This routine handles selection of new rate_cur value depending on
3656 ** outcome of last tx event.
3658 ** client->rate_100 is a precalculated rate value for acx100
3659 ** (we can do without it, but will need to calculate it on each tx).
3661 ** You cannot configure mixed usage of 5.5 and/or 11Mbit rate
3662 ** with PBCC and CCK modulation. Either both at CCK or both at PBCC.
3663 ** In theory you can implement it, but so far it is considered not worth doing.
3665 ** 22Mbit, of course, is PBCC always. */
3667 /* maps acx100 tx descr rate field to acx111 one */
3672 case RATE100_1
: return RATE111_1
;
3673 case RATE100_2
: return RATE111_2
;
3675 case (RATE100_5
| RATE100_PBCC511
): return RATE111_5
;
3677 case (RATE100_11
| RATE100_PBCC511
): return RATE111_11
;
3678 case RATE100_22
: return RATE111_22
;
3680 printk("acx: unexpected acx100 txrate: %u! "
3681 "Please report\n", r
);
3688 acx_l_handle_txrate_auto(wlandevice_t
*priv
, struct client
*txc
,
3689 unsigned int idx
, u8 rate100
, u16 rate111
, u8 error
)
3692 u16 cur
= txc
->rate_cur
;
3693 int slower_rate_was_used
;
3695 /* FIXME: need to implement some kind of rate success memory
3696 * which stores the success percentage per rate, to be taken
3697 * into account when considering allowing a new rate, since it
3698 * doesn't really help to stupidly count fallback/stepup,
3699 * since one invalid rate will spoil the party anyway
3700 * (such as 22M in case of 11M-only peers) */
3702 /* vda: hmm. current code will do this:
3703 ** 1. send packets at 11 Mbit, stepup++
3704 ** 2. will try to send at 22Mbit. hardware will see no ACK,
3705 ** retries at 11Mbit, success. code notes that used rate
3706 ** is lower. stepup = 0, fallback++
3707 ** 3. repeat step 2 fallback_count times. Fall back to
3708 ** 11Mbit. go to step 1.
3709 ** If stepup_count is large (say, 16) and fallback_count
3710 ** is small (3), this wouldn't be too bad wrt throughput */
3712 /* do some preparations, i.e. calculate the one rate that was
3713 * used to send this packet */
3714 if (IS_ACX111(priv
)) {
3715 sent_rate
= 1 << highest_bit(rate111
& RATE111_ALL
);
3717 sent_rate
= rate100to111(rate100
);
3719 /* sent_rate has only one bit set now, corresponding to tx rate
3720 * which was used by hardware to tx this particular packet */
3722 /* now do the actual auto rate management */
3723 acxlog(L_DEBUG
, "tx: %sclient=%p/"MACSTR
" used=%04X cur=%04X cfg=%04X "
3724 "__=%u/%u ^^=%u/%u\n",
3725 (txc
->ignore_count
> 0) ? "[IGN] " : "",
3726 txc
, MAC(txc
->address
), sent_rate
, cur
, txc
->rate_cfg
,
3727 txc
->fallback_count
, priv
->fallback_threshold
,
3728 txc
->stepup_count
, priv
->stepup_threshold
3731 /* we need to ignore old packets already in the tx queue since
3732 * they use older rate bytes configured before our last rate change,
3733 * otherwise our mechanism will get confused by interpreting old data.
3734 * Do it here only, in order to have the logging above */
3735 if (txc
->ignore_count
) {
3736 txc
->ignore_count
--;
3740 /* true only if the only nonzero bit in sent_rate is
3741 ** less significant than highest nonzero bit in cur */
3742 slower_rate_was_used
= ( cur
> ((sent_rate
<<1)-1) );
3744 if (slower_rate_was_used
|| (error
& 0x30)) {
3745 txc
->stepup_count
= 0;
3746 if (++txc
->fallback_count
<= priv
->fallback_threshold
)
3748 txc
->fallback_count
= 0;
3750 /* clear highest 1 bit in cur */
3751 sent_rate
= RATE111_54
;
3752 while (!(cur
& sent_rate
)) sent_rate
>>= 1;
3753 CLEAR_BIT(cur
, sent_rate
);
3755 if (cur
) { /* we can't disable all rates! */
3756 acxlog(L_XFER
, "tx: falling back to ratemask %04X\n", cur
);
3757 txc
->rate_cur
= cur
;
3758 txc
->ignore_count
= TX_CNT
- priv
->tx_free
;
3760 } else if (!slower_rate_was_used
) {
3761 txc
->fallback_count
= 0;
3762 if (++txc
->stepup_count
<= priv
->stepup_threshold
)
3764 txc
->stepup_count
= 0;
3766 /* sanitize. Sort of not needed, but I dont trust hw that much...
3767 ** what if it can report bogus tx rates sometimes? */
3768 while (!(cur
& sent_rate
)) sent_rate
>>= 1;
3769 /* try to find a higher sent_rate that isn't yet in our
3770 * current set, but is an allowed cfg */
3773 if (sent_rate
> txc
->rate_cfg
)
3774 /* no higher rates allowed by config */
3776 if (!(cur
& sent_rate
) && (txc
->rate_cfg
& sent_rate
))
3779 /* not found, try higher one */
3781 SET_BIT(cur
, sent_rate
);
3782 acxlog(L_XFER
, "tx: stepping up to ratemask %04X\n", cur
);
3783 txc
->rate_cur
= cur
;
3784 /* FIXME: totally bogus - we could be sending to many peers at once... */
3785 txc
->ignore_count
= TX_CNT
- priv
->tx_free
;
3788 /* calculate acx100 style rate byte if needed */
3789 if (IS_ACX100(priv
)) {
3790 txc
->rate_100
= bitpos2rate100
[highest_bit(cur
)];
3795 /***********************************************************************
3796 ** acx_l_log_txbuffer
3799 static inline void acx_l_log_txbuffer(const wlandevice_t
*priv
) {}
3802 acx_l_log_txbuffer(wlandevice_t
*priv
)
3807 /* no FN_ENTER here, we don't want that */
3808 /* no locks here, since it's entirely non-critical code */
3809 txdesc
= priv
->txdesc_start
;
3810 if (!txdesc
) return;
3811 printk("tx: desc->Ctl8's:");
3812 for (i
= 0; i
< TX_CNT
; i
++) {
3813 printk(" %02X", txdesc
->Ctl_8
);
3814 txdesc
= move_txdesc(priv
, txdesc
, 1);
3821 /***********************************************************************
3822 ** acx_l_clean_tx_desc
3824 ** This function resets the txdescs' status when the ACX100
3825 ** signals the TX done IRQ (txdescs have been processed), starting with
3826 ** the pool index of the descriptor which we would use next,
3827 ** in order to make sure that we can be as fast as possible
3828 ** in filling new txdescs.
3829 ** Oops, now we have our own index, so everytime we get called we know
3830 ** where the next packet to be cleaned is.
3831 ** Hmm, still need to loop through the whole ring buffer now,
3832 ** since we lost sync for some reason when ping flooding or so...
3833 ** (somehow we don't get the IRQ for acx_l_clean_tx_desc any more when
3834 ** too many packets are being sent!)
3835 ** FIXME: currently we only process one packet, but this gets out of
3836 ** sync for some reason when ping flooding, so we need to loop,
3837 ** but the previous smart loop implementation causes the ping latency
3838 ** to rise dramatically (~3000 ms), at least on CardBus PheeNet WL-0022.
3839 ** Dunno what to do :-\
3842 acx_l_clean_tx_desc(wlandevice_t
*priv
)
3849 u8 error
, ack_failures
, rts_failures
, rts_ok
, r100
;
3853 if (unlikely(acx_debug
& L_DEBUG
))
3854 acx_l_log_txbuffer(priv
);
3856 acxlog(L_BUFT
, "tx: cleaning up bufs from %u\n", priv
->tx_tail
);
3858 /* We know first descr which is not free yet. We advance it as far
3859 ** as we see correct bits set in following descs (if next desc
3860 ** is NOT free, we shouldn't advance at all). We know that in
3861 ** front of tx_tail may be "holes" with isolated free descs.
3862 ** We will catch up when all intermediate descs will be freed also */
3864 finger
= priv
->tx_tail
;
3866 while (finger
!= priv
->tx_head
) {
3867 txdesc
= get_txdesc(priv
, finger
);
3869 /* If we allocated txdesc on tx path but then decided
3870 ** to NOT use it, then it will be left as a free "bubble"
3871 ** in the "allocated for tx" part of the ring.
3872 ** We may meet it on the next ring pass here. */
3874 /* stop if not marked as "tx finished" and "host owned" */
3875 if ((txdesc
->Ctl_8
& DESC_CTL_DONE
) != DESC_CTL_DONE
) {
3876 /* Moan a lot if none was cleaned */
3878 if (!(acx_debug
& L_DEBUG
))
3879 acx_l_log_txbuffer(priv
);
3880 printk("%s: clean_tx_desc: tail is not free. "
3881 "tail:%d head:%d. Please report\n",
3883 priv
->tx_tail
, priv
->tx_head
);
3888 /* remember desc values... */
3889 error
= txdesc
->error
;
3890 ack_failures
= txdesc
->ack_failures
;
3891 rts_failures
= txdesc
->rts_failures
;
3892 rts_ok
= txdesc
->rts_ok
;
3893 r100
= txdesc
->u
.r1
.rate
;
3894 r111
= txdesc
->u
.r2
.rate111
;
3896 #if WIRELESS_EXT > 13 /* wireless_send_event() and IWEVTXDROP are WE13 */
3897 /* need to check for certain error conditions before we
3898 * clean the descriptor: we still need valid descr data here */
3899 if (unlikely(0x30 & error
)) {
3900 /* only send IWEVTXDROP in case of retry or lifetime exceeded;
3901 * all other errors mean we screwed up locally */
3902 union iwreq_data wrqu
;
3904 txhostdesc_t
*hostdesc
;
3906 hostdesc
= acx_get_txhostdesc(priv
, txdesc
);
3907 hdr
= (wlan_hdr_t
*)hostdesc
->data
;
3908 MAC_COPY(wrqu
.addr
.sa_data
, hdr
->a1
);
3909 wireless_send_event(priv
->netdev
, IWEVTXDROP
, &wrqu
, NULL
);
3912 /* ...and free the desc */
3914 txdesc
->ack_failures
= 0;
3915 txdesc
->rts_failures
= 0;
3918 /* Signal host owning it LAST, since ACX already knows that this
3919 ** descriptor is finished since it set Ctl_8 accordingly.
3920 ** NB: older code was setting it to HOSTOWN.
3921 ** This would cause problem if txdesc got allocated but not
3922 ** submitted for tx (left as a "bubble") */
3924 /* TODO: we may avoid setting this at all (just slightly modify
3925 ** check in alloc_tx) since DESC_CTL_DONE bits are already set */
3927 txdesc
->Ctl_8
= DESC_CTL_DONE
;
3931 if ((priv
->tx_free
>= TX_START_QUEUE
)
3932 && (priv
->status
== ACX_STATUS_4_ASSOCIATED
)
3933 && (acx_queue_stopped(priv
->netdev
))
3935 acxlog(L_BUF
, "tx: wake queue (avail. Tx desc %u)\n",
3937 acx_wake_queue(priv
->netdev
, NULL
);
3940 /* do error checking, rate handling and logging
3941 * AFTER having done the work, it's faster */
3943 /* do rate handling */
3944 txc
= acx_get_txc(priv
, txdesc
);
3945 if (txc
&& priv
->rate_auto
) {
3946 acx_l_handle_txrate_auto(priv
, txc
, finger
, r100
, r111
, error
);
3949 if (unlikely(error
))
3950 acx_l_handle_tx_error(priv
, error
, finger
);
3952 if (IS_ACX111(priv
))
3953 acxlog(L_BUFT
, "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u r111=%04X\n",
3954 finger
, ack_failures
, rts_failures
, rts_ok
, r111
);
3956 acxlog(L_BUFT
, "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u rate=%u\n",
3957 finger
, ack_failures
, rts_failures
, rts_ok
, r100
);
3959 /* update pointer for descr to be cleaned next */
3960 finger
= (finger
+ 1) % TX_CNT
;
3963 /* remember last position */
3964 priv
->tx_tail
= finger
;
3966 FN_EXIT1(num_cleaned
);
3970 /* clean *all* Tx descriptors, and regardless of their previous state.
3971 * Used for brute-force reset handling. */
3973 acx_l_clean_tx_desc_emergency(wlandevice_t
*priv
)
3980 for (i
= 0; i
< TX_CNT
; i
++) {
3981 txdesc
= get_txdesc(priv
, i
);
3984 txdesc
->ack_failures
= 0;
3985 txdesc
->rts_failures
= 0;
3988 txdesc
->Ctl_8
= DESC_CTL_DONE
;
3991 priv
->tx_free
= TX_CNT
;
3997 /***********************************************************************
3998 ** acx_l_log_rxbuffer
4000 ** Called from IRQ context only
4003 static inline void acx_l_log_rxbuffer(const wlandevice_t
*priv
) {}
4006 acx_l_log_rxbuffer(const wlandevice_t
*priv
)
4008 const struct rxhostdesc
*rxhostdesc
;
4011 /* no FN_ENTER here, we don't want that */
4013 rxhostdesc
= priv
->rxhostdesc_start
;
4014 if (!rxhostdesc
) return;
4015 for (i
= 0; i
< RX_CNT
; i
++) {
4016 if ((rxhostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
4017 && (rxhostdesc
->Status
& cpu_to_le32(DESC_STATUS_FULL
)))
4018 printk("rx: buf %d full\n", i
);
4025 /***************************************************************
4026 ** acx_l_process_rx_desc
4028 ** Called directly and only from the IRQ handler
4031 acx_l_process_rx_desc(wlandevice_t
*priv
)
4033 rxhostdesc_t
*hostdesc
;
4038 if (unlikely(acx_debug
& L_BUFR
)) {
4039 acx_l_log_rxbuffer(priv
);
4042 /* First, have a loop to determine the first descriptor that's
4043 * full, just in case there's a mismatch between our current
4044 * rx_tail and the full descriptor we're supposed to handle. */
4046 tail
= priv
->rx_tail
;
4048 hostdesc
= &priv
->rxhostdesc_start
[tail
];
4049 /* advance tail regardless of outcome of the below test */
4050 tail
= (tail
+ 1) % RX_CNT
;
4052 if ((hostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
4053 && (hostdesc
->Status
& cpu_to_le32(DESC_STATUS_FULL
)))
4054 break; /* found it! */
4056 if (--count
) /* hmm, no luck: all descs empty, bail out */
4060 /* now process descriptors, starting with the first we figured out */
4062 acxlog(L_BUFR
, "rx: tail=%u Ctl_16=%04X Status=%08X\n",
4063 tail
, hostdesc
->Ctl_16
, hostdesc
->Status
);
4065 acx_l_process_rxbuf(priv
, hostdesc
->data
);
4067 hostdesc
->Status
= 0;
4068 /* flush all writes before adapter sees CTL_HOSTOWN change */
4070 /* Host no longer owns this, needs to be LAST */
4071 CLEAR_BIT(hostdesc
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
4073 /* ok, descriptor is handled, now check the next descriptor */
4074 hostdesc
= &priv
->rxhostdesc_start
[tail
];
4076 /* if next descriptor is empty, then bail out */
4077 if (!(hostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
4078 || !(hostdesc
->Status
& cpu_to_le32(DESC_STATUS_FULL
)))
4081 tail
= (tail
+ 1) % RX_CNT
;
4084 priv
->rx_tail
= tail
;
4089 /***********************************************************************
4090 ** acx_s_create_tx_host_desc_queue
4093 acx_alloc_coherent(struct pci_dev
*hwdev
, size_t size
,
4094 dma_addr_t
*dma_handle
, int flag
)
4096 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 53)
4097 return dma_alloc_coherent(hwdev
== NULL
? NULL
: &hwdev
->dev
,
4098 size
, dma_handle
, flag
);
4100 #warning Using old PCI-specific DMA allocation, may fail with out-of-mem!
4101 #warning Upgrade kernel if it does...
4102 return pci_alloc_consistent(hwdev
, size
, dma_handle
);
4107 allocate(wlandevice_t
*priv
, size_t size
, dma_addr_t
*phy
, const char *msg
)
4109 void *ptr
= acx_alloc_coherent(priv
->pdev
, size
, phy
, GFP_KERNEL
);
4111 acxlog(L_DEBUG
, "%s sz=%d adr=0x%p phy=0x%08llx\n",
4112 msg
, (int)size
, ptr
, (unsigned long long)*phy
);
4113 memset(ptr
, 0, size
);
4116 printk(KERN_ERR
"acx: %s allocation FAILED (%d bytes)\n",
4122 acx_s_create_tx_host_desc_queue(wlandevice_t
*priv
)
4124 txhostdesc_t
*hostdesc
;
4126 dma_addr_t hostdesc_phy
;
4127 dma_addr_t txbuf_phy
;
4132 /* allocate TX buffer */
4133 priv
->txbuf_area_size
= TX_CNT
* WLAN_A4FR_MAXLEN_WEP_FCS
;
4134 priv
->txbuf_start
= allocate(priv
, priv
->txbuf_area_size
,
4135 &priv
->txbuf_startphy
, "txbuf_start");
4136 if (!priv
->txbuf_start
)
4139 /* allocate the TX host descriptor queue pool */
4140 priv
->txhostdesc_area_size
= TX_CNT
* 2*sizeof(txhostdesc_t
);
4141 priv
->txhostdesc_start
= allocate(priv
, priv
->txhostdesc_area_size
,
4142 &priv
->txhostdesc_startphy
, "txhostdesc_start");
4143 if (!priv
->txhostdesc_start
)
4145 /* check for proper alignment of TX host descriptor pool */
4146 if ((long) priv
->txhostdesc_start
& 3) {
4147 printk("acx: driver bug: dma alloc returns unaligned address\n");
4151 /* Each tx frame buffer is accessed by hardware via
4152 ** txdesc -> txhostdesc(s) -> framebuffer(s)
4153 ** We use only one txhostdesc per txdesc, but it looks like
4154 ** acx111 is buggy: it accesses second txhostdesc
4155 ** (via hostdesc.desc_phy_next field) even if
4156 ** txdesc->length == hostdesc->length and thus
4157 ** entire packet was placed into first txhostdesc.
4158 ** Due to this bug acx111 hangs unless second txhostdesc
4159 ** has hostdesc.length = 3 (or larger)
4160 ** Storing NULL into hostdesc.desc_phy_next
4161 ** doesn't seem to help.
4163 ** It is not known whether we need to have 'extra' second
4164 ** txhostdescs for acx100. Maybe it is acx111-only bug.
4166 ** Update: acx111 WG311v2 is even more bogus than this.
4167 ** We will initialize two hostdesc so that they point
4168 ** to adjacent memory areas.
4170 hostdesc
= priv
->txhostdesc_start
;
4171 hostdesc_phy
= priv
->txhostdesc_startphy
;
4172 txbuf
= priv
->txbuf_start
;
4173 txbuf_phy
= priv
->txbuf_startphy
;
4176 /* Works for xterasys xn2522g, does not for WG311v2 !!? */
4177 for (i
= 0; i
< TX_CNT
*2; i
++) {
4178 hostdesc_phy
+= sizeof(txhostdesc_t
);
4180 hostdesc
->data_phy
= cpu2acx(txbuf_phy
);
4181 /* hostdesc->data_offset = ... */
4182 /* hostdesc->reserved = ... */
4183 hostdesc
->Ctl_16
= cpu_to_le16(DESC_CTL_HOSTOWN
);
4184 /* hostdesc->length = ... */
4185 hostdesc
->desc_phy_next
= cpu2acx(hostdesc_phy
);
4186 hostdesc
->pNext
= ptr2acx(NULL
);
4187 /* hostdesc->Status = ... */
4188 /* below: non-hardware fields */
4189 hostdesc
->data
= txbuf
;
4191 txbuf
+= WLAN_A4FR_MAXLEN_WEP_FCS
;
4192 txbuf_phy
+= WLAN_A4FR_MAXLEN_WEP_FCS
;
4194 /* hostdesc->data_phy = ... */
4195 /* hostdesc->data_offset = ... */
4196 /* hostdesc->reserved = ... */
4197 /* hostdesc->Ctl_16 = ... */
4198 hostdesc
->length
= 3; /* bug workaround */
4199 /* hostdesc->desc_phy_next = ... */
4200 /* hostdesc->pNext = ... */
4201 /* hostdesc->Status = ... */
4202 /* below: non-hardware fields */
4203 /* hostdesc->data = ... */
4208 for (i
= 0; i
< TX_CNT
*2; i
++) {
4209 hostdesc_phy
+= sizeof(txhostdesc_t
);
4211 hostdesc
->data_phy
= cpu2acx(txbuf_phy
);
4212 /* done by memset(0): hostdesc->data_offset = 0; */
4213 /* hostdesc->reserved = ... */
4214 hostdesc
->Ctl_16
= cpu_to_le16(DESC_CTL_HOSTOWN
);
4215 /* hostdesc->length = ... */
4216 hostdesc
->desc_phy_next
= cpu2acx(hostdesc_phy
);
4217 /* done by memset(0): hostdesc->pNext = ptr2acx(NULL); */
4218 /* hostdesc->Status = ... */
4219 /* ->data is a non-hardware field: */
4220 hostdesc
->data
= txbuf
;
4223 txbuf
+= WLAN_HDR_A3_LEN
;
4224 txbuf_phy
+= WLAN_HDR_A3_LEN
;
4226 txbuf
+= WLAN_A4FR_MAXLEN_WEP_FCS
- WLAN_HDR_A3_LEN
;
4227 txbuf_phy
+= WLAN_A4FR_MAXLEN_WEP_FCS
- WLAN_HDR_A3_LEN
;
4232 hostdesc
->desc_phy_next
= cpu2acx(priv
->txhostdesc_startphy
);
4237 printk("acx: create_tx_host_desc_queue FAILED\n");
4238 /* dealloc will be done by free function on error case */
4244 /***************************************************************
4245 ** acx_s_create_rx_host_desc_queue
4247 /* the whole size of a data buffer (header plus data body)
4248 * plus 32 bytes safety offset at the end */
4249 #define RX_BUFFER_SIZE (sizeof(rxbuffer_t) + 32)
4252 acx_s_create_rx_host_desc_queue(wlandevice_t
*priv
)
4254 rxhostdesc_t
*hostdesc
;
4256 dma_addr_t hostdesc_phy
;
4257 dma_addr_t rxbuf_phy
;
4262 /* allocate the RX host descriptor queue pool */
4263 priv
->rxhostdesc_area_size
= RX_CNT
* sizeof(rxhostdesc_t
);
4264 priv
->rxhostdesc_start
= allocate(priv
, priv
->rxhostdesc_area_size
,
4265 &priv
->rxhostdesc_startphy
, "rxhostdesc_start");
4266 if (!priv
->rxhostdesc_start
)
4268 /* check for proper alignment of RX host descriptor pool */
4269 if ((long) priv
->rxhostdesc_start
& 3) {
4270 printk("acx: driver bug: dma alloc returns unaligned address\n");
4274 /* allocate Rx buffer pool which will be used by the acx
4275 * to store the whole content of the received frames in it */
4276 priv
->rxbuf_area_size
= RX_CNT
* RX_BUFFER_SIZE
;
4277 priv
->rxbuf_start
= allocate(priv
, priv
->rxbuf_area_size
,
4278 &priv
->rxbuf_startphy
, "rxbuf_start");
4279 if (!priv
->rxbuf_start
)
4282 rxbuf
= priv
->rxbuf_start
;
4283 rxbuf_phy
= priv
->rxbuf_startphy
;
4284 hostdesc
= priv
->rxhostdesc_start
;
4285 hostdesc_phy
= priv
->rxhostdesc_startphy
;
4287 /* don't make any popular C programming pointer arithmetic mistakes
4288 * here, otherwise I'll kill you...
4289 * (and don't dare asking me why I'm warning you about that...) */
4290 for (i
= 0; i
< RX_CNT
; i
++) {
4291 hostdesc
->data
= rxbuf
;
4292 hostdesc
->data_phy
= cpu2acx(rxbuf_phy
);
4293 hostdesc
->length
= cpu_to_le16(RX_BUFFER_SIZE
);
4294 CLEAR_BIT(hostdesc
->Ctl_16
, cpu_to_le16(DESC_CTL_HOSTOWN
));
4296 rxbuf_phy
+= sizeof(rxbuffer_t
);
4297 hostdesc_phy
+= sizeof(rxhostdesc_t
);
4298 hostdesc
->desc_phy_next
= cpu2acx(hostdesc_phy
);
4302 hostdesc
->desc_phy_next
= cpu2acx(priv
->rxhostdesc_startphy
);
4306 printk("acx: create_rx_host_desc_queue FAILED\n");
4307 /* dealloc will be done by free function on error case */
4313 /***************************************************************
4314 ** acx_s_create_hostdesc_queues
4317 acx_s_create_hostdesc_queues(wlandevice_t
*priv
)
4320 result
= acx_s_create_tx_host_desc_queue(priv
);
4321 if (OK
!= result
) return result
;
4322 result
= acx_s_create_rx_host_desc_queue(priv
);
4327 /***************************************************************
4328 ** acx_create_tx_desc_queue
4331 acx_create_tx_desc_queue(wlandevice_t
*priv
, u32 tx_queue_start
)
4334 txhostdesc_t
*hostdesc
;
4335 dma_addr_t hostmemptr
;
4341 priv
->txdesc_size
= sizeof(txdesc_t
);
4343 if (IS_ACX111(priv
)) {
4344 /* the acx111 txdesc is 4 bytes larger */
4345 priv
->txdesc_size
= sizeof(txdesc_t
) + 4;
4348 priv
->txdesc_start
= (txdesc_t
*) (priv
->iobase2
+ tx_queue_start
);
4350 acxlog(L_DEBUG
, "priv->iobase2=%p\n"
4351 "tx_queue_start=%08X\n"
4352 "priv->txdesc_start=%p\n",
4355 priv
->txdesc_start
);
4357 priv
->tx_free
= TX_CNT
;
4358 /* done by memset: priv->tx_head = 0; */
4359 /* done by memset: priv->tx_tail = 0; */
4360 txdesc
= priv
->txdesc_start
;
4361 mem_offs
= tx_queue_start
;
4362 hostmemptr
= priv
->txhostdesc_startphy
;
4363 hostdesc
= priv
->txhostdesc_start
;
4365 if (IS_ACX111(priv
)) {
4366 /* ACX111 has a preinitialized Tx buffer! */
4367 /* loop over whole send pool */
4368 /* FIXME: do we have to do the hostmemptr stuff here?? */
4369 for (i
= 0; i
< TX_CNT
; i
++) {
4370 txdesc
->HostMemPtr
= ptr2acx(hostmemptr
);
4371 txdesc
->Ctl_8
= DESC_CTL_DONE
;
4372 /* reserve two (hdr desc and payload desc) */
4374 hostmemptr
+= 2 * sizeof(txhostdesc_t
);
4375 txdesc
= move_txdesc(priv
, txdesc
, 1);
4378 /* ACX100 Tx buffer needs to be initialized by us */
4379 /* clear whole send pool. sizeof is safe here (we are acx100) */
4380 memset(priv
->txdesc_start
, 0, TX_CNT
* sizeof(txdesc_t
));
4382 /* loop over whole send pool */
4383 for (i
= 0; i
< TX_CNT
; i
++) {
4384 acxlog(L_DEBUG
, "configure card tx descriptor: 0x%p, "
4385 "size: 0x%X\n", txdesc
, priv
->txdesc_size
);
4387 /* pointer to hostdesc memory */
4388 /* FIXME: type-incorrect assignment, might cause trouble
4390 txdesc
->HostMemPtr
= ptr2acx(hostmemptr
);
4391 /* initialise ctl */
4392 txdesc
->Ctl_8
= DESC_CTL_INIT
;
4394 /* point to next txdesc */
4395 txdesc
->pNextDesc
= cpu2acx(mem_offs
+ priv
->txdesc_size
);
4396 /* reserve two (hdr desc and payload desc) */
4398 hostmemptr
+= 2 * sizeof(txhostdesc_t
);
4399 /* go to the next one */
4400 mem_offs
+= priv
->txdesc_size
;
4401 /* ++ is safe here (we are acx100) */
4404 /* go back to the last one */
4406 /* and point to the first making it a ring buffer */
4407 txdesc
->pNextDesc
= cpu2acx(tx_queue_start
);
4413 /***************************************************************
4414 ** acx_create_rx_desc_queue
4417 acx_create_rx_desc_queue(wlandevice_t
*priv
, u32 rx_queue_start
)
4425 /* done by memset: priv->rx_tail = 0; */
4427 /* ACX111 doesn't need any further config: preconfigures itself.
4428 * Simply print ring buffer for debugging */
4429 if (IS_ACX111(priv
)) {
4430 /* rxdesc_start already set here */
4432 priv
->rxdesc_start
= (rxdesc_t
*) ((u8
*)priv
->iobase2
+ rx_queue_start
);
4434 rxdesc
= priv
->rxdesc_start
;
4435 for (i
= 0; i
< RX_CNT
; i
++) {
4436 acxlog(L_DEBUG
, "rx descriptor %d @ 0x%p\n", i
, rxdesc
);
4437 rxdesc
= priv
->rxdesc_start
= (rxdesc_t
*)
4438 (priv
->iobase2
+ acx2cpu(rxdesc
->pNextDesc
));
4441 /* we didn't pre-calculate rxdesc_start in case of ACX100 */
4442 /* rxdesc_start should be right AFTER Tx pool */
4443 priv
->rxdesc_start
= (rxdesc_t
*)
4444 ((u8
*) priv
->txdesc_start
+ (TX_CNT
* sizeof(txdesc_t
)));
4445 /* NB: sizeof(txdesc_t) above is valid because we know
4446 ** we are in if(acx100) block. Beware of cut-n-pasting elsewhere!
4447 ** acx111's txdesc is larger! */
4449 memset(priv
->rxdesc_start
, 0, RX_CNT
* sizeof(rxdesc_t
));
4451 /* loop over whole receive pool */
4452 rxdesc
= priv
->rxdesc_start
;
4453 mem_offs
= rx_queue_start
;
4454 for (i
= 0; i
< RX_CNT
; i
++) {
4455 acxlog(L_DEBUG
, "rx descriptor @ 0x%p\n", rxdesc
);
4456 rxdesc
->Ctl_8
= DESC_CTL_RECLAIM
| DESC_CTL_AUTODMA
;
4457 /* point to next rxdesc */
4458 rxdesc
->pNextDesc
= cpu2acx(mem_offs
+ sizeof(rxdesc_t
));
4459 /* go to the next one */
4460 mem_offs
+= sizeof(rxdesc_t
);
4463 /* go to the last one */
4466 /* and point to the first making it a ring buffer */
4467 rxdesc
->pNextDesc
= cpu2acx(rx_queue_start
);
4473 /***************************************************************
4474 ** acx_create_desc_queues
4477 acx_create_desc_queues(wlandevice_t
*priv
, u32 tx_queue_start
, u32 rx_queue_start
)
4479 acx_create_tx_desc_queue(priv
, tx_queue_start
);
4480 acx_create_rx_desc_queue(priv
, rx_queue_start
);
4484 /***************************************************************
4485 ** acxpci_s_proc_diag_output
4488 acxpci_s_proc_diag_output(char *p
, wlandevice_t
*priv
)
4490 const char *rtl
, *thd
, *ttl
;
4491 rxhostdesc_t
*rxhostdesc
;
4497 p
+= sprintf(p
, "** Rx buf **\n");
4498 rxhostdesc
= priv
->rxhostdesc_start
;
4499 if (rxhostdesc
) for (i
= 0; i
< RX_CNT
; i
++) {
4500 rtl
= (i
== priv
->rx_tail
) ? " [tail]" : "";
4501 if ((rxhostdesc
->Ctl_16
& cpu_to_le16(DESC_CTL_HOSTOWN
))
4502 && (rxhostdesc
->Status
& cpu_to_le32(DESC_STATUS_FULL
)) )
4503 p
+= sprintf(p
, "%02u FULL%s\n", i
, rtl
);
4505 p
+= sprintf(p
, "%02u empty%s\n", i
, rtl
);
4508 p
+= sprintf(p
, "** Tx buf (free %d, Linux netqueue %s) **\n", priv
->tx_free
,
4509 acx_queue_stopped(priv
->netdev
) ? "STOPPED" : "running");
4510 txdesc
= priv
->txdesc_start
;
4511 if (txdesc
) for (i
= 0; i
< TX_CNT
; i
++) {
4512 thd
= (i
== priv
->tx_head
) ? " [head]" : "";
4513 ttl
= (i
== priv
->tx_tail
) ? " [tail]" : "";
4514 if (txdesc
->Ctl_8
& DESC_CTL_ACXDONE
)
4515 p
+= sprintf(p
, "%02u free (%02X)%s%s\n", i
, txdesc
->Ctl_8
, thd
, ttl
);
4517 p
+= sprintf(p
, "%02u tx (%02X)%s%s\n", i
, txdesc
->Ctl_8
, thd
, ttl
);
4518 txdesc
= move_txdesc(priv
, txdesc
, 1);
4523 "txbuf_start %p, txbuf_area_size %u, txbuf_startphy %08llx\n"
4524 "txdesc_size %u, txdesc_start %p\n"
4525 "txhostdesc_start %p, txhostdesc_area_size %u, txhostdesc_startphy %08llx\n"
4527 "rxhostdesc_start %p, rxhostdesc_area_size %u, rxhostdesc_startphy %08llx\n"
4528 "rxbuf_start %p, rxbuf_area_size %u, rxbuf_startphy %08llx\n",
4529 priv
->txbuf_start
, priv
->txbuf_area_size
, (u64
)priv
->txbuf_startphy
,
4530 priv
->txdesc_size
, priv
->txdesc_start
,
4531 priv
->txhostdesc_start
, priv
->txhostdesc_area_size
, (u64
)priv
->txhostdesc_startphy
,
4533 priv
->rxhostdesc_start
, priv
->rxhostdesc_area_size
, (u64
)priv
->rxhostdesc_startphy
,
4534 priv
->rxbuf_start
, priv
->rxbuf_area_size
, (u64
)priv
->rxbuf_startphy
);
4541 /***********************************************************************
4544 acx_proc_eeprom_output(char *buf
, wlandevice_t
*priv
)
4551 for (i
= 0; i
< 0x400; i
++) {
4552 acx_read_eeprom_offset(priv
, i
, p
++);
4560 /***********************************************************************
4563 acx_set_interrupt_mask(wlandevice_t
*priv
)
4565 if (IS_ACX111(priv
)) {
4566 priv
->irq_mask
= (u16
) ~(0
4567 /* | HOST_INT_RX_DATA */
4568 | HOST_INT_TX_COMPLETE
4569 /* | HOST_INT_TX_XFER */
4570 | HOST_INT_RX_COMPLETE
4571 /* | HOST_INT_DTIM */
4572 /* | HOST_INT_BEACON */
4573 /* | HOST_INT_TIMER */
4574 /* | HOST_INT_KEY_NOT_FOUND */
4575 | HOST_INT_IV_ICV_FAILURE
4576 | HOST_INT_CMD_COMPLETE
4578 /* | HOST_INT_OVERFLOW */
4579 /* | HOST_INT_PROCESS_ERROR */
4580 | HOST_INT_SCAN_COMPLETE
4581 | HOST_INT_FCS_THRESHOLD
4582 /* | HOST_INT_UNKNOWN */
4584 priv
->irq_mask_off
= (u16
)~( HOST_INT_CMD_COMPLETE
); /* 0xfdff */
4586 priv
->irq_mask
= (u16
) ~(0
4587 /* | HOST_INT_RX_DATA */
4588 | HOST_INT_TX_COMPLETE
4589 /* | HOST_INT_TX_XFER */
4590 | HOST_INT_RX_COMPLETE
4591 /* | HOST_INT_DTIM */
4592 /* | HOST_INT_BEACON */
4593 /* | HOST_INT_TIMER */
4594 /* | HOST_INT_KEY_NOT_FOUND */
4595 /* | HOST_INT_IV_ICV_FAILURE */
4596 | HOST_INT_CMD_COMPLETE
4598 /* | HOST_INT_OVERFLOW */
4599 /* | HOST_INT_PROCESS_ERROR */
4600 | HOST_INT_SCAN_COMPLETE
4601 /* | HOST_INT_FCS_THRESHOLD */
4602 /* | HOST_INT_UNKNOWN */
4604 priv
->irq_mask_off
= (u16
)~( HOST_INT_UNKNOWN
); /* 0x7fff */
4609 /***********************************************************************
4612 acx100_s_set_tx_level(wlandevice_t
*priv
, u8 level_dbm
)
4614 /* since it can be assumed that at least the Maxim radio has a
4615 * maximum power output of 20dBm and since it also can be
4616 * assumed that these values drive the DAC responsible for
4617 * setting the linear Tx level, I'd guess that these values
4618 * should be the corresponding linear values for a dBm value,
4619 * in other words: calculate the values from that formula:
4620 * Y [dBm] = 10 * log (X [mW])
4621 * then scale the 0..63 value range onto the 1..100mW range (0..20 dBm)
4622 * and you're done...
4623 * Hopefully that's ok, but you never know if we're actually
4624 * right... (especially since Windows XP doesn't seem to show
4625 * actual Tx dBm values :-P) */
4627 /* NOTE: on Maxim, value 30 IS 30mW, and value 10 IS 10mW - so the
4628 * values are EXACTLY mW!!! Not sure about RFMD and others,
4630 static const u8 dbm2val_maxim
[21] = {
4638 static const u8 dbm2val_rfmd
[21] = {
4648 switch (priv
->radio_type
) {
4649 case RADIO_MAXIM_0D
:
4650 table
= &dbm2val_maxim
[0];
4653 case RADIO_RALINK_15
:
4654 table
= &dbm2val_rfmd
[0];
4657 printk("%s: unknown/unsupported radio type, "
4658 "cannot modify tx power level yet!\n",
4659 priv
->netdev
->name
);
4662 printk("%s: changing radio power level to %u dBm (%u)\n",
4663 priv
->netdev
->name
, level_dbm
, table
[level_dbm
]);
4664 acxpci_s_write_phy_reg(priv
, 0x11, table
[level_dbm
]);
4669 /***********************************************************************
4670 ** acx_e_init_module
4672 ** Module initialization routine, called once at module load time
4675 acxpci_e_init_module(void)
4681 #if (ACX_IO_WIDTH==32)
4682 printk("acx: compiled to use 32bit I/O access. "
4683 "I/O timing issues might occur, such as "
4684 "non-working firmware upload. Report them\n");
4686 printk("acx: compiled to use 16bit I/O access only "
4687 "(compatibility mode)\n");
4690 #ifdef __LITTLE_ENDIAN
4691 acxlog(L_INIT
, "running on a little-endian CPU\n");
4693 acxlog(L_INIT
, "running on a BIG-ENDIAN CPU\n");
4695 acxlog(L_INIT
, "PCI module " WLAN_RELEASE
" initialized, "
4696 "waiting for cards to probe...\n");
4698 res
= pci_module_init(&acx_pci_drv_id
);
4704 /***********************************************************************
4705 ** acx_e_cleanup_module
4707 ** Called at module unload time. This is our last chance to
4708 ** clean up after ourselves.
4711 acxpci_e_cleanup_module(void)
4713 struct net_device
*dev
;
4714 unsigned long flags
;
4718 /* Since the whole module is about to be unloaded,
4719 * we recursively shutdown all cards we handled instead
4720 * of doing it in remove_pci() (which will be activated by us
4721 * via pci_unregister_driver at the end).
4722 * remove_pci() might just get called after a card eject,
4723 * that's why hardware operations have to be done here instead
4724 * when the hardware is available. */
4726 down(&root_acx_dev_sem
);
4728 dev
= root_acx_dev
.newest
;
4729 while (dev
!= NULL
) {
4730 /* doh, netdev_priv() doesn't have const! */
4731 wlandevice_t
*priv
= netdev_priv(dev
);
4735 /* disable both Tx and Rx to shut radio down properly */
4736 acx_s_issue_cmd(priv
, ACX1xx_CMD_DISABLE_TX
, NULL
, 0);
4737 acx_s_issue_cmd(priv
, ACX1xx_CMD_DISABLE_RX
, NULL
, 0);
4740 /* put the eCPU to sleep to save power
4741 * Halting is not possible currently,
4742 * since not supported by all firmware versions */
4743 acx_s_issue_cmd(priv
, ACX100_CMD_SLEEP
, NULL
, 0);
4745 acx_lock(priv
, flags
);
4747 /* disable power LED to save power :-) */
4748 acxlog(L_INIT
, "switching off power LED to save power :-)\n");
4749 acx_l_power_led(priv
, 0);
4752 if (IS_ACX111(priv
)) {
4753 /* FIXME: does this actually keep halting the eCPU?
4754 * I don't think so...
4756 acx_l_reset_mac(priv
);
4761 temp
= acx_read_reg16(priv
, IO_ACX_ECPU_CTRL
) | 0x1;
4762 acx_write_reg16(priv
, IO_ACX_ECPU_CTRL
, temp
);
4763 acx_write_flush(priv
);
4766 acx_unlock(priv
, flags
);
4768 acx_sem_unlock(priv
);
4770 dev
= priv
->prev_nd
;
4773 up(&root_acx_dev_sem
);
4775 /* now let the PCI layer recursively remove
4776 * all PCI related things (acx_e_remove_pci()) */
4777 pci_unregister_driver(&acx_pci_drv_id
);