14 #include <linux/sched.h>
15 #include <linux/slab.h>
25 #define byteout(addr, val) outb(val, addr)
26 #define bytein(addr) inb(addr)
40 if (cs->hw.hfcD.cip != reg) {
41 cs->hw.hfcD.cip =
reg;
42 byteout(cs->hw.hfcD.addr | 1, reg);
44 ret =
bytein(cs->hw.hfcD.addr);
46 if (cs->debug & L1_DEB_HSCX_FIFO && (data != 2))
47 debugl1(cs,
"t3c RD %02x %02x", reg, ret);
50 ret =
bytein(cs->hw.hfcD.addr | 1);
57 if (cs->hw.hfcD.cip != reg) {
58 cs->hw.hfcD.cip =
reg;
59 byteout(cs->hw.hfcD.addr | 1, reg);
62 byteout(cs->hw.hfcD.addr, value);
65 debugl1(cs,
"t3c W%c %02x %02x", data ?
'D' :
'C', reg, value);
78 writereghfcd(
struct IsdnCardState *cs,
u_char offset,
u_char value)
84 WaitForBusy(
struct IsdnCardState *cs)
98 WaitNoBusy(
struct IsdnCardState *cs)
112 SelFiFo(
struct IsdnCardState *cs,
u_char FiFo)
116 if (cs->hw.hfcD.fifo == FiFo)
135 cs->hw.hfcD.fifo = FiFo;
143 GetFreeFifoBytes_B(
struct BCState *bcs)
147 if (bcs->hw.hfc.f1 == bcs->hw.hfc.f2)
148 return (bcs->cs->hw.hfcD.bfifosize);
149 s = bcs->hw.hfc.send[bcs->hw.hfc.f1] - bcs->hw.hfc.send[bcs->hw.hfc.f2];
151 s += bcs->cs->hw.hfcD.bfifosize;
152 s = bcs->cs->hw.hfcD.bfifosize -
s;
157 GetFreeFifoBytes_D(
struct IsdnCardState *cs)
161 if (cs->hw.hfcD.f1 == cs->hw.hfcD.f2)
162 return (cs->hw.hfcD.dfifosize);
163 s = cs->hw.hfcD.send[cs->hw.hfcD.f1] - cs->hw.hfcD.send[cs->hw.hfcD.f2];
165 s += cs->hw.hfcD.dfifosize;
166 s = cs->hw.hfcD.dfifosize -
s;
171 ReadZReg(
struct IsdnCardState *cs,
u_char reg)
183 *hfc_empty_fifo(
struct BCState *bcs,
int count)
187 struct IsdnCardState *cs = bcs->cs;
192 if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
196 if (cs->debug & L1_DEB_WARN)
197 debugl1(cs,
"hfc_empty_fifo: incoming packet too large");
199 while (idx++ < count) {
204 }
else if (count < 4) {
205 if (cs->debug & L1_DEB_WARN)
206 debugl1(cs,
"hfc_empty_fifo: incoming packet too small");
208 #ifdef ERROR_STATISTIC
211 while ((idx++ < count) && WaitNoBusy(cs))
214 }
else if (!(skb = dev_alloc_skb(count - 3)))
220 while (idx < (count - 3)) {
227 if (idx != count - 3) {
228 debugl1(cs,
"RFIFO BUSY error");
234 chksum = (ReadReg(cs,
HFCD_DATA, cip) << 8);
239 if (cs->debug & L1_DEB_HSCX)
240 debugl1(cs,
"hfc_empty_fifo %d chksum %x stat %x",
241 bcs->channel, chksum, stat);
246 #ifdef ERROR_STATISTIC
261 hfc_fill_fifo(
struct BCState *bcs)
263 struct IsdnCardState *cs = bcs->cs;
270 if (bcs->tx_skb->len <= 0)
275 bcs->hw.hfc.f1 = ReadReg(cs,
HFCD_DATA, cip);
279 bcs->hw.hfc.f2 = ReadReg(cs,
HFCD_DATA, cip);
281 if (cs->debug & L1_DEB_HSCX)
282 debugl1(cs,
"hfc_fill_fifo %d f1(%d) f2(%d) z1(%x)",
283 bcs->channel, bcs->hw.hfc.f1, bcs->hw.hfc.f2,
284 bcs->hw.hfc.send[bcs->hw.hfc.f1]);
285 fcnt = bcs->hw.hfc.f1 - bcs->hw.hfc.f2;
289 if (cs->debug & L1_DEB_HSCX)
290 debugl1(cs,
"hfc_fill_fifo more as 30 frames");
293 count = GetFreeFifoBytes_B(bcs);
294 if (cs->debug & L1_DEB_HSCX)
295 debugl1(cs,
"hfc_fill_fifo %d count(%u/%d),%lx",
296 bcs->channel, bcs->tx_skb->len,
298 if (count < bcs->tx_skb->len) {
299 if (cs->debug & L1_DEB_HSCX)
300 debugl1(cs,
"hfc_fill_fifo no fifo mem");
308 while (idx < bcs->tx_skb->len) {
314 if (idx != bcs->tx_skb->len) {
315 debugl1(cs,
"FIFO Send BUSY error");
318 bcs->tx_cnt -= bcs->tx_skb->len;
319 if (
test_bit(FLG_LLI_L1WAKEUP, &bcs->st->lli.flag) &&
320 (PACKET_NOACK != bcs->tx_skb->pkt_type)) {
323 bcs->ackcnt += bcs->tx_skb->len;
324 spin_unlock_irqrestore(&bcs->aclock, flags);
339 hfc_send_data(
struct BCState *bcs)
341 struct IsdnCardState *cs = bcs->cs;
347 debugl1(cs,
"send_data %d blocked", bcs->channel);
351 main_rec_2bds0(
struct BCState *bcs)
353 struct IsdnCardState *cs = bcs->cs;
356 int receive, count = 5;
362 debugl1(cs,
"rec_data %d blocked", bcs->channel);
373 if (cs->debug & L1_DEB_HSCX)
374 debugl1(cs,
"hfc rec %d f1(%d) f2(%d)",
375 bcs->channel, f1, f2);
380 rcnt += cs->hw.hfcD.bfifosize;
382 if (cs->debug & L1_DEB_HSCX)
383 debugl1(cs,
"hfc rec %d z1(%x) z2(%x) cnt(%d)",
384 bcs->channel, z1, z2, rcnt);
385 if ((skb = hfc_empty_fifo(bcs, rcnt))) {
399 if (count && receive)
405 mode_2bs0(
struct BCState *bcs,
int mode,
int bc)
407 struct IsdnCardState *cs = bcs->cs;
409 if (cs->debug & L1_DEB_HSCX)
410 debugl1(cs,
"HFCD bchannel mode %d bchan %d/%d",
411 mode, bc, bcs->channel);
417 cs->hw.hfcD.conn |= 0x18;
420 cs->hw.hfcD.conn |= 0x3;
426 cs->hw.hfcD.ctmt |= 2;
427 cs->hw.hfcD.conn &= ~0x18;
430 cs->hw.hfcD.ctmt |= 1;
431 cs->hw.hfcD.conn &= ~0x3;
437 cs->hw.hfcD.ctmt &= ~2;
438 cs->hw.hfcD.conn &= ~0x18;
441 cs->hw.hfcD.ctmt &= ~1;
442 cs->hw.hfcD.conn &= ~0x3;
453 hfc_l2l1(
struct PStack *
st,
int pr,
void *
arg)
455 struct BCState *bcs = st->l1.bcs;
467 bcs->cs->BC_Send_Data(bcs);
469 spin_unlock_irqrestore(&bcs->cs->lock, flags);
478 bcs->cs->BC_Send_Data(bcs);
480 spin_unlock_irqrestore(&bcs->cs->lock, flags);
492 mode_2bs0(bcs, st->l1.mode, st->l1.bc);
493 spin_unlock_irqrestore(&bcs->cs->lock, flags);
503 mode_2bs0(bcs, 0, st->l1.bc);
504 spin_unlock_irqrestore(&bcs->cs->lock, flags);
511 close_2bs0(
struct BCState *bcs)
513 mode_2bs0(bcs, 0, bcs->channel);
526 open_hfcstate(
struct IsdnCardState *cs,
struct BCState *bcs)
529 skb_queue_head_init(&bcs->rqueue);
530 skb_queue_head_init(&bcs->squeue);
540 setstack_2b(
struct PStack *st,
struct BCState *bcs)
542 bcs->channel = st->l1.bc;
543 if (open_hfcstate(st->l1.hardware, bcs))
546 st->l2.l2l1 = hfc_l2l1;
556 struct IsdnCardState *cs =
560 switch (cs->dc.hfcd.ph_state) {
587 int receive_dmsg(
struct IsdnCardState *cs)
598 debugl1(cs,
"rec_dmsg blocked");
604 f1 = cs->readisac(cs, cip) & 0xf;
607 f2 = cs->readisac(cs, cip) & 0xf;
608 while ((f1 != f2) && count--) {
613 rcnt += cs->hw.hfcD.dfifosize;
615 if (cs->debug & L1_DEB_ISAC)
616 debugl1(cs,
"hfcd recd f1(%d) f2(%d) z1(%x) z2(%x) cnt(%d)",
617 f1, f2, z1, z2, rcnt);
621 if (cs->debug & L1_DEB_WARN)
622 debugl1(cs,
"empty_fifo d: incoming packet too large");
624 if (!(WaitNoBusy(cs)))
629 }
else if (rcnt < 4) {
630 if (cs->debug & L1_DEB_WARN)
631 debugl1(cs,
"empty_fifo d: incoming packet too small");
632 while ((idx++ < rcnt) && WaitNoBusy(cs))
634 }
else if ((skb = dev_alloc_skb(rcnt - 3))) {
636 while (idx < (rcnt - 3)) {
637 if (!(WaitNoBusy(cs)))
643 if (idx != (rcnt - 3)) {
644 debugl1(cs,
"RFIFO D BUSY error");
648 #ifdef ERROR_STATISTIC
653 chksum = (ReadReg(cs,
HFCD_DATA, cip) << 8);
658 if (cs->debug & L1_DEB_ISAC)
659 debugl1(cs,
"empty_dfifo chksum %x stat %x",
665 #ifdef ERROR_STATISTIC
682 f2 = cs->readisac(cs, cip) & 0xf;
689 hfc_fill_dfifo(
struct IsdnCardState *cs)
697 if (cs->tx_skb->len <= 0)
703 cs->hw.hfcD.f1 = ReadReg(cs,
HFCD_DATA, cip) & 0xf;
706 cs->hw.hfcD.f2 = ReadReg(cs,
HFCD_DATA, cip) & 0xf;
708 if (cs->debug & L1_DEB_ISAC)
709 debugl1(cs,
"hfc_fill_Dfifo f1(%d) f2(%d) z1(%x)",
710 cs->hw.hfcD.f1, cs->hw.hfcD.f2,
711 cs->hw.hfcD.send[cs->hw.hfcD.f1]);
712 fcnt = cs->hw.hfcD.f1 - cs->hw.hfcD.f2;
716 if (cs->debug & L1_DEB_HSCX)
717 debugl1(cs,
"hfc_fill_Dfifo more as 14 frames");
720 count = GetFreeFifoBytes_D(cs);
721 if (cs->debug & L1_DEB_ISAC)
722 debugl1(cs,
"hfc_fill_Dfifo count(%u/%d)",
723 cs->tx_skb->len, count);
724 if (count < cs->tx_skb->len) {
725 if (cs->debug & L1_DEB_ISAC)
726 debugl1(cs,
"hfc_fill_Dfifo no fifo mem");
734 while (idx < cs->tx_skb->len) {
735 if (!(WaitNoBusy(cs)))
740 if (idx != cs->tx_skb->len) {
741 debugl1(cs,
"DFIFO Send BUSY error");
754 struct BCState *Sel_BCS(
struct IsdnCardState *cs,
int channel)
756 if (cs->bcs[0].mode && (cs->bcs[0].channel == channel))
757 return (&cs->bcs[0]);
758 else if (cs->bcs[1].mode && (cs->bcs[1].channel == channel))
759 return (&cs->bcs[1]);
771 if (cs->debug & L1_DEB_ISAC)
772 debugl1(cs,
"HFCD irq %x %s", val,
773 test_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags) ?
774 "locked" :
"unlocked");
775 val &= cs->hw.hfcD.int_m1;
778 if (cs->debug & L1_DEB_ISAC)
779 debugl1(cs,
"ph_state chg %d->%d", cs->dc.hfcd.ph_state,
781 cs->dc.hfcd.ph_state = exval;
786 if (
test_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
787 cs->hw.hfcD.int_s1 |=
val;
790 if (cs->hw.hfcD.int_s1 & 0x18) {
792 val = cs->hw.hfcD.int_s1;
793 cs->hw.hfcD.int_s1 = exval;
796 if (!(bcs = Sel_BCS(cs, 0))) {
798 debugl1(cs,
"hfcd spurious 0x08 IRQ");
803 if (!(bcs = Sel_BCS(cs, 1))) {
805 debugl1(cs,
"hfcd spurious 0x10 IRQ");
810 if (!(bcs = Sel_BCS(cs, 0))) {
812 debugl1(cs,
"hfcd spurious 0x01 IRQ");
819 debugl1(cs,
"fill_data %d blocked", bcs->channel);
826 debugl1(cs,
"fill_data %d blocked", bcs->channel);
834 if (!(bcs = Sel_BCS(cs, 1))) {
836 debugl1(cs,
"hfcd spurious 0x02 IRQ");
843 debugl1(cs,
"fill_data %d blocked", bcs->channel);
850 debugl1(cs,
"fill_data %d blocked", bcs->channel);
866 if (cs->tx_skb->len) {
871 debugl1(cs,
"hfc_fill_dfifo irq blocked");
886 debugl1(cs,
"hfc_fill_dfifo irq blocked");
892 if (cs->hw.hfcD.int_s1 && count--) {
893 val = cs->hw.hfcD.int_s1;
894 cs->hw.hfcD.int_s1 = 0;
895 if (cs->debug & L1_DEB_ISAC)
896 debugl1(cs,
"HFCD irq %x loop %d", val, 15-count);
903 HFCD_l1hw(
struct PStack *st,
int pr,
void *arg)
905 struct IsdnCardState *cs = (
struct IsdnCardState *) st->l1.hardware;
911 if (cs->debug & DEB_DLOG_HEX)
913 if (cs->debug & DEB_DLOG_VERBOSE)
919 if (cs->debug & L1_DEB_LAPD)
926 if (cs->debug & L1_DEB_LAPD)
933 debugl1(cs,
"hfc_fill_dfifo blocked");
936 spin_unlock_irqrestore(&cs->lock, flags);
941 if (cs->debug & L1_DEB_WARN)
942 debugl1(cs,
" l2l1 tx_skb exist this shouldn't happen");
944 spin_unlock_irqrestore(&cs->lock, flags);
947 if (cs->debug & DEB_DLOG_HEX)
949 if (cs->debug & DEB_DLOG_VERBOSE)
954 if (cs->debug & L1_DEB_LAPD)
961 debugl1(cs,
"hfc_fill_dfifo blocked");
962 spin_unlock_irqrestore(&cs->lock, flags);
966 if (cs->debug & L1_DEB_LAPD)
967 debugl1(cs,
"-> PH_REQUEST_PULL");
983 spin_unlock_irqrestore(&cs->lock, flags);
989 spin_unlock_irqrestore(&cs->lock, flags);
995 spin_unlock_irqrestore(&cs->lock, flags);
1001 spin_unlock_irqrestore(&cs->lock, flags);
1004 if (cs->debug & L1_DEB_WARN)
1005 debugl1(cs,
"hfcd_l1hw unknown pr %4x", pr);
1011 setstack_hfcd(
struct PStack *st,
struct IsdnCardState *cs)
1013 st->l1.l1hw = HFCD_l1hw;
1017 hfc_dbusy_timer(
struct IsdnCardState *cs)
1022 *init_send_hfcd(
int cnt)
1029 "HiSax: No memory for hfcd.send\n");
1032 for (i = 0; i <
cnt; i++)
1040 cs->setstack_d = setstack_hfcd;
1041 if (!cs->hw.hfcD.send)
1042 cs->hw.hfcD.send = init_send_hfcd(16);
1043 if (!cs->bcs[0].hw.hfc.send)
1044 cs->bcs[0].hw.hfc.send = init_send_hfcd(32);
1045 if (!cs->bcs[1].hw.hfc.send)
1046 cs->bcs[1].hw.hfc.send = init_send_hfcd(32);
1047 cs->BC_Send_Data = &hfc_send_data;
1048 cs->bcs[0].BC_SetStack = setstack_2b;
1049 cs->bcs[1].BC_SetStack = setstack_2b;
1050 cs->bcs[0].BC_Close = close_2bs0;
1051 cs->bcs[1].BC_Close = close_2bs0;
1052 mode_2bs0(cs->bcs, 0, 0);
1053 mode_2bs0(cs->bcs + 1, 0, 1);
1059 kfree(cs->bcs[0].hw.hfc.send);
1060 cs->bcs[0].hw.hfc.send =
NULL;
1061 kfree(cs->bcs[1].hw.hfc.send);
1062 cs->bcs[1].hw.hfc.send =
NULL;
1063 kfree(cs->hw.hfcD.send);
1064 cs->hw.hfcD.send =
NULL;
1070 cs->readisac = &readreghfcd;
1071 cs->writeisac = &writereghfcd;
1072 cs->readisacfifo = &dummyf;
1073 cs->writeisacfifo = &dummyf;
1074 cs->BC_Read_Reg = &ReadReg;
1075 cs->BC_Write_Reg = &WriteReg;
1076 cs->dbusytimer.function = (
void *) hfc_dbusy_timer;
1077 cs->dbusytimer.data = (
long) cs;