Re: [PATCH v3 net-next 03/13] net: hisilicon: cleanup to prepare for other cases

2016-06-02 Thread Yisen Zhuang
Hi David,

Thanks for your comment, i will use dev name of this mdio bus instead of 
address.

Thanks,

Yisen

在 2016/6/2 7:07, David Miller 写道:
> From: Yisen Zhuang 
> Date: Mon, 30 May 2016 20:34:14 +0800
> 
>> -static void hns_mdio_bus_name(char *name, struct device_node *np)
>> +static void hns_mdio_bus_name(char *name, phys_addr_t addr)
>>  {
>> -const u32 *addr;
>> -u64 taddr = OF_BAD_ADDR;
>> -
>> -addr = of_get_address(np, 0, NULL, NULL);
>> -if (addr)
>> -taddr = of_translate_address(np, addr);
>> -
>> -snprintf(name, MII_BUS_ID_SIZE, "%s@%llx", np->name,
>> - (unsigned long long)taddr);
>> +snprintf(name, MII_BUS_ID_SIZE,
>> + "hns-mdio@%llx", (unsigned long long)addr);
> 
> This is a really bad idea.
> 
> You're passing in the resource address in here, which can be a bus
> address.
> 
> And on a machine with multiple bus domains, the same address can be
> used multiple times.  They are not unique at all in a multi-domain
> system.
> 
> .
> 



Re: [PATCH v3 net-next 03/13] net: hisilicon: cleanup to prepare for other cases

2016-06-01 Thread David Miller
From: Yisen Zhuang 
Date: Mon, 30 May 2016 20:34:14 +0800

> -static void hns_mdio_bus_name(char *name, struct device_node *np)
> +static void hns_mdio_bus_name(char *name, phys_addr_t addr)
>  {
> - const u32 *addr;
> - u64 taddr = OF_BAD_ADDR;
> -
> - addr = of_get_address(np, 0, NULL, NULL);
> - if (addr)
> - taddr = of_translate_address(np, addr);
> -
> - snprintf(name, MII_BUS_ID_SIZE, "%s@%llx", np->name,
> -  (unsigned long long)taddr);
> + snprintf(name, MII_BUS_ID_SIZE,
> +  "hns-mdio@%llx", (unsigned long long)addr);

This is a really bad idea.

You're passing in the resource address in here, which can be a bus
address.

And on a machine with multiple bus domains, the same address can be
used multiple times.  They are not unique at all in a multi-domain
system.


[PATCH v3 net-next 03/13] net: hisilicon: cleanup to prepare for other cases

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan 

Hns-mdio only supports DT case now. do some cleanup to prepare
for introducing other cases later, no functional change.

Signed-off-by: Kejian Yan 
Signed-off-by: Yisen Zhuang 
---
 drivers/net/ethernet/hisilicon/hns_mdio.c | 46 +++
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns_mdio.c 
b/drivers/net/ethernet/hisilicon/hns_mdio.c
index 765ddb3..381cf0a 100644
--- a/drivers/net/ethernet/hisilicon/hns_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns_mdio.c
@@ -354,6 +354,9 @@ static int hns_mdio_reset(struct mii_bus *bus)
struct hns_mdio_device *mdio_dev = (struct hns_mdio_device *)bus->priv;
int ret;
 
+   if (!dev_of_node(bus->parent))
+   return -ENOTSUPP;
+
if (!mdio_dev->subctrl_vbase) {
dev_err(>dev, "mdio sys ctl reg has not maped\n");
return -ENODEV;
@@ -399,19 +402,12 @@ static int hns_mdio_reset(struct mii_bus *bus)
 /**
  * hns_mdio_bus_name - get mdio bus name
  * @name: mdio bus name
- * @np: mdio device node pointer
+ * @addr: mdio physical address
  */
-static void hns_mdio_bus_name(char *name, struct device_node *np)
+static void hns_mdio_bus_name(char *name, phys_addr_t addr)
 {
-   const u32 *addr;
-   u64 taddr = OF_BAD_ADDR;
-
-   addr = of_get_address(np, 0, NULL, NULL);
-   if (addr)
-   taddr = of_translate_address(np, addr);
-
-   snprintf(name, MII_BUS_ID_SIZE, "%s@%llx", np->name,
-(unsigned long long)taddr);
+   snprintf(name, MII_BUS_ID_SIZE,
+"hns-mdio@%llx", (unsigned long long)addr);
 }
 
 /**
@@ -422,17 +418,16 @@ static void hns_mdio_bus_name(char *name, struct 
device_node *np)
  */
 static int hns_mdio_probe(struct platform_device *pdev)
 {
-   struct device_node *np;
struct hns_mdio_device *mdio_dev;
struct mii_bus *new_bus;
struct resource *res;
-   int ret;
+   int ret = -ENODEV;
 
if (!pdev) {
dev_err(NULL, "pdev is NULL!\r\n");
return -ENODEV;
}
-   np = pdev->dev.of_node;
+
mdio_dev = devm_kzalloc(>dev, sizeof(*mdio_dev), GFP_KERNEL);
if (!mdio_dev)
return -ENOMEM;
@@ -448,7 +443,7 @@ static int hns_mdio_probe(struct platform_device *pdev)
new_bus->write = hns_mdio_write;
new_bus->reset = hns_mdio_reset;
new_bus->priv = mdio_dev;
-   hns_mdio_bus_name(new_bus->id, np);
+   new_bus->parent = >dev;
 
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
mdio_dev->vbase = devm_ioremap_resource(>dev, res);
@@ -457,18 +452,23 @@ static int hns_mdio_probe(struct platform_device *pdev)
return ret;
}
 
-   mdio_dev->subctrl_vbase =
-   syscon_node_to_regmap(of_parse_phandle(np, "subctrl-vbase", 0));
-   if (IS_ERR(mdio_dev->subctrl_vbase)) {
-   dev_warn(>dev, "no syscon hisilicon,peri-c-subctrl\n");
-   mdio_dev->subctrl_vbase = NULL;
-   }
-   new_bus->parent = >dev;
platform_set_drvdata(pdev, new_bus);
 
-   ret = of_mdiobus_register(new_bus, np);
+   hns_mdio_bus_name(new_bus->id, res->start);
+   if (dev_of_node(>dev)) {
+   mdio_dev->subctrl_vbase = syscon_node_to_regmap(
+   of_parse_phandle(pdev->dev.of_node,
+"subctrl-vbase", 0));
+   if (IS_ERR(mdio_dev->subctrl_vbase)) {
+   dev_warn(>dev, "no syscon 
hisilicon,peri-c-subctrl\n");
+   mdio_dev->subctrl_vbase = NULL;
+   }
+   ret = of_mdiobus_register(new_bus, pdev->dev.of_node);
+   }
+
if (ret) {
dev_err(>dev, "Cannot register as MDIO bus!\n");
+
platform_set_drvdata(pdev, NULL);
return ret;
}
-- 
1.9.1