Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: of_get_phy_mode: Change API to solve int/unit warnings

Before this change of_get_phy_mode() returned an enum,
phy_interface_t. On error, -ENODEV etc, is returned. If the result of
the function is stored in a variable of type phy_interface_t, and the
compiler has decided to represent this as an unsigned int, comparision
with -ENODEV etc, is a signed vs unsigned comparision.

Fix this problem by changing the API. Make the function return an
error, or 0 on success, and pass a pointer, of type phy_interface_t,
where the phy mode should be stored.

v2:
Return with *interface set to PHY_INTERFACE_MODE_NA on error.
Add error checks to all users of of_get_phy_mode()
Fixup a few reverse christmas tree errors
Fixup a few slightly malformed reverse christmas trees

v3:
Fix 0-day reported errors.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Andrew Lunn and committed by
David S. Miller
0c65b2b9 5d1fcaf3

+201 -149
+4 -3
drivers/net/dsa/bcm_sf2.c
··· 381 381 struct device_node *dn) 382 382 { 383 383 struct device_node *port; 384 - int mode; 385 384 unsigned int port_num; 385 + phy_interface_t mode; 386 + int err; 386 387 387 388 priv->moca_port = -1; 388 389 ··· 396 395 * has completed, since they might be turned off at that 397 396 * time 398 397 */ 399 - mode = of_get_phy_mode(port); 400 - if (mode < 0) 398 + err = of_get_phy_mode(port, &mode); 399 + if (err) 401 400 continue; 402 401 403 402 if (mode == PHY_INTERFACE_MODE_INTERNAL)
+4 -3
drivers/net/dsa/microchip/ksz_common.c
··· 422 422 int ksz_switch_register(struct ksz_device *dev, 423 423 const struct ksz_dev_ops *ops) 424 424 { 425 + phy_interface_t interface; 425 426 int ret; 426 427 427 428 if (dev->pdata) ··· 457 456 * device tree. 458 457 */ 459 458 if (dev->dev->of_node) { 460 - ret = of_get_phy_mode(dev->dev->of_node); 461 - if (ret >= 0) 462 - dev->interface = ret; 459 + ret = of_get_phy_mode(dev->dev->of_node, &interface); 460 + if (ret == 0) 461 + dev->interface = interface; 463 462 dev->synclko_125 = of_property_read_bool(dev->dev->of_node, 464 463 "microchip,synclko-125"); 465 464 }
+6 -2
drivers/net/dsa/mt7530.c
··· 1340 1340 1341 1341 if (!dsa_is_unused_port(ds, 5)) { 1342 1342 priv->p5_intf_sel = P5_INTF_SEL_GMAC5; 1343 - interface = of_get_phy_mode(dsa_to_port(ds, 5)->dn); 1343 + ret = of_get_phy_mode(dsa_to_port(ds, 5)->dn, &interface); 1344 + if (ret && ret != -ENODEV) 1345 + return ret; 1344 1346 } else { 1345 1347 /* Scan the ethernet nodes. look for GMAC1, lookup used phy */ 1346 1348 for_each_child_of_node(dn, mac_np) { ··· 1356 1354 1357 1355 phy_node = of_parse_phandle(mac_np, "phy-handle", 0); 1358 1356 if (phy_node->parent == priv->dev->of_node->parent) { 1359 - interface = of_get_phy_mode(mac_np); 1357 + ret = of_get_phy_mode(mac_np, &interface); 1358 + if (ret && ret != -ENODEV) 1359 + return ret; 1360 1360 id = of_mdio_parse_addr(ds->dev, phy_node); 1361 1361 if (id == 0) 1362 1362 priv->p5_intf_sel = P5_INTF_SEL_PHY_P0;
+5 -4
drivers/net/dsa/qca8k.c
··· 639 639 qca8k_setup(struct dsa_switch *ds) 640 640 { 641 641 struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; 642 - int ret, i, phy_mode = -1; 642 + phy_interface_t phy_mode = PHY_INTERFACE_MODE_NA; 643 + int ret, i; 643 644 u32 mask; 644 645 645 646 /* Make sure that port 0 is the cpu port */ ··· 662 661 return ret; 663 662 664 663 /* Initialize CPU port pad mode (xMII type, delays...) */ 665 - phy_mode = of_get_phy_mode(dsa_to_port(ds, QCA8K_CPU_PORT)->dn); 666 - if (phy_mode < 0) { 664 + ret = of_get_phy_mode(dsa_to_port(ds, QCA8K_CPU_PORT)->dn, &phy_mode); 665 + if (ret) { 667 666 pr_err("Can't find phy-mode for master device\n"); 668 - return phy_mode; 667 + return ret; 669 668 } 670 669 ret = qca8k_set_pad_ctrl(priv, QCA8K_CPU_PORT, phy_mode); 671 670 if (ret < 0)
+4 -3
drivers/net/dsa/sja1105/sja1105_main.c
··· 584 584 585 585 for_each_child_of_node(ports_node, child) { 586 586 struct device_node *phy_node; 587 - int phy_mode; 587 + phy_interface_t phy_mode; 588 588 u32 index; 589 + int err; 589 590 590 591 /* Get switch port number from DT */ 591 592 if (of_property_read_u32(child, "reg", &index) < 0) { ··· 597 596 } 598 597 599 598 /* Get PHY mode from DT */ 600 - phy_mode = of_get_phy_mode(child); 601 - if (phy_mode < 0) { 599 + err = of_get_phy_mode(child, &phy_mode); 600 + if (err) { 602 601 dev_err(dev, "Failed to read phy-mode or " 603 602 "phy-interface-type property for port %d\n", 604 603 index);
+3 -3
drivers/net/ethernet/altera/altera_tse_main.c
··· 730 730 { 731 731 struct altera_tse_private *priv = netdev_priv(dev); 732 732 struct device_node *np = priv->device->of_node; 733 - int ret = 0; 733 + int ret; 734 734 735 - priv->phy_iface = of_get_phy_mode(np); 735 + ret = of_get_phy_mode(np, &priv->phy_iface); 736 736 737 737 /* Avoid get phy addr and create mdio if no phy is present */ 738 - if (!priv->phy_iface) 738 + if (ret) 739 739 return 0; 740 740 741 741 /* try to get PHY address from device tree, use PHY autodetection if
+10 -5
drivers/net/ethernet/arc/emac_arc.c
··· 20 20 static int emac_arc_probe(struct platform_device *pdev) 21 21 { 22 22 struct device *dev = &pdev->dev; 23 - struct net_device *ndev; 24 23 struct arc_emac_priv *priv; 25 - int interface, err; 24 + phy_interface_t interface; 25 + struct net_device *ndev; 26 + int err; 26 27 27 28 if (!dev->of_node) 28 29 return -ENODEV; ··· 38 37 priv->drv_name = DRV_NAME; 39 38 priv->drv_version = DRV_VERSION; 40 39 41 - interface = of_get_phy_mode(dev->of_node); 42 - if (interface < 0) 43 - interface = PHY_INTERFACE_MODE_MII; 40 + err = of_get_phy_mode(dev->of_node, &interface); 41 + if (err) { 42 + if (err == -ENODEV) 43 + interface = PHY_INTERFACE_MODE_MII; 44 + else 45 + goto out_netdev; 46 + } 44 47 45 48 priv->clk = devm_clk_get(dev, "hclk"); 46 49 if (IS_ERR(priv->clk)) {
+5 -2
drivers/net/ethernet/arc/emac_rockchip.c
··· 97 97 struct net_device *ndev; 98 98 struct rockchip_priv_data *priv; 99 99 const struct of_device_id *match; 100 + phy_interface_t interface; 100 101 u32 data; 101 - int err, interface; 102 + int err; 102 103 103 104 if (!pdev->dev.of_node) 104 105 return -ENODEV; ··· 115 114 priv->emac.drv_version = DRV_VERSION; 116 115 priv->emac.set_mac_speed = emac_rockchip_set_mac_speed; 117 116 118 - interface = of_get_phy_mode(dev->of_node); 117 + err = of_get_phy_mode(dev->of_node, &interface); 118 + if (err) 119 + goto out_netdev; 119 120 120 121 /* RK3036/RK3066/RK3188 SoCs only support RMII */ 121 122 if (interface != PHY_INTERFACE_MODE_RMII) {
+2 -3
drivers/net/ethernet/atheros/ag71xx.c
··· 1744 1744 eth_random_addr(ndev->dev_addr); 1745 1745 } 1746 1746 1747 - ag->phy_if_mode = of_get_phy_mode(np); 1748 - if (ag->phy_if_mode < 0) { 1747 + err = of_get_phy_mode(np, ag->phy_if_mode); 1748 + if (err) { 1749 1749 netif_err(ag, probe, ndev, "missing phy-mode property in DT\n"); 1750 - err = ag->phy_if_mode; 1751 1750 goto err_free; 1752 1751 } 1753 1752
+2 -2
drivers/net/ethernet/aurora/nb8800.c
··· 1371 1371 priv = netdev_priv(dev); 1372 1372 priv->base = base; 1373 1373 1374 - priv->phy_mode = of_get_phy_mode(pdev->dev.of_node); 1375 - if (priv->phy_mode < 0) 1374 + ret = of_get_phy_mode(pdev->dev.of_node, &priv->phy_mode); 1375 + if (ret) 1376 1376 priv->phy_mode = PHY_INTERFACE_MODE_RGMII; 1377 1377 1378 1378 priv->clk = devm_clk_get(&pdev->dev, NULL);
+1 -1
drivers/net/ethernet/aurora/nb8800.h
··· 287 287 struct device_node *phy_node; 288 288 289 289 /* PHY connection type from DT */ 290 - int phy_mode; 290 + phy_interface_t phy_mode; 291 291 292 292 /* Current link status */ 293 293 int speed;
+2 -2
drivers/net/ethernet/broadcom/bcmsysport.c
··· 2479 2479 priv->netdev = dev; 2480 2480 priv->pdev = pdev; 2481 2481 2482 - priv->phy_interface = of_get_phy_mode(dn); 2482 + ret = of_get_phy_mode(dn, &priv->phy_interface); 2483 2483 /* Default to GMII interface mode */ 2484 - if ((int)priv->phy_interface < 0) 2484 + if (ret) 2485 2485 priv->phy_interface = PHY_INTERFACE_MODE_GMII; 2486 2486 2487 2487 /* In the case of a fixed PHY, the DT node associated
+4 -4
drivers/net/ethernet/broadcom/genet/bcmmii.c
··· 436 436 struct device_node *dn = priv->pdev->dev.of_node; 437 437 struct device *kdev = &priv->pdev->dev; 438 438 struct phy_device *phydev; 439 - int phy_mode; 439 + phy_interface_t phy_mode; 440 440 int ret; 441 441 442 442 /* Fetch the PHY phandle */ ··· 454 454 } 455 455 456 456 /* Get the link mode */ 457 - phy_mode = of_get_phy_mode(dn); 458 - if (phy_mode < 0) { 457 + ret = of_get_phy_mode(dn, &phy_mode); 458 + if (ret) { 459 459 dev_err(kdev, "invalid PHY mode property\n"); 460 - return phy_mode; 460 + return ret; 461 461 } 462 462 463 463 priv->phy_interface = phy_mode;
+4 -3
drivers/net/ethernet/cadence/macb_main.c
··· 4182 4182 unsigned int queue_mask, num_queues; 4183 4183 bool native_io; 4184 4184 struct phy_device *phydev; 4185 + phy_interface_t interface; 4185 4186 struct net_device *dev; 4186 4187 struct resource *regs; 4187 4188 void __iomem *mem; ··· 4309 4308 macb_get_hwaddr(bp); 4310 4309 } 4311 4310 4312 - err = of_get_phy_mode(np); 4313 - if (err < 0) 4311 + err = of_get_phy_mode(np, &interface); 4312 + if (err) 4314 4313 /* not found in DT, MII by default */ 4315 4314 bp->phy_interface = PHY_INTERFACE_MODE_MII; 4316 4315 else 4317 - bp->phy_interface = err; 4316 + bp->phy_interface = interface; 4318 4317 4319 4318 /* IP specific init */ 4320 4319 err = init(pdev);
+3 -3
drivers/net/ethernet/faraday/ftgmac100.c
··· 1612 1612 { 1613 1613 struct ftgmac100 *priv = netdev_priv(netdev); 1614 1614 struct platform_device *pdev = to_platform_device(priv->dev); 1615 - int phy_intf = PHY_INTERFACE_MODE_RGMII; 1615 + phy_interface_t phy_intf = PHY_INTERFACE_MODE_RGMII; 1616 1616 struct device_node *np = pdev->dev.of_node; 1617 1617 int i, err = 0; 1618 1618 u32 reg; ··· 1637 1637 /* Get PHY mode from device-tree */ 1638 1638 if (np) { 1639 1639 /* Default to RGMII. It's a gigabit part after all */ 1640 - phy_intf = of_get_phy_mode(np); 1641 - if (phy_intf < 0) 1640 + err = of_get_phy_mode(np, &phy_intf); 1641 + if (err) 1642 1642 phy_intf = PHY_INTERFACE_MODE_RGMII; 1643 1643 1644 1644 /* Aspeed only supports these. I don't know about other IP
+4 -3
drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c
··· 44 44 static int dpaa2_mac_get_if_mode(struct device_node *node, 45 45 struct dpmac_attr attr) 46 46 { 47 - int if_mode; 47 + phy_interface_t if_mode; 48 + int err; 48 49 49 - if_mode = of_get_phy_mode(node); 50 - if (if_mode >= 0) 50 + err = of_get_phy_mode(node, &if_mode); 51 + if (!err) 51 52 return if_mode; 52 53 53 54 if_mode = phy_mode(attr.eth_if);
+2 -2
drivers/net/ethernet/freescale/enetc/enetc_pf.c
··· 784 784 } 785 785 } 786 786 787 - priv->if_mode = of_get_phy_mode(np); 788 - if ((int)priv->if_mode < 0) { 787 + err = of_get_phy_mode(np, &priv->if_mode); 788 + if (err) { 789 789 dev_err(priv->dev, "missing phy type\n"); 790 790 of_node_put(priv->phy_node); 791 791 if (of_phy_is_fixed_link(np))
+4 -3
drivers/net/ethernet/freescale/fec_main.c
··· 3393 3393 { 3394 3394 struct fec_enet_private *fep; 3395 3395 struct fec_platform_data *pdata; 3396 + phy_interface_t interface; 3396 3397 struct net_device *ndev; 3397 3398 int i, irq, ret = 0; 3398 3399 const struct of_device_id *of_id; ··· 3466 3465 } 3467 3466 fep->phy_node = phy_node; 3468 3467 3469 - ret = of_get_phy_mode(pdev->dev.of_node); 3470 - if (ret < 0) { 3468 + ret = of_get_phy_mode(pdev->dev.of_node, &interface); 3469 + if (ret) { 3471 3470 pdata = dev_get_platdata(&pdev->dev); 3472 3471 if (pdata) 3473 3472 fep->phy_interface = pdata->phy; 3474 3473 else 3475 3474 fep->phy_interface = PHY_INTERFACE_MODE_MII; 3476 3475 } else { 3477 - fep->phy_interface = ret; 3476 + fep->phy_interface = interface; 3478 3477 } 3479 3478 3480 3479 fep->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
+3 -3
drivers/net/ethernet/freescale/fman/mac.c
··· 608 608 const u8 *mac_addr; 609 609 u32 val; 610 610 u8 fman_id; 611 - int phy_if; 611 + phy_interface_t phy_if; 612 612 613 613 dev = &_of_dev->dev; 614 614 mac_node = dev->of_node; ··· 776 776 } 777 777 778 778 /* Get the PHY connection type */ 779 - phy_if = of_get_phy_mode(mac_node); 780 - if (phy_if < 0) { 779 + err = of_get_phy_mode(mac_node, &phy_if); 780 + if (err) { 781 781 dev_warn(dev, 782 782 "of_get_phy_mode() for %pOF failed. Defaulting to SGMII\n", 783 783 mac_node);
+4 -3
drivers/net/ethernet/freescale/gianfar.c
··· 641 641 const char *model; 642 642 const void *mac_addr; 643 643 int err = 0, i; 644 + phy_interface_t interface; 644 645 struct net_device *dev = NULL; 645 646 struct gfar_private *priv = NULL; 646 647 struct device_node *np = ofdev->dev.of_node; ··· 806 805 * rgmii-id really needs to be specified. Other types can be 807 806 * detected by hardware 808 807 */ 809 - err = of_get_phy_mode(np); 810 - if (err >= 0) 811 - priv->interface = err; 808 + err = of_get_phy_mode(np, &interface); 809 + if (!err) 810 + priv->interface = interface; 812 811 else 813 812 priv->interface = gfar_get_interface(dev); 814 813
+3 -4
drivers/net/ethernet/hisilicon/hip04_eth.c
··· 211 211 #if defined(CONFIG_HI13X1_GMAC) 212 212 void __iomem *sysctrl_base; 213 213 #endif 214 - int phy_mode; 214 + phy_interface_t phy_mode; 215 215 int chan; 216 216 unsigned int port; 217 217 unsigned int group; ··· 961 961 goto init_fail; 962 962 } 963 963 964 - priv->phy_mode = of_get_phy_mode(node); 965 - if (priv->phy_mode < 0) { 964 + ret = of_get_phy_mode(node, &priv->phy_mode); 965 + if (ret) { 966 966 dev_warn(d, "not find phy-mode\n"); 967 - ret = -EINVAL; 968 967 goto init_fail; 969 968 } 970 969
+2 -3
drivers/net/ethernet/hisilicon/hix5hd2_gmac.c
··· 1193 1193 if (ret) 1194 1194 goto err_free_mdio; 1195 1195 1196 - priv->phy_mode = of_get_phy_mode(node); 1197 - if ((int)priv->phy_mode < 0) { 1196 + ret = of_get_phy_mode(node, &priv->phy_mode); 1197 + if (ret) { 1198 1198 netdev_err(ndev, "not find phy-mode\n"); 1199 - ret = -EINVAL; 1200 1199 goto err_mdiobus; 1201 1200 } 1202 1201
+3 -2
drivers/net/ethernet/ibm/emac/core.c
··· 2849 2849 { 2850 2850 struct device_node *np = dev->ofdev->dev.of_node; 2851 2851 const void *p; 2852 + int err; 2852 2853 2853 2854 /* Read config from device-tree */ 2854 2855 if (emac_read_uint_prop(np, "mal-device", &dev->mal_ph, 1)) ··· 2898 2897 dev->mal_burst_size = 256; 2899 2898 2900 2899 /* PHY mode needs some decoding */ 2901 - dev->phy_mode = of_get_phy_mode(np); 2902 - if (dev->phy_mode < 0) 2900 + err = of_get_phy_mode(np, &dev->phy_mode); 2901 + if (err) 2903 2902 dev->phy_mode = PHY_INTERFACE_MODE_NA; 2904 2903 2905 2904 /* Check EMAC version */
+4 -3
drivers/net/ethernet/marvell/mv643xx_eth.c
··· 2959 2959 static int get_phy_mode(struct mv643xx_eth_private *mp) 2960 2960 { 2961 2961 struct device *dev = mp->dev->dev.parent; 2962 - int iface = -1; 2962 + phy_interface_t iface; 2963 + int err; 2963 2964 2964 2965 if (dev->of_node) 2965 - iface = of_get_phy_mode(dev->of_node); 2966 + err = of_get_phy_mode(dev->of_node, &iface); 2966 2967 2967 2968 /* Historical default if unspecified. We could also read/write 2968 2969 * the interface state in the PSC1 2969 2970 */ 2970 - if (iface < 0) 2971 + if (!dev->of_node || err) 2971 2972 iface = PHY_INTERFACE_MODE_GMII; 2972 2973 return iface; 2973 2974 }
+3 -4
drivers/net/ethernet/marvell/mvneta.c
··· 4797 4797 struct phy *comphy; 4798 4798 const char *dt_mac_addr; 4799 4799 char hw_mac_addr[ETH_ALEN]; 4800 + phy_interface_t phy_mode; 4800 4801 const char *mac_from; 4801 4802 int tx_csum_limit; 4802 - int phy_mode; 4803 4803 int err; 4804 4804 int cpu; 4805 4805 ··· 4812 4812 if (dev->irq == 0) 4813 4813 return -EINVAL; 4814 4814 4815 - phy_mode = of_get_phy_mode(dn); 4816 - if (phy_mode < 0) { 4815 + err = of_get_phy_mode(dn, &phy_mode); 4816 + if (err) { 4817 4817 dev_err(&pdev->dev, "incorrect phy-mode\n"); 4818 - err = -EINVAL; 4819 4818 goto err_free_irq; 4820 4819 } 4821 4820
+3 -1
drivers/net/ethernet/marvell/pxa168_eth.c
··· 1489 1489 goto err_netdev; 1490 1490 } 1491 1491 of_property_read_u32(np, "reg", &pep->phy_addr); 1492 - pep->phy_intf = of_get_phy_mode(pdev->dev.of_node); 1493 1492 of_node_put(np); 1493 + err = of_get_phy_mode(pdev->dev.of_node, &pep->phy_intf); 1494 + if (err && err != -ENODEV) 1495 + goto err_netdev; 1494 1496 } 1495 1497 1496 1498 /* Hardware supports only 3 ports */
+4 -4
drivers/net/ethernet/mediatek/mtk_eth_soc.c
··· 2758 2758 static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np) 2759 2759 { 2760 2760 const __be32 *_id = of_get_property(np, "reg", NULL); 2761 + phy_interface_t phy_mode; 2761 2762 struct phylink *phylink; 2762 - int phy_mode, id, err; 2763 2763 struct mtk_mac *mac; 2764 + int id, err; 2764 2765 2765 2766 if (!_id) { 2766 2767 dev_err(eth->dev, "missing mac id\n"); ··· 2806 2805 mac->hw_stats->reg_offset = id * MTK_STAT_OFFSET; 2807 2806 2808 2807 /* phylink create */ 2809 - phy_mode = of_get_phy_mode(np); 2810 - if (phy_mode < 0) { 2808 + err = of_get_phy_mode(np, &phy_mode); 2809 + if (err) { 2811 2810 dev_err(eth->dev, "incorrect phy-mode\n"); 2812 - err = -EINVAL; 2813 2811 goto free_netdev; 2814 2812 } 2815 2813
+6 -6
drivers/net/ethernet/mscc/ocelot_board.c
··· 364 364 365 365 for_each_available_child_of_node(ports, portnp) { 366 366 struct device_node *phy_node; 367 + phy_interface_t phy_mode; 367 368 struct phy_device *phy; 368 369 struct resource *res; 369 370 struct phy *serdes; 370 371 void __iomem *regs; 371 372 char res_name[8]; 372 - int phy_mode; 373 373 u32 port; 374 374 375 375 if (of_property_read_u32(portnp, "reg", &port)) ··· 398 398 goto out_put_ports; 399 399 } 400 400 401 - phy_mode = of_get_phy_mode(portnp); 402 - if (phy_mode < 0) 403 - ocelot->ports[port]->phy_mode = PHY_INTERFACE_MODE_NA; 404 - else 405 - ocelot->ports[port]->phy_mode = phy_mode; 401 + err = of_get_phy_mode(portnp, &phy_mode); 402 + if (err && err != -ENODEV) 403 + goto out_put_ports; 404 + 405 + ocelot->ports[port]->phy_mode = phy_mode; 406 406 407 407 switch (ocelot->ports[port]->phy_mode) { 408 408 case PHY_INTERFACE_MODE_NA:
+2 -3
drivers/net/ethernet/ni/nixge.c
··· 1346 1346 } 1347 1347 } 1348 1348 1349 - priv->phy_mode = of_get_phy_mode(pdev->dev.of_node); 1350 - if ((int)priv->phy_mode < 0) { 1349 + err = of_get_phy_mode(pdev->dev.of_node, &priv->phy_mode); 1350 + if (err) { 1351 1351 netdev_err(ndev, "not find \"phy-mode\" property\n"); 1352 - err = -EINVAL; 1353 1352 goto unregister_mdio; 1354 1353 } 1355 1354
+3 -1
drivers/net/ethernet/renesas/ravb_main.c
··· 2046 2046 spin_lock_init(&priv->lock); 2047 2047 INIT_WORK(&priv->work, ravb_tx_timeout_work); 2048 2048 2049 - priv->phy_interface = of_get_phy_mode(np); 2049 + error = of_get_phy_mode(np, &priv->phy_interface); 2050 + if (error && error != -ENODEV) 2051 + goto out_release; 2050 2052 2051 2053 priv->no_avb_link = of_property_read_bool(np, "renesas,no-ether-link"); 2052 2054 priv->avb_link_active_low =
+4 -3
drivers/net/ethernet/renesas/sh_eth.c
··· 3183 3183 { 3184 3184 struct device_node *np = dev->of_node; 3185 3185 struct sh_eth_plat_data *pdata; 3186 + phy_interface_t interface; 3186 3187 const char *mac_addr; 3187 3188 int ret; 3188 3189 ··· 3191 3190 if (!pdata) 3192 3191 return NULL; 3193 3192 3194 - ret = of_get_phy_mode(np); 3195 - if (ret < 0) 3193 + ret = of_get_phy_mode(np, &interface); 3194 + if (ret) 3196 3195 return NULL; 3197 - pdata->phy_interface = ret; 3196 + pdata->phy_interface = interface; 3198 3197 3199 3198 mac_addr = of_get_mac_address(np); 3200 3199 if (!IS_ERR(mac_addr))
+4 -1
drivers/net/ethernet/samsung/sxgbe/sxgbe_platform.c
··· 30 30 { 31 31 struct device_node *np = pdev->dev.of_node; 32 32 struct sxgbe_dma_cfg *dma_cfg; 33 + int err; 33 34 34 35 if (!np) 35 36 return -ENODEV; 36 37 37 38 *mac = of_get_mac_address(np); 38 - plat->interface = of_get_phy_mode(np); 39 + err = of_get_phy_mode(np, &plat->interface); 40 + if (err && err != -ENODEV) 41 + return err; 39 42 40 43 plat->bus_id = of_alias_get_id(np, "ethernet"); 41 44 if (plat->bus_id < 0)
+3 -3
drivers/net/ethernet/socionext/sni_ave.c
··· 1565 1565 return -EINVAL; 1566 1566 1567 1567 np = dev->of_node; 1568 - phy_mode = of_get_phy_mode(np); 1569 - if ((int)phy_mode < 0) { 1568 + ret = of_get_phy_mode(np, &phy_mode); 1569 + if (ret) { 1570 1570 dev_err(dev, "phy-mode not found\n"); 1571 - return -EINVAL; 1571 + return ret; 1572 1572 } 1573 1573 1574 1574 irq = platform_get_irq(pdev, 0);
+7 -3
drivers/net/ethernet/stmicro/stmmac/dwmac-anarion.c
··· 61 61 62 62 static struct anarion_gmac *anarion_config_dt(struct platform_device *pdev) 63 63 { 64 - int phy_mode; 65 - void __iomem *ctl_block; 66 64 struct anarion_gmac *gmac; 65 + phy_interface_t phy_mode; 66 + void __iomem *ctl_block; 67 + int err; 67 68 68 69 ctl_block = devm_platform_ioremap_resource(pdev, 1); 69 70 if (IS_ERR(ctl_block)) { ··· 79 78 80 79 gmac->ctl_block = (uintptr_t)ctl_block; 81 80 82 - phy_mode = of_get_phy_mode(pdev->dev.of_node); 81 + err = of_get_phy_mode(pdev->dev.of_node, &phy_mode); 82 + if (err) 83 + return ERR_PTR(err); 84 + 83 85 switch (phy_mode) { 84 86 case PHY_INTERFACE_MODE_RGMII: /* Fall through */ 85 87 case PHY_INTERFACE_MODE_RGMII_ID /* Fall through */:
+3 -2
drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c
··· 189 189 static int ipq806x_gmac_of_parse(struct ipq806x_gmac *gmac) 190 190 { 191 191 struct device *dev = &gmac->pdev->dev; 192 + int ret; 192 193 193 - gmac->phy_mode = of_get_phy_mode(dev->of_node); 194 - if ((int)gmac->phy_mode < 0) { 194 + ret = of_get_phy_mode(dev->of_node, &gmac->phy_mode); 195 + if (ret) { 195 196 dev_err(dev, "missing phy mode property\n"); 196 197 return -EINVAL; 197 198 }
+5 -4
drivers/net/ethernet/stmicro/stmmac/dwmac-mediatek.c
··· 54 54 struct device_node *np; 55 55 struct regmap *peri_regmap; 56 56 struct device *dev; 57 - int phy_mode; 57 + phy_interface_t phy_mode; 58 58 bool rmii_rxc; 59 59 }; 60 60 ··· 243 243 { 244 244 struct mac_delay_struct *mac_delay = &plat->mac_delay; 245 245 u32 tx_delay_ps, rx_delay_ps; 246 + int err; 246 247 247 248 plat->peri_regmap = syscon_regmap_lookup_by_phandle(plat->np, "mediatek,pericfg"); 248 249 if (IS_ERR(plat->peri_regmap)) { ··· 251 250 return PTR_ERR(plat->peri_regmap); 252 251 } 253 252 254 - plat->phy_mode = of_get_phy_mode(plat->np); 255 - if (plat->phy_mode < 0) { 253 + err = of_get_phy_mode(plat->np, &plat->phy_mode); 254 + if (err) { 256 255 dev_err(plat->dev, "not find phy-mode\n"); 257 - return -EINVAL; 256 + return err; 258 257 } 259 258 260 259 if (!of_property_read_u32(plat->np, "mediatek,tx-delay-ps", &tx_delay_ps)) {
+2 -3
drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c
··· 338 338 } 339 339 340 340 dwmac->dev = &pdev->dev; 341 - dwmac->phy_mode = of_get_phy_mode(pdev->dev.of_node); 342 - if ((int)dwmac->phy_mode < 0) { 341 + ret = of_get_phy_mode(pdev->dev.of_node, &dwmac->phy_mode); 342 + if (ret) { 343 343 dev_err(&pdev->dev, "missing phy-mode property\n"); 344 - ret = -EINVAL; 345 344 goto err_remove_config_dt; 346 345 } 347 346
+2 -2
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
··· 37 37 38 38 struct rk_priv_data { 39 39 struct platform_device *pdev; 40 - int phy_iface; 40 + phy_interface_t phy_iface; 41 41 struct regulator *regulator; 42 42 bool suspended; 43 43 const struct rk_gmac_ops *ops; ··· 1224 1224 if (!bsp_priv) 1225 1225 return ERR_PTR(-ENOMEM); 1226 1226 1227 - bsp_priv->phy_iface = of_get_phy_mode(dev->of_node); 1227 + of_get_phy_mode(dev->of_node, &bsp_priv->phy_iface); 1228 1228 bsp_priv->ops = ops; 1229 1229 1230 1230 bsp_priv->regulator = devm_regulator_get_optional(dev, "phy");
+7 -2
drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
··· 116 116 #define ETH_PHY_SEL_MII 0x0 117 117 118 118 struct sti_dwmac { 119 - int interface; /* MII interface */ 119 + phy_interface_t interface; /* MII interface */ 120 120 bool ext_phyclk; /* Clock from external PHY */ 121 121 u32 tx_retime_src; /* TXCLK Retiming*/ 122 122 struct clk *clk; /* PHY clock */ ··· 269 269 return err; 270 270 } 271 271 272 - dwmac->interface = of_get_phy_mode(np); 272 + err = of_get_phy_mode(np, &dwmac->interface); 273 + if (err && err != -ENODEV) { 274 + dev_err(dev, "Can't get phy-mode\n"); 275 + return err; 276 + } 277 + 273 278 dwmac->regmap = regmap; 274 279 dwmac->gmac_en = of_property_read_bool(np, "st,gmac_en"); 275 280 dwmac->ext_phyclk = of_property_read_bool(np, "st,ext-phyclk");
+4 -3
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
··· 1105 1105 struct stmmac_resources stmmac_res; 1106 1106 struct sunxi_priv_data *gmac; 1107 1107 struct device *dev = &pdev->dev; 1108 + phy_interface_t interface; 1108 1109 int ret; 1109 1110 struct stmmac_priv *priv; 1110 1111 struct net_device *ndev; ··· 1179 1178 return ret; 1180 1179 } 1181 1180 1182 - ret = of_get_phy_mode(dev->of_node); 1183 - if (ret < 0) 1181 + ret = of_get_phy_mode(dev->of_node, &interface); 1182 + if (ret) 1184 1183 return -EINVAL; 1185 - plat_dat->interface = ret; 1184 + plat_dat->interface = interface; 1186 1185 1187 1186 /* platform data specifying hardware features and callbacks. 1188 1187 * hardware features were copied from Allwinner drivers.
+6 -2
drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c
··· 18 18 #include "stmmac_platform.h" 19 19 20 20 struct sunxi_priv_data { 21 - int interface; 21 + phy_interface_t interface; 22 22 int clk_enabled; 23 23 struct clk *tx_clk; 24 24 struct regulator *regulator; ··· 118 118 goto err_remove_config_dt; 119 119 } 120 120 121 - gmac->interface = of_get_phy_mode(dev->of_node); 121 + ret = of_get_phy_mode(dev->of_node, &gmac->interface); 122 + if (ret && ret != -ENODEV) { 123 + dev_err(dev, "Can't get phy-mode\n"); 124 + goto err_remove_config_dt; 125 + } 122 126 123 127 gmac->tx_clk = devm_clk_get(dev, "allwinner_gmac_tx"); 124 128 if (IS_ERR(gmac->tx_clk)) {
+3 -3
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
··· 412 412 *mac = NULL; 413 413 } 414 414 415 - plat->phy_interface = of_get_phy_mode(np); 416 - if (plat->phy_interface < 0) 417 - return ERR_PTR(plat->phy_interface); 415 + rc = of_get_phy_mode(np, &plat->phy_interface); 416 + if (rc) 417 + return ERR_PTR(rc); 418 418 419 419 plat->interface = stmmac_of_get_mac_mode(np); 420 420 if (plat->interface < 0)
+2 -3
drivers/net/ethernet/ti/cpsw.c
··· 2619 2619 i); 2620 2620 goto no_phy_slave; 2621 2621 } 2622 - slave_data->phy_if = of_get_phy_mode(slave_node); 2623 - if (slave_data->phy_if < 0) { 2622 + ret = of_get_phy_mode(slave_node, &slave_data->phy_if); 2623 + if (ret) { 2624 2624 dev_err(&pdev->dev, "Missing or malformed slave[%d] phy-mode property\n", 2625 2625 i); 2626 - ret = slave_data->phy_if; 2627 2626 goto err_node_put; 2628 2627 } 2629 2628
+1 -1
drivers/net/ethernet/ti/cpsw_priv.h
··· 275 275 struct device_node *slave_node; 276 276 struct device_node *phy_node; 277 277 char phy_id[MII_BUS_ID_SIZE]; 278 - int phy_if; 278 + phy_interface_t phy_if; 279 279 u8 mac_addr[ETH_ALEN]; 280 280 u16 dual_emac_res_vlan; /* Reserved VLAN for DualEMAC */ 281 281 struct phy *ifphy;
+3 -2
drivers/net/ethernet/ti/netcp_ethss.c
··· 2291 2291 struct gbe_slave *slave = gbe_intf->slave; 2292 2292 phy_interface_t phy_mode; 2293 2293 bool has_phy = false; 2294 + int err; 2294 2295 2295 2296 void (*hndlr)(struct net_device *) = gbe_adjust_link; 2296 2297 ··· 2321 2320 slave->phy_port_t = PORT_MII; 2322 2321 } else if (slave->link_interface == RGMII_LINK_MAC_PHY) { 2323 2322 has_phy = true; 2324 - phy_mode = of_get_phy_mode(slave->node); 2323 + err = of_get_phy_mode(slave->node, &phy_mode); 2325 2324 /* if phy-mode is not present, default to 2326 2325 * PHY_INTERFACE_MODE_RGMII 2327 2326 */ 2328 - if (phy_mode < 0) 2327 + if (err) 2329 2328 phy_mode = PHY_INTERFACE_MODE_RGMII; 2330 2329 2331 2330 if (!phy_interface_mode_is_rgmii(phy_mode)) {
+2 -4
drivers/net/ethernet/xilinx/xilinx_axienet_main.c
··· 1761 1761 goto free_netdev; 1762 1762 } 1763 1763 } else { 1764 - lp->phy_mode = of_get_phy_mode(pdev->dev.of_node); 1765 - if ((int)lp->phy_mode < 0) { 1766 - ret = -EINVAL; 1764 + ret = of_get_phy_mode(pdev->dev.of_node, &lp->phy_mode); 1765 + if (ret) 1767 1766 goto free_netdev; 1768 - } 1769 1767 } 1770 1768 1771 1769 /* Find the DMA node, map the DMA registers, and decode the DMA IRQs */
+2 -2
drivers/of/of_mdio.c
··· 361 361 struct phy_device *phy; 362 362 int ret; 363 363 364 - iface = of_get_phy_mode(np); 365 - if ((int)iface < 0) 364 + ret = of_get_phy_mode(np, &iface); 365 + if (ret) 366 366 return NULL; 367 367 if (of_phy_is_fixed_link(np)) { 368 368 ret = of_phy_register_fixed_link(np);
+11 -5
drivers/of/of_net.c
··· 15 15 /** 16 16 * of_get_phy_mode - Get phy mode for given device_node 17 17 * @np: Pointer to the given device_node 18 + * @interface: Pointer to the result 18 19 * 19 20 * The function gets phy interface string from property 'phy-mode' or 20 - * 'phy-connection-type', and return its index in phy_modes table, or errno in 21 - * error case. 21 + * 'phy-connection-type'. The index in phy_modes table is set in 22 + * interface and 0 returned. In case of error interface is set to 23 + * PHY_INTERFACE_MODE_NA and an errno is returned, e.g. -ENODEV. 22 24 */ 23 - int of_get_phy_mode(struct device_node *np) 25 + int of_get_phy_mode(struct device_node *np, phy_interface_t *interface) 24 26 { 25 27 const char *pm; 26 28 int err, i; 29 + 30 + *interface = PHY_INTERFACE_MODE_NA; 27 31 28 32 err = of_property_read_string(np, "phy-mode", &pm); 29 33 if (err < 0) ··· 36 32 return err; 37 33 38 34 for (i = 0; i < PHY_INTERFACE_MODE_MAX; i++) 39 - if (!strcasecmp(pm, phy_modes(i))) 40 - return i; 35 + if (!strcasecmp(pm, phy_modes(i))) { 36 + *interface = i; 37 + return 0; 38 + } 41 39 42 40 return -ENODEV; 43 41 }
+5 -2
include/linux/of_net.h
··· 6 6 #ifndef __LINUX_OF_NET_H 7 7 #define __LINUX_OF_NET_H 8 8 9 + #include <linux/phy.h> 10 + 9 11 #ifdef CONFIG_OF_NET 10 12 #include <linux/of.h> 11 13 12 14 struct net_device; 13 - extern int of_get_phy_mode(struct device_node *np); 15 + extern int of_get_phy_mode(struct device_node *np, phy_interface_t *interface); 14 16 extern const void *of_get_mac_address(struct device_node *np); 15 17 extern struct net_device *of_find_net_device_by_node(struct device_node *np); 16 18 #else 17 - static inline int of_get_phy_mode(struct device_node *np) 19 + static inline int of_get_phy_mode(struct device_node *np, 20 + phy_interface_t *interface) 18 21 { 19 22 return -ENODEV; 20 23 }
+2 -1
include/linux/stmmac.h
··· 13 13 #define __STMMAC_PLATFORM_DATA 14 14 15 15 #include <linux/platform_device.h> 16 + #include <linux/phy.h> 16 17 17 18 #define MTL_MAX_RX_QUEUES 8 18 19 #define MTL_MAX_TX_QUEUES 8 ··· 133 132 int bus_id; 134 133 int phy_addr; 135 134 int interface; 136 - int phy_interface; 135 + phy_interface_t phy_interface; 137 136 struct stmmac_mdio_bus_data *mdio_bus_data; 138 137 struct device_node *phy_node; 139 138 struct device_node *phylink_node;
+3 -1
include/linux/sxgbe_platform.h
··· 10 10 #ifndef __SXGBE_PLATFORM_H__ 11 11 #define __SXGBE_PLATFORM_H__ 12 12 13 + #include <linux/phy.h> 14 + 13 15 /* MDC Clock Selection define*/ 14 16 #define SXGBE_CSR_100_150M 0x0 /* MDC = clk_scr_i/62 */ 15 17 #define SXGBE_CSR_150_250M 0x1 /* MDC = clk_scr_i/102 */ ··· 40 38 char *phy_bus_name; 41 39 int bus_id; 42 40 int phy_addr; 43 - int interface; 41 + phy_interface_t interface; 44 42 struct sxgbe_mdio_bus_data *mdio_bus_data; 45 43 struct sxgbe_dma_cfg *dma_cfg; 46 44 int clk_csr;
+7 -6
net/dsa/port.c
··· 561 561 struct dsa_switch *ds = dp->ds; 562 562 struct phy_device *phydev; 563 563 int port = dp->index; 564 - int mode; 564 + phy_interface_t mode; 565 565 int err; 566 566 567 567 err = of_phy_register_fixed_link(dn); ··· 574 574 575 575 phydev = of_phy_find_device(dn); 576 576 577 - mode = of_get_phy_mode(dn); 578 - if (mode < 0) 577 + err = of_get_phy_mode(dn, &mode); 578 + if (err) 579 579 mode = PHY_INTERFACE_MODE_NA; 580 580 phydev->interface = mode; 581 581 ··· 593 593 { 594 594 struct dsa_switch *ds = dp->ds; 595 595 struct device_node *port_dn = dp->dn; 596 - int mode, err; 596 + phy_interface_t mode; 597 + int err; 597 598 598 - mode = of_get_phy_mode(port_dn); 599 - if (mode < 0) 599 + err = of_get_phy_mode(port_dn, &mode); 600 + if (err) 600 601 mode = PHY_INTERFACE_MODE_NA; 601 602 602 603 dp->pl_config.dev = ds->dev;
+4 -3
net/dsa/slave.c
··· 1313 1313 struct dsa_port *dp = dsa_slave_to_port(slave_dev); 1314 1314 struct device_node *port_dn = dp->dn; 1315 1315 struct dsa_switch *ds = dp->ds; 1316 + phy_interface_t mode; 1316 1317 u32 phy_flags = 0; 1317 - int mode, ret; 1318 + int ret; 1318 1319 1319 - mode = of_get_phy_mode(port_dn); 1320 - if (mode < 0) 1320 + ret = of_get_phy_mode(port_dn, &mode); 1321 + if (ret) 1321 1322 mode = PHY_INTERFACE_MODE_NA; 1322 1323 1323 1324 dp->pl_config.dev = &slave_dev->dev;