Lines Matching +full:tsi +full:- +full:channel +full:- +full:mask
1 // SPDX-License-Identifier: GPL-2.0-only
8 * It was taken from the frle-0.22 device driver.
11 * frle-0.22 device driver.
26 * 1 - Per card interrupt spinlock (to protect structures and such)
27 * 2 - Per SCQ scq spinlock
28 * 3 - Per card resource spinlock (to access registers, etc.)
42 #include <linux/dma-mapping.h>
105 #define CMD_BUSY(card) (readl((card)->membase + STAT) & NS_STAT_CMDBZ)
109 #define PTR_DIFF(a, b) ((u32)((unsigned long)(a) - (unsigned long)(b)))
112 #define ATM_SKB(s) (&(s)->atm)
116 (scq->dma + ((unsigned long)(p) - (unsigned long)(scq)->org))
181 static int index = -1; in nicstar_init_one()
189 cards[index--] = NULL; /* don't increment index */ in nicstar_init_one()
195 return -ENODEV; in nicstar_init_one()
207 i = card->index; in nicstar_remove_one()
212 if (card->atmdev->phy && card->atmdev->phy->stop) in nicstar_remove_one()
213 card->atmdev->phy->stop(card->atmdev); in nicstar_remove_one()
216 writel(0x00000000, card->membase + CFG); in nicstar_remove_one()
218 /* De-register device */ in nicstar_remove_one()
219 atm_dev_deregister(card->atmdev); in nicstar_remove_one()
226 PRINTK("nicstar%d: freeing %d huge buffers.\n", i, card->hbpool.count); in nicstar_remove_one()
227 while ((hb = skb_dequeue(&card->hbpool.queue)) != NULL) { in nicstar_remove_one()
234 card->iovpool.count); in nicstar_remove_one()
235 while ((iovb = skb_dequeue(&card->iovpool.queue)) != NULL) { in nicstar_remove_one()
240 while ((lb = skb_dequeue(&card->lbpool.queue)) != NULL) in nicstar_remove_one()
242 while ((sb = skb_dequeue(&card->sbpool.queue)) != NULL) in nicstar_remove_one()
244 free_scq(card, card->scq0, NULL); in nicstar_remove_one()
246 if (card->scd2vc[j] != NULL) in nicstar_remove_one()
247 free_scq(card, card->scd2vc[j]->scq, card->scd2vc[j]->tx_vcc); in nicstar_remove_one()
249 idr_destroy(&card->idr); in nicstar_remove_one()
250 dma_free_coherent(&card->pcidev->dev, NS_RSQSIZE + NS_RSQ_ALIGNMENT, in nicstar_remove_one()
251 card->rsq.org, card->rsq.dma); in nicstar_remove_one()
252 dma_free_coherent(&card->pcidev->dev, NS_TSQSIZE + NS_TSQ_ALIGNMENT, in nicstar_remove_one()
253 card->tsq.org, card->tsq.dma); in nicstar_remove_one()
254 free_irq(card->pcidev->irq, card); in nicstar_remove_one()
255 iounmap(card->membase); in nicstar_remove_one()
316 spin_lock_irqsave(&card->res_lock, flags); in ns_read_sram()
318 writel(sram_address, card->membase + CMD); in ns_read_sram()
320 data = readl(card->membase + DR0); in ns_read_sram()
321 spin_unlock_irqrestore(&card->res_lock, flags); in ns_read_sram()
330 count--; /* count range now is 0..3 instead of 1..4 */ in ns_write_sram()
333 spin_lock_irqsave(&card->res_lock, flags); in ns_write_sram()
336 writel(*(value++), card->membase + i); in ns_write_sram()
338 so card->membase + DR0 == card->membase */ in ns_write_sram()
342 writel(sram_address, card->membase + CMD); in ns_write_sram()
343 spin_unlock_irqrestore(&card->res_lock, flags); in ns_write_sram()
366 if (dma_set_mask_and_coherent(&pcidev->dev, DMA_BIT_MASK(32)) != 0) { in ns_init_card()
384 spin_lock_init(&card->int_lock); in ns_init_card()
385 spin_lock_init(&card->res_lock); in ns_init_card()
389 card->index = i; in ns_init_card()
390 card->atmdev = NULL; in ns_init_card()
391 card->pcidev = pcidev; in ns_init_card()
393 card->membase = ioremap(membase, NS_IOREMAP_SIZE); in ns_init_card()
394 if (!card->membase) { in ns_init_card()
400 PRINTK("nicstar%d: membase at 0x%p.\n", i, card->membase); in ns_init_card()
431 data = readl(card->membase + STAT); in ns_init_card()
433 writel(NS_STAT_TMROF, card->membase + STAT); in ns_init_card()
436 writel(NS_CFG_SWRST, card->membase + CFG); in ns_init_card()
438 writel(0x00000000, card->membase + CFG); in ns_init_card()
441 writel(0x00000008, card->membase + GP); in ns_init_card()
443 writel(0x00000001, card->membase + GP); in ns_init_card()
446 writel(NS_CMD_WRITE_UTILITY | 0x00000100, card->membase + CMD); /* Sync UTOPIA with SAR clock */ in ns_init_card()
451 writel(NS_CMD_READ_UTILITY | 0x00000200, card->membase + CMD); in ns_init_card()
453 data = readl(card->membase + DR0); in ns_init_card()
457 card->max_pcr = ATM_25_PCR; in ns_init_card()
459 writel(0x00000008, card->membase + DR0); in ns_init_card()
460 writel(NS_CMD_WRITE_UTILITY | 0x00000200, card->membase + CMD); in ns_init_card()
462 writel(NS_STAT_SFBQF, card->membase + STAT); in ns_init_card()
465 writel(0x00000022, card->membase + DR0); in ns_init_card()
466 writel(NS_CMD_WRITE_UTILITY | 0x00000202, card->membase + CMD); in ns_init_card()
472 card->max_pcr = ATM_OC3_PCR; in ns_init_card()
475 writel(0x00000002, card->membase + DR0); in ns_init_card()
476 writel(NS_CMD_WRITE_UTILITY | 0x00000205, card->membase + CMD); in ns_init_card()
485 writel(0x00000000, card->membase + GP); in ns_init_card()
494 card->sram_size = 128; in ns_init_card()
496 card->sram_size = 32; in ns_init_card()
497 PRINTK("nicstar%d: %dK x 32bit SRAM size.\n", i, card->sram_size); in ns_init_card()
499 card->rct_size = NS_MAX_RCTSIZE; in ns_init_card()
502 if (card->sram_size == 128) in ns_init_card()
507 if (card->sram_size == 32) { in ns_init_card()
511 card->rct_size = 4096; in ns_init_card()
517 card->vpibits = NS_VPIBITS; in ns_init_card()
518 if (card->rct_size == 4096) in ns_init_card()
519 card->vcibits = 12 - NS_VPIBITS; in ns_init_card()
520 else /* card->rct_size == 16384 */ in ns_init_card()
521 card->vcibits = 14 - NS_VPIBITS; in ns_init_card()
525 nicstar_init_eprom(card->membase); in ns_init_card()
527 /* Set the VPI/VCI MSb mask to zero so we can receive OAM cells */ in ns_init_card()
528 writel(0x00000000, card->membase + VPM); in ns_init_card()
530 card->intcnt = 0; in ns_init_card()
532 (pcidev->irq, &ns_irq_handler, IRQF_SHARED, "nicstar", card) != 0) { in ns_init_card()
533 pr_err("nicstar%d: can't allocate IRQ %d.\n", i, pcidev->irq); in ns_init_card()
540 card->tsq.org = dma_alloc_coherent(&card->pcidev->dev, in ns_init_card()
542 &card->tsq.dma, GFP_KERNEL); in ns_init_card()
543 if (card->tsq.org == NULL) { in ns_init_card()
549 card->tsq.base = PTR_ALIGN(card->tsq.org, NS_TSQ_ALIGNMENT); in ns_init_card()
550 card->tsq.next = card->tsq.base; in ns_init_card()
551 card->tsq.last = card->tsq.base + (NS_TSQ_NUM_ENTRIES - 1); in ns_init_card()
553 ns_tsi_init(card->tsq.base + j); in ns_init_card()
554 writel(0x00000000, card->membase + TSQH); in ns_init_card()
555 writel(ALIGN(card->tsq.dma, NS_TSQ_ALIGNMENT), card->membase + TSQB); in ns_init_card()
556 PRINTK("nicstar%d: TSQ base at 0x%p.\n", i, card->tsq.base); in ns_init_card()
559 card->rsq.org = dma_alloc_coherent(&card->pcidev->dev, in ns_init_card()
561 &card->rsq.dma, GFP_KERNEL); in ns_init_card()
562 if (card->rsq.org == NULL) { in ns_init_card()
568 card->rsq.base = PTR_ALIGN(card->rsq.org, NS_RSQ_ALIGNMENT); in ns_init_card()
569 card->rsq.next = card->rsq.base; in ns_init_card()
570 card->rsq.last = card->rsq.base + (NS_RSQ_NUM_ENTRIES - 1); in ns_init_card()
572 ns_rsqe_init(card->rsq.base + j); in ns_init_card()
573 writel(0x00000000, card->membase + RSQH); in ns_init_card()
574 writel(ALIGN(card->rsq.dma, NS_RSQ_ALIGNMENT), card->membase + RSQB); in ns_init_card()
575 PRINTK("nicstar%d: RSQ base at 0x%p.\n", i, card->rsq.base); in ns_init_card()
578 card->scq1 = NULL; in ns_init_card()
579 card->scq2 = NULL; in ns_init_card()
580 card->scq0 = get_scq(card, VBR_SCQSIZE, NS_VRSCD0); in ns_init_card()
581 if (card->scq0 == NULL) { in ns_init_card()
587 u32d[0] = scq_virt_to_bus(card->scq0, card->scq0->base); in ns_init_card()
594 card->scq0->scd = NS_VRSCD0; in ns_init_card()
595 PRINTK("nicstar%d: VBR-SCQ0 base at 0x%p.\n", i, card->scq0->base); in ns_init_card()
598 card->tst_addr = NS_TST0; in ns_init_card()
599 card->tst_free_entries = NS_TST_NUM_ENTRIES; in ns_init_card()
610 card->tste2vc[j] = NULL; in ns_init_card()
611 writel(NS_TST0 << 2, card->membase + TSTB); in ns_init_card()
622 for (j = 0; j < card->rct_size; j++) in ns_init_card()
625 memset(card->vcmap, 0, sizeof(card->vcmap)); in ns_init_card()
628 card->scd2vc[j] = NULL; in ns_init_card()
631 card->sbnr.min = MIN_SB; in ns_init_card()
632 card->sbnr.init = NUM_SB; in ns_init_card()
633 card->sbnr.max = MAX_SB; in ns_init_card()
634 card->lbnr.min = MIN_LB; in ns_init_card()
635 card->lbnr.init = NUM_LB; in ns_init_card()
636 card->lbnr.max = MAX_LB; in ns_init_card()
637 card->iovnr.min = MIN_IOVB; in ns_init_card()
638 card->iovnr.init = NUM_IOVB; in ns_init_card()
639 card->iovnr.max = MAX_IOVB; in ns_init_card()
640 card->hbnr.min = MIN_HB; in ns_init_card()
641 card->hbnr.init = NUM_HB; in ns_init_card()
642 card->hbnr.max = MAX_HB; in ns_init_card()
644 card->sm_handle = NULL; in ns_init_card()
645 card->sm_addr = 0x00000000; in ns_init_card()
646 card->lg_handle = NULL; in ns_init_card()
647 card->lg_addr = 0x00000000; in ns_init_card()
649 card->efbie = 1; /* To prevent push_rxbufs from enabling the interrupt */ in ns_init_card()
651 idr_init(&card->idr); in ns_init_card()
653 /* Pre-allocate some huge buffers */ in ns_init_card()
654 skb_queue_head_init(&card->hbpool.queue); in ns_init_card()
655 card->hbpool.count = 0; in ns_init_card()
668 skb_queue_tail(&card->hbpool.queue, hb); in ns_init_card()
669 card->hbpool.count++; in ns_init_card()
673 skb_queue_head_init(&card->lbpool.queue); in ns_init_card()
674 card->lbpool.count = 0; /* Not used */ in ns_init_card()
687 skb_queue_tail(&card->lbpool.queue, lb); in ns_init_card()
692 card->rcbuf = lb; in ns_init_card()
693 card->rawcell = (struct ns_rcqe *) lb->data; in ns_init_card()
694 card->rawch = NS_PRV_DMA(lb); in ns_init_card()
699 ns_stat_lfbqc_get(readl(card->membase + STAT))) < card->lbnr.min) { in ns_init_card()
709 skb_queue_head_init(&card->sbpool.queue); in ns_init_card()
710 card->sbpool.count = 0; /* Not used */ in ns_init_card()
723 skb_queue_tail(&card->sbpool.queue, sb); in ns_init_card()
729 ns_stat_sfbqc_get(readl(card->membase + STAT))) < card->sbnr.min) { in ns_init_card()
739 skb_queue_head_init(&card->iovpool.queue); in ns_init_card()
740 card->iovpool.count = 0; in ns_init_card()
753 skb_queue_tail(&card->iovpool.queue, iovb); in ns_init_card()
754 card->iovpool.count++; in ns_init_card()
758 if (card->rct_size == 4096) in ns_init_card()
760 else /* (card->rct_size == 16384) */ in ns_init_card()
763 card->efbie = 1; in ns_init_card()
766 card->atmdev = atm_dev_register("nicstar", &card->pcidev->dev, &atm_ops, in ns_init_card()
767 -1, NULL); in ns_init_card()
768 if (card->atmdev == NULL) { in ns_init_card()
775 if (mac[i] == NULL || !mac_pton(mac[i], card->atmdev->esi)) { in ns_init_card()
776 nicstar_read_eprom(card->membase, NICSTAR_EPROM_MAC_ADDR_OFFSET, in ns_init_card()
777 card->atmdev->esi, 6); in ns_init_card()
778 if (ether_addr_equal(card->atmdev->esi, "\x00\x00\x00\x00\x00\x00")) { in ns_init_card()
779 nicstar_read_eprom(card->membase, in ns_init_card()
781 card->atmdev->esi, 6); in ns_init_card()
785 printk("nicstar%d: MAC address %pM\n", i, card->atmdev->esi); in ns_init_card()
787 card->atmdev->dev_data = card; in ns_init_card()
788 card->atmdev->ci_range.vpi_bits = card->vpibits; in ns_init_card()
789 card->atmdev->ci_range.vci_bits = card->vcibits; in ns_init_card()
790 card->atmdev->link_rate = card->max_pcr; in ns_init_card()
791 card->atmdev->phy = NULL; in ns_init_card()
794 if (card->max_pcr == ATM_OC3_PCR) in ns_init_card()
795 suni_init(card->atmdev); in ns_init_card()
799 if (card->max_pcr == ATM_25_PCR) in ns_init_card()
800 idt77105_init(card->atmdev); in ns_init_card()
803 if (card->atmdev->phy && card->atmdev->phy->start) in ns_init_card()
804 card->atmdev->phy->start(card->atmdev); in ns_init_card()
808 NS_CFG_PHYIE, card->membase + CFG); in ns_init_card()
818 writel(0x00000000, card->membase + CFG); in ns_init_card_error()
822 while ((iovb = skb_dequeue(&card->iovpool.queue)) != NULL) in ns_init_card_error()
827 while ((sb = skb_dequeue(&card->sbpool.queue)) != NULL) in ns_init_card_error()
829 free_scq(card, card->scq0, NULL); in ns_init_card_error()
833 while ((lb = skb_dequeue(&card->lbpool.queue)) != NULL) in ns_init_card_error()
838 while ((hb = skb_dequeue(&card->hbpool.queue)) != NULL) in ns_init_card_error()
842 dma_free_coherent(&card->pcidev->dev, NS_RSQSIZE + NS_RSQ_ALIGNMENT, in ns_init_card_error()
843 card->rsq.org, card->rsq.dma); in ns_init_card_error()
846 dma_free_coherent(&card->pcidev->dev, NS_TSQSIZE + NS_TSQ_ALIGNMENT, in ns_init_card_error()
847 card->tsq.org, card->tsq.dma); in ns_init_card_error()
850 free_irq(card->pcidev->irq, card); in ns_init_card_error()
853 iounmap(card->membase); in ns_init_card_error()
856 pci_disable_device(card->pcidev); in ns_init_card_error()
871 scq->org = dma_alloc_coherent(&card->pcidev->dev, in get_scq()
872 2 * size, &scq->dma, GFP_KERNEL); in get_scq()
873 if (!scq->org) { in get_scq()
877 scq->skb = kcalloc(size / NS_SCQE_SIZE, sizeof(*scq->skb), in get_scq()
879 if (!scq->skb) { in get_scq()
880 dma_free_coherent(&card->pcidev->dev, in get_scq()
881 2 * size, scq->org, scq->dma); in get_scq()
885 scq->num_entries = size / NS_SCQE_SIZE; in get_scq()
886 scq->base = PTR_ALIGN(scq->org, size); in get_scq()
887 scq->next = scq->base; in get_scq()
888 scq->last = scq->base + (scq->num_entries - 1); in get_scq()
889 scq->tail = scq->last; in get_scq()
890 scq->scd = scd; in get_scq()
891 scq->tbd_count = 0; in get_scq()
892 init_waitqueue_head(&scq->scqfull_waitq); in get_scq()
893 scq->full = 0; in get_scq()
894 spin_lock_init(&scq->lock); in get_scq()
904 if (scq->num_entries == VBR_SCQ_NUM_ENTRIES) in free_scq()
905 for (i = 0; i < scq->num_entries; i++) { in free_scq()
906 if (scq->skb[i] != NULL) { in free_scq()
907 vcc = ATM_SKB(scq->skb[i])->vcc; in free_scq()
908 if (vcc->pop != NULL) in free_scq()
909 vcc->pop(vcc, scq->skb[i]); in free_scq()
911 dev_kfree_skb_any(scq->skb[i]); in free_scq()
918 for (i = 0; i < scq->num_entries; i++) in free_scq()
919 dev_kfree_skb_any(scq->skb[i]); in free_scq()
921 for (i = 0; i < scq->num_entries; i++) { in free_scq()
922 if (scq->skb[i] != NULL) { in free_scq()
923 if (vcc->pop != NULL) in free_scq()
924 vcc->pop(vcc, scq->skb[i]); in free_scq()
926 dev_kfree_skb_any(scq->skb[i]); in free_scq()
930 kfree(scq->skb); in free_scq()
931 dma_free_coherent(&card->pcidev->dev, in free_scq()
932 2 * (scq->num_entries == VBR_SCQ_NUM_ENTRIES ? in free_scq()
934 scq->org, scq->dma); in free_scq()
952 addr1 = dma_map_single(&card->pcidev->dev, in push_rxbufs()
953 skb->data, in push_rxbufs()
962 card->index); in push_rxbufs()
965 stat = readl(card->membase + STAT); in push_rxbufs()
966 card->sbfqc = ns_stat_sfbqc_get(stat); in push_rxbufs()
967 card->lbfqc = ns_stat_lfbqc_get(stat); in push_rxbufs()
970 if (card->sm_addr) { in push_rxbufs()
971 addr2 = card->sm_addr; in push_rxbufs()
972 handle2 = card->sm_handle; in push_rxbufs()
973 card->sm_addr = 0x00000000; in push_rxbufs()
974 card->sm_handle = NULL; in push_rxbufs()
977 card->sm_addr = addr1; in push_rxbufs()
978 card->sm_handle = handle1; in push_rxbufs()
984 if (card->lg_addr) { in push_rxbufs()
985 addr2 = card->lg_addr; in push_rxbufs()
986 handle2 = card->lg_handle; in push_rxbufs()
987 card->lg_addr = 0x00000000; in push_rxbufs()
988 card->lg_handle = NULL; in push_rxbufs()
991 card->lg_addr = addr1; in push_rxbufs()
992 card->lg_handle = handle1; in push_rxbufs()
999 if (card->sbfqc >= card->sbnr.max) { in push_rxbufs()
1000 skb_unlink(handle1, &card->sbpool.queue); in push_rxbufs()
1002 skb_unlink(handle2, &card->sbpool.queue); in push_rxbufs()
1006 card->sbfqc += 2; in push_rxbufs()
1009 if (card->lbfqc >= card->lbnr.max) { in push_rxbufs()
1010 skb_unlink(handle1, &card->lbpool.queue); in push_rxbufs()
1012 skb_unlink(handle2, &card->lbpool.queue); in push_rxbufs()
1016 card->lbfqc += 2; in push_rxbufs()
1019 id1 = idr_alloc(&card->idr, handle1, 0, 0, GFP_ATOMIC); in push_rxbufs()
1023 id2 = idr_alloc(&card->idr, handle2, 0, 0, GFP_ATOMIC); in push_rxbufs()
1027 spin_lock_irqsave(&card->res_lock, flags); in push_rxbufs()
1029 writel(addr2, card->membase + DR3); in push_rxbufs()
1030 writel(id2, card->membase + DR2); in push_rxbufs()
1031 writel(addr1, card->membase + DR1); in push_rxbufs()
1032 writel(id1, card->membase + DR0); in push_rxbufs()
1034 card->membase + CMD); in push_rxbufs()
1035 spin_unlock_irqrestore(&card->res_lock, flags); in push_rxbufs()
1038 card->index, in push_rxbufs()
1043 if (!card->efbie && card->sbfqc >= card->sbnr.min && in push_rxbufs()
1044 card->lbfqc >= card->lbnr.min) { in push_rxbufs()
1045 card->efbie = 1; in push_rxbufs()
1046 writel((readl(card->membase + CFG) | NS_CFG_EFBIE), in push_rxbufs()
1047 card->membase + CFG); in push_rxbufs()
1062 dev = card->atmdev; in ns_irq_handler()
1063 card->intcnt++; in ns_irq_handler()
1065 PRINTK("nicstar%d: NICStAR generated an interrupt\n", card->index); in ns_irq_handler()
1067 spin_lock_irqsave(&card->int_lock, flags); in ns_irq_handler()
1069 stat_r = readl(card->membase + STAT); in ns_irq_handler()
1073 TXPRINTK("nicstar%d: TSI interrupt\n", card->index); in ns_irq_handler()
1075 writel(NS_STAT_TSIF, card->membase + STAT); in ns_irq_handler()
1078 /* Incomplete CS-PDU has been transmitted */ in ns_irq_handler()
1080 writel(NS_STAT_TXICP, card->membase + STAT); in ns_irq_handler()
1081 TXPRINTK("nicstar%d: Incomplete CS-PDU transmitted.\n", in ns_irq_handler()
1082 card->index); in ns_irq_handler()
1087 writel(NS_STAT_TSQF, card->membase + STAT); in ns_irq_handler()
1088 PRINTK("nicstar%d: TSQ full.\n", card->index); in ns_irq_handler()
1094 writel(NS_STAT_TMROF, card->membase + STAT); in ns_irq_handler()
1095 PRINTK("nicstar%d: Timer overflow.\n", card->index); in ns_irq_handler()
1100 writel(NS_STAT_PHYI, card->membase + STAT); in ns_irq_handler()
1101 PRINTK("nicstar%d: PHY interrupt.\n", card->index); in ns_irq_handler()
1102 if (dev->phy && dev->phy->interrupt) { in ns_irq_handler()
1103 dev->phy->interrupt(dev); in ns_irq_handler()
1109 writel(NS_STAT_SFBQF, card->membase + STAT); in ns_irq_handler()
1111 card->index); in ns_irq_handler()
1116 writel(NS_STAT_LFBQF, card->membase + STAT); in ns_irq_handler()
1118 card->index); in ns_irq_handler()
1123 writel(NS_STAT_RSQF, card->membase + STAT); in ns_irq_handler()
1124 printk("nicstar%d: RSQ full.\n", card->index); in ns_irq_handler()
1128 /* Complete CS-PDU received */ in ns_irq_handler()
1130 RXPRINTK("nicstar%d: End of CS-PDU received.\n", card->index); in ns_irq_handler()
1132 writel(NS_STAT_EOPDU, card->membase + STAT); in ns_irq_handler()
1137 writel(NS_STAT_RAWCF, card->membase + STAT); in ns_irq_handler()
1140 card->index); in ns_irq_handler()
1145 while (readl(card->membase + RAWCT) != card->rawch) { in ns_irq_handler()
1147 if (ns_rcqe_islast(card->rawcell)) { in ns_irq_handler()
1150 oldbuf = card->rcbuf; in ns_irq_handler()
1151 card->rcbuf = idr_find(&card->idr, in ns_irq_handler()
1152 ns_rcqe_nextbufhandle(card->rawcell)); in ns_irq_handler()
1153 card->rawch = NS_PRV_DMA(card->rcbuf); in ns_irq_handler()
1154 card->rawcell = (struct ns_rcqe *) in ns_irq_handler()
1155 card->rcbuf->data; in ns_irq_handler()
1158 card->rawch += NS_RCQE_SIZE; in ns_irq_handler()
1159 card->rawcell++; in ns_irq_handler()
1169 writel(NS_STAT_SFBQE, card->membase + STAT); in ns_irq_handler()
1171 card->index); in ns_irq_handler()
1172 for (i = 0; i < card->sbnr.min; i++) { in ns_irq_handler()
1175 writel(readl(card->membase + CFG) & in ns_irq_handler()
1176 ~NS_CFG_EFBIE, card->membase + CFG); in ns_irq_handler()
1177 card->efbie = 0; in ns_irq_handler()
1181 skb_queue_tail(&card->sbpool.queue, sb); in ns_irq_handler()
1185 card->sbfqc = i; in ns_irq_handler()
1194 writel(NS_STAT_LFBQE, card->membase + STAT); in ns_irq_handler()
1196 card->index); in ns_irq_handler()
1197 for (i = 0; i < card->lbnr.min; i++) { in ns_irq_handler()
1200 writel(readl(card->membase + CFG) & in ns_irq_handler()
1201 ~NS_CFG_EFBIE, card->membase + CFG); in ns_irq_handler()
1202 card->efbie = 0; in ns_irq_handler()
1206 skb_queue_tail(&card->lbpool.queue, lb); in ns_irq_handler()
1210 card->lbfqc = i; in ns_irq_handler()
1216 writel(NS_STAT_RSQAF, card->membase + STAT); in ns_irq_handler()
1217 RXPRINTK("nicstar%d: RSQ almost full.\n", card->index); in ns_irq_handler()
1221 spin_unlock_irqrestore(&card->int_lock, flags); in ns_irq_handler()
1222 PRINTK("nicstar%d: end of interrupt service\n", card->index); in ns_irq_handler()
1240 short vpi = vcc->vpi; in ns_open()
1241 int vci = vcc->vci; in ns_open()
1243 card = (ns_dev *) vcc->dev->dev_data; in ns_open()
1244 PRINTK("nicstar%d: opening vpi.vci %d.%d \n", card->index, (int)vpi, in ns_open()
1246 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) { in ns_open()
1247 PRINTK("nicstar%d: unsupported AAL.\n", card->index); in ns_open()
1248 return -EINVAL; in ns_open()
1251 vc = &(card->vcmap[vpi << card->vcibits | vci]); in ns_open()
1252 vcc->dev_data = vc; in ns_open()
1255 if (vcc->qos.txtp.traffic_class != ATM_NONE && vc->tx) in ns_open()
1257 if (vcc->qos.rxtp.traffic_class != ATM_NONE && vc->rx) in ns_open()
1260 printk("nicstar%d: %s vci already in use.\n", card->index, in ns_open()
1262 return -EINVAL; in ns_open()
1265 set_bit(ATM_VF_ADDR, &vcc->flags); in ns_open()
1270 if (!test_bit(ATM_VF_PARTIAL, &vcc->flags)) { in ns_open()
1273 set_bit(ATM_VF_PARTIAL, &vcc->flags); in ns_open()
1274 if (vcc->qos.txtp.traffic_class == ATM_CBR) { in ns_open()
1276 if (vcc->qos.txtp.max_pcr == 0 && vcc->qos.txtp.pcr == 0 in ns_open()
1277 && vcc->qos.txtp.min_pcr == 0) { in ns_open()
1280 card->index); in ns_open()
1281 clear_bit(ATM_VF_PARTIAL, &vcc->flags); in ns_open()
1282 clear_bit(ATM_VF_ADDR, &vcc->flags); in ns_open()
1283 return -EINVAL; in ns_open()
1286 tcr = atm_pcr_goal(&(vcc->qos.txtp)); in ns_open()
1287 tcra = tcr >= 0 ? tcr : -tcr; in ns_open()
1290 card->index, vcc->qos.txtp.max_pcr); in ns_open()
1295 modl = tmpl % card->max_pcr; in ns_open()
1297 n = (int)(tmpl / card->max_pcr); in ns_open()
1303 (card->tst_free_entries - in ns_open()
1307 card->index); in ns_open()
1308 clear_bit(ATM_VF_PARTIAL, &vcc->flags); in ns_open()
1309 clear_bit(ATM_VF_ADDR, &vcc->flags); in ns_open()
1310 return -EINVAL; in ns_open()
1317 card->index); in ns_open()
1318 clear_bit(ATM_VF_PARTIAL, &vcc->flags); in ns_open()
1319 clear_bit(ATM_VF_ADDR, &vcc->flags); in ns_open()
1320 return -EINVAL; in ns_open()
1323 if (n > (card->tst_free_entries - NS_TST_RESERVED)) { in ns_open()
1326 card->index); in ns_open()
1327 clear_bit(ATM_VF_PARTIAL, &vcc->flags); in ns_open()
1328 clear_bit(ATM_VF_ADDR, &vcc->flags); in ns_open()
1329 return -EINVAL; in ns_open()
1331 card->tst_free_entries -= n; in ns_open()
1334 card->index, n); in ns_open()
1336 if (card->scd2vc[frscdi] == NULL) { in ns_open()
1337 card->scd2vc[frscdi] = vc; in ns_open()
1343 ("nicstar%d: no SCD available for CBR channel.\n", in ns_open()
1344 card->index); in ns_open()
1345 card->tst_free_entries += n; in ns_open()
1346 clear_bit(ATM_VF_PARTIAL, &vcc->flags); in ns_open()
1347 clear_bit(ATM_VF_ADDR, &vcc->flags); in ns_open()
1348 return -EBUSY; in ns_open()
1351 vc->cbr_scd = NS_FRSCD + frscdi * NS_FRSCD_SIZE; in ns_open()
1353 scq = get_scq(card, CBR_SCQSIZE, vc->cbr_scd); in ns_open()
1356 card->index); in ns_open()
1357 card->scd2vc[frscdi] = NULL; in ns_open()
1358 card->tst_free_entries += n; in ns_open()
1359 clear_bit(ATM_VF_PARTIAL, &vcc->flags); in ns_open()
1360 clear_bit(ATM_VF_ADDR, &vcc->flags); in ns_open()
1361 return -ENOMEM; in ns_open()
1363 vc->scq = scq; in ns_open()
1364 u32d[0] = scq_virt_to_bus(scq, scq->base); in ns_open()
1368 ns_write_sram(card, vc->cbr_scd, u32d, 4); in ns_open()
1371 } else if (vcc->qos.txtp.traffic_class == ATM_UBR) { in ns_open()
1372 vc->cbr_scd = 0x00000000; in ns_open()
1373 vc->scq = card->scq0; in ns_open()
1376 if (vcc->qos.txtp.traffic_class != ATM_NONE) { in ns_open()
1377 vc->tx = 1; in ns_open()
1378 vc->tx_vcc = vcc; in ns_open()
1379 vc->tbd_count = 0; in ns_open()
1381 if (vcc->qos.rxtp.traffic_class != ATM_NONE) { in ns_open()
1384 vc->rx = 1; in ns_open()
1385 vc->rx_vcc = vcc; in ns_open()
1386 vc->rx_iov = NULL; in ns_open()
1389 if (vcc->qos.aal == ATM_AAL5) in ns_open()
1391 else /* vcc->qos.aal == ATM_AAL0 */ in ns_open()
1398 (vpi << card->vcibits | vci) * in ns_open()
1404 set_bit(ATM_VF_READY, &vcc->flags); in ns_open()
1415 vc = vcc->dev_data; in ns_close()
1416 card = vcc->dev->dev_data; in ns_close()
1417 PRINTK("nicstar%d: closing vpi.vci %d.%d \n", card->index, in ns_close()
1418 (int)vcc->vpi, vcc->vci); in ns_close()
1420 clear_bit(ATM_VF_READY, &vcc->flags); in ns_close()
1422 if (vcc->qos.rxtp.traffic_class != ATM_NONE) { in ns_close()
1428 (vcc->vpi << card->vcibits | vcc->vci) * NS_RCT_ENTRY_SIZE; in ns_close()
1429 spin_lock_irqsave(&card->res_lock, flags); in ns_close()
1432 card->membase + CMD); in ns_close()
1433 spin_unlock_irqrestore(&card->res_lock, flags); in ns_close()
1435 vc->rx = 0; in ns_close()
1436 if (vc->rx_iov != NULL) { in ns_close()
1440 stat = readl(card->membase + STAT); in ns_close()
1441 card->sbfqc = ns_stat_sfbqc_get(stat); in ns_close()
1442 card->lbfqc = ns_stat_lfbqc_get(stat); in ns_close()
1446 card->index); in ns_close()
1447 iovb = vc->rx_iov; in ns_close()
1448 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data, in ns_close()
1451 spin_lock_irqsave(&card->int_lock, flags); in ns_close()
1453 spin_unlock_irqrestore(&card->int_lock, flags); in ns_close()
1454 vc->rx_iov = NULL; in ns_close()
1458 if (vcc->qos.txtp.traffic_class != ATM_NONE) { in ns_close()
1459 vc->tx = 0; in ns_close()
1462 if (vcc->qos.txtp.traffic_class == ATM_CBR) { in ns_close()
1467 scq = vc->scq; in ns_close()
1470 spin_lock_irqsave(&scq->lock, flags); in ns_close()
1471 scqep = scq->next; in ns_close()
1472 if (scqep == scq->base) in ns_close()
1473 scqep = scq->last; in ns_close()
1475 scqep--; in ns_close()
1476 if (scqep == scq->tail) { in ns_close()
1477 spin_unlock_irqrestore(&scq->lock, flags); in ns_close()
1482 if (!ns_scqe_is_tsr(scqep) && scq->tail != scq->next) { in ns_close()
1489 scdi = (vc->cbr_scd - NS_FRSCD) / NS_FRSCD_SIZE; in ns_close()
1490 scqi = scq->next - scq->base; in ns_close()
1494 *scq->next = tsr; in ns_close()
1496 scq->skb[index] = NULL; in ns_close()
1497 if (scq->next == scq->last) in ns_close()
1498 scq->next = scq->base; in ns_close()
1500 scq->next++; in ns_close()
1501 data = scq_virt_to_bus(scq, scq->next); in ns_close()
1502 ns_write_sram(card, scq->scd, &data, 1); in ns_close()
1504 spin_unlock_irqrestore(&scq->lock, flags); in ns_close()
1511 if (card->tste2vc[i] == vc) { in ns_close()
1512 ns_write_sram(card, card->tst_addr + i, &data, in ns_close()
1514 card->tste2vc[i] = NULL; in ns_close()
1515 card->tst_free_entries++; in ns_close()
1519 card->scd2vc[(vc->cbr_scd - NS_FRSCD) / NS_FRSCD_SIZE] = NULL; in ns_close()
1520 free_scq(card, vc->scq, vcc); in ns_close()
1524 if (vcc->qos.txtp.traffic_class != ATM_NONE) { in ns_close()
1526 scq_info *scq = card->scq0; in ns_close()
1528 spin_lock_irqsave(&scq->lock, flags); in ns_close()
1530 for (i = 0; i < scq->num_entries; i++) { in ns_close()
1531 if (scq->skb[i] && ATM_SKB(scq->skb[i])->vcc == vcc) { in ns_close()
1532 ATM_SKB(scq->skb[i])->vcc = NULL; in ns_close()
1533 atm_return(vcc, scq->skb[i]->truesize); in ns_close()
1539 spin_unlock_irqrestore(&scq->lock, flags); in ns_close()
1542 vcc->dev_data = NULL; in ns_close()
1543 clear_bit(ATM_VF_PARTIAL, &vcc->flags); in ns_close()
1544 clear_bit(ATM_VF_ADDR, &vcc->flags); in ns_close()
1549 stat = readl(card->membase + STAT); in ns_close()
1550 cfg = readl(card->membase + CFG); in ns_close()
1554 card->tsq.base, card->tsq.next, in ns_close()
1555 card->tsq.last, readl(card->membase + TSQT)); in ns_close()
1558 card->rsq.base, card->rsq.next, in ns_close()
1559 card->rsq.last, readl(card->membase + RSQT)); in ns_close()
1561 card->efbie ? "enabled" : "disabled"); in ns_close()
1563 ns_stat_sfbqc_get(stat), card->sbpool.count, in ns_close()
1564 ns_stat_lfbqc_get(stat), card->lbpool.count); in ns_close()
1566 card->hbpool.count, card->iovpool.count); in ns_close()
1582 new_tst = card->tst_addr; in fill_tst()
1587 if (card->tste2vc[e] == NULL) in fill_tst()
1591 printk("nicstar%d: No free TST entries found. \n", card->index); in fill_tst()
1597 data = ns_tste_make(NS_TST_OPCODE_FIXED, vc->cbr_scd); in fill_tst()
1600 if (cl >= NS_TST_NUM_ENTRIES && card->tste2vc[e] == NULL) { in fill_tst()
1601 card->tste2vc[e] = vc; in fill_tst()
1603 cl -= NS_TST_NUM_ENTRIES; in fill_tst()
1604 r--; in fill_tst()
1617 ns_write_sram(card, card->tst_addr + NS_TST_NUM_ENTRIES, &data, 1); in fill_tst()
1618 card->tst_addr = new_tst; in fill_tst()
1630 card = vcc->dev->dev_data; in _ns_send()
1631 TXPRINTK("nicstar%d: ns_send() called.\n", card->index); in _ns_send()
1632 if ((vc = (vc_map *) vcc->dev_data) == NULL) { in _ns_send()
1633 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n", in _ns_send()
1634 card->index); in _ns_send()
1635 atomic_inc(&vcc->stats->tx_err); in _ns_send()
1637 return -EINVAL; in _ns_send()
1640 if (!vc->tx) { in _ns_send()
1641 printk("nicstar%d: Trying to transmit on a non-tx VC.\n", in _ns_send()
1642 card->index); in _ns_send()
1643 atomic_inc(&vcc->stats->tx_err); in _ns_send()
1645 return -EINVAL; in _ns_send()
1648 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) { in _ns_send()
1650 card->index); in _ns_send()
1651 atomic_inc(&vcc->stats->tx_err); in _ns_send()
1653 return -EINVAL; in _ns_send()
1656 if (skb_shinfo(skb)->nr_frags != 0) { in _ns_send()
1657 printk("nicstar%d: No scatter-gather yet.\n", card->index); in _ns_send()
1658 atomic_inc(&vcc->stats->tx_err); in _ns_send()
1660 return -EINVAL; in _ns_send()
1663 ATM_SKB(skb)->vcc = vcc; in _ns_send()
1665 NS_PRV_DMA(skb) = dma_map_single(&card->pcidev->dev, skb->data, in _ns_send()
1666 skb->len, DMA_TO_DEVICE); in _ns_send()
1668 if (vcc->qos.aal == ATM_AAL5) { in _ns_send()
1669 buflen = (skb->len + 47 + 8) / 48 * 48; /* Multiple of 48 */ in _ns_send()
1672 scqe.word_3 = cpu_to_le32(skb->len); in _ns_send()
1674 ns_tbd_mkword_4(0, (u32) vcc->vpi, (u32) vcc->vci, 0, in _ns_send()
1675 ATM_SKB(skb)-> in _ns_send()
1678 } else { /* (vcc->qos.aal == ATM_AAL0) */ in _ns_send()
1684 if (*skb->data & 0x02) /* Payload type 1 - end of pdu */ in _ns_send()
1687 cpu_to_le32(*((u32 *) skb->data) & ~NS_TBD_VC_MASK); in _ns_send()
1690 cpu_to_le32((((u32) vcc-> in _ns_send()
1691 vpi) << NS_TBD_VPI_SHIFT | ((u32) vcc-> in _ns_send()
1696 if (vcc->qos.txtp.traffic_class == ATM_CBR) { in _ns_send()
1698 scq = ((vc_map *) vcc->dev_data)->scq; in _ns_send()
1702 scq = card->scq0; in _ns_send()
1706 atomic_inc(&vcc->stats->tx_err); in _ns_send()
1707 dma_unmap_single(&card->pcidev->dev, NS_PRV_DMA(skb), skb->len, in _ns_send()
1710 return -EIO; in _ns_send()
1712 atomic_inc(&vcc->stats->tx); in _ns_send()
1737 spin_lock_irqsave(&scq->lock, flags); in push_scqe()
1738 while (scq->tail == scq->next) { in push_scqe()
1740 spin_unlock_irqrestore(&scq->lock, flags); in push_scqe()
1741 printk("nicstar%d: Error pushing TBD.\n", card->index); in push_scqe()
1745 scq->full = 1; in push_scqe()
1746 wait_event_interruptible_lock_irq_timeout(scq->scqfull_waitq, in push_scqe()
1747 scq->tail != scq->next, in push_scqe()
1748 scq->lock, in push_scqe()
1751 if (scq->full) { in push_scqe()
1752 spin_unlock_irqrestore(&scq->lock, flags); in push_scqe()
1754 card->index); in push_scqe()
1758 *scq->next = *tbd; in push_scqe()
1759 index = (int)(scq->next - scq->base); in push_scqe()
1760 scq->skb[index] = skb; in push_scqe()
1762 card->index, skb, index); in push_scqe()
1764 card->index, le32_to_cpu(tbd->word_1), le32_to_cpu(tbd->word_2), in push_scqe()
1765 le32_to_cpu(tbd->word_3), le32_to_cpu(tbd->word_4), in push_scqe()
1766 scq->next); in push_scqe()
1767 if (scq->next == scq->last) in push_scqe()
1768 scq->next = scq->base; in push_scqe()
1770 scq->next++; in push_scqe()
1772 vc->tbd_count++; in push_scqe()
1773 if (scq->num_entries == VBR_SCQ_NUM_ENTRIES) { in push_scqe()
1774 scq->tbd_count++; in push_scqe()
1779 if (vc->tbd_count >= MAX_TBD_PER_VC in push_scqe()
1780 || scq->tbd_count >= MAX_TBD_PER_SCQ) { in push_scqe()
1783 while (scq->tail == scq->next) { in push_scqe()
1785 data = scq_virt_to_bus(scq, scq->next); in push_scqe()
1786 ns_write_sram(card, scq->scd, &data, 1); in push_scqe()
1787 spin_unlock_irqrestore(&scq->lock, flags); in push_scqe()
1789 card->index); in push_scqe()
1793 scq->full = 1; in push_scqe()
1796 wait_event_interruptible_lock_irq_timeout(scq->scqfull_waitq, in push_scqe()
1797 scq->tail != scq->next, in push_scqe()
1798 scq->lock, in push_scqe()
1802 if (!scq->full) { in push_scqe()
1807 scdi = (vc->cbr_scd - NS_FRSCD) / NS_FRSCD_SIZE; in push_scqe()
1808 scqi = scq->next - scq->base; in push_scqe()
1813 *scq->next = tsr; in push_scqe()
1815 scq->skb[index] = NULL; in push_scqe()
1818 card->index, le32_to_cpu(tsr.word_1), in push_scqe()
1820 le32_to_cpu(tsr.word_4), scq->next); in push_scqe()
1821 if (scq->next == scq->last) in push_scqe()
1822 scq->next = scq->base; in push_scqe()
1824 scq->next++; in push_scqe()
1825 vc->tbd_count = 0; in push_scqe()
1826 scq->tbd_count = 0; in push_scqe()
1829 card->index); in push_scqe()
1831 data = scq_virt_to_bus(scq, scq->next); in push_scqe()
1832 ns_write_sram(card, scq->scd, &data, 1); in push_scqe()
1834 spin_unlock_irqrestore(&scq->lock, flags); in push_scqe()
1848 if (card->tsq.next == card->tsq.last) in process_tsq()
1849 one_ahead = card->tsq.base; in process_tsq()
1851 one_ahead = card->tsq.next + 1; in process_tsq()
1853 if (one_ahead == card->tsq.last) in process_tsq()
1854 two_ahead = card->tsq.base; in process_tsq()
1858 while (!ns_tsi_isempty(card->tsq.next) || !ns_tsi_isempty(one_ahead) || in process_tsq()
1865 while (ns_tsi_isempty(card->tsq.next)) { in process_tsq()
1866 if (card->tsq.next == card->tsq.last) in process_tsq()
1867 card->tsq.next = card->tsq.base; in process_tsq()
1869 card->tsq.next++; in process_tsq()
1872 if (!ns_tsi_tmrof(card->tsq.next)) { in process_tsq()
1873 scdi = ns_tsi_getscdindex(card->tsq.next); in process_tsq()
1875 scq = card->scq0; in process_tsq()
1877 if (card->scd2vc[scdi] == NULL) { in process_tsq()
1880 card->index); in process_tsq()
1881 ns_tsi_init(card->tsq.next); in process_tsq()
1884 scq = card->scd2vc[scdi]->scq; in process_tsq()
1886 drain_scq(card, scq, ns_tsi_getscqpos(card->tsq.next)); in process_tsq()
1887 scq->full = 0; in process_tsq()
1888 wake_up_interruptible(&(scq->scqfull_waitq)); in process_tsq()
1891 ns_tsi_init(card->tsq.next); in process_tsq()
1892 previous = card->tsq.next; in process_tsq()
1893 if (card->tsq.next == card->tsq.last) in process_tsq()
1894 card->tsq.next = card->tsq.base; in process_tsq()
1896 card->tsq.next++; in process_tsq()
1898 if (card->tsq.next == card->tsq.last) in process_tsq()
1899 one_ahead = card->tsq.base; in process_tsq()
1901 one_ahead = card->tsq.next + 1; in process_tsq()
1903 if (one_ahead == card->tsq.last) in process_tsq()
1904 two_ahead = card->tsq.base; in process_tsq()
1910 writel(PTR_DIFF(previous, card->tsq.base), in process_tsq()
1911 card->membase + TSQH); in process_tsq()
1922 card->index, scq, pos); in drain_scq()
1923 if (pos >= scq->num_entries) { in drain_scq()
1924 printk("nicstar%d: Bad index on drain_scq().\n", card->index); in drain_scq()
1928 spin_lock_irqsave(&scq->lock, flags); in drain_scq()
1929 i = (int)(scq->tail - scq->base); in drain_scq()
1930 if (++i == scq->num_entries) in drain_scq()
1933 skb = scq->skb[i]; in drain_scq()
1935 card->index, skb, i); in drain_scq()
1937 dma_unmap_single(&card->pcidev->dev, in drain_scq()
1939 skb->len, in drain_scq()
1941 vcc = ATM_SKB(skb)->vcc; in drain_scq()
1942 if (vcc && vcc->pop != NULL) { in drain_scq()
1943 vcc->pop(vcc, skb); in drain_scq()
1947 scq->skb[i] = NULL; in drain_scq()
1949 if (++i == scq->num_entries) in drain_scq()
1952 scq->tail = scq->base + pos; in drain_scq()
1953 spin_unlock_irqrestore(&scq->lock, flags); in drain_scq()
1960 if (!ns_rsqe_valid(card->rsq.next)) in process_rsq()
1963 dequeue_rx(card, card->rsq.next); in process_rsq()
1964 ns_rsqe_init(card->rsq.next); in process_rsq()
1965 previous = card->rsq.next; in process_rsq()
1966 if (card->rsq.next == card->rsq.last) in process_rsq()
1967 card->rsq.next = card->rsq.base; in process_rsq()
1969 card->rsq.next++; in process_rsq()
1970 } while (ns_rsqe_valid(card->rsq.next)); in process_rsq()
1971 writel(PTR_DIFF(previous, card->rsq.base), card->membase + RSQH); in process_rsq()
1987 stat = readl(card->membase + STAT); in dequeue_rx()
1988 card->sbfqc = ns_stat_sfbqc_get(stat); in dequeue_rx()
1989 card->lbfqc = ns_stat_lfbqc_get(stat); in dequeue_rx()
1991 id = le32_to_cpu(rsqe->buffer_handle); in dequeue_rx()
1992 skb = idr_remove(&card->idr, id); in dequeue_rx()
1995 "nicstar%d: skb not found!\n", card->index); in dequeue_rx()
1998 dma_sync_single_for_cpu(&card->pcidev->dev, in dequeue_rx()
2003 dma_unmap_single(&card->pcidev->dev, in dequeue_rx()
2010 if (vpi >= 1UL << card->vpibits || vci >= 1UL << card->vcibits) { in dequeue_rx()
2011 printk("nicstar%d: SDU received for out-of-range vc %d.%d.\n", in dequeue_rx()
2012 card->index, vpi, vci); in dequeue_rx()
2017 vc = &(card->vcmap[vpi << card->vcibits | vci]); in dequeue_rx()
2018 if (!vc->rx) { in dequeue_rx()
2019 RXPRINTK("nicstar%d: SDU received on non-rx vc %d.%d.\n", in dequeue_rx()
2020 card->index, vpi, vci); in dequeue_rx()
2025 vcc = vc->rx_vcc; in dequeue_rx()
2027 if (vcc->qos.aal == ATM_AAL0) { in dequeue_rx()
2032 cell = skb->data; in dequeue_rx()
2033 for (i = ns_rsqe_cellcount(rsqe); i; i--) { in dequeue_rx()
2038 card->index); in dequeue_rx()
2039 atomic_add(i, &vcc->stats->rx_drop); in dequeue_rx()
2042 if (!atm_charge(vcc, sb->truesize)) { in dequeue_rx()
2045 card->index); in dequeue_rx()
2046 atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */ in dequeue_rx()
2051 *((u32 *) sb->data) = le32_to_cpu(rsqe->word_1) << 4 | in dequeue_rx()
2054 *((u32 *) sb->data) |= 0x00000002; in dequeue_rx()
2058 ATM_SKB(sb)->vcc = vcc; in dequeue_rx()
2060 vcc->push(vcc, sb); in dequeue_rx()
2061 atomic_inc(&vcc->stats->rx); in dequeue_rx()
2071 if ((iovb = vc->rx_iov) == NULL) { in dequeue_rx()
2072 iovb = skb_dequeue(&(card->iovpool.queue)); in dequeue_rx()
2077 card->index); in dequeue_rx()
2078 atomic_inc(&vcc->stats->rx_drop); in dequeue_rx()
2083 } else if (--card->iovpool.count < card->iovnr.min) { in dequeue_rx()
2088 skb_queue_tail(&card->iovpool.queue, new_iovb); in dequeue_rx()
2089 card->iovpool.count++; in dequeue_rx()
2092 vc->rx_iov = iovb; in dequeue_rx()
2094 iovb->len = 0; in dequeue_rx()
2095 iovb->data = iovb->head; in dequeue_rx()
2101 printk("nicstar%d: received too big AAL5 SDU.\n", card->index); in dequeue_rx()
2102 atomic_inc(&vcc->stats->rx_err); in dequeue_rx()
2103 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data, in dequeue_rx()
2106 iovb->len = 0; in dequeue_rx()
2107 iovb->data = iovb->head; in dequeue_rx()
2110 iov = &((struct iovec *)iovb->data)[NS_PRV_IOVCNT(iovb)++]; in dequeue_rx()
2111 iov->iov_base = (void *)skb; in dequeue_rx()
2112 iov->iov_len = ns_rsqe_cellcount(rsqe) * 48; in dequeue_rx()
2113 iovb->len += iov->iov_len; in dequeue_rx()
2120 card->index); in dequeue_rx()
2122 atomic_inc(&vcc->stats->rx_err); in dequeue_rx()
2124 vc->rx_iov = NULL; in dequeue_rx()
2133 card->index); in dequeue_rx()
2135 atomic_inc(&vcc->stats->rx_err); in dequeue_rx()
2136 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data, in dequeue_rx()
2138 vc->rx_iov = NULL; in dequeue_rx()
2148 (skb->data + iov->iov_len - 6); in dequeue_rx()
2152 len + 8 > iovb->len || len + (47 + 8) < iovb->len) { in dequeue_rx()
2153 printk("nicstar%d: AAL5 CRC error", card->index); in dequeue_rx()
2154 if (len + 8 > iovb->len || len + (47 + 8) < iovb->len) in dequeue_rx()
2155 printk(" - PDU size mismatch.\n"); in dequeue_rx()
2158 atomic_inc(&vcc->stats->rx_err); in dequeue_rx()
2159 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data, in dequeue_rx()
2161 vc->rx_iov = NULL; in dequeue_rx()
2170 if (!atm_charge(vcc, skb->truesize)) { in dequeue_rx()
2172 atomic_inc(&vcc->stats->rx_drop); in dequeue_rx()
2176 ATM_SKB(skb)->vcc = vcc; in dequeue_rx()
2178 vcc->push(vcc, skb); in dequeue_rx()
2179 atomic_inc(&vcc->stats->rx); in dequeue_rx()
2184 sb = (struct sk_buff *)(iov - 1)->iov_base; in dequeue_rx()
2188 if (!atm_charge(vcc, sb->truesize)) { in dequeue_rx()
2190 atomic_inc(&vcc->stats->rx_drop); in dequeue_rx()
2194 ATM_SKB(sb)->vcc = vcc; in dequeue_rx()
2196 vcc->push(vcc, sb); in dequeue_rx()
2197 atomic_inc(&vcc->stats->rx); in dequeue_rx()
2204 if (!atm_charge(vcc, skb->truesize)) { in dequeue_rx()
2206 atomic_inc(&vcc->stats->rx_drop); in dequeue_rx()
2210 skb_copy_from_linear_data(sb, skb->data, in dequeue_rx()
2212 skb_put(skb, len - NS_SMBUFSIZE); in dequeue_rx()
2213 ATM_SKB(skb)->vcc = vcc; in dequeue_rx()
2215 vcc->push(vcc, skb); in dequeue_rx()
2216 atomic_inc(&vcc->stats->rx); in dequeue_rx()
2229 hb = skb_dequeue(&(card->hbpool.queue)); in dequeue_rx()
2236 card->index); in dequeue_rx()
2237 atomic_inc(&vcc->stats->rx_drop); in dequeue_rx()
2240 iovb->data, in dequeue_rx()
2242 vc->rx_iov = NULL; in dequeue_rx()
2245 } else if (card->hbpool.count < card->hbnr.min) { in dequeue_rx()
2250 skb_queue_tail(&card->hbpool. in dequeue_rx()
2252 card->hbpool.count++; in dequeue_rx()
2256 } else if (--card->hbpool.count < card->hbnr.min) { in dequeue_rx()
2261 skb_queue_tail(&card->hbpool.queue, in dequeue_rx()
2263 card->hbpool.count++; in dequeue_rx()
2265 if (card->hbpool.count < card->hbnr.min) { in dequeue_rx()
2271 skb_queue_tail(&card->hbpool. in dequeue_rx()
2273 card->hbpool.count++; in dequeue_rx()
2278 iov = (struct iovec *)iovb->data; in dequeue_rx()
2280 if (!atm_charge(vcc, hb->truesize)) { in dequeue_rx()
2283 if (card->hbpool.count < card->hbnr.max) { in dequeue_rx()
2284 skb_queue_tail(&card->hbpool.queue, hb); in dequeue_rx()
2285 card->hbpool.count++; in dequeue_rx()
2288 atomic_inc(&vcc->stats->rx_drop); in dequeue_rx()
2291 sb = (struct sk_buff *)iov->iov_base; in dequeue_rx()
2292 skb_copy_from_linear_data(sb, hb->data, in dequeue_rx()
2293 iov->iov_len); in dequeue_rx()
2294 skb_put(hb, iov->iov_len); in dequeue_rx()
2295 remaining = len - iov->iov_len; in dequeue_rx()
2302 lb = (struct sk_buff *)iov->iov_base; in dequeue_rx()
2304 min_t(int, remaining, iov->iov_len); in dequeue_rx()
2310 remaining -= tocopy; in dequeue_rx()
2314 if (remaining != 0 || hb->len != len) in dequeue_rx()
2317 card->index); in dequeue_rx()
2319 ATM_SKB(hb)->vcc = vcc; in dequeue_rx()
2321 vcc->push(vcc, hb); in dequeue_rx()
2322 atomic_inc(&vcc->stats->rx); in dequeue_rx()
2326 vc->rx_iov = NULL; in dequeue_rx()
2336 card->index); in recycle_rx_buf()
2344 while (count-- > 0) in recycle_iovec_rx_bufs()
2345 recycle_rx_buf(card, (struct sk_buff *)(iov++)->iov_base); in recycle_iovec_rx_bufs()
2350 if (card->iovpool.count < card->iovnr.max) { in recycle_iov_buf()
2351 skb_queue_tail(&card->iovpool.queue, iovb); in recycle_iov_buf()
2352 card->iovpool.count++; in recycle_iov_buf()
2359 skb_unlink(sb, &card->sbpool.queue); in dequeue_sm_buf()
2360 if (card->sbfqc < card->sbnr.init) { in dequeue_sm_buf()
2364 skb_queue_tail(&card->sbpool.queue, new_sb); in dequeue_sm_buf()
2369 if (card->sbfqc < card->sbnr.init) in dequeue_sm_buf()
2374 skb_queue_tail(&card->sbpool.queue, new_sb); in dequeue_sm_buf()
2383 skb_unlink(lb, &card->lbpool.queue); in dequeue_lg_buf()
2384 if (card->lbfqc < card->lbnr.init) { in dequeue_lg_buf()
2388 skb_queue_tail(&card->lbpool.queue, new_lb); in dequeue_lg_buf()
2393 if (card->lbfqc < card->lbnr.init) in dequeue_lg_buf()
2398 skb_queue_tail(&card->lbpool.queue, new_lb); in dequeue_lg_buf()
2412 card = (ns_dev *) dev->dev_data; in ns_proc_read()
2413 stat = readl(card->membase + STAT); in ns_proc_read()
2414 if (!left--) in ns_proc_read()
2416 if (!left--) in ns_proc_read()
2418 ns_stat_sfbqc_get(stat), card->sbnr.min, in ns_proc_read()
2419 card->sbnr.init, card->sbnr.max); in ns_proc_read()
2420 if (!left--) in ns_proc_read()
2422 ns_stat_lfbqc_get(stat), card->lbnr.min, in ns_proc_read()
2423 card->lbnr.init, card->lbnr.max); in ns_proc_read()
2424 if (!left--) in ns_proc_read()
2426 card->hbpool.count, card->hbnr.min, in ns_proc_read()
2427 card->hbnr.init, card->hbnr.max); in ns_proc_read()
2428 if (!left--) in ns_proc_read()
2430 card->iovpool.count, card->iovnr.min, in ns_proc_read()
2431 card->iovnr.init, card->iovnr.max); in ns_proc_read()
2432 if (!left--) { in ns_proc_read()
2435 sprintf(page, "Interrupt counter: %u \n", card->intcnt); in ns_proc_read()
2436 card->intcnt = 0; in ns_proc_read()
2443 if (card->max_pcr == ATM_25_PCR && !left--) { in ns_proc_read()
2450 card->membase + CMD); in ns_proc_read()
2452 phy_regs[i] = readl(card->membase + DR0) & 0x000000FF; in ns_proc_read()
2459 #endif /* 0 - Dump 25.6 Mbps PHY registers */ in ns_proc_read()
2462 if (left-- < NS_TST_NUM_ENTRIES) { in ns_proc_read()
2463 if (card->tste2vc[left + 1] == NULL) in ns_proc_read()
2464 return sprintf(page, "%5d - VBR/UBR \n", left + 1); in ns_proc_read()
2466 return sprintf(page, "%5d - %d %d \n", left + 1, in ns_proc_read()
2467 card->tste2vc[left + 1]->tx_vcc->vpi, in ns_proc_read()
2468 card->tste2vc[left + 1]->tx_vcc->vci); in ns_proc_read()
2481 card = dev->dev_data; in ns_ioctl()
2485 (pl.buftype, &((pool_levels __user *) arg)->buftype)) in ns_ioctl()
2486 return -EFAULT; in ns_ioctl()
2490 ns_stat_sfbqc_get(readl(card->membase + STAT)); in ns_ioctl()
2491 pl.level.min = card->sbnr.min; in ns_ioctl()
2492 pl.level.init = card->sbnr.init; in ns_ioctl()
2493 pl.level.max = card->sbnr.max; in ns_ioctl()
2498 ns_stat_lfbqc_get(readl(card->membase + STAT)); in ns_ioctl()
2499 pl.level.min = card->lbnr.min; in ns_ioctl()
2500 pl.level.init = card->lbnr.init; in ns_ioctl()
2501 pl.level.max = card->lbnr.max; in ns_ioctl()
2505 pl.count = card->hbpool.count; in ns_ioctl()
2506 pl.level.min = card->hbnr.min; in ns_ioctl()
2507 pl.level.init = card->hbnr.init; in ns_ioctl()
2508 pl.level.max = card->hbnr.max; in ns_ioctl()
2512 pl.count = card->iovpool.count; in ns_ioctl()
2513 pl.level.min = card->iovnr.min; in ns_ioctl()
2514 pl.level.init = card->iovnr.init; in ns_ioctl()
2515 pl.level.max = card->iovnr.max; in ns_ioctl()
2519 return -ENOIOCTLCMD; in ns_ioctl()
2525 return -EFAULT; in ns_ioctl()
2529 return -EPERM; in ns_ioctl()
2531 return -EFAULT; in ns_ioctl()
2534 return -EINVAL; in ns_ioctl()
2536 return -EINVAL; in ns_ioctl()
2540 return -EINVAL; in ns_ioctl()
2541 card->sbnr.min = pl.level.min; in ns_ioctl()
2542 card->sbnr.init = pl.level.init; in ns_ioctl()
2543 card->sbnr.max = pl.level.max; in ns_ioctl()
2548 return -EINVAL; in ns_ioctl()
2549 card->lbnr.min = pl.level.min; in ns_ioctl()
2550 card->lbnr.init = pl.level.init; in ns_ioctl()
2551 card->lbnr.max = pl.level.max; in ns_ioctl()
2556 return -EINVAL; in ns_ioctl()
2557 card->hbnr.min = pl.level.min; in ns_ioctl()
2558 card->hbnr.init = pl.level.init; in ns_ioctl()
2559 card->hbnr.max = pl.level.max; in ns_ioctl()
2564 return -EINVAL; in ns_ioctl()
2565 card->iovnr.min = pl.level.min; in ns_ioctl()
2566 card->iovnr.init = pl.level.init; in ns_ioctl()
2567 card->iovnr.max = pl.level.max; in ns_ioctl()
2571 return -EINVAL; in ns_ioctl()
2578 return -EPERM; in ns_ioctl()
2582 while (card->sbfqc < card->sbnr.init) { in ns_ioctl()
2587 return -ENOMEM; in ns_ioctl()
2589 skb_queue_tail(&card->sbpool.queue, sb); in ns_ioctl()
2596 while (card->lbfqc < card->lbnr.init) { in ns_ioctl()
2601 return -ENOMEM; in ns_ioctl()
2603 skb_queue_tail(&card->lbpool.queue, lb); in ns_ioctl()
2610 while (card->hbpool.count > card->hbnr.init) { in ns_ioctl()
2613 spin_lock_irqsave(&card->int_lock, flags); in ns_ioctl()
2614 hb = skb_dequeue(&card->hbpool.queue); in ns_ioctl()
2615 card->hbpool.count--; in ns_ioctl()
2616 spin_unlock_irqrestore(&card->int_lock, flags); in ns_ioctl()
2620 card->index); in ns_ioctl()
2625 while (card->hbpool.count < card->hbnr.init) { in ns_ioctl()
2630 return -ENOMEM; in ns_ioctl()
2632 spin_lock_irqsave(&card->int_lock, flags); in ns_ioctl()
2633 skb_queue_tail(&card->hbpool.queue, hb); in ns_ioctl()
2634 card->hbpool.count++; in ns_ioctl()
2635 spin_unlock_irqrestore(&card->int_lock, flags); in ns_ioctl()
2640 while (card->iovpool.count > card->iovnr.init) { in ns_ioctl()
2643 spin_lock_irqsave(&card->int_lock, flags); in ns_ioctl()
2644 iovb = skb_dequeue(&card->iovpool.queue); in ns_ioctl()
2645 card->iovpool.count--; in ns_ioctl()
2646 spin_unlock_irqrestore(&card->int_lock, flags); in ns_ioctl()
2650 card->index); in ns_ioctl()
2655 while (card->iovpool.count < card->iovnr.init) { in ns_ioctl()
2660 return -ENOMEM; in ns_ioctl()
2662 spin_lock_irqsave(&card->int_lock, flags); in ns_ioctl()
2663 skb_queue_tail(&card->iovpool.queue, iovb); in ns_ioctl()
2664 card->iovpool.count++; in ns_ioctl()
2665 spin_unlock_irqrestore(&card->int_lock, flags); in ns_ioctl()
2670 return -EINVAL; in ns_ioctl()
2676 if (dev->phy && dev->phy->ioctl) { in ns_ioctl()
2677 return dev->phy->ioctl(dev, cmd, arg); in ns_ioctl()
2679 printk("nicstar%d: %s == NULL \n", card->index, in ns_ioctl()
2680 dev->phy ? "dev->phy->ioctl" : "dev->phy"); in ns_ioctl()
2681 return -ENOIOCTLCMD; in ns_ioctl()
2703 if (!spin_trylock_irqsave(&card->int_lock, flags)) { in ns_poll()
2709 stat_r = readl(card->membase + STAT); in ns_poll()
2718 writel(stat_w, card->membase + STAT); in ns_poll()
2719 spin_unlock_irqrestore(&card->int_lock, flags); in ns_poll()
2731 card = dev->dev_data; in ns_phy_put()
2732 spin_lock_irqsave(&card->res_lock, flags); in ns_phy_put()
2734 writel((u32) value, card->membase + DR0); in ns_phy_put()
2736 card->membase + CMD); in ns_phy_put()
2737 spin_unlock_irqrestore(&card->res_lock, flags); in ns_phy_put()
2746 card = dev->dev_data; in ns_phy_get()
2747 spin_lock_irqsave(&card->res_lock, flags); in ns_phy_get()
2750 card->membase + CMD); in ns_phy_get()
2752 data = readl(card->membase + DR0) & 0x000000FF; in ns_phy_get()
2753 spin_unlock_irqrestore(&card->res_lock, flags); in ns_phy_get()