26 #include <linux/module.h>
27 #include <linux/kernel.h>
29 #include <linux/pci.h>
31 #include <linux/netdevice.h>
33 #include <linux/ethtool.h>
34 #include <linux/mii.h>
39 #define SC92031_NAME "sc92031"
42 #define SC92031_USE_PIO 0
45 static int multicast_filter_limit = 64;
48 "Maximum number of filtered multicast addresses");
53 " 0x01 = 10M half, 0x02 = 10M full,"
54 " 0x04 = 100M half, 0x08 = 100M full)");
57 #define RX_BUF_LEN_IDX 3
58 #define RX_BUF_LEN (8192 << RX_BUF_LEN_IDX)
64 #define MAX_ETH_FRAME_SIZE 1536
67 #define TX_BUF_SIZE MAX_ETH_FRAME_SIZE
68 #define TX_BUF_TOT_LEN (TX_BUF_SIZE * NUM_TX_DESC)
71 #define RX_FIFO_THRESH 7
74 #define TX_TIMEOUT (4*HZ)
76 #define SILAN_STATS_NUM 2
79 #define AUTOSELECT 0x00
82 #define M100_HALF 0x04
83 #define M100_FULL 0x08
119 #define MII_OutputStatus 24
121 #define PHY_16_JAB_ENB 0x1000
122 #define PHY_16_PORT_ENB 0x1
308 static inline void _sc92031_dummy_read(
void __iomem *port_base)
313 static u32 _sc92031_mii_wait(
void __iomem *port_base)
329 _sc92031_mii_wait(port_base);
334 return _sc92031_mii_wait(port_base);
337 static void _sc92031_mii_scan(
void __iomem *port_base)
339 _sc92031_mii_cmd(port_base,
Mii_SCAN, 0x1 << 6);
342 static u16 _sc92031_mii_read(
void __iomem *port_base,
unsigned reg)
344 return _sc92031_mii_cmd(port_base,
Mii_READ, reg << 6) >> 13;
347 static void _sc92031_mii_write(
void __iomem *port_base,
unsigned reg,
u16 val)
349 _sc92031_mii_cmd(port_base,
Mii_WRITE, (reg << 6) | ((
u32)val << 11));
352 static void sc92031_disable_interrupts(
struct net_device *
dev)
363 _sc92031_dummy_read(port_base);
368 tasklet_disable(&priv->
tasklet);
371 static void sc92031_enable_interrupts(
struct net_device *
dev)
376 tasklet_enable(&priv->
tasklet);
413 dev->
stats.tx_dropped++;
418 static void _sc92031_set_mar(
struct net_device *dev)
422 u32 mar0 = 0, mar1 = 0;
427 mar0 = mar1 = 0xffffffff;
438 if (crc & 0x01) bit |= 0x02;
439 if (crc & 0x02) bit |= 0x01;
440 if (crc & 0x10) bit |= 0x20;
441 if (crc & 0x20) bit |= 0x10;
442 if (crc & 0x40) bit |= 0x08;
443 if (crc & 0x80) bit |= 0x04;
446 mar0 |= 0x1 << (bit - 32);
456 static void _sc92031_set_rx_config(
struct net_device *dev)
460 unsigned int old_mc_flags;
461 u32 rx_config_bits = 0;
482 if (netif_carrier_ok(dev) && priv->
mc_flags != old_mc_flags)
486 static bool _sc92031_check_media(
struct net_device *dev)
492 bmsr = _sc92031_mii_read(port_base,
MII_BMSR);
495 bool speed_100, duplex_full;
496 u32 flow_ctrl_config = 0;
497 u16 output_status = _sc92031_mii_read(port_base,
499 _sc92031_mii_scan(port_base);
501 speed_100 = output_status & 0x2;
502 duplex_full = output_status & 0x4;
514 _sc92031_set_rx_config(dev);
525 _sc92031_set_mar(dev);
526 _sc92031_set_rx_config(dev);
527 _sc92031_enable_tx_rx(dev);
532 if (printk_ratelimit())
535 speed_100 ?
"100" :
"10",
536 duplex_full ?
"full" :
"half");
539 _sc92031_mii_scan(port_base);
543 _sc92031_disable_tx_rx(dev);
545 if (printk_ratelimit())
551 static void _sc92031_phy_reset(
struct net_device *dev)
587 _sc92031_mii_write(port_base,
MII_JAB,
589 _sc92031_mii_scan(port_base);
592 netif_stop_queue(dev);
595 static void _sc92031_reset(
struct net_device *dev)
622 _sc92031_tx_clear(dev);
635 _sc92031_phy_reset(dev);
636 _sc92031_check_media(dev);
648 static void _sc92031_tx_tasklet(
struct net_device *dev)
653 unsigned old_tx_tail;
668 dev->
stats.tx_bytes += tx_status & 0x1fff;
669 dev->
stats.tx_packets++;
671 dev->
stats.collisions += (tx_status >> 22) & 0xf;
675 dev->
stats.tx_errors++;
678 dev->
stats.tx_aborted_errors++;
681 dev->
stats.tx_carrier_errors++;
684 dev->
stats.tx_window_errors++;
688 dev->
stats.tx_fifo_errors++;
691 if (priv->
tx_tail != old_tx_tail)
692 if (netif_queue_stopped(dev))
693 netif_wake_queue(dev);
696 static void _sc92031_rx_tasklet_error(
struct net_device *dev,
700 dev->
stats.rx_errors++;
701 dev->
stats.rx_length_errors++;
705 dev->
stats.rx_errors++;
708 dev->
stats.rx_length_errors++;
711 dev->
stats.rx_frame_errors++;
714 dev->
stats.rx_crc_errors++;
721 static void _sc92031_rx_tasklet(
struct net_device *dev)
728 unsigned rx_ring_offset;
751 if (printk_ratelimit())
761 unsigned rx_size, rx_size_align, pkt_size;
767 rx_size = rx_status >> 20;
768 rx_size_align = (rx_size + 3) & ~3;
769 pkt_size = rx_size - 4;
771 rx_ring_offset = (rx_ring_offset + 4) %
RX_BUF_LEN;
777 _sc92031_rx_tasklet_error(dev, rx_status, rx_size);
781 if (
unlikely(rx_size_align + 4 > rx_len)) {
782 if (printk_ratelimit())
787 rx_len -= rx_size_align + 4;
789 skb = netdev_alloc_skb_ip_align(dev, pkt_size);
791 if (printk_ratelimit())
792 printk(
KERN_ERR "%s: Couldn't allocate a skb_buff for a packet of size %u\n",
793 dev->
name, pkt_size);
797 if ((rx_ring_offset + pkt_size) >
RX_BUF_LEN) {
799 rx_ring + rx_ring_offset,
RX_BUF_LEN - rx_ring_offset);
801 rx_ring, pkt_size - (
RX_BUF_LEN - rx_ring_offset));
803 memcpy(
skb_put(skb, pkt_size), rx_ring + rx_ring_offset, pkt_size);
809 dev->
stats.rx_bytes += pkt_size;
810 dev->
stats.rx_packets++;
813 dev->
stats.multicast++;
816 rx_ring_offset = (rx_ring_offset + rx_size_align) %
RX_BUF_LEN;
824 static void _sc92031_link_tasklet(
struct net_device *dev)
826 if (_sc92031_check_media(dev))
827 netif_wake_queue(dev);
829 netif_stop_queue(dev);
830 dev->
stats.tx_carrier_errors++;
834 static void sc92031_tasklet(
unsigned long data)
843 spin_lock(&priv->
lock);
848 if (intr_status &
TxOK)
849 _sc92031_tx_tasklet(dev);
851 if (intr_status &
RxOK)
852 _sc92031_rx_tasklet(dev);
855 dev->
stats.rx_errors++;
858 dev->
stats.rx_errors++;
859 dev->
stats.rx_length_errors++;
863 _sc92031_link_tasklet(dev);
872 spin_unlock(&priv->
lock);
884 _sc92031_dummy_read(port_base);
887 if (
unlikely(intr_status == 0xffffffff))
895 tasklet_schedule(&priv->
tasklet);
915 if (netif_running(dev)) {
918 spin_lock_bh(&priv->
lock);
923 if (temp == 0xffff) {
929 spin_unlock_bh(&priv->
lock);
945 dev->
stats.tx_dropped++;
949 spin_lock(&priv->
lock);
951 if (
unlikely(!netif_carrier_ok(dev))) {
952 dev->
stats.tx_dropped++;
974 tx_status = 0x30000 | len;
976 tx_status = 0x50000 | len;
979 port_base +
TxAddr0 + entry * 4);
984 netif_stop_queue(dev);
987 spin_unlock(&priv->
lock);
995 static int sc92031_open(
struct net_device *dev)
1005 goto out_alloc_rx_ring;
1012 goto out_alloc_tx_bufs;
1019 goto out_request_irq;
1024 spin_lock_bh(&priv->
lock);
1026 _sc92031_reset(dev);
1029 spin_unlock_bh(&priv->
lock);
1030 sc92031_enable_interrupts(dev);
1032 if (netif_carrier_ok(dev))
1033 netif_start_queue(dev);
1035 netif_tx_disable(dev);
1049 static int sc92031_stop(
struct net_device *dev)
1054 netif_tx_disable(dev);
1057 sc92031_disable_interrupts(dev);
1059 spin_lock_bh(&priv->
lock);
1061 _sc92031_disable_tx_rx(dev);
1062 _sc92031_tx_clear(dev);
1065 spin_unlock_bh(&priv->
lock);
1076 static void sc92031_set_multicast_list(
struct net_device *dev)
1080 spin_lock_bh(&priv->
lock);
1082 _sc92031_set_mar(dev);
1083 _sc92031_set_rx_config(dev);
1086 spin_unlock_bh(&priv->
lock);
1089 static void sc92031_tx_timeout(
struct net_device *dev)
1094 sc92031_disable_interrupts(dev);
1096 spin_lock(&priv->
lock);
1100 _sc92031_reset(dev);
1103 spin_unlock(&priv->
lock);
1106 sc92031_enable_interrupts(dev);
1108 if (netif_carrier_ok(dev))
1109 netif_wake_queue(dev);
1112 #ifdef CONFIG_NET_POLL_CONTROLLER
1113 static void sc92031_poll_controller(
struct net_device *dev)
1116 const int irq = priv->
pdev->irq;
1119 if (sc92031_interrupt(irq, dev) !=
IRQ_NONE)
1120 sc92031_tasklet((
unsigned long)dev);
1125 static int sc92031_ethtool_get_settings(
struct net_device *dev,
1134 spin_lock_bh(&priv->
lock);
1140 _sc92031_mii_scan(port_base);
1143 spin_unlock_bh(&priv->
lock);
1165 if ((phy_ctrl & (PhyCtrlSpd100 |
PhyCtrlDux))
1172 ethtool_cmd_speed_set(cmd,
1183 static int sc92031_ethtool_set_settings(
struct net_device *dev,
1188 u32 speed = ethtool_cmd_speed(cmd);
1239 spin_lock_bh(&priv->
lock);
1242 phy_ctrl |= old_phy_ctrl & ~(PhyCtrlAne |
PhyCtrlDux
1244 if (phy_ctrl != old_phy_ctrl)
1247 spin_unlock_bh(&priv->
lock);
1252 static void sc92031_ethtool_get_wol(
struct net_device *dev,
1259 spin_lock_bh(&priv->
lock);
1261 spin_unlock_bh(&priv->
lock);
1279 static int sc92031_ethtool_set_wol(
struct net_device *dev,
1286 spin_lock_bh(&priv->
lock);
1305 spin_unlock_bh(&priv->
lock);
1310 static int sc92031_ethtool_nway_reset(
struct net_device *dev)
1317 spin_lock_bh(&priv->
lock);
1319 bmcr = _sc92031_mii_read(port_base,
MII_BMCR);
1328 _sc92031_mii_scan(port_base);
1331 spin_unlock_bh(&priv->
lock);
1341 static void sc92031_ethtool_get_strings(
struct net_device *dev,
1342 u32 stringset,
u8 *data)
1345 memcpy(data, sc92031_ethtool_stats_strings,
1349 static int sc92031_ethtool_get_sset_count(
struct net_device *dev,
int sset)
1359 static void sc92031_ethtool_get_ethtool_stats(
struct net_device *dev,
1364 spin_lock_bh(&priv->
lock);
1367 spin_unlock_bh(&priv->
lock);
1370 static const struct ethtool_ops sc92031_ethtool_ops = {
1371 .get_settings = sc92031_ethtool_get_settings,
1372 .set_settings = sc92031_ethtool_set_settings,
1373 .get_wol = sc92031_ethtool_get_wol,
1374 .set_wol = sc92031_ethtool_set_wol,
1375 .nway_reset = sc92031_ethtool_nway_reset,
1377 .get_strings = sc92031_ethtool_get_strings,
1378 .get_sset_count = sc92031_ethtool_get_sset_count,
1379 .get_ethtool_stats = sc92031_ethtool_get_ethtool_stats,
1384 .ndo_get_stats = sc92031_get_stats,
1385 .ndo_start_xmit = sc92031_start_xmit,
1386 .ndo_open = sc92031_open,
1387 .ndo_stop = sc92031_stop,
1388 .ndo_set_rx_mode = sc92031_set_multicast_list,
1392 .ndo_tx_timeout = sc92031_tx_timeout,
1393 #ifdef CONFIG_NET_POLL_CONTROLLER
1394 .ndo_poll_controller = sc92031_poll_controller,
1409 goto out_enable_device;
1415 goto out_set_dma_mask;
1417 err = pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(32));
1419 goto out_set_dma_mask;
1423 goto out_request_regions;
1434 goto out_alloc_etherdev;
1437 pci_set_drvdata(pdev, dev);
1448 priv = netdev_priv(dev);
1455 tasklet_disable_nosync(&priv->
tasklet);
1471 goto out_register_netdev;
1479 out_register_netdev:
1485 out_request_regions:
1494 struct net_device *dev = pci_get_drvdata(pdev);
1507 struct net_device *dev = pci_get_drvdata(pdev);
1512 if (!netif_running(dev))
1518 sc92031_disable_interrupts(dev);
1520 spin_lock_bh(&priv->
lock);
1522 _sc92031_disable_tx_rx(dev);
1523 _sc92031_tx_clear(dev);
1526 spin_unlock_bh(&priv->
lock);
1534 static int sc92031_resume(
struct pci_dev *pdev)
1536 struct net_device *dev = pci_get_drvdata(pdev);
1542 if (!netif_running(dev))
1546 spin_lock_bh(&priv->
lock);
1548 _sc92031_reset(dev);
1551 spin_unlock_bh(&priv->
lock);
1552 sc92031_enable_interrupts(dev);
1556 if (netif_carrier_ok(dev))
1557 netif_wake_queue(dev);
1559 netif_tx_disable(dev);
1573 static struct pci_driver sc92031_pci_driver = {
1575 .id_table = sc92031_pci_device_id_table,
1576 .probe = sc92031_probe,
1578 .suspend = sc92031_suspend,
1579 .resume = sc92031_resume,
1582 static int __init sc92031_init(
void)
1584 return pci_register_driver(&sc92031_pci_driver);
1587 static void __exit sc92031_exit(
void)