devices/8139too-2.6.19-ethercat.c
branchstable-1.3
changeset 1744 7bc131b92039
parent 1739 5fcbd29151d2
equal deleted inserted replaced
1743:1a7067207637 1744:7bc131b92039
   150 #include <linux/crc32.h>
   150 #include <linux/crc32.h>
   151 #include <asm/io.h>
   151 #include <asm/io.h>
   152 #include <asm/uaccess.h>
   152 #include <asm/uaccess.h>
   153 #include <asm/irq.h>
   153 #include <asm/irq.h>
   154 
   154 
   155 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
       
   156 
       
   157 #include "../globals.h"
   155 #include "../globals.h"
   158 #include "ecdev.h"
   156 #include "ecdev.h"
   159 
   157 
   160 #define RTL8139_DRIVER_NAME DRV_NAME \
   158 #define RTL8139_DRIVER_NAME DRV_NAME \
   161                             " EtherCAT-capable Fast Ethernet driver " \
   159                             " EtherCAT-capable Fast Ethernet driver " \
   162                             DRV_VERSION ", master " EC_MASTER_VERSION
   160                             DRV_VERSION ", master " EC_MASTER_VERSION
   163 
       
   164 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
   165 
   161 
   166 #define PFX DRV_NAME ": "
   162 #define PFX DRV_NAME ": "
   167 
   163 
   168 /* Default Message level */
   164 /* Default Message level */
   169 #define RTL8139_DEF_MSG_ENABLE   (NETIF_MSG_DRV   | \
   165 #define RTL8139_DEF_MSG_ENABLE   (NETIF_MSG_DRV   | \
   211    The RTL chips use a 64 element hash table based on the Ethernet CRC.  */
   207    The RTL chips use a 64 element hash table based on the Ethernet CRC.  */
   212 static int multicast_filter_limit = 32;
   208 static int multicast_filter_limit = 32;
   213 
   209 
   214 /* bitmapped message enable number */
   210 /* bitmapped message enable number */
   215 static int debug = -1;
   211 static int debug = -1;
   216 
       
   217 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
       
   218 
       
   219 static int ec_device_index = -1;
       
   220 static int ec_device_master_index = 0;
       
   221 static ec_device_t *rtl_ec_dev;
       
   222 struct net_device *rtl_ec_net_dev = NULL;
       
   223 
       
   224 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
   225 
   212 
   226 /*
   213 /*
   227  * Receive ring size
   214  * Receive ring size
   228  * Warning: 64K ring has hardware issues and may lock up.
   215  * Warning: 64K ring has hardware issues and may lock up.
   229  */
   216  */
   335 	{PCI_ANY_ID, 0x8139, 0x13d1, 0xab06, 0, 0, RTL8139 },
   322 	{PCI_ANY_ID, 0x8139, 0x13d1, 0xab06, 0, 0, RTL8139 },
   336 
   323 
   337 	{0,}
   324 	{0,}
   338 };
   325 };
   339 
   326 
   340 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
       
   341 
       
   342 /* prevent driver from being loaded automatically */
   327 /* prevent driver from being loaded automatically */
   343 //MODULE_DEVICE_TABLE (pci, rtl8139_pci_tbl);
   328 //MODULE_DEVICE_TABLE (pci, rtl8139_pci_tbl);
   344 
       
   345 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
   346 
   329 
   347 static struct {
   330 static struct {
   348 	const char str[ETH_GSTRING_LEN];
   331 	const char str[ETH_GSTRING_LEN];
   349 } ethtool_stats_keys[] = {
   332 } ethtool_stats_keys[] = {
   350 	{ "early_rx" },
   333 	{ "early_rx" },
   663 	struct work_struct thread;
   646 	struct work_struct thread;
   664 
   647 
   665 	struct mii_if_info mii;
   648 	struct mii_if_info mii;
   666 	unsigned int regs_len;
   649 	unsigned int regs_len;
   667 	unsigned long fifo_copy_timeout;
   650 	unsigned long fifo_copy_timeout;
       
   651     
       
   652 	ec_device_t *ecdev;
   668 };
   653 };
   669 
       
   670 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
       
   671 
   654 
   672 MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>");
   655 MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>");
   673 MODULE_DESCRIPTION("RealTek RTL-8139 EtherCAT driver");
   656 MODULE_DESCRIPTION("RealTek RTL-8139 EtherCAT driver");
   674 MODULE_LICENSE("GPL");
   657 MODULE_LICENSE("GPL");
   675 MODULE_VERSION(EC_MASTER_VERSION);
   658 MODULE_VERSION(EC_MASTER_VERSION);
   676 
       
   677 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
   678 
   659 
   679 module_param(multicast_filter_limit, int, 0);
   660 module_param(multicast_filter_limit, int, 0);
   680 module_param_array(media, int, NULL, 0);
   661 module_param_array(media, int, NULL, 0);
   681 module_param_array(full_duplex, int, NULL, 0);
   662 module_param_array(full_duplex, int, NULL, 0);
   682 module_param(debug, int, 0);
   663 module_param(debug, int, 0);
   683 MODULE_PARM_DESC (debug, "8139too bitmapped message enable number");
   664 MODULE_PARM_DESC (debug, "8139too bitmapped message enable number");
   684 MODULE_PARM_DESC (multicast_filter_limit, "8139too maximum number of filtered multicast addresses");
   665 MODULE_PARM_DESC (multicast_filter_limit, "8139too maximum number of filtered multicast addresses");
   685 MODULE_PARM_DESC (media, "8139too: Bits 4+9: force full duplex, bit 5: 100Mbps");
   666 MODULE_PARM_DESC (media, "8139too: Bits 4+9: force full duplex, bit 5: 100Mbps");
   686 MODULE_PARM_DESC (full_duplex, "8139too: Force full duplex for board(s) (1)");
   667 MODULE_PARM_DESC (full_duplex, "8139too: Force full duplex for board(s) (1)");
   687 
   668 
   688 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
       
   689 
       
   690 module_param(ec_device_index, int, -1);
       
   691 module_param(ec_device_master_index, int, 0);
       
   692 MODULE_PARM_DESC(ec_device_index,
       
   693                  "Index of the device reserved for EtherCAT.");
       
   694 MODULE_PARM_DESC(ec_device_master_index,
       
   695                  "Index of the EtherCAT master to register the device.");
       
   696 
       
   697 void ec_poll(struct net_device *);
   669 void ec_poll(struct net_device *);
   698 
       
   699 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
   700 
   670 
   701 static int read_eeprom (void __iomem *ioaddr, int location, int addr_len);
   671 static int read_eeprom (void __iomem *ioaddr, int location, int addr_len);
   702 static int rtl8139_open (struct net_device *dev);
   672 static int rtl8139_open (struct net_device *dev);
   703 static int mdio_read (struct net_device *dev, int phy_id, int location);
   673 static int mdio_read (struct net_device *dev, int phy_id, int location);
   704 static void mdio_write (struct net_device *dev, int phy_id, int location,
   674 static void mdio_write (struct net_device *dev, int phy_id, int location,
  1048 		return i;
  1018 		return i;
  1049 
  1019 
  1050 	assert (dev != NULL);
  1020 	assert (dev != NULL);
  1051 	tp = netdev_priv(dev);
  1021 	tp = netdev_priv(dev);
  1052 
  1022 
  1053 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
       
  1054 
       
  1055 	if (board_idx == ec_device_index) {
       
  1056 		rtl_ec_net_dev = dev;
       
  1057 		strcpy(dev->name, "ec0");
       
  1058 	}
       
  1059 
       
  1060 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  1061 
       
  1062 	ioaddr = tp->mmio_addr;
  1023 	ioaddr = tp->mmio_addr;
  1063 	assert (ioaddr != NULL);
  1024 	assert (ioaddr != NULL);
  1064 
  1025 
  1065 	addr_len = read_eeprom (ioaddr, 0, 8) == 0x8129 ? 8 : 6;
  1026 	addr_len = read_eeprom (ioaddr, 0, 8) == 0x8129 ? 8 : 6;
  1066 	for (i = 0; i < 3; i++)
  1027 	for (i = 0; i < 3; i++)
  1108 	tp->mii.mdio_write = mdio_write;
  1069 	tp->mii.mdio_write = mdio_write;
  1109 	tp->mii.phy_id_mask = 0x3f;
  1070 	tp->mii.phy_id_mask = 0x3f;
  1110 	tp->mii.reg_num_mask = 0x1f;
  1071 	tp->mii.reg_num_mask = 0x1f;
  1111 
  1072 
  1112 	/* dev is fully set up and ready to use now */
  1073 	/* dev is fully set up and ready to use now */
  1113 
  1074     
  1114 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1075 	// offer device to EtherCAT master module
  1115 
  1076 	if (ecdev_offer(dev, ec_poll, THIS_MODULE, &tp->ecdev)) {
  1116 	if (dev != rtl_ec_net_dev) {
  1077 		printk(KERN_ERR PFX "Failed to offer device.\n");
       
  1078 		goto err_out;
       
  1079 	}
       
  1080 
       
  1081 	if (!tp->ecdev) {
  1117 		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);
  1118 		i = register_netdev (dev);
  1083 		i = register_netdev (dev);
  1119 		if (i) goto err_out;
  1084 		if (i) goto err_out;
  1120 	}
  1085 	}
  1121 
       
  1122 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  1123 
  1086 
  1124 	pci_set_drvdata (pdev, dev);
  1087 	pci_set_drvdata (pdev, dev);
  1125 
  1088 
  1126 	printk (KERN_INFO "%s: %s at 0x%lx, "
  1089 	printk (KERN_INFO "%s: %s at 0x%lx, "
  1127 		"%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x, "
  1090 		"%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x, "
  1191 
  1154 
  1192 	/* Put the chip into low-power mode. */
  1155 	/* Put the chip into low-power mode. */
  1193 	if (rtl_chip_info[tp->chipset].flags & HasHltClk)
  1156 	if (rtl_chip_info[tp->chipset].flags & HasHltClk)
  1194 		RTL_W8 (HltClk, 'H');	/* 'R' would leave the clock running. */
  1157 		RTL_W8 (HltClk, 'H');	/* 'R' would leave the clock running. */
  1195 
  1158 
       
  1159 	if (tp->ecdev && ecdev_open(tp->ecdev)) {
       
  1160 		ecdev_withdraw(tp->ecdev);
       
  1161 		goto err_out;
       
  1162 	}
       
  1163 
  1196 	return 0;
  1164 	return 0;
  1197 
  1165 
  1198 err_out:
  1166 err_out:
  1199 	__rtl8139_cleanup_dev (dev);
  1167 	__rtl8139_cleanup_dev (dev);
  1200 	pci_disable_device (pdev);
  1168 	pci_disable_device (pdev);
  1203 
  1171 
  1204 
  1172 
  1205 static void __devexit rtl8139_remove_one (struct pci_dev *pdev)
  1173 static void __devexit rtl8139_remove_one (struct pci_dev *pdev)
  1206 {
  1174 {
  1207 	struct net_device *dev = pci_get_drvdata (pdev);
  1175 	struct net_device *dev = pci_get_drvdata (pdev);
       
  1176 	struct rtl8139_private *tp = netdev_priv(dev);
  1208 
  1177 
  1209 	assert (dev != NULL);
  1178 	assert (dev != NULL);
  1210 
  1179 
  1211 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1180 	if (tp->ecdev) {
  1212 
  1181 		ecdev_close(tp->ecdev);
  1213 	if (dev != rtl_ec_net_dev) {
  1182 		ecdev_withdraw(tp->ecdev);
       
  1183 	}
       
  1184 	else {
  1214 		unregister_netdev (dev);
  1185 		unregister_netdev (dev);
  1215 	}
  1186 	}
  1216 
       
  1217 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  1218 
  1187 
  1219 	__rtl8139_cleanup_dev (dev);
  1188 	__rtl8139_cleanup_dev (dev);
  1220 	pci_disable_device (pdev);
  1189 	pci_disable_device (pdev);
  1221 }
  1190 }
  1222 
  1191 
  1414 {
  1383 {
  1415 	struct rtl8139_private *tp = netdev_priv(dev);
  1384 	struct rtl8139_private *tp = netdev_priv(dev);
  1416 	int retval;
  1385 	int retval;
  1417 	void __iomem *ioaddr = tp->mmio_addr;
  1386 	void __iomem *ioaddr = tp->mmio_addr;
  1418 
  1387 
  1419 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1388 	if (!tp->ecdev) {
  1420 
       
  1421 	if (dev != rtl_ec_net_dev) {
       
  1422 		retval = request_irq(dev->irq, rtl8139_interrupt,
  1389 		retval = request_irq(dev->irq, rtl8139_interrupt,
  1423 			IRQF_SHARED, dev->name, dev);
  1390 			IRQF_SHARED, dev->name, dev);
  1424 		if (retval)
  1391 		if (retval)
  1425 			return retval;
  1392 			return retval;
  1426 	}
  1393 	}
  1427 
       
  1428 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  1429 
  1394 
  1430 	tp->tx_bufs = pci_alloc_consistent(tp->pci_dev, TX_BUF_TOT_LEN,
  1395 	tp->tx_bufs = pci_alloc_consistent(tp->pci_dev, TX_BUF_TOT_LEN,
  1431 					   &tp->tx_bufs_dma);
  1396 					   &tp->tx_bufs_dma);
  1432 	tp->rx_ring = pci_alloc_consistent(tp->pci_dev, RX_BUF_TOT_LEN,
  1397 	tp->rx_ring = pci_alloc_consistent(tp->pci_dev, RX_BUF_TOT_LEN,
  1433 					   &tp->rx_ring_dma);
  1398 					   &tp->rx_ring_dma);
  1434 	if (tp->tx_bufs == NULL || tp->rx_ring == NULL) {
  1399 	if (tp->tx_bufs == NULL || tp->rx_ring == NULL) {
  1435 		/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1400 		if (!tp->ecdev) free_irq(dev->irq, dev);
  1436 
       
  1437 		if (dev != rtl_ec_net_dev) {
       
  1438 			free_irq(dev->irq, dev);
       
  1439 		}
       
  1440 
       
  1441 		/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  1442 
  1401 
  1443 		if (tp->tx_bufs)
  1402 		if (tp->tx_bufs)
  1444 			pci_free_consistent(tp->pci_dev, TX_BUF_TOT_LEN,
  1403 			pci_free_consistent(tp->pci_dev, TX_BUF_TOT_LEN,
  1445 					    tp->tx_bufs, tp->tx_bufs_dma);
  1404 					    tp->tx_bufs, tp->tx_bufs_dma);
  1446 		if (tp->rx_ring)
  1405 		if (tp->rx_ring)
  1455 	tp->tx_flag = (TX_FIFO_THRESH << 11) & 0x003f0000;
  1414 	tp->tx_flag = (TX_FIFO_THRESH << 11) & 0x003f0000;
  1456 
  1415 
  1457 	rtl8139_init_ring (dev);
  1416 	rtl8139_init_ring (dev);
  1458 	rtl8139_hw_start (dev);
  1417 	rtl8139_hw_start (dev);
  1459 
  1418 
  1460 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1419 	if (!tp->ecdev) {
  1461 
       
  1462 	if (dev != rtl_ec_net_dev) {
       
  1463 		netif_start_queue (dev);
  1420 		netif_start_queue (dev);
  1464 
  1421 
  1465 		if (netif_msg_ifup(tp))
  1422 		if (netif_msg_ifup(tp))
  1466 			printk(KERN_DEBUG "%s: rtl8139_open() ioaddr %#llx IRQ %d"
  1423 			printk(KERN_DEBUG "%s: rtl8139_open() ioaddr %#llx IRQ %d"
  1467 					" GP Pins %2.2x %s-duplex.\n", dev->name,
  1424 					" GP Pins %2.2x %s-duplex.\n", dev->name,
  1469 					dev->irq, RTL_R8 (MediaStatus),
  1426 					dev->irq, RTL_R8 (MediaStatus),
  1470 					tp->mii.full_duplex ? "full" : "half");
  1427 					tp->mii.full_duplex ? "full" : "half");
  1471 		rtl8139_start_thread(tp);
  1428 		rtl8139_start_thread(tp);
  1472 	}
  1429 	}
  1473 
  1430 
  1474 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  1475 
       
  1476 	return 0;
  1431 	return 0;
  1477 }
  1432 }
  1478 
  1433 
  1479 
  1434 
  1480 static void rtl_check_media (struct net_device *dev, unsigned int init_media)
  1435 static void rtl_check_media (struct net_device *dev, unsigned int init_media)
  1481 {
  1436 {
  1482 	struct rtl8139_private *tp = netdev_priv(dev);
  1437 	struct rtl8139_private *tp = netdev_priv(dev);
  1483 
  1438 
  1484 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1439 	if (tp->ecdev) {
  1485 
  1440 		void __iomem *ioaddr = tp->mmio_addr;
  1486 	if (dev != rtl_ec_net_dev) {
  1441 		uint16_t state = RTL_R16(BasicModeStatus) & BMSR_LSTATUS;
       
  1442 		ecdev_set_link(tp->ecdev, state ? 1 : 0);
       
  1443 	}
       
  1444 	else {
  1487 		if (tp->phys[0] >= 0) {
  1445 		if (tp->phys[0] >= 0) {
  1488 			mii_check_media(&tp->mii, netif_msg_link(tp), init_media);
  1446 			mii_check_media(&tp->mii, netif_msg_link(tp), init_media);
  1489 		}
  1447 		}
  1490 	} else {
  1448 	}
  1491 		void __iomem *ioaddr = tp->mmio_addr;
       
  1492 		uint16_t state = RTL_R16(BasicModeStatus) & BMSR_LSTATUS;
       
  1493 		ecdev_link_state(rtl_ec_dev, state ? 1 : 0);
       
  1494 	}
       
  1495 
       
  1496 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  1497 }
  1449 }
  1498 
  1450 
  1499 /* Start the hardware at open or resume. */
  1451 /* Start the hardware at open or resume. */
  1500 static void rtl8139_hw_start (struct net_device *dev)
  1452 static void rtl8139_hw_start (struct net_device *dev)
  1501 {
  1453 {
  1556 	/* make sure RxTx has started */
  1508 	/* make sure RxTx has started */
  1557 	tmp = RTL_R8 (ChipCmd);
  1509 	tmp = RTL_R8 (ChipCmd);
  1558 	if ((!(tmp & CmdRxEnb)) || (!(tmp & CmdTxEnb)))
  1510 	if ((!(tmp & CmdRxEnb)) || (!(tmp & CmdTxEnb)))
  1559 		RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb);
  1511 		RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb);
  1560 
  1512 
  1561 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1513 	if (!tp->ecdev)
  1562 
       
  1563 	if (dev != rtl_ec_net_dev) {
       
  1564 		/* Enable all known interrupts by setting the interrupt mask. */
  1514 		/* Enable all known interrupts by setting the interrupt mask. */
  1565 		RTL_W16 (IntrMask, rtl8139_intr_mask);
  1515 		RTL_W16 (IntrMask, rtl8139_intr_mask);
  1566 	}
       
  1567 
       
  1568 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  1569 }
  1516 }
  1570 
  1517 
  1571 
  1518 
  1572 /* Initialize the Rx and Tx rings, along with various 'dev' bits. */
  1519 /* Initialize the Rx and Tx rings, along with various 'dev' bits. */
  1573 static void rtl8139_init_ring (struct net_device *dev)
  1520 static void rtl8139_init_ring (struct net_device *dev)
  1811 	/* disable Tx ASAP, if not already */
  1758 	/* disable Tx ASAP, if not already */
  1812 	tmp8 = RTL_R8 (ChipCmd);
  1759 	tmp8 = RTL_R8 (ChipCmd);
  1813 	if (tmp8 & CmdTxEnb)
  1760 	if (tmp8 & CmdTxEnb)
  1814 		RTL_W8 (ChipCmd, CmdRxEnb);
  1761 		RTL_W8 (ChipCmd, CmdRxEnb);
  1815 
  1762 
  1816 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1763 	if (tp->ecdev) {
  1817 
  1764 		rtl8139_tx_clear (tp);
  1818 	if (dev != rtl_ec_net_dev) {
  1765 		rtl8139_hw_start (dev);
       
  1766 	}
       
  1767 	else {
  1819 		spin_lock_bh(&tp->rx_lock);
  1768 		spin_lock_bh(&tp->rx_lock);
  1820 		/* Disable interrupts by clearing the interrupt mask. */
  1769 		/* Disable interrupts by clearing the interrupt mask. */
  1821 		RTL_W16 (IntrMask, 0x0000);
  1770 		RTL_W16 (IntrMask, 0x0000);
  1822 
  1771 
  1823 		/* Stop a shared interrupt from scavenging while we are. */
  1772 		/* Stop a shared interrupt from scavenging while we are. */
  1829 		if (netif_running(dev)) {
  1778 		if (netif_running(dev)) {
  1830 			rtl8139_hw_start (dev);
  1779 			rtl8139_hw_start (dev);
  1831 			netif_wake_queue (dev);
  1780 			netif_wake_queue (dev);
  1832 		}
  1781 		}
  1833 		spin_unlock_bh(&tp->rx_lock);
  1782 		spin_unlock_bh(&tp->rx_lock);
  1834 	} else {
  1783 	}
  1835 		rtl8139_tx_clear (tp);
       
  1836 		rtl8139_hw_start (dev);
       
  1837 	}
       
  1838 
       
  1839 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  1840 }
  1784 }
  1841 
  1785 
  1842 static void rtl8139_tx_timeout (struct net_device *dev)
  1786 static void rtl8139_tx_timeout (struct net_device *dev)
  1843 {
  1787 {
  1844 	struct rtl8139_private *tp = netdev_priv(dev);
  1788 	struct rtl8139_private *tp = netdev_priv(dev);
  1845 
  1789 
  1846 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1790 	if (!tp->ecdev && !tp->have_thread) {
  1847 
       
  1848 	if (dev != rtl_ec_net_dev && !tp->have_thread) {
       
  1849 		INIT_WORK(&tp->thread, rtl8139_tx_timeout_task, dev);
  1791 		INIT_WORK(&tp->thread, rtl8139_tx_timeout_task, dev);
  1850 		schedule_delayed_work(&tp->thread, next_tick);
  1792 		schedule_delayed_work(&tp->thread, next_tick);
  1851 	} else
  1793 	} else
  1852 		tp->watchdog_fired = 1;
  1794 		tp->watchdog_fired = 1;
  1853 
  1795 
  1854 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  1855 }
  1796 }
  1856 
  1797 
  1857 static int rtl8139_start_xmit (struct sk_buff *skb, struct net_device *dev)
  1798 static int rtl8139_start_xmit (struct sk_buff *skb, struct net_device *dev)
  1858 {
  1799 {
  1859 	struct rtl8139_private *tp = netdev_priv(dev);
  1800 	struct rtl8139_private *tp = netdev_priv(dev);
  1863 	unsigned long flags;
  1804 	unsigned long flags;
  1864 
  1805 
  1865 	/* Calculate the next Tx descriptor entry. */
  1806 	/* Calculate the next Tx descriptor entry. */
  1866 	entry = tp->cur_tx % NUM_TX_DESC;
  1807 	entry = tp->cur_tx % NUM_TX_DESC;
  1867 
  1808 
  1868 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
       
  1869 
       
  1870 	/* Note: the chip doesn't have auto-pad! */
  1809 	/* Note: the chip doesn't have auto-pad! */
  1871 	if (likely(len < TX_BUF_SIZE)) {
  1810 	if (likely(len < TX_BUF_SIZE)) {
  1872 		if (len < ETH_ZLEN)
  1811 		if (len < ETH_ZLEN)
  1873 			memset(tp->tx_buf[entry], 0, ETH_ZLEN);
  1812 			memset(tp->tx_buf[entry], 0, ETH_ZLEN);
  1874 		skb_copy_and_csum_dev(skb, tp->tx_buf[entry]);
  1813 		skb_copy_and_csum_dev(skb, tp->tx_buf[entry]);
  1875 		if (dev != rtl_ec_net_dev) {
  1814 		if (!tp->ecdev) dev_kfree_skb(skb);
  1876 			dev_kfree_skb(skb);
       
  1877 		}
       
  1878 	} else {
  1815 	} else {
  1879 		if (dev != rtl_ec_net_dev) {
  1816 		if (!tp->ecdev) dev_kfree_skb(skb);
  1880 			dev_kfree_skb(skb);
       
  1881 		}
       
  1882 		tp->stats.tx_dropped++;
  1817 		tp->stats.tx_dropped++;
  1883 		return 0;
  1818 		return 0;
  1884 	}
  1819 	}
  1885 
  1820 
  1886 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  1821 	if (tp->ecdev) {
  1887 
  1822 		RTL_W32_F (TxStatus0 + (entry * sizeof (u32)),
  1888 	if (dev != rtl_ec_net_dev) {
  1823 				tp->tx_flag | max(len, (unsigned int)ETH_ZLEN));
       
  1824 
       
  1825 		dev->trans_start = jiffies;
       
  1826 
       
  1827 		tp->cur_tx++;
       
  1828 		wmb();
       
  1829 	}
       
  1830 	else {
  1889 		spin_lock_irqsave(&tp->lock, flags);
  1831 		spin_lock_irqsave(&tp->lock, flags);
  1890 
  1832 
  1891 		RTL_W32_F (TxStatus0 + (entry * sizeof (u32)),
  1833 		RTL_W32_F (TxStatus0 + (entry * sizeof (u32)),
  1892 				tp->tx_flag | max(len, (unsigned int)ETH_ZLEN));
  1834 				tp->tx_flag | max(len, (unsigned int)ETH_ZLEN));
  1893 
  1835 
  1902 
  1844 
  1903 		if (netif_msg_tx_queued(tp))
  1845 		if (netif_msg_tx_queued(tp))
  1904 			printk (KERN_DEBUG "%s: Queued Tx packet size %u to slot %d.\n",
  1846 			printk (KERN_DEBUG "%s: Queued Tx packet size %u to slot %d.\n",
  1905 					dev->name, len, entry);
  1847 					dev->name, len, entry);
  1906 	}
  1848 	}
  1907 	else {
       
  1908 		RTL_W32_F (TxStatus0 + (entry * sizeof (u32)),
       
  1909 				tp->tx_flag | max(len, (unsigned int)ETH_ZLEN));
       
  1910 
       
  1911 		dev->trans_start = jiffies;
       
  1912 
       
  1913 		tp->cur_tx++;
       
  1914 		wmb();
       
  1915 	}
       
  1916 
       
  1917 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  1918 
  1849 
  1919 	return 0;
  1850 	return 0;
  1920 }
  1851 }
  1921 
  1852 
  1922 
  1853 
  1971 
  1902 
  1972 		dirty_tx++;
  1903 		dirty_tx++;
  1973 		tx_left--;
  1904 		tx_left--;
  1974 	}
  1905 	}
  1975 
  1906 
  1976 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
       
  1977 
       
  1978 #ifndef RTL8139_NDEBUG
  1907 #ifndef RTL8139_NDEBUG
  1979 	if (dev != rtl_ec_net_dev && tp->cur_tx - dirty_tx > NUM_TX_DESC) {
  1908 	if (!tp->ecdev && tp->cur_tx - dirty_tx > NUM_TX_DESC) {
  1980 		printk (KERN_ERR "%s: Out-of-sync dirty pointer, %ld vs. %ld.\n",
  1909 		printk (KERN_ERR "%s: Out-of-sync dirty pointer, %ld vs. %ld.\n",
  1981 		        dev->name, dirty_tx, tp->cur_tx);
  1910 		        dev->name, dirty_tx, tp->cur_tx);
  1982 		dirty_tx += NUM_TX_DESC;
  1911 		dirty_tx += NUM_TX_DESC;
  1983 	}
  1912 	}
  1984 #endif /* RTL8139_NDEBUG */
  1913 #endif /* RTL8139_NDEBUG */
  1985 
  1914 
  1986 	/* only wake the queue if we did work, and the queue is stopped */
  1915 	/* only wake the queue if we did work, and the queue is stopped */
  1987 	if (tp->dirty_tx != dirty_tx) {
  1916 	if (tp->dirty_tx != dirty_tx) {
  1988 		tp->dirty_tx = dirty_tx;
  1917 		tp->dirty_tx = dirty_tx;
  1989 		mb();
  1918 		mb();
  1990 
  1919 		if (!tp->ecdev) netif_wake_queue (dev);
  1991 		if (dev != rtl_ec_net_dev) {
  1920 	}
  1992 			netif_wake_queue (dev);
       
  1993 		}
       
  1994 	}
       
  1995 
       
  1996 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  1997 }
  1921 }
  1998 
  1922 
  1999 
  1923 
  2000 /* TODO: clean this up!  Rx reset need not be this intensive */
  1924 /* TODO: clean this up!  Rx reset need not be this intensive */
  2001 static void rtl8139_rx_err (u32 rx_status, struct net_device *dev,
  1925 static void rtl8139_rx_err (u32 rx_status, struct net_device *dev,
  2124 	DPRINTK ("%s: In rtl8139_rx(), current %4.4x BufAddr %4.4x,"
  2048 	DPRINTK ("%s: In rtl8139_rx(), current %4.4x BufAddr %4.4x,"
  2125 		 " free to %4.4x, Cmd %2.2x.\n", dev->name, (u16)cur_rx,
  2049 		 " free to %4.4x, Cmd %2.2x.\n", dev->name, (u16)cur_rx,
  2126 		 RTL_R16 (RxBufAddr),
  2050 		 RTL_R16 (RxBufAddr),
  2127 		 RTL_R16 (RxBufPtr), RTL_R8 (ChipCmd));
  2051 		 RTL_R16 (RxBufPtr), RTL_R8 (ChipCmd));
  2128 
  2052 
  2129 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2053 	while ((tp->ecdev || netif_running(dev))
  2130 
       
  2131 	while ((dev == rtl_ec_net_dev || netif_running(dev))
       
  2132 			&& received < budget
  2054 			&& received < budget
  2133 			&& (RTL_R8 (ChipCmd) & RxBufEmpty) == 0) {
  2055 			&& (RTL_R8 (ChipCmd) & RxBufEmpty) == 0) {
  2134 
       
  2135 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2136 
       
  2137 		u32 ring_offset = cur_rx % RX_BUF_LEN;
  2056 		u32 ring_offset = cur_rx % RX_BUF_LEN;
  2138 		u32 rx_status;
  2057 		u32 rx_status;
  2139 		unsigned int pkt_size;
  2058 		unsigned int pkt_size;
  2140 		struct sk_buff *skb;
  2059 		struct sk_buff *skb;
  2141 
  2060 
  2144 		/* read size+status of next frame from DMA ring buffer */
  2063 		/* read size+status of next frame from DMA ring buffer */
  2145 		rx_status = le32_to_cpu (*(u32 *) (rx_ring + ring_offset));
  2064 		rx_status = le32_to_cpu (*(u32 *) (rx_ring + ring_offset));
  2146 		rx_size = rx_status >> 16;
  2065 		rx_size = rx_status >> 16;
  2147 		pkt_size = rx_size - 4;
  2066 		pkt_size = rx_size - 4;
  2148 
  2067 
  2149 		/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2068 		if (!tp->ecdev) {
  2150 
       
  2151 		if (dev != rtl_ec_net_dev) {
       
  2152 			if (netif_msg_rx_status(tp))
  2069 			if (netif_msg_rx_status(tp))
  2153 				printk(KERN_DEBUG "%s:  rtl8139_rx() status %4.4x, size %4.4x,"
  2070 				printk(KERN_DEBUG "%s:  rtl8139_rx() status %4.4x, size %4.4x,"
  2154 				       " cur %4.4x.\n", dev->name, rx_status,
  2071 				       " cur %4.4x.\n", dev->name, rx_status,
  2155 				       rx_size, cur_rx);
  2072 				       rx_size, cur_rx);
  2156 		}
  2073 		}
  2157 
       
  2158 		/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2159 
       
  2160 #if RTL8139_DEBUG > 2
  2074 #if RTL8139_DEBUG > 2
  2161 		{
  2075 		{
  2162 			int i;
  2076 			int i;
  2163 			DPRINTK ("%s: Frame contents ", dev->name);
  2077 			DPRINTK ("%s: Frame contents ", dev->name);
  2164 			for (i = 0; i < 70; i++)
  2078 			for (i = 0; i < 70; i++)
  2202 			rtl8139_rx_err (rx_status, dev, tp, ioaddr);
  2116 			rtl8139_rx_err (rx_status, dev, tp, ioaddr);
  2203 			received = -1;
  2117 			received = -1;
  2204 			goto out;
  2118 			goto out;
  2205 		}
  2119 		}
  2206 
  2120 
  2207 		/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2121 		if (tp->ecdev) {
  2208 
  2122 			ecdev_receive(tp->ecdev,
  2209 		if (dev != rtl_ec_net_dev) {
  2123 					&rx_ring[ring_offset + 4], pkt_size);
       
  2124 			dev->last_rx = jiffies;
       
  2125 			tp->stats.rx_bytes += pkt_size;
       
  2126 			tp->stats.rx_packets++;
       
  2127 		}
       
  2128 		else {
  2210 			/* Malloc up new buffer, compatible with net-2e. */
  2129 			/* Malloc up new buffer, compatible with net-2e. */
  2211 			/* Omit the four octet CRC from the length. */
  2130 			/* Omit the four octet CRC from the length. */
  2212 
  2131 
  2213 			skb = dev_alloc_skb (pkt_size + 2);
  2132 			skb = dev_alloc_skb (pkt_size + 2);
  2214 			if (likely(skb)) {
  2133 			if (likely(skb)) {
  2229 
  2148 
  2230 				netif_receive_skb (skb);
  2149 				netif_receive_skb (skb);
  2231 			} else {
  2150 			} else {
  2232 				if (net_ratelimit())
  2151 				if (net_ratelimit())
  2233 					printk(KERN_WARNING
  2152 					printk(KERN_WARNING
  2234 					       "%s: Memory squeeze, dropping packet.\n",
  2153 							"%s: Memory squeeze, dropping packet.\n",
  2235 					       dev->name);
  2154 							dev->name);
  2236 				tp->stats.rx_dropped++;
  2155 				tp->stats.rx_dropped++;
  2237 			}
  2156 			}
  2238 		} else {
       
  2239 			ecdev_receive(rtl_ec_dev,
       
  2240 			              &rx_ring[ring_offset + 4], pkt_size);
       
  2241 			dev->last_rx = jiffies;
       
  2242 			tp->stats.rx_bytes += pkt_size;
       
  2243 			tp->stats.rx_packets++;
       
  2244 		}
  2157 		}
  2245 
       
  2246 		/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2247 
       
  2248 		received++;
  2158 		received++;
  2249 
  2159 
  2250 		cur_rx = (cur_rx + rx_size + 4 + 3) & ~3;
  2160 		cur_rx = (cur_rx + rx_size + 4 + 3) & ~3;
  2251 		RTL_W16 (RxBufPtr, (u16) (cur_rx - 16));
  2161 		RTL_W16 (RxBufPtr, (u16) (cur_rx - 16));
  2252 
  2162 
  2348 	spin_unlock(&tp->rx_lock);
  2258 	spin_unlock(&tp->rx_lock);
  2349 
  2259 
  2350 	return !done;
  2260 	return !done;
  2351 }
  2261 }
  2352 
  2262 
  2353 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
       
  2354 
       
  2355 void ec_poll(struct net_device *dev)
  2263 void ec_poll(struct net_device *dev)
  2356 {
  2264 {
  2357     rtl8139_interrupt(0, dev);
  2265     rtl8139_interrupt(0, dev);
  2358 }
  2266 }
  2359 
       
  2360 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2361 
  2267 
  2362 /* The interrupt handler does all of the Rx thread work and cleans up
  2268 /* The interrupt handler does all of the Rx thread work and cleans up
  2363    after the Tx thread. */
  2269    after the Tx thread. */
  2364 static irqreturn_t rtl8139_interrupt (int irq, void *dev_instance)
  2270 static irqreturn_t rtl8139_interrupt (int irq, void *dev_instance)
  2365 {
  2271 {
  2368 	void __iomem *ioaddr = tp->mmio_addr;
  2274 	void __iomem *ioaddr = tp->mmio_addr;
  2369 	u16 status, ackstat;
  2275 	u16 status, ackstat;
  2370 	int link_changed = 0; /* avoid bogus "uninit" warning */
  2276 	int link_changed = 0; /* avoid bogus "uninit" warning */
  2371 	int handled = 0;
  2277 	int handled = 0;
  2372 
  2278 
  2373 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2279 	if (tp->ecdev) {
  2374 
  2280 		status = RTL_R16 (IntrStatus);
  2375 	if (dev != rtl_ec_net_dev) {
  2281 	}
       
  2282 	else {
  2376 		spin_lock (&tp->lock);
  2283 		spin_lock (&tp->lock);
  2377 		status = RTL_R16 (IntrStatus);
  2284 		status = RTL_R16 (IntrStatus);
  2378 
  2285 
  2379 		/* shared irq? */
  2286 		/* shared irq? */
  2380 		if (unlikely((status & rtl8139_intr_mask) == 0))
  2287 		if (unlikely((status & rtl8139_intr_mask) == 0))
  2381 			goto out;
  2288 			goto out;
  2382 	} else {
  2289 	}
  2383 		status = RTL_R16 (IntrStatus);
       
  2384 	}
       
  2385 
       
  2386 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2387 
  2290 
  2388 	handled = 1;
  2291 	handled = 1;
  2389 
  2292 
  2390 	/* h/w no longer present (hotplug?) or major error, bail */
  2293 	/* h/w no longer present (hotplug?) or major error, bail */
  2391 	if (unlikely(status == 0xFFFF))
  2294 	if (unlikely(status == 0xFFFF))
  2392 		goto out;
  2295 		goto out;
  2393 
  2296 
  2394 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2297 	if (!tp->ecdev) {
  2395 
       
  2396 	if (dev != rtl_ec_net_dev) {
       
  2397 		/* close possible race's with dev_close */
  2298 		/* close possible race's with dev_close */
  2398 		if (unlikely(!netif_running(dev))) {
  2299 		if (unlikely(!netif_running(dev))) {
  2399 			RTL_W16 (IntrMask, 0);
  2300 			RTL_W16 (IntrMask, 0);
  2400 			goto out;
  2301 			goto out;
  2401 		}
  2302 		}
  2402 	}
  2303 	}
  2403 
  2304 
  2404 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2405 
       
  2406 	/* Acknowledge all of the current interrupt sources ASAP, but
  2305 	/* Acknowledge all of the current interrupt sources ASAP, but
  2407 	   an first get an additional status bit from CSCR. */
  2306 	   an first get an additional status bit from CSCR. */
  2408 	if (unlikely(status & RxUnderrun))
  2307 	if (unlikely(status & RxUnderrun))
  2409 		link_changed = RTL_R16 (CSCR) & CSCR_LinkChangeBit;
  2308 		link_changed = RTL_R16 (CSCR) & CSCR_LinkChangeBit;
  2410 
  2309 
  2412 	if (ackstat)
  2311 	if (ackstat)
  2413 		RTL_W16 (IntrStatus, ackstat);
  2312 		RTL_W16 (IntrStatus, ackstat);
  2414 
  2313 
  2415 	/* Receive packets are processed by poll routine.
  2314 	/* Receive packets are processed by poll routine.
  2416 	   If not running start it now. */
  2315 	   If not running start it now. */
  2417 
       
  2418 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
       
  2419 
       
  2420 	if (status & RxAckBits){
  2316 	if (status & RxAckBits){
  2421 		if (dev != rtl_ec_net_dev) {
  2317 		if (tp->ecdev) {
       
  2318 			/* EtherCAT device: Just receive all frames */
       
  2319 			rtl8139_rx(dev, tp, 100); // FIXME
       
  2320 		}
       
  2321 		else {
  2422 			/* Mark for polling */
  2322 			/* Mark for polling */
  2423 			if (netif_rx_schedule_prep(dev)) {
  2323 			if (netif_rx_schedule_prep(dev)) {
  2424 				RTL_W16_F (IntrMask, rtl8139_norx_intr_mask);
  2324 				RTL_W16_F (IntrMask, rtl8139_norx_intr_mask);
  2425 				__netif_rx_schedule (dev);
  2325 				__netif_rx_schedule (dev);
  2426 			}
  2326 			}
  2427 		} else {
       
  2428 			/* EtherCAT device: Just receive all frames */
       
  2429 			rtl8139_rx(dev, tp, 100); // FIXME
       
  2430 		}
  2327 		}
  2431 	}
  2328 	}
  2432 
       
  2433 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2434 
  2329 
  2435 	/* Check uncommon events with one test. */
  2330 	/* Check uncommon events with one test. */
  2436 	if (unlikely(status & (PCIErr | PCSTimeout | RxUnderrun | RxErr)))
  2331 	if (unlikely(status & (PCIErr | PCSTimeout | RxUnderrun | RxErr)))
  2437 		rtl8139_weird_interrupt (dev, tp, ioaddr,
  2332 		rtl8139_weird_interrupt (dev, tp, ioaddr,
  2438 					 status, link_changed);
  2333 					 status, link_changed);
  2441 		rtl8139_tx_interrupt (dev, tp, ioaddr);
  2336 		rtl8139_tx_interrupt (dev, tp, ioaddr);
  2442 		if (status & TxErr)
  2337 		if (status & TxErr)
  2443 			RTL_W16 (IntrStatus, TxErr);
  2338 			RTL_W16 (IntrStatus, TxErr);
  2444 	}
  2339 	}
  2445  out:
  2340  out:
  2446 
  2341 	if (!tp->ecdev) spin_unlock (&tp->lock);
  2447 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
       
  2448 
       
  2449 	if (dev != rtl_ec_net_dev) {
       
  2450 		spin_unlock (&tp->lock);
       
  2451 	}
       
  2452 
       
  2453 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2454 
  2342 
  2455 	DPRINTK ("%s: exiting interrupt, intr_status=%#4.4x.\n",
  2343 	DPRINTK ("%s: exiting interrupt, intr_status=%#4.4x.\n",
  2456 		 dev->name, RTL_R16 (IntrStatus));
  2344 		 dev->name, RTL_R16 (IntrStatus));
  2457 	return IRQ_RETVAL(handled);
  2345 	return IRQ_RETVAL(handled);
  2458 }
  2346 }
  2474 {
  2362 {
  2475 	struct rtl8139_private *tp = netdev_priv(dev);
  2363 	struct rtl8139_private *tp = netdev_priv(dev);
  2476 	void __iomem *ioaddr = tp->mmio_addr;
  2364 	void __iomem *ioaddr = tp->mmio_addr;
  2477 	unsigned long flags;
  2365 	unsigned long flags;
  2478 
  2366 
  2479 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2367 	if (tp->ecdev) {
  2480 
  2368 		/* Stop the chip's Tx and Rx DMA processes. */
  2481 	if (dev != rtl_ec_net_dev) {
  2369 		RTL_W8 (ChipCmd, 0);
       
  2370 
       
  2371 		/* Disable interrupts by clearing the interrupt mask. */
       
  2372 		RTL_W16 (IntrMask, 0);
       
  2373 
       
  2374 		/* Update the error counts. */
       
  2375 		tp->stats.rx_missed_errors += RTL_R32 (RxMissed);
       
  2376 		RTL_W32 (RxMissed, 0);
       
  2377 	} else {
  2482 		netif_stop_queue (dev);
  2378 		netif_stop_queue (dev);
  2483 
  2379 
  2484 		rtl8139_stop_thread(tp);
  2380 		rtl8139_stop_thread(tp);
  2485 
  2381 
  2486 		if (netif_msg_ifdown(tp))
  2382 		if (netif_msg_ifdown(tp))
  2501 
  2397 
  2502 		spin_unlock_irqrestore (&tp->lock, flags);
  2398 		spin_unlock_irqrestore (&tp->lock, flags);
  2503 
  2399 
  2504 		synchronize_irq (dev->irq);	/* racy, but that's ok here */
  2400 		synchronize_irq (dev->irq);	/* racy, but that's ok here */
  2505 		free_irq (dev->irq, dev);
  2401 		free_irq (dev->irq, dev);
  2506 	} else {
  2402 	}
  2507 		/* Stop the chip's Tx and Rx DMA processes. */
       
  2508 		RTL_W8 (ChipCmd, 0);
       
  2509 
       
  2510 		/* Disable interrupts by clearing the interrupt mask. */
       
  2511 		RTL_W16 (IntrMask, 0);
       
  2512 
       
  2513 		/* Update the error counts. */
       
  2514 		tp->stats.rx_missed_errors += RTL_R32 (RxMissed);
       
  2515 		RTL_W32 (RxMissed, 0);
       
  2516 	}
       
  2517 
       
  2518 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2519 
  2403 
  2520 	rtl8139_tx_clear (tp);
  2404 	rtl8139_tx_clear (tp);
  2521 
  2405 
  2522 	pci_free_consistent(tp->pci_dev, RX_BUF_TOT_LEN,
  2406 	pci_free_consistent(tp->pci_dev, RX_BUF_TOT_LEN,
  2523 			    tp->rx_ring, tp->rx_ring_dma);
  2407 			    tp->rx_ring, tp->rx_ring_dma);
  2729 static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  2613 static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  2730 {
  2614 {
  2731 	struct rtl8139_private *np = netdev_priv(dev);
  2615 	struct rtl8139_private *np = netdev_priv(dev);
  2732 	int rc;
  2616 	int rc;
  2733 
  2617 
  2734 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2618 	if (np->ecdev || !netif_running(dev))
  2735 
       
  2736 	if (dev == rtl_ec_net_dev || !netif_running(dev))
       
  2737 		return -EINVAL;
  2619 		return -EINVAL;
  2738 
       
  2739 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2740 
  2620 
  2741 	spin_lock_irq(&np->lock);
  2621 	spin_lock_irq(&np->lock);
  2742 	rc = generic_mii_ioctl(&np->mii, if_mii(rq), cmd, NULL);
  2622 	rc = generic_mii_ioctl(&np->mii, if_mii(rq), cmd, NULL);
  2743 	spin_unlock_irq(&np->lock);
  2623 	spin_unlock_irq(&np->lock);
  2744 
  2624 
  2750 {
  2630 {
  2751 	struct rtl8139_private *tp = netdev_priv(dev);
  2631 	struct rtl8139_private *tp = netdev_priv(dev);
  2752 	void __iomem *ioaddr = tp->mmio_addr;
  2632 	void __iomem *ioaddr = tp->mmio_addr;
  2753 	unsigned long flags;
  2633 	unsigned long flags;
  2754 
  2634 
  2755 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2635 	if (tp->ecdev || netif_running(dev)) {
  2756 
       
  2757 	if (dev == rtl_ec_net_dev || netif_running(dev)) {
       
  2758 		spin_lock_irqsave (&tp->lock, flags);
  2636 		spin_lock_irqsave (&tp->lock, flags);
  2759 		tp->stats.rx_missed_errors += RTL_R32 (RxMissed);
  2637 		tp->stats.rx_missed_errors += RTL_R32 (RxMissed);
  2760 		RTL_W32 (RxMissed, 0);
  2638 		RTL_W32 (RxMissed, 0);
  2761 		spin_unlock_irqrestore (&tp->lock, flags);
  2639 		spin_unlock_irqrestore (&tp->lock, flags);
  2762 	}
  2640 	}
  2763 
       
  2764 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2765 
  2641 
  2766 	return &tp->stats;
  2642 	return &tp->stats;
  2767 }
  2643 }
  2768 
  2644 
  2769 /* Set or clear the multicast filter for this adaptor.
  2645 /* Set or clear the multicast filter for this adaptor.
  2833 	void __iomem *ioaddr = tp->mmio_addr;
  2709 	void __iomem *ioaddr = tp->mmio_addr;
  2834 	unsigned long flags;
  2710 	unsigned long flags;
  2835 
  2711 
  2836 	pci_save_state (pdev);
  2712 	pci_save_state (pdev);
  2837 
  2713 
  2838 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2714 	if (tp->ecdev || !netif_running (dev))
  2839 
       
  2840 	if (dev == rtl_ec_net_dev || !netif_running (dev))
       
  2841 		return 0;
  2715 		return 0;
  2842 
       
  2843 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2844 
  2716 
  2845 	netif_device_detach (dev);
  2717 	netif_device_detach (dev);
  2846 
  2718 
  2847 	spin_lock_irqsave (&tp->lock, flags);
  2719 	spin_lock_irqsave (&tp->lock, flags);
  2848 
  2720 
  2863 
  2735 
  2864 
  2736 
  2865 static int rtl8139_resume (struct pci_dev *pdev)
  2737 static int rtl8139_resume (struct pci_dev *pdev)
  2866 {
  2738 {
  2867 	struct net_device *dev = pci_get_drvdata (pdev);
  2739 	struct net_device *dev = pci_get_drvdata (pdev);
       
  2740 	struct rtl8139_private *tp = netdev_priv(dev);
  2868 
  2741 
  2869 	pci_restore_state (pdev);
  2742 	pci_restore_state (pdev);
  2870 
  2743 	if (tp->ecdev || !netif_running (dev))
  2871 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
       
  2872 
       
  2873 	if (dev == rtl_ec_net_dev || !netif_running (dev))
       
  2874 		return 0;
  2744 		return 0;
  2875 
       
  2876 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2877 
       
  2878 	pci_set_power_state (pdev, PCI_D0);
  2745 	pci_set_power_state (pdev, PCI_D0);
  2879 	rtl8139_init_ring (dev);
  2746 	rtl8139_init_ring (dev);
  2880 	rtl8139_hw_start (dev);
  2747 	rtl8139_hw_start (dev);
  2881 	netif_device_attach (dev);
  2748 	netif_device_attach (dev);
  2882 	return 0;
  2749 	return 0;
  2897 };
  2764 };
  2898 
  2765 
  2899 
  2766 
  2900 static int __init rtl8139_init_module (void)
  2767 static int __init rtl8139_init_module (void)
  2901 {
  2768 {
  2902 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2769 	/* when we're a module, we always print a version message,
  2903 
  2770 	 * even if no 8139 board is found.
  2904 	printk(KERN_INFO RTL8139_DRIVER_NAME "\n");
  2771 	 */
  2905 	printk(KERN_INFO "ec_device_index is %i\n", ec_device_index);
  2772 #ifdef MODULE
  2906 
  2773 	printk (KERN_INFO RTL8139_DRIVER_NAME "\n");
  2907 	if (pci_register_driver(&rtl8139_pci_driver) < 0) {
  2774 #endif
  2908 		printk(KERN_ERR "Failed to init PCI module.\n");
  2775 
  2909 		goto out_return;
  2776 	return pci_register_driver(&rtl8139_pci_driver);
  2910 	}
       
  2911 
       
  2912 	if (rtl_ec_net_dev) {
       
  2913 		printk(KERN_INFO "Registering EtherCAT device...\n");
       
  2914 		if (!(rtl_ec_dev = ecdev_register(ec_device_master_index,
       
  2915 			rtl_ec_net_dev, ec_poll, THIS_MODULE))) {
       
  2916 			printk(KERN_ERR "Failed to register EtherCAT device!\n");
       
  2917 			goto out_pci;
       
  2918 		}
       
  2919 
       
  2920 		printk(KERN_INFO "Opening EtherCAT device...\n");
       
  2921 		if (ecdev_open(rtl_ec_dev)) {
       
  2922 			printk(KERN_ERR "Failed to open EtherCAT device!\n");
       
  2923 			goto out_unregister;
       
  2924 		}
       
  2925 
       
  2926 		printk(KERN_INFO "EtherCAT device ready.\n");
       
  2927 	} else {
       
  2928 		printk(KERN_WARNING "No EtherCAT device registered!\n");
       
  2929 	}
       
  2930 
       
  2931 	return 0;
       
  2932 
       
  2933     out_unregister:
       
  2934 	printk(KERN_INFO "Unregistering EtherCAT device...\n");
       
  2935 	ecdev_unregister(ec_device_master_index, rtl_ec_dev);
       
  2936 	rtl_ec_dev = NULL;
       
  2937     out_pci:
       
  2938 	pci_unregister_driver(&rtl8139_pci_driver);
       
  2939     out_return:
       
  2940 	return -1;
       
  2941 
       
  2942 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2943 }
  2777 }
  2944 
  2778 
  2945 
  2779 
  2946 static void __exit rtl8139_cleanup_module (void)
  2780 static void __exit rtl8139_cleanup_module (void)
  2947 {
  2781 {
  2948 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2782 	pci_unregister_driver (&rtl8139_pci_driver);
  2949 
       
  2950 	printk(KERN_INFO "Cleaning up RTL8139-EtherCAT module...\n");
       
  2951 
       
  2952 	if (rtl_ec_net_dev) {
       
  2953 		printk(KERN_INFO "Closing EtherCAT device...\n");
       
  2954 		ecdev_close(rtl_ec_dev);
       
  2955 		printk(KERN_INFO "Unregistering EtherCAT device...\n");
       
  2956 		ecdev_unregister(ec_device_master_index, rtl_ec_dev);
       
  2957 		rtl_ec_dev = NULL;
       
  2958 	}
       
  2959 
       
  2960 	pci_unregister_driver(&rtl8139_pci_driver);
       
  2961 
       
  2962 	printk(KERN_INFO "RTL8139-EtherCAT module cleaned up.\n");
       
  2963 
       
  2964 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2965 }
  2783 }
  2966 
  2784 
  2967 
  2785 
  2968 module_init(rtl8139_init_module);
  2786 module_init(rtl8139_init_module);
  2969 module_exit(rtl8139_cleanup_module);
  2787 module_exit(rtl8139_cleanup_module);