636 struct mii_if_info mii; |
635 struct mii_if_info mii; |
637 unsigned int regs_len; |
636 unsigned int regs_len; |
638 unsigned long fifo_copy_timeout; |
637 unsigned long fifo_copy_timeout; |
639 }; |
638 }; |
640 |
639 |
641 MODULE_AUTHOR ("Jeff Garzik <jgarzik@pobox.com>"); |
640 MODULE_AUTHOR ("Wilhelm Hagemeister <hm@igh-essen.com>, Florian Pose <fp@igh-essen.com>"); |
642 MODULE_DESCRIPTION ("RealTek RTL-8139 Fast Ethernet driver"); |
641 MODULE_DESCRIPTION ("RealTek RTL-8139 Fast Ethernet driver with EtherCAT functionality"); |
643 MODULE_LICENSE("GPL"); |
642 MODULE_LICENSE("GPL"); |
644 MODULE_VERSION(DRV_VERSION); |
643 MODULE_VERSION(DRV_VERSION); |
645 |
644 |
646 module_param(multicast_filter_limit, int, 0); |
645 module_param(multicast_filter_limit, int, 0); |
647 module_param_array(media, int, NULL, 0); |
646 module_param_array(media, int, NULL, 0); |
1010 |
1009 |
1011 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1010 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1012 |
1011 |
1013 if (board_idx == ec_device_index) |
1012 if (board_idx == ec_device_index) |
1014 { |
1013 { |
1015 printk("EtherCAT registering board %d.\n", board_idx); |
1014 printk("EtherCAT registering board %d.\n", board_idx); |
1016 |
1015 |
1017 if (EtherCAT_device_assign(&rtl_ecat_dev, dev) < 0) |
1016 if (EtherCAT_device_assign(&rtl_ecat_dev, dev) < 0) |
1018 goto err_out; |
1017 goto err_out; |
1019 |
1018 |
1020 strcpy(dev->name,"ECAT"); //device name überschreiben |
1019 strcpy(dev->name,"ECAT"); //device name überschreiben |
1021 } |
1020 } |
1022 |
1021 |
1023 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1022 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1024 |
1023 |
1025 ioaddr = tp->mmio_addr; |
1024 ioaddr = tp->mmio_addr; |
1063 tp->msg_enable = |
1062 tp->msg_enable = |
1064 (debug < 0 ? RTL8139_DEF_MSG_ENABLE : ((1 << debug) - 1)); |
1063 (debug < 0 ? RTL8139_DEF_MSG_ENABLE : ((1 << debug) - 1)); |
1065 spin_lock_init (&tp->lock); |
1064 spin_lock_init (&tp->lock); |
1066 spin_lock_init (&tp->rx_lock); |
1065 spin_lock_init (&tp->rx_lock); |
1067 |
1066 |
1068 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
1069 |
|
1070 if (board_idx == ec_device_index) |
|
1071 { |
|
1072 rtl_ecat_dev.lock = &tp->lock; |
|
1073 } |
|
1074 |
|
1075 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1076 |
|
1077 init_waitqueue_head (&tp->thr_wait); |
1067 init_waitqueue_head (&tp->thr_wait); |
1078 init_completion (&tp->thr_exited); |
1068 init_completion (&tp->thr_exited); |
1079 tp->mii.dev = dev; |
1069 tp->mii.dev = dev; |
1080 tp->mii.mdio_read = mdio_read; |
1070 tp->mii.mdio_read = mdio_read; |
1081 tp->mii.mdio_write = mdio_write; |
1071 tp->mii.mdio_write = mdio_write; |
1087 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1077 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1088 |
1078 |
1089 /* EtherCAT-Karten nicht beim Stack anmelden. */ |
1079 /* EtherCAT-Karten nicht beim Stack anmelden. */ |
1090 if (dev != rtl_ecat_dev.dev) |
1080 if (dev != rtl_ecat_dev.dev) |
1091 { |
1081 { |
1092 DPRINTK("About to register device named %s (%p)...\n", dev->name, dev); |
1082 DPRINTK("About to register device named %s (%p)...\n", dev->name, dev); |
1093 i = register_netdev (dev); |
1083 i = register_netdev (dev); |
1094 if (i) goto err_out; |
1084 if (i) goto err_out; |
1095 } |
1085 } |
1096 |
1086 |
1097 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1087 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1098 |
1088 |
1099 pci_set_drvdata (pdev, dev); |
1089 pci_set_drvdata (pdev, dev); |
1398 printk(KERN_DEBUG "%s: open\n", dev->name); |
1388 printk(KERN_DEBUG "%s: open\n", dev->name); |
1399 #endif |
1389 #endif |
1400 |
1390 |
1401 if (dev != rtl_ecat_dev.dev) |
1391 if (dev != rtl_ecat_dev.dev) |
1402 { |
1392 { |
1403 retval = request_irq(dev->irq, rtl8139_interrupt, SA_SHIRQ, dev->name, dev); |
1393 retval = request_irq(dev->irq, rtl8139_interrupt, SA_SHIRQ, dev->name, dev); |
1404 if (retval) |
1394 if (retval) |
1405 return retval; |
1395 return retval; |
1406 } |
1396 } |
1407 |
1397 |
1408 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1398 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1409 |
1399 |
1410 tp->tx_bufs = pci_alloc_consistent(tp->pci_dev, TX_BUF_TOT_LEN, |
1400 tp->tx_bufs = pci_alloc_consistent(tp->pci_dev, TX_BUF_TOT_LEN, |
1411 &tp->tx_bufs_dma); |
1401 &tp->tx_bufs_dma); |
1412 tp->rx_ring = pci_alloc_consistent(tp->pci_dev, RX_BUF_TOT_LEN, |
1402 tp->rx_ring = pci_alloc_consistent(tp->pci_dev, RX_BUF_TOT_LEN, |
1413 &tp->rx_ring_dma); |
1403 &tp->rx_ring_dma); |
1414 if (tp->tx_bufs == NULL || tp->rx_ring == NULL) |
1404 if (tp->tx_bufs == NULL || tp->rx_ring == NULL) |
1415 { |
1405 { |
1416 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1406 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1417 |
1407 |
1418 if (dev != rtl_ecat_dev.dev) |
1408 if (dev != rtl_ecat_dev.dev) |
1419 { |
1409 { |
1420 free_irq(dev->irq, dev); |
1410 free_irq(dev->irq, dev); |
1421 } |
1411 } |
1422 |
1412 |
1423 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1413 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1424 |
1414 |
1425 if (tp->tx_bufs) |
1415 if (tp->tx_bufs) |
1426 pci_free_consistent(tp->pci_dev, TX_BUF_TOT_LEN, |
1416 pci_free_consistent(tp->pci_dev, TX_BUF_TOT_LEN, |
1427 tp->tx_bufs, tp->tx_bufs_dma); |
1417 tp->tx_bufs, tp->tx_bufs_dma); |
1428 if (tp->rx_ring) |
1418 if (tp->rx_ring) |
1429 pci_free_consistent(tp->pci_dev, RX_BUF_TOT_LEN, |
1419 pci_free_consistent(tp->pci_dev, RX_BUF_TOT_LEN, |
1430 tp->rx_ring, tp->rx_ring_dma); |
1420 tp->rx_ring, tp->rx_ring_dma); |
1431 |
1421 |
1432 return -ENOMEM; |
1422 return -ENOMEM; |
1433 |
|
1434 } |
1423 } |
1435 |
1424 |
1436 tp->mii.full_duplex = tp->mii.force_media; |
1425 tp->mii.full_duplex = tp->mii.force_media; |
1437 tp->tx_flag = (TX_FIFO_THRESH << 11) & 0x003f0000; |
1426 tp->tx_flag = (TX_FIFO_THRESH << 11) & 0x003f0000; |
1438 |
1427 |
1441 |
1430 |
1442 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1431 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1443 |
1432 |
1444 if (dev != rtl_ecat_dev.dev) |
1433 if (dev != rtl_ecat_dev.dev) |
1445 { |
1434 { |
1446 netif_start_queue (dev); |
1435 netif_start_queue (dev); |
|
1436 |
|
1437 if (netif_msg_ifup(tp)) |
|
1438 { |
|
1439 printk(KERN_DEBUG "%s: rtl8139_open() ioaddr %#lx IRQ %d" |
|
1440 " GP Pins %2.2x %s-duplex.\n", |
|
1441 dev->name, pci_resource_start (tp->pci_dev, 1), |
|
1442 dev->irq, RTL_R8 (MediaStatus), |
|
1443 tp->mii.full_duplex ? "full" : "half"); |
|
1444 } |
|
1445 |
|
1446 rtl8139_start_thread(dev); |
1447 } |
1447 } |
1448 |
|
1449 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1450 |
|
1451 //FIXME muß das hier raus ?? |
|
1452 if (netif_msg_ifup(tp)) |
|
1453 printk(KERN_DEBUG "%s: rtl8139_open() ioaddr %#lx IRQ %d" |
|
1454 " GP Pins %2.2x %s-duplex.\n", |
|
1455 dev->name, pci_resource_start (tp->pci_dev, 1), |
|
1456 dev->irq, RTL_R8 (MediaStatus), |
|
1457 tp->mii.full_duplex ? "full" : "half"); |
|
1458 |
|
1459 |
|
1460 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
1461 |
|
1462 if (dev != rtl_ecat_dev.dev) |
|
1463 { |
|
1464 rtl8139_start_thread(dev); |
|
1465 } |
|
1466 |
1448 |
1467 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1449 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1468 |
1450 |
1469 return 0; |
1451 return 0; |
1470 } |
1452 } |
1807 |
1789 |
1808 printk(KERN_DEBUG "%s: tx_timeout\n", dev->name); |
1790 printk(KERN_DEBUG "%s: tx_timeout\n", dev->name); |
1809 |
1791 |
1810 if (dev == rtl_ecat_dev.dev) |
1792 if (dev == rtl_ecat_dev.dev) |
1811 { |
1793 { |
1812 if (rtl_ecat_dev.state != ECAT_DS_SENT) |
1794 if (rtl_ecat_dev.state != ECAT_DS_SENT) |
1813 { |
1795 { |
1814 printk(KERN_WARNING "EtherCAT: Wrong status at timeout: %i\n", |
1796 printk(KERN_WARNING "EtherCAT: Wrong status at timeout: %i\n", |
1815 rtl_ecat_dev.state); |
1797 rtl_ecat_dev.state); |
1816 } |
1798 } |
1817 |
1799 |
1818 rtl_ecat_dev.state = ECAT_DS_TIMEOUT; |
1800 rtl_ecat_dev.state = ECAT_DS_TIMEOUT; |
1819 } |
1801 } |
1820 |
|
1821 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1822 |
1802 |
1823 /* disable Tx ASAP, if not already */ |
1803 /* disable Tx ASAP, if not already */ |
1824 tmp8 = RTL_R8 (ChipCmd); |
1804 tmp8 = RTL_R8 (ChipCmd); |
1825 if (tmp8 & CmdTxEnb) |
1805 if (tmp8 & CmdTxEnb) |
1826 RTL_W8 (ChipCmd, CmdRxEnb); |
1806 RTL_W8 (ChipCmd, CmdRxEnb); |
1827 |
1807 |
1828 spin_lock(&tp->rx_lock); |
1808 if (dev != rtl_ecat_dev.dev) |
1829 /* Disable interrupts by clearing the interrupt mask. */ |
|
1830 RTL_W16 (IntrMask, 0x0000); |
|
1831 |
|
1832 /* Stop a shared interrupt from scavenging while we are. */ |
|
1833 spin_lock_irqsave (&tp->lock, flags); |
|
1834 rtl8139_tx_clear (tp); |
|
1835 spin_unlock_irqrestore (&tp->lock, flags); |
|
1836 |
|
1837 /* ...and finally, reset everything */ |
|
1838 |
|
1839 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
1840 |
|
1841 if (dev != rtl_ecat_dev.dev) |
|
1842 { |
1809 { |
1843 if (netif_running(dev)) |
1810 spin_lock(&tp->rx_lock); |
1844 { |
1811 |
1845 rtl8139_hw_start (dev); |
1812 /* Disable interrupts by clearing the interrupt mask. */ |
1846 netif_wake_queue (dev); |
1813 RTL_W16 (IntrMask, 0x0000); |
1847 } |
1814 |
|
1815 /* Stop a shared interrupt from scavenging while we are. */ |
|
1816 spin_lock_irqsave (&tp->lock, flags); |
|
1817 rtl8139_tx_clear (tp); |
|
1818 spin_unlock_irqrestore (&tp->lock, flags); |
|
1819 |
|
1820 /* ...and finally, reset everything */ |
|
1821 |
|
1822 if (netif_running(dev)) |
|
1823 { |
|
1824 rtl8139_hw_start (dev); |
|
1825 netif_wake_queue (dev); |
|
1826 } |
|
1827 |
|
1828 spin_unlock(&tp->rx_lock); |
1848 } |
1829 } |
1849 else |
1830 else |
1850 { |
1831 { |
1851 rtl8139_hw_start (dev); |
1832 rtl8139_tx_clear (tp); |
|
1833 rtl8139_hw_start(dev); |
1852 } |
1834 } |
1853 |
|
1854 spin_unlock(&tp->rx_lock); |
|
1855 |
1835 |
1856 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1836 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1857 } |
1837 } |
1858 |
1838 |
1859 static int rtl8139_start_xmit (struct sk_buff *skb, struct net_device *dev) |
1839 static int rtl8139_start_xmit (struct sk_buff *skb, struct net_device *dev) |
1869 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1849 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1870 |
1850 |
1871 /* Note: the chip doesn't have auto-pad! */ |
1851 /* Note: the chip doesn't have auto-pad! */ |
1872 if (likely(len < TX_BUF_SIZE)) |
1852 if (likely(len < TX_BUF_SIZE)) |
1873 { |
1853 { |
1874 if (len < ETH_ZLEN) |
1854 if (len < ETH_ZLEN) |
1875 memset(tp->tx_buf[entry], 0, ETH_ZLEN); |
1855 memset(tp->tx_buf[entry], 0, ETH_ZLEN); |
1876 |
1856 |
1877 skb_copy_and_csum_dev(skb, tp->tx_buf[entry]); |
1857 skb_copy_and_csum_dev(skb, tp->tx_buf[entry]); |
1878 if (dev != rtl_ecat_dev.dev) dev_kfree_skb(skb); |
1858 if (dev != rtl_ecat_dev.dev) dev_kfree_skb(skb); |
1879 } |
1859 } |
1880 else |
1860 else |
1881 { |
1861 { |
1882 if (dev != rtl_ecat_dev.dev) dev_kfree_skb(skb); |
1862 if (dev != rtl_ecat_dev.dev) dev_kfree_skb(skb); |
1883 tp->stats.tx_dropped++; |
1863 tp->stats.tx_dropped++; |
1884 return 0; |
1864 return 0; |
1885 } |
1865 } |
1886 |
1866 |
1887 if (dev != rtl_ecat_dev.dev) //CHANGED HM spinlock falsch |
1867 if (dev != rtl_ecat_dev.dev) |
1888 spin_lock_irq(&tp->lock); |
1868 { |
|
1869 spin_lock_irq(&tp->lock); |
|
1870 } |
1889 |
1871 |
1890 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1872 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1873 |
1891 RTL_W32_F (TxStatus0 + (entry * sizeof (u32)), |
1874 RTL_W32_F (TxStatus0 + (entry * sizeof (u32)), |
1892 tp->tx_flag | max(len, (unsigned int)ETH_ZLEN)); |
1875 tp->tx_flag | max(len, (unsigned int)ETH_ZLEN)); |
1893 |
1876 |
1894 dev->trans_start = jiffies; |
1877 dev->trans_start = jiffies; |
1895 |
1878 |
1898 |
1881 |
1899 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1882 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1900 |
1883 |
1901 if (dev != rtl_ecat_dev.dev) |
1884 if (dev != rtl_ecat_dev.dev) |
1902 { |
1885 { |
1903 if ((tp->cur_tx - NUM_TX_DESC) == tp->dirty_tx) |
1886 if ((tp->cur_tx - NUM_TX_DESC) == tp->dirty_tx) |
1904 netif_stop_queue (dev); |
1887 netif_stop_queue (dev); |
1905 spin_unlock_irq(&tp->lock); |
1888 |
1906 |
1889 spin_unlock_irq(&tp->lock); |
1907 if (netif_msg_tx_queued(tp)) |
1890 |
1908 printk (KERN_DEBUG "%s: Queued Tx packet size %u to slot %d.\n", |
1891 if (netif_msg_tx_queued(tp)) |
1909 dev->name, len, entry); |
1892 printk (KERN_DEBUG "%s: Queued Tx packet size %u to slot %d.\n", |
|
1893 dev->name, len, entry); |
1910 } |
1894 } |
1911 |
1895 |
1912 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1896 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1913 |
1897 |
1914 return 0; |
1898 return 0; |
2151 DPRINTK ("%s: In rtl8139_rx(), current %4.4x BufAddr %4.4x," |
2134 DPRINTK ("%s: In rtl8139_rx(), current %4.4x BufAddr %4.4x," |
2152 " free to %4.4x, Cmd %2.2x.\n", dev->name, (u16)cur_rx, |
2135 " free to %4.4x, Cmd %2.2x.\n", dev->name, (u16)cur_rx, |
2153 RTL_R16 (RxBufAddr), |
2136 RTL_R16 (RxBufAddr), |
2154 RTL_R16 (RxBufPtr), RTL_R8 (ChipCmd)); |
2137 RTL_R16 (RxBufPtr), RTL_R8 (ChipCmd)); |
2155 |
2138 |
2156 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2139 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2157 |
2140 |
2158 if (dev == rtl_ecat_dev.dev) |
2141 if (dev == rtl_ecat_dev.dev) |
2159 { |
2142 { |
2160 rtl_ecat_dev.rx_intr_cnt++; |
2143 rtl_ecat_dev.rx_intr_cnt++; |
2161 rdtscl(rtl_ecat_dev.rx_time); // Get CPU cycles |
2144 rdtscl(rtl_ecat_dev.rx_time); // Get CPU cycles |
2162 } |
2145 } |
2163 |
2146 |
2164 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2147 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2165 |
2148 |
2166 while ((dev == rtl_ecat_dev.dev || netif_running(dev)) //HM |
2149 while ((dev == rtl_ecat_dev.dev || netif_running(dev)) |
2167 && received < budget |
2150 && received < budget |
2168 && (RTL_R8 (ChipCmd) & RxBufEmpty) == 0) { |
2151 && (RTL_R8 (ChipCmd) & RxBufEmpty) == 0) { |
2169 u32 ring_offset = cur_rx % RX_BUF_LEN; |
2152 u32 ring_offset = cur_rx % RX_BUF_LEN; |
2170 u32 rx_status; |
2153 u32 rx_status; |
2171 unsigned int pkt_size; |
2154 unsigned int pkt_size; |
2172 struct sk_buff *skb; |
2155 struct sk_buff *skb; |
2176 /* read size+status of next frame from DMA ring buffer */ |
2159 /* read size+status of next frame from DMA ring buffer */ |
2177 rx_status = le32_to_cpu (*(u32 *) (rx_ring + ring_offset)); |
2160 rx_status = le32_to_cpu (*(u32 *) (rx_ring + ring_offset)); |
2178 rx_size = rx_status >> 16; |
2161 rx_size = rx_status >> 16; |
2179 pkt_size = rx_size - 4; |
2162 pkt_size = rx_size - 4; |
2180 |
2163 |
2181 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2164 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2182 |
2165 |
2183 if (dev != rtl_ecat_dev.dev && netif_msg_rx_status(tp)) |
2166 if (dev != rtl_ecat_dev.dev && netif_msg_rx_status(tp)) |
2184 printk(KERN_DEBUG "%s: rtl8139_rx() status %4.4x, size %4.4x," |
2167 printk(KERN_DEBUG "%s: rtl8139_rx() status %4.4x, size %4.4x," |
2185 " cur %4.4x.\n", dev->name, rx_status, |
2168 " cur %4.4x.\n", dev->name, rx_status, |
2186 rx_size, cur_rx); |
2169 rx_size, cur_rx); |
2187 |
2170 |
2188 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2171 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2189 |
2172 |
2190 #if RTL8139_DEBUG > 2 |
2173 #if RTL8139_DEBUG > 2 |
2191 { |
2174 { |
2192 int i; |
2175 int i; |
2193 DPRINTK ("%s: Frame contents ", dev->name); |
2176 DPRINTK ("%s: Frame contents ", dev->name); |
2232 rtl8139_rx_err (rx_status, dev, tp, ioaddr); |
2215 rtl8139_rx_err (rx_status, dev, tp, ioaddr); |
2233 received = -1; |
2216 received = -1; |
2234 goto out; |
2217 goto out; |
2235 } |
2218 } |
2236 |
2219 |
2237 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2220 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2238 |
2221 |
2239 if (dev != rtl_ecat_dev.dev) |
2222 if (dev != rtl_ecat_dev.dev) |
2240 { |
2223 { |
2241 /* Malloc up new buffer, compatible with net-2e. */ |
2224 /* Malloc up new buffer, compatible with net-2e. */ |
2242 /* Omit the four octet CRC from the length. */ |
2225 /* Omit the four octet CRC from the length. */ |
2243 skb = dev_alloc_skb(pkt_size + 2); |
2226 skb = dev_alloc_skb(pkt_size + 2); |
2244 } |
2227 |
2245 |
2228 if (likely(skb)) { |
2246 if (dev != rtl_ecat_dev.dev) |
2229 skb->dev = dev; |
2247 { |
2230 skb_reserve (skb, 2); /* 16 byte align the IP fields. */ |
2248 if (likely(skb)) { |
|
2249 skb->dev = dev; |
|
2250 skb_reserve (skb, 2); /* 16 byte align the IP fields. */ |
|
2251 #if RX_BUF_IDX == 3 |
2231 #if RX_BUF_IDX == 3 |
2252 wrap_copy(skb, rx_ring, ring_offset+4, pkt_size); |
2232 wrap_copy(skb, rx_ring, ring_offset+4, pkt_size); |
2253 #else |
2233 #else |
2254 eth_copy_and_sum (skb, &rx_ring[ring_offset + 4], pkt_size, 0); |
2234 eth_copy_and_sum (skb, &rx_ring[ring_offset + 4], pkt_size, 0); |
2255 #endif |
2235 #endif |
2256 skb_put (skb, pkt_size); |
2236 skb_put (skb, pkt_size); |
2257 |
2237 |
2258 skb->protocol = eth_type_trans (skb, dev); |
2238 skb->protocol = eth_type_trans (skb, dev); |
2259 |
2239 |
2260 dev->last_rx = jiffies; |
2240 dev->last_rx = jiffies; |
2261 tp->stats.rx_bytes += pkt_size; |
2241 tp->stats.rx_bytes += pkt_size; |
2262 tp->stats.rx_packets++; |
2242 tp->stats.rx_packets++; |
2263 |
2243 |
2264 netif_receive_skb (skb); |
2244 netif_receive_skb (skb); |
2265 |
2245 } else { |
2266 } else { |
2246 if (net_ratelimit()) |
2267 if (net_ratelimit()) |
2247 printk (KERN_WARNING |
2268 printk (KERN_WARNING |
2248 "%s: Memory squeeze, dropping packet.\n", |
2269 "%s: Memory squeeze, dropping packet.\n", |
2249 dev->name); |
2270 dev->name); |
2250 tp->stats.rx_dropped++; |
2271 tp->stats.rx_dropped++; |
2251 } |
2272 } |
2252 } |
2273 } |
2253 else |
2274 else |
2254 { |
2275 { |
2255 if (rtl_ecat_dev.state != ECAT_DS_SENT) |
2276 if (rtl_ecat_dev.state != ECAT_DS_SENT) |
2256 { |
2277 { |
2257 printk(KERN_WARNING "EtherCAT: Received frame while not in SENT state!\n"); |
2278 printk(KERN_WARNING "EtherCAT: Received frame while not in SENT state!\n"); |
2258 } |
2279 } |
2259 else |
2280 else |
2260 { |
2281 { |
2261 // Copy received data to ethercat-device buffer, skip Ethernet-II header |
2282 // Copy received data to ethercat-device buffer, skip Ethernet-II header |
2262 memcpy(rtl_ecat_dev.rx_data, &rx_ring[ring_offset + 4] + ETH_HLEN, |
2283 memcpy(rtl_ecat_dev.rx_data, &rx_ring[ring_offset + 4] + ETH_HLEN, |
2263 pkt_size - ETH_HLEN); |
2284 pkt_size - ETH_HLEN); |
2264 rtl_ecat_dev.rx_data_length = pkt_size - ETH_HLEN; |
2285 rtl_ecat_dev.rx_data_length = pkt_size - ETH_HLEN; |
2265 |
2286 |
2266 rtl_ecat_dev.state = ECAT_DS_RECEIVED; |
2287 rtl_ecat_dev.state = ECAT_DS_RECEIVED; |
2267 |
2288 |
2268 dev->last_rx = jiffies; |
2289 dev->last_rx = jiffies; |
2269 tp->stats.rx_bytes += pkt_size; |
2290 tp->stats.rx_bytes += pkt_size; |
2270 tp->stats.rx_packets++; |
2291 tp->stats.rx_packets++; |
2271 } |
2292 } |
2272 } |
2293 } |
2273 |
2294 |
2274 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2295 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2296 |
2275 |
2297 received++; |
2276 received++; |
2298 |
2277 |
2299 cur_rx = (cur_rx + rx_size + 4 + 3) & ~3; |
2278 cur_rx = (cur_rx + rx_size + 4 + 3) & ~3; |
2300 RTL_W16 (RxBufPtr, (u16) (cur_rx - 16)); |
2279 RTL_W16 (RxBufPtr, (u16) (cur_rx - 16)); |
2419 |
2393 |
2420 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2394 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2421 |
2395 |
2422 if (dev == rtl_ecat_dev.dev) |
2396 if (dev == rtl_ecat_dev.dev) |
2423 { |
2397 { |
2424 rtl_ecat_dev.intr_cnt++; |
2398 rtl_ecat_dev.intr_cnt++; |
2425 |
2399 status = RTL_R16 (IntrStatus); |
2426 } |
2400 } |
2427 else |
2401 else |
2428 { |
2402 { |
2429 spin_lock(&tp->lock); |
2403 spin_lock(&tp->lock); |
|
2404 |
|
2405 status = RTL_R16 (IntrStatus); |
|
2406 |
|
2407 if (unlikely((status & rtl8139_intr_mask) == 0)) |
|
2408 goto out; |
2430 } |
2409 } |
2431 |
2410 |
2432 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2433 |
|
2434 status = RTL_R16 (IntrStatus); |
|
2435 |
|
2436 /* shared irq? */ |
|
2437 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2438 if (dev != rtl_ecat_dev.dev) |
|
2439 if (unlikely((status & rtl8139_intr_mask) == 0)) |
|
2440 goto out; |
|
2441 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2411 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2442 |
2412 |
2443 handled = 1; |
2413 handled = 1; |
2444 |
2414 |
2445 /* h/w no longer present (hotplug?) or major error, bail */ |
2415 /* h/w no longer present (hotplug?) or major error, bail */ |
2446 if (unlikely(status == 0xFFFF)) |
2416 if (unlikely(status == 0xFFFF)) |
2447 goto out; |
2417 goto out; |
2448 |
2418 |
2449 /* close possible race's with dev_close */ |
2419 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
2420 |
|
2421 if (dev != rtl_ecat_dev.dev) |
|
2422 { |
|
2423 /* close possible race's with dev_close */ |
|
2424 if (unlikely(!netif_running(dev))) { |
|
2425 RTL_W16 (IntrMask, 0); |
|
2426 goto out; |
|
2427 } |
|
2428 } |
|
2429 |
2450 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2430 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2451 if (dev != rtl_ecat_dev.dev) { |
2431 |
2452 if (unlikely(!netif_running(dev))) { |
|
2453 RTL_W16 (IntrMask, 0); |
|
2454 goto out; |
|
2455 } |
|
2456 } |
|
2457 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2458 /* Acknowledge all of the current interrupt sources ASAP, but |
2432 /* Acknowledge all of the current interrupt sources ASAP, but |
2459 an first get an additional status bit from CSCR. */ |
2433 an first get an additional status bit from CSCR. */ |
2460 if (unlikely(status & RxUnderrun)) |
2434 if (unlikely(status & RxUnderrun)) |
2461 link_changed = RTL_R16 (CSCR) & CSCR_LinkChangeBit; |
2435 link_changed = RTL_R16 (CSCR) & CSCR_LinkChangeBit; |
2462 |
2436 |
2468 |
2442 |
2469 /* Receive packets are processed by poll routine. |
2443 /* Receive packets are processed by poll routine. |
2470 If not running start it now. */ |
2444 If not running start it now. */ |
2471 |
2445 |
2472 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2446 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2473 if (status & RxAckBits){ |
2447 |
2474 // printk("ECAT-NIC RX-Intr Flag\n"); // HM |
2448 if (status & RxAckBits) |
2475 if (dev != rtl_ecat_dev.dev) { |
2449 { |
2476 if (netif_rx_schedule_prep(dev)) { |
2450 if (dev != rtl_ecat_dev.dev) |
2477 RTL_W16_F (IntrMask, rtl8139_norx_intr_mask); |
2451 { |
2478 __netif_rx_schedule (dev); |
2452 /* Polling vormerken */ |
2479 } |
2453 if (netif_rx_schedule_prep(dev)) { |
2480 } |
2454 RTL_W16_F (IntrMask, rtl8139_norx_intr_mask); |
2481 // else |
2455 __netif_rx_schedule (dev); |
2482 |
2456 } |
2483 } |
2457 } |
|
2458 else |
|
2459 { |
|
2460 /* Beim EtherCAT-Device einfach einen Frame empfangen */ |
|
2461 rtl8139_rx(dev, tp, 1); |
|
2462 } |
|
2463 } |
|
2464 |
|
2465 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2484 |
2466 |
2485 /* Check uncommon events with one test. */ |
2467 /* Check uncommon events with one test. */ |
2486 if (unlikely(status & (PCIErr | PCSTimeout | RxUnderrun | RxErr))) |
2468 if (unlikely(status & (PCIErr | PCSTimeout | RxUnderrun | RxErr))) |
2487 rtl8139_weird_interrupt (dev, tp, ioaddr, |
2469 rtl8139_weird_interrupt (dev, tp, ioaddr, |
2488 status, link_changed); |
2470 status, link_changed); |
2529 |
2511 |
2530 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2512 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2531 |
2513 |
2532 if (dev != rtl_ecat_dev.dev) |
2514 if (dev != rtl_ecat_dev.dev) |
2533 { |
2515 { |
2534 netif_stop_queue(dev); |
2516 netif_stop_queue(dev); |
2535 if (tp->thr_pid >= 0) { |
2517 if (tp->thr_pid >= 0) { |
2536 tp->time_to_die = 1; |
2518 tp->time_to_die = 1; |
2537 wmb(); |
2519 wmb(); |
2538 ret = kill_proc (tp->thr_pid, SIGTERM, 1); |
2520 ret = kill_proc (tp->thr_pid, SIGTERM, 1); |
2539 if (ret) { |
2521 if (ret) { |
2540 printk (KERN_ERR "%s: unable to signal thread\n", dev->name); |
2522 printk (KERN_ERR "%s: unable to signal thread\n", dev->name); |
2541 return ret; |
2523 return ret; |
2542 } |
2524 } |
2543 wait_for_completion (&tp->thr_exited); |
2525 wait_for_completion (&tp->thr_exited); |
2544 } |
2526 } |
2545 } |
2527 |
2546 |
2528 if (netif_msg_ifdown(tp)) |
2547 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2529 printk(KERN_DEBUG "%s: Shutting down ethercard, status was 0x%4.4x.\n", |
2548 |
2530 dev->name, RTL_R16 (IntrStatus)); |
2549 if (dev != rtl_ecat_dev.dev) |
2531 |
|
2532 spin_lock_irqsave (&tp->lock, flags); |
|
2533 |
|
2534 /* Stop the chip's Tx and Rx DMA processes. */ |
|
2535 RTL_W8 (ChipCmd, 0); |
|
2536 |
|
2537 /* Disable interrupts by clearing the interrupt mask. */ |
|
2538 RTL_W16 (IntrMask, 0); |
|
2539 |
|
2540 /* Update the error counts. */ |
|
2541 tp->stats.rx_missed_errors += RTL_R32 (RxMissed); |
|
2542 RTL_W32 (RxMissed, 0); |
|
2543 |
|
2544 spin_unlock_irqrestore (&tp->lock, flags); |
|
2545 |
|
2546 synchronize_irq (dev->irq); /* racy, but that's ok here */ |
|
2547 free_irq (dev->irq, dev); |
|
2548 } |
|
2549 else |
2550 { |
2550 { |
2551 if (netif_msg_ifdown(tp)) |
2551 /* Stop the chip's Tx and Rx DMA processes. */ |
2552 printk(KERN_DEBUG "%s: Shutting down ethercard, status was 0x%4.4x.\n", |
2552 RTL_W8 (ChipCmd, 0); |
2553 dev->name, RTL_R16 (IntrStatus)); |
2553 |
2554 } |
2554 /* Disable interrupts by clearing the interrupt mask. */ |
2555 |
2555 RTL_W16 (IntrMask, 0); |
2556 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2556 |
2557 |
2557 /* Update the error counts. */ |
2558 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2558 tp->stats.rx_missed_errors += RTL_R32 (RxMissed); |
2559 if (dev != rtl_ecat_dev.dev) |
2559 RTL_W32 (RxMissed, 0); |
2560 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
2561 spin_lock_irqsave (&tp->lock, flags); |
|
2562 |
|
2563 /* Stop the chip's Tx and Rx DMA processes. */ |
|
2564 RTL_W8 (ChipCmd, 0); |
|
2565 |
|
2566 /* Disable interrupts by clearing the interrupt mask. */ |
|
2567 RTL_W16 (IntrMask, 0); |
|
2568 |
|
2569 /* Update the error counts. */ |
|
2570 tp->stats.rx_missed_errors += RTL_R32 (RxMissed); |
|
2571 RTL_W32 (RxMissed, 0); |
|
2572 |
|
2573 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
2574 if (dev != rtl_ecat_dev.dev) |
|
2575 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
2576 spin_unlock_irqrestore (&tp->lock, flags); |
|
2577 |
|
2578 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
2579 |
|
2580 if (dev != rtl_ecat_dev.dev) |
|
2581 { |
|
2582 synchronize_irq (dev->irq); /* racy, but that's ok here */ |
|
2583 free_irq (dev->irq, dev); |
|
2584 } |
2560 } |
2585 |
2561 |
2586 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2562 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2587 |
2563 |
2588 rtl8139_tx_clear (tp); |
2564 rtl8139_tx_clear (tp); |
2821 |
2797 |
2822 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2798 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2823 |
2799 |
2824 if (dev == rtl_ecat_dev.dev || netif_running(dev)) |
2800 if (dev == rtl_ecat_dev.dev || netif_running(dev)) |
2825 { |
2801 { |
2826 spin_lock_irqsave (&tp->lock, flags); |
2802 spin_lock_irqsave (&tp->lock, flags); |
2827 tp->stats.rx_missed_errors += RTL_R32 (RxMissed); |
2803 tp->stats.rx_missed_errors += RTL_R32 (RxMissed); |
2828 RTL_W32 (RxMissed, 0); |
2804 RTL_W32 (RxMissed, 0); |
2829 spin_unlock_irqrestore (&tp->lock, flags); |
2805 spin_unlock_irqrestore (&tp->lock, flags); |
2830 } |
2806 } |
2831 |
2807 |
2832 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2808 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2833 |
2809 |
2834 return &tp->stats; |
2810 return &tp->stats; |