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