hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/drivers/net/ethernet/socionext/sni_ave.c
....@@ -185,8 +185,8 @@
185185 NETIF_MSG_TX_ERR)
186186
187187 /* Parameter for descriptor */
188
-#define AVE_NR_TXDESC 32 /* Tx descriptor */
189
-#define AVE_NR_RXDESC 64 /* Rx descriptor */
188
+#define AVE_NR_TXDESC 64 /* Tx descriptor */
189
+#define AVE_NR_RXDESC 256 /* Rx descriptor */
190190
191191 #define AVE_DESC_OFS_CMDSTS 0
192192 #define AVE_DESC_OFS_ADDRL 4
....@@ -262,6 +262,7 @@
262262 struct regmap *regmap;
263263 unsigned int pinmode_mask;
264264 unsigned int pinmode_val;
265
+ u32 wolopts;
265266
266267 /* stats */
267268 struct ave_stats stats_rx;
....@@ -423,16 +424,22 @@
423424 phy_ethtool_get_wol(ndev->phydev, wol);
424425 }
425426
427
+static int __ave_ethtool_set_wol(struct net_device *ndev,
428
+ struct ethtool_wolinfo *wol)
429
+{
430
+ if (!ndev->phydev ||
431
+ (wol->wolopts & (WAKE_ARP | WAKE_MAGICSECURE)))
432
+ return -EOPNOTSUPP;
433
+
434
+ return phy_ethtool_set_wol(ndev->phydev, wol);
435
+}
436
+
426437 static int ave_ethtool_set_wol(struct net_device *ndev,
427438 struct ethtool_wolinfo *wol)
428439 {
429440 int ret;
430441
431
- if (!ndev->phydev ||
432
- (wol->wolopts & (WAKE_ARP | WAKE_MAGICSECURE)))
433
- return -EOPNOTSUPP;
434
-
435
- ret = phy_ethtool_set_wol(ndev->phydev, wol);
442
+ ret = __ave_ethtool_set_wol(ndev, wol);
436443 if (!ret)
437444 device_set_wakeup_enable(&ndev->dev, !!wol->wolopts);
438445
....@@ -462,16 +469,7 @@
462469 priv->pause_rx = pause->rx_pause;
463470 priv->pause_tx = pause->tx_pause;
464471
465
- phydev->advertising &= ~(ADVERTISED_Pause | ADVERTISED_Asym_Pause);
466
- if (pause->rx_pause)
467
- phydev->advertising |= ADVERTISED_Pause | ADVERTISED_Asym_Pause;
468
- if (pause->tx_pause)
469
- phydev->advertising ^= ADVERTISED_Asym_Pause;
470
-
471
- if (pause->autoneg) {
472
- if (netif_running(ndev))
473
- phy_start_aneg(phydev);
474
- }
472
+ phy_set_asym_pause(phydev, pause->rx_pause, pause->tx_pause);
475473
476474 return 0;
477475 }
....@@ -1127,11 +1125,8 @@
11271125 rmt_adv |= LPA_PAUSE_CAP;
11281126 if (phydev->asym_pause)
11291127 rmt_adv |= LPA_PAUSE_ASYM;
1130
- if (phydev->advertising & ADVERTISED_Pause)
1131
- lcl_adv |= ADVERTISE_PAUSE_CAP;
1132
- if (phydev->advertising & ADVERTISED_Asym_Pause)
1133
- lcl_adv |= ADVERTISE_PAUSE_ASYM;
11341128
1129
+ lcl_adv = linkmode_adv_to_lcl_adv_t(phydev->advertising);
11351130 cap = mii_resolve_flowctrl_fdx(lcl_adv, rmt_adv);
11361131 if (cap & FLOW_CTRL_TX)
11371132 txcr |= AVE_TXCR_FLOCTR;
....@@ -1222,14 +1217,17 @@
12221217
12231218 priv->phydev = phydev;
12241219
1225
- phy_ethtool_get_wol(phydev, &wol);
1220
+ ave_ethtool_get_wol(ndev, &wol);
12261221 device_set_wakeup_capable(&ndev->dev, !!wol.supported);
12271222
1228
- if (!phy_interface_is_rgmii(phydev)) {
1229
- phydev->supported &= ~PHY_GBIT_FEATURES;
1230
- phydev->supported |= PHY_BASIC_FEATURES;
1231
- }
1232
- phydev->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
1223
+ /* set wol initial state disabled */
1224
+ wol.wolopts = 0;
1225
+ __ave_ethtool_set_wol(ndev, &wol);
1226
+
1227
+ if (!phy_interface_is_rgmii(phydev))
1228
+ phy_set_max_speed(phydev, SPEED_100);
1229
+
1230
+ phy_support_asym_pause(phydev);
12331231
12341232 phy_attached_info(phydev);
12351233
....@@ -1396,7 +1394,7 @@
13961394 return 0;
13971395 }
13981396
1399
-static int ave_start_xmit(struct sk_buff *skb, struct net_device *ndev)
1397
+static netdev_tx_t ave_start_xmit(struct sk_buff *skb, struct net_device *ndev)
14001398 {
14011399 struct ave_private *priv = netdev_priv(ndev);
14021400 u32 proc_idx, done_idx, ndesc, cmdsts;
....@@ -1561,7 +1559,6 @@
15611559 struct ave_private *priv;
15621560 struct net_device *ndev;
15631561 struct device_node *np;
1564
- struct resource *res;
15651562 const void *mac_addr;
15661563 void __iomem *base;
15671564 const char *name;
....@@ -1574,24 +1571,21 @@
15741571 return -EINVAL;
15751572
15761573 np = dev->of_node;
1577
- phy_mode = of_get_phy_mode(np);
1578
- if ((int)phy_mode < 0) {
1574
+ ret = of_get_phy_mode(np, &phy_mode);
1575
+ if (ret) {
15791576 dev_err(dev, "phy-mode not found\n");
1580
- return -EINVAL;
1577
+ return ret;
15811578 }
15821579
15831580 irq = platform_get_irq(pdev, 0);
1584
- if (irq < 0) {
1585
- dev_err(dev, "IRQ not found\n");
1581
+ if (irq < 0)
15861582 return irq;
1587
- }
15881583
1589
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1590
- base = devm_ioremap_resource(dev, res);
1584
+ base = devm_platform_ioremap_resource(pdev, 0);
15911585 if (IS_ERR(base))
15921586 return PTR_ERR(base);
15931587
1594
- ndev = alloc_etherdev(sizeof(struct ave_private));
1588
+ ndev = devm_alloc_etherdev(dev, sizeof(struct ave_private));
15951589 if (!ndev) {
15961590 dev_err(dev, "can't allocate ethernet device\n");
15971591 return -ENOMEM;
....@@ -1607,7 +1601,7 @@
16071601 ndev->max_mtu = AVE_MAX_ETHFRAME - (ETH_HLEN + ETH_FCS_LEN);
16081602
16091603 mac_addr = of_get_mac_address(np);
1610
- if (mac_addr)
1604
+ if (!IS_ERR(mac_addr))
16111605 ether_addr_copy(ndev->dev_addr, mac_addr);
16121606
16131607 /* if the mac address is invalid, use random mac address */
....@@ -1638,7 +1632,7 @@
16381632 }
16391633 ret = dma_set_mask(dev, dma_mask);
16401634 if (ret)
1641
- goto out_free_netdev;
1635
+ return ret;
16421636
16431637 priv->tx.ndesc = AVE_NR_TXDESC;
16441638 priv->rx.ndesc = AVE_NR_RXDESC;
....@@ -1651,10 +1645,8 @@
16511645 if (!name)
16521646 break;
16531647 priv->clk[i] = devm_clk_get(dev, name);
1654
- if (IS_ERR(priv->clk[i])) {
1655
- ret = PTR_ERR(priv->clk[i]);
1656
- goto out_free_netdev;
1657
- }
1648
+ if (IS_ERR(priv->clk[i]))
1649
+ return PTR_ERR(priv->clk[i]);
16581650 priv->nclks++;
16591651 }
16601652
....@@ -1663,10 +1655,8 @@
16631655 if (!name)
16641656 break;
16651657 priv->rst[i] = devm_reset_control_get_shared(dev, name);
1666
- if (IS_ERR(priv->rst[i])) {
1667
- ret = PTR_ERR(priv->rst[i]);
1668
- goto out_free_netdev;
1669
- }
1658
+ if (IS_ERR(priv->rst[i]))
1659
+ return PTR_ERR(priv->rst[i]);
16701660 priv->nrsts++;
16711661 }
16721662
....@@ -1674,27 +1664,24 @@
16741664 "socionext,syscon-phy-mode",
16751665 1, 0, &args);
16761666 if (ret) {
1677
- netdev_err(ndev, "can't get syscon-phy-mode property\n");
1678
- goto out_free_netdev;
1667
+ dev_err(dev, "can't get syscon-phy-mode property\n");
1668
+ return ret;
16791669 }
16801670 priv->regmap = syscon_node_to_regmap(args.np);
16811671 of_node_put(args.np);
16821672 if (IS_ERR(priv->regmap)) {
1683
- netdev_err(ndev, "can't map syscon-phy-mode\n");
1684
- ret = PTR_ERR(priv->regmap);
1685
- goto out_free_netdev;
1673
+ dev_err(dev, "can't map syscon-phy-mode\n");
1674
+ return PTR_ERR(priv->regmap);
16861675 }
16871676 ret = priv->data->get_pinmode(priv, phy_mode, args.args[0]);
16881677 if (ret) {
1689
- netdev_err(ndev, "invalid phy-mode setting\n");
1690
- goto out_free_netdev;
1678
+ dev_err(dev, "invalid phy-mode setting\n");
1679
+ return ret;
16911680 }
16921681
16931682 priv->mdio = devm_mdiobus_alloc(dev);
1694
- if (!priv->mdio) {
1695
- ret = -ENOMEM;
1696
- goto out_free_netdev;
1697
- }
1683
+ if (!priv->mdio)
1684
+ return -ENOMEM;
16981685 priv->mdio->priv = ndev;
16991686 priv->mdio->parent = dev;
17001687 priv->mdio->read = ave_mdiobus_read;
....@@ -1704,9 +1691,10 @@
17041691 pdev->name, pdev->id);
17051692
17061693 /* Register as a NAPI supported driver */
1707
- netif_napi_add(ndev, &priv->napi_rx, ave_napi_poll_rx, priv->rx.ndesc);
1694
+ netif_napi_add(ndev, &priv->napi_rx, ave_napi_poll_rx,
1695
+ NAPI_POLL_WEIGHT);
17081696 netif_tx_napi_add(ndev, &priv->napi_tx, ave_napi_poll_tx,
1709
- priv->tx.ndesc);
1697
+ NAPI_POLL_WEIGHT);
17101698
17111699 platform_set_drvdata(pdev, ndev);
17121700
....@@ -1730,8 +1718,6 @@
17301718 out_del_napi:
17311719 netif_napi_del(&priv->napi_rx);
17321720 netif_napi_del(&priv->napi_tx);
1733
-out_free_netdev:
1734
- free_netdev(ndev);
17351721
17361722 return ret;
17371723 }
....@@ -1744,10 +1730,61 @@
17441730 unregister_netdev(ndev);
17451731 netif_napi_del(&priv->napi_rx);
17461732 netif_napi_del(&priv->napi_tx);
1747
- free_netdev(ndev);
17481733
17491734 return 0;
17501735 }
1736
+
1737
+#ifdef CONFIG_PM_SLEEP
1738
+static int ave_suspend(struct device *dev)
1739
+{
1740
+ struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
1741
+ struct net_device *ndev = dev_get_drvdata(dev);
1742
+ struct ave_private *priv = netdev_priv(ndev);
1743
+ int ret = 0;
1744
+
1745
+ if (netif_running(ndev)) {
1746
+ ret = ave_stop(ndev);
1747
+ netif_device_detach(ndev);
1748
+ }
1749
+
1750
+ ave_ethtool_get_wol(ndev, &wol);
1751
+ priv->wolopts = wol.wolopts;
1752
+
1753
+ return ret;
1754
+}
1755
+
1756
+static int ave_resume(struct device *dev)
1757
+{
1758
+ struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
1759
+ struct net_device *ndev = dev_get_drvdata(dev);
1760
+ struct ave_private *priv = netdev_priv(ndev);
1761
+ int ret = 0;
1762
+
1763
+ ave_global_reset(ndev);
1764
+
1765
+ ave_ethtool_get_wol(ndev, &wol);
1766
+ wol.wolopts = priv->wolopts;
1767
+ __ave_ethtool_set_wol(ndev, &wol);
1768
+
1769
+ if (ndev->phydev) {
1770
+ ret = phy_resume(ndev->phydev);
1771
+ if (ret)
1772
+ return ret;
1773
+ }
1774
+
1775
+ if (netif_running(ndev)) {
1776
+ ret = ave_open(ndev);
1777
+ netif_device_attach(ndev);
1778
+ }
1779
+
1780
+ return ret;
1781
+}
1782
+
1783
+static SIMPLE_DEV_PM_OPS(ave_pm_ops, ave_suspend, ave_resume);
1784
+#define AVE_PM_OPS (&ave_pm_ops)
1785
+#else
1786
+#define AVE_PM_OPS NULL
1787
+#endif
17511788
17521789 static int ave_pro4_get_pinmode(struct ave_private *priv,
17531790 phy_interface_t phy_mode, u32 arg)
....@@ -1763,6 +1800,9 @@
17631800 break;
17641801 case PHY_INTERFACE_MODE_MII:
17651802 case PHY_INTERFACE_MODE_RGMII:
1803
+ case PHY_INTERFACE_MODE_RGMII_ID:
1804
+ case PHY_INTERFACE_MODE_RGMII_RXID:
1805
+ case PHY_INTERFACE_MODE_RGMII_TXID:
17661806 priv->pinmode_val = 0;
17671807 break;
17681808 default:
....@@ -1807,6 +1847,9 @@
18071847 priv->pinmode_val = SG_ETPINMODE_RMII(0);
18081848 break;
18091849 case PHY_INTERFACE_MODE_RGMII:
1850
+ case PHY_INTERFACE_MODE_RGMII_ID:
1851
+ case PHY_INTERFACE_MODE_RGMII_RXID:
1852
+ case PHY_INTERFACE_MODE_RGMII_TXID:
18101853 priv->pinmode_val = 0;
18111854 break;
18121855 default:
....@@ -1829,6 +1872,9 @@
18291872 priv->pinmode_val = SG_ETPINMODE_RMII(arg);
18301873 break;
18311874 case PHY_INTERFACE_MODE_RGMII:
1875
+ case PHY_INTERFACE_MODE_RGMII_ID:
1876
+ case PHY_INTERFACE_MODE_RGMII_RXID:
1877
+ case PHY_INTERFACE_MODE_RGMII_TXID:
18321878 priv->pinmode_val = 0;
18331879 break;
18341880 default:
....@@ -1923,10 +1969,12 @@
19231969 .remove = ave_remove,
19241970 .driver = {
19251971 .name = "ave",
1972
+ .pm = AVE_PM_OPS,
19261973 .of_match_table = of_ave_match,
19271974 },
19281975 };
19291976 module_platform_driver(ave_driver);
19301977
1978
+MODULE_AUTHOR("Kunihiko Hayashi <hayashi.kunihiko@socionext.com>");
19311979 MODULE_DESCRIPTION("Socionext UniPhier AVE ethernet driver");
19321980 MODULE_LICENSE("GPL v2");