All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch net-next 00/11] net: hns: add support of ACPI
@ 2016-05-13  8:19 Yisen Zhuang
  2016-05-13  8:19 ` [patch net-next 01/11] net: hisilicon: add support of acpi for hns-mdio Yisen Zhuang
                   ` (10 more replies)
  0 siblings, 11 replies; 22+ messages in thread
From: Yisen Zhuang @ 2016-05-13  8:19 UTC (permalink / raw)
  To: davem, rjw, lenb
  Cc: arnd, andriy.shevchenko, andrew, geliangtang, ivecera,
	fengguang.wu, charles.chenxin, haifeng.wei, netdev, linux-kernel,
	linuxarm

HNS driver needs to run only in ACPI case, so this series adds HNS
support of acpi. The routine will call some ACPI helper functions,
like acpi_match_device_ids() and acpi_evaluate_dsm(), which are not
included in other cases. In order to make system compile successfully
in other cases except ACPI, it needs to add relative stub functions to
linux/acpi.h.

Hanjun Guo (1):
  ACPI: bus: move acpi_match_device_ids() to linux/acpi.h

Kejian Yan (10):
  net: hisilicon: add support of acpi for hns-mdio
  net: hns: use device_* APIs instead of of_* APIs
  net: hns: use platform_get_irq instead of irq_of_parse_and_map
  net: hns: enet specify a reference to dsaf by fwnode_handle
  net: hns: add uniform interface for phy connection
  net: hns: dsaf adds support of acpi
  net: hns: register phy device in each mac initial sequence
  ACPI: bus: add stub acpi_evaluate_dsm() to linux/acpi.h
  net: hns: implement the reset sequence by asl
  net: hns: enet adds support of acpi

 drivers/net/ethernet/hisilicon/hns/hnae.c          |  18 +-
 drivers/net/ethernet/hisilicon/hns/hnae.h          |   5 +-
 drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c  |   2 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c  | 221 +++++++++---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h  |   2 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c |  95 ++++--
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 372 ++++++++++++++-------
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c  |   5 +-
 drivers/net/ethernet/hisilicon/hns/hns_enet.c      | 112 +++++--
 drivers/net/ethernet/hisilicon/hns/hns_enet.h      |   2 +-
 drivers/net/ethernet/hisilicon/hns/hns_ethtool.c   |   2 +-
 drivers/net/ethernet/hisilicon/hns_mdio.c          | 145 +++++---
 include/acpi/acpi_bus.h                            |   2 -
 include/linux/acpi.h                               |  19 ++
 14 files changed, 712 insertions(+), 290 deletions(-)

-- 
1.9.1

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [patch net-next 01/11] net: hisilicon: add support of acpi for hns-mdio
  2016-05-13  8:19 [patch net-next 00/11] net: hns: add support of ACPI Yisen Zhuang
@ 2016-05-13  8:19 ` Yisen Zhuang
  2016-05-13 12:59   ` Andy Shevchenko
  2016-05-13  8:19 ` [patch net-next 02/11] net: hns: use device_* APIs instead of of_* APIs Yisen Zhuang
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 22+ messages in thread
From: Yisen Zhuang @ 2016-05-13  8:19 UTC (permalink / raw)
  To: davem, rjw, lenb
  Cc: arnd, andriy.shevchenko, andrew, geliangtang, ivecera,
	fengguang.wu, charles.chenxin, haifeng.wei, netdev, linux-kernel,
	linuxarm

From: Kejian Yan <yankejian@huawei.com>

hns-mdio needs to register itself to mii-bus. The info of the device can
be read by both OF and ACPI.
HNS tries to call Linux PHY driver to help access PHY-devices, the HNS
hardware topology is as below. The MDIO controller may control several
PHY-devices, and each PHY-device connects to a MAC device. The MDIO will
be registered to mdiobus, then PHY-devices will register when each mac
find PHY device.
                       cpu
                        |
                        |
     -------------------------------------------
    |                   |                       |
    |                   |                       |
    |                  dsaf                     |
   MDIO                 |                      MDIO
    |      ---------------------------          |
    |     |         |         |       |         |
    |     |         |         |       |         |
    |    MAC       MAC       MAC     MAC        |
    |     |         |         |       |         |
     ---- |-------- |-------- |       | --------
         ||        ||        ||       ||
         PHY       PHY       PHY     PHY

And the driver can handle reset sequence by _DSD method in DSDT in ACPI case.

Signed-off-by: Kejian Yan <yankejian@huawei.com>
Signed-off-by: Yisen Zhuang <Yisen.Zhuang@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns_mdio.c | 145 ++++++++++++++++++------------
 1 file changed, 90 insertions(+), 55 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns_mdio.c b/drivers/net/ethernet/hisilicon/hns_mdio.c
index 765ddb3..4b779df 100644
--- a/drivers/net/ethernet/hisilicon/hns_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns_mdio.c
@@ -7,6 +7,7 @@
  * (at your option) any later version.
  */
 
+#include <linux/acpi.h>
 #include <linux/errno.h>
 #include <linux/etherdevice.h>
 #include <linux/init.h>
@@ -354,64 +355,72 @@ static int hns_mdio_reset(struct mii_bus *bus)
 	struct hns_mdio_device *mdio_dev = (struct hns_mdio_device *)bus->priv;
 	int ret;
 
-	if (!mdio_dev->subctrl_vbase) {
-		dev_err(&bus->dev, "mdio sys ctl reg has not maped\n");
-		return -ENODEV;
-	}
-
-	/*1. reset req, and read reset st check*/
-	ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_RESET_REQ, 0x1,
-				    MDIO_SC_RESET_ST, 0x1,
-				    MDIO_CHECK_SET_ST);
-	if (ret) {
-		dev_err(&bus->dev, "MDIO reset fail\n");
-		return ret;
-	}
+	if (IS_ENABLED(CONFIG_OF) && bus->parent->of_node) {
+		if (!mdio_dev->subctrl_vbase) {
+			dev_err(&bus->dev, "mdio sys ctl reg has not maped\n");
+			return -ENODEV;
+		}
 
-	/*2. dis clk, and read clk st check*/
-	ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_CLK_DIS,
-				    0x1, MDIO_SC_CLK_ST, 0x1,
-				    MDIO_CHECK_CLR_ST);
-	if (ret) {
-		dev_err(&bus->dev, "MDIO dis clk fail\n");
-		return ret;
-	}
+		/*1. reset req, and read reset st check*/
+		ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_RESET_REQ, 0x1,
+					    MDIO_SC_RESET_ST, 0x1,
+					    MDIO_CHECK_SET_ST);
+		if (ret) {
+			dev_err(&bus->dev, "MDIO reset fail\n");
+			return ret;
+		}
 
-	/*3. reset dreq, and read reset st check*/
-	ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_RESET_DREQ, 0x1,
-				    MDIO_SC_RESET_ST, 0x1,
-				    MDIO_CHECK_CLR_ST);
-	if (ret) {
-		dev_err(&bus->dev, "MDIO dis clk fail\n");
-		return ret;
-	}
+		/*2. dis clk, and read clk st check*/
+		ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_CLK_DIS,
+					    0x1, MDIO_SC_CLK_ST, 0x1,
+					    MDIO_CHECK_CLR_ST);
+		if (ret) {
+			dev_err(&bus->dev, "MDIO dis clk fail\n");
+			return ret;
+		}
 
-	/*4. en clk, and read clk st check*/
-	ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_CLK_EN,
-				    0x1, MDIO_SC_CLK_ST, 0x1,
-				    MDIO_CHECK_SET_ST);
-	if (ret)
-		dev_err(&bus->dev, "MDIO en clk fail\n");
+		/*3. reset dreq, and read reset st check*/
+		ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_RESET_DREQ, 0x1,
+					    MDIO_SC_RESET_ST, 0x1,
+					    MDIO_CHECK_CLR_ST);
+		if (ret) {
+			dev_err(&bus->dev, "MDIO dis clk fail\n");
+			return ret;
+		}
 
+		/*4. en clk, and read clk st check*/
+		ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_CLK_EN,
+					    0x1, MDIO_SC_CLK_ST, 0x1,
+					    MDIO_CHECK_SET_ST);
+		if (ret)
+			dev_err(&bus->dev, "MDIO en clk fail\n");
+	} else if (ACPI_COMPANION(bus->parent)) {
+		acpi_status s;
+
+		s = acpi_evaluate_object(ACPI_HANDLE(bus->parent),
+					 "_RST", NULL, NULL);
+		if (ACPI_FAILURE(s)) {
+			dev_err(&bus->dev, "Reset failed, return:%#x\n", s);
+			ret = -EBUSY;
+		} else {
+			ret = 0;
+		}
+	} else {
+		dev_err(&bus->dev, "cannot get cfd data from of or acpi\n");
+		ret = -ENXIO;
+	}
 	return ret;
 }
 
 /**
  * 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,7 +431,6 @@ 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;
@@ -432,7 +440,7 @@ static int hns_mdio_probe(struct platform_device *pdev)
 		dev_err(NULL, "pdev is NULL!\r\n");
 		return -ENODEV;
 	}
-	np = pdev->dev.of_node;
+
 	mdio_dev = devm_kzalloc(&pdev->dev, sizeof(*mdio_dev), GFP_KERNEL);
 	if (!mdio_dev)
 		return -ENOMEM;
@@ -448,7 +456,6 @@ 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);
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	mdio_dev->vbase = devm_ioremap_resource(&pdev->dev, res);
@@ -457,16 +464,37 @@ 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(&pdev->dev, "no syscon hisilicon,peri-c-subctrl\n");
-		mdio_dev->subctrl_vbase = NULL;
+	hns_mdio_bus_name(new_bus->id, res->start);
+	if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
+		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(&pdev->dev, "no syscon hisilicon,peri-c-subctrl\n");
+			mdio_dev->subctrl_vbase = NULL;
+		}
 	}
 	new_bus->parent = &pdev->dev;
 	platform_set_drvdata(pdev, new_bus);
 
-	ret = of_mdiobus_register(new_bus, np);
+	if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
+		ret = of_mdiobus_register(new_bus, pdev->dev.of_node);
+	} else if (ACPI_COMPANION(&pdev->dev)) {
+		/* Clear all the IRQ properties */
+		memset(new_bus->irq, PHY_POLL, 4 * PHY_MAX_ADDR);
+
+		/* Mask out all PHYs from auto probing. */
+		new_bus->phy_mask = ~0;
+
+		/* Register the MDIO bus */
+		ret = mdiobus_register(new_bus);
+		if (ret)
+			return ret;
+	} else {
+		dev_err(&pdev->dev, "cannot get cfd data from of or acpi\n");
+		return -ENXIO;
+	}
+
 	if (ret) {
 		dev_err(&pdev->dev, "Cannot register as MDIO bus!\n");
 		platform_set_drvdata(pdev, NULL);
@@ -499,12 +527,19 @@ static const struct of_device_id hns_mdio_match[] = {
 	{}
 };
 
+static const struct acpi_device_id hns_mdio_acpi_match[] = {
+	{ "HISI0141", 0 },
+	{ },
+};
+MODULE_DEVICE_TABLE(acpi, hns_mdio_acpi_match);
+
 static struct platform_driver hns_mdio_driver = {
 	.probe = hns_mdio_probe,
 	.remove = hns_mdio_remove,
 	.driver = {
 		   .name = MDIO_DRV_NAME,
 		   .of_match_table = hns_mdio_match,
+		   .acpi_match_table = ACPI_PTR(hns_mdio_acpi_match),
 		   },
 };
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [patch net-next 02/11] net: hns: use device_* APIs instead of of_* APIs
  2016-05-13  8:19 [patch net-next 00/11] net: hns: add support of ACPI Yisen Zhuang
  2016-05-13  8:19 ` [patch net-next 01/11] net: hisilicon: add support of acpi for hns-mdio Yisen Zhuang
@ 2016-05-13  8:19 ` Yisen Zhuang
  2016-05-13  8:19 ` [patch net-next 03/11] net: hns: use platform_get_irq instead of irq_of_parse_and_map Yisen Zhuang
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 22+ messages in thread
From: Yisen Zhuang @ 2016-05-13  8:19 UTC (permalink / raw)
  To: davem, rjw, lenb
  Cc: arnd, andriy.shevchenko, andrew, geliangtang, ivecera,
	fengguang.wu, charles.chenxin, haifeng.wei, netdev, linux-kernel,
	linuxarm

From: Kejian Yan <yankejian@huawei.com>

OF series functions can be used only for OF case. It needs to be similar
series function for the others cases. There are uniform interface which
has device_ prefix to get properties from the platform firmware. So this
patch will use the device_* series functions instead of of_* functions.

Signed-off-by: Kejian Yan <yankejian@huawei.com>
Signed-off-by: Yisen Zhuang <Yisen.Zhuang@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c |  9 +++++----
 drivers/net/ethernet/hisilicon/hns/hns_enet.c      | 11 +++--------
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
index 1c2ddb2..9afc5e6 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
@@ -50,7 +50,7 @@ int hns_dsaf_get_cfg(struct dsaf_device *dsaf_dev)
 	else
 		dsaf_dev->dsaf_ver = AE_VERSION_2;
 
-	ret = of_property_read_string(np, "mode", &mode_str);
+	ret = device_property_read_string(dsaf_dev->dev, "mode", &mode_str);
 	if (ret) {
 		dev_err(dsaf_dev->dev, "get dsaf mode fail, ret=%d!\n", ret);
 		return ret;
@@ -142,7 +142,7 @@ int hns_dsaf_get_cfg(struct dsaf_device *dsaf_dev)
 		}
 	}
 
