Re: [patch net-next 05/11] net: hns: add uniform interface for phy connection
From: Andy Shevchenko
Date: Fri May 13 2016 - 09:06:23 EST
On Fri, 2016-05-13 at 16:19 +0800, Yisen Zhuang wrote:
> From: Kejian Yan <yankejian@xxxxxxxxxx>
>
> As device_node is only used by OF case, HNS needs to treat the others
> cases including ACPI. It needs to use uniform ways to handle both of
> OF and ACPI. This patch chooses phy_device, and of_phy_connect and
> of_phy_attach are only used by OF case. It needs to add uniform
> interface
> to handle that sequence by both OF and ACPI.
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
> +++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
> @@ -987,6 +987,41 @@ static void hns_nic_adjust_link(struct net_device
> *ndev)
> Â h->dev->ops->adjust_link(h, ndev->phydev->speed, ndev-
> >phydev->duplex);
> Â}
> Â
> +static
> +struct phy_device *hns_nic_phy_attach(struct net_device *dev,
> + ÂÂÂÂÂÂstruct phy_device *phy,
> + ÂÂÂÂÂÂu32 flags,
> + ÂÂÂÂÂÂphy_interface_t iface)
> +{
> + int ret;
> +
> + if (!phy)
> + return NULL;
No need to use defensive programming here.
> +
> + ret = phy_attach_direct(dev, phy, flags, iface);
> +
> + return ret ? NULL : phy;
Shouldn't it return an error?
> +}
> +
> +static
> +struct phy_device *hns_nic_phy_connect(struct net_device *dev,
> + ÂÂÂÂÂÂÂstruct phy_device *phy,
> + ÂÂÂÂÂÂÂvoid (*hndlr)(struct
> net_device *),
> + ÂÂÂÂÂÂÂu32 flags,
> + ÂÂÂÂÂÂÂphy_interface_t iface)
> +{
> + int ret;
> +
> + if (!phy)
> + return NULL;
> +
> + phy->dev_flags = flags;
> +
> + ret = phy_connect_direct(dev, phy, hndlr, iface);
> +
> + return ret ? NULL : phy;
> +}
> +
For now looks that above functions are redundant and you may call them
directly in below code.
> Â/**
> Â *hns_nic_init_phy - init phy
> Â *@ndev: net device
> @@ -996,16 +1031,17 @@ static void hns_nic_adjust_link(struct
> net_device *ndev)
> Âint hns_nic_init_phy(struct net_device *ndev, struct hnae_handle *h)
> Â{
> Â struct hns_nic_priv *priv = netdev_priv(ndev);
> - struct phy_device *phy_dev = NULL;
> + struct phy_device *phy_dev = h->phy_dev;
> Â
> - if (!h->phy_node)
> + if (!h->phy_dev)
> Â return 0;
> Â
> Â if (h->phy_if != PHY_INTERFACE_MODE_XGMII)
> - phy_dev = of_phy_connect(ndev, h->phy_node,
> - Âhns_nic_adjust_link, 0, h-
> >phy_if);
> + phy_dev = hns_nic_phy_connect(ndev, phy_dev,
> + ÂÂÂÂÂÂhns_nic_adjust_link,
> + ÂÂÂÂÂÂ0, h->phy_if);
> Â else
> - phy_dev = of_phy_attach(ndev, h->phy_node, 0, h-
> >phy_if);
> + phy_dev = hns_nic_phy_attach(ndev, phy_dev, 0, h-
> >phy_if);
--
Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
Intel Finland Oy