Lines Matching defs:bcs

67 static void fill_mem(struct BCState *bcs, u_int *pos, u_int cnt, int chan, u_char fill)
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;
94 mode, bc, bcs->channel);
95 bcs->mode = mode;
96 bcs->channel = bc;
99 fill_mem(bcs, bcs->hw.tiger.send,
103 bcs->hw.tiger.r_tot, bcs->hw.tiger.r_err,
104 bcs->hw.tiger.s_tot);
105 if ((cs->bcs[0].mode == L1_MODE_NULL) &&
106 (cs->bcs[1].mode == L1_MODE_NULL)) {
126 fill_mem(bcs, bcs->hw.tiger.send,
128 bcs->hw.tiger.r_state = HDLC_ZERO_SEARCH;
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;
135 fill_mem(bcs, bcs->hw.tiger.send,
143 bcs->hw.tiger.sendp = bcs->hw.tiger.send;
144 bcs->hw.tiger.free = NETJET_DMA_TXSIZE;
145 test_and_set_bit(BC_FLG_EMPTY, &bcs->Flag);
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) {
226 if (!bcs->tx_skb) {
227 debugl1(bcs->cs, "tiger make_raw: NULL skb");
230 bcs->hw.tiger.sendbuf[s_cnt++] = HDLC_FLAG_VALUE;
232 for (i = 0; i < bcs->tx_skb->len; i++) {
233 val = bcs->tx_skb->data[i];
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);
264 bcs->hw.tiger.sendbuf[s_cnt++] = s_val;
265 bcs->hw.tiger.sendbuf[s_cnt++] = 0xff; // NJ<->NJ thoughput bug fix
267 bcs->hw.tiger.sendcnt = s_cnt;
268 bcs->tx_cnt -= bcs->tx_skb->len;
269 bcs->hw.tiger.sp = bcs->hw.tiger.sendbuf;
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) {
316 if (!bcs->tx_skb) {
317 debugl1(bcs->cs, "tiger make_raw_56k: NULL skb");
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];
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);
371 bcs->hw.tiger.sendbuf[s_cnt++] = s_val;
372 bcs->hw.tiger.sendbuf[s_cnt++] = 0xff; // NJ<->NJ thoughput bug fix
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) {
386 memcpy(skb_put(skb, count), bcs->hw.tiger.rcvbuf, count);
387 skb_queue_tail(&bcs->rqueue, skb);
389 test_and_set_bit(B_RCVBUFREADY, &bcs->event);
390 schedule_work(&bcs->tqueue);
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) {
402 u_int *pend = bcs->hw.tiger.rec + NETJET_DMA_RXSIZE - 1;
403 register u_char state = bcs->hw.tiger.r_state;
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;
411 if (bcs->mode == L1_MODE_HDLC) { // it's 64k
420 val = bcs->channel ? ((*p >> 8) & 0xff) : (*p & 0xff);
423 p = bcs->hw.tiger.rec;
426 bcs->hw.tiger.r_tot++;
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);
486 bcs->hw.tiger.r_fcs = PPP_INITFCS;
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++;
515 bcs->err_inv++;
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);
521 if (bcs->hw.tiger.r_fcs == PPP_GOODFCS) {
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,
528 bcs->hw.tiger.r_err++;
531 bcs->err_crc++;
551 debugl1(bcs->cs, "tiger: frame too big");
554 bcs->hw.tiger.r_err++;
556 bcs->err_inv++;
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;
583 if (cs->bcs[0].mode)
584 cs->bcs[0].err_rdo++;
585 if (cs->bcs[1].mode)
586 cs->bcs[1].err_rdo++;
594 p = cs->bcs[0].hw.tiger.rec + NETJET_DMA_RXSIZE - 1;
596 p = cs->bcs[0].hw.tiger.rec + cnt - 1;
597 if ((cs->bcs[0].mode == L1_MODE_HDLC) || (cs->bcs[0].mode == L1_MODE_HDLC_56K))
598 read_raw(cs->bcs, p, cnt);
600 if ((cs->bcs[1].mode == L1_MODE_HDLC) || (cs->bcs[1].mode == L1_MODE_HDLC_56K))
601 read_raw(cs->bcs + 1, p, cnt);
605 static void write_raw(struct BCState *bcs, u_int *buf, int cnt);
607 void netjet_fill_dma(struct BCState *bcs)
612 if (!bcs->tx_skb)
614 if (bcs->cs->debug & L1_DEB_HSCX)
615 debugl1(bcs->cs, "tiger fill_dma1: c%d %4lx", bcs->channel,
616 bcs->Flag);
617 if (test_and_set_bit(BC_FLG_BUSY, &bcs->Flag))
619 if (bcs->mode == L1_MODE_HDLC) { // it's 64k
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,
629 bcs->Flag);
630 if (test_and_clear_bit(BC_FLG_NOFRAME, &bcs->Flag)) {
631 write_raw(bcs, bcs->hw.tiger.sendp, bcs->hw.tiger.free);
632 } else if (test_and_clear_bit(BC_FLG_HALF, &bcs->Flag)) {
633 p = bus_to_virt(inl(bcs->cs->hw.njet.base + NETJET_DMA_READ_ADR));
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);
653 } else if (test_and_clear_bit(BC_FLG_EMPTY, &bcs->Flag)) {
654 p = bus_to_virt(inl(bcs->cs->hw.njet.base + NETJET_DMA_READ_ADR));
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,
671 bcs->Flag);
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;
688 if (bcs->channel)
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) {
710 if (!bcs->tx_skb) {
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)) {
716 spin_lock_irqsave(&bcs->aclock, flags);
717 bcs->ackcnt += bcs->tx_skb->len;
718 spin_unlock_irqrestore(&bcs->aclock, flags);
719 schedule_event(bcs, B_ACKPENDING);
721 dev_kfree_skb_any(bcs->tx_skb);
722 bcs->tx_skb = NULL;
724 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
725 bcs->hw.tiger.free = cnt - s_cnt;
726 if (bcs->hw.tiger.free > (NETJET_DMA_TXSIZE / 2))
727 test_and_set_bit(BC_FLG_HALF, &bcs->Flag);
729 test_and_clear_bit(BC_FLG_HALF, &bcs->Flag);
730 test_and_set_bit(BC_FLG_NOFRAME, &bcs->Flag);
732 if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) {
733 netjet_fill_dma(bcs);
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",
746 test_and_set_bit(B_XMTBUFREADY, &bcs->event);
747 schedule_work(&bcs->tqueue);
750 } else if (test_and_clear_bit(BC_FLG_NOFRAME, &bcs->Flag)) {
751 test_and_set_bit(BC_FLG_HALF, &bcs->Flag);
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");
756 } else if (test_and_clear_bit(BC_FLG_HALF, &bcs->Flag)) {
757 test_and_set_bit(BC_FLG_EMPTY, &bcs->Flag);
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");
771 if (cs->bcs[0].mode)
772 cs->bcs[0].err_tx++;
773 if (cs->bcs[1].mode)
774 cs->bcs[1].err_tx++;
782 p = cs->bcs[0].hw.tiger.send + NETJET_DMA_TXSIZE - 1;
784 p = cs->bcs[0].hw.tiger.send + cnt - 1;
785 if ((cs->bcs[0].mode == L1_MODE_HDLC) || (cs->bcs[0].mode == L1_MODE_HDLC_56K))
786 write_raw(cs->bcs, p, cnt);
787 if ((cs->bcs[1].mode == L1_MODE_HDLC) || (cs->bcs[1].mode == L1_MODE_HDLC_56K))
788 write_raw(cs->bcs + 1, p, cnt);
795 struct BCState *bcs = st->l1.bcs;
801 spin_lock_irqsave(&bcs->cs->lock, flags);
802 if (bcs->tx_skb) {
803 skb_queue_tail(&bcs->squeue, skb);
805 bcs->tx_skb = skb;
806 bcs->cs->BC_Send_Data(bcs);
808 spin_unlock_irqrestore(&bcs->cs->lock, flags);
811 spin_lock_irqsave(&bcs->cs->lock, flags);
812 if (bcs->tx_skb) {
815 bcs->tx_skb = skb;
816 bcs->cs->BC_Send_Data(bcs);
818 spin_unlock_irqrestore(&bcs->cs->lock, flags);
821 if (!bcs->tx_skb) {
828 spin_lock_irqsave(&bcs->cs->lock, flags);
829 test_and_set_bit(BC_FLG_ACTIV, &bcs->Flag);
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));
838 bcs->cs->cardmsg(bcs->cs, MDL_BC_RELEASE, (void *)(&st->l1.bc));
842 spin_lock_irqsave(&bcs->cs->lock, flags);
843 test_and_clear_bit(BC_FLG_ACTIV, &bcs->Flag);
844 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
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);
857 if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) {
858 kfree(bcs->hw.tiger.rcvbuf);
859 bcs->hw.tiger.rcvbuf = NULL;
860 kfree(bcs->hw.tiger.sendbuf);
861 bcs->hw.tiger.sendbuf = NULL;
862 skb_queue_purge(&bcs->rqueue);
863 skb_queue_purge(&bcs->squeue);
864 if (bcs->tx_skb) {
865 dev_kfree_skb_any(bcs->tx_skb);
866 bcs->tx_skb = NULL;
867 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
873 open_tigerstate(struct IsdnCardState *cs, struct BCState *bcs)
875 if (!test_and_set_bit(BC_FLG_INIT, &bcs->Flag)) {
876 if (!(bcs->hw.tiger.rcvbuf = kmalloc(HSCX_BUFMAX, GFP_ATOMIC))) {
881 if (!(bcs->hw.tiger.sendbuf = kmalloc(RAW_BUFMAX, GFP_ATOMIC))) {
886 skb_queue_head_init(&bcs->rqueue);
887 skb_queue_head_init(&bcs->squeue);
889 bcs->tx_skb = NULL;
890 bcs->hw.tiger.sendcnt = 0;
891 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
892 bcs->event = 0;
893 bcs->tx_cnt = 0;
898 setstack_tiger(struct PStack *st, struct BCState *bcs)
900 bcs->channel = st->l1.bc;
901 if (open_tigerstate(st->l1.hardware, bcs))
903 st->l1.bcs = bcs;
906 bcs->st = st;
915 if (!(cs->bcs[0].hw.tiger.send = kmalloc(NETJET_DMA_TXSIZE * sizeof(unsigned int),
921 cs->bcs[0].hw.tiger.s_irq = cs->bcs[0].hw.tiger.send + NETJET_DMA_TXSIZE / 2 - 1;
922 cs->bcs[0].hw.tiger.s_end = cs->bcs[0].hw.tiger.send + NETJET_DMA_TXSIZE - 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;
927 memset(cs->bcs[0].hw.tiger.send, 0xff, NETJET_DMA_TXSIZE * sizeof(unsigned int));
928 debugl1(cs, "tiger: send buf %p - %p", cs->bcs[0].hw.tiger.send,
929 cs->bcs[0].hw.tiger.send + NETJET_DMA_TXSIZE - 1);
930 outl(virt_to_bus(cs->bcs[0].hw.tiger.send),
932 outl(virt_to_bus(cs->bcs[0].hw.tiger.s_irq),
934 outl(virt_to_bus(cs->bcs[0].hw.tiger.s_end),
936 if (!(cs->bcs[0].hw.tiger.rec = kmalloc(NETJET_DMA_RXSIZE * sizeof(unsigned int),
942 debugl1(cs, "tiger: rec buf %p - %p", cs->bcs[0].hw.tiger.rec,
943 cs->bcs[0].hw.tiger.rec + NETJET_DMA_RXSIZE - 1);
944 cs->bcs[1].hw.tiger.rec = cs->bcs[0].hw.tiger.rec;
945 memset(cs->bcs[0].hw.tiger.rec, 0xff, NETJET_DMA_RXSIZE * sizeof(unsigned int));
946 outl(virt_to_bus(cs->bcs[0].hw.tiger.rec),
948 outl(virt_to_bus(cs->bcs[0].hw.tiger.rec + NETJET_DMA_RXSIZE / 2 - 1),
950 outl(virt_to_bus(cs->bcs[0].hw.tiger.rec + NETJET_DMA_RXSIZE - 1),
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;
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;