19 #include <linux/pci.h>
20 #include <linux/slab.h>
24 static const char *avm_pci_rev =
"$Revision: 1.29.2.4 $";
26 #define AVM_FRITZ_PCI 1
27 #define AVM_FRITZ_PNP 2
30 #define HDLC_STATUS 0x4
32 #define AVM_HDLC_1 0x00
33 #define AVM_HDLC_2 0x01
34 #define AVM_ISAC_FIFO 0x02
35 #define AVM_ISAC_REG_LOW 0x04
36 #define AVM_ISAC_REG_HIGH 0x06
38 #define AVM_STATUS0_IRQ_ISAC 0x01
39 #define AVM_STATUS0_IRQ_HDLC 0x02
40 #define AVM_STATUS0_IRQ_TIMER 0x04
41 #define AVM_STATUS0_IRQ_MASK 0x07
43 #define AVM_STATUS0_RESET 0x01
44 #define AVM_STATUS0_DIS_TIMER 0x02
45 #define AVM_STATUS0_RES_TIMER 0x04
46 #define AVM_STATUS0_ENA_IRQ 0x08
47 #define AVM_STATUS0_TESTBIT 0x10
49 #define AVM_STATUS1_INT_SEL 0x0f
50 #define AVM_STATUS1_ENA_IOM 0x80
52 #define HDLC_MODE_ITF_FLG 0x01
53 #define HDLC_MODE_TRANS 0x02
54 #define HDLC_MODE_CCR_7 0x04
55 #define HDLC_MODE_CCR_16 0x08
56 #define HDLC_MODE_TESTLOOP 0x80
58 #define HDLC_INT_XPR 0x80
59 #define HDLC_INT_XDU 0x40
60 #define HDLC_INT_RPR 0x20
61 #define HDLC_INT_MASK 0xE0
63 #define HDLC_STAT_RME 0x01
64 #define HDLC_STAT_RDO 0x10
65 #define HDLC_STAT_CRCVFRRAB 0x0E
66 #define HDLC_STAT_CRCVFR 0x06
67 #define HDLC_STAT_RML_MASK 0x3f00
69 #define HDLC_CMD_XRS 0x80
70 #define HDLC_CMD_XME 0x01
71 #define HDLC_CMD_RRS 0x20
72 #define HDLC_CMD_XML_MASK 0x3f00
83 outb(idx, cs->hw.avm.cfg_reg + 4);
84 val =
inb(cs->hw.avm.isac + (offset & 0xf));
93 outb(idx, cs->hw.avm.cfg_reg + 4);
94 outb(value, cs->hw.avm.isac + (offset & 0xf));
101 insb(cs->hw.avm.isac, data, size);
108 outsb(cs->hw.avm.isac, data, size);
117 outl(idx, cs->hw.avm.cfg_reg + 4);
118 val =
inl(cs->hw.avm.isac + offset);
123 WriteHDLCPCI(
struct IsdnCardState *cs,
int chan,
u_char offset,
u_int value)
127 outl(idx, cs->hw.avm.cfg_reg + 4);
128 outl(value, cs->hw.avm.isac + offset);
132 ReadHDLCPnP(
struct IsdnCardState *cs,
int chan,
u_char offset)
137 outb(idx, cs->hw.avm.cfg_reg + 4);
138 val =
inb(cs->hw.avm.isac + offset);
147 outb(idx, cs->hw.avm.cfg_reg + 4);
148 outb(value, cs->hw.avm.isac + offset);
152 ReadHDLC_s(
struct IsdnCardState *cs,
int chan,
u_char offset)
154 return (0xff & ReadHDLCPCI(cs, chan, offset));
160 WriteHDLCPCI(cs, chan, offset, value);
164 struct BCState *Sel_BCS(
struct IsdnCardState *cs,
int channel)
166 if (cs->bcs[0].mode && (cs->bcs[0].channel == channel))
167 return (&cs->bcs[0]);
168 else if (cs->bcs[1].mode && (cs->bcs[1].channel == channel))
169 return (&cs->bcs[1]);
177 if (bcs->cs->debug & L1_DEB_HSCX)
178 debugl1(bcs->cs,
"hdlc %c wr%x ctrl %x",
179 'A' + bcs->channel, which, bcs->hw.hdlc.ctrl.ctrl);
181 WriteHDLCPCI(bcs->cs, bcs->channel,
HDLC_STATUS, bcs->hw.hdlc.ctrl.ctrl);
184 WriteHDLCPnP(bcs->cs, bcs->channel,
HDLC_STATUS + 2,
185 bcs->hw.hdlc.ctrl.sr.mode);
187 WriteHDLCPnP(bcs->cs, bcs->channel,
HDLC_STATUS + 1,
188 bcs->hw.hdlc.ctrl.sr.xml);
191 bcs->hw.hdlc.ctrl.sr.cmd);
196 modehdlc(
struct BCState *bcs,
int mode,
int bc)
198 struct IsdnCardState *cs = bcs->cs;
199 int hdlc = bcs->channel;
201 if (cs->debug & L1_DEB_HSCX)
202 debugl1(cs,
"hdlc %c mode %d --> %d ichan %d --> %d",
203 'A' + hdlc, bcs->mode, mode, hdlc, bc);
204 bcs->hw.hdlc.ctrl.ctrl = 0;
227 bcs->hw.hdlc.ctrl.sr.cmd = 0;
238 bcs->hw.hdlc.ctrl.sr.cmd = 0;
245 hdlc_empty_fifo(
struct BCState *bcs,
int count)
251 struct IsdnCardState *cs = bcs->cs;
253 if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
254 debugl1(cs,
"hdlc_empty_fifo %d", count);
256 if (cs->debug & L1_DEB_WARN)
257 debugl1(cs,
"hdlc_empty_fifo: incoming packet too large");
260 p = bcs->hw.hdlc.rcvbuf + bcs->hw.hdlc.rcvidx;
262 bcs->hw.hdlc.rcvidx +=
count;
264 outl(idx, cs->hw.avm.cfg_reg + 4);
265 while (cnt < count) {
269 *ptr++ =
inl(cs->hw.avm.isac);
274 outb(idx, cs->hw.avm.cfg_reg + 4);
275 while (cnt < count) {
276 *p++ =
inb(cs->hw.avm.isac);
280 if (cs->debug & L1_DEB_HSCX_FIFO) {
285 t +=
sprintf(t,
"hdlc_empty_fifo %c cnt %d",
286 bcs->channel ?
'B' :
'A', count);
293 hdlc_fill_fifo(
struct BCState *bcs)
295 struct IsdnCardState *cs = bcs->cs;
301 if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
305 if (bcs->tx_skb->len <= 0)
309 if (bcs->tx_skb->len > fifo_size) {
312 count = bcs->tx_skb->len;
316 if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
317 debugl1(cs,
"hdlc_fill_fifo %d/%u", count, bcs->tx_skb->len);
318 p = bcs->tx_skb->data;
321 bcs->tx_cnt -=
count;
322 bcs->hw.hdlc.count +=
count;
323 bcs->hw.hdlc.ctrl.sr.xml = ((count ==
fifo_size) ? 0 : count);
326 while (cnt < count) {
330 outl(*ptr++, cs->hw.avm.isac);
335 while (cnt < count) {
336 outb(*p++, cs->hw.avm.isac);
340 if (cs->debug & L1_DEB_HSCX_FIFO) {
345 t +=
sprintf(t,
"hdlc_fill_fifo %c cnt %d",
346 bcs->channel ?
'B' :
'A', count);
353 HDLC_irq(
struct BCState *bcs,
u_int stat) {
357 if (bcs->cs->debug & L1_DEB_HSCX)
358 debugl1(bcs->cs,
"ch%d stat %#x", bcs->channel, stat);
361 if (bcs->cs->debug & L1_DEB_HSCX)
364 debugl1(bcs->cs,
"ch%d stat %#x", bcs->channel, stat);
365 bcs->hw.hdlc.ctrl.sr.xml = 0;
370 bcs->hw.hdlc.rcvidx = 0;
374 hdlc_empty_fifo(bcs, len);
378 if (!(skb = dev_alloc_skb(bcs->hw.hdlc.rcvidx)))
382 bcs->hw.hdlc.rcvbuf, bcs->hw.hdlc.rcvidx);
385 bcs->hw.hdlc.rcvidx = 0;
388 if (bcs->cs->debug & L1_DEB_HSCX)
389 debugl1(bcs->cs,
"invalid frame");
391 debugl1(bcs->cs,
"ch%d invalid frame %#x", bcs->channel, stat);
392 bcs->hw.hdlc.rcvidx = 0;
402 skb_push(bcs->tx_skb, bcs->hw.hdlc.count);
403 bcs->tx_cnt += bcs->hw.hdlc.count;
404 bcs->hw.hdlc.count = 0;
405 if (bcs->cs->debug & L1_DEB_WARN)
406 debugl1(bcs->cs,
"ch%d XDU", bcs->channel);
407 }
else if (bcs->cs->debug & L1_DEB_WARN)
408 debugl1(bcs->cs,
"ch%d XDU without skb", bcs->channel);
409 bcs->hw.hdlc.ctrl.sr.xml = 0;
417 if (bcs->tx_skb->len) {
421 if (
test_bit(FLG_LLI_L1WAKEUP, &bcs->st->lli.flag) &&
422 (PACKET_NOACK != bcs->tx_skb->pkt_type)) {
425 bcs->ackcnt += bcs->hw.hdlc.count;
426 spin_unlock_irqrestore(&bcs->aclock, flags);
430 bcs->hw.hdlc.count = 0;
435 bcs->hw.hdlc.count = 0;
446 HDLC_irq_main(
struct IsdnCardState *cs)
455 if (stat & HDLC_INT_RPR)
456 stat |= (ReadHDLCPnP(cs, 0,
HDLC_STATUS + 1)) << 8;
459 if (!(bcs = Sel_BCS(cs, 0))) {
461 debugl1(cs,
"hdlc spurious channel 0 IRQ");
469 if (stat & HDLC_INT_RPR)
470 stat |= (ReadHDLCPnP(cs, 1,
HDLC_STATUS + 1)) << 8;
472 if (stat & HDLC_INT_MASK) {
473 if (!(bcs = Sel_BCS(cs, 1))) {
475 debugl1(cs,
"hdlc spurious channel 1 IRQ");
482 hdlc_l2l1(
struct PStack *
st,
int pr,
void *
arg)
484 struct BCState *bcs = st->l1.bcs;
496 bcs->hw.hdlc.count = 0;
497 bcs->cs->BC_Send_Data(bcs);
499 spin_unlock_irqrestore(&bcs->cs->lock, flags);
508 bcs->hw.hdlc.count = 0;
509 bcs->cs->BC_Send_Data(bcs);
511 spin_unlock_irqrestore(&bcs->cs->lock, flags);
523 modehdlc(bcs, st->l1.mode, st->l1.bc);
524 spin_unlock_irqrestore(&bcs->cs->lock, flags);
534 modehdlc(bcs, 0, st->l1.bc);
535 spin_unlock_irqrestore(&bcs->cs->lock, flags);
542 close_hdlcstate(
struct BCState *bcs)
546 kfree(bcs->hw.hdlc.rcvbuf);
547 bcs->hw.hdlc.rcvbuf =
NULL;
561 open_hdlcstate(
struct IsdnCardState *cs,
struct BCState *bcs)
566 "HiSax: No memory for hdlc.rcvbuf\n");
571 "HiSax: No memory for bcs->blog\n");
573 kfree(bcs->hw.hdlc.rcvbuf);
574 bcs->hw.hdlc.rcvbuf =
NULL;
577 skb_queue_head_init(&bcs->rqueue);
578 skb_queue_head_init(&bcs->squeue);
583 bcs->hw.hdlc.rcvidx = 0;
589 setstack_hdlc(
struct PStack *st,
struct BCState *bcs)
591 bcs->channel = st->l1.bc;
592 if (open_hdlcstate(st->l1.hardware, bcs))
595 st->l2.l2l1 = hdlc_l2l1;
610 debugl1(cs,
"HDLC 1 STA %x", val);
612 debugl1(cs,
"HDLC 2 STA %x", val);
615 debugl1(cs,
"HDLC 1 STA %x", val);
617 debugl1(cs,
"HDLC 1 RML %x", val);
619 debugl1(cs,
"HDLC 1 MODE %x", val);
621 debugl1(cs,
"HDLC 1 VIN %x", val);
623 debugl1(cs,
"HDLC 2 STA %x", val);
625 debugl1(cs,
"HDLC 2 RML %x", val);
627 debugl1(cs,
"HDLC 2 MODE %x", val);
629 debugl1(cs,
"HDLC 2 VIN %x", val);
635 inithdlc(
struct IsdnCardState *cs)
637 cs->bcs[0].BC_SetStack = setstack_hdlc;
638 cs->bcs[1].BC_SetStack = setstack_hdlc;
639 cs->bcs[0].BC_Close = close_hdlcstate;
640 cs->bcs[1].BC_Close = close_hdlcstate;
641 modehdlc(cs->bcs, -1, 0);
642 modehdlc(cs->bcs + 1, -1, 1);
646 avm_pcipnp_interrupt(
int intno,
void *
dev_id)
648 struct IsdnCardState *cs =
dev_id;
654 sval =
inb(cs->hw.avm.cfg_reg + 2);
657 spin_unlock_irqrestore(&cs->lock, flags);
669 spin_unlock_irqrestore(&cs->lock, flags);
674 reset_avmpcipnp(
struct IsdnCardState *cs)
686 AVM_card_msg(
struct IsdnCardState *cs,
int mt,
void *arg)
694 spin_unlock_irqrestore(&cs->lock, flags);
697 outb(0, cs->hw.avm.cfg_reg + 2);
707 cs->hw.avm.cfg_reg + 2);
713 spin_unlock_irqrestore(&cs->lock, flags);
721 static int __devinit avm_setup_rest(
struct IsdnCardState *cs)
725 cs->hw.avm.isac = cs->hw.avm.cfg_reg + 0x10;
729 "HiSax: Fritz!PCI/PNP config port %x-%x already in use\n",
731 cs->hw.avm.cfg_reg + 31);
734 switch (cs->subtyp) {
736 val =
inl(cs->hw.avm.cfg_reg);
739 val & 0xff, (val >> 8) & 0xff);
740 cs->BC_Read_Reg = &ReadHDLC_s;
741 cs->BC_Write_Reg = &WriteHDLC_s;
744 val =
inb(cs->hw.avm.cfg_reg);
745 ver =
inb(cs->hw.avm.cfg_reg + 1);
747 cs->BC_Read_Reg = &ReadHDLCPnP;
748 cs->BC_Write_Reg = &WriteHDLCPnP;
755 (cs->subtyp ==
AVM_FRITZ_PCI) ?
"AVM Fritz!PCI" :
"AVM Fritz!PnP",
756 cs->irq, cs->hw.avm.cfg_reg);
761 cs->readisacfifo = &ReadISACfifo;
762 cs->writeisacfifo = &WriteISACfifo;
763 cs->BC_Send_Data = &hdlc_fill_fifo;
764 cs->cardmsg = &AVM_card_msg;
765 cs->irq_func = &avm_pcipnp_interrupt;
773 static int __devinit avm_pnp_setup(
struct IsdnCardState *cs)
782 static int __devinit avm_pnp_setup(
struct IsdnCardState *cs)
805 pnp_port_start(pnp_avm_d, 0);
806 cs->irq =
pnp_irq(pnp_avm_d, 0);
811 if (!cs->hw.avm.cfg_reg) {
828 static int __devinit avm_pci_setup(
struct IsdnCardState *cs)
835 static struct pci_dev *dev_avm __devinitdata =
NULL;
837 static int __devinit avm_pci_setup(
struct IsdnCardState *cs)
845 cs->irq = dev_avm->irq;
852 if (!cs->hw.avm.cfg_reg) {
873 struct IsdnCardState *cs = card->
cs;
885 cs->hw.avm.cfg_reg = card->
para[1];
886 cs->irq = card->
para[0];
891 rc = avm_pnp_setup(cs);
897 rc = avm_pci_setup(cs);
902 return avm_setup_rest(cs);