37
39
/* A few user-configurable values.
38
40
These may be modified when a driver module is loaded. */
40
43
static int debug = 1; /* 1 normal messages, 0 quiet .. 7 verbose. */
41
44
static int max_interrupt_work = 20;
112
115
/* These identify the driver base version and may not be removed. */
113
116
static const char version[] __devinitconst =
114
KERN_INFO DRV_NAME ".c:v1.10-LK" DRV_VERSION " " DRV_RELDATE
115
" Written by Donald Becker\n";
117
"v1.10-LK" DRV_VERSION " " DRV_RELDATE " Written by Donald Becker";
117
119
/* This driver was written to use PCI memory space. Some early versions
118
120
of the Rhine may only work correctly with I/O space accesses. */
495
497
static void rhine_init_cam_filter(struct net_device *dev);
496
498
static void rhine_update_vcam(struct net_device *dev);
498
#define RHINE_WAIT_FOR(condition) do { \
500
while (!(condition) && --i) \
502
if (debug > 1 && i < 512) \
503
printk(KERN_INFO "%s: %4d cycles used @ %s:%d\n", \
504
DRV_NAME, 1024-i, __func__, __LINE__); \
500
#define RHINE_WAIT_FOR(condition) \
503
while (!(condition) && --i) \
505
if (debug > 1 && i < 512) \
506
pr_info("%4d cycles used @ %s:%d\n", \
507
1024 - i, __func__, __LINE__); \
507
510
static inline u32 get_intr_status(struct net_device *dev)
588
591
if (ioread8(ioaddr + ChipCmd1) & Cmd1Reset) {
589
printk(KERN_INFO "%s: Reset not complete yet. "
590
"Trying harder.\n", DRV_NAME);
592
netdev_info(dev, "Reset not complete yet. Trying harder.\n");
592
594
/* Force reset */
593
595
if (rp->quirks & rqForceReset)
601
printk(KERN_INFO "%s: Reset %s.\n", dev->name,
602
(ioread8(ioaddr + ChipCmd1) & Cmd1Reset) ?
603
"failed" : "succeeded");
603
netdev_info(dev, "Reset %s\n",
604
(ioread8(ioaddr + ChipCmd1) & Cmd1Reset) ?
605
"failed" : "succeeded");
765
765
/* this should always be supported */
766
766
rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
768
printk(KERN_ERR "32-bit PCI DMA addresses not supported by "
769
"32-bit PCI DMA addresses not supported by the card!?\n");
774
774
if ((pci_resource_len(pdev, 0) < io_size) ||
775
775
(pci_resource_len(pdev, 1) < io_size)) {
777
printk(KERN_ERR "Insufficient PCI resources, aborting\n");
777
dev_err(&pdev->dev, "Insufficient PCI resources, aborting\n");
786
786
dev = alloc_etherdev(sizeof(struct rhine_private));
789
printk(KERN_ERR "alloc_etherdev failed\n");
789
dev_err(&pdev->dev, "alloc_etherdev failed\n");
792
792
SET_NETDEV_DEV(dev, &pdev->dev);
804
804
ioaddr = pci_iomap(pdev, bar, io_size);
807
printk(KERN_ERR "ioremap failed for device %s, region 0x%X "
808
"@ 0x%lX\n", pci_name(pdev), io_size, memaddr);
808
"ioremap failed for device %s, region 0x%X @ 0x%lX\n",
809
pci_name(pdev), io_size, memaddr);
809
810
goto err_out_free_res;
820
821
unsigned char b = readb(ioaddr+reg);
823
printk(KERN_ERR "MMIO do not match PIO [%02x] "
824
"(%02x != %02x)\n", reg, a, b);
825
"MMIO do not match PIO [%02x] (%02x != %02x)\n",
825
827
goto err_out_unmap;
837
839
for (i = 0; i < 6; i++)
838
840
dev->dev_addr[i] = ioread8(ioaddr + StationAddr + i);
842
if (!is_valid_ether_addr(dev->dev_addr)) {
843
/* Report it and use a random ethernet address instead */
844
netdev_err(dev, "Invalid MAC address: %pM\n", dev->dev_addr);
845
random_ether_addr(dev->dev_addr);
846
netdev_info(dev, "Using random MAC address: %pM\n",
839
849
memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
841
if (!is_valid_ether_addr(dev->perm_addr)) {
843
printk(KERN_ERR "Invalid MAC address\n");
847
851
/* For Rhine-I/II, phy_id is loaded from EEPROM */
849
853
phy_id = ioread8(ioaddr + 0x6C);
879
883
goto err_out_unmap;
881
printk(KERN_INFO "%s: VIA %s at 0x%lx, %pM, IRQ %d.\n",
885
netdev_info(dev, "VIA %s at 0x%lx, %pM, IRQ %d\n",
888
dev->dev_addr, pdev->irq);
892
dev->dev_addr, pdev->irq);
890
894
pci_set_drvdata(pdev, dev);
896
900
mdio_write(dev, phy_id, MII_BMCR, mii_cmd);
897
901
if (mii_status != 0xffff && mii_status != 0x0000) {
898
902
rp->mii_if.advertising = mdio_read(dev, phy_id, 4);
899
printk(KERN_INFO "%s: MII PHY found at address "
900
"%d, status 0x%4.4x advertising %4.4x "
901
"Link %4.4x.\n", dev->name, phy_id,
902
mii_status, rp->mii_if.advertising,
903
mdio_read(dev, phy_id, 5));
904
"MII PHY found at address %d, status 0x%04x advertising %04x Link %04x\n",
906
mii_status, rp->mii_if.advertising,
907
mdio_read(dev, phy_id, 5));
905
909
/* set IFF_RUNNING */
906
910
if (mii_status & BMSR_LSTATUS)
913
917
rp->mii_if.phy_id = phy_id;
914
918
if (debug > 1 && avoid_D3)
915
printk(KERN_INFO "%s: No D3 power state at shutdown.\n",
919
netdev_info(dev, "No D3 power state at shutdown\n");
938
941
TX_RING_SIZE * sizeof(struct tx_desc),
941
printk(KERN_ERR "Could not allocate DMA memory.\n");
944
netdev_err(dev, "Could not allocate DMA memory\n");
944
947
if (rp->quirks & rqRhineI) {
1098
1101
iowrite8(ioread8(ioaddr + ChipCmd1) & ~Cmd1FDuplex,
1099
1102
ioaddr + ChipCmd1);
1101
printk(KERN_INFO "%s: force_media %d, carrier %d\n", dev->name,
1102
rp->mii_if.force_media, netif_carrier_ok(dev));
1104
netdev_info(dev, "force_media %d, carrier %d\n",
1105
rp->mii_if.force_media, netif_carrier_ok(dev));
1105
1108
/* Called after status of force_media possibly changed */
1113
1116
else /* Let MMI library update carrier status */
1114
1117
rhine_check_media(mii->dev, 0);
1116
printk(KERN_INFO "%s: force_media %d, carrier %d\n",
1117
mii->dev->name, mii->force_media,
1118
netif_carrier_ok(mii->dev));
1119
netdev_info(mii->dev, "force_media %d, carrier %d\n",
1120
mii->force_media, netif_carrier_ok(mii->dev));
1405
printk(KERN_DEBUG "%s: rhine_open() irq %d.\n",
1406
dev->name, rp->pdev->irq);
1407
netdev_dbg(dev, "%s() irq %d\n", __func__, rp->pdev->irq);
1408
1409
rc = alloc_ring(dev);
1415
1416
rhine_chip_reset(dev);
1416
1417
init_registers(dev);
1418
printk(KERN_DEBUG "%s: Done rhine_open(), status %4.4x "
1419
"MII status: %4.4x.\n",
1420
dev->name, ioread16(ioaddr + ChipCmd),
1421
mdio_read(dev, rp->mii_if.phy_id, MII_BMSR));
1419
netdev_dbg(dev, "%s() Done - status %04x MII status: %04x\n",
1420
__func__, ioread16(ioaddr + ChipCmd),
1421
mdio_read(dev, rp->mii_if.phy_id, MII_BMSR));
1423
1423
netif_start_queue(dev);
1461
1461
struct rhine_private *rp = netdev_priv(dev);
1462
1462
void __iomem *ioaddr = rp->base;
1464
printk(KERN_WARNING "%s: Transmit timed out, status %4.4x, PHY status "
1465
"%4.4x, resetting...\n",
1466
dev->name, ioread16(ioaddr + IntrStatus),
1467
mdio_read(dev, rp->mii_if.phy_id, MII_BMSR));
1464
netdev_warn(dev, "Transmit timed out, status %04x, PHY status %04x, resetting...\n",
1465
ioread16(ioaddr + IntrStatus),
1466
mdio_read(dev, rp->mii_if.phy_id, MII_BMSR));
1469
1468
schedule_work(&rp->reset_task);
1551
1550
spin_unlock_irqrestore(&rp->lock, flags);
1553
1552
if (debug > 4) {
1554
printk(KERN_DEBUG "%s: Transmit frame #%d queued in slot %d.\n",
1555
dev->name, rp->cur_tx-1, entry);
1553
netdev_dbg(dev, "Transmit frame #%d queued in slot %d\n",
1554
rp->cur_tx-1, entry);
1557
1556
return NETDEV_TX_OK;
1581
printk(KERN_DEBUG "%s: Interrupt, status %8.8x.\n",
1582
dev->name, intr_status);
1580
netdev_dbg(dev, "Interrupt, status %08x\n",
1584
1583
if (intr_status & (IntrRxDone | IntrRxErr | IntrRxDropped |
1585
1584
IntrRxWakeUp | IntrRxEmpty | IntrRxNoBuf)) {
1597
1596
RHINE_WAIT_FOR(!(ioread8(ioaddr+ChipCmd) & CmdTxOn));
1598
1597
if (debug > 2 &&
1599
1598
ioread8(ioaddr+ChipCmd) & CmdTxOn)
1600
printk(KERN_WARNING "%s: "
1601
"rhine_interrupt() Tx engine "
1602
"still on.\n", dev->name);
1600
"%s: Tx engine still on\n",
1611
1610
rhine_error(dev, intr_status);
1613
1612
if (--boguscnt < 0) {
1614
printk(KERN_WARNING "%s: Too much work at interrupt, "
1616
dev->name, intr_status);
1613
netdev_warn(dev, "Too much work at interrupt, status=%#08x\n",
1622
printk(KERN_DEBUG "%s: exiting interrupt, status=%8.8x.\n",
1623
dev->name, ioread16(ioaddr + IntrStatus));
1620
netdev_dbg(dev, "exiting interrupt, status=%08x\n",
1621
ioread16(ioaddr + IntrStatus));
1624
1622
return IRQ_RETVAL(handled);
1637
1635
while (rp->dirty_tx != rp->cur_tx) {
1638
1636
txstatus = le32_to_cpu(rp->tx_ring[entry].tx_status);
1640
printk(KERN_DEBUG "Tx scavenge %d status %8.8x.\n",
1638
netdev_dbg(dev, "Tx scavenge %d status %08x\n",
1642
1640
if (txstatus & DescOwn)
1644
1642
if (txstatus & 0x8000) {
1646
printk(KERN_DEBUG "%s: Transmit error, "
1647
"Tx status %8.8x.\n",
1648
dev->name, txstatus);
1644
netdev_dbg(dev, "Transmit error, Tx status %08x\n",
1649
1646
dev->stats.tx_errors++;
1650
1647
if (txstatus & 0x0400)
1651
1648
dev->stats.tx_carrier_errors++;
1669
1666
dev->stats.collisions += txstatus & 0x0F;
1671
printk(KERN_DEBUG "collisions: %1.1x:%1.1x\n",
1672
(txstatus >> 3) & 0xF,
1668
netdev_dbg(dev, "collisions: %1.1x:%1.1x\n",
1669
(txstatus >> 3) & 0xF,
1674
1671
dev->stats.tx_bytes += rp->tx_skbuff[entry]->len;
1675
1672
dev->stats.tx_packets++;
1703
1700
static inline u16 rhine_get_vlan_tci(struct sk_buff *skb, int data_size)
1705
1702
u8 *trailer = (u8 *)skb->data + ((data_size + 3) & ~3) + 2;
1706
return ntohs(*(u16 *)trailer);
1703
return be16_to_cpup((__be16 *)trailer);
1709
1706
/* Process up to limit frames from receive ring */
1714
1711
int entry = rp->cur_rx % RX_RING_SIZE;
1716
1713
if (debug > 4) {
1717
printk(KERN_DEBUG "%s: rhine_rx(), entry %d status %8.8x.\n",
1719
le32_to_cpu(rp->rx_head_desc->rx_status));
1714
netdev_dbg(dev, "%s(), entry %d status %08x\n",
1716
le32_to_cpu(rp->rx_head_desc->rx_status));
1722
1719
/* If EOP is set on the next entry, it's a new packet. Send it up. */
1733
printk(KERN_DEBUG "rhine_rx() status is %8.8x.\n",
1730
netdev_dbg(dev, "%s() status is %08x\n",
1731
__func__, desc_status);
1736
1733
if ((desc_status & (RxWholePkt | RxErr)) != RxWholePkt) {
1737
1734
if ((desc_status & RxWholePkt) != RxWholePkt) {
1738
printk(KERN_WARNING "%s: Oversized Ethernet "
1739
"frame spanned multiple buffers, entry "
1740
"%#x length %d status %8.8x!\n",
1741
dev->name, entry, data_size,
1743
printk(KERN_WARNING "%s: Oversized Ethernet "
1744
"frame %p vs %p.\n", dev->name,
1745
rp->rx_head_desc, &rp->rx_ring[entry]);
1736
"Oversized Ethernet frame spanned multiple buffers, "
1737
"entry %#x length %d status %08x!\n",
1741
"Oversized Ethernet frame %p vs %p\n",
1743
&rp->rx_ring[entry]);
1746
1744
dev->stats.rx_length_errors++;
1747
1745
} else if (desc_status & RxErr) {
1748
1746
/* There was a error. */
1750
printk(KERN_DEBUG "rhine_rx() Rx "
1751
"error was %8.8x.\n",
1748
netdev_dbg(dev, "%s() Rx error was %08x\n",
1749
__func__, desc_status);
1753
1750
dev->stats.rx_errors++;
1754
1751
if (desc_status & 0x0030)
1755
1752
dev->stats.rx_length_errors++;
1792
1789
skb = rp->rx_skbuff[entry];
1793
1790
if (skb == NULL) {
1794
printk(KERN_ERR "%s: Inconsistent Rx "
1795
"descriptor chain.\n",
1791
netdev_err(dev, "Inconsistent Rx descriptor chain\n");
1799
1794
rp->rx_skbuff[entry] = NULL;
1861
1856
u32 intr_status;
1864
* If new errors occured, we need to sort them out before doing Tx.
1859
* If new errors occurred, we need to sort them out before doing Tx.
1865
1860
* In that case the ISR will be back here RSN anyway.
1867
1862
intr_status = get_intr_status(dev);
1887
1882
/* This should never happen */
1889
printk(KERN_WARNING "%s: rhine_restart_tx() "
1890
"Another error occured %8.8x.\n",
1891
dev->name, intr_status);
1884
netdev_warn(dev, "%s() Another error occurred %08x\n",
1885
__func__, intr_status);
1910
1904
if (intr_status & IntrTxAborted) {
1912
printk(KERN_INFO "%s: Abort %8.8x, frame dropped.\n",
1913
dev->name, intr_status);
1906
netdev_info(dev, "Abort %08x, frame dropped\n",
1915
1909
if (intr_status & IntrTxUnderrun) {
1916
1910
if (rp->tx_thresh < 0xE0)
1917
1911
BYTE_REG_BITS_SET((rp->tx_thresh += 0x20), 0x80, ioaddr + TxConfig);
1919
printk(KERN_INFO "%s: Transmitter underrun, Tx "
1920
"threshold now %2.2x.\n",
1921
dev->name, rp->tx_thresh);
1913
netdev_info(dev, "Transmitter underrun, Tx threshold now %02x\n",
1923
1916
if (intr_status & IntrTxDescRace) {
1925
printk(KERN_INFO "%s: Tx descriptor write-back race.\n",
1918
netdev_info(dev, "Tx descriptor write-back race\n");
1928
1920
if ((intr_status & IntrTxError) &&
1929
1921
(intr_status & (IntrTxAborted |
1932
1924
BYTE_REG_BITS_SET((rp->tx_thresh += 0x20), 0x80, ioaddr + TxConfig);
1935
printk(KERN_INFO "%s: Unspecified error. Tx "
1936
"threshold now %2.2x.\n",
1937
dev->name, rp->tx_thresh);
1927
netdev_info(dev, "Unspecified error. Tx threshold now %02x\n",
1939
1930
if (intr_status & (IntrTxAborted | IntrTxUnderrun | IntrTxDescRace |
1944
1935
IntrTxError | IntrTxAborted | IntrNormalSummary |
1945
1936
IntrTxDescRace)) {
1947
printk(KERN_ERR "%s: Something Wicked happened! "
1948
"%8.8x.\n", dev->name, intr_status);
1938
netdev_err(dev, "Something Wicked happened! %08x\n",
1951
1942
spin_unlock(&rp->lock);
2145
2136
spin_lock_irq(&rp->lock);
2148
printk(KERN_DEBUG "%s: Shutting down ethercard, "
2149
"status was %4.4x.\n",
2150
dev->name, ioread16(ioaddr + ChipCmd));
2139
netdev_dbg(dev, "Shutting down ethercard, status was %04x\n",
2140
ioread16(ioaddr + ChipCmd));
2152
2142
/* Switch to loopback mode to avoid hardware races. */
2153
2143
iowrite8(rp->tx_thresh | 0x02, ioaddr + TxConfig);
2267
2257
if (request_irq(dev->irq, rhine_interrupt, IRQF_SHARED, dev->name, dev))
2268
printk(KERN_ERR "via-rhine %s: request_irq failed\n", dev->name);
2258
netdev_err(dev, "request_irq failed\n");
2270
2260
ret = pci_set_power_state(pdev, PCI_D0);
2272
printk(KERN_INFO "%s: Entering power state D0 %s (%d).\n",
2273
dev->name, ret ? "failed" : "succeeded", ret);
2262
netdev_info(dev, "Entering power state D0 %s (%d)\n",
2263
ret ? "failed" : "succeeded", ret);
2275
2265
pci_restore_state(pdev);
2327
2317
/* when a module, this is printed whether or not devices are found in probe */
2319
pr_info("%s\n", version);
2331
2321
if (dmi_check_system(rhine_dmi_table)) {
2332
2322
/* these BIOSes fail at PXE boot if chip is in D3 */
2334
printk(KERN_WARNING "%s: Broken BIOS detected, avoid_D3 "
2324
pr_warn("Broken BIOS detected, avoid_D3 enabled\n");
2338
2326
else if (avoid_D3)
2339
printk(KERN_INFO "%s: avoid_D3 set.\n", DRV_NAME);
2327
pr_info("avoid_D3 set\n");
2341
2329
return pci_register_driver(&rhine_driver);