1 /* $Id: b1dma.c,v 1.1.2.3 2004/02/10 01:07:12 keil Exp $
3 * Common module for AVM B1 cards that support dma with AMCC
5 * Copyright 2000 by Carsten Paeth <calle@calle.de>
7 * This software may be used and distributed according to the terms
8 * of the GNU General Public License, incorporated herein by reference.
12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/skbuff.h>
15 #include <linux/delay.h>
17 #include <linux/interrupt.h>
18 #include <linux/ioport.h>
19 #include <linux/capi.h>
20 #include <linux/kernelcapi.h>
22 #include <linux/init.h>
23 #include <asm/uaccess.h>
24 #include <linux/netdevice.h>
25 #include <linux/isdn/capilli.h>
27 #include <linux/isdn/capicmd.h>
28 #include <linux/isdn/capiutil.h>
30 static char *revision
= "$Revision: 1.1.2.3 $";
32 #undef AVM_B1DMA_DEBUG
34 /* ------------------------------------------------------------- */
36 MODULE_DESCRIPTION("CAPI4Linux: DMA support for active AVM cards");
37 MODULE_AUTHOR("Carsten Paeth");
38 MODULE_LICENSE("GPL");
40 static int suppress_pollack
= 0;
41 module_param(suppress_pollack
, bool, 0);
43 /* ------------------------------------------------------------- */
45 static void b1dma_dispatch_tx(avmcard
*card
);
47 /* ------------------------------------------------------------- */
51 #define AMCC_RXPTR 0x24
52 #define AMCC_RXLEN 0x28
53 #define AMCC_TXPTR 0x2c
54 #define AMCC_TXLEN 0x30
56 #define AMCC_INTCSR 0x38
57 # define EN_READ_TC_INT 0x00008000L
58 # define EN_WRITE_TC_INT 0x00004000L
59 # define EN_TX_TC_INT EN_READ_TC_INT
60 # define EN_RX_TC_INT EN_WRITE_TC_INT
61 # define AVM_FLAG 0x30000000L
63 # define ANY_S5933_INT 0x00800000L
64 # define READ_TC_INT 0x00080000L
65 # define WRITE_TC_INT 0x00040000L
66 # define TX_TC_INT READ_TC_INT
67 # define RX_TC_INT WRITE_TC_INT
68 # define MASTER_ABORT_INT 0x00100000L
69 # define TARGET_ABORT_INT 0x00200000L
70 # define BUS_MASTER_INT 0x00200000L
71 # define ALL_INT 0x000C0000L
73 #define AMCC_MCSR 0x3c
74 # define A2P_HI_PRIORITY 0x00000100L
75 # define EN_A2P_TRANSFERS 0x00000400L
76 # define P2A_HI_PRIORITY 0x00001000L
77 # define EN_P2A_TRANSFERS 0x00004000L
78 # define RESET_A2P_FLAGS 0x04000000L
79 # define RESET_P2A_FLAGS 0x02000000L
81 /* ------------------------------------------------------------- */
83 static inline void b1dma_writel(avmcard
*card
, u32 value
, int off
)
85 writel(value
, card
->mbase
+ off
);
88 static inline u32
b1dma_readl(avmcard
*card
, int off
)
90 return readl(card
->mbase
+ off
);
93 /* ------------------------------------------------------------- */
95 static inline int b1dma_tx_empty(unsigned int port
)
97 return inb(port
+ 0x03) & 0x1;
100 static inline int b1dma_rx_full(unsigned int port
)
102 return inb(port
+ 0x02) & 0x1;
105 static int b1dma_tolink(avmcard
*card
, void *buf
, unsigned int len
)
107 unsigned long stop
= jiffies
+ 1 * HZ
; /* maximum wait time 1 sec */
108 unsigned char *s
= (unsigned char *)buf
;
110 while ( !b1dma_tx_empty(card
->port
)
111 && time_before(jiffies
, stop
));
112 if (!b1dma_tx_empty(card
->port
))
114 t1outp(card
->port
, 0x01, *s
++);
119 static int b1dma_fromlink(avmcard
*card
, void *buf
, unsigned int len
)
121 unsigned long stop
= jiffies
+ 1 * HZ
; /* maximum wait time 1 sec */
122 unsigned char *s
= (unsigned char *)buf
;
124 while ( !b1dma_rx_full(card
->port
)
125 && time_before(jiffies
, stop
));
126 if (!b1dma_rx_full(card
->port
))
128 *s
++ = t1inp(card
->port
, 0x00);
133 static int WriteReg(avmcard
*card
, u32 reg
, u8 val
)
136 if ( b1dma_tolink(card
, &cmd
, 1) == 0
137 && b1dma_tolink(card
, ®
, 4) == 0) {
139 return b1dma_tolink(card
, &tmp
, 4);
144 static u8
ReadReg(avmcard
*card
, u32 reg
)
147 if ( b1dma_tolink(card
, &cmd
, 1) == 0
148 && b1dma_tolink(card
, ®
, 4) == 0) {
150 if (b1dma_fromlink(card
, &tmp
, 4) == 0)
156 /* ------------------------------------------------------------- */
158 static inline void _put_byte(void **pp
, u8 val
)
165 static inline void _put_word(void **pp
, u32 val
)
169 *s
++ = (val
>> 8) & 0xff;
170 *s
++ = (val
>> 16) & 0xff;
171 *s
++ = (val
>> 24) & 0xff;
175 static inline void _put_slice(void **pp
, unsigned char *dp
, unsigned int len
)
180 _put_byte(pp
, *dp
++);
183 static inline u8
_get_byte(void **pp
)
192 static inline u32
_get_word(void **pp
)
204 static inline u32
_get_slice(void **pp
, unsigned char *dp
)
208 len
= i
= _get_word(pp
);
209 while (i
-- > 0) *dp
++ = _get_byte(pp
);
213 /* ------------------------------------------------------------- */
215 void b1dma_reset(avmcard
*card
)
218 b1dma_writel(card
, card
->csr
, AMCC_INTCSR
);
219 b1dma_writel(card
, 0, AMCC_MCSR
);
220 b1dma_writel(card
, 0, AMCC_RXLEN
);
221 b1dma_writel(card
, 0, AMCC_TXLEN
);
223 t1outp(card
->port
, 0x10, 0x00);
224 t1outp(card
->port
, 0x07, 0x00);
226 b1dma_writel(card
, 0, AMCC_MCSR
);
228 b1dma_writel(card
, 0x0f000000, AMCC_MCSR
); /* reset all */
230 b1dma_writel(card
, 0, AMCC_MCSR
);
231 if (card
->cardtype
== avm_t1pci
)
237 /* ------------------------------------------------------------- */
239 static int b1dma_detect(avmcard
*card
)
241 b1dma_writel(card
, 0, AMCC_MCSR
);
243 b1dma_writel(card
, 0x0f000000, AMCC_MCSR
); /* reset all */
245 b1dma_writel(card
, 0, AMCC_MCSR
);
248 b1dma_writel(card
, 0, AMCC_RXLEN
);
249 b1dma_writel(card
, 0, AMCC_TXLEN
);
251 b1dma_writel(card
, card
->csr
, AMCC_INTCSR
);
253 if (b1dma_readl(card
, AMCC_MCSR
) != 0x000000E6)
256 b1dma_writel(card
, 0xffffffff, AMCC_RXPTR
);
257 b1dma_writel(card
, 0xffffffff, AMCC_TXPTR
);
258 if ( b1dma_readl(card
, AMCC_RXPTR
) != 0xfffffffc
259 || b1dma_readl(card
, AMCC_TXPTR
) != 0xfffffffc)
262 b1dma_writel(card
, 0x0, AMCC_RXPTR
);
263 b1dma_writel(card
, 0x0, AMCC_TXPTR
);
264 if ( b1dma_readl(card
, AMCC_RXPTR
) != 0x0
265 || b1dma_readl(card
, AMCC_TXPTR
) != 0x0)
268 t1outp(card
->port
, 0x10, 0x00);
269 t1outp(card
->port
, 0x07, 0x00);
271 t1outp(card
->port
, 0x02, 0x02);
272 t1outp(card
->port
, 0x03, 0x02);
274 if ( (t1inp(card
->port
, 0x02) & 0xFE) != 0x02
275 || t1inp(card
->port
, 0x3) != 0x03)
278 t1outp(card
->port
, 0x02, 0x00);
279 t1outp(card
->port
, 0x03, 0x00);
281 if ( (t1inp(card
->port
, 0x02) & 0xFE) != 0x00
282 || t1inp(card
->port
, 0x3) != 0x01)
288 int t1pci_detect(avmcard
*card
)
292 if ((ret
= b1dma_detect(card
)) != 0)
295 /* Transputer test */
297 if ( WriteReg(card
, 0x80001000, 0x11) != 0
298 || WriteReg(card
, 0x80101000, 0x22) != 0
299 || WriteReg(card
, 0x80201000, 0x33) != 0
300 || WriteReg(card
, 0x80301000, 0x44) != 0)
303 if ( ReadReg(card
, 0x80001000) != 0x11
304 || ReadReg(card
, 0x80101000) != 0x22
305 || ReadReg(card
, 0x80201000) != 0x33
306 || ReadReg(card
, 0x80301000) != 0x44)
309 if ( WriteReg(card
, 0x80001000, 0x55) != 0
310 || WriteReg(card
, 0x80101000, 0x66) != 0
311 || WriteReg(card
, 0x80201000, 0x77) != 0
312 || WriteReg(card
, 0x80301000, 0x88) != 0)
315 if ( ReadReg(card
, 0x80001000) != 0x55
316 || ReadReg(card
, 0x80101000) != 0x66
317 || ReadReg(card
, 0x80201000) != 0x77
318 || ReadReg(card
, 0x80301000) != 0x88)
324 int b1pciv4_detect(avmcard
*card
)
328 if ((ret
= b1dma_detect(card
)) != 0)
331 for (i
=0; i
< 5 ; i
++) {
332 if (WriteReg(card
, 0x80A00000, 0x21) != 0)
334 if ((ReadReg(card
, 0x80A00000) & 0x01) != 0x01)
337 for (i
=0; i
< 5 ; i
++) {
338 if (WriteReg(card
, 0x80A00000, 0x20) != 0)
340 if ((ReadReg(card
, 0x80A00000) & 0x01) != 0x00)
347 static void b1dma_queue_tx(avmcard
*card
, struct sk_buff
*skb
)
351 spin_lock_irqsave(&card
->lock
, flags
);
353 skb_queue_tail(&card
->dma
->send_queue
, skb
);
355 if (!(card
->csr
& EN_TX_TC_INT
)) {
356 b1dma_dispatch_tx(card
);
357 b1dma_writel(card
, card
->csr
, AMCC_INTCSR
);
360 spin_unlock_irqrestore(&card
->lock
, flags
);
363 /* ------------------------------------------------------------- */
365 static void b1dma_dispatch_tx(avmcard
*card
)
367 avmcard_dmainfo
*dma
= card
->dma
;
374 skb
= skb_dequeue(&dma
->send_queue
);
376 len
= CAPIMSG_LEN(skb
->data
);
379 cmd
= CAPIMSG_COMMAND(skb
->data
);
380 subcmd
= CAPIMSG_SUBCOMMAND(skb
->data
);
382 p
= dma
->sendbuf
.dmabuf
;
384 if (CAPICMD(cmd
, subcmd
) == CAPI_DATA_B3_REQ
) {
385 u16 dlen
= CAPIMSG_DATALEN(skb
->data
);
386 _put_byte(&p
, SEND_DATA_B3_REQ
);
387 _put_slice(&p
, skb
->data
, len
);
388 _put_slice(&p
, skb
->data
+ len
, dlen
);
390 _put_byte(&p
, SEND_MESSAGE
);
391 _put_slice(&p
, skb
->data
, len
);
393 txlen
= (u8
*)p
- (u8
*)dma
->sendbuf
.dmabuf
;
394 #ifdef AVM_B1DMA_DEBUG
395 printk(KERN_DEBUG
"tx: put msg len=%d\n", txlen
);
399 #ifdef AVM_B1DMA_POLLDEBUG
400 if (skb
->data
[2] == SEND_POLLACK
)
401 printk(KERN_INFO
"%s: send ack\n", card
->name
);
403 #ifdef AVM_B1DMA_DEBUG
404 printk(KERN_DEBUG
"tx: put 0x%x len=%d\n",
405 skb
->data
[2], txlen
);
407 skb_copy_from_linear_data_offset(skb
, 2, dma
->sendbuf
.dmabuf
,
410 txlen
= (txlen
+ 3) & ~3;
412 b1dma_writel(card
, dma
->sendbuf
.dmaaddr
, AMCC_TXPTR
);
413 b1dma_writel(card
, txlen
, AMCC_TXLEN
);
415 card
->csr
|= EN_TX_TC_INT
;
417 dev_kfree_skb_any(skb
);
420 /* ------------------------------------------------------------- */
422 static void queue_pollack(avmcard
*card
)
427 skb
= alloc_skb(3, GFP_ATOMIC
);
429 printk(KERN_CRIT
"%s: no memory, lost poll ack\n",
436 _put_byte(&p
, SEND_POLLACK
);
437 skb_put(skb
, (u8
*)p
- (u8
*)skb
->data
);
439 b1dma_queue_tx(card
, skb
);
442 /* ------------------------------------------------------------- */
444 static void b1dma_handle_rx(avmcard
*card
)
446 avmctrl_info
*cinfo
= &card
->ctrlinfo
[0];
447 avmcard_dmainfo
*dma
= card
->dma
;
448 struct capi_ctr
*ctrl
= &cinfo
->capi_ctrl
;
450 void *p
= dma
->recvbuf
.dmabuf
+4;
451 u32 ApplId
, MsgLen
, DataB3Len
, NCCI
, WindowSize
;
452 u8 b1cmd
= _get_byte(&p
);
454 #ifdef AVM_B1DMA_DEBUG
455 printk(KERN_DEBUG
"rx: 0x%x %lu\n", b1cmd
, (unsigned long)dma
->recvlen
);
459 case RECEIVE_DATA_B3_IND
:
461 ApplId
= (unsigned) _get_word(&p
);
462 MsgLen
= _get_slice(&p
, card
->msgbuf
);
463 DataB3Len
= _get_slice(&p
, card
->databuf
);
465 if (MsgLen
< 30) { /* not CAPI 64Bit */
466 memset(card
->msgbuf
+MsgLen
, 0, 30-MsgLen
);
468 CAPIMSG_SETLEN(card
->msgbuf
, 30);
470 if (!(skb
= alloc_skb(DataB3Len
+MsgLen
, GFP_ATOMIC
))) {
471 printk(KERN_ERR
"%s: incoming packet dropped\n",
474 memcpy(skb_put(skb
, MsgLen
), card
->msgbuf
, MsgLen
);
475 memcpy(skb_put(skb
, DataB3Len
), card
->databuf
, DataB3Len
);
476 capi_ctr_handle_message(ctrl
, ApplId
, skb
);
480 case RECEIVE_MESSAGE
:
482 ApplId
= (unsigned) _get_word(&p
);
483 MsgLen
= _get_slice(&p
, card
->msgbuf
);
484 if (!(skb
= alloc_skb(MsgLen
, GFP_ATOMIC
))) {
485 printk(KERN_ERR
"%s: incoming packet dropped\n",
488 memcpy(skb_put(skb
, MsgLen
), card
->msgbuf
, MsgLen
);
489 if (CAPIMSG_CMD(skb
->data
) == CAPI_DATA_B3_CONF
) {
490 spin_lock(&card
->lock
);
491 capilib_data_b3_conf(&cinfo
->ncci_head
, ApplId
,
492 CAPIMSG_NCCI(skb
->data
),
493 CAPIMSG_MSGID(skb
->data
));
494 spin_unlock(&card
->lock
);
496 capi_ctr_handle_message(ctrl
, ApplId
, skb
);
500 case RECEIVE_NEW_NCCI
:
502 ApplId
= _get_word(&p
);
503 NCCI
= _get_word(&p
);
504 WindowSize
= _get_word(&p
);
505 spin_lock(&card
->lock
);
506 capilib_new_ncci(&cinfo
->ncci_head
, ApplId
, NCCI
, WindowSize
);
507 spin_unlock(&card
->lock
);
510 case RECEIVE_FREE_NCCI
:
512 ApplId
= _get_word(&p
);
513 NCCI
= _get_word(&p
);
515 if (NCCI
!= 0xffffffff) {
516 spin_lock(&card
->lock
);
517 capilib_free_ncci(&cinfo
->ncci_head
, ApplId
, NCCI
);
518 spin_unlock(&card
->lock
);
523 #ifdef AVM_B1DMA_POLLDEBUG
524 printk(KERN_INFO
"%s: receive poll\n", card
->name
);
526 if (!suppress_pollack
)
528 capi_ctr_resume_output(ctrl
);
532 capi_ctr_suspend_output(ctrl
);
537 cinfo
->versionlen
= _get_slice(&p
, cinfo
->versionbuf
);
538 b1_parse_version(cinfo
);
539 printk(KERN_INFO
"%s: %s-card (%s) now active\n",
541 cinfo
->version
[VER_CARDTYPE
],
542 cinfo
->version
[VER_DRIVER
]);
543 capi_ctr_ready(ctrl
);
546 case RECEIVE_TASK_READY
:
547 ApplId
= (unsigned) _get_word(&p
);
548 MsgLen
= _get_slice(&p
, card
->msgbuf
);
549 card
->msgbuf
[MsgLen
] = 0;
551 && ( card
->msgbuf
[MsgLen
-1] == '\n'
552 || card
->msgbuf
[MsgLen
-1] == '\r')) {
553 card
->msgbuf
[MsgLen
-1] = 0;
556 printk(KERN_INFO
"%s: task %d \"%s\" ready.\n",
557 card
->name
, ApplId
, card
->msgbuf
);
560 case RECEIVE_DEBUGMSG
:
561 MsgLen
= _get_slice(&p
, card
->msgbuf
);
562 card
->msgbuf
[MsgLen
] = 0;
564 && ( card
->msgbuf
[MsgLen
-1] == '\n'
565 || card
->msgbuf
[MsgLen
-1] == '\r')) {
566 card
->msgbuf
[MsgLen
-1] = 0;
569 printk(KERN_INFO
"%s: DEBUG: %s\n", card
->name
, card
->msgbuf
);
573 printk(KERN_ERR
"%s: b1dma_interrupt: 0x%x ???\n",
579 /* ------------------------------------------------------------- */
581 static void b1dma_handle_interrupt(avmcard
*card
)
586 spin_lock(&card
->lock
);
588 status
= b1dma_readl(card
, AMCC_INTCSR
);
589 if ((status
& ANY_S5933_INT
) == 0) {
590 spin_unlock(&card
->lock
);
594 newcsr
= card
->csr
| (status
& ALL_INT
);
595 if (status
& TX_TC_INT
) newcsr
&= ~EN_TX_TC_INT
;
596 if (status
& RX_TC_INT
) newcsr
&= ~EN_RX_TC_INT
;
597 b1dma_writel(card
, newcsr
, AMCC_INTCSR
);
599 if ((status
& RX_TC_INT
) != 0) {
600 struct avmcard_dmainfo
*dma
= card
->dma
;
602 if (card
->dma
->recvlen
== 0) {
603 rxlen
= b1dma_readl(card
, AMCC_RXLEN
);
605 dma
->recvlen
= *((u32
*)dma
->recvbuf
.dmabuf
);
606 rxlen
= (dma
->recvlen
+ 3) & ~3;
607 b1dma_writel(card
, dma
->recvbuf
.dmaaddr
+4, AMCC_RXPTR
);
608 b1dma_writel(card
, rxlen
, AMCC_RXLEN
);
609 #ifdef AVM_B1DMA_DEBUG
611 printk(KERN_ERR
"%s: rx not complete (%d).\n",
616 spin_unlock(&card
->lock
);
617 b1dma_handle_rx(card
);
619 spin_lock(&card
->lock
);
620 b1dma_writel(card
, dma
->recvbuf
.dmaaddr
, AMCC_RXPTR
);
621 b1dma_writel(card
, 4, AMCC_RXLEN
);
625 if ((status
& TX_TC_INT
) != 0) {
626 if (skb_queue_empty(&card
->dma
->send_queue
))
627 card
->csr
&= ~EN_TX_TC_INT
;
629 b1dma_dispatch_tx(card
);
631 b1dma_writel(card
, card
->csr
, AMCC_INTCSR
);
633 spin_unlock(&card
->lock
);
636 irqreturn_t
b1dma_interrupt(int interrupt
, void *devptr
)
638 avmcard
*card
= devptr
;
640 b1dma_handle_interrupt(card
);
644 /* ------------------------------------------------------------- */
646 static int b1dma_loaded(avmcard
*card
)
650 unsigned long tout
= 2;
651 unsigned int base
= card
->port
;
653 for (stop
= jiffies
+ tout
* HZ
; time_before(jiffies
, stop
);) {
654 if (b1_tx_empty(base
))
657 if (!b1_tx_empty(base
)) {
658 printk(KERN_ERR
"%s: b1dma_loaded: tx err, corrupted t4 file ?\n",
662 b1_put_byte(base
, SEND_POLLACK
);
663 for (stop
= jiffies
+ tout
* HZ
; time_before(jiffies
, stop
);) {
664 if (b1_rx_full(base
)) {
665 if ((ans
= b1_get_byte(base
)) == RECEIVE_POLLDWORD
) {
668 printk(KERN_ERR
"%s: b1dma_loaded: got 0x%x, firmware not running in dword mode\n", card
->name
, ans
);
672 printk(KERN_ERR
"%s: b1dma_loaded: firmware not running\n", card
->name
);
676 /* ------------------------------------------------------------- */
678 static void b1dma_send_init(avmcard
*card
)
683 skb
= alloc_skb(15, GFP_ATOMIC
);
685 printk(KERN_CRIT
"%s: no memory, lost register appl.\n",
692 _put_byte(&p
, SEND_INIT
);
693 _put_word(&p
, CAPI_MAXAPPL
);
694 _put_word(&p
, AVM_NCCI_PER_CHANNEL
*30);
695 _put_word(&p
, card
->cardnr
- 1);
696 skb_put(skb
, (u8
*)p
- (u8
*)skb
->data
);
698 b1dma_queue_tx(card
, skb
);
701 int b1dma_load_firmware(struct capi_ctr
*ctrl
, capiloaddata
*data
)
703 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
704 avmcard
*card
= cinfo
->card
;
709 if ((retval
= b1_load_t4file(card
, &data
->firmware
))) {
711 printk(KERN_ERR
"%s: failed to load t4file!!\n",
716 if (data
->configuration
.len
> 0 && data
->configuration
.data
) {
717 if ((retval
= b1_load_config(card
, &data
->configuration
))) {
719 printk(KERN_ERR
"%s: failed to load config!!\n",
725 if (!b1dma_loaded(card
)) {
727 printk(KERN_ERR
"%s: failed to load t4file.\n", card
->name
);
731 card
->csr
= AVM_FLAG
;
732 b1dma_writel(card
, card
->csr
, AMCC_INTCSR
);
733 b1dma_writel(card
, EN_A2P_TRANSFERS
|EN_P2A_TRANSFERS
|A2P_HI_PRIORITY
|
734 P2A_HI_PRIORITY
|RESET_A2P_FLAGS
|RESET_P2A_FLAGS
,
736 t1outp(card
->port
, 0x07, 0x30);
737 t1outp(card
->port
, 0x10, 0xF0);
739 card
->dma
->recvlen
= 0;
740 b1dma_writel(card
, card
->dma
->recvbuf
.dmaaddr
, AMCC_RXPTR
);
741 b1dma_writel(card
, 4, AMCC_RXLEN
);
742 card
->csr
|= EN_RX_TC_INT
;
743 b1dma_writel(card
, card
->csr
, AMCC_INTCSR
);
745 b1dma_send_init(card
);
750 void b1dma_reset_ctr(struct capi_ctr
*ctrl
)
752 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
753 avmcard
*card
= cinfo
->card
;
756 spin_lock_irqsave(&card
->lock
, flags
);
759 memset(cinfo
->version
, 0, sizeof(cinfo
->version
));
760 capilib_release(&cinfo
->ncci_head
);
761 spin_unlock_irqrestore(&card
->lock
, flags
);
765 /* ------------------------------------------------------------- */
767 void b1dma_register_appl(struct capi_ctr
*ctrl
,
769 capi_register_params
*rp
)
771 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
772 avmcard
*card
= cinfo
->card
;
774 int want
= rp
->level3cnt
;
778 if (want
> 0) nconn
= want
;
779 else nconn
= ctrl
->profile
.nbchannel
* -want
;
780 if (nconn
== 0) nconn
= ctrl
->profile
.nbchannel
;
782 skb
= alloc_skb(23, GFP_ATOMIC
);
784 printk(KERN_CRIT
"%s: no memory, lost register appl.\n",
791 _put_byte(&p
, SEND_REGISTER
);
793 _put_word(&p
, 1024 * (nconn
+1));
794 _put_word(&p
, nconn
);
795 _put_word(&p
, rp
->datablkcnt
);
796 _put_word(&p
, rp
->datablklen
);
797 skb_put(skb
, (u8
*)p
- (u8
*)skb
->data
);
799 b1dma_queue_tx(card
, skb
);
802 /* ------------------------------------------------------------- */
804 void b1dma_release_appl(struct capi_ctr
*ctrl
, u16 appl
)
806 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
807 avmcard
*card
= cinfo
->card
;
812 spin_lock_irqsave(&card
->lock
, flags
);
813 capilib_release_appl(&cinfo
->ncci_head
, appl
);
814 spin_unlock_irqrestore(&card
->lock
, flags
);
816 skb
= alloc_skb(7, GFP_ATOMIC
);
818 printk(KERN_CRIT
"%s: no memory, lost release appl.\n",
825 _put_byte(&p
, SEND_RELEASE
);
828 skb_put(skb
, (u8
*)p
- (u8
*)skb
->data
);
830 b1dma_queue_tx(card
, skb
);
833 /* ------------------------------------------------------------- */
835 u16
b1dma_send_message(struct capi_ctr
*ctrl
, struct sk_buff
*skb
)
837 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
838 avmcard
*card
= cinfo
->card
;
839 u16 retval
= CAPI_NOERROR
;
841 if (CAPIMSG_CMD(skb
->data
) == CAPI_DATA_B3_REQ
) {
843 spin_lock_irqsave(&card
->lock
, flags
);
844 retval
= capilib_data_b3_req(&cinfo
->ncci_head
,
845 CAPIMSG_APPID(skb
->data
),
846 CAPIMSG_NCCI(skb
->data
),
847 CAPIMSG_MSGID(skb
->data
));
848 spin_unlock_irqrestore(&card
->lock
, flags
);
850 if (retval
== CAPI_NOERROR
)
851 b1dma_queue_tx(card
, skb
);
856 /* ------------------------------------------------------------- */
858 int b1dmactl_read_proc(char *page
, char **start
, off_t off
,
859 int count
, int *eof
, struct capi_ctr
*ctrl
)
861 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
862 avmcard
*card
= cinfo
->card
;
866 u32 txoff
, txlen
, rxoff
, rxlen
, csr
;
869 len
+= sprintf(page
+len
, "%-16s %s\n", "name", card
->name
);
870 len
+= sprintf(page
+len
, "%-16s 0x%x\n", "io", card
->port
);
871 len
+= sprintf(page
+len
, "%-16s %d\n", "irq", card
->irq
);
872 len
+= sprintf(page
+len
, "%-16s 0x%lx\n", "membase", card
->membase
);
873 switch (card
->cardtype
) {
874 case avm_b1isa
: s
= "B1 ISA"; break;
875 case avm_b1pci
: s
= "B1 PCI"; break;
876 case avm_b1pcmcia
: s
= "B1 PCMCIA"; break;
877 case avm_m1
: s
= "M1"; break;
878 case avm_m2
: s
= "M2"; break;
879 case avm_t1isa
: s
= "T1 ISA (HEMA)"; break;
880 case avm_t1pci
: s
= "T1 PCI"; break;
881 case avm_c4
: s
= "C4"; break;
882 case avm_c2
: s
= "C2"; break;
883 default: s
= "???"; break;
885 len
+= sprintf(page
+len
, "%-16s %s\n", "type", s
);
886 if ((s
= cinfo
->version
[VER_DRIVER
]) != NULL
)
887 len
+= sprintf(page
+len
, "%-16s %s\n", "ver_driver", s
);
888 if ((s
= cinfo
->version
[VER_CARDTYPE
]) != NULL
)
889 len
+= sprintf(page
+len
, "%-16s %s\n", "ver_cardtype", s
);
890 if ((s
= cinfo
->version
[VER_SERIAL
]) != NULL
)
891 len
+= sprintf(page
+len
, "%-16s %s\n", "ver_serial", s
);
893 if (card
->cardtype
!= avm_m1
) {
894 flag
= ((u8
*)(ctrl
->profile
.manu
))[3];
896 len
+= sprintf(page
+len
, "%-16s%s%s%s%s%s%s%s\n",
898 (flag
& 0x01) ? " DSS1" : "",
899 (flag
& 0x02) ? " CT1" : "",
900 (flag
& 0x04) ? " VN3" : "",
901 (flag
& 0x08) ? " NI1" : "",
902 (flag
& 0x10) ? " AUSTEL" : "",
903 (flag
& 0x20) ? " ESS" : "",
904 (flag
& 0x40) ? " 1TR6" : ""
907 if (card
->cardtype
!= avm_m1
) {
908 flag
= ((u8
*)(ctrl
->profile
.manu
))[5];
910 len
+= sprintf(page
+len
, "%-16s%s%s%s%s\n",
912 (flag
& 0x01) ? " point to point" : "",
913 (flag
& 0x02) ? " point to multipoint" : "",
914 (flag
& 0x08) ? " leased line without D-channel" : "",
915 (flag
& 0x04) ? " leased line with D-channel" : ""
918 len
+= sprintf(page
+len
, "%-16s %s\n", "cardname", cinfo
->cardname
);
921 spin_lock_irqsave(&card
->lock
, flags
);
923 txoff
= (dma_addr_t
)b1dma_readl(card
, AMCC_TXPTR
)-card
->dma
->sendbuf
.dmaaddr
;
924 txlen
= b1dma_readl(card
, AMCC_TXLEN
);
926 rxoff
= (dma_addr_t
)b1dma_readl(card
, AMCC_RXPTR
)-card
->dma
->recvbuf
.dmaaddr
;
927 rxlen
= b1dma_readl(card
, AMCC_RXLEN
);
929 csr
= b1dma_readl(card
, AMCC_INTCSR
);
931 spin_unlock_irqrestore(&card
->lock
, flags
);
933 len
+= sprintf(page
+len
, "%-16s 0x%lx\n",
934 "csr (cached)", (unsigned long)card
->csr
);
935 len
+= sprintf(page
+len
, "%-16s 0x%lx\n",
936 "csr", (unsigned long)csr
);
937 len
+= sprintf(page
+len
, "%-16s %lu\n",
938 "txoff", (unsigned long)txoff
);
939 len
+= sprintf(page
+len
, "%-16s %lu\n",
940 "txlen", (unsigned long)txlen
);
941 len
+= sprintf(page
+len
, "%-16s %lu\n",
942 "rxoff", (unsigned long)rxoff
);
943 len
+= sprintf(page
+len
, "%-16s %lu\n",
944 "rxlen", (unsigned long)rxlen
);
946 if (off
+count
>= len
)
951 return ((count
< len
-off
) ? count
: len
-off
);
954 /* ------------------------------------------------------------- */
956 EXPORT_SYMBOL(b1dma_reset
);
957 EXPORT_SYMBOL(t1pci_detect
);
958 EXPORT_SYMBOL(b1pciv4_detect
);
959 EXPORT_SYMBOL(b1dma_interrupt
);
961 EXPORT_SYMBOL(b1dma_load_firmware
);
962 EXPORT_SYMBOL(b1dma_reset_ctr
);
963 EXPORT_SYMBOL(b1dma_register_appl
);
964 EXPORT_SYMBOL(b1dma_release_appl
);
965 EXPORT_SYMBOL(b1dma_send_message
);
966 EXPORT_SYMBOL(b1dmactl_read_proc
);
968 static int __init
b1dma_init(void)
973 if ((p
= strchr(revision
, ':')) != NULL
&& p
[1]) {
974 strlcpy(rev
, p
+ 2, sizeof(rev
));
975 if ((p
= strchr(rev
, '$')) != NULL
&& p
> rev
)
980 printk(KERN_INFO
"b1dma: revision %s\n", rev
);
985 static void __exit
b1dma_exit(void)
989 module_init(b1dma_init
);
990 module_exit(b1dma_exit
);