12 #include <linux/kernel.h>
13 #include <linux/slab.h>
20 #define DBUSY_TIMER_VALUE 80
21 #define TIMER3_VALUE 7000
22 #define MAX_DFRAME_LEN_L1 300
23 #define B_FIFO_SIZE 64
24 #define D_FIFO_SIZE 32
28 #define _MASK_IMASK 0x2E // global mask
29 #define _MASKB_IMASK 0x0B
30 #define _MASKD_IMASK 0x03 // all on
35 static void ph_command(
struct IsdnCardState *
cs,
unsigned int command);
36 static inline void cic_int(
struct IsdnCardState *
cs);
37 static void dch_l2l1(
struct PStack *
st,
int pr,
void *
arg);
38 static void dbusy_timer_handler(
struct IsdnCardState *
cs);
39 static void dch_empty_fifo(
struct IsdnCardState *
cs,
int count);
40 static void dch_fill_fifo(
struct IsdnCardState *
cs);
41 static inline void dch_int(
struct IsdnCardState *
cs);
42 static void dch_setstack(
struct PStack *
st,
struct IsdnCardState *
cs);
43 static void dch_init(
struct IsdnCardState *
cs);
44 static void bch_l2l1(
struct PStack *
st,
int pr,
void *
arg);
45 static void bch_empty_fifo(
struct BCState *bcs,
int count);
46 static void bch_fill_fifo(
struct BCState *bcs);
47 static void bch_int(
struct IsdnCardState *
cs,
u_char hscx);
48 static void bch_mode(
struct BCState *bcs,
int mode,
int bc);
49 static void bch_close_state(
struct BCState *bcs);
50 static int bch_open_state(
struct IsdnCardState *
cs,
struct BCState *bcs);
51 static int bch_setstack(
struct PStack *
st,
struct BCState *bcs);
52 static void bch_init(
struct IsdnCardState *
cs,
int hscx);
53 static void clear_pending_ints(
struct IsdnCardState *
cs);
59 ph_command(
struct IsdnCardState *
cs,
unsigned int command)
61 if (cs->debug & L1_DEB_ISAC)
62 debugl1(cs,
"ph_command (%#x) in (%#x)", command,
63 cs->dc.isac.ph_state);
67 cs->writeisac(cs,
IPACX_CIX0, (command << 4) | 0x0E);
74 cic_int(
struct IsdnCardState *cs)
79 if (cs->debug & L1_DEB_ISAC)
debugl1(cs,
"cic_int(event=%#x)", event);
83 cs->dc.isac.ph_state =
event;
95 dch_l2l1(
struct PStack *
st,
int pr,
void *
arg)
97 struct IsdnCardState *cs = (
struct IsdnCardState *) st->l1.hardware;
104 if (cs->debug & DEB_DLOG_VERBOSE)
dlogframe(cs,
skb, 0);
108 if (cs->debug & L1_DEB_LAPD)
Logl2Frame(cs,
skb,
"PH_DATA Queued", 0);
114 if (cs->debug & L1_DEB_LAPD)
Logl2Frame(cs,
skb,
"PH_DATA", 0);
122 if (cs->debug & L1_DEB_WARN)
123 debugl1(cs,
" l2l1 tx_skb exist this shouldn't happen");
128 if (cs->debug & DEB_DLOG_VERBOSE)
dlogframe(cs,
skb, 0);
132 if (cs->debug & L1_DEB_LAPD)
Logl2Frame(cs,
skb,
"PH_DATA_PULLED", 0);
139 if (cs->debug & L1_DEB_LAPD)
debugl1(cs,
"-> PH_REQUEST_PULL");
193 if (cs->debug & L1_DEB_WARN)
debugl1(cs,
"dch_l2l1 unknown %04x", pr);
201 dbusy_timer_handler(
struct IsdnCardState *cs)
206 if (
test_bit(FLG_DBUSY_TIMER, &cs->HW_Flags)) {
210 debugl1(cs,
"D-Channel Busy RBCHD %02x STARD %02x", rbchd, stard);
211 if (!(stard & 0x40)) {
212 set_bit(FLG_L1_DBUSY, &cs->HW_Flags);
213 for (st = cs->stlist; st; st = st->next) {
218 clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags);
225 debugl1(cs,
"D-Channel Busy no skb");
236 dch_empty_fifo(
struct IsdnCardState *cs,
int count)
240 if ((cs->debug & L1_DEB_ISAC) && !(cs->debug & L1_DEB_ISAC_FIFO))
241 debugl1(cs,
"dch_empty_fifo()");
245 if (cs->debug & L1_DEB_WARN)
246 debugl1(cs,
"dch_empty_fifo() incoming message too large");
252 ptr = cs->rcvbuf + cs->rcvidx;
255 cs->readisacfifo(cs, ptr, count);
258 if (cs->debug & L1_DEB_ISAC_FIFO) {
261 t +=
sprintf(t,
"dch_empty_fifo() cnt %d", count);
271 dch_fill_fifo(
struct IsdnCardState *cs)
276 if ((cs->debug & L1_DEB_ISAC) && !(cs->debug & L1_DEB_ISAC_FIFO))
277 debugl1(cs,
"dch_fill_fifo()");
279 if (!cs->tx_skb)
return;
280 count = cs->tx_skb->len;
281 if (count <= 0)
return;
290 ptr = cs->tx_skb->data;
293 cs->writeisacfifo(cs, ptr, count);
298 debugl1(cs,
"dch_fill_fifo dbusytimer running");
305 if (cs->debug & L1_DEB_ISAC_FIFO) {
308 t +=
sprintf(t,
"dch_fill_fifo() cnt %d", count);
318 dch_int(
struct IsdnCardState *cs)
331 if ((rstad & 0xf0) != 0xa0) {
333 if (cs->debug & L1_DEB_WARN)
334 debugl1(cs,
"dch_int(): invalid frame");
336 if (cs->debug & L1_DEB_WARN)
339 if (cs->debug & L1_DEB_WARN)
340 debugl1(cs,
"dch_int(): CRC error");
347 dch_empty_fifo(cs, count);
348 if ((count = cs->rcvidx) > 0) {
350 if (!(skb = dev_alloc_skb(count)))
367 if (cs->debug & L1_DEB_WARN)
debugl1(cs,
"dch_int(): RFO");
377 if (cs->tx_skb->len) {
398 if (cs->debug & L1_DEB_WARN)
debugl1(cs,
"dch_int(): XDU");
405 debugl1(cs,
"ISAC XDU no skb");
413 dch_setstack(
struct PStack *st,
struct IsdnCardState *cs)
415 st->l1.l1hw = dch_l2l1;
421 dch_init(
struct IsdnCardState *cs)
425 cs->setstack_d = dch_setstack;
427 cs->dbusytimer.function = (
void *) dbusy_timer_handler;
428 cs->dbusytimer.data = (
long) cs;
446 bch_l2l1(
struct PStack *st,
int pr,
void *arg)
448 struct BCState *bcs = st->l1.bcs;
459 set_bit(BC_FLG_BUSY, &bcs->Flag);
460 bcs->hw.hscx.count = 0;
463 spin_unlock_irqrestore(&bcs->cs->lock, flags);
470 set_bit(BC_FLG_BUSY, &bcs->Flag);
472 bcs->hw.hscx.count = 0;
475 spin_unlock_irqrestore(&bcs->cs->lock, flags);
486 set_bit(BC_FLG_ACTIV, &bcs->Flag);
487 bch_mode(bcs, st->l1.mode, st->l1.bc);
488 spin_unlock_irqrestore(&bcs->cs->lock, flags);
498 bch_mode(bcs, 0, st->l1.bc);
499 spin_unlock_irqrestore(&bcs->cs->lock, flags);
509 bch_empty_fifo(
struct BCState *bcs,
int count)
512 struct IsdnCardState *
cs;
516 hscx = bcs->hw.hscx.hscx;
517 if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
518 debugl1(cs,
"bch_empty_fifo()");
522 if (cs->debug & L1_DEB_WARN)
523 debugl1(cs,
"bch_empty_fifo() incoming packet too large");
525 bcs->hw.hscx.rcvidx = 0;
529 ptr = bcs->hw.hscx.rcvbuf + bcs->hw.hscx.rcvidx;
531 while (cnt--) *ptr++ = cs->BC_Read_Reg(cs, hscx,
IPACX_RFIFOB);
534 ptr = bcs->hw.hscx.rcvbuf + bcs->hw.hscx.rcvidx;
535 bcs->hw.hscx.rcvidx +=
count;
537 if (cs->debug & L1_DEB_HSCX_FIFO) {
540 t +=
sprintf(t,
"bch_empty_fifo() B-%d cnt %d", hscx, count);
550 bch_fill_fifo(
struct BCState *bcs)
552 struct IsdnCardState *
cs;
557 if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
558 debugl1(cs,
"bch_fill_fifo()");
560 if (!bcs->tx_skb)
return;
561 if (bcs->tx_skb->len <= 0)
return;
563 hscx = bcs->hw.hscx.hscx;
569 count = bcs->tx_skb->len;
573 p = ptr = bcs->tx_skb->data;
575 bcs->tx_cnt -=
count;
576 bcs->hw.hscx.count +=
count;
577 while (cnt--) cs->BC_Write_Reg(cs, hscx,
IPACX_XFIFOB, *p++);
578 cs->BC_Write_Reg(cs, hscx,
IPACX_CMDRB, (more ? 0x08 : 0x0a));
580 if (cs->debug & L1_DEB_HSCX_FIFO) {
583 t +=
sprintf(t,
"chb_fill_fifo() B-%d cnt %d", hscx, count);
593 bch_int(
struct IsdnCardState *cs,
u_char hscx)
601 bcs = cs->bcs + hscx;
606 if (!
test_bit(BC_FLG_INIT, &bcs->Flag))
return;
610 if ((rstab & 0xf0) != 0xa0) {
612 if (cs->debug & L1_DEB_WARN)
613 debugl1(cs,
"bch_int() B-%d: invalid frame", hscx);
615 if (cs->debug & L1_DEB_WARN)
616 debugl1(cs,
"bch_int() B-%d: RDO mode=%d", hscx, bcs->mode);
618 if (cs->debug & L1_DEB_WARN)
619 debugl1(cs,
"bch_int() B-%d: CRC error", hscx);
625 bch_empty_fifo(bcs, count);
626 if ((count = bcs->hw.hscx.rcvidx - 1) > 0) {
627 if (cs->debug & L1_DEB_HSCX_FIFO)
628 debugl1(cs,
"bch_int Frame %d", count);
629 if (!(skb = dev_alloc_skb(count)))
637 bcs->hw.hscx.rcvidx = 0;
652 bcs->hw.hscx.rcvidx = 0;
658 if (cs->debug & L1_DEB_WARN)
659 debugl1(cs,
"bch_int() B-%d: RFO error", hscx);
665 if (bcs->tx_skb->len) {
669 if (
test_bit(FLG_LLI_L1WAKEUP, &bcs->st->lli.flag) &&
670 (PACKET_NOACK != bcs->tx_skb->pkt_type)) {
673 bcs->ackcnt += bcs->hw.hscx.count;
674 spin_unlock_irqrestore(&bcs->aclock, flags);
679 bcs->hw.hscx.count = 0;
683 bcs->hw.hscx.count = 0;
684 set_bit(BC_FLG_BUSY, &bcs->Flag);
699 skb_push(bcs->tx_skb, bcs->hw.hscx.count);
700 bcs->tx_cnt += bcs->hw.hscx.count;
701 bcs->hw.hscx.count = 0;
704 if (cs->debug & L1_DEB_WARN)
705 debugl1(cs,
"bch_int() B-%d XDU error", hscx);
713 bch_mode(
struct BCState *bcs,
int mode,
int bc)
715 struct IsdnCardState *cs = bcs->cs;
716 int hscx = bcs->hw.hscx.hscx;
719 if (cs->debug & L1_DEB_HSCX)
720 debugl1(cs,
"mode_bch() switch B-%d mode %d chan %d", hscx, mode, bc);
761 bch_close_state(
struct BCState *bcs)
763 bch_mode(bcs, 0, bcs->channel);
765 kfree(bcs->hw.hscx.rcvbuf);
766 bcs->hw.hscx.rcvbuf =
NULL;
782 bch_open_state(
struct IsdnCardState *cs,
struct BCState *bcs)
787 "HiSax open_bchstate(): No memory for hscx.rcvbuf\n");
793 "HiSax open_bchstate: No memory for bcs->blog\n");
795 kfree(bcs->hw.hscx.rcvbuf);
796 bcs->hw.hscx.rcvbuf =
NULL;
799 skb_queue_head_init(&bcs->rqueue);
800 skb_queue_head_init(&bcs->squeue);
805 bcs->hw.hscx.rcvidx = 0;
813 bch_setstack(
struct PStack *st,
struct BCState *bcs)
815 bcs->channel = st->l1.bc;
816 if (bch_open_state(st->l1.hardware, bcs))
return (-1);
818 st->l2.l2l1 = bch_l2l1;
828 bch_init(
struct IsdnCardState *cs,
int hscx)
830 cs->bcs[hscx].BC_SetStack = bch_setstack;
831 cs->bcs[hscx].BC_Close = bch_close_state;
832 cs->bcs[hscx].hw.hscx.hscx = hscx;
833 cs->bcs[hscx].cs =
cs;
834 bch_mode(cs->bcs + hscx, 0, hscx);
850 while ((ista = cs->readisac(cs,
IPACX_ISTA))) {
854 if (ista & 0x80) bch_int(cs, 0);
855 if (ista & 0x40) bch_int(cs, 1);
857 if (ista & 0x01) dch_int(cs);
858 if (ista & 0x10) cic_int(cs);
866 clear_pending_ints(
struct IsdnCardState *cs)
877 if (ista & 0x80) cs->BC_Read_Reg(cs, 0,
IPACX_ISTAB);
878 if (ista & 0x40) cs->BC_Read_Reg(cs, 1,
IPACX_ISTAB);
879 if (ista & 0x10) cs->readisac(cs,
IPACX_CIR0);
894 clear_pending_ints(cs);