devices/8139too-2.6.18-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,
  1049 		return i;
  1019 		return i;
  1050 
  1020 
  1051 	assert (dev != NULL);
  1021 	assert (dev != NULL);
  1052 	tp = netdev_priv(dev);
  1022 	tp = netdev_priv(dev);
  1053 
  1023 
  1054 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
       
  1055 
       
  1056 	if (board_idx == ec_device_index) {
       
  1057 		rtl_ec_net_dev = dev;
       
  1058 		strcpy(dev->name, "ec0");
       
  1059 	}
       
  1060 
       
  1061 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  1062 
       
  1063 	ioaddr = tp->mmio_addr;
  1024 	ioaddr = tp->mmio_addr;
  1064 	assert (ioaddr != NULL);
  1025 	assert (ioaddr != NULL);
  1065 
  1026 
  1066 	addr_len = read_eeprom (ioaddr, 0, 8) == 0x8129 ? 8 : 6;
  1027 	addr_len = read_eeprom (ioaddr, 0, 8) == 0x8129 ? 8 : 6;
  1067 	for (i = 0; i < 3; i++)
  1028 	for (i = 0; i < 3; i++)
  1109 	tp->mii.mdio_write = mdio_write;
  1070 	tp->mii.mdio_write = mdio_write;
  1110 	tp->mii.phy_id_mask = 0x3f;
  1071 	tp->mii.phy_id_mask = 0x3f;
  1111 	tp->mii.reg_num_mask = 0x1f;
  1072 	tp->mii.reg_num_mask = 0x1f;
  1112 
  1073 
  1113 	/* dev is fully set up and ready to use now */
  1074 	/* dev is fully set up and ready to use now */
  1114 
  1075     
  1115 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1076 	// offer device to EtherCAT master module
  1116 
  1077 	if (ecdev_offer(dev, ec_poll, THIS_MODULE, &tp->ecdev)) {
  1117 	if (dev != rtl_ec_net_dev) {
  1078 		printk(KERN_ERR PFX "Failed to offer device.\n");
       
  1079 		goto err_out;
       
  1080 	}
       
  1081 
       
  1082 	if (!tp->ecdev) {
  1118 		DPRINTK("about to register device named %s (%p)...\n", dev->name, dev);
  1083 		DPRINTK("about to register device named %s (%p)...\n", dev->name, dev);
  1119 		i = register_netdev (dev);
  1084 		i = register_netdev (dev);
  1120 		if (i) goto err_out;
  1085 		if (i) goto err_out;
  1121 	}
  1086 	}
  1122 
       
  1123 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  1124 
  1087 
  1125 	pci_set_drvdata (pdev, dev);
  1088 	pci_set_drvdata (pdev, dev);
  1126 
  1089 
  1127 	printk (KERN_INFO "%s: %s at 0x%lx, "
  1090 	printk (KERN_INFO "%s: %s at 0x%lx, "
  1128 		"%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x, "
  1091 		"%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x, "
  1192 
  1155 
  1193 	/* Put the chip into low-power mode. */
  1156 	/* Put the chip into low-power mode. */
  1194 	if (rtl_chip_info[tp->chipset].flags & HasHltClk)
  1157 	if (rtl_chip_info[tp->chipset].flags & HasHltClk)
  1195 		RTL_W8 (HltClk, 'H');	/* 'R' would leave the clock running. */
  1158 		RTL_W8 (HltClk, 'H');	/* 'R' would leave the clock running. */
  1196 
  1159 
       
  1160 	if (tp->ecdev && ecdev_open(tp->ecdev)) {
       
  1161 		ecdev_withdraw(tp->ecdev);
       
  1162 		goto err_out;
       
  1163 	}
       
  1164 
  1197 	return 0;
  1165 	return 0;
  1198 
  1166 
  1199 err_out:
  1167 err_out:
  1200 	__rtl8139_cleanup_dev (dev);
  1168 	__rtl8139_cleanup_dev (dev);
  1201 	pci_disable_device (pdev);
  1169 	pci_disable_device (pdev);
  1204 
  1172 
  1205 
  1173 
  1206 static void __devexit rtl8139_remove_one (struct pci_dev *pdev)
  1174 static void __devexit rtl8139_remove_one (struct pci_dev *pdev)
  1207 {
  1175 {
  1208 	struct net_device *dev = pci_get_drvdata (pdev);
  1176 	struct net_device *dev = pci_get_drvdata (pdev);
       
  1177 	struct rtl8139_private *tp = netdev_priv(dev);
  1209 
  1178 
  1210 	assert (dev != NULL);
  1179 	assert (dev != NULL);
  1211 
  1180 
  1212 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1181 	if (tp->ecdev) {
  1213 
  1182 		ecdev_close(tp->ecdev);
  1214 	if (dev != rtl_ec_net_dev) {
  1183 		ecdev_withdraw(tp->ecdev);
       
  1184 	}
       
  1185 	else {
  1215 		unregister_netdev (dev);
  1186 		unregister_netdev (dev);
  1216 	}
  1187 	}
  1217 
       
  1218 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  1219 
  1188 
  1220 	__rtl8139_cleanup_dev (dev);
  1189 	__rtl8139_cleanup_dev (dev);
  1221 	pci_disable_device (pdev);
  1190 	pci_disable_device (pdev);
  1222 }
  1191 }
  1223 
  1192 
  1415 {
  1384 {
  1416 	struct rtl8139_private *tp = netdev_priv(dev);
  1385 	struct rtl8139_private *tp = netdev_priv(dev);
  1417 	int retval;
  1386 	int retval;
  1418 	void __iomem *ioaddr = tp->mmio_addr;
  1387 	void __iomem *ioaddr = tp->mmio_addr;
  1419 
  1388 
  1420 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1389 	if (!tp->ecdev) {
  1421 
       
  1422 	if (dev != rtl_ec_net_dev) {
       
  1423 		retval = request_irq(dev->irq, rtl8139_interrupt,
  1390 		retval = request_irq(dev->irq, rtl8139_interrupt,
  1424 			IRQF_SHARED, dev->name, dev);
  1391 			IRQF_SHARED, dev->name, dev);
  1425 		if (retval)
  1392 		if (retval)
  1426 			return retval;
  1393 			return retval;
  1427 	}
  1394 	}
  1428 
       
  1429 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  1430 
  1395 
  1431 	tp->tx_bufs = pci_alloc_consistent(tp->pci_dev, TX_BUF_TOT_LEN,
  1396 	tp->tx_bufs = pci_alloc_consistent(tp->pci_dev, TX_BUF_TOT_LEN,
  1432 					   &tp->tx_bufs_dma);
  1397 					   &tp->tx_bufs_dma);
  1433 	tp->rx_ring = pci_alloc_consistent(tp->pci_dev, RX_BUF_TOT_LEN,
  1398 	tp->rx_ring = pci_alloc_consistent(tp->pci_dev, RX_BUF_TOT_LEN,
  1434 					   &tp->rx_ring_dma);
  1399 					   &tp->rx_ring_dma);
  1435 	if (tp->tx_bufs == NULL || tp->rx_ring == NULL) {
  1400 	if (tp->tx_bufs == NULL || tp->rx_ring == NULL) {
  1436 		/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1401 		if (!tp->ecdev) free_irq(dev->irq, dev);
  1437 
       
  1438 		if (dev != rtl_ec_net_dev) {
       
  1439 			free_irq(dev->irq, dev);
       
  1440 		}
       
  1441 
       
  1442 		/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  1443 
  1402 
  1444 		if (tp->tx_bufs)
  1403 		if (tp->tx_bufs)
  1445 			pci_free_consistent(tp->pci_dev, TX_BUF_TOT_LEN,
  1404 			pci_free_consistent(tp->pci_dev, TX_BUF_TOT_LEN,
  1446 					    tp->tx_bufs, tp->tx_bufs_dma);
  1405 					    tp->tx_bufs, tp->tx_bufs_dma);
  1447 		if (tp->rx_ring)
  1406 		if (tp->rx_ring)
  1456 	tp->tx_flag = (TX_FIFO_THRESH << 11) & 0x003f0000;
  1415 	tp->tx_flag = (TX_FIFO_THRESH << 11) & 0x003f0000;
  1457 
  1416 
  1458 	rtl8139_init_ring (dev);
  1417 	rtl8139_init_ring (dev);
  1459 	rtl8139_hw_start (dev);
  1418 	rtl8139_hw_start (dev);
  1460 
  1419 
  1461 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1420 	if (!tp->ecdev) {
  1462 
       
  1463 	if (dev != rtl_ec_net_dev) {
       
  1464 		netif_start_queue (dev);
  1421 		netif_start_queue (dev);
  1465 
  1422 
  1466 		if (netif_msg_ifup(tp))
  1423 		if (netif_msg_ifup(tp))
  1467 			printk(KERN_DEBUG "%s: rtl8139_open() ioaddr %#llx IRQ %d"
  1424 			printk(KERN_DEBUG "%s: rtl8139_open() ioaddr %#llx IRQ %d"
  1468 					" GP Pins %2.2x %s-duplex.\n", dev->name,
  1425 					" GP Pins %2.2x %s-duplex.\n", dev->name,
  1470 					dev->irq, RTL_R8 (MediaStatus),
  1427 					dev->irq, RTL_R8 (MediaStatus),
  1471 					tp->mii.full_duplex ? "full" : "half");
  1428 					tp->mii.full_duplex ? "full" : "half");
  1472 		rtl8139_start_thread(tp);
  1429 		rtl8139_start_thread(tp);
  1473 	}
  1430 	}
  1474 
  1431 
  1475 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  1476 
       
  1477 	return 0;
  1432 	return 0;
  1478 }
  1433 }
  1479 
  1434 
  1480 
  1435 
  1481 static void rtl_check_media (struct net_device *dev, unsigned int init_media)
  1436 static void rtl_check_media (struct net_device *dev, unsigned int init_media)
  1482 {
  1437 {
  1483 	struct rtl8139_private *tp = netdev_priv(dev);
  1438 	struct rtl8139_private *tp = netdev_priv(dev);
  1484 
  1439 
  1485 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1440 	if (tp->ecdev) {
  1486 
  1441 		void __iomem *ioaddr = tp->mmio_addr;
  1487 	if (dev != rtl_ec_net_dev) {
  1442 		uint16_t state = RTL_R16(BasicModeStatus) & BMSR_LSTATUS;
       
  1443 		ecdev_set_link(tp->ecdev, state ? 1 : 0);
       
  1444 	}
       
  1445 	else {
  1488 		if (tp->phys[0] >= 0) {
  1446 		if (tp->phys[0] >= 0) {
  1489 			mii_check_media(&tp->mii, netif_msg_link(tp), init_media);
  1447 			mii_check_media(&tp->mii, netif_msg_link(tp), init_media);
  1490 		}
  1448 		}
  1491 	} else {
  1449 	}
  1492 		void __iomem *ioaddr = tp->mmio_addr;
       
  1493 		uint16_t state = RTL_R16(BasicModeStatus) & BMSR_LSTATUS;
       
  1494 		ecdev_link_state(rtl_ec_dev, state ? 1 : 0);
       
  1495 	}
       
  1496 
       
  1497 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  1498 }
  1450 }
  1499 
  1451 
  1500 /* Start the hardware at open or resume. */
  1452 /* Start the hardware at open or resume. */
  1501 static void rtl8139_hw_start (struct net_device *dev)
  1453 static void rtl8139_hw_start (struct net_device *dev)
  1502 {
  1454 {
  1557 	/* make sure RxTx has started */
  1509 	/* make sure RxTx has started */
  1558 	tmp = RTL_R8 (ChipCmd);
  1510 	tmp = RTL_R8 (ChipCmd);
  1559 	if ((!(tmp & CmdRxEnb)) || (!(tmp & CmdTxEnb)))
  1511 	if ((!(tmp & CmdRxEnb)) || (!(tmp & CmdTxEnb)))
  1560 		RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb);
  1512 		RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb);
  1561 
  1513 
  1562 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1514 	if (!tp->ecdev)
  1563 
       
  1564 	if (dev != rtl_ec_net_dev) {
       
  1565 		/* Enable all known interrupts by setting the interrupt mask. */
  1515 		/* Enable all known interrupts by setting the interrupt mask. */
  1566 		RTL_W16 (IntrMask, rtl8139_intr_mask);
  1516 		RTL_W16 (IntrMask, rtl8139_intr_mask);
  1567 	}
       
  1568 
       
  1569 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  1570 }
  1517 }
  1571 
  1518 
  1572 
  1519 
  1573 /* Initialize the Rx and Tx rings, along with various 'dev' bits. */
  1520 /* Initialize the Rx and Tx rings, along with various 'dev' bits. */
  1574 static void rtl8139_init_ring (struct net_device *dev)
  1521 static void rtl8139_init_ring (struct net_device *dev)
  1812 	/* disable Tx ASAP, if not already */
  1759 	/* disable Tx ASAP, if not already */
  1813 	tmp8 = RTL_R8 (ChipCmd);
  1760 	tmp8 = RTL_R8 (ChipCmd);
  1814 	if (tmp8 & CmdTxEnb)
  1761 	if (tmp8 & CmdTxEnb)
  1815 		RTL_W8 (ChipCmd, CmdRxEnb);
  1762 		RTL_W8 (ChipCmd, CmdRxEnb);
  1816 
  1763 
  1817 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1764 	if (tp->ecdev) {
  1818 
  1765 		rtl8139_tx_clear (tp);
  1819 	if (dev != rtl_ec_net_dev) {
  1766 		rtl8139_hw_start (dev);
       
  1767 	}
       
  1768 	else {
  1820 		spin_lock_bh(&tp->rx_lock);
  1769 		spin_lock_bh(&tp->rx_lock);
  1821 		/* Disable interrupts by clearing the interrupt mask. */
  1770 		/* Disable interrupts by clearing the interrupt mask. */
  1822 		RTL_W16 (IntrMask, 0x0000);
  1771 		RTL_W16 (IntrMask, 0x0000);
  1823 
  1772 
  1824 		/* Stop a shared interrupt from scavenging while we are. */
  1773 		/* Stop a shared interrupt from scavenging while we are. */
  1830 		if (netif_running(dev)) {
  1779 		if (netif_running(dev)) {
  1831 			rtl8139_hw_start (dev);
  1780 			rtl8139_hw_start (dev);
  1832 			netif_wake_queue (dev);
  1781 			netif_wake_queue (dev);
  1833 		}
  1782 		}
  1834 		spin_unlock_bh(&tp->rx_lock);
  1783 		spin_unlock_bh(&tp->rx_lock);
  1835 	} else {
  1784 	}
  1836 		rtl8139_tx_clear (tp);
       
  1837 		rtl8139_hw_start (dev);
       
  1838 	}
       
  1839 
       
  1840 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  1841 }
  1785 }
  1842 
  1786 
  1843 static void rtl8139_tx_timeout (struct net_device *dev)
  1787 static void rtl8139_tx_timeout (struct net_device *dev)
  1844 {
  1788 {
  1845 	struct rtl8139_private *tp = netdev_priv(dev);
  1789 	struct rtl8139_private *tp = netdev_priv(dev);
  1846 
  1790 
  1847 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  1791 	if (!tp->ecdev && !tp->have_thread) {
  1848 
       
  1849 	if (dev != rtl_ec_net_dev && !tp->have_thread) {
       
  1850 		INIT_WORK(&tp->thread, rtl8139_tx_timeout_task, dev);
  1792 		INIT_WORK(&tp->thread, rtl8139_tx_timeout_task, dev);
  1851 		schedule_delayed_work(&tp->thread, next_tick);
  1793 		schedule_delayed_work(&tp->thread, next_tick);
  1852 	} else
  1794 	} else
  1853 		tp->watchdog_fired = 1;
  1795 		tp->watchdog_fired = 1;
  1854 
  1796 
  1855 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  1856 }
  1797 }
  1857 
  1798 
  1858 static int rtl8139_start_xmit (struct sk_buff *skb, struct net_device *dev)
  1799 static int rtl8139_start_xmit (struct sk_buff *skb, struct net_device *dev)
  1859 {
  1800 {
  1860 	struct rtl8139_private *tp = netdev_priv(dev);
  1801 	struct rtl8139_private *tp = netdev_priv(dev);
  1864 	unsigned long flags;
  1805 	unsigned long flags;
  1865 
  1806 
  1866 	/* Calculate the next Tx descriptor entry. */
  1807 	/* Calculate the next Tx descriptor entry. */
  1867 	entry = tp->cur_tx % NUM_TX_DESC;
  1808 	entry = tp->cur_tx % NUM_TX_DESC;
  1868 
  1809 
  1869 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
       
  1870 
       
  1871 	/* Note: the chip doesn't have auto-pad! */
  1810 	/* Note: the chip doesn't have auto-pad! */
  1872 	if (likely(len < TX_BUF_SIZE)) {
  1811 	if (likely(len < TX_BUF_SIZE)) {
  1873 		if (len < ETH_ZLEN)
  1812 		if (len < ETH_ZLEN)
  1874 			memset(tp->tx_buf[entry], 0, ETH_ZLEN);
  1813 			memset(tp->tx_buf[entry], 0, ETH_ZLEN);
  1875 		skb_copy_and_csum_dev(skb, tp->tx_buf[entry]);
  1814 		skb_copy_and_csum_dev(skb, tp->tx_buf[entry]);
  1876 		if (dev != rtl_ec_net_dev) {
  1815 		if (!tp->ecdev) dev_kfree_skb(skb);
  1877 			dev_kfree_skb(skb);
       
  1878 		}
       
  1879 	} else {
  1816 	} else {
  1880 		if (dev != rtl_ec_net_dev) {
  1817 		if (!tp->ecdev) dev_kfree_skb(skb);
  1881 			dev_kfree_skb(skb);
       
  1882 		}
       
  1883 		tp->stats.tx_dropped++;
  1818 		tp->stats.tx_dropped++;
  1884 		return 0;
  1819 		return 0;
  1885 	}
  1820 	}
  1886 
  1821 
  1887 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  1822 	if (tp->ecdev) {
  1888 
  1823 		RTL_W32_F (TxStatus0 + (entry * sizeof (u32)),
  1889 	if (dev != rtl_ec_net_dev) {
  1824 				tp->tx_flag | max(len, (unsigned int)ETH_ZLEN));
       
  1825 
       
  1826 		dev->trans_start = jiffies;
       
  1827 
       
  1828 		tp->cur_tx++;
       
  1829 		wmb();
       
  1830 	}
       
  1831 	else {
  1890 		spin_lock_irqsave(&tp->lock, flags);
  1832 		spin_lock_irqsave(&tp->lock, flags);
  1891 
  1833 
  1892 		RTL_W32_F (TxStatus0 + (entry * sizeof (u32)),
  1834 		RTL_W32_F (TxStatus0 + (entry * sizeof (u32)),
  1893 				tp->tx_flag | max(len, (unsigned int)ETH_ZLEN));
  1835 				tp->tx_flag | max(len, (unsigned int)ETH_ZLEN));
  1894 
  1836 
  1903 
  1845 
  1904 		if (netif_msg_tx_queued(tp))
  1846 		if (netif_msg_tx_queued(tp))
  1905 			printk (KERN_DEBUG "%s: Queued Tx packet size %u to slot %d.\n",
  1847 			printk (KERN_DEBUG "%s: Queued Tx packet size %u to slot %d.\n",
  1906 					dev->name, len, entry);
  1848 					dev->name, len, entry);
  1907 	}
  1849 	}
  1908 	else {
       
  1909 		RTL_W32_F (TxStatus0 + (entry * sizeof (u32)),
       
  1910 				tp->tx_flag | max(len, (unsigned int)ETH_ZLEN));
       
  1911 
       
  1912 		dev->trans_start = jiffies;
       
  1913 
       
  1914 		tp->cur_tx++;
       
  1915 		wmb();
       
  1916 	}
       
  1917 
       
  1918 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  1919 
  1850 
  1920 	return 0;
  1851 	return 0;
  1921 }
  1852 }
  1922 
  1853 
  1923 
  1854 
  1972 
  1903 
  1973 		dirty_tx++;
  1904 		dirty_tx++;
  1974 		tx_left--;
  1905 		tx_left--;
  1975 	}
  1906 	}
  1976 
  1907 
  1977 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
       
  1978 
       
  1979 #ifndef RTL8139_NDEBUG
  1908 #ifndef RTL8139_NDEBUG
  1980 	if (dev != rtl_ec_net_dev && tp->cur_tx - dirty_tx > NUM_TX_DESC) {
  1909 	if (!tp->ecdev && tp->cur_tx - dirty_tx > NUM_TX_DESC) {
  1981 		printk (KERN_ERR "%s: Out-of-sync dirty pointer, %ld vs. %ld.\n",
  1910 		printk (KERN_ERR "%s: Out-of-sync dirty pointer, %ld vs. %ld.\n",
  1982 		        dev->name, dirty_tx, tp->cur_tx);
  1911 		        dev->name, dirty_tx, tp->cur_tx);
  1983 		dirty_tx += NUM_TX_DESC;
  1912 		dirty_tx += NUM_TX_DESC;
  1984 	}
  1913 	}
  1985 #endif /* RTL8139_NDEBUG */
  1914 #endif /* RTL8139_NDEBUG */
  1986 
  1915 
  1987 	/* only wake the queue if we did work, and the queue is stopped */
  1916 	/* only wake the queue if we did work, and the queue is stopped */
  1988 	if (tp->dirty_tx != dirty_tx) {
  1917 	if (tp->dirty_tx != dirty_tx) {
  1989 		tp->dirty_tx = dirty_tx;
  1918 		tp->dirty_tx = dirty_tx;
  1990 		mb();
  1919 		mb();
  1991 
  1920 		if (!tp->ecdev) netif_wake_queue (dev);
  1992 		if (dev != rtl_ec_net_dev) {
  1921 	}
  1993 			netif_wake_queue (dev);
       
  1994 		}
       
  1995 	}
       
  1996 
       
  1997 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  1998 }
  1922 }
  1999 
  1923 
  2000 
  1924 
  2001 /* TODO: clean this up!  Rx reset need not be this intensive */
  1925 /* TODO: clean this up!  Rx reset need not be this intensive */
  2002 static void rtl8139_rx_err (u32 rx_status, struct net_device *dev,
  1926 static void rtl8139_rx_err (u32 rx_status, struct net_device *dev,
  2125 	DPRINTK ("%s: In rtl8139_rx(), current %4.4x BufAddr %4.4x,"
  2049 	DPRINTK ("%s: In rtl8139_rx(), current %4.4x BufAddr %4.4x,"
  2126 		 " free to %4.4x, Cmd %2.2x.\n", dev->name, (u16)cur_rx,
  2050 		 " free to %4.4x, Cmd %2.2x.\n", dev->name, (u16)cur_rx,
  2127 		 RTL_R16 (RxBufAddr),
  2051 		 RTL_R16 (RxBufAddr),
  2128 		 RTL_R16 (RxBufPtr), RTL_R8 (ChipCmd));
  2052 		 RTL_R16 (RxBufPtr), RTL_R8 (ChipCmd));
  2129 
  2053 
  2130 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2054 	while ((tp->ecdev || netif_running(dev))
  2131 
       
  2132 	while ((dev == rtl_ec_net_dev || netif_running(dev))
       
  2133 			&& received < budget
  2055 			&& received < budget
  2134 			&& (RTL_R8 (ChipCmd) & RxBufEmpty) == 0) {
  2056 			&& (RTL_R8 (ChipCmd) & RxBufEmpty) == 0) {
  2135 
       
  2136 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2137 
       
  2138 		u32 ring_offset = cur_rx % RX_BUF_LEN;
  2057 		u32 ring_offset = cur_rx % RX_BUF_LEN;
  2139 		u32 rx_status;
  2058 		u32 rx_status;
  2140 		unsigned int pkt_size;
  2059 		unsigned int pkt_size;
  2141 		struct sk_buff *skb;
  2060 		struct sk_buff *skb;
  2142 
  2061 
  2145 		/* read size+status of next frame from DMA ring buffer */
  2064 		/* read size+status of next frame from DMA ring buffer */
  2146 		rx_status = le32_to_cpu (*(u32 *) (rx_ring + ring_offset));
  2065 		rx_status = le32_to_cpu (*(u32 *) (rx_ring + ring_offset));
  2147 		rx_size = rx_status >> 16;
  2066 		rx_size = rx_status >> 16;
  2148 		pkt_size = rx_size - 4;
  2067 		pkt_size = rx_size - 4;
  2149 
  2068 
  2150 		/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2069 		if (!tp->ecdev) {
  2151 
       
  2152 		if (dev != rtl_ec_net_dev) {
       
  2153 			if (netif_msg_rx_status(tp))
  2070 			if (netif_msg_rx_status(tp))
  2154 				printk(KERN_DEBUG "%s:  rtl8139_rx() status %4.4x, size %4.4x,"
  2071 				printk(KERN_DEBUG "%s:  rtl8139_rx() status %4.4x, size %4.4x,"
  2155 				       " cur %4.4x.\n", dev->name, rx_status,
  2072 				       " cur %4.4x.\n", dev->name, rx_status,
  2156 				       rx_size, cur_rx);
  2073 				       rx_size, cur_rx);
  2157 		}
  2074 		}
  2158 
       
  2159 		/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2160 
       
  2161 #if RTL8139_DEBUG > 2
  2075 #if RTL8139_DEBUG > 2
  2162 		{
  2076 		{
  2163 			int i;
  2077 			int i;
  2164 			DPRINTK ("%s: Frame contents ", dev->name);
  2078 			DPRINTK ("%s: Frame contents ", dev->name);
  2165 			for (i = 0; i < 70; i++)
  2079 			for (i = 0; i < 70; i++)
  2203 			rtl8139_rx_err (rx_status, dev, tp, ioaddr);
  2117 			rtl8139_rx_err (rx_status, dev, tp, ioaddr);
  2204 			received = -1;
  2118 			received = -1;
  2205 			goto out;
  2119 			goto out;
  2206 		}
  2120 		}
  2207 
  2121 
  2208 		/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2122 		if (tp->ecdev) {
  2209 
  2123 			ecdev_receive(tp->ecdev,
  2210 		if (dev != rtl_ec_net_dev) {
  2124 					&rx_ring[ring_offset + 4], pkt_size);
       
  2125 			dev->last_rx = jiffies;
       
  2126 			tp->stats.rx_bytes += pkt_size;
       
  2127 			tp->stats.rx_packets++;
       
  2128 		}
       
  2129 		else {
  2211 			/* Malloc up new buffer, compatible with net-2e. */
  2130 			/* Malloc up new buffer, compatible with net-2e. */
  2212 			/* Omit the four octet CRC from the length. */
  2131 			/* Omit the four octet CRC from the length. */
  2213 
  2132 
  2214 			skb = dev_alloc_skb (pkt_size + 2);
  2133 			skb = dev_alloc_skb (pkt_size + 2);
  2215 			if (likely(skb)) {
  2134 			if (likely(skb)) {
  2230 
  2149 
  2231 				netif_receive_skb (skb);
  2150 				netif_receive_skb (skb);
  2232 			} else {
  2151 			} else {
  2233 				if (net_ratelimit())
  2152 				if (net_ratelimit())
  2234 					printk(KERN_WARNING
  2153 					printk(KERN_WARNING
  2235 					       "%s: Memory squeeze, dropping packet.\n",
  2154 							"%s: Memory squeeze, dropping packet.\n",
  2236 					       dev->name);
  2155 							dev->name);
  2237 				tp->stats.rx_dropped++;
  2156 				tp->stats.rx_dropped++;
  2238 			}
  2157 			}
  2239 		} else {
       
  2240 			ecdev_receive(rtl_ec_dev,
       
  2241 			              &rx_ring[ring_offset + 4], pkt_size);
       
  2242 			dev->last_rx = jiffies;
       
  2243 			tp->stats.rx_bytes += pkt_size;
       
  2244 			tp->stats.rx_packets++;
       
  2245 		}
  2158 		}
  2246 
       
  2247 		/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2248 
       
  2249 		received++;
  2159 		received++;
  2250 
  2160 
  2251 		cur_rx = (cur_rx + rx_size + 4 + 3) & ~3;
  2161 		cur_rx = (cur_rx + rx_size + 4 + 3) & ~3;
  2252 		RTL_W16 (RxBufPtr, (u16) (cur_rx - 16));
  2162 		RTL_W16 (RxBufPtr, (u16) (cur_rx - 16));
  2253 
  2163 
  2349 	spin_unlock(&tp->rx_lock);
  2259 	spin_unlock(&tp->rx_lock);
  2350 
  2260 
  2351 	return !done;
  2261 	return !done;
  2352 }
  2262 }
  2353 
  2263 
  2354 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
       
  2355 
       
  2356 void ec_poll(struct net_device *dev)
  2264 void ec_poll(struct net_device *dev)
  2357 {
  2265 {
  2358     rtl8139_interrupt(0, dev, NULL);
  2266     rtl8139_interrupt(0, dev, NULL);
  2359 }
  2267 }
  2360 
       
  2361 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2362 
  2268 
  2363 /* The interrupt handler does all of the Rx thread work and cleans up
  2269 /* The interrupt handler does all of the Rx thread work and cleans up
  2364    after the Tx thread. */
  2270    after the Tx thread. */
  2365 irqreturn_t rtl8139_interrupt (int irq, void *dev_instance,
  2271 static irqreturn_t rtl8139_interrupt (int irq, void *dev_instance,
  2366                                struct pt_regs *regs)
  2272 			       struct pt_regs *regs)
  2367 {
  2273 {
  2368 	struct net_device *dev = (struct net_device *) dev_instance;
  2274 	struct net_device *dev = (struct net_device *) dev_instance;
  2369 	struct rtl8139_private *tp = netdev_priv(dev);
  2275 	struct rtl8139_private *tp = netdev_priv(dev);
  2370 	void __iomem *ioaddr = tp->mmio_addr;
  2276 	void __iomem *ioaddr = tp->mmio_addr;
  2371 	u16 status, ackstat;
  2277 	u16 status, ackstat;
  2372 	int link_changed = 0; /* avoid bogus "uninit" warning */
  2278 	int link_changed = 0; /* avoid bogus "uninit" warning */
  2373 	int handled = 0;
  2279 	int handled = 0;
  2374 
  2280 
  2375 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2281 	if (tp->ecdev) {
  2376 
  2282 		status = RTL_R16 (IntrStatus);
  2377 	if (dev != rtl_ec_net_dev) {
  2283 	}
       
  2284 	else {
  2378 		spin_lock (&tp->lock);
  2285 		spin_lock (&tp->lock);
  2379 		status = RTL_R16 (IntrStatus);
  2286 		status = RTL_R16 (IntrStatus);
  2380 
  2287 
  2381 		/* shared irq? */
  2288 		/* shared irq? */
  2382 		if (unlikely((status & rtl8139_intr_mask) == 0))
  2289 		if (unlikely((status & rtl8139_intr_mask) == 0))
  2383 			goto out;
  2290 			goto out;
  2384 	} else {
  2291 	}
  2385 		status = RTL_R16 (IntrStatus);
       
  2386 	}
       
  2387 
       
  2388 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2389 
  2292 
  2390 	handled = 1;
  2293 	handled = 1;
  2391 
  2294 
  2392 	/* h/w no longer present (hotplug?) or major error, bail */
  2295 	/* h/w no longer present (hotplug?) or major error, bail */
  2393 	if (unlikely(status == 0xFFFF))
  2296 	if (unlikely(status == 0xFFFF))
  2394 		goto out;
  2297 		goto out;
  2395 
  2298 
  2396 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2299 	if (!tp->ecdev) {
  2397 
       
  2398 	if (dev != rtl_ec_net_dev) {
       
  2399 		/* close possible race's with dev_close */
  2300 		/* close possible race's with dev_close */
  2400 		if (unlikely(!netif_running(dev))) {
  2301 		if (unlikely(!netif_running(dev))) {
  2401 			RTL_W16 (IntrMask, 0);
  2302 			RTL_W16 (IntrMask, 0);
  2402 			goto out;
  2303 			goto out;
  2403 		}
  2304 		}
  2404 	}
  2305 	}
  2405 
  2306 
  2406 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2407 
       
  2408 	/* Acknowledge all of the current interrupt sources ASAP, but
  2307 	/* Acknowledge all of the current interrupt sources ASAP, but
  2409 	   an first get an additional status bit from CSCR. */
  2308 	   an first get an additional status bit from CSCR. */
  2410 	if (unlikely(status & RxUnderrun))
  2309 	if (unlikely(status & RxUnderrun))
  2411 		link_changed = RTL_R16 (CSCR) & CSCR_LinkChangeBit;
  2310 		link_changed = RTL_R16 (CSCR) & CSCR_LinkChangeBit;
  2412 
  2311 
  2414 	if (ackstat)
  2313 	if (ackstat)
  2415 		RTL_W16 (IntrStatus, ackstat);
  2314 		RTL_W16 (IntrStatus, ackstat);
  2416 
  2315 
  2417 	/* Receive packets are processed by poll routine.
  2316 	/* Receive packets are processed by poll routine.
  2418 	   If not running start it now. */
  2317 	   If not running start it now. */
  2419 
       
  2420 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
       
  2421 
       
  2422 	if (status & RxAckBits){
  2318 	if (status & RxAckBits){
  2423 		if (dev != rtl_ec_net_dev) {
  2319 		if (tp->ecdev) {
       
  2320 			/* EtherCAT device: Just receive all frames */
       
  2321 			rtl8139_rx(dev, tp, 100); // FIXME
       
  2322 		}
       
  2323 		else {
  2424 			/* Mark for polling */
  2324 			/* Mark for polling */
  2425 			if (netif_rx_schedule_prep(dev)) {
  2325 			if (netif_rx_schedule_prep(dev)) {
  2426 				RTL_W16_F (IntrMask, rtl8139_norx_intr_mask);
  2326 				RTL_W16_F (IntrMask, rtl8139_norx_intr_mask);
  2427 				__netif_rx_schedule (dev);
  2327 				__netif_rx_schedule (dev);
  2428 			}
  2328 			}
  2429 		} else {
       
  2430 			/* EtherCAT device: Just receive all frames */
       
  2431 			rtl8139_rx(dev, tp, 100); // FIXME
       
  2432 		}
  2329 		}
  2433 	}
  2330 	}
  2434 
       
  2435 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2436 
  2331 
  2437 	/* Check uncommon events with one test. */
  2332 	/* Check uncommon events with one test. */
  2438 	if (unlikely(status & (PCIErr | PCSTimeout | RxUnderrun | RxErr)))
  2333 	if (unlikely(status & (PCIErr | PCSTimeout | RxUnderrun | RxErr)))
  2439 		rtl8139_weird_interrupt (dev, tp, ioaddr,
  2334 		rtl8139_weird_interrupt (dev, tp, ioaddr,
  2440 					 status, link_changed);
  2335 					 status, link_changed);
  2443 		rtl8139_tx_interrupt (dev, tp, ioaddr);
  2338 		rtl8139_tx_interrupt (dev, tp, ioaddr);
  2444 		if (status & TxErr)
  2339 		if (status & TxErr)
  2445 			RTL_W16 (IntrStatus, TxErr);
  2340 			RTL_W16 (IntrStatus, TxErr);
  2446 	}
  2341 	}
  2447  out:
  2342  out:
  2448 
  2343 	if (!tp->ecdev) spin_unlock (&tp->lock);
  2449 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
       
  2450 
       
  2451 	if (dev != rtl_ec_net_dev) {
       
  2452 		spin_unlock (&tp->lock);
       
  2453 	}
       
  2454 
       
  2455 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2456 
  2344 
  2457 	DPRINTK ("%s: exiting interrupt, intr_status=%#4.4x.\n",
  2345 	DPRINTK ("%s: exiting interrupt, intr_status=%#4.4x.\n",
  2458 		 dev->name, RTL_R16 (IntrStatus));
  2346 		 dev->name, RTL_R16 (IntrStatus));
  2459 	return IRQ_RETVAL(handled);
  2347 	return IRQ_RETVAL(handled);
  2460 }
  2348 }
  2476 {
  2364 {
  2477 	struct rtl8139_private *tp = netdev_priv(dev);
  2365 	struct rtl8139_private *tp = netdev_priv(dev);
  2478 	void __iomem *ioaddr = tp->mmio_addr;
  2366 	void __iomem *ioaddr = tp->mmio_addr;
  2479 	unsigned long flags;
  2367 	unsigned long flags;
  2480 
  2368 
  2481 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2369 	if (tp->ecdev) {
  2482 
  2370 		/* Stop the chip's Tx and Rx DMA processes. */
  2483 	if (dev != rtl_ec_net_dev) {
  2371 		RTL_W8 (ChipCmd, 0);
       
  2372 
       
  2373 		/* Disable interrupts by clearing the interrupt mask. */
       
  2374 		RTL_W16 (IntrMask, 0);
       
  2375 
       
  2376 		/* Update the error counts. */
       
  2377 		tp->stats.rx_missed_errors += RTL_R32 (RxMissed);
       
  2378 		RTL_W32 (RxMissed, 0);
       
  2379 	} else {
  2484 		netif_stop_queue (dev);
  2380 		netif_stop_queue (dev);
  2485 
  2381 
  2486 		rtl8139_stop_thread(tp);
  2382 		rtl8139_stop_thread(tp);
  2487 
  2383 
  2488 		if (netif_msg_ifdown(tp))
  2384 		if (netif_msg_ifdown(tp))
  2503 
  2399 
  2504 		spin_unlock_irqrestore (&tp->lock, flags);
  2400 		spin_unlock_irqrestore (&tp->lock, flags);
  2505 
  2401 
  2506 		synchronize_irq (dev->irq);	/* racy, but that's ok here */
  2402 		synchronize_irq (dev->irq);	/* racy, but that's ok here */
  2507 		free_irq (dev->irq, dev);
  2403 		free_irq (dev->irq, dev);
  2508 	} else {
  2404 	}
  2509 		/* Stop the chip's Tx and Rx DMA processes. */
       
  2510 		RTL_W8 (ChipCmd, 0);
       
  2511 
       
  2512 		/* Disable interrupts by clearing the interrupt mask. */
       
  2513 		RTL_W16 (IntrMask, 0);
       
  2514 
       
  2515 		/* Update the error counts. */
       
  2516 		tp->stats.rx_missed_errors += RTL_R32 (RxMissed);
       
  2517 		RTL_W32 (RxMissed, 0);
       
  2518 	}
       
  2519 
       
  2520 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2521 
  2405 
  2522 	rtl8139_tx_clear (tp);
  2406 	rtl8139_tx_clear (tp);
  2523 
  2407 
  2524 	pci_free_consistent(tp->pci_dev, RX_BUF_TOT_LEN,
  2408 	pci_free_consistent(tp->pci_dev, RX_BUF_TOT_LEN,
  2525 			    tp->rx_ring, tp->rx_ring_dma);
  2409 			    tp->rx_ring, tp->rx_ring_dma);
  2731 static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  2615 static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  2732 {
  2616 {
  2733 	struct rtl8139_private *np = netdev_priv(dev);
  2617 	struct rtl8139_private *np = netdev_priv(dev);
  2734 	int rc;
  2618 	int rc;
  2735 
  2619 
  2736 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2620 	if (np->ecdev || !netif_running(dev))
  2737 
       
  2738 	if (dev == rtl_ec_net_dev || !netif_running(dev))
       
  2739 		return -EINVAL;
  2621 		return -EINVAL;
  2740 
       
  2741 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2742 
  2622 
  2743 	spin_lock_irq(&np->lock);
  2623 	spin_lock_irq(&np->lock);
  2744 	rc = generic_mii_ioctl(&np->mii, if_mii(rq), cmd, NULL);
  2624 	rc = generic_mii_ioctl(&np->mii, if_mii(rq), cmd, NULL);
  2745 	spin_unlock_irq(&np->lock);
  2625 	spin_unlock_irq(&np->lock);
  2746 
  2626 
  2752 {
  2632 {
  2753 	struct rtl8139_private *tp = netdev_priv(dev);
  2633 	struct rtl8139_private *tp = netdev_priv(dev);
  2754 	void __iomem *ioaddr = tp->mmio_addr;
  2634 	void __iomem *ioaddr = tp->mmio_addr;
  2755 	unsigned long flags;
  2635 	unsigned long flags;
  2756 
  2636 
  2757 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2637 	if (tp->ecdev || netif_running(dev)) {
  2758 
       
  2759 	if (dev == rtl_ec_net_dev || netif_running(dev)) {
       
  2760 		spin_lock_irqsave (&tp->lock, flags);
  2638 		spin_lock_irqsave (&tp->lock, flags);
  2761 		tp->stats.rx_missed_errors += RTL_R32 (RxMissed);
  2639 		tp->stats.rx_missed_errors += RTL_R32 (RxMissed);
  2762 		RTL_W32 (RxMissed, 0);
  2640 		RTL_W32 (RxMissed, 0);
  2763 		spin_unlock_irqrestore (&tp->lock, flags);
  2641 		spin_unlock_irqrestore (&tp->lock, flags);
  2764 	}
  2642 	}
  2765 
       
  2766 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2767 
  2643 
  2768 	return &tp->stats;
  2644 	return &tp->stats;
  2769 }
  2645 }
  2770 
  2646 
  2771 /* Set or clear the multicast filter for this adaptor.
  2647 /* Set or clear the multicast filter for this adaptor.
  2838 	void __iomem *ioaddr = tp->mmio_addr;
  2714 	void __iomem *ioaddr = tp->mmio_addr;
  2839 	unsigned long flags;
  2715 	unsigned long flags;
  2840 
  2716 
  2841 	pci_save_state (pdev);
  2717 	pci_save_state (pdev);
  2842 
  2718 
  2843 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2719 	if (tp->ecdev || !netif_running (dev))
  2844 
       
  2845 	if (dev == rtl_ec_net_dev || !netif_running (dev))
       
  2846 		return 0;
  2720 		return 0;
  2847 
       
  2848 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2849 
  2721 
  2850 	netif_device_detach (dev);
  2722 	netif_device_detach (dev);
  2851 
  2723 
  2852 	spin_lock_irqsave (&tp->lock, flags);
  2724 	spin_lock_irqsave (&tp->lock, flags);
  2853 
  2725 
  2868 
  2740 
  2869 
  2741 
  2870 static int rtl8139_resume (struct pci_dev *pdev)
  2742 static int rtl8139_resume (struct pci_dev *pdev)
  2871 {
  2743 {
  2872 	struct net_device *dev = pci_get_drvdata (pdev);
  2744 	struct net_device *dev = pci_get_drvdata (pdev);
       
  2745 	struct rtl8139_private *tp = netdev_priv(dev);
  2873 
  2746 
  2874 	pci_restore_state (pdev);
  2747 	pci_restore_state (pdev);
  2875 
  2748 	if (tp->ecdev || !netif_running (dev))
  2876 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
       
  2877 
       
  2878 	if (dev == rtl_ec_net_dev || !netif_running (dev))
       
  2879 		return 0;
  2749 		return 0;
  2880 
       
  2881 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2882 
       
  2883 	pci_set_power_state (pdev, PCI_D0);
  2750 	pci_set_power_state (pdev, PCI_D0);
  2884 	rtl8139_init_ring (dev);
  2751 	rtl8139_init_ring (dev);
  2885 	rtl8139_hw_start (dev);
  2752 	rtl8139_hw_start (dev);
  2886 	netif_device_attach (dev);
  2753 	netif_device_attach (dev);
  2887 	return 0;
  2754 	return 0;
  2902 };
  2769 };
  2903 
  2770 
  2904 
  2771 
  2905 static int __init rtl8139_init_module (void)
  2772 static int __init rtl8139_init_module (void)
  2906 {
  2773 {
  2907 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2774 	/* when we're a module, we always print a version message,
  2908 
  2775 	 * even if no 8139 board is found.
  2909 	printk(KERN_INFO RTL8139_DRIVER_NAME "\n");
  2776 	 */
  2910 	printk(KERN_INFO "ec_device_index is %i\n", ec_device_index);
  2777 #ifdef MODULE
  2911 
  2778 	printk (KERN_INFO RTL8139_DRIVER_NAME "\n");
  2912 	if (pci_module_init(&rtl8139_pci_driver) < 0) {
  2779 #endif
  2913 		printk(KERN_ERR "Failed to init PCI module.\n");
  2780 
  2914 		goto out_return;
  2781 	return pci_module_init (&rtl8139_pci_driver);
  2915 	}
       
  2916 
       
  2917 	if (rtl_ec_net_dev) {
       
  2918 		printk(KERN_INFO "Registering EtherCAT device...\n");
       
  2919 		if (!(rtl_ec_dev = ecdev_register(ec_device_master_index,
       
  2920 			rtl_ec_net_dev, ec_poll, THIS_MODULE))) {
       
  2921 			printk(KERN_ERR "Failed to register EtherCAT device!\n");
       
  2922 			goto out_pci;
       
  2923 		}
       
  2924 
       
  2925 		printk(KERN_INFO "Opening EtherCAT device...\n");
       
  2926 		if (ecdev_open(rtl_ec_dev)) {
       
  2927 			printk(KERN_ERR "Failed to open EtherCAT device!\n");
       
  2928 			goto out_unregister;
       
  2929 		}
       
  2930 
       
  2931 		printk(KERN_INFO "EtherCAT device ready.\n");
       
  2932 	} else {
       
  2933 		printk(KERN_WARNING "No EtherCAT device registered!\n");
       
  2934 	}
       
  2935 
       
  2936 	return 0;
       
  2937 
       
  2938     out_unregister:
       
  2939 	printk(KERN_INFO "Unregistering EtherCAT device...\n");
       
  2940 	ecdev_unregister(ec_device_master_index, rtl_ec_dev);
       
  2941 	rtl_ec_dev = NULL;
       
  2942     out_pci:
       
  2943 	pci_unregister_driver(&rtl8139_pci_driver);
       
  2944     out_return:
       
  2945 	return -1;
       
  2946 
       
  2947 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2948 }
  2782 }
  2949 
  2783 
  2950 
  2784 
  2951 static void __exit rtl8139_cleanup_module (void)
  2785 static void __exit rtl8139_cleanup_module (void)
  2952 {
  2786 {
  2953 	/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  2787 	pci_unregister_driver (&rtl8139_pci_driver);
  2954 
       
  2955 	printk(KERN_INFO "Cleaning up RTL8139-EtherCAT module...\n");
       
  2956 
       
  2957 	if (rtl_ec_net_dev) {
       
  2958 		printk(KERN_INFO "Closing EtherCAT device...\n");
       
  2959 		ecdev_close(rtl_ec_dev);
       
  2960 		printk(KERN_INFO "Unregistering EtherCAT device...\n");
       
  2961 		ecdev_unregister(ec_device_master_index, rtl_ec_dev);
       
  2962 		rtl_ec_dev = NULL;
       
  2963 	}
       
  2964 
       
  2965 	pci_unregister_driver(&rtl8139_pci_driver);
       
  2966 
       
  2967 	printk(KERN_INFO "RTL8139-EtherCAT module cleaned up.\n");
       
  2968 
       
  2969 	/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
       
  2970 }
  2788 }
  2971 
  2789 
  2972 
  2790 
  2973 module_init(rtl8139_init_module);
  2791 module_init(rtl8139_init_module);
  2974 module_exit(rtl8139_cleanup_module);
  2792 module_exit(rtl8139_cleanup_module);