12 #include <linux/module.h>
13 #include <linux/kernel.h>
22 #include <linux/kernelcapi.h>
26 #include <asm/uaccess.h>
27 #include <linux/netdevice.h>
33 static char *
revision =
"$Revision: 1.1.2.3 $";
35 #undef AVM_B1DMA_DEBUG
43 static bool suppress_pollack = 0;
54 #define AMCC_RXPTR 0x24
55 #define AMCC_RXLEN 0x28
56 #define AMCC_TXPTR 0x2c
57 #define AMCC_TXLEN 0x30
59 #define AMCC_INTCSR 0x38
60 # define EN_READ_TC_INT 0x00008000L
61 # define EN_WRITE_TC_INT 0x00004000L
62 # define EN_TX_TC_INT EN_READ_TC_INT
63 # define EN_RX_TC_INT EN_WRITE_TC_INT
64 # define AVM_FLAG 0x30000000L
66 # define ANY_S5933_INT 0x00800000L
67 # define READ_TC_INT 0x00080000L
68 # define WRITE_TC_INT 0x00040000L
69 # define TX_TC_INT READ_TC_INT
70 # define RX_TC_INT WRITE_TC_INT
71 # define MASTER_ABORT_INT 0x00100000L
72 # define TARGET_ABORT_INT 0x00200000L
73 # define BUS_MASTER_INT 0x00200000L
74 # define ALL_INT 0x000C0000L
76 #define AMCC_MCSR 0x3c
77 # define A2P_HI_PRIORITY 0x00000100L
78 # define EN_A2P_TRANSFERS 0x00000400L
79 # define P2A_HI_PRIORITY 0x00001000L
80 # define EN_P2A_TRANSFERS 0x00004000L
81 # define RESET_A2P_FLAGS 0x04000000L
82 # define RESET_P2A_FLAGS 0x02000000L
98 static inline int b1dma_tx_empty(
unsigned int port)
100 return inb(port + 0x03) & 0x1;
103 static inline int b1dma_rx_full(
unsigned int port)
105 return inb(port + 0x02) & 0x1;
108 static int b1dma_tolink(
avmcard *
card,
void *
buf,
unsigned int len)
111 unsigned char *
s = (
unsigned char *)buf;
113 while (!b1dma_tx_empty(card->
port)
115 if (!b1dma_tx_empty(card->
port))
117 t1outp(card->
port, 0x01, *s++);
122 static int b1dma_fromlink(
avmcard *card,
void *buf,
unsigned int len)
125 unsigned char *s = (
unsigned char *)buf;
127 while (!b1dma_rx_full(card->
port)
129 if (!b1dma_rx_full(card->
port))
131 *s++ = t1inp(card->
port, 0x00);
139 if (b1dma_tolink(card, &cmd, 1) == 0
140 && b1dma_tolink(card, ®, 4) == 0) {
142 return b1dma_tolink(card, &tmp, 4);
150 if (b1dma_tolink(card, &cmd, 1) == 0
151 && b1dma_tolink(card, ®, 4) == 0) {
153 if (b1dma_fromlink(card, &tmp, 4) == 0)
161 static inline void _put_byte(
void **
pp,
u8 val)
168 static inline void _put_word(
void **
pp,
u32 val)
172 *s++ = (val >> 8) & 0xff;
173 *s++ = (val >> 16) & 0xff;
174 *s++ = (val >> 24) & 0xff;
178 static inline void _put_slice(
void **
pp,
unsigned char *
dp,
unsigned int len)
183 _put_byte(pp, *dp++);
186 static inline u8 _get_byte(
void **pp)
195 static inline u32 _get_word(
void **pp)
207 static inline u32 _get_slice(
void **pp,
unsigned char *dp)
211 len = i = _get_word(pp);
212 while (i-- > 0) *dp++ = _get_byte(pp);
226 t1outp(card->
port, 0x10, 0x00);
227 t1outp(card->
port, 0x07, 0x00);
231 b1dma_writel(card, 0x0f000000,
AMCC_MCSR);
242 static int b1dma_detect(
avmcard *card)
246 b1dma_writel(card, 0x0f000000,
AMCC_MCSR);
256 if (b1dma_readl(card,
AMCC_MCSR) != 0x000000E6)
261 if (b1dma_readl(card,
AMCC_RXPTR) != 0xfffffffc
262 || b1dma_readl(card,
AMCC_TXPTR) != 0xfffffffc)
271 t1outp(card->
port, 0x10, 0x00);
272 t1outp(card->
port, 0x07, 0x00);
274 t1outp(card->
port, 0x02, 0x02);
275 t1outp(card->
port, 0x03, 0x02);
277 if ((t1inp(card->
port, 0x02) & 0xFE) != 0x02
278 || t1inp(card->
port, 0x3) != 0x03)
281 t1outp(card->
port, 0x02, 0x00);
282 t1outp(card->
port, 0x03, 0x00);
284 if ((t1inp(card->
port, 0x02) & 0xFE) != 0x00
285 || t1inp(card->
port, 0x3) != 0x01)
295 if ((ret = b1dma_detect(card)) != 0)
300 if (WriteReg(card, 0x80001000, 0x11) != 0
301 || WriteReg(card, 0x80101000, 0x22) != 0
302 || WriteReg(card, 0x80201000, 0x33) != 0
303 || WriteReg(card, 0x80301000, 0x44) != 0)
306 if (ReadReg(card, 0x80001000) != 0x11
307 || ReadReg(card, 0x80101000) != 0x22
308 || ReadReg(card, 0x80201000) != 0x33
309 || ReadReg(card, 0x80301000) != 0x44)
312 if (WriteReg(card, 0x80001000, 0x55) != 0
313 || WriteReg(card, 0x80101000, 0x66) != 0
314 || WriteReg(card, 0x80201000, 0x77) != 0
315 || WriteReg(card, 0x80301000, 0x88) != 0)
318 if (ReadReg(card, 0x80001000) != 0x55
319 || ReadReg(card, 0x80101000) != 0x66
320 || ReadReg(card, 0x80201000) != 0x77
321 || ReadReg(card, 0x80301000) != 0x88)
331 if ((ret = b1dma_detect(card)) != 0)
334 for (i = 0; i < 5; i++) {
335 if (WriteReg(card, 0x80A00000, 0x21) != 0)
337 if ((ReadReg(card, 0x80A00000) & 0x01) != 0x01)
340 for (i = 0; i < 5; i++) {
341 if (WriteReg(card, 0x80A00000, 0x20) != 0)
343 if ((ReadReg(card, 0x80A00000) & 0x01) != 0x00)
359 b1dma_dispatch_tx(card);
363 spin_unlock_irqrestore(&card->
lock, flags);
368 static void b1dma_dispatch_tx(
avmcard *card)
390 _put_slice(&p, skb->
data, len);
391 _put_slice(&p, skb->
data + len, dlen);
394 _put_slice(&p, skb->
data, len);
397 #ifdef AVM_B1DMA_DEBUG
401 txlen = skb->
len - 2;
402 #ifdef AVM_B1DMA_POLLDEBUG
406 #ifdef AVM_B1DMA_DEBUG
408 skb->
data[2], txlen);
410 skb_copy_from_linear_data_offset(skb, 2, dma->
sendbuf.
dmabuf,
413 txlen = (txlen + 3) & ~3;
425 static void queue_pollack(
avmcard *card)
442 b1dma_queue_tx(card, skb);
447 static void b1dma_handle_rx(
avmcard *card)
454 u32 ApplId, MsgLen, DataB3Len,
NCCI, WindowSize;
455 u8 b1cmd = _get_byte(&p);
457 #ifdef AVM_B1DMA_DEBUG
464 ApplId = (unsigned) _get_word(&p);
465 MsgLen = _get_slice(&p, card->
msgbuf);
466 DataB3Len = _get_slice(&p, card->
databuf);
473 if (!(skb = alloc_skb(DataB3Len + MsgLen,
GFP_ATOMIC))) {
485 ApplId = (unsigned) _get_word(&p);
486 MsgLen = _get_slice(&p, card->
msgbuf);
493 spin_lock(&card->
lock);
497 spin_unlock(&card->
lock);
505 ApplId = _get_word(&p);
506 NCCI = _get_word(&p);
507 WindowSize = _get_word(&p);
508 spin_lock(&card->
lock);
510 spin_unlock(&card->
lock);
515 ApplId = _get_word(&p);
516 NCCI = _get_word(&p);
518 if (NCCI != 0xffffffff) {
519 spin_lock(&card->
lock);
521 spin_unlock(&card->
lock);
526 #ifdef AVM_B1DMA_POLLDEBUG
529 if (!suppress_pollack)
550 ApplId = (unsigned) _get_word(&p);
551 MsgLen = _get_slice(&p, card->
msgbuf);
554 && (card->
msgbuf[MsgLen - 1] ==
'\n'
555 || card->
msgbuf[MsgLen - 1] ==
'\r')) {
556 card->
msgbuf[MsgLen - 1] = 0;
564 MsgLen = _get_slice(&p, card->
msgbuf);
567 && (card->
msgbuf[MsgLen - 1] ==
'\n'
568 || card->
msgbuf[MsgLen - 1] ==
'\r')) {
569 card->
msgbuf[MsgLen - 1] = 0;
584 static void b1dma_handle_interrupt(
avmcard *card)
589 spin_lock(&card->
lock);
593 spin_unlock(&card->
lock);
602 if ((status & RX_TC_INT) != 0) {
609 rxlen = (dma->
recvlen + 3) & ~3;
612 #ifdef AVM_B1DMA_DEBUG
619 spin_unlock(&card->
lock);
620 b1dma_handle_rx(card);
622 spin_lock(&card->
lock);
628 if ((status & TX_TC_INT) != 0) {
632 b1dma_dispatch_tx(card);
636 spin_unlock(&card->
lock);
643 b1dma_handle_interrupt(card);
649 static int b1dma_loaded(
avmcard *card)
653 unsigned long tout = 2;
656 for (stop = jiffies + tout * HZ;
time_before(jiffies, stop);) {
657 if (b1_tx_empty(base))
660 if (!b1_tx_empty(base)) {
661 printk(
KERN_ERR "%s: b1dma_loaded: tx err, corrupted t4 file ?\n",
666 for (stop = jiffies + tout * HZ;
time_before(jiffies, stop);) {
667 if (b1_rx_full(base)) {
671 printk(
KERN_ERR "%s: b1dma_loaded: got 0x%x, firmware not running in dword mode\n", card->
name, ans);
681 static void b1dma_send_init(
avmcard *card)
698 _put_word(&p, card->
cardnr - 1);
701 b1dma_queue_tx(card, skb);
728 if (!b1dma_loaded(card)) {
739 t1outp(card->
port, 0x07, 0x30);
740 t1outp(card->
port, 0x10, 0xF0);
748 b1dma_send_init(card);
764 spin_unlock_irqrestore(&card->
lock, flags);
781 if (want > 0) nconn = want;
796 _put_word(&p, 1024 * (nconn + 1));
797 _put_word(&p, nconn);
802 b1dma_queue_tx(card, skb);
817 spin_unlock_irqrestore(&card->
lock, flags);
833 b1dma_queue_tx(card, skb);
851 spin_unlock_irqrestore(&card->
lock, flags);
854 b1dma_queue_tx(card, skb);
861 static int b1dmactl_proc_show(
struct seq_file *
m,
void *
v)
879 case avm_m1: s =
"M1";
break;
880 case avm_m2: s =
"M2";
break;
881 case avm_t1isa: s =
"T1 ISA (HEMA)";
break;
883 case avm_c4: s =
"C4";
break;
884 case avm_c2: s =
"C2";
break;
885 default: s =
"???";
break;
891 seq_printf(m,
"%-16s %s\n",
"ver_cardtype", s);
900 (flag & 0x01) ?
" DSS1" :
"",
901 (flag & 0x02) ?
" CT1" :
"",
902 (flag & 0x04) ?
" VN3" :
"",
903 (flag & 0x08) ?
" NI1" :
"",
904 (flag & 0x10) ?
" AUSTEL" :
"",
905 (flag & 0x20) ?
" ESS" :
"",
906 (flag & 0x40) ?
" 1TR6" :
""
914 (flag & 0x01) ?
" point to point" :
"",
915 (flag & 0x02) ?
" point to multipoint" :
"",
916 (flag & 0x08) ?
" leased line without D-channel" :
"",
917 (flag & 0x04) ?
" leased line with D-channel" :
""
933 spin_unlock_irqrestore(&card->
lock, flags);
935 seq_printf(m,
"%-16s 0x%lx\n",
"csr (cached)", (
unsigned long)card->
csr);
936 seq_printf(m,
"%-16s 0x%lx\n",
"csr", (
unsigned long)csr);
937 seq_printf(m,
"%-16s %lu\n",
"txoff", (
unsigned long)txoff);
938 seq_printf(m,
"%-16s %lu\n",
"txlen", (
unsigned long)txlen);
939 seq_printf(m,
"%-16s %lu\n",
"rxoff", (
unsigned long)rxoff);
940 seq_printf(m,
"%-16s %lu\n",
"rxlen", (
unsigned long)rxlen);
952 .open = b1dmactl_proc_open,
972 static int __init b1dma_init(
void)
978 strlcpy(rev, p + 2,
sizeof(rev));
979 if ((p =
strchr(rev,
'$')) !=
NULL && p > rev)
989 static void __exit b1dma_exit(
void)