devices/8139too.c
changeset 191 ca805255a935
parent 104 052bc82d5442
child 192 8d7bd5082ed5
equal deleted inserted replaced
190:4e32bcc6b361 191:ca805255a935
   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 	}
  1188 
  1179 
  1189 	assert (dev != NULL);
  1180 	assert (dev != NULL);
  1190 
  1181 
  1191         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1182         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1192 
  1183 
  1193         if (!ecdev_is_ec(rtl_ec_dev, dev))
  1184         if (dev != rtl_ec_net_dev)
  1194         {
  1185         {
  1195                 unregister_netdev (dev);
  1186                 unregister_netdev (dev);
  1196 	}
  1187 	}
  1197 
  1188 
  1198 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  1189 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  1401 
  1392 
  1402 #ifdef EC_DEBUG
  1393 #ifdef EC_DEBUG
  1403         printk(KERN_DEBUG "%s: open\n", dev->name);
  1394         printk(KERN_DEBUG "%s: open\n", dev->name);
  1404 #endif
  1395 #endif
  1405 
  1396 
  1406         if (!ecdev_is_ec(rtl_ec_dev, dev))
  1397         if (dev != rtl_ec_net_dev)
  1407         {
  1398         {
  1408                 retval = request_irq(dev->irq, rtl8139_interrupt, SA_SHIRQ, dev->name, dev);
  1399                 retval = request_irq(dev->irq, rtl8139_interrupt, SA_SHIRQ, dev->name, dev);
  1409                 if (retval)
  1400                 if (retval)
  1410                   return retval;
  1401                   return retval;
  1411         }
  1402         }
  1418 					   &tp->rx_ring_dma);
  1409 					   &tp->rx_ring_dma);
  1419 	if (tp->tx_bufs == NULL || tp->rx_ring == NULL)
  1410 	if (tp->tx_bufs == NULL || tp->rx_ring == NULL)
  1420         {
  1411         {
  1421                 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1412                 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1422 
  1413 
  1423                 if (!ecdev_is_ec(rtl_ec_dev, dev))
  1414                 if (dev != rtl_ec_net_dev)
  1424                 {
  1415                 {
  1425                           free_irq(dev->irq, dev);
  1416                           free_irq(dev->irq, dev);
  1426                 }
  1417                 }
  1427 
  1418 
  1428                 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  1419                 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  1443 	rtl8139_init_ring (dev);
  1434 	rtl8139_init_ring (dev);
  1444 	rtl8139_hw_start (dev);
  1435 	rtl8139_hw_start (dev);
  1445 
  1436 
  1446         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1437         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1447 
  1438 
  1448         if (!ecdev_is_ec(rtl_ec_dev, dev))
  1439         if (dev != rtl_ec_net_dev)
  1449         {
  1440         {
  1450                 netif_start_queue (dev);
  1441                 netif_start_queue (dev);
  1451 
  1442 
  1452                 if (netif_msg_ifup(tp))
  1443                 if (netif_msg_ifup(tp))
  1453                 {
  1444                 {
  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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  1888 	tp->cur_tx++;
  1879 	tp->cur_tx++;
  1889 	wmb();
  1880 	wmb();
  1890 
  1881 
  1891 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1882 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1892 
  1883 
  1893 	if (!ecdev_is_ec(rtl_ec_dev, dev))
  1884 	if (dev != rtl_ec_net_dev)
  1894         {
  1885         {
  1895                 if ((tp->cur_tx - NUM_TX_DESC) == tp->dirty_tx)
  1886                 if ((tp->cur_tx - NUM_TX_DESC) == tp->dirty_tx)
  1896                         netif_stop_queue (dev);
  1887                         netif_stop_queue (dev);
  1897 
  1888 
  1898                 spin_unlock_irq(&tp->lock);
  1889                 spin_unlock_irq(&tp->lock);
  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 */
  1979 		tp->dirty_tx = dirty_tx;
  1970 		tp->dirty_tx = dirty_tx;
  1980 		mb();
  1971 		mb();
  1981 
  1972 
  1982                 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1973                 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1983 
  1974 
  1984 		if (!ecdev_is_ec(rtl_ec_dev, dev))
  1975 		if (dev != rtl_ec_net_dev)
  1985                 {
  1976                 {
  1986                         netif_wake_queue (dev);
  1977                         netif_wake_queue (dev);
  1987                 }
  1978                 }
  1988 
  1979 
  1989                 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  1980                 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2191 			goto out;
  2182 			goto out;
  2192 		}
  2183 		}
  2193 
  2184 
  2194                 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2185                 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2195 
  2186 
  2196                 if (!ecdev_is_ec(rtl_ec_dev, dev))
  2187                 if (dev != rtl_ec_net_dev)
  2197                 {
  2188                 {
  2198                         /* Malloc up new buffer, compatible with net-2e. */
  2189                         /* Malloc up new buffer, compatible with net-2e. */
  2199                         /* Omit the four octet CRC from the length. */
  2190                         /* Omit the four octet CRC from the length. */
  2200                         skb = dev_alloc_skb(pkt_size + 2);
  2191                         skb = dev_alloc_skb(pkt_size + 2);
  2201 
  2192 
  2354 	int link_changed = 0; /* avoid bogus "uninit" warning */
  2345 	int link_changed = 0; /* avoid bogus "uninit" warning */
  2355 	int handled = 0;
  2346 	int handled = 0;
  2356 
  2347 
  2357         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2348         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2358 
  2349 
  2359 	if (ecdev_is_ec(rtl_ec_dev, dev))
  2350 	if (dev == rtl_ec_net_dev)
  2360         {
  2351         {
  2361                 status = RTL_R16 (IntrStatus);
  2352                 status = RTL_R16 (IntrStatus);
  2362 	}
  2353 	}
  2363 	else
  2354 	else
  2364         {
  2355         {
  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);
  2436 			RTL_W16 (IntrStatus, TxErr);
  2427 			RTL_W16 (IntrStatus, TxErr);
  2437 	}
  2428 	}
  2438  out:
  2429  out:
  2439         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2430         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2440 
  2431 
  2441 	if (!ecdev_is_ec(rtl_ec_dev, dev))
  2432 	if (dev != rtl_ec_net_dev)
  2442         {
  2433         {
  2443           spin_unlock (&tp->lock);
  2434           spin_unlock (&tp->lock);
  2444         }
  2435         }
  2445 
  2436 
  2446         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2437         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2470 	int ret = 0;
  2461 	int ret = 0;
  2471 	unsigned long flags;
  2462 	unsigned long flags;
  2472 
  2463 
  2473         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2464         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2474 
  2465 
  2475         if (!ecdev_is_ec(rtl_ec_dev, dev))
  2466         if (dev != rtl_ec_net_dev)
  2476         {
  2467         {
  2477                 netif_stop_queue(dev);
  2468                 netif_stop_queue(dev);
  2478                 if (tp->thr_pid >= 0) {
  2469                 if (tp->thr_pid >= 0) {
  2479                         tp->time_to_die = 1;
  2470                         tp->time_to_die = 1;
  2480                         wmb();
  2471                         wmb();
  2735 	struct rtl8139_private *np = netdev_priv(dev);
  2726 	struct rtl8139_private *np = netdev_priv(dev);
  2736 	int rc;
  2727 	int rc;
  2737 
  2728 
  2738         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2729         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2739 
  2730 
  2740 	if (ecdev_is_ec(rtl_ec_dev, dev) || !netif_running(dev))
  2731 	if (dev == rtl_ec_net_dev || !netif_running(dev))
  2741 		return -EINVAL;
  2732 		return -EINVAL;
  2742 
  2733 
  2743         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2734         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2744 
  2735 
  2745 	spin_lock_irq(&np->lock);
  2736 	spin_lock_irq(&np->lock);
  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);
  2843 
  2834 
  2844 	pci_save_state (pdev);
  2835 	pci_save_state (pdev);
  2845 
  2836 
  2846         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2837         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2847 
  2838 
  2848 	if (ecdev_is_ec(rtl_ec_dev, dev) || !netif_running (dev))
  2839 	if (dev == rtl_ec_net_dev || !netif_running (dev))
  2849                 return 0;
  2840                 return 0;
  2850 
  2841 
  2851         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2842         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2852 
  2843 
  2853 	netif_device_detach (dev);
  2844 	netif_device_detach (dev);
  2876 
  2867 
  2877 	pci_restore_state (pdev);
  2868 	pci_restore_state (pdev);
  2878 
  2869 
  2879         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2870         /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2880 
  2871 
  2881 	if (ecdev_is_ec(rtl_ec_dev, dev) || !netif_running (dev))
  2872 	if (dev == rtl_ec_net_dev || !netif_running (dev))
  2882                 return 0;
  2873                 return 0;
  2883 
  2874 
  2884         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2875         /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  2885 
  2876 
  2886 	pci_set_power_state (pdev, PCI_D0);
  2877 	pci_set_power_state (pdev, PCI_D0);
  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 }