18 #include <linux/pci.h>
19 #include <linux/slab.h>
33 {0, 0,
"U.S.Robotics",
"ISDN PCI Card TA"}
36 #define W6692_SV_USR 0x16ec
37 #define W6692_SD_USR 0x3409
38 #define W6692_WINBOND 0
39 #define W6692_DYNALINK 1
42 static const char *w6692_revision =
"$Revision: 1.18.2.4 $";
44 #define DBUSY_TIMER_VALUE 80
46 static char *W6692Ver[] =
47 {
"W6692 V00",
"W6692 V01",
"W6692 V10",
51 W6692Version(
struct IsdnCardState *
cs,
char *
s)
56 printk(
KERN_INFO "%s Winbond W6692 version (%x): %s\n", s, val, W6692Ver[(val >> 6) & 3]);
60 ph_command(
struct IsdnCardState *cs,
unsigned int command)
62 if (cs->debug & L1_DEB_ISAC)
63 debugl1(cs,
"ph_command %x", command);
64 cs->writeisac(cs,
W_CIX, command);
69 W6692_new_ph(
struct IsdnCardState *cs)
71 switch (cs->dc.w6692.ph_state) {
105 struct IsdnCardState *cs =
107 struct PStack *stptr;
111 debugl1(cs,
"D-Channel Busy cleared");
113 while (stptr !=
NULL) {
133 W6692_empty_fifo(
struct IsdnCardState *cs,
int count)
137 if ((cs->debug & L1_DEB_ISAC) && !(cs->debug & L1_DEB_ISAC_FIFO))
138 debugl1(cs,
"W6692_empty_fifo");
141 if (cs->debug & L1_DEB_WARN)
142 debugl1(cs,
"W6692_empty_fifo overrun %d",
148 ptr = cs->rcvbuf + cs->rcvidx;
150 cs->readW6692fifo(cs, ptr, count);
152 if (cs->debug & L1_DEB_ISAC_FIFO) {
155 t +=
sprintf(t,
"W6692_empty_fifo cnt %d", count);
162 W6692_fill_fifo(
struct IsdnCardState *cs)
167 if ((cs->debug & L1_DEB_ISAC) && !(cs->debug & L1_DEB_ISAC_FIFO))
168 debugl1(cs,
"W6692_fill_fifo");
173 count = cs->tx_skb->len;
182 ptr = cs->tx_skb->data;
185 cs->writeW6692fifo(cs, ptr, count);
188 debugl1(cs,
"W6692_fill_fifo dbusytimer running");
194 if (cs->debug & L1_DEB_ISAC_FIFO) {
197 t +=
sprintf(t,
"W6692_fill_fifo cnt %d", count);
204 W6692B_empty_fifo(
struct BCState *bcs,
int count)
207 struct IsdnCardState *cs = bcs->cs;
209 if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
210 debugl1(cs,
"W6692B_empty_fifo");
213 if (cs->debug & L1_DEB_WARN)
214 debugl1(cs,
"W6692B_empty_fifo: incoming packet too large");
216 bcs->hw.w6692.rcvidx = 0;
219 ptr = bcs->hw.w6692.rcvbuf + bcs->hw.w6692.rcvidx;
220 bcs->hw.w6692.rcvidx +=
count;
223 if (cs->debug & L1_DEB_HSCX_FIFO) {
226 t +=
sprintf(t,
"W6692B_empty_fifo %c cnt %d",
227 bcs->channel +
'1', count);
234 W6692B_fill_fifo(
struct BCState *bcs)
236 struct IsdnCardState *cs = bcs->cs;
242 if (bcs->tx_skb->len <= 0)
250 count = bcs->tx_skb->len;
252 if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
253 debugl1(cs,
"W6692B_fill_fifo%s%d", (more ?
" " :
" last "), count);
255 ptr = bcs->tx_skb->data;
257 bcs->tx_cnt -=
count;
258 bcs->hw.w6692.count +=
count;
261 if (cs->debug & L1_DEB_HSCX_FIFO) {
264 t +=
sprintf(t,
"W6692B_fill_fifo %c cnt %d",
265 bcs->channel +
'1', count);
272 W6692B_interrupt(
struct IsdnCardState *cs,
u_char bchan)
280 bcs = (cs->bcs->channel ==
bchan) ? cs->bcs : (cs->bcs + 1);
281 val = cs->BC_Read_Reg(cs, bchan,
W_B_EXIR);
282 debugl1(cs,
"W6692B chan %d B_EXIR 0x%02X", bchan, val);
284 if (!
test_bit(BC_FLG_INIT, &bcs->Flag)) {
285 debugl1(cs,
"W6692B not INIT yet");
289 r = cs->BC_Read_Reg(cs, bchan,
W_B_STAR);
291 if (cs->debug & L1_DEB_WARN)
292 debugl1(cs,
"W6692 B STAR %x", r);
294 if (cs->debug & L1_DEB_WARN)
295 debugl1(cs,
"W6692 B RDOV mode=%d",
298 if (cs->debug & L1_DEB_WARN)
299 debugl1(cs,
"W6692 B CRC error");
305 W6692B_empty_fifo(bcs, count);
306 if ((count = bcs->hw.w6692.rcvidx) > 0) {
307 if (cs->debug & L1_DEB_HSCX_FIFO)
308 debugl1(cs,
"W6692 Bchan Frame %d", count);
309 if (!(skb = dev_alloc_skb(count)))
317 bcs->hw.w6692.rcvidx = 0;
322 r = cs->BC_Read_Reg(cs, bchan,
W_B_STAR);
323 if (r & W_B_STAR_RDOV) {
324 if (cs->debug & L1_DEB_WARN)
325 debugl1(cs,
"W6692 B RDOV(RMR) mode=%d", bcs->mode);
328 bcs->hw.w6692.rcvidx = 0;
338 bcs->hw.w6692.rcvidx = 0;
344 if (cs->debug & L1_DEB_WARN)
345 debugl1(cs,
"W6692 B EXIR %x Lost TX", val);
347 W6692B_fill_fifo(bcs);
353 skb_push(bcs->tx_skb, bcs->hw.w6692.count);
354 bcs->tx_cnt += bcs->hw.w6692.count;
355 bcs->hw.w6692.count = 0;
361 r = cs->BC_Read_Reg(cs, bchan,
W_B_STAR);
363 if (cs->debug & L1_DEB_WARN)
364 debugl1(cs,
"W6692 B STAR %x XDOW", r);
366 if (bcs->tx_skb && (bcs->mode != 1)) {
367 skb_push(bcs->tx_skb, bcs->hw.w6692.count);
368 bcs->tx_cnt += bcs->hw.w6692.count;
369 bcs->hw.w6692.count = 0;
373 if (bcs->tx_skb->len) {
374 W6692B_fill_fifo(bcs);
377 if (
test_bit(FLG_LLI_L1WAKEUP, &bcs->st->lli.flag) &&
378 (PACKET_NOACK != bcs->tx_skb->pkt_type)) {
381 bcs->ackcnt += bcs->hw.w6692.count;
382 spin_unlock_irqrestore(&bcs->aclock, flags);
386 bcs->hw.w6692.count = 0;
391 bcs->hw.w6692.count = 0;
393 W6692B_fill_fifo(bcs);
402 W6692_interrupt(
int intno,
void *
dev_id)
404 struct IsdnCardState *cs =
dev_id;
412 val = cs->readW6692(cs,
W_ISTA);
414 spin_unlock_irqrestore(&cs->lock, flags);
418 if (cs->debug & L1_DEB_ISAC)
419 debugl1(cs,
"W6692 ISTA %x", val);
422 exval = cs->readW6692(cs,
W_D_RSTA);
425 if (cs->debug & L1_DEB_WARN)
428 if (cs->debug & L1_DEB_WARN)
429 debugl1(cs,
"W6692 D-channel CRC error");
431 if (cs->debug & L1_DEB_WARN)
432 debugl1(cs,
"W6692 D-channel ABORT");
438 W6692_empty_fifo(cs, count);
439 if ((count = cs->rcvidx) > 0) {
461 if (cs->tx_skb->len) {
478 if (cs->debug & L1_DEB_ISAC)
479 debugl1(cs,
"W6692 spurious XINT!");
482 exval = cs->readW6692(cs,
W_D_EXIR);
483 if (cs->debug & L1_DEB_WARN)
484 debugl1(cs,
"W6692 D_EXIR %02x", exval);
486 debugl1(cs,
"W6692 D-chan underrun/collision");
498 debugl1(cs,
"W6692 XDUN/XCOL no skb");
503 debugl1(cs,
"W6692 D-channel RDOV");
508 debugl1(cs,
"W6692 spurious TIN2 interrupt");
511 debugl1(cs,
"W6692 spurious MOC interrupt");
512 v1 = cs->readW6692(cs,
W_MOSR);
513 debugl1(cs,
"W6692 MOSR %02x", v1);
516 v1 = cs->readW6692(cs,
W_CIR);
517 if (cs->debug & L1_DEB_ISAC)
518 debugl1(cs,
"W6692 ISC CIR=0x%02X", v1);
521 if (cs->debug & L1_DEB_ISAC)
522 debugl1(cs,
"ph_state_change %x", cs->dc.w6692.ph_state);
526 v1 = cs->readW6692(cs,
W_SQR);
527 debugl1(cs,
"W6692 SCC SQR=0x%02X", v1);
531 debugl1(cs,
"W6692 spurious WEXP interrupt!");
534 debugl1(cs,
"W6692 spurious TEXP interrupt!");
538 debugl1(cs,
"W6692 B channel 1 interrupt");
539 W6692B_interrupt(cs, 0);
542 debugl1(cs,
"W6692 B channel 2 interrupt");
543 W6692B_interrupt(cs, 1);
545 val = cs->readW6692(cs,
W_ISTA);
552 cs->writeW6692(cs,
W_IMASK, 0xff);
554 spin_unlock_irqrestore(&cs->lock, flags);
559 W6692_l1hw(
struct PStack *
st,
int pr,
void *
arg)
561 struct IsdnCardState *cs = (
struct IsdnCardState *) st->l1.hardware;
568 if (cs->debug & DEB_DLOG_HEX)
570 if (cs->debug & DEB_DLOG_VERBOSE)
576 if (cs->debug & L1_DEB_LAPD)
583 if (cs->debug & L1_DEB_LAPD)
588 spin_unlock_irqrestore(&cs->lock, flags);
593 if (cs->debug & L1_DEB_WARN)
594 debugl1(cs,
" l2l1 tx_skb exist this shouldn't happen");
596 spin_unlock_irqrestore(&cs->lock, flags);
599 if (cs->debug & DEB_DLOG_HEX)
601 if (cs->debug & DEB_DLOG_VERBOSE)
606 if (cs->debug & L1_DEB_LAPD)
610 spin_unlock_irqrestore(&cs->lock, flags);
614 if (cs->debug & L1_DEB_LAPD)
615 debugl1(cs,
"-> PH_REQUEST_PULL");
627 spin_unlock_irqrestore(&cs->lock, flags);
631 spin_unlock_irqrestore(&cs->lock, flags);
638 spin_unlock_irqrestore(&cs->lock, flags);
643 spin_unlock_irqrestore(&cs->lock, flags);
666 if (cs->debug & L1_DEB_WARN)
667 debugl1(cs,
"W6692_l1hw unknown %04x", pr);
673 setstack_W6692(
struct PStack *st,
struct IsdnCardState *cs)
675 st->l1.l1hw = W6692_l1hw;
679 DC_Close_W6692(
struct IsdnCardState *cs)
684 dbusy_timer_handler(
struct IsdnCardState *cs)
686 struct PStack *stptr;
691 if (
test_bit(FLG_DBUSY_TIMER, &cs->HW_Flags)) {
695 debugl1(cs,
"D-Channel Busy D_RBCH %02x D_STAR %02x",
700 while (stptr !=
NULL) {
713 debugl1(cs,
"D-Channel Busy no skb");
716 spin_unlock_irqrestore(&cs->lock, flags);
717 cs->irq_func(cs->irq, cs);
721 spin_unlock_irqrestore(&cs->lock, flags);
725 W6692Bmode(
struct BCState *bcs,
int mode,
int bchan)
727 struct IsdnCardState *cs = bcs->cs;
729 if (cs->debug & L1_DEB_HSCX)
730 debugl1(cs,
"w6692 %c mode %d ichan %d",
731 '1' + bchan, mode, bchan);
733 bcs->channel =
bchan;
734 bcs->hw.w6692.bchan =
bchan;
738 cs->BC_Write_Reg(cs, bchan,
W_B_MODE, 0);
745 cs->BC_Write_Reg(cs, bchan,
W_B_ADM1, 0xff);
746 cs->BC_Write_Reg(cs, bchan,
W_B_ADM2, 0xff);
752 cs->BC_Write_Reg(cs, bchan,
W_B_EXIM, 0x00);
756 W6692_l2l1(
struct PStack *st,
int pr,
void *arg)
759 struct BCState *bcs = st->l1.bcs;
770 bcs->hw.w6692.count = 0;
771 bcs->cs->BC_Send_Data(bcs);
773 spin_unlock_irqrestore(&bcs->cs->lock, flags);
783 bcs->hw.w6692.count = 0;
784 bcs->cs->BC_Send_Data(bcs);
785 spin_unlock_irqrestore(&bcs->cs->lock, flags);
797 W6692Bmode(bcs, st->l1.mode, st->l1.bc);
798 spin_unlock_irqrestore(&bcs->cs->lock, flags);
808 W6692Bmode(bcs, 0, st->l1.bc);
809 spin_unlock_irqrestore(&bcs->cs->lock, flags);
816 close_w6692state(
struct BCState *bcs)
818 W6692Bmode(bcs, 0, bcs->channel);
820 kfree(bcs->hw.w6692.rcvbuf);
821 bcs->hw.w6692.rcvbuf =
NULL;
835 open_w6692state(
struct IsdnCardState *cs,
struct BCState *bcs)
840 "HiSax: No memory for w6692.rcvbuf\n");
846 "HiSax: No memory for bcs->blog\n");
848 kfree(bcs->hw.w6692.rcvbuf);
849 bcs->hw.w6692.rcvbuf =
NULL;
852 skb_queue_head_init(&bcs->rqueue);
853 skb_queue_head_init(&bcs->squeue);
858 bcs->hw.w6692.rcvidx = 0;
864 setstack_w6692(
struct PStack *st,
struct BCState *bcs)
866 bcs->channel = st->l1.bc;
867 if (open_w6692state(st->l1.hardware, bcs))
870 st->l2.l2l1 = W6692_l2l1;
877 static void resetW6692(
struct IsdnCardState *cs)
881 cs->writeW6692(cs,
W_D_CTL, 0x00);
883 cs->writeW6692(cs,
W_IMASK, 0xff);
884 cs->writeW6692(cs,
W_D_SAM, 0xff);
885 cs->writeW6692(cs,
W_D_TAM, 0xff);
888 cs->writeW6692(cs,
W_IMASK, 0x18);
894 cs->writeW6692(cs,
W_PCTL, 0x80);
895 cs->writeW6692(cs,
W_XDATA, 0x00);
902 cs->setstack_d = setstack_W6692;
903 cs->DC_Close = DC_Close_W6692;
904 cs->dbusytimer.function = (
void *) dbusy_timer_handler;
905 cs->dbusytimer.data = (
long) cs;
913 cs->bcs[0].BC_SetStack = setstack_w6692;
914 cs->bcs[1].BC_SetStack = setstack_w6692;
915 cs->bcs[0].BC_Close = close_w6692state;
916 cs->bcs[1].BC_Close = close_w6692state;
917 W6692Bmode(cs->bcs, 0, 0);
918 W6692Bmode(cs->bcs + 1, 0, 0);
922 cs->writeW6692(cs,
W_IMASK, 0x18);
924 cs->BC_Write_Reg(cs, 0,
W_B_EXIM, 0x00);
925 cs->BC_Write_Reg(cs, 1,
W_B_EXIM, 0x00);
936 return (
inb(cs->hw.w6692.iobase + offset));
942 outb(value, cs->hw.w6692.iobase + offset);
958 ReadW6692B(
struct IsdnCardState *cs,
int bchan,
u_char offset)
960 return (
inb(cs->hw.w6692.iobase + (bchan ? 0x40 : 0) + offset));
966 outb(value, cs->hw.w6692.iobase + (bchan ? 0x40 : 0) + offset);
970 w6692_card_msg(
struct IsdnCardState *cs,
int mt,
void *arg)
977 cs->writeW6692(cs,
W_IMASK, 0xff);
980 cs->writeW6692(cs,
W_XDATA, 0x04);
999 struct IsdnCardState *cs = card->
cs;
1003 u_int pci_ioaddr = 0;
1005 strcpy(tmp, w6692_revision);
1011 dev_w6692 = hisax_find_pci_device(id_list[id_idx].vendor_id,
1017 cs->subtyp = id_idx;
1024 pci_irq = dev_w6692->irq;
1049 cs->hw.w6692.iobase = pci_ioaddr;
1052 pci_ioaddr, pci_irq);
1055 "HiSax: %s I/O ports %x-%x already in use\n",
1057 cs->hw.w6692.iobase,
1058 cs->hw.w6692.iobase + 255);
1063 "HiSax: %s config irq:%d I/O:%x\n",
1065 cs->hw.w6692.iobase);
1068 cs->readW6692 = &ReadW6692;
1069 cs->writeW6692 = &WriteW6692;
1070 cs->readisacfifo = &ReadISACfifo;
1071 cs->writeisacfifo = &WriteISACfifo;
1072 cs->BC_Read_Reg = &ReadW6692B;
1073 cs->BC_Write_Reg = &WriteW6692B;
1074 cs->BC_Send_Data = &W6692B_fill_fifo;
1075 cs->cardmsg = &w6692_card_msg;
1076 cs->irq_func = &W6692_interrupt;
1078 W6692Version(cs,
"W6692:");