aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/8139cp.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/8139cp.c')
-rw-r--r--drivers/net/8139cp.c220
1 files changed, 189 insertions, 31 deletions
diff --git a/drivers/net/8139cp.c b/drivers/net/8139cp.c
index 46d8c01437e9..d2150baa7e35 100644
--- a/drivers/net/8139cp.c
+++ b/drivers/net/8139cp.c
@@ -52,7 +52,6 @@
52#define DRV_RELDATE "Mar 22, 2004" 52#define DRV_RELDATE "Mar 22, 2004"
53 53
54 54
55#include <linux/config.h>
56#include <linux/module.h> 55#include <linux/module.h>
57#include <linux/moduleparam.h> 56#include <linux/moduleparam.h>
58#include <linux/kernel.h> 57#include <linux/kernel.h>
@@ -401,6 +400,11 @@ static void cp_clean_rings (struct cp_private *cp);
401#ifdef CONFIG_NET_POLL_CONTROLLER 400#ifdef CONFIG_NET_POLL_CONTROLLER
402static void cp_poll_controller(struct net_device *dev); 401static void cp_poll_controller(struct net_device *dev);
403#endif 402#endif
403static int cp_get_eeprom_len(struct net_device *dev);
404static int cp_get_eeprom(struct net_device *dev,
405 struct ethtool_eeprom *eeprom, u8 *data);
406static int cp_set_eeprom(struct net_device *dev,
407 struct ethtool_eeprom *eeprom, u8 *data);
404 408
405static struct pci_device_id cp_pci_tbl[] = { 409static struct pci_device_id cp_pci_tbl[] = {
406 { PCI_VENDOR_ID_REALTEK, PCI_DEVICE_ID_REALTEK_8139, 410 { PCI_VENDOR_ID_REALTEK, PCI_DEVICE_ID_REALTEK_8139,
@@ -792,7 +796,7 @@ static int cp_start_xmit (struct sk_buff *skb, struct net_device *dev)
792 entry = cp->tx_head; 796 entry = cp->tx_head;
793 eor = (entry == (CP_TX_RING_SIZE - 1)) ? RingEnd : 0; 797 eor = (entry == (CP_TX_RING_SIZE - 1)) ? RingEnd : 0;
794 if (dev->features & NETIF_F_TSO) 798 if (dev->features & NETIF_F_TSO)
795 mss = skb_shinfo(skb)->tso_size; 799 mss = skb_shinfo(skb)->gso_size;
796 800
797 if (skb_shinfo(skb)->nr_frags == 0) { 801 if (skb_shinfo(skb)->nr_frags == 0) {
798 struct cp_desc *txd = &cp->tx_ring[entry]; 802 struct cp_desc *txd = &cp->tx_ring[entry];
@@ -1199,7 +1203,7 @@ static int cp_open (struct net_device *dev)
1199 1203
1200 cp_init_hw(cp); 1204 cp_init_hw(cp);
1201 1205
1202 rc = request_irq(dev->irq, cp_interrupt, SA_SHIRQ, dev->name, dev); 1206 rc = request_irq(dev->irq, cp_interrupt, IRQF_SHARED, dev->name, dev);
1203 if (rc) 1207 if (rc)
1204 goto err_out_hw; 1208 goto err_out_hw;
1205 1209
@@ -1577,6 +1581,9 @@ static struct ethtool_ops cp_ethtool_ops = {
1577 .get_strings = cp_get_strings, 1581 .get_strings = cp_get_strings,
1578 .get_ethtool_stats = cp_get_ethtool_stats, 1582 .get_ethtool_stats = cp_get_ethtool_stats,
1579 .get_perm_addr = ethtool_op_get_perm_addr, 1583 .get_perm_addr = ethtool_op_get_perm_addr,
1584 .get_eeprom_len = cp_get_eeprom_len,
1585 .get_eeprom = cp_get_eeprom,
1586 .set_eeprom = cp_set_eeprom,
1580}; 1587};
1581 1588
1582static int cp_ioctl (struct net_device *dev, struct ifreq *rq, int cmd) 1589static int cp_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
@@ -1612,24 +1619,32 @@ static int cp_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
1612#define eeprom_delay() readl(ee_addr) 1619#define eeprom_delay() readl(ee_addr)
1613 1620
1614/* The EEPROM commands include the alway-set leading bit. */ 1621/* The EEPROM commands include the alway-set leading bit. */
1622#define EE_EXTEND_CMD (4)
1615#define EE_WRITE_CMD (5) 1623#define EE_WRITE_CMD (5)
1616#define EE_READ_CMD (6) 1624#define EE_READ_CMD (6)
1617#define EE_ERASE_CMD (7) 1625#define EE_ERASE_CMD (7)
1618 1626
1619static int read_eeprom (void __iomem *ioaddr, int location, int addr_len) 1627#define EE_EWDS_ADDR (0)
1620{ 1628#define EE_WRAL_ADDR (1)
1621 int i; 1629#define EE_ERAL_ADDR (2)
1622 unsigned retval = 0; 1630#define EE_EWEN_ADDR (3)
1623 void __iomem *ee_addr = ioaddr + Cfg9346; 1631
1624 int read_cmd = location | (EE_READ_CMD << addr_len); 1632#define CP_EEPROM_MAGIC PCI_DEVICE_ID_REALTEK_8139
1625 1633
1634static void eeprom_cmd_start(void __iomem *ee_addr)
1635{
1626 writeb (EE_ENB & ~EE_CS, ee_addr); 1636 writeb (EE_ENB & ~EE_CS, ee_addr);
1627 writeb (EE_ENB, ee_addr); 1637 writeb (EE_ENB, ee_addr);
1628 eeprom_delay (); 1638 eeprom_delay ();
1639}
1629 1640
1630 /* Shift the read command bits out. */ 1641static void eeprom_cmd(void __iomem *ee_addr, int cmd, int cmd_len)
1631 for (i = 4 + addr_len; i >= 0; i--) { 1642{
1632 int dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0; 1643 int i;
1644
1645 /* Shift the command bits out. */
1646 for (i = cmd_len - 1; i >= 0; i--) {
1647 int dataval = (cmd & (1 << i)) ? EE_DATA_WRITE : 0;
1633 writeb (EE_ENB | dataval, ee_addr); 1648 writeb (EE_ENB | dataval, ee_addr);
1634 eeprom_delay (); 1649 eeprom_delay ();
1635 writeb (EE_ENB | dataval | EE_SHIFT_CLK, ee_addr); 1650 writeb (EE_ENB | dataval | EE_SHIFT_CLK, ee_addr);
@@ -1637,6 +1652,33 @@ static int read_eeprom (void __iomem *ioaddr, int location, int addr_len)
1637 } 1652 }
1638 writeb (EE_ENB, ee_addr); 1653 writeb (EE_ENB, ee_addr);
1639 eeprom_delay (); 1654 eeprom_delay ();
1655}
1656
1657static void eeprom_cmd_end(void __iomem *ee_addr)
1658{
1659 writeb (~EE_CS, ee_addr);
1660 eeprom_delay ();
1661}
1662
1663static void eeprom_extend_cmd(void __iomem *ee_addr, int extend_cmd,
1664 int addr_len)
1665{
1666 int cmd = (EE_EXTEND_CMD << addr_len) | (extend_cmd << (addr_len - 2));
1667
1668 eeprom_cmd_start(ee_addr);
1669 eeprom_cmd(ee_addr, cmd, 3 + addr_len);
1670 eeprom_cmd_end(ee_addr);
1671}
1672
1673static u16 read_eeprom (void __iomem *ioaddr, int location, int addr_len)
1674{
1675 int i;
1676 u16 retval = 0;
1677 void __iomem *ee_addr = ioaddr + Cfg9346;
1678 int read_cmd = location | (EE_READ_CMD << addr_len);
1679
1680 eeprom_cmd_start(ee_addr);
1681 eeprom_cmd(ee_addr, read_cmd, 3 + addr_len);
1640 1682
1641 for (i = 16; i > 0; i--) { 1683 for (i = 16; i > 0; i--) {
1642 writeb (EE_ENB | EE_SHIFT_CLK, ee_addr); 1684 writeb (EE_ENB | EE_SHIFT_CLK, ee_addr);
@@ -1648,13 +1690,125 @@ static int read_eeprom (void __iomem *ioaddr, int location, int addr_len)
1648 eeprom_delay (); 1690 eeprom_delay ();
1649 } 1691 }
1650 1692
1651 /* Terminate the EEPROM access. */ 1693 eeprom_cmd_end(ee_addr);
1652 writeb (~EE_CS, ee_addr);
1653 eeprom_delay ();
1654 1694
1655 return retval; 1695 return retval;
1656} 1696}
1657 1697
1698static void write_eeprom(void __iomem *ioaddr, int location, u16 val,
1699 int addr_len)
1700{
1701 int i;
1702 void __iomem *ee_addr = ioaddr + Cfg9346;
1703 int write_cmd = location | (EE_WRITE_CMD << addr_len);
1704
1705 eeprom_extend_cmd(ee_addr, EE_EWEN_ADDR, addr_len);
1706
1707 eeprom_cmd_start(ee_addr);
1708 eeprom_cmd(ee_addr, write_cmd, 3 + addr_len);
1709 eeprom_cmd(ee_addr, val, 16);
1710 eeprom_cmd_end(ee_addr);
1711
1712 eeprom_cmd_start(ee_addr);
1713 for (i = 0; i < 20000; i++)
1714 if (readb(ee_addr) & EE_DATA_READ)
1715 break;
1716 eeprom_cmd_end(ee_addr);
1717
1718 eeprom_extend_cmd(ee_addr, EE_EWDS_ADDR, addr_len);
1719}
1720
1721static int cp_get_eeprom_len(struct net_device *dev)
1722{
1723 struct cp_private *cp = netdev_priv(dev);
1724 int size;
1725
1726 spin_lock_irq(&cp->lock);
1727 size = read_eeprom(cp->regs, 0, 8) == 0x8129 ? 256 : 128;
1728 spin_unlock_irq(&cp->lock);
1729
1730 return size;
1731}
1732
1733static int cp_get_eeprom(struct net_device *dev,
1734 struct ethtool_eeprom *eeprom, u8 *data)
1735{
1736 struct cp_private *cp = netdev_priv(dev);
1737 unsigned int addr_len;
1738 u16 val;
1739 u32 offset = eeprom->offset >> 1;
1740 u32 len = eeprom->len;
1741 u32 i = 0;
1742
1743 eeprom->magic = CP_EEPROM_MAGIC;
1744
1745 spin_lock_irq(&cp->lock);
1746
1747 addr_len = read_eeprom(cp->regs, 0, 8) == 0x8129 ? 8 : 6;
1748
1749 if (eeprom->offset & 1) {
1750 val = read_eeprom(cp->regs, offset, addr_len);
1751 data[i++] = (u8)(val >> 8);
1752 offset++;
1753 }
1754
1755 while (i < len - 1) {
1756 val = read_eeprom(cp->regs, offset, addr_len);
1757 data[i++] = (u8)val;
1758 data[i++] = (u8)(val >> 8);
1759 offset++;
1760 }
1761
1762 if (i < len) {
1763 val = read_eeprom(cp->regs, offset, addr_len);
1764 data[i] = (u8)val;
1765 }
1766
1767 spin_unlock_irq(&cp->lock);
1768 return 0;
1769}
1770
1771static int cp_set_eeprom(struct net_device *dev,
1772 struct ethtool_eeprom *eeprom, u8 *data)
1773{
1774 struct cp_private *cp = netdev_priv(dev);
1775 unsigned int addr_len;
1776 u16 val;
1777 u32 offset = eeprom->offset >> 1;
1778 u32 len = eeprom->len;
1779 u32 i = 0;
1780
1781 if (eeprom->magic != CP_EEPROM_MAGIC)
1782 return -EINVAL;
1783
1784 spin_lock_irq(&cp->lock);
1785
1786 addr_len = read_eeprom(cp->regs, 0, 8) == 0x8129 ? 8 : 6;
1787
1788 if (eeprom->offset & 1) {
1789 val = read_eeprom(cp->regs, offset, addr_len) & 0xff;
1790 val |= (u16)data[i++] << 8;
1791 write_eeprom(cp->regs, offset, val, addr_len);
1792 offset++;
1793 }
1794
1795 while (i < len - 1) {
1796 val = (u16)data[i++];
1797 val |= (u16)data[i++] << 8;
1798 write_eeprom(cp->regs, offset, val, addr_len);
1799 offset++;
1800 }
1801
1802 if (i < len) {
1803 val = read_eeprom(cp->regs, offset, addr_len) & 0xff00;
1804 val |= (u16)data[i];
1805 write_eeprom(cp->regs, offset, val, addr_len);
1806 }
1807
1808 spin_unlock_irq(&cp->lock);
1809 return 0;
1810}
1811
1658/* Put the board into D3cold state and wait for WakeUp signal */ 1812/* Put the board into D3cold state and wait for WakeUp signal */
1659static void cp_set_d3_state (struct cp_private *cp) 1813static void cp_set_d3_state (struct cp_private *cp)
1660{ 1814{
@@ -1668,7 +1822,7 @@ static int cp_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1668 struct cp_private *cp; 1822 struct cp_private *cp;
1669 int rc; 1823 int rc;
1670 void __iomem *regs; 1824 void __iomem *regs;
1671 long pciaddr; 1825 resource_size_t pciaddr;
1672 unsigned int addr_len, i, pci_using_dac; 1826 unsigned int addr_len, i, pci_using_dac;
1673 u8 pci_rev; 1827 u8 pci_rev;
1674 1828
@@ -1682,9 +1836,10 @@ static int cp_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1682 1836
1683 if (pdev->vendor == PCI_VENDOR_ID_REALTEK && 1837 if (pdev->vendor == PCI_VENDOR_ID_REALTEK &&
1684 pdev->device == PCI_DEVICE_ID_REALTEK_8139 && pci_rev < 0x20) { 1838 pdev->device == PCI_DEVICE_ID_REALTEK_8139 && pci_rev < 0x20) {
1685 printk(KERN_ERR PFX "pci dev %s (id %04x:%04x rev %02x) is not an 8139C+ compatible chip\n", 1839 dev_err(&pdev->dev,
1686 pci_name(pdev), pdev->vendor, pdev->device, pci_rev); 1840 "This (id %04x:%04x rev %02x) is not an 8139C+ compatible chip\n",
1687 printk(KERN_ERR PFX "Try the \"8139too\" driver instead.\n"); 1841 pdev->vendor, pdev->device, pci_rev);
1842 dev_err(&pdev->dev, "Try the \"8139too\" driver instead.\n");
1688 return -ENODEV; 1843 return -ENODEV;
1689 } 1844 }
1690 1845
@@ -1722,14 +1877,13 @@ static int cp_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1722 pciaddr = pci_resource_start(pdev, 1); 1877 pciaddr = pci_resource_start(pdev, 1);
1723 if (!pciaddr) { 1878 if (!pciaddr) {
1724 rc = -EIO; 1879 rc = -EIO;
1725 printk(KERN_ERR PFX "no MMIO resource for pci dev %s\n", 1880 dev_err(&pdev->dev, "no MMIO resource\n");
1726 pci_name(pdev));
1727 goto err_out_res; 1881 goto err_out_res;
1728 } 1882 }
1729 if (pci_resource_len(pdev, 1) < CP_REGS_SIZE) { 1883 if (pci_resource_len(pdev, 1) < CP_REGS_SIZE) {
1730 rc = -EIO; 1884 rc = -EIO;
1731 printk(KERN_ERR PFX "MMIO resource (%lx) too small on pci dev %s\n", 1885 dev_err(&pdev->dev, "MMIO resource (%llx) too small\n",
1732 pci_resource_len(pdev, 1), pci_name(pdev)); 1886 (unsigned long long)pci_resource_len(pdev, 1));
1733 goto err_out_res; 1887 goto err_out_res;
1734 } 1888 }
1735 1889
@@ -1743,14 +1897,15 @@ static int cp_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1743 1897
1744 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK); 1898 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
1745 if (rc) { 1899 if (rc) {
1746 printk(KERN_ERR PFX "No usable DMA configuration, " 1900 dev_err(&pdev->dev,
1747 "aborting.\n"); 1901 "No usable DMA configuration, aborting.\n");
1748 goto err_out_res; 1902 goto err_out_res;
1749 } 1903 }
1750 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); 1904 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
1751 if (rc) { 1905 if (rc) {
1752 printk(KERN_ERR PFX "No usable consistent DMA configuration, " 1906 dev_err(&pdev->dev,
1753 "aborting.\n"); 1907 "No usable consistent DMA configuration, "
1908 "aborting.\n");
1754 goto err_out_res; 1909 goto err_out_res;
1755 } 1910 }
1756 } 1911 }
@@ -1761,8 +1916,9 @@ static int cp_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1761 regs = ioremap(pciaddr, CP_REGS_SIZE); 1916 regs = ioremap(pciaddr, CP_REGS_SIZE);
1762 if (!regs) { 1917 if (!regs) {
1763 rc = -EIO; 1918 rc = -EIO;
1764 printk(KERN_ERR PFX "Cannot map PCI MMIO (%lx@%lx) on pci dev %s\n", 1919 dev_err(&pdev->dev, "Cannot map PCI MMIO (%lx@%lx)\n",
1765 pci_resource_len(pdev, 1), pciaddr, pci_name(pdev)); 1920 (unsigned long long)pci_resource_len(pdev, 1),
1921 (unsigned long long)pciaddr);
1766 goto err_out_res; 1922 goto err_out_res;
1767 } 1923 }
1768 dev->base_addr = (unsigned long) regs; 1924 dev->base_addr = (unsigned long) regs;
@@ -1831,7 +1987,8 @@ static int cp_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1831 /* enable busmastering and memory-write-invalidate */ 1987 /* enable busmastering and memory-write-invalidate */
1832 pci_set_master(pdev); 1988 pci_set_master(pdev);
1833 1989
1834 if (cp->wol_enabled) cp_set_d3_state (cp); 1990 if (cp->wol_enabled)
1991 cp_set_d3_state (cp);
1835 1992
1836 return 0; 1993 return 0;
1837 1994
@@ -1856,7 +2013,8 @@ static void cp_remove_one (struct pci_dev *pdev)
1856 BUG_ON(!dev); 2013 BUG_ON(!dev);
1857 unregister_netdev(dev); 2014 unregister_netdev(dev);
1858 iounmap(cp->regs); 2015 iounmap(cp->regs);
1859 if (cp->wol_enabled) pci_set_power_state (pdev, PCI_D0); 2016 if (cp->wol_enabled)
2017 pci_set_power_state (pdev, PCI_D0);
1860 pci_release_regions(pdev); 2018 pci_release_regions(pdev);
1861 pci_clear_mwi(pdev); 2019 pci_clear_mwi(pdev);
1862 pci_disable_device(pdev); 2020 pci_disable_device(pdev);