1 /* $Id: hfc_2bds0.c,v 1.1.4.1 2001/11/20 14:19:35 kai Exp $
3 * specific routines for CCD's HFC 2BDS0
6 * Copyright by Karsten Keil <keil@isdn4linux.de>
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
13 #define __NO_VERSION__
14 #include <linux/init.h>
16 #include "hfc_2bds0.h"
18 #include <linux/interrupt.h>
24 #define byteout(addr,val) outb(val,addr)
25 #define bytein(addr) inb(addr)
28 dummyf(struct IsdnCardState *cs, u_char * data, int size)
30 printk(KERN_WARNING "HiSax: hfcd dummy fifo called\n");
34 ReadReg(struct IsdnCardState *cs, int data, u_char reg)
39 if (cs->hw.hfcD.cip != reg) {
40 cs->hw.hfcD.cip = reg;
41 byteout(cs->hw.hfcD.addr | 1, reg);
43 ret = bytein(cs->hw.hfcD.addr);
45 if (cs->debug & L1_DEB_HSCX_FIFO && (data != 2))
46 debugl1(cs, "t3c RD %02x %02x", reg, ret);
49 ret = bytein(cs->hw.hfcD.addr | 1);
54 WriteReg(struct IsdnCardState *cs, int data, u_char reg, u_char value)
56 if (cs->hw.hfcD.cip != reg) {
57 cs->hw.hfcD.cip = reg;
58 byteout(cs->hw.hfcD.addr | 1, reg);
61 byteout(cs->hw.hfcD.addr, value);
63 if (cs->debug & L1_DEB_HSCX_FIFO && (data != HFCD_DATA_NODEB))
64 debugl1(cs, "t3c W%c %02x %02x", data ? 'D' : 'C', reg, value);
68 /* Interface functions */
71 readreghfcd(struct IsdnCardState *cs, u_char offset)
73 return(ReadReg(cs, HFCD_DATA, offset));
77 writereghfcd(struct IsdnCardState *cs, u_char offset, u_char value)
79 WriteReg(cs, HFCD_DATA, offset, value);
83 set_cs_func(struct IsdnCardState *cs)
85 cs->readisac = &readreghfcd;
86 cs->writeisac = &writereghfcd;
87 cs->readisacfifo = &dummyf;
88 cs->writeisacfifo = &dummyf;
89 cs->BC_Read_Reg = &ReadReg;
90 cs->BC_Write_Reg = &WriteReg;
94 WaitForBusy(struct IsdnCardState *cs)
98 while (!(ReadReg(cs, HFCD_DATA, HFCD_STAT) & HFCD_BUSY) && to) {
103 printk(KERN_WARNING "HiSax: WaitForBusy timeout\n");
108 WaitNoBusy(struct IsdnCardState *cs)
113 while ((ReadReg(cs, HFCD_STATUS, HFCD_STATUS) & HFCD_BUSY) && to) {
118 restore_flags(flags);
121 printk(KERN_WARNING "HiSax: WaitNoBusy timeout\n");
126 SelFiFo(struct IsdnCardState *cs, u_char FiFo)
132 if (cs->hw.hfcD.fifo == FiFo)
137 case 0: cip = HFCB_FIFO | HFCB_Z1 | HFCB_SEND | HFCB_B1;
139 case 1: cip = HFCB_FIFO | HFCB_Z1 | HFCB_REC | HFCB_B1;
141 case 2: cip = HFCB_FIFO | HFCB_Z1 | HFCB_SEND | HFCB_B2;
143 case 3: cip = HFCB_FIFO | HFCB_Z1 | HFCB_REC | HFCB_B2;
145 case 4: cip = HFCD_FIFO | HFCD_Z1 | HFCD_SEND;
147 case 5: cip = HFCD_FIFO | HFCD_Z1 | HFCD_REC;
150 restore_flags(flags);
151 debugl1(cs, "SelFiFo Error");
154 cs->hw.hfcD.fifo = FiFo;
156 cs->BC_Write_Reg(cs, HFCD_DATA, cip, 0);
159 restore_flags(flags);
163 GetFreeFifoBytes_B(struct BCState *bcs)
167 if (bcs->hw.hfc.f1 == bcs->hw.hfc.f2)
168 return (bcs->cs->hw.hfcD.bfifosize);
169 s = bcs->hw.hfc.send[bcs->hw.hfc.f1] - bcs->hw.hfc.send[bcs->hw.hfc.f2];
171 s += bcs->cs->hw.hfcD.bfifosize;
172 s = bcs->cs->hw.hfcD.bfifosize - s;
177 GetFreeFifoBytes_D(struct IsdnCardState *cs)
181 if (cs->hw.hfcD.f1 == cs->hw.hfcD.f2)
182 return (cs->hw.hfcD.dfifosize);
183 s = cs->hw.hfcD.send[cs->hw.hfcD.f1] - cs->hw.hfcD.send[cs->hw.hfcD.f2];
185 s += cs->hw.hfcD.dfifosize;
186 s = cs->hw.hfcD.dfifosize - s;
191 ReadZReg(struct IsdnCardState *cs, u_char reg)
196 val = 256 * ReadReg(cs, HFCD_DATA, reg | HFCB_Z_HIGH);
198 val += ReadReg(cs, HFCD_DATA, reg | HFCB_Z_LOW);
203 hfc_sched_event(struct BCState *bcs, int event)
205 bcs->event |= 1 << event;
206 queue_task(&bcs->tqueue, &tq_immediate);
207 mark_bh(IMMEDIATE_BH);
210 static struct sk_buff
211 *hfc_empty_fifo(struct BCState *bcs, int count)
215 struct IsdnCardState *cs = bcs->cs;
221 if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
222 debugl1(cs, "hfc_empty_fifo");
225 if (count > HSCX_BUFMAX + 3) {
226 if (cs->debug & L1_DEB_WARN)
227 debugl1(cs, "hfc_empty_fifo: incoming packet too large");
228 cip = HFCB_FIFO | HFCB_FIFO_OUT | HFCB_REC | HFCB_CHANNEL(bcs->channel);
229 while (idx++ < count) {
232 ReadReg(cs, HFCD_DATA_NODEB, cip);
236 } else if (count < 4) {
237 if (cs->debug & L1_DEB_WARN)
238 debugl1(cs, "hfc_empty_fifo: incoming packet too small");
239 cip = HFCB_FIFO | HFCB_FIFO_OUT | HFCB_REC | HFCB_CHANNEL(bcs->channel);
240 #ifdef ERROR_STATISTIC
244 while ((idx++ < count) && WaitNoBusy(cs))
245 ReadReg(cs, HFCD_DATA_NODEB, cip);
247 } else if (!(skb = dev_alloc_skb(count - 3)))
248 printk(KERN_WARNING "HFC: receive out of memory\n");
250 ptr = skb_put(skb, count - 3);
252 cip = HFCB_FIFO | HFCB_FIFO_OUT | HFCB_REC | HFCB_CHANNEL(bcs->channel);
254 while (idx < (count - 3)) {
258 *ptr = ReadReg(cs, HFCD_DATA_NODEB, cip);
263 if (idx != count - 3) {
265 debugl1(cs, "RFIFO BUSY error");
266 printk(KERN_WARNING "HFC FIFO channel %d BUSY Error\n", bcs->channel);
267 dev_kfree_skb_irq(skb);
272 chksum = (ReadReg(cs, HFCD_DATA, cip) << 8);
274 chksum += ReadReg(cs, HFCD_DATA, cip);
276 stat = ReadReg(cs, HFCD_DATA, cip);
278 if (cs->debug & L1_DEB_HSCX)
279 debugl1(cs, "hfc_empty_fifo %d chksum %x stat %x",
280 bcs->channel, chksum, stat);
282 debugl1(cs, "FIFO CRC error");
283 dev_kfree_skb_irq(skb);
285 #ifdef ERROR_STATISTIC
295 stat = ReadReg(cs, HFCD_DATA, HFCB_FIFO | HFCB_F2_INC |
296 HFCB_REC | HFCB_CHANNEL(bcs->channel));
299 restore_flags(flags);
304 hfc_fill_fifo(struct BCState *bcs)
306 struct IsdnCardState *cs = bcs->cs;
314 if (bcs->tx_skb->len <= 0)
318 SelFiFo(cs, HFCB_SEND | HFCB_CHANNEL(bcs->channel));
319 cip = HFCB_FIFO | HFCB_F1 | HFCB_SEND | HFCB_CHANNEL(bcs->channel);
321 bcs->hw.hfc.f1 = ReadReg(cs, HFCD_DATA, cip);
323 cip = HFCB_FIFO | HFCB_F2 | HFCB_SEND | HFCB_CHANNEL(bcs->channel);
325 bcs->hw.hfc.f2 = ReadReg(cs, HFCD_DATA, cip);
326 bcs->hw.hfc.send[bcs->hw.hfc.f1] = ReadZReg(cs, HFCB_FIFO | HFCB_Z1 | HFCB_SEND | HFCB_CHANNEL(bcs->channel));
328 if (cs->debug & L1_DEB_HSCX)
329 debugl1(cs, "hfc_fill_fifo %d f1(%d) f2(%d) z1(%x)",
330 bcs->channel, bcs->hw.hfc.f1, bcs->hw.hfc.f2,
331 bcs->hw.hfc.send[bcs->hw.hfc.f1]);
332 fcnt = bcs->hw.hfc.f1 - bcs->hw.hfc.f2;
336 if (cs->debug & L1_DEB_HSCX)
337 debugl1(cs, "hfc_fill_fifo more as 30 frames");
338 restore_flags(flags);
341 count = GetFreeFifoBytes_B(bcs);
342 if (cs->debug & L1_DEB_HSCX)
343 debugl1(cs, "hfc_fill_fifo %d count(%ld/%d),%lx",
344 bcs->channel, bcs->tx_skb->len,
345 count, current->state);
346 if (count < bcs->tx_skb->len) {
347 if (cs->debug & L1_DEB_HSCX)
348 debugl1(cs, "hfc_fill_fifo no fifo mem");
349 restore_flags(flags);
352 cip = HFCB_FIFO | HFCB_FIFO_IN | HFCB_SEND | HFCB_CHANNEL(bcs->channel);
357 WriteReg(cs, HFCD_DATA_NODEB, cip, bcs->tx_skb->data[idx++]);
358 while (idx < bcs->tx_skb->len) {
362 WriteReg(cs, HFCD_DATA_NODEB, cip, bcs->tx_skb->data[idx]);
366 if (idx != bcs->tx_skb->len) {
368 debugl1(cs, "FIFO Send BUSY error");
369 printk(KERN_WARNING "HFC S FIFO channel %d BUSY Error\n", bcs->channel);
371 bcs->tx_cnt -= bcs->tx_skb->len;
372 if (bcs->st->lli.l1writewakeup &&
373 (PACKET_NOACK != bcs->tx_skb->pkt_type))
374 bcs->st->lli.l1writewakeup(bcs->st, bcs->tx_skb->len);
375 dev_kfree_skb_any(bcs->tx_skb);
381 ReadReg(cs, HFCD_DATA, HFCB_FIFO | HFCB_F1_INC | HFCB_SEND | HFCB_CHANNEL(bcs->channel));
384 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
385 restore_flags(flags);
390 hfc_send_data(struct BCState *bcs)
392 struct IsdnCardState *cs = bcs->cs;
394 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
396 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
398 debugl1(cs,"send_data %d blocked", bcs->channel);
402 main_rec_2bds0(struct BCState *bcs)
405 struct IsdnCardState *cs = bcs->cs;
408 int receive, count = 5;
415 if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
416 debugl1(cs,"rec_data %d blocked", bcs->channel);
417 restore_flags(flags);
420 SelFiFo(cs, HFCB_REC | HFCB_CHANNEL(bcs->channel));
421 cip = HFCB_FIFO | HFCB_F1 | HFCB_REC | HFCB_CHANNEL(bcs->channel);
423 f1 = ReadReg(cs, HFCD_DATA, cip);
424 cip = HFCB_FIFO | HFCB_F2 | HFCB_REC | HFCB_CHANNEL(bcs->channel);
426 f2 = ReadReg(cs, HFCD_DATA, cip);
429 if (cs->debug & L1_DEB_HSCX)
430 debugl1(cs, "hfc rec %d f1(%d) f2(%d)",
431 bcs->channel, f1, f2);
433 z1 = ReadZReg(cs, HFCB_FIFO | HFCB_Z1 | HFCB_REC | HFCB_CHANNEL(bcs->channel));
434 z2 = ReadZReg(cs, HFCB_FIFO | HFCB_Z2 | HFCB_REC | HFCB_CHANNEL(bcs->channel));
438 rcnt += cs->hw.hfcD.bfifosize;
440 if (cs->debug & L1_DEB_HSCX)
441 debugl1(cs, "hfc rec %d z1(%x) z2(%x) cnt(%d)",
442 bcs->channel, z1, z2, rcnt);
443 if ((skb = hfc_empty_fifo(bcs, rcnt))) {
445 skb_queue_tail(&bcs->rqueue, skb);
447 hfc_sched_event(bcs, B_RCVBUFREADY);
458 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
459 if (count && receive)
461 restore_flags(flags);
466 mode_2bs0(struct BCState *bcs, int mode, int bc)
468 struct IsdnCardState *cs = bcs->cs;
470 if (cs->debug & L1_DEB_HSCX)
471 debugl1(cs, "HFCD bchannel mode %d bchan %d/%d",
472 mode, bc, bcs->channel);
478 cs->hw.hfcD.conn |= 0x18;
479 cs->hw.hfcD.sctrl &= ~SCTRL_B2_ENA;
481 cs->hw.hfcD.conn |= 0x3;
482 cs->hw.hfcD.sctrl &= ~SCTRL_B1_ENA;
485 case (L1_MODE_TRANS):
487 cs->hw.hfcD.ctmt |= 2;
488 cs->hw.hfcD.conn &= ~0x18;
489 cs->hw.hfcD.sctrl |= SCTRL_B2_ENA;
491 cs->hw.hfcD.ctmt |= 1;
492 cs->hw.hfcD.conn &= ~0x3;
493 cs->hw.hfcD.sctrl |= SCTRL_B1_ENA;
498 cs->hw.hfcD.ctmt &= ~2;
499 cs->hw.hfcD.conn &= ~0x18;
500 cs->hw.hfcD.sctrl |= SCTRL_B2_ENA;
502 cs->hw.hfcD.ctmt &= ~1;
503 cs->hw.hfcD.conn &= ~0x3;
504 cs->hw.hfcD.sctrl |= SCTRL_B1_ENA;
508 WriteReg(cs, HFCD_DATA, HFCD_SCTRL, cs->hw.hfcD.sctrl);
509 WriteReg(cs, HFCD_DATA, HFCD_CTMT, cs->hw.hfcD.ctmt);
510 WriteReg(cs, HFCD_DATA, HFCD_CONN, cs->hw.hfcD.conn);
514 hfc_l2l1(struct PStack *st, int pr, void *arg)
516 struct sk_buff *skb = arg;
520 case (PH_DATA | REQUEST):
523 if (st->l1.bcs->tx_skb) {
524 skb_queue_tail(&st->l1.bcs->squeue, skb);
525 restore_flags(flags);
527 st->l1.bcs->tx_skb = skb;
528 /* test_and_set_bit(BC_FLG_BUSY, &st->l1.bcs->Flag);
529 */ st->l1.bcs->cs->BC_Send_Data(st->l1.bcs);
530 restore_flags(flags);
533 case (PH_PULL | INDICATION):
534 if (st->l1.bcs->tx_skb) {
535 printk(KERN_WARNING "hfc_l2l1: this shouldn't happen\n");
540 /* test_and_set_bit(BC_FLG_BUSY, &st->l1.bcs->Flag);
541 */ st->l1.bcs->tx_skb = skb;
542 st->l1.bcs->cs->BC_Send_Data(st->l1.bcs);
543 restore_flags(flags);
545 case (PH_PULL | REQUEST):
546 if (!st->l1.bcs->tx_skb) {
547 test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
548 st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
550 test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
552 case (PH_ACTIVATE | REQUEST):
553 test_and_set_bit(BC_FLG_ACTIV, &st->l1.bcs->Flag);
554 mode_2bs0(st->l1.bcs, st->l1.mode, st->l1.bc);
555 l1_msg_b(st, pr, arg);
557 case (PH_DEACTIVATE | REQUEST):
558 l1_msg_b(st, pr, arg);
560 case (PH_DEACTIVATE | CONFIRM):
561 test_and_clear_bit(BC_FLG_ACTIV, &st->l1.bcs->Flag);
562 test_and_clear_bit(BC_FLG_BUSY, &st->l1.bcs->Flag);
563 mode_2bs0(st->l1.bcs, 0, st->l1.bc);
564 st->l1.l1l2(st, PH_DEACTIVATE | CONFIRM, NULL);
570 close_2bs0(struct BCState *bcs)
572 mode_2bs0(bcs, 0, bcs->channel);
573 if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) {
574 skb_queue_purge(&bcs->rqueue);
575 skb_queue_purge(&bcs->squeue);
577 dev_kfree_skb_any(bcs->tx_skb);
579 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
585 open_hfcstate(struct IsdnCardState *cs, struct BCState *bcs)
587 if (!test_and_set_bit(BC_FLG_INIT, &bcs->Flag)) {
588 skb_queue_head_init(&bcs->rqueue);
589 skb_queue_head_init(&bcs->squeue);
592 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
599 setstack_2b(struct PStack *st, struct BCState *bcs)
601 bcs->channel = st->l1.bc;
602 if (open_hfcstate(st->l1.hardware, bcs))
605 st->l2.l2l1 = hfc_l2l1;
606 setstack_manager(st);
613 hfcd_bh(struct IsdnCardState *cs)
615 /* struct PStack *stptr;
619 if (test_and_clear_bit(D_L1STATECHANGE, &cs->event)) {
620 switch (cs->dc.hfcd.ph_state) {
622 l1_msg(cs, HW_RESET | INDICATION, NULL);
625 l1_msg(cs, HW_DEACTIVATE | INDICATION, NULL);
628 l1_msg(cs, HW_RSYNC | INDICATION, NULL);
631 l1_msg(cs, HW_INFO2 | INDICATION, NULL);
634 l1_msg(cs, HW_INFO4_P8 | INDICATION, NULL);
640 if (test_and_clear_bit(D_RCVBUFREADY, &cs->event))
641 DChannel_proc_rcv(cs);
642 if (test_and_clear_bit(D_XMTBUFREADY, &cs->event))
643 DChannel_proc_xmt(cs);
647 sched_event_D(struct IsdnCardState *cs, int event)
649 test_and_set_bit(event, &cs->event);
650 queue_task(&cs->tqueue, &tq_immediate);
651 mark_bh(IMMEDIATE_BH);
655 int receive_dmsg(struct IsdnCardState *cs)
661 u_char stat, cip, f1, f2;
668 if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
669 debugl1(cs, "rec_dmsg blocked");
670 restore_flags(flags);
673 SelFiFo(cs, 4 | HFCD_REC);
674 cip = HFCD_FIFO | HFCD_F1 | HFCD_REC;
676 f1 = cs->readisac(cs, cip) & 0xf;
677 cip = HFCD_FIFO | HFCD_F2 | HFCD_REC;
679 f2 = cs->readisac(cs, cip) & 0xf;
680 while ((f1 != f2) && count--) {
681 z1 = ReadZReg(cs, HFCD_FIFO | HFCD_Z1 | HFCD_REC);
682 z2 = ReadZReg(cs, HFCD_FIFO | HFCD_Z2 | HFCD_REC);
685 rcnt += cs->hw.hfcD.dfifosize;
687 if (cs->debug & L1_DEB_ISAC)
688 debugl1(cs, "hfcd recd f1(%d) f2(%d) z1(%x) z2(%x) cnt(%d)",
689 f1, f2, z1, z2, rcnt);
692 cip = HFCD_FIFO | HFCD_FIFO_OUT | HFCD_REC;
693 if (rcnt > MAX_DFRAME_LEN + 3) {
694 if (cs->debug & L1_DEB_WARN)
695 debugl1(cs, "empty_fifo d: incoming packet too large");
698 if (!(WaitNoBusy(cs)))
700 ReadReg(cs, HFCD_DATA_NODEB, cip);
704 } else if (rcnt < 4) {
705 if (cs->debug & L1_DEB_WARN)
706 debugl1(cs, "empty_fifo d: incoming packet too small");
708 while ((idx++ < rcnt) && WaitNoBusy(cs))
709 ReadReg(cs, HFCD_DATA_NODEB, cip);
710 } else if ((skb = dev_alloc_skb(rcnt - 3))) {
711 ptr = skb_put(skb, rcnt - 3);
712 while (idx < (rcnt - 3)) {
714 if (!(WaitNoBusy(cs)))
716 *ptr = ReadReg(cs, HFCD_DATA_NODEB, cip);
721 if (idx != (rcnt - 3)) {
723 debugl1(cs, "RFIFO D BUSY error");
724 printk(KERN_WARNING "HFC DFIFO channel BUSY Error\n");
725 dev_kfree_skb_irq(skb);
727 #ifdef ERROR_STATISTIC
733 chksum = (ReadReg(cs, HFCD_DATA, cip) << 8);
735 chksum += ReadReg(cs, HFCD_DATA, cip);
737 stat = ReadReg(cs, HFCD_DATA, cip);
739 if (cs->debug & L1_DEB_ISAC)
740 debugl1(cs, "empty_dfifo chksum %x stat %x",
743 debugl1(cs, "FIFO CRC error");
744 dev_kfree_skb_irq(skb);
746 #ifdef ERROR_STATISTIC
750 skb_queue_tail(&cs->rq, skb);
751 sched_event_D(cs, D_RCVBUFREADY);
755 printk(KERN_WARNING "HFC: D receive out of memory\n");
758 cip = HFCD_FIFO | HFCD_F2_INC | HFCD_REC;
761 stat = ReadReg(cs, HFCD_DATA, cip);
764 cip = HFCD_FIFO | HFCD_F2 | HFCD_REC;
767 f2 = cs->readisac(cs, cip) & 0xf;
769 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
770 restore_flags(flags);
775 hfc_fill_dfifo(struct IsdnCardState *cs)
784 if (cs->tx_skb->len <= 0)
789 SelFiFo(cs, 4 | HFCD_SEND);
790 cip = HFCD_FIFO | HFCD_F1 | HFCD_SEND;
792 cs->hw.hfcD.f1 = ReadReg(cs, HFCD_DATA, cip) & 0xf;
794 cip = HFCD_FIFO | HFCD_F2 | HFCD_SEND;
795 cs->hw.hfcD.f2 = ReadReg(cs, HFCD_DATA, cip) & 0xf;
796 cs->hw.hfcD.send[cs->hw.hfcD.f1] = ReadZReg(cs, HFCD_FIFO | HFCD_Z1 | HFCD_SEND);
798 if (cs->debug & L1_DEB_ISAC)
799 debugl1(cs, "hfc_fill_Dfifo f1(%d) f2(%d) z1(%x)",
800 cs->hw.hfcD.f1, cs->hw.hfcD.f2,
801 cs->hw.hfcD.send[cs->hw.hfcD.f1]);
802 fcnt = cs->hw.hfcD.f1 - cs->hw.hfcD.f2;
806 if (cs->debug & L1_DEB_HSCX)
807 debugl1(cs, "hfc_fill_Dfifo more as 14 frames");
808 restore_flags(flags);
811 count = GetFreeFifoBytes_D(cs);
812 if (cs->debug & L1_DEB_ISAC)
813 debugl1(cs, "hfc_fill_Dfifo count(%ld/%d)",
814 cs->tx_skb->len, count);
815 if (count < cs->tx_skb->len) {
816 if (cs->debug & L1_DEB_ISAC)
817 debugl1(cs, "hfc_fill_Dfifo no fifo mem");
818 restore_flags(flags);
821 cip = HFCD_FIFO | HFCD_FIFO_IN | HFCD_SEND;
826 WriteReg(cs, HFCD_DATA_NODEB, cip, cs->tx_skb->data[idx++]);
827 while (idx < cs->tx_skb->len) {
829 if (!(WaitNoBusy(cs)))
831 WriteReg(cs, HFCD_DATA_NODEB, cip, cs->tx_skb->data[idx]);
835 if (idx != cs->tx_skb->len) {
837 debugl1(cs, "DFIFO Send BUSY error");
838 printk(KERN_WARNING "HFC S DFIFO channel BUSY Error\n");
843 ReadReg(cs, HFCD_DATA, HFCD_FIFO | HFCD_F1_INC | HFCD_SEND);
844 dev_kfree_skb_any(cs->tx_skb);
848 restore_flags(flags);
853 struct BCState *Sel_BCS(struct IsdnCardState *cs, int channel)
855 if (cs->bcs[0].mode && (cs->bcs[0].channel == channel))
857 else if (cs->bcs[1].mode && (cs->bcs[1].channel == channel))
864 hfc2bds0_interrupt(struct IsdnCardState *cs, u_char val)
871 if (cs->debug & L1_DEB_ISAC)
872 debugl1(cs, "HFCD irq %x %s", val,
873 test_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags) ?
874 "locked" : "unlocked");
875 val &= cs->hw.hfcD.int_m1;
876 if (val & 0x40) { /* TE state machine irq */
877 exval = cs->readisac(cs, HFCD_STATES) & 0xf;
878 if (cs->debug & L1_DEB_ISAC)
879 debugl1(cs, "ph_state chg %d->%d", cs->dc.hfcd.ph_state,
881 cs->dc.hfcd.ph_state = exval;
882 sched_event_D(cs, D_L1STATECHANGE);
888 if (test_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
889 cs->hw.hfcD.int_s1 |= val;
890 restore_flags(flags);
893 if (cs->hw.hfcD.int_s1 & 0x18) {
895 val = cs->hw.hfcD.int_s1;
896 cs->hw.hfcD.int_s1 = exval;
899 if (!(bcs=Sel_BCS(cs, 0))) {
901 debugl1(cs, "hfcd spurious 0x08 IRQ");
906 if (!(bcs=Sel_BCS(cs, 1))) {
908 debugl1(cs, "hfcd spurious 0x10 IRQ");
913 if (!(bcs=Sel_BCS(cs, 0))) {
915 debugl1(cs, "hfcd spurious 0x01 IRQ");
918 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
920 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
922 debugl1(cs,"fill_data %d blocked", bcs->channel);
924 if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) {
925 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
927 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
929 debugl1(cs,"fill_data %d blocked", bcs->channel);
931 hfc_sched_event(bcs, B_XMTBUFREADY);
937 if (!(bcs=Sel_BCS(cs, 1))) {
939 debugl1(cs, "hfcd spurious 0x02 IRQ");
942 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
944 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
946 debugl1(cs,"fill_data %d blocked", bcs->channel);
948 if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) {
949 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
951 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
953 debugl1(cs,"fill_data %d blocked", bcs->channel);
955 hfc_sched_event(bcs, B_XMTBUFREADY);
960 if (val & 0x20) { /* receive dframe */
963 if (val & 0x04) { /* dframe transmitted */
964 if (test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags))
965 del_timer(&cs->dbusytimer);
966 if (test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags))
967 sched_event_D(cs, D_CLEARBUSY);
969 if (cs->tx_skb->len) {
970 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
972 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
974 debugl1(cs, "hfc_fill_dfifo irq blocked");
978 dev_kfree_skb_irq(cs->tx_skb);
983 if ((cs->tx_skb = skb_dequeue(&cs->sq))) {
985 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
987 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
989 debugl1(cs, "hfc_fill_dfifo irq blocked");
992 sched_event_D(cs, D_XMTBUFREADY);
995 if (cs->hw.hfcD.int_s1 && count--) {
996 val = cs->hw.hfcD.int_s1;
997 cs->hw.hfcD.int_s1 = 0;
998 if (cs->debug & L1_DEB_ISAC)
999 debugl1(cs, "HFCD irq %x loop %d", val, 15-count);
1002 restore_flags(flags);
1007 HFCD_l1hw(struct PStack *st, int pr, void *arg)
1009 struct IsdnCardState *cs = (struct IsdnCardState *) st->l1.hardware;
1010 struct sk_buff *skb = arg;
1013 case (PH_DATA | REQUEST):
1014 if (cs->debug & DEB_DLOG_HEX)
1015 LogFrame(cs, skb->data, skb->len);
1016 if (cs->debug & DEB_DLOG_VERBOSE)
1017 dlogframe(cs, skb, 0);
1019 skb_queue_tail(&cs->sq, skb);
1020 #ifdef L2FRAME_DEBUG /* psa */
1021 if (cs->debug & L1_DEB_LAPD)
1022 Logl2Frame(cs, skb, "PH_DATA Queued", 0);
1027 #ifdef L2FRAME_DEBUG /* psa */
1028 if (cs->debug & L1_DEB_LAPD)
1029 Logl2Frame(cs, skb, "PH_DATA", 0);
1031 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
1033 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
1035 debugl1(cs, "hfc_fill_dfifo blocked");
1039 case (PH_PULL | INDICATION):
1041 if (cs->debug & L1_DEB_WARN)
1042 debugl1(cs, " l2l1 tx_skb exist this shouldn't happen");
1043 skb_queue_tail(&cs->sq, skb);
1046 if (cs->debug & DEB_DLOG_HEX)
1047 LogFrame(cs, skb->data, skb->len);
1048 if (cs->debug & DEB_DLOG_VERBOSE)
1049 dlogframe(cs, skb, 0);
1052 #ifdef L2FRAME_DEBUG /* psa */
1053 if (cs->debug & L1_DEB_LAPD)
1054 Logl2Frame(cs, skb, "PH_DATA_PULLED", 0);
1056 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
1058 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
1060 debugl1(cs, "hfc_fill_dfifo blocked");
1062 case (PH_PULL | REQUEST):
1063 #ifdef L2FRAME_DEBUG /* psa */
1064 if (cs->debug & L1_DEB_LAPD)
1065 debugl1(cs, "-> PH_REQUEST_PULL");
1068 test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
1069 st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
1071 test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
1073 case (HW_RESET | REQUEST):
1074 cs->writeisac(cs, HFCD_STATES, HFCD_LOAD_STATE | 3); /* HFC ST 3 */
1076 cs->writeisac(cs, HFCD_STATES, 3); /* HFC ST 2 */
1077 cs->hw.hfcD.mst_m |= HFCD_MASTER;
1078 cs->writeisac(cs, HFCD_MST_MODE, cs->hw.hfcD.mst_m);
1079 cs->writeisac(cs, HFCD_STATES, HFCD_ACTIVATE | HFCD_DO_ACTION);
1080 l1_msg(cs, HW_POWERUP | CONFIRM, NULL);
1082 case (HW_ENABLE | REQUEST):
1083 cs->writeisac(cs, HFCD_STATES, HFCD_ACTIVATE | HFCD_DO_ACTION);
1085 case (HW_DEACTIVATE | REQUEST):
1086 cs->hw.hfcD.mst_m &= ~HFCD_MASTER;
1087 cs->writeisac(cs, HFCD_MST_MODE, cs->hw.hfcD.mst_m);
1089 case (HW_INFO3 | REQUEST):
1090 cs->hw.hfcD.mst_m |= HFCD_MASTER;
1091 cs->writeisac(cs, HFCD_MST_MODE, cs->hw.hfcD.mst_m);
1094 if (cs->debug & L1_DEB_WARN)
1095 debugl1(cs, "hfcd_l1hw unknown pr %4x", pr);
1101 setstack_hfcd(struct PStack *st, struct IsdnCardState *cs)
1103 st->l1.l1hw = HFCD_l1hw;
1107 hfc_dbusy_timer(struct IsdnCardState *cs)
1112 *init_send_hfcd(int cnt)
1116 if (!(send = kmalloc(cnt * sizeof(unsigned int), GFP_ATOMIC))) {
1118 "HiSax: No memory for hfcd.send\n");
1121 for (i = 0; i < cnt; i++)
1127 init2bds0(struct IsdnCardState *cs)
1129 cs->setstack_d = setstack_hfcd;
1130 cs->dbusytimer.function = (void *) hfc_dbusy_timer;
1131 cs->dbusytimer.data = (long) cs;
1132 init_timer(&cs->dbusytimer);
1133 cs->tqueue.routine = (void *) (void *) hfcd_bh;
1134 if (!cs->hw.hfcD.send)
1135 cs->hw.hfcD.send = init_send_hfcd(16);
1136 if (!cs->bcs[0].hw.hfc.send)
1137 cs->bcs[0].hw.hfc.send = init_send_hfcd(32);
1138 if (!cs->bcs[1].hw.hfc.send)
1139 cs->bcs[1].hw.hfc.send = init_send_hfcd(32);
1140 cs->BC_Send_Data = &hfc_send_data;
1141 cs->bcs[0].BC_SetStack = setstack_2b;
1142 cs->bcs[1].BC_SetStack = setstack_2b;
1143 cs->bcs[0].BC_Close = close_2bs0;
1144 cs->bcs[1].BC_Close = close_2bs0;
1145 mode_2bs0(cs->bcs, 0, 0);
1146 mode_2bs0(cs->bcs + 1, 0, 1);
1150 release2bds0(struct IsdnCardState *cs)
1152 if (cs->bcs[0].hw.hfc.send) {
1153 kfree(cs->bcs[0].hw.hfc.send);
1154 cs->bcs[0].hw.hfc.send = NULL;
1156 if (cs->bcs[1].hw.hfc.send) {
1157 kfree(cs->bcs[1].hw.hfc.send);
1158 cs->bcs[1].hw.hfc.send = NULL;
1160 if (cs->hw.hfcD.send) {
1161 kfree(cs->hw.hfcD.send);
1162 cs->hw.hfcD.send = NULL;