134 #include <asm/uaccess.h> |
134 #include <asm/uaccess.h> |
135 |
135 |
136 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
136 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
137 |
137 |
138 #include "ec_device.h" |
138 #include "ec_device.h" |
139 #include <rtai.h> |
|
140 #include <linux/delay.h> |
|
141 #include "ec_dbg.h" |
139 #include "ec_dbg.h" |
142 |
140 |
143 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
141 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
144 |
142 |
145 #define RTL8139_DRIVER_NAME DRV_NAME " Fast Ethernet driver " DRV_VERSION |
143 #define RTL8139_DRIVER_NAME DRV_NAME " Fast Ethernet driver " DRV_VERSION |
190 The RTL chips use a 64 element hash table based on the Ethernet CRC. */ |
188 The RTL chips use a 64 element hash table based on the Ethernet CRC. */ |
191 static int multicast_filter_limit = 32; |
189 static int multicast_filter_limit = 32; |
192 |
190 |
193 /* bitmapped message enable number */ |
191 /* bitmapped message enable number */ |
194 static int debug = -1; |
192 static int debug = -1; |
|
193 |
|
194 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
195 |
|
196 // Device index for EtherCAT device selection |
|
197 static int ec_device_index = -1; |
|
198 |
|
199 //#define ECAT_DEBUG |
|
200 |
|
201 EtherCAT_device_t rtl_ecat_dev; |
|
202 |
|
203 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
195 |
204 |
196 /* Size of the in-memory receive ring. */ |
205 /* Size of the in-memory receive ring. */ |
197 #define RX_BUF_LEN_IDX 2 /* 0==8K, 1==16K, 2==32K, 3==64K */ |
206 #define RX_BUF_LEN_IDX 2 /* 0==8K, 1==16K, 2==32K, 3==64K */ |
198 #define RX_BUF_LEN (8192 << RX_BUF_LEN_IDX) |
207 #define RX_BUF_LEN (8192 << RX_BUF_LEN_IDX) |
199 #define RX_BUF_PAD 16 |
208 #define RX_BUF_PAD 16 |
633 MODULE_PARM_DESC (multicast_filter_limit, "8139too maximum number of filtered multicast addresses"); |
642 MODULE_PARM_DESC (multicast_filter_limit, "8139too maximum number of filtered multicast addresses"); |
634 MODULE_PARM_DESC (max_interrupt_work, "8139too maximum events handled per interrupt"); |
643 MODULE_PARM_DESC (max_interrupt_work, "8139too maximum events handled per interrupt"); |
635 MODULE_PARM_DESC (media, "8139too: Bits 4+9: force full duplex, bit 5: 100Mbps"); |
644 MODULE_PARM_DESC (media, "8139too: Bits 4+9: force full duplex, bit 5: 100Mbps"); |
636 MODULE_PARM_DESC (full_duplex, "8139too: Force full duplex for board(s) (1)"); |
645 MODULE_PARM_DESC (full_duplex, "8139too: Force full duplex for board(s) (1)"); |
637 |
646 |
|
647 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
648 |
|
649 MODULE_PARM(ec_device_index, "i"); |
|
650 MODULE_PARM_DESC(ec_device_index, "Index of the device reserved for EtherCAT."); |
|
651 |
|
652 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
653 |
638 static int read_eeprom (void *ioaddr, int location, int addr_len); |
654 static int read_eeprom (void *ioaddr, int location, int addr_len); |
639 static int rtl8139_open (struct net_device *dev); |
655 static int rtl8139_open (struct net_device *dev); |
640 static int mdio_read (struct net_device *dev, int phy_id, int location); |
656 static int mdio_read (struct net_device *dev, int phy_id, int location); |
641 static void mdio_write (struct net_device *dev, int phy_id, int location, |
657 static void mdio_write (struct net_device *dev, int phy_id, int location, |
642 int val); |
658 int val); |
645 static void rtl8139_init_ring (struct net_device *dev); |
661 static void rtl8139_init_ring (struct net_device *dev); |
646 static int rtl8139_start_xmit (struct sk_buff *skb, |
662 static int rtl8139_start_xmit (struct sk_buff *skb, |
647 struct net_device *dev); |
663 struct net_device *dev); |
648 static void rtl8139_interrupt (int irq, void *dev_instance, |
664 static void rtl8139_interrupt (int irq, void *dev_instance, |
649 struct pt_regs *regs); |
665 struct pt_regs *regs); |
650 static void rt_rtl8139_interrupt(void); |
|
651 static int rtl8139_close (struct net_device *dev); |
666 static int rtl8139_close (struct net_device *dev); |
652 static int netdev_ioctl (struct net_device *dev, struct ifreq *rq, int cmd); |
667 static int netdev_ioctl (struct net_device *dev, struct ifreq *rq, int cmd); |
653 static struct net_device_stats *rtl8139_get_stats (struct net_device *dev); |
668 static struct net_device_stats *rtl8139_get_stats (struct net_device *dev); |
654 static void rtl8139_set_rx_mode (struct net_device *dev); |
669 static void rtl8139_set_rx_mode (struct net_device *dev); |
655 static void __set_rx_mode (struct net_device *dev); |
670 static void __set_rx_mode (struct net_device *dev); |
709 #define RTL_R8(reg) readb (ioaddr + (reg)) |
724 #define RTL_R8(reg) readb (ioaddr + (reg)) |
710 #define RTL_R16(reg) readw (ioaddr + (reg)) |
725 #define RTL_R16(reg) readw (ioaddr + (reg)) |
711 #define RTL_R32(reg) ((unsigned long) readl (ioaddr + (reg))) |
726 #define RTL_R32(reg) ((unsigned long) readl (ioaddr + (reg))) |
712 |
727 |
713 #endif /* USE_IO_OPS */ |
728 #endif /* USE_IO_OPS */ |
714 |
|
715 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
716 |
|
717 #define ECATcard 1 // Diese Ethernetkarte wird für Ethercat verwendet |
|
718 |
|
719 //#define ECAT_DEBUG |
|
720 |
|
721 EtherCAT_device_t rtl_ecat_dev; |
|
722 |
|
723 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
724 |
729 |
725 static const u16 rtl8139_intr_mask = |
730 static const u16 rtl8139_intr_mask = |
726 PCIErr | PCSTimeout | RxUnderrun | RxOverflow | RxFIFOOver | |
731 PCIErr | PCSTimeout | RxUnderrun | RxOverflow | RxFIFOOver | |
727 TxErr | TxOK | RxErr | RxOK; |
732 TxErr | TxOK | RxErr | RxOK; |
728 |
733 |
997 if (i < 0) |
1002 if (i < 0) |
998 return i; |
1003 return i; |
999 |
1004 |
1000 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1005 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1001 |
1006 |
1002 if (board_idx == ECATcard) |
1007 if (board_idx == ec_device_index) |
1003 { |
1008 { |
1004 EC_DBG("EtherCAT registering board %d.\n", board_idx); |
1009 EC_DBG("EtherCAT registering board %d.\n", board_idx); |
1005 |
1010 |
1006 if (EtherCAT_device_assign(&rtl_ecat_dev, dev) < 0) |
1011 if (EtherCAT_device_assign(&rtl_ecat_dev, dev) < 0) |
1007 goto err_out; |
1012 goto err_out; |
1044 tp->mmio_addr = ioaddr; |
1049 tp->mmio_addr = ioaddr; |
1045 spin_lock_init (&tp->lock); |
1050 spin_lock_init (&tp->lock); |
1046 |
1051 |
1047 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1052 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1048 |
1053 |
1049 if (board_idx == ECATcard) |
1054 if (board_idx == ec_device_index) |
1050 { |
1055 { |
1051 rtl_ecat_dev.lock = &tp->lock; |
1056 rtl_ecat_dev.lock = &tp->lock; |
1052 } |
1057 } |
1053 |
1058 |
1054 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1059 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1376 |
1381 |
1377 EC_DBG(KERN_DEBUG "%s: open\n", dev->name); |
1382 EC_DBG(KERN_DEBUG "%s: open\n", dev->name); |
1378 |
1383 |
1379 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1384 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1380 |
1385 |
1381 if (dev != rtl_ecat_dev.dev) |
1386 if (dev != rtl_ecat_dev.dev) |
1382 { |
1387 { |
1383 retval = request_irq(dev->irq, rtl8139_interrupt, SA_SHIRQ, dev->name, dev); |
1388 retval = request_irq(dev->irq, rtl8139_interrupt, SA_SHIRQ, dev->name, dev); |
|
1389 if (retval) |
|
1390 return retval; |
1384 } |
1391 } |
1385 else |
|
1386 { |
|
1387 //rt_disable_irq(dev->irq); |
|
1388 retval = rt_request_global_irq(dev->irq,rt_rtl8139_interrupt); |
|
1389 //rt_enable_irq(dev->irq); |
|
1390 } |
|
1391 |
|
1392 if (retval) |
|
1393 return retval; |
|
1394 |
1392 |
1395 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1393 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1396 |
1394 |
1397 tp->tx_bufs = pci_alloc_consistent(tp->pci_dev, TX_BUF_TOT_LEN, |
1395 tp->tx_bufs = pci_alloc_consistent(tp->pci_dev, TX_BUF_TOT_LEN, |
1398 &tp->tx_bufs_dma); |
1396 &tp->tx_bufs_dma); |
1404 |
1402 |
1405 if (dev != rtl_ecat_dev.dev) |
1403 if (dev != rtl_ecat_dev.dev) |
1406 { |
1404 { |
1407 free_irq(dev->irq, dev); |
1405 free_irq(dev->irq, dev); |
1408 } |
1406 } |
1409 else |
1407 |
1410 { |
|
1411 rt_free_global_irq (dev->irq); |
|
1412 } |
|
1413 |
|
1414 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1408 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1415 |
1409 |
1416 if (tp->tx_bufs) |
1410 if (tp->tx_bufs) |
1417 pci_free_consistent(tp->pci_dev, TX_BUF_TOT_LEN, |
1411 pci_free_consistent(tp->pci_dev, TX_BUF_TOT_LEN, |
1418 tp->tx_bufs, tp->tx_bufs_dma); |
1412 tp->tx_bufs, tp->tx_bufs_dma); |
1419 if (tp->rx_ring) |
1413 if (tp->rx_ring) |
1420 pci_free_consistent(tp->pci_dev, RX_BUF_TOT_LEN, |
1414 pci_free_consistent(tp->pci_dev, RX_BUF_TOT_LEN, |
1421 tp->rx_ring, tp->rx_ring_dma); |
1415 tp->rx_ring, tp->rx_ring_dma); |
1422 |
1416 |
1423 return -ENOMEM; |
1417 return -ENOMEM; |
1424 |
1418 |
1425 } |
1419 } |
1426 |
1420 |
1427 tp->mii.full_duplex = tp->mii.force_media; |
1421 tp->mii.full_duplex = tp->mii.force_media; |
1447 |
1441 |
1448 if (tp->thr_pid < 0) |
1442 if (tp->thr_pid < 0) |
1449 EC_DBG (KERN_WARNING "%s: unable to start kernel thread\n", |
1443 EC_DBG (KERN_WARNING "%s: unable to start kernel thread\n", |
1450 dev->name); |
1444 dev->name); |
1451 } |
1445 } |
1452 #if 0 |
|
1453 else |
|
1454 { |
|
1455 rt_enable_irq(dev->irq); |
|
1456 } |
|
1457 #endif |
|
1458 |
1446 |
1459 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1447 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1460 |
1448 |
1461 EC_DBG(KERN_DEBUG "%s: open finished.\n", dev->name); |
1449 EC_DBG(KERN_DEBUG "%s: open finished.\n", dev->name); |
1462 |
1450 |
1468 { |
1456 { |
1469 struct rtl8139_private *tp = dev->priv; |
1457 struct rtl8139_private *tp = dev->priv; |
1470 |
1458 |
1471 if (tp->phys[0] >= 0) { |
1459 if (tp->phys[0] >= 0) { |
1472 u16 mii_lpa = mdio_read(dev, tp->phys[0], MII_LPA); |
1460 u16 mii_lpa = mdio_read(dev, tp->phys[0], MII_LPA); |
|
1461 |
1473 if (mii_lpa == 0xffff) |
1462 if (mii_lpa == 0xffff) |
1474 ; /* Not there */ |
1463 ; /* Not there */ |
1475 else if ((mii_lpa & LPA_100FULL) == LPA_100FULL |
1464 else if ((mii_lpa & LPA_100FULL) == LPA_100FULL |
1476 || (mii_lpa & 0x00C0) == LPA_10FULL) |
1465 || (mii_lpa & 0x00C0) == LPA_10FULL) |
1477 tp->mii.full_duplex = 1; |
1466 tp->mii.full_duplex = 1; |
1549 /* make sure RxTx has started */ |
1538 /* make sure RxTx has started */ |
1550 tmp = RTL_R8 (ChipCmd); |
1539 tmp = RTL_R8 (ChipCmd); |
1551 if ((!(tmp & CmdRxEnb)) || (!(tmp & CmdTxEnb))) |
1540 if ((!(tmp & CmdRxEnb)) || (!(tmp & CmdTxEnb))) |
1552 RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb); |
1541 RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb); |
1553 |
1542 |
1554 /* Enable all known interrupts by setting the interrupt mask. */ |
|
1555 RTL_W16 (IntrMask, rtl8139_intr_mask); |
|
1556 |
|
1557 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1543 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1558 |
1544 |
1559 if (dev != rtl_ecat_dev.dev) netif_start_queue (dev); |
1545 if (dev != rtl_ecat_dev.dev) |
1560 |
1546 { |
1561 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1547 /* Enable all known interrupts by setting the interrupt mask. */ |
|
1548 RTL_W16 (IntrMask, rtl8139_intr_mask); |
|
1549 netif_start_queue (dev); |
|
1550 } |
|
1551 else |
|
1552 { |
|
1553 RTL_W16 (IntrMask, 0x0000); |
|
1554 } |
|
1555 |
|
1556 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1562 |
1557 |
1563 EC_DBG(KERN_DEBUG "%s: rtl8139_hw_start finished.\n", dev->name); |
1558 EC_DBG(KERN_DEBUG "%s: rtl8139_hw_start finished.\n", dev->name); |
1564 } |
1559 } |
1565 |
1560 |
1566 |
1561 |
1827 EC_DBG (KERN_DEBUG "%s: Tx descriptor %d is %8.8lx.%s\n", |
1822 EC_DBG (KERN_DEBUG "%s: Tx descriptor %d is %8.8lx.%s\n", |
1828 dev->name, i, RTL_R32 (TxStatus0 + (i * 4)), |
1823 dev->name, i, RTL_R32 (TxStatus0 + (i * 4)), |
1829 i == (int) (tp->dirty_tx % NUM_TX_DESC) ? |
1824 i == (int) (tp->dirty_tx % NUM_TX_DESC) ? |
1830 " (queue head)" : ""); |
1825 " (queue head)" : ""); |
1831 |
1826 |
1832 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
1833 |
|
1834 /* Stop a shared interrupt from scavenging while we are. */ |
1827 /* Stop a shared interrupt from scavenging while we are. */ |
1835 |
1828 |
1836 if (dev == rtl_ecat_dev.dev) |
1829 spin_lock_irqsave (&tp->lock, flags); |
1837 { |
1830 rtl8139_tx_clear (tp); |
1838 flags = rt_spin_lock_irqsave (&tp->lock); |
1831 spin_unlock_irqrestore (&tp->lock, flags); |
1839 rtl8139_tx_clear (tp); |
|
1840 rt_spin_unlock_irqrestore (&tp->lock,flags); |
|
1841 } |
|
1842 else { |
|
1843 spin_lock_irqsave (&tp->lock, flags); |
|
1844 rtl8139_tx_clear (tp); |
|
1845 spin_unlock_irqrestore (&tp->lock, flags); |
|
1846 } |
|
1847 |
|
1848 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1849 |
1832 |
1850 /* ...and finally, reset everything */ |
1833 /* ...and finally, reset everything */ |
1851 rtl8139_hw_start (dev); |
1834 rtl8139_hw_start (dev); |
1852 |
1835 |
1853 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1836 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1874 if (likely(len < TX_BUF_SIZE)) |
1857 if (likely(len < TX_BUF_SIZE)) |
1875 { |
1858 { |
1876 skb_copy_and_csum_dev(skb, tp->tx_buf[entry]); |
1859 skb_copy_and_csum_dev(skb, tp->tx_buf[entry]); |
1877 |
1860 |
1878 // Socket buffer nicht löschen, wenn vom EtherCAT-device |
1861 // Socket buffer nicht löschen, wenn vom EtherCAT-device |
1879 if (dev != rtl_ecat_dev.dev) dev_kfree_skb(skb); |
1862 if (dev != rtl_ecat_dev.dev) dev_kfree_skb(skb); |
1880 } |
1863 } |
1881 else |
1864 else |
1882 { |
1865 { |
1883 if (dev != rtl_ecat_dev.dev) dev_kfree_skb(skb); |
1866 if (dev != rtl_ecat_dev.dev) dev_kfree_skb(skb); |
1884 tp->stats.tx_dropped++; |
1867 tp->stats.tx_dropped++; |
1885 return 0; |
1868 return 0; |
1886 } |
1869 } |
1887 |
1870 |
|
1871 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1872 |
1888 /* Note: the chip doesn't have auto-pad! */ |
1873 /* Note: the chip doesn't have auto-pad! */ |
1889 if (dev == rtl_ecat_dev.dev) |
1874 spin_lock_irq(&tp->lock); |
1890 { |
|
1891 rt_spin_lock_irq(&tp->lock); |
|
1892 } |
|
1893 else |
|
1894 { |
|
1895 spin_lock_irq(&tp->lock); |
|
1896 } |
|
1897 |
|
1898 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1899 |
1875 |
1900 RTL_W32_F (TxStatus0 + (entry * sizeof (u32)), |
1876 RTL_W32_F (TxStatus0 + (entry * sizeof (u32)), |
1901 tp->tx_flag | max(len, (unsigned int)ETH_ZLEN)); |
1877 tp->tx_flag | max(len, (unsigned int)ETH_ZLEN)); |
1902 |
1878 |
1903 dev->trans_start = jiffies; |
1879 dev->trans_start = jiffies; |
1911 && ((tp->cur_tx - NUM_TX_DESC) == tp->dirty_tx)) |
1887 && ((tp->cur_tx - NUM_TX_DESC) == tp->dirty_tx)) |
1912 { |
1888 { |
1913 netif_stop_queue (dev); |
1889 netif_stop_queue (dev); |
1914 } |
1890 } |
1915 |
1891 |
1916 if (dev == rtl_ecat_dev.dev) |
|
1917 { |
|
1918 rt_spin_unlock_irq(&tp->lock); |
|
1919 } |
|
1920 else |
|
1921 { |
|
1922 spin_unlock_irq(&tp->lock); |
|
1923 } |
|
1924 |
|
1925 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1892 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1893 |
|
1894 spin_unlock_irq(&tp->lock); |
1926 |
1895 |
1927 DPRINTK ("%s: Queued Tx packet size %u to slot %d.\n", |
1896 DPRINTK ("%s: Queued Tx packet size %u to slot %d.\n", |
1928 dev->name, len, entry); |
1897 dev->name, len, entry); |
1929 |
1898 |
1930 return 0; |
1899 return 0; |
1979 tp->stats.tx_carrier_errors++; |
1948 tp->stats.tx_carrier_errors++; |
1980 if (txstatus & TxOutOfWindow) |
1949 if (txstatus & TxOutOfWindow) |
1981 tp->stats.tx_window_errors++; |
1950 tp->stats.tx_window_errors++; |
1982 |
1951 |
1983 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1952 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1984 |
1953 |
1985 if (dev == rtl_ecat_dev.dev) |
1954 if (dev == rtl_ecat_dev.dev) |
1986 { |
1955 { |
1987 rtl_ecat_dev.state = ECAT_DS_ERROR; |
1956 rtl_ecat_dev.state = ECAT_DS_ERROR; |
1988 } |
1957 } |
1989 |
1958 |
1990 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1959 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1991 |
1960 |
1992 } else { |
1961 } else { |
1993 if (txstatus & TxUnderrun) { |
1962 if (txstatus & TxUnderrun) { |
1994 /* Add 64 to the Tx FIFO threshold. */ |
1963 /* Add 64 to the Tx FIFO threshold. */ |
2057 } else { |
2026 } else { |
2058 tp->xstats.rx_lost_in_ring++; |
2027 tp->xstats.rx_lost_in_ring++; |
2059 } |
2028 } |
2060 |
2029 |
2061 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2030 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2062 |
2031 |
2063 if (dev == rtl_ecat_dev.dev) |
2032 if (dev == rtl_ecat_dev.dev) |
2064 { |
2033 { |
2065 rtl_ecat_dev.state = ECAT_DS_ERROR; |
2034 rtl_ecat_dev.state = ECAT_DS_ERROR; |
2066 } |
2035 } |
2067 |
2036 |
2068 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2037 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2069 |
2038 |
2070 #ifndef CONFIG_8139_OLD_RX_RESET |
2039 #ifndef CONFIG_8139_OLD_RX_RESET |
2071 tmp8 = RTL_R8 (ChipCmd); |
2040 tmp8 = RTL_R8 (ChipCmd); |
2072 RTL_W8 (ChipCmd, tmp8 & ~CmdRxEnb); |
2041 RTL_W8 (ChipCmd, tmp8 & ~CmdRxEnb); |
2168 " cur %4.4x.\n", dev->name, rx_status, |
2137 " cur %4.4x.\n", dev->name, rx_status, |
2169 rx_size, cur_rx); |
2138 rx_size, cur_rx); |
2170 |
2139 |
2171 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2140 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2172 |
2141 |
2173 #if RTL8139_DEBUG > 2 |
2142 #if RTL8139_DEBUG > 2 |
2174 if (dev == rtl_ecat_dev.dev) |
2143 if (dev == rtl_ecat_dev.dev) |
2175 { |
2144 { |
2176 int i; |
2145 int i; |
2177 DPRINTK("%s: Frame contents ", dev->name); |
2146 DPRINTK("%s: Frame contents ", dev->name); |
2178 for (i = 0; i < 70; i++) EC_DBG(" %2.2x", rx_ring[ring_offset + i]); |
2147 for (i = 0; i < 70; i++) EC_DBG(" %2.2x", rx_ring[ring_offset + i]); |
2257 dev->last_rx = jiffies; |
2226 dev->last_rx = jiffies; |
2258 tp->stats.rx_bytes += pkt_size; |
2227 tp->stats.rx_bytes += pkt_size; |
2259 tp->stats.rx_packets++; |
2228 tp->stats.rx_packets++; |
2260 } |
2229 } |
2261 } |
2230 } |
2262 |
2231 |
2263 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2232 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2264 |
2233 |
2265 cur_rx = (cur_rx + rx_size + 4 + 3) & ~3; |
2234 cur_rx = (cur_rx + rx_size + 4 + 3) & ~3; |
2266 RTL_W16 (RxBufPtr, cur_rx - 16); |
2235 RTL_W16 (RxBufPtr, cur_rx - 16); |
2267 |
2236 |
2328 EC_DBG (KERN_ERR "%s: PCI Bus error %4.4x.\n", |
2297 EC_DBG (KERN_ERR "%s: PCI Bus error %4.4x.\n", |
2329 dev->name, pci_cmd_status); |
2298 dev->name, pci_cmd_status); |
2330 } |
2299 } |
2331 } |
2300 } |
2332 |
2301 |
2333 |
|
2334 |
|
2335 /* The interrupt handler does all of the Rx thread work and cleans up |
2302 /* The interrupt handler does all of the Rx thread work and cleans up |
2336 after the Tx thread. */ |
2303 after the Tx thread. */ |
2337 static void rtl8139_interrupt (int irq, void *dev_instance, |
2304 static void rtl8139_interrupt (int irq, void *dev_instance, |
2338 struct pt_regs *regs) |
2305 struct pt_regs *regs) |
2339 { |
2306 { |
2342 int boguscnt = max_interrupt_work; |
2309 int boguscnt = max_interrupt_work; |
2343 void *ioaddr = tp->mmio_addr; |
2310 void *ioaddr = tp->mmio_addr; |
2344 int ackstat, status; |
2311 int ackstat, status; |
2345 int link_changed = 0; /* avoid bogus "uninit" warning */ |
2312 int link_changed = 0; /* avoid bogus "uninit" warning */ |
2346 |
2313 |
2347 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2314 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2348 |
2315 |
2349 if (dev == rtl_ecat_dev.dev) |
2316 if (dev == rtl_ecat_dev.dev) |
2350 { |
2317 { |
2351 rt_spin_lock(&tp->lock); |
|
2352 rtl_ecat_dev.intr_cnt++; |
2318 rtl_ecat_dev.intr_cnt++; |
2353 } |
2319 } |
2354 else |
2320 else |
2355 { |
2321 { |
2356 spin_lock (&tp->lock); |
2322 spin_lock(&tp->lock); |
2357 } |
2323 } |
2358 |
2324 |
2359 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2325 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2360 |
2326 |
2361 do { |
2327 do { |
2422 RTL_W16 (IntrStatus, 0xffff); |
2388 RTL_W16 (IntrStatus, 0xffff); |
2423 } |
2389 } |
2424 |
2390 |
2425 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2391 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2426 |
2392 |
2427 if (dev == rtl_ecat_dev.dev) |
2393 if (dev != rtl_ecat_dev.dev) |
2428 { |
2394 { |
2429 rt_spin_unlock(&tp->lock); |
2395 spin_unlock (&tp->lock); |
2430 } |
|
2431 else |
|
2432 { |
|
2433 spin_unlock(&tp->lock); |
|
2434 } |
2396 } |
2435 |
2397 |
2436 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2398 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2437 |
2399 |
2438 DPRINTK ("%s: exiting interrupt, intr_status=%#4.4x.\n", |
2400 DPRINTK ("%s: exiting interrupt, intr_status=%#4.4x.\n", |
2439 dev->name, RTL_R16 (IntrStatus)); |
2401 dev->name, RTL_R16 (IntrStatus)); |
2440 } |
2402 } |
2441 |
|
2442 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
2443 |
|
2444 static void rt_rtl8139_interrupt(void) |
|
2445 { |
|
2446 rtl8139_interrupt(rtl_ecat_dev.dev->irq, rtl_ecat_dev.dev, NULL); |
|
2447 } |
|
2448 |
|
2449 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2450 |
2403 |
2451 static int rtl8139_close (struct net_device *dev) |
2404 static int rtl8139_close (struct net_device *dev) |
2452 { |
2405 { |
2453 struct rtl8139_private *tp = dev->priv; |
2406 struct rtl8139_private *tp = dev->priv; |
2454 void *ioaddr = tp->mmio_addr; |
2407 void *ioaddr = tp->mmio_addr; |
2470 return ret; |
2423 return ret; |
2471 } |
2424 } |
2472 wait_for_completion (&tp->thr_exited); |
2425 wait_for_completion (&tp->thr_exited); |
2473 } |
2426 } |
2474 } |
2427 } |
2475 |
2428 |
2476 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2429 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2477 |
2430 |
2478 DPRINTK ("%s: Shutting down ethercard, status was 0x%4.4x.\n", |
2431 DPRINTK ("%s: Shutting down ethercard, status was 0x%4.4x.\n", |
2479 dev->name, RTL_R16 (IntrStatus)); |
2432 dev->name, RTL_R16 (IntrStatus)); |
2480 |
2433 |
2481 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2434 spin_lock_irqsave(&tp->lock, flags); |
2482 |
|
2483 //mdelay(1); |
|
2484 |
|
2485 if (dev == rtl_ecat_dev.dev) |
|
2486 { |
|
2487 flags = rt_spin_lock_irqsave(&tp->lock); |
|
2488 } |
|
2489 else |
|
2490 { |
|
2491 spin_lock_irqsave(&tp->lock, flags); |
|
2492 } |
|
2493 |
|
2494 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2495 |
2435 |
2496 /* Stop the chip's Tx and Rx DMA processes. */ |
2436 /* Stop the chip's Tx and Rx DMA processes. */ |
2497 RTL_W8 (ChipCmd, 0); |
2437 RTL_W8 (ChipCmd, 0); |
2498 |
2438 |
2499 /* Disable interrupts by clearing the interrupt mask. */ |
2439 /* Disable interrupts by clearing the interrupt mask. */ |
2501 |
2441 |
2502 /* Update the error counts. */ |
2442 /* Update the error counts. */ |
2503 tp->stats.rx_missed_errors += RTL_R32 (RxMissed); |
2443 tp->stats.rx_missed_errors += RTL_R32 (RxMissed); |
2504 RTL_W32 (RxMissed, 0); |
2444 RTL_W32 (RxMissed, 0); |
2505 |
2445 |
|
2446 spin_unlock_irqrestore (&tp->lock, flags); |
|
2447 synchronize_irq (); |
|
2448 |
2506 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2449 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2507 |
|
2508 if (dev == rtl_ecat_dev.dev) |
|
2509 { |
|
2510 rt_spin_unlock_irqrestore (&tp->lock, flags); |
|
2511 synchronize_irq (); |
|
2512 } |
|
2513 else |
|
2514 { |
|
2515 spin_unlock_irqrestore (&tp->lock, flags); |
|
2516 synchronize_irq (); |
|
2517 } |
|
2518 |
|
2519 EC_DBG ("rtl8139: freeing irq"); |
|
2520 |
|
2521 //mdelay(1); |
|
2522 |
2450 |
2523 if (dev != rtl_ecat_dev.dev) |
2451 if (dev != rtl_ecat_dev.dev) |
2524 { |
2452 { |
2525 free_irq (dev->irq, dev); |
2453 free_irq(dev->irq, dev); |
2526 } |
2454 } |
2527 else |
|
2528 { |
|
2529 rt_disable_irq(dev->irq); |
|
2530 rt_free_global_irq (dev->irq); |
|
2531 rt_enable_irq(dev->irq); |
|
2532 } |
|
2533 |
2455 |
2534 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2456 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2535 |
2457 |
2536 rtl8139_tx_clear (tp); |
2458 rtl8139_tx_clear (tp); |
2537 |
2459 |
2866 |
2788 |
2867 EC_DBG("%s: rtl8139 GETSTATS called...",dev->name); |
2789 EC_DBG("%s: rtl8139 GETSTATS called...",dev->name); |
2868 |
2790 |
2869 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2791 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2870 |
2792 |
2871 if (dev == rtl_ecat_dev.dev) |
2793 if (dev == rtl_ecat_dev.dev || netif_running(dev)) |
2872 { |
2794 { |
2873 flags = rt_spin_lock_irqsave (&tp->lock); |
2795 spin_lock_irqsave (&tp->lock, flags); |
2874 tp->stats.rx_missed_errors += RTL_R32 (RxMissed); |
2796 tp->stats.rx_missed_errors += RTL_R32 (RxMissed); |
2875 RTL_W32 (RxMissed, 0); |
2797 RTL_W32 (RxMissed, 0); |
2876 rt_spin_unlock_irqrestore (&tp->lock, flags); |
2798 spin_unlock_irqrestore (&tp->lock, flags); |
2877 } |
|
2878 else |
|
2879 { |
|
2880 if (netif_running(dev)) |
|
2881 { |
|
2882 spin_lock_irqsave (&tp->lock, flags); |
|
2883 tp->stats.rx_missed_errors += RTL_R32 (RxMissed); |
|
2884 RTL_W32 (RxMissed, 0); |
|
2885 spin_unlock_irqrestore (&tp->lock, flags); |
|
2886 } |
|
2887 } |
2799 } |
2888 |
2800 |
2889 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2801 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2890 |
2802 |
2891 return &tp->stats; |
2803 return &tp->stats; |
2945 static void rtl8139_set_rx_mode (struct net_device *dev) |
2857 static void rtl8139_set_rx_mode (struct net_device *dev) |
2946 { |
2858 { |
2947 unsigned long flags; |
2859 unsigned long flags; |
2948 struct rtl8139_private *tp = dev->priv; |
2860 struct rtl8139_private *tp = dev->priv; |
2949 |
2861 |
2950 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2862 spin_lock_irqsave (&tp->lock, flags); |
2951 |
2863 __set_rx_mode(dev); |
2952 if (dev == rtl_ecat_dev.dev) |
2864 spin_unlock_irqrestore (&tp->lock, flags); |
2953 { |
|
2954 flags = rt_spin_lock_irqsave (&tp->lock); |
|
2955 __set_rx_mode(dev); |
|
2956 rt_spin_unlock_irqrestore (&tp->lock, flags); |
|
2957 } |
|
2958 else |
|
2959 { |
|
2960 spin_lock_irqsave (&tp->lock, flags); |
|
2961 __set_rx_mode(dev); |
|
2962 spin_unlock_irqrestore (&tp->lock, flags); |
|
2963 } |
|
2964 |
|
2965 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2966 } |
2865 } |
2967 |
2866 |
2968 #ifdef CONFIG_PM |
2867 #ifdef CONFIG_PM |
2969 |
2868 |
2970 static int rtl8139_suspend (struct pci_dev *pdev, u32 state) |
2869 static int rtl8139_suspend (struct pci_dev *pdev, u32 state) |