Lines Matching +full:100 +full:base +full:- +full:fx
3 * Copyright 1996-1999 Thomas Bogendoerfer
85 static int tx_start = 1; /* Mapping -- 0:20, 1:64, 2:128, 3:~220 (depends on chip vers) */
113 PCNET32_PORT_ASEL, /* 0 Auto-select */
117 PCNET32_PORT_10BT | PCNET32_PORT_FD, /* 4 10baseT-FD */
123 PCNET32_PORT_MII | PCNET32_PORT_FD, /* 10 MII 10baseT-FD */
126 PCNET32_PORT_MII | PCNET32_PORT_100, /* 13 MII 100BaseTx */
127 /* 14 MII 100BaseTx-FD */
175 #define PKT_BUF_SIZE (PKT_BUF_SKB - NET_IP_ALIGN)
177 #define NEG_BUF_SIZE (NET_IP_ALIGN - PKT_BUF_SKB)
179 /* Offsets from base I/O address. */
213 __le32 base; member
221 __le32 base; member
228 /* The PCNET32 32-Bit initialization block, described in databook. */
235 /* Receive and transmit ring base, along with extra bits. */
257 /* The Tx and Rx ring entries must be aligned on 16-byte boundaries in 32bit mode. */
264 /* The saved address of a sent-in-place packet/buffer, for skfree(). */
451 napi_disable(&lp->napi); in pcnet32_netif_stop()
458 ulong ioaddr = dev->base_addr; in pcnet32_netif_start()
462 val = lp->a->read_csr(ioaddr, CSR3); in pcnet32_netif_start()
464 lp->a->write_csr(ioaddr, CSR3, val); in pcnet32_netif_start()
465 napi_enable(&lp->napi); in pcnet32_netif_start()
473 * Must be called with lp->lock held.
488 dma_alloc_coherent(&lp->pci_dev->dev, in pcnet32_realloc_tx_ring()
502 kfree(lp->tx_skbuff); in pcnet32_realloc_tx_ring()
503 kfree(lp->tx_dma_addr); in pcnet32_realloc_tx_ring()
504 dma_free_coherent(&lp->pci_dev->dev, in pcnet32_realloc_tx_ring()
505 sizeof(struct pcnet32_tx_head) * lp->tx_ring_size, in pcnet32_realloc_tx_ring()
506 lp->tx_ring, lp->tx_ring_dma_addr); in pcnet32_realloc_tx_ring()
508 lp->tx_ring_size = entries; in pcnet32_realloc_tx_ring()
509 lp->tx_mod_mask = lp->tx_ring_size - 1; in pcnet32_realloc_tx_ring()
510 lp->tx_len_bits = (size << 12); in pcnet32_realloc_tx_ring()
511 lp->tx_ring = new_tx_ring; in pcnet32_realloc_tx_ring()
512 lp->tx_ring_dma_addr = new_ring_dma_addr; in pcnet32_realloc_tx_ring()
513 lp->tx_dma_addr = new_dma_addr_list; in pcnet32_realloc_tx_ring()
514 lp->tx_skbuff = new_skb_list; in pcnet32_realloc_tx_ring()
520 dma_free_coherent(&lp->pci_dev->dev, in pcnet32_realloc_tx_ring()
527 * Re-use old receive buffers.
533 * Must be called with lp->lock held.
547 dma_alloc_coherent(&lp->pci_dev->dev, in pcnet32_realloc_rx_ring()
562 overlap = min(entries, lp->rx_ring_size); in pcnet32_realloc_rx_ring()
564 new_rx_ring[new] = lp->rx_ring[new]; in pcnet32_realloc_rx_ring()
565 new_dma_addr_list[new] = lp->rx_dma_addr[new]; in pcnet32_realloc_rx_ring()
566 new_skb_list[new] = lp->rx_skbuff[new]; in pcnet32_realloc_rx_ring()
582 dma_map_single(&lp->pci_dev->dev, rx_skbuff->data, in pcnet32_realloc_rx_ring()
584 if (dma_mapping_error(&lp->pci_dev->dev, new_dma_addr_list[new])) { in pcnet32_realloc_rx_ring()
590 new_rx_ring[new].base = cpu_to_le32(new_dma_addr_list[new]); in pcnet32_realloc_rx_ring()
595 for (; new < lp->rx_ring_size; new++) { in pcnet32_realloc_rx_ring()
596 if (lp->rx_skbuff[new]) { in pcnet32_realloc_rx_ring()
597 if (!dma_mapping_error(&lp->pci_dev->dev, lp->rx_dma_addr[new])) in pcnet32_realloc_rx_ring()
598 dma_unmap_single(&lp->pci_dev->dev, in pcnet32_realloc_rx_ring()
599 lp->rx_dma_addr[new], in pcnet32_realloc_rx_ring()
602 dev_kfree_skb(lp->rx_skbuff[new]); in pcnet32_realloc_rx_ring()
606 kfree(lp->rx_skbuff); in pcnet32_realloc_rx_ring()
607 kfree(lp->rx_dma_addr); in pcnet32_realloc_rx_ring()
608 dma_free_coherent(&lp->pci_dev->dev, in pcnet32_realloc_rx_ring()
609 sizeof(struct pcnet32_rx_head) * lp->rx_ring_size, in pcnet32_realloc_rx_ring()
610 lp->rx_ring, lp->rx_ring_dma_addr); in pcnet32_realloc_rx_ring()
612 lp->rx_ring_size = entries; in pcnet32_realloc_rx_ring()
613 lp->rx_mod_mask = lp->rx_ring_size - 1; in pcnet32_realloc_rx_ring()
614 lp->rx_len_bits = (size << 4); in pcnet32_realloc_rx_ring()
615 lp->rx_ring = new_rx_ring; in pcnet32_realloc_rx_ring()
616 lp->rx_ring_dma_addr = new_ring_dma_addr; in pcnet32_realloc_rx_ring()
617 lp->rx_dma_addr = new_dma_addr_list; in pcnet32_realloc_rx_ring()
618 lp->rx_skbuff = new_skb_list; in pcnet32_realloc_rx_ring()
622 while (--new >= lp->rx_ring_size) { in pcnet32_realloc_rx_ring()
624 if (!dma_mapping_error(&lp->pci_dev->dev, new_dma_addr_list[new])) in pcnet32_realloc_rx_ring()
625 dma_unmap_single(&lp->pci_dev->dev, in pcnet32_realloc_rx_ring()
636 dma_free_coherent(&lp->pci_dev->dev, in pcnet32_realloc_rx_ring()
647 for (i = 0; i < lp->rx_ring_size; i++) { in pcnet32_purge_rx_ring()
648 lp->rx_ring[i].status = 0; /* CPU owns buffer */ in pcnet32_purge_rx_ring()
650 if (lp->rx_skbuff[i]) { in pcnet32_purge_rx_ring()
651 if (!dma_mapping_error(&lp->pci_dev->dev, lp->rx_dma_addr[i])) in pcnet32_purge_rx_ring()
652 dma_unmap_single(&lp->pci_dev->dev, in pcnet32_purge_rx_ring()
653 lp->rx_dma_addr[i], in pcnet32_purge_rx_ring()
656 dev_kfree_skb_any(lp->rx_skbuff[i]); in pcnet32_purge_rx_ring()
658 lp->rx_skbuff[i] = NULL; in pcnet32_purge_rx_ring()
659 lp->rx_dma_addr[i] = 0; in pcnet32_purge_rx_ring()
666 disable_irq(dev->irq); in pcnet32_poll_controller()
668 enable_irq(dev->irq); in pcnet32_poll_controller()
673 * lp->lock must be held.
680 const struct pcnet32_access *a = lp->a; in pcnet32_suspend()
681 ulong ioaddr = dev->base_addr; in pcnet32_suspend()
685 if (lp->chip_version < PCNET32_79C970A) in pcnet32_suspend()
688 /* set SUSPEND (SPND) - CSR5 bit 0 */ in pcnet32_suspend()
689 csr5 = a->read_csr(ioaddr, CSR5); in pcnet32_suspend()
690 a->write_csr(ioaddr, CSR5, csr5 | CSR5_SUSPEND); in pcnet32_suspend()
694 while (!(a->read_csr(ioaddr, CSR5) & CSR5_SUSPEND)) { in pcnet32_suspend()
695 spin_unlock_irqrestore(&lp->lock, *flags); in pcnet32_suspend()
700 spin_lock_irqsave(&lp->lock, *flags); in pcnet32_suspend()
713 int csr5 = lp->a->read_csr(ioaddr, CSR5); in pcnet32_clr_suspend()
714 /* clear SUSPEND (SPND) - CSR5 bit 0 */ in pcnet32_clr_suspend()
715 lp->a->write_csr(ioaddr, CSR5, csr5 & ~CSR5_SUSPEND); in pcnet32_clr_suspend()
724 spin_lock_irqsave(&lp->lock, flags); in pcnet32_get_link_ksettings()
725 if (lp->mii) { in pcnet32_get_link_ksettings()
726 mii_ethtool_get_link_ksettings(&lp->mii_if, cmd); in pcnet32_get_link_ksettings()
727 } else if (lp->chip_version == PCNET32_79C970A) { in pcnet32_get_link_ksettings()
728 if (lp->autoneg) { in pcnet32_get_link_ksettings()
729 cmd->base.autoneg = AUTONEG_ENABLE; in pcnet32_get_link_ksettings()
730 if (lp->a->read_bcr(dev->base_addr, 4) == 0xc0) in pcnet32_get_link_ksettings()
731 cmd->base.port = PORT_AUI; in pcnet32_get_link_ksettings()
733 cmd->base.port = PORT_TP; in pcnet32_get_link_ksettings()
735 cmd->base.autoneg = AUTONEG_DISABLE; in pcnet32_get_link_ksettings()
736 cmd->base.port = lp->port_tp ? PORT_TP : PORT_AUI; in pcnet32_get_link_ksettings()
738 cmd->base.duplex = lp->fdx ? DUPLEX_FULL : DUPLEX_HALF; in pcnet32_get_link_ksettings()
739 cmd->base.speed = SPEED_10; in pcnet32_get_link_ksettings()
741 cmd->link_modes.supported, in pcnet32_get_link_ksettings()
744 spin_unlock_irqrestore(&lp->lock, flags); in pcnet32_get_link_ksettings()
752 ulong ioaddr = dev->base_addr; in pcnet32_set_link_ksettings()
754 int r = -EOPNOTSUPP; in pcnet32_set_link_ksettings()
757 spin_lock_irqsave(&lp->lock, flags); in pcnet32_set_link_ksettings()
758 if (lp->mii) { in pcnet32_set_link_ksettings()
759 r = mii_ethtool_set_link_ksettings(&lp->mii_if, cmd); in pcnet32_set_link_ksettings()
760 } else if (lp->chip_version == PCNET32_79C970A) { in pcnet32_set_link_ksettings()
763 lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); in pcnet32_set_link_ksettings()
765 lp->autoneg = cmd->base.autoneg == AUTONEG_ENABLE; in pcnet32_set_link_ksettings()
766 bcr2 = lp->a->read_bcr(ioaddr, 2); in pcnet32_set_link_ksettings()
767 if (cmd->base.autoneg == AUTONEG_ENABLE) { in pcnet32_set_link_ksettings()
768 lp->a->write_bcr(ioaddr, 2, bcr2 | 0x0002); in pcnet32_set_link_ksettings()
770 lp->a->write_bcr(ioaddr, 2, bcr2 & ~0x0002); in pcnet32_set_link_ksettings()
772 lp->port_tp = cmd->base.port == PORT_TP; in pcnet32_set_link_ksettings()
773 csr15 = lp->a->read_csr(ioaddr, CSR15) & ~0x0180; in pcnet32_set_link_ksettings()
774 if (cmd->base.port == PORT_TP) in pcnet32_set_link_ksettings()
776 lp->a->write_csr(ioaddr, CSR15, csr15); in pcnet32_set_link_ksettings()
777 lp->init_block->mode = cpu_to_le16(csr15); in pcnet32_set_link_ksettings()
779 lp->fdx = cmd->base.duplex == DUPLEX_FULL; in pcnet32_set_link_ksettings()
780 bcr9 = lp->a->read_bcr(ioaddr, 9) & ~0x0003; in pcnet32_set_link_ksettings()
781 if (cmd->base.duplex == DUPLEX_FULL) in pcnet32_set_link_ksettings()
783 lp->a->write_bcr(ioaddr, 9, bcr9); in pcnet32_set_link_ksettings()
791 spin_unlock_irqrestore(&lp->lock, flags); in pcnet32_set_link_ksettings()
800 strscpy(info->driver, DRV_NAME, sizeof(info->driver)); in pcnet32_get_drvinfo()
801 if (lp->pci_dev) in pcnet32_get_drvinfo()
802 strscpy(info->bus_info, pci_name(lp->pci_dev), in pcnet32_get_drvinfo()
803 sizeof(info->bus_info)); in pcnet32_get_drvinfo()
805 snprintf(info->bus_info, sizeof(info->bus_info), in pcnet32_get_drvinfo()
806 "VLB 0x%lx", dev->base_addr); in pcnet32_get_drvinfo()
815 spin_lock_irqsave(&lp->lock, flags); in pcnet32_get_link()
816 if (lp->mii) { in pcnet32_get_link()
817 r = mii_link_ok(&lp->mii_if); in pcnet32_get_link()
818 } else if (lp->chip_version == PCNET32_79C970A) { in pcnet32_get_link()
819 ulong ioaddr = dev->base_addr; /* card base I/O address */ in pcnet32_get_link()
821 if (!lp->autoneg && lp->port_tp) in pcnet32_get_link()
822 r = (lp->a->read_bcr(ioaddr, 4) != 0xc0); in pcnet32_get_link()
825 } else if (lp->chip_version > PCNET32_79C970A) { in pcnet32_get_link()
826 ulong ioaddr = dev->base_addr; /* card base I/O address */ in pcnet32_get_link()
827 r = (lp->a->read_bcr(ioaddr, 4) != 0xc0); in pcnet32_get_link()
831 spin_unlock_irqrestore(&lp->lock, flags); in pcnet32_get_link()
839 return lp->msg_enable; in pcnet32_get_msglevel()
845 lp->msg_enable = value; in pcnet32_set_msglevel()
852 int r = -EOPNOTSUPP; in pcnet32_nway_reset()
854 if (lp->mii) { in pcnet32_nway_reset()
855 spin_lock_irqsave(&lp->lock, flags); in pcnet32_nway_reset()
856 r = mii_nway_restart(&lp->mii_if); in pcnet32_nway_reset()
857 spin_unlock_irqrestore(&lp->lock, flags); in pcnet32_nway_reset()
869 ering->tx_max_pending = TX_MAX_RING_SIZE; in pcnet32_get_ringparam()
870 ering->tx_pending = lp->tx_ring_size; in pcnet32_get_ringparam()
871 ering->rx_max_pending = RX_MAX_RING_SIZE; in pcnet32_get_ringparam()
872 ering->rx_pending = lp->rx_ring_size; in pcnet32_get_ringparam()
883 ulong ioaddr = dev->base_addr; in pcnet32_set_ringparam()
886 if (ering->rx_mini_pending || ering->rx_jumbo_pending) in pcnet32_set_ringparam()
887 return -EINVAL; in pcnet32_set_ringparam()
892 spin_lock_irqsave(&lp->lock, flags); in pcnet32_set_ringparam()
893 lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */ in pcnet32_set_ringparam()
895 size = min(ering->tx_pending, (unsigned int)TX_MAX_RING_SIZE); in pcnet32_set_ringparam()
904 if ((1 << i) != lp->tx_ring_size) in pcnet32_set_ringparam()
907 size = min(ering->rx_pending, (unsigned int)RX_MAX_RING_SIZE); in pcnet32_set_ringparam()
912 if ((1 << i) != lp->rx_ring_size) in pcnet32_set_ringparam()
915 lp->napi.weight = lp->rx_ring_size / 2; in pcnet32_set_ringparam()
922 spin_unlock_irqrestore(&lp->lock, flags); in pcnet32_set_ringparam()
925 lp->rx_ring_size, lp->tx_ring_size); in pcnet32_set_ringparam()
942 return -EOPNOTSUPP; in pcnet32_get_sset_count()
952 if (test->flags == ETH_TEST_FL_OFFLINE) { in pcnet32_ethtool_test()
957 test->flags |= ETH_TEST_FL_FAILED; in pcnet32_ethtool_test()
969 const struct pcnet32_access *a = lp->a; /* access to registers */ in pcnet32_loopback_test()
970 ulong ioaddr = dev->base_addr; /* card base I/O address */ in pcnet32_loopback_test()
988 spin_lock_irqsave(&lp->lock, flags); in pcnet32_loopback_test()
989 lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */ in pcnet32_loopback_test()
991 numbuffs = min(numbuffs, (int)min(lp->rx_ring_size, lp->tx_ring_size)); in pcnet32_loopback_test()
994 lp->a->reset(ioaddr); in pcnet32_loopback_test()
995 lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */ in pcnet32_loopback_test()
998 lp->a->write_bcr(ioaddr, 20, 2); in pcnet32_loopback_test()
1003 lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */ in pcnet32_loopback_test()
1015 packet = skb->data; in pcnet32_loopback_test()
1017 lp->tx_skbuff[x] = skb; in pcnet32_loopback_test()
1018 lp->tx_ring[x].length = cpu_to_le16(-skb->len); in pcnet32_loopback_test()
1019 lp->tx_ring[x].misc = 0; in pcnet32_loopback_test()
1023 *packet++ = dev->dev_addr[i]; in pcnet32_loopback_test()
1025 *packet++ = dev->dev_addr[i]; in pcnet32_loopback_test()
1035 lp->tx_dma_addr[x] = in pcnet32_loopback_test()
1036 dma_map_single(&lp->pci_dev->dev, skb->data, skb->len, in pcnet32_loopback_test()
1038 if (dma_mapping_error(&lp->pci_dev->dev, lp->tx_dma_addr[x])) { in pcnet32_loopback_test()
1044 lp->tx_ring[x].base = cpu_to_le32(lp->tx_dma_addr[x]); in pcnet32_loopback_test()
1046 lp->tx_ring[x].status = cpu_to_le16(status); in pcnet32_loopback_test()
1049 x = a->read_bcr(ioaddr, 32); /* set internal loopback in BCR32 */ in pcnet32_loopback_test()
1050 a->write_bcr(ioaddr, 32, x | 0x0002); in pcnet32_loopback_test()
1053 x = a->read_csr(ioaddr, CSR15) & 0xfffc; in pcnet32_loopback_test()
1054 lp->a->write_csr(ioaddr, CSR15, x | 0x0044); in pcnet32_loopback_test()
1057 lp->a->write_csr(ioaddr, CSR0, CSR0_START); /* Set STRT bit */ in pcnet32_loopback_test()
1063 while ((lp->rx_ring[x].status & teststatus) && (ticks < 200)) { in pcnet32_loopback_test()
1064 spin_unlock_irqrestore(&lp->lock, flags); in pcnet32_loopback_test()
1066 spin_lock_irqsave(&lp->lock, flags); in pcnet32_loopback_test()
1076 lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */ in pcnet32_loopback_test()
1083 skb = lp->rx_skbuff[x]; in pcnet32_loopback_test()
1085 pr_cont(" %02x", *(skb->data + i)); in pcnet32_loopback_test()
1093 skb = lp->rx_skbuff[x]; in pcnet32_loopback_test()
1094 packet = lp->tx_skbuff[x]->data; in pcnet32_loopback_test()
1096 if (*(skb->data + i) != packet[i]) { in pcnet32_loopback_test()
1098 "Error in compare! %2x - %02x %02x\n", in pcnet32_loopback_test()
1099 i, *(skb->data + i), packet[i]); in pcnet32_loopback_test()
1111 x = a->read_csr(ioaddr, CSR15); in pcnet32_loopback_test()
1112 a->write_csr(ioaddr, CSR15, (x & ~0x0044)); /* reset bits 6 and 2 */ in pcnet32_loopback_test()
1114 x = a->read_bcr(ioaddr, 32); /* reset internal loopback */ in pcnet32_loopback_test()
1115 a->write_bcr(ioaddr, 32, (x & ~0x0002)); in pcnet32_loopback_test()
1122 lp->a->write_bcr(ioaddr, 20, 4); /* return to 16bit mode */ in pcnet32_loopback_test()
1124 spin_unlock_irqrestore(&lp->lock, flags); in pcnet32_loopback_test()
1133 const struct pcnet32_access *a = lp->a; in pcnet32_set_phys_id()
1134 ulong ioaddr = dev->base_addr; in pcnet32_set_phys_id()
1141 spin_lock_irqsave(&lp->lock, flags); in pcnet32_set_phys_id()
1143 lp->save_regs[i - 4] = a->read_bcr(ioaddr, i); in pcnet32_set_phys_id()
1144 spin_unlock_irqrestore(&lp->lock, flags); in pcnet32_set_phys_id()
1150 spin_lock_irqsave(&lp->lock, flags); in pcnet32_set_phys_id()
1152 a->write_bcr(ioaddr, i, a->read_bcr(ioaddr, i) ^ 0x4000); in pcnet32_set_phys_id()
1153 spin_unlock_irqrestore(&lp->lock, flags); in pcnet32_set_phys_id()
1158 spin_lock_irqsave(&lp->lock, flags); in pcnet32_set_phys_id()
1160 a->write_bcr(ioaddr, i, lp->save_regs[i - 4]); in pcnet32_set_phys_id()
1161 spin_unlock_irqrestore(&lp->lock, flags); in pcnet32_set_phys_id()
1175 int status = (short)le16_to_cpu(rxp->status) >> 8; in pcnet32_rx_entry()
1183 * <murf@perftech.com> to Russ Nelson: Even with full-sized in pcnet32_rx_entry()
1188 dev->stats.rx_errors++; /* end of a packet. */ in pcnet32_rx_entry()
1190 dev->stats.rx_frame_errors++; in pcnet32_rx_entry()
1192 dev->stats.rx_over_errors++; in pcnet32_rx_entry()
1194 dev->stats.rx_crc_errors++; in pcnet32_rx_entry()
1196 dev->stats.rx_fifo_errors++; in pcnet32_rx_entry()
1200 pkt_len = (le32_to_cpu(rxp->msg_length) & 0xfff) - 4; in pcnet32_rx_entry()
1206 dev->stats.rx_errors++; in pcnet32_rx_entry()
1211 dev->stats.rx_errors++; in pcnet32_rx_entry()
1226 new_dma_addr = dma_map_single(&lp->pci_dev->dev, in pcnet32_rx_entry()
1227 newskb->data, in pcnet32_rx_entry()
1230 if (dma_mapping_error(&lp->pci_dev->dev, new_dma_addr)) { in pcnet32_rx_entry()
1236 skb = lp->rx_skbuff[entry]; in pcnet32_rx_entry()
1237 dma_unmap_single(&lp->pci_dev->dev, in pcnet32_rx_entry()
1238 lp->rx_dma_addr[entry], in pcnet32_rx_entry()
1242 lp->rx_skbuff[entry] = newskb; in pcnet32_rx_entry()
1243 lp->rx_dma_addr[entry] = new_dma_addr; in pcnet32_rx_entry()
1244 rxp->base = cpu_to_le32(new_dma_addr); in pcnet32_rx_entry()
1253 dev->stats.rx_dropped++; in pcnet32_rx_entry()
1259 dma_sync_single_for_cpu(&lp->pci_dev->dev, in pcnet32_rx_entry()
1260 lp->rx_dma_addr[entry], pkt_len, in pcnet32_rx_entry()
1263 (unsigned char *)(lp->rx_skbuff[entry]->data), in pcnet32_rx_entry()
1265 dma_sync_single_for_device(&lp->pci_dev->dev, in pcnet32_rx_entry()
1266 lp->rx_dma_addr[entry], pkt_len, in pcnet32_rx_entry()
1269 dev->stats.rx_bytes += skb->len; in pcnet32_rx_entry()
1270 skb->protocol = eth_type_trans(skb, dev); in pcnet32_rx_entry()
1272 dev->stats.rx_packets++; in pcnet32_rx_entry()
1278 int entry = lp->cur_rx & lp->rx_mod_mask; in pcnet32_rx()
1279 struct pcnet32_rx_head *rxp = &lp->rx_ring[entry]; in pcnet32_rx()
1283 while (npackets < budget && (short)le16_to_cpu(rxp->status) >= 0) { in pcnet32_rx()
1290 rxp->buf_length = cpu_to_le16(NEG_BUF_SIZE); in pcnet32_rx()
1292 rxp->status = cpu_to_le16(0x8000); in pcnet32_rx()
1293 entry = (++lp->cur_rx) & lp->rx_mod_mask; in pcnet32_rx()
1294 rxp = &lp->rx_ring[entry]; in pcnet32_rx()
1303 unsigned int dirty_tx = lp->dirty_tx; in pcnet32_tx()
1307 while (dirty_tx != lp->cur_tx) { in pcnet32_tx()
1308 int entry = dirty_tx & lp->tx_mod_mask; in pcnet32_tx()
1309 int status = (short)le16_to_cpu(lp->tx_ring[entry].status); in pcnet32_tx()
1314 lp->tx_ring[entry].base = 0; in pcnet32_tx()
1318 int err_status = le32_to_cpu(lp->tx_ring[entry].misc); in pcnet32_tx()
1319 dev->stats.tx_errors++; in pcnet32_tx()
1324 dev->stats.tx_aborted_errors++; in pcnet32_tx()
1326 dev->stats.tx_carrier_errors++; in pcnet32_tx()
1328 dev->stats.tx_window_errors++; in pcnet32_tx()
1331 dev->stats.tx_fifo_errors++; in pcnet32_tx()
1339 dev->stats.tx_fifo_errors++; in pcnet32_tx()
1340 if (!lp->dxsuflo) { /* If controller doesn't recover ... */ in pcnet32_tx()
1350 dev->stats.collisions++; in pcnet32_tx()
1351 dev->stats.tx_packets++; in pcnet32_tx()
1355 if (lp->tx_skbuff[entry]) { in pcnet32_tx()
1356 dma_unmap_single(&lp->pci_dev->dev, in pcnet32_tx()
1357 lp->tx_dma_addr[entry], in pcnet32_tx()
1358 lp->tx_skbuff[entry]->len, in pcnet32_tx()
1360 dev_kfree_skb_any(lp->tx_skbuff[entry]); in pcnet32_tx()
1361 lp->tx_skbuff[entry] = NULL; in pcnet32_tx()
1362 lp->tx_dma_addr[entry] = 0; in pcnet32_tx()
1367 delta = (lp->cur_tx - dirty_tx) & (lp->tx_mod_mask + lp->tx_ring_size); in pcnet32_tx()
1368 if (delta > lp->tx_ring_size) { in pcnet32_tx()
1369 netif_err(lp, drv, dev, "out-of-sync dirty pointer, %d vs. %d, full=%d\n", in pcnet32_tx()
1370 dirty_tx, lp->cur_tx, lp->tx_full); in pcnet32_tx()
1371 dirty_tx += lp->tx_ring_size; in pcnet32_tx()
1372 delta -= lp->tx_ring_size; in pcnet32_tx()
1375 if (lp->tx_full && in pcnet32_tx()
1377 delta < lp->tx_ring_size - 2) { in pcnet32_tx()
1379 lp->tx_full = 0; in pcnet32_tx()
1382 lp->dirty_tx = dirty_tx; in pcnet32_tx()
1390 struct net_device *dev = lp->dev; in pcnet32_poll()
1391 unsigned long ioaddr = dev->base_addr; in pcnet32_poll()
1398 spin_lock_irqsave(&lp->lock, flags); in pcnet32_poll()
1401 lp->a->reset(ioaddr); in pcnet32_poll()
1402 lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */ in pcnet32_poll()
1409 val = lp->a->read_csr(ioaddr, CSR3); in pcnet32_poll()
1411 lp->a->write_csr(ioaddr, CSR3, val); in pcnet32_poll()
1414 lp->a->write_csr(ioaddr, CSR0, CSR0_INTEN); in pcnet32_poll()
1417 spin_unlock_irqrestore(&lp->lock, flags); in pcnet32_poll()
1426 int j = lp->phycount * PCNET32_REGS_PER_PHY; in pcnet32_get_regs_len()
1437 const struct pcnet32_access *a = lp->a; in pcnet32_get_regs()
1438 ulong ioaddr = dev->base_addr; in pcnet32_get_regs()
1441 spin_lock_irqsave(&lp->lock, flags); in pcnet32_get_regs()
1443 csr0 = a->read_csr(ioaddr, CSR0); in pcnet32_get_regs()
1453 *buff++ = a->read_csr(ioaddr, i); in pcnet32_get_regs()
1455 *buff++ = a->read_csr(ioaddr, 112); in pcnet32_get_regs()
1456 *buff++ = a->read_csr(ioaddr, 114); in pcnet32_get_regs()
1460 *buff++ = a->read_bcr(ioaddr, i); in pcnet32_get_regs()
1465 *buff++ = a->read_bcr(ioaddr, i); in pcnet32_get_regs()
1468 if (lp->mii) { in pcnet32_get_regs()
1471 if (lp->phymask & (1 << j)) { in pcnet32_get_regs()
1473 lp->a->write_bcr(ioaddr, 33, in pcnet32_get_regs()
1475 *buff++ = lp->a->read_bcr(ioaddr, 34); in pcnet32_get_regs()
1484 spin_unlock_irqrestore(&lp->lock, flags); in pcnet32_get_regs()
1505 /* only probes for non-PCI devices, the rest are handled by
1536 pr_err("failed to enable device -- err=%d\n", err); in pcnet32_probe_pci()
1544 err = -ENODEV; in pcnet32_probe_pci()
1548 err = dma_set_mask(&pdev->dev, PCNET32_DMA_MASK); in pcnet32_probe_pci()
1559 err = -EBUSY; in pcnet32_probe_pci()
1603 int ret = -ENODEV; in pcnet32_probe1()
1608 /* NOTE: 16-bit check is first, otherwise some older PCnet chips fail */ in pcnet32_probe1()
1624 a->read_csr(ioaddr, 88) | (a->read_csr(ioaddr, 89) << 16); in pcnet32_probe1()
1678 media = a->read_bcr(ioaddr, 49); in pcnet32_probe1()
1685 a->write_bcr(ioaddr, 49, media); in pcnet32_probe1()
1708 * one for latency - although on PCI this isn't a big loss. Older chips in pcnet32_probe1()
1714 a->write_bcr(ioaddr, 18, (a->read_bcr(ioaddr, 18) | 0x0860)); in pcnet32_probe1()
1715 a->write_csr(ioaddr, 80, in pcnet32_probe1()
1716 (a->read_csr(ioaddr, 80) & 0x0C00) | 0x0c00); in pcnet32_probe1()
1730 * to the datasheet, each bit corresponds to a 512-byte in pcnet32_probe1()
1732 * holds the value of the upper 8 bits of the 16-bit SRAM size. in pcnet32_probe1()
1733 * The low 8-bits start at 0x00 and end at 0xff. So the in pcnet32_probe1()
1739 a->write_bcr(ioaddr, 25, 0x17); in pcnet32_probe1()
1740 a->write_bcr(ioaddr, 26, 0xc); in pcnet32_probe1()
1742 a->write_bcr(ioaddr, 18, a->read_bcr(ioaddr, 18) | (1 << 11)); in pcnet32_probe1()
1747 ret = -ENOMEM; in pcnet32_probe1()
1752 SET_NETDEV_DEV(dev, &pdev->dev); in pcnet32_probe1()
1758 * station address PROM at the base address and programmed into the in pcnet32_probe1()
1759 * "Physical Address Registers" CSR12-14. in pcnet32_probe1()
1766 val = a->read_csr(ioaddr, i + 12) & 0x0ffff; in pcnet32_probe1()
1777 if (!ether_addr_equal(promaddr, dev->dev_addr) || in pcnet32_probe1()
1778 !is_valid_ether_addr(dev->dev_addr)) { in pcnet32_probe1()
1789 if (!is_valid_ether_addr(dev->dev_addr)) { in pcnet32_probe1()
1796 pr_cont(" %pM", dev->dev_addr); in pcnet32_probe1()
1800 i = a->read_csr(ioaddr, 80) & 0x0C00; /* Check tx_start_pt */ in pcnet32_probe1()
1816 i = a->read_bcr(ioaddr, 18); /* Check Burst/Bus control */ in pcnet32_probe1()
1826 i = a->read_bcr(ioaddr, 25); in pcnet32_probe1()
1828 i = a->read_bcr(ioaddr, 26); in pcnet32_probe1()
1830 i = a->read_bcr(ioaddr, 27); in pcnet32_probe1()
1836 dev->base_addr = ioaddr; in pcnet32_probe1()
1838 /* dma_alloc_coherent returns page-aligned memory, so we do not have to check the alignment */ in pcnet32_probe1()
1839 lp->init_block = dma_alloc_coherent(&pdev->dev, in pcnet32_probe1()
1840 sizeof(*lp->init_block), in pcnet32_probe1()
1841 &lp->init_dma_addr, GFP_KERNEL); in pcnet32_probe1()
1842 if (!lp->init_block) { in pcnet32_probe1()
1845 ret = -ENOMEM; in pcnet32_probe1()
1848 lp->pci_dev = pdev; in pcnet32_probe1()
1850 lp->dev = dev; in pcnet32_probe1()
1852 spin_lock_init(&lp->lock); in pcnet32_probe1()
1854 lp->name = chipname; in pcnet32_probe1()
1855 lp->shared_irq = shared; in pcnet32_probe1()
1856 lp->tx_ring_size = TX_RING_SIZE; /* default tx ring size */ in pcnet32_probe1()
1857 lp->rx_ring_size = RX_RING_SIZE; /* default rx ring size */ in pcnet32_probe1()
1858 lp->tx_mod_mask = lp->tx_ring_size - 1; in pcnet32_probe1()
1859 lp->rx_mod_mask = lp->rx_ring_size - 1; in pcnet32_probe1()
1860 lp->tx_len_bits = (PCNET32_LOG_TX_BUFFERS << 12); in pcnet32_probe1()
1861 lp->rx_len_bits = (PCNET32_LOG_RX_BUFFERS << 4); in pcnet32_probe1()
1862 lp->mii_if.full_duplex = fdx; in pcnet32_probe1()
1863 lp->mii_if.phy_id_mask = 0x1f; in pcnet32_probe1()
1864 lp->mii_if.reg_num_mask = 0x1f; in pcnet32_probe1()
1865 lp->dxsuflo = dxsuflo; in pcnet32_probe1()
1866 lp->mii = mii; in pcnet32_probe1()
1867 lp->chip_version = chip_version; in pcnet32_probe1()
1868 lp->msg_enable = pcnet32_debug; in pcnet32_probe1()
1871 lp->options = PCNET32_PORT_ASEL; in pcnet32_probe1()
1873 lp->options = options_mapping[options[cards_found]]; in pcnet32_probe1()
1875 if (lp->chip_version == PCNET32_79C970A) in pcnet32_probe1()
1876 lp->options = PCNET32_PORT_10BT; in pcnet32_probe1()
1877 lp->mii_if.dev = dev; in pcnet32_probe1()
1878 lp->mii_if.mdio_read = mdio_read; in pcnet32_probe1()
1879 lp->mii_if.mdio_write = mdio_write; in pcnet32_probe1()
1881 /* napi.weight is used in both the napi and non-napi cases */ in pcnet32_probe1()
1882 lp->napi.weight = lp->rx_ring_size / 2; in pcnet32_probe1()
1884 netif_napi_add_weight(dev, &lp->napi, pcnet32_poll, in pcnet32_probe1()
1885 lp->rx_ring_size / 2); in pcnet32_probe1()
1887 if (fdx && !(lp->options & PCNET32_PORT_ASEL) && in pcnet32_probe1()
1889 lp->options |= PCNET32_PORT_FD; in pcnet32_probe1()
1891 lp->a = a; in pcnet32_probe1()
1893 /* prior to register_netdev, dev->name is not yet correct */ in pcnet32_probe1()
1894 if (pcnet32_alloc_ring(dev, pci_name(lp->pci_dev))) { in pcnet32_probe1()
1895 ret = -ENOMEM; in pcnet32_probe1()
1899 if (dev->dev_addr[0] == 0x00 && dev->dev_addr[1] == 0xe0 && in pcnet32_probe1()
1900 dev->dev_addr[2] == 0x75) in pcnet32_probe1()
1901 lp->options = PCNET32_PORT_FD | PCNET32_PORT_GPSI; in pcnet32_probe1()
1903 lp->init_block->mode = cpu_to_le16(0x0003); /* Disable Rx and Tx. */ in pcnet32_probe1()
1904 lp->init_block->tlen_rlen = in pcnet32_probe1()
1905 cpu_to_le16(lp->tx_len_bits | lp->rx_len_bits); in pcnet32_probe1()
1907 lp->init_block->phys_addr[i] = dev->dev_addr[i]; in pcnet32_probe1()
1908 lp->init_block->filter[0] = 0x00000000; in pcnet32_probe1()
1909 lp->init_block->filter[1] = 0x00000000; in pcnet32_probe1()
1910 lp->init_block->rx_ring = cpu_to_le32(lp->rx_ring_dma_addr); in pcnet32_probe1()
1911 lp->init_block->tx_ring = cpu_to_le32(lp->tx_ring_dma_addr); in pcnet32_probe1()
1914 a->write_bcr(ioaddr, 20, 2); in pcnet32_probe1()
1916 a->write_csr(ioaddr, 1, (lp->init_dma_addr & 0xffff)); in pcnet32_probe1()
1917 a->write_csr(ioaddr, 2, (lp->init_dma_addr >> 16)); in pcnet32_probe1()
1920 dev->irq = pdev->irq; in pcnet32_probe1()
1922 pr_cont(" assigned IRQ %d\n", dev->irq); in pcnet32_probe1()
1927 * To auto-IRQ we enable the initialization-done and DMA error in pcnet32_probe1()
1932 a->write_csr(ioaddr, CSR0, CSR0_INTEN | CSR0_INIT); in pcnet32_probe1()
1935 dev->irq = probe_irq_off(irq_mask); in pcnet32_probe1()
1936 if (!dev->irq) { in pcnet32_probe1()
1939 ret = -ENODEV; in pcnet32_probe1()
1943 pr_cont(", probed IRQ %d\n", dev->irq); in pcnet32_probe1()
1947 if (lp->mii) { in pcnet32_probe1()
1948 /* lp->phycount and lp->phymask are set to 0 by memset above */ in pcnet32_probe1()
1950 lp->mii_if.phy_id = ((lp->a->read_bcr(ioaddr, 33)) >> 5) & 0x1f; in pcnet32_probe1()
1963 lp->phycount++; in pcnet32_probe1()
1964 lp->phymask |= (1 << i); in pcnet32_probe1()
1965 lp->mii_if.phy_id = i; in pcnet32_probe1()
1970 lp->a->write_bcr(ioaddr, 33, (lp->mii_if.phy_id) << 5); in pcnet32_probe1()
1971 if (lp->phycount > 1) in pcnet32_probe1()
1972 lp->options |= PCNET32_PORT_MII; in pcnet32_probe1()
1975 timer_setup(&lp->watchdog_timer, pcnet32_watchdog, 0); in pcnet32_probe1()
1977 /* The PCNET32-specific entries in the device structure. */ in pcnet32_probe1()
1978 dev->netdev_ops = &pcnet32_netdev_ops; in pcnet32_probe1()
1979 dev->ethtool_ops = &pcnet32_ethtool_ops; in pcnet32_probe1()
1980 dev->watchdog_timeo = (5 * HZ); in pcnet32_probe1()
1989 lp->next = pcnet32_dev; in pcnet32_probe1()
1994 pr_info("%s: registered as %s\n", dev->name, lp->name); in pcnet32_probe1()
1998 a->write_bcr(ioaddr, 2, a->read_bcr(ioaddr, 2) | 0x1000); in pcnet32_probe1()
2004 dma_free_coherent(&lp->pci_dev->dev, sizeof(*lp->init_block), in pcnet32_probe1()
2005 lp->init_block, lp->init_dma_addr); in pcnet32_probe1()
2018 lp->tx_ring = dma_alloc_coherent(&lp->pci_dev->dev, in pcnet32_alloc_ring()
2019 sizeof(struct pcnet32_tx_head) * lp->tx_ring_size, in pcnet32_alloc_ring()
2020 &lp->tx_ring_dma_addr, GFP_KERNEL); in pcnet32_alloc_ring()
2021 if (!lp->tx_ring) { in pcnet32_alloc_ring()
2023 return -ENOMEM; in pcnet32_alloc_ring()
2026 lp->rx_ring = dma_alloc_coherent(&lp->pci_dev->dev, in pcnet32_alloc_ring()
2027 sizeof(struct pcnet32_rx_head) * lp->rx_ring_size, in pcnet32_alloc_ring()
2028 &lp->rx_ring_dma_addr, GFP_KERNEL); in pcnet32_alloc_ring()
2029 if (!lp->rx_ring) { in pcnet32_alloc_ring()
2031 return -ENOMEM; in pcnet32_alloc_ring()
2034 lp->tx_dma_addr = kcalloc(lp->tx_ring_size, sizeof(dma_addr_t), in pcnet32_alloc_ring()
2036 if (!lp->tx_dma_addr) in pcnet32_alloc_ring()
2037 return -ENOMEM; in pcnet32_alloc_ring()
2039 lp->rx_dma_addr = kcalloc(lp->rx_ring_size, sizeof(dma_addr_t), in pcnet32_alloc_ring()
2041 if (!lp->rx_dma_addr) in pcnet32_alloc_ring()
2042 return -ENOMEM; in pcnet32_alloc_ring()
2044 lp->tx_skbuff = kcalloc(lp->tx_ring_size, sizeof(struct sk_buff *), in pcnet32_alloc_ring()
2046 if (!lp->tx_skbuff) in pcnet32_alloc_ring()
2047 return -ENOMEM; in pcnet32_alloc_ring()
2049 lp->rx_skbuff = kcalloc(lp->rx_ring_size, sizeof(struct sk_buff *), in pcnet32_alloc_ring()
2051 if (!lp->rx_skbuff) in pcnet32_alloc_ring()
2052 return -ENOMEM; in pcnet32_alloc_ring()
2061 kfree(lp->tx_skbuff); in pcnet32_free_ring()
2062 lp->tx_skbuff = NULL; in pcnet32_free_ring()
2064 kfree(lp->rx_skbuff); in pcnet32_free_ring()
2065 lp->rx_skbuff = NULL; in pcnet32_free_ring()
2067 kfree(lp->tx_dma_addr); in pcnet32_free_ring()
2068 lp->tx_dma_addr = NULL; in pcnet32_free_ring()
2070 kfree(lp->rx_dma_addr); in pcnet32_free_ring()
2071 lp->rx_dma_addr = NULL; in pcnet32_free_ring()
2073 if (lp->tx_ring) { in pcnet32_free_ring()
2074 dma_free_coherent(&lp->pci_dev->dev, in pcnet32_free_ring()
2075 sizeof(struct pcnet32_tx_head) * lp->tx_ring_size, in pcnet32_free_ring()
2076 lp->tx_ring, lp->tx_ring_dma_addr); in pcnet32_free_ring()
2077 lp->tx_ring = NULL; in pcnet32_free_ring()
2080 if (lp->rx_ring) { in pcnet32_free_ring()
2081 dma_free_coherent(&lp->pci_dev->dev, in pcnet32_free_ring()
2082 sizeof(struct pcnet32_rx_head) * lp->rx_ring_size, in pcnet32_free_ring()
2083 lp->rx_ring, lp->rx_ring_dma_addr); in pcnet32_free_ring()
2084 lp->rx_ring = NULL; in pcnet32_free_ring()
2091 struct pci_dev *pdev = lp->pci_dev; in pcnet32_open()
2092 unsigned long ioaddr = dev->base_addr; in pcnet32_open()
2098 if (request_irq(dev->irq, pcnet32_interrupt, in pcnet32_open()
2099 lp->shared_irq ? IRQF_SHARED : 0, dev->name, in pcnet32_open()
2101 return -EAGAIN; in pcnet32_open()
2104 spin_lock_irqsave(&lp->lock, flags); in pcnet32_open()
2106 if (!is_valid_ether_addr(dev->dev_addr)) { in pcnet32_open()
2107 rc = -EINVAL; in pcnet32_open()
2112 lp->a->reset(ioaddr); in pcnet32_open()
2115 lp->a->write_bcr(ioaddr, 20, 2); in pcnet32_open()
2119 __func__, dev->irq, (u32) (lp->tx_ring_dma_addr), in pcnet32_open()
2120 (u32) (lp->rx_ring_dma_addr), in pcnet32_open()
2121 (u32) (lp->init_dma_addr)); in pcnet32_open()
2123 lp->autoneg = !!(lp->options & PCNET32_PORT_ASEL); in pcnet32_open()
2124 lp->port_tp = !!(lp->options & PCNET32_PORT_10BT); in pcnet32_open()
2125 lp->fdx = !!(lp->options & PCNET32_PORT_FD); in pcnet32_open()
2128 val = lp->a->read_bcr(ioaddr, 2) & ~2; in pcnet32_open()
2129 if (lp->options & PCNET32_PORT_ASEL) in pcnet32_open()
2131 lp->a->write_bcr(ioaddr, 2, val); in pcnet32_open()
2134 if (lp->mii_if.full_duplex) { in pcnet32_open()
2135 val = lp->a->read_bcr(ioaddr, 9) & ~3; in pcnet32_open()
2136 if (lp->options & PCNET32_PORT_FD) { in pcnet32_open()
2138 if (lp->options == (PCNET32_PORT_FD | PCNET32_PORT_AUI)) in pcnet32_open()
2140 } else if (lp->options & PCNET32_PORT_ASEL) { in pcnet32_open()
2142 if (lp->chip_version == 0x2627) in pcnet32_open()
2145 lp->a->write_bcr(ioaddr, 9, val); in pcnet32_open()
2149 val = lp->a->read_csr(ioaddr, 124) & ~0x10; in pcnet32_open()
2150 if ((lp->options & PCNET32_PORT_PORTSEL) == PCNET32_PORT_GPSI) in pcnet32_open()
2152 lp->a->write_csr(ioaddr, 124, val); in pcnet32_open()
2154 /* Allied Telesyn AT 2700/2701 FX are 100Mbit only and do not negotiate */ in pcnet32_open()
2155 if (pdev && pdev->subsystem_vendor == PCI_VENDOR_ID_AT && in pcnet32_open()
2156 (pdev->subsystem_device == PCI_SUBDEVICE_ID_AT_2700FX || in pcnet32_open()
2157 pdev->subsystem_device == PCI_SUBDEVICE_ID_AT_2701FX)) { in pcnet32_open()
2158 if (lp->options & PCNET32_PORT_ASEL) { in pcnet32_open()
2159 lp->options = PCNET32_PORT_FD | PCNET32_PORT_100; in pcnet32_open()
2161 "Setting 100Mb-Full Duplex\n"); in pcnet32_open()
2164 if (lp->phycount < 2) { in pcnet32_open()
2170 if (lp->mii && !(lp->options & PCNET32_PORT_ASEL)) { in pcnet32_open()
2171 lp->a->write_bcr(ioaddr, 32, in pcnet32_open()
2172 lp->a->read_bcr(ioaddr, 32) | 0x0080); in pcnet32_open()
2174 val = lp->a->read_bcr(ioaddr, 32) & ~0xb8; in pcnet32_open()
2175 if (lp->options & PCNET32_PORT_FD) in pcnet32_open()
2177 if (lp->options & PCNET32_PORT_100) in pcnet32_open()
2179 lp->a->write_bcr(ioaddr, 32, val); in pcnet32_open()
2181 if (lp->options & PCNET32_PORT_ASEL) { in pcnet32_open()
2182 lp->a->write_bcr(ioaddr, 32, in pcnet32_open()
2183 lp->a->read_bcr(ioaddr, in pcnet32_open()
2186 val = lp->a->read_bcr(ioaddr, 32) & ~0x98; in pcnet32_open()
2188 lp->a->write_bcr(ioaddr, 32, val); in pcnet32_open()
2192 int first_phy = -1; in pcnet32_open()
2201 val = lp->a->read_bcr(ioaddr, 2); in pcnet32_open()
2202 lp->a->write_bcr(ioaddr, 2, val & ~2); in pcnet32_open()
2203 val = lp->a->read_bcr(ioaddr, 32); in pcnet32_open()
2204 lp->a->write_bcr(ioaddr, 32, val & ~(1 << 7)); /* stop MII manager */ in pcnet32_open()
2206 if (!(lp->options & PCNET32_PORT_ASEL)) { in pcnet32_open()
2212 (lp->options & PCNET32_PORT_100) ? in pcnet32_open()
2214 bcr9 = lp->a->read_bcr(ioaddr, 9); in pcnet32_open()
2216 if (lp->options & PCNET32_PORT_FD) { in pcnet32_open()
2223 lp->a->write_bcr(ioaddr, 9, bcr9); in pcnet32_open()
2227 if (lp->phymask & (1 << i)) { in pcnet32_open()
2230 if (first_phy == -1) { in pcnet32_open()
2239 lp->mii_if.phy_id = i; in pcnet32_open()
2241 if (lp->options & PCNET32_PORT_ASEL) { in pcnet32_open()
2242 mii_ethtool_gset(&lp->mii_if, &ecmd); in pcnet32_open()
2245 mii_ethtool_sset(&lp->mii_if, &ecmd); in pcnet32_open()
2248 lp->mii_if.phy_id = first_phy; in pcnet32_open()
2253 if (lp->dxsuflo) { /* Disable transmit stop on underflow */ in pcnet32_open()
2254 val = lp->a->read_csr(ioaddr, CSR3); in pcnet32_open()
2256 lp->a->write_csr(ioaddr, CSR3, val); in pcnet32_open()
2260 lp->init_block->mode = in pcnet32_open()
2261 cpu_to_le16((lp->options & PCNET32_PORT_PORTSEL) << 7); in pcnet32_open()
2265 rc = -ENOMEM; in pcnet32_open()
2269 napi_enable(&lp->napi); in pcnet32_open()
2271 /* Re-initialize the PCNET32, and start it when done. */ in pcnet32_open()
2272 lp->a->write_csr(ioaddr, 1, (lp->init_dma_addr & 0xffff)); in pcnet32_open()
2273 lp->a->write_csr(ioaddr, 2, (lp->init_dma_addr >> 16)); in pcnet32_open()
2275 lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */ in pcnet32_open()
2276 lp->a->write_csr(ioaddr, CSR0, CSR0_INIT); in pcnet32_open()
2280 if (lp->chip_version >= PCNET32_79C970A) { in pcnet32_open()
2283 mod_timer(&lp->watchdog_timer, PCNET32_WATCHDOG_TIMEOUT); in pcnet32_open()
2287 while (i++ < 100) in pcnet32_open()
2288 if (lp->a->read_csr(ioaddr, CSR0) & CSR0_IDON) in pcnet32_open()
2294 lp->a->write_csr(ioaddr, CSR0, CSR0_NORMAL); in pcnet32_open()
2299 (u32) (lp->init_dma_addr), in pcnet32_open()
2300 lp->a->read_csr(ioaddr, CSR0)); in pcnet32_open()
2302 spin_unlock_irqrestore(&lp->lock, flags); in pcnet32_open()
2314 lp->a->write_bcr(ioaddr, 20, 4); in pcnet32_open()
2317 spin_unlock_irqrestore(&lp->lock, flags); in pcnet32_open()
2318 free_irq(dev->irq, dev); in pcnet32_open()
2325 * etc.). Modern LANCE variants always reload their ring-buffer
2329 * sent (in effect, drop the packets on the floor) - the higher-level
2331 * these skbs to a temp list and then actually re-Tx them after
2340 for (i = 0; i < lp->tx_ring_size; i++) { in pcnet32_purge_tx_ring()
2341 lp->tx_ring[i].status = 0; /* CPU owns buffer */ in pcnet32_purge_tx_ring()
2343 if (lp->tx_skbuff[i]) { in pcnet32_purge_tx_ring()
2344 if (!dma_mapping_error(&lp->pci_dev->dev, lp->tx_dma_addr[i])) in pcnet32_purge_tx_ring()
2345 dma_unmap_single(&lp->pci_dev->dev, in pcnet32_purge_tx_ring()
2346 lp->tx_dma_addr[i], in pcnet32_purge_tx_ring()
2347 lp->tx_skbuff[i]->len, in pcnet32_purge_tx_ring()
2349 dev_kfree_skb_any(lp->tx_skbuff[i]); in pcnet32_purge_tx_ring()
2351 lp->tx_skbuff[i] = NULL; in pcnet32_purge_tx_ring()
2352 lp->tx_dma_addr[i] = 0; in pcnet32_purge_tx_ring()
2362 lp->tx_full = 0; in pcnet32_init_ring()
2363 lp->cur_rx = lp->cur_tx = 0; in pcnet32_init_ring()
2364 lp->dirty_rx = lp->dirty_tx = 0; in pcnet32_init_ring()
2366 for (i = 0; i < lp->rx_ring_size; i++) { in pcnet32_init_ring()
2367 struct sk_buff *rx_skbuff = lp->rx_skbuff[i]; in pcnet32_init_ring()
2369 lp->rx_skbuff[i] = netdev_alloc_skb(dev, PKT_BUF_SKB); in pcnet32_init_ring()
2370 rx_skbuff = lp->rx_skbuff[i]; in pcnet32_init_ring()
2375 return -1; in pcnet32_init_ring()
2381 if (lp->rx_dma_addr[i] == 0) { in pcnet32_init_ring()
2382 lp->rx_dma_addr[i] = in pcnet32_init_ring()
2383 dma_map_single(&lp->pci_dev->dev, rx_skbuff->data, in pcnet32_init_ring()
2385 if (dma_mapping_error(&lp->pci_dev->dev, lp->rx_dma_addr[i])) { in pcnet32_init_ring()
2390 return -1; in pcnet32_init_ring()
2393 lp->rx_ring[i].base = cpu_to_le32(lp->rx_dma_addr[i]); in pcnet32_init_ring()
2394 lp->rx_ring[i].buf_length = cpu_to_le16(NEG_BUF_SIZE); in pcnet32_init_ring()
2396 lp->rx_ring[i].status = cpu_to_le16(0x8000); in pcnet32_init_ring()
2400 for (i = 0; i < lp->tx_ring_size; i++) { in pcnet32_init_ring()
2401 lp->tx_ring[i].status = 0; /* CPU owns buffer */ in pcnet32_init_ring()
2403 lp->tx_ring[i].base = 0; in pcnet32_init_ring()
2404 lp->tx_dma_addr[i] = 0; in pcnet32_init_ring()
2407 lp->init_block->tlen_rlen = in pcnet32_init_ring()
2408 cpu_to_le16(lp->tx_len_bits | lp->rx_len_bits); in pcnet32_init_ring()
2410 lp->init_block->phys_addr[i] = dev->dev_addr[i]; in pcnet32_init_ring()
2411 lp->init_block->rx_ring = cpu_to_le32(lp->rx_ring_dma_addr); in pcnet32_init_ring()
2412 lp->init_block->tx_ring = cpu_to_le32(lp->tx_ring_dma_addr); in pcnet32_init_ring()
2418 * then flush the pending transmit operations, re-initialize the ring,
2424 unsigned long ioaddr = dev->base_addr; in pcnet32_restart()
2428 for (i = 0; i < 100; i++) in pcnet32_restart()
2429 if (lp->a->read_csr(ioaddr, CSR0) & CSR0_STOP) in pcnet32_restart()
2432 if (i >= 100) in pcnet32_restart()
2441 lp->a->write_csr(ioaddr, CSR0, CSR0_INIT); in pcnet32_restart()
2444 if (lp->a->read_csr(ioaddr, CSR0) & CSR0_IDON) in pcnet32_restart()
2447 lp->a->write_csr(ioaddr, CSR0, csr0_bits); in pcnet32_restart()
2453 unsigned long ioaddr = dev->base_addr, flags; in pcnet32_tx_timeout()
2455 spin_lock_irqsave(&lp->lock, flags); in pcnet32_tx_timeout()
2459 dev->name, lp->a->read_csr(ioaddr, CSR0)); in pcnet32_tx_timeout()
2460 lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); in pcnet32_tx_timeout()
2461 dev->stats.tx_errors++; in pcnet32_tx_timeout()
2466 lp->dirty_tx, lp->cur_tx, lp->tx_full ? " (full)" : "", in pcnet32_tx_timeout()
2467 lp->cur_rx); in pcnet32_tx_timeout()
2468 for (i = 0; i < lp->rx_ring_size; i++) in pcnet32_tx_timeout()
2470 le32_to_cpu(lp->rx_ring[i].base), in pcnet32_tx_timeout()
2471 (-le16_to_cpu(lp->rx_ring[i].buf_length)) & in pcnet32_tx_timeout()
2472 0xffff, le32_to_cpu(lp->rx_ring[i].msg_length), in pcnet32_tx_timeout()
2473 le16_to_cpu(lp->rx_ring[i].status)); in pcnet32_tx_timeout()
2474 for (i = 0; i < lp->tx_ring_size; i++) in pcnet32_tx_timeout()
2476 le32_to_cpu(lp->tx_ring[i].base), in pcnet32_tx_timeout()
2477 (-le16_to_cpu(lp->tx_ring[i].length)) & 0xffff, in pcnet32_tx_timeout()
2478 le32_to_cpu(lp->tx_ring[i].misc), in pcnet32_tx_timeout()
2479 le16_to_cpu(lp->tx_ring[i].status)); in pcnet32_tx_timeout()
2487 spin_unlock_irqrestore(&lp->lock, flags); in pcnet32_tx_timeout()
2494 unsigned long ioaddr = dev->base_addr; in pcnet32_start_xmit()
2499 spin_lock_irqsave(&lp->lock, flags); in pcnet32_start_xmit()
2503 __func__, lp->a->read_csr(ioaddr, CSR0)); in pcnet32_start_xmit()
2505 /* Default status -- will not enable Successful-TxDone in pcnet32_start_xmit()
2513 entry = lp->cur_tx & lp->tx_mod_mask; in pcnet32_start_xmit()
2518 lp->tx_ring[entry].length = cpu_to_le16(-skb->len); in pcnet32_start_xmit()
2520 lp->tx_ring[entry].misc = 0x00000000; in pcnet32_start_xmit()
2522 lp->tx_dma_addr[entry] = in pcnet32_start_xmit()
2523 dma_map_single(&lp->pci_dev->dev, skb->data, skb->len, in pcnet32_start_xmit()
2525 if (dma_mapping_error(&lp->pci_dev->dev, lp->tx_dma_addr[entry])) { in pcnet32_start_xmit()
2527 dev->stats.tx_dropped++; in pcnet32_start_xmit()
2530 lp->tx_skbuff[entry] = skb; in pcnet32_start_xmit()
2531 lp->tx_ring[entry].base = cpu_to_le32(lp->tx_dma_addr[entry]); in pcnet32_start_xmit()
2533 lp->tx_ring[entry].status = cpu_to_le16(status); in pcnet32_start_xmit()
2535 lp->cur_tx++; in pcnet32_start_xmit()
2536 dev->stats.tx_bytes += skb->len; in pcnet32_start_xmit()
2539 lp->a->write_csr(ioaddr, CSR0, CSR0_INTEN | CSR0_TXPOLL); in pcnet32_start_xmit()
2541 if (lp->tx_ring[(entry + 1) & lp->tx_mod_mask].base != 0) { in pcnet32_start_xmit()
2542 lp->tx_full = 1; in pcnet32_start_xmit()
2546 spin_unlock_irqrestore(&lp->lock, flags); in pcnet32_start_xmit()
2560 ioaddr = dev->base_addr; in pcnet32_interrupt()
2563 spin_lock(&lp->lock); in pcnet32_interrupt()
2565 csr0 = lp->a->read_csr(ioaddr, CSR0); in pcnet32_interrupt()
2566 while ((csr0 & 0x8f00) && --boguscnt >= 0) { in pcnet32_interrupt()
2570 lp->a->write_csr(ioaddr, CSR0, csr0 & ~0x004f); in pcnet32_interrupt()
2574 csr0, lp->a->read_csr(ioaddr, CSR0)); in pcnet32_interrupt()
2578 dev->stats.tx_errors++; /* Tx babble. */ in pcnet32_interrupt()
2591 dev->stats.rx_errors++; /* Missed a Rx frame. */ in pcnet32_interrupt()
2598 if (napi_schedule_prep(&lp->napi)) { in pcnet32_interrupt()
2601 val = lp->a->read_csr(ioaddr, CSR3); in pcnet32_interrupt()
2603 lp->a->write_csr(ioaddr, CSR3, val); in pcnet32_interrupt()
2605 __napi_schedule(&lp->napi); in pcnet32_interrupt()
2608 csr0 = lp->a->read_csr(ioaddr, CSR0); in pcnet32_interrupt()
2613 lp->a->read_csr(ioaddr, CSR0)); in pcnet32_interrupt()
2615 spin_unlock(&lp->lock); in pcnet32_interrupt()
2622 unsigned long ioaddr = dev->base_addr; in pcnet32_close()
2626 del_timer_sync(&lp->watchdog_timer); in pcnet32_close()
2629 napi_disable(&lp->napi); in pcnet32_close()
2631 spin_lock_irqsave(&lp->lock, flags); in pcnet32_close()
2633 dev->stats.rx_missed_errors = lp->a->read_csr(ioaddr, 112); in pcnet32_close()
2637 lp->a->read_csr(ioaddr, CSR0)); in pcnet32_close()
2639 /* We stop the PCNET32 here -- it occasionally polls memory if we don't. */ in pcnet32_close()
2640 lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); in pcnet32_close()
2646 lp->a->write_bcr(ioaddr, 20, 4); in pcnet32_close()
2648 spin_unlock_irqrestore(&lp->lock, flags); in pcnet32_close()
2650 free_irq(dev->irq, dev); in pcnet32_close()
2652 spin_lock_irqsave(&lp->lock, flags); in pcnet32_close()
2657 spin_unlock_irqrestore(&lp->lock, flags); in pcnet32_close()
2665 unsigned long ioaddr = dev->base_addr; in pcnet32_get_stats()
2668 spin_lock_irqsave(&lp->lock, flags); in pcnet32_get_stats()
2669 dev->stats.rx_missed_errors = lp->a->read_csr(ioaddr, 112); in pcnet32_get_stats()
2670 spin_unlock_irqrestore(&lp->lock, flags); in pcnet32_get_stats()
2672 return &dev->stats; in pcnet32_get_stats()
2679 volatile struct pcnet32_init_block *ib = lp->init_block; in pcnet32_load_multicast()
2680 volatile __le16 *mcast_table = (__le16 *)ib->filter; in pcnet32_load_multicast()
2682 unsigned long ioaddr = dev->base_addr; in pcnet32_load_multicast()
2687 if (dev->flags & IFF_ALLMULTI) { in pcnet32_load_multicast()
2688 ib->filter[0] = cpu_to_le32(~0U); in pcnet32_load_multicast()
2689 ib->filter[1] = cpu_to_le32(~0U); in pcnet32_load_multicast()
2690 lp->a->write_csr(ioaddr, PCNET32_MC_FILTER, 0xffff); in pcnet32_load_multicast()
2691 lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+1, 0xffff); in pcnet32_load_multicast()
2692 lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+2, 0xffff); in pcnet32_load_multicast()
2693 lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+3, 0xffff); in pcnet32_load_multicast()
2697 ib->filter[0] = 0; in pcnet32_load_multicast()
2698 ib->filter[1] = 0; in pcnet32_load_multicast()
2702 crc = ether_crc_le(6, ha->addr); in pcnet32_load_multicast()
2707 lp->a->write_csr(ioaddr, PCNET32_MC_FILTER + i, in pcnet32_load_multicast()
2716 unsigned long ioaddr = dev->base_addr, flags; in pcnet32_set_multicast_list()
2720 spin_lock_irqsave(&lp->lock, flags); in pcnet32_set_multicast_list()
2722 csr15 = lp->a->read_csr(ioaddr, CSR15); in pcnet32_set_multicast_list()
2723 if (dev->flags & IFF_PROMISC) { in pcnet32_set_multicast_list()
2726 lp->init_block->mode = in pcnet32_set_multicast_list()
2727 cpu_to_le16(0x8000 | (lp->options & PCNET32_PORT_PORTSEL) << in pcnet32_set_multicast_list()
2729 lp->a->write_csr(ioaddr, CSR15, csr15 | 0x8000); in pcnet32_set_multicast_list()
2731 lp->init_block->mode = in pcnet32_set_multicast_list()
2732 cpu_to_le16((lp->options & PCNET32_PORT_PORTSEL) << 7); in pcnet32_set_multicast_list()
2733 lp->a->write_csr(ioaddr, CSR15, csr15 & 0x7fff); in pcnet32_set_multicast_list()
2740 lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); in pcnet32_set_multicast_list()
2745 spin_unlock_irqrestore(&lp->lock, flags); in pcnet32_set_multicast_list()
2748 /* This routine assumes that the lp->lock is held */
2752 unsigned long ioaddr = dev->base_addr; in mdio_read()
2755 if (!lp->mii) in mdio_read()
2758 lp->a->write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f)); in mdio_read()
2759 val_out = lp->a->read_bcr(ioaddr, 34); in mdio_read()
2764 /* This routine assumes that the lp->lock is held */
2768 unsigned long ioaddr = dev->base_addr; in mdio_write()
2770 if (!lp->mii) in mdio_write()
2773 lp->a->write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f)); in mdio_write()
2774 lp->a->write_bcr(ioaddr, 34, val); in mdio_write()
2784 if (lp->mii) { in pcnet32_ioctl()
2785 spin_lock_irqsave(&lp->lock, flags); in pcnet32_ioctl()
2786 rc = generic_mii_ioctl(&lp->mii_if, if_mii(rq), cmd, NULL); in pcnet32_ioctl()
2787 spin_unlock_irqrestore(&lp->lock, flags); in pcnet32_ioctl()
2789 rc = -EOPNOTSUPP; in pcnet32_ioctl()
2798 struct mii_if_info mii = lp->mii_if; in pcnet32_check_otherphy()
2803 if (i == lp->mii_if.phy_id) in pcnet32_check_otherphy()
2805 if (lp->phymask & (1 << i)) { in pcnet32_check_otherphy()
2814 mdio_read(dev, lp->mii_if.phy_id, MII_BMCR); in pcnet32_check_otherphy()
2815 mdio_write(dev, lp->mii_if.phy_id, MII_BMCR, in pcnet32_check_otherphy()
2818 /* de-isolate new phy */ in pcnet32_check_otherphy()
2824 lp->mii_if.phy_id = i; in pcnet32_check_otherphy()
2837 * Caller is assumed to hold and release the lp->lock.
2847 if (lp->mii) { in pcnet32_check_media()
2848 curr_link = mii_link_ok(&lp->mii_if); in pcnet32_check_media()
2849 } else if (lp->chip_version == PCNET32_79C970A) { in pcnet32_check_media()
2850 ulong ioaddr = dev->base_addr; /* card base I/O address */ in pcnet32_check_media()
2852 if (!lp->autoneg && lp->port_tp) in pcnet32_check_media()
2853 curr_link = (lp->a->read_bcr(ioaddr, 4) != 0xc0); in pcnet32_check_media()
2857 ulong ioaddr = dev->base_addr; /* card base I/O address */ in pcnet32_check_media()
2858 curr_link = (lp->a->read_bcr(ioaddr, 4) != 0xc0); in pcnet32_check_media()
2865 if (lp->phycount > 1) { in pcnet32_check_media()
2870 if (lp->mii) { in pcnet32_check_media()
2874 mii_ethtool_gset(&lp->mii_if, &ecmd); in pcnet32_check_media()
2875 netdev_info(dev, "link up, %uMbps, %s-duplex\n", in pcnet32_check_media()
2880 bcr9 = lp->a->read_bcr(dev->base_addr, 9); in pcnet32_check_media()
2881 if ((bcr9 & (1 << 0)) != lp->mii_if.full_duplex) { in pcnet32_check_media()
2882 if (lp->mii_if.full_duplex) in pcnet32_check_media()
2886 lp->a->write_bcr(dev->base_addr, 9, bcr9); in pcnet32_check_media()
2902 struct net_device *dev = lp->dev; in pcnet32_watchdog()
2906 spin_lock_irqsave(&lp->lock, flags); in pcnet32_watchdog()
2908 spin_unlock_irqrestore(&lp->lock, flags); in pcnet32_watchdog()
2910 mod_timer(&lp->watchdog_timer, round_jiffies(PCNET32_WATCHDOG_TIMEOUT)); in pcnet32_watchdog()
2946 release_region(dev->base_addr, PCNET32_TOTAL_SIZE); in pcnet32_remove_one()
2947 dma_free_coherent(&lp->pci_dev->dev, sizeof(*lp->init_block), in pcnet32_remove_one()
2948 lp->init_block, lp->init_dma_addr); in pcnet32_remove_one()
2967 static int debug = -1;
2968 static int tx_start_pt = -1;
2978 DRV_NAME " copy breakpoint for copy-only-tiny-frames");
2980 MODULE_PARM_DESC(tx_start_pt, DRV_NAME " transmit start point (0-3)");
2984 MODULE_PARM_DESC(options, DRV_NAME " initial option setting(s) (0-15)");
3017 return (pcnet32_have_pci + cards_found) ? 0 : -ENODEV; in pcnet32_init_module()
3026 next_dev = lp->next; in pcnet32_cleanup_module()
3029 release_region(pcnet32_dev->base_addr, PCNET32_TOTAL_SIZE); in pcnet32_cleanup_module()
3030 dma_free_coherent(&lp->pci_dev->dev, sizeof(*lp->init_block), in pcnet32_cleanup_module()
3031 lp->init_block, lp->init_dma_addr); in pcnet32_cleanup_module()