23 #include <linux/ppp_defs.h>
24 #include <linux/slab.h>
35 cs->hw.njet.auxd &= 0xfc;
36 cs->hw.njet.auxd |= (offset >> 4) & 3;
37 byteout(cs->hw.njet.auxa, cs->hw.njet.auxd);
38 ret =
bytein(cs->hw.njet.isac + ((offset & 0xf) << 2));
45 cs->hw.njet.auxd &= 0xfc;
46 cs->hw.njet.auxd |= (offset >> 4) & 3;
47 byteout(cs->hw.njet.auxa, cs->hw.njet.auxd);
48 byteout(cs->hw.njet.isac + ((offset & 0xf) << 2), value);
54 cs->hw.njet.auxd &= 0xfc;
55 byteout(cs->hw.njet.auxa, cs->hw.njet.auxd);
56 insb(cs->hw.njet.isac, data, size);
62 cs->hw.njet.auxd &= 0xfc;
63 byteout(cs->hw.njet.auxa, cs->hw.njet.auxd);
64 outsb(cs->hw.njet.isac, data, size);
78 for (i = 0; i <
cnt; i++) {
81 if (
p > bcs->hw.tiger.s_end)
82 p = bcs->hw.tiger.send;
87 mode_tiger(
struct BCState *bcs,
int mode,
int bc)
89 struct IsdnCardState *
cs = bcs->cs;
92 if (cs->debug & L1_DEB_HSCX)
93 debugl1(cs,
"Tiger mode %d bchan %d/%d",
94 mode, bc, bcs->channel);
99 fill_mem(bcs, bcs->hw.tiger.send,
101 if (cs->debug & L1_DEB_HSCX)
102 debugl1(cs,
"Tiger stat rec %d/%d send %d",
103 bcs->hw.tiger.r_tot, bcs->hw.tiger.r_err,
104 bcs->hw.tiger.s_tot);
107 cs->hw.njet.dmactrl = 0;
109 cs->hw.njet.dmactrl);
116 led = 0x01 << (6 +
led);
118 cs->hw.njet.auxd &=
led;
119 byteout(cs->hw.njet.auxa, cs->hw.njet.auxd);
126 fill_mem(bcs, bcs->hw.tiger.send,
129 bcs->hw.tiger.r_tot = 0;
130 bcs->hw.tiger.r_bitcnt = 0;
131 bcs->hw.tiger.r_one = 0;
132 bcs->hw.tiger.r_err = 0;
133 bcs->hw.tiger.s_tot = 0;
134 if (!cs->hw.njet.dmactrl) {
135 fill_mem(bcs, bcs->hw.tiger.send,
137 cs->hw.njet.dmactrl = 1;
139 cs->hw.njet.dmactrl);
143 bcs->hw.tiger.sendp = bcs->hw.tiger.send;
150 led = 0x01 << (6 +
led);
151 cs->hw.njet.auxd |=
led;
152 byteout(cs->hw.njet.auxa, cs->hw.njet.auxd);
156 if (cs->debug & L1_DEB_HSCX)
157 debugl1(cs,
"tiger: set %x %x %x %x/%x pulse=%d",
166 static void printframe(
struct IsdnCardState *cs,
u_char *
buf,
int count,
char *
s) {
172 t +=
sprintf(t,
"tiger %s(%4d)", s, count);
183 t +=
sprintf(t,
"tiger %s ", s);
189 #define MAKE_RAW_BYTE for (j = 0; j < 8; j++) { \
200 bcs->hw.tiger.sendbuf[s_cnt++] = s_val; \
210 bcs->hw.tiger.sendbuf[s_cnt++] = s_val; \
216 static int make_raw_data(
struct BCState *bcs) {
218 register u_int i, s_cnt = 0;
221 register u_char s_one = 0;
222 register u_char s_val = 0;
223 register u_char bitcnt = 0;
227 debugl1(bcs->cs,
"tiger make_raw: NULL skb");
232 for (i = 0; i < bcs->tx_skb->len; i++) {
233 val = bcs->tx_skb->data[
i];
240 val = (fcs >> 8) & 0xff;
243 for (j = 0; j < 8; j++) {
251 bcs->hw.tiger.sendbuf[s_cnt++] = s_val;
256 if (bcs->cs->debug & L1_DEB_HSCX)
257 debugl1(bcs->cs,
"tiger make_raw: in %u out %d.%d",
258 bcs->tx_skb->len, s_cnt, bitcnt);
260 while (8 > bitcnt++) {
264 bcs->hw.tiger.sendbuf[s_cnt++] = s_val;
265 bcs->hw.tiger.sendbuf[s_cnt++] = 0xff;
267 bcs->hw.tiger.sendcnt = s_cnt;
268 bcs->tx_cnt -= bcs->tx_skb->len;
269 bcs->hw.tiger.sp = bcs->hw.tiger.sendbuf;
275 #define MAKE_RAW_BYTE_56K for (j = 0; j < 8; j++) { \
288 bcs->hw.tiger.sendbuf[s_cnt++] = s_val; \
300 bcs->hw.tiger.sendbuf[s_cnt++] = s_val; \
306 static int make_raw_data_56k(
struct BCState *bcs) {
308 register u_int i, s_cnt = 0;
311 register u_char s_one = 0;
312 register u_char s_val = 0;
313 register u_char bitcnt = 0;
317 debugl1(bcs->cs,
"tiger make_raw_56k: NULL skb");
321 for (j = 0; j < 8; j++) {
331 bcs->hw.tiger.sendbuf[s_cnt++] = s_val;
337 for (i = 0; i < bcs->tx_skb->len; i++) {
338 val = bcs->tx_skb->data[
i];
345 val = (fcs >> 8) & 0xff;
348 for (j = 0; j < 8; j++) {
358 bcs->hw.tiger.sendbuf[s_cnt++] = s_val;
363 if (bcs->cs->debug & L1_DEB_HSCX)
364 debugl1(bcs->cs,
"tiger make_raw_56k: in %u out %d.%d",
365 bcs->tx_skb->len, s_cnt, bitcnt);
367 while (8 > bitcnt++) {
371 bcs->hw.tiger.sendbuf[s_cnt++] = s_val;
372 bcs->hw.tiger.sendbuf[s_cnt++] = 0xff;
374 bcs->hw.tiger.sendcnt = s_cnt;
375 bcs->tx_cnt -= bcs->tx_skb->len;
376 bcs->hw.tiger.sp = bcs->hw.tiger.sendbuf;
380 static void got_frame(
struct BCState *bcs,
int count) {
383 if (!(skb = dev_alloc_skb(count)))
392 if (bcs->cs->debug & L1_DEB_RECEIVE_FRAME)
393 printframe(bcs->cs, bcs->hw.tiger.rcvbuf, count,
"rec");
398 static void read_raw(
struct BCState *bcs,
u_int *buf,
int cnt) {
404 register u_char r_one = bcs->hw.tiger.r_one;
405 register u_char r_val = bcs->hw.tiger.r_val;
406 register u_int bitcnt = bcs->hw.tiger.r_bitcnt;
419 for (i = 0; i <
cnt; i++) {
420 val = bcs->channel ? ((*p >> 8) & 0xff) : (*p & 0xff);
423 p = bcs->hw.tiger.rec;
424 if ((val & mask) ==
mask) {
426 bcs->hw.tiger.r_tot++;
431 for (j = 0; j <
bits; j++) {
438 if (bcs->cs->debug & L1_DEB_HSCX)
439 debugl1(bcs->cs,
"tiger read_raw: zBit(%d,%d,%d) %x",
440 bcs->hw.tiger.r_tot, i, j, val);
453 if (bcs->cs->debug & L1_DEB_HSCX)
454 debugl1(bcs->cs,
"tiger read_raw: flag(%d,%d,%d) %x",
455 bcs->hw.tiger.r_tot, i, j, val);
476 }
else if (r_one != 5) {
487 bcs->hw.tiger.rcvbuf[0] = r_val;
488 bcs->hw.tiger.r_fcs =
PPP_FCS(bcs->hw.tiger.r_fcs, r_val);
489 if (bcs->cs->debug & L1_DEB_HSCX)
490 debugl1(bcs->cs,
"tiger read_raw: byte1(%d,%d,%d) rval %x val %x i %x",
491 bcs->hw.tiger.r_tot, i, j, r_val, val,
492 bcs->cs->hw.njet.irqstat0);
511 debugl1(bcs->cs,
"tiger: frame not byte aligned");
513 bcs->hw.tiger.r_err++;
514 #ifdef ERROR_STATISTIC
518 if (bcs->cs->debug & L1_DEB_HSCX)
519 debugl1(bcs->cs,
"tiger frame end(%d,%d): fcs(%x) i %x",
520 i, j, bcs->hw.tiger.r_fcs, bcs->cs->hw.njet.irqstat0);
522 got_frame(bcs, (bitcnt >> 3) - 3);
524 if (bcs->cs->debug) {
525 debugl1(bcs->cs,
"tiger FCS error");
526 printframe(bcs->cs, bcs->hw.tiger.rcvbuf,
527 (bitcnt >> 3) - 1,
"rec");
528 bcs->hw.tiger.r_err++;
530 #ifdef ERROR_STATISTIC
537 }
else if (r_one == 5) {
551 debugl1(bcs->cs,
"tiger: frame too big");
554 bcs->hw.tiger.r_err++;
555 #ifdef ERROR_STATISTIC
559 bcs->hw.tiger.rcvbuf[(bitcnt >> 3) - 1] = r_val;
560 bcs->hw.tiger.r_fcs =
561 PPP_FCS(bcs->hw.tiger.r_fcs, r_val);
567 bcs->hw.tiger.r_tot++;
569 bcs->hw.tiger.r_state =
state;
570 bcs->hw.tiger.r_one = r_one;
571 bcs->hw.tiger.r_val = r_val;
572 bcs->hw.tiger.r_bitcnt = bitcnt;
580 debugl1(cs,
"tiger warn read double dma %x/%x",
581 cs->hw.njet.irqstat0, cs->hw.njet.last_is0);
582 #ifdef ERROR_STATISTIC
584 cs->bcs[0].err_rdo++;
586 cs->bcs[1].err_rdo++;
596 p = cs->bcs[0].hw.tiger.rec + cnt - 1;
598 read_raw(cs->bcs, p, cnt);
601 read_raw(cs->bcs + 1, p, cnt);
605 static void write_raw(
struct BCState *bcs,
u_int *buf,
int cnt);
614 if (bcs->cs->debug & L1_DEB_HSCX)
615 debugl1(bcs->cs,
"tiger fill_dma1: c%d %4lx", bcs->channel,
620 if (make_raw_data(bcs))
624 if (make_raw_data_56k(bcs))
627 if (bcs->cs->debug & L1_DEB_HSCX)
628 debugl1(bcs->cs,
"tiger fill_dma2: c%d %4lx", bcs->channel,
631 write_raw(bcs, bcs->hw.tiger.sendp, bcs->hw.tiger.free);
634 sp = bcs->hw.tiger.sendp;
635 if (p == bcs->hw.tiger.s_end)
636 p = bcs->hw.tiger.send - 1;
637 if (sp == bcs->hw.tiger.s_end)
638 sp = bcs->hw.tiger.send - 1;
641 write_raw(bcs, bcs->hw.tiger.sendp, bcs->hw.tiger.free);
645 if (p > bcs->hw.tiger.s_end)
646 p = bcs->hw.tiger.send;
649 if (p > bcs->hw.tiger.s_end)
650 p = bcs->hw.tiger.send;
651 write_raw(bcs, p, bcs->hw.tiger.free - cnt);
655 cnt = bcs->hw.tiger.s_end -
p;
657 p = bcs->hw.tiger.send + 1;
667 write_raw(bcs, p, cnt);
669 if (bcs->cs->debug & L1_DEB_HSCX)
670 debugl1(bcs->cs,
"tiger fill_dma3: c%d %4lx", bcs->channel,
674 static void write_raw(
struct BCState *bcs,
u_int *buf,
int cnt) {
680 if (
test_bit(BC_FLG_BUSY, &bcs->Flag)) {
681 if (bcs->hw.tiger.sendcnt > cnt) {
683 bcs->hw.tiger.sendcnt -=
cnt;
685 s_cnt = bcs->hw.tiger.sendcnt;
686 bcs->hw.tiger.sendcnt = 0;
692 for (i = 0; i < s_cnt; i++) {
693 val = bcs->channel ? ((bcs->hw.tiger.sp[
i] << 8) & 0xff00) :
694 (bcs->hw.tiger.sp[
i]);
697 if (p > bcs->hw.tiger.s_end)
698 p = bcs->hw.tiger.send;
700 bcs->hw.tiger.s_tot += s_cnt;
701 if (bcs->cs->debug & L1_DEB_HSCX)
702 debugl1(bcs->cs,
"tiger write_raw: c%d %p-%p %d/%d %d %x", bcs->channel,
704 bcs->hw.tiger.sendcnt, bcs->cs->hw.njet.irqstat0);
705 if (bcs->cs->debug & L1_DEB_HSCX_FIFO)
706 printframe(bcs->cs, bcs->hw.tiger.sp, s_cnt,
"snd");
707 bcs->hw.tiger.sp += s_cnt;
708 bcs->hw.tiger.sendp =
p;
709 if (!bcs->hw.tiger.sendcnt) {
711 debugl1(bcs->cs,
"tiger write_raw: NULL skb s_cnt %d", s_cnt);
713 if (
test_bit(FLG_LLI_L1WAKEUP, &bcs->st->lli.flag) &&
714 (PACKET_NOACK != bcs->tx_skb->pkt_type)) {
717 bcs->ackcnt += bcs->tx_skb->len;
718 spin_unlock_irqrestore(&bcs->aclock, flags);
725 bcs->hw.tiger.free = cnt - s_cnt;
737 for (i = s_cnt; i <
cnt; i++) {
739 if (p > bcs->hw.tiger.s_end)
740 p = bcs->hw.tiger.send;
742 if (bcs->cs->debug & L1_DEB_HSCX)
743 debugl1(bcs->cs,
"tiger write_raw: fill rest %d",
752 fill_mem(bcs, buf, cnt, bcs->channel, 0xff);
753 bcs->hw.tiger.free +=
cnt;
754 if (bcs->cs->debug & L1_DEB_HSCX)
755 debugl1(bcs->cs,
"tiger write_raw: fill half");
758 fill_mem(bcs, buf, cnt, bcs->channel, 0xff);
759 if (bcs->cs->debug & L1_DEB_HSCX)
760 debugl1(bcs->cs,
"tiger write_raw: fill full");
768 debugl1(cs,
"tiger warn write double dma %x/%x",
769 cs->hw.njet.irqstat0, cs->hw.njet.last_is0);
770 #ifdef ERROR_STATISTIC
784 p = cs->bcs[0].hw.tiger.send + cnt - 1;
786 write_raw(cs->bcs, p, cnt);
788 write_raw(cs->bcs + 1, p, cnt);
793 tiger_l2l1(
struct PStack *
st,
int pr,
void *
arg)
795 struct BCState *bcs = st->l1.bcs;
806 bcs->cs->BC_Send_Data(bcs);
808 spin_unlock_irqrestore(&bcs->cs->lock, flags);
816 bcs->cs->BC_Send_Data(bcs);
818 spin_unlock_irqrestore(&bcs->cs->lock, flags);
830 mode_tiger(bcs, st->l1.mode, st->l1.bc);
832 spin_unlock_irqrestore(&bcs->cs->lock, flags);
833 bcs->cs->cardmsg(bcs->cs,
MDL_BC_ASSIGN, (
void *)(&st->l1.bc));
845 mode_tiger(bcs, 0, st->l1.bc);
846 spin_unlock_irqrestore(&bcs->cs->lock, flags);
854 close_tigerstate(
struct BCState *bcs)
856 mode_tiger(bcs, 0, bcs->channel);
858 kfree(bcs->hw.tiger.rcvbuf);
859 bcs->hw.tiger.rcvbuf =
NULL;
860 kfree(bcs->hw.tiger.sendbuf);
861 bcs->hw.tiger.sendbuf =
NULL;
873 open_tigerstate(
struct IsdnCardState *cs,
struct BCState *bcs)
878 "HiSax: No memory for tiger.rcvbuf\n");
883 "HiSax: No memory for tiger.sendbuf\n");
886 skb_queue_head_init(&bcs->rqueue);
887 skb_queue_head_init(&bcs->squeue);
890 bcs->hw.tiger.sendcnt = 0;
898 setstack_tiger(
struct PStack *st,
struct BCState *bcs)
900 bcs->channel = st->l1.bc;
901 if (open_tigerstate(st->l1.hardware, bcs))
904 st->l2.l2l1 = tiger_l2l1;
918 "HiSax: No memory for tiger.send\n");
921 cs->bcs[0].hw.tiger.s_irq = cs->bcs[0].hw.tiger.send +
NETJET_DMA_TXSIZE / 2 - 1;
923 cs->bcs[1].hw.tiger.send = cs->bcs[0].hw.tiger.send;
924 cs->bcs[1].hw.tiger.s_irq = cs->bcs[0].hw.tiger.s_irq;
925 cs->bcs[1].hw.tiger.s_end = cs->bcs[0].hw.tiger.s_end;
928 debugl1(cs,
"tiger: send buf %p - %p", cs->bcs[0].hw.tiger.send,
939 "HiSax: No memory for tiger.rec\n");
942 debugl1(cs,
"tiger: rec buf %p - %p", cs->bcs[0].hw.tiger.rec,
944 cs->bcs[1].hw.tiger.rec = cs->bcs[0].hw.tiger.rec;
952 debugl1(cs,
"tiger: dmacfg %x/%x pulse=%d",
956 cs->hw.njet.last_is0 = 0;
957 cs->bcs[0].BC_SetStack = setstack_tiger;
958 cs->bcs[1].BC_SetStack = setstack_tiger;
959 cs->bcs[0].BC_Close = close_tigerstate;
960 cs->bcs[1].BC_Close = close_tigerstate;
964 releasetiger(
struct IsdnCardState *cs)
966 kfree(cs->bcs[0].hw.tiger.send);
967 cs->bcs[0].hw.tiger.send =
NULL;
968 cs->bcs[1].hw.tiger.send =
NULL;
969 kfree(cs->bcs[0].hw.tiger.rec);
970 cs->bcs[0].hw.tiger.rec =
NULL;
971 cs->bcs[1].hw.tiger.rec =
NULL;