1 /* $Id: hfc_2bds0.c,v 1.18.2.6 2004/02/11 13:21:33 keil 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 #include <linux/init.h>
15 #include "hfc_2bds0.h"
17 #include <linux/interrupt.h>
23 #define byteout(addr,val) outb(val,addr)
24 #define bytein(addr) inb(addr)
27 dummyf(struct IsdnCardState *cs, u_char * data, int size)
29 printk(KERN_WARNING "HiSax: hfcd dummy fifo called\n");
33 ReadReg(struct IsdnCardState *cs, int data, u_char reg)
38 if (cs->hw.hfcD.cip != reg) {
39 cs->hw.hfcD.cip = reg;
40 byteout(cs->hw.hfcD.addr | 1, reg);
42 ret = bytein(cs->hw.hfcD.addr);
44 if (cs->debug & L1_DEB_HSCX_FIFO && (data != 2))
45 debugl1(cs, "t3c RD %02x %02x", reg, ret);
48 ret = bytein(cs->hw.hfcD.addr | 1);
53 WriteReg(struct IsdnCardState *cs, int data, u_char reg, u_char value)
55 if (cs->hw.hfcD.cip != reg) {
56 cs->hw.hfcD.cip = reg;
57 byteout(cs->hw.hfcD.addr | 1, reg);
60 byteout(cs->hw.hfcD.addr, value);
62 if (cs->debug & L1_DEB_HSCX_FIFO && (data != HFCD_DATA_NODEB))
63 debugl1(cs, "t3c W%c %02x %02x", data ? 'D' : 'C', reg, value);
67 /* Interface functions */
70 readreghfcd(struct IsdnCardState *cs, u_char offset)
72 return(ReadReg(cs, HFCD_DATA, offset));
76 writereghfcd(struct IsdnCardState *cs, u_char offset, u_char value)
78 WriteReg(cs, HFCD_DATA, offset, value);
82 WaitForBusy(struct IsdnCardState *cs)
86 while (!(ReadReg(cs, HFCD_DATA, HFCD_STAT) & HFCD_BUSY) && to) {
91 printk(KERN_WARNING "HiSax: WaitForBusy timeout\n");
96 WaitNoBusy(struct IsdnCardState *cs)
100 while ((ReadReg(cs, HFCD_STATUS, HFCD_STATUS) & HFCD_BUSY) && to) {
105 printk(KERN_WARNING "HiSax: WaitNoBusy timeout\n");
110 SelFiFo(struct IsdnCardState *cs, u_char FiFo)
114 if (cs->hw.hfcD.fifo == FiFo)
117 case 0: cip = HFCB_FIFO | HFCB_Z1 | HFCB_SEND | HFCB_B1;
119 case 1: cip = HFCB_FIFO | HFCB_Z1 | HFCB_REC | HFCB_B1;
121 case 2: cip = HFCB_FIFO | HFCB_Z1 | HFCB_SEND | HFCB_B2;
123 case 3: cip = HFCB_FIFO | HFCB_Z1 | HFCB_REC | HFCB_B2;
125 case 4: cip = HFCD_FIFO | HFCD_Z1 | HFCD_SEND;
127 case 5: cip = HFCD_FIFO | HFCD_Z1 | HFCD_REC;
130 debugl1(cs, "SelFiFo Error");
133 cs->hw.hfcD.fifo = FiFo;
135 cs->BC_Write_Reg(cs, HFCD_DATA, cip, 0);
141 GetFreeFifoBytes_B(struct BCState *bcs)
145 if (bcs->hw.hfc.f1 == bcs->hw.hfc.f2)
146 return (bcs->cs->hw.hfcD.bfifosize);
147 s = bcs->hw.hfc.send[bcs->hw.hfc.f1] - bcs->hw.hfc.send[bcs->hw.hfc.f2];
149 s += bcs->cs->hw.hfcD.bfifosize;
150 s = bcs->cs->hw.hfcD.bfifosize - s;
155 GetFreeFifoBytes_D(struct IsdnCardState *cs)
159 if (cs->hw.hfcD.f1 == cs->hw.hfcD.f2)
160 return (cs->hw.hfcD.dfifosize);
161 s = cs->hw.hfcD.send[cs->hw.hfcD.f1] - cs->hw.hfcD.send[cs->hw.hfcD.f2];
163 s += cs->hw.hfcD.dfifosize;
164 s = cs->hw.hfcD.dfifosize - s;
169 ReadZReg(struct IsdnCardState *cs, u_char reg)
174 val = 256 * ReadReg(cs, HFCD_DATA, reg | HFCB_Z_HIGH);
176 val += ReadReg(cs, HFCD_DATA, reg | HFCB_Z_LOW);
180 static struct sk_buff
181 *hfc_empty_fifo(struct BCState *bcs, int count)
185 struct IsdnCardState *cs = bcs->cs;
190 if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
191 debugl1(cs, "hfc_empty_fifo");
193 if (count > HSCX_BUFMAX + 3) {
194 if (cs->debug & L1_DEB_WARN)
195 debugl1(cs, "hfc_empty_fifo: incoming packet too large");
196 cip = HFCB_FIFO | HFCB_FIFO_OUT | HFCB_REC | HFCB_CHANNEL(bcs->channel);
197 while (idx++ < count) {
199 ReadReg(cs, HFCD_DATA_NODEB, cip);
202 } else if (count < 4) {
203 if (cs->debug & L1_DEB_WARN)
204 debugl1(cs, "hfc_empty_fifo: incoming packet too small");
205 cip = HFCB_FIFO | HFCB_FIFO_OUT | HFCB_REC | HFCB_CHANNEL(bcs->channel);
206 #ifdef ERROR_STATISTIC
209 while ((idx++ < count) && WaitNoBusy(cs))
210 ReadReg(cs, HFCD_DATA_NODEB, cip);
212 } else if (!(skb = dev_alloc_skb(count - 3)))
213 printk(KERN_WARNING "HFC: receive out of memory\n");
215 ptr = skb_put(skb, count - 3);
217 cip = HFCB_FIFO | HFCB_FIFO_OUT | HFCB_REC | HFCB_CHANNEL(bcs->channel);
218 while (idx < (count - 3)) {
221 *ptr = ReadReg(cs, HFCD_DATA_NODEB, cip);
225 if (idx != count - 3) {
226 debugl1(cs, "RFIFO BUSY error");
227 printk(KERN_WARNING "HFC FIFO channel %d BUSY Error\n", bcs->channel);
228 dev_kfree_skb_irq(skb);
232 chksum = (ReadReg(cs, HFCD_DATA, cip) << 8);
234 chksum += ReadReg(cs, HFCD_DATA, cip);
236 stat = ReadReg(cs, HFCD_DATA, cip);
237 if (cs->debug & L1_DEB_HSCX)
238 debugl1(cs, "hfc_empty_fifo %d chksum %x stat %x",
239 bcs->channel, chksum, stat);
241 debugl1(cs, "FIFO CRC error");
242 dev_kfree_skb_irq(skb);
244 #ifdef ERROR_STATISTIC
252 stat = ReadReg(cs, HFCD_DATA, HFCB_FIFO | HFCB_F2_INC |
253 HFCB_REC | HFCB_CHANNEL(bcs->channel));
259 hfc_fill_fifo(struct BCState *bcs)
261 struct IsdnCardState *cs = bcs->cs;
268 if (bcs->tx_skb->len <= 0)
270 SelFiFo(cs, HFCB_SEND | HFCB_CHANNEL(bcs->channel));
271 cip = HFCB_FIFO | HFCB_F1 | HFCB_SEND | HFCB_CHANNEL(bcs->channel);
273 bcs->hw.hfc.f1 = ReadReg(cs, HFCD_DATA, cip);
275 cip = HFCB_FIFO | HFCB_F2 | HFCB_SEND | HFCB_CHANNEL(bcs->channel);
277 bcs->hw.hfc.f2 = ReadReg(cs, HFCD_DATA, cip);
278 bcs->hw.hfc.send[bcs->hw.hfc.f1] = ReadZReg(cs, HFCB_FIFO | HFCB_Z1 | HFCB_SEND | HFCB_CHANNEL(bcs->channel));
279 if (cs->debug & L1_DEB_HSCX)
280 debugl1(cs, "hfc_fill_fifo %d f1(%d) f2(%d) z1(%x)",
281 bcs->channel, bcs->hw.hfc.f1, bcs->hw.hfc.f2,
282 bcs->hw.hfc.send[bcs->hw.hfc.f1]);
283 fcnt = bcs->hw.hfc.f1 - bcs->hw.hfc.f2;
287 if (cs->debug & L1_DEB_HSCX)
288 debugl1(cs, "hfc_fill_fifo more as 30 frames");
291 count = GetFreeFifoBytes_B(bcs);
292 if (cs->debug & L1_DEB_HSCX)
293 debugl1(cs, "hfc_fill_fifo %d count(%ld/%d),%lx",
294 bcs->channel, bcs->tx_skb->len,
295 count, current->state);
296 if (count < bcs->tx_skb->len) {
297 if (cs->debug & L1_DEB_HSCX)
298 debugl1(cs, "hfc_fill_fifo no fifo mem");
301 cip = HFCB_FIFO | HFCB_FIFO_IN | HFCB_SEND | HFCB_CHANNEL(bcs->channel);
305 WriteReg(cs, HFCD_DATA_NODEB, cip, bcs->tx_skb->data[idx++]);
306 while (idx < bcs->tx_skb->len) {
309 WriteReg(cs, HFCD_DATA_NODEB, cip, bcs->tx_skb->data[idx]);
312 if (idx != bcs->tx_skb->len) {
313 debugl1(cs, "FIFO Send BUSY error");
314 printk(KERN_WARNING "HFC S FIFO channel %d BUSY Error\n", bcs->channel);
316 bcs->tx_cnt -= bcs->tx_skb->len;
317 if (test_bit(FLG_LLI_L1WAKEUP,&bcs->st->lli.flag) &&
318 (PACKET_NOACK != bcs->tx_skb->pkt_type)) {
320 spin_lock_irqsave(&bcs->aclock, flags);
321 bcs->ackcnt += bcs->tx_skb->len;
322 spin_unlock_irqrestore(&bcs->aclock, flags);
323 schedule_event(bcs, B_ACKPENDING);
325 dev_kfree_skb_any(bcs->tx_skb);
330 ReadReg(cs, HFCD_DATA, HFCB_FIFO | HFCB_F1_INC | HFCB_SEND | HFCB_CHANNEL(bcs->channel));
332 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
337 hfc_send_data(struct BCState *bcs)
339 struct IsdnCardState *cs = bcs->cs;
341 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
343 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
345 debugl1(cs,"send_data %d blocked", bcs->channel);
349 main_rec_2bds0(struct BCState *bcs)
351 struct IsdnCardState *cs = bcs->cs;
354 int receive, count = 5;
359 if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
360 debugl1(cs,"rec_data %d blocked", bcs->channel);
363 SelFiFo(cs, HFCB_REC | HFCB_CHANNEL(bcs->channel));
364 cip = HFCB_FIFO | HFCB_F1 | HFCB_REC | HFCB_CHANNEL(bcs->channel);
366 f1 = ReadReg(cs, HFCD_DATA, cip);
367 cip = HFCB_FIFO | HFCB_F2 | HFCB_REC | HFCB_CHANNEL(bcs->channel);
369 f2 = ReadReg(cs, HFCD_DATA, cip);
371 if (cs->debug & L1_DEB_HSCX)
372 debugl1(cs, "hfc rec %d f1(%d) f2(%d)",
373 bcs->channel, f1, f2);
374 z1 = ReadZReg(cs, HFCB_FIFO | HFCB_Z1 | HFCB_REC | HFCB_CHANNEL(bcs->channel));
375 z2 = ReadZReg(cs, HFCB_FIFO | HFCB_Z2 | HFCB_REC | HFCB_CHANNEL(bcs->channel));
378 rcnt += cs->hw.hfcD.bfifosize;
380 if (cs->debug & L1_DEB_HSCX)
381 debugl1(cs, "hfc rec %d z1(%x) z2(%x) cnt(%d)",
382 bcs->channel, z1, z2, rcnt);
383 if ((skb = hfc_empty_fifo(bcs, rcnt))) {
384 skb_queue_tail(&bcs->rqueue, skb);
385 schedule_event(bcs, B_RCVBUFREADY);
396 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
397 if (count && receive)
403 mode_2bs0(struct BCState *bcs, int mode, int bc)
405 struct IsdnCardState *cs = bcs->cs;
407 if (cs->debug & L1_DEB_HSCX)
408 debugl1(cs, "HFCD bchannel mode %d bchan %d/%d",
409 mode, bc, bcs->channel);
415 cs->hw.hfcD.conn |= 0x18;
416 cs->hw.hfcD.sctrl &= ~SCTRL_B2_ENA;
418 cs->hw.hfcD.conn |= 0x3;
419 cs->hw.hfcD.sctrl &= ~SCTRL_B1_ENA;
422 case (L1_MODE_TRANS):
424 cs->hw.hfcD.ctmt |= 2;
425 cs->hw.hfcD.conn &= ~0x18;
426 cs->hw.hfcD.sctrl |= SCTRL_B2_ENA;
428 cs->hw.hfcD.ctmt |= 1;
429 cs->hw.hfcD.conn &= ~0x3;
430 cs->hw.hfcD.sctrl |= SCTRL_B1_ENA;
435 cs->hw.hfcD.ctmt &= ~2;
436 cs->hw.hfcD.conn &= ~0x18;
437 cs->hw.hfcD.sctrl |= SCTRL_B2_ENA;
439 cs->hw.hfcD.ctmt &= ~1;
440 cs->hw.hfcD.conn &= ~0x3;
441 cs->hw.hfcD.sctrl |= SCTRL_B1_ENA;
445 WriteReg(cs, HFCD_DATA, HFCD_SCTRL, cs->hw.hfcD.sctrl);
446 WriteReg(cs, HFCD_DATA, HFCD_CTMT, cs->hw.hfcD.ctmt);
447 WriteReg(cs, HFCD_DATA, HFCD_CONN, cs->hw.hfcD.conn);
451 hfc_l2l1(struct PStack *st, int pr, void *arg)
453 struct BCState *bcs = st->l1.bcs;
454 struct sk_buff *skb = arg;
458 case (PH_DATA | REQUEST):
459 spin_lock_irqsave(&bcs->cs->lock, flags);
461 skb_queue_tail(&bcs->squeue, skb);
464 // test_and_set_bit(BC_FLG_BUSY, &bcs->Flag);
465 bcs->cs->BC_Send_Data(bcs);
467 spin_unlock_irqrestore(&bcs->cs->lock, flags);
469 case (PH_PULL | INDICATION):
470 spin_lock_irqsave(&bcs->cs->lock, flags);
472 printk(KERN_WARNING "hfc_l2l1: this shouldn't happen\n");
474 // test_and_set_bit(BC_FLG_BUSY, &bcs->Flag);
476 bcs->cs->BC_Send_Data(bcs);
478 spin_unlock_irqrestore(&bcs->cs->lock, flags);
480 case (PH_PULL | REQUEST):
482 test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
483 st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
485 test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
487 case (PH_ACTIVATE | REQUEST):
488 spin_lock_irqsave(&bcs->cs->lock, flags);
489 test_and_set_bit(BC_FLG_ACTIV, &bcs->Flag);
490 mode_2bs0(bcs, st->l1.mode, st->l1.bc);
491 spin_unlock_irqrestore(&bcs->cs->lock, flags);
492 l1_msg_b(st, pr, arg);
494 case (PH_DEACTIVATE | REQUEST):
495 l1_msg_b(st, pr, arg);
497 case (PH_DEACTIVATE | CONFIRM):
498 spin_lock_irqsave(&bcs->cs->lock, flags);
499 test_and_clear_bit(BC_FLG_ACTIV, &bcs->Flag);
500 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
501 mode_2bs0(bcs, 0, st->l1.bc);
502 spin_unlock_irqrestore(&bcs->cs->lock, flags);
503 st->l1.l1l2(st, PH_DEACTIVATE | CONFIRM, NULL);
509 close_2bs0(struct BCState *bcs)
511 mode_2bs0(bcs, 0, bcs->channel);
512 if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) {
513 skb_queue_purge(&bcs->rqueue);
514 skb_queue_purge(&bcs->squeue);
516 dev_kfree_skb_any(bcs->tx_skb);
518 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
524 open_hfcstate(struct IsdnCardState *cs, struct BCState *bcs)
526 if (!test_and_set_bit(BC_FLG_INIT, &bcs->Flag)) {
527 skb_queue_head_init(&bcs->rqueue);
528 skb_queue_head_init(&bcs->squeue);
531 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
538 setstack_2b(struct PStack *st, struct BCState *bcs)
540 bcs->channel = st->l1.bc;
541 if (open_hfcstate(st->l1.hardware, bcs))
544 st->l2.l2l1 = hfc_l2l1;
545 setstack_manager(st);
552 hfcd_bh(struct work_struct *work)
554 struct IsdnCardState *cs =
555 container_of(work, struct IsdnCardState, tqueue);
557 if (test_and_clear_bit(D_L1STATECHANGE, &cs->event)) {
558 switch (cs->dc.hfcd.ph_state) {
560 l1_msg(cs, HW_RESET | INDICATION, NULL);
563 l1_msg(cs, HW_DEACTIVATE | INDICATION, NULL);
566 l1_msg(cs, HW_RSYNC | INDICATION, NULL);
569 l1_msg(cs, HW_INFO2 | INDICATION, NULL);
572 l1_msg(cs, HW_INFO4_P8 | INDICATION, NULL);
578 if (test_and_clear_bit(D_RCVBUFREADY, &cs->event))
579 DChannel_proc_rcv(cs);
580 if (test_and_clear_bit(D_XMTBUFREADY, &cs->event))
581 DChannel_proc_xmt(cs);
585 int receive_dmsg(struct IsdnCardState *cs)
590 u_char stat, cip, f1, f2;
595 if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
596 debugl1(cs, "rec_dmsg blocked");
599 SelFiFo(cs, 4 | HFCD_REC);
600 cip = HFCD_FIFO | HFCD_F1 | HFCD_REC;
602 f1 = cs->readisac(cs, cip) & 0xf;
603 cip = HFCD_FIFO | HFCD_F2 | HFCD_REC;
605 f2 = cs->readisac(cs, cip) & 0xf;
606 while ((f1 != f2) && count--) {
607 z1 = ReadZReg(cs, HFCD_FIFO | HFCD_Z1 | HFCD_REC);
608 z2 = ReadZReg(cs, HFCD_FIFO | HFCD_Z2 | HFCD_REC);
611 rcnt += cs->hw.hfcD.dfifosize;
613 if (cs->debug & L1_DEB_ISAC)
614 debugl1(cs, "hfcd recd f1(%d) f2(%d) z1(%x) z2(%x) cnt(%d)",
615 f1, f2, z1, z2, rcnt);
617 cip = HFCD_FIFO | HFCD_FIFO_OUT | HFCD_REC;
618 if (rcnt > MAX_DFRAME_LEN + 3) {
619 if (cs->debug & L1_DEB_WARN)
620 debugl1(cs, "empty_fifo d: incoming packet too large");
622 if (!(WaitNoBusy(cs)))
624 ReadReg(cs, HFCD_DATA_NODEB, cip);
627 } else if (rcnt < 4) {
628 if (cs->debug & L1_DEB_WARN)
629 debugl1(cs, "empty_fifo d: incoming packet too small");
630 while ((idx++ < rcnt) && WaitNoBusy(cs))
631 ReadReg(cs, HFCD_DATA_NODEB, cip);
632 } else if ((skb = dev_alloc_skb(rcnt - 3))) {
633 ptr = skb_put(skb, rcnt - 3);
634 while (idx < (rcnt - 3)) {
635 if (!(WaitNoBusy(cs)))
637 *ptr = ReadReg(cs, HFCD_DATA_NODEB, cip);
641 if (idx != (rcnt - 3)) {
642 debugl1(cs, "RFIFO D BUSY error");
643 printk(KERN_WARNING "HFC DFIFO channel BUSY Error\n");
644 dev_kfree_skb_irq(skb);
646 #ifdef ERROR_STATISTIC
651 chksum = (ReadReg(cs, HFCD_DATA, cip) << 8);
653 chksum += ReadReg(cs, HFCD_DATA, cip);
655 stat = ReadReg(cs, HFCD_DATA, cip);
656 if (cs->debug & L1_DEB_ISAC)
657 debugl1(cs, "empty_dfifo chksum %x stat %x",
660 debugl1(cs, "FIFO CRC error");
661 dev_kfree_skb_irq(skb);
663 #ifdef ERROR_STATISTIC
667 skb_queue_tail(&cs->rq, skb);
668 schedule_event(cs, D_RCVBUFREADY);
672 printk(KERN_WARNING "HFC: D receive out of memory\n");
674 cip = HFCD_FIFO | HFCD_F2_INC | HFCD_REC;
676 stat = ReadReg(cs, HFCD_DATA, cip);
678 cip = HFCD_FIFO | HFCD_F2 | HFCD_REC;
680 f2 = cs->readisac(cs, cip) & 0xf;
682 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
687 hfc_fill_dfifo(struct IsdnCardState *cs)
695 if (cs->tx_skb->len <= 0)
698 SelFiFo(cs, 4 | HFCD_SEND);
699 cip = HFCD_FIFO | HFCD_F1 | HFCD_SEND;
701 cs->hw.hfcD.f1 = ReadReg(cs, HFCD_DATA, cip) & 0xf;
703 cip = HFCD_FIFO | HFCD_F2 | HFCD_SEND;
704 cs->hw.hfcD.f2 = ReadReg(cs, HFCD_DATA, cip) & 0xf;
705 cs->hw.hfcD.send[cs->hw.hfcD.f1] = ReadZReg(cs, HFCD_FIFO | HFCD_Z1 | HFCD_SEND);
706 if (cs->debug & L1_DEB_ISAC)
707 debugl1(cs, "hfc_fill_Dfifo f1(%d) f2(%d) z1(%x)",
708 cs->hw.hfcD.f1, cs->hw.hfcD.f2,
709 cs->hw.hfcD.send[cs->hw.hfcD.f1]);
710 fcnt = cs->hw.hfcD.f1 - cs->hw.hfcD.f2;
714 if (cs->debug & L1_DEB_HSCX)
715 debugl1(cs, "hfc_fill_Dfifo more as 14 frames");
718 count = GetFreeFifoBytes_D(cs);
719 if (cs->debug & L1_DEB_ISAC)
720 debugl1(cs, "hfc_fill_Dfifo count(%ld/%d)",
721 cs->tx_skb->len, count);
722 if (count < cs->tx_skb->len) {
723 if (cs->debug & L1_DEB_ISAC)
724 debugl1(cs, "hfc_fill_Dfifo no fifo mem");
727 cip = HFCD_FIFO | HFCD_FIFO_IN | HFCD_SEND;
731 WriteReg(cs, HFCD_DATA_NODEB, cip, cs->tx_skb->data[idx++]);
732 while (idx < cs->tx_skb->len) {
733 if (!(WaitNoBusy(cs)))
735 WriteReg(cs, HFCD_DATA_NODEB, cip, cs->tx_skb->data[idx]);
738 if (idx != cs->tx_skb->len) {
739 debugl1(cs, "DFIFO Send BUSY error");
740 printk(KERN_WARNING "HFC S DFIFO channel BUSY Error\n");
744 ReadReg(cs, HFCD_DATA, HFCD_FIFO | HFCD_F1_INC | HFCD_SEND);
745 dev_kfree_skb_any(cs->tx_skb);
752 struct BCState *Sel_BCS(struct IsdnCardState *cs, int channel)
754 if (cs->bcs[0].mode && (cs->bcs[0].channel == channel))
756 else if (cs->bcs[1].mode && (cs->bcs[1].channel == channel))
763 hfc2bds0_interrupt(struct IsdnCardState *cs, u_char val)
769 if (cs->debug & L1_DEB_ISAC)
770 debugl1(cs, "HFCD irq %x %s", val,
771 test_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags) ?
772 "locked" : "unlocked");
773 val &= cs->hw.hfcD.int_m1;
774 if (val & 0x40) { /* TE state machine irq */
775 exval = cs->readisac(cs, HFCD_STATES) & 0xf;
776 if (cs->debug & L1_DEB_ISAC)
777 debugl1(cs, "ph_state chg %d->%d", cs->dc.hfcd.ph_state,
779 cs->dc.hfcd.ph_state = exval;
780 schedule_event(cs, D_L1STATECHANGE);
784 if (test_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
785 cs->hw.hfcD.int_s1 |= val;
788 if (cs->hw.hfcD.int_s1 & 0x18) {
790 val = cs->hw.hfcD.int_s1;
791 cs->hw.hfcD.int_s1 = exval;
794 if (!(bcs=Sel_BCS(cs, 0))) {
796 debugl1(cs, "hfcd spurious 0x08 IRQ");
801 if (!(bcs=Sel_BCS(cs, 1))) {
803 debugl1(cs, "hfcd spurious 0x10 IRQ");
808 if (!(bcs=Sel_BCS(cs, 0))) {
810 debugl1(cs, "hfcd spurious 0x01 IRQ");
813 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
815 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
817 debugl1(cs,"fill_data %d blocked", bcs->channel);
819 if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) {
820 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
822 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
824 debugl1(cs,"fill_data %d blocked", bcs->channel);
826 schedule_event(bcs, B_XMTBUFREADY);
832 if (!(bcs=Sel_BCS(cs, 1))) {
834 debugl1(cs, "hfcd spurious 0x02 IRQ");
837 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
839 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
841 debugl1(cs,"fill_data %d blocked", bcs->channel);
843 if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) {
844 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
846 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
848 debugl1(cs,"fill_data %d blocked", bcs->channel);
850 schedule_event(bcs, B_XMTBUFREADY);
855 if (val & 0x20) { /* receive dframe */
858 if (val & 0x04) { /* dframe transmitted */
859 if (test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags))
860 del_timer(&cs->dbusytimer);
861 if (test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags))
862 schedule_event(cs, D_CLEARBUSY);
864 if (cs->tx_skb->len) {
865 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
867 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
869 debugl1(cs, "hfc_fill_dfifo irq blocked");
873 dev_kfree_skb_irq(cs->tx_skb);
878 if ((cs->tx_skb = skb_dequeue(&cs->sq))) {
880 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
882 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
884 debugl1(cs, "hfc_fill_dfifo irq blocked");
887 schedule_event(cs, D_XMTBUFREADY);
890 if (cs->hw.hfcD.int_s1 && count--) {
891 val = cs->hw.hfcD.int_s1;
892 cs->hw.hfcD.int_s1 = 0;
893 if (cs->debug & L1_DEB_ISAC)
894 debugl1(cs, "HFCD irq %x loop %d", val, 15-count);
901 HFCD_l1hw(struct PStack *st, int pr, void *arg)
903 struct IsdnCardState *cs = (struct IsdnCardState *) st->l1.hardware;
904 struct sk_buff *skb = arg;
908 case (PH_DATA | REQUEST):
909 if (cs->debug & DEB_DLOG_HEX)
910 LogFrame(cs, skb->data, skb->len);
911 if (cs->debug & DEB_DLOG_VERBOSE)
912 dlogframe(cs, skb, 0);
913 spin_lock_irqsave(&cs->lock, flags);
915 skb_queue_tail(&cs->sq, skb);
916 #ifdef L2FRAME_DEBUG /* psa */
917 if (cs->debug & L1_DEB_LAPD)
918 Logl2Frame(cs, skb, "PH_DATA Queued", 0);
923 #ifdef L2FRAME_DEBUG /* psa */
924 if (cs->debug & L1_DEB_LAPD)
925 Logl2Frame(cs, skb, "PH_DATA", 0);
927 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
929 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
931 debugl1(cs, "hfc_fill_dfifo blocked");
934 spin_unlock_irqrestore(&cs->lock, flags);
936 case (PH_PULL | INDICATION):
937 spin_lock_irqsave(&cs->lock, flags);
939 if (cs->debug & L1_DEB_WARN)
940 debugl1(cs, " l2l1 tx_skb exist this shouldn't happen");
941 skb_queue_tail(&cs->sq, skb);
942 spin_unlock_irqrestore(&cs->lock, flags);
945 if (cs->debug & DEB_DLOG_HEX)
946 LogFrame(cs, skb->data, skb->len);
947 if (cs->debug & DEB_DLOG_VERBOSE)
948 dlogframe(cs, skb, 0);
951 #ifdef L2FRAME_DEBUG /* psa */
952 if (cs->debug & L1_DEB_LAPD)
953 Logl2Frame(cs, skb, "PH_DATA_PULLED", 0);
955 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
957 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
959 debugl1(cs, "hfc_fill_dfifo blocked");
960 spin_unlock_irqrestore(&cs->lock, flags);
962 case (PH_PULL | REQUEST):
963 #ifdef L2FRAME_DEBUG /* psa */
964 if (cs->debug & L1_DEB_LAPD)
965 debugl1(cs, "-> PH_REQUEST_PULL");
968 test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
969 st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
971 test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
973 case (HW_RESET | REQUEST):
974 spin_lock_irqsave(&cs->lock, flags);
975 cs->writeisac(cs, HFCD_STATES, HFCD_LOAD_STATE | 3); /* HFC ST 3 */
977 cs->writeisac(cs, HFCD_STATES, 3); /* HFC ST 2 */
978 cs->hw.hfcD.mst_m |= HFCD_MASTER;
979 cs->writeisac(cs, HFCD_MST_MODE, cs->hw.hfcD.mst_m);
980 cs->writeisac(cs, HFCD_STATES, HFCD_ACTIVATE | HFCD_DO_ACTION);
981 spin_unlock_irqrestore(&cs->lock, flags);
982 l1_msg(cs, HW_POWERUP | CONFIRM, NULL);
984 case (HW_ENABLE | REQUEST):
985 spin_lock_irqsave(&cs->lock, flags);
986 cs->writeisac(cs, HFCD_STATES, HFCD_ACTIVATE | HFCD_DO_ACTION);
987 spin_unlock_irqrestore(&cs->lock, flags);
989 case (HW_DEACTIVATE | REQUEST):
990 spin_lock_irqsave(&cs->lock, flags);
991 cs->hw.hfcD.mst_m &= ~HFCD_MASTER;
992 cs->writeisac(cs, HFCD_MST_MODE, cs->hw.hfcD.mst_m);
993 spin_unlock_irqrestore(&cs->lock, flags);
995 case (HW_INFO3 | REQUEST):
996 spin_lock_irqsave(&cs->lock, flags);
997 cs->hw.hfcD.mst_m |= HFCD_MASTER;
998 cs->writeisac(cs, HFCD_MST_MODE, cs->hw.hfcD.mst_m);
999 spin_unlock_irqrestore(&cs->lock, flags);
1002 if (cs->debug & L1_DEB_WARN)
1003 debugl1(cs, "hfcd_l1hw unknown pr %4x", pr);
1009 setstack_hfcd(struct PStack *st, struct IsdnCardState *cs)
1011 st->l1.l1hw = HFCD_l1hw;
1015 hfc_dbusy_timer(struct IsdnCardState *cs)
1020 *init_send_hfcd(int cnt)
1025 if (!(send = kmalloc(cnt * sizeof(unsigned int), GFP_ATOMIC))) {
1027 "HiSax: No memory for hfcd.send\n");
1030 for (i = 0; i < cnt; i++)
1036 init2bds0(struct IsdnCardState *cs)
1038 cs->setstack_d = setstack_hfcd;
1039 if (!cs->hw.hfcD.send)
1040 cs->hw.hfcD.send = init_send_hfcd(16);
1041 if (!cs->bcs[0].hw.hfc.send)
1042 cs->bcs[0].hw.hfc.send = init_send_hfcd(32);
1043 if (!cs->bcs[1].hw.hfc.send)
1044 cs->bcs[1].hw.hfc.send = init_send_hfcd(32);
1045 cs->BC_Send_Data = &hfc_send_data;
1046 cs->bcs[0].BC_SetStack = setstack_2b;
1047 cs->bcs[1].BC_SetStack = setstack_2b;
1048 cs->bcs[0].BC_Close = close_2bs0;
1049 cs->bcs[1].BC_Close = close_2bs0;
1050 mode_2bs0(cs->bcs, 0, 0);
1051 mode_2bs0(cs->bcs + 1, 0, 1);
1055 release2bds0(struct IsdnCardState *cs)
1057 kfree(cs->bcs[0].hw.hfc.send);
1058 cs->bcs[0].hw.hfc.send = NULL;
1059 kfree(cs->bcs[1].hw.hfc.send);
1060 cs->bcs[1].hw.hfc.send = NULL;
1061 kfree(cs->hw.hfcD.send);
1062 cs->hw.hfcD.send = NULL;
1066 set_cs_func(struct IsdnCardState *cs)
1068 cs->readisac = &readreghfcd;
1069 cs->writeisac = &writereghfcd;
1070 cs->readisacfifo = &dummyf;
1071 cs->writeisacfifo = &dummyf;
1072 cs->BC_Read_Reg = &ReadReg;
1073 cs->BC_Write_Reg = &WriteReg;
1074 cs->dbusytimer.function = (void *) hfc_dbusy_timer;
1075 cs->dbusytimer.data = (long) cs;
1076 init_timer(&cs->dbusytimer);
1077 INIT_WORK(&cs->tqueue, hfcd_bh);