devices/8139too.c
changeset 104 052bc82d5442
parent 98 f564d0929292
child 191 ca805255a935
equal deleted inserted replaced
103:d2a8adde27c4 104:052bc82d5442
   132 #include <asm/uaccess.h>
   132 #include <asm/uaccess.h>
   133 #include <asm/irq.h>
   133 #include <asm/irq.h>
   134 
   134 
   135 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
   135 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
   136 
   136 
   137 #include "../include/EtherCAT_dev.h"
   137 #include "ecdev.h"
   138 
   138 
   139 #define EC_LIT(X) #X
   139 #define EC_LIT(X) #X
   140 #define EC_STR(X) EC_LIT(X)
   140 #define EC_STR(X) EC_LIT(X)
   141 
   141 
   142 #define COMPILE_INFO "Revision " EC_STR(EC_REV) \
   142 #define COMPILE_INFO "Revision " EC_STR(EC_REV) \
  1026 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1026 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1027 
  1027 
  1028 	if (board_idx == ec_device_index)
  1028 	if (board_idx == ec_device_index)
  1029     {
  1029     {
  1030           printk(KERN_INFO "Registering EtherCAT device...\n");
  1030           printk(KERN_INFO "Registering EtherCAT device...\n");
  1031           rtl_ec_dev = EtherCAT_dev_register(ec_device_master_index, dev,
  1031           rtl_ec_dev = ecdev_register(ec_device_master_index, dev,
  1032                                              rtl8139_interrupt, THIS_MODULE);
  1032                                              rtl8139_interrupt, THIS_MODULE);
  1033 
  1033 
  1034           if (rtl_ec_dev) strcpy(dev->name, "ec0");
  1034           if (rtl_ec_dev) strcpy(dev->name, "ec0");
  1035 	}
  1035 	}
  1036 
  1036 
  1090 	/* dev is fully set up and ready to use now */
  1090 	/* dev is fully set up and ready to use now */
  1091 
  1091 
  1092 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1092 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1093 
  1093 
  1094 	/* EtherCAT-Karten nicht beim Stack anmelden. */
  1094 	/* EtherCAT-Karten nicht beim Stack anmelden. */
  1095     if (!EtherCAT_dev_is_ec(rtl_ec_dev, dev))
  1095     if (!ecdev_is_ec(rtl_ec_dev, dev))
  1096 	{
  1096 	{
  1097                 DPRINTK("About to register device named %s (%p)...\n", dev->name, dev);
  1097                 DPRINTK("About to register device named %s (%p)...\n", dev->name, dev);
  1098                 i = register_netdev (dev);
  1098                 i = register_netdev (dev);
  1099                 if (i) goto err_out;
  1099                 if (i) goto err_out;
  1100 	}
  1100 	}
  1188 
  1188 
  1189 	assert (dev != NULL);
  1189 	assert (dev != NULL);
  1190 
  1190 
  1191         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1191         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1192 
  1192 
  1193         if (!EtherCAT_dev_is_ec(rtl_ec_dev, dev))
  1193         if (!ecdev_is_ec(rtl_ec_dev, dev))
  1194         {
  1194         {
  1195                 unregister_netdev (dev);
  1195                 unregister_netdev (dev);
  1196 	}
  1196 	}
  1197 
  1197 
  1198 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  1198 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  1401 
  1401 
  1402 #ifdef EC_DEBUG
  1402 #ifdef EC_DEBUG
  1403         printk(KERN_DEBUG "%s: open\n", dev->name);
  1403         printk(KERN_DEBUG "%s: open\n", dev->name);
  1404 #endif
  1404 #endif
  1405 
  1405 
  1406         if (!EtherCAT_dev_is_ec(rtl_ec_dev, dev))
  1406         if (!ecdev_is_ec(rtl_ec_dev, dev))
  1407         {
  1407         {
  1408                 retval = request_irq(dev->irq, rtl8139_interrupt, SA_SHIRQ, dev->name, dev);
  1408                 retval = request_irq(dev->irq, rtl8139_interrupt, SA_SHIRQ, dev->name, dev);
  1409                 if (retval)
  1409                 if (retval)
  1410                   return retval;
  1410                   return retval;
  1411         }
  1411         }
  1418 					   &tp->rx_ring_dma);
  1418 					   &tp->rx_ring_dma);
  1419 	if (tp->tx_bufs == NULL || tp->rx_ring == NULL)
  1419 	if (tp->tx_bufs == NULL || tp->rx_ring == NULL)
  1420         {
  1420         {
  1421                 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1421                 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1422 
  1422 
  1423                 if (!EtherCAT_dev_is_ec(rtl_ec_dev, dev))
  1423                 if (!ecdev_is_ec(rtl_ec_dev, dev))
  1424                 {
  1424                 {
  1425                           free_irq(dev->irq, dev);
  1425                           free_irq(dev->irq, dev);
  1426                 }
  1426                 }
  1427 
  1427 
  1428                 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  1428                 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  1443 	rtl8139_init_ring (dev);
  1443 	rtl8139_init_ring (dev);
  1444 	rtl8139_hw_start (dev);
  1444 	rtl8139_hw_start (dev);
  1445 
  1445 
  1446         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1446         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1447 
  1447 
  1448         if (!EtherCAT_dev_is_ec(rtl_ec_dev, dev))
  1448         if (!ecdev_is_ec(rtl_ec_dev, dev))
  1449         {
  1449         {
  1450                 netif_start_queue (dev);
  1450                 netif_start_queue (dev);
  1451 
  1451 
  1452                 if (netif_msg_ifup(tp))
  1452                 if (netif_msg_ifup(tp))
  1453                 {
  1453                 {
  1469 
  1469 
  1470 static void rtl_check_media (struct net_device *dev, unsigned int init_media)
  1470 static void rtl_check_media (struct net_device *dev, unsigned int init_media)
  1471 {
  1471 {
  1472 	struct rtl8139_private *tp = netdev_priv(dev);
  1472 	struct rtl8139_private *tp = netdev_priv(dev);
  1473 
  1473 
  1474         if (EtherCAT_dev_is_ec(rtl_ec_dev, dev)) {
  1474         if (ecdev_is_ec(rtl_ec_dev, dev)) {
  1475             void __iomem *ioaddr = tp->mmio_addr;
  1475             void __iomem *ioaddr = tp->mmio_addr;
  1476             uint16_t state = RTL_R16(BasicModeStatus) & BMSR_LSTATUS;
  1476             uint16_t state = RTL_R16(BasicModeStatus) & BMSR_LSTATUS;
  1477             EtherCAT_dev_link_state(rtl_ec_dev, state ? 1 : 0);
  1477             ecdev_link_state(rtl_ec_dev, state ? 1 : 0);
  1478         }
  1478         }
  1479         else if (tp->phys[0] >= 0) {
  1479         else if (tp->phys[0] >= 0) {
  1480 		mii_check_media(&tp->mii, netif_msg_link(tp), init_media);
  1480 		mii_check_media(&tp->mii, netif_msg_link(tp), init_media);
  1481 	}
  1481 	}
  1482 }
  1482 }
  1543 	if ((!(tmp & CmdRxEnb)) || (!(tmp & CmdTxEnb)))
  1543 	if ((!(tmp & CmdRxEnb)) || (!(tmp & CmdTxEnb)))
  1544 		RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb);
  1544 		RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb);
  1545 
  1545 
  1546 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1546 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1547 
  1547 
  1548         if (!EtherCAT_dev_is_ec(rtl_ec_dev, dev))
  1548         if (!ecdev_is_ec(rtl_ec_dev, dev))
  1549         {
  1549         {
  1550                 /* Enable all known interrupts by setting the interrupt mask. */
  1550                 /* Enable all known interrupts by setting the interrupt mask. */
  1551                 RTL_W16 (IntrMask, rtl8139_intr_mask);
  1551                 RTL_W16 (IntrMask, rtl8139_intr_mask);
  1552 	}
  1552 	}
  1553 
  1553 
  1812                 RTL_W8 (ChipCmd, CmdRxEnb);
  1812                 RTL_W8 (ChipCmd, CmdRxEnb);
  1813 
  1813 
  1814     /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1814     /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1815 
  1815 
  1816 
  1816 
  1817         if (!EtherCAT_dev_is_ec(rtl_ec_dev, dev))
  1817         if (!ecdev_is_ec(rtl_ec_dev, dev))
  1818         {
  1818         {
  1819                 spin_lock(&tp->rx_lock);
  1819                 spin_lock(&tp->rx_lock);
  1820 
  1820 
  1821                 /* Disable interrupts by clearing the interrupt mask. */
  1821                 /* Disable interrupts by clearing the interrupt mask. */
  1822                 RTL_W16 (IntrMask, 0x0000);
  1822                 RTL_W16 (IntrMask, 0x0000);
  1862         {
  1862         {
  1863                 if (len < ETH_ZLEN)
  1863                 if (len < ETH_ZLEN)
  1864                         memset(tp->tx_buf[entry], 0, ETH_ZLEN);
  1864                         memset(tp->tx_buf[entry], 0, ETH_ZLEN);
  1865 
  1865 
  1866                 skb_copy_and_csum_dev(skb, tp->tx_buf[entry]);
  1866                 skb_copy_and_csum_dev(skb, tp->tx_buf[entry]);
  1867                 if (!EtherCAT_dev_is_ec(rtl_ec_dev, dev)) dev_kfree_skb(skb);
  1867                 if (!ecdev_is_ec(rtl_ec_dev, dev)) dev_kfree_skb(skb);
  1868 	}
  1868 	}
  1869         else
  1869         else
  1870         {
  1870         {
  1871                 if (!EtherCAT_dev_is_ec(rtl_ec_dev, dev)) dev_kfree_skb(skb);
  1871                 if (!ecdev_is_ec(rtl_ec_dev, dev)) dev_kfree_skb(skb);
  1872                 tp->stats.tx_dropped++;
  1872                 tp->stats.tx_dropped++;
  1873                 return 0;
  1873                 return 0;
  1874 	}
  1874 	}
  1875 
  1875 
  1876 	if (!EtherCAT_dev_is_ec(rtl_ec_dev, dev))
  1876 	if (!ecdev_is_ec(rtl_ec_dev, dev))
  1877         {
  1877         {
  1878                 spin_lock_irq(&tp->lock);
  1878                 spin_lock_irq(&tp->lock);
  1879         }
  1879         }
  1880 
  1880 
  1881 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  1881 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  1888 	tp->cur_tx++;
  1888 	tp->cur_tx++;
  1889 	wmb();
  1889 	wmb();
  1890 
  1890 
  1891 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1891 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1892 
  1892 
  1893 	if (!EtherCAT_dev_is_ec(rtl_ec_dev, dev))
  1893 	if (!ecdev_is_ec(rtl_ec_dev, dev))
  1894         {
  1894         {
  1895                 if ((tp->cur_tx - NUM_TX_DESC) == tp->dirty_tx)
  1895                 if ((tp->cur_tx - NUM_TX_DESC) == tp->dirty_tx)
  1896                         netif_stop_queue (dev);
  1896                         netif_stop_queue (dev);
  1897 
  1897 
  1898                 spin_unlock_irq(&tp->lock);
  1898                 spin_unlock_irq(&tp->lock);
  1963 	}
  1963 	}
  1964 
  1964 
  1965         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1965         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1966 
  1966 
  1967 #ifndef RTL8139_NDEBUG
  1967 #ifndef RTL8139_NDEBUG
  1968 	if (!EtherCAT_dev_is_ec(rtl_ec_dev, dev) && tp->cur_tx - dirty_tx > NUM_TX_DESC) {
  1968 	if (!ecdev_is_ec(rtl_ec_dev, dev) && tp->cur_tx - dirty_tx > NUM_TX_DESC) {
  1969 		printk (KERN_ERR "%s: Out-of-sync dirty pointer, %ld vs. %ld.\n",
  1969 		printk (KERN_ERR "%s: Out-of-sync dirty pointer, %ld vs. %ld.\n",
  1970 		        dev->name, dirty_tx, tp->cur_tx);
  1970 		        dev->name, dirty_tx, tp->cur_tx);
  1971 		dirty_tx += NUM_TX_DESC;
  1971 		dirty_tx += NUM_TX_DESC;
  1972 	}
  1972 	}
  1973 #endif /* RTL8139_NDEBUG */
  1973 #endif /* RTL8139_NDEBUG */
  1979 		tp->dirty_tx = dirty_tx;
  1979 		tp->dirty_tx = dirty_tx;
  1980 		mb();
  1980 		mb();
  1981 
  1981 
  1982                 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1982                 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1983 
  1983 
  1984 		if (!EtherCAT_dev_is_ec(rtl_ec_dev, dev))
  1984 		if (!ecdev_is_ec(rtl_ec_dev, dev))
  1985                 {
  1985                 {
  1986                         netif_wake_queue (dev);
  1986                         netif_wake_queue (dev);
  1987                 }
  1987                 }
  1988 
  1988 
  1989                 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  1989                 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2118 	DPRINTK ("%s: In rtl8139_rx(), current %4.4x BufAddr %4.4x,"
  2118 	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,
  2119 		 " free to %4.4x, Cmd %2.2x.\n", dev->name, (u16)cur_rx,
  2120 		 RTL_R16 (RxBufAddr),
  2120 		 RTL_R16 (RxBufAddr),
  2121 		 RTL_R16 (RxBufPtr), RTL_R8 (ChipCmd));
  2121 		 RTL_R16 (RxBufPtr), RTL_R8 (ChipCmd));
  2122 
  2122 
  2123 	while ((EtherCAT_dev_is_ec(rtl_ec_dev, dev) || netif_running(dev))
  2123 	while ((ecdev_is_ec(rtl_ec_dev, dev) || netif_running(dev))
  2124 	       && received < budget
  2124 	       && received < budget
  2125 	       && (RTL_R8 (ChipCmd) & RxBufEmpty) == 0) {
  2125 	       && (RTL_R8 (ChipCmd) & RxBufEmpty) == 0) {
  2126 		u32 ring_offset = cur_rx % RX_BUF_LEN;
  2126 		u32 ring_offset = cur_rx % RX_BUF_LEN;
  2127 		u32 rx_status;
  2127 		u32 rx_status;
  2128 		unsigned int pkt_size;
  2128 		unsigned int pkt_size;
  2135 		rx_size = rx_status >> 16;
  2135 		rx_size = rx_status >> 16;
  2136 		pkt_size = rx_size - 4;
  2136 		pkt_size = rx_size - 4;
  2137 
  2137 
  2138                 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2138                 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2139 
  2139 
  2140 		if (!EtherCAT_dev_is_ec(rtl_ec_dev, dev) && netif_msg_rx_status(tp))
  2140 		if (!ecdev_is_ec(rtl_ec_dev, dev) && netif_msg_rx_status(tp))
  2141                         printk(KERN_DEBUG "%s:  rtl8139_rx() status %4.4x, size %4.4x,"
  2141                         printk(KERN_DEBUG "%s:  rtl8139_rx() status %4.4x, size %4.4x,"
  2142                                " cur %4.4x.\n", dev->name, rx_status,
  2142                                " cur %4.4x.\n", dev->name, rx_status,
  2143                                rx_size, cur_rx);
  2143                                rx_size, cur_rx);
  2144 
  2144 
  2145                 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2145                 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2191 			goto out;
  2191 			goto out;
  2192 		}
  2192 		}
  2193 
  2193 
  2194                 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2194                 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2195 
  2195 
  2196                 if (!EtherCAT_dev_is_ec(rtl_ec_dev, dev))
  2196                 if (!ecdev_is_ec(rtl_ec_dev, dev))
  2197                 {
  2197                 {
  2198                         /* Malloc up new buffer, compatible with net-2e. */
  2198                         /* Malloc up new buffer, compatible with net-2e. */
  2199                         /* Omit the four octet CRC from the length. */
  2199                         /* Omit the four octet CRC from the length. */
  2200                         skb = dev_alloc_skb(pkt_size + 2);
  2200                         skb = dev_alloc_skb(pkt_size + 2);
  2201 
  2201 
  2224                                 tp->stats.rx_dropped++;
  2224                                 tp->stats.rx_dropped++;
  2225                         }
  2225                         }
  2226                 }
  2226                 }
  2227                 else
  2227                 else
  2228                 {
  2228                 {
  2229                     EtherCAT_dev_receive(rtl_ec_dev,
  2229                     ecdev_receive(rtl_ec_dev,
  2230                                          &rx_ring[ring_offset + 4] + ETH_HLEN,
  2230                                          &rx_ring[ring_offset + 4] + ETH_HLEN,
  2231                                          pkt_size - ETH_HLEN);
  2231                                          pkt_size - ETH_HLEN);
  2232                     dev->last_rx = jiffies;
  2232                     dev->last_rx = jiffies;
  2233                     tp->stats.rx_bytes += pkt_size;
  2233                     tp->stats.rx_bytes += pkt_size;
  2234                     tp->stats.rx_packets++;
  2234                     tp->stats.rx_packets++;
  2354 	int link_changed = 0; /* avoid bogus "uninit" warning */
  2354 	int link_changed = 0; /* avoid bogus "uninit" warning */
  2355 	int handled = 0;
  2355 	int handled = 0;
  2356 
  2356 
  2357         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2357         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2358 
  2358 
  2359 	if (EtherCAT_dev_is_ec(rtl_ec_dev, dev))
  2359 	if (ecdev_is_ec(rtl_ec_dev, dev))
  2360         {
  2360         {
  2361                 status = RTL_R16 (IntrStatus);
  2361                 status = RTL_R16 (IntrStatus);
  2362 	}
  2362 	}
  2363 	else
  2363 	else
  2364         {
  2364         {
  2378 	if (unlikely(status == 0xFFFF))
  2378 	if (unlikely(status == 0xFFFF))
  2379 		goto out;
  2379 		goto out;
  2380 
  2380 
  2381         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2381         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2382 
  2382 
  2383 	if (!EtherCAT_dev_is_ec(rtl_ec_dev, dev))
  2383 	if (!ecdev_is_ec(rtl_ec_dev, dev))
  2384         {
  2384         {
  2385                 /* close possible race's with dev_close */
  2385                 /* close possible race's with dev_close */
  2386                 if (unlikely(!netif_running(dev))) {
  2386                 if (unlikely(!netif_running(dev))) {
  2387                         RTL_W16 (IntrMask, 0);
  2387                         RTL_W16 (IntrMask, 0);
  2388                         goto out;
  2388                         goto out;
  2406 
  2406 
  2407         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2407         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2408 
  2408 
  2409 	if (status & RxAckBits)
  2409 	if (status & RxAckBits)
  2410         {
  2410         {
  2411           if (!EtherCAT_dev_is_ec(rtl_ec_dev, dev))
  2411           if (!ecdev_is_ec(rtl_ec_dev, dev))
  2412           {
  2412           {
  2413             /* Polling vormerken */
  2413             /* Polling vormerken */
  2414             if (netif_rx_schedule_prep(dev)) {
  2414             if (netif_rx_schedule_prep(dev)) {
  2415               RTL_W16_F (IntrMask, rtl8139_norx_intr_mask);
  2415               RTL_W16_F (IntrMask, rtl8139_norx_intr_mask);
  2416               __netif_rx_schedule (dev);
  2416               __netif_rx_schedule (dev);
  2436 			RTL_W16 (IntrStatus, TxErr);
  2436 			RTL_W16 (IntrStatus, TxErr);
  2437 	}
  2437 	}
  2438  out:
  2438  out:
  2439         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2439         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2440 
  2440 
  2441 	if (!EtherCAT_dev_is_ec(rtl_ec_dev, dev))
  2441 	if (!ecdev_is_ec(rtl_ec_dev, dev))
  2442         {
  2442         {
  2443           spin_unlock (&tp->lock);
  2443           spin_unlock (&tp->lock);
  2444         }
  2444         }
  2445 
  2445 
  2446         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2446         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2470 	int ret = 0;
  2470 	int ret = 0;
  2471 	unsigned long flags;
  2471 	unsigned long flags;
  2472 
  2472 
  2473         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2473         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2474 
  2474 
  2475         if (!EtherCAT_dev_is_ec(rtl_ec_dev, dev))
  2475         if (!ecdev_is_ec(rtl_ec_dev, dev))
  2476         {
  2476         {
  2477                 netif_stop_queue(dev);
  2477                 netif_stop_queue(dev);
  2478                 if (tp->thr_pid >= 0) {
  2478                 if (tp->thr_pid >= 0) {
  2479                         tp->time_to_die = 1;
  2479                         tp->time_to_die = 1;
  2480                         wmb();
  2480                         wmb();
  2735 	struct rtl8139_private *np = netdev_priv(dev);
  2735 	struct rtl8139_private *np = netdev_priv(dev);
  2736 	int rc;
  2736 	int rc;
  2737 
  2737 
  2738         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2738         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2739 
  2739 
  2740 	if (EtherCAT_dev_is_ec(rtl_ec_dev, dev) || !netif_running(dev))
  2740 	if (ecdev_is_ec(rtl_ec_dev, dev) || !netif_running(dev))
  2741 		return -EINVAL;
  2741 		return -EINVAL;
  2742 
  2742 
  2743         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2743         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2744 
  2744 
  2745 	spin_lock_irq(&np->lock);
  2745 	spin_lock_irq(&np->lock);
  2756 	void __iomem *ioaddr = tp->mmio_addr;
  2756 	void __iomem *ioaddr = tp->mmio_addr;
  2757 	unsigned long flags;
  2757 	unsigned long flags;
  2758 
  2758 
  2759         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2759         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2760 
  2760 
  2761 	if (EtherCAT_dev_is_ec(rtl_ec_dev, dev) || netif_running(dev))
  2761 	if (ecdev_is_ec(rtl_ec_dev, dev) || netif_running(dev))
  2762         {
  2762         {
  2763                 spin_lock_irqsave (&tp->lock, flags);
  2763                 spin_lock_irqsave (&tp->lock, flags);
  2764                 tp->stats.rx_missed_errors += RTL_R32 (RxMissed);
  2764                 tp->stats.rx_missed_errors += RTL_R32 (RxMissed);
  2765                 RTL_W32 (RxMissed, 0);
  2765                 RTL_W32 (RxMissed, 0);
  2766                 spin_unlock_irqrestore (&tp->lock, flags);
  2766                 spin_unlock_irqrestore (&tp->lock, flags);
  2843 
  2843 
  2844 	pci_save_state (pdev);
  2844 	pci_save_state (pdev);
  2845 
  2845 
  2846         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2846         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2847 
  2847 
  2848 	if (EtherCAT_dev_is_ec(rtl_ec_dev, dev) || !netif_running (dev))
  2848 	if (ecdev_is_ec(rtl_ec_dev, dev) || !netif_running (dev))
  2849                 return 0;
  2849                 return 0;
  2850 
  2850 
  2851         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2851         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2852 
  2852 
  2853 	netif_device_detach (dev);
  2853 	netif_device_detach (dev);
  2876 
  2876 
  2877 	pci_restore_state (pdev);
  2877 	pci_restore_state (pdev);
  2878 
  2878 
  2879         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2879         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2880 
  2880 
  2881 	if (EtherCAT_dev_is_ec(rtl_ec_dev, dev) || !netif_running (dev))
  2881 	if (ecdev_is_ec(rtl_ec_dev, dev) || !netif_running (dev))
  2882                 return 0;
  2882                 return 0;
  2883 
  2883 
  2884         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2884         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2885 
  2885 
  2886 	pci_set_power_state (pdev, PCI_D0);
  2886 	pci_set_power_state (pdev, PCI_D0);
  2933     return 0;
  2933     return 0;
  2934 
  2934 
  2935  out_ec_dev:
  2935  out_ec_dev:
  2936     if (rtl_ec_dev) {
  2936     if (rtl_ec_dev) {
  2937       printk(KERN_INFO "Unregistering RTL8139-EtherCAT device...\n");
  2937       printk(KERN_INFO "Unregistering RTL8139-EtherCAT device...\n");
  2938       EtherCAT_dev_unregister(ec_device_master_index, rtl_ec_dev);
  2938       ecdev_unregister(ec_device_master_index, rtl_ec_dev);
  2939       rtl_ec_dev = NULL;
  2939       rtl_ec_dev = NULL;
  2940     }
  2940     }
  2941 
  2941 
  2942     return -1;
  2942     return -1;
  2943 
  2943 
  2953 
  2953 
  2954   pci_unregister_driver(&rtl8139_pci_driver);
  2954   pci_unregister_driver(&rtl8139_pci_driver);
  2955 
  2955 
  2956   if (rtl_ec_dev) {
  2956   if (rtl_ec_dev) {
  2957     printk(KERN_INFO "Unregistering RTL8139-EtherCAT device...\n");
  2957     printk(KERN_INFO "Unregistering RTL8139-EtherCAT device...\n");
  2958     EtherCAT_dev_unregister(ec_device_master_index, rtl_ec_dev);
  2958     ecdev_unregister(ec_device_master_index, rtl_ec_dev);
  2959     rtl_ec_dev = NULL;
  2959     rtl_ec_dev = NULL;
  2960   }
  2960   }
  2961 
  2961 
  2962   printk(KERN_INFO "RTL8139-EtherCAT module cleaned up.\n");
  2962   printk(KERN_INFO "RTL8139-EtherCAT module cleaned up.\n");
  2963 
  2963