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>
23 #include <linux/gfp.h>
25 #include <linux/init.h>
26 #include <linux/uaccess.h>
27 #include <linux/netdevice.h>
28 #include <linux/isdn/capilli.h>
30 #include <linux/isdn/capicmd.h>
31 #include <linux/isdn/capiutil.h>
33 static char *revision
= "$Revision: 1.1.2.3 $";
35 #undef AVM_B1DMA_DEBUG
37 /* ------------------------------------------------------------- */
39 MODULE_DESCRIPTION("CAPI4Linux: DMA support for active AVM cards");
40 MODULE_AUTHOR("Carsten Paeth");
41 MODULE_LICENSE("GPL");
43 static bool suppress_pollack
= 0;
44 module_param(suppress_pollack
, bool, 0);
46 /* ------------------------------------------------------------- */
48 static void b1dma_dispatch_tx(avmcard
*card
);
50 /* ------------------------------------------------------------- */
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
84 /* ------------------------------------------------------------- */
86 static inline void b1dma_writel(avmcard
*card
, u32 value
, int off
)
88 writel(value
, card
->mbase
+ off
);
91 static inline u32
b1dma_readl(avmcard
*card
, int off
)
93 return readl(card
->mbase
+ off
);
96 /* ------------------------------------------------------------- */
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
)
110 unsigned long stop
= jiffies
+ 1 * HZ
; /* maximum wait time 1 sec */
111 unsigned char *s
= (unsigned char *)buf
;
113 while (!b1dma_tx_empty(card
->port
)
114 && time_before(jiffies
, stop
));
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
)
124 unsigned long stop
= jiffies
+ 1 * HZ
; /* maximum wait time 1 sec */
125 unsigned char *s
= (unsigned char *)buf
;
127 while (!b1dma_rx_full(card
->port
)
128 && time_before(jiffies
, stop
));
129 if (!b1dma_rx_full(card
->port
))
131 *s
++ = t1inp(card
->port
, 0x00);
136 static int WriteReg(avmcard
*card
, u32 reg
, u8 val
)
139 if (b1dma_tolink(card
, &cmd
, 1) == 0
140 && b1dma_tolink(card
, ®
, 4) == 0) {
142 return b1dma_tolink(card
, &tmp
, 4);
147 static u8
ReadReg(avmcard
*card
, u32 reg
)
150 if (b1dma_tolink(card
, &cmd
, 1) == 0
151 && b1dma_tolink(card
, ®
, 4) == 0) {
153 if (b1dma_fromlink(card
, &tmp
, 4) == 0)
159 /* ------------------------------------------------------------- */
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
);
216 /* ------------------------------------------------------------- */
218 void b1dma_reset(avmcard
*card
)
221 b1dma_writel(card
, card
->csr
, AMCC_INTCSR
);
222 b1dma_writel(card
, 0, AMCC_MCSR
);
223 b1dma_writel(card
, 0, AMCC_RXLEN
);
224 b1dma_writel(card
, 0, AMCC_TXLEN
);
226 t1outp(card
->port
, 0x10, 0x00);
227 t1outp(card
->port
, 0x07, 0x00);
229 b1dma_writel(card
, 0, AMCC_MCSR
);
231 b1dma_writel(card
, 0x0f000000, AMCC_MCSR
); /* reset all */
233 b1dma_writel(card
, 0, AMCC_MCSR
);
234 if (card
->cardtype
== avm_t1pci
)
240 /* ------------------------------------------------------------- */
242 static int b1dma_detect(avmcard
*card
)
244 b1dma_writel(card
, 0, AMCC_MCSR
);
246 b1dma_writel(card
, 0x0f000000, AMCC_MCSR
); /* reset all */
248 b1dma_writel(card
, 0, AMCC_MCSR
);
251 b1dma_writel(card
, 0, AMCC_RXLEN
);
252 b1dma_writel(card
, 0, AMCC_TXLEN
);
254 b1dma_writel(card
, card
->csr
, AMCC_INTCSR
);
256 if (b1dma_readl(card
, AMCC_MCSR
) != 0x000000E6)
259 b1dma_writel(card
, 0xffffffff, AMCC_RXPTR
);
260 b1dma_writel(card
, 0xffffffff, AMCC_TXPTR
);
261 if (b1dma_readl(card
, AMCC_RXPTR
) != 0xfffffffc
262 || b1dma_readl(card
, AMCC_TXPTR
) != 0xfffffffc)
265 b1dma_writel(card
, 0x0, AMCC_RXPTR
);
266 b1dma_writel(card
, 0x0, AMCC_TXPTR
);
267 if (b1dma_readl(card
, AMCC_RXPTR
) != 0x0
268 || b1dma_readl(card
, AMCC_TXPTR
) != 0x0)
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)
291 int t1pci_detect(avmcard
*card
)
295 if ((ret
= b1dma_detect(card
)) != 0)
298 /* Transputer test */
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)
327 int b1pciv4_detect(avmcard
*card
)
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)
350 static void b1dma_queue_tx(avmcard
*card
, struct sk_buff
*skb
)
354 spin_lock_irqsave(&card
->lock
, flags
);
356 skb_queue_tail(&card
->dma
->send_queue
, skb
);
358 if (!(card
->csr
& EN_TX_TC_INT
)) {
359 b1dma_dispatch_tx(card
);
360 b1dma_writel(card
, card
->csr
, AMCC_INTCSR
);
363 spin_unlock_irqrestore(&card
->lock
, flags
);
366 /* ------------------------------------------------------------- */
368 static void b1dma_dispatch_tx(avmcard
*card
)
370 avmcard_dmainfo
*dma
= card
->dma
;
377 skb
= skb_dequeue(&dma
->send_queue
);
379 len
= CAPIMSG_LEN(skb
->data
);
382 cmd
= CAPIMSG_COMMAND(skb
->data
);
383 subcmd
= CAPIMSG_SUBCOMMAND(skb
->data
);
385 p
= dma
->sendbuf
.dmabuf
;
387 if (CAPICMD(cmd
, subcmd
) == CAPI_DATA_B3_REQ
) {
388 u16 dlen
= CAPIMSG_DATALEN(skb
->data
);
389 _put_byte(&p
, SEND_DATA_B3_REQ
);
390 _put_slice(&p
, skb
->data
, len
);
391 _put_slice(&p
, skb
->data
+ len
, dlen
);
393 _put_byte(&p
, SEND_MESSAGE
);
394 _put_slice(&p
, skb
->data
, len
);
396 txlen
= (u8
*)p
- (u8
*)dma
->sendbuf
.dmabuf
;
397 #ifdef AVM_B1DMA_DEBUG
398 printk(KERN_DEBUG
"tx: put msg len=%d\n", txlen
);
401 txlen
= skb
->len
- 2;
402 #ifdef AVM_B1DMA_POLLDEBUG
403 if (skb
->data
[2] == SEND_POLLACK
)
404 printk(KERN_INFO
"%s: send ack\n", card
->name
);
406 #ifdef AVM_B1DMA_DEBUG
407 printk(KERN_DEBUG
"tx: put 0x%x len=%d\n",
408 skb
->data
[2], txlen
);
410 skb_copy_from_linear_data_offset(skb
, 2, dma
->sendbuf
.dmabuf
,
413 txlen
= (txlen
+ 3) & ~3;
415 b1dma_writel(card
, dma
->sendbuf
.dmaaddr
, AMCC_TXPTR
);
416 b1dma_writel(card
, txlen
, AMCC_TXLEN
);
418 card
->csr
|= EN_TX_TC_INT
;
420 dev_kfree_skb_any(skb
);
423 /* ------------------------------------------------------------- */
425 static void queue_pollack(avmcard
*card
)
430 skb
= alloc_skb(3, GFP_ATOMIC
);
432 printk(KERN_CRIT
"%s: no memory, lost poll ack\n",
439 _put_byte(&p
, SEND_POLLACK
);
440 skb_put(skb
, (u8
*)p
- (u8
*)skb
->data
);
442 b1dma_queue_tx(card
, skb
);
445 /* ------------------------------------------------------------- */
447 static void b1dma_handle_rx(avmcard
*card
)
449 avmctrl_info
*cinfo
= &card
->ctrlinfo
[0];
450 avmcard_dmainfo
*dma
= card
->dma
;
451 struct capi_ctr
*ctrl
= &cinfo
->capi_ctrl
;
453 void *p
= dma
->recvbuf
.dmabuf
+ 4;
454 u32 ApplId
, MsgLen
, DataB3Len
, NCCI
, WindowSize
;
455 u8 b1cmd
= _get_byte(&p
);
457 #ifdef AVM_B1DMA_DEBUG
458 printk(KERN_DEBUG
"rx: 0x%x %lu\n", b1cmd
, (unsigned long)dma
->recvlen
);
462 case RECEIVE_DATA_B3_IND
:
464 ApplId
= (unsigned) _get_word(&p
);
465 MsgLen
= _get_slice(&p
, card
->msgbuf
);
466 DataB3Len
= _get_slice(&p
, card
->databuf
);
468 if (MsgLen
< 30) { /* not CAPI 64Bit */
469 memset(card
->msgbuf
+ MsgLen
, 0, 30 - MsgLen
);
471 CAPIMSG_SETLEN(card
->msgbuf
, 30);
473 if (!(skb
= alloc_skb(DataB3Len
+ MsgLen
, GFP_ATOMIC
))) {
474 printk(KERN_ERR
"%s: incoming packet dropped\n",
477 skb_put_data(skb
, card
->msgbuf
, MsgLen
);
478 skb_put_data(skb
, card
->databuf
, DataB3Len
);
479 capi_ctr_handle_message(ctrl
, ApplId
, skb
);
483 case RECEIVE_MESSAGE
:
485 ApplId
= (unsigned) _get_word(&p
);
486 MsgLen
= _get_slice(&p
, card
->msgbuf
);
487 if (!(skb
= alloc_skb(MsgLen
, GFP_ATOMIC
))) {
488 printk(KERN_ERR
"%s: incoming packet dropped\n",
491 skb_put_data(skb
, card
->msgbuf
, MsgLen
);
492 if (CAPIMSG_CMD(skb
->data
) == CAPI_DATA_B3_CONF
) {
493 spin_lock(&card
->lock
);
494 capilib_data_b3_conf(&cinfo
->ncci_head
, ApplId
,
495 CAPIMSG_NCCI(skb
->data
),
496 CAPIMSG_MSGID(skb
->data
));
497 spin_unlock(&card
->lock
);
499 capi_ctr_handle_message(ctrl
, ApplId
, skb
);
503 case RECEIVE_NEW_NCCI
:
505 ApplId
= _get_word(&p
);
506 NCCI
= _get_word(&p
);
507 WindowSize
= _get_word(&p
);
508 spin_lock(&card
->lock
);
509 capilib_new_ncci(&cinfo
->ncci_head
, ApplId
, NCCI
, WindowSize
);
510 spin_unlock(&card
->lock
);
513 case RECEIVE_FREE_NCCI
:
515 ApplId
= _get_word(&p
);
516 NCCI
= _get_word(&p
);
518 if (NCCI
!= 0xffffffff) {
519 spin_lock(&card
->lock
);
520 capilib_free_ncci(&cinfo
->ncci_head
, ApplId
, NCCI
);
521 spin_unlock(&card
->lock
);
526 #ifdef AVM_B1DMA_POLLDEBUG
527 printk(KERN_INFO
"%s: receive poll\n", card
->name
);
529 if (!suppress_pollack
)
531 capi_ctr_resume_output(ctrl
);
535 capi_ctr_suspend_output(ctrl
);
540 cinfo
->versionlen
= _get_slice(&p
, cinfo
->versionbuf
);
541 b1_parse_version(cinfo
);
542 printk(KERN_INFO
"%s: %s-card (%s) now active\n",
544 cinfo
->version
[VER_CARDTYPE
],
545 cinfo
->version
[VER_DRIVER
]);
546 capi_ctr_ready(ctrl
);
549 case RECEIVE_TASK_READY
:
550 ApplId
= (unsigned) _get_word(&p
);
551 MsgLen
= _get_slice(&p
, card
->msgbuf
);
552 card
->msgbuf
[MsgLen
] = 0;
554 && (card
->msgbuf
[MsgLen
- 1] == '\n'
555 || card
->msgbuf
[MsgLen
- 1] == '\r')) {
556 card
->msgbuf
[MsgLen
- 1] = 0;
559 printk(KERN_INFO
"%s: task %d \"%s\" ready.\n",
560 card
->name
, ApplId
, card
->msgbuf
);
563 case RECEIVE_DEBUGMSG
:
564 MsgLen
= _get_slice(&p
, card
->msgbuf
);
565 card
->msgbuf
[MsgLen
] = 0;
567 && (card
->msgbuf
[MsgLen
- 1] == '\n'
568 || card
->msgbuf
[MsgLen
- 1] == '\r')) {
569 card
->msgbuf
[MsgLen
- 1] = 0;
572 printk(KERN_INFO
"%s: DEBUG: %s\n", card
->name
, card
->msgbuf
);
576 printk(KERN_ERR
"%s: b1dma_interrupt: 0x%x ???\n",
582 /* ------------------------------------------------------------- */
584 static void b1dma_handle_interrupt(avmcard
*card
)
589 spin_lock(&card
->lock
);
591 status
= b1dma_readl(card
, AMCC_INTCSR
);
592 if ((status
& ANY_S5933_INT
) == 0) {
593 spin_unlock(&card
->lock
);
597 newcsr
= card
->csr
| (status
& ALL_INT
);
598 if (status
& TX_TC_INT
) newcsr
&= ~EN_TX_TC_INT
;
599 if (status
& RX_TC_INT
) newcsr
&= ~EN_RX_TC_INT
;
600 b1dma_writel(card
, newcsr
, AMCC_INTCSR
);
602 if ((status
& RX_TC_INT
) != 0) {
603 struct avmcard_dmainfo
*dma
= card
->dma
;
605 if (card
->dma
->recvlen
== 0) {
606 rxlen
= b1dma_readl(card
, AMCC_RXLEN
);
608 dma
->recvlen
= *((u32
*)dma
->recvbuf
.dmabuf
);
609 rxlen
= (dma
->recvlen
+ 3) & ~3;
610 b1dma_writel(card
, dma
->recvbuf
.dmaaddr
+ 4, AMCC_RXPTR
);
611 b1dma_writel(card
, rxlen
, AMCC_RXLEN
);
612 #ifdef AVM_B1DMA_DEBUG
614 printk(KERN_ERR
"%s: rx not complete (%d).\n",
619 spin_unlock(&card
->lock
);
620 b1dma_handle_rx(card
);
622 spin_lock(&card
->lock
);
623 b1dma_writel(card
, dma
->recvbuf
.dmaaddr
, AMCC_RXPTR
);
624 b1dma_writel(card
, 4, AMCC_RXLEN
);
628 if ((status
& TX_TC_INT
) != 0) {
629 if (skb_queue_empty(&card
->dma
->send_queue
))
630 card
->csr
&= ~EN_TX_TC_INT
;
632 b1dma_dispatch_tx(card
);
634 b1dma_writel(card
, card
->csr
, AMCC_INTCSR
);
636 spin_unlock(&card
->lock
);
639 irqreturn_t
b1dma_interrupt(int interrupt
, void *devptr
)
641 avmcard
*card
= devptr
;
643 b1dma_handle_interrupt(card
);
647 /* ------------------------------------------------------------- */
649 static int b1dma_loaded(avmcard
*card
)
653 unsigned long tout
= 2;
654 unsigned int base
= card
->port
;
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",
665 b1_put_byte(base
, SEND_POLLACK
);
666 for (stop
= jiffies
+ tout
* HZ
; time_before(jiffies
, stop
);) {
667 if (b1_rx_full(base
)) {
668 if ((ans
= b1_get_byte(base
)) == RECEIVE_POLLDWORD
) {
671 printk(KERN_ERR
"%s: b1dma_loaded: got 0x%x, firmware not running in dword mode\n", card
->name
, ans
);
675 printk(KERN_ERR
"%s: b1dma_loaded: firmware not running\n", card
->name
);
679 /* ------------------------------------------------------------- */
681 static void b1dma_send_init(avmcard
*card
)
686 skb
= alloc_skb(15, GFP_ATOMIC
);
688 printk(KERN_CRIT
"%s: no memory, lost register appl.\n",
695 _put_byte(&p
, SEND_INIT
);
696 _put_word(&p
, CAPI_MAXAPPL
);
697 _put_word(&p
, AVM_NCCI_PER_CHANNEL
* 30);
698 _put_word(&p
, card
->cardnr
- 1);
699 skb_put(skb
, (u8
*)p
- (u8
*)skb
->data
);
701 b1dma_queue_tx(card
, skb
);
704 int b1dma_load_firmware(struct capi_ctr
*ctrl
, capiloaddata
*data
)
706 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
707 avmcard
*card
= cinfo
->card
;
712 if ((retval
= b1_load_t4file(card
, &data
->firmware
))) {
714 printk(KERN_ERR
"%s: failed to load t4file!!\n",
719 if (data
->configuration
.len
> 0 && data
->configuration
.data
) {
720 if ((retval
= b1_load_config(card
, &data
->configuration
))) {
722 printk(KERN_ERR
"%s: failed to load config!!\n",
728 if (!b1dma_loaded(card
)) {
730 printk(KERN_ERR
"%s: failed to load t4file.\n", card
->name
);
734 card
->csr
= AVM_FLAG
;
735 b1dma_writel(card
, card
->csr
, AMCC_INTCSR
);
736 b1dma_writel(card
, EN_A2P_TRANSFERS
| EN_P2A_TRANSFERS
| A2P_HI_PRIORITY
|
737 P2A_HI_PRIORITY
| RESET_A2P_FLAGS
| RESET_P2A_FLAGS
,
739 t1outp(card
->port
, 0x07, 0x30);
740 t1outp(card
->port
, 0x10, 0xF0);
742 card
->dma
->recvlen
= 0;
743 b1dma_writel(card
, card
->dma
->recvbuf
.dmaaddr
, AMCC_RXPTR
);
744 b1dma_writel(card
, 4, AMCC_RXLEN
);
745 card
->csr
|= EN_RX_TC_INT
;
746 b1dma_writel(card
, card
->csr
, AMCC_INTCSR
);
748 b1dma_send_init(card
);
753 void b1dma_reset_ctr(struct capi_ctr
*ctrl
)
755 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
756 avmcard
*card
= cinfo
->card
;
759 spin_lock_irqsave(&card
->lock
, flags
);
762 memset(cinfo
->version
, 0, sizeof(cinfo
->version
));
763 capilib_release(&cinfo
->ncci_head
);
764 spin_unlock_irqrestore(&card
->lock
, flags
);
768 /* ------------------------------------------------------------- */
770 void b1dma_register_appl(struct capi_ctr
*ctrl
,
772 capi_register_params
*rp
)
774 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
775 avmcard
*card
= cinfo
->card
;
777 int want
= rp
->level3cnt
;
781 if (want
> 0) nconn
= want
;
782 else nconn
= ctrl
->profile
.nbchannel
* -want
;
783 if (nconn
== 0) nconn
= ctrl
->profile
.nbchannel
;
785 skb
= alloc_skb(23, GFP_ATOMIC
);
787 printk(KERN_CRIT
"%s: no memory, lost register appl.\n",
794 _put_byte(&p
, SEND_REGISTER
);
796 _put_word(&p
, 1024 * (nconn
+ 1));
797 _put_word(&p
, nconn
);
798 _put_word(&p
, rp
->datablkcnt
);
799 _put_word(&p
, rp
->datablklen
);
800 skb_put(skb
, (u8
*)p
- (u8
*)skb
->data
);
802 b1dma_queue_tx(card
, skb
);
805 /* ------------------------------------------------------------- */
807 void b1dma_release_appl(struct capi_ctr
*ctrl
, u16 appl
)
809 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
810 avmcard
*card
= cinfo
->card
;
815 spin_lock_irqsave(&card
->lock
, flags
);
816 capilib_release_appl(&cinfo
->ncci_head
, appl
);
817 spin_unlock_irqrestore(&card
->lock
, flags
);
819 skb
= alloc_skb(7, GFP_ATOMIC
);
821 printk(KERN_CRIT
"%s: no memory, lost release appl.\n",
828 _put_byte(&p
, SEND_RELEASE
);
831 skb_put(skb
, (u8
*)p
- (u8
*)skb
->data
);
833 b1dma_queue_tx(card
, skb
);
836 /* ------------------------------------------------------------- */
838 u16
b1dma_send_message(struct capi_ctr
*ctrl
, struct sk_buff
*skb
)
840 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
841 avmcard
*card
= cinfo
->card
;
842 u16 retval
= CAPI_NOERROR
;
844 if (CAPIMSG_CMD(skb
->data
) == CAPI_DATA_B3_REQ
) {
846 spin_lock_irqsave(&card
->lock
, flags
);
847 retval
= capilib_data_b3_req(&cinfo
->ncci_head
,
848 CAPIMSG_APPID(skb
->data
),
849 CAPIMSG_NCCI(skb
->data
),
850 CAPIMSG_MSGID(skb
->data
));
851 spin_unlock_irqrestore(&card
->lock
, flags
);
853 if (retval
== CAPI_NOERROR
)
854 b1dma_queue_tx(card
, skb
);
859 /* ------------------------------------------------------------- */
861 static int b1dmactl_proc_show(struct seq_file
*m
, void *v
)
863 struct capi_ctr
*ctrl
= m
->private;
864 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
865 avmcard
*card
= cinfo
->card
;
868 u32 txoff
, txlen
, rxoff
, rxlen
, csr
;
871 seq_printf(m
, "%-16s %s\n", "name", card
->name
);
872 seq_printf(m
, "%-16s 0x%x\n", "io", card
->port
);
873 seq_printf(m
, "%-16s %d\n", "irq", card
->irq
);
874 seq_printf(m
, "%-16s 0x%lx\n", "membase", card
->membase
);
875 switch (card
->cardtype
) {
876 case avm_b1isa
: s
= "B1 ISA"; break;
877 case avm_b1pci
: s
= "B1 PCI"; break;
878 case avm_b1pcmcia
: s
= "B1 PCMCIA"; break;
879 case avm_m1
: s
= "M1"; break;
880 case avm_m2
: s
= "M2"; break;
881 case avm_t1isa
: s
= "T1 ISA (HEMA)"; break;
882 case avm_t1pci
: s
= "T1 PCI"; break;
883 case avm_c4
: s
= "C4"; break;
884 case avm_c2
: s
= "C2"; break;
885 default: s
= "???"; break;
887 seq_printf(m
, "%-16s %s\n", "type", s
);
888 if ((s
= cinfo
->version
[VER_DRIVER
]) != NULL
)
889 seq_printf(m
, "%-16s %s\n", "ver_driver", s
);
890 if ((s
= cinfo
->version
[VER_CARDTYPE
]) != NULL
)
891 seq_printf(m
, "%-16s %s\n", "ver_cardtype", s
);
892 if ((s
= cinfo
->version
[VER_SERIAL
]) != NULL
)
893 seq_printf(m
, "%-16s %s\n", "ver_serial", s
);
895 if (card
->cardtype
!= avm_m1
) {
896 flag
= ((u8
*)(ctrl
->profile
.manu
))[3];
898 seq_printf(m
, "%-16s%s%s%s%s%s%s%s\n",
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" : ""
909 if (card
->cardtype
!= avm_m1
) {
910 flag
= ((u8
*)(ctrl
->profile
.manu
))[5];
912 seq_printf(m
, "%-16s%s%s%s%s\n",
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" : ""
920 seq_printf(m
, "%-16s %s\n", "cardname", cinfo
->cardname
);
923 spin_lock_irqsave(&card
->lock
, flags
);
925 txoff
= (dma_addr_t
)b1dma_readl(card
, AMCC_TXPTR
)-card
->dma
->sendbuf
.dmaaddr
;
926 txlen
= b1dma_readl(card
, AMCC_TXLEN
);
928 rxoff
= (dma_addr_t
)b1dma_readl(card
, AMCC_RXPTR
)-card
->dma
->recvbuf
.dmaaddr
;
929 rxlen
= b1dma_readl(card
, AMCC_RXLEN
);
931 csr
= b1dma_readl(card
, AMCC_INTCSR
);
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
);
945 static int b1dmactl_proc_open(struct inode
*inode
, struct file
*file
)
947 return single_open(file
, b1dmactl_proc_show
, PDE_DATA(inode
));
950 const struct file_operations b1dmactl_proc_fops
= {
951 .owner
= THIS_MODULE
,
952 .open
= b1dmactl_proc_open
,
955 .release
= single_release
,
957 EXPORT_SYMBOL(b1dmactl_proc_fops
);
959 /* ------------------------------------------------------------- */
961 EXPORT_SYMBOL(b1dma_reset
);
962 EXPORT_SYMBOL(t1pci_detect
);
963 EXPORT_SYMBOL(b1pciv4_detect
);
964 EXPORT_SYMBOL(b1dma_interrupt
);
966 EXPORT_SYMBOL(b1dma_load_firmware
);
967 EXPORT_SYMBOL(b1dma_reset_ctr
);
968 EXPORT_SYMBOL(b1dma_register_appl
);
969 EXPORT_SYMBOL(b1dma_release_appl
);
970 EXPORT_SYMBOL(b1dma_send_message
);
972 static int __init
b1dma_init(void)
977 if ((p
= strchr(revision
, ':')) != NULL
&& p
[1]) {
978 strlcpy(rev
, p
+ 2, sizeof(rev
));
979 if ((p
= strchr(rev
, '$')) != NULL
&& p
> rev
)
984 printk(KERN_INFO
"b1dma: revision %s\n", rev
);
989 static void __exit
b1dma_exit(void)
993 module_init(b1dma_init
);
994 module_exit(b1dma_exit
);