1 // SPDX-License-Identifier: GPL-2.0-only
5 * Author Karsten Keil <keil@isdn4linux.de>
7 * Copyright 2009 by Karsten Keil <keil@isdn4linux.de>
10 #include <linux/interrupt.h>
11 #include <linux/module.h>
12 #include <linux/pci.h>
13 #include <linux/delay.h>
14 #include <linux/mISDNhw.h>
15 #include <linux/slab.h>
21 #define NETJET_REV "2.0"
49 struct isdnhdlc_vars hsend
;
50 struct isdnhdlc_vars hrecv
;
55 #define TX_INIT 0x0001
56 #define TX_IDLE 0x0002
58 #define TX_UNDERRUN 0x0100
59 #define RX_OVERRUN 0x0100
64 struct list_head list
;
66 char name
[MISDN_MAX_IDLEN
];
74 spinlock_t lock
; /* lock HW */
76 struct tiger_dma send
;
77 struct tiger_dma recv
;
78 struct tiger_ch bc
[2];
87 static LIST_HEAD(Cards
);
88 static DEFINE_RWLOCK(card_lock
); /* protect Cards */
93 _set_debug(struct tiger_hw
*card
)
95 card
->isac
.dch
.debug
= debug
;
96 card
->bc
[0].bch
.debug
= debug
;
97 card
->bc
[1].bch
.debug
= debug
;
101 set_debug(const char *val
, const struct kernel_param
*kp
)
104 struct tiger_hw
*card
;
106 ret
= param_set_uint(val
, kp
);
108 read_lock(&card_lock
);
109 list_for_each_entry(card
, &Cards
, list
)
111 read_unlock(&card_lock
);
116 MODULE_AUTHOR("Karsten Keil");
117 MODULE_DESCRIPTION("mISDN driver for NETJet cards");
118 MODULE_LICENSE("GPL v2");
119 MODULE_VERSION(NETJET_REV
);
120 module_param_call(debug
, set_debug
, param_get_uint
, &debug
, S_IRUGO
| S_IWUSR
);
121 MODULE_PARM_DESC(debug
, "Netjet debug mask");
124 nj_disable_hwirq(struct tiger_hw
*card
)
126 outb(0, card
->base
+ NJ_IRQMASK0
);
127 outb(0, card
->base
+ NJ_IRQMASK1
);
132 ReadISAC_nj(void *p
, u8 offset
)
134 struct tiger_hw
*card
= p
;
138 card
->auxd
|= (offset
>> 4) & 3;
139 outb(card
->auxd
, card
->base
+ NJ_AUXDATA
);
140 ret
= inb(card
->base
+ NJ_ISAC_OFF
+ ((offset
& 0x0f) << 2));
145 WriteISAC_nj(void *p
, u8 offset
, u8 value
)
147 struct tiger_hw
*card
= p
;
150 card
->auxd
|= (offset
>> 4) & 3;
151 outb(card
->auxd
, card
->base
+ NJ_AUXDATA
);
152 outb(value
, card
->base
+ NJ_ISAC_OFF
+ ((offset
& 0x0f) << 2));
156 ReadFiFoISAC_nj(void *p
, u8 offset
, u8
*data
, int size
)
158 struct tiger_hw
*card
= p
;
161 outb(card
->auxd
, card
->base
+ NJ_AUXDATA
);
162 insb(card
->base
+ NJ_ISAC_OFF
, data
, size
);
166 WriteFiFoISAC_nj(void *p
, u8 offset
, u8
*data
, int size
)
168 struct tiger_hw
*card
= p
;
171 outb(card
->auxd
, card
->base
+ NJ_AUXDATA
);
172 outsb(card
->base
+ NJ_ISAC_OFF
, data
, size
);
176 fill_mem(struct tiger_ch
*bc
, u32 idx
, u32 cnt
, u32 fill
)
178 struct tiger_hw
*card
= bc
->bch
.hw
;
179 u32 mask
= 0xff, val
;
181 pr_debug("%s: B%1d fill %02x len %d idx %d/%d\n", card
->name
,
182 bc
->bch
.nr
, fill
, cnt
, idx
, card
->send
.idx
);
183 if (bc
->bch
.nr
& 2) {
189 val
= card
->send
.start
[idx
];
192 card
->send
.start
[idx
++] = val
;
193 if (idx
>= card
->send
.size
)
199 mode_tiger(struct tiger_ch
*bc
, u32 protocol
)
201 struct tiger_hw
*card
= bc
->bch
.hw
;
203 pr_debug("%s: B%1d protocol %x-->%x\n", card
->name
,
204 bc
->bch
.nr
, bc
->bch
.state
, protocol
);
207 if (bc
->bch
.state
== ISDN_P_NONE
)
209 fill_mem(bc
, 0, card
->send
.size
, 0xff);
210 bc
->bch
.state
= protocol
;
211 /* only stop dma and interrupts if both channels NULL */
212 if ((card
->bc
[0].bch
.state
== ISDN_P_NONE
) &&
213 (card
->bc
[1].bch
.state
== ISDN_P_NONE
)) {
215 outb(card
->dmactrl
, card
->base
+ NJ_DMACTRL
);
216 outb(0, card
->base
+ NJ_IRQMASK0
);
218 test_and_clear_bit(FLG_HDLC
, &bc
->bch
.Flags
);
219 test_and_clear_bit(FLG_TRANSPARENT
, &bc
->bch
.Flags
);
225 test_and_set_bit(FLG_TRANSPARENT
, &bc
->bch
.Flags
);
226 bc
->bch
.state
= protocol
;
228 bc
->free
= card
->send
.size
/ 2;
230 bc
->txstate
= TX_INIT
| TX_IDLE
;
232 if (!card
->dmactrl
) {
234 outb(card
->dmactrl
, card
->base
+ NJ_DMACTRL
);
235 outb(0x0f, card
->base
+ NJ_IRQMASK0
);
239 test_and_set_bit(FLG_HDLC
, &bc
->bch
.Flags
);
240 bc
->bch
.state
= protocol
;
242 bc
->free
= card
->send
.size
/ 2;
244 bc
->txstate
= TX_INIT
| TX_IDLE
;
245 isdnhdlc_rcv_init(&bc
->hrecv
, 0);
246 isdnhdlc_out_init(&bc
->hsend
, 0);
248 if (!card
->dmactrl
) {
250 outb(card
->dmactrl
, card
->base
+ NJ_DMACTRL
);
251 outb(0x0f, card
->base
+ NJ_IRQMASK0
);
255 pr_info("%s: %s protocol %x not handled\n", card
->name
,
259 card
->send
.dmacur
= inl(card
->base
+ NJ_DMA_READ_ADR
);
260 card
->recv
.dmacur
= inl(card
->base
+ NJ_DMA_WRITE_ADR
);
261 card
->send
.idx
= (card
->send
.dmacur
- card
->send
.dmastart
) >> 2;
262 card
->recv
.idx
= (card
->recv
.dmacur
- card
->recv
.dmastart
) >> 2;
263 pr_debug("%s: %s ctrl %x irq %02x/%02x idx %d/%d\n",
264 card
->name
, __func__
,
265 inb(card
->base
+ NJ_DMACTRL
),
266 inb(card
->base
+ NJ_IRQMASK0
),
267 inb(card
->base
+ NJ_IRQSTAT0
),
274 nj_reset(struct tiger_hw
*card
)
276 outb(0xff, card
->base
+ NJ_CTRL
); /* Reset On */
279 /* now edge triggered for TJ320 GE 13/07/00 */
280 /* see comment in IRQ function */
281 if (card
->typ
== NETJET_S_TJ320
) /* TJ320 */
282 card
->ctrlreg
= 0x40; /* Reset Off and status read clear */
284 card
->ctrlreg
= 0x00; /* Reset Off and status read clear */
285 outb(card
->ctrlreg
, card
->base
+ NJ_CTRL
);
288 /* configure AUX pins (all output except ISAC IRQ pin) */
291 outb(~NJ_ISACIRQ
, card
->base
+ NJ_AUXCTRL
);
292 outb(NJ_ISACIRQ
, card
->base
+ NJ_IRQMASK1
);
293 outb(card
->auxd
, card
->base
+ NJ_AUXDATA
);
297 inittiger(struct tiger_hw
*card
)
301 card
->dma_p
= dma_alloc_coherent(&card
->pdev
->dev
, NJ_DMA_SIZE
,
302 &card
->dma
, GFP_ATOMIC
);
304 pr_info("%s: No DMA memory\n", card
->name
);
307 if ((u64
)card
->dma
> 0xffffffff) {
308 pr_info("%s: DMA outside 32 bit\n", card
->name
);
311 for (i
= 0; i
< 2; i
++) {
312 card
->bc
[i
].hsbuf
= kmalloc(NJ_DMA_TXSIZE
, GFP_ATOMIC
);
313 if (!card
->bc
[i
].hsbuf
) {
314 pr_info("%s: no B%d send buffer\n", card
->name
, i
+ 1);
317 card
->bc
[i
].hrbuf
= kmalloc(NJ_DMA_RXSIZE
, GFP_ATOMIC
);
318 if (!card
->bc
[i
].hrbuf
) {
319 pr_info("%s: no B%d recv buffer\n", card
->name
, i
+ 1);
323 memset(card
->dma_p
, 0xff, NJ_DMA_SIZE
);
325 card
->send
.start
= card
->dma_p
;
326 card
->send
.dmastart
= (u32
)card
->dma
;
327 card
->send
.dmaend
= card
->send
.dmastart
+
328 (4 * (NJ_DMA_TXSIZE
- 1));
329 card
->send
.dmairq
= card
->send
.dmastart
+
330 (4 * ((NJ_DMA_TXSIZE
/ 2) - 1));
331 card
->send
.size
= NJ_DMA_TXSIZE
;
333 if (debug
& DEBUG_HW
)
334 pr_notice("%s: send buffer phy %#x - %#x - %#x virt %p"
335 " size %zu u32\n", card
->name
,
336 card
->send
.dmastart
, card
->send
.dmairq
,
337 card
->send
.dmaend
, card
->send
.start
, card
->send
.size
);
339 outl(card
->send
.dmastart
, card
->base
+ NJ_DMA_READ_START
);
340 outl(card
->send
.dmairq
, card
->base
+ NJ_DMA_READ_IRQ
);
341 outl(card
->send
.dmaend
, card
->base
+ NJ_DMA_READ_END
);
343 card
->recv
.start
= card
->dma_p
+ (NJ_DMA_SIZE
/ 2);
344 card
->recv
.dmastart
= (u32
)card
->dma
+ (NJ_DMA_SIZE
/ 2);
345 card
->recv
.dmaend
= card
->recv
.dmastart
+
346 (4 * (NJ_DMA_RXSIZE
- 1));
347 card
->recv
.dmairq
= card
->recv
.dmastart
+
348 (4 * ((NJ_DMA_RXSIZE
/ 2) - 1));
349 card
->recv
.size
= NJ_DMA_RXSIZE
;
351 if (debug
& DEBUG_HW
)
352 pr_notice("%s: recv buffer phy %#x - %#x - %#x virt %p"
353 " size %zu u32\n", card
->name
,
354 card
->recv
.dmastart
, card
->recv
.dmairq
,
355 card
->recv
.dmaend
, card
->recv
.start
, card
->recv
.size
);
357 outl(card
->recv
.dmastart
, card
->base
+ NJ_DMA_WRITE_START
);
358 outl(card
->recv
.dmairq
, card
->base
+ NJ_DMA_WRITE_IRQ
);
359 outl(card
->recv
.dmaend
, card
->base
+ NJ_DMA_WRITE_END
);
364 read_dma(struct tiger_ch
*bc
, u32 idx
, int cnt
)
366 struct tiger_hw
*card
= bc
->bch
.hw
;
371 if (bc
->lastrx
== idx
) {
372 bc
->rxstate
|= RX_OVERRUN
;
373 pr_info("%s: B%1d overrun at idx %d\n", card
->name
,
377 if (test_bit(FLG_RX_OFF
, &bc
->bch
.Flags
)) {
378 bc
->bch
.dropcnt
+= cnt
;
381 stat
= bchannel_get_rxbuf(&bc
->bch
, cnt
);
382 /* only transparent use the count here, HDLC overun is detected later */
383 if (stat
== -ENOMEM
) {
384 pr_warn("%s.B%d: No memory for %d bytes\n",
385 card
->name
, bc
->bch
.nr
, cnt
);
388 if (test_bit(FLG_TRANSPARENT
, &bc
->bch
.Flags
))
389 p
= skb_put(bc
->bch
.rx_skb
, cnt
);
393 for (i
= 0; i
< cnt
; i
++) {
394 val
= card
->recv
.start
[idx
++];
397 if (idx
>= card
->recv
.size
)
402 if (test_bit(FLG_TRANSPARENT
, &bc
->bch
.Flags
)) {
403 recv_Bchannel(&bc
->bch
, 0, false);
409 stat
= isdnhdlc_decode(&bc
->hrecv
, pn
, cnt
, &i
,
410 bc
->bch
.rx_skb
->data
, bc
->bch
.maxlen
);
411 if (stat
> 0) { /* valid frame received */
412 p
= skb_put(bc
->bch
.rx_skb
, stat
);
413 if (debug
& DEBUG_HW_BFIFO
) {
414 snprintf(card
->log
, LOG_SIZE
,
415 "B%1d-recv %s %d ", bc
->bch
.nr
,
417 print_hex_dump_bytes(card
->log
,
418 DUMP_PREFIX_OFFSET
, p
,
421 recv_Bchannel(&bc
->bch
, 0, false);
422 stat
= bchannel_get_rxbuf(&bc
->bch
, bc
->bch
.maxlen
);
424 pr_warn("%s.B%d: No memory for %d bytes\n",
425 card
->name
, bc
->bch
.nr
, cnt
);
428 } else if (stat
== -HDLC_CRC_ERROR
) {
429 pr_info("%s: B%1d receive frame CRC error\n",
430 card
->name
, bc
->bch
.nr
);
431 } else if (stat
== -HDLC_FRAMING_ERROR
) {
432 pr_info("%s: B%1d receive framing error\n",
433 card
->name
, bc
->bch
.nr
);
434 } else if (stat
== -HDLC_LENGTH_ERROR
) {
435 pr_info("%s: B%1d receive frame too long (> %d)\n",
436 card
->name
, bc
->bch
.nr
, bc
->bch
.maxlen
);
444 recv_tiger(struct tiger_hw
*card
, u8 irq_stat
)
447 int cnt
= card
->recv
.size
/ 2;
449 /* Note receive is via the WRITE DMA channel */
450 card
->last_is0
&= ~NJ_IRQM0_WR_MASK
;
451 card
->last_is0
|= (irq_stat
& NJ_IRQM0_WR_MASK
);
453 if (irq_stat
& NJ_IRQM0_WR_END
)
456 idx
= card
->recv
.size
- 1;
458 if (test_bit(FLG_ACTIVE
, &card
->bc
[0].bch
.Flags
))
459 read_dma(&card
->bc
[0], idx
, cnt
);
460 if (test_bit(FLG_ACTIVE
, &card
->bc
[1].bch
.Flags
))
461 read_dma(&card
->bc
[1], idx
, cnt
);
464 /* sync with current DMA address at start or after exception */
466 resync(struct tiger_ch
*bc
, struct tiger_hw
*card
)
468 card
->send
.dmacur
= inl(card
->base
| NJ_DMA_READ_ADR
);
469 card
->send
.idx
= (card
->send
.dmacur
- card
->send
.dmastart
) >> 2;
470 if (bc
->free
> card
->send
.size
/ 2)
471 bc
->free
= card
->send
.size
/ 2;
472 /* currently we simple sync to the next complete free area
473 * this hast the advantage that we have always maximum time to
476 if (card
->send
.idx
< ((card
->send
.size
/ 2) - 1))
477 bc
->idx
= (card
->recv
.size
/ 2) - 1;
479 bc
->idx
= card
->recv
.size
- 1;
480 bc
->txstate
= TX_RUN
;
481 pr_debug("%s: %s B%1d free %d idx %d/%d\n", card
->name
,
482 __func__
, bc
->bch
.nr
, bc
->free
, bc
->idx
, card
->send
.idx
);
485 static int bc_next_frame(struct tiger_ch
*);
488 fill_hdlc_flag(struct tiger_ch
*bc
)
490 struct tiger_hw
*card
= bc
->bch
.hw
;
497 pr_debug("%s: %s B%1d %d state %x idx %d/%d\n", card
->name
,
498 __func__
, bc
->bch
.nr
, bc
->free
, bc
->txstate
,
499 bc
->idx
, card
->send
.idx
);
500 if (bc
->txstate
& (TX_IDLE
| TX_INIT
| TX_UNDERRUN
))
502 count
= isdnhdlc_encode(&bc
->hsend
, NULL
, 0, &i
,
503 bc
->hsbuf
, bc
->free
);
504 pr_debug("%s: B%1d hdlc encoded %d flags\n", card
->name
,
508 m
= (bc
->bch
.nr
& 1) ? 0xffffff00 : 0xffff00ff;
509 for (i
= 0; i
< count
; i
++) {
510 if (bc
->idx
>= card
->send
.size
)
512 v
= card
->send
.start
[bc
->idx
];
514 v
|= (bc
->bch
.nr
& 1) ? (u32
)(p
[i
]) : ((u32
)(p
[i
])) << 8;
515 card
->send
.start
[bc
->idx
++] = v
;
517 if (debug
& DEBUG_HW_BFIFO
) {
518 snprintf(card
->log
, LOG_SIZE
, "B%1d-send %s %d ",
519 bc
->bch
.nr
, card
->name
, count
);
520 print_hex_dump_bytes(card
->log
, DUMP_PREFIX_OFFSET
, p
, count
);
525 fill_dma(struct tiger_ch
*bc
)
527 struct tiger_hw
*card
= bc
->bch
.hw
;
528 int count
, i
, fillempty
= 0;
534 if (!bc
->bch
.tx_skb
) {
535 if (!test_bit(FLG_TX_EMPTY
, &bc
->bch
.Flags
))
538 count
= card
->send
.size
>> 1;
541 count
= bc
->bch
.tx_skb
->len
- bc
->bch
.tx_idx
;
544 pr_debug("%s: %s B%1d %d/%d/%d/%d state %x idx %d/%d\n",
545 card
->name
, __func__
, bc
->bch
.nr
, count
, bc
->free
,
546 bc
->bch
.tx_idx
, bc
->bch
.tx_skb
->len
, bc
->txstate
,
547 bc
->idx
, card
->send
.idx
);
548 p
= bc
->bch
.tx_skb
->data
+ bc
->bch
.tx_idx
;
550 if (bc
->txstate
& (TX_IDLE
| TX_INIT
| TX_UNDERRUN
))
552 if (test_bit(FLG_HDLC
, &bc
->bch
.Flags
) && !fillempty
) {
553 count
= isdnhdlc_encode(&bc
->hsend
, p
, count
, &i
,
554 bc
->hsbuf
, bc
->free
);
555 pr_debug("%s: B%1d hdlc encoded %d in %d\n", card
->name
,
556 bc
->bch
.nr
, i
, count
);
561 if (count
> bc
->free
)
564 bc
->bch
.tx_idx
+= count
;
567 m
= (bc
->bch
.nr
& 1) ? 0xffffff00 : 0xffff00ff;
570 if (!(bc
->bch
.nr
& 1))
572 for (i
= 0; i
< count
; i
++) {
573 if (bc
->idx
>= card
->send
.size
)
575 v
= card
->send
.start
[bc
->idx
];
578 card
->send
.start
[bc
->idx
++] = v
;
581 for (i
= 0; i
< count
; i
++) {
582 if (bc
->idx
>= card
->send
.size
)
584 v
= card
->send
.start
[bc
->idx
];
587 v
|= (bc
->bch
.nr
& 1) ? n
: n
<< 8;
588 card
->send
.start
[bc
->idx
++] = v
;
591 if (debug
& DEBUG_HW_BFIFO
) {
592 snprintf(card
->log
, LOG_SIZE
, "B%1d-send %s %d ",
593 bc
->bch
.nr
, card
->name
, count
);
594 print_hex_dump_bytes(card
->log
, DUMP_PREFIX_OFFSET
, p
, count
);
602 bc_next_frame(struct tiger_ch
*bc
)
606 if (bc
->bch
.tx_skb
&& bc
->bch
.tx_idx
< bc
->bch
.tx_skb
->len
) {
609 dev_kfree_skb(bc
->bch
.tx_skb
);
610 if (get_next_bframe(&bc
->bch
)) {
612 test_and_clear_bit(FLG_TX_EMPTY
, &bc
->bch
.Flags
);
613 } else if (test_bit(FLG_TX_EMPTY
, &bc
->bch
.Flags
)) {
615 } else if (test_bit(FLG_FILLEMPTY
, &bc
->bch
.Flags
)) {
616 test_and_set_bit(FLG_TX_EMPTY
, &bc
->bch
.Flags
);
626 send_tiger_bc(struct tiger_hw
*card
, struct tiger_ch
*bc
)
630 bc
->free
+= card
->send
.size
/ 2;
631 if (bc
->free
>= card
->send
.size
) {
632 if (!(bc
->txstate
& (TX_UNDERRUN
| TX_INIT
))) {
633 pr_info("%s: B%1d TX underrun state %x\n", card
->name
,
634 bc
->bch
.nr
, bc
->txstate
);
635 bc
->txstate
|= TX_UNDERRUN
;
637 bc
->free
= card
->send
.size
;
639 ret
= bc_next_frame(bc
);
641 if (test_bit(FLG_HDLC
, &bc
->bch
.Flags
)) {
645 pr_debug("%s: B%1d TX no data free %d idx %d/%d\n", card
->name
,
646 bc
->bch
.nr
, bc
->free
, bc
->idx
, card
->send
.idx
);
647 if (!(bc
->txstate
& (TX_IDLE
| TX_INIT
))) {
648 fill_mem(bc
, bc
->idx
, bc
->free
, 0xff);
649 if (bc
->free
== card
->send
.size
)
650 bc
->txstate
|= TX_IDLE
;
656 send_tiger(struct tiger_hw
*card
, u8 irq_stat
)
660 /* Note send is via the READ DMA channel */
661 if ((irq_stat
& card
->last_is0
) & NJ_IRQM0_RD_MASK
) {
662 pr_info("%s: tiger warn write double dma %x/%x\n",
663 card
->name
, irq_stat
, card
->last_is0
);
666 card
->last_is0
&= ~NJ_IRQM0_RD_MASK
;
667 card
->last_is0
|= (irq_stat
& NJ_IRQM0_RD_MASK
);
669 for (i
= 0; i
< 2; i
++) {
670 if (test_bit(FLG_ACTIVE
, &card
->bc
[i
].bch
.Flags
))
671 send_tiger_bc(card
, &card
->bc
[i
]);
676 nj_irq(int intno
, void *dev_id
)
678 struct tiger_hw
*card
= dev_id
;
679 u8 val
, s1val
, s0val
;
681 spin_lock(&card
->lock
);
682 s0val
= inb(card
->base
| NJ_IRQSTAT0
);
683 s1val
= inb(card
->base
| NJ_IRQSTAT1
);
684 if ((s1val
& NJ_ISACIRQ
) && (s0val
== 0)) {
686 spin_unlock(&card
->lock
);
689 pr_debug("%s: IRQSTAT0 %02x IRQSTAT1 %02x\n", card
->name
, s0val
, s1val
);
691 if (!(s1val
& NJ_ISACIRQ
)) {
692 val
= ReadISAC_nj(card
, ISAC_ISTA
);
694 mISDNisac_irq(&card
->isac
, val
);
699 outb(s0val
, card
->base
| NJ_IRQSTAT0
);
703 /* set bits in sval to indicate which page is free */
704 card
->recv
.dmacur
= inl(card
->base
| NJ_DMA_WRITE_ADR
);
705 card
->recv
.idx
= (card
->recv
.dmacur
- card
->recv
.dmastart
) >> 2;
706 if (card
->recv
.dmacur
< card
->recv
.dmairq
)
707 s0val
= 0x08; /* the 2nd write area is free */
709 s0val
= 0x04; /* the 1st write area is free */
711 card
->send
.dmacur
= inl(card
->base
| NJ_DMA_READ_ADR
);
712 card
->send
.idx
= (card
->send
.dmacur
- card
->send
.dmastart
) >> 2;
713 if (card
->send
.dmacur
< card
->send
.dmairq
)
714 s0val
|= 0x02; /* the 2nd read area is free */
716 s0val
|= 0x01; /* the 1st read area is free */
718 pr_debug("%s: DMA Status %02x/%02x/%02x %d/%d\n", card
->name
,
719 s1val
, s0val
, card
->last_is0
,
720 card
->recv
.idx
, card
->send
.idx
);
721 /* test if we have a DMA interrupt */
722 if (s0val
!= card
->last_is0
) {
723 if ((s0val
& NJ_IRQM0_RD_MASK
) !=
724 (card
->last_is0
& NJ_IRQM0_RD_MASK
))
725 /* got a write dma int */
726 send_tiger(card
, s0val
);
727 if ((s0val
& NJ_IRQM0_WR_MASK
) !=
728 (card
->last_is0
& NJ_IRQM0_WR_MASK
))
729 /* got a read dma int */
730 recv_tiger(card
, s0val
);
733 spin_unlock(&card
->lock
);
738 nj_l2l1B(struct mISDNchannel
*ch
, struct sk_buff
*skb
)
741 struct bchannel
*bch
= container_of(ch
, struct bchannel
, ch
);
742 struct tiger_ch
*bc
= container_of(bch
, struct tiger_ch
, bch
);
743 struct tiger_hw
*card
= bch
->hw
;
744 struct mISDNhead
*hh
= mISDN_HEAD_P(skb
);
749 spin_lock_irqsave(&card
->lock
, flags
);
750 ret
= bchannel_senddata(bch
, skb
);
751 if (ret
> 0) { /* direct TX */
755 spin_unlock_irqrestore(&card
->lock
, flags
);
757 case PH_ACTIVATE_REQ
:
758 spin_lock_irqsave(&card
->lock
, flags
);
759 if (!test_and_set_bit(FLG_ACTIVE
, &bch
->Flags
))
760 ret
= mode_tiger(bc
, ch
->protocol
);
763 spin_unlock_irqrestore(&card
->lock
, flags
);
765 _queue_data(ch
, PH_ACTIVATE_IND
, MISDN_ID_ANY
, 0,
768 case PH_DEACTIVATE_REQ
:
769 spin_lock_irqsave(&card
->lock
, flags
);
770 mISDN_clear_bchannel(bch
);
771 mode_tiger(bc
, ISDN_P_NONE
);
772 spin_unlock_irqrestore(&card
->lock
, flags
);
773 _queue_data(ch
, PH_DEACTIVATE_IND
, MISDN_ID_ANY
, 0,
784 channel_bctrl(struct tiger_ch
*bc
, struct mISDN_ctrl_req
*cq
)
786 return mISDN_ctrl_bchannel(&bc
->bch
, cq
);
790 nj_bctrl(struct mISDNchannel
*ch
, u32 cmd
, void *arg
)
792 struct bchannel
*bch
= container_of(ch
, struct bchannel
, ch
);
793 struct tiger_ch
*bc
= container_of(bch
, struct tiger_ch
, bch
);
794 struct tiger_hw
*card
= bch
->hw
;
798 pr_debug("%s: %s cmd:%x %p\n", card
->name
, __func__
, cmd
, arg
);
801 test_and_clear_bit(FLG_OPEN
, &bch
->Flags
);
802 cancel_work_sync(&bch
->workq
);
803 spin_lock_irqsave(&card
->lock
, flags
);
804 mISDN_clear_bchannel(bch
);
805 mode_tiger(bc
, ISDN_P_NONE
);
806 spin_unlock_irqrestore(&card
->lock
, flags
);
807 ch
->protocol
= ISDN_P_NONE
;
809 module_put(THIS_MODULE
);
812 case CONTROL_CHANNEL
:
813 ret
= channel_bctrl(bc
, arg
);
816 pr_info("%s: %s unknown prim(%x)\n", card
->name
, __func__
, cmd
);
822 channel_ctrl(struct tiger_hw
*card
, struct mISDN_ctrl_req
*cq
)
827 case MISDN_CTRL_GETOP
:
828 cq
->op
= MISDN_CTRL_LOOP
| MISDN_CTRL_L1_TIMER3
;
830 case MISDN_CTRL_LOOP
:
831 /* cq->channel: 0 disable, 1 B1 loop 2 B2 loop, 3 both */
832 if (cq
->channel
< 0 || cq
->channel
> 3) {
836 ret
= card
->isac
.ctrl(&card
->isac
, HW_TESTLOOP
, cq
->channel
);
838 case MISDN_CTRL_L1_TIMER3
:
839 ret
= card
->isac
.ctrl(&card
->isac
, HW_TIMER3_VALUE
, cq
->p1
);
842 pr_info("%s: %s unknown Op %x\n", card
->name
, __func__
, cq
->op
);
850 open_bchannel(struct tiger_hw
*card
, struct channel_req
*rq
)
852 struct bchannel
*bch
;
854 if (rq
->adr
.channel
== 0 || rq
->adr
.channel
> 2)
856 if (rq
->protocol
== ISDN_P_NONE
)
858 bch
= &card
->bc
[rq
->adr
.channel
- 1].bch
;
859 if (test_and_set_bit(FLG_OPEN
, &bch
->Flags
))
860 return -EBUSY
; /* b-channel can be only open once */
861 test_and_clear_bit(FLG_FILLEMPTY
, &bch
->Flags
);
862 bch
->ch
.protocol
= rq
->protocol
;
868 * device control function
871 nj_dctrl(struct mISDNchannel
*ch
, u32 cmd
, void *arg
)
873 struct mISDNdevice
*dev
= container_of(ch
, struct mISDNdevice
, D
);
874 struct dchannel
*dch
= container_of(dev
, struct dchannel
, dev
);
875 struct tiger_hw
*card
= dch
->hw
;
876 struct channel_req
*rq
;
879 pr_debug("%s: %s cmd:%x %p\n", card
->name
, __func__
, cmd
, arg
);
883 if (rq
->protocol
== ISDN_P_TE_S0
)
884 err
= card
->isac
.open(&card
->isac
, rq
);
886 err
= open_bchannel(card
, rq
);
889 if (!try_module_get(THIS_MODULE
))
890 pr_info("%s: cannot get module\n", card
->name
);
893 pr_debug("%s: dev(%d) close from %p\n", card
->name
, dch
->dev
.id
,
894 __builtin_return_address(0));
895 module_put(THIS_MODULE
);
897 case CONTROL_CHANNEL
:
898 err
= channel_ctrl(card
, arg
);
901 pr_debug("%s: %s unknown command %x\n",
902 card
->name
, __func__
, cmd
);
909 nj_init_card(struct tiger_hw
*card
)
914 spin_lock_irqsave(&card
->lock
, flags
);
915 nj_disable_hwirq(card
);
916 spin_unlock_irqrestore(&card
->lock
, flags
);
918 card
->irq
= card
->pdev
->irq
;
919 if (request_irq(card
->irq
, nj_irq
, IRQF_SHARED
, card
->name
, card
)) {
920 pr_info("%s: couldn't get interrupt %d\n",
921 card
->name
, card
->irq
);
926 spin_lock_irqsave(&card
->lock
, flags
);
928 ret
= card
->isac
.init(&card
->isac
);
931 ret
= inittiger(card
);
934 mode_tiger(&card
->bc
[0], ISDN_P_NONE
);
935 mode_tiger(&card
->bc
[1], ISDN_P_NONE
);
937 spin_unlock_irqrestore(&card
->lock
, flags
);
943 nj_release(struct tiger_hw
*card
)
949 spin_lock_irqsave(&card
->lock
, flags
);
950 nj_disable_hwirq(card
);
951 mode_tiger(&card
->bc
[0], ISDN_P_NONE
);
952 mode_tiger(&card
->bc
[1], ISDN_P_NONE
);
953 spin_unlock_irqrestore(&card
->lock
, flags
);
954 card
->isac
.release(&card
->isac
);
955 release_region(card
->base
, card
->base_s
);
959 free_irq(card
->irq
, card
);
960 if (device_is_registered(&card
->isac
.dch
.dev
.dev
))
961 mISDN_unregister_device(&card
->isac
.dch
.dev
);
963 for (i
= 0; i
< 2; i
++) {
964 mISDN_freebchannel(&card
->bc
[i
].bch
);
965 kfree(card
->bc
[i
].hsbuf
);
966 kfree(card
->bc
[i
].hrbuf
);
969 dma_free_coherent(&card
->pdev
->dev
, NJ_DMA_SIZE
, card
->dma_p
,
971 write_lock_irqsave(&card_lock
, flags
);
972 list_del(&card
->list
);
973 write_unlock_irqrestore(&card_lock
, flags
);
974 pci_disable_device(card
->pdev
);
975 pci_set_drvdata(card
->pdev
, NULL
);
981 nj_setup(struct tiger_hw
*card
)
983 card
->base
= pci_resource_start(card
->pdev
, 0);
984 card
->base_s
= pci_resource_len(card
->pdev
, 0);
985 if (!request_region(card
->base
, card
->base_s
, card
->name
)) {
986 pr_info("%s: NETjet config port %#x-%#x already in use\n",
987 card
->name
, card
->base
,
988 (u32
)(card
->base
+ card
->base_s
- 1));
992 ASSIGN_FUNC(nj
, ISAC
, card
->isac
);
998 setup_instance(struct tiger_hw
*card
)
1003 snprintf(card
->name
, MISDN_MAX_IDLEN
- 1, "netjet.%d", nj_cnt
+ 1);
1004 write_lock_irqsave(&card_lock
, flags
);
1005 list_add_tail(&card
->list
, &Cards
);
1006 write_unlock_irqrestore(&card_lock
, flags
);
1009 card
->isac
.name
= card
->name
;
1010 spin_lock_init(&card
->lock
);
1011 card
->isac
.hwlock
= &card
->lock
;
1012 mISDNisac_init(&card
->isac
, card
);
1014 card
->isac
.dch
.dev
.Bprotocols
= (1 << (ISDN_P_B_RAW
& ISDN_P_B_MASK
)) |
1015 (1 << (ISDN_P_B_HDLC
& ISDN_P_B_MASK
));
1016 card
->isac
.dch
.dev
.D
.ctrl
= nj_dctrl
;
1017 for (i
= 0; i
< 2; i
++) {
1018 card
->bc
[i
].bch
.nr
= i
+ 1;
1019 set_channelmap(i
+ 1, card
->isac
.dch
.dev
.channelmap
);
1020 mISDN_initbchannel(&card
->bc
[i
].bch
, MAX_DATA_MEM
,
1021 NJ_DMA_RXSIZE
>> 1);
1022 card
->bc
[i
].bch
.hw
= card
;
1023 card
->bc
[i
].bch
.ch
.send
= nj_l2l1B
;
1024 card
->bc
[i
].bch
.ch
.ctrl
= nj_bctrl
;
1025 card
->bc
[i
].bch
.ch
.nr
= i
+ 1;
1026 list_add(&card
->bc
[i
].bch
.ch
.list
,
1027 &card
->isac
.dch
.dev
.bchannels
);
1028 card
->bc
[i
].bch
.hw
= card
;
1030 err
= nj_setup(card
);
1033 err
= mISDN_register_device(&card
->isac
.dch
.dev
, &card
->pdev
->dev
,
1037 err
= nj_init_card(card
);
1040 pr_notice("Netjet %d cards installed\n", nj_cnt
);
1049 nj_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
1053 struct tiger_hw
*card
;
1055 if (pdev
->subsystem_vendor
== 0x8086 &&
1056 pdev
->subsystem_device
== 0x0003) {
1057 pr_notice("Netjet: Digium X100P/X101P not handled\n");
1061 if (pdev
->subsystem_vendor
== 0x55 &&
1062 pdev
->subsystem_device
== 0x02) {
1063 pr_notice("Netjet: Enter!Now not handled yet\n");
1067 if (pdev
->subsystem_vendor
== 0xb100 &&
1068 pdev
->subsystem_device
== 0x0003) {
1069 pr_notice("Netjet: Digium TDM400P not handled yet\n");
1073 card
= kzalloc(sizeof(struct tiger_hw
), GFP_KERNEL
);
1075 pr_info("No kmem for Netjet\n");
1081 err
= pci_enable_device(pdev
);
1087 printk(KERN_INFO
"nj_probe(mISDN): found adapter at %s\n",
1090 pci_set_master(pdev
);
1092 /* the TJ300 and TJ320 must be detected, the IRQ handling is different
1093 * unfortunately the chips use the same device ID, but the TJ320 has
1094 * the bit20 in status PCI cfg register set
1096 pci_read_config_dword(pdev
, 0x04, &cfg
);
1097 if (cfg
& 0x00100000)
1098 card
->typ
= NETJET_S_TJ320
;
1100 card
->typ
= NETJET_S_TJ300
;
1102 card
->base
= pci_resource_start(pdev
, 0);
1103 pci_set_drvdata(pdev
, card
);
1104 err
= setup_instance(card
);
1106 pci_set_drvdata(pdev
, NULL
);
1112 static void nj_remove(struct pci_dev
*pdev
)
1114 struct tiger_hw
*card
= pci_get_drvdata(pdev
);
1119 pr_info("%s drvdata already removed\n", __func__
);
1122 /* We cannot select cards with PCI_SUB... IDs, since here are cards with
1123 * SUB IDs set to PCI_ANY_ID, so we need to match all and reject
1124 * known other cards which not work with this driver - see probe function */
1125 static const struct pci_device_id nj_pci_ids
[] = {
1126 { PCI_VENDOR_ID_TIGERJET
, PCI_DEVICE_ID_TIGERJET_300
,
1127 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
1130 MODULE_DEVICE_TABLE(pci
, nj_pci_ids
);
1132 static struct pci_driver nj_driver
= {
1135 .remove
= nj_remove
,
1136 .id_table
= nj_pci_ids
,
1139 static int __init
nj_init(void)
1143 pr_notice("Netjet PCI driver Rev. %s\n", NETJET_REV
);
1144 err
= pci_register_driver(&nj_driver
);
1148 static void __exit
nj_cleanup(void)
1150 pci_unregister_driver(&nj_driver
);
1153 module_init(nj_init
);
1154 module_exit(nj_cleanup
);