64 static void Amd7930_new_ph(
struct IsdnCardState *
cs);
66 static WORD initAMD[] = {
69 0x00A5, 3, 0x01, 0x40, 0x58,
73 0x0090, 4, 0xFE, 0xFF, 0x02, 0x0F,
74 0x0084, 2, 0x80, 0x00,
84 0x0045, 4, 0x61, 0x72, 0x00, 0x00,
85 0x0063, 2, 0x08, 0x08,
86 0x0064, 2, 0x08, 0x08,
87 0x0065, 2, 0x99, 0x00,
88 0x0066, 2, 0x7C, 0x8B,
89 0x0067, 2, 0x00, 0x00,
90 0x0068, 2, 0x20, 0x20,
110 ReadWordAmd7930(
struct IsdnCardState *cs,
BYTE reg)
129 Amd7930_ph_command(
struct IsdnCardState *cs,
u_char command,
char *
s)
131 if (cs->debug & L1_DEB_ISAC)
132 debugl1(cs,
"AMD7930: %s: ph_command 0x%02X", s, command);
140 static BYTE i430States[] = {
142 0x01, 0x02, 0x00, 0x00, 0x00, 0x07, 0x05, 0x00,
143 0x01, 0x02, 0x00, 0x00, 0x00, 0x07, 0x05, 0x00,
144 0x01, 0x02, 0x00, 0x00, 0x00, 0x09, 0x05, 0x04,
145 0x01, 0x02, 0x00, 0x00, 0x1B, 0x00, 0x00, 0x00,
146 0x01, 0x02, 0x00, 0x00, 0x1B, 0x00, 0x00, 0x00,
147 0x01, 0x03, 0x00, 0x00, 0x00, 0x06, 0x05, 0x00,
148 0x11, 0x13, 0x00, 0x00, 0x1B, 0x00, 0x15, 0x00,
149 0x01, 0x03, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
150 0x01, 0x03, 0x00, 0x00, 0x00, 0x09, 0x00, 0x0A};
154 static BYTE stateHelper[] = { 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
160 Amd7930_get_state(
struct IsdnCardState *cs) {
162 cs->dc.amd7930.ph_state = (lsr & 0x7) + 2;
169 Amd7930_new_ph(
struct IsdnCardState *cs)
171 u_char index = stateHelper[cs->dc.amd7930.old_state] * 8 + stateHelper[cs->dc.amd7930.ph_state] - 1;
174 if (cs->debug & L1_DEB_ISAC)
175 debugl1(cs,
"AMD7930: new_ph %d, old_ph %d, message %d, index %d",
176 cs->dc.amd7930.ph_state, cs->dc.amd7930.old_state, message & 0x0f, index);
178 cs->dc.amd7930.old_state = cs->dc.amd7930.ph_state;
181 if ((message & 0xf0) && (cs->tx_skb)) {
186 switch (message & 0x0f) {
190 Amd7930_get_state(cs);
200 Amd7930_ph_command(cs, 0x50,
"HW_ENABLE REQUEST");
216 Amd7930_ph_command(cs, 0x40,
"HW_ENABLE REQ cleared if set");
222 Amd7930_ph_command(cs, 0x40,
"T3 expired, HW_ENABLE REQ cleared");
223 cs->dc.amd7930.old_state = 3;
238 struct IsdnCardState *cs =
240 struct PStack *stptr;
244 debugl1(cs,
"Amd7930: bh, D-Channel Busy cleared");
246 while (stptr !=
NULL) {
252 if (cs->debug & L1_DEB_ISAC)
253 debugl1(cs,
"AMD7930: bh, D_L1STATECHANGE");
258 if (cs->debug & L1_DEB_ISAC)
259 debugl1(cs,
"AMD7930: bh, D_RCVBUFREADY");
264 if (cs->debug & L1_DEB_ISAC)
265 debugl1(cs,
"AMD7930: bh, D_XMTBUFREADY");
271 Amd7930_empty_Dfifo(
struct IsdnCardState *cs,
int flag)
279 if ((cs->debug & L1_DEB_ISAC) && !(cs->debug & L1_DEB_ISAC_FIFO))
280 debugl1(cs,
"Amd7930: empty_Dfifo");
283 ptr = cs->rcvbuf + cs->rcvidx;
296 cs->rcvidx = ptr - cs->rcvbuf;
307 if ((cs->rcvidx) > 0) {
308 if (!(skb = alloc_skb(cs->rcvidx,
GFP_ATOMIC)))
312 if (cs->debug & L1_DEB_ISAC_FIFO) {
315 t +=
sprintf(t,
"Amd7930: empty_Dfifo cnt: %d |", cs->rcvidx);
316 QuickHex(t, cs->rcvbuf, cs->rcvidx);
334 if (cs->debug & L1_DEB_WARN)
335 debugl1(cs,
"AMD7930: empty_Dfifo L2-Framelength overrun");
345 Amd7930_fill_Dfifo(
struct IsdnCardState *cs)
352 if ((cs->debug & L1_DEB_ISAC) && !(cs->debug & L1_DEB_ISAC_FIFO))
353 debugl1(cs,
"Amd7930: fill_Dfifo");
355 if ((!cs->tx_skb) || (cs->tx_skb->len <= 0))
359 if (!cs->dc.amd7930.tx_xmtlen)
361 len = dtcrw = cs->tx_skb->len;
363 else len = cs->dc.amd7930.tx_xmtlen;
369 deb_ptr = ptr = cs->tx_skb->data;
373 while ((txstat & 0x10) && (cs->tx_cnt < len)) {
379 count = ptr - cs->tx_skb->data;
386 if (cs->debug & L1_DEB_ISAC) {
387 debugl1(cs,
"Amd7930: fill_Dfifo, DMR3: 0x%02X, DTCR read: 0x%04X write: 0x%02X 0x%02X", dmr3, dtcrr,
LOBYTE(dtcrw),
HIBYTE(dtcrw));
391 if (!cs->dc.amd7930.tx_xmtlen) {
393 cs->dc.amd7930.tx_xmtlen = dtcrw;
397 debugl1(cs,
"Amd7930: fill_Dfifo dbusytimer running");
404 if (cs->debug & L1_DEB_ISAC_FIFO) {
407 t +=
sprintf(t,
"Amd7930: fill_Dfifo cnt: %d |", count);
418 BYTE dsr1, dsr2, lsr;
429 if (cs->debug & L1_DEB_ISAC)
430 debugl1(cs,
"Amd7930: interrupt: flags: 0x%02X, DSR1: 0x%02X, DSR2: 0x%02X, LSR: 0x%02X, DER=0x%04X", irflags, dsr1, dsr2, lsr, der);
433 if (der || (dsr2 & 4)) {
435 if (cs->debug & L1_DEB_WARN)
436 debugl1(cs,
"Amd7930: interrupt: D error DER=0x%04X", der);
450 cs->dc.amd7930.tx_xmtlen = 0;
451 Amd7930_fill_Dfifo(cs);
454 debugl1(cs,
"Amd7930: interrupt: D-Collision, no skb");
458 Amd7930_empty_Dfifo(cs, 1);
468 cs->dc.amd7930.tx_xmtlen = 0;
469 Amd7930_fill_Dfifo(cs);
475 if (cs->debug & L1_DEB_ISAC)
476 debugl1(cs,
"Amd7930: interrupt: clear Timer and fill D-TX-FIFO if data");
487 Amd7930_fill_Dfifo(cs);
495 if ((irflags & 2) || (dsr1 & 2)) {
496 if (cs->debug & L1_DEB_ISAC)
497 debugl1(cs,
"Amd7930: interrupt: empty D-FIFO");
498 Amd7930_empty_Dfifo(cs, 0);
504 if (cs->debug & L1_DEB_ISAC) {
505 debugl1(cs,
"Amd7930: interrupt: transmit packet ready");
516 if (cs->debug & L1_DEB_ISAC)
517 debugl1(cs,
"Amd7930: interrupt: TX-Packet ready, freeing skb");
520 cs->dc.amd7930.tx_xmtlen = 0;
524 if (cs->debug & L1_DEB_ISAC)
525 debugl1(cs,
"Amd7930: interrupt: TX-Packet ready, next packet dequeued");
527 cs->dc.amd7930.tx_xmtlen = 0;
528 Amd7930_fill_Dfifo(cs);
541 if (cs->debug & L1_DEB_ISAC)
542 debugl1(cs,
"Amd: interrupt: LSR=0x%02X, LIU is in state %d", lsr, ((lsr & 0x7) + 2));
544 cs->dc.amd7930.ph_state = (lsr & 0x7) + 2;
558 Amd7930_l1hw(
struct PStack *
st,
int pr,
void *
arg)
560 struct IsdnCardState *cs = (
struct IsdnCardState *) st->l1.hardware;
564 if (cs->debug & L1_DEB_ISAC)
565 debugl1(cs,
"Amd7930: l1hw called, pr: 0x%04X", pr);
569 if (cs->debug & DEB_DLOG_HEX)
571 if (cs->debug & DEB_DLOG_VERBOSE)
577 if (cs->debug & L1_DEB_LAPD)
578 Logl2Frame(cs, skb,
"Amd7930: l1hw: PH_DATA Queued", 0);
583 cs->dc.amd7930.tx_xmtlen = 0;
585 if (cs->debug & L1_DEB_LAPD)
586 Logl2Frame(cs, skb,
"Amd7930: l1hw: PH_DATA", 0);
588 Amd7930_fill_Dfifo(cs);
590 spin_unlock_irqrestore(&cs->lock,
flags);
595 if (cs->debug & L1_DEB_WARN)
596 debugl1(cs,
"Amd7930: l1hw: l2l1 tx_skb exist this shouldn't happen");
598 spin_unlock_irqrestore(&cs->lock,
flags);
601 if (cs->debug & DEB_DLOG_HEX)
603 if (cs->debug & DEB_DLOG_VERBOSE)
607 cs->dc.amd7930.tx_xmtlen = 0;
609 if (cs->debug & L1_DEB_LAPD)
610 Logl2Frame(cs, skb,
"Amd7930: l1hw: PH_DATA_PULLED", 0);
612 Amd7930_fill_Dfifo(cs);
613 spin_unlock_irqrestore(&cs->lock,
flags);
617 if (cs->debug & L1_DEB_LAPD)
618 debugl1(cs,
"Amd7930: l1hw: -> PH_REQUEST_PULL, skb: %s", (cs->tx_skb) ?
"yes" :
"no");
628 if ((cs->dc.amd7930.ph_state == 8)) {
631 Amd7930_ph_command(cs, 0x20,
"HW_RESET REQEST");
632 spin_unlock_irqrestore(&cs->lock,
flags);
634 Amd7930_ph_command(cs, 0x40,
"HW_RESET REQUEST");
635 cs->dc.amd7930.ph_state = 2;
636 spin_unlock_irqrestore(&cs->lock,
flags);
641 cs->dc.amd7930.ph_state = 9;
654 dev_kfree_skb(cs->tx_skb);
663 if (cs->debug & L1_DEB_WARN)
664 debugl1(cs,
"Amd7930: l1hw: unknown %04x", pr);
670 setstack_Amd7930(
struct PStack *st,
struct IsdnCardState *cs)
673 if (cs->debug & L1_DEB_ISAC)
674 debugl1(cs,
"Amd7930: setstack called");
676 st->l1.l1hw = Amd7930_l1hw;
681 DC_Close_Amd7930(
struct IsdnCardState *cs) {
682 if (cs->debug & L1_DEB_ISAC)
683 debugl1(cs,
"Amd7930: DC_Close called");
688 dbusy_timer_handler(
struct IsdnCardState *cs)
691 struct PStack *stptr;
696 if (cs->debug & L1_DEB_ISAC)
697 debugl1(cs,
"Amd7930: dbusy_timer expired!");
699 if (
test_bit(FLG_DBUSY_TIMER, &cs->HW_Flags)) {
708 if (cs->debug & L1_DEB_ISAC)
709 debugl1(cs,
"Amd7930: dbusy_timer_handler: DSR1=0x%02X, DSR2=0x%02X, DER=0x%04X, cs->tx_skb->len=%u, tx_stat=%u, dtcr=%u, cs->tx_cnt=%u", dsr1, dsr2, der, cs->tx_skb->len, cs->dc.amd7930.tx_xmtlen, dtcr, cs->tx_cnt);
711 if ((cs->dc.amd7930.tx_xmtlen - dtcr) < cs->tx_cnt) {
714 spin_unlock_irqrestore(&cs->lock, flags);
715 while (stptr !=
NULL) {
727 cs->dc.amd7930.tx_xmtlen = 0;
730 debugl1(cs,
"Amd7930: D-Channel Busy no skb");
736 spin_unlock_irqrestore(&cs->lock, flags);
737 cs->irq_func(cs->irq, cs);
739 if (cs->debug & L1_DEB_ISAC)
740 debugl1(cs,
"Amd7930: dbusy_timer_handler: Transmitter reset");
752 if (cs->debug & L1_DEB_ISAC)
753 debugl1(cs,
"Amd7930: initamd called");
755 cs->dc.amd7930.tx_xmtlen = 0;
756 cs->dc.amd7930.old_state = 0;
757 cs->dc.amd7930.lmr1 = 0x40;
758 cs->dc.amd7930.ph_command = Amd7930_ph_command;
759 cs->setstack_d = setstack_Amd7930;
760 cs->DC_Close = DC_Close_Amd7930;
763 for (ptr = initAMD; *ptr != 0xFFFF; ) {
767 if (*ptr++ >= 0x100) {
773 for (cnt = *ptr++; cnt > 0; cnt--)
783 for (cnt = *ptr++; cnt > 0; cnt--)
793 cs->dbusytimer.function = (
void *) dbusy_timer_handler;
794 cs->dbusytimer.data = (
long) cs;