History

stmmac: move hw init in the probe (v2)

This patch moves the MAC HW initialization and the HW feature verification from the open to the probe function as D. Miller suggested. So the patch actually reorganizes and tidies-up some parts of the driver and indeed fixes some problem when tune its HW features. These can be overwritten by looking at the HW cap register at run-time and that generated problems.

Giuseppe CAVALLARO committed 14 years ago

Commit cf3f0471 parent 7a13f8f4 files · +105 −116Browse files

Unified · Split

4 files
  1. drivers/net/ethernet/stmicro/stmmac/stmmac.h +2 −1
  2. drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +91 −98
  3. drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c +2 −4
  4. drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +10 −13
drivers/net/ethernet/stmicro/stmmac/stmmac.h+2−1
@@ -97,4 +97,5 @@ int stmmac_resume(struct net_device *ndev); · 96 unmodified lines
9797 int stmmac_suspend(struct net_device *ndev);
9898 int stmmac_dvr_remove(struct net_device *ndev);
9999 struct stmmac_priv *stmmac_dvr_probe(struct device *device,
100− struct plat_stmmacenet_data *plat_dat);
100+ struct plat_stmmacenet_data *plat_dat,
101+ void __iomem *addr);
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c+91−98
@@ -241,7 +241,7 @@ static void stmmac_adjust_link(struct net_device *dev) · 240 unmodified lines
241241 case 1000:
242242 if (likely(priv->plat->has_gmac))
243243 ctrl &= ~priv->hw->link.port;
244− stmmac_hw_fix_mac_speed(priv);
244+ stmmac_hw_fix_mac_speed(priv);
245245 break;
246246 case 100:
247247 case 10:
@@ -785,7 +785,7 @@ static u32 stmmac_get_synopsys_id(struct stmmac_priv *priv) · 537 unmodified lines
785785 u32 uid = ((hwid & 0x0000ff00) >> 8);
786786 u32 synid = (hwid & 0x000000ff);
787787
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",
789789 uid, synid);
790790
791791 return synid;
@@ -869,38 +869,6 @@ static int stmmac_get_hw_features(struct stmmac_priv *priv) · 77 unmodified lines
869869 return hw_cap;
870870 }
871871
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− */
879−static 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−
904872 static void stmmac_check_ether_addr(struct stmmac_priv *priv)
905873 {
906874 /* verify if the MAC address is valid, in case of failures it
@@ -930,20 +898,8 @@ static int stmmac_open(struct net_device *dev) · 23 unmodified lines
930898 struct stmmac_priv *priv = netdev_priv(dev);
931899 int ret;
932900
933− /* MAC HW device setup */
934− ret = stmmac_mac_device_setup(dev);
935− if (ret < 0)
936− return ret;
937−
938901 stmmac_check_ether_addr(priv);
939902
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−
947903 /* MDIO bus Registration */
948904 ret = stmmac_mdio_register(dev);
949905 if (ret < 0) {
@@ -976,44 +932,6 @@ static int stmmac_open(struct net_device *dev) · 26 unmodified lines
976932 goto open_error;
977933 }
978934
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−
1017935 /* Create and initialize the TX/RX descriptors chains. */
1018936 priv->dma_tx_size = STMMAC_ALIGN(dma_txsize);
1019937 priv->dma_rx_size = STMMAC_ALIGN(dma_rxsize);
@@ -1030,14 +948,14 @@ static int stmmac_open(struct net_device *dev) · 10 unmodified lines
1030948
1031949 /* Copy the MAC addr into the HW */
1032950 priv->hw->mac->set_umac_addr(priv->ioaddr, dev->dev_addr, 0);
951+
1033952 /* If required, perform hw setup of the bus. */
1034953 if (priv->plat->bus_setup)
1035954 priv->plat->bus_setup(priv->ioaddr);
955+
1036956 /* Initialize the MAC Core */
1037957 priv->hw->mac->core_init(priv->ioaddr);
1038958
1039− netdev_update_features(dev);
1040−
1041959 /* Request the IRQ lines */
1042960 ret = request_irq(dev->irq, stmmac_interrupt,
1043961 IRQF_SHARED, dev->name, dev);
@@ -1073,7 +991,7 @@ static int stmmac_open(struct net_device *dev) · 29 unmodified lines
1073991 #ifdef CONFIG_STMMAC_DEBUG_FS
1074992 ret = stmmac_init_fs(dev);
1075993 if (ret < 0)
1076− pr_warning("\tFailed debugFS registration");
994+ pr_warning("%s: failed debugFS registration\n", __func__);
1077995 #endif
1078996 /* Start the ball rolling... */
1079997 DBG(probe, DEBUG, "%s: DMA RX/TX processes started...\n", dev->name);
@@ -1083,6 +1001,7 @@ static int stmmac_open(struct net_device *dev) · 3 unmodified lines
10831001 #ifdef CONFIG_STMMAC_TIMER
10841002 priv->tm->timer_start(tmrate);
10851003 #endif
1004+
10861005 /* Dump DMA/MAC registers */
10871006 if (netif_msg_hw(priv)) {
10881007 priv->hw->mac->dump_regs(priv->ioaddr);
@@ -1804,6 +1723,69 @@ static const struct net_device_ops stmmac_netdev_ops = { · 715 unmodified lines
18041723 .ndo_set_mac_address = eth_mac_addr,
18051724 };
18061725
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+ */
1735+static 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+
18071789 /**
18081790 * stmmac_dvr_probe
18091791 * @device: device pointer
@@ -1811,7 +1793,8 @@ static const struct net_device_ops stmmac_netdev_ops = { · 1 unmodified line
18111793 * call the alloc_etherdev, allocate the priv structure.
18121794 */
18131795 struct stmmac_priv *stmmac_dvr_probe(struct device *device,
1814− struct plat_stmmacenet_data *plat_dat)
1796+ struct plat_stmmacenet_data *plat_dat,
1797+ void __iomem *addr)
18151798 {
18161799 int ret = 0;
18171800 struct net_device *ndev = NULL;
@@ -1831,10 +1814,27 @@ struct stmmac_priv *stmmac_dvr_probe(struct device *device, · 13 unmodified lines
18311814
18321815 ether_setup(ndev);
18331816
1834− ndev->netdev_ops = &stmmac_netdev_ops;
18351817 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();
18361825
1837− ndev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
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;
1835+
1836+ ndev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
1837+ NETIF_F_RXCSUM;
18381838 ndev->features |= ndev->hw_features | NETIF_F_HIGHDMA;
18391839 ndev->watchdog_timeo = msecs_to_jiffies(watchdog);
18401840 #ifdef STMMAC_VLAN_TAG_USED
@@ -1846,8 +1846,6 @@ struct stmmac_priv *stmmac_dvr_probe(struct device *device, · 5 unmodified lines
18461846 if (flow_ctrl)
18471847 priv->flow_ctrl = FLOW_AUTO; /* RX/TX pause on */
18481848
1849− priv->pause = pause;
1850− priv->plat = plat_dat;
18511849 netif_napi_add(ndev, &priv->napi, stmmac_poll, 64);
18521850
18531851 spin_lock_init(&priv->lock);
@@ -1855,15 +1853,10 @@ struct stmmac_priv *stmmac_dvr_probe(struct device *device, · 1 unmodified line
18551853
18561854 ret = register_netdev(ndev);
18571855 if (ret) {
1858− pr_err("%s: ERROR %i registering the device\n",
1859− __func__, ret);
1856+ pr_err("%s: ERROR %i registering the device\n", __func__, ret);
18601857 goto error;
18611858 }
18621859
1863− DBG(probe, DEBUG, "%s: Scatter/Gather: %s - HW checksums: %s\n",
1864− ndev->name, (ndev->features & NETIF_F_SG) ? "on" : "off",
1865− (ndev->features & NETIF_F_IP_CSUM) ? "on" : "off");
1866−
18671860 return priv;
18681861
18691862 error:
drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c+2−4
@@ -96,13 +96,11 @@ static int __devinit stmmac_pci_probe(struct pci_dev *pdev, · 95 unmodified lines
9696
9797 stmmac_default_data();
9898
99− priv = stmmac_dvr_probe(&(pdev->dev), &plat_dat);
99+ priv = stmmac_dvr_probe(&(pdev->dev), &plat_dat, addr);
100100 if (!priv) {
101− pr_err("%s: main drivr probe failed", __func__);
101+ pr_err("%s: main driver probe failed", __func__);
102102 goto err_out;
103103 }
104− priv->ioaddr = addr;
105− priv->dev->base_addr = (unsigned long)addr;
106104 priv->dev->irq = pdev->irq;
107105 priv->wol_irq = pdev->irq;
108106
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c+10−13
@@ -59,16 +59,20 @@ static int stmmac_pltfr_probe(struct platform_device *pdev) · 58 unmodified lines
5959 goto out_release_region;
6060 }
6161 plat_dat = pdev->dev.platform_data;
62− priv = stmmac_dvr_probe(&(pdev->dev), plat_dat);
62+
63+ /* Custom initialisation (if needed)*/
64+ if (plat_dat->init) {
65+ ret = plat_dat->init(pdev);
66+ if (unlikely(ret))
67+ goto out_unmap;
68+ }
69+
70+ priv = stmmac_dvr_probe(&(pdev->dev), plat_dat, addr);
6371 if (!priv) {
64− pr_err("%s: main drivr probe failed", __func__);
72+ pr_err("%s: main driver probe failed", __func__);
6573 goto out_unmap;
6674 }
6775
68− priv->ioaddr = addr;
69− /* Set the I/O base addr */
70− priv->dev->base_addr = (unsigned long)addr;
71−
7276 /* Get the MAC information */
7377 priv->dev->irq = platform_get_irq_byname(pdev, "macirq");
7478 if (priv->dev->irq == -ENXIO) {
@@ -92,13 +96,6 @@ static int stmmac_pltfr_probe(struct platform_device *pdev) · 17 unmodified lines
9296
9397 platform_set_drvdata(pdev, priv->dev);
9498
95− /* Custom initialisation */
96− if (priv->plat->init) {
97− ret = priv->plat->init(pdev);
98− if (unlikely(ret))
99− goto out_unmap;
100− }
101−
10299 pr_debug("STMMAC platform driver registration completed");
103100
104101 return 0;