24 #include <linux/module.h>
25 #include <linux/pci.h>
28 #include <linux/slab.h>
34 #define NETJET_REV "2.0"
68 #define TX_INIT 0x0001
69 #define TX_IDLE 0x0002
71 #define TX_UNDERRUN 0x0100
72 #define RX_OVERRUN 0x0100
150 card->
auxd |= (offset >> 4) & 3;
162 card->
auxd |= (offset >> 4) & 3;
193 pr_debug(
"%s: B%1d fill %02x len %d idx %d/%d\n", card->
name,
194 bc->
bch.nr, fill, cnt, idx, card->
send.idx);
195 if (bc->
bch.nr & 2) {
205 if (idx >= card->
send.size)
216 bc->
bch.nr, bc->
bch.state, protocol);
221 fill_mem(bc, 0, card->
send.size, 0xff);
267 pr_info(
"%s: %s protocol %x not handled\n", card->
name,
273 card->
send.idx = (card->
send.dmacur - card->
send.dmastart) >> 2;
274 card->
recv.idx = (card->
recv.dmacur - card->
recv.dmastart) >> 2;
275 pr_debug(
"%s: %s ctrl %x irq %02x/%02x idx %d/%d\n",
276 card->
name, __func__,
319 if ((
u64)card->
dma > 0xffffffff) {
323 for (i = 0; i < 2; i++) {
325 if (!card->
bc[i].hsbuf) {
326 pr_info(
"%s: no B%d send buffer\n", card->
name, i + 1);
330 if (!card->
bc[i].hrbuf) {
331 pr_info(
"%s: no B%d recv buffer\n", card->
name, i + 1);
339 card->
send.dmaend = card->
send.dmastart +
341 card->
send.dmairq = card->
send.dmastart +
346 pr_notice(
"%s: send buffer phy %#x - %#x - %#x virt %p"
347 " size %zu u32\n", card->
name,
348 card->
send.dmastart, card->
send.dmairq,
357 card->
recv.dmaend = card->
recv.dmastart +
359 card->
recv.dmairq = card->
recv.dmastart +
363 if (
debug & DEBUG_HW)
364 pr_notice(
"%s: recv buffer phy %#x - %#x - %#x virt %p"
365 " size %zu u32\n", card->
name,
366 card->
recv.dmastart, card->
recv.dmairq,
385 pr_info(
"%s: B%1d overrun at idx %d\n", card->
name,
396 pr_warning(
"%s.B%d: No memory for %d bytes\n",
405 for (i = 0; i <
cnt; i++) {
406 val = card->
recv.start[idx++];
409 if (idx >= card->
recv.size)
422 bc->
bch.rx_skb->data, bc->
bch.maxlen);
427 "B%1d-recv %s %d ", bc->
bch.nr,
429 print_hex_dump_bytes(card->
log,
436 pr_warning(
"%s.B%d: No memory for %d bytes\n",
441 pr_info(
"%s: B%1d receive frame CRC error\n",
444 pr_info(
"%s: B%1d receive framing error\n",
447 pr_info(
"%s: B%1d receive frame too long (> %d)\n",
456 recv_tiger(
struct tiger_hw *card,
u8 irq_stat)
459 int cnt = card->
recv.size / 2;
468 idx = card->
recv.size - 1;
471 read_dma(&card->
bc[0], idx, cnt);
473 read_dma(&card->
bc[1], idx, cnt);
481 card->
send.idx = (card->
send.dmacur - card->
send.dmastart) >> 2;
488 if (card->
send.idx < ((card->
send.size / 2) - 1))
489 bc->
idx = (card->
recv.size / 2) - 1;
497 static int bc_next_frame(
struct tiger_ch *);
509 pr_debug(
"%s: %s B%1d %d state %x idx %d/%d\n", card->
name,
516 pr_debug(
"%s: B%1d hdlc encoded %d flags\n", card->
name,
520 m = (bc->
bch.nr & 1) ? 0xffffff00 : 0xffff00ff;
521 for (i = 0; i <
count; i++) {
522 if (bc->
idx >= card->
send.size)
526 v |= (bc->
bch.nr & 1) ? (
u32)(p[
i]) : ((
u32)(p[
i])) << 8;
529 if (
debug & DEBUG_HW_BFIFO) {
531 bc->
bch.nr, card->
name, count);
540 int count,
i, fillempty = 0;
546 if (!bc->
bch.tx_skb) {
550 count = card->
send.size >> 1;
553 count = bc->
bch.tx_skb->len - bc->
bch.tx_idx;
556 pr_debug(
"%s: %s B%1d %d/%d/%d/%d state %x idx %d/%d\n",
560 p = bc->
bch.tx_skb->data + bc->
bch.tx_idx;
567 pr_debug(
"%s: B%1d hdlc encoded %d in %d\n", card->
name,
568 bc->
bch.nr, i, count);
573 if (count > bc->
free)
579 m = (bc->
bch.nr & 1) ? 0xffffff00 : 0xffff00ff;
582 if (!(bc->
bch.nr & 1))
584 for (i = 0; i <
count; i++) {
585 if (bc->
idx >= card->
send.size)
593 for (i = 0; i <
count; i++) {
594 if (bc->
idx >= card->
send.size)
599 v |= (bc->
bch.nr & 1) ? n : n << 8;
603 if (
debug & DEBUG_HW_BFIFO) {
605 bc->
bch.nr, card->
name, count);
618 if (bc->
bch.tx_skb && bc->
bch.tx_idx < bc->
bch.tx_skb->len) {
622 dev_kfree_skb(bc->
bch.tx_skb);
646 pr_info(
"%s: B%1d TX underrun state %x\n", card->
name,
652 ret = bc_next_frame(bc);
658 pr_debug(
"%s: B%1d TX no data free %d idx %d/%d\n", card->
name,
661 fill_mem(bc, bc->
idx, bc->
free, 0xff);
669 send_tiger(
struct tiger_hw *card,
u8 irq_stat)
675 pr_info(
"%s: tiger warn write double dma %x/%x\n",
679 card->
last_is0 &= ~NJ_IRQM0_RD_MASK;
682 for (i = 0; i < 2; i++) {
684 send_tiger_bc(card, &card->
bc[i]);
689 nj_irq(
int intno,
void *
dev_id)
692 u8 val, s1val, s0val;
694 spin_lock(&card->
lock);
699 spin_unlock(&card->
lock);
702 pr_debug(
"%s: IRQSTAT0 %02x IRQSTAT1 %02x\n", card->
name, s0val, s1val);
704 if (!(s1val & NJ_ISACIRQ)) {
718 card->
recv.idx = (card->
recv.dmacur - card->
recv.dmastart) >> 2;
719 if (card->
recv.dmacur < card->
recv.dmairq)
725 card->
send.idx = (card->
send.dmacur - card->
send.dmastart) >> 2;
726 if (card->
send.dmacur < card->
send.dmairq)
731 pr_debug(
"%s: DMA Status %02x/%02x/%02x %d/%d\n", card->
name,
736 if ((s0val & NJ_IRQM0_RD_MASK) !=
737 (card->
last_is0 & NJ_IRQM0_RD_MASK))
739 send_tiger(card, s0val);
741 (card->
last_is0 & NJ_IRQM0_WR_MASK))
743 recv_tiger(card, s0val);
746 spin_unlock(&card->
lock);
751 nj_l2l1B(
struct mISDNchannel *ch,
struct sk_buff *
skb)
768 spin_unlock_irqrestore(&card->
lock, flags);
773 ret = mode_tiger(bc, ch->protocol);
776 spin_unlock_irqrestore(&card->
lock, flags);
785 spin_unlock_irqrestore(&card->
lock, flags);
803 nj_bctrl(
struct mISDNchannel *ch,
u32 cmd,
void *
arg)
811 pr_debug(
"%s: %s cmd:%x %p\n", card->
name, __func__, cmd, arg);
819 spin_unlock_irqrestore(&card->
lock, flags);
826 ret = channel_bctrl(bc, arg);
829 pr_info(
"%s: %s unknown prim(%x)\n", card->
name, __func__, cmd);
855 pr_info(
"%s: %s unknown Op %x\n", card->
name, __func__, cq->
op);
863 open_bchannel(
struct tiger_hw *card,
struct channel_req *
rq)
867 if (rq->adr.channel == 0 || rq->adr.channel > 2)
871 bch = &card->
bc[rq->adr.channel - 1].bch;
875 bch->
ch.protocol = rq->protocol;
884 nj_dctrl(
struct mISDNchannel *ch,
u32 cmd,
void *arg)
889 struct channel_req *
rq;
892 pr_debug(
"%s: %s cmd:%x %p\n", card->
name, __func__, cmd, arg);
897 err = card->
isac.open(&card->
isac, rq);
899 err = open_bchannel(card, rq);
907 __builtin_return_address(0));
911 err = channel_ctrl(card, arg);
914 pr_debug(
"%s: %s unknown command %x\n",
915 card->
name, __func__, cmd);
928 nj_disable_hwirq(card);
929 spin_unlock_irqrestore(&card->
lock, flags);
933 pr_info(
"%s: couldn't get interrupt %d\n",
944 ret = inittiger(card);
950 spin_unlock_irqrestore(&card->
lock, flags);
963 nj_disable_hwirq(card);
967 spin_unlock_irqrestore(&card->
lock, flags);
973 if (card->
isac.dch.dev.dev.class)
976 for (i = 0; i < 2; i++) {
1000 pr_info(
"%s: NETjet config port %#x-%#x already in use\n",
1012 setup_instance(
struct tiger_hw *card)
1030 card->
isac.dch.dev.D.ctrl = nj_dctrl;
1031 for (i = 0; i < 2; i++) {
1032 card->
bc[
i].bch.nr = i + 1;
1033 set_channelmap(i + 1, card->
isac.dch.dev.channelmap);
1037 card->
bc[
i].bch.ch.send = nj_l2l1B;
1038 card->
bc[
i].bch.ch.ctrl = nj_bctrl;
1039 card->
bc[
i].bch.ch.nr = i + 1;
1040 list_add(&card->
bc[i].bch.ch.list,
1041 &card->
isac.dch.dev.bchannels);
1044 err = nj_setup(card);
1051 err = nj_init_card(card);
1054 pr_notice(
"Netjet %d cards installed\n", nj_cnt);
1071 pr_notice(
"Netjet: Digium X100P/X101P not handled\n");
1077 pr_notice(
"Netjet: Enter!Now not handled yet\n");
1083 pr_notice(
"Netjet: Digium TDM400P not handled yet\n");
1089 pr_info(
"No kmem for Netjet\n");
1110 pci_read_config_dword(pdev, 0x04, &cfg);
1111 if (cfg & 0x00100000)
1118 pci_set_drvdata(pdev, card);
1119 err = setup_instance(card);
1121 pci_set_drvdata(pdev,
NULL);
1129 struct tiger_hw *card = pci_get_drvdata(pdev);
1134 pr_info(
"%s drvdata already removed\n", __func__);
1151 .id_table = nj_pci_ids,
1154 static int __init nj_init(
void)
1159 err = pci_register_driver(&nj_driver);
1163 static void __exit nj_cleanup(
void)