151 #include <linux/crc32.h> |
151 #include <linux/crc32.h> |
152 #include <asm/io.h> |
152 #include <asm/io.h> |
153 #include <asm/uaccess.h> |
153 #include <asm/uaccess.h> |
154 #include <asm/irq.h> |
154 #include <asm/irq.h> |
155 |
155 |
156 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
157 |
|
158 #include "../globals.h" |
156 #include "../globals.h" |
159 #include "ecdev.h" |
157 #include "ecdev.h" |
160 |
158 |
161 #define RTL8139_DRIVER_NAME DRV_NAME \ |
159 #define RTL8139_DRIVER_NAME DRV_NAME \ |
162 " EtherCAT-capable Fast Ethernet driver " \ |
160 " EtherCAT-capable Fast Ethernet driver " \ |
163 DRV_VERSION ", master " EC_MASTER_VERSION |
161 DRV_VERSION ", master " EC_MASTER_VERSION |
164 |
|
165 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
166 |
162 |
167 #define PFX DRV_NAME ": " |
163 #define PFX DRV_NAME ": " |
168 |
164 |
169 /* Default Message level */ |
165 /* Default Message level */ |
170 #define RTL8139_DEF_MSG_ENABLE (NETIF_MSG_DRV | \ |
166 #define RTL8139_DEF_MSG_ENABLE (NETIF_MSG_DRV | \ |
212 The RTL chips use a 64 element hash table based on the Ethernet CRC. */ |
208 The RTL chips use a 64 element hash table based on the Ethernet CRC. */ |
213 static int multicast_filter_limit = 32; |
209 static int multicast_filter_limit = 32; |
214 |
210 |
215 /* bitmapped message enable number */ |
211 /* bitmapped message enable number */ |
216 static int debug = -1; |
212 static int debug = -1; |
217 |
|
218 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
219 |
|
220 static int ec_device_index = -1; |
|
221 static int ec_device_master_index = 0; |
|
222 static ec_device_t *rtl_ec_dev; |
|
223 struct net_device *rtl_ec_net_dev = NULL; |
|
224 |
|
225 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
226 |
213 |
227 /* |
214 /* |
228 * Receive ring size |
215 * Receive ring size |
229 * Warning: 64K ring has hardware issues and may lock up. |
216 * Warning: 64K ring has hardware issues and may lock up. |
230 */ |
217 */ |
336 {PCI_ANY_ID, 0x8139, 0x13d1, 0xab06, 0, 0, RTL8139 }, |
323 {PCI_ANY_ID, 0x8139, 0x13d1, 0xab06, 0, 0, RTL8139 }, |
337 |
324 |
338 {0,} |
325 {0,} |
339 }; |
326 }; |
340 |
327 |
341 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
342 |
|
343 /* prevent driver from being loaded automatically */ |
328 /* prevent driver from being loaded automatically */ |
344 //MODULE_DEVICE_TABLE (pci, rtl8139_pci_tbl); |
329 //MODULE_DEVICE_TABLE (pci, rtl8139_pci_tbl); |
345 |
|
346 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
347 |
330 |
348 static struct { |
331 static struct { |
349 const char str[ETH_GSTRING_LEN]; |
332 const char str[ETH_GSTRING_LEN]; |
350 } ethtool_stats_keys[] = { |
333 } ethtool_stats_keys[] = { |
351 { "early_rx" }, |
334 { "early_rx" }, |
662 struct rtl_extra_stats xstats; |
645 struct rtl_extra_stats xstats; |
663 int time_to_die; |
646 int time_to_die; |
664 struct mii_if_info mii; |
647 struct mii_if_info mii; |
665 unsigned int regs_len; |
648 unsigned int regs_len; |
666 unsigned long fifo_copy_timeout; |
649 unsigned long fifo_copy_timeout; |
|
650 |
|
651 ec_device_t *ecdev; |
667 }; |
652 }; |
668 |
|
669 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
670 |
653 |
671 MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>"); |
654 MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>"); |
672 MODULE_DESCRIPTION("RealTek RTL-8139 EtherCAT driver"); |
655 MODULE_DESCRIPTION("RealTek RTL-8139 EtherCAT driver"); |
673 MODULE_LICENSE("GPL"); |
656 MODULE_LICENSE("GPL"); |
674 MODULE_VERSION(EC_MASTER_VERSION); |
657 MODULE_VERSION(EC_MASTER_VERSION); |
675 |
|
676 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
677 |
658 |
678 module_param(multicast_filter_limit, int, 0); |
659 module_param(multicast_filter_limit, int, 0); |
679 module_param_array(media, int, NULL, 0); |
660 module_param_array(media, int, NULL, 0); |
680 module_param_array(full_duplex, int, NULL, 0); |
661 module_param_array(full_duplex, int, NULL, 0); |
681 module_param(debug, int, 0); |
662 module_param(debug, int, 0); |
682 MODULE_PARM_DESC (debug, "8139too bitmapped message enable number"); |
663 MODULE_PARM_DESC (debug, "8139too bitmapped message enable number"); |
683 MODULE_PARM_DESC (multicast_filter_limit, "8139too maximum number of filtered multicast addresses"); |
664 MODULE_PARM_DESC (multicast_filter_limit, "8139too maximum number of filtered multicast addresses"); |
684 MODULE_PARM_DESC (media, "8139too: Bits 4+9: force full duplex, bit 5: 100Mbps"); |
665 MODULE_PARM_DESC (media, "8139too: Bits 4+9: force full duplex, bit 5: 100Mbps"); |
685 MODULE_PARM_DESC (full_duplex, "8139too: Force full duplex for board(s) (1)"); |
666 MODULE_PARM_DESC (full_duplex, "8139too: Force full duplex for board(s) (1)"); |
686 |
667 |
687 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
688 |
|
689 module_param(ec_device_index, int, -1); |
|
690 module_param(ec_device_master_index, int, 0); |
|
691 MODULE_PARM_DESC(ec_device_index, |
|
692 "Index of the device reserved for EtherCAT."); |
|
693 MODULE_PARM_DESC(ec_device_master_index, |
|
694 "Index of the EtherCAT master to register the device."); |
|
695 |
|
696 void ec_poll(struct net_device *); |
668 void ec_poll(struct net_device *); |
697 |
|
698 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
699 |
669 |
700 static int read_eeprom (void __iomem *ioaddr, int location, int addr_len); |
670 static int read_eeprom (void __iomem *ioaddr, int location, int addr_len); |
701 static int rtl8139_open (struct net_device *dev); |
671 static int rtl8139_open (struct net_device *dev); |
702 static int mdio_read (struct net_device *dev, int phy_id, int location); |
672 static int mdio_read (struct net_device *dev, int phy_id, int location); |
703 static void mdio_write (struct net_device *dev, int phy_id, int location, |
673 static void mdio_write (struct net_device *dev, int phy_id, int location, |
1044 return i; |
1014 return i; |
1045 |
1015 |
1046 assert (dev != NULL); |
1016 assert (dev != NULL); |
1047 tp = netdev_priv(dev); |
1017 tp = netdev_priv(dev); |
1048 |
1018 |
1049 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
1050 |
|
1051 if (board_idx == ec_device_index) { |
|
1052 rtl_ec_net_dev = dev; |
|
1053 strcpy(dev->name, "ec0"); |
|
1054 } |
|
1055 |
|
1056 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1057 |
|
1058 ioaddr = tp->mmio_addr; |
1019 ioaddr = tp->mmio_addr; |
1059 assert (ioaddr != NULL); |
1020 assert (ioaddr != NULL); |
1060 |
1021 |
1061 addr_len = read_eeprom (ioaddr, 0, 8) == 0x8129 ? 8 : 6; |
1022 addr_len = read_eeprom (ioaddr, 0, 8) == 0x8129 ? 8 : 6; |
1062 for (i = 0; i < 3; i++) |
1023 for (i = 0; i < 3; i++) |
1104 tp->mii.mdio_write = mdio_write; |
1065 tp->mii.mdio_write = mdio_write; |
1105 tp->mii.phy_id_mask = 0x3f; |
1066 tp->mii.phy_id_mask = 0x3f; |
1106 tp->mii.reg_num_mask = 0x1f; |
1067 tp->mii.reg_num_mask = 0x1f; |
1107 |
1068 |
1108 /* dev is fully set up and ready to use now */ |
1069 /* dev is fully set up and ready to use now */ |
1109 |
1070 |
1110 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1071 // offer device to EtherCAT master module |
1111 |
1072 if (ecdev_offer(dev, ec_poll, THIS_MODULE, &tp->ecdev)) { |
1112 if (dev != rtl_ec_net_dev) { |
1073 printk(KERN_ERR PFX "Failed to offer device.\n"); |
|
1074 goto err_out; |
|
1075 } |
|
1076 |
|
1077 if (!tp->ecdev) { |
1113 DPRINTK("about to register device named %s (%p)...\n", dev->name, dev); |
1078 DPRINTK("about to register device named %s (%p)...\n", dev->name, dev); |
1114 i = register_netdev (dev); |
1079 i = register_netdev (dev); |
1115 if (i) goto err_out; |
1080 if (i) goto err_out; |
1116 } |
1081 } |
1117 |
|
1118 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1119 |
1082 |
1120 pci_set_drvdata (pdev, dev); |
1083 pci_set_drvdata (pdev, dev); |
1121 |
1084 |
1122 printk (KERN_INFO "%s: %s at 0x%lx, " |
1085 printk (KERN_INFO "%s: %s at 0x%lx, " |
1123 "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x, " |
1086 "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x, " |
1199 |
1167 |
1200 |
1168 |
1201 static void __devexit rtl8139_remove_one (struct pci_dev *pdev) |
1169 static void __devexit rtl8139_remove_one (struct pci_dev *pdev) |
1202 { |
1170 { |
1203 struct net_device *dev = pci_get_drvdata (pdev); |
1171 struct net_device *dev = pci_get_drvdata (pdev); |
|
1172 struct rtl8139_private *tp = netdev_priv(dev); |
1204 |
1173 |
1205 assert (dev != NULL); |
1174 assert (dev != NULL); |
1206 |
1175 |
1207 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1176 if (tp->ecdev) { |
1208 |
1177 ecdev_close(tp->ecdev); |
1209 if (dev != rtl_ec_net_dev) { |
1178 ecdev_withdraw(tp->ecdev); |
|
1179 } |
|
1180 else { |
1210 unregister_netdev (dev); |
1181 unregister_netdev (dev); |
1211 } |
1182 } |
1212 |
|
1213 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1214 |
1183 |
1215 __rtl8139_cleanup_dev (dev); |
1184 __rtl8139_cleanup_dev (dev); |
1216 pci_disable_device (pdev); |
1185 pci_disable_device (pdev); |
1217 } |
1186 } |
1218 |
1187 |
1410 { |
1379 { |
1411 struct rtl8139_private *tp = netdev_priv(dev); |
1380 struct rtl8139_private *tp = netdev_priv(dev); |
1412 int retval; |
1381 int retval; |
1413 void __iomem *ioaddr = tp->mmio_addr; |
1382 void __iomem *ioaddr = tp->mmio_addr; |
1414 |
1383 |
1415 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1384 if (!tp->ecdev) { |
1416 |
|
1417 if (dev != rtl_ec_net_dev) { |
|
1418 retval = request_irq(dev->irq, rtl8139_interrupt, |
1385 retval = request_irq(dev->irq, rtl8139_interrupt, |
1419 SA_SHIRQ, dev->name, dev); |
1386 SA_SHIRQ, dev->name, dev); |
1420 if (retval) |
1387 if (retval) |
1421 return retval; |
1388 return retval; |
1422 } |
1389 } |
1423 |
|
1424 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1425 |
1390 |
1426 tp->tx_bufs = pci_alloc_consistent(tp->pci_dev, TX_BUF_TOT_LEN, |
1391 tp->tx_bufs = pci_alloc_consistent(tp->pci_dev, TX_BUF_TOT_LEN, |
1427 &tp->tx_bufs_dma); |
1392 &tp->tx_bufs_dma); |
1428 tp->rx_ring = pci_alloc_consistent(tp->pci_dev, RX_BUF_TOT_LEN, |
1393 tp->rx_ring = pci_alloc_consistent(tp->pci_dev, RX_BUF_TOT_LEN, |
1429 &tp->rx_ring_dma); |
1394 &tp->rx_ring_dma); |
1430 if (tp->tx_bufs == NULL || tp->rx_ring == NULL) { |
1395 if (tp->tx_bufs == NULL || tp->rx_ring == NULL) { |
1431 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1396 if (!tp->ecdev) free_irq(dev->irq, dev); |
1432 |
|
1433 if (dev != rtl_ec_net_dev) { |
|
1434 free_irq(dev->irq, dev); |
|
1435 } |
|
1436 |
|
1437 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1438 |
|
1439 if (tp->tx_bufs) |
1397 if (tp->tx_bufs) |
1440 pci_free_consistent(tp->pci_dev, TX_BUF_TOT_LEN, |
1398 pci_free_consistent(tp->pci_dev, TX_BUF_TOT_LEN, |
1441 tp->tx_bufs, tp->tx_bufs_dma); |
1399 tp->tx_bufs, tp->tx_bufs_dma); |
1442 if (tp->rx_ring) |
1400 if (tp->rx_ring) |
1443 pci_free_consistent(tp->pci_dev, RX_BUF_TOT_LEN, |
1401 pci_free_consistent(tp->pci_dev, RX_BUF_TOT_LEN, |
1451 tp->tx_flag = (TX_FIFO_THRESH << 11) & 0x003f0000; |
1409 tp->tx_flag = (TX_FIFO_THRESH << 11) & 0x003f0000; |
1452 |
1410 |
1453 rtl8139_init_ring (dev); |
1411 rtl8139_init_ring (dev); |
1454 rtl8139_hw_start (dev); |
1412 rtl8139_hw_start (dev); |
1455 |
1413 |
1456 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1414 if (!tp->ecdev) { |
1457 |
|
1458 if (dev != rtl_ec_net_dev) { |
|
1459 netif_start_queue (dev); |
1415 netif_start_queue (dev); |
1460 |
1416 |
1461 if (netif_msg_ifup(tp)) |
1417 if (netif_msg_ifup(tp)) |
1462 printk(KERN_DEBUG "%s: rtl8139_open() ioaddr %#lx IRQ %d" |
1418 printk(KERN_DEBUG "%s: rtl8139_open() ioaddr %#lx IRQ %d" |
1463 " GP Pins %2.2x %s-duplex.\n", |
1419 " GP Pins %2.2x %s-duplex.\n", |
1466 tp->mii.full_duplex ? "full" : "half"); |
1422 tp->mii.full_duplex ? "full" : "half"); |
1467 |
1423 |
1468 rtl8139_start_thread(dev); |
1424 rtl8139_start_thread(dev); |
1469 } |
1425 } |
1470 |
1426 |
1471 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1472 |
|
1473 return 0; |
1427 return 0; |
1474 } |
1428 } |
1475 |
1429 |
1476 |
1430 |
1477 static void rtl_check_media (struct net_device *dev, unsigned int init_media) |
1431 static void rtl_check_media (struct net_device *dev, unsigned int init_media) |
1478 { |
1432 { |
1479 struct rtl8139_private *tp = netdev_priv(dev); |
1433 struct rtl8139_private *tp = netdev_priv(dev); |
1480 |
1434 |
1481 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1435 if (tp->ecdev) { |
1482 |
1436 void __iomem *ioaddr = tp->mmio_addr; |
1483 if (dev != rtl_ec_net_dev) { |
1437 uint16_t state = RTL_R16(BasicModeStatus) & BMSR_LSTATUS; |
|
1438 ecdev_set_link(tp->ecdev, state ? 1 : 0); |
|
1439 } |
|
1440 else { |
1484 if (tp->phys[0] >= 0) { |
1441 if (tp->phys[0] >= 0) { |
1485 mii_check_media(&tp->mii, netif_msg_link(tp), init_media); |
1442 mii_check_media(&tp->mii, netif_msg_link(tp), init_media); |
1486 } |
1443 } |
1487 } else { |
1444 } |
1488 void __iomem *ioaddr = tp->mmio_addr; |
|
1489 uint16_t state = RTL_R16(BasicModeStatus) & BMSR_LSTATUS; |
|
1490 ecdev_link_state(rtl_ec_dev, state ? 1 : 0); |
|
1491 } |
|
1492 |
|
1493 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1494 } |
1445 } |
1495 |
1446 |
1496 /* Start the hardware at open or resume. */ |
1447 /* Start the hardware at open or resume. */ |
1497 static void rtl8139_hw_start (struct net_device *dev) |
1448 static void rtl8139_hw_start (struct net_device *dev) |
1498 { |
1449 { |
1553 /* make sure RxTx has started */ |
1504 /* make sure RxTx has started */ |
1554 tmp = RTL_R8 (ChipCmd); |
1505 tmp = RTL_R8 (ChipCmd); |
1555 if ((!(tmp & CmdRxEnb)) || (!(tmp & CmdTxEnb))) |
1506 if ((!(tmp & CmdRxEnb)) || (!(tmp & CmdTxEnb))) |
1556 RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb); |
1507 RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb); |
1557 |
1508 |
1558 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1509 if (!tp->ecdev) |
1559 |
|
1560 if (dev != rtl_ec_net_dev) { |
|
1561 /* Enable all known interrupts by setting the interrupt mask. */ |
1510 /* Enable all known interrupts by setting the interrupt mask. */ |
1562 RTL_W16 (IntrMask, rtl8139_intr_mask); |
1511 RTL_W16 (IntrMask, rtl8139_intr_mask); |
1563 } |
|
1564 |
|
1565 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1566 } |
1512 } |
1567 |
1513 |
1568 |
1514 |
1569 /* Initialize the Rx and Tx rings, along with various 'dev' bits. */ |
1515 /* Initialize the Rx and Tx rings, along with various 'dev' bits. */ |
1570 static void rtl8139_init_ring (struct net_device *dev) |
1516 static void rtl8139_init_ring (struct net_device *dev) |
1819 /* disable Tx ASAP, if not already */ |
1765 /* disable Tx ASAP, if not already */ |
1820 tmp8 = RTL_R8 (ChipCmd); |
1766 tmp8 = RTL_R8 (ChipCmd); |
1821 if (tmp8 & CmdTxEnb) |
1767 if (tmp8 & CmdTxEnb) |
1822 RTL_W8 (ChipCmd, CmdRxEnb); |
1768 RTL_W8 (ChipCmd, CmdRxEnb); |
1823 |
1769 |
1824 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1770 if (tp->ecdev) { |
1825 |
1771 rtl8139_tx_clear (tp); |
1826 if (dev != rtl_ec_net_dev) { |
1772 rtl8139_hw_start (dev); |
1827 spin_lock(&tp->rx_lock); |
1773 } |
1828 /* Disable interrupts by clearing the interrupt mask. */ |
1774 else { |
1829 RTL_W16 (IntrMask, 0x0000); |
1775 spin_lock(&tp->rx_lock); |
1830 |
1776 /* Disable interrupts by clearing the interrupt mask. */ |
1831 /* Stop a shared interrupt from scavenging while we are. */ |
1777 RTL_W16 (IntrMask, 0x0000); |
1832 spin_lock_irqsave (&tp->lock, flags); |
1778 |
1833 rtl8139_tx_clear (tp); |
1779 /* Stop a shared interrupt from scavenging while we are. */ |
1834 spin_unlock_irqrestore (&tp->lock, flags); |
1780 spin_lock_irqsave (&tp->lock, flags); |
1835 |
1781 rtl8139_tx_clear (tp); |
1836 /* ...and finally, reset everything */ |
1782 spin_unlock_irqrestore (&tp->lock, flags); |
1837 if (netif_running(dev)) { |
1783 |
1838 rtl8139_hw_start (dev); |
1784 /* ...and finally, reset everything */ |
1839 netif_wake_queue (dev); |
1785 if (netif_running(dev)) { |
1840 } |
1786 rtl8139_hw_start (dev); |
1841 spin_unlock(&tp->rx_lock); |
1787 netif_wake_queue (dev); |
1842 } else { |
1788 } |
1843 rtl8139_tx_clear (tp); |
1789 spin_unlock(&tp->rx_lock); |
1844 rtl8139_hw_start (dev); |
1790 } |
1845 } |
|
1846 |
|
1847 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1848 } |
1791 } |
1849 |
1792 |
1850 |
1793 |
1851 static int rtl8139_start_xmit (struct sk_buff *skb, struct net_device *dev) |
1794 static int rtl8139_start_xmit (struct sk_buff *skb, struct net_device *dev) |
1852 { |
1795 { |
1855 unsigned int entry; |
1798 unsigned int entry; |
1856 unsigned int len = skb->len; |
1799 unsigned int len = skb->len; |
1857 |
1800 |
1858 /* Calculate the next Tx descriptor entry. */ |
1801 /* Calculate the next Tx descriptor entry. */ |
1859 entry = tp->cur_tx % NUM_TX_DESC; |
1802 entry = tp->cur_tx % NUM_TX_DESC; |
1860 |
|
1861 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
1862 |
1803 |
1863 /* Note: the chip doesn't have auto-pad! */ |
1804 /* Note: the chip doesn't have auto-pad! */ |
1864 if (likely(len < TX_BUF_SIZE)) { |
1805 if (likely(len < TX_BUF_SIZE)) { |
1865 if (len < ETH_ZLEN) |
1806 if (len < ETH_ZLEN) |
1866 memset(tp->tx_buf[entry], 0, ETH_ZLEN); |
1807 memset(tp->tx_buf[entry], 0, ETH_ZLEN); |
1867 skb_copy_and_csum_dev(skb, tp->tx_buf[entry]); |
1808 skb_copy_and_csum_dev(skb, tp->tx_buf[entry]); |
1868 if (dev != rtl_ec_net_dev) { |
1809 if (!tp->ecdev) dev_kfree_skb(skb); |
1869 dev_kfree_skb(skb); |
|
1870 } |
|
1871 } else { |
1810 } else { |
1872 if (dev != rtl_ec_net_dev) { |
1811 if (!tp->ecdev) dev_kfree_skb(skb); |
1873 dev_kfree_skb(skb); |
|
1874 } |
|
1875 tp->stats.tx_dropped++; |
1812 tp->stats.tx_dropped++; |
1876 return 0; |
1813 return 0; |
1877 } |
1814 } |
1878 |
1815 |
1879 if (dev != rtl_ec_net_dev) { |
1816 if (!tp->ecdev) spin_lock_irq(&tp->lock); |
1880 spin_lock_irq(&tp->lock); |
|
1881 } |
|
1882 |
|
1883 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1884 |
|
1885 RTL_W32_F (TxStatus0 + (entry * sizeof (u32)), |
1817 RTL_W32_F (TxStatus0 + (entry * sizeof (u32)), |
1886 tp->tx_flag | max(len, (unsigned int)ETH_ZLEN)); |
1818 tp->tx_flag | max(len, (unsigned int)ETH_ZLEN)); |
1887 |
1819 |
1888 dev->trans_start = jiffies; |
1820 dev->trans_start = jiffies; |
1889 |
1821 |
1890 tp->cur_tx++; |
1822 tp->cur_tx++; |
1891 wmb(); |
1823 wmb(); |
1892 |
1824 |
1893 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1825 if (!tp->ecdev) { |
1894 |
|
1895 if (dev != rtl_ec_net_dev) { |
|
1896 if ((tp->cur_tx - NUM_TX_DESC) == tp->dirty_tx) |
1826 if ((tp->cur_tx - NUM_TX_DESC) == tp->dirty_tx) |
1897 netif_stop_queue (dev); |
1827 netif_stop_queue (dev); |
1898 spin_unlock_irq(&tp->lock); |
1828 spin_unlock_irq(&tp->lock); |
1899 |
1829 |
1900 if (netif_msg_tx_queued(tp)) |
1830 if (netif_msg_tx_queued(tp)) |
1901 printk (KERN_DEBUG "%s: Queued Tx packet size %u to slot %d.\n", |
1831 printk (KERN_DEBUG "%s: Queued Tx packet size %u to slot %d.\n", |
1902 dev->name, len, entry); |
1832 dev->name, len, entry); |
1903 } |
1833 } |
1904 |
|
1905 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1906 |
1834 |
1907 return 0; |
1835 return 0; |
1908 } |
1836 } |
1909 |
1837 |
1910 |
1838 |
1959 |
1887 |
1960 dirty_tx++; |
1888 dirty_tx++; |
1961 tx_left--; |
1889 tx_left--; |
1962 } |
1890 } |
1963 |
1891 |
1964 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
1965 |
|
1966 #ifndef RTL8139_NDEBUG |
1892 #ifndef RTL8139_NDEBUG |
1967 if (dev != rtl_ec_net_dev && tp->cur_tx - dirty_tx > NUM_TX_DESC) { |
1893 if (!tp->ecdev && tp->cur_tx - dirty_tx > NUM_TX_DESC) { |
1968 printk (KERN_ERR "%s: Out-of-sync dirty pointer, %ld vs. %ld.\n", |
1894 printk (KERN_ERR "%s: Out-of-sync dirty pointer, %ld vs. %ld.\n", |
1969 dev->name, dirty_tx, tp->cur_tx); |
1895 dev->name, dirty_tx, tp->cur_tx); |
1970 dirty_tx += NUM_TX_DESC; |
1896 dirty_tx += NUM_TX_DESC; |
1971 } |
1897 } |
1972 #endif /* RTL8139_NDEBUG */ |
1898 #endif /* RTL8139_NDEBUG */ |
1973 |
1899 |
1974 /* only wake the queue if we did work, and the queue is stopped */ |
1900 /* only wake the queue if we did work, and the queue is stopped */ |
1975 if (tp->dirty_tx != dirty_tx) { |
1901 if (tp->dirty_tx != dirty_tx) { |
1976 tp->dirty_tx = dirty_tx; |
1902 tp->dirty_tx = dirty_tx; |
1977 mb(); |
1903 mb(); |
1978 |
1904 if (!tp->ecdev) netif_wake_queue (dev); |
1979 if (dev != rtl_ec_net_dev) { |
1905 } |
1980 netif_wake_queue (dev); |
|
1981 } |
|
1982 } |
|
1983 |
|
1984 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1985 } |
1906 } |
1986 |
1907 |
1987 |
1908 |
1988 /* TODO: clean this up! Rx reset need not be this intensive */ |
1909 /* TODO: clean this up! Rx reset need not be this intensive */ |
1989 static void rtl8139_rx_err (u32 rx_status, struct net_device *dev, |
1910 static void rtl8139_rx_err (u32 rx_status, struct net_device *dev, |
2112 DPRINTK ("%s: In rtl8139_rx(), current %4.4x BufAddr %4.4x," |
2033 DPRINTK ("%s: In rtl8139_rx(), current %4.4x BufAddr %4.4x," |
2113 " free to %4.4x, Cmd %2.2x.\n", dev->name, (u16)cur_rx, |
2034 " free to %4.4x, Cmd %2.2x.\n", dev->name, (u16)cur_rx, |
2114 RTL_R16 (RxBufAddr), |
2035 RTL_R16 (RxBufAddr), |
2115 RTL_R16 (RxBufPtr), RTL_R8 (ChipCmd)); |
2036 RTL_R16 (RxBufPtr), RTL_R8 (ChipCmd)); |
2116 |
2037 |
2117 |
2038 while ((tp->ecdev || netif_running(dev)) |
2118 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
2119 |
|
2120 while ((dev == rtl_ec_net_dev || netif_running(dev)) |
|
2121 && received < budget |
2039 && received < budget |
2122 && (RTL_R8 (ChipCmd) & RxBufEmpty) == 0) { |
2040 && (RTL_R8 (ChipCmd) & RxBufEmpty) == 0) { |
2123 |
|
2124 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2125 |
|
2126 u32 ring_offset = cur_rx % RX_BUF_LEN; |
2041 u32 ring_offset = cur_rx % RX_BUF_LEN; |
2127 u32 rx_status; |
2042 u32 rx_status; |
2128 unsigned int pkt_size; |
2043 unsigned int pkt_size; |
2129 struct sk_buff *skb; |
2044 struct sk_buff *skb; |
2130 |
2045 |
2133 /* read size+status of next frame from DMA ring buffer */ |
2048 /* read size+status of next frame from DMA ring buffer */ |
2134 rx_status = le32_to_cpu (*(u32 *) (rx_ring + ring_offset)); |
2049 rx_status = le32_to_cpu (*(u32 *) (rx_ring + ring_offset)); |
2135 rx_size = rx_status >> 16; |
2050 rx_size = rx_status >> 16; |
2136 pkt_size = rx_size - 4; |
2051 pkt_size = rx_size - 4; |
2137 |
2052 |
2138 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2053 if (!tp->ecdev) { |
2139 |
|
2140 if (dev != rtl_ec_net_dev) { |
|
2141 if (netif_msg_rx_status(tp)) |
2054 if (netif_msg_rx_status(tp)) |
2142 printk(KERN_DEBUG "%s: rtl8139_rx() status %4.4x, size %4.4x," |
2055 printk(KERN_DEBUG "%s: rtl8139_rx() status %4.4x, size %4.4x," |
2143 " cur %4.4x.\n", dev->name, rx_status, |
2056 " cur %4.4x.\n", dev->name, rx_status, |
2144 rx_size, cur_rx); |
2057 rx_size, cur_rx); |
2145 } |
2058 } |
2146 |
|
2147 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2148 |
|
2149 #if RTL8139_DEBUG > 2 |
2059 #if RTL8139_DEBUG > 2 |
2150 { |
2060 { |
2151 int i; |
2061 int i; |
2152 DPRINTK ("%s: Frame contents ", dev->name); |
2062 DPRINTK ("%s: Frame contents ", dev->name); |
2153 for (i = 0; i < 70; i++) |
2063 for (i = 0; i < 70; i++) |
2191 rtl8139_rx_err (rx_status, dev, tp, ioaddr); |
2101 rtl8139_rx_err (rx_status, dev, tp, ioaddr); |
2192 received = -1; |
2102 received = -1; |
2193 goto out; |
2103 goto out; |
2194 } |
2104 } |
2195 |
2105 |
2196 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2106 if (tp->ecdev) { |
2197 |
2107 ecdev_receive(tp->ecdev, |
2198 if (dev != rtl_ec_net_dev) { |
2108 &rx_ring[ring_offset + 4], pkt_size); |
|
2109 dev->last_rx = jiffies; |
|
2110 tp->stats.rx_bytes += pkt_size; |
|
2111 tp->stats.rx_packets++; |
|
2112 } |
|
2113 else { |
2199 /* Malloc up new buffer, compatible with net-2e. */ |
2114 /* Malloc up new buffer, compatible with net-2e. */ |
2200 /* Omit the four octet CRC from the length. */ |
2115 /* Omit the four octet CRC from the length. */ |
2201 |
2116 |
2202 skb = dev_alloc_skb (pkt_size + 2); |
2117 skb = dev_alloc_skb (pkt_size + 2); |
2203 if (likely(skb)) { |
2118 if (likely(skb)) { |
2218 |
2133 |
2219 netif_receive_skb (skb); |
2134 netif_receive_skb (skb); |
2220 } else { |
2135 } else { |
2221 if (net_ratelimit()) |
2136 if (net_ratelimit()) |
2222 printk(KERN_WARNING |
2137 printk(KERN_WARNING |
2223 "%s: Memory squeeze, dropping packet.\n", |
2138 "%s: Memory squeeze, dropping packet.\n", |
2224 dev->name); |
2139 dev->name); |
2225 tp->stats.rx_dropped++; |
2140 tp->stats.rx_dropped++; |
2226 } |
2141 } |
2227 } else { |
|
2228 ecdev_receive(rtl_ec_dev, |
|
2229 &rx_ring[ring_offset + 4], pkt_size); |
|
2230 dev->last_rx = jiffies; |
|
2231 tp->stats.rx_bytes += pkt_size; |
|
2232 tp->stats.rx_packets++; |
|
2233 } |
2142 } |
2234 |
|
2235 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2236 |
|
2237 received++; |
2143 received++; |
2238 |
2144 |
2239 cur_rx = (cur_rx + rx_size + 4 + 3) & ~3; |
2145 cur_rx = (cur_rx + rx_size + 4 + 3) & ~3; |
2240 RTL_W16 (RxBufPtr, (u16) (cur_rx - 16)); |
2146 RTL_W16 (RxBufPtr, (u16) (cur_rx - 16)); |
2241 |
2147 |
2337 spin_unlock(&tp->rx_lock); |
2243 spin_unlock(&tp->rx_lock); |
2338 |
2244 |
2339 return !done; |
2245 return !done; |
2340 } |
2246 } |
2341 |
2247 |
2342 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
2343 |
|
2344 void ec_poll(struct net_device *dev) |
2248 void ec_poll(struct net_device *dev) |
2345 { |
2249 { |
2346 rtl8139_interrupt(0, dev, NULL); |
2250 rtl8139_interrupt(0, dev, NULL); |
2347 } |
2251 } |
2348 |
|
2349 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2350 |
2252 |
2351 /* The interrupt handler does all of the Rx thread work and cleans up |
2253 /* The interrupt handler does all of the Rx thread work and cleans up |
2352 after the Tx thread. */ |
2254 after the Tx thread. */ |
2353 irqreturn_t rtl8139_interrupt (int irq, void *dev_instance, |
2255 static irqreturn_t rtl8139_interrupt (int irq, void *dev_instance, |
2354 struct pt_regs *regs) |
2256 struct pt_regs *regs) |
2355 { |
2257 { |
2356 struct net_device *dev = (struct net_device *) dev_instance; |
2258 struct net_device *dev = (struct net_device *) dev_instance; |
2357 struct rtl8139_private *tp = netdev_priv(dev); |
2259 struct rtl8139_private *tp = netdev_priv(dev); |
2358 void __iomem *ioaddr = tp->mmio_addr; |
2260 void __iomem *ioaddr = tp->mmio_addr; |
2359 u16 status, ackstat; |
2261 u16 status, ackstat; |
2360 int link_changed = 0; /* avoid bogus "uninit" warning */ |
2262 int link_changed = 0; /* avoid bogus "uninit" warning */ |
2361 int handled = 0; |
2263 int handled = 0; |
2362 |
2264 |
2363 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2265 if (tp->ecdev) { |
2364 |
2266 status = RTL_R16 (IntrStatus); |
2365 if (dev != rtl_ec_net_dev) { |
2267 } |
|
2268 else { |
2366 spin_lock (&tp->lock); |
2269 spin_lock (&tp->lock); |
2367 status = RTL_R16 (IntrStatus); |
2270 status = RTL_R16 (IntrStatus); |
2368 |
2271 |
2369 /* shared irq? */ |
2272 /* shared irq? */ |
2370 if (unlikely((status & rtl8139_intr_mask) == 0)) |
2273 if (unlikely((status & rtl8139_intr_mask) == 0)) |
2371 goto out; |
2274 goto out; |
2372 } else { |
2275 } |
2373 status = RTL_R16 (IntrStatus); |
|
2374 } |
|
2375 |
|
2376 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2377 |
2276 |
2378 handled = 1; |
2277 handled = 1; |
2379 |
2278 |
2380 /* h/w no longer present (hotplug?) or major error, bail */ |
2279 /* h/w no longer present (hotplug?) or major error, bail */ |
2381 if (unlikely(status == 0xFFFF)) |
2280 if (unlikely(status == 0xFFFF)) |
2382 goto out; |
2281 goto out; |
2383 |
2282 |
2384 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2283 if (!tp->ecdev) { |
2385 |
|
2386 if (dev != rtl_ec_net_dev) { |
|
2387 /* close possible race's with dev_close */ |
2284 /* close possible race's with dev_close */ |
2388 if (unlikely(!netif_running(dev))) { |
2285 if (unlikely(!netif_running(dev))) { |
2389 RTL_W16 (IntrMask, 0); |
2286 RTL_W16 (IntrMask, 0); |
2390 goto out; |
2287 goto out; |
2391 } |
2288 } |
2392 } |
2289 } |
2393 |
2290 |
2394 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2395 |
|
2396 /* Acknowledge all of the current interrupt sources ASAP, but |
2291 /* Acknowledge all of the current interrupt sources ASAP, but |
2397 an first get an additional status bit from CSCR. */ |
2292 an first get an additional status bit from CSCR. */ |
2398 if (unlikely(status & RxUnderrun)) |
2293 if (unlikely(status & RxUnderrun)) |
2399 link_changed = RTL_R16 (CSCR) & CSCR_LinkChangeBit; |
2294 link_changed = RTL_R16 (CSCR) & CSCR_LinkChangeBit; |
2400 |
2295 |
2402 if (ackstat) |
2297 if (ackstat) |
2403 RTL_W16 (IntrStatus, ackstat); |
2298 RTL_W16 (IntrStatus, ackstat); |
2404 |
2299 |
2405 /* Receive packets are processed by poll routine. |
2300 /* Receive packets are processed by poll routine. |
2406 If not running start it now. */ |
2301 If not running start it now. */ |
2407 |
|
2408 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
2409 |
|
2410 if (status & RxAckBits){ |
2302 if (status & RxAckBits){ |
2411 if (dev != rtl_ec_net_dev) { |
2303 if (tp->ecdev) { |
|
2304 /* EtherCAT device: Just receive all frames */ |
|
2305 rtl8139_rx(dev, tp, 100); // FIXME |
|
2306 } |
|
2307 else { |
2412 /* Mark for polling */ |
2308 /* Mark for polling */ |
2413 if (netif_rx_schedule_prep(dev)) { |
2309 if (netif_rx_schedule_prep(dev)) { |
2414 RTL_W16_F (IntrMask, rtl8139_norx_intr_mask); |
2310 RTL_W16_F (IntrMask, rtl8139_norx_intr_mask); |
2415 __netif_rx_schedule (dev); |
2311 __netif_rx_schedule (dev); |
2416 } |
2312 } |
2417 } else { |
|
2418 /* EtherCAT device: Just receive all frames */ |
|
2419 rtl8139_rx(dev, tp, 100); // FIXME |
|
2420 } |
2313 } |
2421 } |
2314 } |
2422 |
|
2423 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2424 |
2315 |
2425 /* Check uncommon events with one test. */ |
2316 /* Check uncommon events with one test. */ |
2426 if (unlikely(status & (PCIErr | PCSTimeout | RxUnderrun | RxErr))) |
2317 if (unlikely(status & (PCIErr | PCSTimeout | RxUnderrun | RxErr))) |
2427 rtl8139_weird_interrupt (dev, tp, ioaddr, |
2318 rtl8139_weird_interrupt (dev, tp, ioaddr, |
2428 status, link_changed); |
2319 status, link_changed); |
2431 rtl8139_tx_interrupt (dev, tp, ioaddr); |
2322 rtl8139_tx_interrupt (dev, tp, ioaddr); |
2432 if (status & TxErr) |
2323 if (status & TxErr) |
2433 RTL_W16 (IntrStatus, TxErr); |
2324 RTL_W16 (IntrStatus, TxErr); |
2434 } |
2325 } |
2435 out: |
2326 out: |
2436 |
2327 if (!tp->ecdev) spin_unlock (&tp->lock); |
2437 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
2438 |
|
2439 if (dev != rtl_ec_net_dev) { |
|
2440 spin_unlock (&tp->lock); |
|
2441 } |
|
2442 |
|
2443 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2444 |
2328 |
2445 DPRINTK ("%s: exiting interrupt, intr_status=%#4.4x.\n", |
2329 DPRINTK ("%s: exiting interrupt, intr_status=%#4.4x.\n", |
2446 dev->name, RTL_R16 (IntrStatus)); |
2330 dev->name, RTL_R16 (IntrStatus)); |
2447 return IRQ_RETVAL(handled); |
2331 return IRQ_RETVAL(handled); |
2448 } |
2332 } |
2465 struct rtl8139_private *tp = netdev_priv(dev); |
2349 struct rtl8139_private *tp = netdev_priv(dev); |
2466 void __iomem *ioaddr = tp->mmio_addr; |
2350 void __iomem *ioaddr = tp->mmio_addr; |
2467 int ret = 0; |
2351 int ret = 0; |
2468 unsigned long flags; |
2352 unsigned long flags; |
2469 |
2353 |
2470 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2354 if (tp->ecdev) { |
2471 |
2355 /* Stop the chip's Tx and Rx DMA processes. */ |
2472 if (dev != rtl_ec_net_dev) { |
2356 RTL_W8 (ChipCmd, 0); |
|
2357 |
|
2358 /* Disable interrupts by clearing the interrupt mask. */ |
|
2359 RTL_W16 (IntrMask, 0); |
|
2360 |
|
2361 /* Update the error counts. */ |
|
2362 tp->stats.rx_missed_errors += RTL_R32 (RxMissed); |
|
2363 RTL_W32 (RxMissed, 0); |
|
2364 } else { |
2473 netif_stop_queue (dev); |
2365 netif_stop_queue (dev); |
2474 |
2366 |
2475 if (tp->thr_pid >= 0) { |
2367 if (tp->thr_pid >= 0) { |
2476 tp->time_to_die = 1; |
2368 tp->time_to_die = 1; |
2477 wmb(); |
2369 wmb(); |
2501 |
2393 |
2502 spin_unlock_irqrestore (&tp->lock, flags); |
2394 spin_unlock_irqrestore (&tp->lock, flags); |
2503 |
2395 |
2504 synchronize_irq (dev->irq); /* racy, but that's ok here */ |
2396 synchronize_irq (dev->irq); /* racy, but that's ok here */ |
2505 free_irq (dev->irq, dev); |
2397 free_irq (dev->irq, dev); |
2506 } else { |
2398 } |
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 |
2399 |
2520 rtl8139_tx_clear (tp); |
2400 rtl8139_tx_clear (tp); |
2521 |
2401 |
2522 pci_free_consistent(tp->pci_dev, RX_BUF_TOT_LEN, |
2402 pci_free_consistent(tp->pci_dev, RX_BUF_TOT_LEN, |
2523 tp->rx_ring, tp->rx_ring_dma); |
2403 tp->rx_ring, tp->rx_ring_dma); |
2728 static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
2608 static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
2729 { |
2609 { |
2730 struct rtl8139_private *np = netdev_priv(dev); |
2610 struct rtl8139_private *np = netdev_priv(dev); |
2731 int rc; |
2611 int rc; |
2732 |
2612 |
2733 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2613 if (np->ecdev || !netif_running(dev)) |
2734 |
|
2735 if (dev == rtl_ec_net_dev || !netif_running(dev)) |
|
2736 return -EINVAL; |
2614 return -EINVAL; |
2737 |
|
2738 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2739 |
2615 |
2740 spin_lock_irq(&np->lock); |
2616 spin_lock_irq(&np->lock); |
2741 rc = generic_mii_ioctl(&np->mii, if_mii(rq), cmd, NULL); |
2617 rc = generic_mii_ioctl(&np->mii, if_mii(rq), cmd, NULL); |
2742 spin_unlock_irq(&np->lock); |
2618 spin_unlock_irq(&np->lock); |
2743 |
2619 |
2749 { |
2625 { |
2750 struct rtl8139_private *tp = netdev_priv(dev); |
2626 struct rtl8139_private *tp = netdev_priv(dev); |
2751 void __iomem *ioaddr = tp->mmio_addr; |
2627 void __iomem *ioaddr = tp->mmio_addr; |
2752 unsigned long flags; |
2628 unsigned long flags; |
2753 |
2629 |
2754 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2630 if (tp->ecdev || netif_running(dev)) { |
2755 |
|
2756 if (dev == rtl_ec_net_dev || netif_running(dev)) { |
|
2757 spin_lock_irqsave (&tp->lock, flags); |
2631 spin_lock_irqsave (&tp->lock, flags); |
2758 tp->stats.rx_missed_errors += RTL_R32 (RxMissed); |
2632 tp->stats.rx_missed_errors += RTL_R32 (RxMissed); |
2759 RTL_W32 (RxMissed, 0); |
2633 RTL_W32 (RxMissed, 0); |
2760 spin_unlock_irqrestore (&tp->lock, flags); |
2634 spin_unlock_irqrestore (&tp->lock, flags); |
2761 } |
2635 } |
2762 |
|
2763 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2764 |
2636 |
2765 return &tp->stats; |
2637 return &tp->stats; |
2766 } |
2638 } |
2767 |
2639 |
2768 /* Set or clear the multicast filter for this adaptor. |
2640 /* Set or clear the multicast filter for this adaptor. |
2865 |
2733 |
2866 |
2734 |
2867 static int rtl8139_resume (struct pci_dev *pdev) |
2735 static int rtl8139_resume (struct pci_dev *pdev) |
2868 { |
2736 { |
2869 struct net_device *dev = pci_get_drvdata (pdev); |
2737 struct net_device *dev = pci_get_drvdata (pdev); |
|
2738 struct rtl8139_private *tp = netdev_priv(dev); |
2870 |
2739 |
2871 pci_restore_state (pdev); |
2740 pci_restore_state (pdev); |
2872 |
2741 if (tp->ecdev || !netif_running (dev)) |
2873 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
2874 |
|
2875 if (dev == rtl_ec_net_dev || !netif_running (dev)) |
|
2876 return 0; |
2742 return 0; |
2877 |
|
2878 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2879 |
|
2880 pci_set_power_state (pdev, PCI_D0); |
2743 pci_set_power_state (pdev, PCI_D0); |
2881 rtl8139_init_ring (dev); |
2744 rtl8139_init_ring (dev); |
2882 rtl8139_hw_start (dev); |
2745 rtl8139_hw_start (dev); |
2883 netif_device_attach (dev); |
2746 netif_device_attach (dev); |
2884 return 0; |
2747 return 0; |
2899 }; |
2762 }; |
2900 |
2763 |
2901 |
2764 |
2902 static int __init rtl8139_init_module (void) |
2765 static int __init rtl8139_init_module (void) |
2903 { |
2766 { |
2904 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2767 /* when we're a module, we always print a version message, |
2905 |
2768 * even if no 8139 board is found. |
2906 printk(KERN_INFO RTL8139_DRIVER_NAME "\n"); |
2769 */ |
2907 printk(KERN_INFO "ec_device_index is %i\n", ec_device_index); |
2770 #ifdef MODULE |
2908 |
2771 printk (KERN_INFO RTL8139_DRIVER_NAME "\n"); |
2909 if (pci_module_init(&rtl8139_pci_driver) < 0) { |
2772 #endif |
2910 printk(KERN_ERR "Failed to init PCI module.\n"); |
2773 |
2911 goto out_return; |
2774 return pci_module_init (&rtl8139_pci_driver); |
2912 } |
|
2913 |
|
2914 if (rtl_ec_net_dev) { |
|
2915 printk(KERN_INFO "Registering EtherCAT device...\n"); |
|
2916 if (!(rtl_ec_dev = ecdev_register(ec_device_master_index, |
|
2917 rtl_ec_net_dev, ec_poll, THIS_MODULE))) { |
|
2918 printk(KERN_ERR "Failed to register EtherCAT device!\n"); |
|
2919 goto out_pci; |
|
2920 } |
|
2921 |
|
2922 printk(KERN_INFO "Opening EtherCAT device...\n"); |
|
2923 if (ecdev_open(rtl_ec_dev)) { |
|
2924 printk(KERN_ERR "Failed to open EtherCAT device!\n"); |
|
2925 goto out_unregister; |
|
2926 } |
|
2927 |
|
2928 printk(KERN_INFO "EtherCAT device ready.\n"); |
|
2929 } else { |
|
2930 printk(KERN_WARNING "No EtherCAT device registered!\n"); |
|
2931 } |
|
2932 |
|
2933 return 0; |
|
2934 |
|
2935 out_unregister: |
|
2936 printk(KERN_INFO "Unregistering EtherCAT device...\n"); |
|
2937 ecdev_unregister(ec_device_master_index, rtl_ec_dev); |
|
2938 rtl_ec_dev = NULL; |
|
2939 out_pci: |
|
2940 pci_unregister_driver(&rtl8139_pci_driver); |
|
2941 out_return: |
|
2942 return -1; |
|
2943 |
|
2944 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2945 } |
2775 } |
2946 |
2776 |
2947 |
2777 |
2948 static void __exit rtl8139_cleanup_module (void) |
2778 static void __exit rtl8139_cleanup_module (void) |
2949 { |
2779 { |
2950 /* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
2780 pci_unregister_driver (&rtl8139_pci_driver); |
2951 |
|
2952 printk(KERN_INFO "Cleaning up RTL8139-EtherCAT module...\n"); |
|
2953 |
|
2954 if (rtl_ec_net_dev) { |
|
2955 printk(KERN_INFO "Closing EtherCAT device...\n"); |
|
2956 ecdev_close(rtl_ec_dev); |
|
2957 printk(KERN_INFO "Unregistering EtherCAT device...\n"); |
|
2958 ecdev_unregister(ec_device_master_index, rtl_ec_dev); |
|
2959 rtl_ec_dev = NULL; |
|
2960 } |
|
2961 |
|
2962 pci_unregister_driver(&rtl8139_pci_driver); |
|
2963 |
|
2964 printk(KERN_INFO "RTL8139-EtherCAT module cleaned up.\n"); |
|
2965 |
|
2966 /* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2967 } |
2781 } |
2968 |
2782 |
2969 |
2783 |
2970 module_init(rtl8139_init_module); |
2784 module_init(rtl8139_init_module); |
2971 module_exit(rtl8139_cleanup_module); |
2785 module_exit(rtl8139_cleanup_module); |