sync hh.org
[hh.org.git] / drivers / net / wireless / acx / mem.c
blob5d81804402ae7d4c16321f1df20041ab293f9742
1 /***********************************************************************
2 ** Copyright (C) 2003 ACX100 Open Source Project
3 **
4 ** The contents of this file are subject to the Mozilla Public
5 ** License Version 1.1 (the "License"); you may not use this file
6 ** except in compliance with the License. You may obtain a copy of
7 ** the License at http://www.mozilla.org/MPL/
8 **
9 ** Software distributed under the License is distributed on an "AS
10 ** IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11 ** implied. See the License for the specific language governing
12 ** rights and limitations under the License.
14 ** Alternatively, the contents of this file may be used under the
15 ** terms of the GNU Public License version 2 (the "GPL"), in which
16 ** case the provisions of the GPL are applicable instead of the
17 ** above. If you wish to allow the use of your version of this file
18 ** only under the terms of the GPL and not to allow others to use
19 ** your version of this file under the MPL, indicate your decision
20 ** by deleting the provisions above and replace them with the notice
21 ** and other provisions required by the GPL. If you do not delete
22 ** the provisions above, a recipient may use your version of this
23 ** file under either the MPL or the GPL.
24 ** ---------------------------------------------------------------------
25 ** Inquiries regarding the ACX100 Open Source Project can be
26 ** made directly to:
28 ** acx100-users@lists.sf.net
29 ** http://acx100.sf.net
30 ** ---------------------------------------------------------------------
32 ** Slave memory interface support:
34 ** Todd Blumer - SDG Systems
35 ** Bill Reese - HP
36 ** Eric McCorkle - Shadowsun
38 #define ACX_MEM 1
41 * non-zero makes it dump the ACX memory to the console then
42 * panic when you cat /proc/driver/acx_wlan0_diag
44 #define DUMP_MEM_DEFINED 1
46 #define DUMP_MEM_DURING_DIAG 0
47 #define DUMP_IF_SLOW 0
49 //#define PATCH_AROUND_BAD_SPOTS 1
51 #include <linux/version.h>
52 #include <linux/compiler.h> /* required for Lx 2.6.8 ?? */
53 #include <linux/kernel.h>
54 #include <linux/module.h>
55 #include <linux/moduleparam.h>
56 #include <linux/sched.h>
57 #include <linux/types.h>
58 #include <linux/skbuff.h>
59 #include <linux/slab.h>
60 #include <linux/if_arp.h>
61 #include <linux/irq.h>
62 #include <linux/rtnetlink.h>
63 #include <linux/wireless.h>
64 #include <net/iw_handler.h>
65 #include <linux/netdevice.h>
66 #include <linux/ioport.h>
67 #include <linux/pci.h>
68 #include <linux/platform_device.h>
69 #include <linux/pm.h>
70 #include <linux/vmalloc.h>
71 #include <linux/delay.h>
72 #include <linux/workqueue.h>
73 #include <linux/utsrelease.h>
75 #include "acx.h"
76 #include "acx_hw.h"
78 /***********************************************************************
81 #define CARD_EEPROM_ID_SIZE 6
83 #include <asm/io.h>
85 #define REG_ACX_VENDOR_ID 0x900
87 * This is the vendor id on the HX4700, anyway
89 #define ACX_VENDOR_ID 0x8400104c
91 typedef enum {
92 ACX_SOFT_RESET = 0,
94 ACX_SLV_REG_ADDR,
95 ACX_SLV_REG_DATA,
96 ACX_SLV_REG_ADATA,
98 ACX_SLV_MEM_CP,
99 ACX_SLV_MEM_ADDR,
100 ACX_SLV_MEM_DATA,
101 ACX_SLV_MEM_CTL,
102 } acxreg_t;
104 /***********************************************************************
106 static void acxmem_i_tx_timeout(struct net_device *ndev);
107 static irqreturn_t acxmem_i_interrupt(int irq, void *dev_id);
108 static void acxmem_i_set_multicast_list(struct net_device *ndev);
110 static int acxmem_e_open(struct net_device *ndev);
111 static int acxmem_e_close(struct net_device *ndev);
112 static void acxmem_s_up(struct net_device *ndev);
113 static void acxmem_s_down(struct net_device *ndev);
115 static void dump_acxmem (acx_device_t *adev, u32 start, int length);
117 /***********************************************************************
118 ** Register access
121 /* Pick one */
122 /* #define INLINE_IO static */
123 #define INLINE_IO static inline
125 INLINE_IO u32
126 read_id_register (acx_device_t *adev)
128 writel (0x24, &adev->iobase[ACX_SLV_REG_ADDR]);
129 return readl (&adev->iobase[ACX_SLV_REG_DATA]);
132 INLINE_IO u32
133 read_reg32(acx_device_t *adev, unsigned int offset)
135 u32 val;
136 u32 addr;
138 if (offset > IO_ACX_ECPU_CTRL)
139 addr = offset;
140 else
141 addr = adev->io[offset];
143 if (addr < 0x20) {
144 return readl(((u8*)adev->iobase) + addr);
147 writel( addr, &adev->iobase[ACX_SLV_REG_ADDR] );
148 val = readl( &adev->iobase[ACX_SLV_REG_DATA] );
150 return val;
153 INLINE_IO u16
154 read_reg16(acx_device_t *adev, unsigned int offset)
156 u16 lo;
157 u32 addr;
159 if (offset > IO_ACX_ECPU_CTRL)
160 addr = offset;
161 else
162 addr = adev->io[offset];
164 if (addr < 0x20) {
165 return readw(((u8 *) adev->iobase) + addr);
168 writel( addr, &adev->iobase[ACX_SLV_REG_ADDR] );
169 lo = readw( (u16 *)&adev->iobase[ACX_SLV_REG_DATA] );
171 return lo;
174 INLINE_IO u8
175 read_reg8(acx_device_t *adev, unsigned int offset)
177 u8 lo;
178 u32 addr;
180 if (offset > IO_ACX_ECPU_CTRL)
181 addr = offset;
182 else
183 addr = adev->io[offset];
185 if (addr < 0x20)
186 return readb(((u8 *)adev->iobase) + addr);
188 writel( addr, &adev->iobase[ACX_SLV_REG_ADDR] );
189 lo = readw( (u8 *)&adev->iobase[ACX_SLV_REG_DATA] );
191 return (u8)lo;
194 INLINE_IO void
195 write_reg32(acx_device_t *adev, unsigned int offset, u32 val)
197 u32 addr;
199 if (offset > IO_ACX_ECPU_CTRL)
200 addr = offset;
201 else
202 addr = adev->io[offset];
204 if (addr < 0x20) {
205 writel(val, ((u8*)adev->iobase) + addr);
206 return;
209 writel( addr, &adev->iobase[ACX_SLV_REG_ADDR] );
210 writel( val, &adev->iobase[ACX_SLV_REG_DATA] );
213 INLINE_IO void
214 write_reg16(acx_device_t *adev, unsigned int offset, u16 val)
216 u32 addr;
218 if (offset > IO_ACX_ECPU_CTRL)
219 addr = offset;
220 else
221 addr = adev->io[offset];
223 if (addr < 0x20) {
224 writew(val, ((u8 *)adev->iobase) + addr);
225 return;
227 writel( addr, &adev->iobase[ACX_SLV_REG_ADDR] );
228 writew( val, (u16 *) &adev->iobase[ACX_SLV_REG_DATA] );
231 INLINE_IO void
232 write_reg8(acx_device_t *adev, unsigned int offset, u8 val)
234 u32 addr;
236 if (offset > IO_ACX_ECPU_CTRL)
237 addr = offset;
238 else
239 addr = adev->io[offset];
241 if (addr < 0x20) {
242 writeb(val, ((u8 *) adev->iobase) + addr);
243 return;
245 writel( addr, &adev->iobase[ACX_SLV_REG_ADDR] );
246 writeb( val, (u8 *)&adev->iobase[ACX_SLV_REG_DATA] );
249 /* Handle PCI posting properly:
250 * Make sure that writes reach the adapter in case they require to be executed
251 * *before* the next write, by reading a random (and safely accessible) register.
252 * This call has to be made if there is no read following (which would flush the data
253 * to the adapter), yet the written data has to reach the adapter immediately. */
254 INLINE_IO void
255 write_flush(acx_device_t *adev)
257 /* readb(adev->iobase + adev->io[IO_ACX_INFO_MAILBOX_OFFS]); */
258 /* faster version (accesses the first register, IO_ACX_SOFT_RESET,
259 * which should also be safe): */
260 (void) readl(adev->iobase);
263 INLINE_IO void
264 set_regbits (acx_device_t *adev, unsigned int offset, u32 bits) {
265 u32 tmp;
267 tmp = read_reg32 (adev, offset);
268 tmp = tmp | bits;
269 write_reg32 (adev, offset, tmp);
270 write_flush (adev);
273 INLINE_IO void
274 clear_regbits (acx_device_t *adev, unsigned int offset, u32 bits) {
275 u32 tmp;
277 tmp = read_reg32 (adev, offset);
278 tmp = tmp & ~bits;
279 write_reg32 (adev, offset, tmp);
280 write_flush (adev);
284 * Copy from PXA memory to the ACX memory. This assumes both the PXA and ACX
285 * addresses are 32 bit aligned. Count is in bytes.
287 INLINE_IO void
288 write_slavemem32 (acx_device_t *adev, u32 slave_address, u32 val)
290 write_reg32 (adev, IO_ACX_SLV_MEM_CTL, 0x0);
291 write_reg32 (adev, IO_ACX_SLV_MEM_ADDR, slave_address);
292 udelay (10);
293 write_reg32 (adev, IO_ACX_SLV_MEM_DATA, val);
296 INLINE_IO u32
297 read_slavemem32 (acx_device_t *adev, u32 slave_address)
299 u32 val;
301 write_reg32 (adev, IO_ACX_SLV_MEM_CTL, 0x0);
302 write_reg32 (adev, IO_ACX_SLV_MEM_ADDR, slave_address);
303 udelay (10);
304 val = read_reg32 (adev, IO_ACX_SLV_MEM_DATA);
306 return val;
309 INLINE_IO void
310 write_slavemem8 (acx_device_t *adev, u32 slave_address, u8 val)
312 u32 data;
313 u32 base;
314 int offset;
317 * Get the word containing the target address and the byte offset in that word.
319 base = slave_address & ~3;
320 offset = (slave_address & 3) * 8;
322 data = read_slavemem32 (adev, base);
323 data &= ~(0xff << offset);
324 data |= val << offset;
325 write_slavemem32 (adev, base, data);
328 INLINE_IO u8
329 read_slavemem8 (acx_device_t *adev, u32 slave_address)
331 u8 val;
332 u32 base;
333 u32 data;
334 int offset;
336 base = slave_address & ~3;
337 offset = (slave_address & 3) * 8;
339 data = read_slavemem32 (adev, base);
341 val = (data >> offset) & 0xff;
343 return val;
347 * doesn't split across word boundaries
349 INLINE_IO void
350 write_slavemem16 (acx_device_t *adev, u32 slave_address, u16 val)
352 u32 data;
353 u32 base;
354 int offset;
357 * Get the word containing the target address and the byte offset in that word.
359 base = slave_address & ~3;
360 offset = (slave_address & 3) * 8;
362 data = read_slavemem32 (adev, base);
363 data &= ~(0xffff << offset);
364 data |= val << offset;
365 write_slavemem32 (adev, base, data);
369 * doesn't split across word boundaries
371 INLINE_IO u16
372 read_slavemem16 (acx_device_t *adev, u32 slave_address)
374 u16 val;
375 u32 base;
376 u32 data;
377 int offset;
379 base = slave_address & ~3;
380 offset = (slave_address & 3) * 8;
382 data = read_slavemem32 (adev, base);
384 val = (data >> offset) & 0xffff;
386 return val;
390 * Copy from slave memory
392 * TODO - rewrite using address autoincrement, handle partial words
394 void
395 copy_from_slavemem (acx_device_t *adev, u8 *destination, u32 source, int count) {
396 u32 tmp = 0;
397 u8 *ptmp = (u8 *) &tmp;
400 * Right now I'm making the assumption that the destination is aligned, but
401 * I'd better check.
403 if ((u32) destination & 3) {
404 printk ("acx copy_from_slavemem: warning! destination not word-aligned!\n");
407 while (count >= 4) {
408 write_reg32 (adev, IO_ACX_SLV_MEM_ADDR, source);
409 udelay (10);
410 *((u32 *) destination) = read_reg32 (adev, IO_ACX_SLV_MEM_DATA);
411 count -= 4;
412 source += 4;
413 destination += 4;
417 * If the word reads above didn't satisfy the count, read one more word
418 * and transfer a byte at a time until the request is satisfied.
420 if (count) {
421 write_reg32 (adev, IO_ACX_SLV_MEM_ADDR, source);
422 udelay (10);
423 tmp = read_reg32 (adev, IO_ACX_SLV_MEM_DATA);
424 while (count--) {
425 *destination++ = *ptmp++;
431 * Copy to slave memory
433 * TODO - rewrite using autoincrement, handle partial words
435 void
436 copy_to_slavemem (acx_device_t *adev, u32 destination, u8 *source, int count)
438 u32 tmp = 0;
439 u8* ptmp = (u8 *) &tmp;
440 static u8 src[512]; /* make static to avoid huge stack objects */
443 * For now, make sure the source is word-aligned by copying it to a word-aligned
444 * buffer. Someday rewrite to avoid the extra copy.
446 if (count > sizeof (src)) {
447 printk ("acx copy_to_slavemem: Warning! buffer overflow!\n");
448 count = sizeof (src);
450 memcpy (src, source, count);
451 source = src;
453 while (count >= 4) {
454 write_reg32 (adev, IO_ACX_SLV_MEM_ADDR, destination);
455 udelay (10);
456 write_reg32 (adev, IO_ACX_SLV_MEM_DATA, *((u32 *) source));
457 count -= 4;
458 source += 4;
459 destination += 4;
463 * If there are leftovers read the next word from the acx and merge in
464 * what they want to write.
466 if (count) {
467 write_reg32 (adev, IO_ACX_SLV_MEM_ADDR, destination);
468 udelay (10);
469 tmp = read_reg32 (adev, IO_ACX_SLV_MEM_DATA);
470 while (count--) {
471 *ptmp++ = *source++;
474 * reset address in case we're currently in auto-increment mode
476 write_reg32 (adev, IO_ACX_SLV_MEM_ADDR, destination);
477 udelay (10);
478 write_reg32 (adev, IO_ACX_SLV_MEM_DATA, tmp);
479 udelay (10);
485 * Block copy to slave buffers using memory block chain mode. Copies to the ACX
486 * transmit buffer structure with minimal intervention on our part.
487 * Interrupts should be disabled when calling this.
489 void
490 chaincopy_to_slavemem (acx_device_t *adev, u32 destination, u8 *source, int count)
492 u32 val;
493 u32 *data = (u32 *) source;
494 static u8 aligned_source[WLAN_A4FR_MAXLEN_WEP_FCS];
497 * Warn if the pointers don't look right. Destination must fit in [23:5] with
498 * zero elsewhere and source should be 32 bit aligned.
499 * This should never happen since we're in control of both, but I want to know about
500 * it if it does.
502 if ((destination & 0x00ffffe0) != destination) {
503 printk ("acx chaincopy: destination block 0x%04x not aligned!\n", destination);
505 if (count > sizeof aligned_source) {
506 printk( KERN_ERR "chaincopy_to_slavemem overflow!\n" );
507 count = sizeof aligned_source;
509 if ((u32) source & 3) {
510 memcpy (aligned_source, source, count);
511 data = (u32 *) aligned_source;
515 * SLV_MEM_CTL[17:16] = memory block chain mode with auto-increment
516 * SLV_MEM_CTL[5:2] = offset to data portion = 1 word
518 val = 2 << 16 | 1 << 2;
519 writel (val, &adev->iobase[ACX_SLV_MEM_CTL]);
522 * SLV_MEM_CP[23:5] = start of 1st block
523 * SLV_MEM_CP[3:2] = offset to memblkptr = 0
525 val = destination & 0x00ffffe0;
526 writel (val, &adev->iobase[ACX_SLV_MEM_CP]);
529 * SLV_MEM_ADDR[23:2] = SLV_MEM_CTL[5:2] + SLV_MEM_CP[23:5]
531 val = (destination & 0x00ffffe0) + (1<<2);
532 writel (val, &adev->iobase[ACX_SLV_MEM_ADDR]);
535 * Write the data to the slave data register, rounding up to the end
536 * of the word containing the last byte (hence the > 0)
538 while (count > 0) {
539 writel (*data++, &adev->iobase[ACX_SLV_MEM_DATA]);
540 count -= 4;
546 * Block copy from slave buffers using memory block chain mode. Copies from the ACX
547 * receive buffer structures with minimal intervention on our part.
548 * Interrupts should be disabled when calling this.
550 void
551 chaincopy_from_slavemem (acx_device_t *adev, u8 *destination, u32 source, int count)
553 u32 val;
554 u32 *data = (u32 *) destination;
555 static u8 aligned_destination[WLAN_A4FR_MAXLEN_WEP_FCS];
556 int saved_count = count;
559 * Warn if the pointers don't look right. Destination must fit in [23:5] with
560 * zero elsewhere and source should be 32 bit aligned.
561 * Turns out the network stack sends unaligned things, so fix them before
562 * copying to the ACX.
564 if ((source & 0x00ffffe0) != source) {
565 printk ("acx chaincopy: source block 0x%04x not aligned!\n", source);
566 dump_acxmem (adev, 0, 0x10000);
568 if ((u32) destination & 3) {
569 //printk ("acx chaincopy: data destination not word aligned!\n");
570 data = (u32 *) aligned_destination;
571 if (count > sizeof aligned_destination) {
572 printk( KERN_ERR "chaincopy_from_slavemem overflow!\n" );
573 count = sizeof aligned_destination;
578 * SLV_MEM_CTL[17:16] = memory block chain mode with auto-increment
579 * SLV_MEM_CTL[5:2] = offset to data portion = 1 word
581 val = (2 << 16) | (1 << 2);
582 writel (val, &adev->iobase[ACX_SLV_MEM_CTL]);
585 * SLV_MEM_CP[23:5] = start of 1st block
586 * SLV_MEM_CP[3:2] = offset to memblkptr = 0
588 val = source & 0x00ffffe0;
589 writel (val, &adev->iobase[ACX_SLV_MEM_CP]);
592 * SLV_MEM_ADDR[23:2] = SLV_MEM_CTL[5:2] + SLV_MEM_CP[23:5]
594 val = (source & 0x00ffffe0) + (1<<2);
595 writel (val, &adev->iobase[ACX_SLV_MEM_ADDR]);
598 * Read the data from the slave data register, rounding up to the end
599 * of the word containing the last byte (hence the > 0)
601 while (count > 0) {
602 *data++ = readl (&adev->iobase[ACX_SLV_MEM_DATA]);
603 count -= 4;
607 * If the destination wasn't aligned, we would have saved it in
608 * the aligned buffer, so copy it where it should go.
610 if ((u32) destination & 3) {
611 memcpy (destination, aligned_destination, saved_count);
615 char
616 printable (char c)
618 return ((c >= 20) && (c < 127)) ? c : '.';
621 #if DUMP_MEM_DEFINED > 0
622 static void
623 dump_acxmem (acx_device_t *adev, u32 start, int length)
625 int i;
626 u8 buf[16];
628 while (length > 0) {
629 printk ("%04x ", start);
630 copy_from_slavemem (adev, buf, start, 16);
631 for (i = 0; (i < 16) && (i < length); i++) {
632 printk ("%02x ", buf[i]);
634 for (i = 0; (i < 16) && (i < length); i++) {
635 printk ("%c", printable (buf[i]));
637 printk ("\n");
638 start += 16;
639 length -= 16;
642 #endif
644 static void
645 enable_acx_irq(acx_device_t *adev);
646 static void
647 disable_acx_irq(acx_device_t *adev);
650 * Return an acx pointer to the next transmit data block.
653 allocate_acx_txbuf_space (acx_device_t *adev, int count) {
654 u32 block, next, last_block;
655 int blocks_needed;
656 unsigned long flags;
658 spin_lock_irqsave(&adev->txbuf_lock, flags);
660 * Take 4 off the memory block size to account for the reserved word at the start of
661 * the block.
663 blocks_needed = count / (adev->memblocksize - 4);
664 if (count % (adev->memblocksize - 4))
665 blocks_needed++;
667 if (blocks_needed <= adev->acx_txbuf_blocks_free) {
669 * Take blocks at the head of the free list.
671 last_block = block = adev->acx_txbuf_free;
674 * Follow block pointers through the requested number of blocks both to
675 * find the new head of the free list and to set the flags for the blocks
676 * appropriately.
678 while (blocks_needed--) {
680 * Keep track of the last block of the allocation
682 last_block = adev->acx_txbuf_free;
685 * Make sure the end control flag is not set.
687 next = read_slavemem32 (adev, adev->acx_txbuf_free) & 0x7ffff;
688 write_slavemem32 (adev, adev->acx_txbuf_free, next);
691 * Update the new head of the free list
693 adev->acx_txbuf_free = next << 5;
694 adev->acx_txbuf_blocks_free--;
699 * Flag the last block both by clearing out the next pointer
700 * and marking the control field.
702 write_slavemem32 (adev, last_block, 0x02000000);
705 * If we're out of buffers make sure the free list pointer is NULL
707 if (!adev->acx_txbuf_blocks_free) {
708 adev->acx_txbuf_free = 0;
711 else {
712 block = 0;
714 spin_unlock_irqrestore (&adev->txbuf_lock, flags);
715 return block;
719 * Return buffer space back to the pool by following the next pointers until we find
720 * the block marked as the end. Point the last block to the head of the free list,
721 * then update the head of the free list to point to the newly freed memory.
722 * This routine gets called in interrupt context, so it shouldn't block to protect
723 * the integrity of the linked list. The ISR already holds the lock.
725 void
726 reclaim_acx_txbuf_space (acx_device_t *adev, u32 blockptr) {
727 u32 cur, last, next;
728 unsigned long flags;
730 spin_lock_irqsave (&adev->txbuf_lock, flags);
731 if ((blockptr >= adev->acx_txbuf_start) &&
732 (blockptr <= adev->acx_txbuf_start +
733 (adev->acx_txbuf_numblocks - 1) * adev->memblocksize)) {
734 cur = blockptr;
735 do {
736 last = cur;
737 next = read_slavemem32 (adev, cur);
740 * Advance to the next block in this allocation
742 cur = (next & 0x7ffff) << 5;
745 * This block now counts as free.
747 adev->acx_txbuf_blocks_free++;
748 } while (!(next & 0x02000000));
751 * last now points to the last block of that allocation. Update the pointer
752 * in that block to point to the free list and reset the free list to the
753 * first block of the free call. If there were no free blocks, make sure
754 * the new end of the list marks itself as truly the end.
756 if (adev->acx_txbuf_free) {
757 write_slavemem32 (adev, last, adev->acx_txbuf_free >> 5);
759 else {
760 write_slavemem32 (adev, last, 0x02000000);
762 adev->acx_txbuf_free = blockptr;
764 spin_unlock_irqrestore(&adev->txbuf_lock, flags);
768 * Initialize the pieces managing the transmit buffer pool on the ACX. The transmit
769 * buffer is a circular queue with one 32 bit word reserved at the beginning of each
770 * block. The upper 13 bits are a control field, of which only 0x02000000 has any
771 * meaning. The lower 19 bits are the address of the next block divided by 32.
773 void
774 init_acx_txbuf (acx_device_t *adev) {
777 * acx100_s_init_memory_pools set up txbuf_start and txbuf_numblocks for us.
778 * All we need to do is reset the rest of the bookeeping.
781 adev->acx_txbuf_free = adev->acx_txbuf_start;
782 adev->acx_txbuf_blocks_free = adev->acx_txbuf_numblocks;
785 * Initialization leaves the last transmit pool block without a pointer back to
786 * the head of the list, but marked as the end of the list. That's how we want
787 * to see it, too, so leave it alone.
792 /***********************************************************************
794 static struct net_device *root_adev_newest = NULL;
795 DECLARE_MUTEX(root_adev_sem);
798 /***********************************************************************
800 static inline txdesc_t*
801 get_txdesc(acx_device_t *adev, int index)
803 return (txdesc_t*) (((u8*)adev->txdesc_start) + index * adev->txdesc_size);
806 static inline txdesc_t*
807 advance_txdesc(acx_device_t *adev, txdesc_t* txdesc, int inc)
809 return (txdesc_t*) (((u8*)txdesc) + inc * adev->txdesc_size);
812 static txhostdesc_t*
813 get_txhostdesc(acx_device_t *adev, txdesc_t* txdesc)
815 int index = (u8*)txdesc - (u8*)adev->txdesc_start;
816 if (unlikely(ACX_DEBUG && (index % adev->txdesc_size))) {
817 printk("bad txdesc ptr %p\n", txdesc);
818 return NULL;
820 index /= adev->txdesc_size;
821 if (unlikely(ACX_DEBUG && (index >= TX_CNT))) {
822 printk("bad txdesc ptr %p\n", txdesc);
823 return NULL;
825 return &adev->txhostdesc_start[index*2];
828 static inline client_t*
829 get_txc(acx_device_t *adev, txdesc_t* txdesc)
831 int index = (u8*)txdesc - (u8*)adev->txdesc_start;
832 if (unlikely(ACX_DEBUG && (index % adev->txdesc_size))) {
833 printk("bad txdesc ptr %p\n", txdesc);
834 return NULL;
836 index /= adev->txdesc_size;
837 if (unlikely(ACX_DEBUG && (index >= TX_CNT))) {
838 printk("bad txdesc ptr %p\n", txdesc);
839 return NULL;
841 return adev->txc[index];
844 static inline u16
845 get_txr(acx_device_t *adev, txdesc_t* txdesc)
847 int index = (u8*)txdesc - (u8*)adev->txdesc_start;
848 index /= adev->txdesc_size;
849 return adev->txr[index];
852 static inline void
853 put_txcr(acx_device_t *adev, txdesc_t* txdesc, client_t* c, u16 r111)
855 int index = (u8*)txdesc - (u8*)adev->txdesc_start;
856 if (unlikely(ACX_DEBUG && (index % adev->txdesc_size))) {
857 printk("bad txdesc ptr %p\n", txdesc);
858 return;
860 index /= adev->txdesc_size;
861 if (unlikely(ACX_DEBUG && (index >= TX_CNT))) {
862 printk("bad txdesc ptr %p\n", txdesc);
863 return;
865 adev->txc[index] = c;
866 adev->txr[index] = r111;
870 /***********************************************************************
871 ** EEPROM and PHY read/write helpers
873 /***********************************************************************
874 ** acxmem_read_eeprom_byte
876 ** Function called to read an octet in the EEPROM.
878 ** This function is used by acxmem_e_probe to check if the
879 ** connected card is a legal one or not.
881 ** Arguments:
882 ** adev ptr to acx_device structure
883 ** addr address to read in the EEPROM
884 ** charbuf ptr to a char. This is where the read octet
885 ** will be stored
888 acxmem_read_eeprom_byte(acx_device_t *adev, u32 addr, u8 *charbuf)
890 int result;
891 int count;
893 write_reg32(adev, IO_ACX_EEPROM_CFG, 0);
894 write_reg32(adev, IO_ACX_EEPROM_ADDR, addr);
895 write_flush(adev);
896 write_reg32(adev, IO_ACX_EEPROM_CTL, 2);
898 count = 0xffff;
899 while (read_reg16(adev, IO_ACX_EEPROM_CTL)) {
900 /* scheduling away instead of CPU burning loop
901 * doesn't seem to work here at all:
902 * awful delay, sometimes also failure.
903 * Doesn't matter anyway (only small delay). */
904 if (unlikely(!--count)) {
905 printk("%s: timeout waiting for EEPROM read\n",
906 adev->ndev->name);
907 result = NOT_OK;
908 goto fail;
910 cpu_relax();
913 *charbuf = read_reg8(adev, IO_ACX_EEPROM_DATA);
914 log(L_DEBUG, "EEPROM at 0x%04X = 0x%02X\n", addr, *charbuf);
915 result = OK;
917 fail:
918 return result;
922 /***********************************************************************
923 ** We don't lock hw accesses here since we never r/w eeprom in IRQ
924 ** Note: this function sleeps only because of GFP_KERNEL alloc
926 #ifdef UNUSED
928 acxmem_s_write_eeprom(acx_device_t *adev, u32 addr, u32 len, const u8 *charbuf)
930 u8 *data_verify = NULL;
931 unsigned long flags;
932 int count, i;
933 int result = NOT_OK;
934 u16 gpio_orig;
936 printk("acx: WARNING! I would write to EEPROM now. "
937 "Since I really DON'T want to unless you know "
938 "what you're doing (THIS CODE WILL PROBABLY "
939 "NOT WORK YET!), I will abort that now. And "
940 "definitely make sure to make a "
941 "/proc/driver/acx_wlan0_eeprom backup copy first!!! "
942 "(the EEPROM content includes the PCI config header!! "
943 "If you kill important stuff, then you WILL "
944 "get in trouble and people DID get in trouble already)\n");
945 return OK;
947 FN_ENTER;
949 data_verify = kmalloc(len, GFP_KERNEL);
950 if (!data_verify) {
951 goto end;
954 /* first we need to enable the OE (EEPROM Output Enable) GPIO line
955 * to be able to write to the EEPROM.
956 * NOTE: an EEPROM writing success has been reported,
957 * but you probably have to modify GPIO_OUT, too,
958 * and you probably need to activate a different GPIO
959 * line instead! */
960 gpio_orig = read_reg16(adev, IO_ACX_GPIO_OE);
961 write_reg16(adev, IO_ACX_GPIO_OE, gpio_orig & ~1);
962 write_flush(adev);
964 /* ok, now start writing the data out */
965 for (i = 0; i < len; i++) {
966 write_reg32(adev, IO_ACX_EEPROM_CFG, 0);
967 write_reg32(adev, IO_ACX_EEPROM_ADDR, addr + i);
968 write_reg32(adev, IO_ACX_EEPROM_DATA, *(charbuf + i));
969 write_flush(adev);
970 write_reg32(adev, IO_ACX_EEPROM_CTL, 1);
972 count = 0xffff;
973 while (read_reg16(adev, IO_ACX_EEPROM_CTL)) {
974 if (unlikely(!--count)) {
975 printk("WARNING, DANGER!!! "
976 "Timeout waiting for EEPROM write\n");
977 goto end;
979 cpu_relax();
983 /* disable EEPROM writing */
984 write_reg16(adev, IO_ACX_GPIO_OE, gpio_orig);
985 write_flush(adev);
987 /* now start a verification run */
988 for (i = 0; i < len; i++) {
989 write_reg32(adev, IO_ACX_EEPROM_CFG, 0);
990 write_reg32(adev, IO_ACX_EEPROM_ADDR, addr + i);
991 write_flush(adev);
992 write_reg32(adev, IO_ACX_EEPROM_CTL, 2);
994 count = 0xffff;
995 while (read_reg16(adev, IO_ACX_EEPROM_CTL)) {
996 if (unlikely(!--count)) {
997 printk("timeout waiting for EEPROM read\n");
998 goto end;
1000 cpu_relax();
1003 data_verify[i] = read_reg16(adev, IO_ACX_EEPROM_DATA);
1006 if (0 == memcmp(charbuf, data_verify, len))
1007 result = OK; /* read data matches, success */
1009 end:
1010 kfree(data_verify);
1011 FN_EXIT1(result);
1012 return result;
1014 #endif /* UNUSED */
1017 /***********************************************************************
1018 ** acxmem_s_read_phy_reg
1020 ** Messing with rx/tx disabling and enabling here
1021 ** (write_reg32(adev, IO_ACX_ENABLE, 0b000000xx)) kills traffic
1024 acxmem_s_read_phy_reg(acx_device_t *adev, u32 reg, u8 *charbuf)
1026 int result = NOT_OK;
1027 int count;
1029 FN_ENTER;
1031 write_reg32(adev, IO_ACX_PHY_ADDR, reg);
1032 write_flush(adev);
1033 write_reg32(adev, IO_ACX_PHY_CTL, 2);
1035 count = 0xffff;
1036 while (read_reg32(adev, IO_ACX_PHY_CTL)) {
1037 /* scheduling away instead of CPU burning loop
1038 * doesn't seem to work here at all:
1039 * awful delay, sometimes also failure.
1040 * Doesn't matter anyway (only small delay). */
1041 if (unlikely(!--count)) {
1042 printk("%s: timeout waiting for phy read\n",
1043 adev->ndev->name);
1044 *charbuf = 0;
1045 goto fail;
1047 cpu_relax();
1050 log(L_DEBUG, "count was %u\n", count);
1051 *charbuf = read_reg8(adev, IO_ACX_PHY_DATA);
1053 log(L_DEBUG, "radio PHY at 0x%04X = 0x%02X\n", *charbuf, reg);
1054 result = OK;
1055 goto fail; /* silence compiler warning */
1056 fail:
1057 FN_EXIT1(result);
1058 return result;
1062 /***********************************************************************
1065 acxmem_s_write_phy_reg(acx_device_t *adev, u32 reg, u8 value)
1067 int count;
1068 FN_ENTER;
1070 /* mprusko said that 32bit accesses result in distorted sensitivity
1071 * on his card. Unconfirmed, looks like it's not true (most likely since we
1072 * now properly flush writes). */
1073 write_reg32(adev, IO_ACX_PHY_DATA, value);
1074 write_reg32(adev, IO_ACX_PHY_ADDR, reg);
1075 write_flush(adev);
1076 write_reg32(adev, IO_ACX_PHY_CTL, 1);
1077 write_flush(adev);
1079 count = 0xffff;
1080 while (read_reg32(adev, IO_ACX_PHY_CTL)) {
1081 /* scheduling away instead of CPU burning loop
1082 * doesn't seem to work here at all:
1083 * awful delay, sometimes also failure.
1084 * Doesn't matter anyway (only small delay). */
1085 if (unlikely(!--count)) {
1086 printk("%s: timeout waiting for phy read\n",
1087 adev->ndev->name);
1088 goto fail;
1090 cpu_relax();
1093 log(L_DEBUG, "radio PHY write 0x%02X at 0x%04X\n", value, reg);
1094 fail:
1095 FN_EXIT1(OK);
1096 return OK;
1100 #define NO_AUTO_INCREMENT 1
1102 /***********************************************************************
1103 ** acxmem_s_write_fw
1105 ** Write the firmware image into the card.
1107 ** Arguments:
1108 ** adev wlan device structure
1109 ** apfw_image firmware image.
1111 ** Returns:
1112 ** 1 firmware image corrupted
1113 ** 0 success
1115 static int
1116 acxmem_s_write_fw(acx_device_t *adev, const firmware_image_t *apfw_image, u32 offset)
1118 int len, size, checkMismatch = -1;
1119 u32 sum, v32, tmp, id;
1120 /* we skip the first four bytes which contain the control sum */
1121 const u8 *image = (u8*)apfw_image + 4;
1123 /* start the image checksum by adding the image size value */
1124 sum = image[0]+image[1]+image[2]+image[3];
1125 image += 4;
1127 #ifdef NOPE
1128 #if NO_AUTO_INCREMENT
1129 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 0); /* use basic mode */
1130 #else
1131 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 1); /* use autoincrement mode */
1132 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset); /* configure start address */
1133 write_flush(adev);
1134 #endif
1135 #endif
1136 len = 0;
1137 size = le32_to_cpu(apfw_image->size) & (~3);
1139 while (likely(len < size)) {
1140 v32 = be32_to_cpu(*(u32*)image);
1141 sum += image[0]+image[1]+image[2]+image[3];
1142 image += 4;
1143 len += 4;
1145 #ifdef NOPE
1146 #if NO_AUTO_INCREMENT
1147 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset + len - 4);
1148 write_flush(adev);
1149 #endif
1150 write_reg32(adev, IO_ACX_SLV_MEM_DATA, v32);
1151 write_flush(adev);
1152 #endif
1153 write_slavemem32 (adev, offset + len - 4, v32);
1155 id = read_id_register (adev);
1158 * check the data written
1160 tmp = read_slavemem32 (adev, offset + len - 4);
1161 if (checkMismatch && (tmp != v32)) {
1162 printk ("first data mismatch at 0x%08x good 0x%08x bad 0x%08x id 0x%08x\n",
1163 offset + len - 4, v32, tmp, id);
1164 checkMismatch = 0;
1167 log(L_DEBUG, "firmware written, size:%d sum1:%x sum2:%x\n",
1168 size, sum, le32_to_cpu(apfw_image->chksum));
1170 /* compare our checksum with the stored image checksum */
1171 return (sum != le32_to_cpu(apfw_image->chksum));
1175 /***********************************************************************
1176 ** acxmem_s_validate_fw
1178 ** Compare the firmware image given with
1179 ** the firmware image written into the card.
1181 ** Arguments:
1182 ** adev wlan device structure
1183 ** apfw_image firmware image.
1185 ** Returns:
1186 ** NOT_OK firmware image corrupted or not correctly written
1187 ** OK success
1189 static int
1190 acxmem_s_validate_fw(acx_device_t *adev, const firmware_image_t *apfw_image,
1191 u32 offset)
1193 u32 sum, v32, w32;
1194 int len, size;
1195 int result = OK;
1196 /* we skip the first four bytes which contain the control sum */
1197 const u8 *image = (u8*)apfw_image + 4;
1199 /* start the image checksum by adding the image size value */
1200 sum = image[0]+image[1]+image[2]+image[3];
1201 image += 4;
1203 write_reg32(adev, IO_ACX_SLV_END_CTL, 0);
1205 #if NO_AUTO_INCREMENT
1206 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 0); /* use basic mode */
1207 #else
1208 write_reg32(adev, IO_ACX_SLV_MEM_CTL, 1); /* use autoincrement mode */
1209 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset); /* configure start address */
1210 #endif
1212 len = 0;
1213 size = le32_to_cpu(apfw_image->size) & (~3);
1215 while (likely(len < size)) {
1216 v32 = be32_to_cpu(*(u32*)image);
1217 image += 4;
1218 len += 4;
1220 #ifdef NOPE
1221 #if NO_AUTO_INCREMENT
1222 write_reg32(adev, IO_ACX_SLV_MEM_ADDR, offset + len - 4);
1223 #endif
1224 udelay(10);
1225 w32 = read_reg32(adev, IO_ACX_SLV_MEM_DATA);
1226 #endif
1227 w32 = read_slavemem32 (adev, offset + len - 4);
1229 if (unlikely(w32 != v32)) {
1230 printk("acx: FATAL: firmware upload: "
1231 "data parts at offset %d don't match\n(0x%08X vs. 0x%08X)!\n"
1232 "I/O timing issues or defective memory, with DWL-xx0+? "
1233 "ACX_IO_WIDTH=16 may help. Please report\n",
1234 len, v32, w32);
1235 result = NOT_OK;
1236 break;
1239 sum += (u8)w32 + (u8)(w32>>8) + (u8)(w32>>16) + (u8)(w32>>24);
1242 /* sum control verification */
1243 if (result != NOT_OK) {
1244 if (sum != le32_to_cpu(apfw_image->chksum)) {
1245 printk("acx: FATAL: firmware upload: "
1246 "checksums don't match!\n");
1247 result = NOT_OK;
1251 return result;
1255 /***********************************************************************
1256 ** acxmem_s_upload_fw
1258 ** Called from acx_reset_dev
1260 static int
1261 acxmem_s_upload_fw(acx_device_t *adev)
1263 firmware_image_t *apfw_image = NULL;
1264 int res = NOT_OK;
1265 int try;
1266 u32 size;
1267 char *filename = "WLANGEN.BIN";
1268 #ifdef PATCH_AROUND_BAD_SPOTS
1269 u32 offset;
1270 int i;
1272 * arm-linux-objdump -d patch.bin, or
1273 * od -Ax -t x4 patch.bin after finding the bounds
1274 * of the .text section with arm-linux-objdump -s patch.bin
1276 u32 patch[] = {
1277 0xe584c030, 0xe59fc008,
1278 0xe92d1000, 0xe59fc004, 0xe8bd8000, 0x0000080c,
1279 0x0000aa68, 0x605a2200, 0x2c0a689c, 0x2414d80a,
1280 0x2f00689f, 0x1c27d007, 0x06241e7c, 0x2f000e24,
1281 0xe000d1f6, 0x602e6018, 0x23036468, 0x480203db,
1282 0x60ca6003, 0xbdf0750a, 0xffff0808
1284 #endif
1286 FN_ENTER;
1287 /* No combined image; tell common we need the radio firmware, too */
1288 adev->need_radio_fw = 1;
1290 apfw_image = acx_s_read_fw(adev->dev, filename, &size);
1291 if (!apfw_image) {
1292 FN_EXIT1(NOT_OK);
1293 return NOT_OK;
1296 for (try = 1; try <= 5; try++) {
1297 res = acxmem_s_write_fw(adev, apfw_image, 0);
1298 log(L_DEBUG|L_INIT, "acx_write_fw (main):%d\n", res);
1299 if (OK == res) {
1300 res = acxmem_s_validate_fw(adev, apfw_image, 0);
1301 log(L_DEBUG|L_INIT, "acx_validate_fw "
1302 "(main):%d\n", res);
1305 if (OK == res) {
1306 SET_BIT(adev->dev_state_mask, ACX_STATE_FW_LOADED);
1307 break;
1309 printk("acx: firmware upload attempt #%d FAILED, "
1310 "retrying...\n", try);
1311 acx_s_msleep(1000); /* better wait for a while... */
1314 vfree(apfw_image);
1315 #ifdef PATCH_AROUND_BAD_SPOTS
1317 * Put the patch after the main firmware image. 0x950c contains
1318 * the ACX's idea of the end of the firmware. Use that location to
1319 * load ours (which depends on that location being 0xab58) then
1320 * update that location to point to after ours.
1322 offset = read_slavemem32 (adev, 0x950c);
1324 printk ("acx: patching in at 0x%04x\n", offset);
1326 for (i = 0; i < sizeof(patch) / sizeof(patch[0]); i++) {
1327 write_slavemem32 (adev, offset, patch[i]);
1328 offset += sizeof(u32);
1332 * Patch the instruction at 0x0804 to branch to our ARM patch at 0xab58
1334 write_slavemem32 (adev, 0x0804, 0xea000000 + (0xab58-0x0804-8)/4);
1337 * Patch the instructions at 0x1f40 to branch to our Thumb patch at 0xab74
1339 * 4a00 ldr r2, [pc, #0]
1340 * 4710 bx r2
1341 * .data 0xab74+1
1343 write_slavemem32 (adev, 0x1f40, 0x47104a00);
1344 write_slavemem32 (adev, 0x1f44, 0x0000ab74+1);
1347 * Bump the end of the firmware up to beyond our patch.
1349 write_slavemem32 (adev, 0x950c, offset);
1351 #endif
1353 FN_EXIT1(res);
1354 return res;
1358 /***********************************************************************
1359 ** acxmem_s_upload_radio
1361 ** Uploads the appropriate radio module firmware into the card.
1364 acxmem_s_upload_radio(acx_device_t *adev)
1366 acx_ie_memmap_t mm;
1367 firmware_image_t *radio_image;
1368 acx_cmd_radioinit_t radioinit;
1369 int res = NOT_OK;
1370 int try;
1371 u32 offset;
1372 u32 size;
1373 char filename[sizeof("RADIONN.BIN")];
1375 if (!adev->need_radio_fw) return OK;
1377 FN_ENTER;
1379 acx_s_interrogate(adev, &mm, ACX1xx_IE_MEMORY_MAP);
1380 offset = le32_to_cpu(mm.CodeEnd);
1382 snprintf(filename, sizeof(filename), "RADIO%02x.BIN",
1383 adev->radio_type);
1384 radio_image = acx_s_read_fw(adev->dev, filename, &size);
1385 if (!radio_image) {
1386 printk("acx: can't load radio module '%s'\n", filename);
1387 goto fail;
1390 acx_s_issue_cmd(adev, ACX1xx_CMD_SLEEP, NULL, 0);
1392 for (try = 1; try <= 5; try++) {
1393 res = acxmem_s_write_fw(adev, radio_image, offset);
1394 log(L_DEBUG|L_INIT, "acx_write_fw (radio): %d\n", res);
1395 if (OK == res) {
1396 res = acxmem_s_validate_fw(adev, radio_image, offset);
1397 log(L_DEBUG|L_INIT, "acx_validate_fw (radio): %d\n", res);
1400 if (OK == res)
1401 break;
1402 printk("acx: radio firmware upload attempt #%d FAILED, "
1403 "retrying...\n", try);
1404 acx_s_msleep(1000); /* better wait for a while... */
1407 acx_s_issue_cmd(adev, ACX1xx_CMD_WAKE, NULL, 0);
1408 radioinit.offset = cpu_to_le32(offset);
1410 /* no endian conversion needed, remains in card CPU area: */
1411 radioinit.len = radio_image->size;
1413 vfree(radio_image);
1415 if (OK != res)
1416 goto fail;
1418 /* will take a moment so let's have a big timeout */
1419 acx_s_issue_cmd_timeo(adev, ACX1xx_CMD_RADIOINIT,
1420 &radioinit, sizeof(radioinit), CMD_TIMEOUT_MS(1000));
1422 res = acx_s_interrogate(adev, &mm, ACX1xx_IE_MEMORY_MAP);
1424 fail:
1425 FN_EXIT1(res);
1426 return res;
1429 /***********************************************************************
1430 ** acxmem_l_reset_mac
1432 ** MAC will be reset
1433 ** Call context: reset_dev
1435 static void
1436 acxmem_l_reset_mac(acx_device_t *adev)
1438 int count;
1439 FN_ENTER;
1441 /* halt eCPU */
1442 set_regbits (adev, IO_ACX_ECPU_CTRL, 0x1);
1444 /* now do soft reset of eCPU, set bit */
1445 set_regbits (adev, IO_ACX_SOFT_RESET, 0x1);
1446 log(L_DEBUG, "%s: enable soft reset...\n", __func__);
1448 /* Windows driver sleeps here for a while with this sequence */
1449 for (count = 0; count < 200; count++) {
1450 udelay (50);
1453 /* now clear bit again: deassert eCPU reset */
1454 log(L_DEBUG, "%s: disable soft reset and go to init mode...\n", __func__);
1455 clear_regbits (adev, IO_ACX_SOFT_RESET, 0x1);
1457 /* now start a burst read from initial EEPROM */
1458 set_regbits (adev, IO_ACX_EE_START, 0x1);
1461 * Windows driver sleeps here for a while with this sequence
1463 for (count = 0; count < 200; count++) {
1464 udelay (50);
1467 /* Windows driver writes 0x10000 to register 0x808 here */
1469 write_reg32 (adev, 0x808, 0x10000);
1471 FN_EXIT0;
1475 /***********************************************************************
1476 ** acxmem_s_verify_init
1478 static int
1479 acxmem_s_verify_init(acx_device_t *adev)
1481 int result = NOT_OK;
1482 unsigned long timeout;
1484 FN_ENTER;
1486 timeout = jiffies + 2*HZ;
1487 for (;;) {
1488 u32 irqstat = read_reg32(adev, IO_ACX_IRQ_STATUS_NON_DES);
1489 if ((irqstat != 0xFFFFFFFF) && (irqstat & HOST_INT_FCS_THRESHOLD)) {
1490 result = OK;
1491 write_reg32(adev, IO_ACX_IRQ_ACK, HOST_INT_FCS_THRESHOLD);
1492 break;
1494 if (time_after(jiffies, timeout))
1495 break;
1496 /* Init may take up to ~0.5 sec total */
1497 acx_s_msleep(50);
1500 FN_EXIT1(result);
1501 return result;
1505 /***********************************************************************
1506 ** A few low-level helpers
1508 ** Note: these functions are not protected by lock
1509 ** and thus are never allowed to be called from IRQ.
1510 ** Also they must not race with fw upload which uses same hw regs
1513 /***********************************************************************
1514 ** acxmem_write_cmd_type_status
1517 static inline void
1518 acxmem_write_cmd_type_status(acx_device_t *adev, u16 type, u16 status)
1520 write_slavemem32 (adev, (u32) adev->cmd_area, type | (status << 16));
1521 write_flush(adev);
1525 /***********************************************************************
1526 ** acxmem_read_cmd_type_status
1528 static u32
1529 acxmem_read_cmd_type_status(acx_device_t *adev)
1531 u32 cmd_type, cmd_status;
1533 cmd_type = read_slavemem32 (adev, (u32) adev->cmd_area);
1535 cmd_status = (cmd_type >> 16);
1536 cmd_type = (u16)cmd_type;
1538 log(L_CTL, "cmd_type:%04X cmd_status:%04X [%s]\n",
1539 cmd_type, cmd_status,
1540 acx_cmd_status_str(cmd_status));
1542 return cmd_status;
1546 /***********************************************************************
1547 ** acxmem_s_reset_dev
1549 ** Arguments:
1550 ** netdevice that contains the adev variable
1551 ** Returns:
1552 ** NOT_OK on fail
1553 ** OK on success
1554 ** Side effects:
1555 ** device is hard reset
1556 ** Call context:
1557 ** acxmem_e_probe
1558 ** Comment:
1559 ** This resets the device using low level hardware calls
1560 ** as well as uploads and verifies the firmware to the card
1563 static inline void
1564 init_mboxes(acx_device_t *adev)
1566 u32 cmd_offs, info_offs;
1568 cmd_offs = read_reg32(adev, IO_ACX_CMD_MAILBOX_OFFS);
1569 info_offs = read_reg32(adev, IO_ACX_INFO_MAILBOX_OFFS);
1570 adev->cmd_area = (u8*) cmd_offs;
1571 adev->info_area = (u8*) info_offs;
1573 log(L_DEBUG, "iobase2=%p\n"
1575 log( L_DEBUG, "cmd_mbox_offset=%X cmd_area=%p\n"
1576 "info_mbox_offset=%X info_area=%p\n",
1577 cmd_offs, adev->cmd_area,
1578 info_offs, adev->info_area);
1582 static inline void
1583 read_eeprom_area(acx_device_t *adev)
1585 #if ACX_DEBUG > 1
1586 int offs;
1587 u8 tmp;
1589 for (offs = 0x8c; offs < 0xb9; offs++)
1590 acxmem_read_eeprom_byte(adev, offs, &tmp);
1591 #endif
1594 static int
1595 acxmem_s_reset_dev(acx_device_t *adev)
1597 const char* msg = "";
1598 unsigned long flags;
1599 int result = NOT_OK;
1600 u16 hardware_info;
1601 u16 ecpu_ctrl;
1602 int count;
1603 u32 tmp;
1605 FN_ENTER;
1607 write_reg32 (adev, IO_ACX_SLV_MEM_CP, 0);
1609 /* reset the device to make sure the eCPU is stopped
1610 * to upload the firmware correctly */
1612 acx_lock(adev, flags);
1614 /* Windows driver does some funny things here */
1616 * clear bit 0x200 in register 0x2A0
1618 clear_regbits (adev, 0x2A0, 0x200);
1621 * Set bit 0x200 in ACX_GPIO_OUT
1623 set_regbits (adev, IO_ACX_GPIO_OUT, 0x200);
1626 * read register 0x900 until its value is 0x8400104C, sleeping
1627 * in between reads if it's not immediate
1629 tmp = read_reg32 (adev, REG_ACX_VENDOR_ID);
1630 count = 500;
1631 while (count-- && (tmp != ACX_VENDOR_ID)) {
1632 mdelay (10);
1633 tmp = read_reg32 (adev, REG_ACX_VENDOR_ID);
1636 /* end what Windows driver does */
1638 acxmem_l_reset_mac(adev);
1640 ecpu_ctrl = read_reg32(adev, IO_ACX_ECPU_CTRL) & 1;
1641 if (!ecpu_ctrl) {
1642 msg = "eCPU is already running. ";
1643 goto end_unlock;
1646 #ifdef WE_DONT_NEED_THAT_DO_WE
1647 if (read_reg16(adev, IO_ACX_SOR_CFG) & 2) {
1648 /* eCPU most likely means "embedded CPU" */
1649 msg = "eCPU did not start after boot from flash. ";
1650 goto end_unlock;
1653 /* check sense on reset flags */
1654 if (read_reg16(adev, IO_ACX_SOR_CFG) & 0x10) {
1655 printk("%s: eCPU did not start after boot (SOR), "
1656 "is this fatal?\n", adev->ndev->name);
1658 #endif
1659 /* scan, if any, is stopped now, setting corresponding IRQ bit */
1660 adev->irq_status |= HOST_INT_SCAN_COMPLETE;
1662 acx_unlock(adev, flags);
1664 /* need to know radio type before fw load */
1665 /* Need to wait for arrival of this information in a loop,
1666 * most probably since eCPU runs some init code from EEPROM
1667 * (started burst read in reset_mac()) which also
1668 * sets the radio type ID */
1670 count = 0xffff;
1671 do {
1672 hardware_info = read_reg16(adev, IO_ACX_EEPROM_INFORMATION);
1673 if (!--count) {
1674 msg = "eCPU didn't indicate radio type";
1675 goto end_fail;
1677 cpu_relax();
1678 } while (!(hardware_info & 0xff00)); /* radio type still zero? */
1679 printk("ACX radio type 0x%02x\n", (hardware_info >> 8) & 0xff);
1680 /* printk("DEBUG: count %d\n", count); */
1681 adev->form_factor = hardware_info & 0xff;
1682 adev->radio_type = hardware_info >> 8;
1684 /* load the firmware */
1685 if (OK != acxmem_s_upload_fw(adev))
1686 goto end_fail;
1688 /* acx_s_msleep(10); this one really shouldn't be required */
1690 /* now start eCPU by clearing bit */
1691 clear_regbits (adev, IO_ACX_ECPU_CTRL, 0x1);
1692 log(L_DEBUG, "booted eCPU up and waiting for completion...\n");
1694 /* Windows driver clears bit 0x200 in register 0x2A0 here */
1695 clear_regbits (adev, 0x2A0, 0x200);
1697 /* Windows driver sets bit 0x200 in ACX_GPIO_OUT here */
1698 set_regbits (adev, IO_ACX_GPIO_OUT, 0x200);
1699 /* wait for eCPU bootup */
1700 if (OK != acxmem_s_verify_init(adev)) {
1701 msg = "timeout waiting for eCPU. ";
1702 goto end_fail;
1704 log(L_DEBUG, "eCPU has woken up, card is ready to be configured\n");
1705 init_mboxes(adev);
1706 acxmem_write_cmd_type_status(adev, ACX1xx_CMD_RESET, 0);
1708 /* test that EEPROM is readable */
1709 read_eeprom_area(adev);
1711 result = OK;
1712 goto end;
1714 /* Finish error message. Indicate which function failed */
1715 end_unlock:
1716 acx_unlock(adev, flags);
1717 end_fail:
1718 printk("acx: %sreset_dev() FAILED\n", msg);
1719 end:
1720 FN_EXIT1(result);
1721 return result;
1725 /***********************************************************************
1726 ** acxmem_s_issue_cmd_timeo
1728 ** Sends command to fw, extract result
1730 ** NB: we do _not_ take lock inside, so be sure to not touch anything
1731 ** which may interfere with IRQ handler operation
1733 ** TODO: busy wait is a bit silly, so:
1734 ** 1) stop doing many iters - go to sleep after first
1735 ** 2) go to waitqueue based approach: wait, not poll!
1737 #undef FUNC
1738 #define FUNC "issue_cmd"
1740 #if !ACX_DEBUG
1742 acxmem_s_issue_cmd_timeo(
1743 acx_device_t *adev,
1744 unsigned int cmd,
1745 void *buffer,
1746 unsigned buflen,
1747 unsigned cmd_timeout)
1749 #else
1751 acxmem_s_issue_cmd_timeo_debug(
1752 acx_device_t *adev,
1753 unsigned cmd,
1754 void *buffer,
1755 unsigned buflen,
1756 unsigned cmd_timeout,
1757 const char* cmdstr)
1759 unsigned long start = jiffies;
1760 #endif
1761 const char *devname;
1762 unsigned counter;
1763 u16 irqtype;
1764 int i, j;
1765 u8 *p;
1766 u16 cmd_status;
1767 unsigned long timeout;
1769 FN_ENTER;
1771 devname = adev->ndev->name;
1772 if (!devname || !devname[0] || devname[4]=='%')
1773 devname = "acx";
1775 log(L_CTL, FUNC"(cmd:%s,buflen:%u,timeout:%ums,type:0x%04X)\n",
1776 cmdstr, buflen, cmd_timeout,
1777 buffer ? le16_to_cpu(((acx_ie_generic_t *)buffer)->type) : -1);
1779 if (!(adev->dev_state_mask & ACX_STATE_FW_LOADED)) {
1780 printk("%s: "FUNC"(): firmware is not loaded yet, "
1781 "cannot execute commands!\n", devname);
1782 goto bad;
1785 if ((acx_debug & L_DEBUG) && (cmd != ACX1xx_CMD_INTERROGATE)) {
1786 printk("input buffer (len=%u):\n", buflen);
1787 acx_dump_bytes(buffer, buflen);
1790 /* wait for firmware to become idle for our command submission */
1791 timeout = HZ/5;
1792 counter = (timeout * 1000 / HZ) - 1; /* in ms */
1793 timeout += jiffies;
1794 do {
1795 cmd_status = acxmem_read_cmd_type_status(adev);
1796 /* Test for IDLE state */
1797 if (!cmd_status)
1798 break;
1799 if (counter % 5 == 0) {
1800 if (time_after(jiffies, timeout)) {
1801 counter = 0;
1802 break;
1804 /* we waited 5 iterations, no luck. Sleep 5 ms */
1805 acx_s_msleep(5);
1807 } while (likely(--counter));
1809 if (!counter) {
1810 /* the card doesn't get idle, we're in trouble */
1811 printk("%s: "FUNC"(): cmd_status is not IDLE: 0x%04X!=0\n",
1812 devname, cmd_status);
1813 #if DUMP_IF_SLOW > 0
1814 dump_acxmem (adev, 0, 0x10000);
1815 panic ("not idle");
1816 #endif
1817 goto bad;
1818 } else if (counter < 190) { /* if waited >10ms... */
1819 log(L_CTL|L_DEBUG, FUNC"(): waited for IDLE %dms. "
1820 "Please report\n", 199 - counter);
1823 /* now write the parameters of the command if needed */
1824 if (buffer && buflen) {
1825 /* if it's an INTERROGATE command, just pass the length
1826 * of parameters to read, as data */
1827 #if CMD_DISCOVERY
1828 if (cmd == ACX1xx_CMD_INTERROGATE)
1829 memset_io(adev->cmd_area + 4, 0xAA, buflen);
1830 #endif
1832 * slave memory version
1834 copy_to_slavemem (adev, (u32) (adev->cmd_area + 4), buffer,
1835 (cmd == ACX1xx_CMD_INTERROGATE) ? 4 : buflen);
1837 /* now write the actual command type */
1838 acxmem_write_cmd_type_status(adev, cmd, 0);
1840 /* clear CMD_COMPLETE bit. can be set only by IRQ handler: */
1841 adev->irq_status &= ~HOST_INT_CMD_COMPLETE;
1843 /* execute command */
1844 write_reg16(adev, IO_ACX_INT_TRIG, INT_TRIG_CMD);
1845 write_flush(adev);
1847 /* wait for firmware to process command */
1849 /* Ensure nonzero and not too large timeout.
1850 ** Also converts e.g. 100->99, 200->199
1851 ** which is nice but not essential */
1852 cmd_timeout = (cmd_timeout-1) | 1;
1853 if (unlikely(cmd_timeout > 1199))
1854 cmd_timeout = 1199;
1856 /* we schedule away sometimes (timeout can be large) */
1857 counter = cmd_timeout;
1858 timeout = jiffies + cmd_timeout * HZ / 1000;
1859 do {
1860 if (!adev->irqs_active) { /* IRQ disabled: poll */
1861 irqtype = read_reg16(adev, IO_ACX_IRQ_STATUS_NON_DES);
1862 if (irqtype & HOST_INT_CMD_COMPLETE) {
1863 write_reg16(adev, IO_ACX_IRQ_ACK,
1864 HOST_INT_CMD_COMPLETE);
1865 break;
1867 } else { /* Wait when IRQ will set the bit */
1868 irqtype = adev->irq_status;
1869 if (irqtype & HOST_INT_CMD_COMPLETE)
1870 break;
1873 if (counter % 5 == 0) {
1874 if (time_after(jiffies, timeout)) {
1875 counter = 0;
1876 break;
1878 /* we waited 5 iterations, no luck. Sleep 5 ms */
1879 acx_s_msleep(5);
1881 } while (likely(--counter));
1883 /* save state for debugging */
1884 cmd_status = acxmem_read_cmd_type_status(adev);
1886 /* put the card in IDLE state */
1887 acxmem_write_cmd_type_status(adev, ACX1xx_CMD_RESET, 0);
1889 if (!counter) { /* timed out! */
1890 printk("%s: "FUNC"(): timed out %s for CMD_COMPLETE. "
1891 "irq bits:0x%04X irq_status:0x%04X timeout:%dms "
1892 "cmd_status:%d (%s)\n",
1893 devname, (adev->irqs_active) ? "waiting" : "polling",
1894 irqtype, adev->irq_status, cmd_timeout,
1895 cmd_status, acx_cmd_status_str(cmd_status));
1896 printk("%s: "FUNC"(): device irq status 0x%04x\n",
1897 devname, read_reg16(adev, IO_ACX_IRQ_STATUS_NON_DES));
1898 #if DUMP_IF_SLOW > 0
1899 dump_acxmem (adev, 0, 0x10000);
1900 panic ("first bad command");
1901 #endif
1902 goto bad;
1903 } else if (cmd_timeout - counter > 30) { /* if waited >30ms... */
1904 log(L_CTL|L_DEBUG, FUNC"(): %s for CMD_COMPLETE %dms. "
1905 "count:%d. Please report\n",
1906 (adev->irqs_active) ? "waited" : "polled",
1907 cmd_timeout - counter, counter);
1910 if (1 != cmd_status) { /* it is not a 'Success' */
1911 printk("%s: "FUNC"(): cmd_status is not SUCCESS: %d (%s). "
1912 "Took %dms of %d\n",
1913 devname, cmd_status, acx_cmd_status_str(cmd_status),
1914 cmd_timeout - counter, cmd_timeout);
1915 /* zero out result buffer
1916 * WARNING: this will trash stack in case of illegally large input
1917 * length! */
1918 if (buflen > 388) {
1920 * 388 is maximum command length
1922 printk ("invalid length 0x%08x\n", buflen);
1923 buflen = 388;
1925 p = (u8 *) buffer;
1926 for (i = 0; i < buflen; i+= 16) {
1927 printk ("%04x:", i);
1928 for (j = 0; (j < 16) && (i+j < buflen); j++) {
1929 printk (" %02x", *p++);
1931 printk ("\n");
1934 if (buffer && buflen)
1935 memset(buffer, 0, buflen);
1936 goto bad;
1939 /* read in result parameters if needed */
1940 if (buffer && buflen && (cmd == ACX1xx_CMD_INTERROGATE)) {
1941 copy_from_slavemem (adev, buffer, (u32) (adev->cmd_area + 4), buflen);
1942 if (acx_debug & L_DEBUG) {
1943 printk("output buffer (len=%u): ", buflen);
1944 acx_dump_bytes(buffer, buflen);
1948 /* ok: */
1949 log(L_CTL, FUNC"(%s): took %ld jiffies to complete\n",
1950 cmdstr, jiffies - start);
1951 FN_EXIT1(OK);
1952 return OK;
1954 bad:
1955 /* Give enough info so that callers can avoid
1956 ** printing their own diagnostic messages */
1957 #if ACX_DEBUG
1958 printk("%s: "FUNC"(cmd:%s) FAILED\n", devname, cmdstr);
1959 #else
1960 printk("%s: "FUNC"(cmd:0x%04X) FAILED\n", devname, cmd);
1961 #endif
1962 dump_stack();
1963 FN_EXIT1(NOT_OK);
1964 return NOT_OK;
1968 /***********************************************************************
1970 #if defined(NONESSENTIAL_FEATURES)
1971 typedef struct device_id {
1972 unsigned char id[6];
1973 char *descr;
1974 char *type;
1975 } device_id_t;
1977 static const device_id_t
1978 device_ids[] =
1981 {'G', 'l', 'o', 'b', 'a', 'l'},
1982 NULL,
1983 NULL,
1986 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
1987 "uninitialized",
1988 "SpeedStream SS1021 or Gigafast WF721-AEX"
1991 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85},
1992 "non-standard",
1993 "DrayTek Vigor 520"
1996 {'?', '?', '?', '?', '?', '?'},
1997 "non-standard",
1998 "Level One WPC-0200"
2001 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
2002 "empty",
2003 "DWL-650+ variant"
2007 static void
2008 acx_show_card_eeprom_id(acx_device_t *adev)
2010 unsigned char buffer[CARD_EEPROM_ID_SIZE];
2011 int i;
2013 memset(&buffer, 0, CARD_EEPROM_ID_SIZE);
2014 /* use direct EEPROM access */
2015 for (i = 0; i < CARD_EEPROM_ID_SIZE; i++) {
2016 if (OK != acxmem_read_eeprom_byte(adev,
2017 ACX100_EEPROM_ID_OFFSET + i,
2018 &buffer[i])) {
2019 printk("acx: reading EEPROM FAILED\n");
2020 break;
2024 for (i = 0; i < VEC_SIZE(device_ids); i++) {
2025 if (!memcmp(&buffer, device_ids[i].id, CARD_EEPROM_ID_SIZE)) {
2026 if (device_ids[i].descr) {
2027 printk("acx: EEPROM card ID string check "
2028 "found %s card ID: is this %s?\n",
2029 device_ids[i].descr, device_ids[i].type);
2031 break;
2034 if (i == VEC_SIZE(device_ids)) {
2035 printk("acx: EEPROM card ID string check found "
2036 "unknown card: expected 'Global', got '%.*s\'. "
2037 "Please report\n", CARD_EEPROM_ID_SIZE, buffer);
2040 #endif /* NONESSENTIAL_FEATURES */
2042 /***********************************************************************
2043 ** acxmem_free_desc_queues
2045 ** Releases the queues that have been allocated, the
2046 ** others have been initialised to NULL so this
2047 ** function can be used if only part of the queues were allocated.
2050 void
2051 acxmem_free_desc_queues(acx_device_t *adev)
2053 #define ACX_FREE_QUEUE(size, ptr, phyaddr) \
2054 if (ptr) { \
2055 kfree(ptr); \
2056 ptr = NULL; \
2057 size = 0; \
2060 FN_ENTER;
2062 ACX_FREE_QUEUE(adev->txhostdesc_area_size, adev->txhostdesc_start, adev->txhostdesc_startphy);
2063 ACX_FREE_QUEUE(adev->txbuf_area_size, adev->txbuf_start, adev->txbuf_startphy);
2065 adev->txdesc_start = NULL;
2067 ACX_FREE_QUEUE(adev->rxhostdesc_area_size, adev->rxhostdesc_start, adev->rxhostdesc_startphy);
2068 ACX_FREE_QUEUE(adev->rxbuf_area_size, adev->rxbuf_start, adev->rxbuf_startphy);
2070 adev->rxdesc_start = NULL;
2072 FN_EXIT0;
2076 /***********************************************************************
2077 ** acxmem_s_delete_dma_regions
2079 static void
2080 acxmem_s_delete_dma_regions(acx_device_t *adev)
2082 unsigned long flags;
2084 FN_ENTER;
2085 /* disable radio Tx/Rx. Shouldn't we use the firmware commands
2086 * here instead? Or are we that much down the road that it's no
2087 * longer possible here? */
2089 * slave memory interface really doesn't like this.
2092 write_reg16(adev, IO_ACX_ENABLE, 0);
2095 acx_s_msleep(100);
2097 acx_lock(adev, flags);
2098 acxmem_free_desc_queues(adev);
2099 acx_unlock(adev, flags);
2101 FN_EXIT0;
2105 /***********************************************************************
2106 ** acxmem_e_probe
2108 ** Probe routine called when a PCI device w/ matching ID is found.
2109 ** Here's the sequence:
2110 ** - Allocate the PCI resources.
2111 ** - Read the PCMCIA attribute memory to make sure we have a WLAN card
2112 ** - Reset the MAC
2113 ** - Initialize the dev and wlan data
2114 ** - Initialize the MAC
2116 ** pdev - ptr to pci device structure containing info about pci configuration
2117 ** id - ptr to the device id entry that matched this device
2119 static const u16
2120 IO_ACX100[] =
2122 0x0000, /* IO_ACX_SOFT_RESET */
2124 0x0014, /* IO_ACX_SLV_MEM_ADDR */
2125 0x0018, /* IO_ACX_SLV_MEM_DATA */
2126 0x001c, /* IO_ACX_SLV_MEM_CTL */
2127 0x0020, /* IO_ACX_SLV_END_CTL */
2129 0x0034, /* IO_ACX_FEMR */
2131 0x007c, /* IO_ACX_INT_TRIG */
2132 0x0098, /* IO_ACX_IRQ_MASK */
2133 0x00a4, /* IO_ACX_IRQ_STATUS_NON_DES */
2134 0x00a8, /* IO_ACX_IRQ_STATUS_CLEAR */
2135 0x00ac, /* IO_ACX_IRQ_ACK */
2136 0x00b0, /* IO_ACX_HINT_TRIG */
2138 0x0104, /* IO_ACX_ENABLE */
2140 0x0250, /* IO_ACX_EEPROM_CTL */
2141 0x0254, /* IO_ACX_EEPROM_ADDR */
2142 0x0258, /* IO_ACX_EEPROM_DATA */
2143 0x025c, /* IO_ACX_EEPROM_CFG */
2145 0x0268, /* IO_ACX_PHY_ADDR */
2146 0x026c, /* IO_ACX_PHY_DATA */
2147 0x0270, /* IO_ACX_PHY_CTL */
2149 0x0290, /* IO_ACX_GPIO_OE */
2151 0x0298, /* IO_ACX_GPIO_OUT */
2153 0x02a4, /* IO_ACX_CMD_MAILBOX_OFFS */
2154 0x02a8, /* IO_ACX_INFO_MAILBOX_OFFS */
2155 0x02ac, /* IO_ACX_EEPROM_INFORMATION */
2157 0x02d0, /* IO_ACX_EE_START */
2158 0x02d4, /* IO_ACX_SOR_CFG */
2159 0x02d8 /* IO_ACX_ECPU_CTRL */
2162 static const u16
2163 IO_ACX111[] =
2165 0x0000, /* IO_ACX_SOFT_RESET */
2167 0x0014, /* IO_ACX_SLV_MEM_ADDR */
2168 0x0018, /* IO_ACX_SLV_MEM_DATA */
2169 0x001c, /* IO_ACX_SLV_MEM_CTL */
2170 0x0020, /* IO_ACX_SLV_MEM_CP */
2172 0x0034, /* IO_ACX_FEMR */
2174 0x00b4, /* IO_ACX_INT_TRIG */
2175 0x00d4, /* IO_ACX_IRQ_MASK */
2176 /* we do mean NON_DES (0xf0), not NON_DES_MASK which is at 0xe0: */
2177 0x00f0, /* IO_ACX_IRQ_STATUS_NON_DES */
2178 0x00e4, /* IO_ACX_IRQ_STATUS_CLEAR */
2179 0x00e8, /* IO_ACX_IRQ_ACK */
2180 0x00ec, /* IO_ACX_HINT_TRIG */
2182 0x01d0, /* IO_ACX_ENABLE */
2184 0x0338, /* IO_ACX_EEPROM_CTL */
2185 0x033c, /* IO_ACX_EEPROM_ADDR */
2186 0x0340, /* IO_ACX_EEPROM_DATA */
2187 0x0344, /* IO_ACX_EEPROM_CFG */
2189 0x0350, /* IO_ACX_PHY_ADDR */
2190 0x0354, /* IO_ACX_PHY_DATA */
2191 0x0358, /* IO_ACX_PHY_CTL */
2193 0x0374, /* IO_ACX_GPIO_OE */
2195 0x037c, /* IO_ACX_GPIO_OUT */
2197 0x0388, /* IO_ACX_CMD_MAILBOX_OFFS */
2198 0x038c, /* IO_ACX_INFO_MAILBOX_OFFS */
2199 0x0390, /* IO_ACX_EEPROM_INFORMATION */
2201 0x0100, /* IO_ACX_EE_START */
2202 0x0104, /* IO_ACX_SOR_CFG */
2203 0x0108, /* IO_ACX_ECPU_CTRL */
2206 static void
2207 dummy_netdev_init(struct net_device *ndev) {}
2209 static int __devinit
2210 acxmem_e_probe(struct device *dev)
2212 struct platform_device *pdev = to_platform_device (dev);
2213 struct acx_hardware_data *hwdata = dev->platform_data;
2214 acx111_ie_configoption_t co;
2215 acx_device_t *adev = NULL;
2216 struct net_device *ndev = NULL;
2217 const char *chip_name;
2218 int result = -EIO;
2219 int err;
2220 int i;
2221 unsigned long addr_size=0;
2222 u8 chip_type;
2224 FN_ENTER;
2225 (void) hwdata->start_hw();
2227 /* FIXME: prism54 calls pci_set_mwi() here,
2228 * should we do/support the same? */
2230 /* chiptype is u8 but id->driver_data is ulong
2231 ** Works for now (possible values are 1 and 2) */
2232 chip_type = CHIPTYPE_ACX100;
2233 /* acx100 and acx111 have different PCI memory regions */
2234 if (chip_type == CHIPTYPE_ACX100) {
2235 chip_name = "ACX100";
2236 } else if (chip_type == CHIPTYPE_ACX111) {
2237 chip_name = "ACX111";
2238 } else {
2239 printk("acx: unknown chip type 0x%04X\n", chip_type);
2240 goto fail_unknown_chiptype;
2243 printk("acx: found %s-based wireless network card\n", chip_name);
2244 log(L_ANY, "initial debug setting is 0x%04X\n", acx_debug);
2246 ndev = alloc_netdev(sizeof(*adev), "wlan%d", dummy_netdev_init);
2247 /* (NB: memsets to 0 entire area) */
2248 if (!ndev) {
2249 printk("acx: no memory for netdevice structure\n");
2250 goto fail_alloc_netdev;
2253 dev_set_drvdata (dev, ndev);
2255 ether_setup(ndev);
2258 * use platform_data resources that were provided
2260 ndev->irq = 0;
2261 for (i=0; i<pdev->num_resources; i++) {
2262 if (pdev->resource[i].flags == IORESOURCE_IRQ) {
2263 ndev->irq = pdev->resource[i].start;
2265 else if (pdev->resource[i].flags == IORESOURCE_MEM) {
2266 ndev->base_addr = pdev->resource[i].start;
2267 addr_size = pdev->resource[i].end - pdev->resource[i].start;
2270 if (addr_size == 0 || ndev->irq == 0)
2271 goto fail_hw_params;
2272 ndev->open = &acxmem_e_open;
2273 ndev->stop = &acxmem_e_close;
2274 dev->release = &acxmem_e_release;
2275 ndev->hard_start_xmit = &acx_i_start_xmit;
2276 ndev->get_stats = &acx_e_get_stats;
2277 #if IW_HANDLER_VERSION <= 5
2278 ndev->get_wireless_stats = &acx_e_get_wireless_stats;
2279 #endif
2280 ndev->wireless_handlers = (struct iw_handler_def *)&acx_ioctl_handler_def;
2281 ndev->set_multicast_list = &acxmem_i_set_multicast_list;
2282 ndev->tx_timeout = &acxmem_i_tx_timeout;
2283 ndev->change_mtu = &acx_e_change_mtu;
2284 ndev->watchdog_timeo = 4 * HZ;
2286 adev = ndev2adev(ndev);
2287 spin_lock_init(&adev->lock); /* initial state: unlocked */
2288 spin_lock_init(&adev->txbuf_lock);
2289 /* We do not start with downed sem: we want PARANOID_LOCKING to work */
2290 sema_init(&adev->sem, 1); /* initial state: 1 (upped) */
2291 /* since nobody can see new netdev yet, we can as well
2292 ** just _presume_ that we're under sem (instead of actually taking it): */
2293 /* acx_sem_lock(adev); */
2294 adev->dev = dev;
2295 adev->ndev = ndev;
2296 adev->dev_type = DEVTYPE_MEM;
2297 adev->chip_type = chip_type;
2298 adev->chip_name = chip_name;
2299 adev->io = (CHIPTYPE_ACX100 == chip_type) ? IO_ACX100 : IO_ACX111;
2300 adev->membase = (volatile u32 *) ndev->base_addr;
2301 adev->iobase = (volatile u32 *) ioremap_nocache (ndev->base_addr, addr_size);
2302 /* to find crashes due to weird driver access
2303 * to unconfigured interface (ifup) */
2304 adev->mgmt_timer.function = (void (*)(unsigned long))0x0000dead;
2306 #if defined(NONESSENTIAL_FEATURES)
2307 acx_show_card_eeprom_id(adev);
2308 #endif /* NONESSENTIAL_FEATURES */
2310 #ifdef SET_MODULE_OWNER
2311 SET_MODULE_OWNER(ndev);
2312 #endif
2313 SET_NETDEV_DEV(ndev, dev);
2315 log(L_IRQ|L_INIT, "using IRQ %d\n", ndev->irq);
2317 /* ok, pci setup is finished, now start initializing the card */
2319 /* NB: read_reg() reads may return bogus data before reset_dev(),
2320 * since the firmware which directly controls large parts of the I/O
2321 * registers isn't initialized yet.
2322 * acx100 seems to be more affected than acx111 */
2323 if (OK != acxmem_s_reset_dev (adev))
2324 goto fail_reset;
2326 if (OK != acxmem_read_eeprom_byte(adev, 0x05, &adev->eeprom_version))
2327 goto fail_read_eeprom_version;
2329 if (IS_ACX100(adev)) {
2330 /* ACX100: configopt struct in cmd mailbox - directly after reset */
2331 copy_from_slavemem (adev, (u8*) &co, (u32) adev->cmd_area, sizeof (co));
2334 if (OK != acx_s_init_mac(adev))
2335 goto fail_init_mac;
2337 if (IS_ACX111(adev)) {
2338 /* ACX111: configopt struct needs to be queried after full init */
2339 acx_s_interrogate(adev, &co, ACX111_IE_CONFIG_OPTIONS);
2343 * Set up transmit buffer administration
2345 init_acx_txbuf (adev);
2348 //TODO: merge them into one function, they are called just once and are the same for pci & usb
2349 acx_s_parse_configoption(adev, &co);
2350 acx_s_set_defaults(adev);
2351 acx_s_get_firmware_version(adev); /* needs to be after acx_s_init_mac() */
2352 acx_display_hardware_details(adev);
2355 * Windows driver writes 0x01000000 to register 0x288, RADIO_CTL, if the form factor
2356 * is 3. It also write protects the EEPROM by writing 1<<9 to GPIO_OUT
2358 if (adev->form_factor == 3) {
2359 set_regbits (adev, 0x288, 0x01000000);
2360 set_regbits (adev, 0x298, 1<<9);
2363 /* Register the card, AFTER everything else has been set up,
2364 * since otherwise an ioctl could step on our feet due to
2365 * firmware operations happening in parallel or uninitialized data */
2366 err = register_netdev(ndev);
2367 if (OK != err) {
2368 printk("acx: register_netdev() FAILED: %d\n", err);
2369 goto fail_register_netdev;
2372 acx_proc_register_entries(ndev);
2374 /* Now we have our device, so make sure the kernel doesn't try
2375 * to send packets even though we're not associated to a network yet */
2376 acx_stop_queue(ndev, "on probe");
2377 acx_carrier_off(ndev, "on probe");
2380 * Set up a default monitor type so that poor combinations of initialization
2381 * sequences in monitor mode don't end up destroying the hardware type.
2383 adev->monitor_type = ARPHRD_ETHER;
2385 /* after register_netdev() userspace may start working with dev
2386 * (in particular, on other CPUs), we only need to up the sem */
2387 /* acx_sem_unlock(adev); */
2389 printk("acx "ACX_RELEASE": net device %s, driver compiled "
2390 "against wireless extensions %d and Linux %s\n",
2391 ndev->name, WIRELESS_EXT, UTS_RELEASE);
2393 #if CMD_DISCOVERY
2394 great_inquisitor(adev);
2395 #endif
2397 result = OK;
2398 goto done;
2400 /* error paths: undo everything in reverse order... */
2402 fail_register_netdev:
2404 acxmem_s_delete_dma_regions(adev);
2406 fail_init_mac:
2407 fail_read_eeprom_version:
2408 fail_reset:
2409 fail_hw_params:
2410 free_netdev(ndev);
2411 fail_alloc_netdev:
2412 fail_unknown_chiptype:
2415 done:
2416 FN_EXIT1(result);
2417 return result;
2421 /***********************************************************************
2422 ** acxmem_e_remove
2424 ** Deallocate PCI resources for the acx chip.
2426 ** This should NOT execute any other hardware operations on the card,
2427 ** since the card might already be ejected. Instead, that should be done
2428 ** in cleanup_module, since the card is most likely still available there.
2430 ** pdev - ptr to PCI device structure containing info about pci configuration
2432 static int __devexit
2433 acxmem_e_remove(struct device *pdev)
2435 struct net_device *ndev;
2436 acx_device_t *adev;
2438 FN_ENTER;
2440 ndev = (struct net_device*) dev_get_drvdata(pdev);
2441 if (!ndev) {
2442 log(L_DEBUG, "%s: card is unused. Skipping any release code\n",
2443 __func__);
2444 goto end;
2447 adev = ndev2adev(ndev);
2449 /* unregister the device to not let the kernel
2450 * (e.g. ioctls) access a half-deconfigured device
2451 * NB: this will cause acxmem_e_close() to be called,
2452 * thus we shouldn't call it under sem! */
2453 log(L_INIT, "removing device %s\n", ndev->name);
2454 unregister_netdev(ndev);
2456 /* unregister_netdev ensures that no references to us left.
2457 * For paranoid reasons we continue to follow the rules */
2458 acx_sem_lock(adev);
2460 acx_proc_unregister_entries(ndev);
2462 if (adev->dev_state_mask & ACX_STATE_IFACE_UP)
2463 acxmem_s_down(ndev);
2465 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
2467 acxmem_s_delete_dma_regions(adev);
2469 /* finally, clean up PCI bus state */
2470 if (adev->iobase) iounmap((void *)adev->iobase);
2472 /* Free netdev (quite late,
2473 * since otherwise we might get caught off-guard
2474 * by a netdev timeout handler execution
2475 * expecting to see a working dev...) */
2476 free_netdev(ndev);
2478 printk ("e_remove done\n");
2479 end:
2480 FN_EXIT0;
2482 return 0;
2486 /***********************************************************************
2487 ** TODO: PM code needs to be fixed / debugged / tested.
2489 #ifdef CONFIG_PM
2490 static int
2491 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
2492 acxmem_e_suspend(struct device *pdev, pm_message_t state)
2493 #else
2494 acxmem_e_suspend(struct device *pdev, u32 state)
2495 #endif
2497 struct net_device *ndev = dev_get_drvdata(pdev);
2498 acx_device_t *adev;
2500 FN_ENTER;
2501 printk("acx: suspend handler is experimental!\n");
2502 printk("sus: dev %p\n", ndev);
2504 if (!netif_running(ndev))
2505 goto end;
2507 adev = ndev2adev(ndev);
2508 printk("sus: adev %p\n", adev);
2510 acx_sem_lock(adev);
2512 netif_device_detach(ndev); /* this one cannot sleep */
2513 acxmem_s_down(ndev);
2514 /* down() does not set it to 0xffff, but here we really want that */
2515 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
2516 write_reg16(adev, IO_ACX_FEMR, 0x0);
2517 acxmem_s_delete_dma_regions(adev);
2519 acx_sem_unlock(adev);
2520 end:
2521 FN_EXIT0;
2522 return OK;
2526 static void
2527 fw_resumer( void *data )
2529 struct device *pdev = data;
2530 struct net_device *ndev = dev_get_drvdata(pdev);
2531 acx_device_t *adev;
2533 printk("acx: resume handler is experimental!\n");
2534 printk("rsm: got dev %p\n", ndev);
2536 if (!netif_running(ndev))
2537 return;
2539 adev = ndev2adev(ndev);
2540 printk("rsm: got adev %p\n", adev);
2542 acx_sem_lock(adev);
2544 if (OK != acxmem_s_reset_dev(adev))
2545 goto end_unlock;
2546 printk("rsm: device reset done\n");
2547 if (OK != acx_s_init_mac(adev))
2548 goto end_unlock;
2549 printk("rsm: init MAC done\n");
2552 * Windows driver writes 0x01000000 to register 0x288, RADIO_CTL, if the form factor
2553 * is 3. It also write protects the EEPROM by writing 1<<9 to GPIO_OUT
2555 if (adev->form_factor == 3) {
2556 set_regbits (adev, 0x288, 0x01000000);
2557 set_regbits (adev, 0x298, 1<<9);
2560 acxmem_s_up(ndev);
2561 printk("rsm: acx up done\n");
2563 /* now even reload all card parameters as they were before suspend,
2564 * and possibly be back in the network again already :-) */
2565 if (ACX_STATE_IFACE_UP & adev->dev_state_mask) {
2566 adev->set_mask = GETSET_ALL;
2567 acx_s_update_card_settings(adev);
2568 printk("rsm: settings updated\n");
2570 netif_device_attach(ndev);
2571 printk("rsm: device attached\n");
2573 end_unlock:
2574 acx_sem_unlock(adev);
2577 DECLARE_WORK( fw_resume_work, fw_resumer, 0 );
2579 static int
2580 acxmem_e_resume(struct device *pdev)
2582 FN_ENTER;
2584 fw_resume_work.data = pdev;
2585 schedule_work( &fw_resume_work );
2587 FN_EXIT0;
2588 return OK;
2590 #endif /* CONFIG_PM */
2593 /***********************************************************************
2594 ** acxmem_s_up
2596 ** This function is called by acxmem_e_open (when ifconfig sets the device as up)
2598 ** Side effects:
2599 ** - Enables on-card interrupt requests
2600 ** - calls acx_s_start
2603 static void
2604 enable_acx_irq(acx_device_t *adev)
2606 FN_ENTER;
2607 write_reg16(adev, IO_ACX_IRQ_MASK, adev->irq_mask);
2608 write_reg16(adev, IO_ACX_FEMR, 0x8000);
2609 adev->irqs_active = 1;
2610 FN_EXIT0;
2613 static void
2614 acxmem_s_up(struct net_device *ndev)
2616 acx_device_t *adev = ndev2adev(ndev);
2617 unsigned long flags;
2619 FN_ENTER;
2621 acx_lock(adev, flags);
2622 enable_acx_irq(adev);
2623 acx_unlock(adev, flags);
2625 /* acx fw < 1.9.3.e has a hardware timer, and older drivers
2626 ** used to use it. But we don't do that anymore, our OS
2627 ** has reliable software timers */
2628 init_timer(&adev->mgmt_timer);
2629 adev->mgmt_timer.function = acx_i_timer;
2630 adev->mgmt_timer.data = (unsigned long)adev;
2632 /* Need to set ACX_STATE_IFACE_UP first, or else
2633 ** timer won't be started by acx_set_status() */
2634 SET_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
2635 switch (adev->mode) {
2636 case ACX_MODE_0_ADHOC:
2637 case ACX_MODE_2_STA:
2638 /* actual scan cmd will happen in start() */
2639 acx_set_status(adev, ACX_STATUS_1_SCANNING); break;
2640 case ACX_MODE_3_AP:
2641 case ACX_MODE_MONITOR:
2642 acx_set_status(adev, ACX_STATUS_4_ASSOCIATED); break;
2645 acx_s_start(adev);
2647 FN_EXIT0;
2651 /***********************************************************************
2652 ** acxmem_s_down
2654 ** This disables the netdevice
2656 ** Side effects:
2657 ** - disables on-card interrupt request
2660 static void
2661 disable_acx_irq(acx_device_t *adev)
2663 FN_ENTER;
2665 /* I guess mask is not 0xffff because acx100 won't signal
2666 ** cmd completion then (needed for ifup).
2667 ** Someone with acx100 please confirm */
2668 write_reg16(adev, IO_ACX_IRQ_MASK, adev->irq_mask_off);
2669 write_reg16(adev, IO_ACX_FEMR, 0x0);
2670 adev->irqs_active = 0;
2671 FN_EXIT0;
2674 static void
2675 acxmem_s_down(struct net_device *ndev)
2677 acx_device_t *adev = ndev2adev(ndev);
2678 unsigned long flags;
2680 FN_ENTER;
2682 /* Disable IRQs first, so that IRQs cannot race with us */
2683 /* then wait until interrupts have finished executing on other CPUs */
2684 acx_lock(adev, flags);
2685 disable_acx_irq(adev);
2686 synchronize_irq(adev->pdev->irq);
2687 acx_unlock(adev, flags);
2689 /* we really don't want to have an asynchronous tasklet disturb us
2690 ** after something vital for its job has been shut down, so
2691 ** end all remaining work now.
2693 ** NB: carrier_off (done by set_status below) would lead to
2694 ** not yet fully understood deadlock in FLUSH_SCHEDULED_WORK().
2695 ** That's why we do FLUSH first.
2697 ** NB2: we have a bad locking bug here: FLUSH_SCHEDULED_WORK()
2698 ** waits for acx_e_after_interrupt_task to complete if it is running
2699 ** on another CPU, but acx_e_after_interrupt_task
2700 ** will sleep on sem forever, because it is taken by us!
2701 ** Work around that by temporary sem unlock.
2702 ** This will fail miserably if we'll be hit by concurrent
2703 ** iwconfig or something in between. TODO! */
2704 acx_sem_unlock(adev);
2705 FLUSH_SCHEDULED_WORK();
2706 acx_sem_lock(adev);
2708 /* This is possible:
2709 ** FLUSH_SCHEDULED_WORK -> acx_e_after_interrupt_task ->
2710 ** -> set_status(ASSOCIATED) -> wake_queue()
2711 ** That's why we stop queue _after_ FLUSH_SCHEDULED_WORK
2712 ** lock/unlock is just paranoia, maybe not needed */
2713 acx_lock(adev, flags);
2714 acx_stop_queue(ndev, "on ifdown");
2715 acx_set_status(adev, ACX_STATUS_0_STOPPED);
2716 acx_unlock(adev, flags);
2718 /* kernel/timer.c says it's illegal to del_timer_sync()
2719 ** a timer which restarts itself. We guarantee this cannot
2720 ** ever happen because acx_i_timer() never does this if
2721 ** status is ACX_STATUS_0_STOPPED */
2722 del_timer_sync(&adev->mgmt_timer);
2724 FN_EXIT0;
2728 /***********************************************************************
2729 ** acxmem_e_open
2731 ** Called as a result of SIOCSIFFLAGS ioctl changing the flags bit IFF_UP
2732 ** from clear to set. In other words: ifconfig up.
2734 ** Returns:
2735 ** 0 success
2736 ** >0 f/w reported error
2737 ** <0 driver reported error
2739 static int
2740 acxmem_e_open(struct net_device *ndev)
2742 acx_device_t *adev = ndev2adev(ndev);
2743 int result = OK;
2745 FN_ENTER;
2747 acx_sem_lock(adev);
2749 acx_init_task_scheduler(adev);
2751 //TODO: pci_set_power_state(pdev, PCI_D0); ?
2753 /* request shared IRQ handler */
2754 if (request_irq(ndev->irq, acxmem_i_interrupt, SA_INTERRUPT, ndev->name, ndev)) {
2755 printk("%s: request_irq FAILED\n", ndev->name);
2756 result = -EAGAIN;
2757 goto done;
2759 set_irq_type (ndev->irq, IRQT_FALLING);
2760 log(L_DEBUG|L_IRQ, "request_irq %d successful\n", ndev->irq);
2762 /* ifup device */
2763 acxmem_s_up(ndev);
2765 /* We don't currently have to do anything else.
2766 * The setup of the MAC should be subsequently completed via
2767 * the mlme commands.
2768 * Higher layers know we're ready from dev->start==1 and
2769 * dev->tbusy==0. Our rx path knows to pass up received/
2770 * frames because of dev->flags&IFF_UP is true.
2772 done:
2773 acx_sem_unlock(adev);
2775 FN_EXIT1(result);
2776 return result;
2780 /***********************************************************************
2781 ** acxmem_e_close
2783 ** Called as a result of SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
2784 ** from set to clear. I.e. called by "ifconfig DEV down"
2786 ** Returns:
2787 ** 0 success
2788 ** >0 f/w reported error
2789 ** <0 driver reported error
2791 static int
2792 acxmem_e_close(struct net_device *ndev)
2794 acx_device_t *adev = ndev2adev(ndev);
2796 FN_ENTER;
2798 acx_sem_lock(adev);
2800 /* ifdown device */
2801 CLEAR_BIT(adev->dev_state_mask, ACX_STATE_IFACE_UP);
2802 if (netif_device_present(ndev)) {
2803 acxmem_s_down(ndev);
2806 /* disable all IRQs, release shared IRQ handler */
2807 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
2808 write_reg16(adev, IO_ACX_FEMR, 0x0);
2809 free_irq(ndev->irq, ndev);
2811 //TODO: pci_set_power_state(pdev, PCI_D3hot); ?
2813 /* We currently don't have to do anything else.
2814 * Higher layers know we're not ready from dev->start==0 and
2815 * dev->tbusy==1. Our rx path knows to not pass up received
2816 * frames because of dev->flags&IFF_UP is false.
2818 acx_sem_unlock(adev);
2820 log(L_INIT, "closed device\n");
2821 FN_EXIT0;
2822 return OK;
2826 /***********************************************************************
2827 ** acxmem_i_tx_timeout
2829 ** Called from network core. Must not sleep!
2831 static void
2832 acxmem_i_tx_timeout(struct net_device *ndev)
2834 acx_device_t *adev = ndev2adev(ndev);
2835 unsigned long flags;
2836 unsigned int tx_num_cleaned;
2838 FN_ENTER;
2840 acx_lock(adev, flags);
2842 /* clean processed tx descs, they may have been completely full */
2843 tx_num_cleaned = acxmem_l_clean_txdesc(adev);
2845 /* nothing cleaned, yet (almost) no free buffers available?
2846 * --> clean all tx descs, no matter which status!!
2847 * Note that I strongly suspect that doing emergency cleaning
2848 * may confuse the firmware. This is a last ditch effort to get
2849 * ANYTHING to work again...
2851 * TODO: it's best to simply reset & reinit hw from scratch...
2853 if ((adev->tx_free <= TX_EMERG_CLEAN) && (tx_num_cleaned == 0)) {
2854 printk("%s: FAILED to free any of the many full tx buffers. "
2855 "Switching to emergency freeing. "
2856 "Please report!\n", ndev->name);
2857 acxmem_l_clean_txdesc_emergency(adev);
2860 if (acx_queue_stopped(ndev) && (ACX_STATUS_4_ASSOCIATED == adev->status))
2861 acx_wake_queue(ndev, "after tx timeout");
2863 /* stall may have happened due to radio drift, so recalib radio */
2864 acx_schedule_task(adev, ACX_AFTER_IRQ_CMD_RADIO_RECALIB);
2866 /* do unimportant work last */
2867 printk("%s: tx timeout!\n", ndev->name);
2868 adev->stats.tx_errors++;
2870 acx_unlock(adev, flags);
2872 FN_EXIT0;
2876 /***********************************************************************
2877 ** acxmem_i_set_multicast_list
2878 ** FIXME: most likely needs refinement
2880 static void
2881 acxmem_i_set_multicast_list(struct net_device *ndev)
2883 acx_device_t *adev = ndev2adev(ndev);
2884 unsigned long flags;
2886 FN_ENTER;
2888 acx_lock(adev, flags);
2890 /* firmwares don't have allmulti capability,
2891 * so just use promiscuous mode instead in this case. */
2892 if (ndev->flags & (IFF_PROMISC|IFF_ALLMULTI)) {
2893 SET_BIT(adev->rx_config_1, RX_CFG1_RCV_PROMISCUOUS);
2894 CLEAR_BIT(adev->rx_config_1, RX_CFG1_FILTER_ALL_MULTI);
2895 SET_BIT(adev->set_mask, SET_RXCONFIG);
2896 /* let kernel know in case *we* needed to set promiscuous */
2897 ndev->flags |= (IFF_PROMISC|IFF_ALLMULTI);
2898 } else {
2899 CLEAR_BIT(adev->rx_config_1, RX_CFG1_RCV_PROMISCUOUS);
2900 SET_BIT(adev->rx_config_1, RX_CFG1_FILTER_ALL_MULTI);
2901 SET_BIT(adev->set_mask, SET_RXCONFIG);
2902 ndev->flags &= ~(IFF_PROMISC|IFF_ALLMULTI);
2905 /* cannot update card settings directly here, atomic context */
2906 acx_schedule_task(adev, ACX_AFTER_IRQ_UPDATE_CARD_CFG);
2908 acx_unlock(adev, flags);
2910 FN_EXIT0;
2914 /***************************************************************
2915 ** acxmem_l_process_rxdesc
2917 ** Called directly and only from the IRQ handler
2920 #if !ACX_DEBUG
2921 static inline void log_rxbuffer(const acx_device_t *adev) {}
2922 #else
2923 static void
2924 log_rxbuffer(const acx_device_t *adev)
2926 register const struct rxhostdesc *rxhostdesc;
2927 int i;
2928 /* no FN_ENTER here, we don't want that */
2930 rxhostdesc = adev->rxhostdesc_start;
2931 if (unlikely(!rxhostdesc)) return;
2932 for (i = 0; i < RX_CNT; i++) {
2933 if ((rxhostdesc->Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
2934 && (rxhostdesc->Status & cpu_to_le32(DESC_STATUS_FULL)))
2935 printk("rx: buf %d full\n", i);
2936 rxhostdesc++;
2939 #endif
2941 static void
2942 acxmem_l_process_rxdesc(acx_device_t *adev)
2944 register rxhostdesc_t *hostdesc;
2945 register rxdesc_t *rxdesc;
2946 int count, tail;
2947 u32 addr;
2948 u8 Ctl_8;
2950 FN_ENTER;
2952 if (unlikely(acx_debug & L_BUFR))
2953 log_rxbuffer(adev);
2955 /* First, have a loop to determine the first descriptor that's
2956 * full, just in case there's a mismatch between our current
2957 * rx_tail and the full descriptor we're supposed to handle. */
2958 tail = adev->rx_tail;
2959 count = RX_CNT;
2960 while (1) {
2961 hostdesc = &adev->rxhostdesc_start[tail];
2962 rxdesc = &adev->rxdesc_start[tail];
2963 /* advance tail regardless of outcome of the below test */
2964 tail = (tail + 1) % RX_CNT;
2967 * Unlike the PCI interface, where the ACX can write directly to
2968 * the host descriptors, on the slave memory interface we have to
2969 * pull these. All we really need to do is check the Ctl_8 field
2970 * in the rx descriptor on the ACX, which should be 0x11000000 if
2971 * we should process it.
2973 Ctl_8 = hostdesc->Ctl_16 = read_slavemem8 (adev, (u32) &(rxdesc->Ctl_8));
2974 if ((Ctl_8 & DESC_CTL_HOSTOWN) &&
2975 (Ctl_8 & DESC_CTL_ACXDONE))
2976 break; /* found it! */
2978 if (unlikely(!--count)) /* hmm, no luck: all descs empty, bail out */
2979 goto end;
2982 /* now process descriptors, starting with the first we figured out */
2983 while (1) {
2984 log(L_BUFR, "rx: tail=%u Ctl_8=%02X\n", tail, Ctl_8);
2986 * If the ACX has CTL_RECLAIM set on this descriptor there
2987 * is no buffer associated; it just wants us to tell it to
2988 * reclaim the memory.
2990 if (!(Ctl_8 & DESC_CTL_RECLAIM)) {
2993 * slave interface - pull data now
2995 hostdesc->length = read_slavemem16 (adev, (u32) &(rxdesc->total_length));
2998 * hostdesc->data is an rxbuffer_t, which includes header information,
2999 * but the length in the data packet doesn't. The header information
3000 * takes up an additional 12 bytes, so add that to the length we copy.
3002 addr = read_slavemem32 (adev, (u32) &(rxdesc->ACXMemPtr));
3003 if (addr) {
3004 chaincopy_from_slavemem (adev, (u8 *) hostdesc->data, addr,
3005 hostdesc->length +
3006 (u32) &((rxbuffer_t *)0)->hdr_a3);
3007 acx_l_process_rxbuf(adev, hostdesc->data);
3010 else {
3011 printk ("rx reclaim only!\n");
3014 hostdesc->Status = 0;
3017 * Let the ACX know we're done.
3019 CLEAR_BIT (Ctl_8, DESC_CTL_HOSTOWN);
3020 SET_BIT (Ctl_8, DESC_CTL_HOSTDONE);
3021 SET_BIT (Ctl_8, DESC_CTL_RECLAIM);
3022 write_slavemem8 (adev, (u32) &rxdesc->Ctl_8, Ctl_8);
3025 * Now tell the ACX we've finished with the receive buffer so
3026 * it can finish the reclaim.
3028 write_reg16 (adev, IO_ACX_INT_TRIG, INT_TRIG_RXPRC);
3030 /* ok, descriptor is handled, now check the next descriptor */
3031 hostdesc = &adev->rxhostdesc_start[tail];
3032 rxdesc = &adev->rxdesc_start[tail];
3034 Ctl_8 = hostdesc->Ctl_16 = read_slavemem8 (adev, (u32) &(rxdesc->Ctl_8));
3036 /* if next descriptor is empty, then bail out */
3037 if (!(Ctl_8 & DESC_CTL_HOSTOWN) || !(Ctl_8 & DESC_CTL_ACXDONE))
3038 break;
3040 tail = (tail + 1) % RX_CNT;
3042 end:
3043 adev->rx_tail = tail;
3044 FN_EXIT0;
3048 /***********************************************************************
3049 ** acxmem_i_interrupt
3051 ** IRQ handler (atomic context, must not sleep, blah, blah)
3054 /* scan is complete. all frames now on the receive queue are valid */
3055 #define INFO_SCAN_COMPLETE 0x0001
3056 #define INFO_WEP_KEY_NOT_FOUND 0x0002
3057 /* hw has been reset as the result of a watchdog timer timeout */
3058 #define INFO_WATCH_DOG_RESET 0x0003
3059 /* failed to send out NULL frame from PS mode notification to AP */
3060 /* recommended action: try entering 802.11 PS mode again */
3061 #define INFO_PS_FAIL 0x0004
3062 /* encryption/decryption process on a packet failed */
3063 #define INFO_IV_ICV_FAILURE 0x0005
3065 /* Info mailbox format:
3066 2 bytes: type
3067 2 bytes: status
3068 more bytes may follow
3069 rumors say about status:
3070 0x0000 info available (set by hw)
3071 0x0001 information received (must be set by host)
3072 0x1000 info available, mailbox overflowed (messages lost) (set by hw)
3073 but in practice we've seen:
3074 0x9000 when we did not set status to 0x0001 on prev message
3075 0x1001 when we did set it
3076 0x0000 was never seen
3077 conclusion: this is really a bitfield:
3078 0x1000 is 'info available' bit
3079 'mailbox overflowed' bit is 0x8000, not 0x1000
3080 value of 0x0000 probably means that there are no messages at all
3081 P.S. I dunno how in hell hw is supposed to notice that messages are lost -
3082 it does NOT clear bit 0x0001, and this bit will probably stay forever set
3083 after we set it once. Let's hope this will be fixed in firmware someday
3086 static void
3087 handle_info_irq(acx_device_t *adev)
3089 #if ACX_DEBUG
3090 static const char * const info_type_msg[] = {
3091 "(unknown)",
3092 "scan complete",
3093 "WEP key not found",
3094 "internal watchdog reset was done",
3095 "failed to send powersave (NULL frame) notification to AP",
3096 "encrypt/decrypt on a packet has failed",
3097 "TKIP tx keys disabled",
3098 "TKIP rx keys disabled",
3099 "TKIP rx: key ID not found",
3100 "???",
3101 "???",
3102 "???",
3103 "???",
3104 "???",
3105 "???",
3106 "???",
3107 "TKIP IV value exceeds thresh"
3109 #endif
3110 u32 info_type, info_status;
3112 info_type = read_slavemem32 (adev, (u32) adev->info_area);
3114 info_status = (info_type >> 16);
3115 info_type = (u16)info_type;
3117 /* inform fw that we have read this info message */
3118 write_slavemem32(adev, (u32) adev->info_area, info_type | 0x00010000);
3119 write_reg16(adev, IO_ACX_INT_TRIG, INT_TRIG_INFOACK);
3120 write_flush(adev);
3122 log(L_CTL, "info_type:%04X info_status:%04X\n",
3123 info_type, info_status);
3125 log(L_IRQ, "got Info IRQ: status %04X type %04X: %s\n",
3126 info_status, info_type,
3127 info_type_msg[(info_type >= VEC_SIZE(info_type_msg)) ?
3128 0 : info_type]
3133 static void
3134 log_unusual_irq(u16 irqtype) {
3136 if (!printk_ratelimit())
3137 return;
3140 printk("acx: got");
3141 if (irqtype & HOST_INT_TX_XFER) {
3142 printk(" Tx_Xfer");
3144 if (irqtype & HOST_INT_RX_COMPLETE) {
3145 printk(" Rx_Complete");
3147 if (irqtype & HOST_INT_DTIM) {
3148 printk(" DTIM");
3150 if (irqtype & HOST_INT_BEACON) {
3151 printk(" Beacon");
3153 if (irqtype & HOST_INT_TIMER) {
3154 log(L_IRQ, " Timer");
3156 if (irqtype & HOST_INT_KEY_NOT_FOUND) {
3157 printk(" Key_Not_Found");
3159 if (irqtype & HOST_INT_IV_ICV_FAILURE) {
3160 printk(" IV_ICV_Failure");
3162 /* HOST_INT_CMD_COMPLETE */
3163 /* HOST_INT_INFO */
3164 if (irqtype & HOST_INT_OVERFLOW) {
3165 printk(" Overflow");
3167 if (irqtype & HOST_INT_PROCESS_ERROR) {
3168 printk(" Process_Error");
3170 /* HOST_INT_SCAN_COMPLETE */
3171 if (irqtype & HOST_INT_FCS_THRESHOLD) {
3172 printk(" FCS_Threshold");
3174 if (irqtype & HOST_INT_BEACON_MISSED) {
3175 printk(" Unknown");
3177 printk(" IRQ(s)\n");
3181 static void
3182 update_link_quality_led(acx_device_t *adev)
3184 int qual;
3186 qual = acx_signal_determine_quality(adev->wstats.qual.level, adev->wstats.qual.noise);
3187 if (qual > adev->brange_max_quality)
3188 qual = adev->brange_max_quality;
3190 if (time_after(jiffies, adev->brange_time_last_state_change +
3191 (HZ/2 - HZ/2 * (unsigned long)qual / adev->brange_max_quality ) )) {
3192 acxmem_l_power_led(adev, (adev->brange_last_state == 0));
3193 adev->brange_last_state ^= 1; /* toggle */
3194 adev->brange_time_last_state_change = jiffies;
3199 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* a la orinoco.c */
3201 static irqreturn_t
3202 acxmem_i_interrupt(int irq, void *dev_id)
3204 acx_device_t *adev;
3205 unsigned long flags;
3206 unsigned int irqcount = MAX_IRQLOOPS_PER_JIFFY;
3207 register u16 irqtype;
3208 u16 unmasked;
3210 adev = ndev2adev((struct net_device*)dev_id);
3212 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
3213 * I am paranoid */
3214 acx_lock(adev, flags);
3216 unmasked = read_reg16(adev, IO_ACX_IRQ_STATUS_CLEAR);
3217 if (unlikely(0xffff == unmasked)) {
3218 /* 0xffff value hints at missing hardware,
3219 * so don't do anything.
3220 * Not very clean, but other drivers do the same... */
3221 log(L_IRQ, "IRQ type:FFFF - device removed? IRQ_NONE\n");
3222 goto none;
3225 /* We will check only "interesting" IRQ types */
3226 irqtype = unmasked & ~adev->irq_mask;
3227 if (!irqtype) {
3228 /* We are on a shared IRQ line and it wasn't our IRQ */
3229 log(L_IRQ, "IRQ type:%04X, mask:%04X - all are masked, IRQ_NONE\n",
3230 unmasked, adev->irq_mask);
3231 goto none;
3234 /* Done here because IRQ_NONEs taking three lines of log
3235 ** drive me crazy */
3236 FN_ENTER;
3238 #define IRQ_ITERATE 1
3239 #if IRQ_ITERATE
3240 if (jiffies != adev->irq_last_jiffies) {
3241 adev->irq_loops_this_jiffy = 0;
3242 adev->irq_last_jiffies = jiffies;
3245 /* safety condition; we'll normally abort loop below
3246 * in case no IRQ type occurred */
3247 while (likely(--irqcount)) {
3248 #endif
3249 /* ACK all IRQs ASAP */
3250 write_reg16(adev, IO_ACX_IRQ_ACK, 0xffff);
3252 log(L_IRQ, "IRQ type:%04X, mask:%04X, type & ~mask:%04X\n",
3253 unmasked, adev->irq_mask, irqtype);
3255 /* Handle most important IRQ types first */
3256 if (irqtype & HOST_INT_RX_DATA) {
3257 log(L_IRQ, "got Rx_Data IRQ\n");
3258 acxmem_l_process_rxdesc(adev);
3260 if (irqtype & HOST_INT_TX_COMPLETE) {
3261 log(L_IRQ, "got Tx_Complete IRQ\n");
3262 /* don't clean up on each Tx complete, wait a bit
3263 * unless we're going towards full, in which case
3264 * we do it immediately, too (otherwise we might lockup
3265 * with a full Tx buffer if we go into
3266 * acxmem_l_clean_txdesc() at a time when we won't wakeup
3267 * the net queue in there for some reason...) */
3268 if (adev->tx_free <= TX_START_CLEAN) {
3269 #if TX_CLEANUP_IN_SOFTIRQ
3270 acx_schedule_task(adev, ACX_AFTER_IRQ_TX_CLEANUP);
3271 #else
3272 acxmem_l_clean_txdesc(adev);
3273 #endif
3277 /* Less frequent ones */
3278 if (irqtype & (0
3279 | HOST_INT_CMD_COMPLETE
3280 | HOST_INT_INFO
3281 | HOST_INT_SCAN_COMPLETE
3282 )) {
3283 if (irqtype & HOST_INT_CMD_COMPLETE) {
3284 log(L_IRQ, "got Command_Complete IRQ\n");
3285 /* save the state for the running issue_cmd() */
3286 SET_BIT(adev->irq_status, HOST_INT_CMD_COMPLETE);
3288 if (irqtype & HOST_INT_INFO) {
3289 handle_info_irq(adev);
3291 if (irqtype & HOST_INT_SCAN_COMPLETE) {
3292 log(L_IRQ, "got Scan_Complete IRQ\n");
3293 /* need to do that in process context */
3294 acx_schedule_task(adev, ACX_AFTER_IRQ_COMPLETE_SCAN);
3295 /* remember that fw is not scanning anymore */
3296 SET_BIT(adev->irq_status, HOST_INT_SCAN_COMPLETE);
3300 /* These we just log, but either they happen rarely
3301 * or we keep them masked out */
3302 if (irqtype & (0
3303 /* | HOST_INT_RX_DATA */
3304 /* | HOST_INT_TX_COMPLETE */
3305 | HOST_INT_TX_XFER
3306 | HOST_INT_RX_COMPLETE
3307 | HOST_INT_DTIM
3308 | HOST_INT_BEACON
3309 | HOST_INT_TIMER
3310 | HOST_INT_KEY_NOT_FOUND
3311 | HOST_INT_IV_ICV_FAILURE
3312 /* | HOST_INT_CMD_COMPLETE */
3313 /* | HOST_INT_INFO */
3314 | HOST_INT_OVERFLOW
3315 | HOST_INT_PROCESS_ERROR
3316 /* | HOST_INT_SCAN_COMPLETE */
3317 | HOST_INT_FCS_THRESHOLD
3318 | HOST_INT_BEACON_MISSED
3319 )) {
3320 log_unusual_irq(irqtype);
3323 #if IRQ_ITERATE
3324 unmasked = read_reg16(adev, IO_ACX_IRQ_STATUS_CLEAR);
3325 irqtype = unmasked & ~adev->irq_mask;
3326 /* Bail out if no new IRQ bits or if all are masked out */
3327 if (!irqtype)
3328 break;
3330 if (unlikely(++adev->irq_loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY)) {
3331 printk(KERN_ERR "acx: too many interrupts per jiffy!\n");
3332 /* Looks like card floods us with IRQs! Try to stop that */
3333 write_reg16(adev, IO_ACX_IRQ_MASK, 0xffff);
3334 /* This will short-circuit all future attempts to handle IRQ.
3335 * We cant do much more... */
3336 adev->irq_mask = 0;
3337 break;
3340 #endif
3341 /* Routine to perform blink with range */
3342 if (unlikely(adev->led_power == 2))
3343 update_link_quality_led(adev);
3345 /* handled: */
3346 /* write_flush(adev); - not needed, last op was read anyway */
3347 acx_unlock(adev, flags);
3348 FN_EXIT0;
3349 return IRQ_HANDLED;
3351 none:
3352 acx_unlock(adev, flags);
3353 return IRQ_NONE;
3357 /***********************************************************************
3358 ** acxmem_l_power_led
3360 void
3361 acxmem_l_power_led(acx_device_t *adev, int enable)
3363 u16 gpio_pled = IS_ACX111(adev) ? 0x0040 : 0x0800;
3365 /* A hack. Not moving message rate limiting to adev->xxx
3366 * (it's only a debug message after all) */
3367 static int rate_limit = 0;
3369 if (rate_limit++ < 3)
3370 log(L_IOCTL, "Please report in case toggling the power "
3371 "LED doesn't work for your card!\n");
3372 if (enable)
3373 write_reg16(adev, IO_ACX_GPIO_OUT,
3374 read_reg16(adev, IO_ACX_GPIO_OUT) & ~gpio_pled);
3375 else
3376 write_reg16(adev, IO_ACX_GPIO_OUT,
3377 read_reg16(adev, IO_ACX_GPIO_OUT) | gpio_pled);
3381 /***********************************************************************
3382 ** Ioctls
3385 /***********************************************************************
3388 acx111pci_ioctl_info(
3389 struct net_device *ndev,
3390 struct iw_request_info *info,
3391 struct iw_param *vwrq,
3392 char *extra)
3394 #if ACX_DEBUG > 1
3395 acx_device_t *adev = ndev2adev(ndev);
3396 rxdesc_t *rxdesc;
3397 txdesc_t *txdesc;
3398 rxhostdesc_t *rxhostdesc;
3399 txhostdesc_t *txhostdesc;
3400 struct acx111_ie_memoryconfig memconf;
3401 struct acx111_ie_queueconfig queueconf;
3402 unsigned long flags;
3403 int i;
3404 char memmap[0x34];
3405 char rxconfig[0x8];
3406 char fcserror[0x8];
3407 char ratefallback[0x5];
3409 if ( !(acx_debug & (L_IOCTL|L_DEBUG)) )
3410 return OK;
3411 /* using printk() since we checked debug flag already */
3413 acx_sem_lock(adev);
3415 if (!IS_ACX111(adev)) {
3416 printk("acx111-specific function called "
3417 "with non-acx111 chip, aborting\n");
3418 goto end_ok;
3421 /* get Acx111 Memory Configuration */
3422 memset(&memconf, 0, sizeof(memconf));
3423 /* BTW, fails with 12 (Write only) error code.
3424 ** Retained for easy testing of issue_cmd error handling :) */
3425 printk ("Interrogating queue config\n");
3426 acx_s_interrogate(adev, &memconf, ACX1xx_IE_QUEUE_CONFIG);
3427 printk ("done with queue config\n");
3429 /* get Acx111 Queue Configuration */
3430 memset(&queueconf, 0, sizeof(queueconf));
3431 printk ("Interrogating mem config options\n");
3432 acx_s_interrogate(adev, &queueconf, ACX1xx_IE_MEMORY_CONFIG_OPTIONS);
3433 printk ("done with mem config options\n");
3435 /* get Acx111 Memory Map */
3436 memset(memmap, 0, sizeof(memmap));
3437 printk ("Interrogating mem map\n");
3438 acx_s_interrogate(adev, &memmap, ACX1xx_IE_MEMORY_MAP);
3439 printk ("done with mem map\n");
3441 /* get Acx111 Rx Config */
3442 memset(rxconfig, 0, sizeof(rxconfig));
3443 printk ("Interrogating rxconfig\n");
3444 acx_s_interrogate(adev, &rxconfig, ACX1xx_IE_RXCONFIG);
3445 printk ("done with queue rxconfig\n");
3447 /* get Acx111 fcs error count */
3448 memset(fcserror, 0, sizeof(fcserror));
3449 printk ("Interrogating fcs err count\n");
3450 acx_s_interrogate(adev, &fcserror, ACX1xx_IE_FCS_ERROR_COUNT);
3451 printk ("done with err count\n");
3453 /* get Acx111 rate fallback */
3454 memset(ratefallback, 0, sizeof(ratefallback));
3455 printk ("Interrogating rate fallback\n");
3456 acx_s_interrogate(adev, &ratefallback, ACX1xx_IE_RATE_FALLBACK);
3457 printk ("done with rate fallback\n");
3459 /* force occurrence of a beacon interrupt */
3460 /* TODO: comment why is this necessary */
3461 write_reg16(adev, IO_ACX_HINT_TRIG, HOST_INT_BEACON);
3463 /* dump Acx111 Mem Configuration */
3464 printk("dump mem config:\n"
3465 "data read: %d, struct size: %d\n"
3466 "Number of stations: %1X\n"
3467 "Memory block size: %1X\n"
3468 "tx/rx memory block allocation: %1X\n"
3469 "count rx: %X / tx: %X queues\n"
3470 "options %1X\n"
3471 "fragmentation %1X\n"
3472 "Rx Queue 1 Count Descriptors: %X\n"
3473 "Rx Queue 1 Host Memory Start: %X\n"
3474 "Tx Queue 1 Count Descriptors: %X\n"
3475 "Tx Queue 1 Attributes: %X\n",
3476 memconf.len, (int) sizeof(memconf),
3477 memconf.no_of_stations,
3478 memconf.memory_block_size,
3479 memconf.tx_rx_memory_block_allocation,
3480 memconf.count_rx_queues, memconf.count_tx_queues,
3481 memconf.options,
3482 memconf.fragmentation,
3483 memconf.rx_queue1_count_descs,
3484 acx2cpu(memconf.rx_queue1_host_rx_start),
3485 memconf.tx_queue1_count_descs,
3486 memconf.tx_queue1_attributes);
3488 /* dump Acx111 Queue Configuration */
3489 printk("dump queue head:\n"
3490 "data read: %d, struct size: %d\n"
3491 "tx_memory_block_address (from card): %X\n"
3492 "rx_memory_block_address (from card): %X\n"
3493 "rx1_queue address (from card): %X\n"
3494 "tx1_queue address (from card): %X\n"
3495 "tx1_queue attributes (from card): %X\n",
3496 queueconf.len, (int) sizeof(queueconf),
3497 queueconf.tx_memory_block_address,
3498 queueconf.rx_memory_block_address,
3499 queueconf.rx1_queue_address,
3500 queueconf.tx1_queue_address,
3501 queueconf.tx1_attributes);
3503 /* dump Acx111 Mem Map */
3504 printk("dump mem map:\n"
3505 "data read: %d, struct size: %d\n"
3506 "Code start: %X\n"
3507 "Code end: %X\n"
3508 "WEP default key start: %X\n"
3509 "WEP default key end: %X\n"
3510 "STA table start: %X\n"
3511 "STA table end: %X\n"
3512 "Packet template start: %X\n"
3513 "Packet template end: %X\n"
3514 "Queue memory start: %X\n"
3515 "Queue memory end: %X\n"
3516 "Packet memory pool start: %X\n"
3517 "Packet memory pool end: %X\n"
3518 "iobase: %p\n"
3519 "iobase2: %p\n",
3520 *((u16 *)&memmap[0x02]), (int) sizeof(memmap),
3521 *((u32 *)&memmap[0x04]),
3522 *((u32 *)&memmap[0x08]),
3523 *((u32 *)&memmap[0x0C]),
3524 *((u32 *)&memmap[0x10]),
3525 *((u32 *)&memmap[0x14]),
3526 *((u32 *)&memmap[0x18]),
3527 *((u32 *)&memmap[0x1C]),
3528 *((u32 *)&memmap[0x20]),
3529 *((u32 *)&memmap[0x24]),
3530 *((u32 *)&memmap[0x28]),
3531 *((u32 *)&memmap[0x2C]),
3532 *((u32 *)&memmap[0x30]),
3533 adev->iobase,
3534 adev->iobase2);
3536 /* dump Acx111 Rx Config */
3537 printk("dump rx config:\n"
3538 "data read: %d, struct size: %d\n"
3539 "rx config: %X\n"
3540 "rx filter config: %X\n",
3541 *((u16 *)&rxconfig[0x02]), (int) sizeof(rxconfig),
3542 *((u16 *)&rxconfig[0x04]),
3543 *((u16 *)&rxconfig[0x06]));
3545 /* dump Acx111 fcs error */
3546 printk("dump fcserror:\n"
3547 "data read: %d, struct size: %d\n"
3548 "fcserrors: %X\n",
3549 *((u16 *)&fcserror[0x02]), (int) sizeof(fcserror),
3550 *((u32 *)&fcserror[0x04]));
3552 /* dump Acx111 rate fallback */
3553 printk("dump rate fallback:\n"
3554 "data read: %d, struct size: %d\n"
3555 "ratefallback: %X\n",
3556 *((u16 *)&ratefallback[0x02]), (int) sizeof(ratefallback),
3557 *((u8 *)&ratefallback[0x04]));
3559 /* protect against IRQ */
3560 acx_lock(adev, flags);
3562 /* dump acx111 internal rx descriptor ring buffer */
3563 rxdesc = adev->rxdesc_start;
3565 /* loop over complete receive pool */
3566 if (rxdesc) for (i = 0; i < RX_CNT; i++) {
3567 printk("\ndump internal rxdesc %d:\n"
3568 "mem pos %p\n"
3569 "next 0x%X\n"
3570 "acx mem pointer (dynamic) 0x%X\n"
3571 "CTL (dynamic) 0x%X\n"
3572 "Rate (dynamic) 0x%X\n"
3573 "RxStatus (dynamic) 0x%X\n"
3574 "Mod/Pre (dynamic) 0x%X\n",
3576 rxdesc,
3577 acx2cpu(rxdesc->pNextDesc),
3578 acx2cpu(rxdesc->ACXMemPtr),
3579 rxdesc->Ctl_8,
3580 rxdesc->rate,
3581 rxdesc->error,
3582 rxdesc->SNR);
3583 rxdesc++;
3586 /* dump host rx descriptor ring buffer */
3588 rxhostdesc = adev->rxhostdesc_start;
3590 /* loop over complete receive pool */
3591 if (rxhostdesc) for (i = 0; i < RX_CNT; i++) {
3592 printk("\ndump host rxdesc %d:\n"
3593 "mem pos %p\n"
3594 "buffer mem pos 0x%X\n"
3595 "buffer mem offset 0x%X\n"
3596 "CTL 0x%X\n"
3597 "Length 0x%X\n"
3598 "next 0x%X\n"
3599 "Status 0x%X\n",
3601 rxhostdesc,
3602 acx2cpu(rxhostdesc->data_phy),
3603 rxhostdesc->data_offset,
3604 le16_to_cpu(rxhostdesc->Ctl_16),
3605 le16_to_cpu(rxhostdesc->length),
3606 acx2cpu(rxhostdesc->desc_phy_next),
3607 rxhostdesc->Status);
3608 rxhostdesc++;
3611 /* dump acx111 internal tx descriptor ring buffer */
3612 txdesc = adev->txdesc_start;
3614 /* loop over complete transmit pool */
3615 if (txdesc) for (i = 0; i < TX_CNT; i++) {
3616 printk("\ndump internal txdesc %d:\n"
3617 "size 0x%X\n"
3618 "mem pos %p\n"
3619 "next 0x%X\n"
3620 "acx mem pointer (dynamic) 0x%X\n"
3621 "host mem pointer (dynamic) 0x%X\n"
3622 "length (dynamic) 0x%X\n"
3623 "CTL (dynamic) 0x%X\n"
3624 "CTL2 (dynamic) 0x%X\n"
3625 "Status (dynamic) 0x%X\n"
3626 "Rate (dynamic) 0x%X\n",
3628 (int) sizeof(struct txdesc),
3629 txdesc,
3630 acx2cpu(txdesc->pNextDesc),
3631 acx2cpu(txdesc->AcxMemPtr),
3632 acx2cpu(txdesc->HostMemPtr),
3633 le16_to_cpu(txdesc->total_length),
3634 txdesc->Ctl_8,
3635 txdesc->Ctl2_8, txdesc->error,
3636 txdesc->u.r1.rate);
3637 txdesc = advance_txdesc(adev, txdesc, 1);
3640 /* dump host tx descriptor ring buffer */
3642 txhostdesc = adev->txhostdesc_start;
3644 /* loop over complete host send pool */
3645 if (txhostdesc) for (i = 0; i < TX_CNT * 2; i++) {
3646 printk("\ndump host txdesc %d:\n"
3647 "mem pos %p\n"
3648 "buffer mem pos 0x%X\n"
3649 "buffer mem offset 0x%X\n"
3650 "CTL 0x%X\n"
3651 "Length 0x%X\n"
3652 "next 0x%X\n"
3653 "Status 0x%X\n",
3655 txhostdesc,
3656 acx2cpu(txhostdesc->data_phy),
3657 txhostdesc->data_offset,
3658 le16_to_cpu(txhostdesc->Ctl_16),
3659 le16_to_cpu(txhostdesc->length),
3660 acx2cpu(txhostdesc->desc_phy_next),
3661 le32_to_cpu(txhostdesc->Status));
3662 txhostdesc++;
3665 /* write_reg16(adev, 0xb4, 0x4); */
3667 acx_unlock(adev, flags);
3668 end_ok:
3670 acx_sem_unlock(adev);
3671 #endif /* ACX_DEBUG */
3672 return OK;
3676 /***********************************************************************
3679 acx100mem_ioctl_set_phy_amp_bias(
3680 struct net_device *ndev,
3681 struct iw_request_info *info,
3682 struct iw_param *vwrq,
3683 char *extra)
3685 acx_device_t *adev = ndev2adev(ndev);
3686 unsigned long flags;
3687 u16 gpio_old;
3689 if (!IS_ACX100(adev)) {
3690 /* WARNING!!!
3691 * Removing this check *might* damage
3692 * hardware, since we're tweaking GPIOs here after all!!!
3693 * You've been warned...
3694 * WARNING!!! */
3695 printk("acx: sorry, setting bias level for non-acx100 "
3696 "is not supported yet\n");
3697 return OK;
3700 if (*extra > 7) {
3701 printk("acx: invalid bias parameter, range is 0-7\n");
3702 return -EINVAL;
3705 acx_sem_lock(adev);
3707 /* Need to lock accesses to [IO_ACX_GPIO_OUT]:
3708 * IRQ handler uses it to update LED */
3709 acx_lock(adev, flags);
3710 gpio_old = read_reg16(adev, IO_ACX_GPIO_OUT);
3711 write_reg16(adev, IO_ACX_GPIO_OUT, (gpio_old & 0xf8ff) | ((u16)*extra << 8));
3712 acx_unlock(adev, flags);
3714 log(L_DEBUG, "gpio_old: 0x%04X\n", gpio_old);
3715 printk("%s: PHY power amplifier bias: old:%d, new:%d\n",
3716 ndev->name,
3717 (gpio_old & 0x0700) >> 8, (unsigned char)*extra);
3719 acx_sem_unlock(adev);
3721 return OK;
3724 /***************************************************************
3725 ** acxmem_l_alloc_tx
3726 ** Actually returns a txdesc_t* ptr
3728 ** FIXME: in case of fragments, should allocate multiple descrs
3729 ** after figuring out how many we need and whether we still have
3730 ** sufficiently many.
3732 tx_t*
3733 acxmem_l_alloc_tx(acx_device_t *adev)
3735 struct txdesc *txdesc;
3736 int head;
3737 u8 ctl8;
3739 FN_ENTER;
3741 if (unlikely(!adev->tx_free)) {
3742 printk("acx: BUG: no free txdesc left\n");
3743 txdesc = NULL;
3744 goto end;
3748 * Make a quick check to see if there is transmit buffer space on
3749 * the ACX. This can't guarantee there is enough space for the packet
3750 * since we don't yet know how big it is, but it will prevent at least some
3751 * annoyances.
3753 if (!adev->acx_txbuf_blocks_free) {
3754 txdesc = NULL;
3755 goto end;
3758 head = adev->tx_head;
3760 * txdesc points to ACX memory
3762 txdesc = get_txdesc(adev, head);
3763 ctl8 = read_slavemem8 (adev, (u32) &(txdesc->Ctl_8));
3766 * If we don't own the buffer (HOSTOWN) it is certainly not free; however,
3767 * we may have previously thought we had enough memory to send
3768 * a packet, allocated the buffer then gave up when we found not enough
3769 * transmit buffer space on the ACX. In that case, HOSTOWN and
3770 * ACXDONE will both be set.
3772 if (unlikely(DESC_CTL_HOSTOWN != (ctl8 & DESC_CTL_HOSTOWN))) {
3773 /* whoops, descr at current index is not free, so probably
3774 * ring buffer already full */
3775 printk("acx: BUG: tx_head:%d Ctl8:0x%02X - failed to find "
3776 "free txdesc\n", head, ctl8);
3777 txdesc = NULL;
3778 goto end;
3781 /* Needed in case txdesc won't be eventually submitted for tx */
3782 write_slavemem8 (adev, (u32) &(txdesc->Ctl_8), DESC_CTL_ACXDONE_HOSTOWN);
3784 adev->tx_free--;
3785 printk( KERN_NOTICE "tx: got desc %u, %u remain\n",
3786 head, adev->tx_free);
3787 /* Keep a few free descs between head and tail of tx ring.
3788 ** It is not absolutely needed, just feels safer */
3789 if (adev->tx_free < TX_STOP_QUEUE) {
3790 log(L_BUF, "stop queue (%u tx desc left)\n",
3791 adev->tx_free);
3792 acx_stop_queue(adev->ndev, NULL);
3795 /* returning current descriptor, so advance to next free one */
3796 adev->tx_head = (head + 1) % TX_CNT;
3797 end:
3798 FN_EXIT0;
3800 return (tx_t*)txdesc;
3804 /***************************************************************
3805 ** acxmem_l_dealloc_tx
3806 ** Clears out a previously allocatedvoid acxmem_l_dealloc_tx(tx_t *tx_opaque);
3807 transmit descriptor. The ACX
3808 ** can get confused if we skip transmit descriptors in the queue,
3809 ** so when we don't need a descriptor return it to its original
3810 ** state and move the queue head pointer back.
3813 void
3814 acxmem_l_dealloc_tx(acx_device_t *adev, tx_t *tx_opaque)
3817 * txdesc is the address of the descriptor on the ACX.
3819 txdesc_t *txdesc = (txdesc_t*)tx_opaque;
3820 txdesc_t tmptxdesc;
3821 int index;
3823 memset (&tmptxdesc, 0, sizeof(tmptxdesc));
3824 tmptxdesc.Ctl_8 = DESC_CTL_HOSTOWN | DESC_CTL_FIRSTFRAG;
3825 tmptxdesc.u.r1.rate = 0x0a;
3828 * Clear out all of the transmit descriptor except for the next pointer
3830 copy_to_slavemem (adev, (u32) &(txdesc->HostMemPtr),
3831 (u8 *) &(tmptxdesc.HostMemPtr),
3832 sizeof (tmptxdesc) - sizeof(tmptxdesc.pNextDesc));
3835 * This is only called immediately after we've allocated, so we should
3836 * be able to set the head back to this descriptor.
3838 index = ((u8*) txdesc - (u8*)adev->txdesc_start) / adev->txdesc_size;
3839 printk ("acx_dealloc: moving head from %d to %d\n", adev->tx_head, index);
3840 adev->tx_head = index;
3844 /***********************************************************************
3846 void*
3847 acxmem_l_get_txbuf(acx_device_t *adev, tx_t* tx_opaque)
3849 return get_txhostdesc(adev, (txdesc_t*)tx_opaque)->data;
3853 /***********************************************************************
3854 ** acxmem_l_tx_data
3856 ** Can be called from IRQ (rx -> (AP bridging or mgmt response) -> tx).
3857 ** Can be called from acx_i_start_xmit (data frames from net core).
3859 ** FIXME: in case of fragments, should loop over the number of
3860 ** pre-allocated tx descrs, properly setting up transfer data and
3861 ** CTL_xxx flags according to fragment number.
3863 void
3864 acxmem_update_queue_indicator (acx_device_t *adev, int txqueue)
3866 #ifdef USING_MORE_THAN_ONE_TRANSMIT_QUEUE
3867 u32 indicator;
3868 unsigned long flags;
3869 int count;
3872 * Can't handle an interrupt while we're fiddling with the ACX's lock,
3873 * according to TI. The ACX is supposed to hold fw_lock for at most
3874 * 500ns.
3876 local_irq_save (flags);
3879 * Wait for ACX to release the lock (at most 500ns).
3881 count = 0;
3882 while (read_slavemem16 (adev, (u32) &(adev->acx_queue_indicator->fw_lock))
3883 && (count++ < 50)) {
3884 ndelay (10);
3886 if (count < 50) {
3889 * Take out the host lock - anything non-zero will work, so don't worry about
3890 * be/le
3892 write_slavemem16 (adev, (u32) &(adev->acx_queue_indicator->host_lock), 1);
3895 * Avoid a race condition
3897 count = 0;
3898 while (read_slavemem16 (adev, (u32) &(adev->acx_queue_indicator->fw_lock))
3899 && (count++ < 50)) {
3900 ndelay (10);
3903 if (count < 50) {
3905 * Mark the queue active
3907 indicator = read_slavemem32 (adev, (u32) &(adev->acx_queue_indicator->indicator));
3908 indicator |= cpu_to_le32 (1 << txqueue);
3909 write_slavemem32 (adev, (u32) &(adev->acx_queue_indicator->indicator), indicator);
3913 * Release the host lock
3915 write_slavemem16 (adev, (u32) &(adev->acx_queue_indicator->host_lock), 0);
3920 * Restore interrupts
3922 local_irq_restore (flags);
3923 #endif
3926 void
3927 acxmem_l_tx_data(acx_device_t *adev, tx_t* tx_opaque, int len)
3930 * txdesc is the address on the ACX
3932 txdesc_t *txdesc = (txdesc_t*)tx_opaque;
3933 txhostdesc_t *hostdesc1, *hostdesc2;
3934 client_t *clt;
3935 u16 rate_cur;
3936 u8 Ctl_8, Ctl2_8;
3937 u32 addr;
3939 FN_ENTER;
3940 /* fw doesn't tx such packets anyhow */
3941 if (unlikely(len < WLAN_HDR_A3_LEN))
3942 goto end;
3944 hostdesc1 = get_txhostdesc(adev, txdesc);
3945 /* modify flag status in separate variable to be able to write it back
3946 * in one big swoop later (also in order to have less device memory
3947 * accesses) */
3948 Ctl_8 = read_slavemem8 (adev, (u32) &(txdesc->Ctl_8));
3949 Ctl2_8 = 0; /* really need to init it to 0, not txdesc->Ctl2_8, it seems */
3951 hostdesc2 = hostdesc1 + 1;
3953 /* DON'T simply set Ctl field to 0 here globally,
3954 * it needs to maintain a consistent flag status (those are state flags!!),
3955 * otherwise it may lead to severe disruption. Only set or reset particular
3956 * flags at the exact moment this is needed... */
3958 /* let chip do RTS/CTS handshaking before sending
3959 * in case packet size exceeds threshold */
3960 if (len > adev->rts_threshold)
3961 SET_BIT(Ctl2_8, DESC_CTL2_RTS);
3962 else
3963 CLEAR_BIT(Ctl2_8, DESC_CTL2_RTS);
3965 switch (adev->mode) {
3966 case ACX_MODE_0_ADHOC:
3967 case ACX_MODE_3_AP:
3968 clt = acx_l_sta_list_get(adev, ((wlan_hdr_t*)hostdesc1->data)->a1);
3969 break;
3970 case ACX_MODE_2_STA:
3971 clt = adev->ap_client;
3972 break;
3973 #if 0
3974 /* testing was done on acx111: */
3975 case ACX_MODE_MONITOR:
3976 SET_BIT(Ctl2_8, 0
3977 /* sends CTS to self before packet */
3978 + DESC_CTL2_SEQ /* don't increase sequence field */
3979 /* not working (looks like good fcs is still added) */
3980 + DESC_CTL2_FCS /* don't add the FCS */
3981 /* not tested */
3982 + DESC_CTL2_MORE_FRAG
3983 /* not tested */
3984 + DESC_CTL2_RETRY /* don't increase retry field */
3985 /* not tested */
3986 + DESC_CTL2_POWER /* don't increase power mgmt. field */
3987 /* no effect */
3988 + DESC_CTL2_WEP /* encrypt this frame */
3989 /* not tested */
3990 + DESC_CTL2_DUR /* don't increase duration field */
3992 /* fallthrough */
3993 #endif
3994 default: /* ACX_MODE_OFF, ACX_MODE_MONITOR */
3995 clt = NULL;
3996 break;
3999 rate_cur = clt ? clt->rate_cur : adev->rate_bcast;
4000 if (unlikely(!rate_cur)) {
4001 printk("acx: driver bug! bad ratemask\n");
4002 goto end;
4005 /* used in tx cleanup routine for auto rate and accounting: */
4006 put_txcr(adev, txdesc, clt, rate_cur);
4008 write_slavemem16 (adev, (u32) &(txdesc->total_length), cpu_to_le16(len));
4009 hostdesc2->length = cpu_to_le16(len - WLAN_HDR_A3_LEN);
4010 if (IS_ACX111(adev)) {
4011 /* note that if !txdesc->do_auto, txrate->cur
4012 ** has only one nonzero bit */
4013 txdesc->u.r2.rate111 = cpu_to_le16(
4014 rate_cur
4015 /* WARNING: I was never able to make it work with prism54 AP.
4016 ** It was falling down to 1Mbit where shortpre is not applicable,
4017 ** and not working at all at "5,11 basic rates only" setting.
4018 ** I even didn't see tx packets in radio packet capture.
4019 ** Disabled for now --vda */
4020 /*| ((clt->shortpre && clt->cur!=RATE111_1) ? RATE111_SHORTPRE : 0) */
4022 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
4023 /* should add this to rate111 above as necessary */
4024 | (clt->pbcc511 ? RATE111_PBCC511 : 0)
4025 #endif
4026 hostdesc1->length = cpu_to_le16(len);
4027 } else { /* ACX100 */
4028 u8 rate_100 = clt ? clt->rate_100 : adev->rate_bcast100;
4029 write_slavemem8 (adev, (u32) &(txdesc->u.r1.rate), rate_100);
4030 #ifdef TODO_FIGURE_OUT_WHEN_TO_SET_THIS
4031 if (clt->pbcc511) {
4032 if (n == RATE100_5 || n == RATE100_11)
4033 n |= RATE100_PBCC511;
4036 if (clt->shortpre && (clt->cur != RATE111_1))
4037 SET_BIT(Ctl_8, DESC_CTL_SHORT_PREAMBLE); /* set Short Preamble */
4038 #endif
4039 /* set autodma and reclaim and 1st mpdu */
4040 SET_BIT(Ctl_8, DESC_CTL_FIRSTFRAG);
4042 #if ACX_FRAGMENTATION
4043 /* SET_BIT(Ctl2_8, DESC_CTL2_MORE_FRAG); cannot set it unconditionally, needs to be set for all non-last fragments */
4044 #endif
4045 hostdesc1->length = cpu_to_le16(WLAN_HDR_A3_LEN);
4048 * Since we're not using autodma copy the packet data to the acx now.
4049 * Even host descriptors point to the packet header, and the odd indexed
4050 * descriptor following points to the packet data.
4052 * The first step is to find free memory in the ACX transmit buffers.
4053 * They don't necessarily map one to one with the transmit queue entries,
4054 * so search through them starting just after the last one used.
4056 addr = allocate_acx_txbuf_space (adev, len);
4057 if (addr) {
4058 chaincopy_to_slavemem (adev, addr, hostdesc1->data, len);
4060 else {
4062 * Bummer. We thought we might have enough room in the transmit
4063 * buffers to send this packet, but it turns out we don't. alloc_tx
4064 * has already marked this transmit descriptor as HOSTOWN and ACXDONE,
4065 * which means the ACX will hang when it gets to this descriptor unless
4066 * we do something about it. Having a bubble in the transmit queue just
4067 * doesn't seem to work, so we have to reset this transmit queue entry's
4068 * state to its original value and back up our head pointer to point
4069 * back to this entry.
4071 hostdesc1->length = 0;
4072 hostdesc2->length = 0;
4073 write_slavemem16 (adev, (u32) &(txdesc->total_length), 0);
4074 write_slavemem8 (adev, (u32) &(txdesc->Ctl_8), DESC_CTL_HOSTOWN | DESC_CTL_FIRSTFRAG);
4075 adev->tx_head = ((u8*) txdesc - (u8*) adev->txdesc_start) / adev->txdesc_size;
4076 goto end;
4079 * Tell the ACX where the packet is.
4081 write_slavemem32 (adev, (u32) &(txdesc->AcxMemPtr), addr);
4084 /* don't need to clean ack/rts statistics here, already
4085 * done on descr cleanup */
4087 /* clears HOSTOWN and ACXDONE bits, thus telling that the descriptors
4088 * are now owned by the acx100; do this as LAST operation */
4089 CLEAR_BIT(Ctl_8, DESC_CTL_ACXDONE_HOSTOWN);
4090 /* flush writes before we release hostdesc to the adapter here */
4091 //wmb();
4093 /* write back modified flags */
4095 * At this point Ctl_8 should just be FIRSTFRAG
4097 write_slavemem8 (adev, (u32) &(txdesc->Ctl2_8),Ctl2_8);
4098 write_slavemem8 (adev, (u32) &(txdesc->Ctl_8), Ctl_8);
4099 /* unused: txdesc->tx_time = cpu_to_le32(jiffies); */
4102 * Update the queue indicator to say there's data on the first queue.
4104 acxmem_update_queue_indicator (adev, 0);
4106 /* flush writes before we tell the adapter that it's its turn now */
4107 mmiowb();
4108 write_reg16(adev, IO_ACX_INT_TRIG, INT_TRIG_TXPRC);
4109 write_flush(adev);
4111 /* log the packet content AFTER sending it,
4112 * in order to not delay sending any further than absolutely needed
4113 * Do separate logs for acx100/111 to have human-readable rates */
4114 if (unlikely(acx_debug & (L_XFER|L_DATA))) {
4115 u16 fc = ((wlan_hdr_t*)hostdesc1->data)->fc;
4116 if (IS_ACX111(adev))
4117 printk("tx: pkt (%s): len %d "
4118 "rate %04X%s status %u\n",
4119 acx_get_packet_type_string(le16_to_cpu(fc)), len,
4120 le16_to_cpu(txdesc->u.r2.rate111),
4121 (le16_to_cpu(txdesc->u.r2.rate111) & RATE111_SHORTPRE) ? "(SPr)" : "",
4122 adev->status);
4123 else
4124 printk("tx: pkt (%s): len %d rate %03u%s status %u\n",
4125 acx_get_packet_type_string(fc), len,
4126 read_slavemem8 (adev, (u32) &(txdesc->u.r1.rate)),
4127 (Ctl_8 & DESC_CTL_SHORT_PREAMBLE) ? "(SPr)" : "",
4128 adev->status);
4130 if (acx_debug & L_DATA) {
4131 printk("tx: 802.11 [%d]: ", len);
4132 acx_dump_bytes(hostdesc1->data, len);
4135 end:
4136 FN_EXIT0;
4140 /***********************************************************************
4141 ** acxmem_l_clean_txdesc
4143 ** This function resets the txdescs' status when the ACX100
4144 ** signals the TX done IRQ (txdescs have been processed), starting with
4145 ** the pool index of the descriptor which we would use next,
4146 ** in order to make sure that we can be as fast as possible
4147 ** in filling new txdescs.
4148 ** Everytime we get called we know where the next packet to be cleaned is.
4151 #if !ACX_DEBUG
4152 static inline void log_txbuffer(const acx_device_t *adev) {}
4153 #else
4154 static void
4155 log_txbuffer(acx_device_t *adev)
4157 txdesc_t *txdesc;
4158 int i;
4159 u8 Ctl_8;
4161 /* no FN_ENTER here, we don't want that */
4162 /* no locks here, since it's entirely non-critical code */
4163 txdesc = adev->txdesc_start;
4164 if (unlikely(!txdesc)) return;
4165 printk("tx: desc->Ctl8's:");
4166 for (i = 0; i < TX_CNT; i++) {
4167 Ctl_8 = read_slavemem8 (adev, (u32) &(txdesc->Ctl_8));
4168 printk(" %02X", Ctl_8);
4169 txdesc = advance_txdesc(adev, txdesc, 1);
4171 printk("\n");
4173 #endif
4176 static void
4177 handle_tx_error(acx_device_t *adev, u8 error, unsigned int finger)
4179 const char *err = "unknown error";
4181 /* hmm, should we handle this as a mask
4182 * of *several* bits?
4183 * For now I think only caring about
4184 * individual bits is ok... */
4185 switch (error) {
4186 case 0x01:
4187 err = "no Tx due to error in other fragment";
4188 adev->wstats.discard.fragment++;
4189 break;
4190 case 0x02:
4191 err = "Tx aborted";
4192 adev->stats.tx_aborted_errors++;
4193 break;
4194 case 0x04:
4195 err = "Tx desc wrong parameters";
4196 adev->wstats.discard.misc++;
4197 break;
4198 case 0x08:
4199 err = "WEP key not found";
4200 adev->wstats.discard.misc++;
4201 break;
4202 case 0x10:
4203 err = "MSDU lifetime timeout? - try changing "
4204 "'iwconfig retry lifetime XXX'";
4205 adev->wstats.discard.misc++;
4206 break;
4207 case 0x20:
4208 err = "excessive Tx retries due to either distance "
4209 "too high or unable to Tx or Tx frame error - "
4210 "try changing 'iwconfig txpower XXX' or "
4211 "'sens'itivity or 'retry'";
4212 adev->wstats.discard.retries++;
4213 /* Tx error 0x20 also seems to occur on
4214 * overheating, so I'm not sure whether we
4215 * actually want to do aggressive radio recalibration,
4216 * since people maybe won't notice then that their hardware
4217 * is slowly getting cooked...
4218 * Or is it still a safe long distance from utter
4219 * radio non-functionality despite many radio recalibs
4220 * to final destructive overheating of the hardware?
4221 * In this case we really should do recalib here...
4222 * I guess the only way to find out is to do a
4223 * potentially fatal self-experiment :-\
4224 * Or maybe only recalib in case we're using Tx
4225 * rate auto (on errors switching to lower speed
4226 * --> less heat?) or 802.11 power save mode?
4228 * ok, just do it. */
4229 if (++adev->retry_errors_msg_ratelimit % 4 == 0) {
4230 if (adev->retry_errors_msg_ratelimit <= 20) {
4231 printk("%s: several excessive Tx "
4232 "retry errors occurred, attempting "
4233 "to recalibrate radio. Radio "
4234 "drift might be caused by increasing "
4235 "card temperature, please check the card "
4236 "before it's too late!\n",
4237 adev->ndev->name);
4238 if (adev->retry_errors_msg_ratelimit == 20)
4239 printk("disabling above message\n");
4242 acx_schedule_task(adev, ACX_AFTER_IRQ_CMD_RADIO_RECALIB);
4244 break;
4245 case 0x40:
4246 err = "Tx buffer overflow";
4247 adev->stats.tx_fifo_errors++;
4248 break;
4249 case 0x80:
4250 err = "DMA error";
4251 adev->wstats.discard.misc++;
4252 break;
4254 adev->stats.tx_errors++;
4255 if (adev->stats.tx_errors <= 20)
4256 printk("%s: tx error 0x%02X, buf %02u! (%s)\n",
4257 adev->ndev->name, error, finger, err);
4258 else
4259 printk("%s: tx error 0x%02X, buf %02u!\n",
4260 adev->ndev->name, error, finger);
4264 unsigned int
4265 acxmem_l_clean_txdesc(acx_device_t *adev)
4267 txdesc_t *txdesc;
4268 int finger;
4269 int num_cleaned;
4270 u16 r111;
4271 u8 error, ack_failures, rts_failures, rts_ok, r100, Ctl_8;
4272 u32 acxmem;
4273 txdesc_t tmptxdesc;
4275 FN_ENTER;
4278 * Set up a template descriptor for re-initialization. The only
4279 * things that get set are Ctl_8 and the rate, and the rate defaults
4280 * to 1Mbps.
4282 memset (&tmptxdesc, 0, sizeof (tmptxdesc));
4283 tmptxdesc.Ctl_8 = DESC_CTL_HOSTOWN | DESC_CTL_FIRSTFRAG;
4284 tmptxdesc.u.r1.rate = 0x0a;
4286 if (unlikely(acx_debug & L_DEBUG))
4287 log_txbuffer(adev);
4289 printk( KERN_NOTICE "tx: cleaning up bufs from %u\n", adev->tx_tail);
4291 /* We know first descr which is not free yet. We advance it as far
4292 ** as we see correct bits set in following descs (if next desc
4293 ** is NOT free, we shouldn't advance at all). We know that in
4294 ** front of tx_tail may be "holes" with isolated free descs.
4295 ** We will catch up when all intermediate descs will be freed also */
4297 finger = adev->tx_tail;
4298 num_cleaned = 0;
4299 while (likely(finger != adev->tx_head)) {
4300 txdesc = get_txdesc(adev, finger);
4302 /* If we allocated txdesc on tx path but then decided
4303 ** to NOT use it, then it will be left as a free "bubble"
4304 ** in the "allocated for tx" part of the ring.
4305 ** We may meet it on the next ring pass here. */
4307 /* stop if not marked as "tx finished" and "host owned" */
4308 Ctl_8 = read_slavemem8 (adev, (u32) &(txdesc->Ctl_8));
4309 if ((Ctl_8 & DESC_CTL_ACXDONE_HOSTOWN)
4310 != DESC_CTL_ACXDONE_HOSTOWN) {
4311 if (unlikely(!num_cleaned)) { /* maybe remove completely */
4312 printk( KERN_NOTICE "clean_txdesc: tail isn't free. "
4313 "tail:%d head:%d\n",
4314 adev->tx_tail, adev->tx_head);
4316 break;
4319 /* remember desc values... */
4320 error = read_slavemem8 (adev, (u32) &(txdesc->error));
4321 ack_failures = read_slavemem8 (adev, (u32) &(txdesc->ack_failures));
4322 rts_failures = read_slavemem8 (adev, (u32) &(txdesc->u.rts.rts_failures));
4323 rts_ok = read_slavemem8 (adev, (u32) &(txdesc->u.rts.rts_ok));
4324 r100 = read_slavemem8 (adev, (u32) &(txdesc->u.r1.rate));
4325 r111 = le16_to_cpu(read_slavemem16 (adev, (u32) &(txdesc->u.r2.rate111)));
4327 /* need to check for certain error conditions before we
4328 * clean the descriptor: we still need valid descr data here */
4329 if (unlikely(0x30 & error)) {
4330 /* only send IWEVTXDROP in case of retry or lifetime exceeded;
4331 * all other errors mean we screwed up locally */
4332 union iwreq_data wrqu;
4333 wlan_hdr_t *hdr;
4334 txhostdesc_t *hostdesc;
4336 hostdesc = get_txhostdesc(adev, txdesc);
4337 hdr = (wlan_hdr_t *)hostdesc->data;
4338 MAC_COPY(wrqu.addr.sa_data, hdr->a1);
4339 wireless_send_event(adev->ndev, IWEVTXDROP, &wrqu, NULL);
4343 * Free up the transmit data buffers
4345 acxmem = read_slavemem32 (adev, (u32) &(txdesc->AcxMemPtr));
4346 if (acxmem) {
4347 reclaim_acx_txbuf_space (adev, acxmem);
4350 /* ...and free the desc by clearing all the fields
4351 except the next pointer */
4352 copy_to_slavemem (adev,
4353 (u32) &(txdesc->HostMemPtr),
4354 (u8 *) &(tmptxdesc.HostMemPtr),
4355 sizeof (tmptxdesc) - sizeof(tmptxdesc.pNextDesc)
4358 adev->tx_free++;
4359 num_cleaned++;
4361 if ((adev->tx_free >= TX_START_QUEUE)
4362 && (adev->status == ACX_STATUS_4_ASSOCIATED)
4363 && (acx_queue_stopped(adev->ndev))
4365 log(L_BUF, "tx: wake queue (avail. Tx desc %u)\n",
4366 adev->tx_free);
4367 acx_wake_queue(adev->ndev, NULL);
4370 /* do error checking, rate handling and logging
4371 * AFTER having done the work, it's faster */
4373 /* do rate handling */
4374 if (adev->rate_auto) {
4375 struct client *clt = get_txc(adev, txdesc);
4376 if (clt) {
4377 u16 cur = get_txr(adev, txdesc);
4378 if (clt->rate_cur == cur) {
4379 acx_l_handle_txrate_auto(adev, clt,
4380 cur, /* intended rate */
4381 r100, r111, /* actually used rate */
4382 (error & 0x30), /* was there an error? */
4383 TX_CNT + TX_CLEAN_BACKLOG - adev->tx_free);
4388 if (unlikely(error))
4389 handle_tx_error(adev, error, finger);
4391 if (IS_ACX111(adev))
4392 printk( KERN_NOTICE "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u r111=%04X\n",
4393 finger, ack_failures, rts_failures, rts_ok, r111);
4394 else
4395 printk( KERN_NOTICE "tx: cleaned %u: !ACK=%u !RTS=%u RTS=%u rate=%u\n",
4396 finger, ack_failures, rts_failures, rts_ok, r100);
4398 /* update pointer for descr to be cleaned next */
4399 finger = (finger + 1) % TX_CNT;
4402 /* remember last position */
4403 adev->tx_tail = finger;
4404 /* end: */
4405 FN_EXIT1(num_cleaned);
4406 return num_cleaned;
4409 /* clean *all* Tx descriptors, and regardless of their previous state.
4410 * Used for brute-force reset handling. */
4411 void
4412 acxmem_l_clean_txdesc_emergency(acx_device_t *adev)
4414 txdesc_t *txdesc;
4415 int i;
4417 FN_ENTER;
4419 for (i = 0; i < TX_CNT; i++) {
4420 txdesc = get_txdesc(adev, i);
4422 /* free it */
4423 write_slavemem8 (adev, (u32) &(txdesc->ack_failures), 0);
4424 write_slavemem8 (adev, (u32) &(txdesc->u.rts.rts_failures), 0);
4425 write_slavemem8 (adev, (u32) &(txdesc->u.rts.rts_ok), 0);
4426 write_slavemem8 (adev, (u32) &(txdesc->error), 0);
4427 write_slavemem8 (adev, (u32) &(txdesc->Ctl_8), DESC_CTL_HOSTOWN);
4430 adev->tx_free = TX_CNT;
4432 FN_EXIT0;
4436 /***********************************************************************
4437 ** acxmem_s_create_tx_host_desc_queue
4440 static void*
4441 allocate(acx_device_t *adev, size_t size, dma_addr_t *phy, const char *msg)
4443 void *ptr;
4444 ptr = kmalloc (size, GFP_KERNEL);
4446 * The ACX can't use the physical address, so we'll have to fake it
4447 * later and it might be handy to have the virtual address.
4449 *phy = (dma_addr_t) NULL;
4451 if (ptr) {
4452 log(L_DEBUG, "%s sz=%d adr=0x%p phy=0x%08llx\n",
4453 msg, (int)size, ptr, (unsigned long long)*phy);
4454 memset(ptr, 0, size);
4455 return ptr;
4457 printk(KERN_ERR "acx: %s allocation FAILED (%d bytes)\n",
4458 msg, (int)size);
4459 return NULL;
4464 * In the generic slave memory access mode, most of the stuff in
4465 * the txhostdesc_t is unused. It's only here because the rest of
4466 * the ACX driver expects it to be since the PCI version uses indirect
4467 * host memory organization with DMA. Since we're not using DMA the
4468 * only use we have for the host descriptors is to store the packets
4469 * on the way out.
4471 static int
4472 acxmem_s_create_tx_host_desc_queue(acx_device_t *adev)
4474 txhostdesc_t *hostdesc;
4475 u8 *txbuf;
4476 int i;
4478 FN_ENTER;
4480 /* allocate TX buffer */
4481 adev->txbuf_area_size = TX_CNT * WLAN_A4FR_MAXLEN_WEP_FCS;
4482 adev->txbuf_start = allocate(adev, adev->txbuf_area_size,
4483 &adev->txbuf_startphy, "txbuf_start");
4484 if (!adev->txbuf_start)
4485 goto fail;
4487 /* allocate the TX host descriptor queue pool */
4488 adev->txhostdesc_area_size = TX_CNT * 2*sizeof(*hostdesc);
4489 adev->txhostdesc_start = allocate(adev, adev->txhostdesc_area_size,
4490 &adev->txhostdesc_startphy, "txhostdesc_start");
4491 if (!adev->txhostdesc_start)
4492 goto fail;
4493 /* check for proper alignment of TX host descriptor pool */
4494 if ((long) adev->txhostdesc_start & 3) {
4495 printk("acx: driver bug: dma alloc returns unaligned address\n");
4496 goto fail;
4499 hostdesc = adev->txhostdesc_start;
4500 txbuf = adev->txbuf_start;
4502 #if 0
4503 /* Each tx buffer is accessed by hardware via
4504 ** txdesc -> txhostdesc(s) -> txbuffer(s).
4505 ** We use only one txhostdesc per txdesc, but it looks like
4506 ** acx111 is buggy: it accesses second txhostdesc
4507 ** (via hostdesc.desc_phy_next field) even if
4508 ** txdesc->length == hostdesc->length and thus
4509 ** entire packet was placed into first txhostdesc.
4510 ** Due to this bug acx111 hangs unless second txhostdesc
4511 ** has le16_to_cpu(hostdesc.length) = 3 (or larger)
4512 ** Storing NULL into hostdesc.desc_phy_next
4513 ** doesn't seem to help.
4515 ** Update: although it worked on Xterasys XN-2522g
4516 ** with len=3 trick, WG311v2 is even more bogus, doesn't work.
4517 ** Keeping this code (#ifdef'ed out) for documentational purposes.
4519 for (i = 0; i < TX_CNT*2; i++) {
4520 hostdesc_phy += sizeof(*hostdesc);
4521 if (!(i & 1)) {
4522 hostdesc->data_phy = cpu2acx(txbuf_phy);
4523 /* hostdesc->data_offset = ... */
4524 /* hostdesc->reserved = ... */
4525 hostdesc->Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
4526 /* hostdesc->length = ... */
4527 hostdesc->desc_phy_next = cpu2acx(hostdesc_phy);
4528 hostdesc->pNext = ptr2acx(NULL);
4529 /* hostdesc->Status = ... */
4530 /* below: non-hardware fields */
4531 hostdesc->data = txbuf;
4533 txbuf += WLAN_A4FR_MAXLEN_WEP_FCS;
4534 txbuf_phy += WLAN_A4FR_MAXLEN_WEP_FCS;
4535 } else {
4536 /* hostdesc->data_phy = ... */
4537 /* hostdesc->data_offset = ... */
4538 /* hostdesc->reserved = ... */
4539 /* hostdesc->Ctl_16 = ... */
4540 hostdesc->length = cpu_to_le16(3); /* bug workaround */
4541 /* hostdesc->desc_phy_next = ... */
4542 /* hostdesc->pNext = ... */
4543 /* hostdesc->Status = ... */
4544 /* below: non-hardware fields */
4545 /* hostdesc->data = ... */
4547 hostdesc++;
4549 #endif
4550 /* We initialize two hostdescs so that they point to adjacent
4551 ** memory areas. Thus txbuf is really just a contiguous memory area */
4552 for (i = 0; i < TX_CNT*2; i++) {
4553 /* ->data is a non-hardware field: */
4554 hostdesc->data = txbuf;
4556 if (!(i & 1)) {
4557 txbuf += WLAN_HDR_A3_LEN;
4558 } else {
4559 txbuf += WLAN_A4FR_MAXLEN_WEP_FCS - WLAN_HDR_A3_LEN;
4561 hostdesc++;
4563 hostdesc--;
4565 FN_EXIT1(OK);
4566 return OK;
4567 fail:
4568 printk("acx: create_tx_host_desc_queue FAILED\n");
4569 /* dealloc will be done by free function on error case */
4570 FN_EXIT1(NOT_OK);
4571 return NOT_OK;
4575 /***************************************************************
4576 ** acxmem_s_create_rx_host_desc_queue
4578 /* the whole size of a data buffer (header plus data body)
4579 * plus 32 bytes safety offset at the end */
4580 #define RX_BUFFER_SIZE (sizeof(rxbuffer_t) + 32)
4582 static int
4583 acxmem_s_create_rx_host_desc_queue(acx_device_t *adev)
4585 rxhostdesc_t *hostdesc;
4586 rxbuffer_t *rxbuf;
4587 int i;
4589 FN_ENTER;
4591 /* allocate the RX host descriptor queue pool */
4592 adev->rxhostdesc_area_size = RX_CNT * sizeof(*hostdesc);
4593 adev->rxhostdesc_start = allocate(adev, adev->rxhostdesc_area_size,
4594 &adev->rxhostdesc_startphy, "rxhostdesc_start");
4595 if (!adev->rxhostdesc_start)
4596 goto fail;
4597 /* check for proper alignment of RX host descriptor pool */
4598 if ((long) adev->rxhostdesc_start & 3) {
4599 printk("acx: driver bug: dma alloc returns unaligned address\n");
4600 goto fail;
4603 /* allocate Rx buffer pool which will be used by the acx
4604 * to store the whole content of the received frames in it */
4605 adev->rxbuf_area_size = RX_CNT * RX_BUFFER_SIZE;
4606 adev->rxbuf_start = allocate(adev, adev->rxbuf_area_size,
4607 &adev->rxbuf_startphy, "rxbuf_start");
4608 if (!adev->rxbuf_start)
4609 goto fail;
4611 rxbuf = adev->rxbuf_start;
4612 hostdesc = adev->rxhostdesc_start;
4614 /* don't make any popular C programming pointer arithmetic mistakes
4615 * here, otherwise I'll kill you...
4616 * (and don't dare asking me why I'm warning you about that...) */
4617 for (i = 0; i < RX_CNT; i++) {
4618 hostdesc->data = rxbuf;
4619 hostdesc->length = cpu_to_le16(RX_BUFFER_SIZE);
4620 rxbuf++;
4621 hostdesc++;
4623 hostdesc--;
4624 FN_EXIT1(OK);
4625 return OK;
4626 fail:
4627 printk("acx: create_rx_host_desc_queue FAILED\n");
4628 /* dealloc will be done by free function on error case */
4629 FN_EXIT1(NOT_OK);
4630 return NOT_OK;
4634 /***************************************************************
4635 ** acxmem_s_create_hostdesc_queues
4638 acxmem_s_create_hostdesc_queues(acx_device_t *adev)
4640 int result;
4641 result = acxmem_s_create_tx_host_desc_queue(adev);
4642 if (OK != result) return result;
4643 result = acxmem_s_create_rx_host_desc_queue(adev);
4644 return result;
4648 /***************************************************************
4649 ** acxmem_create_tx_desc_queue
4651 static void
4652 acxmem_create_tx_desc_queue(acx_device_t *adev, u32 tx_queue_start)
4654 txdesc_t *txdesc;
4655 u32 clr;
4656 int i;
4658 FN_ENTER;
4660 if (IS_ACX100(adev))
4661 adev->txdesc_size = sizeof(*txdesc);
4662 else
4663 /* the acx111 txdesc is 4 bytes larger */
4664 adev->txdesc_size = sizeof(*txdesc) + 4;
4667 * This refers to an ACX address, not one of ours
4669 adev->txdesc_start = (txdesc_t *) tx_queue_start;
4671 log(L_DEBUG, "adev->txdesc_start=%p\n",
4672 adev->txdesc_start);
4674 adev->tx_free = TX_CNT;
4675 /* done by memset: adev->tx_head = 0; */
4676 /* done by memset: adev->tx_tail = 0; */
4677 txdesc = adev->txdesc_start;
4679 if (IS_ACX111(adev)) {
4680 /* ACX111 has a preinitialized Tx buffer! */
4681 /* loop over whole send pool */
4682 /* FIXME: do we have to do the hostmemptr stuff here?? */
4683 for (i = 0; i < TX_CNT; i++) {
4684 txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
4685 /* reserve two (hdr desc and payload desc) */
4686 txdesc = advance_txdesc(adev, txdesc, 1);
4688 } else {
4689 /* ACX100 Tx buffer needs to be initialized by us */
4690 /* clear whole send pool. sizeof is safe here (we are acx100) */
4693 * adev->txdesc_start refers to device memory, so we can't write
4694 * directly to it.
4696 clr = (u32) adev->txdesc_start;
4697 while (clr < (u32) adev->txdesc_start + (TX_CNT * sizeof(*txdesc))) {
4698 write_slavemem32 (adev, clr, 0);
4699 clr += 4;
4702 /* loop over whole send pool */
4703 for (i = 0; i < TX_CNT; i++) {
4704 log(L_DEBUG, "configure card tx descriptor: 0x%p, "
4705 "size: 0x%X\n", txdesc, adev->txdesc_size);
4707 /* initialise ctl */
4709 * No auto DMA here
4711 write_slavemem8 (adev, (u32) &(txdesc->Ctl_8),
4712 (u8) (DESC_CTL_HOSTOWN | DESC_CTL_FIRSTFRAG));
4713 /* done by memset(0): txdesc->Ctl2_8 = 0; */
4715 /* point to next txdesc */
4716 write_slavemem32 (adev, (u32) &(txdesc->pNextDesc),
4717 (u32) cpu_to_le32 ((u8 *) txdesc + adev->txdesc_size));
4719 /* go to the next one */
4720 /* ++ is safe here (we are acx100) */
4721 txdesc++;
4723 /* go back to the last one */
4724 txdesc--;
4725 /* and point to the first making it a ring buffer */
4726 write_slavemem32 (adev, (u32) &(txdesc->pNextDesc),
4727 (u32) cpu_to_le32 (tx_queue_start));
4729 FN_EXIT0;
4733 /***************************************************************
4734 ** acxmem_create_rx_desc_queue
4736 static void
4737 acxmem_create_rx_desc_queue(acx_device_t *adev, u32 rx_queue_start)
4739 rxdesc_t *rxdesc;
4740 u32 mem_offs;
4741 int i;
4743 FN_ENTER;
4745 /* done by memset: adev->rx_tail = 0; */
4747 /* ACX111 doesn't need any further config: preconfigures itself.
4748 * Simply print ring buffer for debugging */
4749 if (IS_ACX111(adev)) {
4750 /* rxdesc_start already set here */
4752 adev->rxdesc_start = (rxdesc_t *) rx_queue_start;
4754 rxdesc = adev->rxdesc_start;
4755 for (i = 0; i < RX_CNT; i++) {
4756 log(L_DEBUG, "rx descriptor %d @ 0x%p\n", i, rxdesc);
4757 rxdesc = adev->rxdesc_start = (rxdesc_t *)
4758 acx2cpu(rxdesc->pNextDesc);
4760 } else {
4761 /* we didn't pre-calculate rxdesc_start in case of ACX100 */
4762 /* rxdesc_start should be right AFTER Tx pool */
4763 adev->rxdesc_start = (rxdesc_t *)
4764 ((u8 *) adev->txdesc_start + (TX_CNT * sizeof(txdesc_t)));
4765 /* NB: sizeof(txdesc_t) above is valid because we know
4766 ** we are in if (acx100) block. Beware of cut-n-pasting elsewhere!
4767 ** acx111's txdesc is larger! */
4769 mem_offs = (u32) adev->rxdesc_start;
4770 while (mem_offs < (u32) adev->rxdesc_start + (RX_CNT * sizeof (*rxdesc))) {
4771 write_slavemem32 (adev, mem_offs, 0);
4772 mem_offs += 4;
4775 /* loop over whole receive pool */
4776 rxdesc = adev->rxdesc_start;
4777 for (i = 0; i < RX_CNT; i++) {
4778 log(L_DEBUG, "rx descriptor @ 0x%p\n", rxdesc);
4779 /* point to next rxdesc */
4780 write_slavemem32 (adev, (u32) &(rxdesc->pNextDesc),
4781 (u32) cpu_to_le32 ((u8 *) rxdesc + sizeof(*rxdesc)));
4782 /* go to the next one */
4783 rxdesc++;
4785 /* go to the last one */
4786 rxdesc--;
4788 /* and point to the first making it a ring buffer */
4789 write_slavemem32 (adev, (u32) &(rxdesc->pNextDesc),
4790 (u32) cpu_to_le32 (rx_queue_start));
4792 FN_EXIT0;
4796 /***************************************************************
4797 ** acxmem_create_desc_queues
4799 void
4800 acxmem_create_desc_queues(acx_device_t *adev, u32 tx_queue_start, u32 rx_queue_start)
4802 u32 *p;
4803 int i;
4805 acxmem_create_tx_desc_queue(adev, tx_queue_start);
4806 acxmem_create_rx_desc_queue(adev, rx_queue_start);
4807 p = (u32 *) adev->acx_queue_indicator;
4808 for (i = 0; i < 4; i++) {
4809 write_slavemem32 (adev, (u32) p, 0);
4810 p++;
4815 /***************************************************************
4816 ** acxmem_s_proc_diag_output
4818 char*
4819 acxmem_s_proc_diag_output(char *p, acx_device_t *adev)
4821 const char *rtl, *thd, *ttl;
4822 txdesc_t *txdesc;
4823 u8 Ctl_8;
4824 rxdesc_t *rxdesc;
4825 int i;
4826 u32 tmp;
4828 FN_ENTER;
4830 #if DUMP_MEM_DURING_DIAG > 0
4831 dump_acxmem (adev, 0, 0x10000);
4832 panic ("dump finished");
4833 #endif
4835 p += sprintf(p, "** Rx buf **\n");
4836 rxdesc = adev->rxdesc_start;
4837 if (rxdesc) for (i = 0; i < RX_CNT; i++) {
4838 rtl = (i == adev->rx_tail) ? " [tail]" : "";
4839 Ctl_8 = read_slavemem8 (adev, (u32) &(rxdesc->Ctl_8));
4840 if (Ctl_8 & DESC_CTL_HOSTOWN)
4841 p += sprintf(p, "%02u (%02x) FULL%s\n", i, Ctl_8, rtl);
4842 else
4843 p += sprintf(p, "%02u (%02x) empty%s\n", i, Ctl_8, rtl);
4844 rxdesc++;
4846 p += sprintf(p, "** Tx buf (free %d, Linux netqueue %s) **\n", adev->tx_free,
4847 acx_queue_stopped(adev->ndev) ? "STOPPED" : "running");
4849 p += sprintf(p, "** Tx buf %d blocks total, %d available, free list head %04x\n",
4850 adev->acx_txbuf_numblocks, adev->acx_txbuf_blocks_free, adev->acx_txbuf_free);
4851 txdesc = adev->txdesc_start;
4852 if (txdesc) for (i = 0; i < TX_CNT; i++) {
4853 thd = (i == adev->tx_head) ? " [head]" : "";
4854 ttl = (i == adev->tx_tail) ? " [tail]" : "";
4855 Ctl_8 = read_slavemem8 (adev, (u32) &(txdesc->Ctl_8));
4856 if (Ctl_8 & DESC_CTL_ACXDONE)
4857 p += sprintf(p, "%02u ready to free (%02X)%s%s", i, Ctl_8, thd, ttl);
4858 else if (Ctl_8 & DESC_CTL_HOSTOWN)
4859 p += sprintf(p, "%02u available (%02X)%s%s", i, Ctl_8, thd, ttl);
4860 else
4861 p += sprintf(p, "%02u busy (%02X)%s%s", i, Ctl_8, thd, ttl);
4862 tmp = read_slavemem32 (adev, (u32) &(txdesc->AcxMemPtr));
4863 if (tmp) {
4864 p += sprintf (p, " %04x", tmp);
4865 while ((tmp = read_slavemem32 (adev, (u32) tmp)) != 0x02000000) {
4866 tmp <<= 5;
4867 p += sprintf (p, " %04x", tmp);
4870 p += sprintf (p, "\n");
4871 txdesc = advance_txdesc(adev, txdesc, 1);
4874 p += sprintf(p,
4875 "\n"
4876 "** Generic slave data **\n"
4877 "irq_mask %04x irq_status %04x irq on acx %04x\n"
4878 "txbuf_start %p, txbuf_area_size %u\n"
4879 "txdesc_size %u, txdesc_start %p\n"
4880 "txhostdesc_start %p, txhostdesc_area_size %u\n"
4881 "txbuf start %04x, txbuf size %d\n"
4882 "rxdesc_start %p\n"
4883 "rxhostdesc_start %p, rxhostdesc_area_size %u\n"
4884 "rxbuf_start %p, rxbuf_area_size %u\n",
4885 adev->irq_mask, adev->irq_status, read_reg32(adev, IO_ACX_IRQ_STATUS_NON_DES),
4886 adev->txbuf_start, adev->txbuf_area_size,
4887 adev->txdesc_size, adev->txdesc_start,
4888 adev->txhostdesc_start, adev->txhostdesc_area_size,
4889 adev->acx_txbuf_start, adev->acx_txbuf_numblocks * adev->memblocksize,
4890 adev->rxdesc_start,
4891 adev->rxhostdesc_start, adev->rxhostdesc_area_size,
4892 adev->rxbuf_start, adev->rxbuf_area_size);
4893 FN_EXIT0;
4894 return p;
4898 /***********************************************************************
4901 acxmem_proc_eeprom_output(char *buf, acx_device_t *adev)
4903 char *p = buf;
4904 int i;
4906 FN_ENTER;
4908 for (i = 0; i < 0x400; i++) {
4909 acxmem_read_eeprom_byte(adev, i, p++);
4912 FN_EXIT1(p - buf);
4913 return p - buf;
4917 /***********************************************************************
4919 void
4920 acxmem_set_interrupt_mask(acx_device_t *adev)
4922 if (IS_ACX111(adev)) {
4923 adev->irq_mask = (u16) ~(0
4924 | HOST_INT_RX_DATA
4925 | HOST_INT_TX_COMPLETE
4926 /* | HOST_INT_TX_XFER */
4927 /* | HOST_INT_RX_COMPLETE */
4928 /* | HOST_INT_DTIM */
4929 /* | HOST_INT_BEACON */
4930 /* | HOST_INT_TIMER */
4931 /* | HOST_INT_KEY_NOT_FOUND */
4932 | HOST_INT_IV_ICV_FAILURE
4933 | HOST_INT_CMD_COMPLETE
4934 | HOST_INT_INFO
4935 | HOST_INT_OVERFLOW
4936 /* | HOST_INT_PROCESS_ERROR */
4937 | HOST_INT_SCAN_COMPLETE
4938 | HOST_INT_FCS_THRESHOLD
4939 | HOST_INT_BEACON_MISSED
4941 /* Or else acx100 won't signal cmd completion, right? */
4942 adev->irq_mask_off = (u16)~( HOST_INT_CMD_COMPLETE ); /* 0xfdff */
4943 } else {
4944 adev->irq_mask = (u16) ~(0
4945 | HOST_INT_RX_DATA
4946 | HOST_INT_TX_COMPLETE
4947 /* | HOST_INT_TX_XFER */
4948 /* | HOST_INT_RX_COMPLETE */
4949 /* | HOST_INT_DTIM */
4950 /* | HOST_INT_BEACON */
4951 /* | HOST_INT_TIMER */
4952 /* | HOST_INT_KEY_NOT_FOUND */
4953 /* | HOST_INT_IV_ICV_FAILURE */
4954 | HOST_INT_CMD_COMPLETE
4955 | HOST_INT_INFO
4956 /* | HOST_INT_OVERFLOW */
4957 /* | HOST_INT_PROCESS_ERROR */
4958 | HOST_INT_SCAN_COMPLETE
4959 /* | HOST_INT_FCS_THRESHOLD */
4960 /* | HOST_INT_BEACON_MISSED */
4962 adev->irq_mask_off = (u16)~( HOST_INT_BEACON_MISSED ); /* 0x7fff */
4967 /***********************************************************************
4970 acx100mem_s_set_tx_level(acx_device_t *adev, u8 level_dbm)
4972 struct acx111_ie_tx_level tx_level;
4974 /* since it can be assumed that at least the Maxim radio has a
4975 * maximum power output of 20dBm and since it also can be
4976 * assumed that these values drive the DAC responsible for
4977 * setting the linear Tx level, I'd guess that these values
4978 * should be the corresponding linear values for a dBm value,
4979 * in other words: calculate the values from that formula:
4980 * Y [dBm] = 10 * log (X [mW])
4981 * then scale the 0..63 value range onto the 1..100mW range (0..20 dBm)
4982 * and you're done...
4983 * Hopefully that's ok, but you never know if we're actually
4984 * right... (especially since Windows XP doesn't seem to show
4985 * actual Tx dBm values :-P) */
4987 /* NOTE: on Maxim, value 30 IS 30mW, and value 10 IS 10mW - so the
4988 * values are EXACTLY mW!!! Not sure about RFMD and others,
4989 * though... */
4990 static const u8 dbm2val_maxim[21] = {
4991 63, 63, 63, 62,
4992 61, 61, 60, 60,
4993 59, 58, 57, 55,
4994 53, 50, 47, 43,
4995 38, 31, 23, 13,
4998 static const u8 dbm2val_rfmd[21] = {
4999 0, 0, 0, 1,
5000 2, 2, 3, 3,
5001 4, 5, 6, 8,
5002 10, 13, 16, 20,
5003 25, 32, 41, 50,
5006 const u8 *table;
5008 switch (adev->radio_type) {
5009 case RADIO_MAXIM_0D:
5010 table = &dbm2val_maxim[0];
5011 break;
5012 case RADIO_RFMD_11:
5013 case RADIO_RALINK_15:
5014 table = &dbm2val_rfmd[0];
5015 break;
5016 default:
5017 printk("%s: unknown/unsupported radio type, "
5018 "cannot modify tx power level yet!\n",
5019 adev->ndev->name);
5020 return NOT_OK;
5023 * The hx4700 EEPROM, at least, only supports 1 power setting. The configure
5024 * routine matches the PA bias with the gain, so just use its default value.
5025 * The values are: 0x2b for the gain and 0x03 for the PA bias. The firmware
5026 * writes the gain level to the Tx gain control DAC and the PA bias to the Maxim
5027 * radio's PA bias register. The firmware limits itself to 0 - 64 when writing to the
5028 * gain control DAC.
5030 * Physically between the ACX and the radio, higher Tx gain control DAC values result
5031 * in less power output; 0 volts to the Maxim radio results in the highest output power
5032 * level, which I'm assuming matches up with 0 in the Tx Gain DAC register.
5034 * Although there is only the 1 power setting, one of the radio firmware functions adjusts
5035 * the transmit power level up and down. That function is called by the ACX FIQ handler
5036 * under certain conditions.
5038 tx_level.level = 1;
5039 //return acx_s_configure(adev, &tx_level, ACX1xx_IE_DOT11_TX_POWER_LEVEL);
5041 printk("%s: changing radio power level to %u dBm (%u)\n",
5042 adev->ndev->name, level_dbm, table[level_dbm]);
5043 acxmem_s_write_phy_reg(adev, 0x11, table[level_dbm]);
5045 return 0;
5049 static struct device_driver
5050 acxmem_drv_id = {
5051 .name = "acx-mem",
5052 .bus = &platform_bus_type,
5053 .probe = acxmem_e_probe,
5054 .remove = __devexit_p(acxmem_e_remove),
5055 #ifdef CONFIG_PM
5056 .suspend = acxmem_e_suspend,
5057 .resume = acxmem_e_resume
5058 #endif /* CONFIG_PM */
5062 /***********************************************************************
5063 ** acxmem_e_init_module
5065 ** Module initialization routine, called once at module load time
5067 int __init
5068 acxmem_e_init_module(void)
5070 int res;
5072 FN_ENTER;
5074 #if (ACX_IO_WIDTH==32)
5075 printk("acx: compiled to use 32bit I/O access. "
5076 "I/O timing issues might occur, such as "
5077 "non-working firmware upload. Report them\n");
5078 #else
5079 printk("acx: compiled to use 16bit I/O access only "
5080 "(compatibility mode)\n");
5081 #endif
5083 #ifdef __LITTLE_ENDIAN
5084 #define ENDIANNESS_STRING "running on a little-endian CPU\n"
5085 #else
5086 #define ENDIANNESS_STRING "running on a BIG-ENDIAN CPU\n"
5087 #endif
5088 log(L_INIT,
5089 ENDIANNESS_STRING
5090 "PCI module " ACX_RELEASE " initialized, "
5091 "waiting for cards to probe...\n"
5094 res = driver_register (&acxmem_drv_id);
5095 FN_EXIT1(res);
5096 return res;
5100 /***********************************************************************
5101 ** acxmem_e_cleanup_module
5103 ** Called at module unload time. This is our last chance to
5104 ** clean up after ourselves.
5106 void __exit
5107 acxmem_e_cleanup_module(void)
5109 struct net_device *ndev;
5110 unsigned long flags;
5112 FN_ENTER;
5113 printk ("cleanup_module\n");
5114 /* Since the whole module is about to be unloaded,
5115 * we recursively shutdown all cards we handled instead
5116 * of doing it in acxmem_e_remove() (which will be activated by us
5117 * via pci_unregister_driver at the end).
5118 * acxmem_e_remove() might just get called after a card eject,
5119 * that's why hardware operations have to be done here instead
5120 * when the hardware is available. */
5122 down(&root_adev_sem);
5124 ndev = root_adev_newest;
5125 while (ndev) {
5126 acx_device_t *adev = ndev2adev(ndev);
5127 struct acx_hardware_data *hwdata = adev->dev->platform_data;
5129 acx_sem_lock(adev);
5131 /* disable both Tx and Rx to shut radio down properly */
5132 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_TX, NULL, 0);
5133 acx_s_issue_cmd(adev, ACX1xx_CMD_DISABLE_RX, NULL, 0);
5135 #ifdef REDUNDANT
5136 /* put the eCPU to sleep to save power
5137 * Halting is not possible currently,
5138 * since not supported by all firmware versions */
5139 acx_s_issue_cmd(adev, ACX100_CMD_SLEEP, NULL, 0);
5140 #endif
5141 acx_lock(adev, flags);
5143 /* disable power LED to save power :-) */
5144 log(L_INIT, "switching off power LED to save power\n");
5145 acxmem_l_power_led(adev, 0);
5147 /* stop our eCPU */
5148 if (IS_ACX111(adev)) {
5149 /* FIXME: does this actually keep halting the eCPU?
5150 * I don't think so...
5152 acxmem_l_reset_mac(adev);
5153 } else {
5154 u16 temp;
5156 /* halt eCPU */
5157 temp = read_reg16(adev, IO_ACX_ECPU_CTRL) | 0x1;
5158 write_reg16(adev, IO_ACX_ECPU_CTRL, temp);
5159 write_flush(adev);
5162 (void) hwdata->stop_hw();
5164 acx_unlock(adev, flags);
5166 acx_sem_unlock(adev);
5169 up(&root_adev_sem);
5171 driver_unregister( &acxmem_drv_id );
5173 FN_EXIT0;
5176 void acxmem_e_release(struct device *dev) {
5179 MODULE_AUTHOR( "Todd Blumer <todd@sdgsystems.com>" );
5180 MODULE_DESCRIPTION( "ACX Slave Memory Driver" );
5181 MODULE_LICENSE( "GPL" );