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/proc_fs.h>
15 #include <linux/seq_file.h>
16 #include <linux/skbuff.h>
17 #include <linux/delay.h>
19 #include <linux/interrupt.h>
20 #include <linux/ioport.h>
21 #include <linux/capi.h>
22 #include <linux/kernelcapi.h>
24 #include <linux/init.h>
25 #include <asm/uaccess.h>
26 #include <linux/netdevice.h>
27 #include <linux/isdn/capilli.h>
29 #include <linux/isdn/capicmd.h>
30 #include <linux/isdn/capiutil.h>
32 static char *revision
= "$Revision: 1.1.2.3 $";
34 #undef AVM_B1DMA_DEBUG
36 /* ------------------------------------------------------------- */
38 MODULE_DESCRIPTION("CAPI4Linux: DMA support for active AVM cards");
39 MODULE_AUTHOR("Carsten Paeth");
40 MODULE_LICENSE("GPL");
42 static int suppress_pollack
= 0;
43 module_param(suppress_pollack
, bool, 0);
45 /* ------------------------------------------------------------- */
47 static void b1dma_dispatch_tx(avmcard
*card
);
49 /* ------------------------------------------------------------- */
53 #define AMCC_RXPTR 0x24
54 #define AMCC_RXLEN 0x28
55 #define AMCC_TXPTR 0x2c
56 #define AMCC_TXLEN 0x30
58 #define AMCC_INTCSR 0x38
59 # define EN_READ_TC_INT 0x00008000L
60 # define EN_WRITE_TC_INT 0x00004000L
61 # define EN_TX_TC_INT EN_READ_TC_INT
62 # define EN_RX_TC_INT EN_WRITE_TC_INT
63 # define AVM_FLAG 0x30000000L
65 # define ANY_S5933_INT 0x00800000L
66 # define READ_TC_INT 0x00080000L
67 # define WRITE_TC_INT 0x00040000L
68 # define TX_TC_INT READ_TC_INT
69 # define RX_TC_INT WRITE_TC_INT
70 # define MASTER_ABORT_INT 0x00100000L
71 # define TARGET_ABORT_INT 0x00200000L
72 # define BUS_MASTER_INT 0x00200000L
73 # define ALL_INT 0x000C0000L
75 #define AMCC_MCSR 0x3c
76 # define A2P_HI_PRIORITY 0x00000100L
77 # define EN_A2P_TRANSFERS 0x00000400L
78 # define P2A_HI_PRIORITY 0x00001000L
79 # define EN_P2A_TRANSFERS 0x00004000L
80 # define RESET_A2P_FLAGS 0x04000000L
81 # define RESET_P2A_FLAGS 0x02000000L
83 /* ------------------------------------------------------------- */
85 static inline void b1dma_writel(avmcard
*card
, u32 value
, int off
)
87 writel(value
, card
->mbase
+ off
);
90 static inline u32
b1dma_readl(avmcard
*card
, int off
)
92 return readl(card
->mbase
+ off
);
95 /* ------------------------------------------------------------- */
97 static inline int b1dma_tx_empty(unsigned int port
)
99 return inb(port
+ 0x03) & 0x1;
102 static inline int b1dma_rx_full(unsigned int port
)
104 return inb(port
+ 0x02) & 0x1;
107 static int b1dma_tolink(avmcard
*card
, void *buf
, unsigned int len
)
109 unsigned long stop
= jiffies
+ 1 * HZ
; /* maximum wait time 1 sec */
110 unsigned char *s
= (unsigned char *)buf
;
112 while ( !b1dma_tx_empty(card
->port
)
113 && time_before(jiffies
, stop
));
114 if (!b1dma_tx_empty(card
->port
))
116 t1outp(card
->port
, 0x01, *s
++);
121 static int b1dma_fromlink(avmcard
*card
, void *buf
, unsigned int len
)
123 unsigned long stop
= jiffies
+ 1 * HZ
; /* maximum wait time 1 sec */
124 unsigned char *s
= (unsigned char *)buf
;
126 while ( !b1dma_rx_full(card
->port
)
127 && time_before(jiffies
, stop
));
128 if (!b1dma_rx_full(card
->port
))
130 *s
++ = t1inp(card
->port
, 0x00);
135 static int WriteReg(avmcard
*card
, u32 reg
, u8 val
)
138 if ( b1dma_tolink(card
, &cmd
, 1) == 0
139 && b1dma_tolink(card
, ®
, 4) == 0) {
141 return b1dma_tolink(card
, &tmp
, 4);
146 static u8
ReadReg(avmcard
*card
, u32 reg
)
149 if ( b1dma_tolink(card
, &cmd
, 1) == 0
150 && b1dma_tolink(card
, ®
, 4) == 0) {
152 if (b1dma_fromlink(card
, &tmp
, 4) == 0)
158 /* ------------------------------------------------------------- */
160 static inline void _put_byte(void **pp
, u8 val
)
167 static inline void _put_word(void **pp
, u32 val
)
171 *s
++ = (val
>> 8) & 0xff;
172 *s
++ = (val
>> 16) & 0xff;
173 *s
++ = (val
>> 24) & 0xff;
177 static inline void _put_slice(void **pp
, unsigned char *dp
, unsigned int len
)
182 _put_byte(pp
, *dp
++);
185 static inline u8
_get_byte(void **pp
)
194 static inline u32
_get_word(void **pp
)
206 static inline u32
_get_slice(void **pp
, unsigned char *dp
)
210 len
= i
= _get_word(pp
);
211 while (i
-- > 0) *dp
++ = _get_byte(pp
);
215 /* ------------------------------------------------------------- */
217 void b1dma_reset(avmcard
*card
)
220 b1dma_writel(card
, card
->csr
, AMCC_INTCSR
);
221 b1dma_writel(card
, 0, AMCC_MCSR
);
222 b1dma_writel(card
, 0, AMCC_RXLEN
);
223 b1dma_writel(card
, 0, AMCC_TXLEN
);
225 t1outp(card
->port
, 0x10, 0x00);
226 t1outp(card
->port
, 0x07, 0x00);
228 b1dma_writel(card
, 0, AMCC_MCSR
);
230 b1dma_writel(card
, 0x0f000000, AMCC_MCSR
); /* reset all */
232 b1dma_writel(card
, 0, AMCC_MCSR
);
233 if (card
->cardtype
== avm_t1pci
)
239 /* ------------------------------------------------------------- */
241 static int b1dma_detect(avmcard
*card
)
243 b1dma_writel(card
, 0, AMCC_MCSR
);
245 b1dma_writel(card
, 0x0f000000, AMCC_MCSR
); /* reset all */
247 b1dma_writel(card
, 0, AMCC_MCSR
);
250 b1dma_writel(card
, 0, AMCC_RXLEN
);
251 b1dma_writel(card
, 0, AMCC_TXLEN
);
253 b1dma_writel(card
, card
->csr
, AMCC_INTCSR
);
255 if (b1dma_readl(card
, AMCC_MCSR
) != 0x000000E6)
258 b1dma_writel(card
, 0xffffffff, AMCC_RXPTR
);
259 b1dma_writel(card
, 0xffffffff, AMCC_TXPTR
);
260 if ( b1dma_readl(card
, AMCC_RXPTR
) != 0xfffffffc
261 || b1dma_readl(card
, AMCC_TXPTR
) != 0xfffffffc)
264 b1dma_writel(card
, 0x0, AMCC_RXPTR
);
265 b1dma_writel(card
, 0x0, AMCC_TXPTR
);
266 if ( b1dma_readl(card
, AMCC_RXPTR
) != 0x0
267 || b1dma_readl(card
, AMCC_TXPTR
) != 0x0)
270 t1outp(card
->port
, 0x10, 0x00);
271 t1outp(card
->port
, 0x07, 0x00);
273 t1outp(card
->port
, 0x02, 0x02);
274 t1outp(card
->port
, 0x03, 0x02);
276 if ( (t1inp(card
->port
, 0x02) & 0xFE) != 0x02
277 || t1inp(card
->port
, 0x3) != 0x03)
280 t1outp(card
->port
, 0x02, 0x00);
281 t1outp(card
->port
, 0x03, 0x00);
283 if ( (t1inp(card
->port
, 0x02) & 0xFE) != 0x00
284 || t1inp(card
->port
, 0x3) != 0x01)
290 int t1pci_detect(avmcard
*card
)
294 if ((ret
= b1dma_detect(card
)) != 0)
297 /* Transputer test */
299 if ( WriteReg(card
, 0x80001000, 0x11) != 0
300 || WriteReg(card
, 0x80101000, 0x22) != 0
301 || WriteReg(card
, 0x80201000, 0x33) != 0
302 || WriteReg(card
, 0x80301000, 0x44) != 0)
305 if ( ReadReg(card
, 0x80001000) != 0x11
306 || ReadReg(card
, 0x80101000) != 0x22
307 || ReadReg(card
, 0x80201000) != 0x33
308 || ReadReg(card
, 0x80301000) != 0x44)
311 if ( WriteReg(card
, 0x80001000, 0x55) != 0
312 || WriteReg(card
, 0x80101000, 0x66) != 0
313 || WriteReg(card
, 0x80201000, 0x77) != 0
314 || WriteReg(card
, 0x80301000, 0x88) != 0)
317 if ( ReadReg(card
, 0x80001000) != 0x55
318 || ReadReg(card
, 0x80101000) != 0x66
319 || ReadReg(card
, 0x80201000) != 0x77
320 || ReadReg(card
, 0x80301000) != 0x88)
326 int b1pciv4_detect(avmcard
*card
)
330 if ((ret
= b1dma_detect(card
)) != 0)
333 for (i
=0; i
< 5 ; i
++) {
334 if (WriteReg(card
, 0x80A00000, 0x21) != 0)
336 if ((ReadReg(card
, 0x80A00000) & 0x01) != 0x01)
339 for (i
=0; i
< 5 ; i
++) {
340 if (WriteReg(card
, 0x80A00000, 0x20) != 0)
342 if ((ReadReg(card
, 0x80A00000) & 0x01) != 0x00)
349 static void b1dma_queue_tx(avmcard
*card
, struct sk_buff
*skb
)
353 spin_lock_irqsave(&card
->lock
, flags
);
355 skb_queue_tail(&card
->dma
->send_queue
, skb
);
357 if (!(card
->csr
& EN_TX_TC_INT
)) {
358 b1dma_dispatch_tx(card
);
359 b1dma_writel(card
, card
->csr
, AMCC_INTCSR
);
362 spin_unlock_irqrestore(&card
->lock
, flags
);
365 /* ------------------------------------------------------------- */
367 static void b1dma_dispatch_tx(avmcard
*card
)
369 avmcard_dmainfo
*dma
= card
->dma
;
376 skb
= skb_dequeue(&dma
->send_queue
);
378 len
= CAPIMSG_LEN(skb
->data
);
381 cmd
= CAPIMSG_COMMAND(skb
->data
);
382 subcmd
= CAPIMSG_SUBCOMMAND(skb
->data
);
384 p
= dma
->sendbuf
.dmabuf
;
386 if (CAPICMD(cmd
, subcmd
) == CAPI_DATA_B3_REQ
) {
387 u16 dlen
= CAPIMSG_DATALEN(skb
->data
);
388 _put_byte(&p
, SEND_DATA_B3_REQ
);
389 _put_slice(&p
, skb
->data
, len
);
390 _put_slice(&p
, skb
->data
+ len
, dlen
);
392 _put_byte(&p
, SEND_MESSAGE
);
393 _put_slice(&p
, skb
->data
, len
);
395 txlen
= (u8
*)p
- (u8
*)dma
->sendbuf
.dmabuf
;
396 #ifdef AVM_B1DMA_DEBUG
397 printk(KERN_DEBUG
"tx: put msg len=%d\n", txlen
);
401 #ifdef AVM_B1DMA_POLLDEBUG
402 if (skb
->data
[2] == SEND_POLLACK
)
403 printk(KERN_INFO
"%s: send ack\n", card
->name
);
405 #ifdef AVM_B1DMA_DEBUG
406 printk(KERN_DEBUG
"tx: put 0x%x len=%d\n",
407 skb
->data
[2], txlen
);
409 skb_copy_from_linear_data_offset(skb
, 2, dma
->sendbuf
.dmabuf
,
412 txlen
= (txlen
+ 3) & ~3;
414 b1dma_writel(card
, dma
->sendbuf
.dmaaddr
, AMCC_TXPTR
);
415 b1dma_writel(card
, txlen
, AMCC_TXLEN
);
417 card
->csr
|= EN_TX_TC_INT
;
419 dev_kfree_skb_any(skb
);
422 /* ------------------------------------------------------------- */
424 static void queue_pollack(avmcard
*card
)
429 skb
= alloc_skb(3, GFP_ATOMIC
);
431 printk(KERN_CRIT
"%s: no memory, lost poll ack\n",
438 _put_byte(&p
, SEND_POLLACK
);
439 skb_put(skb
, (u8
*)p
- (u8
*)skb
->data
);
441 b1dma_queue_tx(card
, skb
);
444 /* ------------------------------------------------------------- */
446 static void b1dma_handle_rx(avmcard
*card
)
448 avmctrl_info
*cinfo
= &card
->ctrlinfo
[0];
449 avmcard_dmainfo
*dma
= card
->dma
;
450 struct capi_ctr
*ctrl
= &cinfo
->capi_ctrl
;
452 void *p
= dma
->recvbuf
.dmabuf
+4;
453 u32 ApplId
, MsgLen
, DataB3Len
, NCCI
, WindowSize
;
454 u8 b1cmd
= _get_byte(&p
);
456 #ifdef AVM_B1DMA_DEBUG
457 printk(KERN_DEBUG
"rx: 0x%x %lu\n", b1cmd
, (unsigned long)dma
->recvlen
);
461 case RECEIVE_DATA_B3_IND
:
463 ApplId
= (unsigned) _get_word(&p
);
464 MsgLen
= _get_slice(&p
, card
->msgbuf
);
465 DataB3Len
= _get_slice(&p
, card
->databuf
);
467 if (MsgLen
< 30) { /* not CAPI 64Bit */
468 memset(card
->msgbuf
+MsgLen
, 0, 30-MsgLen
);
470 CAPIMSG_SETLEN(card
->msgbuf
, 30);
472 if (!(skb
= alloc_skb(DataB3Len
+MsgLen
, GFP_ATOMIC
))) {
473 printk(KERN_ERR
"%s: incoming packet dropped\n",
476 memcpy(skb_put(skb
, MsgLen
), card
->msgbuf
, MsgLen
);
477 memcpy(skb_put(skb
, DataB3Len
), card
->databuf
, DataB3Len
);
478 capi_ctr_handle_message(ctrl
, ApplId
, skb
);
482 case RECEIVE_MESSAGE
:
484 ApplId
= (unsigned) _get_word(&p
);
485 MsgLen
= _get_slice(&p
, card
->msgbuf
);
486 if (!(skb
= alloc_skb(MsgLen
, GFP_ATOMIC
))) {
487 printk(KERN_ERR
"%s: incoming packet dropped\n",
490 memcpy(skb_put(skb
, MsgLen
), card
->msgbuf
, MsgLen
);
491 if (CAPIMSG_CMD(skb
->data
) == CAPI_DATA_B3_CONF
) {
492 spin_lock(&card
->lock
);
493 capilib_data_b3_conf(&cinfo
->ncci_head
, ApplId
,
494 CAPIMSG_NCCI(skb
->data
),
495 CAPIMSG_MSGID(skb
->data
));
496 spin_unlock(&card
->lock
);
498 capi_ctr_handle_message(ctrl
, ApplId
, skb
);
502 case RECEIVE_NEW_NCCI
:
504 ApplId
= _get_word(&p
);
505 NCCI
= _get_word(&p
);
506 WindowSize
= _get_word(&p
);
507 spin_lock(&card
->lock
);
508 capilib_new_ncci(&cinfo
->ncci_head
, ApplId
, NCCI
, WindowSize
);
509 spin_unlock(&card
->lock
);
512 case RECEIVE_FREE_NCCI
:
514 ApplId
= _get_word(&p
);
515 NCCI
= _get_word(&p
);
517 if (NCCI
!= 0xffffffff) {
518 spin_lock(&card
->lock
);
519 capilib_free_ncci(&cinfo
->ncci_head
, ApplId
, NCCI
);
520 spin_unlock(&card
->lock
);
525 #ifdef AVM_B1DMA_POLLDEBUG
526 printk(KERN_INFO
"%s: receive poll\n", card
->name
);
528 if (!suppress_pollack
)
530 capi_ctr_resume_output(ctrl
);
534 capi_ctr_suspend_output(ctrl
);
539 cinfo
->versionlen
= _get_slice(&p
, cinfo
->versionbuf
);
540 b1_parse_version(cinfo
);
541 printk(KERN_INFO
"%s: %s-card (%s) now active\n",
543 cinfo
->version
[VER_CARDTYPE
],
544 cinfo
->version
[VER_DRIVER
]);
545 capi_ctr_ready(ctrl
);
548 case RECEIVE_TASK_READY
:
549 ApplId
= (unsigned) _get_word(&p
);
550 MsgLen
= _get_slice(&p
, card
->msgbuf
);
551 card
->msgbuf
[MsgLen
] = 0;
553 && ( card
->msgbuf
[MsgLen
-1] == '\n'
554 || card
->msgbuf
[MsgLen
-1] == '\r')) {
555 card
->msgbuf
[MsgLen
-1] = 0;
558 printk(KERN_INFO
"%s: task %d \"%s\" ready.\n",
559 card
->name
, ApplId
, card
->msgbuf
);
562 case RECEIVE_DEBUGMSG
:
563 MsgLen
= _get_slice(&p
, card
->msgbuf
);
564 card
->msgbuf
[MsgLen
] = 0;
566 && ( card
->msgbuf
[MsgLen
-1] == '\n'
567 || card
->msgbuf
[MsgLen
-1] == '\r')) {
568 card
->msgbuf
[MsgLen
-1] = 0;
571 printk(KERN_INFO
"%s: DEBUG: %s\n", card
->name
, card
->msgbuf
);
575 printk(KERN_ERR
"%s: b1dma_interrupt: 0x%x ???\n",
581 /* ------------------------------------------------------------- */
583 static void b1dma_handle_interrupt(avmcard
*card
)
588 spin_lock(&card
->lock
);
590 status
= b1dma_readl(card
, AMCC_INTCSR
);
591 if ((status
& ANY_S5933_INT
) == 0) {
592 spin_unlock(&card
->lock
);
596 newcsr
= card
->csr
| (status
& ALL_INT
);
597 if (status
& TX_TC_INT
) newcsr
&= ~EN_TX_TC_INT
;
598 if (status
& RX_TC_INT
) newcsr
&= ~EN_RX_TC_INT
;
599 b1dma_writel(card
, newcsr
, AMCC_INTCSR
);
601 if ((status
& RX_TC_INT
) != 0) {
602 struct avmcard_dmainfo
*dma
= card
->dma
;
604 if (card
->dma
->recvlen
== 0) {
605 rxlen
= b1dma_readl(card
, AMCC_RXLEN
);
607 dma
->recvlen
= *((u32
*)dma
->recvbuf
.dmabuf
);
608 rxlen
= (dma
->recvlen
+ 3) & ~3;
609 b1dma_writel(card
, dma
->recvbuf
.dmaaddr
+4, AMCC_RXPTR
);
610 b1dma_writel(card
, rxlen
, AMCC_RXLEN
);
611 #ifdef AVM_B1DMA_DEBUG
613 printk(KERN_ERR
"%s: rx not complete (%d).\n",
618 spin_unlock(&card
->lock
);
619 b1dma_handle_rx(card
);
621 spin_lock(&card
->lock
);
622 b1dma_writel(card
, dma
->recvbuf
.dmaaddr
, AMCC_RXPTR
);
623 b1dma_writel(card
, 4, AMCC_RXLEN
);
627 if ((status
& TX_TC_INT
) != 0) {
628 if (skb_queue_empty(&card
->dma
->send_queue
))
629 card
->csr
&= ~EN_TX_TC_INT
;
631 b1dma_dispatch_tx(card
);
633 b1dma_writel(card
, card
->csr
, AMCC_INTCSR
);
635 spin_unlock(&card
->lock
);
638 irqreturn_t
b1dma_interrupt(int interrupt
, void *devptr
)
640 avmcard
*card
= devptr
;
642 b1dma_handle_interrupt(card
);
646 /* ------------------------------------------------------------- */
648 static int b1dma_loaded(avmcard
*card
)
652 unsigned long tout
= 2;
653 unsigned int base
= card
->port
;
655 for (stop
= jiffies
+ tout
* HZ
; time_before(jiffies
, stop
);) {
656 if (b1_tx_empty(base
))
659 if (!b1_tx_empty(base
)) {
660 printk(KERN_ERR
"%s: b1dma_loaded: tx err, corrupted t4 file ?\n",
664 b1_put_byte(base
, SEND_POLLACK
);
665 for (stop
= jiffies
+ tout
* HZ
; time_before(jiffies
, stop
);) {
666 if (b1_rx_full(base
)) {
667 if ((ans
= b1_get_byte(base
)) == RECEIVE_POLLDWORD
) {
670 printk(KERN_ERR
"%s: b1dma_loaded: got 0x%x, firmware not running in dword mode\n", card
->name
, ans
);
674 printk(KERN_ERR
"%s: b1dma_loaded: firmware not running\n", card
->name
);
678 /* ------------------------------------------------------------- */
680 static void b1dma_send_init(avmcard
*card
)
685 skb
= alloc_skb(15, GFP_ATOMIC
);
687 printk(KERN_CRIT
"%s: no memory, lost register appl.\n",
694 _put_byte(&p
, SEND_INIT
);
695 _put_word(&p
, CAPI_MAXAPPL
);
696 _put_word(&p
, AVM_NCCI_PER_CHANNEL
*30);
697 _put_word(&p
, card
->cardnr
- 1);
698 skb_put(skb
, (u8
*)p
- (u8
*)skb
->data
);
700 b1dma_queue_tx(card
, skb
);
703 int b1dma_load_firmware(struct capi_ctr
*ctrl
, capiloaddata
*data
)
705 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
706 avmcard
*card
= cinfo
->card
;
711 if ((retval
= b1_load_t4file(card
, &data
->firmware
))) {
713 printk(KERN_ERR
"%s: failed to load t4file!!\n",
718 if (data
->configuration
.len
> 0 && data
->configuration
.data
) {
719 if ((retval
= b1_load_config(card
, &data
->configuration
))) {
721 printk(KERN_ERR
"%s: failed to load config!!\n",
727 if (!b1dma_loaded(card
)) {
729 printk(KERN_ERR
"%s: failed to load t4file.\n", card
->name
);
733 card
->csr
= AVM_FLAG
;
734 b1dma_writel(card
, card
->csr
, AMCC_INTCSR
);
735 b1dma_writel(card
, EN_A2P_TRANSFERS
|EN_P2A_TRANSFERS
|A2P_HI_PRIORITY
|
736 P2A_HI_PRIORITY
|RESET_A2P_FLAGS
|RESET_P2A_FLAGS
,
738 t1outp(card
->port
, 0x07, 0x30);
739 t1outp(card
->port
, 0x10, 0xF0);
741 card
->dma
->recvlen
= 0;
742 b1dma_writel(card
, card
->dma
->recvbuf
.dmaaddr
, AMCC_RXPTR
);
743 b1dma_writel(card
, 4, AMCC_RXLEN
);
744 card
->csr
|= EN_RX_TC_INT
;
745 b1dma_writel(card
, card
->csr
, AMCC_INTCSR
);
747 b1dma_send_init(card
);
752 void b1dma_reset_ctr(struct capi_ctr
*ctrl
)
754 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
755 avmcard
*card
= cinfo
->card
;
758 spin_lock_irqsave(&card
->lock
, flags
);
761 memset(cinfo
->version
, 0, sizeof(cinfo
->version
));
762 capilib_release(&cinfo
->ncci_head
);
763 spin_unlock_irqrestore(&card
->lock
, flags
);
767 /* ------------------------------------------------------------- */
769 void b1dma_register_appl(struct capi_ctr
*ctrl
,
771 capi_register_params
*rp
)
773 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
774 avmcard
*card
= cinfo
->card
;
776 int want
= rp
->level3cnt
;
780 if (want
> 0) nconn
= want
;
781 else nconn
= ctrl
->profile
.nbchannel
* -want
;
782 if (nconn
== 0) nconn
= ctrl
->profile
.nbchannel
;
784 skb
= alloc_skb(23, GFP_ATOMIC
);
786 printk(KERN_CRIT
"%s: no memory, lost register appl.\n",
793 _put_byte(&p
, SEND_REGISTER
);
795 _put_word(&p
, 1024 * (nconn
+1));
796 _put_word(&p
, nconn
);
797 _put_word(&p
, rp
->datablkcnt
);
798 _put_word(&p
, rp
->datablklen
);
799 skb_put(skb
, (u8
*)p
- (u8
*)skb
->data
);
801 b1dma_queue_tx(card
, skb
);
804 /* ------------------------------------------------------------- */
806 void b1dma_release_appl(struct capi_ctr
*ctrl
, u16 appl
)
808 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
809 avmcard
*card
= cinfo
->card
;
814 spin_lock_irqsave(&card
->lock
, flags
);
815 capilib_release_appl(&cinfo
->ncci_head
, appl
);
816 spin_unlock_irqrestore(&card
->lock
, flags
);
818 skb
= alloc_skb(7, GFP_ATOMIC
);
820 printk(KERN_CRIT
"%s: no memory, lost release appl.\n",
827 _put_byte(&p
, SEND_RELEASE
);
830 skb_put(skb
, (u8
*)p
- (u8
*)skb
->data
);
832 b1dma_queue_tx(card
, skb
);
835 /* ------------------------------------------------------------- */
837 u16
b1dma_send_message(struct capi_ctr
*ctrl
, struct sk_buff
*skb
)
839 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
840 avmcard
*card
= cinfo
->card
;
841 u16 retval
= CAPI_NOERROR
;
843 if (CAPIMSG_CMD(skb
->data
) == CAPI_DATA_B3_REQ
) {
845 spin_lock_irqsave(&card
->lock
, flags
);
846 retval
= capilib_data_b3_req(&cinfo
->ncci_head
,
847 CAPIMSG_APPID(skb
->data
),
848 CAPIMSG_NCCI(skb
->data
),
849 CAPIMSG_MSGID(skb
->data
));
850 spin_unlock_irqrestore(&card
->lock
, flags
);
852 if (retval
== CAPI_NOERROR
)
853 b1dma_queue_tx(card
, skb
);
858 /* ------------------------------------------------------------- */
860 static int b1dmactl_proc_show(struct seq_file
*m
, void *v
)
862 struct capi_ctr
*ctrl
= m
->private;
863 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
864 avmcard
*card
= cinfo
->card
;
867 u32 txoff
, txlen
, rxoff
, rxlen
, csr
;
870 seq_printf(m
, "%-16s %s\n", "name", card
->name
);
871 seq_printf(m
, "%-16s 0x%x\n", "io", card
->port
);
872 seq_printf(m
, "%-16s %d\n", "irq", card
->irq
);
873 seq_printf(m
, "%-16s 0x%lx\n", "membase", card
->membase
);
874 switch (card
->cardtype
) {
875 case avm_b1isa
: s
= "B1 ISA"; break;
876 case avm_b1pci
: s
= "B1 PCI"; break;
877 case avm_b1pcmcia
: s
= "B1 PCMCIA"; break;
878 case avm_m1
: s
= "M1"; break;
879 case avm_m2
: s
= "M2"; break;
880 case avm_t1isa
: s
= "T1 ISA (HEMA)"; break;
881 case avm_t1pci
: s
= "T1 PCI"; break;
882 case avm_c4
: s
= "C4"; break;
883 case avm_c2
: s
= "C2"; break;
884 default: s
= "???"; break;
886 seq_printf(m
, "%-16s %s\n", "type", s
);
887 if ((s
= cinfo
->version
[VER_DRIVER
]) != NULL
)
888 seq_printf(m
, "%-16s %s\n", "ver_driver", s
);
889 if ((s
= cinfo
->version
[VER_CARDTYPE
]) != NULL
)
890 seq_printf(m
, "%-16s %s\n", "ver_cardtype", s
);
891 if ((s
= cinfo
->version
[VER_SERIAL
]) != NULL
)
892 seq_printf(m
, "%-16s %s\n", "ver_serial", s
);
894 if (card
->cardtype
!= avm_m1
) {
895 flag
= ((u8
*)(ctrl
->profile
.manu
))[3];
897 seq_printf(m
, "%-16s%s%s%s%s%s%s%s\n",
899 (flag
& 0x01) ? " DSS1" : "",
900 (flag
& 0x02) ? " CT1" : "",
901 (flag
& 0x04) ? " VN3" : "",
902 (flag
& 0x08) ? " NI1" : "",
903 (flag
& 0x10) ? " AUSTEL" : "",
904 (flag
& 0x20) ? " ESS" : "",
905 (flag
& 0x40) ? " 1TR6" : ""
908 if (card
->cardtype
!= avm_m1
) {
909 flag
= ((u8
*)(ctrl
->profile
.manu
))[5];
911 seq_printf(m
, "%-16s%s%s%s%s\n",
913 (flag
& 0x01) ? " point to point" : "",
914 (flag
& 0x02) ? " point to multipoint" : "",
915 (flag
& 0x08) ? " leased line without D-channel" : "",
916 (flag
& 0x04) ? " leased line with D-channel" : ""
919 seq_printf(m
, "%-16s %s\n", "cardname", cinfo
->cardname
);
922 spin_lock_irqsave(&card
->lock
, flags
);
924 txoff
= (dma_addr_t
)b1dma_readl(card
, AMCC_TXPTR
)-card
->dma
->sendbuf
.dmaaddr
;
925 txlen
= b1dma_readl(card
, AMCC_TXLEN
);
927 rxoff
= (dma_addr_t
)b1dma_readl(card
, AMCC_RXPTR
)-card
->dma
->recvbuf
.dmaaddr
;
928 rxlen
= b1dma_readl(card
, AMCC_RXLEN
);
930 csr
= b1dma_readl(card
, AMCC_INTCSR
);
932 spin_unlock_irqrestore(&card
->lock
, flags
);
934 seq_printf(m
, "%-16s 0x%lx\n", "csr (cached)", (unsigned long)card
->csr
);
935 seq_printf(m
, "%-16s 0x%lx\n", "csr", (unsigned long)csr
);
936 seq_printf(m
, "%-16s %lu\n", "txoff", (unsigned long)txoff
);
937 seq_printf(m
, "%-16s %lu\n", "txlen", (unsigned long)txlen
);
938 seq_printf(m
, "%-16s %lu\n", "rxoff", (unsigned long)rxoff
);
939 seq_printf(m
, "%-16s %lu\n", "rxlen", (unsigned long)rxlen
);
944 static int b1dmactl_proc_open(struct inode
*inode
, struct file
*file
)
946 return single_open(file
, b1dmactl_proc_show
, PDE(inode
)->data
);
949 const struct file_operations b1dmactl_proc_fops
= {
950 .owner
= THIS_MODULE
,
951 .open
= b1dmactl_proc_open
,
954 .release
= single_release
,
956 EXPORT_SYMBOL(b1dmactl_proc_fops
);
958 /* ------------------------------------------------------------- */
960 EXPORT_SYMBOL(b1dma_reset
);
961 EXPORT_SYMBOL(t1pci_detect
);
962 EXPORT_SYMBOL(b1pciv4_detect
);
963 EXPORT_SYMBOL(b1dma_interrupt
);
965 EXPORT_SYMBOL(b1dma_load_firmware
);
966 EXPORT_SYMBOL(b1dma_reset_ctr
);
967 EXPORT_SYMBOL(b1dma_register_appl
);
968 EXPORT_SYMBOL(b1dma_release_appl
);
969 EXPORT_SYMBOL(b1dma_send_message
);
971 static int __init
b1dma_init(void)
976 if ((p
= strchr(revision
, ':')) != NULL
&& p
[1]) {
977 strlcpy(rev
, p
+ 2, sizeof(rev
));
978 if ((p
= strchr(rev
, '$')) != NULL
&& p
> rev
)
983 printk(KERN_INFO
"b1dma: revision %s\n", rev
);
988 static void __exit
b1dma_exit(void)
992 module_init(b1dma_init
);
993 module_exit(b1dma_exit
);