-	ret = of_property_read_u32(np, "desc-num", &desc_num);
+	ret = device_property_read_u32(dsaf_dev->dev, "desc-num", &desc_num);
 	if (ret < 0 || desc_num < HNS_DSAF_MIN_DESC_CNT ||
 	    desc_num > HNS_DSAF_MAX_DESC_CNT) {
 		dev_err(dsaf_dev->dev, "get desc-num(%d) fail, ret=%d!\n",
@@ -151,14 +151,15 @@ int hns_dsaf_get_cfg(struct dsaf_device *dsaf_dev)
 	}
 	dsaf_dev->desc_num = desc_num;
 
-	ret = of_property_read_u32(np, "reset-field-offset", &reset_offset);
+	ret = device_property_read_u32(dsaf_dev->dev, "reset-field-offset",
+				       &reset_offset);
 	if (ret < 0) {
 		dev_dbg(dsaf_dev->dev,
 			"get reset-field-offset fail, ret=%d!\r\n", ret);
 	}
 	dsaf_dev->reset_offset = reset_offset;
 
-	ret = of_property_read_u32(np, "buf-size", &buf_size);
+	ret = device_property_read_u32(dsaf_dev->dev, "buf-size", &buf_size);
 	if (ret < 0) {
 		dev_err(dsaf_dev->dev,
 			"get buf-size fail, ret=%d!\r\n", ret);
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index e621636..8851420 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -1067,13 +1067,8 @@ void hns_nic_update_stats(struct net_device *netdev)
 static void hns_init_mac_addr(struct net_device *ndev)
 {
 	struct hns_nic_priv *priv = netdev_priv(ndev);
-	struct device_node *node = priv->dev->of_node;
-	const void *mac_addr_temp;
 
-	mac_addr_temp = of_get_mac_address(node);
-	if (mac_addr_temp && is_valid_ether_addr(mac_addr_temp)) {
-		memcpy(ndev->dev_addr, mac_addr_temp, ndev->addr_len);
-	} else {
+	if (!device_get_mac_address(priv->dev, ndev->dev_addr, ETH_ALEN)) {
 		eth_hw_addr_random(ndev);
 		dev_warn(priv->dev, "No valid mac, use random mac %pM",
 			 ndev->dev_addr);
@@ -1898,10 +1893,10 @@ static int hns_nic_dev_probe(struct platform_device *pdev)
 		goto out_read_prop_fail;
 	}
 	/* try to find port-idx-in-ae first */
-	ret = of_property_read_u32(node, "port-idx-in-ae", &port_id);
+	ret = device_property_read_u32(dev, "port-idx-in-ae", &port_id);
 	if (ret) {
 		/* only for old code compatible */
-		ret = of_property_read_u32(node, "port-id", &port_id);
+		ret = device_property_read_u32(dev, "port-id", &port_id);
 		if (ret)
 			goto out_read_prop_fail;
 		/* for old dts, we need to caculate the port offset */
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [patch net-next 03/11] net: hns: use platform_get_irq instead of irq_of_parse_and_map
  2016-05-13  8:19 [patch net-next 00/11] net: hns: add support of ACPI Yisen Zhuang
  2016-05-13  8:19 ` [patch net-next 01/11] net: hisilicon: add support of acpi for hns-mdio Yisen Zhuang
  2016-05-13  8:19 ` [patch net-next 02/11] net: hns: use device_* APIs instead of of_* APIs Yisen Zhuang
@ 2016-05-13  8:19 ` Yisen Zhuang
  2016-05-13  8:19 ` [patch net-next 04/11] net: hns: enet specify a reference to dsaf by fwnode_handle Yisen Zhuang
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 22+ messages in thread
From: Yisen Zhuang @ 2016-05-13  8:19 UTC (permalink / raw)
  To: davem, rjw, lenb
  Cc: arnd, andriy.shevchenko, andrew, geliangtang, ivecera,
	fengguang.wu, charles.chenxin, haifeng.wei, netdev, linux-kernel,
	linuxarm

From: Kejian Yan <yankejian@huawei.com>

As irq_of_parse_and_map is only used by OF case, it is excepted to use
a uniform interface. So it is used platform_get_irq() instead.

Signed-off-by: Kejian Yan <yankejian@huawei.com>
Signed-off-by: Yisen Zhuang <Yisen.Zhuang@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c
index 4ef6d23..3ce2409 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c
@@ -458,7 +458,6 @@ void hns_rcb_get_cfg(struct rcb_common_cb *rcb_common)
 	u32 i;
 	u32 ring_num = rcb_common->ring_num;
 	int base_irq_idx = hns_rcb_get_base_irq_idx(rcb_common);
-	struct device_node *np = rcb_common->dsaf_dev->dev->of_node;
 	struct platform_device *pdev =
 		to_platform_device(rcb_common->dsaf_dev->dev);
 	bool is_ver1 = AE_IS_VER1(rcb_common->dsaf_dev->dsaf_ver);
@@ -473,10 +472,10 @@ void hns_rcb_get_cfg(struct rcb_common_cb *rcb_common)
 		ring_pair_cb->port_id_in_comm =
 			hns_rcb_get_port_in_comm(rcb_common, i);
 		ring_pair_cb->virq[HNS_RCB_IRQ_IDX_TX] =
-		is_ver1 ? irq_of_parse_and_map(np, base_irq_idx + i * 2) :
+		is_ver1 ? platform_get_irq(pdev, base_irq_idx + i * 2) :
 			  platform_get_irq(pdev, base_irq_idx + i * 3 + 1);
 		ring_pair_cb->virq[HNS_RCB_IRQ_IDX_RX] =
-		is_ver1 ? irq_of_parse_and_map(np, base_irq_idx + i * 2 + 1) :
+		is_ver1 ? platform_get_irq(pdev, base_irq_idx + i * 2 + 1) :
 			  platform_get_irq(pdev, base_irq_idx + i * 3);
 		ring_pair_cb->q.phy_base =
 			RCB_COMM_BASE_TO_RING_BASE(rcb_common->phy_base, i);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [patch net-next 04/11] net: hns: enet specify a reference to dsaf by fwnode_handle
  2016-05-13  8:19 [patch net-next 00/11] net: hns: add support of ACPI Yisen Zhuang
                   ` (2 preceding siblings ...)
  2016-05-13  8:19 ` [patch net-next 03/11] net: hns: use platform_get_irq instead of irq_of_parse_and_map Yisen Zhuang
@ 2016-05-13  8:19 ` Yisen Zhuang
  2016-05-13 13:01   ` Andy Shevchenko
  2016-05-13  8:19 ` [patch net-next 05/11] net: hns: add uniform interface for phy connection Yisen Zhuang
                   ` (6 subsequent siblings)
  10 siblings, 1 reply; 22+ messages in thread
From: Yisen Zhuang @ 2016-05-13  8:19 UTC (permalink / raw)
  To: davem, rjw, lenb
  Cc: arnd, andriy.shevchenko, andrew, geliangtang, ivecera,
	fengguang.wu, charles.chenxin, haifeng.wei, netdev, linux-kernel,
	linuxarm

From: Kejian Yan <yankejian@huawei.com>

As device_node is only used by OF case, it is expected to find uniform
ways. So fwnode_handle is the suitable method.

Signed-off-by: Kejian Yan <yankejian@huawei.com>
Signed-off-by: Yisen Zhuang <Yisen.Zhuang@huawei.com>
---
 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;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [patch net-next 05/11] net: hns: add uniform interface for phy connection
  2016-05-13  8:19 [patch net-next 00/11] net: hns: add support of ACPI Yisen Zhuang
                   ` (3 preceding siblings ...)
  2016-05-13  8:19 ` [patch net-next 04/11] net: hns: enet specify a reference to dsaf by fwnode_handle Yisen Zhuang
@ 2016-05-13  8:19 ` Yisen Zhuang
  2016-05-13 13:07   ` Andy Shevchenko
  2016-05-13  8:19 ` [patch net-next 06/11] ACPI: bus: move acpi_match_device_ids() to linux/acpi.h Yisen Zhuang
                   ` (5 subsequent siblings)
  10 siblings, 1 reply; 22+ messages in thread
From: Yisen Zhuang @ 2016-05-13  8:19 UTC (permalink / raw)
  To: davem, rjw, lenb
  Cc: arnd, andriy.shevchenko, andrew, geliangtang, ivecera,
	fengguang.wu, charles.chenxin, haifeng.wei, netdev, linux-kernel,
	linuxarm

From: Kejian Yan <yankejian@huawei.com>

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.

Signed-off-by: Kejian Yan <yankejian@huawei.com>
Signed-off-by: Yisen Zhuang <Yisen.Zhuang@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hnae.h          |  2 +-
 drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c  |  2 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c  | 34 +++++++++++-----
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h  |  2 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c |  2 +-
 drivers/net/ethernet/hisilicon/hns/hns_enet.c      | 46 +++++++++++++++++++---
 drivers/net/ethernet/hisilicon/hns/hns_ethtool.c   |  2 +-
 7 files changed, 70 insertions(+), 20 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.h b/drivers/net/ethernet/hisilicon/hns/hnae.h
index 3ad3e55..529cb13 100644
--- a/drivers/net/ethernet/hisilicon/hns/hnae.h
+++ b/drivers/net/ethernet/hisilicon/hns/hnae.h
@@ -513,7 +513,7 @@ struct hnae_ae_dev {
 struct hnae_handle {
 	struct device *owner_dev; /* the device which make use of this handle */
 	struct hnae_ae_dev *dev;  /* the device who provides this handle */
-	struct device_node *phy_node;
+	struct phy_device *phy_dev;
 	phy_interface_t phy_if;
 	u32 if_support;
 	int q_num;
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
index 7a757e8..8e009f4 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
@@ -131,7 +131,7 @@ struct hnae_handle *hns_ae_get_handle(struct hnae_ae_dev *dev,
 	vf_cb->mac_cb = dsaf_dev->mac_cb[port_id];
 
 	ae_handle->phy_if = vf_cb->mac_cb->phy_if;
-	ae_handle->phy_node = vf_cb->mac_cb->phy_node;
+	ae_handle->phy_dev = vf_cb->mac_cb->phy_dev;
 	ae_handle->if_support = vf_cb->mac_cb->if_support;
 	ae_handle->port_type = vf_cb->mac_cb->mac_type;
 	ae_handle->dport_id = port_id;
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
index 611581f..527b49d 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
@@ -15,7 +15,8 @@
 #include <linux/netdevice.h>
 #include <linux/of.h>
 #include <linux/of_address.h>
-#include <linux/phy_fixed.h>
+#include <linux/of_mdio.h>
+#include <linux/phy.h>
 #include <linux/platform_device.h>
 
 #include "hns_dsaf_main.h"
@@ -645,7 +646,7 @@ free_mac_drv:
  */
 static int  hns_mac_get_info(struct hns_mac_cb *mac_cb)
 {
-	struct device_node *np = mac_cb->dev->of_node;
+	struct device_node *np;
 	struct regmap *syscon;
 	struct of_phandle_args cpld_args;
 	u32 ret;
@@ -672,21 +673,34 @@ static int  hns_mac_get_info(struct hns_mac_cb *mac_cb)
 	 * from dsaf node
 	 */
 	if (!mac_cb->fw_port) {
-		mac_cb->phy_node = of_parse_phandle(np, "phy-handle",
-						    mac_cb->mac_id);
-		if (mac_cb->phy_node)
+		np = of_parse_phandle(mac_cb->dev->of_node, "phy-handle",
+				      mac_cb->mac_id);
+		mac_cb->phy_dev = of_phy_find_device(np);
+		if (mac_cb->phy_dev) {
+			/* refcount is held by of_phy_find_device()
+			 * if the phy_dev is found
+			 */
+			put_device(&mac_cb->phy_dev->mdio.dev);
+
 			dev_dbg(mac_cb->dev, "mac%d phy_node: %s\n",
-				mac_cb->mac_id, mac_cb->phy_node->name);
+				mac_cb->mac_id, np->name);
+		}
+
 		return 0;
 	}
+
 	if (!is_of_node(mac_cb->fw_port))
 		return -EINVAL;
+
 	/* parse property from port subnode in dsaf */
-	mac_cb->phy_node = of_parse_phandle(to_of_node(mac_cb->fw_port),
-					    "phy-handle", 0);
-	if (mac_cb->phy_node)
+	np = of_parse_phandle(to_of_node(mac_cb->fw_port), "phy-handle", 0);
+	mac_cb->phy_dev = of_phy_find_device(np);
+	if (mac_cb->phy_dev) {
+		put_device(&mac_cb->phy_dev->mdio.dev);
 		dev_dbg(mac_cb->dev, "mac%d phy_node: %s\n",
-			mac_cb->mac_id, mac_cb->phy_node->name);
+			mac_cb->mac_id, np->name);
+		}
+
 	syscon = syscon_node_to_regmap(
 			of_parse_phandle(to_of_node(mac_cb->fw_port),
 					 "serdes-syscon", 0));
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h
index 97ce9a7..89b49d7 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h
@@ -338,7 +338,7 @@ struct hns_mac_cb {
 	phy_interface_t phy_if;
 	enum hnae_loop loop_mode;
 
-	struct device_node *phy_node;
+	struct phy_device *phy_dev;
 
 	struct mac_hw_stats hw_stats;
 };
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
index a837bb9..a843a86 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
@@ -332,7 +332,7 @@ int hns_mac_config_sds_loopback(struct hns_mac_cb *mac_cb, u8 en)
 	int sfp_prsnt;
 	int ret = hns_mac_get_sfp_prsnt(mac_cb, &sfp_prsnt);
 
-	if (!mac_cb->phy_node) {
+	if (!mac_cb->phy_dev) {
 		if (ret)
 			pr_info("please confirm sfp is present or not\n");
 		else
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index 4fa9c21..34ebe7d 100644
--- 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;
+
+	ret = phy_attach_direct(dev, phy, flags, iface);
+
+	return ret ? NULL : phy;
+}
+
+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;
+}
+
 /**
  *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);
 
 	if (unlikely(!phy_dev) || IS_ERR(phy_dev))
 		return !phy_dev ? -ENODEV : PTR_ERR(phy_dev);
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
index 3d746c8..03007d2 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
@@ -597,7 +597,7 @@ static void hns_nic_self_test(struct net_device *ndev,
 	st_param[1][0] = MAC_INTERNALLOOP_SERDES;
 	st_param[1][1] = 1; /*serdes must exist*/
 	st_param[2][0] = MAC_INTERNALLOOP_PHY; /* only supporte phy node*/
-	st_param[2][1] = ((!!(priv->ae_handle->phy_node)) &&
+	st_param[2][1] = ((!!(priv->ae_handle->phy_dev)) &&
 		(priv->ae_handle->phy_if != PHY_INTERFACE_MODE_XGMII));
 
 	if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [patch net-next 06/11] ACPI: bus: move acpi_match_device_ids() to linux/acpi.h
  2016-05-13  8:19 [patch net-next 00/11] net: hns: add support of ACPI Yisen Zhuang
                   ` (4 preceding siblings ...)
  2016-05-13  8:19 ` [patch net-next 05/11] net: hns: add uniform interface for phy connection Yisen Zhuang
@ 2016-05-13  8:19 ` Yisen Zhuang
  2016-05-13 13:15   ` Andy Shevchenko
  2016-05-13  8:19 ` [patch net-next 07/11] net: hns: dsaf adds support of acpi Yisen Zhuang
                   ` (4 subsequent siblings)
  10 siblings, 1 reply; 22+ messages in thread
From: Yisen Zhuang @ 2016-05-13  8:19 UTC (permalink / raw)
  To: davem, rjw, lenb
  Cc: arnd, andriy.shevchenko, andrew, geliangtang, ivecera,
	fengguang.wu, charles.chenxin, haifeng.wei, netdev, linux-kernel,
	linuxarm

From: Hanjun Guo <hanjun.guo@linaro.org>

acpi_match_device_ids() will be used for drivers to match
different hardware versions, it will be compiled in non-ACPI
case, but acpi_match_device_ids() in acpi_bus.h and it can
only be used in ACPI case, so move it to linux/acpi.h and
introduce a stub function for it.

Signed-off-by: Hanjun Guo <hanjun.guo@linaro.org>
Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
Signed-off-by: Kejian Yan <yankejian@huawei.com>
Signed-off-by: Yisen Zhuang <Yisen.Zhuang@huawei.com>
---
 include/acpi/acpi_bus.h |  2 --
 include/linux/acpi.h    | 11 +++++++++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 3a93250..12cf2cb 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -513,8 +513,6 @@ void acpi_bus_unregister_driver(struct acpi_driver *driver);
 int acpi_bus_scan(acpi_handle handle);
 void acpi_bus_trim(struct acpi_device *start);
 acpi_status acpi_bus_get_ejd(acpi_handle handle, acpi_handle * ejd);
-int acpi_match_device_ids(struct acpi_device *device,
-			  const struct acpi_device_id *ids);
 int acpi_create_dir(struct acpi_device *);
 void acpi_remove_dir(struct acpi_device *);
 
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 06ed7e5..e578bce 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -933,7 +933,18 @@ int __acpi_probe_device_table(struct acpi_probe_entry *start, int nr);
 					  (&ACPI_PROBE_TABLE_END(t) -	\
 					   &ACPI_PROBE_TABLE(t)));	\
 	})
+
+int acpi_match_device_ids(struct acpi_device *device,
+			  const struct acpi_device_id *ids);
+
 #else
+
+static inline int acpi_match_device_ids(struct acpi_device *device,
+					const struct acpi_device_id *ids)
+{
+	return -ENOENT;
+}
+
 static inline int acpi_dev_get_property(struct acpi_device *adev,
 					const char *name, acpi_object_type type,
 					const union acpi_object **obj)
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [patch net-next 07/11] net: hns: dsaf adds support of acpi
  2016-05-13  8:19 [patch net-next 00/11] net: hns: add support of ACPI Yisen Zhuang
                   ` (5 preceding siblings ...)
  2016-05-13  8:19 ` [patch net-next 06/11] ACPI: bus: move acpi_match_device_ids() to linux/acpi.h Yisen Zhuang
@ 2016-05-13  8:19 ` Yisen Zhuang
  2016-05-13 13:12   ` Andy Shevchenko
  2016-05-13  8:19 ` [patch net-next 08/11] net: hns: register phy device in each mac initial sequence Yisen Zhuang
                   ` (3 subsequent siblings)
  10 siblings, 1 reply; 22+ messages in thread
From: Yisen Zhuang @ 2016-05-13  8:19 UTC (permalink / raw)
  To: davem, rjw, lenb
  Cc: arnd, andriy.shevchenko, andrew, geliangtang, ivecera,
	fengguang.wu, charles.chenxin, haifeng.wei, netdev, linux-kernel,
	linuxarm

From: Kejian Yan <yankejian@huawei.com>

Dsaf needs to get configuration parameter by ACPI, so this patch add
support of ACPI.

Signed-off-by: Kejian Yan <yankejian@huawei.com>
Signed-off-by: Yisen Zhuang <Yisen.Zhuang@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c  |  80 +++----
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c |  86 ++++---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 259 ++++++++++++---------
 3 files changed, 244 insertions(+), 181 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
index 527b49d..6e8f2b3 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
@@ -689,9 +689,7 @@ static int  hns_mac_get_info(struct hns_mac_cb *mac_cb)
 		return 0;
 	}
 
-	if (!is_of_node(mac_cb->fw_port))
-		return -EINVAL;
-
+	if (is_of_node(mac_cb->fw_port)) {
 	/* parse property from port subnode in dsaf */
 	np = of_parse_phandle(to_of_node(mac_cb->fw_port), "phy-handle", 0);
 	mac_cb->phy_dev = of_phy_find_device(np);
@@ -701,47 +699,49 @@ static int  hns_mac_get_info(struct hns_mac_cb *mac_cb)
 			mac_cb->mac_id, np->name);
 		}
 
-	syscon = syscon_node_to_regmap(
-			of_parse_phandle(to_of_node(mac_cb->fw_port),
-					 "serdes-syscon", 0));
-	if (IS_ERR_OR_NULL(syscon)) {
-		dev_err(mac_cb->dev, "serdes-syscon is needed!\n");
-		return -EINVAL;
-	}
-	mac_cb->serdes_ctrl = syscon;
-
-	ret = fwnode_property_read_u32(mac_cb->fw_port,
-				       "port-rst-offset",
-				       &mac_cb->port_rst_off);
-	if (ret) {
-		dev_dbg(mac_cb->dev,
-			"mac%d port-rst-offset not found, use default value.\n",
-			mac_cb->mac_id);
-	}
+		syscon = syscon_node_to_regmap(
+				of_parse_phandle(to_of_node(mac_cb->fw_port),
+						 "serdes-syscon", 0));
+		if (IS_ERR_OR_NULL(syscon)) {
+			dev_err(mac_cb->dev, "serdes-syscon is needed!\n");
+			return -EINVAL;
+		}
+		mac_cb->serdes_ctrl = syscon;
 
-	ret = fwnode_property_read_u32(mac_cb->fw_port,
-				       "port-mode-offset",
-				       &mac_cb->port_mode_off);
-	if (ret) {
-		dev_dbg(mac_cb->dev,
-			"mac%d port-mode-offset not found, use default value.\n",
-			mac_cb->mac_id);
-	}
+		ret = fwnode_property_read_u32(mac_cb->fw_port,
+					       "port-rst-offset",
+					       &mac_cb->port_rst_off);
+		if (ret) {
+			dev_dbg(mac_cb->dev,
+				"mac%d port-rst-offset not found, use default value.\n",
+				mac_cb->mac_id);
+		}
 
-	ret = of_parse_phandle_with_fixed_args(to_of_node(mac_cb->fw_port),
-					       "cpld-syscon", 1, 0, &cpld_args);
-	if (ret) {
-		dev_dbg(mac_cb->dev, "mac%d no cpld-syscon found.\n",
-			mac_cb->mac_id);
-		mac_cb->cpld_ctrl = NULL;
-	} else {
-		syscon = syscon_node_to_regmap(cpld_args.np);
-		if (IS_ERR_OR_NULL(syscon)) {
-			dev_dbg(mac_cb->dev, "no cpld-syscon found!\n");
+		ret = fwnode_property_read_u32(mac_cb->fw_port,
+					       "port-mode-offset",
+					       &mac_cb->port_mode_off);
+		if (ret) {
+			dev_dbg(mac_cb->dev,
+				"mac%d port-mode-offset not found, use default value.\n",
+				mac_cb->mac_id);
+		}
+
+		ret = of_parse_phandle_with_fixed_args(
+			to_of_node(mac_cb->fw_port), "cpld-syscon", 1, 0,
+			&cpld_args);
+		if (ret) {
+			dev_dbg(mac_cb->dev, "mac%d no cpld-syscon found.\n",
+				mac_cb->mac_id);
 			mac_cb->cpld_ctrl = NULL;
 		} else {
-			mac_cb->cpld_ctrl = syscon;
-			mac_cb->cpld_ctrl_reg = cpld_args.args[0];
+			syscon = syscon_node_to_regmap(cpld_args.np);
+			if (IS_ERR_OR_NULL(syscon)) {
+				dev_dbg(mac_cb->dev, "no cpld-syscon found!\n");
+				mac_cb->cpld_ctrl = NULL;
+			} else {
+				mac_cb->cpld_ctrl = syscon;
+				mac_cb->cpld_ctrl_reg = cpld_args.args[0];
+			}
 		}
 	}
 
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
index 9afc5e6..da878b1 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
@@ -7,6 +7,7 @@
  * (at your option) any later version.
  */
 
+#include <linux/acpi.h>
 #include <linux/device.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
@@ -32,6 +33,13 @@ const char *g_dsaf_mode_match[DSAF_MODE_MAX] = {
 	[DSAF_MODE_DISABLE_SP] = "single-port",
 };
 
+static const struct acpi_device_id hns_dsaf_acpi_match[] = {
+	{ "HISI00B1", 0 },
+	{ "HISI00B2", 0 },
+	{ },
+};
+MODULE_DEVICE_TABLE(acpi, hns_dsaf_acpi_match);
+
 int hns_dsaf_get_cfg(struct dsaf_device *dsaf_dev)
 {
 	int ret, i;
@@ -43,12 +51,25 @@ int hns_dsaf_get_cfg(struct dsaf_device *dsaf_dev)
 	struct regmap *syscon;
 	struct resource *res;
 	struct device_node *np = dsaf_dev->dev->of_node;
+	struct fwnode_handle *fwnode = dsaf_dev->dev->fwnode;
+	struct acpi_device *adev;
 	struct platform_device *pdev = to_platform_device(dsaf_dev->dev);
 
-	if (of_device_is_compatible(np, "hisilicon,hns-dsaf-v1"))
-		dsaf_dev->dsaf_ver = AE_VERSION_1;
-	else
-		dsaf_dev->dsaf_ver = AE_VERSION_2;
+	if (IS_ENABLED(CONFIG_OF) && np) {
+		if (of_device_is_compatible(np, "hisilicon,hns-dsaf-v1"))
+			dsaf_dev->dsaf_ver = AE_VERSION_1;
+		else
+			dsaf_dev->dsaf_ver = AE_VERSION_2;
+	} else if (ACPI_COMPANION(dsaf_dev->dev)) {
+		adev = to_acpi_device_node(fwnode);
+		if (!acpi_match_device_ids(adev, &hns_dsaf_acpi_match[1]))
+			dsaf_dev->dsaf_ver = AE_VERSION_2;
+		else
+			dsaf_dev->dsaf_ver = AE_VERSION_1;
+	} else {
+		dev_err(dsaf_dev->dev, "cannot get cfd data from of or acpi\n");
+		return -ENXIO;
+	}
 
 	ret = device_property_read_string(dsaf_dev->dev, "mode", &mode_str);
 	if (ret) {
@@ -80,32 +101,40 @@ int hns_dsaf_get_cfg(struct dsaf_device *dsaf_dev)
 	else
 		dsaf_dev->dsaf_tc_mode = HRD_DSAF_4TC_MODE;
 
-	syscon = syscon_node_to_regmap(
-			of_parse_phandle(np, "subctrl-syscon", 0));
-	if (IS_ERR_OR_NULL(syscon)) {
-		res = platform_get_resource(pdev, IORESOURCE_MEM, res_idx++);
-		if (!res) {
-			dev_err(dsaf_dev->dev, "subctrl info is needed!\n");
-			return -ENOMEM;
-		}
-		dsaf_dev->sc_base = devm_ioremap_resource(&pdev->dev, res);
-		if (!dsaf_dev->sc_base) {
-			dev_err(dsaf_dev->dev, "subctrl can not map!\n");
-			return -ENOMEM;
-		}
+	if (IS_ENABLED(CONFIG_OF) && np) {
+		syscon = syscon_node_to_regmap(
+				of_parse_phandle(np, "subctrl-syscon", 0));
+		if (IS_ERR_OR_NULL(syscon)) {
+			res = platform_get_resource(pdev, IORESOURCE_MEM,
+						    res_idx++);
+			if (!res) {
+				dev_err(dsaf_dev->dev, "subctrl info is needed!\n");
+				return -ENOMEM;
+			}
 
-		res = platform_get_resource(pdev, IORESOURCE_MEM, res_idx++);
-		if (!res) {
-			dev_err(dsaf_dev->dev, "serdes-ctrl info is needed!\n");
-			return -ENOMEM;
-		}
-		dsaf_dev->sds_base = devm_ioremap_resource(&pdev->dev, res);
-		if (!dsaf_dev->sds_base) {
-			dev_err(dsaf_dev->dev, "serdes-ctrl can not map!\n");
-			return -ENOMEM;
+			dsaf_dev->sc_base = devm_ioremap_resource(&pdev->dev,
+								  res);
+			if (!dsaf_dev->sc_base) {
+				dev_err(dsaf_dev->dev, "subctrl can not map!\n");
+				return -ENOMEM;
+			}
+
+			res = platform_get_resource(pdev, IORESOURCE_MEM,
+						    res_idx++);
+			if (!res) {
+				dev_err(dsaf_dev->dev, "serdes-ctrl info is needed!\n");
+				return -ENOMEM;
+			}
+
+			dsaf_dev->sds_base = devm_ioremap_resource(&pdev->dev,
+								   res);
+			if (!dsaf_dev->sds_base) {
+				dev_err(dsaf_dev->dev, "serdes-ctrl can not map!\n");
+				return -ENOMEM;
+			}
+		} else {
+			dsaf_dev->sub_ctrl = syscon;
 		}
-	} else {
-		dsaf_dev->sub_ctrl = syscon;
 	}
 
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ppe-base");
@@ -2681,6 +2710,7 @@ static struct platform_driver g_dsaf_driver = {
 	.driver = {
 		.name = DSAF_DRV_NAME,
 		.of_match_table = g_dsaf_match,
+		.acpi_match_table = hns_dsaf_acpi_match,
 	},
 };
 
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
index a843a86..ed96d7b 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
@@ -114,16 +114,18 @@ void hns_dsaf_rst(struct dsaf_device *dsaf_dev, u32 val)
 	u32 xbar_reg_addr;
 	u32 nt_reg_addr;
 
-	if (!val) {
-		xbar_reg_addr = DSAF_SUB_SC_XBAR_RESET_REQ_REG;
-		nt_reg_addr = DSAF_SUB_SC_NT_RESET_REQ_REG;
-	} else {
-		xbar_reg_addr = DSAF_SUB_SC_XBAR_RESET_DREQ_REG;
-		nt_reg_addr = DSAF_SUB_SC_NT_RESET_DREQ_REG;
-	}
+	if (IS_ENABLED(CONFIG_OF) && dsaf_dev->dev->of_node) {
+		if (!val) {
+			xbar_reg_addr = DSAF_SUB_SC_XBAR_RESET_REQ_REG;
+			nt_reg_addr = DSAF_SUB_SC_NT_RESET_REQ_REG;
+		} else {
+			xbar_reg_addr = DSAF_SUB_SC_XBAR_RESET_DREQ_REG;
+			nt_reg_addr = DSAF_SUB_SC_NT_RESET_DREQ_REG;
+		}
 
-	dsaf_write_sub(dsaf_dev, xbar_reg_addr, RESET_REQ_OR_DREQ);
-	dsaf_write_sub(dsaf_dev, nt_reg_addr, RESET_REQ_OR_DREQ);
+		dsaf_write_sub(dsaf_dev, xbar_reg_addr, RESET_REQ_OR_DREQ);
+		dsaf_write_sub(dsaf_dev, nt_reg_addr, RESET_REQ_OR_DREQ);
+	}
 }
 
 void hns_dsaf_xge_srst_by_port(struct dsaf_device *dsaf_dev, u32 port, u32 val)
@@ -134,15 +136,18 @@ void hns_dsaf_xge_srst_by_port(struct dsaf_device *dsaf_dev, u32 port, u32 val)
 	if (port >= DSAF_XGE_NUM)
 		return;
 
-	reg_val |= RESET_REQ_OR_DREQ;
-	reg_val |= 0x2082082 << dsaf_dev->mac_cb[port]->port_rst_off;
+	if (IS_ENABLED(CONFIG_OF) && dsaf_dev->dev->of_node) {
+		reg_val |= RESET_REQ_OR_DREQ;
 
-	if (val == 0)
-		reg_addr = DSAF_SUB_SC_XGE_RESET_REQ_REG;
-	else
-		reg_addr = DSAF_SUB_SC_XGE_RESET_DREQ_REG;
+		reg_val |= 0x2082082 << dsaf_dev->mac_cb[port]->port_rst_off;
 
-	dsaf_write_sub(dsaf_dev, reg_addr, reg_val);
+		if (val == 0)
+			reg_addr = DSAF_SUB_SC_XGE_RESET_REQ_REG;
+		else
+			reg_addr = DSAF_SUB_SC_XGE_RESET_DREQ_REG;
+
+		dsaf_write_sub(dsaf_dev, reg_addr, reg_val);
+	}
 }
 
 void hns_dsaf_xge_core_srst_by_port(struct dsaf_device *dsaf_dev,
@@ -153,16 +158,17 @@ void hns_dsaf_xge_core_srst_by_port(struct dsaf_device *dsaf_dev,
 
 	if (port >= DSAF_XGE_NUM)
 		return;
+	if (IS_ENABLED(CONFIG_OF) && dsaf_dev->dev->of_node) {
+		reg_val |= XGMAC_TRX_CORE_SRST_M
+			<< dsaf_dev->mac_cb[port]->port_rst_off;
 
-	reg_val |= XGMAC_TRX_CORE_SRST_M
-		<< dsaf_dev->mac_cb[port]->port_rst_off;
-
-	if (val == 0)
-		reg_addr = DSAF_SUB_SC_XGE_RESET_REQ_REG;
-	else
-		reg_addr = DSAF_SUB_SC_XGE_RESET_DREQ_REG;
+		if (val == 0)
+			reg_addr = DSAF_SUB_SC_XGE_RESET_REQ_REG;
+		else
+			reg_addr = DSAF_SUB_SC_XGE_RESET_DREQ_REG;
 
-	dsaf_write_sub(dsaf_dev, reg_addr, reg_val);
+		dsaf_write_sub(dsaf_dev, reg_addr, reg_val);
+	}
 }
 
 void hns_dsaf_ge_srst_by_port(struct dsaf_device *dsaf_dev, u32 port, u32 val)
@@ -174,44 +180,54 @@ void hns_dsaf_ge_srst_by_port(struct dsaf_device *dsaf_dev, u32 port, u32 val)
 	if (port >= DSAF_GE_NUM)
 		return;
 
-	if (!HNS_DSAF_IS_DEBUG(dsaf_dev)) {
-		reg_val_1  = 0x1 << port;
-		port_rst_off = dsaf_dev->mac_cb[port]->port_rst_off;
-		/* there is difference between V1 and V2 in register.*/
-		if (AE_IS_VER1(dsaf_dev->dsaf_ver))
-			reg_val_2  = 0x1041041 << port_rst_off;
-		else
-			reg_val_2  = 0x2082082 << port_rst_off;
-
-		if (val == 0) {
-			dsaf_write_sub(dsaf_dev, DSAF_SUB_SC_GE_RESET_REQ1_REG,
-				       reg_val_1);
-
-			dsaf_write_sub(dsaf_dev, DSAF_SUB_SC_GE_RESET_REQ0_REG,
-				       reg_val_2);
-		} else {
-			dsaf_write_sub(dsaf_dev, DSAF_SUB_SC_GE_RESET_DREQ0_REG,
-				       reg_val_2);
-
-			dsaf_write_sub(dsaf_dev, DSAF_SUB_SC_GE_RESET_DREQ1_REG,
-				       reg_val_1);
-		}
-	} else {
-		reg_val_1 = 0x15540 << dsaf_dev->reset_offset;
-		reg_val_2 = 0x100 << dsaf_dev->reset_offset;
-
-		if (val == 0) {
-			dsaf_write_sub(dsaf_dev, DSAF_SUB_SC_GE_RESET_REQ1_REG,
-				       reg_val_1);
-
-			dsaf_write_sub(dsaf_dev, DSAF_SUB_SC_PPE_RESET_REQ_REG,
-				       reg_val_2);
+	if (IS_ENABLED(CONFIG_OF) && dsaf_dev->dev->of_node) {
+		if (!HNS_DSAF_IS_DEBUG(dsaf_dev)) {
+			reg_val_1  = 0x1 << port;
+			port_rst_off = dsaf_dev->mac_cb[port]->port_rst_off;
+			/* there is difference between V1 and V2 in register.*/
+			if (AE_IS_VER1(dsaf_dev->dsaf_ver))
+				reg_val_2  = 0x1041041 << port_rst_off;
+			else
+				reg_val_2  = 0x2082082 << port_rst_off;
+
+			if (val == 0) {
+				dsaf_write_sub(dsaf_dev,
+					       DSAF_SUB_SC_GE_RESET_REQ1_REG,
+					       reg_val_1);
+
+				dsaf_write_sub(dsaf_dev,
+					       DSAF_SUB_SC_GE_RESET_REQ0_REG,
+					       reg_val_2);
+			} else {
+				dsaf_write_sub(dsaf_dev,
+					       DSAF_SUB_SC_GE_RESET_DREQ0_REG,
+					       reg_val_2);
+
+				dsaf_write_sub(dsaf_dev,
+					       DSAF_SUB_SC_GE_RESET_DREQ1_REG,
+					       reg_val_1);
+			}
 		} else {
-			dsaf_write_sub(dsaf_dev, DSAF_SUB_SC_GE_RESET_DREQ1_REG,
-				       reg_val_1);
-
-			dsaf_write_sub(dsaf_dev, DSAF_SUB_SC_PPE_RESET_DREQ_REG,
-				       reg_val_2);
+			reg_val_1 = 0x15540 << dsaf_dev->reset_offset;
+			reg_val_2 = 0x100 << dsaf_dev->reset_offset;
+
+			if (val == 0) {
+				dsaf_write_sub(dsaf_dev,
+					       DSAF_SUB_SC_GE_RESET_REQ1_REG,
+					       reg_val_1);
+
+				dsaf_write_sub(dsaf_dev,
+					       DSAF_SUB_SC_PPE_RESET_REQ_REG,
+					       reg_val_2);
+			} else {
+				dsaf_write_sub(dsaf_dev,
+					       DSAF_SUB_SC_GE_RESET_DREQ1_REG,
+					       reg_val_1);
+
+				dsaf_write_sub(dsaf_dev,
+					       DSAF_SUB_SC_PPE_RESET_DREQ_REG,
+					       reg_val_2);
+			}
 		}
 	}
 }
@@ -221,14 +237,18 @@ void hns_ppe_srst_by_port(struct dsaf_device *dsaf_dev, u32 port, u32 val)
 	u32 reg_val = 0;
 	u32 reg_addr;
 
-	reg_val |= RESET_REQ_OR_DREQ <<	dsaf_dev->mac_cb[port]->port_rst_off;
+	if (IS_ENABLED(CONFIG_OF) && dsaf_dev->dev->of_node) {
+		struct hns_mac_cb *mac_cb = dsaf_dev->mac_cb[port];
 
-	if (val == 0)
-		reg_addr = DSAF_SUB_SC_PPE_RESET_REQ_REG;
-	else
-		reg_addr = DSAF_SUB_SC_PPE_RESET_DREQ_REG;
+		reg_val |= RESET_REQ_OR_DREQ << mac_cb->port_rst_off;
 
-	dsaf_write_sub(dsaf_dev, reg_addr, reg_val);
+		if (val == 0)
+			reg_addr = DSAF_SUB_SC_PPE_RESET_REQ_REG;
+		else
+			reg_addr = DSAF_SUB_SC_PPE_RESET_DREQ_REG;
+
+		dsaf_write_sub(dsaf_dev, reg_addr, reg_val);
+	}
 }
 
 void hns_ppe_com_srst(struct ppe_common_cb *ppe_common, u32 val)
@@ -237,6 +257,9 @@ void hns_ppe_com_srst(struct ppe_common_cb *ppe_common, u32 val)
 	u32 reg_val;
 	u32 reg_addr;
 
+	if (!(IS_ENABLED(CONFIG_OF) && dsaf_dev->dev->of_node))
+		return;
+
 	if (!HNS_DSAF_IS_DEBUG(dsaf_dev)) {
 		reg_val = RESET_REQ_OR_DREQ;
 		if (val == 0)
@@ -267,29 +290,31 @@ phy_interface_t hns_mac_get_phy_if(struct hns_mac_cb *mac_cb)
 	u32 reg;
 	bool is_ver1 = AE_IS_VER1(mac_cb->dsaf_dev->dsaf_ver);
 	int mac_id = mac_cb->mac_id;
-	phy_interface_t phy_if;
+	phy_interface_t phy_if = PHY_INTERFACE_MODE_NA;
 
-	if (is_ver1) {
-		if (HNS_DSAF_IS_DEBUG(mac_cb->dsaf_dev))
-			return PHY_INTERFACE_MODE_SGMII;
+	if (IS_ENABLED(CONFIG_OF) && mac_cb->dev->of_node) {
+		if (is_ver1) {
+			if (HNS_DSAF_IS_DEBUG(mac_cb->dsaf_dev))
+				return PHY_INTERFACE_MODE_SGMII;
 
-		if (mac_id >= 0 && mac_id <= 3)
-			reg = HNS_MAC_HILINK4_REG;
-		else
-			reg = HNS_MAC_HILINK3_REG;
-	} else{
-		if (!HNS_DSAF_IS_DEBUG(mac_cb->dsaf_dev) && mac_id <= 3)
-			reg = HNS_MAC_HILINK4V2_REG;
+			if (mac_id >= 0 && mac_id <= 3)
+				reg = HNS_MAC_HILINK4_REG;
+			else
+				reg = HNS_MAC_HILINK3_REG;
+		} else {
+			if (!HNS_DSAF_IS_DEBUG(mac_cb->dsaf_dev) && mac_id <= 3)
+				reg = HNS_MAC_HILINK4V2_REG;
+			else
+				reg = HNS_MAC_HILINK3V2_REG;
+		}
+
+		mode = dsaf_read_sub(mac_cb->dsaf_dev, reg);
+		if (dsaf_get_bit(mode, mac_cb->port_mode_off))
+			phy_if = PHY_INTERFACE_MODE_XGMII;
 		else
-			reg = HNS_MAC_HILINK3V2_REG;
+			phy_if = PHY_INTERFACE_MODE_SGMII;
 	}
 
-	mode = dsaf_read_sub(mac_cb->dsaf_dev, reg);
-	if (dsaf_get_bit(mode, mac_cb->port_mode_off))
-		phy_if = PHY_INTERFACE_MODE_XGMII;
-	else
-		phy_if = PHY_INTERFACE_MODE_SGMII;
-
 	return phy_if;
 }
 
@@ -311,42 +336,50 @@ int hns_mac_get_sfp_prsnt(struct hns_mac_cb *mac_cb, int *sfp_prsnt)
  */
 int hns_mac_config_sds_loopback(struct hns_mac_cb *mac_cb, u8 en)
 {
+	struct dsaf_device *dsaf_dev = mac_cb->dsaf_dev;
+
 	/* port 0-3 hilink4 base is serdes_vaddr + 0x00280000
 	 * port 4-7 hilink3 base is serdes_vaddr + 0x00200000
 	 */
-	u8 *base_addr = (u8 *)mac_cb->serdes_vaddr +
-		       (mac_cb->mac_id <= 3 ? 0x00280000 : 0x00200000);
-	const u8 lane_id[] = {
-		0,	/* mac 0 -> lane 0 */
-		1,	/* mac 1 -> lane 1 */
-		2,	/* mac 2 -> lane 2 */
-		3,	/* mac 3 -> lane 3 */
-		2,	/* mac 4 -> lane 2 */
-		3,	/* mac 5 -> lane 3 */
-		0,	/* mac 6 -> lane 0 */
-		1	/* mac 7 -> lane 1 */
-	};
+
+	if (IS_ENABLED(CONFIG_OF) && dsaf_dev->dev->of_node) {
+		u8 *base_addr = (u8 *)mac_cb->serdes_vaddr +
+			(mac_cb->mac_id <= 3 ? 0x00280000 : 0x00200000);
+		const u8 lane_id[] = {
+			0,	/* mac 0 -> lane 0 */
+			1,	/* mac 1 -> lane 1 */
+			2,	/* mac 2 -> lane 2 */
+			3,	/* mac 3 -> lane 3 */
+			2,	/* mac 4 -> lane 2 */
+			3,	/* mac 5 -> lane 3 */
+			0,	/* mac 6 -> lane 0 */
+			1	/* mac 7 -> lane 1 */
+		};
 #define RX_CSR(lane, reg) ((0x4080 + (reg) * 0x0002 + (lane) * 0x0200) * 2)
-	u64 reg_offset = RX_CSR(lane_id[mac_cb->mac_id], 0);
+		u64 reg_offset = RX_CSR(lane_id[mac_cb->mac_id], 0);
 
-	int sfp_prsnt;
-	int ret = hns_mac_get_sfp_prsnt(mac_cb, &sfp_prsnt);
+		int sfp_prsnt;
+		int ret = hns_mac_get_sfp_prsnt(mac_cb, &sfp_prsnt);
 
-	if (!mac_cb->phy_dev) {
-		if (ret)
-			pr_info("please confirm sfp is present or not\n");
-		else
-			if (!sfp_prsnt)
-				pr_info("no sfp in this eth\n");
-	}
+		if (!mac_cb->phy_dev) {
+			if (ret)
+				pr_info("please confirm sfp is present or not\n");
+			else
+				if (!sfp_prsnt)
+					pr_info("no sfp in this eth\n");
+		}
 
-	if (mac_cb->serdes_ctrl) {
-		u32 origin = dsaf_read_syscon(mac_cb->serdes_ctrl, reg_offset);
+		if (mac_cb->serdes_ctrl) {
+			u32 origin = dsaf_read_syscon(mac_cb->serdes_ctrl,
+						      reg_offset);
 
-		dsaf_set_field(origin, 1ull << 10, 10, !!en);
-		dsaf_write_syscon(mac_cb->serdes_ctrl, reg_offset, origin);
-	} else {
-		dsaf_set_reg_field(base_addr, reg_offset, 1ull << 10, 10, !!en);
+			dsaf_set_field(origin, 1ull << 10, 10, !!en);
+			dsaf_write_syscon(mac_cb->serdes_ctrl, reg_offset,
+					  origin);
+		} else {
+			dsaf_set_reg_field(base_addr, reg_offset, 1ull << 10,
+					   10, !!en);
+		}
 	}
 
 	return 0;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [patch net-next 08/11] net: hns: register phy device in each mac initial sequence
  2016-05-13  8:19 [patch net-next 00/11] net: hns: add support of ACPI Yisen Zhuang
                   ` (6 preceding siblings ...)
  2016-05-13  8:19 ` [patch net-next 07/11] net: hns: dsaf adds support of acpi Yisen Zhuang
@ 2016-05-13  8:19 ` Yisen Zhuang
  2016-05-13  8:29   ` kbuild test robot
  2016-05-13  8:19 ` [patch net-next 09/11] ACPI: bus: add stub acpi_evaluate_dsm() to linux/acpi.h Yisen Zhuang
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 22+ messages in thread
From: Yisen Zhuang @ 2016-05-13  8:19 UTC (permalink / raw)
  To: davem, rjw, lenb
  Cc: arnd, andriy.shevchenko, andrew, geliangtang, ivecera,
	fengguang.wu, charles.chenxin, haifeng.wei, netdev, linux-kernel,
	linuxarm

From: Kejian Yan <yankejian@huawei.com>

In ACPI case, there is no interface to register phy device to mdio-bus.
Phy device has to be registered itself to mdio-bus, and then enet can
get the phy device's info so that it can config the phy-device to help
to trasmit and receive data.
HNS hardware topology is as below. The MDIO controller may control several
PHY-devices, and each PHY-device connects to a MAC device. PHY-devices
will register when each mac find PHY device in initial sequence.

                       cpu
                        |
                        |
     -------------------------------------------
    |                   |                       |
    |                   |                       |
    |                  dsaf                     |
   MDIO                 |                      MDIO
    |      ---------------------------          |
    |     |         |         |       |         |
    |     |         |         |       |         |
    |    MAC       MAC       MAC     MAC        |
    |     |         |         |       |         |
     ---- |-------- |-------- |       | --------
         ||        ||        ||       ||
         PHY       PHY       PHY     PHY

Signed-off-by: Kejian Yan <yankejian@huawei.com>
Signed-off-by: Yisen Zhuang <Yisen.Zhuang@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 119 +++++++++++++++++++++-
 1 file changed, 115 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
index 6e8f2b3..79d820b 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
@@ -7,6 +7,7 @@
  * (at your option) any later version.
  */
 
+#include <linux/acpi.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
@@ -638,6 +639,115 @@ free_mac_drv:
 	return ret;
 }
 
+static int
+hns_mac_phy_parse_addr(struct device *dev, struct fwnode_handle *fwnode)
+{
+	u32 addr;
+	int ret;
+
+	ret = fwnode_property_read_u32(fwnode, "phy-addr", &addr);
+	if (ret) {
+		dev_err(dev, "has invalid PHY address ret:%d\n", ret);
+		return ret;
+	}
+
+	if (addr >= PHY_MAX_ADDR) {
+		dev_err(dev, "PHY address %i is too large\n", addr);
+		return -EINVAL;
+	}
+
+	return addr;
+}
+
+static int hns_mac_phydev_match(struct device *dev, void *fwnode)
+{
+	return dev->fwnode == fwnode;
+}
+
+static struct
+platform_device *hns_mac_find_platform_device(struct fwnode_handle *fwnode)
+{
+	struct device *dev;
+
+	dev = bus_find_device(&platform_bus_type, NULL,
+			      fwnode, hns_mac_phydev_match);
+	return dev ? to_platform_device(dev) : NULL;
+}
+
+static int
+hns_mac_register_phydev(struct mii_bus *mdio, struct hns_mac_cb *mac_cb,
+			u32 addr)
+{
+	struct phy_device *phy;
+	const char *phy_type;
+	bool is_c45;
+	int rc;
+
+	rc = fwnode_property_read_string(mac_cb->fw_port,
+					 "phy-mode", &phy_type);
+	if (rc < 0)
+		return rc;
+
+	if (!strcmp(phy_type, phy_modes(PHY_INTERFACE_MODE_XGMII)))
+		is_c45 = 1;
+	else if (!strcmp(phy_type, phy_modes(PHY_INTERFACE_MODE_SGMII)))
+		is_c45 = 0;
+	else
+		return -ENODATA;
+
+	phy = get_phy_device(mdio, addr, is_c45);
+	if (!phy || IS_ERR(phy))
+		return -EIO;
+
+	if (mdio->irq)
+		phy->irq = mdio->irq[addr];
+
+	/* All data is now stored in the phy struct;
+	 * register it
+	 */
+	rc = phy_device_register(phy);
+	if (rc) {
+		phy_device_free(phy);
+		return -ENODEV;
+	}
+
+	mac_cb->phy_dev = phy;
+
+	dev_dbg(&mdio->dev, "registered phy at address %i\n", addr);
+
+	return 0;
+}
+
+static void hns_mac_register_phy(struct hns_mac_cb *mac_cb)
+{
+	struct acpi_reference_args args;
+	struct platform_device *pdev;
+	struct mii_bus *mii_bus;
+	int rc;
+	int addr;
+
+	/* Loop over the child nodes and register a phy_device for each one */
+	if (!to_acpi_device_node(mac_cb->fw_port))
+		return;
+
+	rc = acpi_node_get_property_reference(
+			mac_cb->fw_port, "mdio-node", 0, &args);
+	if (rc)
+		return;
+
+	addr = hns_mac_phy_parse_addr(mac_cb->dev, mac_cb->fw_port);
+	if (addr < 0)
+		return;
+
+	/* dev address in adev */
+	pdev = hns_mac_find_platform_device(acpi_fwnode_handle(args.adev));
+	mii_bus = platform_get_drvdata(pdev);
+	rc = hns_mac_register_phydev(mii_bus, mac_cb, addr);
+	if (!rc)
+		dev_dbg(mac_cb->dev, "mac%d register phy addr:%d\n",
+			mac_cb->mac_id, addr);
+}
+
 /**
  *hns_mac_get_info  - get mac information from device node
  *@mac_cb: mac device
@@ -677,11 +787,7 @@ static int  hns_mac_get_info(struct hns_mac_cb *mac_cb)
 				      mac_cb->mac_id);
 		mac_cb->phy_dev = of_phy_find_device(np);
 		if (mac_cb->phy_dev) {
-			/* refcount is held by of_phy_find_device()
-			 * if the phy_dev is found
-			 */
 			put_device(&mac_cb->phy_dev->mdio.dev);
-
 			dev_dbg(mac_cb->dev, "mac%d phy_node: %s\n",
 				mac_cb->mac_id, np->name);
 		}
@@ -743,6 +849,11 @@ static int  hns_mac_get_info(struct hns_mac_cb *mac_cb)
 				mac_cb->cpld_ctrl_reg = cpld_args.args[0];
 			}
 		}
+	} else if (ACPI_COMPANION(dev)) {
+		hns_mac_register_phy(mac_cb);
+	} else {
+		dev_err(mac_cb->dev, "mac%d cannot find phy node\n",
+			mac_cb->mac_id);
 	}
 
 	return 0;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [patch net-next 09/11] ACPI: bus: add stub acpi_evaluate_dsm() to linux/acpi.h
  2016-05-13  8:19 [patch net-next 00/11] net: hns: add support of ACPI Yisen Zhuang
                   ` (7 preceding siblings ...)
  2016-05-13  8:19 ` [patch net-next 08/11] net: hns: register phy device in each mac initial sequence Yisen Zhuang
@ 2016-05-13  8:19 ` Yisen Zhuang
  2016-05-13  8:19 ` [patch net-next 10/11] net: hns: implement the reset sequence by asl Yisen Zhuang
  2016-05-13  8:19 ` [patch net-next 11/11] net: hns: enet adds support of acpi Yisen Zhuang
  10 siblings, 0 replies; 22+ messages in thread
From: Yisen Zhuang @ 2016-05-13  8:19 UTC (permalink / raw)
  To: davem, rjw, lenb
  Cc: arnd, andriy.shevchenko, andrew, geliangtang, ivecera,
	fengguang.wu, charles.chenxin, haifeng.wei, netdev, linux-kernel,
	linuxarm

From: Kejian Yan <yankejian@huawei.com>

acpi_evaluate_dsm() will be used to handle the _DSM method in ACPI case.
It will be compiled in non-ACPI case, but the function is in acpi_bus.h
and acpi_bus.h can only be used in ACPI case, so this patch add the stub
function to linux/acpi.h to make compiled successfully in non-ACPI cases.

Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
Signed-off-by: Kejian Yan <yankejian@huawei.com>
Signed-off-by: Yisen Zhuang <Yisen.Zhuang@huawei.com>
---
 include/linux/acpi.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index e578bce..5c5566e 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -661,6 +661,14 @@ static inline bool acpi_driver_match_device(struct device *dev,
 	return false;
 }
 
+static inline union acpi_object *acpi_evaluate_dsm(acpi_handle handle,
+						   const u8 *uuid,
+						   int rev, int func,
+						   union acpi_object *argv4)
+{
+	return NULL;
+}
+
 static inline int acpi_device_uevent_modalias(struct device *dev,
 				struct kobj_uevent_env *env)
 {
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [patch net-next 10/11] net: hns: implement the reset sequence by asl
  2016-05-13  8:19 [patch net-next 00/11] net: hns: add support of ACPI Yisen Zhuang
                   ` (8 preceding siblings ...)
  2016-05-13  8:19 ` [patch net-next 09/11] ACPI: bus: add stub acpi_evaluate_dsm() to linux/acpi.h Yisen Zhuang
@ 2016-05-13  8:19 ` Yisen Zhuang
  2016-05-13  8:19 ` [patch net-next 11/11] net: hns: enet adds support of acpi Yisen Zhuang
  10 siblings, 0 replies; 22+ messages in thread
From: Yisen Zhuang @ 2016-05-13  8:19 UTC (permalink / raw)
  To: davem, rjw, lenb
  Cc: arnd, andriy.shevchenko, andrew, geliangtang, ivecera,
	fengguang.wu, charles.chenxin, haifeng.wei, netdev, linux-kernel,
	linuxarm

From: Kejian Yan <yankejian@huawei.com>

The reset sequence is implemented in BIOS, the kernel can call _DSM
method help to call the implementation in ACPI case. Here is a patch
to do that.

Signed-off-by: Kejian Yan <yankejian@huawei.com>
Signed-off-by: Yisen Zhuang <Yisen.Zhuang@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 113 +++++++++++++++++++++
 1 file changed, 113 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
index ed96d7b..9edf4f7 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
@@ -12,6 +12,27 @@
 #include "hns_dsaf_ppe.h"
 #include "hns_dsaf_reg.h"
 
+enum _dsm_op_index {
+	HNS_OP_RESET_FUNC               = 0x1,
+	HNS_OP_SERDES_LP_FUNC           = 0x2,
+	HNS_OP_LED_SET_FUNC             = 0x3,
+	HNS_OP_GET_PORT_TYPE_FUNC       = 0x4,
+	HNS_OP_GET_SFP_STAT_FUNC        = 0x5,
+};
+
+enum _dsm_rst_type {
+	HNS_DSAF_RESET_FUNC     = 0x1,
+	HNS_PPE_RESET_FUNC      = 0x2,
+	HNS_XGE_CORE_RESET_FUNC = 0x3,
+	HNS_XGE_RESET_FUNC      = 0x4,
+	HNS_GE_RESET_FUNC       = 0x5,
+};
+
+const u8 hns_dsaf_acpi_dsm_uuid[] = {
+	0x1A, 0xAA, 0x85, 0x1A, 0x93, 0xE2, 0x5E, 0x41,
+	0x8E, 0x28, 0x8D, 0x69, 0x0A, 0x0F, 0x82, 0x0A
+};
+
 static void dsaf_write_sub(struct dsaf_device *dsaf_dev, u32 reg, u32 val)
 {
 	if (dsaf_dev->sub_ctrl)
@@ -109,6 +130,34 @@ int cpld_set_led_id(struct hns_mac_cb *mac_cb,
 
 #define RESET_REQ_OR_DREQ 1
 
+static void hns_dsaf_acpi_srst_by_port(struct dsaf_device *dsaf_dev, u8 op_type,
+				       u32 port_type, u32 port, u32 val)
+{
+	union acpi_object *obj;
+	union acpi_object obj_args[3], argv4;
+
+	obj_args[0].integer.type = ACPI_TYPE_INTEGER;
+	obj_args[0].integer.value = port_type;
+	obj_args[1].integer.type = ACPI_TYPE_INTEGER;
+	obj_args[1].integer.value = port;
+	obj_args[2].integer.type = ACPI_TYPE_INTEGER;
+	obj_args[2].integer.value = val;
+
+	argv4.type = ACPI_TYPE_PACKAGE;
+	argv4.package.count = 3;
+	argv4.package.elements = obj_args;
+
+	obj = acpi_evaluate_dsm(ACPI_HANDLE(dsaf_dev->dev),
+				hns_dsaf_acpi_dsm_uuid, 0, op_type, &argv4);
+	if (!obj) {
+		dev_warn(dsaf_dev->dev, "reset port_type%d port%d fail!",
+			 port_type, port);
+		return;
+	}
+
+	ACPI_FREE(obj);
+}
+
 void hns_dsaf_rst(struct dsaf_device *dsaf_dev, u32 val)
 {
 	u32 xbar_reg_addr;
@@ -125,6 +174,10 @@ void hns_dsaf_rst(struct dsaf_device *dsaf_dev, u32 val)
 
 		dsaf_write_sub(dsaf_dev, xbar_reg_addr, RESET_REQ_OR_DREQ);
 		dsaf_write_sub(dsaf_dev, nt_reg_addr, RESET_REQ_OR_DREQ);
+	} else if (is_acpi_device_node(dsaf_dev->dev->fwnode)) {
+		hns_dsaf_acpi_srst_by_port(dsaf_dev, HNS_OP_RESET_FUNC,
+					   HNS_DSAF_RESET_FUNC,
+					   0, val);
 	}
 }
 
@@ -147,6 +200,9 @@ void hns_dsaf_xge_srst_by_port(struct dsaf_device *dsaf_dev, u32 port, u32 val)
 			reg_addr = DSAF_SUB_SC_XGE_RESET_DREQ_REG;
 
 		dsaf_write_sub(dsaf_dev, reg_addr, reg_val);
+	} else if (is_acpi_device_node(dsaf_dev->dev->fwnode)) {
+		hns_dsaf_acpi_srst_by_port(dsaf_dev, HNS_OP_RESET_FUNC,
+					   HNS_XGE_RESET_FUNC, port, val);
 	}
 }
 
@@ -168,6 +224,9 @@ void hns_dsaf_xge_core_srst_by_port(struct dsaf_device *dsaf_dev,
 			reg_addr = DSAF_SUB_SC_XGE_RESET_DREQ_REG;
 
 		dsaf_write_sub(dsaf_dev, reg_addr, reg_val);
+	} else if (is_acpi_device_node(dsaf_dev->dev->fwnode)) {
+		hns_dsaf_acpi_srst_by_port(dsaf_dev, HNS_OP_RESET_FUNC,
+					   HNS_XGE_CORE_RESET_FUNC, port, val);
 	}
 }
 
@@ -229,6 +288,9 @@ void hns_dsaf_ge_srst_by_port(struct dsaf_device *dsaf_dev, u32 port, u32 val)
 					       reg_val_2);
 			}
 		}
+	} else if (is_acpi_device_node(dsaf_dev->dev->fwnode)) {
+		hns_dsaf_acpi_srst_by_port(dsaf_dev, HNS_OP_RESET_FUNC,
+					   HNS_GE_RESET_FUNC, port, val);
 	}
 }
 
@@ -248,6 +310,9 @@ void hns_ppe_srst_by_port(struct dsaf_device *dsaf_dev, u32 port, u32 val)
 			reg_addr = DSAF_SUB_SC_PPE_RESET_DREQ_REG;
 
 		dsaf_write_sub(dsaf_dev, reg_addr, reg_val);
+	} else if (is_acpi_device_node(dsaf_dev->dev->fwnode)) {
+		hns_dsaf_acpi_srst_by_port(dsaf_dev, HNS_OP_RESET_FUNC,
+					   HNS_PPE_RESET_FUNC, port, val);
 	}
 }
 
@@ -313,6 +378,30 @@ phy_interface_t hns_mac_get_phy_if(struct hns_mac_cb *mac_cb)
 			phy_if = PHY_INTERFACE_MODE_XGMII;
 		else
 			phy_if = PHY_INTERFACE_MODE_SGMII;
+	} else if (is_acpi_device_node(mac_cb->dev->fwnode)) {
+		union acpi_object *obj;
+		union acpi_object obj_args, argv4;
+
+		obj_args.integer.type = ACPI_TYPE_INTEGER;
+		obj_args.integer.value = mac_cb->mac_id;
+
+		argv4.type = ACPI_TYPE_PACKAGE,
+		argv4.package.count = 1,
+		argv4.package.elements = &obj_args,
+
+		obj = acpi_evaluate_dsm(ACPI_HANDLE(mac_cb->dev),
+					hns_dsaf_acpi_dsm_uuid, 0,
+					HNS_OP_GET_PORT_TYPE_FUNC, &argv4);
+
+		if (!obj || obj->type != ACPI_TYPE_INTEGER)
+			return phy_if;
+
+		phy_if = obj->integer.value ?
+			PHY_INTERFACE_MODE_XGMII : PHY_INTERFACE_MODE_SGMII;
+
+		dev_dbg(mac_cb->dev, "mac_id=%d, phy_if=%d\n", mac_id, phy_if);
+
+		ACPI_FREE(obj);
 	}
 
 	return phy_if;
@@ -380,6 +469,30 @@ int hns_mac_config_sds_loopback(struct hns_mac_cb *mac_cb, u8 en)
 			dsaf_set_reg_field(base_addr, reg_offset, 1ull << 10,
 					   10, !!en);
 		}
