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, &tp->ecdev, "8139too", board_idx, |
1116 if (dev != rtl_ec_net_dev) { |
1077 ec_poll, THIS_MODULE)) { |
|
1078 printk(KERN_ERR PFX "Failed to offer device.\n"); |
|
1079 goto err_out; |
|
1080 } |
|
1081 |
|
1082 if (!tp->ecdev) { |
1117 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); |
1118 i = register_netdev (dev); |
1084 i = register_netdev (dev); |
1119 if (i) goto err_out; |
1085 if (i) goto err_out; |
1120 } |
1086 } |
1121 |
|
1122 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1123 |
1087 |
1124 pci_set_drvdata (pdev, dev); |
1088 pci_set_drvdata (pdev, dev); |
1125 |
1089 |
1126 printk (KERN_INFO "%s: %s at 0x%lx, " |
1090 printk (KERN_INFO "%s: %s at 0x%lx, " |
1127 "%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, " |
1203 |
1172 |
1204 |
1173 |
1205 static void __devexit rtl8139_remove_one (struct pci_dev *pdev) |
1174 static void __devexit rtl8139_remove_one (struct pci_dev *pdev) |
1206 { |
1175 { |
1207 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); |
1208 |
1178 |
1209 assert (dev != NULL); |
1179 assert (dev != NULL); |
1210 |
1180 |
1211 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1181 if (tp->ecdev) { |
1212 |
1182 ecdev_close(tp->ecdev); |
1213 if (dev != rtl_ec_net_dev) { |
1183 ecdev_withdraw(tp->ecdev); |
|
1184 } |
|
1185 else { |
1214 unregister_netdev (dev); |
1186 unregister_netdev (dev); |
1215 } |
1187 } |
1216 |
|
1217 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1218 |
1188 |
1219 __rtl8139_cleanup_dev (dev); |
1189 __rtl8139_cleanup_dev (dev); |
1220 pci_disable_device (pdev); |
1190 pci_disable_device (pdev); |
1221 } |
1191 } |
1222 |
1192 |
1414 { |
1384 { |
1415 struct rtl8139_private *tp = netdev_priv(dev); |
1385 struct rtl8139_private *tp = netdev_priv(dev); |
1416 int retval; |
1386 int retval; |
1417 void __iomem *ioaddr = tp->mmio_addr; |
1387 void __iomem *ioaddr = tp->mmio_addr; |
1418 |
1388 |
1419 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1389 if (!tp->ecdev) { |
1420 |
|
1421 if (dev != rtl_ec_net_dev) { |
|
1422 retval = request_irq(dev->irq, rtl8139_interrupt, |
1390 retval = request_irq(dev->irq, rtl8139_interrupt, |
1423 IRQF_SHARED, dev->name, dev); |
1391 IRQF_SHARED, dev->name, dev); |
1424 if (retval) |
1392 if (retval) |
1425 return retval; |
1393 return retval; |
1426 } |
1394 } |
1427 |
|
1428 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1429 |
1395 |
1430 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, |
1431 &tp->tx_bufs_dma); |
1397 &tp->tx_bufs_dma); |
1432 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, |
1433 &tp->rx_ring_dma); |
1399 &tp->rx_ring_dma); |
1434 if (tp->tx_bufs == NULL || tp->rx_ring == NULL) { |
1400 if (tp->tx_bufs == NULL || tp->rx_ring == NULL) { |
1435 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1401 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 |
1402 |
1443 if (tp->tx_bufs) |
1403 if (tp->tx_bufs) |
1444 pci_free_consistent(tp->pci_dev, TX_BUF_TOT_LEN, |
1404 pci_free_consistent(tp->pci_dev, TX_BUF_TOT_LEN, |
1445 tp->tx_bufs, tp->tx_bufs_dma); |
1405 tp->tx_bufs, tp->tx_bufs_dma); |
1446 if (tp->rx_ring) |
1406 if (tp->rx_ring) |
1455 tp->tx_flag = (TX_FIFO_THRESH << 11) & 0x003f0000; |
1415 tp->tx_flag = (TX_FIFO_THRESH << 11) & 0x003f0000; |
1456 |
1416 |
1457 rtl8139_init_ring (dev); |
1417 rtl8139_init_ring (dev); |
1458 rtl8139_hw_start (dev); |
1418 rtl8139_hw_start (dev); |
1459 |
1419 |
1460 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1420 if (!tp->ecdev) { |
1461 |
|
1462 if (dev != rtl_ec_net_dev) { |
|
1463 netif_start_queue (dev); |
1421 netif_start_queue (dev); |
1464 |
1422 |
1465 if (netif_msg_ifup(tp)) |
1423 if (netif_msg_ifup(tp)) |
1466 printk(KERN_DEBUG "%s: rtl8139_open() ioaddr %#llx IRQ %d" |
1424 printk(KERN_DEBUG "%s: rtl8139_open() ioaddr %#llx IRQ %d" |
1467 " GP Pins %2.2x %s-duplex.\n", dev->name, |
1425 " GP Pins %2.2x %s-duplex.\n", dev->name, |
1469 dev->irq, RTL_R8 (MediaStatus), |
1427 dev->irq, RTL_R8 (MediaStatus), |
1470 tp->mii.full_duplex ? "full" : "half"); |
1428 tp->mii.full_duplex ? "full" : "half"); |
1471 rtl8139_start_thread(tp); |
1429 rtl8139_start_thread(tp); |
1472 } |
1430 } |
1473 |
1431 |
1474 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1475 |
|
1476 return 0; |
1432 return 0; |
1477 } |
1433 } |
1478 |
1434 |
1479 |
1435 |
1480 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) |
1481 { |
1437 { |
1482 struct rtl8139_private *tp = netdev_priv(dev); |
1438 struct rtl8139_private *tp = netdev_priv(dev); |
1483 |
1439 |
1484 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1440 if (tp->ecdev) { |
1485 |
1441 void __iomem *ioaddr = tp->mmio_addr; |
1486 if (dev != rtl_ec_net_dev) { |
1442 uint16_t state = RTL_R16(BasicModeStatus) & BMSR_LSTATUS; |
|
1443 ecdev_link_state(tp->ecdev, state ? 1 : 0); |
|
1444 } |
|
1445 else { |
1487 if (tp->phys[0] >= 0) { |
1446 if (tp->phys[0] >= 0) { |
1488 mii_check_media(&tp->mii, netif_msg_link(tp), init_media); |
1447 mii_check_media(&tp->mii, netif_msg_link(tp), init_media); |
1489 } |
1448 } |
1490 } else { |
1449 } |
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 } |
1450 } |
1498 |
1451 |
1499 /* Start the hardware at open or resume. */ |
1452 /* Start the hardware at open or resume. */ |
1500 static void rtl8139_hw_start (struct net_device *dev) |
1453 static void rtl8139_hw_start (struct net_device *dev) |
1501 { |
1454 { |
1556 /* make sure RxTx has started */ |
1509 /* make sure RxTx has started */ |
1557 tmp = RTL_R8 (ChipCmd); |
1510 tmp = RTL_R8 (ChipCmd); |
1558 if ((!(tmp & CmdRxEnb)) || (!(tmp & CmdTxEnb))) |
1511 if ((!(tmp & CmdRxEnb)) || (!(tmp & CmdTxEnb))) |
1559 RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb); |
1512 RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb); |
1560 |
1513 |
1561 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1514 if (!tp->ecdev) |
1562 |
|
1563 if (dev != rtl_ec_net_dev) { |
|
1564 /* Enable all known interrupts by setting the interrupt mask. */ |
1515 /* Enable all known interrupts by setting the interrupt mask. */ |
1565 RTL_W16 (IntrMask, rtl8139_intr_mask); |
1516 RTL_W16 (IntrMask, rtl8139_intr_mask); |
1566 } |
|
1567 |
|
1568 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1569 } |
1517 } |
1570 |
1518 |
1571 |
1519 |
1572 /* Initialize the Rx and Tx rings, along with various 'dev' bits. */ |
1520 /* Initialize the Rx and Tx rings, along with various 'dev' bits. */ |
1573 static void rtl8139_init_ring (struct net_device *dev) |
1521 static void rtl8139_init_ring (struct net_device *dev) |
1811 /* disable Tx ASAP, if not already */ |
1759 /* disable Tx ASAP, if not already */ |
1812 tmp8 = RTL_R8 (ChipCmd); |
1760 tmp8 = RTL_R8 (ChipCmd); |
1813 if (tmp8 & CmdTxEnb) |
1761 if (tmp8 & CmdTxEnb) |
1814 RTL_W8 (ChipCmd, CmdRxEnb); |
1762 RTL_W8 (ChipCmd, CmdRxEnb); |
1815 |
1763 |
1816 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1764 if (tp->ecdev) { |
1817 |
1765 rtl8139_tx_clear (tp); |
1818 if (dev != rtl_ec_net_dev) { |
1766 rtl8139_hw_start (dev); |
|
1767 } |
|
1768 else { |
1819 spin_lock_bh(&tp->rx_lock); |
1769 spin_lock_bh(&tp->rx_lock); |
1820 /* Disable interrupts by clearing the interrupt mask. */ |
1770 /* Disable interrupts by clearing the interrupt mask. */ |
1821 RTL_W16 (IntrMask, 0x0000); |
1771 RTL_W16 (IntrMask, 0x0000); |
1822 |
1772 |
1823 /* Stop a shared interrupt from scavenging while we are. */ |
1773 /* Stop a shared interrupt from scavenging while we are. */ |
1829 if (netif_running(dev)) { |
1779 if (netif_running(dev)) { |
1830 rtl8139_hw_start (dev); |
1780 rtl8139_hw_start (dev); |
1831 netif_wake_queue (dev); |
1781 netif_wake_queue (dev); |
1832 } |
1782 } |
1833 spin_unlock_bh(&tp->rx_lock); |
1783 spin_unlock_bh(&tp->rx_lock); |
1834 } else { |
1784 } |
1835 rtl8139_tx_clear (tp); |
|
1836 rtl8139_hw_start (dev); |
|
1837 } |
|
1838 |
|
1839 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1840 } |
1785 } |
1841 |
1786 |
1842 static void rtl8139_tx_timeout (struct net_device *dev) |
1787 static void rtl8139_tx_timeout (struct net_device *dev) |
1843 { |
1788 { |
1844 struct rtl8139_private *tp = netdev_priv(dev); |
1789 struct rtl8139_private *tp = netdev_priv(dev); |
1845 |
1790 |
1846 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1791 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); |
1792 INIT_WORK(&tp->thread, rtl8139_tx_timeout_task, dev); |
1850 schedule_delayed_work(&tp->thread, next_tick); |
1793 schedule_delayed_work(&tp->thread, next_tick); |
1851 } else |
1794 } else |
1852 tp->watchdog_fired = 1; |
1795 tp->watchdog_fired = 1; |
1853 |
1796 |
1854 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1855 } |
1797 } |
1856 |
1798 |
1857 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) |
1858 { |
1800 { |
1859 struct rtl8139_private *tp = netdev_priv(dev); |
1801 struct rtl8139_private *tp = netdev_priv(dev); |
1863 unsigned long flags; |
1805 unsigned long flags; |
1864 |
1806 |
1865 /* Calculate the next Tx descriptor entry. */ |
1807 /* Calculate the next Tx descriptor entry. */ |
1866 entry = tp->cur_tx % NUM_TX_DESC; |
1808 entry = tp->cur_tx % NUM_TX_DESC; |
1867 |
1809 |
1868 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
1869 |
|
1870 /* Note: the chip doesn't have auto-pad! */ |
1810 /* Note: the chip doesn't have auto-pad! */ |
1871 if (likely(len < TX_BUF_SIZE)) { |
1811 if (likely(len < TX_BUF_SIZE)) { |
1872 if (len < ETH_ZLEN) |
1812 if (len < ETH_ZLEN) |
1873 memset(tp->tx_buf[entry], 0, ETH_ZLEN); |
1813 memset(tp->tx_buf[entry], 0, ETH_ZLEN); |
1874 skb_copy_and_csum_dev(skb, tp->tx_buf[entry]); |
1814 skb_copy_and_csum_dev(skb, tp->tx_buf[entry]); |
1875 if (dev != rtl_ec_net_dev) { |
1815 if (!tp->ecdev) dev_kfree_skb(skb); |
1876 dev_kfree_skb(skb); |
|
1877 } |
|
1878 } else { |
1816 } else { |
1879 if (dev != rtl_ec_net_dev) { |
1817 if (!tp->ecdev) dev_kfree_skb(skb); |
1880 dev_kfree_skb(skb); |
|
1881 } |
|
1882 tp->stats.tx_dropped++; |
1818 tp->stats.tx_dropped++; |
1883 return 0; |
1819 return 0; |
1884 } |
1820 } |
1885 |
1821 |
1886 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1822 if (tp->ecdev) { |
1887 |
1823 RTL_W32_F (TxStatus0 + (entry * sizeof (u32)), |
1888 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 { |
1889 spin_lock_irqsave(&tp->lock, flags); |
1832 spin_lock_irqsave(&tp->lock, flags); |
1890 |
1833 |
1891 RTL_W32_F (TxStatus0 + (entry * sizeof (u32)), |
1834 RTL_W32_F (TxStatus0 + (entry * sizeof (u32)), |
1892 tp->tx_flag | max(len, (unsigned int)ETH_ZLEN)); |
1835 tp->tx_flag | max(len, (unsigned int)ETH_ZLEN)); |
1893 |
1836 |
1971 |
1903 |
1972 dirty_tx++; |
1904 dirty_tx++; |
1973 tx_left--; |
1905 tx_left--; |
1974 } |
1906 } |
1975 |
1907 |
1976 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
1977 |
|
1978 #ifndef RTL8139_NDEBUG |
1908 #ifndef RTL8139_NDEBUG |
1979 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) { |
1980 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", |
1981 dev->name, dirty_tx, tp->cur_tx); |
1911 dev->name, dirty_tx, tp->cur_tx); |
1982 dirty_tx += NUM_TX_DESC; |
1912 dirty_tx += NUM_TX_DESC; |
1983 } |
1913 } |
1984 #endif /* RTL8139_NDEBUG */ |
1914 #endif /* RTL8139_NDEBUG */ |
1985 |
1915 |
1986 /* 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 */ |
1987 if (tp->dirty_tx != dirty_tx) { |
1917 if (tp->dirty_tx != dirty_tx) { |
1988 tp->dirty_tx = dirty_tx; |
1918 tp->dirty_tx = dirty_tx; |
1989 mb(); |
1919 mb(); |
1990 |
1920 if (!tp->ecdev) netif_wake_queue (dev); |
1991 if (dev != rtl_ec_net_dev) { |
1921 } |
1992 netif_wake_queue (dev); |
|
1993 } |
|
1994 } |
|
1995 |
|
1996 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1997 } |
1922 } |
1998 |
1923 |
1999 |
1924 |
2000 /* TODO: clean this up! Rx reset need not be this intensive */ |
1925 /* TODO: clean this up! Rx reset need not be this intensive */ |
2001 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, |
2124 DPRINTK ("%s: In rtl8139_rx(), current %4.4x BufAddr %4.4x," |
2049 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, |
2050 " free to %4.4x, Cmd %2.2x.\n", dev->name, (u16)cur_rx, |
2126 RTL_R16 (RxBufAddr), |
2051 RTL_R16 (RxBufAddr), |
2127 RTL_R16 (RxBufPtr), RTL_R8 (ChipCmd)); |
2052 RTL_R16 (RxBufPtr), RTL_R8 (ChipCmd)); |
2128 |
2053 |
2129 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2054 while ((tp->ecdev || netif_running(dev)) |
2130 |
|
2131 while ((dev == rtl_ec_net_dev || netif_running(dev)) |
|
2132 && received < budget |
2055 && received < budget |
2133 && (RTL_R8 (ChipCmd) & RxBufEmpty) == 0) { |
2056 && (RTL_R8 (ChipCmd) & RxBufEmpty) == 0) { |
2134 |
|
2135 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2136 |
|
2137 u32 ring_offset = cur_rx % RX_BUF_LEN; |
2057 u32 ring_offset = cur_rx % RX_BUF_LEN; |
2138 u32 rx_status; |
2058 u32 rx_status; |
2139 unsigned int pkt_size; |
2059 unsigned int pkt_size; |
2140 struct sk_buff *skb; |
2060 struct sk_buff *skb; |
2141 |
2061 |
2144 /* read size+status of next frame from DMA ring buffer */ |
2064 /* read size+status of next frame from DMA ring buffer */ |
2145 rx_status = le32_to_cpu (*(u32 *) (rx_ring + ring_offset)); |
2065 rx_status = le32_to_cpu (*(u32 *) (rx_ring + ring_offset)); |
2146 rx_size = rx_status >> 16; |
2066 rx_size = rx_status >> 16; |
2147 pkt_size = rx_size - 4; |
2067 pkt_size = rx_size - 4; |
2148 |
2068 |
2149 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2069 if (!tp->ecdev) { |
2150 |
|
2151 if (dev != rtl_ec_net_dev) { |
|
2152 if (netif_msg_rx_status(tp)) |
2070 if (netif_msg_rx_status(tp)) |
2153 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," |
2154 " cur %4.4x.\n", dev->name, rx_status, |
2072 " cur %4.4x.\n", dev->name, rx_status, |
2155 rx_size, cur_rx); |
2073 rx_size, cur_rx); |
2156 } |
2074 } |
2157 |
|
2158 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2159 |
|
2160 #if RTL8139_DEBUG > 2 |
2075 #if RTL8139_DEBUG > 2 |
2161 { |
2076 { |
2162 int i; |
2077 int i; |
2163 DPRINTK ("%s: Frame contents ", dev->name); |
2078 DPRINTK ("%s: Frame contents ", dev->name); |
2164 for (i = 0; i < 70; i++) |
2079 for (i = 0; i < 70; i++) |
2202 rtl8139_rx_err (rx_status, dev, tp, ioaddr); |
2117 rtl8139_rx_err (rx_status, dev, tp, ioaddr); |
2203 received = -1; |
2118 received = -1; |
2204 goto out; |
2119 goto out; |
2205 } |
2120 } |
2206 |
2121 |
2207 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2122 if (tp->ecdev) { |
2208 |
2123 ecdev_receive(tp->ecdev, |
2209 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 { |
2210 /* Malloc up new buffer, compatible with net-2e. */ |
2130 /* Malloc up new buffer, compatible with net-2e. */ |
2211 /* Omit the four octet CRC from the length. */ |
2131 /* Omit the four octet CRC from the length. */ |
2212 |
2132 |
2213 skb = dev_alloc_skb (pkt_size + 2); |
2133 skb = dev_alloc_skb (pkt_size + 2); |
2214 if (likely(skb)) { |
2134 if (likely(skb)) { |
2229 |
2149 |
2230 netif_receive_skb (skb); |
2150 netif_receive_skb (skb); |
2231 } else { |
2151 } else { |
2232 if (net_ratelimit()) |
2152 if (net_ratelimit()) |
2233 printk(KERN_WARNING |
2153 printk(KERN_WARNING |
2234 "%s: Memory squeeze, dropping packet.\n", |
2154 "%s: Memory squeeze, dropping packet.\n", |
2235 dev->name); |
2155 dev->name); |
2236 tp->stats.rx_dropped++; |
2156 tp->stats.rx_dropped++; |
2237 } |
2157 } |
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 } |
2158 } |
2245 |
|
2246 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2247 |
|
2248 received++; |
2159 received++; |
2249 |
2160 |
2250 cur_rx = (cur_rx + rx_size + 4 + 3) & ~3; |
2161 cur_rx = (cur_rx + rx_size + 4 + 3) & ~3; |
2251 RTL_W16 (RxBufPtr, (u16) (cur_rx - 16)); |
2162 RTL_W16 (RxBufPtr, (u16) (cur_rx - 16)); |
2252 |
2163 |
2368 void __iomem *ioaddr = tp->mmio_addr; |
2275 void __iomem *ioaddr = tp->mmio_addr; |
2369 u16 status, ackstat; |
2276 u16 status, ackstat; |
2370 int link_changed = 0; /* avoid bogus "uninit" warning */ |
2277 int link_changed = 0; /* avoid bogus "uninit" warning */ |
2371 int handled = 0; |
2278 int handled = 0; |
2372 |
2279 |
2373 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2280 if (tp->ecdev) { |
2374 |
2281 status = RTL_R16 (IntrStatus); |
2375 if (dev != rtl_ec_net_dev) { |
2282 } |
|
2283 else { |
2376 spin_lock (&tp->lock); |
2284 spin_lock (&tp->lock); |
2377 status = RTL_R16 (IntrStatus); |
2285 status = RTL_R16 (IntrStatus); |
2378 |
2286 |
2379 /* shared irq? */ |
2287 /* shared irq? */ |
2380 if (unlikely((status & rtl8139_intr_mask) == 0)) |
2288 if (unlikely((status & rtl8139_intr_mask) == 0)) |
2381 goto out; |
2289 goto out; |
2382 } else { |
2290 } |
2383 status = RTL_R16 (IntrStatus); |
|
2384 } |
|
2385 |
|
2386 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2387 |
2291 |
2388 handled = 1; |
2292 handled = 1; |
2389 |
2293 |
2390 /* h/w no longer present (hotplug?) or major error, bail */ |
2294 /* h/w no longer present (hotplug?) or major error, bail */ |
2391 if (unlikely(status == 0xFFFF)) |
2295 if (unlikely(status == 0xFFFF)) |
2392 goto out; |
2296 goto out; |
2393 |
2297 |
2394 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2298 if (!tp->ecdev) { |
2395 |
|
2396 if (dev != rtl_ec_net_dev) { |
|
2397 /* close possible race's with dev_close */ |
2299 /* close possible race's with dev_close */ |
2398 if (unlikely(!netif_running(dev))) { |
2300 if (unlikely(!netif_running(dev))) { |
2399 RTL_W16 (IntrMask, 0); |
2301 RTL_W16 (IntrMask, 0); |
2400 goto out; |
2302 goto out; |
2401 } |
2303 } |
2402 } |
2304 } |
2403 |
2305 |
2404 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2405 |
|
2406 /* Acknowledge all of the current interrupt sources ASAP, but |
2306 /* Acknowledge all of the current interrupt sources ASAP, but |
2407 an first get an additional status bit from CSCR. */ |
2307 an first get an additional status bit from CSCR. */ |
2408 if (unlikely(status & RxUnderrun)) |
2308 if (unlikely(status & RxUnderrun)) |
2409 link_changed = RTL_R16 (CSCR) & CSCR_LinkChangeBit; |
2309 link_changed = RTL_R16 (CSCR) & CSCR_LinkChangeBit; |
2410 |
2310 |
2412 if (ackstat) |
2312 if (ackstat) |
2413 RTL_W16 (IntrStatus, ackstat); |
2313 RTL_W16 (IntrStatus, ackstat); |
2414 |
2314 |
2415 /* Receive packets are processed by poll routine. |
2315 /* Receive packets are processed by poll routine. |
2416 If not running start it now. */ |
2316 If not running start it now. */ |
2417 |
|
2418 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
2419 |
|
2420 if (status & RxAckBits){ |
2317 if (status & RxAckBits){ |
2421 if (dev != rtl_ec_net_dev) { |
2318 if (tp->ecdev) { |
|
2319 /* EtherCAT device: Just receive all frames */ |
|
2320 rtl8139_rx(dev, tp, 100); // FIXME |
|
2321 } |
|
2322 else { |
2422 /* Mark for polling */ |
2323 /* Mark for polling */ |
2423 if (netif_rx_schedule_prep(dev)) { |
2324 if (netif_rx_schedule_prep(dev)) { |
2424 RTL_W16_F (IntrMask, rtl8139_norx_intr_mask); |
2325 RTL_W16_F (IntrMask, rtl8139_norx_intr_mask); |
2425 __netif_rx_schedule (dev); |
2326 __netif_rx_schedule (dev); |
2426 } |
2327 } |
2427 } else { |
|
2428 /* EtherCAT device: Just receive all frames */ |
|
2429 rtl8139_rx(dev, tp, 100); // FIXME |
|
2430 } |
2328 } |
2431 } |
2329 } |
2432 |
|
2433 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2434 |
2330 |
2435 /* Check uncommon events with one test. */ |
2331 /* Check uncommon events with one test. */ |
2436 if (unlikely(status & (PCIErr | PCSTimeout | RxUnderrun | RxErr))) |
2332 if (unlikely(status & (PCIErr | PCSTimeout | RxUnderrun | RxErr))) |
2437 rtl8139_weird_interrupt (dev, tp, ioaddr, |
2333 rtl8139_weird_interrupt (dev, tp, ioaddr, |
2438 status, link_changed); |
2334 status, link_changed); |
2441 rtl8139_tx_interrupt (dev, tp, ioaddr); |
2337 rtl8139_tx_interrupt (dev, tp, ioaddr); |
2442 if (status & TxErr) |
2338 if (status & TxErr) |
2443 RTL_W16 (IntrStatus, TxErr); |
2339 RTL_W16 (IntrStatus, TxErr); |
2444 } |
2340 } |
2445 out: |
2341 out: |
2446 |
2342 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 |
2343 |
2455 DPRINTK ("%s: exiting interrupt, intr_status=%#4.4x.\n", |
2344 DPRINTK ("%s: exiting interrupt, intr_status=%#4.4x.\n", |
2456 dev->name, RTL_R16 (IntrStatus)); |
2345 dev->name, RTL_R16 (IntrStatus)); |
2457 return IRQ_RETVAL(handled); |
2346 return IRQ_RETVAL(handled); |
2458 } |
2347 } |
2474 { |
2363 { |
2475 struct rtl8139_private *tp = netdev_priv(dev); |
2364 struct rtl8139_private *tp = netdev_priv(dev); |
2476 void __iomem *ioaddr = tp->mmio_addr; |
2365 void __iomem *ioaddr = tp->mmio_addr; |
2477 unsigned long flags; |
2366 unsigned long flags; |
2478 |
2367 |
2479 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2368 if (tp->ecdev) { |
2480 |
2369 /* Stop the chip's Tx and Rx DMA processes. */ |
2481 if (dev != rtl_ec_net_dev) { |
2370 RTL_W8 (ChipCmd, 0); |
|
2371 |
|
2372 /* Disable interrupts by clearing the interrupt mask. */ |
|
2373 RTL_W16 (IntrMask, 0); |
|
2374 |
|
2375 /* Update the error counts. */ |
|
2376 tp->stats.rx_missed_errors += RTL_R32 (RxMissed); |
|
2377 RTL_W32 (RxMissed, 0); |
|
2378 } else { |
2482 netif_stop_queue (dev); |
2379 netif_stop_queue (dev); |
2483 |
2380 |
2484 rtl8139_stop_thread(tp); |
2381 rtl8139_stop_thread(tp); |
2485 |
2382 |
2486 if (netif_msg_ifdown(tp)) |
2383 if (netif_msg_ifdown(tp)) |
2501 |
2398 |
2502 spin_unlock_irqrestore (&tp->lock, flags); |
2399 spin_unlock_irqrestore (&tp->lock, flags); |
2503 |
2400 |
2504 synchronize_irq (dev->irq); /* racy, but that's ok here */ |
2401 synchronize_irq (dev->irq); /* racy, but that's ok here */ |
2505 free_irq (dev->irq, dev); |
2402 free_irq (dev->irq, dev); |
2506 } else { |
2403 } |
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 |
2404 |
2520 rtl8139_tx_clear (tp); |
2405 rtl8139_tx_clear (tp); |
2521 |
2406 |
2522 pci_free_consistent(tp->pci_dev, RX_BUF_TOT_LEN, |
2407 pci_free_consistent(tp->pci_dev, RX_BUF_TOT_LEN, |
2523 tp->rx_ring, tp->rx_ring_dma); |
2408 tp->rx_ring, tp->rx_ring_dma); |
2729 static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
2614 static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
2730 { |
2615 { |
2731 struct rtl8139_private *np = netdev_priv(dev); |
2616 struct rtl8139_private *np = netdev_priv(dev); |
2732 int rc; |
2617 int rc; |
2733 |
2618 |
2734 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2619 if (np->ecdev || !netif_running(dev)) |
2735 |
|
2736 if (dev == rtl_ec_net_dev || !netif_running(dev)) |
|
2737 return -EINVAL; |
2620 return -EINVAL; |
2738 |
|
2739 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2740 |
2621 |
2741 spin_lock_irq(&np->lock); |
2622 spin_lock_irq(&np->lock); |
2742 rc = generic_mii_ioctl(&np->mii, if_mii(rq), cmd, NULL); |
2623 rc = generic_mii_ioctl(&np->mii, if_mii(rq), cmd, NULL); |
2743 spin_unlock_irq(&np->lock); |
2624 spin_unlock_irq(&np->lock); |
2744 |
2625 |
2750 { |
2631 { |
2751 struct rtl8139_private *tp = netdev_priv(dev); |
2632 struct rtl8139_private *tp = netdev_priv(dev); |
2752 void __iomem *ioaddr = tp->mmio_addr; |
2633 void __iomem *ioaddr = tp->mmio_addr; |
2753 unsigned long flags; |
2634 unsigned long flags; |
2754 |
2635 |
2755 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2636 if (tp->ecdev || netif_running(dev)) { |
2756 |
|
2757 if (dev == rtl_ec_net_dev || netif_running(dev)) { |
|
2758 spin_lock_irqsave (&tp->lock, flags); |
2637 spin_lock_irqsave (&tp->lock, flags); |
2759 tp->stats.rx_missed_errors += RTL_R32 (RxMissed); |
2638 tp->stats.rx_missed_errors += RTL_R32 (RxMissed); |
2760 RTL_W32 (RxMissed, 0); |
2639 RTL_W32 (RxMissed, 0); |
2761 spin_unlock_irqrestore (&tp->lock, flags); |
2640 spin_unlock_irqrestore (&tp->lock, flags); |
2762 } |
2641 } |
2763 |
|
2764 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2765 |
2642 |
2766 return &tp->stats; |
2643 return &tp->stats; |
2767 } |
2644 } |
2768 |
2645 |
2769 /* Set or clear the multicast filter for this adaptor. |
2646 /* Set or clear the multicast filter for this adaptor. |
2863 |
2736 |
2864 |
2737 |
2865 static int rtl8139_resume (struct pci_dev *pdev) |
2738 static int rtl8139_resume (struct pci_dev *pdev) |
2866 { |
2739 { |
2867 struct net_device *dev = pci_get_drvdata (pdev); |
2740 struct net_device *dev = pci_get_drvdata (pdev); |
|
2741 struct rtl8139_private *tp = netdev_priv(dev); |
2868 |
2742 |
2869 pci_restore_state (pdev); |
2743 pci_restore_state (pdev); |
2870 |
2744 if (tp->ecdev || !netif_running (dev)) |
2871 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
2872 |
|
2873 if (dev == rtl_ec_net_dev || !netif_running (dev)) |
|
2874 return 0; |
2745 return 0; |
2875 |
|
2876 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2877 |
|
2878 pci_set_power_state (pdev, PCI_D0); |
2746 pci_set_power_state (pdev, PCI_D0); |
2879 rtl8139_init_ring (dev); |
2747 rtl8139_init_ring (dev); |
2880 rtl8139_hw_start (dev); |
2748 rtl8139_hw_start (dev); |
2881 netif_device_attach (dev); |
2749 netif_device_attach (dev); |
2882 return 0; |
2750 return 0; |
2897 }; |
2765 }; |
2898 |
2766 |
2899 |
2767 |
2900 static int __init rtl8139_init_module (void) |
2768 static int __init rtl8139_init_module (void) |
2901 { |
2769 { |
2902 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2770 /* when we're a module, we always print a version message, |
2903 |
2771 * even if no 8139 board is found. |
2904 printk(KERN_INFO RTL8139_DRIVER_NAME "\n"); |
2772 */ |
2905 printk(KERN_INFO "ec_device_index is %i\n", ec_device_index); |
2773 #ifdef MODULE |
2906 |
2774 printk (KERN_INFO RTL8139_DRIVER_NAME "\n"); |
2907 if (pci_register_driver(&rtl8139_pci_driver) < 0) { |
2775 #endif |
2908 printk(KERN_ERR "Failed to init PCI module.\n"); |
2776 |
2909 goto out_return; |
2777 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 } |
2778 } |
2944 |
2779 |
2945 |
2780 |
2946 static void __exit rtl8139_cleanup_module (void) |
2781 static void __exit rtl8139_cleanup_module (void) |
2947 { |
2782 { |
2948 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2783 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 } |
2784 } |
2966 |
2785 |
2967 |
2786 |
2968 module_init(rtl8139_init_module); |
2787 module_init(rtl8139_init_module); |
2969 module_exit(rtl8139_cleanup_module); |
2788 module_exit(rtl8139_cleanup_module); |