Re: [patch net-next 04/11] net: hns: enet specify a reference to dsaf by fwnode_handle
From: Andy Shevchenko
Date: Fri May 13 2016 - 09:00:19 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, it is expected to find uniform
> ways. So fwnode_handle is the suitable method.
Yeah, and this is part of conversion to fwnode, see previous comment.
>
> Signed-off-by: Kejian Yan <yankejian@xxxxxxxxxx>
> Signed-off-by: Yisen Zhuang <Yisen.Zhuang@xxxxxxxxxx>
> ---
> Âdrivers/net/ethernet/hisilicon/hns/hnae.cÂÂÂÂÂ| 18 ++++++++++++------
> Âdrivers/net/ethernet/hisilicon/hns/hnae.hÂÂÂÂÂ|ÂÂ3 ++-
> Âdrivers/net/ethernet/hisilicon/hns/hns_enet.c | 15 ++++++++-------
> Âdrivers/net/ethernet/hisilicon/hns/hns_enet.h |ÂÂ2 +-
> Â4 files changed, 23 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.c
> b/drivers/net/ethernet/hisilicon/hns/hnae.c
> index 3bfe36f..b5bf12a 100644
> --- a/drivers/net/ethernet/hisilicon/hns/hnae.c
> +++ b/drivers/net/ethernet/hisilicon/hns/hnae.c
> @@ -96,16 +96,22 @@ static int __ae_match(struct device *dev, const
> void *data)
> Â{
> Â struct hnae_ae_dev *hdev = cls_to_ae_dev(dev);
> Â
> - return hdev->dev->of_node == data;
> + if (IS_ENABLED(CONFIG_OF) && hdev->dev->of_node)
> + return (data == &hdev->dev->of_node->fwnode);
> + else if (ACPI_COMPANION(hdev->dev))
> + return (data == hdev->dev->fwnode);
> +
> + dev_err(dev, "__ae_match cannot read cfg data from OF or
> acpi\n");
> + return 0;
> Â}
> Â
> -static struct hnae_ae_dev *find_ae(const struct device_node *ae_node)
> +static struct hnae_ae_dev *find_ae(const struct fwnode_handle
> *fwnode)
> Â{
> Â struct device *dev;
> Â
> - WARN_ON(!ae_node);
> + WARN_ON(!fwnode);
> Â
> - dev = class_find_device(hnae_class, NULL, ae_node,
> __ae_match);
> + dev = class_find_device(hnae_class, NULL, fwnode,
> __ae_match);
> Â
> Â return dev ? cls_to_ae_dev(dev) : NULL;
> Â}
> @@ -312,7 +318,7 @@ EXPORT_SYMBOL(hnae_reinit_handle);
> Â * return handle ptr or ERR_PTR
> Â */
> Âstruct hnae_handle *hnae_get_handle(struct device *owner_dev,
> - ÂÂÂÂconst struct device_node
> *ae_node,
> + ÂÂÂÂconst struct fwnode_handle
> *fwnode,
> Â ÂÂÂÂu32 port_id,
> Â ÂÂÂÂstruct hnae_buf_ops *bops)
> Â{
> @@ -321,7 +327,7 @@ struct hnae_handle *hnae_get_handle(struct device
> *owner_dev,
> Â int i, j;
> Â int ret;
> Â
> - dev = find_ae(ae_node);
> + dev = find_ae(fwnode);
> Â if (!dev)
> Â return ERR_PTR(-ENODEV);
> Â
> diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.h
> b/drivers/net/ethernet/hisilicon/hns/hnae.h
> index e8d36aa..3ad3e55 100644
> --- a/drivers/net/ethernet/hisilicon/hns/hnae.h
> +++ b/drivers/net/ethernet/hisilicon/hns/hnae.h
> @@ -27,6 +27,7 @@
> Â * "cb" means control block
> Â */
> Â
> +#include <linux/acpi.h>
> Â#include <linux/delay.h>
> Â#include <linux/device.h>
> Â#include <linux/module.h>
> @@ -528,7 +529,7 @@ struct hnae_handle {
> Â#define ring_to_dev(ring) ((ring)->q->dev->dev)
> Â
> Âstruct hnae_handle *hnae_get_handle(struct device *owner_dev,
> - ÂÂÂÂconst struct device_node
> *ae_node,
> + ÂÂÂÂconst struct fwnode_handle
> *fwnode,
> Â ÂÂÂÂu32 port_id,
> Â ÂÂÂÂstruct hnae_buf_ops *bops);
> Â
> diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
> b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
> index 8851420..4fa9c21 100644
> --- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
> +++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
> @@ -1807,7 +1807,7 @@ static int hns_nic_try_get_ae(struct net_device
> *ndev)
> Â int ret;
> Â
> Â h = hnae_get_handle(&priv->netdev->dev,
> - ÂÂÂÂpriv->ae_node, priv->port_id, NULL);
> + ÂÂÂÂpriv->fwnode, priv->port_id, NULL);
> Â if (IS_ERR_OR_NULL(h)) {
> Â ret = -ENODEV;
> Â dev_dbg(priv->dev, "has not handle, register
> notifier!\n");
> @@ -1867,7 +1867,7 @@ static int hns_nic_dev_probe(struct
> platform_device *pdev)
> Â struct device *dev = &pdev->dev;
> Â struct net_device *ndev;
> Â struct hns_nic_priv *priv;
> - struct device_node *node = dev->of_node;
> + struct device_node *ae_node;
> Â u32 port_id;
> Â int ret;
> Â
> @@ -1881,18 +1881,19 @@ static int hns_nic_dev_probe(struct
> platform_device *pdev)
> Â priv->dev = dev;
> Â priv->netdev = ndev;
> Â
> - if (of_device_is_compatible(node, "hisilicon,hns-nic-v1"))
> + if (of_device_is_compatible(dev->of_node, "hisilicon,hns-nic-
> v1"))
> Â priv->enet_ver = AE_VERSION_1;
> Â else
> Â priv->enet_ver = AE_VERSION_2;
> Â
> - priv->ae_node = (void *)of_parse_phandle(node, "ae-handle",
> 0);
> - if (IS_ERR_OR_NULL(priv->ae_node)) {
> - ret = PTR_ERR(priv->ae_node);
> + ae_node = of_parse_phandle(dev->of_node, "ae-handle", 0);
> + if (IS_ERR_OR_NULL(ae_node)) {
> + ret = PTR_ERR(ae_node);
> Â dev_err(dev, "not find ae-handle\n");
> Â goto out_read_prop_fail;
> Â }
> - /* try to find port-idx-in-ae first */
> + priv->fwnode = &ae_node->fwnode;
> +
> Â ret = device_property_read_u32(dev, "port-idx-in-ae",
> &port_id);
> Â if (ret) {
> Â /* only for old code compatible */
> diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.h
> b/drivers/net/ethernet/hisilicon/hns/hns_enet.h
> index 337efa5..44bb301 100644
> --- a/drivers/net/ethernet/hisilicon/hns/hns_enet.h
> +++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.h
> @@ -54,7 +54,7 @@ struct hns_nic_ops {
> Â};
> Â
> Âstruct hns_nic_priv {
> - const struct device_node *ae_node;
> + const struct fwnode_handleÂÂÂÂÂÂ*fwnode;
> Â u32 enet_ver;
> Â u32 port_id;
> Â int phy_mode;
--
Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
Intel Finland Oy