Lines Matching refs:dev

376 #define __kick_rx(dev)	writel(CR_RXE, dev->base + CR)  argument
378 #define kick_rx(dev) do { \ argument
380 if (test_and_clear_bit(0, &dev->rx_info.idle)) { \
382 writel(dev->rx_info.phy_descs + (4 * DESC_SIZE * dev->rx_info.next_rx), dev->base + RXDP); \
383 if (dev->rx_info.next_rx == dev->rx_info.next_empty) \
384 printk(KERN_DEBUG "%s: uh-oh: next_rx == next_empty???\n", dev->net_dev.name);\
385 __kick_rx(dev); \
481 #define start_tx_okay(dev) \ argument
482 (((NR_TX_DESC-2 + dev->tx_done_idx - dev->tx_free_idx) % NR_TX_DESC) > MIN_TX_DESC_FREE)
498 static inline void build_rx_desc(struct ns83820 *dev, u32 *desc, dma_addr_t link, dma_addr_t buf, u… in build_rx_desc() argument
507 #define nr_rx_empty(dev) ((NR_RX_DESC-2 + dev->rx_info.next_rx - dev->rx_info.next_empty) % NR_RX_D… argument
508 static inline int ns83820_add_rx_skb(struct ns83820 *dev, struct sk_buff *skb) in ns83820_add_rx_skb() argument
515 next_empty = dev->rx_info.next_empty; in ns83820_add_rx_skb()
518 if (unlikely(nr_rx_empty(dev) <= 2)) { in ns83820_add_rx_skb()
525 dev->rx_info.next_empty, in ns83820_add_rx_skb()
526 dev->rx_info.nr_used, in ns83820_add_rx_skb()
527 dev->rx_info.next_rx in ns83820_add_rx_skb()
531 sg = dev->rx_info.descs + (next_empty * DESC_SIZE); in ns83820_add_rx_skb()
532 if (unlikely(NULL != dev->rx_info.skbs[next_empty])) in ns83820_add_rx_skb()
534 dev->rx_info.skbs[next_empty] = skb; in ns83820_add_rx_skb()
536 dev->rx_info.next_empty = (next_empty + 1) % NR_RX_DESC; in ns83820_add_rx_skb()
538 buf = pci_map_single(dev->pci_dev, skb->tail, in ns83820_add_rx_skb()
540 build_rx_desc(dev, sg, 0, buf, cmdsts, 0); in ns83820_add_rx_skb()
542 if (likely(next_empty != dev->rx_info.next_rx)) in ns83820_add_rx_skb()
543dev->rx_info.descs[((NR_RX_DESC + next_empty - 1) % NR_RX_DESC) * DESC_SIZE] = cpu_to_le32(dev->rx… in ns83820_add_rx_skb()
548 static inline int rx_refill(struct ns83820 *dev, int gfp) in rx_refill() argument
553 if (unlikely(nr_rx_empty(dev) <= 2)) in rx_refill()
556 dprintk("rx_refill(%p)\n", dev); in rx_refill()
558 spin_lock_irqsave(&dev->rx_info.lock, flags); in rx_refill()
572 skb->dev = &dev->net_dev; in rx_refill()
574 spin_lock_irqsave(&dev->rx_info.lock, flags); in rx_refill()
575 res = ns83820_add_rx_skb(dev, skb); in rx_refill()
577 spin_unlock_irqrestore(&dev->rx_info.lock, flags); in rx_refill()
584 spin_unlock_irqrestore(&dev->rx_info.lock, flags); in rx_refill()
589 static void FASTCALL(rx_refill_atomic(struct ns83820 *dev));
590 static void fastcall rx_refill_atomic(struct ns83820 *dev) in rx_refill_atomic() argument
592 rx_refill(dev, GFP_ATOMIC); in rx_refill_atomic()
598 struct ns83820 *dev = _dev; in queue_refill() local
600 rx_refill(dev, GFP_KERNEL); in queue_refill()
601 if (dev->rx_info.up) in queue_refill()
602 kick_rx(dev); in queue_refill()
605 static inline void clear_rx_desc(struct ns83820 *dev, unsigned i) in clear_rx_desc() argument
607 build_rx_desc(dev, dev->rx_info.descs + (DESC_SIZE * i), 0, 0, CMDSTS_OWN, 0); in clear_rx_desc()
610 static void FASTCALL(phy_intr(struct ns83820 *dev));
611 static void fastcall phy_intr(struct ns83820 *dev) in phy_intr() argument
618 cfg = readl(dev->base + CFG) ^ SPDSTS_POLARITY; in phy_intr()
620 if (dev->CFG_cache & CFG_TBI_EN) { in phy_intr()
622 tbisr = readl(dev->base + TBISR); in phy_intr()
623 tanar = readl(dev->base + TANAR); in phy_intr()
624 tanlpar = readl(dev->base + TANLPAR); in phy_intr()
632 writel(readl(dev->base + TXCFG) in phy_intr()
634 dev->base + TXCFG); in phy_intr()
635 writel(readl(dev->base + RXCFG) | RXCFG_RX_FD, in phy_intr()
636 dev->base + RXCFG); in phy_intr()
638 writel(readl(dev->base + GPIOR) | GPIOR_GP1_OUT, in phy_intr()
639 dev->base + GPIOR); in phy_intr()
649 writel((readl(dev->base + TXCFG) in phy_intr()
651 dev->base + TXCFG); in phy_intr()
652 writel(readl(dev->base + RXCFG) & ~RXCFG_RX_FD, in phy_intr()
653 dev->base + RXCFG); in phy_intr()
655 writel(readl(dev->base + GPIOR) & ~GPIOR_GP1_OUT, in phy_intr()
656 dev->base + GPIOR); in phy_intr()
663 new_cfg = dev->CFG_cache & ~(CFG_SB | CFG_MODE_1000 | CFG_SPDSTS); in phy_intr()
677 ((new_cfg ^ dev->CFG_cache) & CFG_MODE_1000)) { in phy_intr()
678 writel(new_cfg, dev->base + CFG); in phy_intr()
679 dev->CFG_cache = new_cfg; in phy_intr()
682 dev->CFG_cache &= ~CFG_SPDSTS; in phy_intr()
683 dev->CFG_cache |= cfg & CFG_SPDSTS; in phy_intr()
689 && dev->linkstate != newlinkstate) { in phy_intr()
690 netif_start_queue(&dev->net_dev); in phy_intr()
691 netif_wake_queue(&dev->net_dev); in phy_intr()
693 dev->net_dev.name, in phy_intr()
697 && dev->linkstate != newlinkstate) { in phy_intr()
698 netif_stop_queue(&dev->net_dev); in phy_intr()
699 printk(KERN_INFO "%s: link now down.\n", dev->net_dev.name); in phy_intr()
702 dev->linkstate = newlinkstate; in phy_intr()
705 static int ns83820_setup_rx(struct ns83820 *dev) in ns83820_setup_rx() argument
710 dprintk("ns83820_setup_rx(%p)\n", dev); in ns83820_setup_rx()
712 dev->rx_info.idle = 1; in ns83820_setup_rx()
713 dev->rx_info.next_rx = 0; in ns83820_setup_rx()
714 dev->rx_info.next_rx_desc = dev->rx_info.descs; in ns83820_setup_rx()
715 dev->rx_info.next_empty = 0; in ns83820_setup_rx()
718 clear_rx_desc(dev, i); in ns83820_setup_rx()
720 writel(0, dev->base + RXDP_HI); in ns83820_setup_rx()
721 writel(dev->rx_info.phy_descs, dev->base + RXDP); in ns83820_setup_rx()
723 ret = rx_refill(dev, GFP_KERNEL); in ns83820_setup_rx()
727 spin_lock_irq(&dev->rx_info.lock); in ns83820_setup_rx()
729 writel(0x0001, dev->base + CCSR); in ns83820_setup_rx()
730 writel(0, dev->base + RFCR); in ns83820_setup_rx()
731 writel(0x7fc00000, dev->base + RFCR); in ns83820_setup_rx()
732 writel(0xffc00000, dev->base + RFCR); in ns83820_setup_rx()
734 dev->rx_info.up = 1; in ns83820_setup_rx()
736 phy_intr(dev); in ns83820_setup_rx()
739 spin_lock_irq(&dev->misc_lock); in ns83820_setup_rx()
740 dev->IMR_cache |= ISR_PHY; in ns83820_setup_rx()
741 dev->IMR_cache |= ISR_RXRCMP; in ns83820_setup_rx()
744 dev->IMR_cache |= ISR_RXORN; in ns83820_setup_rx()
745 dev->IMR_cache |= ISR_RXSOVR; in ns83820_setup_rx()
746 dev->IMR_cache |= ISR_RXDESC; in ns83820_setup_rx()
747 dev->IMR_cache |= ISR_RXIDLE; in ns83820_setup_rx()
748 dev->IMR_cache |= ISR_TXDESC; in ns83820_setup_rx()
749 dev->IMR_cache |= ISR_TXIDLE; in ns83820_setup_rx()
751 writel(dev->IMR_cache, dev->base + IMR); in ns83820_setup_rx()
752 writel(1, dev->base + IER); in ns83820_setup_rx()
753 spin_unlock_irq(&dev->misc_lock); in ns83820_setup_rx()
755 kick_rx(dev); in ns83820_setup_rx()
757 spin_unlock_irq(&dev->rx_info.lock); in ns83820_setup_rx()
762 static void ns83820_cleanup_rx(struct ns83820 *dev) in ns83820_cleanup_rx() argument
767 dprintk("ns83820_cleanup_rx(%p)\n", dev); in ns83820_cleanup_rx()
770 spin_lock_irqsave(&dev->misc_lock, flags); in ns83820_cleanup_rx()
771 dev->IMR_cache &= ~(ISR_RXOK | ISR_RXDESC | ISR_RXERR | ISR_RXEARLY | ISR_RXIDLE); in ns83820_cleanup_rx()
772 writel(dev->IMR_cache, dev->base + IMR); in ns83820_cleanup_rx()
773 spin_unlock_irqrestore(&dev->misc_lock, flags); in ns83820_cleanup_rx()
776 dev->rx_info.up = 0; in ns83820_cleanup_rx()
780 readl(dev->base + IMR); in ns83820_cleanup_rx()
783 writel(0, dev->base + RXDP_HI); in ns83820_cleanup_rx()
784 writel(0, dev->base + RXDP); in ns83820_cleanup_rx()
787 struct sk_buff *skb = dev->rx_info.skbs[i]; in ns83820_cleanup_rx()
788 dev->rx_info.skbs[i] = NULL; in ns83820_cleanup_rx()
789 clear_rx_desc(dev, i); in ns83820_cleanup_rx()
795 static void FASTCALL(ns83820_rx_kick(struct ns83820 *dev));
796 static void fastcall ns83820_rx_kick(struct ns83820 *dev) in ns83820_rx_kick() argument
799 if (dev->rx_info.up) { in ns83820_rx_kick()
800 rx_refill_atomic(dev); in ns83820_rx_kick()
801 kick_rx(dev); in ns83820_rx_kick()
805 if (dev->rx_info.up && nr_rx_empty(dev) > NR_RX_DESC*3/4) in ns83820_rx_kick()
806 schedule_task(&dev->tq_refill); in ns83820_rx_kick()
808 kick_rx(dev); in ns83820_rx_kick()
809 if (dev->rx_info.idle) in ns83820_rx_kick()
810 printk(KERN_DEBUG "%s: BAD\n", dev->net_dev.name); in ns83820_rx_kick()
816 static void FASTCALL(rx_irq(struct ns83820 *dev));
817 static void fastcall rx_irq(struct ns83820 *dev) in rx_irq() argument
819 struct rx_info *info = &dev->rx_info; in rx_irq()
825 dprintk("rx_irq(%p)\n", dev); in rx_irq()
827 readl(dev->base + RXDP), in rx_irq()
828 (long)(dev->rx_info.phy_descs), in rx_irq()
829 (int)dev->rx_info.next_rx, in rx_irq()
830 (dev->rx_info.descs + (DESC_SIZE * dev->rx_info.next_rx)), in rx_irq()
831 (int)dev->rx_info.next_empty, in rx_irq()
832 (dev->rx_info.descs + (DESC_SIZE * dev->rx_info.next_empty)) in rx_irq()
857 clear_rx_desc(dev, next_rx); in rx_irq()
859 pci_unmap_single(dev->pci_dev, bufptr, in rx_irq()
867 dev->stats.multicast ++; in rx_irq()
868 dev->stats.rx_packets ++; in rx_irq()
869 dev->stats.rx_bytes += len; in rx_irq()
875 skb->protocol = eth_type_trans(skb, &dev->net_dev); in rx_irq()
878 dev->stats.rx_dropped ++; in rx_irq()
901 struct ns83820 *dev = (void *)_dev; in rx_action() local
902 rx_irq(dev); in rx_action()
903 writel(ihr, dev->base + IHR); in rx_action()
905 spin_lock_irq(&dev->misc_lock); in rx_action()
906 dev->IMR_cache |= ISR_RXDESC; in rx_action()
907 writel(dev->IMR_cache, dev->base + IMR); in rx_action()
908 spin_unlock_irq(&dev->misc_lock); in rx_action()
910 rx_irq(dev); in rx_action()
911 ns83820_rx_kick(dev); in rx_action()
916 static inline void kick_tx(struct ns83820 *dev) in kick_tx() argument
919 dev, dev->tx_idx, dev->tx_free_idx); in kick_tx()
920 writel(CR_TXE, dev->base + CR); in kick_tx()
926 static void do_tx_done(struct ns83820 *dev) in do_tx_done() argument
930 spin_lock_irq(&dev->tx_lock); in do_tx_done()
932 dprintk("do_tx_done(%p)\n", dev); in do_tx_done()
933 tx_done_idx = dev->tx_done_idx; in do_tx_done()
934 desc = dev->tx_descs + (tx_done_idx * DESC_SIZE); in do_tx_done()
937 tx_done_idx, dev->tx_free_idx, le32_to_cpu(desc[DESC_CMDSTS])); in do_tx_done()
938 while ((tx_done_idx != dev->tx_free_idx) && in do_tx_done()
945 dev->stats.tx_errors ++; in do_tx_done()
947 dev->stats.tx_packets ++; in do_tx_done()
949 dev->stats.tx_bytes += cmdsts & 0xffff; in do_tx_done()
952 tx_done_idx, dev->tx_free_idx, cmdsts); in do_tx_done()
953 skb = dev->tx_skbs[tx_done_idx]; in do_tx_done()
954 dev->tx_skbs[tx_done_idx] = NULL; in do_tx_done()
960 pci_unmap_single(dev->pci_dev, in do_tx_done()
965 atomic_dec(&dev->nr_tx_skbs); in do_tx_done()
967 pci_unmap_page(dev->pci_dev, in do_tx_done()
973 dev->tx_done_idx = tx_done_idx; in do_tx_done()
976 desc = dev->tx_descs + (tx_done_idx * DESC_SIZE); in do_tx_done()
982 if (netif_queue_stopped(&dev->net_dev) && start_tx_okay(dev)) { in do_tx_done()
983 dprintk("start_queue(%p)\n", dev); in do_tx_done()
984 netif_start_queue(&dev->net_dev); in do_tx_done()
985 netif_wake_queue(&dev->net_dev); in do_tx_done()
987 spin_unlock_irq(&dev->tx_lock); in do_tx_done()
990 static void ns83820_cleanup_tx(struct ns83820 *dev) in ns83820_cleanup_tx() argument
995 struct sk_buff *skb = dev->tx_skbs[i]; in ns83820_cleanup_tx()
996 dev->tx_skbs[i] = NULL; in ns83820_cleanup_tx()
998 u32 *desc = dev->tx_descs + (i * DESC_SIZE); in ns83820_cleanup_tx()
999 pci_unmap_single(dev->pci_dev, in ns83820_cleanup_tx()
1004 atomic_dec(&dev->nr_tx_skbs); in ns83820_cleanup_tx()
1008 memset(dev->tx_descs, 0, NR_TX_DESC * DESC_SIZE * 4); in ns83820_cleanup_tx()
1019 struct ns83820 *dev = (struct ns83820 *)_dev; in ns83820_hard_start_xmit() local
1034 if (unlikely(dev->CFG_cache & CFG_LNKSTS)) { in ns83820_hard_start_xmit()
1035 netif_stop_queue(&dev->net_dev); in ns83820_hard_start_xmit()
1036 if (unlikely(dev->CFG_cache & CFG_LNKSTS)) in ns83820_hard_start_xmit()
1038 netif_start_queue(&dev->net_dev); in ns83820_hard_start_xmit()
1041 last_idx = free_idx = dev->tx_free_idx; in ns83820_hard_start_xmit()
1042 tx_done_idx = dev->tx_done_idx; in ns83820_hard_start_xmit()
1046 dprintk("stop_queue - not enough(%p)\n", dev); in ns83820_hard_start_xmit()
1047 netif_stop_queue(&dev->net_dev); in ns83820_hard_start_xmit()
1050 if (dev->tx_done_idx != tx_done_idx) { in ns83820_hard_start_xmit()
1051 dprintk("restart queue(%p)\n", dev); in ns83820_hard_start_xmit()
1052 netif_start_queue(&dev->net_dev); in ns83820_hard_start_xmit()
1058 if (free_idx == dev->tx_intr_idx) { in ns83820_hard_start_xmit()
1060 dev->tx_intr_idx = (dev->tx_intr_idx + NR_TX_DESC/4) % NR_TX_DESC; in ns83820_hard_start_xmit()
1065 dprintk("stop_queue - last entry(%p)\n", dev); in ns83820_hard_start_xmit()
1066 netif_stop_queue(&dev->net_dev); in ns83820_hard_start_xmit()
1085 buf = pci_map_single(dev->pci_dev, skb->data, len, PCI_DMA_TODEVICE); in ns83820_hard_start_xmit()
1087 first_desc = dev->tx_descs + (free_idx * DESC_SIZE); in ns83820_hard_start_xmit()
1090 volatile u32 *desc = dev->tx_descs + (free_idx * DESC_SIZE); in ns83820_hard_start_xmit()
1097 desc[DESC_LINK] = cpu_to_le32(dev->tx_phy_descs + (free_idx * DESC_SIZE * 4)); in ns83820_hard_start_xmit()
1115 buf = pci_map_page(dev->pci_dev, frag->page, in ns83820_hard_start_xmit()
1127 spin_lock_irq(&dev->tx_lock); in ns83820_hard_start_xmit()
1128 dev->tx_skbs[last_idx] = skb; in ns83820_hard_start_xmit()
1130 dev->tx_free_idx = free_idx; in ns83820_hard_start_xmit()
1131 atomic_inc(&dev->nr_tx_skbs); in ns83820_hard_start_xmit()
1132 spin_unlock_irq(&dev->tx_lock); in ns83820_hard_start_xmit()
1134 kick_tx(dev); in ns83820_hard_start_xmit()
1137 if (stopped && (dev->tx_done_idx != tx_done_idx) && start_tx_okay(dev)) in ns83820_hard_start_xmit()
1138 netif_start_queue(&dev->net_dev); in ns83820_hard_start_xmit()
1141 dev->net_dev.trans_start = jiffies; in ns83820_hard_start_xmit()
1145 static void ns83820_update_stats(struct ns83820 *dev) in ns83820_update_stats() argument
1147 u8 *base = dev->base; in ns83820_update_stats()
1150 dev->stats.rx_errors += readl(base + 0x60) & 0xffff; in ns83820_update_stats()
1151 dev->stats.rx_crc_errors += readl(base + 0x64) & 0xffff; in ns83820_update_stats()
1152 dev->stats.rx_missed_errors += readl(base + 0x68) & 0xffff; in ns83820_update_stats()
1153 dev->stats.rx_frame_errors += readl(base + 0x6c) & 0xffff; in ns83820_update_stats()
1155 dev->stats.rx_length_errors += readl(base + 0x74) & 0xffff; in ns83820_update_stats()
1156 dev->stats.rx_length_errors += readl(base + 0x78) & 0xffff; in ns83820_update_stats()
1160 dev->stats.tx_carrier_errors += readl(base + 0x88) & 0xff; in ns83820_update_stats()
1165 struct ns83820 *dev = (void *)_dev; in ns83820_get_stats() local
1168 spin_lock_irq(&dev->misc_lock); in ns83820_get_stats()
1169 ns83820_update_stats(dev); in ns83820_get_stats()
1170 spin_unlock_irq(&dev->misc_lock); in ns83820_get_stats()
1172 return &dev->stats; in ns83820_get_stats()
1175 static int ns83820_ethtool_ioctl (struct ns83820 *dev, void *useraddr) in ns83820_ethtool_ioctl() argument
1188 strcpy(info.bus_info, dev->pci_dev->slot_name); in ns83820_ethtool_ioctl()
1197 u32 cfg = readl(dev->base + CFG) ^ SPDSTS_POLARITY; in ns83820_ethtool_ioctl()
1217 struct ns83820 *dev = (struct ns83820 *)_dev; in ns83820_ioctl() local
1221 return ns83820_ethtool_ioctl(dev, (void *) rq->ifr_data); in ns83820_ioctl()
1228 static void ns83820_mib_isr(struct ns83820 *dev) in ns83820_mib_isr() argument
1230 spin_lock(&dev->misc_lock); in ns83820_mib_isr()
1231 ns83820_update_stats(dev); in ns83820_mib_isr()
1232 spin_unlock(&dev->misc_lock); in ns83820_mib_isr()
1235 static void ns83820_do_isr(struct ns83820 *dev, u32 isr);
1238 struct ns83820 *dev = data; in ns83820_irq() local
1240 dprintk("ns83820_irq(%p)\n", dev); in ns83820_irq()
1242 dev->ihr = 0; in ns83820_irq()
1244 isr = readl(dev->base + ISR); in ns83820_irq()
1246 ns83820_do_isr(dev, isr); in ns83820_irq()
1249 static void ns83820_do_isr(struct ns83820 *dev, u32 isr) in ns83820_do_isr() argument
1257 dev->rx_info.idle = 1; in ns83820_do_isr()
1259 ns83820_rx_kick(dev); in ns83820_do_isr()
1263 prefetch(dev->rx_info.next_rx_desc); in ns83820_do_isr()
1265 spin_lock_irq(&dev->misc_lock); in ns83820_do_isr()
1266 dev->IMR_cache &= ~(ISR_RXDESC | ISR_RXOK); in ns83820_do_isr()
1267 writel(dev->IMR_cache, dev->base + IMR); in ns83820_do_isr()
1268 spin_unlock_irq(&dev->misc_lock); in ns83820_do_isr()
1270 tasklet_schedule(&dev->rx_tasklet); in ns83820_do_isr()
1276 ns83820_rx_kick(dev); in ns83820_do_isr()
1280 dev->stats.rx_fifo_errors ++; in ns83820_do_isr()
1285 dev->stats.rx_fifo_errors ++; in ns83820_do_isr()
1288 if ((ISR_RXRCMP & isr) && dev->rx_info.up) in ns83820_do_isr()
1289 writel(CR_RXE, dev->base + CR); in ns83820_do_isr()
1293 txdp = readl(dev->base + TXDP); in ns83820_do_isr()
1295 txdp -= dev->tx_phy_descs; in ns83820_do_isr()
1296 dev->tx_idx = txdp / (DESC_SIZE * 4); in ns83820_do_isr()
1297 if (dev->tx_idx >= NR_TX_DESC) { in ns83820_do_isr()
1298 printk(KERN_ALERT "%s: BUG -- txdp out of range\n", dev->net_dev.name); in ns83820_do_isr()
1299 dev->tx_idx = 0; in ns83820_do_isr()
1306 if (dev->tx_idx != dev->tx_free_idx) in ns83820_do_isr()
1307 kick_tx(dev); in ns83820_do_isr()
1314 do_tx_done(dev); in ns83820_do_isr()
1318 if ((dev->tx_done_idx == dev->tx_free_idx) && in ns83820_do_isr()
1319 (dev->IMR_cache & ISR_TXOK)) { in ns83820_do_isr()
1320 spin_lock_irq(&dev->misc_lock); in ns83820_do_isr()
1321 dev->IMR_cache &= ~ISR_TXOK; in ns83820_do_isr()
1322 writel(dev->IMR_cache, dev->base + IMR); in ns83820_do_isr()
1323 spin_unlock_irq(&dev->misc_lock); in ns83820_do_isr()
1333 if ((ISR_TXIDLE & isr) && (dev->tx_done_idx != dev->tx_free_idx)) { in ns83820_do_isr()
1334 spin_lock_irq(&dev->misc_lock); in ns83820_do_isr()
1335 dev->IMR_cache |= ISR_TXOK; in ns83820_do_isr()
1336 writel(dev->IMR_cache, dev->base + IMR); in ns83820_do_isr()
1337 spin_unlock_irq(&dev->misc_lock); in ns83820_do_isr()
1342 ns83820_mib_isr(dev); in ns83820_do_isr()
1346 phy_intr(dev); in ns83820_do_isr()
1349 if (dev->ihr) in ns83820_do_isr()
1350 writel(dev->ihr, dev->base + IHR); in ns83820_do_isr()
1354 static void ns83820_do_reset(struct ns83820 *dev, u32 which) in ns83820_do_reset() argument
1357 writel(which, dev->base + CR); in ns83820_do_reset()
1360 } while (readl(dev->base + CR) & which); in ns83820_do_reset()
1366 struct ns83820 *dev = (struct ns83820 *)_dev; in ns83820_stop() local
1369 del_timer_sync(&dev->tx_watchdog); in ns83820_stop()
1372 writel(0, dev->base + IMR); in ns83820_stop()
1373 writel(0, dev->base + IER); in ns83820_stop()
1374 readl(dev->base + IER); in ns83820_stop()
1376 dev->rx_info.up = 0; in ns83820_stop()
1379 ns83820_do_reset(dev, CR_RST); in ns83820_stop()
1383 spin_lock_irq(&dev->misc_lock); in ns83820_stop()
1384 dev->IMR_cache &= ~(ISR_TXURN | ISR_TXIDLE | ISR_TXERR | ISR_TXDESC | ISR_TXOK); in ns83820_stop()
1385 spin_unlock_irq(&dev->misc_lock); in ns83820_stop()
1387 ns83820_cleanup_rx(dev); in ns83820_stop()
1388 ns83820_cleanup_tx(dev); in ns83820_stop()
1393 static void ns83820_do_isr(struct ns83820 *dev, u32 isr);
1396 struct ns83820 *dev = (struct ns83820 *)_dev; in ns83820_tx_timeout() local
1403 tx_done_idx = dev->tx_done_idx; in ns83820_tx_timeout()
1404 desc = dev->tx_descs + (tx_done_idx * DESC_SIZE); in ns83820_tx_timeout()
1407 dev->net_dev.name, in ns83820_tx_timeout()
1408 tx_done_idx, dev->tx_free_idx, le32_to_cpu(desc[DESC_CMDSTS])); in ns83820_tx_timeout()
1413 isr = readl(dev->base + ISR); in ns83820_tx_timeout()
1414 printk("irq: %08x imr: %08x\n", isr, dev->IMR_cache); in ns83820_tx_timeout()
1415 ns83820_do_isr(dev, isr); in ns83820_tx_timeout()
1419 do_tx_done(dev); in ns83820_tx_timeout()
1421 tx_done_idx = dev->tx_done_idx; in ns83820_tx_timeout()
1422 desc = dev->tx_descs + (tx_done_idx * DESC_SIZE); in ns83820_tx_timeout()
1425 dev->net_dev.name, in ns83820_tx_timeout()
1426 tx_done_idx, dev->tx_free_idx, le32_to_cpu(desc[DESC_CMDSTS])); in ns83820_tx_timeout()
1433 struct ns83820 *dev = (void *)data; in ns83820_tx_watch() local
1437 dev->tx_done_idx, dev->tx_free_idx, atomic_read(&dev->nr_tx_skbs) in ns83820_tx_watch()
1441 if (time_after(jiffies, dev->net_dev.trans_start + 1*HZ) && in ns83820_tx_watch()
1442 dev->tx_done_idx != dev->tx_free_idx) { in ns83820_tx_watch()
1444 dev->net_dev.name, in ns83820_tx_watch()
1445 dev->tx_done_idx, dev->tx_free_idx, in ns83820_tx_watch()
1446 atomic_read(&dev->nr_tx_skbs)); in ns83820_tx_watch()
1447 ns83820_tx_timeout(&dev->net_dev); in ns83820_tx_watch()
1450 mod_timer(&dev->tx_watchdog, jiffies + 2*HZ); in ns83820_tx_watch()
1455 struct ns83820 *dev = (struct ns83820 *)_dev; in ns83820_open() local
1462 writel(0, dev->base + PQCR); in ns83820_open()
1464 ret = ns83820_setup_rx(dev); in ns83820_open()
1468 memset(dev->tx_descs, 0, 4 * NR_TX_DESC * DESC_SIZE); in ns83820_open()
1470 dev->tx_descs[(i * DESC_SIZE) + DESC_LINK] in ns83820_open()
1472 dev->tx_phy_descs in ns83820_open()
1476 dev->tx_idx = 0; in ns83820_open()
1477 dev->tx_done_idx = 0; in ns83820_open()
1478 desc = dev->tx_phy_descs; in ns83820_open()
1479 writel(0, dev->base + TXDP_HI); in ns83820_open()
1480 writel(desc, dev->base + TXDP); in ns83820_open()
1482 init_timer(&dev->tx_watchdog); in ns83820_open()
1483 dev->tx_watchdog.data = (unsigned long)dev; in ns83820_open()
1484 dev->tx_watchdog.function = ns83820_tx_watch; in ns83820_open()
1485 mod_timer(&dev->tx_watchdog, jiffies + 2*HZ); in ns83820_open()
1487 netif_start_queue(&dev->net_dev); /* FIXME: wait for phy to come up */ in ns83820_open()
1496 static void ns83820_getmac(struct ns83820 *dev, u8 *mac) in ns83820_getmac() argument
1502 data = eeprom_readw(&dev->ee, 0xa + 2 - i); in ns83820_getmac()
1507 writel(i*2, dev->base + RFCR); in ns83820_getmac()
1508 data = readl(dev->base + RFDR); in ns83820_getmac()
1525 struct ns83820 *dev = (void *)_dev; in ns83820_set_multicast() local
1526 u8 *rfcr = dev->base + RFCR; in ns83820_set_multicast()
1531 if (dev->net_dev.flags & IFF_PROMISC) in ns83820_set_multicast()
1536 if (dev->net_dev.flags & IFF_ALLMULTI) in ns83820_set_multicast()
1541 spin_lock_irq(&dev->misc_lock); in ns83820_set_multicast()
1546 spin_unlock_irq(&dev->misc_lock); in ns83820_set_multicast()
1549 static void ns83820_run_bist(struct ns83820 *dev, const char *name, u32 enable, u32 done, u32 fail) in ns83820_run_bist() argument
1556 dprintk("%s: start %s\n", dev->net_dev.name, name); in ns83820_run_bist()
1560 writel(enable, dev->base + PTSCR); in ns83820_run_bist()
1563 status = readl(dev->base + PTSCR); in ns83820_run_bist()
1580 dev->net_dev.name, name, status, fail); in ns83820_run_bist()
1583 dev->net_dev.name, name, status); in ns83820_run_bist()
1585 dprintk("%s: done %s in %d loops\n", dev->net_dev.name, name, loops); in ns83820_run_bist()
1589 static void ns83820_mii_write_bit(struct ns83820 *dev, int bit) in ns83820_mii_write_bit() argument
1592 dev->MEAR_cache &= ~MEAR_MDC; in ns83820_mii_write_bit()
1593 writel(dev->MEAR_cache, dev->base + MEAR); in ns83820_mii_write_bit()
1594 readl(dev->base + MEAR); in ns83820_mii_write_bit()
1597 dev->MEAR_cache |= MEAR_MDDIR; in ns83820_mii_write_bit()
1599 dev->MEAR_cache |= MEAR_MDIO; in ns83820_mii_write_bit()
1601 dev->MEAR_cache &= ~MEAR_MDIO; in ns83820_mii_write_bit()
1604 writel(dev->MEAR_cache, dev->base + MEAR); in ns83820_mii_write_bit()
1605 readl(dev->base + MEAR); in ns83820_mii_write_bit()
1611 dev->MEAR_cache |= MEAR_MDC; in ns83820_mii_write_bit()
1612 writel(dev->MEAR_cache, dev->base + MEAR); in ns83820_mii_write_bit()
1613 readl(dev->base + MEAR); in ns83820_mii_write_bit()
1619 static int ns83820_mii_read_bit(struct ns83820 *dev) in ns83820_mii_read_bit() argument
1624 dev->MEAR_cache &= ~MEAR_MDC; in ns83820_mii_read_bit()
1625 dev->MEAR_cache &= ~MEAR_MDDIR; in ns83820_mii_read_bit()
1626 writel(dev->MEAR_cache, dev->base + MEAR); in ns83820_mii_read_bit()
1627 readl(dev->base + MEAR); in ns83820_mii_read_bit()
1633 bit = (readl(dev->base + MEAR) & MEAR_MDIO) ? 1 : 0; in ns83820_mii_read_bit()
1634 dev->MEAR_cache |= MEAR_MDC; in ns83820_mii_read_bit()
1635 writel(dev->MEAR_cache, dev->base + MEAR); in ns83820_mii_read_bit()
1643 static unsigned ns83820_mii_read_reg(struct ns83820 *dev, unsigned phy, unsigned reg) in ns83820_mii_read_reg() argument
1650 ns83820_mii_read_bit(dev); in ns83820_mii_read_reg()
1652 ns83820_mii_write_bit(dev, 0); /* start */ in ns83820_mii_read_reg()
1653 ns83820_mii_write_bit(dev, 1); in ns83820_mii_read_reg()
1654 ns83820_mii_write_bit(dev, 1); /* opcode read */ in ns83820_mii_read_reg()
1655 ns83820_mii_write_bit(dev, 0); in ns83820_mii_read_reg()
1659 ns83820_mii_write_bit(dev, phy & (0x10 >> i)); in ns83820_mii_read_reg()
1663 ns83820_mii_write_bit(dev, reg & (0x10 >> i)); in ns83820_mii_read_reg()
1665 ns83820_mii_read_bit(dev); /* turn around cycles */ in ns83820_mii_read_reg()
1666 ns83820_mii_read_bit(dev); in ns83820_mii_read_reg()
1671 data |= ns83820_mii_read_bit(dev); in ns83820_mii_read_reg()
1677 static unsigned ns83820_mii_write_reg(struct ns83820 *dev, unsigned phy, unsigned reg, unsigned dat… in ns83820_mii_write_reg() argument
1683 ns83820_mii_read_bit(dev); in ns83820_mii_write_reg()
1685 ns83820_mii_write_bit(dev, 0); /* start */ in ns83820_mii_write_reg()
1686 ns83820_mii_write_bit(dev, 1); in ns83820_mii_write_reg()
1687 ns83820_mii_write_bit(dev, 0); /* opcode read */ in ns83820_mii_write_reg()
1688 ns83820_mii_write_bit(dev, 1); in ns83820_mii_write_reg()
1692 ns83820_mii_write_bit(dev, phy & (0x10 >> i)); in ns83820_mii_write_reg()
1696 ns83820_mii_write_bit(dev, reg & (0x10 >> i)); in ns83820_mii_write_reg()
1698 ns83820_mii_read_bit(dev); /* turn around cycles */ in ns83820_mii_write_reg()
1699 ns83820_mii_read_bit(dev); in ns83820_mii_write_reg()
1703 ns83820_mii_write_bit(dev, (data >> (15 - i)) & 1); in ns83820_mii_write_reg()
1708 static void ns83820_probe_phy(struct ns83820 *dev) in ns83820_probe_phy() argument
1718 ns83820_mii_read_reg(dev, 1, 0x09); in ns83820_probe_phy()
1719 ns83820_mii_write_reg(dev, 1, 0x10, 0x0d3e); in ns83820_probe_phy()
1721 tmp = ns83820_mii_read_reg(dev, 1, 0x00); in ns83820_probe_phy()
1722 ns83820_mii_write_reg(dev, 1, 0x00, tmp | 0x8000); in ns83820_probe_phy()
1724 ns83820_mii_read_reg(dev, 1, 0x09); in ns83820_probe_phy()
1732 a = ns83820_mii_read_reg(dev, i, MII_PHYIDR1); in ns83820_probe_phy()
1733 b = ns83820_mii_read_reg(dev, i, MII_PHYIDR2); in ns83820_probe_phy()
1740 dev->net_dev.name, j, in ns83820_probe_phy()
1741 ns83820_mii_read_reg(dev, i, 0 + j), in ns83820_probe_phy()
1742 ns83820_mii_read_reg(dev, i, 1 + j), in ns83820_probe_phy()
1743 ns83820_mii_read_reg(dev, i, 2 + j), in ns83820_probe_phy()
1744 ns83820_mii_read_reg(dev, i, 3 + j) in ns83820_probe_phy()
1751 ns83820_mii_write_reg(dev, 1, 0x16, 0x000d); in ns83820_probe_phy()
1752 ns83820_mii_write_reg(dev, 1, 0x1e, 0x810e); in ns83820_probe_phy()
1753 a = ns83820_mii_read_reg(dev, 1, 0x1d); in ns83820_probe_phy()
1755 ns83820_mii_write_reg(dev, 1, 0x16, 0x000d); in ns83820_probe_phy()
1756 ns83820_mii_write_reg(dev, 1, 0x1e, 0x810e); in ns83820_probe_phy()
1757 b = ns83820_mii_read_reg(dev, 1, 0x1d); in ns83820_probe_phy()
1765 struct ns83820 *dev; in ns83820_init_one() local
1780 dev = (struct ns83820 *)alloc_etherdev((sizeof *dev) - (sizeof dev->net_dev)); in ns83820_init_one()
1782 if (!dev) in ns83820_init_one()
1785 spin_lock_init(&dev->rx_info.lock); in ns83820_init_one()
1786 spin_lock_init(&dev->tx_lock); in ns83820_init_one()
1787 spin_lock_init(&dev->misc_lock); in ns83820_init_one()
1788 dev->pci_dev = pci_dev; in ns83820_init_one()
1790 dev->ee.cache = &dev->MEAR_cache; in ns83820_init_one()
1791 dev->ee.lock = &dev->misc_lock; in ns83820_init_one()
1792 dev->net_dev.owner = THIS_MODULE; in ns83820_init_one()
1793 dev->net_dev.priv = dev; in ns83820_init_one()
1795 INIT_TQUEUE(&dev->tq_refill, queue_refill, dev); in ns83820_init_one()
1796 tasklet_init(&dev->rx_tasklet, rx_action, (unsigned long)dev); in ns83820_init_one()
1806 dev->base = ioremap_nocache(addr, PAGE_SIZE); in ns83820_init_one()
1807 dev->tx_descs = pci_alloc_consistent(pci_dev, in ns83820_init_one()
1808 4 * DESC_SIZE * NR_TX_DESC, &dev->tx_phy_descs); in ns83820_init_one()
1809 dev->rx_info.descs = pci_alloc_consistent(pci_dev, in ns83820_init_one()
1810 4 * DESC_SIZE * NR_RX_DESC, &dev->rx_info.phy_descs); in ns83820_init_one()
1812 if (!dev->base || !dev->tx_descs || !dev->rx_info.descs) in ns83820_init_one()
1816 dev->tx_descs, (long)dev->tx_phy_descs, in ns83820_init_one()
1817 dev->rx_info.descs, (long)dev->rx_info.phy_descs); in ns83820_init_one()
1820 writel(0, dev->base + IMR); in ns83820_init_one()
1821 writel(0, dev->base + IER); in ns83820_init_one()
1822 readl(dev->base + IER); in ns83820_init_one()
1824 dev->IMR_cache = 0; in ns83820_init_one()
1826 setup_ee_mem_bitbanger(&dev->ee, (long)dev->base + MEAR, 3, 2, 1, 0, in ns83820_init_one()
1830 dev->net_dev.name, dev); in ns83820_init_one()
1837 err = register_netdev(&dev->net_dev); in ns83820_init_one()
1844 dev->net_dev.name, le32_to_cpu(readl(dev->base + 0x22c)), in ns83820_init_one()
1847 dev->net_dev.open = ns83820_open; in ns83820_init_one()
1848 dev->net_dev.stop = ns83820_stop; in ns83820_init_one()
1849 dev->net_dev.hard_start_xmit = ns83820_hard_start_xmit; in ns83820_init_one()
1850 dev->net_dev.get_stats = ns83820_get_stats; in ns83820_init_one()
1851 dev->net_dev.change_mtu = ns83820_change_mtu; in ns83820_init_one()
1852 dev->net_dev.set_multicast_list = ns83820_set_multicast; in ns83820_init_one()
1853 dev->net_dev.do_ioctl = ns83820_ioctl; in ns83820_init_one()
1854 dev->net_dev.tx_timeout = ns83820_tx_timeout; in ns83820_init_one()
1855 dev->net_dev.watchdog_timeo = 5 * HZ; in ns83820_init_one()
1857 pci_set_drvdata(pci_dev, dev); in ns83820_init_one()
1859 ns83820_do_reset(dev, CR_RST); in ns83820_init_one()
1862 writel(PTSCR_RBIST_RST, dev->base + PTSCR); in ns83820_init_one()
1863 ns83820_run_bist(dev, "sram bist", PTSCR_RBIST_EN, in ns83820_init_one()
1865 ns83820_run_bist(dev, "eeprom bist", PTSCR_EEBIST_EN, 0, in ns83820_init_one()
1867 ns83820_run_bist(dev, "eeprom load", PTSCR_EELOAD_EN, 0, 0); in ns83820_init_one()
1870 dev->CFG_cache = readl(dev->base + CFG); in ns83820_init_one()
1872 if ((dev->CFG_cache & CFG_PCI64_DET)) { in ns83820_init_one()
1874 dev->net_dev.name); in ns83820_init_one()
1876 if (!(dev->CFG_cache & CFG_DATA64_EN)) in ns83820_init_one()
1878 dev->net_dev.name); in ns83820_init_one()
1880 dev->CFG_cache &= ~(CFG_DATA64_EN); in ns83820_init_one()
1882 dev->CFG_cache &= (CFG_TBI_EN | CFG_MRM_DIS | CFG_MWI_DIS | in ns83820_init_one()
1885 dev->CFG_cache |= CFG_PINT_DUPSTS | CFG_PINT_LNKSTS | CFG_PINT_SPDSTS | in ns83820_init_one()
1887 dev->CFG_cache |= CFG_REQALG; in ns83820_init_one()
1888 dev->CFG_cache |= CFG_POW; in ns83820_init_one()
1889 dev->CFG_cache |= CFG_TMRTEST; in ns83820_init_one()
1895 dev->CFG_cache |= CFG_M64ADDR; in ns83820_init_one()
1898 dev->CFG_cache |= CFG_T64ADDR; in ns83820_init_one()
1901 dev->CFG_cache &= ~CFG_BEM; in ns83820_init_one()
1904 if (dev->CFG_cache & CFG_TBI_EN) { in ns83820_init_one()
1906 dev->net_dev.name); in ns83820_init_one()
1907 writel(readl(dev->base + GPIOR) | 0x3e8, dev->base + GPIOR); in ns83820_init_one()
1910 writel(readl(dev->base + TANAR) in ns83820_init_one()
1912 dev->base + TANAR); in ns83820_init_one()
1916 dev->base + TBICR); in ns83820_init_one()
1917 writel(TBICR_MR_AN_ENABLE, dev->base + TBICR); in ns83820_init_one()
1918 dev->linkstate = LINK_AUTONEGOTIATE; in ns83820_init_one()
1920 dev->CFG_cache |= CFG_MODE_1000; in ns83820_init_one()
1923 writel(dev->CFG_cache, dev->base + CFG); in ns83820_init_one()
1924 dprintk("CFG: %08x\n", dev->CFG_cache); in ns83820_init_one()
1927 printk(KERN_INFO "%s: resetting phy\n", dev->net_dev.name); in ns83820_init_one()
1928 writel(dev->CFG_cache | CFG_PHY_RST, dev->base + CFG); in ns83820_init_one()
1931 writel(dev->CFG_cache, dev->base + CFG); in ns83820_init_one()
1937 if (readl(dev->base + SRR)) in ns83820_init_one()
1938 writel(readl(dev->base+0x20c) | 0xfe00, dev->base + 0x20c); in ns83820_init_one()
1950 dev->base + TXCFG); in ns83820_init_one()
1953 writel(0x000, dev->base + IHR); in ns83820_init_one()
1954 writel(0x100, dev->base + IHR); in ns83820_init_one()
1955 writel(0x000, dev->base + IHR); in ns83820_init_one()
1966 | (RXCFG_MXDMA512) | 0, dev->base + RXCFG); in ns83820_init_one()
1969 writel(0, dev->base + PQCR); in ns83820_init_one()
1983 writel(VRCR_IPEN | VRCR_VTDEN, dev->base + VRCR); in ns83820_init_one()
1986 writel(VTCR_PPCHK, dev->base + VTCR); in ns83820_init_one()
1992 dev->base + PCR); in ns83820_init_one()
1995 writel(0, dev->base + WCSR); in ns83820_init_one()
1997 ns83820_getmac(dev, dev->net_dev.dev_addr); in ns83820_init_one()
2000 dev->net_dev.features |= NETIF_F_SG; in ns83820_init_one()
2001 dev->net_dev.features |= NETIF_F_IP_CSUM; in ns83820_init_one()
2005 dev->net_dev.name); in ns83820_init_one()
2006 dev->net_dev.features |= NETIF_F_HIGHDMA; in ns83820_init_one()
2010 dev->net_dev.name, in ns83820_init_one()
2011 (unsigned)readl(dev->base + SRR) >> 8, in ns83820_init_one()
2012 (unsigned)readl(dev->base + SRR) & 0xff, in ns83820_init_one()
2013 dev->net_dev.dev_addr[0], dev->net_dev.dev_addr[1], in ns83820_init_one()
2014 dev->net_dev.dev_addr[2], dev->net_dev.dev_addr[3], in ns83820_init_one()
2015 dev->net_dev.dev_addr[4], dev->net_dev.dev_addr[5], in ns83820_init_one()
2017 (dev->net_dev.features & NETIF_F_HIGHDMA) ? "h,sg" : "sg" in ns83820_init_one()
2021 ns83820_probe_phy(dev); in ns83820_init_one()
2027 iounmap(dev->base); in ns83820_init_one()
2029 pci_free_consistent(pci_dev, 4 * DESC_SIZE * NR_TX_DESC, dev->tx_descs, dev->tx_phy_descs); in ns83820_init_one()
2030 …pci_free_consistent(pci_dev, 4 * DESC_SIZE * NR_RX_DESC, dev->rx_info.descs, dev->rx_info.phy_desc… in ns83820_init_one()
2033 kfree(dev); in ns83820_init_one()
2041 struct ns83820 *dev = pci_get_drvdata(pci_dev); in ns83820_remove_one() local
2043 if (!dev) /* paranoia */ in ns83820_remove_one()
2046 writel(0, dev->base + IMR); /* paranoia */ in ns83820_remove_one()
2047 writel(0, dev->base + IER); in ns83820_remove_one()
2048 readl(dev->base + IER); in ns83820_remove_one()
2050 unregister_netdev(&dev->net_dev); in ns83820_remove_one()
2051 free_irq(dev->pci_dev->irq, dev); in ns83820_remove_one()
2052 iounmap(dev->base); in ns83820_remove_one()
2053 pci_free_consistent(dev->pci_dev, 4 * DESC_SIZE * NR_TX_DESC, in ns83820_remove_one()
2054 dev->tx_descs, dev->tx_phy_descs); in ns83820_remove_one()
2055 pci_free_consistent(dev->pci_dev, 4 * DESC_SIZE * NR_RX_DESC, in ns83820_remove_one()
2056 dev->rx_info.descs, dev->rx_info.phy_descs); in ns83820_remove_one()
2057 pci_disable_device(dev->pci_dev); in ns83820_remove_one()
2058 kfree(dev); in ns83820_remove_one()