+	} else if (is_acpi_device_node(dsaf_dev->dev->fwnode)) {
+		union acpi_object *obj;
+		union acpi_object obj_args[3], argv4;
+
+		obj_args[0].integer.type = ACPI_TYPE_INTEGER;
+		obj_args[0].integer.value = mac_cb->mac_id;
+		obj_args[1].integer.type = ACPI_TYPE_INTEGER;
+		obj_args[1].integer.value = !!en;
+
+		argv4.type = ACPI_TYPE_PACKAGE;
+		argv4.package.count = 2;
+		argv4.package.elements = obj_args;
+
+		obj = acpi_evaluate_dsm(ACPI_HANDLE(dsaf_dev->dev),
+					hns_dsaf_acpi_dsm_uuid, 0,
+					HNS_OP_SERDES_LP_FUNC, &argv4);
+		if (!obj) {
+			dev_warn(dsaf_dev->dev, "set port%d serdes lp fail!",
+				 mac_cb->mac_id);
+
+			return -ENOTSUPP;
+		}
+
+		ACPI_FREE(obj);
 	}
 
 	return 0;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [patch net-next 11/11] net: hns: enet adds support of acpi
  2016-05-13  8:19 [patch net-next 00/11] net: hns: add support of ACPI Yisen Zhuang
                   ` (9 preceding siblings ...)
  2016-05-13  8:19 ` [patch net-next 10/11] net: hns: implement the reset sequence by asl Yisen Zhuang
