24 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26 #define DRV_NAME "pcnet32"
27 #define DRV_VERSION "1.35"
28 #define DRV_RELDATE "21.Apr.2008"
29 #define PFX DRV_NAME ": "
31 static const char *
const version =
34 #include <linux/module.h>
35 #include <linux/kernel.h>
36 #include <linux/sched.h>
37 #include <linux/string.h>
38 #include <linux/errno.h>
40 #include <linux/slab.h>
42 #include <linux/pci.h>
45 #include <linux/ethtool.h>
46 #include <linux/mii.h>
48 #include <linux/netdevice.h>
50 #include <linux/if_ether.h>
54 #include <linux/bitops.h>
80 static int cards_found;
85 static unsigned int pcnet32_portlist[] =
86 { 0x300, 0x320, 0x340, 0x360, 0 };
88 static int pcnet32_debug;
90 static int pcnet32vlb;
94 static int max_interrupt_work = 2;
95 static int rx_copybreak = 200;
97 #define PCNET32_PORT_AUI 0x00
98 #define PCNET32_PORT_10BT 0x01
99 #define PCNET32_PORT_GPSI 0x02
100 #define PCNET32_PORT_MII 0x03
102 #define PCNET32_PORT_PORTSEL 0x03
103 #define PCNET32_PORT_ASEL 0x04
104 #define PCNET32_PORT_100 0x40
105 #define PCNET32_PORT_FD 0x80
107 #define PCNET32_DMA_MASK 0xffffffff
109 #define PCNET32_WATCHDOG_TIMEOUT (jiffies + (2 * HZ))
110 #define PCNET32_BLINK_TIMEOUT (jiffies + (HZ/4))
116 static const unsigned char options_mapping[] = {
137 "Loopback test (offline)"
140 #define PCNET32_TEST_LEN ARRAY_SIZE(pcnet32_gstrings_test)
142 #define PCNET32_NUM_REGS 136
164 #ifndef PCNET32_LOG_TX_BUFFERS
165 #define PCNET32_LOG_TX_BUFFERS 4
166 #define PCNET32_LOG_RX_BUFFERS 5
167 #define PCNET32_LOG_MAX_TX_BUFFERS 9
168 #define PCNET32_LOG_MAX_RX_BUFFERS 9
171 #define TX_RING_SIZE (1 << (PCNET32_LOG_TX_BUFFERS))
172 #define TX_MAX_RING_SIZE (1 << (PCNET32_LOG_MAX_TX_BUFFERS))
174 #define RX_RING_SIZE (1 << (PCNET32_LOG_RX_BUFFERS))
175 #define RX_MAX_RING_SIZE (1 << (PCNET32_LOG_MAX_RX_BUFFERS))
177 #define PKT_BUF_SKB 1544
179 #define PKT_BUF_SIZE (PKT_BUF_SKB - NET_IP_ALIGN)
181 #define NEG_BUF_SIZE (NET_IP_ALIGN - PKT_BUF_SKB)
184 #define PCNET32_WIO_RDP 0x10
185 #define PCNET32_WIO_RAP 0x12
186 #define PCNET32_WIO_RESET 0x14
187 #define PCNET32_WIO_BDP 0x16
189 #define PCNET32_DWIO_RDP 0x10
190 #define PCNET32_DWIO_RAP 0x14
191 #define PCNET32_DWIO_RESET 0x18
192 #define PCNET32_DWIO_BDP 0x1C
194 #define PCNET32_TOTAL_SIZE 0x20
197 #define CSR0_INIT 0x1
198 #define CSR0_START 0x2
199 #define CSR0_STOP 0x4
200 #define CSR0_TXPOLL 0x8
201 #define CSR0_INTEN 0x40
202 #define CSR0_IDON 0x0100
203 #define CSR0_NORMAL (CSR0_START | CSR0_INTEN)
204 #define PCNET32_INIT_LOW 1
205 #define PCNET32_INIT_HIGH 2
209 #define CSR5_SUSPEND 0x0001
211 #define PCNET32_MC_FILTER 8
213 #define PCNET32_79C970A 0x2621
309 static int pcnet32_probe1(
unsigned long,
int,
struct pci_dev *);
311 static int pcnet32_init_ring(
struct net_device *);
316 static int pcnet32_close(
struct net_device *);
319 static void pcnet32_set_multicast_list(
struct net_device *);
321 static void pcnet32_watchdog(
struct net_device *);
325 static void pcnet32_restart(
struct net_device *
dev,
unsigned int csr0_bits);
337 static u16 pcnet32_wio_read_csr(
unsigned long addr,
int index)
343 static void pcnet32_wio_write_csr(
unsigned long addr,
int index,
u16 val)
349 static u16 pcnet32_wio_read_bcr(
unsigned long addr,
int index)
355 static void pcnet32_wio_write_bcr(
unsigned long addr,
int index,
u16 val)
361 static u16 pcnet32_wio_read_rap(
unsigned long addr)
366 static void pcnet32_wio_write_rap(
unsigned long addr,
u16 val)
371 static void pcnet32_wio_reset(
unsigned long addr)
376 static int pcnet32_wio_check(
unsigned long addr)
383 .read_csr = pcnet32_wio_read_csr,
384 .write_csr = pcnet32_wio_write_csr,
385 .read_bcr = pcnet32_wio_read_bcr,
386 .write_bcr = pcnet32_wio_write_bcr,
387 .read_rap = pcnet32_wio_read_rap,
388 .write_rap = pcnet32_wio_write_rap,
389 .reset = pcnet32_wio_reset
392 static u16 pcnet32_dwio_read_csr(
unsigned long addr,
int index)
398 static void pcnet32_dwio_write_csr(
unsigned long addr,
int index,
u16 val)
404 static u16 pcnet32_dwio_read_bcr(
unsigned long addr,
int index)
410 static void pcnet32_dwio_write_bcr(
unsigned long addr,
int index,
u16 val)
416 static u16 pcnet32_dwio_read_rap(
unsigned long addr)
421 static void pcnet32_dwio_write_rap(
unsigned long addr,
u16 val)
426 static void pcnet32_dwio_reset(
unsigned long addr)
431 static int pcnet32_dwio_check(
unsigned long addr)
438 .read_csr = pcnet32_dwio_read_csr,
439 .write_csr = pcnet32_dwio_write_csr,
440 .read_bcr = pcnet32_dwio_read_bcr,
441 .write_bcr = pcnet32_dwio_write_bcr,
442 .read_rap = pcnet32_dwio_read_rap,
443 .write_rap = pcnet32_dwio_write_rap,
444 .reset = pcnet32_dwio_reset
452 napi_disable(&lp->
napi);
453 netif_tx_disable(dev);
462 netif_wake_queue(dev);
463 val = lp->
a->read_csr(ioaddr,
CSR3);
465 lp->
a->write_csr(ioaddr,
CSR3, val);
466 napi_enable(&lp->
napi);
476 static void pcnet32_realloc_tx_ring(
struct net_device *dev,
485 pcnet32_purge_tx_ring(dev);
491 if (new_tx_ring ==
NULL) {
492 netif_err(lp, drv, dev,
"Consistent memory allocation failed\n");
497 new_dma_addr_list = kcalloc((1 << size),
sizeof(
dma_addr_t),
499 if (!new_dma_addr_list) {
500 netif_err(lp, drv, dev,
"Memory allocation failed\n");
501 goto free_new_tx_ring;
504 new_skb_list = kcalloc((1 << size),
sizeof(
struct sk_buff *),
507 netif_err(lp, drv, dev,
"Memory allocation failed\n");
528 kfree(new_dma_addr_list);
547 static void pcnet32_realloc_rx_ring(
struct net_device *dev,
561 if (new_rx_ring ==
NULL) {
562 netif_err(lp, drv, dev,
"Consistent memory allocation failed\n");
567 new_dma_addr_list = kcalloc((1 << size),
sizeof(
dma_addr_t),
569 if (!new_dma_addr_list) {
570 netif_err(lp, drv, dev,
"Memory allocation failed\n");
571 goto free_new_rx_ring;
574 new_skb_list = kcalloc((1 << size),
sizeof(
struct sk_buff *),
577 netif_err(lp, drv, dev,
"Memory allocation failed\n");
583 for (
new = 0;
new < overlap;
new++) {
584 new_rx_ring[
new] = lp->
rx_ring[
new];
589 for (;
new <
size;
new++) {
591 new_skb_list[
new] = netdev_alloc_skb(dev,
PKT_BUF_SKB);
592 rx_skbuff = new_skb_list[
new];
595 netif_err(lp, drv, dev,
"%s netdev_alloc_skb failed\n",
601 new_dma_addr_list[
new] =
635 if (new_skb_list[
new]) {
636 pci_unmap_single(lp->
pci_dev, new_dma_addr_list[
new],
638 dev_kfree_skb(new_skb_list[
new]);
643 kfree(new_dma_addr_list);
652 static void pcnet32_purge_rx_ring(
struct net_device *dev)
671 #ifdef CONFIG_NET_POLL_CONTROLLER
672 static void pcnet32_poll_controller(
struct net_device *dev)
675 pcnet32_interrupt(0, dev);
689 spin_unlock_irqrestore(&lp->
lock, flags);
704 spin_unlock_irqrestore(&lp->
lock, flags);
709 static void pcnet32_get_drvinfo(
struct net_device *dev,
735 r = (lp->
a->read_bcr(ioaddr, 4) != 0xc0);
739 spin_unlock_irqrestore(&lp->
lock, flags);
756 static int pcnet32_nway_reset(
struct net_device *dev)
765 spin_unlock_irqrestore(&lp->
lock, flags);
770 static void pcnet32_get_ringparam(
struct net_device *dev,
781 static int pcnet32_set_ringparam(
struct net_device *dev,
793 if (netif_running(dev))
794 pcnet32_netif_stop(dev);
805 if (size <= (1 << i))
809 pcnet32_realloc_tx_ring(dev, lp, i);
813 if (size <= (1 << i))
817 pcnet32_realloc_rx_ring(dev, lp, i);
821 if (netif_running(dev)) {
822 pcnet32_netif_start(dev);
826 spin_unlock_irqrestore(&lp->
lock, flags);
828 netif_info(lp, drv, dev,
"Ring Param Settings: RX: %d, TX: %d\n",
834 static void pcnet32_get_strings(
struct net_device *dev,
u32 stringset,
837 memcpy(data, pcnet32_gstrings_test,
sizeof(pcnet32_gstrings_test));
840 static int pcnet32_get_sset_count(
struct net_device *dev,
int sset)
850 static void pcnet32_ethtool_test(
struct net_device *dev,
857 rc = pcnet32_loopback_test(dev, data);
860 "Loopback test failed\n");
864 "Loopback test passed\n");
867 "No tests to run (specify 'Offline' on ethtool)\n");
889 if (netif_running(dev))
890 pcnet32_netif_stop(dev);
898 lp->
a->reset(ioaddr);
899 lp->
a->write_csr(ioaddr,
CSR4, 0x0915);
902 lp->
a->write_bcr(ioaddr, 20, 2);
905 pcnet32_restart(dev, 0x0000);
910 size = data_len + 15;
911 for (x = 0; x < numbuffs; x++) {
912 skb = netdev_alloc_skb(dev, size);
915 "Cannot allocate skb at line: %d!\n",
926 for (i = 0; i < 6; i++)
928 for (i = 0; i < 6; i++)
952 lp->
a->write_csr(ioaddr,
CSR15, x | 0x0044);
958 for (x = 0; x < numbuffs; x++) {
961 while ((lp->
rx_ring[x].status & teststatus) && (ticks < 200)) {
962 spin_unlock_irqrestore(&lp->
lock, flags);
969 netif_err(lp,
hw, dev,
"Desc %d failed to reset!\n", x);
979 for (x = 0; x < numbuffs; x++) {
982 for (i = 0; i <
size; i++)
990 while (x < numbuffs && !rc) {
993 for (i = 0; i <
size; i++) {
994 if (*(skb->
data + i) != packet[i]) {
996 "Error in compare! %2x - %02x %02x\n",
997 i, *(skb->
data + i), packet[i]);
1007 pcnet32_purge_tx_ring(dev);
1013 a->
write_bcr(ioaddr, 32, (x & ~0x0002));
1015 if (netif_running(dev)) {
1016 pcnet32_netif_start(dev);
1019 pcnet32_purge_rx_ring(dev);
1020 lp->
a->write_bcr(ioaddr, 20, 4);
1022 spin_unlock_irqrestore(&lp->
lock, flags);
1027 static int pcnet32_set_phys_id(
struct net_device *dev,
1033 unsigned long flags;
1040 for (i = 4; i < 8; i++)
1042 spin_unlock_irqrestore(&lp->
lock, flags);
1049 for (i = 4; i < 8; i++)
1051 spin_unlock_irqrestore(&lp->
lock, flags);
1057 for (i = 4; i < 8; i++)
1059 spin_unlock_irqrestore(&lp->
lock, flags);
1067 static int pcnet32_suspend(
struct net_device *dev,
unsigned long *flags,
1087 spin_unlock_irqrestore(&lp->
lock, *flags);
1096 "Error getting into suspend!\n");
1107 static void pcnet32_rx_entry(
struct net_device *dev,
1113 int rx_in_place = 0;
1117 if (status != 0x03) {
1125 dev->
stats.rx_errors++;
1127 dev->
stats.rx_frame_errors++;
1129 dev->
stats.rx_over_errors++;
1131 dev->
stats.rx_crc_errors++;
1133 dev->
stats.rx_fifo_errors++;
1141 netif_err(lp, drv, dev,
"Impossible packet size %d!\n",
1143 dev->
stats.rx_errors++;
1147 netif_err(lp, rx_err, dev,
"Runt packet!\n");
1148 dev->
stats.rx_errors++;
1152 if (pkt_len > rx_copybreak) {
1178 netif_err(lp, drv, dev,
"Memory squeeze, dropping packet\n");
1179 dev->
stats.rx_dropped++;
1185 pci_dma_sync_single_for_cpu(lp->
pci_dev,
1189 skb_copy_to_linear_data(skb,
1190 (
unsigned char *)(lp->
rx_skbuff[entry]->data),
1192 pci_dma_sync_single_for_device(lp->
pci_dev,
1200 dev->
stats.rx_packets++;
1212 pcnet32_rx_entry(dev, lp, rxp, entry);
1228 static int pcnet32_tx(
struct net_device *dev)
1233 int must_restart = 0;
1235 while (dirty_tx != lp->
cur_tx) {
1244 if (status & 0x4000) {
1247 dev->
stats.tx_errors++;
1249 "Tx error status=%04x err_status=%08x\n",
1250 status, err_status);
1251 if (err_status & 0x04000000)
1252 dev->
stats.tx_aborted_errors++;
1253 if (err_status & 0x08000000)
1254 dev->
stats.tx_carrier_errors++;
1255 if (err_status & 0x10000000)
1256 dev->
stats.tx_window_errors++;
1258 if (err_status & 0x40000000) {
1259 dev->
stats.tx_fifo_errors++;
1262 netif_err(lp, tx_err, dev,
"Tx FIFO error!\n");
1266 if (err_status & 0x40000000) {
1267 dev->
stats.tx_fifo_errors++;
1271 netif_err(lp, tx_err, dev,
"Tx FIFO error!\n");
1277 if (status & 0x1800)
1278 dev->
stats.collisions++;
1279 dev->
stats.tx_packets++;
1297 netif_err(lp, drv, dev,
"out-of-sync dirty pointer, %d vs. %d, full=%d\n",
1304 netif_queue_stopped(dev) &&
1308 netif_wake_queue(dev);
1312 return must_restart;
1320 unsigned long flags;
1324 work_done = pcnet32_rx(dev, budget);
1327 if (pcnet32_tx(dev)) {
1329 lp->
a->reset(ioaddr);
1330 lp->
a->write_csr(ioaddr,
CSR4, 0x0915);
1332 netif_wake_queue(dev);
1334 spin_unlock_irqrestore(&lp->
lock, flags);
1336 if (work_done < budget) {
1342 val = lp->
a->read_csr(ioaddr,
CSR3);
1344 lp->
a->write_csr(ioaddr,
CSR3, val);
1349 spin_unlock_irqrestore(&lp->
lock, flags);
1354 #define PCNET32_REGS_PER_PHY 32
1355 #define PCNET32_MAX_PHYS 32
1356 static int pcnet32_get_regs_len(
struct net_device *dev)
1372 unsigned long flags;
1378 pcnet32_suspend(dev, &flags, 1);
1381 for (i = 0; i < 16; i += 2)
1382 *buff++ =
inw(ioaddr + i);
1385 for (i = 0; i < 90; i++)
1388 *buff++ = a->
read_csr(ioaddr, 112);
1389 *buff++ = a->
read_csr(ioaddr, 114);
1392 for (i = 0; i < 30; i++)
1397 for (i = 31; i < 36; i++)
1406 lp->
a->write_bcr(ioaddr, 33,
1408 *buff++ = lp->
a->read_bcr(ioaddr, 34);
1414 if (!(csr0 & CSR0_STOP)) {
1422 spin_unlock_irqrestore(&lp->
lock, flags);
1425 static const struct ethtool_ops pcnet32_ethtool_ops = {
1426 .get_settings = pcnet32_get_settings,
1427 .set_settings = pcnet32_set_settings,
1428 .get_drvinfo = pcnet32_get_drvinfo,
1429 .get_msglevel = pcnet32_get_msglevel,
1430 .set_msglevel = pcnet32_set_msglevel,
1431 .nway_reset = pcnet32_nway_reset,
1432 .get_link = pcnet32_get_link,
1433 .get_ringparam = pcnet32_get_ringparam,
1434 .set_ringparam = pcnet32_set_ringparam,
1435 .get_strings = pcnet32_get_strings,
1436 .self_test = pcnet32_ethtool_test,
1437 .set_phys_id = pcnet32_set_phys_id,
1438 .get_regs_len = pcnet32_get_regs_len,
1439 .get_regs = pcnet32_get_regs,
1440 .get_sset_count = pcnet32_get_sset_count,
1446 static void __devinit pcnet32_probe_vlbus(
unsigned int *pcnet32_portlist)
1448 unsigned int *
port, ioaddr;
1451 for (port = pcnet32_portlist; (ioaddr = *
port); port++) {
1455 if ((
inb(ioaddr + 14) == 0x57) &&
1456 (
inb(ioaddr + 15) == 0x57)) {
1457 pcnet32_probe1(ioaddr, 0,
NULL);
1468 unsigned long ioaddr;
1474 pr_err(
"failed to enable device -- err=%d\n", err);
1482 pr_err(
"card has no PCI IO resources, aborting\n");
1488 pr_err(
"architecture does not support 32bit PCI busmaster DMA\n");
1493 pr_err(
"io address range already allocated\n");
1497 err = pcnet32_probe1(ioaddr, 1, pdev);
1505 .ndo_open = pcnet32_open,
1506 .ndo_stop = pcnet32_close,
1507 .ndo_start_xmit = pcnet32_start_xmit,
1508 .ndo_tx_timeout = pcnet32_tx_timeout,
1509 .ndo_get_stats = pcnet32_get_stats,
1510 .ndo_set_rx_mode = pcnet32_set_multicast_list,
1511 .ndo_do_ioctl = pcnet32_ioctl,
1515 #ifdef CONFIG_NET_POLL_CONTROLLER
1516 .ndo_poll_controller = pcnet32_poll_controller,
1525 pcnet32_probe1(
unsigned long ioaddr,
int shared,
struct pci_dev *pdev)
1538 pcnet32_wio_reset(ioaddr);
1541 if (pcnet32_wio_read_csr(ioaddr, 0) == 4 && pcnet32_wio_check(ioaddr)) {
1544 pcnet32_dwio_reset(ioaddr);
1545 if (pcnet32_dwio_read_csr(ioaddr, 0) == 4 &&
1546 pcnet32_dwio_check(ioaddr)) {
1550 pr_err(
"No access methods\n");
1551 goto err_release_region;
1558 pr_info(
" PCnet chip version is %#x\n", chip_version);
1559 if ((chip_version & 0xfff) != 0x003) {
1560 if (pcnet32_debug & NETIF_MSG_PROBE)
1561 pr_info(
"Unsupported chip version\n");
1562 goto err_release_region;
1566 fdx = mii = fset = dxsuflo = 0;
1567 chip_version = (chip_version >> 12) & 0xffff;
1569 switch (chip_version) {
1571 chipname =
"PCnet/PCI 79C970";
1575 chipname =
"PCnet/PCI 79C970";
1577 chipname =
"PCnet/32 79C965";
1580 chipname =
"PCnet/PCI II 79C970A";
1584 chipname =
"PCnet/FAST 79C971";
1590 chipname =
"PCnet/FAST+ 79C972";
1596 chipname =
"PCnet/FAST III 79C973";
1601 chipname =
"PCnet/Home 79C978";
1611 if (cards_found <
MAX_UNITS && homepna[cards_found])
1613 if (pcnet32_debug & NETIF_MSG_PROBE)
1615 (media & 1) ?
"1" :
"10");
1619 chipname =
"PCnet/FAST III 79C975";
1624 chipname =
"PCnet/PRO 79C976";
1629 if (pcnet32_debug & NETIF_MSG_PROBE)
1630 pr_info(
"PCnet version %#x, no PCnet32 chip\n",
1632 goto err_release_region;
1646 (a->
read_csr(ioaddr, 80) & 0x0C00) | 0x0c00);
1650 dev = alloc_etherdev(
sizeof(*lp));
1653 goto err_release_region;
1659 if (pcnet32_debug & NETIF_MSG_PROBE)
1660 pr_info(
"%s at %#3lx,", chipname, ioaddr);
1669 for (i = 0; i < 3; i++) {
1671 val = a->
read_csr(ioaddr, i + 12) & 0x0ffff;
1674 dev->
dev_addr[2 * i + 1] = (val >> 8) & 0x0ff;
1678 for (i = 0; i < 6; i++)
1679 promaddr[i] =
inb(ioaddr + i);
1682 !is_valid_ether_addr(dev->
dev_addr)) {
1683 if (is_valid_ether_addr(promaddr)) {
1684 if (pcnet32_debug & NETIF_MSG_PROBE) {
1685 pr_cont(
" warning: CSR address invalid,\n");
1686 pr_info(
" using instead PROM address of");
1694 if (!is_valid_ether_addr(dev->
perm_addr))
1697 if (pcnet32_debug & NETIF_MSG_PROBE) {
1701 if (((chip_version + 1) & 0xfffe) == 0x2624) {
1702 i = a->
read_csr(ioaddr, 80) & 0x0C00;
1703 pr_info(
" tx_start_pt(0x%04x):", i);
1719 pr_cont(
" BCR18(%x):", i & 0xffff);
1729 pr_info(
" SRAMSIZE=0x%04x,", i << 8);
1731 pr_cont(
" SRAM_BND=0x%04x,", i << 8);
1739 lp = netdev_priv(dev);
1744 if (pcnet32_debug & NETIF_MSG_PROBE)
1745 pr_err(
"Consistent memory allocation failed\n");
1747 goto err_free_netdev;
1755 lp->
name = chipname;
1763 lp->
mii_if.full_duplex = fdx;
1764 lp->
mii_if.phy_id_mask = 0x1f;
1765 lp->
mii_if.reg_num_mask = 0x1f;
1771 (options[cards_found] >=
sizeof(options_mapping)))
1774 lp->
options = options_mapping[options[cards_found]];
1776 lp->
mii_if.mdio_read = mdio_read;
1777 lp->
mii_if.mdio_write = mdio_write;
1785 ((cards_found >=
MAX_UNITS) || full_duplex[cards_found]))
1791 if (pcnet32_alloc_ring(dev, pci_name(lp->
pci_dev))) {
1803 for (i = 0; i < 6; i++)
1818 if (pcnet32_debug & NETIF_MSG_PROBE)
1834 if (pcnet32_debug & NETIF_MSG_PROBE)
1835 pr_cont(
", failed to detect IRQ line\n");
1839 if (pcnet32_debug & NETIF_MSG_PROBE)
1847 lp->
mii_if.phy_id = ((lp->
a->read_bcr(ioaddr, 33)) >> 5) & 0x1f;
1858 if (i == 31 && ((chip_version + 1) & 0xfffe) == 0x2624)
1863 if (pcnet32_debug & NETIF_MSG_PROBE)
1864 pr_info(
"Found PHY %04x:%04x at address %d\n",
1867 lp->
a->write_bcr(ioaddr, 33, (lp->
mii_if.phy_id) << 5);
1886 pci_set_drvdata(pdev, dev);
1888 lp->
next = pcnet32_dev;
1892 if (pcnet32_debug & NETIF_MSG_PROBE)
1902 pcnet32_free_ring(dev);
1913 static int pcnet32_alloc_ring(
struct net_device *dev,
const char *
name)
1922 netif_err(lp, drv, dev,
"Consistent memory allocation failed\n");
1931 netif_err(lp, drv, dev,
"Consistent memory allocation failed\n");
1938 netif_err(lp, drv, dev,
"Memory allocation failed\n");
1945 netif_err(lp, drv, dev,
"Memory allocation failed\n");
1952 netif_err(lp, drv, dev,
"Memory allocation failed\n");
1959 netif_err(lp, drv, dev,
"Memory allocation failed\n");
1966 static void pcnet32_free_ring(
struct net_device *dev)
1999 static int pcnet32_open(
struct net_device *dev)
2007 unsigned long flags;
2017 if (!is_valid_ether_addr(dev->
dev_addr)) {
2023 lp->
a->reset(ioaddr);
2026 lp->
a->write_bcr(ioaddr, 20, 2);
2029 "%s() irq %d tx/rx rings %#x/%#x init %#x\n",
2035 val = lp->
a->read_bcr(ioaddr, 2) & ~2;
2038 lp->
a->write_bcr(ioaddr, 2, val);
2041 if (lp->
mii_if.full_duplex) {
2042 val = lp->
a->read_bcr(ioaddr, 9) & ~3;
2052 lp->
a->write_bcr(ioaddr, 9, val);
2056 val = lp->
a->read_csr(ioaddr, 124) & ~0x10;
2059 lp->
a->write_csr(ioaddr, 124, val);
2068 "Setting 100Mb-Full Duplex\n");
2078 lp->
a->write_bcr(ioaddr, 32,
2079 lp->
a->read_bcr(ioaddr, 32) | 0x0080);
2081 val = lp->
a->read_bcr(ioaddr, 32) & ~0xb8;
2086 lp->
a->write_bcr(ioaddr, 32, val);
2089 lp->
a->write_bcr(ioaddr, 32,
2090 lp->
a->read_bcr(ioaddr,
2093 val = lp->
a->read_bcr(ioaddr, 32) & ~0x98;
2095 lp->
a->write_bcr(ioaddr, 32, val);
2108 val = lp->
a->read_bcr(ioaddr, 2);
2109 lp->
a->write_bcr(ioaddr, 2, val & ~2);
2110 val = lp->
a->read_bcr(ioaddr, 32);
2111 lp->
a->write_bcr(ioaddr, 32, val & ~(1 << 7));
2118 ethtool_cmd_speed_set(&ecmd,
2121 bcr9 = lp->
a->read_bcr(ioaddr, 9);
2130 lp->
a->write_bcr(ioaddr, 9, bcr9);
2136 bmcr = mdio_read(dev, i,
MII_BMCR);
2137 if (first_phy == -1) {
2155 lp->
mii_if.phy_id = first_phy;
2161 val = lp->
a->read_csr(ioaddr,
CSR3);
2163 lp->
a->write_csr(ioaddr,
CSR3, val);
2169 pcnet32_load_multicast(dev);
2171 if (pcnet32_init_ring(dev)) {
2176 napi_enable(&lp->
napi);
2182 lp->
a->write_csr(ioaddr,
CSR4, 0x0915);
2185 netif_start_queue(dev);
2189 pcnet32_check_media(dev, 1);
2204 "pcnet32 open after %d ticks, init block %#x csr0 %4.4x\n",
2207 lp->
a->read_csr(ioaddr,
CSR0));
2209 spin_unlock_irqrestore(&lp->
lock, flags);
2215 pcnet32_purge_rx_ring(dev);
2221 lp->
a->write_bcr(ioaddr, 20, 4);
2224 spin_unlock_irqrestore(&lp->
lock, flags);
2242 static void pcnet32_purge_tx_ring(
struct net_device *dev)
2262 static int pcnet32_init_ring(
struct net_device *dev)
2273 if (rx_skbuff ==
NULL) {
2278 netif_err(lp, drv, dev,
"%s netdev_alloc_skb failed\n",
2306 for (i = 0; i < 6; i++)
2318 static void pcnet32_restart(
struct net_device *dev,
unsigned int csr0_bits)
2325 for (i = 0; i < 100; i++)
2330 netif_err(lp, drv, dev,
"%s timed out waiting for stop\n",
2333 pcnet32_purge_tx_ring(dev);
2334 if (pcnet32_init_ring(dev))
2344 lp->
a->write_csr(ioaddr,
CSR0, csr0_bits);
2347 static void pcnet32_tx_timeout(
struct net_device *dev)
2355 pr_err(
"%s: transmit timed out, status %4.4x, resetting\n",
2356 dev->
name, lp->
a->read_csr(ioaddr,
CSR0));
2357 lp->
a->write_csr(ioaddr,
CSR0, CSR0_STOP);
2358 dev->
stats.tx_errors++;
2362 " Ring data dump: dirty_tx %d cur_tx %d%s cur_rx %d.",
2366 printk(
"%s %08x %04x %08x %04x", i & 1 ?
"" :
"\n ",
2372 printk(
"%s %08x %04x %08x %04x", i & 1 ?
"" :
"\n ",
2382 netif_wake_queue(dev);
2384 spin_unlock_irqrestore(&lp->
lock, flags);
2394 unsigned long flags;
2399 "%s() called, csr0 %4.4x\n",
2400 __func__, lp->
a->read_csr(ioaddr,
CSR0));
2434 netif_stop_queue(dev);
2436 spin_unlock_irqrestore(&lp->
lock, flags);
2442 pcnet32_interrupt(
int irq,
void *
dev_id)
2446 unsigned long ioaddr;
2448 int boguscnt = max_interrupt_work;
2451 lp = netdev_priv(dev);
2453 spin_lock(&lp->
lock);
2455 csr0 = lp->
a->read_csr(ioaddr,
CSR0);
2456 while ((csr0 & 0x8f00) && --boguscnt >= 0) {
2460 lp->
a->write_csr(ioaddr,
CSR0, csr0 & ~0x004f);
2463 "interrupt csr0=%#2.2x new csr=%#2.2x\n",
2464 csr0, lp->
a->read_csr(ioaddr,
CSR0));
2468 dev->
stats.tx_errors++;
2469 if (csr0 & 0x1000) {
2481 dev->
stats.rx_errors++;
2483 if (csr0 & 0x0800) {
2484 netif_err(lp, drv, dev,
"Bus master arbitration failure, status %4.4x\n",
2488 if (napi_schedule_prep(&lp->
napi)) {
2491 val = lp->
a->read_csr(ioaddr,
CSR3);
2493 lp->
a->write_csr(ioaddr,
CSR3, val);
2498 csr0 = lp->
a->read_csr(ioaddr,
CSR0);
2502 "exiting interrupt, csr0=%#4.4x\n",
2503 lp->
a->read_csr(ioaddr,
CSR0));
2505 spin_unlock(&lp->
lock);
2510 static int pcnet32_close(
struct net_device *dev)
2514 unsigned long flags;
2518 netif_stop_queue(dev);
2519 napi_disable(&lp->
napi);
2523 dev->
stats.rx_missed_errors = lp->
a->read_csr(ioaddr, 112);
2526 "Shutting down ethercard, status was %2.2x\n",
2527 lp->
a->read_csr(ioaddr,
CSR0));
2530 lp->
a->write_csr(ioaddr,
CSR0, CSR0_STOP);
2536 lp->
a->write_bcr(ioaddr, 20, 4);
2538 spin_unlock_irqrestore(&lp->
lock, flags);
2544 pcnet32_purge_rx_ring(dev);
2545 pcnet32_purge_tx_ring(dev);
2547 spin_unlock_irqrestore(&lp->
lock, flags);
2556 unsigned long flags;
2559 dev->
stats.rx_missed_errors = lp->
a->read_csr(ioaddr, 112);
2560 spin_unlock_irqrestore(&lp->
lock, flags);
2566 static void pcnet32_load_multicast(
struct net_device *dev)
2596 for (i = 0; i < 4; i++)
2604 static void pcnet32_set_multicast_list(
struct net_device *dev)
2611 suspended = pcnet32_suspend(dev, &flags, 0);
2612 csr15 = lp->
a->read_csr(ioaddr,
CSR15);
2619 lp->
a->write_csr(ioaddr,
CSR15, csr15 | 0x8000);
2623 lp->
a->write_csr(ioaddr,
CSR15, csr15 & 0x7fff);
2624 pcnet32_load_multicast(dev);
2630 csr5 = lp->
a->read_csr(ioaddr,
CSR5);
2633 lp->
a->write_csr(ioaddr,
CSR0, CSR0_STOP);
2635 netif_wake_queue(dev);
2638 spin_unlock_irqrestore(&lp->
lock, flags);
2651 lp->
a->write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
2652 val_out = lp->
a->read_bcr(ioaddr, 34);
2658 static void mdio_write(
struct net_device *dev,
int phy_id,
int reg_num,
int val)
2666 lp->
a->write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
2667 lp->
a->write_bcr(ioaddr, 34, val);
2674 unsigned long flags;
2680 spin_unlock_irqrestore(&lp->
lock, flags);
2688 static int pcnet32_check_otherphy(
struct net_device *dev)
2696 if (i == lp->
mii_if.phy_id)
2737 int prev_link = netif_carrier_ok(dev) ? 1 : 0;
2744 curr_link = (lp->
a->read_bcr(ioaddr, 4) != 0xc0);
2747 if (prev_link || verbose) {
2752 curr_link = pcnet32_check_otherphy(dev);
2755 }
else if (verbose || !prev_link) {
2762 netdev_info(dev,
"link up, %uMbps, %s-duplex\n",
2763 ethtool_cmd_speed(&ecmd),
2768 if ((bcr9 & (1 << 0)) != lp->
mii_if.full_duplex) {
2769 if (lp->
mii_if.full_duplex)
2786 static void pcnet32_watchdog(
struct net_device *dev)
2789 unsigned long flags;
2793 pcnet32_check_media(dev, 0);
2794 spin_unlock_irqrestore(&lp->
lock, flags);
2801 struct net_device *dev = pci_get_drvdata(pdev);
2803 if (netif_running(dev)) {
2812 static int pcnet32_pm_resume(
struct pci_dev *pdev)
2814 struct net_device *dev = pci_get_drvdata(pdev);
2819 if (netif_running(dev)) {
2828 struct net_device *dev = pci_get_drvdata(pdev);
2834 pcnet32_free_ring(dev);
2840 pci_set_drvdata(pdev,
NULL);
2846 .probe = pcnet32_probe_pci,
2848 .id_table = pcnet32_pci_tbl,
2849 .suspend = pcnet32_pm_suspend,
2850 .resume = pcnet32_pm_resume,
2854 static int debug = -1;
2855 static int tx_start_pt = -1;
2856 static int pcnet32_have_pci;
2862 DRV_NAME " maximum events handled per interrupt");
2865 DRV_NAME " copy breakpoint for copy-only-tiny-frames");
2878 " mode for 79C978 cards (1 for HomePNA, 0 for Ethernet, default Ethernet");
2884 #define PCNET32_MSG_DEFAULT (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
2886 static int __init pcnet32_init_module(
void)
2892 if ((tx_start_pt >= 0) && (tx_start_pt <= 3))
2893 tx_start = tx_start_pt;
2896 if (!pci_register_driver(&pcnet32_driver))
2897 pcnet32_have_pci = 1;
2901 pcnet32_probe_vlbus(pcnet32_portlist);
2903 if (cards_found && (pcnet32_debug & NETIF_MSG_PROBE))
2904 pr_info(
"%d cards_found\n", cards_found);
2906 return (pcnet32_have_pci + cards_found) ? 0 : -
ENODEV;
2909 static void __exit pcnet32_cleanup_module(
void)
2913 while (pcnet32_dev) {
2915 next_dev = lp->
next;
2917 pcnet32_free_ring(pcnet32_dev);
2922 pcnet32_dev = next_dev;
2925 if (pcnet32_have_pci)