aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/ethernet/stmicro/stmmac/stmmac_main.c')
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_main.c205
1 files changed, 107 insertions, 98 deletions
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 96fa2da30763..6ee593a55a64 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -241,7 +241,7 @@ static void stmmac_adjust_link(struct net_device *dev)
241 case 1000: 241 case 1000:
242 if (likely(priv->plat->has_gmac)) 242 if (likely(priv->plat->has_gmac))
243 ctrl &= ~priv->hw->link.port; 243 ctrl &= ~priv->hw->link.port;
244 stmmac_hw_fix_mac_speed(priv); 244 stmmac_hw_fix_mac_speed(priv);
245 break; 245 break;
246 case 100: 246 case 100:
247 case 10: 247 case 10:
@@ -785,7 +785,7 @@ static u32 stmmac_get_synopsys_id(struct stmmac_priv *priv)
785 u32 uid = ((hwid & 0x0000ff00) >> 8); 785 u32 uid = ((hwid & 0x0000ff00) >> 8);
786 u32 synid = (hwid & 0x000000ff); 786 u32 synid = (hwid & 0x000000ff);
787 787
788 pr_info("STMMAC - user ID: 0x%x, Synopsys ID: 0x%x\n", 788 pr_info("stmmac - user ID: 0x%x, Synopsys ID: 0x%x\n",
789 uid, synid); 789 uid, synid);
790 790
791 return synid; 791 return synid;
@@ -869,38 +869,6 @@ static int stmmac_get_hw_features(struct stmmac_priv *priv)
869 return hw_cap; 869 return hw_cap;
870} 870}
871 871
872/**
873 * stmmac_mac_device_setup
874 * @dev : device pointer
875 * Description: this is to attach the GMAC or MAC 10/100
876 * main core structures that will be completed during the
877 * open step.
878 */
879static int stmmac_mac_device_setup(struct net_device *dev)
880{
881 struct stmmac_priv *priv = netdev_priv(dev);
882
883 struct mac_device_info *device;
884
885 if (priv->plat->has_gmac)
886 device = dwmac1000_setup(priv->ioaddr);
887 else
888 device = dwmac100_setup(priv->ioaddr);
889
890 if (!device)
891 return -ENOMEM;
892
893 priv->hw = device;
894 priv->hw->ring = &ring_mode_ops;
895
896 if (device_can_wakeup(priv->device)) {
897 priv->wolopts = WAKE_MAGIC; /* Magic Frame as default */
898 enable_irq_wake(priv->wol_irq);
899 }
900
901 return 0;
902}
903
904static void stmmac_check_ether_addr(struct stmmac_priv *priv) 872static void stmmac_check_ether_addr(struct stmmac_priv *priv)
905{ 873{
906 /* verify if the MAC address is valid, in case of failures it 874 /* verify if the MAC address is valid, in case of failures it
@@ -930,20 +898,8 @@ static int stmmac_open(struct net_device *dev)
930 struct stmmac_priv *priv = netdev_priv(dev); 898 struct stmmac_priv *priv = netdev_priv(dev);
931 int ret; 899 int ret;
932 900
933 /* MAC HW device setup */
934 ret = stmmac_mac_device_setup(dev);
935 if (ret < 0)
936 return ret;
937
938 stmmac_check_ether_addr(priv); 901 stmmac_check_ether_addr(priv);
939 902
940 stmmac_verify_args();
941
942 /* Override with kernel parameters if supplied XXX CRS XXX
943 * this needs to have multiple instances */
944 if ((phyaddr >= 0) && (phyaddr <= 31))
945 priv->plat->phy_addr = phyaddr;
946
947 /* MDIO bus Registration */ 903 /* MDIO bus Registration */
948 ret = stmmac_mdio_register(dev); 904 ret = stmmac_mdio_register(dev);
949 if (ret < 0) { 905 if (ret < 0) {
@@ -976,44 +932,6 @@ static int stmmac_open(struct net_device *dev)
976 goto open_error; 932 goto open_error;
977 } 933 }
978 934
979 stmmac_get_synopsys_id(priv);
980
981 priv->hw_cap_support = stmmac_get_hw_features(priv);
982
983 if (priv->hw_cap_support) {
984 pr_info(" Support DMA HW capability register");
985
986 /* We can override some gmac/dma configuration fields: e.g.
987 * enh_desc, tx_coe (e.g. that are passed through the
988 * platform) with the values from the HW capability
989 * register (if supported).
990 */
991 priv->plat->enh_desc = priv->dma_cap.enh_desc;
992 priv->plat->tx_coe = priv->dma_cap.tx_coe;
993 priv->plat->pmt = priv->dma_cap.pmt_remote_wake_up;
994
995 /* By default disable wol on magic frame if not supported */
996 if (!priv->dma_cap.pmt_magic_frame)
997 priv->wolopts &= ~WAKE_MAGIC;
998
999 } else
1000 pr_info(" No HW DMA feature register supported");
1001
1002 /* Select the enhnaced/normal descriptor structures */
1003 stmmac_selec_desc_mode(priv);
1004
1005 /* PMT module is not integrated in all the MAC devices. */
1006 if (priv->plat->pmt) {
1007 pr_info(" Remote wake-up capable\n");
1008 device_set_wakeup_capable(priv->device, 1);
1009 }
1010
1011 priv->rx_coe = priv->hw->mac->rx_coe(priv->ioaddr);
1012 if (priv->rx_coe)
1013 pr_info(" Checksum Offload Engine supported\n");
1014 if (priv->plat->tx_coe)
1015 pr_info(" Checksum insertion supported\n");
1016
1017 /* Create and initialize the TX/RX descriptors chains. */ 935 /* Create and initialize the TX/RX descriptors chains. */
1018 priv->dma_tx_size = STMMAC_ALIGN(dma_txsize); 936 priv->dma_tx_size = STMMAC_ALIGN(dma_txsize);
1019 priv->dma_rx_size = STMMAC_ALIGN(dma_rxsize); 937 priv->dma_rx_size = STMMAC_ALIGN(dma_rxsize);
@@ -1030,14 +948,14 @@ static int stmmac_open(struct net_device *dev)
1030 948
1031 /* Copy the MAC addr into the HW */ 949 /* Copy the MAC addr into the HW */
1032 priv->hw->mac->set_umac_addr(priv->ioaddr, dev->dev_addr, 0); 950 priv->hw->mac->set_umac_addr(priv->ioaddr, dev->dev_addr, 0);
951
1033 /* If required, perform hw setup of the bus. */ 952 /* If required, perform hw setup of the bus. */
1034 if (priv->plat->bus_setup) 953 if (priv->plat->bus_setup)
1035 priv->plat->bus_setup(priv->ioaddr); 954 priv->plat->bus_setup(priv->ioaddr);
955
1036 /* Initialize the MAC Core */ 956 /* Initialize the MAC Core */
1037 priv->hw->mac->core_init(priv->ioaddr); 957 priv->hw->mac->core_init(priv->ioaddr);
1038 958
1039 netdev_update_features(dev);
1040
1041 /* Request the IRQ lines */ 959 /* Request the IRQ lines */
1042 ret = request_irq(dev->irq, stmmac_interrupt, 960 ret = request_irq(dev->irq, stmmac_interrupt,
1043 IRQF_SHARED, dev->name, dev); 961 IRQF_SHARED, dev->name, dev);
@@ -1047,6 +965,17 @@ static int stmmac_open(struct net_device *dev)
1047 goto open_error; 965 goto open_error;
1048 } 966 }
1049 967
968 /* Request the Wake IRQ in case of another line is used for WoL */
969 if (priv->wol_irq != dev->irq) {
970 ret = request_irq(priv->wol_irq, stmmac_interrupt,
971 IRQF_SHARED, dev->name, dev);
972 if (unlikely(ret < 0)) {
973 pr_err("%s: ERROR: allocating the ext WoL IRQ %d "
974 "(error: %d)\n", __func__, priv->wol_irq, ret);
975 goto open_error_wolirq;
976 }
977 }
978
1050 /* Enable the MAC Rx/Tx */ 979 /* Enable the MAC Rx/Tx */
1051 stmmac_set_mac(priv->ioaddr, true); 980 stmmac_set_mac(priv->ioaddr, true);
1052 981
@@ -1062,7 +991,7 @@ static int stmmac_open(struct net_device *dev)
1062#ifdef CONFIG_STMMAC_DEBUG_FS 991#ifdef CONFIG_STMMAC_DEBUG_FS
1063 ret = stmmac_init_fs(dev); 992 ret = stmmac_init_fs(dev);
1064 if (ret < 0) 993 if (ret < 0)
1065 pr_warning("\tFailed debugFS registration"); 994 pr_warning("%s: failed debugFS registration\n", __func__);
1066#endif 995#endif
1067 /* Start the ball rolling... */ 996 /* Start the ball rolling... */
1068 DBG(probe, DEBUG, "%s: DMA RX/TX processes started...\n", dev->name); 997 DBG(probe, DEBUG, "%s: DMA RX/TX processes started...\n", dev->name);
@@ -1072,6 +1001,7 @@ static int stmmac_open(struct net_device *dev)
1072#ifdef CONFIG_STMMAC_TIMER 1001#ifdef CONFIG_STMMAC_TIMER
1073 priv->tm->timer_start(tmrate); 1002 priv->tm->timer_start(tmrate);
1074#endif 1003#endif
1004
1075 /* Dump DMA/MAC registers */ 1005 /* Dump DMA/MAC registers */
1076 if (netif_msg_hw(priv)) { 1006 if (netif_msg_hw(priv)) {
1077 priv->hw->mac->dump_regs(priv->ioaddr); 1007 priv->hw->mac->dump_regs(priv->ioaddr);
@@ -1087,6 +1017,9 @@ static int stmmac_open(struct net_device *dev)
1087 1017
1088 return 0; 1018 return 0;
1089 1019
1020open_error_wolirq:
1021 free_irq(dev->irq, dev);
1022
1090open_error: 1023open_error:
1091#ifdef CONFIG_STMMAC_TIMER 1024#ifdef CONFIG_STMMAC_TIMER
1092 kfree(priv->tm); 1025 kfree(priv->tm);
@@ -1127,6 +1060,8 @@ static int stmmac_release(struct net_device *dev)
1127 1060
1128 /* Free the IRQ lines */ 1061 /* Free the IRQ lines */
1129 free_irq(dev->irq, dev); 1062 free_irq(dev->irq, dev);
1063 if (priv->wol_irq != dev->irq)
1064 free_irq(priv->wol_irq, dev);
1130 1065
1131 /* Stop TX/RX DMA and clear the descriptors */ 1066 /* Stop TX/RX DMA and clear the descriptors */
1132 priv->hw->dma->stop_tx(priv->ioaddr); 1067 priv->hw->dma->stop_tx(priv->ioaddr);
@@ -1789,13 +1724,77 @@ static const struct net_device_ops stmmac_netdev_ops = {
1789}; 1724};
1790 1725
1791/** 1726/**
1727 * stmmac_hw_init - Init the MAC device
1728 * @priv : pointer to the private device structure.
1729 * Description: this function detects which MAC device
1730 * (GMAC/MAC10-100) has to attached, checks the HW capability
1731 * (if supported) and sets the driver's features (for example
1732 * to use the ring or chaine mode or support the normal/enh
1733 * descriptor structure).
1734 */
1735static int stmmac_hw_init(struct stmmac_priv *priv)
1736{
1737 int ret = 0;
1738 struct mac_device_info *mac;
1739
1740 /* Identify the MAC HW device */
1741 if (priv->plat->has_gmac)
1742 mac = dwmac1000_setup(priv->ioaddr);
1743 else
1744 mac = dwmac100_setup(priv->ioaddr);
1745 if (!mac)
1746 return -ENOMEM;
1747
1748 priv->hw = mac;
1749
1750 /* To use the chained or ring mode */
1751 priv->hw->ring = &ring_mode_ops;
1752
1753 /* Get and dump the chip ID */
1754 stmmac_get_synopsys_id(priv);
1755
1756 /* Get the HW capability (new GMAC newer than 3.50a) */
1757 priv->hw_cap_support = stmmac_get_hw_features(priv);
1758 if (priv->hw_cap_support) {
1759 pr_info(" DMA HW capability register supported");
1760
1761 /* We can override some gmac/dma configuration fields: e.g.
1762 * enh_desc, tx_coe (e.g. that are passed through the
1763 * platform) with the values from the HW capability
1764 * register (if supported).
1765 */
1766 priv->plat->enh_desc = priv->dma_cap.enh_desc;
1767 priv->plat->tx_coe = priv->dma_cap.tx_coe;
1768 priv->plat->pmt = priv->dma_cap.pmt_remote_wake_up;
1769 } else
1770 pr_info(" No HW DMA feature register supported");
1771
1772 /* Select the enhnaced/normal descriptor structures */
1773 stmmac_selec_desc_mode(priv);
1774
1775 priv->rx_coe = priv->hw->mac->rx_coe(priv->ioaddr);
1776 if (priv->rx_coe)
1777 pr_info(" RX Checksum Offload Engine supported\n");
1778 if (priv->plat->tx_coe)
1779 pr_info(" TX Checksum insertion supported\n");
1780
1781 if (priv->plat->pmt) {
1782 pr_info(" Wake-Up On Lan supported\n");
1783 device_set_wakeup_capable(priv->device, 1);
1784 }
1785
1786 return ret;
1787}
1788
1789/**
1792 * stmmac_dvr_probe 1790 * stmmac_dvr_probe
1793 * @device: device pointer 1791 * @device: device pointer
1794 * Description: this is the main probe function used to 1792 * Description: this is the main probe function used to
1795 * call the alloc_etherdev, allocate the priv structure. 1793 * call the alloc_etherdev, allocate the priv structure.
1796 */ 1794 */
1797struct stmmac_priv *stmmac_dvr_probe(struct device *device, 1795struct stmmac_priv *stmmac_dvr_probe(struct device *device,
1798 struct plat_stmmacenet_data *plat_dat) 1796 struct plat_stmmacenet_data *plat_dat,
1797 void __iomem *addr)
1799{ 1798{
1800 int ret = 0; 1799 int ret = 0;
1801 struct net_device *ndev = NULL; 1800 struct net_device *ndev = NULL;
@@ -1815,10 +1814,27 @@ struct stmmac_priv *stmmac_dvr_probe(struct device *device,
1815 1814
1816 ether_setup(ndev); 1815 ether_setup(ndev);
1817 1816
1818 ndev->netdev_ops = &stmmac_netdev_ops;
1819 stmmac_set_ethtool_ops(ndev); 1817 stmmac_set_ethtool_ops(ndev);
1818 priv->pause = pause;
1819 priv->plat = plat_dat;
1820 priv->ioaddr = addr;
1821 priv->dev->base_addr = (unsigned long)addr;
1822
1823 /* Verify driver arguments */
1824 stmmac_verify_args();
1825
1826 /* Override with kernel parameters if supplied XXX CRS XXX
1827 * this needs to have multiple instances */
1828 if ((phyaddr >= 0) && (phyaddr <= 31))
1829 priv->plat->phy_addr = phyaddr;
1830
1831 /* Init MAC and get the capabilities */
1832 stmmac_hw_init(priv);
1833
1834 ndev->netdev_ops = &stmmac_netdev_ops;
1820 1835
1821 ndev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM; 1836 ndev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
1837 NETIF_F_RXCSUM;
1822 ndev->features |= ndev->hw_features | NETIF_F_HIGHDMA; 1838 ndev->features |= ndev->hw_features | NETIF_F_HIGHDMA;
1823 ndev->watchdog_timeo = msecs_to_jiffies(watchdog); 1839 ndev->watchdog_timeo = msecs_to_jiffies(watchdog);
1824#ifdef STMMAC_VLAN_TAG_USED 1840#ifdef STMMAC_VLAN_TAG_USED
@@ -1830,8 +1846,6 @@ struct stmmac_priv *stmmac_dvr_probe(struct device *device,
1830 if (flow_ctrl) 1846 if (flow_ctrl)
1831 priv->flow_ctrl = FLOW_AUTO; /* RX/TX pause on */ 1847 priv->flow_ctrl = FLOW_AUTO; /* RX/TX pause on */
1832 1848
1833 priv->pause = pause;
1834 priv->plat = plat_dat;
1835 netif_napi_add(ndev, &priv->napi, stmmac_poll, 64); 1849 netif_napi_add(ndev, &priv->napi, stmmac_poll, 64);
1836 1850
1837 spin_lock_init(&priv->lock); 1851 spin_lock_init(&priv->lock);
@@ -1839,15 +1853,10 @@ struct stmmac_priv *stmmac_dvr_probe(struct device *device,
1839 1853
1840 ret = register_netdev(ndev); 1854 ret = register_netdev(ndev);
1841 if (ret) { 1855 if (ret) {
1842 pr_err("%s: ERROR %i registering the device\n", 1856 pr_err("%s: ERROR %i registering the device\n", __func__, ret);
1843 __func__, ret);
1844 goto error; 1857 goto error;
1845 } 1858 }
1846 1859
1847 DBG(probe, DEBUG, "%s: Scatter/Gather: %s - HW checksums: %s\n",
1848 ndev->name, (ndev->features & NETIF_F_SG) ? "on" : "off",
1849 (ndev->features & NETIF_F_IP_CSUM) ? "on" : "off");
1850
1851 return priv; 1860 return priv;
1852 1861
1853error: 1862error: