24 #include <linux/module.h>
25 #include <linux/pci.h>
28 #include <linux/slab.h>
29 #include <asm/unaligned.h>
33 #define AVMFRITZ_REV "2.3"
44 #define HDLC_STATUS 0x4
45 #define CHIP_WINDOW 0x10
47 #define CHIP_INDEX 0x4
48 #define AVM_HDLC_1 0x00
49 #define AVM_HDLC_2 0x01
50 #define AVM_ISAC_FIFO 0x02
51 #define AVM_ISAC_REG_LOW 0x04
52 #define AVM_ISAC_REG_HIGH 0x06
54 #define AVM_STATUS0_IRQ_ISAC 0x01
55 #define AVM_STATUS0_IRQ_HDLC 0x02
56 #define AVM_STATUS0_IRQ_TIMER 0x04
57 #define AVM_STATUS0_IRQ_MASK 0x07
59 #define AVM_STATUS0_RESET 0x01
60 #define AVM_STATUS0_DIS_TIMER 0x02
61 #define AVM_STATUS0_RES_TIMER 0x04
62 #define AVM_STATUS0_ENA_IRQ 0x08
63 #define AVM_STATUS0_TESTBIT 0x10
65 #define AVM_STATUS1_INT_SEL 0x0f
66 #define AVM_STATUS1_ENA_IOM 0x80
68 #define HDLC_MODE_ITF_FLG 0x01
69 #define HDLC_MODE_TRANS 0x02
70 #define HDLC_MODE_CCR_7 0x04
71 #define HDLC_MODE_CCR_16 0x08
72 #define HDLC_FIFO_SIZE_128 0x20
73 #define HDLC_MODE_TESTLOOP 0x80
75 #define HDLC_INT_XPR 0x80
76 #define HDLC_INT_XDU 0x40
77 #define HDLC_INT_RPR 0x20
78 #define HDLC_INT_MASK 0xE0
80 #define HDLC_STAT_RME 0x01
81 #define HDLC_STAT_RDO 0x10
82 #define HDLC_STAT_CRCVFRRAB 0x0E
83 #define HDLC_STAT_CRCVFR 0x06
84 #define HDLC_STAT_RML_MASK_V1 0x3f00
85 #define HDLC_STAT_RML_MASK_V2 0x7f00
87 #define HDLC_CMD_XRS 0x80
88 #define HDLC_CMD_XME 0x01
89 #define HDLC_CMD_RRS 0x20
90 #define HDLC_CMD_XML_MASK 0x3f00
92 #define HDLC_FIFO_SIZE_V1 32
93 #define HDLC_FIFO_SIZE_V2 128
97 #define AVM_HDLC_FIFO_1 0x10
98 #define AVM_HDLC_FIFO_2 0x18
100 #define AVM_HDLC_STATUS_1 0x14
101 #define AVM_HDLC_STATUS_2 0x1c
103 #define AVM_ISACX_INDEX 0x04
104 #define AVM_ISACX_DATA 0x08
245 for (i = 0; i <
size; i++)
250 WriteFiFoISAC_V2(
void *p,
u8 off,
u8 *data,
int size)
256 for (i = 0; i <
size; i++)
264 (fc->
bch[0].nr & channel))
267 (fc->
bch[1].nr & channel))
292 hdlc = &fc->
hdlc[(bch->
nr - 1) & 1];
294 which, hdlc->
ctrl.ctrl);
297 __write_ctrl_pciv2(fc, hdlc, bch->
nr);
300 __write_ctrl_pci(fc, hdlc, bch->
nr);
326 return __read_status_pciv2(fc->
addr, channel);
328 return __read_status_pci(fc->
addr, channel);
355 hdlc = &fc->
hdlc[(bch->
nr - 1) & 1];
356 pr_debug(
"%s: hdlc %c protocol %x-->%x ch %d\n", fc->
name,
357 '@' + bch->
nr, bch->
state, protocol, bch->
nr);
381 hdlc->
ctrl.sr.cmd = 0;
391 hdlc->
ctrl.sr.cmd = 0;
395 pr_info(
"%s: protocol not known %x\n", fc->
name, protocol);
417 pr_warning(
"%s.B%d: No bufferspace for %d bytes\n",
418 fc->
name, bch->
nr, count);
425 addr = fc->
addr + (bch->
nr == 2 ?
432 while (cnt < count) {
442 bch->
nr, fc->
name, count);
448 hdlc_fill_fifo(
struct bchannel *bch)
453 bool fillempty =
false;
457 idx = (bch->
nr - 1) & 1;
488 hdlc->
ctrl.sr.xml = ((count ==
fs) ? 0 : count);
490 __write_ctrl_pciv2(fc, hdlc, bch->
nr);
491 addr = fc->
addr + (bch->
nr == 2 ?
494 __write_ctrl_pci(fc, hdlc, bch->
nr);
498 while (cnt < count) {
504 while (cnt < count) {
513 bch->
nr, fc->
name, count);
525 dev_kfree_skb(bch->
tx_skb);
543 hdlc = &fc->
hdlc[(bch->
nr - 1) & 1];
556 hdlc->
ctrl.sr.xml = 0;
564 len = (stat & rmlMask) >> 8;
567 hdlc_empty_fifo(bch, len);
591 stat, bch->
tx_skb ?
"tx_skb" :
"no tx_skb");
598 hdlc->
ctrl.sr.xml = 0;
614 stat = read_status(fc, 1);
616 bch = Sel_BCS(fc, 1);
622 stat = read_status(fc, 2);
623 if (stat & HDLC_INT_MASK) {
624 bch = Sel_BCS(fc, 2);
633 avm_fritz_interrupt(
int intno,
void *
dev_id)
639 spin_lock(&fc->
lock);
644 spin_unlock(&fc->
lock);
655 spin_unlock(&fc->
lock);
660 avm_fritzv2_interrupt(
int intno,
void *dev_id)
666 spin_lock(&fc->
lock);
669 if (!(sval & AVM_STATUS0_IRQ_MASK)) {
671 spin_unlock(&fc->
lock);
678 if (sval & AVM_STATUS0_IRQ_ISAC) {
688 spin_unlock(&fc->
lock);
693 avm_l2l1B(
struct mISDNchannel *ch,
struct sk_buff *
skb)
709 spin_unlock_irqrestore(&fc->
lock, flags);
714 ret = modehdlc(bch, ch->protocol);
717 spin_unlock_irqrestore(&fc->
lock, flags);
726 spin_unlock_irqrestore(&fc->
lock, flags);
740 modehdlc(&fc->
bch[0], -1);
741 modehdlc(&fc->
bch[1], -1);
749 val = read_status(fc, 1);
751 val = read_status(fc, 2);
782 if (
debug & DEBUG_HW)
801 pr_info(
"%s: couldn't get interrupt %d\n",
809 spin_unlock_irqrestore(&fc->
lock, flags);
810 pr_info(
"%s: ISAC init failed with %d\n",
825 spin_unlock_irqrestore(&fc->
lock, flags);
828 if (
debug & DEBUG_HW)
832 pr_info(
"%s: IRQ(%d) getting no IRQs during init %d\n",
849 avm_bctrl(
struct mISDNchannel *ch,
u32 cmd,
void *
arg)
856 pr_debug(
"%s: %s cmd:%x %p\n", fc->
name, __func__, cmd, arg);
864 spin_unlock_irqrestore(&fc->
lock, flags);
871 ret = channel_bctrl(bch, arg);
874 pr_info(
"%s: %s unknown prim(%x)\n", fc->
name, __func__, cmd);
900 pr_info(
"%s: %s unknown Op %x\n", fc->
name, __func__, cq->
op);
908 open_bchannel(
struct fritzcard *fc,
struct channel_req *
rq)
912 if (rq->adr.channel == 0 || rq->adr.channel > 2)
916 bch = &fc->
bch[rq->adr.channel - 1];
919 bch->
ch.protocol = rq->protocol;
928 avm_dctrl(
struct mISDNchannel *ch,
u32 cmd,
void *arg)
933 struct channel_req *
rq;
936 pr_debug(
"%s: %s cmd:%x %p\n", fc->
name, __func__, cmd, arg);
943 err = open_bchannel(fc, rq);
951 __builtin_return_address(0));
955 err = channel_ctrl(fc, arg);
958 pr_debug(
"%s: %s unknown command %x\n",
959 fc->
name, __func__, cmd);
971 pr_info(
"%s: AVM config port %x-%x already in use\n",
980 if (
debug & DEBUG_HW) {
983 val & 0xff, (val >> 8) & 0xff);
992 if (
debug & DEBUG_HW) {
995 val & 0xff, (val >> 8) & 0xff);
1008 "AVM Fritz!CARD PCIv2", fc->
irq, fc->
addr);
1017 disable_hwirq(card);
1021 spin_unlock_irqrestore(&card->
lock, flags);
1057 card->
isac.dch.dev.D.ctrl = avm_dctrl;
1058 for (i = 0; i < 2; i++) {
1059 card->
bch[
i].nr = i + 1;
1060 set_channelmap(i + 1, card->
isac.dch.dev.channelmap);
1067 card->
bch[
i].ch.send = avm_l2l1B;
1068 card->
bch[
i].ch.ctrl = avm_bctrl;
1069 card->
bch[
i].ch.nr = i + 1;
1070 list_add(&card->
bch[i].ch.list, &card->
isac.dch.dev.bchannels);
1079 err = init_card(card);
1082 pr_notice(
"AVM %d cards installed DEBUG\n", AVM_cnt);
1107 pr_info(
"No kmem for fritzcard\n");
1121 pr_notice(
"mISDN: found adapter %s at %s\n",
1126 pci_set_drvdata(pdev, card);
1127 err = setup_instance(card);
1129 pci_set_drvdata(pdev,
NULL);
1134 fritz_remove_pci(
struct pci_dev *pdev)
1136 struct fritzcard *card = pci_get_drvdata(pdev);
1142 pr_info(
"%s: drvdata already removed\n", __func__);
1147 0, 0, (
unsigned long)
"Fritz!Card PCI"},
1149 0, 0, (
unsigned long)
"Fritz!Card PCI v2" },
1156 .probe = fritzpci_probe,
1158 .id_table = fcpci_ids,
1161 static int __init AVM_init(
void)
1166 err = pci_register_driver(&fcpci_driver);
1170 static void __exit AVM_cleanup(
void)