@ 2016-05-13  8:19 ` Yisen Zhuang
  10 siblings, 0 replies; 22+ messages in thread
From: Yisen Zhuang @ 2016-05-13  8:19 UTC (permalink / raw)
  To: davem, rjw, lenb
  Cc: arnd, andriy.shevchenko, andrew, geliangtang, ivecera,
	fengguang.wu, charles.chenxin, haifeng.wei, netdev, linux-kernel,
	linuxarm

From: Kejian Yan <yankejian@huawei.com>

Enet needs to get configration parameter by acpi. This patch
adds support of ACPI for enet. The configuration parameter will
be configed in BIOS.

Signed-off-by: Kejian Yan <yankejian@huawei.com>
Signed-off-by: Yisen Zhuang <Yisen.Zhuang@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_enet.c | 54 +++++++++++++++++++++------
 1 file changed, 42 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index 34ebe7d..ade14d9 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -132,6 +132,13 @@ static void fill_v2_desc(struct hnae_ring *ring, void *priv,
 	ring_ptr_move_fw(ring, next_to_use);
 }
 
+static const struct acpi_device_id hns_enet_acpi_match[] = {
+	{ "HISI00C1", 0 },
+	{ "HISI00C2", 0 },
+	{ },
+};
+MODULE_DEVICE_TABLE(acpi, hns_enet_acpi_match);
+
 static void fill_desc(struct hnae_ring *ring, void *priv,
 		      int size, dma_addr_t dma, int frag_end,
 		      int buf_num, enum hns_desc_type type, int mtu)
@@ -1903,7 +1910,6 @@ 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 *ae_node;
 	u32 port_id;
 	int ret;
 
@@ -1917,19 +1923,42 @@ static int hns_nic_dev_probe(struct platform_device *pdev)
 	priv->dev = dev;
 	priv->netdev = ndev;
 
-	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;
+	if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
+		struct device_node *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;
-	}
-	priv->fwnode = &ae_node->fwnode;
+		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;
+
+		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;
+		}
+			priv->fwnode = &ae_node->fwnode;
+	} else if (ACPI_COMPANION(&pdev->dev)) {
+		struct acpi_device *adev = to_acpi_device_node(dev->fwnode);
+		struct acpi_reference_args args;
 
+		if (!acpi_match_device_ids(adev, &hns_enet_acpi_match[1]))
+			priv->enet_ver = AE_VERSION_2;
+		else
+			priv->enet_ver = AE_VERSION_1;
+
+		ret = acpi_node_get_property_reference(dev->fwnode,
+						       "ae-handle", 0, &args);
+		if (ret) {
+			dev_err(dev, "not find ae-handle\n");
+			goto out_read_prop_fail;
+		}
+		priv->fwnode = acpi_fwnode_handle(args.adev);
+	} else {
+		dev_err(dev, "cannot read cfg data from OF or acpi\n");
+		return -ENXIO;
+	}
 	ret = device_property_read_u32(dev, "port-idx-in-ae", &port_id);
 	if (ret) {
 		/* only for old code compatible */
@@ -2046,6 +2075,7 @@ static struct platform_driver hns_nic_dev_driver = {
 	.driver = {
 		.name = "hns-nic",
 		.of_match_table = hns_enet_of_match,
+		.acpi_match_table = ACPI_PTR(hns_enet_acpi_match),
 	},
 	.probe = hns_nic_dev_probe,
 	.remove = hns_nic_dev_remove,
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [patch net-next 08/11] net: hns: register phy device in each mac initial sequence
  2016-05-13  8:19 ` [patch net-next 08/11] net: hns: register phy device in each mac initial sequence Yisen Zhuang
