197 /* bitmapped message enable number */ |
197 /* bitmapped message enable number */ |
198 static int debug = -1; |
198 static int debug = -1; |
199 |
199 |
200 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
200 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
201 |
201 |
202 // Uncomment for debugging |
|
203 //#define EC_DEBUG |
|
204 |
|
205 // Device index for EtherCAT device selection |
|
206 static int ec_device_index = -1; |
202 static int ec_device_index = -1; |
207 static int ec_device_master_index = 0; |
203 static int ec_device_master_index = 0; |
208 |
|
209 static ec_device_t *rtl_ec_dev; |
204 static ec_device_t *rtl_ec_dev; |
210 int rtl_ec_dev_registered = 0; |
205 struct net_device *rtl_ec_net_dev = NULL; |
211 |
206 |
212 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
207 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
213 |
208 |
214 /* |
209 /* |
215 * Receive ring size |
210 * Receive ring size |
1023 assert (dev != NULL); |
1018 assert (dev != NULL); |
1024 tp = netdev_priv(dev); |
1019 tp = netdev_priv(dev); |
1025 |
1020 |
1026 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1021 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1027 |
1022 |
1028 if (board_idx == ec_device_index) |
1023 if (board_idx == ec_device_index) { |
1029 { |
1024 rtl_ec_net_dev = dev; |
1030 printk(KERN_INFO "Registering EtherCAT device...\n"); |
1025 strcpy(dev->name, "ec0"); |
1031 rtl_ec_dev = ecdev_register(ec_device_master_index, dev, |
|
1032 rtl8139_interrupt, THIS_MODULE); |
|
1033 |
|
1034 if (rtl_ec_dev) strcpy(dev->name, "ec0"); |
|
1035 } |
1026 } |
1036 |
1027 |
1037 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1028 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1038 |
1029 |
1039 ioaddr = tp->mmio_addr; |
1030 ioaddr = tp->mmio_addr; |
1090 /* dev is fully set up and ready to use now */ |
1081 /* dev is fully set up and ready to use now */ |
1091 |
1082 |
1092 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1083 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1093 |
1084 |
1094 /* EtherCAT-Karten nicht beim Stack anmelden. */ |
1085 /* EtherCAT-Karten nicht beim Stack anmelden. */ |
1095 if (!ecdev_is_ec(rtl_ec_dev, dev)) |
1086 if (dev != rtl_ec_net_dev) |
1096 { |
1087 { |
1097 DPRINTK("About to register device named %s (%p)...\n", dev->name, dev); |
1088 DPRINTK("About to register device named %s (%p)...\n", dev->name, dev); |
1098 i = register_netdev (dev); |
1089 i = register_netdev (dev); |
1099 if (i) goto err_out; |
1090 if (i) goto err_out; |
1100 } |
1091 } |
1469 |
1460 |
1470 static void rtl_check_media (struct net_device *dev, unsigned int init_media) |
1461 static void rtl_check_media (struct net_device *dev, unsigned int init_media) |
1471 { |
1462 { |
1472 struct rtl8139_private *tp = netdev_priv(dev); |
1463 struct rtl8139_private *tp = netdev_priv(dev); |
1473 |
1464 |
1474 if (ecdev_is_ec(rtl_ec_dev, dev)) { |
1465 if (dev == rtl_ec_net_dev) { |
1475 void __iomem *ioaddr = tp->mmio_addr; |
1466 void __iomem *ioaddr = tp->mmio_addr; |
1476 uint16_t state = RTL_R16(BasicModeStatus) & BMSR_LSTATUS; |
1467 uint16_t state = RTL_R16(BasicModeStatus) & BMSR_LSTATUS; |
1477 ecdev_link_state(rtl_ec_dev, state ? 1 : 0); |
1468 ecdev_link_state(rtl_ec_dev, state ? 1 : 0); |
1478 } |
1469 } |
1479 else if (tp->phys[0] >= 0) { |
1470 else if (tp->phys[0] >= 0) { |
1543 if ((!(tmp & CmdRxEnb)) || (!(tmp & CmdTxEnb))) |
1534 if ((!(tmp & CmdRxEnb)) || (!(tmp & CmdTxEnb))) |
1544 RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb); |
1535 RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb); |
1545 |
1536 |
1546 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1537 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1547 |
1538 |
1548 if (!ecdev_is_ec(rtl_ec_dev, dev)) |
1539 if (dev != rtl_ec_net_dev) |
1549 { |
1540 { |
1550 /* Enable all known interrupts by setting the interrupt mask. */ |
1541 /* Enable all known interrupts by setting the interrupt mask. */ |
1551 RTL_W16 (IntrMask, rtl8139_intr_mask); |
1542 RTL_W16 (IntrMask, rtl8139_intr_mask); |
1552 } |
1543 } |
1553 |
1544 |
1812 RTL_W8 (ChipCmd, CmdRxEnb); |
1803 RTL_W8 (ChipCmd, CmdRxEnb); |
1813 |
1804 |
1814 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1805 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1815 |
1806 |
1816 |
1807 |
1817 if (!ecdev_is_ec(rtl_ec_dev, dev)) |
1808 if (dev != rtl_ec_net_dev) |
1818 { |
1809 { |
1819 spin_lock(&tp->rx_lock); |
1810 spin_lock(&tp->rx_lock); |
1820 |
1811 |
1821 /* Disable interrupts by clearing the interrupt mask. */ |
1812 /* Disable interrupts by clearing the interrupt mask. */ |
1822 RTL_W16 (IntrMask, 0x0000); |
1813 RTL_W16 (IntrMask, 0x0000); |
1862 { |
1853 { |
1863 if (len < ETH_ZLEN) |
1854 if (len < ETH_ZLEN) |
1864 memset(tp->tx_buf[entry], 0, ETH_ZLEN); |
1855 memset(tp->tx_buf[entry], 0, ETH_ZLEN); |
1865 |
1856 |
1866 skb_copy_and_csum_dev(skb, tp->tx_buf[entry]); |
1857 skb_copy_and_csum_dev(skb, tp->tx_buf[entry]); |
1867 if (!ecdev_is_ec(rtl_ec_dev, dev)) dev_kfree_skb(skb); |
1858 if (dev != rtl_ec_net_dev) dev_kfree_skb(skb); |
1868 } |
1859 } |
1869 else |
1860 else |
1870 { |
1861 { |
1871 if (!ecdev_is_ec(rtl_ec_dev, dev)) dev_kfree_skb(skb); |
1862 if (dev != rtl_ec_net_dev) dev_kfree_skb(skb); |
1872 tp->stats.tx_dropped++; |
1863 tp->stats.tx_dropped++; |
1873 return 0; |
1864 return 0; |
1874 } |
1865 } |
1875 |
1866 |
1876 if (!ecdev_is_ec(rtl_ec_dev, dev)) |
1867 if (dev != rtl_ec_net_dev) |
1877 { |
1868 { |
1878 spin_lock_irq(&tp->lock); |
1869 spin_lock_irq(&tp->lock); |
1879 } |
1870 } |
1880 |
1871 |
1881 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1872 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1963 } |
1954 } |
1964 |
1955 |
1965 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1956 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1966 |
1957 |
1967 #ifndef RTL8139_NDEBUG |
1958 #ifndef RTL8139_NDEBUG |
1968 if (!ecdev_is_ec(rtl_ec_dev, dev) && tp->cur_tx - dirty_tx > NUM_TX_DESC) { |
1959 if (dev != rtl_ec_net_dev && tp->cur_tx - dirty_tx > NUM_TX_DESC) { |
1969 printk (KERN_ERR "%s: Out-of-sync dirty pointer, %ld vs. %ld.\n", |
1960 printk (KERN_ERR "%s: Out-of-sync dirty pointer, %ld vs. %ld.\n", |
1970 dev->name, dirty_tx, tp->cur_tx); |
1961 dev->name, dirty_tx, tp->cur_tx); |
1971 dirty_tx += NUM_TX_DESC; |
1962 dirty_tx += NUM_TX_DESC; |
1972 } |
1963 } |
1973 #endif /* RTL8139_NDEBUG */ |
1964 #endif /* RTL8139_NDEBUG */ |
2118 DPRINTK ("%s: In rtl8139_rx(), current %4.4x BufAddr %4.4x," |
2109 DPRINTK ("%s: In rtl8139_rx(), current %4.4x BufAddr %4.4x," |
2119 " free to %4.4x, Cmd %2.2x.\n", dev->name, (u16)cur_rx, |
2110 " free to %4.4x, Cmd %2.2x.\n", dev->name, (u16)cur_rx, |
2120 RTL_R16 (RxBufAddr), |
2111 RTL_R16 (RxBufAddr), |
2121 RTL_R16 (RxBufPtr), RTL_R8 (ChipCmd)); |
2112 RTL_R16 (RxBufPtr), RTL_R8 (ChipCmd)); |
2122 |
2113 |
2123 while ((ecdev_is_ec(rtl_ec_dev, dev) || netif_running(dev)) |
2114 while ((dev == rtl_ec_net_dev || netif_running(dev)) |
2124 && received < budget |
2115 && received < budget |
2125 && (RTL_R8 (ChipCmd) & RxBufEmpty) == 0) { |
2116 && (RTL_R8 (ChipCmd) & RxBufEmpty) == 0) { |
2126 u32 ring_offset = cur_rx % RX_BUF_LEN; |
2117 u32 ring_offset = cur_rx % RX_BUF_LEN; |
2127 u32 rx_status; |
2118 u32 rx_status; |
2128 unsigned int pkt_size; |
2119 unsigned int pkt_size; |
2135 rx_size = rx_status >> 16; |
2126 rx_size = rx_status >> 16; |
2136 pkt_size = rx_size - 4; |
2127 pkt_size = rx_size - 4; |
2137 |
2128 |
2138 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2129 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2139 |
2130 |
2140 if (!ecdev_is_ec(rtl_ec_dev, dev) && netif_msg_rx_status(tp)) |
2131 if (dev != rtl_ec_net_dev && netif_msg_rx_status(tp)) |
2141 printk(KERN_DEBUG "%s: rtl8139_rx() status %4.4x, size %4.4x," |
2132 printk(KERN_DEBUG "%s: rtl8139_rx() status %4.4x, size %4.4x," |
2142 " cur %4.4x.\n", dev->name, rx_status, |
2133 " cur %4.4x.\n", dev->name, rx_status, |
2143 rx_size, cur_rx); |
2134 rx_size, cur_rx); |
2144 |
2135 |
2145 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2136 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2378 if (unlikely(status == 0xFFFF)) |
2369 if (unlikely(status == 0xFFFF)) |
2379 goto out; |
2370 goto out; |
2380 |
2371 |
2381 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2372 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2382 |
2373 |
2383 if (!ecdev_is_ec(rtl_ec_dev, dev)) |
2374 if (dev != rtl_ec_net_dev) |
2384 { |
2375 { |
2385 /* close possible race's with dev_close */ |
2376 /* close possible race's with dev_close */ |
2386 if (unlikely(!netif_running(dev))) { |
2377 if (unlikely(!netif_running(dev))) { |
2387 RTL_W16 (IntrMask, 0); |
2378 RTL_W16 (IntrMask, 0); |
2388 goto out; |
2379 goto out; |
2406 |
2397 |
2407 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2398 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2408 |
2399 |
2409 if (status & RxAckBits) |
2400 if (status & RxAckBits) |
2410 { |
2401 { |
2411 if (!ecdev_is_ec(rtl_ec_dev, dev)) |
2402 if (dev != rtl_ec_net_dev) |
2412 { |
2403 { |
2413 /* Polling vormerken */ |
2404 /* Polling vormerken */ |
2414 if (netif_rx_schedule_prep(dev)) { |
2405 if (netif_rx_schedule_prep(dev)) { |
2415 RTL_W16_F (IntrMask, rtl8139_norx_intr_mask); |
2406 RTL_W16_F (IntrMask, rtl8139_norx_intr_mask); |
2416 __netif_rx_schedule (dev); |
2407 __netif_rx_schedule (dev); |
2756 void __iomem *ioaddr = tp->mmio_addr; |
2747 void __iomem *ioaddr = tp->mmio_addr; |
2757 unsigned long flags; |
2748 unsigned long flags; |
2758 |
2749 |
2759 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2750 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2760 |
2751 |
2761 if (ecdev_is_ec(rtl_ec_dev, dev) || netif_running(dev)) |
2752 if (dev == rtl_ec_net_dev || netif_running(dev)) |
2762 { |
2753 { |
2763 spin_lock_irqsave (&tp->lock, flags); |
2754 spin_lock_irqsave (&tp->lock, flags); |
2764 tp->stats.rx_missed_errors += RTL_R32 (RxMissed); |
2755 tp->stats.rx_missed_errors += RTL_R32 (RxMissed); |
2765 RTL_W32 (RxMissed, 0); |
2756 RTL_W32 (RxMissed, 0); |
2766 spin_unlock_irqrestore (&tp->lock, flags); |
2757 spin_unlock_irqrestore (&tp->lock, flags); |
2905 }; |
2896 }; |
2906 |
2897 |
2907 |
2898 |
2908 static int __init rtl8139_init_module (void) |
2899 static int __init rtl8139_init_module (void) |
2909 { |
2900 { |
2910 /* when we're a module, we always print a version message, |
|
2911 * even if no 8139 board is found. |
|
2912 */ |
|
2913 #ifdef MODULE |
|
2914 printk (KERN_INFO RTL8139_DRIVER_NAME "\n"); |
|
2915 #endif |
|
2916 |
|
2917 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2901 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2918 |
2902 |
2919 printk(KERN_INFO "Initializing RTL8139-EtherCAT module. %s\n", COMPILE_INFO); |
2903 printk(KERN_INFO RTL8139_DRIVER_NAME " " COMPILE_INFO "\n"); |
2920 printk(KERN_INFO "EtherCAT device index is %i.\n", ec_device_index); |
2904 printk(KERN_INFO "ec_device_index is %i\n", ec_device_index); |
2921 |
2905 |
2922 if (pci_module_init(&rtl8139_pci_driver) < 0) |
2906 if (pci_module_init(&rtl8139_pci_driver) < 0) { |
2923 { |
2907 printk(KERN_ERR "Failed to init PCI module.\n"); |
2924 printk(KERN_ERR "Could not init PCI module.\n"); |
2908 goto out_return; |
2925 goto out_ec_dev; |
|
2926 } |
2909 } |
2927 |
2910 |
2928 if (!rtl_ec_dev) |
2911 if (rtl_ec_net_dev) { |
2929 { |
2912 printk(KERN_INFO "Registering EtherCAT device...\n"); |
2930 printk(KERN_WARNING "NO EtherCAT device registered!\n"); |
2913 if (!(rtl_ec_dev = ecdev_register(ec_device_master_index, |
|
2914 rtl_ec_net_dev, rtl8139_interrupt, |
|
2915 THIS_MODULE))) { |
|
2916 printk(KERN_ERR "Failed to register EtherCAT device!\n"); |
|
2917 goto out_pci; |
|
2918 } |
|
2919 |
|
2920 printk(KERN_INFO "Starting EtherCAT device...\n"); |
|
2921 if (ecdev_start(ec_device_master_index)) { |
|
2922 printk(KERN_ERR "Failed to start EtherCAT device!\n"); |
|
2923 goto out_unregister; |
|
2924 } |
2931 } |
2925 } |
|
2926 else { |
|
2927 printk(KERN_WARNING "NO EtherCAT device registered!\n"); |
|
2928 } |
2932 |
2929 |
2933 return 0; |
2930 return 0; |
2934 |
2931 |
2935 out_ec_dev: |
2932 out_unregister: |
2936 if (rtl_ec_dev) { |
2933 ecdev_unregister(ec_device_master_index, rtl_ec_dev); |
2937 printk(KERN_INFO "Unregistering RTL8139-EtherCAT device...\n"); |
2934 out_pci: |
|
2935 pci_unregister_driver(&rtl8139_pci_driver); |
|
2936 out_return: |
|
2937 return -1; |
|
2938 |
|
2939 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2940 } |
|
2941 |
|
2942 |
|
2943 static void __exit rtl8139_cleanup_module (void) |
|
2944 { |
|
2945 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
2946 |
|
2947 printk(KERN_INFO "Cleaning up RTL8139-EtherCAT module...\n"); |
|
2948 |
|
2949 if (rtl_ec_net_dev) { |
|
2950 printk(KERN_INFO "Stopping device...\n"); |
|
2951 ecdev_stop(ec_device_master_index); |
|
2952 printk(KERN_INFO "Unregistering device...\n"); |
2938 ecdev_unregister(ec_device_master_index, rtl_ec_dev); |
2953 ecdev_unregister(ec_device_master_index, rtl_ec_dev); |
2939 rtl_ec_dev = NULL; |
2954 rtl_ec_dev = NULL; |
2940 } |
2955 } |
2941 |
|
2942 return -1; |
|
2943 |
|
2944 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2945 } |
|
2946 |
|
2947 |
|
2948 static void __exit rtl8139_cleanup_module (void) |
|
2949 { |
|
2950 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
2951 |
|
2952 printk(KERN_INFO "Cleaning up RTL8139-EtherCAT module...\n"); |
|
2953 |
2956 |
2954 pci_unregister_driver(&rtl8139_pci_driver); |
2957 pci_unregister_driver(&rtl8139_pci_driver); |
2955 |
|
2956 if (rtl_ec_dev) { |
|
2957 printk(KERN_INFO "Unregistering RTL8139-EtherCAT device...\n"); |
|
2958 ecdev_unregister(ec_device_master_index, rtl_ec_dev); |
|
2959 rtl_ec_dev = NULL; |
|
2960 } |
|
2961 |
2958 |
2962 printk(KERN_INFO "RTL8139-EtherCAT module cleaned up.\n"); |
2959 printk(KERN_INFO "RTL8139-EtherCAT module cleaned up.\n"); |
2963 |
2960 |
2964 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2961 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2965 } |
2962 } |