52 #include <linux/module.h>
54 #include <linux/kernel.h>
55 #include <linux/sched.h>
56 #include <linux/string.h>
58 #include <linux/errno.h>
60 #include <linux/slab.h>
62 #include <linux/pci.h>
63 #include <linux/netdevice.h>
65 #include <linux/mii.h>
69 #include <linux/ethtool.h>
71 #include <linux/bitops.h>
74 #include <asm/processor.h>
77 #include <asm/uaccess.h>
81 #define SIS900_MODULE_NAME "sis900"
82 #define SIS900_DRV_VERSION "v1.08.10 Apr. 2 2006"
87 static int max_interrupt_work = 40;
88 static int multicast_filter_limit = 128;
90 static int sis900_debug = -1;
92 #define SIS900_DEF_MSG \
99 #define TX_TIMEOUT (4*HZ)
105 static const char * card_names[] = {
106 "SiS 900 PCI Fast Ethernet",
107 "SiS 7016 PCI Fast Ethernet"
118 static void sis900_read_mode(
struct net_device *net_dev,
int *speed,
int *
duplex);
120 static const struct mii_chip_info {
129 } mii_chip_table[] = {
130 {
"SiS 900 Internal MII PHY", 0x001d, 0x8000,
LAN },
131 {
"SiS 7014 Physical Layer Solution", 0x0016, 0xf830,
LAN },
132 {
"SiS 900 on Foxconn 661 7MI", 0x0143, 0xBC70,
LAN },
133 {
"Altimata AC101LF PHY", 0x0022, 0x5520,
LAN },
134 {
"ADM 7001 LAN PHY", 0x002e, 0xcc60,
LAN },
135 {
"AMD 79C901 10BASE-T PHY", 0x0000, 0x6B70,
LAN },
136 {
"AMD 79C901 HomePNA PHY", 0x0000, 0x6B90,
HOME},
137 {
"ICS LAN PHY", 0x0015, 0xF440,
LAN },
138 {
"ICS LAN PHY", 0x0143, 0xBC70,
LAN },
139 {
"NS 83851 PHY", 0x2000, 0x5C20,
MIX },
140 {
"NS 83847 PHY", 0x2000, 0x5C30,
MIX },
141 {
"Realtek RTL8201 PHY", 0x0000, 0x8200,
LAN },
142 {
"VIA 6103 PHY", 0x0101, 0x8f20,
LAN },
202 MODULE_PARM_DESC(multicast_filter_limit,
"SiS 900/7016 maximum number of filtered multicast addresses");
203 MODULE_PARM_DESC(max_interrupt_work,
"SiS 900/7016 maximum events handled per interrupt");
204 MODULE_PARM_DESC(sis900_debug,
"SiS 900/7016 bitmapped debugging message level");
206 #define sw32(reg, val) iowrite32(val, ioaddr + (reg))
207 #define sw8(reg, val) iowrite8(val, ioaddr + (reg))
208 #define sr32(reg) ioread32(ioaddr + (reg))
209 #define sr16(reg) ioread16(ioaddr + (reg))
211 #ifdef CONFIG_NET_POLL_CONTROLLER
214 static int sis900_open(
struct net_device *net_dev);
215 static int sis900_mii_probe (
struct net_device * net_dev);
216 static void sis900_init_rxfilter (
struct net_device * net_dev);
220 static void sis900_timer(
unsigned long data);
222 static void sis900_tx_timeout(
struct net_device *net_dev);
223 static void sis900_init_tx_ring(
struct net_device *net_dev);
224 static void sis900_init_rx_ring(
struct net_device *net_dev);
227 static int sis900_rx(
struct net_device *net_dev);
228 static void sis900_finish_xmit (
struct net_device *net_dev);
229 static irqreturn_t sis900_interrupt(
int irq,
void *dev_instance);
230 static int sis900_close(
struct net_device *net_dev);
233 static void set_rx_mode(
struct net_device *net_dev);
234 static void sis900_reset(
struct net_device *net_dev);
239 static u16 sis900_reset_phy(
struct net_device *net_dev,
int phy_addr);
240 static void sis900_auto_negotiate(
struct net_device *net_dev,
int phy_addr);
242 static const struct ethtool_ops sis900_ethtool_ops;
263 if (signature == 0xffff || signature == 0x0000) {
265 pci_name(pci_dev), signature);
270 for (i = 0; i < 3; i++)
290 static int __devinit sis630e_get_mac_addr(
struct pci_dev * pci_dev,
305 pci_read_config_byte(isa_bridge, 0x48, ®);
306 pci_write_config_byte(isa_bridge, 0x48, reg | 0x40);
308 for (i = 0; i < 6; i++) {
309 outb(0x09 + i, 0x70);
316 pci_write_config_byte(isa_bridge, 0x48, reg & ~0x40);
333 static int __devinit sis635_get_mac_addr(
struct pci_dev * pci_dev,
350 for (i = 0 ; i < 3 ; i++) {
380 static int __devinit sis96x_get_mac_addr(
struct pci_dev * pci_dev,
388 for (wait = 0; wait < 2000; wait++) {
394 for (i = 0; i < 3; i++)
410 .ndo_open = sis900_open,
411 .ndo_stop = sis900_close,
412 .ndo_start_xmit = sis900_start_xmit,
413 .ndo_set_config = sis900_set_config,
414 .ndo_set_rx_mode = set_rx_mode,
418 .ndo_do_ioctl = mii_ioctl,
419 .ndo_tx_timeout = sis900_tx_timeout,
420 #ifdef CONFIG_NET_POLL_CONTROLLER
421 .ndo_poll_controller = sis900_poll,
436 static int __devinit sis900_probe(
struct pci_dev *pci_dev,
446 const char *card_name = card_names[pci_id->
driver_data];
447 const char *dev_name = pci_name(pci_dev);
451 static int printed_version;
452 if (!printed_version++)
463 "32bit PCI busmaster DMA\n");
480 ioaddr = pci_iomap(pci_dev, 0, 0);
483 goto err_out_cleardev;
486 sis_priv = netdev_priv(net_dev);
487 sis_priv->
ioaddr = ioaddr;
491 pci_set_drvdata(pci_dev, net_dev);
498 sis_priv->
tx_ring = ring_space;
506 sis_priv->
rx_ring = ring_space;
514 if (sis900_debug > 0)
520 sis_priv->
mii_info.mdio_read = mdio_read;
521 sis_priv->
mii_info.mdio_write = mdio_write;
522 sis_priv->
mii_info.phy_id_mask = 0x1f;
523 sis_priv->
mii_info.reg_num_mask = 0x1f;
529 "trying to get MAC address...\n",
534 ret = sis630e_get_mac_addr(pci_dev, net_dev);
536 ret = sis635_get_mac_addr(pci_dev, net_dev);
538 ret = sis96x_get_mac_addr(pci_dev, net_dev);
540 ret = sis900_get_mac_addr(pci_dev, net_dev);
542 if (!ret || !is_valid_ether_addr(net_dev->
dev_addr)) {
543 eth_hw_addr_random(net_dev);
545 "using random generated one\n", dev_name);
553 if (sis900_mii_probe(net_dev) == 0) {
573 net_dev->
name, card_name, ioaddr, pci_dev->
irq,
592 pci_set_drvdata(pci_dev,
NULL);
611 const char *dev_name = pci_name(sis_priv->
pci_dev);
619 for (phy_addr = 0; phy_addr < 32; phy_addr++) {
625 for(i = 0; i < 2; i++)
628 if (mii_status == 0xffff || mii_status == 0x0000) {
641 mii_phy = mii_phy->
next;
650 mii_phy->
status = mii_status;
652 sis_priv->
mii = mii_phy;
655 for (i = 0; mii_chip_table[
i].phy_id1; i++)
656 if ((mii_phy->
phy_id0 == mii_chip_table[i].phy_id0 ) &&
657 ((mii_phy->
phy_id1 & 0xFFF0) == mii_chip_table[i].phy_id1)){
658 mii_phy->
phy_types = mii_chip_table[
i].phy_types;
665 mii_chip_table[i].
name,
670 if( !mii_chip_table[i].
phy_id1 ) {
684 sis900_default_phy( net_dev );
687 if ((sis_priv->
mii->phy_id0 == 0x001D) &&
688 ((sis_priv->
mii->phy_id1&0xFFF0) == 0x8000))
689 status = sis900_reset_phy(net_dev, sis_priv->
cur_phy);
692 if ((sis_priv->
mii->phy_id0 == 0x0015) &&
693 ((sis_priv->
mii->phy_id1&0xFFF0) == 0xF440))
718 if (sis_priv->
mii->status & MII_STAT_LINK)
739 *default_phy =
NULL, *phy_lan =
NULL;
747 if ((status & MII_STAT_LINK) && !default_phy &&
761 if (!default_phy && phy_home)
762 default_phy = phy_home;
763 else if (!default_phy && phy_lan)
764 default_phy = phy_lan;
765 else if (!default_phy)
768 if (sis_priv->
mii != default_phy) {
769 sis_priv->
mii = default_phy;
770 sis_priv->
cur_phy = default_phy->phy_addr;
771 printk(
KERN_INFO "%s: Using transceiver found at address %d as default\n",
797 static void sis900_set_capability(
struct net_device *net_dev,
struct mii_phy *phy)
816 #define eeprom_delay() sr32(mear)
839 for (i = 8; i >= 0; i--) {
851 for (i = 16; i > 0; i--) {
870 #define mdio_delay() sr32(mear)
887 for (i = 31; i >= 0; i--) {
917 for (i = 15; i >= 0; i--) {
927 for (i = 16; i > 0; i--) {
951 static void mdio_write(
struct net_device *net_dev,
int phy_id,
int location,
963 for (i = 15; i >= 0; i--) {
974 for (i = 15; i >= 0; i--) {
985 for (i = 2; i > 0; i--) {
1005 static u16 sis900_reset_phy(
struct net_device *net_dev,
int phy_addr)
1010 for (i = 0; i < 2; i++)
1011 status = mdio_read(net_dev, phy_addr,
MII_STATUS);
1018 #ifdef CONFIG_NET_POLL_CONTROLLER
1024 static void sis900_poll(
struct net_device *dev)
1030 sis900_interrupt(irq, dev);
1051 sis900_reset(net_dev);
1057 net_dev->
name, net_dev);
1061 sis900_init_rxfilter(net_dev);
1063 sis900_init_tx_ring(net_dev);
1064 sis900_init_rx_ring(net_dev);
1066 set_rx_mode(net_dev);
1068 netif_start_queue(net_dev);
1078 sis900_check_mode(net_dev, sis_priv->
mii);
1084 sis_priv->
timer.data = (
unsigned long)net_dev;
1085 sis_priv->
timer.function = sis900_timer;
1100 sis900_init_rxfilter (
struct net_device * net_dev)
1113 for (i = 0 ; i < 3 ; i++) {
1137 sis900_init_tx_ring(
struct net_device *net_dev)
1171 sis900_init_rx_ring(
struct net_device *net_dev)
1206 sis_priv->
dirty_rx = (
unsigned int) (i - NUM_RX_DESC);
1252 if (netif_carrier_ok(net_dev)) {
1255 (0x2200 | reg14h) & 0xBFFF);
1256 for (i=0; i < maxcount; i++) {
1257 eq_value = (0x00F8 & mdio_read(net_dev,
1263 min_value = (eq_value < min_value) ?
1264 eq_value : min_value;
1285 eq_value = (
max_value + min_value + 1)/2;
1289 reg14h = (reg14h & 0xFF07) | ((eq_value << 3) & 0x00F8);
1290 reg14h = (reg14h | 0x6000) & 0xFDFF;
1298 (reg14h | 0x2200) & 0xBFFF);
1301 (reg14h | 0x2000) & 0xBFFF);
1313 static void sis900_timer(
unsigned long data)
1317 struct mii_phy *mii_phy = sis_priv->
mii;
1318 static const int next_tick = 5*
HZ;
1324 sis900_read_mode(net_dev, &
speed, &duplex);
1326 sis900_set_mode(sis_priv,
speed, duplex);
1328 netif_start_queue(net_dev);
1340 if (!netif_carrier_ok(net_dev)) {
1343 status = sis900_default_phy(net_dev);
1344 mii_phy = sis_priv->
mii;
1346 if (status & MII_STAT_LINK){
1347 sis900_check_mode(net_dev, mii_phy);
1352 if (!(status & MII_STAT_LINK)){
1358 if ((mii_phy->
phy_id0 == 0x001D) &&
1359 ((mii_phy->
phy_id1 & 0xFFF0) == 0x8000))
1360 sis900_reset_phy(net_dev, sis_priv->
cur_phy);
1384 static void sis900_check_mode(
struct net_device *net_dev,
struct mii_phy *mii_phy)
1392 sis900_set_capability(net_dev , mii_phy);
1393 sis900_auto_negotiate(net_dev, sis_priv->
cur_phy);
1398 sis900_set_mode(sis_priv, speed, duplex);
1416 static void sis900_set_mode(
struct sis900_private *sp,
int speed,
int duplex)
1419 u32 tx_flags = 0, rx_flags = 0;
1444 #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
1464 static void sis900_auto_negotiate(
struct net_device *net_dev,
int phy_addr)
1470 for (i = 0; i < 2; i++)
1471 status = mdio_read(net_dev, phy_addr,
MII_STATUS);
1473 if (!(status & MII_STAT_LINK)){
1499 static void sis900_read_mode(
struct net_device *net_dev,
int *speed,
int *duplex)
1502 struct mii_phy *phy = sis_priv->
mii;
1503 int phy_addr = sis_priv->
cur_phy;
1505 u16 autoadv, autorec;
1508 for (i = 0; i < 2; i++)
1511 if (!(status & MII_STAT_LINK))
1517 status = autoadv & autorec;
1530 if ((phy->
phy_id0 == 0x0000) && ((phy->
phy_id1 & 0xFFF0) == 0x8200)) {
1533 if (
mdio_read(net_dev, phy_addr, 0x0019) & 0x01)
1541 "100mbps" :
"10mbps",
1554 static void sis900_tx_timeout(
struct net_device *net_dev)
1558 unsigned long flags;
1578 pci_unmap_single(sis_priv->
pci_dev,
1585 net_dev->
stats.tx_dropped++;
1589 netif_wake_queue(net_dev);
1591 spin_unlock_irqrestore(&sis_priv->
lock, flags);
1618 unsigned long flags;
1619 unsigned int index_cur_tx, index_dirty_tx;
1620 unsigned int count_dirty_tx;
1624 netif_stop_queue(net_dev);
1641 index_cur_tx = sis_priv->
cur_tx;
1642 index_dirty_tx = sis_priv->
dirty_tx;
1644 for (count_dirty_tx = 0; index_cur_tx != index_dirty_tx; index_dirty_tx++)
1647 if (index_cur_tx == index_dirty_tx) {
1650 netif_stop_queue(net_dev);
1651 }
else if (count_dirty_tx < NUM_TX_DESC) {
1653 netif_start_queue(net_dev);
1657 netif_stop_queue(net_dev);
1660 spin_unlock_irqrestore(&sis_priv->
lock, flags);
1679 static irqreturn_t sis900_interrupt(
int irq,
void *dev_instance)
1683 int boguscnt = max_interrupt_work;
1686 unsigned int handled = 0;
1688 spin_lock (&sis_priv->
lock);
1705 sis900_finish_xmit(net_dev);
1711 "status %#8.8x.\n", net_dev->
name, status);
1714 if (--boguscnt < 0) {
1717 "interrupt status = %#8.8x.\n",
1718 net_dev->
name, status);
1725 "interrupt status = 0x%#8.8x.\n",
1728 spin_unlock (&sis_priv->
lock);
1742 static int sis900_rx(
struct net_device *net_dev)
1754 rx_work_limit = sis_priv->
dirty_rx + NUM_RX_DESC - sis_priv->
cur_rx;
1756 while (rx_status &
OWN) {
1757 unsigned int rx_size;
1760 if (--rx_work_limit < 0)
1763 data_size = rx_status &
DSIZE;
1766 #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
1769 rx_status &= (~ ((
unsigned int)TOOLONG));
1776 "received, buffer status = 0x%8.8x/%d.\n",
1777 net_dev->
name, rx_status, data_size);
1778 net_dev->
stats.rx_errors++;
1780 net_dev->
stats.rx_over_errors++;
1781 if (rx_status & (TOOLONG|
RUNT))
1782 net_dev->
stats.rx_length_errors++;
1784 net_dev->
stats.rx_frame_errors++;
1786 net_dev->
stats.rx_crc_errors++;
1793 pci_unmap_single(sis_priv->
pci_dev,
1807 net_dev->
stats.rx_dropped++;
1808 goto refill_rx_ring;
1817 "encountered in Rx ring\n"
1818 "cur_rx:%4.4d, dirty_rx:%4.4d\n",
1833 net_dev->
stats.multicast++;
1834 net_dev->
stats.rx_bytes += rx_size;
1835 net_dev->
stats.rx_packets++;
1864 "deferring packet.\n",
1866 net_dev->
stats.rx_dropped++;
1892 static void sis900_finish_xmit (
struct net_device *net_dev)
1904 if (tx_status & OWN) {
1915 "error, Tx status %8.8x.\n",
1916 net_dev->
name, tx_status);
1917 net_dev->
stats.tx_errors++;
1919 net_dev->
stats.tx_fifo_errors++;
1920 if (tx_status &
ABORT)
1921 net_dev->
stats.tx_aborted_errors++;
1923 net_dev->
stats.tx_carrier_errors++;
1925 net_dev->
stats.tx_window_errors++;
1928 net_dev->
stats.collisions += (tx_status &
COLCNT) >> 16;
1929 net_dev->
stats.tx_bytes += tx_status &
DSIZE;
1930 net_dev->
stats.tx_packets++;
1934 pci_unmap_single(sis_priv->
pci_dev,
1943 if (sis_priv->
tx_full && netif_queue_stopped(net_dev) &&
1948 netif_wake_queue (net_dev);
1960 static int sis900_close(
struct net_device *net_dev)
1968 netif_stop_queue(net_dev);
2014 static void sis900_get_drvinfo(
struct net_device *net_dev,
2031 static void sis900_set_msglevel(
struct net_device *net_dev,
u32 value)
2043 static int sis900_get_settings(
struct net_device *net_dev,
2047 spin_lock_irq(&sis_priv->
lock);
2049 spin_unlock_irq(&sis_priv->
lock);
2053 static int sis900_set_settings(
struct net_device *net_dev,
2058 spin_lock_irq(&sis_priv->
lock);
2060 spin_unlock_irq(&sis_priv->
lock);
2064 static int sis900_nway_reset(
struct net_device *net_dev)
2085 u32 cfgpmcsr = 0, pmctrl_bits = 0;
2126 if (pmctrl_bits &
LINKON)
2132 static const struct ethtool_ops sis900_ethtool_ops = {
2133 .get_drvinfo = sis900_get_drvinfo,
2134 .get_msglevel = sis900_get_msglevel,
2135 .set_msglevel = sis900_set_msglevel,
2136 .get_link = sis900_get_link,
2137 .get_settings = sis900_get_settings,
2138 .set_settings = sis900_set_settings,
2139 .nway_reset = sis900_nway_reset,
2140 .get_wol = sis900_get_wol,
2141 .set_wol = sis900_set_wol
2188 struct mii_phy *mii_phy = sis_priv->
mii;
2286 static inline u16 sis900_mcast_bitnr(
u8 *
addr,
u8 revision)
2293 return (
int)(crc >> 24);
2295 return (
int)(crc >> 25);
2307 static void set_rx_mode(
struct net_device *net_dev)
2311 u16 mc_filter[16] = {0};
2312 int i, table_entries;
2325 for (i = 0; i < table_entries; i++)
2326 mc_filter[i] = 0xffff;
2331 for (i = 0; i < table_entries; i++)
2332 mc_filter[i] = 0xffff;
2341 unsigned int bit_nr;
2343 bit_nr = sis900_mcast_bitnr(ha->
addr,
2345 mc_filter[bit_nr >> 4] |= (1 << (bit_nr & 0xf));
2350 for (i = 0; i < table_entries; i++) {
2382 static void sis900_reset(
struct net_device *net_dev)
2396 for (i = 0; status && (i < 1000); i++)
2413 static void __devexit sis900_remove(
struct pci_dev *pci_dev)
2415 struct net_device *net_dev = pci_get_drvdata(pci_dev);
2421 struct mii_phy *phy = sis_priv->
first_mii;
2434 pci_set_drvdata(pci_dev,
NULL);
2441 struct net_device *net_dev = pci_get_drvdata(pci_dev);
2445 if(!netif_running(net_dev))
2448 netif_stop_queue(net_dev);
2460 static int sis900_resume(
struct pci_dev *pci_dev)
2462 struct net_device *net_dev = pci_get_drvdata(pci_dev);
2466 if(!netif_running(net_dev))
2471 sis900_init_rxfilter(net_dev);
2473 sis900_init_tx_ring(net_dev);
2474 sis900_init_rx_ring(net_dev);
2476 set_rx_mode(net_dev);
2479 netif_start_queue(net_dev);
2489 sis900_check_mode(net_dev, sis_priv->
mii);
2495 static struct pci_driver sis900_pci_driver = {
2497 .id_table = sis900_pci_tbl,
2498 .probe = sis900_probe,
2501 .suspend = sis900_suspend,
2502 .resume = sis900_resume,
2506 static int __init sis900_init_module(
void)
2513 return pci_register_driver(&sis900_pci_driver);
2516 static void __exit sis900_cleanup_module(
void)