@ 2016-05-13  8:29   ` kbuild test robot
  0 siblings, 0 replies; 22+ messages in thread
From: kbuild test robot @ 2016-05-13  8:29 UTC (permalink / raw)
  To: Yisen Zhuang
  Cc: kbuild-all, davem, rjw, lenb, arnd, andriy.shevchenko, andrew,
	geliangtang, ivecera, fengguang.wu, charles.chenxin, haifeng.wei,
	netdev, linux-kernel, linuxarm

[-- Attachment #1: Type: text/plain, Size: 2239 bytes --]

Hi,

[auto build test ERROR on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Yisen-Zhuang/net-hns-add-support-of-ACPI/20160513-161402
config: ia64-allyesconfig (attached as .config)
compiler: ia64-linux-gcc (GCC) 4.9.0
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=ia64 

Note: the linux-review/Yisen-Zhuang/net-hns-add-support-of-ACPI/20160513-161402 HEAD b35bbec71070d6f7073f4bce154081fac5f156ec builds fine.
      It only hurts bisectibility.

All errors (new ones prefixed by >>):

   In file included from drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c:10:0:
   drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c: In function 'hns_mac_get_info':
>> drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c:852:28: error: 'dev' undeclared (first use in this function)
     } else if (ACPI_COMPANION(dev)) {
                               ^
   include/linux/acpi.h:54:51: note: in definition of macro 'ACPI_COMPANION'
    #define ACPI_COMPANION(dev)  to_acpi_device_node((dev)->fwnode)
                                                      ^
   drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c:852:28: note: each undeclared identifier is reported only once for each function it appears in
     } else if (ACPI_COMPANION(dev)) {
                               ^
   include/linux/acpi.h:54:51: note: in definition of macro 'ACPI_COMPANION'
    #define ACPI_COMPANION(dev)  to_acpi_device_node((dev)->fwnode)
                                                      ^

vim +/dev +852 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c

   846					mac_cb->cpld_ctrl = NULL;
   847				} else {
   848					mac_cb->cpld_ctrl = syscon;
   849					mac_cb->cpld_ctrl_reg = cpld_args.args[0];
   850				}
   851			}
 > 852		} else if (ACPI_COMPANION(dev)) {
   853			hns_mac_register_phy(mac_cb);
   854		} else {
   855			dev_err(mac_cb->dev, "mac%d cannot find phy node\n",

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 45888 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [patch net-next 01/11] net: hisilicon: add support of acpi for hns-mdio
  2016-05-13  8:19 ` [patch net-next 01/11] net: hisilicon: add support of acpi for hns-mdio Yisen Zhuang
