1 /***********************************************************************
2 ** Copyright (C) 2003 ACX100 Open Source Project
4 ** The contents of this file are subject to the Mozilla Public
5 ** License Version 1.1 (the "License"); you may not use this file
6 ** except in compliance with the License. You may obtain a copy of
7 ** the License at http://www.mozilla.org/MPL/
9 ** Software distributed under the License is distributed on an "AS
10 ** IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11 ** implied. See the License for the specific language governing
12 ** rights and limitations under the License.
14 ** Alternatively, the contents of this file may be used under the
15 ** terms of the GNU Public License version 2 (the "GPL"), in which
16 ** case the provisions of the GPL are applicable instead of the
17 ** above. If you wish to allow the use of your version of this file
18 ** only under the terms of the GPL and not to allow others to use
19 ** your version of this file under the MPL, indicate your decision
20 ** by deleting the provisions above and replace them with the notice
21 ** and other provisions required by the GPL. If you do not delete
22 ** the provisions above, a recipient may use your version of this
23 ** file under either the MPL or the GPL.
24 ** ---------------------------------------------------------------------
25 ** Inquiries regarding the ACX100 Open Source Project can be
28 ** acx100-users@lists.sf.net
29 ** http://acx100.sf.net
30 ** ---------------------------------------------------------------------
32 ** Slave memory interface support:
34 ** Todd Blumer - SDG Systems
36 ** Eric McCorkle - Shadowsun
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>
70 #include <linux/vmalloc.h>
71 #include <linux/delay.h>
72 #include <linux/workqueue.h>
73 #include <linux/utsrelease.h>
78 /***********************************************************************
81 #define CARD_EEPROM_ID_SIZE 6
85 #define REG_ACX_VENDOR_ID 0x900
87 * This is the vendor id on the HX4700, anyway
89 #define ACX_VENDOR_ID 0x8400104c
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 /***********************************************************************
122 /* #define INLINE_IO static */
123 #define INLINE_IO static inline
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
]);
133 read_reg32(acx_device_t
*adev
, unsigned int offset
)
138 if (offset
> IO_ACX_ECPU_CTRL
)
141 addr
= adev
->io
[offset
];
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
] );
154 read_reg16(acx_device_t
*adev
, unsigned int offset
)
159 if (offset
> IO_ACX_ECPU_CTRL
)
162 addr
= adev
->io
[offset
];
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
] );
175 read_reg8(acx_device_t
*adev
, unsigned int offset
)
180 if (offset
> IO_ACX_ECPU_CTRL
)
183 addr
= adev
->io
[offset
];
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
] );
195 write_reg32(acx_device_t
*adev
, unsigned int offset
, u32 val
)
199 if (offset
> IO_ACX_ECPU_CTRL
)
202 addr
= adev
->io
[offset
];
205 writel(val
, ((u8
*)adev
->iobase
) + addr
);
209 writel( addr
, &adev
->iobase
[ACX_SLV_REG_ADDR
] );
210 writel( val
, &adev
->iobase
[ACX_SLV_REG_DATA
] );
214 write_reg16(acx_device_t
*adev
, unsigned int offset
, u16 val
)
218 if (offset
> IO_ACX_ECPU_CTRL
)
221 addr
= adev
->io
[offset
];
224 writew(val
, ((u8
*)adev
->iobase
) + addr
);
227 writel( addr
, &adev
->iobase
[ACX_SLV_REG_ADDR
] );
228 writew( val
, (u16
*) &adev
->iobase
[ACX_SLV_REG_DATA
] );
232 write_reg8(acx_device_t
*adev
, unsigned int offset
, u8 val
)
236 if (offset
> IO_ACX_ECPU_CTRL
)
239 addr
= adev
->io
[offset
];
242 writeb(val
, ((u8
*) adev
->iobase
) + addr
);
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. */
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
);
264 set_regbits (acx_device_t
*adev
, unsigned int offset
, u32 bits
) {
267 tmp
= read_reg32 (adev
, offset
);
269 write_reg32 (adev
, offset
, tmp
);
274 clear_regbits (acx_device_t
*adev
, unsigned int offset
, u32 bits
) {
277 tmp
= read_reg32 (adev
, offset
);
279 write_reg32 (adev
, offset
, tmp
);
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.
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
);
293 write_reg32 (adev
, IO_ACX_SLV_MEM_DATA
, val
);
297 read_slavemem32 (acx_device_t
*adev
, u32 slave_address
)
301 write_reg32 (adev
, IO_ACX_SLV_MEM_CTL
, 0x0);
302 write_reg32 (adev
, IO_ACX_SLV_MEM_ADDR
, slave_address
);
304 val
= read_reg32 (adev
, IO_ACX_SLV_MEM_DATA
);
310 write_slavemem8 (acx_device_t
*adev
, u32 slave_address
, u8 val
)
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
);
329 read_slavemem8 (acx_device_t
*adev
, u32 slave_address
)
336 base
= slave_address
& ~3;
337 offset
= (slave_address
& 3) * 8;
339 data
= read_slavemem32 (adev
, base
);
341 val
= (data
>> offset
) & 0xff;
347 * doesn't split across word boundaries
350 write_slavemem16 (acx_device_t
*adev
, u32 slave_address
, u16 val
)
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
372 read_slavemem16 (acx_device_t
*adev
, u32 slave_address
)
379 base
= slave_address
& ~3;
380 offset
= (slave_address
& 3) * 8;
382 data
= read_slavemem32 (adev
, base
);
384 val
= (data
>> offset
) & 0xffff;
390 * Copy from slave memory
392 * TODO - rewrite using address autoincrement, handle partial words
395 copy_from_slavemem (acx_device_t
*adev
, u8
*destination
, u32 source
, int count
) {
397 u8
*ptmp
= (u8
*) &tmp
;
400 * Right now I'm making the assumption that the destination is aligned, but
403 if ((u32
) destination
& 3) {
404 printk ("acx copy_from_slavemem: warning! destination not word-aligned!\n");
408 write_reg32 (adev
, IO_ACX_SLV_MEM_ADDR
, source
);
410 *((u32
*) destination
) = read_reg32 (adev
, IO_ACX_SLV_MEM_DATA
);
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.
421 write_reg32 (adev
, IO_ACX_SLV_MEM_ADDR
, source
);
423 tmp
= read_reg32 (adev
, IO_ACX_SLV_MEM_DATA
);
425 *destination
++ = *ptmp
++;
431 * Copy to slave memory
433 * TODO - rewrite using autoincrement, handle partial words
436 copy_to_slavemem (acx_device_t
*adev
, u32 destination
, u8
*source
, int count
)
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
);
454 write_reg32 (adev
, IO_ACX_SLV_MEM_ADDR
, destination
);
456 write_reg32 (adev
, IO_ACX_SLV_MEM_DATA
, *((u32
*) source
));
463 * If there are leftovers read the next word from the acx and merge in
464 * what they want to write.
467 write_reg32 (adev
, IO_ACX_SLV_MEM_ADDR
, destination
);
469 tmp
= read_reg32 (adev
, IO_ACX_SLV_MEM_DATA
);
474 * reset address in case we're currently in auto-increment mode
476 write_reg32 (adev
, IO_ACX_SLV_MEM_ADDR
, destination
);
478 write_reg32 (adev
, IO_ACX_SLV_MEM_DATA
, tmp
);
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.
490 chaincopy_to_slavemem (acx_device_t
*adev
, u32 destination
, u8
*source
, int count
)
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
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)
539 writel (*data
++, &adev
->iobase
[ACX_SLV_MEM_DATA
]);
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.
551 chaincopy_from_slavemem (acx_device_t
*adev
, u8
*destination
, u32 source
, int count
)
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)
602 *data
++ = readl (&adev
->iobase
[ACX_SLV_MEM_DATA
]);
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
);
618 return ((c
>= 20) && (c
< 127)) ? c
: '.';
621 #if DUMP_MEM_DEFINED > 0
623 dump_acxmem (acx_device_t
*adev
, u32 start
, int length
)
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
]));
645 enable_acx_irq(acx_device_t
*adev
);
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
;
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
663 blocks_needed
= count
/ (adev
->memblocksize
- 4);
664 if (count
% (adev
->memblocksize
- 4))
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
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;
714 spin_unlock_irqrestore (&adev
->txbuf_lock
, flags
);
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.
726 reclaim_acx_txbuf_space (acx_device_t
*adev
, u32 blockptr
) {
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
)) {
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);
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.
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
);
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
);
820 index
/= adev
->txdesc_size
;
821 if (unlikely(ACX_DEBUG
&& (index
>= TX_CNT
))) {
822 printk("bad txdesc ptr %p\n", txdesc
);
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
);
836 index
/= adev
->txdesc_size
;
837 if (unlikely(ACX_DEBUG
&& (index
>= TX_CNT
))) {
838 printk("bad txdesc ptr %p\n", txdesc
);
841 return adev
->txc
[index
];
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
];
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
);
860 index
/= adev
->txdesc_size
;
861 if (unlikely(ACX_DEBUG
&& (index
>= TX_CNT
))) {
862 printk("bad txdesc ptr %p\n", txdesc
);
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.
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
888 acxmem_read_eeprom_byte(acx_device_t
*adev
, u32 addr
, u8
*charbuf
)
893 write_reg32(adev
, IO_ACX_EEPROM_CFG
, 0);
894 write_reg32(adev
, IO_ACX_EEPROM_ADDR
, addr
);
896 write_reg32(adev
, IO_ACX_EEPROM_CTL
, 2);
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",
913 *charbuf
= read_reg8(adev
, IO_ACX_EEPROM_DATA
);
914 log(L_DEBUG
, "EEPROM at 0x%04X = 0x%02X\n", addr
, *charbuf
);
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
928 acxmem_s_write_eeprom(acx_device_t
*adev
, u32 addr
, u32 len
, const u8
*charbuf
)
930 u8
*data_verify
= NULL
;
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");
949 data_verify
= kmalloc(len
, GFP_KERNEL
);
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
960 gpio_orig
= read_reg16(adev
, IO_ACX_GPIO_OE
);
961 write_reg16(adev
, IO_ACX_GPIO_OE
, gpio_orig
& ~1);
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
));
970 write_reg32(adev
, IO_ACX_EEPROM_CTL
, 1);
973 while (read_reg16(adev
, IO_ACX_EEPROM_CTL
)) {
974 if (unlikely(!--count
)) {
975 printk("WARNING, DANGER!!! "
976 "Timeout waiting for EEPROM write\n");
983 /* disable EEPROM writing */
984 write_reg16(adev
, IO_ACX_GPIO_OE
, gpio_orig
);
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
);
992 write_reg32(adev
, IO_ACX_EEPROM_CTL
, 2);
995 while (read_reg16(adev
, IO_ACX_EEPROM_CTL
)) {
996 if (unlikely(!--count
)) {
997 printk("timeout waiting for EEPROM read\n");
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 */
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
;
1031 write_reg32(adev
, IO_ACX_PHY_ADDR
, reg
);
1033 write_reg32(adev
, IO_ACX_PHY_CTL
, 2);
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",
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
);
1055 goto fail
; /* silence compiler warning */
1062 /***********************************************************************
1065 acxmem_s_write_phy_reg(acx_device_t
*adev
, u32 reg
, u8 value
)
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
);
1076 write_reg32(adev
, IO_ACX_PHY_CTL
, 1);
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",
1093 log(L_DEBUG
, "radio PHY write 0x%02X at 0x%04X\n", value
, reg
);
1100 #define NO_AUTO_INCREMENT 1
1102 /***********************************************************************
1103 ** acxmem_s_write_fw
1105 ** Write the firmware image into the card.
1108 ** adev wlan device structure
1109 ** apfw_image firmware image.
1112 ** 1 firmware image corrupted
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];
1128 #if NO_AUTO_INCREMENT
1129 write_reg32(adev
, IO_ACX_SLV_MEM_CTL
, 0); /* use basic mode */
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 */
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];
1146 #if NO_AUTO_INCREMENT
1147 write_reg32(adev
, IO_ACX_SLV_MEM_ADDR
, offset
+ len
- 4);
1150 write_reg32(adev
, IO_ACX_SLV_MEM_DATA
, v32
);
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
);
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.
1182 ** adev wlan device structure
1183 ** apfw_image firmware image.
1186 ** NOT_OK firmware image corrupted or not correctly written
1190 acxmem_s_validate_fw(acx_device_t
*adev
, const firmware_image_t
*apfw_image
,
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];
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 */
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 */
1213 size
= le32_to_cpu(apfw_image
->size
) & (~3);
1215 while (likely(len
< size
)) {
1216 v32
= be32_to_cpu(*(u32
*)image
);
1221 #if NO_AUTO_INCREMENT
1222 write_reg32(adev
, IO_ACX_SLV_MEM_ADDR
, offset
+ len
- 4);
1225 w32
= read_reg32(adev
, IO_ACX_SLV_MEM_DATA
);
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",
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");
1255 /***********************************************************************
1256 ** acxmem_s_upload_fw
1258 ** Called from acx_reset_dev
1261 acxmem_s_upload_fw(acx_device_t
*adev
)
1263 firmware_image_t
*apfw_image
= NULL
;
1267 char *filename
= "WLANGEN.BIN";
1268 #ifdef PATCH_AROUND_BAD_SPOTS
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
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
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
);
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
);
1300 res
= acxmem_s_validate_fw(adev
, apfw_image
, 0);
1301 log(L_DEBUG
|L_INIT
, "acx_validate_fw "
1302 "(main):%d\n", res
);
1306 SET_BIT(adev
->dev_state_mask
, ACX_STATE_FW_LOADED
);
1309 printk("acx: firmware upload attempt #%d FAILED, "
1310 "retrying...\n", try);
1311 acx_s_msleep(1000); /* better wait for a while... */
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]
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
);
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
)
1367 firmware_image_t
*radio_image
;
1368 acx_cmd_radioinit_t radioinit
;
1373 char filename
[sizeof("RADIONN.BIN")];
1375 if (!adev
->need_radio_fw
) return OK
;
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",
1384 radio_image
= acx_s_read_fw(adev
->dev
, filename
, &size
);
1386 printk("acx: can't load radio module '%s'\n", filename
);
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
);
1396 res
= acxmem_s_validate_fw(adev
, radio_image
, offset
);
1397 log(L_DEBUG
|L_INIT
, "acx_validate_fw (radio): %d\n", res
);
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
;
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
);
1429 /***********************************************************************
1430 ** acxmem_l_reset_mac
1432 ** MAC will be reset
1433 ** Call context: reset_dev
1436 acxmem_l_reset_mac(acx_device_t
*adev
)
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
++) {
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
++) {
1467 /* Windows driver writes 0x10000 to register 0x808 here */
1469 write_reg32 (adev
, 0x808, 0x10000);
1475 /***********************************************************************
1476 ** acxmem_s_verify_init
1479 acxmem_s_verify_init(acx_device_t
*adev
)
1481 int result
= NOT_OK
;
1482 unsigned long timeout
;
1486 timeout
= jiffies
+ 2*HZ
;
1488 u32 irqstat
= read_reg32(adev
, IO_ACX_IRQ_STATUS_NON_DES
);
1489 if ((irqstat
!= 0xFFFFFFFF) && (irqstat
& HOST_INT_FCS_THRESHOLD
)) {
1491 write_reg32(adev
, IO_ACX_IRQ_ACK
, HOST_INT_FCS_THRESHOLD
);
1494 if (time_after(jiffies
, timeout
))
1496 /* Init may take up to ~0.5 sec total */
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
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));
1525 /***********************************************************************
1526 ** acxmem_read_cmd_type_status
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
));
1546 /***********************************************************************
1547 ** acxmem_s_reset_dev
1550 ** netdevice that contains the adev variable
1555 ** device is hard reset
1559 ** This resets the device using low level hardware calls
1560 ** as well as uploads and verifies the firmware to the card
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
);
1583 read_eeprom_area(acx_device_t
*adev
)
1589 for (offs
= 0x8c; offs
< 0xb9; offs
++)
1590 acxmem_read_eeprom_byte(adev
, offs
, &tmp
);
1595 acxmem_s_reset_dev(acx_device_t
*adev
)
1597 const char* msg
= "";
1598 unsigned long flags
;
1599 int result
= NOT_OK
;
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
);
1631 while (count
-- && (tmp
!= ACX_VENDOR_ID
)) {
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;
1642 msg
= "eCPU is already running. ";
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. ";
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
);
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 */
1672 hardware_info
= read_reg16(adev
, IO_ACX_EEPROM_INFORMATION
);
1674 msg
= "eCPU didn't indicate radio type";
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
))
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. ";
1704 log(L_DEBUG
, "eCPU has woken up, card is ready to be configured\n");
1706 acxmem_write_cmd_type_status(adev
, ACX1xx_CMD_RESET
, 0);
1708 /* test that EEPROM is readable */
1709 read_eeprom_area(adev
);
1714 /* Finish error message. Indicate which function failed */
1716 acx_unlock(adev
, flags
);
1718 printk("acx: %sreset_dev() FAILED\n", msg
);
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!
1738 #define FUNC "issue_cmd"
1742 acxmem_s_issue_cmd_timeo(
1747 unsigned cmd_timeout
)
1751 acxmem_s_issue_cmd_timeo_debug(
1756 unsigned cmd_timeout
,
1759 unsigned long start
= jiffies
;
1761 const char *devname
;
1767 unsigned long timeout
;
1771 devname
= adev
->ndev
->name
;
1772 if (!devname
|| !devname
[0] || devname
[4]=='%')
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
);
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 */
1792 counter
= (timeout
* 1000 / HZ
) - 1; /* in ms */
1795 cmd_status
= acxmem_read_cmd_type_status(adev
);
1796 /* Test for IDLE state */
1799 if (counter
% 5 == 0) {
1800 if (time_after(jiffies
, timeout
)) {
1804 /* we waited 5 iterations, no luck. Sleep 5 ms */
1807 } while (likely(--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);
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 */
1828 if (cmd
== ACX1xx_CMD_INTERROGATE
)
1829 memset_io(adev
->cmd_area
+ 4, 0xAA, buflen
);
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
);
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))
1856 /* we schedule away sometimes (timeout can be large) */
1857 counter
= cmd_timeout
;
1858 timeout
= jiffies
+ cmd_timeout
* HZ
/ 1000;
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
);
1867 } else { /* Wait when IRQ will set the bit */
1868 irqtype
= adev
->irq_status
;
1869 if (irqtype
& HOST_INT_CMD_COMPLETE
)
1873 if (counter
% 5 == 0) {
1874 if (time_after(jiffies
, timeout
)) {
1878 /* we waited 5 iterations, no luck. Sleep 5 ms */
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");
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
1920 * 388 is maximum command length
1922 printk ("invalid length 0x%08x\n", buflen
);
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
++);
1934 if (buffer
&& buflen
)
1935 memset(buffer
, 0, buflen
);
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
);
1949 log(L_CTL
, FUNC
"(%s): took %ld jiffies to complete\n",
1950 cmdstr
, jiffies
- start
);
1955 /* Give enough info so that callers can avoid
1956 ** printing their own diagnostic messages */
1958 printk("%s: "FUNC
"(cmd:%s) FAILED\n", devname
, cmdstr
);
1960 printk("%s: "FUNC
"(cmd:0x%04X) FAILED\n", devname
, cmd
);
1968 /***********************************************************************
1970 #if defined(NONESSENTIAL_FEATURES)
1971 typedef struct device_id
{
1972 unsigned char id
[6];
1977 static const device_id_t
1981 {'G', 'l', 'o', 'b', 'a', 'l'},
1986 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
1988 "SpeedStream SS1021 or Gigafast WF721-AEX"
1991 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85},
1996 {'?', '?', '?', '?', '?', '?'},
1998 "Level One WPC-0200"
2001 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
2008 acx_show_card_eeprom_id(acx_device_t
*adev
)
2010 unsigned char buffer
[CARD_EEPROM_ID_SIZE
];
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
,
2019 printk("acx: reading EEPROM FAILED\n");
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
);
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.
2051 acxmem_free_desc_queues(acx_device_t
*adev
)
2053 #define ACX_FREE_QUEUE(size, ptr, phyaddr) \
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
;
2076 /***********************************************************************
2077 ** acxmem_s_delete_dma_regions
2080 acxmem_s_delete_dma_regions(acx_device_t
*adev
)
2082 unsigned long flags
;
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);
2097 acx_lock(adev
, flags
);
2098 acxmem_free_desc_queues(adev
);
2099 acx_unlock(adev
, flags
);
2105 /***********************************************************************
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
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
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 */
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 */
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
;
2221 unsigned long addr_size
=0;
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";
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) */
2249 printk("acx: no memory for netdevice structure\n");
2250 goto fail_alloc_netdev
;
2253 dev_set_drvdata (dev
, ndev
);
2258 * use platform_data resources that were provided
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
;
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); */
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
);
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
))
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
))
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
);
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
);
2394 great_inquisitor(adev
);
2400 /* error paths: undo everything in reverse order... */
2402 fail_register_netdev
:
2404 acxmem_s_delete_dma_regions(adev
);
2407 fail_read_eeprom_version
:
2412 fail_unknown_chiptype
:
2421 /***********************************************************************
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
;
2440 ndev
= (struct net_device
*) dev_get_drvdata(pdev
);
2442 log(L_DEBUG
, "%s: card is unused. Skipping any release code\n",
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 */
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...) */
2478 printk ("e_remove done\n");
2486 /***********************************************************************
2487 ** TODO: PM code needs to be fixed / debugged / tested.
2491 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
2492 acxmem_e_suspend(struct device
*pdev
, pm_message_t state
)
2494 acxmem_e_suspend(struct device
*pdev
, u32 state
)
2497 struct net_device
*ndev
= dev_get_drvdata(pdev
);
2501 printk("acx: suspend handler is experimental!\n");
2502 printk("sus: dev %p\n", ndev
);
2504 if (!netif_running(ndev
))
2507 adev
= ndev2adev(ndev
);
2508 printk("sus: adev %p\n", 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
);
2527 fw_resumer( void *data
)
2529 struct device
*pdev
= data
;
2530 struct net_device
*ndev
= dev_get_drvdata(pdev
);
2533 printk("acx: resume handler is experimental!\n");
2534 printk("rsm: got dev %p\n", ndev
);
2536 if (!netif_running(ndev
))
2539 adev
= ndev2adev(ndev
);
2540 printk("rsm: got adev %p\n", adev
);
2544 if (OK
!= acxmem_s_reset_dev(adev
))
2546 printk("rsm: device reset done\n");
2547 if (OK
!= acx_s_init_mac(adev
))
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);
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");
2574 acx_sem_unlock(adev
);
2577 DECLARE_WORK( fw_resume_work
, fw_resumer
, 0 );
2580 acxmem_e_resume(struct device
*pdev
)
2584 fw_resume_work
.data
= pdev
;
2585 schedule_work( &fw_resume_work
);
2590 #endif /* CONFIG_PM */
2593 /***********************************************************************
2596 ** This function is called by acxmem_e_open (when ifconfig sets the device as up)
2599 ** - Enables on-card interrupt requests
2600 ** - calls acx_s_start
2604 enable_acx_irq(acx_device_t
*adev
)
2607 write_reg16(adev
, IO_ACX_IRQ_MASK
, adev
->irq_mask
);
2608 write_reg16(adev
, IO_ACX_FEMR
, 0x8000);
2609 adev
->irqs_active
= 1;
2614 acxmem_s_up(struct net_device
*ndev
)
2616 acx_device_t
*adev
= ndev2adev(ndev
);
2617 unsigned long flags
;
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;
2641 case ACX_MODE_MONITOR
:
2642 acx_set_status(adev
, ACX_STATUS_4_ASSOCIATED
); break;
2651 /***********************************************************************
2654 ** This disables the netdevice
2657 ** - disables on-card interrupt request
2661 disable_acx_irq(acx_device_t
*adev
)
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;
2675 acxmem_s_down(struct net_device
*ndev
)
2677 acx_device_t
*adev
= ndev2adev(ndev
);
2678 unsigned long flags
;
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();
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
);
2728 /***********************************************************************
2731 ** Called as a result of SIOCSIFFLAGS ioctl changing the flags bit IFF_UP
2732 ** from clear to set. In other words: ifconfig up.
2736 ** >0 f/w reported error
2737 ** <0 driver reported error
2740 acxmem_e_open(struct net_device
*ndev
)
2742 acx_device_t
*adev
= ndev2adev(ndev
);
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
);
2759 set_irq_type (ndev
->irq
, IRQT_FALLING
);
2760 log(L_DEBUG
|L_IRQ
, "request_irq %d successful\n", ndev
->irq
);
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.
2773 acx_sem_unlock(adev
);
2780 /***********************************************************************
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"
2788 ** >0 f/w reported error
2789 ** <0 driver reported error
2792 acxmem_e_close(struct net_device
*ndev
)
2794 acx_device_t
*adev
= ndev2adev(ndev
);
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");
2826 /***********************************************************************
2827 ** acxmem_i_tx_timeout
2829 ** Called from network core. Must not sleep!
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
;
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
);
2876 /***********************************************************************
2877 ** acxmem_i_set_multicast_list
2878 ** FIXME: most likely needs refinement
2881 acxmem_i_set_multicast_list(struct net_device
*ndev
)
2883 acx_device_t
*adev
= ndev2adev(ndev
);
2884 unsigned long flags
;
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
);
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
);
2914 /***************************************************************
2915 ** acxmem_l_process_rxdesc
2917 ** Called directly and only from the IRQ handler
2921 static inline void log_rxbuffer(const acx_device_t
*adev
) {}
2924 log_rxbuffer(const acx_device_t
*adev
)
2926 register const struct rxhostdesc
*rxhostdesc
;
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
);
2942 acxmem_l_process_rxdesc(acx_device_t
*adev
)
2944 register rxhostdesc_t
*hostdesc
;
2945 register rxdesc_t
*rxdesc
;
2952 if (unlikely(acx_debug
& L_BUFR
))
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
;
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 */
2982 /* now process descriptors, starting with the first we figured out */
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
));
3004 chaincopy_from_slavemem (adev
, (u8
*) hostdesc
->data
, addr
,
3006 (u32
) &((rxbuffer_t
*)0)->hdr_a3
);
3007 acx_l_process_rxbuf(adev
, hostdesc
->data
);
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
))
3040 tail
= (tail
+ 1) % RX_CNT
;
3043 adev
->rx_tail
= tail
;
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:
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
3087 handle_info_irq(acx_device_t
*adev
)
3090 static const char * const info_type_msg
[] = {
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",
3107 "TKIP IV value exceeds thresh"
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
);
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
)) ?
3134 log_unusual_irq(u16 irqtype
) {
3136 if (!printk_ratelimit())
3141 if (irqtype
& HOST_INT_TX_XFER
) {
3144 if (irqtype
& HOST_INT_RX_COMPLETE
) {
3145 printk(" Rx_Complete");
3147 if (irqtype
& HOST_INT_DTIM
) {
3150 if (irqtype
& HOST_INT_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 */
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
) {
3177 printk(" IRQ(s)\n");
3182 update_link_quality_led(acx_device_t
*adev
)
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 */
3202 acxmem_i_interrupt(int irq
, void *dev_id
)
3205 unsigned long flags
;
3206 unsigned int irqcount
= MAX_IRQLOOPS_PER_JIFFY
;
3207 register u16 irqtype
;
3210 adev
= ndev2adev((struct net_device
*)dev_id
);
3212 /* LOCKING: can just spin_lock() since IRQs are disabled anyway.
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");
3225 /* We will check only "interesting" IRQ types */
3226 irqtype
= unmasked
& ~adev
->irq_mask
;
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
);
3234 /* Done here because IRQ_NONEs taking three lines of log
3235 ** drive me crazy */
3238 #define IRQ_ITERATE 1
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
)) {
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
);
3272 acxmem_l_clean_txdesc(adev
);
3277 /* Less frequent ones */
3279 | HOST_INT_CMD_COMPLETE
3281 | HOST_INT_SCAN_COMPLETE
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 */
3303 /* | HOST_INT_RX_DATA */
3304 /* | HOST_INT_TX_COMPLETE */
3306 | HOST_INT_RX_COMPLETE
3310 | HOST_INT_KEY_NOT_FOUND
3311 | HOST_INT_IV_ICV_FAILURE
3312 /* | HOST_INT_CMD_COMPLETE */
3313 /* | HOST_INT_INFO */
3315 | HOST_INT_PROCESS_ERROR
3316 /* | HOST_INT_SCAN_COMPLETE */
3317 | HOST_INT_FCS_THRESHOLD
3318 | HOST_INT_BEACON_MISSED
3320 log_unusual_irq(irqtype
);
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 */
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... */
3341 /* Routine to perform blink with range */
3342 if (unlikely(adev
->led_power
== 2))
3343 update_link_quality_led(adev
);
3346 /* write_flush(adev); - not needed, last op was read anyway */
3347 acx_unlock(adev
, flags
);
3352 acx_unlock(adev
, flags
);
3357 /***********************************************************************
3358 ** acxmem_l_power_led
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");
3373 write_reg16(adev
, IO_ACX_GPIO_OUT
,
3374 read_reg16(adev
, IO_ACX_GPIO_OUT
) & ~gpio_pled
);
3376 write_reg16(adev
, IO_ACX_GPIO_OUT
,
3377 read_reg16(adev
, IO_ACX_GPIO_OUT
) | gpio_pled
);
3381 /***********************************************************************
3385 /***********************************************************************
3388 acx111pci_ioctl_info(
3389 struct net_device
*ndev
,
3390 struct iw_request_info
*info
,
3391 struct iw_param
*vwrq
,
3395 acx_device_t
*adev
= ndev2adev(ndev
);
3398 rxhostdesc_t
*rxhostdesc
;
3399 txhostdesc_t
*txhostdesc
;
3400 struct acx111_ie_memoryconfig memconf
;
3401 struct acx111_ie_queueconfig queueconf
;
3402 unsigned long flags
;
3407 char ratefallback
[0x5];
3409 if ( !(acx_debug
& (L_IOCTL
|L_DEBUG
)) )
3411 /* using printk() since we checked debug flag already */
3415 if (!IS_ACX111(adev
)) {
3416 printk("acx111-specific function called "
3417 "with non-acx111 chip, aborting\n");
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"
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
,
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"
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"
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]),
3536 /* dump Acx111 Rx Config */
3537 printk("dump rx config:\n"
3538 "data read: %d, struct size: %d\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"
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"
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",
3577 acx2cpu(rxdesc
->pNextDesc
),
3578 acx2cpu(rxdesc
->ACXMemPtr
),
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"
3594 "buffer mem pos 0x%X\n"
3595 "buffer mem offset 0x%X\n"
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
);
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"
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
),
3630 acx2cpu(txdesc
->pNextDesc
),
3631 acx2cpu(txdesc
->AcxMemPtr
),
3632 acx2cpu(txdesc
->HostMemPtr
),
3633 le16_to_cpu(txdesc
->total_length
),
3635 txdesc
->Ctl2_8
, txdesc
->error
,
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"
3648 "buffer mem pos 0x%X\n"
3649 "buffer mem offset 0x%X\n"
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
));
3665 /* write_reg16(adev, 0xb4, 0x4); */
3667 acx_unlock(adev
, flags
);
3670 acx_sem_unlock(adev
);
3671 #endif /* ACX_DEBUG */
3676 /***********************************************************************
3679 acx100mem_ioctl_set_phy_amp_bias(
3680 struct net_device
*ndev
,
3681 struct iw_request_info
*info
,
3682 struct iw_param
*vwrq
,
3685 acx_device_t
*adev
= ndev2adev(ndev
);
3686 unsigned long flags
;
3689 if (!IS_ACX100(adev
)) {
3691 * Removing this check *might* damage
3692 * hardware, since we're tweaking GPIOs here after all!!!
3693 * You've been warned...
3695 printk("acx: sorry, setting bias level for non-acx100 "
3696 "is not supported yet\n");
3701 printk("acx: invalid bias parameter, range is 0-7\n");
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",
3717 (gpio_old
& 0x0700) >> 8, (unsigned char)*extra
);
3719 acx_sem_unlock(adev
);
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.
3733 acxmem_l_alloc_tx(acx_device_t
*adev
)
3735 struct txdesc
*txdesc
;
3741 if (unlikely(!adev
->tx_free
)) {
3742 printk("acx: BUG: no free txdesc left\n");
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
3753 if (!adev
->acx_txbuf_blocks_free
) {
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
);
3781 /* Needed in case txdesc won't be eventually submitted for tx */
3782 write_slavemem8 (adev
, (u32
) &(txdesc
->Ctl_8
), DESC_CTL_ACXDONE_HOSTOWN
);
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",
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
;
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.
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
;
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 /***********************************************************************
3847 acxmem_l_get_txbuf(acx_device_t
*adev
, tx_t
* tx_opaque
)
3849 return get_txhostdesc(adev
, (txdesc_t
*)tx_opaque
)->data
;
3853 /***********************************************************************
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.
3864 acxmem_update_queue_indicator (acx_device_t
*adev
, int txqueue
)
3866 #ifdef USING_MORE_THAN_ONE_TRANSMIT_QUEUE
3868 unsigned long flags
;
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
3876 local_irq_save (flags
);
3879 * Wait for ACX to release the lock (at most 500ns).
3882 while (read_slavemem16 (adev
, (u32
) &(adev
->acx_queue_indicator
->fw_lock
))
3883 && (count
++ < 50)) {
3889 * Take out the host lock - anything non-zero will work, so don't worry about
3892 write_slavemem16 (adev
, (u32
) &(adev
->acx_queue_indicator
->host_lock
), 1);
3895 * Avoid a race condition
3898 while (read_slavemem16 (adev
, (u32
) &(adev
->acx_queue_indicator
->fw_lock
))
3899 && (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
);
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
;
3940 /* fw doesn't tx such packets anyhow */
3941 if (unlikely(len
< WLAN_HDR_A3_LEN
))
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
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
);
3963 CLEAR_BIT(Ctl2_8
, DESC_CTL2_RTS
);
3965 switch (adev
->mode
) {
3966 case ACX_MODE_0_ADHOC
:
3968 clt
= acx_l_sta_list_get(adev
, ((wlan_hdr_t
*)hostdesc1
->data
)->a1
);
3970 case ACX_MODE_2_STA
:
3971 clt
= adev
->ap_client
;
3974 /* testing was done on acx111: */
3975 case ACX_MODE_MONITOR
:
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 */
3982 + DESC_CTL2_MORE_FRAG
3984 + DESC_CTL2_RETRY
/* don't increase retry field */
3986 + DESC_CTL2_POWER
/* don't increase power mgmt. field */
3988 + DESC_CTL2_WEP
/* encrypt this frame */
3990 + DESC_CTL2_DUR
/* don't increase duration field */
3994 default: /* ACX_MODE_OFF, ACX_MODE_MONITOR */
3999 rate_cur
= clt
? clt
->rate_cur
: adev
->rate_bcast
;
4000 if (unlikely(!rate_cur
)) {
4001 printk("acx: driver bug! bad ratemask\n");
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(
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)
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
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 */
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 */
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
);
4058 chaincopy_to_slavemem (adev
, addr
, hostdesc1
->data
, len
);
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
;
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 */
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 */
4108 write_reg16(adev
, IO_ACX_INT_TRIG
, INT_TRIG_TXPRC
);
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)" : "",
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)" : "",
4130 if (acx_debug
& L_DATA
) {
4131 printk("tx: 802.11 [%d]: ", len
);
4132 acx_dump_bytes(hostdesc1
->data
, len
);
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.
4152 static inline void log_txbuffer(const acx_device_t
*adev
) {}
4155 log_txbuffer(acx_device_t
*adev
)
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);
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... */
4187 err
= "no Tx due to error in other fragment";
4188 adev
->wstats
.discard
.fragment
++;
4192 adev
->stats
.tx_aborted_errors
++;
4195 err
= "Tx desc wrong parameters";
4196 adev
->wstats
.discard
.misc
++;
4199 err
= "WEP key not found";
4200 adev
->wstats
.discard
.misc
++;
4203 err
= "MSDU lifetime timeout? - try changing "
4204 "'iwconfig retry lifetime XXX'";
4205 adev
->wstats
.discard
.misc
++;
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",
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
);
4246 err
= "Tx buffer overflow";
4247 adev
->stats
.tx_fifo_errors
++;
4251 adev
->wstats
.discard
.misc
++;
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
);
4259 printk("%s: tx error 0x%02X, buf %02u!\n",
4260 adev
->ndev
->name
, error
, finger
);
4265 acxmem_l_clean_txdesc(acx_device_t
*adev
)
4271 u8 error
, ack_failures
, rts_failures
, rts_ok
, r100
, Ctl_8
;
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
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
))
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
;
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
);
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
;
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
));
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
)
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",
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
);
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
);
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
;
4405 FN_EXIT1(num_cleaned
);
4409 /* clean *all* Tx descriptors, and regardless of their previous state.
4410 * Used for brute-force reset handling. */
4412 acxmem_l_clean_txdesc_emergency(acx_device_t
*adev
)
4419 for (i
= 0; i
< TX_CNT
; i
++) {
4420 txdesc
= get_txdesc(adev
, i
);
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
;
4436 /***********************************************************************
4437 ** acxmem_s_create_tx_host_desc_queue
4441 allocate(acx_device_t
*adev
, size_t size
, dma_addr_t
*phy
, const char *msg
)
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
;
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
);
4457 printk(KERN_ERR
"acx: %s allocation FAILED (%d bytes)\n",
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
4472 acxmem_s_create_tx_host_desc_queue(acx_device_t
*adev
)
4474 txhostdesc_t
*hostdesc
;
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
)
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
)
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");
4499 hostdesc
= adev
->txhostdesc_start
;
4500 txbuf
= adev
->txbuf_start
;
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
);
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
;
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 = ... */
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
;
4557 txbuf
+= WLAN_HDR_A3_LEN
;
4559 txbuf
+= WLAN_A4FR_MAXLEN_WEP_FCS
- WLAN_HDR_A3_LEN
;
4568 printk("acx: create_tx_host_desc_queue FAILED\n");
4569 /* dealloc will be done by free function on error case */
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)
4583 acxmem_s_create_rx_host_desc_queue(acx_device_t
*adev
)
4585 rxhostdesc_t
*hostdesc
;
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
)
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");
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
)
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
);
4627 printk("acx: create_rx_host_desc_queue FAILED\n");
4628 /* dealloc will be done by free function on error case */
4634 /***************************************************************
4635 ** acxmem_s_create_hostdesc_queues
4638 acxmem_s_create_hostdesc_queues(acx_device_t
*adev
)
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
);
4648 /***************************************************************
4649 ** acxmem_create_tx_desc_queue
4652 acxmem_create_tx_desc_queue(acx_device_t
*adev
, u32 tx_queue_start
)
4660 if (IS_ACX100(adev
))
4661 adev
->txdesc_size
= sizeof(*txdesc
);
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);
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
4696 clr
= (u32
) adev
->txdesc_start
;
4697 while (clr
< (u32
) adev
->txdesc_start
+ (TX_CNT
* sizeof(*txdesc
))) {
4698 write_slavemem32 (adev
, clr
, 0);
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 */
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) */
4723 /* go back to the last one */
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
));
4733 /***************************************************************
4734 ** acxmem_create_rx_desc_queue
4737 acxmem_create_rx_desc_queue(acx_device_t
*adev
, u32 rx_queue_start
)
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
);
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);
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 */
4785 /* go to the last one */
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
));
4796 /***************************************************************
4797 ** acxmem_create_desc_queues
4800 acxmem_create_desc_queues(acx_device_t
*adev
, u32 tx_queue_start
, u32 rx_queue_start
)
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);
4815 /***************************************************************
4816 ** acxmem_s_proc_diag_output
4819 acxmem_s_proc_diag_output(char *p
, acx_device_t
*adev
)
4821 const char *rtl
, *thd
, *ttl
;
4830 #if DUMP_MEM_DURING_DIAG > 0
4831 dump_acxmem (adev
, 0, 0x10000);
4832 panic ("dump finished");
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
);
4843 p
+= sprintf(p
, "%02u (%02x) empty%s\n", i
, Ctl_8
, rtl
);
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
);
4861 p
+= sprintf(p
, "%02u busy (%02X)%s%s", i
, Ctl_8
, thd
, ttl
);
4862 tmp
= read_slavemem32 (adev
, (u32
) &(txdesc
->AcxMemPtr
));
4864 p
+= sprintf (p
, " %04x", tmp
);
4865 while ((tmp
= read_slavemem32 (adev
, (u32
) tmp
)) != 0x02000000) {
4867 p
+= sprintf (p
, " %04x", tmp
);
4870 p
+= sprintf (p
, "\n");
4871 txdesc
= advance_txdesc(adev
, txdesc
, 1);
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"
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
,
4891 adev
->rxhostdesc_start
, adev
->rxhostdesc_area_size
,
4892 adev
->rxbuf_start
, adev
->rxbuf_area_size
);
4898 /***********************************************************************
4901 acxmem_proc_eeprom_output(char *buf
, acx_device_t
*adev
)
4908 for (i
= 0; i
< 0x400; i
++) {
4909 acxmem_read_eeprom_byte(adev
, i
, p
++);
4917 /***********************************************************************
4920 acxmem_set_interrupt_mask(acx_device_t
*adev
)
4922 if (IS_ACX111(adev
)) {
4923 adev
->irq_mask
= (u16
) ~(0
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
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 */
4944 adev
->irq_mask
= (u16
) ~(0
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
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,
4990 static const u8 dbm2val_maxim
[21] = {
4998 static const u8 dbm2val_rfmd
[21] = {
5008 switch (adev
->radio_type
) {
5009 case RADIO_MAXIM_0D
:
5010 table
= &dbm2val_maxim
[0];
5013 case RADIO_RALINK_15
:
5014 table
= &dbm2val_rfmd
[0];
5017 printk("%s: unknown/unsupported radio type, "
5018 "cannot modify tx power level yet!\n",
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
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.
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
]);
5049 static struct device_driver
5052 .bus
= &platform_bus_type
,
5053 .probe
= acxmem_e_probe
,
5054 .remove
= __devexit_p(acxmem_e_remove
),
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
5068 acxmem_e_init_module(void)
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");
5079 printk("acx: compiled to use 16bit I/O access only "
5080 "(compatibility mode)\n");
5083 #ifdef __LITTLE_ENDIAN
5084 #define ENDIANNESS_STRING "running on a little-endian CPU\n"
5086 #define ENDIANNESS_STRING "running on a BIG-ENDIAN CPU\n"
5090 "PCI module " ACX_RELEASE
" initialized, "
5091 "waiting for cards to probe...\n"
5094 res
= driver_register (&acxmem_drv_id
);
5100 /***********************************************************************
5101 ** acxmem_e_cleanup_module
5103 ** Called at module unload time. This is our last chance to
5104 ** clean up after ourselves.
5107 acxmem_e_cleanup_module(void)
5109 struct net_device
*ndev
;
5110 unsigned long flags
;
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
;
5126 acx_device_t
*adev
= ndev2adev(ndev
);
5127 struct acx_hardware_data
*hwdata
= adev
->dev
->platform_data
;
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);
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);
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);
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
);
5157 temp
= read_reg16(adev
, IO_ACX_ECPU_CTRL
) | 0x1;
5158 write_reg16(adev
, IO_ACX_ECPU_CTRL
, temp
);
5162 (void) hwdata
->stop_hw();
5164 acx_unlock(adev
, flags
);
5166 acx_sem_unlock(adev
);
5171 driver_unregister( &acxmem_drv_id
);
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" );