22 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25 #include <linux/module.h>
27 #include <linux/netdevice.h>
28 #include <linux/rtnetlink.h>
30 #include <linux/ethtool.h>
31 #include <linux/pci.h>
32 #include <linux/mii.h>
36 #include <linux/slab.h>
39 #define PHY_MAX_ADDR 32
40 #define PHY_ID_ANY 0x1f
41 #define MII_REG_ANY 0x1f
43 #define DRV_VERSION "1.4"
44 #define DRV_NAME "sis190"
45 #define SIS190_DRIVER_NAME DRV_NAME " Gigabit Ethernet driver " DRV_VERSION
47 #define sis190_rx_skb netif_rx
48 #define sis190_rx_quota(count, quota) count
50 #define NUM_TX_DESC 64
51 #define NUM_RX_DESC 64
52 #define TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc))
53 #define RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc))
54 #define RX_BUF_SIZE 1536
55 #define RX_BUF_MASK 0xfff8
57 #define SIS190_REGS_SIZE 0x80
58 #define SIS190_TX_TIMEOUT (6*HZ)
59 #define SIS190_PHY_TIMEOUT (10*HZ)
60 #define SIS190_MSG_DEFAULT (NETIF_MSG_DRV | NETIF_MSG_PROBE | \
61 NETIF_MSG_LINK | NETIF_MSG_IFUP | \
65 #define EhnMIIread 0x0000
66 #define EhnMIIwrite 0x0020
67 #define EhnMIIdataShift 16
68 #define EhnMIIpmdShift 6
69 #define EhnMIIregShift 11
70 #define EhnMIIreq 0x0010
71 #define EhnMIInotDone 0x0010
74 #define SIS_W8(reg, val) writeb ((val), ioaddr + (reg))
75 #define SIS_W16(reg, val) writew ((val), ioaddr + (reg))
76 #define SIS_W32(reg, val) writel ((val), ioaddr + (reg))
77 #define SIS_R8(reg) readb (ioaddr + (reg))
78 #define SIS_R16(reg) readw (ioaddr + (reg))
79 #define SIS_R32(reg) readl (ioaddr + (reg))
81 #define SIS_PCI_COMMIT() SIS_R32(IntrControl)
310 static struct mii_chip_info {
315 } mii_chip_table[] = {
316 {
"Atheros PHY", { 0x004d, 0xd010 },
LAN, 0 },
317 {
"Atheros PHY AR8012", { 0x004d, 0xd020 },
LAN, 0 },
319 {
"Broadcom PHY AC131", { 0x0143, 0xbc70 },
LAN, 0 },
320 {
"Agere PHY ET1101B", { 0x0282, 0xf010 },
LAN, 0 },
322 {
"Realtek PHY RTL8201", { 0x0000, 0x8200 },
LAN, 0 },
326 static const struct {
328 } sis_chip_info[] = {
329 {
"SiS 190 PCI Fast Ethernet adapter" },
330 {
"SiS 191 PCI Gigabit Ethernet adapter" },
341 static int rx_copybreak = 200;
349 MODULE_PARM_DESC(rx_copybreak,
"Copy breakpoint for copy-only-tiny-frames");
356 static const u32 sis190_intr_mask =
363 static const int multicast_filter_limit = 32;
373 for (i = 0; i < 100; i++) {
380 pr_err(
"PHY command failed !\n");
390 static int mdio_read(
void __iomem *ioaddr,
int phy_id,
int reg)
398 static void __mdio_write(
struct net_device *
dev,
int phy_id,
int reg,
int val)
402 mdio_write(tp->
mmio_addr, phy_id, reg, val);
405 static int __mdio_read(
struct net_device *
dev,
int phy_id,
int reg)
409 return mdio_read(tp->
mmio_addr, phy_id, reg);
412 static u16 mdio_read_latched(
void __iomem *ioaddr,
int phy_id,
int reg)
414 mdio_read(ioaddr, phy_id, reg);
415 return mdio_read(ioaddr, phy_id, reg);
428 for (i = 0; i < 200; i++) {
439 static void sis190_irq_mask_and_ack(
void __iomem *ioaddr)
446 static void sis190_asic_down(
void __iomem *ioaddr)
453 sis190_irq_mask_and_ack(ioaddr);
456 static void sis190_mark_as_last_descriptor(
struct RxDesc *
desc)
475 sis190_give_to_asic(desc, rx_buf_sz);
478 static inline void sis190_make_unusable_by_asic(
struct RxDesc *desc)
494 skb = netdev_alloc_skb(tp->
dev, rx_buf_sz);
496 goto skb_alloc_failed;
499 if (pci_dma_mapping_error(tp->
pci_dev, mapping))
501 sis190_map_to_asic(desc, mapping, rx_buf_sz);
508 sis190_make_unusable_by_asic(desc);
517 for (cur = start; cur <
end; cur++) {
538 if (pkt_size >= rx_copybreak)
541 skb = netdev_alloc_skb_ip_align(tp->
dev, pkt_size);
547 skb_copy_to_linear_data(skb, sk_buff[0]->data, pkt_size);
556 #define ErrMask (OVRUN | SHORT | LIMIT | MIIER | NIBON | COLON | ABORT)
558 if ((status &
CRCOK) && !(status & ErrMask))
561 if (!(status & CRCOK))
563 else if (status &
OVRUN)
574 static int sis190_rx_interrupt(
struct net_device *dev,
584 for (; rx_left > 0; rx_left--, cur_rx++) {
596 if (sis190_rx_pkt_err(status, stats) < 0)
597 sis190_give_to_asic(desc, tp->
rx_buf_sz);
606 "(frag) status = %08x\n", status);
609 sis190_give_to_asic(desc, tp->
rx_buf_sz);
614 if (sis190_try_rx_copy(tp, &skb, pkt_size, addr)) {
615 pci_dma_sync_single_for_device(pdev, addr,
617 sis190_give_to_asic(desc, tp->
rx_buf_sz);
619 pci_unmap_single(pdev, addr, tp->
rx_buf_sz,
622 sis190_make_unusable_by_asic(desc);
636 count = cur_rx - tp->
cur_rx;
650 static void sis190_unmap_tx_skb(
struct pci_dev *pdev,
struct sk_buff *skb,
659 memset(desc, 0x00,
sizeof(*desc));
664 #define TxErrMask (WND | TABRT | FIFO | LINK)
683 static void sis190_tx_interrupt(
struct net_device *dev,
692 unsigned int queue_stopped;
695 pending = tp->
cur_tx - dirty_tx;
698 for (; pending; pending--, dirty_tx++) {
709 if (
likely(sis190_tx_pkt_err(status, stats) == 0)) {
715 sis190_unmap_tx_skb(tp->
pci_dev, skb, txd);
724 netif_wake_queue(dev);
732 static irqreturn_t sis190_irq(
int irq,
void *__dev)
737 unsigned int handled = 0;
742 if ((status == 0xffffffff) || !status)
747 if (
unlikely(!netif_running(dev))) {
748 sis190_asic_down(ioaddr);
763 sis190_rx_interrupt(dev, tp, ioaddr);
766 sis190_tx_interrupt(dev, tp, ioaddr);
771 #ifdef CONFIG_NET_POLL_CONTROLLER
772 static void sis190_netpoll(
struct net_device *dev)
775 const int irq = tp->
pci_dev->irq;
778 sis190_irq(irq, dev);
784 struct sk_buff **sk_buff,
struct RxDesc *desc)
790 dev_kfree_skb(*sk_buff);
792 sis190_make_unusable_by_asic(desc);
811 static int sis190_init_ring(
struct net_device *dev)
815 sis190_init_ring_indexes(tp);
820 if (sis190_rx_fill(tp, dev, 0, NUM_RX_DESC) != NUM_RX_DESC)
823 sis190_mark_as_last_descriptor(tp->
RxDescRing + NUM_RX_DESC - 1);
832 static void sis190_set_rx_mode(
struct net_device *dev)
844 mc_filter[1] = mc_filter[0] = 0xffffffff;
849 mc_filter[1] = mc_filter[0] = 0xffffffff;
854 mc_filter[1] = mc_filter[0] = 0;
858 mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31);
869 spin_unlock_irqrestore(&tp->
lock, flags);
872 static void sis190_soft_reset(
void __iomem *ioaddr)
877 sis190_asic_down(ioaddr);
880 static void sis190_hw_start(
struct net_device *dev)
885 sis190_soft_reset(ioaddr);
902 sis190_set_rx_mode(dev);
910 netif_start_queue(dev);
919 int phy_id = tp->
mii_if.phy_id;
924 if (!netif_running(dev))
927 val = mdio_read(ioaddr, phy_id,
MII_BMCR);
934 val = mdio_read_latched(ioaddr, phy_id,
MII_BMSR);
947 "1000 Mbps Full Duplex" },
949 "1000 Mbps Half Duplex" },
951 "100 Mbps Full Duplex" },
953 "100 Mbps Half Duplex" },
955 "10 Mbps Full Duplex" },
957 "10 Mbps Half Duplex" },
958 { 0, 0x04000400,
"unknown" }
960 u16 adv, autoexp, gigadv, gigrec;
962 val = mdio_read(ioaddr, phy_id, 0x1f);
965 val = mdio_read(ioaddr, phy_id,
MII_LPA);
975 val = (gigadv & (gigrec >> 2));
984 for (
p = reg31;
p->val;
p++) {
985 if ((val &
p->val) ==
p->val)
995 mdio_write(ioaddr, phy_id, 0x18, 0xf1c7);
997 mdio_write(ioaddr, phy_id, 0x1c, 0x8c00);
998 p->ctl |= 0x03000000;
1013 }
else if (!(val & BMSR_LSTATUS) && tp->
link_status != LNK_AUTONEG)
1021 static void sis190_phy_timer(
unsigned long __opaque)
1026 if (
likely(netif_running(dev)))
1030 static inline void sis190_delete_timer(
struct net_device *dev)
1037 static inline void sis190_request_timer(
struct net_device *dev)
1045 timer->
function = sis190_phy_timer;
1052 unsigned int mtu = dev->
mtu;
1062 static int sis190_open(
struct net_device *dev)
1068 sis190_set_rxbufsize(tp, dev);
1082 rc = sis190_init_ring(dev);
1086 sis190_request_timer(dev);
1090 goto err_release_timer_2;
1092 sis190_hw_start(dev);
1096 err_release_timer_2:
1097 sis190_delete_timer(dev);
1098 sis190_rx_clear(tp);
1120 tp->
dev->stats.tx_dropped++;
1125 static void sis190_down(
struct net_device *dev)
1129 unsigned int poll_locked = 0;
1131 sis190_delete_timer(dev);
1133 netif_stop_queue(dev);
1136 spin_lock_irq(&tp->
lock);
1138 sis190_asic_down(ioaddr);
1140 spin_unlock_irq(&tp->
lock);
1151 sis190_tx_clear(tp);
1152 sis190_rx_clear(tp);
1155 static int sis190_close(
struct net_device *dev)
1173 static netdev_tx_t sis190_start_xmit(
struct sk_buff *skb,
1184 dev->
stats.tx_dropped++;
1196 netif_stop_queue(dev);
1198 "BUG! Tx Ring full when queue awake!\n");
1203 if (pci_dma_mapping_error(tp->
pci_dev, mapping)) {
1205 "PCI mapping failed, dropping packet");
1215 if (entry == (NUM_TX_DESC - 1))
1235 if ((tp->
cur_tx - NUM_TX_DESC) == dirty_tx) {
1236 netif_stop_queue(dev);
1239 netif_wake_queue(dev);
1245 static void sis190_free_phy(
struct list_head *first_phy)
1270 phy_home = phy_default = phy_lan =
NULL;
1276 if ((status & BMSR_LSTATUS) &&
1293 phy_default = phy_home;
1295 phy_default = phy_lan;
1304 pr_info(
"%s: Using transceiver at address %d as default\n",
1322 struct mii_chip_info *
p;
1324 INIT_LIST_HEAD(&phy->
list);
1325 phy->
status = mii_status;
1331 for (p = mii_chip_table; p->type; p++) {
1332 if ((p->id[0] == phy->
id[0]) &&
1333 (p->id[1] == (phy->
id[1] & 0xfff0))) {
1339 phy->
type = (p->type ==
MIX) ?
1344 pr_info(
"%s: %s transceiver at address %d\n",
1349 pr_info(
"%s: unknown PHY 0x%x:0x%x transceiver at address %d\n",
1351 phy->
id[0], (phy->
id[1] & 0xfff0), phy_id);
1355 static void sis190_mii_probe_88e1111_fixup(
struct sis190_private *tp)
1359 int phy_id = tp->
mii_if.phy_id;
1367 mdio_write(ioaddr, phy_id, 0x1b, p[0]);
1369 mdio_write(ioaddr, phy_id, 0x14, p[1]);
1396 status = mdio_read_latched(ioaddr, phy_id,
MII_BMSR);
1399 if (status == 0xffff || status == 0x0000)
1409 sis190_init_phy(dev, tp, phy, phy_id, status);
1416 pr_info(
"%s: No MII transceivers found!\n",
1423 sis190_default_phy(dev);
1425 sis190_mii_probe_88e1111_fixup(tp);
1436 static void sis190_mii_remove(
struct net_device *dev)
1443 static void sis190_release_board(
struct pci_dev *pdev)
1445 struct net_device *dev = pci_get_drvdata(pdev);
1461 dev = alloc_etherdev(
sizeof(*tp));
1469 tp = netdev_priv(dev);
1476 pr_err(
"%s: enable failure\n", pci_name(pdev));
1477 goto err_free_dev_1;
1484 pr_err(
"%s: region #0 is no MMIO resource\n",
1486 goto err_pci_disable_2;
1490 pr_err(
"%s: invalid PCI region size(s)\n",
1492 goto err_pci_disable_2;
1498 pr_err(
"%s: could not request regions\n",
1500 goto err_pci_disable_2;
1506 pr_err(
"%s: DMA configuration failed\n",
1508 goto err_free_res_3;
1516 pr_err(
"%s: cannot remap MMIO, aborting\n",
1519 goto err_free_res_3;
1526 sis190_irq_mask_and_ack(ioaddr);
1528 sis190_soft_reset(ioaddr);
1543 static void sis190_tx_timeout(
struct net_device *dev)
1554 netif_info(tp, tx_err, dev,
"Transmit timeout, status %08x %08x\n",
1561 spin_lock_irq(&tp->
lock);
1562 sis190_tx_clear(tp);
1563 spin_unlock_irq(&tp->
lock);
1566 sis190_hw_start(dev);
1568 netif_wake_queue(dev);
1585 pr_info(
"%s: Read MAC address from EEPROM\n", pci_name(pdev));
1590 if ((sig == 0xffff) || (sig == 0x0000)) {
1592 pr_info(
"%s: Error EEPROM read %x\n",
1593 pci_name(pdev),
sig);
1598 for (i = 0; i <
ETH_ALEN / 2; i++) {
1604 sis190_set_rgmii(tp, sis190_read_eeprom(ioaddr,
EEPROMInfo));
1628 pr_info(
"%s: Read MAC address from APC\n", pci_name(pdev));
1638 pr_info(
"%s: Can not find ISA bridge\n",
1644 pci_read_config_byte(isa_bridge, 0x48, &tmp8);
1645 reg = (tmp8 & ~0x02);
1646 pci_write_config_byte(isa_bridge, 0x48, reg);
1648 pci_read_config_byte(isa_bridge, 0x48, ®);
1651 outb(0x9 + i, 0x78);
1658 sis190_set_rgmii(tp, reg);
1661 pci_write_config_byte(isa_bridge, 0x48, tmp8);
1674 static inline void sis190_init_rxfilter(
struct net_device *dev)
1701 rc = sis190_get_mac_addr_from_eeprom(pdev, dev);
1705 pci_read_config_byte(pdev, 0x73, ®);
1707 if (reg & 0x00000001)
1708 rc = sis190_get_mac_addr_from_apc(pdev, dev);
1713 static void sis190_set_speed_auto(
struct net_device *dev)
1717 int phy_id = tp->
mii_if.phy_id;
1731 mdio_write(ioaddr, phy_id,
MII_CTRL1000, ADVERTISE_1000FULL);
1734 mdio_write(ioaddr, phy_id,
MII_BMCR,
1752 static void sis190_get_drvinfo(
struct net_device *dev,
1763 static int sis190_get_regs_len(
struct net_device *dev)
1772 unsigned long flags;
1779 spin_unlock_irqrestore(&tp->
lock, flags);
1782 static int sis190_nway_reset(
struct net_device *dev)
1803 static const struct ethtool_ops sis190_ethtool_ops = {
1804 .get_settings = sis190_get_settings,
1805 .set_settings = sis190_set_settings,
1806 .get_drvinfo = sis190_get_drvinfo,
1807 .get_regs_len = sis190_get_regs_len,
1808 .get_regs = sis190_get_regs,
1810 .get_msglevel = sis190_get_msglevel,
1811 .set_msglevel = sis190_set_msglevel,
1812 .nway_reset = sis190_nway_reset,
1819 return !netif_running(dev) ? -
EINVAL :
1823 static int sis190_mac_addr(
struct net_device *dev,
void *p)
1829 sis190_init_rxfilter(dev);
1834 .ndo_open = sis190_open,
1835 .ndo_stop = sis190_close,
1836 .ndo_do_ioctl = sis190_ioctl,
1837 .ndo_start_xmit = sis190_start_xmit,
1838 .ndo_tx_timeout = sis190_tx_timeout,
1839 .ndo_set_rx_mode = sis190_set_rx_mode,
1841 .ndo_set_mac_address = sis190_mac_addr,
1843 #ifdef CONFIG_NET_POLL_CONTROLLER
1844 .ndo_poll_controller = sis190_netpoll,
1851 static int printed_version = 0;
1857 if (!printed_version) {
1860 printed_version = 1;
1863 dev = sis190_init_board(pdev);
1869 pci_set_drvdata(pdev, dev);
1871 tp = netdev_priv(dev);
1874 rc = sis190_get_mac_addr(pdev, dev);
1876 goto err_release_board;
1878 sis190_init_rxfilter(dev);
1889 rc = sis190_mii_probe(dev);
1891 goto err_release_board;
1895 goto err_remove_mii;
1898 netdev_info(dev,
"%s: %s at %p (IRQ: %d), %pM\n",
1902 netdev_info(dev,
"%s mode.\n",
1908 sis190_set_speed_auto(dev);
1913 sis190_mii_remove(dev);
1915 sis190_release_board(pdev);
1921 struct net_device *dev = pci_get_drvdata(pdev);
1924 sis190_mii_remove(dev);
1927 sis190_release_board(pdev);
1928 pci_set_drvdata(pdev,
NULL);
1931 static struct pci_driver sis190_pci_driver = {
1933 .id_table = sis190_pci_tbl,
1934 .probe = sis190_init_one,
1938 static int __init sis190_init_module(
void)
1940 return pci_register_driver(&sis190_pci_driver);
1943 static void __exit sis190_cleanup_module(
void)