@ 2016-05-13 12:59   ` Andy Shevchenko
  2016-05-16  7:10     ` Yankejian (Hackim Yim)
  0 siblings, 1 reply; 22+ messages in thread
From: Andy Shevchenko @ 2016-05-13 12:59 UTC (permalink / raw)
  To: Yisen Zhuang, davem, rjw, lenb
  Cc: arnd, andrew, geliangtang, ivecera, fengguang.wu,
	charles.chenxin, haifeng.wei, netdev, linux-kernel, linuxarm

On Fri, 2016-05-13 at 16:19 +0800, Yisen Zhuang wrote:
> From: Kejian Yan <yankejian@huawei.com>
> 
> hns-mdio needs to register itself to mii-bus. The info of the device
> can
> be read by both OF and ACPI.
> HNS tries to call Linux PHY driver to help access PHY-devices, the HNS
> hardware topology is as below. The MDIO controller may control several
> PHY-devices, and each PHY-device connects to a MAC device. The MDIO
> will
> be registered to mdiobus, then PHY-devices will register when each mac
> find PHY device.
>                        cpu
>                         |
>                         |
>      -------------------------------------------
>     |                   |                       |
>     |                   |                       |
>     |                  dsaf                     |
>    MDIO                 |                      MDIO
>     |      ---------------------------          |
>     |     |         |         |       |         |
>     |     |         |         |       |         |
>     |    MAC       MAC       MAC     MAC        |
>     |     |         |         |       |         |
>      ---- |-------- |-------- |       | --------
>          ||        ||        ||       ||
>          PHY       PHY       PHY     PHY
> 
> And the driver can handle reset sequence by _DSD method in DSDT in
> ACPI case.
> 
> Signed-off-by: Kejian Yan <yankejian@huawei.com>
> Signed-off-by: Yisen Zhuang <Yisen.Zhuang@huawei.com>
> ---
>  drivers/net/ethernet/hisilicon/hns_mdio.c | 145 ++++++++++++++++++---
> ---------
>  1 file changed, 90 insertions(+), 55 deletions(-)
> 
> diff --git a/drivers/net/ethernet/hisilicon/hns_mdio.c
> b/drivers/net/ethernet/hisilicon/hns_mdio.c
> index 765ddb3..4b779df 100644
> --- a/drivers/net/ethernet/hisilicon/hns_mdio.c
> +++ b/drivers/net/ethernet/hisilicon/hns_mdio.c
> @@ -7,6 +7,7 @@
>   * (at your option) any later version.
>   */
>  
> +#include <linux/acpi.h>
>  #include <linux/errno.h>
>  #include <linux/etherdevice.h>
>  #include <linux/init.h>
> @@ -354,64 +355,72 @@ static int hns_mdio_reset(struct mii_bus *bus)
>  	struct hns_mdio_device *mdio_dev = (struct hns_mdio_device
> *)bus->priv;
>  	int ret;
>  
> -	if (!mdio_dev->subctrl_vbase) {
> -		dev_err(&bus->dev, "mdio sys ctl reg has not
> maped\n");
> -		return -ENODEV;
> -	}
> -
> -	/*1. reset req, and read reset st check*/
> -	ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_RESET_REQ, 0x1,
> -				    MDIO_SC_RESET_ST, 0x1,
> -				    MDIO_CHECK_SET_ST);
> -	if (ret) {
> -		dev_err(&bus->dev, "MDIO reset fail\n");
> -		return ret;
> -	}
> +	if (IS_ENABLED(CONFIG_OF) && bus->parent->of_node) {

Can you keep indentation the same?

Also I suggest to use struct fwnode_handle, and this will be something
like

if (is_of_node(...))

> +		if (!mdio_dev->subctrl_vbase) {
> +			dev_err(&bus->dev, "mdio sys ctl reg has not
> maped\n");
> +			return -ENODEV;
> +		}
>  
> -	/*2. dis clk, and read clk st check*/
> -	ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_CLK_DIS,
> -				    0x1, MDIO_SC_CLK_ST, 0x1,
> -				    MDIO_CHECK_CLR_ST);
> -	if (ret) {
> -		dev_err(&bus->dev, "MDIO dis clk fail\n");
> -		return ret;
> -	}
> +		/*1. reset req, and read reset st check*/
> +		ret = mdio_sc_cfg_reg_write(mdio_dev,
> MDIO_SC_RESET_REQ, 0x1,
> +					    MDIO_SC_RESET_ST, 0x1,
> +					    MDIO_CHECK_SET_ST);
> +		if (ret) {
> +			dev_err(&bus->dev, "MDIO reset fail\n");
> +			return ret;
> +		}
>  
> -	/*3. reset dreq, and read reset st check*/
> -	ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_RESET_DREQ,
> 0x1,
> -				    MDIO_SC_RESET_ST, 0x1,
> -				    MDIO_CHECK_CLR_ST);
> -	if (ret) {
> -		dev_err(&bus->dev, "MDIO dis clk fail\n");
> -		return ret;
> -	}
> +		/*2. dis clk, and read clk st check*/
> +		ret = mdio_sc_cfg_reg_write(mdio_dev,
> MDIO_SC_CLK_DIS,
> +					    0x1, MDIO_SC_CLK_ST, 0x1,
> +					    MDIO_CHECK_CLR_ST);
> +		if (ret) {
> +			dev_err(&bus->dev, "MDIO dis clk fail\n");
> +			return ret;
> +		}
>  
> -	/*4. en clk, and read clk st check*/
> -	ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_CLK_EN,
> -				    0x1, MDIO_SC_CLK_ST, 0x1,
> -				    MDIO_CHECK_SET_ST);
> -	if (ret)
> -		dev_err(&bus->dev, "MDIO en clk fail\n");
> +		/*3. reset dreq, and read reset st check*/
> +		ret = mdio_sc_cfg_reg_write(mdio_dev,
> MDIO_SC_RESET_DREQ, 0x1,
> +					    MDIO_SC_RESET_ST, 0x1,
> +					    MDIO_CHECK_CLR_ST);
> +		if (ret) {
> +			dev_err(&bus->dev, "MDIO dis clk fail\n");
> +			return ret;
> +		}
>  
> +		/*4. en clk, and read clk st check*/
> +		ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_CLK_EN,
> +					    0x1, MDIO_SC_CLK_ST, 0x1,
> +					    MDIO_CHECK_SET_ST);
> +		if (ret)
> +			dev_err(&bus->dev, "MDIO en clk fail\n");
> +	} else if (ACPI_COMPANION(bus->parent)) {
> +		acpi_status s;
> +
> +		s = acpi_evaluate_object(ACPI_HANDLE(bus->parent),
> +					 "_RST", NULL, NULL);
> +		if (ACPI_FAILURE(s)) {
> +			dev_err(&bus->dev, "Reset failed,
> return:%#x\n", s);
> +			ret = -EBUSY;
> +		} else {
> +			ret = 0;
> +		}
> +	} else {
> +		dev_err(&bus->dev, "cannot get cfd data from of or
> acpi\n");

cannot -> Can not

WTF cfd?

of or acpi -> DT or ACPI

> +		ret = -ENXIO;
> +	}
>  	return ret;
>  }
>  
>  /**
>   * 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,7 +431,6 @@ 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;
> @@ -432,7 +440,7 @@ static int hns_mdio_probe(struct platform_device
> *pdev)
>  		dev_err(NULL, "pdev is NULL!\r\n");
>  		return -ENODEV;
>  	}
> -	np = pdev->dev.of_node;
> +
>  	mdio_dev = devm_kzalloc(&pdev->dev, sizeof(*mdio_dev),
> GFP_KERNEL);
>  	if (!mdio_dev)
>  		return -ENOMEM;
> @@ -448,7 +456,6 @@ 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);
>  
>  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>  	mdio_dev->vbase = devm_ioremap_resource(&pdev->dev, res);
> @@ -457,16 +464,37 @@ 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(&pdev->dev, "no syscon hisilicon,peri-c-
> subctrl\n");
> -		mdio_dev->subctrl_vbase = NULL;
> +	hns_mdio_bus_name(new_bus->id, res->start);
> +	if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {

is_of_node()

> +		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(&pdev->dev, "no syscon
> hisilicon,peri-c-subctrl\n");
> +			mdio_dev->subctrl_vbase = NULL;
> +		}
>  	}
>  	new_bus->parent = &pdev->dev;
>  	platform_set_drvdata(pdev, new_bus);
>  
> -	ret = of_mdiobus_register(new_bus, np);
> +	if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {

Ditto

> +		ret = of_mdiobus_register(new_bus, pdev-
> >dev.of_node);
> +	} else if (ACPI_COMPANION(&pdev->dev)) {

is_acpi_node()

> +		/* Clear all the IRQ properties */
> +		memset(new_bus->irq, PHY_POLL, 4 * PHY_MAX_ADDR);
> +
> +		/* Mask out all PHYs from auto probing. */
> +		new_bus->phy_mask = ~0;
> +
> +		/* Register the MDIO bus */
> +		ret = mdiobus_register(new_bus);
> +		if (ret)
> +			return ret;
> +	} else {
> +		dev_err(&pdev->dev, "cannot get cfd data from of or
> acpi\n");

Same as for previous message.

> +		return -ENXIO;
> +	}
> +
>  	if (ret) {
>  		dev_err(&pdev->dev, "Cannot register as MDIO
> bus!\n");
>  		platform_set_drvdata(pdev, NULL);
> @@ -499,12 +527,19 @@ static const struct of_device_id
> hns_mdio_match[] = {
>  	{}
>  };
>  
> +static const struct acpi_device_id hns_mdio_acpi_match[] = {
> +	{ "HISI0141", 0 },
> +	{ },
> +};
> +MODULE_DEVICE_TABLE(acpi, hns_mdio_acpi_match);
> +
>  static struct platform_driver hns_mdio_driver = {
>  	.probe = hns_mdio_probe,
>  	.remove = hns_mdio_remove,
>  	.driver = {
>  		   .name = MDIO_DRV_NAME,
>  		   .of_match_table = hns_mdio_match,
> +		   .acpi_match_table = ACPI_PTR(hns_mdio_acpi_match),
>  		   },
>  };
>  


So, I suggest to split this to two logical changes:

1. Move to use fwnode_handle
2. Add ACPI bits

-- 
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [patch net-next 04/11] net: hns: enet specify a reference to dsaf by fwnode_handle
  2016-05-13  8:19 ` [patch net-next 04/11] net: hns: enet specify a reference to dsaf by fwnode_handle Yisen Zhuang
@ 2016-05-13 13:01   ` Andy Shevchenko
  0 siblings, 0 replies; 22+ messages in thread
From: Andy Shevchenko @ 2016-05-13 13:01 UTC (permalink / raw)
  To: Yisen Zhuang, davem, rjw, lenb
  Cc: arnd, andrew, geliangtang, ivecera, fengguang.wu,
	charles.chenxin, haifeng.wei, netdev, linux-kernel, linuxarm

On Fri, 2016-05-13 at 16:19 +0800, Yisen Zhuang wrote:
> From: Kejian Yan <yankejian@huawei.com>
> 
> 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@huawei.com>
> Signed-off-by: Yisen Zhuang <Yisen.Zhuang@huawei.com>
> ---
>  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@linux.intel.com>
Intel Finland Oy

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [patch net-next 05/11] net: hns: add uniform interface for phy connection
  2016-05-13  8:19 ` [patch net-next 05/11] net: hns: add uniform interface for phy connection Yisen Zhuang
@ 2016-05-13 13:07   ` Andy Shevchenko
  2016-05-16  0:40     ` Yankejian (Hackim Yim)
  0 siblings, 1 reply; 22+ messages in thread
From: Andy Shevchenko @ 2016-05-13 13:07 UTC (permalink / raw)
  To: Yisen Zhuang, davem, rjw, lenb
  Cc: arnd, andrew, geliangtang, ivecera, fengguang.wu,
	charles.chenxin, haifeng.wei, netdev, linux-kernel, linuxarm

On Fri, 2016-05-13 at 16:19 +0800, Yisen Zhuang wrote:
> From: Kejian Yan <yankejian@huawei.com>
> 
> 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@linux.intel.com>
Intel Finland Oy

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [patch net-next 07/11] net: hns: dsaf adds support of acpi
  2016-05-13  8:19 ` [patch net-next 07/11] net: hns: dsaf adds support of acpi Yisen Zhuang
@ 2016-05-13 13:12   ` Andy Shevchenko
  2016-05-16  2:06     ` Yankejian (Hackim Yim)
  0 siblings, 1 reply; 22+ messages in thread
From: Andy Shevchenko @ 2016-05-13 13:12 UTC (permalink / raw)
  To: Yisen Zhuang, davem, rjw, lenb
  Cc: arnd, andrew, geliangtang, ivecera, fengguang.wu,
	charles.chenxin, haifeng.wei, netdev, linux-kernel, linuxarm

On Fri, 2016-05-13 at 16:19 +0800, Yisen Zhuang wrote:
> From: Kejian Yan <yankejian@huawei.com>
> 
> Dsaf needs to get configuration parameter by ACPI, so this patch add
> support of ACPI.
> 

Looks like at some point better to split driver to core part, and PCI
and ACPI/DT/platform code.

Too many changes where IS_ENABLED() involved shows as I can imagine bad
architecture / split of the driver.

-- 
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [patch net-next 06/11] ACPI: bus: move acpi_match_device_ids() to linux/acpi.h
  2016-05-13  8:19 ` [patch net-next 06/11] ACPI: bus: move acpi_match_device_ids() to linux/acpi.h Yisen Zhuang
@ 2016-05-13 13:15   ` Andy Shevchenko
  2016-05-16  1:57     ` Yankejian (Hackim Yim)
  0 siblings, 1 reply; 22+ messages in thread
From: Andy Shevchenko @ 2016-05-13 13:15 UTC (permalink / raw)
  To: Yisen Zhuang, davem, rjw, lenb
  Cc: arnd, andrew, geliangtang, ivecera, fengguang.wu,
	charles.chenxin, haifeng.wei, netdev, linux-kernel, linuxarm

On Fri, 2016-05-13 at 16:19 +0800, Yisen Zhuang wrote:
> From: Hanjun Guo <hanjun.guo@linaro.org>
> 
> acpi_match_device_ids() will be used for drivers to match
> different hardware versions, it will be compiled in non-ACPI
> case, but acpi_match_device_ids() in acpi_bus.h and it can
> only be used in ACPI case, so move it to linux/acpi.h and
> introduce a stub function for it.

I somehow doubt this is right move.

Like I said in the previous comment the architectural split might make
this a bit better.

You might use 

#ifdef IS_ENABLED(CONFIG_ACPI)
#else
#endif

only once to some big part of code. If kernel is build without ACPI
support you even will not have this in your driver at all.

-- 
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [patch net-next 05/11] net: hns: add uniform interface for phy connection
  2016-05-13 13:07   ` Andy Shevchenko
@ 2016-05-16  0:40     ` Yankejian (Hackim Yim)
  0 siblings, 0 replies; 22+ messages in thread
From: Yankejian (Hackim Yim) @ 2016-05-16  0:40 UTC (permalink / raw)
  To: Andy Shevchenko, Yisen Zhuang, davem, rjw, lenb
  Cc: arnd, andrew, geliangtang, ivecera, fengguang.wu,
	charles.chenxin, haifeng.wei, netdev, linux-kernel, linuxarm



On 2016/5/13 21:07, Andy Shevchenko wrote:
> On Fri, 2016-05-13 at 16:19 +0800, Yisen Zhuang wrote:
>> From: Kejian Yan <yankejian@huawei.com>
>>
>> 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.

Hi Andy,
Thanks for you suggestions, it will be fixed in next submit

MBR,
Kejian

>>  /**
>>   *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);
>

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [patch net-next 06/11] ACPI: bus: move acpi_match_device_ids() to linux/acpi.h
  2016-05-13 13:15   ` Andy Shevchenko
@ 2016-05-16  1:57     ` Yankejian (Hackim Yim)
  0 siblings, 0 replies; 22+ messages in thread
From: Yankejian (Hackim Yim) @ 2016-05-16  1:57 UTC (permalink / raw)
  To: Andy Shevchenko, Yisen Zhuang, davem, rjw, lenb
  Cc: arnd, andrew, geliangtang, ivecera, fengguang.wu,
	charles.chenxin, haifeng.wei, netdev, linux-kernel, linuxarm



On 2016/5/13 21:15, Andy Shevchenko wrote:
> On Fri, 2016-05-13 at 16:19 +0800, Yisen Zhuang wrote:
>> From: Hanjun Guo <hanjun.guo@linaro.org>
>>
>> acpi_match_device_ids() will be used for drivers to match
>> different hardware versions, it will be compiled in non-ACPI
>> case, but acpi_match_device_ids() in acpi_bus.h and it can
>> only be used in ACPI case, so move it to linux/acpi.h and
>> introduce a stub function for it.
> I somehow doubt this is right move.
>
> Like I said in the previous comment the architectural split might make
> this a bit better.
>
> You might use 
>
> #ifdef IS_ENABLED(CONFIG_ACPI)
> #else
> #endif
>
> only once to some big part of code. If kernel is build without ACPI
> support you even will not have this in your driver at all.

Hi Andy,

Thanks for your suggestions. It will add stub function instead in next submit.


> -- 
> Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Intel Finland Oy
>
>
> .
>

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [patch net-next 07/11] net: hns: dsaf adds support of acpi
  2016-05-13 13:12   ` Andy Shevchenko
@ 2016-05-16  2:06     ` Yankejian (Hackim Yim)
  0 siblings, 0 replies; 22+ messages in thread
From: Yankejian (Hackim Yim) @ 2016-05-16  2:06 UTC (permalink / raw)
  To: Andy Shevchenko, Yisen Zhuang, davem, rjw, lenb
  Cc: arnd, andrew, geliangtang, ivecera, fengguang.wu,
	charles.chenxin, haifeng.wei, netdev, linux-kernel, linuxarm



On 2016/5/13 21:12, Andy Shevchenko wrote:
> On Fri, 2016-05-13 at 16:19 +0800, Yisen Zhuang wrote:
>> From: Kejian Yan <yankejian@huawei.com>
>>
>> Dsaf needs to get configuration parameter by ACPI, so this patch add
>> support of ACPI.
>>
> Looks like at some point better to split driver to core part, and PCI
> and ACPI/DT/platform code.
>
> Too many changes where IS_ENABLED() involved shows as I can imagine bad
> architecture / split of the driver.

Hi Andy,
Actully, we use the unified function asap. The routine in DT/ACPI maybe difference. Some routine
will be treated in BIOS in ACPI case, but it will be treated in OS in DT case, so we need to distinguish
it.
And we will try to reduce the use of IS_ENABLED().

Thanks very much for your suggestions, Andy

Kejian

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [patch net-next 01/11] net: hisilicon: add support of acpi for hns-mdio
  2016-05-13 12:59   ` Andy Shevchenko
@ 2016-05-16  7:10     ` Yankejian (Hackim Yim)
  0 siblings, 0 replies; 22+ messages in thread
From: Yankejian (Hackim Yim) @ 2016-05-16  7:10 UTC (permalink / raw)
  To: Andy Shevchenko, Yisen Zhuang, davem, rjw, lenb
  Cc: arnd, andrew, geliangtang, ivecera, fengguang.wu,
	charles.chenxin, haifeng.wei, netdev, linux-kernel, linuxarm



On 2016/5/13 20:59, Andy Shevchenko wrote:
> On Fri, 2016-05-13 at 16:19 +0800, Yisen Zhuang wrote:
>> From: Kejian Yan <yankejian@huawei.com>
>>
>> hns-mdio needs to register itself to mii-bus. The info of the device
>> can
>> be read by both OF and ACPI.
>> HNS tries to call Linux PHY driver to help access PHY-devices, the HNS
>> hardware topology is as below. The MDIO controller may control several
>> PHY-devices, and each PHY-device connects to a MAC device. The MDIO
>> will
>> be registered to mdiobus, then PHY-devices will register when each mac
>> find PHY device.
>>                        cpu
>>                         |
>>                         |
>>      -------------------------------------------
>>     |                   |                       |
>>     |                   |                       |
>>     |                  dsaf                     |
>>    MDIO                 |                      MDIO
>>     |      ---------------------------          |
>>     |     |         |         |       |         |
>>     |     |         |         |       |         |
>>     |    MAC       MAC       MAC     MAC        |
>>     |     |         |         |       |         |
>>      ---- |-------- |-------- |       | --------
>>          ||        ||        ||       ||
>>          PHY       PHY       PHY     PHY
>>
>> And the driver can handle reset sequence by _DSD method in DSDT in
>> ACPI case.
>>
>> Signed-off-by: Kejian Yan <yankejian@huawei.com>
>> Signed-off-by: Yisen Zhuang <Yisen.Zhuang@huawei.com>
>> ---
>>  drivers/net/ethernet/hisilicon/hns_mdio.c | 145 ++++++++++++++++++---
>> ---------
>>  1 file changed, 90 insertions(+), 55 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/hisilicon/hns_mdio.c
>> b/drivers/net/ethernet/hisilicon/hns_mdio.c
>> index 765ddb3..4b779df 100644
>> --- a/drivers/net/ethernet/hisilicon/hns_mdio.c
>> +++ b/drivers/net/ethernet/hisilicon/hns_mdio.c
>> @@ -7,6 +7,7 @@
>>   * (at your option) any later version.
>>   */
>>  
>> +#include <linux/acpi.h>
>>  #include <linux/errno.h>
>>  #include <linux/etherdevice.h>
>>  #include <linux/init.h>
>> @@ -354,64 +355,72 @@ static int hns_mdio_reset(struct mii_bus *bus)
>>  	struct hns_mdio_device *mdio_dev = (struct hns_mdio_device
>> *)bus->priv;
>>  	int ret;
>>  
>> -	if (!mdio_dev->subctrl_vbase) {
>> -		dev_err(&bus->dev, "mdio sys ctl reg has not
>> maped\n");
>> -		return -ENODEV;
>> -	}
>> -
>> -	/*1. reset req, and read reset st check*/
>> -	ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_RESET_REQ, 0x1,
>> -				    MDIO_SC_RESET_ST, 0x1,
>> -				    MDIO_CHECK_SET_ST);
>> -	if (ret) {
>> -		dev_err(&bus->dev, "MDIO reset fail\n");
>> -		return ret;
>> -	}
>> +	if (IS_ENABLED(CONFIG_OF) && bus->parent->of_node) {
> Can you keep indentation the same?
>
> Also I suggest to use struct fwnode_handle, and this will be something
> like
>
> if (is_of_node(...))
ok, thanks Andy. i will fix it in next submit

>
>> +		if (!mdio_dev->subctrl_vbase) {
>> +			dev_err(&bus->dev, "mdio sys ctl reg has not
>> maped\n");
>> +			return -ENODEV;
>> +		}
>>  
>> -	/*2. dis clk, and read clk st check*/
>> -	ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_CLK_DIS,
>> -				    0x1, MDIO_SC_CLK_ST, 0x1,
>> -				    MDIO_CHECK_CLR_ST);
>> -	if (ret) {
>> -		dev_err(&bus->dev, "MDIO dis clk fail\n");
>> -		return ret;
>> -	}
>> +		/*1. reset req, and read reset st check*/
>> +		ret = mdio_sc_cfg_reg_write(mdio_dev,
>> MDIO_SC_RESET_REQ, 0x1,
>> +					    MDIO_SC_RESET_ST, 0x1,
>> +					    MDIO_CHECK_SET_ST);
>> +		if (ret) {
>> +			dev_err(&bus->dev, "MDIO reset fail\n");
>> +			return ret;
>> +		}
>>  
>> -	/*3. reset dreq, and read reset st check*/
>> -	ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_RESET_DREQ,
>> 0x1,
>> -				    MDIO_SC_RESET_ST, 0x1,
>> -				    MDIO_CHECK_CLR_ST);
>> -	if (ret) {
>> -		dev_err(&bus->dev, "MDIO dis clk fail\n");
>> -		return ret;
>> -	}
>> +		/*2. dis clk, and read clk st check*/
>> +		ret = mdio_sc_cfg_reg_write(mdio_dev,
>> MDIO_SC_CLK_DIS,
>> +					    0x1, MDIO_SC_CLK_ST, 0x1,
>> +					    MDIO_CHECK_CLR_ST);
>> +		if (ret) {
>> +			dev_err(&bus->dev, "MDIO dis clk fail\n");
>> +			return ret;
>> +		}
>>  
>> -	/*4. en clk, and read clk st check*/
>> -	ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_CLK_EN,
>> -				    0x1, MDIO_SC_CLK_ST, 0x1,
>> -				    MDIO_CHECK_SET_ST);
>> -	if (ret)
>> -		dev_err(&bus->dev, "MDIO en clk fail\n");
>> +		/*3. reset dreq, and read reset st check*/
>> +		ret = mdio_sc_cfg_reg_write(mdio_dev,
>> MDIO_SC_RESET_DREQ, 0x1,
>> +					    MDIO_SC_RESET_ST, 0x1,
>> +					    MDIO_CHECK_CLR_ST);
>> +		if (ret) {
>> +			dev_err(&bus->dev, "MDIO dis clk fail\n");
>> +			return ret;
>> +		}
>>  
>> +		/*4. en clk, and read clk st check*/
>> +		ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_CLK_EN,
>> +					    0x1, MDIO_SC_CLK_ST, 0x1,
>> +					    MDIO_CHECK_SET_ST);
>> +		if (ret)
>> +			dev_err(&bus->dev, "MDIO en clk fail\n");
>> +	} else if (ACPI_COMPANION(bus->parent)) {
>> +		acpi_status s;
>> +
>> +		s = acpi_evaluate_object(ACPI_HANDLE(bus->parent),
>> +					 "_RST", NULL, NULL);
>> +		if (ACPI_FAILURE(s)) {
>> +			dev_err(&bus->dev, "Reset failed,
>> return:%#x\n", s);
>> +			ret = -EBUSY;
>> +		} else {
>> +			ret = 0;
>> +		}
>> +	} else {
>> +		dev_err(&bus->dev, "cannot get cfd data from of or
>> acpi\n");
> cannot -> Can not
>
> WTF cfd?
>
> of or acpi -> DT or ACPI

ok, thanks Andy. i will fix it in next submit

>> +		ret = -ENXIO;
>> +	}
>>  	return ret;
>>  }
>>  
>>  /**
>>   * 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,7 +431,6 @@ 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;
>> @@ -432,7 +440,7 @@ static int hns_mdio_probe(struct platform_device
>> *pdev)
>>  		dev_err(NULL, "pdev is NULL!\r\n");
>>  		return -ENODEV;
>>  	}
>> -	np = pdev->dev.of_node;
>> +
>>  	mdio_dev = devm_kzalloc(&pdev->dev, sizeof(*mdio_dev),
>> GFP_KERNEL);
>>  	if (!mdio_dev)
>>  		return -ENOMEM;
>> @@ -448,7 +456,6 @@ 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);
>>  
>>  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>>  	mdio_dev->vbase = devm_ioremap_resource(&pdev->dev, res);
>> @@ -457,16 +464,37 @@ 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(&pdev->dev, "no syscon hisilicon,peri-c-
>> subctrl\n");
>> -		mdio_dev->subctrl_vbase = NULL;
>> +	hns_mdio_bus_name(new_bus->id, res->start);
>> +	if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
> is_of_node()

ok, thanks Andy. i will fix it in next submit

>> +		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(&pdev->dev, "no syscon
>> hisilicon,peri-c-subctrl\n");
>> +			mdio_dev->subctrl_vbase = NULL;
>> +		}
>>  	}
>>  	new_bus->parent = &pdev->dev;
>>  	platform_set_drvdata(pdev, new_bus);
>>  
>> -	ret = of_mdiobus_register(new_bus, np);
>> +	if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
> Ditto
>
>> +		ret = of_mdiobus_register(new_bus, pdev-
>>> dev.of_node);
>> +	} else if (ACPI_COMPANION(&pdev->dev)) {
> is_acpi_node()
>
>> +		/* Clear all the IRQ properties */
>> +		memset(new_bus->irq, PHY_POLL, 4 * PHY_MAX_ADDR);
>> +
>> +		/* Mask out all PHYs from auto probing. */
>> +		new_bus->phy_mask = ~0;
>> +
>> +		/* Register the MDIO bus */
>> +		ret = mdiobus_register(new_bus);
>> +		if (ret)
>> +			return ret;
>> +	} else {
>> +		dev_err(&pdev->dev, "cannot get cfd data from of or
>> acpi\n");
> Same as for previous message.
>
>> +		return -ENXIO;
>> +	}
>> +
>>  	if (ret) {
>>  		dev_err(&pdev->dev, "Cannot register as MDIO
>> bus!\n");
>>  		platform_set_drvdata(pdev, NULL);
>> @@ -499,12 +527,19 @@ static const struct of_device_id
>> hns_mdio_match[] = {
>>  	{}
>>  };
>>  
>> +static const struct acpi_device_id hns_mdio_acpi_match[] = {
>> +	{ "HISI0141", 0 },
>> +	{ },
>> +};
>> +MODULE_DEVICE_TABLE(acpi, hns_mdio_acpi_match);
>> +
>>  static struct platform_driver hns_mdio_driver = {
>>  	.probe = hns_mdio_probe,
>>  	.remove = hns_mdio_remove,
>>  	.driver = {
>>  		   .name = MDIO_DRV_NAME,
>>  		   .of_match_table = hns_mdio_match,
>> +		   .acpi_match_table = ACPI_PTR(hns_mdio_acpi_match),
>>  		   },
>>  };
>>  
>
> So, I suggest to split this to two logical changes:
>
> 1. Move to use fwnode_handle
> 2. Add ACPI bits

ok, thanks Andy. i will fix it in next submit

MBR,
Kejian

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2016-05-16  7:12 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-13  8:19 [patch net-next 00/11] net: hns: add support of ACPI Yisen Zhuang
2016-05-13  8:19 ` [patch net-next 01/11] net: hisilicon: add support of acpi for hns-mdio Yisen Zhuang
2016-05-13 12:59   ` Andy Shevchenko
2016-05-16  7:10     ` Yankejian (Hackim Yim)
2016-05-13  8:19 ` [patch net-next 02/11] net: hns: use device_* APIs instead of of_* APIs Yisen Zhuang
2016-05-13  8:19 ` [patch net-next 03/11] net: hns: use platform_get_irq instead of irq_of_parse_and_map Yisen Zhuang
2016-05-13  8:19 ` [patch net-next 04/11] net: hns: enet specify a reference to dsaf by fwnode_handle Yisen Zhuang
2016-05-13 13:01   ` Andy Shevchenko
2016-05-13  8:19 ` [patch net-next 05/11] net: hns: add uniform interface for phy connection Yisen Zhuang
2016-05-13 13:07   ` Andy Shevchenko
2016-05-16  0:40     ` Yankejian (Hackim Yim)
2016-05-13  8:19 ` [patch net-next 06/11] ACPI: bus: move acpi_match_device_ids() to linux/acpi.h Yisen Zhuang
2016-05-13 13:15   ` Andy Shevchenko
2016-05-16  1:57     ` Yankejian (Hackim Yim)
2016-05-13  8:19 ` [patch net-next 07/11] net: hns: dsaf adds support of acpi Yisen Zhuang
2016-05-13 13:12   ` Andy Shevchenko
2016-05-16  2:06     ` Yankejian (Hackim Yim)
2016-05-13  8:19 ` [patch net-next 08/11] net: hns: register phy device in each mac initial sequence Yisen Zhuang
2016-05-13  8:29   ` kbuild test robot
2016-05-13  8:19 ` [patch net-next 09/11] ACPI: bus: add stub acpi_evaluate_dsm() to linux/acpi.h Yisen Zhuang
2016-05-13  8:19 ` [patch net-next 10/11] net: hns: implement the reset sequence by asl Yisen Zhuang
2016-05-13  8:19 ` [patch net-next 11/11] net: hns: enet adds support of acpi Yisen Zhuang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.